filename
stringlengths
5
42
content
stringlengths
15
319k
mxalgebra.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 finfun bigop finset fingroup perm order. From mathcomp Require Import div prime binomial ssralg finalg zmodp matrix. (*****************************************************************************) (* In this file we develop the rank and row space theory of matrices, based *) (* on an extended Gaussian elimination procedure similar to LUP *) (* decomposition. This provides us with a concrete but generic model of *) (* finite dimensional vector spaces and F-algebras, in which vectors, linear *) (* functions, families, bases, subspaces, ideals and subrings are all *) (* represented using matrices. This model can be used as a foundation for *) (* the usual theory of abstract linear algebra, but it can also be used to *) (* develop directly substantial theories, such as the theory of finite group *) (* linear representation. *) (* Here we define the following concepts and notations: *) (* Gaussian_elimination A == a permuted triangular decomposition (L, U, r) *) (* of A, with L a column permutation of a lower triangular *) (* invertible matrix, U a row permutation of an upper *) (* triangular invertible matrix, and r the rank of A, all *) (* satisfying the identity L *m pid_mx r *m U = A. *) (* \rank A == the rank of A. *) (* row_free A <=> the rows of A are linearly free (i.e., the rank and *) (* height of A are equal). *) (* row_full A <=> the row-space of A spans all row-vectors (i.e., the *) (* rank and width of A are equal). *) (* col_ebase A == the extended column basis of A (the first matrix L *) (* returned by Gaussian_elimination A). *) (* row_ebase A == the extended row base of A (the second matrix U *) (* returned by Gaussian_elimination A). *) (* col_base A == a basis for the columns of A: a row-full matrix *) (* consisting of the first \rank A columns of col_ebase A. *) (* row_base A == a basis for the rows of A: a row-free matrix consisting *) (* of the first \rank A rows of row_ebase A. *) (* pinvmx A == a partial inverse for A in its row space (or on its *) (* column space, equivalently). In particular, if u is a *) (* row vector in the row_space of A, then u *m pinvmx A is *) (* the row vector of the coefficients of a decomposition *) (* of u as a sub of rows of A. *) (* kermx A == the row kernel of A : a square matrix whose row space *) (* consists of all u such that u *m A = 0 (it consists of *) (* the inverse of col_ebase A, with the top \rank A rows *) (* zeroed out). Also, kermx A is a partial right inverse *) (* to col_ebase A, in the row space annihilated by A. *) (* cokermx A == the cokernel of A : a square matrix whose column space *) (* consists of all v such that A *m v = 0 (it consists of *) (* the inverse of row_ebase A, with the leftmost \rank A *) (* columns zeroed out). *) (* maxrankfun A == injective function f so that rowsub f A is a submatrix *) (* of A with the same rank as A. *) (* fullrankfun fA == injective function f so that rowsub f A is row full, *) (* where fA is a proof of row_full A *) (* eigenvalue g a <=> a is an eigenvalue of the square matrix g. *) (* eigenspace g a == a square matrix whose row space is the eigenspace of *) (* the eigenvalue a of g (or 0 if a is not an eigenvalue). *) (* We use a different scope %MS for matrix row-space set-like operations; to *) (* avoid confusion, this scope should not be opened globally. Note that the *) (* the arguments of \rank _ and the operations below have default scope %MS. *) (* (A <= B)%MS <=> the row-space of A is included in the row-space of B. *) (* We test for this by testing if cokermx B annihilates A. *) (* (A < B)%MS <=> the row-space of A is properly included in the *) (* row-space of B. *) (* (A <= B <= C)%MS == (A <= B)%MS && (B <= C)%MS, and similarly for *) (* (A < B <= C)%MS, (A < B <= C)%MS and (A < B < C)%MS. *) (* (A == B)%MS == (A <= B <= A)%MS (A and B have the same row-space). *) (* (A :=: B)%MS == A and B behave identically wrt. \rank and <=. This *) (* triple rewrite rule is the Prop version of (A == B)%MS. *) (* Note that :=: cannot be treated as a setoid-style *) (* Equivalence because its arguments can have different *) (* types: A and B need not have the same number of rows, *) (* and often don't (e.g., in row_base A :=: A). *) (* <<A>>%MS == a square matrix with the same row-space as A; <<A>>%MS *) (* is a canonical representation of the subspace generated *) (* by A, viewed as a list of row-vectors: if (A == B)%MS, *) (* then <<A>>%MS = <<B>>%MS. *) (* (A + B)%MS == a square matrix whose row-space is the sum of the *) (* row-spaces of A and B; thus (A + B == col_mx A B)%MS. *) (* (\sum_i <expr i>)%MS == the "big" version of (_ + _)%MS; as the latter *) (* has a canonical abelian monoid structure, most generic *) (* bigop lemmas apply (the other bigop indexing notations *) (* are also defined). *) (* (A :&: B)%MS == a square matrix whose row-space is the intersection of *) (* the row-spaces of A and B. *) (* (\bigcap_i <expr i>)%MS == the "big" version of (_ :&: _)%MS, which also *) (* has a canonical abelian monoid structure. *) (* A^C%MS == a square matrix whose row-space is a complement to the *) (* the row-space of A (it consists of row_ebase A with the *) (* top \rank A rows zeroed out). *) (* (A :\: B)%MS == a square matrix whose row-space is a complement of the *) (* the row-space of (A :&: B)%MS in the row-space of A. *) (* We have (A :\: B := A :&: (capmx_gen A B)^C)%MS, where *) (* capmx_gen A B is a rectangular matrix equivalent to *) (* (A :&: B)%MS, i.e., (capmx_gen A B == A :&: B)%MS. *) (* proj_mx A B == a square matrix that projects (A + B)%MS onto A *) (* parallel to B, when (A :&: B)%MS = 0 (A and B must also *) (* be square). *) (* mxdirect S == the sum expression S is a direct sum. This is a NON *) (* EXTENSIONAL notation: the exact boolean expression is *) (* inferred from the syntactic form of S (expanding *) (* definitions, however); both (\sum_(i | _) _)%MS and *) (* (_ + _)%MS sums are recognized. This construct uses a *) (* variant of the reflexive ("quote") canonical structure, *) (* mxsum_expr. The structure also recognizes sums of *) (* matrix ranks, so that lemmas concerning the rank of *) (* direct sums can be used bidirectionally. *) (* stablemx V f <=> the matrix f represents an endomorphism that preserves V *) (* := (V *m f <= V)%MS *) (* The next set of definitions let us represent F-algebras using matrices: *) (* 'A[F]_(m, n) == the type of matrices encoding (sub)algebras of square *) (* n x n matrices, via mxvec; as in the matrix type *) (* notation, m and F can be omitted (m defaults to n ^ 2). *) (* := 'M[F]_(m, n ^ 2). *) (* (A \in R)%MS <=> the square matrix A belongs to the linear set of *) (* matrices (most often, a sub-algebra) encoded by the *) (* row space of R. This is simply notation, so all the *) (* lemmas and rewrite rules for (_ <= _)%MS can apply. *) (* := (mxvec A <= R)%MS. *) (* (R * S)%MS == a square n^2 x n^2 matrix whose row-space encodes the *) (* linear set of n x n matrices generated by the pointwise *) (* product of the sets of matrices encoded by R and S. *) (* 'C(R)%MS == a square matrix encoding the centraliser of the set of *) (* square matrices encoded by R. *) (* 'C_S(R)%MS := (S :&: 'C(R))%MS (the centraliser of R in S). *) (* 'Z(R)%MS == the center of R (i.e., 'C_R(R)%MS). *) (* left_mx_ideal R S <=> S is a left ideal for R (R * S <= S)%MS. *) (* right_mx_ideal R S <=> S is a right ideal for R (S * R <= S)%MS. *) (* mx_ideal R S <=> S is a bilateral ideal for R. *) (* mxring_id R e <-> e is an identity element for R (Prop predicate). *) (* has_mxring_id R <=> R has a nonzero identity element (bool predicate). *) (* mxring R <=> R encodes a nontrivial subring. *) (*****************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope matrix_set_scope. Import GroupScope. Import GRing.Theory. Local Open Scope ring_scope. Reserved Notation "\rank A" (at level 10, A at level 8, format "\rank A"). Reserved Notation "A ^C" (format "A ^C"). Notation "''A_' ( m , n )" := 'M_(m, n ^ 2) (format "''A_' ( m , n )") : type_scope. Notation "''A_' ( n )" := 'A_(n ^ 2, n) (only parsing) : type_scope. Notation "''A_' n" := 'A_(n) (n at next level, format "''A_' n") : type_scope. Notation "''A' [ F ]_ ( m , n )" := 'M[F]_(m, n ^ 2) (only parsing) : type_scope. Notation "''A' [ F ]_ ( n )" := 'A[F]_(n ^ 2, n) (only parsing) : type_scope. Notation "''A' [ F ]_ n" := 'A[F]_(n) (n at level 2, only parsing) : type_scope. Delimit Scope matrix_set_scope with MS. Local Notation simp := (Monoid.Theory.simpm, oppr0). (*****************************************************************************) (******************** Rank and row-space theory ******************************) (*****************************************************************************) (* Decomposition with double pivoting; computes the rank, row and column *) (* images, kernels, and complements of a matrix. *) Fixpoint Gaussian_elimination_ {F : fieldType} {m n} : 'M[F]_(m, n) -> 'M_m * 'M_n * nat := match m, n with | _.+1, _.+1 => fun A : 'M_(1 + _, 1 + _) => if [pick ij | A ij.1 ij.2 != 0] is Some (i, j) then let a := A i j in let A1 := xrow i 0 (xcol j 0 A) in let u := ursubmx A1 in let v := a^-1 *: dlsubmx A1 in let: (L, U, r) := Gaussian_elimination_ (drsubmx A1 - v *m u) in (xrow i 0 (block_mx 1 0 v L), xcol j 0 (block_mx a%:M u 0 U), r.+1) else (1%:M, 1%:M, 0) | _, _ => fun _ => (1%:M, 1%:M, 0) end. HB.lock Definition Gaussian_elimination := @Gaussian_elimination_. Canonical Gaussian_elimination_unlockable := Unlockable Gaussian_elimination.unlock. HB.lock Definition mxrank (F : fieldType) m n (A : 'M_(m, n)) := if [|| m == 0 | n == 0]%N then 0 else (@Gaussian_elimination F m n A).2. Canonical mxrank_unlockable := Unlockable mxrank.unlock. Section RowSpaceTheoryDefs. Variable F : fieldType. Implicit Types m n p r : nat. Local Notation "''M_' ( m , n )" := 'M[F]_(m, n) : type_scope. Local Notation "''M_' n" := 'M[F]_(n, n) : type_scope. Variables (m n : nat) (A : 'M_(m, n)). Local Notation mxrank := (@mxrank F m n A). Let LUr := @Gaussian_elimination F m n A. Definition col_ebase := LUr.1.1. Definition row_ebase := LUr.1.2. Definition row_free := mxrank == m. Definition row_full := mxrank == n. Definition row_base : 'M_(mxrank, n) := pid_mx mxrank *m row_ebase. Definition col_base : 'M_(m, mxrank) := col_ebase *m pid_mx mxrank. Definition complmx : 'M_n := copid_mx mxrank *m row_ebase. Definition kermx : 'M_m := copid_mx mxrank *m invmx col_ebase. Definition cokermx : 'M_n := invmx row_ebase *m copid_mx mxrank. Definition pinvmx : 'M_(n, m) := invmx row_ebase *m pid_mx mxrank *m invmx col_ebase. End RowSpaceTheoryDefs. Implicit Types F : fieldType. HB.lock Definition submx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := A *m cokermx B == 0. Canonical submx_unlockable := Unlockable submx.unlock. Arguments mxrank {F} {m%_N n%_N} A%_MS. Arguments complmx {F} {m%_N n%_N} A%_MS. Arguments submx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "\rank A" := (mxrank A) : nat_scope. Local Notation "A ^C" := (complmx A) : matrix_set_scope. Local Notation "A <= B" := (submx A B) : matrix_set_scope. Local Notation "A <= B <= C" := ((A <= B) && (B <= C))%MS : matrix_set_scope. Local Notation "A == B" := (A <= B <= A)%MS : matrix_set_scope. Definition ltmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := (A <= B)%MS && ~~ (B <= A)%MS. Arguments ltmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS. Local Notation "A < B" := (ltmx A B) : matrix_set_scope. Definition eqmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := prod (\rank A = \rank B) (forall m3 (C : 'M_(m3, n)), ((A <= C) = (B <= C)) * ((C <= A) = (C <= B)))%MS. Arguments eqmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS. Local Notation "A :=: B" := (eqmx A%MS B%MS) : matrix_set_scope. Notation stablemx V f := (V%MS *m f%R <= V%MS)%MS. Section LtmxIdentities. Variable F : fieldType. Implicit Types m n p r : nat. Local Notation "''M_' ( m , n )" := 'M[F]_(m, n) : type_scope. Local Notation "''M_' n" := 'M[F]_(n, n) : type_scope. Variables (m1 m2 n : nat) (A : 'M_(m1, n)) (B : 'M_(m2, n)). Lemma ltmxE : (A < B)%MS = ((A <= B)%MS && ~~ (B <= A)%MS). Proof. by []. Qed. Lemma ltmxW : (A < B)%MS -> (A <= B)%MS. Proof. by case/andP. Qed. Lemma ltmxEneq : (A < B)%MS = (A <= B)%MS && ~~ (A == B)%MS. Proof. by apply: andb_id2l => ->. Qed. Lemma submxElt : (A <= B)%MS = (A == B)%MS || (A < B)%MS. Proof. by rewrite -andb_orr orbN andbT. Qed. End LtmxIdentities. (* The definition of the row-space operator is rigged to return the identity *) (* matrix for full matrices. To allow for further tweaks that will make the *) (* row-space intersection operator strictly commutative and monoidal, we *) (* slightly generalize some auxiliary definitions: we parametrize the *) (* "equivalent subspace and identity" choice predicate equivmx by a boolean *) (* determining whether the matrix should be the identity (so for genmx A its *) (* value is row_full A), and introduce a "quasi-identity" predicate qidmx *) (* that selects non-square full matrices along with the identity matrix 1%:M *) (* (this does not affect genmx, which chooses a square matrix). *) (* The choice witness for genmx A is either 1%:M for a row-full A, or else *) (* row_base A padded with null rows. *) Local Definition qidmx F m n (A : 'M[F]_(m, n)) := if m == n then A == pid_mx n else row_full A. Local Definition equivmx F m n (A : 'M[F]_(m, n)) idA (B : 'M_n) := (B == A)%MS && (qidmx B == idA). Local Definition equivmx_spec F m n (A : 'M[F]_(m, n)) idA (B : 'M_n) := prod (B :=: A)%MS (qidmx B = idA). Local Definition genmx_witness F m n (A : 'M[F]_(m, n)) : 'M_n := if row_full A then 1%:M else pid_mx (\rank A) *m row_ebase A. HB.lock Definition genmx F m n (A : 'M[F]_(m, n)) : 'M_n := choose (equivmx A (row_full A)) (genmx_witness A). Canonical genmx_unlockable := Unlockable genmx.unlock. Arguments genmx {F} {n m}%_N A%_MS : rename. Local Notation "<< A >>" := (genmx A%MS) : matrix_set_scope. (* The setwise sum is tweaked so that 0 is a strict identity element for *) (* square matrices, because this lets us use the bigop component. As a result *) (* setwise sum is not quite strictly extensional. *) Local Definition addsmx_nop F m n (A : 'M[F]_(m, n)) := conform_mx <<A>>%MS A. HB.lock Definition addsmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) : 'M_n := if A == 0 then addsmx_nop B else if B == 0 then addsmx_nop A else <<col_mx A B>>%MS. Canonical addsmx_unlockable := Unlockable addsmx.unlock. Arguments addsmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "A + B" := (addsmx A B) : matrix_set_scope. Local Notation "\sum_ ( i | P ) B" := (\big[addsmx/0]_(i | P) B%MS) : matrix_set_scope. Local Notation "\sum_ ( i <- r | P ) B" := (\big[addsmx/0]_(i <- r | P) B%MS) : matrix_set_scope. (* The set intersection is similarly biased so that the identity matrix is a *) (* strict identity. This is somewhat more delicate than for the sum, because *) (* the test for the identity is non-extensional. This forces us to actually *) (* bias the choice operator so that it does not accidentally map an *) (* intersection of non-identity matrices to 1%:M; this would spoil *) (* associativity: if B :&: C = 1%:M but B and C are not identity, then for a *) (* square matrix A we have A :&: (B :&: C) = A != (A :&: B) :&: C in general. *) (* To complicate matters there may not be a square non-singular matrix *) (* different than 1%:M, since we could be dealing with 'M['F_2]_1. We *) (* sidestep the issue by making all non-square row-full matrices identities, *) (* and choosing a normal representative that preserves the qidmx property. *) (* Thus A :&: B = 1%:M iff A and B are both identities, and this suffices for *) (* showing that associativity is strict. *) Local Definition capmx_witness F m n (A : 'M[F]_(m, n)) := if row_full A then conform_mx 1%:M A else <<A>>%MS. Local Definition capmx_norm F m n (A : 'M[F]_(m, n)) := choose (equivmx A (qidmx A)) (capmx_witness A). Local Definition capmx_nop F m n (A : 'M[F]_(m, n)) := conform_mx (capmx_norm A) A. Definition capmx_gen F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) := lsubmx (kermx (col_mx A B)) *m A. HB.lock Definition capmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) : 'M_n := if qidmx A then capmx_nop B else if qidmx B then capmx_nop A else if row_full B then capmx_norm A else capmx_norm (capmx_gen A B). Canonical capmx_unlockable := Unlockable capmx.unlock. Arguments capmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "A :&: B" := (capmx A B) : matrix_set_scope. Local Notation "\bigcap_ ( i | P ) B" := (\big[capmx/1%:M]_(i | P) B) : matrix_set_scope. HB.lock Definition diffmx F m1 m2 n (A : 'M[F]_(m1, n)) (B : 'M_(m2, n)) : 'M_n := <<capmx_gen A (capmx_gen A B)^C>>%MS. Canonical diffmx_unlockable := Unlockable diffmx.unlock. Arguments diffmx {F} {m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Local Notation "A :\: B" := (diffmx A B) : matrix_set_scope. Section RowSpaceTheory. Variable F : fieldType. Implicit Types m n p r : nat. Local Notation "''M_' ( m , n )" := 'M[F]_(m, n) : type_scope. Local Notation "''M_' n" := 'M[F]_(n, n) : type_scope. Definition proj_mx n (U V : 'M_n) : 'M_n := pinvmx (col_mx U V) *m col_mx U 0. Local Notation GaussE := Gaussian_elimination_. Fact mxrankE m n (A : 'M_(m, n)) : \rank A = (GaussE A).2. Proof. by rewrite mxrank.unlock unlock /=; case: m n A => [|m] [|n]. Qed. Lemma rank_leq_row m n (A : 'M_(m, n)) : \rank A <= m. Proof. rewrite mxrankE. elim: m n A => [|m IHm] [|n] //= A; case: pickP => [[i j] _|] //=. by move: (_ - _) => B; case: GaussE (IHm _ B) => [[L U] r] /=. Qed. Lemma row_leq_rank m n (A : 'M_(m, n)) : (m <= \rank A) = row_free A. Proof. by rewrite /row_free eqn_leq rank_leq_row. Qed. Lemma rank_leq_col m n (A : 'M_(m, n)) : \rank A <= n. Proof. rewrite mxrankE. elim: m n A => [|m IHm] [|n] //= A; case: pickP => [[i j] _|] //=. by move: (_ - _) => B; case: GaussE (IHm _ B) => [[L U] r] /=. Qed. Lemma col_leq_rank m n (A : 'M_(m, n)) : (n <= \rank A) = row_full A. Proof. by rewrite /row_full eqn_leq rank_leq_col. Qed. Lemma eq_row_full m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> row_full A = row_full B. Proof. by rewrite /row_full => ->. Qed. Let unitmx1F := @unitmx1 F. Lemma row_ebase_unit m n (A : 'M_(m, n)) : row_ebase A \in unitmx. Proof. rewrite /row_ebase unlock; elim: m n A => [|m IHm] [|n] //= A. case: pickP => [[i j] /= nzAij | //=]; move: (_ - _) => B. case: GaussE (IHm _ B) => [[L U] r] /= uU. rewrite unitmxE xcolE det_mulmx (@det_ublock _ 1) det_scalar1 !unitrM. by rewrite unitfE nzAij -!unitmxE uU unitmx_perm. Qed. Lemma col_ebase_unit m n (A : 'M_(m, n)) : col_ebase A \in unitmx. Proof. rewrite /col_ebase unlock; elim: m n A => [|m IHm] [|n] //= A. case: pickP => [[i j] _|] //=; move: (_ - _) => B. case: GaussE (IHm _ B) => [[L U] r] /= uL. rewrite unitmxE xrowE det_mulmx (@det_lblock _ 1) det1 mul1r unitrM. by rewrite -unitmxE unitmx_perm. Qed. Hint Resolve rank_leq_row rank_leq_col row_ebase_unit col_ebase_unit : core. Lemma mulmx_ebase m n (A : 'M_(m, n)) : col_ebase A *m pid_mx (\rank A) *m row_ebase A = A. Proof. rewrite mxrankE /col_ebase /row_ebase unlock. elim: m n A => [n A | m IHm]; first by rewrite [A]flatmx0 [_ *m _]flatmx0. case=> [A | n]; first by rewrite [_ *m _]thinmx0 [A]thinmx0. rewrite -(add1n m) -?(add1n n) => A /=. case: pickP => [[i0 j0] | A0] /=; last first. apply/matrixP=> i j; rewrite pid_mx_0 mulmx0 mul0mx mxE. by move/eqP: (A0 (i, j)). set a := A i0 j0 => nz_a; set A1 := xrow _ _ _. set u := ursubmx _; set v := _ *: _; set B : 'M_(m, n) := _ - _. move: (rank_leq_col B) (rank_leq_row B) {IHm}(IHm n B); rewrite mxrankE. case: (GaussE B) => [[L U] r] /= r_m r_n defB. have ->: pid_mx (1 + r) = block_mx 1 0 0 (pid_mx r) :> 'M[F]_(1 + m, 1 + n). rewrite -(subnKC r_m) -(subnKC r_n) pid_mx_block -col_mx0 -row_mx0. by rewrite block_mxA castmx_id col_mx0 row_mx0 -scalar_mx_block -pid_mx_block. rewrite xcolE xrowE mulmxA -xcolE -!mulmxA. rewrite !(addr0, add0r, mulmx0, mul0mx, mulmx_block, mul1mx) mulmxA defB. rewrite addrC subrK mul_mx_scalar scalerA divff // scale1r. have ->: a%:M = ulsubmx A1 by rewrite [_ A1]mx11_scalar !mxE !lshift0 !tpermR. rewrite submxK /A1 xrowE !xcolE -!mulmxA mulmxA -!perm_mxM !tperm2 !perm_mx1. by rewrite mulmx1 mul1mx. Qed. Lemma mulmx_base m n (A : 'M_(m, n)) : col_base A *m row_base A = A. Proof. by rewrite mulmxA -[col_base A *m _]mulmxA pid_mx_id ?mulmx_ebase. Qed. Lemma mulmx1_min_rank r m n (A : 'M_(m, n)) M N : M *m A *m N = 1%:M :> 'M_r -> r <= \rank A. Proof. by rewrite -{1}(mulmx_base A) mulmxA -mulmxA; move/mulmx1_min. Qed. Arguments mulmx1_min_rank [r m n A]. Lemma mulmx_max_rank r m n (M : 'M_(m, r)) (N : 'M_(r, n)) : \rank (M *m N) <= r. Proof. set MN := M *m N; set rMN := \rank _. pose L : 'M_(rMN, m) := pid_mx rMN *m invmx (col_ebase MN). pose U : 'M_(n, rMN) := invmx (row_ebase MN) *m pid_mx rMN. suffices: L *m M *m (N *m U) = 1%:M by apply: mulmx1_min. rewrite mulmxA -(mulmxA L) -[M *m N]mulmx_ebase -/MN. by rewrite !mulmxA mulmxKV // mulmxK // !pid_mx_id /rMN ?pid_mx_1. Qed. Arguments mulmx_max_rank [r m n]. Lemma mxrank_tr m n (A : 'M_(m, n)) : \rank A^T = \rank A. Proof. apply/eqP; rewrite eqn_leq -{3}[A]trmxK -{1}(mulmx_base A) -{1}(mulmx_base A^T). by rewrite !trmx_mul !mulmx_max_rank. Qed. Lemma mxrank_add m n (A B : 'M_(m, n)) : \rank (A + B)%R <= \rank A + \rank B. Proof. by rewrite -{1}(mulmx_base A) -{1}(mulmx_base B) -mul_row_col mulmx_max_rank. Qed. Lemma mxrankM_maxl m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : \rank (A *m B) <= \rank A. Proof. by rewrite -{1}(mulmx_base A) -mulmxA mulmx_max_rank. Qed. Lemma mxrankM_maxr m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : \rank (A *m B) <= \rank B. Proof. by rewrite -mxrank_tr -(mxrank_tr B) trmx_mul mxrankM_maxl. Qed. Lemma mxrank_scale m n a (A : 'M_(m, n)) : \rank (a *: A) <= \rank A. Proof. by rewrite -mul_scalar_mx mxrankM_maxr. Qed. Lemma mxrank_scale_nz m n a (A : 'M_(m, n)) : a != 0 -> \rank (a *: A) = \rank A. Proof. move=> nza; apply/eqP; rewrite eqn_leq -{3}[A]scale1r -(mulVf nza). by rewrite -scalerA !mxrank_scale. Qed. Lemma mxrank_opp m n (A : 'M_(m, n)) : \rank (- A) = \rank A. Proof. by rewrite -scaleN1r mxrank_scale_nz // oppr_eq0 oner_eq0. Qed. Lemma mxrank0 m n : \rank (0 : 'M_(m, n)) = 0%N. Proof. by apply/eqP; rewrite -leqn0 -(@mulmx0 _ m 0 n 0) mulmx_max_rank. Qed. Lemma mxrank_eq0 m n (A : 'M_(m, n)) : (\rank A == 0) = (A == 0). Proof. apply/eqP/eqP=> [rA0 | ->{A}]; last exact: mxrank0. move: (col_base A) (row_base A) (mulmx_base A); rewrite rA0 => Ac Ar <-. by rewrite [Ac]thinmx0 mul0mx. Qed. Lemma mulmx_coker m n (A : 'M_(m, n)) : A *m cokermx A = 0. Proof. by rewrite -{1}[A]mulmx_ebase -!mulmxA mulKVmx // mul_pid_mx_copid ?mulmx0. Qed. Lemma submxE m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS = (A *m cokermx B == 0). Proof. by rewrite unlock. Qed. Lemma mulmxKpV m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> A *m pinvmx B *m B = A. Proof. rewrite submxE !mulmxA mulmxBr mulmx1 subr_eq0 => /eqP defA. rewrite -{4}[B]mulmx_ebase -!mulmxA mulKmx //. by rewrite (mulmxA (pid_mx _)) pid_mx_id // !mulmxA -{}defA mulmxKV. Qed. Lemma mulmxVp m n (A : 'M[F]_(m, n)) : row_free A -> A *m pinvmx A = 1%:M. Proof. move=> fA; rewrite -[X in X *m _]mulmx_ebase !mulmxA mulmxK ?row_ebase_unit//. rewrite -[X in X *m _]mulmxA mul_pid_mx !minnn (minn_idPr _) ?rank_leq_col//. by rewrite (eqP fA) pid_mx_1 mulmx1 mulmxV ?col_ebase_unit. Qed. Lemma mulmxKp p m n (B : 'M[F]_(m, n)) : row_free B -> cancel ((@mulmx _ p _ _)^~ B) (mulmx^~ (pinvmx B)). Proof. by move=> ? A; rewrite -mulmxA mulmxVp ?mulmx1. Qed. Lemma submxP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (exists D, A = D *m B) (A <= B)%MS. Proof. apply: (iffP idP) => [/mulmxKpV | [D ->]]; first by exists (A *m pinvmx B). by rewrite submxE -mulmxA mulmx_coker mulmx0. Qed. Arguments submxP {m1 m2 n A B}. Lemma submx_refl m n (A : 'M_(m, n)) : (A <= A)%MS. Proof. by rewrite submxE mulmx_coker. Qed. Hint Resolve submx_refl : core. Lemma submxMl m n p (D : 'M_(m, n)) (A : 'M_(n, p)) : (D *m A <= A)%MS. Proof. by rewrite submxE -mulmxA mulmx_coker mulmx0. Qed. Lemma submxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : (A <= B)%MS -> (A *m C <= B *m C)%MS. Proof. by case/submxP=> D ->; rewrite -mulmxA submxMl. Qed. Lemma mulmx_sub m n1 n2 p (C : 'M_(m, n1)) A (B : 'M_(n2, p)) : (A <= B -> C *m A <= B)%MS. Proof. by case/submxP=> D ->; rewrite mulmxA submxMl. Qed. Lemma submx_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= B -> B <= C -> A <= C)%MS. Proof. by case/submxP=> D ->{A}; apply: mulmx_sub. Qed. Lemma ltmx_sub_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A < B)%MS -> (B <= C)%MS -> (A < C)%MS. Proof. case/andP=> sAB ltAB sBC; rewrite ltmxE (submx_trans sAB) //. by apply: contra ltAB; apply: submx_trans. Qed. Lemma sub_ltmx_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= B)%MS -> (B < C)%MS -> (A < C)%MS. Proof. move=> sAB /andP[sBC ltBC]; rewrite ltmxE (submx_trans sAB) //. by apply: contra ltBC => sCA; apply: submx_trans sAB. Qed. Lemma ltmx_trans m n : transitive (@ltmx F m m n). Proof. by move=> A B C; move/ltmxW; apply: sub_ltmx_trans. Qed. Lemma ltmx_irrefl m n : irreflexive (@ltmx F m m n). Proof. by move=> A; rewrite /ltmx submx_refl andbF. Qed. Lemma sub0mx m1 m2 n (A : 'M_(m2, n)) : ((0 : 'M_(m1, n)) <= A)%MS. Proof. by rewrite submxE mul0mx. Qed. Lemma submx0null m1 m2 n (A : 'M[F]_(m1, n)) : (A <= (0 : 'M_(m2, n)))%MS -> A = 0. Proof. by case/submxP=> D; rewrite mulmx0. Qed. Lemma submx0 m n (A : 'M_(m, n)) : (A <= (0 : 'M_n))%MS = (A == 0). Proof. by apply/idP/eqP=> [|->]; [apply: submx0null | apply: sub0mx]. Qed. Lemma lt0mx m n (A : 'M_(m, n)) : ((0 : 'M_n) < A)%MS = (A != 0). Proof. by rewrite /ltmx sub0mx submx0. Qed. Lemma ltmx0 m n (A : 'M[F]_(m, n)) : (A < (0 : 'M_n))%MS = false. Proof. by rewrite /ltmx sub0mx andbF. Qed. Lemma eqmx0P m n (A : 'M_(m, n)) : reflect (A = 0) (A == (0 : 'M_n))%MS. Proof. by rewrite submx0 sub0mx andbT; apply: eqP. Qed. Lemma eqmx_eq0 m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> (A == 0) = (B == 0). Proof. by move=> eqAB; rewrite -!submx0 eqAB. Qed. Lemma addmx_sub m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m1, n)) (C : 'M_(m2, n)) : (A <= C)%MS -> (B <= C)%MS -> ((A + B)%R <= C)%MS. Proof. by case/submxP=> A' ->; case/submxP=> B' ->; rewrite -mulmxDl submxMl. Qed. Lemma rowsub_sub m1 m2 n (f : 'I_m2 -> 'I_m1) (A : 'M_(m1, n)) : (rowsub f A <= A)%MS. Proof. by rewrite rowsubE mulmx_sub. Qed. Lemma summx_sub m1 m2 n (B : 'M_(m2, n)) I (r : seq I) (P : pred I) (A_ : I -> 'M_(m1, n)) : (forall i, P i -> A_ i <= B)%MS -> ((\sum_(i <- r | P i) A_ i)%R <= B)%MS. Proof. by move=> leAB; elim/big_ind: _ => // [|C D]; [apply/sub0mx | apply/addmx_sub]. Qed. Lemma scalemx_sub m1 m2 n a (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> (a *: A <= B)%MS. Proof. by case/submxP=> A' ->; rewrite scalemxAl submxMl. Qed. Lemma row_sub m n i (A : 'M_(m, n)) : (row i A <= A)%MS. Proof. exact: rowsub_sub. Qed. Lemma eq_row_sub m n v (A : 'M_(m, n)) i : row i A = v -> (v <= A)%MS. Proof. by move <-; rewrite row_sub. Qed. Arguments eq_row_sub [m n v A]. Lemma nz_row_sub m n (A : 'M_(m, n)) : (nz_row A <= A)%MS. Proof. by rewrite /nz_row; case: pickP => [i|] _; rewrite ?row_sub ?sub0mx. Qed. Lemma row_subP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (forall i, row i A <= B)%MS (A <= B)%MS. Proof. apply: (iffP idP) => [sAB i|sAB]. by apply: submx_trans sAB; apply: row_sub. rewrite submxE; apply/eqP/row_matrixP=> i; apply/eqP. by rewrite row_mul row0 -submxE. Qed. Arguments row_subP {m1 m2 n A B}. Lemma rV_subP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (forall v : 'rV_n, v <= A -> v <= B)%MS (A <= B)%MS. Proof. apply: (iffP idP) => [sAB v Av | sAB]; first exact: submx_trans sAB. by apply/row_subP=> i; rewrite sAB ?row_sub. Qed. Arguments rV_subP {m1 m2 n A B}. Lemma row_subPn m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (exists i, ~~ (row i A <= B)%MS) (~~ (A <= B)%MS). Proof. by rewrite (sameP row_subP forallP); apply: forallPn. Qed. Lemma sub_rVP n (u v : 'rV[F]_n) : reflect (exists a, u = a *: v) (u <= v)%MS. Proof. apply: (iffP submxP) => [[w ->] | [a ->]]. by exists (w 0 0); rewrite -mul_scalar_mx -mx11_scalar. by exists a%:M; rewrite mul_scalar_mx. Qed. Lemma rank_rV n (v : 'rV[F]_n) : \rank v = (v != 0). Proof. case: eqP => [-> | nz_v]; first by rewrite mxrank0. by apply/eqP; rewrite eqn_leq rank_leq_row lt0n mxrank_eq0; apply/eqP. Qed. Lemma rowV0Pn m n (A : 'M_(m, n)) : reflect (exists2 v : 'rV_n, v <= A & v != 0)%MS (A != 0). Proof. rewrite -submx0; apply: (iffP idP) => [| [v svA]]; last first. by rewrite -submx0; apply: contra (submx_trans _). by case/row_subPn=> i; rewrite submx0; exists (row i A); rewrite ?row_sub. Qed. Lemma rowV0P m n (A : 'M_(m, n)) : reflect (forall v : 'rV_n, v <= A -> v = 0)%MS (A == 0). Proof. rewrite -[A == 0]negbK; case: rowV0Pn => IH. by right; case: IH => v svA nzv IH; case/eqP: nzv; apply: IH. by left=> v svA; apply/eqP/idPn=> nzv; case: IH; exists v. Qed. Lemma submx_full m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : row_full B -> (A <= B)%MS. Proof. by rewrite submxE /cokermx => /eqnP->; rewrite /copid_mx pid_mx_1 subrr !mulmx0. Qed. Lemma row_fullP m n (A : 'M_(m, n)) : reflect (exists B, B *m A = 1%:M) (row_full A). Proof. apply: (iffP idP) => [Afull | [B kA]]. by exists (1%:M *m pinvmx A); apply: mulmxKpV (submx_full _ Afull). by rewrite [_ A]eqn_leq rank_leq_col (mulmx1_min_rank B 1%:M) ?mulmx1. Qed. Arguments row_fullP {m n A}. Lemma row_full_inj m n p A : row_full A -> injective (@mulmx F m n p A). Proof. case/row_fullP=> A' A'K; apply: can_inj (mulmx A') _ => B. by rewrite mulmxA A'K mul1mx. Qed. Lemma row_freeP m n (A : 'M_(m, n)) : reflect (exists B, A *m B = 1%:M) (row_free A). Proof. rewrite /row_free -mxrank_tr. apply: (iffP row_fullP) => [] [B kA]; by exists B^T; rewrite -trmx1 -kA trmx_mul ?trmxK. Qed. Lemma row_free_inj m n p A : row_free A -> injective ((@mulmx F m n p)^~ A). Proof. case/row_freeP=> A' AK; apply: can_inj (mulmx^~ A') _ => B. by rewrite -mulmxA AK mulmx1. Qed. (* A variant of row_free_inj that exposes mulmxr, an alias for mulmx^~ *) (* but which is canonically additive *) Definition row_free_injr m n p A : row_free A -> injective (mulmxr A) := @row_free_inj m n p A. Lemma row_free_unit n (A : 'M_n) : row_free A = (A \in unitmx). Proof. apply/row_fullP/idP=> [[A'] | uA]; first by case/mulmx1_unit. by exists (invmx A); rewrite mulVmx. Qed. Lemma row_full_unit n (A : 'M_n) : row_full A = (A \in unitmx). Proof. exact: row_free_unit. Qed. Lemma mxrank_unit n (A : 'M_n) : A \in unitmx -> \rank A = n. Proof. by rewrite -row_full_unit => /eqnP. Qed. Lemma mxrank1 n : \rank (1%:M : 'M_n) = n. Proof. exact: mxrank_unit. Qed. Lemma mxrank_delta m n i j : \rank (delta_mx i j : 'M_(m, n)) = 1. Proof. apply/eqP; rewrite eqn_leq lt0n mxrank_eq0. rewrite -{1}(mul_delta_mx (0 : 'I_1)) mulmx_max_rank. by apply/eqP; move/matrixP; move/(_ i j); move/eqP; rewrite !mxE !eqxx oner_eq0. Qed. Lemma mxrankS m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> \rank A <= \rank B. Proof. by case/submxP=> D ->; rewrite mxrankM_maxr. Qed. Lemma submx1 m n (A : 'M_(m, n)) : (A <= 1%:M)%MS. Proof. by rewrite submx_full // row_full_unit unitmx1. Qed. Lemma sub1mx m n (A : 'M_(m, n)) : (1%:M <= A)%MS = row_full A. Proof. apply/idP/idP; last exact: submx_full. by move/mxrankS; rewrite mxrank1 col_leq_rank. Qed. Lemma ltmx1 m n (A : 'M_(m, n)) : (A < 1%:M)%MS = ~~ row_full A. Proof. by rewrite /ltmx sub1mx submx1. Qed. Lemma lt1mx m n (A : 'M_(m, n)) : (1%:M < A)%MS = false. Proof. by rewrite /ltmx submx1 andbF. Qed. Lemma pinvmxE n (A : 'M[F]_n) : A \in unitmx -> pinvmx A = invmx A. Proof. move=> A_unit; apply: (@row_free_inj _ _ _ A); rewrite ?row_free_unit//. by rewrite -[pinvmx _]mul1mx mulmxKpV ?sub1mx ?row_full_unit// mulVmx. Qed. Lemma mulVpmx m n (A : 'M[F]_(m, n)) : row_full A -> pinvmx A *m A = 1%:M. Proof. by move=> fA; rewrite -[pinvmx _]mul1mx mulmxKpV// sub1mx. Qed. Lemma pinvmx_free m n (A : 'M[F]_(m, n)) : row_full A -> row_free (pinvmx A). Proof. by move=> /mulVpmx pAA1; apply/row_freeP; exists A. Qed. Lemma pinvmx_full m n (A : 'M[F]_(m, n)) : row_free A -> row_full (pinvmx A). Proof. by move=> /mulmxVp ApA1; apply/row_fullP; exists A. Qed. Lemma eqmxP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :=: B)%MS (A == B)%MS. Proof. apply: (iffP andP) => [[sAB sBA] | eqAB]; last by rewrite !eqAB. split=> [|m3 C]; first by apply/eqP; rewrite eqn_leq !mxrankS. split; first by apply/idP/idP; apply: submx_trans. by apply/idP/idP=> sC; apply: submx_trans sC _. Qed. Arguments eqmxP {m1 m2 n A B}. Lemma rV_eqP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (forall u : 'rV_n, (u <= A) = (u <= B))%MS (A == B)%MS. Proof. apply: (iffP idP) => [eqAB u | eqAB]; first by rewrite (eqmxP eqAB). by apply/andP; split; apply/rV_subP=> u; rewrite eqAB. Qed. Lemma mulmxP (m n : nat) (A B : 'M[F]_(m, n)) : reflect (forall u : 'rV_m, u *m A = u *m B) (A == B). Proof. apply: (iffP eqP) => [-> //|eqAB]. apply: (@row_full_inj _ _ _ 1%:M); first by rewrite row_full_unit unitmx1. by apply/row_matrixP => i; rewrite !row_mul eqAB. Qed. Lemma eqmx_refl m1 n (A : 'M_(m1, n)) : (A :=: A)%MS. Proof. by []. Qed. Lemma eqmx_sym m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> (B :=: A)%MS. Proof. by move=> eqAB; split=> [|m3 C]; rewrite !eqAB. Qed. Lemma eqmx_trans m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A :=: B)%MS -> (B :=: C)%MS -> (A :=: C)%MS. Proof. by move=> eqAB eqBC; split=> [|m4 D]; rewrite !eqAB !eqBC. Qed. Lemma eqmx_rank m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A == B)%MS -> \rank A = \rank B. Proof. by move/eqmxP->. Qed. Lemma lt_eqmx m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> forall C : 'M_(m3, n), (((A < C) = (B < C))%MS * ((C < A) = (C < B))%MS)%type. Proof. by move=> eqAB C; rewrite /ltmx !eqAB. Qed. Lemma eqmxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : (A :=: B)%MS -> (A *m C :=: B *m C)%MS. Proof. by move=> eqAB; apply/eqmxP; rewrite !submxMr ?eqAB. Qed. Lemma eqmxMfull m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : row_full A -> (A *m B :=: B)%MS. Proof. case/row_fullP=> A' A'A; apply/eqmxP; rewrite submxMl /=. by apply/submxP; exists A'; rewrite mulmxA A'A mul1mx. Qed. Lemma eqmx0 m n : ((0 : 'M[F]_(m, n)) :=: (0 : 'M_n))%MS. Proof. by apply/eqmxP; rewrite !sub0mx. Qed. Lemma eqmx_scale m n a (A : 'M_(m, n)) : a != 0 -> (a *: A :=: A)%MS. Proof. move=> nz_a; apply/eqmxP; rewrite scalemx_sub //. by rewrite -{1}[A]scale1r -(mulVf nz_a) -scalerA scalemx_sub. Qed. Lemma eqmx_opp m n (A : 'M_(m, n)) : (- A :=: A)%MS. Proof. by rewrite -scaleN1r; apply: eqmx_scale => //; rewrite oppr_eq0 oner_eq0. Qed. Lemma submxMfree m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : row_free C -> (A *m C <= B *m C)%MS = (A <= B)%MS. Proof. case/row_freeP=> C' C_C'_1; apply/idP/idP=> sAB; last exact: submxMr. by rewrite -[A]mulmx1 -[B]mulmx1 -C_C'_1 !mulmxA submxMr. Qed. Lemma eqmxMfree m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : row_free C -> (A *m C :=: B *m C)%MS -> (A :=: B)%MS. Proof. by move=> Cfree eqAB; apply/eqmxP; move/eqmxP: eqAB; rewrite !submxMfree. Qed. Lemma mxrankMfree m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : row_free B -> \rank (A *m B) = \rank A. Proof. by move=> Bfree; rewrite -mxrank_tr trmx_mul eqmxMfull /row_full mxrank_tr. Qed. Lemma eq_row_base m n (A : 'M_(m, n)) : (row_base A :=: A)%MS. Proof. apply/eqmxP/andP; split; apply/submxP. exists (pid_mx (\rank A) *m invmx (col_ebase A)). by rewrite -{8}[A]mulmx_ebase !mulmxA mulmxKV // pid_mx_id. exists (col_ebase A *m pid_mx (\rank A)). by rewrite mulmxA -(mulmxA _ _ (pid_mx _)) pid_mx_id // mulmx_ebase. Qed. Lemma row_base0 (m n : nat) : row_base (0 : 'M[F]_(m, n)) = 0. Proof. by apply/eqmx0P; rewrite !eq_row_base !sub0mx. Qed. Let qidmx_eq1 n (A : 'M_n) : qidmx A = (A == 1%:M). Proof. by rewrite /qidmx eqxx pid_mx_1. Qed. Let genmx_witnessP m n (A : 'M_(m, n)) : equivmx A (row_full A) (genmx_witness A). Proof. rewrite /equivmx qidmx_eq1 /genmx_witness. case fullA: (row_full A); first by rewrite eqxx sub1mx submx1 fullA. set B := _ *m _; have defB : (B == A)%MS. apply/andP; split; apply/submxP. exists (pid_mx (\rank A) *m invmx (col_ebase A)). by rewrite -{3}[A]mulmx_ebase !mulmxA mulmxKV // pid_mx_id. exists (col_ebase A *m pid_mx (\rank A)). by rewrite mulmxA -(mulmxA _ _ (pid_mx _)) pid_mx_id // mulmx_ebase. rewrite defB -negb_add addbF; case: eqP defB => // ->. by rewrite sub1mx fullA. Qed. Lemma genmxE m n (A : 'M_(m, n)) : (<<A>> :=: A)%MS. Proof. by rewrite unlock; apply/eqmxP; case/andP: (chooseP (genmx_witnessP A)). Qed. Lemma eq_genmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B -> <<A>> = <<B>>)%MS. Proof. move=> eqAB; rewrite unlock. have{} eqAB: equivmx A (row_full A) =1 equivmx B (row_full B). by move=> C; rewrite /row_full /equivmx !eqAB. rewrite (eq_choose eqAB) (choose_id _ (genmx_witnessP B)) //. by rewrite -eqAB genmx_witnessP. Qed. Lemma genmxP m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (<<A>> = <<B>>)%MS (A == B)%MS. Proof. apply: (iffP idP) => eqAB; first exact: eq_genmx (eqmxP _). by rewrite -!(genmxE A) eqAB !genmxE andbb. Qed. Arguments genmxP {m1 m2 n A B}. Lemma genmx0 m n : <<0 : 'M_(m, n)>>%MS = 0. Proof. by apply/eqP; rewrite -submx0 genmxE sub0mx. Qed. Lemma genmx1 n : <<1%:M : 'M_n>>%MS = 1%:M. Proof. rewrite unlock; case/andP: (chooseP (@genmx_witnessP n n 1%:M)) => _ /eqP. by rewrite qidmx_eq1 row_full_unit unitmx1 => /eqP. Qed. Lemma genmx_id m n (A : 'M_(m, n)) : (<<<<A>>>> = <<A>>)%MS. Proof. exact/eq_genmx/genmxE. Qed. Lemma row_base_free m n (A : 'M_(m, n)) : row_free (row_base A). Proof. by apply/eqnP; rewrite eq_row_base. Qed. Lemma mxrank_gen m n (A : 'M_(m, n)) : \rank <<A>>%MS = \rank A. Proof. by rewrite genmxE. Qed. Lemma col_base_full m n (A : 'M_(m, n)) : row_full (col_base A). Proof. apply/row_fullP; exists (pid_mx (\rank A) *m invmx (col_ebase A)). by rewrite !mulmxA mulmxKV // pid_mx_id // pid_mx_1. Qed. Hint Resolve row_base_free col_base_full : core. Lemma mxrank_leqif_sup m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> \rank A <= \rank B ?= iff (B <= A)%MS. Proof. move=> sAB; split; first by rewrite mxrankS. apply/idP/idP=> [| sBA]; last by rewrite eqn_leq !mxrankS. case/submxP: sAB => D ->; set r := \rank B; rewrite -(mulmx_base B) mulmxA. rewrite mxrankMfree // => /row_fullP[E kE]. by rewrite -[rB in _ *m rB]mul1mx -kE -(mulmxA E) (mulmxA _ E) submxMl. Qed. Lemma mxrank_leqif_eq m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A <= B)%MS -> \rank A <= \rank B ?= iff (A == B)%MS. Proof. by move=> sAB; rewrite sAB; apply: mxrank_leqif_sup. Qed. Lemma ltmxErank m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A < B)%MS = (A <= B)%MS && (\rank A < \rank B). Proof. by apply: andb_id2l => sAB; rewrite (ltn_leqif (mxrank_leqif_sup sAB)). Qed. Lemma rank_ltmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A < B)%MS -> \rank A < \rank B. Proof. by rewrite ltmxErank => /andP[]. Qed. Lemma eqmx_cast m1 m2 n (A : 'M_(m1, n)) e : ((castmx e A : 'M_(m2, n)) :=: A)%MS. Proof. by case: e A; case: m2 / => A e; rewrite castmx_id. Qed. Lemma row_full_castmx m1 m2 n (A : 'M_(m1, n)) e : row_full (castmx e A : 'M_(m2, n)) = row_full A. Proof. exact/eq_row_full/eqmx_cast. Qed. Lemma row_free_castmx m1 m2 n (A : 'M_(m1, n)) e : row_free (castmx e A : 'M_(m2, n)) = row_free A. Proof. by rewrite /row_free eqmx_cast; congr (_ == _); rewrite e.1. Qed. Lemma eqmx_conform m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (conform_mx A B :=: A \/ conform_mx A B :=: B)%MS. Proof. case: (eqVneq m2 m1) => [-> | neqm12] in B *. by right; rewrite conform_mx_id. by left; rewrite nonconform_mx ?neqm12. Qed. Let eqmx_sum_nop m n (A : 'M_(m, n)) : (addsmx_nop A :=: A)%MS. Proof. case: (eqmx_conform <<A>>%MS A) => // eq_id_gen. exact: eqmx_trans (genmxE A). Qed. Lemma rowsub_comp_sub (m n p q : nat) f (g : 'I_n -> 'I_p) (A : 'M_(m, q)) : (rowsub (f \o g) A <= rowsub f A)%MS. Proof. by rewrite rowsub_comp rowsubE mulmx_sub. Qed. Lemma submx_rowsub (m n p q : nat) (h : 'I_n -> 'I_p) f g (A : 'M_(m, q)) : f =1 g \o h -> (rowsub f A <= rowsub g A)%MS. Proof. by move=> /eq_rowsub->; rewrite rowsub_comp_sub. Qed. Arguments submx_rowsub [m1 m2 m3 n] h [f g A] _ : rename. Lemma eqmx_rowsub_comp_perm (m1 m2 n : nat) (s : 'S_m2) f (A : 'M_(m1, n)) : (rowsub (f \o s) A :=: rowsub f A)%MS. Proof. rewrite rowsub_comp rowsubE; apply: eqmxMfull. by rewrite -perm_mxEsub row_full_unit unitmx_perm. Qed. Lemma eqmx_rowsub_comp (m n p q : nat) f (g : 'I_n -> 'I_p) (A : 'M_(m, q)) : p <= n -> injective g -> (rowsub (f \o g) A :=: rowsub f A)%MS. Proof. move=> leq_pn g_inj; have eq_np : n == p by rewrite eqn_leq leq_pn (inj_leq g). rewrite (eqP eq_np) in g g_inj *. rewrite (eq_rowsub (f \o (perm g_inj))); last by move=> i; rewrite /= permE. exact: eqmx_rowsub_comp_perm. Qed. Lemma eqmx_rowsub (m n p q : nat) (h : 'I_n -> 'I_p) f g (A : 'M_(m, q)) : injective h -> p <= n -> f =1 g \o h -> (rowsub f A :=: rowsub g A)%MS. Proof. by move=> leq_pn h_inj /eq_rowsub->; apply: eqmx_rowsub_comp. Qed. Arguments eqmx_rowsub [m1 m2 m3 n] h [f g A] _ : rename. Section AddsmxSub. Variable (m1 m2 n : nat) (A : 'M[F]_(m1, n)) (B : 'M[F]_(m2, n)). Lemma col_mx_sub m3 (C : 'M_(m3, n)) : (col_mx A B <= C)%MS = (A <= C)%MS && (B <= C)%MS. Proof. rewrite !submxE mul_col_mx -col_mx0. by apply/eqP/andP; [case/eq_col_mx=> -> -> | case; do 2!move/eqP->]. Qed. Lemma addsmxE : (A + B :=: col_mx A B)%MS. Proof. have:= submx_refl (col_mx A B); rewrite col_mx_sub; case/andP=> sAS sBS. rewrite unlock; do 2?case: eqP => [AB0 | _]; last exact: genmxE. by apply/eqmxP; rewrite !eqmx_sum_nop sBS col_mx_sub AB0 sub0mx /=. by apply/eqmxP; rewrite !eqmx_sum_nop sAS col_mx_sub AB0 sub0mx andbT /=. Qed. Lemma addsmx_sub m3 (C : 'M_(m3, n)) : (A + B <= C)%MS = (A <= C)%MS && (B <= C)%MS. Proof. by rewrite addsmxE col_mx_sub. Qed. Lemma addsmxSl : (A <= A + B)%MS. Proof. by have:= submx_refl (A + B)%MS; rewrite addsmx_sub; case/andP. Qed. Lemma addsmxSr : (B <= A + B)%MS. Proof. by have:= submx_refl (A + B)%MS; rewrite addsmx_sub; case/andP. Qed. Lemma addsmx_idPr : reflect (A + B :=: B)%MS (A <= B)%MS. Proof. have:= @eqmxP _ _ _ (A + B)%MS B. by rewrite addsmxSr addsmx_sub submx_refl !andbT. Qed. Lemma addsmx_idPl : reflect (A + B :=: A)%MS (B <= A)%MS. Proof. have:= @eqmxP _ _ _ (A + B)%MS A. by rewrite addsmxSl addsmx_sub submx_refl !andbT. Qed. End AddsmxSub. Lemma adds0mx m1 m2 n (B : 'M_(m2, n)) : ((0 : 'M_(m1, n)) + B :=: B)%MS. Proof. by apply/eqmxP; rewrite addsmx_sub sub0mx addsmxSr /= andbT. Qed. Lemma addsmx0 m1 m2 n (A : 'M_(m1, n)) : (A + (0 : 'M_(m2, n)) :=: A)%MS. Proof. by apply/eqmxP; rewrite addsmx_sub sub0mx addsmxSl /= !andbT. Qed. Let addsmx_nop_eq0 m n (A : 'M_(m, n)) : (addsmx_nop A == 0) = (A == 0). Proof. by rewrite -!submx0 eqmx_sum_nop. Qed. Let addsmx_nop0 m n : addsmx_nop (0 : 'M_(m, n)) = 0. Proof. by apply/eqP; rewrite addsmx_nop_eq0. Qed. Let addsmx_nop_id n (A : 'M_n) : addsmx_nop A = A. Proof. exact: conform_mx_id. Qed. Lemma addsmxC m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A + B = B + A)%MS. Proof. have: (A + B == B + A)%MS. by apply/andP; rewrite !addsmx_sub andbC -addsmx_sub andbC -addsmx_sub. move/genmxP; rewrite [@addsmx]unlock -!submx0 !submx0. by do 2!case: eqP => [// -> | _]; rewrite ?genmx_id ?addsmx_nop0. Qed. Lemma adds0mx_id m1 n (B : 'M_n) : ((0 : 'M_(m1, n)) + B)%MS = B. Proof. by rewrite unlock eqxx addsmx_nop_id. Qed. Lemma addsmx0_id m2 n (A : 'M_n) : (A + (0 : 'M_(m2, n)))%MS = A. Proof. by rewrite addsmxC adds0mx_id. Qed. Lemma addsmxA m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A + (B + C) = A + B + C)%MS. Proof. have: (A + (B + C) :=: A + B + C)%MS. by apply/eqmxP/andP; rewrite !addsmx_sub -andbA andbA -!addsmx_sub. rewrite {1 3}[in @addsmx _ m1]unlock [in @addsmx _ n]unlock !addsmx_nop_id -!submx0. rewrite !addsmx_sub ![@addsmx]unlock -!submx0; move/eq_genmx. by do 3!case: (_ <= 0)%MS; rewrite //= !genmx_id. Qed. HB.instance Definition _ n := Monoid.isComLaw.Build (matrix F n n) 0%MS addsmx.body (@addsmxA n n n n) (@addsmxC n n n) (@adds0mx_id n n). Lemma addsmxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : ((A + B)%MS *m C :=: A *m C + B *m C)%MS. Proof. by apply/eqmxP; rewrite !addsmxE -!mul_col_mx !submxMr ?addsmxE. Qed. Lemma addsmxS m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A <= C -> B <= D -> A + B <= C + D)%MS. Proof. move=> sAC sBD. by rewrite addsmx_sub {1}addsmxC !(submx_trans _ (addsmxSr _ _)). Qed. Lemma addmx_sub_adds m m1 m2 n (A : 'M_(m, n)) (B : 'M_(m, n)) (C : 'M_(m1, n)) (D : 'M_(m2, n)) : (A <= C -> B <= D -> (A + B)%R <= C + D)%MS. Proof. move=> sAC; move/(addsmxS sAC); apply: submx_trans. by rewrite addmx_sub ?addsmxSl ?addsmxSr. Qed. Lemma addsmx_addKl n m1 m2 (A : 'M_(m1, n)) (B C : 'M_(m2, n)) : (B <= A)%MS -> (A + (B + C)%R :=: A + C)%MS. Proof. move=> sBA; apply/eqmxP; rewrite !addsmx_sub !addsmxSl. by rewrite -{3}[C](addKr B) !addmx_sub_adds ?eqmx_opp. Qed. Lemma addsmx_addKr n m1 m2 (A B : 'M_(m1, n)) (C : 'M_(m2, n)) : (B <= C)%MS -> ((A + B)%R + C :=: A + C)%MS. Proof. by rewrite -!(addsmxC C) addrC; apply: addsmx_addKl. Qed. Lemma adds_eqmx m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A :=: C -> B :=: D -> A + B :=: C + D)%MS. Proof. by move=> eqAC eqBD; apply/eqmxP; rewrite !addsmxS ?eqAC ?eqBD. Qed. Lemma genmx_adds m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (<<(A + B)%MS>> = <<A>> + <<B>>)%MS. Proof. rewrite -(eq_genmx (adds_eqmx (genmxE A) (genmxE B))). by rewrite [@addsmx]unlock !addsmx_nop_id !(fun_if (@genmx _ _ _)) !genmx_id. Qed. Lemma sub_addsmxP m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : reflect (exists u, A = u.1 *m B + u.2 *m C) (A <= B + C)%MS. Proof. apply: (iffP idP) => [|[u ->]]; last by rewrite addmx_sub_adds ?submxMl. rewrite addsmxE; case/submxP=> u ->; exists (lsubmx u, rsubmx u). by rewrite -mul_row_col hsubmxK. Qed. Arguments sub_addsmxP {m1 m2 m3 n A B C}. Variable I : finType. Implicit Type P : pred I. Lemma genmx_sums P n (B_ : I -> 'M_n) : <<(\sum_(i | P i) B_ i)%MS>>%MS = (\sum_(i | P i) <<B_ i>>)%MS. Proof. exact: (big_morph _ (@genmx_adds n n n) (@genmx0 n n)). Qed. Lemma sumsmx_sup i0 P m n (A : 'M_(m, n)) (B_ : I -> 'M_n) : P i0 -> (A <= B_ i0)%MS -> (A <= \sum_(i | P i) B_ i)%MS. Proof. by move=> Pi0 sAB; apply: submx_trans sAB _; rewrite (bigD1 i0) // addsmxSl. Qed. Arguments sumsmx_sup i0 [P m n A B_]. Lemma sumsmx_subP P m n (A_ : I -> 'M_n) (B : 'M_(m, n)) : reflect (forall i, P i -> A_ i <= B)%MS (\sum_(i | P i) A_ i <= B)%MS. Proof. apply: (iffP idP) => [sAB i Pi | sAB]. by apply: submx_trans sAB; apply: sumsmx_sup Pi _. by elim/big_rec: _ => [|i Ai Pi sAiB]; rewrite ?sub0mx // addsmx_sub sAB. Qed. Lemma summx_sub_sums P m n (A : I -> 'M[F]_(m, n)) B : (forall i, P i -> A i <= B i)%MS -> ((\sum_(i | P i) A i)%R <= \sum_(i | P i) B i)%MS. Proof. by move=> sAB; apply: summx_sub => i Pi; rewrite (sumsmx_sup i) ?sAB. Qed. Lemma sumsmxS P n (A B : I -> 'M[F]_n) : (forall i, P i -> A i <= B i)%MS -> (\sum_(i | P i) A i <= \sum_(i | P i) B i)%MS. Proof. by move=> sAB; apply/sumsmx_subP=> i Pi; rewrite (sumsmx_sup i) ?sAB. Qed. Lemma eqmx_sums P n (A B : I -> 'M[F]_n) : (forall i, P i -> A i :=: B i)%MS -> (\sum_(i | P i) A i :=: \sum_(i | P i) B i)%MS. Proof. by move=> eqAB; apply/eqmxP; rewrite !sumsmxS // => i; move/eqAB->. Qed. Lemma sub_sums_genmxP P m n p (A : 'M_(m, p)) (B_ : I -> 'M_(n, p)) : reflect (exists u_ : I -> 'M_(m, n), A = \sum_(i | P i) u_ i *m B_ i) (A <= \sum_(i | P i) <<B_ i>>)%MS. Proof. apply: (iffP idP) => [| [u_ ->]]; last first. by apply: summx_sub_sums => i _; rewrite genmxE; apply: submxMl. have [b] := ubnP #|P|; elim: b => // b IHb in P A *. case: (pickP P) => [i Pi | P0 _]; last first. rewrite big_pred0 //; move/submx0null->. by exists (fun _ => 0); rewrite big_pred0. rewrite (cardD1x Pi) (bigD1 i) //= => /IHb{b IHb} /= IHi. rewrite (adds_eqmx (genmxE _) (eqmx_refl _)) => /sub_addsmxP[u ->]. have [u_ ->] := IHi _ (submxMl u.2 _). exists [eta u_ with i |-> u.1]; rewrite (bigD1 i Pi)/= eqxx; congr (_ + _). by apply: eq_bigr => j /andP[_ /negPf->]. Qed. Lemma sub_sumsmxP P m n (A : 'M_(m, n)) (B_ : I -> 'M_n) : reflect (exists u_, A = \sum_(i | P i) u_ i *m B_ i) (A <= \sum_(i | P i) B_ i)%MS. Proof. by rewrite -(eqmx_sums (fun _ _ => genmxE _)); apply/sub_sums_genmxP. Qed. Lemma sumsmxMr_gen P m n A (B : 'M[F]_(m, n)) : ((\sum_(i | P i) A i)%MS *m B :=: \sum_(i | P i) <<A i *m B>>)%MS. Proof. apply/eqmxP/andP; split; last first. by apply/sumsmx_subP=> i Pi; rewrite genmxE submxMr ?(sumsmx_sup i). have [u ->] := sub_sumsmxP _ _ _ (submx_refl (\sum_(i | P i) A i)%MS). by rewrite mulmx_suml summx_sub_sums // => i _; rewrite genmxE -mulmxA submxMl. Qed. Lemma sumsmxMr P n (A_ : I -> 'M[F]_n) (B : 'M_n) : ((\sum_(i | P i) A_ i)%MS *m B :=: \sum_(i | P i) (A_ i *m B))%MS. Proof. by apply: eqmx_trans (sumsmxMr_gen _ _ _) (eqmx_sums _) => i _; apply: genmxE. Qed. Lemma rank_pid_mx m n r : r <= m -> r <= n -> \rank (pid_mx r : 'M_(m, n)) = r. Proof. do 2!move/subnKC <-; rewrite pid_mx_block block_mxEv row_mx0 -addsmxE addsmx0. by rewrite -mxrank_tr tr_row_mx trmx0 trmx1 -addsmxE addsmx0 mxrank1. Qed. Lemma rank_copid_mx n r : r <= n -> \rank (copid_mx r : 'M_n) = (n - r)%N. Proof. move/subnKC <-; rewrite /copid_mx pid_mx_block scalar_mx_block. rewrite opp_block_mx !oppr0 add_block_mx !addr0 subrr block_mxEv row_mx0. rewrite -addsmxE adds0mx -mxrank_tr tr_row_mx trmx0 trmx1. by rewrite -addsmxE adds0mx mxrank1 addKn. Qed. Lemma mxrank_compl m n (A : 'M_(m, n)) : \rank A^C = (n - \rank A)%N. Proof. by rewrite mxrankMfree ?row_free_unit ?rank_copid_mx. Qed. Lemma mxrank_ker m n (A : 'M_(m, n)) : \rank (kermx A) = (m - \rank A)%N. Proof. by rewrite mxrankMfree ?row_free_unit ?unitmx_inv ?rank_copid_mx. Qed. Lemma kermx_eq0 n m (A : 'M_(m, n)) : (kermx A == 0) = row_free A. Proof. by rewrite -mxrank_eq0 mxrank_ker subn_eq0 row_leq_rank. Qed. Lemma mxrank_coker m n (A : 'M_(m, n)) : \rank (cokermx A) = (n - \rank A)%N. Proof. by rewrite eqmxMfull ?row_full_unit ?unitmx_inv ?rank_copid_mx. Qed. Lemma cokermx_eq0 n m (A : 'M_(m, n)) : (cokermx A == 0) = row_full A. Proof. by rewrite -mxrank_eq0 mxrank_coker subn_eq0 col_leq_rank. Qed. Lemma mulmx_ker m n (A : 'M_(m, n)) : kermx A *m A = 0. Proof. by rewrite -{2}[A]mulmx_ebase !mulmxA mulmxKV // mul_copid_mx_pid ?mul0mx. Qed. Lemma mulmxKV_ker m n p (A : 'M_(n, p)) (B : 'M_(m, n)) : B *m A = 0 -> B *m col_ebase A *m kermx A = B. Proof. rewrite mulmxA mulmxBr mulmx1 mulmxBl mulmxK //. rewrite -{1}[A]mulmx_ebase !mulmxA => /(canRL (mulmxK (row_ebase_unit A))). rewrite mul0mx // => BA0; apply: (canLR (addrK _)). by rewrite -(pid_mx_id _ _ n (rank_leq_col A)) mulmxA BA0 !mul0mx addr0. Qed. Lemma sub_kermxP p m n (A : 'M_(m, n)) (B : 'M_(p, m)) : reflect (B *m A = 0) (B <= kermx A)%MS. Proof. apply: (iffP submxP) => [[D ->]|]; first by rewrite -mulmxA mulmx_ker mulmx0. by move/mulmxKV_ker; exists (B *m col_ebase A). Qed. Lemma sub_kermx p m n (A : 'M_(m, n)) (B : 'M_(p, m)) : (B <= kermx A)%MS = (B *m A == 0). Proof. exact/sub_kermxP/eqP. Qed. Lemma kermx0 m n : (kermx (0 : 'M_(m, n)) :=: 1%:M)%MS. Proof. by apply/eqmxP; rewrite submx1/= sub_kermx mulmx0. Qed. Lemma mulmx_free_eq0 m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : row_free B -> (A *m B == 0) = (A == 0). Proof. by rewrite -sub_kermx -kermx_eq0 => /eqP->; rewrite submx0. Qed. Lemma inj_row_free m n (A : 'M_(m, n)) : (forall v : 'rV_m, v *m A = 0 -> v = 0) -> row_free A. Proof. move=> Ainj; rewrite -kermx_eq0; apply/eqP/row_matrixP => i. by rewrite row0; apply/Ainj; rewrite -row_mul mulmx_ker row0. Qed. Lemma row_freePn m n (M : 'M[F]_(m, n)) : reflect (exists i, (row i M <= row' i M)%MS) (~~ row_free M). Proof. rewrite -kermx_eq0; apply: (iffP (rowV0Pn _)) => [|[i0 /submxP[D rM]]]. move=> [v /sub_kermxP vM_eq0 /rV0Pn[i0 vi0_neq0]]; exists i0. have := vM_eq0; rewrite mulmx_sum_row (bigD1_ord i0)//=. move=> /(canRL (addrK _))/(canRL (scalerK _))->//. rewrite sub0r scalerN -scaleNr scalemx_sub// summx_sub// => l _. by rewrite scalemx_sub// -row_rowsub row_sub. exists (\row_j oapp (D 0) (- 1) (unlift i0 j)); last first. by apply/rV0Pn; exists i0; rewrite !mxE unlift_none/= oppr_eq0 oner_eq0. apply/sub_kermxP; rewrite mulmx_sum_row (bigD1_ord i0)//= !mxE. rewrite unlift_none scaleN1r rM mulmx_sum_row addrC -sumrB big1 // => l _. by rewrite !mxE liftK row_rowsub subrr. Qed. Lemma negb_row_free m n (M : 'M[F]_(m, n)) : ~~ row_free M = [exists i, (row i M <= row' i M)%MS]. Proof. exact/row_freePn/existsP. Qed. Lemma mulmx0_rank_max m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : A *m B = 0 -> \rank A + \rank B <= n. Proof. move=> AB0; rewrite -{3}(subnK (rank_leq_row B)) leq_add2r. by rewrite -mxrank_ker mxrankS // sub_kermx AB0. Qed. Lemma mxrank_Frobenius m n p q (A : 'M_(m, n)) B (C : 'M_(p, q)) : \rank (A *m B) + \rank (B *m C) <= \rank B + \rank (A *m B *m C). Proof. rewrite -{2}(mulmx_base (A *m B)) -mulmxA (eqmxMfull _ (col_base_full _)). set C2 := row_base _ *m C. rewrite -{1}(subnK (rank_leq_row C2)) -(mxrank_ker C2) addnAC leq_add2r. rewrite addnC -{1}(mulmx_base B) -mulmxA eqmxMfull //. set C1 := _ *m C; rewrite -{2}(subnKC (rank_leq_row C1)) leq_add2l -mxrank_ker. rewrite -(mxrankMfree _ (row_base_free (A *m B))). have: (row_base (A *m B) <= row_base B)%MS by rewrite !eq_row_base submxMl. case/submxP=> D defD; rewrite defD mulmxA mxrankMfree ?mxrankS //. by rewrite sub_kermx -mulmxA (mulmxA D) -defD -/C2 mulmx_ker. Qed. Lemma mxrank_mul_min m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : \rank A + \rank B - n <= \rank (A *m B). Proof. by have:= mxrank_Frobenius A 1%:M B; rewrite mulmx1 mul1mx mxrank1 leq_subLR. Qed. Lemma addsmx_compl_full m n (A : 'M_(m, n)) : row_full (A + A^C)%MS. Proof. rewrite /row_full addsmxE; apply/row_fullP. exists (row_mx (pinvmx A) (cokermx A)); rewrite mul_row_col. rewrite -{2}[A]mulmx_ebase -!mulmxA mulKmx // -mulmxDr !mulmxA. by rewrite pid_mx_id ?copid_mx_id // -mulmxDl addrC subrK mul1mx mulVmx. Qed. Lemma sub_capmx_gen m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= capmx_gen B C)%MS = (A <= B)%MS && (A <= C)%MS. Proof. apply/idP/andP=> [sAI | [/submxP[B' ->{A}] /submxP[C' eqBC']]]. rewrite !(submx_trans sAI) ?submxMl // /capmx_gen. have:= mulmx_ker (col_mx B C); set K := kermx _. rewrite -{1}[K]hsubmxK mul_row_col; move/(canRL (addrK _))->. by rewrite add0r -mulNmx submxMl. have: (row_mx B' (- C') <= kermx (col_mx B C))%MS. by rewrite sub_kermx mul_row_col eqBC' mulNmx subrr. case/submxP=> D; rewrite -[kermx _]hsubmxK mul_mx_row. by case/eq_row_mx=> -> _; rewrite -mulmxA submxMl. Qed. Let capmx_witnessP m n (A : 'M_(m, n)) : equivmx A (qidmx A) (capmx_witness A). Proof. rewrite /equivmx qidmx_eq1 /qidmx /capmx_witness. rewrite -sub1mx; case s1A: (1%:M <= A)%MS => /=; last first. rewrite !genmxE submx_refl /= -negb_add; apply: contra {s1A}(negbT s1A). have [<- | _] := eqP; first by rewrite genmxE. by case: eqP A => //= -> A /eqP ->; rewrite pid_mx_1. case: (m =P n) => [-> | ne_mn] in A s1A *. by rewrite conform_mx_id submx_refl pid_mx_1 eqxx. by rewrite nonconform_mx ?submx1 ?s1A ?eqxx //; case: eqP. Qed. Let capmx_normP m n (A : 'M_(m, n)) : equivmx_spec A (qidmx A) (capmx_norm A). Proof. by case/andP: (chooseP (capmx_witnessP A)) => /eqmxP defN /eqP. Qed. Let capmx_norm_eq m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx A = qidmx B -> (A == B)%MS -> capmx_norm A = capmx_norm B. Proof. move=> eqABid /eqmxP eqAB. have{eqABid} eqAB: equivmx A (qidmx A) =1 equivmx B (qidmx B). by move=> C; rewrite /equivmx eqABid !eqAB. rewrite {1}/capmx_norm (eq_choose eqAB). by apply: choose_id; first rewrite -eqAB; apply: capmx_witnessP. Qed. Let capmx_nopP m n (A : 'M_(m, n)) : equivmx_spec A (qidmx A) (capmx_nop A). Proof. rewrite /capmx_nop; case: (eqVneq m n) => [-> | ne_mn] in A *. by rewrite conform_mx_id. by rewrite nonconform_mx ?ne_mn //; apply: capmx_normP. Qed. Let sub_qidmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx B -> (A <= B)%MS. Proof. rewrite /qidmx => idB; apply: {A}submx_trans (submx1 A) _. by case: eqP B idB => [-> _ /eqP-> | _ B]; rewrite (=^~ sub1mx, pid_mx_1). Qed. Let qidmx_cap m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx (A :&: B)%MS = qidmx A && qidmx B. Proof. rewrite unlock -sub1mx. case idA: (qidmx A); case idB: (qidmx B); try by rewrite capmx_nopP. case s1B: (_ <= B)%MS; first by rewrite capmx_normP. apply/idP=> /(sub_qidmx 1%:M). by rewrite capmx_normP sub_capmx_gen s1B andbF. Qed. Let capmx_eq_norm m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : qidmx A = qidmx B -> (A :&: B)%MS = capmx_norm (A :&: B)%MS. Proof. move=> eqABid; rewrite unlock -sub1mx {}eqABid. have norm_id m (C : 'M_(m, n)) (N := capmx_norm C) : capmx_norm N = N. by apply: capmx_norm_eq; rewrite ?capmx_normP ?andbb. case idB: (qidmx B); last by case: ifP; rewrite norm_id. rewrite /capmx_nop; case: (eqVneq m2 n) => [-> | neqm2n] in B idB *. have idN := idB; rewrite -{1}capmx_normP !qidmx_eq1 in idN idB. by rewrite conform_mx_id (eqP idN) (eqP idB). by rewrite nonconform_mx ?neqm2n ?norm_id. Qed. Lemma capmxE m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B :=: capmx_gen A B)%MS. Proof. rewrite unlock -sub1mx; apply/eqmxP. have:= submx_refl (capmx_gen A B); rewrite !sub_capmx_gen => /andP[sIA sIB]. case idA: (qidmx A); first by rewrite !capmx_nopP submx_refl sub_qidmx. case idB: (qidmx B); first by rewrite !capmx_nopP submx_refl sub_qidmx. case s1B: (1%:M <= B)%MS; rewrite !capmx_normP ?sub_capmx_gen sIA ?sIB //=. by rewrite submx_refl (submx_trans (submx1 _)). Qed. Lemma capmxSl m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B <= A)%MS. Proof. by rewrite capmxE submxMl. Qed. Lemma sub_capmx m m1 m2 n (A : 'M_(m, n)) (B : 'M_(m1, n)) (C : 'M_(m2, n)) : (A <= B :&: C)%MS = (A <= B)%MS && (A <= C)%MS. Proof. by rewrite capmxE sub_capmx_gen. Qed. Lemma capmxC m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B = B :&: A)%MS. Proof. have [eqAB|] := eqVneq (qidmx A) (qidmx B). rewrite (capmx_eq_norm eqAB) (capmx_eq_norm (esym eqAB)). apply: capmx_norm_eq; first by rewrite !qidmx_cap andbC. by apply/andP; split; rewrite !sub_capmx andbC -sub_capmx. by rewrite negb_eqb !unlock => /addbP <-; case: (qidmx A). Qed. Lemma capmxSr m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B <= B)%MS. Proof. by rewrite capmxC capmxSl. Qed. Lemma capmx_idPr n m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :&: B :=: B)%MS (B <= A)%MS. Proof. have:= @eqmxP _ _ _ (A :&: B)%MS B. by rewrite capmxSr sub_capmx submx_refl !andbT. Qed. Lemma capmx_idPl n m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :&: B :=: A)%MS (A <= B)%MS. Proof. by rewrite capmxC; apply: capmx_idPr. Qed. Lemma capmxS m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A <= C -> B <= D -> A :&: B <= C :&: D)%MS. Proof. by move=> sAC sBD; rewrite sub_capmx {1}capmxC !(submx_trans (capmxSr _ _)). Qed. Lemma cap_eqmx m1 m2 m3 m4 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) (D : 'M_(m4, n)) : (A :=: C -> B :=: D -> A :&: B :=: C :&: D)%MS. Proof. by move=> eqAC eqBD; apply/eqmxP; rewrite !capmxS ?eqAC ?eqBD. Qed. Lemma capmxMr m1 m2 n p (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(n, p)) : ((A :&: B) *m C <= A *m C :&: B *m C)%MS. Proof. by rewrite sub_capmx !submxMr ?capmxSl ?capmxSr. Qed. Lemma cap0mx m1 m2 n (A : 'M_(m2, n)) : ((0 : 'M_(m1, n)) :&: A)%MS = 0. Proof. exact: submx0null (capmxSl _ _). Qed. Lemma capmx0 m1 m2 n (A : 'M_(m1, n)) : (A :&: (0 : 'M_(m2, n)))%MS = 0. Proof. exact: submx0null (capmxSr _ _). Qed. Lemma capmxT m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : row_full B -> (A :&: B :=: A)%MS. Proof. rewrite -sub1mx => s1B; apply/eqmxP. by rewrite capmxSl sub_capmx submx_refl (submx_trans (submx1 A)). Qed. Lemma capTmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : row_full A -> (A :&: B :=: B)%MS. Proof. by move=> Afull; apply/eqmxP; rewrite capmxC !capmxT ?andbb. Qed. Let capmx_nop_id n (A : 'M_n) : capmx_nop A = A. Proof. by rewrite /capmx_nop conform_mx_id. Qed. Lemma cap1mx n (A : 'M_n) : (1%:M :&: A = A)%MS. Proof. by rewrite unlock qidmx_eq1 eqxx capmx_nop_id. Qed. Lemma capmx1 n (A : 'M_n) : (A :&: 1%:M = A)%MS. Proof. by rewrite capmxC cap1mx. Qed. Lemma genmx_cap m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : <<A :&: B>>%MS = (<<A>> :&: <<B>>)%MS. Proof. rewrite -(eq_genmx (cap_eqmx (genmxE A) (genmxE B))). case idAB: (qidmx <<A>> || qidmx <<B>>)%MS. rewrite [@capmx]unlock !capmx_nop_id !(fun_if (@genmx _ _ _)) !genmx_id. by case: (qidmx _) idAB => //= ->. case idA: (qidmx _) idAB => //= idB; rewrite {2}capmx_eq_norm ?idA //. set C := (_ :&: _)%MS; have eq_idC: row_full C = qidmx C. rewrite qidmx_cap idA -sub1mx sub_capmx genmxE; apply/andP=> [[s1A]]. by case/idP: idA; rewrite qidmx_eq1 -genmx1 (sameP eqP genmxP) submx1. rewrite unlock /capmx_norm eq_idC. by apply: choose_id (capmx_witnessP _); rewrite -eq_idC genmx_witnessP. Qed. Lemma capmxA m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A :&: (B :&: C) = A :&: B :&: C)%MS. Proof. rewrite (capmxC A B) capmxC; wlog idA: m1 m3 A C / qidmx A. move=> IH; case idA: (qidmx A); first exact: IH. case idC: (qidmx C); first by rewrite -IH. rewrite (@capmx_eq_norm n m3) ?qidmx_cap ?idA ?idC ?andbF //. rewrite capmx_eq_norm ?qidmx_cap ?idA ?idC ?andbF //. apply: capmx_norm_eq; first by rewrite !qidmx_cap andbAC. by apply/andP; split; rewrite !sub_capmx andbAC -!sub_capmx. rewrite -!(capmxC A) [in @capmx _ m1]unlock idA capmx_nop_id. have [eqBC|] := eqVneq (qidmx B) (qidmx C). rewrite (@capmx_eq_norm n) ?capmx_nopP // capmx_eq_norm //. by apply: capmx_norm_eq; rewrite ?qidmx_cap ?capmxS ?capmx_nopP. by rewrite !unlock capmx_nopP capmx_nop_id; do 2?case: (qidmx _) => //. Qed. HB.instance Definition _ n := Monoid.isComLaw.Build (matrix F n n) 1%:M capmx.body (@capmxA n n n n) (@capmxC n n n) (@cap1mx n). Lemma bigcapmx_inf i0 P m n (A_ : I -> 'M_n) (B : 'M_(m, n)) : P i0 -> (A_ i0 <= B -> \bigcap_(i | P i) A_ i <= B)%MS. Proof. by move=> Pi0; apply: submx_trans; rewrite (bigD1 i0) // capmxSl. Qed. Lemma sub_bigcapmxP P m n (A : 'M_(m, n)) (B_ : I -> 'M_n) : reflect (forall i, P i -> A <= B_ i)%MS (A <= \bigcap_(i | P i) B_ i)%MS. Proof. apply: (iffP idP) => [sAB i Pi | sAB]. by apply: (submx_trans sAB); rewrite (bigcapmx_inf Pi). by elim/big_rec: _ => [|i Pi C sAC]; rewrite ?submx1 // sub_capmx sAB. Qed. Lemma genmx_bigcap P n (A_ : I -> 'M_n) : (<<\bigcap_(i | P i) A_ i>> = \bigcap_(i | P i) <<A_ i>>)%MS. Proof. exact: (big_morph _ (@genmx_cap n n n) (@genmx1 n)). Qed. Lemma matrix_modl m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (A <= C -> A + (B :&: C) :=: (A + B) :&: C)%MS. Proof. move=> sAC; set D := ((A + B) :&: C)%MS; apply/eqmxP. rewrite sub_capmx addsmxS ?capmxSl // addsmx_sub sAC capmxSr /=. have: (D <= B + A)%MS by rewrite addsmxC capmxSl. case/sub_addsmxP=> u defD; rewrite defD addrC addmx_sub_adds ?submxMl //. rewrite sub_capmx submxMl -[_ *m B](addrK (u.2 *m A)) -defD. by rewrite addmx_sub ?capmxSr // eqmx_opp mulmx_sub. Qed. Lemma matrix_modr m1 m2 m3 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) (C : 'M_(m3, n)) : (C <= A -> (A :&: B) + C :=: A :&: (B + C))%MS. Proof. by rewrite !(capmxC A) -!(addsmxC C); apply: matrix_modl. Qed. Lemma capmx_compl m n (A : 'M_(m, n)) : (A :&: A^C)%MS = 0. Proof. set D := (A :&: A^C)%MS; have: (D <= D)%MS by []. rewrite sub_capmx andbC => /andP[/submxP[B defB]]. rewrite submxE => /eqP; rewrite defB -!mulmxA mulKVmx ?copid_mx_id //. by rewrite mulmxA => ->; rewrite mul0mx. Qed. Lemma mxrank_mul_ker m n p (A : 'M_(m, n)) (B : 'M_(n, p)) : (\rank (A *m B) + \rank (A :&: kermx B))%N = \rank A. Proof. apply/eqP; set K := kermx B; set C := (A :&: K)%MS. rewrite -(eqmxMr B (eq_row_base A)); set K' := _ *m B. rewrite -{2}(subnKC (rank_leq_row K')) -mxrank_ker eqn_add2l. rewrite -(mxrankMfree _ (row_base_free A)) mxrank_leqif_sup. by rewrite sub_capmx -(eq_row_base A) submxMl sub_kermx -mulmxA mulmx_ker/=. have /submxP[C' defC]: (C <= row_base A)%MS by rewrite eq_row_base capmxSl. by rewrite defC submxMr // sub_kermx mulmxA -defC -sub_kermx capmxSr. Qed. Lemma mxrank_injP m n p (A : 'M_(m, n)) (f : 'M_(n, p)) : reflect (\rank (A *m f) = \rank A) ((A :&: kermx f)%MS == 0). Proof. rewrite -mxrank_eq0 -(eqn_add2l (\rank (A *m f))). by rewrite mxrank_mul_ker addn0 eq_sym; apply: eqP. Qed. Lemma mxrank_disjoint_sum m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :&: B)%MS = 0 -> \rank (A + B)%MS = (\rank A + \rank B)%N. Proof. move=> AB0; pose Ar := row_base A; pose Br := row_base B. have [Afree Bfree]: row_free Ar /\ row_free Br by rewrite !row_base_free. have: (Ar :&: Br <= A :&: B)%MS by rewrite capmxS ?eq_row_base. rewrite {}AB0 submx0 -mxrank_eq0 capmxE mxrankMfree //. set Cr := col_mx Ar Br; set Crl := lsubmx _; rewrite mxrank_eq0 => /eqP Crl0. rewrite -(adds_eqmx (eq_row_base _) (eq_row_base _)) addsmxE -/Cr. suffices K0: kermx Cr = 0. by apply/eqP; rewrite eqn_leq rank_leq_row -subn_eq0 -mxrank_ker K0 mxrank0. move/eqP: (mulmx_ker Cr); rewrite -[kermx Cr]hsubmxK mul_row_col -/Crl Crl0. rewrite mul0mx add0r -mxrank_eq0 mxrankMfree // mxrank_eq0 => /eqP->. exact: row_mx0. Qed. Lemma diffmxE m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :\: B :=: A :&: (capmx_gen A B)^C)%MS. Proof. by rewrite unlock; apply/eqmxP; rewrite !genmxE !capmxE andbb. Qed. Lemma genmx_diff m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (<<A :\: B>> = A :\: B)%MS. Proof. by rewrite [@diffmx]unlock genmx_id. Qed. Lemma diffmxSl m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :\: B <= A)%MS. Proof. by rewrite diffmxE capmxSl. Qed. Lemma capmx_diff m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : ((A :\: B) :&: B)%MS = 0. Proof. apply/eqP; pose C := capmx_gen A B; rewrite -submx0 -(capmx_compl C). by rewrite sub_capmx -capmxE sub_capmx andbAC -sub_capmx -diffmxE -sub_capmx. Qed. Lemma addsmx_diff_cap_eq m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :\: B + A :&: B :=: A)%MS. Proof. apply/eqmxP; rewrite addsmx_sub capmxSl diffmxSl /=. set C := (A :\: B)%MS; set D := capmx_gen A B. suffices sACD: (A <= C + D)%MS. by rewrite (submx_trans sACD) ?addsmxS ?capmxE. have:= addsmx_compl_full D; rewrite /row_full addsmxE. case/row_fullP=> U /(congr1 (mulmx A)); rewrite mulmx1. rewrite -[U]hsubmxK mul_row_col mulmxDr addrC 2!mulmxA. set V := _ *m _ => defA; rewrite -defA; move/(canRL (addrK _)): defA => defV. suffices /submxP[W ->]: (V <= C)%MS by rewrite -mul_row_col addsmxE submxMl. rewrite diffmxE sub_capmx {1}defV -mulNmx addmx_sub 1?mulmx_sub //. by rewrite -capmxE capmxSl. Qed. Lemma mxrank_cap_compl m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (\rank (A :&: B) + \rank (A :\: B))%N = \rank A. Proof. rewrite addnC -mxrank_disjoint_sum ?addsmx_diff_cap_eq //. by rewrite (capmxC A) capmxA capmx_diff cap0mx. Qed. Lemma mxrank_sum_cap m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (\rank (A + B) + \rank (A :&: B) = \rank A + \rank B)%N. Proof. set C := (A :&: B)%MS; set D := (A :\: B)%MS. have rDB: \rank (A + B)%MS = \rank (D + B)%MS. apply/eqP; rewrite mxrank_leqif_sup; first by rewrite addsmxS ?diffmxSl. by rewrite addsmx_sub addsmxSr -(addsmx_diff_cap_eq A B) addsmxS ?capmxSr. rewrite {1}rDB mxrank_disjoint_sum ?capmx_diff //. by rewrite addnC addnA mxrank_cap_compl. Qed. Lemma mxrank_adds_leqif m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : \rank (A + B) <= \rank A + \rank B ?= iff (A :&: B <= (0 : 'M_n))%MS. Proof. rewrite -mxrank_sum_cap; split; first exact: leq_addr. by rewrite addnC (@eqn_add2r _ 0) eq_sym mxrank_eq0 -submx0. Qed. (* rank of block matrices with 0s inside *) Lemma rank_col_mx0 m n p (A : 'M_(m, n)) : \rank (col_mx A (0 : 'M_(p, n))) = \rank A. Proof. by rewrite -addsmxE addsmx0. Qed. Lemma rank_col_0mx m n p (A : 'M_(m, n)) : \rank (col_mx (0 : 'M_(p, n)) A) = \rank A. Proof. by rewrite -addsmxE adds0mx. Qed. Lemma rank_row_mx0 m n p (A : 'M_(m, n)) : \rank (row_mx A (0 : 'M_(m, p))) = \rank A. Proof. by rewrite -mxrank_tr -[RHS]mxrank_tr tr_row_mx trmx0 rank_col_mx0. Qed. Lemma rank_row_0mx m n p (A : 'M_(m, n)) : \rank (row_mx (0 : 'M_(m, p)) A) = \rank A. Proof. by rewrite -mxrank_tr -[RHS]mxrank_tr tr_row_mx trmx0 rank_col_0mx. Qed. Lemma rank_diag_block_mx m n p q (A : 'M_(m, n)) (B : 'M_(p, q)) : \rank (block_mx A 0 0 B) = (\rank A + \rank B)%N. Proof. rewrite block_mxEv -addsmxE mxrank_disjoint_sum ?rank_row_mx0 ?rank_row_0mx//. apply/eqP/rowV0P => v; rewrite sub_capmx => /andP[/submxP[x ->]]. rewrite mul_mx_row mulmx0 => /submxP[y]; rewrite mul_mx_row mulmx0. by move=> /eq_row_mx[-> _]; rewrite row_mx0. Qed. (* Subspace projection matrix *) Lemma proj_mx_sub m n U V (W : 'M_(m, n)) : (W *m proj_mx U V <= U)%MS. Proof. by rewrite !mulmx_sub // -addsmxE addsmx0. Qed. Lemma proj_mx_compl_sub m n U V (W : 'M_(m, n)) : (W <= U + V -> W - W *m proj_mx U V <= V)%MS. Proof. rewrite addsmxE => sWUV; rewrite mulmxA -{1}(mulmxKpV sWUV) -mulmxBr. by rewrite mulmx_sub // opp_col_mx add_col_mx subrr subr0 -addsmxE adds0mx. Qed. Lemma proj_mx_id m n U V (W : 'M_(m, n)) : (U :&: V = 0)%MS -> (W <= U)%MS -> W *m proj_mx U V = W. Proof. move=> dxUV sWU; apply/eqP; rewrite -subr_eq0 -submx0 -dxUV. rewrite sub_capmx addmx_sub ?eqmx_opp ?proj_mx_sub //= -eqmx_opp opprB. by rewrite proj_mx_compl_sub // (submx_trans sWU) ?addsmxSl. Qed. Lemma proj_mx_0 m n U V (W : 'M_(m, n)) : (U :&: V = 0)%MS -> (W <= V)%MS -> W *m proj_mx U V = 0. Proof. move=> dxUV sWV; apply/eqP; rewrite -submx0 -dxUV. rewrite sub_capmx proj_mx_sub /= -[_ *m _](subrK W) addmx_sub // -eqmx_opp. by rewrite opprB proj_mx_compl_sub // (submx_trans sWV) ?addsmxSr. Qed. Lemma add_proj_mx m n U V (W : 'M_(m, n)) : (U :&: V = 0)%MS -> (W <= U + V)%MS -> W *m proj_mx U V + W *m proj_mx V U = W. Proof. move=> dxUV sWUV; apply/eqP; rewrite -subr_eq0 -submx0 -dxUV. rewrite -addrA sub_capmx {2}addrCA -!(opprB W). by rewrite !{1}addmx_sub ?proj_mx_sub ?eqmx_opp ?proj_mx_compl_sub // addsmxC. Qed. Lemma proj_mx_proj n (U V : 'M_n) : let P := proj_mx U V in (U :&: V = 0)%MS -> P *m P = P. Proof. by move=> P dxUV; rewrite -[P in P *m _]mul1mx proj_mx_id ?proj_mx_sub ?mul1mx. Qed. (* Completing a partially injective matrix to get a unit matrix. *) Lemma complete_unitmx m n (U : 'M_(m, n)) (f : 'M_n) : \rank (U *m f) = \rank U -> {g : 'M_n | g \in unitmx & U *m f = U *m g}. Proof. move=> injfU; pose V := <<U>>%MS; pose W := V *m f. pose g := proj_mx V (V^C)%MS *m f + cokermx V *m row_ebase W. have defW: V *m g = W. rewrite mulmxDr mulmxA proj_mx_id ?genmxE ?capmx_compl //. by rewrite mulmxA mulmx_coker mul0mx addr0. exists g; last first. have /submxP[u ->]: (U <= V)%MS by rewrite genmxE. by rewrite -!mulmxA defW. rewrite -row_full_unit -sub1mx; apply/submxP. have: (invmx (col_ebase W) *m W <= V *m g)%MS by rewrite defW submxMl. case/submxP=> v def_v; exists (invmx (row_ebase W) *m (v *m V + (V^C)%MS)). rewrite -mulmxA mulmxDl -mulmxA -def_v -{3}[W]mulmx_ebase -mulmxA. rewrite mulKmx ?col_ebase_unit // [_ *m g]mulmxDr mulmxA. rewrite (proj_mx_0 (capmx_compl _)) // mul0mx add0r 2!mulmxA. rewrite mulmxK ?row_ebase_unit // copid_mx_id ?rank_leq_row //. rewrite (eqmxMr _ (genmxE U)) injfU genmxE addrC -mulmxDl subrK. by rewrite mul1mx mulVmx ?row_ebase_unit. Qed. (* Two matrices with the same shape represent the same subspace *) (* iff they differ only by a change of basis. *) Lemma eqmxMunitP m n (U V : 'M_(m, n)) : reflect (exists2 P, P \in unitmx & U = P *m V) (U == V)%MS. Proof. apply: (iffP eqmxP) => [eqUV | [P Punit ->]]; last first. by apply/eqmxMfull; rewrite row_full_unit. have [D defU]: exists D, U = D *m V by apply/submxP; rewrite eqUV. have{eqUV} [Pt Pt_unit defUt]: {Pt | Pt \in unitmx & V^T *m D^T = V^T *m Pt}. by apply/complete_unitmx; rewrite -trmx_mul -defU !mxrank_tr eqUV. by exists Pt^T; last apply/trmx_inj; rewrite ?unitmx_tr // defU !trmx_mul trmxK. Qed. (* Mapping between two subspaces with the same dimension. *) Lemma eq_rank_unitmx m1 m2 n (U : 'M_(m1, n)) (V : 'M_(m2, n)) : \rank U = \rank V -> {f : 'M_n | f \in unitmx & V :=: U *m f}%MS. Proof. move=> eqrUV; pose f := invmx (row_ebase <<U>>%MS) *m row_ebase <<V>>%MS. have defUf: (<<U>> *m f :=: <<V>>)%MS. rewrite -[<<U>>%MS]mulmx_ebase mulmxA mulmxK ?row_ebase_unit // -mulmxA. rewrite genmxE eqrUV -genmxE -{3}[<<V>>%MS]mulmx_ebase -mulmxA. move: (pid_mx _ *m _) => W; apply/eqmxP. by rewrite !eqmxMfull ?andbb // row_full_unit col_ebase_unit. have{defUf} defV: (V :=: U *m f)%MS. by apply/eqmxP; rewrite -!(eqmxMr f (genmxE U)) !defUf !genmxE andbb. have injfU: \rank (U *m f) = \rank U by rewrite -defV eqrUV. by have [g injg defUg] := complete_unitmx injfU; exists g; rewrite -?defUg. Qed. (* maximal rank and full rank submatrices *) Section MaxRankSubMatrix. Variables (m n : nat) (A : 'M_(m, n)). Definition maxrankfun : 'I_m ^ \rank A := [arg max_(f > finfun (widen_ord (rank_leq_row A))) \rank (rowsub f A)]. Local Notation mxf := maxrankfun. Lemma maxrowsub_free : row_free (rowsub mxf A). Proof. rewrite /mxf; case: arg_maxnP => //= f _ fM; apply/negP => /negP rfA. have [i NriA] : exists i, ~~ (row i A <= rowsub f A)%MS. by apply/row_subPn; apply: contraNN rfA => /mxrankS; rewrite row_leq_rank. have [j rjfA] : exists j, (row (f j) A <= rowsub (f \o lift j) A)%MS. case/row_freePn: rfA => j. by rewrite row_rowsub row'Esub -mxsub_comp; exists j. pose g : 'I_m ^ \rank A := finfun [eta f with j |-> i]. suff: (rowsub f A < rowsub g A)%MS by rewrite ltmxErank andbC ltnNge fM. rewrite ltmxE; apply/andP; split; last first. apply: contra NriA; apply: submx_trans. by rewrite (eq_row_sub j)// row_rowsub ffunE/= eqxx. apply/row_subP => k; rewrite !row_rowsub. have [->|/negPf eq_kjF] := eqVneq k j; last first. by rewrite (eq_row_sub k)// row_rowsub ffunE/= eq_kjF. rewrite (submx_trans rjfA)// (submx_rowsub (lift j))// => l /=. by rewrite ffunE/= eq_sym (negPf (neq_lift _ _)). Qed. Lemma eq_maxrowsub : (rowsub mxf A :=: A)%MS. Proof. apply/eqmxP; rewrite -(eq_leqif (mxrank_leqif_eq _))//. exact: maxrowsub_free. apply/row_subP => i; apply/submxP; exists (delta_mx 0 (mxf i)). by rewrite -rowE; apply/rowP => j; rewrite !mxE. Qed. Lemma maxrankfun_inj : injective mxf. Proof. move=> i j eqAij; have /row_free_inj := maxrowsub_free. move=> /(_ 1) /(_ (delta_mx 0 i) (delta_mx 0 j)). rewrite -!rowE !row_rowsub eqAij => /(_ erefl) /matrixP /(_ 0 i) /eqP. by rewrite !mxE !eqxx/=; case: (i =P j); rewrite // oner_eq0. Qed. Variable (rkA : row_full A). Lemma maxrowsub_full : row_full (rowsub mxf A). Proof. by rewrite /row_full eq_maxrowsub. Qed. Hint Resolve maxrowsub_full : core. Definition fullrankfun : 'I_m ^ n := finfun (mxf \o cast_ord (esym (eqP rkA))). Local Notation frf := fullrankfun. Lemma fullrowsub_full : row_full (rowsub frf A). Proof. by rewrite mxsub_ffunl rowsub_comp rowsub_cast esymK row_full_castmx. Qed. Lemma fullrowsub_unit : rowsub frf A \in unitmx. Proof. by rewrite -row_full_unit fullrowsub_full. Qed. Lemma fullrowsub_free : row_free (rowsub frf A). Proof. by rewrite row_free_unit fullrowsub_unit. Qed. Lemma mxrank_fullrowsub : \rank (rowsub frf A) = n. Proof. exact/eqP/fullrowsub_full. Qed. Lemma eq_fullrowsub : (rowsub frf A :=: A)%MS. Proof. rewrite mxsub_ffunl rowsub_comp rowsub_cast esymK. exact: (eqmx_trans (eqmx_cast _ _) eq_maxrowsub). Qed. Lemma fullrankfun_inj : injective frf. Proof. by move=> i j; rewrite !ffunE => /maxrankfun_inj /(congr1 val)/= /val_inj. Qed. End MaxRankSubMatrix. Section SumExpr. (* This is the infrastructure to support the mxdirect predicate. We use a *) (* bespoke canonical structure to decompose a matrix expression into binary *) (* and n-ary products, using some of the "quote" technology. This lets us *) (* characterize direct sums as set sums whose rank is equal to the sum of the *) (* ranks of the individual terms. The mxsum_expr/proper_mxsum_expr structures *) (* below supply both the decomposition and the calculation of the rank sum. *) (* The mxsum_spec dependent predicate family expresses the consistency of *) (* these two decompositions. *) (* The main technical difficulty we need to overcome is the fact that *) (* the "catch-all" case of canonical structures has a priority lower than *) (* constant expansion. However, it is undesirable that local abbreviations *) (* be opaque for the direct-sum predicate, e.g., not be able to handle *) (* let S := (\sum_(i | P i) LargeExpression i)%MS in mxdirect S -> ...). *) (* As in "quote", we use the interleaving of constant expansion and *) (* canonical projection matching to achieve our goal: we use a "wrapper" type *) (* (indeed, the wrapped T type defined in ssrfun.v) with a self-inserting *) (* non-primitive constructor to gain finer control over the type and *) (* structure inference process. The innermost, primitive, constructor flags *) (* trivial sums; it is initially hidden by an eta-expansion, which has been *) (* made into a (default) canonical structure -- this lets type inference *) (* automatically insert this outer tag. *) (* In detail, we define three types *) (* mxsum_spec S r <-> There exists a finite list of matrices A1, ..., Ak *) (* such that S is the set sum of the Ai, and r is the sum *) (* of the ranks of the Ai, i.e., S = (A1 + ... + Ak)%MS *) (* and r = \rank A1 + ... + \rank Ak. Note that *) (* mxsum_spec is a recursive dependent predicate family *) (* whose elimination rewrites simultaneaously S, r and *) (* the height of S. *) (* proper_mxsum_expr n == The interface for proper sum expressions; this is *) (* a double-entry interface, keyed on both the matrix sum *) (* value and the rank sum. The matrix value is restricted *) (* to square matrices, as the "+"%MS operator always *) (* returns a square matrix. This interface has two *) (* canonical instances, for binary and n-ary sums. *) (* mxsum_expr m n == The interface for general sum expressions, comprising *) (* both proper sums and trivial sums consisting of a *) (* single matrix. The key values are WRAPPED as this lets *) (* us give priority to the "proper sum" interpretation *) (* (see below). To allow for trivial sums, the matrix key *) (* can have any dimension. The mxsum_expr interface has *) (* two canonical instances, for trivial and proper sums, *) (* keyed to the Wrap and wrap constructors, respectively. *) (* The projections for the two interfaces above are *) (* proper_mxsum_val, mxsum_val : these are respectively coercions to 'M_n *) (* and wrapped 'M_(m, n); thus, the matrix sum for an *) (* S : mxsum_expr m n can be written unwrap S. *) (* proper_mxsum_rank, mxsum_rank : projections to the nat and wrapped nat, *) (* respectively; the rank sum for S : mxsum_expr m n is *) (* thus written unwrap (mxsum_rank S). *) (* The mxdirect A predicate actually gets A in a phantom argument, which is *) (* used to infer an (implicit) S : mxsum_expr such that unwrap S = A; the *) (* actual definition is \rank (unwrap S) == unwrap (mxsum_rank S). *) (* Note that the inference of S is inherently ambiguous: ANY matrix can be *) (* viewed as a trivial sum, including one whose description is manifestly a *) (* proper sum. We use the wrapped type and the interaction between delta *) (* reduction and canonical structure inference to resolve this ambiguity in *) (* favor of proper sums, as follows: *) (* - The phantom type sets up a unification problem of the form *) (* unwrap (mxsum_val ?S) = A *) (* with unknown evar ?S : mxsum_expr m n. *) (* - As the constructor wrap is also a default Canonical instance for the *) (* wrapped type, so A is immediately replaced with unwrap (wrap A) and *) (* we get the residual unification problem *) (* mxsum_val ?S = wrap A *) (* - Now Coq tries to apply the proper sum Canonical instance, which has *) (* key projection wrap (proper_mxsum_val ?PS) where ?PS is a fresh evar *) (* (of type proper_mxsum_expr n). This can only succeed if m = n, and if *) (* a solution can be found to the recursive unification problem *) (* proper_mxsum_val ?PS = A *) (* This causes Coq to look for one of the two canonical constants for *) (* proper_mxsum_val (addsmx or bigop) at the head of A, delta-expanding *) (* A as needed, and then inferring recursively mxsum_expr structures for *) (* the last argument(s) of that constant. *) (* - If the above step fails then the wrap constant is expanded, revealing *) (* the primitive Wrap constructor; the unification problem now becomes *) (* mxsum_val ?S = Wrap A *) (* which fits perfectly the trivial sum canonical structure, whose key *) (* projection is Wrap ?B where ?B is a fresh evar. Thus the inference *) (* succeeds, and returns the trivial sum. *) (* Note that the rank projections also register canonical values, so that the *) (* same process can be used to infer a sum structure from the rank sum. In *) (* that case, however, there is no ambiguity and the inference can fail, *) (* because the rank sum for a trivial sum is not an arbitrary integer -- it *) (* must be of the form \rank ?B. It is nevertheless necessary to use the *) (* wrapped nat type for the rank sums, because in the non-trivial case the *) (* head constant of the nat expression is determined by the proper_mxsum_expr *) (* canonical structure, so the mxsum_expr structure must use a generic *) (* constant, namely wrap. *) Inductive mxsum_spec n : forall m, 'M[F]_(m, n) -> nat -> Prop := | TrivialMxsum m A : @mxsum_spec n m A (\rank A) | ProperMxsum m1 m2 T1 T2 r1 r2 of @mxsum_spec n m1 T1 r1 & @mxsum_spec n m2 T2 r2 : mxsum_spec (T1 + T2)%MS (r1 + r2)%N. Arguments mxsum_spec {n%_N m%_N} T%_MS r%_N. Structure mxsum_expr m n := Mxsum { mxsum_val :> wrapped 'M_(m, n); mxsum_rank : wrapped nat; _ : mxsum_spec (unwrap mxsum_val) (unwrap mxsum_rank) }. Canonical trivial_mxsum m n A := @Mxsum m n (Wrap A) (Wrap (\rank A)) (TrivialMxsum A). Structure proper_mxsum_expr n := ProperMxsumExpr { proper_mxsum_val :> 'M_n; proper_mxsum_rank : nat; _ : mxsum_spec proper_mxsum_val proper_mxsum_rank }. Definition proper_mxsumP n (S : proper_mxsum_expr n) := let: ProperMxsumExpr _ _ termS := S return mxsum_spec S (proper_mxsum_rank S) in termS. Canonical sum_mxsum n (S : proper_mxsum_expr n) := @Mxsum n n (wrap (S : 'M_n)) (wrap (proper_mxsum_rank S)) (proper_mxsumP S). Section Binary. Variable (m1 m2 n : nat) (S1 : mxsum_expr m1 n) (S2 : mxsum_expr m2 n). Fact binary_mxsum_proof : mxsum_spec (unwrap S1 + unwrap S2) (unwrap (mxsum_rank S1) + unwrap (mxsum_rank S2)). Proof. by case: S1 S2 => [A1 r1 A1P] [A2 r2 A2P]; right. Qed. Canonical binary_mxsum_expr := ProperMxsumExpr binary_mxsum_proof. End Binary. Section Nary. Context J (r : seq J) (P : pred J) n (S_ : J -> mxsum_expr n n). Fact nary_mxsum_proof : mxsum_spec (\sum_(j <- r | P j) unwrap (S_ j)) (\sum_(j <- r | P j) unwrap (mxsum_rank (S_ j))). Proof. elim/big_rec2: _ => [|j]; first by rewrite -(mxrank0 n n); left. by case: (S_ j); right. Qed. Canonical nary_mxsum_expr := ProperMxsumExpr nary_mxsum_proof. End Nary. Definition mxdirect_def m n T of phantom 'M_(m, n) (unwrap (mxsum_val T)) := \rank (unwrap T) == unwrap (mxsum_rank T). End SumExpr. Notation mxdirect A := (mxdirect_def (Phantom 'M_(_,_) A%MS)). Lemma mxdirectP n (S : proper_mxsum_expr n) : reflect (\rank S = proper_mxsum_rank S) (mxdirect S). Proof. exact: eqnP. Qed. Arguments mxdirectP {n S}. Lemma mxdirect_trivial m n A : mxdirect (unwrap (@trivial_mxsum m n A)). Proof. exact: eqxx. Qed. Lemma mxrank_sum_leqif m n (S : mxsum_expr m n) : \rank (unwrap S) <= unwrap (mxsum_rank S) ?= iff mxdirect (unwrap S). Proof. rewrite /mxdirect_def; case: S => [[A] [r] /= defAr]; split=> //=. elim: m A r / defAr => // m1 m2 A1 A2 r1 r2 _ leAr1 _ leAr2. by apply: leq_trans (leq_add leAr1 leAr2); rewrite mxrank_adds_leqif. Qed. Lemma mxdirectE m n (S : mxsum_expr m n) : mxdirect (unwrap S) = (\rank (unwrap S) == unwrap (mxsum_rank S)). Proof. by []. Qed. Lemma mxdirectEgeq m n (S : mxsum_expr m n) : mxdirect (unwrap S) = (\rank (unwrap S) >= unwrap (mxsum_rank S)). Proof. by rewrite (geq_leqif (mxrank_sum_leqif S)). Qed. Section BinaryDirect. Variables m1 m2 n : nat. Lemma mxdirect_addsE (S1 : mxsum_expr m1 n) (S2 : mxsum_expr m2 n) : mxdirect (unwrap S1 + unwrap S2) = [&& mxdirect (unwrap S1), mxdirect (unwrap S2) & unwrap S1 :&: unwrap S2 == 0]%MS. Proof. rewrite (@mxdirectE n) /=. have:= leqif_add (mxrank_sum_leqif S1) (mxrank_sum_leqif S2). move/(leqif_trans (mxrank_adds_leqif (unwrap S1) (unwrap S2)))=> ->. by rewrite andbC -andbA submx0. Qed. Lemma mxdirect_addsP (A : 'M_(m1, n)) (B : 'M_(m2, n)) : reflect (A :&: B = 0)%MS (mxdirect (A + B)). Proof. by rewrite mxdirect_addsE !mxdirect_trivial; apply: eqP. Qed. End BinaryDirect. Section NaryDirect. Variables (P : pred I) (n : nat). Let TIsum A_ i := (A_ i :&: (\sum_(j | P j && (j != i)) A_ j) = 0 :> 'M_n)%MS. Let mxdirect_sums_recP (S_ : I -> mxsum_expr n n) : reflect (forall i, P i -> mxdirect (unwrap (S_ i)) /\ TIsum (unwrap \o S_) i) (mxdirect (\sum_(i | P i) (unwrap (S_ i)))). Proof. rewrite /TIsum; apply: (iffP eqnP) => /= [dxS i Pi | dxS]. set Si' := (\sum_(j | _) unwrap (S_ j))%MS. have: mxdirect (unwrap (S_ i) + Si') by apply/eqnP; rewrite /= -!(bigD1 i). by rewrite mxdirect_addsE => /and3P[-> _ /eqP]. set Q := P; have [m] := ubnP #|Q|; have: Q \subset P by []. elim: m Q => // m IHm Q /subsetP-sQP. case: (pickP Q) => [i Qi | Q0]; last by rewrite !big_pred0 ?mxrank0. rewrite (cardD1x Qi) !((bigD1 i) Q) //=. move/IHm=> <- {IHm}/=; last by apply/subsetP=> j /andP[/sQP]. case: (dxS i (sQP i Qi)) => /eqnP=> <- TiQ_0; rewrite mxrank_disjoint_sum //. apply/eqP; rewrite -submx0 -{2}TiQ_0 capmxS //=. by apply/sumsmx_subP=> j /= /andP[Qj i'j]; rewrite (sumsmx_sup j) ?[P j]sQP. Qed. Lemma mxdirect_sumsP (A_ : I -> 'M_n) : reflect (forall i, P i -> A_ i :&: (\sum_(j | P j && (j != i)) A_ j) = 0)%MS (mxdirect (\sum_(i | P i) A_ i)). Proof. apply: (iffP (mxdirect_sums_recP _)) => dxA i /dxA; first by case. by rewrite mxdirect_trivial. Qed. Lemma mxdirect_sumsE (S_ : I -> mxsum_expr n n) (xunwrap := unwrap) : reflect (and (forall i, P i -> mxdirect (unwrap (S_ i))) (mxdirect (\sum_(i | P i) (xunwrap (S_ i))))) (mxdirect (\sum_(i | P i) (unwrap (S_ i)))). Proof. apply: (iffP (mxdirect_sums_recP _)) => [dxS | [dxS_ dxS] i Pi]. by do [split; last apply/mxdirect_sumsP] => i; case/dxS. by split; [apply: dxS_ | apply: mxdirect_sumsP Pi]. Qed. End NaryDirect. Section SubDaddsmx. Variables m m1 m2 n : nat. Variables (A : 'M[F]_(m, n)) (B1 : 'M[F]_(m1, n)) (B2 : 'M[F]_(m2, n)). Variant sub_daddsmx_spec : Prop := SubDaddsmxSpec A1 A2 of (A1 <= B1)%MS & (A2 <= B2)%MS & A = A1 + A2 & forall C1 C2, (C1 <= B1)%MS -> (C2 <= B2)%MS -> A = C1 + C2 -> C1 = A1 /\ C2 = A2. Lemma sub_daddsmx : (B1 :&: B2 = 0)%MS -> (A <= B1 + B2)%MS -> sub_daddsmx_spec. Proof. move=> dxB /sub_addsmxP[u defA]. exists (u.1 *m B1) (u.2 *m B2); rewrite ?submxMl // => C1 C2 sCB1 sCB2. move/(canLR (addrK _)) => defC1. suffices: (C2 - u.2 *m B2 <= B1 :&: B2)%MS. by rewrite dxB submx0 subr_eq0 -defC1 defA; move/eqP->; rewrite addrK. rewrite sub_capmx -opprB -{1}(canLR (addKr _) defA) -addrA defC1. by rewrite !(eqmx_opp, addmx_sub) ?submxMl. Qed. End SubDaddsmx. Section SubDsumsmx. Variables (P : pred I) (m n : nat) (A : 'M[F]_(m, n)) (B : I -> 'M[F]_n). Variant sub_dsumsmx_spec : Prop := SubDsumsmxSpec A_ of forall i, P i -> (A_ i <= B i)%MS & A = \sum_(i | P i) A_ i & forall C, (forall i, P i -> C i <= B i)%MS -> A = \sum_(i | P i) C i -> {in SimplPred P, C =1 A_}. Lemma sub_dsumsmx : mxdirect (\sum_(i | P i) B i) -> (A <= \sum_(i | P i) B i)%MS -> sub_dsumsmx_spec. Proof. move/mxdirect_sumsP=> dxB /sub_sumsmxP[u defA]. pose A_ i := u i *m B i. exists A_ => //= [i _ | C sCB defAC i Pi]; first exact: submxMl. apply/eqP; rewrite -subr_eq0 -submx0 -{dxB}(dxB i Pi) /=. rewrite sub_capmx addmx_sub ?eqmx_opp ?submxMl ?sCB //=. rewrite -(subrK A (C i)) -addrA -opprB addmx_sub ?eqmx_opp //. rewrite addrC defAC (bigD1 i) // addKr /= summx_sub // => j Pi'j. by rewrite (sumsmx_sup j) ?sCB //; case/andP: Pi'j. rewrite addrC defA (bigD1 i) // addKr /= summx_sub // => j Pi'j. by rewrite (sumsmx_sup j) ?submxMl. Qed. End SubDsumsmx. Section Eigenspace. Variables (n : nat) (g : 'M_n). Definition eigenspace a := kermx (g - a%:M). Definition eigenvalue : pred F := fun a => eigenspace a != 0. Lemma eigenspaceP a m (W : 'M_(m, n)) : reflect (W *m g = a *: W) (W <= eigenspace a)%MS. Proof. by rewrite sub_kermx mulmxBr subr_eq0 mul_mx_scalar; apply/eqP. Qed. Lemma eigenvalueP a : reflect (exists2 v : 'rV_n, v *m g = a *: v & v != 0) (eigenvalue a). Proof. by apply: (iffP (rowV0Pn _)) => [] [v]; move/eigenspaceP; exists v. Qed. Notation stablemx V f := (V%MS *m f%R <= V%MS)%MS. Lemma eigenvectorP {v : 'rV_n} : reflect (exists a, (v <= eigenspace a)%MS) (stablemx v g). Proof. by apply: (iffP (sub_rVP _ _)) => -[a] /eigenspaceP; exists a. Qed. Lemma mxdirect_sum_eigenspace (P : pred I) a_ : {in P &, injective a_} -> mxdirect (\sum_(i | P i) eigenspace (a_ i)). Proof. have [m] := ubnP #|P|; elim: m P => // m IHm P lePm inj_a. apply/mxdirect_sumsP=> i Pi; apply/eqP/rowV0P => v. rewrite sub_capmx => /andP[/eigenspaceP def_vg]. set Vi' := (\sum_(i | _) _)%MS => Vi'v. have dxVi': mxdirect Vi'. rewrite (cardD1x Pi) in lePm; apply: IHm => //. by apply: sub_in2 inj_a => j /andP[]. case/sub_dsumsmx: Vi'v => // u Vi'u def_v _. rewrite def_v big1 // => j Pi'j; apply/eqP. have nz_aij: a_ i - a_ j != 0. by case/andP: Pi'j => Pj ne_ji; rewrite subr_eq0 eq_sym (inj_in_eq inj_a). case: (sub_dsumsmx dxVi' (sub0mx 1 _)) => C _ _ uniqC. rewrite -(eqmx_eq0 (eqmx_scale _ nz_aij)). rewrite (uniqC (fun k => (a_ i - a_ k) *: u k)) => // [|k Pi'k|]. - by rewrite -(uniqC (fun _ => 0)) ?big1 // => k Pi'k; apply: sub0mx. - by rewrite scalemx_sub ?Vi'u. rewrite -{1}(subrr (v *m g)) {1}def_vg def_v scaler_sumr mulmx_suml -sumrB. by apply: eq_bigr => k /Vi'u/eigenspaceP->; rewrite scalerBl. Qed. End Eigenspace. End RowSpaceTheory. #[global] Hint Resolve submx_refl : core. Arguments submxP {F m1 m2 n A B}. Arguments eq_row_sub [F m n v A]. Arguments row_subP {F m1 m2 n A B}. Arguments rV_subP {F m1 m2 n A B}. Arguments row_subPn {F m1 m2 n A B}. Arguments sub_rVP {F n u v}. Arguments rV_eqP {F m1 m2 n A B}. Arguments rowV0Pn {F m n A}. Arguments rowV0P {F m n A}. Arguments eqmx0P {F m n A}. Arguments row_fullP {F m n A}. Arguments row_freeP {F m n A}. Arguments eqmxP {F m1 m2 n A B}. Arguments genmxP {F m1 m2 n A B}. Arguments addsmx_idPr {F m1 m2 n A B}. Arguments addsmx_idPl {F m1 m2 n A B}. Arguments sub_addsmxP {F m1 m2 m3 n A B C}. Arguments sumsmx_sup [F I] i0 [P m n A B_]. Arguments sumsmx_subP {F I P m n A_ B}. Arguments sub_sumsmxP {F I P m n A B_}. Arguments sub_kermxP {F p m n A B}. Arguments capmx_idPr {F n m1 m2 A B}. Arguments capmx_idPl {F n m1 m2 A B}. Arguments bigcapmx_inf [F I] i0 [P m n A_ B]. Arguments sub_bigcapmxP {F I P m n A B_}. Arguments mxrank_injP {F m n} p {A f}. Arguments mxdirectP {F n S}. Arguments mxdirect_addsP {F m1 m2 n A B}. Arguments mxdirect_sumsP {F I P n A_}. Arguments mxdirect_sumsE {F I P n S_}. Arguments eigenspaceP {F n g a m W}. Arguments eigenvalueP {F n g a}. Arguments submx_rowsub [F m1 m2 m3 n] h [f g A] _ : rename. Arguments eqmx_rowsub [F m1 m2 m3 n] h [f g A] _ : rename. Arguments mxrank {F m%_N n%_N} A%_MS. Arguments complmx {F m%_N n%_N} A%_MS. Arguments row_full {F m%_N n%_N} A%_MS. Arguments submx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments ltmx {F m1%_N m2%_N n%_N} A%_MS B%_MS. Arguments eqmx {F m1%_N m2%_N n%_N} A%_MS B%_MS. Arguments addsmx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments capmx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments diffmx {F m1%_N m2%_N n%_N} A%_MS B%_MS : rename. Arguments genmx {F m%_N n%_N} A%_R : rename. Notation "\rank A" := (mxrank A) : nat_scope. Notation "<< A >>" := (genmx A) : matrix_set_scope. Notation "A ^C" := (complmx A) : matrix_set_scope. Notation "A <= B" := (submx A B) : matrix_set_scope. Notation "A < B" := (ltmx A B) : matrix_set_scope. Notation "A <= B <= C" := ((submx A B) && (submx B C)) : matrix_set_scope. Notation "A < B <= C" := (ltmx A B && submx B C) : matrix_set_scope. Notation "A <= B < C" := (submx A B && ltmx B C) : matrix_set_scope. Notation "A < B < C" := (ltmx A B && ltmx B C) : matrix_set_scope. Notation "A == B" := ((submx A B) && (submx B A)) : matrix_set_scope. Notation "A :=: B" := (eqmx A B) : matrix_set_scope. Notation "A + B" := (addsmx A B) : matrix_set_scope. Notation "A :&: B" := (capmx A B) : matrix_set_scope. Notation "A :\: B" := (diffmx A B) : matrix_set_scope. Notation mxdirect S := (mxdirect_def (Phantom 'M_(_,_) S%MS)). Notation "\sum_ ( i <- r | P ) B" := (\big[addsmx/0%R]_(i <- r | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( i <- r ) B" := (\big[addsmx/0%R]_(i <- r) B%MS) : matrix_set_scope. Notation "\sum_ ( m <= i < n | P ) B" := (\big[addsmx/0%R]_(m <= i < n | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( m <= i < n ) B" := (\big[addsmx/0%R]_(m <= i < n) B%MS) : matrix_set_scope. Notation "\sum_ ( i | P ) B" := (\big[addsmx/0%R]_(i | P%B) B%MS) : matrix_set_scope. Notation "\sum_ i B" := (\big[addsmx/0%R]_i B%MS) : matrix_set_scope. Notation "\sum_ ( i : t | P ) B" := (\big[addsmx/0%R]_(i : t | P%B) B%MS) (only parsing) : matrix_set_scope. Notation "\sum_ ( i : t ) B" := (\big[addsmx/0%R]_(i : t) B%MS) (only parsing) : matrix_set_scope. Notation "\sum_ ( i < n | P ) B" := (\big[addsmx/0%R]_(i < n | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( i < n ) B" := (\big[addsmx/0%R]_(i < n) B%MS) : matrix_set_scope. Notation "\sum_ ( i 'in' A | P ) B" := (\big[addsmx/0%R]_(i in A | P%B) B%MS) : matrix_set_scope. Notation "\sum_ ( i 'in' A ) B" := (\big[addsmx/0%R]_(i in A) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i <- r | P ) B" := (\big[capmx/1%:M]_(i <- r | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i <- r ) B" := (\big[capmx/1%:M]_(i <- r) B%MS) : matrix_set_scope. Notation "\bigcap_ ( m <= i < n | P ) B" := (\big[capmx/1%:M]_(m <= i < n | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( m <= i < n ) B" := (\big[capmx/1%:M]_(m <= i < n) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i | P ) B" := (\big[capmx/1%:M]_(i | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ i B" := (\big[capmx/1%:M]_i B%MS) : matrix_set_scope. Notation "\bigcap_ ( i : t | P ) B" := (\big[capmx/1%:M]_(i : t | P%B) B%MS) (only parsing) : matrix_set_scope. Notation "\bigcap_ ( i : t ) B" := (\big[capmx/1%:M]_(i : t) B%MS) (only parsing) : matrix_set_scope. Notation "\bigcap_ ( i < n | P ) B" := (\big[capmx/1%:M]_(i < n | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i < n ) B" := (\big[capmx/1%:M]_(i < n) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i 'in' A | P ) B" := (\big[capmx/1%:M]_(i in A | P%B) B%MS) : matrix_set_scope. Notation "\bigcap_ ( i 'in' A ) B" := (\big[capmx/1%:M]_(i in A) B%MS) : matrix_set_scope. Section Stability. Variable (F : fieldType). Lemma eqmx_stable m m' n (V : 'M[F]_(m, n)) (V' : 'M[F]_(m', n)) (f : 'M[F]_n) : (V :=: V')%MS -> stablemx V f = stablemx V' f. Proof. by move=> eqVV'; rewrite (eqmxMr _ eqVV') eqVV'. Qed. Section FixedDim. Variables (m n : nat) (V W : 'M[F]_(m, n)) (f g : 'M[F]_n). Lemma stablemx_row_base : (stablemx (row_base V) f) = (stablemx V f). Proof. by apply: eqmx_stable; apply: eq_row_base. Qed. Lemma stablemx_full : row_full V -> stablemx V f. Proof. exact: submx_full. Qed. Lemma stablemxM : stablemx V f -> stablemx V g -> stablemx V (f *m g). Proof. by move=> f_stab /(submx_trans _)->//; rewrite mulmxA submxMr. Qed. Lemma stablemxD : stablemx V f -> stablemx V g -> stablemx V (f + g). Proof. by move=> f_stab g_stab; rewrite mulmxDr addmx_sub. Qed. Lemma stablemxN : stablemx V (- f) = stablemx V f. Proof. by rewrite mulmxN eqmx_opp. Qed. Lemma stablemxC x : stablemx V x%:M. Proof. by rewrite mul_mx_scalar scalemx_sub. Qed. Lemma stablemx0 : stablemx V 0. Proof. by rewrite mulmx0 sub0mx. Qed. Lemma stableDmx : stablemx V f -> stablemx W f -> stablemx (V + W)%MS f. Proof. by move=> fV fW; rewrite addsmxMr addsmxS. Qed. Lemma stableNmx : stablemx (- V) f = stablemx V f. Proof. by rewrite mulNmx !eqmx_opp. Qed. Lemma stable0mx : stablemx (0 : 'M_(m, n)) f. Proof. by rewrite mul0mx. Qed. End FixedDim. Lemma stableCmx (m n : nat) x (f : 'M[F]_(m, n)) : stablemx x%:M f. Proof. have [->|x_neq0] := eqVneq x 0; first by rewrite mul_scalar_mx scale0r sub0mx. by rewrite -![x%:M]scalemx1 eqmx_scale// submx_full// -sub1mx. Qed. Lemma stablemx_sums (n : nat) (I : finType) (V_ : I -> 'M[F]_n) (f : 'M_n) : (forall i, stablemx (V_ i) f) -> stablemx (\sum_i V_ i)%MS f. Proof. by move=> fV; rewrite sumsmxMr; apply/sumsmx_subP => i; rewrite (sumsmx_sup i). Qed. Lemma stablemx_unit (n : nat) (V f : 'M[F]_n) : V \in unitmx -> stablemx V f. Proof. by move=> Vunit; rewrite submx_full ?row_full_unit. Qed. Section Commutation. Variable (n : nat). Implicit Types (f g : 'M[F]_n). Lemma comm_mx_stable (f g : 'M[F]_n) : comm_mx f g -> stablemx f g. Proof. by move=> comm_fg; rewrite [_ *m _]comm_fg mulmx_sub. Qed. Lemma comm_mx_stable_ker (f g : 'M[F]_n) : comm_mx f g -> stablemx (kermx f) g. Proof. move=> comm_fg; apply/sub_kermxP. by rewrite -mulmxA -[g *m _]comm_fg mulmxA mulmx_ker mul0mx. Qed. Lemma comm_mx_stable_eigenspace (f g : 'M[F]_n) a : comm_mx f g -> stablemx (eigenspace f a) g. Proof. move=> cfg; rewrite comm_mx_stable_ker//. by apply/comm_mx_sym/comm_mxB => //; apply:comm_mx_scalar. Qed. End Commutation. End Stability. Section DirectSums. Variables (F : fieldType) (I : finType) (P : pred I). Lemma mxdirect_delta n f : {in P &, injective f} -> mxdirect (\sum_(i | P i) <<delta_mx 0 (f i) : 'rV[F]_n>>). Proof. pose fP := image f P => Uf; have UfP: uniq fP by apply/dinjectiveP. suffices /mxdirectP : mxdirect (\sum_i <<delta_mx 0 i : 'rV[F]_n>>). rewrite /= !(bigID [in fP] predT) -!big_uniq //= !big_map !big_enum. by move/mxdirectP; rewrite mxdirect_addsE => /andP[]. apply/mxdirectP=> /=; transitivity (mxrank (1%:M : 'M[F]_n)). apply/eqmx_rank; rewrite submx1 mx1_sum_delta summx_sub_sums // => i _. by rewrite -(mul_delta_mx (0 : 'I_1)) genmxE submxMl. rewrite mxrank1 -[LHS]card_ord -sum1_card. by apply/eq_bigr=> i _; rewrite /= mxrank_gen mxrank_delta. Qed. End DirectSums. Section CardGL. Variable F : finFieldType. Lemma card_GL n : n > 0 -> #|'GL_n[F]| = (#|F| ^ 'C(n, 2) * \prod_(1 <= i < n.+1) (#|F| ^ i - 1))%N. Proof. case: n => // n' _; set n := n'.+1; set p := #|F|. rewrite big_nat_rev big_add1 -bin2_sum expn_sum -big_split /=. pose fr m := [pred A : 'M[F]_(m, n) | \rank A == m]. set m := n; rewrite [in m.+1]/m; transitivity #|fr m|. by rewrite cardsT /= card_sub; apply: eq_card => A; rewrite -row_free_unit. have: m <= n by []; elim: m => [_ | m IHm /ltnW-le_mn]. rewrite (@eq_card1 _ (0 : 'M_(0, n))) ?big_geq //= => A. by rewrite flatmx0 !inE mxrank.unlock !eqxx. rewrite big_nat_recr // -{}IHm //= !subSS mulnBr muln1 -expnD subnKC //. rewrite -sum_nat_const /= -sum1_card -add1n. rewrite (partition_big dsubmx (fr m)) /= => [|A]; last first. rewrite !inE -{1}(vsubmxK A); move: {A}(_ A) (_ A) => Ad Au Afull. rewrite eqn_leq rank_leq_row -(leq_add2l (\rank Au)) -mxrank_sum_cap. rewrite {1 3}[@mxrank]lock addsmxE (eqnP Afull) -lock -addnA. by rewrite leq_add ?rank_leq_row ?leq_addr. apply: eq_bigr => A rAm; rewrite (reindex (col_mx^~ A)) /=; last first. exists usubmx => [v _ | vA]; first by rewrite col_mxKu. by case/andP=> _ /eqP <-; rewrite vsubmxK. transitivity #|~: [set v *m A | v in 'rV_m]|; last first. rewrite cardsCs setCK card_imset ?card_mx ?card_ord ?mul1n //. have [B AB1] := row_freeP rAm; apply: can_inj (mulmx^~ B) _ => v. by rewrite -mulmxA AB1 mulmx1. rewrite -sum1_card; apply: eq_bigl => v; rewrite !inE col_mxKd eqxx. rewrite andbT eqn_leq rank_leq_row /= -(leq_add2r (\rank (v :&: A)%MS)). rewrite -addsmxE mxrank_sum_cap (eqnP rAm) addnAC leq_add2r. rewrite (ltn_leqif (mxrank_leqif_sup _)) ?capmxSl // sub_capmx submx_refl. by congr (~~ _); apply/submxP/imsetP=> [] [u]; exists u. Qed. (* An alternate, somewhat more elementary proof, that does not rely on the *) (* row-space theory, but directly performs the LUP decomposition. *) Lemma LUP_card_GL n : n > 0 -> #|'GL_n[F]| = (#|F| ^ 'C(n, 2) * \prod_(1 <= i < n.+1) (#|F| ^ i - 1))%N. Proof. case: n => // n' _; set n := n'.+1; set p := #|F|. rewrite cardsT /= card_sub /GRing.unit /= big_add1 /= -bin2_sum -/n /=. elim: {n'}n => [|n IHn]. rewrite !big_geq // mul1n (@eq_card _ _ predT) ?card_mx //= => M. by rewrite {1}[M]flatmx0 -(flatmx0 1%:M) unitmx1. rewrite !big_nat_recr //= expnD mulnAC mulnA -{}IHn -mulnA mulnC. set LHS := #|_|; rewrite -[n.+1]muln1 -{2}[n]mul1n {}/LHS. rewrite -!card_mx subn1 -(cardC1 0) -mulnA; set nzC := predC1 _. rewrite -sum1_card (partition_big lsubmx nzC) => [|A]; last first. rewrite unitmxE unitfE; apply: contra; move/eqP=> v0. rewrite -[A]hsubmxK v0 -[n.+1]/(1 + n)%N -col_mx0. rewrite -[rsubmx _]vsubmxK -det_tr tr_row_mx !tr_col_mx !trmx0. by rewrite det_lblock [0]mx11_scalar det_scalar1 mxE mul0r. rewrite -sum_nat_const; apply: eq_bigr => /= v /cV0Pn[k nza]. have xrkK: involutive (@xrow F _ _ 0 k). by move=> m A /=; rewrite /xrow -row_permM tperm2 row_perm1. rewrite (reindex_inj (inv_inj (xrkK (1 + n)%N))) /= -[n.+1]/(1 + n)%N. rewrite (partition_big ursubmx xpredT) //= -sum_nat_const. apply: eq_bigr => u _; set a : F := v _ _ in nza. set v1 : 'cV_(1 + n) := xrow 0 k v. have def_a: usubmx v1 = a%:M. by rewrite [_ v1]mx11_scalar mxE lshift0 mxE tpermL. pose Schur := dsubmx v1 *m (a^-1 *: u). pose L : 'M_(1 + n) := block_mx a%:M 0 (dsubmx v1) 1%:M. pose U B : 'M_(1 + n) := block_mx 1 (a^-1 *: u) 0 B. rewrite (reindex (fun B => L *m U B)); last first. exists (fun A1 => drsubmx A1 - Schur) => [B _ | A1]. by rewrite mulmx_block block_mxKdr mul1mx addrC addKr. rewrite !inE mulmx_block !mulmx0 mul0mx !mulmx1 !addr0 mul1mx addrC subrK. rewrite mul_scalar_mx scalerA divff // scale1r andbC; case/and3P => /eqP <- _. rewrite -{1}(hsubmxK A1) xrowE mul_mx_row row_mxKl -xrowE => /eqP def_v. rewrite -def_a block_mxEh vsubmxK /v1 -def_v xrkK. apply: trmx_inj; rewrite tr_row_mx tr_col_mx trmx_ursub trmx_drsub trmx_lsub. by rewrite hsubmxK vsubmxK. rewrite -sum1_card; apply: eq_bigl => B; rewrite xrowE unitmxE. rewrite !det_mulmx unitrM -unitmxE unitmx_perm det_lblock det_ublock. rewrite !det_scalar1 det1 mulr1 mul1r unitrM unitfE nza -unitmxE. rewrite mulmx_block !mulmx0 mul0mx !addr0 !mulmx1 mul1mx block_mxKur. rewrite mul_scalar_mx scalerA divff // scale1r eqxx andbT. by rewrite block_mxEh mul_mx_row row_mxKl -def_a vsubmxK -xrowE xrkK eqxx andbT. Qed. Lemma card_GL_1 : #|'GL_1[F]| = #|F|.-1. Proof. by rewrite card_GL // mul1n big_nat1 expn1 subn1. Qed. Lemma card_GL_2 : #|'GL_2[F]| = (#|F| * #|F|.-1 ^ 2 * #|F|.+1)%N. Proof. rewrite card_GL // big_ltn // big_nat1 expn1 -(addn1 #|F|) -subn1 -!mulnA. by rewrite -subn_sqr. Qed. End CardGL. Lemma logn_card_GL_p n p : prime p -> logn p #|'GL_n(p)| = 'C(n, 2). Proof. move=> p_pr; have p_gt1 := prime_gt1 p_pr. have p_i_gt0: p ^ _ > 0 by move=> i; rewrite expn_gt0 ltnW. have <- : #|'GL_n.-1.+1(p)| = #|'GL_n(p)| by []. rewrite (card_GL _ (ltn0Sn n.-1)) card_ord Fp_cast // big_add1 /=. pose p'gt0 m := m > 0 /\ logn p m = 0. suffices [Pgt0 p'P]: p'gt0 (\prod_(0 <= i < n.-1.+1) (p ^ i.+1 - 1))%N. by rewrite lognM // p'P pfactorK // addn0; case n. apply: big_ind => [|m1 m2 [m10 p'm1] [m20]|i _]; rewrite {}/p'gt0 ?logn1 //. by rewrite muln_gt0 m10 lognM ?p'm1. rewrite lognE -if_neg subn_gt0 p_pr /= -{1 2}(exp1n i.+1) ltn_exp2r // p_gt1. by rewrite dvdn_subr ?dvdn_exp // gtnNdvd. Qed. Section MatrixAlgebra. Variables F : fieldType. Local Notation "A \in R" := (@submx F _ _ _ (mxvec A) R). Lemma mem0mx m n (R : 'A_(m, n)) : 0 \in R. Proof. by rewrite linear0 sub0mx. Qed. Lemma memmx0 n A : (A \in (0 : 'A_n)) -> A = 0. Proof. by rewrite submx0 mxvec_eq0; move/eqP. Qed. Lemma memmx1 n (A : 'M_n) : (A \in mxvec 1%:M) = is_scalar_mx A. Proof. apply/sub_rVP/is_scalar_mxP=> [[a] | [a ->]]. by rewrite -linearZ scale_scalar_mx mulr1 => /(can_inj mxvecK); exists a. by exists a; rewrite -linearZ scale_scalar_mx mulr1. Qed. Lemma memmx_subP m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (forall A, A \in R1 -> A \in R2) (R1 <= R2)%MS. Proof. apply: (iffP idP) => [sR12 A R1_A | sR12]; first exact: submx_trans sR12. by apply/rV_subP=> vA; rewrite -(vec_mxK vA); apply: sR12. Qed. Arguments memmx_subP {m1 m2 n R1 R2}. Lemma memmx_eqP m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (forall A, (A \in R1) = (A \in R2)) (R1 == R2)%MS. Proof. apply: (iffP eqmxP) => [eqR12 A | eqR12]; first by rewrite eqR12. by apply/eqmxP/rV_eqP=> vA; rewrite -(vec_mxK vA) eqR12. Qed. Arguments memmx_eqP {m1 m2 n R1 R2}. Lemma memmx_addsP m1 m2 n A (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (exists D, [/\ D.1 \in R1, D.2 \in R2 & A = D.1 + D.2]) (A \in R1 + R2)%MS. Proof. apply: (iffP sub_addsmxP) => [[u /(canRL mxvecK)->] | [D []]]. exists (vec_mx (u.1 *m R1), vec_mx (u.2 *m R2)). by rewrite /= linearD !vec_mxK !submxMl. case/submxP=> u1 defD1 /submxP[u2 defD2] ->. by exists (u1, u2); rewrite linearD /= defD1 defD2. Qed. Arguments memmx_addsP {m1 m2 n A R1 R2}. Lemma memmx_sumsP (I : finType) (P : pred I) n (A : 'M_n) R_ : reflect (exists2 A_, A = \sum_(i | P i) A_ i & forall i, A_ i \in R_ i) (A \in \sum_(i | P i) R_ i)%MS. Proof. apply: (iffP sub_sumsmxP) => [[C defA] | [A_ -> R_A] {A}]. exists (fun i => vec_mx (C i *m R_ i)) => [|i]. by rewrite -linear_sum -defA /= mxvecK. by rewrite vec_mxK submxMl. exists (fun i => mxvec (A_ i) *m pinvmx (R_ i)). by rewrite linear_sum; apply: eq_bigr => i _; rewrite mulmxKpV. Qed. Arguments memmx_sumsP {I P n A R_}. Lemma has_non_scalar_mxP m n (R : 'A_(m, n)) : (1%:M \in R)%MS -> reflect (exists2 A, A \in R & ~~ is_scalar_mx A)%MS (1 < \rank R). Proof. case: (posnP n) => [-> | n_gt0] in R *; set S := mxvec _ => sSR. by rewrite [R]thinmx0 mxrank0; right; case; rewrite /is_scalar_mx ?insubF. have rankS: \rank S = 1%N. apply/eqP; rewrite eqn_leq rank_leq_row lt0n mxrank_eq0 mxvec_eq0. by rewrite -mxrank_eq0 mxrank1 -lt0n. rewrite -{2}rankS (ltn_leqif (mxrank_leqif_sup sSR)). apply: (iffP idP) => [/row_subPn[i] | [A sAR]]. rewrite -[row i R]vec_mxK memmx1; set A := vec_mx _ => nsA. by exists A; rewrite // vec_mxK row_sub. by rewrite -memmx1; apply/contra/submx_trans. Qed. Definition mulsmx m1 m2 n (R1 : 'A[F]_(m1, n)) (R2 : 'A_(m2, n)) := (\sum_i <<R1 *m lin_mx (mulmxr (vec_mx (row i R2)))>>)%MS. Arguments mulsmx {m1%_N m2%_N n%_N} R1%_MS R2%_MS. Local Notation "R1 * R2" := (mulsmx R1 R2) : matrix_set_scope. Lemma genmx_muls m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : <<(R1 * R2)%MS>>%MS = (R1 * R2)%MS. Proof. by rewrite genmx_sums; apply: eq_bigr => i; rewrite genmx_id. Qed. Lemma mem_mulsmx m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) A1 A2 : (A1 \in R1 -> A2 \in R2 -> A1 *m A2 \in R1 * R2)%MS. Proof. move=> R_A1 R_A2; rewrite -[A2]mxvecK; case/submxP: R_A2 => a ->{A2}. rewrite mulmx_sum_row !linear_sum summx_sub // => i _. rewrite 3!linearZ scalemx_sub {a}//= (sumsmx_sup i) // genmxE. rewrite -[A1]mxvecK; case/submxP: R_A1 => a ->{A1}. by apply/submxP; exists a; rewrite mulmxA mul_rV_lin. Qed. Lemma mulsmx_subP m1 m2 m n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R : 'A_(m, n)) : reflect (forall A1 A2, A1 \in R1 -> A2 \in R2 -> A1 *m A2 \in R) (R1 * R2 <= R)%MS. Proof. apply: (iffP memmx_subP) => [sR12R A1 A2 R_A1 R_A2 | sR12R A]. by rewrite sR12R ?mem_mulsmx. case/memmx_sumsP=> A_ -> R_A; rewrite linear_sum summx_sub //= => j _. rewrite (submx_trans (R_A _)) // genmxE; apply/row_subP=> i. by rewrite row_mul mul_rV_lin sR12R ?vec_mxK ?row_sub. Qed. Arguments mulsmx_subP {m1 m2 m n R1 R2 R}. Lemma mulsmxS m1 m2 m3 m4 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) (R4 : 'A_(m4, n)) : (R1 <= R3 -> R2 <= R4 -> R1 * R2 <= R3 * R4)%MS. Proof. move=> sR13 sR24; apply/mulsmx_subP=> A1 A2 R_A1 R_A2. by apply: mem_mulsmx; [apply: submx_trans sR13 | apply: submx_trans sR24]. Qed. Lemma muls_eqmx m1 m2 m3 m4 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) (R4 : 'A_(m4, n)) : (R1 :=: R3 -> R2 :=: R4 -> R1 * R2 = R3 * R4)%MS. Proof. move=> eqR13 eqR24; rewrite -(genmx_muls R1 R2) -(genmx_muls R3 R4). by apply/genmxP; rewrite !mulsmxS ?eqR13 ?eqR24. Qed. Lemma mulsmxP m1 m2 n A (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : reflect (exists2 A1, forall i, A1 i \in R1 & exists2 A2, forall i, A2 i \in R2 & A = \sum_(i < n ^ 2) A1 i *m A2 i) (A \in R1 * R2)%MS. Proof. apply: (iffP idP) => [R_A|[A1 R_A1 [A2 R_A2 ->{A}]]]; last first. by rewrite linear_sum summx_sub // => i _; rewrite mem_mulsmx. have{R_A}: (A \in R1 * <<R2>>)%MS. by apply: memmx_subP R_A; rewrite mulsmxS ?genmxE. case/memmx_sumsP=> A_ -> R_A; pose A2_ i := vec_mx (row i <<R2>>%MS). pose A1_ i := mxvec (A_ i) *m pinvmx (R1 *m lin_mx (mulmxr (A2_ i))) *m R1. exists (vec_mx \o A1_) => [i|]; first by rewrite vec_mxK submxMl. exists A2_ => [i|]; first by rewrite vec_mxK -(genmxE R2) row_sub. apply: eq_bigr => i _; rewrite -[_ *m _](mx_rV_lin (mulmxr (A2_ i))). by rewrite -mulmxA mulmxKpV ?mxvecK // -(genmxE (_ *m _)) R_A. Qed. Arguments mulsmxP {m1 m2 n A R1 R2}. Lemma mulsmxA m1 m2 m3 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) : (R1 * (R2 * R3) = R1 * R2 * R3)%MS. Proof. rewrite -(genmx_muls (_ * _)%MS) -genmx_muls; apply/genmxP/andP; split. apply/mulsmx_subP=> A1 A23 R_A1; case/mulsmxP=> A2 R_A2 [A3 R_A3 ->{A23}]. by rewrite !linear_sum summx_sub //= => i _; rewrite mulmxA !mem_mulsmx. apply/mulsmx_subP=> _ A3 /mulsmxP[A1 R_A1 [A2 R_A2 ->]] R_A3. rewrite mulmx_suml linear_sum summx_sub //= => i _. by rewrite -mulmxA !mem_mulsmx. Qed. Lemma mulsmxDl m1 m2 m3 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) : ((R1 + R2) * R3 = R1 * R3 + R2 * R3)%MS. Proof. rewrite -(genmx_muls R2 R3) -(genmx_muls R1 R3) -genmx_muls -genmx_adds. apply/genmxP; rewrite andbC addsmx_sub !mulsmxS ?addsmxSl ?addsmxSr //=. apply/mulsmx_subP=> _ A3 /memmx_addsP[A [R_A1 R_A2 ->]] R_A3. by rewrite mulmxDl linearD addmx_sub_adds ?mem_mulsmx. Qed. Lemma mulsmxDr m1 m2 m3 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) (R3 : 'A_(m3, n)) : (R1 * (R2 + R3) = R1 * R2 + R1 * R3)%MS. Proof. rewrite -(genmx_muls R1 R3) -(genmx_muls R1 R2) -genmx_muls -genmx_adds. apply/genmxP; rewrite andbC addsmx_sub !mulsmxS ?addsmxSl ?addsmxSr //=. apply/mulsmx_subP=> A1 _ R_A1 /memmx_addsP[A [R_A2 R_A3 ->]]. by rewrite mulmxDr linearD addmx_sub_adds ?mem_mulsmx. Qed. Lemma mulsmx0 m1 m2 n (R1 : 'A_(m1, n)) : (R1 * (0 : 'A_(m2, n)) = 0)%MS. Proof. apply/eqP; rewrite -submx0; apply/mulsmx_subP=> A1 A0 _. by rewrite [A0 \in 0]eqmx0 => /memmx0->; rewrite mulmx0 mem0mx. Qed. Lemma muls0mx m1 m2 n (R2 : 'A_(m2, n)) : ((0 : 'A_(m1, n)) * R2 = 0)%MS. Proof. apply/eqP; rewrite -submx0; apply/mulsmx_subP=> A0 A2. by rewrite [A0 \in 0]eqmx0 => /memmx0->; rewrite mul0mx mem0mx. Qed. Definition left_mx_ideal m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) := (R1 * R2 <= R2)%MS. Definition right_mx_ideal m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) := (R2 * R1 <= R2)%MS. Definition mx_ideal m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) := left_mx_ideal R1 R2 && right_mx_ideal R1 R2. Definition mxring_id m n (R : 'A_(m, n)) e := [/\ e != 0, e \in R, forall A, A \in R -> e *m A = A & forall A, A \in R -> A *m e = A]%MS. Definition has_mxring_id m n (R : 'A[F]_(m , n)) := (R != 0) && (row_mx 0 (row_mx (mxvec R) (mxvec R)) <= row_mx (cokermx R) (row_mx (lin_mx (mulmx R \o lin_mulmx)) (lin_mx (mulmx R \o lin_mulmxr))))%MS. Definition mxring m n (R : 'A_(m, n)) := left_mx_ideal R R && has_mxring_id R. Lemma mxring_idP m n (R : 'A_(m, n)) : reflect (exists e, mxring_id R e) (has_mxring_id R). Proof. apply: (iffP andP) => [[nzR] | [e [nz_e Re ideR idRe]]]. case/submxP=> v; rewrite -[v]vec_mxK; move/vec_mx: v => e. rewrite !mul_mx_row; case/eq_row_mx => /eqP. rewrite eq_sym -submxE => Re. case/eq_row_mx; rewrite !{1}mul_rV_lin1 /= mxvecK. set u := (_ *m _) => /(can_inj mxvecK) idRe /(can_inj mxvecK) ideR. exists e; split=> // [ | A /submxP[a defA] | A /submxP[a defA]]. - by apply: contra nzR; rewrite ideR => /eqP->; rewrite !linear0. - by rewrite -{2}[A]mxvecK defA idRe mulmxA mx_rV_lin -defA /= mxvecK. by rewrite -{2}[A]mxvecK defA ideR mulmxA mx_rV_lin -defA /= mxvecK. split. by apply: contraNneq nz_e => R0; rewrite R0 eqmx0 in Re; rewrite (memmx0 Re). apply/submxP; exists (mxvec e); rewrite !mul_mx_row !{1}mul_rV_lin1. rewrite submxE in Re; rewrite {Re}(eqP Re). congr (row_mx 0 (row_mx (mxvec _) (mxvec _))); apply/row_matrixP=> i. by rewrite !row_mul !mul_rV_lin1 /= mxvecK ideR vec_mxK ?row_sub. by rewrite !row_mul !mul_rV_lin1 /= mxvecK idRe vec_mxK ?row_sub. Qed. Arguments mxring_idP {m n R}. Section CentMxDef. Variables (m n : nat) (R : 'A[F]_(m, n)). Definition cent_mx_fun (B : 'M[F]_n) := R *m lin_mx (mulmxr B \- mulmx B). Lemma cent_mx_fun_is_linear : linear cent_mx_fun. Proof. move=> a A B; apply/row_matrixP=> i; rewrite linearP row_mul mul_rV_lin. rewrite /= [row i _ as v in a *: v]row_mul mul_rV_lin row_mul mul_rV_lin. by rewrite -linearP -(linearP (mulmx (vec_mx (row i R)) \- mulmxr _)). Qed. HB.instance Definition _ := GRing.isSemilinear.Build F 'M[F]_n 'M[F]_(m, n * n) _ cent_mx_fun (GRing.semilinear_linear cent_mx_fun_is_linear). Definition cent_mx := kermx (lin_mx cent_mx_fun). Definition center_mx := (R :&: cent_mx)%MS. End CentMxDef. Local Notation "''C' ( R )" := (cent_mx R) : matrix_set_scope. Local Notation "''Z' ( R )" := (center_mx R) : matrix_set_scope. Lemma cent_rowP m n B (R : 'A_(m, n)) : reflect (forall i (A := vec_mx (row i R)), A *m B = B *m A) (B \in 'C(R))%MS. Proof. apply: (iffP sub_kermxP); rewrite mul_vec_lin => cBE. move/(canRL mxvecK): cBE => cBE i A /=; move/(congr1 (row i)): cBE. rewrite row_mul mul_rV_lin -/A; move/(canRL mxvecK). by move/(canRL (subrK _)); rewrite !linear0 add0r. apply: (canLR vec_mxK); apply/row_matrixP=> i. by rewrite row_mul mul_rV_lin /= cBE subrr !linear0. Qed. Arguments cent_rowP {m n B R}. Lemma cent_mxP m n B (R : 'A_(m, n)) : reflect (forall A, A \in R -> A *m B = B *m A) (B \in 'C(R))%MS. Proof. apply: (iffP cent_rowP) => cEB => [A sAE | i A]. rewrite -[A]mxvecK -(mulmxKpV sAE); move: (mxvec A *m _) => u. rewrite !mulmx_sum_row !linear_sum mulmx_suml; apply: eq_bigr => i _ /=. by rewrite 2!linearZ -scalemxAl /= cEB. by rewrite cEB // vec_mxK row_sub. Qed. Arguments cent_mxP {m n B R}. Lemma scalar_mx_cent m n a (R : 'A_(m, n)) : (a%:M \in 'C(R))%MS. Proof. by apply/cent_mxP=> A _; apply: scalar_mxC. Qed. Lemma center_mx_sub m n (R : 'A_(m, n)) : ('Z(R) <= R)%MS. Proof. exact: capmxSl. Qed. Lemma center_mxP m n A (R : 'A_(m, n)) : reflect (A \in R /\ forall B, B \in R -> B *m A = A *m B) (A \in 'Z(R))%MS. Proof. rewrite sub_capmx; case R_A: (A \in R); last by right; case. by apply: (iffP cent_mxP) => [cAR | [_ cAR]]. Qed. Arguments center_mxP {m n A R}. Lemma mxring_id_uniq m n (R : 'A_(m, n)) e1 e2 : mxring_id R e1 -> mxring_id R e2 -> e1 = e2. Proof. by case=> [_ Re1 idRe1 _] [_ Re2 _ ide2R]; rewrite -(idRe1 _ Re2) ide2R. Qed. Lemma cent_mx_ideal m n (R : 'A_(m, n)) : left_mx_ideal 'C(R)%MS 'C(R)%MS. Proof. apply/mulsmx_subP=> A1 A2 C_A1 C_A2; apply/cent_mxP=> B R_B. by rewrite mulmxA (cent_mxP C_A1) // -!mulmxA (cent_mxP C_A2). Qed. Lemma cent_mx_ring m n (R : 'A_(m, n)) : n > 0 -> mxring 'C(R)%MS. Proof. move=> n_gt0; rewrite /mxring cent_mx_ideal; apply/mxring_idP. exists 1%:M; split=> [||A _|A _]; rewrite ?mulmx1 ?mul1mx ?scalar_mx_cent //. by rewrite -mxrank_eq0 mxrank1 -lt0n. Qed. Lemma mxdirect_adds_center m1 m2 n (R1 : 'A_(m1, n)) (R2 : 'A_(m2, n)) : mx_ideal (R1 + R2)%MS R1 -> mx_ideal (R1 + R2)%MS R2 -> mxdirect (R1 + R2) -> ('Z((R1 + R2)%MS) :=: 'Z(R1) + 'Z(R2))%MS. Proof. case/andP=> idlR1 idrR1 /andP[idlR2 idrR2] /mxdirect_addsP dxR12. apply/eqmxP/andP; split. apply/memmx_subP=> z0; rewrite sub_capmx => /andP[]. case/memmx_addsP=> z [R1z1 R2z2 ->{z0}] Cz. rewrite linearD addmx_sub_adds //= ?sub_capmx ?R1z1 ?R2z2 /=. apply/cent_mxP=> A R1_A; have R_A := submx_trans R1_A (addsmxSl R1 R2). have Rz2 := submx_trans R2z2 (addsmxSr R1 R2). rewrite -{1}[z.1](addrK z.2) mulmxBr (cent_mxP Cz) // mulmxDl. rewrite [A *m z.2]memmx0 1?[z.2 *m A]memmx0 ?addrK //. by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). apply/cent_mxP=> A R2_A; have R_A := submx_trans R2_A (addsmxSr R1 R2). have Rz1 := submx_trans R1z1 (addsmxSl R1 R2). rewrite -{1}[z.2](addKr z.1) mulmxDr (cent_mxP Cz) // mulmxDl. rewrite mulmxN [A *m z.1]memmx0 1?[z.1 *m A]memmx0 ?addKr //. by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). rewrite addsmx_sub; apply/andP; split. apply/memmx_subP=> z; rewrite sub_capmx => /andP[R1z cR1z]. have Rz := submx_trans R1z (addsmxSl R1 R2). rewrite sub_capmx Rz; apply/cent_mxP=> A0. case/memmx_addsP=> A [R1_A1 R2_A2] ->{A0}. have R_A2 := submx_trans R2_A2 (addsmxSr R1 R2). rewrite mulmxDl mulmxDr (cent_mxP cR1z) //; congr (_ + _). rewrite [A.2 *m z]memmx0 1?[z *m A.2]memmx0 //. by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). apply/memmx_subP=> z; rewrite !sub_capmx => /andP[R2z cR2z]. have Rz := submx_trans R2z (addsmxSr R1 R2); rewrite Rz. apply/cent_mxP=> _ /memmx_addsP[A [R1_A1 R2_A2 ->]]. rewrite mulmxDl mulmxDr (cent_mxP cR2z _ R2_A2) //; congr (_ + _). have R_A1 := submx_trans R1_A1 (addsmxSl R1 R2). rewrite [A.1 *m z]memmx0 1?[z *m A.1]memmx0 //. by rewrite -dxR12 sub_capmx (mulsmx_subP idlR1) // (mulsmx_subP idrR2). by rewrite -dxR12 sub_capmx (mulsmx_subP idrR1) // (mulsmx_subP idlR2). Qed. Lemma mxdirect_sums_center (I : finType) m n (R : 'A_(m, n)) R_ : (\sum_i R_ i :=: R)%MS -> mxdirect (\sum_i R_ i) -> (forall i : I, mx_ideal R (R_ i)) -> ('Z(R) :=: \sum_i 'Z(R_ i))%MS. Proof. move=> defR dxR idealR. have sR_R: (R_ _ <= R)%MS by move=> i; rewrite -defR (sumsmx_sup i). have anhR i j A B : i != j -> A \in R_ i -> B \in R_ j -> A *m B = 0. move=> ne_ij RiA RjB; apply: memmx0. have [[_ idRiR] [idRRj _]] := (andP (idealR i), andP (idealR j)). rewrite -(mxdirect_sumsP dxR j) // sub_capmx (sumsmx_sup i) //. by rewrite (mulsmx_subP idRRj) // (memmx_subP (sR_R i)). by rewrite (mulsmx_subP idRiR) // (memmx_subP (sR_R j)). apply/eqmxP/andP; split. apply/memmx_subP=> Z; rewrite sub_capmx => /andP[]. rewrite -{1}defR => /memmx_sumsP[z ->{Z} Rz cRz]. apply/memmx_sumsP; exists z => // i; rewrite sub_capmx Rz. apply/cent_mxP=> A RiA; have:= cent_mxP cRz A (memmx_subP (sR_R i) A RiA). rewrite (bigD1 i) //= mulmxDl mulmxDr mulmx_suml mulmx_sumr. by rewrite !big1 ?addr0 // => j; last rewrite eq_sym; move/anhR->. apply/sumsmx_subP => i _; apply/memmx_subP=> z; rewrite sub_capmx. case/andP=> Riz cRiz; rewrite sub_capmx (memmx_subP (sR_R i)) //=. apply/cent_mxP=> A; rewrite -{1}defR; case/memmx_sumsP=> a -> R_a. rewrite (bigD1 i) // mulmxDl mulmxDr mulmx_suml mulmx_sumr. rewrite !big1 => [|j|j]; first by rewrite !addr0 (cent_mxP cRiz). by rewrite eq_sym => /anhR->. by move/anhR->. Qed. End MatrixAlgebra. Arguments mulsmx {F m1%_N m2%_N n%_N} R1%_MS R2%_MS. Arguments left_mx_ideal {F m1%_N m2%_N n%_N} R%_MS S%_MS : rename. Arguments right_mx_ideal {F m1%_N m2%_N n%_N} R%_MS S%_MS : rename. Arguments mx_ideal {F m1%_N m2%_N n%_N} R%_MS S%_MS : rename. Arguments mxring_id {F m%_N n%_N} R%_MS e%_R. Arguments has_mxring_id {F m%_N n%_N} R%_MS. Arguments mxring {F m%_N n%_N} R%_MS. Arguments cent_mx {F m%_N n%_N} R%_MS. Arguments center_mx {F m%_N n%_N} R%_MS. Notation "A \in R" := (submx (mxvec A) R) : matrix_set_scope. Notation "R * S" := (mulsmx R S) : matrix_set_scope. Notation "''C' ( R )" := (cent_mx R) : matrix_set_scope. Notation "''C_' R ( S )" := (R :&: 'C(S))%MS : matrix_set_scope. Notation "''C_' ( R ) ( S )" := ('C_R(S))%MS (only parsing) : matrix_set_scope. Notation "''Z' ( R )" := (center_mx R) : matrix_set_scope. Arguments memmx_subP {F m1 m2 n R1 R2}. Arguments memmx_eqP {F m1 m2 n R1 R2}. Arguments memmx_addsP {F m1 m2 n} A {R1 R2}. Arguments memmx_sumsP {F I P n A R_}. Arguments mulsmx_subP {F m1 m2 m n R1 R2 R}. Arguments mulsmxP {F m1 m2 n A R1 R2}. Arguments mxring_idP F {m n R}. Arguments cent_rowP {F m n B R}. Arguments cent_mxP {F m n B R}. Arguments center_mxP {F m n A R}. (* Parametricity for the row-space/F-algebra theory. *) Section MapMatrixSpaces. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Lemma Gaussian_elimination_map m n (A : 'M_(m, n)) : Gaussian_elimination_ A^f = ((col_ebase A)^f, (row_ebase A)^f, \rank A). Proof. rewrite mxrankE /row_ebase /col_ebase unlock. elim: m n A => [|m IHm] [|n] A /=; rewrite ?map_mx1 //. set pAnz := [pred k | A k.1 k.2 != 0]. rewrite (@eq_pick _ _ pAnz) => [|k]; last by rewrite /= mxE fmorph_eq0. case: {+}(pick _) => [[i j]|]; last by rewrite !map_mx1. rewrite mxE -fmorphV -map_xcol -map_xrow -map_dlsubmx -map_drsubmx. rewrite -map_ursubmx -map_mxZ -map_mxM -map_mxB {}IHm /=. case: {+}(Gaussian_elimination_ _) => [[L U] r] /=; rewrite map_xrow map_xcol. by rewrite !(@map_block_mx _ _ f 1 _ 1) !map_mx0 ?map_mx1 ?map_scalar_mx. Qed. Lemma mxrank_map m n (A : 'M_(m, n)) : \rank A^f = \rank A. Proof. by rewrite mxrankE Gaussian_elimination_map. Qed. Lemma row_free_map m n (A : 'M_(m, n)) : row_free A^f = row_free A. Proof. by rewrite /row_free mxrank_map. Qed. Lemma row_full_map m n (A : 'M_(m, n)) : row_full A^f = row_full A. Proof. by rewrite /row_full mxrank_map. Qed. Lemma map_row_ebase m n (A : 'M_(m, n)) : (row_ebase A)^f = row_ebase A^f. Proof. by rewrite {2}/row_ebase unlock Gaussian_elimination_map. Qed. Lemma map_col_ebase m n (A : 'M_(m, n)) : (col_ebase A)^f = col_ebase A^f. Proof. by rewrite {2}/col_ebase unlock Gaussian_elimination_map. Qed. Lemma map_row_base m n (A : 'M_(m, n)) : (row_base A)^f = castmx (mxrank_map A, erefl n) (row_base A^f). Proof. move: (mxrank_map A); rewrite {2}/row_base mxrank_map => eqrr. by rewrite castmx_id map_mxM map_pid_mx map_row_ebase. Qed. Lemma map_col_base m n (A : 'M_(m, n)) : (col_base A)^f = castmx (erefl m, mxrank_map A) (col_base A^f). Proof. move: (mxrank_map A); rewrite {2}/col_base mxrank_map => eqrr. by rewrite castmx_id map_mxM map_pid_mx map_col_ebase. Qed. Lemma map_pinvmx m n (A : 'M_(m, n)) : (pinvmx A)^f = pinvmx A^f. Proof. rewrite !map_mxM !map_invmx map_row_ebase map_col_ebase. by rewrite map_pid_mx -mxrank_map. Qed. Lemma map_kermx m n (A : 'M_(m, n)) : (kermx A)^f = kermx A^f. Proof. by rewrite !map_mxM map_invmx map_col_ebase -mxrank_map map_copid_mx. Qed. Lemma map_cokermx m n (A : 'M_(m, n)) : (cokermx A)^f = cokermx A^f. Proof. by rewrite !map_mxM map_invmx map_row_ebase -mxrank_map map_copid_mx. Qed. Lemma map_submx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A^f <= B^f)%MS = (A <= B)%MS. Proof. by rewrite !submxE -map_cokermx -map_mxM map_mx_eq0. Qed. Lemma map_ltmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A^f < B^f)%MS = (A < B)%MS. Proof. by rewrite /ltmx !map_submx. Qed. Lemma map_eqmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A^f :=: B^f)%MS <-> (A :=: B)%MS. Proof. split=> [/eqmxP|eqAB]; first by rewrite !map_submx => /eqmxP. by apply/eqmxP; rewrite !map_submx !eqAB !submx_refl. Qed. Lemma map_genmx m n (A : 'M_(m, n)) : (<<A>>^f :=: <<A^f>>)%MS. Proof. by apply/eqmxP; rewrite !(genmxE, map_submx) andbb. Qed. Lemma map_addsmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (((A + B)%MS)^f :=: A^f + B^f)%MS. Proof. by apply/eqmxP; rewrite !addsmxE -map_col_mx !map_submx !addsmxE andbb. Qed. Lemma map_capmx_gen m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (capmx_gen A B)^f = capmx_gen A^f B^f. Proof. by rewrite map_mxM map_lsubmx map_kermx map_col_mx. Qed. Lemma map_capmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : ((A :&: B)^f :=: A^f :&: B^f)%MS. Proof. by apply/eqmxP; rewrite !capmxE -map_capmx_gen !map_submx -!capmxE andbb. Qed. Lemma map_complmx m n (A : 'M_(m, n)) : (A^C^f = A^f^C)%MS. Proof. by rewrite map_mxM map_row_ebase -mxrank_map map_copid_mx. Qed. Lemma map_diffmx m1 m2 n (A : 'M_(m1, n)) (B : 'M_(m2, n)) : ((A :\: B)^f :=: A^f :\: B^f)%MS. Proof. apply/eqmxP; rewrite !diffmxE -map_capmx_gen -map_complmx. by rewrite -!map_capmx !map_submx -!diffmxE andbb. Qed. Lemma map_eigenspace n (g : 'M_n) a : (eigenspace g a)^f = eigenspace g^f (f a). Proof. by rewrite map_kermx map_mxB ?map_scalar_mx. Qed. Lemma eigenvalue_map n (g : 'M_n) a : eigenvalue g^f (f a) = eigenvalue g a. Proof. by rewrite /eigenvalue -map_eigenspace map_mx_eq0. Qed. Lemma memmx_map m n A (E : 'A_(m, n)) : (A^f \in E^f)%MS = (A \in E)%MS. Proof. by rewrite -map_mxvec map_submx. Qed. Lemma map_mulsmx m1 m2 n (E1 : 'A_(m1, n)) (E2 : 'A_(m2, n)) : ((E1 * E2)%MS^f :=: E1^f * E2^f)%MS. Proof. rewrite /mulsmx; elim/big_rec2: _ => [|i A Af _ eqA]; first by rewrite map_mx0. apply: (eqmx_trans (map_addsmx _ _)); apply: adds_eqmx {A Af}eqA. apply/eqmxP; rewrite !map_genmx !genmxE map_mxM. apply/rV_eqP=> u; congr (u <= _ *m _)%MS. by apply: map_lin_mx => //= A; rewrite map_mxM // map_vec_mx map_row. Qed. Lemma map_cent_mx m n (E : 'A_(m, n)) : ('C(E)%MS)^f = 'C(E^f)%MS. Proof. rewrite map_kermx; congr kermx; apply: map_lin_mx => A; rewrite map_mxM. by congr (_ *m _); apply: map_lin_mx => B; rewrite map_mxB ?map_mxM. Qed. Lemma map_center_mx m n (E : 'A_(m, n)) : (('Z(E))^f :=: 'Z(E^f))%MS. Proof. by rewrite /center_mx -map_cent_mx; apply: map_capmx. Qed. End MapMatrixSpaces. Section RowColDiagBlockMatrix. Import tagnat. Context {F : fieldType} {n : nat} {p_ : 'I_n -> nat}. Lemma eqmx_col {m} (V_ : forall i, 'M[F]_(p_ i, m)) : (\mxcol_i V_ i :=: \sum_i <<V_ i>>)%MS. Proof. apply/eqmxP/andP; split. apply/row_subP => i; rewrite row_mxcol. by rewrite (sumsmx_sup (sig1 i))// genmxE row_sub. apply/sumsmx_subP => i0 _; rewrite genmxE; apply/row_subP => j. apply: (eq_row_sub (Rank _ j)); apply/rowP => k. by rewrite !mxE Rank2K; case: _ / esym; rewrite cast_ord_id. Qed. Lemma rank_mxdiag (V_ : forall i, 'M[F]_(p_ i)) : (\rank (\mxdiag_i V_ i) = \sum_i \rank (V_ i))%N. Proof. elim: {+}n {+}p_ V_ => [|m IHm] q_ V_. by move: (\mxdiag__ _); rewrite !big_ord0 => M; rewrite flatmx0 mxrank0. rewrite mxdiag_recl [RHS]big_ord_recl/= -IHm. by case: _ / mxsize_recl; rewrite ?castmx_id rank_diag_block_mx. Qed. End RowColDiagBlockMatrix.
maximal.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice. From mathcomp Require Import div fintype finfun bigop finset prime binomial. From mathcomp Require Import fingroup morphism perm automorphism quotient. From mathcomp Require Import action commutator gproduct gfunctor ssralg . From mathcomp Require Import countalg finalg zmodp cyclic pgroup center gseries. From mathcomp Require Import nilpotent sylow abelian finmodule. (******************************************************************************) (* This file establishes basic properties of several important classes of *) (* maximal subgroups: maximal, max and min normal, simple, characteristically *) (* simple subgroups, the Frattini and Fitting subgroups, the Thompson *) (* critical subgroup, special and extra-special groups, and self-centralising *) (* normal (SCN) subgroups. In detail, we define: *) (* charsimple G == G is characteristically simple (it has no nontrivial *) (* characteristic subgroups, and is nontrivial) *) (* 'Phi(G) == the Frattini subgroup of G, i.e., the intersection of *) (* all its maximal proper subgroups. *) (* 'F(G) == the Fitting subgroup of G, i.e., the largest normal *) (* nilpotent subgroup of G (defined as the (direct) *) (* product of all the p-cores of G). *) (* critical C G == C is a critical subgroup of G: C is characteristic *) (* (but not functorial) in G, the center of C contains *) (* both its Frattini subgroup and the commutator [G, C], *) (* and is equal to the centraliser of C in G. The *) (* Thompson_critical theorem provides critical subgroups *) (* for p-groups; we also show that in this case the *) (* centraliser of C in Aut G is a p-group as well. *) (* special G == G is a special group: its center, Frattini, and *) (* derived sugroups coincide (we follow Aschbacher in *) (* not considering nontrivial elementary abelian groups *) (* as special); we show that a p-group factors under *) (* coprime action into special groups (Aschbacher 24.7). *) (* extraspecial G == G is a special group whose center has prime order *) (* (hence G is non-abelian). *) (* 'SCN(G) == the set of self-centralising normal abelian subgroups *) (* of G (the A <| G such that 'C_G(A) = A). *) (* 'SCN_n(G) == the subset of 'SCN(G) containing all groups with rank *) (* at least n (i.e., A \in 'SCN(G) and 'm(A) >= n). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section Defs. Variable gT : finGroupType. Implicit Types (A B D : {set gT}) (G : {group gT}). Definition charsimple A := [min A of G | G :!=: 1 & G \char A]. Definition Frattini A := \bigcap_(G : {group gT} | maximal_eq G A) G. Canonical Frattini_group A : {group gT} := Eval hnf in [group of Frattini A]. Definition Fitting A := \big[dprod/1]_(p <- primes #|A|) 'O_p(A). Lemma Fitting_group_set G : group_set (Fitting G). Proof. suffices [F ->]: exists F : {group gT}, Fitting G = F by apply: groupP. rewrite /Fitting; elim: primes (primes_uniq #|G|) => [_|p r IHr] /=. by exists [1 gT]%G; rewrite big_nil. case/andP=> rp /IHr[F defF]; rewrite big_cons defF. suffices{IHr} /and3P[p'F sFG nFG]: p^'.-group F && (F <| G). have nFGp: 'O_p(G) \subset 'N(F) := gFsub_trans _ nFG. have pGp: p.-group('O_p(G)) := pcore_pgroup p G. have{pGp} tiGpF: 'O_p(G) :&: F = 1 by rewrite coprime_TIg ?(pnat_coprime pGp). exists ('O_p(G) <*> F)%G; rewrite dprodEY // (sameP commG1P trivgP) -tiGpF. by rewrite subsetI commg_subl commg_subr (subset_trans sFG) // gFnorm. move/bigdprodWY: defF => <- {F}; elim: r rp => [_|q r IHr] /=. by rewrite big_nil gen0 pgroup1 normal1. rewrite inE eq_sym big_cons -joingE -joing_idr => /norP[qp /IHr {IHr}]. set F := <<_>> => /andP[p'F nsFG]. rewrite norm_joinEl /= -/F; last exact/gFsub_trans/normal_norm. by rewrite pgroupM p'F normalM ?pcore_normal //= (pi_pgroup (pcore_pgroup q G)). Qed. Canonical Fitting_group G := group (Fitting_group_set G). Definition critical A B := [/\ A \char B, Frattini A \subset 'Z(A), [~: B, A] \subset 'Z(A) & 'C_B(A) = 'Z(A)]. Definition special A := Frattini A = 'Z(A) /\ A^`(1) = 'Z(A). Definition extraspecial A := special A /\ prime #|'Z(A)|. Definition SCN B := [set A : {group gT} | A <| B & 'C_B(A) == A]. Definition SCN_at n B := [set A in SCN B | n <= 'r(A)]. End Defs. Arguments charsimple {gT} A%_g. Arguments Frattini {gT} A%_g. Arguments Fitting {gT} A%_g. Arguments critical {gT} A%_g B%_g. Arguments special {gT} A%_g. Arguments extraspecial {gT} A%_g. Arguments SCN {gT} B%_g. Arguments SCN_at {gT} n%_N B%_g. Notation "''Phi' ( A )" := (Frattini A) (format "''Phi' ( A )") : group_scope. Notation "''Phi' ( G )" := (Frattini_group G) : Group_scope. Notation "''F' ( G )" := (Fitting G) (format "''F' ( G )") : group_scope. Notation "''F' ( G )" := (Fitting_group G) : Group_scope. Notation "''SCN' ( B )" := (SCN B) (format "''SCN' ( B )") : group_scope. Notation "''SCN_' n ( B )" := (SCN_at n B) (n at level 2, format "''SCN_' n ( B )") : group_scope. Section PMax. Variables (gT : finGroupType) (p : nat) (P M : {group gT}). Hypothesis pP : p.-group P. Lemma p_maximal_normal : maximal M P -> M <| P. Proof. case/maxgroupP=> /andP[sMP sPM] maxM; rewrite /normal sMP. have:= subsetIl P 'N(M); rewrite subEproper. case/predU1P=> [/setIidPl-> // | /maxM/= SNM]; case/negP: sPM. rewrite (nilpotent_sub_norm (pgroup_nil pP) sMP) //. by rewrite SNM // subsetI sMP normG. Qed. Lemma p_maximal_index : maximal M P -> #|P : M| = p. Proof. move=> maxM; have nM := p_maximal_normal maxM. rewrite -card_quotient ?normal_norm //. rewrite -(quotient_maximal _ nM) ?normal_refl // trivg_quotient in maxM. case/maxgroupP: maxM; rewrite properEneq eq_sym sub1G andbT /=. case/(pgroup_pdiv (quotient_pgroup M pP)) => p_pr /Cauchy[] // xq. rewrite /order -cycle_subG subEproper => /predU1P[-> // | sxPq oxq_p _]. by move/(_ _ sxPq (sub1G _)) => xq1; rewrite -oxq_p xq1 cards1 in p_pr. Qed. Lemma p_index_maximal : M \subset P -> prime #|P : M| -> maximal M P. Proof. move=> sMP /primeP[lt1PM pr_PM]. apply/maxgroupP; rewrite properEcard sMP -(Lagrange sMP). rewrite -{1}(muln1 #|M|) ltn_pmul2l //; split=> // H sHP sMH. apply/eqP; rewrite eq_sym eqEcard sMH. case/orP: (pr_PM _ (indexSg sMH (proper_sub sHP))) => /eqP iM. by rewrite -(Lagrange sMH) iM muln1 /=. by have:= proper_card sHP; rewrite -(Lagrange sMH) iM Lagrange ?ltnn. Qed. End PMax. Section Frattini. Variables gT : finGroupType. Implicit Type G M : {group gT}. Lemma Phi_sub G : 'Phi(G) \subset G. Proof. by rewrite bigcap_inf // /maximal_eq eqxx. Qed. Lemma Phi_sub_max G M : maximal M G -> 'Phi(G) \subset M. Proof. by move=> maxM; rewrite bigcap_inf // /maximal_eq predU1r. Qed. Lemma Phi_proper G : G :!=: 1 -> 'Phi(G) \proper G. Proof. move/eqP; case/maximal_exists: (sub1G G) => [<- //| [M maxM _] _]. exact: sub_proper_trans (Phi_sub_max maxM) (maxgroupp maxM). Qed. Lemma Phi_nongen G X : 'Phi(G) <*> X = G -> <<X>> = G. Proof. move=> defG; have: <<X>> \subset G by rewrite -{1}defG genS ?subsetUr. case/maximal_exists=> //= [[M maxM]]; rewrite gen_subG => sXM. case/andP: (maxgroupp maxM) => _ /negP[]. by rewrite -defG gen_subG subUset Phi_sub_max. Qed. Lemma Frattini_continuous (rT : finGroupType) G (f : {morphism G >-> rT}) : f @* 'Phi(G) \subset 'Phi(f @* G). Proof. apply/bigcapsP=> M maxM; rewrite sub_morphim_pre ?Phi_sub // bigcap_inf //. have {2}<-: f @*^-1 (f @* G) = G by rewrite morphimGK ?subsetIl. by rewrite morphpre_maximal_eq ?maxM //; case/maximal_eqP: maxM. Qed. End Frattini. Canonical Frattini_igFun := [igFun by Phi_sub & Frattini_continuous]. Canonical Frattini_gFun := [gFun by Frattini_continuous]. Section Frattini0. Variable gT : finGroupType. Implicit Types (rT : finGroupType) (D G : {group gT}). Lemma Phi_char G : 'Phi(G) \char G. Proof. exact: gFchar. Qed. Lemma Phi_normal G : 'Phi(G) <| G. Proof. exact: gFnormal. Qed. Lemma injm_Phi rT D G (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> f @* 'Phi(G) = 'Phi(f @* G). Proof. exact: injmF. Qed. Lemma isog_Phi rT G (H : {group rT}) : G \isog H -> 'Phi(G) \isog 'Phi(H). Proof. exact: gFisog. Qed. Lemma PhiJ G x : 'Phi(G :^ x) = 'Phi(G) :^ x. Proof. rewrite -{1}(setIid G) -(setIidPr (Phi_sub G)) -!morphim_conj. by rewrite injm_Phi ?injm_conj. Qed. End Frattini0. Section Frattini2. Variables gT : finGroupType. Implicit Type G : {group gT}. Lemma Phi_quotient_id G : 'Phi (G / 'Phi(G)) = 1. Proof. apply/trivgP; rewrite -cosetpreSK cosetpre1 /=; apply/bigcapsP=> M maxM. have nPhi := Phi_normal G; have nPhiM: 'Phi(G) <| M. by apply: normalS nPhi; [apply: bigcap_inf | case/maximal_eqP: maxM]. by rewrite sub_cosetpre_quo ?bigcap_inf // quotient_maximal_eq. Qed. Lemma Phi_quotient_cyclic G : cyclic (G / 'Phi(G)) -> cyclic G. Proof. case/cyclicP=> /= Px; case: (cosetP Px) => x nPx ->{Px} defG. apply/cyclicP; exists x; symmetry; apply: Phi_nongen. rewrite -joing_idr norm_joinEr -?quotientK ?cycle_subG //. by rewrite /quotient morphim_cycle //= -defG quotientGK ?Phi_normal. Qed. Variables (p : nat) (P : {group gT}). Lemma trivg_Phi : p.-group P -> ('Phi(P) == 1) = p.-abelem P. Proof. move=> pP; case: (eqsVneq P 1) => [P1 | ntP]. by rewrite P1 abelem1 -subG1 -P1 Phi_sub. have [p_pr _ _] := pgroup_pdiv pP ntP. apply/eqP/idP=> [trPhi | abP]. apply/abelemP=> //; split=> [|x Px]. apply/commG1P/trivgP; rewrite -trPhi. apply/bigcapsP=> M /predU1P[-> | maxM]; first exact: der1_subG. have /andP[_ nMP]: M <| P := p_maximal_normal pP maxM. rewrite der1_min // cyclic_abelian // prime_cyclic // card_quotient //. by rewrite (p_maximal_index pP). apply/set1gP; rewrite -trPhi; apply/bigcapP=> M. case/predU1P=> [-> | maxM]; first exact: groupX. have /andP[_ nMP] := p_maximal_normal pP maxM. have nMx : x \in 'N(M) by apply: subsetP Px. apply: coset_idr; rewrite ?groupX ?morphX //=; apply/eqP. rewrite -(p_maximal_index pP maxM) -card_quotient // -order_dvdn cardSg //=. by rewrite cycle_subG mem_quotient. apply/trivgP/subsetP=> x Phi_x; rewrite -cycle_subG. have Px: x \in P by apply: (subsetP (Phi_sub P)). have sxP: <[x]> \subset P by rewrite cycle_subG. case/splitsP: (abelem_splits abP sxP) => K /complP[tiKx defP]. have [-> | nt_x] := eqVneq x 1; first by rewrite cycle1. have oxp := abelem_order_p abP Px nt_x. rewrite /= -tiKx subsetI subxx cycle_subG. apply: (bigcapP Phi_x); apply/orP; right. apply: p_index_maximal; rewrite -?divgS -defP ?mulG_subr //. by rewrite (TI_cardMg tiKx) mulnK // [#|_|]oxp. Qed. End Frattini2. Section Frattini3. Variables (gT : finGroupType) (p : nat) (P : {group gT}). Hypothesis pP : p.-group P. Lemma Phi_quotient_abelem : p.-abelem (P / 'Phi(P)). Proof. by rewrite -trivg_Phi ?morphim_pgroup //= Phi_quotient_id. Qed. Lemma Phi_joing : 'Phi(P) = P^`(1) <*> 'Mho^1(P). Proof. have [sPhiP nPhiP] := andP (Phi_normal P). apply/eqP; rewrite eqEsubset join_subG. case: (eqsVneq P 1) => [-> | ntP] in sPhiP *. by rewrite /= (trivgP sPhiP) sub1G der_subS Mho_sub. have [p_pr _ _] := pgroup_pdiv pP ntP. have [abP x1P] := abelemP p_pr Phi_quotient_abelem. apply/andP; split. have nMP: P \subset 'N(P^`(1) <*> 'Mho^1(P)) by rewrite normsY // !gFnorm. rewrite -quotient_sub1 ?gFsub_trans //=. suffices <-: 'Phi(P / (P^`(1) <*> 'Mho^1(P))) = 1 by apply: morphimF. apply/eqP; rewrite (trivg_Phi (morphim_pgroup _ pP)) /= -quotientE. apply/abelemP=> //; rewrite [abelian _]quotient_cents2 ?joing_subl //. split=> // _ /morphimP[x Nx Px ->] /=. rewrite -morphX //= coset_id // (MhoE 1 pP) joing_idr expn1. by rewrite mem_gen //; apply/setUP; right; apply: imset_f. rewrite -quotient_cents2 // [_ \subset 'C(_)]abP (MhoE 1 pP) gen_subG /=. apply/subsetP=> _ /imsetP[x Px ->]; rewrite expn1. have nPhi_x: x \in 'N('Phi(P)) by apply: (subsetP nPhiP). by rewrite coset_idr ?groupX ?morphX ?x1P ?mem_morphim. Qed. Lemma Phi_Mho : abelian P -> 'Phi(P) = 'Mho^1(P). Proof. by move=> cPP; rewrite Phi_joing (derG1P cPP) joing1G. Qed. End Frattini3. Section Frattini4. Variables (p : nat) (gT : finGroupType). Implicit Types (rT : finGroupType) (P G H K D : {group gT}). Lemma PhiS G H : p.-group H -> G \subset H -> 'Phi(G) \subset 'Phi(H). Proof. move=> pH sGH; rewrite (Phi_joing pH) (Phi_joing (pgroupS sGH pH)). by rewrite genS // setUSS ?dergS ?MhoS. Qed. Lemma morphim_Phi rT P D (f : {morphism D >-> rT}) : p.-group P -> P \subset D -> f @* 'Phi(P) = 'Phi(f @* P). Proof. move=> pP sPD; rewrite !(@Phi_joing _ p) ?morphim_pgroup //. rewrite morphim_gen ?subUset ?gFsub_trans // morphimU -joingE. by rewrite morphimR ?morphim_Mho. Qed. Lemma quotient_Phi P H : p.-group P -> P \subset 'N(H) -> 'Phi(P) / H = 'Phi(P / H). Proof. exact: morphim_Phi. Qed. (* This is Aschbacher (23.2) *) Lemma Phi_min G H : p.-group G -> G \subset 'N(H) -> p.-abelem (G / H) -> 'Phi(G) \subset H. Proof. move=> pG nHG; rewrite -trivg_Phi ?quotient_pgroup // -subG1 /=. by rewrite -(quotient_Phi pG) ?quotient_sub1 // gFsub_trans. Qed. Lemma Phi_cprod G H K : p.-group G -> H \* K = G -> 'Phi(H) \* 'Phi(K) = 'Phi(G). Proof. move=> pG defG; have [_ /mulG_sub[sHG sKG] cHK] := cprodP defG. rewrite cprodEY /=; last by rewrite (centSS (Phi_sub _) (Phi_sub _)). rewrite !(Phi_joing (pgroupS _ pG)) //=. have /cprodP[_ <- /cent_joinEr <-] := der_cprod 1 defG. have /cprodP[_ <- /cent_joinEr <-] := Mho_cprod 1 defG. by rewrite !joingA /= -!(joingA H^`(1)) (joingC K^`(1)). Qed. Lemma Phi_mulg H K : p.-group H -> p.-group K -> K \subset 'C(H) -> 'Phi(H * K) = 'Phi(H) * 'Phi(K). Proof. move=> pH pK cHK; have defHK := cprodEY cHK. have [|_ ->] /= := cprodP (Phi_cprod _ defHK); rewrite cent_joinEr //. by rewrite pgroupM pH. Qed. Lemma charsimpleP G : reflect (G :!=: 1 /\ forall K, K :!=: 1 -> K \char G -> K :=: G) (charsimple G). Proof. apply: (iffP mingroupP); rewrite char_refl andbT => -[ntG simG]. by split=> // K ntK chK; apply: simG; rewrite ?ntK // char_sub. by split=> // K /andP[ntK chK] _; apply: simG. Qed. End Frattini4. Section Fitting. Variable gT : finGroupType. Implicit Types (p : nat) (G H : {group gT}). Lemma Fitting_normal G : 'F(G) <| G. Proof. rewrite -['F(G)](bigdprodWY (erefl 'F(G))). elim/big_rec: _ => [|p H _ nsHG]; first by rewrite gen0 normal1. by rewrite -[<<_>>]joing_idr normalY ?pcore_normal. Qed. Lemma Fitting_sub G : 'F(G) \subset G. Proof. by rewrite normal_sub ?Fitting_normal. Qed. Lemma Fitting_nil G : nilpotent 'F(G). Proof. apply: (bigdprod_nil (erefl 'F(G))) => p _. exact: pgroup_nil (pcore_pgroup p G). Qed. Lemma Fitting_max G H : H <| G -> nilpotent H -> H \subset 'F(G). Proof. move=> nsHG nilH; rewrite -(Sylow_gen H) gen_subG. apply/bigcupsP=> P /SylowP[p _ sylP]. case Gp: (p \in \pi(G)); last first. rewrite card1_trivg ?sub1G // (card_Hall sylP). rewrite part_p'nat // (pnat_dvd (cardSg (normal_sub nsHG))) //. by rewrite /pnat cardG_gt0 all_predC has_pred1 Gp. rewrite {P sylP}(nilpotent_Hall_pcore nilH sylP). rewrite -(bigdprodWY (erefl 'F(G))) sub_gen //. rewrite -(filter_pi_of (ltnSn _)) big_filter big_mkord. apply: (bigcup_max (Sub p _)) => //= [|_]. by have:= Gp; rewrite ltnS mem_primes => /and3P[_ ntG /dvdn_leq->]. by rewrite pcore_max ?pcore_pgroup ?gFnormal_trans. Qed. Lemma pcore_Fitting pi G : 'O_pi('F(G)) \subset 'O_pi(G). Proof. by rewrite pcore_max ?pcore_pgroup ?gFnormal_trans ?Fitting_normal. Qed. Lemma p_core_Fitting p G : 'O_p('F(G)) = 'O_p(G). Proof. apply/eqP; rewrite eqEsubset pcore_Fitting pcore_max ?pcore_pgroup //. apply: normalS (normal_sub (Fitting_normal _)) (pcore_normal _ _). exact: Fitting_max (pcore_normal _ _) (pgroup_nil (pcore_pgroup _ _)). Qed. Lemma nilpotent_Fitting G : nilpotent G -> 'F(G) = G. Proof. by move=> nilG; apply/eqP; rewrite eqEsubset Fitting_sub Fitting_max. Qed. Lemma Fitting_eq_pcore p G : 'O_p^'(G) = 1 -> 'F(G) = 'O_p(G). Proof. move=> p'G1; have /dprodP[_ /= <- _ _] := nilpotent_pcoreC p (Fitting_nil G). by rewrite p_core_Fitting ['O_p^'(_)](trivgP _) ?mulg1 // -p'G1 pcore_Fitting. Qed. Lemma FittingEgen G : 'F(G) = <<\bigcup_(p < #|G|.+1 | (p : nat) \in \pi(G)) 'O_p(G)>>. Proof. apply/eqP; rewrite eqEsubset gen_subG /=. rewrite -{1}(bigdprodWY (erefl 'F(G))) (big_nth 0) big_mkord genS. by apply/bigcupsP=> p _; rewrite -p_core_Fitting pcore_sub. apply/bigcupsP=> [[i /= lti]] _; set p := nth _ _ i. have pi_p: p \in \pi(G) by rewrite mem_nth. have p_dv_G: p %| #|G| by rewrite mem_primes in pi_p; case/and3P: pi_p. have lepG: p < #|G|.+1 by rewrite ltnS dvdn_leq. by rewrite (bigcup_max (Ordinal lepG)). Qed. End Fitting. Section FittingFun. Implicit Types gT rT : finGroupType. Lemma morphim_Fitting : GFunctor.pcontinuous (@Fitting). Proof. move=> gT rT G D f; apply: Fitting_max. by rewrite morphim_normal ?Fitting_normal. by rewrite morphim_nil ?Fitting_nil. Qed. Lemma FittingS gT (G H : {group gT}) : H \subset G -> H :&: 'F(G) \subset 'F(H). Proof. move=> sHG; rewrite -{2}(setIidPl sHG). do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom; apply: morphim_Fitting. Qed. Lemma FittingJ gT (G : {group gT}) x : 'F(G :^ x) = 'F(G) :^ x. Proof. rewrite !FittingEgen -genJ /= cardJg; symmetry; congr <<_>>. rewrite (big_morph (conjugate^~ x) (fun A B => conjUg A B x) (imset0 _)). by apply: eq_bigr => p _; rewrite pcoreJ. Qed. End FittingFun. Canonical Fitting_igFun := [igFun by Fitting_sub & morphim_Fitting]. Canonical Fitting_gFun := [gFun by morphim_Fitting]. Canonical Fitting_pgFun := [pgFun by morphim_Fitting]. Section IsoFitting. Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}). Lemma Fitting_char : 'F(G) \char G. Proof. exact: gFchar. Qed. Lemma injm_Fitting : 'injm f -> G \subset D -> f @* 'F(G) = 'F(f @* G). Proof. exact: injmF. Qed. Lemma isog_Fitting (H : {group rT}) : G \isog H -> 'F(G) \isog 'F(H). Proof. exact: gFisog. Qed. End IsoFitting. Section CharSimple. Variable gT : finGroupType. Implicit Types (rT : finGroupType) (G H K L : {group gT}) (p : nat). Lemma minnormal_charsimple G H : minnormal H G -> charsimple H. Proof. case/mingroupP=> /andP[ntH nHG] minH. apply/charsimpleP; split=> // K ntK chK. by apply: minH; rewrite ?ntK (char_sub chK, char_norm_trans chK). Qed. Lemma maxnormal_charsimple G H L : G <| L -> maxnormal H G L -> charsimple (G / H). Proof. case/andP=> sGL nGL /maxgroupP[/andP[/andP[sHG not_sGH] nHL] maxH]. have nHG: G \subset 'N(H) := subset_trans sGL nHL. apply/charsimpleP; rewrite -subG1 quotient_sub1 //; split=> // HK ntHK chHK. case/(inv_quotientN _): (char_normal chHK) => [|K defHK sHK]; first exact/andP. case/andP; rewrite subEproper defHK => /predU1P[-> // | ltKG] nKG. have nHK: H <| K by rewrite /normal sHK (subset_trans (proper_sub ltKG)). case/negP: ntHK; rewrite defHK -subG1 quotient_sub1 ?normal_norm //. rewrite (maxH K) // ltKG -(quotientGK nHK) -defHK norm_quotient_pre //. by rewrite (char_norm_trans chHK) ?quotient_norms. Qed. Lemma abelem_split_dprod rT p (A B : {group rT}) : p.-abelem A -> B \subset A -> exists C : {group rT}, B \x C = A. Proof. move=> abelA sBA; have [_ cAA _]:= and3P abelA. case/splitsP: (abelem_splits abelA sBA) => C /complP[tiBC defA]. by exists C; rewrite dprodE // (centSS _ sBA cAA) // -defA mulG_subr. Qed. Lemma p_abelem_split1 rT p (A : {group rT}) x : p.-abelem A -> x \in A -> exists B : {group rT}, [/\ B \subset A, #|B| = #|A| %/ #[x] & <[x]> \x B = A]. Proof. move=> abelA Ax; have sxA: <[x]> \subset A by rewrite cycle_subG. have [B defA] := abelem_split_dprod abelA sxA. have [_ defxB _ ti_xB] := dprodP defA. have sBA: B \subset A by rewrite -defxB mulG_subr. by exists B; split; rewrite // -defxB (TI_cardMg ti_xB) mulKn ?order_gt0. Qed. Lemma abelem_charsimple p G : p.-abelem G -> G :!=: 1 -> charsimple G. Proof. move=> abelG ntG; apply/charsimpleP; split=> // K ntK /charP[sKG chK]. case/eqVproper: sKG => // /properP[sKG [x Gx notKx]]. have ox := abelem_order_p abelG Gx (group1_contra notKx). have [A [sAG oA defA]] := p_abelem_split1 abelG Gx. case/trivgPn: ntK => y Ky nty; have Gy := subsetP sKG y Ky. have{nty} oy := abelem_order_p abelG Gy nty. have [B [sBG oB defB]] := p_abelem_split1 abelG Gy. have: isog A B; last case/isogP=> fAB injAB defAB. rewrite (isog_abelem_card _ (abelemS sAG abelG)) (abelemS sBG) //=. by rewrite oA oB ox oy. have: isog <[x]> <[y]>; last case/isogP=> fxy injxy /= defxy. by rewrite isog_cyclic_card ?cycle_cyclic // [#|_|]oy -ox eqxx. have cfxA: fAB @* A \subset 'C(fxy @* <[x]>). by rewrite defAB defxy; case/dprodP: defB. have injf: 'injm (dprodm defA cfxA). by rewrite injm_dprodm injAB injxy defAB defxy; apply/eqP; case/dprodP: defB. case/negP: notKx; rewrite -cycle_subG -(injmSK injf) ?cycle_subG //=. rewrite morphim_dprodml // defxy cycle_subG /= chK //. have [_ {4}<- _ _] := dprodP defB; have [_ {3}<- _ _] := dprodP defA. by rewrite morphim_dprodm // defAB defxy. Qed. Lemma charsimple_dprod G : charsimple G -> exists H : {group gT}, [/\ H \subset G, simple H & exists2 I : {set {perm gT}}, I \subset Aut G & \big[dprod/1]_(f in I) f @: H = G]. Proof. case/charsimpleP=> ntG simG. have [H minH sHG]: {H : {group gT} | minnormal H G & H \subset G}. by apply: mingroup_exists; rewrite ntG normG. case/mingroupP: minH => /andP[ntH nHG] minH. pose Iok (I : {set {perm gT}}) := (I \subset Aut G) && [exists (M : {group gT} | M <| G), \big[dprod/1]_(f in I) f @: H == M]. have defH: (1 : {perm gT}) @: H = H. apply/eqP; rewrite eqEcard card_imset ?leqnn; last exact: perm_inj. by rewrite andbT; apply/subsetP=> _ /imsetP[x Hx ->]; rewrite perm1. have [|I] := @maxset_exists _ Iok 1. rewrite /Iok sub1G; apply/existsP; exists H. by rewrite /normal sHG nHG (big_pred1 1) => [|f]; rewrite ?defH /= ?inE. case/maxsetP=> /andP[Aut_I /exists_eq_inP[M /andP[sMG nMG] defM]] maxI. rewrite sub1set=> ntI; case/eqVproper: sMG => [defG | /andP[sMG not_sGM]]. exists H; split=> //; last by exists I; rewrite ?defM. apply/mingroupP; rewrite ntH normG; split=> // N /andP[ntN nNH] sNH. apply: minH => //; rewrite ntN /= -defG. move: defM; rewrite (bigD1 1) //= defH; case/dprodP=> [[_ K _ ->] <- cHK _]. by rewrite mul_subG // cents_norm // (subset_trans cHK) ?centS. have defG: <<\bigcup_(f in Aut G) f @: H>> = G. have sXG: \bigcup_(f in Aut G) f @: H \subset G. by apply/bigcupsP=> f Af; rewrite -(im_autm Af) morphimEdom imsetS. apply: simG. apply: contra ntH; rewrite -!subG1; apply: subset_trans. by rewrite sub_gen // (bigcup_max 1) ?group1 ?defH. rewrite /characteristic gen_subG sXG; apply/forall_inP=> f Af. rewrite -(autmE Af) -morphimEsub ?gen_subG ?morphim_gen // genS //. rewrite morphimEsub //= autmE. apply/subsetP=> _ /imsetP[_ /bigcupP[g Ag /imsetP[x Hx ->]] ->]. apply/bigcupP; exists (g * f); first exact: groupM. by apply/imsetP; exists x; rewrite // permM. have [f Af sfHM]: exists2 f, f \in Aut G & ~~ (f @: H \subset M). move: not_sGM; rewrite -{1}defG gen_subG; case/subsetPn=> x. by case/bigcupP=> f Af fHx Mx; exists f => //; apply/subsetPn; exists x. case If: (f \in I). by case/negP: sfHM; rewrite -(bigdprodWY defM) sub_gen // (bigcup_max f). case/idP: (If); rewrite -(maxI ([set f] :|: I)) ?subsetUr ?inE ?eqxx //. rewrite {maxI}/Iok subUset sub1set Af {}Aut_I; apply/existsP. have sfHG: autm Af @* H \subset G by rewrite -{4}(im_autm Af) morphimS. have{minH nHG} /mingroupP[/andP[ntfH nfHG] minfH]: minnormal (autm Af @* H) G. apply/mingroupP; rewrite andbC -{1}(im_autm Af) morphim_norms //=. rewrite -subG1 sub_morphim_pre // -kerE ker_autm subG1. split=> // N /andP[ntN nNG] sNfH. have sNG: N \subset G := subset_trans sNfH sfHG. apply/eqP; rewrite eqEsubset sNfH sub_morphim_pre //=. rewrite -(morphim_invmE (injm_autm Af)) [_ @* N]minH //=. rewrite -subG1 sub_morphim_pre /= ?im_autm // morphpre_invm morphim1 subG1. by rewrite ntN -{1}(im_invm (injm_autm Af)) /= {2}im_autm morphim_norms. by rewrite sub_morphim_pre /= ?im_autm // morphpre_invm. have{minfH sfHM} tifHM: autm Af @* H :&: M = 1. apply/eqP/idPn=> ntMfH; case/setIidPl: sfHM. rewrite -(autmE Af) -morphimEsub //. by apply: minfH; rewrite ?subsetIl // ntMfH normsI. have cfHM: M \subset 'C(autm Af @* H). rewrite centsC (sameP commG1P trivgP) -tifHM subsetI commg_subl commg_subr. by rewrite (subset_trans sMG) // (subset_trans sfHG). exists (autm Af @* H <*> M)%G; rewrite /normal /= join_subG sMG sfHG normsY //=. rewrite (bigD1 f) ?inE ?eqxx // (eq_bigl [in I]) /= => [|g]; last first. by rewrite /= !inE andbC; case: eqP => // ->. by rewrite defM -(autmE Af) -morphimEsub // dprodE // cent_joinEr ?eqxx. Qed. Lemma simple_sol_prime G : solvable G -> simple G -> prime #|G|. Proof. move=> solG /simpleP[ntG simG]. have{solG} cGG: abelian G. apply/commG1P; case/simG: (der_normal 1 G) => // /eqP/idPn[]. by rewrite proper_neq // (sol_der1_proper solG). case: (trivgVpdiv G) ntG => [-> | [p p_pr]]; first by rewrite eqxx. case/Cauchy=> // x Gx oxp _; move: p_pr; rewrite -oxp orderE. have: <[x]> <| G by rewrite -sub_abelian_normal ?cycle_subG. by case/simG=> -> //; rewrite cards1. Qed. Lemma charsimple_solvable G : charsimple G -> solvable G -> is_abelem G. Proof. case/charsimple_dprod=> H [sHG simH [I Aut_I defG]] solG. have p_pr: prime #|H| by apply: simple_sol_prime (solvableS sHG solG) simH. set p := #|H| in p_pr; apply/is_abelemP; exists p => //. elim/big_rec: _ (G) defG => [_ <-|f B If IH_B M defM]; first exact: abelem1. have [Af [[_ K _ defB] _ _ _]] := (subsetP Aut_I f If, dprodP defM). rewrite (dprod_abelem p defM) defB IH_B // andbT -(autmE Af) -morphimEsub //=. rewrite morphim_abelem ?abelemE // exponent_dvdn. by rewrite cyclic_abelian ?prime_cyclic. Qed. Lemma minnormal_solvable L G H : minnormal H L -> H \subset G -> solvable G -> [/\ L \subset 'N(H), H :!=: 1 & is_abelem H]. Proof. move=> minH sHG solG; have /andP[ntH nHL] := mingroupp minH. split=> //; apply: (charsimple_solvable (minnormal_charsimple minH)). exact: solvableS solG. Qed. Lemma solvable_norm_abelem L G : solvable G -> G <| L -> G :!=: 1 -> exists H : {group gT}, [/\ H \subset G, H <| L, H :!=: 1 & is_abelem H]. Proof. move=> solG /andP[sGL nGL] ntG. have [H minH sHG]: {H : {group gT} | minnormal H L & H \subset G}. by apply: mingroup_exists; rewrite ntG. have [nHL ntH abH] := minnormal_solvable minH sHG solG. by exists H; split; rewrite // /normal (subset_trans sHG). Qed. Lemma trivg_Fitting G : solvable G -> ('F(G) == 1) = (G :==: 1). Proof. move=> solG; apply/idP/idP=> [F1 | /eqP->]; last by rewrite gF1. apply/idPn=> /(solvable_norm_abelem solG (normal_refl _))[M [_ nsMG ntM]]. case/is_abelemP=> p _ /and3P[pM _ _]; case/negP: ntM. by rewrite -subG1 -(eqP F1) Fitting_max ?(pgroup_nil pM). Qed. Lemma Fitting_pcore pi G : 'F('O_pi(G)) = 'O_pi('F(G)). Proof. apply/eqP; rewrite eqEsubset. rewrite (subset_trans _ (pcoreS _ (Fitting_sub _))); last first. by rewrite subsetI Fitting_sub Fitting_max ?Fitting_nil ?gFnormal_trans. rewrite (subset_trans _ (FittingS (pcore_sub _ _))) // subsetI pcore_sub. by rewrite pcore_max ?pcore_pgroup ?gFnormal_trans. Qed. End CharSimple. Section SolvablePrimeFactor. Variables (gT : finGroupType) (G : {group gT}). Lemma index_maxnormal_sol_prime (H : {group gT}) : solvable G -> maxnormal H G G -> prime #|G : H|. Proof. move=> solG maxH; have nsHG := maxnormal_normal maxH. rewrite -card_quotient ?normal_norm // simple_sol_prime ?quotient_sol //. by rewrite quotient_simple. Qed. Lemma sol_prime_factor_exists : solvable G -> G :!=: 1 -> {H : {group gT} | H <| G & prime #|G : H| }. Proof. move=> solG /ex_maxnormal_ntrivg[H maxH]. by exists H; [apply: maxnormal_normal | apply: index_maxnormal_sol_prime]. Qed. End SolvablePrimeFactor. Section Special. Variables (gT : finGroupType) (p : nat) (A G : {group gT}). (* This is Aschbacher (23.7) *) Lemma center_special_abelem : p.-group G -> special G -> p.-abelem 'Z(G). Proof. move=> pG [defPhi defG']. have [-> | ntG] := eqsVneq G 1; first by rewrite center1 abelem1. have [p_pr _ _] := pgroup_pdiv pG ntG. have fM: {in 'Z(G) &, {morph expgn^~ p : x y / x * y}}. by move=> x y /setIP[_ /centP cxG] /setIP[/cxG cxy _]; apply: expgMn. rewrite abelemE //= center_abelian; apply/exponentP=> /= z Zz. apply: (@kerP _ _ _ (Morphism fM)) => //; apply: subsetP z Zz. rewrite -{1}defG' gen_subG; apply/subsetP=> _ /imset2P[x y Gx Gy ->]. have Zxy: [~ x, y] \in 'Z(G) by rewrite -defG' mem_commg. have Zxp: x ^+ p \in 'Z(G). rewrite -defPhi (Phi_joing pG) (MhoE 1 pG) joing_idr mem_gen // !inE. by rewrite expn1 orbC (imset_f (expgn^~ p)). rewrite mem_morphpre /= ?defG' ?Zxy // inE -commXg; last first. by red; case/setIP: Zxy => _ /centP->. by apply/commgP; red; case/setIP: Zxp => _ /centP->. Qed. Lemma exponent_special : p.-group G -> special G -> exponent G %| p ^ 2. Proof. move=> pG spG; have [defPhi _] := spG. have /and3P[_ _ expZ] := center_special_abelem pG spG. apply/exponentP=> x Gx; rewrite expgM (exponentP expZ) // -defPhi. by rewrite (Phi_joing pG) mem_gen // inE orbC (Mho_p_elt 1) ?(mem_p_elt pG). Qed. (* Aschbacher 24.7 (replaces Gorenstein 5.3.7) *) Theorem abelian_charsimple_special : p.-group G -> coprime #|G| #|A| -> [~: G, A] = G -> \bigcup_(H : {group gT} | (H \char G) && abelian H) H \subset 'C(A) -> special G /\ 'C_G(A) = 'Z(G). Proof. move=> pG coGA defG /bigcupsP cChaA. have cZA: 'Z(G) \subset 'C_G(A). by rewrite subsetI center_sub cChaA // center_char center_abelian. have cChaG (H : {group gT}): H \char G -> abelian H -> H \subset 'Z(G). move=> chH abH; rewrite subsetI char_sub //= centsC -defG. rewrite comm_norm_cent_cent ?(char_norm chH) -?commg_subl ?defG //. by rewrite centsC cChaA ?chH. have cZ2GG: [~: 'Z_2(G), G, G] = 1. by apply/commG1P; rewrite (subset_trans (ucn_comm 1 G)) // ucn1 subsetIr. have{cZ2GG} cG'Z: 'Z_2(G) \subset 'C(G^`(1)). by rewrite centsC; apply/commG1P; rewrite three_subgroup // (commGC G). have{cG'Z} sZ2G'_Z: 'Z_2(G) :&: G^`(1) \subset 'Z(G). apply: cChaG; first by rewrite charI ?ucn_char ?der_char. by rewrite /abelian subIset // (subset_trans cG'Z) // centS ?subsetIr. have{sZ2G'_Z} sG'Z: G^`(1) \subset 'Z(G). rewrite der1_min ?gFnorm //; apply/derG1P. have /TI_center_nil: nilpotent (G / 'Z(G)) := quotient_nil _ (pgroup_nil pG). apply; first exact: gFnormal; rewrite /= setIC -ucn1 -ucn_central. rewrite -quotient_der ?gFnorm // -quotientGI ?ucn_subS ?quotientS1 //=. by rewrite ucn1. have sCG': 'C_G(A) \subset G^`(1). rewrite -quotient_sub1 //; last by rewrite subIset ?gFnorm. rewrite (subset_trans (quotient_subcent _ G A)) //= -[G in G / _]defG. have nGA: A \subset 'N(G) by rewrite -commg_subl defG. rewrite quotientR ?gFnorm_trans ?normG //. rewrite coprime_abel_cent_TI ?quotient_norms ?coprime_morph //. exact: sub_der1_abelian. have defZ: 'Z(G) = G^`(1) by apply/eqP; rewrite eqEsubset (subset_trans cZA). split; last by apply/eqP; rewrite eqEsubset cZA defZ sCG'. split=> //; apply/eqP; rewrite eqEsubset defZ (Phi_joing pG) joing_subl. have:= pG; rewrite -pnat_exponent => /p_natP[n expGpn]. rewrite join_subG subxx andbT /= -defZ -(subnn n.-1). elim: {2}n.-1 => [|m IHm]. rewrite (MhoE _ pG) gen_subG; apply/subsetP=> _ /imsetP[x Gx ->]. rewrite subn0 -subn1 -add1n -maxnE maxnC maxnE expnD. by rewrite expgM -expGpn expg_exponent ?groupX ?group1. rewrite cChaG ?Mho_char //= (MhoE _ pG) /abelian cent_gen gen_subG. apply/centsP=> _ /imsetP[x Gx ->] _ /imsetP[y Gy ->]. move: sG'Z; rewrite subsetI centsC => /andP[_ /centsP cGG']. apply/commgP; rewrite {1}expnSr expgM. rewrite commXg -?commgX; try by apply: cGG'; rewrite ?mem_commg ?groupX. apply/commgP; rewrite subsetI Mho_sub centsC in IHm. apply: (centsP IHm); first by rewrite groupX. rewrite -add1n -(addn1 m) subnDA -maxnE maxnC maxnE. rewrite -expgM -expnSr -addSn expnD expgM groupX //=. by rewrite Mho_p_elt ?(mem_p_elt pG). Qed. End Special. Section Extraspecial. Variables (p : nat) (gT rT : finGroupType). Implicit Types D E F G H K M R S T U : {group gT}. Section Basic. Variable S : {group gT}. Hypotheses (pS : p.-group S) (esS : extraspecial S). Let pZ : p.-group 'Z(S) := pgroupS (center_sub S) pS. Lemma extraspecial_prime : prime p. Proof. by case: esS => _ /prime_gt1; rewrite cardG_gt1; case/(pgroup_pdiv pZ). Qed. Lemma card_center_extraspecial : #|'Z(S)| = p. Proof. by apply/eqP; apply: (pgroupP pZ); case: esS. Qed. Lemma min_card_extraspecial : #|S| >= p ^ 3. Proof. have p_gt1 := prime_gt1 extraspecial_prime. rewrite leqNgt (card_pgroup pS) ltn_exp2l // ltnS. case: esS => [[_ defS']]; apply: contraL => /(p2group_abelian pS)/derG1P S'1. by rewrite -defS' S'1 cards1. Qed. End Basic. Lemma card_p3group_extraspecial E : prime p -> #|E| = (p ^ 3)%N -> #|'Z(E)| = p -> extraspecial E. Proof. move=> p_pr oEp3 oZp; have p_gt0 := prime_gt0 p_pr. have pE: p.-group E by rewrite /pgroup oEp3 pnatX pnat_id. have pEq: p.-group (E / 'Z(E))%g by rewrite quotient_pgroup. have /andP[sZE nZE] := center_normal E. have oEq: #|E / 'Z(E)|%g = (p ^ 2)%N. by rewrite card_quotient -?divgS // oEp3 oZp expnS mulKn. have cEEq: abelian (E / 'Z(E))%g by apply: card_p2group_abelian oEq. have not_cEE: ~~ abelian E. have: #|'Z(E)| < #|E| by rewrite oEp3 oZp (ltn_exp2l 1) ?prime_gt1. by apply: contraL => cEE; rewrite -leqNgt subset_leq_card // subsetI subxx. have defE': E^`(1) = 'Z(E). apply/eqP; rewrite eqEsubset der1_min //=; apply: contraR not_cEE => not_sE'Z. apply/commG1P/(TI_center_nil (pgroup_nil pE) (der_normal 1 _)). by rewrite setIC prime_TIg ?oZp. split; [split=> // | by rewrite oZp]; apply/eqP. rewrite eqEsubset andbC -{1}defE' {1}(Phi_joing pE) joing_subl. rewrite -quotient_sub1 ?gFsub_trans ?subG1 //=. rewrite (quotient_Phi pE) //= (trivg_Phi pEq). apply/abelemP=> //; split=> // Zx EqZx; apply/eqP; rewrite -order_dvdn /order. rewrite (card_pgroup (mem_p_elt pEq EqZx)) (@dvdn_exp2l _ _ 1) //. rewrite leqNgt -pfactor_dvdn // -oEq; apply: contra not_cEE => sEqZx. rewrite cyclic_center_factor_abelian //; apply/cyclicP. exists Zx; apply/eqP; rewrite eq_sym eqEcard cycle_subG EqZx -orderE. exact: dvdn_leq sEqZx. Qed. Lemma p3group_extraspecial G : p.-group G -> ~~ abelian G -> logn p #|G| <= 3 -> extraspecial G. Proof. move=> pG not_cGG; have /andP[sZG nZG] := center_normal G. have ntG: G :!=: 1 by apply: contraNneq not_cGG => ->; apply: abelian1. have ntZ: 'Z(G) != 1 by rewrite (center_nil_eq1 (pgroup_nil pG)). have [p_pr _ [n oG]] := pgroup_pdiv pG ntG; rewrite oG pfactorK //. have [_ _ [m oZ]] := pgroup_pdiv (pgroupS sZG pG) ntZ. have lt_m1_n: m.+1 < n. suffices: 1 < logn p #|(G / 'Z(G))|. rewrite card_quotient // -divgS // logn_div ?cardSg //. by rewrite oG oZ !pfactorK // ltn_subRL addn1. rewrite ltnNge; apply: contra not_cGG => cycGs. apply: cyclic_center_factor_abelian; rewrite (dvdn_prime_cyclic p_pr) //. by rewrite (card_pgroup (quotient_pgroup _ pG)) (dvdn_exp2l _ cycGs). rewrite -{lt_m1_n}(subnKC lt_m1_n) !addSn !ltnS leqn0 in oG *. case: m => // in oZ oG * => /eqP n2; rewrite {n}n2 in oG. exact: card_p3group_extraspecial oZ. Qed. Lemma extraspecial_nonabelian G : extraspecial G -> ~~ abelian G. Proof. case=> [[_ defG'] oZ]; rewrite /abelian (sameP commG1P eqP). by rewrite -derg1 defG' -cardG_gt1 prime_gt1. Qed. Lemma exponent_2extraspecial G : 2.-group G -> extraspecial G -> exponent G = 4. Proof. move=> p2G esG; have [spG _] := esG. case/dvdn_pfactor: (exponent_special p2G spG) => // k. rewrite leq_eqVlt ltnS => /predU1P[-> // | lek1] expG. case/negP: (extraspecial_nonabelian esG). by rewrite (@abelem_abelian _ 2) ?exponent2_abelem // expG pfactor_dvdn. Qed. Lemma injm_special D G (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> special G -> special (f @* G). Proof. move=> injf sGD [defPhiG defG']. by rewrite /special -morphim_der // -injm_Phi // defPhiG defG' injm_center. Qed. Lemma injm_extraspecial D G (f : {morphism D >-> rT}) : 'injm f -> G \subset D -> extraspecial G -> extraspecial (f @* G). Proof. move=> injf sGD [spG ZG_pr]; split; first exact: injm_special spG. by rewrite -injm_center // card_injm // subIset ?sGD. Qed. Lemma isog_special G (R : {group rT}) : G \isog R -> special G -> special R. Proof. by case/isogP=> f injf <-; apply: injm_special. Qed. Lemma isog_extraspecial G (R : {group rT}) : G \isog R -> extraspecial G -> extraspecial R. Proof. by case/isogP=> f injf <-; apply: injm_extraspecial. Qed. Lemma cprod_extraspecial G H K : p.-group G -> H \* K = G -> H :&: K = 'Z(H) -> extraspecial H -> extraspecial K -> extraspecial G. Proof. move=> pG defG ziHK [[PhiH defH'] ZH_pr] [[PhiK defK'] ZK_pr]. have [_ defHK cHK]:= cprodP defG. have sZHK: 'Z(H) \subset 'Z(K). by rewrite subsetI -{1}ziHK subsetIr subIset // centsC cHK. have{sZHK} defZH: 'Z(H) = 'Z(K). by apply/eqP; rewrite eqEcard sZHK leq_eqVlt eq_sym -dvdn_prime2 ?cardSg. have defZ: 'Z(G) = 'Z(K). by case/cprodP: (center_cprod defG) => /= _ <- _; rewrite defZH mulGid. split; first split; rewrite defZ //. by have /cprodP[_ <- _] := Phi_cprod pG defG; rewrite PhiH PhiK defZH mulGid. by have /cprodP[_ <- _] := der_cprod 1 defG; rewrite defH' defK' defZH mulGid. Qed. (* Lemmas bundling Aschbacher (23.10) with (19.1), (19.2), (19.12) and (20.8) *) Section ExtraspecialFormspace. Variable G : {group gT}. Hypotheses (pG : p.-group G) (esG : extraspecial G). Let p_pr := extraspecial_prime pG esG. Let oZ := card_center_extraspecial pG esG. Let p_gt1 := prime_gt1 p_pr. Let p_gt0 := prime_gt0 p_pr. (* This encasulates Aschbacher (23.10)(1). *) Lemma cent1_extraspecial_maximal x : x \in G -> x \notin 'Z(G) -> maximal 'C_G[x] G. Proof. move=> Gx notZx; pose f y := [~ x, y]; have [[_ defG'] prZ] := esG. have{defG'} fZ y: y \in G -> f y \in 'Z(G). by move=> Gy; rewrite -defG' mem_commg. have fM: {in G &, {morph f : y z / y * z}}%g. move=> y z Gy Gz; rewrite {1}/f commgMJ conjgCV -conjgM (conjg_fixP _) //. rewrite (sameP commgP cent1P); apply: subsetP (fZ y Gy). by rewrite subIset // orbC -cent_set1 centS // sub1set !(groupM, groupV). pose fm := Morphism fM. have fmG: fm @* G = 'Z(G). have sfmG: fm @* G \subset 'Z(G). by apply/subsetP=> _ /morphimP[z _ Gz ->]; apply: fZ. apply/eqP; rewrite eqEsubset sfmG; apply: contraR notZx => /(prime_TIg prZ). rewrite (setIidPr _) // => fmG1; rewrite inE Gx; apply/centP=> y Gy. by apply/commgP; rewrite -in_set1 -[[set _]]fmG1; apply: mem_morphim. have ->: 'C_G[x] = 'ker fm. apply/setP=> z; rewrite inE (sameP cent1P commgP) !inE. by rewrite -invg_comm eq_invg_mul mulg1. rewrite p_index_maximal ?subsetIl // -card_quotient ?ker_norm //. by rewrite (card_isog (first_isog fm)) /= fmG. Qed. (* This is the tranposition of the hyperplane dimension theorem (Aschbacher *) (* (19.1)) to subgroups of an extraspecial group. *) Lemma subcent1_extraspecial_maximal U x : U \subset G -> x \in G :\: 'C(U) -> maximal 'C_U[x] U. Proof. move=> sUG /setDP[Gx not_cUx]; apply/maxgroupP; split=> [|H ltHU sCxH]. by rewrite /proper subsetIl subsetI subxx sub_cent1. case/andP: ltHU => sHU not_sHU; have sHG := subset_trans sHU sUG. apply/eqP; rewrite eqEsubset sCxH subsetI sHU /= andbT. apply: contraR not_sHU => not_sHCx. have maxCx: maximal 'C_G[x] G. rewrite cent1_extraspecial_maximal //; apply: contra not_cUx. by rewrite inE Gx; apply: subsetP (centS sUG) _. have nsCx := p_maximal_normal pG maxCx. rewrite -(setIidPl sUG) -(mulg_normal_maximal nsCx maxCx sHG) ?subsetI ?sHG //. by rewrite -group_modr //= setIA (setIidPl sUG) mul_subG. Qed. (* This is the tranposition of the orthogonal subspace dimension theorem *) (* (Aschbacher (19.2)) to subgroups of an extraspecial group. *) Lemma card_subcent_extraspecial U : U \subset G -> #|'C_G(U)| = (#|'Z(G) :&: U| * #|G : U|)%N. Proof. move=> sUG; rewrite setIAC (setIidPr sUG). have [m leUm] := ubnP #|U|; elim: m => // m IHm in U leUm sUG *. have [cUG | not_cUG]:= orP (orbN (G \subset 'C(U))). by rewrite !(setIidPl _) ?Lagrange // centsC. have{not_cUG} [x Gx not_cUx] := subsetPn not_cUG. pose W := 'C_U[x]; have sCW_G: 'C_G(W) \subset G := subsetIl G _. have maxW: maximal W U by rewrite subcent1_extraspecial_maximal // inE not_cUx. have nsWU: W <| U := p_maximal_normal (pgroupS sUG pG) maxW. have ltWU: W \proper U by apply: maxgroupp maxW. have [sWU [u Uu notWu]] := properP ltWU; have sWG := subset_trans sWU sUG. have defU: W * <[u]> = U by rewrite (mulg_normal_maximal nsWU) ?cycle_subG. have iCW_CU: #|'C_G(W) : 'C_G(U)| = p. rewrite -defU centM cent_cycle setIA /=; rewrite inE Uu cent1C in notWu. apply: p_maximal_index (pgroupS sCW_G pG) _. apply: subcent1_extraspecial_maximal sCW_G _. rewrite inE andbC (subsetP sUG) //= -sub_cent1. by apply/subsetPn; exists x; rewrite // inE Gx -sub_cent1 subsetIr. apply/eqP; rewrite -(eqn_pmul2r p_gt0) -{1}iCW_CU Lagrange ?setIS ?centS //. rewrite IHm ?(leq_trans (proper_card ltWU)) // -setIA -mulnA. rewrite -(Lagrange_index sUG sWU) (p_maximal_index (pgroupS sUG pG)) //=. by rewrite -cent_set1 (setIidPr (centS _)) ?sub1set. Qed. (* This is the tranposition of the proof that a singular vector is contained *) (* in a hyperbolic plane (Aschbacher (19.12)) to subgroups of an extraspecial *) (* group. *) Lemma split1_extraspecial x : x \in G :\: 'Z(G) -> {E : {group gT} & {R : {group gT} | [/\ #|E| = (p ^ 3)%N /\ #|R| = #|G| %/ p ^ 2, E \* R = G /\ E :&: R = 'Z(E), 'Z(E) = 'Z(G) /\ 'Z(R) = 'Z(G), extraspecial E /\ x \in E & if abelian R then R :=: 'Z(G) else extraspecial R]}}. Proof. case/setDP=> Gx notZx; rewrite inE Gx /= in notZx. have [[defPhiG defG'] prZ] := esG. have maxCx: maximal 'C_G[x] G. by rewrite subcent1_extraspecial_maximal // inE notZx. pose y := repr (G :\: 'C[x]). have [Gy not_cxy]: y \in G /\ y \notin 'C[x]. move/maxgroupp: maxCx => /properP[_ [t Gt not_cyt]]. by apply/setDP; apply: (mem_repr t); rewrite !inE Gt andbT in not_cyt *. pose E := <[x]> <*> <[y]>; pose R := 'C_G(E). exists [group of E]; exists [group of R] => /=. have sEG: E \subset G by rewrite join_subG !cycle_subG Gx. have [Ex Ey]: x \in E /\ y \in E by rewrite !mem_gen // inE cycle_id ?orbT. have sZE: 'Z(G) \subset E. rewrite (('Z(G) =P E^`(1)) _) ?der_sub // eqEsubset -{2}defG' dergS // andbT. apply: contraR not_cxy => /= not_sZE'. rewrite (sameP cent1P commgP) -in_set1 -[[set 1]](prime_TIg prZ not_sZE'). by rewrite /= -defG' inE !mem_commg. have ziER: E :&: R = 'Z(E) by rewrite setIA (setIidPl sEG). have cER: R \subset 'C(E) by rewrite subsetIr. have iCxG: #|G : 'C_G[x]| = p by apply: p_maximal_index. have maxR: maximal R 'C_G[x]. rewrite /R centY !cent_cycle setIA. rewrite subcent1_extraspecial_maximal ?subsetIl // inE Gy andbT -sub_cent1. by apply/subsetPn; exists x; rewrite 1?cent1C // inE Gx cent1id. have sRCx: R \subset 'C_G[x] by rewrite -cent_cycle setIS ?centS ?joing_subl. have sCxG: 'C_G[x] \subset G by rewrite subsetIl. have sRG: R \subset G by rewrite subsetIl. have iRCx: #|'C_G[x] : R| = p by rewrite (p_maximal_index (pgroupS sCxG pG)). have defG: E * R = G. rewrite -cent_joinEr //= -/R joingC joingA. have cGx_x: <[x]> \subset 'C_G[x] by rewrite cycle_subG inE Gx cent1id. have nsRcx := p_maximal_normal (pgroupS sCxG pG) maxR. rewrite (norm_joinEr (subset_trans cGx_x (normal_norm nsRcx))). rewrite (mulg_normal_maximal nsRcx) //=; last first. by rewrite centY !cent_cycle cycle_subG !in_setI Gx cent1id cent1C. have nsCxG := p_maximal_normal pG maxCx. have syG: <[y]> \subset G by rewrite cycle_subG. rewrite (norm_joinEr (subset_trans syG (normal_norm nsCxG))). by rewrite (mulg_normal_maximal nsCxG) //= cycle_subG inE Gy. have defZR: 'Z(R) = 'Z(G) by rewrite -['Z(R)]setIA -centM defG. have defZE: 'Z(E) = 'Z(G). by rewrite -defG -center_prod ?mulGSid //= -ziER subsetI center_sub defZR sZE. have [n oG] := p_natP pG. have n_gt1: n > 1. by rewrite ltnW // -(@leq_exp2l p) // -oG min_card_extraspecial. have oR: #|R| = (p ^ n.-2)%N. apply/eqP; rewrite -(divg_indexS sRCx) iRCx /= -(divg_indexS sCxG) iCxG /= oG. by rewrite -{1}(subnKC n_gt1) subn2 !expnS !mulKn. have oE: #|E| = (p ^ 3)%N. apply/eqP; rewrite -(@eqn_pmul2r #|R|) ?cardG_gt0 // mul_cardG defG ziER. by rewrite defZE oZ oG -{1}(subnKC n_gt1) oR -expnSr -expnD subn2. rewrite cprodE // oR oG -expnB ?subn2 //; split=> //. by split=> //; apply: card_p3group_extraspecial _ oE _; rewrite // defZE. case: ifP => [cRR | not_cRR]; first by rewrite -defZR (center_idP _). split; rewrite /special defZR //. have ntR': R^`(1) != 1 by rewrite (sameP eqP commG1P) -abelianE not_cRR. have pR: p.-group R := pgroupS sRG pG. have pR': p.-group R^`(1) := pgroupS (der_sub 1 _) pR. have defR': R^`(1) = 'Z(G). apply/eqP; rewrite eqEcard -{1}defG' dergS //= oZ. by have [_ _ [k ->]]:= pgroup_pdiv pR' ntR'; rewrite (leq_exp2l 1). split=> //; apply/eqP; rewrite eqEsubset -{1}defPhiG -defR' (PhiS pG) //=. by rewrite (Phi_joing pR) joing_subl. Qed. (* This is the tranposition of the proof that the dimension of any maximal *) (* totally singular subspace is equal to the Witt index (Aschbacher (20.8)), *) (* to subgroups of an extraspecial group (in a slightly more general form, *) (* since we allow for p != 2). *) (* Note that Aschbacher derives this from the Witt lemma, which we avoid. *) Lemma pmaxElem_extraspecial : 'E*_p(G) = 'E_p^('r_p(G))(G). Proof. have sZmax: {in 'E*_p(G), forall E, 'Z(G) \subset E}. move=> E maxE; have defE := pmaxElem_LdivP p_pr maxE. have abelZ: p.-abelem 'Z(G) by rewrite prime_abelem ?oZ. rewrite -(Ohm1_id abelZ) (OhmE 1 (abelem_pgroup abelZ)) gen_subG -defE. by rewrite setSI // setIS ?centS // -defE !subIset ?subxx. suffices card_max: {in 'E*_p(G) &, forall E F, #|E| <= #|F| }. have EprGmax: 'E_p^('r_p(G))(G) \subset 'E*_p(G) := p_rankElem_max p G. have [E EprE]:= p_rank_witness p G; have maxE := subsetP EprGmax E EprE. apply/eqP; rewrite eqEsubset EprGmax andbT; apply/subsetP=> F maxF. rewrite inE; have [-> _]:= pmaxElemP maxF; have [_ _ <-]:= pnElemP EprE. by apply/eqP; congr (logn p _); apply/eqP; rewrite eqn_leq !card_max. move=> E F maxE maxF; set U := E :&: F. have [sUE sUF]: U \subset E /\ U \subset F by apply/andP; rewrite -subsetI. have sZU: 'Z(G) \subset U by rewrite subsetI !sZmax. have [EpE _]:= pmaxElemP maxE; have{EpE} [sEG abelE] := pElemP EpE. have [EpF _]:= pmaxElemP maxF; have{EpF} [sFG abelF] := pElemP EpF. have [V] := abelem_split_dprod abelE sUE; case/dprodP=> _ defE cUV tiUV. have [W] := abelem_split_dprod abelF sUF; case/dprodP=> _ defF _ tiUW. have [sVE sWF]: V \subset E /\ W \subset F by rewrite -defE -defF !mulG_subr. have [sVG sWG] := (subset_trans sVE sEG, subset_trans sWF sFG). rewrite -defE -defF !TI_cardMg // leq_pmul2l ?cardG_gt0 //. rewrite -(leq_pmul2r (cardG_gt0 'C_G(W))) mul_cardG. rewrite card_subcent_extraspecial // mulnCA Lagrange // mulnC. rewrite leq_mul ?subset_leq_card //; last by rewrite mul_subG ?subsetIl. apply: subset_trans (sub1G _); rewrite -tiUV !subsetI subsetIl subIset ?sVE //=. rewrite -(pmaxElem_LdivP p_pr maxF) -defF centM -!setIA -(setICA 'C(W)). rewrite setIC (setIA G) setIS // subsetI cUV sub_LdivT. by case/and3P: (abelemS sVE abelE). Qed. End ExtraspecialFormspace. (* This is B & G, Theorem 4.15, as done in Aschbacher (23.8) *) Lemma critical_extraspecial R S : p.-group R -> S \subset R -> extraspecial S -> [~: S, R] \subset S^`(1) -> S \* 'C_R(S) = R. Proof. move=> pR sSR esS sSR_S'; have [[defPhi defS'] _] := esS. have [pS [sPS nPS]] := (pgroupS sSR pR, andP (Phi_normal S : 'Phi(S) <| S)). have{esS} oZS: #|'Z(S)| = p := card_center_extraspecial pS esS. have nSR: R \subset 'N(S) by rewrite -commg_subl (subset_trans sSR_S') ?der_sub. have nsCR: 'C_R(S) <| R by rewrite (normalGI nSR) ?cent_normal. have nCS: S \subset 'N('C_R(S)) by rewrite cents_norm // centsC subsetIr. rewrite cprodE ?subsetIr //= -{2}(quotientGK nsCR) normC -?quotientK //. congr (_ @*^-1 _); apply/eqP; rewrite eqEcard quotientS //=. rewrite -(card_isog (second_isog nCS)) setIAC (setIidPr sSR) /= -/'Z(S) -defPhi. rewrite -ker_conj_aut (card_isog (first_isog_loc _ nSR)) //=; set A := _ @* R. have{pS} abelSb := Phi_quotient_abelem pS; have [pSb cSSb _] := and3P abelSb. have [/= Xb defSb oXb] := grank_witness (S / 'Phi(S)). pose X := (repr \o val : coset_of _ -> gT) @: Xb. have sXS: X \subset S; last have nPX := subset_trans sXS nPS. apply/subsetP=> x; case/imsetP=> xb Xxb ->; have nPx := repr_coset_norm xb. rewrite -sub1set -(quotientSGK _ sPS) ?sub1set ?quotient_set1 //= sub1set. by rewrite coset_reprK -defSb mem_gen. have defS: <<X>> = S. apply: Phi_nongen; apply/eqP; rewrite eqEsubset join_subG sPS sXS -joing_idr. rewrite -genM_join sub_gen // -quotientSK ?quotient_gen // -defSb genS //. apply/subsetP=> xb Xxb; apply/imsetP; rewrite (setIidPr nPX). by exists (repr xb); rewrite /= ?coset_reprK //; apply: imset_f. pose f (a : {perm gT}) := [ffun x => if x \in X then x^-1 * a x else 1]. have injf: {in A &, injective f}. move=> _ _ /morphimP[y nSy Ry ->] /morphimP[z nSz Rz ->]. move/ffunP=> eq_fyz; apply: (@eq_Aut _ S); rewrite ?Aut_aut //= => x Sx. rewrite !norm_conj_autE //; apply: canRL (conjgKV z) _; rewrite -conjgM. rewrite /conjg -(centP _ x Sx) ?mulKg {x Sx}// -defS cent_gen -sub_cent1. apply/subsetP=> x Xx; have Sx := subsetP sXS x Xx. move/(_ x): eq_fyz; rewrite !ffunE Xx !norm_conj_autE // => /mulgI xy_xz. by rewrite cent1C inE conjg_set1 conjgM xy_xz conjgK. have sfA_XS': f @: A \subset pffun_on 1 X S^`(1). apply/subsetP=> _ /imsetP[_ /morphimP[y nSy Ry ->] ->]. apply/pffun_onP; split=> [|_ /imageP[x /= Xx ->]]. by apply/subsetP=> x; apply: contraNT => /[!ffunE]/negPf->. have Sx := subsetP sXS x Xx. by rewrite ffunE Xx norm_conj_autE // (subsetP sSR_S') ?mem_commg. rewrite -(card_in_imset injf) (leq_trans (subset_leq_card sfA_XS')) // defS'. rewrite card_pffun_on (card_pgroup pSb) -rank_abelem -?grank_abelian // -oXb. by rewrite -oZS ?leq_pexp2l ?cardG_gt0 ?leq_imset_card. Qed. (* This is part of Aschbacher (23.13) and (23.14). *) Theorem extraspecial_structure S : p.-group S -> extraspecial S -> {Es | all (fun E => (#|E| == p ^ 3)%N && ('Z(E) == 'Z(S))) Es & \big[cprod/1%g]_(E <- Es) E \* 'Z(S) = S}. Proof. have [m] := ubnP #|S|; elim: m S => // m IHm S leSm pS esS. have [x Z'x]: {x | x \in S :\: 'Z(S)}. apply/sigW/set0Pn; rewrite -subset0 subDset setU0. apply: contra (extraspecial_nonabelian esS) => sSZ. exact: abelianS sSZ (center_abelian S). have [E [R [[oE oR]]]]:= split1_extraspecial pS esS Z'x. case=> defS _ [defZE defZR] _; case: ifP => [_ defR | _ esR]. by exists [:: E]; rewrite /= ?oE ?defZE ?eqxx // big_seq1 -defR. have sRS: R \subset S by case/cprodP: defS => _ <- _; rewrite mulG_subr. have [|Es esEs defR] := IHm _ _ (pgroupS sRS pS) esR. rewrite oR (leq_trans (ltn_Pdiv _ _)) ?cardG_gt0 // (ltn_exp2l 0) //. exact: prime_gt1 (extraspecial_prime pS esS). exists (E :: Es); first by rewrite /= oE defZE !eqxx -defZR. by rewrite -defZR big_cons -cprodA defR. Qed. Section StructureCorollaries. Variable S : {group gT}. Hypotheses (pS : p.-group S) (esS : extraspecial S). Let p_pr := extraspecial_prime pS esS. Let oZ := card_center_extraspecial pS esS. (* This is Aschbacher (23.10)(2). *) Lemma card_extraspecial : {n | n > 0 & #|S| = (p ^ n.*2.+1)%N}. Proof. set T := S; exists (logn p #|T|)./2. rewrite half_gt0 ltnW // -(leq_exp2l _ _ (prime_gt1 p_pr)) -card_pgroup //. exact: min_card_extraspecial. have [Es] := extraspecial_structure pS esS; rewrite -[in RHS]/T. elim: Es T => [_ _ <-| E s IHs T] /=. by rewrite big_nil cprod1g oZ (pfactorK 1). rewrite -andbA big_cons -cprodA => /and3P[/eqP oEp3 /eqP defZE]. move=> /IHs{}IHs /cprodP[[_ U _ defU]]; rewrite defU => defT cEU. rewrite -(mulnK #|T| (cardG_gt0 (E :&: U))) -defT -mul_cardG /=. have ->: E :&: U = 'Z(S). apply/eqP; rewrite eqEsubset subsetI -{1 2}defZE subsetIl setIS //=. by case/cprodP: defU => [[V _ -> _]] <- _; apply: mulG_subr. rewrite (IHs U) // oEp3 oZ -expnD addSn expnS mulKn ?prime_gt0 //. by rewrite pfactorK //= uphalf_double. Qed. Lemma Aut_extraspecial_full : Aut_in (Aut S) 'Z(S) \isog Aut 'Z(S). Proof. have [p_gt1 p_gt0] := (prime_gt1 p_pr, prime_gt0 p_pr). have [Es] := extraspecial_structure pS esS. elim: Es S oZ => [T _ _ <-| E s IHs T oZT] /=. rewrite big_nil cprod1g (center_idP (center_abelian T)). by apply/Aut_sub_fullP=> // g injg gZ; exists g. rewrite -andbA big_cons -cprodA => /and3P[/eqP-oE /eqP-defZE es_s]. case/cprodP=> -[_ U _ defU]; rewrite defU => defT cEU. have sUT: U \subset T by rewrite -defT mulG_subr. have sZU: 'Z(T) \subset U. by case/cprodP: defU => [[V _ -> _] <- _]; apply: mulG_subr. have defZU: 'Z(E) = 'Z(U). apply/eqP; rewrite eqEsubset defZE subsetI sZU subIset ?centS ?orbT //=. by rewrite subsetI subIset ?sUT //= -defT centM setSI. apply: (Aut_cprod_full _ defZU); rewrite ?cprodE //; last first. by apply: IHs; rewrite -?defZU ?defZE. have oZE: #|'Z(E)| = p by rewrite defZE. have [p2 | odd_p] := even_prime p_pr. suffices <-: restr_perm 'Z(E) @* Aut E = Aut 'Z(E) by apply: Aut_in_isog. apply/eqP; rewrite eqEcard restr_perm_Aut ?center_sub //=. by rewrite card_Aut_cyclic ?prime_cyclic ?oZE // {1}p2 cardG_gt0. have pE: p.-group E by rewrite /pgroup oE pnatX pnat_id. have nZE: E \subset 'N('Z(E)) by rewrite normal_norm ?center_normal. have esE: extraspecial E := card_p3group_extraspecial p_pr oE oZE. have [[defPhiE defE'] prZ] := esE. have{defPhiE} sEpZ x: x \in E -> (x ^+ p)%g \in 'Z(E). move=> Ex; rewrite -defPhiE (Phi_joing pE) mem_gen // inE orbC. by rewrite (Mho_p_elt 1) // (mem_p_elt pE). have ltZE: 'Z(E) \proper E by rewrite properEcard subsetIl oZE oE (ltn_exp2l 1). have [x [Ex notZx oxp]]: exists x, [/\ x \in E, x \notin 'Z(E) & #[x] %| p]%N. have [_ [x Ex notZx]] := properP ltZE. case: (prime_subgroupVti <[x ^+ p]> prZ) => [sZxp | ]; last first. move/eqP; rewrite (setIidPl _) ?cycle_subG ?sEpZ //. by rewrite cycle_eq1 -order_dvdn; exists x. have [y Ey notxy]: exists2 y, y \in E & y \notin <[x]>. apply/subsetPn; apply: contra (extraspecial_nonabelian esE) => sEx. by rewrite (abelianS sEx) ?cycle_abelian. have: (y ^+ p)%g \in <[x ^+ p]> by rewrite (subsetP sZxp) ?sEpZ. case/cycleP=> i def_yp; set xi := (x ^- i)%g. have Exi: xi \in E by rewrite groupV groupX. exists (y * xi)%g; split; first by rewrite groupM. have sxpx: <[x ^+ p]> \subset <[x]> by rewrite cycle_subG mem_cycle. apply: contra notxy; move/(subsetP (subset_trans sZxp sxpx)). by rewrite groupMr // groupV mem_cycle. pose z := [~ xi, y]; have Zz: z \in 'Z(E) by rewrite -defE' mem_commg. case: (setIP Zz) => _; move/centP=> cEz. rewrite order_dvdn expMg_Rmul; try by apply: commute_sym; apply: cEz. rewrite def_yp expgVn -!expgM mulnC mulgV mul1g -order_dvdn. by rewrite (dvdn_trans (order_dvdG Zz)) //= oZE bin2odd // dvdn_mulr. have{oxp} ox: #[x] = p. apply/eqP; case/primeP: p_pr => _ dvd_p; case/orP: (dvd_p _ oxp) => //. by rewrite order_eq1; case: eqP notZx => // ->; rewrite group1. have [y Ey not_cxy]: exists2 y, y \in E & y \notin 'C[x]. by apply/subsetPn; rewrite sub_cent1; rewrite inE Ex in notZx. have notZy: y \notin 'Z(E). apply: contra not_cxy; rewrite inE Ey; apply: subsetP. by rewrite -cent_set1 centS ?sub1set. pose K := 'C_E[y]; have maxK: maximal K E by apply: cent1_extraspecial_maximal. have nsKE: K <| E := p_maximal_normal pE maxK; have [sKE nKE] := andP nsKE. have oK: #|K| = (p ^ 2)%N. by rewrite -(divg_indexS sKE) oE (p_maximal_index pE) ?mulKn. have cKK: abelian K := card_p2group_abelian p_pr oK. have sZK: 'Z(E) \subset K by rewrite setIS // -cent_set1 centS ?sub1set. have defE: K ><| <[x]> = E. have notKx: x \notin K by rewrite inE Ex cent1C. rewrite sdprodE ?(mulg_normal_maximal nsKE) ?cycle_subG ?(subsetP nKE) //. by rewrite setIC prime_TIg -?orderE ?ox ?cycle_subG. have /cyclicP[z defZ]: cyclic 'Z(E) by rewrite prime_cyclic ?oZE. apply/(Aut_sub_fullP (center_sub E)); rewrite /= defZ => g injg gZ. pose k := invm (injm_Zp_unitm z) (aut injg gZ). have fM: {in K &, {morph expgn^~ (val k): u v / u * v}}. by move=> u v Ku Kv; rewrite /= expgMn // /commute (centsP cKK). pose f := Morphism fM; have fK: f @* K = K. apply/setP=> u; rewrite morphimEdom. apply/imsetP/idP=> [[v Kv ->] | Ku]; first exact: groupX. exists (u ^+ expg_invn K (val k)); first exact: groupX. rewrite /f /= expgAC expgK // oK coprimeXl // -unitZpE //. by case: (k) => /=; rewrite orderE -defZ oZE => j; rewrite natr_Zp. have fMact: {in K & <[x]>, morph_act 'J 'J f (idm <[x]>)}. by move=> u v _ _; rewrite /= conjXg. exists (sdprodm_morphism defE fMact). rewrite im_sdprodm injm_sdprodm injm_idm -card_im_injm im_idm fK. have [_ -> _ ->] := sdprodP defE; rewrite !eqxx; split=> //= u Zu. rewrite sdprodmEl ?(subsetP sZK) ?defZ // -(autE injg gZ Zu). rewrite -[aut _ _](invmK (injm_Zp_unitm z)); first by rewrite permE Zu. by rewrite im_Zp_unitm Aut_aut. Qed. (* These are the parts of Aschbacher (23.12) and exercise 8.5 that are later *) (* used in Aschbacher (34.9), which itself replaces the informal discussion *) (* quoted from Gorenstein in the proof of B & G, Theorem 2.5. *) Lemma center_aut_extraspecial k : coprime k p -> exists2 f, f \in Aut S & forall z, z \in 'Z(S) -> f z = (z ^+ k)%g. Proof. have /cyclicP[z defZ]: cyclic 'Z(S) by rewrite prime_cyclic ?oZ. have oz: #[z] = p by rewrite orderE -defZ. rewrite coprime_sym -unitZpE ?prime_gt1 // -oz => u_k. pose g := Zp_unitm (FinRing.unit 'Z_#[z] u_k). have AutZg: g \in Aut 'Z(S) by rewrite defZ -im_Zp_unitm mem_morphim ?inE. have ZSfull := Aut_sub_fullP (center_sub S) Aut_extraspecial_full. have [f [injf fS fZ]] := ZSfull _ (injm_autm AutZg) (im_autm AutZg). exists (aut injf fS) => [|u Zu]; first exact: Aut_aut. have [Su _] := setIP Zu; have z_u: u \in <[z]> by rewrite -defZ. by rewrite autE // fZ //= autmE permE /= z_u /cyclem expg_znat. Qed. End StructureCorollaries. End Extraspecial. Section SCN. Variables (gT : finGroupType) (p : nat) (G : {group gT}). Implicit Types A Z H : {group gT}. Lemma SCN_P A : reflect (A <| G /\ 'C_G(A) = A) (A \in 'SCN(G)). Proof. by apply: (iffP setIdP) => [] [->]; move/eqP. Qed. Lemma SCN_abelian A : A \in 'SCN(G) -> abelian A. Proof. by case/SCN_P=> _ defA; rewrite /abelian -{1}defA subsetIr. Qed. Lemma exponent_Ohm1_class2 H : odd p -> p.-group H -> nil_class H <= 2 -> exponent 'Ohm_1(H) %| p. Proof. move=> odd_p pH; rewrite nil_class2 => sH'Z; apply/exponentP=> x /=. rewrite (OhmE 1 pH) expn1 gen_set_id => {x} [/LdivP[] //|]. apply/group_setP; split=> [|x y]; first by rewrite !inE group1 expg1n //=. case/LdivP=> Hx xp1 /LdivP[Hy yp1]; rewrite !inE groupM //=. have [_ czH]: [~ y, x] \in H /\ centralises [~ y, x] H. by apply/centerP; rewrite (subsetP sH'Z) ?mem_commg. rewrite expMg_Rmul ?xp1 ?yp1 /commute ?czH //= !mul1g. by rewrite bin2odd // -commXXg ?yp1 /commute ?czH // comm1g. Qed. (* SCN_max and max_SCN cover Aschbacher 23.15(1) *) Lemma SCN_max A : A \in 'SCN(G) -> [max A | A <| G & abelian A]. Proof. case/SCN_P => nAG scA; apply/maxgroupP; split=> [|H]. by rewrite nAG /abelian -{1}scA subsetIr. do 2![case/andP]=> sHG _ abelH sAH; apply/eqP. by rewrite eqEsubset sAH -scA subsetI sHG centsC (subset_trans sAH). Qed. Lemma max_SCN A : p.-group G -> [max A | A <| G & abelian A] -> A \in 'SCN(G). Proof. move/pgroup_nil=> nilG; rewrite /abelian. case/maxgroupP=> /andP[nsAG abelA] maxA; have [sAG nAG] := andP nsAG. rewrite inE nsAG eqEsubset /= andbC subsetI abelA normal_sub //=. rewrite -quotient_sub1; last by rewrite subIset 1?normal_norm. apply/trivgP; apply: (TI_center_nil (quotient_nil A nilG)). by rewrite quotient_normal // /normal subsetIl normsI ?normG ?norms_cent. apply/trivgP/subsetP=> _ /setIP[/morphimP[x Nx /setIP[_ Cx]] ->]. rewrite -cycle_subG in Cx => /setIP[GAx CAx]. have{CAx GAx}: <[coset A x]> <| G / A. by rewrite /normal cycle_subG GAx cents_norm // centsC cycle_subG. case/(inv_quotientN nsAG)=> B /= defB sAB nBG. rewrite -cycle_subG defB (maxA B) ?trivg_quotient // nBG. have{} defB : B :=: A * <[x]>. rewrite -quotientK ?cycle_subG ?quotient_cycle // defB quotientGK //. exact: normalS (normal_sub nBG) nsAG. apply/setIidPl; rewrite ?defB -[_ :&: _]center_prod //=. rewrite /center !(setIidPl _) //; apply: cycle_abelian. Qed. (* The two other assertions of Aschbacher 23.15 state properties of the *) (* normal series 1 <| Z = 'Ohm_1(A) <| A with A \in 'SCN(G). *) Section SCNseries. Variables A : {group gT}. Hypothesis SCN_A : A \in 'SCN(G). Let Z := 'Ohm_1(A). Let cAA := SCN_abelian SCN_A. Let sZA: Z \subset A := Ohm_sub 1 A. Let nZA : A \subset 'N(Z) := sub_abelian_norm cAA sZA. (* This is Aschbacher 23.15(2). *) Lemma der1_stab_Ohm1_SCN_series : ('C(Z) :&: 'C_G(A / Z | 'Q))^`(1) \subset A. Proof. case/SCN_P: SCN_A => /andP[sAG nAG] {4} <-. rewrite subsetI {1}setICA comm_subG ?subsetIl //= gen_subG. apply/subsetP=> w /imset2P[u v]. rewrite /= -groupV -(groupV _ v) /= astabQR //= -/Z !inE (groupV 'C(Z)). case/and4P=> cZu _ _ sRuZ /and4P[cZv' _ _ sRvZ] ->{w}. apply/centP=> a Aa; rewrite /commute -!mulgA (commgCV v) (mulgA u). rewrite (centP cZu); last by rewrite (subsetP sRvZ) ?mem_commg ?set11 ?groupV. rewrite 2!(mulgA v^-1) mulKVg 4!mulgA invgK (commgC u^-1) mulgA. rewrite -(mulgA _ _ v^-1) -(centP cZv') ?(subsetP sRuZ) ?mem_commg ?set11//. by rewrite -!mulgA invgK mulKVg !mulKg. Qed. (* This is Aschbacher 23.15(3); note that this proof does not depend on the *) (* maximality of A. *) Lemma Ohm1_stab_Ohm1_SCN_series : odd p -> p.-group G -> 'Ohm_1('C_G(Z)) \subset 'C_G(A / Z | 'Q). Proof. have [-> | ntG] := eqsVneq G 1; first by rewrite !(setIidPl (sub1G _)) Ohm1. move=> p_odd pG; have{ntG} [p_pr _ _] := pgroup_pdiv pG ntG. case/SCN_P: SCN_A => /andP[sAG nAG] _; have pA := pgroupS sAG pG. have pCGZ : p.-group 'C_G(Z) by rewrite (pgroupS _ pG) // subsetIl. rewrite {pCGZ}(OhmE 1 pCGZ) gen_subG; apply/subsetP=> x; rewrite /= 3!inE -andbA. rewrite -!cycle_subG => /and3P[sXG cZX xp1] /=; have cXX := cycle_abelian x. have nZX := cents_norm cZX; have{nAG} nAX := subset_trans sXG nAG. pose XA := <[x]> <*> A; pose C := 'C(<[x]> / Z | 'Q); pose CA := A :&: C. pose Y := <[x]> <*> CA; pose W := 'Ohm_1(Y). have sXC: <[x]> \subset C by rewrite sub_astabQ nZX (quotient_cents _ cXX). have defY : Y = <[x]> * CA by rewrite -norm_joinEl // normsI ?nAX ?normsG. have{nAX} defXA: XA = <[x]> * A := norm_joinEl nAX. suffices{sXC}: XA \subset Y. rewrite subsetI sXG /= sub_astabQ nZX centsC defY group_modl //= -/Z -/C. by rewrite subsetI sub_astabQ defXA quotientMl //= !mulG_subG; case/and4P. have sZCA: Z \subset CA by rewrite subsetI sZA [C]astabQ sub_cosetpre. have cZCA: CA \subset 'C(Z) by rewrite subIset 1?(sub_abelian_cent2 cAA). have sZY: Z \subset Y by rewrite (subset_trans sZCA) ?joing_subr. have{cZCA cZX} cZY: Y \subset 'C(Z) by rewrite join_subG cZX. have{cXX nZX} sY'Z : Y^`(1) \subset Z. rewrite der1_min ?cents_norm //= -/Y defY quotientMl // abelianM /= -/Z -/CA. rewrite !quotient_abelian // ?(abelianS _ cAA) ?subsetIl //=. by rewrite /= quotientGI ?Ohm_sub // quotient_astabQ subsetIr. have{sY'Z cZY} nil_classY: nil_class Y <= 2. by rewrite nil_class2 (subset_trans sY'Z ) // subsetI sZY centsC. have pY: p.-group Y by rewrite (pgroupS _ pG) // join_subG sXG subIset ?sAG. have sXW: <[x]> \subset W. by rewrite [W](OhmE 1 pY) ?genS // sub1set !inE -cycle_subG joing_subl. have{nil_classY pY sXW sZY sZCA} defW: W = <[x]> * Z. rewrite -[W](setIidPr (Ohm_sub _ _)) /= -/Y {1}defY -group_modl //= -/Y -/W. congr (_ * _); apply/eqP; rewrite eqEsubset {1}[Z](OhmE 1 pA). rewrite subsetI setIAC subIset //; first by rewrite sZCA -[Z]Ohm_id OhmS. rewrite sub_gen ?setIS //; apply/subsetP=> w Ww; rewrite inE. by apply/eqP; apply: exponentP w Ww; apply: exponent_Ohm1_class2. have{sXG sAG} sXAG: XA \subset G by rewrite join_subG sXG. have{sXAG} nilXA: nilpotent XA := nilpotentS sXAG (pgroup_nil pG). have sYXA: Y \subset XA by rewrite defY defXA mulgS ?subsetIl. rewrite -[Y](nilpotent_sub_norm nilXA) {nilXA sYXA}//= -/Y -/XA. suffices: 'N_XA('Ohm_1(Y)) \subset Y by apply/subset_trans/setIS/gFnorms. rewrite {XA}defXA -group_modl ?normsG /= -/W ?{W}defW ?mulG_subl //. rewrite {Y}defY mulgS // subsetI subsetIl {CA C}sub_astabQ subIset ?nZA //= -/Z. rewrite (subset_trans (quotient_subnorm _ _ _)) //= quotientMidr /= -/Z. rewrite -quotient_sub1 ?subIset ?cent_norm ?orbT //. rewrite (subset_trans (quotientI _ _ _)) ?coprime_TIg //. rewrite (@pnat_coprime p) // -/(p.-group _) ?quotient_pgroup {pA}//= -pgroupE. rewrite -(setIidPr (cent_sub _)) p'group_quotient_cent_prime //. by rewrite (dvdn_trans (dvdn_quotient _ _)) ?order_dvdn. Qed. End SCNseries. (* This is Aschbacher 23.16. *) Lemma Ohm1_cent_max_normal_abelem Z : odd p -> p.-group G -> [max Z | Z <| G & p.-abelem Z] -> 'Ohm_1('C_G(Z)) = Z. Proof. move=> p_odd pG; set X := 'Ohm_1('C_G(Z)). case/maxgroupP=> /andP[nsZG abelZ] maxZ. have [sZG nZG] := andP nsZG; have [_ cZZ expZp] := and3P abelZ. have{nZG} nsXG: X <| G by rewrite gFnormal_trans ?norm_normalI ?norms_cent. have cZX : X \subset 'C(Z) by apply/gFsub_trans/subsetIr. have{sZG expZp} sZX: Z \subset X. rewrite [X](OhmE 1 (pgroupS _ pG)) ?subsetIl ?sub_gen //. apply/subsetP=> x Zx; rewrite !inE ?(subsetP sZG) ?(subsetP cZZ) //=. by rewrite (exponentP expZp). suffices{sZX} expXp: (exponent X %| p). apply/eqP; rewrite eqEsubset sZX andbT -quotient_sub1 ?cents_norm //= -/X. have pGq: p.-group (G / Z) by rewrite quotient_pgroup. rewrite (TI_center_nil (pgroup_nil pGq)) ?quotient_normal //= -/X setIC. apply/eqP/trivgPn=> [[Zd]]; rewrite inE -!cycle_subG -cycle_eq1 -subG1 /= -/X. case/andP=> /sub_center_normal nsZdG. have{nsZdG} [D defD sZD nsDG] := inv_quotientN nsZG nsZdG; rewrite defD. have sDG := normal_sub nsDG; have nsZD := normalS sZD sDG nsZG. rewrite quotientSGK ?quotient_sub1 ?normal_norm //= -/X => sDX /negP[]. rewrite (maxZ D) // nsDG andbA (pgroupS sDG) ?(dvdn_trans (exponentS sDX)) //. have sZZD: Z \subset 'Z(D) by rewrite subsetI sZD centsC (subset_trans sDX). by rewrite (cyclic_factor_abelian sZZD) //= -defD cycle_cyclic. pose normal_abelian := [pred A : {group gT} | A <| G & abelian A]. have{nsZG cZZ} normal_abelian_Z : normal_abelian Z by apply/andP. have{normal_abelian_Z} [A maxA sZA] := maxgroup_exists normal_abelian_Z. have SCN_A : A \in 'SCN(G) by apply: max_SCN pG maxA. move/maxgroupp: maxA => /andP[nsAG cAA] {normal_abelian}. have pA := pgroupS (normal_sub nsAG) pG. have{abelZ maxZ nsAG cAA sZA} defA1: 'Ohm_1(A) = Z. have: Z \subset 'Ohm_1(A) by rewrite -(Ohm1_id abelZ) OhmS. by apply: maxZ; rewrite Ohm1_abelem ?gFnormal_trans. have{SCN_A} sX'A: X^`(1) \subset A. have sX_CWA1 : X \subset 'C('Ohm_1(A)) :&: 'C_G(A / 'Ohm_1(A) | 'Q). rewrite subsetI /X -defA1 (Ohm1_stab_Ohm1_SCN_series _ p_odd) //=. by rewrite gFsub_trans ?subsetIr. by apply: subset_trans (der1_stab_Ohm1_SCN_series SCN_A); rewrite commgSS. pose genXp := [pred U : {group gT} | 'Ohm_1(U) == U & ~~ (exponent U %| p)]. apply/idPn=> expXp'; have genXp_X: genXp [group of X] by rewrite /= Ohm_id eqxx. have{genXp_X expXp'} [U] := mingroup_exists genXp_X; case/mingroupP; case/andP. move/eqP=> defU1 expUp' minU sUX; case/negP: expUp'. have{nsXG} pU := pgroupS (subset_trans sUX (normal_sub nsXG)) pG. case gsetU1: (group_set 'Ldiv_p(U)). by rewrite -defU1 (OhmE 1 pU) gen_set_id // -sub_LdivT subsetIr. move: gsetU1; rewrite /group_set 2!inE group1 expg1n eqxx; case/subsetPn=> xy. case/imset2P=> x y /[!inE] /andP[Ux xp1] /andP[Uy yp1] ->{xy}. rewrite groupM //= => nt_xyp; pose XY := <[x]> <*> <[y]>. have{yp1 nt_xyp} defXY: XY = U. have sXY_U: XY \subset U by rewrite join_subG !cycle_subG Ux Uy. rewrite [XY]minU //= eqEsubset Ohm_sub (OhmE 1 (pgroupS _ pU)) //. rewrite /= joing_idl joing_idr genS; last first. by rewrite subsetI subset_gen subUset !sub1set !inE xp1 yp1. apply: contra nt_xyp => /exponentP-> //. by rewrite groupMl mem_gen // (set21, set22). have: <[x]> <|<| U by rewrite nilpotent_subnormal ?(pgroup_nil pU) ?cycle_subG. case/subnormalEsupport=> [defU | /=]. by apply: dvdn_trans (exponent_dvdn U) _; rewrite -defU order_dvdn. set V := <<class_support <[x]> U>>; case/andP=> sVU ltVU. have{genXp minU xp1 sVU ltVU} expVp: exponent V %| p. apply: contraR ltVU => expVp'; rewrite [V]minU //= expVp' eqEsubset Ohm_sub. rewrite (OhmE 1 (pgroupS sVU pU)) genS //= subsetI subset_gen class_supportEr. apply/bigcupsP=> z _; apply/subsetP=> v Vv. by rewrite inE -order_dvdn (dvdn_trans (order_dvdG Vv)) // cardJg order_dvdn. have{A pA defA1 sX'A V expVp} Zxy: [~ x, y] \in Z. rewrite -defA1 (OhmE 1 pA) mem_gen // !inE (exponentP expVp). by rewrite (subsetP sX'A) //= mem_commg ?(subsetP sUX). by rewrite groupMl -1?[x^-1]conjg1 mem_gen // imset2_f // ?groupV cycle_id. have{Zxy sUX cZX} cXYxy: [~ x, y] \in 'C(XY). by rewrite centsC in cZX; rewrite defXY (subsetP (centS sUX)) ?(subsetP cZX). rewrite -defU1 exponent_Ohm1_class2 // nil_class2 -defXY der1_joing_cycles //. by rewrite subsetI {1}defXY !cycle_subG groupR. Qed. Lemma critical_class2 H : critical H G -> nil_class H <= 2. Proof. case=> [chH _ sRZ _]. by rewrite nil_class2 (subset_trans _ sRZ) ?commSg // char_sub. Qed. (* This proof of the Thompson critical lemma is adapted from Aschbacher 23.6 *) Lemma Thompson_critical : p.-group G -> {K : {group gT} | critical K G}. Proof. move=> pG; pose qcr A := (A \char G) && ('Phi(A) :|: [~: G, A] \subset 'Z(A)). have [|K]:= @maxgroup_exists _ qcr 1 _. by rewrite /qcr char1 center1 commG1 subUset Phi_sub subxx. case/maxgroupP; rewrite {}/qcr subUset => /and3P[chK sPhiZ sRZ] maxK _. have sKG := char_sub chK; have nKG := char_normal chK. exists K; split=> //; apply/eqP; rewrite eqEsubset andbC setSI //=. have chZ: 'Z(K) \char G by [apply: subcent_char]; have nZG := char_norm chZ. have chC: 'C_G(K) \char G by apply: subcent_char chK. rewrite -quotient_sub1; last by rewrite subIset // char_norm. apply/trivgP; apply: (TI_center_nil (quotient_nil _ (pgroup_nil pG))). by rewrite quotient_normal ?norm_normalI ?norms_cent ?normal_norm. apply: TI_Ohm1; apply/trivgP; rewrite -trivg_quotient -sub_cosetpre_quo //. rewrite morphpreI quotientGK /=; last first. by apply: normalS (char_normal chZ); rewrite ?subsetIl ?setSI. set X := _ :&: _; pose gX := [group of X]. have sXG: X \subset G by rewrite subIset ?subsetIl. have cXK: K \subset 'C(gX) by rewrite centsC 2?subIset // subxx orbT. rewrite subsetI centsC cXK andbT -(mul1g K) -mulSG mul1g -(cent_joinEr cXK). rewrite [_ <*> K]maxK ?joing_subr //= andbC (cent_joinEr cXK). rewrite -center_prod // (subset_trans _ (mulG_subr _ _)). rewrite charM 1?charI ?(char_from_quotient (normal_cosetpre _)) //. by rewrite cosetpreK !gFchar_trans. rewrite (@Phi_mulg p) ?(pgroupS _ pG) // subUset commGC commMG; last first. by rewrite normsR ?(normsG sKG) // cents_norm // centsC. rewrite !mul_subG 1?commGC //. apply: subset_trans (commgS _ (subsetIr _ _)) _. rewrite -quotient_cents2 ?subsetIl // centsC // cosetpreK //. exact/gFsub_trans/subsetIr. have nZX := subset_trans sXG nZG; have pX : p.-group gX by apply: pgroupS pG. rewrite -quotient_sub1 ?gFsub_trans //=. have pXZ: p.-group (gX / 'Z(K)) by apply: morphim_pgroup. rewrite (quotient_Phi pX nZX) subG1 (trivg_Phi pXZ). apply: (abelemS (quotientS _ (subsetIr _ _))); rewrite /= cosetpreK /=. have pZ: p.-group 'Z(G / 'Z(K)). by rewrite (pgroupS (center_sub _)) ?morphim_pgroup. by rewrite Ohm1_abelem ?center_abelian. Qed. Lemma critical_p_stab_Aut H : critical H G -> p.-group G -> p.-group 'C(H | [Aut G]). Proof. move=> [chH sPhiZ sRZ eqCZ] pG; have sHG := char_sub chH. pose G' := (sdpair1 [Aut G] @* G)%G; pose H' := (sdpair1 [Aut G] @* H)%G. apply/pgroupP=> q pr_q; case/Cauchy=> //= f cHF; move: (cHF); rewrite astab_ract. case/setIP=> Af cHFP ofq; rewrite -cycle_subG in cHF; apply: (pgroupP pG) => //. pose F' := (sdpair2 [Aut G] @* <[f]>)%G. have trHF: [~: H', F'] = 1. apply/trivgP; rewrite gen_subG; apply/subsetP=> u; case/imset2P=> x' a'. case/morphimP=> x Gx Hx ->; case/morphimP=> a Aa Fa -> -> {u x' a'}. by rewrite inE commgEl -sdpair_act ?(astab_act (subsetP cHF _ Fa) Hx) ?mulVg. have sGH_H: [~: G', H'] \subset H'. by rewrite -morphimR ?(char_sub chH) // morphimS // commg_subr char_norm. have{trHF sGH_H} trFGH: [~: F', G', H'] = 1. apply: three_subgroup; last by rewrite trHF comm1G. by apply/trivgP; rewrite -trHF commSg. apply/negP=> qG; case: (qG); rewrite -ofq. suffices ->: f = 1 by rewrite order1 dvd1n. apply/permP=> x; rewrite perm1; case Gx: (x \in G); last first. by apply: out_perm (negbT Gx); case/setIdP: Af. have Gfx: f x \in G by rewrite -(im_autm Af) -{1}(autmE Af) mem_morphim. pose y := x^-1 * f x; have Gy: y \in G by rewrite groupMl ?groupV. have [inj1 inj2] := (injm_sdpair1 [Aut G], injm_sdpair2 [Aut G]). have Hy: y \in H. rewrite (subsetP (center_sub H)) // -eqCZ -cycle_subG. rewrite -(injmSK inj1) ?cycle_subG // injm_subcent // subsetI. rewrite morphimS ?morphim_cycle ?cycle_subG //=. suffices: sdpair1 [Aut G] y \in [~: G', F']. by rewrite commGC; apply: subsetP; apply/commG1P. rewrite morphM ?groupV ?morphV //= sdpair_act // -commgEl. by rewrite mem_commg ?mem_morphim ?cycle_id. have fy: f y = y := astabP cHFP _ Hy. have: (f ^+ q) x = x * y ^+ q. elim: (q) => [|i IHi]; first by rewrite perm1 mulg1. rewrite expgSr permM {}IHi -(autmE Af) morphM ?morphX ?groupX //= autmE. by rewrite fy expgS mulgA mulKVg. move/eqP; rewrite -{1}ofq expg_order perm1 eq_mulVg1 mulKg -order_dvdn. case/primeP: pr_q => _ pr_q /pr_q; rewrite order_eq1 -eq_mulVg1. by case: eqP => //= _ /eqP oyq; case: qG; rewrite -oyq order_dvdG. Qed. End SCN. Arguments SCN_P {gT G A}.
SequentialProduct.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.Functor.OfSequence import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts import Mathlib.CategoryTheory.Limits.Shapes.Countable import Mathlib.CategoryTheory.Limits.Shapes.PiProd import Mathlib.CategoryTheory.Limits.Shapes.RegularMono import Mathlib.Order.Interval.Finset.Nat /-! # ℕ-indexed products as sequential limits Given sequences `M N : ℕ → C` of objects with morphisms `f n : M n ⟶ N n` for all `n`, this file exhibits `∏ M` as the limit of the tower ``` ⋯ → ∏_{n < m + 1} M n × ∏_{n ≥ m + 1} N n → ∏_{n < m} M n × ∏_{n ≥ m} N n → ⋯ → ∏ N ``` Further, we prove that the transition maps in this tower are epimorphisms, in the case when each `f n` is an epimorphism and `C` has finite biproducts. -/ namespace CategoryTheory.Limits.SequentialProduct variable {C : Type*} {M N : ℕ → C} lemma functorObj_eq_pos {n m : ℕ} (h : m < n) : (fun i ↦ if _ : i < n then M i else N i) m = M m := dif_pos h lemma functorObj_eq_neg {n m : ℕ} (h : ¬(m < n)) : (fun i ↦ if _ : i < n then M i else N i) m = N m := dif_neg h variable [Category C] (f : ∀ n, M n ⟶ N n) [HasProductsOfShape ℕ C] variable (M N) in /-- The product of the `m` first objects of `M` and the rest of the rest of `N` -/ noncomputable def functorObj : ℕ → C := fun n ↦ ∏ᶜ (fun m ↦ if _ : m < n then M m else N m) /-- The projection map from `functorObj M N n` to `M m`, when `m < n` -/ noncomputable def functorObjProj_pos (n m : ℕ) (h : m < n) : functorObj M N n ⟶ M m := Pi.π (fun m ↦ if _ : m < n then M m else N m) m ≫ eqToHom (functorObj_eq_pos (by omega)) /-- The projection map from `functorObj M N n` to `N m`, when `m ≥ n` -/ noncomputable def functorObjProj_neg (n m : ℕ) (h : ¬(m < n)) : functorObj M N n ⟶ N m := Pi.π (fun m ↦ if _ : m < n then M m else N m) m ≫ eqToHom (functorObj_eq_neg (by omega)) /-- The transition maps in the sequential limit of products -/ noncomputable def functorMap : ∀ n, functorObj M N (n + 1) ⟶ functorObj M N n := by intro n refine Limits.Pi.map fun m ↦ if h : m < n then eqToHom ?_ else if h' : m < n + 1 then eqToHom ?_ ≫ f m ≫ eqToHom ?_ else eqToHom ?_ all_goals split_ifs; try rfl; try omega lemma functorMap_commSq_succ (n : ℕ) : (Functor.ofOpSequence (functorMap f)).map (homOfLE (by omega : n ≤ n + 1)).op ≫ Pi.π _ n ≫ eqToHom (functorObj_eq_neg (by omega : ¬(n < n))) = (Pi.π (fun i ↦ if _ : i < (n + 1) then M i else N i) n) ≫ eqToHom (functorObj_eq_pos (by omega)) ≫ f n := by simp [functorMap] lemma functorMap_commSq_aux {n m k : ℕ} (h : n ≤ m) (hh : ¬(k < m)) : (Functor.ofOpSequence (functorMap f)).map (homOfLE h).op ≫ Pi.π _ k ≫ eqToHom (functorObj_eq_neg (by omega : ¬(k < n))) = (Pi.π (fun i ↦ if _ : i < m then M i else N i) k) ≫ eqToHom (functorObj_eq_neg hh) := by induction' h using Nat.leRec with m h ih · simp · specialize ih (by omega) have : homOfLE (by omega : n ≤ m + 1) = homOfLE (by omega : n ≤ m) ≫ homOfLE (by omega : m ≤ m + 1) := by simp rw [this, op_comp, Functor.map_comp] slice_lhs 2 4 => rw [ih] simp only [Functor.ofOpSequence_obj, homOfLE_leOfHom, Functor.ofOpSequence_map_homOfLE_succ, functorMap, dite_eq_ite, limMap_π_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app] split_ifs simp [dif_neg (by omega : ¬(k < m))] lemma functorMap_commSq {n m : ℕ} (h : ¬(m < n)) : (Functor.ofOpSequence (functorMap f)).map (homOfLE (by omega : n ≤ m + 1)).op ≫ Pi.π _ m ≫ eqToHom (functorObj_eq_neg (by omega : ¬(m < n))) = (Pi.π (fun i ↦ if _ : i < m + 1 then M i else N i) m) ≫ eqToHom (functorObj_eq_pos (by omega)) ≫ f m := by cases m with | zero => have : n = 0 := by omega subst this simp [functorMap] | succ m => rw [← functorMap_commSq_succ f (m + 1)] simp only [Functor.ofOpSequence_obj, homOfLE_leOfHom, dite_eq_ite, Functor.ofOpSequence_map_homOfLE_succ] have : homOfLE (by omega : n ≤ m + 1 + 1) = homOfLE (by omega : n ≤ m + 1) ≫ homOfLE (by omega : m + 1 ≤ m + 1 + 1) := by simp rw [this, op_comp, Functor.map_comp] simp only [Functor.ofOpSequence_obj, homOfLE_leOfHom, Functor.ofOpSequence_map_homOfLE_succ, Category.assoc] congr 1 exact functorMap_commSq_aux f (by omega) (by omega) /-- The cone over the tower ``` ⋯ → ∏_{n < m} M n × ∏_{n ≥ m} N n → ⋯ → ∏ N ``` with cone point `∏ M`. This is a limit cone, see `CategoryTheory.Limits.SequentialProduct.isLimit`. -/ noncomputable def cone : Cone (Functor.ofOpSequence (functorMap f)) where pt := ∏ᶜ M π := by refine NatTrans.ofOpSequence (fun n ↦ Limits.Pi.map fun m ↦ if h : m < n then eqToHom (functorObj_eq_pos h).symm else f m ≫ eqToHom (functorObj_eq_neg h).symm) (fun n ↦ ?_) apply Limits.Pi.hom_ext intro m simp only [Functor.const_obj_obj, Functor.ofOpSequence_obj, homOfLE_leOfHom, Functor.const_obj_map, Category.id_comp, limMap_π, Discrete.functor_obj_eq_as, Discrete.natTrans_app, Functor.ofOpSequence_map_homOfLE_succ, functorMap, Category.assoc, limMap_π_assoc] split · simp [dif_pos (by omega : m < n + 1)] · split all_goals simp lemma cone_π_app (n : ℕ) : (cone f).π.app ⟨n⟩ = Limits.Pi.map fun m ↦ if h : m < n then eqToHom (functorObj_eq_pos h).symm else f m ≫ eqToHom (functorObj_eq_neg h).symm := rfl @[reassoc] lemma cone_π_app_comp_Pi_π_pos (m n : ℕ) (h : n < m) : (cone f).π.app ⟨m⟩ ≫ Pi.π (fun i ↦ if _ : i < m then M i else N i) n = Pi.π _ n ≫ eqToHom (functorObj_eq_pos h).symm := by simp only [Functor.const_obj_obj, dite_eq_ite, Functor.ofOpSequence_obj, cone_π_app, limMap_π, Discrete.functor_obj_eq_as, Discrete.natTrans_app] rw [dif_pos h] @[reassoc] lemma cone_π_app_comp_Pi_π_neg (m n : ℕ) (h : ¬(n < m)) : (cone f).π.app ⟨m⟩ ≫ Pi.π _ n = Pi.π _ n ≫ f n ≫ eqToHom (functorObj_eq_neg h).symm := by simp only [Functor.const_obj_obj, dite_eq_ite, Functor.ofOpSequence_obj, cone_π_app, limMap_π, Discrete.functor_obj_eq_as, Discrete.natTrans_app] rw [dif_neg h] /-- The cone over the tower ``` ⋯ → ∏_{n < m} M n × ∏_{n ≥ m} N n → ⋯ → ∏ N ``` with cone point `∏ M` is indeed a limit cone. -/ noncomputable def isLimit : IsLimit (cone f) where lift s := Pi.lift fun m ↦ s.π.app ⟨m + 1⟩ ≫ Pi.π (fun i ↦ if _ : i < m + 1 then M i else N i) m ≫ eqToHom (dif_pos (by omega : m < m + 1)) fac s := by intro ⟨n⟩ apply Pi.hom_ext intro m by_cases h : m < n · simp only [Category.assoc, cone_π_app_comp_Pi_π_pos f _ _ h] simp only [dite_eq_ite, Functor.ofOpSequence_obj, limit.lift_π_assoc, Fan.mk_pt, Discrete.functor_obj_eq_as, Fan.mk_π_app, Category.assoc, eqToHom_trans] have hh : m + 1 ≤ n := by omega rw [← s.w (homOfLE hh).op] simp only [Functor.const_obj_obj, Functor.ofOpSequence_obj, homOfLE_leOfHom, Category.assoc] congr induction' hh using Nat.leRec with n hh ih · simp · have : homOfLE (Nat.le_succ_of_le hh) = homOfLE hh ≫ homOfLE (Nat.le_succ n) := by simp rw [this, op_comp, Functor.map_comp] simp only [Functor.ofOpSequence_obj, Nat.succ_eq_add_one, homOfLE_leOfHom, Functor.ofOpSequence_map_homOfLE_succ, Category.assoc] have h₁ : (if _ : m < m + 1 then M m else N m) = if _ : m < n then M m else N m := by rw [dif_pos (by omega), dif_pos (by omega)] have h₂ : (if _ : m < n then M m else N m) = if _ : m < n + 1 then M m else N m := by rw [dif_pos h, dif_pos (by omega)] rw [← eqToHom_trans h₁ h₂] slice_lhs 2 4 => rw [ih (by omega)] simp only [functorMap, dite_eq_ite, Pi.π, limMap_π_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app] split_ifs rw [dif_pos (by omega)] simp · simp only [Category.assoc] rw [cone_π_app_comp_Pi_π_neg f _ _ h] simp only [dite_eq_ite, Functor.ofOpSequence_obj, limit.lift_π_assoc, Fan.mk_pt, Discrete.functor_obj_eq_as, Fan.mk_π_app, Category.assoc] slice_lhs 2 4 => erw [← functorMap_commSq f h] simp uniq s m h := by apply Pi.hom_ext intro n simp only [Functor.ofOpSequence_obj, dite_eq_ite, limit.lift_π, Fan.mk_pt, Fan.mk_π_app, ← h ⟨n + 1⟩, Category.assoc] slice_rhs 2 3 => erw [cone_π_app_comp_Pi_π_pos f (n + 1) _ (by omega)] simp section variable [HasZeroMorphisms C] [HasFiniteBiproducts C] [HasCountableProducts C] [∀ n, Epi (f n)] attribute [local instance] hasBinaryBiproducts_of_finite_biproducts lemma functorMap_epi (n : ℕ) : Epi (functorMap f n) := by rw [functorMap, Pi.map_eq_prod_map (P := fun m : ℕ ↦ m < n + 1)] apply (config := { allowSynthFailures := true }) epi_comp apply (config := { allowSynthFailures := true }) epi_comp apply (config := { allowSynthFailures := true }) prod.map_epi · apply (config := { allowSynthFailures := true }) Pi.map_epi intro ⟨_, _⟩ split all_goals infer_instance · apply (config := { allowSynthFailures := true }) IsIso.epi_of_iso apply (config := { allowSynthFailures := true }) Pi.map_isIso intro ⟨_, _⟩ split all_goals infer_instance end end CategoryTheory.Limits.SequentialProduct
UniqueFactorizationDomain.lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.RingTheory.Noetherian.Defs import Mathlib.RingTheory.UniqueFactorizationDomain.Ideal /-! # Noetherian domains have unique factorization ## Main results # IsNoetherianRing.wfDvdMonoid -/ variable {R : Type*} [CommSemiring R] [IsDomain R] -- see Note [lower instance priority] instance (priority := 100) IsNoetherianRing.wfDvdMonoid [h : IsNoetherianRing R] : WfDvdMonoid R := WfDvdMonoid.of_setOf_isPrincipal_wellFoundedOn_gt h.wf.wellFoundedOn
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.
CountableInter.lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Order.Filter.Curry import Mathlib.Data.Set.Countable /-! # Filters with countable intersection property In this file we define `CountableInterFilter` to be the class of filters with the following property: for any countable collection of sets `s ∈ l` their intersection belongs to `l` as well. Two main examples are the `residual` filter defined in `Mathlib/Topology/GDelta.lean` and the `MeasureTheory.ae` filter defined in `Mathlib/MeasureTheory.OuterMeasure/AE`. We reformulate the definition in terms of indexed intersection and in terms of `Filter.Eventually` and provide instances for some basic constructions (`⊥`, `⊤`, `Filter.principal`, `Filter.map`, `Filter.comap`, `Inf.inf`). We also provide a custom constructor `Filter.ofCountableInter` that deduces two axioms of a `Filter` from the countable intersection property. Note that there also exists a typeclass `CardinalInterFilter`, and thus an alternative spelling of `CountableInterFilter` as `CardinalInterFilter l ℵ₁`. The former (defined here) is the preferred spelling; it has the advantage of not requiring the user to import the theory of ordinals. ## Tags filter, countable -/ open Set Filter variable {ι : Sort*} {α β : Type*} /-- A filter `l` has the countable intersection property if for any countable collection of sets `s ∈ l` their intersection belongs to `l` as well. -/ class CountableInterFilter (l : Filter α) : Prop where /-- For a countable collection of sets `s ∈ l`, their intersection belongs to `l` as well. -/ countable_sInter_mem : ∀ S : Set (Set α), S.Countable → (∀ s ∈ S, s ∈ l) → ⋂₀ S ∈ l variable {l : Filter α} [CountableInterFilter l] theorem countable_sInter_mem {S : Set (Set α)} (hSc : S.Countable) : ⋂₀ S ∈ l ↔ ∀ s ∈ S, s ∈ l := ⟨fun hS _s hs => mem_of_superset hS (sInter_subset_of_mem hs), CountableInterFilter.countable_sInter_mem _ hSc⟩ theorem countable_iInter_mem [Countable ι] {s : ι → Set α} : (⋂ i, s i) ∈ l ↔ ∀ i, s i ∈ l := sInter_range s ▸ (countable_sInter_mem (countable_range _)).trans forall_mem_range theorem countable_bInter_mem {ι : Type*} {S : Set ι} (hS : S.Countable) {s : ∀ i ∈ S, Set α} : (⋂ i, ⋂ hi : i ∈ S, s i ‹_›) ∈ l ↔ ∀ i, ∀ hi : i ∈ S, s i ‹_› ∈ l := by rw [biInter_eq_iInter] haveI := hS.toEncodable exact countable_iInter_mem.trans Subtype.forall theorem eventually_countable_forall [Countable ι] {p : α → ι → Prop} : (∀ᶠ x in l, ∀ i, p x i) ↔ ∀ i, ∀ᶠ x in l, p x i := by simpa only [Filter.Eventually, setOf_forall] using @countable_iInter_mem _ _ l _ _ fun i => { x | p x i } theorem eventually_countable_ball {ι : Type*} {S : Set ι} (hS : S.Countable) {p : α → ∀ i ∈ S, Prop} : (∀ᶠ x in l, ∀ i hi, p x i hi) ↔ ∀ i hi, ∀ᶠ x in l, p x i hi := by simpa only [Filter.Eventually, setOf_forall] using @countable_bInter_mem _ l _ _ _ hS fun i hi => { x | p x i hi } theorem EventuallyLE.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : ⋃ i, s i ≤ᶠ[l] ⋃ i, t i := (eventually_countable_forall.2 h).mono fun _ hst hs => mem_iUnion.2 <| (mem_iUnion.1 hs).imp hst theorem EventuallyEq.countable_iUnion [Countable ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : ⋃ i, s i =ᶠ[l] ⋃ i, t i := (EventuallyLE.countable_iUnion fun i => (h i).le).antisymm (EventuallyLE.countable_iUnion fun i => (h i).symm.le) theorem EventuallyLE.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› ≤ᶠ[l] ⋃ i ∈ S, t i ‹_› := by simp only [biUnion_eq_iUnion] haveI := hS.toEncodable exact EventuallyLE.countable_iUnion fun i => h i i.2 theorem EventuallyEq.countable_bUnion {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› =ᶠ[l] ⋃ i ∈ S, t i ‹_› := (EventuallyLE.countable_bUnion hS fun i hi => (h i hi).le).antisymm (EventuallyLE.countable_bUnion hS fun i hi => (h i hi).symm.le) theorem EventuallyLE.countable_iInter [Countable ι] {s t : ι → Set α} (h : ∀ i, s i ≤ᶠ[l] t i) : ⋂ i, s i ≤ᶠ[l] ⋂ i, t i := (eventually_countable_forall.2 h).mono fun _ hst hs => mem_iInter.2 fun i => hst _ (mem_iInter.1 hs i) theorem EventuallyEq.countable_iInter [Countable ι] {s t : ι → Set α} (h : ∀ i, s i =ᶠ[l] t i) : ⋂ i, s i =ᶠ[l] ⋂ i, t i := (EventuallyLE.countable_iInter fun i => (h i).le).antisymm (EventuallyLE.countable_iInter fun i => (h i).symm.le) theorem EventuallyLE.countable_bInter {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› ≤ᶠ[l] ⋂ i ∈ S, t i ‹_› := by simp only [biInter_eq_iInter] haveI := hS.toEncodable exact EventuallyLE.countable_iInter fun i => h i i.2 theorem EventuallyEq.countable_bInter {ι : Type*} {S : Set ι} (hS : S.Countable) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› =ᶠ[l] ⋂ i ∈ S, t i ‹_› := (EventuallyLE.countable_bInter hS fun i hi => (h i hi).le).antisymm (EventuallyLE.countable_bInter hS fun i hi => (h i hi).symm.le) /-- Construct a filter with countable intersection property. This constructor deduces `Filter.univ_sets` and `Filter.inter_sets` from the countable intersection property. -/ def Filter.ofCountableInter (l : Set (Set α)) (hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : Filter α where sets := l univ_sets := @sInter_empty α ▸ hl _ countable_empty (empty_subset _) sets_of_superset := h_mono _ _ inter_sets {s t} hs ht := sInter_pair s t ▸ hl _ ((countable_singleton _).insert _) (insert_subset_iff.2 ⟨hs, singleton_subset_iff.2 ht⟩) instance Filter.countableInter_ofCountableInter (l : Set (Set α)) (hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : CountableInterFilter (Filter.ofCountableInter l hl h_mono) := ⟨hl⟩ @[simp] theorem Filter.mem_ofCountableInter {l : Set (Set α)} (hl : ∀ S : Set (Set α), S.Countable → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) {s : Set α} : s ∈ Filter.ofCountableInter l hl h_mono ↔ s ∈ l := Iff.rfl /-- Construct a filter with countable intersection property. Similarly to `Filter.comk`, a set belongs to this filter if its complement satisfies the property. Similarly to `Filter.ofCountableInter`, this constructor deduces some properties from the countable intersection property which becomes the countable union property because we take complements of all sets. -/ def Filter.ofCountableUnion (l : Set (Set α)) (hUnion : ∀ S : Set (Set α), S.Countable → (∀ s ∈ S, s ∈ l) → ⋃₀ S ∈ l) (hmono : ∀ t ∈ l, ∀ s ⊆ t, s ∈ l) : Filter α := by refine .ofCountableInter {s | sᶜ ∈ l} (fun S hSc hSp ↦ ?_) fun s t ht hsub ↦ ?_ · rw [mem_setOf_eq, compl_sInter] apply hUnion (compl '' S) (hSc.image _) intro s hs rw [mem_image] at hs rcases hs with ⟨t, ht, rfl⟩ apply hSp ht · rw [mem_setOf_eq] rw [← compl_subset_compl] at hsub exact hmono sᶜ ht tᶜ hsub instance Filter.countableInter_ofCountableUnion (l : Set (Set α)) (h₁ h₂) : CountableInterFilter (Filter.ofCountableUnion l h₁ h₂) := countableInter_ofCountableInter .. @[simp] theorem Filter.mem_ofCountableUnion {l : Set (Set α)} {hunion hmono s} : s ∈ ofCountableUnion l hunion hmono ↔ l sᶜ := Iff.rfl instance countableInterFilter_principal (s : Set α) : CountableInterFilter (𝓟 s) := ⟨fun _ _ hS => subset_sInter hS⟩ instance countableInterFilter_bot : CountableInterFilter (⊥ : Filter α) := by rw [← principal_empty] apply countableInterFilter_principal instance countableInterFilter_top : CountableInterFilter (⊤ : Filter α) := by rw [← principal_univ] apply countableInterFilter_principal instance (l : Filter β) [CountableInterFilter l] (f : α → β) : CountableInterFilter (comap f l) := by refine ⟨fun S hSc hS => ?_⟩ choose! t htl ht using hS have : (⋂ s ∈ S, t s) ∈ l := (countable_bInter_mem hSc).2 htl refine ⟨_, this, ?_⟩ simpa [preimage_iInter] using iInter₂_mono ht instance (l : Filter α) [CountableInterFilter l] (f : α → β) : CountableInterFilter (map f l) := by refine ⟨fun S hSc hS => ?_⟩ simp only [mem_map, sInter_eq_biInter, preimage_iInter₂] at hS ⊢ exact (countable_bInter_mem hSc).2 hS /-- Infimum of two `CountableInterFilter`s is a `CountableInterFilter`. This is useful, e.g., to automatically get an instance for `residual α ⊓ 𝓟 s`. -/ instance countableInterFilter_inf (l₁ l₂ : Filter α) [CountableInterFilter l₁] [CountableInterFilter l₂] : CountableInterFilter (l₁ ⊓ l₂) := by refine ⟨fun S hSc hS => ?_⟩ choose s hs t ht hst using hS replace hs : (⋂ i ∈ S, s i ‹_›) ∈ l₁ := (countable_bInter_mem hSc).2 hs replace ht : (⋂ i ∈ S, t i ‹_›) ∈ l₂ := (countable_bInter_mem hSc).2 ht refine mem_of_superset (inter_mem_inf hs ht) (subset_sInter fun i hi => ?_) rw [hst i hi] apply inter_subset_inter <;> exact iInter_subset_of_subset i (iInter_subset _ _) /-- Supremum of two `CountableInterFilter`s is a `CountableInterFilter`. -/ instance countableInterFilter_sup (l₁ l₂ : Filter α) [CountableInterFilter l₁] [CountableInterFilter l₂] : CountableInterFilter (l₁ ⊔ l₂) := by refine ⟨fun S hSc hS => ⟨?_, ?_⟩⟩ <;> refine (countable_sInter_mem hSc).2 fun s hs => ?_ exacts [(hS s hs).1, (hS s hs).2] instance CountableInterFilter.curry {α β : Type*} {l : Filter α} {m : Filter β} [CountableInterFilter l] [CountableInterFilter m] : CountableInterFilter (l.curry m) := ⟨by intro S Sct hS simp_rw [mem_curry_iff, mem_sInter, eventually_countable_ball (p := fun _ _ _ => (_ ,_) ∈ _) Sct, eventually_countable_ball (p := fun _ _ _ => ∀ᶠ (_ : β) in m, _) Sct, ← mem_curry_iff] exact hS⟩ namespace Filter variable (g : Set (Set α)) /-- `Filter.CountableGenerateSets g` is the (sets of the) greatest `countableInterFilter` containing `g`. -/ inductive CountableGenerateSets : Set α → Prop | basic {s : Set α} : s ∈ g → CountableGenerateSets s | univ : CountableGenerateSets univ | superset {s t : Set α} : CountableGenerateSets s → s ⊆ t → CountableGenerateSets t | sInter {S : Set (Set α)} : S.Countable → (∀ s ∈ S, CountableGenerateSets s) → CountableGenerateSets (⋂₀ S) /-- `Filter.countableGenerate g` is the greatest `countableInterFilter` containing `g`. -/ def countableGenerate : Filter α := ofCountableInter (CountableGenerateSets g) (fun _ => CountableGenerateSets.sInter) fun _ _ => CountableGenerateSets.superset deriving CountableInterFilter variable {g} /-- A set is in the `countableInterFilter` generated by `g` if and only if it contains a countable intersection of elements of `g`. -/ theorem mem_countableGenerate_iff {s : Set α} : s ∈ countableGenerate g ↔ ∃ S : Set (Set α), S ⊆ g ∧ S.Countable ∧ ⋂₀ S ⊆ s := by constructor <;> intro h · induction h with | @basic s hs => exact ⟨{s}, by simp [hs, subset_refl]⟩ | univ => exact ⟨∅, by simp⟩ | superset _ _ ih => refine Exists.imp (fun S => ?_) ih; tauto | @sInter S Sct _ ih => choose T Tg Tct hT using ih refine ⟨⋃ (s) (H : s ∈ S), T s H, by simpa, Sct.biUnion Tct, ?_⟩ apply subset_sInter intro s H exact subset_trans (sInter_subset_sInter (subset_iUnion₂ s H)) (hT s H) rcases h with ⟨S, Sg, Sct, hS⟩ refine mem_of_superset ((countable_sInter_mem Sct).mpr ?_) hS intro s H exact CountableGenerateSets.basic (Sg H) theorem le_countableGenerate_iff_of_countableInterFilter {f : Filter α} [CountableInterFilter f] : f ≤ countableGenerate g ↔ g ⊆ f.sets := by constructor <;> intro h · exact subset_trans (fun s => CountableGenerateSets.basic) h intro s hs induction hs with | basic hs => exact h hs | univ => exact univ_mem | superset _ st ih => exact mem_of_superset ih st | sInter Sct _ ih => exact (countable_sInter_mem Sct).mpr ih variable (g) /-- `countableGenerate g` is the greatest `countableInterFilter` containing `g`. -/ theorem countableGenerate_isGreatest : IsGreatest { f : Filter α | CountableInterFilter f ∧ g ⊆ f.sets } (countableGenerate g) := by refine ⟨⟨inferInstance, fun s => CountableGenerateSets.basic⟩, ?_⟩ rintro f ⟨fct, hf⟩ rwa [@le_countableGenerate_iff_of_countableInterFilter _ _ _ fct] end Filter
Defs.lean
/- Copyright (c) 2025 Yunzhou Xie. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yunzhou Xie, Jujian Zhang -/ import Mathlib.Algebra.Module.Projective import Mathlib.RingTheory.Finiteness.Defs import Mathlib.RingTheory.TensorProduct.Basic /-! # Azumaya Algebras An Azumaya algebra over a commutative ring `R` is a finitely generated, projective and faithful R-algebra where the tensor product `A ⊗[R] Aᵐᵒᵖ` is isomorphic to the `R`-endomorphisms of A via the map `f : a ⊗ b ↦ (x ↦ a * x * b.unop)`. TODO : Add the three more definitions and prove they are equivalent: · There exists an `R`-algebra `B` such that `B ⊗[R] A` is Morita equivalent to `R`; · `Aᵐᵒᵖ ⊗[R] A` is Morita equivalent to `R`; · The center of `A` is `R` and `A` is a separable algebra. ## Reference * [Benson Farb , R. Keith Dennis, *Noncommutative Algebra*][bensonfarb1993] ## Tags Azumaya algebra, central simple algebra, noncommutative algebra -/ variable (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] open TensorProduct MulOpposite /-- `A` as a `A ⊗[R] Aᵐᵒᵖ`-module (or equivalently, an `A`-`A` bimodule). -/ abbrev instModuleTensorProductMop : Module (A ⊗[R] Aᵐᵒᵖ) A := TensorProduct.Algebra.module /-- The canonical map from `A ⊗[R] Aᵐᵒᵖ` to `Module.End R A` where `a ⊗ b` maps to `f : x ↦ a * x * b`. -/ def AlgHom.mulLeftRight : (A ⊗[R] Aᵐᵒᵖ) →ₐ[R] Module.End R A := letI : Module (A ⊗[R] Aᵐᵒᵖ) A := TensorProduct.Algebra.module letI : IsScalarTower R (A ⊗[R] Aᵐᵒᵖ) A := { smul_assoc := fun r ab a ↦ by change TensorProduct.Algebra.moduleAux _ _ = _ • TensorProduct.Algebra.moduleAux _ _ simp } Algebra.lsmul R (A := A ⊗[R] Aᵐᵒᵖ) R A @[simp] lemma AlgHom.mulLeftRight_apply (a : A) (b : Aᵐᵒᵖ) (x : A) : AlgHom.mulLeftRight R A (a ⊗ₜ b) x = a * x * b.unop := by simp only [AlgHom.mulLeftRight, Algebra.lsmul_coe] change TensorProduct.Algebra.moduleAux _ _ = _ simp [TensorProduct.Algebra.moduleAux, ← mul_assoc] /-- An Azumaya algebra is a finitely generated, projective and faithful R-algebra where `AlgHom.mulLeftRight R A : (A ⊗[R] Aᵐᵒᵖ) →ₐ[R] Module.End R A` is an isomorphism. -/ class IsAzumaya : Prop extends Module.Projective R A, FaithfulSMul R A, Module.Finite R A where bij : Function.Bijective <| AlgHom.mulLeftRight R A
ssralg.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div seq. From mathcomp Require Import choice fintype finfun bigop prime binomial. From mathcomp Require Export nmodule. (******************************************************************************) (* Ring-like structures *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* Reference: Francois Garillot, Georges Gonthier, Assia Mahboubi, Laurence *) (* Rideau, Packaging mathematical structures, TPHOLs 2009 *) (* *) (* This file defines the following algebraic structures: *) (* *) (* semiPzRingType == non-commutative semi rings *) (* (NModule with a multiplication) *) (* The HB class is called PzSemiRing. *) (* nzSemiRingType == non-commutative non-trivial semi rings *) (* (NModule with a multiplication) *) (* The HB class is called NzSemiRing. *) (* comPzSemiRingType == commutative semi rings *) (* The HB class is called ComPzSemiRing. *) (* comNzSemiRingType == commutative non-trivial semi rings *) (* The HB class is called ComNzSemiRing. *) (* pzRingType == non-commutative rings *) (* (semi rings with an opposite) *) (* The HB class is called PzRing. *) (* nzRingType == non-commutative non-trivial rings *) (* (semi rings with an opposite) *) (* The HB class is called NzRing. *) (* comPzRingType == commutative rings *) (* The HB class is called ComPzRing. *) (* comNzRingType == commutative non-trivial rings *) (* The HB class is called ComNzRing. *) (* lSemiModType R == semimodule with left multiplication by external scalars *) (* in the semiring R *) (* The HB class is called LSemiModule. *) (* lmodType R == module with left multiplication by external scalars *) (* in the pzRing R *) (* The HB class is called Lmodule. *) (* lSemiAlgType R == left semialgebra, semiring with scaling that associates *) (* on the left *) (* The HB class is called LSemiAlgebra. *) (* lalgType R == left algebra, ring with scaling that associates on the *) (* left *) (* The HB class is called Lalgebra. *) (* semiAlgType R == semialgebra, semiring with scaling that associates both *) (* left and right *) (* The HB class is called SemiAlgebra. *) (* algType R == algebra, ring with scaling that associates both left *) (* and right *) (* The HB class is called Algebra. *) (*comSemiAlgType R == commutative semiAlgType *) (* The HB class is called ComSemiAlgebra. *) (* comAlgType R == commutative algType *) (* The HB class is called ComAlgebra. *) (* unitRingType == Rings whose units have computable inverses *) (* The HB class is called UnitRing. *) (* comUnitRingType == commutative UnitRing *) (* The HB class is called ComUnitRing. *) (* unitAlgType R == algebra with computable inverses *) (* The HB class is called UnitAlgebra. *) (*comUnitAlgType R == commutative UnitAlgebra *) (* The HB class is called ComUnitAlgebra. *) (* idomainType == integral, commutative, ring with partial inverses *) (* The HB class is called IntegralDomain. *) (* fieldType == commutative fields *) (* The HB class is called Field. *) (* decFieldType == fields with a decidable first order theory *) (* The HB class is called DecidableField. *) (* closedFieldType == algebraically closed fields *) (* The HB class is called ClosedField. *) (* *) (* and their joins with subType: *) (* *) (* subPzSemiRingType R P == join of pzSemiRingType and *) (* subType (P : pred R) such that val is a *) (* semiring morphism *) (* The HB class is called SubPzSemiRing. *) (* subNzSemiRingType R P == join of nzSemiRingType and *) (* subType (P : pred R) such that val is a *) (* semiring morphism *) (* The HB class is called SubNzSemiRing. *) (*subComPzSemiRingType R P == join of comPzSemiRingType and *) (* subType (P : pred R) such that val is a morphism*) (* The HB class is called SubComPzSemiRing. *) (*subComNzSemiRingType R P == join of comNzSemiRingType and *) (* subType (P : pred R) such that val is a morphism*) (* The HB class is called SubComNzSemiRing. *) (* subPzRingType R P == join of pzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubPzRing. *) (* subComPzRingType R P == join of comPzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubComPzRing. *) (* subNzRingType R P == join of nzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubNzRing. *) (* subComNzRingType R P == join of comNzRingType and subType (P : pred R) *) (* such that val is a morphism *) (* The HB class is called SubComNzRing. *) (* subLSemiModType R V P == join of lSemiModType and subType (P : pred V) *) (* such that val is scalable *) (* The HB class is called SubLSemiModule. *) (* subLmodType R V P == join of lmodType and subType (P : pred V) *) (* such that val is scalable *) (* The HB class is called SubLmodule. *) (* subLSemiAlgType R V P == join of lSemiAlgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubLSemiAlgebra. *) (* subLalgType R V P == join of lalgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubLalgebra. *) (* subSemiAlgType R V P == join of semiAlgType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubSemiAlgebra. *) (* subAlgType R V P == join of algType and subType (P : pred V) *) (* such that val is linear *) (* The HB class is called SubAlgebra. *) (* subUnitRingType R P == join of unitRingType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubUnitRing. *) (* subComUnitRingType R P == join of comUnitRingType and subType (P : pred R)*) (* such that val is a ring morphism *) (* The HB class is called SubComUnitRing. *) (* subIdomainType R P == join of idomainType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubIntegralDomain. *) (* subField R P == join of fieldType and subType (P : pred R) *) (* such that val is a ring morphism *) (* The HB class is called SubField. *) (* *) (* Morphisms between the above structures (see below for details): *) (* *) (* {rmorphism R -> S} == semi ring (resp. ring) morphism between *) (* semiPzRingType (resp. pzRingType) instances *) (* R and S. *) (* The HB class is called RMorphism. *) (* {linear U -> V | s} == semilinear (resp. linear) functions of type *) (* U -> V, where U is a left semimodule (resp. *) (* left module) over semiring (resp. ring) R, V is *) (* an N-module (resp. Z-module), and s is a scaling*) (* operator (detailed below) of type R -> V -> V. *) (* The HB class is called Linear. *) (* {lrmorphism A -> B | s} == semialgebra (resp. algebra) morphisms of type *) (* A -> B, where A is a left semialgebra *) (* (resp. left algebra) over semiring (resp. ring) *) (* R, B is an semiring (resp. ring), and s is a *) (* scaling operator (detailed below) of type *) (* R -> B -> B. *) (* The HB class is called LRMorphism. *) (* *) (* -> The scaling operator s above should be one of *:%R, *%R, or a *) (* combination nu \; *:%R or nu \; *%R with a semiring morphism nu; *) (* otherwise some of the theory (e.g., the linearZ rule) will not apply. *) (* To enable the overloading of the scaling operator, we use the following *) (* structures: *) (* *) (* GRing.Scale.preLaw R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.PreLaw. *) (* GRing.Scale.semiLaw R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.SemiLaw. *) (* GRing.Scale.law R V == scaling morphisms of type R -> V -> V *) (* The HB class is called Scale.Law. *) (* *) (* Closedness predicates for the algebraic structures: *) (* *) (* addrClosed V == predicate closed under addition on V : nmodType *) (* The HB class is called AddClosed. *) (* opprClosed V == predicate closed under opposite on V : zmodType *) (* The HB class is called OppClosed. *) (* zmodClosed V == predicate closed under opposite and addition on V *) (* The HB class is called ZmodClosed. *) (* mulr2Closed R == predicate closed under multiplication on *) (* R : semiPzRingType *) (* The HB class is called Mul2Closed. *) (* mulrClosed R == predicate closed under multiplication and for 1 *) (* The HB class is called MulClosed. *) (* semiring2Closed R == predicate closed under addition and multiplication *) (* The HB class is called Semiring2Closed. *) (* semiringClosed R == predicate closed under semiring operations *) (* The HB class is called SemiringClosed. *) (* smulClosed R == predicate closed under multiplication and for -1 *) (* The HB class is called SmulClosed. *) (* subringClosed R == predicate closed under ring operations *) (* The HB class is called SubringClosed. *) (* divClosed R == predicate closed under division *) (* The HB class is called DivClosed. *) (* sdivClosed R == predicate closed under division and opposite *) (* The HB class is called SdivClosed. *) (* submodClosed R == predicate closed under lSemiModType operations *) (* The HB class is called SubmodClosed. *) (* subalgClosed R == predicate closed under lSemiAlgType operations *) (* The HB class is called SubalgClosed. *) (* divringClosed R == predicate closed under unitRing operations *) (* The HB class is called DivringClosed. *) (* divalgClosed R S == predicate closed under (S : unitAlg R) operations *) (* The HB class is called DivalgClosed. *) (* *) (* The rpred* lemmas ensure that the set S remains stable under the specified *) (* operations, provided the corresponding closedness predicate is satisfied. *) (* This stability is crucial for constructing and reasoning about *) (* substructures within algebraic hierarchies. For example: *) (* *) (* - rpred0: Concludes 0 \in S if S is addrClosed. *) (* - rpredD: Concludes x + y \in S if x \in S and y \in S and S is addrClosed.*) (* - rpredN: Concludes -x \in S if x \in S and S is opprClosed. *) (* - rpredZ: Concludes a *: v \in S if v \in S and S is scalerClosed. *) (* *) (* Canonical properties of the algebraic structures: *) (* * Nmodule (additive abelian monoids): *) (* 0 == the zero (additive identity) of a Nmodule *) (* x + y == the sum of x and y (in a Nmodule) *) (* x *+ n == n times x, with n in nat (non-negative), i.e., *) (* x + (x + .. (x + x)..) (n terms); x *+ 1 is thus *) (* convertible to x, and x *+ 2 to x + x *) (* \sum_<range> e == iterated sum for a Nmodule (cf bigop.v) *) (* e`_i == nth 0 e i, when e : seq M and M has a nmodType *) (* structure *) (* support f == 0.-support f, i.e., [pred x | f x != 0] *) (* addr_closed S <-> collective predicate S is closed under finite *) (* sums (0 and x + y in S, for x, y in S) *) (* [SubChoice_isSubNmodule of U by <:] == nmodType mixin for a subType whose *) (* base type is a nmodType and whose predicate's is *) (* an addrClosed *) (* *) (* * Zmodule (additive abelian groups): *) (* - x == the opposite (additive inverse) of x *) (* x - y == the difference of x and y; this is only notation *) (* for x + (- y) *) (* x *- n == notation for - (x *+ n), the opposite of x *+ n *) (* oppr_closed S <-> collective predicate S is closed under opposite *) (* zmod_closed S <-> collective predicate S is closed under zmodType *) (* operations (0 and x - y in S, for x, y in S) *) (* This property coerces to oppr_pred and addr_pred. *) (* [SubChoice_isSubZmodule of U by <:] == zmodType mixin for a subType whose *) (* base type is a zmodType and whose predicate's *) (* is a zmodClosed *) (* *) (* * PzSemiRing (non-commutative semirings): *) (* R^c == the converse (semi)ring for R: R^c is convertible*) (* to R but when R has a canonical (semi)ring *) (* structure R^c has the converse one: *) (* if x y : R^c, then x * y = (y : R) * (x : R) *) (* 1 == the multiplicative identity element of a semiring*) (* n%:R == the semiring image of an n in nat; this is just *) (* notation for 1 *+ n, so 1%:R is convertible to 1 *) (* and 2%:R to 1 + 1 *) (* <number> == <number>%:R with <number> a sequence of digits *) (* x * y == the semiring product of x and y *) (* \prod_<range> e == iterated product for a semiring (cf bigop.v) *) (* x ^+ n == x to the nth power with n in nat (non-negative), *) (* i.e., x * (x * .. (x * x)..) (n factors); x ^+ 1 *) (* is thus convertible to x, and x ^+ 2 to x * x *) (* GRing.comm x y <-> x and y commute, i.e., x * y = y * x *) (* GRing.lreg x <-> x if left-regular, i.e., *%R x is injective *) (* GRing.rreg x <-> x if right-regular, i.e., *%R^~ x is injective *) (* [pchar R] == the characteristic of R, defined as the set of *) (* prime numbers p such that p%:R = 0 in R *) (* The set [pchar R] has at most one element, and is*) (* implemented as a pred_nat collective predicate *) (* (see prime.v); thus the statement p \in [pchar R]*) (* can be read as `R has characteristic p', while *) (* [pchar R] =i pred0 means `R has characteristic 0'*) (* when R is a field. *) (* pFrobenius_aut chRp == the Frobenius automorphism mapping x in R to *) (* x ^+ p, where chRp : p \in [pchar R] is a proof *) (* that R has (non-zero) characteristic p *) (* mulr_closed S <-> collective predicate S is closed under finite *) (* products (1 and x * y in S for x, y in S) *) (* semiring_closed S <-> collective predicate S is closed under semiring *) (* operations (0, 1, x + y and x * y in S) *) (* [SubNmodule_isSubPzSemiRing of R by <:] == *) (* [SubChoice_isSubPzSemiRing of R by <:] == semiPzRingType mixin for a *) (* subType whose base type is a pzSemiRingType and *) (* whose predicate's is a semiringClosed *) (* *) (* * NzSemiRing (non-commutative non-trivial semirings): *) (* [SubNmodule_isSubNzSemiRing of R by <:] == *) (* [SubChoice_isSubNzSemiRing of R by <:] == semiNzRingType mixin for a *) (* subType whose base type is a nzSemiRingType and *) (* whose predicate's is a semiringClosed *) (* *) (* * PzRing (non-commutative rings): *) (* GRing.sign R b := (-1) ^+ b in R : pzRingType, with b : bool *) (* This is a parsing-only helper notation, to be *) (* used for defining more specific instances. *) (* smulr_closed S <-> collective predicate S is closed under products *) (* and opposite (-1 and x * y in S for x, y in S) *) (* subring_closed S <-> collective predicate S is closed under ring *) (* operations (1, x - y and x * y in S) *) (* [SubZmodule_isSubPzRing of R by <:] == *) (* [SubChoice_isSubPzRing of R by <:] == pzRingType mixin for a subType whose *) (* base *) (* type is a pzRingType and whose predicate's is a *) (* subringClosed *) (* *) (* * NzRing (non-commutative non-trivial rings): *) (* [SubZmodule_isSubNzRing of R by <:] == *) (* [SubChoice_isSubNzRing of R by <:] == nzRingType mixin for a subType whose *) (* base *) (* type is a nzRingType and whose predicate's is a *) (* subringClosed *) (* *) (* * ComPzSemiRing (commutative PzSemiRings): *) (* [SubNmodule_isSubComPzSemiRing of R by <:] == *) (* [SubChoice_isSubComPzSemiRing of R by <:] == comPzSemiRingType mixin for a *) (* subType whose base type is a comPzSemiRingType *) (* and whose predicate's is a semiringClosed *) (* *) (* * ComNzSemiRing (commutative NzSemiRings): *) (* [SubNmodule_isSubComNzSemiRing of R by <:] == *) (* [SubChoice_isSubComNzSemiRing of R by <:] == comNzSemiRingType mixin for a *) (* subType whose base type is a comNzSemiRingType *) (* and whose predicate's is a semiringClosed *) (* *) (* * ComPzRing (commutative PzRings): *) (* [SubZmodule_isSubComPzRing of R by <:] == *) (* [SubChoice_isSubComPzRing of R by <:] == comPzRingType mixin for a *) (* subType whose base type is a comPzRingType and *) (* whose predicate's is a subringClosed *) (* *) (* * ComNzRing (commutative NzRings): *) (* [SubZmodule_isSubComNzRing of R by <:] == *) (* [SubChoice_isSubComNzRing of R by <:] == comNzRingType mixin for a *) (* subType whose base type is a comNzRingType and *) (* whose predicate's is a subringClosed *) (* *) (* * UnitRing (NzRings whose units have computable inverses): *) (* x \is a GRing.unit <=> x is a unit (i.e., has an inverse) *) (* x^-1 == the ring inverse of x, if x is a unit, else x *) (* x / y == x divided by y (notation for x * y^-1) *) (* x ^- n := notation for (x ^+ n)^-1, the inverse of x ^+ n *) (* invr_closed S <-> collective predicate S is closed under inverse *) (* divr_closed S <-> collective predicate S is closed under division *) (* (1 and x / y in S) *) (* sdivr_closed S <-> collective predicate S is closed under division *) (* and opposite (-1 and x / y in S, for x, y in S) *) (* divring_closed S <-> collective predicate S is closed under unitRing *) (* operations (1, x - y and x / y in S) *) (* [SubNzRing_isSubUnitRing of R by <:] == *) (* [SubChoice_isSubUnitRing of R by <:] == unitRingType mixin for a subType *) (* whose base type is a unitRingType and whose *) (* predicate's is a divringClosed and whose ring *) (* structure is compatible with the base type's *) (* *) (* * ComUnitRing (commutative rings with computable inverses): *) (* [SubChoice_isSubComUnitRing of R by <:] == comUnitRingType mixin for a *) (* subType whose base type is a comUnitRingType and *) (* whose predicate's is a divringClosed and whose *) (* ring structure is compatible with the base *) (* type's *) (* *) (* * IntegralDomain (integral, commutative, ring with partial inverses): *) (* [SubComUnitRing_isSubIntegralDomain R by <:] == *) (* [SubChoice_isSubIntegralDomain R by <:] == mixin axiom for a idomain *) (* subType *) (* *) (* * Field (commutative fields): *) (* GRing.Field.axiom inv == field axiom: x != 0 -> inv x * x = 1 for all x *) (* This is equivalent to the property above, but *) (* does not require a unitRingType as inv is an *) (* explicit argument. *) (* [SubIntegralDomain_isSubField of R by <:] == mixin axiom for a field *) (* subType *) (* *) (* * DecidableField (fields with a decidable first order theory): *) (* GRing.term R == the type of formal expressions in a unit ring R *) (* with formal variables 'X_k, k : nat, and *) (* manifest constants x%:T, x : R *) (* The notation of all the ring operations is *) (* redefined for terms, in scope %T. *) (* GRing.formula R == the type of first order formulas over R; the %T *) (* scope binds the logical connectives /\, \/, ~, *) (* ==>, ==, and != to formulae; GRing.True/False *) (* and GRing.Bool b denote constant formulae, and *) (* quantifiers are written 'forall/'exists 'X_k, f *) (* GRing.Unit x tests for ring units *) (* GRing.If p_f t_f e_f emulates if-then-else *) (* GRing.Pick p_f t_f e_f emulates fintype.pick *) (* foldr GRing.Exists/Forall q_f xs can be used *) (* to write iterated quantifiers *) (* GRing.eval e t == the value of term t with valuation e : seq R *) (* (e maps 'X_i to e`_i) *) (* GRing.same_env e1 e2 <-> environments e1 and e2 are extensionally equal *) (* GRing.qf_form f == f is quantifier-free *) (* GRing.holds e f == the intuitionistic CiC interpretation of the *) (* formula f holds with valuation e *) (* GRing.qf_eval e f == the value (in bool) of a quantifier-free f *) (* GRing.sat e f == valuation e satisfies f (only in a decField) *) (* GRing.sol n f == a sequence e of size n such that e satisfies f, *) (* if one exists, or [::] if there is no such e *) (* 'exists 'X_i, u1 == 0 /\ ... /\ u_m == 0 /\ v1 != 0 ... /\ v_n != 0 *) (* *) (* * LSemiModule (semimodule with left multiplication by external scalars). *) (* a *: v == v scaled by a, when v is in an LSemiModule V and *) (* a is in the scalar semiring of V *) (* scaler_closed S <-> collective predicate S is closed under scaling *) (* subsemimod_closed S <-> collective predicate S is closed under *) (* lSemiModType operations (0, +%R, and *:%R) *) (* [SubNmodule_isSubLSemiModule of V by <:] == *) (* [SubChoice_isSubLSemiModule of V by <:] == mixin axiom for a subType of an *) (* lSemiModType *) (* *) (* * Lmodule (module with left multiplication by external scalars). *) (* linear_closed S <-> collective predicate S is closed under linear *) (* combinations (a *: u + v in S when u, v in S) *) (* submod_closed S <-> collective predicate S is closed under lmodType *) (* operations (0 and a *: u + v in S) *) (* [SubZmodule_isSubLmodule of V by <:] == *) (* [SubChoice_isSubLmodule of V by <:] == mixin axiom for a subType of an *) (* lmodType *) (* *) (* * LSemiAlgebra *) (* (left semialgebra, semiring with scaling that associates on the left): *) (* R^o == the regular (semi)algebra of R: R^o is *) (* convertible to R, but when R has a *) (* nz(Semi)RingType structure then R^o extends it *) (* to an l(Semi)AlgType structure by letting R act *) (* on itself: if x : R and y : R^o then *) (* x *: y = x * (y : R) *) (* k%:A == the image of the scalar k in a left semialgebra; *) (* this is simply notation for k *: 1 *) (* [SubSemiRing_SubLSemiModule_isSubLSemiAlgebra of V by <:] *) (* == mixin axiom for a subType of an lSemiAlgType *) (* *) (* * Lalgebra (left algebra, ring with scaling that associates on the left): *) (* subalg_closed S <-> collective predicate S is closed under lalgType *) (* operations (1, a *: u + v and u * v in S) *) (* [SubNzRing_SubLmodule_isSubLalgebra of V by <:] == *) (* [SubChoice_isSubLalgebra of V by <:] == mixin axiom for a subType of an *) (* lalgType *) (* *) (* * SemiAlgebra (semiring with scaling that associates both left and right):*) (* [SubLSemiAlgebra_isSubSemiAlgebra of V by <:] == *) (* == mixin axiom for a subType of an semiAlgType *) (* *) (* * Algebra (ring with scaling that associates both left and right): *) (* [SubLalgebra_isSubAlgebra of V by <:] == *) (* [SubChoice_isSubAlgebra of V by <:] == mixin axiom for a subType of an *) (* algType *) (* *) (* * UnitAlgebra (algebra with computable inverses): *) (* divalg_closed S <-> collective predicate S is closed under all *) (* unitAlgType operations (1, a *: u + v and u / v *) (* are in S fo u, v in S) *) (* *) (* In addition to this structure hierarchy, we also develop a separate, *) (* parallel hierarchy for morphisms linking these structures: *) (* *) (* * RMorphism (semiring or ring morphisms): *) (* monoid_morphism f <-> f of type R -> S is a multiplicative monoid *) (* morphism, i.e., f maps 1 and * in R to 1 and * *) (* in S, respectively. R and S must have canonical *) (* pzSemiRingType instances. *) (* {rmorphism R -> S} == the interface type for semiring morphisms; both *) (* R and S must have pzSemiRingType instances *) (* When both R and S have pzRingType instances, it *) (* is a ring morphism. *) (* := GRing.RMorphism.type R S *) (* *) (* -> If R and S are UnitRings the f also maps units to units and inverses *) (* of units to inverses; if R is a field then f is a field isomorphism *) (* between R and its image. *) (* -> Additive properties (raddf_suffix, see below) are duplicated and *) (* specialised for RMorphism (as rmorph_suffix). This allows more *) (* precise rewriting and cleaner chaining: although raddf lemmas will *) (* recognize RMorphism functions, the converse will not hold (we cannot *) (* add reverse inheritance rules because of incomplete backtracking in *) (* the Canonical Projection unification), so one would have to insert a *) (* /= every time one switched from additive to multiplicative rules. *) (* *) (* * Linear (semilinear or linear functions): *) (* scalable_for s f <-> f of type U -> V is scalable for the scaling *) (* operator s of type R -> V -> V, i.e., *) (* f morphs a *: _ to s a _; R, U, and V must be a *) (* pzSemiRingType, an lSemiModType R, and an *) (* nmodType, respectively. *) (* := forall a, {morph f : u / a *: u >-> s a u} *) (* scalable f <-> f of type U -> V is scalable, i.e., f morphs *) (* scaling on U to scaling on V, a *: _ to a *: _; *) (* U and V must be lSemiModType R for the same *) (* pzSemiRingType R. *) (* := scalable_for *:%R f *) (* semilinear_for s f <-> f of type U -> V is semilinear for s of type *) (* R -> V -> V , i.e., f morphs a *: _ and addition *) (* on U to s a _ and addition on V, respectively; *) (* R, U, and V must be a pzSemiRingType, an *) (* lSemiModType R and an nmodType, respectively. *) (* := scalable_for s f * {morph f : x y / x + y} *) (* semilinear f <-> f of type U -> V is semilinear, i.e., f morphs *) (* scaling and addition on U to scaling and *) (* addition on V, respectively; U and V must be *) (* lSemiModType R for the same pzSemiRingType R. *) (* := semilinear_for *:% f *) (* semiscalar f <-> f of type U -> R is a semiscalar function, *) (* i.e., f morphs scaling and addition on U to *) (* multiplication and addition on R; R and U must *) (* be a pzSemiRingType and an lSemiModType R, *) (* respectively. *) (* := semilinear_for *%R f *) (* linear_for s f <-> f of type U -> V is linear for s of type *) (* R -> V -> V, i.e., *) (* f (a *: u + v) = s a (f u) + f v; *) (* R, U, and V must be a pzRingType, an lmodType R, *) (* and a zmodType, respectively. *) (* linear f <-> f of type U -> V is linear, i.e., *) (* f (f *: u + v) = a *: f u + f v; *) (* U and V must be lmodType R for the same *) (* pzRingType R. *) (* := linear_for *:%R f *) (* scalar f <-> f of type U -> R is a scalar function, i.e., *) (* f (a *: u + v) = a * f u + f v; *) (* R and U must be a pzRingType and an lmodType R, *) (* respectively. *) (* := linear_for *%R f *) (* {linear U -> V | s} == the interface type for functions (semi)linear *) (* for the scaling operator s of type R -> V -> V, *) (* i.e., a structure that encapsulates two *) (* properties semi_additive f and scalable_for s f *) (* for functions f : U -> V; R, U, and V must be a *) (* pzSemiRingType, an lSemiModType R, and an *) (* nmodType, respectively. *) (* {linear U -> V} == the interface type for (semi)linear functions, *) (* of type U -> V where both U and V must be *) (* lSemiModType R for the same pzSemiRingType R *) (* := {linear U -> V | *:%R} *) (* {scalar U} == the interface type for (semi)scalar functions, *) (* of type U -> R where U must be an lSemiModType R *) (* := {linear U -> R | *%R} *) (* (a *: u)%Rlin == transient forms that simplify to a *: u, a * u, *) (* (a * u)%Rlin nu a *: u, and nu a * u, respectively, and are *) (* (a *:^nu u)%Rlin created by rewriting with the linearZ lemma *) (* (a *^nu u)%Rlin The forms allows the RHS of linearZ to be matched*) (* reliably, using the GRing.Scale.law structure. *) (* -> Similarly to semiring morphisms, semiadditive properties are *) (* specialized for semilinear functions. *) (* -> Although {scalar U} is convertible to {linear U -> R^o}, it does not *) (* actually use R^o, so that rewriting preserves the canonical structure *) (* of the range of scalar functions. *) (* -> The generic linearZ lemma uses a set of bespoke interface structures to *) (* ensure that both left-to-right and right-to-left rewriting work even in *) (* the presence of scaling functions that simplify non-trivially (e.g., *) (* idfun \; *%R). Because most of the canonical instances and projections *) (* are coercions the machinery will be mostly invisible (with only the *) (* {linear ...} structure and %Rlin notations showing), but users should *) (* beware that in (a *: f u)%Rlin, a actually occurs in the f u subterm. *) (* -> The simpler linear_LR, or more specialized linearZZ and scalarZ rules *) (* should be used instead of linearZ if there are complexity issues, as *) (* well as for explicit forward and backward application, as the main *) (* parameter of linearZ is a proper sub-interface of {linear U -> V | s}. *) (* *) (* * LRMorphism (semialgebra or algebra morphisms): *) (* {lrmorphism A -> B | s} == the interface type for semiring (resp. ring) *) (* morphisms semilinear (resp. linear) for the *) (* scaling operator s of type R -> B -> B, i.e., *) (* the join of semiring (resp. ring) morphisms *) (* {rmorphism A -> B} and semilinear (resp. linear) *) (* functions {linear A -> B | s}; R, A, and B must *) (* be a pzSemiRingType (resp. pzRingType), an *) (* lSemiAlgType R (resp. lalgType R), and a *) (* pzSemiRingType (resp. pzRingType), respectively *) (* {lrmorphism A -> B} == the interface type for semialgebra (resp. *) (* algebra) morphisms, where A and B must be *) (* lSemiAlgType R (resp. lalgType R) for the same *) (* pzSemiRingType (resp. pzRingType) R *) (* := {lrmorphism A -> B | *:%R} *) (* -> Linear and rmorphism properties do not need to be specialized for *) (* as we supply inheritance join instances in both directions. *) (* Finally we supply some helper notation for morphisms: *) (* x^f == the image of x under some morphism *) (* This notation is only reserved (not defined) *) (* here; it is bound locally in sections where some *) (* morphism is used heavily (e.g., the container *) (* morphism in the parametricity sections of poly *) (* and matrix, or the Frobenius section here) *) (* \0 == the constant null function, which has a *) (* canonical linear structure, and simplifies on *) (* application (see ssrfun.v) *) (* f \+ g == the additive composition of f and g, i.e., the *) (* function x |-> f x + g x; f \+ g is canonically *) (* linear when f and g are, and simplifies on *) (* application (see ssrfun.v) *) (* f \- g == the function x |-> f x - g x, canonically *) (* linear when f and g are, and simplifies on *) (* application *) (* \- g == the function x |-> - f x, canonically linear *) (* when f is, and simplifies on application *) (* k \*: f == the function x |-> k *: f x, which is *) (* canonically linear when f is and simplifies on *) (* application (this is a shorter alternative to *) (* *:%R k \o f) *) (* GRing.in_alg A == the ring morphism that injects R into A, where A *) (* has an lalgType R structure; GRing.in_alg A k *) (* simplifies to k%:A *) (* a \*o f == the function x |-> a * f x, canonically linear *) (* when f is and its codomain is an algType *) (* and which simplifies on application *) (* a \o* f == the function x |-> f x * a, canonically linear *) (* when f is and its codomain is an lalgType *) (* and which simplifies on application *) (* f \* g == the function x |-> f x * g x; f \* g *) (* simplifies on application *) (* The Lemmas about these structures are contained in both the GRing module *) (* and in the submodule GRing.Theory, which can be imported when unqualified *) (* access to the theory is needed (GRing.Theory also allows the unqualified *) (* use of additive, linear, Linear, etc). The main GRing module should NOT be *) (* imported. *) (* Notations are defined in scope ring_scope (delimiter %R), except term *) (* and formula notations, which are in term_scope (delimiter %T). *) (* This library also extends the conventional suffixes described in library *) (* ssrbool.v with the following: *) (* 0 -- ring 0, as in addr0 : x + 0 = x *) (* 1 -- ring 1, as in mulr1 : x * 1 = x *) (* D -- ring addition, as in linearD : f (u + v) = f u + f v *) (* B -- ring subtraction, as in opprB : - (x - y) = y - x *) (* M -- ring multiplication, as in invfM : (x * y)^-1 = x^-1 * y^-1 *) (* Mn -- ring by nat multiplication, as in raddfMn : f (x *+ n) = f x *+ n *) (* N -- ring opposite, as in mulNr : (- x) * y = - (x * y) *) (* V -- ring inverse, as in mulVr : x^-1 * x = 1 *) (* X -- ring exponentiation, as in rmorphXn : f (x ^+ n) = f x ^+ n *) (* Z -- (left) module scaling, as in linearZ : f (a *: v) = s *: f v *) (* The operator suffixes D, B, M and X are also used for the corresponding *) (* operations on nat, as in natrX : (m ^ n)%:R = m%:R ^+ n. For the binary *) (* power operator, a trailing "n" suffix is used to indicate the operator *) (* suffix applies to the left-hand ring argument, as in *) (* expr1n : 1 ^+ n = 1 vs. expr1 : x ^+ 1 = x. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope ring_scope. Declare Scope term_scope. Declare Scope linear_ring_scope. Reserved Notation "+%R". Reserved Notation "-%R". Reserved Notation "*%R" (format " *%R"). Reserved Notation "*:%R" (format " *:%R"). Reserved Notation "n %:R" (left associativity, format "n %:R"). Reserved Notation "k %:A" (left associativity, format "k %:A"). Reserved Notation "[ 'pchar' F ]" (format "[ 'pchar' F ]"). Reserved Notation "[ 'char' F ]" (format "[ 'char' F ]"). Reserved Notation "x %:T" (left associativity, format "x %:T"). Reserved Notation "''X_' i" (at level 8, i at level 2, format "''X_' i"). (* Patch for recurring Coq parser bug: Coq seg faults when a level 200 *) (* notation is used as a pattern. *) Reserved Notation "''exists' ''X_' i , f" (at level 199, i at level 2, right associativity, format "'[hv' ''exists' ''X_' i , '/ ' f ']'"). Reserved Notation "''forall' ''X_' i , f" (at level 199, i at level 2, right associativity, format "'[hv' ''forall' ''X_' i , '/ ' f ']'"). Reserved Notation "x ^f" (left associativity, format "x ^f"). Reserved Notation "\0". Reserved Notation "f \+ g" (at level 50, left associativity). Reserved Notation "f \- g" (at level 50, left associativity). Reserved Notation "\- f" (at level 35, f at level 35). Reserved Notation "a \*o f" (at level 40). Reserved Notation "a \o* f" (at level 40). Reserved Notation "a \*: f" (at level 40). Reserved Notation "f \* g" (at level 40, left associativity). Reserved Notation "'{' 'additive' U '->' V '}'" (U at level 98, V at level 99, format "{ 'additive' U -> V }"). Reserved Notation "'{' 'rmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'rmorphism' U -> V }"). Reserved Notation "'{' 'lrmorphism' U '->' V '|' s '}'" (U at level 98, V at level 99, format "{ 'lrmorphism' U -> V | s }"). Reserved Notation "'{' 'lrmorphism' U '->' V '}'" (U at level 98, V at level 99, format "{ 'lrmorphism' U -> V }"). Reserved Notation "'{' 'linear' U '->' V '|' s '}'" (U at level 98, V at level 99, format "{ 'linear' U -> V | s }"). Reserved Notation "'{' 'linear' U '->' V '}'" (U at level 98, V at level 99, format "{ 'linear' U -> V }"). Reserved Notation "'{' 'scalar' U '}'" (format "{ 'scalar' U }"). Reserved Notation "R ^c" (format "R ^c"). Reserved Notation "R ^o" (format "R ^o"). Declare Scope ring_scope. Delimit Scope ring_scope with R. Declare Scope term_scope. Delimit Scope term_scope with T. Local Open Scope ring_scope. Module Export Dummy. Module GRing := Algebra. End Dummy. Module Import GRing. Export Algebra. Import Monoid.Theory. Local Notation "0" := (@zero _) : ring_scope. Local Notation "+%R" := (@add _) : function_scope. Local Notation "x + y" := (add x y) : ring_scope. Local Notation "x *+ n" := (natmul x n) : ring_scope. Local Notation "\sum_ ( i <- r | P ) F" := (\big[+%R/0]_(i <- r | P) F). Local Notation "\sum_ ( m <= i < n ) F" := (\big[+%R/0]_(m <= i < n) F). Local Notation "\sum_ ( i < n ) F" := (\big[+%R/0]_(i < n) F). Local Notation "\sum_ ( i 'in' A ) F" := (\big[+%R/0]_(i in A) F). Local Notation "s `_ i" := (nth 0 s i) : ring_scope. Section NmoduleTheory. Variable V : nmodType. Implicit Types x y : V. Lemma addrA : associative (@add V). Proof. exact: addrA. Qed. Lemma addrC : commutative (@add V). Proof. exact: addrC. Qed. Lemma add0r : left_id (@zero V) add. Proof. exact: add0r. Qed. Lemma addr0 : right_id (@zero V) add. Proof. exact: addr0. Qed. Lemma addrCA : @left_commutative V V +%R. Proof. exact: addrCA. Qed. Lemma addrAC : @right_commutative V V +%R. Proof. exact: addrAC. Qed. Lemma addrACA : @interchange V +%R +%R. Proof. exact: addrACA. Qed. Lemma mulr0n x : x *+ 0 = 0. Proof. exact: mulr0n. Qed. Lemma mulr1n x : x *+ 1 = x. Proof. exact: mulr1n. Qed. Lemma mulr2n x : x *+ 2 = x + x. Proof. exact: mulr2n. Qed. Lemma mulrS x n : x *+ n.+1 = x + (x *+ n). Proof. exact: mulrS. Qed. Lemma mulrSr x n : x *+ n.+1 = x *+ n + x. Proof. exact: mulrSr. Qed. Lemma mulrb x (b : bool) : x *+ b = (if b then x else 0). Proof. exact: mulrb. Qed. Lemma mul0rn n : 0 *+ n = 0 :> V. Proof. exact: mul0rn. Qed. Lemma mulrnDl n : {morph (fun x => x *+ n) : x y / x + y}. Proof. exact: mulrnDl. Qed. Lemma mulrnDr x m n : x *+ (m + n) = x *+ m + x *+ n. Proof. exact: mulrnDr. Qed. Lemma mulrnA x m n : x *+ (m * n) = x *+ m *+ n. Proof. exact: mulrnA. Qed. Lemma mulrnAC x m n : x *+ m *+ n = x *+ n *+ m. Proof. exact: mulrnAC. Qed. Lemma iter_addr n x y : iter n (+%R x) y = x *+ n + y. Proof. exact: iter_addr. Qed. Lemma iter_addr_0 n x : iter n (+%R x) 0 = x *+ n. Proof. exact: iter_addr_0. Qed. Lemma sumrMnl I r P (F : I -> V) n : \sum_(i <- r | P i) F i *+ n = (\sum_(i <- r | P i) F i) *+ n. Proof. exact: sumrMnl. Qed. Lemma sumrMnr x I r P (F : I -> nat) : \sum_(i <- r | P i) x *+ F i = x *+ (\sum_(i <- r | P i) F i). Proof. exact: sumrMnr. Qed. Lemma sumr_const (I : finType) (A : pred I) x : \sum_(i in A) x = x *+ #|A|. Proof. exact: sumr_const. Qed. Lemma sumr_const_nat m n x : \sum_(n <= i < m) x = x *+ (m - n). Proof. exact: sumr_const_nat. Qed. #[deprecated(since="mathcomp 2.4.0", note="Use Algebra.nmod_closed instead.")] Definition addr_closed := nmod_closed. End NmoduleTheory. Local Notation "-%R" := (@opp _) : ring_scope. Local Notation "- x" := (opp x) : ring_scope. Local Notation "x - y" := (x + - y) : ring_scope. Local Notation "x *- n" := (- (x *+ n)) : ring_scope. Section ZmoduleTheory. Variable V : zmodType. Implicit Types x y : V. Lemma addNr : @left_inverse V V V 0 -%R +%R. Proof. exact: addNr. Qed. Lemma addrN : @right_inverse V V V 0 -%R +%R. Proof. exact: addrN. Qed. Definition subrr := addrN. Lemma addKr : @left_loop V V -%R +%R. Proof. exact: addKr. Qed. Lemma addNKr : @rev_left_loop V V -%R +%R. Proof. exact: addNKr. Qed. Lemma addrK : @right_loop V V -%R +%R. Proof. exact: addrK. Qed. Lemma addrNK : @rev_right_loop V V -%R +%R. Proof. exact: addrNK. Qed. Definition subrK := addrNK. Lemma subrKC x y : x + (y - x) = y. Proof. by rewrite addrC subrK. Qed. Lemma subKr x : involutive (fun y => x - y). Proof. exact: subKr. Qed. Lemma addrI : @right_injective V V V +%R. Proof. exact: addrI. Qed. Lemma addIr : @left_injective V V V +%R. Proof. exact: addIr. Qed. Lemma subrI : right_injective (fun x y => x - y). Proof. exact: subrI. Qed. Lemma subIr : left_injective (fun x y => x - y). Proof. exact: subIr. Qed. Lemma opprK : @involutive V -%R. Proof. exact: opprK. Qed. Lemma oppr_inj : @injective V V -%R. Proof. exact: oppr_inj. Qed. Lemma oppr0 : -0 = 0 :> V. Proof. exact: oppr0. Qed. Lemma oppr_eq0 x : (- x == 0) = (x == 0). Proof. exact: oppr_eq0. Qed. Lemma subr0 x : x - 0 = x. Proof. exact: subr0. Qed. Lemma sub0r x : 0 - x = - x. Proof. exact: sub0r. Qed. Lemma opprB x y : - (x - y) = y - x. Proof. exact: opprB. Qed. Lemma opprD : {morph -%R: x y / x + y : V}. Proof. exact: opprD. Qed. Lemma addrKA z x y : (x + z) - (z + y) = x - y. Proof. exact: addrKA. Qed. Lemma subrKA z x y : (x - z) + (z + y) = x + y. Proof. exact: subrKA. Qed. Lemma addr0_eq x y : x + y = 0 -> - x = y. Proof. exact: addr0_eq. Qed. Lemma subr0_eq x y : x - y = 0 -> x = y. Proof. exact: subr0_eq. Qed. Lemma subr_eq x y z : (x - z == y) = (x == y + z). Proof. exact: subr_eq. Qed. Lemma subr_eq0 x y : (x - y == 0) = (x == y). Proof. exact: subr_eq0. Qed. Lemma addr_eq0 x y : (x + y == 0) = (x == - y). Proof. exact: addr_eq0. Qed. Lemma eqr_opp x y : (- x == - y) = (x == y). Proof. exact: eqr_opp. Qed. Lemma eqr_oppLR x y : (- x == y) = (x == - y). Proof. exact: eqr_oppLR. Qed. Lemma mulNrn x n : (- x) *+ n = x *- n. Proof. exact: mulNrn. Qed. Lemma mulrnBl n : {morph (fun x => x *+ n) : x y / x - y}. Proof. exact: mulrnBl. Qed. Lemma mulrnBr x m n : n <= m -> x *+ (m - n) = x *+ m - x *+ n. Proof. exact: mulrnBr. Qed. Lemma sumrN I r P (F : I -> V) : (\sum_(i <- r | P i) - F i = - (\sum_(i <- r | P i) F i)). Proof. exact: sumrN. Qed. Lemma sumrB I r (P : pred I) (F1 F2 : I -> V) : \sum_(i <- r | P i) (F1 i - F2 i) = \sum_(i <- r | P i) F1 i - \sum_(i <- r | P i) F2 i. Proof. exact: sumrB. Qed. Lemma telescope_sumr n m (f : nat -> V) : n <= m -> \sum_(n <= k < m) (f k.+1 - f k) = f m - f n. Proof. exact: telescope_sumr. Qed. Lemma telescope_sumr_eq n m (f u : nat -> V) : n <= m -> (forall k, (n <= k < m)%N -> u k = f k.+1 - f k) -> \sum_(n <= k < m) u k = f m - f n. Proof. exact: telescope_sumr_eq. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition oppr_closed := oppr_closed S. Definition subr_2closed := subr_closed S. Definition zmod_closed := zmod_closed S. Lemma zmod_closedN : zmod_closed -> oppr_closed. Proof. exact: zmod_closedN. Qed. Lemma zmod_closedD : zmod_closed -> nmod_closed S. Proof. by move=> z; split; [case: z|apply/zmod_closedD]. Qed. End ClosedPredicates. End ZmoduleTheory. Arguments addrI {V} y [x1 x2]. Arguments addIr {V} x [x1 x2]. Arguments opprK {V}. Arguments oppr_inj {V} [x1 x2]. Arguments telescope_sumr_eq {V n m} f u. HB.mixin Record Nmodule_isPzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; }. #[short(type="pzSemiRingType")] HB.structure Definition PzSemiRing := { R of Nmodule_isPzSemiRing R & Nmodule R }. HB.factory Record isPzSemiRing R of Choice R := { zero : R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; }. HB.builders Context R of isPzSemiRing R. HB.instance Definition _ := @isNmodule.Build R zero add addrA addrC add0r. HB.instance Definition _ := @Nmodule_isPzSemiRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.end. Module PzSemiRingExports. Bind Scope ring_scope with PzSemiRing.sort. End PzSemiRingExports. HB.export PzSemiRingExports. HB.mixin Record PzSemiRing_isNonZero R of PzSemiRing R := { oner_neq0 : @one R != 0 }. #[short(type="nzSemiRingType")] HB.structure Definition NzSemiRing := { R of PzSemiRing_isNonZero R & PzSemiRing R }. #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing instead.")] Notation SemiRing R := (NzSemiRing R) (only parsing). Module SemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.sort instead.")] Notation sort := (NzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.on instead.")] Notation on R := (NzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzSemiRing.copy instead.")] Notation copy T U := (NzSemiRing.copy T U) (only parsing). End SemiRing. HB.factory Record Nmodule_isNzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; oner_neq0 : one != 0 }. HB.builders Context R of Nmodule_isNzSemiRing R. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0. HB.end. Module Nmodule_isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isNzSemiRing.Build instead.")] Notation Build R := (Nmodule_isNzSemiRing.Build R) (only parsing). End Nmodule_isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isNzSemiRing instead.")] Notation Nmodule_isSemiRing R := (Nmodule_isNzSemiRing R) (only parsing). HB.factory Record isNzSemiRing R of Choice R := { zero : R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; mul0r : left_zero zero mul; mulr0 : right_zero zero mul; oner_neq0 : one != zero }. Module isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzSemiRing.Build instead.")] Notation Build R := (isNzSemiRing.Build R) (only parsing). End isSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzSemiRing instead.")] Notation isSemiRing R := (isNzSemiRing R) (only parsing). HB.builders Context R of isNzSemiRing R. HB.instance Definition _ := @isNmodule.Build R zero add addrA addrC add0r. HB.instance Definition _ := @Nmodule_isNzSemiRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0. HB.end. Module NzSemiRingExports. Bind Scope ring_scope with NzSemiRing.sort. End NzSemiRingExports. HB.export NzSemiRingExports. Definition exp R x n := iterop n (@mul R) x (@one R). Arguments exp : simpl never. Definition comm R x y := @mul R x y = mul y x. Definition lreg R x := injective (@mul R x). Definition rreg R x := injective ((@mul R)^~ x). Local Notation "1" := (@one _) : ring_scope. Local Notation "n %:R" := (1 *+ n) : ring_scope. Local Notation "*%R" := (@mul _) : function_scope. Local Notation "x * y" := (mul x y) : ring_scope. Local Notation "x ^+ n" := (exp x n) : ring_scope. Local Notation "\prod_ ( i <- r | P ) F" := (\big[*%R/1]_(i <- r | P) F). Local Notation "\prod_ ( i | P ) F" := (\big[*%R/1]_(i | P) F). Local Notation "\prod_ ( i 'in' A ) F" := (\big[*%R/1]_(i in A) F). Local Notation "\prod_ ( m <= i < n ) F" := (\big[*%R/1%R]_(m <= i < n) F%R). (* The ``field'' characteristic; the definition, and many of the theorems, *) (* has to apply to rings as well; indeed, we need the Frobenius automorphism *) (* results for a non commutative ring in the proof of Gorenstein 2.6.3. *) Definition pchar (R : nzSemiRingType) : nat_pred := [pred p | prime p & p%:R == 0 :> R]. #[deprecated(since="mathcomp 2.4.0", note="Use pchar instead.")] Notation char := pchar (only parsing). Local Notation has_pchar0 L := (pchar L =i pred0). #[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")] Notation has_char0 L := (has_pchar0 L) (only parsing). (* Converse ring tag. *) Definition converse R : Type := R. Local Notation "R ^c" := (converse R) : type_scope. Section PzSemiRingTheory. Variable R : pzSemiRingType. Implicit Types x y : R. #[export] HB.instance Definition _ := Monoid.isLaw.Build R 1 *%R mulrA mul1r mulr1. #[export] HB.instance Definition _ := Monoid.isMulLaw.Build R 0 *%R mul0r mulr0. #[export] HB.instance Definition _ := Monoid.isAddLaw.Build R *%R +%R mulrDl mulrDr. Lemma mulr_suml I r P (F : I -> R) x : (\sum_(i <- r | P i) F i) * x = \sum_(i <- r | P i) F i * x. Proof. exact: big_distrl. Qed. Lemma mulr_sumr I r P (F : I -> R) x : x * (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) x * F i. Proof. exact: big_distrr. Qed. Lemma mulrnAl x y n : (x *+ n) * y = (x * y) *+ n. Proof. by elim: n => [|n IHn]; rewrite ?mul0r // !mulrS mulrDl IHn. Qed. Lemma mulrnAr x y n : x * (y *+ n) = (x * y) *+ n. Proof. by elim: n => [|n IHn]; rewrite ?mulr0 // !mulrS mulrDr IHn. Qed. Lemma mulr_natl x n : n%:R * x = x *+ n. Proof. by rewrite mulrnAl mul1r. Qed. Lemma mulr_natr x n : x * n%:R = x *+ n. Proof. by rewrite mulrnAr mulr1. Qed. Lemma natrD m n : (m + n)%:R = m%:R + n%:R :> R. Proof. exact: mulrnDr. Qed. Lemma natr1 n : n%:R + 1 = n.+1%:R :> R. Proof. by rewrite mulrSr. Qed. Lemma nat1r n : 1 + n%:R = n.+1%:R :> R. Proof. by rewrite mulrS. Qed. Definition natr_sum := big_morph (natmul 1) natrD (mulr0n 1). Lemma natrM m n : (m * n)%:R = m%:R * n%:R :> R. Proof. by rewrite mulrnA mulr_natr. Qed. Lemma expr0 x : x ^+ 0 = 1. Proof. by []. Qed. Lemma expr1 x : x ^+ 1 = x. Proof. by []. Qed. Lemma expr2 x : x ^+ 2 = x * x. Proof. by []. Qed. Lemma exprS x n : x ^+ n.+1 = x * x ^+ n. Proof. by case: n => //; rewrite mulr1. Qed. Lemma expr0n n : 0 ^+ n = (n == 0%N)%:R :> R. Proof. by case: n => // n; rewrite exprS mul0r. Qed. Lemma expr1n n : 1 ^+ n = 1 :> R. Proof. by elim: n => // n IHn; rewrite exprS mul1r. Qed. Lemma exprD x m n : x ^+ (m + n) = x ^+ m * x ^+ n. Proof. by elim: m => [|m IHm]; rewrite ?mul1r // !exprS -mulrA -IHm. Qed. Lemma exprSr x n : x ^+ n.+1 = x ^+ n * x. Proof. by rewrite -addn1 exprD expr1. Qed. Lemma expr_sum x (I : Type) (s : seq I) (P : pred I) F : x ^+ (\sum_(i <- s | P i) F i) = \prod_(i <- s | P i) x ^+ F i :> R. Proof. exact: (big_morph _ (exprD _)). Qed. Lemma commr_sym x y : comm x y -> comm y x. Proof. by []. Qed. Lemma commr_refl x : comm x x. Proof. by []. Qed. Lemma commr0 x : comm x 0. Proof. by rewrite /comm mulr0 mul0r. Qed. Lemma commr1 x : comm x 1. Proof. by rewrite /comm mulr1 mul1r. Qed. Lemma commrD x y z : comm x y -> comm x z -> comm x (y + z). Proof. by rewrite /comm mulrDl mulrDr => -> ->. Qed. Lemma commr_sum (I : Type) (s : seq I) (P : pred I) (F : I -> R) x : (forall i, P i -> comm x (F i)) -> comm x (\sum_(i <- s | P i) F i). Proof. move=> comm_x_F; rewrite /comm mulr_suml mulr_sumr. by apply: eq_bigr => i /comm_x_F. Qed. Lemma commrMn x y n : comm x y -> comm x (y *+ n). Proof. rewrite /comm => com_xy. by elim: n => [|n IHn]; rewrite ?commr0 // mulrS commrD. Qed. Lemma commrM x y z : comm x y -> comm x z -> comm x (y * z). Proof. by move=> com_xy; rewrite /comm mulrA com_xy -!mulrA => ->. Qed. Lemma commr_prod (I : Type) (s : seq I) (P : pred I) (F : I -> R) x : (forall i, P i -> comm x (F i)) -> comm x (\prod_(i <- s | P i) F i). Proof. exact: (big_ind _ (commr1 x) (@commrM x)). Qed. Lemma commr_nat x n : comm x n%:R. Proof. exact/commrMn/commr1. Qed. Lemma commrX x y n : comm x y -> comm x (y ^+ n). Proof. rewrite /comm => com_xy. by elim: n => [|n IHn]; rewrite ?commr1 // exprS commrM. Qed. Lemma exprMn_comm x y n : comm x y -> (x * y) ^+ n = x ^+ n * y ^+ n. Proof. move=> com_xy; elim: n => /= [|n IHn]; first by rewrite mulr1. by rewrite !exprS IHn !mulrA; congr (_ * _); rewrite -!mulrA -commrX. Qed. Lemma exprMn_n x m n : (x *+ m) ^+ n = x ^+ n *+ (m ^ n) :> R. Proof. elim: n => [|n IHn]; first by rewrite mulr1n. by rewrite exprS IHn mulrnAl mulrnAr -mulrnA exprS -expnSr. Qed. Lemma exprM x m n : x ^+ (m * n) = x ^+ m ^+ n. Proof. elim: m => [|m IHm]; first by rewrite expr1n. by rewrite mulSn exprD IHm exprS exprMn_comm //; apply: commrX. Qed. Lemma exprAC x m n : (x ^+ m) ^+ n = (x ^+ n) ^+ m. Proof. by rewrite -!exprM mulnC. Qed. Lemma expr_mod n x i : x ^+ n = 1 -> x ^+ (i %% n) = x ^+ i. Proof. move=> xn1; rewrite {2}(divn_eq i n) exprD mulnC exprM xn1. by rewrite expr1n mul1r. Qed. Lemma expr_dvd n x i : x ^+ n = 1 -> n %| i -> x ^+ i = 1. Proof. by move=> xn1 dvd_n_i; rewrite -(expr_mod i xn1) (eqnP dvd_n_i). Qed. Lemma natrX n k : (n ^ k)%:R = n%:R ^+ k :> R. Proof. by rewrite exprMn_n expr1n. Qed. Lemma mulrI_eq0 x y : lreg x -> (x * y == 0) = (y == 0). Proof. by move=> reg_x; rewrite -{1}(mulr0 x) (inj_eq reg_x). Qed. Lemma lreg1 : lreg (1 : R). Proof. by move=> x y; rewrite !mul1r. Qed. Lemma lregM x y : lreg x -> lreg y -> lreg (x * y). Proof. by move=> reg_x reg_y z t; rewrite -!mulrA => /reg_x/reg_y. Qed. Lemma lregMl (a b: R) : lreg (a * b) -> lreg b. Proof. by move=> rab c c' eq_bc; apply/rab; rewrite -!mulrA eq_bc. Qed. Lemma rregMr (a b: R) : rreg (a * b) -> rreg a. Proof. by move=> rab c c' eq_ca; apply/rab; rewrite !mulrA eq_ca. Qed. Lemma lregX x n : lreg x -> lreg (x ^+ n). Proof. by move=> reg_x; elim: n => [|n]; [apply: lreg1 | rewrite exprS; apply: lregM]. Qed. Lemma iter_mulr n x y : iter n ( *%R x) y = x ^+ n * y. Proof. by elim: n => [|n ih]; rewrite ?expr0 ?mul1r //= ih exprS -mulrA. Qed. Lemma iter_mulr_1 n x : iter n ( *%R x) 1 = x ^+ n. Proof. by rewrite iter_mulr mulr1. Qed. Lemma prodr_const (I : finType) (A : pred I) x : \prod_(i in A) x = x ^+ #|A|. Proof. by rewrite big_const -iteropE. Qed. Lemma prodr_const_nat n m x : \prod_(n <= i < m) x = x ^+ (m - n). Proof. by rewrite big_const_nat -iteropE. Qed. Lemma prodrXr x I r P (F : I -> nat) : \prod_(i <- r | P i) x ^+ F i = x ^+ (\sum_(i <- r | P i) F i). Proof. by rewrite (big_morph _ (exprD _) (erefl _)). Qed. Lemma prodrM_comm {I : eqType} r (P : pred I) (F G : I -> R) : (forall i j, P i -> P j -> comm (F i) (G j)) -> \prod_(i <- r | P i) (F i * G i) = \prod_(i <- r | P i) F i * \prod_(i <- r | P i) G i. Proof. move=> FG; elim: r => [|i r IHr]; rewrite !(big_nil, big_cons) ?mulr1//. case: ifPn => // Pi; rewrite IHr !mulrA; congr (_ * _); rewrite -!mulrA. by rewrite commr_prod // => j Pj; apply/commr_sym/FG. Qed. Lemma prodrMl_comm {I : finType} (A : pred I) (x : R) F : (forall i, A i -> comm x (F i)) -> \prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i. Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j _ /xF. Qed. Lemma prodrMr_comm {I : finType} (A : pred I) (x : R) F : (forall i, A i -> comm x (F i)) -> \prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|. Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j /xF. Qed. Lemma prodrMn (I : Type) (s : seq I) (P : pred I) (F : I -> R) (g : I -> nat) : \prod_(i <- s | P i) (F i *+ g i) = \prod_(i <- s | P i) (F i) *+ \prod_(i <- s | P i) g i. Proof. by elim/big_rec3: _ => // i y1 y2 y3 _ ->; rewrite mulrnAr mulrnAl -mulrnA. Qed. Lemma prodrMn_const n (I : finType) (A : pred I) (F : I -> R) : \prod_(i in A) (F i *+ n) = \prod_(i in A) F i *+ n ^ #|A|. Proof. by rewrite prodrMn prod_nat_const. Qed. Lemma natr_prod I r P (F : I -> nat) : (\prod_(i <- r | P i) F i)%:R = \prod_(i <- r | P i) (F i)%:R :> R. Proof. exact: (big_morph _ natrM). Qed. Lemma exprDn_comm x y n (cxy : comm x y) : (x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. elim: n => [|n IHn]; rewrite big_ord_recl mulr1 ?big_ord0 ?addr0 //=. rewrite exprS {}IHn /= mulrDl !big_distrr /= big_ord_recl mulr1 subn0. rewrite !big_ord_recr /= !binn !subnn !mul1r !subn0 bin0 !exprS -addrA. congr (_ + _); rewrite addrA -big_split /=; congr (_ + _). apply: eq_bigr => i _; rewrite !mulrnAr !mulrA -exprS -subSn ?(valP i) //. by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS -mulrnDr. Qed. Lemma exprD1n x n : (x + 1) ^+ n = \sum_(i < n.+1) x ^+ i *+ 'C(n, i). Proof. rewrite addrC (exprDn_comm n (commr_sym (commr1 x))). by apply: eq_bigr => i _; rewrite expr1n mul1r. Qed. Lemma sqrrD1 x : (x + 1) ^+ 2 = x ^+ 2 + x *+ 2 + 1. Proof. rewrite exprD1n !big_ord_recr big_ord0 /= add0r. by rewrite addrC addrA addrAC. Qed. Section ClosedPredicates. Variable S : {pred R}. Definition mulr_2closed := {in S &, forall u v, u * v \in S}. Definition mulr_closed := 1 \in S /\ mulr_2closed. Definition semiring_closed := nmod_closed S /\ mulr_closed. Lemma semiring_closedD : semiring_closed -> nmod_closed S. Proof. by case. Qed. Lemma semiring_closedM : semiring_closed -> mulr_closed. Proof. by case. Qed. End ClosedPredicates. End PzSemiRingTheory. Section NzSemiRingTheory. Variable R : nzSemiRingType. Implicit Types x y : R. Lemma oner_eq0 : (1 == 0 :> R) = false. Proof. exact: negbTE oner_neq0. Qed. Lemma lastr_eq0 (s : seq R) x : x != 0 -> (last x s == 0) = (last 1 s == 0). Proof. by case: s => [|y s] /negPf // ->; rewrite oner_eq0. Qed. Lemma lreg_neq0 x : lreg x -> x != 0. Proof. by move=> reg_x; rewrite -[x]mulr1 mulrI_eq0 ?oner_eq0. Qed. Definition pFrobenius_aut p of p \in pchar R := fun x => x ^+ p. (* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible definition. *) Section FrobeniusAutomorphism. Variable p : nat. Hypothesis pcharFp : p \in pchar R. Lemma pcharf0 : p%:R = 0 :> R. Proof. by apply/eqP; case/andP: pcharFp. Qed. Lemma pcharf_prime : prime p. Proof. by case/andP: pcharFp. Qed. Hint Resolve pcharf_prime : core. Lemma mulrn_pchar x : x *+ p = 0. Proof. by rewrite -mulr_natl pcharf0 mul0r. Qed. Lemma natr_mod_pchar n : (n %% p)%:R = n%:R :> R. Proof. by rewrite {2}(divn_eq n p) natrD mulrnA mulrn_pchar add0r. Qed. Lemma dvdn_pcharf n : (p %| n)%N = (n%:R == 0 :> R). Proof. apply/idP/eqP=> [/dvdnP[n' ->]|n0]; first by rewrite natrM pcharf0 mulr0. apply/idPn; rewrite -prime_coprime // => /eqnP pn1. have [a _ /dvdnP[b]] := Bezoutl n (prime_gt0 pcharf_prime). move/(congr1 (fun m => m%:R : R))/eqP. by rewrite natrD !natrM pcharf0 n0 !mulr0 pn1 addr0 oner_eq0. Qed. Lemma pcharf_eq : pchar R =i (p : nat_pred). Proof. move=> q; apply/andP/eqP=> [[q_pr q0] | ->]; last by rewrite pcharf0. by apply/eqP; rewrite eq_sym -dvdn_prime2 // dvdn_pcharf. Qed. Lemma bin_lt_pcharf_0 k : 0 < k < p -> 'C(p, k)%:R = 0 :> R. Proof. by move=> lt0kp; apply/eqP; rewrite -dvdn_pcharf prime_dvd_bin. Qed. Local Notation "x ^f" := (pFrobenius_aut pcharFp x). Lemma pFrobenius_autE x : x^f = x ^+ p. Proof. by []. Qed. Local Notation f'E := pFrobenius_autE. Lemma pFrobenius_aut0 : 0^f = 0. Proof. by rewrite f'E -(prednK (prime_gt0 pcharf_prime)) exprS mul0r. Qed. Lemma pFrobenius_aut1 : 1^f = 1. Proof. by rewrite f'E expr1n. Qed. Lemma pFrobenius_autD_comm x y (cxy : comm x y) : (x + y)^f = x^f + y^f. Proof. have defp := prednK (prime_gt0 pcharf_prime). rewrite !f'E exprDn_comm // big_ord_recr subnn -defp big_ord_recl /= defp. rewrite subn0 mulr1 mul1r bin0 binn big1 ?addr0 // => i _. by rewrite -mulr_natl bin_lt_pcharf_0 ?mul0r //= -{2}defp ltnS (valP i). Qed. Lemma pFrobenius_autMn x n : (x *+ n)^f = x^f *+ n. Proof. elim: n => [|n IHn]; first exact: pFrobenius_aut0. by rewrite !mulrS pFrobenius_autD_comm ?IHn //; apply: commrMn. Qed. Lemma pFrobenius_aut_nat n : (n%:R)^f = n%:R. Proof. by rewrite pFrobenius_autMn pFrobenius_aut1. Qed. Lemma pFrobenius_autM_comm x y : comm x y -> (x * y)^f = x^f * y^f. Proof. exact: exprMn_comm. Qed. Lemma pFrobenius_autX x n : (x ^+ n)^f = x^f ^+ n. Proof. by rewrite !f'E -!exprM mulnC. Qed. End FrobeniusAutomorphism. Section Char2. Hypothesis pcharR2 : 2 \in pchar R. Lemma addrr_pchar2 x : x + x = 0. Proof. by rewrite -mulr2n mulrn_pchar. Qed. End Char2. End NzSemiRingTheory. #[short(type="pzRingType")] HB.structure Definition PzRing := { R of PzSemiRing R & Zmodule R }. HB.factory Record Zmodule_isPzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; }. HB.builders Context R of Zmodule_isPzRing R. Local Notation "1" := one. Local Notation "x * y" := (mul x y). Lemma mul0r : @left_zero R R 0 mul. Proof. by move=> x; apply: (addIr (1 * x)); rewrite -mulrDl !add0r mul1r. Qed. Lemma mulr0 : @right_zero R R 0 mul. Proof. by move=> x; apply: (addIr (x * 1)); rewrite -mulrDr !add0r mulr1. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.end. HB.factory Record isPzRing R of Choice R := { zero : R; opp : R -> R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; addNr : left_inverse zero opp add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; }. HB.builders Context R of isPzRing R. HB.instance Definition _ := @isZmodule.Build R zero opp add addrA addrC add0r addNr. HB.instance Definition _ := @Zmodule_isPzRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr. HB.end. Module PzRingExports. Bind Scope ring_scope with PzRing.sort. End PzRingExports. HB.export PzRingExports. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")] Notation Frobenius_aut := pFrobenius_aut (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")] Notation charf0 := pcharf0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")] Notation charf_prime := pcharf_prime (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")] Notation mulrn_char := mulrn_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use natr_mod_pchar instead.")] Notation natr_mod_char := natr_mod_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")] Notation dvdn_charf := dvdn_pcharf (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")] Notation charf_eq := pcharf_eq (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")] Notation bin_lt_charf_0 := bin_lt_pcharf_0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")] Notation Frobenius_autE := pFrobenius_autE (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")] Notation Frobenius_aut0 := pFrobenius_aut0 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")] Notation Frobenius_aut1 := pFrobenius_aut1 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")] Notation Frobenius_autD_comm := pFrobenius_autD_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")] Notation Frobenius_autMn := pFrobenius_autMn (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")] Notation Frobenius_aut_nat := pFrobenius_aut_nat (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")] Notation Frobenius_autM_comm := pFrobenius_autM_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")] Notation Frobenius_autX := pFrobenius_autX (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")] Notation addrr_char2 := addrr_pchar2 (only parsing). #[short(type="nzRingType")] HB.structure Definition NzRing := { R of NzSemiRing R & Zmodule R }. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing instead.")] Notation Ring R := (NzRing R) (only parsing). Module Ring. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.sort instead.")] Notation sort := (NzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.on instead.")] Notation on R := (NzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use NzRing.copy instead.")] Notation copy T U := (NzRing.copy T U) (only parsing). End Ring. HB.factory Record Zmodule_isNzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul +%R; mulrDr : right_distributive mul +%R; oner_neq0 : one != 0 }. Module Zmodule_isRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isNzRing.Build instead.")] Notation Build R := (Zmodule_isNzRing.Build R) (only parsing). End Zmodule_isRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isNzRing instead.")] Notation Zmodule_isRing R := (Zmodule_isNzRing R) (only parsing). HB.builders Context R of Zmodule_isNzRing R. HB.instance Definition _ := Zmodule_isPzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr. HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0. HB.end. HB.factory Record isNzRing R of Choice R := { zero : R; opp : R -> R; add : R -> R -> R; one : R; mul : R -> R -> R; addrA : associative add; addrC : commutative add; add0r : left_id zero add; addNr : left_inverse zero opp add; mulrA : associative mul; mul1r : left_id one mul; mulr1 : right_id one mul; mulrDl : left_distributive mul add; mulrDr : right_distributive mul add; oner_neq0 : one != zero }. Module isRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzRing.Build instead.")] Notation Build R := (isNzRing.Build R) (only parsing). End isRing. #[deprecated(since="mathcomp 2.4.0", note="Use isNzRing instead.")] Notation isRing R := (isNzRing R) (only parsing). HB.builders Context R of isNzRing R. HB.instance Definition _ := @isZmodule.Build R zero opp add addrA addrC add0r addNr. HB.instance Definition _ := @Zmodule_isNzRing.Build R one mul mulrA mul1r mulr1 mulrDl mulrDr oner_neq0. HB.end. Module NzRingExports. Bind Scope ring_scope with NzRing.sort. End NzRingExports. HB.export NzRingExports. Notation sign R b := (exp (- @one R) (nat_of_bool b)) (only parsing). Local Notation "- 1" := (- (1)) : ring_scope. Section PzRingTheory. Variable R : pzRingType. Implicit Types x y : R. Lemma mulrN x y : x * (- y) = - (x * y). Proof. by apply: (addrI (x * y)); rewrite -mulrDr !subrr mulr0. Qed. Lemma mulNr x y : (- x) * y = - (x * y). Proof. by apply: (addrI (x * y)); rewrite -mulrDl !subrr mul0r. Qed. Lemma mulrNN x y : (- x) * (- y) = x * y. Proof. by rewrite mulrN mulNr opprK. Qed. Lemma mulN1r x : -1 * x = - x. Proof. by rewrite mulNr mul1r. Qed. Lemma mulrN1 x : x * -1 = - x. Proof. by rewrite mulrN mulr1. Qed. Lemma mulrBl x y z : (y - z) * x = y * x - z * x. Proof. by rewrite mulrDl mulNr. Qed. Lemma mulrBr x y z : x * (y - z) = x * y - x * z. Proof. by rewrite mulrDr mulrN. Qed. Lemma natrB m n : n <= m -> (m - n)%:R = m%:R - n%:R :> R. Proof. exact: mulrnBr. Qed. Lemma commrN x y : comm x y -> comm x (- y). Proof. by move=> com_xy; rewrite /comm mulrN com_xy mulNr. Qed. Lemma commrN1 x : comm x (-1). Proof. exact/commrN/commr1. Qed. Lemma commrB x y z : comm x y -> comm x z -> comm x (y - z). Proof. by move=> com_xy com_xz; apply: commrD => //; apply: commrN. Qed. Lemma commr_sign x n : comm x ((-1) ^+ n). Proof. exact: (commrX n (commrN1 x)). Qed. Lemma signr_odd n : (-1) ^+ (odd n) = (-1) ^+ n :> R. Proof. elim: n => //= n IHn; rewrite exprS -{}IHn. by case/odd: n; rewrite !mulN1r ?opprK. Qed. Lemma mulr_sign (b : bool) x : (-1) ^+ b * x = (if b then - x else x). Proof. by case: b; rewrite ?mulNr mul1r. Qed. Lemma signr_addb b1 b2 : (-1) ^+ (b1 (+) b2) = (-1) ^+ b1 * (-1) ^+ b2 :> R. Proof. by rewrite mulr_sign; case: b1 b2 => [] []; rewrite ?opprK. Qed. Lemma signrE (b : bool) : (-1) ^+ b = 1 - b.*2%:R :> R. Proof. by case: b; rewrite ?subr0 // opprD addNKr. Qed. Lemma signrN b : (-1) ^+ (~~ b) = - (-1) ^+ b :> R. Proof. by case: b; rewrite ?opprK. Qed. Lemma mulr_signM (b1 b2 : bool) x1 x2 : ((-1) ^+ b1 * x1) * ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 * x2). Proof. by rewrite signr_addb -!mulrA; congr (_ * _); rewrite !mulrA commr_sign. Qed. Lemma exprNn x n : (- x) ^+ n = (-1) ^+ n * x ^+ n :> R. Proof. by rewrite -mulN1r exprMn_comm // /comm mulN1r mulrN mulr1. Qed. Lemma sqrrN x : (- x) ^+ 2 = x ^+ 2. Proof. exact: mulrNN. Qed. Lemma sqrr_sign n : ((-1) ^+ n) ^+ 2 = 1 :> R. Proof. by rewrite exprAC sqrrN !expr1n. Qed. Lemma signrMK n : @involutive R ( *%R ((-1) ^+ n)). Proof. by move=> x; rewrite mulrA -expr2 sqrr_sign mul1r. Qed. Lemma mulrI0_lreg x : (forall y, x * y = 0 -> y = 0) -> lreg x. Proof. move=> reg_x y z eq_xy_xz; apply/eqP; rewrite -subr_eq0 [y - z]reg_x //. by rewrite mulrBr eq_xy_xz subrr. Qed. Lemma lregN x : lreg x -> lreg (- x). Proof. by move=> reg_x y z; rewrite !mulNr => /oppr_inj/reg_x. Qed. Lemma lreg_sign n : lreg ((-1) ^+ n : R). Proof. exact/lregX/lregN/lreg1. Qed. Lemma prodrN (I : finType) (A : pred I) (F : I -> R) : \prod_(i in A) - F i = (- 1) ^+ #|A| * \prod_(i in A) F i. Proof. rewrite -sum1_card; elim/big_rec3: _ => [|i x n _ _ ->]; first by rewrite mulr1. by rewrite exprS !mulrA mulN1r !mulNr commrX //; apply: commrN1. Qed. Lemma exprBn_comm x y n (cxy : comm x y) : (x - y) ^+ n = \sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. rewrite exprDn_comm; last exact: commrN. by apply: eq_bigr => i _; congr (_ *+ _); rewrite -commr_sign -mulrA -exprNn. Qed. Lemma subrXX_comm x y n (cxy : comm x y) : x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i). Proof. case: n => [|n]; first by rewrite big_ord0 mulr0 subrr. rewrite mulrBl !big_distrr big_ord_recl big_ord_recr /= subnn mulr1 mul1r. rewrite subn0 -!exprS opprD -!addrA; congr (_ + _); rewrite addrA -sumrB. rewrite big1 ?add0r // => i _; rewrite !mulrA -exprS -subSn ?(valP i) //. by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS subrr. Qed. Lemma subrX1 x n : x ^+ n - 1 = (x - 1) * (\sum_(i < n) x ^+ i). Proof. rewrite -!(opprB 1) mulNr -{1}(expr1n _ n). rewrite (subrXX_comm _ (commr_sym (commr1 x))); congr (- (_ * _)). by apply: eq_bigr => i _; rewrite expr1n mul1r. Qed. Lemma sqrrB1 x : (x - 1) ^+ 2 = x ^+ 2 - x *+ 2 + 1. Proof. by rewrite -sqrrN opprB addrC sqrrD1 sqrrN mulNrn. Qed. Lemma subr_sqr_1 x : x ^+ 2 - 1 = (x - 1) * (x + 1). Proof. by rewrite subrX1 !big_ord_recr big_ord0 /= addrAC add0r. Qed. Section ClosedPredicates. Variable S : {pred R}. Definition smulr_closed := -1 \in S /\ mulr_2closed S. Definition subring_closed := [/\ 1 \in S, subr_2closed S & mulr_2closed S]. Lemma smulr_closedM : smulr_closed -> mulr_closed S. Proof. by case=> SN1 SM; split=> //; rewrite -[1]mulr1 -mulrNN SM. Qed. Lemma smulr_closedN : smulr_closed -> oppr_closed S. Proof. by case=> SN1 SM x Sx; rewrite -mulN1r SM. Qed. Lemma subring_closedB : subring_closed -> zmod_closed S. Proof. by case=> S1 SB _; split; rewrite // -(subrr 1) SB. Qed. Lemma subring_closedM : subring_closed -> smulr_closed. Proof. by case=> S1 SB SM; split; rewrite ?(zmod_closedN (subring_closedB _)). Qed. Lemma subring_closed_semi : subring_closed -> semiring_closed S. Proof. by move=> ringS; split; [apply/zmod_closedD/subring_closedB | case: ringS]. Qed. End ClosedPredicates. End PzRingTheory. Section NzRingTheory. Variable R : nzRingType. Implicit Types x y : R. Lemma signr_eq0 n : ((-1) ^+ n == 0 :> R) = false. Proof. by rewrite -signr_odd; case: odd; rewrite ?oppr_eq0 oner_eq0. Qed. (* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible definition. *) Section FrobeniusAutomorphism. Variable p : nat. Hypothesis pcharFp : p \in pchar R. Hint Resolve pcharf_prime : core. Local Notation "x ^f" := (pFrobenius_aut pcharFp x). Lemma pFrobenius_autN x : (- x)^f = - x^f. Proof. apply/eqP; rewrite -subr_eq0 opprK addrC. by rewrite -(pFrobenius_autD_comm _ (commrN _)) // subrr pFrobenius_aut0. Qed. Lemma pFrobenius_autB_comm x y : comm x y -> (x - y)^f = x^f - y^f. Proof. by move/commrN/pFrobenius_autD_comm->; rewrite pFrobenius_autN. Qed. End FrobeniusAutomorphism. Lemma exprNn_pchar x n : (pchar R).-nat n -> (- x) ^+ n = - (x ^+ n). Proof. pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]]. have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) // pi_pdiv. have /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)). elim: e => // e IHe; rewrite expnSr !exprM {}IHe. by rewrite -pFrobenius_autE pFrobenius_autN. Qed. Section Char2. Hypothesis pcharR2 : 2 \in pchar R. Lemma oppr_pchar2 x : - x = x. Proof. by apply/esym/eqP; rewrite -addr_eq0 addrr_pchar2. Qed. Lemma subr_pchar2 x y : x - y = x + y. Proof. by rewrite oppr_pchar2. Qed. Lemma addrK_pchar2 x : involutive (+%R^~ x). Proof. by move=> y; rewrite /= -subr_pchar2 addrK. Qed. Lemma addKr_pchar2 x : involutive (+%R x). Proof. by move=> y; rewrite -{1}[x]oppr_pchar2 addKr. Qed. End Char2. End NzRingTheory. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")] Notation Frobenius_autN := pFrobenius_autN (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")] Notation Frobenius_autB_comm := pFrobenius_autB_comm (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")] Notation exprNn_char := exprNn_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")] Notation oppr_char2 := oppr_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use subr_pchar2 instead.")] Notation subr_char2 := subr_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")] Notation addrK_char2 := addrK_pchar2 (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")] Notation addKr_char2 := addKr_pchar2 (only parsing). Section ConverseRing. #[export] HB.instance Definition _ (T : eqType) := Equality.on T^c. #[export] HB.instance Definition _ (T : choiceType) := Choice.on T^c. #[export] HB.instance Definition _ (U : nmodType) := Nmodule.on U^c. #[export] HB.instance Definition _ (U : zmodType) := Zmodule.on U^c. #[export] HB.instance Definition _ (R : pzSemiRingType) := let mul' (x y : R) := y * x in let mulrA' x y z := esym (mulrA z y x) in let mulrDl' x y z := mulrDr z x y in let mulrDr' x y z := mulrDl y z x in Nmodule_isPzSemiRing.Build R^c mulrA' mulr1 mul1r mulrDl' mulrDr' mulr0 mul0r. #[export] HB.instance Definition _ (R : pzRingType) := PzSemiRing.on R^c. #[export] HB.instance Definition _ (R : nzSemiRingType) := PzSemiRing_isNonZero.Build R^c oner_neq0. #[export] HB.instance Definition _ (R : nzRingType) := NzSemiRing.on R^c. End ConverseRing. Lemma rev_prodr (R : pzSemiRingType) (I : Type) (r : seq I) (P : pred I) (E : I -> R) : \prod_(i <- r | P i) (E i : R^c) = \prod_(i <- rev r | P i) E i. Proof. by rewrite rev_big_rev. Qed. Section SemiRightRegular. Variable R : pzSemiRingType. Implicit Types x y : R. Lemma mulIr_eq0 x y : rreg x -> (y * x == 0) = (y == 0). Proof. exact: (@mulrI_eq0 R^c). Qed. Lemma rreg1 : rreg (1 : R). Proof. exact: (@lreg1 R^c). Qed. Lemma rregM x y : rreg x -> rreg y -> rreg (x * y). Proof. by move=> reg_x reg_y; apply: (@lregM R^c). Qed. Lemma revrX x n : (x : R^c) ^+ n = (x : R) ^+ n. Proof. by elim: n => // n IHn; rewrite exprS exprSr IHn. Qed. Lemma rregX x n : rreg x -> rreg (x ^+ n). Proof. by move/(@lregX R^c x n); rewrite revrX. Qed. End SemiRightRegular. Lemma rreg_neq0 (R : nzSemiRingType) (x : R) : rreg x -> x != 0. Proof. exact: (@lreg_neq0 R^c). Qed. Section RightRegular. Variable R : pzRingType. Implicit Types x y : R. Lemma mulIr0_rreg x : (forall y, y * x = 0 -> y = 0) -> rreg x. Proof. exact: (@mulrI0_lreg R^c). Qed. Lemma rregN x : rreg x -> rreg (- x). Proof. exact: (@lregN R^c). Qed. End RightRegular. HB.mixin Record Nmodule_isLSemiModule (R : pzSemiRingType) V of Nmodule V := { scale : R -> V -> V; scalerA : forall a b v, scale a (scale b v) = scale (a * b) v; scale0r : forall v, scale 0 v = 0; scale1r : left_id 1 scale; scalerDr : right_distributive scale +%R; scalerDl : forall v, {morph scale^~ v: a b / a + b} }. #[short(type="lSemiModType")] HB.structure Definition LSemiModule (R : pzSemiRingType) := {M of Nmodule M & Nmodule_isLSemiModule R M}. Module LSemiModExports. Bind Scope ring_scope with LSemiModule.sort. End LSemiModExports. HB.export LSemiModExports. Local Notation "*:%R" := (@scale _ _) : function_scope. Local Notation "a *: v" := (scale a v) : ring_scope. #[short(type="lmodType")] HB.structure Definition Lmodule (R : pzRingType) := {M of Zmodule M & Nmodule_isLSemiModule R M}. (* FIXME: see #1126 and #1127 *) Arguments scalerA [R s] (a b)%_ring_scope v. Module LmodExports. Bind Scope ring_scope with Lmodule.sort. End LmodExports. HB.export LmodExports. HB.factory Record Zmodule_isLmodule (R : pzRingType) V of Zmodule V := { scale : R -> V -> V; scalerA : forall a b v, scale a (scale b v) = scale (a * b) v; scale1r : left_id 1 scale; scalerDr : right_distributive scale +%R; scalerDl : forall v, {morph scale^~ v: a b / a + b} }. HB.builders Context R V of Zmodule_isLmodule R V. Lemma scale0r v : scale 0 v = 0. Proof. by apply: (addIr (scale 1 v)); rewrite -scalerDl !add0r. Qed. HB.instance Definition _ := Nmodule_isLSemiModule.Build R V scalerA scale0r scale1r scalerDr scalerDl. HB.end. HB.factory Record LSemiModule_isLmodule (R : pzRingType) V of LSemiModule R V := {}. HB.builders Context R V of LSemiModule_isLmodule R V. Definition opp : V -> V := scale (- 1). Lemma addNr : left_inverse 0 opp +%R. Proof. move=> v; suff : scale (-1 + 1) v = 0 by rewrite scalerDl scale1r. by rewrite addNr scale0r. Qed. HB.instance Definition _ := Nmodule_isZmodule.Build V addNr. HB.end. Section LSemiModuleTheory. Variables (R : pzSemiRingType) (V : lSemiModType R). Implicit Types (a b c : R) (u v : V). Lemma scaler0 a : a *: 0 = 0 :> V. Proof. by rewrite -[0 in LHS](scale0r 0) scalerA mulr0 scale0r. Qed. Lemma scaler_nat n v : n%:R *: v = v *+ n. Proof. elim: n => /= [|n]; first by rewrite scale0r. by rewrite !mulrS scalerDl ?scale1r => ->. Qed. Lemma scalerMnl a v n : a *: v *+ n = (a *+ n) *: v. Proof. elim: n => [|n IHn]; first by rewrite !mulr0n scale0r. by rewrite !mulrSr IHn scalerDl. Qed. Lemma scalerMnr a v n : a *: v *+ n = a *: (v *+ n). Proof. elim: n => [|n IHn]; first by rewrite !mulr0n scaler0. by rewrite !mulrSr IHn scalerDr. Qed. Lemma scaler_suml v I r (P : pred I) F : (\sum_(i <- r | P i) F i) *: v = \sum_(i <- r | P i) F i *: v. Proof. exact: (big_morph _ (scalerDl v) (scale0r v)). Qed. Lemma scaler_sumr a I r (P : pred I) (F : I -> V) : a *: (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) a *: F i. Proof. exact: big_endo (scalerDr a) (scaler0 a) I r P F. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition scaler_closed := forall a, {in S, forall v, a *: v \in S}. Definition subsemimod_closed := nmod_closed S /\ scaler_closed. Lemma subsemimod_closedD : subsemimod_closed -> nmod_closed S. Proof. by case. Qed. Lemma subsemimod_closedZ : subsemimod_closed -> scaler_closed. Proof. by case. Qed. End ClosedPredicates. End LSemiModuleTheory. Section LmoduleTheory. Variables (R : pzRingType) (V : lmodType R). Implicit Types (a b c : R) (u v : V). Lemma scaleNr a v : - a *: v = - (a *: v). Proof. by apply: (addIr (a *: v)); rewrite -scalerDl !addNr scale0r. Qed. Lemma scaleN1r v : - 1 *: v = - v. Proof. by rewrite scaleNr scale1r. Qed. Lemma scalerN a v : a *: - v = - (a *: v). Proof. by apply: (addIr (a *: v)); rewrite -scalerDr !addNr scaler0. Qed. Lemma scalerBl a b v : (a - b) *: v = a *: v - b *: v. Proof. by rewrite scalerDl scaleNr. Qed. Lemma scalerBr a u v : a *: (u - v) = a *: u - a *: v. Proof. by rewrite scalerDr scalerN. Qed. Lemma scaler_sign (b : bool) v : (-1) ^+ b *: v = (if b then - v else v). Proof. by case: b; rewrite ?scaleNr scale1r. Qed. Lemma signrZK n : @involutive V ( *:%R ((-1) ^+ n)). Proof. by move=> u; rewrite scalerA -expr2 sqrr_sign scale1r. Qed. Section ClosedPredicates. Variable S : {pred V}. Definition linear_closed := forall a, {in S &, forall u v, a *: u + v \in S}. Definition submod_closed := 0 \in S /\ linear_closed. Lemma linear_closedB : linear_closed -> subr_2closed S. Proof. by move=> Slin u v Su Sv; rewrite addrC -scaleN1r Slin. Qed. Lemma submod_closedB : submod_closed -> zmod_closed S. Proof. by case=> S0 /linear_closedB. Qed. Lemma submod_closed_semi : submod_closed -> subsemimod_closed S. Proof. move=> /[dup] /submod_closedB /zmod_closedD SD [S0 Slin]; split => // a v Sv. by rewrite -[a *: v]addr0 Slin. Qed. End ClosedPredicates. End LmoduleTheory. (* TOTHINK: Can I change `NzSemiRing` to `PzSemiRing`? *) HB.mixin Record LSemiModule_isLSemiAlgebra R V of NzSemiRing V & LSemiModule R V := { scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v }. #[short(type="lSemiAlgType")] HB.structure Definition LSemiAlgebra R := {A of LSemiModule R A & NzSemiRing A & LSemiModule_isLSemiAlgebra R A}. Module LSemiAlgExports. Bind Scope ring_scope with LSemiAlgebra.sort. End LSemiAlgExports. HB.export LSemiAlgExports. (* Scalar injection (see the definition of in_alg A below). *) Local Notation "k %:A" := (k *: 1) : ring_scope. #[short(type="lalgType")] HB.structure Definition Lalgebra R := {A of Lmodule R A & NzRing A & LSemiModule_isLSemiAlgebra R A}. Module LalgExports. Bind Scope ring_scope with Lalgebra.sort. End LalgExports. HB.export LalgExports. HB.factory Record Lmodule_isLalgebra R V of NzRing V & Lmodule R V := { scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v }. HB.builders Context R V of Lmodule_isLalgebra R V. HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R V scalerAl. HB.end. (* Regular ring algebra tag. *) Definition regular R : Type := R. Local Notation "R ^o" := (regular R) : type_scope. Section RegularAlgebra. #[export] HB.instance Definition _ (V : nmodType) := Nmodule.on V^o. #[export] HB.instance Definition _ (V : zmodType) := Zmodule.on V^o. #[export] HB.instance Definition _ (R : pzSemiRingType) := PzSemiRing.on R^o. #[export] HB.instance Definition _ (R : nzSemiRingType) := NzSemiRing.on R^o. #[export] HB.instance Definition _ (R : pzSemiRingType) := @Nmodule_isLSemiModule.Build R R^o mul mulrA mul0r mul1r mulrDr (fun v a b => mulrDl a b v). #[export] HB.instance Definition _ (R : nzSemiRingType) := LSemiModule_isLSemiAlgebra.Build R R^o mulrA. #[export] HB.instance Definition _ (R : pzRingType) := PzRing.on R^o. #[export] HB.instance Definition _ (R : nzRingType) := NzRing.on R^o. End RegularAlgebra. Section LSemiAlgebraTheory. Variables (R : pzSemiRingType) (A : lSemiAlgType R). Lemma mulr_algl (a : R) (x : A) : (a *: 1) * x = a *: x. Proof. by rewrite -scalerAl mul1r. Qed. End LSemiAlgebraTheory. Section LalgebraTheory. Variables (R : pzRingType) (A : lalgType R). Section ClosedPredicates. Variable S : {pred A}. Definition subalg_closed := [/\ 1 \in S, linear_closed S & mulr_2closed S]. Lemma subalg_closedZ : subalg_closed -> submod_closed S. Proof. by case=> S1 Slin _; split; rewrite // -(subrr 1) linear_closedB. Qed. Lemma subalg_closedBM : subalg_closed -> subring_closed S. Proof. by case=> S1 Slin SM; split=> //; apply: linear_closedB. Qed. End ClosedPredicates. End LalgebraTheory. (* Morphism hierarchy. *) (* Lifted multiplication. *) Section LiftedSemiRing. Variables (R : pzSemiRingType) (T : Type). Implicit Type f : T -> R. Definition mull_fun a f x := a * f x. Definition mulr_fun a f x := f x * a. Definition mul_fun f g x := f x * g x. End LiftedSemiRing. (* Lifted linear operations. *) Section LiftedScale. Variables (R : pzSemiRingType) (U : Type). Variables (V : lSemiModType R) (A : lSemiAlgType R). Definition scale_fun a (f : U -> V) x := a *: f x. Definition in_alg k : A := k%:A. End LiftedScale. Local Notation "\0" := (null_fun _) : function_scope. Local Notation "f \+ g" := (add_fun f g) : function_scope. Local Notation "f \- g" := (sub_fun f g) : function_scope. Local Notation "\- f" := (opp_fun f) : function_scope. Local Notation "a \*: f" := (scale_fun a f) : function_scope. Local Notation "x \*o f" := (mull_fun x f) : function_scope. Local Notation "x \o* f" := (mulr_fun x f) : function_scope. Local Notation "f \* g" := (mul_fun f g) : function_scope. Arguments in_alg {_} A _ /. Arguments mull_fun {_ _} a f _ /. Arguments mulr_fun {_ _} a f _ /. Arguments scale_fun {_ _ _} a f _ /. Arguments mul_fun {_ _} f g _ /. Section AdditiveTheory. Section SemiRingProperties. Variables (R S : pzSemiRingType) (f : {additive R -> S}). Lemma raddfMnat n x : f (n%:R * x) = n%:R * f x. Proof. by rewrite !mulr_natl raddfMn. Qed. Variables (U : lSemiModType R) (V : lSemiModType S) (h : {additive U -> V}). Lemma raddfZnat n u : h (n%:R *: u) = n%:R *: h u. Proof. by rewrite !scaler_nat raddfMn. Qed. End SemiRingProperties. Section MulFun. Variables (R : pzSemiRingType) (U : nmodType) (a : R) (f : {additive U -> R}). Fact mull_fun_is_nmod_morphism : nmod_morphism (a \*o f). Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mulr0// raddfD mulrDr. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build U R (a \*o f) mull_fun_is_nmod_morphism. Fact mulr_fun_is_nmod_morphism : nmod_morphism (a \o* f). Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mul0r// raddfD mulrDl. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build U R (a \o* f) mulr_fun_is_nmod_morphism. End MulFun. Section Properties. Variables (U V : zmodType) (f : {additive U -> V}). Lemma raddfN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma raddfB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed. Lemma raddf_inj : (forall x, f x = 0 -> x = 0) -> injective f. Proof. exact: raddf_inj. Qed. Lemma raddfMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. End Properties. Section RingProperties. Variables (R S : pzRingType) (f : {additive R -> S}). Lemma raddfMsign n x : f ((-1) ^+ n * x) = (-1) ^+ n * f x. Proof. by rewrite !(mulr_sign, =^~ signr_odd) (fun_if f) raddfN. Qed. Variables (U : lmodType R) (V : lmodType S) (h : {additive U -> V}). Lemma raddfZsign n u : h ((-1) ^+ n *: u) = (-1) ^+ n *: h u. Proof. by rewrite !(scaler_sign, =^~ signr_odd) (fun_if h) raddfN. Qed. End RingProperties. Section ScaleFun. Variables (R : pzSemiRingType) (U : nmodType) (V : lSemiModType R). Variables (a : R) (f : {additive U -> V}). #[export] HB.instance Definition _ := isNmodMorphism.Build V V ( *:%R a) (conj (scaler0 _ a) (scalerDr a)). #[export] HB.instance Definition _ := Additive.copy (a \*: f) (f \; *:%R a). End ScaleFun. End AdditiveTheory. #[deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")] Definition multiplicative (R S : pzSemiRingType) (f : R -> S) : Prop := {morph f : x y / x * y}%R * (f 1 = 1). (* FIXME: remove once PzSemiRing extends Monoid. *) Definition monoid_morphism (R S : pzSemiRingType) (f : R -> S) : Prop := (f 1 = 1) * {morph f : x y / x * y}%R. HB.mixin Record isMonoidMorphism (R S : pzSemiRingType) (f : R -> S) := { monoid_morphism_subproof : monoid_morphism f }. HB.structure Definition RMorphism (R S : pzSemiRingType) := {f of @isNmodMorphism R S f & isMonoidMorphism R S f}. (* FIXME: remove the @ once https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *) #[warning="-deprecated-since-mathcomp-2.5.0"] HB.factory Record isMultiplicative (R S : pzSemiRingType) (f : R -> S) := { rmorphism_subproof : multiplicative f }. HB.builders Context R S f of isMultiplicative R S f. #[warning="-HB.no-new-instance"] HB.instance Definition _ := isMonoidMorphism.Build R S f (rmorphism_subproof.2, rmorphism_subproof.1). HB.end. Module RMorphismExports. Notation "{ 'rmorphism' U -> V }" := (RMorphism.type U%type V%type) : type_scope. End RMorphismExports. HB.export RMorphismExports. Section RmorphismTheory. Section Properties. Variables (R S : pzSemiRingType) (f : {rmorphism R -> S}). Lemma rmorph0 : f 0 = 0. Proof. exact: raddf0. Qed. Lemma rmorphD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed. Lemma rmorphMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma rmorph_sum I r (P : pred I) E : f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i). Proof. exact: raddf_sum. Qed. Lemma rmorphism_monoidP : monoid_morphism f. Proof. exact: monoid_morphism_subproof. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `rmorphism_monoidP` instead")] Definition rmorphismMP : multiplicative f := (fun p => (p.2, p.1)) rmorphism_monoidP. Lemma rmorph1 : f 1 = 1. Proof. by case: rmorphism_monoidP. Qed. Lemma rmorphM : {morph f: x y / x * y}. Proof. by case: rmorphism_monoidP. Qed. Lemma rmorph_prod I r (P : pred I) E : f (\prod_(i <- r | P i) E i) = \prod_(i <- r | P i) f (E i). Proof. exact: (big_morph f rmorphM rmorph1). Qed. Lemma rmorphXn n : {morph f : x / x ^+ n}. Proof. by elim: n => [|n IHn] x; rewrite ?rmorph1 // !exprS rmorphM IHn. Qed. Lemma rmorph_nat n : f n%:R = n%:R. Proof. by rewrite rmorphMn rmorph1. Qed. Lemma rmorph_eq_nat x n : injective f -> (f x == n%:R) = (x == n%:R). Proof. by move/inj_eq <-; rewrite rmorph_nat. Qed. Lemma rmorph_eq1 x : injective f -> (f x == 1) = (x == 1). Proof. exact: rmorph_eq_nat 1%N. Qed. Lemma can2_monoid_morphism f' : cancel f f' -> cancel f' f -> monoid_morphism f'. Proof. move=> fK f'K. by split=> [|x y]; apply: (canLR fK); rewrite /= (rmorph1, rmorphM) ?f'K. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `can2_monoid_morphism` instead")] Definition can2_rmorphism f' (cff' : cancel f f') := (fun p => (p.2, p.1)) \o (can2_monoid_morphism cff'). End Properties. Lemma rmorph_pchar (R S : nzSemiRingType) (f : {rmorphism R -> S}) p : p \in pchar R -> p \in pchar S. Proof. by rewrite !inE -(rmorph_nat f) => /andP[-> /= /eqP->]; rewrite rmorph0. Qed. Section Projections. Variables (R S T : pzSemiRingType). Variables (f : {rmorphism S -> T}) (g : {rmorphism R -> S}). Fact idfun_is_monoid_morphism : monoid_morphism (@idfun R). Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R R idfun idfun_is_monoid_morphism. Fact comp_is_monoid_morphism : monoid_morphism (f \o g). Proof. by split=> [|x y] /=; rewrite ?rmorph1 ?rmorphM. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R T (f \o g) comp_is_monoid_morphism. End Projections. Section Properties. Variables (R S : pzRingType) (f : {rmorphism R -> S}). Lemma rmorphN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma rmorphB : {morph f: x y / x - y}. Proof. exact: raddfB. Qed. Lemma rmorphMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. Lemma rmorphMsign n : {morph f : x / (- 1) ^+ n * x}. Proof. exact: raddfMsign. Qed. Lemma rmorphN1 : f (- 1) = (- 1). Proof. by rewrite rmorphN rmorph1. Qed. Lemma rmorph_sign n : f ((- 1) ^+ n) = (- 1) ^+ n. Proof. by rewrite rmorphXn /= rmorphN1. Qed. End Properties. Section InSemiAlgebra. Variables (R : pzSemiRingType) (A : lSemiAlgType R). Fact in_alg_is_nmod_morphism : nmod_morphism (in_alg A). Proof. by split; [exact: scale0r | exact: scalerDl]. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build R A (in_alg A) in_alg_is_nmod_morphism. Fact in_alg_is_monoid_morphism : monoid_morphism (in_alg A). Proof. by split=> [|x y]; rewrite /= ?scale1r // mulr_algl scalerA. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build R A (in_alg A) in_alg_is_monoid_morphism. Lemma in_algE a : in_alg A a = a%:A. Proof. by []. Qed. End InSemiAlgebra. End RmorphismTheory. #[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")] Notation rmorph_char := rmorph_pchar (only parsing). Module Scale. HB.mixin Record isPreLaw (R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := { op_nmod_morphism : forall a, nmod_morphism (op a); }. #[export] HB.structure Definition PreLaw R V := {op of isPreLaw R V op}. Definition preLaw := PreLaw.type. HB.mixin Record isSemiLaw (R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := { op0v : forall v, op 0 v = 0; op1v : op 1 =1 id; opA : forall a b v, op a (op b v) = op (a * b) v; }. #[export] HB.structure Definition SemiLaw R V := {op of isPreLaw R V op & isSemiLaw R V op}. Definition semiLaw := SemiLaw.type. HB.mixin Record isLaw (R : pzRingType) (V : zmodType) (op : R -> V -> V) := { N1op : op (-1) =1 -%R }. #[export] HB.structure Definition Law (R : pzRingType) (V : zmodType) := {op of isPreLaw R V op & isLaw R V op}. Definition law := Law.type. Section CompSemiLaw. Context (R : pzSemiRingType) (V : nmodType) (s : semiLaw R V). Context (aR : pzSemiRingType) (nu : {rmorphism aR -> R}). Fact comp_op0v v : (nu \; s) 0 v = 0. Proof. by rewrite /= rmorph0 op0v. Qed. Fact comp_op1v : (nu \; s) 1 =1 id. Proof. by move=> v; rewrite /= rmorph1 op1v. Qed. Fact comp_opA a b v : (nu \; s) a ((nu \; s) b v) = (nu \; s) (a * b) v. Proof. by rewrite /= opA rmorphM. Qed. End CompSemiLaw. Fact compN1op (R : pzRingType) (V : zmodType) (s : law R V) (aR : pzRingType) (nu : {rmorphism aR -> R}) : (nu \; s) (-1) =1 -%R. Proof. by move=> v; rewrite /= rmorphN1 N1op. Qed. Module Exports. HB.reexport. End Exports. End Scale. Export Scale.Exports. #[export] HB.instance Definition _ (R : pzSemiRingType) := Scale.isPreLaw.Build R R *%R (fun => mull_fun_is_nmod_morphism _ idfun). #[export] HB.instance Definition _ (R : pzSemiRingType) := Scale.isSemiLaw.Build R R *%R mul0r mul1r mulrA. #[export] HB.instance Definition _ (R : pzRingType) := Scale.isLaw.Build R R *%R (@mulN1r R). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) := Scale.isPreLaw.Build R V *:%R (fun => (scaler0 _ _, scalerDr _)). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) := Scale.isSemiLaw.Build R V *:%R scale0r scale1r (@scalerA _ _). #[export] HB.instance Definition _ (R : pzRingType) (U : lmodType R) := Scale.isLaw.Build R U *:%R (@scaleN1r R U). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V) (aR : pzSemiRingType) (nu : {rmorphism aR -> R}) := Scale.isPreLaw.Build aR V (nu \; s) (fun => Scale.op_nmod_morphism _). #[export] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.semiLaw R V) (aR : pzSemiRingType) (nu : {rmorphism aR -> R}) := Scale.isSemiLaw.Build aR V (nu \; s) (Scale.comp_op0v s nu) (Scale.comp_op1v s nu) (Scale.comp_opA s nu). #[export] HB.instance Definition _ (R : pzRingType) (V : zmodType) (s : Scale.law R V) (aR : pzRingType) (nu : {rmorphism aR -> R}) := Scale.isLaw.Build aR V (nu \; s) (Scale.compN1op s nu). #[export, non_forgetful_inheritance] HB.instance Definition _ (R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V) a := isNmodMorphism.Build V V (s a) (Scale.op_nmod_morphism a). Definition scalable_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := forall a, {morph f : u / a *: u >-> s a u}. HB.mixin Record isScalable (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := { semi_linear_subproof : scalable_for s f; }. HB.structure Definition Linear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) := {f of @isNmodMorphism U V f & isScalable R U V s f}. Definition semilinear_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) : Type := scalable_for s f * {morph f : x y / x + y}. Lemma nmod_morphism_semilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) : semilinear_for s f -> nmod_morphism f. Proof. by case=> sf Df; split => //; rewrite -[0 in LHS](scale0r 0) sf Scale.op0v. Qed. Definition additive_semilinear := nmod_morphism_semilinear. Lemma scalable_semilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.preLaw R V) (f : U -> V) : semilinear_for s f -> scalable_for s f. Proof. by case. Qed. HB.factory Record isSemilinear (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) := { linear_subproof : semilinear_for s f; }. HB.builders Context R U V s f of isSemilinear R U V s f. HB.instance Definition _ := isNmodMorphism.Build U V f (additive_semilinear linear_subproof). HB.instance Definition _ := isScalable.Build R U V s f (scalable_semilinear linear_subproof). HB.end. Definition linear_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) := forall a, {morph f : u v / a *: u + v >-> s a u + v}. Lemma zmod_morphism_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> zmod_morphism f. Proof. by move=> Lsf x y; rewrite -scaleN1r addrC Lsf Scale.N1op addrC. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism_linear` instead")] Definition additive_linear := zmod_morphism_linear. Lemma scalable_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> scalable_for s f. Proof. by move=> Lsf a v; rewrite -[a *:v](addrK v) (zmod_morphism_linear Lsf) Lsf addrK. Qed. Lemma semilinear_linear (R : pzRingType) (U : lmodType R) V (s : Scale.law R V) (f : U -> V) : linear_for s f -> semilinear_for s f. Proof. move=> Lsf; split=> [a x|x y]; first exact: (scalable_linear Lsf). have f0: f 0 = 0 by rewrite -[0 in LHS]subr0 (zmod_morphism_linear Lsf) subrr. by rewrite -[y in LHS]opprK -[- y]add0r !(zmod_morphism_linear Lsf) f0 sub0r opprK. Qed. HB.factory Record isLinear (R : pzRingType) (U : lmodType R) (V : zmodType) (s : Scale.law R V) (f : U -> V) := { linear_subproof : linear_for s f; }. HB.builders Context R U V s f of isLinear R U V s f. HB.instance Definition _ := isZmodMorphism.Build U V f (zmod_morphism_linear linear_subproof). HB.instance Definition _ := isScalable.Build R U V s f (scalable_linear linear_subproof). HB.end. Module LinearExports. Notation scalable f := (scalable_for *:%R f). Notation semilinear f := (semilinear_for *:%R f). Notation semiscalar f := (semilinear_for *%R f). Notation linear f := (linear_for *:%R f). Notation scalar f := (linear_for *%R f). Module Linear. Section Linear. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V). (* Support for right-to-left rewriting with the generic linearZ rule. *) Local Notation mapUV := (@Linear.type R U V s). Definition map_class := mapUV. Definition map_at (a : R) := mapUV. Structure map_for a s_a := MapFor {map_for_map : mapUV; _ : s a = s_a}. Definition unify_map_at a (g : map_at a) := MapFor g (erefl (s a)). Structure wrapped := Wrap {unwrap : mapUV}. Definition wrap (f : map_class) := Wrap f. End Linear. End Linear. Notation "{ 'linear' U -> V | s }" := (@Linear.type _ U V s) : type_scope. Notation "{ 'linear' U -> V }" := {linear U -> V | *:%R} : type_scope. Notation "{ 'scalar' U }" := {linear U -> _ | *%R} (format "{ 'scalar' U }") : type_scope. (* Support for right-to-left rewriting with the generic linearZ rule. *) Coercion Linear.map_for_map : Linear.map_for >-> Linear.type. Coercion Linear.unify_map_at : Linear.map_at >-> Linear.map_for. Canonical Linear.unify_map_at. Coercion Linear.unwrap : Linear.wrapped >-> Linear.type. Coercion Linear.wrap : Linear.map_class >-> Linear.wrapped. Canonical Linear.wrap. End LinearExports. HB.export LinearExports. Section LinearTheory. Section GenericProperties. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V) (f : {linear U -> V | s}). Lemma linear0 : f 0 = 0. Proof. exact: raddf0. Qed. Lemma linearD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed. Lemma linearMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed. Lemma linear_sum I r (P : pred I) E : f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i). Proof. exact: raddf_sum. Qed. Lemma linearZ_LR : scalable_for s f. Proof. exact: semi_linear_subproof. Qed. Lemma semilinearP : semilinear_for s f. Proof. split; [exact: linearZ_LR | exact: linearD]. Qed. Lemma linearP : linear_for s f. Proof. by move=> a u v /=; rewrite !semilinearP. Qed. End GenericProperties. Section GenericProperties. Variables (R : pzRingType) (U : lmodType R) (V : zmodType) (s : R -> V -> V). Variables (f : {linear U -> V | s}). Lemma linearN : {morph f : x / - x}. Proof. exact: raddfN. Qed. Lemma linearB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed. Lemma linearMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed. End GenericProperties. Section BidirectionalLinearZ. (* The general form of the linearZ lemma uses some bespoke interfaces to *) (* allow right-to-left rewriting when a composite scaling operation such as *) (* conjC \; *%R has been expanded, say in a^* * f u. This redex is matched *) (* by using the Scale.law interface to recognize a "head" scaling operation *) (* h (here *%R), stow away its "scalar" c, then reconcile h c and s a, once *) (* s is known, that is, once the Linear.map structure for f has been found. *) (* In general, s and a need not be equal to h and c; indeed they need not *) (* have the same type! The unification is performed by the unify_map_at *) (* default instance for the Linear.map_for U s a h_c sub-interface of *) (* Linear.map; the h_c pattern uses the Scale.law structure to insure it is *) (* inferred when rewriting right-to-left. *) (* The wrap on the rhs allows rewriting f (a *: b *: u) into a *: b *: f u *) (* with rewrite !linearZ /= instead of rewrite linearZ /= linearZ /=. *) (* Without it, the first rewrite linearZ would produce *) (* (a *: apply (map_for_map (@check_map_at .. a f)) (b *: u)%R)%Rlin *) (* and matching the second rewrite LHS would bypass the unify_map_at default *) (* instance for b, reuse the one for a, and subsequently fail to match the *) (* b *: u argument. The extra wrap / unwrap ensures that this can't happen. *) (* In the RL direction, the wrap / unwrap will be inserted on the redex side *) (* as needed, without causing unnecessary delta-expansion: using an explicit *) (* identity function would have Coq normalize the redex to head normal, then *) (* reduce the identity to expose the map_for_map projection, and the *) (* expanded Linear.map structure would then be exposed in the result. *) (* Most of this machinery will be invisible to a casual user, because all *) (* the projections and default instances involved are declared as coercions. *) Lemma linearZ (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (S : pzSemiRingType) (h : Scale.preLaw S V) (c : S) (a : R) (h_c := h c) (f : Linear.map_for U s a h_c) (u : U) : f (a *: u) = h_c (Linear.wrap f u). Proof. by rewrite linearZ_LR; case: f => f /= ->. Qed. End BidirectionalLinearZ. Section LmodProperties. Variables (R : pzSemiRingType) (U V : lSemiModType R) (f : {linear U -> V}). Lemma linearZZ : scalable f. Proof. exact: linearZ_LR. Qed. Lemma semilinearPZ : semilinear f. Proof. exact: semilinearP. Qed. Lemma linearPZ : linear f. Proof. exact: linearP. Qed. Lemma can2_scalable f' : cancel f f' -> cancel f' f -> scalable f'. Proof. by move=> fK f'K a x; apply: (canLR fK); rewrite linearZZ f'K. Qed. Lemma can2_semilinear f' : cancel f f' -> cancel f' f -> semilinear f'. Proof. by move=> fK f'K; split=> ? ?; apply: (canLR fK); rewrite semilinearPZ !f'K. Qed. Lemma can2_linear f' : cancel f f' -> cancel f' f -> linear f'. Proof. by move=> fK f'K a x y /=; apply: (canLR fK); rewrite linearP !f'K. Qed. End LmodProperties. Section ScalarProperties. Variable (R : pzSemiRingType) (U : lSemiModType R) (f : {scalar U}). Lemma scalarZ : scalable_for *%R f. Proof. exact: linearZ_LR. Qed. Lemma semiscalarP : semiscalar f. Proof. exact: semilinearP. Qed. Lemma scalarP : scalar f. Proof. exact: linearP. Qed. End ScalarProperties. Section LinearLSemiMod. Section Idfun. Variables (R : pzSemiRingType) (U : lSemiModType R). Lemma idfun_is_scalable : scalable (@idfun U). Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R U U *:%R idfun idfun_is_scalable. End Idfun. Section Plain. Variables (R : pzSemiRingType) (W U : lSemiModType R) (V : nmodType). Variables (s : R -> V -> V) (f : {linear U -> V | s}) (g : {linear W -> U}). Lemma comp_is_scalable : scalable_for s (f \o g). Proof. by move=> a v /=; rewrite !linearZ_LR. Qed. #[export] HB.instance Definition _ := isScalable.Build R W V s (f \o g) comp_is_scalable. End Plain. Section SemiScale. Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType). Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}). Lemma null_fun_is_scalable : scalable_for s (\0 : U -> V). Proof. by move=> a v /=; rewrite raddf0. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s \0 null_fun_is_scalable. Lemma add_fun_is_scalable : scalable_for s (add_fun f g). Proof. by move=> a u; rewrite /= !linearZ_LR raddfD. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (f \+ g) add_fun_is_scalable. End SemiScale. End LinearLSemiMod. Section LinearLmod. Variables (R : pzRingType) (U : lmodType R). Lemma opp_is_scalable : scalable (-%R : U -> U). Proof. by move=> a v /=; rewrite scalerN. Qed. #[export] HB.instance Definition _ := isScalable.Build R U U *:%R -%R opp_is_scalable. End LinearLmod. Section Scale. Variables (R : pzRingType) (U : lmodType R) (V : zmodType). Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}). Lemma sub_fun_is_scalable : scalable_for s (f \- g). Proof. by move=> a u; rewrite /= !linearZ_LR raddfB. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (f \- g) sub_fun_is_scalable. Lemma opp_fun_is_scalable : scalable_for s (\- f). Proof. by move=> a u; rewrite /= linearZ_LR raddfN. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V s (\- f) opp_fun_is_scalable. End Scale. Section LinearLSemiAlg. Variables (R : pzSemiRingType) (A : lSemiAlgType R) (U : lSemiModType R). Variables (a : A) (f : {linear U -> A}). Fact mulr_fun_is_scalable : scalable (a \o* f). Proof. by move=> k x /=; rewrite linearZ scalerAl. Qed. #[export] HB.instance Definition _ := isScalable.Build R U A *:%R (a \o* f) mulr_fun_is_scalable. End LinearLSemiAlg. End LinearTheory. HB.structure Definition LRMorphism (R : pzSemiRingType) (A : lSemiAlgType R) (B : pzSemiRingType) (s : R -> B -> B) := {f of @RMorphism A B f & isScalable R A B s f}. (* FIXME: remove the @ once https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *) Module LRMorphismExports. Notation "{ 'lrmorphism' A -> B | s }" := (@LRMorphism.type _ A%type B%type s) : type_scope. Notation "{ 'lrmorphism' A -> B }" := {lrmorphism A%type -> B%type | *:%R} : type_scope. End LRMorphismExports. HB.export LRMorphismExports. Section LRMorphismTheory. Variables (R : pzSemiRingType) (A B : lSemiAlgType R) (C : pzSemiRingType). Variables (s : R -> C -> C). Variables (f : {lrmorphism A -> B}) (g : {lrmorphism B -> C | s}). #[export] HB.instance Definition _ := RMorphism.on (@idfun A). #[export] HB.instance Definition _ := RMorphism.on (g \o f). Lemma rmorph_alg a : f a%:A = a%:A. Proof. by rewrite linearZ /= rmorph1. Qed. End LRMorphismTheory. HB.mixin Record PzSemiRing_hasCommutativeMul R of PzSemiRing R := { mulrC : commutative (@mul R) }. Module SemiRing_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzSemiRing_hasCommutativeMul.Build instead.")] Notation Build R := (PzSemiRing_hasCommutativeMul.Build R) (only parsing). End SemiRing_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzSemiRing_hasCommutativeMul instead.")] Notation SemiRing_hasCommutativeMul R := (PzSemiRing_hasCommutativeMul R) (only parsing). #[short(type="comPzSemiRingType")] HB.structure Definition ComPzSemiRing := {R of PzSemiRing R & PzSemiRing_hasCommutativeMul R}. Module ComPzSemiRingExports. Bind Scope ring_scope with ComPzSemiRing.sort. End ComPzSemiRingExports. HB.export ComPzSemiRingExports. HB.factory Record Nmodule_isComPzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; mul0r : left_zero zero mul; }. HB.builders Context R of Nmodule_isComPzSemiRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. Lemma mulr0 : right_zero zero mul. Proof. by move=> x; rewrite mulrC mul0r. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. #[short(type="comNzSemiRingType")] HB.structure Definition ComNzSemiRing := {R of NzSemiRing R & PzSemiRing_hasCommutativeMul R}. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing instead.")] Notation ComSemiRing R := (ComNzSemiRing R) (only parsing). Module ComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.sort instead.")] Notation sort := (ComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.on instead.")] Notation on R := (ComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzSemiRing.copy instead.")] Notation copy T U := (ComNzSemiRing.copy T U) (only parsing). End ComSemiRing. Module ComNzSemiRingExports. Bind Scope ring_scope with ComNzSemiRing.sort. End ComNzSemiRingExports. HB.export ComNzSemiRingExports. HB.factory Record Nmodule_isComNzSemiRing R of Nmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; mul0r : left_zero zero mul; oner_neq0 : one != zero }. Module Nmodule_isComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isComNzSemiRing.Build instead.")] Notation Build R := (Nmodule_isComNzSemiRing.Build R) (only parsing). End Nmodule_isComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use Nmodule_isComNzSemiRing instead.")] Notation Nmodule_isComSemiRing R := (Nmodule_isComNzSemiRing R) (only parsing). HB.builders Context R of Nmodule_isComNzSemiRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. Lemma mulr0 : right_zero zero mul. Proof. by move=> x; rewrite mulrC mul0r. Qed. HB.instance Definition _ := Nmodule_isNzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. Section ComSemiRingTheory. Variable R : comPzSemiRingType. Implicit Types x y : R. #[export] HB.instance Definition _ := SemiGroup.isCommutativeLaw.Build R *%R mulrC. Lemma mulrCA : @left_commutative R R *%R. Proof. exact: mulmCA. Qed. Lemma mulrAC : @right_commutative R R *%R. Proof. exact: mulmAC. Qed. Lemma mulrACA : @interchange R *%R *%R. Proof. exact: mulmACA. Qed. Lemma exprMn n : {morph (fun x => x ^+ n) : x y / x * y}. Proof. by move=> x y; exact/exprMn_comm/mulrC. Qed. Lemma prodrXl n I r (P : pred I) (F : I -> R) : \prod_(i <- r | P i) F i ^+ n = (\prod_(i <- r | P i) F i) ^+ n. Proof. by rewrite (big_morph _ (exprMn n) (expr1n _ n)). Qed. Lemma prodr_undup_exp_count (I : eqType) r (P : pred I) (F : I -> R) : \prod_(i <- undup r | P i) F i ^+ count_mem i r = \prod_(i <- r | P i) F i. Proof. exact: big_undup_iterop_count. Qed. Lemma prodrMl {I : finType} (A : pred I) (x : R) F : \prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i. Proof. by rewrite big_split ?prodr_const. Qed. Lemma prodrMr {I : finType} (A : pred I) (x : R) F : \prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|. Proof. by rewrite big_split ?prodr_const. Qed. Lemma exprDn x y n : (x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. by rewrite exprDn_comm //; apply: mulrC. Qed. Lemma sqrrD x y : (x + y) ^+ 2 = x ^+ 2 + x * y *+ 2 + y ^+ 2. Proof. by rewrite exprDn !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed. End ComSemiRingTheory. (* FIXME: Generalize to `comPzSemiRingType` ? *) Section ComNzSemiRingTheory. Variable R : comNzSemiRingType. Implicit Types x y : R. Section FrobeniusAutomorphism. Variables (p : nat) (pcharRp : p \in pchar R). Lemma pFrobenius_aut_is_nmod_morphism : nmod_morphism (pFrobenius_aut pcharRp). Proof. by split=> [|x y]; [exact: pFrobenius_aut0 | exact/pFrobenius_autD_comm/mulrC]. Qed. Lemma pFrobenius_aut_is_monoid_morphism : monoid_morphism (pFrobenius_aut pcharRp). Proof. by split=> [|x y]; [exact: pFrobenius_aut1 | exact/pFrobenius_autM_comm/mulrC]. Qed. #[export] HB.instance Definition _ := isNmodMorphism.Build R R (pFrobenius_aut pcharRp) pFrobenius_aut_is_nmod_morphism. #[export] HB.instance Definition _ := isMonoidMorphism.Build R R (pFrobenius_aut pcharRp) pFrobenius_aut_is_monoid_morphism. End FrobeniusAutomorphism. Lemma exprDn_pchar x y n : (pchar R).-nat n -> (x + y) ^+ n = x ^+ n + y ^+ n. Proof. pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]]. have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) ?pi_pdiv. have{pcharRn} /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)). by elim: e => // e IHe; rewrite !expnSr !exprM IHe -pFrobenius_autE rmorphD. Qed. (* FIXME: Generalize to `comPzSemiRingType` ? *) Lemma rmorph_comm (S : nzSemiRingType) (f : {rmorphism R -> S}) x y : comm (f x) (f y). Proof. by red; rewrite -!rmorphM mulrC. Qed. Section ScaleLinear. Variables (U V : lSemiModType R) (b : R) (f : {linear U -> V}). Lemma scale_is_scalable : scalable ( *:%R b : V -> V). Proof. by move=> a v /=; rewrite !scalerA mulrC. Qed. #[export] HB.instance Definition _ := isScalable.Build R V V *:%R ( *:%R b) scale_is_scalable. Lemma scale_fun_is_scalable : scalable (b \*: f). Proof. by move=> a v /=; rewrite !linearZ. Qed. #[export] HB.instance Definition _ := isScalable.Build R U V *:%R (b \*: f) scale_fun_is_scalable. End ScaleLinear. End ComNzSemiRingTheory. #[short(type="comPzRingType")] HB.structure Definition ComPzRing := {R of PzRing R & ComPzSemiRing R}. HB.factory Record PzRing_hasCommutativeMul R of PzRing R := { mulrC : commutative (@mul R) }. Module Ring_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzRing_hasCommutativeMul.Build instead.")] Notation Build R := (PzRing_hasCommutativeMul.Build R) (only parsing). End Ring_hasCommutativeMul. #[deprecated(since="mathcomp 2.4.0", note="Use PzRing_hasCommutativeMul instead.")] Notation Ring_hasCommutativeMul R := (PzRing_hasCommutativeMul R) (only parsing). HB.builders Context R of PzRing_hasCommutativeMul R. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC. HB.end. HB.factory Record Zmodule_isComPzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; }. HB.builders Context R of Zmodule_isComPzRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. HB.instance Definition _ := Zmodule_isPzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr. HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC. HB.end. Module ComPzRingExports. Bind Scope ring_scope with ComPzRing.sort. End ComPzRingExports. HB.export ComPzRingExports. #[deprecated(since="mathcomp 2.5.0", note="Use pFrobenius_aut_is_monoid_morphism instead.")] Notation pFrobenius_aut_is_multiplicative := (fun p => (p.2, p.1) \o pFrobenius_aut_is_monoid_morphism) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")] Notation exprDn_char := exprDn_pchar (only parsing). #[short(type="comNzRingType")] HB.structure Definition ComNzRing := {R of NzRing R & ComNzSemiRing R}. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing instead.")] Notation ComRing R := (ComNzRing R) (only parsing). Module ComRing. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.sort instead.")] Notation sort := (ComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.on instead.")] Notation on R := (ComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing.copy instead.")] Notation copy T U := (ComNzRing.copy T U) (only parsing). End ComRing. HB.factory Record Zmodule_isComNzRing R of Zmodule R := { one : R; mul : R -> R -> R; mulrA : associative mul; mulrC : commutative mul; mul1r : left_id one mul; mulrDl : left_distributive mul add; oner_neq0 : one != zero }. Module Zmodule_isComRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isComNzRing.Build instead.")] Notation Build R := (Zmodule_isComNzRing.Build R) (only parsing). End Zmodule_isComRing. #[deprecated(since="mathcomp 2.4.0", note="Use Zmodule_isComNzRing instead.")] Notation Zmodule_isComRing R := (Zmodule_isComNzRing R) (only parsing). HB.builders Context R of Zmodule_isComNzRing R. Definition mulr1 := Monoid.mulC_id mulrC mul1r. Definition mulrDr := Monoid.mulC_dist mulrC mulrDl. HB.instance Definition _ := Zmodule_isNzRing.Build R mulrA mul1r mulr1 mulrDl mulrDr oner_neq0. HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC. HB.end. Module ComNzRingExports. Bind Scope ring_scope with ComNzRing.sort. End ComNzRingExports. HB.export ComNzRingExports. Section ComPzRingTheory. Variable R : comPzRingType. Implicit Types x y : R. Lemma exprBn x y n : (x - y) ^+ n = \sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i). Proof. by rewrite exprBn_comm //; apply: mulrC. Qed. Lemma subrXX x y n : x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i). Proof. by rewrite -subrXX_comm //; apply: mulrC. Qed. Lemma sqrrB x y : (x - y) ^+ 2 = x ^+ 2 - x * y *+ 2 + y ^+ 2. Proof. by rewrite sqrrD mulrN mulNrn sqrrN. Qed. Lemma subr_sqr x y : x ^+ 2 - y ^+ 2 = (x - y) * (x + y). Proof. by rewrite subrXX !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed. Lemma subr_sqrDB x y : (x + y) ^+ 2 - (x - y) ^+ 2 = x * y *+ 4. Proof. rewrite sqrrD sqrrB -!(addrAC _ (y ^+ 2)) opprB. by rewrite [LHS]addrC addrA subrK -mulrnDr. Qed. End ComPzRingTheory. HB.mixin Record LSemiAlgebra_isSemiAlgebra R V of LSemiAlgebra R V := { scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y); }. #[short(type="semiAlgType")] HB.structure Definition SemiAlgebra (R : pzSemiRingType) := {A of LSemiAlgebra_isSemiAlgebra R A & LSemiAlgebra R A}. Module SemiAlgExports. Bind Scope ring_scope with SemiAlgebra.sort. End SemiAlgExports. HB.factory Record LSemiAlgebra_isComSemiAlgebra R V of ComPzSemiRing V & LSemiAlgebra R V := {}. HB.builders Context (R : pzSemiRingType) V of LSemiAlgebra_isComSemiAlgebra R V. Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y). Proof. by rewrite mulrC scalerAl mulrC. Qed. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalarAr. HB.end. #[short(type="algType")] HB.structure Definition Algebra (R : pzRingType) := {A of LSemiAlgebra_isSemiAlgebra R A & Lalgebra R A}. Module AlgExports. Bind Scope ring_scope with Algebra.sort. End AlgExports. HB.export AlgExports. HB.factory Record Lalgebra_isAlgebra (R : pzRingType) V of Lalgebra R V := { scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y); }. HB.builders Context (R : pzRingType) V of Lalgebra_isAlgebra R V. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalerAr. HB.end. HB.factory Record Lalgebra_isComAlgebra R V of ComPzRing V & Lalgebra R V := {}. HB.builders Context (R : pzRingType) V of Lalgebra_isComAlgebra R V. Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y). Proof. by rewrite mulrC scalerAl mulrC. Qed. HB.instance Definition lalgebra_is_algebra : Lalgebra_isAlgebra R V := Lalgebra_isAlgebra.Build R V scalarAr. HB.end. #[short(type="comSemiAlgType")] HB.structure Definition ComSemiAlgebra R := {V of ComNzSemiRing V & SemiAlgebra R V}. Module ComSemiAlgExports. Bind Scope ring_scope with ComSemiAlgebra.sort. End ComSemiAlgExports. HB.export ComSemiAlgExports. Section SemiAlgebraTheory. #[export] HB.instance Definition _ (R : comPzSemiRingType) := PzSemiRing_hasCommutativeMul.Build R^c (fun _ _ => mulrC _ _). #[export] HB.instance Definition _ (R : comPzSemiRingType) := ComPzSemiRing.on R^o. #[export] HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^c. #[export] HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^o. #[export] HB.instance Definition _ (R : comNzSemiRingType) := LSemiAlgebra_isComSemiAlgebra.Build R R^o. End SemiAlgebraTheory. #[short(type="comAlgType")] HB.structure Definition ComAlgebra R := {V of ComNzRing V & Algebra R V}. Module ComAlgExports. Bind Scope ring_scope with ComAlgebra.sort. End ComAlgExports. HB.export ComAlgExports. Section AlgebraTheory. #[export] HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^c. #[export] HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^o. #[export] HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^c. #[export] HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^o. End AlgebraTheory. Section SemiAlgebraTheory. Variables (R : pzSemiRingType) (A : semiAlgType R). Implicit Types (k : R) (x y : A). Lemma scalerCA k x y : k *: x * y = x * (k *: y). Proof. by rewrite -scalerAl scalerAr. Qed. Lemma mulr_algr a x : x * a%:A = a *: x. Proof. by rewrite -scalerAr mulr1. Qed. Lemma comm_alg a x : comm a%:A x. Proof. by rewrite /comm mulr_algr mulr_algl. Qed. Lemma exprZn k x n : (k *: x) ^+ n = k ^+ n *: x ^+ n. Proof. elim: n => [|n IHn]; first by rewrite !expr0 scale1r. by rewrite !exprS IHn -scalerA scalerAr scalerAl. Qed. Lemma scaler_prod I r (P : pred I) (F : I -> R) (G : I -> A) : \prod_(i <- r | P i) (F i *: G i) = \prod_(i <- r | P i) F i *: \prod_(i <- r | P i) G i. Proof. elim/big_rec3: _ => [|i x a _ _ ->]; first by rewrite scale1r. by rewrite -scalerAl -scalerAr scalerA. Qed. Lemma scaler_prodl (I : finType) (S : pred I) (F : I -> A) k : \prod_(i in S) (k *: F i) = k ^+ #|S| *: \prod_(i in S) F i. Proof. by rewrite scaler_prod prodr_const. Qed. Lemma scaler_prodr (I : finType) (S : pred I) (F : I -> R) x : \prod_(i in S) (F i *: x) = \prod_(i in S) F i *: x ^+ #|S|. Proof. by rewrite scaler_prod prodr_const. Qed. End SemiAlgebraTheory. Section AlgebraTheory. Variables (R : pzSemiRingType) (A : semiAlgType R). Variables (U : lSemiModType R) (a : A) (f : {linear U -> A}). Lemma mull_fun_is_scalable : scalable (a \*o f). Proof. by move=> k x /=; rewrite linearZ scalerAr. Qed. #[export] HB.instance Definition _ := isScalable.Build R U A *:%R (a \*o f) mull_fun_is_scalable. End AlgebraTheory. HB.mixin Record NzRing_hasMulInverse R of NzRing R := { unit_subdef : pred R; inv : R -> R; mulVr_subproof : {in unit_subdef, left_inverse 1 inv *%R}; divrr_subproof : {in unit_subdef, right_inverse 1 inv *%R}; unitrP_subproof : forall x y, y * x = 1 /\ x * y = 1 -> unit_subdef x; invr_out_subproof : {in [predC unit_subdef], inv =1 id} }. Module Ring_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing_hasMulInverse.Build instead.")] Notation Build R := (NzRing_hasMulInverse.Build R) (only parsing). End Ring_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use NzRing_hasMulInverse instead.")] Notation Ring_hasMulInverse R := (NzRing_hasMulInverse R) (only parsing). #[short(type="unitRingType")] HB.structure Definition UnitRing := {R of NzRing_hasMulInverse R & NzRing R}. Module UnitRingExports. Bind Scope ring_scope with UnitRing.sort. End UnitRingExports. HB.export UnitRingExports. Definition unit_pred {R : unitRingType} := Eval cbv [ unit_subdef NzRing_hasMulInverse.unit_subdef ] in (fun u : R => unit_subdef u). Arguments unit_pred _ _ /. Definition unit {R : unitRingType} := [qualify a u : R | unit_pred u]. Local Notation "x ^-1" := (inv x). Local Notation "x / y" := (x * y^-1). Local Notation "x ^- n" := ((x ^+ n)^-1). Section UnitRingTheory. Variable R : unitRingType. Implicit Types x y : R. Lemma divrr : {in unit, right_inverse 1 (@inv R) *%R}. Proof. exact: divrr_subproof. Qed. Definition mulrV := divrr. Lemma mulVr : {in unit, left_inverse 1 (@inv R) *%R}. Proof. exact: mulVr_subproof. Qed. Lemma invr_out x : x \isn't a unit -> x^-1 = x. Proof. exact: invr_out_subproof. Qed. Lemma unitrP x : reflect (exists y, y * x = 1 /\ x * y = 1) (x \is a unit). Proof. apply: (iffP idP) => [Ux | []]; last exact: unitrP_subproof. by exists x^-1; rewrite divrr ?mulVr. Qed. Lemma mulKr : {in unit, left_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite mulrA mulVr ?mul1r. Qed. Lemma mulVKr : {in unit, rev_left_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite mulrA mulrV ?mul1r. Qed. Lemma mulrK : {in unit, right_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite -mulrA divrr ?mulr1. Qed. Lemma mulrVK : {in unit, rev_right_loop (@inv R) *%R}. Proof. by move=> x Ux y; rewrite -mulrA mulVr ?mulr1. Qed. Definition divrK := mulrVK. Lemma mulrI : {in @unit R, right_injective *%R}. Proof. by move=> x Ux; apply: can_inj (mulKr Ux). Qed. Lemma mulIr : {in @unit R, left_injective *%R}. Proof. by move=> x Ux; apply: can_inj (mulrK Ux). Qed. (* Due to noncommutativity, fractions are inverted. *) Lemma telescope_prodr n m (f : nat -> R) : (forall k, n < k < m -> f k \is a unit) -> n < m -> \prod_(n <= k < m) (f k / f k.+1) = f n / f m. Proof. move=> Uf ltnm; rewrite (telescope_big (fun i j => f i / f j)) ?ltnm//. by move=> k ltnkm /=; rewrite mulrA divrK// Uf. Qed. Lemma telescope_prodr_eq n m (f u : nat -> R) : n < m -> (forall k, n < k < m -> f k \is a unit) -> (forall k, (n <= k < m)%N -> u k = f k / f k.+1) -> \prod_(n <= k < m) u k = f n / f m. Proof. by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodr. Qed. Lemma commrV x y : comm x y -> comm x y^-1. Proof. have [Uy cxy | /invr_out-> //] := boolP (y \in unit). by apply: (canLR (mulrK Uy)); rewrite -mulrA cxy mulKr. Qed. Lemma unitrE x : (x \is a unit) = (x / x == 1). Proof. apply/idP/eqP=> [Ux | xx1]; first exact: divrr. by apply/unitrP; exists x^-1; rewrite -commrV. Qed. Lemma invrK : involutive (@inv R). Proof. move=> x; case Ux: (x \in unit); last by rewrite !invr_out ?Ux. rewrite -(mulrK Ux _^-1) -mulrA commrV ?mulKr //. by apply/unitrP; exists x; rewrite divrr ?mulVr. Qed. Lemma invr_inj : injective (@inv R). Proof. exact: inv_inj invrK. Qed. Lemma unitrV x : (x^-1 \in unit) = (x \in unit). Proof. by rewrite !unitrE invrK commrV. Qed. Lemma unitr1 : 1 \in @unit R. Proof. by apply/unitrP; exists 1; rewrite mulr1. Qed. Lemma invr1 : 1^-1 = 1 :> R. Proof. by rewrite -{2}(mulVr unitr1) mulr1. Qed. Lemma div1r x : 1 / x = x^-1. Proof. by rewrite mul1r. Qed. Lemma divr1 x : x / 1 = x. Proof. by rewrite invr1 mulr1. Qed. Lemma natr_div m d : d %| m -> d%:R \is a @unit R -> (m %/ d)%:R = m%:R / d%:R :> R. Proof. by rewrite dvdn_eq => /eqP def_m unit_d; rewrite -{2}def_m natrM mulrK. Qed. Lemma divrI : {in unit, right_injective (fun x y => x / y)}. Proof. by move=> x /mulrI/inj_comp; apply; apply: invr_inj. Qed. Lemma divIr : {in unit, left_injective (fun x y => x / y)}. Proof. by move=> x; rewrite -unitrV => /mulIr. Qed. Lemma unitr0 : (0 \is a @unit R) = false. Proof. by apply/unitrP=> [[x [_ /esym/eqP]]]; rewrite mul0r oner_eq0. Qed. Lemma invr0 : 0^-1 = 0 :> R. Proof. by rewrite invr_out ?unitr0. Qed. Lemma unitrN1 : -1 \is a @unit R. Proof. by apply/unitrP; exists (-1); rewrite mulrNN mulr1. Qed. Lemma invrN1 : (-1)^-1 = -1 :> R. Proof. by rewrite -{2}(divrr unitrN1) mulN1r opprK. Qed. Lemma invr_sign n : ((-1) ^- n) = (-1) ^+ n :> R. Proof. by rewrite -signr_odd; case: (odd n); rewrite (invr1, invrN1). Qed. Lemma unitrMl x y : y \is a unit -> (x * y \is a unit) = (x \is a unit). Proof. move=> Uy; wlog Ux: x y Uy / x \is a unit => [WHxy|]. by apply/idP/idP=> Ux; first rewrite -(mulrK Uy x); rewrite WHxy ?unitrV. rewrite Ux; apply/unitrP; exists (y^-1 * x^-1). by rewrite -!mulrA mulKr ?mulrA ?mulrK ?divrr ?mulVr. Qed. Lemma unitrMr x y : x \is a unit -> (x * y \is a unit) = (y \is a unit). Proof. move=> Ux; apply/idP/idP=> [Uxy | Uy]; last by rewrite unitrMl. by rewrite -(mulKr Ux y) unitrMl ?unitrV. Qed. Lemma unitr_prod {I : Type} (P : pred I) (E : I -> R) (r : seq I) : (forall i, P i -> E i \is a GRing.unit) -> (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. by move=> Eunit; elim/big_rec: _ => [/[!unitr1] |i x /Eunit/unitrMr->]. Qed. Lemma unitr_prod_in {I : eqType} (P : pred I) (E : I -> R) (r : seq I) : {in r, forall i, P i -> E i \is a GRing.unit} -> (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. by rewrite big_seq_cond => H; apply: unitr_prod => i /andP[]; exact: H. Qed. Lemma invrM : {in unit &, forall x y, (x * y)^-1 = y^-1 * x^-1}. Proof. move=> x y Ux Uy; have Uxy: (x * y \in unit) by rewrite unitrMl. by apply: (mulrI Uxy); rewrite divrr ?mulrA ?mulrK ?divrr. Qed. Lemma unitrM_comm x y : comm x y -> (x * y \is a unit) = (x \is a unit) && (y \is a unit). Proof. move=> cxy; apply/idP/andP=> [Uxy | [Ux Uy]]; last by rewrite unitrMl. suffices Ux: x \in unit by rewrite unitrMr in Uxy. apply/unitrP; case/unitrP: Uxy => z [zxy xyz]; exists (y * z). rewrite mulrA xyz -{1}[y]mul1r -{1}zxy cxy -!mulrA (mulrA x) (mulrA _ z) xyz. by rewrite mul1r -cxy. Qed. Lemma unitrX x n : x \is a unit -> x ^+ n \is a unit. Proof. by move=> Ux; elim: n => [|n IHn]; rewrite ?unitr1 // exprS unitrMl. Qed. Lemma unitrX_pos x n : n > 0 -> (x ^+ n \in unit) = (x \in unit). Proof. case: n => // n _; rewrite exprS unitrM_comm; last exact: commrX. by case Ux: (x \is a unit); rewrite // unitrX. Qed. Lemma exprVn x n : x^-1 ^+ n = x ^- n. Proof. elim: n => [|n IHn]; first by rewrite !expr0 ?invr1. case Ux: (x \is a unit); first by rewrite exprSr exprS IHn -invrM // unitrX. by rewrite !invr_out ?unitrX_pos ?Ux. Qed. Lemma exprB m n x : n <= m -> x \is a unit -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. by move/subnK=> {2}<- Ux; rewrite exprD mulrK ?unitrX. Qed. Lemma invr_neq0 x : x != 0 -> x^-1 != 0. Proof. move=> nx0; case Ux: (x \is a unit); last by rewrite invr_out ?Ux. by apply/eqP=> x'0; rewrite -unitrV x'0 unitr0 in Ux. Qed. Lemma invr_eq0 x : (x^-1 == 0) = (x == 0). Proof. by apply: negb_inj; apply/idP/idP; move/invr_neq0; rewrite ?invrK. Qed. Lemma invr_eq1 x : (x^-1 == 1) = (x == 1). Proof. by rewrite (inv_eq invrK) invr1. Qed. Lemma rev_unitrP (x y : R^c) : y * x = 1 /\ x * y = 1 -> x \is a unit. Proof. by case=> [yx1 xy1]; apply/unitrP; exists y. Qed. #[export] HB.instance Definition _ := NzRing_hasMulInverse.Build R^c mulrV mulVr rev_unitrP invr_out. #[export] HB.instance Definition _ := UnitRing.on R^o. End UnitRingTheory. Arguments invrK {R}. Arguments invr_inj {R} [x1 x2]. Arguments telescope_prodr_eq {R n m} f u. Lemma rev_prodrV (R : unitRingType) (I : Type) (r : seq I) (P : pred I) (E : I -> R) : (forall i, P i -> E i \is a GRing.unit) -> \prod_(i <- r | P i) (E i)^-1 = ((\prod_(i <- r | P i) (E i : R^c))^-1). Proof. move=> Eunit; symmetry. apply: (big_morph_in GRing.unit _ _ (unitr1 R^c) (@invrM _) (invr1 _)) Eunit. by move=> x y xunit; rewrite unitrMr. Qed. Section UnitRingClosedPredicates. Variables (R : unitRingType) (S : {pred R}). Definition invr_closed := {in S, forall x, x^-1 \in S}. Definition divr_2closed := {in S &, forall x y, x / y \in S}. Definition divr_closed := 1 \in S /\ divr_2closed. Definition sdivr_closed := -1 \in S /\ divr_2closed. Definition divring_closed := [/\ 1 \in S, subr_2closed S & divr_2closed]. Lemma divr_closedV : divr_closed -> invr_closed. Proof. by case=> S1 Sdiv x Sx; rewrite -[x^-1]mul1r Sdiv. Qed. Lemma divr_closedM : divr_closed -> mulr_closed S. Proof. by case=> S1 Sdiv; split=> // x y Sx Sy; rewrite -[y]invrK -[y^-1]mul1r !Sdiv. Qed. Lemma sdivr_closed_div : sdivr_closed -> divr_closed. Proof. by case=> SN1 Sdiv; split; rewrite // -(divrr (@unitrN1 _)) Sdiv. Qed. Lemma sdivr_closedM : sdivr_closed -> smulr_closed S. Proof. by move=> Sdiv; have [_ SM] := divr_closedM (sdivr_closed_div Sdiv); case: Sdiv. Qed. Lemma divring_closedBM : divring_closed -> subring_closed S. Proof. by case=> S1 SB Sdiv; split=> //; case: divr_closedM. Qed. Lemma divring_closed_div : divring_closed -> sdivr_closed. Proof. case=> S1 SB Sdiv; split; rewrite ?zmod_closedN //. exact/subring_closedB/divring_closedBM. Qed. End UnitRingClosedPredicates. Section UnitRingMorphism. Variables (R S : unitRingType) (f : {rmorphism R -> S}). Lemma rmorph_unit x : x \in unit -> f x \in unit. Proof. case/unitrP=> y [yx1 xy1]; apply/unitrP. by exists (f y); rewrite -!rmorphM // yx1 xy1 rmorph1. Qed. Lemma rmorphV : {in unit, {morph f: x / x^-1}}. Proof. move=> x Ux; rewrite /= -[(f x)^-1]mul1r. by apply: (canRL (mulrK (rmorph_unit Ux))); rewrite -rmorphM mulVr ?rmorph1. Qed. Lemma rmorph_div x y : y \in unit -> f (x / y) = f x / f y. Proof. by move=> Uy; rewrite rmorphM /= rmorphV. Qed. End UnitRingMorphism. #[short(type="comUnitRingType")] HB.structure Definition ComUnitRing := {R of ComNzRing R & UnitRing R}. Module ComUnitRingExports. Bind Scope ring_scope with ComUnitRing.sort. End ComUnitRingExports. HB.export ComUnitRingExports. (* TODO_HB: fix the name (was ComUnitRingMixin) *) HB.factory Record ComNzRing_hasMulInverse R of ComNzRing R := { unit : {pred R}; inv : R -> R; mulVx : {in unit, left_inverse 1 inv *%R}; unitPl : forall x y, y * x = 1 -> unit x; invr_out : {in [predC unit], inv =1 id} }. Module ComRing_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_hasMulInverse.Build instead.")] Notation Build R := (ComNzRing_hasMulInverse.Build R) (only parsing). End ComRing_hasMulInverse. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_hasMulInverse instead.")] Notation ComRing_hasMulInverse R := (ComNzRing_hasMulInverse R) (only parsing). HB.builders Context R of ComNzRing_hasMulInverse R. Fact mulC_mulrV : {in unit, right_inverse 1 inv *%R}. Proof. by move=> x Ux /=; rewrite mulrC mulVx. Qed. Fact mulC_unitP x y : y * x = 1 /\ x * y = 1 -> unit x. Proof. by case=> yx _; apply: unitPl yx. Qed. HB.instance Definition _ := NzRing_hasMulInverse.Build R mulVx mulC_mulrV mulC_unitP invr_out. HB.end. #[short(type="unitAlgType")] HB.structure Definition UnitAlgebra R := {V of Algebra R V & UnitRing V}. Module UnitAlgebraExports. Bind Scope ring_scope with UnitAlgebra.sort. End UnitAlgebraExports. HB.export UnitAlgebraExports. #[short(type="comUnitAlgType")] HB.structure Definition ComUnitAlgebra R := {V of ComAlgebra R V & UnitRing V}. Module ComUnitAlgebraExports. Bind Scope ring_scope with UnitAlgebra.sort. End ComUnitAlgebraExports. HB.export ComUnitAlgebraExports. Section ComUnitRingTheory. Variable R : comUnitRingType. Implicit Types x y : R. Lemma unitrM x y : (x * y \in unit) = (x \in unit) && (y \in unit). Proof. exact/unitrM_comm/mulrC. Qed. Lemma unitrPr x : reflect (exists y, x * y = 1) (x \in unit). Proof. by apply: (iffP (unitrP x)) => [[y []] | [y]]; exists y; rewrite // mulrC. Qed. Lemma mulr1_eq x y : x * y = 1 -> x^-1 = y. Proof. by move=> xy_eq1; rewrite -[LHS]mulr1 -xy_eq1; apply/mulKr/unitrPr; exists y. Qed. Lemma divr1_eq x y : x / y = 1 -> x = y. Proof. by move/mulr1_eq/invr_inj. Qed. Lemma divKr x : x \is a unit -> {in unit, involutive (fun y => x / y)}. Proof. by move=> Ux y Uy; rewrite /= invrM ?unitrV // invrK mulrC divrK. Qed. Lemma expr_div_n x y n : (x / y) ^+ n = x ^+ n / y ^+ n. Proof. by rewrite exprMn exprVn. Qed. Lemma unitr_prodP (I : eqType) (r : seq I) (P : pred I) (E : I -> R) : reflect {in r, forall i, P i -> E i \is a GRing.unit} (\prod_(i <- r | P i) E i \is a GRing.unit). Proof. rewrite (big_morph [in unit] unitrM (@unitr1 _) ) big_all_cond. exact: 'all_implyP. Qed. Lemma prodrV (I : eqType) (r : seq I) (P : pred I) (E : I -> R) : (forall i, P i -> E i \is a GRing.unit) -> \prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1. Proof. by move=> /rev_prodrV->; rewrite rev_prodr (perm_big r)// perm_rev. Qed. (* TODO: HB.saturate *) #[export] HB.instance Definition _ := ComUnitRing.on R^c. #[export] HB.instance Definition _ := ComUnitRing.on R^o. (* /TODO *) End ComUnitRingTheory. Section UnitAlgebraTheory. Variable (R : comUnitRingType) (A : unitAlgType R). Implicit Types (k : R) (x y : A). Lemma scaler_injl : {in unit, @right_injective R A A *:%R}. Proof. move=> k Uk x1 x2 Hx1x2. by rewrite -[x1]scale1r -(mulVr Uk) -scalerA Hx1x2 scalerA mulVr // scale1r. Qed. Lemma scaler_unit k x : k \in unit -> (k *: x \in unit) = (x \in unit). Proof. move=> Uk; apply/idP/idP=> [Ukx | Ux]; apply/unitrP; last first. exists (k^-1 *: x^-1). by rewrite -!scalerAl -!scalerAr !scalerA !mulVr // !mulrV // scale1r. exists (k *: (k *: x)^-1); split. apply: (mulrI Ukx). by rewrite mulr1 mulrA -scalerAr mulrV // -scalerAl mul1r. apply: (mulIr Ukx). by rewrite mul1r -mulrA -scalerAl mulVr // -scalerAr mulr1. Qed. Lemma invrZ k x : k \in unit -> x \in unit -> (k *: x)^-1 = k^-1 *: x^-1. Proof. move=> Uk Ux; have Ukx: (k *: x \in unit) by rewrite scaler_unit. apply: (mulIr Ukx). by rewrite mulVr // -scalerAl -scalerAr scalerA !mulVr // scale1r. Qed. Section ClosedPredicates. Variables S : {pred A}. Definition divalg_closed := [/\ 1 \in S, linear_closed S & divr_2closed S]. Lemma divalg_closedBdiv : divalg_closed -> divring_closed S. Proof. by case=> S1 /linear_closedB. Qed. Lemma divalg_closedZ : divalg_closed -> subalg_closed S. Proof. by case=> S1 Slin Sdiv; split=> //; have [] := @divr_closedM A S. Qed. End ClosedPredicates. End UnitAlgebraTheory. Module ClosedExports. Notation addr_closed := nmod_closed. Notation oppr_closed := oppr_closed. Notation zmod_closed := zmod_closed. Notation mulr_closed := mulr_closed. Notation semiring_closed := semiring_closed. Notation smulr_closed := smulr_closed. Notation subring_closed := subring_closed. Notation scaler_closed := scaler_closed. Notation subsemimod_closed := subsemimod_closed. Notation linear_closed := linear_closed. Notation submod_closed := submod_closed. Notation subalg_closed := subalg_closed. Notation invr_closed := invr_closed. Notation divr_2closed := divr_2closed. Notation divr_closed := divr_closed. Notation sdivr_closed := sdivr_closed. Notation divring_closed := divring_closed. Notation divalg_closed := divalg_closed. Coercion zmod_closedD : zmod_closed >-> nmod_closed. Coercion zmod_closedN : zmod_closed >-> oppr_closed. Coercion semiring_closedD : semiring_closed >-> addr_closed. Coercion semiring_closedM : semiring_closed >-> mulr_closed. Coercion smulr_closedM : smulr_closed >-> mulr_closed. Coercion smulr_closedN : smulr_closed >-> oppr_closed. Coercion subring_closedB : subring_closed >-> zmod_closed. Coercion subring_closedM : subring_closed >-> smulr_closed. Coercion subring_closed_semi : subring_closed >-> semiring_closed. Coercion subsemimod_closedD : subsemimod_closed >-> addr_closed. Coercion subsemimod_closedZ : subsemimod_closed >-> scaler_closed. Coercion linear_closedB : linear_closed >-> subr_2closed. Coercion submod_closedB : submod_closed >-> zmod_closed. Coercion submod_closed_semi : submod_closed >-> subsemimod_closed. Coercion subalg_closedZ : subalg_closed >-> submod_closed. Coercion subalg_closedBM : subalg_closed >-> subring_closed. Coercion divr_closedV : divr_closed >-> invr_closed. Coercion divr_closedM : divr_closed >-> mulr_closed. Coercion sdivr_closed_div : sdivr_closed >-> divr_closed. Coercion sdivr_closedM : sdivr_closed >-> smulr_closed. Coercion divring_closedBM : divring_closed >-> subring_closed. Coercion divring_closed_div : divring_closed >-> sdivr_closed. Coercion divalg_closedBdiv : divalg_closed >-> divring_closed. Coercion divalg_closedZ : divalg_closed >-> subalg_closed. End ClosedExports. (* Reification of the theory of rings with units, in named style *) Section TermDef. Variable R : Type. Inductive term : Type := | Var of nat | Const of R | NatConst of nat | Add of term & term | Opp of term | NatMul of term & nat | Mul of term & term | Inv of term | Exp of term & nat. Inductive formula : Type := | Bool of bool | Equal of term & term | Unit of term | And of formula & formula | Or of formula & formula | Implies of formula & formula | Not of formula | Exists of nat & formula | Forall of nat & formula. End TermDef. Bind Scope term_scope with term. Bind Scope term_scope with formula. Arguments Add {R} t1%_T t2%_T. Arguments Opp {R} t1%_T. Arguments NatMul {R} t1%_T n%_N. Arguments Mul {R} t1%_T t2%_T. Arguments Inv {R} t1%_T. Arguments Exp {R} t1%_T n%_N. Arguments Equal {R} t1%_T t2%_T. Arguments Unit {R} t1%_T. Arguments And {R} f1%_T f2%_T. Arguments Or {R} f1%_T f2%_T. Arguments Implies {R} f1%_T f2%_T. Arguments Not {R} f1%_T. Arguments Exists {R} i%_N f1%_T. Arguments Forall {R} i%_N f1%_T. Arguments Bool {R} b. Arguments Const {R} x. Notation True := (Bool true). Notation False := (Bool false). Local Notation "''X_' i" := (Var _ i) : term_scope. Local Notation "n %:R" := (NatConst _ n) : term_scope. Local Notation "x %:T" := (Const x) : term_scope. Local Notation "0" := 0%:R%T : term_scope. Local Notation "1" := 1%:R%T : term_scope. Local Infix "+" := Add : term_scope. Local Notation "- t" := (Opp t) : term_scope. Local Notation "t - u" := (Add t (- u)) : term_scope. Local Infix "*" := Mul : term_scope. Local Infix "*+" := NatMul : term_scope. Local Notation "t ^-1" := (Inv t) : term_scope. Local Notation "t / u" := (Mul t u^-1) : term_scope. Local Infix "^+" := Exp : term_scope. Local Infix "==" := Equal : term_scope. Local Infix "/\" := And : term_scope. Local Infix "\/" := Or : term_scope. Local Infix "==>" := Implies : term_scope. Local Notation "~ f" := (Not f) : term_scope. Local Notation "x != y" := (Not (x == y)) : term_scope. Local Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope. Local Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope. Section Substitution. Variable R : Type. Fixpoint tsubst (t : term R) (s : nat * term R) := match t with | 'X_i => if i == s.1 then s.2 else t | _%:T | _%:R => t | t1 + t2 => tsubst t1 s + tsubst t2 s | - t1 => - tsubst t1 s | t1 *+ n => tsubst t1 s *+ n | t1 * t2 => tsubst t1 s * tsubst t2 s | t1^-1 => (tsubst t1 s)^-1 | t1 ^+ n => tsubst t1 s ^+ n end%T. Fixpoint fsubst (f : formula R) (s : nat * term R) := match f with | Bool _ => f | t1 == t2 => tsubst t1 s == tsubst t2 s | Unit t1 => Unit (tsubst t1 s) | f1 /\ f2 => fsubst f1 s /\ fsubst f2 s | f1 \/ f2 => fsubst f1 s \/ fsubst f2 s | f1 ==> f2 => fsubst f1 s ==> fsubst f2 s | ~ f1 => ~ fsubst f1 s | ('exists 'X_i, f1) => 'exists 'X_i, if i == s.1 then f1 else fsubst f1 s | ('forall 'X_i, f1) => 'forall 'X_i, if i == s.1 then f1 else fsubst f1 s end%T. End Substitution. Section EvalTerm. Variable R : unitRingType. (* Evaluation of a reified term into R a ring with units *) Fixpoint eval (e : seq R) (t : term R) {struct t} : R := match t with | ('X_i)%T => e`_i | (x%:T)%T => x | (n%:R)%T => n%:R | (t1 + t2)%T => eval e t1 + eval e t2 | (- t1)%T => - eval e t1 | (t1 *+ n)%T => eval e t1 *+ n | (t1 * t2)%T => eval e t1 * eval e t2 | t1^-1%T => (eval e t1)^-1 | (t1 ^+ n)%T => eval e t1 ^+ n end. Definition same_env (e e' : seq R) := nth 0 e =1 nth 0 e'. Lemma eq_eval e e' t : same_env e e' -> eval e t = eval e' t. Proof. by move=> eq_e; elim: t => //= t1 -> // t2 ->. Qed. Lemma eval_tsubst e t s : eval e (tsubst t s) = eval (set_nth 0 e s.1 (eval e s.2)) t. Proof. case: s => i u; elim: t => //=; do 2?[move=> ? -> //] => j. by rewrite nth_set_nth /=; case: (_ == _). Qed. (* Evaluation of a reified formula *) Fixpoint holds (e : seq R) (f : formula R) {struct f} : Prop := match f with | Bool b => b | (t1 == t2)%T => eval e t1 = eval e t2 | Unit t1 => eval e t1 \in unit | (f1 /\ f2)%T => holds e f1 /\ holds e f2 | (f1 \/ f2)%T => holds e f1 \/ holds e f2 | (f1 ==> f2)%T => holds e f1 -> holds e f2 | (~ f1)%T => ~ holds e f1 | ('exists 'X_i, f1)%T => exists x, holds (set_nth 0 e i x) f1 | ('forall 'X_i, f1)%T => forall x, holds (set_nth 0 e i x) f1 end. Lemma same_env_sym e e' : same_env e e' -> same_env e' e. Proof. exact: fsym. Qed. (* Extensionality of formula evaluation *) Lemma eq_holds e e' f : same_env e e' -> holds e f -> holds e' f. Proof. pose sv := set_nth (0 : R). have eq_i i v e1 e2: same_env e1 e2 -> same_env (sv e1 i v) (sv e2 i v). by move=> eq_e j; rewrite !nth_set_nth /= eq_e. elim: f e e' => //=. - by move=> t1 t2 e e' eq_e; rewrite !(eq_eval _ eq_e). - by move=> t e e' eq_e; rewrite (eq_eval _ eq_e). - by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto. - by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto. - by move=> f1 IH1 f2 IH2 e e' eq_e f12; move/IH1: (same_env_sym eq_e); eauto. - by move=> f1 IH1 e e'; move/same_env_sym; move/IH1; tauto. - by move=> i f1 IH1 e e'; move/(eq_i i)=> eq_e [x f_ex]; exists x; eauto. by move=> i f1 IH1 e e'; move/(eq_i i); eauto. Qed. (* Evaluation and substitution by a constant *) Lemma holds_fsubst e f i v : holds e (fsubst f (i, v%:T)%T) <-> holds (set_nth 0 e i v) f. Proof. elim: f e => //=; do [ by move=> *; rewrite !eval_tsubst | move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto | move=> f IHf e; move: (IHf e); tauto | move=> j f IHf e]. - case eq_ji: (j == i); first rewrite (eqP eq_ji). by split=> [] [x f_x]; exists x; rewrite set_set_nth eqxx in f_x *. split=> [] [x f_x]; exists x; move: f_x; rewrite set_set_nth eq_sym eq_ji; have:= IHf (set_nth 0 e j x); tauto. case eq_ji: (j == i); first rewrite (eqP eq_ji). by split=> [] f_ x; move: (f_ x); rewrite set_set_nth eqxx. split=> [] f_ x; move: (IHf (set_nth 0 e j x)) (f_ x); by rewrite set_set_nth 1?[i == j]eq_sym eq_ji; tauto. Qed. (* Boolean test selecting terms in the language of rings *) Fixpoint rterm (t : term R) := match t with | _^-1 => false | t1 + t2 | t1 * t2 => rterm t1 && rterm t2 | - t1 | t1 *+ _ | t1 ^+ _ => rterm t1 | _ => true end%T. (* Boolean test selecting formulas in the theory of rings *) Fixpoint rformula (f : formula R) := match f with | Bool _ => true | t1 == t2 => rterm t1 && rterm t2 | Unit t1 => false | f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => rformula f1 && rformula f2 | ~ f1 | ('exists 'X__, f1) | ('forall 'X__, f1) => rformula f1 end%T. (* Upper bound of the names used in a term *) Fixpoint ub_var (t : term R) := match t with | 'X_i => i.+1 | t1 + t2 | t1 * t2 => maxn (ub_var t1) (ub_var t2) | - t1 | t1 *+ _ | t1 ^+ _ | t1^-1 => ub_var t1 | _ => 0%N end%T. (* Replaces inverses in the term t by fresh variables, accumulating the *) (* substitution. *) Fixpoint to_rterm (t : term R) (r : seq (term R)) (n : nat) {struct t} := match t with | t1^-1 => let: (t1', r1) := to_rterm t1 r n in ('X_(n + size r1), rcons r1 t1') | t1 + t2 => let: (t1', r1) := to_rterm t1 r n in let: (t2', r2) := to_rterm t2 r1 n in (t1' + t2', r2) | - t1 => let: (t1', r1) := to_rterm t1 r n in (- t1', r1) | t1 *+ m => let: (t1', r1) := to_rterm t1 r n in (t1' *+ m, r1) | t1 * t2 => let: (t1', r1) := to_rterm t1 r n in let: (t2', r2) := to_rterm t2 r1 n in (Mul t1' t2', r2) | t1 ^+ m => let: (t1', r1) := to_rterm t1 r n in (t1' ^+ m, r1) | _ => (t, r) end%T. Lemma to_rterm_id t r n : rterm t -> to_rterm t r n = (t, r). Proof. elim: t r n => //. - by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2. - by move=> t IHt r n /= rt; rewrite {}IHt. - by move=> t IHt r n m /= rt; rewrite {}IHt. - by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2. - by move=> t IHt r n m /= rt; rewrite {}IHt. Qed. (* A ring formula stating that t1 is equal to 0 in the ring theory. *) (* Also applies to non commutative rings. *) Definition eq0_rform t1 := let m := ub_var t1 in let: (t1', r1) := to_rterm t1 [::] m in let fix loop r i := match r with | [::] => t1' == 0 | t :: r' => let f := 'X_i * t == 1 /\ t * 'X_i == 1 in 'forall 'X_i, (f \/ 'X_i == t /\ ~ ('exists 'X_i, f)) ==> loop r' i.+1 end%T in loop r1 m. (* Transformation of a formula in the theory of rings with units into an *) (* equivalent formula in the sub-theory of rings. *) Fixpoint to_rform f := match f with | Bool b => f | t1 == t2 => eq0_rform (t1 - t2) | Unit t1 => eq0_rform (t1 * t1^-1 - 1) | f1 /\ f2 => to_rform f1 /\ to_rform f2 | f1 \/ f2 => to_rform f1 \/ to_rform f2 | f1 ==> f2 => to_rform f1 ==> to_rform f2 | ~ f1 => ~ to_rform f1 | ('exists 'X_i, f1) => 'exists 'X_i, to_rform f1 | ('forall 'X_i, f1) => 'forall 'X_i, to_rform f1 end%T. (* The transformation gives a ring formula. *) Lemma to_rform_rformula f : rformula (to_rform f). Proof. suffices eq0_ring t1: rformula (eq0_rform t1) by elim: f => //= => f1 ->. rewrite /eq0_rform; move: (ub_var t1) => m; set tr := _ m. suffices: all rterm (tr.1 :: tr.2). case: tr => {}t1 r /= /andP[t1_r]. by elim: r m => [|t r IHr] m; rewrite /= ?andbT // => /andP[->]; apply: IHr. have: all rterm [::] by []. rewrite {}/tr; elim: t1 [::] => //=. - move=> t1 IHt1 t2 IHt2 r. move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r]. move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r]. by rewrite t1_r t2_r. - by move=> t1 IHt1 r /IHt1; case: to_rterm. - by move=> t1 IHt1 n r /IHt1; case: to_rterm. - move=> t1 IHt1 t2 IHt2 r. move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r]. move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r]. by rewrite t1_r t2_r. - move=> t1 IHt1 r. by move/IHt1; case: to_rterm => {r IHt1}t1 r /=; rewrite all_rcons. - by move=> t1 IHt1 n r /IHt1; case: to_rterm. Qed. (* Correctness of the transformation. *) Lemma to_rformP e f : holds e (to_rform f) <-> holds e f. Proof. suffices{e f} equal0_equiv e t1 t2: holds e (eq0_rform (t1 - t2)) <-> (eval e t1 == eval e t2). - elim: f e => /=; try tauto. + move=> t1 t2 e. by split; [move/equal0_equiv/eqP | move/eqP/equal0_equiv]. + by move=> t1 e; rewrite unitrE; apply: equal0_equiv. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto. + by move=> f1 IHf1 e; move: (IHf1 e); tauto. + by move=> n f1 IHf1 e; split=> [] [x] /IHf1; exists x. + by move=> n f1 IHf1 e; split=> Hx x; apply/IHf1. rewrite -(add0r (eval e t2)) -(can2_eq (subrK _) (addrK _)). rewrite -/(eval e (t1 - t2)); move: (t1 - t2)%T => {t1 t2} t. have sub_var_tsubst s t0: s.1 >= ub_var t0 -> tsubst t0 s = t0. elim: t0 {t} => //=. - by move=> n; case: ltngtP. - by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->]. - by move=> t1 IHt1 /IHt1->. - by move=> t1 IHt1 n /IHt1->. - by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->]. - by move=> t1 IHt1 /IHt1->. - by move=> t1 IHt1 n /IHt1->. pose fix rsub t' m r : term R := if r is u :: r' then tsubst (rsub t' m.+1 r') (m, u^-1)%T else t'. pose fix ub_sub m r : Prop := if r is u :: r' then ub_var u <= m /\ ub_sub m.+1 r' else true. suffices{t} rsub_to_r t r0 m: m >= ub_var t -> ub_sub m r0 -> let: (t', r) := to_rterm t r0 m in [/\ take (size r0) r = r0, ub_var t' <= m + size r, ub_sub m r & rsub t' m r = t]. - have:= rsub_to_r t [::] _ (leqnn _); rewrite /eq0_rform. case: (to_rterm _ _ _) => [t1' r1] [//|_ _ ub_r1 def_t]. rewrite -{2}def_t {def_t}. elim: r1 (ub_var t) e ub_r1 => [|u r1 IHr1] m e /= => [_|[ub_u ub_r1]]. by split=> /eqP. rewrite eval_tsubst /=; set y := eval e u; split=> t_eq0. apply/IHr1=> //; apply: t_eq0. rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)). rewrite sub_var_tsubst //= -/y. case Uy: (y \in unit); [left | right]; first by rewrite mulVr ?divrr. split=> [|[z]]; first by rewrite invr_out ?Uy. rewrite nth_set_nth /= eqxx. rewrite -!(eval_tsubst _ _ (m, Const _)) !sub_var_tsubst // -/y => yz1. by case/unitrP: Uy; exists z. move=> x def_x; apply/IHr1=> //; suff ->: x = y^-1 by []; move: def_x. rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)). rewrite sub_var_tsubst //= -/y; case=> [[xy1 yx1] | [xy nUy]]. by rewrite -[y^-1]mul1r -[1]xy1 mulrK //; apply/unitrP; exists x. rewrite invr_out //; apply/unitrP=> [[z yz1]]; case: nUy; exists z. rewrite nth_set_nth /= eqxx -!(eval_tsubst _ _ (m, _%:T)%T). by rewrite !sub_var_tsubst. have rsub_id r t0 n: ub_var t0 <= n -> rsub t0 n r = t0. by elim: r n => //= t1 r IHr n let0n; rewrite IHr ?sub_var_tsubst ?leqW. have rsub_acc r s t1 m1: ub_var t1 <= m1 + size r -> rsub t1 m1 (r ++ s) = rsub t1 m1 r. elim: r t1 m1 => [|t1 r IHr] t2 m1 /=; first by rewrite addn0; apply: rsub_id. by move=> letmr; rewrite IHr ?addSnnS. elim: t r0 m => /=; try do [ by move=> n r m hlt hub; rewrite take_size (ltn_addr _ hlt) rsub_id | by move=> n r m hlt hub; rewrite leq0n take_size rsub_id | move=> t1 IHt1 t2 IHt2 r m; rewrite geq_max; case/andP=> hub1 hub2 hmr; case: to_rterm {hub1 hmr}(IHt1 r m hub1 hmr) => t1' r1; case=> htake1 hub1' hsub1 <-; case: to_rterm {IHt2 hub2 hsub1}(IHt2 r1 m hub2 hsub1) => t2' r2 /=; rewrite geq_max; case=> htake2 -> hsub2 /= <-; rewrite -{1 2}(cat_take_drop (size r1) r2) htake2; set r3 := drop _ _; rewrite size_cat addnA (leq_trans _ (leq_addr _ _)) //; split=> {hsub2}//; first by [rewrite takel_cat // -htake1 size_take geq_min leqnn orbT]; rewrite -(rsub_acc r1 r3 t1') {hub1'}// -{htake1}htake2 {r3}cat_take_drop; by elim: r2 m => //= u r2 IHr2 m; rewrite IHr2 | do [ move=> t1 IHt1 r m; do 2!move=> /IHt1{}IHt1 | move=> t1 IHt1 n r m; do 2!move=> /IHt1{}IHt1]; case: to_rterm IHt1 => t1' r1 [-> -> hsub1 <-]; split=> {hsub1}//; by elim: r1 m => //= u r1 IHr1 m; rewrite IHr1]. move=> t1 IH r m letm /IH {IH} /(_ letm) {letm}. case: to_rterm => t1' r1 /= [def_r ub_t1' ub_r1 <-]. rewrite size_rcons addnS leqnn -{1}cats1 takel_cat ?def_r; last first. by rewrite -def_r size_take geq_min leqnn orbT. elim: r1 m ub_r1 ub_t1' {def_r} => /= [|u r1 IHr1] m => [_|[->]]. by rewrite addn0 eqxx. by rewrite -addSnnS => /IHr1 IH /IH[_ _ ub_r1 ->]. Qed. (* Boolean test selecting formulas which describe a constructible set, *) (* i.e. formulas without quantifiers. *) (* The quantifier elimination check. *) Fixpoint qf_form (f : formula R) := match f with | Bool _ | _ == _ | Unit _ => true | f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => qf_form f1 && qf_form f2 | ~ f1 => qf_form f1 | _ => false end%T. (* Boolean holds predicate for quantifier free formulas *) Definition qf_eval e := fix loop (f : formula R) : bool := match f with | Bool b => b | t1 == t2 => (eval e t1 == eval e t2)%bool | Unit t1 => eval e t1 \in unit | f1 /\ f2 => loop f1 && loop f2 | f1 \/ f2 => loop f1 || loop f2 | f1 ==> f2 => (loop f1 ==> loop f2)%bool | ~ f1 => ~~ loop f1 |_ => false end%T. (* qf_eval is equivalent to holds *) Lemma qf_evalP e f : qf_form f -> reflect (holds e f) (qf_eval e f). Proof. elim: f => //=; try by move=> *; apply: idP. - by move=> t1 t2 _; apply: eqP. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by right; case. by case/IHf2; [left | right; case]. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1F]; first by do 2 left. by case/IHf2; [left; right | right; case]. - move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by left. by case/IHf2; [left | right; move/(_ f1T)]. by move=> f1 IHf1 /IHf1[]; [right | left]. Qed. Implicit Type bc : seq (term R) * seq (term R). (* Quantifier-free formula are normalized into DNF. A DNF is *) (* represented by the type seq (seq (term R) * seq (term R)), where we *) (* separate positive and negative literals *) (* DNF preserving conjunction *) Definition and_dnf bcs1 bcs2 := \big[cat/nil]_(bc1 <- bcs1) map (fun bc2 => (bc1.1 ++ bc2.1, bc1.2 ++ bc2.2)) bcs2. (* Computes a DNF from a qf ring formula *) Fixpoint qf_to_dnf (f : formula R) (neg : bool) {struct f} := match f with | Bool b => if b (+) neg then [:: ([::], [::])] else [::] | t1 == t2 => [:: if neg then ([::], [:: t1 - t2]) else ([:: t1 - t2], [::])] | f1 /\ f2 => (if neg then cat else and_dnf) [rec f1, neg] [rec f2, neg] | f1 \/ f2 => (if neg then and_dnf else cat) [rec f1, neg] [rec f2, neg] | f1 ==> f2 => (if neg then and_dnf else cat) [rec f1, ~~ neg] [rec f2, neg] | ~ f1 => [rec f1, ~~ neg] | _ => if neg then [:: ([::], [::])] else [::] end%T where "[ 'rec' f , neg ]" := (qf_to_dnf f neg). (* Conversely, transforms a DNF into a formula *) Definition dnf_to_form := let pos_lit t := And (t == 0) in let neg_lit t := And (t != 0) in let cls bc := Or (foldr pos_lit True bc.1 /\ foldr neg_lit True bc.2) in foldr cls False. (* Catenation of dnf is the Or of formulas *) Lemma cat_dnfP e bcs1 bcs2 : qf_eval e (dnf_to_form (bcs1 ++ bcs2)) = qf_eval e (dnf_to_form bcs1 \/ dnf_to_form bcs2). Proof. by elim: bcs1 => //= bc1 bcs1 IH1; rewrite -orbA; congr orb; rewrite IH1. Qed. (* and_dnf is the And of formulas *) Lemma and_dnfP e bcs1 bcs2 : qf_eval e (dnf_to_form (and_dnf bcs1 bcs2)) = qf_eval e (dnf_to_form bcs1 /\ dnf_to_form bcs2). Proof. elim: bcs1 => [|bc1 bcs1 IH1] /=; first by rewrite /and_dnf big_nil. rewrite /and_dnf big_cons -/(and_dnf bcs1 bcs2) cat_dnfP /=. rewrite {}IH1 /= andb_orl; congr orb. elim: bcs2 bc1 {bcs1} => [|bc2 bcs2 IH] bc1 /=; first by rewrite andbF. rewrite {}IH /= andb_orr; congr orb => {bcs2}. suffices aux (l1 l2 : seq (term R)) g : let redg := foldr (And \o g) True in qf_eval e (redg (l1 ++ l2)) = qf_eval e (redg l1 /\ redg l2)%T. + by rewrite 2!aux /= 2!andbA -andbA -andbCA andbA andbCA andbA. by elim: l1 => [| t1 l1 IHl1] //=; rewrite -andbA IHl1. Qed. Lemma qf_to_dnfP e : let qev f b := qf_eval e (dnf_to_form (qf_to_dnf f b)) in forall f, qf_form f && rformula f -> qev f false = qf_eval e f. Proof. move=> qev; have qevT f: qev f true = ~~ qev f false. rewrite {}/qev; elim: f => //=; do [by case | move=> f1 IH1 f2 IH2 | ]. - by move=> t1 t2; rewrite !andbT !orbF. - by rewrite and_dnfP cat_dnfP negb_and -IH1 -IH2. - by rewrite and_dnfP cat_dnfP negb_or -IH1 -IH2. - by rewrite and_dnfP cat_dnfP /= negb_or IH1 -IH2 negbK. by move=> t1 ->; rewrite negbK. rewrite /qev; elim=> //=; first by case. - by move=> t1 t2 _; rewrite subr_eq0 !andbT orbF. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite and_dnfP /= => /IH1-> /IH2->. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite cat_dnfP /= => /IH1-> => /IH2->. - move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP. by rewrite cat_dnfP /= [qf_eval _ _]qevT -implybE => /IH1 <- /IH2->. by move=> f1 IH1 /IH1 <-; rewrite -qevT. Qed. Lemma dnf_to_form_qf bcs : qf_form (dnf_to_form bcs). Proof. by elim: bcs => //= [[clT clF] _ ->] /=; elim: clT => //=; elim: clF. Qed. Definition dnf_rterm cl := all rterm cl.1 && all rterm cl.2. Lemma qf_to_dnf_rterm f b : rformula f -> all dnf_rterm (qf_to_dnf f b). Proof. set ok := all dnf_rterm. have cat_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (bcs1 ++ bcs2). by move=> ok1 ok2; rewrite [ok _]all_cat; apply/andP. have and_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (and_dnf bcs1 bcs2). rewrite /and_dnf unlock; elim: bcs1 => //= cl1 bcs1 IH1; rewrite -andbA. case/and3P=> ok11 ok12 ok1 ok2; rewrite cat_ok ?{}IH1 {bcs1 ok1}//. elim: bcs2 ok2 => //= cl2 bcs2 IH2 /andP[ok2 /IH2->]. by rewrite /dnf_rterm !all_cat ok11 ok12 /= !andbT. elim: f b => //=; [ by do 2!case | | | | | by auto | | ]; try by repeat case/andP || intro; case: ifP; auto. by rewrite /dnf_rterm => ?? [] /= ->. Qed. Lemma dnf_to_rform bcs : rformula (dnf_to_form bcs) = all dnf_rterm bcs. Proof. elim: bcs => //= [[cl1 cl2] bcs ->]; rewrite {2}/dnf_rterm /=; congr (_ && _). by (congr andb; [elim: cl1 | elim: cl2]) => //= t cl ->; rewrite andbT. Qed. Section If. Variables (pred_f then_f else_f : formula R). Definition If := (pred_f /\ then_f \/ ~ pred_f /\ else_f)%T. Lemma If_form_qf : qf_form pred_f -> qf_form then_f -> qf_form else_f -> qf_form If. Proof. by move=> /= -> -> ->. Qed. Lemma If_form_rf : rformula pred_f -> rformula then_f -> rformula else_f -> rformula If. Proof. by move=> /= -> -> ->. Qed. Lemma eval_If e : let ev := qf_eval e in ev If = (if ev pred_f then ev then_f else ev else_f). Proof. by rewrite /=; case: ifP => _; rewrite ?orbF. Qed. End If. Section Pick. Variables (I : finType) (pred_f then_f : I -> formula R) (else_f : formula R). Definition Pick := \big[Or/False]_(p : {ffun pred I}) ((\big[And/True]_i (if p i then pred_f i else ~ pred_f i)) /\ (if pick p is Some i then then_f i else else_f))%T. Lemma Pick_form_qf : (forall i, qf_form (pred_f i)) -> (forall i, qf_form (then_f i)) -> qf_form else_f -> qf_form Pick. Proof. move=> qfp qft qfe; have mA := (big_morph qf_form) true andb. rewrite mA // big1 //= => p _. rewrite mA // big1 => [|i _]; first by case: pick. by rewrite fun_if if_same /= qfp. Qed. Lemma eval_Pick e (qev := qf_eval e) : let P i := qev (pred_f i) in qev Pick = (if pick P is Some i then qev (then_f i) else qev else_f). Proof. move=> P; rewrite ((big_morph qev) false orb) //= big_orE /=. apply/existsP/idP=> [[p] | true_at_P]. rewrite ((big_morph qev) true andb) //= big_andE /=. case/andP=> /forallP-eq_p_P. rewrite (@eq_pick _ _ P) => [|i]; first by case: pick. by move/(_ i): eq_p_P => /=; case: (p i) => //= /negPf. exists [ffun i => P i] => /=; apply/andP; split. rewrite ((big_morph qev) true andb) //= big_andE /=. by apply/forallP=> i; rewrite /= ffunE; case Pi: (P i) => //=; apply: negbT. rewrite (@eq_pick _ _ P) => [|i]; first by case: pick true_at_P. by rewrite ffunE. Qed. End Pick. Section MultiQuant. Variable f : formula R. Implicit Types (I : seq nat) (e : seq R). Lemma foldExistsP I e : (exists2 e', {in [predC I], same_env e e'} & holds e' f) <-> holds e (foldr Exists f I). Proof. elim: I e => /= [|i I IHi] e. by split=> [[e' eq_e] |]; [apply: eq_holds => i; rewrite eq_e | exists e]. split=> [[e' eq_e f_e'] | [x]]; last set e_x := set_nth 0 e i x. exists e'`_i; apply/IHi; exists e' => // j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->. case/IHi=> e' eq_e f_e'; exists e' => // j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP. Qed. Lemma foldForallP I e : (forall e', {in [predC I], same_env e e'} -> holds e' f) <-> holds e (foldr Forall f I). Proof. elim: I e => /= [|i I IHi] e. by split=> [|f_e e' eq_e]; [apply | apply: eq_holds f_e => i; rewrite eq_e]. split=> [f_e' x | f_e e' eq_e]; first set e_x := set_nth 0 e i x. apply/IHi=> e' eq_e; apply: f_e' => j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP. move/IHi: (f_e e'`_i); apply=> j. by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->. Qed. End MultiQuant. End EvalTerm. Prenex Implicits dnf_rterm. Definition integral_domain_axiom (R : pzRingType) := forall x y : R, x * y = 0 -> (x == 0) || (y == 0). HB.mixin Record ComUnitRing_isIntegral R of ComUnitRing R := { mulf_eq0_subproof : integral_domain_axiom R; }. #[mathcomp(axiom="integral_domain_axiom"), short(type="idomainType")] HB.structure Definition IntegralDomain := {R of ComUnitRing_isIntegral R & ComUnitRing R}. Module IntegralDomainExports. Bind Scope ring_scope with IntegralDomain.sort. End IntegralDomainExports. HB.export IntegralDomainExports. Section IntegralDomainTheory. Variable R : idomainType. Implicit Types x y : R. Lemma mulf_eq0 x y : (x * y == 0) = (x == 0) || (y == 0). Proof. apply/eqP/idP; first exact: mulf_eq0_subproof. by case/pred2P=> ->; rewrite (mulr0, mul0r). Qed. Lemma prodf_eq0 (I : finType) (P : pred I) (F : I -> R) : reflect (exists2 i, P i & (F i == 0)) (\prod_(i | P i) F i == 0). Proof. apply: (iffP idP) => [|[i Pi /eqP Fi0]]; last first. by rewrite (bigD1 i) //= Fi0 mul0r. elim: (index_enum _) => [|i r IHr]; first by rewrite big_nil oner_eq0. rewrite big_cons /=; have [Pi | _] := ifP; last exact: IHr. by rewrite mulf_eq0; case/orP=> // Fi0; exists i. Qed. Lemma prodf_seq_eq0 I r (P : pred I) (F : I -> R) : (\prod_(i <- r | P i) F i == 0) = has (fun i => P i && (F i == 0)) r. Proof. by rewrite (big_morph _ mulf_eq0 (oner_eq0 _)) big_has_cond. Qed. Lemma mulf_neq0 x y : x != 0 -> y != 0 -> x * y != 0. Proof. by move=> x0 y0; rewrite mulf_eq0; apply/norP. Qed. Lemma prodf_neq0 (I : finType) (P : pred I) (F : I -> R) : reflect (forall i, P i -> (F i != 0)) (\prod_(i | P i) F i != 0). Proof. by rewrite (sameP (prodf_eq0 _ _) exists_inP); apply: exists_inPn. Qed. Lemma prodf_seq_neq0 I r (P : pred I) (F : I -> R) : (\prod_(i <- r | P i) F i != 0) = all (fun i => P i ==> (F i != 0)) r. Proof. rewrite prodf_seq_eq0 -all_predC; apply: eq_all => i /=. by rewrite implybE negb_and. Qed. Lemma expf_eq0 x n : (x ^+ n == 0) = (n > 0) && (x == 0). Proof. elim: n => [|n IHn]; first by rewrite oner_eq0. by rewrite exprS mulf_eq0 IHn andKb. Qed. Lemma sqrf_eq0 x : (x ^+ 2 == 0) = (x == 0). Proof. exact: expf_eq0. Qed. Lemma expf_neq0 x m : x != 0 -> x ^+ m != 0. Proof. by move=> x_nz; rewrite expf_eq0; apply/nandP; right. Qed. Lemma natf_neq0_pchar n : (n%:R != 0 :> R) = (pchar R)^'.-nat n. Proof. have [-> | /prod_prime_decomp->] := posnP n; first by rewrite eqxx. rewrite !big_seq; elim/big_rec: _ => [|[p e] s /=]; first by rewrite oner_eq0. case/mem_prime_decomp=> p_pr _ _; rewrite pnatM pnatX eqn0Ngt orbC => <-. by rewrite natrM natrX mulf_eq0 expf_eq0 negb_or negb_and pnatE ?inE p_pr. Qed. Lemma natf0_pchar n : n > 0 -> n%:R == 0 :> R -> exists p, p \in pchar R. Proof. move=> n_gt0 nR_0; exists (pdiv n`_(pchar R)). apply: pnatP (pdiv_dvd _); rewrite ?part_pnat // ?pdiv_prime //. by rewrite ltn_neqAle eq_sym partn_eq1 // -natf_neq0_pchar nR_0 /=. Qed. Lemma pcharf'_nat n : (pchar R)^'.-nat n = (n%:R != 0 :> R). Proof. have [-> | n_gt0] := posnP n; first by rewrite eqxx. apply/idP/idP => [|nz_n]; last first. by apply/pnatP=> // p p_pr p_dvd_n; apply: contra nz_n => /dvdn_pcharf <-. apply: contraL => n0; have [// | p pcharRp] := natf0_pchar _ n0. have [p_pr _] := andP pcharRp; rewrite (eq_pnat _ (eq_negn (pcharf_eq pcharRp))). by rewrite p'natE // (dvdn_pcharf pcharRp) n0. Qed. Lemma pcharf0P : pchar R =i pred0 <-> (forall n, (n%:R == 0 :> R) = (n == 0)%N). Proof. split=> pcharF0 n; last by rewrite !inE pcharF0 andbC; case: eqP => // ->. have [-> | n_gt0] := posnP; first exact: eqxx. by apply/negP; case/natf0_pchar=> // p; rewrite pcharF0. Qed. Lemma eqf_sqr x y : (x ^+ 2 == y ^+ 2) = (x == y) || (x == - y). Proof. by rewrite -subr_eq0 subr_sqr mulf_eq0 subr_eq0 addr_eq0. Qed. Lemma mulfI x : x != 0 -> injective ( *%R x). Proof. move=> nz_x y z; apply: contra_eq => neq_yz. by rewrite -subr_eq0 -mulrBr mulf_neq0 ?subr_eq0. Qed. Lemma mulIf x : x != 0 -> injective ( *%R^~ x). Proof. by move=> nz_x y z; rewrite -!(mulrC x); apply: mulfI. Qed. Lemma divfI x : x != 0 -> injective (fun y => x / y). Proof. by move/mulfI/inj_comp; apply; apply: invr_inj. Qed. Lemma divIf y : y != 0 -> injective (fun x => x / y). Proof. by rewrite -invr_eq0; apply: mulIf. Qed. Lemma sqrf_eq1 x : (x ^+ 2 == 1) = (x == 1) || (x == -1). Proof. by rewrite -subr_eq0 subr_sqr_1 mulf_eq0 subr_eq0 addr_eq0. Qed. Lemma expfS_eq1 x n : (x ^+ n.+1 == 1) = (x == 1) || (\sum_(i < n.+1) x ^+ i == 0). Proof. by rewrite -![_ == 1]subr_eq0 subrX1 mulf_eq0. Qed. Lemma lregP x : reflect (lreg x) (x != 0). Proof. by apply: (iffP idP) => [/mulfI | /lreg_neq0]. Qed. Lemma rregP x : reflect (rreg x) (x != 0). Proof. by apply: (iffP idP) => [/mulIf | /rreg_neq0]. Qed. #[export] HB.instance Definition _ := IntegralDomain.on R^o. End IntegralDomainTheory. #[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")] Notation natf_neq0 := natf_neq0_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")] Notation natf0_char := natf0_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")] Notation charf'_nat := pcharf'_nat (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")] Notation charf0P := pcharf0P (only parsing). Arguments lregP {R x}. Arguments rregP {R x}. Definition field_axiom (R : unitRingType) := forall x : R, x != 0 -> x \in unit. HB.mixin Record UnitRing_isField R of UnitRing R := { fieldP : field_axiom R; }. #[mathcomp(axiom="field_axiom"), short(type="fieldType")] HB.structure Definition Field := { R of IntegralDomain R & UnitRing_isField R }. Module FieldExports. Bind Scope ring_scope with Field.sort. End FieldExports. HB.export FieldExports. #[export] HB.instance Definition regular_field (F : fieldType) := Field.on F^o. Lemma IdomainMixin (R : unitRingType): Field.axiom R -> IntegralDomain.axiom R. Proof. move=> m x y xy0; apply/norP=> [[]] /m Ux /m. by rewrite -(unitrMr _ Ux) xy0 unitr0. Qed. HB.factory Record ComUnitRing_isField R of ComUnitRing R := { fieldP : field_axiom R; }. HB.builders Context R of ComUnitRing_isField R. HB.instance Definition _ := ComUnitRing_isIntegral.Build R (IdomainMixin fieldP). HB.instance Definition _ := UnitRing_isField.Build R fieldP. HB.end. HB.factory Record ComNzRing_isField R of ComNzRing R := { inv : R -> R; mulVf : forall x, x != 0 -> inv x * x = 1; invr0 : inv 0 = 0; }. Module ComRing_isField. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_isField.Build instead.")] Notation Build R := (ComNzRing_isField.Build R) (only parsing). End ComRing_isField. #[deprecated(since="mathcomp 2.4.0", note="Use ComNzRing_isField instead.")] Notation ComRing_isField R := (ComNzRing_isField R) (only parsing). HB.builders Context R of ComNzRing_isField R. Fact intro_unit (x y : R) : y * x = 1 -> x != 0. Proof. move=> yx1; apply: contraNneq (@oner_neq0 R) => x0. by rewrite -yx1 x0 mulr0. Qed. Fact inv_out : {in predC (predC1 0), inv =1 id}. Proof. by move=> x /negbNE/eqP->; exact: invr0. Qed. HB.instance Definition _ : ComNzRing_hasMulInverse R := ComNzRing_hasMulInverse.Build R mulVf intro_unit inv_out. HB.instance Definition _ : ComUnitRing_isField R := ComUnitRing_isField.Build R (fun x x_neq_0 => x_neq_0). HB.end. Section FieldTheory. Variable F : fieldType. Implicit Types x y : F. Lemma unitfE x : (x \in unit) = (x != 0). Proof. by apply/idP/idP=> [/(memPn _)-> | /fieldP]; rewrite ?unitr0. Qed. Lemma mulVf x : x != 0 -> x^-1 * x = 1. Proof. by rewrite -unitfE; apply: mulVr. Qed. Lemma divff x : x != 0 -> x / x = 1. Proof. by rewrite -unitfE; apply: divrr. Qed. Definition mulfV := divff. Lemma mulKf x : x != 0 -> cancel ( *%R x) ( *%R x^-1). Proof. by rewrite -unitfE; apply: mulKr. Qed. Lemma mulVKf x : x != 0 -> cancel ( *%R x^-1) ( *%R x). Proof. by rewrite -unitfE; apply: mulVKr. Qed. Lemma mulfK x : x != 0 -> cancel ( *%R^~ x) ( *%R^~ x^-1). Proof. by rewrite -unitfE; apply: mulrK. Qed. Lemma mulfVK x : x != 0 -> cancel ( *%R^~ x^-1) ( *%R^~ x). Proof. by rewrite -unitfE; apply: divrK. Qed. Definition divfK := mulfVK. Lemma invfM : {morph @inv F : x y / x * y}. Proof. move=> x y; have [->|nzx] := eqVneq x 0; first by rewrite !(mul0r, invr0). have [->|nzy] := eqVneq y 0; first by rewrite !(mulr0, invr0). by rewrite mulrC invrM ?unitfE. Qed. Lemma invf_div x y : (x / y)^-1 = y / x. Proof. by rewrite invfM invrK mulrC. Qed. Lemma divKf x : x != 0 -> involutive (fun y => x / y). Proof. by move=> nz_x y; rewrite invf_div mulrC divfK. Qed. Lemma expfB_cond m n x : (x == 0) + n <= m -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. move/subnK=> <-; rewrite addnA addnK !exprD. have [-> | nz_x] := eqVneq; first by rewrite !mulr0 !mul0r. by rewrite mulfK ?expf_neq0. Qed. Lemma expfB m n x : n < m -> x ^+ (m - n) = x ^+ m / x ^+ n. Proof. by move=> lt_n_m; apply: expfB_cond; case: eqP => // _; apply: ltnW. Qed. Lemma prodfV I r (P : pred I) (E : I -> F) : \prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1. Proof. by rewrite (big_morph _ invfM (invr1 F)). Qed. Lemma prodf_div I r (P : pred I) (E D : I -> F) : \prod_(i <- r | P i) (E i / D i) = \prod_(i <- r | P i) E i / \prod_(i <- r | P i) D i. Proof. by rewrite big_split prodfV. Qed. Lemma telescope_prodf n m (f : nat -> F) : (forall k, n < k < m -> f k != 0) -> n < m -> \prod_(n <= k < m) (f k.+1 / f k) = f m / f n. Proof. move=> nz_f ltnm; apply: invr_inj; rewrite prodf_div !invf_div -prodf_div. by apply: telescope_prodr => // k /nz_f; rewrite unitfE. Qed. Lemma telescope_prodf_eq n m (f u : nat -> F) : (forall k, n < k < m -> f k != 0) -> n < m -> (forall k, n <= k < m -> u k = f k.+1 / f k) -> \prod_(n <= k < m) u k = f m / f n. Proof. by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodf. Qed. Lemma addf_div x1 y1 x2 y2 : y1 != 0 -> y2 != 0 -> x1 / y1 + x2 / y2 = (x1 * y2 + x2 * y1) / (y1 * y2). Proof. by move=> nzy1 nzy2; rewrite invfM mulrDl !mulrA mulrAC !mulfK. Qed. Lemma mulf_div x1 y1 x2 y2 : (x1 / y1) * (x2 / y2) = (x1 * x2) / (y1 * y2). Proof. by rewrite mulrACA -invfM. Qed. Lemma eqr_div x y z t : y != 0 -> t != 0 -> (x / y == z / t) = (x * t == z * y). Proof. move=> yD0 tD0; rewrite -[x in RHS](divfK yD0) -[z in RHS](divfK tD0) mulrAC. by apply/eqP/eqP => [->|/(mulIf yD0)/(mulIf tD0)]. Qed. Lemma eqr_sum_div I r P (f : I -> F) c a : c != 0 -> \big[+%R/0]_(x <- r | P x) (f x / c) == a = (\big[+%R/0]_(x <- r | P x) f x == a * c). Proof. by move=> ?; rewrite -mulr_suml -(divr1 a) eqr_div ?oner_eq0// mulr1 divr1. Qed. Lemma pchar0_natf_div : pchar F =i pred0 -> forall m d, d %| m -> (m %/ d)%:R = m%:R / d%:R :> F. Proof. move/pcharf0P=> pchar0F m [|d] d_dv_m; first by rewrite divn0 invr0 mulr0. by rewrite natr_div // unitfE pchar0F. Qed. Section FieldMorphismInj. Variables (R : nzRingType) (f : {rmorphism F -> R}). Lemma fmorph_eq0 x : (f x == 0) = (x == 0). Proof. have [-> | nz_x] := eqVneq x; first by rewrite rmorph0 eqxx. apply/eqP; move/(congr1 ( *%R (f x^-1)))/eqP. by rewrite -rmorphM mulVf // mulr0 rmorph1 ?oner_eq0. Qed. Lemma fmorph_inj : injective f. Proof. by apply/raddf_inj => x /eqP; rewrite fmorph_eq0 => /eqP. Qed. Lemma fmorph_eq : {mono f : x y / x == y}. Proof. exact: inj_eq fmorph_inj. Qed. Lemma fmorph_eq1 x : (f x == 1) = (x == 1). Proof. by rewrite -(inj_eq fmorph_inj) rmorph1. Qed. Lemma fmorph_pchar : pchar R =i pchar F. Proof. by move=> p; rewrite !inE -fmorph_eq0 rmorph_nat. Qed. End FieldMorphismInj. Section FieldMorphismInv. Variables (R : unitRingType) (f : {rmorphism F -> R}). Lemma fmorph_unit x : (f x \in unit) = (x != 0). Proof. have [-> |] := eqVneq x; first by rewrite rmorph0 unitr0. by rewrite -unitfE; apply: rmorph_unit. Qed. Lemma fmorphV : {morph f: x / x^-1}. Proof. move=> x; have [-> | nz_x] := eqVneq x 0; first by rewrite !(invr0, rmorph0). by rewrite rmorphV ?unitfE. Qed. Lemma fmorph_div : {morph f : x y / x / y}. Proof. by move=> x y; rewrite rmorphM /= fmorphV. Qed. End FieldMorphismInv. Section ModuleTheory. Variable V : lmodType F. Implicit Types (a : F) (v : V). Lemma scalerK a : a != 0 -> cancel ( *:%R a : V -> V) ( *:%R a^-1). Proof. by move=> nz_a v; rewrite scalerA mulVf // scale1r. Qed. Lemma scalerKV a : a != 0 -> cancel ( *:%R a^-1 : V -> V) ( *:%R a). Proof. by rewrite -invr_eq0 -{3}[a]invrK; apply: scalerK. Qed. Lemma scalerI a : a != 0 -> injective ( *:%R a : V -> V). Proof. by move=> nz_a; apply: can_inj (scalerK nz_a). Qed. Lemma scaler_eq0 a v : (a *: v == 0) = (a == 0) || (v == 0). Proof. have [-> | nz_a] := eqVneq a; first by rewrite scale0r eqxx. by rewrite (can2_eq (scalerK nz_a) (scalerKV nz_a)) scaler0. Qed. End ModuleTheory. Lemma pchar_lalg (A : lalgType F) : pchar A =i pchar F. Proof. by move=> p; rewrite inE -scaler_nat scaler_eq0 oner_eq0 orbF. Qed. End FieldTheory. #[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")] Notation char0_natf_div := pchar0_natf_div (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")] Notation fmorph_char := fmorph_pchar (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")] Notation char_lalg := pchar_lalg (only parsing). Arguments fmorph_inj {F R} f [x1 x2]. Arguments telescope_prodf_eq {F n m} f u. Definition decidable_field_axiom (R : unitRingType) (s : seq R -> pred (formula R)) := forall e f, reflect (holds e f) (s e f). HB.mixin Record Field_isDecField R of UnitRing R := { sat : seq R -> pred (formula R); satP : decidable_field_axiom sat; }. #[mathcomp(axiom="decidable_field_axiom"), short(type="decFieldType")] HB.structure Definition DecidableField := { F of Field F & Field_isDecField F }. Module DecFieldExports. Bind Scope ring_scope with DecidableField.sort. End DecFieldExports. HB.export DecFieldExports. #[export] HB.instance Definition _ (F : decFieldType) := DecidableField.on F^o. Section DecidableFieldTheory. Variable F : decFieldType. Implicit Type f : formula F. Fact sol_subproof n f : reflect (exists s, (size s == n) && sat s f) (sat [::] (foldr Exists f (iota 0 n))). Proof. apply: (iffP (satP _ _)) => [|[s]]; last first. case/andP=> /eqP sz_s /satP f_s; apply/foldExistsP. exists s => // i; rewrite !inE mem_iota -leqNgt add0n => le_n_i. by rewrite !nth_default ?sz_s. case/foldExistsP=> e e0 f_e; set s := take n (set_nth 0 e n 0). have sz_s: size s = n by rewrite size_take size_set_nth leq_max leqnn. exists s; rewrite sz_s eqxx; apply/satP; apply: eq_holds f_e => i. case: (leqP n i) => [le_n_i | lt_i_n]. by rewrite -e0 ?nth_default ?sz_s // !inE mem_iota -leqNgt. by rewrite nth_take // nth_set_nth /= eq_sym eqn_leq leqNgt lt_i_n. Qed. Definition sol n f := if sol_subproof n f is ReflectT sP then xchoose sP else nseq n 0. Lemma size_sol n f : size (sol n f) = n. Proof. rewrite /sol; case: sol_subproof => [sP | _]; last exact: size_nseq. by case/andP: (xchooseP sP) => /eqP. Qed. Lemma solP n f : reflect (exists2 s, size s = n & holds s f) (sat (sol n f) f). Proof. rewrite /sol; case: sol_subproof => [sP | sPn]. case/andP: (xchooseP sP) => _ ->; left. by case: sP => s; case/andP; move/eqP=> <-; move/satP; exists s. apply: (iffP (satP _ _)); first by exists (nseq n 0); rewrite ?size_nseq. by case=> s sz_s; move/satP=> f_s; case: sPn; exists s; rewrite sz_s eqxx. Qed. Lemma eq_sat f1 f2 : (forall e, holds e f1 <-> holds e f2) -> sat^~ f1 =1 sat^~ f2. Proof. by move=> eqf12 e; apply/satP/satP; case: (eqf12 e). Qed. Lemma eq_sol f1 f2 : (forall e, holds e f1 <-> holds e f2) -> sol^~ f1 =1 sol^~ f2. Proof. rewrite /sol => /eq_sat eqf12 n. do 2![case: sol_subproof] => //= [f1s f2s | ns1 [s f2s] | [s f1s] []]. - by apply: eq_xchoose => s; rewrite eqf12. - by case: ns1; exists s; rewrite -eqf12. by exists s; rewrite eqf12. Qed. End DecidableFieldTheory. Arguments satP {F e f} : rename. Arguments solP {F n f} : rename. Section QE_Mixin. Variable F : Field.type. Implicit Type f : formula F. Variable proj : nat -> seq (term F) * seq (term F) -> formula F. (* proj is the elimination of a single existential quantifier *) (* The elimination projector is well_formed. *) Definition wf_QE_proj := forall i bc (bc_i := proj i bc), dnf_rterm bc -> qf_form bc_i && rformula bc_i. (* The elimination projector is valid *) Definition valid_QE_proj := forall i bc (ex_i_bc := ('exists 'X_i, dnf_to_form [:: bc])%T) e, dnf_rterm bc -> reflect (holds e ex_i_bc) (qf_eval e (proj i bc)). Hypotheses (wf_proj : wf_QE_proj) (ok_proj : valid_QE_proj). Let elim_aux f n := foldr Or False (map (proj n) (qf_to_dnf f false)). Fixpoint quantifier_elim f := match f with | f1 /\ f2 => (quantifier_elim f1) /\ (quantifier_elim f2) | f1 \/ f2 => (quantifier_elim f1) \/ (quantifier_elim f2) | f1 ==> f2 => (~ quantifier_elim f1) \/ (quantifier_elim f2) | ~ f => ~ quantifier_elim f | ('exists 'X_n, f) => elim_aux (quantifier_elim f) n | ('forall 'X_n, f) => ~ elim_aux (~ quantifier_elim f) n | _ => f end%T. Lemma quantifier_elim_wf f : let qf := quantifier_elim f in rformula f -> qf_form qf && rformula qf. Proof. suffices aux_wf f0 n : let qf := elim_aux f0 n in rformula f0 -> qf_form qf && rformula qf. - by elim: f => //=; do ?[ move=> f1 IH1 f2 IH2; case/andP=> rf1 rf2; case/andP:(IH1 rf1)=> -> ->; case/andP:(IH2 rf2)=> -> -> // | move=> n f1 IH rf1; case/andP: (IH rf1)=> qff rf; rewrite aux_wf ]. rewrite /elim_aux => rf. suffices or_wf fs : let ofs := foldr Or False fs in all (@qf_form F) fs && all (@rformula F) fs -> qf_form ofs && rformula ofs. - apply: or_wf. suffices map_proj_wf bcs: let mbcs := map (proj n) bcs in all dnf_rterm bcs -> all (@qf_form _) mbcs && all (@rformula _) mbcs. by apply/map_proj_wf/qf_to_dnf_rterm. elim: bcs => [|bc bcs ihb] bcsr //= /andP[rbc rbcs]. by rewrite andbAC andbA wf_proj //= andbC ihb. elim: fs => //= g gs ihg; rewrite -andbA => /and4P[-> qgs -> rgs] /=. by apply: ihg; rewrite qgs rgs. Qed. Lemma quantifier_elim_rformP e f : rformula f -> reflect (holds e f) (qf_eval e (quantifier_elim f)). Proof. pose rc e n f := exists x, qf_eval (set_nth 0 e n x) f. have auxP f0 e0 n0: qf_form f0 && rformula f0 -> reflect (rc e0 n0 f0) (qf_eval e0 (elim_aux f0 n0)). + rewrite /elim_aux => cf; set bcs := qf_to_dnf f0 false. apply: (@iffP (rc e0 n0 (dnf_to_form bcs))); last first. - by case=> x; rewrite -qf_to_dnfP //; exists x. - by case=> x; rewrite qf_to_dnfP //; exists x. have: all dnf_rterm bcs by case/andP: cf => _; apply: qf_to_dnf_rterm. elim: {f0 cf}bcs => [|bc bcs IHbcs] /=; first by right; case. case/andP=> r_bc /IHbcs {IHbcs}bcsP. have f_qf := dnf_to_form_qf [:: bc]. case: ok_proj => //= [ex_x|no_x]. left; case: ex_x => x /(qf_evalP _ f_qf); rewrite /= orbF => bc_x. by exists x; rewrite /= bc_x. apply: (iffP bcsP) => [[x bcs_x] | [x]] /=. by exists x; rewrite /= bcs_x orbT. case/orP => [bc_x|]; last by exists x. by case: no_x; exists x; apply/(qf_evalP _ f_qf); rewrite /= bc_x. elim: f e => //. - by move=> b e _; apply: idP. - by move=> t1 t2 e _; apply: eqP. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by right; case. by case/IH2; [left | right; case]. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; first by do 2!left. by case/IH2; [left; right | right; case]. - move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by left. by case/IH2; [left | right; move/(_ f1e)]. - by move=> f IHf e /= /IHf[]; [right | left]. - move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf. by apply: (iffP (auxP _ _ _ rqf)) => [] [x]; exists x; apply/IHf. move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf. case: auxP => // [f_x|no_x]; first by right=> no_x; case: f_x => x /IHf[]. by left=> x; apply/IHf=> //; apply/idPn=> f_x; case: no_x; exists x. Qed. Definition proj_sat e f := qf_eval e (quantifier_elim (to_rform f)). Lemma proj_satP : DecidableField.axiom proj_sat. Proof. move=> e f; have fP := quantifier_elim_rformP e (to_rform_rformula f). by apply: (iffP fP); move/to_rformP. Qed. End QE_Mixin. HB.factory Record Field_QE_isDecField F of Field F := { proj : nat -> seq (term F) * seq (term F) -> formula F; wf_proj : wf_QE_proj proj; ok_proj : valid_QE_proj proj; }. HB.builders Context F of Field_QE_isDecField F. HB.instance Definition qe_is_def_field : Field_isDecField F := Field_isDecField.Build F (proj_satP wf_proj ok_proj). HB.end. (* Axiom == all non-constant monic polynomials have a root *) Definition closed_field_axiom (R : pzRingType) := forall n (P : nat -> R), n > 0 -> exists x : R, x ^+ n = \sum_(i < n) P i * (x ^+ i). HB.mixin Record DecField_isAlgClosed F of DecidableField F := { solve_monicpoly : closed_field_axiom F; }. #[mathcomp(axiom="closed_field_axiom"), short(type="closedFieldType")] HB.structure Definition ClosedField := { F of DecidableField F & DecField_isAlgClosed F }. Module ClosedFieldExports. Bind Scope ring_scope with ClosedField.sort. End ClosedFieldExports. HB.export ClosedFieldExports. #[export] HB.instance Definition _ (F : closedFieldType) := ClosedField.on F^o. Section ClosedFieldTheory. Variable F : closedFieldType. Lemma imaginary_exists : {i : F | i ^+ 2 = -1}. Proof. have /sig_eqW[i Di2] := @solve_monicpoly F 2 (nth 0 [:: -1]) isT. by exists i; rewrite Di2 !big_ord_recl big_ord0 mul0r mulr1 !addr0. Qed. End ClosedFieldTheory. Lemma lalgMixin (R : pzRingType) (A : lalgType R) (B : lmodType R) (f : B -> A) : phant B -> injective f -> scalable f -> forall mulB, {morph f : x y / mulB x y >-> x * y} -> forall a u v, a *: (mulB u v) = mulB (a *: u) v. Proof. by move=> _ injf fZ mulB fM a x y; apply: injf; rewrite !(fZ, fM) scalerAl. Qed. Lemma comRingMixin (R : comPzRingType) (T : pzRingType) (f : T -> R) : phant T -> injective f -> {morph f : x y / x * y} -> commutative (@mul T). Proof. by move=> _ inj_f fM x y; apply: inj_f; rewrite !fM mulrC. Qed. Lemma algMixin (R : pzRingType) (A : algType R) (B : lalgType R) (f : B -> A) : phant B -> injective f -> {morph f : x y / x * y} -> scalable f -> forall k (x y : B), k *: (x * y) = x * (k *: y). Proof. by move=> _ inj_f fM fZ a x y; apply: inj_f; rewrite !(fM, fZ) scalerAr. Qed. (* Mixins for stability properties *) HB.mixin Record isMul2Closed (R : pzSemiRingType) (S : {pred R}) := { rpredM : mulr_2closed S }. HB.mixin Record isMul1Closed (R : pzSemiRingType) (S : {pred R}) := { rpred1 : 1 \in S }. HB.mixin Record isInvClosed (R : unitRingType) (S : {pred R}) := { rpredVr : invr_closed S }. HB.mixin Record isScaleClosed (R : pzSemiRingType) (V : lSemiModType R) (S : {pred V}) := { rpredZ : scaler_closed S }. (* Structures for stability properties *) Local Notation addrClosed := addrClosed. Local Notation opprClosed := opprClosed. #[short(type="mulr2Closed")] HB.structure Definition Mul2Closed (R : pzSemiRingType) := {S of isMul2Closed R S}. #[short(type="mulrClosed")] HB.structure Definition MulClosed (R : pzSemiRingType) := {S of Mul2Closed R S & isMul1Closed R S}. #[short(type="semiring2Closed")] HB.structure Definition Semiring2Closed (R : pzSemiRingType) := {S of AddClosed R S & Mul2Closed R S}. #[short(type="semiringClosed")] HB.structure Definition SemiringClosed (R : pzSemiRingType) := {S of AddClosed R S & MulClosed R S}. #[short(type="smulClosed")] HB.structure Definition SmulClosed (R : pzRingType) := {S of OppClosed R S & MulClosed R S}. #[short(type="subringClosed")] HB.structure Definition SubringClosed (R : pzRingType) := {S of ZmodClosed R S & MulClosed R S}. #[short(type="divClosed")] HB.structure Definition DivClosed (R : unitRingType) := {S of MulClosed R S & isInvClosed R S}. #[short(type="sdivClosed")] HB.structure Definition SdivClosed (R : unitRingType) := {S of SmulClosed R S & isInvClosed R S}. #[short(type="submodClosed")] HB.structure Definition SubmodClosed (R : pzSemiRingType) (V : lSemiModType R) := {S of AddClosed V S & isScaleClosed R V S}. #[short(type="subalgClosed")] HB.structure Definition SubalgClosed (R : pzSemiRingType) (A : lSemiAlgType R) := {S of SemiringClosed A S & isScaleClosed R A S}. #[short(type="divringClosed")] HB.structure Definition DivringClosed (R : unitRingType) := {S of SubringClosed R S & isInvClosed R S}. #[short(type="divalgClosed")] HB.structure Definition DivalgClosed (R : pzRingType) (A : unitAlgType R) := {S of DivringClosed A S & isScaleClosed R A S}. (* Factories for stability properties *) HB.factory Record isMulClosed (R : pzSemiRingType) (S : {pred R}) := { rpred1M : mulr_closed S }. HB.builders Context R S of isMulClosed R S. HB.instance Definition _ := isMul2Closed.Build R S (proj2 rpred1M). HB.instance Definition _ := isMul1Closed.Build R S (proj1 rpred1M). HB.end. HB.factory Record isSmulClosed (R : pzRingType) (S : R -> bool) := { smulr_closed_subproof : smulr_closed S }. HB.builders Context R S of isSmulClosed R S. HB.instance Definition _ := isMulClosed.Build R S (smulr_closedM smulr_closed_subproof). HB.instance Definition _ := isOppClosed.Build R S (smulr_closedN smulr_closed_subproof). HB.end. HB.factory Record isSemiringClosed (R : pzSemiRingType) (S : R -> bool) := { semiring_closed_subproof : semiring_closed S }. HB.builders Context R S of isSemiringClosed R S. HB.instance Definition _ := isAddClosed.Build R S (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := isMulClosed.Build R S (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record isSubringClosed (R : pzRingType) (S : R -> bool) := { subring_closed_subproof : subring_closed S }. HB.builders Context R S of isSubringClosed R S. HB.instance Definition _ := isZmodClosed.Build R S (subring_closedB subring_closed_subproof). HB.instance Definition _ := isSmulClosed.Build R S (subring_closedM subring_closed_subproof). HB.end. HB.factory Record isDivClosed (R : unitRingType) (S : R -> bool) := { divr_closed_subproof : divr_closed S }. HB.builders Context R S of isDivClosed R S. HB.instance Definition _ := isMulClosed.Build R S (divr_closedM divr_closed_subproof). HB.instance Definition _ := isInvClosed.Build R S (divr_closedV divr_closed_subproof). HB.end. HB.factory Record isSdivClosed (R : unitRingType) (S : R -> bool) := { sdivr_closed_subproof : sdivr_closed S }. HB.builders Context R S of isSdivClosed R S. HB.instance Definition _ := isDivClosed.Build R S (sdivr_closed_div sdivr_closed_subproof). HB.instance Definition _ := isSmulClosed.Build R S (sdivr_closedM sdivr_closed_subproof). HB.end. HB.factory Record isSubSemiModClosed (R : pzSemiRingType) (V : lSemiModType R) (S : V -> bool) := { subsemimod_closed_subproof : subsemimod_closed S }. HB.builders Context R V S of isSubSemiModClosed R V S. HB.instance Definition _ := isAddClosed.Build V S (subsemimod_closedD subsemimod_closed_subproof). HB.instance Definition _ := isScaleClosed.Build R V S (subsemimod_closedZ subsemimod_closed_subproof). HB.end. HB.factory Record isSubmodClosed (R : pzRingType) (V : lmodType R) (S : V -> bool) := { submod_closed_subproof : submod_closed S }. HB.builders Context R V S of isSubmodClosed R V S. HB.instance Definition _ := isZmodClosed.Build V S (submod_closedB submod_closed_subproof). HB.instance Definition _ := isScaleClosed.Build R V S (subsemimod_closedZ (submod_closed_semi submod_closed_subproof)). HB.end. HB.factory Record isSubalgClosed (R : pzRingType) (A : lalgType R) (S : A -> bool) := { subalg_closed_subproof : subalg_closed S }. HB.builders Context R A S of isSubalgClosed R A S. HB.instance Definition _ := isSubmodClosed.Build R A S (subalg_closedZ subalg_closed_subproof). HB.instance Definition _ := isSubringClosed.Build A S (subalg_closedBM subalg_closed_subproof). HB.end. HB.factory Record isDivringClosed (R : unitRingType) (S : R -> bool) := { divring_closed_subproof : divring_closed S }. HB.builders Context R S of isDivringClosed R S. HB.instance Definition _ := isSubringClosed.Build R S (divring_closedBM divring_closed_subproof). HB.instance Definition _ := isSdivClosed.Build R S (divring_closed_div divring_closed_subproof). HB.end. HB.factory Record isDivalgClosed (R : comUnitRingType) (A : unitAlgType R) (S : A -> bool) := { divalg_closed_subproof : divalg_closed S }. HB.builders Context R A S of isDivalgClosed R A S. HB.instance Definition _ := isDivringClosed.Build A S (divalg_closedBdiv divalg_closed_subproof). HB.instance Definition _ := isSubalgClosed.Build R A S (divalg_closedZ divalg_closed_subproof). HB.end. Section NmodulePred. Variables (V : nmodType). Section Add. Variable S : addrClosed V. Lemma rpred0D : nmod_closed S. Proof. exact: nmod_closed_subproof. Qed. End Add. End NmodulePred. Section ZmodulePred. Variables (V : zmodType). Section Opp. Variable S : opprClosed V. End Opp. Section Sub. Variable S : zmodClosed V. Lemma zmodClosedP : zmod_closed S. Proof. split; [ exact: (@rpred0D V S).1 | exact: rpredB ]. Qed. End Sub. End ZmodulePred. Section SemiRingPred. Variables (R : pzSemiRingType). Section Mul. Variable S : mulrClosed R. Lemma rpred1M : mulr_closed S. Proof. exact: (conj rpred1 rpredM). Qed. Lemma rpred_prod I r (P : pred I) F : (forall i, P i -> F i \in S) -> \prod_(i <- r | P i) F i \in S. Proof. by move=> IH; elim/big_ind: _; [apply: rpred1 | apply: rpredM |]. Qed. Lemma rpredX n : {in S, forall u, u ^+ n \in S}. Proof. by move=> u Su; rewrite -(card_ord n) -prodr_const rpred_prod. Qed. End Mul. Lemma rpred_nat (S : semiringClosed R) n : n%:R \in S. Proof. by rewrite rpredMn ?rpred1. Qed. Lemma semiringClosedP (rngS : semiringClosed R) : semiring_closed rngS. Proof. split; [ exact: rpred0D | exact: rpred1M ]. Qed. End SemiRingPred. Section RingPred. Variables (R : pzRingType). Lemma rpredMsign (S : opprClosed R) n x : ((-1) ^+ n * x \in S) = (x \in S). Proof. by rewrite -signr_odd mulr_sign; case: ifP => // _; rewrite rpredN. Qed. Lemma rpredN1 (S : smulClosed R) : -1 \in S. Proof. by rewrite rpredN rpred1. Qed. Lemma rpred_sign (S : smulClosed R) n : (-1) ^+ n \in S. Proof. by rewrite rpredX ?rpredN1. Qed. Lemma subringClosedP (rngS : subringClosed R) : subring_closed rngS. Proof. split; [ exact: rpred1 | exact: (zmodClosedP rngS).2 | exact: rpredM ]. Qed. End RingPred. Section LmodPred. Variables (R : pzSemiRingType) (V : lSemiModType R). Lemma rpredZnat (S : addrClosed V) n : {in S, forall u, n%:R *: u \in S}. Proof. by move=> u Su; rewrite /= scaler_nat rpredMn. Qed. Lemma subsemimodClosedP (modS : submodClosed V) : subsemimod_closed modS. Proof. by split; [exact: rpred0D | exact: rpredZ]. Qed. End LmodPred. Section LmodPred. Variables (R : pzRingType) (V : lmodType R). Lemma rpredZsign (S : opprClosed V) n u : ((-1) ^+ n *: u \in S) = (u \in S). Proof. by rewrite -signr_odd scaler_sign fun_if if_arg rpredN if_same. Qed. Lemma submodClosedP (modS : submodClosed V) : submod_closed modS. Proof. split; first exact (@rpred0D V modS).1. by move=> a u v uS vS; apply: rpredD; first exact: rpredZ. Qed. End LmodPred. Section LalgPred. Variables (R : pzRingType) (A : lalgType R). Lemma subalgClosedP (algS : subalgClosed A) : subalg_closed algS. Proof. split; [ exact: rpred1 | | exact: rpredM ]. by move=> a u v uS vS; apply: rpredD; first exact: rpredZ. Qed. End LalgPred. Section UnitRingPred. Variable R : unitRingType. Section Div. Variable S : divClosed R. Lemma rpredV x : (x^-1 \in S) = (x \in S). Proof. by apply/idP/idP=> /rpredVr; rewrite ?invrK. Qed. Lemma rpred_div : {in S &, forall x y, x / y \in S}. Proof. by move=> x y Sx Sy; rewrite /= rpredM ?rpredV. Qed. Lemma rpredXN n : {in S, forall x, x ^- n \in S}. Proof. by move=> x Sx; rewrite /= rpredV rpredX. Qed. Lemma rpredMl x y : x \in S -> x \is a unit-> (x * y \in S) = (y \in S). Proof. move=> Sx Ux; apply/idP/idP=> [Sxy | /(rpredM _ _ Sx)-> //]. by rewrite -(mulKr Ux y); rewrite rpredM ?rpredV. Qed. Lemma rpredMr x y : x \in S -> x \is a unit -> (y * x \in S) = (y \in S). Proof. move=> Sx Ux; apply/idP/idP=> [Sxy | /rpredM-> //]. by rewrite -(mulrK Ux y); rewrite rpred_div. Qed. Lemma rpred_divr x y : x \in S -> x \is a unit -> (y / x \in S) = (y \in S). Proof. by rewrite -rpredV -unitrV; apply: rpredMr. Qed. Lemma rpred_divl x y : x \in S -> x \is a unit -> (x / y \in S) = (y \in S). Proof. by rewrite -(rpredV y); apply: rpredMl. Qed. End Div. Lemma divringClosedP (divS : divringClosed R) : divring_closed divS. Proof. split; [ exact: rpred1 | exact: rpredB | exact: rpred_div ]. Qed. Fact unitr_sdivr_closed : @sdivr_closed R unit. Proof. by split=> [|x y Ux Uy]; rewrite ?unitrN1 // unitrMl ?unitrV. Qed. #[export] HB.instance Definition _ := isSdivClosed.Build R unit_pred unitr_sdivr_closed. Implicit Type x : R. Lemma unitrN x : (- x \is a unit) = (x \is a unit). Proof. exact: rpredN. Qed. Lemma invrN x : (- x)^-1 = - x^-1. Proof. have [Ux | U'x] := boolP (x \is a unit); last by rewrite !invr_out ?unitrN. by rewrite -mulN1r invrM ?unitrN1 // invrN1 mulrN1. Qed. Lemma divrNN x y : (- x) / (- y) = x / y. Proof. by rewrite invrN mulrNN. Qed. Lemma divrN x y : x / (- y) = - (x / y). Proof. by rewrite invrN mulrN. Qed. Lemma invr_signM n x : ((-1) ^+ n * x)^-1 = (-1) ^+ n * x^-1. Proof. by rewrite -signr_odd !mulr_sign; case: ifP => // _; rewrite invrN. Qed. Lemma divr_signM (b1 b2 : bool) x1 x2: ((-1) ^+ b1 * x1) / ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 / x2). Proof. by rewrite invr_signM mulr_signM. Qed. End UnitRingPred. Section FieldPred. Variable F : fieldType. Implicit Types x y : F. Section ModuleTheory. Variable V : lmodType F. Implicit Types (a : F) (v : V). Lemma rpredZeq (S : submodClosed V) a v : (a *: v \in S) = (a == 0) || (v \in S). Proof. have [-> | nz_a] := eqVneq; first by rewrite scale0r rpred0. by apply/idP/idP; first rewrite -{2}(scalerK nz_a v); apply: rpredZ. Qed. End ModuleTheory. Section Predicates. Context (S : divClosed F). Lemma fpredMl x y : x \in S -> x != 0 -> (x * y \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpredMl. Qed. Lemma fpredMr x y : x \in S -> x != 0 -> (y * x \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpredMr. Qed. Lemma fpred_divl x y : x \in S -> x != 0 -> (x / y \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpred_divl. Qed. Lemma fpred_divr x y : x \in S -> x != 0 -> (y / x \in S) = (y \in S). Proof. by rewrite -!unitfE; apply: rpred_divr. Qed. End Predicates. End FieldPred. HB.mixin Record isSubPzSemiRing (R : pzSemiRingType) (S : pred R) U of SubNmodule R S U & PzSemiRing U := { valM_subproof : monoid_morphism (val : U -> R); }. Module isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isSubPzSemiRing.Build instead.")] Notation Build R S U := (isSubPzSemiRing.Build R S U) (only parsing). End isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use isSubPzSemiRing instead.")] Notation isSubSemiRing R S U := (isSubPzSemiRing R S U) (only parsing). #[short(type="subPzSemiRingType")] HB.structure Definition SubPzSemiRing (R : pzSemiRingType) (S : pred R) := { U of SubNmodule R S U & PzSemiRing U & isSubPzSemiRing R S U }. #[short(type="subNzSemiRingType")] HB.structure Definition SubNzSemiRing (R : nzSemiRingType) (S : pred R) := { U of SubNmodule R S U & NzSemiRing U & isSubPzSemiRing R S U }. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing instead.")] Notation SubSemiRing R := (SubNzSemiRing R) (only parsing). Module SubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.sort instead.")] Notation sort := (SubNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.on instead.")] Notation on R := (SubNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing.copy instead.")] Notation copy T U := (SubNzSemiRing.copy T U) (only parsing). End SubSemiRing. Section multiplicative. Context (R : pzSemiRingType) (S : pred R) (U : SubPzSemiRing.type S). Notation val := (val : U -> R). #[export] HB.instance Definition _ := isMonoidMorphism.Build U R val valM_subproof. Lemma val1 : val 1 = 1. Proof. exact: rmorph1. Qed. Lemma valM : {morph val : x y / x * y}. Proof. exact: rmorphM. Qed. Lemma valM1 : monoid_morphism val. Proof. exact: valM_subproof. Qed. End multiplicative. HB.factory Record SubNmodule_isSubPzSemiRing (R : pzSemiRingType) S U of SubNmodule R S U := { mulr_closed_subproof : mulr_closed S }. HB.builders Context R S U of SubNmodule_isSubPzSemiRing R S U. HB.instance Definition _ := isMulClosed.Build R S mulr_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). Lemma mulrA : associative mulU. Proof. by move=> x y z; apply: val_inj; rewrite !SubK mulrA. Qed. Lemma mul1r : left_id oneU mulU. Proof. by move=> x; apply: val_inj; rewrite !SubK mul1r. Qed. Lemma mulr1 : right_id oneU mulU. Proof. by move=> x; apply: val_inj; rewrite !SubK mulr1. Qed. Lemma mulrDl : left_distributive mulU +%R. Proof. by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDl. Qed. Lemma mulrDr : right_distributive mulU +%R. Proof. by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDr. Qed. Lemma mul0r : left_zero 0%R mulU. Proof. by move=> x; apply: val_inj; rewrite SubK val0 mul0r. Qed. Lemma mulr0 : right_zero 0%R mulU. Proof. by move=> x; apply: val_inj; rewrite SubK val0 mulr0. Qed. HB.instance Definition _ := Nmodule_isPzSemiRing.Build U mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0. Lemma valM : monoid_morphism (val : U -> R). Proof. by split=> [|x y] /=; rewrite !SubK. Qed. HB.instance Definition _ := isSubPzSemiRing.Build R S U valM. HB.end. HB.factory Record SubNmodule_isSubNzSemiRing (R : nzSemiRingType) S U of SubNmodule R S U := { mulr_closed_subproof : mulr_closed S }. Module SubNmodule_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNmodule_isSubNzSemiRing.Build instead.")] Notation Build R S U := (SubNmodule_isSubNzSemiRing.Build R S U) (only parsing). End SubNmodule_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNmodule_isSubNzSemiRing instead.")] Notation SubNmodule_isSubSemiRing R S U := (SubNmodule_isSubNzSemiRing R S U) (only parsing). HB.builders Context R S U of SubNmodule_isSubNzSemiRing R S U. HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U mulr_closed_subproof. Lemma oner_neq0 : (1 : U) != 0. Proof. by rewrite -(inj_eq val_inj) SubK raddf0 oner_neq0. Qed. HB.instance Definition _ := PzSemiRing_isNonZero.Build U oner_neq0. HB.end. #[short(type="subComPzSemiRingType")] HB.structure Definition SubComPzSemiRing (R : pzSemiRingType) S := {U of SubPzSemiRing R S U & ComPzSemiRing U}. HB.factory Record SubPzSemiRing_isSubComPzSemiRing (R : comPzSemiRingType) S U of SubPzSemiRing R S U := {}. HB.builders Context R S U of SubPzSemiRing_isSubComPzSemiRing R S U. Lemma mulrC : @commutative U U *%R. Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed. HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build U mulrC. HB.end. #[short(type="subComNzSemiRingType")] HB.structure Definition SubComNzSemiRing (R : nzSemiRingType) S := {U of SubNzSemiRing R S U & ComNzSemiRing U}. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing instead.")] Notation SubComSemiRing R := (SubComNzSemiRing R) (only parsing). Module SubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.sort instead.")] Notation sort := (SubComNzSemiRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.on instead.")] Notation on R := (SubComNzSemiRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzSemiRing.copy instead.")] Notation copy T U := (SubComNzSemiRing.copy T U) (only parsing). End SubComSemiRing. HB.factory Record SubNzSemiRing_isSubComNzSemiRing (R : comNzSemiRingType) S U of SubNzSemiRing R S U := {}. Module SubSemiRing_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing_isSubComNzSemiRing.Build instead.")] Notation Build R S U := (SubNzSemiRing_isSubComNzSemiRing.Build R S U) (only parsing). End SubSemiRing_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzSemiRing_isSubComNzSemiRing instead.")] Notation SubSemiRing_isSubComSemiRing R S U := (SubNzSemiRing_isSubComNzSemiRing R S U) (only parsing). HB.builders Context R S U of SubNzSemiRing_isSubComNzSemiRing R S U. HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U. HB.end. #[short(type="subPzRingType")] HB.structure Definition SubPzRing (R : pzRingType) (S : pred R) := { U of SubPzSemiRing R S U & PzRing U & isSubZmodule R S U }. HB.factory Record SubZmodule_isSubPzRing (R : pzRingType) S U of SubZmodule R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context R S U of SubZmodule_isSubPzRing R S U. HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U (smulr_closedM (subring_closedM subring_closed_subproof)). HB.end. #[short(type="subNzRingType")] HB.structure Definition SubNzRing (R : nzRingType) (S : pred R) := { U of SubNzSemiRing R S U & NzRing U & isSubBaseAddUMagma R S U }. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing instead.")] Notation SubRing R := (SubNzRing R) (only parsing). Module SubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.sort instead.")] Notation sort := (SubNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.on instead.")] Notation on R := (SubNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing.copy instead.")] Notation copy T U := (SubNzRing.copy T U) (only parsing). End SubRing. HB.factory Record SubZmodule_isSubNzRing (R : nzRingType) S U of SubZmodule R S U := { subring_closed_subproof : subring_closed S }. Module SubZmodule_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubZmodule_isSubNzRing.Build instead.")] Notation Build R S U := (SubZmodule_isSubNzRing.Build R S U) (only parsing). End SubZmodule_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubZmodule_isSubNzRing instead.")] Notation SubZmodule_isSubRing R S U := (SubZmodule_isSubNzRing R S U) (only parsing). HB.builders Context R S U of SubZmodule_isSubNzRing R S U. HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)). Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)). HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U (smulr_closedM (subring_closedM subring_closed_subproof)). HB.end. #[short(type="subComPzRingType")] HB.structure Definition SubComPzRing (R : pzRingType) S := {U of SubPzRing R S U & ComPzRing U}. HB.factory Record SubPzRing_isSubComPzRing (R : comPzRingType) S U of SubPzRing R S U := {}. HB.builders Context R S U of SubPzRing_isSubComPzRing R S U. Lemma mulrC : @commutative U U *%R. Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed. HB.instance Definition _ := PzRing_hasCommutativeMul.Build U mulrC. HB.end. #[short(type="subComNzRingType")] HB.structure Definition SubComNzRing (R : nzRingType) S := {U of SubNzRing R S U & ComNzRing U}. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing instead.")] Notation SubComRing R := (SubComNzRing R) (only parsing). Module SubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.sort instead.")] Notation sort := (SubComNzRing.sort) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.on instead.")] Notation on R := (SubComNzRing.on R) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use SubComNzRing.copy instead.")] Notation copy T U := (SubComNzRing.copy T U) (only parsing). End SubComRing. HB.factory Record SubNzRing_isSubComNzRing (R : comNzRingType) S U of SubNzRing R S U := {}. Module SubRing_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_isSubComNzRing.Build instead.")] Notation Build R S U := (SubNzRing_isSubComNzRing.Build R S U) (only parsing). End SubRing_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_isSubComNzRing instead.")] Notation SubRing_isSubComRing R S U := (SubNzRing_isSubComNzRing R S U) (only parsing). HB.builders Context R S U of SubNzRing_isSubComNzRing R S U. HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U. HB.end. HB.mixin Record isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) (S : pred V) W of SubNmodule V S W & LSemiModule R W := { valZ : scalable (val : W -> V); }. #[short(type="subLSemiModType")] HB.structure Definition SubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) (S : pred V) := { W of SubNmodule V S W & Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}. #[short(type="subLmodType")] HB.structure Definition SubLmodule (R : pzRingType) (V : lmodType R) (S : pred V) := { W of SubZmodule V S W & Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}. Section linear. Context (R : pzSemiRingType) (V : lSemiModType R). Context (S : pred V) (W : subLSemiModType S). Notation val := (val : W -> V). #[export] HB.instance Definition _ := isScalable.Build R W V *:%R val valZ. End linear. HB.factory Record isSubLmodule (R : pzRingType) (V : lmodType R) (S : pred V) W of SubZmodule V S W & Lmodule R W := { valZ : scalable (val : W -> V); }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of isSubLmodule R V S W. HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ. HB.end. HB.factory Record SubNmodule_isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) S W of SubNmodule V S W := { submod_closed_subproof : subsemimod_closed S }. HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W of SubNmodule_isSubLSemiModule R V S W. HB.instance Definition _ := isSubSemiModClosed.Build R V S submod_closed_subproof. Let inW v Sv : W := Sub v Sv. Let scaleW a (w : W) := inW (rpredZ a _ (valP w)). Lemma scalerA' a b v : scaleW a (scaleW b v) = scaleW (a * b) v. Proof. by apply: val_inj; rewrite !SubK scalerA. Qed. Lemma scale0r v : scaleW 0 v = 0. Proof. by apply: val_inj; rewrite SubK scale0r raddf0. Qed. Lemma scale1r : left_id 1 scaleW. Proof. by move=> x; apply: val_inj; rewrite SubK scale1r. Qed. Lemma scalerDr : right_distributive scaleW +%R. Proof. by move=> a u v; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK. Qed. Lemma scalerDl v : {morph scaleW^~ v : a b / a + b}. Proof. by move=> a b; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK scalerDl. Qed. HB.instance Definition _ := Nmodule_isLSemiModule.Build R W scalerA' scale0r scale1r scalerDr scalerDl. Fact valZ : scalable (val : W -> _). Proof. by move=> k w; rewrite SubK. Qed. HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ. HB.end. HB.factory Record SubZmodule_isSubLmodule (R : pzRingType) (V : lmodType R) S W of SubZmodule V S W := { submod_closed_subproof : submod_closed S }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of SubZmodule_isSubLmodule R V S W. HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W (submod_closed_semi submod_closed_subproof). HB.end. #[short(type="subLSemiAlgType")] HB.structure Definition SubLSemiAlgebra (R : pzSemiRingType) (V : lSemiAlgType R) S := {W of SubNzSemiRing V S W & @SubLSemiModule R V S W & LSemiAlgebra R W}. #[short(type="subLalgType")] HB.structure Definition SubLalgebra (R : pzRingType) (V : lalgType R) S := {W of SubNzRing V S W & @SubLmodule R V S W & Lalgebra R W}. HB.factory Record SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra (R : pzSemiRingType) (V : lSemiAlgType R) S W of SubNzSemiRing V S W & @SubLSemiModule R V S W := {}. HB.builders Context (R : pzSemiRingType) (V : lSemiAlgType R) S W of SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra R V S W. Lemma scalerAl (a : R) (u v : W) : a *: (u * v) = a *: u * v. Proof. by apply: val_inj; rewrite !(linearZ, rmorphM) /= linearZ scalerAl. Qed. HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R W scalerAl. HB.end. HB.factory Record SubNzRing_SubLmodule_isSubLalgebra (R : pzRingType) (V : lalgType R) S W of SubNzRing V S W & @SubLmodule R V S W := {}. Module SubRing_SubLmodule_isSubLalgebra. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_SubLmodule_isSubLalgebra.Build instead.")] Notation Build R V S U := (SubNzRing_SubLmodule_isSubLalgebra.Build R V S U) (only parsing). End SubRing_SubLmodule_isSubLalgebra. #[deprecated(since="mathcomp 2.4.0", note="Use SubNzRing_SubLmodule_isSubLalgebra instead.")] Notation SubRing_SubLmodule_isSubLalgebra R V S U := (SubNzRing_SubLmodule_isSubLalgebra R V S U) (only parsing). HB.builders Context (R : pzRingType) (V : lalgType R) S W of SubNzRing_SubLmodule_isSubLalgebra R V S W. HB.instance Definition _ := SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build R V S W. HB.end. #[short(type="subSemiAlgType")] HB.structure Definition SubSemiAlgebra (R : pzSemiRingType) (V : semiAlgType R) S := {W of @SubLSemiAlgebra R V S W & SemiAlgebra R W}. #[short(type="subAlgType")] HB.structure Definition SubAlgebra (R : pzRingType) (V : algType R) S := {W of @SubLalgebra R V S W & Algebra R W}. HB.factory Record SubLSemiAlgebra_isSubSemiAlgebra (R : pzSemiRingType) (V : semiAlgType R) S W of @SubLSemiAlgebra R V S W := {}. HB.builders Context (R : pzSemiRingType) (V : semiAlgType R) S W of SubLSemiAlgebra_isSubSemiAlgebra R V S W. Lemma scalerAr (k : R) (x y : W) : k *: (x * y) = x * (k *: y). Proof. by apply: val_inj; rewrite !(linearZ, rmorphM)/= linearZ scalerAr. Qed. HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R W scalerAr. HB.end. HB.factory Record SubLalgebra_isSubAlgebra (R : pzRingType) (V : algType R) S W of @SubLalgebra R V S W := {}. HB.builders Context (R : pzRingType) (V : algType R) S W of SubLalgebra_isSubAlgebra R V S W. HB.instance Definition _ := SubLSemiAlgebra_isSubSemiAlgebra.Build R V S W. HB.end. #[short(type="subUnitRingType")] HB.structure Definition SubUnitRing (R : nzRingType) (S : pred R) := {U of SubNzRing R S U & UnitRing U}. HB.factory Record SubNzRing_isSubUnitRing (R : unitRingType) S U of SubNzRing R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : unitRingType) S U of SubNzRing_isSubUnitRing R S U. HB.instance Definition _ := isDivringClosed.Build R S divring_closed_subproof. Let inU v Sv : U := Sub v Sv. Let invU (u : U) := inU (rpredVr _ (valP u)). Lemma mulVr : {in [pred x | val x \is a unit], left_inverse 1 invU *%R}. Proof. by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulVr. Qed. Lemma divrr : {in [pred x | val x \is a unit], right_inverse 1 invU *%R}. by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulrV. Qed. Lemma unitrP (x y : U) : y * x = 1 /\ x * y = 1 -> val x \is a unit. Proof. move=> -[/(congr1 val) yx1 /(congr1 val) xy1]. by apply: rev_unitrP (val y) _; rewrite !rmorphM rmorph1 /= in yx1 xy1. Qed. Lemma invr_out : {in [pred x | val x \isn't a unit], invU =1 id}. Proof. by move=> x /[!inE] xNU; apply: val_inj; rewrite SubK invr_out. Qed. HB.instance Definition _ := NzRing_hasMulInverse.Build U mulVr divrr unitrP invr_out. HB.end. #[short(type="subComUnitRingType")] HB.structure Definition SubComUnitRing (R : comUnitRingType) (S : pred R) := {U of SubComNzRing R S U & SubUnitRing R S U}. #[short(type="subIdomainType")] HB.structure Definition SubIntegralDomain (R : idomainType) (S : pred R) := {U of SubComNzRing R S U & IntegralDomain U}. HB.factory Record SubComUnitRing_isSubIntegralDomain (R : idomainType) S U of SubComUnitRing R S U := {}. HB.builders Context (R : idomainType) S U of SubComUnitRing_isSubIntegralDomain R S U. Lemma id : IntegralDomain.axiom U. Proof. move=> x y /(congr1 val)/eqP; rewrite rmorphM /=. by rewrite -!(inj_eq val_inj) rmorph0 -mulf_eq0. Qed. HB.instance Definition _ := ComUnitRing_isIntegral.Build U id. HB.end. #[short(type="subFieldType")] HB.structure Definition SubField (F : fieldType) (S : pred F) := {U of SubIntegralDomain F S U & Field U}. HB.factory Record SubIntegralDomain_isSubField (F : fieldType) S U of SubIntegralDomain F S U := { subfield_subproof : {mono (val : U -> F) : u / u \in unit} }. HB.builders Context (F : fieldType) S U of SubIntegralDomain_isSubField F S U. Lemma fieldP : Field.axiom U. Proof. by move=> u; rewrite -(inj_eq val_inj) rmorph0 -unitfE subfield_subproof. Qed. HB.instance Definition _ := UnitRing_isField.Build U fieldP. HB.end. HB.factory Record SubChoice_isSubPzSemiRing (R : pzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. HB.builders Context (R : pzSemiRingType) S U of SubChoice_isSubPzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record SubChoice_isSubNzSemiRing (R : nzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. Module SubChoice_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzSemiRing.Build instead.")] Notation Build R S U := (SubChoice_isSubNzSemiRing.Build R S U) (only parsing). End SubChoice_isSubSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzSemiRing instead.")] Notation SubChoice_isSubSemiRing R S U := (SubChoice_isSubNzSemiRing R S U) (only parsing). HB.builders Context (R : nzSemiRingType) S U of SubChoice_isSubNzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U (semiring_closedD semiring_closed_subproof). HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U (semiring_closedM semiring_closed_subproof). HB.end. HB.factory Record SubChoice_isSubComPzSemiRing (R : comPzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. HB.builders Context (R : comPzSemiRingType) S U of SubChoice_isSubComPzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubPzSemiRing.Build R S U semiring_closed_subproof. HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubComNzSemiRing (R : comNzSemiRingType) S U of SubChoice R S U := { semiring_closed_subproof : semiring_closed S }. Module SubChoice_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzSemiRing.Build instead.")] Notation Build R S U := (SubChoice_isSubComNzSemiRing.Build R S U) (only parsing). End SubChoice_isSubComSemiRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzSemiRing instead.")] Notation SubChoice_isSubComSemiRing R S U := (SubChoice_isSubComNzSemiRing R S U) (only parsing). HB.builders Context (R : comNzSemiRingType) S U of SubChoice_isSubComNzSemiRing R S U. HB.instance Definition _ := SubChoice_isSubNzSemiRing.Build R S U semiring_closed_subproof. HB.instance Definition _ := SubNzSemiRing_isSubComNzSemiRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubPzRing (R : pzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context (R : pzRingType) S U of SubChoice_isSubPzRing R S U. HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U (subring_closedB subring_closed_subproof). HB.instance Definition _ := SubZmodule_isSubPzRing.Build R S U subring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubNzRing (R : nzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. Module SubChoice_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzRing.Build instead.")] Notation Build R S U := (SubChoice_isSubNzRing.Build R S U) (only parsing). End SubChoice_isSubRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubNzRing instead.")] Notation SubChoice_isSubRing R S U := (SubChoice_isSubNzRing R S U) (only parsing). HB.builders Context (R : nzRingType) S U of SubChoice_isSubNzRing R S U. HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U (subring_closedB subring_closed_subproof). HB.instance Definition _ := SubZmodule_isSubNzRing.Build R S U subring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubComPzRing (R : comPzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. HB.builders Context (R : comPzRingType) S U of SubChoice_isSubComPzRing R S U. HB.instance Definition _ := SubChoice_isSubPzRing.Build R S U subring_closed_subproof. HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubComNzRing (R : comNzRingType) S U of SubChoice R S U := { subring_closed_subproof : subring_closed S }. Module SubChoice_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzRing.Build instead.")] Notation Build R S U := (SubChoice_isSubComNzRing.Build R S U) (only parsing). End SubChoice_isSubComRing. #[deprecated(since="mathcomp 2.4.0", note="Use SubChoice_isSubComNzRing instead.")] Notation SubChoice_isSubComRing R S U := (SubChoice_isSubComNzRing R S U) (only parsing). HB.builders Context (R : comNzRingType) S U of SubChoice_isSubComNzRing R S U. HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U subring_closed_subproof. HB.instance Definition _ := SubNzRing_isSubComNzRing.Build R S U. HB.end. HB.factory Record SubChoice_isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R) S W of SubChoice V S W := { subsemimod_closed_subproof : subsemimod_closed S }. HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W of SubChoice_isSubLSemiModule R V S W. HB.instance Definition _ := SubChoice_isSubNmodule.Build V S W (subsemimod_closedD subsemimod_closed_subproof). HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W subsemimod_closed_subproof. HB.end. HB.factory Record SubChoice_isSubLmodule (R : pzRingType) (V : lmodType R) S W of SubChoice V S W := { submod_closed_subproof : submod_closed S }. HB.builders Context (R : pzRingType) (V : lmodType R) S W of SubChoice_isSubLmodule R V S W. HB.instance Definition _ := SubChoice_isSubZmodule.Build V S W (submod_closedB submod_closed_subproof). HB.instance Definition _ := SubZmodule_isSubLmodule.Build R V S W submod_closed_subproof. HB.end. (* TODO: SubChoice_isSubLSemiAlgebra? *) HB.factory Record SubChoice_isSubLalgebra (R : pzRingType) (A : lalgType R) S W of SubChoice A S W := { subalg_closed_subproof : subalg_closed S }. HB.builders Context (R : pzRingType) (A : lalgType R) S W of SubChoice_isSubLalgebra R A S W. HB.instance Definition _ := SubChoice_isSubNzRing.Build A S W (subalg_closedBM subalg_closed_subproof). HB.instance Definition _ := SubZmodule_isSubLmodule.Build R A S W (subalg_closedZ subalg_closed_subproof). HB.instance Definition _ := SubNzRing_SubLmodule_isSubLalgebra.Build R A S W. HB.end. (* TODO: SubChoice_isSubSemiAlgebra? *) HB.factory Record SubChoice_isSubAlgebra (R : pzRingType) (A : algType R) S W of SubChoice A S W := { subalg_closed_subproof : subalg_closed S }. HB.builders Context (R : pzRingType) (A : algType R) S W of SubChoice_isSubAlgebra R A S W. HB.instance Definition _ := SubChoice_isSubLalgebra.Build R A S W subalg_closed_subproof. HB.instance Definition _ := SubLalgebra_isSubAlgebra.Build R A S W. HB.end. HB.factory Record SubChoice_isSubUnitRing (R : unitRingType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : unitRingType) S U of SubChoice_isSubUnitRing R S U. HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U (divring_closedBM divring_closed_subproof). HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U divring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubComUnitRing (R : comUnitRingType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : comUnitRingType) S U of SubChoice_isSubComUnitRing R S U. HB.instance Definition _ := SubChoice_isSubComNzRing.Build R S U (divring_closedBM divring_closed_subproof). HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U divring_closed_subproof. HB.end. HB.factory Record SubChoice_isSubIntegralDomain (R : idomainType) S U of SubChoice R S U := { divring_closed_subproof : divring_closed S }. HB.builders Context (R : idomainType) S U of SubChoice_isSubIntegralDomain R S U. HB.instance Definition _ := SubChoice_isSubComUnitRing.Build R S U divring_closed_subproof. HB.instance Definition _ := SubComUnitRing_isSubIntegralDomain.Build R S U. HB.end. Module SubExports. Notation "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]" := (SubChoice_isSubNmodule.Build _ _ U rpred0D) (format "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]" := (SubChoice_isSubZmodule.Build _ _ U (zmodClosedP _)) (format "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]" := (SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _)) (format "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ SubNmodule_isSubNzSemiRing of U by <: ] instead.")] Notation "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]" := (SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _)) (format "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]" := (SubNzSemiRing_isSubComNzSemiRing.Build _ _ U) (format "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzSemiRing_isSubComNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]" := (SubNzSemiRing_isSubComNzSemiRing.Build _ _ U) (format "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubComNzSemiRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _)) (format "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]" := (SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubZmodule_isSubNzRing' of U by <: ] instead.")] Notation "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]" := (SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubNzRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]" := (SubChoice_isSubNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]" := (SubNzRing_isSubComNzRing.Build _ _ U) (format "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_isSubComNzRing' of U by <: ] instead.")] Notation "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]" := (SubNzRing_isSubComNzRing.Build _ _ U) (format "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubChoice_isSubComNzRing' of U by <: ] instead.")] Notation "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]" := (SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _)) (format "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]" := (SubNmodule_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _)) (format "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]" := (SubChoice_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _)) (format "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]" := (SubZmodule_isSubLmodule.Build _ _ _ U (submodClosedP _)) (format "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]" := (SubChoice_isSubLmodule.Build _ _ _ U (submodClosedP _)) (format "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]" := (SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build _ _ _ U) (format "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]") : form_scope. (* TODO: SubChoice_isSubLSemiAlgebra? *) Notation "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" := (SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U) (format "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_SubLmodule_isSubLalgebra' of U by <: ] instead.")] Notation "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" := (SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U) (format "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]" := (SubChoice_isSubLalgebra.Build _ _ _ U (subalgClosedP _)) (format "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]" := (SubLSemiAlgebra_isSubSemiAlgebra.Build _ _ _ U) (format "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]") : form_scope. (* TODO: SubChoice_isSubSemiAlgebra? *) Notation "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]" := (SubLalgebra_isSubAlgebra.Build _ _ _ U) (format "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]" := (SubChoice_isSubAlgebra.Build _ _ _ U (subalgClosedP _)) (format "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]" := (SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [ 'SubNzRing_isSubUnitRing' of U by <: ] instead.")] Notation "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]" := (SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]" := (SubChoice_isSubUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]" := (SubChoice_isSubComUnitRing.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]" := (SubComUnitRing_isSubIntegralDomain.Build _ _ U) (format "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]" := (SubChoice_isSubIntegralDomain.Build _ _ U (divringClosedP _)) (format "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]") : form_scope. Notation "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]" := (SubIntegralDomain_isSubField.Build _ _ U (frefl _)) (format "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]") : form_scope. End SubExports. HB.export SubExports. Module Theory. Definition addrA := @addrA. Definition addrC := @addrC. Definition add0r := @add0r. Definition addNr := @addNr. Definition addr0 := addr0. Definition addrN := addrN. Definition subrr := subrr. Definition addrCA := addrCA. Definition addrAC := addrAC. Definition addrACA := addrACA. Definition addKr := addKr. Definition addNKr := addNKr. Definition addrK := addrK. Definition addrNK := addrNK. Definition subrK := subrK. Definition subKr := subKr. Definition addrI := @addrI. Definition addIr := @addIr. Definition subrI := @subrI. Definition subIr := @subIr. Arguments addrI {V} y [x1 x2]. Arguments addIr {V} x [x1 x2]. Arguments subrI {V} y [x1 x2]. Arguments subIr {V} x [x1 x2]. Definition opprK := @opprK. Arguments opprK {V}. Definition oppr_inj := @oppr_inj. Arguments oppr_inj {V} [x1 x2]. Definition oppr0 := oppr0. Definition oppr_eq0 := oppr_eq0. Definition opprD := opprD. Definition opprB := opprB. Definition addrKA := addrKA. Definition subrKA := subrKA. Definition subr0 := subr0. Definition sub0r := sub0r. Definition subr_eq := subr_eq. Definition addr0_eq := addr0_eq. Definition subr0_eq := subr0_eq. Definition subr_eq0 := subr_eq0. Definition addr_eq0 := addr_eq0. Definition eqr_opp := eqr_opp. Definition eqr_oppLR := eqr_oppLR. Definition sumrN := sumrN. Definition sumrB := sumrB. Definition sumrMnl := sumrMnl. Definition sumrMnr := sumrMnr. Definition sumr_const := sumr_const. Definition sumr_const_nat := sumr_const_nat. Definition telescope_sumr := telescope_sumr. Definition telescope_sumr_eq := @telescope_sumr_eq. Arguments telescope_sumr_eq {V n m} f u. Definition mulr0n := mulr0n. Definition mulr1n := mulr1n. Definition mulr2n := mulr2n. Definition mulrS := mulrS. Definition mulrSr := mulrSr. Definition mulrb := mulrb. Definition mul0rn := mul0rn. Definition mulNrn := mulNrn. Definition mulrnDl := mulrnDl. Definition mulrnDr := mulrnDr. Definition mulrnBl := mulrnBl. Definition mulrnBr := mulrnBr. Definition mulrnA := mulrnA. Definition mulrnAC := mulrnAC. Definition iter_addr := iter_addr. Definition iter_addr_0 := iter_addr_0. Definition mulrA := @mulrA. Definition mul1r := @mul1r. Definition mulr1 := @mulr1. Definition mulrDl := @mulrDl. Definition mulrDr := @mulrDr. Definition oner_neq0 := @oner_neq0. Definition oner_eq0 := oner_eq0. Definition mul0r := @mul0r. Definition mulr0 := @mulr0. Definition mulrN := mulrN. Definition mulNr := mulNr. Definition mulrNN := mulrNN. Definition mulN1r := mulN1r. Definition mulrN1 := mulrN1. Definition mulr_suml := mulr_suml. Definition mulr_sumr := mulr_sumr. Definition mulrBl := mulrBl. Definition mulrBr := mulrBr. Definition mulrnAl := mulrnAl. Definition mulrnAr := mulrnAr. Definition mulr_natl := mulr_natl. Definition mulr_natr := mulr_natr. Definition natrD := natrD. Definition nat1r := nat1r. Definition natr1 := natr1. Arguments natr1 {R} n. Arguments nat1r {R} n. Definition natrB := natrB. Definition natr_sum := natr_sum. Definition natrM := natrM. Definition natrX := natrX. Definition expr0 := expr0. Definition exprS := exprS. Definition expr1 := expr1. Definition expr2 := expr2. Definition expr0n := expr0n. Definition expr1n := expr1n. Definition exprD := exprD. Definition exprSr := exprSr. Definition expr_sum := expr_sum. Definition commr_sym := commr_sym. Definition commr_refl := commr_refl. Definition commr0 := commr0. Definition commr1 := commr1. Definition commrN := commrN. Definition commrN1 := commrN1. Definition commrD := commrD. Definition commrB := commrB. Definition commr_sum := commr_sum. Definition commr_prod := commr_prod. Definition commrMn := commrMn. Definition commrM := commrM. Definition commr_nat := commr_nat. Definition commrX := commrX. Definition exprMn_comm := exprMn_comm. Definition commr_sign := commr_sign. Definition exprMn_n := exprMn_n. Definition exprM := exprM. Definition exprAC := exprAC. Definition expr_mod := expr_mod. Definition expr_dvd := expr_dvd. Definition signr_odd := signr_odd. Definition signr_eq0 := signr_eq0. Definition mulr_sign := mulr_sign. Definition signr_addb := signr_addb. Definition signrN := signrN. Definition signrE := signrE. Definition mulr_signM := mulr_signM. Definition exprNn := exprNn. Definition sqrrN := sqrrN. Definition sqrr_sign := sqrr_sign. Definition signrMK := signrMK. Definition mulrI_eq0 := mulrI_eq0. Definition lreg_neq0 := lreg_neq0. Definition mulrI0_lreg := mulrI0_lreg. Definition lregN := lregN. Definition lreg1 := lreg1. Definition lregM := lregM. Definition lregX := lregX. Definition lreg_sign := lreg_sign. Definition lregP {R x} := @lregP R x. Definition mulIr_eq0 := mulIr_eq0. Definition mulIr0_rreg := mulIr0_rreg. Definition rreg_neq0 := rreg_neq0. Definition rregN := rregN. Definition rreg1 := rreg1. Definition rregM := rregM. Definition revrX := revrX. Definition rregX := rregX. Definition rregP {R x} := @rregP R x. Definition exprDn_comm := exprDn_comm. Definition exprBn_comm := exprBn_comm. Definition subrXX_comm := subrXX_comm. Definition exprD1n := exprD1n. Definition subrX1 := subrX1. Definition sqrrD1 := sqrrD1. Definition sqrrB1 := sqrrB1. Definition subr_sqr_1 := subr_sqr_1. Definition pcharf0 := pcharf0. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")] Definition charf0 := pcharf0. Definition pcharf_prime := pcharf_prime. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")] Definition charf_prime := pcharf_prime. Definition mulrn_pchar := mulrn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")] Definition mulrn_char := mulrn_pchar. Definition dvdn_pcharf := dvdn_pcharf. #[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")] Definition dvdn_charf := dvdn_pcharf. Definition pcharf_eq := pcharf_eq. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")] Definition charf_eq := pcharf_eq. Definition bin_lt_pcharf_0 := bin_lt_pcharf_0. #[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")] Definition bin_lt_charf_0 := bin_lt_pcharf_0. Definition pFrobenius_autE := pFrobenius_autE. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")] Definition Frobenius_autE := pFrobenius_autE. Definition pFrobenius_aut0 := pFrobenius_aut0. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")] Definition Frobenius_aut0 := pFrobenius_aut0. Definition pFrobenius_aut1 := pFrobenius_aut1. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")] Definition Frobenius_aut1 := pFrobenius_aut1. Definition pFrobenius_autD_comm := pFrobenius_autD_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")] Definition Frobenius_autD_comm := pFrobenius_autD_comm. Definition pFrobenius_autMn := pFrobenius_autMn. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")] Definition Frobenius_autMn := pFrobenius_autMn. Definition pFrobenius_aut_nat := pFrobenius_aut_nat. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")] Definition Frobenius_aut_nat := pFrobenius_aut_nat. Definition pFrobenius_autM_comm := pFrobenius_autM_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")] Definition Frobenius_autM_comm := pFrobenius_autM_comm. Definition pFrobenius_autX := pFrobenius_autX. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")] Definition Frobenius_autX := pFrobenius_autX. Definition pFrobenius_autN := pFrobenius_autN. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")] Definition Frobenius_autN := pFrobenius_autN. Definition pFrobenius_autB_comm := pFrobenius_autB_comm. #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")] Definition Frobenius_autB_comm := pFrobenius_autB_comm. Definition exprNn_pchar := exprNn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")] Definition exprNn_char := exprNn_pchar. Definition addrr_pchar2 := addrr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")] Definition addrr_char2 := addrr_pchar2. Definition oppr_pchar2 := oppr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")] Definition oppr_char2 := oppr_pchar2. Definition addrK_pchar2 := addrK_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")] Definition addrK_char2 := addrK_pchar2. Definition addKr_pchar2 := addKr_pchar2. #[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")] Definition addKr_char2 := addKr_pchar2. Definition iter_mulr := iter_mulr. Definition iter_mulr_1 := iter_mulr_1. Definition prodr_const := prodr_const. Definition prodr_const_nat := prodr_const_nat. Definition mulrC := @mulrC. Definition mulrCA := mulrCA. Definition mulrAC := mulrAC. Definition mulrACA := mulrACA. Definition exprMn := exprMn. Definition prodrXl := prodrXl. Definition prodrXr := prodrXr. Definition prodrN := prodrN. Definition prodrMn_const := prodrMn_const. Definition prodrM_comm := prodrM_comm. Definition prodrMl_comm := prodrMl_comm. Definition prodrMr_comm := prodrMr_comm. Definition prodrMl := prodrMl. Definition prodrMr := prodrMr. Definition prodrMn := prodrMn. Definition rev_prodr := rev_prodr. Definition natr_prod := natr_prod. Definition prodr_undup_exp_count := prodr_undup_exp_count. Definition exprDn := exprDn. Definition exprBn := exprBn. Definition subrXX := subrXX. Definition sqrrD := sqrrD. Definition sqrrB := sqrrB. Definition subr_sqr := subr_sqr. Definition subr_sqrDB := subr_sqrDB. Definition exprDn_pchar := exprDn_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")] Definition exprDn_char := exprDn_pchar. Definition mulrV := mulrV. Definition divrr := divrr. Definition mulVr := mulVr. Definition invr_out := invr_out. Definition unitrP {R x} := @unitrP R x. Definition mulKr := mulKr. Definition mulVKr := mulVKr. Definition mulrK := mulrK. Definition mulrVK := mulrVK. Definition divrK := divrK. Definition mulrI := mulrI. Definition mulIr := mulIr. Definition divrI := divrI. Definition divIr := divIr. Definition telescope_prodr := telescope_prodr. Definition telescope_prodr_eq := @telescope_prodr_eq. Arguments telescope_prodr_eq {R n m} f u. Definition commrV := commrV. Definition unitrE := unitrE. Definition invrK := @invrK. Arguments invrK {R}. Definition invr_inj := @invr_inj. Arguments invr_inj {R} [x1 x2]. Definition unitrV := unitrV. Definition unitr1 := unitr1. Definition invr1 := invr1. Definition divr1 := divr1. Definition div1r := div1r. Definition natr_div := natr_div. Definition unitr0 := unitr0. Definition invr0 := invr0. Definition unitrN1 := unitrN1. Definition unitrN := unitrN. Definition invrN1 := invrN1. Definition invrN := invrN. Definition divrNN := divrNN. Definition divrN := divrN. Definition invr_sign := invr_sign. Definition unitrMl := unitrMl. Definition unitrMr := unitrMr. Definition invrM := invrM. Definition unitr_prod := unitr_prod. Definition unitr_prod_in := unitr_prod_in. Definition invr_eq0 := invr_eq0. Definition invr_eq1 := invr_eq1. Definition invr_neq0 := invr_neq0. Definition rev_unitrP := rev_unitrP. Definition rev_prodrV := rev_prodrV. Definition unitrM_comm := unitrM_comm. Definition unitrX := unitrX. Definition unitrX_pos := unitrX_pos. Definition exprVn := exprVn. Definition exprB := exprB. Definition invr_signM := invr_signM. Definition divr_signM := divr_signM. Definition rpred0D := @rpred0D. Definition rpred0 := rpred0. Definition rpredD := rpredD. Definition rpredNr := @rpredNr. Definition rpred_sum := rpred_sum. Definition rpredMn := rpredMn. Definition rpredN := rpredN. Definition rpredB := rpredB. Definition rpredBC := rpredBC. Definition rpredMNn := rpredMNn. Definition rpredDr := rpredDr. Definition rpredDl := rpredDl. Definition rpredBr := rpredBr. Definition rpredBl := rpredBl. Definition zmodClosedP := zmodClosedP. Definition rpredMsign := rpredMsign. Definition rpred1M := @rpred1M. Definition rpred1 := @rpred1. Definition rpredM := @rpredM. Definition rpred_prod := rpred_prod. Definition rpredX := rpredX. Definition rpred_nat := rpred_nat. Definition rpredN1 := rpredN1. Definition rpred_sign := rpred_sign. Definition semiringClosedP := semiringClosedP. Definition subringClosedP := subringClosedP. Definition rpredZsign := rpredZsign. Definition rpredZnat := rpredZnat. Definition submodClosedP := submodClosedP. Definition subalgClosedP := subalgClosedP. Definition rpredZ := @rpredZ. Definition rpredVr := @rpredVr. Definition rpredV := rpredV. Definition rpred_div := rpred_div. Definition rpredXN := rpredXN. Definition rpredZeq := rpredZeq. Definition pchar_lalg := pchar_lalg. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")] Definition char_lalg := pchar_lalg. Definition rpredMr := rpredMr. Definition rpredMl := rpredMl. Definition rpred_divr := rpred_divr. Definition rpred_divl := rpred_divl. Definition divringClosedP := divringClosedP. Definition eq_eval := eq_eval. Definition eval_tsubst := eval_tsubst. Definition eq_holds := eq_holds. Definition holds_fsubst := holds_fsubst. Definition unitrM := unitrM. Definition unitr_prodP := unitr_prodP. Definition prodrV := prodrV. Definition unitrPr {R x} := @unitrPr R x. Definition expr_div_n := expr_div_n. Definition mulr1_eq := mulr1_eq. Definition divr1_eq := divr1_eq. Definition divKr := divKr. Definition mulf_eq0 := mulf_eq0. Definition prodf_eq0 := prodf_eq0. Definition prodf_seq_eq0 := prodf_seq_eq0. Definition mulf_neq0 := mulf_neq0. Definition prodf_neq0 := prodf_neq0. Definition prodf_seq_neq0 := prodf_seq_neq0. Definition expf_eq0 := expf_eq0. Definition sqrf_eq0 := sqrf_eq0. Definition expf_neq0 := expf_neq0. Definition natf_neq0_pchar := natf_neq0_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")] Definition natf_neq0 := natf_neq0_pchar. Definition natf0_pchar := natf0_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")] Definition natf0_char := natf0_pchar. Definition pcharf'_nat := pcharf'_nat. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")] Definition charf'_nat := pcharf'_nat. Definition pcharf0P := pcharf0P. #[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")] Definition charf0P := pcharf0P. Definition eqf_sqr := eqf_sqr. Definition mulfI := mulfI. Definition mulIf := mulIf. Definition divfI := divfI. Definition divIf := divIf. Definition sqrf_eq1 := sqrf_eq1. Definition expfS_eq1 := expfS_eq1. Definition fieldP := @fieldP. Definition unitfE := unitfE. Definition mulVf := mulVf. Definition mulfV := mulfV. Definition divff := divff. Definition mulKf := mulKf. Definition mulVKf := mulVKf. Definition mulfK := mulfK. Definition mulfVK := mulfVK. Definition divfK := divfK. Definition divKf := divKf. Definition invfM := invfM. Definition invf_div := invf_div. Definition expfB_cond := expfB_cond. Definition expfB := expfB. Definition prodfV := prodfV. Definition prodf_div := prodf_div. Definition telescope_prodf := telescope_prodf. Definition telescope_prodf_eq := @telescope_prodf_eq. Arguments telescope_prodf_eq {F n m} f u. Definition addf_div := addf_div. Definition mulf_div := mulf_div. Definition eqr_div := eqr_div. Definition eqr_sum_div := eqr_sum_div. Definition pchar0_natf_div := pchar0_natf_div. #[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")] Definition char0_natf_div := pchar0_natf_div. Definition fpredMr := fpredMr. Definition fpredMl := fpredMl. Definition fpred_divr := fpred_divr. Definition fpred_divl := fpred_divl. Definition satP {F e f} := @satP F e f. Definition eq_sat := eq_sat. Definition solP {F n f} := @solP F n f. Definition eq_sol := eq_sol. Definition size_sol := size_sol. Definition solve_monicpoly := @solve_monicpoly. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `nmod_morphism` instead")] Definition semi_additive := semi_additive. Definition nmod_morphism := nmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism` instead")] Definition additive := additive. Definition zmod_morphism := zmod_morphism. Definition raddf0 := raddf0. Definition raddf_eq0 := raddf_eq0. Definition raddf_inj := raddf_inj. Definition raddfN := raddfN. Definition raddfD := raddfD. Definition raddfB := raddfB. Definition raddf_sum := raddf_sum. Definition raddfMn := raddfMn. Definition raddfMNn := raddfMNn. Definition raddfMnat := raddfMnat. Definition raddfMsign := raddfMsign. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_nmod_morphism` instead")] Definition can2_semi_additive := can2_semi_additive. Definition can2_nmod_morphism := can2_nmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_zmod_morphism` instead")] Definition can2_additive := can2_additive. Definition can2_zmod_morphism := can2_zmod_morphism. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")] Definition multiplicative := multiplicative. Definition monoid_morphism := monoid_morphism. Definition rmorph0 := rmorph0. Definition rmorphN := rmorphN. Definition rmorphD := rmorphD. Definition rmorphB := rmorphB. Definition rmorph_sum := rmorph_sum. Definition rmorphMn := rmorphMn. Definition rmorphMNn := rmorphMNn. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `rmorphism_monoidP` instead")] Definition rmorphismMP := rmorphismMP. Definition rmorphism_monoidP := rmorphism_monoidP. Definition rmorph1 := rmorph1. Definition rmorph_eq1 := rmorph_eq1. Definition rmorphM := rmorphM. Definition rmorphMsign := rmorphMsign. Definition rmorph_nat := rmorph_nat. Definition rmorph_eq_nat := rmorph_eq_nat. Definition rmorph_prod := rmorph_prod. Definition rmorphXn := rmorphXn. Definition rmorphN1 := rmorphN1. Definition rmorph_sign := rmorph_sign. Definition rmorph_pchar := rmorph_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")] Definition rmorph_char := rmorph_pchar. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `can2_monoid_morphism` instead")] Definition can2_rmorphism := can2_rmorphism. Definition can2_monoid_morphism := can2_monoid_morphism. Definition rmorph_comm := rmorph_comm. Definition rmorph_unit := rmorph_unit. Definition rmorphV := rmorphV. Definition rmorph_div := rmorph_div. Definition fmorph_eq0 := fmorph_eq0. Definition fmorph_inj := @fmorph_inj. Arguments fmorph_inj {F R} f [x1 x2]. Definition fmorph_eq := fmorph_eq. Definition fmorph_eq1 := fmorph_eq1. Definition fmorph_pchar := fmorph_pchar. #[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")] Definition fmorph_char := fmorph_pchar. Definition fmorph_unit := fmorph_unit. Definition fmorphV := fmorphV. Definition fmorph_div := fmorph_div. Definition scalerA := scalerA. Definition scale1r := @scale1r. Definition scalerDr := @scalerDr. Definition scalerDl := @scalerDl. Definition scaler0 := scaler0. Definition scale0r := @scale0r. Definition scaleNr := scaleNr. Definition scaleN1r := scaleN1r. Definition scalerN := scalerN. Definition scalerBl := scalerBl. Definition scalerBr := scalerBr. Definition scaler_nat := scaler_nat. Definition scalerMnl := scalerMnl. Definition scalerMnr := scalerMnr. Definition scaler_suml := scaler_suml. Definition scaler_sumr := scaler_sumr. Definition scaler_eq0 := scaler_eq0. Definition scalerK := scalerK. Definition scalerKV := scalerKV. Definition scalerI := scalerI. Definition scalerAl := @scalerAl. Definition mulr_algl := mulr_algl. Definition scaler_sign := scaler_sign. Definition signrZK := signrZK. Definition scalerCA := scalerCA. Definition scalerAr := @scalerAr. Definition mulr_algr := mulr_algr. Definition comm_alg := comm_alg. Definition exprZn := exprZn. Definition scaler_prodl := scaler_prodl. Definition scaler_prodr := scaler_prodr. Definition scaler_prod := scaler_prod. Definition scaler_injl := scaler_injl. Definition scaler_unit := scaler_unit. Definition invrZ := invrZ. Definition raddfZnat := raddfZnat. Definition raddfZsign := raddfZsign. Definition in_algE := in_algE. Definition scalable_for := scalable_for. Definition semilinear_for := semilinear_for. Definition linear_for := linear_for. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `nmod_morphism_semilinear` instead")] Definition additive_semilinear := additive_semilinear. Definition nmod_morphism_semilinear := nmod_morphism_semilinear. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism_linear` instead")] Definition additive_linear := additive_linear. Definition zmod_morphism_linear := zmod_morphism_linear. Definition scalable_semilinear := scalable_semilinear. Definition scalable_linear := scalable_linear. Definition linear0 := linear0. Definition linearN := linearN. Definition linearD := linearD. Definition linearB := linearB. Definition linear_sum := linear_sum. Definition linearMn := linearMn. Definition linearMNn := linearMNn. Definition semilinearP := semilinearP. Definition linearP := linearP. Definition linearZ_LR := linearZ_LR. Definition linearZ := linearZ. Definition semilinearPZ := semilinearPZ. Definition linearPZ := linearPZ. Definition linearZZ := linearZZ. Definition semiscalarP := semiscalarP. Definition scalarP := scalarP. Definition scalarZ := scalarZ. Definition can2_scalable := can2_scalable. Definition can2_linear := can2_linear. Definition can2_semilinear := can2_semilinear. Definition rmorph_alg := rmorph_alg. Definition imaginary_exists := imaginary_exists. Definition raddf := (raddf0, raddfN, raddfD, raddfMn). Definition rmorphE := (rmorphD, rmorph0, rmorphB, rmorphN, rmorphMNn, rmorphMn, rmorph1, rmorphXn). Definition linearE := (linearD, linear0, linearB, linearMNn, linearMn, linearZ). Notation null_fun V := (null_fun V) (only parsing). Notation in_alg A := (in_alg A) (only parsing). End Theory. Module AllExports. HB.reexport. End AllExports. End GRing. Export AllExports. Export Scale.Exports. Export ClosedExports. #[deprecated(since="mathcomp 2.4.0", note="Try pzSemiRingType (the potentially-zero counterpart) first, or use nzSemiRingType instead.")] Notation semiRingType := (nzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try pzRingType (the potentially-zero counterpart) first, or use nzRingType instead.")] Notation ringType := (nzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try comPzSemiRingType (the potentially-zero counterpart) first, or use comNzSemiRingType instead.")] Notation comSemiRingType := (comNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try comPzRingType (the potentially-zero counterpart) first, or use comNzRingType instead.")] Notation comRingType := (comNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subPzSemiRingType (the potentially-zero counterpart) first, or use subNzSemiRingType instead.")] Notation subSemiRingType := (subNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subComPzSemiRingType (the potentially-zero counterpart) first, or use subComNzSemiRingType instead.")] Notation subComSemiRingType := (subComNzSemiRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subPzRingType (the potentially-zero counterpart) first, or use subNzRingType instead.")] Notation subRingType := (subNzRingType) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Try subComPzRingType (the potentially-zero counterpart) first, or use subComNzRingType instead.")] Notation subComNzRingType := (subComNzRingType) (only parsing). Notation addrClosed := addrClosed. Notation opprClosed := opprClosed. Variant Ione := IOne : Ione. Inductive Inatmul := | INatmul : Ione -> nat -> Inatmul | IOpp : Inatmul -> Inatmul. Variant Idummy_placeholder :=. Definition parse (x : Number.int) : Inatmul := match x with | Number.IntDecimal (Decimal.Pos u) => INatmul IOne (Nat.of_uint u) | Number.IntDecimal (Decimal.Neg u) => IOpp (INatmul IOne (Nat.of_uint u)) | Number.IntHexadecimal (Hexadecimal.Pos u) => INatmul IOne (Nat.of_hex_uint u) | Number.IntHexadecimal (Hexadecimal.Neg u) => IOpp (INatmul IOne (Nat.of_hex_uint u)) end. Definition print (x : Inatmul) : option Number.int := match x with | INatmul IOne n => Some (Number.IntDecimal (Decimal.Pos (Nat.to_uint n))) | IOpp (INatmul IOne n) => Some (Number.IntDecimal (Decimal.Neg (Nat.to_uint n))) | _ => None end. Arguments GRing.one {_}. Set Warnings "-via-type-remapping,-via-type-mismatch". Number Notation Idummy_placeholder parse print (via Inatmul mapping [[natmul] => INatmul, [opp] => IOpp, [one] => IOne]) : ring_scope. Set Warnings "via-type-remapping,via-type-mismatch". Arguments GRing.one : clear implicits. Notation "0" := (@zero _) : ring_scope. Notation "-%R" := (@opp _) : ring_scope. Notation "- x" := (opp x) : ring_scope. Notation "+%R" := (@add _) : function_scope. Notation "x + y" := (add x y) : ring_scope. Notation "x - y" := (add x (- y)) : ring_scope. Arguments natmul : simpl never. Notation "x *+ n" := (natmul x n) : ring_scope. Notation "x *- n" := (opp (x *+ n)) : ring_scope. Notation "s `_ i" := (seq.nth 0%R s%R i) : ring_scope. Notation support := 0.-support. Notation "1" := (@one _) : ring_scope. Notation "- 1" := (opp 1) : ring_scope. Notation "n %:R" := (natmul 1 n) : ring_scope. Arguments GRing.pchar R%_type. Notation "[ 'pchar' R ]" := (GRing.pchar R) : ring_scope. #[deprecated(since="mathcomp 2.4.0", note="Use [pchar R] instead.")] Notation "[ 'char' R ]" := (GRing.pchar R) : ring_scope. Notation has_pchar0 R := (GRing.pchar R =i pred0). #[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")] Notation has_char0 R := (GRing.pchar R =i pred0). Notation pFrobenius_aut chRp := (pFrobenius_aut chRp). #[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")] Notation Frobenius_aut chRp := (pFrobenius_aut chRp). Notation "*%R" := (@mul _) : function_scope. Notation "x * y" := (mul x y) : ring_scope. Arguments exp : simpl never. Notation "x ^+ n" := (exp x n) : ring_scope. Notation "x ^-1" := (inv x) : ring_scope. Notation "x ^- n" := (inv (x ^+ n)) : ring_scope. Notation "x / y" := (mul x y^-1) : ring_scope. Notation "*:%R" := (@scale _ _) : function_scope. Notation "a *: m" := (scale a m) : ring_scope. Notation "k %:A" := (scale k 1) : ring_scope. Notation "\0" := (null_fun _) : ring_scope. Notation "f \+ g" := (add_fun f g) : ring_scope. Notation "f \- g" := (sub_fun f g) : ring_scope. Notation "\- f" := (opp_fun f) : ring_scope. Notation "a \*: f" := (scale_fun a f) : ring_scope. Notation "x \*o f" := (mull_fun x f) : ring_scope. Notation "x \o* f" := (mulr_fun x f) : ring_scope. Notation "f \* g" := (mul_fun f g) : ring_scope. Arguments mull_fun {_ _} a f _ /. Arguments mulr_fun {_ _} a f _ /. Arguments scale_fun {_ _ _} a f _ /. Arguments mul_fun {_ _} f g _ /. Notation "\sum_ ( i <- r | P ) F" := (\big[+%R/0%R]_(i <- r | P%B) F%R) : ring_scope. Notation "\sum_ ( i <- r ) F" := (\big[+%R/0%R]_(i <- r) F%R) : ring_scope. Notation "\sum_ ( m <= i < n | P ) F" := (\big[+%R/0%R]_(m <= i < n | P%B) F%R) : ring_scope. Notation "\sum_ ( m <= i < n ) F" := (\big[+%R/0%R]_(m <= i < n) F%R) : ring_scope. Notation "\sum_ ( i | P ) F" := (\big[+%R/0%R]_(i | P%B) F%R) : ring_scope. Notation "\sum_ i F" := (\big[+%R/0%R]_i F%R) : ring_scope. Notation "\sum_ ( i : t | P ) F" := (\big[+%R/0%R]_(i : t | P%B) F%R) (only parsing) : ring_scope. Notation "\sum_ ( i : t ) F" := (\big[+%R/0%R]_(i : t) F%R) (only parsing) : ring_scope. Notation "\sum_ ( i < n | P ) F" := (\big[+%R/0%R]_(i < n | P%B) F%R) : ring_scope. Notation "\sum_ ( i < n ) F" := (\big[+%R/0%R]_(i < n) F%R) : ring_scope. Notation "\sum_ ( i 'in' A | P ) F" := (\big[+%R/0%R]_(i in A | P%B) F%R) : ring_scope. Notation "\sum_ ( i 'in' A ) F" := (\big[+%R/0%R]_(i in A) F%R) : ring_scope. Notation "\prod_ ( i <- r | P ) F" := (\big[*%R/1%R]_(i <- r | P%B) F%R) : ring_scope. Notation "\prod_ ( i <- r ) F" := (\big[*%R/1%R]_(i <- r) F%R) : ring_scope. Notation "\prod_ ( m <= i < n | P ) F" := (\big[*%R/1%R]_(m <= i < n | P%B) F%R) : ring_scope. Notation "\prod_ ( m <= i < n ) F" := (\big[*%R/1%R]_(m <= i < n) F%R) : ring_scope. Notation "\prod_ ( i | P ) F" := (\big[*%R/1%R]_(i | P%B) F%R) : ring_scope. Notation "\prod_ i F" := (\big[*%R/1%R]_i F%R) : ring_scope. Notation "\prod_ ( i : t | P ) F" := (\big[*%R/1%R]_(i : t | P%B) F%R) (only parsing) : ring_scope. Notation "\prod_ ( i : t ) F" := (\big[*%R/1%R]_(i : t) F%R) (only parsing) : ring_scope. Notation "\prod_ ( i < n | P ) F" := (\big[*%R/1%R]_(i < n | P%B) F%R) : ring_scope. Notation "\prod_ ( i < n ) F" := (\big[*%R/1%R]_(i < n) F%R) : ring_scope. Notation "\prod_ ( i 'in' A | P ) F" := (\big[*%R/1%R]_(i in A | P%B) F%R) : ring_scope. Notation "\prod_ ( i 'in' A ) F" := (\big[*%R/1%R]_(i in A) F%R) : ring_scope. Notation "R ^c" := (converse R) : type_scope. Notation "R ^o" := (regular R) : type_scope. Bind Scope term_scope with term. Bind Scope term_scope with formula. Notation "''X_' i" := (Var _ i) : term_scope. Notation "n %:R" := (NatConst _ n) : term_scope. Notation "0" := 0%:R%T : term_scope. Notation "1" := 1%:R%T : term_scope. Notation "x %:T" := (Const x) : term_scope. Infix "+" := Add : term_scope. Notation "- t" := (Opp t) : term_scope. Notation "t - u" := (Add t (- u)) : term_scope. Infix "*" := Mul : term_scope. Infix "*+" := NatMul : term_scope. Notation "t ^-1" := (Inv t) : term_scope. Notation "t / u" := (Mul t u^-1) : term_scope. Infix "^+" := Exp : term_scope. Infix "==" := Equal : term_scope. Notation "x != y" := (GRing.Not (x == y)) : term_scope. Infix "/\" := And : term_scope. Infix "\/" := Or : term_scope. Infix "==>" := Implies : term_scope. Notation "~ f" := (Not f) : term_scope. Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope. Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope. (* Lifting Structure from the codomain of finfuns. *) Section Sum. Variables (aT : finType) (rT : nmodType). Variables (I : Type) (r : seq I) (P : pred I) (F : I -> {ffun aT -> rT}). Lemma sum_ffunE x : (\sum_(i <- r | P i) F i) x = \sum_(i <- r | P i) F i x. Proof. by elim/big_rec2: _ => // [|i _ y _ <-]; rewrite !ffunE. Qed. Lemma sum_ffun : \sum_(i <- r | P i) F i = [ffun x => \sum_(i <- r | P i) F i x]. Proof. by apply/ffunP=> i; rewrite sum_ffunE ffunE. Qed. End Sum. Section FinFunSemiRing. (* As rings require 1 != 0 in order to lift a ring structure over finfuns *) (* we need evidence that the domain is non-empty. *) Variable (aT : finType) (R : pzSemiRingType). Definition ffun_one : {ffun aT -> R} := [ffun => 1]. Definition ffun_mul (f g : {ffun aT -> R}) := [ffun x => f x * g x]. Fact ffun_mulA : associative ffun_mul. Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrA. Qed. Fact ffun_mul_1l : left_id ffun_one ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul1r. Qed. Fact ffun_mul_1r : right_id ffun_one ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr1. Qed. Fact ffun_mul_addl : left_distributive ffun_mul (@ffun_add _ _). Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDl. Qed. Fact ffun_mul_addr : right_distributive ffun_mul (@ffun_add _ _). Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDr. Qed. Fact ffun_mul_0l : left_zero (@ffun_zero _ _) ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul0r. Qed. Fact ffun_mul_0r : right_zero (@ffun_zero _ _) ffun_mul. Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr0. Qed. #[export] HB.instance Definition _ := Nmodule_isPzSemiRing.Build {ffun aT -> R} ffun_mulA ffun_mul_1l ffun_mul_1r ffun_mul_addl ffun_mul_addr ffun_mul_0l ffun_mul_0r. Definition ffun_semiring : pzSemiRingType := {ffun aT -> R}. End FinFunSemiRing. Section FinFunSemiRing. Variable (aT : finType) (R : nzSemiRingType) (a : aT). Fact ffun1_nonzero : ffun_one aT R != 0. Proof. by apply/eqP => /ffunP/(_ a)/eqP; rewrite !ffunE oner_eq0. Qed. (* TODO_HB uncomment once ffun_ring below is fixed #[export] HB.instance Definition _ := PzSemiRing_isNonZero.Build {ffun aT -> R} ffun1_nonzero. *) End FinFunSemiRing. HB.instance Definition _ (aT : finType) (R : pzRingType) := Zmodule_isPzRing.Build {ffun aT -> R} (@ffun_mulA _ _) (@ffun_mul_1l _ _) (@ffun_mul_1r _ _) (@ffun_mul_addl _ _) (@ffun_mul_addr _ _). (* As nzRings require 1 != 0 in order to lift a ring structure over finfuns *) (* we need evidence that the domain is non-empty. *) Section FinFunRing. Variable (aT : finType) (R : nzRingType) (a : aT). (* TODO_HB: doesn't work in combination with ffun_semiring above *) HB.instance Definition _ := PzSemiRing_isNonZero.Build {ffun aT -> R} (@ffun1_nonzero _ _ a). Definition ffun_ring : nzRingType := {ffun aT -> R}. End FinFunRing. (* TODO_HB do FinFunComSemiRing once above is fixed *) Section FinFunComRing. Variable (aT : finType) (R : comPzRingType) (a : aT). Fact ffun_mulC : commutative (@ffun_mul aT R). Proof. by move=> f1 f2; apply/ffunP=> i; rewrite !ffunE mulrC. Qed. (* TODO_HB #[export] HB.instance Definition _ := Ring_hasCommutativeMul.Build (ffun_ring _ a) ffun_mulC. *) End FinFunComRing. Section FinFunLSemiMod. Variable (R : pzSemiRingType) (aT : finType) (rT : lSemiModType R). Implicit Types f g : {ffun aT -> rT}. Definition ffun_scale k f := [ffun a => k *: f a]. Fact ffun_scaleA k1 k2 f : ffun_scale k1 (ffun_scale k2 f) = ffun_scale (k1 * k2) f. Proof. by apply/ffunP=> a; rewrite !ffunE scalerA. Qed. Fact ffun_scale0r f : ffun_scale 0 f = 0. Proof. by apply/ffunP=> a; rewrite !ffunE scale0r. Qed. Fact ffun_scale1 : left_id 1 ffun_scale. Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE scale1r. Qed. Fact ffun_scale_addr k : {morph (ffun_scale k) : x y / x + y}. Proof. by move=> f g; apply/ffunP=> a; rewrite !ffunE scalerDr. Qed. Fact ffun_scale_addl u : {morph (ffun_scale)^~ u : k1 k2 / k1 + k2}. Proof. by move=> k1 k2; apply/ffunP=> a; rewrite !ffunE scalerDl. Qed. #[export] HB.instance Definition _ := Nmodule_isLSemiModule.Build R {ffun aT -> rT} ffun_scaleA ffun_scale0r ffun_scale1 ffun_scale_addr ffun_scale_addl. End FinFunLSemiMod. #[export] HB.instance Definition _ (R : pzRingType) (aT : finType) (rT : lmodType R) := LSemiModule.on {ffun aT -> rT}. (* External direct product. *) Section PairSemiRing. Variables R1 R2 : pzSemiRingType. Definition mul_pair (x y : R1 * R2) := (x.1 * y.1, x.2 * y.2). Fact pair_mulA : associative mul_pair. Proof. by move=> x y z; congr (_, _); apply: mulrA. Qed. Fact pair_mul1l : left_id (1, 1) mul_pair. Proof. by case=> x1 x2; congr (_, _); apply: mul1r. Qed. Fact pair_mul1r : right_id (1, 1) mul_pair. Proof. by case=> x1 x2; congr (_, _); apply: mulr1. Qed. Fact pair_mulDl : left_distributive mul_pair +%R. Proof. by move=> x y z; congr (_, _); apply: mulrDl. Qed. Fact pair_mulDr : right_distributive mul_pair +%R. Proof. by move=> x y z; congr (_, _); apply: mulrDr. Qed. Fact pair_mul0r : left_zero 0 mul_pair. Proof. by move=> x; congr (_, _); apply: mul0r. Qed. Fact pair_mulr0 : right_zero 0 mul_pair. Proof. by move=> x; congr (_, _); apply: mulr0. Qed. #[export] HB.instance Definition _ := Nmodule_isPzSemiRing.Build (R1 * R2)%type pair_mulA pair_mul1l pair_mul1r pair_mulDl pair_mulDr pair_mul0r pair_mulr0. Fact fst_is_monoid_morphism : monoid_morphism fst. Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R1 fst fst_is_monoid_morphism. Fact snd_is_monoid_morphism : monoid_morphism snd. Proof. by []. Qed. #[export] HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R2 snd snd_is_monoid_morphism. End PairSemiRing. Section PairSemiRing. Variables R1 R2 : nzSemiRingType. Fact pair_one_neq0 : 1 != 0 :> R1 * R2. Proof. by rewrite xpair_eqE oner_eq0. Qed. #[export] HB.instance Definition _ := PzSemiRing_isNonZero.Build (R1 * R2)%type pair_one_neq0. End PairSemiRing. Section PairComSemiRing. Variables R1 R2 : comPzSemiRingType. Fact pair_mulC : commutative (@mul_pair R1 R2). Proof. by move=> x y; congr (_, _); apply: mulrC. Qed. #[export] HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build (R1 * R2)%type pair_mulC. End PairComSemiRing. (* TODO: HB.saturate *) #[export] HB.instance Definition _ (R1 R2 : comNzSemiRingType) := NzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : pzRingType) := PzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : nzRingType) := NzSemiRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : comPzRingType) := PzRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R1 R2 : comNzRingType) := NzRing.on (R1 * R2)%type. (* /TODO *) Section PairLSemiMod. Variables (R : pzSemiRingType) (V1 V2 : lSemiModType R). Definition scale_pair a (v : V1 * V2) : V1 * V2 := (a *: v.1, a *: v.2). Fact pair_scaleA a b u : scale_pair a (scale_pair b u) = scale_pair (a * b) u. Proof. by congr (_, _); apply: scalerA. Qed. Fact pair_scale0 u : scale_pair 0 u = 0. Proof. by case: u => u1 u2; congr (_, _); apply: scale0r. Qed. Fact pair_scale1 u : scale_pair 1 u = u. Proof. by case: u => u1 u2; congr (_, _); apply: scale1r. Qed. Fact pair_scaleDr : right_distributive scale_pair +%R. Proof. by move=> a u v; congr (_, _); apply: scalerDr. Qed. Fact pair_scaleDl u : {morph scale_pair^~ u: a b / a + b}. Proof. by move=> a b; congr (_, _); apply: scalerDl. Qed. #[export] HB.instance Definition _ := Nmodule_isLSemiModule.Build R (V1 * V2)%type pair_scaleA pair_scale0 pair_scale1 pair_scaleDr pair_scaleDl. Fact fst_is_scalable : scalable fst. Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R (V1 * V2)%type V1 *:%R fst fst_is_scalable. Fact snd_is_scalable : scalable snd. Proof. by []. Qed. #[export] HB.instance Definition _ := isScalable.Build R (V1 * V2)%type V2 *:%R snd snd_is_scalable. End PairLSemiMod. Section PairLSemiAlg. Variables (R : pzSemiRingType) (A1 A2 : lSemiAlgType R). Fact pair_scaleAl a (u v : A1 * A2) : a *: (u * v) = (a *: u) * v. Proof. by congr (_, _); apply: scalerAl. Qed. #[export] HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R (A1 * A2)%type pair_scaleAl. (* TODO: HB.saturate *) #[export] HB.instance Definition _ := RMorphism.on (@fst A1 A2). #[export] HB.instance Definition _ := RMorphism.on (@snd A1 A2). (* /TODO *) End PairLSemiAlg. Section PairSemiAlg. Variables (R : pzSemiRingType) (A1 A2 : semiAlgType R). Fact pair_scaleAr a (u v : A1 * A2) : a *: (u * v) = u * (a *: v). Proof. by congr (_, _); apply: scalerAr. Qed. #[export] HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R (A1 * A2)%type pair_scaleAr. End PairSemiAlg. Section PairUnitRing. Variables R1 R2 : unitRingType. Definition pair_unitr := [qualify a x : R1 * R2 | (x.1 \is a GRing.unit) && (x.2 \is a GRing.unit)]. Definition pair_invr x := if x \is a pair_unitr then (x.1^-1, x.2^-1) else x. Lemma pair_mulVl : {in pair_unitr, left_inverse 1 pair_invr *%R}. Proof. rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _. by congr (_, _); apply: mulVr. Qed. Lemma pair_mulVr : {in pair_unitr, right_inverse 1 pair_invr *%R}. Proof. rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _. by congr (_, _); apply: mulrV. Qed. Lemma pair_unitP x y : y * x = 1 /\ x * y = 1 -> x \is a pair_unitr. Proof. case=> [[y1x y2x] [x1y x2y]]; apply/andP. by split; apply/unitrP; [exists y.1 | exists y.2]. Qed. Lemma pair_invr_out : {in [predC pair_unitr], pair_invr =1 id}. Proof. by rewrite /pair_invr => x /negPf/= ->. Qed. #[export] HB.instance Definition _ := NzRing_hasMulInverse.Build (R1 * R2)%type pair_mulVl pair_mulVr pair_unitP pair_invr_out. End PairUnitRing. (* TODO: HB.saturate *) #[export] HB.instance Definition _ (R1 R2 : comUnitRingType) := UnitRing.on (R1 * R2)%type. #[export] HB.instance Definition _ (R : pzSemiRingType) (A1 A2 : comSemiAlgType R) := SemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (V1 V2 : lmodType R) := LSemiModule.on (V1 * V2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : lalgType R) := LSemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : algType R) := SemiAlgebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : comAlgType R) := Algebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : unitAlgType R) := Algebra.on (A1 * A2)%type. #[export] HB.instance Definition _ (R : pzRingType) (A1 A2 : comUnitAlgType R) := Algebra.on (A1 * A2)%type. (* /TODO *) Lemma pairMnE (M1 M2 : zmodType) (x : M1 * M2) n : x *+ n = (x.1 *+ n, x.2 *+ n). Proof. by case: x => x y; elim: n => //= n; rewrite !mulrS => ->. Qed. (* begin hide *) (* Testing subtype hierarchy Section Test0. Variables (T : choiceType) (S : {pred T}). Inductive B := mkB x & x \in S. Definition vB u := let: mkB x _ := u in x. HB.instance Definition _ := [isSub for vB]. HB.instance Definition _ := [Choice of B by <:]. End Test0. Section Test1. Variables (R : unitRingType) (S : divringClosed R). HB.instance Definition _ := [SubChoice_isSubUnitRing of B S by <:]. End Test1. Section Test2. Variables (R : comUnitRingType) (A : unitAlgType R) (S : divalgClosed A). HB.instance Definition _ := [SubZmodule_isSubLmodule of B S by <:]. HB.instance Definition _ := [SubNzRing_SubLmodule_isSubLalgebra of B S by <:]. HB.instance Definition _ := [SubLalgebra_isSubAlgebra of B S by <:]. End Test2. Section Test3. Variables (F : fieldType) (S : divringClosed F). HB.instance Definition _ := [SubRing_isSubComNzRing of B S by <:]. HB.instance Definition _ := [SubComUnitRing_isSubIntegralDomain of B S by <:]. HB.instance Definition _ := [SubIntegralDomain_isSubField of B S by <:]. End Test3. *) (* end hide *) (* Algebraic structure of bool *) HB.instance Definition _ := Zmodule_isComNzRing.Build bool andbA andbC andTb andb_addl isT. Fact mulVb (b : bool) : b != 0 -> b * b = 1. Proof. by case: b. Qed. Fact invb_out (x y : bool) : y * x = 1 -> x != 0. Proof. by case: x; case: y. Qed. HB.instance Definition _ := ComNzRing_hasMulInverse.Build bool mulVb invb_out (fun x => fun => erefl x). Lemma bool_fieldP : Field.axiom bool. Proof. by []. Qed. HB.instance Definition _ := ComUnitRing_isField.Build bool bool_fieldP. (* Algebraic structure of nat *) HB.instance Definition _ := Nmodule_isComNzSemiRing.Build nat mulnA mulnC mul1n mulnDl mul0n erefl. HB.instance Definition _ (R : pzSemiRingType) := isMonoidMorphism.Build nat R (natmul 1) (mulr1n 1, natrM R). Lemma natr0E : 0 = 0%N. Proof. by []. Qed. Lemma natr1E : 1 = 1%N. Proof. by []. Qed. Lemma natn n : n%:R = n. Proof. by elim: n => [//|n IHn]; rewrite -nat1r IHn. Qed. Lemma natrDE n m : n + m = (n + m)%N. Proof. by []. Qed. Lemma natrME n m : n * m = (n * m)%N. Proof. by []. Qed. Lemma natrXE n m : n ^+ m = (n ^ m)%N. Proof. by []. Qed. Definition natrE := (natr0E, natr1E, natn, natrDE, natrME, natrXE).
LinearMap.lean
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.LinearAlgebra.Trace /-! # Linear maps between direct sums This file contains results about linear maps which respect direct sum decompositions of their domain and codomain. -/ open DirectSum Module Set namespace LinearMap variable {ι R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {N : ι → Submodule R M} section IsInternal variable [DecidableEq ι] /-- If a linear map `f : M₁ → M₂` respects direct sum decompositions of `M₁` and `M₂`, then it has a block diagonal matrix with respect to bases compatible with the direct sum decompositions. -/ lemma toMatrix_directSum_collectedBasis_eq_blockDiagonal' {R M₁ M₂ : Type*} [CommSemiring R] [AddCommMonoid M₁] [Module R M₁] {N₁ : ι → Submodule R M₁} (h₁ : IsInternal N₁) [AddCommMonoid M₂] [Module R M₂] {N₂ : ι → Submodule R M₂} (h₂ : IsInternal N₂) {κ₁ κ₂ : ι → Type*} [∀ i, Fintype (κ₁ i)] [∀ i, Finite (κ₂ i)] [∀ i, DecidableEq (κ₁ i)] [Fintype ι] (b₁ : (i : ι) → Basis (κ₁ i) R (N₁ i)) (b₂ : (i : ι) → Basis (κ₂ i) R (N₂ i)) {f : M₁ →ₗ[R] M₂} (hf : ∀ i, MapsTo f (N₁ i) (N₂ i)) : toMatrix (h₁.collectedBasis b₁) (h₂.collectedBasis b₂) f = Matrix.blockDiagonal' fun i ↦ toMatrix (b₁ i) (b₂ i) (f.restrict (hf i)) := by ext ⟨i, _⟩ ⟨j, _⟩ simp only [toMatrix_apply, Matrix.blockDiagonal'_apply] rcases eq_or_ne i j with rfl | hij · simp [h₂.collectedBasis_repr_of_mem _ (hf _ (Subtype.mem _)), restrict_apply] · simp [hij, h₂.collectedBasis_repr_of_mem_ne _ hij.symm (hf _ (Subtype.mem _))] lemma diag_toMatrix_directSum_collectedBasis_eq_zero_of_mapsTo_ne {κ : ι → Type*} [∀ i, Fintype (κ i)] [∀ i, DecidableEq (κ i)] {s : Finset ι} (h : IsInternal fun i : s ↦ N i) (b : (i : s) → Basis (κ i) R (N i)) (σ : ι → ι) (hσ : ∀ i, σ i ≠ i) {f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N <| σ i)) (hN : ∀ i, i ∉ s → N i = ⊥) : Matrix.diag (toMatrix (h.collectedBasis b) (h.collectedBasis b) f) = 0 := by ext ⟨i, k⟩ simp only [Matrix.diag_apply, Pi.zero_apply, toMatrix_apply, IsInternal.collectedBasis_coe] by_cases hi : σ i ∈ s · let j : s := ⟨σ i, hi⟩ replace hσ : j ≠ i := fun hij ↦ hσ i <| Subtype.ext_iff.mp hij exact h.collectedBasis_repr_of_mem_ne b hσ <| hf _ <| Subtype.mem (b i k) · suffices f (b i k) = 0 by simp [this] simpa [hN _ hi] using hf i <| Subtype.mem (b i k) variable [∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)] /-- The trace of an endomorphism of a direct sum is the sum of the traces on each component. See also `LinearMap.trace_restrict_eq_sum_trace_restrict`. -/ lemma trace_eq_sum_trace_restrict (h : IsInternal N) [Fintype ι] {f : M →ₗ[R] M} (hf : ∀ i, MapsTo f (N i) (N i)) : trace R M f = ∑ i, trace R (N i) (f.restrict (hf i)) := by let b : (i : ι) → Basis _ R (N i) := fun i ↦ Module.Free.chooseBasis R (N i) simp_rw [trace_eq_matrix_trace R (h.collectedBasis b), toMatrix_directSum_collectedBasis_eq_blockDiagonal' h h b b hf, Matrix.trace_blockDiagonal', ← trace_eq_matrix_trace] lemma trace_eq_sum_trace_restrict' (h : IsInternal N) (hN : {i | N i ≠ ⊥}.Finite) {f : M →ₗ[R] M} (hf : ∀ i, MapsTo f (N i) (N i)) : trace R M f = ∑ i ∈ hN.toFinset, trace R (N i) (f.restrict (hf i)) := by let _ : Fintype {i // N i ≠ ⊥} := hN.fintype let _ : Fintype {i | N i ≠ ⊥} := hN.fintype rw [← Finset.sum_coe_sort, trace_eq_sum_trace_restrict (isInternal_ne_bot_iff.mpr h) _] exact Fintype.sum_equiv hN.subtypeEquivToFinset _ _ (fun i ↦ rfl) lemma trace_eq_zero_of_mapsTo_ne (h : IsInternal N) [IsNoetherian R M] (σ : ι → ι) (hσ : ∀ i, σ i ≠ i) {f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N <| σ i)) : trace R M f = 0 := by have hN : {i | N i ≠ ⊥}.Finite := WellFoundedGT.finite_ne_bot_of_iSupIndep h.submodule_iSupIndep let s := hN.toFinset let κ := fun i ↦ Module.Free.ChooseBasisIndex R (N i) let b : (i : s) → Basis (κ i) R (N i) := fun i ↦ Module.Free.chooseBasis R (N i) replace h : IsInternal fun i : s ↦ N i := by convert DirectSum.isInternal_ne_bot_iff.mpr h <;> simp [s] simp_rw [trace_eq_matrix_trace R (h.collectedBasis b), Matrix.trace, diag_toMatrix_directSum_collectedBasis_eq_zero_of_mapsTo_ne h b σ hσ hf (by simp [s]), Pi.zero_apply, Finset.sum_const_zero] /-- If `f` and `g` are commuting endomorphisms of a finite, free `R`-module `M`, such that `f` is triangularizable, then to prove that the trace of `g ∘ f` vanishes, it is sufficient to prove that the trace of `g` vanishes on each generalized eigenspace of `f`. -/ lemma trace_comp_eq_zero_of_commute_of_trace_restrict_eq_zero [IsDomain R] [IsPrincipalIdealRing R] [Module.Free R M] [Module.Finite R M] {f g : Module.End R M} (h_comm : Commute f g) (hf : ⨆ μ, f.maxGenEigenspace μ = ⊤) (hg : ∀ μ, trace R _ (g.restrict (f.mapsTo_maxGenEigenspace_of_comm h_comm μ)) = 0) : trace R _ (g ∘ₗ f) = 0 := by have hfg : ∀ μ, MapsTo (g ∘ₗ f) ↑(f.maxGenEigenspace μ) ↑(f.maxGenEigenspace μ) := fun μ ↦ (f.mapsTo_maxGenEigenspace_of_comm h_comm μ).comp (f.mapsTo_maxGenEigenspace_of_comm rfl μ) suffices ∀ μ, trace R _ ((g ∘ₗ f).restrict (hfg μ)) = 0 by classical have hds := DirectSum.isInternal_submodule_of_iSupIndep_of_iSup_eq_top f.independent_maxGenEigenspace hf have h_fin : {μ | f.maxGenEigenspace μ ≠ ⊥}.Finite := WellFoundedGT.finite_ne_bot_of_iSupIndep f.independent_maxGenEigenspace simp [trace_eq_sum_trace_restrict' hds h_fin hfg, this] intro μ replace h_comm : Commute (g.restrict (f.mapsTo_maxGenEigenspace_of_comm h_comm μ)) (f.restrict (f.mapsTo_maxGenEigenspace_of_comm rfl μ)) := restrict_commute h_comm.symm _ _ rw [restrict_comp, trace_comp_eq_mul_of_commute_of_isNilpotent μ h_comm (f.isNilpotent_restrict_maxGenEigenspace_sub_algebraMap μ), hg, mul_zero] lemma mapsTo_biSup_of_mapsTo {ι : Type*} {N : ι → Submodule R M} (s : Set ι) {f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N i)) : MapsTo f ↑(⨆ i ∈ s, N i) ↑(⨆ i ∈ s, N i) := by replace hf : ∀ i, (N i).map f ≤ N i := fun i ↦ Submodule.map_le_iff_le_comap.mpr (hf i) suffices (⨆ i ∈ s, N i).map f ≤ ⨆ i ∈ s, N i from Submodule.map_le_iff_le_comap.mp this simpa only [Submodule.map_iSup] using iSup₂_mono <| fun i _ ↦ hf i end IsInternal /-- The trace of an endomorphism of a direct sum is the sum of the traces on each component. Note that it is important the statement gives the user definitional control over `p` since the _type_ of the term `trace R p (f.restrict hp')` depends on `p`. -/ lemma trace_eq_sum_trace_restrict_of_eq_biSup [∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)] (s : Finset ι) (h : iSupIndep <| fun i : s ↦ N i) {f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N i)) (p : Submodule R M) (hp : p = ⨆ i ∈ s, N i) (hp' : MapsTo f p p := hp ▸ mapsTo_biSup_of_mapsTo (s : Set ι) hf) : trace R p (f.restrict hp') = ∑ i ∈ s, trace R (N i) (f.restrict (hf i)) := by classical let N' : s → Submodule R p := fun i ↦ (N i).comap p.subtype replace h : IsInternal N' := hp ▸ isInternal_biSup_submodule_of_iSupIndep (s : Set ι) h have hf' : ∀ i, MapsTo (restrict f hp') (N' i) (N' i) := fun i x hx' ↦ by simpa using hf i hx' let e : (i : s) → N' i ≃ₗ[R] N i := fun ⟨i, hi⟩ ↦ (N i).comapSubtypeEquivOfLe (hp ▸ le_biSup N hi) have _i1 : ∀ i, Module.Finite R (N' i) := fun i ↦ Module.Finite.equiv (e i).symm have _i2 : ∀ i, Module.Free R (N' i) := fun i ↦ Module.Free.of_equiv (e i).symm rw [trace_eq_sum_trace_restrict h hf', ← s.sum_coe_sort] have : ∀ i : s, f.restrict (hf i) = (e i).conj ((f.restrict hp').restrict (hf' i)) := fun _ ↦ rfl simp [this] end LinearMap
StructureSheaf.lean
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.AlgebraicGeometry.ProjectiveSpectrum.Topology import Mathlib.Topology.Sheaves.LocalPredicate import Mathlib.RingTheory.GradedAlgebra.HomogeneousLocalization import Mathlib.Geometry.RingedSpace.LocallyRingedSpace /-! # The structure sheaf on `ProjectiveSpectrum 𝒜`. In `Mathlib/AlgebraicGeometry/Topology.lean`, we have given a topology on `ProjectiveSpectrum 𝒜`; in this file we will construct a sheaf on `ProjectiveSpectrum 𝒜`. ## Notation - `R` is a commutative semiring; - `A` is a commutative ring and an `R`-algebra; - `𝒜 : ℕ → Submodule R A` is the grading of `A`; - `U` is opposite object of some open subset of `ProjectiveSpectrum.top`. ## Main definitions and results We define the structure sheaf as the subsheaf of all dependent function `f : Π x : U, HomogeneousLocalization 𝒜 x` such that `f` is locally expressible as ratio of two elements of the *same grading*, i.e. `∀ y ∈ U, ∃ (V ⊆ U) (i : ℕ) (a b ∈ 𝒜 i), ∀ z ∈ V, f z = a / b`. * `AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf.isLocallyFraction`: the predicate that a dependent function is locally expressible as a ratio of two elements of the same grading. * `AlgebraicGeometry.ProjectiveSpectrum.StructureSheaf.sectionsSubring`: the dependent functions satisfying the above local property forms a subring of all dependent functions `Π x : U, HomogeneousLocalization 𝒜 x`. * `AlgebraicGeometry.Proj.StructureSheaf`: the sheaf with `U ↦ sectionsSubring U` and natural restriction map. Then we establish that `Proj 𝒜` is a `LocallyRingedSpace`: * `AlgebraicGeometry.Proj.stalkIso'`: for any `x : ProjectiveSpectrum 𝒜`, the stalk of `Proj.StructureSheaf` at `x` is isomorphic to `HomogeneousLocalization 𝒜 x`. * `AlgebraicGeometry.Proj.toLocallyRingedSpace`: `Proj` as a locally ringed space. ## References * [Robin Hartshorne, *Algebraic Geometry*][Har77] -/ noncomputable section namespace AlgebraicGeometry open scoped DirectSum Pointwise open DirectSum SetLike Localization TopCat TopologicalSpace CategoryTheory Opposite variable {R A : Type*} variable [CommRing R] [CommRing A] [Algebra R A] variable (𝒜 : ℕ → Submodule R A) [GradedAlgebra 𝒜] local notation3 "at " x => HomogeneousLocalization.AtPrime 𝒜 (HomogeneousIdeal.toIdeal (ProjectiveSpectrum.asHomogeneousIdeal x)) namespace ProjectiveSpectrum.StructureSheaf variable {𝒜} in /-- The predicate saying that a dependent function on an open `U` is realised as a fixed fraction `r / s` of *same grading* in each of the stalks (which are localizations at various prime ideals). -/ def IsFraction {U : Opens (ProjectiveSpectrum.top 𝒜)} (f : ∀ x : U, at x.1) : Prop := ∃ (i : ℕ) (r s : 𝒜 i) (s_nin : ∀ x : U, s.1 ∉ x.1.asHomogeneousIdeal), ∀ x : U, f x = .mk ⟨i, r, s, s_nin x⟩ /-- The predicate `IsFraction` is "prelocal", in the sense that if it holds on `U` it holds on any open subset `V` of `U`. -/ def isFractionPrelocal : PrelocalPredicate fun x : ProjectiveSpectrum.top 𝒜 => at x where pred f := IsFraction f res := by rintro V U i f ⟨j, r, s, h, w⟩; exact ⟨j, r, s, (h <| i ·), (w <| i ·)⟩ /-- We will define the structure sheaf as the subsheaf of all dependent functions in `Π x : U, HomogeneousLocalization 𝒜 x` consisting of those functions which can locally be expressed as a ratio of `A` of same grading. -/ def isLocallyFraction : LocalPredicate fun x : ProjectiveSpectrum.top 𝒜 => at x := (isFractionPrelocal 𝒜).sheafify namespace SectionSubring variable {𝒜} open Submodule SetLike.GradedMonoid HomogeneousLocalization theorem zero_mem' (U : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ) : (isLocallyFraction 𝒜).pred (0 : ∀ x : U.unop, at x.1) := fun x => ⟨unop U, x.2, 𝟙 (unop U), ⟨0, ⟨0, zero_mem _⟩, ⟨1, one_mem_graded _⟩, _, fun _ => rfl⟩⟩ theorem one_mem' (U : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ) : (isLocallyFraction 𝒜).pred (1 : ∀ x : U.unop, at x.1) := fun x => ⟨unop U, x.2, 𝟙 (unop U), ⟨0, ⟨1, one_mem_graded _⟩, ⟨1, one_mem_graded _⟩, _, fun _ => rfl⟩⟩ theorem add_mem' (U : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ) (a b : ∀ x : U.unop, at x.1) (ha : (isLocallyFraction 𝒜).pred a) (hb : (isLocallyFraction 𝒜).pred b) : (isLocallyFraction 𝒜).pred (a + b) := fun x => by rcases ha x with ⟨Va, ma, ia, ja, ⟨ra, ra_mem⟩, ⟨sa, sa_mem⟩, hwa, wa⟩ rcases hb x with ⟨Vb, mb, ib, jb, ⟨rb, rb_mem⟩, ⟨sb, sb_mem⟩, hwb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ja + jb, ⟨sb * ra + sa * rb, add_mem (add_comm jb ja ▸ mul_mem_graded sb_mem ra_mem : sb * ra ∈ 𝒜 (ja + jb)) (mul_mem_graded sa_mem rb_mem)⟩, ⟨sa * sb, mul_mem_graded sa_mem sb_mem⟩, fun y ↦ y.1.asHomogeneousIdeal.toIdeal.primeCompl.mul_mem (hwa ⟨y.1, y.2.1⟩) (hwb ⟨y.1, y.2.2⟩), ?_⟩ rintro ⟨y, hy⟩ simp only [Subtype.forall, Opens.apply_mk] at wa wb simp [wa y hy.1, wb y hy.2, ext_iff_val, add_mk, add_comm (sa * rb)] theorem neg_mem' (U : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ) (a : ∀ x : U.unop, at x.1) (ha : (isLocallyFraction 𝒜).pred a) : (isLocallyFraction 𝒜).pred (-a) := fun x => by rcases ha x with ⟨V, m, i, j, ⟨r, r_mem⟩, ⟨s, s_mem⟩, nin, hy⟩ refine ⟨V, m, i, j, ⟨-r, Submodule.neg_mem _ r_mem⟩, ⟨s, s_mem⟩, nin, fun y => ?_⟩ simp only [ext_iff_val, val_mk] at hy simp only [Pi.neg_apply, ext_iff_val, val_neg, hy, val_mk, neg_mk] theorem mul_mem' (U : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ) (a b : ∀ x : U.unop, at x.1) (ha : (isLocallyFraction 𝒜).pred a) (hb : (isLocallyFraction 𝒜).pred b) : (isLocallyFraction 𝒜).pred (a * b) := fun x => by rcases ha x with ⟨Va, ma, ia, ja, ⟨ra, ra_mem⟩, ⟨sa, sa_mem⟩, hwa, wa⟩ rcases hb x with ⟨Vb, mb, ib, jb, ⟨rb, rb_mem⟩, ⟨sb, sb_mem⟩, hwb, wb⟩ refine ⟨Va ⊓ Vb, ⟨ma, mb⟩, Opens.infLELeft _ _ ≫ ia, ja + jb, ⟨ra * rb, SetLike.mul_mem_graded ra_mem rb_mem⟩, ⟨sa * sb, SetLike.mul_mem_graded sa_mem sb_mem⟩, fun y => y.1.asHomogeneousIdeal.toIdeal.primeCompl.mul_mem (hwa ⟨y.1, y.2.1⟩) (hwb ⟨y.1, y.2.2⟩), ?_⟩ rintro ⟨y, hy⟩ simp only [Subtype.forall, Opens.apply_mk] at wa wb simp [wa y hy.1, wb y hy.2, ext_iff_val, Localization.mk_mul] end SectionSubring section open SectionSubring variable {𝒜} /-- The functions satisfying `isLocallyFraction` form a subring of all dependent functions `Π x : U, HomogeneousLocalization 𝒜 x`. -/ def sectionsSubring (U : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ) : Subring (∀ x : U.unop, at x.1) where carrier := {f | (isLocallyFraction 𝒜).pred f} zero_mem' := zero_mem' U one_mem' := one_mem' U add_mem' := add_mem' U _ _ neg_mem' := neg_mem' U _ mul_mem' := mul_mem' U _ _ end /-- The structure sheaf (valued in `Type`, not yet `CommRing`) is the subsheaf consisting of functions satisfying `isLocallyFraction`. -/ def structureSheafInType : Sheaf (Type _) (ProjectiveSpectrum.top 𝒜) := subsheafToTypes (isLocallyFraction 𝒜) instance commRingStructureSheafInTypeObj (U : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ) : CommRing ((structureSheafInType 𝒜).1.obj U) := (sectionsSubring U).toCommRing /-- The structure presheaf, valued in `CommRing`, constructed by dressing up the `Type` valued structure presheaf. -/ @[simps obj_carrier] def structurePresheafInCommRing : Presheaf CommRingCat (ProjectiveSpectrum.top 𝒜) where obj U := CommRingCat.of ((structureSheafInType 𝒜).1.obj U) map i := CommRingCat.ofHom { toFun := (structureSheafInType 𝒜).1.map i map_zero' := rfl map_add' := fun _ _ => rfl map_one' := rfl map_mul' := fun _ _ => rfl } /-- Some glue, verifying that the structure presheaf valued in `CommRing` agrees with the `Type` valued structure presheaf. -/ def structurePresheafCompForget : structurePresheafInCommRing 𝒜 ⋙ forget CommRingCat ≅ (structureSheafInType 𝒜).1 := NatIso.ofComponents (fun _ => Iso.refl _) (by cat_disch) end ProjectiveSpectrum.StructureSheaf namespace ProjectiveSpectrum open TopCat.Presheaf ProjectiveSpectrum.StructureSheaf Opens /-- The structure sheaf on `Proj` 𝒜, valued in `CommRing`. -/ def Proj.structureSheaf : Sheaf CommRingCat (ProjectiveSpectrum.top 𝒜) := ⟨structurePresheafInCommRing 𝒜, (-- We check the sheaf condition under `forget CommRing`. isSheaf_iff_isSheaf_comp _ _).mpr (isSheaf_of_iso (structurePresheafCompForget 𝒜).symm (structureSheafInType 𝒜).cond)⟩ end ProjectiveSpectrum section open ProjectiveSpectrum ProjectiveSpectrum.StructureSheaf Opens section variable {U V : (Opens (ProjectiveSpectrum.top 𝒜))ᵒᵖ} (i : V ⟶ U) (s t : (Proj.structureSheaf 𝒜).1.obj V) (x : V.unop) @[simp] theorem Proj.res_apply (x) : ((Proj.structureSheaf 𝒜).1.map i s).1 x = s.1 (i.unop x) := rfl @[ext] theorem Proj.ext (h : s.1 = t.1) : s = t := Subtype.ext h @[simp] theorem Proj.add_apply : (s + t).1 x = s.1 x + t.1 x := rfl @[simp] theorem Proj.mul_apply : (s * t).1 x = s.1 x * t.1 x := rfl @[simp] theorem Proj.sub_apply : (s - t).1 x = s.1 x - t.1 x := rfl @[simp] theorem Proj.pow_apply (n : ℕ) : (s ^ n).1 x = s.1 x ^ n := rfl @[simp] theorem Proj.zero_apply : (0 : (Proj.structureSheaf 𝒜).1.obj V).1 x = 0 := rfl @[simp] theorem Proj.one_apply : (1 : (Proj.structureSheaf 𝒜).1.obj V).1 x = 1 := rfl end /-- `Proj` of a graded ring as a `SheafedSpace` -/ def Proj.toSheafedSpace : SheafedSpace CommRingCat where carrier := TopCat.of (ProjectiveSpectrum 𝒜) presheaf := (Proj.structureSheaf 𝒜).1 IsSheaf := (Proj.structureSheaf 𝒜).2 /-- The ring homomorphism that takes a section of the structure sheaf of `Proj` on the open set `U`, implemented as a subtype of dependent functions to localizations at homogeneous prime ideals, and evaluates the section on the point corresponding to a given homogeneous prime ideal. -/ def openToLocalization (U : Opens (ProjectiveSpectrum.top 𝒜)) (x : ProjectiveSpectrum.top 𝒜) (hx : x ∈ U) : (Proj.structureSheaf 𝒜).1.obj (op U) ⟶ CommRingCat.of (at x) := CommRingCat.ofHom { toFun s := (s.1 ⟨x, hx⟩ :) map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl } /-- The ring homomorphism from the stalk of the structure sheaf of `Proj` at a point corresponding to a homogeneous prime ideal `x` to the *homogeneous localization* at `x`, formed by gluing the `openToLocalization` maps. -/ def stalkToFiberRingHom (x : ProjectiveSpectrum.top 𝒜) : (Proj.structureSheaf 𝒜).presheaf.stalk x ⟶ CommRingCat.of (at x) := Limits.colimit.desc ((OpenNhds.inclusion x).op ⋙ (Proj.structureSheaf 𝒜).1) { pt := _ ι := { app := fun U => openToLocalization 𝒜 ((OpenNhds.inclusion _).obj U.unop) x U.unop.2 } } @[simp] theorem germ_comp_stalkToFiberRingHom (U : Opens (ProjectiveSpectrum.top 𝒜)) (x : ProjectiveSpectrum.top 𝒜) (hx : x ∈ U) : (Proj.structureSheaf 𝒜).presheaf.germ U x hx ≫ stalkToFiberRingHom 𝒜 x = openToLocalization 𝒜 U x hx := Limits.colimit.ι_desc _ _ @[simp] theorem stalkToFiberRingHom_germ (U : Opens (ProjectiveSpectrum.top 𝒜)) (x : ProjectiveSpectrum.top 𝒜) (hx : x ∈ U) (s : (Proj.structureSheaf 𝒜).1.obj (op U)) : stalkToFiberRingHom 𝒜 x ((Proj.structureSheaf 𝒜).presheaf.germ _ x hx s) = s.1 ⟨x, hx⟩ := RingHom.ext_iff.1 (CommRingCat.hom_ext_iff.mp (germ_comp_stalkToFiberRingHom 𝒜 U x hx)) s theorem mem_basicOpen_den (x : ProjectiveSpectrum.top 𝒜) (f : HomogeneousLocalization.NumDenSameDeg 𝒜 x.asHomogeneousIdeal.toIdeal.primeCompl) : x ∈ ProjectiveSpectrum.basicOpen 𝒜 f.den := by rw [ProjectiveSpectrum.mem_basicOpen] exact f.den_mem /-- Given a point `x` corresponding to a homogeneous prime ideal, there is a (dependent) function such that, for any `f` in the homogeneous localization at `x`, it returns the obvious section in the basic open set `D(f.den)`. -/ def sectionInBasicOpen (x : ProjectiveSpectrum.top 𝒜) : ∀ f : HomogeneousLocalization.NumDenSameDeg 𝒜 x.asHomogeneousIdeal.toIdeal.primeCompl, (Proj.structureSheaf 𝒜).1.obj (op (ProjectiveSpectrum.basicOpen 𝒜 f.den)) := fun f => ⟨fun y => HomogeneousLocalization.mk ⟨f.deg, f.num, f.den, y.2⟩, fun y => ⟨ProjectiveSpectrum.basicOpen 𝒜 f.den, y.2, ⟨𝟙 _, ⟨f.deg, ⟨f.num, f.den, _, fun _ => rfl⟩⟩⟩⟩⟩ open HomogeneousLocalization in /-- Given any point `x` and `f` in the homogeneous localization at `x`, there is an element in the stalk at `x` obtained by `sectionInBasicOpen`. This is the inverse of `stalkToFiberRingHom`. -/ def homogeneousLocalizationToStalk (x : ProjectiveSpectrum.top 𝒜) (y : at x) : (Proj.structureSheaf 𝒜).presheaf.stalk x := Quotient.liftOn' y (fun f => (Proj.structureSheaf 𝒜).presheaf.germ _ x (mem_basicOpen_den _ x f) (sectionInBasicOpen _ x f)) fun f g (e : f.embedding = g.embedding) ↦ by simp only [HomogeneousLocalization.NumDenSameDeg.embedding, Localization.mk_eq_mk', IsLocalization.mk'_eq_iff_eq, IsLocalization.eq_iff_exists x.asHomogeneousIdeal.toIdeal.primeCompl] at e obtain ⟨⟨c, hc⟩, hc'⟩ := e apply (Proj.structureSheaf 𝒜).presheaf.germ_ext (ProjectiveSpectrum.basicOpen 𝒜 f.den.1 ⊓ ProjectiveSpectrum.basicOpen 𝒜 g.den.1 ⊓ ProjectiveSpectrum.basicOpen 𝒜 c) ⟨⟨mem_basicOpen_den _ x f, mem_basicOpen_den _ x g⟩, hc⟩ (homOfLE inf_le_left ≫ homOfLE inf_le_left) (homOfLE inf_le_left ≫ homOfLE inf_le_right) apply Subtype.ext ext ⟨t, ⟨htf, htg⟩, ht'⟩ rw [Proj.res_apply, Proj.res_apply] simp only [sectionInBasicOpen, HomogeneousLocalization.val_mk, Localization.mk_eq_mk', IsLocalization.mk'_eq_iff_eq] apply (IsLocalization.map_units (M := t.asHomogeneousIdeal.toIdeal.primeCompl) (Localization t.asHomogeneousIdeal.toIdeal.primeCompl) ⟨c, ht'⟩).mul_left_cancel rw [← map_mul, ← map_mul, hc'] lemma homogeneousLocalizationToStalk_stalkToFiberRingHom (x z) : homogeneousLocalizationToStalk 𝒜 x (stalkToFiberRingHom 𝒜 x z) = z := by obtain ⟨U, hxU, s, rfl⟩ := (Proj.structureSheaf 𝒜).presheaf.germ_exist x z change homogeneousLocalizationToStalk 𝒜 x ((stalkToFiberRingHom 𝒜 x).hom (((Proj.structureSheaf 𝒜).presheaf.germ U x hxU) s)) = ((Proj.structureSheaf 𝒜).presheaf.germ U x hxU) s obtain ⟨V, hxV, i, n, a, b, h, e⟩ := s.2 ⟨x, hxU⟩ simp only [Subtype.forall, apply_mk] at e rw [stalkToFiberRingHom_germ, homogeneousLocalizationToStalk, e x hxV, Quotient.liftOn'_mk''] refine Presheaf.germ_ext (C := CommRingCat) _ V hxV (homOfLE <| fun _ h' ↦ h ⟨_, h'⟩) i ?_ change ((Proj.structureSheaf 𝒜).presheaf.map (homOfLE <| fun _ h' ↦ h ⟨_, h'⟩).op) _ = ((Proj.structureSheaf 𝒜).presheaf.map i.op) s apply Subtype.ext ext ⟨t, ht⟩ rw [Proj.res_apply, Proj.res_apply] simp [sectionInBasicOpen, HomogeneousLocalization.val_mk, Localization.mk_eq_mk', e t ht] lemma stalkToFiberRingHom_homogeneousLocalizationToStalk (x z) : stalkToFiberRingHom 𝒜 x (homogeneousLocalizationToStalk 𝒜 x z) = z := by obtain ⟨z, rfl⟩ := Quotient.mk''_surjective z rw [homogeneousLocalizationToStalk, Quotient.liftOn'_mk'', stalkToFiberRingHom_germ, sectionInBasicOpen] /-- Using `homogeneousLocalizationToStalk`, we construct a ring isomorphism between stalk at `x` and homogeneous localization at `x` for any point `x` in `Proj`. -/ def Proj.stalkIso' (x : ProjectiveSpectrum.top 𝒜) : (Proj.structureSheaf 𝒜).presheaf.stalk x ≃+* at x where __ := (stalkToFiberRingHom _ x).hom invFun := homogeneousLocalizationToStalk 𝒜 x left_inv := homogeneousLocalizationToStalk_stalkToFiberRingHom 𝒜 x right_inv := stalkToFiberRingHom_homogeneousLocalizationToStalk 𝒜 x @[simp] theorem Proj.stalkIso'_germ (U : Opens (ProjectiveSpectrum.top 𝒜)) (x : ProjectiveSpectrum.top 𝒜) (hx : x ∈ U) (s : (Proj.structureSheaf 𝒜).1.obj (op U)) : Proj.stalkIso' 𝒜 x ((Proj.structureSheaf 𝒜).presheaf.germ _ x hx s) = s.1 ⟨x, hx⟩ := stalkToFiberRingHom_germ 𝒜 U x hx s @[simp] theorem Proj.stalkIso'_symm_mk (x) (f) : (Proj.stalkIso' 𝒜 x).symm (.mk f) = (Proj.structureSheaf 𝒜).presheaf.germ _ x (mem_basicOpen_den _ x f) (sectionInBasicOpen _ x f) := rfl /-- `Proj` of a graded ring as a `LocallyRingedSpace` -/ def Proj.toLocallyRingedSpace : LocallyRingedSpace := { Proj.toSheafedSpace 𝒜 with isLocalRing := fun x => @RingEquiv.isLocalRing _ _ _ (show IsLocalRing (at x) from inferInstance) _ (Proj.stalkIso' 𝒜 x).symm } end end AlgebraicGeometry
Constructions.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Floris van Doorn, Michael Rothgang -/ import Mathlib.Geometry.Manifold.ContMDiff.Basic /-! ## Smoothness of standard maps associated to the product of manifolds This file contains results about smoothness of standard maps associated to products and sums (disjoint unions) of smooth manifolds: - if `f` and `g` are `C^n`, so is their point-wise product. - the component projections from a product of manifolds are smooth. - functions into a product (*pi type*) are `C^n` iff their components are - if `M` and `N` are manifolds modelled over the same space, `Sum.inl` and `Sum.inr` are `C^n`, as are `Sum.elim`, `Sum.map` and `Sum.swap`. -/ open Set Function Filter ChartedSpace open scoped Topology Manifold variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare a charted space `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- declare a charted space `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] -- declare a charted space `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] -- declare a few vector spaces {F₁ : Type*} [NormedAddCommGroup F₁] [NormedSpace 𝕜 F₁] {F₂ : Type*} [NormedAddCommGroup F₂] [NormedSpace 𝕜 F₂] -- declare functions, sets, points and smoothness indices {f : M → M'} {s : Set M} {x : M} {n : WithTop ℕ∞} section ProdMk theorem ContMDiffWithinAt.prodMk {f : M → M'} {g : M → N'} (hf : ContMDiffWithinAt I I' n f s x) (hg : ContMDiffWithinAt I J' n g s x) : ContMDiffWithinAt I (I'.prod J') n (fun x => (f x, g x)) s x := by rw [contMDiffWithinAt_iff] at * exact ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ @[deprecated (since := "2025-03-08")] alias ContMDiffWithinAt.prod_mk := ContMDiffWithinAt.prodMk theorem ContMDiffWithinAt.prodMk_space {f : M → E'} {g : M → F'} (hf : ContMDiffWithinAt I 𝓘(𝕜, E') n f s x) (hg : ContMDiffWithinAt I 𝓘(𝕜, F') n g s x) : ContMDiffWithinAt I 𝓘(𝕜, E' × F') n (fun x => (f x, g x)) s x := by rw [contMDiffWithinAt_iff] at * exact ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ @[deprecated (since := "2025-03-08")] alias ContMDiffWithinAt.prod_mk_space := ContMDiffWithinAt.prodMk_space nonrec theorem ContMDiffAt.prodMk {f : M → M'} {g : M → N'} (hf : ContMDiffAt I I' n f x) (hg : ContMDiffAt I J' n g x) : ContMDiffAt I (I'.prod J') n (fun x => (f x, g x)) x := hf.prodMk hg @[deprecated (since := "2025-03-08")] alias ContMDiffAt.prod_mk := ContMDiffAt.prodMk nonrec theorem ContMDiffAt.prodMk_space {f : M → E'} {g : M → F'} (hf : ContMDiffAt I 𝓘(𝕜, E') n f x) (hg : ContMDiffAt I 𝓘(𝕜, F') n g x) : ContMDiffAt I 𝓘(𝕜, E' × F') n (fun x => (f x, g x)) x := hf.prodMk_space hg @[deprecated (since := "2025-03-08")] alias ContMDiffAt.prod_mk_space := ContMDiffAt.prodMk_space theorem ContMDiffOn.prodMk {f : M → M'} {g : M → N'} (hf : ContMDiffOn I I' n f s) (hg : ContMDiffOn I J' n g s) : ContMDiffOn I (I'.prod J') n (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk (hg x hx) @[deprecated (since := "2025-03-08")] alias ContMDiffOn.prod_mk := ContMDiffOn.prodMk theorem ContMDiffOn.prodMk_space {f : M → E'} {g : M → F'} (hf : ContMDiffOn I 𝓘(𝕜, E') n f s) (hg : ContMDiffOn I 𝓘(𝕜, F') n g s) : ContMDiffOn I 𝓘(𝕜, E' × F') n (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk_space (hg x hx) @[deprecated (since := "2025-03-08")] alias ContMDiffOn.prod_mk_space := ContMDiffOn.prodMk_space nonrec theorem ContMDiff.prodMk {f : M → M'} {g : M → N'} (hf : ContMDiff I I' n f) (hg : ContMDiff I J' n g) : ContMDiff I (I'.prod J') n fun x => (f x, g x) := fun x => (hf x).prodMk (hg x) @[deprecated (since := "2025-03-08")] alias ContMDiff.prod_mk := ContMDiff.prodMk theorem ContMDiff.prodMk_space {f : M → E'} {g : M → F'} (hf : ContMDiff I 𝓘(𝕜, E') n f) (hg : ContMDiff I 𝓘(𝕜, F') n g) : ContMDiff I 𝓘(𝕜, E' × F') n fun x => (f x, g x) := fun x => (hf x).prodMk_space (hg x) @[deprecated (since := "2025-03-08")] alias ContMDiff.prod_mk_space := ContMDiff.prodMk_space end ProdMk section Projections theorem contMDiffWithinAt_fst {s : Set (M × N)} {p : M × N} : ContMDiffWithinAt (I.prod J) I n Prod.fst s p := by /- porting note: `simp` fails to apply lemmas to `ModelProd`. Was rw [contMDiffWithinAt_iff'] refine' ⟨continuousWithinAt_fst, _⟩ refine' contDiffWithinAt_fst.congr (fun y hy => _) _ · simp only [mfld_simps] at hy simp only [hy, mfld_simps] · simp only [mfld_simps] -/ rw [contMDiffWithinAt_iff'] refine ⟨continuousWithinAt_fst, contDiffWithinAt_fst.congr (fun y hy => ?_) ?_⟩ · exact (extChartAt I p.1).right_inv ⟨hy.1.1.1, hy.1.2.1⟩ · exact (extChartAt I p.1).right_inv <| (extChartAt I p.1).map_source (mem_extChartAt_source _) theorem ContMDiffWithinAt.fst {f : N → M × M'} {s : Set N} {x : N} (hf : ContMDiffWithinAt J (I.prod I') n f s x) : ContMDiffWithinAt J I n (fun x => (f x).1) s x := contMDiffWithinAt_fst.comp x hf (mapsTo_image f s) theorem contMDiffAt_fst {p : M × N} : ContMDiffAt (I.prod J) I n Prod.fst p := contMDiffWithinAt_fst theorem contMDiffOn_fst {s : Set (M × N)} : ContMDiffOn (I.prod J) I n Prod.fst s := fun _ _ => contMDiffWithinAt_fst theorem contMDiff_fst : ContMDiff (I.prod J) I n (@Prod.fst M N) := fun _ => contMDiffAt_fst theorem ContMDiffAt.fst {f : N → M × M'} {x : N} (hf : ContMDiffAt J (I.prod I') n f x) : ContMDiffAt J I n (fun x => (f x).1) x := contMDiffAt_fst.comp x hf theorem ContMDiff.fst {f : N → M × M'} (hf : ContMDiff J (I.prod I') n f) : ContMDiff J I n fun x => (f x).1 := contMDiff_fst.comp hf theorem contMDiffWithinAt_snd {s : Set (M × N)} {p : M × N} : ContMDiffWithinAt (I.prod J) J n Prod.snd s p := by /- porting note: `simp` fails to apply lemmas to `ModelProd`. Was rw [contMDiffWithinAt_iff'] refine' ⟨continuousWithinAt_snd, _⟩ refine' contDiffWithinAt_snd.congr (fun y hy => _) _ · simp only [mfld_simps] at hy simp only [hy, mfld_simps] · simp only [mfld_simps] -/ rw [contMDiffWithinAt_iff'] refine ⟨continuousWithinAt_snd, contDiffWithinAt_snd.congr (fun y hy => ?_) ?_⟩ · exact (extChartAt J p.2).right_inv ⟨hy.1.1.2, hy.1.2.2⟩ · exact (extChartAt J p.2).right_inv <| (extChartAt J p.2).map_source (mem_extChartAt_source _) theorem ContMDiffWithinAt.snd {f : N → M × M'} {s : Set N} {x : N} (hf : ContMDiffWithinAt J (I.prod I') n f s x) : ContMDiffWithinAt J I' n (fun x => (f x).2) s x := contMDiffWithinAt_snd.comp x hf (mapsTo_image f s) theorem contMDiffAt_snd {p : M × N} : ContMDiffAt (I.prod J) J n Prod.snd p := contMDiffWithinAt_snd theorem contMDiffOn_snd {s : Set (M × N)} : ContMDiffOn (I.prod J) J n Prod.snd s := fun _ _ => contMDiffWithinAt_snd theorem contMDiff_snd : ContMDiff (I.prod J) J n (@Prod.snd M N) := fun _ => contMDiffAt_snd theorem ContMDiffAt.snd {f : N → M × M'} {x : N} (hf : ContMDiffAt J (I.prod I') n f x) : ContMDiffAt J I' n (fun x => (f x).2) x := contMDiffAt_snd.comp x hf theorem ContMDiff.snd {f : N → M × M'} (hf : ContMDiff J (I.prod I') n f) : ContMDiff J I' n fun x => (f x).2 := contMDiff_snd.comp hf end Projections theorem contMDiffWithinAt_prod_iff (f : M → M' × N') : ContMDiffWithinAt I (I'.prod J') n f s x ↔ ContMDiffWithinAt I I' n (Prod.fst ∘ f) s x ∧ ContMDiffWithinAt I J' n (Prod.snd ∘ f) s x := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prodMk h.2⟩ theorem contMDiffWithinAt_prod_module_iff (f : M → F₁ × F₂) : ContMDiffWithinAt I 𝓘(𝕜, F₁ × F₂) n f s x ↔ ContMDiffWithinAt I 𝓘(𝕜, F₁) n (Prod.fst ∘ f) s x ∧ ContMDiffWithinAt I 𝓘(𝕜, F₂) n (Prod.snd ∘ f) s x := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact contMDiffWithinAt_prod_iff f theorem contMDiffAt_prod_iff (f : M → M' × N') : ContMDiffAt I (I'.prod J') n f x ↔ ContMDiffAt I I' n (Prod.fst ∘ f) x ∧ ContMDiffAt I J' n (Prod.snd ∘ f) x := by simp_rw [← contMDiffWithinAt_univ]; exact contMDiffWithinAt_prod_iff f theorem contMDiffAt_prod_module_iff (f : M → F₁ × F₂) : ContMDiffAt I 𝓘(𝕜, F₁ × F₂) n f x ↔ ContMDiffAt I 𝓘(𝕜, F₁) n (Prod.fst ∘ f) x ∧ ContMDiffAt I 𝓘(𝕜, F₂) n (Prod.snd ∘ f) x := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact contMDiffAt_prod_iff f theorem contMDiffOn_prod_iff (f : M → M' × N') : ContMDiffOn I (I'.prod J') n f s ↔ ContMDiffOn I I' n (Prod.fst ∘ f) s ∧ ContMDiffOn I J' n (Prod.snd ∘ f) s := ⟨fun h ↦ ⟨fun x hx ↦ ((contMDiffWithinAt_prod_iff f).1 (h x hx)).1, fun x hx ↦ ((contMDiffWithinAt_prod_iff f).1 (h x hx)).2⟩ , fun h x hx ↦ (contMDiffWithinAt_prod_iff f).2 ⟨h.1 x hx, h.2 x hx⟩⟩ theorem contMDiffOn_prod_module_iff (f : M → F₁ × F₂) : ContMDiffOn I 𝓘(𝕜, F₁ × F₂) n f s ↔ ContMDiffOn I 𝓘(𝕜, F₁) n (Prod.fst ∘ f) s ∧ ContMDiffOn I 𝓘(𝕜, F₂) n (Prod.snd ∘ f) s := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact contMDiffOn_prod_iff f theorem contMDiff_prod_iff (f : M → M' × N') : ContMDiff I (I'.prod J') n f ↔ ContMDiff I I' n (Prod.fst ∘ f) ∧ ContMDiff I J' n (Prod.snd ∘ f) := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => by convert h.1.prodMk h.2⟩ theorem contMDiff_prod_module_iff (f : M → F₁ × F₂) : ContMDiff I 𝓘(𝕜, F₁ × F₂) n f ↔ ContMDiff I 𝓘(𝕜, F₁) n (Prod.fst ∘ f) ∧ ContMDiff I 𝓘(𝕜, F₂) n (Prod.snd ∘ f) := by rw [modelWithCornersSelf_prod, ← chartedSpaceSelf_prod] exact contMDiff_prod_iff f theorem contMDiff_prod_assoc : ContMDiff ((I.prod I').prod J) (I.prod (I'.prod J)) n fun x : (M × M') × N => (x.1.1, x.1.2, x.2) := contMDiff_fst.fst.prodMk <| contMDiff_fst.snd.prodMk contMDiff_snd section prodMap variable {g : N → N'} {r : Set N} {y : N} /-- The product map of two `C^n` functions within a set at a point is `C^n` within the product set at the product point. -/ theorem ContMDiffWithinAt.prodMap' {p : M × N} (hf : ContMDiffWithinAt I I' n f s p.1) (hg : ContMDiffWithinAt J J' n g r p.2) : ContMDiffWithinAt (I.prod J) (I'.prod J') n (Prod.map f g) (s ×ˢ r) p := (hf.comp p contMDiffWithinAt_fst mapsTo_fst_prod).prodMk <| hg.comp p contMDiffWithinAt_snd mapsTo_snd_prod @[deprecated (since := "2025-03-08")] alias ContMDiffWithinAt.prod_map' := ContMDiffWithinAt.prodMap' theorem ContMDiffWithinAt.prodMap (hf : ContMDiffWithinAt I I' n f s x) (hg : ContMDiffWithinAt J J' n g r y) : ContMDiffWithinAt (I.prod J) (I'.prod J') n (Prod.map f g) (s ×ˢ r) (x, y) := ContMDiffWithinAt.prodMap' hf hg @[deprecated (since := "2025-03-08")] alias ContMDiffWithinAt.prod_map := ContMDiffWithinAt.prodMap theorem ContMDiffAt.prodMap (hf : ContMDiffAt I I' n f x) (hg : ContMDiffAt J J' n g y) : ContMDiffAt (I.prod J) (I'.prod J') n (Prod.map f g) (x, y) := by simp only [← contMDiffWithinAt_univ, ← univ_prod_univ] at * exact hf.prodMap hg @[deprecated (since := "2025-03-08")] alias ContMDiffAt.prod_map := ContMDiffAt.prodMap theorem ContMDiffAt.prodMap' {p : M × N} (hf : ContMDiffAt I I' n f p.1) (hg : ContMDiffAt J J' n g p.2) : ContMDiffAt (I.prod J) (I'.prod J') n (Prod.map f g) p := hf.prodMap hg @[deprecated (since := "2025-03-08")] alias ContMDiffAt.prod_map' := ContMDiffAt.prodMap' theorem ContMDiffOn.prodMap (hf : ContMDiffOn I I' n f s) (hg : ContMDiffOn J J' n g r) : ContMDiffOn (I.prod J) (I'.prod J') n (Prod.map f g) (s ×ˢ r) := (hf.comp contMDiffOn_fst mapsTo_fst_prod).prodMk <| hg.comp contMDiffOn_snd mapsTo_snd_prod @[deprecated (since := "2025-03-08")] alias ContMDiffOn.prod_map := ContMDiffOn.prodMap theorem ContMDiff.prodMap (hf : ContMDiff I I' n f) (hg : ContMDiff J J' n g) : ContMDiff (I.prod J) (I'.prod J') n (Prod.map f g) := by intro p exact (hf p.1).prodMap' (hg p.2) @[deprecated (since := "2025-03-08")] alias ContMDiff.prod_map := ContMDiff.prodMap end prodMap section PiSpace /-! ### Regularity of functions with codomain `Π i, F i` We have no `ModelWithCorners.pi` yet, so we prove lemmas about functions `f : M → Π i, F i` and use `𝓘(𝕜, Π i, F i)` as the model space. -/ variable {ι : Type*} [Fintype ι] {Fi : ι → Type*} [∀ i, NormedAddCommGroup (Fi i)] [∀ i, NormedSpace 𝕜 (Fi i)] {φ : M → ∀ i, Fi i} theorem contMDiffWithinAt_pi_space : ContMDiffWithinAt I 𝓘(𝕜, ∀ i, Fi i) n φ s x ↔ ∀ i, ContMDiffWithinAt I 𝓘(𝕜, Fi i) n (fun x => φ x i) s x := by simp only [contMDiffWithinAt_iff, continuousWithinAt_pi, contDiffWithinAt_pi, forall_and, extChartAt_model_space_eq_id, Function.comp_def, PartialEquiv.refl_coe, id] theorem contMDiffOn_pi_space : ContMDiffOn I 𝓘(𝕜, ∀ i, Fi i) n φ s ↔ ∀ i, ContMDiffOn I 𝓘(𝕜, Fi i) n (fun x => φ x i) s := ⟨fun h i x hx => contMDiffWithinAt_pi_space.1 (h x hx) i, fun h x hx => contMDiffWithinAt_pi_space.2 fun i => h i x hx⟩ theorem contMDiffAt_pi_space : ContMDiffAt I 𝓘(𝕜, ∀ i, Fi i) n φ x ↔ ∀ i, ContMDiffAt I 𝓘(𝕜, Fi i) n (fun x => φ x i) x := contMDiffWithinAt_pi_space theorem contMDiff_pi_space : ContMDiff I 𝓘(𝕜, ∀ i, Fi i) n φ ↔ ∀ i, ContMDiff I 𝓘(𝕜, Fi i) n fun x => φ x i := ⟨fun h i x => contMDiffAt_pi_space.1 (h x) i, fun h x => contMDiffAt_pi_space.2 fun i => h i x⟩ end PiSpace section disjointUnion variable {M' : Type*} [TopologicalSpace M'] [ChartedSpace H M'] {n : WithTop ℕ∞} {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {J : Type*} {J : ModelWithCorners 𝕜 E' H'} {N N' : Type*} [TopologicalSpace N] [TopologicalSpace N'] [ChartedSpace H' N] [ChartedSpace H' N'] open Topology lemma ContMDiff.inl : ContMDiff I I n (@Sum.inl M M') := by intro x rw [contMDiffAt_iff] refine ⟨continuous_inl.continuousAt, ?_⟩ -- In extended charts, .inl equals the identity (on the chart sources). apply contDiffWithinAt_id.congr_of_eventuallyEq; swap · simp [ChartedSpace.sum_chartAt_inl] congr apply Sum.inl_injective.extend_apply (chartAt _ x) set C := chartAt H x with hC have : I.symm ⁻¹' C.target ∩ range I ∈ 𝓝[range I] (extChartAt I x) x := by rw [← I.image_eq (chartAt H x).target] exact (chartAt H x).extend_image_target_mem_nhds (mem_chart_source _ x) filter_upwards [this] with y hy simp [extChartAt, sum_chartAt_inl, ← hC, Sum.inl_injective.extend_apply C, C.right_inv hy.1, I.right_inv hy.2] lemma ContMDiff.inr : ContMDiff I I n (@Sum.inr M M') := by intro x rw [contMDiffAt_iff] refine ⟨continuous_inr.continuousAt, ?_⟩ -- In extended charts, .inl equals the identity (on the chart sources). apply contDiffWithinAt_id.congr_of_eventuallyEq; swap · simp only [mfld_simps, sum_chartAt_inr] congr apply Sum.inr_injective.extend_apply (chartAt _ x) set C := chartAt H x with hC have : I.symm ⁻¹' (chartAt H x).target ∩ range I ∈ 𝓝[range I] (extChartAt I x) x := by rw [← I.image_eq (chartAt H x).target] exact (chartAt H x).extend_image_target_mem_nhds (mem_chart_source _ x) filter_upwards [this] with y hy simp [extChartAt, sum_chartAt_inr, ← hC, Sum.inr_injective.extend_apply C, C.right_inv hy.1, I.right_inv hy.2] lemma extChartAt_inl_apply {x y : M} : (extChartAt I (.inl x : M ⊕ M')) (Sum.inl y) = (extChartAt I x) y := by simp lemma extChartAt_inr_apply {x y : M'} : (extChartAt I (.inr x : M ⊕ M')) (Sum.inr y) = (extChartAt I x) y := by simp lemma ContMDiff.sumElim {f : M → N} {g : M' → N} (hf : ContMDiff I J n f) (hg : ContMDiff I J n g) : ContMDiff I J n (Sum.elim f g) := by intro p rw [contMDiffAt_iff] refine ⟨(Continuous.sumElim hf.continuous hg.continuous).continuousAt, ?_⟩ cases p with | inl x => -- In charts around x : M, the map f ⊔ g looks like f. -- This is how they both look like in extended charts. have : ContDiffWithinAt 𝕜 n ((extChartAt J (f x)) ∘ f ∘ (extChartAt I x).symm) (range I) ((extChartAt I (.inl x : M ⊕ M')) (Sum.inl x)) := by let hf' := hf x rw [contMDiffAt_iff] at hf' simpa using hf'.2 apply this.congr_of_eventuallyEq · simp only [extChartAt, Sum.elim_inl, ChartedSpace.sum_chartAt_inl] filter_upwards with a congr · -- They agree at the image of x. simp only [extChartAt, ChartedSpace.sum_chartAt_inl, Sum.elim_inl] congr | inr x => -- In charts around x : M, the map f ⊔ g looks like g. -- This is how they both look like in extended charts. have : ContDiffWithinAt 𝕜 n ((extChartAt J (g x)) ∘ g ∘ (extChartAt I x).symm) (range I) ((extChartAt I (.inr x : M ⊕ M')) (Sum.inr x)) := by let hg' := hg x rw [contMDiffAt_iff] at hg' simpa using hg'.2 apply this.congr_of_eventuallyEq · simp only [extChartAt, Sum.elim_inr, ChartedSpace.sum_chartAt_inr] filter_upwards with a congr · -- They agree at the image of x. simp only [extChartAt, ChartedSpace.sum_chartAt_inr, Sum.elim_inr] congr @[deprecated (since := "2025-02-20")] alias ContMDiff.sum_elim := ContMDiff.sumElim lemma ContMDiff.sumMap {f : M → N} {g : M' → N'} (hf : ContMDiff I J n f) (hg : ContMDiff I J n g) : ContMDiff I J n (Sum.map f g) := ContMDiff.sumElim (ContMDiff.inl.comp hf) (ContMDiff.inr.comp hg) @[deprecated (since := "2025-02-20")] alias ContMDiff.sum_map := ContMDiff.sumMap lemma contMDiff_of_contMDiff_inl {f : M → N} (h : ContMDiff I J n ((@Sum.inl N N') ∘ f)) : ContMDiff I J n f := by nontriviality N inhabit N let aux : N ⊕ N' → N := Sum.elim (@id N) (fun _ ↦ inhabited_h.default) have : aux ∘ (@Sum.inl N N') ∘ f = f := by ext; simp [aux] rw [← this] rw [← contMDiffOn_univ] at h ⊢ apply (contMDiff_id.sumElim contMDiff_const).contMDiffOn (s := @Sum.inl N N' '' univ).comp h intro x _hx rw [mem_preimage, Function.comp_apply] use f x, trivial lemma contMDiff_of_contMDiff_inr {g : M' → N'} (h : ContMDiff I J n ((@Sum.inr N N') ∘ g)) : ContMDiff I J n g := by nontriviality N' inhabit N' let aux : N ⊕ N' → N' := Sum.elim (fun _ ↦ inhabited_h.default) (@id N') have : aux ∘ (@Sum.inr N N') ∘ g = g := by ext; simp [aux] rw [← this] rw [← contMDiffOn_univ] at h ⊢ apply ((contMDiff_const.sumElim contMDiff_id).contMDiffOn (s := Sum.inr '' univ)).comp h intro x _hx rw [mem_preimage, Function.comp_apply] use g x, trivial lemma contMDiff_sum_map {f : M → N} {g : M' → N'} : ContMDiff I J n (Sum.map f g) ↔ ContMDiff I J n f ∧ ContMDiff I J n g := ⟨fun h ↦ ⟨contMDiff_of_contMDiff_inl (h.comp ContMDiff.inl), contMDiff_of_contMDiff_inr (h.comp ContMDiff.inr)⟩, fun h ↦ ContMDiff.sumMap h.1 h.2⟩ lemma ContMDiff.swap : ContMDiff I I n (@Sum.swap M M') := ContMDiff.sumElim inr inl end disjointUnion
FreeCommRing.lean
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.ModelTheory.Algebra.Ring.Basic import Mathlib.RingTheory.FreeCommRing /-! # Making a term in the language of rings from an element of the FreeCommRing This file defines the function `FirstOrder.Ring.termOfFreeCommRing` which constructs a `Language.ring.Term α` from an element of `FreeCommRing α`. The theorem `FirstOrder.Ring.realize_termOfFreeCommRing` shows that the term constructed when realized in a ring `R` is equal to the lift of the element of `FreeCommRing α` to `R`. -/ namespace FirstOrder namespace Ring open Language variable {α : Type*} section attribute [local instance] compatibleRingOfRing private theorem exists_term_realize_eq_freeCommRing (p : FreeCommRing α) : ∃ t : Language.ring.Term α, (t.realize FreeCommRing.of : FreeCommRing α) = p := FreeCommRing.induction_on p ⟨-1, by simp⟩ (fun a => ⟨Term.var a, by simp [Term.realize]⟩) (fun x y ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ => ⟨t₁ + t₂, by simp_all⟩) (fun x y ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩ => ⟨t₁ * t₂, by simp_all⟩) end /-- Make a `Language.ring.Term α` from an element of `FreeCommRing α` -/ noncomputable def termOfFreeCommRing (p : FreeCommRing α) : Language.ring.Term α := Classical.choose (exists_term_realize_eq_freeCommRing p) variable {R : Type*} [CommRing R] [CompatibleRing R] @[simp] theorem realize_termOfFreeCommRing (p : FreeCommRing α) (v : α → R) : (termOfFreeCommRing p).realize v = FreeCommRing.lift v p := by let _ := compatibleRingOfRing (FreeCommRing α) rw [termOfFreeCommRing] conv_rhs => rw [← Classical.choose_spec (exists_term_realize_eq_freeCommRing p)] induction Classical.choose (exists_term_realize_eq_freeCommRing p) with | var _ => simp | func f a ih => cases f <;> simp [ih] end Ring end FirstOrder
Pi.lean
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Prod import Mathlib.CategoryTheory.Localization.Equivalence import Mathlib.Data.Fintype.Option /-! # Localization of product categories In this file, it is shown that if for all `j : J` (with `J` finite), functors `L j : C j ⥤ D j` are localization functors with respect to a class of morphisms `W j : MorphismProperty (C j)`, then the product functor `Functor.pi L : (∀ j, C j) ⥤ ∀ j, D j` is a localization functor for the product class of morphisms `MorphismProperty.pi W`. The proof proceeds by induction on the cardinal of `J` using the main result of the file `Mathlib/CategoryTheory/Localization/Prod.lean`. -/ universe w v₁ v₂ u₁ u₂ namespace CategoryTheory.Functor.IsLocalization instance pi {J : Type w} [Finite J] {C : J → Type u₁} {D : J → Type u₂} [∀ j, Category.{v₁} (C j)] [∀ j, Category.{v₂} (D j)] (L : ∀ j, C j ⥤ D j) (W : ∀ j, MorphismProperty (C j)) [∀ j, (W j).ContainsIdentities] [∀ j, (L j).IsLocalization (W j)] : (Functor.pi L).IsLocalization (MorphismProperty.pi W) := by revert J apply Finite.induction_empty_option · intro J₁ J₂ e hJ₁ C₂ D₂ _ _ L₂ W₂ _ _ let L₁ := fun j => (L₂ (e j)) let E := Pi.equivalenceOfEquiv C₂ e let E' := Pi.equivalenceOfEquiv D₂ e haveI : CatCommSq E.functor (Functor.pi L₁) (Functor.pi L₂) E'.functor := (CatCommSq.hInvEquiv E (Functor.pi L₁) (Functor.pi L₂) E').symm ⟨Iso.refl _⟩ refine IsLocalization.of_equivalences (Functor.pi L₁) (MorphismProperty.pi (fun j => (W₂ (e j)))) (Functor.pi L₂) (MorphismProperty.pi W₂) E E' ?_ (MorphismProperty.IsInvertedBy.pi _ _ (fun _ => Localization.inverts _ _)) intro _ _ f hf refine ⟨_, _, E.functor.map f, fun i => ?_, ⟨Iso.refl _⟩⟩ have H : ∀ {j j' : J₂} (h : j = j') {X Y : C₂ j} (g : X ⟶ Y) (_ : W₂ j g), W₂ j' ((Pi.eqToEquivalence C₂ h).functor.map g) := by rintro j _ rfl _ _ g hg exact hg exact H (e.apply_symm_apply i) _ (hf (e.symm i)) · intro C D _ _ L W _ _ haveI : ∀ j, IsEquivalence (L j) := by rintro ⟨⟩ refine IsLocalization.of_isEquivalence _ _ (fun _ _ _ _ => ?_) rw [MorphismProperty.isomorphisms.iff, isIso_pi_iff] rintro ⟨⟩ · intro J _ hJ C D _ _ L W _ _ let L₁ := (L none).prod (Functor.pi (fun j => L (some j))) haveI : CatCommSq (Pi.optionEquivalence C).symm.functor L₁ (Functor.pi L) (Pi.optionEquivalence D).symm.functor := ⟨NatIso.pi' (by rintro (_ | i) <;> apply Iso.refl)⟩ refine IsLocalization.of_equivalences L₁ ((W none).prod (MorphismProperty.pi (fun j => W (some j)))) (Functor.pi L) _ (Pi.optionEquivalence C).symm (Pi.optionEquivalence D).symm ?_ ?_ · intro ⟨X₁, X₂⟩ ⟨Y₁, Y₂⟩ f ⟨hf₁, hf₂⟩ refine ⟨_, _, (Pi.optionEquivalence C).inverse.map f, ?_, ⟨Iso.refl _⟩⟩ rintro (_ | i) · exact hf₁ · apply hf₂ · apply MorphismProperty.IsInvertedBy.pi rintro (_ | i) <;> apply Localization.inverts /-- If `L : C ⥤ D` is a localization functor for `W : MorphismProperty C`, then the induced functor `(Discrete J ⥤ C) ⥤ (Discrete J ⥤ D)` is also a localization for `W.functorCategory (Discrete J)` if `W` contains identities. -/ instance {J : Type} [Finite J] {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (L : C ⥤ D) (W : MorphismProperty C) [W.ContainsIdentities] [L.IsLocalization W] : ((whiskeringRight (Discrete J) C D).obj L).IsLocalization (W.functorCategory (Discrete J)) := by let E := piEquivalenceFunctorDiscrete J C let E' := piEquivalenceFunctorDiscrete J D let L₂ := (whiskeringRight (Discrete J) C D).obj L let L₁ := Functor.pi (fun (_ : J) => L) have : CatCommSq E.functor L₁ L₂ E'.functor := ⟨(Functor.rightUnitor _).symm ≪≫ isoWhiskerLeft _ E'.counitIso.symm ≪≫ Functor.associator _ _ _≪≫ isoWhiskerLeft _ ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (by exact Iso.refl _) _) ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight ((Functor.associator _ _ _).symm ≪≫ isoWhiskerRight E.unitIso.symm L₁) _ ≪≫ isoWhiskerRight L₁.leftUnitor _⟩ refine Functor.IsLocalization.of_equivalences L₁ (MorphismProperty.pi (fun _ => W)) L₂ _ E E' ?_ ?_ · intro X Y f hf exact MorphismProperty.le_isoClosure _ _ (fun ⟨j⟩ => hf j) · intro X Y f hf have : ∀ (j : Discrete J), IsIso ((L₂.map f).app j) := fun j => Localization.inverts L W _ (hf j) apply NatIso.isIso_of_isIso_app end CategoryTheory.Functor.IsLocalization
Irrational.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.Data.Real.Irrational import Mathlib.Data.Rat.Encodable import Mathlib.Topology.Separation.GDelta import Mathlib.Topology.Instances.Real.Lemmas /-! # Topology of irrational numbers In this file we prove the following theorems: * `IsGδ.setOf_irrational`, `dense_irrational`, `eventually_residual_irrational`: irrational numbers form a dense Gδ set; * `Irrational.eventually_forall_le_dist_cast_div`, `Irrational.eventually_forall_le_dist_cast_div_of_denom_le`; `Irrational.eventually_forall_le_dist_cast_rat_of_denom_le`: a sufficiently small neighborhood of an irrational number is disjoint with the set of rational numbers with bounded denominator. We also provide `OrderTopology`, `NoMinOrder`, `NoMaxOrder`, and `DenselyOrdered` instances for `{x // Irrational x}`. ## Tags irrational, residual -/ open Set Filter Metric open Filter Topology protected theorem IsGδ.setOf_irrational : IsGδ { x | Irrational x } := (countable_range _).isGδ_compl theorem dense_irrational : Dense { x : ℝ | Irrational x } := by refine Real.isTopologicalBasis_Ioo_rat.dense_iff.2 ?_ simp only [mem_iUnion, mem_singleton_iff, exists_prop, forall_exists_index, and_imp] rintro _ a b hlt rfl _ rw [inter_comm] exact exists_irrational_btwn (Rat.cast_lt.2 hlt) theorem eventually_residual_irrational : ∀ᶠ x in residual ℝ, Irrational x := residual_of_dense_Gδ .setOf_irrational dense_irrational namespace Irrational variable {x : ℝ} instance : OrderTopology { x // Irrational x } := induced_orderTopology _ Iff.rfl <| @fun _ _ hlt => let ⟨z, hz, hxz, hzy⟩ := exists_irrational_btwn hlt ⟨⟨z, hz⟩, hxz, hzy⟩ instance : NoMaxOrder { x // Irrational x } := ⟨fun ⟨x, hx⟩ => ⟨⟨x + (1 : ℕ), hx.add_natCast 1⟩, by simp⟩⟩ instance : NoMinOrder { x // Irrational x } := ⟨fun ⟨x, hx⟩ => ⟨⟨x - (1 : ℕ), hx.sub_natCast 1⟩, by simp⟩⟩ instance : DenselyOrdered { x // Irrational x } := ⟨fun _ _ hlt => let ⟨z, hz, hxz, hzy⟩ := exists_irrational_btwn hlt ⟨⟨z, hz⟩, hxz, hzy⟩⟩ theorem eventually_forall_le_dist_cast_div (hx : Irrational x) (n : ℕ) : ∀ᶠ ε : ℝ in 𝓝 0, ∀ m : ℤ, ε ≤ dist x (m / n) := by have A : IsClosed (range (fun m => (n : ℝ)⁻¹ * m : ℤ → ℝ)) := ((isClosedMap_smul₀ (n⁻¹ : ℝ)).comp Int.isClosedEmbedding_coe_real.isClosedMap).isClosed_range have B : x ∉ range (fun m => (n : ℝ)⁻¹ * m : ℤ → ℝ) := by rintro ⟨m, rfl⟩ simp at hx rcases Metric.mem_nhds_iff.1 (A.isOpen_compl.mem_nhds B) with ⟨ε, ε0, hε⟩ refine (ge_mem_nhds ε0).mono fun δ hδ m => not_lt.1 fun hlt => ?_ rw [dist_comm] at hlt refine hε (ball_subset_ball hδ hlt) ⟨m, ?_⟩ simp [div_eq_inv_mul] theorem eventually_forall_le_dist_cast_div_of_denom_le (hx : Irrational x) (n : ℕ) : ∀ᶠ ε : ℝ in 𝓝 0, ∀ k ≤ n, ∀ (m : ℤ), ε ≤ dist x (m / k) := (finite_le_nat n).eventually_all.2 fun k _ => hx.eventually_forall_le_dist_cast_div k theorem eventually_forall_le_dist_cast_rat_of_den_le (hx : Irrational x) (n : ℕ) : ∀ᶠ ε : ℝ in 𝓝 0, ∀ r : ℚ, r.den ≤ n → ε ≤ dist x r := (hx.eventually_forall_le_dist_cast_div_of_denom_le n).mono fun ε H r hr => by simpa only [Rat.cast_def] using H r.den hr r.num end Irrational
Basic.lean
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov, Heather Macbeth, Patrick Massot -/ import Mathlib.Topology.Algebra.Module.Alternating.Topology import Mathlib.Analysis.NormedSpace.Multilinear.Basic /-! # Operator norm on the space of continuous alternating maps In this file we show that continuous alternating maps from a seminormed space to a (semi)normed space form a (semi)normed space. We also prove basic facts about this norm and define bundled versions of some operations on continuous alternating maps. Most proofs just invoke the corresponding fact about continuous multilinear maps. -/ noncomputable section open scoped BigOperators NNReal open Finset Metric /-! ### Type variables We use the following type variables in this file: * `𝕜` : a nontrivially normed field; * `ι`: a finite index type; * `E`, `F`, `G`: (semi)normed vector spaces over `𝕜`. -/ /-- Applying a continuous alternating map to a vector is continuous in the pair (map, vector). Continuity in in the vector holds by definition and continuity in the map holds if both the domain and the codomain are topological vector spaces. However, continuity in the pair (map, vector) needs the domain to be a locally bounded TVS. We have no typeclass for a locally bounded TVS, so we require it to be a seminormed space instead. -/ instance ContinuousAlternatingMap.instContinuousEval {𝕜 ι E F : Type*} [NormedField 𝕜] [Finite ι] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] [TopologicalSpace F] [AddCommGroup F] [IsTopologicalAddGroup F] [Module 𝕜 F] : ContinuousEval (E [⋀^ι]→L[𝕜] F) (ι → E) F := .of_continuous_forget continuous_toContinuousMultilinearMap section Seminorm universe u wE wF wG v variable {𝕜 : Type u} {n : ℕ} {E : Type wE} {F : Type wF} {G : Type wG} {ι : Type v} [NontriviallyNormedField 𝕜] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] [SeminormedAddCommGroup F] [NormedSpace 𝕜 F] [SeminormedAddCommGroup G] [NormedSpace 𝕜 G] /-! ### Continuity properties of alternating maps We relate continuity of alternating maps to the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, in both directions. Along the way, we prove useful bounds on the difference `‖f m₁ - f m₂‖`. -/ namespace AlternatingMap /-- If `f` is a continuous alternating map on `E` and `m` is an element of `ι → E` such that one of the `m i` has norm `0`, then `f m` has norm `0`. Note that we cannot drop the continuity assumption. Indeed, let `ℝ₀` be a copy or `ℝ` with zero norm and indiscrete topology. Then `f : (Unit → ℝ₀) → ℝ` given by `f x = x ()` sends vector `1` with zero norm to number `1` with nonzero norm. -/ theorem norm_map_coord_zero (f : E [⋀^ι]→ₗ[𝕜] F) (hf : Continuous f) {m : ι → E} {i : ι} (hi : ‖m i‖ = 0) : ‖f m‖ = 0 := f.1.norm_map_coord_zero hf hi variable [Fintype ι] /-- If an alternating map in finitely many variables on seminormed spaces sends vectors with a component of norm zero to vectors of norm zero and satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i` for some positive numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`, then it satisfies this inequality for all `m`. The first assumption is automatically satisfied on normed spaces, see `bound_of_shell` below. For seminormed spaces, it follows from continuity of `f`, see lemma `bound_of_shell_of_continuous` below. -/ theorem bound_of_shell_of_norm_map_coord_zero (f : E [⋀^ι]→ₗ[𝕜] F) (hf₀ : ∀ {m i}, ‖m i‖ = 0 → ‖f m‖ = 0) {ε : ι → ℝ} {C : ℝ} (hε : ∀ i, 0 < ε i) {c : ι → 𝕜} (hc : ∀ i, 1 < ‖c i‖) (hf : ∀ m : ι → E, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m : ι → E) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := f.1.bound_of_shell_of_norm_map_coord_zero hf₀ hε hc hf m /-- If a continuous alternating map in finitely many variables on normed spaces satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε / ‖c‖ < ‖m i‖ < ε` for some positive number `ε` and an elements `c : 𝕜`, `1 < ‖c‖`, then it satisfies this inequality for all `m`. If the domain is a Hausdorff space, then the continuity assumption is redundant, see `bound_of_shell` below. -/ theorem bound_of_shell_of_continuous (f : E [⋀^ι]→ₗ[𝕜] F) (hfc : Continuous f) {ε : ℝ} {C : ℝ} (hε : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖) (hf : ∀ m : ι → E, (∀ i, ε / ‖c‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε) → ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m : ι → E) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := f.1.bound_of_shell_of_continuous hfc (fun _ ↦ hε) (fun _ ↦ hc) hf m /-- If an alternating map in finitely many variables on a seminormed space is continuous, then it satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, for some `C` which can be chosen to be positive. -/ theorem exists_bound_of_continuous (f : E [⋀^ι]→ₗ[𝕜] F) (hf : Continuous f) : ∃ (C : ℝ), 0 < C ∧ (∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) := f.1.exists_bound_of_continuous hf /-- If an alternating map `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a precise but hard to use version. See `AlternatingMap.norm_image_sub_le_of_bound` for a less precise but more usable version. The bound reads `‖f m - f m'‖ ≤ C * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`. -/ theorem norm_image_sub_le_of_bound' [DecidableEq ι] (f : E [⋀^ι]→ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ι → E) : ‖f m₁ - f m₂‖ ≤ C * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := f.toMultilinearMap.norm_image_sub_le_of_bound' hC H m₁ m₂ /-- If an alternating map `f` satisfies a boundedness property around `0`, one can deduce a bound on `f m₁ - f m₂` using the multilinearity. Here, we give a usable but not very precise version. See `AlternatingMap.norm_image_sub_le_of_bound'` for a more precise but less usable version. The bound is `‖f m - f m'‖ ≤ C * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/ theorem norm_image_sub_le_of_bound (f : E [⋀^ι]→ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m₁ m₂ : ι → E) : ‖f m₁ - f m₂‖ ≤ C * (Fintype.card ι) * (max ‖m₁‖ ‖m₂‖) ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := f.toMultilinearMap.norm_image_sub_le_of_bound hC H m₁ m₂ /-- If an alternating map satisfies an inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖`, then it is continuous. -/ theorem continuous_of_bound (f : E [⋀^ι]→ₗ[𝕜] F) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : Continuous f := f.toMultilinearMap.continuous_of_bound C H /-- Construct a continuous alternating map from a alternating map satisfying a boundedness condition. -/ def mkContinuous (f : E [⋀^ι]→ₗ[𝕜] F) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : E [⋀^ι]→L[𝕜] F := { f with cont := f.continuous_of_bound C H } @[simp] theorem coe_mkContinuous (f : E [⋀^ι]→ₗ[𝕜] F) (C : ℝ) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : (f.mkContinuous C H : (ι → E) → F) = f := rfl end AlternatingMap /-! ### Continuous alternating maps We define the norm `‖f‖` of a continuous alternating map `f` in finitely many variables as the smallest nonnegative number such that `‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖` for all `m`. We show that this defines a normed space structure on `E [⋀^ι]→L[𝕜] F`. -/ namespace ContinuousAlternatingMap variable [Fintype ι] {f : E [⋀^ι]→L[𝕜] F} {m : ι → E} theorem bound (f : E [⋀^ι]→L[𝕜] F) : ∃ (C : ℝ), 0 < C ∧ (∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) := f.toContinuousMultilinearMap.bound /-- Continuous alternating maps form a seminormed additive commutative group. We override projection to `PseudoMetricSpace` to ensure that instances commute in `with_reducible_and_instances`. -/ instance instSeminormedAddCommGroup : SeminormedAddCommGroup (E [⋀^ι]→L[𝕜] F) where toPseudoMetricSpace := .induced toContinuousMultilinearMap inferInstance __ := SeminormedAddCommGroup.induced _ _ (toMultilinearAddHom : E [⋀^ι]→L[𝕜] F →+ _) norm f := ‖f.toContinuousMultilinearMap‖ @[simp] theorem norm_toContinuousMultilinearMap (f : E [⋀^ι]→L[𝕜] F) : ‖f.1‖ = ‖f‖ := rfl @[simp] theorem nnnorm_toContinuousMultilinearMap (f : E [⋀^ι]→L[𝕜] F) : ‖f.1‖₊ = ‖f‖₊ := rfl @[simp] theorem enorm_toContinuousMultilinearMap (f : E [⋀^ι]→L[𝕜] F) : ‖f.1‖ₑ = ‖f‖ₑ := rfl /-- The inclusion of `E [⋀^ι]→L[𝕜] F` into `ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ E) F` as a linear isometry. -/ @[simps!] def toContinuousMultilinearMapLI : E [⋀^ι]→L[𝕜] F →ₗᵢ[𝕜] ContinuousMultilinearMap 𝕜 (fun _ : ι ↦ E) F where toLinearMap := toContinuousMultilinearMapLinear norm_map' _ := rfl theorem norm_def (f : E [⋀^ι]→L[𝕜] F) : ‖f‖ = sInf {c : ℝ | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} := rfl theorem bounds_nonempty : ∃ c, c ∈ {c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} := ContinuousMultilinearMap.bounds_nonempty theorem bounds_bddBelow {f : E [⋀^ι]→L[𝕜] F} : BddBelow {c | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} := ContinuousMultilinearMap.bounds_bddBelow theorem isLeast_opNorm (f : E [⋀^ι]→L[𝕜] F) : IsLeast {c : ℝ | 0 ≤ c ∧ ∀ m, ‖f m‖ ≤ c * ∏ i, ‖m i‖} ‖f‖ := f.1.isLeast_opNorm /-- The fundamental property of the operator norm of a continuous alternating map: `‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`. -/ theorem le_opNorm (f : E [⋀^ι]→L[𝕜] F) (m : ι → E) : ‖f m‖ ≤ ‖f‖ * ∏ i, ‖m i‖ := f.1.le_opNorm m theorem le_mul_prod_of_opNorm_le_of_le {m : ι → E} {C : ℝ} {b : ι → ℝ} (hC : ‖f‖ ≤ C) (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ C * ∏ i, b i := f.1.le_mul_prod_of_opNorm_le_of_le hC hm theorem le_opNorm_mul_prod_of_le (f : E [⋀^ι]→L[𝕜] F) {b : ι → ℝ} (hm : ∀ i, ‖m i‖ ≤ b i) : ‖f m‖ ≤ ‖f‖ * ∏ i, b i := f.1.le_opNorm_mul_prod_of_le hm theorem le_opNorm_mul_pow_card_of_le (f : E [⋀^ι]→L[𝕜] F) {m b} (hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ Fintype.card ι := f.1.le_opNorm_mul_pow_card_of_le hm theorem le_opNorm_mul_pow_of_le {n} (f : E [⋀^Fin n]→L[𝕜] F) {m b} (hm : ‖m‖ ≤ b) : ‖f m‖ ≤ ‖f‖ * b ^ n := f.1.le_opNorm_mul_pow_of_le hm theorem le_of_opNorm_le {C : ℝ} (h : ‖f‖ ≤ C) (m : ι → E) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := f.1.le_of_opNorm_le h m theorem ratio_le_opNorm (f : E [⋀^ι]→L[𝕜] F) (m : ι → E) : ‖f m‖ / ∏ i, ‖m i‖ ≤ ‖f‖ := f.1.ratio_le_opNorm m /-- The image of the unit ball under a continuous alternating map is bounded. -/ theorem unit_le_opNorm (f : E [⋀^ι]→L[𝕜] F) (h : ‖m‖ ≤ 1) : ‖f m‖ ≤ ‖f‖ := f.1.unit_le_opNorm h /-- If one controls the norm of every `f x`, then one controls the norm of `f`. -/ theorem opNorm_le_bound (f : E [⋀^ι]→L[𝕜] F) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ m, ‖f m‖ ≤ M * ∏ i, ‖m i‖) : ‖f‖ ≤ M := f.1.opNorm_le_bound hMp hM theorem opNorm_le_iff {C : ℝ} (hC : 0 ≤ C) : ‖f‖ ≤ C ↔ ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖ := f.1.opNorm_le_iff hC /-- The fundamental property of the operator norm of a continuous alternating map: `‖f m‖` is bounded by `‖f‖` times the product of the `‖m i‖`, `nnnorm` version. -/ theorem le_opNNNorm (f : E [⋀^ι]→L[𝕜] F) (m : ι → E) : ‖f m‖₊ ≤ ‖f‖₊ * ∏ i, ‖m i‖₊ := f.1.le_opNNNorm m theorem le_of_opNNNorm_le {C : ℝ≥0} (h : ‖f‖₊ ≤ C) (m : ι → E) : ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := f.1.le_of_opNNNorm_le h m theorem opNNNorm_le_iff {C : ℝ≥0} : ‖f‖₊ ≤ C ↔ ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊ := f.1.opNNNorm_le_iff theorem isLeast_opNNNorm (f : E [⋀^ι]→L[𝕜] F) : IsLeast {C : ℝ≥0 | ∀ m, ‖f m‖₊ ≤ C * ∏ i, ‖m i‖₊} ‖f‖₊ := f.1.isLeast_opNNNorm theorem opNNNorm_prod (f : E [⋀^ι]→L[𝕜] F) (g : E [⋀^ι]→L[𝕜] G) : ‖f.prod g‖₊ = max (‖f‖₊) (‖g‖₊) := f.1.opNNNorm_prod g.1 theorem opNorm_prod (f : E [⋀^ι]→L[𝕜] F) (g : E [⋀^ι]→L[𝕜] G) : ‖f.prod g‖ = max (‖f‖) (‖g‖) := f.1.opNorm_prod g.1 theorem opNNNorm_pi {ι' : Type*} [Fintype ι'] {F : ι' → Type*} [∀ i', SeminormedAddCommGroup (F i')] [∀ i', NormedSpace 𝕜 (F i')] (f : ∀ i', E [⋀^ι]→L[𝕜] F i') : ‖pi f‖₊ = ‖f‖₊ := ContinuousMultilinearMap.opNNNorm_pi fun i ↦ (f i).1 theorem opNorm_pi {ι' : Type*} [Fintype ι'] {F : ι' → Type*} [∀ i', SeminormedAddCommGroup (F i')] [∀ i', NormedSpace 𝕜 (F i')] (f : ∀ i', E [⋀^ι]→L[𝕜] F i') : ‖pi f‖ = ‖f‖ := ContinuousMultilinearMap.opNorm_pi fun i ↦ (f i).1 instance instNormedSpace {𝕜' : Type*} [NormedField 𝕜'] [NormedSpace 𝕜' F] [SMulCommClass 𝕜 𝕜' F] : NormedSpace 𝕜' (E [⋀^ι]→L[𝕜] F) := ⟨fun c f ↦ f.1.opNorm_smul_le c⟩ section @[simp] theorem norm_ofSubsingleton [Subsingleton ι] (i : ι) (f : E →L[𝕜] F) : ‖ofSubsingleton 𝕜 E F i f‖ = ‖f‖ := ContinuousMultilinearMap.norm_ofSubsingleton i f @[simp] theorem nnnorm_ofSubsingleton [Subsingleton ι] (i : ι) (f : E →L[𝕜] F) : ‖ofSubsingleton 𝕜 E F i f‖₊ = ‖f‖₊ := NNReal.eq <| norm_ofSubsingleton i f /-- `ContinuousAlternatingMap.ofSubsingleton` as a linear isometry. -/ @[simps +simpRhs] def ofSubsingletonLIE [Subsingleton ι] (i : ι) : (E →L[𝕜] F) ≃ₗᵢ[𝕜] (E [⋀^ι]→L[𝕜] F) where __ := ofSubsingleton 𝕜 E F i map_add' _ _ := rfl map_smul' _ _ := rfl norm_map' := norm_ofSubsingleton i theorem norm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) : ‖ofSubsingleton 𝕜 E E i (.id _ _)‖ ≤ 1 := ContinuousMultilinearMap.norm_ofSubsingleton_id_le .. theorem nnnorm_ofSubsingleton_id_le [Subsingleton ι] (i : ι) : ‖ofSubsingleton 𝕜 E E i (.id _ _)‖₊ ≤ 1 := ContinuousMultilinearMap.nnnorm_ofSubsingleton_id_le .. variable (𝕜 E) @[simp] theorem norm_constOfIsEmpty [IsEmpty ι] (x : F) : ‖constOfIsEmpty 𝕜 E ι x‖ = ‖x‖ := ContinuousMultilinearMap.norm_constOfIsEmpty _ _ _ @[simp] theorem nnnorm_constOfIsEmpty [IsEmpty ι] (x : F) : ‖constOfIsEmpty 𝕜 E ι x‖₊ = ‖x‖₊ := NNReal.eq <| norm_constOfIsEmpty _ _ _ end variable (𝕜 E F G) in /-- `ContinuousAlternatingMap.prod` as a `LinearIsometryEquiv`. -/ @[simps] def prodLIE : (E [⋀^ι]→L[𝕜] F) × (E [⋀^ι]→L[𝕜] G) ≃ₗᵢ[𝕜] (E [⋀^ι]→L[𝕜] (F × G)) where toFun f := f.1.prod f.2 invFun f := ((ContinuousLinearMap.fst 𝕜 F G).compContinuousAlternatingMap f, (ContinuousLinearMap.snd 𝕜 F G).compContinuousAlternatingMap f) map_add' _ _ := rfl map_smul' _ _ := rfl norm_map' f := opNorm_prod f.1 f.2 variable (𝕜 E) in /-- `ContinuousAlternatingMap.pi` as a `LinearIsometryEquiv`. -/ @[simps!] def piLIE {ι' : Type*} [Fintype ι'] {F : ι' → Type*} [∀ i', SeminormedAddCommGroup (F i')] [∀ i', NormedSpace 𝕜 (F i')] : (∀ i', E [⋀^ι]→L[𝕜] F i') ≃ₗᵢ[𝕜] (E [⋀^ι]→L[𝕜] (∀ i, F i)) where toLinearEquiv := piLinearEquiv norm_map' := opNorm_pi section restrictScalars variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜' 𝕜] variable [NormedSpace 𝕜' F] [IsScalarTower 𝕜' 𝕜 F] variable [NormedSpace 𝕜' E] [IsScalarTower 𝕜' 𝕜 E] @[simp] theorem norm_restrictScalars : ‖f.restrictScalars 𝕜'‖ = ‖f‖ := rfl variable (𝕜') /-- `ContinuousAlternatingMap.restrictScalars` as a `LinearIsometry`. -/ @[simps] def restrictScalarsLI : E [⋀^ι]→L[𝕜] F →ₗᵢ[𝕜'] E [⋀^ι]→L[𝕜'] F where toFun := restrictScalars 𝕜' map_add' _ _ := rfl map_smul' _ _ := rfl norm_map' _ := rfl variable {𝕜'} end restrictScalars /-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, precise version. For a less precise but more usable version, see `norm_image_sub_le`. The bound reads `‖f m - f m'‖ ≤ ‖f‖ * ‖m 1 - m' 1‖ * max ‖m 2‖ ‖m' 2‖ * max ‖m 3‖ ‖m' 3‖ * ... * max ‖m n‖ ‖m' n‖ + ...`, where the other terms in the sum are the same products where `1` is replaced by any `i`. -/ theorem norm_image_sub_le' [DecidableEq ι] (f : E [⋀^ι]→L[𝕜] F) (m₁ m₂ : ι → E) : ‖f m₁ - f m₂‖ ≤ ‖f‖ * ∑ i, ∏ j, if j = i then ‖m₁ i - m₂ i‖ else max ‖m₁ j‖ ‖m₂ j‖ := f.1.norm_image_sub_le' m₁ m₂ /-- The difference `f m₁ - f m₂` is controlled in terms of `‖f‖` and `‖m₁ - m₂‖`, less precise version. For a more precise but less usable version, see `norm_image_sub_le'`. The bound is `‖f m - f m'‖ ≤ ‖f‖ * card ι * ‖m - m'‖ * (max ‖m‖ ‖m'‖) ^ (card ι - 1)`. -/ theorem norm_image_sub_le (f : E [⋀^ι]→L[𝕜] F) (m₁ m₂ : ι → E) : ‖f m₁ - f m₂‖ ≤ ‖f‖ * (Fintype.card ι) * (max ‖m₁‖ ‖m₂‖) ^ (Fintype.card ι - 1) * ‖m₁ - m₂‖ := f.1.norm_image_sub_le m₁ m₂ end ContinuousAlternatingMap variable [Fintype ι] /-- If a continuous alternating map is constructed from a alternating map via the constructor `mkContinuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ theorem AlternatingMap.mkContinuous_norm_le (f : E [⋀^ι]→ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ C := f.toMultilinearMap.mkContinuous_norm_le hC H /-- If a continuous alternating map is constructed from a alternating map via the constructor `mk_continuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ theorem AlternatingMap.mkContinuous_norm_le' (f : E [⋀^ι]→ₗ[𝕜] F) {C : ℝ} (H : ∀ m, ‖f m‖ ≤ C * ∏ i, ‖m i‖) : ‖f.mkContinuous C H‖ ≤ max C 0 := ContinuousMultilinearMap.opNorm_le_bound (le_max_right _ _) fun m ↦ (H m).trans <| by gcongr apply le_max_left namespace ContinuousLinearMap theorem norm_compContinuousAlternatingMap_le (g : F →L[𝕜] G) (f : E [⋀^ι]→L[𝕜] F) : ‖g.compContinuousAlternatingMap f‖ ≤ ‖g‖ * ‖f‖ := g.norm_compContinuousMultilinearMap_le f.1 variable (𝕜 E F G) in /-- `ContinuousLinearMap.compContinuousAlternatingMap` as a bundled continuous bilinear map. -/ @[simps! apply_apply] def compContinuousAlternatingMapCLM : (F →L[𝕜] G) →L[𝕜] (E [⋀^ι]→L[𝕜] F) →L[𝕜] (E [⋀^ι]→L[𝕜] G) := LinearMap.mkContinuous₂ (compContinuousAlternatingMapₗ 𝕜 E F G) 1 fun f g ↦ by simpa using f.norm_compContinuousAlternatingMap_le g /-- `ContinuousLinearMap.compContinuousAlternatingMap` as a bundled continuous linear equiv. -/ @[simps +simpRhs apply] def _root_.ContinuousLinearEquiv.continuousAlternatingMapCongrRight (g : F ≃L[𝕜] G) : (E [⋀^ι]→L[𝕜] F) ≃L[𝕜] (E [⋀^ι]→L[𝕜] G) where __ := g.continuousAlternatingMapCongrRightEquiv __ := compContinuousAlternatingMapCLM 𝕜 E F G g.toContinuousLinearMap continuous_toFun := (compContinuousAlternatingMapCLM 𝕜 E F G g.toContinuousLinearMap).continuous continuous_invFun := (compContinuousAlternatingMapCLM 𝕜 E G F g.symm.toContinuousLinearMap).continuous @[simp] theorem _root_.ContinuousLinearEquiv.continuousAlternatingMapCongrRight_symm (g : F ≃L[𝕜] G) : (g.continuousAlternatingMapCongrRight (ι := ι) (E := E)).symm = g.symm.continuousAlternatingMapCongrRight := rfl /-- Flip arguments in `f : F →L[𝕜] E [⋀^ι]→L[𝕜] G` to get `⋀^ι⟮𝕜; E; F →L[𝕜] G⟯` -/ @[simps! apply_apply] def flipAlternating (f : F →L[𝕜] (E [⋀^ι]→L[𝕜] G)) : E [⋀^ι]→L[𝕜] (F →L[𝕜] G) where toContinuousMultilinearMap := ((ContinuousAlternatingMap.toContinuousMultilinearMapCLM 𝕜).comp f).flipMultilinear map_eq_zero_of_eq' v i j hv hne := by ext x; simp [(f x).map_eq_zero_of_eq v hv hne] end ContinuousLinearMap theorem LinearIsometry.norm_compContinuousAlternatingMap (g : F →ₗᵢ[𝕜] G) (f : E [⋀^ι]→L[𝕜] F) : ‖g.toContinuousLinearMap.compContinuousAlternatingMap f‖ = ‖f‖ := g.norm_compContinuousMultilinearMap f.1 open ContinuousAlternatingMap section theorem ContinuousAlternatingMap.norm_compContinuousLinearMap_le (f : F [⋀^ι]→L[𝕜] G) (g : E →L[𝕜] F) : ‖f.compContinuousLinearMap g‖ ≤ ‖f‖ * (‖g‖ ^ Fintype.card ι) := (f.1.norm_compContinuousLinearMap_le _).trans_eq <| by simp /-- Composition of a continuous alternating map and a continuous linear map as a bundled continuous linear map. -/ def ContinuousAlternatingMap.compContinuousLinearMapCLM (f : E →L[𝕜] F) : (F [⋀^ι]→L[𝕜] G) →L[𝕜] (E [⋀^ι]→L[𝕜] G) := LinearMap.mkContinuous (ContinuousAlternatingMap.compContinuousLinearMapₗ f) (‖f‖ ^ Fintype.card ι) fun g ↦ (g.norm_compContinuousLinearMap_le f).trans_eq (mul_comm _ _) /-- Given a continuous linear isomorphism between the domains, generate a continuous linear isomorphism between the spaces of continuous alternating maps. This is `ContinuousAlternatingMap.compContinuousLinearMap` as an equivalence, and is the continuous version of `AlternatingMap.domLCongr`. -/ @[simps apply] def ContinuousLinearEquiv.continuousAlternatingMapCongrLeft (f : E ≃L[𝕜] F) : E [⋀^ι]→L[𝕜] G ≃L[𝕜] (F [⋀^ι]→L[𝕜] G) where __ := f.continuousAlternatingMapCongrLeftEquiv __ := ContinuousAlternatingMap.compContinuousLinearMapCLM (f.symm : F →L[𝕜] E) toFun g := g.compContinuousLinearMap (f.symm : F →L[𝕜] E) continuous_invFun := (ContinuousAlternatingMap.compContinuousLinearMapCLM (f : E →L[𝕜] F)).cont continuous_toFun := (ContinuousAlternatingMap.compContinuousLinearMapCLM (f.symm : F →L[𝕜] E)).cont variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] /-- Continuous linear equivalences between the domains and the codomains generate a continuous linear equivalence between the spaces of continuous alternating maps. -/ @[simps! apply] def ContinuousLinearEquiv.continuousAlternatingMapCongr (e : E ≃L[𝕜] E') (e' : F ≃L[𝕜] F') : (E [⋀^ι]→L[𝕜] F) ≃L[𝕜] (E' [⋀^ι]→L[𝕜] F') := e.continuousAlternatingMapCongrLeft.trans <| e'.continuousAlternatingMapCongrRight end open ContinuousAlternatingMap namespace AlternatingMap /-- Given a map `f : F →ₗ[𝕜] E [⋀^ι]→ₗ[𝕜] G` and an estimate `H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖`, construct a continuous linear map from `F` to `E [⋀^ι]→L[𝕜] G`. In order to lift, e.g., a map `f : (E [⋀^ι]→ₗ[𝕜] F) →ₗ[𝕜] E' [⋀^ι]→ₗ[𝕜] G` to a map `(E [⋀^ι]→L[𝕜] F) →L[𝕜] E' [⋀^ι]→L[𝕜] G`, one can apply this construction to `f.comp ContinuousAlternatingMap.toAlternatingMapLinear` which is a linear map from `E [⋀^ι]→L[𝕜] F` to `E' [⋀^ι]→ₗ[𝕜] G`. -/ def mkContinuousLinear (f : F →ₗ[𝕜] E [⋀^ι]→ₗ[𝕜] G) (C : ℝ) (H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : F →L[𝕜] E [⋀^ι]→L[𝕜] G := LinearMap.mkContinuous { toFun x := (f x).mkContinuous (C * ‖x‖) <| H x map_add' x y := by ext1; simp map_smul' c x := by ext1; simp } (max C 0) fun x ↦ by rw [LinearMap.coe_mk, AddHom.coe_mk] exact (mkContinuous_norm_le' _ _).trans_eq <| by rw [max_mul_of_nonneg _ _ (norm_nonneg x), zero_mul] theorem mkContinuousLinear_norm_le_max (f : F →ₗ[𝕜] E [⋀^ι]→ₗ[𝕜] G) (C : ℝ) (H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : ‖mkContinuousLinear f C H‖ ≤ max C 0 := LinearMap.mkContinuous_norm_le _ (le_max_right _ _) _ theorem mkContinuousLinear_norm_le (f : F →ₗ[𝕜] E [⋀^ι]→ₗ[𝕜] G) {C : ℝ} (hC : 0 ≤ C) (H : ∀ x m, ‖f x m‖ ≤ C * ‖x‖ * ∏ i, ‖m i‖) : ‖mkContinuousLinear f C H‖ ≤ C := (mkContinuousLinear_norm_le_max f C H).trans_eq (max_eq_left hC) variable {ι' : Type*} [Fintype ι'] /-- Given a map `f : E [⋀^ι]→ₗ[𝕜] (F [⋀^ι']→ₗ[𝕜] G)` and an estimate `H : ∀ m m', ‖f m m'‖ ≤ C * ∏ i, ‖m i‖ * ∏ i, ‖m' i‖`, upgrade all `AlternatingMap`s in the type to `ContinuousAlternatingMap`s. -/ def mkContinuousAlternating (f : E [⋀^ι]→ₗ[𝕜] (F [⋀^ι']→ₗ[𝕜] G)) (C : ℝ) (H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) : E [⋀^ι]→L[𝕜] (F [⋀^ι']→L[𝕜] G) := mkContinuous { toFun m := mkContinuous (f m) (C * ∏ i, ‖m i‖) <| H m map_update_add' m i x y := by ext1; simp map_update_smul' m i c x := by ext1; simp map_eq_zero_of_eq' v i j hv hij := by ext v' have : f v = 0 := by simpa using f.map_eq_zero_of_eq' v i j hv hij simp [this] } (max C 0) fun m => by simp only [coe_mk, MultilinearMap.coe_mk] refine ((f m).mkContinuous_norm_le' _).trans_eq ?_ rw [max_mul_of_nonneg, zero_mul] positivity @[simp] theorem mkContinuousAlternating_apply (f : E [⋀^ι]→ₗ[𝕜] (F [⋀^ι']→ₗ[𝕜] G)) {C : ℝ} (H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) (m : ι → E) : ⇑(mkContinuousAlternating f C H m) = f m := rfl theorem mkContinuousAlternating_norm_le_max (f : E [⋀^ι]→ₗ[𝕜] (F [⋀^ι']→ₗ[𝕜] G)) {C : ℝ} (H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) : ‖mkContinuousAlternating f C H‖ ≤ max C 0 := by dsimp only [mkContinuousAlternating] exact mkContinuous_norm_le _ (le_max_right _ _) _ theorem mkContinuousAlternating_norm_le (f : E [⋀^ι]→ₗ[𝕜] (F [⋀^ι']→ₗ[𝕜] G)) {C : ℝ} (hC : 0 ≤ C) (H : ∀ m₁ m₂, ‖f m₁ m₂‖ ≤ (C * ∏ i, ‖m₁ i‖) * ∏ i, ‖m₂ i‖) : ‖mkContinuousAlternating f C H‖ ≤ C := (mkContinuousAlternating_norm_le_max f H).trans_eq (max_eq_left hC) end AlternatingMap end Seminorm section Norm /-! Results that are only true if the target space is a `NormedAddCommGroup` (and not just a `SeminormedAddCommGroup`). -/ universe u wE wF v variable {𝕜 : Type u} {n : ℕ} {E : Type wE} {F : Type wF} {ι : Type v} [Fintype ι] [NontriviallyNormedField 𝕜] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] namespace ContinuousAlternatingMap /-- Continuous alternating maps themselves form a normed group with respect to the operator norm. -/ instance instNormedAddCommGroup : NormedAddCommGroup (E [⋀^ι]→L[𝕜] F) := NormedAddCommGroup.ofSeparation fun _f hf ↦ toContinuousMultilinearMap_injective <| norm_eq_zero.mp hf variable (𝕜 F) in theorem norm_ofSubsingleton_id [Subsingleton ι] [Nontrivial F] (i : ι) : ‖ofSubsingleton 𝕜 F F i (.id _ _)‖ = 1 := ContinuousMultilinearMap.norm_ofSubsingleton_id 𝕜 F i variable (𝕜 F) in theorem nnnorm_ofSubsingleton_id [Subsingleton ι] [Nontrivial F] (i : ι) : ‖ofSubsingleton 𝕜 F F i (.id _ _)‖₊ = 1 := NNReal.eq <| norm_ofSubsingleton_id .. end ContinuousAlternatingMap namespace AlternatingMap /-- If an alternating map in finitely many variables on a normed space satisfies the inequality `‖f m‖ ≤ C * ∏ i, ‖m i‖` on a shell `ε i / ‖c i‖ < ‖m i‖ < ε i` for some positive numbers `ε i` and elements `c i : 𝕜`, `1 < ‖c i‖`, then it satisfies this inequality for all `m`. -/ theorem bound_of_shell (f : F [⋀^ι]→ₗ[𝕜] E) {ε : ι → ℝ} {C : ℝ} {c : ι → 𝕜} (hε : ∀ i, 0 < ε i) (hc : ∀ i, 1 < ‖c i‖) (hf : ∀ m : ι → F, (∀ i, ε i / ‖c i‖ ≤ ‖m i‖) → (∀ i, ‖m i‖ < ε i) → ‖f m‖ ≤ C * ∏ i, ‖m i‖) (m : ι → F) : ‖f m‖ ≤ C * ∏ i, ‖m i‖ := f.1.bound_of_shell hε hc hf m end AlternatingMap end Norm
Invariant.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.GroupTheory.GroupAction.Hom import Mathlib.Algebra.Ring.Subring.Defs /-! # Subrings invariant under an action If a monoid acts on a ring via a `MulSemiringAction`, then `IsInvariantSubring` is a predicate on subrings asserting that the subring is fixed elementwise by the action. -/ assert_not_exists RelIso section Ring variable (M R : Type*) [Monoid M] [Ring R] [MulSemiringAction M R] variable (S : Subring R) open MulAction variable {R} /-- A typeclass for subrings invariant under a `MulSemiringAction`. -/ class IsInvariantSubring : Prop where smul_mem : ∀ (m : M) {x : R}, x ∈ S → m • x ∈ S instance IsInvariantSubring.toMulSemiringAction [IsInvariantSubring M S] : MulSemiringAction M S where smul m x := ⟨m • ↑x, IsInvariantSubring.smul_mem m x.2⟩ one_smul s := Subtype.eq <| one_smul M (s : R) mul_smul m₁ m₂ s := Subtype.eq <| mul_smul m₁ m₂ (s : R) smul_add m s₁ s₂ := Subtype.eq <| smul_add m (s₁ : R) (s₂ : R) smul_zero m := Subtype.eq <| smul_zero m smul_one m := Subtype.eq <| smul_one m smul_mul m s₁ s₂ := Subtype.eq <| smul_mul' m (s₁ : R) (s₂ : R) end Ring section variable (M : Type*) [Monoid M] variable {R' : Type*} [Ring R'] [MulSemiringAction M R'] variable (U : Subring R') [IsInvariantSubring M U] /-- The canonical inclusion from an invariant subring. -/ def IsInvariantSubring.subtypeHom : U →+*[M] R' := { U.subtype with map_smul' := fun _ _ ↦ rfl } @[simp] theorem IsInvariantSubring.coe_subtypeHom : (IsInvariantSubring.subtypeHom M U : U → R') = Subtype.val := rfl @[simp] theorem IsInvariantSubring.coe_subtypeHom' : ((IsInvariantSubring.subtypeHom M U) : U →+* R') = U.subtype := rfl end
BohrMollerup.lean
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Gamma.Deriv import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral /-! # Convexity properties of the Gamma function In this file, we prove that `Gamma` and `log ∘ Gamma` are convex functions on the positive real line. We then prove the Bohr-Mollerup theorem, which characterises `Gamma` as the *unique* positive-real-valued, log-convex function on the positive reals satisfying `f (x + 1) = x f x` and `f 1 = 1`. The proof of the Bohr-Mollerup theorem is bound up with the proof of (a weak form of) the Euler limit formula, `Real.BohrMollerup.tendsto_logGammaSeq`, stating that for positive real `x` the sequence `x * log n + log n! - ∑ (m : ℕ) ∈ Finset.range (n + 1), log (x + m)` tends to `log Γ(x)` as `n → ∞`. We prove that any function satisfying the hypotheses of the Bohr-Mollerup theorem must agree with the limit in the Euler limit formula, so there is at most one such function; then we show that `Γ` satisfies these conditions. Since most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the context of this proof, we place them in a separate namespace `Real.BohrMollerup` to avoid clutter. (This includes the logarithmic form of the Euler limit formula, since later we will prove a more general form of the Euler limit formula valid for any real or complex `x`; see `Real.Gamma_seq_tendsto_Gamma` and `Complex.Gamma_seq_tendsto_Gamma` in the file `Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean`.) As an application of the Bohr-Mollerup theorem we prove the Legendre doubling formula for the Gamma function for real positive `s` (which will be upgraded to a proof for all complex `s` in a later file). TODO: This argument can be extended to prove the general `k`-multiplication formula (at least up to a constant, and it should be possible to deduce the value of this constant using Stirling's formula). -/ noncomputable section open Filter Set MeasureTheory open scoped Nat ENNReal Topology Real namespace Real section Convexity /-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form), proved using the Hölder inequality applied to Euler's integral. -/ theorem Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : ℝ} (hs : 0 < s) (ht : 0 < t) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : Gamma (a * s + b * t) ≤ Gamma s ^ a * Gamma t ^ b := by -- We will apply Hölder's inequality, for the conjugate exponents `p = 1 / a` -- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows: let f : ℝ → ℝ → ℝ → ℝ := fun c u x => exp (-c * x) * x ^ (c * (u - 1)) have e : HolderConjugate (1 / a) (1 / b) := Real.holderConjugate_one_div ha hb hab have hab' : b = 1 - a := by linarith have hst : 0 < a * s + b * t := by positivity -- some properties of f: have posf : ∀ c u x : ℝ, x ∈ Ioi (0 : ℝ) → 0 ≤ f c u x := fun c u x hx => mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le have posf' : ∀ c u : ℝ, ∀ᵐ x : ℝ ∂volume.restrict (Ioi 0), 0 ≤ f c u x := fun c u => (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ (posf c u)) have fpow : ∀ {c x : ℝ} (_ : 0 < c) (u : ℝ) (_ : 0 < x), exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c) := by intro c x hc u hx dsimp only [f] rw [mul_rpow (exp_pos _).le ((rpow_nonneg hx.le) _), ← exp_mul, ← rpow_mul hx.le] congr 2 <;> field_simp [hc.ne']; ring -- show `f c u` is in `ℒp` for `p = 1/c`: have f_mem_Lp : ∀ {c u : ℝ} (hc : 0 < c) (hu : 0 < u), MemLp (f c u) (ENNReal.ofReal (1 / c)) (volume.restrict (Ioi 0)) := by intro c u hc hu have A : ENNReal.ofReal (1 / c) ≠ 0 := by rwa [Ne, ENNReal.ofReal_eq_zero, not_le, one_div_pos] have B : ENNReal.ofReal (1 / c) ≠ ∞ := ENNReal.ofReal_ne_top rw [← memLp_norm_rpow_iff _ A B, ENNReal.toReal_ofReal (one_div_nonneg.mpr hc.le), ENNReal.div_self A B, memLp_one_iff_integrable] · apply Integrable.congr (GammaIntegral_convergent hu) refine eventuallyEq_of_mem (self_mem_ae_restrict measurableSet_Ioi) fun x hx => ?_ dsimp only rw [fpow hc u hx] congr 1 exact (norm_of_nonneg (posf _ _ x hx)).symm · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi refine (Continuous.continuousOn ?_).mul (continuousOn_of_forall_continuousAt fun x hx => ?_) · exact continuous_exp.comp (continuous_const.mul continuous_id') · exact continuousAt_rpow_const _ _ (Or.inl (mem_Ioi.mp hx).ne') -- now apply Hölder: rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst] convert MeasureTheory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t) (f_mem_Lp ha hs) (f_mem_Lp hb ht) using 1 · refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ dsimp only have A : exp (-x) = exp (-a * x) * exp (-b * x) := by rw [← exp_add, ← add_mul, ← neg_add, hab, neg_one_mul] have B : x ^ (a * s + b * t - 1) = x ^ (a * (s - 1)) * x ^ (b * (t - 1)) := by rw [← rpow_add hx, hab']; congr 1; ring rw [A, B] ring · rw [one_div_one_div, one_div_one_div] congr 2 <;> exact setIntegral_congr_fun measurableSet_Ioi fun x hx => fpow (by assumption) _ hx theorem convexOn_log_Gamma : ConvexOn ℝ (Ioi 0) (log ∘ Gamma) := by refine convexOn_iff_forall_pos.mpr ⟨convex_Ioi _, fun x hx y hy a b ha hb hab => ?_⟩ have : b = 1 - a := by linarith subst this simp_rw [Function.comp_apply, smul_eq_mul] simp only [mem_Ioi] at hx hy rw [← log_rpow, ← log_rpow, ← log_mul] · gcongr exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab all_goals positivity theorem convexOn_Gamma : ConvexOn ℝ (Ioi 0) Gamma := by refine ((convexOn_exp.subset (subset_univ _) ?_).comp convexOn_log_Gamma (exp_monotone.monotoneOn _)).congr fun x hx => exp_log (Gamma_pos_of_pos hx) rw [convex_iff_isPreconnected] refine isPreconnected_Ioi.image _ fun x hx => ContinuousAt.continuousWithinAt ?_ refine (differentiableAt_Gamma fun m => ?_).continuousAt.log (Gamma_pos_of_pos hx).ne' exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg (mem_Ioi.mp hx) (Nat.cast_nonneg m))).ne' end Convexity section BohrMollerup namespace BohrMollerup /-- The function `n ↦ x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to `log (Gamma x)` as `n → ∞`. -/ def logGammaSeq (x : ℝ) (n : ℕ) : ℝ := x * log n + log n ! - ∑ m ∈ Finset.range (n + 1), log (x + m) variable {f : ℝ → ℝ} {x : ℝ} {n : ℕ} theorem f_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) : f n = f 1 + log (n - 1)! := by refine Nat.le_induction (by simp) (fun m hm IH => ?_) n (Nat.one_le_iff_ne_zero.2 hn) have A : 0 < (m : ℝ) := Nat.cast_pos.2 hm simp only [hf_feq A, Nat.cast_add, Nat.cast_one, Nat.add_succ_sub_one, add_zero] rw [IH, add_assoc, ← log_mul (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) A.ne', ← Nat.cast_mul] conv_rhs => rw [← Nat.succ_pred_eq_of_pos hm, Nat.factorial_succ, mul_comm] congr exact (Nat.succ_pred_eq_of_pos hm).symm theorem f_add_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (n : ℕ) : f (x + n) = f x + ∑ m ∈ Finset.range n, log (x + m) := by induction n with | zero => simp | succ n hn => have : x + n.succ = x + n + 1 := by push_cast; ring rw [this, hf_feq, hn] · rw [Finset.range_succ, Finset.sum_insert Finset.notMem_range_self] abel · linarith [(Nat.cast_nonneg n : 0 ≤ (n : ℝ))] /-- Linear upper bound for `f (x + n)` on unit interval -/ theorem f_add_nat_le (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) (hx : 0 < x) (hx' : x ≤ 1) : f (n + x) ≤ f n + x * log n := by have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) have : f n + x * log n = (1 - x) * f n + x * f (n + 1) := by rw [hf_feq hn']; ring rw [this, (by ring : (n : ℝ) + x = (1 - x) * n + x * (n + 1))] simpa only [smul_eq_mul] using hf_conv.2 hn' (by linarith : 0 < (n + 1 : ℝ)) (by linarith : 0 ≤ 1 - x) hx.le (by linarith) /-- Linear lower bound for `f (x + n)` on unit interval -/ theorem f_add_nat_ge (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : 2 ≤ n) (hx : 0 < x) : f n + x * log (n - 1) ≤ f (n + x) := by have npos : 0 < (n : ℝ) - 1 := by rw [← Nat.cast_one, sub_pos, Nat.cast_lt]; omega have c := (convexOn_iff_slope_mono_adjacent.mp <| hf_conv).2 npos (by linarith : 0 < (n : ℝ) + x) (by linarith : (n : ℝ) - 1 < (n : ℝ)) (by linarith) rw [add_sub_cancel_left, sub_sub_cancel, div_one] at c have : f (↑n - 1) = f n - log (↑n - 1) := by rw [eq_sub_iff_add_eq, ← hf_feq npos, sub_add_cancel] rwa [this, le_div_iff₀ hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c theorem logGammaSeq_add_one (x : ℝ) (n : ℕ) : logGammaSeq (x + 1) n = logGammaSeq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) := by dsimp only [Nat.factorial_succ, logGammaSeq] conv_rhs => rw [Finset.sum_range_succ', Nat.cast_zero, add_zero] rw [Nat.cast_mul, log_mul]; rotate_left · rw [Nat.cast_ne_zero]; exact Nat.succ_ne_zero n · rw [Nat.cast_ne_zero]; exact Nat.factorial_ne_zero n have : ∑ m ∈ Finset.range (n + 1), log (x + 1 + ↑m) = ∑ k ∈ Finset.range (n + 1), log (x + ↑(k + 1)) := by congr! 2 with m push_cast abel rw [← this, Nat.cast_add_one n] ring theorem le_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) (n : ℕ) : f x ≤ f 1 + x * log (n + 1) - x * log n + logGammaSeq x n := by rw [logGammaSeq, ← add_sub_assoc, le_sub_iff_add_le, ← f_add_nat_eq (@hf_feq) hx, add_comm x] refine (f_add_nat_le hf_conv (@hf_feq) (Nat.add_one_ne_zero n) hx hx').trans (le_of_eq ?_) rw [f_nat_eq @hf_feq (by omega : n + 1 ≠ 0), Nat.add_sub_cancel, Nat.cast_add_one] ring theorem ge_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hn : n ≠ 0) : f 1 + logGammaSeq x n ≤ f x := by dsimp [logGammaSeq] rw [← add_sub_assoc, sub_le_iff_le_add, ← f_add_nat_eq (@hf_feq) hx, add_comm x _] refine le_trans (le_of_eq ?_) (f_add_nat_ge hf_conv @hf_feq ?_ hx) · rw [f_nat_eq @hf_feq, Nat.add_sub_cancel, Nat.cast_add_one, add_sub_cancel_right] · ring · exact Nat.succ_ne_zero _ · omega theorem tendsto_logGammaSeq_of_le_one (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by refine tendsto_of_tendsto_of_tendsto_of_le_of_le' (f := logGammaSeq x) (g := fun n ↦ f x - f 1 - x * (log (n + 1) - log n)) ?_ tendsto_const_nhds ?_ ?_ · have : f x - f 1 = f x - f 1 - x * 0 := by ring nth_rw 2 [this] exact Tendsto.sub tendsto_const_nhds (tendsto_log_nat_add_one_sub_log.const_mul _) · filter_upwards with n rw [sub_le_iff_le_add', sub_le_iff_le_add'] convert le_logGammaSeq hf_conv (@hf_feq) hx hx' n using 1 ring · change ∀ᶠ n : ℕ in atTop, logGammaSeq x n ≤ f x - f 1 filter_upwards [eventually_ne_atTop 0] with n hn using le_sub_iff_add_le'.mpr (ge_logGammaSeq hf_conv hf_feq hx hn) theorem tendsto_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by suffices ∀ m : ℕ, ↑m < x → x ≤ m + 1 → Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) by refine this ⌈x - 1⌉₊ ?_ ?_ · rcases lt_or_ge x 1 with ⟨⟩ · rwa [Nat.ceil_eq_zero.mpr (by linarith : x - 1 ≤ 0), Nat.cast_zero] · convert Nat.ceil_lt_add_one (by linarith : 0 ≤ x - 1) abel · rw [← sub_le_iff_le_add]; exact Nat.le_ceil _ intro m induction' m with m hm generalizing x · rw [Nat.cast_zero, zero_add] exact fun _ hx' => tendsto_logGammaSeq_of_le_one hf_conv (@hf_feq) hx hx' · intro hy hy' rw [Nat.cast_succ, ← sub_le_iff_le_add] at hy' rw [Nat.cast_succ, ← lt_sub_iff_add_lt] at hy specialize hm ((Nat.cast_nonneg _).trans_lt hy) hy hy' -- now massage gauss_product n (x - 1) into gauss_product (n - 1) x have : ∀ᶠ n : ℕ in atTop, logGammaSeq (x - 1) n = logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1) := by refine Eventually.mp (eventually_ge_atTop 1) (Eventually.of_forall fun n hn => ?_) have := logGammaSeq_add_one (x - 1) (n - 1) rw [sub_add_cancel, Nat.sub_add_cancel hn] at this rw [this] ring replace hm := ((Tendsto.congr' this hm).add (tendsto_const_nhds : Tendsto (fun _ => log (x - 1)) _ _)).comp (tendsto_add_atTop_nat 1) have : ((fun x_1 : ℕ => (fun n : ℕ => logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1)) x_1 + (fun b : ℕ => log (x - 1)) x_1) ∘ fun a : ℕ => a + 1) = fun n => logGammaSeq x n + x * (log (↑n + 1) - log ↑n) := by ext1 n dsimp only [Function.comp_apply] rw [sub_add_cancel, Nat.add_sub_cancel] rw [this] at hm convert hm.sub (tendsto_log_nat_add_one_sub_log.const_mul x) using 2 · ring · have := hf_feq ((Nat.cast_nonneg m).trans_lt hy) rw [sub_add_cancel] at this rw [this] ring theorem tendsto_log_gamma {x : ℝ} (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| log (Gamma x)) := by have : log (Gamma x) = (log ∘ Gamma) x - (log ∘ Gamma) 1 := by simp_rw [Function.comp_apply, Gamma_one, log_one, sub_zero] rw [this] refine BohrMollerup.tendsto_logGammaSeq convexOn_log_Gamma (fun {y} hy => ?_) hx rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] end BohrMollerup -- (namespace) /-- The **Bohr-Mollerup theorem**: the Gamma function is the *unique* log-convex, positive-valued function on the positive reals which satisfies `f 1 = 1` and `f (x + 1) = x * f x` for all `x`. -/ theorem eq_Gamma_of_log_convex {f : ℝ → ℝ} (hf_conv : ConvexOn ℝ (Ioi 0) (log ∘ f)) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = y * f y) (hf_pos : ∀ {y : ℝ}, 0 < y → 0 < f y) (hf_one : f 1 = 1) : EqOn f Gamma (Ioi (0 : ℝ)) := by suffices EqOn (log ∘ f) (log ∘ Gamma) (Ioi (0 : ℝ)) from fun x hx ↦ log_injOn_pos (hf_pos hx) (Gamma_pos_of_pos hx) (this hx) intro x hx have e1 := BohrMollerup.tendsto_logGammaSeq hf_conv ?_ hx · rw [Function.comp_apply (f := log) (g := f) (x := 1), hf_one, log_one, sub_zero] at e1 exact tendsto_nhds_unique e1 (BohrMollerup.tendsto_log_gamma hx) · intro y hy rw [Function.comp_apply, Function.comp_apply, hf_feq hy, log_mul hy.ne' (hf_pos hy).ne'] ring end BohrMollerup -- (section) section StrictMono theorem Gamma_two : Gamma 2 = 1 := by simp [Nat.factorial_one] theorem Gamma_three_div_two_lt_one : Gamma (3 / 2) < 1 := by -- This can also be proved using the closed-form evaluation of `Gamma (1 / 2)` in -- `Mathlib/Analysis/SpecialFunctions/Gaussian.lean`, but we give a self-contained proof using -- log-convexity to avoid unnecessary imports. have A : (0 : ℝ) < 3 / 2 := by simp have := BohrMollerup.f_add_nat_le convexOn_log_Gamma (fun {y} hy => ?_) two_ne_zero one_half_pos (by norm_num : 1 / 2 ≤ (1 : ℝ)) swap · rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] rw [Function.comp_apply, Function.comp_apply, Nat.cast_two, Gamma_two, log_one, zero_add, (by norm_num : (2 : ℝ) + 1 / 2 = 3 / 2 + 1), Gamma_add_one A.ne', log_mul A.ne' (Gamma_pos_of_pos A).ne', ← le_sub_iff_add_le', log_le_iff_le_exp (Gamma_pos_of_pos A)] at this refine this.trans_lt (exp_lt_one_iff.mpr ?_) rw [mul_comm, ← mul_div_assoc, div_sub' two_ne_zero] refine div_neg_of_neg_of_pos ?_ two_pos rw [sub_neg, mul_one, ← Nat.cast_two, ← log_pow, ← exp_lt_exp, Nat.cast_two, exp_log two_pos, exp_log] <;> norm_num theorem Gamma_strictMonoOn_Ici : StrictMonoOn Gamma (Ici 2) := by convert convexOn_Gamma.strict_mono_of_lt (by norm_num : (0 : ℝ) < 3 / 2) (by norm_num : (3 / 2 : ℝ) < 2) (Gamma_two.symm ▸ Gamma_three_div_two_lt_one) symm rw [inter_eq_right] exact fun x hx => two_pos.trans_le <| mem_Ici.mp hx end StrictMono section Doubling /-! ## The Gamma doubling formula As a fun application of the Bohr-Mollerup theorem, we prove the Gamma-function doubling formula (for positive real `s`). The idea is that `2 ^ s * Gamma (s / 2) * Gamma (s / 2 + 1 / 2)` is log-convex and satisfies the Gamma functional equation, so it must actually be a constant multiple of `Gamma`, and we can compute the constant by specialising at `s = 1`. -/ /-- Auxiliary definition for the doubling formula (we'll show this is equal to `Gamma s`) -/ def doublingGamma (s : ℝ) : ℝ := Gamma (s / 2) * Gamma (s / 2 + 1 / 2) * 2 ^ (s - 1) / √π theorem doublingGamma_add_one (s : ℝ) (hs : s ≠ 0) : doublingGamma (s + 1) = s * doublingGamma s := by rw [doublingGamma, doublingGamma, (by abel : s + 1 - 1 = s - 1 + 1), add_div, add_assoc, add_halves (1 : ℝ), Gamma_add_one (div_ne_zero hs two_ne_zero), rpow_add two_pos, rpow_one] ring theorem doublingGamma_one : doublingGamma 1 = 1 := by simp_rw [doublingGamma, Gamma_one_half_eq, add_halves (1 : ℝ), sub_self, Gamma_one, mul_one, rpow_zero, mul_one, div_self (sqrt_ne_zero'.mpr pi_pos)] theorem log_doublingGamma_eq : EqOn (log ∘ doublingGamma) (fun s => log (Gamma (s / 2)) + log (Gamma (s / 2 + 1 / 2)) + s * log 2 - log (2 * √π)) (Ioi 0) := by intro s hs have h1 : √π ≠ 0 := sqrt_ne_zero'.mpr pi_pos have h2 : Gamma (s / 2) ≠ 0 := (Gamma_pos_of_pos <| div_pos hs two_pos).ne' have h3 : Gamma (s / 2 + 1 / 2) ≠ 0 := (Gamma_pos_of_pos <| add_pos (div_pos hs two_pos) one_half_pos).ne' have h4 : (2 : ℝ) ^ (s - 1) ≠ 0 := (rpow_pos_of_pos two_pos _).ne' rw [Function.comp_apply, doublingGamma, log_div (mul_ne_zero (mul_ne_zero h2 h3) h4) h1, log_mul (mul_ne_zero h2 h3) h4, log_mul h2 h3, log_rpow two_pos, log_mul two_ne_zero h1] ring_nf theorem doublingGamma_log_convex_Ioi : ConvexOn ℝ (Ioi (0 : ℝ)) (log ∘ doublingGamma) := by refine (((ConvexOn.add ?_ ?_).add ?_).add_const _).congr log_doublingGamma_eq.symm · convert convexOn_log_Gamma.comp_affineMap (DistribMulAction.toLinearMap ℝ ℝ (1 / 2 : ℝ)).toAffineMap using 1 · simpa only [zero_div] using (preimage_const_mul_Ioi (0 : ℝ) one_half_pos).symm · ext1 x simp only [LinearMap.coe_toAffineMap, Function.comp_apply, DistribMulAction.toLinearMap_apply] rw [smul_eq_mul, mul_comm, mul_one_div] · refine ConvexOn.subset ?_ (Ioi_subset_Ioi <| neg_one_lt_zero.le) (convex_Ioi _) convert convexOn_log_Gamma.comp_affineMap ((DistribMulAction.toLinearMap ℝ ℝ (1 / 2 : ℝ)).toAffineMap + AffineMap.const ℝ ℝ (1 / 2 : ℝ)) using 1 · change Ioi (-1 : ℝ) = ((fun x : ℝ => x + 1 / 2) ∘ fun x : ℝ => (1 / 2 : ℝ) * x) ⁻¹' Ioi 0 rw [preimage_comp, preimage_add_const_Ioi, zero_sub, preimage_const_mul_Ioi (_ : ℝ) one_half_pos, neg_div, div_self (@one_half_pos ℝ _).ne'] · ext1 x change log (Gamma (x / 2 + 1 / 2)) = log (Gamma ((1 / 2 : ℝ) • x + 1 / 2)) rw [smul_eq_mul, mul_comm, mul_one_div] · simpa only [mul_comm _ (log _)] using (convexOn_id (convex_Ioi (0 : ℝ))).smul (log_pos one_lt_two).le theorem doublingGamma_eq_Gamma {s : ℝ} (hs : 0 < s) : doublingGamma s = Gamma s := by refine eq_Gamma_of_log_convex doublingGamma_log_convex_Ioi (fun {y} hy => doublingGamma_add_one y hy.ne') (fun {y} hy => ?_) doublingGamma_one hs apply_rules [mul_pos, Gamma_pos_of_pos, add_pos, inv_pos_of_pos, rpow_pos_of_pos, two_pos, one_pos, sqrt_pos_of_pos pi_pos] /-- Legendre's doubling formula for the Gamma function, for positive real arguments. Note that we shall later prove this for all `s` as `Real.Gamma_mul_Gamma_add_half` (superseding this result) but this result is needed as an intermediate step. -/ theorem Gamma_mul_Gamma_add_half_of_pos {s : ℝ} (hs : 0 < s) : Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * √π := by rw [← doublingGamma_eq_Gamma (mul_pos two_pos hs), doublingGamma, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), (by abel : 1 - 2 * s = -(2 * s - 1)), rpow_neg zero_le_two] field_simp [(sqrt_pos_of_pos pi_pos).ne', (rpow_pos_of_pos two_pos (2 * s - 1)).ne'] ring end Doubling end Real
seq.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. (******************************************************************************) (* The seq type is the ssreflect type for sequences; it is an alias for the *) (* standard Coq list type. The ssreflect library equips it with many *) (* operations, as well as eqType and predType (and, later, choiceType) *) (* structures. The operations are geared towards reflection: they generally *) (* expect and provide boolean predicates, e.g., the membership predicate *) (* expects an eqType. To avoid any confusion we do not Import the Coq List *) (* module. *) (* As there is no true subtyping in Coq, we don't use a type for non-empty *) (* sequences; rather, we pass explicitly the head and tail of the sequence. *) (* The empty sequence is especially bothersome for subscripting, since it *) (* forces us to pass a default value. This default value can often be hidden *) (* by a notation. *) (* Here is the list of seq operations: *) (* ** Constructors: *) (* seq T == the type of sequences of items of type T. *) (* bitseq == seq bool. *) (* [::], nil, Nil T == the empty sequence (of type T). *) (* x :: s, cons x s, Cons T x s == the sequence x followed by s (of type T). *) (* [:: x] == the singleton sequence. *) (* [:: x_0; ...; x_n] == the explicit sequence of the x_i. *) (* [:: x_0, ..., x_n & s] == the sequence of the x_i, followed by s. *) (* rcons s x == the sequence s, followed by x. *) (* All of the above, except rcons, can be used in patterns. We define a view *) (* lastP and an induction principle last_ind that can be used to decompose *) (* or traverse a sequence in a right to left order. The view lemma lastP has *) (* a dependent family type, so the ssreflect tactic case/lastP: p => [|p' x] *) (* will generate two subgoals in which p has been replaced by [::] and by *) (* rcons p' x, respectively. *) (* ** Factories: *) (* nseq n x == a sequence of n x's. *) (* ncons n x s == a sequence of n x's, followed by s. *) (* seqn n x_0 ... x_n-1 == the sequence of the x_i; can be partially applied. *) (* iota m n == the sequence m, m + 1, ..., m + n - 1. *) (* mkseq f n == the sequence f 0, f 1, ..., f (n - 1). *) (* ** Sequential access: *) (* head x0 s == the head (zero'th item) of s if s is non-empty, else x0. *) (* ohead s == None if s is empty, else Some x when the head of s is x. *) (* behead s == s minus its head, i.e., s' if s = x :: s', else [::]. *) (* last x s == the last element of x :: s (which is non-empty). *) (* belast x s == x :: s minus its last item. *) (* ** Dimensions: *) (* size s == the number of items (length) in s. *) (* shape ss == the sequence of sizes of the items of the sequence of *) (* sequences ss. *) (* ** Random access: *) (* nth x0 s i == the item i of s (numbered from 0), or x0 if s does *) (* not have at least i+1 items (i.e., size x <= i) *) (* s`_i == standard notation for nth x0 s i for a default x0, *) (* e.g., 0 for rings. *) (* onth s i == Some x if x is the i^th idem of s (numbered from 0), *) (* or None if size s <= i) *) (* set_nth x0 s i y == s where item i has been changed to y; if s does not *) (* have an item i, it is first padded with copies of x0 *) (* to size i+1. *) (* incr_nth s i == the nat sequence s with item i incremented (s is *) (* first padded with 0's to size i+1, if needed). *) (* ** Predicates: *) (* nilp s <=> s is [::]. *) (* := (size s == 0). *) (* x \in s == x appears in s (this requires an eqType for T). *) (* index x s == the first index at which x appears in s, or size s if *) (* x \notin s. *) (* has a s <=> a holds for some item in s, where a is an applicative *) (* bool predicate. *) (* all a s <=> a holds for all items in s. *) (* 'has_aP <-> the view reflect (exists2 x, x \in s & A x) (has a s), *) (* where aP x : reflect (A x) (a x). *) (* 'all_aP <=> the view for reflect {in s, forall x, A x} (all a s). *) (* all2 r s t <=> the (bool) relation r holds for all _respective_ items *) (* in s and t, which must also have the same size, i.e., *) (* for s := [:: x1; ...; x_m] and t := [:: y1; ...; y_n], *) (* the condition [&& r x_1 y_1, ..., r x_n y_n & m == n]. *) (* find p s == the index of the first item in s for which p holds, *) (* or size s if no such item is found. *) (* count p s == the number of items of s for which p holds. *) (* count_mem x s == the multiplicity of x in s, i.e., count (pred1 x) s. *) (* tally s == a tally of s, i.e., a sequence of (item, multiplicity) *) (* pairs for all items in sequence s (without duplicates). *) (* incr_tally bs x == increment the multiplicity of x in the tally bs, or add *) (* x with multiplicity 1 at then end if x is not in bs. *) (* bs \is a wf_tally <=> bs is well-formed tally, with no duplicate items or *) (* null multiplicities. *) (* tally_seq bs == the expansion of a tally bs into a sequence where each *) (* (x, n) pair expands into a sequence of n x's. *) (* constant s <=> all items in s are identical (trivial if s = [::]). *) (* uniq s <=> all the items in s are pairwise different. *) (* subseq s1 s2 <=> s1 is a subsequence of s2, i.e., s1 = mask m s2 for *) (* some m : bitseq (see below). *) (* infix s1 s2 <=> s1 is a contiguous subsequence of s2, i.e., *) (* s ++ s1 ++ s' = s2 for some sequences s, s'. *) (* prefix s1 s2 <=> s1 is a subchain of s2 appearing at the beginning *) (* of s2. *) (* suffix s1 s2 <=> s1 is a subchain of s2 appearing at the end of s2. *) (* infix_index s1 s2 <=> the first index at which s1 appears in s2, *) (* or (size s2).+1 if infix s1 s2 is false. *) (* perm_eq s1 s2 <=> s2 is a permutation of s1, i.e., s1 and s2 have the *) (* items (with the same repetitions), but possibly in a *) (* different order. *) (* perm_eql s1 s2 <-> s1 and s2 behave identically on the left of perm_eq. *) (* perm_eqr s1 s2 <-> s1 and s2 behave identically on the right of perm_eq. *) (* --> These left/right transitive versions of perm_eq make it easier to *) (* chain a sequence of equivalences. *) (* permutations s == a duplicate-free list of all permutations of s. *) (* ** Filtering: *) (* filter p s == the subsequence of s consisting of all the items *) (* for which the (boolean) predicate p holds. *) (* rem x s == the subsequence of s, where the first occurrence *) (* of x has been removed (compare filter (predC1 x) s *) (* where ALL occurrences of x are removed). *) (* undup s == the subsequence of s containing only the first *) (* occurrence of each item in s, i.e., s with all *) (* duplicates removed. *) (* mask m s == the subsequence of s selected by m : bitseq, with *) (* item i of s selected by bit i in m (extra items or *) (* bits are ignored. *) (* ** Surgery: *) (* s1 ++ s2, cat s1 s2 == the concatenation of s1 and s2. *) (* take n s == the sequence containing only the first n items of s *) (* (or all of s if size s <= n). *) (* drop n s == s minus its first n items ([::] if size s <= n) *) (* rot n s == s rotated left n times (or s if size s <= n). *) (* := drop n s ++ take n s *) (* rotr n s == s rotated right n times (or s if size s <= n). *) (* rev s == the (linear time) reversal of s. *) (* catrev s1 s2 == the reversal of s1 followed by s2 (this is the *) (* recursive form of rev). *) (* ** Dependent iterator: for s : seq S and t : S -> seq T *) (* [seq E | x <- s, y <- t] := flatten [seq [seq E | x <- t] | y <- s] *) (* == the sequence of all the f x y, with x and y drawn from *) (* s and t, respectively, in row-major order, *) (* and where t is possibly dependent in elements of s *) (* allpairs_dep f s t := self expanding definition for *) (* [seq f x y | x <- s, y <- t y] *) (* ** Iterators: for s == [:: x_1, ..., x_n], t == [:: y_1, ..., y_m], *) (* allpairs f s t := same as allpairs_dep but where t is non dependent, *) (* i.e. self expanding definition for *) (* [seq f x y | x <- s, y <- t] *) (* := [:: f x_1 y_1; ...; f x_1 y_m; f x_2 y_1; ...; f x_n y_m] *) (* allrel r xs ys := all [pred x | all (r x) ys] xs *) (* <=> r x y holds whenever x is in xs and y is in ys *) (* all2rel r xs := allrel r xs xs *) (* <=> the proposition r x y holds for all possible x, y in xs.*) (* pairwise r xs <=> the relation r holds for any i-th and j-th element of *) (* xs such that i < j. *) (* map f s == the sequence [:: f x_1, ..., f x_n]. *) (* pmap pf s == the sequence [:: y_i1, ..., y_ik] where i1 < ... < ik, *) (* pf x_i = Some y_i, and pf x_j = None iff j is not in *) (* {i1, ..., ik}. *) (* foldr f a s == the right fold of s by f (i.e., the natural iterator). *) (* := f x_1 (f x_2 ... (f x_n a)) *) (* sumn s == x_1 + (x_2 + ... + (x_n + 0)) (when s : seq nat). *) (* foldl f a s == the left fold of s by f. *) (* := f (f ... (f a x_1) ... x_n-1) x_n *) (* scanl f a s == the sequence of partial accumulators of foldl f a s. *) (* := [:: f a x_1; ...; foldl f a s] *) (* pairmap f a s == the sequence of f applied to consecutive items in a :: s. *) (* := [:: f a x_1; f x_1 x_2; ...; f x_n-1 x_n] *) (* zip s t == itemwise pairing of s and t (dropping any extra items). *) (* := [:: (x_1, y_1); ...; (x_mn, y_mn)] with mn = minn n m. *) (* unzip1 s == [:: (x_1).1; ...; (x_n).1] when s : seq (S * T). *) (* unzip2 s == [:: (x_1).2; ...; (x_n).2] when s : seq (S * T). *) (* flatten s == x_1 ++ ... ++ x_n ++ [::] when s : seq (seq T). *) (* reshape r s == s reshaped into a sequence of sequences whose sizes are *) (* given by r (truncating if s is too long or too short). *) (* := [:: [:: x_1; ...; x_r1]; *) (* [:: x_(r1 + 1); ...; x_(r0 + r1)]; *) (* ...; *) (* [:: x_(r1 + ... + r(k-1) + 1); ...; x_(r0 + ... rk)]] *) (* flatten_index sh r c == the index, in flatten ss, of the item of indexes *) (* (r, c) in any sequence of sequences ss of shape sh *) (* := sh_1 + sh_2 + ... + sh_r + c *) (* reshape_index sh i == the index, in reshape sh s, of the sequence *) (* containing the i-th item of s. *) (* reshape_offset sh i == the offset, in the (reshape_index sh i)-th *) (* sequence of reshape sh s of the i-th item of s *) (* ** Notation for manifest comprehensions: *) (* [seq x <- s | C] := filter (fun x => C) s. *) (* [seq E | x <- s] := map (fun x => E) s. *) (* [seq x <- s | C1 & C2] := [seq x <- s | C1 && C2]. *) (* [seq E | x <- s & C] := [seq E | x <- [seq x | C]]. *) (* --> The above allow optional type casts on the eigenvariables, as in *) (* [seq x : T <- s | C] or [seq E | x : T <- s, y : U <- t]. The cast may be *) (* needed as type inference considers E or C before s. *) (* We are quite systematic in providing lemmas to rewrite any composition *) (* of two operations. "rev", whose simplifications are not natural, is *) (* protected with simpl never. *) (* ** The following are equivalent: *) (* [<-> P0; P1; ..; Pn] <-> P0, P1, ..., Pn are all equivalent. *) (* := P0 -> P1 -> ... -> Pn -> P0 *) (* if T : [<-> P0; P1; ..; Pn] is such an equivalence, and i, j are in nat *) (* then T i j is a proof of the equivalence Pi <-> Pj between Pi and Pj; *) (* when i (resp. j) is out of bounds, Pi (resp. Pj) defaults to P0. *) (* The tactic tfae splits the goal into n+1 implications to prove. *) (* An example of use can be found in fingraph theorem orbitPcycle. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope seq_scope. Reserved Notation "[ '<->' P0 ; P1 ; .. ; Pn ]" (format "[ '<->' '[' P0 ; '/' P1 ; '/' .. ; '/' Pn ']' ]"). Delimit Scope seq_scope with SEQ. Open Scope seq_scope. (* Inductive seq (T : Type) : Type := Nil | Cons of T & seq T. *) Notation seq := list. Bind Scope seq_scope with list. Arguments cons {T%_type} x s%_SEQ : rename. Arguments nil {T%_type} : rename. Notation Cons T := (@cons T) (only parsing). Notation Nil T := (@nil T) (only parsing). (* As :: and ++ are (improperly) declared in Init.datatypes, we only rebind *) (* them here. *) Infix "::" := cons : seq_scope. Notation "[ :: ]" := nil (format "[ :: ]") : seq_scope. Notation "[ :: x1 ]" := (x1 :: [::]) (format "[ :: x1 ]") : seq_scope. Notation "[ :: x & s ]" := (x :: s) (only parsing) : seq_scope. Notation "[ :: x1 , x2 , .. , xn & s ]" := (x1 :: x2 :: .. (xn :: s) ..) (format "'[hv' [ :: '[' x1 , '/' x2 , '/' .. , '/' xn ']' '/ ' & s ] ']'" ) : seq_scope. Notation "[ :: x1 ; x2 ; .. ; xn ]" := (x1 :: x2 :: .. [:: xn] ..) (format "[ :: '[' x1 ; '/' x2 ; '/' .. ; '/' xn ']' ]" ) : seq_scope. Section Sequences. Variable n0 : nat. (* numerical parameter for take, drop et al *) Variable T : Type. (* must come before the implicit Type *) Variable x0 : T. (* default for head/nth *) Implicit Types x y z : T. Implicit Types m n : nat. Implicit Type s : seq T. Fixpoint size s := if s is _ :: s' then (size s').+1 else 0. Lemma size0nil s : size s = 0 -> s = [::]. Proof. by case: s. Qed. Definition nilp s := size s == 0. Lemma nilP s : reflect (s = [::]) (nilp s). Proof. by case: s => [|x s]; constructor. Qed. Definition ohead s := if s is x :: _ then Some x else None. Definition head s := if s is x :: _ then x else x0. Definition behead s := if s is _ :: s' then s' else [::]. Lemma size_behead s : size (behead s) = (size s).-1. Proof. by case: s. Qed. (* Factories *) Definition ncons n x := iter n (cons x). Definition nseq n x := ncons n x [::]. Lemma size_ncons n x s : size (ncons n x s) = n + size s. Proof. by elim: n => //= n ->. Qed. Lemma size_nseq n x : size (nseq n x) = n. Proof. by rewrite size_ncons addn0. Qed. (* n-ary, dependently typed constructor. *) Fixpoint seqn_type n := if n is n'.+1 then T -> seqn_type n' else seq T. Fixpoint seqn_rec f n : seqn_type n := if n is n'.+1 return seqn_type n then fun x => seqn_rec (fun s => f (x :: s)) n' else f [::]. Definition seqn := seqn_rec id. (* Sequence catenation "cat". *) Fixpoint cat s1 s2 := if s1 is x :: s1' then x :: s1' ++ s2 else s2 where "s1 ++ s2" := (cat s1 s2) : seq_scope. Lemma cat0s s : [::] ++ s = s. Proof. by []. Qed. Lemma cat1s x s : [:: x] ++ s = x :: s. Proof. by []. Qed. Lemma cat_cons x s1 s2 : (x :: s1) ++ s2 = x :: s1 ++ s2. Proof. by []. Qed. Lemma cat_nseq n x s : nseq n x ++ s = ncons n x s. Proof. by elim: n => //= n ->. Qed. Lemma nseqD n1 n2 x : nseq (n1 + n2) x = nseq n1 x ++ nseq n2 x. Proof. by rewrite cat_nseq /nseq /ncons iterD. Qed. Lemma cats0 s : s ++ [::] = s. Proof. by elim: s => //= x s ->. Qed. Lemma catA s1 s2 s3 : s1 ++ s2 ++ s3 = (s1 ++ s2) ++ s3. Proof. by elim: s1 => //= x s1 ->. Qed. Lemma size_cat s1 s2 : size (s1 ++ s2) = size s1 + size s2. Proof. by elim: s1 => //= x s1 ->. Qed. Lemma cat_nilp s1 s2 : nilp (s1 ++ s2) = nilp s1 && nilp s2. Proof. by case: s1. Qed. (* last, belast, rcons, and last induction. *) Fixpoint rcons s z := if s is x :: s' then x :: rcons s' z else [:: z]. Lemma rcons_cons x s z : rcons (x :: s) z = x :: rcons s z. Proof. by []. Qed. Lemma cats1 s z : s ++ [:: z] = rcons s z. Proof. by elim: s => //= x s ->. Qed. Fixpoint last x s := if s is x' :: s' then last x' s' else x. Fixpoint belast x s := if s is x' :: s' then x :: (belast x' s') else [::]. Lemma lastI x s : x :: s = rcons (belast x s) (last x s). Proof. by elim: s x => [|y s IHs] x //=; rewrite IHs. Qed. Lemma last_cons x y s : last x (y :: s) = last y s. Proof. by []. Qed. Lemma size_rcons s x : size (rcons s x) = (size s).+1. Proof. by rewrite -cats1 size_cat addnC. Qed. Lemma size_belast x s : size (belast x s) = size s. Proof. by elim: s x => [|y s IHs] x //=; rewrite IHs. Qed. Lemma last_cat x s1 s2 : last x (s1 ++ s2) = last (last x s1) s2. Proof. by elim: s1 x => [|y s1 IHs] x //=; rewrite IHs. Qed. Lemma last_rcons x s z : last x (rcons s z) = z. Proof. by rewrite -cats1 last_cat. Qed. Lemma belast_cat x s1 s2 : belast x (s1 ++ s2) = belast x s1 ++ belast (last x s1) s2. Proof. by elim: s1 x => [|y s1 IHs] x //=; rewrite IHs. Qed. Lemma belast_rcons x s z : belast x (rcons s z) = x :: s. Proof. by rewrite lastI -!cats1 belast_cat. Qed. Lemma cat_rcons x s1 s2 : rcons s1 x ++ s2 = s1 ++ x :: s2. Proof. by rewrite -cats1 -catA. Qed. Lemma rcons_cat x s1 s2 : rcons (s1 ++ s2) x = s1 ++ rcons s2 x. Proof. by rewrite -!cats1 catA. Qed. Variant last_spec : seq T -> Type := | LastNil : last_spec [::] | LastRcons s x : last_spec (rcons s x). Lemma lastP s : last_spec s. Proof. case: s => [|x s]; [left | rewrite lastI; right]. Qed. Lemma last_ind P : P [::] -> (forall s x, P s -> P (rcons s x)) -> forall s, P s. Proof. move=> Hnil Hlast s; rewrite -(cat0s s). elim: s [::] Hnil => [|x s2 IHs] s1 Hs1; first by rewrite cats0. by rewrite -cat_rcons; apply/IHs/Hlast. Qed. (* Sequence indexing. *) Fixpoint nth s n {struct n} := if s is x :: s' then if n is n'.+1 then @nth s' n' else x else x0. Fixpoint set_nth s n y {struct n} := if s is x :: s' then if n is n'.+1 then x :: @set_nth s' n' y else y :: s' else ncons n x0 [:: y]. Lemma nth0 s : nth s 0 = head s. Proof. by []. Qed. Lemma nth_default s n : size s <= n -> nth s n = x0. Proof. by elim: s n => [|x s IHs] []. Qed. Lemma if_nth s b n : b || (size s <= n) -> (if b then nth s n else x0) = nth s n. Proof. by case: leqP; case: ifP => //= *; rewrite nth_default. Qed. Lemma nth_nil n : nth [::] n = x0. Proof. by case: n. Qed. Lemma nth_seq1 n x : nth [:: x] n = if n == 0 then x else x0. Proof. by case: n => [|[]]. Qed. Lemma last_nth x s : last x s = nth (x :: s) (size s). Proof. by elim: s x => [|y s IHs] x /=. Qed. Lemma nth_last s : nth s (size s).-1 = last x0 s. Proof. by case: s => //= x s; rewrite last_nth. Qed. Lemma nth_behead s n : nth (behead s) n = nth s n.+1. Proof. by case: s n => [|x s] [|n]. Qed. Lemma nth_cat s1 s2 n : nth (s1 ++ s2) n = if n < size s1 then nth s1 n else nth s2 (n - size s1). Proof. by elim: s1 n => [|x s1 IHs] []. Qed. Lemma nth_rcons s x n : nth (rcons s x) n = if n < size s then nth s n else if n == size s then x else x0. Proof. by elim: s n => [|y s IHs] [] //=; apply: nth_nil. Qed. Lemma nth_rcons_default s i : nth (rcons s x0) i = nth s i. Proof. by rewrite nth_rcons; case: ltngtP => //[/ltnW ?|->]; rewrite nth_default. Qed. Lemma nth_ncons m x s n : nth (ncons m x s) n = if n < m then x else nth s (n - m). Proof. by elim: m n => [|m IHm] []. Qed. Lemma nth_nseq m x n : nth (nseq m x) n = (if n < m then x else x0). Proof. by elim: m n => [|m IHm] []. Qed. Lemma eq_from_nth s1 s2 : size s1 = size s2 -> (forall i, i < size s1 -> nth s1 i = nth s2 i) -> s1 = s2. Proof. elim: s1 s2 => [|x1 s1 IHs1] [|x2 s2] //= [eq_sz] eq_s12. by rewrite [x1](eq_s12 0) // (IHs1 s2) // => i; apply: (eq_s12 i.+1). Qed. Lemma size_set_nth s n y : size (set_nth s n y) = maxn n.+1 (size s). Proof. rewrite maxnC; elim: s n => [|x s IHs] [|n] //=. - by rewrite size_ncons addn1. - by rewrite IHs maxnSS. Qed. Lemma set_nth_nil n y : set_nth [::] n y = ncons n x0 [:: y]. Proof. by case: n. Qed. Lemma nth_set_nth s n y : nth (set_nth s n y) =1 [eta nth s with n |-> y]. Proof. elim: s n => [|x s IHs] [|n] [|m] //=; rewrite ?nth_nil ?IHs // nth_ncons eqSS. case: ltngtP => // [lt_nm | ->]; last by rewrite subnn. by rewrite nth_default // subn_gt0. Qed. Lemma set_set_nth s n1 y1 n2 y2 (s2 := set_nth s n2 y2) : set_nth (set_nth s n1 y1) n2 y2 = if n1 == n2 then s2 else set_nth s2 n1 y1. Proof. have [-> | ne_n12] := eqVneq. apply: eq_from_nth => [|i _]; first by rewrite !size_set_nth maxnA maxnn. by do 2!rewrite !nth_set_nth /=; case: eqP. apply: eq_from_nth => [|i _]; first by rewrite !size_set_nth maxnCA. by do 2!rewrite !nth_set_nth /=; case: eqP => // ->; case: eqVneq ne_n12. Qed. (* find, count, has, all. *) Section SeqFind. Variable a : pred T. Fixpoint find s := if s is x :: s' then if a x then 0 else (find s').+1 else 0. Fixpoint filter s := if s is x :: s' then if a x then x :: filter s' else filter s' else [::]. Fixpoint count s := if s is x :: s' then a x + count s' else 0. Fixpoint has s := if s is x :: s' then a x || has s' else false. Fixpoint all s := if s is x :: s' then a x && all s' else true. Lemma size_filter s : size (filter s) = count s. Proof. by elim: s => //= x s <-; case (a x). Qed. Lemma has_count s : has s = (0 < count s). Proof. by elim: s => //= x s ->; case (a x). Qed. Lemma size_filter_gt0 s : (size (filter s) > 0) = (has s). Proof. by rewrite size_filter -has_count. Qed. Lemma count_size s : count s <= size s. Proof. by elim: s => //= x s; case: (a x); last apply: leqW. Qed. Lemma all_count s : all s = (count s == size s). Proof. elim: s => //= x s; case: (a x) => _ //=. by rewrite add0n eqn_leq andbC ltnNge count_size. Qed. Lemma filter_all s : all (filter s). Proof. by elim: s => //= x s IHs; case: ifP => //= ->. Qed. Lemma all_filterP s : reflect (filter s = s) (all s). Proof. apply: (iffP idP) => [| <-]; last exact: filter_all. by elim: s => //= x s IHs /andP[-> Hs]; rewrite IHs. Qed. Lemma filter_id s : filter (filter s) = filter s. Proof. by apply/all_filterP; apply: filter_all. Qed. Lemma has_find s : has s = (find s < size s). Proof. by elim: s => //= x s IHs; case (a x); rewrite ?leqnn. Qed. Lemma find_size s : find s <= size s. Proof. by elim: s => //= x s IHs; case (a x). Qed. Lemma find_cat s1 s2 : find (s1 ++ s2) = if has s1 then find s1 else size s1 + find s2. Proof. by elim: s1 => //= x s1 IHs; case: (a x) => //; rewrite IHs (fun_if succn). Qed. Lemma has_nil : has [::] = false. Proof. by []. Qed. Lemma has_seq1 x : has [:: x] = a x. Proof. exact: orbF. Qed. Lemma has_nseq n x : has (nseq n x) = (0 < n) && a x. Proof. by elim: n => //= n ->; apply: andKb. Qed. Lemma has_seqb (b : bool) x : has (nseq b x) = b && a x. Proof. by rewrite has_nseq lt0b. Qed. Lemma all_nil : all [::] = true. Proof. by []. Qed. Lemma all_seq1 x : all [:: x] = a x. Proof. exact: andbT. Qed. Lemma all_nseq n x : all (nseq n x) = (n == 0) || a x. Proof. by elim: n => //= n ->; apply: orKb. Qed. Lemma all_nseqb (b : bool) x : all (nseq b x) = b ==> a x. Proof. by rewrite all_nseq eqb0 implybE. Qed. Lemma filter_nseq n x : filter (nseq n x) = nseq (a x * n) x. Proof. by elim: n => /= [|n ->]; case: (a x). Qed. Lemma count_nseq n x : count (nseq n x) = a x * n. Proof. by rewrite -size_filter filter_nseq size_nseq. Qed. Lemma find_nseq n x : find (nseq n x) = ~~ a x * n. Proof. by elim: n => /= [|n ->]; case: (a x). Qed. Lemma nth_find s : has s -> a (nth s (find s)). Proof. by elim: s => //= x s IHs; case a_x: (a x). Qed. Lemma before_find s i : i < find s -> a (nth s i) = false. Proof. by elim: s i => //= x s IHs; case: ifP => // a'x [|i] // /(IHs i). Qed. Lemma hasNfind s : ~~ has s -> find s = size s. Proof. by rewrite has_find; case: ltngtP (find_size s). Qed. Lemma filter_cat s1 s2 : filter (s1 ++ s2) = filter s1 ++ filter s2. Proof. by elim: s1 => //= x s1 ->; case (a x). Qed. Lemma filter_rcons s x : filter (rcons s x) = if a x then rcons (filter s) x else filter s. Proof. by rewrite -!cats1 filter_cat /=; case (a x); rewrite /= ?cats0. Qed. Lemma count_cat s1 s2 : count (s1 ++ s2) = count s1 + count s2. Proof. by rewrite -!size_filter filter_cat size_cat. Qed. Lemma has_cat s1 s2 : has (s1 ++ s2) = has s1 || has s2. Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs orbA. Qed. Lemma has_rcons s x : has (rcons s x) = a x || has s. Proof. by rewrite -cats1 has_cat has_seq1 orbC. Qed. Lemma all_cat s1 s2 : all (s1 ++ s2) = all s1 && all s2. Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs andbA. Qed. Lemma all_rcons s x : all (rcons s x) = a x && all s. Proof. by rewrite -cats1 all_cat all_seq1 andbC. Qed. End SeqFind. Lemma find_pred0 s : find pred0 s = size s. Proof. by []. Qed. Lemma find_predT s : find predT s = 0. Proof. by case: s. Qed. Lemma eq_find a1 a2 : a1 =1 a2 -> find a1 =1 find a2. Proof. by move=> Ea; elim=> //= x s IHs; rewrite Ea IHs. Qed. Lemma eq_filter a1 a2 : a1 =1 a2 -> filter a1 =1 filter a2. Proof. by move=> Ea; elim=> //= x s IHs; rewrite Ea IHs. Qed. Lemma eq_count a1 a2 : a1 =1 a2 -> count a1 =1 count a2. Proof. by move=> Ea s; rewrite -!size_filter (eq_filter Ea). Qed. Lemma eq_has a1 a2 : a1 =1 a2 -> has a1 =1 has a2. Proof. by move=> Ea s; rewrite !has_count (eq_count Ea). Qed. Lemma eq_all a1 a2 : a1 =1 a2 -> all a1 =1 all a2. Proof. by move=> Ea s; rewrite !all_count (eq_count Ea). Qed. Lemma all_filter (p q : pred T) xs : all p (filter q xs) = all [pred i | q i ==> p i] xs. Proof. by elim: xs => //= x xs <-; case: (q x). Qed. Section SubPred. Variable (a1 a2 : pred T). Hypothesis s12 : subpred a1 a2. Lemma sub_find s : find a2 s <= find a1 s. Proof. by elim: s => //= x s IHs; case: ifP => // /(contraFF (@s12 x))->. Qed. Lemma sub_has s : has a1 s -> has a2 s. Proof. by rewrite !has_find; apply: leq_ltn_trans (sub_find s). Qed. Lemma sub_count s : count a1 s <= count a2 s. Proof. by elim: s => //= x s; apply: leq_add; case a1x: (a1 x); rewrite // s12. Qed. Lemma sub_all s : all a1 s -> all a2 s. Proof. by rewrite !all_count !eqn_leq !count_size => /leq_trans-> //; apply: sub_count. Qed. End SubPred. Lemma filter_pred0 s : filter pred0 s = [::]. Proof. by elim: s. Qed. Lemma filter_predT s : filter predT s = s. Proof. by elim: s => //= x s ->. Qed. Lemma filter_predI a1 a2 s : filter (predI a1 a2) s = filter a1 (filter a2 s). Proof. by elim: s => //= x s ->; rewrite andbC; case: (a2 x). Qed. Lemma count_pred0 s : count pred0 s = 0. Proof. by rewrite -size_filter filter_pred0. Qed. Lemma count_predT s : count predT s = size s. Proof. by rewrite -size_filter filter_predT. Qed. Lemma count_predUI a1 a2 s : count (predU a1 a2) s + count (predI a1 a2) s = count a1 s + count a2 s. Proof. elim: s => //= x s IHs; rewrite /= addnACA [RHS]addnACA IHs. by case: (a1 x) => //; rewrite addn0. Qed. Lemma count_predC a s : count a s + count (predC a) s = size s. Proof. by elim: s => //= x s IHs; rewrite addnACA IHs; case: (a _). Qed. Lemma count_filter a1 a2 s : count a1 (filter a2 s) = count (predI a1 a2) s. Proof. by rewrite -!size_filter filter_predI. Qed. Lemma has_pred0 s : has pred0 s = false. Proof. by rewrite has_count count_pred0. Qed. Lemma has_predT s : has predT s = (0 < size s). Proof. by rewrite has_count count_predT. Qed. Lemma has_predC a s : has (predC a) s = ~~ all a s. Proof. by elim: s => //= x s ->; case (a x). Qed. Lemma has_predU a1 a2 s : has (predU a1 a2) s = has a1 s || has a2 s. Proof. by elim: s => //= x s ->; rewrite -!orbA; do !bool_congr. Qed. Lemma all_pred0 s : all pred0 s = (size s == 0). Proof. by rewrite all_count count_pred0 eq_sym. Qed. Lemma all_predT s : all predT s. Proof. by rewrite all_count count_predT. Qed. Lemma allT (a : pred T) s : (forall x, a x) -> all a s. Proof. by move/eq_all->; apply/all_predT. Qed. Lemma all_predC a s : all (predC a) s = ~~ has a s. Proof. by elim: s => //= x s ->; case (a x). Qed. Lemma all_predI a1 a2 s : all (predI a1 a2) s = all a1 s && all a2 s. Proof. apply: (can_inj negbK); rewrite negb_and -!has_predC -has_predU. by apply: eq_has => x; rewrite /= negb_and. Qed. (* Surgery: drop, take, rot, rotr. *) Fixpoint drop n s {struct s} := match s, n with | _ :: s', n'.+1 => drop n' s' | _, _ => s end. Lemma drop_behead : drop n0 =1 iter n0 behead. Proof. by elim: n0 => [|n IHn] [|x s] //; rewrite iterSr -IHn. Qed. Lemma drop0 s : drop 0 s = s. Proof. by case: s. Qed. Lemma drop1 : drop 1 =1 behead. Proof. by case=> [|x [|y s]]. Qed. Lemma drop_oversize n s : size s <= n -> drop n s = [::]. Proof. by elim: s n => [|x s IHs] []. Qed. Lemma drop_size s : drop (size s) s = [::]. Proof. by rewrite drop_oversize // leqnn. Qed. Lemma drop_cons x s : drop n0 (x :: s) = if n0 is n.+1 then drop n s else x :: s. Proof. by []. Qed. Lemma size_drop s : size (drop n0 s) = size s - n0. Proof. by elim: s n0 => [|x s IHs] []. Qed. Lemma drop_cat s1 s2 : drop n0 (s1 ++ s2) = if n0 < size s1 then drop n0 s1 ++ s2 else drop (n0 - size s1) s2. Proof. by elim: s1 n0 => [|x s1 IHs] []. Qed. Lemma drop_size_cat n s1 s2 : size s1 = n -> drop n (s1 ++ s2) = s2. Proof. by move <-; elim: s1 => //=; rewrite drop0. Qed. Lemma nconsK n x : cancel (ncons n x) (drop n). Proof. by elim: n => // -[]. Qed. Lemma drop_drop s n1 n2 : drop n1 (drop n2 s) = drop (n1 + n2) s. Proof. by elim: s n2 => // x s ihs [|n2]; rewrite ?drop0 ?addn0 ?addnS /=. Qed. Fixpoint take n s {struct s} := match s, n with | x :: s', n'.+1 => x :: take n' s' | _, _ => [::] end. Lemma take0 s : take 0 s = [::]. Proof. by case: s. Qed. Lemma take_oversize n s : size s <= n -> take n s = s. Proof. by elim: s n => [|x s IHs] [|n] //= /IHs->. Qed. Lemma take_size s : take (size s) s = s. Proof. exact: take_oversize. Qed. Lemma take_cons x s : take n0 (x :: s) = if n0 is n.+1 then x :: (take n s) else [::]. Proof. by []. Qed. Lemma drop_rcons s : n0 <= size s -> forall x, drop n0 (rcons s x) = rcons (drop n0 s) x. Proof. by elim: s n0 => [|y s IHs] []. Qed. Lemma cat_take_drop s : take n0 s ++ drop n0 s = s. Proof. by elim: s n0 => [|x s IHs] [|n] //=; rewrite IHs. Qed. Lemma size_takel s : n0 <= size s -> size (take n0 s) = n0. Proof. by move/subKn; rewrite -size_drop -[in size s](cat_take_drop s) size_cat addnK. Qed. Lemma size_take s : size (take n0 s) = if n0 < size s then n0 else size s. Proof. have [le_sn | lt_ns] := leqP (size s) n0; first by rewrite take_oversize. by rewrite size_takel // ltnW. Qed. Lemma size_take_min s : size (take n0 s) = minn n0 (size s). Proof. exact: size_take. Qed. Lemma take_cat s1 s2 : take n0 (s1 ++ s2) = if n0 < size s1 then take n0 s1 else s1 ++ take (n0 - size s1) s2. Proof. elim: s1 n0 => [|x s1 IHs] [|n] //=. by rewrite ltnS subSS -(fun_if (cons x)) -IHs. Qed. Lemma take_size_cat n s1 s2 : size s1 = n -> take n (s1 ++ s2) = s1. Proof. by move <-; elim: s1 => [|x s1 IHs]; rewrite ?take0 //= IHs. Qed. Lemma takel_cat s1 s2 : n0 <= size s1 -> take n0 (s1 ++ s2) = take n0 s1. Proof. by rewrite take_cat; case: ltngtP => // ->; rewrite subnn take0 take_size cats0. Qed. Lemma nth_drop s i : nth (drop n0 s) i = nth s (n0 + i). Proof. rewrite -[s in RHS]cat_take_drop nth_cat size_take ltnNge. case: ltnP => [?|le_s_n0]; rewrite ?(leq_trans le_s_n0) ?leq_addr ?addKn //=. by rewrite drop_oversize // !nth_default. Qed. Lemma find_ltn p s i : has p (take i s) -> find p s < i. Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs. Qed. Lemma has_take p s i : has p s -> has p (take i s) = (find p s < i). Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs ->. Qed. Lemma has_take_leq (p : pred T) (s : seq T) i : i <= size s -> has p (take i s) = (find p s < i). Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs ->. Qed. Lemma nth_take i : i < n0 -> forall s, nth (take n0 s) i = nth s i. Proof. move=> lt_i_n0 s; case lt_n0_s: (n0 < size s). by rewrite -[s in RHS]cat_take_drop nth_cat size_take lt_n0_s /= lt_i_n0. by rewrite -[s in LHS]cats0 take_cat lt_n0_s /= cats0. Qed. Lemma take_min i j s : take (minn i j) s = take i (take j s). Proof. by elim: s i j => //= a l IH [|i] [|j] //=; rewrite minnSS IH. Qed. Lemma take_takel i j s : i <= j -> take i (take j s) = take i s. Proof. by move=> ?; rewrite -take_min (minn_idPl _). Qed. Lemma take_taker i j s : j <= i -> take i (take j s) = take j s. Proof. by move=> ?; rewrite -take_min (minn_idPr _). Qed. Lemma take_drop i j s : take i (drop j s) = drop j (take (i + j) s). Proof. by rewrite addnC; elim: s i j => // x s IHs [|i] [|j] /=. Qed. Lemma takeD i j s : take (i + j) s = take i s ++ take j (drop i s). Proof. elim: i j s => [|i IHi] [|j] [|a s] //; first by rewrite take0 addn0 cats0. by rewrite addSn /= IHi. Qed. Lemma takeC i j s : take i (take j s) = take j (take i s). Proof. by rewrite -!take_min minnC. Qed. Lemma take_nseq i j x : i <= j -> take i (nseq j x) = nseq i x. Proof. by move=>/subnKC <-; rewrite nseqD take_size_cat // size_nseq. Qed. Lemma drop_nseq i j x : drop i (nseq j x) = nseq (j - i) x. Proof. case: (leqP i j) => [/subnKC {1}<-|/ltnW j_le_i]. by rewrite nseqD drop_size_cat // size_nseq. by rewrite drop_oversize ?size_nseq // (eqP j_le_i). Qed. (* drop_nth and take_nth below do NOT use the default n0, because the "n" *) (* can be inferred from the condition, whereas the nth default value x0 *) (* will have to be given explicitly (and this will provide "d" as well). *) Lemma drop_nth n s : n < size s -> drop n s = nth s n :: drop n.+1 s. Proof. by elim: s n => [|x s IHs] [|n] Hn //=; rewrite ?drop0 1?IHs. Qed. Lemma take_nth n s : n < size s -> take n.+1 s = rcons (take n s) (nth s n). Proof. by elim: s n => [|x s IHs] //= [|n] Hn /=; rewrite ?take0 -?IHs. Qed. (* Rotation *) Definition rot n s := drop n s ++ take n s. Lemma rot0 s : rot 0 s = s. Proof. by rewrite /rot drop0 take0 cats0. Qed. Lemma size_rot s : size (rot n0 s) = size s. Proof. by rewrite -[s in RHS]cat_take_drop /rot !size_cat addnC. Qed. Lemma rot_oversize n s : size s <= n -> rot n s = s. Proof. by move=> le_s_n; rewrite /rot take_oversize ?drop_oversize. Qed. Lemma rot_size s : rot (size s) s = s. Proof. exact: rot_oversize. Qed. Lemma has_rot s a : has a (rot n0 s) = has a s. Proof. by rewrite has_cat orbC -has_cat cat_take_drop. Qed. Lemma rot_size_cat s1 s2 : rot (size s1) (s1 ++ s2) = s2 ++ s1. Proof. by rewrite /rot take_size_cat ?drop_size_cat. Qed. Definition rotr n s := rot (size s - n) s. Lemma rotK : cancel (rot n0) (rotr n0). Proof. move=> s; rewrite /rotr size_rot -size_drop {2}/rot. by rewrite rot_size_cat cat_take_drop. Qed. Lemma rot_inj : injective (rot n0). Proof. exact (can_inj rotK). Qed. (* (efficient) reversal *) Fixpoint catrev s1 s2 := if s1 is x :: s1' then catrev s1' (x :: s2) else s2. Definition rev s := catrev s [::]. Lemma catrev_catl s t u : catrev (s ++ t) u = catrev t (catrev s u). Proof. by elim: s u => /=. Qed. Lemma catrev_catr s t u : catrev s (t ++ u) = catrev s t ++ u. Proof. by elim: s t => //= x s IHs t; rewrite -IHs. Qed. Lemma catrevE s t : catrev s t = rev s ++ t. Proof. by rewrite -catrev_catr. Qed. Lemma rev_cons x s : rev (x :: s) = rcons (rev s) x. Proof. by rewrite -cats1 -catrevE. Qed. Lemma size_rev s : size (rev s) = size s. Proof. by elim: s => // x s IHs; rewrite rev_cons size_rcons IHs. Qed. Lemma rev_nilp s : nilp (rev s) = nilp s. Proof. by rewrite /nilp size_rev. Qed. Lemma rev_cat s t : rev (s ++ t) = rev t ++ rev s. Proof. by rewrite -catrev_catr -catrev_catl. Qed. Lemma rev_rcons s x : rev (rcons s x) = x :: rev s. Proof. by rewrite -cats1 rev_cat. Qed. Lemma revK : involutive rev. Proof. by elim=> //= x s IHs; rewrite rev_cons rev_rcons IHs. Qed. Lemma nth_rev n s : n < size s -> nth (rev s) n = nth s (size s - n.+1). Proof. elim/last_ind: s => // s x IHs in n *. rewrite rev_rcons size_rcons ltnS subSS -cats1 nth_cat /=. case: n => [|n] lt_n_s; first by rewrite subn0 ltnn subnn. by rewrite subnSK //= leq_subr IHs. Qed. Lemma filter_rev a s : filter a (rev s) = rev (filter a s). Proof. by elim: s => //= x s IH; rewrite fun_if !rev_cons filter_rcons IH. Qed. Lemma count_rev a s : count a (rev s) = count a s. Proof. by rewrite -!size_filter filter_rev size_rev. Qed. Lemma has_rev a s : has a (rev s) = has a s. Proof. by rewrite !has_count count_rev. Qed. Lemma all_rev a s : all a (rev s) = all a s. Proof. by rewrite !all_count count_rev size_rev. Qed. Lemma rev_nseq n x : rev (nseq n x) = nseq n x. Proof. by elim: n => // n IHn; rewrite -[in LHS]addn1 nseqD rev_cat IHn. Qed. End Sequences. Prenex Implicits size ncons nseq head ohead behead last rcons belast. Arguments seqn {T} n. Prenex Implicits cat take drop rot rotr catrev. Prenex Implicits find count nth all has filter. Arguments rev {T} s : simpl never. Arguments nth : simpl nomatch. Arguments set_nth : simpl nomatch. Arguments take : simpl nomatch. Arguments drop : simpl nomatch. Arguments nilP {T s}. Arguments all_filterP {T a s}. Arguments rotK n0 {T} s : rename. Arguments rot_inj {n0 T} [s1 s2] eq_rot_s12 : rename. Arguments revK {T} s : rename. Notation count_mem x := (count (pred_of_simpl (pred1 x))). Infix "++" := cat : seq_scope. Notation "[ 'seq' x <- s | C ]" := (filter (fun x => C%B) s) (x at level 99, format "[ '[hv' 'seq' x <- s '/ ' | C ] ']'") : seq_scope. Notation "[ 'seq' x <- s | C1 & C2 ]" := [seq x <- s | C1 && C2] (format "[ '[hv' 'seq' x <- s '/ ' | C1 '/ ' & C2 ] ']'") : seq_scope. Notation "[ 'seq' ' x <- s | C ]" := (filter (fun x => C%B) s) (x strict pattern, format "[ '[hv' 'seq' ' x <- s '/ ' | C ] ']'") : seq_scope. Notation "[ 'seq' ' x <- s | C1 & C2 ]" := [seq x <- s | C1 && C2] (x strict pattern, format "[ '[hv' 'seq' ' x <- s '/ ' | C1 '/ ' & C2 ] ']'") : seq_scope. Notation "[ 'seq' x : T <- s | C ]" := (filter (fun x : T => C%B) s) (only parsing). Notation "[ 'seq' x : T <- s | C1 & C2 ]" := [seq x : T <- s | C1 && C2] (only parsing). (* Double induction/recursion. *) Lemma seq_ind2 {S T} (P : seq S -> seq T -> Type) : P [::] [::] -> (forall x y s t, size s = size t -> P s t -> P (x :: s) (y :: t)) -> forall s t, size s = size t -> P s t. Proof. by move=> Pnil Pcons; elim=> [|x s IHs] [|y t] //= [eq_sz]; apply/Pcons/IHs. Qed. Section AllIff. (* The Following Are Equivalent *) (* We introduce a specific conjunction, used to chain the consecutive *) (* items in a circular list of implications *) Inductive all_iff_and (P Q : Prop) : Prop := AllIffConj of P & Q. Definition all_iff (P0 : Prop) (Ps : seq Prop) : Prop := let fix loop (P : Prop) (Qs : seq Prop) : Prop := if Qs is Q :: Qs then all_iff_and (P -> Q) (loop Q Qs) else P -> P0 in loop P0 Ps. Lemma all_iffLR P0 Ps : all_iff P0 Ps -> forall m n, nth P0 (P0 :: Ps) m -> nth P0 (P0 :: Ps) n. Proof. move=> iffPs; have PsS n: nth P0 Ps n -> nth P0 Ps n.+1. elim: n P0 Ps iffPs => [|n IHn] P0 [|P [|Q Ps]] //= [iP0P] //; first by case. by rewrite nth_nil. by case=> iPQ iffPs; apply: IHn; split=> // /iP0P. have{PsS} lePs: {homo nth P0 Ps : m n / m <= n >-> (m -> n)}. by move=> m n /subnK<-; elim: {n}(n - m) => // n IHn /IHn; apply: PsS. move=> m n P_m; have{m P_m} hP0: P0. case: m P_m => //= m /(lePs m _ (leq_maxl m (size Ps))). by rewrite nth_default ?leq_maxr. case: n =>// n; apply: lePs 0 n (leq0n n) _. by case: Ps iffPs hP0 => // P Ps []. Qed. Lemma all_iffP P0 Ps : all_iff P0 Ps -> forall m n, nth P0 (P0 :: Ps) m <-> nth P0 (P0 :: Ps) n. Proof. by move=> /all_iffLR-iffPs m n; split => /iffPs. Qed. End AllIff. Arguments all_iffLR {P0 Ps}. Arguments all_iffP {P0 Ps}. Coercion all_iffP : all_iff >-> Funclass. (* This means "the following are all equivalent: P0, ... Pn" *) Notation "[ '<->' P0 ; P1 ; .. ; Pn ]" := (all_iff P0 (@cons Prop P1 (.. (@cons Prop Pn nil) ..))) : form_scope. Ltac tfae := do !apply: AllIffConj. Section FindSpec. Variable (T : Type) (a : {pred T}) (s : seq T). Variant find_spec : bool -> nat -> Type := | NotFound of ~~ has a s : find_spec false (size s) | Found (i : nat) of i < size s & (forall x0, a (nth x0 s i)) & (forall x0 j, j < i -> a (nth x0 s j) = false) : find_spec true i. Lemma findP : find_spec (has a s) (find a s). Proof. have [a_s|aNs] := boolP (has a s); last by rewrite hasNfind//; constructor. by constructor=> [|x0|x0]; rewrite -?has_find ?nth_find//; apply: before_find. Qed. End FindSpec. Arguments findP {T}. Section RotRcons. Variable T : Type. Implicit Types (x : T) (s : seq T). Lemma rot1_cons x s : rot 1 (x :: s) = rcons s x. Proof. by rewrite /rot /= take0 drop0 -cats1. Qed. Lemma rcons_inj s1 s2 x1 x2 : rcons s1 x1 = rcons s2 x2 :> seq T -> (s1, x1) = (s2, x2). Proof. by rewrite -!rot1_cons => /rot_inj[-> ->]. Qed. Lemma rcons_injl x : injective (rcons^~ x). Proof. by move=> s1 s2 /rcons_inj[]. Qed. Lemma rcons_injr s : injective (rcons s). Proof. by move=> x1 x2 /rcons_inj[]. Qed. End RotRcons. Arguments rcons_inj {T s1 x1 s2 x2} eq_rcons : rename. Arguments rcons_injl {T} x [s1 s2] eq_rcons : rename. Arguments rcons_injr {T} s [x1 x2] eq_rcons : rename. (* Equality and eqType for seq. *) Section EqSeq. Variables (n0 : nat) (T : eqType) (x0 : T). Local Notation nth := (nth x0). Implicit Types (x y z : T) (s : seq T). Fixpoint eqseq s1 s2 {struct s2} := match s1, s2 with | [::], [::] => true | x1 :: s1', x2 :: s2' => (x1 == x2) && eqseq s1' s2' | _, _ => false end. Lemma eqseqP : Equality.axiom eqseq. Proof. move; elim=> [|x1 s1 IHs] [|x2 s2]; do [by constructor | simpl]. have [<-|neqx] := x1 =P x2; last by right; case. by apply: (iffP (IHs s2)) => [<-|[]]. Qed. HB.instance Definition _ := hasDecEq.Build (seq T) eqseqP. Lemma eqseqE : eqseq = eq_op. Proof. by []. Qed. Lemma eqseq_cons x1 x2 s1 s2 : (x1 :: s1 == x2 :: s2) = (x1 == x2) && (s1 == s2). Proof. by []. Qed. Lemma eqseq_cat s1 s2 s3 s4 : size s1 = size s2 -> (s1 ++ s3 == s2 ++ s4) = (s1 == s2) && (s3 == s4). Proof. elim: s1 s2 => [|x1 s1 IHs] [|x2 s2] //= [sz12]. by rewrite !eqseq_cons -andbA IHs. Qed. Lemma eqseq_rcons s1 s2 x1 x2 : (rcons s1 x1 == rcons s2 x2) = (s1 == s2) && (x1 == x2). Proof. by rewrite -(can_eq revK) !rev_rcons eqseq_cons andbC (can_eq revK). Qed. Lemma size_eq0 s : (size s == 0) = (s == [::]). Proof. exact: (sameP nilP eqP). Qed. Lemma nilpE s : nilp s = (s == [::]). Proof. by case: s. Qed. Lemma has_filter a s : has a s = (filter a s != [::]). Proof. by rewrite -size_eq0 size_filter has_count lt0n. Qed. (* mem_seq and index. *) (* mem_seq defines a predType for seq. *) Fixpoint mem_seq (s : seq T) := if s is y :: s' then xpredU1 y (mem_seq s') else xpred0. Definition seq_eqclass := seq T. Identity Coercion seq_of_eqclass : seq_eqclass >-> seq. Coercion pred_of_seq (s : seq_eqclass) : {pred T} := mem_seq s. Canonical seq_predType := PredType (pred_of_seq : seq T -> pred T). (* The line below makes mem_seq a canonical instance of topred. *) Canonical mem_seq_predType := PredType mem_seq. Lemma in_cons y s x : (x \in y :: s) = (x == y) || (x \in s). Proof. by []. Qed. Lemma in_nil x : (x \in [::]) = false. Proof. by []. Qed. Lemma mem_seq1 x y : (x \in [:: y]) = (x == y). Proof. by rewrite in_cons orbF. Qed. (* to be repeated after the Section discharge. *) Let inE := (mem_seq1, in_cons, inE). Lemma forall_cons {P : T -> Prop} {a s} : {in a::s, forall x, P x} <-> P a /\ {in s, forall x, P x}. Proof. split=> [A|[A B]]; last by move => x /predU1P [-> //|]; apply: B. by split=> [|b Hb]; apply: A; rewrite !inE ?eqxx ?Hb ?orbT. Qed. Lemma exists_cons {P : T -> Prop} {a s} : (exists2 x, x \in a::s & P x) <-> P a \/ exists2 x, x \in s & P x. Proof. split=> [[x /predU1P[->|x_s] Px]|]; [by left| by right; exists x|]. by move=> [?|[x x_s ?]]; [exists a|exists x]; rewrite ?inE ?eqxx ?x_s ?orbT. Qed. Lemma mem_seq2 x y z : (x \in [:: y; z]) = xpred2 y z x. Proof. by rewrite !inE. Qed. Lemma mem_seq3 x y z t : (x \in [:: y; z; t]) = xpred3 y z t x. Proof. by rewrite !inE. Qed. Lemma mem_seq4 x y z t u : (x \in [:: y; z; t; u]) = xpred4 y z t u x. Proof. by rewrite !inE. Qed. Lemma mem_cat x s1 s2 : (x \in s1 ++ s2) = (x \in s1) || (x \in s2). Proof. by elim: s1 => //= y s1 IHs; rewrite !inE /= -orbA -IHs. Qed. Lemma mem_rcons s y : rcons s y =i y :: s. Proof. by move=> x; rewrite -cats1 /= mem_cat mem_seq1 orbC in_cons. Qed. Lemma mem_head x s : x \in x :: s. Proof. exact: predU1l. Qed. Lemma mem_last x s : last x s \in x :: s. Proof. by rewrite lastI mem_rcons mem_head. Qed. Lemma mem_behead s : {subset behead s <= s}. Proof. by case: s => // y s x; apply: predU1r. Qed. Lemma mem_belast s y : {subset belast y s <= y :: s}. Proof. by move=> x ys'x; rewrite lastI mem_rcons mem_behead. Qed. Lemma mem_nth s n : n < size s -> nth s n \in s. Proof. by elim: s n => // x s IHs [_|n sz_s]; rewrite ?mem_head // mem_behead ?IHs. Qed. Lemma mem_take s x : x \in take n0 s -> x \in s. Proof. by move=> s0x; rewrite -(cat_take_drop n0 s) mem_cat /= s0x. Qed. Lemma mem_drop s x : x \in drop n0 s -> x \in s. Proof. by move=> s0'x; rewrite -(cat_take_drop n0 s) mem_cat /= s0'x orbT. Qed. Lemma last_eq s z x y : x != y -> z != y -> (last x s == y) = (last z s == y). Proof. by move=> /negPf xz /negPf yz; case: s => [|t s]//; rewrite xz yz. Qed. Section Filters. Implicit Type a : pred T. Lemma hasP {a s} : reflect (exists2 x, x \in s & a x) (has a s). Proof. elim: s => [|y s IHs] /=; first by right; case. exact: equivP (orPP idP IHs) (iff_sym exists_cons). Qed. Lemma allP {a s} : reflect {in s, forall x, a x} (all a s). Proof. elim: s => [|/= y s IHs]; first by left. exact: equivP (andPP idP IHs) (iff_sym forall_cons). Qed. Lemma hasPn a s : reflect {in s, forall x, ~~ a x} (~~ has a s). Proof. by rewrite -all_predC; apply: allP. Qed. Lemma allPn a s : reflect (exists2 x, x \in s & ~~ a x) (~~ all a s). Proof. by rewrite -has_predC; apply: hasP. Qed. Lemma allss s : all [in s] s. Proof. exact/allP. Qed. Lemma mem_filter a x s : (x \in filter a s) = a x && (x \in s). Proof. rewrite andbC; elim: s => //= y s IHs. rewrite (fun_if (fun s' : seq T => x \in s')) !in_cons {}IHs. by case: eqP => [->|_]; case (a y); rewrite /= ?andbF. Qed. Variables (a : pred T) (s : seq T) (A : T -> Prop). Hypothesis aP : forall x, reflect (A x) (a x). Lemma hasPP : reflect (exists2 x, x \in s & A x) (has a s). Proof. by apply: (iffP hasP) => -[x ? /aP]; exists x. Qed. Lemma allPP : reflect {in s, forall x, A x} (all a s). Proof. by apply: (iffP allP) => a_s x /a_s/aP. Qed. End Filters. Section EqIn. Variables a1 a2 : pred T. Lemma eq_in_filter s : {in s, a1 =1 a2} -> filter a1 s = filter a2 s. Proof. by elim: s => //= x s IHs /forall_cons [-> /IHs ->]. Qed. Lemma eq_in_find s : {in s, a1 =1 a2} -> find a1 s = find a2 s. Proof. by elim: s => //= x s IHs /forall_cons [-> /IHs ->]. Qed. Lemma eq_in_count s : {in s, a1 =1 a2} -> count a1 s = count a2 s. Proof. by move/eq_in_filter=> eq_a12; rewrite -!size_filter eq_a12. Qed. Lemma eq_in_all s : {in s, a1 =1 a2} -> all a1 s = all a2 s. Proof. by move=> eq_a12; rewrite !all_count eq_in_count. Qed. Lemma eq_in_has s : {in s, a1 =1 a2} -> has a1 s = has a2 s. Proof. by move/eq_in_filter=> eq_a12; rewrite !has_filter eq_a12. Qed. End EqIn. Lemma eq_has_r s1 s2 : s1 =i s2 -> has^~ s1 =1 has^~ s2. Proof. by move=> Es a; apply/hasP/hasP=> -[x sx ax]; exists x; rewrite ?Es in sx *. Qed. Lemma eq_all_r s1 s2 : s1 =i s2 -> all^~ s1 =1 all^~ s2. Proof. by move=> Es a; apply/negb_inj; rewrite -!has_predC (eq_has_r Es). Qed. Lemma has_sym s1 s2 : has [in s1] s2 = has [in s2] s1. Proof. by apply/hasP/hasP=> -[x]; exists x. Qed. Lemma has_pred1 x s : has (pred1 x) s = (x \in s). Proof. by rewrite -(eq_has (mem_seq1^~ x)) (has_sym [:: x]) /= orbF. Qed. Lemma mem_rev s : rev s =i s. Proof. by move=> a; rewrite -!has_pred1 has_rev. Qed. (* Constant sequences, i.e., the image of nseq. *) Definition constant s := if s is x :: s' then all (pred1 x) s' else true. Lemma all_pred1P x s : reflect (s = nseq (size s) x) (all (pred1 x) s). Proof. elim: s => [|y s IHs] /=; first by left. case: eqP => [->{y} | ne_xy]; last by right=> [] [? _]; case ne_xy. by apply: (iffP IHs) => [<- //| []]. Qed. Lemma all_pred1_constant x s : all (pred1 x) s -> constant s. Proof. by case: s => //= y s /andP[/eqP->]. Qed. Lemma all_pred1_nseq x n : all (pred1 x) (nseq n x). Proof. by rewrite all_nseq /= eqxx orbT. Qed. Lemma mem_nseq n x y : (y \in nseq n x) = (0 < n) && (y == x). Proof. by rewrite -has_pred1 has_nseq eq_sym. Qed. Lemma nseqP n x y : reflect (y = x /\ n > 0) (y \in nseq n x). Proof. by rewrite mem_nseq andbC; apply: (iffP andP) => -[/eqP]. Qed. Lemma constant_nseq n x : constant (nseq n x). Proof. exact: all_pred1_constant (all_pred1_nseq x n). Qed. (* Uses x0 *) Lemma constantP s : reflect (exists x, s = nseq (size s) x) (constant s). Proof. apply: (iffP idP) => [| [x ->]]; last exact: constant_nseq. case: s => [|x s] /=; first by exists x0. by move/all_pred1P=> def_s; exists x; rewrite -def_s. Qed. (* Duplicate-freenes. *) Fixpoint uniq s := if s is x :: s' then (x \notin s') && uniq s' else true. Lemma cons_uniq x s : uniq (x :: s) = (x \notin s) && uniq s. Proof. by []. Qed. Lemma cat_uniq s1 s2 : uniq (s1 ++ s2) = [&& uniq s1, ~~ has [in s1] s2 & uniq s2]. Proof. elim: s1 => [|x s1 IHs]; first by rewrite /= has_pred0. by rewrite has_sym /= mem_cat !negb_or has_sym IHs -!andbA; do !bool_congr. Qed. Lemma uniq_catC s1 s2 : uniq (s1 ++ s2) = uniq (s2 ++ s1). Proof. by rewrite !cat_uniq has_sym andbCA andbA andbC. Qed. Lemma uniq_catCA s1 s2 s3 : uniq (s1 ++ s2 ++ s3) = uniq (s2 ++ s1 ++ s3). Proof. by rewrite !catA -!(uniq_catC s3) !(cat_uniq s3) uniq_catC !has_cat orbC. Qed. Lemma rcons_uniq s x : uniq (rcons s x) = (x \notin s) && uniq s. Proof. by rewrite -cats1 uniq_catC. Qed. Lemma filter_uniq s a : uniq s -> uniq (filter a s). Proof. elim: s => //= x s IHs /andP[s'x]; case: ifP => //= a_x /IHs->. by rewrite mem_filter a_x s'x. Qed. Lemma rot_uniq s : uniq (rot n0 s) = uniq s. Proof. by rewrite /rot uniq_catC cat_take_drop. Qed. Lemma rev_uniq s : uniq (rev s) = uniq s. Proof. elim: s => // x s IHs. by rewrite rev_cons -cats1 cat_uniq /= andbT andbC mem_rev orbF IHs. Qed. Lemma count_memPn x s : reflect (count_mem x s = 0) (x \notin s). Proof. by rewrite -has_pred1 has_count -eqn0Ngt; apply: eqP. Qed. Lemma count_uniq_mem s x : uniq s -> count_mem x s = (x \in s). Proof. elim: s => //= y s IHs /andP[/negbTE s'y /IHs-> {IHs}]. by rewrite in_cons; case: (eqVneq y x) => // <-; rewrite s'y. Qed. Lemma leq_uniq_countP x s1 s2 : uniq s1 -> reflect (x \in s1 -> x \in s2) (count_mem x s1 <= count_mem x s2). Proof. move/count_uniq_mem->; case: (boolP (_ \in _)) => //= _; last by constructor. by rewrite -has_pred1 has_count; apply: (iffP idP) => //; apply. Qed. Lemma leq_uniq_count s1 s2 : uniq s1 -> {subset s1 <= s2} -> (forall x, count_mem x s1 <= count_mem x s2). Proof. by move=> s1_uniq s1_s2 x; apply/leq_uniq_countP/s1_s2. Qed. Lemma filter_pred1_uniq s x : uniq s -> x \in s -> filter (pred1 x) s = [:: x]. Proof. move=> uniq_s s_x; rewrite (all_pred1P _ _ (filter_all _ _)). by rewrite size_filter count_uniq_mem ?s_x. Qed. (* Removing duplicates *) Fixpoint undup s := if s is x :: s' then if x \in s' then undup s' else x :: undup s' else [::]. Lemma size_undup s : size (undup s) <= size s. Proof. by elim: s => //= x s IHs; case: (x \in s) => //=; apply: ltnW. Qed. Lemma mem_undup s : undup s =i s. Proof. move=> x; elim: s => //= y s IHs. by case s_y: (y \in s); rewrite !inE IHs //; case: eqP => [->|]. Qed. Lemma undup_uniq s : uniq (undup s). Proof. by elim: s => //= x s IHs; case s_x: (x \in s); rewrite //= mem_undup s_x. Qed. Lemma undup_id s : uniq s -> undup s = s. Proof. by elim: s => //= x s IHs /andP[/negbTE-> /IHs->]. Qed. Lemma ltn_size_undup s : (size (undup s) < size s) = ~~ uniq s. Proof. by elim: s => //= x s IHs; case s_x: (x \in s); rewrite //= ltnS size_undup. Qed. Lemma filter_undup p s : filter p (undup s) = undup (filter p s). Proof. elim: s => //= x s IHs; rewrite (fun_if undup) [_ = _]fun_if /= mem_filter /=. by rewrite (fun_if (filter p)) /= IHs; case: ifP => -> //=; apply: if_same. Qed. Lemma undup_nil s : undup s = [::] -> s = [::]. Proof. by case: s => //= x s; rewrite -mem_undup; case: ifP; case: undup. Qed. Lemma undup_cat s t : undup (s ++ t) = [seq x <- undup s | x \notin t] ++ undup t. Proof. by elim: s => //= x s ->; rewrite mem_cat; do 2 case: in_mem => //=. Qed. Lemma undup_rcons s x : undup (rcons s x) = rcons [seq y <- undup s | y != x] x. Proof. by rewrite -!cats1 undup_cat; congr cat; apply: eq_filter => y; rewrite inE. Qed. Lemma count_undup s p : count p (undup s) <= count p s. Proof. by rewrite -!size_filter filter_undup size_undup. Qed. Lemma has_undup p s : has p (undup s) = has p s. Proof. by apply: eq_has_r => x; rewrite mem_undup. Qed. Lemma all_undup p s : all p (undup s) = all p s. Proof. by apply: eq_all_r => x; rewrite mem_undup. Qed. (* Lookup *) Definition index x := find (pred1 x). Lemma index_size x s : index x s <= size s. Proof. by rewrite /index find_size. Qed. Lemma index_mem x s : (index x s < size s) = (x \in s). Proof. by rewrite -has_pred1 has_find. Qed. Lemma memNindex x s : x \notin s -> index x s = size s. Proof. by rewrite -has_pred1 => /hasNfind. Qed. Lemma nth_index x s : x \in s -> nth s (index x s) = x. Proof. by rewrite -has_pred1 => /(nth_find x0)/eqP. Qed. Lemma index_inj s : {in s &, injective (index ^~ s)}. Proof. by move=> x y x_s y_s eidx; rewrite -(nth_index x_s) eidx nth_index. Qed. Lemma index_cat x s1 s2 : index x (s1 ++ s2) = if x \in s1 then index x s1 else size s1 + index x s2. Proof. by rewrite /index find_cat has_pred1. Qed. Lemma index_ltn x s i : x \in take i s -> index x s < i. Proof. by rewrite -has_pred1; apply: find_ltn. Qed. Lemma in_take x s i : x \in s -> (x \in take i s) = (index x s < i). Proof. by rewrite -?has_pred1; apply: has_take. Qed. Lemma in_take_leq x s i : i <= size s -> (x \in take i s) = (index x s < i). Proof. by rewrite -?has_pred1; apply: has_take_leq. Qed. Lemma index_nth i s : i < size s -> index (nth s i) s <= i. Proof. move=> lti; rewrite -ltnS index_ltn// -(@nth_take i.+1)// mem_nth // size_take. by case: ifP. Qed. Lemma nthK s: uniq s -> {in gtn (size s), cancel (nth s) (index^~ s)}. Proof. elim: s => //= x s IHs /andP[s'x Us] i; rewrite inE ltnS eq_sym -if_neg. by case: i => /= [_|i lt_i_s]; rewrite ?eqxx ?IHs ?(memPn s'x) ?mem_nth. Qed. Lemma index_uniq i s : i < size s -> uniq s -> index (nth s i) s = i. Proof. by move/nthK. Qed. Lemma index_head x s : index x (x :: s) = 0. Proof. by rewrite /= eqxx. Qed. Lemma index_last x s : uniq (x :: s) -> index (last x s) (x :: s) = size s. Proof. rewrite lastI rcons_uniq -cats1 index_cat size_belast. by case: ifP => //=; rewrite eqxx addn0. Qed. Lemma nth_uniq s i j : i < size s -> j < size s -> uniq s -> (nth s i == nth s j) = (i == j). Proof. by move=> lti ltj /nthK/can_in_eq->. Qed. Lemma uniqPn s : reflect (exists i j, [/\ i < j, j < size s & nth s i = nth s j]) (~~ uniq s). Proof. apply: (iffP idP) => [|[i [j [ltij ltjs]]]]; last first. by apply: contra_eqN => Us; rewrite nth_uniq ?ltn_eqF // (ltn_trans ltij). elim: s => // x s IHs /nandP[/negbNE | /IHs[i [j]]]; last by exists i.+1, j.+1. by exists 0, (index x s).+1; rewrite !ltnS index_mem /= nth_index. Qed. Lemma uniqP s : reflect {in gtn (size s) &, injective (nth s)} (uniq s). Proof. apply: (iffP idP) => [/nthK/can_in_inj// | nth_inj]. apply/uniqPn => -[i [j [ltij ltjs /nth_inj/eqP/idPn]]]. by rewrite !inE (ltn_trans ltij ltjs) ltn_eqF //=; case. Qed. Lemma mem_rot s : rot n0 s =i s. Proof. by move=> x; rewrite -[s in RHS](cat_take_drop n0) !mem_cat /= orbC. Qed. Lemma eqseq_rot s1 s2 : (rot n0 s1 == rot n0 s2) = (s1 == s2). Proof. exact/inj_eq/rot_inj. Qed. Lemma drop_index s (n := index x0 s) : x0 \in s -> drop n s = x0 :: drop n.+1 s. Proof. by move=> xs; rewrite (drop_nth x0) ?index_mem ?nth_index. Qed. (* lemmas about the pivot pattern [_ ++ _ :: _] *) Lemma index_pivot x s1 s2 (s := s1 ++ x :: s2) : x \notin s1 -> index x s = size s1. Proof. by rewrite index_cat/= eqxx addn0; case: ifPn. Qed. Lemma take_pivot x s2 s1 (s := s1 ++ x :: s2) : x \notin s1 -> take (index x s) s = s1. Proof. by move=> /index_pivot->; rewrite take_size_cat. Qed. Lemma rev_pivot x s1 s2 : rev (s1 ++ x :: s2) = rev s2 ++ x :: rev s1. Proof. by rewrite rev_cat rev_cons cat_rcons. Qed. Lemma eqseq_pivot2l x s1 s2 s3 s4 : x \notin s1 -> x \notin s3 -> (s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4). Proof. move=> xNs1 xNs3; apply/idP/idP => [E|/andP[/eqP-> /eqP->]//]. suff S : size s1 = size s3 by rewrite eqseq_cat// eqseq_cons eqxx in E. by rewrite -(index_pivot s2 xNs1) (eqP E) index_pivot. Qed. Lemma eqseq_pivot2r x s1 s2 s3 s4 : x \notin s2 -> x \notin s4 -> (s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4). Proof. move=> xNs2 xNs4; rewrite -(can_eq revK) !rev_pivot. by rewrite eqseq_pivot2l ?mem_rev // !(can_eq revK) andbC. Qed. Lemma eqseq_pivotl x s1 s2 s3 s4 : x \notin s1 -> x \notin s2 -> (s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4). Proof. move=> xNs1 xNs2; apply/idP/idP => [E|/andP[/eqP-> /eqP->]//]. rewrite -(@eqseq_pivot2l x)//; have /eqP/(congr1 (count_mem x)) := E. rewrite !count_cat/= eqxx !addnS (count_memPn _ _ xNs1) (count_memPn _ _ xNs2). by move=> -[/esym/eqP]; rewrite addn_eq0 => /andP[/eqP/count_memPn]. Qed. Lemma eqseq_pivotr x s1 s2 s3 s4 : x \notin s3 -> x \notin s4 -> (s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4). Proof. by move=> *; rewrite eq_sym eqseq_pivotl//; case: eqVneq => /=. Qed. Lemma uniq_eqseq_pivotl x s1 s2 s3 s4 : uniq (s1 ++ x :: s2) -> (s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4). Proof. by rewrite uniq_catC/= mem_cat => /andP[/norP[? ?] _]; rewrite eqseq_pivotl. Qed. Lemma uniq_eqseq_pivotr x s1 s2 s3 s4 : uniq (s3 ++ x :: s4) -> (s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4). Proof. by move=> ?; rewrite eq_sym uniq_eqseq_pivotl//; case: eqVneq => /=. Qed. End EqSeq. Arguments eqseq : simpl nomatch. Notation "'has_ view" := (hasPP _ (fun _ => view)) (at level 4, right associativity, format "''has_' view"). Notation "'all_ view" := (allPP _ (fun _ => view)) (at level 4, right associativity, format "''all_' view"). Section RotIndex. Variables (T : eqType). Implicit Types x y z : T. Lemma rot_index s x (i := index x s) : x \in s -> rot i s = x :: (drop i.+1 s ++ take i s). Proof. by move=> x_s; rewrite /rot drop_index. Qed. Variant rot_to_spec s x := RotToSpec i s' of rot i s = x :: s'. Lemma rot_to s x : x \in s -> rot_to_spec s x. Proof. by move=> /rot_index /RotToSpec. Qed. End RotIndex. Definition inE := (mem_seq1, in_cons, inE). Prenex Implicits mem_seq1 constant uniq undup index. Arguments eqseq {T} !_ !_. Arguments pred_of_seq {T} s x /. Arguments eqseqP {T x y}. Arguments hasP {T a s}. Arguments hasPn {T a s}. Arguments allP {T a s}. Arguments allPn {T a s}. Arguments nseqP {T n x y}. Arguments count_memPn {T x s}. Arguments uniqPn {T} x0 {s}. Arguments uniqP {T} x0 {s}. Arguments forall_cons {T P a s}. Arguments exists_cons {T P a s}. (* Since both `all [in s] s`, `all (mem s) s`, and `all (pred_of_seq s) s` *) (* may appear in goals, the following hint has to be declared using the *) (* `Hint Extern` command. Additionally, `mem` and `pred_of_seq` in the above *) (* terms do not reduce to each other; thus, stating `allss` in the form of *) (* one of them makes `apply: allss` fail for the other case. Since both `mem` *) (* and `pred_of_seq` reduce to `mem_seq`, the following explicit type *) (* annotation for `allss` makes it work for both cases. *) #[export] Hint Extern 0 (is_true (all _ _)) => apply: (allss : forall T s, all (mem_seq s) s) : core. Section NthTheory. Lemma nthP (T : eqType) (s : seq T) x x0 : reflect (exists2 i, i < size s & nth x0 s i = x) (x \in s). Proof. apply: (iffP idP) => [|[n Hn <-]]; last exact: mem_nth. by exists (index x s); [rewrite index_mem | apply nth_index]. Qed. Variable T : Type. Implicit Types (a : pred T) (x : T). Lemma has_nthP a s x0 : reflect (exists2 i, i < size s & a (nth x0 s i)) (has a s). Proof. elim: s => [|x s IHs] /=; first by right; case. case nax: (a x); first by left; exists 0. by apply: (iffP IHs) => [[i]|[[|i]]]; [exists i.+1 | rewrite nax | exists i]. Qed. Lemma all_nthP a s x0 : reflect (forall i, i < size s -> a (nth x0 s i)) (all a s). Proof. rewrite -(eq_all (fun x => negbK (a x))) all_predC. case: (has_nthP _ _ x0) => [na_s | a_s]; [right=> a_s | left=> i lti]. by case: na_s => i lti; rewrite a_s. by apply/idPn=> na_si; case: a_s; exists i. Qed. Lemma set_nthE s x0 n x : set_nth x0 s n x = if n < size s then take n s ++ x :: drop n.+1 s else s ++ ncons (n - size s) x0 [:: x]. Proof. elim: s n => [|a s IH] n /=; first by rewrite subn0 set_nth_nil. case: n => [|n]; first by rewrite drop0. by rewrite ltnS /=; case: ltnP (IH n) => _ ->. Qed. Lemma count_set_nth a s x0 n x : count a (set_nth x0 s n x) = count a s + a x - a (nth x0 s n) * (n < size s) + (a x0) * (n - size s). Proof. rewrite set_nthE; case: ltnP => [nlts|nges]; last first. rewrite -cat_nseq !count_cat count_nseq /=. by rewrite muln0 addn0 subn0 addnAC addnA. have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW. rewrite -[in count a s](cat_take_drop n s) [drop n s](drop_nth x0)//. by rewrite !count_cat/= muln1 muln0 addn0 addnAC !addnA [in RHS]addnAC addnK. Qed. Lemma count_set_nth_ltn a s x0 n x : n < size s -> count a (set_nth x0 s n x) = count a s + a x - a (nth x0 s n). Proof. move=> nlts; rewrite count_set_nth nlts muln1. have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW. by rewrite muln0 addn0. Qed. Lemma count_set_nthF a s x0 n x : ~~ a x0 -> count a (set_nth x0 s n x) = count a s + a x - a (nth x0 s n). Proof. move=> /negbTE ax0; rewrite count_set_nth ax0 mul0n addn0. case: ltnP => [_|nges]; first by rewrite muln1. by rewrite nth_default// ax0 subn0. Qed. End NthTheory. Lemma set_nth_default T s (y0 x0 : T) n : n < size s -> nth x0 s n = nth y0 s n. Proof. by elim: s n => [|y s' IHs] [|n] //= /IHs. Qed. Lemma headI T s (x : T) : rcons s x = head x s :: behead (rcons s x). Proof. by case: s. Qed. Arguments nthP {T s x}. Arguments has_nthP {T a s}. Arguments all_nthP {T a s}. Definition bitseq := seq bool. #[hnf] HB.instance Definition _ := Equality.on bitseq. Canonical bitseq_predType := Eval hnf in [predType of bitseq]. (* Generalizations of splitP (from path.v): split_find_nth and split_find *) Section FindNth. Variables (T : Type). Implicit Types (x : T) (p : pred T) (s : seq T). Variant split_find_nth_spec p : seq T -> seq T -> seq T -> T -> Type := FindNth x s1 s2 of p x & ~~ has p s1 : split_find_nth_spec p (rcons s1 x ++ s2) s1 s2 x. Lemma split_find_nth x0 p s (i := find p s) : has p s -> split_find_nth_spec p s (take i s) (drop i.+1 s) (nth x0 s i). Proof. move=> p_s; rewrite -[X in split_find_nth_spec _ X](cat_take_drop i s). rewrite (drop_nth x0 _) -?has_find// -cat_rcons. by constructor; [apply: nth_find | rewrite has_take -?leqNgt]. Qed. Variant split_find_spec p : seq T -> seq T -> seq T -> Type := FindSplit x s1 s2 of p x & ~~ has p s1 : split_find_spec p (rcons s1 x ++ s2) s1 s2. Lemma split_find p s (i := find p s) : has p s -> split_find_spec p s (take i s) (drop i.+1 s). Proof. by case: s => // x ? in i * => ?; case: split_find_nth => //; constructor. Qed. Lemma nth_rcons_cat_find x0 p s1 s2 x (s := rcons s1 x ++ s2) : p x -> ~~ has p s1 -> nth x0 s (find p s) = x. Proof. move=> pz pNs1; rewrite /s cat_rcons find_cat (negPf pNs1). by rewrite nth_cat/= pz addn0 subnn ltnn. Qed. End FindNth. (* Incrementing the ith nat in a seq nat, padding with 0's if needed. This *) (* allows us to use nat seqs as bags of nats. *) Fixpoint incr_nth v i {struct i} := if v is n :: v' then if i is i'.+1 then n :: incr_nth v' i' else n.+1 :: v' else ncons i 0 [:: 1]. Arguments incr_nth : simpl nomatch. Lemma nth_incr_nth v i j : nth 0 (incr_nth v i) j = (i == j) + nth 0 v j. Proof. elim: v i j => [|n v IHv] [|i] [|j] //=; rewrite ?eqSS ?addn0 //; try by case j. elim: i j => [|i IHv] [|j] //=; rewrite ?eqSS //; by case j. Qed. Lemma size_incr_nth v i : size (incr_nth v i) = if i < size v then size v else i.+1. Proof. elim: v i => [|n v IHv] [|i] //=; first by rewrite size_ncons /= addn1. by rewrite IHv; apply: fun_if. Qed. Lemma incr_nth_inj v : injective (incr_nth v). Proof. move=> i j /(congr1 (nth 0 ^~ i)); apply: contra_eq => neq_ij. by rewrite !nth_incr_nth eqn_add2r eqxx /nat_of_bool ifN_eqC. Qed. Lemma incr_nthC v i j : incr_nth (incr_nth v i) j = incr_nth (incr_nth v j) i. Proof. apply: (@eq_from_nth _ 0) => [|k _]; last by rewrite !nth_incr_nth addnCA. by do !rewrite size_incr_nth leqNgt if_neg -/(maxn _ _); apply: maxnAC. Qed. (* Equality up to permutation *) Section PermSeq. Variable T : eqType. Implicit Type s : seq T. Definition perm_eq s1 s2 := all [pred x | count_mem x s1 == count_mem x s2] (s1 ++ s2). Lemma permP s1 s2 : reflect (count^~ s1 =1 count^~ s2) (perm_eq s1 s2). Proof. apply: (iffP allP) => /= [eq_cnt1 a | eq_cnt x _]; last exact/eqP. have [n le_an] := ubnP (count a (s1 ++ s2)); elim: n => // n IHn in a le_an *. have [/eqP|] := posnP (count a (s1 ++ s2)). by rewrite count_cat addn_eq0; do 2!case: eqP => // ->. rewrite -has_count => /hasP[x s12x a_x]; pose a' := predD1 a x. have cnt_a' s: count a s = count_mem x s + count a' s. rewrite -count_predUI -[LHS]addn0 -(count_pred0 s). by congr (_ + _); apply: eq_count => y /=; case: eqP => // ->. rewrite !cnt_a' (eqnP (eq_cnt1 _ s12x)) (IHn a') // -ltnS. apply: leq_trans le_an. by rewrite ltnS cnt_a' -add1n leq_add2r -has_count has_pred1. Qed. Lemma perm_refl s : perm_eq s s. Proof. exact/permP. Qed. Hint Resolve perm_refl : core. Lemma perm_sym : symmetric perm_eq. Proof. by move=> s1 s2; apply/permP/permP=> eq_s12 a. Qed. Lemma perm_trans : transitive perm_eq. Proof. by move=> s2 s1 s3 /permP-eq12 /permP/(ftrans eq12)/permP. Qed. Notation perm_eql s1 s2 := (perm_eq s1 =1 perm_eq s2). Notation perm_eqr s1 s2 := (perm_eq^~ s1 =1 perm_eq^~ s2). Lemma permEl s1 s2 : perm_eql s1 s2 -> perm_eq s1 s2. Proof. by move->. Qed. Lemma permPl s1 s2 : reflect (perm_eql s1 s2) (perm_eq s1 s2). Proof. apply: (iffP idP) => [eq12 s3 | -> //]; apply/idP/idP; last exact: perm_trans. by rewrite -!(perm_sym s3) => /perm_trans; apply. Qed. Lemma permPr s1 s2 : reflect (perm_eqr s1 s2) (perm_eq s1 s2). Proof. by apply/(iffP idP) => [/permPl eq12 s3| <- //]; rewrite !(perm_sym s3) eq12. Qed. Lemma perm_catC s1 s2 : perm_eql (s1 ++ s2) (s2 ++ s1). Proof. by apply/permPl/permP=> a; rewrite !count_cat addnC. Qed. Lemma perm_cat2l s1 s2 s3 : perm_eq (s1 ++ s2) (s1 ++ s3) = perm_eq s2 s3. Proof. apply/permP/permP=> eq23 a; apply/eqP; by move/(_ a)/eqP: eq23; rewrite !count_cat eqn_add2l. Qed. Lemma perm_catl s t1 t2 : perm_eq t1 t2 -> perm_eql (s ++ t1) (s ++ t2). Proof. by move=> eq_t12; apply/permPl; rewrite perm_cat2l. Qed. Lemma perm_cons x s1 s2 : perm_eq (x :: s1) (x :: s2) = perm_eq s1 s2. Proof. exact: (perm_cat2l [::x]). Qed. Lemma perm_cat2r s1 s2 s3 : perm_eq (s2 ++ s1) (s3 ++ s1) = perm_eq s2 s3. Proof. by do 2!rewrite perm_sym perm_catC; apply: perm_cat2l. Qed. Lemma perm_catr s1 s2 t : perm_eq s1 s2 -> perm_eql (s1 ++ t) (s2 ++ t). Proof. by move=> eq_s12; apply/permPl; rewrite perm_cat2r. Qed. Lemma perm_cat s1 s2 t1 t2 : perm_eq s1 s2 -> perm_eq t1 t2 -> perm_eq (s1 ++ t1) (s2 ++ t2). Proof. by move=> /perm_catr-> /perm_catl->. Qed. Lemma perm_catAC s1 s2 s3 : perm_eql ((s1 ++ s2) ++ s3) ((s1 ++ s3) ++ s2). Proof. by apply/permPl; rewrite -!catA perm_cat2l perm_catC. Qed. Lemma perm_catCA s1 s2 s3 : perm_eql (s1 ++ s2 ++ s3) (s2 ++ s1 ++ s3). Proof. by apply/permPl; rewrite !catA perm_cat2r perm_catC. Qed. Lemma perm_catACA s1 s2 s3 s4 : perm_eql ((s1 ++ s2) ++ (s3 ++ s4)) ((s1 ++ s3) ++ (s2 ++ s4)). Proof. by apply/permPl; rewrite perm_catAC !catA perm_catAC. Qed. Lemma perm_rcons x s : perm_eql (rcons s x) (x :: s). Proof. by move=> /= s2; rewrite -cats1 perm_catC. Qed. Lemma perm_rot n s : perm_eql (rot n s) s. Proof. by move=> /= s2; rewrite perm_catC cat_take_drop. Qed. Lemma perm_rotr n s : perm_eql (rotr n s) s. Proof. exact: perm_rot. Qed. Lemma perm_rev s : perm_eql (rev s) s. Proof. by apply/permPl/permP=> i; rewrite count_rev. Qed. Lemma perm_filter s1 s2 a : perm_eq s1 s2 -> perm_eq (filter a s1) (filter a s2). Proof. by move/permP=> s12_count; apply/permP=> Q; rewrite !count_filter. Qed. Lemma perm_filterC a s : perm_eql (filter a s ++ filter (predC a) s) s. Proof. apply/permPl; elim: s => //= x s IHs. by case: (a x); last rewrite /= -cat1s perm_catCA; rewrite perm_cons. Qed. Lemma perm_size s1 s2 : perm_eq s1 s2 -> size s1 = size s2. Proof. by move/permP=> eq12; rewrite -!count_predT eq12. Qed. Lemma perm_mem s1 s2 : perm_eq s1 s2 -> s1 =i s2. Proof. by move/permP=> eq12 x; rewrite -!has_pred1 !has_count eq12. Qed. Lemma perm_nilP s : reflect (s = [::]) (perm_eq s [::]). Proof. by apply: (iffP idP) => [/perm_size/eqP/nilP | ->]. Qed. Lemma perm_consP x s t : reflect (exists i u, rot i t = x :: u /\ perm_eq u s) (perm_eq t (x :: s)). Proof. apply: (iffP idP) => [eq_txs | [i [u [Dt eq_us]]]]. have /rot_to[i u Dt]: x \in t by rewrite (perm_mem eq_txs) mem_head. by exists i, u; rewrite -(perm_cons x) -Dt perm_rot. by rewrite -(perm_rot i) Dt perm_cons. Qed. Lemma perm_has s1 s2 a : perm_eq s1 s2 -> has a s1 = has a s2. Proof. by move/perm_mem/eq_has_r. Qed. Lemma perm_all s1 s2 a : perm_eq s1 s2 -> all a s1 = all a s2. Proof. by move/perm_mem/eq_all_r. Qed. Lemma perm_small_eq s1 s2 : size s2 <= 1 -> perm_eq s1 s2 -> s1 = s2. Proof. move=> s2_le1 eqs12; move/perm_size: eqs12 s2_le1 (perm_mem eqs12). by case: s2 s1 => [|x []] // [|y []] // _ _ /(_ x) /[!(inE, eqxx)] /eqP->. Qed. Lemma uniq_leq_size s1 s2 : uniq s1 -> {subset s1 <= s2} -> size s1 <= size s2. Proof. elim: s1 s2 => //= x s1 IHs s2 /andP[not_s1x Us1] /forall_cons[s2x ss12]. have [i s3 def_s2] := rot_to s2x; rewrite -(size_rot i s2) def_s2. apply: IHs => // y s1y; have:= ss12 y s1y. by rewrite -(mem_rot i) def_s2 inE (negPf (memPn _ y s1y)). Qed. Lemma leq_size_uniq s1 s2 : uniq s1 -> {subset s1 <= s2} -> size s2 <= size s1 -> uniq s2. Proof. elim: s1 s2 => [[] | x s1 IHs s2] // Us1x; have /andP[not_s1x Us1] := Us1x. case/forall_cons => /rot_to[i s3 def_s2] ss12 le_s21. rewrite -(rot_uniq i) -(size_rot i) def_s2 /= in le_s21 *. have ss13 y (s1y : y \in s1): y \in s3. by have:= ss12 y s1y; rewrite -(mem_rot i) def_s2 inE (negPf (memPn _ y s1y)). rewrite IHs // andbT; apply: contraL _ le_s21 => s3x; rewrite -leqNgt. by apply/(uniq_leq_size Us1x)/allP; rewrite /= s3x; apply/allP. Qed. Lemma uniq_size_uniq s1 s2 : uniq s1 -> s1 =i s2 -> uniq s2 = (size s2 == size s1). Proof. move=> Us1 eqs12; apply/idP/idP=> [Us2 | /eqP eq_sz12]. by rewrite eqn_leq !uniq_leq_size // => y; rewrite eqs12. by apply: (leq_size_uniq Us1) => [y|]; rewrite (eqs12, eq_sz12). Qed. Lemma uniq_min_size s1 s2 : uniq s1 -> {subset s1 <= s2} -> size s2 <= size s1 -> (size s1 = size s2) * (s1 =i s2). Proof. move=> Us1 ss12 le_s21; have Us2: uniq s2 := leq_size_uniq Us1 ss12 le_s21. suffices: s1 =i s2 by split; first by apply/eqP; rewrite -uniq_size_uniq. move=> x; apply/idP/idP=> [/ss12// | s2x]; apply: contraLR le_s21 => not_s1x. rewrite -ltnNge (@uniq_leq_size (x :: s1)) /= ?not_s1x //. by apply/allP; rewrite /= s2x; apply/allP. Qed. Lemma eq_uniq s1 s2 : size s1 = size s2 -> s1 =i s2 -> uniq s1 = uniq s2. Proof. move=> eq_sz12 eq_s12. by apply/idP/idP=> Us; rewrite (uniq_size_uniq Us) ?eq_sz12 ?eqxx. Qed. Lemma perm_uniq s1 s2 : perm_eq s1 s2 -> uniq s1 = uniq s2. Proof. by move=> eq_s12; apply/eq_uniq; [apply/perm_size | apply/perm_mem]. Qed. Lemma uniq_perm s1 s2 : uniq s1 -> uniq s2 -> s1 =i s2 -> perm_eq s1 s2. Proof. move=> Us1 Us2 eq12; apply/allP=> x _; apply/eqP. by rewrite !count_uniq_mem ?eq12. Qed. Lemma perm_undup s1 s2 : s1 =i s2 -> perm_eq (undup s1) (undup s2). Proof. by move=> Es12; rewrite uniq_perm ?undup_uniq // => s; rewrite !mem_undup. Qed. Lemma count_mem_uniq s : (forall x, count_mem x s = (x \in s)) -> uniq s. Proof. move=> count1_s; have Uus := undup_uniq s. suffices: perm_eq s (undup s) by move/perm_uniq->. by apply/allP=> x _; apply/eqP; rewrite (count_uniq_mem x Uus) mem_undup. Qed. Lemma eq_count_undup a s1 s2 : {in a, s1 =i s2} -> count a (undup s1) = count a (undup s2). Proof. move=> s1_eq_s2; rewrite -!size_filter !filter_undup. apply/perm_size/perm_undup => x. by rewrite !mem_filter; case: (boolP (a x)) => //= /s1_eq_s2. Qed. Lemma catCA_perm_ind P : (forall s1 s2 s3, P (s1 ++ s2 ++ s3) -> P (s2 ++ s1 ++ s3)) -> (forall s1 s2, perm_eq s1 s2 -> P s1 -> P s2). Proof. move=> PcatCA s1 s2 eq_s12; rewrite -[s1]cats0 -[s2]cats0. elim: s2 nil => [|x s2 IHs] s3 in s1 eq_s12 *. by case: s1 {eq_s12}(perm_size eq_s12). have /rot_to[i s' def_s1]: x \in s1 by rewrite (perm_mem eq_s12) mem_head. rewrite -(cat_take_drop i s1) -catA => /PcatCA. rewrite catA -/(rot i s1) def_s1 /= -cat1s => /PcatCA/IHs/PcatCA; apply. by rewrite -(perm_cons x) -def_s1 perm_rot. Qed. Lemma catCA_perm_subst R F : (forall s1 s2 s3, F (s1 ++ s2 ++ s3) = F (s2 ++ s1 ++ s3) :> R) -> (forall s1 s2, perm_eq s1 s2 -> F s1 = F s2). Proof. move=> FcatCA s1 s2 /catCA_perm_ind => ind_s12. by apply: (ind_s12 (eq _ \o F)) => //= *; rewrite FcatCA. Qed. End PermSeq. Notation perm_eql s1 s2 := (perm_eq s1 =1 perm_eq s2). Notation perm_eqr s1 s2 := (perm_eq^~ s1 =1 perm_eq^~ s2). Arguments permP {T s1 s2}. Arguments permPl {T s1 s2}. Arguments permPr {T s1 s2}. Prenex Implicits perm_eq. #[global] Hint Resolve perm_refl : core. Section RotrLemmas. Variables (n0 : nat) (T : Type) (T' : eqType). Implicit Types (x : T) (s : seq T). Lemma size_rotr s : size (rotr n0 s) = size s. Proof. by rewrite size_rot. Qed. Lemma mem_rotr (s : seq T') : rotr n0 s =i s. Proof. by move=> x; rewrite mem_rot. Qed. Lemma rotr_size_cat s1 s2 : rotr (size s2) (s1 ++ s2) = s2 ++ s1. Proof. by rewrite /rotr size_cat addnK rot_size_cat. Qed. Lemma rotr1_rcons x s : rotr 1 (rcons s x) = x :: s. Proof. by rewrite -rot1_cons rotK. Qed. Lemma has_rotr a s : has a (rotr n0 s) = has a s. Proof. by rewrite has_rot. Qed. Lemma rotr_uniq (s : seq T') : uniq (rotr n0 s) = uniq s. Proof. by rewrite rot_uniq. Qed. Lemma rotrK : cancel (@rotr T n0) (rot n0). Proof. move=> s; have [lt_n0s | ge_n0s] := ltnP n0 (size s). by rewrite -{1}(subKn (ltnW lt_n0s)) -{1}[size s]size_rotr; apply: rotK. by rewrite -[in RHS](rot_oversize ge_n0s) /rotr (eqnP ge_n0s) rot0. Qed. Lemma rotr_inj : injective (@rotr T n0). Proof. exact (can_inj rotrK). Qed. Lemma take_rev s : take n0 (rev s) = rev (drop (size s - n0) s). Proof. set m := _ - n0; rewrite -[s in LHS](cat_take_drop m) rev_cat take_cat. rewrite size_rev size_drop -minnE minnC leq_min ltnn /m. by have [_|/eqnP->] := ltnP; rewrite ?subnn take0 cats0. Qed. Lemma rev_take s : rev (take n0 s) = drop (size s - n0) (rev s). Proof. by rewrite -[s in take _ s]revK take_rev revK size_rev. Qed. Lemma drop_rev s : drop n0 (rev s) = rev (take (size s - n0) s). Proof. set m := _ - n0; rewrite -[s in LHS](cat_take_drop m) rev_cat drop_cat. rewrite size_rev size_drop -minnE minnC leq_min ltnn /m. by have [_|/eqnP->] := ltnP; rewrite ?take0 // subnn drop0. Qed. Lemma rev_drop s : rev (drop n0 s) = take (size s - n0) (rev s). Proof. by rewrite -[s in drop _ s]revK drop_rev revK size_rev. Qed. Lemma rev_rotr s : rev (rotr n0 s) = rot n0 (rev s). Proof. by rewrite rev_cat -take_rev -drop_rev. Qed. Lemma rev_rot s : rev (rot n0 s) = rotr n0 (rev s). Proof. by apply: canLR revK _; rewrite rev_rotr revK. Qed. End RotrLemmas. Arguments rotrK n0 {T} s : rename. Arguments rotr_inj {n0 T} [s1 s2] eq_rotr_s12 : rename. Section RotCompLemmas. Variable T : Type. Implicit Type s : seq T. Lemma rotD m n s : m + n <= size s -> rot (m + n) s = rot m (rot n s). Proof. move=> sz_s; rewrite [LHS]/rot -[take _ s](cat_take_drop n). rewrite 5!(catA, =^~ rot_size_cat) !cat_take_drop. by rewrite size_drop !size_takel ?leq_addl ?addnK. Qed. Lemma rotS n s : n < size s -> rot n.+1 s = rot 1 (rot n s). Proof. exact: (@rotD 1). Qed. Lemma rot_add_mod m n s : n <= size s -> m <= size s -> rot m (rot n s) = rot (if m + n <= size s then m + n else m + n - size s) s. Proof. move=> Hn Hm; case: leqP => [/rotD // | /ltnW Hmn]; symmetry. by rewrite -{2}(rotK n s) /rotr -rotD size_rot addnBA ?subnK ?addnK. Qed. Lemma rot_minn n s : rot n s = rot (minn n (size s)) s. Proof. by case: (leqP n (size s)) => // /leqW ?; rewrite rot_size rot_oversize. Qed. Definition rot_add s n m (k := size s) (p := minn m k + minn n k) := locked (if p <= k then p else p - k). Lemma leq_rot_add n m s : rot_add s n m <= size s. Proof. by unlock rot_add; case: ifP; rewrite // leq_subLR leq_add // geq_minr. Qed. Lemma rot_addC n m s : rot_add s n m = rot_add s m n. Proof. by unlock rot_add; rewrite ![minn n _ + _]addnC. Qed. Lemma rot_rot_add n m s : rot m (rot n s) = rot (rot_add s n m) s. Proof. unlock rot_add. by rewrite (rot_minn n) (rot_minn m) rot_add_mod ?size_rot ?geq_minr. Qed. Lemma rot_rot m n s : rot m (rot n s) = rot n (rot m s). Proof. by rewrite rot_rot_add rot_addC -rot_rot_add. Qed. Lemma rot_rotr m n s : rot m (rotr n s) = rotr n (rot m s). Proof. by rewrite [RHS]/rotr size_rot rot_rot. Qed. Lemma rotr_rotr m n s : rotr m (rotr n s) = rotr n (rotr m s). Proof. by rewrite /rotr !size_rot rot_rot. Qed. End RotCompLemmas. Section Mask. Variables (n0 : nat) (T : Type). Implicit Types (m : bitseq) (s : seq T). Fixpoint mask m s {struct m} := match m, s with | b :: m', x :: s' => if b then x :: mask m' s' else mask m' s' | _, _ => [::] end. Lemma mask_false s n : mask (nseq n false) s = [::]. Proof. by elim: s n => [|x s IHs] [|n] /=. Qed. Lemma mask_true s n : size s <= n -> mask (nseq n true) s = s. Proof. by elim: s n => [|x s IHs] [|n] //= Hn; congr (_ :: _); apply: IHs. Qed. Lemma mask0 m : mask m [::] = [::]. Proof. by case: m. Qed. Lemma mask0s s : mask [::] s = [::]. Proof. by []. Qed. Lemma mask1 b x : mask [:: b] [:: x] = nseq b x. Proof. by case: b. Qed. Lemma mask_cons b m x s : mask (b :: m) (x :: s) = nseq b x ++ mask m s. Proof. by case: b. Qed. Lemma size_mask m s : size m = size s -> size (mask m s) = count id m. Proof. by move: m s; apply: seq_ind2 => // -[] x m s /= _ ->. Qed. Lemma mask_cat m1 m2 s1 s2 : size m1 = size s1 -> mask (m1 ++ m2) (s1 ++ s2) = mask m1 s1 ++ mask m2 s2. Proof. by move: m1 s1; apply: seq_ind2 => // -[] m1 x1 s1 /= _ ->. Qed. Lemma mask_rcons b m x s : size m = size s -> mask (rcons m b) (rcons s x) = mask m s ++ nseq b x. Proof. by move=> ms; rewrite -!cats1 mask_cat//; case: b. Qed. Lemma all_mask a m s : all a s -> all a (mask m s). Proof. by elim: s m => [|x s IHs] [|[] m]//= /andP[ax /IHs->]; rewrite ?ax. Qed. Lemma has_mask_cons a b m x s : has a (mask (b :: m) (x :: s)) = b && a x || has a (mask m s). Proof. by case: b. Qed. Lemma has_mask a m s : has a (mask m s) -> has a s. Proof. by apply/contraTT; rewrite -!all_predC; apply: all_mask. Qed. Lemma rev_mask m s : size m = size s -> rev (mask m s) = mask (rev m) (rev s). Proof. move: m s; apply: seq_ind2 => //= b x m s eq_size_sm IH. by case: b; rewrite !rev_cons mask_rcons ?IH ?size_rev// (cats1, cats0). Qed. Lemma mask_rot m s : size m = size s -> mask (rot n0 m) (rot n0 s) = rot (count id (take n0 m)) (mask m s). Proof. move=> Ems; rewrite mask_cat ?size_drop ?Ems // -rot_size_cat. by rewrite size_mask -?mask_cat ?size_take ?Ems // !cat_take_drop. Qed. Lemma resize_mask m s : {m1 | size m1 = size s & mask m s = mask m1 s}. Proof. exists (take (size s) m ++ nseq (size s - size m) false). by elim: s m => [|x s IHs] [|b m] //=; rewrite (size_nseq, IHs). by elim: s m => [|x s IHs] [|b m] //=; rewrite (mask_false, IHs). Qed. Lemma takeEmask i s : take i s = mask (nseq i true) s. Proof. by elim: i s => [s|i IHi []// ? ?]; rewrite ?take0 //= IHi. Qed. Lemma dropEmask i s : drop i s = mask (nseq i false ++ nseq (size s - i) true) s. Proof. by elim: i s => [s|? ? []//]; rewrite drop0/= mask_true// subn0. Qed. End Mask. Arguments mask _ !_ !_. Section EqMask. Variables (n0 : nat) (T : eqType). Implicit Types (s : seq T) (m : bitseq). Lemma mem_mask_cons x b m y s : (x \in mask (b :: m) (y :: s)) = b && (x == y) || (x \in mask m s). Proof. by case: b. Qed. Lemma mem_mask x m s : x \in mask m s -> x \in s. Proof. by rewrite -!has_pred1 => /has_mask. Qed. Lemma in_mask x m s : uniq s -> x \in mask m s = (x \in s) && nth false m (index x s). Proof. elim: s m => [|y s IHs] [|[] m]//= /andP[yNs ?]; rewrite ?in_cons ?IHs //=; by have [->|neq_xy] //= := eqVneq; rewrite ?andbF // (negPf yNs). Qed. Lemma mask_uniq s : uniq s -> forall m, uniq (mask m s). Proof. elim: s => [|x s IHs] Uxs [|b m] //=. case: b Uxs => //= /andP[s'x Us]; rewrite {}IHs // andbT. by apply: contra s'x; apply: mem_mask. Qed. Lemma mem_mask_rot m s : size m = size s -> mask (rot n0 m) (rot n0 s) =i mask m s. Proof. by move=> Ems x; rewrite mask_rot // mem_rot. Qed. End EqMask. Section Subseq. Variable T : eqType. Implicit Type s : seq T. Fixpoint subseq s1 s2 := if s2 is y :: s2' then if s1 is x :: s1' then subseq (if x == y then s1' else s1) s2' else true else s1 == [::]. Lemma sub0seq s : subseq [::] s. Proof. by case: s. Qed. Lemma subseq0 s : subseq s [::] = (s == [::]). Proof. by []. Qed. Lemma subseq_refl s : subseq s s. Proof. by elim: s => //= x s IHs; rewrite eqxx. Qed. Hint Resolve subseq_refl : core. Lemma subseqP s1 s2 : reflect (exists2 m, size m = size s2 & s1 = mask m s2) (subseq s1 s2). Proof. elim: s2 s1 => [|y s2 IHs2] [|x s1]. - by left; exists [::]. - by right=> -[m /eqP/nilP->]. - by left; exists (nseq (size s2).+1 false); rewrite ?size_nseq //= mask_false. apply: {IHs2}(iffP (IHs2 _)) => [] [m sz_m def_s1]. by exists ((x == y) :: m); rewrite /= ?sz_m // -def_s1; case: eqP => // ->. case: eqP => [_ | ne_xy]; last first. by case: m def_s1 sz_m => [|[] m] //; [case | move=> -> [<-]; exists m]. pose i := index true m; have def_m_i: take i m = nseq (size (take i m)) false. apply/all_pred1P; apply/(all_nthP true) => j. rewrite size_take ltnNge geq_min negb_or -ltnNge => /andP[lt_j_i _]. rewrite nth_take //= -negb_add addbF -addbT -negb_eqb. by rewrite [_ == _](before_find _ lt_j_i). have lt_i_m: i < size m. rewrite ltnNge; apply/negP=> le_m_i; rewrite take_oversize // in def_m_i. by rewrite def_m_i mask_false in def_s1. rewrite size_take lt_i_m in def_m_i. exists (take i m ++ drop i.+1 m). rewrite size_cat size_take size_drop lt_i_m. by rewrite sz_m in lt_i_m *; rewrite subnKC. rewrite {s1 def_s1}[s1](congr1 behead def_s1). rewrite -[s2](cat_take_drop i) -[m in LHS](cat_take_drop i) {}def_m_i -cat_cons. have sz_i_s2: size (take i s2) = i by apply: size_takel; rewrite sz_m in lt_i_m. rewrite lastI cat_rcons !mask_cat ?size_nseq ?size_belast ?mask_false //=. by rewrite (drop_nth true) // nth_index -?index_mem. Qed. Lemma mask_subseq m s : subseq (mask m s) s. Proof. by apply/subseqP; have [m1] := resize_mask m s; exists m1. Qed. Lemma subseq_trans : transitive subseq. Proof. move=> _ _ s /subseqP[m2 _ ->] /subseqP[m1 _ ->]. elim: s => [|x s IHs] in m2 m1 *; first by rewrite !mask0. case: m1 => [|[] m1]; first by rewrite mask0. case: m2 => [|[] m2] //; first by rewrite /= eqxx IHs. case/subseqP: (IHs m2 m1) => m sz_m def_s; apply/subseqP. by exists (false :: m); rewrite //= sz_m. case/subseqP: (IHs m2 m1) => m sz_m def_s; apply/subseqP. by exists (false :: m); rewrite //= sz_m. Qed. Lemma cat_subseq s1 s2 s3 s4 : subseq s1 s3 -> subseq s2 s4 -> subseq (s1 ++ s2) (s3 ++ s4). Proof. case/subseqP=> m1 sz_m1 -> /subseqP [m2 sz_m2 ->]; apply/subseqP. by exists (m1 ++ m2); rewrite ?size_cat ?mask_cat ?sz_m1 ?sz_m2. Qed. Lemma prefix_subseq s1 s2 : subseq s1 (s1 ++ s2). Proof. by rewrite -[s1 in subseq s1]cats0 cat_subseq ?sub0seq. Qed. Lemma suffix_subseq s1 s2 : subseq s2 (s1 ++ s2). Proof. exact: cat_subseq (sub0seq s1) _. Qed. Lemma take_subseq s i : subseq (take i s) s. Proof. by rewrite -[s in X in subseq _ X](cat_take_drop i) prefix_subseq. Qed. Lemma drop_subseq s i : subseq (drop i s) s. Proof. by rewrite -[s in X in subseq _ X](cat_take_drop i) suffix_subseq. Qed. Lemma mem_subseq s1 s2 : subseq s1 s2 -> {subset s1 <= s2}. Proof. by case/subseqP=> m _ -> x; apply: mem_mask. Qed. Lemma sub1seq x s : subseq [:: x] s = (x \in s). Proof. by elim: s => //= y s /[1!inE]; case: ifP; rewrite ?sub0seq. Qed. Lemma size_subseq s1 s2 : subseq s1 s2 -> size s1 <= size s2. Proof. by case/subseqP=> m sz_m ->; rewrite size_mask -sz_m ?count_size. Qed. Lemma size_subseq_leqif s1 s2 : subseq s1 s2 -> size s1 <= size s2 ?= iff (s1 == s2). Proof. move=> sub12; split; first exact: size_subseq. apply/idP/eqP=> [|-> //]; case/subseqP: sub12 => m sz_m ->{s1}. rewrite size_mask -sz_m // -all_count -(eq_all eqb_id). by move/(@all_pred1P _ true)->; rewrite sz_m mask_true. Qed. Lemma subseq_anti : antisymmetric subseq. Proof. move=> s1 s2 /andP[] /size_subseq_leqif /leqifP. by case: eqP => [//|_] + /size_subseq; rewrite ltnNge => /negP. Qed. Lemma subseq_cons s x : subseq s (x :: s). Proof. exact: suffix_subseq [:: x] s. Qed. Lemma cons_subseq s1 s2 x : subseq (x :: s1) s2 -> subseq s1 s2. Proof. exact/subseq_trans/subseq_cons. Qed. Lemma subseq_rcons s x : subseq s (rcons s x). Proof. by rewrite -cats1 prefix_subseq. Qed. Lemma subseq_uniq s1 s2 : subseq s1 s2 -> uniq s2 -> uniq s1. Proof. by case/subseqP=> m _ -> Us2; apply: mask_uniq. Qed. Lemma take_uniq s n : uniq s -> uniq (take n s). Proof. exact/subseq_uniq/take_subseq. Qed. Lemma drop_uniq s n : uniq s -> uniq (drop n s). Proof. exact/subseq_uniq/drop_subseq. Qed. Lemma undup_subseq s : subseq (undup s) s. Proof. elim: s => //= x s; case: (_ \in _); last by rewrite eqxx. by case: (undup s) => //= y u; case: (_ == _) => //=; apply: cons_subseq. Qed. Lemma subseq_rev s1 s2 : subseq (rev s1) (rev s2) = subseq s1 s2. Proof. wlog suff W : s1 s2 / subseq s1 s2 -> subseq (rev s1) (rev s2). by apply/idP/idP => /W //; rewrite !revK. by case/subseqP => m size_m ->; rewrite rev_mask // mask_subseq. Qed. Lemma subseq_cat2l s s1 s2 : subseq (s ++ s1) (s ++ s2) = subseq s1 s2. Proof. by elim: s => // x s IHs; rewrite !cat_cons /= eqxx. Qed. Lemma subseq_cat2r s s1 s2 : subseq (s1 ++ s) (s2 ++ s) = subseq s1 s2. Proof. by rewrite -subseq_rev !rev_cat subseq_cat2l subseq_rev. Qed. Lemma subseq_rot p s n : subseq p s -> exists2 k, k <= n & subseq (rot k p) (rot n s). Proof. move=> /subseqP[m size_m ->]. exists (count id (take n m)); last by rewrite -mask_rot // mask_subseq. by rewrite (leq_trans (count_size _ _))// size_take_min geq_minl. Qed. End Subseq. Prenex Implicits subseq. Arguments subseqP {T s1 s2}. #[global] Hint Resolve subseq_refl : core. Section Rem. Variables (T : eqType) (x : T). Fixpoint rem s := if s is y :: t then (if y == x then t else y :: rem t) else s. Lemma rem_cons y s : rem (y :: s) = if y == x then s else y :: rem s. Proof. by []. Qed. Lemma remE s : rem s = take (index x s) s ++ drop (index x s).+1 s. Proof. by elim: s => //= y s ->; case: eqVneq; rewrite ?drop0. Qed. Lemma rem_id s : x \notin s -> rem s = s. Proof. by elim: s => //= y s IHs /norP[neq_yx /IHs->]; case: eqVneq neq_yx. Qed. Lemma perm_to_rem s : x \in s -> perm_eq s (x :: rem s). Proof. move=> xs; rewrite remE -[X in perm_eq X](cat_take_drop (index x s)). by rewrite drop_index// -cat1s perm_catCA cat1s. Qed. Lemma size_rem s : x \in s -> size (rem s) = (size s).-1. Proof. by move/perm_to_rem/perm_size->. Qed. Lemma rem_subseq s : subseq (rem s) s. Proof. elim: s => //= y s IHs; rewrite eq_sym. by case: ifP => _; [apply: subseq_cons | rewrite eqxx]. Qed. Lemma rem_uniq s : uniq s -> uniq (rem s). Proof. by apply: subseq_uniq; apply: rem_subseq. Qed. Lemma mem_rem s : {subset rem s <= s}. Proof. exact: mem_subseq (rem_subseq s). Qed. Lemma rem_mem y s : y != x -> y \in s -> y \in rem s. Proof. move=> yx; elim: s => [//|z s IHs] /=. rewrite inE => /orP[/eqP<-|ys]; first by rewrite (negbTE yx) inE eqxx. by case: ifP => _ //; rewrite inE IHs ?orbT. Qed. Lemma rem_filter s : uniq s -> rem s = filter (predC1 x) s. Proof. elim: s => //= y s IHs /andP[not_s_y /IHs->]. by case: eqP => //= <-; apply/esym/all_filterP; rewrite all_predC has_pred1. Qed. Lemma mem_rem_uniq s : uniq s -> rem s =i [predD1 s & x]. Proof. by move/rem_filter=> -> y; rewrite mem_filter. Qed. Lemma mem_rem_uniqF s : uniq s -> x \in rem s = false. Proof. by move/mem_rem_uniq->; rewrite inE eqxx. Qed. Lemma count_rem P s : count P (rem s) = count P s - (x \in s) && P x. Proof. have [/perm_to_rem/permP->|xNs]/= := boolP (x \in s); first by rewrite addKn. by rewrite subn0 rem_id. Qed. Lemma count_mem_rem y s : count_mem y (rem s) = count_mem y s - (x == y). Proof. rewrite count_rem; have []//= := boolP (x \in s). by case: eqP => // <- /count_memPn->. Qed. End Rem. Section Map. Variables (n0 : nat) (T1 : Type) (x1 : T1). Variables (T2 : Type) (x2 : T2) (f : T1 -> T2). Fixpoint map s := if s is x :: s' then f x :: map s' else [::]. Lemma map_cons x s : map (x :: s) = f x :: map s. Proof. by []. Qed. Lemma map_nseq x : map (nseq n0 x) = nseq n0 (f x). Proof. by elim: n0 => // *; congr (_ :: _). Qed. Lemma map_cat s1 s2 : map (s1 ++ s2) = map s1 ++ map s2. Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs. Qed. Lemma size_map s : size (map s) = size s. Proof. by elim: s => //= x s ->. Qed. Lemma behead_map s : behead (map s) = map (behead s). Proof. by case: s. Qed. Lemma nth_map n s : n < size s -> nth x2 (map s) n = f (nth x1 s n). Proof. by elim: s n => [|x s IHs] []. Qed. Lemma map_rcons s x : map (rcons s x) = rcons (map s) (f x). Proof. by rewrite -!cats1 map_cat. Qed. Lemma last_map s x : last (f x) (map s) = f (last x s). Proof. by elim: s x => /=. Qed. Lemma belast_map s x : belast (f x) (map s) = map (belast x s). Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed. Lemma filter_map a s : filter a (map s) = map (filter (preim f a) s). Proof. by elim: s => //= x s IHs; rewrite (fun_if map) /= IHs. Qed. Lemma find_map a s : find a (map s) = find (preim f a) s. Proof. by elim: s => //= x s ->. Qed. Lemma has_map a s : has a (map s) = has (preim f a) s. Proof. by elim: s => //= x s ->. Qed. Lemma all_map a s : all a (map s) = all (preim f a) s. Proof. by elim: s => //= x s ->. Qed. Lemma all_mapT (a : pred T2) s : (forall x, a (f x)) -> all a (map s). Proof. by rewrite all_map => /allT->. Qed. Lemma count_map a s : count a (map s) = count (preim f a) s. Proof. by elim: s => //= x s ->. Qed. Lemma map_take s : map (take n0 s) = take n0 (map s). Proof. by elim: n0 s => [|n IHn] [|x s] //=; rewrite IHn. Qed. Lemma map_drop s : map (drop n0 s) = drop n0 (map s). Proof. by elim: n0 s => [|n IHn] [|x s] //=; rewrite IHn. Qed. Lemma map_rot s : map (rot n0 s) = rot n0 (map s). Proof. by rewrite /rot map_cat map_take map_drop. Qed. Lemma map_rotr s : map (rotr n0 s) = rotr n0 (map s). Proof. by apply: canRL (rotK n0) _; rewrite -map_rot rotrK. Qed. Lemma map_rev s : map (rev s) = rev (map s). Proof. by elim: s => //= x s IHs; rewrite !rev_cons -!cats1 map_cat IHs. Qed. Lemma map_mask m s : map (mask m s) = mask m (map s). Proof. by elim: m s => [|[|] m IHm] [|x p] //=; rewrite IHm. Qed. Lemma inj_map : injective f -> injective map. Proof. by move=> injf; elim=> [|x s IHs] [|y t] //= [/injf-> /IHs->]. Qed. Lemma inj_in_map (A : {pred T1}) : {in A &, injective f} -> {in [pred s | all [in A] s] &, injective map}. Proof. move=> injf; elim=> [|x s IHs] [|y t] //= /andP[Ax As] /andP[Ay At]. by case=> /injf-> // /IHs->. Qed. End Map. (* Sequence indexing with error. *) Section onth. Variable T : Type. Implicit Types x y z : T. Implicit Types m n : nat. Implicit Type s : seq T. Fixpoint onth s n {struct n} : option T := if s isn't x :: s then None else if n isn't n.+1 then Some x else onth s n. Lemma odflt_onth x0 s n : odflt x0 (onth s n) = nth x0 s n. Proof. by elim: n s => [|? ?] []. Qed. Lemma onthE s : onth s =1 nth None (map Some s). Proof. by move=> n; elim: n s => [|? ?] []. Qed. Lemma onth_nth x0 x t n : onth t n = Some x -> nth x0 t n = x. Proof. by move=> tn; rewrite -odflt_onth tn. Qed. Lemma onth0n n : onth [::] n = None. Proof. by case: n. Qed. Lemma onth1P x y n : onth [:: x] n = Some y <-> n = 0 /\ x = y. Proof. by case: n => [|[]]; split=> // -[] // _ ->. Qed. Lemma onthTE s n : onth s n = (n < size s) :> bool. Proof. by elim: n s => [|? ?] []. Qed. Lemma onthNE s n: ~~ onth s n = (size s <= n). Proof. by rewrite onthTE -leqNgt. Qed. Lemma onth_default n s : size s <= n -> onth s n = None. Proof. by rewrite -onthNE; case: onth. Qed. Lemma onth_cat s1 s2 n : onth (s1 ++ s2) n = if n < size s1 then onth s1 n else onth s2 (n - size s1). Proof. by elim: n s1 => [|? ?] []. Qed. Lemma onth_nseq x n m : onth (nseq n x) m = if m < n then Some x else None. Proof. by rewrite onthE/= -nth_nseq map_nseq. Qed. Lemma eq_onthP {s1 s2} : [<-> s1 = s2; forall i : nat, i < maxn (size s1) (size s2) -> onth s1 i = onth s2 i; forall i : nat, onth s1 i = onth s2 i]. Proof. tfae=> [->//|eqs12 i|eqs12]. have := eqs12 i; case: ltnP => [_ ->//|]. by rewrite geq_max => /andP[is1 is2] _; rewrite !onth_default. have /eqP eq_size_12 : size s1 == size s2. by rewrite eqn_leq -!onthNE eqs12 onthNE -eqs12 onthNE !leqnn. apply/(inj_map Some_inj)/(@eq_from_nth _ None); rewrite !size_map//. by move=> i _; rewrite -!onthE eqs12. Qed. Lemma eq_from_onth [s1 s2 : seq T] : (forall i : nat, onth s1 i = onth s2 i) -> s1 = s2. Proof. by move/(eq_onthP 0 2). Qed. Lemma eq_from_onth_le [s1 s2 : seq T] : (forall i : nat, i < maxn (size s1) (size s2) -> onth s1 i = onth s2 i) -> s1 = s2. Proof. by move/(eq_onthP 0 1). Qed. End onth. Lemma onth_map {T S} n (s : seq T) (f : T -> S) : onth (map f s) n = omap f (onth s n). Proof. by elim: s n => [|x s IHs] []. Qed. Lemma inj_onth_map {T S} n (s : seq T) (f : T -> S) x : injective f -> onth (map f s) n = Some (f x) -> onth s n = Some x. Proof. by rewrite onth_map => /inj_omap + fs; apply. Qed. Section onthEqType. Variables T : eqType. Implicit Types x y z : T. Implicit Types i m n : nat. Implicit Type s : seq T. Lemma onthP s x : reflect (exists i, onth s i = Some x) (x \in s). Proof. elim: s => [|y s IHs]; first by constructor=> -[] []. rewrite in_cons; case: eqVneq => [->|/= Nxy]; first by constructor; exists 0. apply: (iffP idP) => [/IHs[i <-]|[[|i]//=]]; first by exists i.+1. by move=> [eq_xy]; rewrite eq_xy eqxx in Nxy. by move=> six; apply/IHs; exists i. Qed. Lemma onthPn s x : reflect (forall i, onth s i != Some x) (x \notin s). Proof. apply: (iffP idP); first by move=> /onthP + i; apply: contra_not_neq; exists i. by move=> nsix; apply/onthP => -[n /eqP/negPn]; rewrite nsix. Qed. Lemma onth_inj s n m : uniq s -> minn m n < size s -> onth s n = onth s m -> n = m. Proof. elim: s m n => [|x s IHs]//= [|m] [|n]//=; rewrite ?minnSS !ltnS. - by move=> /andP[+ _] _ /eqP => /onthPn/(_ _)/negPf->. - by move=> /andP[+ _] _ /esym /eqP => /onthPn/(_ _)/negPf->. by move=> /andP[xNs /IHs]/[apply]/[apply]->. Qed. End onthEqType. Arguments onthP {T s x}. Arguments onthPn {T s x}. Arguments onth_nth {T}. Arguments onth_inj {T}. Notation "[ 'seq' E | i <- s ]" := (map (fun i => E) s) (i binder, format "[ '[hv' 'seq' E '/ ' | i <- s ] ']'") : seq_scope. Notation "[ 'seq' E | i <- s & C ]" := [seq E | i <- [seq i <- s | C]] (i binder, format "[ '[hv' 'seq' E '/ ' | i <- s '/ ' & C ] ']'") : seq_scope. Notation "[ 'seq' E : R | i <- s ]" := (@map _ R (fun i => E) s) (i binder, only parsing) : seq_scope. Notation "[ 'seq' E : R | i <- s & C ]" := [seq E : R | i <- [seq i <- s | C]] (i binder, only parsing) : seq_scope. Lemma filter_mask T a (s : seq T) : filter a s = mask (map a s) s. Proof. by elim: s => //= x s <-; case: (a x). Qed. Lemma all_sigP T a (s : seq T) : all a s -> {s' : seq (sig a) | s = map sval s'}. Proof. elim: s => /= [_|x s ihs /andP [ax /ihs [s' ->]]]; first by exists [::]. by exists (exist a x ax :: s'). Qed. Section MiscMask. Lemma leq_count_mask T (P : {pred T}) m s : count P (mask m s) <= count P s. Proof. by elim: s m => [|x s IHs] [|[] m]//=; rewrite ?leq_add2l (leq_trans (IHs _)) ?leq_addl. Qed. Variable (T : eqType). Implicit Types (s : seq T) (m : bitseq). Lemma mask_filter s m : uniq s -> mask m s = [seq i <- s | i \in mask m s]. Proof. elim: m s => [|[] m IH] [|x s /= /andP[/negP xS uS]]; rewrite ?filter_pred0 //. rewrite inE eqxx /=; congr cons; rewrite [LHS]IH//. by apply/eq_in_filter => ? /[1!inE]; case: eqP => [->|]. by case: ifP => [/mem_mask //|_]; apply: IH. Qed. Lemma leq_count_subseq P s1 s2 : subseq s1 s2 -> count P s1 <= count P s2. Proof. by move=> /subseqP[m _ ->]; rewrite leq_count_mask. Qed. Lemma count_maskP s1 s2 : (forall x, count_mem x s1 <= count_mem x s2) <-> exists2 m : bitseq, size m = size s2 & perm_eq s1 (mask m s2). Proof. split=> [s1_le|[m _ /permP s1ms2 x]]; last by rewrite s1ms2 leq_count_mask. suff [m mP]: exists m, perm_eq s1 (mask m s2). by have [m' sm' eqm] := resize_mask m s2; exists m'; rewrite -?eqm. elim: s2 => [|x s2 IHs]//= in s1 s1_le *. by exists [::]; apply/allP => x _/=; rewrite eqn_leq s1_le. have [y|m s1s2] := IHs (rem x s1); first by rewrite count_mem_rem leq_subLR. exists ((x \in s1) :: m); have [|/rem_id<-//] := boolP (x \in s1). by move/perm_to_rem/permPl->; rewrite perm_cons. Qed. Lemma count_subseqP s1 s2 : (forall x, count_mem x s1 <= count_mem x s2) <-> exists2 s, subseq s s2 & perm_eq s1 s. Proof. split=> [/count_maskP[m _]|]; first by exists (mask m s2); rewrite ?mask_subseq. by move=> -[_/subseqP[m sm ->] ?]; apply/count_maskP; exists m. Qed. End MiscMask. Section FilterSubseq. Variable T : eqType. Implicit Types (s : seq T) (a : pred T). Lemma filter_subseq a s : subseq (filter a s) s. Proof. by apply/subseqP; exists (map a s); rewrite ?size_map ?filter_mask. Qed. Lemma subseq_filter s1 s2 a : subseq s1 (filter a s2) = all a s1 && subseq s1 s2. Proof. elim: s2 s1 => [|x s2 IHs] [|y s1] //=; rewrite ?andbF ?sub0seq //. by case a_x: (a x); rewrite /= !IHs /=; case: eqP => // ->; rewrite a_x. Qed. Lemma subseq_uniqP s1 s2 : uniq s2 -> reflect (s1 = filter [in s1] s2) (subseq s1 s2). Proof. move=> uniq_s2; apply: (iffP idP) => [ss12 | ->]; last exact: filter_subseq. apply/eqP; rewrite -size_subseq_leqif ?subseq_filter ?(introT allP) //. apply/eqP/esym/perm_size. rewrite uniq_perm ?filter_uniq ?(subseq_uniq ss12) // => x. by rewrite mem_filter; apply: andb_idr; apply: (mem_subseq ss12). Qed. Lemma uniq_subseq_pivot x (s1 s2 s3 s4 : seq T) (s := s3 ++ x :: s4) : uniq s -> subseq (s1 ++ x :: s2) s = (subseq s1 s3 && subseq s2 s4). Proof. move=> uniq_s; apply/idP/idP => [sub_s'_s|/andP[? ?]]; last first. by rewrite cat_subseq //= eqxx. have uniq_s' := subseq_uniq sub_s'_s uniq_s. have/eqP {sub_s'_s uniq_s} := subseq_uniqP _ uniq_s sub_s'_s. rewrite !filter_cat /= mem_cat inE eqxx orbT /=. rewrite uniq_eqseq_pivotl // => /andP [/eqP -> /eqP ->]. by rewrite !filter_subseq. Qed. Lemma perm_to_subseq s1 s2 : subseq s1 s2 -> {s3 | perm_eq s2 (s1 ++ s3)}. Proof. elim Ds2: s2 s1 => [|y s2' IHs] [|x s1] //=; try by exists s2; rewrite Ds2. case: eqP => [-> | _] /IHs[s3 perm_s2] {IHs}. by exists s3; rewrite perm_cons. by exists (rcons s3 y); rewrite -cat_cons -perm_rcons -!cats1 catA perm_cat2r. Qed. Lemma subseq_rem x : {homo rem x : s1 s2 / @subseq T s1 s2}. Proof. move=> s1 s2; elim: s2 s1 => [|x2 s2 IHs2] [|x1 s1]; rewrite ?sub0seq //=. have [->|_] := eqVneq x1 x2; first by case: eqP => //= _ /IHs2; rewrite eqxx. move=> /IHs2/subseq_trans->//. by have [->|_] := eqVneq x x2; [apply: rem_subseq|apply: subseq_cons]. Qed. End FilterSubseq. Arguments subseq_uniqP [T s1 s2]. Section EqMap. Variables (n0 : nat) (T1 : eqType) (x1 : T1). Variables (T2 : eqType) (x2 : T2) (f : T1 -> T2). Implicit Type s : seq T1. Lemma map_f s x : x \in s -> f x \in map f s. Proof. by elim: s => //= y s IHs /predU1P[->|/IHs]; [apply: predU1l | apply: predU1r]. Qed. Lemma mapP s y : reflect (exists2 x, x \in s & y = f x) (y \in map f s). Proof. elim: s => [|x s IHs]; [by right; case|rewrite /= inE]. exact: equivP (orPP eqP IHs) (iff_sym exists_cons). Qed. Lemma subset_mapP (s : seq T1) (s' : seq T2) : {subset s' <= map f s} <-> exists2 t, all (mem s) t & s' = map f t. Proof. split => [|[r /allP/= rE ->] _ /mapP[x xr ->]]; last by rewrite map_f ?rE. elim: s' => [|x s' IHs'] subss'; first by exists [::]. have /mapP[y ys ->] := subss' _ (mem_head _ _). have [x' x's'|t st ->] := IHs'; first by rewrite subss'// inE x's' orbT. by exists (y :: t); rewrite //= ys st. Qed. Lemma map_uniq s : uniq (map f s) -> uniq s. Proof. elim: s => //= x s IHs /andP[not_sfx /IHs->]; rewrite andbT. by apply: contra not_sfx => sx; apply/mapP; exists x. Qed. Lemma map_inj_in_uniq s : {in s &, injective f} -> uniq (map f s) = uniq s. Proof. elim: s => //= x s IHs //= injf; congr (~~ _ && _). apply/mapP/idP=> [[y sy /injf] | ]; last by exists x. by rewrite mem_head mem_behead // => ->. by apply: IHs => y z sy sz; apply: injf => //; apply: predU1r. Qed. Lemma map_subseq s1 s2 : subseq s1 s2 -> subseq (map f s1) (map f s2). Proof. case/subseqP=> m sz_m ->; apply/subseqP. by exists m; rewrite ?size_map ?map_mask. Qed. Lemma nth_index_map s x0 x : {in s &, injective f} -> x \in s -> nth x0 s (index (f x) (map f s)) = x. Proof. elim: s => //= y s IHs inj_f s_x; rewrite (inj_in_eq inj_f) ?mem_head //. move: s_x; rewrite inE; have [-> // | _] := eqVneq; apply: IHs. by apply: sub_in2 inj_f => z; apply: predU1r. Qed. Lemma perm_map s t : perm_eq s t -> perm_eq (map f s) (map f t). Proof. by move/permP=> Est; apply/permP=> a; rewrite !count_map Est. Qed. Lemma sub_map s1 s2 : {subset s1 <= s2} -> {subset map f s1 <= map f s2}. Proof. by move=> sub_s ? /mapP[x x_s ->]; rewrite map_f ?sub_s. Qed. Lemma eq_mem_map s1 s2 : s1 =i s2 -> map f s1 =i map f s2. Proof. by move=> Es x; apply/idP/idP; apply: sub_map => ?; rewrite Es. Qed. Hypothesis Hf : injective f. Lemma mem_map s x : (f x \in map f s) = (x \in s). Proof. by apply/mapP/idP=> [[y Hy /Hf->] //|]; exists x. Qed. Lemma index_map s x : index (f x) (map f s) = index x s. Proof. by rewrite /index; elim: s => //= y s IHs; rewrite (inj_eq Hf) IHs. Qed. Lemma map_inj_uniq s : uniq (map f s) = uniq s. Proof. by apply: map_inj_in_uniq; apply: in2W. Qed. Lemma undup_map_inj s : undup (map f s) = map f (undup s). Proof. by elim: s => //= s0 s ->; rewrite mem_map //; case: (_ \in _). Qed. Lemma perm_map_inj s t : perm_eq (map f s) (map f t) -> perm_eq s t. Proof. move/permP=> Est; apply/allP=> x _ /=. have Dx: pred1 x =1 preim f (pred1 (f x)) by move=> y /=; rewrite inj_eq. by rewrite !(eq_count Dx) -!count_map Est. Qed. End EqMap. Arguments mapP {T1 T2 f s y}. Arguments subset_mapP {T1 T2}. Lemma map_of_seq (T1 : eqType) T2 (s : seq T1) (fs : seq T2) (y0 : T2) : {f | uniq s -> size fs = size s -> map f s = fs}. Proof. exists (fun x => nth y0 fs (index x s)) => uAs eq_sz. apply/esym/(@eq_from_nth _ y0); rewrite ?size_map eq_sz // => i ltis. by have x0 : T1 by [case: (s) ltis]; rewrite (nth_map x0) // index_uniq. Qed. Section MapComp. Variable S T U : Type. Lemma map_id (s : seq T) : map id s = s. Proof. by elim: s => //= x s ->. Qed. Lemma eq_map (f g : S -> T) : f =1 g -> map f =1 map g. Proof. by move=> Ef; elim=> //= x s ->; rewrite Ef. Qed. Lemma map_comp (f : T -> U) (g : S -> T) s : map (f \o g) s = map f (map g s). Proof. by elim: s => //= x s ->. Qed. Lemma mapK (f : S -> T) (g : T -> S) : cancel f g -> cancel (map f) (map g). Proof. by move=> fK; elim=> //= x s ->; rewrite fK. Qed. Lemma mapK_in (A : {pred S}) (f : S -> T) (g : T -> S) : {in A, cancel f g} -> {in [pred s | all [in A] s], cancel (map f) (map g)}. Proof. by move=> fK; elim=> //= x s IHs /andP[/fK-> /IHs->]. Qed. End MapComp. Lemma eq_in_map (S : eqType) T (f g : S -> T) (s : seq S) : {in s, f =1 g} <-> map f s = map g s. Proof. elim: s => //= x s IHs; split=> [/forall_cons[-> ?]|]; first by rewrite IHs.1. by move=> -[? ?]; apply/forall_cons; split=> [//|]; apply: IHs.2. Qed. Lemma map_id_in (T : eqType) f (s : seq T) : {in s, f =1 id} -> map f s = s. Proof. by move/eq_in_map->; apply: map_id. Qed. (* Map a partial function *) Section Pmap. Variables (aT rT : Type) (f : aT -> option rT) (g : rT -> aT). Fixpoint pmap s := if s is x :: s' then let r := pmap s' in oapp (cons^~ r) r (f x) else [::]. Lemma map_pK : pcancel g f -> cancel (map g) pmap. Proof. by move=> gK; elim=> //= x s ->; rewrite gK. Qed. Lemma size_pmap s : size (pmap s) = count [eta f] s. Proof. by elim: s => //= x s <-; case: (f _). Qed. Lemma pmapS_filter s : map some (pmap s) = map f (filter [eta f] s). Proof. by elim: s => //= x s; case fx: (f x) => //= [u] <-; congr (_ :: _). Qed. Hypothesis fK : ocancel f g. Lemma pmap_filter s : map g (pmap s) = filter [eta f] s. Proof. by elim: s => //= x s <-; rewrite -{3}(fK x); case: (f _). Qed. Lemma pmap_cat s t : pmap (s ++ t) = pmap s ++ pmap t. Proof. by elim: s => //= x s ->; case/f: x. Qed. Lemma all_pmap (p : pred rT) s : all p (pmap s) = all [pred i | oapp p true (f i)] s. Proof. by elim: s => //= x s <-; case: f. Qed. End Pmap. Lemma eq_in_pmap (aT : eqType) rT (f1 f2 : aT -> option rT) s : {in s, f1 =1 f2} -> pmap f1 s = pmap f2 s. Proof. by elim: s => //= a s IHs /forall_cons [-> /IHs ->]. Qed. Lemma eq_pmap aT rT (f1 f2 : aT -> option rT) : f1 =1 f2 -> pmap f1 =1 pmap f2. Proof. by move=> Ef; elim => //= a s ->; rewrite Ef. Qed. Section EqPmap. Variables (aT rT : eqType) (f : aT -> option rT) (g : rT -> aT). Lemma mem_pmap s u : (u \in pmap f s) = (Some u \in map f s). Proof. by elim: s => //= x s IHs; rewrite in_cons -IHs; case: (f x). Qed. Hypothesis fK : ocancel f g. Lemma can2_mem_pmap : pcancel g f -> forall s u, (u \in pmap f s) = (g u \in s). Proof. by move=> gK s u; rewrite -(mem_map (pcan_inj gK)) pmap_filter // mem_filter gK. Qed. Lemma pmap_uniq s : uniq s -> uniq (pmap f s). Proof. move/(filter_uniq f); rewrite -(pmap_filter fK); exact: map_uniq. Qed. Lemma perm_pmap s t : perm_eq s t -> perm_eq (pmap f s) (pmap f t). Proof. move=> eq_st; apply/(perm_map_inj Some_inj); rewrite !pmapS_filter. exact/perm_map/perm_filter. Qed. End EqPmap. Section PmapSub. Variables (T : Type) (p : pred T) (sT : subType p). Lemma size_pmap_sub s : size (pmap (insub : T -> option sT) s) = count p s. Proof. by rewrite size_pmap (eq_count (isSome_insub _)). Qed. End PmapSub. Section EqPmapSub. Variables (T : eqType) (p : pred T) (sT : subEqType p). Let insT : T -> option sT := insub. Lemma mem_pmap_sub s u : (u \in pmap insT s) = (val u \in s). Proof. exact/(can2_mem_pmap (insubK _))/valK. Qed. Lemma pmap_sub_uniq s : uniq s -> uniq (pmap insT s). Proof. exact: (pmap_uniq (insubK _)). Qed. End EqPmapSub. (* Index sequence *) Fixpoint iota m n := if n is n'.+1 then m :: iota m.+1 n' else [::]. Lemma size_iota m n : size (iota m n) = n. Proof. by elim: n m => //= n IHn m; rewrite IHn. Qed. Lemma iotaD m n1 n2 : iota m (n1 + n2) = iota m n1 ++ iota (m + n1) n2. Proof. by elim: n1 m => [|n1 IHn1] m; rewrite ?addn0 // -addSnnS /= -IHn1. Qed. Lemma iotaDl m1 m2 n : iota (m1 + m2) n = map (addn m1) (iota m2 n). Proof. by elim: n m2 => //= n IHn m2; rewrite -addnS IHn. Qed. Lemma nth_iota p m n i : i < n -> nth p (iota m n) i = m + i. Proof. by move/subnKC <-; rewrite addSnnS iotaD nth_cat size_iota ltnn subnn. Qed. Lemma mem_iota m n i : (i \in iota m n) = (m <= i < m + n). Proof. elim: n m => [|n IHn] /= m; first by rewrite addn0 ltnNge andbN. by rewrite in_cons IHn addnS ltnS; case: ltngtP => // ->; rewrite leq_addr. Qed. Lemma iota_uniq m n : uniq (iota m n). Proof. by elim: n m => //= n IHn m; rewrite mem_iota ltnn /=. Qed. Lemma take_iota k m n : take k (iota m n) = iota m (minn k n). Proof. have [lt_k_n|le_n_k] := ltnP. by elim: k n lt_k_n m => [|k IHk] [|n] //= H m; rewrite IHk. by apply: take_oversize; rewrite size_iota. Qed. Lemma drop_iota k m n : drop k (iota m n) = iota (m + k) (n - k). Proof. by elim: k m n => [|k IHk] m [|n] //=; rewrite ?addn0 // IHk addnS subSS. Qed. Lemma filter_iota_ltn m n j : j <= n -> [seq i <- iota m n | i < m + j] = iota m j. Proof. elim: n m j => [m j|n IHn m [|j] jlen]; first by rewrite leqn0 => /eqP ->. rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => i. by rewrite addn0 ltnNge mem_iota => /andP[->]. by rewrite /= addnS leq_addr -addSn IHn. Qed. Lemma filter_iota_leq n m j : j < n -> [seq i <- iota m n | i <= m + j] = iota m j.+1. Proof. elim: n m j => [//|n IHn] m [|j] jlen /=; rewrite leq_addr. rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => i. by rewrite addn0 leqNgt mem_iota => /andP[->]. by rewrite addnS -addSn IHn -1?ltnS. Qed. (* Making a sequence of a specific length, using indexes to compute items. *) Section MakeSeq. Variables (T : Type) (x0 : T). Definition mkseq f n : seq T := map f (iota 0 n). Lemma size_mkseq f n : size (mkseq f n) = n. Proof. by rewrite size_map size_iota. Qed. Lemma mkseqS f n : mkseq f n.+1 = rcons (mkseq f n) (f n). Proof. by rewrite /mkseq -addn1 iotaD add0n map_cat cats1. Qed. Lemma eq_mkseq f g : f =1 g -> mkseq f =1 mkseq g. Proof. by move=> Efg n; apply: eq_map Efg _. Qed. Lemma nth_mkseq f n i : i < n -> nth x0 (mkseq f n) i = f i. Proof. by move=> Hi; rewrite (nth_map 0) ?nth_iota ?size_iota. Qed. Lemma mkseq_nth s : mkseq (nth x0 s) (size s) = s. Proof. by apply: (@eq_from_nth _ x0); rewrite size_mkseq // => i Hi; rewrite nth_mkseq. Qed. Variant mkseq_spec s : seq T -> Type := | MapIota n f : s = mkseq f n -> mkseq_spec s (mkseq f n). Lemma mkseqP s : mkseq_spec s s. Proof. by rewrite -[s]mkseq_nth; constructor. Qed. Lemma map_nth_iota0 s i : i <= size s -> [seq nth x0 s j | j <- iota 0 i] = take i s. Proof. by move=> ile; rewrite -[s in RHS]mkseq_nth -map_take take_iota (minn_idPl _). Qed. Lemma map_nth_iota s i j : j <= size s - i -> [seq nth x0 s k | k <- iota i j] = take j (drop i s). Proof. elim: i => [|i IH] in s j *; first by rewrite subn0 drop0 => /map_nth_iota0->. case: s => [|x s /IH<-]; first by rewrite leqn0 => /eqP->. by rewrite -add1n iotaDl -map_comp. Qed. End MakeSeq. Section MakeEqSeq. Variable T : eqType. Lemma mkseq_uniqP (f : nat -> T) n : reflect {in gtn n &, injective f} (uniq (mkseq f n)). Proof. apply: (equivP (uniqP (f 0))); rewrite size_mkseq. by split=> injf i j lti ltj; have:= injf i j lti ltj; rewrite !nth_mkseq. Qed. Lemma mkseq_uniq (f : nat -> T) n : injective f -> uniq (mkseq f n). Proof. by move/map_inj_uniq->; apply: iota_uniq. Qed. Lemma perm_iotaP {s t : seq T} x0 (It := iota 0 (size t)) : reflect (exists2 Is, perm_eq Is It & s = map (nth x0 t) Is) (perm_eq s t). Proof. apply: (iffP idP) => [Est | [Is eqIst ->]]; last first. by rewrite -{2}[t](mkseq_nth x0) perm_map. elim: t => [|x t IHt] in s It Est *. by rewrite (perm_small_eq _ Est) //; exists [::]. have /rot_to[k s1 Ds]: x \in s by rewrite (perm_mem Est) mem_head. have [|Is1 eqIst1 Ds1] := IHt s1; first by rewrite -(perm_cons x) -Ds perm_rot. exists (rotr k (0 :: map succn Is1)). by rewrite perm_rot /It /= perm_cons (iotaDl 1) perm_map. by rewrite map_rotr /= -map_comp -(@eq_map _ _ (nth x0 t)) // -Ds1 -Ds rotK. Qed. End MakeEqSeq. Arguments perm_iotaP {T s t}. Section FoldRight. Variables (T : Type) (R : Type) (f : T -> R -> R) (z0 : R). Fixpoint foldr s := if s is x :: s' then f x (foldr s') else z0. End FoldRight. Section FoldRightComp. Variables (T1 T2 : Type) (h : T1 -> T2). Variables (R : Type) (f : T2 -> R -> R) (z0 : R). Lemma foldr_cat s1 s2 : foldr f z0 (s1 ++ s2) = foldr f (foldr f z0 s2) s1. Proof. by elim: s1 => //= x s1 ->. Qed. Lemma foldr_rcons s x : foldr f z0 (rcons s x) = foldr f (f x z0) s. Proof. by rewrite -cats1 foldr_cat. Qed. Lemma foldr_map s : foldr f z0 (map h s) = foldr (fun x z => f (h x) z) z0 s. Proof. by elim: s => //= x s ->. Qed. End FoldRightComp. (* Quick characterization of the null sequence. *) Definition sumn := foldr addn 0. Lemma sumn_ncons x n s : sumn (ncons n x s) = x * n + sumn s. Proof. by rewrite mulnC; elim: n => //= n ->; rewrite addnA. Qed. Lemma sumn_nseq x n : sumn (nseq n x) = x * n. Proof. by rewrite sumn_ncons addn0. Qed. Lemma sumn_cat s1 s2 : sumn (s1 ++ s2) = sumn s1 + sumn s2. Proof. by elim: s1 => //= x s1 ->; rewrite addnA. Qed. Lemma sumn_count T (a : pred T) s : sumn [seq a i : nat | i <- s] = count a s. Proof. by elim: s => //= s0 s /= ->. Qed. Lemma sumn_rcons s n : sumn (rcons s n) = sumn s + n. Proof. by rewrite -cats1 sumn_cat /= addn0. Qed. Lemma perm_sumn s1 s2 : perm_eq s1 s2 -> sumn s1 = sumn s2. Proof. by apply/catCA_perm_subst: s1 s2 => s1 s2 s3; rewrite !sumn_cat addnCA. Qed. Lemma sumn_rot s n : sumn (rot n s) = sumn s. Proof. by apply/perm_sumn; rewrite perm_rot. Qed. Lemma sumn_rev s : sumn (rev s) = sumn s. Proof. by apply/perm_sumn; rewrite perm_rev. Qed. Lemma natnseq0P s : reflect (s = nseq (size s) 0) (sumn s == 0). Proof. apply: (iffP idP) => [|->]; last by rewrite sumn_nseq. by elim: s => //= x s IHs; rewrite addn_eq0 => /andP[/eqP-> /IHs <-]. Qed. Lemma sumn_set_nth s x0 n x : sumn (set_nth x0 s n x) = sumn s + x - (nth x0 s n) * (n < size s) + x0 * (n - size s). Proof. rewrite set_nthE; case: ltnP => [nlts|nges]; last first. by rewrite sumn_cat sumn_ncons /= addn0 muln0 subn0 addnAC addnA. have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW. rewrite -[in sumn s](cat_take_drop n s) [drop n s](drop_nth x0)//. by rewrite !sumn_cat /= muln1 muln0 addn0 addnAC !addnA [in RHS]addnAC addnK. Qed. Lemma sumn_set_nth_ltn s x0 n x : n < size s -> sumn (set_nth x0 s n x) = sumn s + x - nth x0 s n. Proof. move=> nlts; rewrite sumn_set_nth nlts muln1. have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW. by rewrite muln0 addn0. Qed. Lemma sumn_set_nth0 s n x : sumn (set_nth 0 s n x) = sumn s + x - nth 0 s n. Proof. rewrite sumn_set_nth mul0n addn0. by case: ltnP => [_|nges]; rewrite ?muln1// nth_default. Qed. Section FoldLeft. Variables (T R : Type) (f : R -> T -> R). Fixpoint foldl z s := if s is x :: s' then foldl (f z x) s' else z. Lemma foldl_rev z s : foldl z (rev s) = foldr (fun x z => f z x) z s. Proof. by elim/last_ind: s z => // s x IHs z; rewrite rev_rcons -cats1 foldr_cat -IHs. Qed. Lemma foldl_cat z s1 s2 : foldl z (s1 ++ s2) = foldl (foldl z s1) s2. Proof. by rewrite -(revK (s1 ++ s2)) foldl_rev rev_cat foldr_cat -!foldl_rev !revK. Qed. Lemma foldl_rcons z s x : foldl z (rcons s x) = f (foldl z s) x. Proof. by rewrite -cats1 foldl_cat. Qed. End FoldLeft. Section Folds. Variables (T : Type) (f : T -> T -> T). Hypotheses (fA : associative f) (fC : commutative f). Lemma foldl_foldr x0 l : foldl f x0 l = foldr f x0 l. Proof. elim: l x0 => [//|x1 l IHl] x0 /=; rewrite {}IHl. by elim: l x0 x1 => [//|x2 l IHl] x0 x1 /=; rewrite IHl !fA [f x2 x1]fC. Qed. End Folds. Section Scan. Variables (T1 : Type) (x1 : T1) (T2 : Type) (x2 : T2). Variables (f : T1 -> T1 -> T2) (g : T1 -> T2 -> T1). Fixpoint pairmap x s := if s is y :: s' then f x y :: pairmap y s' else [::]. Lemma size_pairmap x s : size (pairmap x s) = size s. Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed. Lemma pairmap_cat x s1 s2 : pairmap x (s1 ++ s2) = pairmap x s1 ++ pairmap (last x s1) s2. Proof. by elim: s1 x => //= y s1 IHs1 x; rewrite IHs1. Qed. Lemma nth_pairmap s n : n < size s -> forall x, nth x2 (pairmap x s) n = f (nth x1 (x :: s) n) (nth x1 s n). Proof. by elim: s n => [|y s IHs] [|n] //= Hn x; apply: IHs. Qed. Fixpoint scanl x s := if s is y :: s' then let x' := g x y in x' :: scanl x' s' else [::]. Lemma size_scanl x s : size (scanl x s) = size s. Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed. Lemma scanl_cat x s1 s2 : scanl x (s1 ++ s2) = scanl x s1 ++ scanl (foldl g x s1) s2. Proof. by elim: s1 x => //= y s1 IHs1 x; rewrite IHs1. Qed. Lemma scanl_rcons x s1 y : scanl x (rcons s1 y) = rcons (scanl x s1) (foldl g x (rcons s1 y)). Proof. by rewrite -!cats1 scanl_cat foldl_cat. Qed. Lemma nth_cons_scanl s n : n <= size s -> forall x, nth x1 (x :: scanl x s) n = foldl g x (take n s). Proof. by elim: s n => [|y s IHs] [|n] Hn x //=; rewrite IHs. Qed. Lemma nth_scanl s n : n < size s -> forall x, nth x1 (scanl x s) n = foldl g x (take n.+1 s). Proof. by move=> n_lt x; rewrite -nth_cons_scanl. Qed. Lemma scanlK : (forall x, cancel (g x) (f x)) -> forall x, cancel (scanl x) (pairmap x). Proof. by move=> Hfg x s; elim: s x => //= y s IHs x; rewrite Hfg IHs. Qed. Lemma pairmapK : (forall x, cancel (f x) (g x)) -> forall x, cancel (pairmap x) (scanl x). Proof. by move=> Hgf x s; elim: s x => //= y s IHs x; rewrite Hgf IHs. Qed. End Scan. Prenex Implicits mask map pmap foldr foldl scanl pairmap. Section Zip. Variables (S T : Type) (r : S -> T -> bool). Fixpoint zip (s : seq S) (t : seq T) {struct t} := match s, t with | x :: s', y :: t' => (x, y) :: zip s' t' | _, _ => [::] end. Definition unzip1 := map (@fst S T). Definition unzip2 := map (@snd S T). Fixpoint all2 s t := match s, t with | [::], [::] => true | x :: s, y :: t => r x y && all2 s t | _, _ => false end. Lemma zip_unzip s : zip (unzip1 s) (unzip2 s) = s. Proof. by elim: s => [|[x y] s /= ->]. Qed. Lemma unzip1_zip s t : size s <= size t -> unzip1 (zip s t) = s. Proof. by elim: s t => [|x s IHs] [|y t] //= le_s_t; rewrite IHs. Qed. Lemma unzip2_zip s t : size t <= size s -> unzip2 (zip s t) = t. Proof. by elim: s t => [|x s IHs] [|y t] //= le_t_s; rewrite IHs. Qed. Lemma size1_zip s t : size s <= size t -> size (zip s t) = size s. Proof. by elim: s t => [|x s IHs] [|y t] //= Hs; rewrite IHs. Qed. Lemma size2_zip s t : size t <= size s -> size (zip s t) = size t. Proof. by elim: s t => [|x s IHs] [|y t] //= Hs; rewrite IHs. Qed. Lemma size_zip s t : size (zip s t) = minn (size s) (size t). Proof. by elim: s t => [|x s IHs] [|t2 t] //=; rewrite IHs minnSS. Qed. Lemma zip_cat s1 s2 t1 t2 : size s1 = size t1 -> zip (s1 ++ s2) (t1 ++ t2) = zip s1 t1 ++ zip s2 t2. Proof. by move: s1 t1; apply: seq_ind2 => //= x y s1 t1 _ ->. Qed. Lemma nth_zip x y s t i : size s = size t -> nth (x, y) (zip s t) i = (nth x s i, nth y t i). Proof. by elim: i s t => [|i IHi] [|y1 s1] [|y2 t] //= [/IHi->]. Qed. Lemma nth_zip_cond p s t i : nth p (zip s t) i = (if i < size (zip s t) then (nth p.1 s i, nth p.2 t i) else p). Proof. rewrite size_zip ltnNge geq_min. by elim: s t i => [|x s IHs] [|y t] [|i] //=; rewrite ?orbT -?IHs. Qed. Lemma zip_rcons s t x y : size s = size t -> zip (rcons s x) (rcons t y) = rcons (zip s t) (x, y). Proof. by move=> eq_sz; rewrite -!cats1 zip_cat //= eq_sz. Qed. Lemma rev_zip s t : size s = size t -> rev (zip s t) = zip (rev s) (rev t). Proof. move: s t; apply: seq_ind2 => //= x y s t eq_sz IHs. by rewrite !rev_cons IHs zip_rcons ?size_rev. Qed. Lemma all2E s t : all2 s t = (size s == size t) && all [pred xy | r xy.1 xy.2] (zip s t). Proof. by elim: s t => [|x s IHs] [|y t] //=; rewrite IHs andbCA. Qed. Lemma zip_map I f g (s : seq I) : zip (map f s) (map g s) = [seq (f i, g i) | i <- s]. Proof. by elim: s => //= i s ->. Qed. Lemma unzip1_map_nth_zip x y s t l : size s = size t -> unzip1 [seq nth (x, y) (zip s t) i | i <- l] = [seq nth x s i | i <- l]. Proof. by move=> st; elim: l => [//=|n l IH /=]; rewrite nth_zip ?IH ?st. Qed. Lemma unzip2_map_nth_zip x y s t l : size s = size t -> unzip2 [seq nth (x, y) (zip s t) i | i <- l] = [seq nth y t i | i <- l]. Proof. by move=> st; elim: l => [//=|n l IH /=]; rewrite nth_zip ?IH ?st. Qed. End Zip. Lemma zip_uniql (S T : eqType) (s : seq S) (t : seq T) : uniq s -> uniq (zip s t). Proof. case: s t => [|s0 s] [|t0 t] //; apply: contraTT => /(uniqPn (s0, t0)) [i [j]]. case=> o z; rewrite !nth_zip_cond !ifT ?js ?(ltn_trans o)// => -[n _]. by apply/(uniqPn s0); exists i, j; rewrite o n (leq_trans z) ?size_zip?geq_minl. Qed. Lemma zip_uniqr (S T : eqType) (s : seq S) (t : seq T) : uniq t -> uniq (zip s t). Proof. case: s t => [|s0 s] [|t0 t] //; apply: contraTT => /(uniqPn (s0, t0)) [i [j]]. case=> o z; rewrite !nth_zip_cond !ifT ?js ?(ltn_trans o)// => -[_ n]. by apply/(uniqPn t0); exists i, j; rewrite o n (leq_trans z) ?size_zip?geq_minr. Qed. Lemma perm_zip_sym (S T : eqType) (s1 s2 : seq S) (t1 t2 : seq T) : perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq (zip t1 s1) (zip t2 s2). Proof. have swap t s : zip t s = map (fun u => (u.2, u.1)) (zip s t). by elim: s t => [|x s +] [|y t]//= => ->. by rewrite [zip t1 s1]swap [zip t2 s2]swap; apply: perm_map. Qed. Lemma perm_zip1 {S T : eqType} (t1 t2 : seq T) (s1 s2 : seq S): size s1 = size t1 -> size s2 = size t2 -> perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq s1 s2. Proof. wlog [x y] : s1 s2 t1 t2 / (S * T)%type => [hwlog|]. case: s2 t2 => [|x s2] [|y t2] //; last exact: hwlog. by case: s1 t1 => [|u s1] [|v t1]//= _ _ /perm_nilP. move=> eq1 eq2 /(perm_iotaP (x, y))[ns nsP /(congr1 (@unzip1 _ _))]. rewrite unzip1_zip ?unzip1_map_nth_zip -?eq1// => ->. by apply/(perm_iotaP x); exists ns; rewrite // size_zip -eq2 minnn in nsP. Qed. Lemma perm_zip2 {S T : eqType} (s1 s2 : seq S) (t1 t2 : seq T) : size s1 = size t1 -> size s2 = size t2 -> perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq t1 t2. Proof. by move=> ? ? ?; rewrite (@perm_zip1 _ _ s1 s2) 1?perm_zip_sym. Qed. Prenex Implicits zip unzip1 unzip2 all2. Lemma eqseq_all (T : eqType) (s t : seq T) : (s == t) = all2 eq_op s t. Proof. by elim: s t => [|x s +] [|y t]//= => <-. Qed. Lemma eq_map_all I (T : eqType) (f g : I -> T) (s : seq I) : (map f s == map g s) = all [pred xy | xy.1 == xy.2] [seq (f i, g i) | i <- s]. Proof. by rewrite eqseq_all all2E !size_map eqxx zip_map. Qed. Section Flatten. Variable T : Type. Implicit Types (s : seq T) (ss : seq (seq T)). Definition flatten := foldr cat (Nil T). Definition shape := map (@size T). Fixpoint reshape sh s := if sh is n :: sh' then take n s :: reshape sh' (drop n s) else [::]. Definition flatten_index sh r c := sumn (take r sh) + c. Definition reshape_index sh i := find (pred1 0) (scanl subn i.+1 sh). Definition reshape_offset sh i := i - sumn (take (reshape_index sh i) sh). Lemma size_flatten ss : size (flatten ss) = sumn (shape ss). Proof. by elim: ss => //= s ss <-; rewrite size_cat. Qed. Lemma flatten_cat ss1 ss2 : flatten (ss1 ++ ss2) = flatten ss1 ++ flatten ss2. Proof. by elim: ss1 => //= s ss1 ->; rewrite catA. Qed. Lemma size_reshape sh s : size (reshape sh s) = size sh. Proof. by elim: sh s => //= s0 sh IHsh s; rewrite IHsh. Qed. Lemma nth_reshape (sh : seq nat) l n : nth [::] (reshape sh l) n = take (nth 0 sh n) (drop (sumn (take n sh)) l). Proof. elim: n sh l => [| n IHn] [| sh0 sh] l; rewrite ?take0 ?drop0 //=. by rewrite addnC -drop_drop; apply: IHn. Qed. Lemma flattenK ss : reshape (shape ss) (flatten ss) = ss. Proof. by elim: ss => //= s ss IHss; rewrite take_size_cat ?drop_size_cat ?IHss. Qed. Lemma reshapeKr sh s : size s <= sumn sh -> flatten (reshape sh s) = s. Proof. elim: sh s => [[]|n sh IHsh] //= s sz_s; rewrite IHsh ?cat_take_drop //. by rewrite size_drop leq_subLR. Qed. Lemma reshapeKl sh s : size s >= sumn sh -> shape (reshape sh s) = sh. Proof. elim: sh s => [[]|n sh IHsh] //= s sz_s. rewrite size_takel; last exact: leq_trans (leq_addr _ _) sz_s. by rewrite IHsh // -(leq_add2l n) size_drop -maxnE leq_max sz_s orbT. Qed. Lemma flatten_rcons ss s : flatten (rcons ss s) = flatten ss ++ s. Proof. by rewrite -cats1 flatten_cat /= cats0. Qed. Lemma flatten_seq1 s : flatten [seq [:: x] | x <- s] = s. Proof. by elim: s => //= s0 s ->. Qed. Lemma count_flatten ss P : count P (flatten ss) = sumn [seq count P x | x <- ss]. Proof. by elim: ss => //= s ss IHss; rewrite count_cat IHss. Qed. Lemma filter_flatten ss (P : pred T) : filter P (flatten ss) = flatten [seq filter P i | i <- ss]. Proof. by elim: ss => // s ss /= <-; apply: filter_cat. Qed. Lemma rev_flatten ss : rev (flatten ss) = flatten (rev (map rev ss)). Proof. by elim: ss => //= s ss IHss; rewrite rev_cons flatten_rcons -IHss rev_cat. Qed. Lemma nth_shape ss i : nth 0 (shape ss) i = size (nth [::] ss i). Proof. rewrite /shape; case: (ltnP i (size ss)) => Hi; first exact: nth_map. by rewrite !nth_default // size_map. Qed. Lemma shape_rev ss : shape (rev ss) = rev (shape ss). Proof. exact: map_rev. Qed. Lemma eq_from_flatten_shape ss1 ss2 : flatten ss1 = flatten ss2 -> shape ss1 = shape ss2 -> ss1 = ss2. Proof. by move=> Eflat Esh; rewrite -[LHS]flattenK Eflat Esh flattenK. Qed. Lemma rev_reshape sh s : size s = sumn sh -> rev (reshape sh s) = map rev (reshape (rev sh) (rev s)). Proof. move=> sz_s; apply/(canLR revK)/eq_from_flatten_shape. rewrite reshapeKr ?sz_s // -rev_flatten reshapeKr ?revK //. by rewrite size_rev sumn_rev sz_s. transitivity (rev (shape (reshape (rev sh) (rev s)))). by rewrite !reshapeKl ?revK ?size_rev ?sz_s ?sumn_rev. rewrite shape_rev; congr (rev _); rewrite -[RHS]map_comp. by under eq_map do rewrite /= size_rev. Qed. Lemma reshape_rcons s sh n (m := sumn sh) : m + n = size s -> reshape (rcons sh n) s = rcons (reshape sh (take m s)) (drop m s). Proof. move=> Dmn; apply/(can_inj revK); rewrite rev_reshape ?rev_rcons ?sumn_rcons //. rewrite /= take_rev drop_rev -Dmn addnK revK -rev_reshape //. by rewrite size_takel // -Dmn leq_addr. Qed. Lemma flatten_indexP sh r c : c < nth 0 sh r -> flatten_index sh r c < sumn sh. Proof. move=> lt_c_sh; rewrite -[sh in sumn sh](cat_take_drop r) sumn_cat ltn_add2l. suffices lt_r_sh: r < size sh by rewrite (drop_nth 0 lt_r_sh) ltn_addr. by case: ltnP => // le_sh_r; rewrite nth_default in lt_c_sh. Qed. Lemma reshape_indexP sh i : i < sumn sh -> reshape_index sh i < size sh. Proof. rewrite /reshape_index; elim: sh => //= n sh IHsh in i *; rewrite subn_eq0. by have [// | le_n_i] := ltnP i n; rewrite -leq_subLR subSn // => /IHsh. Qed. Lemma reshape_offsetP sh i : i < sumn sh -> reshape_offset sh i < nth 0 sh (reshape_index sh i). Proof. rewrite /reshape_offset /reshape_index; elim: sh => //= n sh IHsh in i *. rewrite subn_eq0; have [| le_n_i] := ltnP i n; first by rewrite subn0. by rewrite -leq_subLR /= subnDA subSn // => /IHsh. Qed. Lemma reshape_indexK sh i : flatten_index sh (reshape_index sh i) (reshape_offset sh i) = i. Proof. rewrite /reshape_offset /reshape_index /flatten_index -subSKn. elim: sh => //= n sh IHsh in i *; rewrite subn_eq0; have [//|le_n_i] := ltnP. by rewrite /= subnDA subSn // -addnA IHsh subnKC. Qed. Lemma flatten_indexKl sh r c : c < nth 0 sh r -> reshape_index sh (flatten_index sh r c) = r. Proof. rewrite /reshape_index /flatten_index. elim: sh r => [|n sh IHsh] [|r] //= lt_c_sh; first by rewrite ifT. by rewrite -addnA -addnS addKn IHsh. Qed. Lemma flatten_indexKr sh r c : c < nth 0 sh r -> reshape_offset sh (flatten_index sh r c) = c. Proof. rewrite /reshape_offset /reshape_index /flatten_index. elim: sh r => [|n sh IHsh] [|r] //= lt_c_sh; first by rewrite ifT ?subn0. by rewrite -addnA -addnS addKn /= subnDl IHsh. Qed. Lemma nth_flatten x0 ss i (r := reshape_index (shape ss) i) : nth x0 (flatten ss) i = nth x0 (nth [::] ss r) (reshape_offset (shape ss) i). Proof. rewrite /reshape_offset -subSKn {}/r /reshape_index. elim: ss => //= s ss IHss in i *; rewrite subn_eq0 nth_cat. by have [//|le_s_i] := ltnP; rewrite subnDA subSn /=. Qed. Lemma reshape_leq sh i1 i2 (r1 := reshape_index sh i1) (c1 := reshape_offset sh i1) (r2 := reshape_index sh i2) (c2 := reshape_offset sh i2) : (i1 <= i2) = ((r1 < r2) || ((r1 == r2) && (c1 <= c2))). Proof. rewrite {}/r1 {}/c1 {}/r2 {}/c2 /reshape_offset /reshape_index. elim: sh => [|s0 s IHs] /= in i1 i2 *; rewrite ?subn0 ?subn_eq0 //. have [[] i1s0 [] i2s0] := (ltnP i1 s0, ltnP i2 s0); first by rewrite !subn0. - by apply: leq_trans i2s0; apply/ltnW. - by apply/negP => /(leq_trans i1s0); rewrite leqNgt i2s0. by rewrite !subSn // !eqSS !ltnS !subnDA -IHs leq_subLR subnKC. Qed. End Flatten. Prenex Implicits flatten shape reshape. Lemma map_flatten S T (f : T -> S) ss : map f (flatten ss) = flatten (map (map f) ss). Proof. by elim: ss => // s ss /= <-; apply: map_cat. Qed. Lemma flatten_map1 (S T : Type) (f : S -> T) s : flatten [seq [:: f x] | x <- s] = map f s. Proof. by elim: s => //= s0 s ->. Qed. Lemma undup_flatten_nseq n (T : eqType) (s : seq T) : 0 < n -> undup (flatten (nseq n s)) = undup s. Proof. elim: n => [|[|n]/= IHn]//= _; rewrite ?cats0// undup_cat {}IHn//. rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => x. by rewrite mem_undup mem_cat => ->. Qed. Lemma sumn_flatten (ss : seq (seq nat)) : sumn (flatten ss) = sumn (map sumn ss). Proof. by elim: ss => // s ss /= <-; apply: sumn_cat. Qed. Lemma map_reshape T S (f : T -> S) sh s : map (map f) (reshape sh s) = reshape sh (map f s). Proof. by elim: sh s => //= sh0 sh IHsh s; rewrite map_take IHsh map_drop. Qed. Section EqFlatten. Variables S T : eqType. Lemma flattenP (A : seq (seq T)) x : reflect (exists2 s, s \in A & x \in s) (x \in flatten A). Proof. elim: A => /= [|s A IH_A]; [by right; case | rewrite mem_cat]. by apply: equivP (iff_sym exists_cons); apply: (orPP idP IH_A). Qed. Arguments flattenP {A x}. Lemma flatten_mapP (A : S -> seq T) s y : reflect (exists2 x, x \in s & y \in A x) (y \in flatten (map A s)). Proof. apply: (iffP flattenP) => [[_ /mapP[x sx ->]] | [x sx]] Axy; first by exists x. by exists (A x); rewrite ?map_f. Qed. Lemma perm_flatten (ss1 ss2 : seq (seq T)) : perm_eq ss1 ss2 -> perm_eq (flatten ss1) (flatten ss2). Proof. move=> eq_ss; apply/permP=> a; apply/catCA_perm_subst: ss1 ss2 eq_ss. by move=> ss1 ss2 ss3; rewrite !flatten_cat !count_cat addnCA. Qed. End EqFlatten. Arguments flattenP {T A x}. Arguments flatten_mapP {S T A s y}. Notation "[ 'seq' E | x <- s , y <- t ]" := (flatten [seq [seq E | y <- t] | x <- s]) (x binder, y binder, format "[ '[hv' 'seq' E '/ ' | x <- s , '/ ' y <- t ] ']'") : seq_scope. Notation "[ 'seq' E : R | x <- s , y <- t ]" := (flatten [seq [seq E : R | y <- t] | x <- s]) (x binder, y binder, only parsing) : seq_scope. Section PrefixSuffixInfix. Variables T : eqType. Implicit Type s : seq T. Fixpoint prefix s1 s2 {struct s2} := if s1 isn't x :: s1' then true else if s2 isn't y :: s2' then false else (x == y) && prefix s1' s2'. Lemma prefixE s1 s2 : prefix s1 s2 = (take (size s1) s2 == s1). Proof. by elim: s2 s1 => [|y s2 +] [|x s1]//= => ->; rewrite eq_sym. Qed. Lemma prefix_refl s : prefix s s. Proof. by rewrite prefixE take_size. Qed. Lemma prefixs0 s : prefix s [::] = (s == [::]). Proof. by case: s. Qed. Lemma prefix0s s : prefix [::] s. Proof. by case: s. Qed. Lemma prefix_cons s1 s2 x y : prefix (x :: s1) (y :: s2) = (x == y) && prefix s1 s2. Proof. by []. Qed. Lemma prefix_catr s1 s2 s1' s3 : size s1 = size s1' -> prefix (s1 ++ s2) (s1' ++ s3) = (s1 == s1') && prefix s2 s3. Proof. elim: s1 s1' => [|x s1 IHs1] [|y s1']//= [eqs1]. by rewrite IHs1// eqseq_cons andbA. Qed. Lemma prefix_prefix s1 s2 : prefix s1 (s1 ++ s2). Proof. by rewrite prefixE take_cat ltnn subnn take0 cats0. Qed. Hint Resolve prefix_prefix : core. Lemma prefixP {s1 s2} : reflect (exists s2' : seq T, s2 = s1 ++ s2') (prefix s1 s2). Proof. apply: (iffP idP) => [|[{}s2 ->]]; last exact: prefix_prefix. by rewrite prefixE => /eqP<-; exists (drop (size s1) s2); rewrite cat_take_drop. Qed. Lemma prefix_trans : transitive prefix. Proof. by move=> _ s2 _ /prefixP[s1 ->] /prefixP[s3 ->]; rewrite -catA. Qed. Lemma prefixs1 s x : prefix s [:: x] = (s == [::]) || (s == [:: x]). Proof. by case: s => //= y s; rewrite prefixs0 eqseq_cons. Qed. Lemma catl_prefix s1 s2 s3 : prefix (s1 ++ s3) s2 -> prefix s1 s2. Proof. by move=> /prefixP [s2'] ->; rewrite -catA. Qed. Lemma prefix_catl s1 s2 s3 : prefix s1 s2 -> prefix s1 (s2 ++ s3). Proof. by move=> /prefixP [s2'] ->; rewrite -catA. Qed. Lemma prefix_rcons s x : prefix s (rcons s x). Proof. by rewrite -cats1 prefix_prefix. Qed. Definition suffix s1 s2 := prefix (rev s1) (rev s2). Lemma suffixE s1 s2 : suffix s1 s2 = (drop (size s2 - size s1) s2 == s1). Proof. by rewrite /suffix prefixE take_rev (can_eq revK) size_rev. Qed. Lemma suffix_refl s : suffix s s. Proof. exact: prefix_refl. Qed. Lemma suffixs0 s : suffix s [::] = (s == [::]). Proof. by rewrite /suffix prefixs0 -!nilpE rev_nilp. Qed. Lemma suffix0s s : suffix [::] s. Proof. exact: prefix0s. Qed. Lemma prefix_rev s1 s2 : prefix (rev s1) (rev s2) = suffix s1 s2. Proof. by []. Qed. Lemma prefix_revLR s1 s2 : prefix (rev s1) s2 = suffix s1 (rev s2). Proof. by rewrite -prefix_rev revK. Qed. Lemma suffix_rev s1 s2 : suffix (rev s1) (rev s2) = prefix s1 s2. Proof. by rewrite -prefix_rev !revK. Qed. Lemma suffix_revLR s1 s2 : suffix (rev s1) s2 = prefix s1 (rev s2). Proof. by rewrite -prefix_rev revK. Qed. Lemma suffix_suffix s1 s2 : suffix s2 (s1 ++ s2). Proof. by rewrite /suffix rev_cat prefix_prefix. Qed. Hint Resolve suffix_suffix : core. Lemma suffixP {s1 s2} : reflect (exists s2' : seq T, s2 = s2' ++ s1) (suffix s1 s2). Proof. apply: (iffP prefixP) => [[s2' rev_s2]|[s2' ->]]; exists (rev s2'); last first. by rewrite rev_cat. by rewrite -[s2]revK rev_s2 rev_cat revK. Qed. Lemma suffix_trans : transitive suffix. Proof. by move=> _ s2 _ /suffixP[s1 ->] /suffixP[s3 ->]; rewrite catA. Qed. Lemma suffix_rcons s1 s2 x y : suffix (rcons s1 x) (rcons s2 y) = (x == y) && suffix s1 s2. Proof. by rewrite /suffix 2!rev_rcons prefix_cons. Qed. Lemma suffix_catl s1 s2 s3 s3' : size s3 = size s3' -> suffix (s1 ++ s3) (s2 ++ s3') = (s3 == s3') && suffix s1 s2. Proof. by move=> eqs3; rewrite /suffix !rev_cat prefix_catr ?size_rev// (can_eq revK). Qed. Lemma suffix_catr s1 s2 s3 : suffix s1 s2 -> suffix s1 (s3 ++ s2). Proof. by move=> /suffixP [s2'] ->; rewrite catA suffix_suffix. Qed. Lemma catl_suffix s s1 s2 : suffix (s ++ s1) s2 -> suffix s1 s2. Proof. by move=> /suffixP [s2'] ->; rewrite catA suffix_suffix. Qed. Lemma suffix_cons s x : suffix s (x :: s). Proof. by rewrite /suffix rev_cons prefix_rcons. Qed. Fixpoint infix s1 s2 := if s2 is y :: s2' then prefix s1 s2 || infix s1 s2' else s1 == [::]. Fixpoint infix_index s1 s2 := if prefix s1 s2 then 0 else if s2 is y :: s2' then (infix_index s1 s2').+1 else 1. Lemma infix0s s : infix [::] s. Proof. by case: s. Qed. Lemma infixs0 s : infix s [::] = (s == [::]). Proof. by case: s. Qed. Lemma infix_consl s1 y s2 : infix s1 (y :: s2) = prefix s1 (y :: s2) || infix s1 s2. Proof. by []. Qed. Lemma infix_indexss s : infix_index s s = 0. Proof. by case: s => //= x s; rewrite eqxx prefix_refl. Qed. Lemma infix_index_le s1 s2 : infix_index s1 s2 <= (size s2).+1. Proof. by elim: s2 => [|x s2'] /=; case: ifP. Qed. Lemma infixTindex s1 s2 : (infix_index s1 s2 <= size s2) = infix s1 s2. Proof. by elim: s2 s1 => [|y s2 +] [|x s1]//= => <-; case: ifP. Qed. Lemma infixPn s1 s2 : reflect (infix_index s1 s2 = (size s2).+1) (~~ infix s1 s2). Proof. rewrite -infixTindex -ltnNge; apply: (iffP idP) => [s2lt|->//]. by apply/eqP; rewrite eqn_leq s2lt infix_index_le. Qed. Lemma infix_index0s s : infix_index [::] s = 0. Proof. by case: s. Qed. Lemma infix_indexs0 s : infix_index s [::] = (s != [::]). Proof. by case: s. Qed. Lemma infixE s1 s2 : infix s1 s2 = (take (size s1) (drop (infix_index s1 s2) s2) == s1). Proof. elim: s2 s1 => [|y s2 +] [|x s1]//= => -> /=. by case: ifP => // /andP[/eqP-> ps1s2/=]; rewrite eqseq_cons -prefixE eqxx. Qed. Lemma infix_refl s : infix s s. Proof. by rewrite infixE infix_indexss// drop0 take_size. Qed. Lemma prefixW s1 s2 : prefix s1 s2 -> infix s1 s2. Proof. by elim: s2 s1 => [|y s2 IHs2] [|x s1]//=->. Qed. Lemma prefix_infix s1 s2 : infix s1 (s1 ++ s2). Proof. exact: prefixW. Qed. Hint Resolve prefix_infix : core. Lemma infix_infix s1 s2 s3 : infix s2 (s1 ++ s2 ++ s3). Proof. by elim: s1 => //= x s1 ->; rewrite orbT. Qed. Hint Resolve infix_infix : core. Lemma suffix_infix s1 s2 : infix s2 (s1 ++ s2). Proof. by rewrite -[X in s1 ++ X]cats0. Qed. Hint Resolve suffix_infix : core. Lemma infixP {s1 s2} : reflect (exists s s' : seq T, s2 = s ++ s1 ++ s') (infix s1 s2). Proof. apply: (iffP idP) => [|[p [s {s2}->]]]//=; rewrite infixE => /eqP<-. set k := infix_index _ _; exists (take k s2), (drop (size s1 + k) s2). by rewrite -drop_drop !cat_take_drop. Qed. Lemma infix_rev s1 s2 : infix (rev s1) (rev s2) = infix s1 s2. Proof. gen have sr : s1 s2 / infix s1 s2 -> infix (rev s1) (rev s2); last first. by apply/idP/idP => /sr; rewrite ?revK. by move=> /infixP[s [p ->]]; rewrite !rev_cat -catA. Qed. Lemma suffixW s1 s2 : suffix s1 s2 -> infix s1 s2. Proof. by rewrite -infix_rev; apply: prefixW. Qed. Lemma infix_trans : transitive infix. Proof. move=> s s1 s2 /infixP[s1p [s1s def_s]] /infixP[sp [ss def_s2]]. by apply/infixP; exists (sp ++ s1p),(s1s ++ ss); rewrite def_s2 def_s -!catA. Qed. Lemma infix_revLR s1 s2 : infix (rev s1) s2 = infix s1 (rev s2). Proof. by rewrite -infix_rev revK. Qed. Lemma infix_rconsl s1 s2 y : infix s1 (rcons s2 y) = suffix s1 (rcons s2 y) || infix s1 s2. Proof. rewrite -infix_rev rev_rcons infix_consl. by rewrite -rev_rcons prefix_rev infix_rev. Qed. Lemma infix_cons s x : infix s (x :: s). Proof. by rewrite -cat1s suffix_infix. Qed. Lemma infixs1 s x : infix s [:: x] = (s == [::]) || (s == [:: x]). Proof. by rewrite infix_consl prefixs1 orbC orbA orbb. Qed. Lemma catl_infix s s1 s2 : infix (s ++ s1) s2 -> infix s1 s2. Proof. apply: infix_trans; exact/suffixW/suffix_suffix. Qed. Lemma catr_infix s s1 s2 : infix (s1 ++ s) s2 -> infix s1 s2. Proof. by rewrite -infix_rev rev_cat => /catl_infix; rewrite infix_rev. Qed. Lemma cons2_infix s1 s2 x : infix (x :: s1) (x :: s2) -> infix s1 s2. Proof. by rewrite /= eqxx /= -cat1s => /orP[/prefixW//|]; exact: catl_infix. Qed. Lemma rcons2_infix s1 s2 x : infix (rcons s1 x) (rcons s2 x) -> infix s1 s2. Proof. by rewrite -infix_rev !rev_rcons => /cons2_infix; rewrite infix_rev. Qed. Lemma catr2_infix s s1 s2 : infix (s ++ s1) (s ++ s2) -> infix s1 s2. Proof. by elim: s => //= x s IHs /cons2_infix. Qed. Lemma catl2_infix s s1 s2 : infix (s1 ++ s) (s2 ++ s) -> infix s1 s2. Proof. by rewrite -infix_rev !rev_cat => /catr2_infix; rewrite infix_rev. Qed. Lemma infix_catl s1 s2 s3 : infix s1 s2 -> infix s1 (s3 ++ s2). Proof. by move=> is12; apply: infix_trans is12 (suffix_infix _ _). Qed. Lemma infix_catr s1 s2 s3 : infix s1 s2 -> infix s1 (s2 ++ s3). Proof. case: s3 => [|x s /infixP [p [sf]] ->]; first by rewrite cats0. by rewrite -catA; apply: infix_catl; rewrite -catA prefix_infix. Qed. Lemma prefix_infix_trans s2 s1 s3 : prefix s1 s2 -> infix s2 s3 -> infix s1 s3. Proof. by move=> /prefixW/infix_trans; apply. Qed. Lemma suffix_infix_trans s2 s1 s3 : suffix s1 s2 -> infix s2 s3 -> infix s1 s3. Proof. by move=> /suffixW/infix_trans; apply. Qed. Lemma infix_prefix_trans s2 s1 s3 : infix s1 s2 -> prefix s2 s3 -> infix s1 s3. Proof. by move=> + /prefixW; apply: infix_trans. Qed. Lemma infix_suffix_trans s2 s1 s3 : infix s1 s2 -> suffix s2 s3 -> infix s1 s3. Proof. by move=> + /suffixW; apply: infix_trans. Qed. Lemma prefix_suffix_trans s2 s1 s3 : prefix s1 s2 -> suffix s2 s3 -> infix s1 s3. Proof. by move=> /prefixW + /suffixW +; apply: infix_trans. Qed. Lemma suffix_prefix_trans s2 s1 s3 : suffix s1 s2 -> prefix s2 s3 -> infix s1 s3. Proof. by move=> /suffixW + /prefixW +; apply: infix_trans. Qed. Lemma infixW s1 s2 : infix s1 s2 -> subseq s1 s2. Proof. move=> /infixP[sp [ss ->]]. exact: subseq_trans (prefix_subseq _ _) (suffix_subseq _ _). Qed. Lemma mem_infix s1 s2 : infix s1 s2 -> {subset s1 <= s2}. Proof. by move=> /infixW subH; apply: mem_subseq. Qed. Lemma infix1s s x : infix [:: x] s = (x \in s). Proof. by elim: s => // x' s /= ->; rewrite in_cons prefix0s andbT. Qed. Lemma prefix1s s x : prefix [:: x] s -> x \in s. Proof. by rewrite -infix1s => /prefixW. Qed. Lemma suffix1s s x : suffix [:: x] s -> x \in s. Proof. by rewrite -infix1s => /suffixW. Qed. Lemma infix_rcons s x : infix s (rcons s x). Proof. by rewrite -cats1 prefix_infix. Qed. Lemma infix_uniq s1 s2 : infix s1 s2 -> uniq s2 -> uniq s1. Proof. by move=> /infixW /subseq_uniq subH. Qed. Lemma prefix_uniq s1 s2 : prefix s1 s2 -> uniq s2 -> uniq s1. Proof. by move=> /prefixW /infix_uniq preH. Qed. Lemma suffix_uniq s1 s2 : suffix s1 s2 -> uniq s2 -> uniq s1. Proof. by move=> /suffixW /infix_uniq preH. Qed. Lemma prefix_take s i : prefix (take i s) s. Proof. by rewrite -{2}[s](cat_take_drop i). Qed. Lemma suffix_drop s i : suffix (drop i s) s. Proof. by rewrite -{2}[s](cat_take_drop i). Qed. Lemma infix_take s i : infix (take i s) s. Proof. by rewrite prefixW // prefix_take. Qed. Lemma prefix_drop_gt0 s i : ~~ prefix (drop i s) s -> i > 0. Proof. by case: i => //=; rewrite drop0 ltnn prefix_refl. Qed. Lemma infix_drop s i : infix (drop i s) s. Proof. by rewrite -{2}[s](cat_take_drop i). Qed. Lemma consr_infix s1 s2 x : infix (x :: s1) s2 -> infix [:: x] s2. Proof. by rewrite -cat1s => /catr_infix. Qed. Lemma consl_infix s1 s2 x : infix (x :: s1) s2 -> infix s1 s2. Proof. by rewrite -cat1s => /catl_infix. Qed. Lemma prefix_index s1 s2 : prefix s1 s2 -> infix_index s1 s2 = 0. Proof. by case: s1 s2 => [|x s1] [|y s2] //= ->. Qed. Lemma size_infix s1 s2 : infix s1 s2 -> size s1 <= size s2. Proof. by move=> /infixW; apply: size_subseq. Qed. Lemma size_prefix s1 s2 : prefix s1 s2 -> size s1 <= size s2. Proof. by move=> /prefixW; apply: size_infix. Qed. Lemma size_suffix s1 s2 : suffix s1 s2 -> size s1 <= size s2. Proof. by move=> /suffixW; apply: size_infix. Qed. End PrefixSuffixInfix. Section AllPairsDep. Variables (S S' : Type) (T T' : S -> Type) (R : Type). Implicit Type f : forall x, T x -> R. Definition allpairs_dep f s t := [seq f x y | x <- s, y <- t x]. Lemma size_allpairs_dep f s t : size [seq f x y | x <- s, y <- t x] = sumn [seq size (t x) | x <- s]. Proof. by elim: s => //= x s IHs; rewrite size_cat size_map IHs. Qed. Lemma allpairs0l f t : [seq f x y | x <- [::], y <- t x] = [::]. Proof. by []. Qed. Lemma allpairs0r f s : [seq f x y | x <- s, y <- [::]] = [::]. Proof. by elim: s. Qed. Lemma allpairs1l f x t : [seq f x y | x <- [:: x], y <- t x] = [seq f x y | y <- t x]. Proof. exact: cats0. Qed. Lemma allpairs1r f s y : [seq f x y | x <- s, y <- [:: y x]] = [seq f x (y x) | x <- s]. Proof. exact: flatten_map1. Qed. Lemma allpairs_cons f x s t : [seq f x y | x <- x :: s, y <- t x] = [seq f x y | y <- t x] ++ [seq f x y | x <- s, y <- t x]. Proof. by []. Qed. Lemma eq_allpairs (f1 f2 : forall x, T x -> R) s t : (forall x, f1 x =1 f2 x) -> [seq f1 x y | x <- s, y <- t x] = [seq f2 x y | x <- s, y <- t x]. Proof. by move=> eq_f; under eq_map do under eq_map do rewrite eq_f. Qed. Lemma eq_allpairsr (f : forall x, T x -> R) s t1 t2 : (forall x, t1 x = t2 x) -> [seq f x y | x <- s, y <- t1 x] = [seq f x y | x <- s, y <- t2 x]. Proof. by move=> eq_t; under eq_map do rewrite eq_t. Qed. Lemma allpairs_cat f s1 s2 t : [seq f x y | x <- s1 ++ s2, y <- t x] = [seq f x y | x <- s1, y <- t x] ++ [seq f x y | x <- s2, y <- t x]. Proof. by rewrite map_cat flatten_cat. Qed. Lemma allpairs_rcons f x s t : [seq f x y | x <- rcons s x, y <- t x] = [seq f x y | x <- s, y <- t x] ++ [seq f x y | y <- t x]. Proof. by rewrite -cats1 allpairs_cat allpairs1l. Qed. Lemma allpairs_mapl f (g : S' -> S) s t : [seq f x y | x <- map g s, y <- t x] = [seq f (g x) y | x <- s, y <- t (g x)]. Proof. by rewrite -map_comp. Qed. Lemma allpairs_mapr f (g : forall x, T' x -> T x) s t : [seq f x y | x <- s, y <- map (g x) (t x)] = [seq f x (g x y) | x <- s, y <- t x]. Proof. by under eq_map do rewrite -map_comp. Qed. End AllPairsDep. Arguments allpairs_dep {S T R} f s t /. Lemma map_allpairs S T R R' (g : R' -> R) f s t : map g [seq f x y | x : S <- s, y : T x <- t x] = [seq g (f x y) | x <- s, y <- t x]. Proof. by rewrite map_flatten allpairs_mapl allpairs_mapr. Qed. Section AllPairsNonDep. Variables (S T R : Type) (f : S -> T -> R). Implicit Types (s : seq S) (t : seq T). Definition allpairs s t := [seq f x y | x <- s, y <- t]. Lemma size_allpairs s t : size [seq f x y | x <- s, y <- t] = size s * size t. Proof. by elim: s => //= x s IHs; rewrite size_cat size_map IHs. Qed. End AllPairsNonDep. Arguments allpairs {S T R} f s t /. Section EqAllPairsDep. Variables (S : eqType) (T : S -> eqType). Implicit Types (R : eqType) (s : seq S) (t : forall x, seq (T x)). Lemma allpairsPdep R (f : forall x, T x -> R) s t (z : R) : reflect (exists x y, [/\ x \in s, y \in t x & z = f x y]) (z \in [seq f x y | x <- s, y <- t x]). Proof. apply: (iffP flatten_mapP); first by case=> x sx /mapP[y ty ->]; exists x, y. by case=> x [y [sx ty ->]]; exists x; last apply: map_f. Qed. Variable R : eqType. Implicit Type f : forall x, T x -> R. Lemma allpairs_f_dep f s t x y : x \in s -> y \in t x -> f x y \in [seq f x y | x <- s, y <- t x]. Proof. by move=> sx ty; apply/allpairsPdep; exists x, y. Qed. Lemma eq_in_allpairs_dep f1 f2 s t : {in s, forall x, {in t x, f1 x =1 f2 x}} <-> [seq f1 x y : R | x <- s, y <- t x] = [seq f2 x y | x <- s, y <- t x]. Proof. split=> [eq_f | eq_fst x s_x]. by congr flatten; apply/eq_in_map=> x s_x; apply/eq_in_map/eq_f. apply/eq_in_map; apply/eq_in_map: x s_x; apply/eq_from_flatten_shape => //. by rewrite /shape -!map_comp; apply/eq_map=> x /=; rewrite !size_map. Qed. Lemma perm_allpairs_dep f s1 t1 s2 t2 : perm_eq s1 s2 -> {in s1, forall x, perm_eq (t1 x) (t2 x)} -> perm_eq [seq f x y | x <- s1, y <- t1 x] [seq f x y | x <- s2, y <- t2 x]. Proof. elim: s1 s2 t1 t2 => [s2 t1 t2 |a s1 IH s2 t1 t2 perm_s2 perm_t1]. by rewrite perm_sym => /perm_nilP->. have mem_a : a \in s2 by rewrite -(perm_mem perm_s2) inE eqxx. rewrite -[s2](cat_take_drop (index a s2)). rewrite allpairs_cat (drop_nth a) ?index_mem //= nth_index //=. rewrite perm_sym perm_catC -catA perm_cat //; last first. rewrite perm_catC -allpairs_cat. rewrite -remE perm_sym IH // => [|x xI]; last first. by apply: perm_t1; rewrite inE xI orbT. by rewrite -(perm_cons a) (perm_trans perm_s2 (perm_to_rem _)). have /perm_t1 : a \in a :: s1 by rewrite inE eqxx. rewrite perm_sym; elim: (t2 a) (t1 a) => /= [s4|b s3 IH1 s4 perm_s4]. by rewrite perm_sym => /perm_nilP->. have mem_b : b \in s4 by rewrite -(perm_mem perm_s4) inE eqxx. rewrite -[s4](cat_take_drop (index b s4)). rewrite map_cat /= (drop_nth b) ?index_mem //= nth_index //=. rewrite perm_sym perm_catC /= perm_cons // perm_catC -map_cat. rewrite -remE perm_sym IH1 // -(perm_cons b). by apply: perm_trans perm_s4 (perm_to_rem _). Qed. Lemma mem_allpairs_dep f s1 t1 s2 t2 : s1 =i s2 -> {in s1, forall x, t1 x =i t2 x} -> [seq f x y | x <- s1, y <- t1 x] =i [seq f x y | x <- s2, y <- t2 x]. Proof. move=> eq_s eq_t z; apply/allpairsPdep/allpairsPdep=> -[x [y [sx ty ->]]]; by exists x, y; rewrite -eq_s in sx *; rewrite eq_t in ty *. Qed. Lemma allpairs_uniq_dep f s t (st := [seq Tagged T y | x <- s, y <- t x]) : let g (p : {x : S & T x}) : R := f (tag p) (tagged p) in uniq s -> {in s, forall x, uniq (t x)} -> {in st &, injective g} -> uniq [seq f x y | x <- s, y <- t x]. Proof. move=> g Us Ut; rewrite -(map_allpairs g (existT T)) => /map_inj_in_uniq->{f g}. elim: s Us => //= x s IHs /andP[s'x Us] in st Ut *; rewrite {st}cat_uniq. rewrite {}IHs {Us}// ?andbT => [|x1 s_s1]; last exact/Ut/mem_behead. have injT: injective (existT T x) by move=> y z /eqP; rewrite eq_Tagged => /eqP. rewrite (map_inj_in_uniq (in2W injT)) {injT}Ut ?mem_head // has_sym has_map. by apply: contra s'x => /hasP[y _ /allpairsPdep[z [_ [? _ /(congr1 tag)/=->]]]]. Qed. End EqAllPairsDep. Arguments allpairsPdep {S T R f s t z}. Section MemAllPairs. Variables (S : Type) (T : S -> Type) (R : eqType). Implicit Types (f : forall x, T x -> R) (s : seq S). Lemma perm_allpairs_catr f s t1 t2 : perm_eql [seq f x y | x <- s, y <- t1 x ++ t2 x] ([seq f x y | x <- s, y <- t1 x] ++ [seq f x y | x <- s, y <- t2 x]). Proof. apply/permPl; rewrite perm_sym; elim: s => //= x s ihs. by rewrite perm_catACA perm_cat ?map_cat. Qed. Lemma mem_allpairs_catr f s y0 t : [seq f x y | x <- s, y <- y0 x ++ t x] =i [seq f x y | x <- s, y <- y0 x] ++ [seq f x y | x <- s, y <- t x]. Proof. exact/perm_mem/permPl/perm_allpairs_catr. Qed. Lemma perm_allpairs_consr f s y0 t : perm_eql [seq f x y | x <- s, y <- y0 x :: t x] ([seq f x (y0 x) | x <- s] ++ [seq f x y | x <- s, y <- t x]). Proof. by apply/permPl; rewrite (perm_allpairs_catr _ _ (fun=> [:: _])) allpairs1r. Qed. Lemma mem_allpairs_consr f s t y0 : [seq f x y | x <- s, y <- y0 x :: t x] =i [seq f x (y0 x) | x <- s] ++ [seq f x y | x <- s, y <- t x]. Proof. exact/perm_mem/permPl/perm_allpairs_consr. Qed. Lemma allpairs_rconsr f s y0 t : perm_eql [seq f x y | x <- s, y <- rcons (t x) (y0 x)] ([seq f x y | x <- s, y <- t x] ++ [seq f x (y0 x) | x <- s]). Proof. apply/permPl; rewrite -(eq_allpairsr _ _ (fun=> cats1 _ _)). by rewrite perm_allpairs_catr allpairs1r. Qed. Lemma mem_allpairs_rconsr f s t y0 : [seq f x y | x <- s, y <- rcons (t x) (y0 x)] =i ([seq f x y | x <- s, y <- t x] ++ [seq f x (y0 x) | x <- s]). Proof. exact/perm_mem/permPl/allpairs_rconsr. Qed. End MemAllPairs. Lemma all_allpairsP (S : eqType) (T : S -> eqType) (R : Type) (p : pred R) (f : forall x : S, T x -> R) (s : seq S) (t : forall x : S, seq (T x)) : reflect (forall (x : S) (y : T x), x \in s -> y \in t x -> p (f x y)) (all p [seq f x y | x <- s, y <- t x]). Proof. elim: s => [|x s IHs]; first by constructor. rewrite /= all_cat all_map /preim. apply/(iffP andP)=> [[/allP /= ? ? x' y x'_in_xs]|p_xs_t]. by move: x'_in_xs y => /[1!inE] /predU1P [-> //|? ?]; exact: IHs. split; first by apply/allP => ?; exact/p_xs_t/mem_head. by apply/IHs => x' y x'_in_s; apply: p_xs_t; rewrite inE x'_in_s orbT. Qed. Arguments all_allpairsP {S T R p f s t}. Section EqAllPairs. Variables S T R : eqType. Implicit Types (f : S -> T -> R) (s : seq S) (t : seq T). Lemma allpairsP f s t (z : R) : reflect (exists p, [/\ p.1 \in s, p.2 \in t & z = f p.1 p.2]) (z \in [seq f x y | x <- s, y <- t]). Proof. by apply: (iffP allpairsPdep) => [[x[y]]|[[x y]]]; [exists (x, y)|exists x, y]. Qed. Lemma allpairs_f f s t x y : x \in s -> y \in t -> f x y \in [seq f x y | x <- s, y <- t]. Proof. exact: allpairs_f_dep. Qed. Lemma eq_in_allpairs f1 f2 s t : {in s & t, f1 =2 f2} <-> [seq f1 x y : R | x <- s, y <- t] = [seq f2 x y | x <- s, y <- t]. Proof. split=> [eq_f | /eq_in_allpairs_dep-eq_f x y /eq_f/(_ y)//]. by apply/eq_in_allpairs_dep=> x /eq_f. Qed. Lemma perm_allpairs f s1 t1 s2 t2 : perm_eq s1 s2 -> perm_eq t1 t2 -> perm_eq [seq f x y | x <- s1, y <- t1] [seq f x y | x <- s2, y <- t2]. Proof. by move=> perm_s perm_t; apply: perm_allpairs_dep. Qed. Lemma mem_allpairs f s1 t1 s2 t2 : s1 =i s2 -> t1 =i t2 -> [seq f x y | x <- s1, y <- t1] =i [seq f x y | x <- s2, y <- t2]. Proof. by move=> eq_s eq_t; apply: mem_allpairs_dep. Qed. Lemma allpairs_uniq f s t (st := [seq (x, y) | x <- s, y <- t]) : uniq s -> uniq t -> {in st &, injective (uncurry f)} -> uniq [seq f x y | x <- s, y <- t]. Proof. move=> Us Ut inj_f; rewrite -(map_allpairs (uncurry f) (@pair S T)) -/st. rewrite map_inj_in_uniq // allpairs_uniq_dep {Us Ut st inj_f}//. by apply: in2W => -[x1 y1] [x2 y2] /= [-> ->]. Qed. End EqAllPairs. Arguments allpairsP {S T R f s t z}. Arguments perm_nilP {T s}. Arguments perm_consP {T x s t}. Section AllRel. Variables (T S : Type) (r : T -> S -> bool). Implicit Types (x : T) (y : S) (xs : seq T) (ys : seq S). Definition allrel xs ys := all [pred x | all (r x) ys] xs. Lemma allrel0l ys : allrel [::] ys. Proof. by []. Qed. Lemma allrel0r xs : allrel xs [::]. Proof. by elim: xs. Qed. Lemma allrel_consl x xs ys : allrel (x :: xs) ys = all (r x) ys && allrel xs ys. Proof. by []. Qed. Lemma allrel_consr xs y ys : allrel xs (y :: ys) = all (r^~ y) xs && allrel xs ys. Proof. exact: all_predI. Qed. Lemma allrel_cons2 x y xs ys : allrel (x :: xs) (y :: ys) = [&& r x y, all (r x) ys, all (r^~ y) xs & allrel xs ys]. Proof. by rewrite /= allrel_consr -andbA. Qed. Lemma allrel1l x ys : allrel [:: x] ys = all (r x) ys. Proof. exact: andbT. Qed. Lemma allrel1r xs y : allrel xs [:: y] = all (r^~ y) xs. Proof. by rewrite allrel_consr allrel0r andbT. Qed. Lemma allrel_catl xs xs' ys : allrel (xs ++ xs') ys = allrel xs ys && allrel xs' ys. Proof. exact: all_cat. Qed. Lemma allrel_catr xs ys ys' : allrel xs (ys ++ ys') = allrel xs ys && allrel xs ys'. Proof. elim: ys => /= [|y ys ihys]; first by rewrite allrel0r. by rewrite !allrel_consr ihys andbA. Qed. Lemma allrel_maskl m xs ys : allrel xs ys -> allrel (mask m xs) ys. Proof. by elim: m xs => [|[] m IHm] [|x xs] //= /andP [xys /IHm->]; rewrite ?xys. Qed. Lemma allrel_maskr m xs ys : allrel xs ys -> allrel xs (mask m ys). Proof. by elim: xs => //= x xs IHxs /andP [/all_mask->]. Qed. Lemma allrel_filterl a xs ys : allrel xs ys -> allrel (filter a xs) ys. Proof. by rewrite filter_mask; apply: allrel_maskl. Qed. Lemma allrel_filterr a xs ys : allrel xs ys -> allrel xs (filter a ys). Proof. by rewrite filter_mask; apply: allrel_maskr. Qed. Lemma allrel_allpairsE xs ys : allrel xs ys = all id [seq r x y | x <- xs, y <- ys]. Proof. by elim: xs => //= x xs ->; rewrite all_cat all_map. Qed. End AllRel. Arguments allrel {T S} r xs ys : simpl never. Arguments allrel0l {T S} r ys. Arguments allrel0r {T S} r xs. Arguments allrel_consl {T S} r x xs ys. Arguments allrel_consr {T S} r xs y ys. Arguments allrel1l {T S} r x ys. Arguments allrel1r {T S} r xs y. Arguments allrel_catl {T S} r xs xs' ys. Arguments allrel_catr {T S} r xs ys ys'. Arguments allrel_maskl {T S} r m xs ys. Arguments allrel_maskr {T S} r m xs ys. Arguments allrel_filterl {T S} r a xs ys. Arguments allrel_filterr {T S} r a xs ys. Arguments allrel_allpairsE {T S} r xs ys. Notation all2rel r xs := (allrel r xs xs). Lemma sub_in_allrel {T S : Type} (P : {pred T}) (Q : {pred S}) (r r' : T -> S -> bool) : {in P & Q, forall x y, r x y -> r' x y} -> forall xs ys, all P xs -> all Q ys -> allrel r xs ys -> allrel r' xs ys. Proof. move=> rr' + ys; elim=> //= x xs IHxs /andP [Px Pxs] Qys. rewrite !allrel_consl => /andP [+ {}/IHxs-> //]; rewrite andbT. by elim: ys Qys => //= y ys IHys /andP [Qy Qys] /andP [/rr'-> // /IHys->]. Qed. Lemma sub_allrel {T S : Type} (r r' : T -> S -> bool) : (forall x y, r x y -> r' x y) -> forall xs ys, allrel r xs ys -> allrel r' xs ys. Proof. by move=> rr' xs ys; apply/sub_in_allrel/all_predT/all_predT; apply: in2W. Qed. Lemma eq_in_allrel {T S : Type} (P : {pred T}) (Q : {pred S}) r r' : {in P & Q, r =2 r'} -> forall xs ys, all P xs -> all Q ys -> allrel r xs ys = allrel r' xs ys. Proof. move=> rr' xs ys Pxs Qys. by apply/idP/idP; apply/sub_in_allrel/Qys/Pxs => ? ? ? ?; rewrite rr'. Qed. Lemma eq_allrel {T S : Type} (r r' : T -> S -> bool) : r =2 r' -> allrel r =2 allrel r'. Proof. by move=> rr' xs ys; apply/eq_in_allrel/all_predT/all_predT. Qed. Lemma allrelC {T S : Type} (r : T -> S -> bool) xs ys : allrel r xs ys = allrel (fun y => r^~ y) ys xs. Proof. by elim: xs => [|x xs ih]; [elim: ys | rewrite allrel_consr -ih]. Qed. Lemma allrel_mapl {T T' S : Type} (f : T' -> T) (r : T -> S -> bool) xs ys : allrel r (map f xs) ys = allrel (fun x => r (f x)) xs ys. Proof. exact: all_map. Qed. Lemma allrel_mapr {T S S' : Type} (f : S' -> S) (r : T -> S -> bool) xs ys : allrel r xs (map f ys) = allrel (fun x y => r x (f y)) xs ys. Proof. by rewrite allrelC allrel_mapl allrelC. Qed. Lemma allrelP {T S : eqType} {r : T -> S -> bool} {xs ys} : reflect {in xs & ys, forall x y, r x y} (allrel r xs ys). Proof. by rewrite allrel_allpairsE; exact: all_allpairsP. Qed. Lemma allrelT {T S : Type} (xs : seq T) (ys : seq S) : allrel (fun _ _ => true) xs ys = true. Proof. by elim: xs => //= ? ?; rewrite allrel_consl all_predT. Qed. Lemma allrel_relI {T S : Type} (r r' : T -> S -> bool) xs ys : allrel (fun x y => r x y && r' x y) xs ys = allrel r xs ys && allrel r' xs ys. Proof. by rewrite -all_predI; apply: eq_all => ?; rewrite /= -all_predI. Qed. Lemma allrel_revl {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) : allrel r (rev s1) s2 = allrel r s1 s2. Proof. exact: all_rev. Qed. Lemma allrel_revr {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) : allrel r s1 (rev s2) = allrel r s1 s2. Proof. by rewrite allrelC allrel_revl allrelC. Qed. Lemma allrel_rev2 {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) : allrel r (rev s1) (rev s2) = allrel r s1 s2. Proof. by rewrite allrel_revr allrel_revl. Qed. Lemma eq_allrel_meml {T : eqType} {S} (r : T -> S -> bool) (s1 s1' : seq T) s2 : s1 =i s1' -> allrel r s1 s2 = allrel r s1' s2. Proof. by move=> eqs1; apply: eq_all_r. Qed. Lemma eq_allrel_memr {T} {S : eqType} (r : T -> S -> bool) s1 (s2 s2' : seq S) : s2 =i s2' -> allrel r s1 s2 = allrel r s1 s2'. Proof. by rewrite ![allrel _ s1 _]allrelC; apply: eq_allrel_meml. Qed. Lemma eq_allrel_mem2 {T S : eqType} (r : T -> S -> bool) (s1 s1' : seq T) (s2 s2' : seq S) : s1 =i s1' -> s2 =i s2' -> allrel r s1 s2 = allrel r s1' s2'. Proof. by move=> /eq_allrel_meml -> /eq_allrel_memr ->. Qed. Section All2Rel. Variable (T : nonPropType) (r : rel T). Implicit Types (x y z : T) (xs : seq T). Hypothesis (rsym : symmetric r). Lemma all2rel1 x : all2rel r [:: x] = r x x. Proof. by rewrite /allrel /= !andbT. Qed. Lemma all2rel2 x y : all2rel r [:: x; y] = r x x && r y y && r x y. Proof. by rewrite /allrel /= rsym; do 3 case: r. Qed. Lemma all2rel_cons x xs : all2rel r (x :: xs) = [&& r x x, all (r x) xs & all2rel r xs]. Proof. rewrite allrel_cons2; congr andb; rewrite andbA -all_predI; congr andb. by elim: xs => //= y xs ->; rewrite rsym andbb. Qed. End All2Rel. Section Pairwise. Variables (T : Type) (r : T -> T -> bool). Implicit Types (x y : T) (xs ys : seq T). Fixpoint pairwise xs : bool := if xs is x :: xs then all (r x) xs && pairwise xs else true. Lemma pairwise_cons x xs : pairwise (x :: xs) = all (r x) xs && pairwise xs. Proof. by []. Qed. Lemma pairwise_cat xs ys : pairwise (xs ++ ys) = [&& allrel r xs ys, pairwise xs & pairwise ys]. Proof. by elim: xs => //= x xs ->; rewrite all_cat -!andbA; bool_congr. Qed. Lemma pairwise_rcons xs x : pairwise (rcons xs x) = all (r^~ x) xs && pairwise xs. Proof. by rewrite -cats1 pairwise_cat allrel1r andbT. Qed. Lemma pairwise2 x y : pairwise [:: x; y] = r x y. Proof. by rewrite /= !andbT. Qed. Lemma pairwise_mask m xs : pairwise xs -> pairwise (mask m xs). Proof. by elim: m xs => [|[] m IHm] [|x xs] //= /andP [? ?]; rewrite ?IHm // all_mask. Qed. Lemma pairwise_filter a xs : pairwise xs -> pairwise (filter a xs). Proof. by rewrite filter_mask; apply: pairwise_mask. Qed. Lemma pairwiseP x0 xs : reflect {in gtn (size xs) &, {homo nth x0 xs : i j / i < j >-> r i j}} (pairwise xs). Proof. elim: xs => /= [|x xs IHxs]; first exact: (iffP idP). apply: (iffP andP) => [[r_x_xs pxs] i j|Hnth]; rewrite -?topredE /= ?ltnS. by case: i j => [|i] [|j] //= gti gtj ij; [exact/all_nthP | exact/IHxs]. split; last by apply/IHxs => // i j; apply/(Hnth i.+1 j.+1). by apply/(all_nthP x0) => i gti; apply/(Hnth 0 i.+1). Qed. Lemma pairwise_all2rel : reflexive r -> symmetric r -> forall xs, pairwise xs = all2rel r xs. Proof. by move=> r_refl r_sym; elim => //= x xs ->; rewrite all2rel_cons // r_refl. Qed. End Pairwise. Arguments pairwise {T} r xs. Arguments pairwise_cons {T} r x xs. Arguments pairwise_cat {T} r xs ys. Arguments pairwise_rcons {T} r xs x. Arguments pairwise2 {T} r x y. Arguments pairwise_mask {T r} m {xs}. Arguments pairwise_filter {T r} a {xs}. Arguments pairwiseP {T r} x0 {xs}. Arguments pairwise_all2rel {T r} r_refl r_sym xs. Lemma sub_in_pairwise {T : Type} (P : {pred T}) (r r' : rel T) : {in P &, subrel r r'} -> forall xs, all P xs -> pairwise r xs -> pairwise r' xs. Proof. move=> rr'; elim=> //= x xs IHxs /andP [Px Pxs] /andP [+ {}/IHxs->] //. rewrite andbT; elim: xs Pxs => //= x' xs IHxs /andP [? ?] /andP [+ /IHxs->] //. by rewrite andbT; apply: rr'. Qed. Lemma sub_pairwise {T : Type} (r r' : rel T) xs : subrel r r' -> pairwise r xs -> pairwise r' xs. Proof. by move=> rr'; apply/sub_in_pairwise/all_predT; apply: in2W. Qed. Lemma eq_in_pairwise {T : Type} (P : {pred T}) (r r' : rel T) : {in P &, r =2 r'} -> forall xs, all P xs -> pairwise r xs = pairwise r' xs. Proof. move=> rr' xs Pxs. by apply/idP/idP; apply/sub_in_pairwise/Pxs => ? ? ? ?; rewrite rr'. Qed. Lemma eq_pairwise {T : Type} (r r' : rel T) : r =2 r' -> pairwise r =i pairwise r'. Proof. by move=> rr' xs; apply/eq_in_pairwise/all_predT. Qed. Lemma pairwise_map {T T' : Type} (f : T' -> T) (r : rel T) xs : pairwise r (map f xs) = pairwise (relpre f r) xs. Proof. by elim: xs => //= x xs ->; rewrite all_map. Qed. Lemma pairwise_relI {T : Type} (r r' : rel T) (s : seq T) : pairwise [rel x y | r x y && r' x y] s = pairwise r s && pairwise r' s. Proof. by elim: s => //= x s ->; rewrite andbACA all_predI. Qed. Section EqPairwise. Variables (T : eqType) (r : T -> T -> bool). Implicit Types (xs ys : seq T). Lemma subseq_pairwise xs ys : subseq xs ys -> pairwise r ys -> pairwise r xs. Proof. by case/subseqP => m _ ->; apply: pairwise_mask. Qed. Lemma uniq_pairwise xs : uniq xs = pairwise [rel x y | x != y] xs. Proof. elim: xs => //= x xs ->; congr andb; rewrite -has_pred1 -all_predC. by elim: xs => //= x' xs ->; case: eqVneq. Qed. Lemma pairwise_uniq xs : irreflexive r -> pairwise r xs -> uniq xs. Proof. move=> r_irr; rewrite uniq_pairwise; apply/sub_pairwise => x y. by apply: contraTneq => ->; rewrite r_irr. Qed. Lemma pairwise_eq : antisymmetric r -> forall xs ys, pairwise r xs -> pairwise r ys -> perm_eq xs ys -> xs = ys. Proof. move=> r_asym; elim=> [|x xs IHxs] [|y ys] //=; try by move=> ? ? /perm_size. move=> /andP [r_x_xs pxs] /andP [r_y_ys pys] eq_xs_ys. move: (mem_head y ys) (mem_head x xs). rewrite -(perm_mem eq_xs_ys) [x \in _](perm_mem eq_xs_ys) !inE. case: eqVneq eq_xs_ys => /= [->|ne_xy] eq_xs_ys ys_x xs_y. by rewrite (IHxs ys) // -(perm_cons x). by case/eqP: ne_xy; apply: r_asym; rewrite (allP r_x_xs) ?(allP r_y_ys). Qed. Lemma pairwise_trans s : antisymmetric r -> pairwise r s -> {in s & &, transitive r}. Proof. move=> /(_ _ _ _)/eqP r_anti + y x z => /pairwiseP-/(_ y) ltP ys xs zs. have [-> //|neqxy] := eqVneq x y; have [-> //|neqzy] := eqVneq z y. move=> lxy lyz; move: ys xs zs lxy neqxy lyz neqzy. move=> /(nthP y)[j jlt <-] /(nthP y)[i ilt <-] /(nthP y)[k klt <-]. have [ltij|ltji|->] := ltngtP i j; last 2 first. - by move=> leij; rewrite r_anti// leij ltP. - by move=> lejj; rewrite r_anti// lejj. move=> _ _; have [ltjk|ltkj|->] := ltngtP j k; last 2 first. - by move=> lejk; rewrite r_anti// lejk ltP. - by move=> lekk; rewrite r_anti// lekk. by move=> _ _; apply: (ltP) => //; apply: ltn_trans ltjk. Qed. End EqPairwise. Arguments subseq_pairwise {T r xs ys}. Arguments uniq_pairwise {T} xs. Arguments pairwise_uniq {T r xs}. Arguments pairwise_eq {T r} r_asym {xs ys}. Section Permutations. Variable T : eqType. Implicit Types (x : T) (s t : seq T) (bs : seq (T * nat)) (acc : seq (seq T)). Fixpoint incr_tally bs x := if bs isn't b :: bs then [:: (x, 1)] else if x == b.1 then (x, b.2.+1) :: bs else b :: incr_tally bs x. Definition tally s := foldl incr_tally [::] s. Definition wf_tally := [qualify a bs : seq (T * nat) | uniq (unzip1 bs) && (0 \notin unzip2 bs)]. Definition tally_seq bs := flatten [seq nseq b.2 b.1 | b <- bs]. Local Notation tseq := tally_seq. Lemma size_tally_seq bs : size (tally_seq bs) = sumn (unzip2 bs). Proof. by rewrite size_flatten /shape -map_comp; under eq_map do rewrite /= size_nseq. Qed. Lemma tally_seqK : {in wf_tally, cancel tally_seq tally}. Proof. move=> bs /andP[]; elim: bs => [|[x [|n]] bs IHbs] //= /andP[bs'x Ubs] bs'0. rewrite inE /tseq /tally /= -[n.+1]addn1 in bs'0 *. elim: n 1 => /= [|n IHn] m; last by rewrite eqxx IHn addnS. rewrite -{}[in RHS]IHbs {Ubs bs'0}// /tally /tally_seq add0n. elim: bs bs'x [::] => [|[y n] bs IHbs] //= /[1!inE] /norP[y'x bs'x]. by elim: n => [|n IHn] bs1 /=; [rewrite IHbs | rewrite eq_sym ifN // IHn]. Qed. Lemma incr_tallyP x : {homo incr_tally^~ x : bs / bs \in wf_tally}. Proof. move=> bs /andP[]; rewrite unfold_in. elim: bs => [|[y [|n]] bs IHbs] //= /andP[bs'y Ubs] /[1!inE] /= bs'0. have [<- | y'x] /= := eqVneq y; first by rewrite bs'y Ubs. rewrite -andbA {}IHbs {Ubs bs'0}// andbT. elim: bs bs'y => [|b bs IHbs] /=; rewrite inE ?y'x // => /norP[b'y bs'y]. by case: ifP => _; rewrite /= inE negb_or ?y'x // b'y IHbs. Qed. Lemma tallyP s : tally s \is a wf_tally. Proof. rewrite /tally; set bs := [::]; have: bs \in wf_tally by []. by elim: s bs => //= x s IHs bs /(incr_tallyP x)/IHs. Qed. Lemma tallyK s : perm_eq (tally_seq (tally s)) s. Proof. rewrite -[s in perm_eq _ s]cats0 -[nil]/(tseq [::]) /tally. elim: s [::] => //= x s IHs bs; rewrite {IHs}(permPl (IHs _)). rewrite perm_sym -cat1s perm_catCA {s}perm_cat2l. elim: bs => //= b bs IHbs; case: eqP => [-> | _] //=. by rewrite -cat1s perm_catCA perm_cat2l. Qed. Lemma tallyEl s : perm_eq (unzip1 (tally s)) (undup s). Proof. have /andP[Ubs bs'0] := tallyP s; set bs := tally s in Ubs bs'0 *. rewrite uniq_perm ?undup_uniq {Ubs}// => x. rewrite mem_undup -(perm_mem (tallyK s)) -/bs. elim: bs => [|[y [|m]] bs IHbs] //= in bs'0 *. by rewrite inE IHbs // mem_cat mem_nseq. Qed. Lemma tallyE s : perm_eq (tally s) [seq (x, count_mem x s) | x <- undup s]. Proof. have /andP[Ubs _] := tallyP s; pose b := [fun s x => (x, count_mem x (tseq s))]. suffices /permPl->: perm_eq (tally s) (map (b (tally s)) (unzip1 (tally s))). congr perm_eq: (perm_map (b (tally s)) (tallyEl s)). by under eq_map do rewrite /= (permP (tallyK s)). elim: (tally s) Ubs => [|[x m] bs IH] //= /andP[bs'x /IH-IHbs {IH}]. rewrite /tseq /= -/(tseq _) count_cat count_nseq /= eqxx mul1n. rewrite (count_memPn _) ?addn0 ?perm_cons; last first. apply: contra bs'x; elim: {b IHbs}bs => //= b bs IHbs. by rewrite mem_cat mem_nseq inE andbC; case: (_ == _). congr perm_eq: IHbs; apply/eq_in_map=> y bs_y; congr (y, _). by rewrite count_cat count_nseq /= (negPf (memPnC bs'x y bs_y)). Qed. Lemma perm_tally s1 s2 : perm_eq s1 s2 -> perm_eq (tally s1) (tally s2). Proof. move=> eq_s12; apply: (@perm_trans _ [seq (x, count_mem x s2) | x <- undup s1]). by congr perm_eq: (tallyE s1); under eq_map do rewrite (permP eq_s12). by rewrite (permPr (tallyE s2)); apply/perm_map/perm_undup/(perm_mem eq_s12). Qed. Lemma perm_tally_seq bs1 bs2 : perm_eq bs1 bs2 -> perm_eq (tally_seq bs1) (tally_seq bs2). Proof. by move=> Ebs12; rewrite perm_flatten ?perm_map. Qed. Local Notation perm_tseq := perm_tally_seq. Lemma perm_count_undup s : perm_eq (flatten [seq nseq (count_mem x s) x | x <- undup s]) s. Proof. by rewrite -(permPr (tallyK s)) (permPr (perm_tseq (tallyE s))) /tseq -map_comp. Qed. Local Fixpoint cons_perms_ perms_rec (s : seq T) bs bs2 acc := if bs isn't b :: bs1 then acc else if b isn't (x, m.+1) then cons_perms_ perms_rec s bs1 bs2 acc else let acc_xs := perms_rec (x :: s) ((x, m) :: bs1 ++ bs2) acc in cons_perms_ perms_rec s bs1 (b :: bs2) acc_xs. Local Fixpoint perms_rec n s bs acc := if n isn't n.+1 then s :: acc else cons_perms_ (perms_rec n) s bs [::] acc. Local Notation cons_perms n := (cons_perms_ (perms_rec n) [::]). Definition permutations s := perms_rec (size s) [::] (tally s) [::]. Let permsP s : exists n bs, [/\ permutations s = perms_rec n [::] bs [::], size (tseq bs) == n, perm_eq (tseq bs) s & uniq (unzip1 bs)]. Proof. have /andP[Ubs _] := tallyP s; exists (size s), (tally s). by rewrite (perm_size (tallyK s)) tallyK. Qed. Local Notation bsCA := (permEl (perm_catCA _ [:: _] _)). Let cons_permsE : forall n x bs bs1 bs2, let cp := cons_perms n bs bs2 in let perms s := perms_rec n s bs1 [::] in cp (perms [:: x]) = cp [::] ++ [seq rcons t x | t <- perms [::]]. Proof. pose is_acc f := forall acc, f acc = f [::] ++ acc. (* f is accumulating. *) have cpE: forall f & forall s bs, is_acc (f s bs), is_acc (cons_perms_ f _ _ _). move=> s bs bs2 f fE acc; elim: bs => [|[x [|m]] bs IHbs] //= in s bs2 acc *. by rewrite fE IHbs catA -IHbs. have prE: is_acc (perms_rec _ _ _) by elim=> //= n IHn s bs; apply: cpE. pose has_suffix f := forall s : seq T, f s = [seq t ++ s | t <- f [::]]. suffices prEs n bs: has_suffix (fun s => perms_rec n s bs [::]). move=> n x bs bs1 bs2 /=; rewrite cpE // prEs. by under eq_map do rewrite cats1. elim: n bs => //= n IHn bs s; elim: bs [::] => [|[x [|m]] bs IHbs] //= bs1. rewrite cpE // IHbs IHn [in RHS]cpE // [in RHS]IHn map_cat -map_comp. by congr (_ ++ _); apply: eq_map => t /=; rewrite -catA. Qed. Lemma mem_permutations s t : (t \in permutations s) = perm_eq t s. Proof. have{s} [n [bs [-> Dn /permPr<- _]]] := permsP s. elim: n => [|n IHn] /= in t bs Dn *. by rewrite inE (nilP Dn); apply/eqP/perm_nilP. rewrite -[bs in tseq bs]cats0 in Dn *; have x0 : T by case: (tseq _) Dn. rewrite -[RHS](@andb_idl (last x0 t \in tseq bs)); last first. case/lastP: t {IHn} => [|t x] Dt; first by rewrite -(perm_size Dt) in Dn. by rewrite -[bs]cats0 -(perm_mem Dt) last_rcons mem_rcons mem_head. elim: bs [::] => [|[x [|m]] bs IHbs] //= bs2 in Dn *. rewrite cons_permsE -!cat_cons !mem_cat (mem_nseq m.+1) orbC andb_orl. rewrite {}IHbs ?(perm_size (perm_tseq bsCA)) //= (permPr (perm_tseq bsCA)). congr (_ || _); apply/mapP/andP=> [[t1 Dt1 ->] | [/eqP]]. by rewrite last_rcons perm_rcons perm_cons IHn in Dt1 *. case/lastP: t => [_ /perm_size//|t y]; rewrite last_rcons perm_rcons => ->. by rewrite perm_cons; exists t; rewrite ?IHn. Qed. Lemma permutations_uniq s : uniq (permutations s). Proof. have{s} [n [bs [-> Dn _ Ubs]]] := permsP s. elim: n => //= n IHn in bs Dn Ubs *; rewrite -[bs]cats0 /unzip1 in Dn Ubs. elim: bs [::] => [|[x [|m]] bs IHbs] //= bs2 in Dn Ubs *. by case/andP: Ubs => _ /IHbs->. rewrite /= cons_permsE cat_uniq has_sym andbCA andbC. rewrite {}IHbs; first 1 last; first by rewrite (perm_size (perm_tseq bsCA)). by rewrite (perm_uniq (perm_map _ bsCA)). rewrite (map_inj_uniq (rcons_injl x)) {}IHn {Dn}//=. have: x \notin unzip1 bs by apply: contraL Ubs; rewrite map_cat mem_cat => ->. move: {bs2 m Ubs}(perms_rec n _ _ _) (_ :: bs2) => ts. elim: bs => [|[y [|m]] bs IHbs] //= /[1!inE] bs2 /norP[x'y /IHbs//]. rewrite cons_permsE has_cat negb_or has_map => ->. by apply/hasPn=> t _; apply: contra x'y => /mapP[t1 _ /rcons_inj[_ ->]]. Qed. Notation perms := permutations. Lemma permutationsE s : 0 < size s -> perm_eq (perms s) [seq x :: t | x <- undup s, t <- perms (rem x s)]. Proof. move=> nt_s; apply/uniq_perm=> [||t]; first exact: permutations_uniq. apply/allpairs_uniq_dep=> [|x _|]; rewrite ?undup_uniq ?permutations_uniq //. by case=> [_ _] [x t] _ _ [-> ->]. rewrite mem_permutations; apply/idP/allpairsPdep=> [Dt | [x [t1 []]]]. rewrite -(perm_size Dt) in nt_s; case: t nt_s => // x t _ in Dt *. have s_x: x \in s by rewrite -(perm_mem Dt) mem_head. exists x, t; rewrite mem_undup mem_permutations; split=> //. by rewrite -(perm_cons x) (permPl Dt) perm_to_rem. rewrite mem_undup mem_permutations -(perm_cons x) => s_x Dt1 ->. by rewrite (permPl Dt1) perm_sym perm_to_rem. Qed. Lemma permutationsErot x s (le_x := fun t => iota 0 (index x t + 1)) : perm_eq (perms (x :: s)) [seq rot i (x :: t) | t <- perms s, i <- le_x t]. Proof. have take'x t i: i <= index x t -> i <= size t /\ x \notin take i t. move=> le_i_x; have le_i_t: i <= size t := leq_trans le_i_x (index_size x t). case: (nthP x) => // -[j lt_j_i /eqP]; rewrite size_takel // in lt_j_i. by rewrite nth_take // [_ == _](before_find x (leq_trans lt_j_i le_i_x)). pose xrot t i := rot i (x :: t); pose xrotV t := index x (rev (rot 1 t)). have xrotK t: {in le_x t, cancel (xrot t) xrotV}. move=> i; rewrite mem_iota addn1 /xrotV => /take'x[le_i_t ti'x]. rewrite -rotD ?rev_cat //= rev_cons cat_rcons index_cat mem_rev size_rev. by rewrite ifN // size_takel //= eqxx addn0. apply/uniq_perm=> [||t]; first exact: permutations_uniq. apply/allpairs_uniq_dep=> [|t _|]; rewrite ?permutations_uniq ?iota_uniq //. move=> _ _ /allpairsPdep[t [i [_ ? ->]]] /allpairsPdep[u [j [_ ? ->]]] Etu. have Eij: i = j by rewrite -(xrotK t i) // /xrot Etu xrotK. by move: Etu; rewrite Eij => /rot_inj[->]. rewrite mem_permutations; apply/esym; apply/allpairsPdep/idP=> [[u [i]] | Dt]. rewrite mem_permutations => -[Du _ /(canLR (rotK i))]; rewrite /rotr. by set j := (j in rot j _) => Dt; apply/perm_consP; exists j, u. pose r := rev (rot 1 t); pose i := index x r; pose u := rev (take i r). have r_x: x \in r by rewrite mem_rev mem_rot (perm_mem Dt) mem_head. have [v Duv]: {v | rot i (x :: u ++ v) = t}; first exists (rev (drop i.+1 r)). rewrite -rev_cat -rev_rcons -rot1_cons -cat_cons -(nth_index x r_x). by rewrite -drop_nth ?index_mem // rot_rot !rev_rot revK rotK rotrK. exists (u ++ v), i; rewrite mem_permutations -(perm_cons x) -(perm_rot i) Duv. rewrite mem_iota addn1 ltnS /= index_cat mem_rev size_rev. by have /take'x[le_i_t ti'x] := leqnn i; rewrite ifN ?size_takel ?leq_addr. Qed. Lemma size_permutations s : uniq s -> size (permutations s) = (size s)`!. Proof. move Dn: (size s) => n Us; elim: n s => [[]|n IHn s] //= in Dn Us *. rewrite (perm_size (permutationsE _)) ?Dn // undup_id // factS -Dn. rewrite -(size_iota 0 n`!) -(size_allpairs (fun=>id)) !size_allpairs_dep. by apply/congr1/eq_in_map=> x sx; rewrite size_iota IHn ?size_rem ?Dn ?rem_uniq. Qed. Lemma permutations_all_uniq s : uniq s -> all uniq (permutations s). Proof. by move=> Us; apply/allP=> t; rewrite mem_permutations => /perm_uniq->. Qed. Lemma perm_permutations s t : perm_eq s t -> perm_eq (permutations s) (permutations t). Proof. move=> Est; apply/uniq_perm; try exact: permutations_uniq. by move=> u; rewrite !mem_permutations (permPr Est). Qed. End Permutations.
Lattice.lean
/- Copyright (c) 2021 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Analysis.Normed.Group.Constructions import Mathlib.Analysis.Normed.Group.Rat import Mathlib.Analysis.Normed.Group.Uniform import Mathlib.Topology.Order.Lattice /-! # Normed lattice ordered groups Motivated by the theory of Banach Lattices, we then define `NormedLatticeAddCommGroup` as a lattice with a covariant normed group addition satisfying the solid axiom. ## Main statements We show that a normed lattice ordered group is a topological lattice with respect to the norm topology. ## References * [Meyer-Nieberg, Banach lattices][MeyerNieberg1991] ## Tags normed, lattice, ordered, group -/ /-! ### Normed lattice ordered groups Motivated by the theory of Banach Lattices, this section introduces normed lattice ordered groups. -/ section SolidNorm /-- Let `α` be an `AddCommGroup` with a `Lattice` structure. A norm on `α` is *solid* if, for `a` and `b` in `α`, with absolute values `|a|` and `|b|` respectively, `|a| ≤ |b|` implies `‖a‖ ≤ ‖b‖`. -/ class HasSolidNorm (α : Type*) [NormedAddCommGroup α] [Lattice α] : Prop where solid : ∀ ⦃x y : α⦄, |x| ≤ |y| → ‖x‖ ≤ ‖y‖ variable {α : Type*} [NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] theorem norm_le_norm_of_abs_le_abs {a b : α} (h : |a| ≤ |b|) : ‖a‖ ≤ ‖b‖ := HasSolidNorm.solid h /-- If `α` has a solid norm, then the balls centered at the origin of `α` are solid sets. -/ theorem LatticeOrderedAddCommGroup.isSolid_ball (r : ℝ) : LatticeOrderedAddCommGroup.IsSolid (Metric.ball (0 : α) r) := fun _ hx _ hxy => mem_ball_zero_iff.mpr ((HasSolidNorm.solid hxy).trans_lt (mem_ball_zero_iff.mp hx)) instance : HasSolidNorm ℝ := ⟨fun _ _ => id⟩ instance : HasSolidNorm ℚ := ⟨fun _ _ _ => by simpa only [norm, ← Rat.cast_abs, Rat.cast_le]⟩ end SolidNorm /-- Let `α` be a normed commutative group equipped with a partial order covariant with addition, with respect which `α` forms a lattice. Suppose that `α` is *solid*, that is to say, for `a` and `b` in `α`, with absolute values `|a|` and `|b|` respectively, `|a| ≤ |b|` implies `‖a‖ ≤ ‖b‖`. Then `α` is said to be a normed lattice ordered group. -/ @[deprecated "Use `[NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] [IsOrderedAddMonoid α]` instead." (since := "2025-04-10")] structure NormedLatticeAddCommGroup (α : Type*) extends NormedAddCommGroup α, Lattice α, HasSolidNorm α where add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b instance Int.hasSolidNorm : HasSolidNorm ℤ where solid x y h := by simpa [← Int.norm_cast_real, ← Int.cast_abs] using h instance Rat.hasSolidNorm : HasSolidNorm ℚ where solid x y h := by simpa [← Rat.norm_cast_real, ← Rat.cast_abs] using h variable {α : Type*} [NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] [IsOrderedAddMonoid α] open HasSolidNorm theorem dual_solid (a b : α) (h : b ⊓ -b ≤ a ⊓ -a) : ‖a‖ ≤ ‖b‖ := by apply solid rw [abs] nth_rw 1 [← neg_neg a] rw [← neg_inf] rw [abs] nth_rw 1 [← neg_neg b] rwa [← neg_inf, neg_le_neg_iff, inf_comm _ b, inf_comm _ a] -- see Note [lower instance priority] /-- Let `α` be a normed lattice ordered group, then the order dual is also a normed lattice ordered group. -/ instance (priority := 100) OrderDual.instHasSolidNorm : HasSolidNorm αᵒᵈ := { solid := dual_solid (α := α) } theorem norm_abs_eq_norm (a : α) : ‖|a|‖ = ‖a‖ := (solid (abs_abs a).le).antisymm (solid (abs_abs a).symm.le) theorem norm_inf_sub_inf_le_add_norm (a b c d : α) : ‖a ⊓ b - c ⊓ d‖ ≤ ‖a - c‖ + ‖b - d‖ := by rw [← norm_abs_eq_norm (a - c), ← norm_abs_eq_norm (b - d)] refine le_trans (solid ?_) (norm_add_le |a - c| |b - d|) rw [abs_of_nonneg (add_nonneg (abs_nonneg (a - c)) (abs_nonneg (b - d)))] calc |a ⊓ b - c ⊓ d| = |a ⊓ b - c ⊓ b + (c ⊓ b - c ⊓ d)| := by rw [sub_add_sub_cancel] _ ≤ |a ⊓ b - c ⊓ b| + |c ⊓ b - c ⊓ d| := abs_add_le _ _ _ ≤ |a - c| + |b - d| := by gcongr ?_ + ?_ · exact abs_inf_sub_inf_le_abs _ _ _ · rw [inf_comm c, inf_comm c] exact abs_inf_sub_inf_le_abs _ _ _ theorem norm_sup_sub_sup_le_add_norm (a b c d : α) : ‖a ⊔ b - c ⊔ d‖ ≤ ‖a - c‖ + ‖b - d‖ := by rw [← norm_abs_eq_norm (a - c), ← norm_abs_eq_norm (b - d)] refine le_trans (solid ?_) (norm_add_le |a - c| |b - d|) rw [abs_of_nonneg (add_nonneg (abs_nonneg (a - c)) (abs_nonneg (b - d)))] calc |a ⊔ b - c ⊔ d| = |a ⊔ b - c ⊔ b + (c ⊔ b - c ⊔ d)| := by rw [sub_add_sub_cancel] _ ≤ |a ⊔ b - c ⊔ b| + |c ⊔ b - c ⊔ d| := abs_add_le _ _ _ ≤ |a - c| + |b - d| := by gcongr ?_ + ?_ · exact abs_sup_sub_sup_le_abs _ _ _ · rw [sup_comm c, sup_comm c] exact abs_sup_sub_sup_le_abs _ _ _ theorem norm_inf_le_add (x y : α) : ‖x ⊓ y‖ ≤ ‖x‖ + ‖y‖ := by have h : ‖x ⊓ y - 0 ⊓ 0‖ ≤ ‖x - 0‖ + ‖y - 0‖ := norm_inf_sub_inf_le_add_norm x y 0 0 simpa only [inf_idem, sub_zero] using h theorem norm_sup_le_add (x y : α) : ‖x ⊔ y‖ ≤ ‖x‖ + ‖y‖ := by have h : ‖x ⊔ y - 0 ⊔ 0‖ ≤ ‖x - 0‖ + ‖y - 0‖ := norm_sup_sub_sup_le_add_norm x y 0 0 simpa only [sup_idem, sub_zero] using h -- see Note [lower instance priority] /-- Let `α` be a normed lattice ordered group. Then the infimum is jointly continuous. -/ instance (priority := 100) HasSolidNorm.continuousInf : ContinuousInf α := by refine ⟨continuous_iff_continuousAt.2 fun q => tendsto_iff_norm_sub_tendsto_zero.2 <| ?_⟩ have : ∀ p : α × α, ‖p.1 ⊓ p.2 - q.1 ⊓ q.2‖ ≤ ‖p.1 - q.1‖ + ‖p.2 - q.2‖ := fun _ => norm_inf_sub_inf_le_add_norm _ _ _ _ refine squeeze_zero (fun e => norm_nonneg _) this ?_ convert ((continuous_fst.tendsto q).sub <| tendsto_const_nhds).norm.add ((continuous_snd.tendsto q).sub <| tendsto_const_nhds).norm simp -- see Note [lower instance priority] instance (priority := 100) HasSolidNorm.continuousSup {α : Type*} [NormedAddCommGroup α] [Lattice α] [HasSolidNorm α] [IsOrderedAddMonoid α] : ContinuousSup α := OrderDual.continuousSup αᵒᵈ -- see Note [lower instance priority] /-- Let `α` be a normed lattice ordered group. Then `α` is a topological lattice in the norm topology. -/ instance (priority := 100) HasSolidNorm.toTopologicalLattice : TopologicalLattice α := TopologicalLattice.mk theorem norm_abs_sub_abs (a b : α) : ‖|a| - |b|‖ ≤ ‖a - b‖ := solid (abs_abs_sub_abs_le _ _) theorem norm_sup_sub_sup_le_norm (x y z : α) : ‖x ⊔ z - y ⊔ z‖ ≤ ‖x - y‖ := solid (abs_sup_sub_sup_le_abs x y z) theorem norm_inf_sub_inf_le_norm (x y z : α) : ‖x ⊓ z - y ⊓ z‖ ≤ ‖x - y‖ := solid (abs_inf_sub_inf_le_abs x y z) theorem lipschitzWith_sup_right (z : α) : LipschitzWith 1 fun x => x ⊔ z := LipschitzWith.of_dist_le_mul fun x y => by rw [NNReal.coe_one, one_mul, dist_eq_norm, dist_eq_norm] exact norm_sup_sub_sup_le_norm x y z lemma lipschitzWith_posPart : LipschitzWith 1 (posPart : α → α) := lipschitzWith_sup_right 0 lemma lipschitzWith_negPart : LipschitzWith 1 (negPart : α → α) := by simpa [Function.comp] using lipschitzWith_posPart.comp LipschitzWith.id.neg @[fun_prop] lemma continuous_posPart : Continuous (posPart : α → α) := lipschitzWith_posPart.continuous @[fun_prop] lemma continuous_negPart : Continuous (negPart : α → α) := lipschitzWith_negPart.continuous lemma isClosed_nonneg : IsClosed {x : α | 0 ≤ x} := by have : {x : α | 0 ≤ x} = negPart ⁻¹' {0} := by ext; simp [negPart_eq_zero] rw [this] exact isClosed_singleton.preimage continuous_negPart theorem isClosed_le_of_isClosed_nonneg {G} [AddCommGroup G] [PartialOrder G] [IsOrderedAddMonoid G] [TopologicalSpace G] [ContinuousSub G] (h : IsClosed { x : G | 0 ≤ x }) : IsClosed { p : G × G | p.fst ≤ p.snd } := by have : { p : G × G | p.fst ≤ p.snd } = (fun p : G × G => p.snd - p.fst) ⁻¹' { x : G | 0 ≤ x } := by ext1 p; simp only [sub_nonneg, Set.preimage_setOf_eq] rw [this] exact IsClosed.preimage (continuous_snd.sub continuous_fst) h -- See note [lower instance priority] instance (priority := 100) HasSolidNorm.orderClosedTopology {E} [NormedAddCommGroup E] [Lattice E] [HasSolidNorm E] [IsOrderedAddMonoid E] : OrderClosedTopology E := ⟨isClosed_le_of_isClosed_nonneg isClosed_nonneg⟩
Preserves.lean
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Sites.EqualizerSheafCondition /-! # Sheaves preserve products We prove that a presheaf which satisfies the sheaf condition with respect to certain presieves preserve "the corresponding products". ## Main results More precisely, given a presheaf `F : Cᵒᵖ ⥤ Type*`, we have: * If `F` satisfies the sheaf condition with respect to the empty sieve on the initial object of `C`, then `F` preserves terminal objects. See `preservesTerminalOfIsSheafForEmpty`. * If `F` furthermore satisfies the sheaf condition with respect to the presieve consisting of the inclusion arrows in a coproduct in `C`, then `F` preserves the corresponding product. See `preservesProductOfIsSheafFor`. * If `F` preserves a product, then it satisfies the sheaf condition with respect to the corresponding presieve of arrows. See `isSheafFor_of_preservesProduct`. -/ universe v u w namespace CategoryTheory.Presieve variable {C : Type u} [Category.{v} C] {I : C} (F : Cᵒᵖ ⥤ Type w) open Limits Opposite variable (hF : (ofArrows (X := I) Empty.elim Empty.instIsEmpty.elim).IsSheafFor F) section Terminal variable (I) in /-- If `F` is a presheaf which satisfies the sheaf condition with respect to the empty presieve on any object, then `F` takes that object to the terminal object. -/ noncomputable def isTerminal_of_isSheafFor_empty_presieve : IsTerminal (F.obj (op I)) := by refine @IsTerminal.ofUnique _ _ _ fun Y ↦ ?_ choose t h using hF (by tauto) (by tauto) exact ⟨⟨fun _ ↦ t⟩, fun a ↦ by ext; exact h.2 _ (by tauto)⟩ include hF in /-- If `F` is a presheaf which satisfies the sheaf condition with respect to the empty presieve on the initial object, then `F` preserves terminal objects. -/ lemma preservesTerminal_of_isSheaf_for_empty (hI : IsInitial I) : PreservesLimit (Functor.empty.{0} Cᵒᵖ) F := have := hI.hasInitial (preservesTerminal_of_iso F ((F.mapIso (terminalIsoIsTerminal (terminalOpOfInitial initialIsInitial)) ≪≫ (F.mapIso (initialIsoIsInitial hI).symm.op) ≪≫ (terminalIsoIsTerminal (isTerminal_of_isSheafFor_empty_presieve I F hF)).symm))) end Terminal section Product variable (hI : IsInitial I) -- This is the data of a particular disjoint coproduct in `C`. variable {α : Type*} [Small.{w} α] {X : α → C} (c : Cofan X) (hc : IsColimit c) theorem piComparison_fac : have : HasCoproduct X := ⟨⟨c, hc⟩⟩ piComparison F (fun x ↦ op (X x)) = F.map (opCoproductIsoProduct' hc (productIsProduct _)).inv ≫ Equalizer.Presieve.Arrows.forkMap F X c.inj := by have : HasCoproduct X := ⟨⟨c, hc⟩⟩ dsimp only [Equalizer.Presieve.Arrows.forkMap] have h : Pi.lift (fun i ↦ F.map (c.inj i).op) = F.map (Pi.lift (fun i ↦ (c.inj i).op)) ≫ piComparison F _ := by simp rw [h, ← Category.assoc, ← Functor.map_comp] have hh : Pi.lift (fun i ↦ (c.inj i).op) = (productIsProduct (op <| X ·)).lift c.op := by simp [Pi.lift, productIsProduct] rw [hh, ← desc_op_comp_opCoproductIsoProduct'_hom hc] simp variable [(ofArrows X c.inj).hasPullbacks] include hc in /-- If `F` preserves a particular product, then it `IsSheafFor` the corresponding presieve of arrows. -/ theorem isSheafFor_of_preservesProduct [PreservesLimit (Discrete.functor (fun x ↦ op (X x))) F] : (ofArrows X c.inj).IsSheafFor F := by rw [Equalizer.Presieve.Arrows.sheaf_condition, Limits.Types.type_equalizer_iff_unique] have : HasCoproduct X := ⟨⟨c, hc⟩⟩ have hi : IsIso (piComparison F (fun x ↦ op (X x))) := inferInstance rw [piComparison_fac (hc := hc), isIso_iff_bijective, Function.bijective_iff_existsUnique] at hi intro b _ obtain ⟨t, ht₁, ht₂⟩ := hi b refine ⟨F.map ((opCoproductIsoProduct' hc (productIsProduct _)).inv) t, ht₁, fun y hy ↦ ?_⟩ apply_fun F.map ((opCoproductIsoProduct' hc (productIsProduct _)).hom) using injective_of_mono _ simp [← FunctorToTypes.map_comp_apply, ht₂ (F.map ((opCoproductIsoProduct' hc (productIsProduct _)).hom) y) (by simp [← hy])] variable [HasInitial C] [∀ i, Mono (c.inj i)] (hd : Pairwise fun i j => IsPullback (initial.to _) (initial.to _) (c.inj i) (c.inj j)) include hd hF hI in /-- The two parallel maps in the equalizer diagram for the sheaf condition corresponding to the inclusion maps in a disjoint coproduct are equal. -/ theorem firstMap_eq_secondMap : Equalizer.Presieve.Arrows.firstMap F X c.inj = Equalizer.Presieve.Arrows.secondMap F X c.inj := by ext a ⟨i, j⟩ simp only [Equalizer.Presieve.Arrows.firstMap, Types.pi_lift_π_apply, types_comp_apply, Equalizer.Presieve.Arrows.secondMap] by_cases hi : i = j · rw [hi, Mono.right_cancellation _ _ pullback.condition] · have := preservesTerminal_of_isSheaf_for_empty F hF hI apply_fun (F.mapIso ((hd hi).isoPullback).op ≪≫ F.mapIso (terminalIsoIsTerminal (terminalOpOfInitial initialIsInitial)).symm ≪≫ (PreservesTerminal.iso F)).hom using injective_of_mono _ ext ⟨i⟩ exact i.elim include hc hd hF hI in /-- If `F` is a presheaf which `IsSheafFor` a presieve of arrows and the empty presieve, then it preserves the product corresponding to the presieve of arrows. -/ lemma preservesProduct_of_isSheafFor (hF' : (ofArrows X c.inj).IsSheafFor F) : PreservesLimit (Discrete.functor (fun x ↦ op (X x))) F := by have : HasCoproduct X := ⟨⟨c, hc⟩⟩ refine @PreservesProduct.of_iso_comparison _ _ _ _ F _ (fun x ↦ op (X x)) _ _ ?_ rw [piComparison_fac (hc := hc)] refine IsIso.comp_isIso' inferInstance ?_ rw [isIso_iff_bijective, Function.bijective_iff_existsUnique] rw [Equalizer.Presieve.Arrows.sheaf_condition, Limits.Types.type_equalizer_iff_unique] at hF' exact fun b ↦ hF' b (congr_fun (firstMap_eq_secondMap F hF hI c hd) b) include hc hd hF hI in theorem isSheafFor_iff_preservesProduct : (ofArrows X c.inj).IsSheafFor F ↔ PreservesLimit (Discrete.functor (fun x ↦ op (X x))) F := ⟨fun hF' ↦ preservesProduct_of_isSheafFor _ hF hI c hc hd hF', fun _ ↦ isSheafFor_of_preservesProduct F c hc⟩ end Product end CategoryTheory.Presieve
Localization.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.RingTheory.Localization.AsSubring import Mathlib.RingTheory.Spectrum.Maximal.Basic import Mathlib.RingTheory.Spectrum.Prime.RingHom /-! # Maximal spectrum of a commutative (semi)ring Localization results. -/ noncomputable section variable (R S P : Type*) [CommSemiring R] [CommSemiring S] [CommSemiring P] namespace MaximalSpectrum variable {R} open PrimeSpectrum Set variable (R : Type*) variable [CommRing R] [IsDomain R] (K : Type*) [Field K] [Algebra R K] [IsFractionRing R K] /-- An integral domain is equal to the intersection of its localizations at all its maximal ideals viewed as subalgebras of its field of fractions. -/ theorem iInf_localization_eq_bot : (⨅ v : MaximalSpectrum R, Localization.subalgebra.ofField K _ v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by ext x rw [Algebra.mem_bot, Algebra.mem_iInf] constructor · contrapose intro hrange hlocal let denom : Ideal R := (1 : Submodule R K).comap (LinearMap.toSpanSingleton R K x) have hdenom : (1 : R) ∉ denom := by simpa [denom] using hrange rcases denom.exists_le_maximal (denom.ne_top_iff_one.mpr hdenom) with ⟨max, hmax, hle⟩ rcases hlocal ⟨max, hmax⟩ with ⟨n, d, hd, rfl⟩ exact hd (hle ⟨n, by simp [Algebra.smul_def, mul_left_comm, mul_inv_cancel₀ <| (map_ne_zero_iff _ <| IsFractionRing.injective R K).mpr fun h ↦ hd (h ▸ max.zero_mem :)]⟩) · rintro ⟨y, rfl⟩ ⟨v, hv⟩ exact ⟨y, 1, v.ne_top_iff_one.mp hv.ne_top, by rw [map_one, inv_one, mul_one]⟩ end MaximalSpectrum namespace PrimeSpectrum variable (R : Type*) variable [CommRing R] [IsDomain R] (K : Type*) [Field K] [Algebra R K] [IsFractionRing R K] /-- An integral domain is equal to the intersection of its localizations at all its prime ideals viewed as subalgebras of its field of fractions. -/ theorem iInf_localization_eq_bot : ⨅ v : PrimeSpectrum R, Localization.subalgebra.ofField K _ (v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by refine bot_unique (.trans (fun _ ↦ ?_) (MaximalSpectrum.iInf_localization_eq_bot R K).le) simpa only [Algebra.mem_iInf] using fun hx ⟨v, hv⟩ ↦ hx ⟨v, hv.isPrime⟩ end PrimeSpectrum namespace MaximalSpectrum /-- The product of localizations at all maximal ideals of a commutative semiring. -/ abbrev PiLocalization : Type _ := Π I : MaximalSpectrum R, Localization.AtPrime I.1 /-- The canonical ring homomorphism from a commutative semiring to the product of its localizations at all maximal ideals. It is always injective. -/ def toPiLocalization : R →+* PiLocalization R := algebraMap R _ theorem toPiLocalization_injective : Function.Injective (toPiLocalization R) := fun r r' eq ↦ by rw [← one_mul r, ← one_mul r'] by_contra ne have ⟨I, mI, hI⟩ := (Module.eqIdeal R r r').exists_le_maximal ((Ideal.ne_top_iff_one _).mpr ne) have ⟨s, hs⟩ := (IsLocalization.eq_iff_exists I.primeCompl _).mp (congr_fun eq ⟨I, mI⟩) exact s.2 (hI hs) theorem toPiLocalization_apply_apply {r I} : toPiLocalization R r I = algebraMap R _ r := rfl variable {R S} (f : R →+* S) (g : S →+* P) (hf : Function.Bijective f) (hg : Function.Bijective g) /-- Functoriality of `PiLocalization` but restricted to bijective ring homs. If R and S are commutative rings, surjectivity would be enough. -/ noncomputable def mapPiLocalization : PiLocalization R →+* PiLocalization S := Pi.ringHom fun I ↦ (Localization.localRingHom _ _ f rfl).comp <| Pi.evalRingHom _ (⟨_, I.2.comap_bijective f hf⟩ : MaximalSpectrum R) theorem mapPiLocalization_naturality : (mapPiLocalization f hf).comp (toPiLocalization R) = (toPiLocalization S).comp f := by ext r I change Localization.localRingHom _ _ _ rfl (algebraMap _ _ r) = algebraMap _ _ (f r) simp_rw [← IsLocalization.mk'_one (M := (I.1.comap f).primeCompl), Localization.localRingHom_mk', ← IsLocalization.mk'_one (M := I.1.primeCompl), Submonoid.coe_one, map_one f] rfl theorem mapPiLocalization_id : mapPiLocalization (.id R) Function.bijective_id = .id _ := RingHom.ext fun _ ↦ funext fun _ ↦ congr($(Localization.localRingHom_id _) _) theorem mapPiLocalization_comp : mapPiLocalization (g.comp f) (hg.comp hf) = (mapPiLocalization g hg).comp (mapPiLocalization f hf) := RingHom.ext fun _ ↦ funext fun _ ↦ congr($(Localization.localRingHom_comp _ _ _ _ rfl _ rfl) _) theorem mapPiLocalization_bijective : Function.Bijective (mapPiLocalization f hf) := by let f := RingEquiv.ofBijective f hf let e := RingEquiv.ofRingHom (mapPiLocalization f hf) (mapPiLocalization (f.symm : S →+* R) f.symm.bijective) ?_ ?_ · exact e.bijective · rw [← mapPiLocalization_comp] simp_rw [RingEquiv.comp_symm, mapPiLocalization_id] · rw [← mapPiLocalization_comp] simp_rw [RingEquiv.symm_comp, mapPiLocalization_id] section Pi variable {ι} (R : ι → Type*) [∀ i, CommSemiring (R i)] [∀ i, Nontrivial (R i)] theorem toPiLocalization_not_surjective_of_infinite [Infinite ι] : ¬ Function.Surjective (toPiLocalization (Π i, R i)) := fun surj ↦ by classical have ⟨J, max, notMem⟩ := PrimeSpectrum.exists_maximal_notMem_range_sigmaToPi_of_infinite R obtain ⟨r, hr⟩ := surj (Function.update 0 ⟨J, max⟩ 1) have : r = 0 := funext fun i ↦ toPiLocalization_injective _ <| funext fun I ↦ by replace hr := congr_fun hr ⟨_, I.2.comap_piEvalRingHom⟩ dsimp only [toPiLocalization_apply_apply, Subtype.coe_mk] at hr simp_rw [toPiLocalization_apply_apply, ← Localization.AtPrime.mapPiEvalRingHom_algebraMap_apply, hr] rw [Function.update_of_ne]; · simp_rw [Pi.zero_apply, map_zero] exact fun h ↦ notMem ⟨⟨i, I.1, I.2.isPrime⟩, PrimeSpectrum.ext congr($h.1)⟩ replace hr := congr_fun hr ⟨J, max⟩ rw [this, map_zero, Function.update_self] at hr exact zero_ne_one hr variable {R} theorem finite_of_toPiLocalization_pi_surjective (h : Function.Surjective (toPiLocalization (Π i, R i))) : Finite ι := by contrapose h; rw [not_finite_iff_infinite] at h exact toPiLocalization_not_surjective_of_infinite _ end Pi theorem finite_of_toPiLocalization_surjective (surj : Function.Surjective (toPiLocalization R)) : Finite (MaximalSpectrum R) := by replace surj := mapPiLocalization_bijective _ ⟨toPiLocalization_injective R, surj⟩ |>.2.comp surj rw [← RingHom.coe_comp, mapPiLocalization_naturality, RingHom.coe_comp] at surj exact finite_of_toPiLocalization_pi_surjective surj.of_comp end MaximalSpectrum namespace PrimeSpectrum /-- The product of localizations at all prime ideals of a commutative semiring. -/ abbrev PiLocalization : Type _ := Π p : PrimeSpectrum R, Localization p.asIdeal.primeCompl /-- The canonical ring homomorphism from a commutative semiring to the product of its localizations at all prime ideals. It is always injective. -/ def toPiLocalization : R →+* PiLocalization R := algebraMap R _ theorem toPiLocalization_injective : Function.Injective (toPiLocalization R) := fun _ _ eq ↦ MaximalSpectrum.toPiLocalization_injective R <| funext fun I ↦ congr_fun eq I.toPrimeSpectrum /-- The projection from the product of localizations at primes to the product of localizations at maximal ideals. -/ def piLocalizationToMaximal : PiLocalization R →+* MaximalSpectrum.PiLocalization R := Pi.ringHom fun I ↦ Pi.evalRingHom _ I.toPrimeSpectrum open scoped Classical in theorem piLocalizationToMaximal_surjective : Function.Surjective (piLocalizationToMaximal R) := fun r ↦ ⟨fun I ↦ if h : I.1.IsMaximal then r ⟨_, h⟩ else 0, funext fun _ ↦ dif_pos _⟩ variable {R} /-- If R has Krull dimension ≤ 0, then `piLocalizationToIsMaximal R` is an isomorphism. -/ def piLocalizationToMaximalEquiv (h : ∀ I : Ideal R, I.IsPrime → I.IsMaximal) : PiLocalization R ≃+* MaximalSpectrum.PiLocalization R where __ := piLocalizationToMaximal R invFun := Pi.ringHom fun I ↦ Pi.evalRingHom _ (⟨_, h _ I.2⟩ : MaximalSpectrum R) theorem piLocalizationToMaximal_bijective (h : ∀ I : Ideal R, I.IsPrime → I.IsMaximal) : Function.Bijective (piLocalizationToMaximal R) := (piLocalizationToMaximalEquiv h).bijective theorem piLocalizationToMaximal_comp_toPiLocalization : (piLocalizationToMaximal R).comp (toPiLocalization R) = MaximalSpectrum.toPiLocalization R := rfl variable {S} theorem isMaximal_of_toPiLocalization_surjective (surj : Function.Surjective (toPiLocalization R)) (I : PrimeSpectrum R) : I.1.IsMaximal := by classical have ⟨J, max, le⟩ := I.1.exists_le_maximal I.2.ne_top obtain ⟨r, hr⟩ := surj (Function.update 0 ⟨J, max.isPrime⟩ 1) by_contra h have hJ : algebraMap _ _ r = _ := (congr_fun hr _).trans (Function.update_self ..) have hI : algebraMap _ _ r = _ := congr_fun hr I rw [← IsLocalization.lift_eq (M := J.primeCompl) (S := Localization J.primeCompl), hJ, map_one, Function.update_of_ne] at hI · exact one_ne_zero hI · intro eq; have : I.1 = J := congr_arg (·.1) eq; exact h (this ▸ max) · exact fun ⟨s, hs⟩ ↦ IsLocalization.map_units (M := I.1.primeCompl) _ ⟨s, fun h ↦ hs (le h)⟩ variable (f : R →+* S) /-- A ring homomorphism induces a homomorphism between the products of localizations at primes. -/ noncomputable def mapPiLocalization : PiLocalization R →+* PiLocalization S := Pi.ringHom fun I ↦ (Localization.localRingHom _ I.1 f rfl).comp (Pi.evalRingHom _ (f.specComap I)) theorem mapPiLocalization_naturality : (mapPiLocalization f).comp (toPiLocalization R) = (toPiLocalization S).comp f := by ext r I change Localization.localRingHom _ _ _ rfl (algebraMap _ _ r) = algebraMap _ _ (f r) simp_rw [← IsLocalization.mk'_one (M := (I.1.comap f).primeCompl), Localization.localRingHom_mk', ← IsLocalization.mk'_one (M := I.1.primeCompl), Submonoid.coe_one, map_one f] rfl theorem mapPiLocalization_id : mapPiLocalization (.id R) = .id _ := by ext; exact congr($(Localization.localRingHom_id _) _) theorem mapPiLocalization_comp (g : S →+* P) : mapPiLocalization (g.comp f) = (mapPiLocalization g).comp (mapPiLocalization f) := by ext; exact congr($(Localization.localRingHom_comp _ _ _ _ rfl _ rfl) _) theorem mapPiLocalization_bijective (hf : Function.Bijective f) : Function.Bijective (mapPiLocalization f) := by let f := RingEquiv.ofBijective f hf let e := RingEquiv.ofRingHom (mapPiLocalization (f : R →+* S)) (mapPiLocalization f.symm) ?_ ?_ · exact e.bijective · rw [← mapPiLocalization_comp, RingEquiv.comp_symm, mapPiLocalization_id] · rw [← mapPiLocalization_comp, RingEquiv.symm_comp, mapPiLocalization_id] section Pi variable {ι} (R : ι → Type*) [∀ i, CommSemiring (R i)] [∀ i, Nontrivial (R i)] theorem toPiLocalization_not_surjective_of_infinite [Infinite ι] : ¬ Function.Surjective (toPiLocalization (Π i, R i)) := fun surj ↦ MaximalSpectrum.toPiLocalization_not_surjective_of_infinite R <| by rw [← piLocalizationToMaximal_comp_toPiLocalization] exact (piLocalizationToMaximal_surjective _).comp surj variable {R} theorem finite_of_toPiLocalization_pi_surjective (h : Function.Surjective (toPiLocalization (Π i, R i))) : Finite ι := by contrapose h; rw [not_finite_iff_infinite] at h exact toPiLocalization_not_surjective_of_infinite _ end Pi theorem finite_of_toPiLocalization_surjective (surj : Function.Surjective (toPiLocalization R)) : Finite (PrimeSpectrum R) := by replace surj := (mapPiLocalization_bijective _ ⟨toPiLocalization_injective R, surj⟩).2.comp surj rw [← RingHom.coe_comp, mapPiLocalization_naturality, RingHom.coe_comp] at surj exact finite_of_toPiLocalization_pi_surjective surj.of_comp end PrimeSpectrum
MonoidAlgebra.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.RingTheory.Bialgebra.MonoidAlgebra import Mathlib.RingTheory.HopfAlgebra.Basic /-! # The Hopf algebra structure on group algebras Given a group `G`, a commutative semiring `R` and an `R`-Hopf algebra `A`, this file collects results about the `R`-Hopf algebra instance on `A[G]`, building upon results in `Mathlib/RingTheory/Bialgebra/MonoidAlgebra.lean` about the bialgebra structure. ## Main definitions * `(Add)MonoidAlgebra.instHopfAlgebra`: the `R`-Hopf algebra structure on `A[G]` when `G` is an (add) group and `A` is an `R`-Hopf algebra. * `LaurentPolynomial.instHopfAlgebra`: the `R`-Hopf algebra structure on the Laurent polynomials `A[T;T⁻¹]` when `A` is an `R`-Hopf algebra. When `A = R` this corresponds to the fact that `𝔾ₘ/R` is a group scheme. -/ noncomputable section open HopfAlgebra namespace MonoidAlgebra variable {R A : Type*} [CommSemiring R] [Semiring A] [HopfAlgebra R A] variable {G : Type*} [Group G] variable (R A G) in instance instHopfAlgebraStruct : HopfAlgebraStruct R (MonoidAlgebra A G) where antipode := Finsupp.lsum R fun g => Finsupp.lsingle g⁻¹ ∘ₗ antipode R @[simp] lemma antipode_single (g : G) (a : A) : antipode R (single g a) = single g⁻¹ (antipode R a) := by simp [MonoidAlgebra, antipode] open Coalgebra in instance instHopfAlgebra : HopfAlgebra R (MonoidAlgebra A G) where mul_antipode_rTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq] using congr(lsingle (R := R) (1 : G) $(sum_antipode_mul_eq_algebraMap_counit (ℛ R b))) mul_antipode_lTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq] using congr(lsingle (R := R) (1 : G) $(sum_mul_antipode_eq_algebraMap_counit (ℛ R b))) end MonoidAlgebra namespace AddMonoidAlgebra variable {R A : Type*} [CommSemiring R] [Semiring A] [HopfAlgebra R A] variable {G : Type*} [AddGroup G] variable (R A G) in instance instHopfAlgebraStruct : HopfAlgebraStruct R A[G] where antipode := Finsupp.lsum R fun g => Finsupp.lsingle (-g) ∘ₗ antipode R @[simp] lemma antipode_single (g : G) (a : A) : antipode R (single g a) = single (-g) (antipode R a) := by simp [AddMonoidAlgebra, antipode] open Coalgebra in instance instHopfAlgebra : HopfAlgebra R A[G] where mul_antipode_rTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq, single_mul_single] using congr(lsingle (R := R) (0 : G) $(sum_antipode_mul_eq_algebraMap_counit (ℛ R b))) mul_antipode_lTensor_comul := by ext a b : 2 simpa [← (ℛ R b).eq, single_mul_single] using congr(lsingle (R := R) (0 : G) $(sum_mul_antipode_eq_algebraMap_counit (ℛ R b))) end AddMonoidAlgebra namespace LaurentPolynomial open Finsupp variable (R A : Type*) [CommSemiring R] [Semiring A] [HopfAlgebra R A] instance instHopfAlgebra : HopfAlgebra R A[T;T⁻¹] := inferInstanceAs (HopfAlgebra R <| AddMonoidAlgebra A ℤ) variable {R A} @[simp] theorem antipode_C (a : A) : HopfAlgebra.antipode R (C a) = C (HopfAlgebra.antipode R a) := by rw [← single_eq_C, AddMonoidAlgebra.antipode_single] simp @[simp] theorem antipode_T (n : ℤ) : HopfAlgebra.antipode R (T n : A[T;T⁻¹]) = T (-n) := by unfold T rw [AddMonoidAlgebra.antipode_single] simp only [HopfAlgebra.antipode_one, single_eq_C_mul_T, map_one, one_mul] @[simp] theorem antipode_C_mul_T (a : A) (n : ℤ) : HopfAlgebra.antipode R (C a * T n) = C (HopfAlgebra.antipode R a) * T (-n) := by simp [← single_eq_C_mul_T] end LaurentPolynomial
Coloring.lean
/- Copyright (c) 2021 Arthur Paulino. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arthur Paulino, Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Clique import Mathlib.Data.ENat.Lattice import Mathlib.Data.Nat.Lattice import Mathlib.Data.Setoid.Partition import Mathlib.Order.Antichain import Mathlib.Data.Nat.Cast.Order.Ring /-! # Graph Coloring This module defines colorings of simple graphs (also known as proper colorings in the literature). A graph coloring is the attribution of "colors" to all of its vertices such that adjacent vertices have different colors. A coloring can be represented as a homomorphism into a complete graph, whose vertices represent the colors. ## Main definitions * `G.Coloring α` is the type of `α`-colorings of a simple graph `G`, with `α` being the set of available colors. The type is defined to be homomorphisms from `G` into the complete graph on `α`, and colorings have a coercion to `V → α`. * `G.Colorable n` is the proposition that `G` is `n`-colorable, which is whether there exists a coloring with at most *n* colors. * `G.chromaticNumber` is the minimal `n` such that `G` is `n`-colorable, or `⊤` if it cannot be colored with finitely many colors. (Cardinal-valued chromatic numbers are more niche, so we stick to `ℕ∞`.) We write `G.chromaticNumber ≠ ⊤` to mean a graph is colorable with finitely many colors. * `C.colorClass c` is the set of vertices colored by `c : α` in the coloring `C : G.Coloring α`. * `C.colorClasses` is the set containing all color classes. ## TODO * Gather material from: * https://github.com/leanprover-community/mathlib/blob/simple_graph_matching/src/combinatorics/simple_graph/coloring.lean * https://github.com/kmill/lean-graphcoloring/blob/master/src/graph.lean * Trees * Planar graphs * Chromatic polynomials * develop API for partial colorings, likely as colorings of subgraphs (`H.coe.Coloring α`) -/ assert_not_exists Field open Fintype Function universe u v namespace SimpleGraph variable {V : Type u} (G : SimpleGraph V) {n : ℕ} /-- An `α`-coloring of a simple graph `G` is a homomorphism of `G` into the complete graph on `α`. This is also known as a proper coloring. -/ abbrev Coloring (α : Type v) := G →g completeGraph α variable {G} variable {α β : Type*} (C : G.Coloring α) theorem Coloring.valid {v w : V} (h : G.Adj v w) : C v ≠ C w := C.map_rel h /-- Construct a term of `SimpleGraph.Coloring` using a function that assigns vertices to colors and a proof that it is as proper coloring. (Note: this is a definitionally the constructor for `SimpleGraph.Hom`, but with a syntactically better proper coloring hypothesis.) -/ @[match_pattern] def Coloring.mk (color : V → α) (valid : ∀ {v w : V}, G.Adj v w → color v ≠ color w) : G.Coloring α := ⟨color, @valid⟩ /-- The color class of a given color. -/ def Coloring.colorClass (c : α) : Set V := { v : V | C v = c } /-- The set containing all color classes. -/ def Coloring.colorClasses : Set (Set V) := (Setoid.ker C).classes theorem Coloring.mem_colorClass (v : V) : v ∈ C.colorClass (C v) := rfl theorem Coloring.colorClasses_isPartition : Setoid.IsPartition C.colorClasses := Setoid.isPartition_classes (Setoid.ker C) theorem Coloring.mem_colorClasses {v : V} : C.colorClass (C v) ∈ C.colorClasses := ⟨v, rfl⟩ theorem Coloring.colorClasses_finite [Finite α] : C.colorClasses.Finite := Setoid.finite_classes_ker _ theorem Coloring.card_colorClasses_le [Fintype α] [Fintype C.colorClasses] : Fintype.card C.colorClasses ≤ Fintype.card α := by simp only [colorClasses] convert Setoid.card_classes_ker_le C theorem Coloring.not_adj_of_mem_colorClass {c : α} {v w : V} (hv : v ∈ C.colorClass c) (hw : w ∈ C.colorClass c) : ¬G.Adj v w := fun h => C.valid h (Eq.trans hv (Eq.symm hw)) theorem Coloring.color_classes_independent (c : α) : IsAntichain G.Adj (C.colorClass c) := fun _ hv _ hw _ => C.not_adj_of_mem_colorClass hv hw -- TODO make this computable noncomputable instance [Fintype V] [Fintype α] : Fintype (Coloring G α) := by classical change Fintype (RelHom G.Adj (completeGraph α).Adj) apply Fintype.ofInjective _ RelHom.coe_fn_injective variable (G) /-- Whether a graph can be colored by at most `n` colors. -/ def Colorable (n : ℕ) : Prop := Nonempty (G.Coloring (Fin n)) /-- The coloring of an empty graph. -/ def coloringOfIsEmpty [IsEmpty V] : G.Coloring α := Coloring.mk isEmptyElim fun {v} => isEmptyElim v theorem colorable_of_isEmpty [IsEmpty V] (n : ℕ) : G.Colorable n := ⟨G.coloringOfIsEmpty⟩ theorem isEmpty_of_colorable_zero (h : G.Colorable 0) : IsEmpty V := by constructor intro v obtain ⟨i, hi⟩ := h.some v exact Nat.not_lt_zero _ hi @[simp] lemma colorable_zero_iff : G.Colorable 0 ↔ IsEmpty V := ⟨G.isEmpty_of_colorable_zero, fun _ ↦ G.colorable_of_isEmpty 0⟩ /-- The "tautological" coloring of a graph, using the vertices of the graph as colors. -/ def selfColoring : G.Coloring V := Coloring.mk id fun {_ _} => G.ne_of_adj /-- The chromatic number of a graph is the minimal number of colors needed to color it. This is `⊤` (infinity) iff `G` isn't colorable with finitely many colors. If `G` is colorable, then `ENat.toNat G.chromaticNumber` is the `ℕ`-valued chromatic number. -/ noncomputable def chromaticNumber : ℕ∞ := ⨅ n ∈ setOf G.Colorable, (n : ℕ∞) lemma chromaticNumber_eq_biInf {G : SimpleGraph V} : G.chromaticNumber = ⨅ n ∈ setOf G.Colorable, (n : ℕ∞) := rfl lemma chromaticNumber_eq_iInf {G : SimpleGraph V} : G.chromaticNumber = ⨅ n : {m | G.Colorable m}, (n : ℕ∞) := by rw [chromaticNumber, iInf_subtype] lemma Colorable.chromaticNumber_eq_sInf {G : SimpleGraph V} {n} (h : G.Colorable n) : G.chromaticNumber = sInf {n' : ℕ | G.Colorable n'} := by rw [ENat.coe_sInf, chromaticNumber] exact ⟨_, h⟩ /-- Given an embedding, there is an induced embedding of colorings. -/ def recolorOfEmbedding {α β : Type*} (f : α ↪ β) : G.Coloring α ↪ G.Coloring β where toFun C := (Embedding.completeGraph f).toHom.comp C inj' := by -- this was strangely painful; seems like missing lemmas about embeddings intro C C' h dsimp only at h ext v apply (Embedding.completeGraph f).inj' change ((Embedding.completeGraph f).toHom.comp C) v = _ rw [h] rfl @[simp] lemma coe_recolorOfEmbedding (f : α ↪ β) : ⇑(G.recolorOfEmbedding f) = (Embedding.completeGraph f).toHom.comp := rfl /-- Given an equivalence, there is an induced equivalence between colorings. -/ def recolorOfEquiv {α β : Type*} (f : α ≃ β) : G.Coloring α ≃ G.Coloring β where toFun := G.recolorOfEmbedding f.toEmbedding invFun := G.recolorOfEmbedding f.symm.toEmbedding left_inv C := by ext v apply Equiv.symm_apply_apply right_inv C := by ext v apply Equiv.apply_symm_apply @[simp] lemma coe_recolorOfEquiv (f : α ≃ β) : ⇑(G.recolorOfEquiv f) = (Embedding.completeGraph f).toHom.comp := rfl /-- There is a noncomputable embedding of `α`-colorings to `β`-colorings if `β` has at least as large a cardinality as `α`. -/ noncomputable def recolorOfCardLE {α β : Type*} [Fintype α] [Fintype β] (hn : Fintype.card α ≤ Fintype.card β) : G.Coloring α ↪ G.Coloring β := G.recolorOfEmbedding <| (Function.Embedding.nonempty_of_card_le hn).some @[simp] lemma coe_recolorOfCardLE [Fintype α] [Fintype β] (hαβ : card α ≤ card β) : ⇑(G.recolorOfCardLE hαβ) = (Embedding.completeGraph (Embedding.nonempty_of_card_le hαβ).some).toHom.comp := rfl variable {G} theorem Colorable.mono {n m : ℕ} (h : n ≤ m) (hc : G.Colorable n) : G.Colorable m := ⟨G.recolorOfCardLE (by simp [h]) hc.some⟩ theorem Coloring.colorable [Fintype α] (C : G.Coloring α) : G.Colorable (Fintype.card α) := ⟨G.recolorOfCardLE (by simp) C⟩ theorem colorable_of_fintype (G : SimpleGraph V) [Fintype V] : G.Colorable (Fintype.card V) := G.selfColoring.colorable /-- Noncomputably get a coloring from colorability. -/ noncomputable def Colorable.toColoring [Fintype α] {n : ℕ} (hc : G.Colorable n) (hn : n ≤ Fintype.card α) : G.Coloring α := by rw [← Fintype.card_fin n] at hn exact G.recolorOfCardLE hn hc.some theorem Colorable.of_embedding {V' : Type*} {G' : SimpleGraph V'} (f : G ↪g G') {n : ℕ} (h : G'.Colorable n) : G.Colorable n := ⟨(h.toColoring (by simp)).comp f⟩ theorem colorable_iff_exists_bdd_nat_coloring (n : ℕ) : G.Colorable n ↔ ∃ C : G.Coloring ℕ, ∀ v, C v < n := by constructor · rintro hc have C : G.Coloring (Fin n) := hc.toColoring (by simp) let f := Embedding.completeGraph (@Fin.valEmbedding n) use f.toHom.comp C intro v exact Fin.is_lt (C.1 v) · rintro ⟨C, Cf⟩ refine ⟨Coloring.mk ?_ ?_⟩ · exact fun v => ⟨C v, Cf v⟩ · rintro v w hvw simp only [Fin.mk_eq_mk, Ne] exact C.valid hvw theorem colorable_set_nonempty_of_colorable {n : ℕ} (hc : G.Colorable n) : { n : ℕ | G.Colorable n }.Nonempty := ⟨n, hc⟩ theorem chromaticNumber_bddBelow : BddBelow { n : ℕ | G.Colorable n } := ⟨0, fun _ _ => zero_le _⟩ theorem Colorable.chromaticNumber_le {n : ℕ} (hc : G.Colorable n) : G.chromaticNumber ≤ n := by rw [hc.chromaticNumber_eq_sInf] norm_cast apply csInf_le chromaticNumber_bddBelow exact hc theorem chromaticNumber_ne_top_iff_exists : G.chromaticNumber ≠ ⊤ ↔ ∃ n, G.Colorable n := by rw [chromaticNumber] convert_to ⨅ n : {m | G.Colorable m}, (n : ℕ∞) ≠ ⊤ ↔ _ · rw [iInf_subtype] rw [← lt_top_iff_ne_top, ENat.iInf_coe_lt_top] simp theorem chromaticNumber_le_iff_colorable {n : ℕ} : G.chromaticNumber ≤ n ↔ G.Colorable n := by refine ⟨fun h ↦ ?_, Colorable.chromaticNumber_le⟩ have : G.chromaticNumber ≠ ⊤ := (trans h (WithTop.coe_lt_top n)).ne rw [chromaticNumber_ne_top_iff_exists] at this obtain ⟨m, hm⟩ := this rw [hm.chromaticNumber_eq_sInf, Nat.cast_le] at h have := Nat.sInf_mem (⟨m, hm⟩ : {n' | G.Colorable n'}.Nonempty) rw [Set.mem_setOf_eq] at this exact this.mono h theorem colorable_chromaticNumber {m : ℕ} (hc : G.Colorable m) : G.Colorable (ENat.toNat G.chromaticNumber) := by classical rw [hc.chromaticNumber_eq_sInf, Nat.sInf_def] · apply Nat.find_spec · exact colorable_set_nonempty_of_colorable hc theorem colorable_chromaticNumber_of_fintype (G : SimpleGraph V) [Finite V] : G.Colorable (ENat.toNat G.chromaticNumber) := by cases nonempty_fintype V exact colorable_chromaticNumber G.colorable_of_fintype theorem chromaticNumber_le_one_of_subsingleton (G : SimpleGraph V) [Subsingleton V] : G.chromaticNumber ≤ 1 := by rw [← Nat.cast_one, chromaticNumber_le_iff_colorable] refine ⟨Coloring.mk (fun _ => 0) ?_⟩ intros v w cases Subsingleton.elim v w simp theorem chromaticNumber_eq_zero_of_isempty (G : SimpleGraph V) [IsEmpty V] : G.chromaticNumber = 0 := by rw [← nonpos_iff_eq_zero, ← Nat.cast_zero, chromaticNumber_le_iff_colorable] apply colorable_of_isEmpty theorem isEmpty_of_chromaticNumber_eq_zero (G : SimpleGraph V) [Finite V] (h : G.chromaticNumber = 0) : IsEmpty V := by have h' := G.colorable_chromaticNumber_of_fintype rw [h] at h' exact G.isEmpty_of_colorable_zero h' theorem chromaticNumber_pos [Nonempty V] {n : ℕ} (hc : G.Colorable n) : 0 < G.chromaticNumber := by rw [hc.chromaticNumber_eq_sInf, Nat.cast_pos] apply le_csInf (colorable_set_nonempty_of_colorable hc) intro m hm by_contra h' simp only [not_le] at h' obtain ⟨i, hi⟩ := hm.some (Classical.arbitrary V) have h₁ : i < 0 := lt_of_lt_of_le hi (Nat.le_of_lt_succ h') exact Nat.not_lt_zero _ h₁ theorem colorable_of_chromaticNumber_ne_top (h : G.chromaticNumber ≠ ⊤) : G.Colorable (ENat.toNat G.chromaticNumber) := by rw [chromaticNumber_ne_top_iff_exists] at h obtain ⟨n, hn⟩ := h exact colorable_chromaticNumber hn theorem Colorable.mono_left {G' : SimpleGraph V} (h : G ≤ G') {n : ℕ} (hc : G'.Colorable n) : G.Colorable n := ⟨hc.some.comp (.ofLE h)⟩ theorem chromaticNumber_le_of_forall_imp {V' : Type*} {G' : SimpleGraph V'} (h : ∀ n, G'.Colorable n → G.Colorable n) : G.chromaticNumber ≤ G'.chromaticNumber := by rw [chromaticNumber, chromaticNumber] simp only [Set.mem_setOf_eq, le_iInf_iff] intro m hc have := h _ hc rw [← chromaticNumber_le_iff_colorable] at this exact this theorem chromaticNumber_mono (G' : SimpleGraph V) (h : G ≤ G') : G.chromaticNumber ≤ G'.chromaticNumber := chromaticNumber_le_of_forall_imp fun _ => Colorable.mono_left h theorem chromaticNumber_mono_of_embedding {V' : Type*} {G' : SimpleGraph V'} (f : G ↪g G') : G.chromaticNumber ≤ G'.chromaticNumber := chromaticNumber_le_of_forall_imp fun _ => Colorable.of_embedding f lemma card_le_chromaticNumber_iff_forall_surjective [Fintype α] : card α ≤ G.chromaticNumber ↔ ∀ C : G.Coloring α, Surjective C := by refine ⟨fun h C ↦ ?_, fun h ↦ ?_⟩ · rw [C.colorable.chromaticNumber_eq_sInf, Nat.cast_le] at h intro i by_contra! hi let D : G.Coloring {a // a ≠ i} := ⟨fun v ↦ ⟨C v, hi v⟩, (C.valid · <| congr_arg Subtype.val ·)⟩ classical exact Nat.notMem_of_lt_sInf ((Nat.sub_one_lt_of_lt <| card_pos_iff.2 ⟨i⟩).trans_le h) ⟨G.recolorOfEquiv (equivOfCardEq <| by simp) D⟩ · simp only [chromaticNumber, Set.mem_setOf_eq, le_iInf_iff, Nat.cast_le] rintro i ⟨C⟩ contrapose! h refine ⟨G.recolorOfCardLE (by simpa using h.le) C, fun hC ↦ ?_⟩ dsimp at hC simpa [h.not_ge] using Fintype.card_le_of_surjective _ hC.of_comp lemma le_chromaticNumber_iff_forall_surjective : n ≤ G.chromaticNumber ↔ ∀ C : G.Coloring (Fin n), Surjective C := by simp [← card_le_chromaticNumber_iff_forall_surjective] lemma chromaticNumber_eq_card_iff_forall_surjective [Fintype α] (hG : G.Colorable (card α)) : G.chromaticNumber = card α ↔ ∀ C : G.Coloring α, Surjective C := by rw [← hG.chromaticNumber_le.ge_iff_eq, card_le_chromaticNumber_iff_forall_surjective] lemma chromaticNumber_eq_iff_forall_surjective (hG : G.Colorable n) : G.chromaticNumber = n ↔ ∀ C : G.Coloring (Fin n), Surjective C := by rw [← hG.chromaticNumber_le.ge_iff_eq, le_chromaticNumber_iff_forall_surjective] theorem chromaticNumber_bot [Nonempty V] : (⊥ : SimpleGraph V).chromaticNumber = 1 := by have : (⊥ : SimpleGraph V).Colorable 1 := ⟨.mk 0 <| by simp⟩ exact this.chromaticNumber_le.antisymm <| Order.one_le_iff_pos.2 <| chromaticNumber_pos this @[simp] theorem chromaticNumber_top [Fintype V] : (⊤ : SimpleGraph V).chromaticNumber = Fintype.card V := by rw [chromaticNumber_eq_card_iff_forall_surjective (selfColoring _).colorable] intro C rw [← Finite.injective_iff_surjective] intro v w contrapose intro h exact C.valid h theorem chromaticNumber_top_eq_top_of_infinite (V : Type*) [Infinite V] : (⊤ : SimpleGraph V).chromaticNumber = ⊤ := by by_contra hc rw [← Ne, chromaticNumber_ne_top_iff_exists] at hc obtain ⟨n, ⟨hn⟩⟩ := hc exact not_injective_infinite_finite _ hn.injective_of_top_hom /-- The bicoloring of a complete bipartite graph using whether a vertex is on the left or on the right. -/ def CompleteBipartiteGraph.bicoloring (V W : Type*) : (completeBipartiteGraph V W).Coloring Bool := Coloring.mk (fun v => v.isRight) (by intro v w cases v <;> cases w <;> simp) theorem CompleteBipartiteGraph.chromaticNumber {V W : Type*} [Nonempty V] [Nonempty W] : (completeBipartiteGraph V W).chromaticNumber = 2 := by rw [← Nat.cast_two, chromaticNumber_eq_iff_forall_surjective (by simpa using (CompleteBipartiteGraph.bicoloring V W).colorable)] intro C b have v := Classical.arbitrary V have w := Classical.arbitrary W have h : (completeBipartiteGraph V W).Adj (Sum.inl v) (Sum.inr w) := by simp by_cases he : C (Sum.inl v) = b · exact ⟨_, he⟩ by_cases he' : C (Sum.inr w) = b · exact ⟨_, he'⟩ · simpa using two_lt_card_iff.2 ⟨_, _, _, C.valid h, he, he'⟩ /-! ### Cliques -/ theorem IsClique.card_le_of_coloring {s : Finset V} (h : G.IsClique s) [Fintype α] (C : G.Coloring α) : s.card ≤ Fintype.card α := by rw [isClique_iff_induce_eq] at h have f : G.induce ↑s ↪g G := Embedding.comap (Function.Embedding.subtype fun x => x ∈ ↑s) G rw [h] at f convert Fintype.card_le_of_injective _ (C.comp f.toHom).injective_of_top_hom using 1 simp theorem IsClique.card_le_of_colorable {s : Finset V} (h : G.IsClique s) {n : ℕ} (hc : G.Colorable n) : s.card ≤ n := by convert h.card_le_of_coloring hc.some simp theorem IsClique.card_le_chromaticNumber {s : Finset V} (h : G.IsClique s) : s.card ≤ G.chromaticNumber := by obtain (hc | hc) := eq_or_ne G.chromaticNumber ⊤ · rw [hc] exact le_top · have hc' := hc rw [chromaticNumber_ne_top_iff_exists] at hc' obtain ⟨n, c⟩ := hc' rw [← ENat.coe_toNat_eq_self] at hc rw [← hc, Nat.cast_le] exact h.card_le_of_colorable (colorable_chromaticNumber c) protected theorem Colorable.cliqueFree {n m : ℕ} (hc : G.Colorable n) (hm : n < m) : G.CliqueFree m := by by_contra h simp only [CliqueFree, isNClique_iff, not_forall, Classical.not_not] at h obtain ⟨s, h, rfl⟩ := h exact Nat.lt_le_asymm hm (h.card_le_of_colorable hc) theorem cliqueFree_of_chromaticNumber_lt {n : ℕ} (hc : G.chromaticNumber < n) : G.CliqueFree n := by have hne : G.chromaticNumber ≠ ⊤ := hc.ne_top obtain ⟨m, hc'⟩ := chromaticNumber_ne_top_iff_exists.mp hne have := colorable_chromaticNumber hc' refine this.cliqueFree ?_ rw [← ENat.coe_toNat_eq_self] at hne rw [← hne] at hc simpa using hc /-- Given a colouring `α` of `G`, and a clique of size at least the number of colours, the clique contains a vertex of each colour. -/ lemma Coloring.surjOn_of_card_le_isClique [Fintype α] {s : Finset V} (h : G.IsClique s) (hc : Fintype.card α ≤ s.card) (C : G.Coloring α) : Set.SurjOn C s Set.univ := by intro _ _ obtain ⟨_, hx⟩ := card_le_chromaticNumber_iff_forall_surjective.mp (by simp_all [isClique_iff_induce_eq]) (C.comp (Embedding.induce s).toHom) _ exact ⟨_, Subtype.coe_prop _, hx⟩ namespace completeMultipartiteGraph variable {ι : Type*} (V : ι → Type*) /-- The canonical `ι`-coloring of a `completeMultipartiteGraph` with parts indexed by `ι` -/ def coloring : (completeMultipartiteGraph V).Coloring ι := Coloring.mk (fun v ↦ v.1) (by simp) lemma colorable [Fintype ι] : (completeMultipartiteGraph V).Colorable (Fintype.card ι) := (coloring V).colorable theorem chromaticNumber [Fintype ι] (f : ∀ (i : ι), V i) : (completeMultipartiteGraph V).chromaticNumber = Fintype.card ι := by apply le_antisymm (colorable V).chromaticNumber_le by_contra! h exact not_cliqueFree_of_le_card V f le_rfl <| cliqueFree_of_chromaticNumber_lt h theorem colorable_of_cliqueFree (f : ∀ (i : ι), V i) (hc : (completeMultipartiteGraph V).CliqueFree n) : (completeMultipartiteGraph V).Colorable (n - 1) := by cases n with | zero => exact absurd hc not_cliqueFree_zero | succ n => have : Fintype ι := fintypeOfNotInfinite fun hinf ↦ not_cliqueFree_of_infinite V f hc apply (coloring V).colorable.mono have := not_cliqueFree_of_le_card V f le_rfl contrapose! this exact hc.mono this end completeMultipartiteGraph end SimpleGraph
Complex.lean
/- Copyright (c) 2022 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Data.Complex.FiniteDimensional import Mathlib.FieldTheory.IntermediateField.Basic import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.Topology.Algebra.Field import Mathlib.Topology.Algebra.UniformRing /-! # Some results about the topology of ℂ -/ section ComplexSubfield open Complex Set open ComplexConjugate /-- The only closed subfields of `ℂ` are `ℝ` and `ℂ`. -/ theorem Complex.subfield_eq_of_closed {K : Subfield ℂ} (hc : IsClosed (K : Set ℂ)) : K = ofRealHom.fieldRange ∨ K = ⊤ := by suffices range (ofReal : ℝ → ℂ) ⊆ K by rw [range_subset_iff, ← coe_algebraMap] at this have := (Subalgebra.isSimpleOrder_of_finrank finrank_real_complex).eq_bot_or_eq_top (Subfield.toIntermediateField K this).toSubalgebra simp_rw [← SetLike.coe_set_eq, IntermediateField.coe_toSubalgebra] at this ⊢ exact this suffices range (ofReal : ℝ → ℂ) ⊆ closure (Set.range ((ofReal : ℝ → ℂ) ∘ ((↑) : ℚ → ℝ))) by refine subset_trans this ?_ rw [← IsClosed.closure_eq hc] apply closure_mono rintro _ ⟨_, rfl⟩ simp only [Function.comp_apply, ofReal_ratCast, SetLike.mem_coe, SubfieldClass.ratCast_mem] nth_rw 1 [range_comp] refine subset_trans ?_ (image_closure_subset_closure_image continuous_ofReal) rw [DenseRange.closure_range Rat.isDenseEmbedding_coe_real.dense] simp only [image_univ] rfl /-- Let `K` a subfield of `ℂ` and let `ψ : K →+* ℂ` a ring homomorphism. Assume that `ψ` is uniform continuous, then `ψ` is either the inclusion map or the composition of the inclusion map with the complex conjugation. -/ theorem Complex.uniformContinuous_ringHom_eq_id_or_conj (K : Subfield ℂ) {ψ : K →+* ℂ} (hc : UniformContinuous ψ) : ψ.toFun = K.subtype ∨ ψ.toFun = conj ∘ K.subtype := by letI : IsTopologicalDivisionRing ℂ := IsTopologicalDivisionRing.mk letI : IsTopologicalRing K.topologicalClosure := Subring.instIsTopologicalRing K.topologicalClosure.toSubring set ι : K → K.topologicalClosure := ⇑(Subfield.inclusion K.le_topologicalClosure) have ui : IsUniformInducing ι := ⟨by rw [uniformity_subtype, uniformity_subtype, Filter.comap_comap] congr ⟩ let di := ui.isDenseInducing (?_ : DenseRange ι) · -- extψ : closure(K) →+* ℂ is the extension of ψ : K →+* ℂ let extψ := IsDenseInducing.extendRingHom ui di.dense hc haveI hψ := (uniformContinuous_uniformly_extend ui di.dense hc).continuous rcases Complex.subfield_eq_of_closed (Subfield.isClosed_topologicalClosure K) with h | h · left let j := RingEquiv.subfieldCongr h -- ψ₁ is the continuous ring hom `ℝ →+* ℂ` constructed from `j : closure (K) ≃+* ℝ` -- and `extψ : closure (K) →+* ℂ` let ψ₁ := RingHom.comp extψ (RingHom.comp j.symm.toRingHom ofRealHom.rangeRestrict) -- Porting note: was `by continuity!` and was used inline have hψ₁ : Continuous ψ₁ := by simpa only [RingHom.coe_comp] using hψ.comp ((continuous_algebraMap ℝ ℂ).subtype_mk _) ext1 x rsuffices ⟨r, hr⟩ : ∃ r : ℝ, ofRealHom.rangeRestrict r = j (ι x) · have := RingHom.congr_fun (ringHom_eq_ofReal_of_continuous hψ₁) r rw [RingHom.comp_apply, RingHom.comp_apply] at this -- In `this`, the `DFunLike.coe` thinks it is applying a `(ℝ →+* ↥ofRealHom.fieldRange)`, -- while in `hr`, we have a `(ℝ →+* ↥ofRealHom.range)`. -- We could add a `@[simp]` lemma fixing this, but it breaks later steps of the proof. erw [hr] at this rw [RingEquiv.toRingHom_eq_coe] at this convert this using 1 · exact (IsDenseInducing.extend_eq di hc.continuous _).symm · rw [← ofRealHom.coe_rangeRestrict, hr] rfl obtain ⟨r, hr⟩ := SetLike.coe_mem (j (ι x)) exact ⟨r, Subtype.ext hr⟩ · -- ψ₁ is the continuous ring hom `ℂ →+* ℂ` constructed from `closure (K) ≃+* ℂ` -- and `extψ : closure (K) →+* ℂ` let ψ₁ := RingHom.comp extψ (RingHom.comp (RingEquiv.subfieldCongr h).symm.toRingHom (@Subfield.topEquiv ℂ _).symm.toRingHom) -- Porting note: was `by continuity!` and was used inline have hψ₁ : Continuous ψ₁ := by simpa only [RingHom.coe_comp] using hψ.comp (continuous_id.subtype_mk _) rcases ringHom_eq_id_or_conj_of_continuous hψ₁ with h | h · left ext1 z convert RingHom.congr_fun h z using 1 exact (IsDenseInducing.extend_eq di hc.continuous z).symm · right ext1 z convert RingHom.congr_fun h z using 1 exact (IsDenseInducing.extend_eq di hc.continuous z).symm · let j : { x // x ∈ closure (id '' { x | (K : Set ℂ) x }) } → (K.topologicalClosure : Set ℂ) := fun x => ⟨x, by convert x.prop simp only [id, Set.image_id'] rfl ⟩ convert DenseRange.comp (Function.Surjective.denseRange _) (IsDenseEmbedding.id.subtype (K : Set ℂ)).dense (by fun_prop : Continuous j) rintro ⟨y, hy⟩ use ⟨y, by convert hy simp only [id, Set.image_id'] rfl ⟩ end ComplexSubfield
EpiMono.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.MorphismProperty.Concrete import Mathlib.CategoryTheory.Types import Mathlib.CategoryTheory.Limits.Preserves.Basic import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Epi and mono in concrete categories In this file, we relate epimorphisms and monomorphisms in a concrete category `C` to surjective and injective morphisms, and we show that if `C` has strong epi mono factorizations and is such that `forget C` preserves both epi and mono, then any morphism in `C` can be factored in a functorial manner as a composition of a surjective morphism followed by an injective morphism. -/ universe w v v' u u' namespace CategoryTheory variable {C : Type u} [Category.{v} C] {FC : C → C → Type*} {CC : C → Type w} variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC] open Limits MorphismProperty namespace ConcreteCategory section /-- In any concrete category, injective morphisms are monomorphisms. -/ theorem mono_of_injective {X Y : C} (f : X ⟶ Y) (i : Function.Injective f) : Mono f := (forget C).mono_of_mono_map ((mono_iff_injective ((forget C).map f)).2 i) instance forget₂_preservesMonomorphisms (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] [(forget C).PreservesMonomorphisms] : (forget₂ C D).PreservesMonomorphisms := have : (forget₂ C D ⋙ forget D).PreservesMonomorphisms := by simp only [HasForget₂.forget_comp] infer_instance Functor.preservesMonomorphisms_of_preserves_of_reflects _ (forget D) instance forget₂_preservesEpimorphisms (C : Type u) (D : Type u') [Category.{v} C] [HasForget.{w} C] [Category.{v'} D] [HasForget.{w} D] [HasForget₂ C D] [(forget C).PreservesEpimorphisms] : (forget₂ C D).PreservesEpimorphisms := have : (forget₂ C D ⋙ forget D).PreservesEpimorphisms := by simp only [HasForget₂.forget_comp] infer_instance Functor.preservesEpimorphisms_of_preserves_of_reflects _ (forget D) variable (C) lemma surjective_le_epimorphisms : MorphismProperty.surjective C ≤ epimorphisms C := fun _ _ _ hf => (forget C).epi_of_epi_map ((epi_iff_surjective _).2 hf) lemma injective_le_monomorphisms : MorphismProperty.injective C ≤ monomorphisms C := fun _ _ _ hf => (forget C).mono_of_mono_map ((mono_iff_injective _).2 hf) lemma surjective_eq_epimorphisms_iff : MorphismProperty.surjective C = epimorphisms C ↔ (forget C).PreservesEpimorphisms := by constructor · intro h constructor rintro _ _ f (hf : epimorphisms C f) rw [epi_iff_surjective] rw [← h] at hf exact hf · intro apply le_antisymm (surjective_le_epimorphisms C) intro _ _ f hf have : Epi f := hf change Function.Surjective ((forget C).map f) rw [← epi_iff_surjective] infer_instance lemma injective_eq_monomorphisms_iff : MorphismProperty.injective C = monomorphisms C ↔ (forget C).PreservesMonomorphisms := by constructor · intro h constructor rintro _ _ f (hf : monomorphisms C f) rw [mono_iff_injective] rw [← h] at hf exact hf · intro apply le_antisymm (injective_le_monomorphisms C) intro _ _ f hf have : Mono f := hf change Function.Injective ((forget C).map f) rw [← mono_iff_injective] infer_instance lemma injective_eq_monomorphisms [(forget C).PreservesMonomorphisms] : MorphismProperty.injective C = monomorphisms C := by rw [injective_eq_monomorphisms_iff] infer_instance lemma surjective_eq_epimorphisms [(forget C).PreservesEpimorphisms] : MorphismProperty.surjective C = epimorphisms C := by rw [surjective_eq_epimorphisms_iff] infer_instance variable [HasStrongEpiMonoFactorisations C] [(forget C).PreservesMonomorphisms] [(forget C).PreservesEpimorphisms] /-- A concrete category with strong epi mono factorizations and such that the forget functor preserves mono and epi admits functorial surjective/injective factorizations. -/ noncomputable def functorialSurjectiveInjectiveFactorizationData : FunctorialSurjectiveInjectiveFactorizationData C := (functorialEpiMonoFactorizationData C).ofLE (by rw [surjective_eq_epimorphisms]) (by rw [injective_eq_monomorphisms]) instance (priority := 100) : HasFunctorialSurjectiveInjectiveFactorization C where nonempty_functorialFactorizationData := ⟨functorialSurjectiveInjectiveFactorizationData C⟩ end section open CategoryTheory.Limits theorem injective_of_mono_of_preservesPullback {X Y : C} (f : X ⟶ Y) [Mono f] [PreservesLimitsOfShape WalkingCospan (forget C)] : Function.Injective f := (mono_iff_injective ((forget C).map f)).mp inferInstance theorem mono_iff_injective_of_preservesPullback {X Y : C} (f : X ⟶ Y) [PreservesLimitsOfShape WalkingCospan (forget C)] : Mono f ↔ Function.Injective f := ((forget C).mono_map_iff_mono _).symm.trans (mono_iff_injective _) /-- In any concrete category, surjective morphisms are epimorphisms. -/ theorem epi_of_surjective {X Y : C} (f : X ⟶ Y) (s : Function.Surjective f) : Epi f := (forget C).epi_of_epi_map ((epi_iff_surjective ((forget C).map f)).2 s) theorem surjective_of_epi_of_preservesPushout {X Y : C} (f : X ⟶ Y) [Epi f] [PreservesColimitsOfShape WalkingSpan (forget C)] : Function.Surjective f := (epi_iff_surjective ((forget C).map f)).mp inferInstance theorem epi_iff_surjective_of_preservesPushout {X Y : C} (f : X ⟶ Y) [PreservesColimitsOfShape WalkingSpan (forget C)] : Epi f ↔ Function.Surjective f := ((forget C).epi_map_iff_epi _).symm.trans (epi_iff_surjective _) theorem bijective_of_isIso {X Y : C} (f : X ⟶ Y) [IsIso f] : Function.Bijective f := by rw [← isIso_iff_bijective] infer_instance /-- If the forgetful functor of a concrete category reflects isomorphisms, being an isomorphism is equivalent to being bijective. -/ theorem isIso_iff_bijective [(forget C).ReflectsIsomorphisms] {X Y : C} (f : X ⟶ Y) : IsIso f ↔ Function.Bijective f := by rw [← CategoryTheory.isIso_iff_bijective] exact ⟨fun _ ↦ inferInstance, fun _ ↦ isIso_of_reflects_iso f (forget C)⟩ end end ConcreteCategory end CategoryTheory
Subspace.lean
/- Copyright (c) 2022 Michael Blyth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Blyth -/ import Mathlib.LinearAlgebra.Projectivization.Basic /-! # Subspaces of Projective Space In this file we define subspaces of a projective space, and show that the subspaces of a projective space form a complete lattice under inclusion. ## Implementation Details A subspace of a projective space ℙ K V is defined to be a structure consisting of a subset of ℙ K V such that if two nonzero vectors in V determine points in ℙ K V which are in the subset, and the sum of the two vectors is nonzero, then the point determined by the sum of the two vectors is also in the subset. ## Results - There is a Galois insertion between the subsets of points of a projective space and the subspaces of the projective space, which is given by taking the span of the set of points. - The subspaces of a projective space form a complete lattice under inclusion. # Future Work - Show that there is a one-to-one order-preserving correspondence between subspaces of a projective space and the submodules of the underlying vector space. -/ variable (K V : Type*) [Field K] [AddCommGroup V] [Module K V] namespace Projectivization open scoped LinearAlgebra.Projectivization /-- A subspace of a projective space is a structure consisting of a set of points such that: If two nonzero vectors determine points which are in the set, and the sum of the two vectors is nonzero, then the point determined by the sum is also in the set. -/ @[ext] structure Subspace where /-- The set of points. -/ carrier : Set (ℙ K V) /-- The addition rule. -/ mem_add' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : mk K v hv ∈ carrier → mk K w hw ∈ carrier → mk K (v + w) hvw ∈ carrier namespace Subspace variable {K V} instance : SetLike (Subspace K V) (ℙ K V) where coe := carrier coe_injective' A B := by cases A cases B simp @[simp] theorem mem_carrier_iff (A : Subspace K V) (x : ℙ K V) : x ∈ A.carrier ↔ x ∈ A := Iff.refl _ theorem mem_add (T : Subspace K V) (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : Projectivization.mk K v hv ∈ T → Projectivization.mk K w hw ∈ T → Projectivization.mk K (v + w) hvw ∈ T := T.mem_add' v w hv hw hvw /-- The span of a set of points in a projective space is defined inductively to be the set of points which contains the original set, and contains all points determined by the (nonzero) sum of two nonzero vectors, each of which determine points in the span. -/ inductive spanCarrier (S : Set (ℙ K V)) : Set (ℙ K V) | of (x : ℙ K V) (hx : x ∈ S) : spanCarrier S x | mem_add (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : spanCarrier S (Projectivization.mk K v hv) → spanCarrier S (Projectivization.mk K w hw) → spanCarrier S (Projectivization.mk K (v + w) hvw) /-- The span of a set of points in projective space is a subspace. -/ def span (S : Set (ℙ K V)) : Subspace K V where carrier := spanCarrier S mem_add' v w hv hw hvw := spanCarrier.mem_add v w hv hw hvw /-- The span of a set of points contains the set of points. -/ theorem subset_span (S : Set (ℙ K V)) : S ⊆ span S := fun _x hx => spanCarrier.of _ hx /-- The span of a set of points is a Galois insertion between sets of points of a projective space and subspaces of the projective space. -/ def gi : GaloisInsertion (span : Set (ℙ K V) → Subspace K V) SetLike.coe where choice S _hS := span S gc A B := ⟨fun h => le_trans (subset_span _) h, by intro h x hx induction hx with | of => apply h; assumption | mem_add => apply B.mem_add; assumption'⟩ le_l_u _ := subset_span _ choice_eq _ _ := rfl /-- The span of a subspace is the subspace. -/ @[simp] theorem span_coe (W : Subspace K V) : span ↑W = W := GaloisInsertion.l_u_eq gi W /-- The infimum of two subspaces exists. -/ instance instInf : Min (Subspace K V) := ⟨fun A B => ⟨A ⊓ B, fun _v _w hv hw _hvw h1 h2 => ⟨A.mem_add _ _ hv hw _ h1.1 h2.1, B.mem_add _ _ hv hw _ h1.2 h2.2⟩⟩⟩ /-- Infimums of arbitrary collections of subspaces exist. -/ instance instInfSet : InfSet (Subspace K V) := ⟨fun A => ⟨sInf (SetLike.coe '' A), fun v w hv hw hvw h1 h2 t => by rintro ⟨s, hs, rfl⟩ exact s.mem_add v w hv hw _ (h1 s ⟨s, hs, rfl⟩) (h2 s ⟨s, hs, rfl⟩)⟩⟩ /-- The subspaces of a projective space form a complete lattice. -/ instance : CompleteLattice (Subspace K V) := { __ := completeLatticeOfInf (Subspace K V) (by refine fun s => ⟨fun a ha x hx => hx _ ⟨a, ha, rfl⟩, fun a ha x hx E => ?_⟩ rintro ⟨E, hE, rfl⟩ exact ha hE hx) inf_le_left := fun A B _ hx => (@inf_le_left _ _ A B) hx inf_le_right := fun A B _ hx => (@inf_le_right _ _ A B) hx le_inf := fun _ _ _ h1 h2 _ hx => (le_inf h1 h2) hx } instance subspaceInhabited : Inhabited (Subspace K V) where default := ⊤ /-- The span of the empty set is the bottom of the lattice of subspaces. -/ @[simp] theorem span_empty : span (∅ : Set (ℙ K V)) = ⊥ := gi.gc.l_bot /-- The span of the entire projective space is the top of the lattice of subspaces. -/ @[simp] theorem span_univ : span (Set.univ : Set (ℙ K V)) = ⊤ := by rw [eq_top_iff, SetLike.le_def] intro x _hx exact subset_span _ (Set.mem_univ x) /-- The span of a set of points is contained in a subspace if and only if the set of points is contained in the subspace. -/ theorem span_le_subspace_iff {S : Set (ℙ K V)} {W : Subspace K V} : span S ≤ W ↔ S ⊆ W := gi.gc S W /-- If a set of points is a subset of another set of points, then its span will be contained in the span of that set. -/ @[mono] theorem monotone_span : Monotone (span : Set (ℙ K V) → Subspace K V) := gi.gc.monotone_l @[gcongr] lemma span_le_span {s t : Set (ℙ K V)} (hst : s ⊆ t) : span s ≤ span t := monotone_span hst theorem subset_span_trans {S T U : Set (ℙ K V)} (hST : S ⊆ span T) (hTU : T ⊆ span U) : S ⊆ span U := gi.gc.le_u_l_trans hST hTU /-- The supremum of two subspaces is equal to the span of their union. -/ theorem span_union (S T : Set (ℙ K V)) : span (S ∪ T) = span S ⊔ span T := (@gi K V _ _ _).gc.l_sup /-- The supremum of a collection of subspaces is equal to the span of the union of the collection. -/ theorem span_iUnion {ι} (s : ι → Set (ℙ K V)) : span (⋃ i, s i) = ⨆ i, span (s i) := (@gi K V _ _ _).gc.l_iSup /-- The supremum of a subspace and the span of a set of points is equal to the span of the union of the subspace and the set of points. -/ theorem sup_span {S : Set (ℙ K V)} {W : Subspace K V} : W ⊔ span S = span (W ∪ S) := by rw [span_union, span_coe] theorem span_sup {S : Set (ℙ K V)} {W : Subspace K V} : span S ⊔ W = span (S ∪ W) := by rw [span_union, span_coe] /-- A point in a projective space is contained in the span of a set of points if and only if the point is contained in all subspaces of the projective space which contain the set of points. -/ theorem mem_span {S : Set (ℙ K V)} (u : ℙ K V) : u ∈ span S ↔ ∀ W : Subspace K V, S ⊆ W → u ∈ W := by simp_rw [← span_le_subspace_iff] exact ⟨fun hu W hW => hW hu, fun W => W (span S) (le_refl _)⟩ /-- The span of a set of points in a projective space is equal to the infimum of the collection of subspaces which contain the set. -/ theorem span_eq_sInf {S : Set (ℙ K V)} : span S = sInf { W : Subspace K V| S ⊆ W } := by ext x simp_rw [mem_carrier_iff, mem_span x] refine ⟨fun hx => ?_, fun hx W hW => ?_⟩ · rintro W ⟨T, hT, rfl⟩ exact hx T hT · exact (@sInf_le _ _ { W : Subspace K V | S ⊆ ↑W } W hW) hx /-- If a set of points in projective space is contained in a subspace, and that subspace is contained in the span of the set of points, then the span of the set of points is equal to the subspace. -/ theorem span_eq_of_le {S : Set (ℙ K V)} {W : Subspace K V} (hS : S ⊆ W) (hW : W ≤ span S) : span S = W := le_antisymm (span_le_subspace_iff.mpr hS) hW /-- The spans of two sets of points in a projective space are equal if and only if each set of points is contained in the span of the other set. -/ theorem span_eq_span_iff {S T : Set (ℙ K V)} : span S = span T ↔ S ⊆ span T ∧ T ⊆ span S := ⟨fun h => ⟨h ▸ subset_span S, h.symm ▸ subset_span T⟩, fun h => le_antisymm (span_le_subspace_iff.2 h.1) (span_le_subspace_iff.2 h.2)⟩ end Subspace end Projectivization
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, Jeremy Avigad, Yury Kudryashov, Patrick Massot -/ import Mathlib.Data.Set.Piecewise import Mathlib.Order.Filter.Basic /-! # Definition of `Filter.atTop` and `Filter.atBot` filters In this file we define the filters * `Filter.atTop`: corresponds to `n → +∞`; * `Filter.atBot`: corresponds to `n → -∞`. -/ assert_not_exists Finset variable {ι ι' α β γ : Type*} open Set namespace Filter /-- `atTop` is the filter representing the limit `→ ∞` on an ordered set. It is generated by the collection of up-sets `{b | a ≤ b}`. (The preorder need not have a top element for this to be well defined, and indeed is trivial when a top element exists.) -/ def atTop [Preorder α] : Filter α := ⨅ a, 𝓟 (Ici a) /-- `atBot` is the filter representing the limit `→ -∞` on an ordered set. It is generated by the collection of down-sets `{b | b ≤ a}`. (The preorder need not have a bottom element for this to be well defined, and indeed is trivial when a bottom element exists.) -/ def atBot [Preorder α] : Filter α := ⨅ a, 𝓟 (Iic a) theorem mem_atTop [Preorder α] (a : α) : { b : α | a ≤ b } ∈ @atTop α _ := mem_iInf_of_mem a <| Subset.refl _ theorem Ici_mem_atTop [Preorder α] (a : α) : Ici a ∈ (atTop : Filter α) := mem_atTop a theorem Ioi_mem_atTop [Preorder α] [NoTopOrder α] (x : α) : Ioi x ∈ (atTop : Filter α) := let ⟨z, hz⟩ := exists_not_le x mem_of_superset (inter_mem (mem_atTop x) (mem_atTop z)) fun _ ⟨hxy, hzy⟩ => lt_of_le_not_ge hxy fun hyx => hz (hzy.trans hyx) theorem mem_atBot [Preorder α] (a : α) : { b : α | b ≤ a } ∈ @atBot α _ := mem_iInf_of_mem a <| Subset.refl _ theorem Iic_mem_atBot [Preorder α] (a : α) : Iic a ∈ (atBot : Filter α) := mem_atBot a theorem Iio_mem_atBot [Preorder α] [NoBotOrder α] (x : α) : Iio x ∈ (atBot : Filter α) := let ⟨z, hz⟩ := exists_not_ge x mem_of_superset (inter_mem (mem_atBot x) (mem_atBot z)) fun _ ⟨hyx, hyz⟩ => lt_of_le_not_ge hyx fun hxy => hz (hxy.trans hyz) theorem eventually_ge_atTop [Preorder α] (a : α) : ∀ᶠ x in atTop, a ≤ x := mem_atTop a theorem eventually_le_atBot [Preorder α] (a : α) : ∀ᶠ x in atBot, x ≤ a := mem_atBot a theorem eventually_gt_atTop [Preorder α] [NoTopOrder α] (a : α) : ∀ᶠ x in atTop, a < x := Ioi_mem_atTop a theorem eventually_ne_atTop [Preorder α] [NoTopOrder α] (a : α) : ∀ᶠ x in atTop, x ≠ a := (eventually_gt_atTop a).mono fun _ => ne_of_gt theorem eventually_lt_atBot [Preorder α] [NoBotOrder α] (a : α) : ∀ᶠ x in atBot, x < a := Iio_mem_atBot a theorem eventually_ne_atBot [Preorder α] [NoBotOrder α] (a : α) : ∀ᶠ x in atBot, x ≠ a := (eventually_lt_atBot a).mono fun _ => ne_of_lt theorem _root_.IsTop.atTop_eq [Preorder α] {a : α} (ha : IsTop a) : atTop = 𝓟 (Ici a) := (iInf_le _ _).antisymm <| le_iInf fun b ↦ principal_mono.2 <| Ici_subset_Ici.2 <| ha b theorem _root_.IsBot.atBot_eq [Preorder α] {a : α} (ha : IsBot a) : atBot = 𝓟 (Iic a) := ha.toDual.atTop_eq theorem atTop_eq_generate_Ici [Preorder α] : atTop = generate (range (Ici (α := α))) := by simp only [generate_eq_biInf, atTop, iInf_range] theorem Frequently.forall_exists_of_atTop [Preorder α] {p : α → Prop} (h : ∃ᶠ x in atTop, p x) (a : α) : ∃ b ≥ a, p b := by rw [Filter.Frequently] at h contrapose! h exact (eventually_ge_atTop a).mono h theorem Frequently.forall_exists_of_atBot [Preorder α] {p : α → Prop} (h : ∃ᶠ x in atBot, p x) (a : α) : ∃ b ≤ a, p b := Frequently.forall_exists_of_atTop (α := αᵒᵈ) h _ lemma atTop_eq_generate_of_forall_exists_le [Preorder α] {s : Set α} (hs : ∀ x, ∃ y ∈ s, x ≤ y) : (atTop : Filter α) = generate (Ici '' s) := by rw [atTop_eq_generate_Ici] apply le_antisymm · rw [le_generate_iff] rintro - ⟨y, -, rfl⟩ exact mem_generate_of_mem ⟨y, rfl⟩ · rw [le_generate_iff] rintro - ⟨x, -, -, rfl⟩ rcases hs x with ⟨y, ys, hy⟩ have A : Ici y ∈ generate (Ici '' s) := mem_generate_of_mem (mem_image_of_mem _ ys) have B : Ici y ⊆ Ici x := Ici_subset_Ici.2 hy exact sets_of_superset (generate (Ici '' s)) A B lemma atTop_eq_generate_of_not_bddAbove [LinearOrder α] {s : Set α} (hs : ¬ BddAbove s) : (atTop : Filter α) = generate (Ici '' s) := by refine atTop_eq_generate_of_forall_exists_le fun x ↦ ?_ obtain ⟨y, hy, hy'⟩ := not_bddAbove_iff.mp hs x exact ⟨y, hy, hy'.le⟩ end Filter open Filter theorem Monotone.piecewise_eventually_eq_iUnion {β : α → Type*} [Preorder ι] {s : ι → Set α} [∀ i, DecidablePred (· ∈ s i)] [DecidablePred (· ∈ ⋃ i, s i)] (hs : Monotone s) (f g : (a : α) → β a) (a : α) : ∀ᶠ i in atTop, (s i).piecewise f g a = (⋃ i, s i).piecewise f g a := by rcases em (∃ i, a ∈ s i) with ⟨i, hi⟩ | ha · refine (eventually_ge_atTop i).mono fun j hij ↦ ?_ simp only [Set.piecewise_eq_of_mem, hs hij hi, subset_iUnion _ _ hi] · filter_upwards with i simp only [Set.piecewise_eq_of_notMem, not_exists.1 ha i, mt mem_iUnion.1 ha, not_false_eq_true] theorem Antitone.piecewise_eventually_eq_iInter {β : α → Type*} [Preorder ι] {s : ι → Set α} [∀ i, DecidablePred (· ∈ s i)] [DecidablePred (· ∈ ⋂ i, s i)] (hs : Antitone s) (f g : (a : α) → β a) (a : α) : ∀ᶠ i in atTop, (s i).piecewise f g a = (⋂ i, s i).piecewise f g a := by classical convert ← (compl_anti.comp hs).piecewise_eventually_eq_iUnion g f a using 3 · convert congr_fun (Set.piecewise_compl (s _) g f) a · simp only [(· ∘ ·), ← compl_iInter, Set.piecewise_compl]
WeylGroup.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.RootSystem.Hom import Mathlib.RepresentationTheory.Basic /-! # The Weyl group of a root pairing This file defines the Weyl group of a root pairing as the subgroup of automorphisms generated by reflection automorphisms. This deviates from the existing literature, which typically defines the Weyl group as the subgroup of linear transformations of the weight space generated by linear reflections. However, the automorphism group of a root pairing comes with a permutation representation on the set indexing roots and faithful linear representations on the weight space and coweight space. Thus, our formalism gives us an isomorphism to the traditional Weyl group together with the natural dual representation generated by coreflections and the permutation representation on roots. ## Main definitions * `RootPairing.weylGroup` : The group of automorphisms generated by reflections. * `RootPairing.weylGroupToPerm` : The permutation representation of the Weyl group on roots. ## Results * `RootPairing.range_weylGroup_weightHom` : The image of the weight space representation is equal to the subgroup generated by linear reflections. * `RootPairing.range_weylGroup_coweightHom` : The image of the coweight space representation is equal to the subgroup generated by linear coreflections. * `RootPairing.range_weylGroupToPerm` : The image of the permutation representation is equal to the subgroup generated by reflection permutations. ## TODO * faithfulness of `weylGroupToPerm` when multiplication by 2 is injective on the weight space. -/ open Set Function variable {ι R M N : Type*} noncomputable section namespace RootPairing variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] (P : RootPairing ι R M N) (i : ι) /-- The `Weyl group` of a root pairing is the group of automorphisms of the root pairing generated by reflections. -/ def weylGroup : Subgroup (Aut P) := Subgroup.closure (range (Equiv.reflection P)) lemma reflection_mem_weylGroup : Equiv.reflection P i ∈ P.weylGroup := Subgroup.subset_closure <| mem_range_self i /-- The `ith` reflection as a term of the Weyl group. -/ def weylGroup.ofIdx (i : ι) : P.weylGroup := ⟨_, P.reflection_mem_weylGroup i⟩ @[simp] lemma weylGroup.ofIdx_smul (i : ι) (m : M) : weylGroup.ofIdx P i • m = Equiv.reflection P i • m := rfl /-- Usually `RootPairing.weylGroup.induction` will be more useful than this lemma. -/ lemma weylGroup_toSubmonoid : P.weylGroup.toSubmonoid = Submonoid.closure (range (Equiv.reflection P)) := by suffices range (Equiv.reflection P) = (range (Equiv.reflection P))⁻¹ by rw [weylGroup, Subgroup.closure_toSubmonoid, ← this, union_self] ext; simp [← inv_eq_iff_eq_inv] @[elab_as_elim] lemma weylGroup.induction {pred : (g : Aut P) → g ∈ P.weylGroup → Prop} (mem : ∀ i, pred (Equiv.reflection P i) (P.reflection_mem_weylGroup i)) (one : pred 1 (one_mem _)) (mul : ∀ x y hx hy, pred x hx → pred y hy → pred (x * y) (mul_mem hx hy)) {x} (hx : x ∈ P.weylGroup) : pred x hx := by let pred' : (g : Aut P) → g ∈ Submonoid.closure (range (Equiv.reflection P)) → Prop := fun g hg ↦ pred g <| by change g ∈ P.weylGroup.toSubmonoid; rwa [weylGroup_toSubmonoid] have hx' : x ∈ Submonoid.closure (range (Equiv.reflection P)) := by rwa [← weylGroup_toSubmonoid] suffices pred' x hx' from this apply Submonoid.closure_induction · rintro - ⟨i, rfl⟩ exact mem i · exact one · intro x y hx hy hx' hy' rw [← weylGroup_toSubmonoid] at hx hy exact mul x y hx hy hx' hy' @[elab_as_elim] lemma weylGroup.induction' [Nonempty ι] {pred : (g : Aut P) → g ∈ P.weylGroup → Prop} (mem : ∀ i, pred (Equiv.reflection P i) (P.reflection_mem_weylGroup i)) (mul : ∀ x y hx hy, pred x hx → pred y hy → pred (x * y) (mul_mem hx hy)) {x} (hx : x ∈ P.weylGroup) : pred x hx := by refine weylGroup.induction P mem ?_ mul hx obtain ⟨i⟩ : Nonempty ι := inferInstance have : (Equiv.reflection P i) ^ 2 = 1 := by rw [sq, mul_eq_one_iff_inv_eq, Equiv.reflection_inv P i] simpa [sq, ← this] using mul _ _ _ _ (mem i) (mem i) lemma range_weylGroup_weightHom : MonoidHom.range ((Equiv.weightHom P).restrict P.weylGroup) = Subgroup.closure (range P.reflection) := by refine (Subgroup.closure_eq_of_le _ ?_ ?_).symm · rintro - ⟨i, rfl⟩ simp only [MonoidHom.restrict_range, Subgroup.coe_map, Equiv.weightHom_apply, mem_image, SetLike.mem_coe] use Equiv.reflection P i exact ⟨reflection_mem_weylGroup P i, Equiv.reflection_weightEquiv P i⟩ · rintro fg ⟨⟨w, hw⟩, rfl⟩ induction hw using Subgroup.closure_induction'' with | one => change ((Equiv.weightHom P).restrict P.weylGroup) 1 ∈ _ simp only [map_one, one_mem] | mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [MonoidHom.restrict_apply, Equiv.weightHom_apply, Equiv.reflection_weightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | inv_mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [Equiv.reflection_inv, MonoidHom.restrict_apply, Equiv.weightHom_apply, Equiv.reflection_weightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | mul w₁ w₂ hw₁ hw₂ h₁ h₂ => simpa only [← Submonoid.mk_mul_mk _ w₁ w₂ hw₁ hw₂, map_mul] using Subgroup.mul_mem _ h₁ h₂ lemma range_weylGroup_coweightHom : MonoidHom.range ((Equiv.coweightHom P).restrict P.weylGroup) = Subgroup.closure (range (MulOpposite.op ∘ P.coreflection)) := by refine (Subgroup.closure_eq_of_le _ ?_ ?_).symm · rintro - ⟨i, rfl⟩ simp only [MonoidHom.restrict_range, Subgroup.coe_map, mem_image, SetLike.mem_coe] use Equiv.reflection P i refine ⟨reflection_mem_weylGroup P i, by simp⟩ · rintro fg ⟨⟨w, hw⟩, rfl⟩ induction hw using Subgroup.closure_induction'' with | one => change ((Equiv.coweightHom P).restrict P.weylGroup) 1 ∈ _ simp only [map_one, one_mem] | mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [MonoidHom.restrict_apply, Equiv.coweightHom_apply, Equiv.reflection_coweightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | inv_mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [Equiv.reflection_inv, MonoidHom.restrict_apply, Equiv.coweightHom_apply, Equiv.reflection_coweightEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | mul w₁ w₂ hw₁ hw₂ h₁ h₂ => simpa only [← Submonoid.mk_mul_mk _ w₁ w₂ hw₁ hw₂, map_mul] using Subgroup.mul_mem _ h₁ h₂ /-- The permutation representation of the Weyl group induced by `reflectionPerm`. -/ abbrev weylGroupToPerm := (Equiv.indexHom P).restrict P.weylGroup lemma range_weylGroupToPerm : P.weylGroupToPerm.range = Subgroup.closure (range P.reflectionPerm) := by refine (Subgroup.closure_eq_of_le _ ?_ ?_).symm · rintro - ⟨i, rfl⟩ simp only [MonoidHom.restrict_range, Subgroup.coe_map, mem_image, SetLike.mem_coe] use Equiv.reflection P i refine ⟨reflection_mem_weylGroup P i, by simp⟩ · rintro fg ⟨⟨w, hw⟩, rfl⟩ induction hw using Subgroup.closure_induction'' with | one => change ((Equiv.indexHom P).restrict P.weylGroup) 1 ∈ _ simp only [map_one, one_mem] | mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [MonoidHom.restrict_apply, Equiv.indexHom_apply, Equiv.reflection_indexEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | inv_mem w' hw' => obtain ⟨i, rfl⟩ := hw' simp only [Equiv.reflection_inv, MonoidHom.restrict_apply, Equiv.indexHom_apply, Equiv.reflection_indexEquiv] simpa only [reflection_mem_weylGroup] using Subgroup.subset_closure (mem_range_self i) | mul w₁ w₂ hw₁ hw₂ h₁ h₂ => simpa only [← Submonoid.mk_mul_mk _ w₁ w₂ hw₁ hw₂, map_mul] using Subgroup.mul_mem _ h₁ h₂ /-- The natural representation of the Weyl group on the root space. -/ def weylGroupRootRep : Representation R P.weylGroup M := Representation.ofDistribMulAction R P.weylGroup M /-- The natural representation of the Weyl group on the coroot space. -/ def weylGroupCorootRep : Representation R P.weylGroup.op N := Representation.ofDistribMulAction R P.weylGroup.op N lemma weylGroup_apply_root (g : P.weylGroup) (i : ι) : g • P.root i = P.root (P.weylGroupToPerm g i) := Hom.root_weightMap_apply _ _ _ _ end RootPairing
algebraics_fundamentals.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 ssrnat eqtype seq choice. From mathcomp Require Import div fintype path tuple bigop finset prime order. From mathcomp Require Import ssralg poly polydiv mxpoly countalg closed_field. From mathcomp Require Import ssrnum ssrint archimedean rat intdiv fingroup. From mathcomp Require Import finalg zmodp cyclic pgroup sylow vector falgebra. From mathcomp Require Import fieldext separable galois. (******************************************************************************) (* The main result in this file is the existence theorem that underpins the *) (* construction of the algebraic numbers in file algC.v. This theorem simply *) (* asserts the existence of an algebraically closed field with an *) (* automorphism of order 2, and dubbed the Fundamental_Theorem_of_Algebraics *) (* because it is essentially the Fundamental Theorem of Algebra for algebraic *) (* numbers (the more familiar version for complex numbers can be derived by *) (* continuity). *) (* Although our proof does indeed construct exactly the algebraics, we *) (* choose not to expose this in the statement of our Theorem. In algC.v we *) (* construct the norm and partial order of the "complex field" introduced by *) (* the Theorem; as these imply is has characteristic 0, we then get the *) (* algebraics as a subfield. To avoid some duplication a few basic properties *) (* of the algebraics, such as the existence of minimal polynomials, that are *) (* required by the proof of the Theorem, are also proved here. *) (* The main theorem of closed_field supplies us directly with an algebraic *) (* closure of the rationals (as the rationals are a countable field), so all *) (* we really need to construct is a conjugation automorphism that exchanges *) (* the two roots (i and -i) of X^2 + 1, and fixes a (real) subfield of *) (* index 2. This does not require actually constructing this field: the *) (* kHomExtend construction from galois.v supplies us with an automorphism *) (* conj_n of the number field Q[z_n] = Q[x_n, i] for any x_n such that Q[x_n] *) (* does not contain i (e.g., such that Q[x_n] is real). As conj_n will extend *) (* conj_m when Q[x_n] contains x_m, it therefore suffices to construct a *) (* sequence x_n such that *) (* (1) For each n, Q[x_n] is a REAL field containing Q[x_m] for all m <= n. *) (* (2) Each z in C belongs to Q[z_n] = Q[x_n, i] for large enough n. *) (* This, of course, amounts to proving the Fundamental Theorem of Algebra. *) (* Indeed, we use a constructive variant of Artin's algebraic proof of that *) (* Theorem to replace (2) by *) (* (3) Each monic polynomial over Q[x_m] whose constant term is -c^2 for some *) (* c in Q[x_m] has a root in Q[x_n] for large enough n. *) (* We then ensure (3) by setting Q[x_n+1] = Q[x_n, y] where y is the root of *) (* of such a polynomial p found by dichotomy in some interval [0, b] with b *) (* suitably large (such that p[b] >= 0), and p is obtained by decoding n into *) (* a triple (m, p, c) that satisfies the conditions of (3) (taking x_n+1=x_n *) (* if this is not the case), thereby ensuring that all such triples are *) (* ultimately considered. *) (* In more detail, the 600-line proof consists in six (uneven) parts: *) (* (A) - Construction of number fields (~ 100 lines): in order to make use of *) (* the theory developped in falgebra, fieldext, separable and galois we *) (* construct a separate fielExtType Q z for the number field Q[z], with *) (* z in C, the closure of rat supplied by countable_algebraic_closure. *) (* The morphism (ofQ z) maps Q z to C, and the Primitive Element Theorem *) (* lets us define a predicate sQ z characterizing the image of (ofQ z), *) (* as well as a partial inverse (inQ z) to (ofQ z). *) (* (B) - Construction of the real extension Q[x, y] (~ 230 lines): here y has *) (* to be a root of a polynomial p over Q[x] satisfying the conditions of *) (* (3), and Q[x] should be real and archimedean, which we represent by *) (* a morphism from Q x to some archimedean field R, as the ssrnum and *) (* fieldext structures are not compatible. The construction starts by *) (* weakening the condition p[0] = -c^2 to p[0] <= 0 (in R), then reducing *) (* to the case where p is the minimal polynomial over Q[x] of some y (in *) (* some Q[w] that contains x and all roots of p). Then we only need to *) (* construct a realFieldType structure for Q[t] = Q[x,y] (we don't even *) (* need to show it is consistent with that of R). This amounts to fixing *) (* the sign of all z != 0 in Q[t], consistently with arithmetic in Q[t]. *) (* Now any such z is equal to q[y] for some q in Q[x][X] coprime with p. *) (* Then up + vq = 1 for Bezout coefficients u and v. As p is monic, there *) (* is some b0 >= 0 in R such that p changes sign in ab0 = [0; b0]. As R *) (* is archimedean, some iteration of the binary search for a root of p in *) (* ab0 will yield an interval ab_n such that |up[d]| < 1/2 for d in ab_n. *) (* Then |q[d]| > 1/2M > 0 for any upper bound M on |v[X]| in ab0, so q *) (* cannot change sign in ab_n (as then root-finding in ab_n would yield a *) (* d with |Mq[d]| < 1/2), so we can fix the sign of z to that of q in *) (* ab_n. *) (* (C) - Construction of the x_n and z_n (~50 lines): x_ n is obtained by *) (* iterating (B), starting with x_0 = 0, and then (A) and the PET yield *) (* z_ n. We establish (1) and (3), and that the minimal polynomial of the *) (* preimage i_ n of i over the preimage R_ n of Q[x_n] is X^2 + 1. *) (* (D) - Establish (2), i.e., prove the FTA (~180 lines). We must depart from *) (* Artin's proof because deciding membership in the union of the Q[x_n] *) (* requires the FTA, i.e., we cannot (yet) construct a maximal real *) (* subfield of C. We work around this issue by first reducing to the case *) (* where Q[z] is Galois over Q and contains i, then using induction over *) (* the degree of z over Q[z_ n] (i.e., the degree of a monic polynomial *) (* over Q[z_n] that has z as a root). We can assume that z is not in *) (* Q[z_n]; then it suffices to find some y in Q[z_n, z] \ Q[z_n] that is *) (* also in Q[z_m] for some m > n, as then we can apply induction with the *) (* minimal polynomial of z over Q[z_n, y]. In any Galois extension Q[t] *) (* of Q that contains both z and z_n, Q[x_n, z] = Q[z_n, z] is Galois *) (* over both Q[x_n] and Q[z_n]. If Gal(Q[x_n,z] / Q[x_n]) isn't a 2-group *) (* take one of its Sylow 2-groups P; the minimal polynomial p of any *) (* generator of the fixed field F of P over Q[x_n] has odd degree, hence *) (* by (3) - p[X]p[-X] and thus p has a root y in some Q[x_m], hence in *) (* Q[z_m]. As F is normal, y is in F, with minimal polynomial p, and y *) (* is not in Q[z_n] = Q[x_n, i] since p has odd degree. Otherwise, *) (* Gal(Q[z_n,z] / Q[z_n]) is a proper 2-group, and has a maximal subgroup *) (* P of index 2. The fixed field F of P has a generator w over Q[z_n] *) (* with w^2 in Q[z_n] \ Q[x_n], i.e. w^2 = u + 2iv with v != 0. From (3) *) (* X^4 - uX^2 - v^2 has a root x in some Q[x_m]; then x != 0 as v != 0, *) (* hence w^2 = y^2 for y = x + iv/x in Q[z_m], and y generates F. *) (* (E) - Construct conj and conclude (~40 lines): conj z is defined as *) (* conj_ n z with the n provided by (2); since each conj_ m is a morphism *) (* of order 2 and conj z = conj_ m z for any m >= n, it follows that conj *) (* is also a morphism of order 2. *) (* Note that (C), (D) and (E) only depend on Q[x_n] not containing i; the *) (* order structure is not used (hence we need not prove that the ordering of *) (* Q[x_m] is consistent with that of Q[x_n] for m >= n). *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import Order.TTheory GroupScope GRing.Theory Num.Theory. Local Open Scope ring_scope. Local Notation "p ^ f" := (map_poly f p) : ring_scope. Local Notation "p ^@" := (p ^ in_alg _) (format "p ^@"): ring_scope. Local Notation "<< E ; u >>" := <<E; u>>%VS. Local Notation Qmorphism C := {rmorphism rat -> C}. Lemma rat_algebraic_archimedean (C : numFieldType) (QtoC : Qmorphism C) : integralRange QtoC -> Num.archimedean_axiom C. Proof. move=> algC x. without loss x_ge0: x / 0 <= x by rewrite -normr_id; apply. have [-> | nz_x] := eqVneq x 0; first by exists 1; rewrite normr0. have [p mon_p px0] := algC x; exists (\sum_(j < size p) `|numq p`_j|)%N. rewrite ger0_norm // real_ltNge ?rpred_nat ?ger0_real //. apply: contraL px0 => lb_x; rewrite rootE gt_eqF // horner_coef size_map_poly. have x_gt0 k: 0 < x ^+ k by rewrite exprn_gt0 // lt_def nz_x. move: lb_x; rewrite polySpred ?monic_neq0 // !big_ord_recr coef_map /=. rewrite -lead_coefE (monicP mon_p) natrD [QtoC _]rmorph1 mul1r => lb_x. case: _.-1 (lb_x) => [|n]; first by rewrite !big_ord0 !add0r ltr01. rewrite -ltrBlDl add0r -(ler_pM2r (x_gt0 n)) -exprS. apply: lt_le_trans; rewrite mulrDl mul1r ltr_pwDr // -sumrN. rewrite natr_sum mulr_suml ler_sum // => j _. rewrite coef_map /= fmorph_eq_rat (le_trans (real_ler_norm _)) //. by rewrite rpredN rpredM ?rpred_rat ?rpredX // ger0_real. rewrite normrN normrM ler_pM //. rewrite normf_div -!intr_norm -!abszE ler_piMr ?ler0n //. by rewrite invf_le1 ?ler1n ?ltr0n absz_gt0. rewrite normrX ger0_norm ?(ltrW x_gt0) // ler_weXn2l ?leq_ord //. by rewrite (le_trans _ lb_x) // natr1 ler1n. Qed. Definition decidable_embedding sT T (f : sT -> T) := forall y, decidable (exists x, y = f x). Lemma rat_algebraic_decidable (C : fieldType) (QtoC : Qmorphism C) : integralRange QtoC -> decidable_embedding QtoC. Proof. have QtoCinj: injective QtoC by apply: fmorph_inj. pose ZtoQ : int -> rat := intr; pose ZtoC : int -> C := intr. have ZtoQinj: injective ZtoQ by apply: intr_inj. have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> m; rewrite /= rmorph_int. move=> algC x; have /sig2_eqW[q mon_q qx0] := algC x; pose d := (size q).-1. have [n ub_n]: {n | forall y, root q y -> `|y| < n}. have [n1 ub_n1] := monic_Cauchy_bound mon_q. have /monic_Cauchy_bound[n2 ub_n2]: (-1) ^+ d *: (q \Po - 'X) \is monic. rewrite monicE lead_coefZ lead_coef_comp ?size_polyN ?size_polyX // -/d. by rewrite lead_coefN lead_coefX (monicP mon_q) (mulrC 1) signrMK. exists (Num.max n1 n2) => y; rewrite ltNge ler_normr !leUx rootE. apply: contraL => /orP[]/andP[] => [/ub_n1/gt_eqF->// | _ /ub_n2/gt_eqF]. by rewrite hornerZ horner_comp !hornerE opprK mulf_eq0 signr_eq0 => /= ->. have [p [a nz_a Dq]] := rat_poly_scale q; pose N := Num.bound `|n * a%:~R|. pose xa : seq rat := [seq (m%:R - N%:R) / a%:~R | m <- iota 0 N.*2]. have [/sig2_eqW[y _ ->] | xa'x] := @mapP _ _ QtoC xa x; first by left; exists y. right=> [[y Dx]]; case: xa'x; exists y => //. have{x Dx qx0} qy0: root q y by rewrite Dx fmorph_root in qx0. have /dvdzP[b Da]: (denq y %| a)%Z. have /Gauss_dvdzl <-: coprimez (denq y) (numq y ^+ d). by rewrite coprimez_sym coprimezXl //; apply: coprime_num_den. pose p1 : {poly int} := a *: 'X^d - p. have Dp1: p1 ^ intr = a%:~R *: ('X^d - q). by rewrite rmorphB /= linearZ /= map_polyXn scalerBr Dq scalerKV ?intr_eq0. apply/dvdzP; exists (\sum_(i < d) p1`_i * numq y ^+ i * denq y ^+ (d - i.+1)). apply: ZtoQinj; rewrite /ZtoQ rmorphM mulr_suml rmorph_sum /=. transitivity ((p1 ^ intr).[y] * (denq y ^+ d)%:~R). rewrite Dp1 !hornerE (rootP qy0) subr0. by rewrite !rmorphXn /= numqE exprMn mulrA. have sz_p1: (size (p1 ^ ZtoQ)%R <= d)%N. rewrite Dp1 size_scale ?intr_eq0 //; apply/leq_sizeP=> i. rewrite leq_eqVlt eq_sym -polySpred ?monic_neq0 // coefB coefXn. case: eqP => [-> _ | _ /(nth_default 0)->//]. by rewrite -lead_coefE (monicP mon_q). rewrite (horner_coef_wide _ sz_p1) mulr_suml; apply: eq_bigr => i _. rewrite -!mulrA -exprSr coef_map !rmorphM !rmorphXn /= numqE exprMn -mulrA. by rewrite -exprD -addSnnS subnKC. pose m := `|(numq y * b + N)%R|%N. have Dm: m%:R = `|y * a%:~R + N%:R|. by rewrite pmulrn abszE intr_norm Da rmorphD !rmorphM /= numqE mulrAC mulrA. have ltr_Qnat n1 n2 : (n1%:R < n2%:R :> rat = _) := ltr_nat _ n1 n2. have ub_y: `|y * a%:~R| < N%:R. apply: le_lt_trans (archi_boundP (normr_ge0 _)); rewrite !normrM. by rewrite ler_pM // (le_trans _ (ler_norm n)) ?ltW ?ub_n. apply/mapP; exists m. rewrite mem_iota /= add0n -addnn -ltr_Qnat Dm natrD. by rewrite (le_lt_trans (ler_normD _ _)) // normr_nat ltrD2. rewrite Dm ger0_norm ?addrK ?mulfK ?intr_eq0 // -lerBlDl sub0r. by rewrite (le_trans (ler_norm _)) ?normrN ?ltW. Qed. Lemma minPoly_decidable_closure (F : fieldType) (L : closedFieldType) (FtoL : {rmorphism F -> L}) x : decidable_embedding FtoL -> integralOver FtoL x -> {p | [/\ p \is monic, root (p ^ FtoL) x & irreducible_poly p]}. Proof. move=> isF /sig2W[p /monicP mon_p px0]. have [r Dp] := closed_field_poly_normal (p ^ FtoL); pose n := size r. rewrite lead_coef_map {}mon_p rmorph1 scale1r in Dp. pose Fpx q := (q \is a polyOver isF) && root q x. have FpxF q: Fpx (q ^ FtoL) = root (q ^ FtoL) x. by rewrite /Fpx polyOver_poly // => j _; apply/sumboolP; exists q`_j. pose p_ (I : {set 'I_n}) := \prod_(i <- enum I) ('X - (r`_i)%:P). have{px0 Dp} /ex_minset[I /minsetP[/andP[FpI pIx0] minI]]: exists I, Fpx (p_ I). exists setT; suffices ->: p_ setT = p ^ FtoL by rewrite FpxF. by rewrite Dp (big_nth 0) big_mkord /p_ big_enum; apply/eq_bigl => i /[1!inE]. have{p} [p DpI]: {p | p_ I = p ^ FtoL}. exists (p_ I ^ (fun y => if isF y is left Fy then sval (sig_eqW Fy) else 0)). rewrite -map_poly_comp map_poly_id // => y /(allP FpI) /=. by rewrite unfold_in; case: (isF y) => // Fy _; case: (sig_eqW _). have mon_pI: p_ I \is monic by apply: monic_prod_XsubC. have mon_p: p \is monic by rewrite -(map_monic FtoL) -DpI. exists p; rewrite -DpI; split=> //; split=> [|q nCq q_dv_p]. by rewrite -(size_map_poly FtoL) -DpI (root_size_gt1 _ pIx0) ?monic_neq0. rewrite -dvdp_size_eqp //; apply/eqP. without loss mon_q: q nCq q_dv_p / q \is monic. move=> IHq; pose a := lead_coef q; pose q1 := a^-1 *: q. have nz_a: a != 0 by rewrite lead_coef_eq0 (dvdpN0 q_dv_p) ?monic_neq0. have /IHq IHq1: q1 \is monic by rewrite monicE lead_coefZ mulVf. by rewrite -IHq1 ?size_scale ?dvdpZl ?invr_eq0. without loss{nCq} qx0: q mon_q q_dv_p / root (q ^ FtoL) x. have /dvdpP[q1 Dp] := q_dv_p; rewrite DpI Dp rmorphM rootM -implyNb in pIx0. have mon_q1: q1 \is monic by rewrite Dp monicMr in mon_p. move=> IH; apply: (IH) (implyP pIx0 _) => //; apply: contra nCq => /IH IHq1. rewrite natr1E -(subnn (size q1)) {1}IHq1 ?Dp ?dvdp_mulr //. rewrite polySpred ?monic_neq0 //. by rewrite eqSS size_monicM ?monic_neq0 // -!subn1 subnAC addKn. have /dvdp_prod_XsubC[m Dq]: q ^ FtoL %| p_ I by rewrite DpI dvdp_map. pose B := [set j in mask m (enum I)]; have{} Dq: q ^ FtoL = p_ B. apply/eqP; rewrite -eqp_monic ?monic_map ?monic_prod_XsubC //. congr (_ %= _): Dq; apply: perm_big => //. by rewrite uniq_perm ?mask_uniq ?enum_uniq // => j; rewrite mem_enum inE. rewrite -!(size_map_poly FtoL) Dq -DpI (minI B) // -?Dq ?FpxF //. by apply/subsetP=> j /[1!inE] /mem_mask; rewrite mem_enum. Qed. Lemma alg_integral (F : fieldType) (L : fieldExtType F) : integralRange (in_alg L). Proof. move=> x; have [/polyOver1P[p Dp]] := (minPolyOver 1 x, monic_minPoly 1 x). by rewrite Dp map_monic; exists p; rewrite // -Dp root_minPoly. Qed. Prenex Implicits alg_integral. Arguments map_poly_inj {F R} f [p1 p2]. Theorem Fundamental_Theorem_of_Algebraics : {L : closedFieldType & {conj : {rmorphism L -> L} | involutive conj & ~ conj =1 id}}. Proof. have maxn3 n1 n2 n3: {m | [/\ n1 <= m, n2 <= m & n3 <= m]%N}. by exists (maxn n1 (maxn n2 n3)); apply/and3P; rewrite -!geq_max. have [C [/= QtoC algC]] := countable_algebraic_closure rat. exists C; have [i Di2] := GRing.imaginary_exists C. pose Qfield := fieldExtType rat. pose Cmorph (L : Qfield) := {rmorphism L -> C}. have pcharQ (L : Qfield): [pchar L] =i pred0 := ftrans (pchar_lalg L) (pchar_num _). have sepQ (L : Qfield) (K E : {subfield L}): separable K E. by apply/separableP=> u _; apply: pcharf0_separable. pose genQfield z L := {LtoC : Cmorph L & {u | LtoC u = z & <<1; u>> = fullv}}. have /all_tag[Q /all_tag[ofQ genQz]] z: {Qz : Qfield & genQfield z Qz}. have [|p [/monic_neq0 nzp pz0 irr_p]] := minPoly_decidable_closure _ (algC z). exact: rat_algebraic_decidable. pose Qz := SubFieldExtType pz0 irr_p. pose QzC : {rmorphism _ -> _} := @subfx_inj _ _ QtoC z p. exists Qz, QzC, (subfx_root QtoC z p); first exact: subfx_inj_root. apply/vspaceP=> u; rewrite memvf; apply/Fadjoin1_polyP. by have [q] := subfxEroot pz0 nzp u; exists q. have pQof z p: p^@ ^ ofQ z = p ^ QtoC. by rewrite -map_poly_comp; apply: eq_map_poly => x; rewrite !fmorph_eq_rat. have pQof2 z p u: ofQ z p^@.[u] = (p ^ QtoC).[ofQ z u]. by rewrite -horner_map pQof. have PET_Qz z (E : {subfield Q z}): {u | <<1; u>> = E}. exists (separable_generator 1 E). by rewrite -eq_adjoin_separable_generator ?sub1v. pose gen z x := exists q, x = (q ^ QtoC).[z]. have PET2 x y: {z | gen z x & gen z y}. pose Gxy := (x, y) = let: (p, q, z) := _ in ((p ^ QtoC).[z], (q ^ QtoC).[z]). suffices [[[p q] z] []]: {w | Gxy w} by exists z; [exists p | exists q]. apply/sig_eqW; have /integral_algebraic[px nz_px pxx0] := algC x. have /integral_algebraic[py nz_py pyy0] := algC y. have [n [[p Dx] [q Dy]]] := pchar0_PET nz_px pxx0 nz_py pyy0 (pchar_num _). by exists (p, q, y *+ n - x); congr (_, _). have gen_inQ z x: gen z x -> {u | ofQ z u = x}. have [u Dz _] := genQz z => /sig_eqW[q ->]. by exists q^@.[u]; rewrite pQof2 Dz. have gen_ofP z u v: reflect (gen (ofQ z u) (ofQ z v)) (v \in <<1; u>>). apply: (iffP Fadjoin1_polyP) => [[q ->]|]; first by rewrite pQof2; exists q. by case=> q; rewrite -pQof2 => /fmorph_inj->; exists q. have /all_tag[sQ genP] z: {s : pred C & forall x, reflect (gen z x) (x \in s)}. apply: all_tag (fun x => reflect (gen z x)) _ => x. have [w /gen_inQ[u <-] /gen_inQ[v <-]] := PET2 z x. by exists (v \in <<1; u>>)%VS; apply: gen_ofP. have sQtrans: transitive (fun x z => x \in sQ z). move=> x y z /genP[p ->] /genP[q ->]; apply/genP; exists (p \Po q). by rewrite map_comp_poly horner_comp. have sQid z: z \in sQ z by apply/genP; exists 'X; rewrite map_polyX hornerX. have{gen_ofP} sQof2 z u v: (ofQ z u \in sQ (ofQ z v)) = (u \in <<1; v>>%VS). exact/genP/(gen_ofP z). have sQof z v: ofQ z v \in sQ z. by have [u Dz defQz] := genQz z; rewrite -[in sQ z]Dz sQof2 defQz memvf. have{gen_inQ} sQ_inQ z x z_x := gen_inQ z x (genP z x z_x). have /all_sig[inQ inQ_K] z: {inQ | {in sQ z, cancel inQ (ofQ z)}}. by apply: all_sig_cond (fun x u => ofQ z u = x) 0 _ => x /sQ_inQ. have ofQ_K z: cancel (ofQ z) (inQ z). by move=> x; have /inQ_K/fmorph_inj := sQof z x. have sQring z: divring_closed (sQ z). have sQ_1: 1 \in sQ z by rewrite -(rmorph1 (ofQ z)) sQof. by split=> // x y /inQ_K<- /inQ_K<- /=; rewrite -(rmorphB, fmorph_div) sQof. pose sQzM z := GRing.isZmodClosed.Build _ _ (sQring z : zmod_closed _). pose sQmM z := GRing.isMulClosed.Build _ _ (sQring z). pose sQiM z := GRing.isInvClosed.Build _ _ (sQring z). pose sQC z : divringClosed _ := HB.pack (sQ z) (sQzM z) (sQmM z) (sQiM z). pose morph_ofQ x z Qxz := forall u, ofQ z (Qxz u) = ofQ x u. have QtoQ z x: x \in sQ z -> {Qxz : 'AHom(Q x, Q z) | morph_ofQ x z Qxz}. move=> z_x; pose Qxz u := inQ z (ofQ x u). have QxzE u: ofQ z (Qxz u) = ofQ x u by apply/inQ_K/(sQtrans x). have Qxza : zmod_morphism Qxz. by move=> u v; apply: (canLR (ofQ_K z)); rewrite !rmorphB !QxzE. have Qxzm : monoid_morphism Qxz. by split=> [|u v]; apply: (canLR (ofQ_K z)); rewrite ?rmorph1 ?rmorphM /= ?QxzE. have QxzaM := GRing.isZmodMorphism.Build _ _ _ Qxza. have QxzmM := GRing.isMonoidMorphism.Build _ _ _ Qxzm. have QxzlM := GRing.isScalable.Build _ _ _ _ _ (rat_linear Qxza). pose QxzLRM : {lrmorphism _ -> _} := HB.pack Qxz QxzaM QxzmM QxzlM. by exists (linfun_ahom QxzLRM) => u; rewrite lfunE QxzE. pose sQs z s := all (mem (sQ z)) s. have inQsK z s: sQs z s -> map (ofQ z) (map (inQ z) s) = s. by rewrite -map_comp => /allP/(_ _ _)/inQ_K; apply: map_id_in. have inQpK z p: p \is a polyOver (sQ z) -> (p ^ inQ z) ^ ofQ z = p. by move=> /allP/(_ _ _)/inQ_K/=/map_poly_id; rewrite -map_poly_comp. have{gen PET2 genP} PET s: {z | sQs z s & <<1 & map (inQ z) s>>%VS = fullv}. have [y /inQsK Ds]: {y | sQs y s}. elim: s => [|x s /= [y IHs]]; first by exists 0. have [z /genP z_x /genP z_y] := PET2 x y. by exists z; rewrite /= {x}z_x; apply: sub_all IHs => x /sQtrans/= ->. have [w defQs] := PET_Qz _ <<1 & map (inQ y) s>>%AS; pose z := ofQ y w. have z_s: sQs z s. rewrite -Ds /sQs all_map; apply/allP=> u s_u /=. by rewrite sQof2 defQs seqv_sub_adjoin. have [[u Dz defQz] [Qzy QzyE]] := (genQz z, QtoQ y z (sQof y w)). exists z => //; apply/eqP; rewrite eqEsubv subvf /= -defQz. rewrite -(limg_ker0 _ _ (AHom_lker0 Qzy)) aimg_adjoin_seq aimg_adjoin aimg1. rewrite -[map _ _](mapK (ofQ_K y)) -(map_comp (ofQ y)) (eq_map QzyE) inQsK //. by rewrite -defQs -(canLR (ofQ_K y) Dz) -QzyE ofQ_K. pose rp s := \prod_(z <- s) ('X - z%:P). have map_rp (f : {rmorphism _ -> _}) s: rp _ s ^ f = rp _ (map f s). rewrite rmorph_prod /rp big_map; apply: eq_bigr => x _ /=. by rewrite rmorphB /= map_polyX map_polyC. pose is_Gal z := SplittingField.axiom (Q z). have galQ x: {z | x \in sQ z & is_Gal z}. have /sig2W[p mon_p pz0] := algC x. have [s Dp] := closed_field_poly_normal (p ^ QtoC). rewrite (monicP _) ?monic_map // scale1r in Dp; have [z z_s defQz] := PET s. exists z; first by apply/(allP z_s); rewrite -root_prod_XsubC -Dp. exists p^@; first exact: alg_polyOver. exists (map (inQ z) s); last by apply/vspaceP=> u; rewrite defQz memvf. by rewrite -(eqp_map (ofQ z)) pQof Dp map_rp inQsK ?eqpxx. pose is_realC x := {R : archiRealFieldType & {rmorphism Q x -> R}}. pose realC := {x : C & is_realC x}. pose has_Rroot (xR : realC) p c (Rx := sQ (tag xR)) := [&& p \is a polyOver Rx, p \is monic, c \in Rx & p.[0] == - c ^+ 2]. pose root_in (xR : realC) p := exists2 w, w \in sQ (tag xR) & root p w. pose extendsR (xR yR : realC) := tag xR \in sQ (tag yR). have add_Rroot xR p c: {yR | extendsR xR yR & has_Rroot xR p c -> root_in yR p}. rewrite {}/extendsR; case: (has_Rroot xR p c) / and4P; last by exists xR. case: xR => x [R QxR] /= [/inQpK <-]; move: (p ^ _) => {}p mon_p /inQ_K<- Dc. have{c Dc} p0_le0: (p ^ QxR).[0] <= 0. rewrite horner_coef0 coef_map -[p`_0]ofQ_K -coef_map -horner_coef0 (eqP Dc). by rewrite -rmorphXn -rmorphN ofQ_K /= rmorphN rmorphXn oppr_le0 sqr_ge0. have [s Dp] := closed_field_poly_normal (p ^ ofQ x). have{Dp} /all_and2[s_p p_s] y: root (p ^ ofQ x) y <-> (y \in s). by rewrite Dp (monicP mon_p) scale1r root_prod_XsubC. rewrite map_monic in mon_p; have [z /andP[z_x /allP/=z_s] _] := PET (x :: s). have{z_x} [[Qxz QxzE] Dx] := (QtoQ z x z_x, inQ_K z x z_x). pose Qx := <<1; inQ z x>>%AS. have pQwx q1: q1 \is a polyOver Qx -> {q | q1 = q ^ Qxz}. move/polyOverP=> Qx_q1; exists ((q1 ^ ofQ z) ^ inQ x). apply: (map_poly_inj (ofQ z)); rewrite -map_poly_comp (eq_map_poly QxzE). by rewrite inQpK ?polyOver_poly // => j _; rewrite -Dx sQof2 Qx_q1. have /all_sig[t_ Dt] u: {t | <<1; t>> = <<Qx; u>>} by apply: PET_Qz. suffices{p_s}[u Ry px0]: {u : Q z & is_realC (ofQ z (t_ u)) & ofQ z u \in s}. exists (Tagged is_realC Ry) => [|_] /=. by rewrite -Dx sQof2 Dt subvP_adjoin ?memv_adjoin. by exists (ofQ z u); rewrite ?p_s // sQof2 Dt memv_adjoin. without loss{z_s s_p} [u Dp s_y]: p mon_p p0_le0 / {u | minPoly Qx u = p ^ Qxz & ofQ z u \in s}. - move=> IHp; move: {2}_.+1 (ltnSn (size p)) => d. elim: d => // d IHd in p mon_p s_p p0_le0 *; rewrite ltnS => le_p_d. have /closed_rootP/sig_eqW[y py0]: size (p ^ ofQ x) != 1. rewrite size_map_poly size_poly_eq1 eqp_monic ?rpred1 //. by apply: contraTneq p0_le0 => ->; rewrite rmorph1 hornerC lt_geF ?ltr01. have /s_p s_y := py0; have /z_s/sQ_inQ[u Dy] := s_y. have /pQwx[q Dq] := minPolyOver Qx u. have mon_q: q \is monic by have:= monic_minPoly Qx u; rewrite Dq map_monic. have /dvdpP/sig_eqW[r Dp]: q %| p. rewrite -(dvdp_map Qxz) -Dq minPoly_dvdp //. by apply: polyOver_poly => j _; rewrite -sQof2 QxzE Dx. by rewrite -(fmorph_root (ofQ z)) Dy -map_poly_comp (eq_map_poly QxzE). have mon_r: r \is monic by rewrite Dp monicMr in mon_p. have [q0_le0 | q0_gt0] := lerP ((q ^ QxR).[0]) 0. by apply: (IHp q) => //; exists u; rewrite ?Dy. have r0_le0: (r ^ QxR).[0] <= 0. by rewrite -(ler_pM2r q0_gt0) mul0r -hornerM -rmorphM -Dp. apply: (IHd r mon_r) => // [w rw0|]. by rewrite s_p // Dp rmorphM rootM rw0. apply: leq_trans le_p_d; rewrite Dp size_Mmonic ?monic_neq0 // addnC. by rewrite -(size_map_poly Qxz q) -Dq size_minPoly !ltnS leq_addl. exists u => {s s_y}//; set y := ofQ z (t_ u); set p1 := minPoly Qx u in Dp. have /QtoQ[Qyz QyzE]: y \in sQ z := sQof z (t_ u). pose q1_ v := Fadjoin_poly Qx u (Qyz v). have{} QyzE v: Qyz v = (q1_ v).[u]. by rewrite Fadjoin_poly_eq // -Dt -sQof2 QyzE sQof. have /all_sig2[q_ coqp Dq] v: {q | v != 0 -> coprimep p q & q ^ Qxz = q1_ v}. have /pQwx[q Dq]: q1_ v \is a polyOver Qx by apply: Fadjoin_polyOver. exists q => // nz_v; rewrite -(coprimep_map Qxz) -Dp -Dq -gcdp_eqp1. have /minPoly_irr/orP[] // := dvdp_gcdl p1 (q1_ v). by rewrite gcdp_polyOver ?minPolyOver ?Fadjoin_polyOver. rewrite -/p1 {1}/eqp dvdp_gcd => /and3P[_ _ /dvdp_leq/=/implyP]. rewrite size_minPoly ltnNge size_poly (contraNneq _ nz_v) // => q1v0. by rewrite -(fmorph_eq0 Qyz) /= QyzE q1v0 horner0. pose h2 : R := 2^-1; have nz2: 2 != 0 :> R by rewrite pnatr_eq0. pose itv ab := [pred c : R | ab.1 <= c <= ab.2]. pose wid ab : R := ab.2 - ab.1; pose mid ab := (ab.1 + ab.2) * h2. pose sub_itv ab cd := cd.1 <= ab.1 :> R /\ ab.2 <= cd.2 :> R. pose xup q ab := [/\ q.[ab.1] <= 0, q.[ab.2] >= 0 & ab.1 <= ab.2 :> R]. pose narrow q ab (c := mid ab) := if q.[c] >= 0 then (ab.1, c) else (c, ab.2). pose find k q := iter k (narrow q). have findP k q ab (cd := find k q ab): xup q ab -> [/\ xup q cd, sub_itv cd ab & wid cd = wid ab / (2 ^ k)%:R]. - rewrite {}/cd; case: ab => a b xq_ab. elim: k => /= [|k]; first by rewrite divr1. case: (find k q _) => c d [[/= qc_le0 qd_ge0 le_cd] [/= le_ac le_db] Dcd]. have [/= le_ce le_ed] := midf_le le_cd; set e := _ / _ in le_ce le_ed. rewrite expnSr natrM invfM mulrA -{}Dcd /narrow /= -[mid _]/e. have [qe_ge0 // | /ltW qe_le0] := lerP 0 q.[e]. do ?split=> //=; [exact: (le_trans le_ed) | apply: canRL (mulfK nz2) _]. by rewrite mulrBl divfK // mulr_natr opprD addrACA subrr add0r. do ?split=> //=; [exact: (le_trans le_ac) | apply: canRL (mulfK nz2) _]. by rewrite mulrBl divfK // mulr_natr opprD addrACA subrr addr0. have find_root r q ab: xup q ab -> {n | forall x, x \in itv (find n q ab) ->`|(r * q).[x]| < h2}. - move=> xab; have ub_ab := poly_itv_bound _ ab.1 ab.2. have [Mu MuP] := ub_ab r; have /all_sig[Mq MqP] j := ub_ab q^`N(j). pose d := wid ab; pose dq := \poly_(i < (size q).-1) Mq i.+1. have d_ge0: 0 <= d by rewrite subr_ge0; case: xab. have [Mdq MdqP] := poly_disk_bound dq d. pose n := Num.bound (Mu * Mdq * d); exists n => c /andP[]. have{xab} [[]] := findP n _ _ xab; case: (find n q ab) => a1 b1 /=. rewrite -/d => qa1_le0 qb1_ge0 le_ab1 [/= le_aa1 le_b1b] Dab1 le_a1c le_cb1. have /MuP lbMu: c \in itv ab. by rewrite inE (le_trans le_aa1) ?(le_trans le_cb1). have Mu_ge0: 0 <= Mu by rewrite (le_trans _ lbMu). have Mdq_ge0: 0 <= Mdq. by rewrite (le_trans _ (MdqP 0 _)) ?normr0. suffices lb1 a2 b2 (ab1 := (a1, b1)) (ab2 := (a2, b2)) : xup q ab2 /\ sub_itv ab2 ab1 -> q.[b2] - q.[a2] <= Mdq * wid ab1. + apply: le_lt_trans (_ : Mu * Mdq * wid (a1, b1) < h2); last first. rewrite {}Dab1 mulrA ltr_pdivrMr ?ltr0n ?expn_gt0 //. rewrite (lt_le_trans (archi_boundP _)) ?mulr_ge0 ?ltr_nat // -/n. rewrite ler_pdivlMl ?ltr0n // -natrM ler_nat. by case: n => // n; rewrite expnS leq_pmul2l // ltn_expl. rewrite -mulrA hornerM normrM ler_pM //. have [/ltW qc_le0 | qc_ge0] := ltrP q.[c] 0. by apply: le_trans (lb1 c b1 _); rewrite ?ler0_norm ?ler_wpDl. by apply: le_trans (lb1 a1 c _); rewrite ?ger0_norm ?ler_wpDr ?oppr_ge0. case{c le_a1c le_cb1 lbMu}=> [[/=qa2_le0 qb2_ge0 le_ab2] [/=le_a12 le_b21]]. pose h := b2 - a2; have h_ge0: 0 <= h by rewrite subr_ge0. have [-> | nz_q] := eqVneq q 0. by rewrite !horner0 subrr mulr_ge0 ?subr_ge0. rewrite -(subrK a2 b2) (addrC h) (nderiv_taylor q (mulrC a2 h)). rewrite (polySpred nz_q) big_ord_recl /= mulr1 nderivn0 addrC addKr. have [le_aa2 le_b2b] := (le_trans le_aa1 le_a12, le_trans le_b21 le_b1b). have /MqP MqPx1: a2 \in itv ab by rewrite inE le_aa2 (le_trans le_ab2). apply: le_trans (le_trans (ler_norm _) (ler_norm_sum _ _ _)) _. apply: le_trans (_ : `|dq.[h] * h| <= _); last first. by rewrite normrM ler_pM ?normr_ge0 ?MdqP // ?ger0_norm ?lerB ?h_ge0. rewrite horner_poly ger0_norm ?mulr_ge0 ?sumr_ge0 // => [|j _]; last first. by rewrite mulr_ge0 ?exprn_ge0 // (le_trans _ (MqPx1 _)). rewrite mulr_suml ler_sum // => j _; rewrite normrM -mulrA -exprSr. by rewrite ler_pM // normrX ger0_norm. have [ab0 xab0]: {ab | xup (p ^ QxR) ab}. have /monic_Cauchy_bound[b pb_gt0]: p ^ QxR \is monic by apply: monic_map. by exists (0, `|b|); rewrite /xup normr_ge0 p0_le0 ltW ?pb_gt0 ?ler_norm. pose ab_ n := find n (p ^ QxR) ab0; pose Iab_ n := itv (ab_ n). pose lim v a := (q_ v ^ QxR).[a]; pose nlim v n := lim v (ab_ n).2. have lim0 a: lim 0 a = 0. rewrite /lim; suffices /eqP ->: q_ 0 == 0 by rewrite rmorph0 horner0. by rewrite -(map_poly_eq0 Qxz) Dq /q1_ !raddf0. have limN v a: lim (- v) a = - lim v a. rewrite /lim; suffices ->: q_ (- v) = - q_ v by rewrite rmorphN hornerN. apply: (map_poly_inj Qxz). by rewrite Dq /q1_ (raddfN _ v) (raddfN _ (Qyz v)) [RHS]raddfN /= Dq. pose lim_nz n v := exists2 e, e > 0 & {in Iab_ n, forall a, e < `|lim v a| }. have /(all_sig_cond 0)[n_ nzP] v: v != 0 -> {n | lim_nz n v}. move=> nz_v; do [move/(_ v nz_v); rewrite -(coprimep_map QxR)] in coqp. have /sig_eqW[r r_pq_1] := Bezout_eq1_coprimepP _ _ coqp. have /(find_root r.1)[n ub_rp] := xab0; exists n. have [M Mgt0 ubM]: {M | 0 < M & {in Iab_ n, forall a, `|r.2.[a]| <= M}}. have [M ubM] := poly_itv_bound r.2 (ab_ n).1 (ab_ n).2. exists (Num.max 1 M) => [|s /ubM vM]; first by rewrite lt_max ltr01. by rewrite le_max orbC vM. exists (h2 / M) => [|a xn_a]; first by rewrite divr_gt0 ?invr_gt0 ?ltr0n. rewrite ltr_pdivrMr // -(ltrD2l h2) -mulr2n -mulr_natl divff //. rewrite -normr1 -(hornerC 1 a) -[1%:P]r_pq_1 hornerD. rewrite ?(le_lt_trans (ler_normD _ _)) ?ltr_leD ?ub_rp //. by rewrite mulrC hornerM normrM ler_wpM2l ?ubM. have ab_le m n: (m <= n)%N -> (ab_ n).2 \in Iab_ m. move/subnKC=> <-; move: {n}(n - m)%N => n; rewrite /ab_. have /(findP m)[/(findP n)[[_ _]]] := xab0. rewrite /find -iterD -!/(find _ _) -!/(ab_ _) addnC !inE. by move: (ab_ _) => /= ab_mn le_ab_mn [/le_trans->]. pose lt v w := 0 < nlim (w - v) (n_ (w - v)). have posN v: lt 0 (- v) = lt v 0 by rewrite /lt subr0 add0r. have posB v w: lt 0 (w - v) = lt v w by rewrite /lt subr0. have posE n v: (n_ v <= n)%N -> lt 0 v = (0 < nlim v n). rewrite /lt subr0 /nlim => /ab_le; set a := _.2; set b := _.2 => Iv_a. have [-> | /nzP[e e_gt0]] := eqVneq v 0; first by rewrite !lim0 ltxx. move: (n_ v) => m in Iv_a b * => v_gte. without loss lt0v: v v_gte / 0 < lim v b. move=> IHv; apply/idP/idP => [v_gt0 | /ltW]; first by rewrite -IHv. rewrite lt_def -normr_gt0 ?(lt_trans _ (v_gte _ _)) ?ab_le //=. rewrite !leNgt -!oppr_gt0 -!limN; apply: contra => v_lt0. by rewrite -IHv // => c /v_gte; rewrite limN normrN. rewrite lt0v (lt_trans e_gt0) ?(lt_le_trans (v_gte a Iv_a)) //. rewrite ger0_norm // leNgt; apply/negP=> /ltW lev0. have [le_a le_ab] : _ /\ a <= b := andP Iv_a. have xab: xup (q_ v ^ QxR) (a, b) by move/ltW in lt0v. have /(find_root (h2 / e)%:P)[n1] := xab; have /(findP n1)[[_ _]] := xab. case: (find _ _ _) => c d /= le_cd [/= le_ac le_db] _ /(_ c)/implyP. rewrite inE lexx le_cd hornerM hornerC normrM le_gtF //. rewrite ger0_norm ?divr_ge0 ?invr_ge0 ?ler0n ?(ltW e_gt0) // mulrAC. rewrite ler_pdivlMr // ler_wpM2l ?invr_ge0 ?ler0n // ltW // v_gte //=. by rewrite inE -/b (le_trans le_a) //= (le_trans le_cd). pose lim_pos m v := exists2 e, e > 0 & forall n, (m <= n)%N -> e < nlim v n. have posP v: reflect (exists m, lim_pos m v) (lt 0 v). apply: (iffP idP) => [v_gt0|[m [e e_gt0 v_gte]]]; last first. by rewrite (posE _ _ (leq_maxl _ m)) (lt_trans e_gt0) ?v_gte ?leq_maxr. have [|e e_gt0 v_gte] := nzP v. by apply: contraTneq v_gt0 => ->; rewrite /lt subr0 /nlim lim0 ltxx. exists (n_ v), e => // n le_vn; rewrite (posE n) // in v_gt0. by rewrite -(ger0_norm (ltW v_gt0)) v_gte ?ab_le. have posNneg v: lt 0 v -> ~~ lt v 0. case/posP=> m [d d_gt0 v_gtd]; rewrite -posN. apply: contraL d_gt0 => /posP[n [e e_gt0 nv_gte]]. rewrite lt_gtF // (lt_trans (v_gtd _ (leq_maxl m n))) // -oppr_gt0. by rewrite /nlim -limN (lt_trans e_gt0) ?nv_gte ?leq_maxr. have posVneg v: v != 0 -> lt 0 v || lt v 0. case/nzP=> e e_gt0 v_gte; rewrite -posN; set w := - v. have [m [le_vm le_wm _]] := maxn3 (n_ v) (n_ w) 0; rewrite !(posE m) //. by rewrite /nlim limN -ltr_normr (lt_trans e_gt0) ?v_gte ?ab_le. have posD v w: lt 0 v -> lt 0 w -> lt 0 (v + w). move=> /posP[m [d d_gt0 v_gtd]] /posP[n [e e_gt0 w_gte]]. apply/posP; exists (maxn m n), (d + e) => [|k]; first exact: addr_gt0. rewrite geq_max => /andP[le_mk le_nk]; rewrite /nlim /lim. have ->: q_ (v + w) = q_ v + q_ w. by apply: (map_poly_inj Qxz); rewrite rmorphD /= !{1}Dq /q1_ !raddfD. by rewrite rmorphD hornerD ltrD ?v_gtd ?w_gte. have posM v w: lt 0 v -> lt 0 w -> lt 0 (v * w). move=> /posP[m [d d_gt0 v_gtd]] /posP[n [e e_gt0 w_gte]]. have /dvdpP[r /(canRL (subrK _))Dqvw]: p %| q_ (v * w) - q_ v * q_ w. rewrite -(dvdp_map Qxz) rmorphB rmorphM /= !Dq -Dp minPoly_dvdp //. by rewrite rpredB 1?rpredM ?Fadjoin_polyOver. by rewrite rootE !hornerE -!QyzE rmorphM subrr. have /(find_root ((d * e)^-1 *: r ^ QxR))[N ub_rp] := xab0. pose f := d * e * h2; apply/posP; exists (maxn N (maxn m n)), f => [|k]. by rewrite !mulr_gt0 ?invr_gt0 ?ltr0n. rewrite !geq_max => /and3P[/ab_le/ub_rp{}ub_rp le_mk le_nk]. rewrite -(ltrD2r f) -mulr2n -mulr_natr divfK // /nlim /lim Dqvw. rewrite rmorphD hornerD /= -addrA -ltrBlDl ler_ltD //. by rewrite rmorphM hornerM ler_pM ?ltW ?v_gtd ?w_gte. rewrite -ltr_pdivrMl ?mulr_gt0 // (le_lt_trans _ ub_rp) //. by rewrite -scalerAl hornerZ -rmorphM mulrN -normrN ler_norm. pose le v w := (v == w) || lt v w. pose abs v := if le 0 v then v else - v. have absN v: abs (- v) = abs v. rewrite /abs /le !(eq_sym 0) oppr_eq0 opprK posN. have [-> | /posVneg/orP[v_gt0 | v_lt0]] := eqVneq; first by rewrite oppr0. by rewrite v_gt0 /= -if_neg posNneg. by rewrite v_lt0 /= -if_neg -(opprK v) posN posNneg ?posN. have absE v: le 0 v -> abs v = v by rewrite /abs => ->. pose RyM := Num.IntegralDomain_isLtReal.Build (Q y) posD posM posNneg posB posVneg absN absE (rrefl _). pose Ry : realFieldType := HB.pack (Q y) RyM. have QisArchi : Num.NumDomain_bounded_isArchimedean Ry. by constructor; apply: (@rat_algebraic_archimedean Ry _ alg_integral). exists (HB.pack_for archiRealFieldType _ QisArchi); apply: idfun. have some_realC: realC. suffices /all_sig[f QfK] x: {a | in_alg (Q 0) a = x}. have fA : zmod_morphism f. exact: can2_zmod_morphism (inj_can_sym QfK (fmorph_inj _)) QfK. have fM : monoid_morphism f. exact: can2_monoid_morphism (inj_can_sym QfK (fmorph_inj _)) QfK. pose faM := GRing.isZmodMorphism.Build _ _ _ fA. pose fmM := GRing.isMonoidMorphism.Build _ _ _ fM. pose fRM : {rmorphism _ -> _} := HB.pack f faM fmM. by exists 0, rat; exact: fRM. have /Fadjoin1_polyP/sig_eqW[q]: x \in <<1; 0>>%VS by rewrite -sQof2 rmorph0. by exists q.[0]; rewrite -horner_map rmorph0. pose fix xR n : realC := if n isn't n'.+1 then some_realC else if unpickle (nth 0 (CodeSeq.decode n') 1) isn't Some (p, c) then xR n' else tag (add_Rroot (xR n') p c). pose x_ n := tag (xR n). have sRle m n: (m <= n)%N -> {subset sQ (x_ m) <= sQ (x_ n)}. move/subnK <-; elim: {n}(n - m)%N => // n IHn x /IHn{IHn}Rx. rewrite addSn /x_ /=; case: (unpickle _) => [[p c]|] //=. by case: (add_Rroot _ _ _) => yR /= /(sQtrans _ x)->. have xRroot n p c: has_Rroot (xR n) p c -> {m | n <= m & root_in (xR m) p}%N. case/and4P=> Rp mon_p Rc Dc; pose m := CodeSeq.code [:: n; pickle (p, c)]. have le_n_m: (n <= m)%N by apply/ltnW/(allP (CodeSeq.ltn_code _))/mem_head. exists m.+1; rewrite ?leqW /x_ //= CodeSeq.codeK pickleK. case: (add_Rroot _ _ _) => yR /= _; apply; apply/and4P. by split=> //; first apply: polyOverS Rp; apply: (sRle n). have /all_sig[z_ /all_and3[Ri_R Ri_i defRi]] n (x := x_ n): {z | [/\ x \in sQ z, i \in sQ z & <<<<1; inQ z x>>; inQ z i>> = fullv]}. - have [z /and3P[z_x z_i _] Dzi] := PET [:: x; i]. by exists z; rewrite -adjoin_seq1 -adjoin_cons. pose i_ n := inQ (z_ n) i; pose R_ n := <<1; inQ (z_ n) (x_ n)>>%AS. have memRi n: <<R_ n; i_ n>> =i predT by move=> u; rewrite defRi memvf. have sCle m n: (m <= n)%N -> {subset sQ (z_ m) <= sQ (z_ n)}. move/sRle=> Rmn _ /sQ_inQ[u <-]. have /Fadjoin_polyP[p /polyOverP Rp ->] := memRi m u. rewrite -horner_map inQ_K ?(@rpred_horner _ (sQC _)) //=. apply/polyOver_poly=> j _. by apply: sQtrans (Ri_R n); rewrite Rmn // -(inQ_K _ _ (Ri_R m)) sQof2. have R'i n: i \notin sQ (x_ n). rewrite /x_; case: (xR n) => x [Rn QxR] /=. apply: contraL (@ltr01 Rn) => /sQ_inQ[v Di]. suffices /eqP <-: - QxR v ^+ 2 == 1 by rewrite oppr_gt0 -leNgt sqr_ge0. rewrite -rmorphXn -rmorphN fmorph_eq1 -(fmorph_eq1 (ofQ x)) rmorphN eqr_oppLR. by rewrite rmorphXn /= Di Di2. have szX2_1: size ('X^2 + 1) = 3%N. by move=> R; rewrite size_polyDl ?size_polyXn ?size_poly1. have minp_i n (p_i := minPoly (R_ n) (i_ n)): p_i = 'X^2 + 1. have p_dv_X2_1: p_i %| 'X^2 + 1. rewrite minPoly_dvdp ?rpredD ?rpredX ?rpred1 ?polyOverX //. rewrite -(fmorph_root (ofQ _)) inQ_K // rmorphD rmorph1 /= map_polyXn. by rewrite rootE hornerD hornerXn hornerC Di2 addNr. apply/eqP; rewrite -eqp_monic ?monic_minPoly //; last first. by rewrite monicE lead_coefE szX2_1 coefD coefXn coefC addr0. rewrite -dvdp_size_eqp // eqn_leq dvdp_leq -?size_poly_eq0 ?szX2_1 //= ltnNge. by rewrite size_minPoly ltnS leq_eqVlt orbF adjoin_deg_eq1 -sQof2 !inQ_K. have /all_sig[n_ FTA] z: {n | z \in sQ (z_ n)}. without loss [z_i gal_z]: z / i \in sQ z /\ is_Gal z. have [y /and3P[/sQtrans y_z /sQtrans y_i _] _] := PET [:: z; i]. have [t /sQtrans t_y gal_t] := galQ y. by case/(_ t)=> [|n]; last exists n; rewrite ?y_z ?y_i ?t_y. apply/sig_eqW; have n := 0%N. have [p]: exists p, [&& p \is monic, root p z & p \is a polyOver (sQ (z_ n))]. have [p mon_p pz0] := algC z; exists (p ^ QtoC). by rewrite map_monic mon_p pz0 -(pQof (z_ n)); apply/polyOver_poly. have [d lepd] := ubnP (size p); elim: d => // d IHd in p n lepd * => pz0. have [t [t_C t_z gal_t]]: exists t, [/\ z_ n \in sQ t, z \in sQ t & is_Gal t]. have [y /and3P[y_C y_z _]] := PET [:: z_ n; z]. by have [t /(sQtrans y)t_y] := galQ y; exists t; rewrite !t_y. pose QtMixin := FieldExt_isSplittingField.Build _ (Q t) gal_t. pose Qt : splittingFieldType rat := HB.pack (Q t) QtMixin. have /QtoQ[CnQt CnQtE] := t_C. pose Rn : {subfield Qt} := (CnQt @: R_ n)%AS; pose i_t : Qt := CnQt (i_ n). pose Cn : {subfield Qt} := <<Rn; i_t>>%AS. have defCn: Cn = limg CnQt :> {vspace Q t} by rewrite /= -aimg_adjoin defRi. have memRn u: (u \in Rn) = (ofQ t u \in sQ (x_ n)). by rewrite /= aimg_adjoin aimg1 -sQof2 CnQtE inQ_K. have memCn u: (u \in Cn) = (ofQ t u \in sQ (z_ n)). have [v Dv genCn] := genQz (z_ n). by rewrite -Dv -CnQtE sQof2 defCn -genCn aimg_adjoin aimg1. have Dit: ofQ t i_t = i by rewrite CnQtE inQ_K. have Dit2: i_t ^+ 2 = -1. by apply: (fmorph_inj (ofQ t)); rewrite rmorphXn rmorphN1 /= Dit. have dimCn: \dim_Rn Cn = 2%N. rewrite -adjoin_degreeE adjoin_degree_aimg. by apply: succn_inj; rewrite -size_minPoly minp_i szX2_1. have /sQ_inQ[u_z Dz] := t_z; pose Rz := <<Cn; u_z>>%AS. have{p lepd pz0} le_Rz_d: (\dim_Cn Rz < d)%N. rewrite -ltnS -adjoin_degreeE -size_minPoly (leq_trans _ lepd) // !ltnS. have{pz0} [mon_p pz0 Cp] := and3P pz0. have{Cp} Dp: ((p ^ inQ (z_ n)) ^ CnQt) ^ ofQ t = p. by rewrite -map_poly_comp (eq_map_poly CnQtE) inQpK. rewrite -Dp size_map_poly dvdp_leq ?monic_neq0 -?(map_monic (ofQ _)) ?Dp //. rewrite defCn minPoly_dvdp //; try by rewrite -(fmorph_root (ofQ t)) Dz Dp. by apply/polyOver_poly=> j _; rewrite memv_img ?memvf. have [sRCn sCnRz]: (Rn <= Cn)%VS /\ (Cn <= Rz)%VS by rewrite !subv_adjoin. have sRnRz := subv_trans sRCn sCnRz. have{gal_z} galRz: galois Rn Rz. apply/and3P; split; [by []|by apply: sepQ|]. apply/splitting_normalField=> //. pose QzMixin := FieldExt_isSplittingField.Build _ (Q z) gal_z. pose Qz : splittingFieldType _ := HB.pack (Q z) QzMixin. pose u : Qz := inQ z z. have /QtoQ[Qzt QztE] := t_z; exists (minPoly 1 u ^ Qzt). have /polyOver1P[q ->] := minPolyOver 1 u; apply/polyOver_poly=> j _. by rewrite coef_map linearZZ rmorph1 rpredZ ?rpred1. have [s /eqP Ds] := splitting_field_normal 1 u. rewrite Ds; exists (map Qzt s); first by rewrite map_rp eqpxx. apply/eqP; rewrite eqEsubv; apply/andP; split. apply/Fadjoin_seqP; split=> // _ /mapP[w s_w ->]. by rewrite (subvP (adjoinSl u_z (sub1v _))) // -sQof2 Dz QztE. rewrite /= adjoinC (Fadjoin_idP _) -/Rz; last first. by rewrite (subvP (adjoinSl _ (sub1v _))) // -sQof2 Dz Dit. rewrite /= -adjoin_seq1 adjoin_seqSr //; apply/allP=> /=; rewrite andbT. rewrite -(mem_map (fmorph_inj (ofQ _))) -map_comp (eq_map QztE); apply/mapP. by exists u; rewrite ?inQ_K // -root_prod_XsubC -Ds root_minPoly. have galCz: galois Cn Rz by rewrite (galoisS _ galRz) ?sRCn. have [Cz | C'z]:= boolP (u_z \in Cn); first by exists n; rewrite -Dz -memCn. pose G := 'Gal(Rz / Cn)%G; have{C'z} ntG: G :!=: 1%g. rewrite trivg_card1 -galois_dim 1?(galoisS _ galCz) ?subvv //=. by rewrite -adjoin_degreeE adjoin_deg_eq1. pose extRz m := exists2 w, ofQ t w \in sQ (z_ m) & w \in [predD Rz & Cn]. suffices [m le_n_m [w Cw /andP[C'w Rz_w]]]: exists2 m, (n <= m)%N & extRz m. pose p := minPoly <<Cn; w>> u_z; apply: (IHd (p ^ ofQ t) m). apply: leq_trans le_Rz_d; rewrite size_map_poly size_minPoly ltnS. rewrite adjoin_degreeE adjoinC (addv_idPl Rz_w) agenv_id. rewrite ltn_divLR ?adim_gt0 // mulnC. rewrite muln_divCA ?field_dimS ?subv_adjoin // ltn_Pmulr ?adim_gt0 //. by rewrite -adjoin_degreeE ltnNge leq_eqVlt orbF adjoin_deg_eq1. rewrite map_monic monic_minPoly -Dz fmorph_root root_minPoly /=. have /polyOverP Cw_p: p \is a polyOver <<Cn; w>>%VS by apply: minPolyOver. apply/polyOver_poly=> j _; have /Fadjoin_polyP[q Cq {j}->] := Cw_p j. rewrite -horner_map (@rpred_horner _ (sQC _)) //. apply/polyOver_poly=> j _. by rewrite (sCle n) // -memCn (polyOverP Cq). have [evenG | oddG] := boolP (2.-group G); last first. have [P /and3P[sPG evenP oddPG]] := Sylow_exists 2 'Gal(Rz / Rn). have [w defQw] := PET_Qz t [aspace of fixedField P]. pose pw := minPoly Rn w; pose p := (- pw * (pw \Po - 'X)) ^ ofQ t. have sz_pw: (size pw).-1 = #|'Gal(Rz / Rn) : P|. rewrite size_minPoly adjoin_degreeE -dim_fixed_galois //= -defQw. congr (\dim_Rn _); apply/esym/eqP; rewrite eqEsubv adjoinSl ?sub1v //=. by apply/FadjoinP; rewrite memv_adjoin /= defQw -galois_connection. have mon_p: p \is monic. have mon_pw: pw \is monic := monic_minPoly _ _. rewrite map_monic mulNr -mulrN monicMl // monicE. rewrite !(lead_coefN, lead_coef_comp) ?size_polyN ?size_polyX //. by rewrite lead_coefX sz_pw -signr_odd odd_2'nat oddPG mulrN1 opprK. have Dp0: p.[0] = - ofQ t pw.[0] ^+ 2. rewrite -(rmorph0 (ofQ t)) horner_map hornerM rmorphM. by rewrite horner_comp !hornerN hornerX oppr0 /= rmorphN mulNr. have Rpw: pw \is a polyOver Rn by apply: minPolyOver. have Rp: p \is a polyOver (sQ (x_ n)). apply/polyOver_poly=> j _; rewrite -memRn; apply: polyOverP j => /=. by rewrite rpredM 1?polyOver_comp ?rpredN ?polyOverX. have Rp0: ofQ t pw.[0] \in sQ (x_ n) by rewrite -memRn rpred_horner ?rpred0. have [|{mon_p Rp Rp0 Dp0}m lenm p_Rm_0] := xRroot n p (ofQ t pw.[0]). by rewrite /has_Rroot mon_p Rp Rp0 -Dp0 /=. have{p_Rm_0} [y Ry pw_y]: {y | y \in sQ (x_ m) & root (pw ^ ofQ t) y}. apply/sig2W; have [y Ry] := p_Rm_0. rewrite [p]rmorphM /= map_comp_poly !rmorphN /= map_polyX. rewrite rootM rootN root_comp hornerN hornerX. by case/orP; [exists y | exists (- y)]; rewrite ?(rpredN (sQC _)). have [u Rz_u Dy]: exists2 u, u \in Rz & y = ofQ t u. have Rz_w: w \in Rz by rewrite -sub_adjoin1v defQw capvSl. have [sg [Gsg _ Dpw]] := galois_factors sRnRz galRz w Rz_w. set s := map _ sg in Dpw. have /mapP[u /mapP[g Gg Du] ->]: y \in map (ofQ t) s. by rewrite -root_prod_XsubC -/(rp C _) -map_rp -[rp _ _]Dpw. by exists u; rewrite // Du memv_gal. have{pw_y} pw_u: root pw u by rewrite -(fmorph_root (ofQ t)) -Dy. exists m => //; exists u; first by rewrite -Dy; apply: sQtrans Ry _. rewrite inE /= Rz_u andbT; apply: contra oddG => Cu. suffices: 2.-group 'Gal(Rz / Rn). apply: pnat_dvd; rewrite -!galois_dim // ?(galoisS _ galQr) ?sRCz //. rewrite dvdn_divLR ?field_dimS ?adim_gt0 //. by rewrite mulnC muln_divCA ?field_dimS ?dvdn_mulr. congr (2.-group _): evenP; apply/eqP. rewrite eqEsubset sPG -indexg_eq1 (pnat_1 _ oddPG) // -sz_pw. have (pu := minPoly Rn u): (pu %= pw) || (pu %= 1). by rewrite minPoly_irr ?minPoly_dvdp ?minPolyOver. rewrite /= -size_poly_eq1 {1}size_minPoly orbF => /eqp_size <-. rewrite size_minPoly /= adjoin_degreeE (@pnat_dvd _ 2) // -dimCn. rewrite dvdn_divLR ?divnK ?adim_gt0 ?field_dimS ?subv_adjoin //. exact/FadjoinP. have [w Rz_w deg_w]: exists2 w, w \in Rz & adjoin_degree Cn w = 2%N. have [P sPG iPG]: exists2 P : {group gal_of Rz}, P \subset G & #|G : P| = 2%N. have [_ _ [k oG]] := pgroup_pdiv evenG ntG. have [P [sPG _ oP]] := normal_pgroup evenG (normal_refl G) (leq_pred _). by exists P => //; rewrite -divgS // oP oG pfactorK // -expnB ?subSnn. have [w defQw] := PET_Qz _ [aspace of fixedField P]. exists w; first by rewrite -sub_adjoin1v defQw capvSl. rewrite adjoin_degreeE -iPG -dim_fixed_galois // -defQw; congr (\dim_Cn _). apply/esym/eqP; rewrite eqEsubv adjoinSl ?sub1v //=; apply/FadjoinP. by rewrite memv_adjoin /= defQw -galois_connection. have nz2: 2 != 0 :> Qt by move/pcharf0P: (pcharQ (Q t)) => ->. without loss{deg_w} [C'w Cw2]: w Rz_w / w \notin Cn /\ w ^+ 2 \in Cn. pose p := minPoly Cn w; pose v := p`_1 / 2. have /polyOverP Cp: p \is a polyOver Cn := minPolyOver Cn w. have Cv: v \in Cn by rewrite rpred_div ?rpred_nat ?Cp. move/(_ (v + w)); apply; first by rewrite rpredD // subvP_adjoin. split; first by rewrite rpredDl // -adjoin_deg_eq1 deg_w. rewrite addrC -[_ ^+ 2]subr0 -(rootP (root_minPoly Cn w)) -/p. rewrite sqrrD [_ - _]addrAC rpredD ?rpredX // -mulr_natr -mulrA divfK //. rewrite [w ^+ 2 + _]addrC mulrC -rpredN opprB horner_coef. have /monicP := monic_minPoly Cn w; rewrite lead_coefE size_minPoly deg_w. by rewrite 2!big_ord_recl big_ord1 => ->; rewrite mulr1 mul1r addrK Cp. without loss R'w2: w Rz_w C'w Cw2 / w ^+ 2 \notin Rn. move=> IHw; have [Rw2 | /IHw] := boolP (w ^+ 2 \in Rn); last exact. have R'it: i_t \notin Rn by rewrite memRn Dit. pose v := 1 + i_t; have R'v: v \notin Rn by rewrite rpredDl ?rpred1. have Cv: v \in Cn by rewrite rpredD ?rpred1 ?memv_adjoin. have nz_v: v != 0 by rewrite (memPnC R'v) ?rpred0. apply: (IHw (v * w)); last 1 [|] || by rewrite fpredMl // subvP_adjoin. by rewrite exprMn rpredM // rpredX. rewrite exprMn fpredMr //=; last by rewrite expf_eq0 (memPnC C'w) ?rpred0. by rewrite sqrrD Dit2 expr1n addrC addKr -mulrnAl fpredMl ?rpred_nat. pose rect_w2 u v := [/\ u \in Rn, v \in Rn & u + i_t * (v * 2) = w ^+ 2]. have{Cw2} [u [v [Ru Rv Dw2]]]: {u : Qt & {v | rect_w2 u v}}. rewrite /rect_w2 -(Fadjoin_poly_eq Cw2); set p := Fadjoin_poly Rn i_t _. have /polyOverP Rp: p \is a polyOver Rn by apply: Fadjoin_polyOver. exists p`_0, (p`_1 / 2); split; rewrite ?rpred_div ?rpred_nat //. rewrite divfK // (horner_coef_wide _ (size_Fadjoin_poly _ _ _)) -/p. by rewrite adjoin_degreeE dimCn big_ord_recl big_ord1 mulr1 mulrC. pose p := Poly [:: - (ofQ t v ^+ 2); 0; - ofQ t u; 0; 1]. have [|m lenm [x Rx px0]] := xRroot n p (ofQ t v). rewrite /has_Rroot 2!unfold_in/= lead_coefE horner_coef0 -memRn Rv. rewrite (@PolyK _ 1) ?oner_eq0 //= !eqxx. rewrite !(rpred0 (sQC _)) ?(rpred1 (sQC _)) ?(rpredN (sQC _)) //=. by rewrite !andbT (@rpredX _ (sQC _)) -memRn. suffices [y Cy Dy2]: {y | y \in sQ (z_ m) & ofQ t w ^+ 2 == y ^+ 2}. exists m => //; exists w; last by rewrite inE C'w. by move: Dy2; rewrite eqf_sqr => /pred2P[]->; rewrite ?(rpredN (sQC _)). exists (x + i * (ofQ t v / x)). rewrite (@rpredD _ (sQC _)) 1?(@rpredM _ (sQC _)) //=. exact: (sQtrans (x_ m)). by rewrite (@rpred_div _ (sQC _)) // (sQtrans (x_ m)) // (sRle n) // -memRn. rewrite rootE /horner (@PolyK _ 1) ?oner_eq0 //= ?addr0 ?mul0r in px0. rewrite add0r mul1r -mulrA -expr2 subr_eq0 in px0. have nz_x2: x ^+ 2 != 0. apply: contraNneq R'w2 => y2_0; rewrite -Dw2 mulrCA. suffices /eqP->: v == 0 by rewrite mul0r addr0. by rewrite y2_0 mulr0 eq_sym sqrf_eq0 fmorph_eq0 in px0. apply/eqP/esym/(mulIf nz_x2); rewrite -exprMn -rmorphXn -Dw2 rmorphD rmorphM. rewrite /= Dit mulrDl -expr2 mulrA divfK; last by rewrite expf_eq0 in nz_x2. rewrite mulr_natr addrC sqrrD exprMn Di2 mulN1r -(eqP px0) -mulNr opprB. by rewrite -mulrnAl -mulrnAr -rmorphMn -!mulrDl addrAC subrK. have inFTA n z: (n_ z <= n)%N -> z = ofQ (z_ n) (inQ (z_ n) z). by move/sCle=> le_zn; rewrite inQ_K ?le_zn. pose is_cj n cj := {in R_ n, cj =1 id} /\ cj (i_ n) = - i_ n. have /all_sig[cj_ /all_and2[cj_R cj_i]] n: {cj : 'AEnd(Q (z_ n)) | is_cj n cj}. have cj_P: root (minPoly (R_ n) (i_ n) ^ \1%VF) (- i_ n). rewrite minp_i -(fmorph_root (ofQ _)) !rmorphD !rmorph1 /= !map_polyXn. by rewrite rmorphN inQ_K // rootE hornerD hornerXn hornerC sqrrN Di2 addNr. have cj_M: ahom_in fullv (kHomExtend (R_ n) \1 (i_ n) (- i_ n)). by rewrite -defRi -k1HomE kHomExtendP ?sub1v ?kHom1. exists (AHom cj_M); split=> [y /kHomExtend_id->|]; first by rewrite ?id_lfunE. by rewrite (kHomExtend_val (kHom1 1 _)). pose conj_ n z := ofQ _ (cj_ n (inQ _ z)); pose conj z := conj_ (n_ z) z. have conjK n m z: (n_ z <= n)%N -> (n <= m)%N -> conj_ m (conj_ n z) = z. move/sCle=> le_z_n le_n_m; have /le_z_n/sQ_inQ[u <-] := FTA z. have /QtoQ[Qmn QmnE]: z_ n \in sQ (z_ m) by rewrite (sCle n). rewrite /conj_ ofQ_K -!QmnE !ofQ_K -!comp_lfunE; congr (ofQ _ _). move: u (memRi n u); apply/eqlfun_inP/FadjoinP; split=> /=. apply/eqlfun_inP=> y Ry; rewrite !comp_lfunE !cj_R //. by move: Ry; rewrite -!sQof2 QmnE !inQ_K //; apply: sRle. apply/eqlfunP; rewrite !comp_lfunE cj_i !linearN /=. suffices ->: Qmn (i_ n) = i_ m by rewrite cj_i ?opprK. by apply: (fmorph_inj (ofQ _)); rewrite QmnE !inQ_K. have conjE n z: (n_ z <= n)%N -> conj z = conj_ n z. move/leq_trans=> le_zn; set x := conj z; set y := conj_ n z. have [m [le_xm le_ym le_nm]] := maxn3 (n_ x) (n_ y) n. by have /conjK/=/can_in_inj := leqnn m; apply; rewrite ?conjK // le_zn. have conjA : zmod_morphism conj. move=> x y. have [m [le_xm le_ym le_xym]] := maxn3 (n_ x) (n_ y) (n_ (x - y)). by rewrite !(conjE m) // (inFTA m x) // (inFTA m y) -?rmorphB /conj_ ?ofQ_K. have conjM : monoid_morphism conj. split=> [|x y]; first pose n1 := n_ 1. by rewrite /conj -/n1 -(rmorph1 (ofQ (z_ n1))) /conj_ ofQ_K !rmorph1. have [m [le_xm le_ym le_xym]] := maxn3 (n_ x) (n_ y) (n_ (x * y)). by rewrite !(conjE m) // (inFTA m x) // (inFTA m y) -?rmorphM /conj_ ?ofQ_K. have conjaM := GRing.isZmodMorphism.Build _ _ _ conjA. have conjmM := GRing.isMonoidMorphism.Build _ _ _ conjM. pose conjRM : {rmorphism _ -> _} := HB.pack conj conjaM conjmM. exists conjRM => [z | /(_ i)/eqP/idPn[]] /=. by have [n [/conjE-> /(conjK (n_ z))->]] := maxn3 (n_ (conj z)) (n_ z) 0. rewrite /conj/conj_ cj_i rmorphN inQ_K // eq_sym -addr_eq0 -mulr2n -mulr_natl. rewrite mulf_neq0 ?(memPnC (R'i 0)) ?(rpred0 (sQC _)) //. by have /pcharf0P-> := ftrans (fmorph_pchar QtoC) (pchar_num _). Qed.
Length.lean
/- Copyright (c) 2024 Mitchell Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Lee -/ import Mathlib.Data.ZMod.Basic import Mathlib.GroupTheory.Coxeter.Basic import Mathlib.Tactic.Linarith import Mathlib.Tactic.Zify /-! # The length function, reduced words, and descents Throughout this file, `B` is a type and `M : CoxeterMatrix B` is a Coxeter matrix. `cs : CoxeterSystem M W` is a Coxeter system; that is, `W` is a group, and `cs` holds the data of a group isomorphism `W ≃* M.group`, where `M.group` refers to the quotient of the free group on `B` by the Coxeter relations given by the matrix `M`. See `Mathlib/GroupTheory/Coxeter/Basic.lean` for more details. Given any element $w \in W$, its *length* (`CoxeterSystem.length`), denoted $\ell(w)$, is the minimum number $\ell$ such that $w$ can be written as a product of a sequence of $\ell$ simple reflections: $$w = s_{i_1} \cdots s_{i_\ell}.$$ We prove for all $w_1, w_2 \in W$ that $\ell (w_1 w_2) \leq \ell (w_1) + \ell (w_2)$ and that $\ell (w_1 w_2)$ has the same parity as $\ell (w_1) + \ell (w_2)$. We define a *reduced word* (`CoxeterSystem.IsReduced`) for an element $w \in W$ to be a way of writing $w$ as a product of exactly $\ell(w)$ simple reflections. Every element of $W$ has a reduced word. We say that $i \in B$ is a *left descent* (`CoxeterSystem.IsLeftDescent`) of $w \in W$ if $\ell(s_i w) < \ell(w)$. We show that if $i$ is a left descent of $w$, then $\ell(s_i w) + 1 = \ell(w)$. On the other hand, if $i$ is not a left descent of $w$, then $\ell(s_i w) = \ell(w) + 1$. We similarly define right descents (`CoxeterSystem.IsRightDescent`) and prove analogous results. ## Main definitions * `cs.length` * `cs.IsReduced` * `cs.IsLeftDescent` * `cs.IsRightDescent` ## References * [A. Björner and F. Brenti, *Combinatorics of Coxeter Groups*](bjorner2005) -/ assert_not_exists TwoSidedIdeal namespace CoxeterSystem open List Matrix Function variable {B : Type*} variable {W : Type*} [Group W] variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W) local prefix:100 "s" => cs.simple local prefix:100 "π" => cs.wordProd /-! ### Length -/ private theorem exists_word_with_prod (w : W) : ∃ n ω, ω.length = n ∧ π ω = w := by rcases cs.wordProd_surjective w with ⟨ω, rfl⟩ use ω.length, ω open scoped Classical in /-- The length of `w`; i.e., the minimum number of simple reflections that must be multiplied to form `w`. -/ noncomputable def length (w : W) : ℕ := Nat.find (cs.exists_word_with_prod w) local prefix:100 "ℓ" => cs.length theorem exists_reduced_word (w : W) : ∃ ω, ω.length = ℓ w ∧ w = π ω := by classical have := Nat.find_spec (cs.exists_word_with_prod w) tauto open scoped Classical in theorem length_wordProd_le (ω : List B) : ℓ (π ω) ≤ ω.length := Nat.find_min' (cs.exists_word_with_prod (π ω)) ⟨ω, by tauto⟩ @[simp] theorem length_one : ℓ (1 : W) = 0 := Nat.eq_zero_of_le_zero (cs.length_wordProd_le []) @[simp] theorem length_eq_zero_iff {w : W} : ℓ w = 0 ↔ w = 1 := by constructor · intro h rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ have : ω = [] := eq_nil_of_length_eq_zero (hω.trans h) rw [this, wordProd_nil] · rintro rfl exact cs.length_one @[simp] theorem length_inv (w : W) : ℓ (w⁻¹) = ℓ w := by apply Nat.le_antisymm · rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ have := cs.length_wordProd_le (List.reverse ω) rwa [wordProd_reverse, length_reverse, hω] at this · rcases cs.exists_reduced_word w⁻¹ with ⟨ω, hω, h'ω⟩ have := cs.length_wordProd_le (List.reverse ω) rwa [wordProd_reverse, length_reverse, ← h'ω, hω, inv_inv] at this theorem length_mul_le (w₁ w₂ : W) : ℓ (w₁ * w₂) ≤ ℓ w₁ + ℓ w₂ := by rcases cs.exists_reduced_word w₁ with ⟨ω₁, hω₁, rfl⟩ rcases cs.exists_reduced_word w₂ with ⟨ω₂, hω₂, rfl⟩ have := cs.length_wordProd_le (ω₁ ++ ω₂) simpa [hω₁, hω₂, wordProd_append] using this theorem length_mul_ge_length_sub_length (w₁ w₂ : W) : ℓ w₁ - ℓ w₂ ≤ ℓ (w₁ * w₂) := by simpa [Nat.sub_le_of_le_add] using cs.length_mul_le (w₁ * w₂) w₂⁻¹ theorem length_mul_ge_length_sub_length' (w₁ w₂ : W) : ℓ w₂ - ℓ w₁ ≤ ℓ (w₁ * w₂) := by simpa [Nat.sub_le_of_le_add, add_comm] using cs.length_mul_le w₁⁻¹ (w₁ * w₂) theorem length_mul_ge_max (w₁ w₂ : W) : max (ℓ w₁ - ℓ w₂) (ℓ w₂ - ℓ w₁) ≤ ℓ (w₁ * w₂) := max_le_iff.mpr ⟨length_mul_ge_length_sub_length _ _ _, length_mul_ge_length_sub_length' _ _ _⟩ /-- The homomorphism that sends each element `w : W` to the parity of the length of `w`. (See `lengthParity_eq_ofAdd_length`.) -/ def lengthParity : W →* Multiplicative (ZMod 2) := cs.lift ⟨fun _ ↦ Multiplicative.ofAdd 1, by simp_rw [CoxeterMatrix.IsLiftable, ← ofAdd_add, (by decide : (1 + 1 : ZMod 2) = 0)] simp⟩ theorem lengthParity_simple (i : B) : cs.lengthParity (s i) = Multiplicative.ofAdd 1 := cs.lift_apply_simple _ _ theorem lengthParity_comp_simple : cs.lengthParity ∘ cs.simple = fun _ ↦ Multiplicative.ofAdd 1 := funext cs.lengthParity_simple theorem lengthParity_eq_ofAdd_length (w : W) : cs.lengthParity w = Multiplicative.ofAdd (↑(ℓ w)) := by rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ rw [← hω, wordProd, map_list_prod, List.map_map, lengthParity_comp_simple, map_const', prod_replicate, ← ofAdd_nsmul, nsmul_one] theorem length_mul_mod_two (w₁ w₂ : W) : ℓ (w₁ * w₂) % 2 = (ℓ w₁ + ℓ w₂) % 2 := by rw [← ZMod.natCast_eq_natCast_iff', Nat.cast_add] simpa only [lengthParity_eq_ofAdd_length, ofAdd_add] using map_mul cs.lengthParity w₁ w₂ @[simp] theorem length_simple (i : B) : ℓ (s i) = 1 := by apply Nat.le_antisymm · simpa using cs.length_wordProd_le [i] · by_contra! length_lt_one have : cs.lengthParity (s i) = Multiplicative.ofAdd 0 := by rw [lengthParity_eq_ofAdd_length, Nat.lt_one_iff.mp length_lt_one, Nat.cast_zero] have : Multiplicative.ofAdd (0 : ZMod 2) = Multiplicative.ofAdd 1 := this.symm.trans (cs.lengthParity_simple i) contradiction theorem length_eq_one_iff {w : W} : ℓ w = 1 ↔ ∃ i : B, w = s i := by constructor · intro h rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ rcases List.length_eq_one_iff.mp (hω.trans h) with ⟨i, rfl⟩ exact ⟨i, cs.wordProd_singleton i⟩ · rintro ⟨i, rfl⟩ exact cs.length_simple i theorem length_mul_simple_ne (w : W) (i : B) : ℓ (w * s i) ≠ ℓ w := by intro eq have length_mod_two := cs.length_mul_mod_two w (s i) rw [eq, length_simple] at length_mod_two omega theorem length_simple_mul_ne (w : W) (i : B) : ℓ (s i * w) ≠ ℓ w := by convert cs.length_mul_simple_ne w⁻¹ i using 1 · convert cs.length_inv ?_ using 2 simp · simp theorem length_mul_simple (w : W) (i : B) : ℓ (w * s i) = ℓ w + 1 ∨ ℓ (w * s i) + 1 = ℓ w := by rcases Nat.lt_or_gt_of_ne (cs.length_mul_simple_ne w i) with lt | gt · -- lt : ℓ (w * s i) < ℓ w right have length_ge := cs.length_mul_ge_length_sub_length w (s i) simp only [length_simple, tsub_le_iff_right] at length_ge -- length_ge : ℓ w ≤ ℓ (w * s i) + 1 omega · -- gt : ℓ w < ℓ (w * s i) left have length_le := cs.length_mul_le w (s i) simp only [length_simple] at length_le -- length_le : ℓ (w * s i) ≤ ℓ w + 1 omega theorem length_simple_mul (w : W) (i : B) : ℓ (s i * w) = ℓ w + 1 ∨ ℓ (s i * w) + 1 = ℓ w := by have := cs.length_mul_simple w⁻¹ i rwa [(by simp : w⁻¹ * (s i) = ((s i) * w)⁻¹), length_inv, length_inv] at this /-! ### Reduced words -/ /-- The proposition that `ω` is reduced; that is, it has minimal length among all words that represent the same element of `W`. -/ def IsReduced (ω : List B) : Prop := ℓ (π ω) = ω.length @[simp] theorem isReduced_reverse_iff (ω : List B) : cs.IsReduced (ω.reverse) ↔ cs.IsReduced ω := by simp [IsReduced] theorem IsReduced.reverse {cs : CoxeterSystem M W} {ω : List B} (hω : cs.IsReduced ω) : cs.IsReduced (ω.reverse) := (cs.isReduced_reverse_iff ω).mpr hω theorem exists_reduced_word' (w : W) : ∃ ω : List B, cs.IsReduced ω ∧ w = π ω := by rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩ use ω tauto private theorem isReduced_take_and_drop {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) : cs.IsReduced (ω.take j) ∧ cs.IsReduced (ω.drop j) := by have h₁ : ℓ (π (ω.take j)) ≤ (ω.take j).length := cs.length_wordProd_le (ω.take j) have h₂ : ℓ (π (ω.drop j)) ≤ (ω.drop j).length := cs.length_wordProd_le (ω.drop j) have h₃ := calc (ω.take j).length + (ω.drop j).length _ = ω.length := by rw [← List.length_append, ω.take_append_drop j] _ = ℓ (π ω) := hω.symm _ = ℓ (π (ω.take j) * π (ω.drop j)) := by rw [← cs.wordProd_append, ω.take_append_drop j] _ ≤ ℓ (π (ω.take j)) + ℓ (π (ω.drop j)) := cs.length_mul_le _ _ unfold IsReduced omega theorem IsReduced.take {cs : CoxeterSystem M W} {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) : cs.IsReduced (ω.take j) := (isReduced_take_and_drop _ hω _).1 theorem IsReduced.drop {cs : CoxeterSystem M W} {ω : List B} (hω : cs.IsReduced ω) (j : ℕ) : cs.IsReduced (ω.drop j) := (isReduced_take_and_drop _ hω _).2 theorem not_isReduced_alternatingWord (i i' : B) {m : ℕ} (hM : M i i' ≠ 0) (hm : m > M i i') : ¬cs.IsReduced (alternatingWord i i' m) := by induction hm with | refl => -- Base case; m = M i i' + 1 suffices h : ℓ (π (alternatingWord i i' (M i i' + 1))) < M i i' + 1 by unfold IsReduced rw [Nat.succ_eq_add_one, length_alternatingWord] omega have : M i i' + 1 ≤ M i i' * 2 := by linarith [Nat.one_le_iff_ne_zero.mpr hM] rw [cs.prod_alternatingWord_eq_prod_alternatingWord_sub i i' _ this] have : M i i' * 2 - (M i i' + 1) = M i i' - 1 := by omega rw [this] calc ℓ (π (alternatingWord i' i (M i i' - 1))) _ ≤ (alternatingWord i' i (M i i' - 1)).length := cs.length_wordProd_le _ _ = M i i' - 1 := length_alternatingWord _ _ _ _ ≤ M i i' := Nat.sub_le _ _ _ < M i i' + 1 := Nat.lt_succ_self _ | step m ih => -- Inductive step contrapose! ih rw [alternatingWord_succ'] at ih apply IsReduced.drop (j := 1) at ih simpa using ih /-! ### Descents -/ /-- The proposition that `i` is a left descent of `w`; that is, $\ell(s_i w) < \ell(w)$. -/ def IsLeftDescent (w : W) (i : B) : Prop := ℓ (s i * w) < ℓ w /-- The proposition that `i` is a right descent of `w`; that is, $\ell(w s_i) < \ell(w)$. -/ def IsRightDescent (w : W) (i : B) : Prop := ℓ (w * s i) < ℓ w theorem not_isLeftDescent_one (i : B) : ¬cs.IsLeftDescent 1 i := by simp [IsLeftDescent] theorem not_isRightDescent_one (i : B) : ¬cs.IsRightDescent 1 i := by simp [IsRightDescent] theorem isLeftDescent_inv_iff {w : W} {i : B} : cs.IsLeftDescent w⁻¹ i ↔ cs.IsRightDescent w i := by unfold IsLeftDescent IsRightDescent nth_rw 1 [← length_inv] simp theorem isRightDescent_inv_iff {w : W} {i : B} : cs.IsRightDescent w⁻¹ i ↔ cs.IsLeftDescent w i := by simpa using (cs.isLeftDescent_inv_iff (w := w⁻¹)).symm theorem exists_leftDescent_of_ne_one {w : W} (hw : w ≠ 1) : ∃ i : B, cs.IsLeftDescent w i := by rcases cs.exists_reduced_word w with ⟨ω, h, rfl⟩ have h₁ : ω ≠ [] := by rintro rfl; simp at hw rcases List.exists_cons_of_ne_nil h₁ with ⟨i, ω', rfl⟩ use i rw [IsLeftDescent, ← h, wordProd_cons, simple_mul_simple_cancel_left] calc ℓ (π ω') ≤ ω'.length := cs.length_wordProd_le ω' _ < (i :: ω').length := by simp theorem exists_rightDescent_of_ne_one {w : W} (hw : w ≠ 1) : ∃ i : B, cs.IsRightDescent w i := by simp only [← isLeftDescent_inv_iff] apply exists_leftDescent_of_ne_one simpa theorem isLeftDescent_iff {w : W} {i : B} : cs.IsLeftDescent w i ↔ ℓ (s i * w) + 1 = ℓ w := by unfold IsLeftDescent constructor · intro _ exact (cs.length_simple_mul w i).resolve_left (by omega) · omega theorem not_isLeftDescent_iff {w : W} {i : B} : ¬cs.IsLeftDescent w i ↔ ℓ (s i * w) = ℓ w + 1 := by unfold IsLeftDescent constructor · intro _ exact (cs.length_simple_mul w i).resolve_right (by omega) · omega theorem isRightDescent_iff {w : W} {i : B} : cs.IsRightDescent w i ↔ ℓ (w * s i) + 1 = ℓ w := by unfold IsRightDescent constructor · intro _ exact (cs.length_mul_simple w i).resolve_left (by omega) · omega theorem not_isRightDescent_iff {w : W} {i : B} : ¬cs.IsRightDescent w i ↔ ℓ (w * s i) = ℓ w + 1 := by unfold IsRightDescent constructor · intro _ exact (cs.length_mul_simple w i).resolve_right (by omega) · omega theorem isLeftDescent_iff_not_isLeftDescent_mul {w : W} {i : B} : cs.IsLeftDescent w i ↔ ¬cs.IsLeftDescent (s i * w) i := by rw [isLeftDescent_iff, not_isLeftDescent_iff, simple_mul_simple_cancel_left] tauto theorem isRightDescent_iff_not_isRightDescent_mul {w : W} {i : B} : cs.IsRightDescent w i ↔ ¬cs.IsRightDescent (w * s i) i := by rw [isRightDescent_iff, not_isRightDescent_iff, simple_mul_simple_cancel_right] tauto end CoxeterSystem
Finiteness.lean
/- Copyright (c) 2021 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.Group.Pointwise.Set.Finite import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.GroupTheory.QuotientGroup.Defs /-! # Finitely generated monoids and groups We define finitely generated monoids and groups. See also `Submodule.FG` and `Module.Finite` for finitely-generated modules. ## Main definition * `Submonoid.FG S`, `AddSubmonoid.FG S` : A submonoid `S` is finitely generated. * `Monoid.FG M`, `AddMonoid.FG M` : A typeclass indicating a type `M` is finitely generated as a monoid. * `Subgroup.FG S`, `AddSubgroup.FG S` : A subgroup `S` is finitely generated. * `Group.FG M`, `AddGroup.FG M` : A typeclass indicating a type `M` is finitely generated as a group. -/ assert_not_exists MonoidWithZero /-! ### Monoids and submonoids -/ open Pointwise variable {M N : Type*} [Monoid M] section Submonoid variable [Monoid N] {P : Submonoid M} {Q : Submonoid N} /-- A submonoid of `M` is finitely generated if it is the closure of a finite subset of `M`. -/ @[to_additive] def Submonoid.FG (P : Submonoid M) : Prop := ∃ S : Finset M, Submonoid.closure ↑S = P /-- An additive submonoid of `N` is finitely generated if it is the closure of a finite subset of `M`. -/ add_decl_doc AddSubmonoid.FG /-- An equivalent expression of `Submonoid.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive /-- An equivalent expression of `AddSubmonoid.FG` in terms of `Set.Finite` instead of `Finset`. -/] theorem Submonoid.fg_iff (P : Submonoid M) : Submonoid.FG P ↔ ∃ S : Set M, Submonoid.closure S = P ∧ S.Finite := ⟨fun ⟨S, hS⟩ => ⟨S, hS, Finset.finite_toSet S⟩, fun ⟨S, hS, hf⟩ => ⟨Set.Finite.toFinset hf, by simp [hS]⟩⟩ /-- A finitely generated submonoid has a minimal generating set. -/ @[to_additive /-- A finitely generated submonoid has a minimal generating set. -/] lemma Submonoid.FG.exists_minimal_closure_eq (hP : P.FG) : ∃ S : Finset M, Minimal (closure ·.toSet = P) S := exists_minimal_of_wellFoundedLT _ hP theorem Submonoid.fg_iff_add_fg (P : Submonoid M) : P.FG ↔ P.toAddSubmonoid.FG := ⟨fun h => let ⟨S, hS, hf⟩ := (Submonoid.fg_iff _).1 h (AddSubmonoid.fg_iff _).mpr ⟨Additive.toMul ⁻¹' S, by simp [← Submonoid.toAddSubmonoid_closure, hS], hf⟩, fun h => let ⟨T, hT, hf⟩ := (AddSubmonoid.fg_iff _).1 h (Submonoid.fg_iff _).mpr ⟨Additive.ofMul ⁻¹' T, by simp [← AddSubmonoid.toSubmonoid'_closure, hT], hf⟩⟩ theorem AddSubmonoid.fg_iff_mul_fg {M : Type*} [AddMonoid M] (P : AddSubmonoid M) : P.FG ↔ P.toSubmonoid.FG := by convert (Submonoid.fg_iff_add_fg (toSubmonoid P)).symm /-- The product of finitely generated submonoids is finitely generated. -/ @[to_additive /-- The product of finitely generated submonoids is finitely generated. -/] lemma Submonoid.FG.prod (hP : P.FG) (hQ : Q.FG) : (P.prod Q).FG := by classical obtain ⟨bM, hbM⟩ := hP obtain ⟨bN, hbN⟩ := hQ refine ⟨bM ×ˢ singleton 1 ∪ singleton 1 ×ˢ bN, ?_⟩ push_cast simp [Submonoid.closure_union, hbM, hbN] end Submonoid section Monoid /-- An additive monoid is finitely generated if it is finitely generated as an additive submonoid of itself. -/ @[mk_iff] class AddMonoid.FG (M : Type*) [AddMonoid M] : Prop where fg_top : (⊤ : AddSubmonoid M).FG variable (M) in /-- A monoid is finitely generated if it is finitely generated as a submonoid of itself. -/ @[to_additive] class Monoid.FG : Prop where fg_top : (⊤ : Submonoid M).FG @[to_additive] theorem Monoid.fg_def : Monoid.FG M ↔ (⊤ : Submonoid M).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- An equivalent expression of `Monoid.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive /-- An equivalent expression of `AddMonoid.FG` in terms of `Set.Finite` instead of `Finset`. -/] theorem Monoid.fg_iff : Monoid.FG M ↔ ∃ S : Set M, Submonoid.closure S = (⊤ : Submonoid M) ∧ S.Finite := ⟨fun _ => (Submonoid.fg_iff ⊤).1 FG.fg_top, fun h => ⟨(Submonoid.fg_iff ⊤).2 h⟩⟩ variable (M) in /-- A finitely generated monoid has a minimal generating set. -/ @[to_additive /-- A finitely generated monoid has a minimal generating set. -/] lemma Submonoid.exists_minimal_closure_eq_top [Monoid.FG M] : ∃ S : Finset M, Minimal (Submonoid.closure ·.toSet = ⊤) S := Monoid.FG.fg_top.exists_minimal_closure_eq theorem Monoid.fg_iff_add_fg : Monoid.FG M ↔ AddMonoid.FG (Additive M) where mp _ := ⟨(Submonoid.fg_iff_add_fg ⊤).1 FG.fg_top⟩ mpr h := ⟨(Submonoid.fg_iff_add_fg ⊤).2 h.fg_top⟩ theorem AddMonoid.fg_iff_mul_fg {M : Type*} [AddMonoid M] : AddMonoid.FG M ↔ Monoid.FG (Multiplicative M) where mp _ := ⟨(AddSubmonoid.fg_iff_mul_fg ⊤).1 FG.fg_top⟩ mpr h := ⟨(AddSubmonoid.fg_iff_mul_fg ⊤).2 h.fg_top⟩ instance AddMonoid.fg_of_monoid_fg [Monoid.FG M] : AddMonoid.FG (Additive M) := Monoid.fg_iff_add_fg.1 ‹_› instance Monoid.fg_of_addMonoid_fg {M : Type*} [AddMonoid M] [AddMonoid.FG M] : Monoid.FG (Multiplicative M) := AddMonoid.fg_iff_mul_fg.1 ‹_› -- This was previously a global instance, -- but it doesn't appear to be used and has been implicated in slow typeclass resolutions. @[to_additive] lemma Monoid.fg_of_finite [Finite M] : Monoid.FG M := by cases nonempty_fintype M exact ⟨⟨Finset.univ, by rw [Finset.coe_univ]; exact Submonoid.closure_univ⟩⟩ end Monoid @[to_additive] theorem Submonoid.FG.map {M' : Type*} [Monoid M'] {P : Submonoid M} (h : P.FG) (e : M →* M') : (P.map e).FG := by classical obtain ⟨s, rfl⟩ := h exact ⟨s.image e, by rw [Finset.coe_image, MonoidHom.map_mclosure]⟩ @[to_additive] theorem Submonoid.FG.map_injective {M' : Type*} [Monoid M'] {P : Submonoid M} (e : M →* M') (he : Function.Injective e) (h : (P.map e).FG) : P.FG := by obtain ⟨s, hs⟩ := h use s.preimage e he.injOn apply Submonoid.map_injective_of_injective he rw [← hs, MonoidHom.map_mclosure e, Finset.coe_preimage] congr rw [Set.image_preimage_eq_iff, ← MonoidHom.coe_mrange e, ← Submonoid.closure_le, hs, MonoidHom.mrange_eq_map e] exact Submonoid.monotone_map le_top @[to_additive (attr := simp)] theorem Monoid.fg_iff_submonoid_fg (N : Submonoid M) : Monoid.FG N ↔ N.FG := by conv_rhs => rw [← N.mrange_subtype, MonoidHom.mrange_eq_map] exact ⟨fun h ↦ h.fg_top.map N.subtype, fun h => ⟨h.map_injective N.subtype Subtype.coe_injective⟩⟩ @[to_additive] theorem Monoid.fg_of_surjective {M' : Type*} [Monoid M'] [Monoid.FG M] (f : M →* M') (hf : Function.Surjective f) : Monoid.FG M' := by classical obtain ⟨s, hs⟩ := Monoid.fg_def.mp ‹_› use s.image f rwa [Finset.coe_image, ← MonoidHom.map_mclosure, hs, ← MonoidHom.mrange_eq_map, MonoidHom.mrange_eq_top] @[to_additive] instance Monoid.fg_range {M' : Type*} [Monoid M'] [Monoid.FG M] (f : M →* M') : Monoid.FG (MonoidHom.mrange f) := Monoid.fg_of_surjective f.mrangeRestrict f.mrangeRestrict_surjective @[to_additive] theorem Submonoid.powers_fg (r : M) : (Submonoid.powers r).FG := ⟨{r}, (Finset.coe_singleton r).symm ▸ (Submonoid.powers_eq_closure r).symm⟩ @[to_additive] instance Monoid.powers_fg (r : M) : Monoid.FG (Submonoid.powers r) := (Monoid.fg_iff_submonoid_fg _).mpr (Submonoid.powers_fg r) @[to_additive] instance Monoid.closure_finset_fg (s : Finset M) : Monoid.FG (Submonoid.closure (s : Set M)) := by refine ⟨⟨s.preimage Subtype.val Subtype.coe_injective.injOn, ?_⟩⟩ rw [Finset.coe_preimage, Submonoid.closure_closure_coe_preimage] @[to_additive] instance Monoid.closure_finite_fg (s : Set M) [Finite s] : Monoid.FG (Submonoid.closure s) := haveI := Fintype.ofFinite s s.coe_toFinset ▸ Monoid.closure_finset_fg s.toFinset /-! ### Groups and subgroups -/ variable {G H : Type*} [Group G] [AddGroup H] section Subgroup /-- A subgroup of `G` is finitely generated if it is the closure of a finite subset of `G`. -/ @[to_additive] def Subgroup.FG (P : Subgroup G) : Prop := ∃ S : Finset G, Subgroup.closure ↑S = P /-- An additive subgroup of `H` is finitely generated if it is the closure of a finite subset of `H`. -/ add_decl_doc AddSubgroup.FG /-- An equivalent expression of `Subgroup.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive /-- An equivalent expression of `AddSubgroup.fg` in terms of `Set.Finite` instead of `Finset`. -/] theorem Subgroup.fg_iff (P : Subgroup G) : Subgroup.FG P ↔ ∃ S : Set G, Subgroup.closure S = P ∧ S.Finite := ⟨fun ⟨S, hS⟩ => ⟨S, hS, Finset.finite_toSet S⟩, fun ⟨S, hS, hf⟩ => ⟨Set.Finite.toFinset hf, by simp [hS]⟩⟩ /-- A subgroup is finitely generated if and only if it is finitely generated as a submonoid. -/ @[to_additive /-- An additive subgroup is finitely generated if and only if it is finitely generated as an additive submonoid. -/] theorem Subgroup.fg_iff_submonoid_fg (P : Subgroup G) : P.FG ↔ P.toSubmonoid.FG := by constructor · rintro ⟨S, rfl⟩ rw [Submonoid.fg_iff] refine ⟨S ∪ S⁻¹, ?_, S.finite_toSet.union S.finite_toSet.inv⟩ exact (Subgroup.closure_toSubmonoid _).symm · rintro ⟨S, hS⟩ refine ⟨S, le_antisymm ?_ ?_⟩ · rw [Subgroup.closure_le, ← Subgroup.coe_toSubmonoid, ← hS] exact Submonoid.subset_closure · rw [← Subgroup.toSubmonoid_le, ← hS, Submonoid.closure_le] exact Subgroup.subset_closure theorem Subgroup.fg_iff_add_fg (P : Subgroup G) : P.FG ↔ P.toAddSubgroup.FG := by rw [Subgroup.fg_iff_submonoid_fg, AddSubgroup.fg_iff_addSubmonoid_fg] exact (Subgroup.toSubmonoid P).fg_iff_add_fg theorem AddSubgroup.fg_iff_mul_fg (P : AddSubgroup H) : P.FG ↔ P.toSubgroup.FG := by rw [AddSubgroup.fg_iff_addSubmonoid_fg, Subgroup.fg_iff_submonoid_fg] exact AddSubmonoid.fg_iff_mul_fg (AddSubgroup.toAddSubmonoid P) end Subgroup section Group variable (G H) /-- A group is finitely generated if it is finitely generated as a subgroup of itself. -/ class Group.FG : Prop where out : (⊤ : Subgroup G).FG /-- An additive group is finitely generated if it is finitely generated as an additive subgroup of itself. -/ class AddGroup.FG : Prop where out : (⊤ : AddSubgroup H).FG attribute [to_additive] Group.FG variable {G H} theorem Group.fg_def : Group.FG G ↔ (⊤ : Subgroup G).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ theorem AddGroup.fg_def : AddGroup.FG H ↔ (⊤ : AddSubgroup H).FG := ⟨fun h => h.1, fun h => ⟨h⟩⟩ /-- An equivalent expression of `Group.FG` in terms of `Set.Finite` instead of `Finset`. -/ @[to_additive /-- An equivalent expression of `AddGroup.fg` in terms of `Set.Finite` instead of `Finset`. -/] theorem Group.fg_iff : Group.FG G ↔ ∃ S : Set G, Subgroup.closure S = (⊤ : Subgroup G) ∧ S.Finite := ⟨fun h => (Subgroup.fg_iff ⊤).1 h.out, fun h => ⟨(Subgroup.fg_iff ⊤).2 h⟩⟩ @[to_additive] theorem Group.fg_iff' : Group.FG G ↔ ∃ (n : _) (S : Finset G), S.card = n ∧ Subgroup.closure (S : Set G) = ⊤ := Group.fg_def.trans ⟨fun ⟨S, hS⟩ => ⟨S.card, S, rfl, hS⟩, fun ⟨_n, S, _hn, hS⟩ => ⟨S, hS⟩⟩ /-- A group is finitely generated if and only if it is finitely generated as a monoid. -/ @[to_additive /-- An additive group is finitely generated if and only if it is finitely generated as an additive monoid. -/] theorem Group.fg_iff_monoid_fg : Group.FG G ↔ Monoid.FG G := ⟨fun h => Monoid.fg_def.2 <| (Subgroup.fg_iff_submonoid_fg ⊤).1 (Group.fg_def.1 h), fun h => Group.fg_def.2 <| (Subgroup.fg_iff_submonoid_fg ⊤).2 (Monoid.fg_def.1 h)⟩ @[to_additive] instance Monoid.fg_of_group_fg [Group.FG G] : Monoid.FG G := Group.fg_iff_monoid_fg.1 ‹_› @[to_additive (attr := simp)] theorem Group.fg_iff_subgroup_fg (H : Subgroup G) : Group.FG H ↔ H.FG := (fg_iff_monoid_fg.trans (Monoid.fg_iff_submonoid_fg _)).trans (Subgroup.fg_iff_submonoid_fg _).symm theorem GroupFG.iff_add_fg : Group.FG G ↔ AddGroup.FG (Additive G) := ⟨fun h => ⟨(Subgroup.fg_iff_add_fg ⊤).1 h.out⟩, fun h => ⟨(Subgroup.fg_iff_add_fg ⊤).2 h.out⟩⟩ theorem AddGroup.fg_iff_mul_fg : AddGroup.FG H ↔ Group.FG (Multiplicative H) := ⟨fun h => ⟨(AddSubgroup.fg_iff_mul_fg ⊤).1 h.out⟩, fun h => ⟨(AddSubgroup.fg_iff_mul_fg ⊤).2 h.out⟩⟩ instance AddGroup.fg_of_group_fg [Group.FG G] : AddGroup.FG (Additive G) := GroupFG.iff_add_fg.1 ‹_› instance Group.fg_of_mul_group_fg [AddGroup.FG H] : Group.FG (Multiplicative H) := AddGroup.fg_iff_mul_fg.1 ‹_› @[to_additive] instance (priority := 100) Group.fg_of_finite [Finite G] : Group.FG G := by cases nonempty_fintype G exact ⟨⟨Finset.univ, by rw [Finset.coe_univ]; exact Subgroup.closure_univ⟩⟩ @[to_additive] theorem Group.fg_of_surjective {G' : Type*} [Group G'] [hG : Group.FG G] {f : G →* G'} (hf : Function.Surjective f) : Group.FG G' := Group.fg_iff_monoid_fg.mpr <| @Monoid.fg_of_surjective G _ G' _ (Group.fg_iff_monoid_fg.mp hG) f hf @[to_additive] instance Group.fg_range {G' : Type*} [Group G'] [Group.FG G] (f : G →* G') : Group.FG f.range := Group.fg_of_surjective f.rangeRestrict_surjective @[to_additive] instance Group.closure_finset_fg (s : Finset G) : Group.FG (Subgroup.closure (s : Set G)) := by refine ⟨⟨s.preimage Subtype.val Subtype.coe_injective.injOn, ?_⟩⟩ rw [Finset.coe_preimage, ← Subgroup.coe_subtype, Subgroup.closure_preimage_eq_top] @[to_additive] instance Group.closure_finite_fg (s : Set G) [Finite s] : Group.FG (Subgroup.closure s) := haveI := Fintype.ofFinite s s.coe_toFinset ▸ Group.closure_finset_fg s.toFinset end Group section QuotientGroup @[to_additive] instance QuotientGroup.fg [Group.FG G] (N : Subgroup G) [Subgroup.Normal N] : Group.FG <| G ⧸ N := Group.fg_of_surjective <| QuotientGroup.mk'_surjective N end QuotientGroup namespace Prod variable [Monoid N] open Monoid in /-- The product of finitely generated monoids is finitely generated. -/ @[to_additive /-- The product of finitely generated monoids is finitely generated. -/] instance instMonoidFG [FG M] [FG N] : FG (M × N) where fg_top := by rw [← Submonoid.top_prod_top]; exact .prod ‹FG M›.fg_top ‹FG N›.fg_top end Prod namespace AddMonoid instance : FG ℕ := by rw [fg_iff, ← Nat.addSubmonoid_closure_one] exact ⟨{1}, rfl, by simp⟩ end AddMonoid namespace AddGroup instance : FG ℤ := by rw [fg_iff] refine ⟨{1}, ?_, by simp⟩ ext x simp [AddSubgroup.mem_closure_singleton] end AddGroup
Monoidal.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou, Dagur Asgeirsson -/ import Mathlib.CategoryTheory.Localization.Trifunctor import Mathlib.CategoryTheory.Monoidal.Functor /-! # Localization of monoidal categories Let `C` be a monoidal category equipped with a class of morphisms `W` which is compatible with the monoidal category structure: this means `W` is multiplicative and stable by left and right whiskerings (this is the type class `W.IsMonoidal`). Let `L : C ⥤ D` be a localization functor for `W`. In the file, we construct a monoidal category structure on `D` such that the localization functor is monoidal. The structure is actually defined on a type synonym `LocalizedMonoidal L W ε`. Here, the data `ε : L.obj (𝟙_ C) ≅ unit` is an isomorphism to some object `unit : D` which allows the user to provide a preferred choice of a unit object. -/ namespace CategoryTheory open Category MonoidalCategory variable {C D : Type*} [Category C] [Category D] (L : C ⥤ D) (W : MorphismProperty C) [MonoidalCategory C] namespace MorphismProperty /-- A class of morphisms `W` in a monoidal category is monoidal if it is multiplicative and stable under left and right whiskering. Under this condition, the localized category can be equipped with a monoidal category structure, see `LocalizedMonoidal`. -/ class IsMonoidal : Prop extends W.IsMultiplicative where whiskerLeft (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) (hg : W g) : W (X ◁ g) whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (hf : W f) (Y : C) : W (f ▷ Y) variable [W.IsMonoidal] lemma whiskerLeft_mem (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) (hg : W g) : W (X ◁ g) := IsMonoidal.whiskerLeft _ _ hg lemma whiskerRight_mem {X₁ X₂ : C} (f : X₁ ⟶ X₂) (hf : W f) (Y : C) : W (f ▷ Y) := IsMonoidal.whiskerRight _ hf Y lemma tensorHom_mem {X₁ X₂ : C} (f : X₁ ⟶ X₂) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) (hf : W f) (hg : W g) : W (f ⊗ₘ g) := by rw [tensorHom_def] exact comp_mem _ _ _ (whiskerRight_mem _ _ hf _) (whiskerLeft_mem _ _ _ hg) end MorphismProperty /-- Given a monoidal category `C`, a localization functor `L : C ⥤ D` with respect to `W : MorphismProperty C` which satisfies `W.IsMonoidal`, and a choice of object `unit : D` with an isomorphism `L.obj (𝟙_ C) ≅ unit`, this is a type synonym for `D` on which we define the localized monoidal category structure. -/ @[nolint unusedArguments] def LocalizedMonoidal (L : C ⥤ D) (W : MorphismProperty C) [W.IsMonoidal] [L.IsLocalization W] {unit : D} (_ : L.obj (𝟙_ C) ≅ unit) := D variable [W.IsMonoidal] [L.IsLocalization W] {unit : D} (ε : L.obj (𝟙_ C) ≅ unit) namespace Localization instance : Category (LocalizedMonoidal L W ε) := inferInstanceAs (Category D) namespace Monoidal /-- The monoidal functor from a monoidal category `C` to its localization `LocalizedMonoidal L W ε`. -/ def toMonoidalCategory : C ⥤ LocalizedMonoidal L W ε := L /-- The isomorphism `ε : L.obj (𝟙_ C) ≅ unit`, as `(toMonoidalCategory L W ε).obj (𝟙_ C) ≅ unit`. -/ abbrev ε' : (toMonoidalCategory L W ε).obj (𝟙_ C) ≅ unit := ε local notation "L'" => toMonoidalCategory L W ε instance : (L').IsLocalization W := inferInstanceAs (L.IsLocalization W) lemma isInvertedBy₂ : MorphismProperty.IsInvertedBy₂ W W (curriedTensor C ⋙ (Functor.whiskeringRight C C D).obj L') := by rintro ⟨X₁, Y₁⟩ ⟨X₂, Y₂⟩ ⟨f₁, f₂⟩ ⟨hf₁, hf₂⟩ have := Localization.inverts L' W _ (W.whiskerRight_mem f₁ hf₁ Y₁) have := Localization.inverts L' W _ (W.whiskerLeft_mem X₂ f₂ hf₂) dsimp infer_instance /-- The localized tensor product, as a bifunctor. -/ noncomputable def tensorBifunctor : LocalizedMonoidal L W ε ⥤ LocalizedMonoidal L W ε ⥤ LocalizedMonoidal L W ε := Localization.lift₂ _ (isInvertedBy₂ L W ε) L L noncomputable instance : Lifting₂ L' L' W W (curriedTensor C ⋙ (Functor.whiskeringRight C C (LocalizedMonoidal L W ε)).obj L') (tensorBifunctor L W ε) := inferInstanceAs (Lifting₂ L L W W (curriedTensor C ⋙ (Functor.whiskeringRight C C D).obj L') (Localization.lift₂ _ (isInvertedBy₂ L W ε) L L)) /-- The bifunctor `tensorBifunctor` on `LocalizedMonoidal L W ε` is induced by `curriedTensor C`. -/ noncomputable abbrev tensorBifunctorIso : (((Functor.whiskeringLeft₂ D).obj L').obj L').obj (tensorBifunctor L W ε) ≅ (Functor.postcompose₂.obj L').obj (curriedTensor C) := Lifting₂.iso L' L' W W (curriedTensor C ⋙ (Functor.whiskeringRight C C (LocalizedMonoidal L W ε)).obj L') (tensorBifunctor L W ε) noncomputable instance (X : C) : Lifting L' W (tensorLeft X ⋙ L') ((tensorBifunctor L W ε).obj ((L').obj X)) := by apply Lifting₂.liftingLift₂ (hF := isInvertedBy₂ L W ε) noncomputable instance (Y : C) : Lifting L' W (tensorRight Y ⋙ L') ((tensorBifunctor L W ε).flip.obj ((L').obj Y)) := by apply Lifting₂.liftingLift₂Flip (hF := isInvertedBy₂ L W ε) /-- The left unitor in the localized monoidal category `LocalizedMonoidal L W ε`. -/ noncomputable def leftUnitor : (tensorBifunctor L W ε).obj unit ≅ 𝟭 _ := (tensorBifunctor L W ε).mapIso ε.symm ≪≫ Localization.liftNatIso L' W (tensorLeft (𝟙_ C) ⋙ L') L' ((tensorBifunctor L W ε).obj ((L').obj (𝟙_ _))) _ (Functor.isoWhiskerRight (leftUnitorNatIso C) _ ≪≫ L.leftUnitor) /-- The right unitor in the localized monoidal category `LocalizedMonoidal L W ε`. -/ noncomputable def rightUnitor : (tensorBifunctor L W ε).flip.obj unit ≅ 𝟭 _ := (tensorBifunctor L W ε).flip.mapIso ε.symm ≪≫ Localization.liftNatIso L' W (tensorRight (𝟙_ C) ⋙ L') L' ((tensorBifunctor L W ε).flip.obj ((L').obj (𝟙_ _))) _ (Functor.isoWhiskerRight (rightUnitorNatIso C) _ ≪≫ L.leftUnitor) /-- The associator in the localized monoidal category `LocalizedMonoidal L W ε`. -/ noncomputable def associator : bifunctorComp₁₂ (tensorBifunctor L W ε) (tensorBifunctor L W ε) ≅ bifunctorComp₂₃ (tensorBifunctor L W ε) (tensorBifunctor L W ε) := Localization.associator L' L' L' L' L' L' W W W W W (curriedAssociatorNatIso C) (tensorBifunctor L W ε) (tensorBifunctor L W ε) (tensorBifunctor L W ε) (tensorBifunctor L W ε) noncomputable instance monoidalCategoryStruct : MonoidalCategoryStruct (LocalizedMonoidal L W ε) where tensorObj X Y := ((tensorBifunctor L W ε).obj X).obj Y whiskerLeft X _ _ g := ((tensorBifunctor L W ε).obj X).map g whiskerRight f Y := ((tensorBifunctor L W ε).map f).app Y tensorUnit := unit associator X Y Z := (((associator L W ε).app X).app Y).app Z leftUnitor Y := (leftUnitor L W ε).app Y rightUnitor X := (rightUnitor L W ε).app X /-- The compatibility isomorphism of the monoidal functor `toMonoidalCategory L W ε` with respect to the tensor product. -/ noncomputable def μ (X Y : C) : (L').obj X ⊗ (L').obj Y ≅ (L').obj (X ⊗ Y) := ((tensorBifunctorIso L W ε).app X).app Y @[reassoc (attr := simp)] lemma μ_natural_left {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : (L').map f ▷ (L').obj Y ≫ (μ L W ε X₂ Y).hom = (μ L W ε X₁ Y).hom ≫ (L').map (f ▷ Y) := NatTrans.naturality_app (tensorBifunctorIso L W ε).hom Y f @[reassoc (attr := simp)] lemma μ_inv_natural_left {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : (μ L W ε X₁ Y).inv ≫ (L').map f ▷ (L').obj Y = (L').map (f ▷ Y) ≫ (μ L W ε X₂ Y).inv := by simp [Iso.eq_comp_inv] @[reassoc (attr := simp)] lemma μ_natural_right (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) : (L').obj X ◁ (L').map g ≫ (μ L W ε X Y₂).hom = (μ L W ε X Y₁).hom ≫ (L').map (X ◁ g) := ((tensorBifunctorIso L W ε).hom.app X).naturality g @[reassoc (attr := simp)] lemma μ_inv_natural_right (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) : (μ L W ε X Y₁).inv ≫ (L').obj X ◁ (L').map g = (L').map (X ◁ g) ≫ (μ L W ε X Y₂).inv := by simp [Iso.eq_comp_inv] lemma leftUnitor_hom_app (Y : C) : (λ_ ((L').obj Y)).hom = (ε' L W ε).inv ▷ (L').obj Y ≫ (μ _ _ _ _ _).hom ≫ (L').map (λ_ Y).hom := by dsimp [monoidalCategoryStruct, leftUnitor] rw [liftNatTrans_app] dsimp rw [assoc] change _ ≫ (μ L W ε _ _).hom ≫ _ ≫ 𝟙 _ ≫ 𝟙 _ = _ simp only [comp_id] lemma rightUnitor_hom_app (X : C) : (ρ_ ((L').obj X)).hom = (L').obj X ◁ (ε' L W ε).inv ≫ (μ _ _ _ _ _).hom ≫ (L').map (ρ_ X).hom := by dsimp [monoidalCategoryStruct, rightUnitor] rw [liftNatTrans_app] dsimp rw [assoc] change _ ≫ (μ L W ε _ _).hom ≫ _ ≫ 𝟙 _ ≫ 𝟙 _ = _ simp only [comp_id] lemma associator_hom_app (X₁ X₂ X₃ : C) : (α_ ((L').obj X₁) ((L').obj X₂) ((L').obj X₃)).hom = ((μ L W ε _ _).hom ⊗ₘ 𝟙 _) ≫ (μ L W ε _ _).hom ≫ (L').map (α_ X₁ X₂ X₃).hom ≫ (μ L W ε _ _).inv ≫ (𝟙 _ ⊗ₘ (μ L W ε _ _).inv) := by dsimp [monoidalCategoryStruct, associator] simp only [Functor.map_id, comp_id, NatTrans.id_app, id_comp] rw [Localization.associator_hom_app_app_app] rfl lemma id_tensorHom (X : LocalizedMonoidal L W ε) {Y₁ Y₂ : LocalizedMonoidal L W ε} (f : Y₁ ⟶ Y₂) : 𝟙 X ⊗ₘ f = X ◁ f := by simp [monoidalCategoryStruct] lemma tensorHom_id {X₁ X₂ : LocalizedMonoidal L W ε} (f : X₁ ⟶ X₂) (Y : LocalizedMonoidal L W ε) : f ⊗ₘ 𝟙 Y = f ▷ Y := by simp [monoidalCategoryStruct] @[reassoc] lemma tensor_comp {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : LocalizedMonoidal L W ε} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂) : (f₁ ≫ g₁) ⊗ₘ (f₂ ≫ g₂) = (f₁ ⊗ₘ f₂) ≫ (g₁ ⊗ₘ g₂) := by simp [monoidalCategoryStruct] lemma id_tensorHom_id (X₁ X₂ : LocalizedMonoidal L W ε) : 𝟙 X₁ ⊗ₘ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by simp [monoidalCategoryStruct] @[deprecated (since := "2025-07-14")] alias tensor_id := id_tensorHom_id @[reassoc] theorem whiskerLeft_comp (Q : LocalizedMonoidal L W ε) {X Y Z : LocalizedMonoidal L W ε} (f : X ⟶ Y) (g : Y ⟶ Z) : Q ◁ (f ≫ g) = Q ◁ f ≫ Q ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc] theorem whiskerRight_comp (Q : LocalizedMonoidal L W ε) {X Y Z : LocalizedMonoidal L W ε} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g) ▷ Q = f ▷ Q ≫ g ▷ Q := by simp only [← tensorHom_id, ← tensor_comp, comp_id] lemma whiskerLeft_id (X Y : LocalizedMonoidal L W ε) : X ◁ (𝟙 Y) = 𝟙 _ := by simp [monoidalCategoryStruct] lemma whiskerRight_id (X Y : LocalizedMonoidal L W ε) : (𝟙 X) ▷ Y = 𝟙 _ := by simp [monoidalCategoryStruct] @[reassoc] lemma whisker_exchange {Q X Y Z : LocalizedMonoidal L W ε} (f : Q ⟶ X) (g : Y ⟶ Z) : Q ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] lemma associator_naturality {X₁ X₂ X₃ Y₁ Y₂ Y₃ : LocalizedMonoidal L W ε} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃) : ((f₁ ⊗ₘ f₂) ⊗ₘ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ₘ f₂ ⊗ₘ f₃) := by have h₁ := (((associator L W ε).hom.app Y₁).app Y₂).naturality f₃ have h₂ := NatTrans.congr_app (((associator L W ε).hom.app Y₁).naturality f₂) X₃ have h₃ := NatTrans.congr_app (NatTrans.congr_app ((associator L W ε).hom.naturality f₁) X₂) X₃ simp only [monoidalCategoryStruct, Functor.map_comp, assoc] dsimp at h₁ h₂ h₃ ⊢ rw [h₁, assoc, reassoc_of% h₂, reassoc_of% h₃] @[reassoc] lemma associator_naturality₁ {X₁ X₂ X₃ Y₁ : LocalizedMonoidal L W ε} (f₁ : X₁ ⟶ Y₁) : ((f₁ ▷ X₂) ▷ X₃) ≫ (α_ Y₁ X₂ X₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ▷ (X₂ ⊗ X₃)) := by simp only [← tensorHom_id, associator_naturality, id_tensorHom_id] @[reassoc] lemma associator_naturality₂ {X₁ X₂ X₃ Y₂ : LocalizedMonoidal L W ε} (f₂ : X₂ ⟶ Y₂) : ((X₁ ◁ f₂) ▷ X₃) ≫ (α_ X₁ Y₂ X₃).hom = (α_ X₁ X₂ X₃).hom ≫ (X₁ ◁ (f₂ ▷ X₃)) := by simp only [← tensorHom_id, ← id_tensorHom, associator_naturality] @[reassoc] lemma associator_naturality₃ {X₁ X₂ X₃ Y₃ : LocalizedMonoidal L W ε} (f₃ : X₃ ⟶ Y₃) : ((X₁ ⊗ X₂) ◁ f₃) ≫ (α_ X₁ X₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (X₁ ◁ (X₂ ◁ f₃)) := by simp only [← id_tensorHom, ← id_tensorHom_id, associator_naturality] lemma pentagon_aux₁ {X₁ X₂ X₃ Y₁ : LocalizedMonoidal L W ε} (i : X₁ ≅ Y₁) : ((i.hom ▷ X₂) ▷ X₃) ≫ (α_ Y₁ X₂ X₃).hom ≫ (i.inv ▷ (X₂ ⊗ X₃)) = (α_ X₁ X₂ X₃).hom := by simp only [associator_naturality₁_assoc, ← whiskerRight_comp, Iso.hom_inv_id, whiskerRight_id, comp_id] lemma pentagon_aux₂ {X₁ X₂ X₃ Y₂ : LocalizedMonoidal L W ε} (i : X₂ ≅ Y₂) : ((X₁ ◁ i.hom) ▷ X₃) ≫ (α_ X₁ Y₂ X₃).hom ≫ (X₁ ◁ (i.inv ▷ X₃)) = (α_ X₁ X₂ X₃).hom := by simp only [associator_naturality₂_assoc, ← whiskerLeft_comp, ← whiskerRight_comp, Iso.hom_inv_id, whiskerRight_id, whiskerLeft_id, comp_id] lemma pentagon_aux₃ {X₁ X₂ X₃ Y₃ : LocalizedMonoidal L W ε} (i : X₃ ≅ Y₃) : ((X₁ ⊗ X₂) ◁ i.hom) ≫ (α_ X₁ X₂ Y₃).hom ≫ (X₁ ◁ (X₂ ◁ i.inv)) = (α_ X₁ X₂ X₃).hom := by simp only [associator_naturality₃_assoc, ← whiskerLeft_comp, Iso.hom_inv_id, whiskerLeft_id, comp_id] instance : (L').EssSurj := Localization.essSurj L' W variable {L W ε} in lemma pentagon (Y₁ Y₂ Y₃ Y₄ : LocalizedMonoidal L W ε) : Pentagon Y₁ Y₂ Y₃ Y₄ := by obtain ⟨X₁, ⟨e₁⟩⟩ : ∃ X₁, Nonempty ((L').obj X₁ ≅ Y₁) := ⟨_, ⟨(L').objObjPreimageIso Y₁⟩⟩ obtain ⟨X₂, ⟨e₂⟩⟩ : ∃ X₂, Nonempty ((L').obj X₂ ≅ Y₂) := ⟨_, ⟨(L').objObjPreimageIso Y₂⟩⟩ obtain ⟨X₃, ⟨e₃⟩⟩ : ∃ X₃, Nonempty ((L').obj X₃ ≅ Y₃) := ⟨_, ⟨(L').objObjPreimageIso Y₃⟩⟩ obtain ⟨X₄, ⟨e₄⟩⟩ : ∃ X₄, Nonempty ((L').obj X₄ ≅ Y₄) := ⟨_, ⟨(L').objObjPreimageIso Y₄⟩⟩ suffices Pentagon ((L').obj X₁) ((L').obj X₂) ((L').obj X₃) ((L').obj X₄) by dsimp [Pentagon] refine Eq.trans ?_ (((((e₁.inv ⊗ₘ e₂.inv) ⊗ₘ e₃.inv) ⊗ₘ e₄.inv) ≫= this =≫ (e₁.hom ⊗ₘ e₂.hom ⊗ₘ e₃.hom ⊗ₘ e₄.hom)).trans ?_) · rw [← id_tensorHom, ← id_tensorHom, ← tensorHom_id, ← tensorHom_id, assoc, assoc, ← tensor_comp, ← associator_naturality, id_comp, ← comp_id e₁.hom, tensor_comp, ← associator_naturality_assoc, ← comp_id (𝟙 ((L').obj X₄)), ← tensor_comp_assoc, associator_naturality, comp_id, comp_id, ← tensor_comp_assoc, assoc, e₄.inv_hom_id, ← tensor_comp, e₁.inv_hom_id, ← tensor_comp, e₂.inv_hom_id, e₃.inv_hom_id, id_tensorHom_id, id_tensorHom_id, comp_id] · rw [assoc, associator_naturality_assoc, associator_naturality_assoc, ← tensor_comp, e₁.inv_hom_id, ← tensor_comp, e₂.inv_hom_id, ← tensor_comp, e₃.inv_hom_id, e₄.inv_hom_id, id_tensorHom_id, id_tensorHom_id, id_tensorHom_id, comp_id] dsimp [Pentagon] have : ((L').obj X₁ ◁ (μ L W ε X₂ X₃).inv) ▷ (L').obj X₄ ≫ (α_ ((L').obj X₁) ((L').obj X₂ ⊗ (L').obj X₃) ((L').obj X₄)).hom ≫ (L').obj X₁ ◁ (μ L W ε X₂ X₃).hom ▷ (L').obj X₄ = (α_ ((L').obj X₁) ((L').obj (X₂ ⊗ X₃)) ((L').obj X₄)).hom := pentagon_aux₂ _ _ _ (μ L W ε X₂ X₃).symm rw [associator_hom_app, tensorHom_id, id_tensorHom, associator_hom_app, tensorHom_id, whiskerLeft_comp, whiskerRight_comp, whiskerRight_comp, whiskerRight_comp, assoc, assoc, assoc, whiskerRight_comp, assoc, reassoc_of% this, associator_hom_app, tensorHom_id, ← pentagon_aux₁ (X₂ := (L').obj X₃) (X₃ := (L').obj X₄) (i := μ L W ε X₁ X₂), ← pentagon_aux₃ (X₁ := (L').obj X₁) (X₂ := (L').obj X₂) (i := μ L W ε X₃ X₄), associator_hom_app, associator_hom_app] simp only [assoc, ← whiskerRight_comp_assoc, Iso.inv_hom_id, comp_id, μ_natural_left_assoc, id_tensorHom, ← whiskerLeft_comp, Iso.inv_hom_id_assoc] rw [← (L').map_comp_assoc, whiskerLeft_comp, μ_inv_natural_right_assoc, ← (L').map_comp_assoc] simp only [assoc, MonoidalCategory.pentagon, Functor.map_comp, tensorHom_id, whiskerRight_comp_assoc] congr 3; simp only [← assoc]; congr simp only [← cancel_mono (μ L W ε (X₁ ⊗ X₂) (X₃ ⊗ X₄)).inv, assoc, id_comp, whisker_exchange_assoc, ← whiskerRight_comp_assoc, Iso.inv_hom_id, whiskerRight_id, ← whiskerLeft_comp, whiskerLeft_id] lemma leftUnitor_naturality {X Y : LocalizedMonoidal L W ε} (f : X ⟶ Y) : 𝟙_ (LocalizedMonoidal L W ε) ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by simp [monoidalCategoryStruct] lemma rightUnitor_naturality {X Y : LocalizedMonoidal L W ε} (f : X ⟶ Y) : f ▷ 𝟙_ (LocalizedMonoidal L W ε) ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := (rightUnitor L W ε).hom.naturality f @[reassoc] lemma triangle_aux₁ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : LocalizedMonoidal L W ε} (i₁ : X₁ ≅ Y₁) (i₂ : X₂ ≅ Y₂) (i₃ : X₃ ≅ Y₃) : ((i₁.hom ⊗ₘ i₂.hom) ⊗ₘ i₃.hom) ≫ (α_ Y₁ Y₂ Y₃).hom ≫ (i₁.inv ⊗ₘ i₂.inv ⊗ₘ i₃.inv) = (α_ X₁ X₂ X₃).hom := by simp only [associator_naturality_assoc, ← tensor_comp, Iso.hom_inv_id, id_tensorHom, whiskerLeft_id, comp_id] lemma triangle_aux₂ {X Y : LocalizedMonoidal L W ε} {X' Y' : C} (e₁ : (L').obj X' ≅ X) (e₂ : (L').obj Y' ≅ Y) : e₁.hom ⊗ₘ (ε.hom ⊗ₘ e₂.hom) ≫ (λ_ Y).hom = (L').obj X' ◁ ((ε' L W ε).hom ▷ (L').obj Y' ≫ 𝟙_ _ ◁ e₂.hom ≫ (λ_ Y).hom) ≫ e₁.hom ▷ Y := by simp only [← tensorHom_id, ← id_tensorHom, ← tensor_comp, comp_id, id_comp, ← tensor_comp_assoc, id_comp] congr 3 exact (comp_id _).symm lemma triangle_aux₃ {X Y : LocalizedMonoidal L W ε} {X' Y' : C} (e₁ : (L').obj X' ≅ X) (e₂ : (L').obj Y' ≅ Y) : (ρ_ X).hom ▷ _ = ((e₁.inv ⊗ₘ ε.inv) ⊗ₘ e₂.inv) ≫ _ ◁ e₂.hom ≫ ((μ L W ε X' (𝟙_ C)).hom ≫ (L').map (ρ_ X').hom) ▷ Y ≫ e₁.hom ▷ Y := by simp only [← tensorHom_id, ← id_tensorHom, ← tensor_comp, assoc, comp_id, id_comp, Iso.inv_hom_id] congr rw [← cancel_mono e₁.inv, assoc, assoc, assoc, Iso.hom_inv_id, comp_id, ← rightUnitor_naturality, rightUnitor_hom_app, ← tensorHom_id, ← id_tensorHom, ← tensor_comp_assoc, comp_id, id_comp] variable {L W ε} in lemma triangle (X Y : LocalizedMonoidal L W ε) : (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by obtain ⟨X', ⟨e₁⟩⟩ : ∃ X₁, Nonempty ((L').obj X₁ ≅ X) := ⟨_, ⟨(L').objObjPreimageIso X⟩⟩ obtain ⟨Y', ⟨e₂⟩⟩ : ∃ X₂, Nonempty ((L').obj X₂ ≅ Y) := ⟨_, ⟨(L').objObjPreimageIso Y⟩⟩ have h₁ := (associator_hom_app L W ε X' (𝟙_ _) Y' =≫ (𝟙 ((L').obj X') ⊗ₘ (μ L W ε (𝟙_ C) Y').hom)) simp only [assoc, id_tensorHom, ← whiskerLeft_comp, Iso.inv_hom_id, whiskerLeft_id, comp_id, Iso.inv_hom_id, ← cancel_mono (μ L W ε X' (𝟙_ C ⊗ Y')).hom] at h₁ have h₂ := (ε' L W ε).hom ▷ (L').obj Y' ≫= leftUnitor_hom_app L W ε Y' simp only [← whiskerRight_comp_assoc, Iso.hom_inv_id, whiskerRight_id, id_comp] at h₂ have h₃ := (((μ L W ε _ _).hom ⊗ₘ 𝟙 _) ≫ (μ L W ε _ _).hom) ≫= ((L').congr_map (MonoidalCategory.triangle X' Y')) simp only [assoc, Functor.map_comp, ← reassoc_of% h₁] at h₃ rw [← μ_natural_left, tensorHom_id, ← whiskerRight_comp_assoc, ← μ_natural_right, ← Iso.comp_inv_eq, assoc, assoc, assoc, Iso.hom_inv_id, comp_id, ← whiskerLeft_comp, ← h₂] at h₃ replace h₃ := ((e₁.inv ⊗ₘ ε.inv) ⊗ₘ e₂.inv) ≫= (h₃ =≫ (_ ◁ e₂.hom)) =≫ (e₁.hom ▷ _) simp only [← whiskerLeft_comp, assoc, ← leftUnitor_naturality, ← whisker_exchange] at h₃ have : _ = (α_ X (𝟙_ (LocalizedMonoidal L W ε)) Y).hom := triangle_aux₁ _ _ _ e₁.symm ε.symm e₂.symm simp only [← this, Iso.symm_hom, Iso.symm_inv, assoc, ← id_tensorHom, ← tensor_comp, comp_id] convert h₃ · exact triangle_aux₂ _ _ _ e₁ e₂ · exact triangle_aux₃ _ _ _ e₁ e₂ noncomputable instance : MonoidalCategory (LocalizedMonoidal L W ε) where tensorHom_def := by intros; simp [monoidalCategoryStruct] id_tensorHom_id := by intros; simp [monoidalCategoryStruct] tensor_comp := by intros; simp [monoidalCategoryStruct] whiskerLeft_id := by intros; simp [monoidalCategoryStruct] id_whiskerRight := by intros; simp [monoidalCategoryStruct] associator_naturality {X₁ X₂ X₃ Y₁ Y₂ Y₃} f₁ f₂ f₃ := by apply associator_naturality leftUnitor_naturality := by intros; simp [monoidalCategoryStruct] rightUnitor_naturality := fun f ↦ (rightUnitor L W ε).hom.naturality f pentagon := pentagon triangle := triangle end Monoidal end Localization open Localization.Monoidal noncomputable instance : (toMonoidalCategory L W ε).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := ε.symm μIso X Y := μ L W ε X Y associativity X Y Z := by simp [associator_hom_app L W ε X Y Z] left_unitality Y := leftUnitor_hom_app L W ε Y right_unitality X := rightUnitor_hom_app L W ε X } end CategoryTheory
output.v
From mathcomp Require Import all_boot all_order all_algebra all_field all_character all_fingroup all_solvable. Open Scope group_scope. Check @cyclic_pgroup_Aut_structure.
pgroup.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div. From mathcomp Require Import fintype bigop finset prime fingroup morphism. From mathcomp Require Import gfunctor automorphism quotient action gproduct. From mathcomp Require Import cyclic. (******************************************************************************) (* Standard group notions and constructions based on the prime decomposition *) (* of the order of the group or its elements: *) (* pi.-group G <=> G is a pi-group, i.e., pi.-nat #|G|. *) (* -> Recall that here and in the sequel pi can be a single prime p. *) (* pi.-subgroup(H) G <=> H is a pi-subgroup of G. *) (* := (H \subset G) && pi.-group H. *) (* -> This is provided mostly as a shorhand, with few associated lemmas. *) (* However, we do establish some results on maximal pi-subgroups. *) (* pi.-elt x <=> x is a pi-element. *) (* := pi.-nat #[x] or pi.-group <[x]>. *) (* x.`_pi == the pi-constituent of x: the (unique) pi-element *) (* y \in <[x]> such that x * y^-1 is a pi'-element. *) (* pi.-Hall(G) H <=> H is a Hall pi-subgroup of G. *) (* := [&& H \subset G, pi.-group H & pi^'.-nat #|G : H|]. *) (* -> This is also equivalent to H \subset G /\ #|H| = #|G|`_pi. *) (* p.-Sylow(G) P <=> P is a Sylow p-subgroup of G. *) (* -> This is the display and preferred input notation for p.-Hall(G) P. *) (* 'Syl_p(G) == the set of the p-Sylow subgroups of G. *) (* := [set P : {group _} | p.-Sylow(G) P]. *) (* p_group P <=> P is a p-group for some prime p. *) (* Hall G H <=> H is a Hall pi-subgroup of G for some pi. *) (* := coprime #|H| #|G : H| && (H \subset G). *) (* Sylow G P <=> P is a Sylow p-subgroup of G for some p. *) (* := p_group P && Hall G P. *) (* 'O_pi(G) == the pi-core (largest normal pi-subgroup) of G. *) (* pcore_mod pi G H == the pi-core of G mod H. *) (* := G :&: (coset H @*^-1 'O_pi(G / H)). *) (* 'O_{pi2, pi1}(G) == the pi1,pi2-core of G. *) (* := the pi1-core of G mod 'O_pi2(G). *) (* -> We have 'O_{pi2, pi1}(G) / 'O_pi2(G) = 'O_pi1(G / 'O_pi2(G)) *) (* with 'O_pi2(G) <| 'O_{pi2, pi1}(G) <| G. *) (* 'O_{pn, ..., p1}(G) == the p1, ..., pn-core of G. *) (* := the p1-core of G mod 'O_{pn, ..., p2}(G). *) (* Note that notions are always defined on sets even though their name *) (* indicates "group" properties; the actual definition of the notion never *) (* tests for the group property, since this property will always be provided *) (* by a (canonical) group structure. Similarly, p-group properties assume *) (* without test that p is a prime. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Section PgroupDefs. (* We defer the definition of the functors ('0_p(G), etc) because they need *) (* to quantify over the finGroupType explicitly. *) Variable gT : finGroupType. Implicit Type (x : gT) (A B : {set gT}) (pi : nat_pred) (p n : nat). Definition pgroup pi A := pi.-nat #|A|. Definition psubgroup pi A B := (B \subset A) && pgroup pi B. Definition p_group A := pgroup (pdiv #|A|) A. Definition p_elt pi x := pi.-nat #[x]. Definition constt x pi := x ^+ (chinese #[x]`_pi #[x]`_pi^' 1 0). Definition Hall A B := (B \subset A) && coprime #|B| #|A : B|. Definition pHall pi A B := [&& B \subset A, pgroup pi B & pi^'.-nat #|A : B|]. Definition Syl p A := [set P : {group gT} | pHall p A P]. Definition Sylow A B := p_group B && Hall A B. End PgroupDefs. Arguments pgroup {gT} pi%_N A%_g. Arguments psubgroup {gT} pi%_N A%_g B%_g. Arguments p_group {gT} A%_g. Arguments p_elt {gT} pi%_N x. Arguments constt {gT} x%_g pi%_N. Arguments Hall {gT} A%_g B%_g. Arguments pHall {gT} pi%_N A%_g B%_g. Arguments Syl {gT} p%_N A%_g. Arguments Sylow {gT} A%_g B%_g. Notation "pi .-group" := (pgroup pi) (format "pi .-group") : group_scope. Notation "pi .-subgroup ( A )" := (psubgroup pi A) (format "pi .-subgroup ( A )") : group_scope. Notation "pi .-elt" := (p_elt pi) (format "pi .-elt") : group_scope. Notation "x .`_ pi" := (constt x pi) (at level 3, left associativity, format "x .`_ pi") : group_scope. Notation "pi .-Hall ( G )" := (pHall pi G) (format "pi .-Hall ( G )") : group_scope. Notation "p .-Sylow ( G )" := (nat_pred_of_nat p).-Hall(G) (format "p .-Sylow ( G )") : group_scope. Notation "''Syl_' p ( G )" := (Syl p G) (p at level 2, format "''Syl_' p ( G )") : group_scope. Section PgroupProps. Variable gT : finGroupType. Implicit Types (pi rho : nat_pred) (p : nat). Implicit Types (x y z : gT) (A B C D : {set gT}) (G H K P Q R : {group gT}). Lemma trivgVpdiv G : G :=: 1 \/ (exists2 p, prime p & p %| #|G|). Proof. have [leG1|lt1G] := leqP #|G| 1; first by left; apply: card_le1_trivg. by right; exists (pdiv #|G|); rewrite ?pdiv_dvd ?pdiv_prime. Qed. Lemma prime_subgroupVti G H : prime #|G| -> G \subset H \/ H :&: G = 1. Proof. move=> prG; have [|[p p_pr pG]] := trivgVpdiv (H :&: G); first by right. left; rewrite (sameP setIidPr eqP) eqEcard subsetIr. suffices <-: p = #|G| by rewrite dvdn_leq ?cardG_gt0. by apply/eqP; rewrite -dvdn_prime2 // -(LagrangeI G H) setIC dvdn_mulr. Qed. Lemma pgroupE pi A : pi.-group A = pi.-nat #|A|. Proof. by []. Qed. Lemma sub_pgroup pi rho A : {subset pi <= rho} -> pi.-group A -> rho.-group A. Proof. by move=> pi_sub_rho; apply: sub_in_pnat (in1W pi_sub_rho). Qed. Lemma eq_pgroup pi rho A : pi =i rho -> pi.-group A = rho.-group A. Proof. exact: eq_pnat. Qed. Lemma eq_p'group pi rho A : pi =i rho -> pi^'.-group A = rho^'.-group A. Proof. by move/eq_negn; apply: eq_pnat. Qed. Lemma pgroupNK pi A : pi^'^'.-group A = pi.-group A. Proof. exact: pnatNK. Qed. Lemma pi_pgroup p pi A : p.-group A -> p \in pi -> pi.-group A. Proof. exact: pi_pnat. Qed. Lemma pi_p'group p pi A : pi.-group A -> p \in pi^' -> p^'.-group A. Proof. exact: pi_p'nat. Qed. Lemma pi'_p'group p pi A : pi^'.-group A -> p \in pi -> p^'.-group A. Proof. exact: pi'_p'nat. Qed. Lemma p'groupEpi p G : p^'.-group G = (p \notin \pi(G)). Proof. exact: p'natEpi (cardG_gt0 G). Qed. Lemma pgroup_pi G : \pi(G).-group G. Proof. by rewrite /=; apply: pnat_pi. Qed. Lemma partG_eq1 pi G : (#|G|`_pi == 1%N) = pi^'.-group G. Proof. exact: partn_eq1 (cardG_gt0 G). Qed. Lemma pgroupP pi G : reflect (forall p, prime p -> p %| #|G| -> p \in pi) (pi.-group G). Proof. exact: pnatP. Qed. Arguments pgroupP {pi G}. Lemma pgroup1 pi : pi.-group [1 gT]. Proof. by rewrite /pgroup cards1. Qed. Lemma pgroupS pi G H : H \subset G -> pi.-group G -> pi.-group H. Proof. by move=> sHG; apply: pnat_dvd (cardSg sHG). Qed. Lemma oddSg G H : H \subset G -> odd #|G| -> odd #|H|. Proof. by rewrite !odd_2'nat; apply: pgroupS. Qed. Lemma odd_pgroup_odd p G : odd p -> p.-group G -> odd #|G|. Proof. move=> p_odd pG; rewrite odd_2'nat (pi_pnat pG) // !inE. by case: eqP p_odd => // ->. Qed. Lemma card_pgroup p G : p.-group G -> #|G| = (p ^ logn p #|G|)%N. Proof. by move=> pG; rewrite -p_part part_pnat_id. Qed. Lemma properG_ltn_log p G H : p.-group G -> H \proper G -> logn p #|H| < logn p #|G|. Proof. move=> pG; rewrite properEneq eqEcard andbC ltnNge => /andP[sHG]. rewrite sHG /= {1}(card_pgroup pG) {1}(card_pgroup (pgroupS sHG pG)). by apply: contra; case: p {pG} => [|p] leHG; rewrite ?logn0 // leq_pexp2l. Qed. Lemma pgroupM pi G H : pi.-group (G * H) = pi.-group G && pi.-group H. Proof. have GH_gt0: 0 < #|G :&: H| := cardG_gt0 _. rewrite /pgroup -(mulnK #|_| GH_gt0) -mul_cardG -(LagrangeI G H) -mulnA. by rewrite mulKn // -(LagrangeI H G) setIC !pnatM andbCA; case: (pnat _). Qed. Lemma pgroupJ pi G x : pi.-group (G :^ x) = pi.-group G. Proof. by rewrite /pgroup cardJg. Qed. Lemma pgroup_p p P : p.-group P -> p_group P. Proof. case: (leqP #|P| 1); first by move=> /card_le1_trivg-> _; apply: pgroup1. move/pdiv_prime=> pr_q pgP; have:= pgroupP pgP _ pr_q (pdiv_dvd _). by rewrite /p_group => /eqnP->. Qed. Lemma p_groupP P : p_group P -> exists2 p, prime p & p.-group P. Proof. case: (ltnP 1 #|P|); first by move/pdiv_prime; exists (pdiv #|P|). by move/card_le1_trivg=> -> _; exists 2 => //; apply: pgroup1. Qed. Lemma pgroup_pdiv p G : p.-group G -> G :!=: 1 -> [/\ prime p, p %| #|G| & exists m, #|G| = p ^ m.+1]%N. Proof. move=> pG; rewrite trivg_card1; case/p_groupP: (pgroup_p pG) => q q_pr qG. move/implyP: (pgroupP pG q q_pr); case/p_natP: qG => // [[|m] ->] //. by rewrite dvdn_exp // => /eqnP <- _; split; rewrite ?dvdn_exp //; exists m. Qed. Lemma coprime_p'group p K R : coprime #|K| #|R| -> p.-group R -> R :!=: 1 -> p^'.-group K. Proof. move=> coKR pR ntR; have [p_pr _ [e oK]] := pgroup_pdiv pR ntR. by rewrite oK coprime_sym coprime_pexpl // prime_coprime // -p'natE in coKR. Qed. Lemma card_Hall pi G H : pi.-Hall(G) H -> #|H| = #|G|`_pi. Proof. case/and3P=> sHG piH pi'H; rewrite -(Lagrange sHG). by rewrite partnM ?Lagrange // part_pnat_id ?part_p'nat ?muln1. Qed. Lemma pHall_sub pi A B : pi.-Hall(A) B -> B \subset A. Proof. by case/andP. Qed. Lemma pHall_pgroup pi A B : pi.-Hall(A) B -> pi.-group B. Proof. by case/and3P. Qed. Lemma pHallP pi G H : reflect (H \subset G /\ #|H| = #|G|`_pi) (pi.-Hall(G) H). Proof. apply: (iffP idP) => [piH | [sHG oH]]. by split; [apply: pHall_sub piH | apply: card_Hall]. rewrite /pHall sHG -divgS // /pgroup oH. by rewrite -{2}(@partnC pi #|G|) ?mulKn ?part_pnat. Qed. Lemma pHallE pi G H : pi.-Hall(G) H = (H \subset G) && (#|H| == #|G|`_pi). Proof. by apply/pHallP/andP=> [] [->] /eqP. Qed. Lemma coprime_mulpG_Hall pi G K R : K * R = G -> pi.-group K -> pi^'.-group R -> pi.-Hall(G) K /\ pi^'.-Hall(G) R. Proof. move=> defG piK pi'R; apply/andP. rewrite /pHall piK -!divgS /= -defG ?mulG_subl ?mulg_subr //= pnatNK. by rewrite coprime_cardMg ?(pnat_coprime piK) // mulKn ?mulnK //; apply/and3P. Qed. Lemma coprime_mulGp_Hall pi G K R : K * R = G -> pi^'.-group K -> pi.-group R -> pi^'.-Hall(G) K /\ pi.-Hall(G) R. Proof. move=> defG pi'K piR; apply/andP; rewrite andbC; apply/andP. by apply: coprime_mulpG_Hall => //; rewrite -(comm_group_setP _) defG ?groupP. Qed. Lemma eq_in_pHall pi rho G H : {in \pi(G), pi =i rho} -> pi.-Hall(G) H = rho.-Hall(G) H. Proof. move=> eq_pi_rho; apply: andb_id2l => sHG. congr (_ && _); apply: eq_in_pnat => p piHp. by apply: eq_pi_rho; apply: (piSg sHG). by congr (~~ _); apply: eq_pi_rho; apply: (pi_of_dvd (dvdn_indexg G H)). Qed. Lemma eq_pHall pi rho G H : pi =i rho -> pi.-Hall(G) H = rho.-Hall(G) H. Proof. by move=> eq_pi_rho; apply: eq_in_pHall (in1W eq_pi_rho). Qed. Lemma eq_p'Hall pi rho G H : pi =i rho -> pi^'.-Hall(G) H = rho^'.-Hall(G) H. Proof. by move=> eq_pi_rho; apply: eq_pHall (eq_negn _). Qed. Lemma pHallNK pi G H : pi^'^'.-Hall(G) H = pi.-Hall(G) H. Proof. exact: eq_pHall (negnK _). Qed. Lemma subHall_Hall pi rho G H K : rho.-Hall(G) H -> {subset pi <= rho} -> pi.-Hall(H) K -> pi.-Hall(G) K. Proof. move=> hallH pi_sub_rho hallK. rewrite pHallE (subset_trans (pHall_sub hallK) (pHall_sub hallH)) /=. by rewrite (card_Hall hallK) (card_Hall hallH) partn_part. Qed. Lemma subHall_Sylow pi p G H P : pi.-Hall(G) H -> p \in pi -> p.-Sylow(H) P -> p.-Sylow(G) P. Proof. move=> hallH pi_p sylP; have [sHG piH _] := and3P hallH. rewrite pHallE (subset_trans (pHall_sub sylP) sHG) /=. by rewrite (card_Hall sylP) (card_Hall hallH) partn_part // => q; move/eqnP->. Qed. Lemma pHall_Hall pi A B : pi.-Hall(A) B -> Hall A B. Proof. by case/and3P=> sBA piB pi'B; rewrite /Hall sBA (pnat_coprime piB). Qed. Lemma Hall_pi G H : Hall G H -> \pi(H).-Hall(G) H. Proof. by case/andP=> sHG coHG /=; rewrite /pHall sHG /pgroup pnat_pi -?coprime_pi'. Qed. Lemma HallP G H : Hall G H -> exists pi, pi.-Hall(G) H. Proof. by exists \pi(H); apply: Hall_pi. Qed. Lemma sdprod_Hall G K H : K ><| H = G -> Hall G K = Hall G H. Proof. case/sdprod_context=> /andP[sKG _] sHG defG _ tiKH. by rewrite /Hall sKG sHG -!divgS // -defG TI_cardMg // coprime_sym mulKn ?mulnK. Qed. Lemma coprime_sdprod_Hall_l G K H : K ><| H = G -> coprime #|K| #|H| = Hall G K. Proof. case/sdprod_context=> /andP[sKG _] _ defG _ tiKH. by rewrite /Hall sKG -divgS // -defG TI_cardMg ?mulKn. Qed. Lemma coprime_sdprod_Hall_r G K H : K ><| H = G -> coprime #|K| #|H| = Hall G H. Proof. by move=> defG; rewrite (coprime_sdprod_Hall_l defG) (sdprod_Hall defG). Qed. Lemma compl_pHall pi K H G : pi.-Hall(G) K -> (H \in [complements to K in G]) = pi^'.-Hall(G) H. Proof. move=> hallK; apply/complP/idP=> [[tiKH mulKH] | hallH]. have [_] := andP hallK; rewrite /pHall pnatNK -{3}(invGid G) -mulKH mulG_subr. rewrite invMG !indexMg -indexgI andbC. by rewrite -[#|K : H|]indexgI setIC tiKH !indexg1. have [[sKG piK _] [sHG pi'H _]] := (and3P hallK, and3P hallH). have tiKH: K :&: H = 1 := coprime_TIg (pnat_coprime piK pi'H). split=> //; apply/eqP; rewrite eqEcard mul_subG //= TI_cardMg //. by rewrite (card_Hall hallK) (card_Hall hallH) partnC. Qed. Lemma compl_p'Hall pi K H G : pi^'.-Hall(G) K -> (H \in [complements to K in G]) = pi.-Hall(G) H. Proof. by move/compl_pHall->; apply: eq_pHall (negnK pi). Qed. Lemma sdprod_normal_p'HallP pi K H G : K <| G -> pi^'.-Hall(G) H -> reflect (K ><| H = G) (pi.-Hall(G) K). Proof. move=> nsKG hallH; rewrite -(compl_p'Hall K hallH). exact: sdprod_normal_complP. Qed. Lemma sdprod_normal_pHallP pi K H G : K <| G -> pi.-Hall(G) H -> reflect (K ><| H = G) (pi^'.-Hall(G) K). Proof. by move=> nsKG hallH; apply: sdprod_normal_p'HallP; rewrite ?pHallNK. Qed. Lemma pHallJ2 pi G H x : pi.-Hall(G :^ x) (H :^ x) = pi.-Hall(G) H. Proof. by rewrite !pHallE conjSg !cardJg. Qed. Lemma pHallJnorm pi G H x : x \in 'N(G) -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H. Proof. by move=> Nx; rewrite -{1}(normP Nx) pHallJ2. Qed. Lemma pHallJ pi G H x : x \in G -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H. Proof. by move=> Gx; rewrite -{1}(conjGid Gx) pHallJ2. Qed. Lemma HallJ G H x : x \in G -> Hall G (H :^ x) = Hall G H. Proof. by move=> Gx; rewrite /Hall -!divgI -{1 3}(conjGid Gx) conjSg -conjIg !cardJg. Qed. Lemma psubgroupJ pi G H x : x \in G -> pi.-subgroup(G) (H :^ x) = pi.-subgroup(G) H. Proof. by move=> Gx; rewrite /psubgroup pgroupJ -{1}(conjGid Gx) conjSg. Qed. Lemma p_groupJ P x : p_group (P :^ x) = p_group P. Proof. by rewrite /p_group cardJg pgroupJ. Qed. Lemma SylowJ G P x : x \in G -> Sylow G (P :^ x) = Sylow G P. Proof. by move=> Gx; rewrite /Sylow p_groupJ HallJ. Qed. Lemma p_Sylow p G P : p.-Sylow(G) P -> Sylow G P. Proof. by move=> pP; rewrite /Sylow (pgroup_p (pHall_pgroup pP)) (pHall_Hall pP). Qed. Lemma pHall_subl pi G K H : H \subset K -> K \subset G -> pi.-Hall(G) H -> pi.-Hall(K) H. Proof. by move=> sHK sKG; rewrite /pHall sHK => /and3P[_ ->]; apply/pnat_dvd/indexSg. Qed. Lemma Hall1 G : Hall G 1. Proof. by rewrite /Hall sub1G cards1 coprime1n. Qed. Lemma p_group1 : @p_group gT 1. Proof. by rewrite (@pgroup_p 2) ?pgroup1. Qed. Lemma Sylow1 G : Sylow G 1. Proof. by rewrite /Sylow p_group1 Hall1. Qed. Lemma SylowP G P : reflect (exists2 p, prime p & p.-Sylow(G) P) (Sylow G P). Proof. apply: (iffP idP) => [| [p _]]; last exact: p_Sylow. case/andP=> /p_groupP[p p_pr] /p_natP[[P1 _ | n oP /Hall_pi]]; last first. by rewrite /= oP pi_of_exp // (eq_pHall _ _ (pi_of_prime _)) //; exists p. have{p p_pr P1} ->: P :=: 1 by apply: card1_trivg; rewrite P1. pose p := pdiv #|G|.+1; have p_pr: prime p by rewrite pdiv_prime ?ltnS. exists p; rewrite // pHallE sub1G cards1 part_p'nat //. apply/pgroupP=> q pr_q qG; apply/eqnP=> def_q. have: p %| #|G| + 1 by rewrite addn1 pdiv_dvd. by rewrite dvdn_addr -def_q // Euclid_dvd1. Qed. Lemma p_elt_exp pi x m : pi.-elt (x ^+ m) = (#[x]`_pi^' %| m). Proof. apply/idP/idP=> [pi_xm | /dvdnP[q ->{m}]]; last first. rewrite mulnC; apply: pnat_dvd (part_pnat pi #[x]). by rewrite order_dvdn -expgM mulnC mulnA partnC // -order_dvdn dvdn_mulr. rewrite -(@Gauss_dvdr _ #[x ^+ m]); last first. by rewrite coprime_sym (pnat_coprime pi_xm) ?part_pnat. apply: (@dvdn_trans #[x]); first by rewrite -{2}[#[x]](partnC pi) ?dvdn_mull. by rewrite order_dvdn mulnC expgM expg_order. Qed. Lemma mem_p_elt pi x G : pi.-group G -> x \in G -> pi.-elt x. Proof. by move=> piG Gx; apply: pgroupS piG; rewrite cycle_subG. Qed. Lemma p_eltM_norm pi x y : x \in 'N(<[y]>) -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y). Proof. move=> nyx pi_x pi_y; apply: (@mem_p_elt pi _ (<[x]> <*> <[y]>)%G). by rewrite /= norm_joinEl ?cycle_subG // pgroupM; apply/andP. by rewrite groupM // mem_gen // inE cycle_id ?orbT. Qed. Lemma p_eltM pi x y : commute x y -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y). Proof. move=> cxy; apply: p_eltM_norm; apply: (subsetP (cent_sub _)). by rewrite cent_gen cent_set1; apply/cent1P. Qed. Lemma p_elt1 pi : pi.-elt (1 : gT). Proof. by rewrite /p_elt order1. Qed. Lemma p_eltV pi x : pi.-elt x^-1 = pi.-elt x. Proof. by rewrite /p_elt orderV. Qed. Lemma p_eltX pi x n : pi.-elt x -> pi.-elt (x ^+ n). Proof. by rewrite -{1}[x]expg1 !p_elt_exp dvdn1 => /eqnP->. Qed. Lemma p_eltJ pi x y : pi.-elt (x ^ y) = pi.-elt x. Proof. by congr pnat; rewrite orderJ. Qed. Lemma sub_p_elt pi1 pi2 x : {subset pi1 <= pi2} -> pi1.-elt x -> pi2.-elt x. Proof. by move=> pi12; apply: sub_in_pnat => q _; apply: pi12. Qed. Lemma eq_p_elt pi1 pi2 x : pi1 =i pi2 -> pi1.-elt x = pi2.-elt x. Proof. by move=> pi12; apply: eq_pnat. Qed. Lemma p_eltNK pi x : pi^'^'.-elt x = pi.-elt x. Proof. exact: pnatNK. Qed. Lemma eq_constt pi1 pi2 x : pi1 =i pi2 -> x.`_pi1 = x.`_pi2. Proof. move=> pi12; congr (x ^+ (chinese _ _ 1 0)); apply: eq_partn => // a. by congr (~~ _); apply: pi12. Qed. Lemma consttNK pi x : x.`_pi^'^' = x.`_pi. Proof. by rewrite /constt !partnNK. Qed. Lemma cycle_constt pi x : x.`_pi \in <[x]>. Proof. exact: mem_cycle. Qed. Lemma consttV pi x : (x^-1).`_pi = (x.`_pi)^-1. Proof. by rewrite /constt expgVn orderV. Qed. Lemma constt1 pi : 1.`_pi = 1 :> gT. Proof. exact: expg1n. Qed. Lemma consttJ pi x y : (x ^ y).`_pi = x.`_pi ^ y. Proof. by rewrite /constt orderJ conjXg. Qed. Lemma p_elt_constt pi x : pi.-elt x.`_pi. Proof. by rewrite p_elt_exp /chinese addn0 mul1n dvdn_mulr. Qed. Lemma consttC pi x : x.`_pi * x.`_pi^' = x. Proof. apply/eqP; rewrite -{3}[x]expg1 -expgD eq_expg_mod_order. rewrite partnNK -{5 6}(@partnC pi #[x]) // /chinese !addn0. by rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC ?eqxx. Qed. Lemma p'_elt_constt pi x : pi^'.-elt (x * (x.`_pi)^-1). Proof. by rewrite -{1}(consttC pi^' x) consttNK mulgK p_elt_constt. Qed. Lemma order_constt pi (x : gT) : #[x.`_pi] = #[x]`_pi. Proof. rewrite -{2}(consttC pi x) orderM; [|exact: commuteX2|]; last first. by apply: (@pnat_coprime pi); apply: p_elt_constt. by rewrite partnM // part_pnat_id ?part_p'nat ?muln1 //; apply: p_elt_constt. Qed. Lemma consttM pi x y : commute x y -> (x * y).`_pi = x.`_pi * y.`_pi. Proof. move=> cxy; pose m := #|<<[set x; y]>>|; have m_gt0: 0 < m := cardG_gt0 _. pose k := chinese m`_pi m`_pi^' 1 0. suffices kXpi z: z \in <<[set x; y]>> -> z.`_pi = z ^+ k. by rewrite !kXpi ?expgMn // ?groupM ?mem_gen // !inE eqxx ?orbT. move=> xyz; have{xyz} zm: #[z] %| m by rewrite cardSg ?cycle_subG. apply/eqP; rewrite eq_expg_mod_order -{3 4}[#[z]](partnC pi) //. rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC //. rewrite -!(modn_dvdm k (partn_dvd _ m_gt0 zm)). rewrite chinese_modl ?chinese_modr ?coprime_partC //. by rewrite !modn_dvdm ?partn_dvd ?eqxx. Qed. Lemma consttX pi x n : (x ^+ n).`_pi = x.`_pi ^+ n. Proof. elim: n => [|n IHn]; first exact: constt1. by rewrite !expgS consttM ?IHn //; apply: commuteX. Qed. Lemma constt1P pi x : reflect (x.`_pi = 1) (pi^'.-elt x). Proof. rewrite -{2}[x]expg1 p_elt_exp -order_constt consttNK order_dvdn expg1. exact: eqP. Qed. Lemma constt_p_elt pi x : pi.-elt x -> x.`_pi = x. Proof. by rewrite -p_eltNK -{3}(consttC pi x) => /constt1P->; rewrite mulg1. Qed. Lemma sub_in_constt pi1 pi2 x : {in \pi(#[x]), {subset pi1 <= pi2}} -> x.`_pi2.`_pi1 = x.`_pi1. Proof. move=> pi12; rewrite -{2}(consttC pi2 x) consttM; last exact: commuteX2. rewrite (constt1P _ x.`_pi2^' _) ?mulg1 //. apply: sub_in_pnat (p_elt_constt _ x) => p; rewrite order_constt => pi_p. by apply/contra/pi12; rewrite -[#[x]](partnC pi2^') // primesM // pi_p. Qed. Lemma prod_constt x : \prod_(0 <= p < #[x].+1) x.`_p = x. Proof. pose lp n := [pred p | p < n]. have: (lp #[x].+1).-elt x by apply/pnatP=> // p _; apply: dvdn_leq. move/constt_p_elt=> def_x; symmetry; rewrite -{1}def_x {def_x}. elim: _.+1 => [|p IHp]. by rewrite big_nil; apply/constt1P; apply/pgroupP. rewrite big_nat_recr //= -{}IHp -(consttC (lp p) x.`__); congr (_ * _). by rewrite sub_in_constt // => q _; apply: leqW. set y := _.`__; rewrite -(consttC p y) (constt1P p^' _ _) ?mulg1. by rewrite 2?sub_in_constt // => q _; move/eqnP->; rewrite !inE ?ltnn. rewrite /p_elt pnatNK !order_constt -partnI. apply: sub_in_pnat (part_pnat _ _) => q _. by rewrite !inE ltnS -leqNgt -eqn_leq. Qed. Lemma max_pgroupJ pi M G x : x \in G -> [max M | pi.-subgroup(G) M] -> [max M :^ x of M | pi.-subgroup(G) M]. Proof. move=> Gx /maxgroupP[piM maxM]; apply/maxgroupP. split=> [|H piH]; first by rewrite psubgroupJ. by rewrite -(conjsgKV x H) conjSg => /maxM/=-> //; rewrite psubgroupJ ?groupV. Qed. Lemma comm_sub_max_pgroup pi H M G : [max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G -> commute H M -> H \subset M. Proof. case/maxgroupP=> /andP[sMG piM] maxM piH sHG cHM. rewrite -(maxM (H <*> M)%G) /= comm_joingE ?(mulG_subl, mulG_subr) //. by rewrite /psubgroup pgroupM piM piH mul_subG. Qed. Lemma normal_sub_max_pgroup pi H M G : [max M | pi.-subgroup(G) M] -> pi.-group H -> H <| G -> H \subset M. Proof. move=> maxM piH /andP[sHG nHG]. apply: comm_sub_max_pgroup piH sHG _ => //; apply: commute_sym; apply: normC. by apply: subset_trans nHG; case/andP: (maxgroupp maxM). Qed. Lemma norm_sub_max_pgroup pi H M G : [max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G -> H \subset 'N(M) -> H \subset M. Proof. by move=> maxM piH sHG /normC; apply: comm_sub_max_pgroup piH sHG. Qed. Lemma sub_pHall pi H G K : pi.-Hall(G) H -> pi.-group K -> H \subset K -> K \subset G -> K :=: H. Proof. move=> hallH piK sHK sKG; apply/eqP; rewrite eq_sym eqEcard sHK. by rewrite (card_Hall hallH) -(part_pnat_id piK) dvdn_leq ?partn_dvd ?cardSg. Qed. Lemma Hall_max pi H G : pi.-Hall(G) H -> [max H | pi.-subgroup(G) H]. Proof. move=> hallH; apply/maxgroupP; split=> [|K /andP[sKG piK] sHK]. by rewrite /psubgroup; case/and3P: hallH => ->. exact: (sub_pHall hallH). Qed. Lemma pHall_id pi H G : pi.-Hall(G) H -> pi.-group G -> H :=: G. Proof. by move=> hallH piG; rewrite (sub_pHall hallH piG) ?(pHall_sub hallH). Qed. Lemma psubgroup1 pi G : pi.-subgroup(G) 1. Proof. by rewrite /psubgroup sub1G pgroup1. Qed. Lemma Cauchy p G : prime p -> p %| #|G| -> {x | x \in G & #[x] = p}. Proof. move=> p_pr; have [n] := ubnP #|G|; elim: n G => // n IHn G /ltnSE-leGn pG. pose xpG := [pred x in G | #[x] == p]. have [x /andP[Gx /eqP] | no_x] := pickP xpG; first by exists x. have{pG n leGn IHn} pZ: p %| #|'C_G(G)|. suffices /dvdn_addl <-: p %| #|G :\: 'C(G)| by rewrite cardsID. have /acts_sum_card_orbit <-: [acts G, on G :\: 'C(G) | 'J]. by apply/actsP=> x Gx y; rewrite !inE -!mem_conjgV -centJ conjGid ?groupV. elim/big_rec: _ => // _ _ /imsetP[x /setDP[Gx nCx] ->] /dvdn_addl->. have ltCx: 'C_G[x] \proper G by rewrite properE subsetIl subsetIidl sub_cent1. have /negP: ~ p %| #|'C_G[x]|. case/(IHn _ (leq_trans (proper_card ltCx) leGn))=> y /setIP[Gy _] /eqP-oy. by have /andP[] := no_x y. by apply/implyP; rewrite -index_cent1 indexgI implyNb -Euclid_dvdM ?LagrangeI. have [Q maxQ _]: {Q | [max Q | p^'.-subgroup('C_G(G)) Q] & 1%G \subset Q}. by apply: maxgroup_exists; apply: psubgroup1. case/andP: (maxgroupp maxQ) => sQC; rewrite /pgroup p'natE // => /negP[]. apply: dvdn_trans pZ (cardSg _); apply/subsetP=> x /setIP[Gx Cx]. rewrite -sub1set -gen_subG (normal_sub_max_pgroup maxQ) //; last first. rewrite /normal subsetI !cycle_subG ?Gx ?cents_norm ?subIset ?andbT //=. by rewrite centsC cycle_subG Cx. rewrite /pgroup p'natE //= -[#|_|]/#[x]; apply/dvdnP=> [[m oxm]]. have m_gt0: 0 < m by apply: dvdn_gt0 (order_gt0 x) _; rewrite oxm dvdn_mulr. case/idP: (no_x (x ^+ m)); rewrite /= groupX //= orderXgcd //= oxm. by rewrite gcdnC gcdnMr mulKn. Qed. (* These lemmas actually hold for maximal pi-groups, but below we'll *) (* derive from the Cauchy lemma that a normal max pi-group is Hall. *) Lemma sub_normal_Hall pi G H K : pi.-Hall(G) H -> H <| G -> K \subset G -> (K \subset H) = pi.-group K. Proof. move=> hallH nsHG sKG; apply/idP/idP=> [sKH | piK]. by rewrite (pgroupS sKH) ?(pHall_pgroup hallH). apply: norm_sub_max_pgroup (Hall_max hallH) piK _ _ => //. exact: subset_trans sKG (normal_norm nsHG). Qed. Lemma mem_normal_Hall pi H G x : pi.-Hall(G) H -> H <| G -> x \in G -> (x \in H) = pi.-elt x. Proof. by rewrite -!cycle_subG; apply: sub_normal_Hall. Qed. Lemma uniq_normal_Hall pi H G K : pi.-Hall(G) H -> H <| G -> [max K | pi.-subgroup(G) K] -> K :=: H. Proof. move=> hallH nHG /maxgroupP[/andP[sKG piK] /(_ H) -> //]. exact: (maxgroupp (Hall_max hallH)). by rewrite (sub_normal_Hall hallH). Qed. End PgroupProps. Arguments pgroupP {gT pi G}. Arguments constt1P {gT pi x}. Section NormalHall. Variables (gT : finGroupType) (pi : nat_pred). Implicit Types G H K : {group gT}. Lemma normal_max_pgroup_Hall G H : [max H | pi.-subgroup(G) H] -> H <| G -> pi.-Hall(G) H. Proof. case/maxgroupP=> /andP[sHG piH] maxH nsHG; have [_ nHG] := andP nsHG. rewrite /pHall sHG piH; apply/pnatP=> // p p_pr. rewrite inE /= -pnatE // -card_quotient //. case/Cauchy=> //= Hx; rewrite -sub1set -gen_subG -/<[Hx]> /order. case/inv_quotientS=> //= K -> sHK sKG {Hx}. rewrite card_quotient ?(subset_trans sKG) // => iKH; apply/negP=> pi_p. rewrite -iKH -divgS // (maxH K) ?divnn ?cardG_gt0 // in p_pr. by rewrite /psubgroup sKG /pgroup -(Lagrange sHK) mulnC pnatM iKH pi_p. Qed. Lemma setI_normal_Hall G H K : H <| G -> pi.-Hall(G) H -> K \subset G -> pi.-Hall(K) (H :&: K). Proof. move=> nsHG hallH sKG; apply: normal_max_pgroup_Hall; last first. by rewrite /= setIC (normalGI sKG nsHG). apply/maxgroupP; split=> [|M /andP[sMK piM] sHK_M]. by rewrite /psubgroup subsetIr (pgroupS (subsetIl _ _) (pHall_pgroup hallH)). apply/eqP; rewrite eqEsubset sHK_M subsetI sMK !andbT. by rewrite (sub_normal_Hall hallH) // (subset_trans sMK). Qed. End NormalHall. Section Morphim. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Implicit Types (pi : nat_pred) (G H P : {group aT}). Lemma morphim_pgroup pi G : pi.-group G -> pi.-group (f @* G). Proof. by apply: pnat_dvd; apply: dvdn_morphim. Qed. Lemma morphim_odd G : odd #|G| -> odd #|f @* G|. Proof. by rewrite !odd_2'nat; apply: morphim_pgroup. Qed. Lemma pmorphim_pgroup pi G : pi.-group ('ker f) -> G \subset D -> pi.-group (f @* G) = pi.-group G. Proof. move=> piker sGD; apply/idP/idP=> [pifG|]; last exact: morphim_pgroup. apply: (@pgroupS _ _ (f @*^-1 (f @* G))); first by rewrite -sub_morphim_pre. by rewrite /pgroup card_morphpre ?morphimS // pnatM; apply/andP. Qed. Lemma morphim_p_index pi G H : H \subset D -> pi.-nat #|G : H| -> pi.-nat #|f @* G : f @* H|. Proof. by move=> sHD; apply: pnat_dvd; rewrite index_morphim ?subIset // sHD orbT. Qed. Lemma morphim_pHall pi G H : H \subset D -> pi.-Hall(G) H -> pi.-Hall(f @* G) (f @* H). Proof. move=> sHD /and3P[sHG piH pi'GH]. by rewrite /pHall morphimS // morphim_pgroup // morphim_p_index. Qed. Lemma pmorphim_pHall pi G H : G \subset D -> H \subset D -> pi.-subgroup(H :&: G) ('ker f) -> pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H. Proof. move=> sGD sHD /andP[/subsetIP[sKH sKG] piK]; rewrite !pHallE morphimSGK //. apply: andb_id2l => sHG; rewrite -(Lagrange sKH) -(Lagrange sKG) partnM //. by rewrite (part_pnat_id piK) !card_morphim !(setIidPr _) // eqn_pmul2l. Qed. Lemma morphim_Hall G H : H \subset D -> Hall G H -> Hall (f @* G) (f @* H). Proof. by move=> sHD /HallP[pi piH]; apply: (@pHall_Hall _ pi); apply: morphim_pHall. Qed. Lemma morphim_pSylow p G P : P \subset D -> p.-Sylow(G) P -> p.-Sylow(f @* G) (f @* P). Proof. exact: morphim_pHall. Qed. Lemma morphim_p_group P : p_group P -> p_group (f @* P). Proof. by move/morphim_pgroup; apply: pgroup_p. Qed. Lemma morphim_Sylow G P : P \subset D -> Sylow G P -> Sylow (f @* G) (f @* P). Proof. by move=> sPD /andP[pP hallP]; rewrite /Sylow morphim_p_group // morphim_Hall. Qed. Lemma morph_p_elt pi x : x \in D -> pi.-elt x -> pi.-elt (f x). Proof. by move=> Dx; apply: pnat_dvd; apply: morph_order. Qed. Lemma morph_constt pi x : x \in D -> f x.`_pi = (f x).`_pi. Proof. move=> Dx; rewrite -{2}(consttC pi x) morphM ?groupX //. rewrite consttM; last by rewrite !morphX //; apply: commuteX2. have: pi.-elt (f x.`_pi) by rewrite morph_p_elt ?groupX ?p_elt_constt //. have: pi^'.-elt (f x.`_pi^') by rewrite morph_p_elt ?groupX ?p_elt_constt //. by move/constt1P->; move/constt_p_elt->; rewrite mulg1. Qed. End Morphim. Section Pquotient. Variables (pi : nat_pred) (gT : finGroupType) (p : nat) (G H K : {group gT}). Hypothesis piK : pi.-group K. Lemma quotient_pgroup : pi.-group (K / H). Proof. exact: morphim_pgroup. Qed. Lemma quotient_pHall : K \subset 'N(H) -> pi.-Hall(G) K -> pi.-Hall(G / H) (K / H). Proof. exact: morphim_pHall. Qed. Lemma quotient_odd : odd #|K| -> odd #|K / H|. Proof. exact: morphim_odd. Qed. Lemma pquotient_pgroup : G \subset 'N(K) -> pi.-group (G / K) = pi.-group G. Proof. by move=> nKG; rewrite pmorphim_pgroup ?ker_coset. Qed. Lemma pquotient_pHall : K <| G -> K <| H -> pi.-Hall(G / K) (H / K) = pi.-Hall(G) H. Proof. case/andP=> sKG nKG; case/andP=> sKH nKH. by rewrite pmorphim_pHall // ker_coset /psubgroup subsetI sKH sKG. Qed. Lemma ltn_log_quotient : p.-group G -> H :!=: 1 -> H \subset G -> logn p #|G / H| < logn p #|G|. Proof. move=> pG ntH sHG; apply: contraLR (ltn_quotient ntH sHG); rewrite -!leqNgt. rewrite {2}(card_pgroup pG) {2}(card_pgroup (morphim_pgroup _ pG)). by case: (posnP p) => [-> //|]; apply: leq_pexp2l. Qed. End Pquotient. (* Application of card_Aut_cyclic to internal faithful action on cyclic *) (* p-subgroups. *) Section InnerAutCyclicPgroup. Variables (gT : finGroupType) (p : nat) (G C : {group gT}). Hypothesis nCG : G \subset 'N(C). Lemma logn_quotient_cent_cyclic_pgroup : p.-group C -> cyclic C -> logn p #|G / 'C_G(C)| <= (logn p #|C|).-1. Proof. move=> pC cycC; have [-> | ntC] := eqsVneq C 1. by rewrite cent1T setIT trivg_quotient cards1 logn1. have [p_pr _ [e oC]] := pgroup_pdiv pC ntC. rewrite -ker_conj_aut (card_isog (first_isog_loc _ _)) //. apply: leq_trans (dvdn_leq_log _ _ (cardSg (Aut_conj_aut _ _))) _ => //. rewrite card_Aut_cyclic // oC totient_pfactor //= logn_Gauss ?pfactorK //. by rewrite prime_coprime // gtnNdvd // -(subnKC (prime_gt1 p_pr)). Qed. Lemma p'group_quotient_cent_prime : prime p -> #|C| %| p -> p^'.-group (G / 'C_G(C)). Proof. move=> p_pr pC; have pgC: p.-group C := pnat_dvd pC (pnat_id p_pr). have [_ dv_p] := primeP p_pr; case/pred2P: {dv_p pC}(dv_p _ pC) => [|pC]. by move/card1_trivg->; rewrite cent1T setIT trivg_quotient pgroup1. have le_oGC := logn_quotient_cent_cyclic_pgroup pgC. rewrite /pgroup -partn_eq1 ?cardG_gt0 // -dvdn1 p_part pfactor_dvdn // logn1. by rewrite (leq_trans (le_oGC _)) ?prime_cyclic // pC ?(pfactorK 1). Qed. End InnerAutCyclicPgroup. Section PcoreDef. (* A functor needs to quantify over the finGroupType just beore the set. *) Variables (pi : nat_pred) (gT : finGroupType) (A : {set gT}). Definition pcore := \bigcap_(G | [max G | pi.-subgroup(A) G]) G. Canonical pcore_group : {group gT} := Eval hnf in [group of pcore]. End PcoreDef. Arguments pcore pi%_N {gT} A%_g. Arguments pcore_group pi%_N {gT} A%_G. Notation "''O_' pi ( G )" := (pcore pi G) (pi at level 2, format "''O_' pi ( G )") : group_scope. Notation "''O_' pi ( G )" := (pcore_group pi G) : Group_scope. Section PseriesDefs. Variables (pis : seq nat_pred) (gT : finGroupType) (A : {set gT}). Definition pcore_mod pi B := coset B @*^-1 'O_pi(A / B). Canonical pcore_mod_group pi B : {group gT} := Eval hnf in [group of pcore_mod pi B]. Definition pseries := foldr pcore_mod 1 (rev pis). Lemma pseries_group_set : group_set pseries. Proof. by rewrite /pseries; case: rev => [|pi1 pi1']; apply: groupP. Qed. Canonical pseries_group : {group gT} := group pseries_group_set. End PseriesDefs. Arguments pseries pis%_SEQ {gT} _%_g. Local Notation ConsPred p := (@Cons nat_pred p%N) (only parsing). Notation "''O_{' p1 , .. , pn } ( A )" := (pseries (ConsPred p1 .. (ConsPred pn [::]) ..) A) (format "''O_{' p1 , .. , pn } ( A )") : group_scope. Notation "''O_{' p1 , .. , pn } ( A )" := (pseries_group (ConsPred p1 .. (ConsPred pn [::]) ..) A) : Group_scope. Section PCoreProps. Variables (pi : nat_pred) (gT : finGroupType). Implicit Types (A : {set gT}) (G H M K : {group gT}). Lemma pcore_psubgroup G : pi.-subgroup(G) 'O_pi(G). Proof. have [M maxM _]: {M | [max M | pi.-subgroup(G) M] & 1%G \subset M}. by apply: maxgroup_exists; rewrite /psubgroup sub1G pgroup1. have sOM: 'O_pi(G) \subset M by apply: bigcap_inf. have /andP[piM sMG] := maxgroupp maxM. by rewrite /psubgroup (pgroupS sOM) // (subset_trans sOM). Qed. Lemma pcore_pgroup G : pi.-group 'O_pi(G). Proof. by case/andP: (pcore_psubgroup G). Qed. Lemma pcore_sub G : 'O_pi(G) \subset G. Proof. by case/andP: (pcore_psubgroup G). Qed. Lemma pcore_sub_Hall G H : pi.-Hall(G) H -> 'O_pi(G) \subset H. Proof. by move/Hall_max=> maxH; apply: bigcap_inf. Qed. Lemma pcore_max G H : pi.-group H -> H <| G -> H \subset 'O_pi(G). Proof. move=> piH nHG; apply/bigcapsP=> M maxM. exact: normal_sub_max_pgroup piH nHG. Qed. Lemma pcore_pgroup_id G : pi.-group G -> 'O_pi(G) = G. Proof. by move=> piG; apply/eqP; rewrite eqEsubset pcore_sub pcore_max. Qed. Lemma pcore_normal G : 'O_pi(G) <| G. Proof. rewrite /(_ <| G) pcore_sub; apply/subsetP=> x Gx. rewrite inE; apply/bigcapsP=> M maxM; rewrite sub_conjg. by apply: bigcap_inf; apply: max_pgroupJ; rewrite ?groupV. Qed. Lemma normal_Hall_pcore H G : pi.-Hall(G) H -> H <| G -> 'O_pi(G) = H. Proof. move=> hallH nHG; apply/eqP. rewrite eqEsubset (sub_normal_Hall hallH) ?pcore_sub ?pcore_pgroup //=. by rewrite pcore_max //= (pHall_pgroup hallH). Qed. Lemma eq_Hall_pcore G H : pi.-Hall(G) 'O_pi(G) -> pi.-Hall(G) H -> H :=: 'O_pi(G). Proof. move=> hallGpi hallH. exact: uniq_normal_Hall (pcore_normal G) (Hall_max hallH). Qed. Lemma sub_Hall_pcore G K : pi.-Hall(G) 'O_pi(G) -> K \subset G -> (K \subset 'O_pi(G)) = pi.-group K. Proof. by move=> hallGpi; apply: sub_normal_Hall (pcore_normal G). Qed. Lemma mem_Hall_pcore G x : pi.-Hall(G) 'O_pi(G) -> x \in G -> (x \in 'O_pi(G)) = pi.-elt x. Proof. by move=> hallGpi; apply: mem_normal_Hall (pcore_normal G). Qed. Lemma sdprod_Hall_pcoreP H G : pi.-Hall(G) 'O_pi(G) -> reflect ('O_pi(G) ><| H = G) (pi^'.-Hall(G) H). Proof. move=> hallGpi; rewrite -(compl_pHall H hallGpi) complgC. exact: sdprod_normal_complP (pcore_normal G). Qed. Lemma sdprod_pcore_HallP H G : pi^'.-Hall(G) H -> reflect ('O_pi(G) ><| H = G) (pi.-Hall(G) 'O_pi(G)). Proof. exact: sdprod_normal_p'HallP (pcore_normal G). Qed. Lemma pcoreJ G x : 'O_pi(G :^ x) = 'O_pi(G) :^ x. Proof. apply/eqP; rewrite eqEsubset -sub_conjgV. rewrite !pcore_max ?pgroupJ ?pcore_pgroup ?normalJ ?pcore_normal //. by rewrite -(normalJ _ _ x) conjsgKV pcore_normal. Qed. End PCoreProps. Section MorphPcore. Implicit Types (pi : nat_pred) (gT rT : finGroupType). Lemma morphim_pcore pi : GFunctor.pcontinuous (@pcore pi). Proof. move=> gT rT D G f; apply/bigcapsP=> M /normal_sub_max_pgroup; apply. by rewrite morphim_pgroup ?pcore_pgroup. by apply: morphim_normal; apply: pcore_normal. Qed. Lemma pcoreS pi gT (G H : {group gT}) : H \subset G -> H :&: 'O_pi(G) \subset 'O_pi(H). Proof. move=> sHG; rewrite -{2}(setIidPl sHG). by do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom; apply: morphim_pcore. Qed. Canonical pcore_igFun pi := [igFun by pcore_sub pi & morphim_pcore pi]. Canonical pcore_gFun pi := [gFun by morphim_pcore pi]. Canonical pcore_pgFun pi := [pgFun by morphim_pcore pi]. Lemma pcore_char pi gT (G : {group gT}) : 'O_pi(G) \char G. Proof. exact: gFchar. Qed. Section PcoreMod. Variable F : GFunctor.pmap. Lemma pcore_mod_sub pi gT (G : {group gT}) : pcore_mod G pi (F _ G) \subset G. Proof. by rewrite sub_morphpre_im ?gFsub_trans ?morphimS ?gFnorm //= ker_coset gFsub. Qed. Lemma quotient_pcore_mod pi gT (G : {group gT}) (B : {set gT}) : pcore_mod G pi B / B = 'O_pi(G / B). Proof. exact/morphpreK/gFsub_trans/morphim_sub. Qed. Lemma morphim_pcore_mod pi gT rT (D G : {group gT}) (f : {morphism D >-> rT}) : f @* pcore_mod G pi (F _ G) \subset pcore_mod (f @* G) pi (F _ (f @* G)). Proof. have sDF: D :&: G \subset 'dom (coset (F _ G)). by rewrite setIC subIset ?gFnorm. have sDFf: D :&: G \subset 'dom (coset (F _ (f @* G)) \o f). by rewrite -sub_morphim_pre ?subsetIl // morphimIdom gFnorm. pose K := 'ker (restrm sDFf (coset (F _ (f @* G)) \o f)). have sFK: 'ker (restrm sDF (coset (F _ G))) \subset K. rewrite /K !ker_restrm ker_comp /= subsetI subsetIl /= -setIA. rewrite -sub_morphim_pre ?subsetIl //. by rewrite morphimIdom !ker_coset (setIidPr _) ?pmorphimF ?gFsub. have sOF := pcore_sub pi (G / F _ G); have sDD: D :&: G \subset D :&: G by []. rewrite -sub_morphim_pre -?quotientE; last first. by apply: subset_trans (gFnorm F _); rewrite morphimS ?pcore_mod_sub. suffices im_fact (H : {group gT}) : F _ G \subset H -> H \subset G -> factm sFK sDD @* (H / F _ G) = f @* H / F _ (f @* G). - rewrite -2?im_fact ?pcore_mod_sub ?gFsub //; try by rewrite -{1}[F _ G]ker_coset morphpreS ?sub1G. by rewrite quotient_pcore_mod morphim_pcore. move=> sFH sHG; rewrite -(morphimIdom _ (H / _)) /= {2}morphim_restrm setIid. rewrite -morphimIG ?ker_coset //. rewrite -(morphim_restrm sDF) morphim_factm morphim_restrm. by rewrite morphim_comp -quotientE -setIA morphimIdom (setIidPr _). Qed. Lemma pcore_mod_res pi gT rT (D : {group gT}) (f : {morphism D >-> rT}) : f @* pcore_mod D pi (F _ D) \subset pcore_mod (f @* D) pi (F _ (f @* D)). Proof. exact: morphim_pcore_mod. Qed. Lemma pcore_mod1 pi gT (G : {group gT}) : pcore_mod G pi 1 = 'O_pi(G). Proof. rewrite /pcore_mod; have inj1 := coset1_injm gT; rewrite -injmF ?norms1 //. by rewrite -(morphim_invmE inj1) morphim_invm ?norms1. Qed. End PcoreMod. Lemma pseries_rcons pi pis gT (A : {set gT}) : pseries (rcons pis pi) A = pcore_mod A pi (pseries pis A). Proof. by rewrite /pseries rev_rcons. Qed. Lemma pseries_subfun pis : GFunctor.closed (@pseries pis) /\ GFunctor.pcontinuous (@pseries pis). Proof. elim/last_ind: pis => [|pis pi [sFpi fFpi]]. by split=> [gT G | gT rT D G f]; rewrite (sub1G, morphim1). pose fF := [gFun by fFpi : GFunctor.continuous [igFun by sFpi & fFpi]]. pose F := [pgFun by fFpi : GFunctor.hereditary fF]. split=> [gT G | gT rT D G f]; rewrite !pseries_rcons ?(pcore_mod_sub F) //. exact: (morphim_pcore_mod F). Qed. Lemma pseries_sub pis : GFunctor.closed (@pseries pis). Proof. by case: (pseries_subfun pis). Qed. Lemma morphim_pseries pis : GFunctor.pcontinuous (@pseries pis). Proof. by case: (pseries_subfun pis). Qed. Lemma pseriesS pis : GFunctor.hereditary (@pseries pis). Proof. exact: (morphim_pseries pis). Qed. Canonical pseries_igFun pis := [igFun by pseries_sub pis & morphim_pseries pis]. Canonical pseries_gFun pis := [gFun by morphim_pseries pis]. Canonical pseries_pgFun pis := [pgFun by morphim_pseries pis]. Lemma pseries_char pis gT (G : {group gT}) : pseries pis G \char G. Proof. exact: gFchar. Qed. Lemma pseries_normal pis gT (G : {group gT}) : pseries pis G <| G. Proof. exact: gFnormal. Qed. Lemma pseriesJ pis gT (G : {group gT}) x : pseries pis (G :^ x) = pseries pis G :^ x. Proof. rewrite -{1}(setIid G) -morphim_conj -(injmF _ (injm_conj G x)) //=. by rewrite morphim_conj (setIidPr (pseries_sub _ _)). Qed. Lemma pseries1 pi gT (G : {group gT}) : 'O_{pi}(G) = 'O_pi(G). Proof. exact: pcore_mod1. Qed. Lemma pseries_pop pi pis gT (G : {group gT}) : 'O_pi(G) = 1 -> pseries (pi :: pis) G = pseries pis G. Proof. by move=> OG1; rewrite /pseries rev_cons -cats1 foldr_cat /= pcore_mod1 OG1. Qed. Lemma pseries_pop2 pi1 pi2 gT (G : {group gT}) : 'O_pi1(G) = 1 -> 'O_{pi1, pi2}(G) = 'O_pi2(G). Proof. by move/pseries_pop->; apply: pseries1. Qed. Lemma pseries_sub_catl pi1s pi2s gT (G : {group gT}) : pseries pi1s G \subset pseries (pi1s ++ pi2s) G. Proof. elim/last_ind: pi2s => [|pi pis IHpi]; rewrite ?cats0 // -rcons_cat. by rewrite pseries_rcons; apply: subset_trans IHpi _; rewrite sub_cosetpre. Qed. Lemma quotient_pseries pis pi gT (G : {group gT}) : pseries (rcons pis pi) G / pseries pis G = 'O_pi(G / pseries pis G). Proof. by rewrite pseries_rcons quotient_pcore_mod. Qed. Lemma pseries_norm2 pi1s pi2s gT (G : {group gT}) : pseries pi2s G \subset 'N(pseries pi1s G). Proof. by rewrite gFsub_trans ?gFnorm. Qed. Lemma pseries_sub_catr pi1s pi2s gT (G : {group gT}) : pseries pi2s G \subset pseries (pi1s ++ pi2s) G. Proof. elim: pi1s => //= pi1 pi1s /subset_trans; apply. elim/last_ind: {pi1s pi2s}(_ ++ _) => [|pis pi IHpi]; first exact: sub1G. rewrite -rcons_cons (pseries_rcons _ (pi1 :: pis)). rewrite -sub_morphim_pre ?pseries_norm2 //. apply: pcore_max; last by rewrite morphim_normal ?pseries_normal. have: pi.-group (pseries (rcons pis pi) G / pseries pis G). by rewrite quotient_pseries pcore_pgroup. by apply: pnat_dvd; rewrite !card_quotient ?pseries_norm2 // indexgS. Qed. Lemma quotient_pseries2 pi1 pi2 gT (G : {group gT}) : 'O_{pi1, pi2}(G) / 'O_pi1(G) = 'O_pi2(G / 'O_pi1(G)). Proof. by rewrite -pseries1 -quotient_pseries. Qed. Lemma quotient_pseries_cat pi1s pi2s gT (G : {group gT}) : pseries (pi1s ++ pi2s) G / pseries pi1s G = pseries pi2s (G / pseries pi1s G). Proof. elim/last_ind: pi2s => [|pi2s pi IHpi]; first by rewrite cats0 trivg_quotient. have psN := pseries_normal _ G; set K := pseries _ G. case: (third_isom (pseries_sub_catl pi1s pi2s G) (psN _)) => //= f inj_f im_f. have nH2H: pseries pi2s (G / K) <| pseries (pi1s ++ rcons pi2s pi) G / K. rewrite -IHpi morphim_normal // -cats1 catA. by apply/andP; rewrite pseries_sub_catl pseries_norm2. apply: (quotient_inj nH2H). by apply/andP; rewrite /= -cats1 pseries_sub_catl pseries_norm2. rewrite /= quotient_pseries /= -IHpi -rcons_cat. rewrite -[G / _ / _](morphim_invm inj_f) //= {2}im_f //. rewrite -(@injmF [igFun of @pcore pi]) /= ?injm_invm ?im_f // -quotient_pseries. by rewrite -im_f ?morphim_invm ?morphimS ?normal_sub. Qed. Lemma pseries_catl_id pi1s pi2s gT (G : {group gT}) : pseries pi1s (pseries (pi1s ++ pi2s) G) = pseries pi1s G. Proof. elim/last_ind: pi1s => [//|pi1s pi IHpi] in pi2s *. apply: (@quotient_inj _ (pseries_group pi1s G)). - rewrite /= -(IHpi (pi :: pi2s)) cat_rcons /(_ <| _) pseries_norm2. by rewrite -cats1 pseries_sub_catl. - by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl. rewrite /= cat_rcons -(IHpi (pi :: pi2s)) {1}quotient_pseries IHpi. apply/eqP; rewrite quotient_pseries eqEsubset !pcore_max ?pcore_pgroup //=. rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2. by rewrite -cat_rcons pseries_sub_catl. by rewrite gFnormal_trans ?quotient_normal ?gFnormal. Qed. Lemma pseries_char_catl pi1s pi2s gT (G : {group gT}) : pseries pi1s G \char pseries (pi1s ++ pi2s) G. Proof. by rewrite -(pseries_catl_id pi1s pi2s G) pseries_char. Qed. Lemma pseries_catr_id pi1s pi2s gT (G : {group gT}) : pseries pi2s (pseries (pi1s ++ pi2s) G) = pseries pi2s G. Proof. elim/last_ind: pi2s => [//|pi2s pi IHpi] in G *. have Epis: pseries pi2s (pseries (pi1s ++ rcons pi2s pi) G) = pseries pi2s G. by rewrite -cats1 catA -[RHS]IHpi -[LHS]IHpi /= [pseries (_ ++ _) _]pseries_catl_id. apply: (@quotient_inj _ (pseries_group pi2s G)). - by rewrite /= -Epis /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl. - by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl. rewrite /= -Epis {1}quotient_pseries Epis quotient_pseries. apply/eqP; rewrite eqEsubset !pcore_max ?pcore_pgroup //=. rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2. by rewrite pseries_sub_catr. by rewrite gFnormal_trans ?morphim_normal ?gFnormal. Qed. Lemma pseries_char_catr pi1s pi2s gT (G : {group gT}) : pseries pi2s G \char pseries (pi1s ++ pi2s) G. Proof. by rewrite -(pseries_catr_id pi1s pi2s G) pseries_char. Qed. Lemma pcore_modp pi gT (G H : {group gT}) : H <| G -> pi.-group H -> pcore_mod G pi H = 'O_pi(G). Proof. move=> nsHG piH; have nHG := normal_norm nsHG; apply/eqP. rewrite eqEsubset andbC -sub_morphim_pre ?(gFsub_trans, morphim_pcore) //=. rewrite -[G in 'O_pi(G)](quotientGK nsHG) pcore_max //. by rewrite -(pquotient_pgroup piH) ?subsetIl // cosetpreK pcore_pgroup. by rewrite morphpre_normal ?gFnormal ?gFsub_trans ?morphim_sub. Qed. Lemma pquotient_pcore pi gT (G H : {group gT}) : H <| G -> pi.-group H -> 'O_pi(G / H) = 'O_pi(G) / H. Proof. by move=> nsHG piH; rewrite -quotient_pcore_mod pcore_modp. Qed. Lemma trivg_pcore_quotient pi gT (G : {group gT}) : 'O_pi(G / 'O_pi(G)) = 1. Proof. by rewrite pquotient_pcore ?gFnormal ?pcore_pgroup ?trivg_quotient. Qed. Lemma pseries_rcons_id pis pi gT (G : {group gT}) : pseries (rcons (rcons pis pi) pi) G = pseries (rcons pis pi) G. Proof. apply/eqP; rewrite -!cats1 eqEsubset pseries_sub_catl andbT -catA. rewrite -(quotientSGK _ (pseries_sub_catl _ _ _)) ?pseries_norm2 //. rewrite !quotient_pseries_cat -quotient_sub1 ?pseries_norm2 //. by rewrite quotient_pseries_cat /= !pseries1 trivg_pcore_quotient. Qed. End MorphPcore. Section EqPcore. Variables gT : finGroupType. Implicit Types (pi rho : nat_pred) (G H : {group gT}). Lemma sub_in_pcore pi rho G : {in \pi(G), {subset pi <= rho}} -> 'O_pi(G) \subset 'O_rho(G). Proof. move=> pi_sub_rho; rewrite pcore_max ?pcore_normal //. apply: sub_in_pnat (pcore_pgroup _ _) => p. by move/(piSg (pcore_sub _ _)); apply: pi_sub_rho. Qed. Lemma sub_pcore pi rho G : {subset pi <= rho} -> 'O_pi(G) \subset 'O_rho(G). Proof. by move=> pi_sub_rho; apply: sub_in_pcore (in1W pi_sub_rho). Qed. Lemma eq_in_pcore pi rho G : {in \pi(G), pi =i rho} -> 'O_pi(G) = 'O_rho(G). Proof. move=> eq_pi_rho; apply/eqP; rewrite eqEsubset. by rewrite !sub_in_pcore // => p /eq_pi_rho->. Qed. Lemma eq_pcore pi rho G : pi =i rho -> 'O_pi(G) = 'O_rho(G). Proof. by move=> eq_pi_rho; apply: eq_in_pcore (in1W eq_pi_rho). Qed. Lemma pcoreNK pi G : 'O_pi^'^'(G) = 'O_pi(G). Proof. by apply: eq_pcore; apply: negnK. Qed. Lemma eq_p'core pi rho G : pi =i rho -> 'O_pi^'(G) = 'O_rho^'(G). Proof. by move/eq_negn; apply: eq_pcore. Qed. Lemma sdprod_Hall_p'coreP pi H G : pi^'.-Hall(G) 'O_pi^'(G) -> reflect ('O_pi^'(G) ><| H = G) (pi.-Hall(G) H). Proof. by rewrite -(pHallNK pi G H); apply: sdprod_Hall_pcoreP. Qed. Lemma sdprod_p'core_HallP pi H G : pi.-Hall(G) H -> reflect ('O_pi^'(G) ><| H = G) (pi^'.-Hall(G) 'O_pi^'(G)). Proof. by rewrite -(pHallNK pi G H); apply: sdprod_pcore_HallP. Qed. Lemma pcoreI pi rho G : 'O_[predI pi & rho](G) = 'O_pi('O_rho(G)). Proof. apply/eqP; rewrite eqEsubset !pcore_max //. - rewrite /pgroup pnatI -!pgroupE. by rewrite pcore_pgroup (pgroupS (pcore_sub pi _))// pcore_pgroup. - by rewrite !gFnormal_trans. - by apply: sub_pgroup (pcore_pgroup _ _) => p /andP[]. apply/andP; split; first by apply: sub_pcore => p /andP[]. by rewrite gFnorm_trans ?normsG ?gFsub. Qed. Lemma bigcap_p'core pi G : G :&: \bigcap_(p < #|G|.+1 | (p : nat) \in pi) 'O_p^'(G) = 'O_pi^'(G). Proof. apply/eqP; rewrite eqEsubset subsetI pcore_sub pcore_max /=. - by apply/bigcapsP=> p pi_p; apply: sub_pcore => r; apply: contraNneq => ->. - apply/pgroupP=> q q_pr qGpi'; apply: contraL (eqxx q) => /= pi_q. apply: (pgroupP (pcore_pgroup q^' G)) => //. have qG: q %| #|G| by rewrite (dvdn_trans qGpi') // cardSg ?subsetIl. have ltqG: q < #|G|.+1 by rewrite ltnS dvdn_leq. rewrite (dvdn_trans qGpi') ?cardSg ?subIset //= orbC. by rewrite (bigcap_inf (Ordinal ltqG)). rewrite /normal subsetIl normsI ?normG // norms_bigcap //. by apply/bigcapsP => p _; apply: gFnorm. Qed. Lemma coprime_pcoreC (rT : finGroupType) pi G (R : {group rT}) : coprime #|'O_pi(G)| #|'O_pi^'(R)|. Proof. exact: pnat_coprime (pcore_pgroup _ _) (pcore_pgroup _ _). Qed. Lemma TI_pcoreC pi G H : 'O_pi(G) :&: 'O_pi^'(H) = 1. Proof. by rewrite coprime_TIg ?coprime_pcoreC. Qed. Lemma pcore_setI_normal pi G H : H <| G -> 'O_pi(G) :&: H = 'O_pi(H). Proof. move=> nsHG; apply/eqP; rewrite eqEsubset subsetI pcore_sub setIC. rewrite !pcore_max ?(pgroupS (subsetIr H _)) ?pcore_pgroup ?gFnormal_trans //=. by rewrite norm_normalI ?gFnorm_trans ?normsG ?normal_sub. Qed. End EqPcore. Arguments sdprod_Hall_pcoreP {pi gT H G}. Arguments sdprod_Hall_p'coreP {gT pi H G}. Section Injm. Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}). Hypothesis injf : 'injm f. Implicit Types (A : {set aT}) (G H : {group aT}). Lemma injm_pgroup pi A : A \subset D -> pi.-group (f @* A) = pi.-group A. Proof. by move=> sAD; rewrite /pgroup card_injm. Qed. Lemma injm_pelt pi x : x \in D -> pi.-elt (f x) = pi.-elt x. Proof. by move=> Dx; rewrite /p_elt order_injm. Qed. Lemma injm_pHall pi G H : G \subset D -> H \subset D -> pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H. Proof. by move=> sGD sGH; rewrite !pHallE injmSK ?card_injm. Qed. Lemma injm_pcore pi G : G \subset D -> f @* 'O_pi(G) = 'O_pi(f @* G). Proof. exact: injmF. Qed. Lemma injm_pseries pis G : G \subset D -> f @* pseries pis G = pseries pis (f @* G). Proof. exact: injmF. Qed. End Injm. Section Isog. Variables (aT rT : finGroupType) (G : {group aT}) (H : {group rT}). Lemma isog_pgroup pi : G \isog H -> pi.-group G = pi.-group H. Proof. by move=> isoGH; rewrite /pgroup (card_isog isoGH). Qed. Lemma isog_pcore pi : G \isog H -> 'O_pi(G) \isog 'O_pi(H). Proof. exact: gFisog. Qed. Lemma isog_pseries pis : G \isog H -> pseries pis G \isog pseries pis H. Proof. exact: gFisog. Qed. End Isog.
MorphismProperty.lean
/- Copyright (c) 2025 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Abelian.SerreClass.Basic import Mathlib.CategoryTheory.Abelian.DiagramLemmas.KernelCokernelComp import Mathlib.CategoryTheory.MorphismProperty.Composition import Mathlib.CategoryTheory.MorphismProperty.Retract import Mathlib.CategoryTheory.MorphismProperty.IsInvertedBy /-! # The class of isomorphisms modulo a Serre class Let `C` be an abelian category and `P : ObjectProperty C` a Serre class. We define `P.isoModSerre : MorphismProperty C`, which is the class of morphisms `f` such that `kernel f` and `cokernel f` satisfy `P`. We show that `P.isoModSerre` is multiplicative, satisfies the two out of three property and is stable under retracts. (Similarly, we define `P.monoModSerre` and `P.epiModSerre`.) ## TODO * show that a localized category with respect to `P.isoModSerre` is abelian. -/ universe v v' u u' namespace CategoryTheory open Category Limits ZeroObject MorphismProperty variable {C : Type u} [Category.{v} C] [Abelian C] {D : Type u'} [Category.{v'} D] [Abelian D] namespace ObjectProperty variable (P : ObjectProperty C) /-- The class of monomorphisms modulo a Serre class: given a Serre class `P : ObjectProperty C`, this is the class of morphisms `f` such that `kernel f` satisfies `P`. -/ @[nolint unusedArguments] def monoModSerre [P.IsSerreClass] : MorphismProperty C := fun _ _ f ↦ P (kernel f) /-- The class of epimorphisms modulo a Serre class: given a Serre class `P : ObjectProperty C`, this is the class of morphisms `f` such that `cokernel f` satisfies `P`. -/ @[nolint unusedArguments] def epiModSerre [P.IsSerreClass] : MorphismProperty C := fun _ _ f ↦ P (cokernel f) /-- The class of isomorphisms modulo a Serre class: given a Serre class `P : ObjectProperty C`, this is the class of morphisms `f` such that `kernel f` and `cokernel f` satisfy `P`. -/ @[nolint unusedArguments] def isoModSerre [P.IsSerreClass] : MorphismProperty C := P.monoModSerre ⊓ P.epiModSerre variable [P.IsSerreClass] lemma monoModSerre_iff {X Y : C} (f : X ⟶ Y) : P.monoModSerre f ↔ P (kernel f) := Iff.rfl lemma monomorphisms_le_monoModSerre : monomorphisms C ≤ P.monoModSerre := fun _ _ f (_ : Mono f) ↦ P.prop_of_isZero (isZero_kernel_of_mono f) lemma monoModSerre_of_mono {X Y : C} (f : X ⟶ Y) [Mono f] : P.monoModSerre f := P.monomorphisms_le_monoModSerre f (monomorphisms.infer_property f) lemma epiModSerre_iff {X Y : C} (f : X ⟶ Y) : P.epiModSerre f ↔ P (cokernel f) := Iff.rfl lemma epimorphisms_le_epiModSerre : epimorphisms C ≤ P.epiModSerre := fun _ _ f (_ : Epi f) ↦ P.prop_of_isZero (isZero_cokernel_of_epi f) lemma epiModSerre_of_epi {X Y : C} (f : X ⟶ Y) [Epi f] : P.epiModSerre f := P.epimorphisms_le_epiModSerre f (epimorphisms.infer_property f) lemma isoModSerre_iff {X Y : C} (f : X ⟶ Y) : P.isoModSerre f ↔ P.monoModSerre f ∧ P.epiModSerre f := Iff.rfl lemma isoModSerre_iff_of_mono {X Y : C} (f : X ⟶ Y) [Mono f] : P.isoModSerre f ↔ P.epiModSerre f := by have := P.monoModSerre_of_mono f rw [isoModSerre_iff] tauto lemma isoModSerre_iff_of_epi {X Y : C} (f : X ⟶ Y) [Epi f] : P.isoModSerre f ↔ P.monoModSerre f := by have := P.epiModSerre_of_epi f rw [isoModSerre_iff] tauto lemma isoModSerre_of_mono {X Y : C} (f : X ⟶ Y) [Mono f] (hf : P.epiModSerre f) : P.isoModSerre f := by rwa [isoModSerre_iff_of_mono] lemma isoModSerre_of_epi {X Y : C} (f : X ⟶ Y) [Epi f] (hf : P.monoModSerre f) : P.isoModSerre f := by rwa [isoModSerre_iff_of_epi] lemma isomorphisms_le_isoModSerre : isomorphisms C ≤ P.isoModSerre := fun _ _ f (_ : IsIso f) ↦ ⟨P.monoModSerre_of_mono f, P.epiModSerre_of_epi f⟩ lemma isoModSerre_of_isIso {X Y : C} (f : X ⟶ Y) [IsIso f] : P.isoModSerre f := P.isomorphisms_le_isoModSerre f (isomorphisms.infer_property f) instance : P.monoModSerre.IsMultiplicative where id_mem _ := P.monoModSerre_of_mono _ comp_mem f g hf hg := P.prop_X₂_of_exact ((kernelCokernelCompSequence_exact f g).exact 0) hf hg instance : P.epiModSerre.IsMultiplicative where id_mem _ := P.epiModSerre_of_epi _ comp_mem f g hf hg := P.prop_X₂_of_exact ((kernelCokernelCompSequence_exact f g).exact 3) hf hg instance : P.isoModSerre.IsMultiplicative := by dsimp only [isoModSerre] infer_instance instance : P.monoModSerre.IsStableUnderRetracts where of_retract {X' Y' X Y} f' f h hf := P.prop_of_mono (kernel.map f' f h.left.i h.right.i (by simp)) hf instance : P.epiModSerre.IsStableUnderRetracts where of_retract {X' Y' X Y} f' f h hf := P.prop_of_epi (cokernel.map f f' h.left.r h.right.r (by simp)) hf instance : P.isoModSerre.IsStableUnderRetracts := by dsimp only [isoModSerre] infer_instance instance : P.isoModSerre.HasTwoOutOfThreeProperty where of_postcomp f g hg hfg := ⟨P.prop_of_mono (kernel.map f (f ≫ g) (𝟙 _) g (by simp)) hfg.1, P.prop_X₂_of_exact ((kernelCokernelCompSequence_exact f g).exact 2) hg.1 hfg.2⟩ of_precomp f g hf hfg := ⟨P.prop_X₂_of_exact ((kernelCokernelCompSequence_exact f g).exact 1) hfg.1 hf.2, P.prop_of_epi (cokernel.map (f ≫ g) g f (𝟙 _) (by simp)) hfg.2⟩ lemma le_kernel_of_isoModSerre_isInvertedBy (F : C ⥤ D) [F.PreservesZeroMorphisms] (hF : P.isoModSerre.IsInvertedBy F) : P ≤ F.kernel := by intro X hX let f : 0 ⟶ X := 0 have := hF _ ((P.isoModSerre_iff_of_mono f).2 ((P.prop_iff_of_iso cokernelZeroIsoTarget).2 hX)) exact (asIso (F.map f)).isZero_iff.1 (F.map_isZero (isZero_zero C)) lemma isoModSerre_isInvertedBy_iff (F : C ⥤ D) [PreservesFiniteLimits F] [PreservesFiniteColimits F] : P.isoModSerre.IsInvertedBy F ↔ P ≤ F.kernel := by refine ⟨P.le_kernel_of_isoModSerre_isInvertedBy F, fun hF X Y f ⟨h₁, h₂⟩ ↦ ?_⟩ have : Mono (F.map f) := (((ShortComplex.mk _ _ (kernel.condition f)).exact_of_f_is_kernel (kernelIsKernel f)).map F).mono_g (((hF _ h₁).eq_of_src _ _)) have : Epi (F.map f) := (((ShortComplex.mk _ _ (cokernel.condition f)).exact_of_g_is_cokernel (cokernelIsCokernel f)).map F).epi_f (((hF _ h₂).eq_of_tgt _ _)) exact isIso_of_mono_of_epi (F.map f) end ObjectProperty end CategoryTheory
Basic.lean
/- Copyright (c) 2025 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang, Yunzhou Xie -/ import Mathlib.Algebra.Category.ModuleCat.ChangeOfRings import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.Algebra.Category.ModuleCat.Basic import Mathlib.CategoryTheory.Adjunction.Limits /-! # Morita equivalence Two `R`-algebras `A` and `B` are Morita equivalent if the categories of modules over `A` and `B` are `R`-linearly equivalent. In this file, we prove that Morita equivalence is an equivalence relation and that isomorphic algebras are Morita equivalent. # Main definitions - `MoritaEquivalence R A B`: a structure containing an `R`-linear equivalence of categories between the module categories of `A` and `B`. - `IsMoritaEquivalent R A B`: a predicate asserting that `R`-algebras `A` and `B` are Morita equivalent. ## TODO - For any ring `R`, `R` and `Matₙ(R)` are Morita equivalent. - Morita equivalence in terms of projective generators. - Morita equivalence in terms of full idempotents. - Morita equivalence in terms of existence of an invertible bimodule. - If `R ≈ S`, then `R` is simple iff `S` is simple. ## References * [Nathan Jacobson, *Basic Algebra II*][jacobson1989] ## Tags Morita Equivalence, Category Theory, Noncommutative Ring, Module Theory -/ universe u₀ u₁ u₂ u₃ open CategoryTheory variable (R : Type u₀) [CommSemiring R] open scoped ModuleCat.Algebra /-- Let `A` and `B` be `R`-algebras. A Morita equivalence between `A` and `B` is an `R`-linear equivalence between the categories of `A`-modules and `B`-modules. -/ structure MoritaEquivalence (A : Type u₁) [Ring A] [Algebra R A] (B : Type u₂) [Ring B] [Algebra R B] where /-- The underlying equivalence of categories -/ eqv : ModuleCat.{max u₁ u₂} A ≌ ModuleCat.{max u₁ u₂} B linear : eqv.functor.Linear R := by infer_instance namespace MoritaEquivalence attribute [instance] MoritaEquivalence.linear instance {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (e : MoritaEquivalence R A B) : e.eqv.functor.Additive := e.eqv.functor.additive_of_preserves_binary_products /-- For any `R`-algebra `A`, `A` is Morita equivalent to itself. -/ def refl (A : Type u₁) [Ring A] [Algebra R A] : MoritaEquivalence R A A where eqv := CategoryTheory.Equivalence.refl linear := Functor.instLinearId /-- For any `R`-algebras `A` and `B`, if `A` is Morita equivalent to `B`, then `B` is Morita equivalent to `A`. -/ def symm {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (e : MoritaEquivalence R A B) : MoritaEquivalence R B A where eqv := e.eqv.symm linear := e.eqv.inverseLinear R -- TODO: We have restricted all the rings to the same universe here because of the complication -- `max u₁ u₂`, `max u₂ u₃` vs `max u₁ u₃`. But once we proved the definition of Morita -- equivalence is equivalent to the existence of a full idempotent element, we can remove this -- restriction in the universe. -- Or alternatively, @alreadydone has sketched an argument on how the universe restriction can be -- removed via a categorical argument, -- see [here](https://github.com/leanprover-community/mathlib4/pull/20640#discussion_r1912189931) /-- For any `R`-algebras `A`, `B`, and `C`, if `A` is Morita equivalent to `B` and `B` is Morita equivalent to `C`, then `A` is Morita equivalent to `C`. -/ def trans {A B C : Type u₁} [Ring A] [Algebra R A] [Ring B] [Algebra R B] [Ring C] [Algebra R C] (e : MoritaEquivalence R A B) (e' : MoritaEquivalence R B C) : MoritaEquivalence R A C where eqv := e.eqv.trans e'.eqv linear := e.eqv.functor.instLinearComp e'.eqv.functor variable {R} in /-- Isomorphic `R`-algebras are Morita equivalent. -/ noncomputable def ofAlgEquiv {A : Type u₁} {B : Type u₂} [Ring A] [Algebra R A] [Ring B] [Algebra R B] (f : A ≃ₐ[R] B) : MoritaEquivalence R A B where eqv := ModuleCat.restrictScalarsEquivalenceOfRingEquiv f.symm.toRingEquiv linear := ModuleCat.Algebra.restrictScalarsEquivalenceOfRingEquiv_linear f.symm end MoritaEquivalence /-- Let `A` and `B` be `R`-algebras. We say that `A` and `B` are Morita equivalent if the categories of `A`-modules and `B`-modules are equivalent as `R`-linear categories. -/ structure IsMoritaEquivalent (A : Type u₁) [Ring A] [Algebra R A] (B : Type u₂) [Ring B] [Algebra R B] : Prop where cond : Nonempty <| MoritaEquivalence R A B namespace IsMoritaEquivalent lemma refl (A : Type u₁) [Ring A] [Algebra R A] : IsMoritaEquivalent R A A where cond := ⟨.refl R A⟩ lemma symm {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (h : IsMoritaEquivalent R A B) : IsMoritaEquivalent R B A where cond := h.cond.map <| .symm R lemma trans {A B C : Type u₁} [Ring A] [Ring B] [Ring C] [Algebra R A] [Algebra R B] [Algebra R C] (h : IsMoritaEquivalent R A B) (h' : IsMoritaEquivalent R B C) : IsMoritaEquivalent R A C where cond := Nonempty.map2 (.trans R) h.cond h'.cond lemma of_algEquiv {A : Type u₁} [Ring A] [Algebra R A] {B : Type u₂} [Ring B] [Algebra R B] (f : A ≃ₐ[R] B) : IsMoritaEquivalent R A B where cond := ⟨.ofAlgEquiv f⟩ end IsMoritaEquivalent
Enum.lean
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.Family /-! # Enumerating sets of ordinals by ordinals The ordinals have the peculiar property that every subset bounded above is a small type, while themselves not being small. As a consequence of this, every unbounded subset of `Ordinal` is order isomorphic to `Ordinal`. We define this correspondence as `enumOrd`, and use it to then define an order isomorphism `enumOrdOrderIso`. This can be thought of as an ordinal analog of `Nat.nth`. -/ universe u open Order Set namespace Ordinal variable {o a b : Ordinal.{u}} /-- Enumerator function for an unbounded set of ordinals. -/ noncomputable def enumOrd (s : Set Ordinal.{u}) (o : Ordinal.{u}) : Ordinal.{u} := sInf (s ∩ { b | ∀ c, c < o → enumOrd s c < b }) termination_by o variable {s : Set Ordinal.{u}} theorem enumOrd_le_of_forall_lt (ha : a ∈ s) (H : ∀ b < o, enumOrd s b < a) : enumOrd s o ≤ a := by rw [enumOrd] exact csInf_le' ⟨ha, H⟩ /-- The set in the definition of `enumOrd` is nonempty. -/ private theorem enumOrd_nonempty (hs : ¬ BddAbove s) (o : Ordinal) : (s ∩ { b | ∀ c, c < o → enumOrd s c < b }).Nonempty := by rw [not_bddAbove_iff] at hs obtain ⟨a, ha⟩ := bddAbove_of_small (enumOrd s '' Iio o) obtain ⟨b, hb, hba⟩ := hs a exact ⟨b, hb, fun c hc ↦ (ha (mem_image_of_mem _ hc)).trans_lt hba⟩ private theorem enumOrd_mem_aux (hs : ¬ BddAbove s) (o : Ordinal) : enumOrd s o ∈ s ∩ { b | ∀ c, c < o → enumOrd s c < b } := by rw [enumOrd] exact csInf_mem (enumOrd_nonempty hs o) theorem enumOrd_mem (hs : ¬ BddAbove s) (o : Ordinal) : enumOrd s o ∈ s := (enumOrd_mem_aux hs o).1 theorem enumOrd_strictMono (hs : ¬ BddAbove s) : StrictMono (enumOrd s) := fun a b ↦ (enumOrd_mem_aux hs b).2 a theorem enumOrd_injective (hs : ¬ BddAbove s) : Function.Injective (enumOrd s) := (enumOrd_strictMono hs).injective theorem enumOrd_inj (hs : ¬ BddAbove s) {a b : Ordinal} : enumOrd s a = enumOrd s b ↔ a = b := (enumOrd_injective hs).eq_iff theorem enumOrd_le_enumOrd (hs : ¬ BddAbove s) {a b : Ordinal} : enumOrd s a ≤ enumOrd s b ↔ a ≤ b := (enumOrd_strictMono hs).le_iff_le theorem enumOrd_lt_enumOrd (hs : ¬ BddAbove s) {a b : Ordinal} : enumOrd s a < enumOrd s b ↔ a < b := (enumOrd_strictMono hs).lt_iff_lt theorem id_le_enumOrd (hs : ¬ BddAbove s) : id ≤ enumOrd s := (enumOrd_strictMono hs).id_le theorem le_enumOrd_self (hs : ¬ BddAbove s) {a} : a ≤ enumOrd s a := (enumOrd_strictMono hs).le_apply theorem enumOrd_succ_le (hs : ¬ BddAbove s) (ha : a ∈ s) (hb : enumOrd s b < a) : enumOrd s (succ b) ≤ a := by apply enumOrd_le_of_forall_lt ha intro c hc rw [lt_succ_iff] at hc exact ((enumOrd_strictMono hs).monotone hc).trans_lt hb theorem range_enumOrd (hs : ¬ BddAbove s) : range (enumOrd s) = s := by ext a let t := { b | a ≤ enumOrd s b } constructor · rintro ⟨b, rfl⟩ exact enumOrd_mem hs b · intro ha refine ⟨sInf t, (enumOrd_le_of_forall_lt ha ?_).antisymm ?_⟩ · intro b hb by_contra! hb' exact hb.not_ge (csInf_le' hb') · exact csInf_mem (s := t) ⟨a, (enumOrd_strictMono hs).id_le a⟩ theorem enumOrd_surjective (hs : ¬ BddAbove s) {b : Ordinal} (hb : b ∈ s) : ∃ a, enumOrd s a = b := by rwa [← range_enumOrd hs] at hb theorem enumOrd_le_of_subset {t : Set Ordinal} (hs : ¬ BddAbove s) (hst : s ⊆ t) : enumOrd t ≤ enumOrd s := by intro a rw [enumOrd, enumOrd] apply csInf_le_csInf' (enumOrd_nonempty hs a) (inter_subset_inter hst _) intro b hb c hc exact (enumOrd_le_of_subset hs hst c).trans_lt <| hb c hc termination_by a => a /-- A characterization of `enumOrd`: it is the unique strict monotonic function with range `s`. -/ theorem eq_enumOrd (f : Ordinal → Ordinal) (hs : ¬ BddAbove s) : enumOrd s = f ↔ StrictMono f ∧ range f = s := by constructor · rintro rfl exact ⟨enumOrd_strictMono hs, range_enumOrd hs⟩ · rintro ⟨h₁, h₂⟩ rwa [← (enumOrd_strictMono hs).range_inj h₁, range_enumOrd hs, eq_comm] theorem enumOrd_range {f : Ordinal → Ordinal} (hf : StrictMono f) : enumOrd (range f) = f := (eq_enumOrd _ hf.not_bddAbove_range_of_wellFoundedLT).2 ⟨hf, rfl⟩ /-- If `s` is closed under nonempty suprema, then its enumerator function is normal. See also `enumOrd_isNormal_iff_isClosed`. -/ theorem isNormal_enumOrd (H : ∀ t ⊆ s, t.Nonempty → BddAbove t → sSup t ∈ s) (hs : ¬ BddAbove s) : IsNormal (enumOrd s) := by refine (isNormal_iff_strictMono_limit _).2 ⟨enumOrd_strictMono hs, fun o ho a ha ↦ ?_⟩ trans ⨆ b : Iio o, enumOrd s b · refine enumOrd_le_of_forall_lt ?_ (fun b hb ↦ (enumOrd_strictMono hs (lt_succ b)).trans_le ?_) · have : Nonempty (Iio o) := ⟨0, ho.bot_lt⟩ apply H _ _ (range_nonempty _) (bddAbove_of_small _) rintro _ ⟨c, rfl⟩ exact enumOrd_mem hs c · exact Ordinal.le_iSup _ (⟨_, ho.succ_lt hb⟩ : Iio o) · exact Ordinal.iSup_le fun x ↦ ha _ x.2 @[simp] theorem enumOrd_univ : enumOrd Set.univ = id := by rw [← range_id] exact enumOrd_range strictMono_id @[simp] theorem enumOrd_zero : enumOrd s 0 = sInf s := by rw [enumOrd] simp [Ordinal.not_lt_zero] /-- An order isomorphism between an unbounded set of ordinals and the ordinals. -/ noncomputable def enumOrdOrderIso (s : Set Ordinal) (hs : ¬ BddAbove s) : Ordinal ≃o s := StrictMono.orderIsoOfSurjective (fun o => ⟨_, enumOrd_mem hs o⟩) (enumOrd_strictMono hs) fun s => let ⟨a, ha⟩ := enumOrd_surjective hs s.prop ⟨a, Subtype.eq ha⟩ end Ordinal
FunctionData.lean
/- Copyright (c) 2024 Tomáš Skřivan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Tomáš Skřivan -/ import Qq import Mathlib.Tactic.FunProp.Mor import Mathlib.Tactic.FunProp.ToBatteries /-! ## `funProp` data structure holding information about a function `FunctionData` holds data about function in the form `fun x => f x₁ ... xₙ`. -/ namespace Mathlib open Lean Meta namespace Meta.FunProp /-- Structure storing parts of a function in funProp-normal form. -/ structure FunctionData where /-- local context where `mainVar` exists -/ lctx : LocalContext /-- local instances -/ insts : LocalInstances /-- main function -/ fn : Expr /-- applied function arguments -/ args : Array Mor.Arg /-- main variable -/ mainVar : Expr /-- indices of `args` that contain `mainVars` -/ mainArgs : Array Nat /-- Turn function data back to expression. -/ def FunctionData.toExpr (f : FunctionData) : MetaM Expr := do withLCtx f.lctx f.insts do let body := Mor.mkAppN f.fn f.args mkLambdaFVars #[f.mainVar] body /-- Is `f` an identity function? -/ def FunctionData.isIdentityFun (f : FunctionData) : Bool := (f.args.size = 0 && f.fn == f.mainVar) /-- Is `f` a constant function? -/ def FunctionData.isConstantFun (f : FunctionData) : Bool := ((f.mainArgs.size = 0) && !(f.fn.containsFVar f.mainVar.fvarId!)) /-- Domain type of `f`. -/ def FunctionData.domainType (f : FunctionData) : MetaM Expr := withLCtx f.lctx f.insts do inferType f.mainVar /-- Is head function of `f` a constant? If the head of `f` is a projection return the name of corresponding projection function. -/ def FunctionData.getFnConstName? (f : FunctionData) : MetaM (Option Name) := do match f.fn with | .const n _ => return n | .proj typeName idx _ => let .some info := getStructureInfo? (← getEnv) typeName | return none let .some projName := info.getProjFn? idx | return none return projName | _ => return none /-- Get `FunctionData` for `f`. Throws if `f` can't be put into funProp-normal form. -/ def getFunctionData (f : Expr) : MetaM FunctionData := do lambdaTelescope f fun xs b => do let xId := xs[0]!.fvarId! Mor.withApp b fun fn args => do let mut fn := fn let mut args := args -- revert projection in fn if let .proj n i x := fn then let .some info := getStructureInfo? (← getEnv) n | unreachable! let .some projName := info.getProjFn? i | unreachable! let p ← mkAppM projName #[x] fn := p.getAppFn args := p.getAppArgs.map (fun a => {expr:=a}) ++ args let mainArgs := args |>.mapIdx (fun i ⟨arg,_⟩ => if arg.containsFVar xId then some i else none) |>.filterMap id return { lctx := ← getLCtx insts := ← getLocalInstances fn := fn args := args mainVar := xs[0]! mainArgs := mainArgs } /-- Result of `getFunctionData?`. It returns function data if the function is in the form `fun x => f y₁ ... yₙ`. Two other cases are `fun x => let y := ...` or `fun x y => ...` -/ inductive MaybeFunctionData where /-- Can't generate function data as function body has let binder. -/ | letE (f : Expr) /-- Can't generate function data as function body has lambda binder. -/ | lam (f : Expr) /-- Function data has been successfully generated. -/ | data (fData : FunctionData) /-- Turn `MaybeFunctionData` to the function. -/ def MaybeFunctionData.get (fData : MaybeFunctionData) : MetaM Expr := match fData with | .letE f | .lam f => pure f | .data d => d.toExpr /-- Get `FunctionData` for `f`. -/ def getFunctionData? (f : Expr) (unfoldPred : Name → Bool := fun _ => false) : MetaM MaybeFunctionData := do withConfig (fun cfg => { cfg with zeta := false, zetaDelta := false }) do let unfold := fun e : Expr => do if let .some n := e.getAppFn'.constName? then pure ((unfoldPred n) || (← isReducible n)) else pure false let .forallE xName xType _ _ ← instantiateMVars (← inferType f) | throwError m!"fun_prop bug: function expected, got `{f} : {← inferType f}, \ type ctor {(← inferType f).ctorName}" withLocalDeclD xName xType fun x => do let fx' := (← Mor.whnfPred (f.beta #[x]).eta unfold) |> headBetaThroughLet let f' ← mkLambdaFVars #[x] fx' match fx' with | .letE .. => return .letE f' | .lam .. => return .lam f' | _ => return .data (← getFunctionData f') /-- If head function is a let-fvar unfold it and return resulting function. Return `none` otherwise. -/ def FunctionData.unfoldHeadFVar? (fData : FunctionData) : MetaM (Option Expr) := do let .fvar id := fData.fn | return none let .some val ← id.getValue? | return none let f ← withLCtx fData.lctx fData.insts do mkLambdaFVars #[fData.mainVar] (headBetaThroughLet (Mor.mkAppN val fData.args)) return f /-- Type of morphism application. -/ inductive MorApplication where /-- Of the form `⇑f` i.e. missing argument. -/ | underApplied /-- Of the form `⇑f x` i.e. morphism and one argument is provided. -/ | exact /-- Of the form `⇑f x y ...` i.e. additional applied arguments `y ...`. -/ | overApplied /-- Not a morphism application. -/ | none deriving Inhabited, BEq /-- Is function body of `f` a morphism application? What kind? -/ def FunctionData.isMorApplication (f : FunctionData) : MetaM MorApplication := do if let .some name := f.fn.constName? then if ← Mor.isCoeFunName name then let info ← getConstInfo name let arity := info.type.getNumHeadForalls match compare arity f.args.size with | .eq => return .exact | .lt => return .overApplied | .gt => return .underApplied match h : f.args.size with | 0 => return .none | n + 1 => if f.args[n].coe.isSome then return .exact else if f.args.any (fun a => a.coe.isSome) then return .overApplied else return .none /-- Decomposes `fun x => f y₁ ... yₙ` into `(fun g => g yₙ) ∘ (fun x y => f y₁ ... yₙ₋₁ y)` Returns none if: - `n=0` - `yₙ` contains `x` - `n=1` and `(fun x y => f y)` is identity function i.e. `x=f` -/ def FunctionData.peeloffArgDecomposition (fData : FunctionData) : MetaM (Option (Expr × Expr)) := do unless fData.args.size > 0 do return none withLCtx fData.lctx fData.insts do let n := fData.args.size let x := fData.mainVar let yₙ := fData.args[n-1]! if yₙ.expr.containsFVar x.fvarId! then return none if fData.args.size = 1 && fData.mainVar == fData.fn then return none let gBody' := Mor.mkAppN fData.fn fData.args[:n-1] let gBody' := if let .some coe := yₙ.coe then coe.app gBody' else gBody' let g' ← mkLambdaFVars #[x] gBody' let f' := Expr.lam `f (← inferType gBody') (.app (.bvar 0) (yₙ.expr)) default return (f',g') /-- Decompose function `f = (← fData.toExpr)` into composition of two functions. Returns none if the decomposition would produce composition with identity function. -/ def FunctionData.nontrivialDecomposition (fData : FunctionData) : MetaM (Option (Expr × Expr)) := do let mut lctx := fData.lctx let insts := fData.insts let x := fData.mainVar let xId := x.fvarId! let xName ← withLCtx lctx insts xId.getUserName let fn := fData.fn let mut args := fData.args if fn.containsFVar xId then return ← fData.peeloffArgDecomposition let mut yVals : Array Expr := #[] let mut yVars : Array Expr := #[] for argId in fData.mainArgs do let yVal := args[argId]! let yVal' := yVal.expr let yId ← withLCtx lctx insts mkFreshFVarId let yType ← withLCtx lctx insts (inferType yVal') if yType.containsFVar fData.mainVar.fvarId! then return none lctx := lctx.mkLocalDecl yId (xName.appendAfter (toString argId)) yType let yVar := Expr.fvar yId yVars := yVars.push yVar yVals := yVals.push yVal' args := args.set! argId ⟨yVar, yVal.coe⟩ let g ← withLCtx lctx insts do mkLambdaFVars #[x] (← mkProdElem yVals) let f ← withLCtx lctx insts do (mkLambdaFVars yVars (Mor.mkAppN fn args)) >>= mkUncurryFun yVars.size -- check if is non-triviality let f' ← fData.toExpr if (← withReducibleAndInstances <| isDefEq f' f <||> isDefEq f' g) then return none return (f, g) /-- Decompose function `fun x => f y₁ ... yₙ` over specified argument indices `#[i, j, ...]`. The result is: ``` (fun (yᵢ',yⱼ',...) => f y₁ .. yᵢ' .. yⱼ' .. yₙ) ∘ (fun x => (yᵢ, yⱼ, ...)) ``` This is not possible if `yₗ` for `l ∉ #[i,j,...]` still contains `x`. In such case `none` is returned. -/ def FunctionData.decompositionOverArgs (fData : FunctionData) (args : Array Nat) : MetaM (Option (Expr × Expr)) := do unless isOrderedSubsetOf fData.mainArgs args do return none unless ¬(fData.fn.containsFVar fData.mainVar.fvarId!) do return none withLCtx fData.lctx fData.insts do let gxs := args.map (fun i => fData.args[i]!.expr) try let gx ← mkProdElem gxs -- this can crash if we have dependent types let g ← withLCtx fData.lctx fData.insts <| mkLambdaFVars #[fData.mainVar] gx withLocalDeclD `y (← inferType gx) fun y => do let ys ← mkProdSplitElem y gxs.size let args' := (args.zip ys).foldl (init := fData.args) (fun args' (i,y) => args'.set! i { expr := y, coe := args'[i]!.coe }) let f ← mkLambdaFVars #[y] (Mor.mkAppN fData.fn args') return (f,g) catch _ => return none end Meta.FunProp end Mathlib
PseudometrizableLindelof.lean
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Metrizable.Basic import Mathlib.Topology.Compactness.Lindelof /-! # Second-countability of pseudometrizable Lindelöf spaces Factored out from `Mathlib/Topology/Compactness/Lindelof.lean` to avoid circular dependencies. -/ variable {X : Type*} [TopologicalSpace X] open Set Filter Topology TopologicalSpace instance SecondCountableTopology.ofPseudoMetrizableSpaceLindelofSpace [PseudoMetrizableSpace X] [LindelofSpace X] : SecondCountableTopology X := by letI : PseudoMetricSpace X := TopologicalSpace.pseudoMetrizableSpacePseudoMetric X have h_dense (ε) (hpos : 0 < ε) : ∃ s : Set X, s.Countable ∧ ∀ x, ∃ y ∈ s, dist x y ≤ ε := by let U := fun (z : X) ↦ Metric.ball z ε obtain ⟨t, hct, huniv⟩ := LindelofSpace.elim_nhds_subcover U (fun _ ↦ (Metric.isOpen_ball).mem_nhds (Metric.mem_ball_self hpos)) refine ⟨t, hct, fun z ↦ ?_⟩ obtain ⟨y, ht, hzy⟩ : ∃ y ∈ t, z ∈ U y := exists_set_mem_of_union_eq_top t (fun i ↦ U i) huniv z exact ⟨y, ht, (Metric.mem_ball.mp hzy).le⟩ exact Metric.secondCountable_of_almost_dense_set h_dense
Basic.lean
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Finite.Prod import Mathlib.Data.Matroid.Init import Mathlib.Data.Set.Card import Mathlib.Data.Set.Finite.Powerset import Mathlib.Order.UpperLower.Closure /-! # Matroids A `Matroid` is a structure that combinatorially abstracts the notion of linear independence and dependence; matroids have connections with graph theory, discrete optimization, additive combinatorics and algebraic geometry. Mathematically, a matroid `M` is a structure on a set `E` comprising a collection of subsets of `E` called the bases of `M`, where the bases are required to obey certain axioms. This file gives a definition of a matroid `M` in terms of its bases, and some API relating independent sets (subsets of bases) and the notion of a basis of a set `X` (a maximal independent subset of `X`). ## Main definitions * a `Matroid α` on a type `α` is a structure comprising a 'ground set' and a suitably behaved 'base' predicate. Given `M : Matroid α` ... * `M.E` denotes the ground set of `M`, which has type `Set α` * For `B : Set α`, `M.IsBase B` means that `B` is a base of `M`. * For `I : Set α`, `M.Indep I` means that `I` is independent in `M` (that is, `I` is contained in a base of `M`). * For `D : Set α`, `M.Dep D` means that `D` is contained in the ground set of `M` but isn't independent. * For `I : Set α` and `X : Set α`, `M.IsBasis I X` means that `I` is a maximal independent subset of `X`. * `M.Finite` means that `M` has finite ground set. * `M.Nonempty` means that the ground set of `M` is nonempty. * `RankFinite M` means that the bases of `M` are finite. * `RankInfinite M` means that the bases of `M` are infinite. * `RankPos M` means that the bases of `M` are nonempty. * `Finitary M` means that a set is independent if and only if all its finite subsets are independent. * `aesop_mat` : a tactic designed to prove `X ⊆ M.E` for some set `X` and matroid `M`. ## Implementation details There are a few design decisions worth discussing. ### Finiteness The first is that our matroids are allowed to be infinite. Unlike with many mathematical structures, this isn't such an obvious choice. Finite matroids have been studied since the 1930's, and there was never controversy as to what is and isn't an example of a finite matroid - in fact, surprisingly many apparently different definitions of a matroid give rise to the same class of objects. However, generalizing different definitions of a finite matroid to the infinite in the obvious way (i.e. by simply allowing the ground set to be infinite) gives a number of different notions of 'infinite matroid' that disagree with each other, and that all lack nice properties. Many different competing notions of infinite matroid were studied through the years; in fact, the problem of which definition is the best was only really solved in 2013, when Bruhn et al. [2] showed that there is a unique 'reasonable' notion of an infinite matroid (these objects had previously defined by Higgs under the name 'B-matroid'). These are defined by adding one carefully chosen axiom to the standard set, and adapting existing axioms to not mention set cardinalities; they enjoy nearly all the nice properties of standard finite matroids. Even though at least 90% of the literature is on finite matroids, B-matroids are the definition we use, because they allow for additional generality, nearly all theorems are still true and just as easy to state, and (hopefully) the more general definition will prevent the need for a costly future refactor. The disadvantage is that developing API for the finite case is harder work (for instance, it is harder to prove that something is a matroid in the first place, and one must deal with `ℕ∞` rather than `ℕ`). For serious work on finite matroids, we provide the typeclasses `[M.Finite]` and `[RankFinite M]` and associated API. ### Cardinality Just as with bases of a vector space, all bases of a finite matroid `M` are finite and have the same cardinality; this cardinality is an important invariant known as the 'rank' of `M`. For infinite matroids, bases are not in general equicardinal; in fact the equicardinality of bases of infinite matroids is independent of ZFC [3]. What is still true is that either all bases are finite and equicardinal, or all bases are infinite. This means that the natural notion of 'size' for a set in matroid theory is given by the function `Set.encard`, which is the cardinality as a term in `ℕ∞`. We use this function extensively in building the API; it is preferable to both `Set.ncard` and `Finset.card` because it allows infinite sets to be handled without splitting into cases. ### The ground `Set` A last place where we make a consequential choice is making the ground set of a matroid a structure field of type `Set α` (where `α` is the type of 'possible matroid elements') rather than just having a type `α` of all the matroid elements. This is because of how common it is to simultaneously consider a number of matroids on different but related ground sets. For example, a matroid `M` on ground set `E` can have its structure 'restricted' to some subset `R ⊆ E` to give a smaller matroid `M ↾ R` with ground set `R`. A statement like `(M ↾ R₁) ↾ R₂ = M ↾ R₂` is mathematically obvious. But if the ground set of a matroid is a type, this doesn't typecheck, and is only true up to canonical isomorphism. Restriction is just the tip of the iceberg here; one can also 'contract' and 'delete' elements and sets of elements in a matroid to give a smaller matroid, and in practice it is common to make statements like `M₁.E = M₂.E ∩ M₃.E` and `((M ⟋ e) ↾ R) ⟋ C = M ⟋ (C ∪ {e}) ↾ R`. Such things are a nightmare to work with unless `=` is actually propositional equality (especially because the relevant coercions are usually between sets and not just elements). So the solution is that the ground set `M.E` has type `Set α`, and there are elements of type `α` that aren't in the matroid. The tradeoff is that for many statements, one now has to add hypotheses of the form `X ⊆ M.E` to make sure than `X` is actually 'in the matroid', rather than letting a 'type of matroid elements' take care of this invisibly. It still seems that this is worth it. The tactic `aesop_mat` exists specifically to discharge such goals with minimal fuss (using default values). The tactic works fairly well, but has room for improvement. A related decision is to not have matroids themselves be a typeclass. This would make things be notationally simpler (having `Base` in the presence of `[Matroid α]` rather than `M.Base` for a term `M : Matroid α`) but is again just too awkward when one has multiple matroids on the same type. In fact, in regular written mathematics, it is normal to explicitly indicate which matroid something is happening in, so our notation mirrors common practice. ### Notation We use a few nonstandard conventions in theorem names that are related to the above. First, we mirror common informal practice by referring explicitly to the `ground` set rather than the notation `E`. (Writing `ground` everywhere in a proof term would be unwieldy, and writing `E` in theorem names would be unnatural to read.) Second, because we are typically interested in subsets of the ground set `M.E`, using `Set.compl` is inconvenient, since `Xᶜ ⊆ M.E` is typically false for `X ⊆ M.E`. On the other hand (especially when duals arise), it is common to complement a set `X ⊆ M.E` *within* the ground set, giving `M.E \ X`. For this reason, we use the term `compl` in theorem names to refer to taking a set difference with respect to the ground set, rather than a complement within a type. The lemma `compl_isBase_dual` is one of the many examples of this. Finally, in theorem names, matroid predicates that apply to sets (such as `Base`, `Indep`, `IsBasis`) are typically used as suffixes rather than prefixes. For instance, we have `ground_indep_iff_isBase` rather than `indep_ground_iff_isBase`. ## References * [J. Oxley, Matroid Theory][oxley2011] * [H. Bruhn, R. Diestel, M. Kriesell, R. Pendavingh, P. Wollan, Axioms for infinite matroids, Adv. Math 239 (2013), 18-46][bruhnDiestelKriesselPendavinghWollan2013] * [N. Bowler, S. Geschke, Self-dual uniform matroids on infinite sets, Proc. Amer. Math. Soc. 144 (2016), 459-471][bowlerGeschke2015] -/ assert_not_exists Field open Set /-- A predicate `P` on sets satisfies the **exchange property** if, for all `X` and `Y` satisfying `P` and all `a ∈ X \ Y`, there exists `b ∈ Y \ X` so that swapping `a` for `b` in `X` maintains `P`. -/ def Matroid.ExchangeProperty {α : Type*} (P : Set α → Prop) : Prop := ∀ X Y, P X → P Y → ∀ a ∈ X \ Y, ∃ b ∈ Y \ X, P (insert b (X \ {a})) /-- A set `X` has the maximal subset property for a predicate `P` if every subset of `X` satisfying `P` is contained in a maximal subset of `X` satisfying `P`. -/ def Matroid.ExistsMaximalSubsetProperty {α : Type*} (P : Set α → Prop) (X : Set α) : Prop := ∀ I, P I → I ⊆ X → ∃ J, I ⊆ J ∧ Maximal (fun K ↦ P K ∧ K ⊆ X) J /-- A `Matroid α` is a ground set `E` of type `Set α`, and a nonempty collection of its subsets satisfying the exchange property and the maximal subset property. Each such set is called a `Base` of `M`. An `Indep`endent set is just a set contained in a base, but we include this predicate as a structure field for better definitional properties. In most cases, using this definition directly is not the best way to construct a matroid, since it requires specifying both the bases and independent sets. If the bases are known, use `Matroid.ofBase` or a variant. If just the independent sets are known, define an `IndepMatroid`, and then use `IndepMatroid.matroid`. -/ structure Matroid (α : Type*) where /-- `M` has a ground set `E`. -/ (E : Set α) /-- `M` has a predicate `Base` defining its bases. -/ (IsBase : Set α → Prop) /-- `M` has a predicate `Indep` defining its independent sets. -/ (Indep : Set α → Prop) /-- The `Indep`endent sets are those contained in `Base`s. -/ (indep_iff' : ∀ ⦃I⦄, Indep I ↔ ∃ B, IsBase B ∧ I ⊆ B) /-- There is at least one `Base`. -/ (exists_isBase : ∃ B, IsBase B) /-- For any bases `B`, `B'` and `e ∈ B \ B'`, there is some `f ∈ B' \ B` for which `B-e+f` is a base. -/ (isBase_exchange : Matroid.ExchangeProperty IsBase) /-- Every independent subset `I` of a set `X` for is contained in a maximal independent subset of `X`. -/ (maximality : ∀ X, X ⊆ E → Matroid.ExistsMaximalSubsetProperty Indep X) /-- Every base is contained in the ground set. -/ (subset_ground : ∀ B, IsBase B → B ⊆ E) attribute [local ext] Matroid namespace Matroid variable {α : Type*} {M : Matroid α} @[deprecated (since := "2025-02-14")] alias Base := IsBase instance (M : Matroid α) : Nonempty {B // M.IsBase B} := nonempty_subtype.2 M.exists_isBase /-- Typeclass for a matroid having finite ground set. Just a wrapper for `M.E.Finite`. -/ @[mk_iff] protected class Finite (M : Matroid α) : Prop where /-- The ground set is finite -/ (ground_finite : M.E.Finite) /-- Typeclass for a matroid having nonempty ground set. Just a wrapper for `M.E.Nonempty`. -/ protected class Nonempty (M : Matroid α) : Prop where /-- The ground set is nonempty -/ (ground_nonempty : M.E.Nonempty) theorem ground_nonempty (M : Matroid α) [M.Nonempty] : M.E.Nonempty := Nonempty.ground_nonempty theorem ground_nonempty_iff (M : Matroid α) : M.E.Nonempty ↔ M.Nonempty := ⟨fun h ↦ ⟨h⟩, fun ⟨h⟩ ↦ h⟩ lemma nonempty_type (M : Matroid α) [h : M.Nonempty] : Nonempty α := ⟨M.ground_nonempty.some⟩ theorem ground_finite (M : Matroid α) [M.Finite] : M.E.Finite := Finite.ground_finite theorem set_finite (M : Matroid α) [M.Finite] (X : Set α) (hX : X ⊆ M.E := by aesop) : X.Finite := M.ground_finite.subset hX instance finite_of_finite [Finite α] {M : Matroid α} : M.Finite := ⟨Set.toFinite _⟩ /-- A `RankFinite` matroid is one whose bases are finite -/ @[mk_iff] class RankFinite (M : Matroid α) : Prop where /-- There is a finite base -/ exists_finite_isBase : ∃ B, M.IsBase B ∧ B.Finite @[deprecated (since := "2025-02-09")] alias FiniteRk := RankFinite instance rankFinite_of_finite (M : Matroid α) [M.Finite] : RankFinite M := ⟨M.exists_isBase.imp (fun B hB ↦ ⟨hB, M.set_finite B (M.subset_ground _ hB)⟩)⟩ /-- An `RankInfinite` matroid is one whose bases are infinite. -/ @[mk_iff] class RankInfinite (M : Matroid α) : Prop where /-- There is an infinite base -/ exists_infinite_isBase : ∃ B, M.IsBase B ∧ B.Infinite @[deprecated (since := "2025-02-09")] alias InfiniteRk := RankInfinite /-- A `RankPos` matroid is one whose bases are nonempty. -/ @[mk_iff] class RankPos (M : Matroid α) : Prop where /-- The empty set isn't a base -/ empty_not_isBase : ¬M.IsBase ∅ @[deprecated (since := "2025-02-09")] alias RkPos := RankPos instance rankPos_nonempty {M : Matroid α} [M.RankPos] : M.Nonempty := by obtain ⟨B, hB⟩ := M.exists_isBase obtain rfl | ⟨e, heB⟩ := B.eq_empty_or_nonempty · exact False.elim <| RankPos.empty_not_isBase hB exact ⟨e, M.subset_ground B hB heB ⟩ section exchange namespace ExchangeProperty variable {IsBase : Set α → Prop} {B B' : Set α} /-- A family of sets with the exchange property is an antichain. -/ theorem antichain (exch : ExchangeProperty IsBase) (hB : IsBase B) (hB' : IsBase B') (h : B ⊆ B') : B = B' := h.antisymm (fun x hx ↦ by_contra (fun hxB ↦ let ⟨_, hy, _⟩ := exch B' B hB' hB x ⟨hx, hxB⟩; hy.2 <| h hy.1)) theorem encard_diff_le_aux {B₁ B₂ : Set α} (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase B₂) : (B₁ \ B₂).encard ≤ (B₂ \ B₁).encard := by obtain (he | hinf | ⟨e, he, hcard⟩) := (B₂ \ B₁).eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · rw [exch.antichain hB₂ hB₁ (diff_eq_empty.mp he)] · exact le_top.trans_eq hinf.symm obtain ⟨f, hf, hB'⟩ := exch B₂ B₁ hB₂ hB₁ e he have : encard (insert f (B₂ \ {e}) \ B₁) < encard (B₂ \ B₁) := by rw [insert_diff_of_mem _ hf.1, diff_diff_comm]; exact hcard have hencard := encard_diff_le_aux exch hB₁ hB' rw [insert_diff_of_mem _ hf.1, diff_diff_comm, ← union_singleton, ← diff_diff, diff_diff_right, inter_singleton_eq_empty.mpr he.2, union_empty] at hencard rw [← encard_diff_singleton_add_one he, ← encard_diff_singleton_add_one hf] exact add_le_add_right hencard 1 termination_by (B₂ \ B₁).encard variable {B₁ B₂ : Set α} /-- For any two sets `B₁`, `B₂` in a family with the exchange property, the differences `B₁ \ B₂` and `B₂ \ B₁` have the same `ℕ∞`-cardinality. -/ theorem encard_diff_eq (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := (encard_diff_le_aux exch hB₁ hB₂).antisymm (encard_diff_le_aux exch hB₂ hB₁) /-- Any two sets `B₁`, `B₂` in a family with the exchange property have the same `ℕ∞`-cardinality. -/ theorem encard_isBase_eq (exch : ExchangeProperty IsBase) (hB₁ : IsBase B₁) (hB₂ : IsBase B₂) : B₁.encard = B₂.encard := by rw [← encard_diff_add_encard_inter B₁ B₂, exch.encard_diff_eq hB₁ hB₂, inter_comm, encard_diff_add_encard_inter] end ExchangeProperty end exchange section aesop /-- The `aesop_mat` tactic attempts to prove a set is contained in the ground set of a matroid. It uses a `[Matroid]` ruleset, and is allowed to fail. -/ macro (name := aesop_mat) "aesop_mat" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := {terminal := true}) (rule_sets := [$(Lean.mkIdent `Matroid):ident])) /- We add a number of trivial lemmas (deliberately specialized to statements in terms of the ground set of a matroid) to the ruleset `Matroid` for `aesop`. -/ variable {X Y : Set α} {e : α} @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_right_subset_ground (hX : X ⊆ M.E) : X ∩ Y ⊆ M.E := inter_subset_left.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem inter_left_subset_ground (hX : X ⊆ M.E) : Y ∩ X ⊆ M.E := inter_subset_right.trans hX @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem diff_subset_ground (hX : X ⊆ M.E) : X \ Y ⊆ M.E := diff_subset.trans hX @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem ground_diff_subset_ground : M.E \ X ⊆ M.E := diff_subset_ground rfl.subset @[aesop unsafe 10% (rule_sets := [Matroid])] private theorem singleton_subset_ground (he : e ∈ M.E) : {e} ⊆ M.E := singleton_subset_iff.mpr he @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem subset_ground_of_subset (hXY : X ⊆ Y) (hY : Y ⊆ M.E) : X ⊆ M.E := hXY.trans hY @[aesop unsafe 5% (rule_sets := [Matroid])] private theorem mem_ground_of_mem_of_subset (hX : X ⊆ M.E) (heX : e ∈ X) : e ∈ M.E := hX heX @[aesop safe (rule_sets := [Matroid])] private theorem insert_subset_ground {e : α} {X : Set α} {M : Matroid α} (he : e ∈ M.E) (hX : X ⊆ M.E) : insert e X ⊆ M.E := insert_subset he hX @[aesop safe (rule_sets := [Matroid])] private theorem ground_subset_ground {M : Matroid α} : M.E ⊆ M.E := rfl.subset attribute [aesop safe (rule_sets := [Matroid])] empty_subset union_subset iUnion_subset end aesop section IsBase variable {B B₁ B₂ : Set α} @[aesop unsafe 10% (rule_sets := [Matroid])] theorem IsBase.subset_ground (hB : M.IsBase B) : B ⊆ M.E := M.subset_ground B hB theorem IsBase.exchange {e : α} (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hx : e ∈ B₁ \ B₂) : ∃ y ∈ B₂ \ B₁, M.IsBase (insert y (B₁ \ {e})) := M.isBase_exchange B₁ B₂ hB₁ hB₂ _ hx theorem IsBase.exchange_mem {e : α} (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hxB₁ : e ∈ B₁) (hxB₂ : e ∉ B₂) : ∃ y, (y ∈ B₂ ∧ y ∉ B₁) ∧ M.IsBase (insert y (B₁ \ {e})) := by simpa using hB₁.exchange hB₂ ⟨hxB₁, hxB₂⟩ theorem IsBase.eq_of_subset_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) (hB₁B₂ : B₁ ⊆ B₂) : B₁ = B₂ := M.isBase_exchange.antichain hB₁ hB₂ hB₁B₂ theorem IsBase.not_isBase_of_ssubset {X : Set α} (hB : M.IsBase B) (hX : X ⊂ B) : ¬ M.IsBase X := fun h ↦ hX.ne (h.eq_of_subset_isBase hB hX.subset) theorem IsBase.insert_not_isBase {e : α} (hB : M.IsBase B) (heB : e ∉ B) : ¬ M.IsBase (insert e B) := fun h ↦ h.not_isBase_of_ssubset (ssubset_insert heB) hB theorem IsBase.encard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).encard = (B₂ \ B₁).encard := M.isBase_exchange.encard_diff_eq hB₁ hB₂ theorem IsBase.ncard_diff_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).ncard = (B₂ \ B₁).ncard := by rw [ncard_def, hB₁.encard_diff_comm hB₂, ← ncard_def] theorem IsBase.encard_eq_encard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : B₁.encard = B₂.encard := by rw [M.isBase_exchange.encard_isBase_eq hB₁ hB₂] theorem IsBase.ncard_eq_ncard_of_isBase (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : B₁.ncard = B₂.ncard := by rw [ncard_def B₁, hB₁.encard_eq_encard_of_isBase hB₂, ← ncard_def] theorem IsBase.finite_of_finite {B' : Set α} (hB : M.IsBase B) (h : B.Finite) (hB' : M.IsBase B') : B'.Finite := (finite_iff_finite_of_encard_eq_encard (hB.encard_eq_encard_of_isBase hB')).mp h theorem IsBase.infinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) (hB₁ : M.IsBase B₁) : B₁.Infinite := by_contra (fun hB_inf ↦ (hB₁.finite_of_finite (not_infinite.mp hB_inf) hB).not_infinite h) theorem IsBase.finite [RankFinite M] (hB : M.IsBase B) : B.Finite := let ⟨_,hB₀⟩ := ‹RankFinite M›.exists_finite_isBase hB₀.1.finite_of_finite hB₀.2 hB theorem IsBase.infinite [RankInfinite M] (hB : M.IsBase B) : B.Infinite := let ⟨_,hB₀⟩ := ‹RankInfinite M›.exists_infinite_isBase hB₀.1.infinite_of_infinite hB₀.2 hB theorem empty_not_isBase [h : RankPos M] : ¬M.IsBase ∅ := h.empty_not_isBase theorem IsBase.nonempty [RankPos M] (hB : M.IsBase B) : B.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; exact M.empty_not_isBase hB theorem IsBase.rankPos_of_nonempty (hB : M.IsBase B) (h : B.Nonempty) : M.RankPos := by rw [rankPos_iff] intro he obtain rfl := he.eq_of_subset_isBase hB (empty_subset B) simp at h theorem IsBase.rankFinite_of_finite (hB : M.IsBase B) (hfin : B.Finite) : RankFinite M := ⟨⟨B, hB, hfin⟩⟩ theorem IsBase.rankInfinite_of_infinite (hB : M.IsBase B) (h : B.Infinite) : RankInfinite M := ⟨⟨B, hB, h⟩⟩ theorem not_rankFinite (M : Matroid α) [RankInfinite M] : ¬ RankFinite M := by intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite theorem not_rankInfinite (M : Matroid α) [RankFinite M] : ¬ RankInfinite M := by intro h; obtain ⟨B,hB⟩ := M.exists_isBase; exact hB.infinite hB.finite theorem rankFinite_or_rankInfinite (M : Matroid α) : RankFinite M ∨ RankInfinite M := let ⟨B, hB⟩ := M.exists_isBase B.finite_or_infinite.imp hB.rankFinite_of_finite hB.rankInfinite_of_infinite @[deprecated (since := "2025-03-27")] alias finite_or_rankInfinite := rankFinite_or_rankInfinite @[simp] theorem not_rankFinite_iff (M : Matroid α) : ¬ RankFinite M ↔ RankInfinite M := M.rankFinite_or_rankInfinite.elim (fun h ↦ iff_of_false (by simpa) M.not_rankInfinite) fun h ↦ iff_of_true M.not_rankFinite h @[simp] theorem not_rankInfinite_iff (M : Matroid α) : ¬ RankInfinite M ↔ RankFinite M := by rw [← not_rankFinite_iff, not_not] theorem IsBase.diff_finite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).Finite ↔ (B₂ \ B₁).Finite := finite_iff_finite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem IsBase.diff_infinite_comm (hB₁ : M.IsBase B₁) (hB₂ : M.IsBase B₂) : (B₁ \ B₂).Infinite ↔ (B₂ \ B₁).Infinite := infinite_iff_infinite_of_encard_eq_encard (hB₁.encard_diff_comm hB₂) theorem ext_isBase {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (h : ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B)) : M₁ = M₂ := by have h' : ∀ B, M₁.IsBase B ↔ M₂.IsBase B := fun B ↦ ⟨fun hB ↦ (h hB.subset_ground).1 hB, fun hB ↦ (h <| hB.subset_ground.trans_eq hE.symm).2 hB⟩ ext <;> simp [hE, M₁.indep_iff', M₂.indep_iff', h'] theorem ext_iff_isBase {M₁ M₂ : Matroid α} : M₁ = M₂ ↔ M₁.E = M₂.E ∧ ∀ ⦃B⦄, B ⊆ M₁.E → (M₁.IsBase B ↔ M₂.IsBase B) := ⟨fun h ↦ by simp [h], fun ⟨hE, h⟩ ↦ ext_isBase hE h⟩ theorem isBase_compl_iff_maximal_disjoint_isBase (hB : B ⊆ M.E := by aesop_mat) : M.IsBase (M.E \ B) ↔ Maximal (fun I ↦ I ⊆ M.E ∧ ∃ B, M.IsBase B ∧ Disjoint I B) B := by simp_rw [maximal_iff, and_iff_right hB, and_imp, forall_exists_index] refine ⟨fun h ↦ ⟨⟨_, h, disjoint_sdiff_right⟩, fun I hI B' ⟨hB', hIB'⟩ hBI ↦ hBI.antisymm ?_⟩, fun ⟨⟨B', hB', hBB'⟩,h⟩ ↦ ?_⟩ · rw [hB'.eq_of_subset_isBase h, ← subset_compl_iff_disjoint_right, diff_eq, compl_inter, compl_compl] at hIB' · exact fun e he ↦ (hIB' he).elim (fun h' ↦ (h' (hI he)).elim) id rw [subset_diff, and_iff_right hB'.subset_ground, disjoint_comm] exact disjoint_of_subset_left hBI hIB' rw [h diff_subset B' ⟨hB', disjoint_sdiff_left⟩] · simpa [hB'.subset_ground] simp [subset_diff, hB, hBB'] end IsBase section dep_indep /-- A subset of `M.E` is `Dep`endent if it is not `Indep`endent . -/ def Dep (M : Matroid α) (D : Set α) : Prop := ¬M.Indep D ∧ D ⊆ M.E variable {B B' I J D X : Set α} {e f : α} theorem indep_iff : M.Indep I ↔ ∃ B, M.IsBase B ∧ I ⊆ B := M.indep_iff' (I := I) theorem setOf_indep_eq (M : Matroid α) : {I | M.Indep I} = lowerClosure ({B | M.IsBase B}) := by simp_rw [indep_iff, lowerClosure, LowerSet.coe_mk, mem_setOf, le_eq_subset] theorem Indep.exists_isBase_superset (hI : M.Indep I) : ∃ B, M.IsBase B ∧ I ⊆ B := indep_iff.1 hI theorem dep_iff : M.Dep D ↔ ¬M.Indep D ∧ D ⊆ M.E := Iff.rfl theorem setOf_dep_eq (M : Matroid α) : {D | M.Dep D} = {I | M.Indep I}ᶜ ∩ Iic M.E := rfl @[aesop unsafe 30% (rule_sets := [Matroid])] theorem Indep.subset_ground (hI : M.Indep I) : I ⊆ M.E := by obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact hIB.trans hB.subset_ground @[aesop unsafe 20% (rule_sets := [Matroid])] theorem Dep.subset_ground (hD : M.Dep D) : D ⊆ M.E := hD.2 theorem indep_or_dep (hX : X ⊆ M.E := by aesop_mat) : M.Indep X ∨ M.Dep X := by rw [Dep, and_iff_left hX] apply em theorem Indep.not_dep (hI : M.Indep I) : ¬ M.Dep I := fun h ↦ h.1 hI theorem Dep.not_indep (hD : M.Dep D) : ¬ M.Indep D := hD.1 theorem dep_of_not_indep (hD : ¬ M.Indep D) (hDE : D ⊆ M.E := by aesop_mat) : M.Dep D := ⟨hD, hDE⟩ theorem indep_of_not_dep (hI : ¬ M.Dep I) (hIE : I ⊆ M.E := by aesop_mat) : M.Indep I := by_contra (fun h ↦ hI ⟨h, hIE⟩) @[simp] theorem not_dep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Dep X ↔ M.Indep X := by rw [Dep, and_iff_left hX, not_not] @[simp] theorem not_indep_iff (hX : X ⊆ M.E := by aesop_mat) : ¬ M.Indep X ↔ M.Dep X := by rw [Dep, and_iff_left hX] theorem indep_iff_not_dep : M.Indep I ↔ ¬M.Dep I ∧ I ⊆ M.E := by rw [dep_iff, not_and, not_imp_not] exact ⟨fun h ↦ ⟨fun _ ↦ h, h.subset_ground⟩, fun h ↦ h.1 h.2⟩ theorem Indep.subset (hJ : M.Indep J) (hIJ : I ⊆ J) : M.Indep I := by obtain ⟨B, hB, hJB⟩ := hJ.exists_isBase_superset exact indep_iff.2 ⟨B, hB, hIJ.trans hJB⟩ theorem Dep.superset (hD : M.Dep D) (hDX : D ⊆ X) (hXE : X ⊆ M.E := by aesop_mat) : M.Dep X := dep_of_not_indep (fun hI ↦ (hI.subset hDX).not_dep hD) theorem IsBase.indep (hB : M.IsBase B) : M.Indep B := indep_iff.2 ⟨B, hB, subset_rfl⟩ @[simp] theorem empty_indep (M : Matroid α) : M.Indep ∅ := Exists.elim M.exists_isBase (fun _ hB ↦ hB.indep.subset (empty_subset _)) theorem Dep.nonempty (hD : M.Dep D) : D.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; exact hD.not_indep M.empty_indep theorem Indep.finite [RankFinite M] (hI : M.Indep I) : I.Finite := let ⟨_, hB, hIB⟩ := hI.exists_isBase_superset hB.finite.subset hIB theorem Indep.rankPos_of_nonempty (hI : M.Indep I) (hne : I.Nonempty) : M.RankPos := by obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact hB.rankPos_of_nonempty (hne.mono hIB) theorem Indep.inter_right (hI : M.Indep I) (X : Set α) : M.Indep (I ∩ X) := hI.subset inter_subset_left theorem Indep.inter_left (hI : M.Indep I) (X : Set α) : M.Indep (X ∩ I) := hI.subset inter_subset_right theorem Indep.diff (hI : M.Indep I) (X : Set α) : M.Indep (I \ X) := hI.subset diff_subset theorem IsBase.eq_of_subset_indep (hB : M.IsBase B) (hI : M.Indep I) (hBI : B ⊆ I) : B = I := let ⟨B', hB', hB'I⟩ := hI.exists_isBase_superset hBI.antisymm (by rwa [hB.eq_of_subset_isBase hB' (hBI.trans hB'I)]) theorem isBase_iff_maximal_indep : M.IsBase B ↔ Maximal M.Indep B := by rw [maximal_subset_iff] refine ⟨fun h ↦ ⟨h.indep, fun _ ↦ h.eq_of_subset_indep⟩, fun ⟨h, h'⟩ ↦ ?_⟩ obtain ⟨B', hB', hBB'⟩ := h.exists_isBase_superset rwa [h' hB'.indep hBB'] theorem Indep.isBase_of_maximal (hI : M.Indep I) (h : ∀ ⦃J⦄, M.Indep J → I ⊆ J → I = J) : M.IsBase I := by rwa [isBase_iff_maximal_indep, maximal_subset_iff, and_iff_right hI] theorem IsBase.dep_of_ssubset (hB : M.IsBase B) (h : B ⊂ X) (hX : X ⊆ M.E := by aesop_mat) : M.Dep X := ⟨fun hX ↦ h.ne (hB.eq_of_subset_indep hX h.subset), hX⟩ theorem IsBase.dep_of_insert (hB : M.IsBase B) (heB : e ∉ B) (he : e ∈ M.E := by aesop_mat) : M.Dep (insert e B) := hB.dep_of_ssubset (ssubset_insert heB) (insert_subset he hB.subset_ground) theorem IsBase.mem_of_insert_indep (hB : M.IsBase B) (heB : M.Indep (insert e B)) : e ∈ B := by_contra fun he ↦ (hB.dep_of_insert he (heB.subset_ground (mem_insert _ _))).not_indep heB /-- If the difference of two IsBases is a singleton, then they differ by an insertion/removal -/ theorem IsBase.eq_exchange_of_diff_eq_singleton (hB : M.IsBase B) (hB' : M.IsBase B') (h : B \ B' = {e}) : ∃ f ∈ B' \ B, B' = (insert f B) \ {e} := by obtain ⟨f, hf, hb⟩ := hB.exchange hB' (h.symm.subset (mem_singleton e)) have hne : f ≠ e := by rintro rfl; exact hf.2 (h.symm.subset (mem_singleton f)).1 rw [insert_diff_singleton_comm hne] at hb refine ⟨f, hf, (hb.eq_of_subset_isBase hB' ?_).symm⟩ rw [diff_subset_iff, insert_subset_iff, union_comm, ← diff_subset_iff, h, and_iff_left rfl.subset] exact Or.inl hf.1 theorem IsBase.exchange_isBase_of_indep (hB : M.IsBase B) (hf : f ∉ B) (hI : M.Indep (insert f (B \ {e}))) : M.IsBase (insert f (B \ {e})) := by obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_superset have hcard := hB'.encard_diff_comm hB rw [insert_subset_iff, ← diff_eq_empty, diff_diff_comm, diff_eq_empty, subset_singleton_iff_eq] at hIB' obtain ⟨hfB, (h | h)⟩ := hIB' · rw [h, encard_empty, encard_eq_zero, eq_empty_iff_forall_notMem] at hcard exact (hcard f ⟨hfB, hf⟩).elim rw [h, encard_singleton, encard_eq_one] at hcard obtain ⟨x, hx⟩ := hcard obtain (rfl : f = x) := hx.subset ⟨hfB, hf⟩ simp_rw [← h, ← singleton_union, ← hx, sdiff_sdiff_right_self, inf_eq_inter, inter_comm B, diff_union_inter] exact hB' theorem IsBase.exchange_isBase_of_indep' (hB : M.IsBase B) (he : e ∈ B) (hf : f ∉ B) (hI : M.Indep (insert f B \ {e})) : M.IsBase (insert f B \ {e}) := by have hfe : f ≠ e := ne_of_mem_of_not_mem he hf |>.symm rw [← insert_diff_singleton_comm hfe] at * exact hB.exchange_isBase_of_indep hf hI lemma insert_isBase_of_insert_indep {M : Matroid α} {I : Set α} {e f : α} (he : e ∉ I) (hf : f ∉ I) (heI : M.IsBase (insert e I)) (hfI : M.Indep (insert f I)) : M.IsBase (insert f I) := by obtain rfl | hef := eq_or_ne e f · assumption simpa [diff_singleton_eq_self he, hfI] using heI.exchange_isBase_of_indep (e := e) (f := f) (by simp [hef.symm, hf]) theorem IsBase.insert_dep (hB : M.IsBase B) (h : e ∈ M.E \ B) : M.Dep (insert e B) := by rw [← not_indep_iff (insert_subset h.1 hB.subset_ground)] exact h.2 ∘ (fun hi ↦ insert_eq_self.mp (hB.eq_of_subset_indep hi (subset_insert e B)).symm) theorem Indep.exists_insert_of_not_isBase (hI : M.Indep I) (hI' : ¬M.IsBase I) (hB : M.IsBase B) : ∃ e ∈ B \ I, M.Indep (insert e I) := by obtain ⟨B', hB', hIB'⟩ := hI.exists_isBase_superset obtain ⟨x, hxB', hx⟩ := exists_of_ssubset (hIB'.ssubset_of_ne (by (rintro rfl; exact hI' hB'))) by_cases hxB : x ∈ B · exact ⟨x, ⟨hxB, hx⟩, hB'.indep.subset (insert_subset hxB' hIB')⟩ obtain ⟨e,he, hBase⟩ := hB'.exchange hB ⟨hxB',hxB⟩ exact ⟨e, ⟨he.1, notMem_subset hIB' he.2⟩, indep_iff.2 ⟨_, hBase, insert_subset_insert (subset_diff_singleton hIB' hx)⟩⟩ /-- This is the same as `Indep.exists_insert_of_not_isBase`, but phrased so that it is defeq to the augmentation axiom for independent sets. -/ theorem Indep.exists_insert_of_not_maximal (M : Matroid α) ⦃I B : Set α⦄ (hI : M.Indep I) (hInotmax : ¬ Maximal M.Indep I) (hB : Maximal M.Indep B) : ∃ x ∈ B \ I, M.Indep (insert x I) := by simp only [maximal_subset_iff, hI, not_and, not_forall, exists_prop, true_imp_iff] at hB hInotmax refine hI.exists_insert_of_not_isBase (fun hIb ↦ ?_) ?_ · obtain ⟨I', hII', hI', hne⟩ := hInotmax exact hne <| hIb.eq_of_subset_indep hII' hI' exact hB.1.isBase_of_maximal fun J hJ hBJ ↦ hB.2 hJ hBJ theorem Indep.isBase_of_forall_insert (hB : M.Indep B) (hBmax : ∀ e ∈ M.E \ B, ¬ M.Indep (insert e B)) : M.IsBase B := by refine by_contra fun hnb ↦ ?_ obtain ⟨B', hB'⟩ := M.exists_isBase obtain ⟨e, he, h⟩ := hB.exists_insert_of_not_isBase hnb hB' exact hBmax e ⟨hB'.subset_ground he.1, he.2⟩ h theorem ground_indep_iff_isBase : M.Indep M.E ↔ M.IsBase M.E := ⟨fun h ↦ h.isBase_of_maximal (fun _ hJ hEJ ↦ hEJ.antisymm hJ.subset_ground), IsBase.indep⟩ theorem IsBase.exists_insert_of_ssubset (hB : M.IsBase B) (hIB : I ⊂ B) (hB' : M.IsBase B') : ∃ e ∈ B' \ I, M.Indep (insert e I) := (hB.indep.subset hIB.subset).exists_insert_of_not_isBase (fun hI ↦ hIB.ne (hI.eq_of_subset_isBase hB hIB.subset)) hB' @[ext] theorem ext_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (h : ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I)) : M₁ = M₂ := have h' : M₁.Indep = M₂.Indep := by ext I by_cases hI : I ⊆ M₁.E · rwa [h] exact iff_of_false (fun hi ↦ hI hi.subset_ground) (fun hi ↦ hI (hi.subset_ground.trans_eq hE.symm)) ext_isBase hE (fun B _ ↦ by simp_rw [isBase_iff_maximal_indep, h']) theorem ext_iff_indep {M₁ M₂ : Matroid α} : M₁ = M₂ ↔ (M₁.E = M₂.E) ∧ ∀ ⦃I⦄, I ⊆ M₁.E → (M₁.Indep I ↔ M₂.Indep I) := ⟨fun h ↦ by (subst h; simp), fun h ↦ ext_indep h.1 h.2⟩ /-- If every base of `M₁` is independent in `M₂` and vice versa, then `M₁ = M₂`. -/ lemma ext_isBase_indep {M₁ M₂ : Matroid α} (hE : M₁.E = M₂.E) (hM₁ : ∀ ⦃B⦄, M₁.IsBase B → M₂.Indep B) (hM₂ : ∀ ⦃B⦄, M₂.IsBase B → M₁.Indep B) : M₁ = M₂ := by refine ext_indep hE fun I hIE ↦ ⟨fun hI ↦ ?_, fun hI ↦ ?_⟩ · obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact (hM₁ hB).subset hIB obtain ⟨B, hB, hIB⟩ := hI.exists_isBase_superset exact (hM₂ hB).subset hIB /-- A `Finitary` matroid is one where a set is independent if and only if it all its finite subsets are independent, or equivalently a matroid whose circuits are finite. -/ @[mk_iff] class Finitary (M : Matroid α) : Prop where /-- `I` is independent if all its finite subsets are independent. -/ indep_of_forall_finite : ∀ I, (∀ J, J ⊆ I → J.Finite → M.Indep J) → M.Indep I theorem indep_of_forall_finite_subset_indep {M : Matroid α} [Finitary M] (I : Set α) (h : ∀ J, J ⊆ I → J.Finite → M.Indep J) : M.Indep I := Finitary.indep_of_forall_finite I h theorem indep_iff_forall_finite_subset_indep {M : Matroid α} [Finitary M] : M.Indep I ↔ ∀ J, J ⊆ I → J.Finite → M.Indep J := ⟨fun h _ hJI _ ↦ h.subset hJI, Finitary.indep_of_forall_finite I⟩ instance finitary_of_rankFinite {M : Matroid α} [RankFinite M] : Finitary M where indep_of_forall_finite I hI := by refine I.finite_or_infinite.elim (hI _ Subset.rfl) (fun h ↦ False.elim ?_) obtain ⟨B, hB⟩ := M.exists_isBase obtain ⟨I₀, hI₀I, hI₀fin, hI₀card⟩ := h.exists_subset_ncard_eq (B.ncard + 1) obtain ⟨B', hB', hI₀B'⟩ := (hI _ hI₀I hI₀fin).exists_isBase_superset have hle := ncard_le_ncard hI₀B' hB'.finite rw [hI₀card, hB'.ncard_eq_ncard_of_isBase hB, Nat.add_one_le_iff] at hle exact hle.ne rfl /-- Matroids obey the maximality axiom -/ theorem existsMaximalSubsetProperty_indep (M : Matroid α) : ∀ X, X ⊆ M.E → ExistsMaximalSubsetProperty M.Indep X := M.maximality end dep_indep section copy /-- create a copy of `M : Matroid α` with independence and base predicates and ground set defeq to supplied arguments that are provably equal to those of `M`. -/ @[simps] def copy (M : Matroid α) (E : Set α) (IsBase Indep : Set α → Prop) (hE : E = M.E) (hB : ∀ B, IsBase B ↔ M.IsBase B) (hI : ∀ I, Indep I ↔ M.Indep I) : Matroid α where E := E IsBase := IsBase Indep := Indep indep_iff' _ := by simp_rw [hI, hB, M.indep_iff] exists_isBase := by simp_rw [hB] exact M.exists_isBase isBase_exchange := by simp_rw [show IsBase = M.IsBase from funext (by simp [hB])] exact M.isBase_exchange maximality := by simp_rw [hE, show Indep = M.Indep from funext (by simp [hI])] exact M.maximality subset_ground := by simp_rw [hE, hB] exact M.subset_ground /-- create a copy of `M : Matroid α` with an independence predicate and ground set defeq to supplied arguments that are provably equal to those of `M`. -/ @[simps!] def copyIndep (M : Matroid α) (E : Set α) (Indep : Set α → Prop) (hE : E = M.E) (h : ∀ I, Indep I ↔ M.Indep I) : Matroid α := M.copy E M.IsBase Indep hE (fun _ ↦ Iff.rfl) h /-- create a copy of `M : Matroid α` with a base predicate and ground set defeq to supplied arguments that are provably equal to those of `M`. -/ @[simps!] def copyBase (M : Matroid α) (E : Set α) (IsBase : Set α → Prop) (hE : E = M.E) (h : ∀ B, IsBase B ↔ M.IsBase B) : Matroid α := M.copy E IsBase M.Indep hE h (fun _ ↦ Iff.rfl) end copy section IsBasis /-- A Basis for a set `X ⊆ M.E` is a maximal independent subset of `X` (Often in the literature, the word 'Basis' is used to refer to what we call a 'Base'). -/ def IsBasis (M : Matroid α) (I X : Set α) : Prop := Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I ∧ X ⊆ M.E @[deprecated (since := "2025-02-14")] alias Basis := IsBasis /-- `Matroid.IsBasis' I X` is the same as `Matroid.IsBasis I X`, without the requirement that `X ⊆ M.E`. This is convenient for some API building, especially when working with rank and closure. -/ def IsBasis' (M : Matroid α) (I X : Set α) : Prop := Maximal (fun A ↦ M.Indep A ∧ A ⊆ X) I @[deprecated (since := "2025-02-14")] alias Basis' := IsBasis' variable {B I J X Y : Set α} {e : α} theorem IsBasis'.indep (hI : M.IsBasis' I X) : M.Indep I := hI.1.1 theorem IsBasis.indep (hI : M.IsBasis I X) : M.Indep I := hI.1.1.1 theorem IsBasis.subset (hI : M.IsBasis I X) : I ⊆ X := hI.1.1.2 theorem IsBasis.isBasis' (hI : M.IsBasis I X) : M.IsBasis' I X := hI.1 theorem IsBasis'.isBasis (hI : M.IsBasis' I X) (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X := ⟨hI, hX⟩ theorem IsBasis'.subset (hI : M.IsBasis' I X) : I ⊆ X := hI.1.2 @[aesop unsafe 15% (rule_sets := [Matroid])] theorem IsBasis.subset_ground (hI : M.IsBasis I X) : X ⊆ M.E := hI.2 theorem IsBasis.isBasis_inter_ground (hI : M.IsBasis I X) : M.IsBasis I (X ∩ M.E) := by convert hI rw [inter_eq_self_of_subset_left hI.subset_ground] @[aesop unsafe 15% (rule_sets := [Matroid])] theorem IsBasis.left_subset_ground (hI : M.IsBasis I X) : I ⊆ M.E := hI.indep.subset_ground theorem IsBasis.eq_of_subset_indep (hI : M.IsBasis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) (hJX : J ⊆ X) : I = J := hIJ.antisymm (hI.1.2 ⟨hJ, hJX⟩ hIJ) theorem IsBasis.Finite (hI : M.IsBasis I X) [RankFinite M] : I.Finite := hI.indep.finite theorem isBasis_iff' : M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → I = J) ∧ X ⊆ M.E := by rw [IsBasis, maximal_subset_iff] tauto theorem isBasis_iff (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X ↔ (M.Indep I ∧ I ⊆ X ∧ ∀ J, M.Indep J → I ⊆ J → J ⊆ X → I = J) := by rw [isBasis_iff', and_iff_left hX] theorem isBasis'_iff_isBasis_inter_ground : M.IsBasis' I X ↔ M.IsBasis I (X ∩ M.E) := by rw [IsBasis', IsBasis, and_iff_left inter_subset_right, maximal_iff_maximal_of_imp_of_forall] · exact fun I hI ↦ ⟨hI.1, hI.2.trans inter_subset_left⟩ exact fun I hI ↦ ⟨I, rfl.le, hI.1, subset_inter hI.2 hI.1.subset_ground⟩ theorem isBasis'_iff_isBasis (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis' I X ↔ M.IsBasis I X := by rw [isBasis'_iff_isBasis_inter_ground, inter_eq_self_of_subset_left hX] theorem isBasis_iff_isBasis'_subset_ground : M.IsBasis I X ↔ M.IsBasis' I X ∧ X ⊆ M.E := ⟨fun h ↦ ⟨h.isBasis', h.subset_ground⟩, fun h ↦ (isBasis'_iff_isBasis h.2).mp h.1⟩ theorem IsBasis'.isBasis_inter_ground (hIX : M.IsBasis' I X) : M.IsBasis I (X ∩ M.E) := isBasis'_iff_isBasis_inter_ground.mp hIX theorem IsBasis'.eq_of_subset_indep (hI : M.IsBasis' I X) (hJ : M.Indep J) (hIJ : I ⊆ J) (hJX : J ⊆ X) : I = J := hIJ.antisymm (hI.2 ⟨hJ, hJX⟩ hIJ) theorem IsBasis'.insert_not_indep (hI : M.IsBasis' I X) (he : e ∈ X \ I) : ¬ M.Indep (insert e I) := fun hi ↦ he.2 <| insert_eq_self.1 <| Eq.symm <| hI.eq_of_subset_indep hi (subset_insert _ _) (insert_subset he.1 hI.subset) theorem isBasis_iff_maximal (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X ↔ Maximal (fun I ↦ M.Indep I ∧ I ⊆ X) I := by rw [IsBasis, and_iff_left hX] theorem Indep.isBasis_of_maximal_subset (hI : M.Indep I) (hIX : I ⊆ X) (hmax : ∀ ⦃J⦄, M.Indep J → I ⊆ J → J ⊆ X → J ⊆ I) (hX : X ⊆ M.E := by aesop_mat) : M.IsBasis I X := by rw [isBasis_iff (by aesop_mat : X ⊆ M.E), and_iff_right hI, and_iff_right hIX] exact fun J hJ hIJ hJX ↦ hIJ.antisymm (hmax hJ hIJ hJX) theorem IsBasis.isBasis_subset (hI : M.IsBasis I X) (hIY : I ⊆ Y) (hYX : Y ⊆ X) : M.IsBasis I Y := by rw [isBasis_iff (hYX.trans hI.subset_ground), and_iff_right hI.indep, and_iff_right hIY] exact fun J hJ hIJ hJY ↦ hI.eq_of_subset_indep hJ hIJ (hJY.trans hYX) @[simp] theorem isBasis_self_iff_indep : M.IsBasis I I ↔ M.Indep I := by rw [isBasis_iff', and_iff_right rfl.subset, and_assoc, and_iff_left_iff_imp] exact fun hi ↦ ⟨fun _ _ ↦ subset_antisymm, hi.subset_ground⟩ theorem Indep.isBasis_self (h : M.Indep I) : M.IsBasis I I := isBasis_self_iff_indep.mpr h @[simp] theorem isBasis_empty_iff (M : Matroid α) : M.IsBasis I ∅ ↔ I = ∅ := ⟨fun h ↦ subset_empty_iff.mp h.subset, fun h ↦ by (rw [h]; exact M.empty_indep.isBasis_self)⟩ theorem IsBasis.dep_of_ssubset (hI : M.IsBasis I X) (hIY : I ⊂ Y) (hYX : Y ⊆ X) : M.Dep Y := by have : X ⊆ M.E := hI.subset_ground rw [← not_indep_iff] exact fun hY ↦ hIY.ne (hI.eq_of_subset_indep hY hIY.subset hYX) theorem IsBasis.insert_dep (hI : M.IsBasis I X) (he : e ∈ X \ I) : M.Dep (insert e I) := hI.dep_of_ssubset (ssubset_insert he.2) (insert_subset he.1 hI.subset) theorem IsBasis.mem_of_insert_indep (hI : M.IsBasis I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) : e ∈ I := by_contra (fun heI ↦ (hI.insert_dep ⟨he, heI⟩).not_indep hIe) theorem IsBasis'.mem_of_insert_indep (hI : M.IsBasis' I X) (he : e ∈ X) (hIe : M.Indep (insert e I)) : e ∈ I := hI.isBasis_inter_ground.mem_of_insert_indep ⟨he, hIe.subset_ground (mem_insert _ _)⟩ hIe theorem IsBasis.not_isBasis_of_ssubset (hI : M.IsBasis I X) (hJI : J ⊂ I) : ¬ M.IsBasis J X := fun h ↦ hJI.ne (h.eq_of_subset_indep hI.indep hJI.subset hI.subset) theorem Indep.subset_isBasis_of_subset (hI : M.Indep I) (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) : ∃ J, M.IsBasis J X ∧ I ⊆ J := by obtain ⟨J, hJ, hJmax⟩ := M.maximality X hX I hI hIX exact ⟨J, ⟨hJmax, hX⟩, hJ⟩ theorem Indep.subset_isBasis'_of_subset (hI : M.Indep I) (hIX : I ⊆ X) : ∃ J, M.IsBasis' J X ∧ I ⊆ J := by simp_rw [isBasis'_iff_isBasis_inter_ground] exact hI.subset_isBasis_of_subset (subset_inter hIX hI.subset_ground) theorem exists_isBasis (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) : ∃ I, M.IsBasis I X := let ⟨_, hI, _⟩ := M.empty_indep.subset_isBasis_of_subset (empty_subset X) ⟨_, hI⟩ theorem exists_isBasis' (M : Matroid α) (X : Set α) : ∃ I, M.IsBasis' I X := let ⟨_, hI, _⟩ := M.empty_indep.subset_isBasis'_of_subset (empty_subset X) ⟨_, hI⟩ theorem exists_isBasis_subset_isBasis (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) : ∃ I J, M.IsBasis I X ∧ M.IsBasis J Y ∧ I ⊆ J := by obtain ⟨I, hI⟩ := M.exists_isBasis X (hXY.trans hY) obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_isBasis_of_subset (hI.subset.trans hXY) exact ⟨_, _, hI, hJ, hIJ⟩ theorem IsBasis.exists_isBasis_inter_eq_of_superset (hI : M.IsBasis I X) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) : ∃ J, M.IsBasis J Y ∧ J ∩ X = I := by obtain ⟨J, hJ, hIJ⟩ := hI.indep.subset_isBasis_of_subset (hI.subset.trans hXY) refine ⟨J, hJ, subset_antisymm ?_ (subset_inter hIJ hI.subset)⟩ exact fun e he ↦ hI.mem_of_insert_indep he.2 (hJ.indep.subset (insert_subset he.1 hIJ)) theorem exists_isBasis_union_inter_isBasis (M : Matroid α) (X Y : Set α) (hX : X ⊆ M.E := by aesop_mat) (hY : Y ⊆ M.E := by aesop_mat) : ∃ I, M.IsBasis I (X ∪ Y) ∧ M.IsBasis (I ∩ Y) Y := let ⟨J, hJ⟩ := M.exists_isBasis Y (hJ.exists_isBasis_inter_eq_of_superset subset_union_right).imp (fun I hI ↦ ⟨hI.1, by rwa [hI.2]⟩) theorem Indep.eq_of_isBasis (hI : M.Indep I) (hJ : M.IsBasis J I) : J = I := hJ.eq_of_subset_indep hI hJ.subset rfl.subset theorem IsBasis.exists_isBase (hI : M.IsBasis I X) : ∃ B, M.IsBase B ∧ I = B ∩ X := let ⟨B,hB, hIB⟩ := hI.indep.exists_isBase_superset ⟨B, hB, subset_antisymm (subset_inter hIB hI.subset) (by rw [hI.eq_of_subset_indep (hB.indep.inter_right X) (subset_inter hIB hI.subset) inter_subset_right])⟩ @[simp] theorem isBasis_ground_iff : M.IsBasis B M.E ↔ M.IsBase B := by rw [IsBasis, and_iff_left rfl.subset, isBase_iff_maximal_indep, maximal_and_iff_right_of_imp (fun _ h ↦ h.subset_ground), and_iff_left_of_imp (fun h ↦ h.1.subset_ground)] theorem IsBase.isBasis_ground (hB : M.IsBase B) : M.IsBasis B M.E := isBasis_ground_iff.mpr hB theorem Indep.isBasis_iff_forall_insert_dep (hI : M.Indep I) (hIX : I ⊆ X) : M.IsBasis I X ↔ ∀ e ∈ X \ I, M.Dep (insert e I) := by rw [IsBasis, maximal_iff_forall_insert (fun I J hI hIJ ↦ ⟨hI.1.subset hIJ, hIJ.trans hI.2⟩)] simp only [hI, hIX, and_self, insert_subset_iff, and_true, not_and, true_and, mem_diff, and_imp, Dep, hI.subset_ground] exact ⟨fun h e heX heI ↦ ⟨fun hi ↦ h.1 e heI hi heX, h.2 heX⟩, fun h ↦ ⟨fun e heI hi heX ↦ (h e heX heI).1 hi, fun e heX ↦ (em (e ∈ I)).elim (fun h ↦ hI.subset_ground h) fun heI ↦ (h _ heX heI).2 ⟩⟩ theorem Indep.isBasis_of_forall_insert (hI : M.Indep I) (hIX : I ⊆ X) (he : ∀ e ∈ X \ I, M.Dep (insert e I)) : M.IsBasis I X := (hI.isBasis_iff_forall_insert_dep hIX).mpr he theorem Indep.isBasis_insert_iff (hI : M.Indep I) : M.IsBasis I (insert e I) ↔ M.Dep (insert e I) ∨ e ∈ I := by simp_rw [hI.isBasis_iff_forall_insert_dep (subset_insert _ _), dep_iff, insert_subset_iff, and_iff_left hI.subset_ground, mem_diff, mem_insert_iff, or_and_right, and_not_self, or_false, and_imp, forall_eq] tauto theorem IsBasis.iUnion_isBasis_iUnion {ι : Type _} (X I : ι → Set α) (hI : ∀ i, M.IsBasis (I i) (X i)) (h_ind : M.Indep (⋃ i, I i)) : M.IsBasis (⋃ i, I i) (⋃ i, X i) := by refine h_ind.isBasis_of_forall_insert (iUnion_subset (fun i ↦ (hI i).subset.trans (subset_iUnion _ _))) ?_ rintro e ⟨⟨_, ⟨⟨i, hi, rfl⟩, (hes : e ∈ X i)⟩⟩, he'⟩ rw [mem_iUnion, not_exists] at he' refine ((hI i).insert_dep ⟨hes, he' _⟩).superset (insert_subset_insert (subset_iUnion _ _)) ?_ rw [insert_subset_iff, iUnion_subset_iff, and_iff_left (fun i ↦ (hI i).indep.subset_ground)] exact (hI i).subset_ground hes theorem IsBasis.isBasis_iUnion {ι : Type _} [Nonempty ι] (X : ι → Set α) (hI : ∀ i, M.IsBasis I (X i)) : M.IsBasis I (⋃ i, X i) := by convert IsBasis.iUnion_isBasis_iUnion X (fun _ ↦ I) (fun i ↦ hI i) _ <;> rw [iUnion_const] exact (hI (Classical.arbitrary ι)).indep theorem IsBasis.isBasis_sUnion {Xs : Set (Set α)} (hne : Xs.Nonempty) (h : ∀ X ∈ Xs, M.IsBasis I X) : M.IsBasis I (⋃₀ Xs) := by rw [sUnion_eq_iUnion] have := Iff.mpr nonempty_coe_sort hne exact IsBasis.isBasis_iUnion _ fun X ↦ h X X.prop theorem Indep.isBasis_setOf_insert_isBasis (hI : M.Indep I) : M.IsBasis I {x | M.IsBasis I (insert x I)} := by refine hI.isBasis_of_forall_insert (fun e he ↦ (?_ : M.IsBasis _ _)) (fun e he ↦ ⟨fun hu ↦ he.2 ?_, he.1.subset_ground⟩) · rw [insert_eq_of_mem he]; exact hI.isBasis_self simpa using (hu.eq_of_isBasis he.1).symm theorem IsBasis.union_isBasis_union (hIX : M.IsBasis I X) (hJY : M.IsBasis J Y) (h : M.Indep (I ∪ J)) : M.IsBasis (I ∪ J) (X ∪ Y) := by rw [union_eq_iUnion, union_eq_iUnion] refine IsBasis.iUnion_isBasis_iUnion _ _ ?_ ?_ · simp only [Bool.forall_bool, cond_false, cond_true]; exact ⟨hJY, hIX⟩ rwa [← union_eq_iUnion] theorem IsBasis.isBasis_union (hIX : M.IsBasis I X) (hIY : M.IsBasis I Y) : M.IsBasis I (X ∪ Y) := by convert hIX.union_isBasis_union hIY _ <;> rw [union_self]; exact hIX.indep theorem IsBasis.isBasis_union_of_subset (hI : M.IsBasis I X) (hJ : M.Indep J) (hIJ : I ⊆ J) : M.IsBasis J (J ∪ X) := by convert hJ.isBasis_self.union_isBasis_union hI _ <;> rw [union_eq_self_of_subset_right hIJ] assumption theorem IsBasis.insert_isBasis_insert (hI : M.IsBasis I X) (h : M.Indep (insert e I)) : M.IsBasis (insert e I) (insert e X) := by simp_rw [← union_singleton] at * exact hI.union_isBasis_union (h.subset subset_union_right).isBasis_self h theorem IsBase.isBase_of_isBasis_superset (hB : M.IsBase B) (hBX : B ⊆ X) (hIX : M.IsBasis I X) : M.IsBase I := by by_contra h obtain ⟨e,heBI,he⟩ := hIX.indep.exists_insert_of_not_isBase h hB exact heBI.2 (hIX.mem_of_insert_indep (hBX heBI.1) he) theorem Indep.exists_isBase_subset_union_isBase (hI : M.Indep I) (hB : M.IsBase B) : ∃ B', M.IsBase B' ∧ I ⊆ B' ∧ B' ⊆ I ∪ B := by obtain ⟨B', hB', hIB'⟩ := hI.subset_isBasis_of_subset <| subset_union_left (t := B) exact ⟨B', hB.isBase_of_isBasis_superset subset_union_right hB', hIB', hB'.subset⟩ theorem IsBasis.inter_eq_of_subset_indep (hIX : M.IsBasis I X) (hIJ : I ⊆ J) (hJ : M.Indep J) : J ∩ X = I := (subset_inter hIJ hIX.subset).antisymm' (fun _ he ↦ hIX.mem_of_insert_indep he.2 (hJ.subset (insert_subset he.1 hIJ))) theorem IsBasis'.inter_eq_of_subset_indep (hI : M.IsBasis' I X) (hIJ : I ⊆ J) (hJ : M.Indep J) : J ∩ X = I := by rw [← hI.isBasis_inter_ground.inter_eq_of_subset_indep hIJ hJ, inter_comm X, ← inter_assoc, inter_eq_self_of_subset_left hJ.subset_ground] theorem IsBase.isBasis_of_subset (hX : X ⊆ M.E := by aesop_mat) (hB : M.IsBase B) (hBX : B ⊆ X) : M.IsBasis B X := by rw [isBasis_iff, and_iff_right hB.indep, and_iff_right hBX] exact fun J hJ hBJ _ ↦ hB.eq_of_subset_indep hJ hBJ theorem exists_isBasis_disjoint_isBasis_of_subset (M : Matroid α) {X Y : Set α} (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) : ∃ I J, M.IsBasis I X ∧ M.IsBasis (I ∪ J) Y ∧ Disjoint X J := by obtain ⟨I, I', hI, hI', hII'⟩ := M.exists_isBasis_subset_isBasis hXY refine ⟨I, I' \ I, hI, by rwa [union_diff_self, union_eq_self_of_subset_left hII'], ?_⟩ rw [disjoint_iff_forall_ne] rintro e heX _ ⟨heI', heI⟩ rfl exact heI <| hI.mem_of_insert_indep heX (hI'.indep.subset (insert_subset heI' hII')) end IsBasis section Finite /-- For finite `E`, finitely many matroids have ground set contained in `E`. -/ theorem finite_setOf_matroid {E : Set α} (hE : E.Finite) : {M : Matroid α | M.E ⊆ E}.Finite := by set f : Matroid α → Set α × (Set (Set α)) := fun M ↦ ⟨M.E, {B | M.IsBase B}⟩ have hf : f.Injective := by refine fun M M' hMM' ↦ ?_ rw [Prod.mk.injEq, and_comm, Set.ext_iff, and_comm] at hMM' exact ext_isBase hMM'.1 (fun B _ ↦ hMM'.2 B) rw [← Set.finite_image_iff hf.injOn] refine (hE.finite_subsets.prod hE.finite_subsets.finite_subsets).subset ?_ rintro _ ⟨M, hE : M.E ⊆ E, rfl⟩ simp only [Set.mem_prod, Set.mem_setOf_eq] exact ⟨hE, fun B hB ↦ hB.subset_ground.trans hE⟩ /-- For finite `E`, finitely many matroids have ground set `E`. -/ theorem finite_setOf_matroid' {E : Set α} (hE : E.Finite) : {M : Matroid α | M.E = E}.Finite := (finite_setOf_matroid hE).subset (fun M ↦ by rintro rfl; exact rfl.subset) end Finite end Matroid
Subalgebra.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Basic import Mathlib.RingTheory.Artinian.Module /-! # Lie subalgebras This file defines Lie subalgebras of a Lie algebra and provides basic related definitions and results. ## Main definitions * `LieSubalgebra` * `LieSubalgebra.incl` * `LieSubalgebra.map` * `LieHom.range` * `LieEquiv.ofInjective` * `LieEquiv.ofEq` * `LieEquiv.ofSubalgebras` ## Tags lie algebra, lie subalgebra -/ universe u v w w₁ w₂ section LieSubalgebra variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L] /-- A Lie subalgebra of a Lie algebra is submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie algebra. -/ structure LieSubalgebra extends Submodule R L where /-- A Lie subalgebra is closed under Lie bracket. -/ lie_mem' : ∀ {x y}, x ∈ carrier → y ∈ carrier → ⁅x, y⁆ ∈ carrier /-- The zero algebra is a subalgebra of any Lie algebra. -/ instance : Zero (LieSubalgebra R L) := ⟨⟨0, @fun x y hx _hy ↦ by rw [(Submodule.mem_bot R).1 hx, zero_lie] exact Submodule.zero_mem 0⟩⟩ instance : Inhabited (LieSubalgebra R L) := ⟨0⟩ instance : Coe (LieSubalgebra R L) (Submodule R L) := ⟨LieSubalgebra.toSubmodule⟩ namespace LieSubalgebra instance : SetLike (LieSubalgebra R L) L where coe L' := L'.carrier coe_injective' L' L'' h := by rcases L' with ⟨⟨⟩⟩ rcases L'' with ⟨⟨⟩⟩ congr exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubalgebra R L) L where add_mem := Submodule.add_mem _ zero_mem L' := L'.zero_mem' neg_mem {L'} x hx := show -x ∈ (L' : Submodule R L) from neg_mem hx instance : SMulMemClass (LieSubalgebra R L) R L where smul_mem {s} := SMulMemClass.smul_mem (s := s.toSubmodule) /-- A Lie subalgebra forms a new Lie ring. -/ instance lieRing (L' : LieSubalgebra R L) : LieRing L' where bracket x y := ⟨⁅x.val, y.val⁆, L'.lie_mem' x.property y.property⟩ lie_add := by intros apply SetCoe.ext apply lie_add add_lie := by intros apply SetCoe.ext apply add_lie lie_self := by intros apply SetCoe.ext apply lie_self leibniz_lie := by intros apply SetCoe.ext apply leibniz_lie section variable {R₁ : Type*} [Semiring R₁] /-- A Lie subalgebra inherits module structures from `L`. -/ instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : Module R₁ L' := L'.toSubmodule.module' instance [SMul R₁ R] [SMul R₁ᵐᵒᵖ R] [Module R₁ L] [Module R₁ᵐᵒᵖ L] [IsScalarTower R₁ R L] [IsScalarTower R₁ᵐᵒᵖ R L] [IsCentralScalar R₁ L] (L' : LieSubalgebra R L) : IsCentralScalar R₁ L' := L'.toSubmodule.isCentralScalar instance [SMul R₁ R] [Module R₁ L] [IsScalarTower R₁ R L] (L' : LieSubalgebra R L) : IsScalarTower R₁ R L' := L'.toSubmodule.isScalarTower instance (L' : LieSubalgebra R L) [IsNoetherian R L] : IsNoetherian R L' := isNoetherian_submodule' _ instance (L' : LieSubalgebra R L) [IsArtinian R L] : IsArtinian R L' := isArtinian_submodule' _ end /-- A Lie subalgebra forms a new Lie algebra. -/ instance lieAlgebra (L' : LieSubalgebra R L) : LieAlgebra R L' where lie_smul := by { intros apply SetCoe.ext apply lie_smul } variable {R L} variable (L' : LieSubalgebra R L) protected theorem zero_mem : (0 : L) ∈ L' := zero_mem L' protected theorem add_mem {x y : L} : x ∈ L' → y ∈ L' → (x + y : L) ∈ L' := add_mem protected theorem sub_mem {x y : L} : x ∈ L' → y ∈ L' → (x - y : L) ∈ L' := sub_mem protected theorem smul_mem (t : R) {x : L} (h : x ∈ L') : t • x ∈ L' := SMulMemClass.smul_mem _ h theorem lie_mem {x y : L} (hx : x ∈ L') (hy : y ∈ L') : (⁅x, y⁆ : L) ∈ L' := L'.lie_mem' hx hy theorem mem_carrier {x : L} : x ∈ L'.carrier ↔ x ∈ (L' : Set L) := Iff.rfl theorem mem_mk_iff (S : Set L) (h₁ h₂ h₃ h₄) {x : L} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) ↔ x ∈ S := Iff.rfl @[simp] theorem mem_toSubmodule {x : L} : x ∈ (L' : Submodule R L) ↔ x ∈ L' := Iff.rfl @[simp] theorem mem_mk_iff' (p : Submodule R L) (h) {x : L} : x ∈ (⟨p, h⟩ : LieSubalgebra R L) ↔ x ∈ p := Iff.rfl theorem mem_coe {x : L} : x ∈ (L' : Set L) ↔ x ∈ L' := Iff.rfl @[simp, norm_cast] theorem coe_bracket (x y : L') : (↑⁅x, y⁆ : L) = ⁅(↑x : L), ↑y⁆ := rfl theorem ext_iff (x y : L') : x = y ↔ (x : L) = y := Subtype.ext_iff theorem coe_zero_iff_zero (x : L') : (x : L) = 0 ↔ x = 0 := (ext_iff L' x 0).symm @[ext] theorem ext (L₁' L₂' : LieSubalgebra R L) (h : ∀ x, x ∈ L₁' ↔ x ∈ L₂') : L₁' = L₂' := SetLike.ext h theorem ext_iff' (L₁' L₂' : LieSubalgebra R L) : L₁' = L₂' ↔ ∀ x, x ∈ L₁' ↔ x ∈ L₂' := SetLike.ext_iff @[simp] theorem mk_coe (S : Set L) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubalgebra R L) : Set L) = S := rfl theorem toSubmodule_mk (p : Submodule R L) (h) : (({ p with lie_mem' := h } : LieSubalgebra R L) : Submodule R L) = p := by cases p rfl theorem coe_injective : Function.Injective ((↑) : LieSubalgebra R L → Set L) := SetLike.coe_injective @[norm_cast] theorem coe_set_eq (L₁' L₂' : LieSubalgebra R L) : (L₁' : Set L) = L₂' ↔ L₁' = L₂' := SetLike.coe_set_eq theorem toSubmodule_injective : Function.Injective ((↑) : LieSubalgebra R L → Submodule R L) := fun L₁' L₂' h ↦ by rw [SetLike.ext'_iff] at h rw [← coe_set_eq] exact h @[simp] theorem toSubmodule_inj (L₁' L₂' : LieSubalgebra R L) : (L₁' : Submodule R L) = (L₂' : Submodule R L) ↔ L₁' = L₂' := toSubmodule_injective.eq_iff theorem coe_toSubmodule : ((L' : Submodule R L) : Set L) = L' := rfl section LieModule variable {M : Type w} [AddCommGroup M] [LieRingModule L M] variable {N : Type w₁} [AddCommGroup N] [LieRingModule L N] [Module R N] instance : Bracket L' M where bracket x m := ⁅(x : L), m⁆ @[simp] theorem coe_bracket_of_module (x : L') (m : M) : ⁅x, m⁆ = ⁅(x : L), m⁆ := rfl instance : IsLieTower L' L M where leibniz_lie x y m := leibniz_lie x.val y m /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie ring module `M` of `L`, we may regard `M` as a Lie ring module of `L'` by restriction. -/ instance lieRingModule : LieRingModule L' M where add_lie x y m := add_lie (x : L) y m lie_add x y m := lie_add (x : L) y m leibniz_lie x y m := leibniz_lie x (y : L) m variable [Module R M] /-- Given a Lie algebra `L` containing a Lie subalgebra `L' ⊆ L`, together with a Lie module `M` of `L`, we may regard `M` as a Lie module of `L'` by restriction. -/ instance lieModule [LieModule R L M] : LieModule R L' M where smul_lie t x m := by rw [coe_bracket_of_module, Submodule.coe_smul_of_tower, smul_lie, coe_bracket_of_module] lie_smul t x m := by simp only [coe_bracket_of_module, lie_smul] /-- An `L`-equivariant map of Lie modules `M → N` is `L'`-equivariant for any Lie subalgebra `L' ⊆ L`. -/ def _root_.LieModuleHom.restrictLie (f : M →ₗ⁅R,L⁆ N) (L' : LieSubalgebra R L) : M →ₗ⁅R,L'⁆ N := { (f : M →ₗ[R] N) with map_lie' := @fun x m ↦ f.map_lie (↑x) m } @[simp] theorem _root_.LieModuleHom.coe_restrictLie (f : M →ₗ⁅R,L⁆ N) : ⇑(f.restrictLie L') = f := rfl end LieModule /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie algebras. -/ def incl : L' →ₗ⁅R⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } @[simp] theorem coe_incl : ⇑L'.incl = ((↑) : L' → L) := rfl /-- The embedding of a Lie subalgebra into the ambient space as a morphism of Lie modules. -/ def incl' : L' →ₗ⁅R,L'⁆ L := { (L' : Submodule R L).subtype with map_lie' := rfl } @[simp] theorem coe_incl' : ⇑L'.incl' = ((↑) : L' → L) := rfl end LieSubalgebra variable {R L} variable {L₂ : Type w} [LieRing L₂] [LieAlgebra R L₂] variable (f : L →ₗ⁅R⁆ L₂) namespace LieHom /-- The range of a morphism of Lie algebras is a Lie subalgebra. -/ def range : LieSubalgebra R L₂ := { LinearMap.range (f : L →ₗ[R] L₂) with lie_mem' := by rintro - - ⟨x, rfl⟩ ⟨y, rfl⟩ exact ⟨⁅x, y⁆, f.map_lie x y⟩ } @[simp] theorem range_coe : (f.range : Set L₂) = Set.range f := LinearMap.range_coe (f : L →ₗ[R] L₂) @[simp] theorem mem_range (x : L₂) : x ∈ f.range ↔ ∃ y : L, f y = x := LinearMap.mem_range theorem mem_range_self (x : L) : f x ∈ f.range := LinearMap.mem_range_self (f : L →ₗ[R] L₂) x /-- We can restrict a morphism to a (surjective) map to its range. -/ def rangeRestrict : L →ₗ⁅R⁆ f.range := { (f : L →ₗ[R] L₂).rangeRestrict with map_lie' := @fun x y ↦ by apply Subtype.ext exact f.map_lie x y } @[simp] theorem rangeRestrict_apply (x : L) : f.rangeRestrict x = ⟨f x, f.mem_range_self x⟩ := rfl theorem surjective_rangeRestrict : Function.Surjective f.rangeRestrict := by rintro ⟨y, hy⟩ rw [mem_range] at hy; obtain ⟨x, rfl⟩ := hy use x simp only [rangeRestrict_apply] /-- A Lie algebra is equivalent to its range under an injective Lie algebra morphism. -/ noncomputable def equivRangeOfInjective (h : Function.Injective f) : L ≃ₗ⁅R⁆ f.range := LieEquiv.ofBijective f.rangeRestrict ⟨fun x y hxy ↦ by simp only [Subtype.mk_eq_mk, rangeRestrict_apply] at hxy exact h hxy, f.surjective_rangeRestrict⟩ @[simp] theorem equivRangeOfInjective_apply (h : Function.Injective f) (x : L) : f.equivRangeOfInjective h x = ⟨f x, mem_range_self f x⟩ := rfl end LieHom theorem Submodule.exists_lieSubalgebra_coe_eq_iff (p : Submodule R L) : (∃ K : LieSubalgebra R L, ↑K = p) ↔ ∀ x y : L, x ∈ p → y ∈ p → ⁅x, y⁆ ∈ p := by constructor · rintro ⟨K, rfl⟩ _ _ exact K.lie_mem' · intro h use { p with lie_mem' := h _ _ } namespace LieSubalgebra variable (K K' : LieSubalgebra R L) (K₂ : LieSubalgebra R L₂) @[simp] theorem incl_range : K.incl.range = K := by rw [← toSubmodule_inj] exact (K : Submodule R L).range_subtype /-- The image of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the codomain. -/ def map : LieSubalgebra R L₂ := { (K : Submodule R L).map (f : L →ₗ[R] L₂) with lie_mem' {x y} hx hy := by simp only [AddSubsemigroup.mem_carrier] at hx hy rcases hx with ⟨x', hx', rfl⟩ rcases hy with ⟨y', hy', rfl⟩ simpa using ⟨⁅x', y'⁆, K.lie_mem hx' hy', f.map_lie x' y'⟩ } @[simp] theorem mem_map (x : L₂) : x ∈ K.map f ↔ ∃ y : L, y ∈ K ∧ f y = x := Submodule.mem_map -- TODO Rename and state for homs instead of equivs. theorem mem_map_submodule (e : L ≃ₗ⁅R⁆ L₂) (x : L₂) : x ∈ K.map (e : L →ₗ⁅R⁆ L₂) ↔ x ∈ (K : Submodule R L).map (e : L →ₗ[R] L₂) := Iff.rfl /-- The preimage of a Lie subalgebra under a Lie algebra morphism is a Lie subalgebra of the domain. -/ def comap : LieSubalgebra R L := { (K₂ : Submodule R L₂).comap (f : L →ₗ[R] L₂) with lie_mem' := @fun x y hx hy ↦ by suffices ⁅f x, f y⁆ ∈ K₂ by simp [this] exact K₂.lie_mem hx hy } @[simp] lemma mem_comap {x : L} : x ∈ K₂.comap f ↔ f x ∈ K₂ := Iff.rfl section LatticeStructure open Set instance : PartialOrder (LieSubalgebra R L) := { PartialOrder.lift ((↑) : LieSubalgebra R L → Set L) coe_injective with le := fun N N' ↦ ∀ ⦃x⦄, x ∈ N → x ∈ N' } theorem le_def : K ≤ K' ↔ (K : Set L) ⊆ K' := Iff.rfl @[simp] theorem toSubmodule_le_toSubmodule : (K : Submodule R L) ≤ K' ↔ K ≤ K' := Iff.rfl instance : Bot (LieSubalgebra R L) := ⟨0⟩ @[simp] theorem bot_coe : ((⊥ : LieSubalgebra R L) : Set L) = {0} := rfl @[simp] theorem bot_toSubmodule : ((⊥ : LieSubalgebra R L) : Submodule R L) = ⊥ := rfl @[simp] theorem mem_bot (x : L) : x ∈ (⊥ : LieSubalgebra R L) ↔ x = 0 := mem_singleton_iff instance : Top (LieSubalgebra R L) := ⟨{ (⊤ : Submodule R L) with lie_mem' := @fun x y _ _ ↦ mem_univ ⁅x, y⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubalgebra R L) : Set L) = univ := rfl @[simp] theorem top_toSubmodule : ((⊤ : LieSubalgebra R L) : Submodule R L) = ⊤ := rfl @[simp] theorem mem_top (x : L) : x ∈ (⊤ : LieSubalgebra R L) := mem_univ x theorem _root_.LieHom.range_eq_map : f.range = map f ⊤ := by ext simp instance : Min (LieSubalgebra R L) := ⟨fun K K' ↦ { (K ⊓ K' : Submodule R L) with lie_mem' := fun hx hy ↦ mem_inter (K.lie_mem hx.1 hy.1) (K'.lie_mem hx.2 hy.2) }⟩ instance : InfSet (LieSubalgebra R L) := ⟨fun S ↦ { sInf {(s : Submodule R L) | s ∈ S} with lie_mem' := @fun x y hx hy ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp] at hx hy ⊢ intro K hK exact K.lie_mem (hx K hK) (hy K hK) }⟩ @[simp] theorem inf_coe : (↑(K ⊓ K') : Set L) = (K : Set L) ∩ (K' : Set L) := rfl @[simp] theorem sInf_toSubmodule (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Submodule R L) = sInf {(s : Submodule R L) | s ∈ S} := rfl @[simp] theorem sInf_coe (S : Set (LieSubalgebra R L)) : (↑(sInf S) : Set L) = ⋂ s ∈ S, (s : Set L) := by rw [← coe_toSubmodule, sInf_toSubmodule, Submodule.sInf_coe] ext x simp theorem sInf_glb (S : Set (LieSubalgebra R L)) : IsGLB S (sInf S) := by have h : ∀ K K' : LieSubalgebra R L, (K : Set L) ≤ K' ↔ K ≤ K' := by intros exact Iff.rfl apply IsGLB.of_image @h simp only [sInf_coe] exact isGLB_biInf /-- The set of Lie subalgebras of a Lie algebra form a complete lattice. We provide explicit values for the fields `bot`, `top`, `inf` to get more convenient definitions than we would otherwise obtain from `completeLatticeOfInf`. -/ instance completeLattice : CompleteLattice (LieSubalgebra R L) := { completeLatticeOfInf _ sInf_glb with bot := ⊥ bot_le := fun N _ h ↦ by rw [mem_bot] at h rw [h] exact N.zero_mem' top := ⊤ le_top := fun _ _ _ ↦ trivial inf := (· ⊓ ·) le_inf := fun _ _ _ h₁₂ h₁₃ _ hm ↦ ⟨h₁₂ hm, h₁₃ hm⟩ inf_le_left := fun _ _ _ ↦ And.left inf_le_right := fun _ _ _ ↦ And.right } instance : Add (LieSubalgebra R L) where add := max instance : Zero (LieSubalgebra R L) where zero := ⊥ instance addCommMonoid : AddCommMonoid (LieSubalgebra R L) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec instance : IsOrderedAddMonoid (LieSubalgebra R L) where add_le_add_left _ _ := sup_le_sup_left instance : CanonicallyOrderedAdd (LieSubalgebra R L) where exists_add_of_le {_a b} h := ⟨b, (sup_eq_right.2 h).symm⟩ le_self_add _ _ := le_sup_left @[simp] theorem add_eq_sup : K + K' = K ⊔ K' := rfl @[simp] theorem inf_toSubmodule : (↑(K ⊓ K') : Submodule R L) = (K : Submodule R L) ⊓ (K' : Submodule R L) := rfl @[simp] theorem mem_inf (x : L) : x ∈ K ⊓ K' ↔ x ∈ K ∧ x ∈ K' := by rw [← mem_toSubmodule, ← mem_toSubmodule, ← mem_toSubmodule, inf_toSubmodule, Submodule.mem_inf] theorem eq_bot_iff : K = ⊥ ↔ ∀ x : L, x ∈ K → x = 0 := by rw [_root_.eq_bot_iff] exact Iff.rfl instance subsingleton_of_bot : Subsingleton (LieSubalgebra R (⊥ : LieSubalgebra R L)) := by apply subsingleton_of_bot_eq_top ext ⟨x, hx⟩; change x ∈ ⊥ at hx; rw [LieSubalgebra.mem_bot] at hx; subst hx simp only [mem_bot, mem_top, iff_true] rfl theorem subsingleton_bot : Subsingleton (⊥ : LieSubalgebra R L) := show Subsingleton ((⊥ : LieSubalgebra R L) : Set L) by simp variable (R L) instance wellFoundedGT_of_noetherian [IsNoetherian R L] : WellFoundedGT (LieSubalgebra R L) := RelHomClass.isWellFounded (⟨toSubmodule, @fun _ _ h ↦ h⟩ : _ →r (· > ·)) variable {R L K K' f} section NestedSubalgebras variable (h : K ≤ K') /-- Given two nested Lie subalgebras `K ⊆ K'`, the inclusion `K ↪ K'` is a morphism of Lie algebras. -/ def inclusion : K →ₗ⁅R⁆ K' := { Submodule.inclusion h with map_lie' := @fun _ _ ↦ rfl } @[simp] theorem coe_inclusion (x : K) : (inclusion h x : L) = x := rfl theorem inclusion_apply (x : K) : inclusion h x = ⟨x.1, h x.2⟩ := rfl theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe] /-- Given two nested Lie subalgebras `K ⊆ K'`, we can view `K` as a Lie subalgebra of `K'`, regarded as Lie algebra in its own right. -/ def ofLe : LieSubalgebra R K' := (inclusion h).range @[simp] theorem mem_ofLe (x : K') : x ∈ ofLe h ↔ (x : L) ∈ K := by simp only [ofLe, inclusion_apply, LieHom.mem_range] constructor · rintro ⟨y, rfl⟩ exact y.property · intro h use ⟨(x : L), h⟩ theorem ofLe_eq_comap_incl : ofLe h = K.comap K'.incl := by ext rw [mem_ofLe] rfl @[simp] theorem coe_ofLe : (ofLe h : Submodule R K') = LinearMap.range (Submodule.inclusion h) := rfl /-- Given nested Lie subalgebras `K ⊆ K'`, there is a natural equivalence from `K` to its image in `K'`. -/ noncomputable def equivOfLe : K ≃ₗ⁅R⁆ ofLe h := (inclusion h).equivRangeOfInjective (inclusion_injective h) @[simp] theorem equivOfLe_apply (x : K) : equivOfLe h x = ⟨inclusion h x, (inclusion h).mem_range_self x⟩ := rfl end NestedSubalgebras theorem map_le_iff_le_comap {K : LieSubalgebra R L} {K' : LieSubalgebra R L₂} : map f K ≤ K' ↔ K ≤ comap f K' := Set.image_subset_iff theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap end LatticeStructure section LieSpan variable (R L) (s : Set L) /-- The Lie subalgebra of a Lie algebra `L` generated by a subset `s ⊆ L`. -/ def lieSpan : LieSubalgebra R L := sInf { N | s ⊆ N } variable {R L s} theorem mem_lieSpan {x : L} : x ∈ lieSpan R L s ↔ ∀ K : LieSubalgebra R L, s ⊆ K → x ∈ K := by rw [← SetLike.mem_coe, lieSpan, sInf_coe] exact Set.mem_iInter₂ theorem subset_lieSpan : s ⊆ lieSpan R L s := by intro m hm rw [SetLike.mem_coe, mem_lieSpan] intro K hK exact hK hm theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by rw [Submodule.span_le, coe_toSubmodule] apply subset_lieSpan theorem lieSpan_le {K} : lieSpan R L s ≤ K ↔ s ⊆ K := by constructor · exact Set.Subset.trans subset_lieSpan · intro hs m hm rw [mem_lieSpan] at hm exact hm _ hs theorem lieSpan_mono {t : Set L} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by rw [lieSpan_le] exact Set.Subset.trans h subset_lieSpan theorem lieSpan_eq : lieSpan R L (K : Set L) = K := le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan theorem coe_lieSpan_submodule_eq_iff {p : Submodule R L} : (lieSpan R L (p : Set L) : Submodule R L) = p ↔ ∃ K : LieSubalgebra R L, ↑K = p := by rw [p.exists_lieSubalgebra_coe_eq_iff]; constructor <;> intro h · intro x m hm rw [← h, mem_toSubmodule] exact lie_mem _ (subset_lieSpan hm) · rw [← toSubmodule_mk p @h, coe_toSubmodule, toSubmodule_inj, lieSpan_eq] open Submodule in theorem coe_lieSpan_eq_span_of_forall_lie_eq_zero {s : Set L} (hs : ∀ᵉ (x ∈ s) (y ∈ s), ⁅x, y⁆ = 0) : lieSpan R L s = span R s := by suffices ∀ {x y}, x ∈ span R s → y ∈ span R s → ⁅x, y⁆ ∈ span R s by refine le_antisymm ?_ submodule_span_le_lieSpan change _ ≤ ({ span R s with lie_mem' := this } : LieSubalgebra R L) rw [lieSpan_le] exact subset_span intro x y hx hy induction hx, hy using span_induction₂ with | mem_mem x y hx hy => simp [hs x hx y hy] | zero_left y hy => simp | zero_right x hx => simp | add_left x y z _ _ _ hx hy => simp [add_mem hx hy] | add_right x y z _ _ _ hx hy => simp [add_mem hx hy] | smul_left r x y _ _ h => simp [smul_mem _ r h] | smul_right r x y _ _ h => simp [smul_mem _ r h] variable (R L) /-- `lieSpan` forms a Galois insertion with the coercion from `LieSubalgebra` to `Set`. -/ protected def gi : GaloisInsertion (lieSpan R L : Set L → LieSubalgebra R L) (↑) where choice s _ := lieSpan R L s gc _ _ := lieSpan_le le_l_u _ := subset_lieSpan choice_eq _ _ := rfl @[simp] theorem span_empty : lieSpan R L (∅ : Set L) = ⊥ := (LieSubalgebra.gi R L).gc.l_bot @[simp] theorem span_univ : lieSpan R L (Set.univ : Set L) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_lieSpan variable {L} theorem span_union (s t : Set L) : lieSpan R L (s ∪ t) = lieSpan R L s ⊔ lieSpan R L t := (LieSubalgebra.gi R L).gc.l_sup theorem span_iUnion {ι} (s : ι → Set L) : lieSpan R L (⋃ i, s i) = ⨆ i, lieSpan R L (s i) := (LieSubalgebra.gi R L).gc.l_iSup /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition, scalar multiplication and the Lie bracket, then `p` holds for all elements of the Lie algebra spanned by `s`. -/ @[elab_as_elim] theorem lieSpan_induction {p : (x : L) → x ∈ lieSpan R L s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_lieSpan h)) (zero : p 0 (LieSubalgebra.zero_mem _)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (LieSubalgebra.add_mem _ ‹_› ‹_›)) (smul : ∀ (a : R) (x hx), p x hx → p (a • x) (LieSubalgebra.smul_mem _ _ ‹_›)) {x} (lie : ∀ x y hx hy, p x hx → p y hy → p (⁅x, y⁆) (LieSubalgebra.lie_mem _ ‹_› ‹_›)) (hx : x ∈ lieSpan R L s) : p x hx := by let p : LieSubalgebra R L := { carrier := { x | ∃ hx, p x hx } add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩ zero_mem' := ⟨_, zero⟩ smul_mem' := fun r ↦ fun ⟨_, hpx⟩ ↦ ⟨_, smul r _ _ hpx⟩ lie_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, lie _ _ _ _ hpx hpy⟩ } exact lieSpan_le (K := p) |>.mpr (fun y hy ↦ ⟨subset_lieSpan hy, mem y hy⟩) hx |>.elim fun _ ↦ id end LieSpan end LieSubalgebra end LieSubalgebra namespace LieEquiv variable {R : Type u} {L₁ : Type v} {L₂ : Type w} variable [CommRing R] [LieRing L₁] [LieRing L₂] [LieAlgebra R L₁] [LieAlgebra R L₂] /-- An injective Lie algebra morphism is an equivalence onto its range. -/ noncomputable def ofInjective (f : L₁ →ₗ⁅R⁆ L₂) (h : Function.Injective f) : L₁ ≃ₗ⁅R⁆ f.range := { LinearEquiv.ofInjective (f : L₁ →ₗ[R] L₂) <| by rwa [LieHom.coe_toLinearMap] with map_lie' {x y} := SetCoe.ext <| f.map_lie x y } @[simp] theorem ofInjective_apply (f : L₁ →ₗ⁅R⁆ L₂) (h : Function.Injective f) (x : L₁) : ↑(ofInjective f h x) = f x := rfl variable (L₁' L₁'' : LieSubalgebra R L₁) (L₂' : LieSubalgebra R L₂) /-- Lie subalgebras that are equal as sets are equivalent as Lie algebras. -/ def ofEq (h : (L₁' : Set L₁) = L₁'') : L₁' ≃ₗ⁅R⁆ L₁'' := { LinearEquiv.ofEq (L₁' : Submodule R L₁) (L₁'' : Submodule R L₁) (by ext x change x ∈ (L₁' : Set L₁) ↔ x ∈ (L₁'' : Set L₁) rw [h]) with map_lie' {_ _} := rfl } @[simp] theorem ofEq_apply (L L' : LieSubalgebra R L₁) (h : (L : Set L₁) = L') (x : L) : (↑(ofEq L L' h x) : L₁) = x := rfl variable (e : L₁ ≃ₗ⁅R⁆ L₂) /-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its image. -/ def lieSubalgebraMap : L₁'' ≃ₗ⁅R⁆ (L₁''.map e : LieSubalgebra R L₂) := { LinearEquiv.submoduleMap (e : L₁ ≃ₗ[R] L₂) ↑L₁'' with map_lie' := @fun x y ↦ by apply SetCoe.ext exact LieHom.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y } @[simp] theorem lieSubalgebraMap_apply (x : L₁'') : ↑(e.lieSubalgebraMap _ x) = e x := rfl /-- An equivalence of Lie algebras restricts to an equivalence from any Lie subalgebra onto its image. -/ def ofSubalgebras (h : L₁'.map ↑e = L₂') : L₁' ≃ₗ⁅R⁆ L₂' := { LinearEquiv.ofSubmodules (e : L₁ ≃ₗ[R] L₂) (↑L₁') (↑L₂') (by rw [← h] rfl) with map_lie' := @fun x y ↦ by apply SetCoe.ext exact LieHom.map_lie (↑e : L₁ →ₗ⁅R⁆ L₂) ↑x ↑y } @[simp] theorem ofSubalgebras_apply (h : L₁'.map ↑e = L₂') (x : L₁') : ↑(e.ofSubalgebras _ _ h x) = e x := rfl @[simp] theorem ofSubalgebras_symm_apply (h : L₁'.map ↑e = L₂') (x : L₂') : ↑((e.ofSubalgebras _ _ h).symm x) = e.symm x := rfl end LieEquiv
Division.lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.MonoidAlgebra.Division import Mathlib.Algebra.MvPolynomial.Basic /-! # Division of `MvPolynomial` by monomials ## Main definitions * `MvPolynomial.divMonomial x s`: divides `x` by the monomial `MvPolynomial.monomial 1 s` * `MvPolynomial.modMonomial x s`: the remainder upon dividing `x` by the monomial `MvPolynomial.monomial 1 s`. ## Main results * `MvPolynomial.divMonomial_add_modMonomial`, `MvPolynomial.modMonomial_add_divMonomial`: `divMonomial` and `modMonomial` are well-behaved as quotient and remainder operators. ## Implementation notes Where possible, the results in this file should be first proved in the generality of `AddMonoidAlgebra`, and then the versions specialized to `MvPolynomial` proved in terms of these. -/ variable {σ R : Type*} [CommSemiring R] namespace MvPolynomial section CopiedDeclarations /-! Please ensure the declarations in this section are direct translations of `AddMonoidAlgebra` results. -/ /-- Divide by `monomial 1 s`, discarding terms not divisible by this. -/ noncomputable def divMonomial (p : MvPolynomial σ R) (s : σ →₀ ℕ) : MvPolynomial σ R := AddMonoidAlgebra.divOf p s local infixl:70 " /ᵐᵒⁿᵒᵐⁱᵃˡ " => divMonomial @[simp] theorem coeff_divMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) (s' : σ →₀ ℕ) : coeff s' (x /ᵐᵒⁿᵒᵐⁱᵃˡ s) = coeff (s + s') x := rfl @[simp] theorem support_divMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) : (x /ᵐᵒⁿᵒᵐⁱᵃˡ s).support = x.support.preimage _ (add_right_injective s).injOn := rfl @[simp] theorem zero_divMonomial (s : σ →₀ ℕ) : (0 : MvPolynomial σ R) /ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 := AddMonoidAlgebra.zero_divOf _ theorem divMonomial_zero (x : MvPolynomial σ R) : x /ᵐᵒⁿᵒᵐⁱᵃˡ 0 = x := x.divOf_zero theorem add_divMonomial (x y : MvPolynomial σ R) (s : σ →₀ ℕ) : (x + y) /ᵐᵒⁿᵒᵐⁱᵃˡ s = x /ᵐᵒⁿᵒᵐⁱᵃˡ s + y /ᵐᵒⁿᵒᵐⁱᵃˡ s := map_add (N := _ →₀ _) _ _ _ theorem divMonomial_add (a b : σ →₀ ℕ) (x : MvPolynomial σ R) : x /ᵐᵒⁿᵒᵐⁱᵃˡ (a + b) = x /ᵐᵒⁿᵒᵐⁱᵃˡ a /ᵐᵒⁿᵒᵐⁱᵃˡ b := x.divOf_add _ _ @[simp] theorem divMonomial_monomial_mul (a : σ →₀ ℕ) (x : MvPolynomial σ R) : monomial a 1 * x /ᵐᵒⁿᵒᵐⁱᵃˡ a = x := x.of'_mul_divOf _ @[simp] theorem divMonomial_mul_monomial (a : σ →₀ ℕ) (x : MvPolynomial σ R) : x * monomial a 1 /ᵐᵒⁿᵒᵐⁱᵃˡ a = x := x.mul_of'_divOf _ @[simp] theorem divMonomial_monomial (a : σ →₀ ℕ) : monomial a 1 /ᵐᵒⁿᵒᵐⁱᵃˡ a = (1 : MvPolynomial σ R) := AddMonoidAlgebra.of'_divOf _ /-- The remainder upon division by `monomial 1 s`. -/ noncomputable def modMonomial (x : MvPolynomial σ R) (s : σ →₀ ℕ) : MvPolynomial σ R := x.modOf s local infixl:70 " %ᵐᵒⁿᵒᵐⁱᵃˡ " => modMonomial @[simp] theorem coeff_modMonomial_of_not_le {s' s : σ →₀ ℕ} (x : MvPolynomial σ R) (h : ¬s ≤ s') : coeff s' (x %ᵐᵒⁿᵒᵐⁱᵃˡ s) = coeff s' x := x.modOf_apply_of_not_exists_add s s' (by rintro ⟨d, rfl⟩ exact h le_self_add) @[simp] theorem coeff_modMonomial_of_le {s' s : σ →₀ ℕ} (x : MvPolynomial σ R) (h : s ≤ s') : coeff s' (x %ᵐᵒⁿᵒᵐⁱᵃˡ s) = 0 := x.modOf_apply_of_exists_add _ _ <| exists_add_of_le h @[simp] theorem monomial_mul_modMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) : monomial s 1 * x %ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 := x.of'_mul_modOf _ @[simp] theorem mul_monomial_modMonomial (s : σ →₀ ℕ) (x : MvPolynomial σ R) : x * monomial s 1 %ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 := x.mul_of'_modOf _ @[simp] theorem monomial_modMonomial (s : σ →₀ ℕ) : monomial s (1 : R) %ᵐᵒⁿᵒᵐⁱᵃˡ s = 0 := AddMonoidAlgebra.of'_modOf _ theorem divMonomial_add_modMonomial (x : MvPolynomial σ R) (s : σ →₀ ℕ) : monomial s 1 * (x /ᵐᵒⁿᵒᵐⁱᵃˡ s) + x %ᵐᵒⁿᵒᵐⁱᵃˡ s = x := AddMonoidAlgebra.divOf_add_modOf x s theorem modMonomial_add_divMonomial (x : MvPolynomial σ R) (s : σ →₀ ℕ) : x %ᵐᵒⁿᵒᵐⁱᵃˡ s + monomial s 1 * (x /ᵐᵒⁿᵒᵐⁱᵃˡ s) = x := AddMonoidAlgebra.modOf_add_divOf x s theorem monomial_one_dvd_iff_modMonomial_eq_zero {i : σ →₀ ℕ} {x : MvPolynomial σ R} : monomial i (1 : R) ∣ x ↔ x %ᵐᵒⁿᵒᵐⁱᵃˡ i = 0 := AddMonoidAlgebra.of'_dvd_iff_modOf_eq_zero end CopiedDeclarations section XLemmas local infixl:70 " /ᵐᵒⁿᵒᵐⁱᵃˡ " => divMonomial local infixl:70 " %ᵐᵒⁿᵒᵐⁱᵃˡ " => modMonomial @[simp] theorem X_mul_divMonomial (i : σ) (x : MvPolynomial σ R) : X i * x /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = x := divMonomial_monomial_mul _ _ @[simp] theorem X_divMonomial (i : σ) : (X i : MvPolynomial σ R) /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 1 := divMonomial_monomial (Finsupp.single i 1) @[simp] theorem mul_X_divMonomial (x : MvPolynomial σ R) (i : σ) : x * X i /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = x := divMonomial_mul_monomial _ _ @[simp] theorem X_mul_modMonomial (i : σ) (x : MvPolynomial σ R) : X i * x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 := monomial_mul_modMonomial _ _ @[simp] theorem mul_X_modMonomial (x : MvPolynomial σ R) (i : σ) : x * X i %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 := mul_monomial_modMonomial _ _ @[simp] theorem modMonomial_X (i : σ) : (X i : MvPolynomial σ R) %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 := monomial_modMonomial _ theorem divMonomial_add_modMonomial_single (x : MvPolynomial σ R) (i : σ) : X i * (x /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1) + x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = x := divMonomial_add_modMonomial _ _ theorem modMonomial_add_divMonomial_single (x : MvPolynomial σ R) (i : σ) : x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 + X i * (x /ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1) = x := modMonomial_add_divMonomial _ _ theorem X_dvd_iff_modMonomial_eq_zero {i : σ} {x : MvPolynomial σ R} : X i ∣ x ↔ x %ᵐᵒⁿᵒᵐⁱᵃˡ Finsupp.single i 1 = 0 := monomial_one_dvd_iff_modMonomial_eq_zero end XLemmas /-! ### Some results about dvd (`∣`) on `monomial` and `X` -/ theorem monomial_dvd_monomial {r s : R} {i j : σ →₀ ℕ} : monomial i r ∣ monomial j s ↔ (s = 0 ∨ i ≤ j) ∧ r ∣ s := by constructor · rintro ⟨x, hx⟩ rw [MvPolynomial.ext_iff] at hx have hj := hx j have hi := hx i classical simp_rw [coeff_monomial, if_pos] at hj hi simp_rw [coeff_monomial_mul'] at hi hj split_ifs at hi hj with hi hi · exact ⟨Or.inr hi, _, hj⟩ · exact ⟨Or.inl hj, hj.symm ▸ dvd_zero _⟩ -- Porting note: two goals remain at this point in Lean 4 · simp_all only [or_true, dvd_mul_right, and_self] · simp_all only [ite_self, le_refl, ite_true, dvd_mul_right, or_false, and_self] · rintro ⟨h | hij, d, rfl⟩ · simp_rw [h, monomial_zero, dvd_zero] · refine ⟨monomial (j - i) d, ?_⟩ rw [monomial_mul, add_tsub_cancel_of_le hij] @[simp] theorem monomial_one_dvd_monomial_one [Nontrivial R] {i j : σ →₀ ℕ} : monomial i (1 : R) ∣ monomial j 1 ↔ i ≤ j := by rw [monomial_dvd_monomial] simp_rw [one_ne_zero, false_or, dvd_rfl, and_true] @[simp] theorem X_dvd_X [Nontrivial R] {i j : σ} : (X i : MvPolynomial σ R) ∣ (X j : MvPolynomial σ R) ↔ i = j := by refine monomial_one_dvd_monomial_one.trans ?_ simp_rw [Finsupp.single_le_iff, Nat.one_le_iff_ne_zero, Finsupp.single_apply_ne_zero, ne_eq, reduceCtorEq, not_false_eq_true, and_true] @[simp] theorem X_dvd_monomial {i : σ} {j : σ →₀ ℕ} {r : R} : (X i : MvPolynomial σ R) ∣ monomial j r ↔ r = 0 ∨ j i ≠ 0 := by refine monomial_dvd_monomial.trans ?_ simp_rw [one_dvd, and_true, Finsupp.single_le_iff, Nat.one_le_iff_ne_zero] end MvPolynomial
algnum.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime. From mathcomp Require Import ssralg poly polydiv ssrnum ssrint archimedean rat. From mathcomp Require Import finalg zmodp matrix mxalgebra mxpoly vector intdiv. From mathcomp Require Import falgebra fieldext separable galois algC cyclotomic. (******************************************************************************) (* This file provides a few basic results and constructions in algebraic *) (* number theory, that are used in the character theory library. Most of *) (* these could be generalized to a more abstract setting. Note that the type *) (* of abstract number fields is simply extFieldType rat. We define here: *) (* x \in Crat_span X <=> x is a Q-linear combination of elements of *) (* X : seq algC. *) (* x \in Cint_span X <=> x is a Z-linear combination of elements of *) (* X : seq algC. *) (* x \in Aint <=> x : algC is an algebraic integer, i.e., the (monic) *) (* polynomial of x over Q has integer coefficients. *) (* (e %| a)%A <=> e divides a with respect to algebraic integers, *) (* (e %| a)%Ax i.e., a is in the algebraic integer ideal generated *) (* by e. This is is notation for a \in dvdA e, where *) (* dvdv is the (collective) predicate for the Aint *) (* ideal generated by e. As in the (e %| a)%C notation *) (* e and a can be coerced to algC from nat or int. *) (* The (e %| a)%Ax display form is a workaround for *) (* design limitations of the Coq Notation facilities. *) (* (a == b %[mod e])%A, (a != b %[mod e])%A <=> *) (* a is equal (resp. not equal) to b mod e, i.e., a and *) (* b belong to the same e * Aint class. We do not *) (* force a, b and e to be algebraic integers. *) (* #[x]%C == the multiplicative order of x, i.e., the n such that *) (* x is an nth primitive root of unity, or 0 if x is not *) (* a root of unity. *) (* In addition several lemmas prove the (constructive) existence of number *) (* fields and of automorphisms of algC. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope algC_scope. Declare Scope algC_expanded_scope. Import GRing.Theory Num.Theory. Local Open Scope ring_scope. Local Notation ZtoQ := (intr : int -> rat). Local Notation ZtoC := (intr : int -> algC). Local Notation QtoC := (ratr : rat -> algC). Local Notation intrp := (map_poly intr). Local Notation pZtoQ := (map_poly ZtoQ). Local Notation pZtoC := (map_poly ZtoC). Local Notation pQtoC := (map_poly ratr). Local Definition intr_inj_ZtoC := (intr_inj : injective ZtoC). #[local] Hint Resolve intr_inj_ZtoC : core. Section MoreAlgCaut. Implicit Type rR : unitRingType. Lemma alg_num_field (Qz : fieldExtType rat) a : a%:A = ratr a :> Qz. Proof. by rewrite -in_algE fmorph_eq_rat. Qed. Lemma rmorphZ_num (Qz : fieldExtType rat) rR (f : {rmorphism Qz -> rR}) a x : f (a *: x) = ratr a * f x. Proof. by rewrite -mulr_algl rmorphM alg_num_field fmorph_rat. Qed. Lemma fmorph_numZ (Qz1 Qz2 : fieldExtType rat) (f : {rmorphism Qz1 -> Qz2}) : scalable f. Proof. by move=> a x; rewrite rmorphZ_num -alg_num_field mulr_algl. Qed. End MoreAlgCaut. (* Number fields and rational spans. *) Lemma algC_PET (s : seq algC) : {z | exists a : nat ^ size s, z = \sum_(i < size s) s`_i *+ a i & exists ps, s = [seq (pQtoC p).[z] | p <- ps]}. Proof. elim: s => [|x s [z /sig_eqW[a Dz] /sig_eqW[ps Ds]]]. by exists 0; [exists [ffun _ => 2%N]; rewrite big_ord0 | exists nil]. have r_exists (y : algC): {r | r != 0 & root (pQtoC r) y}. have [r [_ mon_r] dv_r] := minCpolyP y. by exists r; rewrite ?monic_neq0 ?dv_r. suffices /sig_eqW[[n [|px [|pz []]]]// [Dpx Dpz]]: exists np, let zn := x *+ np.1 + z in [:: x; z] = [seq (pQtoC p).[zn] | p <- np.2]. - exists (x *+ n + z). exists [ffun i => oapp a n (unlift ord0 i)]. rewrite /= big_ord_recl ffunE unlift_none Dz; congr (_ + _). by apply: eq_bigr => i _; rewrite ffunE liftK. exists (px :: [seq p \Po pz | p <- ps]); rewrite /= -Dpx; congr (_ :: _). rewrite -map_comp Ds; apply: eq_map => p /=. by rewrite map_comp_poly horner_comp -Dpz. have [rx nz_rx rx0] := r_exists x. have [rz nz_rz rz0] := r_exists (- z). have pchar0_Q: [pchar rat] =i pred0 by apply: pchar_num. have [n [[pz Dpz] [px Dpx]]] := pchar0_PET nz_rz rz0 nz_rx rx0 pchar0_Q. by exists (n, [:: px; - pz]); rewrite /= !raddfN hornerN -[z]opprK Dpz Dpx. Qed. Lemma num_field_exists (s : seq algC) : {Qs : fieldExtType rat & {QsC : {rmorphism Qs -> algC} & {s1 : seq Qs | map QsC s1 = s & <<1 & s1>>%VS = fullv}}}. Proof. have [z /sig_eqW[a Dz] /sig_eqW[ps Ds]] := algC_PET s. suffices [Qs [QsC [z1 z1C z1gen]]]: {Qs : fieldExtType rat & {QsC : {rmorphism Qs -> algC} & {z1 : Qs | QsC z1 = z & forall xx, exists p, fieldExt_horner z1 p = xx}}}. - set inQs := fieldExt_horner z1 in z1gen *; pose s1 := map inQs ps. have inQsK p: QsC (inQs p) = (pQtoC p).[z]. rewrite /= -horner_map z1C -map_poly_comp; congr _.[z]. by apply: eq_map_poly => b /=; rewrite alg_num_field fmorph_rat. exists Qs, QsC, s1; first by rewrite -map_comp Ds (eq_map inQsK). have sz_ps: size ps = size s by rewrite Ds size_map. apply/vspaceP=> x; rewrite memvf; have [p {x}<-] := z1gen x. elim/poly_ind: p => [|p b ApQs]; first by rewrite /inQs rmorph0 mem0v. rewrite /inQs rmorphD rmorphM /= fieldExt_hornerX fieldExt_hornerC -/inQs /=. suffices ->: z1 = \sum_(i < size s) s1`_i *+ a i. rewrite memvD ?memvZ ?mem1v ?memvM ?memv_suml // => i _. by rewrite rpredMn ?seqv_sub_adjoin ?mem_nth // size_map sz_ps. apply: (fmorph_inj QsC); rewrite z1C Dz rmorph_sum; apply: eq_bigr => i _. by rewrite rmorphMn {1}Ds !(nth_map 0) ?sz_ps //= inQsK. have [r [Dr /monic_neq0 nz_r] dv_r] := minCpolyP z. have rz0: root (pQtoC r) z by rewrite dv_r. have irr_r: irreducible_poly r. by apply/(subfx_irreducibleP rz0 nz_r)=> q qz0 nzq; rewrite dvdp_leq // -dv_r. exists (SubFieldExtType rz0 irr_r), (@subfx_inj _ _ QtoC z r). exists (subfx_root _ z r) => [|x]; first exact: subfx_inj_root. by have{x} [p ->] := subfxEroot rz0 nz_r x; exists p. Qed. Definition in_Crat_span s x := exists a : rat ^ size s, x = \sum_i QtoC (a i) * s`_i. Fact Crat_span_subproof s x : decidable (in_Crat_span s x). Proof. have [Qxs [QxsC [[|x1 s1] // [<- <-] {x s} _]]] := num_field_exists (x :: s). apply: decP (x1 \in <<in_tuple s1>>%VS) _; rewrite /in_Crat_span size_map. apply: (iffP idP) => [/coord_span-> | [a Dx]]. move: (coord _) => a; exists [ffun i => a i x1]; rewrite rmorph_sum /=. by apply: eq_bigr => i _; rewrite ffunE rmorphZ_num (nth_map 0). have{Dx} ->: x1 = \sum_i a i *: s1`_i. apply: (fmorph_inj QxsC); rewrite Dx rmorph_sum /=. by apply: eq_bigr => i _; rewrite rmorphZ_num (nth_map 0). by apply: memv_suml => i _; rewrite memvZ ?memv_span ?mem_nth. Qed. Definition Crat_span s : pred algC := Crat_span_subproof s. Lemma Crat_spanP s x : reflect (in_Crat_span s x) (x \in Crat_span s). Proof. exact: sumboolP. Qed. Lemma mem_Crat_span s : {subset s <= Crat_span s}. Proof. move=> _ /(nthP 0)[ix ltxs <-]; pose i0 := Ordinal ltxs. apply/Crat_spanP; exists [ffun i => (i == i0)%:R]. rewrite (bigD1_ord i0) //= ffunE eqxx // rmorph1 mul1r. by rewrite big1 ?addr0 // => i; rewrite ffunE rmorph_nat mulr_natl lift_eqF. Qed. Fact Crat_span_zmod_closed s : zmod_closed (Crat_span s). Proof. split=> [|_ _ /Crat_spanP[x ->] /Crat_spanP[y ->]]. apply/Crat_spanP; exists 0. by apply/esym/big1=> i _; rewrite ffunE rmorph0 mul0r. apply/Crat_spanP; exists (x - y); rewrite -sumrB; apply: eq_bigr => i _. by rewrite -mulrBl -rmorphB !ffunE. Qed. HB.instance Definition _ s := GRing.isZmodClosed.Build _ (Crat_span s) (Crat_span_zmod_closed s). Section NumFieldProj. Variables (Qn : fieldExtType rat) (QnC : {rmorphism Qn -> algC}). Lemma Crat_spanZ b a : {in Crat_span b, forall x, ratr a * x \in Crat_span b}. Proof. move=> _ /Crat_spanP[a1 ->]; apply/Crat_spanP; exists [ffun i => a * a1 i]. by rewrite mulr_sumr; apply: eq_bigr => i _; rewrite ffunE mulrA -rmorphM. Qed. Lemma Crat_spanM b : {in Crat & Crat_span b, forall a x, a * x \in Crat_span b}. Proof. by move=> _ x /CratP[a ->]; apply: Crat_spanZ. Qed. (* In principle CtoQn could be taken to be additive and Q-linear, but this *) (* would require a limit construction. *) Lemma num_field_proj : {CtoQn | CtoQn 0 = 0 & cancel QnC CtoQn}. Proof. pose b := vbasis {:Qn}. have Qn_bC (u : {x | x \in Crat_span (map QnC b)}): {y | QnC y = sval u}. case: u => _ /= /Crat_spanP/sig_eqW[a ->]. exists (\sum_i a i *: b`_i); rewrite rmorph_sum /=; apply: eq_bigr => i _. by rewrite rmorphZ_num (nth_map 0) // -(size_map QnC). pose CtoQn x := oapp (fun u => sval (Qn_bC u)) 0 (insub x). suffices QnCK: cancel QnC CtoQn by exists CtoQn; rewrite // -(rmorph0 QnC) /=. move=> x; rewrite /CtoQn insubT => /= [|Qn_x]; last first. by case: (Qn_bC _) => x1 /= /fmorph_inj. rewrite (coord_vbasis (memvf x)) rmorph_sum rpred_sum //= => i _. rewrite rmorphZ_num Crat_spanZ ?mem_Crat_span // -/b. by rewrite -tnth_nth -tnth_map mem_tnth. Qed. Lemma restrict_aut_to_num_field (nu : {rmorphism algC -> algC}) : (forall x, exists y, nu (QnC x) = QnC y) -> {nu0 : {lrmorphism Qn -> Qn} | {morph QnC : x / nu0 x >-> nu x}}. Proof. move=> Qn_nu; pose nu0 x := sval (sig_eqW (Qn_nu x)). have QnC_nu0: {morph QnC : x / nu0 x >-> nu x}. by rewrite /nu0 => x; case: (sig_eqW _). have nu0a : zmod_morphism nu0. by move=> x y; apply: (fmorph_inj QnC); rewrite !(QnC_nu0, rmorphB). have nu0m : monoid_morphism nu0. split=> [|x y]; apply: (fmorph_inj QnC); rewrite ?QnC_nu0 ?rmorph1 //. by rewrite !rmorphM /= !QnC_nu0. pose nu0aM := GRing.isZmodMorphism.Build Qn Qn nu0 nu0a. pose nu0mM := GRing.isMonoidMorphism.Build Qn Qn nu0 nu0m. pose nu0RM : {rmorphism _ -> _} := HB.pack nu0 nu0aM nu0mM. pose nu0lM := GRing.isScalable.Build rat Qn Qn *:%R nu0 (fmorph_numZ nu0RM). pose nu0LRM : {lrmorphism _ -> _} := HB.pack nu0 nu0aM nu0mM nu0lM. by exists nu0LRM. Qed. Lemma map_Qnum_poly (nu : {rmorphism algC -> algC}) p : p \in polyOver 1%VS -> map_poly (nu \o QnC) p = (map_poly QnC p). Proof. move=> Qp; apply/polyP=> i; rewrite /= !coef_map /=. have /vlineP[a ->]: p`_i \in 1%VS by apply: polyOverP. by rewrite alg_num_field !fmorph_rat. Qed. End NumFieldProj. Lemma restrict_aut_to_normal_num_field (Qn : splittingFieldType rat) (QnC : {rmorphism Qn -> algC})(nu : {rmorphism algC -> algC}) : {nu0 : {lrmorphism Qn -> Qn} | {morph QnC : x / nu0 x >-> nu x}}. Proof. apply: restrict_aut_to_num_field => x. case: (splitting_field_normal 1%AS x) => rs /eqP Hrs. have: root (map_poly (nu \o QnC) (minPoly 1%AS x)) (nu (QnC x)). by rewrite fmorph_root root_minPoly. rewrite map_Qnum_poly ?minPolyOver // Hrs. rewrite [map_poly _ _](_:_ = \prod_(y <- map QnC rs) ('X - y%:P)). by rewrite root_prod_XsubC; case/mapP => y _ ?; exists y. by rewrite big_map rmorph_prod /=; apply: eq_bigr => i _; rewrite map_polyXsubC. Qed. (* Integral spans. *) Lemma dec_Cint_span (V : vectType algC) m (s : m.-tuple V) v : decidable (inIntSpan s v). Proof. have s_s (i : 'I_m): s`_i \in <<s>>%VS by rewrite memv_span ?memt_nth. have s_Zs a: \sum_(i < m) s`_i *~ a i \in <<s>>%VS. by rewrite memv_suml // => i _; rewrite -scaler_int memvZ. case s_v: (v \in <<s>>%VS); last by right=> [[a Dv]]; rewrite Dv s_Zs in s_v. pose IzT := {: 'I_m * 'I_(\dim <<s>>)}; pose Iz := 'I_#|IzT|. pose b := vbasis <<s>>. pose z_s := [seq coord b ij.2 (tnth s ij.1) | ij : IzT]. pose rank2 j i: Iz := enum_rank (i, j); pose val21 (p : Iz) := (enum_val p).1. pose inQzs w := [forall j, Crat_span z_s (coord b j w)]. have enum_pairK j: {in predT, cancel (rank2 j) val21}. by move=> i; rewrite /val21 enum_rankK. have Qz_Zs a: inQzs (\sum_(i < m) s`_i *~ a i). apply/forallP=> j; apply/Crat_spanP; rewrite /in_Crat_span size_map -cardE. exists [ffun ij => (a (val21 ij))%:Q *+ ((enum_val ij).2 == j)]. rewrite linear_sum {1}(reindex_onto _ _ (enum_pairK j)) big_mkcond /=. apply: eq_bigr => ij _ /=; rewrite nth_image (tnth_nth 0) ffunE /val21. rewrite raddfMz rmorphMn rmorph_int mulrnAl mulrzl /=. rewrite (can2_eq (@enum_rankK _) (@enum_valK _)). by case: (enum_val ij) => i j1; rewrite xpair_eqE eqxx; have [->|] := eqVneq. case Qz_v: (inQzs v); last by right=> [[a Dv]]; rewrite Dv Qz_Zs in Qz_v. have [Qz [QzC [z1s Dz_s _]]] := num_field_exists z_s. have sz_z1s: size z1s = #|IzT| by rewrite -(size_map QzC) Dz_s size_map cardE. have xv j: {x | coord b j v = QzC x}. apply: sig_eqW; have /Crat_spanP[x ->] := forallP Qz_v j. exists (\sum_ij x ij *: z1s`_ij); rewrite rmorph_sum; apply: eq_bigr => ij _. by rewrite rmorphZ_num -[in RHS](nth_map _ 0) ?Dz_s // -(size_map QzC) Dz_s. pose sz := [tuple [ffun j => z1s`_(rank2 j i)] | i < m]. have [Zsv | Zs'v] := dec_Qint_span sz [ffun j => sval (xv j)]. left; have{Zsv} [a Dv] := Zsv; exists a. transitivity (\sum_j \sum_(i < m) QzC ((sz`_i *~ a i) j) *: b`_j). rewrite {1}(coord_vbasis s_v) -/b; apply: eq_bigr => j _. rewrite -scaler_suml; congr (_ *: _). have{Dv} /ffunP/(_ j) := Dv; rewrite sum_ffunE !ffunE -rmorph_sum => <-. by case: (xv j). rewrite exchange_big; apply: eq_bigr => i _. rewrite (coord_vbasis (s_s i)) -/b mulrz_suml; apply: eq_bigr => j _. rewrite scalerMzl ffunMzE rmorphMz; congr ((_ *~ _) *: _). rewrite nth_mktuple ffunE -(nth_map _ 0) ?sz_z1s // Dz_s. by rewrite nth_image enum_rankK /= (tnth_nth 0). right=> [[a Dv]]; case: Zs'v; exists a. apply/ffunP=> j; rewrite sum_ffunE !ffunE; apply: (fmorph_inj QzC). case: (xv j) => /= _ <-; rewrite Dv linear_sum rmorph_sum /=. apply: eq_bigr => i _; rewrite nth_mktuple raddfMz !ffunMzE rmorphMz ffunE. by rewrite -(nth_map _ 0 QzC) ?sz_z1s // Dz_s nth_image enum_rankK -tnth_nth. Qed. Definition Cint_span (s : seq algC) : pred algC := fun x => dec_Cint_span (in_tuple [seq \row_(i < 1) y | y <- s]) (\row_i x). Lemma Cint_spanP n (s : n.-tuple algC) x : reflect (inIntSpan s x) (x \in Cint_span s). Proof. rewrite unfold_in; case: (dec_Cint_span _ _) => [Zs_x | Zs'x] /=. left; have{Zs_x} [] := Zs_x; rewrite /= size_map size_tuple => a /rowP/(_ 0). rewrite !mxE => ->; exists a; rewrite summxE; apply: eq_bigr => i _. by rewrite -scaler_int (nth_map 0) ?size_tuple // !mxE mulrzl. right=> [[a Dx]]; have{Zs'x} [] := Zs'x. rewrite /inIntSpan /= size_map size_tuple; exists a. apply/rowP=> i0; rewrite !mxE summxE Dx; apply: eq_bigr => i _. by rewrite -scaler_int mxE mulrzl (nth_map 0) ?size_tuple // !mxE. Qed. Lemma mem_Cint_span s : {subset s <= Cint_span s}. Proof. move=> _ /(nthP 0)[ix ltxs <-]; apply/(Cint_spanP (in_tuple s)). exists [ffun i => i == Ordinal ltxs : int]. rewrite (bigD1 (Ordinal ltxs)) //= ffunE eqxx. by rewrite big1 ?addr0 // => i; rewrite ffunE => /negbTE->. Qed. Lemma Cint_span_zmod_closed s : zmod_closed (Cint_span s). Proof. have sP := Cint_spanP (in_tuple s); split=> [|_ _ /sP[x ->] /sP[y ->]]. by apply/sP; exists 0; rewrite big1 // => i; rewrite ffunE. apply/sP; exists (x - y); rewrite -sumrB; apply: eq_bigr => i _. by rewrite !ffunE raddfB. Qed. HB.instance Definition _ s := GRing.isZmodClosed.Build _ (Cint_span s) (Cint_span_zmod_closed s). (* Automorphism extensions. *) Lemma extend_algC_subfield_aut (Qs : fieldExtType rat) (QsC : {rmorphism Qs -> algC}) (phi : {rmorphism Qs -> Qs}) : {nu : {rmorphism algC -> algC} | {morph QsC : x / phi x >-> nu x}}. Proof. pose numF_inj (Qr : fieldExtType rat) := {rmorphism Qr -> algC}. pose subAut := {Qr : _ & numF_inj Qr * {lrmorphism Qr -> Qr}}%type. pose SubAut := existT _ _ (_, _) : subAut. pose Sdom (mu : subAut) := projT1 mu. pose Sinj (mu : subAut) : {rmorphism Sdom mu -> algC} := (projT2 mu).1. pose Saut (mu : subAut) : {rmorphism Sdom mu -> Sdom mu} := (projT2 mu).2. have Sinj_poly Qr (QrC : numF_inj Qr) p: map_poly QrC (map_poly (in_alg Qr) p) = pQtoC p. - rewrite -map_poly_comp; apply: eq_map_poly => a. by rewrite /= rmorphZ_num rmorph1 mulr1. have ext1 mu0 x : {mu1 | exists y, x = Sinj mu1 y & exists2 in01 : {lrmorphism _ -> _}, Sinj mu0 =1 Sinj mu1 \o in01 & {morph in01: y / Saut mu0 y >-> Saut mu1 y}}. - pose b0 := vbasis {:Sdom mu0}. have [z _ /sig_eqW[[|px ps] // [Dx Ds]]] := algC_PET (x :: map (Sinj mu0) b0). have [p [_ mon_p] /(_ p) pz0] := minCpolyP z; rewrite dvdpp in pz0. have [r Dr] := closed_field_poly_normal (pQtoC p : {poly algC}). rewrite lead_coef_map {mon_p}(monicP mon_p) rmorph1 scale1r in Dr. have{pz0} rz: z \in r by rewrite -root_prod_XsubC -Dr. have [Qr [QrC [rr Drr genQr]]] := num_field_exists r. have{rz} [zz Dz]: {zz | QrC zz = z}. by move: rz; rewrite -Drr => /mapP/sig2_eqW[zz]; exists zz. have{ps Ds} [in01 Din01]: {in01 : {lrmorphism _ -> _} | Sinj mu0 =1 QrC \o in01}. have in01P y: {yy | Sinj mu0 y = QrC yy}. exists (\sum_i coord b0 i y *: (map_poly (in_alg Qr) ps`_i).[zz]). rewrite {1}(coord_vbasis (memvf y)) !rmorph_sum /=; apply: eq_bigr => i _. rewrite 2!rmorphZ_num -(nth_map _ 0) ?size_tuple // Ds. rewrite -horner_map Dz Sinj_poly (nth_map 0) //. by have:= congr1 size Ds; rewrite !size_map size_tuple => <-. pose in01 y := sval (in01P y). have Din01 y: Sinj mu0 y = QrC (in01 y) by rewrite /in01; case: (in01P y). pose rwM := (=^~ Din01, rmorphZ_num, rmorph1, rmorphB, rmorphM). have in01a : zmod_morphism in01. by move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM. have in01m : monoid_morphism in01. by split; try move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM /= ?rwM. have in01l : scalable in01. by try move=> ? ?; apply: (fmorph_inj QrC); rewrite !rwM. pose in01aM := GRing.isZmodMorphism.Build _ _ in01 in01a. pose in01mM := GRing.isMonoidMorphism.Build _ _ in01 in01m. pose in01lM := GRing.isScalable.Build _ _ _ _ in01 in01l. pose in01LRM : {lrmorphism _ -> _} := HB.pack in01 in01aM in01mM in01lM. by exists in01LRM. have {z zz Dz px} Dx: exists xx, x = QrC xx. exists (map_poly (in_alg Qr) px).[zz]. by rewrite -horner_map Dz Sinj_poly Dx. pose lin01 := linfun in01; pose K := (lin01 @: fullv)%VS. have memK y: reflect (exists yy, y = in01 yy) (y \in K). apply: (iffP memv_imgP) => [[yy _ ->] | [yy ->]]; by exists yy; rewrite ?lfunE ?memvf. have algK: is_aspace K. rewrite /is_aspace has_algid1; last first. by apply/memK; exists 1; rewrite rmorph1. apply/prodvP=> _ _ /memK[y1 ->] /memK[y2 ->]. by apply/memK; exists (y1 * y2); rewrite rmorphM. have ker_in01: lker lin01 == 0%VS. by apply/lker0P=> y1 y2; rewrite !lfunE; apply: fmorph_inj. pose f := (lin01 \o linfun (Saut mu0) \o lin01^-1)%VF. have Df y: f (in01 y) = in01 (Saut mu0 y). transitivity (f (lin01 y)); first by rewrite !lfunE. by do 4!rewrite lfunE /=; rewrite lker0_lfunK. have hom_f: kHom 1 (ASpace algK) f. apply/kHomP_tmp; split=> [_ /vlineP[a ->] | _ _ /memK[y1 ->] /memK[y2 ->]]. by rewrite -(rmorph_alg in01) Df /= !rmorph_alg. by rewrite -rmorphM !Df !rmorphM. pose pr := map_poly (in_alg Qr) p. have Qpr: pr \is a polyOver 1%VS. by apply/polyOverP=> i; rewrite coef_map memvZ ?memv_line. have splitQr: splittingFieldFor K pr fullv. apply: splittingFieldForS (sub1v (Sub K algK)) (subvf _) _; exists rr => //. congr (_ %= _): (eqpxx pr); apply/(map_poly_inj QrC). rewrite Sinj_poly Dr -Drr big_map rmorph_prod /=; apply: eq_bigr => zz _. by rewrite map_polyXsubC. have [f1 aut_f1 Df1]:= kHom_extends (sub1v (ASpace algK)) hom_f Qpr splitQr. pose f1mM := GRing.isMonoidMorphism.Build _ _ f1 (kHom_monoid_morphism aut_f1). pose nu : {lrmorphism _ -> _} := HB.pack (fun_of_lfun f1) f1mM. exists (SubAut Qr QrC nu) => //; exists in01 => //= y. by rewrite -Df -Df1 //; apply/memK; exists y. have phiZ: scalable phi. by move=> a y; rewrite rmorphZ_num -alg_num_field mulr_algl. pose philM := GRing.isScalable.Build _ _ _ _ phi phiZ. pose phiLRM : {lrmorphism _ -> _} := HB.pack (GRing.RMorphism.sort phi) philM. pose fix ext n := if n is i.+1 then oapp (fun x => s2val (ext1 (ext i) x)) (ext i) (unpickle i) else SubAut Qs QsC phiLRM. have mem_ext x n: (pickle x < n)%N -> {xx | Sinj (ext n) xx = x}. move=> ltxn; apply: sig_eqW; elim: n ltxn => // n IHn. rewrite ltnS leq_eqVlt => /predU1P[<- | /IHn[xx <-]] /=. by rewrite pickleK /=; case: (ext1 _ x) => mu [xx]; exists xx. case: (unpickle n) => /= [y|]; last by exists xx. case: (ext1 _ y) => mu /= _ [in_mu inj_in_mu _]. by exists (in_mu xx); rewrite inj_in_mu. pose nu x := Sinj _ (Saut _ (sval (mem_ext x _ (ltnSn _)))). have nu_inj n y: nu (Sinj (ext n) y) = Sinj (ext n) (Saut (ext n) y). rewrite /nu; case: (mem_ext _ _ _); move: _.+1 => n1 y1 Dy /=. without loss /subnK Dn1: n n1 y y1 Dy / (n <= n1)%N. by move=> IH; case/orP: (leq_total n n1) => /IH => [/(_ y) | /(_ y1)]->. move: (n1 - n)%N => k in Dn1; elim: k => [|k IHk] in n Dn1 y Dy *. by move: y1 Dy; rewrite -Dn1 => y1 /fmorph_inj ->. rewrite addSnnS in Dn1; move/IHk: Dn1 => /=. case: (unpickle _) => [z|] /=; last exact. case: (ext1 _ _) => mu /= _ [in_mu Dinj Daut]. by rewrite Dy => /(_ _ (Dinj _))->; rewrite -Daut Dinj. pose le_nu (x : algC) n := (pickle x < n)%N. have max3 x1 x2 x3: exists n, [/\ le_nu x1 n, le_nu x2 n & le_nu x3 n]. exists (maxn (pickle x1) (maxn (pickle x2) (pickle x3))).+1. by apply/and3P; rewrite /le_nu !ltnS -!geq_max. have nua : zmod_morphism nu. move=> x1 x2; have [n] := max3 (x1 - x2) x1 x2. case=> /mem_ext[y Dx] /mem_ext[y1 Dx1] /mem_ext[y2 Dx2]. rewrite -Dx nu_inj; rewrite -Dx1 -Dx2 -rmorphB in Dx. by rewrite (fmorph_inj _ Dx) !rmorphB -!nu_inj Dx1 Dx2. have num : monoid_morphism nu. split=> [|x1 x2]; first by rewrite -(rmorph1 QsC) (nu_inj 0) !rmorph1. have [n] := max3 (x1 * x2) x1 x2. case=> /mem_ext[y Dx] /mem_ext[y1 Dx1] /mem_ext[y2 Dx2]. rewrite -Dx nu_inj; rewrite -Dx1 -Dx2 -rmorphM in Dx. by rewrite (fmorph_inj _ Dx) !rmorphM /= -!nu_inj Dx1 Dx2. pose nuaM := GRing.isZmodMorphism.Build _ _ nu nua. pose numM := GRing.isMonoidMorphism.Build _ _ nu num. pose nuRM : {rmorphism _ -> _} := HB.pack nu nuaM numM. by exists nuRM => x; rewrite /= (nu_inj 0). Qed. (* Extended automorphisms of Q_n. *) Lemma Qn_aut_exists k n : coprime k n -> {u : {rmorphism algC -> algC} | forall z, z ^+ n = 1 -> u z = z ^+ k}. Proof. have [-> /eqnP | n_gt0 co_k_n] := posnP n. by rewrite gcdn0 => ->; exists idfun. have [z prim_z] := C_prim_root_exists n_gt0. have [Qn [QnC [[|zn []] // [Dz]]] genQn] := num_field_exists [:: z]. pose phi := kHomExtend 1 \1 zn (zn ^+ k). have homQn1: kHom 1 1 (\1%VF : 'End(Qn)) by rewrite kHom1. have pzn_zk0: root (map_poly \1%VF (minPoly 1 zn)) (zn ^+ k). rewrite -(fmorph_root QnC) rmorphXn /= Dz -map_poly_comp. rewrite (@eq_map_poly _ _ _ QnC) => [|a]; last by rewrite /= id_lfunE. set p1 := map_poly _ _. have [q1 Dp1]: exists q1, p1 = pQtoC q1. have aP i: (minPoly 1 zn)`_i \in 1%VS. by apply/polyOverP; apply: minPolyOver. have{aP} a_ i := sig_eqW (vlineP _ _ (aP i)). exists (\poly_(i < size (minPoly 1 zn)) sval (a_ i)). apply/polyP=> i; rewrite coef_poly coef_map coef_poly /=. case: ifP => _; rewrite ?rmorph0 //; case: (a_ i) => a /= ->. by rewrite alg_num_field fmorph_rat. have: root p1 z by rewrite -Dz fmorph_root root_minPoly. rewrite Dp1; have [q2 [Dq2 _] ->] := minCpolyP z. case/dvdpP=> r1 ->; rewrite rmorphM rootM /= -Dq2; apply/orP; right. rewrite (minCpoly_cyclotomic prim_z) /cyclotomic. rewrite (bigD1 (Ordinal (ltn_pmod k n_gt0))) ?coprime_modl //=. by rewrite rootM root_XsubC prim_expr_mod ?eqxx. have phim : monoid_morphism phi. by apply/kHom_monoid_morphism; rewrite -genQn span_seq1 /= kHomExtendP. pose phimM := GRing.isMonoidMorphism.Build _ _ phi phim. pose phiRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun phi) phimM. have [nu Dnu] := extend_algC_subfield_aut QnC phiRM. exists nu => _ /(prim_rootP prim_z)[i ->]. rewrite rmorphXn /= exprAC -Dz -Dnu /= -{1}[zn]hornerX /phi. rewrite (kHomExtend_poly homQn1) ?polyOverX //. rewrite map_polyE map_id_in => [|?]; last by rewrite id_lfunE. by rewrite polyseqK hornerX rmorphXn. Qed. (* Algebraic integers. *) Definition Aint : {pred algC} := fun x => minCpoly x \is a polyOver Num.int. Lemma root_monic_Aint p x : root p x -> p \is monic -> p \is a polyOver Num.int -> x \in Aint. Proof. have pZtoQtoC pz: pQtoC (pZtoQ pz) = pZtoC pz. by rewrite -map_poly_comp; apply: eq_map_poly => b; rewrite /= rmorph_int. move=> px0 mon_p /floorpP[pz Dp]; rewrite unfold_in. move: px0; rewrite Dp -pZtoQtoC; have [q [-> mon_q] ->] := minCpolyP x. case/dvdpP_rat_int=> qz [a nz_a Dq] [r]. move/(congr1 (fun q1 => lead_coef (a *: pZtoQ q1))). rewrite rmorphM scalerAl -Dq lead_coefZ lead_coefM /=. have /monicP->: pZtoQ pz \is monic by rewrite -(map_monic QtoC) pZtoQtoC -Dp. rewrite (monicP mon_q) mul1r mulr1 lead_coef_map_inj //; last exact: intr_inj. rewrite Dq => ->; apply/polyOverP=> i; rewrite !(coefZ, coef_map). by rewrite -rmorphM /= rmorph_int. Qed. Lemma Cint_rat_Aint z : z \in Crat -> z \in Aint -> z \in Num.int. Proof. case/CratP=> a ->{z} /polyOverP/(_ 0). have [p [Dp mon_p] dv_p] := minCpolyP (ratr a); rewrite Dp coef_map. suffices /eqP->: p == 'X - a%:P by rewrite polyseqXsubC /= rmorphN rpredN. rewrite -eqp_monic ?monicXsubC // irredp_XsubC //. by rewrite -(size_map_poly QtoC) -Dp neq_ltn size_minCpoly orbT. by rewrite -dv_p fmorph_root root_XsubC. Qed. Lemma Aint_Cint : {subset Num.int <= Aint}. Proof. move=> x; rewrite -polyOverXsubC. by apply: root_monic_Aint; rewrite ?monicXsubC ?root_XsubC. Qed. Lemma Aint_int x : x%:~R \in Aint. Proof. by rewrite Aint_Cint. Qed. Lemma Aint0 : 0 \in Aint. Proof. exact: Aint_int 0. Qed. Lemma Aint1 : 1 \in Aint. Proof. exact: Aint_int 1. Qed. #[global] Hint Resolve Aint0 Aint1 : core. Lemma Aint_unity_root n x : (n > 0)%N -> n.-unity_root x -> x \in Aint. Proof. move=> n_gt0 xn1; apply: root_monic_Aint xn1 (monicXnsubC _ n_gt0) _. by apply/polyOverP=> i; rewrite coefB coefC -mulrb coefXn /= rpredB ?rpred_nat. Qed. Lemma Aint_prim_root n z : n.-primitive_root z -> z \in Aint. Proof. move=> pr_z; apply/(Aint_unity_root (prim_order_gt0 pr_z))/unity_rootP. exact: prim_expr_order. Qed. Lemma Aint_Cnat : {subset Num.nat <= Aint}. Proof. by move=> z /intr_nat/Aint_Cint. Qed. (* This is Isaacs, Lemma (3.3) *) Lemma Aint_subring_exists (X : seq algC) : {subset X <= Aint} -> {S : pred algC & (*a*) subring_closed S /\ (*b*) {subset X <= S} & (*c*) {Y : {n : nat & n.-tuple algC} & {subset tagged Y <= S} & forall x, reflect (inIntSpan (tagged Y) x) (x \in S)}}. Proof. move=> AZ_X; pose m := (size X).+1. pose n (i : 'I_m) := (size (minCpoly X`_i)).-2; pose N := (\max_i n i).+1. pose IY := family (fun i => [pred e : 'I_N | e <= n i]%N). have IY_0: 0 \in IY by apply/familyP=> // i; rewrite ffunE. pose inIY := enum_rank_in IY_0. pose Y := [seq \prod_(i < m) X`_i ^+ (f : 'I_N ^ m) i | f in IY]. have S_P := Cint_spanP [tuple of Y]; set S := Cint_span _ in S_P. have sYS: {subset Y <= S} by apply: mem_Cint_span. have S_1: 1 \in S. by apply/sYS/imageP; exists 0 => //; rewrite big1 // => i; rewrite ffunE. have SmulX (i : 'I_m): {in S, forall x, x * X`_i \in S}. move=> _ /S_P[x ->]; rewrite mulr_suml rpred_sum // => j _. rewrite mulrzAl rpredMz {x}// nth_image mulrC (bigD1 i) //= mulrA -exprS. move: {j}(enum_val j) (familyP (enum_valP j)) => f fP. have:= fP i; rewrite inE /= leq_eqVlt => /predU1P[-> | fi_ltn]; last first. apply/sYS/imageP; have fiK: (inord (f i).+1 : 'I_N) = (f i).+1 :> nat. by rewrite inordK // ltnS (bigmax_sup i). exists (finfun [eta f with i |-> inord (f i).+1]). apply/familyP=> i1; rewrite inE ffunE /= fun_if fiK. by case: eqP => [-> // | _]; apply: fP. rewrite (bigD1 i isT) ffunE /= eqxx fiK; congr (_ * _). by apply: eq_bigr => i1 /[!ffunE]/= /negPf->. have [/monicP ] := (minCpoly_monic X`_i, root_minCpoly X`_i). rewrite /root horner_coef lead_coefE -(subnKC (size_minCpoly _)) subn2. rewrite big_ord_recr /= addrC addr_eq0 => ->; rewrite mul1r => /eqP->. have /floorpP[p Dp]: X`_i \in Aint. by have [/(nth_default 0)-> | /(mem_nth 0)/AZ_X] := leqP (size X) i. rewrite -/(n i) Dp mulNr rpredN // mulr_suml rpred_sum // => [[e le_e]] /= _. rewrite coef_map -mulrA mulrzl rpredMz ?sYS //; apply/imageP. have eK: (inord e : 'I_N) = e :> nat by rewrite inordK // ltnS (bigmax_sup i). exists (finfun [eta f with i |-> inord e]). apply/familyP=> i1; rewrite inE ffunE /= fun_if eK. by case: eqP => [-> // | _]; apply: fP. rewrite (bigD1 i isT) ffunE /= eqxx eK; congr (_ * _). by apply: eq_bigr => i1 /[!ffunE] /= /negPf->. exists S; last by exists (Tagged (fun n => n.-tuple _) [tuple of Y]). split=> [|x Xx]; last first. by rewrite -[x]mul1r -(nth_index 0 Xx) (SmulX (Ordinal _)) // ltnS index_size. split=> // x y Sx Sy; first by rewrite rpredB. case/S_P: Sy => {y}[y ->]; rewrite mulr_sumr rpred_sum //= => j. rewrite mulrzAr rpredMz {y}// nth_image; move: {j}(enum_val j) => f. elim/big_rec: _ => [|i y _ IHy] in x Sx *; first by rewrite mulr1. rewrite mulrA {y}IHy //. elim: {f}(f i : nat) => [|e IHe] in x Sx *; first by rewrite mulr1. by rewrite exprS mulrA IHe // SmulX. Qed. Section AlgIntSubring. (* This is Isaacs, Theorem (3.4). *) Theorem fin_Csubring_Aint S n (Y : n.-tuple algC) : mulr_closed S -> (forall x, reflect (inIntSpan Y x) (x \in S)) -> {subset S <= Aint}. Proof. move=> mulS. pose Sm := GRing.isMulClosed.Build _ _ mulS. pose SC : mulrClosed _ := HB.pack S Sm. have ZP_C c: (ZtoC c)%:P \is a polyOver Num.int_num_subdef. by rewrite raddfMz rpred_int. move=> S_P x Sx; pose v := \row_(i < n) Y`_i. have [v0 | nz_v] := eqVneq v 0. case/S_P: Sx => {}x ->; rewrite big1 ?isAlgInt0 // => i _. by have /rowP/(_ i)/[!mxE] -> := v0; rewrite mul0rz. have sYS (i : 'I_n): x * Y`_i \in SC. by rewrite rpredM //; apply/S_P/Cint_spanP/mem_Cint_span/memt_nth. pose A := \matrix_(i, j < n) sval (sig_eqW (S_P _ (sYS j))) i. pose p := char_poly (map_mx ZtoC A). have: p \is a polyOver Num.int_num_subdef. rewrite rpred_sum // => s _; rewrite rpredMsign rpred_prod // => j _. by rewrite !mxE /= rpredB ?rpredMn ?polyOverX. apply: root_monic_Aint (char_poly_monic _). rewrite -eigenvalue_root_char; apply/eigenvalueP; exists v => //. apply/rowP=> j; case dAj: (sig_eqW (S_P _ (sYS j))) => [a DxY]. by rewrite !mxE DxY; apply: eq_bigr => i _; rewrite !mxE dAj /= mulrzr. Qed. (* This is Isaacs, Corollary (3.5). *) Corollary Aint_subring : subring_closed Aint. Proof. suff rAZ: {in Aint &, forall x y, (x - y \in Aint) * (x * y \in Aint)}. by split=> // x y AZx AZy; rewrite rAZ. move=> x y AZx AZy. have [|S [ringS] ] := @Aint_subring_exists [:: x; y]; first exact/allP/and3P. move=> /allP/and3P[Sx Sy _] [Y _ genYS]. have AZ_S := fin_Csubring_Aint ringS genYS. by have [_ S_B S_M] := ringS; rewrite !AZ_S ?S_B ?S_M. Qed. HB.instance Definition _ := GRing.isSubringClosed.Build _ Aint Aint_subring. End AlgIntSubring. Lemma Aint_aut (nu : {rmorphism algC -> algC}) x : (nu x \in Aint) = (x \in Aint). Proof. by rewrite !unfold_in minCpoly_aut. Qed. Definition dvdA (e : Algebraics.divisor) : {pred algC} := fun z => if e == 0 then z == 0 else z / e \in Aint. Delimit Scope algC_scope with A. Delimit Scope algC_expanded_scope with Ax. Notation "e %| x" := (x \in dvdA e) : algC_expanded_scope. Notation "e %| x" := (@in_mem Algebraics.divisor x (mem (dvdA e))) : algC_scope. Fact dvdA_zmod_closed e : zmod_closed (dvdA e). Proof. split=> [|x y]; first by rewrite unfold_in mul0r eqxx rpred0 ?if_same. rewrite ![(e %| _)%A]unfold_in. case: ifP => [_ x0 /eqP-> | _]; first by rewrite subr0. by rewrite mulrBl; apply: rpredB. Qed. HB.instance Definition _ e := GRing.isZmodClosed.Build _ (dvdA e) (dvdA_zmod_closed e). Definition eqAmod (e x y : Algebraics.divisor) := (e %| x - y)%A. Notation "x == y %[mod e ]" := (eqAmod e x y) : algC_scope. Notation "x != y %[mod e ]" := (~~ (eqAmod e x y)) : algC_scope. Lemma eqAmod_refl e x : (x == x %[mod e])%A. Proof. by rewrite /eqAmod subrr rpred0. Qed. #[global] Hint Resolve eqAmod_refl : core. Lemma eqAmod_sym e x y : ((x == y %[mod e]) = (y == x %[mod e]))%A. Proof. by rewrite /eqAmod -opprB rpredN. Qed. Lemma eqAmod_trans e y x z : (x == y %[mod e] -> y == z %[mod e] -> x == z %[mod e])%A. Proof. by move=> Exy Eyz; rewrite /eqAmod -[x](subrK y) -[_ - z]addrA rpredD. Qed. Lemma eqAmod_transl e x y z : (x == y %[mod e])%A -> (x == z %[mod e])%A = (y == z %[mod e])%A. Proof. by move/(sym_left_transitive (eqAmod_sym e) (@eqAmod_trans e)). Qed. Lemma eqAmod_transr e x y z : (x == y %[mod e])%A -> (z == x %[mod e])%A = (z == y %[mod e])%A. Proof. by move/(sym_right_transitive (eqAmod_sym e) (@eqAmod_trans e)). Qed. Lemma eqAmod0 e x : (x == 0 %[mod e])%A = (e %| x)%A. Proof. by rewrite /eqAmod subr0. Qed. Lemma eqAmodN e x y : (- x == y %[mod e])%A = (x == - y %[mod e])%A. Proof. by rewrite eqAmod_sym /eqAmod !opprK addrC. Qed. Lemma eqAmodDr e x y z : (y + x == z + x %[mod e])%A = (y == z %[mod e])%A. Proof. by rewrite /eqAmod addrAC opprD !addrA subrK. Qed. Lemma eqAmodDl e x y z : (x + y == x + z %[mod e])%A = (y == z %[mod e])%A. Proof. by rewrite !(addrC x) eqAmodDr. Qed. Lemma eqAmodD e x1 x2 y1 y2 : (x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 + y1 == x2 + y2 %[mod e])%A. Proof. by rewrite -(eqAmodDl e x2 y1) -(eqAmodDr e y1); apply: eqAmod_trans. Qed. Lemma eqAmodm0 e : (e == 0 %[mod e])%A. Proof. by rewrite /eqAmod subr0 unfold_in; case: ifPn => // /divff->. Qed. #[global] Hint Resolve eqAmodm0 : core. Lemma eqAmodMr e : {in Aint, forall z x y, x == y %[mod e] -> x * z == y * z %[mod e]}%A. Proof. move=> z Zz x y. rewrite /eqAmod -mulrBl ![(e %| _)%A]unfold_in mulf_eq0 mulrAC. by case: ifP => [_ -> // | _ Exy]; apply: rpredM. Qed. Lemma eqAmodMl e : {in Aint, forall z x y, x == y %[mod e] -> z * x == z * y %[mod e]}%A. Proof. by move=> z Zz x y Exy; rewrite !(mulrC z) eqAmodMr. Qed. Lemma eqAmodMl0 e : {in Aint, forall x, x * e == 0 %[mod e]}%A. Proof. by move=> x Zx; rewrite -(mulr0 x) eqAmodMl. Qed. Lemma eqAmodMr0 e : {in Aint, forall x, e * x == 0 %[mod e]}%A. Proof. by move=> x Zx; rewrite /= mulrC eqAmodMl0. Qed. Lemma eqAmod_addl_mul e : {in Aint, forall x y, x * e + y == y %[mod e]}%A. Proof. by move=> x Zx y; rewrite -{2}[y]add0r eqAmodDr eqAmodMl0. Qed. Lemma eqAmodM e : {in Aint &, forall x1 y2 x2 y1, x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 * y1 == x2 * y2 %[mod e]}%A. Proof. move=> x1 y2 Zx1 Zy2 x2 y1 eq_x /(eqAmodMl Zx1)/eqAmod_trans-> //. exact: eqAmodMr. Qed. Lemma eqAmod_rat : {in Crat & &, forall e m n, (m == n %[mod e])%A = (m == n %[mod e])%C}. Proof. move=> e m n Qe Qm Qn; rewrite /eqCmod unfold_in /eqAmod unfold_in. case: ifPn => // nz_e; apply/idP/idP=> [/Cint_rat_Aint | /Aint_Cint] -> //. by rewrite rpred_div ?rpredB. Qed. Lemma eqAmod0_rat : {in Crat &, forall e n, (n == 0 %[mod e])%A = (e %| n)%C}. Proof. by move=> e n Qe Qn; rewrite /= eqAmod_rat /eqCmod ?subr0 ?Crat0. Qed. Lemma eqAmod_nat (e m n : nat) : (m == n %[mod e])%A = (m == n %[mod e])%N. Proof. by rewrite eqAmod_rat ?rpred_nat // eqCmod_nat. Qed. Lemma eqAmod0_nat (e m : nat) : (m == 0 %[mod e])%A = (e %| m)%N. Proof. by rewrite eqAmod0_rat ?rpred_nat // dvdC_nat. Qed. (* Multiplicative order. *) Definition orderC x := let p := minCpoly x in oapp val 0 [pick n : 'I_(2 * size p ^ 2) | p == intrp 'Phi_n]. Notation "#[ x ]" := (orderC x) : C_scope. Lemma exp_orderC x : x ^+ #[x]%C = 1. Proof. rewrite /orderC; case: pickP => //= [] [n _] /= /eqP Dp. have n_gt0: (0 < n)%N. rewrite lt0n; apply: contraTneq (size_minCpoly x) => n0. by rewrite Dp n0 Cyclotomic0 rmorph1 size_poly1. have [z prim_z] := C_prim_root_exists n_gt0. rewrite prim_expr_order // -(root_cyclotomic prim_z). by rewrite -Cintr_Cyclotomic // -Dp root_minCpoly. Qed. Lemma dvdn_orderC x n : (#[x]%C %| n)%N = (x ^+ n == 1). Proof. apply/idP/eqP=> [|x_n_1]; first by apply: expr_dvd; apply: exp_orderC. have [-> | n_gt0] := posnP n; first by rewrite dvdn0. have [m prim_x m_dv_n] := prim_order_exists n_gt0 x_n_1. have{n_gt0} m_gt0 := dvdn_gt0 n_gt0 m_dv_n; congr (_ %| n)%N: m_dv_n. pose p := minCpoly x; have Dp: p = cyclotomic x m := minCpoly_cyclotomic prim_x. rewrite /orderC; case: pickP => /= [k /eqP Dp_k | no_k]; last first. suffices lt_m_2p: (m < 2 * size p ^ 2)%N. have /eqP[] := no_k (Ordinal lt_m_2p). by rewrite /= -/p Dp -Cintr_Cyclotomic. rewrite Dp size_cyclotomic (sqrnD 1) addnAC mulnDr -add1n leq_add //. suffices: (m <= \prod_(q <- primes m | q == 2) q * totient m ^ 2)%N. have [m_even | m_odd] := boolP (2%N \in primes m). by rewrite -big_filter filter_pred1_uniq ?primes_uniq // big_seq1. by rewrite big_hasC ?has_pred1 // => /leq_trans-> //; apply: leq_addl. rewrite big_mkcond totientE // -mulnn -!big_split /=. rewrite {1}[m]prod_prime_decomp // prime_decompE big_map /= !big_seq. elim/big_ind2: _ => // [n1 m1 n2 m2 | q]; first exact: leq_mul. rewrite mem_primes => /and3P[q_pr _ q_dv_m]. rewrite lognE q_pr m_gt0 q_dv_m /=; move: (logn q _) => k. rewrite !mulnA expnS leq_mul //. case: (ltngtP q 2) (prime_gt1 q_pr) => // [q_gt2|->] _. rewrite mul1n mulnAC mulnn -{1}[q]muln1 leq_mul ?expn_gt0 ?prime_gt0 //. by rewrite -(subnKC q_gt2) (ltn_exp2l 1). by rewrite !muln1 -expnS (ltn_exp2l 0). have k_prim_x: k.-primitive_root x. have k_gt0: (0 < k)%N. rewrite lt0n; apply: contraTneq (size_minCpoly x) => k0. by rewrite Dp_k k0 Cyclotomic0 rmorph1 size_poly1. have [z prim_z] := C_prim_root_exists k_gt0. rewrite -(root_cyclotomic prim_z) -Cintr_Cyclotomic //. by rewrite -Dp_k root_minCpoly. apply/eqP; rewrite eqn_dvd !(@prim_order_dvd _ _ x) //. by rewrite !prim_expr_order ?eqxx. Qed.
mxpoly.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice seq. From mathcomp Require Import div fintype tuple finfun bigop fingroup perm. From mathcomp Require Import ssralg zmodp matrix mxalgebra poly polydiv. (******************************************************************************) (* This file provides basic support for formal computation with matrices, *) (* mainly results combining matrices and univariate polynomials, such as the *) (* Cayley-Hamilton theorem; it also contains an extension of the first order *) (* representation of algebra introduced in ssralg (GRing.term/formula). *) (* rVpoly v == the little-endian decoding of the row vector v as a *) (* polynomial p = \sum_i (v 0 i)%:P * 'X^i. *) (* poly_rV p == the partial inverse to rVpoly, for polynomials of degree *) (* less than d to 'rV_d (d is inferred from the context). *) (* Sylvester_mx p q == the Sylvester matrix of p and q. *) (* resultant p q == the resultant of p and q, i.e., \det (Sylvester_mx p q). *) (* horner_mx A == the morphism from {poly R} to 'M_n (n of the form n'.+1) *) (* mapping a (scalar) polynomial p to the value of its *) (* scalar matrix interpretation at A (this is an instance of *) (* the generic horner_morph construct defined in poly). *) (* powers_mx A d == the d x (n ^ 2) matrix whose rows are the mxvec encodings *) (* of the first d powers of A (n of the form n'.+1). Thus, *) (* vec_mx (v *m powers_mx A d) = horner_mx A (rVpoly v). *) (* char_poly A == the characteristic polynomial of A. *) (* char_poly_mx A == a matrix whose determinant is char_poly A. *) (* companionmx p == a matrix whose char_poly is p *) (* mxminpoly A == the minimal polynomial of A, i.e., the smallest monic *) (* polynomial that annihilates A (A must be nontrivial). *) (* degree_mxminpoly A == the (positive) degree of mxminpoly A. *) (* mx_inv_horner A == the inverse of horner_mx A for polynomials of degree *) (* smaller than degree_mxminpoly A. *) (* kermxpoly g p == the kernel of p(g) *) (* geigenspace g a == the generalized eigenspace of g for eigenvalue a *) (* := kermxpoly g ('X ^ n - a%:P) where g : 'M_n *) (* eigenpoly g p <=> p is an eigen polynomial for g, i.e. kermxpoly g p != 0 *) (* integralOver RtoK u <-> u is in the integral closure of the image of R *) (* under RtoK : R -> K, i.e. u is a root of the image of a *) (* monic polynomial in R. *) (* algebraicOver FtoE u <-> u : E is algebraic over E; it is a root of the *) (* image of a nonzero polynomial under FtoE; as F must be a *) (* fieldType, this is equivalent to integralOver FtoE u. *) (* integralRange RtoK <-> the integral closure of the image of R contains *) (* all of K (:= forall u, integralOver RtoK u). *) (* This toolkit for building formal matrix expressions is packaged in the *) (* MatrixFormula submodule, and comprises the following: *) (* eval_mx e == GRing.eval lifted to matrices (:= map_mx (GRing.eval e)). *) (* mx_term A == GRing.Const lifted to matrices. *) (* mulmx_term A B == the formal product of two matrices of terms. *) (* mxrank_form m A == a GRing.formula asserting that the interpretation of *) (* the term matrix A has rank m. *) (* submx_form A B == a GRing.formula asserting that the row space of the *) (* interpretation of the term matrix A is included in the *) (* row space of the interpretation of B. *) (* seq_of_rV v == the seq corresponding to a row vector. *) (* row_env e == the flattening of a tensored environment e : seq 'rV_d. *) (* row_var F d k == the term vector of width d such that for e : seq 'rV[F]_d *) (* we have eval e 'X_k = eval_mx (row_env e) (row_var d k). *) (* conjmx V f := V *m f *m pinvmx V *) (* == the conjugation of f by V, i.e. "the" matrix of f *) (* in the basis of row vectors of V. *) (* Although this makes sense only when f stabilizes V, *) (* the definition can be stated more generally. *) (* restrictmx V := conjmx (row_base V) *) (* A ~_P {in S'} == where P is a base change matrix, A is a matrix, and S *) (* is a boolean predicate representing a set of matrices, *) (* this states that conjmx P A is in S, *) (* which means A is similar to a matrix in S. *) (* From the latter, we derive several related notions: *) (* A ~_P B := A ~_P {in pred1 B} *) (* A is similar to B, with base change matrix P *) (* A ~_{in S} B := exists P, P \in S /\ A ~_P B *) (* == A is similar to B, with a base change matrix in S *) (* A ~_{in S} {in S'} := exists P, P \in S /\ A ~_P {in S'} *) (* == A is similar to a matrix in the class S', *) (* with a base change matrix in S *) (* all_simmx_in S As S' == all the matrices in the sequence As are *) (* similar to some matrix in the predicate S', *) (* with a base change matrix in S. *) (* *) (* We also specialize the class S' to diagonalizability: *) (* diagonalizable_for P A := A ~_P {in is_diag_mx}. *) (* diagonalizable_in S A := A ~_{in S} {in is_diag_mx}. *) (* diagonalizable A := diagonalizable_in unitmx A. *) (* codiagonalizable_in S As := all_simmx_in S As is_diag_mx. *) (* codiagonalizable As := codiagonalizable_in unitmx As. *) (* *) (* The main results in diagnonalization theory are: *) (* - diagonalizablePeigen: *) (* a matrix is diagonalizable iff there is a sequence *) (* of scalars r, such that the sum of the associated *) (* eigenspaces is full. *) (* - diagonalizableP: *) (* a matrix is diagonalizable iff its minimal polynomial *) (* divides a split polynomial with simple roots. *) (* - codiagonalizableP: *) (* a sequence of matrices are diagonalizable in the same basis *) (* iff they are all diagonalizable and commute pairwize. *) (* *) (* Naming conventions: *) (* - p, q are polynomials *) (* - A, B, C are matrices *) (* - f, g are matrices that are viewed as linear maps *) (* - V, W are matrices that are viewed as subspaces *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Monoid.Theory. Local Open Scope ring_scope. Import Pdiv.Idomain. (* Row vector <-> bounded degree polynomial bijection *) Section RowPoly. Variables (R : nzRingType) (d : nat). Implicit Types u v : 'rV[R]_d. Implicit Types p q : {poly R}. Definition rVpoly v := \poly_(k < d) (if insub k is Some i then v 0 i else 0). Definition poly_rV p := \row_(i < d) p`_i. Lemma coef_rVpoly v k : (rVpoly v)`_k = if insub k is Some i then v 0 i else 0. Proof. by rewrite coef_poly; case: insubP => [i ->|]; rewrite ?if_same. Qed. Lemma coef_rVpoly_ord v (i : 'I_d) : (rVpoly v)`_i = v 0 i. Proof. by rewrite coef_rVpoly valK. Qed. Lemma rVpoly_delta i : rVpoly (delta_mx 0 i) = 'X^i. Proof. apply/polyP=> j; rewrite coef_rVpoly coefXn. case: insubP => [k _ <- | j_ge_d]; first by rewrite mxE. by case: eqP j_ge_d => // ->; rewrite ltn_ord. Qed. Lemma rVpolyK : cancel rVpoly poly_rV. Proof. by move=> u; apply/rowP=> i; rewrite mxE coef_rVpoly_ord. Qed. Lemma poly_rV_K p : size p <= d -> rVpoly (poly_rV p) = p. Proof. move=> le_p_d; apply/polyP=> k; rewrite coef_rVpoly. case: insubP => [i _ <- | ]; first by rewrite mxE. by rewrite -ltnNge => le_d_l; rewrite nth_default ?(leq_trans le_p_d). Qed. Lemma poly_rV_is_linear : linear poly_rV. Proof. by move=> a p q; apply/rowP=> i; rewrite !mxE coefD coefZ. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} 'rV_d _ poly_rV (GRing.semilinear_linear poly_rV_is_linear). Lemma rVpoly_is_linear : linear rVpoly. Proof. move=> a u v; apply/polyP=> k; rewrite coefD coefZ !coef_rVpoly. by case: insubP => [i _ _ | _]; rewrite ?mxE // mulr0 addr0. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R 'rV_d {poly R} _ rVpoly (GRing.semilinear_linear rVpoly_is_linear). End RowPoly. Prenex Implicits rVpoly rVpolyK. Arguments poly_rV {R d}. Arguments poly_rV_K {R d} [p] le_p_d. Section Resultant. Variables (R : nzRingType) (p q : {poly R}). Let dS := ((size q).-1 + (size p).-1)%N. Local Notation band r := (lin1_mx (poly_rV \o r \o* rVpoly)). Definition Sylvester_mx : 'M[R]_dS := col_mx (band p) (band q). Lemma Sylvester_mxE (i j : 'I_dS) : let S_ r k := r`_(j - k) *+ (k <= j) in Sylvester_mx i j = match split i with inl k => S_ p k | inr k => S_ q k end. Proof. move=> S_ /[1!mxE]; case: {i}(split i) => i /[!mxE]/=; by rewrite rVpoly_delta coefXnM ltnNge if_neg -mulrb. Qed. Definition resultant := \det Sylvester_mx. End Resultant. Prenex Implicits Sylvester_mx resultant. Lemma resultant_in_ideal (R : comNzRingType) (p q : {poly R}) : size p > 1 -> size q > 1 -> {uv : {poly R} * {poly R} | size uv.1 < size q /\ size uv.2 < size p & (resultant p q)%:P = uv.1 * p + uv.2 * q}. Proof. move=> p_nc q_nc; pose dp := (size p).-1; pose dq := (size q).-1. pose S := Sylvester_mx p q; pose dS := (dq + dp)%N. have dS_gt0: dS > 0 by rewrite /dS /dq -(subnKC q_nc). pose j0 := Ordinal dS_gt0. pose Ss0 := col_mx (p *: \col_(i < dq) 'X^i) (q *: \col_(i < dp) 'X^i). pose Ss := \matrix_(i, j) (if j == j0 then Ss0 i 0 else (S i j)%:P). pose u ds s := \sum_(i < ds) cofactor Ss (s i) j0 * 'X^i. exists (u _ (lshift dp), u _ ((rshift dq) _)). suffices sz_u ds s: ds > 1 -> size (u ds.-1 s) < ds by rewrite !sz_u. move/ltn_predK=> {2}<-; apply: leq_trans (size_sum _ _ _) _. apply/bigmax_leqP=> i _. have ->: cofactor Ss (s i) j0 = (cofactor S (s i) j0)%:P. rewrite rmorphM /= rmorph_sign -det_map_mx; congr (_ * \det _). by apply/matrixP=> i' j'; rewrite !mxE. apply: leq_trans (size_polyMleq _ _) (leq_trans _ (valP i)). by rewrite size_polyC size_polyXn addnS /= -add1n leq_add2r leq_b1. transitivity (\det Ss); last first. rewrite (expand_det_col Ss j0) big_split_ord !big_distrl /=. by congr (_ + _); apply: eq_bigr => i _; rewrite mxE eqxx (col_mxEu, col_mxEd) !mxE mulrC mulrA mulrAC. pose S_ j1 := map_mx polyC (\matrix_(i, j) S i (if j == j0 then j1 else j)). pose Ss0_ i dj := \poly_(j < dj) S i (insubd j0 j). pose Ss_ dj := \matrix_(i, j) (if j == j0 then Ss0_ i dj else (S i j)%:P). have{Ss u} ->: Ss = Ss_ dS. apply/matrixP=> i j; rewrite mxE [in RHS]mxE; case: (j == j0) => {j}//. apply/polyP=> k; rewrite coef_poly Sylvester_mxE mxE. have [k_ge_dS | k_lt_dS] := leqP dS k. case: (split i) => {}i; rewrite !mxE coefMXn; case: ifP => // /negbT; rewrite -ltnNge ltnS => hi. apply: (leq_sizeP _ _ (leqnn (size p))); rewrite -(ltn_predK p_nc). by rewrite ltn_subRL (leq_trans _ k_ge_dS) // ltn_add2r. - apply: (leq_sizeP _ _ (leqnn (size q))); rewrite -(ltn_predK q_nc). by rewrite ltn_subRL (leq_trans _ k_ge_dS) // addnC ltn_add2l. by rewrite insubdK //; case: (split i) => {}i; rewrite !mxE coefMXn; case: leqP. case: (ubnPgeq dS) (dS_gt0); elim=> // dj IHj ltjS _; pose j1 := Ordinal ltjS. pose rj0T (A : 'M[{poly R}]_dS) := row j0 A^T. have: rj0T (Ss_ dj.+1) = 'X^dj *: rj0T (S_ j1) + 1 *: rj0T (Ss_ dj). apply/rowP=> i; apply/polyP=> k; rewrite scale1r !(Sylvester_mxE, mxE) eqxx. rewrite coefD coefXnM coefC !coef_poly ltnS subn_eq0 ltn_neqAle andbC. have [k_le_dj | k_gt_dj] /= := leqP k dj; last by rewrite addr0. rewrite Sylvester_mxE insubdK; last exact: leq_ltn_trans (ltjS). by have [->|] := eqP; rewrite (addr0, add0r). rewrite -det_tr => /determinant_multilinear->; try by apply/matrixP=> i j; rewrite !mxE lift_eqF. have [dj0 | dj_gt0] := posnP dj; rewrite ?dj0 !mul1r. rewrite !det_tr det_map_mx addrC (expand_det_col _ j0) big1 => [|i _]. rewrite add0r; congr (\det _)%:P. apply/matrixP=> i j; rewrite [in RHS]mxE; case: eqP => // ->. by congr (S i _); apply: val_inj. by rewrite mxE /= [Ss0_ _ _]poly_def big_ord0 mul0r. have /determinant_alternate->: j1 != j0 by rewrite -val_eqE -lt0n. by rewrite mulr0 add0r det_tr IHj // ltnW. by move=> i; rewrite !mxE if_same. Qed. Lemma resultant_eq0 (R : idomainType) (p q : {poly R}) : (resultant p q == 0) = (size (gcdp p q) > 1). Proof. have dvdpp := dvdpp; set r := gcdp p q. pose dp := (size p).-1; pose dq := (size q).-1. have /andP[r_p r_q]: (r %| p) && (r %| q) by rewrite -dvdp_gcd. apply/det0P/idP=> [[uv nz_uv] | r_nonC]. have [p0 _ | p_nz] := eqVneq p 0. have: dq + dp > 0. rewrite lt0n; apply: contraNneq nz_uv => dqp0. by rewrite dqp0 in uv *; rewrite [uv]thinmx0. by rewrite /dp /dq /r p0 size_poly0 addn0 gcd0p -subn1 subn_gt0. do [rewrite -[uv]hsubmxK -{1}row_mx0 mul_row_col !mul_rV_lin1 /=] in nz_uv *. set u := rVpoly _; set v := rVpoly _; pose m := gcdp (v * p) (v * q). have lt_vp: size v < size p by rewrite (polySpred p_nz) ltnS size_poly. move/(congr1 rVpoly)/eqP; rewrite -linearD linear0 poly_rV_K; last first. rewrite (leq_trans (size_polyD _ _)) // geq_max. rewrite !(leq_trans (size_polyMleq _ _)) // -subn1 leq_subLR. by rewrite addnC addnA leq_add ?leqSpred ?size_poly. by rewrite addnCA leq_add ?leqSpred ?size_poly. rewrite addrC addr_eq0 => /eqP vq_up. have nz_v: v != 0. apply: contraNneq nz_uv => v0; apply/eqP. congr row_mx; apply: (can_inj rVpolyK); rewrite linear0 // -/u. by apply: contra_eq vq_up; rewrite v0 mul0r -addr_eq0 add0r => /mulf_neq0->. have r_nz: r != 0 := dvdpN0 r_p p_nz. have /dvdpP [[c w] /= nz_c wv]: v %| m by rewrite dvdp_gcd !dvdp_mulr. have m_wd d: m %| v * d -> w %| d. case/dvdpP=> [[k f]] /= nz_k /(congr1 ( *:%R c)). rewrite mulrC scalerA scalerAl scalerAr wv mulrA => /(mulIf nz_v)def_fw. by apply/dvdpP; exists (c * k, f); rewrite //= mulf_neq0. have w_r: w %| r by rewrite dvdp_gcd !m_wd ?dvdp_gcdl ?dvdp_gcdr. have w_nz: w != 0 := dvdpN0 w_r r_nz. have p_m: p %| m by rewrite dvdp_gcd vq_up -mulNr !dvdp_mull. rewrite (leq_trans _ (dvdp_leq r_nz w_r)) // -(ltn_add2l (size v)). rewrite addnC -ltn_subRL subn1 -size_mul // mulrC -wv size_scale //. rewrite (leq_trans lt_vp) // dvdp_leq // -size_poly_eq0. by rewrite -(size_scale _ nz_c) size_poly_eq0 wv mulf_neq0. have [[c p'] /= nz_c p'r] := dvdpP _ _ r_p. have [[k q'] /= nz_k q'r] := dvdpP _ _ r_q. have def_r := subnKC r_nonC; have r_nz: r != 0 by rewrite -size_poly_eq0 -def_r. have le_p'_dp: size p' <= dp. have [-> | nz_p'] := eqVneq p' 0; first by rewrite size_poly0. by rewrite /dp -(size_scale p nz_c) p'r size_mul // addnC -def_r leq_addl. have le_q'_dq: size q' <= dq. have [-> | nz_q'] := eqVneq q' 0; first by rewrite size_poly0. by rewrite /dq -(size_scale q nz_k) q'r size_mul // addnC -def_r leq_addl. exists (row_mx (- c *: poly_rV q') (k *: poly_rV p')); last first. rewrite mul_row_col scaleNr mulNmx !mul_rV_lin1 /= 2!linearZ /= !poly_rV_K //. by rewrite !scalerCA p'r q'r mulrCA addNr. apply: contraNneq r_nz; rewrite -row_mx0 => /eq_row_mx[/eqP]. rewrite scaleNr oppr_eq0 gcdp_eq0 -!size_poly_eq0 => /eqP q0 p0. rewrite -(size_scale p nz_c) -(size_scale (c *: p) nz_k) p'r. rewrite -(size_scale q nz_k) -(size_scale (k *: q) nz_c) q'r !scalerAl. rewrite -(poly_rV_K le_p'_dp) -(poly_rV_K le_q'_dq). by rewrite -2![_ *: rVpoly _]linearZ p0 q0 !linear0 mul0r size_poly0. Qed. Section HornerMx. Variables (R : comNzRingType) (n' : nat). Local Notation n := n'.+1. Implicit Types (A B : 'M[R]_n) (p q : {poly R}). Section OneMatrix. Variable A : 'M[R]_n. Definition horner_mx := horner_morph (comm_mx_scalar^~ A). HB.instance Definition _ := GRing.RMorphism.on horner_mx. Lemma horner_mx_C a : horner_mx a%:P = a%:M. Proof. exact: horner_morphC. Qed. Lemma horner_mx_X : horner_mx 'X = A. Proof. exact: horner_morphX. Qed. Lemma horner_mxZ : scalable horner_mx. Proof. move=> a p /=; rewrite -mul_polyC rmorphM /=. by rewrite horner_mx_C [_ * _]mul_scalar_mx. Qed. HB.instance Definition _ := GRing.isScalable.Build R _ _ *:%R horner_mx horner_mxZ. Definition powers_mx d := \matrix_(i < d) mxvec (A ^+ i). Lemma horner_rVpoly m (u : 'rV_m) : horner_mx (rVpoly u) = vec_mx (u *m powers_mx m). Proof. rewrite mulmx_sum_row [rVpoly u]poly_def 2!linear_sum; apply: eq_bigr => i _. by rewrite valK /= 2!linearZ rmorphXn/= horner_mx_X rowK mxvecK. Qed. End OneMatrix. Lemma horner_mx_diag (d : 'rV[R]_n) (p : {poly R}) : horner_mx (diag_mx d) p = diag_mx (map_mx (horner p) d). Proof. apply/matrixP => i j; rewrite !mxE. elim/poly_ind: p => [|p c ihp]; first by rewrite rmorph0 horner0 mxE mul0rn. rewrite !hornerE mulrnDl rmorphD rmorphM /= horner_mx_X horner_mx_C !mxE. rewrite (bigD1 j)//= ihp mxE eqxx mulr1n -mulrnAl big1 ?addr0. by have [->|_] := eqVneq; rewrite /= !(mulr1n, addr0, mul0r). by move=> k /negPf nkF; rewrite mxE nkF mulr0. Qed. Lemma comm_mx_horner A B p : comm_mx A B -> comm_mx A (horner_mx B p). Proof. move=> fg; apply: commr_horner => // i. by rewrite coef_map; apply/comm_scalar_mx. Qed. Lemma comm_horner_mx A B p : comm_mx A B -> comm_mx (horner_mx A p) B. Proof. by move=> ?; apply/comm_mx_sym/comm_mx_horner/comm_mx_sym. Qed. Lemma comm_horner_mx2 A p q : GRing.comm (horner_mx A p) (horner_mx A q). Proof. exact/comm_mx_horner/comm_horner_mx. Qed. End HornerMx. Lemma horner_mx_stable (K : fieldType) m n p (V : 'M[K]_(n.+1, m.+1)) (f : 'M_m.+1) : stablemx V f -> stablemx V (horner_mx f p). Proof. move=> V_fstab; elim/poly_ind: p => [|p c]; first by rewrite rmorph0 stablemx0. move=> fp_stable; rewrite rmorphD rmorphM/= horner_mx_X horner_mx_C. by rewrite stablemxD ?stablemxM ?fp_stable ?stablemxC. Qed. Prenex Implicits horner_mx powers_mx. Section CharPoly. Variables (R : nzRingType) (n : nat) (A : 'M[R]_n). Implicit Types p q : {poly R}. Definition char_poly_mx := 'X%:M - map_mx (@polyC R) A. Definition char_poly := \det char_poly_mx. Let diagA := [seq A i i | i <- index_enum _ & true]. Let size_diagA : size diagA = n. Proof. by rewrite -[n]card_ord size_map; have [e _ _ []] := big_enumP. Qed. Let split_diagA : exists2 q, \prod_(x <- diagA) ('X - x%:P) + q = char_poly & size q <= n.-1. Proof. rewrite [char_poly](bigD1 1%g) //=; set q := \sum_(s | _) _; exists q. congr (_ + _); rewrite odd_perm1 mul1r big_map big_filter /=. by apply: eq_bigr => i _; rewrite !mxE perm1 eqxx. apply: leq_trans {q}(size_sum _ _ _) _; apply/bigmax_leqP=> s nt_s. have{nt_s} [i nfix_i]: exists i, s i != i. apply/existsP; rewrite -negb_forall; apply: contra nt_s => s_1. by apply/eqP/permP=> i; apply/eqP; rewrite perm1 (forallP s_1). apply: leq_trans (_ : #|[pred j | s j == j]|.+1 <= n.-1). rewrite -sum1_card (@big_mkcond nat) /= size_Msign. apply: (big_ind2 (fun p m => size p <= m.+1)) => [| p mp q mq IHp IHq | j _]. - by rewrite size_poly1. - apply: leq_trans (size_polyMleq _ _) _. by rewrite -subn1 -addnS leq_subLR addnA leq_add. rewrite !mxE eq_sym !inE; case: (s j == j); first by rewrite polyseqXsubC. by rewrite sub0r size_polyN size_polyC leq_b1. rewrite -[n in n.-1]card_ord -(cardC (pred2 (s i) i)) card2 nfix_i !ltnS. apply/subset_leq_card/subsetP=> j /(_ =P j) fix_j. rewrite !inE -{1}fix_j (inj_eq perm_inj) orbb. by apply: contraNneq nfix_i => <-; rewrite fix_j. Qed. Lemma size_char_poly : size char_poly = n.+1. Proof. have [q <- lt_q_n] := split_diagA; have le_q_n := leq_trans lt_q_n (leq_pred n). by rewrite size_polyDl size_prod_XsubC size_diagA. Qed. Lemma char_poly_monic : char_poly \is monic. Proof. rewrite monicE -(monicP (monic_prod_XsubC diagA xpredT id)). rewrite !lead_coefE size_char_poly. have [q <- lt_q_n] := split_diagA; have le_q_n := leq_trans lt_q_n (leq_pred n). by rewrite size_prod_XsubC size_diagA coefD (nth_default 0 le_q_n) addr0. Qed. Lemma char_poly_trace : n > 0 -> char_poly`_n.-1 = - \tr A. Proof. move=> n_gt0; have [q <- lt_q_n] := split_diagA; set p := \prod_(x <- _) _. rewrite coefD {q lt_q_n}(nth_default 0 lt_q_n) addr0. have{n_gt0} ->: p`_n.-1 = ('X * p)`_n by rewrite coefXM eqn0Ngt n_gt0. have ->: \tr A = \sum_(x <- diagA) x by rewrite big_map big_filter. rewrite -size_diagA {}/p; elim: diagA => [|x d IHd]. by rewrite !big_nil mulr1 coefX oppr0. rewrite !big_cons coefXM mulrBl coefB IHd opprD addrC; congr (- _ + _). rewrite mul_polyC coefZ [size _]/= -(size_prod_XsubC _ id) -lead_coefE. by rewrite (monicP _) ?monic_prod_XsubC ?mulr1. Qed. Lemma char_poly_det : char_poly`_0 = (- 1) ^+ n * \det A. Proof. rewrite big_distrr coef_sum [0%N]lock /=; apply: eq_bigr => s _. rewrite -{1}rmorphN -rmorphXn mul_polyC coefZ /=. rewrite mulrA -exprD addnC exprD -mulrA -lock; congr (_ * _). transitivity (\prod_(i < n) - A i (s i)); last by rewrite prodrN card_ord. elim: (index_enum _) => [|i e IHe]; rewrite !(big_nil, big_cons) ?coef1 //. by rewrite coefM big_ord1 IHe !mxE coefB coefC coefMn coefX mul0rn sub0r. Qed. End CharPoly. Prenex Implicits char_poly_mx char_poly. Lemma mx_poly_ring_isom (R : nzRingType) n' (n := n'.+1) : exists phi : {rmorphism 'M[{poly R}]_n -> {poly 'M[R]_n}}, [/\ bijective phi, forall p, phi p%:M = map_poly scalar_mx p, forall A, phi (map_mx polyC A) = A%:P & forall A i j k, (phi A)`_k i j = (A i j)`_k]. Proof. set M_RX := 'M[{poly R}]_n; set MR_X := ({poly 'M[R]_n}). pose Msize (A : M_RX) := \max_i \max_j size (A i j). pose phi (A : M_RX) := \poly_(k < Msize A) \matrix_(i, j) (A i j)`_k. have coef_phi A i j k: (phi A)`_k i j = (A i j)`_k. rewrite coef_poly; case: (ltnP k _) => le_m_k; rewrite mxE // nth_default //. by apply: leq_trans (leq_trans (leq_bigmax i) le_m_k); apply: (leq_bigmax j). have phi_is_zmod_morphism : zmod_morphism phi. move=> A B; apply/polyP => k; apply/matrixP => i j. by rewrite !(coef_phi, mxE, coefD, coefN). have phi_is_monoid_morphism : monoid_morphism phi. split=> [|A B]; apply/polyP => k; apply/matrixP => i j. by rewrite coef_phi mxE coefMn !coefC; case: (k == _); rewrite ?mxE ?mul0rn. rewrite !coef_phi !mxE !coefM summxE coef_sum. pose F k1 k2 := (A i k1)`_k2 * (B k1 j)`_(k - k2). transitivity (\sum_k1 \sum_(k2 < k.+1) F k1 k2); rewrite {}/F. by apply: eq_bigr=> k1 _; rewrite coefM. rewrite exchange_big /=; apply: eq_bigr => k2 _. by rewrite mxE; apply: eq_bigr => k1 _; rewrite !coef_phi. have bij_phi: bijective phi. exists (fun P : MR_X => \matrix_(i, j) \poly_(k < size P) P`_k i j) => [A|P]. apply/matrixP=> i j; rewrite mxE; apply/polyP=> k. rewrite coef_poly -coef_phi. by case: leqP => // P_le_k; rewrite nth_default ?mxE. apply/polyP=> k; apply/matrixP=> i j; rewrite coef_phi mxE coef_poly. by case: leqP => // P_le_k; rewrite nth_default ?mxE. pose phiaM := GRing.isZmodMorphism.Build _ _ phi phi_is_zmod_morphism. pose phimM := GRing.isMonoidMorphism.Build _ _ phi phi_is_monoid_morphism. pose phiRM : {rmorphism _ -> _} := HB.pack phi phiaM phimM. exists phiRM; split=> // [p | A]; apply/polyP=> k; apply/matrixP=> i j. by rewrite coef_phi coef_map !mxE coefMn. by rewrite coef_phi !mxE !coefC; case k; last rewrite /= mxE. Qed. Theorem Cayley_Hamilton (R : comNzRingType) n' (A : 'M[R]_n'.+1) : horner_mx A (char_poly A) = 0. Proof. have [phi [_ phiZ phiC _]] := mx_poly_ring_isom R n'. apply/rootP/factor_theorem; rewrite -phiZ -mul_adj_mx rmorphM /=. by move: (phi _) => q; exists q; rewrite rmorphB phiC phiZ map_polyX. Qed. Lemma eigenvalue_root_char (F : fieldType) n (A : 'M[F]_n) a : eigenvalue A a = root (char_poly A) a. Proof. transitivity (\det (a%:M - A) == 0). apply/eigenvalueP/det0P=> [[v Av_av v_nz] | [v v_nz Av_av]]; exists v => //. by rewrite mulmxBr Av_av mul_mx_scalar subrr. by apply/eqP; rewrite -mul_mx_scalar eq_sym -subr_eq0 -mulmxBr Av_av. congr (_ == 0); rewrite horner_sum; apply: eq_bigr => s _. rewrite hornerM horner_exp !hornerE; congr (_ * _). rewrite (big_morph _ (fun p q => hornerM p q a) (hornerC 1 a)). by apply: eq_bigr => i _; rewrite !mxE !(hornerE, hornerMn). Qed. Lemma char_poly_trig {R : comNzRingType} n (A : 'M[R]_n) : is_trig_mx A -> char_poly A = \prod_(i < n) ('X - (A i i)%:P). Proof. move=> /is_trig_mxP Atrig; rewrite /char_poly det_trig. by apply: eq_bigr => i; rewrite !mxE eqxx. by apply/is_trig_mxP => i j lt_ij; rewrite !mxE -val_eqE ltn_eqF ?Atrig ?subrr. Qed. Definition companionmx {R : nzRingType} (p : seq R) (d := (size p).-1) := \matrix_(i < d, j < d) if (i == d.-1 :> nat) then - p`_j else (i.+1 == j :> nat)%:R. Lemma companionmxK {R : comNzRingType} (p : {poly R}) : p \is monic -> char_poly (companionmx p) = p. Proof. pose D n : 'M[{poly R}]_n := \matrix_(i, j) ('X *+ (i == j.+1 :> nat) - ((i == j)%:R)%:P). have detD n : \det (D n) = (-1) ^+ n. elim: n => [|n IHn]; first by rewrite det_mx00. rewrite (expand_det_row _ ord0) big_ord_recl !mxE /= sub0r. rewrite big1 ?addr0; last by move=> i _; rewrite !mxE /= subrr mul0r. rewrite /cofactor mul1r [X in \det X](_ : _ = D _) ?IHn ?exprS//. by apply/matrixP=> i j; rewrite !mxE /= /bump !add1n eqSS. elim/poly_ind: p => [|p c IHp]. by rewrite monicE lead_coef0 eq_sym oner_eq0. have [->|p_neq0] := eqVneq p 0. rewrite mul0r add0r monicE lead_coefC => /eqP->. by rewrite /companionmx /char_poly size_poly1 det_mx00. rewrite monicE lead_coefDl ?lead_coefMX => [p_monic|]; last first. rewrite size_polyC size_mulX ?polyX_eq0// ltnS. by rewrite (leq_trans (leq_b1 _)) ?size_poly_gt0. rewrite -[in RHS]IHp // /companionmx size_MXaddC (negPf p_neq0) /=. rewrite /char_poly polySpred //. have [->|spV1_gt0] := posnP (size p).-1. rewrite [X in \det X]mx11_scalar det_scalar1 !mxE ?eqxx det_mx00. by rewrite mul1r -horner_coef0 hornerMXaddC mulr0 add0r rmorphN opprK. rewrite (expand_det_col _ ord0) /= -[(size p).-1]prednK //. rewrite big_ord_recr big_ord_recl/= big1 ?add0r //=; last first. move=> i _; rewrite !mxE -val_eqE /= /bump leq0n add1n eqSS. by rewrite ltn_eqF ?subrr ?mul0r. rewrite !mxE ?subnn -horner_coef0 /= hornerMXaddC. rewrite !(eqxx, mulr0, add0r, addr0, subr0, rmorphN, opprK)/=. rewrite mulrC /cofactor; congr (_ * 'X + _). rewrite /cofactor -signr_odd oddD addbb mul1r; congr (\det _). apply/matrixP => i j; rewrite !mxE -val_eqE coefD coefMX coefC. by rewrite /= /bump /= !add1n !eqSS addr0. rewrite /cofactor [X in \det X](_ : _ = D _). by rewrite detD /= addn0 -signr_odd -signr_addb addbb mulr1. apply/matrixP=> i j; rewrite !mxE -!val_eqE /= /bump /=. by rewrite leqNgt ltn_ord add0n add1n [_ == _.-2.+1]ltn_eqF. Qed. Lemma mulmx_delta_companion (R : nzRingType) (p : seq R) (i: 'I_(size p).-1) (i_small : i.+1 < (size p).-1): delta_mx 0 i *m companionmx p = delta_mx 0 (Ordinal i_small) :> 'rV__. Proof. apply/rowP => j; rewrite !mxE (bigD1 i) //= ?(=^~val_eqE, mxE) /= eqxx mul1r. rewrite ltn_eqF ?big1 ?addr0 1?eq_sym //; last first. by rewrite -ltnS prednK // (leq_trans _ i_small). by move=> k /negPf ki_eqF; rewrite !mxE eqxx ki_eqF mul0r. Qed. Lemma row'_col'_char_poly_mx {R : nzRingType} m i (M : 'M[R]_m) : row' i (col' i (char_poly_mx M)) = char_poly_mx (row' i (col' i M)). Proof. by apply/matrixP => k l; rewrite !mxE (inj_eq lift_inj). Qed. Lemma char_block_diag_mx {R : nzRingType} m n (A : 'M[R]_m) (B : 'M[R]_n) : char_poly_mx (block_mx A 0 0 B) = block_mx (char_poly_mx A) 0 0 (char_poly_mx B). Proof. rewrite /char_poly_mx map_block_mx/= !map_mx0. by rewrite scalar_mx_block opp_block_mx add_block_mx !subr0. Qed. Section MinPoly. Variables (F : fieldType) (n' : nat). Local Notation n := n'.+1. Variable A : 'M[F]_n. Implicit Types p q : {poly F}. Fact degree_mxminpoly_proof : exists d, \rank (powers_mx A d.+1) <= d. Proof. by exists (n ^ 2)%N; rewrite rank_leq_col. Qed. Definition degree_mxminpoly := ex_minn degree_mxminpoly_proof. Local Notation d := degree_mxminpoly. Local Notation Ad := (powers_mx A d). Lemma mxminpoly_nonconstant : d > 0. Proof. rewrite /d; case: ex_minnP => -[] //; rewrite leqn0 mxrank_eq0; move/eqP. by move/row_matrixP/(_ 0)/eqP; rewrite rowK row0 mxvec_eq0 -mxrank_eq0 mxrank1. Qed. Lemma minpoly_mx1 : (1%:M \in Ad)%MS. Proof. by apply: (eq_row_sub (Ordinal mxminpoly_nonconstant)); rewrite rowK. Qed. Lemma minpoly_mx_free : row_free Ad. Proof. have:= mxminpoly_nonconstant; rewrite /d; case: ex_minnP => -[] // d' _ /(_ d'). by move/implyP; rewrite ltnn implybF -ltnS ltn_neqAle rank_leq_row andbT negbK. Qed. Lemma horner_mx_mem p : (horner_mx A p \in Ad)%MS. Proof. elim/poly_ind: p => [|p a IHp]; first by rewrite rmorph0 // linear0 sub0mx. rewrite rmorphD rmorphM /= horner_mx_C horner_mx_X. rewrite addrC -scalemx1 linearP /= -(mul_vec_lin (mulmxr A)). case/submxP: IHp => u ->{p}. have: (powers_mx A (1 + d) <= Ad)%MS. rewrite -(geq_leqif (mxrank_leqif_sup _)). by rewrite (eqnP minpoly_mx_free) /d; case: ex_minnP. rewrite addnC; apply/row_subP=> i. by apply: eq_row_sub (lshift 1 i) _; rewrite !rowK. apply: submx_trans; rewrite addmx_sub ?scalemx_sub //. by apply: (eq_row_sub 0); rewrite rowK. rewrite -mulmxA mulmx_sub {u}//; apply/row_subP=> i. rewrite row_mul rowK mul_vec_lin /= mulmxE -exprSr. by apply: (eq_row_sub (rshift 1 i)); rewrite rowK. Qed. Definition mx_inv_horner B := rVpoly (mxvec B *m pinvmx Ad). Lemma mx_inv_horner0 : mx_inv_horner 0 = 0. Proof. by rewrite /mx_inv_horner !(linear0, mul0mx). Qed. Lemma mx_inv_hornerK B : (B \in Ad)%MS -> horner_mx A (mx_inv_horner B) = B. Proof. by move=> sBAd; rewrite horner_rVpoly mulmxKpV ?mxvecK. Qed. Lemma minpoly_mxM B C : (B \in Ad -> C \in Ad -> B * C \in Ad)%MS. Proof. move=> AdB AdC; rewrite -(mx_inv_hornerK AdB) -(mx_inv_hornerK AdC). by rewrite -rmorphM ?horner_mx_mem. Qed. Lemma minpoly_mx_ring : mxring Ad. Proof. apply/andP; split; first exact/mulsmx_subP/minpoly_mxM. apply/mxring_idP; exists 1%:M; split=> *; rewrite ?mulmx1 ?mul1mx //. by rewrite -mxrank_eq0 mxrank1. exact: minpoly_mx1. Qed. Definition mxminpoly := 'X^d - mx_inv_horner (A ^+ d). Local Notation p_A := mxminpoly. Lemma size_mxminpoly : size p_A = d.+1. Proof. by rewrite size_polyDl ?size_polyXn // size_polyN ltnS size_poly. Qed. Lemma mxminpoly_monic : p_A \is monic. Proof. rewrite monicE /lead_coef size_mxminpoly coefB coefXn eqxx /=. by rewrite nth_default ?size_poly // subr0. Qed. Lemma size_mod_mxminpoly p : size (p %% p_A) <= d. Proof. by rewrite -ltnS -size_mxminpoly ltn_modp // -size_poly_eq0 size_mxminpoly. Qed. Lemma mx_root_minpoly : horner_mx A p_A = 0. Proof. rewrite rmorphB -{3}(horner_mx_X A) -rmorphXn /=. by rewrite mx_inv_hornerK ?subrr ?horner_mx_mem. Qed. Lemma horner_rVpolyK (u : 'rV_d) : mx_inv_horner (horner_mx A (rVpoly u)) = rVpoly u. Proof. congr rVpoly; rewrite horner_rVpoly vec_mxK. by apply: (row_free_inj minpoly_mx_free); rewrite mulmxKpV ?submxMl. Qed. Lemma horner_mxK p : mx_inv_horner (horner_mx A p) = p %% p_A. Proof. rewrite {1}(Pdiv.IdomainMonic.divp_eq mxminpoly_monic p) rmorphD rmorphM /=. rewrite mx_root_minpoly mulr0 add0r. by rewrite -(poly_rV_K (size_mod_mxminpoly _)) horner_rVpolyK. Qed. Lemma mxminpoly_min p : horner_mx A p = 0 -> p_A %| p. Proof. by move=> pA0; rewrite /dvdp -horner_mxK pA0 mx_inv_horner0. Qed. Lemma mxminpoly_minP p : reflect (horner_mx A p = 0) (p_A %| p). Proof. apply: (iffP idP); last exact: mxminpoly_min. by move=> /Pdiv.Field.dvdpP[q ->]; rewrite rmorphM/= mx_root_minpoly mulr0. Qed. Lemma dvd_mxminpoly p : (p_A %| p) = (horner_mx A p == 0). Proof. exact/mxminpoly_minP/eqP. Qed. Lemma horner_rVpoly_inj : injective (horner_mx A \o rVpoly : 'rV_d -> 'M_n). Proof. apply: can_inj (poly_rV \o mx_inv_horner) _ => u /=. by rewrite horner_rVpolyK rVpolyK. Qed. Lemma mxminpoly_linear_is_scalar : (d <= 1) = is_scalar_mx A. Proof. have scalP := has_non_scalar_mxP minpoly_mx1. rewrite leqNgt -(eqnP minpoly_mx_free); apply/scalP/idP=> [|[[B]]]. case scalA: (is_scalar_mx A); [by right | left]. by exists A; rewrite ?scalA // -{1}(horner_mx_X A) horner_mx_mem. move/mx_inv_hornerK=> <- nsB; case/is_scalar_mxP=> a defA; case/negP: nsB. move: {B}(_ B); apply: poly_ind => [|p c]. by rewrite rmorph0 ?mx0_is_scalar. rewrite rmorphD ?rmorphM /= horner_mx_X defA; case/is_scalar_mxP=> b ->. by rewrite -rmorphM horner_mx_C -rmorphD /= scalar_mx_is_scalar. Qed. Lemma mxminpoly_dvd_char : p_A %| char_poly A. Proof. exact/mxminpoly_min/Cayley_Hamilton. Qed. Lemma eigenvalue_root_min a : eigenvalue A a = root p_A a. Proof. apply/idP/idP=> Aa; last first. rewrite eigenvalue_root_char !root_factor_theorem in Aa *. exact: dvdp_trans Aa mxminpoly_dvd_char. have{Aa} [v Av_av v_nz] := eigenvalueP Aa. apply: contraR v_nz => pa_nz; rewrite -{pa_nz}(eqmx_eq0 (eqmx_scale _ pa_nz)). apply/eqP; rewrite -(mulmx0 _ v) -mx_root_minpoly. elim/poly_ind: p_A => [|p c IHp]. by rewrite rmorph0 horner0 scale0r mulmx0. rewrite !hornerE rmorphD rmorphM /= horner_mx_X horner_mx_C scalerDl. by rewrite -scalerA mulmxDr mul_mx_scalar mulmxA -IHp -scalemxAl Av_av. Qed. Lemma root_mxminpoly a : root p_A a = root (char_poly A) a. Proof. by rewrite -eigenvalue_root_min eigenvalue_root_char. Qed. End MinPoly. Lemma mxminpoly_diag {F : fieldType} {n} (d : 'rV[F]_n.+1) (u := undup [seq d 0 i | i <- enum 'I_n.+1]) : mxminpoly (diag_mx d) = \prod_(r <- u) ('X - r%:P). Proof. apply/eqP; rewrite -eqp_monic ?mxminpoly_monic ?monic_prod_XsubC// /eqp. rewrite mxminpoly_min/=; last first. rewrite horner_mx_diag; apply/matrixP => i j; rewrite !mxE horner_prod. case: (altP (i =P j)) => [->|neq_ij//]; rewrite mulr1n. rewrite (bigD1_seq (d 0 j)) ?undup_uniq ?mem_undup ?map_f// /=. by rewrite hornerD hornerN hornerX hornerC subrr mul0r. apply: uniq_roots_dvdp; last by rewrite uniq_rootsE undup_uniq. apply/allP => x; rewrite mem_undup root_mxminpoly char_poly_trig//. rewrite -(big_map _ predT (fun x => _ - x%:P)) root_prod_XsubC. by move=> /mapP[i _ ->]; apply/mapP; exists i; rewrite ?(mxE, eqxx). Qed. Prenex Implicits degree_mxminpoly mxminpoly mx_inv_horner. Arguments mx_inv_hornerK {F n' A} [B] AnB. Arguments horner_rVpoly_inj {F n' A} [u1 u2] eq_u12A : rename. (* Parametricity. *) Section MapRingMatrix. Variables (aR rR : nzRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx (GRing.RMorphism.sort f) A) : ring_scope. Local Notation fp := (map_poly (GRing.RMorphism.sort f)). Variables (d n : nat) (A : 'M[aR]_n). Lemma map_rVpoly (u : 'rV_d) : fp (rVpoly u) = rVpoly u^f. Proof. apply/polyP=> k; rewrite coef_map !coef_rVpoly. by case: (insub k) => [i|]; rewrite /= ?rmorph0 // mxE. Qed. Lemma map_poly_rV p : (poly_rV p)^f = poly_rV (fp p) :> 'rV_d. Proof. by apply/rowP=> j; rewrite !mxE coef_map. Qed. Lemma map_char_poly_mx : map_mx fp (char_poly_mx A) = char_poly_mx A^f. Proof. rewrite raddfB /= map_scalar_mx /= map_polyX; congr (_ - _). by apply/matrixP=> i j; rewrite !mxE map_polyC. Qed. Lemma map_char_poly : fp (char_poly A) = char_poly A^f. Proof. by rewrite -det_map_mx map_char_poly_mx. Qed. End MapRingMatrix. Section MapResultant. Lemma map_resultant (aR rR : nzRingType) (f : {rmorphism {poly aR} -> rR}) p q : f (lead_coef p) != 0 -> f (lead_coef q) != 0 -> f (resultant p q)= resultant (map_poly f p) (map_poly f q). Proof. move=> nz_fp nz_fq; rewrite /resultant /Sylvester_mx !size_map_poly_id0 //. rewrite -det_map_mx /= map_col_mx; congr (\det (col_mx _ _)); by apply: map_lin1_mx => v; rewrite map_poly_rV rmorphM /= map_rVpoly. Qed. End MapResultant. Section MapComRing. Variables (aR rR : comNzRingType) (f : {rmorphism aR -> rR}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Local Notation fp := (map_poly f). Variables (n' : nat) (A : 'M[aR]_n'.+1). Lemma map_powers_mx e : (powers_mx A e)^f = powers_mx A^f e. Proof. by apply/row_matrixP=> i; rewrite -map_row !rowK map_mxvec rmorphXn. Qed. Lemma map_horner_mx p : (horner_mx A p)^f = horner_mx A^f (fp p). Proof. rewrite -[p](poly_rV_K (leqnn _)) map_rVpoly. by rewrite !horner_rVpoly map_vec_mx map_mxM map_powers_mx. Qed. End MapComRing. Section MapField. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Local Notation "A ^f" := (map_mx f A) : ring_scope. Local Notation fp := (map_poly f). Variables (n' : nat) (A : 'M[aF]_n'.+1) (p : {poly aF}). Lemma map_mx_companion (e := congr1 predn (size_map_poly _ _)) : (companionmx p)^f = castmx (e, e) (companionmx (fp p)). Proof. apply/matrixP => i j; rewrite !(castmxE, mxE) /= (fun_if f). by rewrite rmorphN coef_map size_map_poly rmorph_nat. Qed. Lemma companion_map_poly (e := esym (congr1 predn (size_map_poly _ _))) : companionmx (fp p) = castmx (e, e) (companionmx p)^f. Proof. by rewrite map_mx_companion castmx_comp castmx_id. Qed. Lemma degree_mxminpoly_map : degree_mxminpoly A^f = degree_mxminpoly A. Proof. by apply: eq_ex_minn => e; rewrite -map_powers_mx mxrank_map. Qed. Lemma mxminpoly_map : mxminpoly A^f = fp (mxminpoly A). Proof. rewrite rmorphB; congr (_ - _). by rewrite /= map_polyXn degree_mxminpoly_map. rewrite degree_mxminpoly_map -rmorphXn /=. apply/polyP=> i; rewrite coef_map //= !coef_rVpoly degree_mxminpoly_map. case/insub: i => [i|]; last by rewrite rmorph0. by rewrite -map_powers_mx -map_pinvmx // -map_mxvec -map_mxM // mxE. Qed. Lemma map_mx_inv_horner u : fp (mx_inv_horner A u) = mx_inv_horner A^f u^f. Proof. rewrite map_rVpoly map_mxM map_mxvec map_pinvmx map_powers_mx. by rewrite /mx_inv_horner degree_mxminpoly_map. Qed. End MapField. Section KernelLemmas. Variable K : fieldType. (* convertible to kermx (horner_mx g p) when n = n.+1 *) Definition kermxpoly n (g : 'M_n) (p : {poly K}) : 'M_n := kermx ((if n is n.+1 then horner_mx^~ p : 'M_n.+1 -> 'M_n.+1 else \0) g). Lemma kermxpolyC n (g : 'M_n) c : c != 0 -> kermxpoly g c%:P = 0. Proof. move=> c_neq0; case: n => [|n] in g *; first by rewrite thinmx0. apply/eqP; rewrite /kermxpoly horner_mx_C kermx_eq0 row_free_unit. by rewrite -scalemx1 scaler_unit ?unitmx1// unitfE. Qed. Lemma kermxpoly1 n (g : 'M_n) : kermxpoly g 1 = 0. Proof. by rewrite kermxpolyC ?oner_eq0. Qed. Lemma kermxpolyX n (g : 'M_n) : kermxpoly g 'X = kermx g. Proof. case: n => [|n] in g *; first by rewrite !thinmx0. by rewrite /kermxpoly horner_mx_X. Qed. Lemma kermxpoly_min n (g : 'M[K]_n.+1) p : mxminpoly g %| p -> (kermxpoly g p :=: 1)%MS. Proof. by rewrite /kermxpoly => /mxminpoly_minP ->; apply: kermx0. Qed. Lemma comm_mx_stable_kermxpoly n (f g : 'M_n) (p : {poly K}) : comm_mx f g -> stablemx (kermxpoly f p) g. Proof. case: n => [|n] in f g *; first by rewrite !thinmx0. move=> fg; rewrite /kermxpoly; apply: comm_mx_stable_ker. by apply/comm_mx_sym/comm_mx_horner/comm_mx_sym. Qed. Lemma mxdirect_kermxpoly n (g : 'M_n) (p q : {poly K}) : coprimep p q -> (kermxpoly g p :&: kermxpoly g q = 0)%MS. Proof. case: n => [|n] in g *; first by rewrite thinmx0 ?cap0mx ?submx_refl. move=> /Bezout_eq1_coprimepP [[/= u v]]; rewrite mulrC [v * _]mulrC => cpq. apply/eqP/rowV0P => x. rewrite sub_capmx => /andP[/sub_kermxP xgp0 /sub_kermxP xgq0]. move: cpq => /(congr1 (mulmx x \o horner_mx g))/=. rewrite !(rmorphM, rmorphD, rmorph1, mulmx1, mulmxDr, mulmxA). by rewrite xgp0 xgq0 !mul0mx add0r. Qed. Lemma kermxpolyM n (g : 'M_n) (p q : {poly K}) : coprimep p q -> (kermxpoly g (p * q) :=: kermxpoly g p + kermxpoly g q)%MS. Proof. case: n => [|n] in g *; first by rewrite !thinmx0. move=> /Bezout_eq1_coprimepP [[/= u v]]; rewrite mulrC [v * _]mulrC => cpq. apply/eqmxP/andP; split; last first. apply/sub_kermxP/eqmx0P; rewrite !addsmxMr [in X in (_ + X)%MS]mulrC. by rewrite !rmorphM/= !mulmxA !mulmx_ker !mul0mx !addsmx0 submx_refl. move: cpq => /(congr1 (horner_mx g))/=; rewrite rmorph1 rmorphD/=. rewrite -[X in (X <= _)%MS]mulr1 => <-; rewrite mulrDr [p * u]mulrC addrC. rewrite addmx_sub_adds//; apply/sub_kermxP; rewrite mulmxE -mulrA -rmorphM. by rewrite mulrAC [q * p]mulrC rmorphM/= mulrA -!mulmxE mulmx_ker mul0mx. rewrite -[_ * _ * q]mulrA [u * _]mulrC. by rewrite rmorphM mulrA -!mulmxE mulmx_ker mul0mx. Qed. Lemma kermxpoly_prod n (g : 'M_n) (I : finType) (P : {pred I}) (p_ : I -> {poly K}) : {in P &, forall i j, j != i -> coprimep (p_ i) (p_ j)} -> (kermxpoly g (\prod_(i | P i) p_ i) :=: \sum_(i | P i) kermxpoly g (p_ i))%MS. Proof. move=> p_coprime; elim: index_enum (index_enum_uniq I). by rewrite !big_nil ?kermxpoly1 ?submx_refl//. move=> j js ihjs /= /andP[jNjs js_uniq]; apply/eqmxP. rewrite !big_cons; case: ifP => [Pj|PNj]; rewrite ?ihjs ?submx_refl//. suff cjjs: coprimep (p_ j) (\prod_(i <- js | P i) p_ i). by rewrite !kermxpolyM// !(adds_eqmx (eqmx_refl _) (ihjs _)) ?submx_refl. rewrite (@big_morph _ _ _ true andb) ?big_all_cond ?coprimep1//; last first. by move=> p q; rewrite coprimepMr. apply/allP => i i_js; apply/implyP => Pi; apply: p_coprime => //. by apply: contraNneq jNjs => <-. Qed. Lemma mxdirect_sum_kermx n (g : 'M_n) (I : finType) (P : {pred I}) (p_ : I -> {poly K}) : {in P &, forall i j, j != i -> coprimep (p_ i) (p_ j)} -> mxdirect (\sum_(i | P i) kermxpoly g (p_ i))%MS. Proof. move=> p_coprime; apply/mxdirect_sumsP => i Pi; apply/eqmx0P. have cpNi : {in [pred j | P j && (j != i)] &, forall j k : I, k != j -> coprimep (p_ j) (p_ k)}. by move=> j k /andP[Pj _] /andP[Pk _]; apply: p_coprime. rewrite -!(cap_eqmx (eqmx_refl _) (kermxpoly_prod g _))//. rewrite mxdirect_kermxpoly ?submx_refl//. rewrite (@big_morph _ _ _ true andb) ?big_all_cond ?coprimep1//; last first. by move=> p q; rewrite coprimepMr. by apply/allP => j _; apply/implyP => /andP[Pj neq_ji]; apply: p_coprime. Qed. Lemma eigenspace_poly n a (f : 'M_n) : eigenspace f a = kermxpoly f ('X - a%:P). Proof. case: n => [|m] in a f *; first by rewrite !thinmx0. by congr (kermx _); rewrite rmorphB /= ?horner_mx_X ?horner_mx_C. Qed. Definition geigenspace n (g : 'M_n) a := kermxpoly g (('X - a%:P) ^+ n). Lemma geigenspaceE n' (g : 'M_n'.+1) a : geigenspace g a = kermx ((g - a%:M) ^+ n'.+1). Proof. by rewrite /geigenspace /kermxpoly rmorphXn/= rmorphB/= horner_mx_X horner_mx_C. Qed. Lemma eigenspace_sub_geigen n (g : 'M_n) a : (eigenspace g a <= geigenspace g a)%MS. Proof. case: n => [|n] in g *; rewrite ?thinmx0 ?sub0mx// geigenspaceE. by apply/sub_kermxP; rewrite exprS mulmxA mulmx_ker mul0mx. Qed. Lemma mxdirect_sum_geigenspace (I : finType) (n : nat) (g : 'M_n) (P : {pred I}) (a_ : I -> K) : {in P &, injective a_} -> mxdirect (\sum_(i | P i) geigenspace g (a_ i)). Proof. move=> /inj_in_eq eq_a; apply: mxdirect_sum_kermx => i j Pi Pj Nji. by rewrite coprimep_expr ?coprimep_expl// coprimep_XsubC root_XsubC eq_a. Qed. Definition eigenpoly n (g : 'M_n) : pred {poly K} := (fun p => kermxpoly g p != 0). Lemma eigenpolyP n (g : 'M_n) (p : {poly K}) : reflect (exists2 v : 'rV_n, (v <= kermxpoly g p)%MS & v != 0) (eigenpoly g p). Proof. exact: rowV0Pn. Qed. Lemma eigenvalue_poly n a (f : 'M_n) : eigenvalue f a = eigenpoly f ('X - a%:P). Proof. by rewrite /eigenpoly /eigenvalue eigenspace_poly. Qed. Lemma comm_mx_stable_geigenspace n (f g : 'M_n) a : comm_mx f g -> stablemx (geigenspace f a) g. Proof. exact: comm_mx_stable_kermxpoly. Qed. End KernelLemmas. Section MapKermxPoly. Variables (aF rF : fieldType) (f : {rmorphism aF -> rF}). Lemma map_kermxpoly (n : nat) (g : 'M_n) (p : {poly aF}) : map_mx f (kermxpoly g p) = kermxpoly (map_mx f g) (map_poly f p). Proof. by case: n => [|n] in g *; rewrite ?thinmx0// map_kermx map_horner_mx. Qed. Lemma map_geigenspace (n : nat) (g : 'M_n) (a : aF) : map_mx f (geigenspace g a) = geigenspace (map_mx f g) (f a). Proof. by rewrite map_kermxpoly rmorphXn/= rmorphB /= map_polyX map_polyC. Qed. Lemma eigenpoly_map n (g : 'M_n) (p : {poly aF}) : eigenpoly (map_mx f g) (map_poly f p) = eigenpoly g p. Proof. by rewrite /eigenpoly -map_kermxpoly map_mx_eq0. Qed. End MapKermxPoly. Section IntegralOverRing. Definition integralOver (R K : nzRingType) (RtoK : R -> K) (z : K) := exists2 p, p \is monic & root (map_poly RtoK p) z. Definition integralRange R K RtoK := forall z, @integralOver R K RtoK z. Variables (B R K : nzRingType) (BtoR : B -> R) (RtoK : {rmorphism R -> K}). Lemma integral_rmorph x : integralOver BtoR x -> integralOver (RtoK \o BtoR) (RtoK x). Proof. by case=> p; exists p; rewrite // map_poly_comp rmorph_root. Qed. Lemma integral_id x : integralOver RtoK (RtoK x). Proof. by exists ('X - x%:P); rewrite ?monicXsubC ?rmorph_root ?root_XsubC. Qed. Lemma integral_nat n : integralOver RtoK n%:R. Proof. by rewrite -(rmorph_nat RtoK); apply: integral_id. Qed. Lemma integral0 : integralOver RtoK 0. Proof. exact: (integral_nat 0). Qed. Lemma integral1 : integralOver RtoK 1. Proof. exact: (integral_nat 1). Qed. Lemma integral_poly (p : {poly K}) : (forall i, integralOver RtoK p`_i) <-> {in p : seq K, integralRange RtoK}. Proof. split=> intRp => [_ /(nthP 0)[i _ <-] // | i]; rewrite -[p]coefK coef_poly. by case: ifP => [ltip | _]; [apply/intRp/mem_nth | apply: integral0]. Qed. End IntegralOverRing. Section IntegralOverComRing. Variables (R K : comNzRingType) (RtoK : {rmorphism R -> K}). Lemma integral_horner_root w (p q : {poly K}) : p \is monic -> root p w -> {in p : seq K, integralRange RtoK} -> {in q : seq K, integralRange RtoK} -> integralOver RtoK q.[w]. Proof. move=> mon_p pw0 intRp intRq. pose memR y := exists x, y = RtoK x. have memRid x: memR (RtoK x) by exists x. have memR_nat n: memR n%:R by rewrite -(rmorph_nat RtoK) /=. have [memR0 memR1]: memR 0 * memR 1 := (memR_nat 0, memR_nat 1). have memRN1: memR (- 1) by exists (- 1); rewrite rmorphN1. pose rVin (E : K -> Prop) n (a : 'rV[K]_n) := forall i, E (a 0 i). pose pXin (E : K -> Prop) (r : {poly K}) := forall i, E r`_i. pose memM E n (X : 'rV_n) y := exists a, rVin E n a /\ y = (a *m X^T) 0 0. pose finM E S := exists n, exists X, forall y, memM E n X y <-> S y. have tensorM E n1 n2 X Y: finM E (memM (memM E n2 Y) n1 X). exists (n1 * n2)%N, (mxvec (X^T *m Y)) => y. split=> [[a [Ea Dy]] | [a1 [/fin_all_exists[a /all_and2[Ea Da1]] ->]]]. exists (Y *m (vec_mx a)^T); split=> [i|]. exists (row i (vec_mx a)); split=> [j|]; first by rewrite !mxE; apply: Ea. by rewrite -row_mul -{1}[Y]trmxK -trmx_mul !mxE. by rewrite -[Y]trmxK -!trmx_mul mulmxA -mxvec_dotmul trmx_mul trmxK vec_mxK. exists (mxvec (\matrix_i a i)); split. by case/mxvec_indexP=> i j; rewrite mxvecE mxE; apply: Ea. rewrite -[mxvec _]trmxK -trmx_mul mxvec_dotmul -mulmxA trmx_mul !mxE. apply: eq_bigr => i _; rewrite Da1 !mxE; congr (_ * _). by apply: eq_bigr => j _; rewrite !mxE. suffices [m [X [[u [_ Du]] idealM]]]: exists m, exists X, let M := memM memR m X in M 1 /\ forall y, M y -> M (q.[w] * y). - do [set M := memM _ m X; move: q.[w] => z] in idealM *. have MX i: M (X 0 i). by exists (delta_mx 0 i); split=> [j|]; rewrite -?rowE !mxE. have /fin_all_exists[a /all_and2[Fa Da1]] i := idealM _ (MX i). have /fin_all_exists[r Dr] i := fin_all_exists (Fa i). pose A := \matrix_(i, j) r j i; pose B := z%:M - map_mx RtoK A. have XB0: X *m B = 0. apply/eqP; rewrite mulmxBr mul_mx_scalar subr_eq0; apply/eqP/rowP=> i. by rewrite !mxE Da1 mxE; apply: eq_bigr=> j _; rewrite !mxE mulrC Dr. exists (char_poly A); first exact: char_poly_monic. have: (\det B *: (u *m X^T)) 0 0 == 0. rewrite scalemxAr -linearZ -mul_mx_scalar -mul_mx_adj mulmxA XB0 /=. by rewrite mul0mx trmx0 mulmx0 mxE. rewrite mxE -Du mulr1 rootE -horner_evalE -2!det_map_mx; congr (\det _ == 0). rewrite raddfB/= map_scalar_mx; apply/matrixP=> i j. by rewrite !mxE raddfB raddfMn/= map_polyX map_polyC /horner_eval !hornerE. pose gen1 x E y := exists2 r, pXin E r & y = r.[x]; pose gen := foldr gen1 memR. have gen1S (E : K -> Prop) x y: E 0 -> E y -> gen1 x E y. by exists y%:P => [i|]; rewrite ?hornerC ?coefC //; case: ifP. have genR S y: memR y -> gen S y. by elim: S => //= x S IH in y * => /IH; apply/gen1S/IH. have gen0 := genR _ 0 memR0; have gen_1 := genR _ 1 memR1. have{gen1S} genS S y: y \in S -> gen S y. elim: S => //= x S IH /predU1P[-> | /IH//]; last exact: gen1S. by exists 'X => [i|]; rewrite ?hornerX // coefX; apply: genR. pose propD (R : K -> Prop) := forall x y, R x -> R y -> R (x + y). have memRD: propD memR. by move=> _ _ [a ->] [b ->]; exists (a + b); rewrite rmorphD. have genD S: propD (gen S). elim: S => //= x S IH _ _ [r1 Sr1 ->] [r2 Sr2 ->]; rewrite -hornerD. by exists (r1 + r2) => // i; rewrite coefD; apply: IH. have gen_sum S := big_ind _ (gen0 S) (genD S). pose propM (R : K -> Prop) := forall x y, R x -> R y -> R (x * y). have memRM: propM memR. by move=> _ _ [a ->] [b ->]; exists (a * b); rewrite rmorphM. have genM S: propM (gen S). elim: S => //= x S IH _ _ [r1 Sr1 ->] [r2 Sr2 ->]; rewrite -hornerM. by exists (r1 * r2) => // i; rewrite coefM; apply: gen_sum => j _; apply: IH. have gen_horner S r y: pXin (gen S) r -> gen S y -> gen S r.[y]. move=> Sq Sy; rewrite horner_coef; apply: gen_sum => [[i _] /= _]. by elim: {2}i => [|n IHn]; rewrite ?mulr1 // exprSr mulrA; apply: genM. pose S := w :: q ++ p; suffices [m [X defX]]: finM memR (gen S). exists m, X => M; split=> [|y /defX Xy]; first exact/defX. apply/defX/genM => //; apply: gen_horner => // [i|]; last exact/genS/mem_head. rewrite -[q]coefK coef_poly; case: ifP => // lt_i_q. by apply: genS; rewrite inE mem_cat mem_nth ?orbT. pose intR R y := exists r, [/\ r \is monic, root r y & pXin R r]. pose fix genI s := if s is y :: s1 then intR (gen s1) y /\ genI s1 else True. have{mon_p pw0 intRp intRq}: genI S. split; set S1 := _ ++ _; first exists p. split=> // i; rewrite -[p]coefK coef_poly; case: ifP => // lt_i_p. by apply: genS; rewrite mem_cat orbC mem_nth. set S2 := S1; have: all [in S1] S2 by apply/allP. elim: S2 => //= y S2 IH /andP[S1y S12]; split; last exact: IH. have{q S S1 IH S1y S12 intRp intRq} [q mon_q qx0]: integralOver RtoK y. by move: S1y; rewrite mem_cat => /orP[]; [apply: intRq | apply: intRp]. exists (map_poly RtoK q); split=> // [|i]; first exact: monic_map. by rewrite coef_map /=; apply: genR. elim: {w p q}S => /= [_|x S IH [[p [mon_p px0 Sp]] /IH{IH}[m2 [X2 defS]]]]. exists 1, 1 => y; split=> [[a [Fa ->]] | Fy]. by rewrite tr_scalar_mx mulmx1; apply: Fa. by exists y%:M; split=> [i|]; rewrite 1?ord1 ?tr_scalar_mx ?mulmx1 mxE. pose m1 := (size p).-1; pose X1 := \row_(i < m1) x ^+ i. have [m [X defM]] := tensorM memR m1 m2 X1 X2; set M := memM _ _ _ in defM. exists m, X => y; rewrite -/M; split=> [/defM[a [M2a]] | [q Sq]] -> {y}. exists (rVpoly a) => [i|]. by rewrite coef_rVpoly; case/insub: i => // i; apply/defS/M2a. rewrite mxE (horner_coef_wide _ (size_poly _ _)) -/(rVpoly a). by apply: eq_bigr => i _; rewrite coef_rVpoly_ord !mxE. have M_0: M 0 by exists 0; split=> [i|]; rewrite ?mul0mx mxE. have M_D: propD M. move=> _ _ [a [Fa ->]] [b [Fb ->]]; exists (a + b). by rewrite mulmxDl !mxE; split=> // i /[1!mxE]; apply: memRD. have{M_0 M_D} Msum := big_ind _ M_0 M_D. rewrite horner_coef; apply: (Msum) => i _; case: i q`_i {Sq}(Sq i) => /=. elim: {q}(size q) => // n IHn i i_le_n y Sy. have [i_lt_m1 | m1_le_i] := ltnP i m1. apply/defM; exists (y *: delta_mx 0 (Ordinal i_lt_m1)); split=> [j|]. by apply/defS; rewrite !mxE /= mulr_natr; case: eqP. by rewrite -scalemxAl -rowE !mxE. rewrite -(subnK m1_le_i) exprD -[x ^+ m1]subr0 -(rootP px0) horner_coef. rewrite polySpred ?monic_neq0 // -/m1 big_ord_recr /= -lead_coefE. rewrite opprD addrC (monicP mon_p) mul1r subrK !mulrN -mulNr !mulr_sumr. apply: Msum => j _; rewrite [X in M X]mulrA mulrACA -exprD; apply: IHn. by rewrite -addnS addnC addnBA // leq_subLR leq_add. by rewrite -mulN1r; do 2!apply: (genM) => //; apply: genR. Qed. Lemma integral_root_monic u p : p \is monic -> root p u -> {in p : seq K, integralRange RtoK} -> integralOver RtoK u. Proof. move=> mon_p pu0 intRp; rewrite -[u]hornerX. apply: integral_horner_root mon_p pu0 intRp _. by apply/integral_poly => i; rewrite coefX; apply: integral_nat. Qed. Let integral0_RtoK := integral0 RtoK. Let integral1_RtoK := integral1 RtoK. Let monicXsubC_K := @monicXsubC K. Hint Resolve integral0_RtoK integral1_RtoK monicXsubC_K : core. Let XsubC0 (u : K) : root ('X - u%:P) u. Proof. by rewrite root_XsubC. Qed. Let intR_XsubC u : integralOver RtoK (- u) -> {in 'X - u%:P : seq K, integralRange RtoK}. Proof. by move=> intRu v; rewrite polyseqXsubC !inE => /pred2P[]->. Qed. Lemma integral_opp u : integralOver RtoK u -> integralOver RtoK (- u). Proof. by rewrite -{1}[u]opprK => /intR_XsubC/integral_root_monic; apply. Qed. Lemma integral_horner (p : {poly K}) u : {in p : seq K, integralRange RtoK} -> integralOver RtoK u -> integralOver RtoK p.[u]. Proof. by move=> ? /integral_opp/intR_XsubC/integral_horner_root; apply. Qed. Lemma integral_sub u v : integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u - v). Proof. move=> intRu /integral_opp/intR_XsubC/integral_horner/(_ intRu). by rewrite !hornerE. Qed. Lemma integral_add u v : integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u + v). Proof. by rewrite -{2}[v]opprK => intRu /integral_opp; apply: integral_sub. Qed. Lemma integral_mul u v : integralOver RtoK u -> integralOver RtoK v -> integralOver RtoK (u * v). Proof. rewrite -{2}[v]hornerX -hornerZ => intRu; apply: integral_horner. by apply/integral_poly=> i; rewrite coefZ coefX mulr_natr mulrb; case: ifP. Qed. End IntegralOverComRing. Section IntegralOverField. Variables (F E : fieldType) (FtoE : {rmorphism F -> E}). Definition algebraicOver (fFtoE : F -> E) u := exists2 p, p != 0 & root (map_poly fFtoE p) u. Notation mk_mon p := ((lead_coef p)^-1 *: p). Lemma integral_algebraic u : algebraicOver FtoE u <-> integralOver FtoE u. Proof. split=> [] [p p_nz pu0]; last by exists p; rewrite ?monic_neq0. exists (mk_mon p); first by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0. by rewrite linearZ rootE hornerZ (rootP pu0) mulr0. Qed. Lemma algebraic_id a : algebraicOver FtoE (FtoE a). Proof. exact/integral_algebraic/integral_id. Qed. Lemma algebraic0 : algebraicOver FtoE 0. Proof. exact/integral_algebraic/integral0. Qed. Lemma algebraic1 : algebraicOver FtoE 1. Proof. exact/integral_algebraic/integral1. Qed. Lemma algebraic_opp x : algebraicOver FtoE x -> algebraicOver FtoE (- x). Proof. by move/integral_algebraic/integral_opp/integral_algebraic. Qed. Lemma algebraic_add x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x + y). Proof. move/integral_algebraic=> intFx /integral_algebraic intFy. exact/integral_algebraic/integral_add. Qed. Lemma algebraic_sub x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x - y). Proof. by move=> algFx /algebraic_opp; apply: algebraic_add. Qed. Lemma algebraic_mul x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x * y). Proof. move/integral_algebraic=> intFx /integral_algebraic intFy. exact/integral_algebraic/integral_mul. Qed. Lemma algebraic_inv u : algebraicOver FtoE u -> algebraicOver FtoE u^-1. Proof. have [-> | /expf_neq0 nz_u_n] := eqVneq u 0; first by rewrite invr0. case=> p nz_p pu0; exists (Poly (rev p)). apply/eqP=> /polyP/(_ 0); rewrite coef_Poly coef0 nth_rev ?size_poly_gt0 //. by apply/eqP; rewrite subn1 lead_coef_eq0. apply/eqP/(mulfI (nz_u_n (size p).-1)); rewrite mulr0 -(rootP pu0). rewrite (@horner_coef_wide _ (size p)); last first. by rewrite size_map_poly -(size_rev p) size_Poly. rewrite horner_coef mulr_sumr size_map_poly. rewrite [rhs in _ = rhs](reindex_inj rev_ord_inj) /=. apply: eq_bigr => i _; rewrite !coef_map coef_Poly nth_rev // mulrCA. by congr (_ * _); rewrite -{1}(subnKC (valP i)) addSn addnC exprD exprVn ?mulfK. Qed. Lemma algebraic_div x y : algebraicOver FtoE x -> algebraicOver FtoE y -> algebraicOver FtoE (x / y). Proof. by move=> algFx /algebraic_inv; apply: algebraic_mul. Qed. Lemma integral_inv x : integralOver FtoE x -> integralOver FtoE x^-1. Proof. by move/integral_algebraic/algebraic_inv/integral_algebraic. Qed. Lemma integral_div x y : integralOver FtoE x -> integralOver FtoE y -> integralOver FtoE (x / y). Proof. by move=> algFx /integral_inv; apply: integral_mul. Qed. Lemma integral_root p u : p != 0 -> root p u -> {in p : seq E, integralRange FtoE} -> integralOver FtoE u. Proof. move=> nz_p pu0 algFp. have mon_p1: mk_mon p \is monic. by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0. have p1u0: root (mk_mon p) u by rewrite rootE hornerZ (rootP pu0) mulr0. apply: integral_root_monic mon_p1 p1u0 _ => _ /(nthP 0)[i ltip <-]. rewrite coefZ mulrC; rewrite size_scale ?invr_eq0 ?lead_coef_eq0 // in ltip. by apply: integral_div; apply/algFp/mem_nth; rewrite -?polySpred. Qed. End IntegralOverField. (* Lifting term, formula, envs and eval to matrices. Wlog, and for the sake *) (* of simplicity, we only lift (tensor) envs to row vectors; we can always *) (* use mxvec/vec_mx to store and retrieve matrices. *) (* We don't provide definitions for addition, subtraction, scaling, etc, *) (* because they have simple matrix expressions. *) Module MatrixFormula. Section MatrixFormula. Variable F : fieldType. Local Notation False := GRing.False. Local Notation True := GRing.True. Local Notation And := GRing.And (only parsing). Local Notation Add := GRing.Add (only parsing). Local Notation Bool b := (GRing.Bool b%bool). Local Notation term := (GRing.term F). Local Notation form := (GRing.formula F). Local Notation eval := GRing.eval. Local Notation holds := GRing.holds. Local Notation qf_form := GRing.qf_form. Local Notation qf_eval := GRing.qf_eval. Definition eval_mx (e : seq F) := @map_mx term F (eval e). Definition mx_term := @map_mx F term GRing.Const. Lemma eval_mx_term e m n (A : 'M_(m, n)) : eval_mx e (mx_term A) = A. Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Definition mulmx_term m n p (A : 'M[term]_(m, n)) (B : 'M_(n, p)) := \matrix_(i, k) (\big[Add/0]_j (A i j * B j k))%T. Lemma eval_mulmx e m n p (A : 'M[term]_(m, n)) (B : 'M_(n, p)) : eval_mx e (mulmx_term A B) = eval_mx e A *m eval_mx e B. Proof. apply/matrixP=> i k; rewrite !mxE /= ((big_morph (eval e)) 0 +%R) //=. by apply: eq_bigr => j _; rewrite /= !mxE. Qed. Local Notation morphAnd f := ((big_morph f) true andb). Let Schur m n (A : 'M[term]_(1 + m, 1 + n)) (a := A 0 0) := \matrix_(i, j) (drsubmx A i j - a^-1 * dlsubmx A i 0%R * ursubmx A 0%R j)%T. Fixpoint mxrank_form (r m n : nat) : 'M_(m, n) -> form := match m, n return 'M_(m, n) -> form with | m'.+1, n'.+1 => fun A : 'M_(1 + m', 1 + n') => let nzA k := A k.1 k.2 != 0 in let xSchur k := Schur (xrow k.1 0%R (xcol k.2 0%R A)) in let recf k := Bool (r > 0) /\ mxrank_form r.-1 (xSchur k) in GRing.Pick nzA recf (Bool (r == 0%N)) | _, _ => fun _ => Bool (r == 0%N) end%T. Lemma mxrank_form_qf r m n (A : 'M_(m, n)) : qf_form (mxrank_form r A). Proof. by elim: m r n A => [|m IHm] r [|n] A //=; rewrite GRing.Pick_form_qf /=. Qed. Lemma eval_mxrank e r m n (A : 'M_(m, n)) : qf_eval e (mxrank_form r A) = (\rank (eval_mx e A) == r). Proof. elim: m r n A => [|m IHm] r [|n] A /=; try by case r; rewrite unlock. rewrite GRing.eval_Pick !unlock /=; set pf := fun _ => _. rewrite -(@eq_pick _ pf) => [|k]; rewrite {}/pf ?mxE // eq_sym. case: pick => [[i j]|] //=; set B := _ - _; have:= mxrankE B. case: (Gaussian_elimination_ B) r => [[_ _] _] [|r] //= <-; rewrite {}IHm eqSS. by congr (\rank _ == r); apply/matrixP=> k l; rewrite !(mxE, big_ord1) !tpermR. Qed. Lemma eval_vec_mx e m n (u : 'rV_(m * n)) : eval_mx e (vec_mx u) = vec_mx (eval_mx e u). Proof. by apply/matrixP=> i j; rewrite !mxE. Qed. Lemma eval_mxvec e m n (A : 'M_(m, n)) : eval_mx e (mxvec A) = mxvec (eval_mx e A). Proof. by rewrite -{2}[A]mxvecK eval_vec_mx vec_mxK. Qed. Section Subsetmx. Variables (m1 m2 n : nat) (A : 'M[term]_(m1, n)) (B : 'M[term]_(m2, n)). Definition submx_form := \big[And/True]_(r < n.+1) (mxrank_form r (col_mx A B) ==> mxrank_form r B)%T. Lemma eval_col_mx e : eval_mx e (col_mx A B) = col_mx (eval_mx e A) (eval_mx e B). Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed. Lemma submx_form_qf : qf_form submx_form. Proof. by rewrite (morphAnd (@qf_form _)) ?big1 //= => r _; rewrite !mxrank_form_qf. Qed. Lemma eval_submx e : qf_eval e submx_form = (eval_mx e A <= eval_mx e B)%MS. Proof. rewrite (morphAnd (qf_eval e)) //= big_andE /=. apply/forallP/idP=> /= [|sAB d]; last first. rewrite !eval_mxrank eval_col_mx -addsmxE; apply/implyP=> /eqP <-. by rewrite mxrank_leqif_sup ?addsmxSr // addsmx_sub sAB /=. move/(_ (inord (\rank (eval_mx e (col_mx A B))))). rewrite inordK ?ltnS ?rank_leq_col // !eval_mxrank eqxx /= eval_col_mx. by rewrite -addsmxE mxrank_leqif_sup ?addsmxSr // addsmx_sub; case/andP. Qed. End Subsetmx. Section Env. Variable d : nat. Definition seq_of_rV (v : 'rV_d) : seq F := fgraph [ffun i => v 0 i]. Lemma size_seq_of_rV v : size (seq_of_rV v) = d. Proof. by rewrite tuple.size_tuple card_ord. Qed. Lemma nth_seq_of_rV x0 v (i : 'I_d) : nth x0 (seq_of_rV v) i = v 0 i. Proof. by rewrite nth_fgraph_ord ffunE. Qed. Definition row_var k : 'rV[term]_d := \row_i ('X_(k * d + i))%T. Definition row_env (e : seq 'rV_d) := flatten (map seq_of_rV e). Lemma nth_row_env e k (i : 'I_d) : (row_env e)`_(k * d + i) = e`_k 0 i. Proof. elim: e k => [|v e IHe] k; first by rewrite !nth_nil mxE. rewrite /row_env /= nth_cat size_seq_of_rV. case: k => [|k]; first by rewrite (valP i) nth_seq_of_rV. by rewrite mulSn -addnA -if_neg -leqNgt leq_addr addKn IHe. Qed. Lemma eval_row_var e k : eval_mx (row_env e) (row_var k) = e`_k :> 'rV_d. Proof. by apply/rowP=> i; rewrite !mxE /= nth_row_env. Qed. Definition Exists_row_form k (f : form) := foldr GRing.Exists f (codom (fun i : 'I_d => k * d + i)%N). Lemma Exists_rowP e k f : d > 0 -> ((exists v : 'rV[F]_d, holds (row_env (set_nth 0 e k v)) f) <-> holds (row_env e) (Exists_row_form k f)). Proof. move=> d_gt0; pose i_ j := Ordinal (ltn_pmod j d_gt0). have d_eq j: (j = j %/ d * d + i_ j)%N := divn_eq j d. split=> [[v f_v] | ]; last case/GRing.foldExistsP=> e' ee' f_e'. apply/GRing.foldExistsP; exists (row_env (set_nth 0 e k v)) => {f f_v}// j. rewrite [j]d_eq !nth_row_env nth_set_nth /=; case: eqP => // ->. by case/imageP; exists (i_ j). exists (\row_i e'`_(k * d + i)); apply: eq_holds f_e' => j /=. move/(_ j): ee'; rewrite [j]d_eq !nth_row_env nth_set_nth /=. case: eqP => [-> | ne_j_k -> //]; first by rewrite mxE. apply/mapP=> [[r lt_r_d]]; rewrite -d_eq => def_j; case: ne_j_k. by rewrite def_j divnMDl // divn_small ?addn0. Qed. End Env. End MatrixFormula. End MatrixFormula. Section ConjMx. Context {F : fieldType}. Definition conjmx (m n : nat) (V : 'M_(m, n)) (f : 'M[F]_n) : 'M_m := V *m f *m pinvmx V. Notation restrictmx V := (conjmx (row_base V)). Lemma stablemx_comp (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : stablemx W f -> stablemx V (conjmx W f) -> stablemx (V *m W) f. Proof. by move=> Wf /(submxMr W); rewrite -mulmxA mulmxKpV// mulmxA. Qed. Lemma stablemx_restrict m n (A : 'M[F]_n) (V : 'M_n) (W : 'M_(m, \rank V)): stablemx V A -> stablemx W (restrictmx V A) = stablemx (W *m row_base V) A. Proof. move=> A_stabV; rewrite mulmxA -[in RHS]mulmxA. rewrite -(submxMfree _ W (row_base_free V)) mulmxKpV //. by rewrite mulmx_sub ?stablemx_row_base. Qed. Lemma conjmxM (m n : nat) (V : 'M[F]_(m, n)) : {in [pred f | stablemx V f] &, {morph conjmx V : f g / f *m g}}. Proof. move=> f g; rewrite !inE => Vf Vg /=. by rewrite /conjmx 2!mulmxA mulmxA mulmxKpV ?stablemx_row_base. Qed. Lemma conjMmx (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) : row_free (V *m W) -> stablemx W f -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> rfVW Wf VWf; apply: (row_free_inj rfVW); rewrite mulmxKpV ?stablemx_comp//. by rewrite mulmxA mulmxKpV// -[RHS]mulmxA mulmxKpV ?mulmxA. Qed. Lemma conjuMmx (m n : nat) (V : 'M[F]_m) (W : 'M_(m, n)) (f : 'M_n) : V \in unitmx -> row_free W -> stablemx W f -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Vu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree// -/(row_free V) row_free_unit. Qed. Lemma conjMumx (m n : nat) (V : 'M[F]_(m, n)) (W f : 'M_n) : W \in unitmx -> row_free V -> stablemx V (conjmx W f) -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. move=> Wu rfW Wf; rewrite conjMmx ?stablemx_unit//. by rewrite /row_free mxrankMfree ?row_free_unit. Qed. Lemma conjuMumx (n : nat) (V W f : 'M[F]_n) : V \in unitmx -> W \in unitmx -> conjmx (V *m W) f = conjmx V (conjmx W f). Proof. by move=> Vu Wu; rewrite conjuMmx ?stablemx_unit ?row_free_unit. Qed. Lemma conjmx_scalar (m n : nat) (V : 'M[F]_(m, n)) (a : F) : row_free V -> conjmx V a%:M = a%:M. Proof. by move=> rfV; rewrite /conjmx scalar_mxC mulmxKp. Qed. Lemma conj0mx (m n : nat) f : conjmx (0 : 'M[F]_(m, n)) f = 0. Proof. by rewrite /conjmx !mul0mx. Qed. Lemma conjmx0 (m n : nat) (V : 'M[F]_(m, n)) : conjmx V 0 = 0. Proof. by rewrite /conjmx mulmx0 mul0mx. Qed. Lemma conjumx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx V f = V *m f *m invmx V. Proof. by move=> uV; rewrite /conjmx pinvmxE. Qed. Lemma conj1mx (n : nat) (f : 'M[F]_n) : conjmx 1%:M f = f. Proof. by rewrite conjumx ?unitmx1// invmx1 mulmx1 mul1mx. Qed. Lemma conjVmx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) f = invmx V *m f *m V. Proof. by move=> Vunit; rewrite conjumx ?invmxK ?unitmx_inv. Qed. Lemma conjmxK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx (invmx V) (conjmx V f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulVmx ?conj1mx. Qed. Lemma conjmxVK (n : nat) (V f : 'M[F]_n) : V \in unitmx -> conjmx V (conjmx (invmx V) f) = f. Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulmxV ?conj1mx. Qed. Lemma horner_mx_conj m n p (V : 'M[F]_(n.+1, m.+1)) (f : 'M_m.+1) : row_free V -> stablemx V f -> horner_mx (conjmx V f) p = conjmx V (horner_mx f p). Proof. move=> V_free V_stab; rewrite/conjmx; elim/poly_ind: p => [|p c]. by rewrite !rmorph0 mulmx0 mul0mx. rewrite !(rmorphD, rmorphM)/= !(horner_mx_X, horner_mx_C) => ->. rewrite [_ * _]mulmxA [_ *m (V *m _)]mulmxA mulmxKpV ?horner_mx_stable//. apply: (row_free_inj V_free); rewrite [_ *m V]mulmxDl. pose stablemxE := (stablemxD, stablemxM, stablemxC, horner_mx_stable). by rewrite !mulmxKpV -?[V *m _ *m _]mulmxA ?stablemxE// mulmxDr -scalar_mxC. Qed. Lemma horner_mx_uconj n p (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \is a GRing.unit -> horner_mx (V *m f *m invmx V) p = V *m horner_mx f p *m invmx V. Proof. move=> V_unit; rewrite -!conjumx//. by rewrite horner_mx_conj ?row_free_unit ?stablemx_unit. Qed. Lemma horner_mx_uconjC n p (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \is a GRing.unit -> horner_mx (invmx V *m f *m V) p = invmx V *m horner_mx f p *m V. Proof. move=> V_unit; rewrite -[X in _ *m X](invmxK V). by rewrite horner_mx_uconj ?invmxK ?unitmx_inv. Qed. Lemma mxminpoly_conj m n (V : 'M[F]_(m.+1, n.+1)) (f : 'M_n.+1) : row_free V -> stablemx V f -> mxminpoly (conjmx V f) %| mxminpoly f. Proof. by move=> *; rewrite mxminpoly_min// horner_mx_conj// mx_root_minpoly conjmx0. Qed. Lemma mxminpoly_uconj n (V : 'M[F]_(n.+1)) (f : 'M_n.+1) : V \in unitmx -> mxminpoly (conjmx V f) = mxminpoly f. Proof. have simp := (row_free_unit, stablemx_unit, unitmx_inv, unitmx1). move=> Vu; apply/eqP; rewrite -eqp_monic ?mxminpoly_monic// /eqp. apply/andP; split; first by rewrite mxminpoly_conj ?simp. by rewrite -[f in X in X %| _](conjmxK _ Vu) mxminpoly_conj ?simp. Qed. Section fixed_stablemx_space. Variables (m n : nat). Implicit Types (V : 'M[F]_(m, n)) (A : 'M[F]_n). Implicit Types (a : F) (p : {poly F}). Section Sub. Variable (k : nat). Implicit Types (W : 'M[F]_(k, m)). Lemma sub_kermxpoly_conjmx V f p W : stablemx V f -> row_free V -> (W <= kermxpoly (conjmx V f) p)%MS = (W *m V <= kermxpoly f p)%MS. Proof. case: n m => [|n'] [|m'] in V f W * => fV rfV; rewrite ?thinmx0//. by rewrite /row_free mxrank.unlock in rfV. by rewrite mul0mx !sub0mx. apply/sub_kermxP/sub_kermxP; rewrite horner_mx_conj//; last first. by move=> /(congr1 (mulmxr (pinvmx V)))/=; rewrite mul0mx !mulmxA. move=> /(congr1 (mulmxr V))/=; rewrite ![W *m _]mulmxA ?mul0mx mulmxKpV//. by rewrite -mulmxA mulmx_sub// horner_mx_stable//. Qed. Lemma sub_eigenspace_conjmx V f a W : stablemx V f -> row_free V -> (W <= eigenspace (conjmx V f) a)%MS = (W *m V <= eigenspace f a)%MS. Proof. by move=> fV rfV; rewrite !eigenspace_poly sub_kermxpoly_conjmx. Qed. End Sub. Lemma eigenpoly_conjmx V f : stablemx V f -> row_free V -> {subset eigenpoly (conjmx V f) <= eigenpoly f}. Proof. move=> fV rfV a /eigenpolyP [x]; rewrite sub_kermxpoly_conjmx//. move=> xV_le_fa x_neq0; apply/eigenpolyP. by exists (x *m V); rewrite ?mulmx_free_eq0. Qed. Lemma eigenvalue_conjmx V f : stablemx V f -> row_free V -> {subset eigenvalue (conjmx V f) <= eigenvalue f}. Proof. by move=> fV rfV a; rewrite ![_ \in _]eigenvalue_poly; apply: eigenpoly_conjmx. Qed. Lemma conjmx_eigenvalue a V f : (V <= eigenspace f a)%MS -> row_free V -> conjmx V f = a%:M. Proof. by move=> /eigenspaceP Vfa rfV; rewrite /conjmx Vfa -mul_scalar_mx mulmxKp. Qed. End fixed_stablemx_space. End ConjMx. Notation restrictmx V := (conjmx (row_base V)). Definition simmx_to_for {F : fieldType} {m n} (P : 'M_(m, n)) A (S : {pred 'M[F]_m}) := S (conjmx P A). Notation "A ~_ P '{' 'in' S '}'" := (simmx_to_for P A S) (at level 70, P at level 0, format "A ~_ P '{' 'in' S '}'") : ring_scope. Notation simmx_for P A B := (A ~_P {in PredOfSimpl.coerce (pred1 B)}). Notation "A ~_ P B" := (simmx_for P A B) (format "A ~_ P B"). Notation simmx_in S A B := (exists2 P, P \in S & A ~_P B). Notation "A '~_{in' S '}' B" := (simmx_in S A B) (at level 70, format "A '~_{in' S '}' B"). Notation simmx_in_to S A S' := (exists2 P, P \in S & A ~_P {in S'}). Notation "A '~_{in' S '}' '{' 'in' S' '}'" := (simmx_in_to S A S') (format "A '~_{in' S '}' '{' 'in' S' '}'"). Notation all_simmx_in S As S' := (exists2 P, P \in S & all [pred A | A ~_P {in S'}] As). Notation diagonalizable_for P A := (A ~_P {in is_diag_mx}). Notation diagonalizable_in S A := (A ~_{in S} {in is_diag_mx}). Notation diagonalizable A := (diagonalizable_in unitmx A). Notation codiagonalizable_in S As := (all_simmx_in S As is_diag_mx). Notation codiagonalizable As := (codiagonalizable_in unitmx As). Section Simmxity. Context {F : fieldType}. Lemma simmxPp m n {P : 'M[F]_(m, n)} {A B} : stablemx P A -> A ~_P B -> P *m A = B *m P. Proof. by move=> stablemxPA /eqP <-; rewrite mulmxKpV. Qed. Lemma simmxW m n {P : 'M[F]_(m, n)} {A B} : row_free P -> P *m A = B *m P -> A ~_P B. Proof. by rewrite /(_ ~__ _)/= /conjmx => fP ->; rewrite mulmxKp. Qed. Section Simmx. Context {n : nat}. Implicit Types (A B P : 'M[F]_n) (As : seq 'M[F]_n) (d : 'rV[F]_n). Lemma simmxP {P A B} : P \in unitmx -> reflect (P *m A = B *m P) (A ~_P B). Proof. move=> p_unit; apply: (iffP idP); first exact/simmxPp/stablemx_unit. by apply: simmxW; rewrite row_free_unit. Qed. Lemma simmxRL {P A B} : P \in unitmx -> reflect (B = P *m A *m invmx P) (A ~_P B). Proof. by move=> ?; apply: (iffP eqP); rewrite conjumx. Qed. Lemma simmxLR {P A B} : P \in unitmx -> reflect (A = conjmx (invmx P) B) (A ~_P B). Proof. by move=> Pu; rewrite conjVmx//; apply: (iffP (simmxRL Pu)) => ->; rewrite !mulmxA ?(mulmxK, mulmxKV, mulVmx, mulmxV, mul1mx, mulmx1). Qed. End Simmx. Lemma simmx_minpoly {n} {P A B : 'M[F]_n.+1} : P \in unitmx -> A ~_P B -> mxminpoly A = mxminpoly B. Proof. by move=> Pu /eqP<-; rewrite mxminpoly_uconj. Qed. Lemma diagonalizable_for_row_base m n (P : 'M[F]_(m, n)) (A : 'M_n) : diagonalizable_for (row_base P) A = is_diag_mx (restrictmx P A). Proof. by []. Qed. Lemma diagonalizable_forPp m n (P : 'M[F]_(m, n)) A : reflect (forall i j : 'I__, i != j :> nat -> conjmx P A i j = 0) (diagonalizable_for P A). Proof. exact: @is_diag_mxP. Qed. Lemma diagonalizable_forP n (P : 'M[F]_n) A : P \in unitmx -> reflect (forall i j : 'I__, i != j :> nat -> (P *m A *m invmx P) i j = 0) (diagonalizable_for P A). Proof. by move=> Pu; rewrite -conjumx//; exact: is_diag_mxP. Qed. Lemma diagonalizable_forPex {m} {n} {P : 'M[F]_(m, n)} {A} : reflect (exists D, A ~_P (diag_mx D)) (diagonalizable_for P A). Proof. by apply: (iffP (diag_mxP _)) => -[D]/eqP; exists D. Qed. Lemma diagonalizable_forLR n {P : 'M[F]_n} {A} : P \in unitmx -> reflect (exists D, A = conjmx (invmx P) (diag_mx D)) (diagonalizable_for P A). Proof. by move=> Punit; apply: (iffP diagonalizable_forPex) => -[D /(simmxLR Punit)]; exists D. Qed. Lemma diagonalizable_for_mxminpoly {n} {P A : 'M[F]_n.+1} (rs := undup [seq conjmx P A i i | i <- enum 'I_n.+1]) : P \in unitmx -> diagonalizable_for P A -> mxminpoly A = \prod_(r <- rs) ('X - r%:P). Proof. rewrite /rs => pu /(diagonalizable_forLR pu)[d {A rs}->]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by rewrite [in X in _ = X](@eq_map _ _ _ (d 0))// => i; rewrite conjmxVK// mxE eqxx. Qed. End Simmxity. Lemma diagonalizable_for_sum (F : fieldType) (m n : nat) (p_ : 'I_n -> nat) (V_ : forall i, 'M[F]_(p_ i, m)) (A : 'M[F]_m) : mxdirect (\sum_i <<V_ i>>) -> (forall i, stablemx (V_ i) A) -> (forall i, row_free (V_ i)) -> diagonalizable_for (\mxcol_i V_ i) A = [forall i, diagonalizable_for (V_ i) A]. Proof. move=> Vd VA rAV; have aVA : stablemx (\mxcol_i V_ i) A. rewrite (eqmx_stable _ (eqmx_col _)) stablemx_sums//. by move=> i; rewrite (eqmx_stable _ (genmxE _)). apply/diagonalizable_forPex/'forall_diagonalizable_forPex => /= [[D /(simmxPp aVA) +] i|/(_ _)/sigW DoA]. rewrite mxcol_mul -[D]submxrowK diag_mxrow mul_mxdiag_mxcol. move=> /eq_mxcolP/(_ i); set D0 := (submxrow _ _) => VMeq. by exists D0; apply/simmxW. exists (\mxrow_i tag (DoA i)); apply/simmxW. rewrite -row_leq_rank eqmx_col (mxdirectP Vd)/=. by under [leqRHS]eq_bigr do rewrite genmxE (eqP (rAV _)). rewrite mxcol_mul diag_mxrow mul_mxdiag_mxcol; apply: eq_mxcol => i. by case: DoA => /= k /(simmxPp); rewrite VA => /(_ isT) ->. Qed. Section Diag. Variable (F : fieldType). Lemma codiagonalizable1 n (A : 'M[F]_n) : codiagonalizable [:: A] <-> diagonalizable A. Proof. by split=> -[P Punit PA]; exists P; move: PA; rewrite //= andbT. Qed. Definition codiagonalizablePfull n (As : seq 'M[F]_n) : codiagonalizable As <-> exists m, exists2 P : 'M_(m, n), row_full P & all [pred A | diagonalizable_for P A] As. Proof. split => [[P Punit SPA]|[m [P Pfull SPA]]]. by exists n => //; exists P; rewrite ?row_full_unit. have Qfull := fullrowsub_unit Pfull. exists (rowsub (fullrankfun Pfull) P) => //; apply/allP => A AAs/=. have /allP /(_ _ AAs)/= /diagonalizable_forPex[d /simmxPp] := SPA. rewrite submx_full// => /(_ isT) PA_eq. apply/diagonalizable_forPex; exists (colsub (fullrankfun Pfull) d). apply/simmxP => //; apply/row_matrixP => i. rewrite !row_mul row_diag_mx -scalemxAl -rowE !row_rowsub !mxE. have /(congr1 (row (fullrankfun Pfull i))) := PA_eq. by rewrite !row_mul row_diag_mx -scalemxAl -rowE => ->. Qed. Lemma codiagonalizable_on m n (V_ : 'I_n -> 'M[F]_m) (As : seq 'M[F]_m) : (\sum_i V_ i :=: 1%:M)%MS -> mxdirect (\sum_i V_ i) -> (forall i, all (fun A => stablemx (V_ i) A) As) -> (forall i, codiagonalizable (map (restrictmx (V_ i)) As)) -> codiagonalizable As. Proof. move=> V1 Vdirect /(_ _)/allP AV /(_ _) /sig2W/= Pof. pose P_ i := tag (Pof i). have P_unit i : P_ i \in unitmx by rewrite /P_; case: {+}Pof. have P_diag i A : A \in As -> diagonalizable_for (P_ i *m row_base (V_ i)) A. move=> AAs; rewrite /P_; case: {+}Pof => /= P Punit. rewrite all_map => /allP/(_ A AAs); rewrite /= !/(diagonalizable_for _ _). by rewrite conjuMmx ?row_base_free ?stablemx_row_base ?AV. pose P := \mxcol_i (P_ i *m row_base (V_ i)). have P_full i : row_full (P_ i) by rewrite row_full_unit. have PrV i : (P_ i *m row_base (V_ i) :=: V_ i)%MS. exact/(eqmx_trans _ (eq_row_base _))/eqmxMfull. apply/codiagonalizablePfull; eexists _; last exists P; rewrite /=. - rewrite -sub1mx eqmx_col. by under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. apply/allP => A AAs /=; rewrite diagonalizable_for_sum. - by apply/forallP => i; apply: P_diag. - rewrite mxdirectE/=. under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1. by under eq_bigr do rewrite genmxE PrV; rewrite -(mxdirectP Vdirect)//= V1. - by move=> i; rewrite (eqmx_stable _ (PrV _)) ?AV. - by move=> i; rewrite /row_free eqmxMfull ?eq_row_base ?row_full_unit. Qed. Lemma diagonalizable_diag {n} (d : 'rV[F]_n) : diagonalizable (diag_mx d). Proof. exists 1%:M; rewrite ?unitmx1// /(diagonalizable_for _ _). by rewrite conj1mx diag_mx_is_diag. Qed. Hint Resolve diagonalizable_diag : core. Lemma diagonalizable_scalar {n} (a : F) : diagonalizable (a%:M : 'M_n). Proof. by rewrite -diag_const_mx. Qed. Hint Resolve diagonalizable_scalar : core. Lemma diagonalizable0 {n} : diagonalizable (0 : 'M[F]_n). Proof. by rewrite (_ : 0 = 0%:M)//; apply/matrixP => i j; rewrite !mxE// mul0rn. Qed. Hint Resolve diagonalizable0 : core. Lemma diagonalizablePeigen {n} {A : 'M[F]_n} : diagonalizable A <-> exists2 rs, uniq rs & (\sum_(r <- rs) eigenspace A r :=: 1%:M)%MS. Proof. split=> [df|[rs urs rsP]]. suff [rs rsP] : exists rs, (\sum_(r <- rs) eigenspace A r :=: 1%:M)%MS. exists (undup rs); rewrite ?undup_uniq//; apply: eqmx_trans rsP. elim: rs => //= r rs IHrs; rewrite big_cons. case: ifPn => in_rs; rewrite ?big_cons; last exact: adds_eqmx. apply/(eqmx_trans IHrs)/eqmx_sym/addsmx_idPr. have rrs : (index r rs < size rs)%N by rewrite index_mem. rewrite (big_nth 0) big_mkord (sumsmx_sup (Ordinal rrs)) ?nth_index//. move: df => [P Punit /(diagonalizable_forLR Punit)[d ->]]. exists [seq d 0 i | i <- enum 'I_n]; rewrite big_image/=. apply: (@eqmx_trans _ _ _ _ _ _ P); apply/eqmxP; rewrite ?sub1mx ?submx1 ?row_full_unit//. rewrite submx_full ?row_full_unit//=. apply/row_subP => i; rewrite rowE (sumsmx_sup i)//. apply/eigenspaceP; rewrite conjVmx// !mulmxA mulmxK//. by rewrite -rowE row_diag_mx scalemxAl. have mxdirect_eigenspaces : mxdirect (\sum_(i < size rs) eigenspace A rs`_i). apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. rewrite (big_nth 0) big_mkord in rsP; apply/codiagonalizable1. apply/(codiagonalizable_on _ mxdirect_eigenspaces) => // i/=. case: n => [|n] in A {mxdirect_eigenspaces} rsP *. by rewrite thinmx0 sub0mx. by rewrite comm_mx_stable_eigenspace. apply/codiagonalizable1. rewrite (@conjmx_eigenvalue _ _ _ rs`_i); first exact: diagonalizable_scalar. by rewrite eq_row_base. by rewrite row_base_free. Qed. Lemma diagonalizableP n' (n := n'.+1) (A : 'M[F]_n) : diagonalizable A <-> exists2 rs, uniq rs & mxminpoly A %| \prod_(x <- rs) ('X - x%:P). Proof. split=> [[P Punit /diagonalizable_forPex[d /(simmxLR Punit)->]]|]. rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag. by eexists; [|by []]; rewrite undup_uniq. move=> + /ltac:(apply/diagonalizablePeigen) => -[rs rsu rsP]; exists rs => //. rewrite (big_nth 0) [X in (X :=: _)%MS](big_nth 0) !big_mkord in rsP *. rewrite (eq_bigr _ (fun _ _ => eigenspace_poly _ _)). apply: (eqmx_trans (eqmx_sym (kermxpoly_prod _ _)) (kermxpoly_min _)) => //. by move=> i j _ _; rewrite coprimep_XsubC root_XsubC nth_uniq. Qed. Lemma diagonalizable_conj_diag m n (V : 'M[F]_(m, n)) (d : 'rV[F]_n) : stablemx V (diag_mx d) -> row_free V -> diagonalizable (conjmx V (diag_mx d)). Proof. case: m n => [|m] [|n] in V d * => Vd rdV; rewrite ?thinmx0. - by []. - by []. - by exfalso; move: rdV; rewrite /row_free mxrank.unlock eqxx orbT. apply/diagonalizableP; pose u := undup [seq d 0 i | i <- enum 'I_n.+1]. exists u; first by rewrite undup_uniq. by rewrite (dvdp_trans (mxminpoly_conj (f:=diag_mx d) _ _))// mxminpoly_diag. Qed. Lemma codiagonalizableP n (As : seq 'M[F]_n) : {in As &, forall A B, comm_mx A B} /\ {in As, forall A, diagonalizable A} <-> codiagonalizable As. Proof. split => [cdAs|[P Punit /allP/= AsD]]/=; last first. split; last by exists P; rewrite // AsD. move=> A B AAs BAs; move=> /(_ _ _)/diagonalizable_forPex/sigW in AsD. have [[dA /simmxLR->//] [dB /simmxLR->//]] := (AsD _ AAs, AsD _ BAs). by rewrite /comm_mx -!conjmxM 1?diag_mxC// inE stablemx_unit ?unitmx_inv. move: cdAs => -[]; move/(rwP (all_comm_mxP _)) => cdAs cdAs'. have [k] := ubnP (size As); elim: k => [|k IHk]//= in n As cdAs cdAs' *. case: As cdAs cdAs' => [|A As]//=; first by exists 1%:M; rewrite ?unitmx1. rewrite ltnS all_comm_mx_cons => /andP[/allP/(_ _ _)/eqP AAsC AsC dAAs] Ask. have /diagonalizablePeigen [rs urs rs1] := dAAs _ (mem_head _ _). rewrite (big_nth 0) big_mkord in rs1. have eAB (i : 'I_(size rs)) B : B \in A :: As -> stablemx (eigenspace A rs`_i) B. case: n => [|n'] in B A As AAsC AsC {dAAs rs1 Ask} * => B_AAs. by rewrite thinmx0 sub0mx. rewrite comm_mx_stable_eigenspace//. by move: B_AAs; rewrite !inE => /predU1P [->//|/AAsC]. apply/(@codiagonalizable_on _ _ _ (_ :: _) rs1) => [|i|i /=]. - apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj. by apply: uniqP rsij; rewrite ?inE. - by apply/allP => B B_AAs; rewrite eAB. rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free//. set Bs := map _ _; suff [P Punit /= PBs] : codiagonalizable Bs. exists P; rewrite /= ?PBs ?andbT// /(diagonalizable_for _ _). by rewrite conjmx_scalar ?mx_scalar_is_diag// row_free_unit. apply: IHk; rewrite ?size_map/= ?ltnS//. apply/all_comm_mxP => _ _ /mapP[/= B BAs ->] /mapP[/= h hAs ->]. rewrite -!conjmxM ?inE ?stablemx_row_base ?eAB ?inE ?BAs ?hAs ?orbT//. by rewrite (all_comm_mxP _ AsC). move=> _ /mapP[/= B BAs ->]. have: stablemx (row_base (eigenspace A rs`_i)) B. by rewrite stablemx_row_base eAB// inE BAs orbT. have := dAAs B; rewrite inE BAs orbT => /(_ isT) [P Punit]. move=> /diagonalizable_forPex[D /(simmxLR Punit)->] sePD. have rAeP : row_free (row_base (eigenspace A rs`_i) *m invmx P). by rewrite /row_free mxrankMfree ?row_free_unit ?unitmx_inv// eq_row_base. rewrite -conjMumx ?unitmx_inv ?row_base_free => [|//|//|//]. apply/diagonalizable_conj_diag => //. by rewrite stablemx_comp// stablemx_unit ?unitmx_inv. Qed. End Diag.
Coequalizer.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.Reflexive import Mathlib.CategoryTheory.Limits.Shapes.SplitCoequalizer import Mathlib.CategoryTheory.Monad.Algebra /-! # Special coequalizers associated to a monad Associated to a monad `T : C ⥤ C` we have important coequalizer constructions: Any algebra is a coequalizer (in the category of algebras) of free algebras. Furthermore, this coequalizer is reflexive. In `C`, this cofork diagram is a split coequalizer (in particular, it is still a coequalizer). This split coequalizer is known as the Beck coequalizer (as it features heavily in Beck's monadicity theorem). This file has been adapted to `Mathlib/CategoryTheory/Monad/Equalizer.lean`. Please try to keep them in sync. -/ universe v₁ u₁ namespace CategoryTheory namespace Monad open Limits variable {C : Type u₁} variable [Category.{v₁} C] variable {T : Monad C} (X : Algebra T) /-! Show that any algebra is a coequalizer of free algebras. -/ /-- The top map in the coequalizer diagram we will construct. -/ @[simps!] def FreeCoequalizer.topMap : (Monad.free T).obj (T.obj X.A) ⟶ (Monad.free T).obj X.A := (Monad.free T).map X.a /-- The bottom map in the coequalizer diagram we will construct. -/ @[simps] def FreeCoequalizer.bottomMap : (Monad.free T).obj (T.obj X.A) ⟶ (Monad.free T).obj X.A where f := T.μ.app X.A h := T.assoc X.A /-- The cofork map in the coequalizer diagram we will construct. -/ @[simps] def FreeCoequalizer.π : (Monad.free T).obj X.A ⟶ X where f := X.a h := X.assoc.symm theorem FreeCoequalizer.condition : FreeCoequalizer.topMap X ≫ FreeCoequalizer.π X = FreeCoequalizer.bottomMap X ≫ FreeCoequalizer.π X := Algebra.Hom.ext X.assoc.symm instance : IsReflexivePair (FreeCoequalizer.topMap X) (FreeCoequalizer.bottomMap X) := by apply IsReflexivePair.mk' _ _ _ · apply (free T).map (T.η.app X.A) · ext dsimp rw [← Functor.map_comp, X.unit, Functor.map_id] · ext apply Monad.right_unit /-- Construct the Beck cofork in the category of algebras. This cofork is reflexive as well as a coequalizer. -/ @[simps!] def beckAlgebraCofork : Cofork (FreeCoequalizer.topMap X) (FreeCoequalizer.bottomMap X) := Cofork.ofπ _ (FreeCoequalizer.condition X) /-- The cofork constructed is a colimit. This shows that any algebra is a (reflexive) coequalizer of free algebras. -/ def beckAlgebraCoequalizer : IsColimit (beckAlgebraCofork X) := Cofork.IsColimit.mk' _ fun s => by have h₁ : (T : C ⥤ C).map X.a ≫ s.π.f = T.μ.app X.A ≫ s.π.f := congr_arg Monad.Algebra.Hom.f s.condition have h₂ : (T : C ⥤ C).map s.π.f ≫ s.pt.a = T.μ.app X.A ≫ s.π.f := s.π.h refine ⟨⟨T.η.app _ ≫ s.π.f, ?_⟩, ?_, ?_⟩ · dsimp rw [Functor.map_comp, Category.assoc, h₂, Monad.right_unit_assoc, show X.a ≫ _ ≫ _ = _ from T.η.naturality_assoc _ _, h₁, Monad.left_unit_assoc] · ext simpa [← T.η.naturality_assoc, T.left_unit_assoc] using T.η.app ((T : C ⥤ C).obj X.A) ≫= h₁ · intro m hm ext dsimp only rw [← hm] apply (X.unit_assoc _).symm /-- The Beck cofork is a split coequalizer. -/ def beckSplitCoequalizer : IsSplitCoequalizer (T.map X.a) (T.μ.app _) X.a := ⟨T.η.app _, T.η.app _, X.assoc.symm, X.unit, T.left_unit _, (T.η.naturality _).symm⟩ /-- This is the Beck cofork. It is a split coequalizer, in particular a coequalizer. -/ @[simps! pt] def beckCofork : Cofork (T.map X.a) (T.μ.app _) := (beckSplitCoequalizer X).asCofork @[simp] theorem beckCofork_π : (beckCofork X).π = X.a := rfl /-- The Beck cofork is a coequalizer. -/ def beckCoequalizer : IsColimit (beckCofork X) := (beckSplitCoequalizer X).isCoequalizer @[simp] theorem beckCoequalizer_desc (s : Cofork (T.toFunctor.map X.a) (T.μ.app X.A)) : (beckCoequalizer X).desc s = T.η.app _ ≫ s.π := rfl end Monad end CategoryTheory
Imo1982Q3.lean
/- Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios, Alex Brodbelt -/ import Mathlib.Algebra.Order.Field.GeomSum import Mathlib.Data.NNReal.Basic /-! # IMO 1982 Q3 Consider infinite sequences $\{x_n\}$ of positive reals such that $x_0 = 1$ and $x_0 \ge x_1 \ge x_2 \ge \ldots$ a) Prove that for every such sequence there is an $n \ge 1$ such that: $$\frac{x_0^2}{x_1} + \ldots + \frac{x_{n-1}^2}{x_n} \ge 3.999$$ b) Find such a sequence such that for all $n$: $$\frac{x_0^2}{x_1} + \ldots + \frac{x_{n-1}^2}{x_n} < 4$$ The solution is based on Solution 1 from the [Art of Problem Solving](https://artofproblemsolving.com/wiki/index.php/1982_IMO_Problems/Problem_3) website. For part a, we use Sedrakyan's lemma to show the sum is bounded below by $\frac{4n}{n + 1}$, which can be made arbitrarily close to $4$ by taking large $n$. For part b, we show the sequence $x_n = 2^{-n}$ satisfies the desired inequality. -/ open Finset NNReal variable {x : ℕ → ℝ} {n : ℕ} (hn : n ≠ 0) (hx : Antitone x) namespace Imo1982Q3 include hn hx /-- `x n` is at most the average of all previous terms in the sequence. This is expressed here with `∑ k ∈ range n, x k` added to both sides. -/ lemma le_avg : ∑ k ∈ range (n + 1), x k ≤ (∑ k ∈ range n, x k) * (1 + 1 / n) := by rw [sum_range_succ, mul_one_add, add_le_add_iff_left, mul_one_div, le_div_iff₀ (mod_cast hn.bot_lt), mul_comm, ← nsmul_eq_mul] conv_lhs => rw [← card_range n, ← sum_const] gcongr with i hi refine hx <| le_of_lt ?_ simpa using hi /-- The main inequality used for part a. -/ lemma ineq (h0 : x 0 = 1) (hp : ∀ k, 0 < x k) : 4 * n / (n + 1) ≤ ∑ k ∈ range (n + 1), x k ^ 2 / x (k + 1) := by calc -- We first use AM-GM. _ ≤ (∑ k ∈ range n, x (k + 1) + 1) ^ 2 / (∑ k ∈ range n, x (k + 1)) * n / (n + 1) := by gcongr rw [le_div_iff₀] · simpa using four_mul_le_sq_add (∑ k ∈ range n, x (k + 1)) 1 · exact sum_pos (fun k _ ↦ hp _) (nonempty_range_iff.2 hn) -- We move the fraction into the denominator. _ = (∑ k ∈ range n, x (k + 1) + 1) ^ 2 / ((∑ k ∈ range n, x (k + 1)) * (1 + 1 / n)) := by field_simp -- We make use of the `le_avg` lemma. _ ≤ (∑ k ∈ range (n + 1), x k) ^ 2 / ∑ k ∈ range (n + 1), x (k + 1) := by gcongr · exact sum_pos (fun k _ ↦ hp _) nonempty_range_succ · exact add_nonneg (sum_nonneg fun k _ ↦ (hp _).le) zero_le_one · rw [sum_range_succ', h0] · exact le_avg hn (hx.comp_monotone @Nat.succ_le_succ) -- We conclude by Sedrakyan. _ ≤ _ := sq_sum_div_le_sum_sq_div _ x fun k _ ↦ hp (k + 1) end Imo1982Q3 /-- Part a of the problem is solved by `n = 4000`. -/ theorem imo1982_q3a (hx : Antitone x) (h0 : x 0 = 1) (hp : ∀ k, 0 < x k) : ∃ n : ℕ, 3.999 ≤ ∑ k ∈ range n, (x k) ^ 2 / x (k + 1) := by use 4000 convert Imo1982Q3.ineq (Nat.succ_ne_zero 3998) hx h0 hp norm_num /-- Part b of the problem is solved by `x k = (1 / 2) ^ k`. -/ theorem imo1982_q3b : ∃ x : ℕ → ℝ, Antitone x ∧ x 0 = 1 ∧ (∀ k, 0 < x k) ∧ ∀ n, ∑ k ∈ range n, x k ^ 2 / x (k + 1) < 4 := by refine ⟨fun k ↦ 2⁻¹ ^ k, ?_, pow_zero _, ?_, fun n ↦ ?_⟩ · apply (pow_right_strictAnti₀ _ _).antitone <;> norm_num · simp · have {k : ℕ} : (2 : ℝ)⁻¹ ^ (k * 2) * ((2 : ℝ)⁻¹ ^ k)⁻¹ = (2 : ℝ)⁻¹ ^ k := by rw [← pow_sub₀] <;> simp [mul_two] simp_rw [← pow_mul, pow_succ, ← div_eq_mul_inv, div_div_eq_mul_div, mul_comm, mul_div_assoc, ← mul_sum, div_eq_mul_inv, this, ← two_add_two_eq_four, ← mul_two, mul_lt_mul_iff_of_pos_left two_pos] convert NNReal.coe_lt_coe.2 <| geom_sum_lt (inv_ne_zero two_ne_zero) two_inv_lt_one n · simp · norm_num
ExponentialBounds.lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Joseph Myers -/ import Mathlib.Data.Complex.Exponential import Mathlib.Analysis.SpecialFunctions.Log.Deriv /-! # Bounds on specific values of the exponential -/ namespace Real open IsAbsoluteValue Finset CauSeq Complex theorem exp_one_near_10 : |exp 1 - 2244083 / 825552| ≤ 1 / 10 ^ 10 := by apply exp_approx_start iterate 13 refine exp_1_approx_succ_eq (by norm_num1; rfl) (by norm_cast) ?_ norm_num1 refine exp_approx_end' _ (by norm_num1; rfl) _ (by norm_cast) (by simp) ?_ rw [_root_.abs_one, abs_of_pos] <;> norm_num1 theorem exp_one_near_20 : |exp 1 - 363916618873 / 133877442384| ≤ 1 / 10 ^ 20 := by apply exp_approx_start iterate 21 refine exp_1_approx_succ_eq (by norm_num1; rfl) (by norm_cast) ?_ norm_num1 refine exp_approx_end' _ (by norm_num1; rfl) _ (by norm_cast) (by simp) ?_ rw [_root_.abs_one, abs_of_pos] <;> norm_num1 theorem exp_one_gt_d9 : 2.7182818283 < exp 1 := lt_of_lt_of_le (by norm_num) (sub_le_comm.1 (abs_sub_le_iff.1 exp_one_near_10).2) theorem exp_one_lt_d9 : exp 1 < 2.7182818286 := lt_of_le_of_lt (sub_le_iff_le_add.1 (abs_sub_le_iff.1 exp_one_near_10).1) (by norm_num) theorem exp_neg_one_gt_d9 : 0.36787944116 < exp (-1) := by rw [exp_neg, lt_inv_comm₀ _ (exp_pos _)] · refine lt_of_le_of_lt (sub_le_iff_le_add.1 (abs_sub_le_iff.1 exp_one_near_10).1) ?_ norm_num · norm_num theorem exp_neg_one_lt_d9 : exp (-1) < 0.3678794412 := by rw [exp_neg, inv_lt_comm₀ (exp_pos _) (by norm_num)] exact lt_of_lt_of_le (by norm_num) (sub_le_comm.1 (abs_sub_le_iff.1 exp_one_near_10).2) theorem log_two_near_10 : |log 2 - 287209 / 414355| ≤ 1 / 10 ^ 10 := by suffices |log 2 - 287209 / 414355| ≤ 1 / 17179869184 + (1 / 10 ^ 10 - 1 / 2 ^ 34) by norm_num1 at * assumption have t : |(2⁻¹ : ℝ)| = 2⁻¹ := by rw [abs_of_pos]; norm_num have z := Real.abs_log_sub_add_sum_range_le (show |(2⁻¹ : ℝ)| < 1 by rw [t]; norm_num) 34 rw [t] at z norm_num1 at z rw [one_div (2 : ℝ), log_inv, ← sub_eq_add_neg, _root_.abs_sub_comm] at z apply le_trans (_root_.abs_sub_le _ _ _) (add_le_add z _) simp_rw [sum_range_succ] norm_num rw [abs_of_pos] <;> norm_num theorem log_two_gt_d9 : 0.6931471803 < log 2 := lt_of_lt_of_le (by norm_num1) (sub_le_comm.1 (abs_sub_le_iff.1 log_two_near_10).2) theorem log_two_lt_d9 : log 2 < 0.6931471808 := lt_of_le_of_lt (sub_le_iff_le_add.1 (abs_sub_le_iff.1 log_two_near_10).1) (by norm_num) end Real
Density.lean
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.Order.Field.Basic import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Data.Rat.Cast.Order import Mathlib.Order.Partition.Finpartition import Mathlib.Tactic.GCongr import Mathlib.Tactic.NormNum import Mathlib.Tactic.Positivity import Mathlib.Tactic.Ring /-! # Edge density This file defines the number and density of edges of a relation/graph. ## Main declarations Between two finsets of vertices, * `Rel.interedges`: Finset of edges of a relation. * `Rel.edgeDensity`: Edge density of a relation. * `SimpleGraph.interedges`: Finset of edges of a graph. * `SimpleGraph.edgeDensity`: Edge density of a graph. -/ open Finset variable {𝕜 ι κ α β : Type*} /-! ### Density of a relation -/ namespace Rel section Asymmetric variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] (r : α → β → Prop) [∀ a, DecidablePred (r a)] {s s₁ s₂ : Finset α} {t t₁ t₂ : Finset β} {a : α} {b : β} {δ : 𝕜} /-- Finset of edges of a relation between two finsets of vertices. -/ def interedges (s : Finset α) (t : Finset β) : Finset (α × β) := {e ∈ s ×ˢ t | r e.1 e.2} /-- Edge density of a relation between two finsets of vertices. -/ def edgeDensity (s : Finset α) (t : Finset β) : ℚ := #(interedges r s t) / (#s * #t) variable {r} theorem mem_interedges_iff {x : α × β} : x ∈ interedges r s t ↔ x.1 ∈ s ∧ x.2 ∈ t ∧ r x.1 x.2 := by rw [interedges, mem_filter, Finset.mem_product, and_assoc] theorem mk_mem_interedges_iff : (a, b) ∈ interedges r s t ↔ a ∈ s ∧ b ∈ t ∧ r a b := mem_interedges_iff @[simp] theorem interedges_empty_left (t : Finset β) : interedges r ∅ t = ∅ := by rw [interedges, Finset.empty_product, filter_empty] theorem interedges_mono (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) : interedges r s₂ t₂ ⊆ interedges r s₁ t₁ := fun x ↦ by simp_rw [mem_interedges_iff] exact fun h ↦ ⟨hs h.1, ht h.2.1, h.2.2⟩ variable (r) theorem card_interedges_add_card_interedges_compl (s : Finset α) (t : Finset β) : #(interedges r s t) + #(interedges (fun x y ↦ ¬r x y) s t) = #s * #t := by classical rw [← card_product, interedges, interedges, ← card_union_of_disjoint, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ ↦ Classical.not_not.2 theorem interedges_disjoint_left {s s' : Finset α} (hs : Disjoint s s') (t : Finset β) : Disjoint (interedges r s t) (interedges r s' t) := by rw [Finset.disjoint_left] at hs ⊢ intro _ hx hy rw [mem_interedges_iff] at hx hy exact hs hx.1 hy.1 theorem interedges_disjoint_right (s : Finset α) {t t' : Finset β} (ht : Disjoint t t') : Disjoint (interedges r s t) (interedges r s t') := by rw [Finset.disjoint_left] at ht ⊢ intro _ hx hy rw [mem_interedges_iff] at hx hy exact ht hx.2.1 hy.2.1 section DecidableEq variable [DecidableEq α] [DecidableEq β] lemma interedges_eq_biUnion : interedges r s t = s.biUnion fun x ↦ {y ∈ t | r x y}.map ⟨(x, ·), Prod.mk_right_injective x⟩ := by ext ⟨x, y⟩; simp [mem_interedges_iff] theorem interedges_biUnion_left (s : Finset ι) (t : Finset β) (f : ι → Finset α) : interedges r (s.biUnion f) t = s.biUnion fun a ↦ interedges r (f a) t := by ext simp only [mem_biUnion, mem_interedges_iff, exists_and_right, ← and_assoc] theorem interedges_biUnion_right (s : Finset α) (t : Finset ι) (f : ι → Finset β) : interedges r s (t.biUnion f) = t.biUnion fun b ↦ interedges r s (f b) := by ext a simp only [mem_interedges_iff, mem_biUnion] exact ⟨fun ⟨x₁, ⟨x₂, x₃, x₄⟩, x₅⟩ ↦ ⟨x₂, x₃, x₁, x₄, x₅⟩, fun ⟨x₂, x₃, x₁, x₄, x₅⟩ ↦ ⟨x₁, ⟨x₂, x₃, x₄⟩, x₅⟩⟩ theorem interedges_biUnion (s : Finset ι) (t : Finset κ) (f : ι → Finset α) (g : κ → Finset β) : interedges r (s.biUnion f) (t.biUnion g) = (s ×ˢ t).biUnion fun ab ↦ interedges r (f ab.1) (g ab.2) := by simp_rw [product_biUnion, interedges_biUnion_left, interedges_biUnion_right] end DecidableEq theorem card_interedges_le_mul (s : Finset α) (t : Finset β) : #(interedges r s t) ≤ #s * #t := (card_filter_le _ _).trans (card_product _ _).le theorem edgeDensity_nonneg (s : Finset α) (t : Finset β) : 0 ≤ edgeDensity r s t := by apply div_nonneg <;> exact mod_cast Nat.zero_le _ theorem edgeDensity_le_one (s : Finset α) (t : Finset β) : edgeDensity r s t ≤ 1 := by apply div_le_one_of_le₀ · exact mod_cast card_interedges_le_mul r s t · exact mod_cast Nat.zero_le _ theorem edgeDensity_add_edgeDensity_compl (hs : s.Nonempty) (ht : t.Nonempty) : edgeDensity r s t + edgeDensity (fun x y ↦ ¬r x y) s t = 1 := by rw [edgeDensity, edgeDensity, div_add_div_same, div_eq_one_iff_eq] · exact mod_cast card_interedges_add_card_interedges_compl r s t · exact mod_cast (mul_pos hs.card_pos ht.card_pos).ne' @[simp] theorem edgeDensity_empty_left (t : Finset β) : edgeDensity r ∅ t = 0 := by rw [edgeDensity, Finset.card_empty, Nat.cast_zero, zero_mul, div_zero] @[simp] theorem edgeDensity_empty_right (s : Finset α) : edgeDensity r s ∅ = 0 := by rw [edgeDensity, Finset.card_empty, Nat.cast_zero, mul_zero, div_zero] theorem card_interedges_finpartition_left [DecidableEq α] (P : Finpartition s) (t : Finset β) : #(interedges r s t) = ∑ a ∈ P.parts, #(interedges r a t) := by classical simp_rw [← P.biUnion_parts, interedges_biUnion_left, id] rw [card_biUnion] exact fun x hx y hy h ↦ interedges_disjoint_left r (P.disjoint hx hy h) _ theorem card_interedges_finpartition_right [DecidableEq β] (s : Finset α) (P : Finpartition t) : #(interedges r s t) = ∑ b ∈ P.parts, #(interedges r s b) := by classical simp_rw [← P.biUnion_parts, interedges_biUnion_right, id] rw [card_biUnion] exact fun x hx y hy h ↦ interedges_disjoint_right r _ (P.disjoint hx hy h) theorem card_interedges_finpartition [DecidableEq α] [DecidableEq β] (P : Finpartition s) (Q : Finpartition t) : #(interedges r s t) = ∑ ab ∈ P.parts ×ˢ Q.parts, #(interedges r ab.1 ab.2) := by rw [card_interedges_finpartition_left _ P, sum_product] congr; ext rw [card_interedges_finpartition_right] theorem mul_edgeDensity_le_edgeDensity (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) (hs₂ : s₂.Nonempty) (ht₂ : t₂.Nonempty) : (#s₂ : ℚ) / #s₁ * (#t₂ / #t₁) * edgeDensity r s₂ t₂ ≤ edgeDensity r s₁ t₁ := by have hst : (#s₂ : ℚ) * #t₂ ≠ 0 := by simp [hs₂.ne_empty, ht₂.ne_empty] rw [edgeDensity, edgeDensity, div_mul_div_comm, mul_comm, div_mul_div_cancel₀ hst] gcongr exact interedges_mono hs ht theorem edgeDensity_sub_edgeDensity_le_one_sub_mul (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) (hs₂ : s₂.Nonempty) (ht₂ : t₂.Nonempty) : edgeDensity r s₂ t₂ - edgeDensity r s₁ t₁ ≤ 1 - #s₂ / #s₁ * (#t₂ / #t₁) := by refine (sub_le_sub_left (mul_edgeDensity_le_edgeDensity r hs ht hs₂ ht₂) _).trans ?_ refine le_trans ?_ (mul_le_of_le_one_right ?_ (edgeDensity_le_one r s₂ t₂)) · rw [sub_mul, one_mul] refine sub_nonneg_of_le (mul_le_one₀ ?_ ?_ ?_) · exact div_le_one_of_le₀ ((@Nat.cast_le ℚ).2 (card_le_card hs)) (Nat.cast_nonneg _) · apply div_nonneg <;> exact mod_cast Nat.zero_le _ · exact div_le_one_of_le₀ ((@Nat.cast_le ℚ).2 (card_le_card ht)) (Nat.cast_nonneg _) theorem abs_edgeDensity_sub_edgeDensity_le_one_sub_mul (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) (hs₂ : s₂.Nonempty) (ht₂ : t₂.Nonempty) : |edgeDensity r s₂ t₂ - edgeDensity r s₁ t₁| ≤ 1 - #s₂ / #s₁ * (#t₂ / #t₁) := by refine abs_sub_le_iff.2 ⟨edgeDensity_sub_edgeDensity_le_one_sub_mul r hs ht hs₂ ht₂, ?_⟩ rw [← add_sub_cancel_right (edgeDensity r s₁ t₁) (edgeDensity (fun x y ↦ ¬r x y) s₁ t₁), ← add_sub_cancel_right (edgeDensity r s₂ t₂) (edgeDensity (fun x y ↦ ¬r x y) s₂ t₂), edgeDensity_add_edgeDensity_compl _ (hs₂.mono hs) (ht₂.mono ht), edgeDensity_add_edgeDensity_compl _ hs₂ ht₂, sub_sub_sub_cancel_left] exact edgeDensity_sub_edgeDensity_le_one_sub_mul _ hs ht hs₂ ht₂ theorem abs_edgeDensity_sub_edgeDensity_le_two_mul_sub_sq (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) (hδ₀ : 0 ≤ δ) (hδ₁ : δ < 1) (hs₂ : (1 - δ) * #s₁ ≤ #s₂) (ht₂ : (1 - δ) * #t₁ ≤ #t₂) : |(edgeDensity r s₂ t₂ : 𝕜) - edgeDensity r s₁ t₁| ≤ 2 * δ - δ ^ 2 := by have hδ' : 0 ≤ 2 * δ - δ ^ 2 := by rw [sub_nonneg, sq] gcongr exact hδ₁.le.trans (by simp) rw [← sub_pos] at hδ₁ obtain rfl | hs₂' := s₂.eq_empty_or_nonempty · rw [Finset.card_empty, Nat.cast_zero] at hs₂ simpa [edgeDensity, (nonpos_of_mul_nonpos_right hs₂ hδ₁).antisymm (Nat.cast_nonneg _)] using hδ' obtain rfl | ht₂' := t₂.eq_empty_or_nonempty · rw [Finset.card_empty, Nat.cast_zero] at ht₂ simpa [edgeDensity, (nonpos_of_mul_nonpos_right ht₂ hδ₁).antisymm (Nat.cast_nonneg _)] using hδ' have hr : 2 * δ - δ ^ 2 = 1 - (1 - δ) * (1 - δ) := by ring rw [hr] norm_cast refine (Rat.cast_le.2 <| abs_edgeDensity_sub_edgeDensity_le_one_sub_mul r hs ht hs₂' ht₂').trans ?_ push_cast have h₁ := hs₂'.mono hs have h₂ := ht₂'.mono ht gcongr · refine (le_div_iff₀ ?_).2 hs₂ exact mod_cast h₁.card_pos · refine (le_div_iff₀ ?_).2 ht₂ exact mod_cast h₂.card_pos /-- If `s₂ ⊆ s₁`, `t₂ ⊆ t₁` and they take up all but a `δ`-proportion, then the difference in edge densities is at most `2 * δ`. -/ theorem abs_edgeDensity_sub_edgeDensity_le_two_mul (hs : s₂ ⊆ s₁) (ht : t₂ ⊆ t₁) (hδ : 0 ≤ δ) (hscard : (1 - δ) * #s₁ ≤ #s₂) (htcard : (1 - δ) * #t₁ ≤ #t₂) : |(edgeDensity r s₂ t₂ : 𝕜) - edgeDensity r s₁ t₁| ≤ 2 * δ := by rcases lt_or_ge δ 1 with h | h · exact (abs_edgeDensity_sub_edgeDensity_le_two_mul_sub_sq r hs ht hδ h hscard htcard).trans ((sub_le_self_iff _).2 <| sq_nonneg δ) rw [two_mul] refine (abs_sub _ _).trans (add_le_add (le_trans ?_ h) (le_trans ?_ h)) <;> · rw [abs_of_nonneg] · exact mod_cast edgeDensity_le_one r _ _ · exact mod_cast edgeDensity_nonneg r _ _ end Asymmetric section Symmetric variable {r : α → α → Prop} [DecidableRel r] {s t : Finset α} {a b : α} @[simp] theorem swap_mem_interedges_iff (hr : Symmetric r) {x : α × α} : x.swap ∈ interedges r s t ↔ x ∈ interedges r t s := by rw [mem_interedges_iff, mem_interedges_iff, hr.iff] exact and_left_comm theorem mk_mem_interedges_comm (hr : Symmetric r) : (a, b) ∈ interedges r s t ↔ (b, a) ∈ interedges r t s := @swap_mem_interedges_iff _ _ _ _ _ hr (b, a) theorem card_interedges_comm (hr : Symmetric r) (s t : Finset α) : #(interedges r s t) = #(interedges r t s) := Finset.card_bij (fun (x : α × α) _ ↦ x.swap) (fun _ ↦ (swap_mem_interedges_iff hr).2) (fun _ _ _ _ h ↦ Prod.swap_injective h) fun x h ↦ ⟨x.swap, (swap_mem_interedges_iff hr).2 h, x.swap_swap⟩ theorem edgeDensity_comm (hr : Symmetric r) (s t : Finset α) : edgeDensity r s t = edgeDensity r t s := by rw [edgeDensity, mul_comm, card_interedges_comm hr, edgeDensity] end Symmetric end Rel open Rel /-! ### Density of a graph -/ namespace SimpleGraph variable (G : SimpleGraph α) [DecidableRel G.Adj] {s s₁ s₂ t t₁ t₂ : Finset α} {a b : α} /-- Finset of edges of a relation between two finsets of vertices. -/ def interedges (s t : Finset α) : Finset (α × α) := Rel.interedges G.Adj s t /-- Density of edges of a graph between two finsets of vertices. -/ def edgeDensity : Finset α → Finset α → ℚ := Rel.edgeDensity G.Adj lemma interedges_def (s t : Finset α) : G.interedges s t = {e ∈ s ×ˢ t | G.Adj e.1 e.2} := rfl lemma edgeDensity_def (s t : Finset α) : G.edgeDensity s t = #(G.interedges s t) / (#s * #t) := rfl theorem card_interedges_div_card (s t : Finset α) : (#(G.interedges s t) : ℚ) / (#s * #t) = G.edgeDensity s t := rfl theorem mem_interedges_iff {x : α × α} : x ∈ G.interedges s t ↔ x.1 ∈ s ∧ x.2 ∈ t ∧ G.Adj x.1 x.2 := Rel.mem_interedges_iff theorem mk_mem_interedges_iff : (a, b) ∈ G.interedges s t ↔ a ∈ s ∧ b ∈ t ∧ G.Adj a b := Rel.mk_mem_interedges_iff @[simp] theorem interedges_empty_left (t : Finset α) : G.interedges ∅ t = ∅ := Rel.interedges_empty_left _ theorem interedges_mono : s₂ ⊆ s₁ → t₂ ⊆ t₁ → G.interedges s₂ t₂ ⊆ G.interedges s₁ t₁ := Rel.interedges_mono theorem interedges_disjoint_left (hs : Disjoint s₁ s₂) (t : Finset α) : Disjoint (G.interedges s₁ t) (G.interedges s₂ t) := Rel.interedges_disjoint_left _ hs _ theorem interedges_disjoint_right (s : Finset α) (ht : Disjoint t₁ t₂) : Disjoint (G.interedges s t₁) (G.interedges s t₂) := Rel.interedges_disjoint_right _ _ ht section DecidableEq variable [DecidableEq α] theorem interedges_biUnion_left (s : Finset ι) (t : Finset α) (f : ι → Finset α) : G.interedges (s.biUnion f) t = s.biUnion fun a ↦ G.interedges (f a) t := Rel.interedges_biUnion_left _ _ _ _ theorem interedges_biUnion_right (s : Finset α) (t : Finset ι) (f : ι → Finset α) : G.interedges s (t.biUnion f) = t.biUnion fun b ↦ G.interedges s (f b) := Rel.interedges_biUnion_right _ _ _ _ theorem interedges_biUnion (s : Finset ι) (t : Finset κ) (f : ι → Finset α) (g : κ → Finset α) : G.interedges (s.biUnion f) (t.biUnion g) = (s ×ˢ t).biUnion fun ab ↦ G.interedges (f ab.1) (g ab.2) := Rel.interedges_biUnion _ _ _ _ _ theorem card_interedges_add_card_interedges_compl (h : Disjoint s t) : #(G.interedges s t) + #(Gᶜ.interedges s t) = #s * #t := by rw [← card_product, interedges_def, interedges_def] have : {e ∈ s ×ˢ t | Gᶜ.Adj e.1 e.2} = {e ∈ s ×ˢ t | ¬G.Adj e.1 e.2} := by refine filter_congr fun x hx ↦ ?_ rw [mem_product] at hx rw [compl_adj, and_iff_right (h.forall_ne_finset hx.1 hx.2)] rw [this, ← card_union_of_disjoint, filter_union_filter_neg_eq] exact disjoint_filter.2 fun _ _ ↦ Classical.not_not.2 theorem edgeDensity_add_edgeDensity_compl (hs : s.Nonempty) (ht : t.Nonempty) (h : Disjoint s t) : G.edgeDensity s t + Gᶜ.edgeDensity s t = 1 := by rw [edgeDensity_def, edgeDensity_def, div_add_div_same, div_eq_one_iff_eq] · exact mod_cast card_interedges_add_card_interedges_compl _ h · positivity end DecidableEq theorem card_interedges_le_mul (s t : Finset α) : #(G.interedges s t) ≤ #s * #t := Rel.card_interedges_le_mul _ _ _ theorem edgeDensity_nonneg (s t : Finset α) : 0 ≤ G.edgeDensity s t := Rel.edgeDensity_nonneg _ _ _ theorem edgeDensity_le_one (s t : Finset α) : G.edgeDensity s t ≤ 1 := Rel.edgeDensity_le_one _ _ _ @[simp] theorem edgeDensity_empty_left (t : Finset α) : G.edgeDensity ∅ t = 0 := Rel.edgeDensity_empty_left _ _ @[simp] theorem edgeDensity_empty_right (s : Finset α) : G.edgeDensity s ∅ = 0 := Rel.edgeDensity_empty_right _ _ @[simp] theorem swap_mem_interedges_iff {x : α × α} : x.swap ∈ G.interedges s t ↔ x ∈ G.interedges t s := Rel.swap_mem_interedges_iff G.symm theorem mk_mem_interedges_comm : (a, b) ∈ G.interedges s t ↔ (b, a) ∈ G.interedges t s := Rel.mk_mem_interedges_comm G.symm theorem edgeDensity_comm (s t : Finset α) : G.edgeDensity s t = G.edgeDensity t s := Rel.edgeDensity_comm G.symm s t end SimpleGraph /- Porting note: Commented out `Tactic` namespace. namespace Tactic open Positivity /-- Extension for the `positivity` tactic: `Rel.edgeDensity` and `SimpleGraph.edgeDensity` are always nonnegative. -/ @[positivity] unsafe def positivity_edge_density : expr → tactic strictness | q(Rel.edgeDensity $(r) $(s) $(t)) => nonnegative <$> mk_mapp `` Rel.edgeDensity_nonneg [none, none, r, none, s, t] | q(SimpleGraph.edgeDensity $(G) $(s) $(t)) => nonnegative <$> mk_mapp `` SimpleGraph.edgeDensity_nonneg [none, G, none, s, t] | e => pp e >>= fail ∘ format.bracket "The expression `" "` isn't of the form `Rel.edgeDensity r s t` nor `SimpleGraph.edgeDensity G s t`" end Tactic -/
prime.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 path. From mathcomp Require Import choice fintype div bigop. (******************************************************************************) (* This file contains the definitions of: *) (* prime p <=> p is a prime. *) (* primes m == the sorted list of prime divisors of m > 1, else [::]. *) (* pfactor p e == the value p ^ e of a prime factor (p, e). *) (* NumFactor f == print version of a prime factor, converting the prime *) (* component to a Num (which can print large values). *) (* prime_decomp m == the list of prime factors of m > 1, sorted by primes. *) (* logn p m == the e such that (p ^ e) \in prime_decomp n, else 0. *) (* trunc_log p m == the largest e such that p ^ e <= m, or 0 if p <= 1 or *) (* m is 0. *) (* up_log p m == the smallest e such that m <= p ^ e, or 0 if p <= 1 *) (* pdiv n == the smallest prime divisor of n > 1, else 1. *) (* max_pdiv n == the largest prime divisor of n > 1, else 1. *) (* divisors m == the sorted list of divisors of m > 0, else [::]. *) (* totient n == the Euler totient (#|{i < n | i and n coprime}|). *) (* nat_pred == the type of explicit collective nat predicates. *) (* := simpl_pred nat. *) (* -> We allow the coercion nat >-> nat_pred, interpreting p as pred1 p. *) (* -> We define a predType for nat_pred, enabling the notation p \in pi. *) (* -> We don't have nat_pred >-> pred, which would imply nat >-> Funclass. *) (* pi^' == the complement of pi : nat_pred, i.e., the nat_pred such *) (* that (p \in pi^') = (p \notin pi). *) (* \pi(n) == the set of prime divisors of n, i.e., the nat_pred such *) (* that (p \in \pi(n)) = (p \in primes n). *) (* \pi(A) == the set of primes of #|A|, with A a collective predicate *) (* over a finite Type. *) (* -> The notation \pi(A) is implemented with a collapsible Coercion. The *) (* type of A must coerce to finpred_sort (e.g., by coercing to {set T}) *) (* and not merely implement the predType interface (as seq T does). *) (* -> The expression #|A| will only appear in \pi(A) after simplification *) (* collapses the coercion, so it is advisable to do so early on. *) (* pi.-nat n <=> n > 0 and all prime divisors of n are in pi. *) (* n`_pi == the pi-part of n -- the largest pi.-nat divisor of n. *) (* := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. *) (* -> The nat >-> nat_pred coercion lets us write p.-nat n and n`_p. *) (* In addition to the lemmas relevant to these definitions, this file also *) (* contains the dvdn_sum lemma, so that bigop.v doesn't depend on div.v. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "pi ^'" (format "pi ^'"). Reserved Notation "pi .-nat" (format "pi .-nat"). (* The complexity of any arithmetic operation with the Peano representation *) (* is pretty dreadful, so using algorithms for "harder" problems such as *) (* factoring, that are geared for efficient arithmetic leads to dismal *) (* performance -- it takes a significant time, for instance, to compute the *) (* divisors of just a two-digit number. On the other hand, for Peano *) (* integers, prime factoring (and testing) is linear-time with a small *) (* constant factor -- indeed, the same as converting in and out of a binary *) (* representation. This is implemented by the code below, which is then *) (* used to give the "standard" definitions of prime, primes, and divisors, *) (* which can then be used casually in proofs with moderately-sized numeric *) (* values (indeed, the code here performs well for up to 6-digit numbers). *) Module Import PrimeDecompAux. (* We start with faster mod-2 and 2-valuation functions. *) Fixpoint edivn2 q r := if r is r'.+2 then edivn2 q.+1 r' else (q, r). Lemma edivn2P n : edivn_spec n 2 (edivn2 0 n). Proof. rewrite -[n]odd_double_half addnC -{1}[n./2]addn0 -{1}mul2n mulnC. elim: n./2 {1 4}0 => [|r IHr] q; first by case (odd n) => /=. by rewrite addSnnS; apply: IHr. Qed. Fixpoint elogn2 e q r {struct q} := match q, r with | 0, _ | _, 0 => (e, q) | q'.+1, 1 => elogn2 e.+1 q' q' | q'.+1, r'.+2 => elogn2 e q' r' end. Arguments elogn2 : simpl nomatch. Variant elogn2_spec n : nat * nat -> Type := Elogn2Spec e m of n = 2 ^ e * m.*2.+1 : elogn2_spec n (e, m). Lemma elogn2P n : elogn2_spec n.+1 (elogn2 0 n n). Proof. rewrite -[n.+1]mul1n -[1]/(2 ^ 0) -[n in _ * n.+1](addKn n n) addnn. elim: n {1 4 6}n {2 3}0 (leqnn n) => [|q IHq] [|[|r]] e //=; last first. by move/ltnW; apply: IHq. rewrite subn1 prednK // -mul2n mulnA -expnSr. by rewrite -[q in _ * q.+1](addKn q q) addnn => _; apply: IHq. Qed. Definition ifnz T n (x y : T) := if n is 0 then y else x. Variant ifnz_spec T n (x y : T) : T -> Type := | IfnzPos of n > 0 : ifnz_spec n x y x | IfnzZero of n = 0 : ifnz_spec n x y y. Lemma ifnzP T n (x y : T) : ifnz_spec n x y (ifnz n x y). Proof. by case: n => [|n]; [right | left]. Qed. (* The list of divisors and the Euler function are computed directly from *) (* the decomposition, using a merge_sort variant sort of the divisor list. *) Definition add_divisors f divs := let: (p, e) := f in let add1 divs' := merge leq (map (NatTrec.mul p) divs') divs in iter e add1 divs. Import NatTrec. Definition add_totient_factor f m := let: (p, e) := f in p.-1 * p ^ e.-1 * m. Definition cons_pfactor (p e : nat) pd := ifnz e ((p, e) :: pd) pd. Notation "p ^? e :: pd" := (cons_pfactor p e pd) (at level 30, e at level 30, pd at level 60) : nat_scope. End PrimeDecompAux. (* For pretty-printing. *) Definition NumFactor (f : nat * nat) := ([Num of f.1], f.2). Definition pfactor p e := p ^ e. Section prime_decomp. Import NatTrec. Local Fixpoint prime_decomp_rec m k a b c e := let p := k.*2.+1 in if a is a'.+1 then if b - (ifnz e 1 k - c) is b'.+1 then [rec m, k, a', b', ifnz c c.-1 (ifnz e p.-2 1), e] else if (b == 0) && (c == 0) then let b' := k + a' in [rec b'.*2.+3, k, a', b', k.-1, e.+1] else let bc' := ifnz e (ifnz b (k, 0) (edivn2 0 c)) (b, c) in p ^? e :: ifnz a' [rec m, k.+1, a'.-1, bc'.1 + a', bc'.2, 0] [:: (m, 1)] else if (b == 0) && (c == 0) then [:: (p, e.+2)] else p ^? e :: [:: (m, 1)] where "[ 'rec' m , k , a , b , c , e ]" := (prime_decomp_rec m k a b c e). Definition prime_decomp n := let: (e2, m2) := elogn2 0 n.-1 n.-1 in if m2 < 2 then 2 ^? e2 :: 3 ^? m2 :: [::] else let: (a, bc) := edivn m2.-2 3 in let: (b, c) := edivn (2 - bc) 2 in 2 ^? e2 :: [rec m2.*2.+1, 1, a, b, c, 0]. End prime_decomp. Definition primes n := unzip1 (prime_decomp n). Definition prime p := if prime_decomp p is [:: (_ , 1)] then true else false. Definition nat_pred := simpl_pred nat. Definition pi_arg := nat. Coercion pi_arg_of_nat (n : nat) : pi_arg := n. Coercion pi_arg_of_fin_pred T pT (A : @fin_pred_sort T pT) : pi_arg := #|A|. Arguments pi_arg_of_nat n /. Arguments pi_arg_of_fin_pred {T pT} A /. Definition pi_of (n : pi_arg) : nat_pred := [pred p in primes n]. Notation "\pi ( n )" := (pi_of n) (format "\pi ( n )") : nat_scope. Notation "\p 'i' ( A )" := \pi(#|A|) (format "\p 'i' ( A )") : nat_scope. Definition pdiv n := head 1 (primes n). Definition max_pdiv n := last 1 (primes n). Definition divisors n := foldr add_divisors [:: 1] (prime_decomp n). Definition totient n := foldr add_totient_factor (n > 0) (prime_decomp n). (* Correctness of the decomposition algorithm. *) Lemma prime_decomp_correct : let pd_val pd := \prod_(f <- pd) pfactor f.1 f.2 in let lb_dvd q m := ~~ has [pred d | d %| m] (index_iota 2 q) in let pf_ok f := lb_dvd f.1 f.1 && (0 < f.2) in let pd_ord q pd := path ltn q (unzip1 pd) in let pd_ok q n pd := [/\ n = pd_val pd, all pf_ok pd & pd_ord q pd] in forall n, n > 0 -> pd_ok 1 n (prime_decomp n). Proof. rewrite unlock => pd_val lb_dvd pf_ok pd_ord pd_ok. have leq_pd_ok m p q pd: q <= p -> pd_ok p m pd -> pd_ok q m pd. rewrite /pd_ok /pd_ord; case: pd => [|[r _] pd] //= leqp [<- ->]. by case/andP=> /(leq_trans _)->. have apd_ok m e q p pd: lb_dvd p p || (e == 0) -> q < p -> pd_ok p m pd -> pd_ok q (p ^ e * m) (p ^? e :: pd). - case: e => [|e]; rewrite orbC /= => pr_p ltqp. by rewrite mul1n; apply: leq_pd_ok; apply: ltnW. by rewrite /pd_ok /pd_ord /pf_ok /= pr_p ltqp => [[<- -> ->]]. case=> // n _; rewrite /prime_decomp. case: elogn2P => e2 m2 -> {n}; case: m2 => [|[|abc]]; try exact: apd_ok. rewrite [_.-2]/= !ltnS ltn0 natTrecE; case: edivnP => a bc ->{abc}. case: edivnP => b c def_bc /= ltc2 ltbc3; apply: (apd_ok) => //. move def_m: _.*2.+1 => m; set k := {2}1; rewrite -[2]/k.*2; set e := 0. pose p := k.*2.+1; rewrite -{1}[m]mul1n -[1]/(p ^ e)%N. have{def_m bc def_bc ltc2 ltbc3}: let kb := (ifnz e k 1).*2 in [&& k > 0, p < m, lb_dvd p m, c < kb & lb_dvd p p || (e == 0)] /\ m + (b * kb + c).*2 = p ^ 2 + (a * p).*2. - rewrite -def_m [in lb_dvd _ _]def_m; split=> //=; last first. by rewrite -def_bc addSn -doubleD 2!addSn -addnA subnKC // addnC. rewrite ltc2 /lb_dvd /index_iota /= dvdn2 -def_m. by rewrite [_.+2]lock /= odd_double. have [n] := ubnP a. elim: n => // n IHn in a (k) p m b c (e) * => /ltnSE-le_a_n []. set kb := _.*2; set d := _ + c => /and5P[lt0k ltpm leppm ltc pr_p def_m]. have def_k1: k.-1.+1 = k := ltn_predK lt0k. have def_kb1: kb.-1.+1 = kb by rewrite /kb -def_k1; case e. have eq_bc_0: (b == 0) && (c == 0) = (d == 0). by rewrite addn_eq0 muln_eq0 orbC -def_kb1. have lt1p: 1 < p by rewrite ltnS double_gt0. have co_p_2: coprime p 2 by rewrite /coprime gcdnC gcdnE modn2 /= odd_double. have if_d0: d = 0 -> [/\ m = (p + a.*2) * p, lb_dvd p p & lb_dvd p (p + a.*2)]. move=> d0; have{d0} def_m: m = (p + a.*2) * p. by rewrite d0 addn0 -!mul2n mulnA -mulnDl in def_m *. split=> //; apply/hasPn=> r /(hasPn leppm); apply: contra => /= dv_r. by rewrite def_m dvdn_mull. by rewrite def_m dvdn_mulr. case def_a: a => [|a'] /= in le_a_n *; rewrite !natTrecE -/p {}eq_bc_0. case: d if_d0 def_m => [[//| def_m {}pr_p pr_m'] _ | d _ def_m] /=. rewrite def_m def_a addn0 mulnA -2!expnSr. by split; rewrite /pd_ord /pf_ok /= ?muln1 ?pr_p ?leqnn. apply: apd_ok; rewrite // /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm. rewrite /pf_ok !andbT /=; split=> //; apply: contra leppm. case/hasP=> r /=; rewrite mem_index_iota => /andP[lt1r ltrm] dvrm; apply/hasP. have [ltrp | lepr] := ltnP r p. by exists r; rewrite // mem_index_iota lt1r. case/dvdnP: dvrm => q def_q; exists q; last by rewrite def_q /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1r)) -def_q mul1n ltrm. move: def_m; rewrite def_a addn0 -(@ltn_pmul2r p) // mulnn => <-. apply: (@leq_ltn_trans m); first by rewrite def_q leq_mul. by rewrite -addn1 leq_add2l. have def_k2: k.*2 = ifnz e 1 k * kb. by rewrite /kb; case: (e) => [|e']; rewrite (mul1n, muln2). case def_b': (b - _) => [|b']; last first. have ->: ifnz e k.*2.-1 1 = kb.-1 by rewrite /kb; case e. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split=> //. rewrite lt0k ltpm leppm pr_p andbT /=. by case: ifnzP; [move/ltn_predK->; apply: ltnW | rewrite def_kb1]. apply: (@addIn p.*2). rewrite -2!addnA -!doubleD -addnA -mulSnr -def_a -def_m /d. have ->: b * kb = b' * kb + (k.*2 - c * kb + kb). rewrite addnCA addnC -mulSnr -def_b' def_k2 -mulnBl -mulnDl subnK //. by rewrite ltnW // -subn_gt0 def_b'. rewrite -addnA; congr (_ + (_ + _).*2). case: (c) ltc; first by rewrite -addSnnS def_kb1 subn0 addn0 addnC. rewrite /kb; case e => [[] // _ | e' c' _] /=; last first. by rewrite subnDA subnn addnC addSnnS. by rewrite mul1n -doubleB -doubleD subn1 !addn1 def_k1. have ltdp: d < p. move/eqP: def_b'; rewrite subn_eq0 -(@leq_pmul2r kb); last first. by rewrite -def_kb1. rewrite mulnBl -def_k2 ltnS -(leq_add2r c); move/leq_trans; apply. have{} ltc: c < k.*2. by apply: (leq_trans ltc); rewrite leq_double /kb; case e. rewrite -{2}(subnK (ltnW ltc)) leq_add2r leq_sub2l //. by rewrite -def_kb1 mulnS leq_addr. case def_d: d if_d0 => [|d'] => [[//|{ltdp pr_p}def_m pr_p pr_m'] | _]. rewrite eqxx -doubleS -addnS -def_a doubleD -addSn -/p def_m. rewrite mulnCA mulnC -expnSr. apply: IHn => {n le_a_n}//; rewrite -/p -/kb; split. rewrite lt0k -addn1 leq_add2l {1}def_a pr_m' pr_p /= def_k1 -addnn. by rewrite leq_addr. rewrite -addnA -doubleD addnCA def_a addSnnS def_k1 -(addnC k) -mulnSr. by rewrite -[_.*2.+1]/p mulnDl doubleD addnA -mul2n mulnA mul2n -mulSn. have next_pm: lb_dvd p.+2 m. rewrite /lb_dvd /index_iota (addKn 2) -(subnK lt1p) iotaD has_cat. apply/norP; split; rewrite //= orbF subnKC // orbC. apply/norP; split; apply/dvdnP=> [[q def_q]]. case/hasP: leppm; exists 2; first by rewrite /p -(subnKC lt0k). by rewrite /= def_q dvdn_mull // dvdn2 /= odd_double. move/(congr1 (dvdn p)): def_m; rewrite -!mul2n mulnA -mulnDl. rewrite dvdn_mull // dvdn_addr; last by rewrite def_q dvdn_mull. case/dvdnP=> r; rewrite mul2n => def_r; move: ltdp (congr1 odd def_r). rewrite odd_double -ltn_double def_r -mul2n ltn_pmul2r //. by case: r def_r => [|[|[]]] //; rewrite def_d // mul1n /= odd_double. apply: apd_ok => //; case: a' def_a le_a_n => [|a'] def_a => [_ | lta] /=. rewrite /pd_ok /= /pfactor expn1 muln1 /pd_ord /= ltpm /pf_ok !andbT /=. split=> //; apply: contra next_pm. case/hasP=> q; rewrite mem_index_iota => /andP[lt1q ltqm] dvqm; apply/hasP. have [ltqp | lepq] := ltnP q p.+2. by exists q; rewrite // mem_index_iota lt1q. case/dvdnP: dvqm => r def_r; exists r; last by rewrite def_r /= dvdn_mulr. rewrite mem_index_iota -(ltn_pmul2r (ltnW lt1q)) -def_r mul1n ltqm /=. rewrite -(@ltn_pmul2l p.+2) //; apply: (@leq_ltn_trans m). by rewrite def_r mulnC leq_mul. rewrite -addn2 mulnn sqrnD mul2n muln2 -addnn addnACA. by rewrite def_a mul1n in def_m; rewrite -def_m addnS /= ltnS -addnA leq_addr. set bc := ifnz _ _ _; apply: leq_pd_ok (leqnSn _) _. rewrite -doubleS -{1}[m]mul1n -[1]/(k.+1.*2.+1 ^ 0)%N. apply: IHn; first exact: ltnW. rewrite doubleS -/p [ifnz 0 _ _]/=; do 2?split => //. rewrite orbT next_pm /= -(leq_add2r d.*2) def_m 2!addSnnS -doubleS leq_add. - move: ltc; rewrite /kb {}/bc andbT; case e => //= e' _; case: ifnzP => //. by case: edivn2P. - by rewrite -[ltnLHS]muln1 ltn_pmul2l. by rewrite leq_double def_a mulSn (leq_trans ltdp) ?leq_addr. rewrite mulnDl !muln2 -addnA addnCA doubleD addnCA. rewrite (_ : _ + bc.2 = d); last first. rewrite /d {}/bc /kb -muln2. case: (e) (b) def_b' => //= _ []; first by case: edivn2P. by case c; do 2?case; rewrite // mul1n /= muln2. rewrite def_m 3!doubleS addnC -(addn2 p) sqrnD mul2n muln2 -3!addnA. congr (_ + _); rewrite 4!addnS -!doubleD; congr _.*2.+2.+2. by rewrite def_a -add2n mulnDl -addnA -muln2 -mulnDr mul2n. Qed. Lemma primePn n : reflect (n < 2 \/ exists2 d, 1 < d < n & d %| n) (~~ prime n). Proof. rewrite /prime; case: n => [|[|p2]]; try by do 2!left. case: (@prime_decomp_correct p2.+2) => //; rewrite unlock. case: prime_decomp => [|[q [|[|e]]] pd] //=; last first; last by rewrite andbF. rewrite {1}/pfactor 2!expnS -!mulnA /=. case: (_ ^ _ * _) => [|u -> _ /andP[lt1q _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. have lt0q := ltnW lt1q; rewrite lt1q -[ltnLHS]muln1 ltn_pmul2l //. by rewrite -[2]muln1 leq_mul. rewrite {1}/pfactor expn1; case: pd => [|[r e] pd] /=; last first. case: e => [|e] /=; first by rewrite !andbF. rewrite {1}/pfactor expnS -mulnA. case: (_ ^ _ * _) => [|u -> _ /and3P[lt1q ltqr _]]; first by rewrite !muln0. left; right; exists q; last by rewrite dvdn_mulr. by rewrite lt1q -[ltnLHS]mul1n ltn_mul // -[q.+1]muln1 leq_mul. rewrite muln1 !andbT => def_q pr_q lt1q; right=> [[]] // [d]. by rewrite def_q -mem_index_iota => in_d_2q dv_d_q; case/hasP: pr_q; exists d. Qed. Lemma primeNsig n : ~~ prime n -> 2 <= n -> { d : nat | 1 < d < n & d %| n }. Proof. by move=> /primePn; case: ltnP => // lt1n nP _; apply/sig2W; case: nP. Qed. Lemma primeP p : reflect (p > 1 /\ forall d, d %| p -> xpred2 1 p d) (prime p). Proof. rewrite -[prime p]negbK; have [npr_p | pr_p] := primePn p. right=> [[lt1p pr_p]]; case: npr_p => [|[d n1pd]]. by rewrite ltnNge lt1p. by move/pr_p=> /orP[] /eqP def_d; rewrite def_d ltnn ?andbF in n1pd. have [lep1 | lt1p] := leqP; first by case: pr_p; left. left; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]; case: pr_p; right. exists d; rewrite // andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_nt_dvdP d p : prime p -> d != 1 -> reflect (d = p) (d %| p). Proof. case/primeP=> _ min_p d_neq1; apply: (iffP idP) => [/min_p|-> //]. by rewrite (negPf d_neq1) /= => /eqP. Qed. Arguments primeP {p}. Arguments primePn {n}. Lemma prime_gt1 p : prime p -> 1 < p. Proof. by case/primeP. Qed. Lemma prime_gt0 p : prime p -> 0 < p. Proof. by move/prime_gt1; apply: ltnW. Qed. #[global] Hint Resolve prime_gt1 prime_gt0 : core. Lemma prod_prime_decomp n : n > 0 -> n = \prod_(f <- prime_decomp n) f.1 ^ f.2. Proof. by case/prime_decomp_correct. Qed. Lemma even_prime p : prime p -> p = 2 \/ odd p. Proof. move=> pr_p; case odd_p: (odd p); [by right | left]. have: 2 %| p by rewrite dvdn2 odd_p. by case/primeP: pr_p => _ dv_p /dv_p/(2 =P p). Qed. Lemma prime_oddPn p : prime p -> reflect (p = 2) (~~ odd p). Proof. by move=> p_pr; apply: (iffP idP) => [|-> //]; case/even_prime: p_pr => ->. Qed. Lemma odd_prime_gt2 p : odd p -> prime p -> p > 2. Proof. by move=> odd_p /prime_gt1; apply: odd_gt2. Qed. Lemma mem_prime_decomp n p e : (p, e) \in prime_decomp n -> [/\ prime p, e > 0 & p ^ e %| n]. Proof. case: (posnP n) => [-> //| /prime_decomp_correct[def_n mem_pd ord_pd pd_pe]]. have /andP[pr_p ->] := allP mem_pd _ pd_pe; split=> //; last first. case/splitPr: pd_pe def_n => pd1 pd2 ->. by rewrite big_cat big_cons /= mulnCA dvdn_mulr. have lt1p: 1 < p. apply: (allP (order_path_min ltn_trans ord_pd)). by apply/mapP; exists (p, e). apply/primeP; split=> // d dv_d_p; apply/norP=> [[nd1 ndp]]. case/hasP: pr_p; exists d => //. rewrite mem_index_iota andbC 2!ltn_neqAle ndp eq_sym nd1. by have lt0p := ltnW lt1p; rewrite dvdn_leq // (dvdn_gt0 lt0p). Qed. Lemma prime_coprime p m : prime p -> coprime p m = ~~ (p %| m). Proof. case/primeP=> p_gt1 p_pr; apply/eqP/negP=> [d1 | ndv_pm]. case/dvdnP=> k def_m; rewrite -(addn0 m) def_m gcdnMDl gcdn0 in d1. by rewrite d1 in p_gt1. by apply: gcdn_def => // d /p_pr /orP[] /eqP->. Qed. Lemma dvdn_prime2 p q : prime p -> prime q -> (p %| q) = (p == q). Proof. move=> pr_p pr_q; apply: negb_inj. by rewrite eqn_dvd negb_and -!prime_coprime // coprime_sym orbb. Qed. Lemma Euclid_dvd1 p : prime p -> (p %| 1) = false. Proof. by rewrite dvdn1; case: eqP => // ->. Qed. Lemma Euclid_dvdM m n p : prime p -> (p %| m * n) = (p %| m) || (p %| n). Proof. move=> pr_p; case dv_pm: (p %| m); first exact: dvdn_mulr. by rewrite Gauss_dvdr // prime_coprime // dv_pm. Qed. Lemma Euclid_dvd_prod (I : Type) (r : seq I) (P : pred I) (f : I -> nat) p : prime p -> p %| \prod_(i <- r | P i) f i = \big[orb/false]_(i <- r | P i) (p %| f i). Proof. move=> pP; apply: big_morph=> [x y|]; [exact: Euclid_dvdM | exact: Euclid_dvd1]. Qed. Lemma Euclid_dvdX m n p : prime p -> (p %| m ^ n) = (p %| m) && (n > 0). Proof. case: n => [|n] pr_p; first by rewrite andbF Euclid_dvd1. by apply: (inv_inj negbK); rewrite !andbT -!prime_coprime // coprime_pexpr. Qed. Lemma mem_primes p n : (p \in primes n) = [&& prime p, n > 0 & p %| n]. Proof. rewrite andbCA; have [-> // | /= n_gt0] := posnP. apply/mapP/andP=> [[[q e]]|[pr_p]] /=. case/mem_prime_decomp=> pr_q e_gt0 /dvdnP [u ->] -> {p}. by rewrite -(prednK e_gt0) expnS mulnCA dvdn_mulr. rewrite [n in _ %| n]prod_prime_decomp // big_seq. apply big_ind => [| u v IHu IHv | [q e] /= mem_qe dv_p_qe]. - by rewrite Euclid_dvd1. - by rewrite Euclid_dvdM // => /orP[]. exists (q, e) => //=; case/mem_prime_decomp: mem_qe => pr_q _ _. by rewrite Euclid_dvdX // dvdn_prime2 // in dv_p_qe; case: eqP dv_p_qe. Qed. Lemma sorted_primes n : sorted ltn (primes n). Proof. by case: (posnP n) => [-> // | /prime_decomp_correct[_ _]]; apply: path_sorted. Qed. Lemma all_prime_primes n : all prime (primes n). Proof. by apply/allP => p; rewrite mem_primes => /and3P[]. Qed. Lemma eq_primes m n : (primes m =i primes n) <-> (primes m = primes n). Proof. split=> [eqpr| -> //]. by apply: (irr_sorted_eq ltn_trans ltnn); rewrite ?sorted_primes. Qed. Lemma primes_uniq n : uniq (primes n). Proof. exact: (sorted_uniq ltn_trans ltnn (sorted_primes n)). Qed. (* The smallest prime divisor *) Lemma pi_pdiv n : (pdiv n \in \pi(n)) = (n > 1). Proof. case: n => [|[|n]] //; rewrite /pdiv !inE /primes. have:= prod_prime_decomp (ltn0Sn n.+1); rewrite unlock. by case: prime_decomp => //= pf pd _; rewrite mem_head. Qed. Lemma pdiv_prime n : 1 < n -> prime (pdiv n). Proof. by rewrite -pi_pdiv mem_primes; case/and3P. Qed. Lemma pdiv_dvd n : pdiv n %| n. Proof. by case: n (pi_pdiv n) => [|[|n]] //; rewrite mem_primes=> /and3P[]. Qed. Lemma pi_max_pdiv n : (max_pdiv n \in \pi(n)) = (n > 1). Proof. rewrite !inE -pi_pdiv /max_pdiv /pdiv !inE. by case: (primes n) => //= p ps; rewrite mem_head mem_last. Qed. Lemma max_pdiv_prime n : n > 1 -> prime (max_pdiv n). Proof. by rewrite -pi_max_pdiv mem_primes => /andP[]. Qed. Lemma max_pdiv_dvd n : max_pdiv n %| n. Proof. by case: n (pi_max_pdiv n) => [|[|n]] //; rewrite mem_primes => /andP[]. Qed. Lemma pdiv_leq n : 0 < n -> pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // pdiv_dvd. Qed. Lemma max_pdiv_leq n : 0 < n -> max_pdiv n <= n. Proof. by move=> n_gt0; rewrite dvdn_leq // max_pdiv_dvd. Qed. Lemma pdiv_gt0 n : 0 < pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?pdiv_prime. Qed. Lemma max_pdiv_gt0 n : 0 < max_pdiv n. Proof. by case: n => [|[|n]] //; rewrite prime_gt0 ?max_pdiv_prime. Qed. #[global] Hint Resolve pdiv_gt0 max_pdiv_gt0 : core. Lemma pdiv_min_dvd m d : 1 < d -> d %| m -> pdiv m <= d. Proof. case: (posnP m) => [->|mpos] lt1d dv_d_m; first exact: ltnW. rewrite /pdiv; apply: leq_trans (pdiv_leq (ltnW lt1d)). have: pdiv d \in primes m. by rewrite mem_primes mpos pdiv_prime // (dvdn_trans (pdiv_dvd d)). case: (primes m) (sorted_primes m) => //= p pm ord_pm; rewrite inE. by case/predU1P => [-> | /(allP (order_path_min ltn_trans ord_pm)) /ltnW]. Qed. Lemma max_pdiv_max n p : p \in \pi(n) -> p <= max_pdiv n. Proof. rewrite /max_pdiv !inE => n_p. case/splitPr: n_p (sorted_primes n) => p1 p2; rewrite last_cat -cat_rcons /=. rewrite headI /= cat_path -(last_cons 0) -headI last_rcons; case/andP=> _. move/(order_path_min ltn_trans); case/lastP: p2 => //= p2 q. by rewrite all_rcons last_rcons ltn_neqAle -andbA => /and3P[]. Qed. Lemma ltn_pdiv2_prime n : 0 < n -> n < pdiv n ^ 2 -> prime n. Proof. case def_n: n => [|[|n']] // _; rewrite -def_n => lt_n_p2. suffices ->: n = pdiv n by rewrite pdiv_prime ?def_n. apply/eqP; rewrite eqn_leq leqNgt andbC pdiv_leq; last by rewrite def_n. apply/contraL: lt_n_p2 => lt_pm_m; case/dvdnP: (pdiv_dvd n) => q def_q. rewrite -leqNgt [leqRHS]def_q leq_pmul2r // pdiv_min_dvd //. by rewrite -[pdiv n]mul1n [ltnRHS]def_q ltn_pmul2r in lt_pm_m. by rewrite def_q dvdn_mulr. Qed. Lemma primePns n : reflect (n < 2 \/ exists p, [/\ prime p, p ^ 2 <= n & p %| n]) (~~ prime n). Proof. apply: (iffP idP) => [npr_p|]; last first. case=> [|[p [pr_p le_p2_n dv_p_n]]]; first by case: n => [|[]]. apply/negP=> pr_n; move: dv_p_n le_p2_n; rewrite dvdn_prime2 //; move/eqP->. by rewrite leqNgt -[ltnLHS]muln1 ltn_pmul2l ?prime_gt1 ?prime_gt0. have [lt1p|] := leqP; [right | by left]. exists (pdiv n); rewrite pdiv_dvd pdiv_prime //; split=> //. by case: leqP npr_p => // /ltn_pdiv2_prime -> //; exact: ltnW. Qed. Arguments primePns {n}. Lemma pdivP n : n > 1 -> {p | prime p & p %| n}. Proof. by move=> lt1n; exists (pdiv n); rewrite ?pdiv_dvd ?pdiv_prime. Qed. Lemma primes_eq0 n : (primes n == [::]) = (n < 2). Proof. case: n => [|[|n']]//=; have [//|p pp pn] := @pdivP (n'.+2). suff: p \in primes n'.+2 by case: primes. by rewrite mem_primes pp pn. Qed. Lemma primesM m n p : m > 0 -> n > 0 -> (p \in primes (m * n)) = (p \in primes m) || (p \in primes n). Proof. move=> m_gt0 n_gt0; rewrite !mem_primes muln_gt0 m_gt0 n_gt0. by case pr_p: (prime p); rewrite // Euclid_dvdM. Qed. Lemma primesX m n : n > 0 -> primes (m ^ n) = primes m. Proof. case: n => // n _; rewrite expnS; have [-> // | m_gt0] := posnP m. apply/eq_primes => /= p; elim: n => [|n IHn]; first by rewrite muln1. by rewrite primesM ?(expn_gt0, expnS, IHn, orbb, m_gt0). Qed. Lemma primes_prime p : prime p -> primes p = [:: p]. Proof. move=> pr_p; apply: (irr_sorted_eq ltn_trans ltnn) => // [|q]. exact: sorted_primes. rewrite mem_seq1 mem_primes prime_gt0 //=. by apply/andP/idP=> [[pr_q q_p] | /eqP-> //]; rewrite -dvdn_prime2. Qed. Lemma coprime_has_primes m n : 0 < m -> 0 < n -> coprime m n = ~~ has [in primes m] (primes n). Proof. move=> m_gt0 n_gt0; apply/eqP/hasPn=> [mn1 p | no_p_mn]. rewrite /= !mem_primes m_gt0 n_gt0 /= => /andP[pr_p p_n]. have:= prime_gt1 pr_p; rewrite pr_p ltnNge -mn1 /=; apply: contra => p_m. by rewrite dvdn_leq ?gcdn_gt0 ?m_gt0 // dvdn_gcd ?p_m. apply/eqP; rewrite eqn_leq gcdn_gt0 m_gt0 andbT leqNgt; apply/negP. move/pdiv_prime; set p := pdiv _ => pr_p. move/implyP: (no_p_mn p); rewrite /= !mem_primes m_gt0 n_gt0 pr_p /=. by rewrite !(dvdn_trans (pdiv_dvd _)) // (dvdn_gcdl, dvdn_gcdr). Qed. Lemma pdiv_id p : prime p -> pdiv p = p. Proof. by move=> p_pr; rewrite /pdiv primes_prime. Qed. Lemma pdiv_pfactor p k : prime p -> pdiv (p ^ k.+1) = p. Proof. by move=> p_pr; rewrite /pdiv primesX ?primes_prime. Qed. (* Primes are unbounded. *) Lemma prime_above m : {p | m < p & prime p}. Proof. have /pdivP[p pr_p p_dv_m1]: 1 < m`! + 1 by rewrite addn1 ltnS fact_gt0. exists p => //; rewrite ltnNge; apply: contraL p_dv_m1 => p_le_m. by rewrite dvdn_addr ?dvdn_fact ?prime_gt0 // gtnNdvd ?prime_gt1. Qed. (* "prime" logarithms and p-parts. *) Fixpoint logn_rec d m r := match r, edivn m d with | r'.+1, (_.+1 as m', 0) => (logn_rec d m' r').+1 | _, _ => 0 end. Definition logn p m := if prime p then logn_rec p m m else 0. Lemma lognE p m : logn p m = if [&& prime p, 0 < m & p %| m] then (logn p (m %/ p)).+1 else 0. Proof. rewrite /logn /dvdn; case p_pr: (prime p) => //. case def_m: m => // [m']; rewrite !andTb [LHS]/= -def_m /divn modn_def. case: edivnP def_m => [[|q] [|r] -> _] // def_m; congr _.+1; rewrite [_.1]/=. have{m def_m}: q < m'. by rewrite -ltnS -def_m addn0 mulnC -{1}[q.+1]mul1n ltn_pmul2r // prime_gt1. elim/ltn_ind: m' {q}q.+1 (ltn0Sn q) => -[_ []|r IHr m] //= m_gt0 le_mr. rewrite -[m in logn_rec _ _ m]prednK //=. case: edivnP => [[|q] [|_] def_q _] //; rewrite addn0 in def_q. have{def_q} lt_qm1: q < m.-1. by rewrite -[q.+1]muln1 -ltnS prednK // def_q ltn_pmul2l // prime_gt1. have{le_mr} le_m1r: m.-1 <= r by rewrite -ltnS prednK. by rewrite (IHr r) ?(IHr m.-1) // (leq_trans lt_qm1). Qed. Lemma logn_gt0 p n : (0 < logn p n) = (p \in primes n). Proof. by rewrite lognE -mem_primes; case: {+}(p \in _). Qed. Lemma ltn_log0 p n : n < p -> logn p n = 0. Proof. by case: n => [|n] ltnp; rewrite lognE ?andbF // gtnNdvd ?andbF. Qed. Lemma logn0 p : logn p 0 = 0. Proof. by rewrite /logn if_same. Qed. Lemma logn1 p : logn p 1 = 0. Proof. by rewrite lognE dvdn1 /= andbC; case: eqP => // ->. Qed. Lemma pfactor_gt0 p n : 0 < p ^ logn p n. Proof. by rewrite expn_gt0 lognE; case: (posnP p) => // ->. Qed. #[global] Hint Resolve pfactor_gt0 : core. Lemma pfactor_dvdn p n m : prime p -> m > 0 -> (p ^ n %| m) = (n <= logn p m). Proof. move=> p_pr; elim: n m => [|n IHn] m m_gt0; first exact: dvd1n. rewrite lognE p_pr m_gt0 /=; case dv_pm: (p %| m); last first. apply/dvdnP=> [] [/= q def_m]. by rewrite def_m expnS mulnCA dvdn_mulr in dv_pm. case/dvdnP: dv_pm m_gt0 => q ->{m}; rewrite muln_gt0 => /andP[p_gt0 q_gt0]. by rewrite expnSr dvdn_pmul2r // mulnK // IHn. Qed. Lemma pfactor_dvdnn p n : p ^ logn p n %| n. Proof. case: n => // n; case pr_p: (prime p); first by rewrite pfactor_dvdn. by rewrite lognE pr_p dvd1n. Qed. Lemma logn_prime p q : prime q -> logn p q = (p == q). Proof. move=> pr_q; have q_gt0 := prime_gt0 pr_q; rewrite lognE q_gt0 /=. case pr_p: (prime p); last by case: eqP pr_p pr_q => // -> ->. by rewrite dvdn_prime2 //; case: eqP => // ->; rewrite divnn q_gt0 logn1. Qed. Lemma pfactor_coprime p n : prime p -> n > 0 -> {m | coprime p m & n = m * p ^ logn p n}. Proof. move=> p_pr n_gt0; set k := logn p n. have dv_pk_n: p ^ k %| n by rewrite pfactor_dvdn. exists (n %/ p ^ k); last by rewrite divnK. rewrite prime_coprime // -(@dvdn_pmul2r (p ^ k)) ?expn_gt0 ?prime_gt0 //. by rewrite -expnS divnK // pfactor_dvdn // ltnn. Qed. Lemma pfactorK p n : prime p -> logn p (p ^ n) = n. Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply/eqP; rewrite eqn_leq -pfactor_dvdn // dvdnn andbT. by rewrite -(leq_exp2l _ _ (prime_gt1 p_pr)) dvdn_leq // pfactor_dvdn. Qed. Lemma pfactorKpdiv p n : prime p -> logn (pdiv (p ^ n)) (p ^ n) = n. Proof. by case: n => // n p_pr; rewrite pdiv_pfactor ?pfactorK. Qed. Lemma dvdn_leq_log p m n : 0 < n -> m %| n -> logn p m <= logn p n. Proof. move=> n_gt0 dv_m_n; have m_gt0 := dvdn_gt0 n_gt0 dv_m_n. case p_pr: (prime p); last by do 2!rewrite lognE p_pr /=. by rewrite -pfactor_dvdn //; apply: dvdn_trans dv_m_n; rewrite pfactor_dvdn. Qed. Lemma ltn_logl p n : 0 < n -> logn p n < n. Proof. move=> n_gt0; have [p_gt1 | p_le1] := boolP (1 < p). by rewrite (leq_trans (ltn_expl _ p_gt1)) // dvdn_leq ?pfactor_dvdnn. by rewrite lognE (contraNF (@prime_gt1 _)). Qed. Lemma logn_Gauss p m n : coprime p m -> logn p (m * n) = logn p n. Proof. move=> co_pm; case p_pr: (prime p); last by rewrite /logn p_pr. have [-> | n_gt0] := posnP n; first by rewrite muln0. have [m0 | m_gt0] := posnP m; first by rewrite m0 prime_coprime ?dvdn0 in co_pm. have mn_gt0: m * n > 0 by rewrite muln_gt0 m_gt0. apply/eqP; rewrite eqn_leq andbC dvdn_leq_log ?dvdn_mull //. set k := logn p _; have: p ^ k %| m * n by rewrite pfactor_dvdn. by rewrite Gauss_dvdr ?coprimeXl // -pfactor_dvdn. Qed. Lemma logn_coprime p m : coprime p m -> logn p m = 0. Proof. by move=> coprime_pm; rewrite -[m]muln1 logn_Gauss// logn1. Qed. Lemma lognM p m n : 0 < m -> 0 < n -> logn p (m * n) = logn p m + logn p n. Proof. case p_pr: (prime p); last by rewrite /logn p_pr. have xlp := pfactor_coprime p_pr. case/xlp=> m' co_m' def_m /xlp[n' co_n' def_n] {xlp}. rewrite [in LHS]def_m [in LHS]def_n mulnCA -mulnA -expnD !logn_Gauss //. exact: pfactorK. Qed. Lemma lognX p m n : logn p (m ^ n) = n * logn p m. Proof. case p_pr: (prime p); last by rewrite /logn p_pr muln0. elim: n => [|n IHn]; first by rewrite logn1. have [->|m_gt0] := posnP m; first by rewrite exp0n // lognE andbF muln0. by rewrite expnS lognM ?IHn // expn_gt0 m_gt0. Qed. Lemma logn_div p m n : m %| n -> logn p (n %/ m) = logn p n - logn p m. Proof. rewrite dvdn_eq => /eqP def_n. case: (posnP n) => [-> |]; first by rewrite div0n logn0. by rewrite -{1 3}def_n muln_gt0 => /andP[q_gt0 m_gt0]; rewrite lognM ?addnK. Qed. Lemma dvdn_pfactor p d n : prime p -> reflect (exists2 m, m <= n & d = p ^ m) (d %| p ^ n). Proof. move=> p_pr; have pn_gt0: p ^ n > 0 by rewrite expn_gt0 prime_gt0. apply: (iffP idP) => [dv_d_pn|[m le_m_n ->]]; last first. by rewrite -(subnK le_m_n) expnD dvdn_mull. exists (logn p d); first by rewrite -(pfactorK n p_pr) dvdn_leq_log. have d_gt0: d > 0 by apply: dvdn_gt0 dv_d_pn. case: (pfactor_coprime p_pr d_gt0) => q co_p_q def_d. rewrite [LHS]def_d ((q =P 1) _) ?mul1n // -dvdn1. suff: q %| p ^ n * 1 by rewrite Gauss_dvdr // coprime_sym coprimeXl. by rewrite muln1 (dvdn_trans _ dv_d_pn) // def_d dvdn_mulr. Qed. Lemma prime_decompE n : prime_decomp n = [seq (p, logn p n) | p <- primes n]. Proof. case: n => // n; pose f0 := (0, 0); rewrite -map_comp. apply: (@eq_from_nth _ f0) => [|i lt_i_n]; first by rewrite size_map. rewrite (nth_map f0) //; case def_f: (nth _ _ i) => [p e] /=. congr (_, _); rewrite [n.+1]prod_prime_decomp //. have: (p, e) \in prime_decomp n.+1 by rewrite -def_f mem_nth. case/mem_prime_decomp=> pr_p _ _. rewrite (big_nth f0) big_mkord (bigD1 (Ordinal lt_i_n)) //=. rewrite def_f mulnC logn_Gauss ?pfactorK //. apply big_ind => [|m1 m2 com1 com2| [j ltj] /=]; first exact: coprimen1. by rewrite coprimeMr com1. rewrite -val_eqE /= => nji; case def_j: (nth _ _ j) => [q e1] /=. have: (q, e1) \in prime_decomp n.+1 by rewrite -def_j mem_nth. case/mem_prime_decomp=> pr_q e1_gt0 _; rewrite coprime_pexpr //. rewrite prime_coprime // dvdn_prime2 //; apply: contra nji => eq_pq. rewrite -(nth_uniq 0 _ _ (primes_uniq n.+1)) ?size_map //=. by rewrite !(nth_map f0) // def_f def_j /= eq_sym. Qed. (* Some combinatorial formulae. *) Lemma divn_count_dvd d n : n %/ d = \sum_(1 <= i < n.+1) (d %| i). Proof. have [-> | d_gt0] := posnP d; first by rewrite big_add1 divn0 big1. apply: (@addnI (d %| 0)); rewrite -(@big_ltn _ 0 _ 0 _ (dvdn d)) // big_mkord. rewrite (partition_big (fun i : 'I_n.+1 => inord (i %/ d)) 'I_(n %/ d).+1) //=. rewrite dvdn0 add1n -[_.+1 in LHS]card_ord -sum1_card. apply: eq_bigr => [[q ?] _]. rewrite (bigD1 (inord (q * d))) /eq_op /= !inordK ?ltnS -?leq_divRL ?mulnK //. rewrite dvdn_mull ?big1 // => [[i /= ?] /andP[/eqP <- /negPf]]. by rewrite eq_sym dvdn_eq inordK ?ltnS ?leq_div2r // => ->. Qed. Lemma logn_count_dvd p n : prime p -> logn p n = \sum_(1 <= k < n) (p ^ k %| n). Proof. rewrite big_add1 => p_prime; case: n => [|n]; first by rewrite logn0 big_geq. rewrite big_mkord -big_mkcond (eq_bigl _ _ (fun _ => pfactor_dvdn _ _ _)) //=. by rewrite big_ord_narrow ?sum1_card ?card_ord // -ltnS ltn_logl. Qed. (* Truncated real log. *) Definition trunc_log p n := let fix loop n k := if k is k'.+1 then if p <= n then (loop (n %/ p) k').+1 else 0 else 0 in if p <= 1 then 0 else loop n n. Lemma trunc_log0 p : trunc_log p 0 = 0. Proof. by case: p => [] // []. Qed. Lemma trunc_log1 p : trunc_log p 1 = 0. Proof. by case: p => [|[]]. Qed. Lemma trunc_log_bounds p n : 1 < p -> 0 < n -> let k := trunc_log p n in p ^ k <= n < p ^ k.+1. Proof. rewrite {+}/trunc_log => p_gt1; have p_gt0 := ltnW p_gt1. rewrite [p <= 1]leqNgt p_gt1 /=. set loop := (loop in loop n n); set m := n; rewrite [in n in loop m n]/m. have: m <= n by []; elim: n m => [|n IHn] [|m] //= /ltnSE-le_m_n _. have [le_p_n | // ] := leqP p _; rewrite 2!expnSr -leq_divRL -?ltn_divLR //. by apply: IHn; rewrite ?divn_gt0 // -ltnS (leq_trans (ltn_Pdiv _ _)). Qed. Lemma trunc_logP p n : 1 < p -> 0 < n -> p ^ trunc_log p n <= n. Proof. by move=> p_gt1 /(trunc_log_bounds p_gt1)/andP[]. Qed. Lemma trunc_log_ltn p n : 1 < p -> n < p ^ (trunc_log p n).+1. Proof. have [-> | n_gt0] := posnP n; first by rewrite trunc_log0 => /ltnW. by case/trunc_log_bounds/(_ n_gt0)/andP. Qed. Lemma trunc_log_max p k j : 1 < p -> p ^ j <= k -> j <= trunc_log p k. Proof. move=> p_gt1 le_pj_k; rewrite -ltnS -(@ltn_exp2l p) //. exact: leq_ltn_trans (trunc_log_ltn _ _). Qed. Lemma trunc_log_eq0 p n : (trunc_log p n == 0) = (p <= 1) || (n <= p.-1). Proof. case: p => [|[|p]]; case: n => // n; rewrite /= ltnS. have /= /andP[] := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+1). case: trunc_log => [//|k] b1 b2. apply/idP/idP => [/eqP sk0 | nlep]; first by move: b2; rewrite sk0. symmetry; rewrite -[_ == _]/false /is_true -b1; apply/negbTE; rewrite -ltnNge. move: nlep; rewrite -ltnS => nlep; apply: (leq_ltn_trans nlep). by rewrite -[leqLHS]expn1; apply: leq_pexp2l. Qed. Lemma trunc_log_gt0 p n : (0 < trunc_log p n) = (1 < p) && (p.-1 < n). Proof. by rewrite ltnNge leqn0 trunc_log_eq0 negb_or -!ltnNge. Qed. Lemma trunc_log0n n : trunc_log 0 n = 0. Proof. by []. Qed. Lemma trunc_log1n n : trunc_log 1 n = 0. Proof. by []. Qed. Lemma leq_trunc_log p m n : m <= n -> trunc_log p m <= trunc_log p n. Proof. move=> mlen; case: p => [|[|p]]; rewrite ?trunc_log0n ?trunc_log1n //. case: m mlen => [|m] mlen; first by rewrite trunc_log0. apply/trunc_log_max => //; apply: leq_trans mlen; exact: trunc_logP. Qed. Lemma trunc_log_eq p n k : 1 < p -> p ^ n <= k < p ^ n.+1 -> trunc_log p k = n. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/anti_leq. rewrite trunc_log_max// andbT -ltnS -(ltn_exp2l _ _ p_gt1). apply: leq_ltn_trans kLpn; apply: trunc_logP => //. by apply: leq_trans npLk; rewrite expn_gt0 ltnW. Qed. Lemma trunc_lognn p : 1 < p -> trunc_log p p = 1. Proof. by case: p => [|[|p]] // _; rewrite /trunc_log ltnSn divnn. Qed. Lemma trunc_expnK p n : 1 < p -> trunc_log p (p ^ n) = n. Proof. by move=> ?; apply: trunc_log_eq; rewrite // leqnn ltn_exp2l /=. Qed. Lemma trunc_logMp p n : 1 < p -> 0 < n -> trunc_log p (p * n) = (trunc_log p n).+1. Proof. case: p => [//|p] => p_gt0 n_gt0; apply: trunc_log_eq => //. rewrite expnS leq_pmul2l// trunc_logP//=. by rewrite expnS ltn_pmul2l// trunc_log_ltn. Qed. Lemma trunc_log2_double n : 0 < n -> trunc_log 2 n.*2 = (trunc_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n trunc_logMp. Qed. Lemma trunc_log2S n : 1 < n -> trunc_log 2 n = (trunc_log 2 n./2).+1. Proof. move=> n_gt1. rewrite -trunc_log2_double ?half_gt0//. rewrite -[n in LHS]odd_double_half. case: odd => //; rewrite add1n. apply: trunc_log_eq => //. rewrite leqW ?trunc_logP //= ?double_gt0 ?half_gt0//. rewrite trunc_log2_double ?half_gt0// expnS. by rewrite -doubleS mul2n leq_double trunc_log_ltn. Qed. (* Truncated up real logarithm *) Definition up_log p n := if (p <= 1) then 0 else let v := trunc_log p n in if n <= p ^ v then v else v.+1. Lemma up_log0 p : up_log p 0 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log1 p : up_log p 1 = 0. Proof. by case: p => // [] []. Qed. Lemma up_log_eq0 p n : (up_log p n == 0) = (p <= 1) || (n <= 1). Proof. case: p => // [] [] // p. case: n => [|[|n]]; rewrite /up_log //=. have /= := trunc_log_bounds (isT : 1 < p.+2) (isT : 0 < n.+2). by case: (leqP _ n.+1); case: trunc_log. Qed. Lemma up_log_gt0 p n : (0 < up_log p n) = (1 < p) && (1 < n). Proof. by rewrite ltnNge leqn0 up_log_eq0 negb_or -!ltnNge. Qed. Lemma up_log_bounds p n : 1 < p -> 1 < n -> let k := up_log p n in p ^ k.-1 < n <= p ^ k. Proof. move=> p_gt1 n_gt1. have n_gt0 : 0 < n by apply: leq_trans n_gt1. rewrite /up_log (leqNgt p 1) p_gt1 /=. have /= /andP[tpLn nLtpS] := trunc_log_bounds p_gt1 n_gt0. have [nLnp|npLn] := leqP n (p ^ trunc_log p n); last by rewrite npLn ltnW. rewrite nLnp (leq_trans _ tpLn) // ltn_exp2l // prednK ?leqnn //. by case: trunc_log (leq_trans n_gt1 nLnp). Qed. Lemma up_logP p n : 1 < p -> n <= p ^ up_log p n. Proof. case: n => [|[|n]] // p_gt1; first by rewrite up_log1. by have /andP[] := up_log_bounds p_gt1 (isT: 1 < n.+2). Qed. Lemma up_log_gtn p n : 1 < p -> 1 < n -> p ^ (up_log p n).-1 < n. Proof. by case: n => [|[|n]] p_gt1 n_gt1 //; have /andP[] := up_log_bounds p_gt1 n_gt1. Qed. Lemma up_log_min p k j : 1 < p -> k <= p ^ j -> up_log p k <= j. Proof. case: k => [|[|k]] // p_gt1 kLj; rewrite ?(up_log0, up_log1) //. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt1 // -(@ltn_exp2l p) //. by apply: leq_trans (up_log_gtn p_gt1 (isT : 1 < k.+2)) _. Qed. Lemma leq_up_log p m n : m <= n -> up_log p m <= up_log p n. Proof. move=> mLn; case: p => [|[|p]] //. by apply/up_log_min => //; apply: leq_trans mLn (up_logP _ _). Qed. Lemma up_log_eq p n k : 1 < p -> p ^ n < k <= p ^ n.+1 -> up_log p k = n.+1. Proof. move=> p_gt1 /andP[npLk kLpn]; apply/eqP; rewrite eqn_leq. apply/andP; split; first by apply: up_log_min. rewrite -(ltn_exp2l _ _ p_gt1) //. by apply: leq_trans npLk (up_logP _ _). Qed. Lemma up_lognn p : 1 < p -> up_log p p = 1. Proof. by move=> p_gt1; apply: up_log_eq; rewrite p_gt1 /=. Qed. Lemma up_expnK p n : 1 < p -> up_log p (p ^ n) = n. Proof. case: n => [|n] p_gt1 /=; first by rewrite up_log1. by apply: up_log_eq; rewrite // leqnn andbT ltn_exp2l. Qed. Lemma up_logMp p n : 1 < p -> 0 < n -> up_log p (p * n) = (up_log p n).+1. Proof. case: p => [//|p] p_gt0. case: n => [//|[|n]] _; first by rewrite muln1 up_lognn// up_log1. apply: up_log_eq => //. rewrite expnS leq_pmul2l// up_logP// andbT. rewrite -[up_log _ _]prednK ?up_log_gt0 ?p_gt0 //. by rewrite expnS ltn_pmul2l// up_log_gtn. Qed. Lemma up_log2_double n : 0 < n -> up_log 2 n.*2 = (up_log 2 n).+1. Proof. by move=> n_gt0; rewrite -mul2n up_logMp. Qed. Lemma up_log2S n : 0 < n -> up_log 2 n.+1 = (up_log 2 (n./2.+1)).+1. Proof. case: n=> // [] [|n] // _. apply: up_log_eq => //; apply/andP; split. apply: leq_trans (_ : n./2.+1.*2 < n.+3); last first. by rewrite doubleS !ltnS -[leqRHS]odd_double_half leq_addl. have /= /andP[H1n _] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). by rewrite ltnS -leq_double -mul2n -expnS prednK ?up_log_gt0 // in H1n. rewrite -[_./2.+1]/(n./2.+2). have /= /andP[_ H2n] := up_log_bounds (isT : 1 < 2) (isT : 1 < n./2.+2). rewrite -leq_double -!mul2n -expnS in H2n. apply: leq_trans H2n. rewrite mul2n !doubleS !ltnS. by rewrite -[leqLHS]odd_double_half -add1n leq_add2r; case: odd. Qed. Lemma up_log_trunc_log p n : 1 < p -> 1 < n -> up_log p n = (trunc_log p n.-1).+1. Proof. move=> p_gt1 n_gt1; apply: up_log_eq => //. rewrite -[n]prednK ?ltnS -?pred_Sn ?[0 < n]ltnW//. by rewrite trunc_logP ?ltn_predRL// trunc_log_ltn. Qed. Lemma trunc_log_up_log p n : 1 < p -> 0 < n -> trunc_log p n = (up_log p n.+1).-1. Proof. by move=> ? ?; rewrite up_log_trunc_log. Qed. (* pi- parts *) (* Testing for membership in set of prime factors. *) Canonical nat_pred_pred := Eval hnf in [predType of nat_pred]. Coercion nat_pred_of_nat (p : nat) : nat_pred := pred1 p. Section NatPreds. Variables (n : nat) (pi : nat_pred). Definition negn : nat_pred := [predC pi]. Definition pnat : pred nat := fun m => (m > 0) && all [in pi] (primes m). Definition partn := \prod_(0 <= p < n.+1 | p \in pi) p ^ logn p n. End NatPreds. Notation "pi ^'" := (negn pi) : nat_scope. Notation "pi .-nat" := (pnat pi) : nat_scope. Notation "n `_ pi" := (partn n pi) : nat_scope. Section PnatTheory. Implicit Types (n p : nat) (pi rho : nat_pred). Lemma negnK pi : pi^'^' =i pi. Proof. by move=> p; apply: negbK. Qed. Lemma eq_negn pi1 pi2 : pi1 =i pi2 -> pi1^' =i pi2^'. Proof. by move=> eq_pi n; rewrite inE eq_pi. Qed. Lemma eq_piP m n : \pi(m) =i \pi(n) <-> \pi(m) = \pi(n). Proof. rewrite /pi_of; have eqs := irr_sorted_eq ltn_trans ltnn. by split=> [|-> //] /(eqs _ _ (sorted_primes m) (sorted_primes n)) ->. Qed. Lemma part_gt0 pi n : 0 < n`_pi. Proof. exact: prodn_gt0. Qed. Hint Resolve part_gt0 : core. Lemma sub_in_partn pi1 pi2 n : {in \pi(n), {subset pi1 <= pi2}} -> n`_pi1 %| n`_pi2. Proof. move=> pi12; rewrite ![n`__]big_mkcond /=. apply (big_ind2 (fun m1 m2 => m1 %| m2)) => // [*|p _]; first exact: dvdn_mul. rewrite lognE -mem_primes; case: ifP => pi1p; last exact: dvd1n. by case: ifP => pr_p; [rewrite pi12 | rewrite if_same]. Qed. Lemma eq_in_partn pi1 pi2 n : {in \pi(n), pi1 =i pi2} -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply/eqP; rewrite eqn_dvd ?sub_in_partn // => p /pi12->. Qed. Lemma eq_partn pi1 pi2 n : pi1 =i pi2 -> n`_pi1 = n`_pi2. Proof. by move=> pi12; apply: eq_in_partn => p _. Qed. Lemma partnNK pi n : n`_pi^'^' = n`_pi. Proof. by apply: eq_partn; apply: negnK. Qed. Lemma widen_partn m pi n : n <= m -> n`_pi = \prod_(0 <= p < m.+1 | p \in pi) p ^ logn p n. Proof. move=> le_n_m; rewrite big_mkcond /=. rewrite [n`_pi](big_nat_widen _ _ m.+1) // big_mkcond /=. apply: eq_bigr => p _; rewrite ltnS lognE. by case: and3P => [[_ n_gt0 p_dv_n]|]; rewrite ?if_same // andbC dvdn_leq. Qed. Lemma eq_partn_from_log m n (pi : nat_pred) : 0 < m -> 0 < n -> {in pi, logn^~ m =1 logn^~ n} -> m`_pi = n`_pi. Proof. move=> m0 n0 eq_log; rewrite !(@widen_partn (maxn m n)) ?leq_maxl ?leq_maxr//. by apply: eq_bigr => p /eq_log ->. Qed. Lemma partn0 pi : 0`_pi = 1. Proof. by apply: big1_seq => [] [|n]; rewrite andbC. Qed. Lemma partn1 pi : 1`_pi = 1. Proof. by apply: big1_seq => [] [|[|n]]; rewrite andbC. Qed. Lemma partnM pi m n : m > 0 -> n > 0 -> (m * n)`_pi = m`_pi * n`_pi. Proof. have le_pmul m' n': m' > 0 -> n' <= m' * n' by move/prednK <-; apply: leq_addr. move=> mpos npos; rewrite !(@widen_partn (n * m)) 3?(le_pmul, mulnC) //. rewrite !big_mkord -big_split; apply: eq_bigr => p _ /=. by rewrite lognM // expnD. Qed. Lemma partnX pi m n : (m ^ n)`_pi = m`_pi ^ n. Proof. elim: n => [|n IHn]; first exact: partn1. rewrite expnS; have [->|m_gt0] := posnP m; first by rewrite partn0 exp1n. by rewrite expnS partnM ?IHn // expn_gt0 m_gt0. Qed. Lemma partn_dvd pi m n : n > 0 -> m %| n -> m`_pi %| n`_pi. Proof. move=> n_gt0 dvmn; case/dvdnP: dvmn n_gt0 => q ->{n}. by rewrite muln_gt0 => /andP[q_gt0 m_gt0]; rewrite partnM ?dvdn_mull. Qed. Lemma p_part p n : n`_p = p ^ logn p n. Proof. case (posnP (logn p n)) => [log0 |]. by rewrite log0 [n`_p]big1_seq // => q /andP [/eqP ->]; rewrite log0. rewrite logn_gt0 mem_primes; case/and3P=> _ n_gt0 dv_p_n. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. by rewrite [n`_p]big_mkord (big_pred1 (Ordinal le_p_n)). Qed. Lemma p_part_eq1 p n : (n`_p == 1) = (p \notin \pi(n)). Proof. rewrite mem_primes p_part lognE; case: and3P => // [[p_pr _ _]]. by rewrite -dvdn1 pfactor_dvdn // logn1. Qed. Lemma p_part_gt1 p n : (n`_p > 1) = (p \in \pi(n)). Proof. by rewrite ltn_neqAle part_gt0 andbT eq_sym p_part_eq1 negbK. Qed. Lemma primes_part pi n : primes n`_pi = filter [in pi] (primes n). Proof. have ltnT := ltn_trans; have [->|n_gt0] := posnP n; first by rewrite partn0. apply: (irr_sorted_eq ltnT ltnn); rewrite ?(sorted_primes, sorted_filter) //. move=> p; rewrite mem_filter /= !mem_primes n_gt0 part_gt0 /=. apply/andP/and3P=> [[p_pr] | [pi_p p_pr dv_p_n]]. rewrite /partn; apply big_ind => [|n1 n2 IHn1 IHn2|q pi_q]. - by rewrite dvdn1; case: eqP p_pr => // ->. - by rewrite Euclid_dvdM //; case/orP. rewrite -{1}(expn1 p) pfactor_dvdn // lognX muln_gt0. rewrite logn_gt0 mem_primes n_gt0 - andbA /=; case/and3P=> pr_q dv_q_n. by rewrite logn_prime //; case: eqP => // ->. have le_p_n: p < n.+1 by rewrite ltnS dvdn_leq. rewrite [n`_pi]big_mkord (bigD1 (Ordinal le_p_n)) //= dvdn_mulr //. by rewrite lognE p_pr n_gt0 dv_p_n expnS dvdn_mulr. Qed. Lemma filter_pi_of n m : n < m -> filter \pi(n) (index_iota 0 m) = primes n. Proof. move=> lt_n_m; have ltnT := ltn_trans; apply: (irr_sorted_eq ltnT ltnn). - by rewrite sorted_filter // iota_ltn_sorted. - exact: sorted_primes. move=> p; rewrite mem_filter mem_index_iota /= mem_primes; case: and3P => //. by case=> _ n_gt0 dv_p_n; apply: leq_ltn_trans lt_n_m; apply: dvdn_leq. Qed. Lemma partn_pi n : n > 0 -> n`_\pi(n) = n. Proof. move=> n_gt0; rewrite [RHS]prod_prime_decomp // prime_decompE big_map. by rewrite -[n`__]big_filter filter_pi_of. Qed. Lemma partnT n : n > 0 -> n`_predT = n. Proof. move=> n_gt0; rewrite -[RHS]partn_pi // [RHS]/partn big_mkcond /=. by apply: eq_bigr => p _; rewrite -logn_gt0; case: (logn p _). Qed. Lemma eqn_from_log m n : 0 < m -> 0 < n -> logn^~ m =1 logn^~ n -> m = n. Proof. by move=> ? ? /(@in1W _ predT)/eq_partn_from_log; rewrite !partnT// => ->. Qed. Lemma partnC pi n : n > 0 -> n`_pi * n`_pi^' = n. Proof. move=> n_gt0; rewrite -[RHS]partnT /partn //. do 2!rewrite mulnC big_mkcond /=; rewrite -big_split; apply: eq_bigr => p _ /=. by rewrite mulnC inE /=; case: (p \in pi); rewrite /= (muln1, mul1n). Qed. Lemma dvdn_part pi n : n`_pi %| n. Proof. by case: n => // n; rewrite -{2}[n.+1](@partnC pi) // dvdn_mulr. Qed. Lemma logn_part p m : logn p m`_p = logn p m. Proof. case p_pr: (prime p); first by rewrite p_part pfactorK. by rewrite lognE (lognE p m) p_pr. Qed. Lemma partn_lcm pi m n : m > 0 -> n > 0 -> (lcmn m n)`_pi = lcmn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: lcmn m n > 0 by rewrite lcmn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_lcm !partn_dvd ?dvdn_lcml ?dvdn_lcmr //. rewrite -(dvdn_pmul2r (part_gt0 pi^' (lcmn m n))) partnC // dvdn_lcm !andbT. rewrite -[m in m %| _](partnC pi m_gt0) andbC -[n in n %| _](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_lcml ?dvdn_lcmr. Qed. Lemma partn_gcd pi m n : m > 0 -> n > 0 -> (gcdn m n)`_pi = gcdn m`_pi n`_pi. Proof. move=> m_gt0 n_gt0; have p_gt0: gcdn m n > 0 by rewrite gcdn_gt0 m_gt0. apply/eqP; rewrite eqn_dvd dvdn_gcd !partn_dvd ?dvdn_gcdl ?dvdn_gcdr //=. rewrite -(dvdn_pmul2r (part_gt0 pi^' (gcdn m n))) partnC // dvdn_gcd. rewrite -[m in _ %| m](partnC pi m_gt0) andbC -[n in _%| n](partnC pi n_gt0). by rewrite !dvdn_mul ?partn_dvd ?dvdn_gcdl ?dvdn_gcdr. Qed. Lemma partn_biglcm (I : finType) (P : pred I) F pi : (forall i, P i -> F i > 0) -> (\big[lcmn/1%N]_(i | P i) F i)`_pi = \big[lcmn/1%N]_(i | P i) (F i)`_pi. Proof. move=> F_gt0; set m := \big[lcmn/1%N]_(i | P i) F i. have m_gt0: 0 < m by elim/big_ind: m => // p q p_gt0; rewrite lcmn_gt0 p_gt0. apply/eqP; rewrite eqn_dvd andbC; apply/andP; split. by apply/dvdn_biglcmP=> i Pi; rewrite partn_dvd // (@biglcmn_sup _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' m)) partnC //. apply/dvdn_biglcmP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biglcmn_sup _ i). by rewrite partn_dvd // (@biglcmn_sup _ i). Qed. Lemma partn_biggcd (I : finType) (P : pred I) F pi : #|SimplPred P| > 0 -> (forall i, P i -> F i > 0) -> (\big[gcdn/0]_(i | P i) F i)`_pi = \big[gcdn/0]_(i | P i) (F i)`_pi. Proof. move=> ntP F_gt0; set d := \big[gcdn/0]_(i | P i) F i. have d_gt0: 0 < d. case/card_gt0P: ntP => i /= Pi; have:= F_gt0 i Pi. rewrite !lt0n -!dvd0n; apply: contra => dv0d. by rewrite (dvdn_trans dv0d) // (@biggcdn_inf _ i). apply/eqP; rewrite eqn_dvd; apply/andP; split. by apply/dvdn_biggcdP=> i Pi; rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). rewrite -(dvdn_pmul2r (part_gt0 pi^' d)) partnC //. apply/dvdn_biggcdP=> i Pi; rewrite -(partnC pi (F_gt0 i Pi)) dvdn_mul //. by rewrite (@biggcdn_inf _ i). by rewrite partn_dvd ?F_gt0 // (@biggcdn_inf _ i). Qed. Lemma logn_gcd p m n : 0 < m -> 0 < n -> logn p (gcdn m n) = minn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; case p_pr: (prime p); last by rewrite /logn p_pr. by apply: (@expnI p); rewrite ?prime_gt1// expn_min -!p_part partn_gcd. Qed. Lemma logn_lcm p m n : 0 < m -> 0 < n -> logn p (lcmn m n) = maxn (logn p m) (logn p n). Proof. move=> m_gt0 n_gt0; rewrite /lcmn logn_div ?dvdn_mull ?dvdn_gcdr//. by rewrite lognM// logn_gcd// -addn_min_max addnC addnK. Qed. Lemma sub_in_pnat pi rho n : {in \pi(n), {subset pi <= rho}} -> pi.-nat n -> rho.-nat n. Proof. rewrite /pnat => subpi /andP[-> pi_n]. by apply/allP=> p pr_p; apply: subpi => //; apply: (allP pi_n). Qed. Lemma eq_in_pnat pi rho n : {in \pi(n), pi =i rho} -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply/idP/idP; apply: sub_in_pnat => p /eqpi->. Qed. Lemma eq_pnat pi rho n : pi =i rho -> pi.-nat n = rho.-nat n. Proof. by move=> eqpi; apply: eq_in_pnat => p _. Qed. Lemma pnatNK pi n : pi^'^'.-nat n = pi.-nat n. Proof. exact: eq_pnat (negnK pi). Qed. Lemma pnatI pi rho n : [predI pi & rho].-nat n = pi.-nat n && rho.-nat n. Proof. by rewrite /pnat andbCA all_predI !andbA andbb. Qed. Lemma pnatM pi m n : pi.-nat (m * n) = pi.-nat m && pi.-nat n. Proof. rewrite /pnat muln_gt0 andbCA -andbA andbCA. case: posnP => // n_gt0; case: posnP => //= m_gt0. apply/allP/andP=> [pi_mn | [pi_m pi_n] p]. by split; apply/allP=> p m_p; apply: pi_mn; rewrite primesM // m_p ?orbT. by rewrite primesM // => /orP[]; [apply: (allP pi_m) | apply: (allP pi_n)]. Qed. Lemma pnatX pi m n : pi.-nat (m ^ n) = pi.-nat m || (n == 0). Proof. by case: n => [|n]; rewrite orbC // /pnat expn_gt0 orbC primesX. Qed. Lemma part_pnat pi n : pi.-nat n`_pi. Proof. rewrite /pnat primes_part part_gt0. by apply/allP=> p; rewrite mem_filter => /andP[]. Qed. Lemma pnatE pi p : prime p -> pi.-nat p = (p \in pi). Proof. by move=> pr_p; rewrite /pnat prime_gt0 ?primes_prime //= andbT. Qed. Lemma pnat_id p : prime p -> p.-nat p. Proof. by move=> pr_p; rewrite pnatE ?inE /=. Qed. Lemma coprime_pi' m n : m > 0 -> n > 0 -> coprime m n = \pi(m)^'.-nat n. Proof. by move=> m_gt0 n_gt0; rewrite /pnat n_gt0 all_predC coprime_has_primes. Qed. Lemma pnat_pi n : n > 0 -> \pi(n).-nat n. Proof. by rewrite /pnat => ->; apply/allP. Qed. Lemma pi_of_dvd m n : m %| n -> n > 0 -> {subset \pi(m) <= \pi(n)}. Proof. move=> m_dv_n n_gt0 p; rewrite !mem_primes n_gt0 => /and3P[-> _ p_dv_m]. exact: dvdn_trans p_dv_m m_dv_n. Qed. Lemma pi_ofM m n : m > 0 -> n > 0 -> \pi(m * n) =i [predU \pi(m) & \pi(n)]. Proof. by move=> m_gt0 n_gt0 p; apply: primesM. Qed. Lemma pi_of_part pi n : n > 0 -> \pi(n`_pi) =i [predI \pi(n) & pi]. Proof. by move=> n_gt0 p; rewrite /pi_of primes_part mem_filter andbC. Qed. Lemma pi_of_exp p n : n > 0 -> \pi(p ^ n) = \pi(p). Proof. by move=> n_gt0; rewrite /pi_of primesX. Qed. Lemma pi_of_prime p : prime p -> \pi(p) =i (p : nat_pred). Proof. by move=> pr_p q; rewrite /pi_of primes_prime // mem_seq1. Qed. Lemma p'natEpi p n : n > 0 -> p^'.-nat n = (p \notin \pi(n)). Proof. by case: n => // n _; rewrite /pnat all_predC has_pred1. Qed. Lemma p'natE p n : prime p -> p^'.-nat n = ~~ (p %| n). Proof. case: n => [|n] p_pr; first by case: p p_pr. by rewrite p'natEpi // mem_primes p_pr. Qed. Lemma pnatPpi pi n p : pi.-nat n -> p \in \pi(n) -> p \in pi. Proof. by case/andP=> _ /allP; apply. Qed. Lemma pnat_dvd m n pi : m %| n -> pi.-nat n -> pi.-nat m. Proof. by case/dvdnP=> q ->; rewrite pnatM; case/andP. Qed. Lemma pnat_div m n pi : m %| n -> pi.-nat n -> pi.-nat (n %/ m). Proof. case/dvdnP=> q ->; rewrite pnatM andbC => /andP[]. by case: m => // m _; rewrite mulnK. Qed. Lemma pnat_coprime pi m n : pi.-nat m -> pi^'.-nat n -> coprime m n. Proof. case/andP=> m_gt0 pi_m /andP[n_gt0 pi'_n]; rewrite coprime_has_primes //. by apply/hasPn=> p /(allP pi'_n); apply/contra/allP. Qed. Lemma p'nat_coprime pi m n : pi^'.-nat m -> pi.-nat n -> coprime m n. Proof. by move=> pi'm pi_n; rewrite (pnat_coprime pi'm) ?pnatNK. Qed. Lemma sub_pnat_coprime pi rho m n : {subset rho <= pi^'} -> pi.-nat m -> rho.-nat n -> coprime m n. Proof. by move=> pi'rho pi_m /(sub_in_pnat (in1W pi'rho)); apply: pnat_coprime. Qed. Lemma coprime_partC pi m n : coprime m`_pi n`_pi^'. Proof. by apply: (@pnat_coprime pi); apply: part_pnat. Qed. Lemma pnat_1 pi n : pi.-nat n -> pi^'.-nat n -> n = 1. Proof. by move=> pi_n pi'_n; rewrite -(eqnP (pnat_coprime pi_n pi'_n)) gcdnn. Qed. Lemma part_pnat_id pi n : pi.-nat n -> n`_pi = n. Proof. case/andP=> n_gt0 pi_n; rewrite -[RHS]partnT // /partn big_mkcond /=. apply: eq_bigr=> p _; have [->|] := posnP (logn p n); first by rewrite if_same. by rewrite logn_gt0 => /(allP pi_n)/= ->. Qed. Lemma part_p'nat pi n : pi^'.-nat n -> n`_pi = 1. Proof. case/andP=> n_gt0 pi'_n; apply: big1_seq => p /andP[pi_p _]. by have [-> //|] := posnP (logn p n); rewrite logn_gt0; case/(allP pi'_n)/negP. Qed. Lemma partn_eq1 pi n : n > 0 -> (n`_pi == 1) = pi^'.-nat n. Proof. move=> n_gt0; apply/eqP/idP=> [pi_n_1|]; last exact: part_p'nat. by rewrite -(partnC pi n_gt0) pi_n_1 mul1n part_pnat. Qed. Lemma pnatP pi n : n > 0 -> reflect (forall p, prime p -> p %| n -> p \in pi) (pi.-nat n). Proof. move=> n_gt0; rewrite /pnat n_gt0. apply: (iffP allP) => /= pi_n p => [pr_p p_n|]. by rewrite pi_n // mem_primes pr_p n_gt0. by rewrite mem_primes n_gt0 /=; case/andP; move: p. Qed. Lemma pi_pnat pi p n : p.-nat n -> p \in pi -> pi.-nat n. Proof. move=> p_n pi_p; have [n_gt0 _] := andP p_n. by apply/pnatP=> // q q_pr /(pnatP _ n_gt0 p_n _ q_pr)/eqnP->. Qed. Lemma p_natP p n : p.-nat n -> {k | n = p ^ k}. Proof. by move=> p_n; exists (logn p n); rewrite -p_part part_pnat_id. Qed. Lemma pi'_p'nat pi p n : pi^'.-nat n -> p \in pi -> p^'.-nat n. Proof. by move=> pi'n pi_p; apply: sub_in_pnat pi'n => q _; apply: contraNneq => ->. Qed. Lemma pi_p'nat p pi n : pi.-nat n -> p \in pi^' -> p^'.-nat n. Proof. by move=> pi_n; apply: pi'_p'nat; rewrite pnatNK. Qed. Lemma partn_part pi rho n : {subset pi <= rho} -> n`_rho`_pi = n`_pi. Proof. move=> pi_sub_rho; have [->|n_gt0] := posnP n; first by rewrite !partn0 partn1. rewrite -[in RHS](partnC rho n_gt0) partnM //. suffices: pi^'.-nat n`_rho^' by move/part_p'nat->; rewrite muln1. by apply: sub_in_pnat (part_pnat _ _) => q _; apply/contra/pi_sub_rho. Qed. Lemma partnI pi rho n : n`_[predI pi & rho] = n`_pi`_rho. Proof. rewrite -(@partnC [predI pi & rho] _`_rho) //. symmetry; rewrite 2?partn_part; try by move=> p /andP []. rewrite mulnC part_p'nat ?mul1n // pnatNK pnatI part_pnat andbT. exact: pnat_dvd (dvdn_part _ _) (part_pnat _ _). Qed. Lemma odd_2'nat n : odd n = 2^'.-nat n. Proof. by case: n => // n; rewrite p'natE // dvdn2 negbK. Qed. End PnatTheory. #[global] Hint Resolve part_gt0 : core. (************************************) (* Properties of the divisors list. *) (************************************) Lemma divisors_correct n : n > 0 -> [/\ uniq (divisors n), sorted leq (divisors n) & forall d, (d \in divisors n) = (d %| n)]. Proof. move/prod_prime_decomp=> def_n; rewrite {4}def_n {def_n}. have: all prime (primes n) by apply/allP=> p; rewrite mem_primes; case/andP. have:= primes_uniq n; rewrite /primes /divisors; move/prime_decomp: n. elim=> [|[p e] pd] /=; first by split=> // d; rewrite big_nil dvdn1 mem_seq1. rewrite big_cons /=; move: (foldr _ _ pd) => divs. move=> IHpd /andP[npd_p Upd] /andP[pr_p pr_pd]. have lt0p: 0 < p by apply: prime_gt0. have {IHpd Upd}[Udivs Odivs mem_divs] := IHpd Upd pr_pd. have ndivs_p m: p * m \notin divs. suffices: p \notin divs; rewrite !mem_divs. by apply: contra => /dvdnP[n ->]; rewrite mulnCA dvdn_mulr. have ndv_p_1: ~~(p %| 1) by rewrite dvdn1 neq_ltn orbC prime_gt1. rewrite big_seq; elim/big_ind: _ => [//|u v npu npv|[q f] /= pd_qf]. by rewrite Euclid_dvdM //; apply/norP. elim: (f) => // f'; rewrite expnS Euclid_dvdM // orbC negb_or => -> {f'}/=. have pd_q: q \in unzip1 pd by apply/mapP; exists (q, f). by apply: contra npd_p; rewrite dvdn_prime2 // ?(allP pr_pd) // => /eqP->. elim: e => [|e] /=; first by split=> // d; rewrite mul1n. have Tmulp_inj: injective (NatTrec.mul p). by move=> u v /eqP; rewrite !natTrecE eqn_pmul2l // => /eqP. move: (iter e _ _) => divs' [Udivs' Odivs' mem_divs']; split=> [||d]. - rewrite merge_uniq cat_uniq map_inj_uniq // Udivs Udivs' andbT /=. apply/hasP=> [[d dv_d /mapP[d' _ def_d]]]. by case/idPn: dv_d; rewrite def_d natTrecE. - rewrite (merge_sorted leq_total) //; case: (divs') Odivs' => //= d ds. rewrite (@map_path _ _ _ _ leq xpred0) ?has_pred0 // => u v _. by rewrite !natTrecE leq_pmul2l. rewrite mem_merge mem_cat; case dv_d_p: (p %| d). case/dvdnP: dv_d_p => d' ->{d}; rewrite mulnC (negbTE (ndivs_p d')) orbF. rewrite expnS -mulnA dvdn_pmul2l // -mem_divs'. by rewrite -(mem_map Tmulp_inj divs') natTrecE. case pdiv_d: (_ \in _). by case/mapP: pdiv_d dv_d_p => d' _ ->; rewrite natTrecE dvdn_mulr. rewrite mem_divs Gauss_dvdr // coprime_sym. by rewrite coprimeXl ?prime_coprime ?dv_d_p. Qed. Lemma sorted_divisors n : sorted leq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma divisors_uniq n : uniq (divisors n). Proof. by case: (posnP n) => [-> | /divisors_correct[]]. Qed. Lemma sorted_divisors_ltn n : sorted ltn (divisors n). Proof. by rewrite ltn_sorted_uniq_leq divisors_uniq sorted_divisors. Qed. Lemma dvdn_divisors d m : 0 < m -> (d %| m) = (d \in divisors m). Proof. by case/divisors_correct. Qed. Lemma divisor1 n : 1 \in divisors n. Proof. by case: n => // n; rewrite -dvdn_divisors // dvd1n. Qed. Lemma divisors_id n : 0 < n -> n \in divisors n. Proof. by move/dvdn_divisors <-. Qed. (* Big sum / product lemmas*) Lemma dvdn_sum d I r (K : pred I) F : (forall i, K i -> d %| F i) -> d %| \sum_(i <- r | K i) F i. Proof. by move=> dF; elim/big_ind: _ => //; apply: dvdn_add. Qed. Lemma dvdn_partP n m : 0 < n -> reflect (forall p, p \in \pi(n) -> n`_p %| m) (n %| m). Proof. move=> n_gt0; apply: (iffP idP) => n_dvd_m => [p _|]. by apply: dvdn_trans n_dvd_m; apply: dvdn_part. have [-> // | m_gt0] := posnP m. rewrite -(partnT n_gt0) -(partnT m_gt0). rewrite !(@widen_partn (m + n)) ?leq_addl ?leq_addr // /in_mem /=. elim/big_ind2: _ => // [* | q _]; first exact: dvdn_mul. have [-> // | ] := posnP (logn q n); rewrite logn_gt0 => q_n. have pr_q: prime q by move: q_n; rewrite mem_primes; case/andP. by have:= n_dvd_m q q_n; rewrite p_part !pfactor_dvdn // pfactorK. Qed. Lemma modn_partP n a b : 0 < n -> reflect (forall p : nat, p \in \pi(n) -> a = b %[mod n`_p]) (a == b %[mod n]). Proof. move=> n_gt0; wlog le_b_a: a b / b <= a. move=> IH; case: (leqP b a) => [|/ltnW] /IH {IH}// IH. by rewrite eq_sym; apply: (iffP IH) => eqab p /eqab. rewrite eqn_mod_dvd //; apply: (iffP (dvdn_partP _ n_gt0)) => eqab p /eqab; by rewrite -eqn_mod_dvd // => /eqP. Qed. (* The Euler totient function *) Lemma totientE n : n > 0 -> totient n = \prod_(p <- primes n) (p.-1 * p ^ (logn p n).-1). Proof. move=> n_gt0; rewrite /totient n_gt0 prime_decompE unlock. by elim: (primes n) => //= [p pr ->]; rewrite !natTrecE. Qed. Lemma totient_gt0 n : (0 < totient n) = (0 < n). Proof. case: n => // n; rewrite totientE // big_seq_cond prodn_cond_gt0 // => p. by rewrite mem_primes muln_gt0 expn_gt0; case: p => [|[|]]. Qed. Lemma totient_pfactor p e : prime p -> e > 0 -> totient (p ^ e) = p.-1 * p ^ e.-1. Proof. move=> p_pr e_gt0; rewrite totientE ?expn_gt0 ?prime_gt0 //. by rewrite primesX // primes_prime // unlock /= muln1 pfactorK. Qed. Lemma totient_prime p : prime p -> totient p = p.-1. Proof. by move=> p_prime; rewrite -{1}[p]expn1 totient_pfactor // muln1. Qed. Lemma totient_coprime m n : coprime m n -> totient (m * n) = totient m * totient n. Proof. move=> co_mn; have [-> //| m_gt0] := posnP m. have [->|n_gt0] := posnP n; first by rewrite !muln0. rewrite !totientE ?muln_gt0 ?m_gt0 //. have /(perm_big _)->: perm_eq (primes (m * n)) (primes m ++ primes n). apply: uniq_perm => [||p]; first exact: primes_uniq. by rewrite cat_uniq !primes_uniq -coprime_has_primes // co_mn. by rewrite mem_cat primesM. rewrite big_cat /= !big_seq. congr (_ * _); apply: eq_bigr => p; rewrite mem_primes => /and3P[_ _ dvp]. rewrite (mulnC m) logn_Gauss //; move: co_mn. by rewrite -(divnK dvp) coprimeMl => /andP[]. rewrite logn_Gauss //; move: co_mn. by rewrite coprime_sym -(divnK dvp) coprimeMl => /andP[]. Qed. Lemma totient_count_coprime n : totient n = \sum_(0 <= d < n) coprime n d. Proof. elim/ltn_ind: n => // n IHn. case: (leqP n 1) => [|lt1n]; first by rewrite unlock; case: (n) => [|[]]. pose p := pdiv n; have p_pr: prime p by apply: pdiv_prime. have p1 := prime_gt1 p_pr; have p0 := ltnW p1. pose np := n`_p; pose np' := n`_p^'. have co_npp': coprime np np' by rewrite coprime_partC. have [n0 np0 np'0]: [/\ n > 0, np > 0 & np' > 0] by rewrite ltnW ?part_gt0. have def_n: n = np * np' by rewrite partnC. have lnp0: 0 < logn p n by rewrite lognE p_pr n0 pdiv_dvd. pose in_mod k (k0 : k > 0) d := Ordinal (ltn_pmod d k0). rewrite {1}def_n totient_coprime // {IHn}(IHn np') ?big_mkord; last first. by rewrite def_n ltn_Pmull // /np p_part -(expn0 p) ltn_exp2l. have ->: totient np = #|[pred d : 'I_np | coprime np d]|. rewrite [np in LHS]p_part totient_pfactor //=; set q := p ^ _. apply: (@addnI (1 * q)); rewrite -mulnDl [1 + _]prednK // mul1n. have def_np: np = p * q by rewrite -expnS prednK // -p_part. pose mulp := [fun d : 'I_q => in_mod _ np0 (p * d)]. rewrite -def_np -{1}[np]card_ord -(cardC [in codom mulp]). rewrite card_in_image => [|[d1 ltd1] [d2 ltd2] /= _ _ []]; last first. move/eqP; rewrite def_np -!muln_modr ?modn_small //. by rewrite eqn_pmul2l // => eq_op12; apply/eqP. rewrite card_ord; congr (q + _); apply: eq_card => d /=. rewrite !inE [np in coprime np _]p_part coprime_pexpl ?prime_coprime //. congr (~~ _); apply/codomP/idP=> [[d' -> /=] | /dvdnP[r def_d]]. by rewrite def_np -muln_modr // dvdn_mulr. do [rewrite mulnC; case: d => d ltd /=] in def_d *. have ltr: r < q by rewrite -(ltn_pmul2l p0) -def_np -def_d. by exists (Ordinal ltr); apply: val_inj; rewrite /= -def_d modn_small. pose h (d : 'I_n) := (in_mod _ np0 d, in_mod _ np'0 d). pose h' (d : 'I_np * 'I_np') := in_mod _ n0 (chinese np np' d.1 d.2). rewrite -!big_mkcond -sum_nat_const pair_big (reindex_onto h h') => [|[d d'] _]. apply: eq_bigl => [[d ltd] /=]; rewrite !inE -val_eqE /= andbC !coprime_modr. by rewrite def_n -chinese_mod // -coprimeMl -def_n modn_small ?eqxx. apply/eqP; rewrite /eq_op /= /eq_op /= !modn_dvdm ?dvdn_part //. by rewrite chinese_modl // chinese_modr // !modn_small ?eqxx ?ltn_ord. Qed. Lemma totient_gt1 n : (totient n > 1) = (n > 2). Proof. case: n => [|[|[|[|n']]]]//=; set n := n'.+4; rewrite [RHS]isT. wlog [q] : / exists k, k.+3 \in primes n; last first. rewrite mem_primes => /and3P[qp ngt0 qn]. have [[|k]// cqk ->] := pfactor_coprime qp ngt0. rewrite totient_coprime 1?coprime_sym ?coprimeXl//. rewrite totient_pfactor// -?pfactor_dvdn// mulnCA/= (@leq_trans q.+2)//. by rewrite leq_pmulr// muln_gt0 totient_gt0 expn_gt0. have := @prod_prime_decomp n isT; rewrite prime_decompE big_map/=. case: (primes n) (all_prime_primes n) (sorted_primes n) => [|[|[|p']]// [|[|[|[|q']]] r]]//=; first by rewrite big_nil. case: p' => [_ _|p' _ _ _]; last by apply; exists p'; rewrite ?mem_head. rewrite big_seq1; case: logn => [|[|k]]//= ->. by rewrite totient_pfactor//= mul1n (@leq_pexp2l 2 1)//. by move=> _ _ _; apply; exists q'=> //; rewrite !in_cons eqxx orbT. Qed.
AddCircleMulti.lean
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Fourier.AddCircle import Mathlib.MeasureTheory.Integral.Pi /-! # Multivariate Fourier series In this file we define the Fourier series of an L² function on the `d`-dimensional unit circle, and show that it converges to the function in the L² norm. We also prove uniform convergence of the Fourier series if `f` is continuous and the sequence of its Fourier coefficients is summable. -/ noncomputable section open scoped BigOperators ComplexConjugate ENNReal open Set Algebra Submodule MeasureTheory -- some instances for unit circle attribute [local instance] Real.fact_zero_lt_one /-- In this file we normalise the measure on `ℝ / ℤ` to have total volume 1. -/ local instance : MeasureSpace UnitAddCircle := ⟨AddCircle.haarAddCircle⟩ /-- The measure on `ℝ / ℤ` is a Haar measure. -/ local instance : Measure.IsAddHaarMeasure (volume : Measure UnitAddCircle) := inferInstanceAs (Measure.IsAddHaarMeasure AddCircle.haarAddCircle) /-- The measure on `ℝ / ℤ` is a probability measure. -/ local instance : IsProbabilityMeasure (volume : Measure UnitAddCircle) := inferInstanceAs (IsProbabilityMeasure AddCircle.haarAddCircle) /-- The product of finitely many copies of the unit circle, indexed by `d`. -/ abbrev UnitAddTorus (d : Type*) := d → UnitAddCircle namespace UnitAddTorus variable {d : Type*} [Fintype d] section Monomials variable (n : d → ℤ) /-- Exponential monomials in `d` variables. -/ def mFourier : C(UnitAddTorus d, ℂ) where toFun x := ∏ i : d, fourier (n i) (x i) continuous_toFun := continuous_finset_prod _ fun i _ ↦ (fourier (n i)).continuous.comp (continuous_apply i) variable {n} {x : UnitAddTorus d} lemma mFourier_neg : mFourier (-n) x = conj (mFourier n x) := by simp only [mFourier, Pi.neg_apply, fourier_neg, ContinuousMap.coe_mk, map_prod] lemma mFourier_add {m : d → ℤ} : mFourier (m + n) x = mFourier m x * mFourier n x := by simp only [mFourier, Pi.add_apply, fourier_add, ContinuousMap.coe_mk, ← Finset.prod_mul_distrib] lemma mFourier_zero : mFourier (0 : d → ℤ) = 1 := by ext x simp only [mFourier, Pi.zero_apply, fourier_zero, Finset.prod_const_one, ContinuousMap.coe_mk, ContinuousMap.one_apply] lemma mFourier_norm : ‖mFourier n‖ = 1 := by apply le_antisymm · refine (ContinuousMap.norm_le _ zero_le_one).mpr fun i ↦ ?_ simp only [mFourier, fourier_apply, ContinuousMap.coe_mk, norm_prod, Circle.norm_coe, Finset.prod_const_one, le_rfl] · refine (le_of_eq ?_).trans ((mFourier n).norm_coe_le_norm fun _ ↦ 0) simp only [mFourier, ContinuousMap.coe_mk, fourier_eval_zero, Finset.prod_const_one, CStarRing.norm_one] lemma mFourier_single [DecidableEq d] (z : d → AddCircle (1 : ℝ)) (i : d) : mFourier (Pi.single i 1) z = fourier 1 (z i) := by simp_rw [mFourier, ContinuousMap.coe_mk] have := Finset.prod_mul_prod_compl {i} (fun j ↦ fourier ((Pi.single i (1 : ℤ) : d → ℤ) j) (z j)) rw [Finset.prod_singleton, Finset.prod_congr rfl (fun j hj ↦ ?_)] at this · rw [← this, Finset.prod_const_one, mul_one, Pi.single_eq_same] · rw [Finset.mem_compl, Finset.mem_singleton] at hj simp only [Pi.single_eq_of_ne hj, fourier_zero] end Monomials section Algebra /-- The star subalgebra of `C(UnitAddTorus d, ℂ)` generated by `mFourier n` for `n ∈ ℤᵈ`. -/ def mFourierSubalgebra (d : Type*) [Fintype d] : StarSubalgebra ℂ C(UnitAddTorus d, ℂ) where toSubalgebra := Algebra.adjoin ℂ (range mFourier) star_mem' := by change Algebra.adjoin ℂ (range mFourier) ≤ star (Algebra.adjoin ℂ (range mFourier)) refine adjoin_le ?_ rintro _ ⟨n, rfl⟩ refine subset_adjoin ⟨-n, ?_⟩ ext1 x simp only [mFourier_neg, starRingEnd_apply, ContinuousMap.star_apply] /-- The star subalgebra of `C(UnitAddTorus d, ℂ)` generated by `mFourier n` for `n ∈ ℤᵈ` is in fact the linear span of these functions. -/ theorem mFourierSubalgebra_coe : (mFourierSubalgebra d).toSubalgebra.toSubmodule = span ℂ (range mFourier) := by apply adjoin_eq_span_of_subset refine .trans (fun x ↦ Submonoid.closure_induction (fun _ ↦ id) ⟨0, ?_⟩ ?_) subset_span · ext z simp only [mFourier, Pi.zero_apply, fourier_zero, Finset.prod_const, one_pow, ContinuousMap.coe_mk, ContinuousMap.one_apply] · rintro _ _ _ _ ⟨m, rfl⟩ ⟨n, rfl⟩ refine ⟨m + n, ?_⟩ ext z simp only [mFourier, Pi.add_apply, fourier_apply, fourier_add', Finset.prod_mul_distrib, ContinuousMap.coe_mk, ContinuousMap.mul_apply] /-- The subalgebra of `C(UnitAddTorus d, ℂ)` generated by `mFourier n` for `n ∈ ℤᵈ` separates points. -/ theorem mFourierSubalgebra_separatesPoints : (mFourierSubalgebra d).SeparatesPoints := by classical intro x y hxy rw [Ne, funext_iff, not_forall] at hxy obtain ⟨i, hi⟩ := hxy refine ⟨_, ⟨mFourier (Pi.single i 1), subset_adjoin ⟨Pi.single i 1, rfl⟩, rfl⟩, ?_⟩ dsimp only rw [mFourier_single, mFourier_single, fourier_one, fourier_one, Ne, Subtype.coe_inj] contrapose! hi exact AddCircle.injective_toCircle one_ne_zero hi /-- The subalgebra of `C(UnitAddTorus d, ℂ)` generated by `mFourier n` for `n : d → ℤ` is dense. -/ theorem mFourierSubalgebra_closure_eq_top : (mFourierSubalgebra d).topologicalClosure = ⊤ := ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints _ mFourierSubalgebra_separatesPoints /-- The linear span of the monomials `mFourier n` is dense in `C(UnitAddTorus d, ℂ)`. -/ theorem span_mFourier_closure_eq_top : (span ℂ (range <| mFourier (d := d))).topologicalClosure = ⊤ := by rw [← mFourierSubalgebra_coe] exact congr_arg (Subalgebra.toSubmodule <| StarSubalgebra.toSubalgebra ·) mFourierSubalgebra_closure_eq_top end Algebra section Lp /-- The family of monomials `mFourier n`, parametrized by `n : ℤᵈ` and considered as elements of the `Lp` space of functions `UnitAddTorus d → ℂ`. -/ abbrev mFourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : d → ℤ) : Lp ℂ p (volume : Measure (UnitAddTorus d)) := ContinuousMap.toLp (E := ℂ) p volume ℂ (mFourier n) theorem coeFn_mFourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : d → ℤ) : mFourierLp p n =ᵐ[volume] mFourier n := ContinuousMap.coeFn_toLp volume (mFourier n) /-- For each `1 ≤ p < ∞`, the linear span of the monomials `mFourier n` is dense in the `Lᵖ` space of functions on `UnitAddTorus d`. -/ theorem span_mFourierLp_closure_eq_top {p : ℝ≥0∞} [Fact (1 ≤ p)] (hp : p ≠ ∞) : (span ℂ (range (@mFourierLp d _ p _))).topologicalClosure = ⊤ := by simpa only [map_span, ContinuousLinearMap.coe_coe, ← range_comp, Function.comp_def] using (ContinuousMap.toLp_denseRange ℂ volume ℂ hp).topologicalClosure_map_submodule span_mFourier_closure_eq_top /-- The monomials `mFourierLp 2 n` are an orthonormal set in `L²`. -/ theorem orthonormal_mFourier : Orthonormal ℂ (mFourierLp (d := d) 2) := by rw [orthonormal_iff_ite] intro m n simp only [ContinuousMap.inner_toLp, ← mFourier_neg, ← mFourier_add] split_ifs with h · simpa only [h, add_neg_cancel, mFourier_zero, measureReal_univ_eq_one, one_smul] using integral_const (α := UnitAddTorus d) (μ := volume) (1 : ℂ) rw [mFourier, ContinuousMap.coe_mk, MeasureTheory.integral_fintype_prod_volume_eq_prod] obtain ⟨i, hi⟩ := Function.ne_iff.mp h apply Finset.prod_eq_zero (Finset.mem_univ i) simpa only [eq_false_intro hi, if_false, ContinuousMap.inner_toLp, ← fourier_neg, ← fourier_add] using (orthonormal_iff_ite.mp <| orthonormal_fourier) (m i) (n i) end Lp section fourierCoeff variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℂ E] /-- The `n`-th Fourier coefficient of a function `UnitAddTorus d → E`, for `E` a complete normed `ℂ`-vector space, defined as the integral over `UnitAddTorus d` of `mFourier (-n) t • f t`. -/ def mFourierCoeff (f : UnitAddTorus d → E) (n : d → ℤ) : E := ∫ t, mFourier (-n) t • f t end fourierCoeff section FourierL2 local notation "L²(" α ")" => Lp ℂ 2 (volume : Measure α) /-- We define `mFourierBasis` to be a `ℤᵈ`-indexed Hilbert basis for the `L²` space of functions on `UnitAddTorus d`, which by definition is an isometric isomorphism from `L²(UnitAddTorus d)` to `ℓ²(ℤᵈ, ℂ)`. -/ def mFourierBasis : HilbertBasis (d → ℤ) ℂ L²(UnitAddTorus d) := HilbertBasis.mk orthonormal_mFourier (span_mFourierLp_closure_eq_top (by simp)).ge /-- The elements of the Hilbert basis `mFourierBasis` are the functions `mFourierLp 2`, i.e. the monomials `mFourier n` on `UnitAddTorus d` considered as elements of `L²`. -/ @[simp] theorem coe_mFourierBasis : ⇑(mFourierBasis (d := d)) = mFourierLp 2 := HilbertBasis.coe_mk _ _ /-- Under the isometric isomorphism `mFourierBasis` from `L²(UnitAddTorus d)` to `ℓ²(ℤᵈ, ℂ)`, the `i`-th coefficient is `mFourierCoeff f i`. -/ theorem mFourierBasis_repr (f : L²(UnitAddTorus d)) (i : d → ℤ) : mFourierBasis.repr f i = mFourierCoeff f i := by trans ∫ t, conj (mFourierLp 2 i t) * f t · rw [mFourierBasis.repr_apply_apply f i, MeasureTheory.L2.inner_def, coe_mFourierBasis] simp only [RCLike.inner_apply, mul_comm] · apply integral_congr_ae filter_upwards [coeFn_mFourierLp 2 i] with _ ht rw [ht, ← mFourier_neg, smul_eq_mul] /-- The Fourier series of an `L2` function `f` sums to `f` in the `L²` norm. -/ theorem hasSum_mFourier_series_L2 (f : L²(UnitAddTorus d)) : HasSum (fun i ↦ mFourierCoeff f i • mFourierLp 2 i) f := by simpa [← coe_mFourierBasis, mFourierBasis_repr] using mFourierBasis.hasSum_repr f /-- **Parseval's identity** for inner products: for `L²` functions `f, g` on `UnitAddTorus d`, the inner product of the Fourier coefficients of `f` and `g` is the inner product of `f` and `g`. -/ theorem hasSum_prod_mFourierCoeff (f g : L²(UnitAddTorus d)) : HasSum (fun i ↦ conj (mFourierCoeff f i) * (mFourierCoeff g i)) (∫ t, conj (f t) * g t) := by simp_rw [mul_comm (conj _)] refine HasSum.congr_fun (mFourierBasis.hasSum_inner_mul_inner f g) (fun n ↦ ?_) simp only [← mFourierBasis_repr, HilbertBasis.repr_apply_apply, inner_conj_symm, mul_comm (inner ℂ f _)] /-- **Parseval's identity** for norms: for an `L²` function `f` on `UnitAddTorus d`, the sum of the squared norms of the Fourier coefficients equals the `L²` norm of `f`. -/ theorem hasSum_sq_mFourierCoeff (f : L²(UnitAddTorus d)) : HasSum (fun i ↦ ‖mFourierCoeff f i‖ ^ 2) (∫ t, ‖f t‖ ^ 2) := by simpa only [← RCLike.inner_apply', inner_self_eq_norm_sq, ← integral_re (L2.integrable_inner f f)] using RCLike.hasSum_re ℂ (hasSum_prod_mFourierCoeff f f) end FourierL2 section Convergence variable (f : C(UnitAddTorus d, ℂ)) theorem mFourierCoeff_toLp (n : d → ℤ) : mFourierCoeff (f.toLp 2 volume ℂ) n = mFourierCoeff f n := integral_congr_ae (ae_eq_rfl.mul <| f.coeFn_toAEEqFun _) variable {f} /-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series converges uniformly to `f`. -/ theorem hasSum_mFourier_series_of_summable (h : Summable (mFourierCoeff f)) : HasSum (fun i ↦ mFourierCoeff f i • mFourier i) f := by have sum_L2 := hasSum_mFourier_series_L2 (ContinuousMap.toLp 2 volume ℂ f) simp only [mFourierCoeff_toLp] at sum_L2 refine ContinuousMap.hasSum_of_hasSum_Lp (.of_norm ?_) sum_L2 simpa only [norm_smul, mFourier_norm, mul_one] using h.norm /-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series of `f` converges everywhere pointwise to `f`. -/ theorem hasSum_mFourier_series_apply_of_summable (h : Summable (mFourierCoeff f)) (x : UnitAddTorus d) : HasSum (fun i ↦ mFourierCoeff f i • mFourier i x) (f x) := by simpa only [map_smul] using (ContinuousMap.evalCLM ℂ x).hasSum (hasSum_mFourier_series_of_summable h) end Convergence end UnitAddTorus
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.
jordanholder.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 bigop finset fingroup morphism. From mathcomp Require Import automorphism quotient action gseries. (******************************************************************************) (* This files establishes Jordan-Holder theorems for finite groups. These *) (* theorems state the uniqueness up to permutation and isomorphism for the *) (* series of quotient built from the successive elements of any composition *) (* series of the same group. These quotients are also called factors of the *) (* composition series. To avoid the heavy use of highly polymorphic lists *) (* describing these quotient series, we introduce sections. *) (* This library defines: *) (* (G1 / G2)%sec == alias for the pair (G1, G2) of groups in the same *) (* finGroupType, coerced to the actual quotient group*) (* group G1 / G2. We call this pseudo-quotient a *) (* section of G1 and G2. *) (* section_isog s1 s2 == s1 and s2 respectively coerce to isomorphic *) (* quotient groups. *) (* section_repr s == canonical representative of the isomorphism class *) (* of the section s. *) (* mksrepr G1 G2 == canonical representative of the isomorphism class *) (* of (G1 / G2)%sec. *) (* mkfactors G s == if s is [:: s1, s2, ..., sn], constructs the list *) (* [:: mksrepr G s1, mksrepr s1 s2, ..., mksrepr sn-1 sn] *) (* comps G s == s is a composition series for G i.e. s is a *) (* decreasing sequence of subgroups of G *) (* in which two adjacent elements are maxnormal one *) (* in the other and the last element of s is 1. *) (* Given aT and rT two finGroupTypes, (D : {group rT}), (A : {group aT}) and *) (* (to : groupAction A D) an external action. *) (* maxainv to B C == C is a maximal proper normal subgroup of B *) (* invariant by (the external action of A via) to. *) (* asimple to B == the maximal proper normal subgroup of B invariant *) (* by the external action to is trivial. *) (* acomps to G s == s is a composition series for G invariant by to, *) (* i.e. s is a decreasing sequence of subgroups of G *) (* in which two adjacent elements are maximally *) (* invariant by to one in the other and the *) (* last element of s is 1. *) (* We prove two versions of the result: *) (* - JordanHolderUniqueness establishes the uniqueness up to permutation *) (* and isomorphism of the lists of factors in composition series of a *) (* given group. *) (* - StrongJordanHolderUniqueness extends the result to composition series *) (* invariant by an external group action. *) (* See also "The Rooster and the Butterflies", proceedings of Calculemus 2013,*) (* by Assia Mahboubi. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope section_scope. Import GroupScope. Inductive section (gT : finGroupType) := GSection of {group gT} * {group gT}. Delimit Scope section_scope with sec. Bind Scope section_scope with section. Definition mkSec (gT : finGroupType) (G1 G2 : {group gT}) := GSection (G1, G2). Infix "/" := mkSec : section_scope. Coercion pair_of_section gT (s : section gT) := let: GSection u := s in u. Coercion quotient_of_section gT (s : section gT) : GroupSet.sort _ := s.1 / s.2. Coercion section_group gT (s : section gT) : {group (coset_of s.2)} := Eval hnf in [group of s]. Section Sections. Variables (gT : finGroupType). Implicit Types (G : {group gT}) (s : section gT). HB.instance Definition _ := [isNew for (@pair_of_section gT)]. HB.instance Definition _ := [Finite of section gT by <:]. Canonical section_group. (* Isomorphic sections *) Definition section_isog := [rel x y : section gT | x \isog y]. (* A witness of the isomorphism class of a section *) Definition section_repr s := odflt (1 / 1)%sec (pick (section_isog ^~ s)). Definition mksrepr G1 G2 := section_repr (mkSec G1 G2). Lemma section_reprP s : section_repr s \isog s. Proof. by rewrite /section_repr; case: pickP => //= /(_ s); rewrite isog_refl. Qed. Lemma section_repr_isog s1 s2 : s1 \isog s2 -> section_repr s1 = section_repr s2. Proof. by move=> iso12; congr (odflt _ _); apply: eq_pick => s; apply: isog_transr. Qed. Definition mkfactors (G : {group gT}) (s : seq {group gT}) := map section_repr (pairmap (@mkSec _) G s). End Sections. Section CompositionSeries. Variable gT : finGroupType. Local Notation gTg := {group gT}. Implicit Types (G : gTg) (s : seq gTg). Local Notation compo := [rel x y : {set gT} | maxnormal y x x]. Definition comps G s := ((last G s) == 1%G) && compo.-series G s. Lemma compsP G s : reflect (last G s = 1%G /\ path [rel x y : gTg | maxnormal y x x] G s) (comps G s). Proof. by apply: (iffP andP) => [] [/eqP]. Qed. Lemma trivg_comps G s : comps G s -> (G :==: 1) = (s == [::]). Proof. case/andP=> ls cs; apply/eqP/eqP=> [G1 | s1]; last first. by rewrite s1 /= in ls; apply/eqP. by case: s {ls} cs => //= H s /andP[/maxgroupp]; rewrite G1 /proper sub1G andbF. Qed. Lemma comps_cons G H s : comps G (H :: s) -> comps H s. Proof. by case/andP => /= ls /andP[_]; rewrite /comps ls. Qed. Lemma simple_compsP G s : comps G s -> reflect (s = [:: 1%G]) (simple G). Proof. move=> cs; apply: (iffP idP) => [|s1]; last first. by rewrite s1 /comps eqxx /= andbT -simple_maxnormal in cs. case: s cs => [/trivg_comps/eqP-> | H s]; first by case/simpleP; rewrite eqxx. rewrite [comps _ _]andbCA /= => /andP[/maxgroupp maxH /trivg_comps/esym nil_s]. rewrite simple_maxnormal => /maxgroupP[_ simG]. have H1: H = 1%G by apply/val_inj/simG; rewrite // sub1G. by move: nil_s; rewrite H1 eqxx => /eqP->. Qed. Lemma exists_comps (G : gTg) : exists s, comps G s. Proof. elim: {G} #|G| {1 3}G (leqnn #|G|) => [G | n IHn G cG]. by rewrite leqNgt cardG_gt0. have [sG | nsG] := boolP (simple G). by exists [:: 1%G]; rewrite /comps eqxx /= -simple_maxnormal andbT. have [-> | ntG] := eqVneq G 1%G; first by exists [::]; rewrite /comps eqxx. have [N maxN] := ex_maxnormal_ntrivg ntG. have [|s /andP[ls cs]] := IHn N. by rewrite -ltnS (leq_trans _ cG) // proper_card // (maxnormal_proper maxN). by exists (N :: s); apply/and3P. Qed. (******************************************************************************) (* The factors associated to two composition series of the same group are *) (* the same up to isomorphism and permutation *) (******************************************************************************) Lemma JordanHolderUniqueness (G : gTg) (s1 s2 : seq gTg) : comps G s1 -> comps G s2 -> perm_eq (mkfactors G s1) (mkfactors G s2). Proof. have [n] := ubnP #|G|; elim: n G => // n Hi G in s1 s2 * => /ltnSE-cG cs1 cs2. have [G1 | ntG] := boolP (G :==: 1). have -> : s1 = [::] by apply/eqP; rewrite -(trivg_comps cs1). have -> : s2 = [::] by apply/eqP; rewrite -(trivg_comps cs2). by rewrite /= perm_refl. have [sG | nsG] := boolP (simple G). by rewrite (simple_compsP cs1 sG) (simple_compsP cs2 sG) perm_refl. case es1: s1 cs1 => [|N1 st1] cs1. by move: (trivg_comps cs1); rewrite eqxx; move/negP:ntG. case es2: s2 cs2 => [|N2 st2] cs2 {s1 es1}. by move: (trivg_comps cs2); rewrite eqxx; move/negP:ntG. case/andP: cs1 => /= lst1; case/andP=> maxN_1 pst1. case/andP: cs2 => /= lst2; case/andP=> maxN_2 pst2. have cN1 : #|N1| < n. by rewrite (leq_trans _ cG) ?proper_card ?(maxnormal_proper maxN_1). have cN2 : #|N2| < n. by rewrite (leq_trans _ cG) ?proper_card ?(maxnormal_proper maxN_2). case: (N1 =P N2) {s2 es2} => [eN12 |]. by rewrite eN12 /= perm_cons Hi // /comps ?lst2 //= -eN12 lst1. move/eqP; rewrite -val_eqE /=; move/eqP=> neN12. have nN1G : N1 <| G by apply: maxnormal_normal. have nN2G : N2 <| G by apply: maxnormal_normal. pose N := (N1 :&: N2)%G. have nNG : N <| G. by rewrite /normal subIset ?(normal_sub nN1G) //= normsI ?normal_norm. have iso1 : (G / N1)%G \isog (N2 / N)%G. rewrite isog_sym /= -(maxnormalM maxN_1 maxN_2) //. rewrite (@normC _ N1 N2) ?(subset_trans (normal_sub nN1G)) ?normal_norm //. by rewrite weak_second_isog ?(subset_trans (normal_sub nN2G)) ?normal_norm. have iso2 : (G / N2)%G \isog (N1 / N)%G. rewrite isog_sym /= -(maxnormalM maxN_1 maxN_2) // setIC. by rewrite weak_second_isog ?(subset_trans (normal_sub nN1G)) ?normal_norm. have [sN /andP[lsN csN]] := exists_comps N. have i1 : perm_eq (mksrepr G N1 :: mkfactors N1 st1) [:: mksrepr G N1, mksrepr N1 N & mkfactors N sN]. rewrite perm_cons -[mksrepr _ _ :: _]/(mkfactors N1 [:: N & sN]). apply: Hi=> //; rewrite /comps ?lst1 //= lsN csN andbT /=. rewrite -quotient_simple. by rewrite -(isog_simple iso2) quotient_simple. by rewrite (normalS (subsetIl N1 N2) (normal_sub nN1G)). have i2 : perm_eq (mksrepr G N2 :: mkfactors N2 st2) [:: mksrepr G N2, mksrepr N2 N & mkfactors N sN]. rewrite perm_cons -[mksrepr _ _ :: _]/(mkfactors N2 [:: N & sN]). apply: Hi=> //; rewrite /comps ?lst2 //= lsN csN andbT /=. rewrite -quotient_simple. by rewrite -(isog_simple iso1) quotient_simple. by rewrite (normalS (subsetIr N1 N2) (normal_sub nN2G)). pose fG1 := [:: mksrepr G N1, mksrepr N1 N & mkfactors N sN]. pose fG2 := [:: mksrepr G N2, mksrepr N2 N & mkfactors N sN]. have i3 : perm_eq fG1 fG2. rewrite (@perm_catCA _ [::_] [::_]) /mksrepr. rewrite (@section_repr_isog _ (mkSec _ _) (mkSec _ _) iso1). rewrite -(@section_repr_isog _ (mkSec _ _) (mkSec _ _) iso2). exact: perm_refl. apply: (perm_trans i1); apply: (perm_trans i3); rewrite perm_sym. by apply: perm_trans i2; apply: perm_refl. Qed. End CompositionSeries. (******************************************************************************) (* Helper lemmas for group actions. *) (******************************************************************************) Section MoreGroupAction. Variables (aT rT : finGroupType). Variables (A : {group aT}) (D : {group rT}). Variable to : groupAction A D. Lemma gactsP (G : {set rT}) : reflect {acts A, on G | to} [acts A, on G | to]. Proof. apply: (iffP idP) => [nGA x|nGA]; first exact: acts_act. apply/subsetP=> a Aa /[!inE]; rewrite Aa. by apply/subsetP=> x; rewrite inE nGA. Qed. Lemma gactsM (N1 N2 : {set rT}) : N1 \subset D -> N2 \subset D -> [acts A, on N1 | to] -> [acts A, on N2 | to] -> [acts A, on N1 * N2 | to]. Proof. move=> sN1D sN2D aAN1 aAN2; apply/gactsP=> x Ax y. apply/idP/idP; case/mulsgP=> y1 y2 N1y1 N2y2 e. move: (actKin to Ax y); rewrite e; move<-. rewrite gactM ?groupV ?(subsetP sN1D y1) ?(subsetP sN2D) //. by apply: mem_mulg; rewrite ?(gactsP _ aAN1) ?(gactsP _ aAN2) // groupV. rewrite e gactM // ?(subsetP sN1D y1) ?(subsetP sN2D) //. by apply: mem_mulg; rewrite ?(gactsP _ aAN1) // ?(gactsP _ aAN2). Qed. Lemma gactsI (N1 N2 : {set rT}) : [acts A, on N1 | to] -> [acts A, on N2 | to] -> [acts A, on N1 :&: N2 | to]. Proof. move=> aAN1 aAN2. apply/subsetP=> x Ax; rewrite !inE Ax /=; apply/subsetP=> y Ny /[1!inE]. case/setIP: Ny=> N1y N2y; rewrite inE ?astabs_act ?N1y ?N2y //. - by move/subsetP: aAN2; move/(_ x Ax). - by move/subsetP: aAN1; move/(_ x Ax). Qed. Lemma gastabsP (S : {set rT}) (a : aT) : a \in A -> reflect (forall x, (to x a \in S) = (x \in S)) (a \in 'N(S | to)). Proof. move=> Aa; apply: (iffP idP) => [nSa x|nSa]; first exact: astabs_act. by rewrite !inE Aa; apply/subsetP=> x; rewrite inE nSa. Qed. End MoreGroupAction. (******************************************************************************) (* Helper lemmas for quotient actions. *) (******************************************************************************) Section MoreQuotientAction. Variables (aT rT : finGroupType). Variables (A : {group aT})(D : {group rT}). Variable to : groupAction A D. Lemma qact_dom_doms (H : {group rT}) : H \subset D -> qact_dom to H \subset A. Proof. by move=> sHD; apply/subsetP=> x; rewrite qact_domE // inE; case/andP. Qed. Lemma acts_qact_doms (H : {group rT}) : H \subset D -> [acts A, on H | to] -> qact_dom to H :=: A. Proof. move=> sHD aH; apply/eqP; rewrite eqEsubset; apply/andP. split; first exact: qact_dom_doms. apply/subsetP=> x Ax; rewrite qact_domE //; apply/gastabsP=> //. by move/gactsP: aH; move/(_ x Ax). Qed. Lemma qacts_cosetpre (H : {group rT}) (K' : {group coset_of H}) : H \subset D -> [acts A, on H | to] -> [acts qact_dom to H, on K' | to / H] -> [acts A, on coset H @*^-1 K' | to]. Proof. move=> sHD aH aK'; apply/subsetP=> x Ax; move: (Ax) (subsetP aK'). rewrite -{1}(acts_qact_doms sHD aH) => qdx; move/(_ x qdx) => nx. rewrite !inE Ax; apply/subsetP=> y; case/morphpreP=> Ny /= K'Hy /[1!inE]. apply/morphpreP; split; first by rewrite acts_qact_dom_norm. by move/gastabsP: nx; move/(_ qdx (coset H y)); rewrite K'Hy qactE. Qed. Lemma qacts_coset (H K : {group rT}) : H \subset D -> [acts A, on K | to] -> [acts qact_dom to H, on (coset H) @* K | to / H]. Proof. move=> sHD aK. apply/subsetP=> x qdx; rewrite inE qdx inE; apply/subsetP=> y. case/morphimP=> z Nz Kz /= e; rewrite e inE qactE // imset_f // inE. move/gactsP: aK; move/(_ x (subsetP (qact_dom_doms sHD) _ qdx) z); rewrite Kz. move->; move/acts_act: (acts_qact_dom to H); move/(_ x qdx z). by rewrite Nz andbT. Qed. End MoreQuotientAction. Section StableCompositionSeries. Variables (aT rT : finGroupType). Variables (D : {group rT})(A : {group aT}). Variable to : groupAction A D. Definition maxainv (B C : {set rT}) := [max C of H | [&& (H <| B), ~~ (B \subset H) & [acts A, on H | to]]]. Section MaxAinvProps. Variables K N : {group rT}. Lemma maxainv_norm : maxainv K N -> N <| K. Proof. by move/maxgroupp; case/andP. Qed. Lemma maxainv_proper : maxainv K N -> N \proper K. Proof. by move/maxgroupp; case/andP; rewrite properE; move/normal_sub->; case/andP. Qed. Lemma maxainv_sub : maxainv K N -> N \subset K. Proof. by move=> h; apply: proper_sub; apply: maxainv_proper. Qed. Lemma maxainv_ainvar : maxainv K N -> A \subset 'N(N | to). Proof. by move/maxgroupp; case/and3P. Qed. Lemma maxainvS : maxainv K N -> N \subset K. Proof. by move=> pNN; rewrite proper_sub // maxainv_proper. Qed. Lemma maxainv_exists : K :!=: 1 -> {N : {group rT} | maxainv K N}. Proof. move=> nt; apply: ex_maxgroup. exists [1 rT]%G. rewrite /= normal1 subG1 nt /=. apply/subsetP=> a Da; rewrite !inE Da /= sub1set !inE. by rewrite /= -actmE // morph1 eqxx. Qed. End MaxAinvProps. Lemma maxainvM (G H K : {group rT}) : H \subset D -> K \subset D -> maxainv G H -> maxainv G K -> H :<>: K -> H * K = G. Proof. move: H K => N1 N2 sN1D sN2D pmN1 pmN2 neN12. have cN12 : commute N1 N2. apply: normC; apply: (subset_trans (maxainv_sub pmN1)). by rewrite normal_norm ?maxainv_norm. wlog nsN21 : G N1 N2 sN1D sN2D pmN1 pmN2 neN12 cN12/ ~~(N1 \subset N2). move/eqP: (neN12); rewrite eqEsubset negb_and; case/orP=> ns; first by apply. by rewrite cN12; apply=> //; apply: sym_not_eq. have nP : N1 * N2 <| G by rewrite normalM ?maxainv_norm. have sN2P : N2 \subset N1 * N2 by rewrite mulg_subr ?group1. case/maxgroupP: (pmN1); case/andP=> nN1G pN1G mN1. case/maxgroupP: (pmN2); case/andP=> nN2G pN2G mN2. case/andP: pN1G=> nsGN1 ha1; case/andP: pN2G=> nsGN2 ha2. case e : (G \subset N1 * N2). by apply/eqP; rewrite eqEsubset e mulG_subG !normal_sub. have: N1 <*> N2 = N2 by apply: mN2; rewrite /= ?comm_joingE // nP e /= gactsM. by rewrite comm_joingE // => h; move: nsN21; rewrite -h mulg_subl. Qed. Definition asimple (K : {set rT}) := maxainv K 1. Implicit Types (H K : {group rT}) (s : seq {group rT}). Lemma asimpleP K : reflect [/\ K :!=: 1 & forall H, H <| K -> [acts A, on H | to] -> H :=: 1 \/ H :=: K] (asimple K). Proof. apply: (iffP idP). case/maxgroupP; rewrite normal1 /=; case/andP=> nsK1 aK H1. rewrite eqEsubset negb_and nsK1 /=; split => // H nHK ha. case eHK : (H :==: K); first by right; apply/eqP. left; apply: H1; rewrite ?sub1G // nHK; move/negbT: eHK. by rewrite eqEsubset negb_and normal_sub //=; move->. case=> ntK h; apply/maxgroupP; split. move: ntK; rewrite eqEsubset sub1G andbT normal1; move->. apply/subsetP=> a Da; rewrite !inE Da /= sub1set !inE. by rewrite /= -actmE // morph1 eqxx. move=> H /andP[nHK /andP[nsKH ha]] _. case: (h _ nHK ha)=> // /eqP; rewrite eqEsubset. by rewrite (negbTE nsKH) andbF. Qed. Definition acomps K s := ((last K s) == 1%G) && path [rel x y : {group rT} | maxainv x y] K s. Lemma acompsP K s : reflect (last K s = 1%G /\ path [rel x y : {group rT} | maxainv x y] K s) (acomps K s). Proof. by apply: (iffP andP); case; move/eqP. Qed. Lemma trivg_acomps K s : acomps K s -> (K :==: 1) = (s == [::]). Proof. case/andP=> ls cs; apply/eqP/eqP; last first. by move=> se; rewrite se /= in ls; apply/eqP. move=> G1; case: s ls cs => // H s _ /=; case/andP; case/maxgroupP. by rewrite G1 sub1G andbF. Qed. Lemma acomps_cons K H s : acomps K (H :: s) -> acomps H s. Proof. by case/andP => /= ls; case/andP=> _ p; rewrite /acomps ls. Qed. Lemma asimple_acompsP K s : acomps K s -> reflect (s = [:: 1%G]) (asimple K). Proof. move=> cs; apply: (iffP idP); last first. by move=> se; move: cs; rewrite se /=; case/andP=> /=; rewrite andbT. case: s cs. by rewrite /acomps /= andbT; move/eqP->; case/asimpleP; rewrite eqxx. move=> H s cs sG; apply/eqP. rewrite eqseq_cons -(trivg_acomps (acomps_cons cs)) andbC andbb. case/acompsP: cs => /= ls; case/andP=> mH ps. case/maxgroupP: sG; case/and3P => _ ntG _ ->; rewrite ?sub1G //. rewrite (maxainv_norm mH); case/andP: (maxainv_proper mH)=> _ ->. exact: (maxainv_ainvar mH). Qed. Lemma exists_acomps K : exists s, acomps K s. Proof. elim: {K} #|K| {1 3}K (leqnn #|K|) => [K | n Hi K cK]. by rewrite leqNgt cardG_gt0. case/orP: (orbN (asimple K)) => [sK | nsK]. by exists [:: (1%G : {group rT})]; rewrite /acomps eqxx /= andbT. case/orP: (orbN (K :==: 1))=> [tK | ntK]. by exists (Nil _); rewrite /acomps /= andbT. case: (maxainv_exists ntK)=> N pmN. have cN: #|N| <= n. by rewrite -ltnS (leq_trans _ cK) // proper_card // (maxainv_proper pmN). case: (Hi _ cN)=> s; case/andP=> lasts ps; exists [:: N & s]; rewrite /acomps. by rewrite last_cons lasts /= pmN. Qed. End StableCompositionSeries. Arguments maxainv {aT rT D%_G A%_G} to%_gact B%_g C%_g. Arguments asimple {aT rT D%_G A%_G} to%_gact K%_g. Section StrongJordanHolder. Section AuxiliaryLemmas. Variables aT rT : finGroupType. Variables (A : {group aT}) (D : {group rT}) (to : groupAction A D). Lemma maxainv_asimple_quo (G H : {group rT}) : H \subset D -> maxainv to G H -> asimple (to / H) (G / H). Proof. move=> sHD /maxgroupP[/and3P[nHG pHG aH] Hmax]. apply/asimpleP; split; first by rewrite -subG1 quotient_sub1 ?normal_norm. move=> K' nK'Q aK'. have: (K' \proper (G / H)) || (G / H == K'). by rewrite properE eqEsubset andbC (normal_sub nK'Q) !andbT orbC orbN. case/orP=> [ pHQ | eQH]; last by right; apply sym_eq; apply/eqP. left; pose K := ((coset H) @*^-1 K')%G. have eK'I : K' \subset (coset H) @* 'N(H). by rewrite (subset_trans (normal_sub nK'Q)) ?morphimS ?normal_norm. have eKK' : K' :=: K / H by rewrite /(K / H) morphpreK //=. suff eKH : K :=: H by rewrite -trivg_quotient eKK' eKH. have sHK : H \subset K by rewrite -ker_coset kerE morphpreS // sub1set group1. apply: Hmax => //; apply/and3P; split; last exact: qacts_cosetpre. by rewrite -(quotientGK nHG) cosetpre_normal. by move: (proper_subn pHQ); rewrite sub_morphim_pre ?normal_norm. Qed. Lemma asimple_quo_maxainv (G H : {group rT}) : H \subset D -> G \subset D -> [acts A, on G | to] -> [acts A, on H | to] -> H <| G -> asimple (to / H) (G / H) -> maxainv to G H. Proof. move=> sHD sGD aG aH nHG /asimpleP[ntQ maxQ]; apply/maxgroupP; split. by rewrite nHG -quotient_sub1 ?normal_norm // subG1 ntQ. move=> K /and3P[nKG nsGK aK] sHK. pose K' := (K / H)%G. have K'dQ : K' <| (G / H)%G by apply: morphim_normal. have nKH : H <| K by rewrite (normalS _ _ nHG) // normal_sub. have: K' :=: 1%G \/ K' :=: (G / H). apply: (maxQ K' K'dQ) => /=. apply/subsetP=> x Adx. rewrite inE Adx /= inE. apply/subsetP=> y. rewrite quotientE; case/morphimP=> z Nz Kz ->; rewrite /= !inE qactE //. have ntoyx : to z x \in 'N(H) by rewrite (acts_qact_dom_norm Adx). apply/morphimP; exists (to z x) => //. suff h: qact_dom to H \subset A. by rewrite astabs_act // (subsetP aK) //; apply: (subsetP h). by apply/subsetP=> t; rewrite qact_domE // inE; case/andP. case=> [|/quotient_injG /[!inE]/(_ nKH nHG) c]; last by rewrite c subxx in nsGK. rewrite /= -trivg_quotient => tK'; apply: (congr1 (@gval _)); move: tK'. by apply: (@quotient_injG _ H); rewrite ?inE /= ?normal_refl. Qed. Lemma asimpleI (N1 N2 : {group rT}) : N2 \subset 'N(N1) -> N1 \subset D -> [acts A, on N1 | to] -> [acts A, on N2 | to] -> asimple (to / N1) (N2 / N1) -> asimple (to / (N2 :&: N1)) (N2 / (N2 :&: N1)). Proof. move=> nN21 sN1D aN1 aN2 /asimpleP[ntQ1 max1]. have [f1 [f1e f1ker f1pre f1im]] := restrmP (coset_morphism N1) nN21. have hf2' : N2 \subset 'N(N2 :&: N1) by apply: normsI => //; rewrite normG. have hf2'' : 'ker (coset (N2 :&: N1)) \subset 'ker f1. by rewrite f1ker !ker_coset. pose f2 := factm_morphism hf2'' hf2'. apply/asimpleP; split. rewrite /= setIC; apply/negP; move: (second_isog nN21); move/isog_eq1->. by apply/negP. move=> H nHQ2 aH; pose K := f2 @* H. have nKQ1 : K <| N2 / N1. rewrite (_ : N2 / N1 = f2 @* (N2 / (N2 :&: N1))) ?morphim_normal //. by rewrite morphim_factm f1im. have sqA : qact_dom to N1 \subset A. by apply/subsetP=> t; rewrite qact_domE // inE; case/andP. have nNN2 : (N2 :&: N1) <| N2. by rewrite /normal subsetIl; apply: normsI => //; apply: normG. have aKQ1 : [acts qact_dom to N1, on K | to / N1]. pose H':= coset (N2 :&: N1)@*^-1 H. have eHH' : H :=: H' / (N2 :&: N1) by rewrite cosetpreK. have -> : K :=: f1 @* H' by rewrite /K eHH' morphim_factm. have sH'N2 : H' \subset N2. rewrite /H' eHH' quotientGK ?normal_cosetpre //=. by rewrite sub_cosetpre_quo ?normal_sub. have -> : f1 @* H' = coset N1 @* H' by rewrite f1im //=. apply: qacts_coset => //; apply: qacts_cosetpre => //; last exact: gactsI. by apply: (subset_trans (subsetIr _ _)). have injf2 : 'injm f2. by rewrite ker_factm f1ker /= ker_coset /= subG1 /= -quotientE trivg_quotient. have iHK : H \isog K. apply/isogP; pose f3 := restrm_morphism (normal_sub nHQ2) f2. by exists f3; rewrite 1?injm_restrm // morphim_restrm setIid. case: (max1 _ nKQ1 aKQ1). by move/eqP; rewrite -(isog_eq1 iHK); move/eqP->; left. move=> he /=; right; apply/eqP; rewrite eqEcard normal_sub //=. move: (second_isog nN21); rewrite setIC; move/card_isog->; rewrite -he. by move/card_isog: iHK=> <-; rewrite leqnn. Qed. End AuxiliaryLemmas. Variables (aT rT : finGroupType). Variables (A : {group aT}) (D : {group rT}) (to : groupAction A D). (******************************************************************************) (* The factors associated to two A-stable composition series of the same *) (* group are the same up to isomorphism and permutation *) (******************************************************************************) Lemma StrongJordanHolderUniqueness (G : {group rT}) (s1 s2 : seq {group rT}) : G \subset D -> acomps to G s1 -> acomps to G s2 -> perm_eq (mkfactors G s1) (mkfactors G s2). Proof. have [n] := ubnP #|G|; elim: n G => // n Hi G in s1 s2 * => cG hsD cs1 cs2. case/orP: (orbN (G :==: 1)) => [tG | ntG]. have -> : s1 = [::] by apply/eqP; rewrite -(trivg_acomps cs1). have -> : s2 = [::] by apply/eqP; rewrite -(trivg_acomps cs2). by rewrite /= perm_refl. case/orP: (orbN (asimple to G))=> [sG | nsG]. have -> : s1 = [:: 1%G ] by apply/(asimple_acompsP cs1). have -> : s2 = [:: 1%G ] by apply/(asimple_acompsP cs2). by rewrite /= perm_refl. case es1: s1 cs1 => [|N1 st1] cs1. by move: (trivg_comps cs1); rewrite eqxx; move/negP:ntG. case es2: s2 cs2 => [|N2 st2] cs2 {s1 es1}. by move: (trivg_comps cs2); rewrite eqxx; move/negP:ntG. case/andP: cs1 => /= lst1; case/andP=> maxN_1 pst1. case/andP: cs2 => /= lst2; case/andP=> maxN_2 pst2. have sN1D : N1 \subset D. by apply: subset_trans hsD; apply: maxainv_sub maxN_1. have sN2D : N2 \subset D. by apply: subset_trans hsD; apply: maxainv_sub maxN_2. have cN1 : #|N1| < n. by rewrite -ltnS (leq_trans _ cG) ?ltnS ?proper_card ?(maxainv_proper maxN_1). have cN2 : #|N2| < n. by rewrite -ltnS (leq_trans _ cG) ?ltnS ?proper_card ?(maxainv_proper maxN_2). case: (N1 =P N2) {s2 es2} => [eN12 |]. by rewrite eN12 /= perm_cons Hi // /acomps ?lst2 //= -eN12 lst1. move/eqP; rewrite -val_eqE /=; move/eqP=> neN12. have nN1G : N1 <| G by apply: (maxainv_norm maxN_1). have nN2G : N2 <| G by apply: (maxainv_norm maxN_2). pose N := (N1 :&: N2)%G. have nNG : N <| G. by rewrite /normal subIset ?(normal_sub nN1G) //= normsI ?normal_norm. have iso1 : (G / N1)%G \isog (N2 / N)%G. rewrite isog_sym /= -(maxainvM _ _ maxN_1 maxN_2) //. rewrite (@normC _ N1 N2) ?(subset_trans (normal_sub nN1G)) ?normal_norm //. by rewrite weak_second_isog ?(subset_trans (normal_sub nN2G)) ?normal_norm. have iso2 : (G / N2)%G \isog (N1 / N)%G. rewrite isog_sym /= -(maxainvM _ _ maxN_1 maxN_2) // setIC. by rewrite weak_second_isog ?(subset_trans (normal_sub nN1G)) ?normal_norm. case: (exists_acomps to N)=> sN; case/andP=> lsN csN. have aN1 : [acts A, on N1 | to]. by case/maxgroupP: maxN_1; case/and3P. have aN2 : [acts A, on N2 | to]. by case/maxgroupP: maxN_2; case/and3P. have nNN1 : N <| N1. by apply: (normalS _ _ nNG); rewrite ?subsetIl ?normal_sub. have nNN2 : N <| N2. by apply: (normalS _ _ nNG); rewrite ?subsetIr ?normal_sub. have aN : [ acts A, on N1 :&: N2 | to]. apply/subsetP=> x Ax; rewrite !inE Ax /=; apply/subsetP=> y Ny; rewrite inE. case/setIP: Ny=> N1y N2y. rewrite inE ?astabs_act ?N1y ?N2y //. by move/subsetP: aN2; move/(_ x Ax). by move/subsetP: aN1; move/(_ x Ax). have i1 : perm_eq (mksrepr G N1 :: mkfactors N1 st1) [:: mksrepr G N1, mksrepr N1 N & mkfactors N sN]. rewrite perm_cons -[mksrepr _ _ :: _]/(mkfactors N1 [:: N & sN]). apply: Hi=> //; rewrite /acomps ?lst1 //= lsN csN andbT /=. apply: asimple_quo_maxainv=> //; first by apply: subIset; rewrite sN1D. apply: asimpleI => //. by apply: subset_trans (normal_norm nN2G); apply: normal_sub. rewrite -quotientMidl (maxainvM _ _ maxN_2) //. by apply: maxainv_asimple_quo. by move=> e; apply: neN12. have i2 : perm_eq (mksrepr G N2 :: mkfactors N2 st2) [:: mksrepr G N2, mksrepr N2 N & mkfactors N sN]. rewrite perm_cons -[mksrepr _ _ :: _]/(mkfactors N2 [:: N & sN]). apply: Hi=> //; rewrite /acomps ?lst2 //= lsN csN andbT /=. apply: asimple_quo_maxainv=> //; first by apply: subIset; rewrite sN1D. have e : N1 :&: N2 :=: N2 :&: N1 by rewrite setIC. rewrite (group_inj (setIC N1 N2)); apply: asimpleI => //. by apply: subset_trans (normal_norm nN1G); apply: normal_sub. rewrite -quotientMidl (maxainvM _ _ maxN_1) //. exact: maxainv_asimple_quo. pose fG1 := [:: mksrepr G N1, mksrepr N1 N & mkfactors N sN]. pose fG2 := [:: mksrepr G N2, mksrepr N2 N & mkfactors N sN]. have i3 : perm_eq fG1 fG2. rewrite (@perm_catCA _ [::_] [::_]) /mksrepr. rewrite (@section_repr_isog _ (mkSec _ _) (mkSec _ _) iso1). rewrite -(@section_repr_isog _ (mkSec _ _) (mkSec _ _) iso2). exact: perm_refl. apply: (perm_trans i1); apply: (perm_trans i3); rewrite perm_sym. by apply: perm_trans i2; apply: perm_refl. Qed. End StrongJordanHolder.
trace.lean
import Mathlib.Tactic.Trace set_option linter.unusedTactic false /-- info: 7 -/ #guard_msgs in example : True := by trace 2 + 2 + 3 trivial /-- info: hello world -/ #guard_msgs in example : True := by trace "hello" ++ " world" trivial
Support.lean
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Embedding import Mathlib.Algebra.MonoidAlgebra.Module import Mathlib.LinearAlgebra.Finsupp.Supported import Mathlib.Algebra.Group.Pointwise.Finset.Basic /-! # Lemmas about the support of a finitely supported function -/ open scoped Pointwise universe u₁ u₂ u₃ namespace MonoidAlgebra open Finset Finsupp variable {k : Type u₁} {G : Type u₂} [Semiring k] theorem support_mul [Mul G] [DecidableEq G] (a b : MonoidAlgebra k G) : (a * b).support ⊆ a.support * b.support := by rw [MonoidAlgebra.mul_def] exact support_sum.trans <| biUnion_subset.2 fun _x hx ↦ support_sum.trans <| biUnion_subset.2 fun _y hy ↦ support_single_subset.trans <| singleton_subset_iff.2 <| mem_image₂_of_mem hx hy theorem support_single_mul_subset [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) (r : k) (a : G) : (single a r * f : MonoidAlgebra k G).support ⊆ Finset.image (a * ·) f.support := (support_mul _ _).trans <| (Finset.image₂_subset_right support_single_subset).trans <| by rw [Finset.image₂_singleton_left] theorem support_mul_single_subset [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) (r : k) (a : G) : (f * single a r).support ⊆ Finset.image (· * a) f.support := (support_mul _ _).trans <| (Finset.image₂_subset_left support_single_subset).trans <| by rw [Finset.image₂_singleton_right] theorem support_single_mul_eq_image [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) {r : k} (hr : ∀ y, r * y = 0 ↔ y = 0) {x : G} (lx : IsLeftRegular x) : (single x r * f : MonoidAlgebra k G).support = Finset.image (x * ·) f.support := by refine subset_antisymm (support_single_mul_subset f _ _) fun y hy => ?_ obtain ⟨y, yf, rfl⟩ : ∃ a : G, a ∈ f.support ∧ x * a = y := by grind simp only [mul_apply, mem_support_iff.mp yf, hr, mem_support_iff, sum_single_index, Finsupp.sum_ite_eq', Ne, not_false_iff, if_true, zero_mul, ite_self, sum_zero, lx.eq_iff] theorem support_mul_single_eq_image [DecidableEq G] [Mul G] (f : MonoidAlgebra k G) {r : k} (hr : ∀ y, y * r = 0 ↔ y = 0) {x : G} (rx : IsRightRegular x) : (f * single x r).support = Finset.image (· * x) f.support := by refine subset_antisymm (support_mul_single_subset f _ _) fun y hy => ?_ obtain ⟨y, yf, rfl⟩ : ∃ a : G, a ∈ f.support ∧ a * x = y := by grind simp only [mul_apply, mem_support_iff.mp yf, hr, mem_support_iff, sum_single_index, Finsupp.sum_ite_eq', Ne, not_false_iff, if_true, mul_zero, ite_self, rx.eq_iff] theorem support_mul_single [Mul G] [IsRightCancelMul G] (f : MonoidAlgebra k G) (r : k) (hr : ∀ y, y * r = 0 ↔ y = 0) (x : G) : (f * single x r).support = f.support.map (mulRightEmbedding x) := by classical ext simp only [support_mul_single_eq_image f hr (IsRightRegular.all x), mem_image, mem_map, mulRightEmbedding_apply] theorem support_single_mul [Mul G] [IsLeftCancelMul G] (f : MonoidAlgebra k G) (r : k) (hr : ∀ y, r * y = 0 ↔ y = 0) (x : G) : (single x r * f : MonoidAlgebra k G).support = f.support.map (mulLeftEmbedding x) := by classical ext simp only [support_single_mul_eq_image f hr (IsLeftRegular.all x), mem_image, mem_map, mulLeftEmbedding_apply] lemma support_one_subset [One G] : (1 : MonoidAlgebra k G).support ⊆ 1 := Finsupp.support_single_subset @[simp] lemma support_one [One G] [NeZero (1 : k)] : (1 : MonoidAlgebra k G).support = 1 := Finsupp.support_single_ne_zero _ one_ne_zero section Span variable [MulOneClass G] /-- An element of `MonoidAlgebra k G` is in the subalgebra generated by its support. -/ theorem mem_span_support (f : MonoidAlgebra k G) : f ∈ Submodule.span k (of k G '' (f.support : Set G)) := by erw [of, MonoidHom.coe_mk, ← supported_eq_span_single, Finsupp.mem_supported] end Span end MonoidAlgebra namespace AddMonoidAlgebra open Finset Finsupp MulOpposite variable {k : Type u₁} {G : Type u₂} [Semiring k] theorem support_mul [DecidableEq G] [Add G] (a b : k[G]) : (a * b).support ⊆ a.support + b.support := @MonoidAlgebra.support_mul k (Multiplicative G) _ _ _ _ _ theorem support_mul_single [Add G] [IsRightCancelAdd G] (f : k[G]) (r : k) (hr : ∀ y, y * r = 0 ↔ y = 0) (x : G) : (f * single x r : k[G]).support = f.support.map (addRightEmbedding x) := MonoidAlgebra.support_mul_single (G := Multiplicative G) _ _ hr _ theorem support_single_mul [Add G] [IsLeftCancelAdd G] (f : k[G]) (r : k) (hr : ∀ y, r * y = 0 ↔ y = 0) (x : G) : (single x r * f : k[G]).support = f.support.map (addLeftEmbedding x) := MonoidAlgebra.support_single_mul (G := Multiplicative G) _ _ hr _ lemma support_one_subset [Zero G] : (1 : k[G]).support ⊆ 0 := Finsupp.support_single_subset @[simp] lemma support_one [Zero G] [NeZero (1 : k)] : (1 : k[G]).support = 0 := Finsupp.support_single_ne_zero _ one_ne_zero section Span /-- An element of `k[G]` is in the submodule generated by its support. -/ theorem mem_span_support [AddZeroClass G] (f : k[G]) : f ∈ Submodule.span k (of k G '' (f.support : Set G)) := by erw [of, MonoidHom.coe_mk, ← Finsupp.supported_eq_span_single, Finsupp.mem_supported] /-- An element of `k[G]` is in the subalgebra generated by its support, using unbundled inclusion. -/ theorem mem_span_support' (f : k[G]) : f ∈ Submodule.span k (of' k G '' (f.support : Set G)) := by delta of' rw [← Finsupp.supported_eq_span_single, Finsupp.mem_supported] end Span end AddMonoidAlgebra
SwapVar.lean
/- Copyright (c) 2022 Arthur Paulino. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Arthur Paulino -/ import Mathlib.Tactic.Basic import Mathlib.Tactic.SwapVar example {P Q : Prop} (q : P) (p : Q) : P ∧ Q := by swap_var p ↔ q exact ⟨p, q⟩ example {a b : Nat} (h : a = b) : a = b ∧ a = a := by swap_var a ↔ b guard_hyp h : b = a guard_target = b = a ∧ b = b exact ⟨h, Eq.refl b⟩ example {a b c d : Nat} (h : a = b ∧ c = d) : a = b ∧ c = d := by swap_var a ↔ b, b c guard_target = c = a ∧ b = d exact h
Directed.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, Yaël Dillies -/ import Mathlib.Data.Set.Image /-! # Directed indexed families and sets This file defines directed indexed families and directed sets. An indexed family/set is directed iff each pair of elements has a shared upper bound. ## Main declarations * `Directed r f`: Predicate stating that the indexed family `f` is `r`-directed. * `DirectedOn r s`: Predicate stating that the set `s` is `r`-directed. * `IsDirected α r`: Prop-valued mixin stating that `α` is `r`-directed. Follows the style of the unbundled relation classes such as `IsTotal`. ## TODO Define connected orders (the transitive symmetric closure of `≤` is everything) and show that (co)directed orders are connected. ## References * [Gierz et al, *A Compendium of Continuous Lattices*][GierzEtAl1980] -/ open Function universe u v w variable {α : Type u} {β : Type v} {ι : Sort w} (r r' s : α → α → Prop) /-- Local notation for a relation -/ local infixl:50 " ≼ " => r /-- A family of elements of α is directed (with respect to a relation `≼` on α) if there is a member of the family `≼`-above any pair in the family. -/ def Directed (f : ι → α) := ∀ x y, ∃ z, f x ≼ f z ∧ f y ≼ f z /-- A subset of α is directed if there is an element of the set `≼`-above any pair of elements in the set. -/ def DirectedOn (s : Set α) := ∀ x ∈ s, ∀ y ∈ s, ∃ z ∈ s, x ≼ z ∧ y ≼ z variable {r r'} theorem directedOn_iff_directed {s} : @DirectedOn α r s ↔ Directed r (Subtype.val : s → α) := by simp only [DirectedOn, Directed, Subtype.exists, exists_and_left, exists_prop, Subtype.forall] exact forall₂_congr fun x _ => by simp [And.comm, and_assoc] alias ⟨DirectedOn.directed_val, _⟩ := directedOn_iff_directed theorem directedOn_range {f : ι → α} : Directed r f ↔ DirectedOn r (Set.range f) := by simp_rw [Directed, DirectedOn, Set.forall_mem_range, Set.exists_range_iff] protected alias ⟨Directed.directedOn_range, _⟩ := directedOn_range theorem directedOn_image {s : Set β} {f : β → α} : DirectedOn r (f '' s) ↔ DirectedOn (f ⁻¹'o r) s := by simp only [DirectedOn, Set.mem_image, exists_exists_and_eq_and, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, Order.Preimage] theorem DirectedOn.mono' {s : Set α} (hs : DirectedOn r s) (h : ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → r a b → r' a b) : DirectedOn r' s := fun _ hx _ hy => let ⟨z, hz, hxz, hyz⟩ := hs _ hx _ hy ⟨z, hz, h hx hz hxz, h hy hz hyz⟩ theorem DirectedOn.mono {s : Set α} (h : DirectedOn r s) (H : ∀ ⦃a b⦄, r a b → r' a b) : DirectedOn r' s := h.mono' fun _ _ _ _ h ↦ H h theorem directed_comp {ι} {f : ι → β} {g : β → α} : Directed r (g ∘ f) ↔ Directed (g ⁻¹'o r) f := Iff.rfl theorem Directed.mono {s : α → α → Prop} {ι} {f : ι → α} (H : ∀ a b, r a b → s a b) (h : Directed r f) : Directed s f := fun a b => let ⟨c, h₁, h₂⟩ := h a b ⟨c, H _ _ h₁, H _ _ h₂⟩ theorem Directed.mono_comp (r : α → α → Prop) {ι} {rb : β → β → Prop} {g : α → β} {f : ι → α} (hg : ∀ ⦃x y⦄, r x y → rb (g x) (g y)) (hf : Directed r f) : Directed rb (g ∘ f) := directed_comp.2 <| hf.mono hg theorem DirectedOn.mono_comp {r : α → α → Prop} {rb : β → β → Prop} {g : α → β} {s : Set α} (hg : ∀ ⦃x y⦄, r x y → rb (g x) (g y)) (hf : DirectedOn r s) : DirectedOn rb (g '' s) := directedOn_image.mpr (hf.mono hg) /-- A set stable by supremum is `≤`-directed. -/ theorem directedOn_of_sup_mem [SemilatticeSup α] {S : Set α} (H : ∀ ⦃i j⦄, i ∈ S → j ∈ S → i ⊔ j ∈ S) : DirectedOn (· ≤ ·) S := fun a ha b hb => ⟨a ⊔ b, H ha hb, le_sup_left, le_sup_right⟩ theorem Directed.extend_bot [Preorder α] [OrderBot α] {e : ι → β} {f : ι → α} (hf : Directed (· ≤ ·) f) (he : Function.Injective e) : Directed (· ≤ ·) (Function.extend e f ⊥) := by intro a b rcases (em (∃ i, e i = a)).symm with (ha | ⟨i, rfl⟩) · use b simp [Function.extend_apply' _ _ _ ha] rcases (em (∃ i, e i = b)).symm with (hb | ⟨j, rfl⟩) · use e i simp [Function.extend_apply' _ _ _ hb] rcases hf i j with ⟨k, hi, hj⟩ use e k simp only [he.extend_apply, *, true_and] /-- A set stable by infimum is `≥`-directed. -/ theorem directedOn_of_inf_mem [SemilatticeInf α] {S : Set α} (H : ∀ ⦃i j⦄, i ∈ S → j ∈ S → i ⊓ j ∈ S) : DirectedOn (· ≥ ·) S := directedOn_of_sup_mem (α := αᵒᵈ) H theorem IsTotal.directed [IsTotal α r] (f : ι → α) : Directed r f := fun i j => Or.casesOn (total_of r (f i) (f j)) (fun h => ⟨j, h, refl _⟩) fun h => ⟨i, refl _, h⟩ /-- `IsDirected α r` states that for any elements `a`, `b` there exists an element `c` such that `r a c` and `r b c`. -/ class IsDirected (α : Type*) (r : α → α → Prop) : Prop where /-- For every pair of elements `a` and `b` there is a `c` such that `r a c` and `r b c` -/ directed (a b : α) : ∃ c, r a c ∧ r b c theorem directed_of (r : α → α → Prop) [IsDirected α r] (a b : α) : ∃ c, r a c ∧ r b c := IsDirected.directed _ _ theorem directed_of₃ (r : α → α → Prop) [IsDirected α r] [IsTrans α r] (a b c : α) : ∃ d, r a d ∧ r b d ∧ r c d := have ⟨e, hae, hbe⟩ := directed_of r a b have ⟨f, hef, hcf⟩ := directed_of r e c ⟨f, Trans.trans hae hef, Trans.trans hbe hef, hcf⟩ theorem directed_id [IsDirected α r] : Directed r id := directed_of r theorem directed_id_iff : Directed r id ↔ IsDirected α r := ⟨fun h => ⟨h⟩, @directed_id _ _⟩ theorem directedOn_univ [IsDirected α r] : DirectedOn r Set.univ := fun a _ b _ => let ⟨c, hc⟩ := directed_of r a b ⟨c, trivial, hc⟩ theorem directedOn_univ_iff : DirectedOn r Set.univ ↔ IsDirected α r := ⟨fun h => ⟨fun a b => let ⟨c, _, hc⟩ := h a trivial b trivial ⟨c, hc⟩⟩, @directedOn_univ _ _⟩ -- see Note [lower instance priority] instance (priority := 100) IsTotal.to_isDirected [IsTotal α r] : IsDirected α r := directed_id_iff.1 <| IsTotal.directed _ theorem isDirected_mono [IsDirected α r] (h : ∀ ⦃a b⦄, r a b → s a b) : IsDirected α s := ⟨fun a b => let ⟨c, ha, hb⟩ := IsDirected.directed a b ⟨c, h ha, h hb⟩⟩ theorem exists_ge_ge [LE α] [IsDirected α (· ≤ ·)] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c := directed_of (· ≤ ·) a b theorem exists_le_le [LE α] [IsDirected α (· ≥ ·)] (a b : α) : ∃ c, c ≤ a ∧ c ≤ b := directed_of (· ≥ ·) a b instance OrderDual.isDirected_ge [LE α] [IsDirected α (· ≤ ·)] : IsDirected αᵒᵈ (· ≥ ·) := by assumption instance OrderDual.isDirected_le [LE α] [IsDirected α (· ≥ ·)] : IsDirected αᵒᵈ (· ≤ ·) := by assumption /-- A monotone function on an upwards-directed type is directed. -/ theorem directed_of_isDirected_le [LE α] [IsDirected α (· ≤ ·)] {f : α → β} {r : β → β → Prop} (H : ∀ ⦃i j⦄, i ≤ j → r (f i) (f j)) : Directed r f := directed_id.mono_comp _ H theorem Monotone.directed_le [Preorder α] [IsDirected α (· ≤ ·)] [Preorder β] {f : α → β} : Monotone f → Directed (· ≤ ·) f := directed_of_isDirected_le theorem Antitone.directed_ge [Preorder α] [IsDirected α (· ≤ ·)] [Preorder β] {f : α → β} (hf : Antitone f) : Directed (· ≥ ·) f := directed_of_isDirected_le hf /-- An antitone function on a downwards-directed type is directed. -/ theorem directed_of_isDirected_ge [LE α] [IsDirected α (· ≥ ·)] {r : β → β → Prop} {f : α → β} (hf : ∀ a₁ a₂, a₁ ≤ a₂ → r (f a₂) (f a₁)) : Directed r f := directed_of_isDirected_le (α := αᵒᵈ) fun _ _ ↦ hf _ _ theorem Monotone.directed_ge [Preorder α] [IsDirected α (· ≥ ·)] [Preorder β] {f : α → β} (hf : Monotone f) : Directed (· ≥ ·) f := directed_of_isDirected_ge hf theorem Antitone.directed_le [Preorder α] [IsDirected α (· ≥ ·)] [Preorder β] {f : α → β} (hf : Antitone f) : Directed (· ≤ ·) f := directed_of_isDirected_ge hf section Reflexive protected theorem DirectedOn.insert (h : Reflexive r) (a : α) {s : Set α} (hd : DirectedOn r s) (ha : ∀ b ∈ s, ∃ c ∈ s, a ≼ c ∧ b ≼ c) : DirectedOn r (insert a s) := by rintro x (rfl | hx) y (rfl | hy) · exact ⟨y, Set.mem_insert _ _, h _, h _⟩ · obtain ⟨w, hws, hwr⟩ := ha y hy exact ⟨w, Set.mem_insert_of_mem _ hws, hwr⟩ · obtain ⟨w, hws, hwr⟩ := ha x hx exact ⟨w, Set.mem_insert_of_mem _ hws, hwr.symm⟩ · obtain ⟨w, hws, hwr⟩ := hd x hx y hy exact ⟨w, Set.mem_insert_of_mem _ hws, hwr⟩ theorem directedOn_singleton (h : Reflexive r) (a : α) : DirectedOn r ({a} : Set α) := fun x hx _ hy => ⟨x, hx, h _, hx.symm ▸ hy.symm ▸ h _⟩ theorem directedOn_pair (h : Reflexive r) {a b : α} (hab : a ≼ b) : DirectedOn r ({a, b} : Set α) := (directedOn_singleton h _).insert h _ fun c hc => ⟨c, hc, hc.symm ▸ hab, h _⟩ theorem directedOn_pair' (h : Reflexive r) {a b : α} (hab : a ≼ b) : DirectedOn r ({b, a} : Set α) := by rw [Set.pair_comm] apply directedOn_pair h hab end Reflexive section Preorder variable [Preorder α] {a : α} protected theorem IsMin.isBot [IsDirected α (· ≥ ·)] (h : IsMin a) : IsBot a := fun b => let ⟨_, hca, hcb⟩ := exists_le_le a b (h hca).trans hcb protected theorem IsMax.isTop [IsDirected α (· ≤ ·)] (h : IsMax a) : IsTop a := h.toDual.isBot lemma DirectedOn.is_bot_of_is_min {s : Set α} (hd : DirectedOn (· ≥ ·) s) {m} (hm : m ∈ s) (hmin : ∀ a ∈ s, a ≤ m → m ≤ a) : ∀ a ∈ s, m ≤ a := fun a as => let ⟨x, xs, xm, xa⟩ := hd m hm a as (hmin x xs xm).trans xa lemma DirectedOn.is_top_of_is_max {s : Set α} (hd : DirectedOn (· ≤ ·) s) {m} (hm : m ∈ s) (hmax : ∀ a ∈ s, m ≤ a → a ≤ m) : ∀ a ∈ s, a ≤ m := @DirectedOn.is_bot_of_is_min αᵒᵈ _ s hd m hm hmax theorem isTop_or_exists_gt [IsDirected α (· ≤ ·)] (a : α) : IsTop a ∨ ∃ b, a < b := (em (IsMax a)).imp IsMax.isTop not_isMax_iff.mp theorem isBot_or_exists_lt [IsDirected α (· ≥ ·)] (a : α) : IsBot a ∨ ∃ b, b < a := @isTop_or_exists_gt αᵒᵈ _ _ a theorem isBot_iff_isMin [IsDirected α (· ≥ ·)] : IsBot a ↔ IsMin a := ⟨IsBot.isMin, IsMin.isBot⟩ theorem isTop_iff_isMax [IsDirected α (· ≤ ·)] : IsTop a ↔ IsMax a := ⟨IsTop.isMax, IsMax.isTop⟩ end Preorder section PartialOrder variable [PartialOrder β] section Nontrivial variable [Nontrivial β] variable (β) in theorem exists_lt_of_directed_ge [IsDirected β (· ≥ ·)] : ∃ a b : β, a < b := by rcases exists_pair_ne β with ⟨a, b, hne⟩ rcases isBot_or_exists_lt a with (ha | ⟨c, hc⟩) exacts [⟨a, b, (ha b).lt_of_ne hne⟩, ⟨_, _, hc⟩] variable (β) in theorem exists_lt_of_directed_le [IsDirected β (· ≤ ·)] : ∃ a b : β, a < b := let ⟨a, b, h⟩ := exists_lt_of_directed_ge βᵒᵈ ⟨b, a, h⟩ protected theorem IsMin.not_isMax [IsDirected β (· ≥ ·)] {b : β} (hb : IsMin b) : ¬ IsMax b := by intro hb' obtain ⟨a, c, hac⟩ := exists_lt_of_directed_ge β have := hb.isBot a obtain rfl := (hb' <| this).antisymm this exact hb'.not_lt hac protected theorem IsMin.not_isMax' [IsDirected β (· ≤ ·)] {b : β} (hb : IsMin b) : ¬ IsMax b := fun hb' ↦ hb'.toDual.not_isMax hb.toDual protected theorem IsMax.not_isMin [IsDirected β (· ≤ ·)] {b : β} (hb : IsMax b) : ¬ IsMin b := fun hb' ↦ hb.toDual.not_isMax hb'.toDual protected theorem IsMax.not_isMin' [IsDirected β (· ≥ ·)] {b : β} (hb : IsMax b) : ¬ IsMin b := fun hb' ↦ hb'.toDual.not_isMin hb.toDual end Nontrivial variable [Preorder α] {f : α → β} {s : Set α} -- TODO: Generalise the following two lemmas to connected orders /-- If `f` is monotone and antitone on a directed order, then `f` is constant. -/ lemma constant_of_monotone_antitone [IsDirected α (· ≤ ·)] (hf : Monotone f) (hf' : Antitone f) (a b : α) : f a = f b := by obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b exact le_antisymm ((hf hac).trans <| hf' hbc) ((hf hbc).trans <| hf' hac) /-- If `f` is monotone and antitone on a directed set `s`, then `f` is constant on `s`. -/ lemma constant_of_monotoneOn_antitoneOn (hf : MonotoneOn f s) (hf' : AntitoneOn f s) (hs : DirectedOn (· ≤ ·) s) : ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → f a = f b := by rintro a ha b hb obtain ⟨c, hc, hac, hbc⟩ := hs _ ha _ hb exact le_antisymm ((hf ha hc hac).trans <| hf' hb hc hbc) ((hf hb hc hbc).trans <| hf' ha hc hac) end PartialOrder -- see Note [lower instance priority] instance (priority := 100) SemilatticeSup.to_isDirected_le [SemilatticeSup α] : IsDirected α (· ≤ ·) := ⟨fun a b => ⟨a ⊔ b, le_sup_left, le_sup_right⟩⟩ -- see Note [lower instance priority] instance (priority := 100) SemilatticeInf.to_isDirected_ge [SemilatticeInf α] : IsDirected α (· ≥ ·) := ⟨fun a b => ⟨a ⊓ b, inf_le_left, inf_le_right⟩⟩ -- see Note [lower instance priority] instance (priority := 100) OrderTop.to_isDirected_le [LE α] [OrderTop α] : IsDirected α (· ≤ ·) := ⟨fun _ _ => ⟨⊤, le_top _, le_top _⟩⟩ -- see Note [lower instance priority] instance (priority := 100) OrderBot.to_isDirected_ge [LE α] [OrderBot α] : IsDirected α (· ≥ ·) := ⟨fun _ _ => ⟨⊥, bot_le _, bot_le _⟩⟩ namespace DirectedOn section Pi variable {ι : Type*} {α : ι → Type*} {r : (i : ι) → α i → α i → Prop} lemma proj {d : Set (Π i, α i)} (hd : DirectedOn (fun x y => ∀ i, r i (x i) (y i)) d) (i : ι) : DirectedOn (r i) ((fun a => a i) '' d) := DirectedOn.mono_comp (fun _ _ h => h) (mono hd fun ⦃_ _⦄ h ↦ h i) lemma pi {d : (i : ι) → Set (α i)} (hd : ∀ (i : ι), DirectedOn (r i) (d i)) : DirectedOn (fun x y => ∀ i, r i (x i) (y i)) (Set.pi Set.univ d) := by intro a ha b hb choose f hfd haf hbf using fun i => hd i (a i) (ha i trivial) (b i) (hb i trivial) exact ⟨f, fun i _ => hfd i, haf, hbf⟩ end Pi section Prod variable {r₂ : β → β → Prop} /-- Local notation for a relation -/ local infixl:50 " ≼₁ " => r /-- Local notation for a relation -/ local infixl:50 " ≼₂ " => r₂ lemma fst {d : Set (α × β)} (hd : DirectedOn (fun p q ↦ p.1 ≼₁ q.1 ∧ p.2 ≼₂ q.2) d) : DirectedOn (· ≼₁ ·) (Prod.fst '' d) := DirectedOn.mono_comp (fun ⦃_ _⦄ h ↦ h) (mono hd fun ⦃_ _⦄ h ↦ h.1) lemma snd {d : Set (α × β)} (hd : DirectedOn (fun p q ↦ p.1 ≼₁ q.1 ∧ p.2 ≼₂ q.2) d) : DirectedOn (· ≼₂ ·) (Prod.snd '' d) := DirectedOn.mono_comp (fun ⦃_ _⦄ h ↦ h) (mono hd fun ⦃_ _⦄ h ↦ h.2) lemma prod {d₁ : Set α} {d₂ : Set β} (h₁ : DirectedOn (· ≼₁ ·) d₁) (h₂ : DirectedOn (· ≼₂ ·) d₂) : DirectedOn (fun p q ↦ p.1 ≼₁ q.1 ∧ p.2 ≼₂ q.2) (d₁ ×ˢ d₂) := fun _ hpd _ hqd => by obtain ⟨r₁, hdr₁, hpr₁, hqr₁⟩ := h₁ _ hpd.1 _ hqd.1 obtain ⟨r₂, hdr₂, hpr₂, hqr₂⟩ := h₂ _ hpd.2 _ hqd.2 exact ⟨⟨r₁, r₂⟩, ⟨hdr₁, hdr₂⟩, ⟨hpr₁, hpr₂⟩, ⟨hqr₁, hqr₂⟩⟩ end Prod end DirectedOn
galois.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div. From mathcomp Require Import choice fintype tuple finfun bigop ssralg poly. From mathcomp Require Import polydiv finset fingroup morphism quotient perm. From mathcomp Require Import action zmodp cyclic matrix mxalgebra vector. From mathcomp Require Import falgebra fieldext separable. (******************************************************************************) (* Basic Galois field theory *) (* *) (* This file defines: *) (* splittingFieldFor K p E <-> E is the smallest field over K that splits p *) (* into linear factors *) (* kHom K E f <=> f : 'End(L) is a ring morphism on E and fixes K *) (* kAut K E f <=> f : 'End(L) is a kHom K E and f @: E == E *) (* kHomExtend E f x y == a kHom K <<E; x>> that extends f and maps x to y, *) (* when f \is a kHom K E and root (minPoly E x) y *) (* splittingFieldType F == the interface type of splitting field extensions *) (* of F, that is, extensions generated by all the *) (* algebraic roots of some polynomial, or, *) (* equivalently, normal field extensions of F *) (* The HB class is called SplittingField. *) (* splitting_field_axiom F L == the axiom stating that L is a splitting field *) (* gal_of E == the group_type of automorphisms of E over the *) (* base field F *) (* 'Gal(E / K) == the group of automorphisms of E that fix K *) (* fixedField s == the field fixed by the set of automorphisms s *) (* fixedField set0 = E when set0 : {set: gal_of E} *) (* normalField K E <=> E is invariant for every 'Gal(L / K) for every L *) (* galois K E <=> E is a normal and separable field extension of K *) (* galTrace K E a == \sum_(f in 'Gal(E / K)) (f a) *) (* galNorm K E a == \prod_(f in 'Gal(E / K)) (f a) *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Reserved Notation "''Gal' ( A / B )" (A at level 35, format "''Gal' ( A / B )"). Import GroupScope GRing.Theory. Local Open Scope ring_scope. Section SplittingFieldFor. Variables (F : fieldType) (L : fieldExtType F). Definition splittingFieldFor (U : {vspace L}) (p : {poly L}) (V : {vspace L}) := exists2 rs, p %= \prod_(z <- rs) ('X - z%:P) & <<U & rs>>%VS = V. Lemma splittingFieldForS (K M E : {subfield L}) p : (K <= M)%VS -> (M <= E)%VS -> splittingFieldFor K p E -> splittingFieldFor M p E. Proof. move=> sKM sKE [rs Dp genL]; exists rs => //; apply/eqP. rewrite eqEsubv -[in X in _ && (X <= _)%VS]genL adjoin_seqSl // andbT. by apply/Fadjoin_seqP; split; rewrite // -genL; apply: seqv_sub_adjoin. Qed. End SplittingFieldFor. Section kHom. Variables (F : fieldType) (L : fieldExtType F). Implicit Types (U V : {vspace L}) (K E : {subfield L}) (f g : 'End(L)). Definition kHom U V f := ahom_in V f && (U <= fixedSpace f)%VS. Lemma kHomP_tmp {K V f} : reflect [/\ {in K, forall x, f x = x} & {in V &, forall x y, f (x * y) = f x * f y}] (kHom K V f). Proof. apply: (iffP andP) => [[/ahom_inP[fM _] /subvP idKf] | [idKf fM]]. by split=> // x /idKf/fixedSpaceP. split; last by apply/subvP=> x /idKf/fixedSpaceP. by apply/ahom_inP; split=> //; rewrite idKf ?mem1v. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `kHomP_tmp` instead")] Lemma kHomP {K V f} : reflect [/\ {in V &, forall x y, f (x * y) = f x * f y} & {in K, forall x, f x = x}] (kHom K V f). Proof. by apply: (iffP kHomP_tmp) => [][]. Qed. Lemma kAHomP {U V} {f : 'AEnd(L)} : reflect {in U, forall x, f x = x} (kHom U V f). Proof. by rewrite /kHom ahomWin; apply: fixedSpacesP. Qed. Lemma kHom1 U V : kHom U V \1. Proof. by apply/kAHomP => u _; rewrite lfunE. Qed. Lemma k1HomE V f : kHom 1 V f = ahom_in V f. Proof. by apply: andb_idr => /ahom_inP[_ f1]; apply/fixedSpaceP. Qed. Lemma kHom_monoid_morphism (f : 'End(L)) : reflect (monoid_morphism f) (kHom 1 {:L} f). Proof. by rewrite k1HomE; apply: ahomP_tmp. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `kHom_monoid_morphism` instead")] Lemma kHom_lrmorphism (f : 'End(L)) : reflect (multiplicative f) (kHom 1 {:L} f). Proof. #[warning="-deprecated-since-mathcomp-2.5.0"] by rewrite k1HomE; apply: ahomP. Qed. (* Lemma kHom_lrmorphism (f : 'End(L)) : reflect (lrmorphism f) (kHom 1 {:L} f). *) (* Proof. by rewrite k1HomE; apply: ahomP. Qed. *) Lemma k1AHom V (f : 'AEnd(L)) : kHom 1 V f. Proof. by rewrite k1HomE ahomWin. Qed. Lemma kHom_poly_id K E f p : kHom K E f -> p \is a polyOver K -> map_poly f p = p. Proof. by case/kHomP_tmp=> idKf _ /polyOverP Kp; apply/polyP=> i; rewrite coef_map /= idKf. Qed. Lemma kHomSl U1 U2 V f : (U1 <= U2)%VS -> kHom U2 V f -> kHom U1 V f. Proof. by rewrite /kHom => sU12 /andP[-> /(subv_trans sU12)]. Qed. Lemma kHomSr K V1 V2 f : (V1 <= V2)%VS -> kHom K V2 f -> kHom K V1 f. Proof. by move/subvP=> sV12 /kHomP_tmp[idKf /(sub_in2 sV12)fM]; apply/kHomP_tmp. Qed. Lemma kHomS K1 K2 V1 V2 f : (K1 <= K2)%VS -> (V1 <= V2)%VS -> kHom K2 V2 f -> kHom K1 V1 f. Proof. by move=> sK12 sV12 /(kHomSl sK12)/(kHomSr sV12). Qed. Lemma kHom_eq K E f g : (K <= E)%VS -> {in E, f =1 g} -> kHom K E f = kHom K E g. Proof. move/subvP=> sKE eq_fg; wlog suffices: f g eq_fg / kHom K E f -> kHom K E g. by move=> IH; apply/idP/idP; apply: IH => x /eq_fg. case/kHomP_tmp=> idKf fM; apply/kHomP_tmp. by split=> [x Kx | x y Ex Ey]; rewrite -!eq_fg ?fM ?rpredM // ?idKf ?sKE. Qed. Lemma kHom_inv K E f : kHom K E f -> {in E, {morph f : x / x^-1}}. Proof. case/kHomP_tmp=> idKf fM x Ex. have [-> | nz_x] := eqVneq x 0; first by rewrite linear0 invr0 linear0. have fxV: f x * f x^-1 = 1 by rewrite -fM ?rpredV ?divff // idKf ?mem1v. have Ufx: f x \is a GRing.unit by apply/unitrPr; exists (f x^-1). by apply: (mulrI Ufx); rewrite divrr. Qed. Lemma kHom_dim K E f : kHom K E f -> \dim (f @: E) = \dim E. Proof. move=> homKf; have [idKf fM] := kHomP_tmp homKf. apply/limg_dim_eq/eqP; rewrite -subv0; apply/subvP=> v. rewrite memv_cap memv0 memv_ker => /andP[Ev]; apply: contraLR => nz_v. by rewrite -unitfE unitrE -(kHom_inv homKf) // -fM ?rpredV ?divff ?idKf ?mem1v. Qed. Section kHomMorphism. Variables (K E : {subfield L}) (f : 'End(L)). Let kHomf : subvs_of E -> L := f \o vsval. Lemma kHom_is_zmod_morphism : kHom K E f -> zmod_morphism kHomf. Proof. by case/kHomP_tmp => idKf fM; apply: raddfB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `kHom_is_zmod_morphism` instead")] Definition kHom_is_additive := kHom_is_zmod_morphism. Lemma kHom_is_monoid_morphism : kHom K E f -> monoid_morphism kHomf. Proof. case/kHomP_tmp=> idKf fM; rewrite /kHomf. by split=> [|a b] /=; [rewrite algid1 idKf // mem1v | rewrite /= fM ?subvsP]. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `kHom_is_monoid_morphism` instead")] Definition kHom_is_multiplicative := (fun p => (p.1, p.2)) \o kHom_is_monoid_morphism. Variable (homKEf : kHom K E f). HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ kHomf (kHom_is_zmod_morphism homKEf). HB.instance Definition _ := @GRing.isMonoidMorphism.Build _ _ kHomf (kHom_is_monoid_morphism homKEf). Definition kHom_rmorphism := Eval hnf in (kHomf : {rmorphism _ -> _}). End kHomMorphism. Lemma kHom_horner K E f p x : kHom K E f -> p \is a polyOver E -> x \in E -> f p.[x] = (map_poly f p).[f x]. Proof. move=> homKf /polyOver_subvs[{}p -> Ex]; pose fRM := kHom_rmorphism homKf. by rewrite (horner_map _ _ (Subvs Ex)) -[f _](horner_map fRM) map_poly_comp. Qed. Lemma kHom_root K E f p x : kHom K E f -> p \is a polyOver E -> x \in E -> root p x -> root (map_poly f p) (f x). Proof. by move/kHom_horner=> homKf Ep Ex /rootP px0; rewrite /root -homKf ?px0 ?raddf0. Qed. Lemma kHom_root_id K E f p x : (K <= E)%VS -> kHom K E f -> p \is a polyOver K -> x \in E -> root p x -> root p (f x). Proof. move=> sKE homKf Kp Ex /(kHom_root homKf (polyOverSv sKE Kp) Ex). by rewrite (kHom_poly_id homKf). Qed. Section kHomExtend. Variables (K E : {subfield L}) (f : 'End(L)) (x y : L). Let kHomf z := (map_poly f (Fadjoin_poly E x z)).[y]. Fact kHomExtend_zmod_morphism_subproof : zmod_morphism kHomf. Proof. by move=> a b; rewrite /kHomf 2!raddfB hornerD hornerN. Qed. Fact kHomExtend_scalable_subproof : scalable kHomf. Proof. move=> k a; rewrite /kHomf linearZ /= -[RHS]mulr_algl -hornerZ; congr _.[_]. by apply/polyP => i; rewrite !(coefZ, coef_map) /= !mulr_algl linearZ. Qed. HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ kHomf kHomExtend_zmod_morphism_subproof. HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ kHomf kHomExtend_scalable_subproof. Let kHomExtendLinear := Eval hnf in (kHomf : {linear _ -> _}). Definition kHomExtend := linfun kHomExtendLinear. Lemma kHomExtendE z : kHomExtend z = (map_poly f (Fadjoin_poly E x z)).[y]. Proof. by rewrite lfunE. Qed. Hypotheses (sKE : (K <= E)%VS) (homKf : kHom K E f). Local Notation Px := (minPoly E x). Hypothesis fPx_y_0 : root (map_poly f Px) y. Lemma kHomExtend_id z : z \in E -> kHomExtend z = f z. Proof. by move=> Ez; rewrite kHomExtendE Fadjoin_polyC ?map_polyC ?hornerC. Qed. Lemma kHomExtend_val : kHomExtend x = y. Proof. have fX: map_poly f 'X = 'X by rewrite (kHom_poly_id homKf) ?polyOverX. have [Ex | E'x] := boolP (x \in E); last first. by rewrite kHomExtendE Fadjoin_polyX // fX hornerX. have:= fPx_y_0; rewrite (minPoly_XsubC Ex) raddfB /= map_polyC fX root_XsubC /=. by rewrite (kHomExtend_id Ex) => /eqP->. Qed. Lemma kHomExtend_poly p : p \in polyOver E -> kHomExtend p.[x] = (map_poly f p).[y]. Proof. move=> Ep; rewrite kHomExtendE (Fadjoin_poly_mod x) //. rewrite (divp_eq (map_poly f p) (map_poly f Px)). rewrite !hornerE (rootP fPx_y_0) mulr0 add0r. have [p1 ->] := polyOver_subvs Ep. have [Px1 ->] := polyOver_subvs (minPolyOver E x). by rewrite -map_modp -!map_poly_comp (map_modp (kHom_rmorphism homKf)). Qed. Lemma kHomExtendP : kHom K <<E; x>> kHomExtend. Proof. have [idKf fM] := kHomP_tmp homKf. apply/kHomP_tmp; split=> [z Kz|]; first by rewrite kHomExtend_id ?(subvP sKE) ?idKf. move=> _ _ /Fadjoin_polyP[p Ep ->] /Fadjoin_polyP[q Eq ->]. rewrite -hornerM !kHomExtend_poly ?rpredM // -hornerM; congr _.[_]. apply/polyP=> i; rewrite coef_map !coefM /= linear_sum /=. by apply: eq_bigr => j _; rewrite !coef_map /= fM ?(polyOverP _). Qed. End kHomExtend. Definition kAut U V f := kHom U V f && (f @: V == V)%VS. Lemma kAutE K E f : kAut K E f = kHom K E f && (f @: E <= E)%VS. Proof. apply/andP/andP=> [[-> /eqP->] // | [homKf EfE]]. by rewrite eqEdim EfE /= (kHom_dim homKf). Qed. Lemma kAutS U1 U2 V f : (U1 <= U2)%VS -> kAut U2 V f -> kAut U1 V f. Proof. by move=> sU12 /andP[/(kHomSl sU12)homU1f EfE]; apply/andP. Qed. Lemma kHom_kAut_sub K E f : kAut K E f -> kHom K E f. Proof. by case/andP. Qed. Lemma kAut_eq K E (f g : 'End(L)) : (K <= E)%VS -> {in E, f =1 g} -> kAut K E f = kAut K E g. Proof. by move=> sKE eq_fg; rewrite !kAutE (kHom_eq sKE eq_fg) (eq_in_limg eq_fg). Qed. Lemma kAutfE K f : kAut K {:L} f = kHom K {:L} f. Proof. by rewrite kAutE subvf andbT. Qed. Lemma kAut1E E (f : 'AEnd(L)) : kAut 1 E f = (f @: E <= E)%VS. Proof. by rewrite kAutE k1AHom. Qed. Lemma kAutf_lker0 K f : kHom K {:L} f -> lker f == 0%VS. Proof. move/(kHomSl (sub1v _))/kHom_monoid_morphism => fM. pose fmM := GRing.isMonoidMorphism.Build _ _ _ fM. pose fRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun f) fmM. by apply/lker0P; apply: (fmorph_inj fRM). Qed. Lemma inv_kHomf K f : kHom K {:L} f -> kHom K {:L} f^-1. Proof. move=> homKf; have [[idKf fM] kerf0] := (kHomP_tmp homKf, kAutf_lker0 homKf). have f1K: cancel f^-1%VF f by apply: lker0_lfunVK. apply/kHomP_tmp; split=> [x Kx | x y _ _]; apply: (lker0P kerf0). by rewrite f1K idKf. by rewrite fM ?memvf ?{1}f1K. Qed. Lemma inv_is_ahom (f : 'AEnd(L)) : ahom_in {:L} f^-1. Proof. have /ahomP_tmp/kHom_monoid_morphism hom1f := valP f. exact/ahomP_tmp/kHom_monoid_morphism/inv_kHomf. Qed. Canonical inv_ahom (f : 'AEnd(L)) : 'AEnd(L) := AHom (inv_is_ahom f). Notation "f ^-1" := (inv_ahom f) : lrfun_scope. Lemma comp_kHom_img K E f g : kHom K (g @: E) f -> kHom K E g -> kHom K E (f \o g). Proof. move=> /kHomP_tmp[idKf fM] /kHomP_tmp[idKg gM]; apply/kHomP_tmp; split=> [x Kx | x y Ex Ey]. by rewrite lfunE /= idKg ?idKf. by rewrite !lfunE /= gM // fM ?memv_img. Qed. Lemma comp_kHom K E f g : kHom K {:L} f -> kHom K E g -> kHom K E (f \o g). Proof. by move/(kHomSr (subvf (g @: E))); apply: comp_kHom_img. Qed. Lemma kHom_extends K E f p U : (K <= E)%VS -> kHom K E f -> p \is a polyOver K -> splittingFieldFor E p U -> {g | kHom K U g & {in E, f =1 g}}. Proof. move=> sKE homEf Kp /sig2_eqW[rs Dp <-{U}]. set r := rs; have rs_r: all [in rs] r by apply/allP. elim: r rs_r => [_|z r IHr /=/andP[rs_z rs_r]] /= in E f sKE homEf *. by exists f; rewrite ?Fadjoin_nil. set Ez := <<E; z>>%AS; pose fpEz := map_poly f (minPoly E z). suffices{IHr} /sigW[y fpEz_y]: exists y, root fpEz y. have homEz_fz: kHom K Ez (kHomExtend E f z y) by apply: kHomExtendP. have sKEz: (K <= Ez)%VS := subv_trans sKE (subv_adjoin E z). have [g homGg Dg] := IHr rs_r _ _ sKEz homEz_fz. exists g => [|x Ex]; first by rewrite adjoin_cons. by rewrite -Dg ?subvP_adjoin // kHomExtend_id. have [m DfpEz]: {m | fpEz %= \prod_(w <- mask m rs) ('X - w%:P)}. apply: dvdp_prod_XsubC; rewrite -(eqp_dvdr _ Dp) -(kHom_poly_id homEf Kp). have /polyOver_subvs[q Dq] := polyOverSv sKE Kp. have /polyOver_subvs[qz Dqz] := minPolyOver E z. rewrite /fpEz Dq Dqz -2?{1}map_poly_comp (dvdp_map (kHom_rmorphism homEf)). rewrite -(dvdp_map (@vsval _ _ E)) -Dqz -Dq. by rewrite minPoly_dvdp ?(polyOverSv sKE) // (eqp_root Dp) root_prod_XsubC. exists (mask m rs)`_0; rewrite (eqp_root DfpEz) root_prod_XsubC mem_nth //. rewrite -ltnS -(size_prod_XsubC _ id) -(eqp_size DfpEz). rewrite size_poly_eq -?lead_coefE ?size_minPoly // (monicP (monic_minPoly E z)). by have [idKf _] := kHomP_tmp homEf; rewrite idKf ?mem1v ?oner_eq0. Qed. End kHom. Notation "f ^-1" := (inv_ahom f) : lrfun_scope. #[warning="-deprecated-since-mathcomp-2.5.0"] Arguments kHomP {F L K V f}. Arguments kHomP_tmp {F L K V f}. Arguments kAHomP {F L U V f}. #[warning="-deprecated-since-mathcomp-2.5.0"] Arguments kHom_lrmorphism {F L f}. Arguments kHom_monoid_morphism {F L f}. Definition splitting_field_axiom (F : fieldType) (L : fieldExtType F) := exists2 p : {poly L}, p \is a polyOver 1%VS & splittingFieldFor 1 p {:L}. HB.mixin Record FieldExt_isSplittingField (F : fieldType) L of FieldExt F L := { splittingFieldP_subproof : splitting_field_axiom L }. #[mathcomp(axiom="splitting_field_axiom"), short(type="splittingFieldType")] HB.structure Definition SplittingField F := { T of FieldExt_isSplittingField F T & FieldExt F T }. Module SplittingFieldExports. Bind Scope ring_scope with SplittingField.sort. End SplittingFieldExports. HB.export SplittingFieldExports. Lemma normal_field_splitting (F : fieldType) (L : fieldExtType F) : (forall (K : {subfield L}) x, exists r, minPoly K x == \prod_(y <- r) ('X - y%:P)) -> SplittingField.axiom L. Proof. move=> normalL; pose r i := sval (sigW (normalL 1%AS (tnth (vbasis {:L}) i))). have sz_r i: size (r i) <= \dim {:L}. rewrite -ltnS -(size_prod_XsubC _ id) /r; case: sigW => _ /= /eqP <-. rewrite size_minPoly ltnS; move: (tnth _ _) => x. by rewrite adjoin_degreeE dimv1 divn1 dimvS // subvf. pose mkf (z : L) := 'X - z%:P. exists (\prod_i \prod_(j < \dim {:L} | j < size (r i)) mkf (r i)`_j). apply: rpred_prod => i _; rewrite big_ord_narrow /= /r; case: sigW => rs /=. by rewrite (big_nth 0) big_mkord => /eqP <- {rs}; apply: minPolyOver. rewrite pair_big_dep /= -big_filter -(big_map _ xpredT mkf). set rF := map _ _; exists rF; first exact: eqpxx. apply/eqP; rewrite eqEsubv subvf -(span_basis (vbasisP {:L})). apply/span_subvP=> _ /tnthP[i ->]; set x := tnth _ i. have /tnthP[j ->]: x \in in_tuple (r i). by rewrite -root_prod_XsubC /r; case: sigW => _ /=/eqP<-; apply: root_minPoly. apply/seqv_sub_adjoin/mapP; rewrite (tnth_nth 0). exists (i, widen_ord (sz_r i) j) => //. by rewrite mem_filter /= ltn_ord mem_index_enum. Qed. HB.factory Record FieldExt_isNormalSplittingField (F : fieldType) L of FieldExt F L := { normal_field_splitting_axiom : forall (K : {subfield L}) x, exists r, minPoly K x == \prod_(y <- r) ('X - y%:P) }. HB.builders Context F L of FieldExt_isNormalSplittingField F L. HB.instance Definition _ := FieldExt_isSplittingField.Build F L (normal_field_splitting normal_field_splitting_axiom). HB.end. Fact regular_splittingAxiom (F : fieldType) : SplittingField.axiom F^o. Proof. exists 1; first exact: rpred1. by exists [::]; [rewrite big_nil eqpxx | rewrite Fadjoin_nil regular_fullv]. Qed. HB.instance Definition _ (F : fieldType) := FieldExt_isSplittingField.Build F F^o (regular_splittingAxiom F). Section SplittingFieldTheory. Variables (F : fieldType) (L : splittingFieldType F). Implicit Types (U V W : {vspace L}). Implicit Types (K M E : {subfield L}). Lemma splittingFieldP : SplittingField.axiom L. Proof. exact: splittingFieldP_subproof. Qed. Lemma splittingPoly : {p : {poly L} | p \is a polyOver 1%VS & splittingFieldFor 1 p {:L}}. Proof. pose factF p s := (p \is a polyOver 1%VS) && (p %= \prod_(z <- s) ('X - z%:P)). suffices [[p rs] /andP[]]: {ps | factF F L ps.1 ps.2 & <<1 & ps.2>> = {:L}}%VS. by exists p; last exists rs. apply: sig2_eqW; have [p F0p [rs splitLp genLrs]] := splittingFieldP. by exists (p, rs); rewrite // /factF F0p splitLp. Qed. Fact fieldOver_splitting E : SplittingField.axiom (fieldOver E). Proof. have [p Fp [r Dp defL]] := splittingFieldP; exists p. apply/polyOverP=> j; rewrite trivial_fieldOver. by rewrite (subvP (sub1v E)) ?(polyOverP Fp). exists r => //; apply/vspaceP=> x; rewrite memvf. have [L0 [_ _ defL0]] := @aspaceOverP _ _ E <<1 & r : seq (fieldOver E)>>. rewrite defL0; have: x \in <<1 & r>>%VS by rewrite defL (@memvf _ L). apply: subvP; apply/Fadjoin_seqP; rewrite -memvE -defL0 mem1v. by split=> // y r_y; rewrite -defL0 seqv_sub_adjoin. Qed. HB.instance Definition _ E := FieldExt_isSplittingField.Build (subvs_of E) (fieldOver E) (fieldOver_splitting E). Lemma enum_AEnd : {kAutL : seq 'AEnd(L) | forall f, f \in kAutL}. Proof. pose isAutL (s : seq 'AEnd(L)) (f : 'AEnd(L)) := kHom 1 {:L} f = (f \in s). suffices [kAutL in_kAutL] : {kAutL : seq 'AEnd(L) | forall f, isAutL kAutL f}. by exists kAutL => f; rewrite -in_kAutL k1AHom. have [p Kp /sig2_eqW[rs Dp defL]] := splittingPoly. do [rewrite {}/isAutL -(erefl (asval 1)); set r := rs; set E := 1%AS] in defL *. have [sKE rs_r]: (1 <= E)%VS /\ all [in rs] r by split; last apply/allP. elim: r rs_r => [_|z r IHr /=/andP[rs_z rs_r]] /= in (E) sKE defL *. rewrite Fadjoin_nil in defL; exists [tuple \1%AF] => f; rewrite defL inE. apply/idP/eqP=> [/kAHomP f1 | ->]; last exact: kHom1. by apply/val_inj/lfunP=> x; rewrite id_lfunE f1 ?memvf. do [set Ez := <<E; z>>%VS; rewrite adjoin_cons] in defL. have sEEz: (E <= Ez)%VS := subv_adjoin E z; have sKEz := subv_trans sKE sEEz. have{IHr} [homEz DhomEz] := IHr rs_r _ sKEz defL. have Ep: p \in polyOver E := polyOverSv sKE Kp. have{rs_z} pz0: root p z by rewrite (eqp_root Dp) root_prod_XsubC. pose pEz := minPoly E z; pose n := \dim_E Ez. have{pz0} [rz DpEz]: {rz : n.-tuple L | pEz %= \prod_(w <- rz) ('X - w%:P)}. have /dvdp_prod_XsubC[m DpEz]: pEz %| \prod_(w <- rs) ('X - w%:P). by rewrite -(eqp_dvdr _ Dp) minPoly_dvdp ?(polyOverSv sKE). suffices sz_rz: size (mask m rs) == n by exists (Tuple sz_rz). rewrite -[n]adjoin_degreeE -eqSS -size_minPoly. by rewrite (eqp_size DpEz) size_prod_XsubC. have fEz i (y := tnth rz i): {f : 'AEnd(L) | kHom E {:L} f & f z = y}. have homEfz: kHom E Ez (kHomExtend E \1 z y). rewrite kHomExtendP ?kHom1 // lfun1_poly. by rewrite (eqp_root DpEz) -/rz root_prod_XsubC mem_tnth. have splitFp: splittingFieldFor Ez p {:L}. exists rs => //; apply/eqP; rewrite eqEsubv subvf -defL adjoin_seqSr //. exact/allP. have [f homLf Df] := kHom_extends sEEz homEfz Ep splitFp. have [ahomf _] := andP homLf; exists (AHom ahomf) => //. rewrite -Df ?memv_adjoin ?(kHomExtend_val (kHom1 E E)) // lfun1_poly. by rewrite (eqp_root DpEz) root_prod_XsubC mem_tnth. exists [seq (s2val (fEz i) \o f)%AF| i <- enum 'I_n, f <- homEz] => f. apply/idP/allpairsP => [homLf | [[i g] [_ Hg ->]] /=]; last first. by case: (fEz i) => fi /= /comp_kHom->; rewrite ?(kHomSl sEEz) ?DhomEz. have /tnthP[i Dfz]: f z \in rz. rewrite memtE /= -root_prod_XsubC -(eqp_root DpEz). by rewrite (kHom_root_id _ homLf) ?memvf ?subvf ?minPolyOver ?root_minPoly. case Dfi: (fEz i) => [fi homLfi fi_z]; have kerfi0 := kAutf_lker0 homLfi. set fj := (fi ^-1 \o f)%AF; suffices Hfj : fj \in homEz. exists (i, fj) => //=; rewrite mem_enum inE Hfj; split => //. by apply/val_inj; rewrite {}Dfi /= (lker0_compVKf kerfi0). rewrite -DhomEz; apply/kAHomP => _ /Fadjoin_polyP[q Eq ->]. have homLfj: kHom E {:L} fj := comp_kHom (inv_kHomf homLfi) homLf. have /kHom_monoid_morphism fjM := kHomSl (sub1v _) homLfj. pose fjmM := GRing.isMonoidMorphism.Build _ _ _ fjM. pose fjRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun fj) fjmM. rewrite -[fj _](horner_map fjRM) (kHom_poly_id homLfj) //=. by rewrite (@lfunE _ _ L) /= Dfz -fi_z lker0_lfunK. Qed. Lemma splitting_field_normal K x : exists r, minPoly K x == \prod_(y <- r) ('X - y%:P). Proof. pose q1 := minPoly 1 x; pose fx_root q (f : 'AEnd(L)) := root q (f x). have [[p F0p splitLp] [autL DautL]] := (splittingFieldP, enum_AEnd). suffices{K} autL_px q: q != 0 -> q %| q1 -> size q > 1 -> has (fx_root q) autL. set q := minPoly K x; have: q \is monic := monic_minPoly K x. have: q %| q1 by rewrite minPolyS // sub1v. have [d] := ubnP (size q); elim: d q => // d IHd q leqd q_dv_q1 mon_q. have nz_q: q != 0 := monic_neq0 mon_q. have [|q_gt1|q_1] := ltngtP (size q) 1; last first; last by rewrite polySpred. by exists nil; rewrite big_nil -eqp_monic ?monic1 // -size_poly_eq1 q_1. have /hasP[f autLf /factor_theorem[q2 Dq]] := autL_px q nz_q q_dv_q1 q_gt1. have mon_q2: q2 \is monic by rewrite -(monicMr _ (monicXsubC (f x))) -Dq. rewrite Dq size_monicM -?size_poly_eq0 ?size_XsubC ?addn2 //= ltnS in leqd. have q2_dv_q1: q2 %| q1 by rewrite (dvdp_trans _ q_dv_q1) // Dq dvdp_mulr. rewrite Dq; have [r /eqP->] := IHd q2 leqd q2_dv_q1 mon_q2. by exists (f x :: r); rewrite big_cons mulrC. have [d] := ubnP (size q); elim: d q => // d IHd q leqd nz_q q_dv_q1 q_gt1. without loss{d leqd IHd nz_q q_gt1} irr_q: q q_dv_q1 / irreducible_poly q. move=> IHq; apply: wlog_neg => not_autLx_q; apply: IHq => //. split=> // q2 q2_neq1 q2_dv_q; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=. rewrite leqNgt; apply: contra not_autLx_q => ltq2q. have nz_q2: q2 != 0 by apply: contraTneq q2_dv_q => ->; rewrite dvd0p. have{q2_neq1} q2_gt1: size q2 > 1 by rewrite neq_ltn polySpred in q2_neq1 *. have{leqd ltq2q} ltq2d: size q2 < d by apply: leq_trans ltq2q _. apply: sub_has (IHd _ ltq2d nz_q2 (dvdp_trans q2_dv_q q_dv_q1) q2_gt1) => f. by rewrite /fx_root !root_factor_theorem => /dvdp_trans->. have{irr_q} [Lz [inLz [z qz0]]]: {Lz : fieldExtType F & {inLz : 'AHom(L, Lz) & {z : Lz | root (map_poly inLz q) z}}}. - have [Lz0 _ [z qz0 defLz]] := irredp_FAdjoin irr_q. pose Lz : fieldExtType _ := baseFieldType Lz0. pose inLz : {rmorphism L -> Lz} := in_alg Lz0. have inLzL_linear: linear (locked inLz). by move=> a u v; rewrite -[in LHS]mulr_algl rmorphD rmorphM -lock mulr_algl. pose inLzLlM := GRing.isLinear.Build _ _ _ _ _ inLzL_linear. pose inLzLL : {linear _ -> _} := HB.pack (locked inLz : _ -> _) inLzLlM. have ihLzZ: ahom_in {:L} (linfun inLzLL). by apply/ahom_inP; split=> [u v|]; rewrite !lfunE (rmorphM, rmorph1). exists Lz, (AHom ihLzZ), z; congr (root _ z): qz0. by apply: eq_map_poly => y; rewrite lfunE /= -lock. pose imL := [aspace of limg inLz]; pose pz := map_poly inLz p. have in_imL u: inLz u \in imL by rewrite memv_img ?memvf. have F0pz: pz \is a polyOver 1%VS. apply/polyOverP=> i; rewrite -(aimg1 inLz) coef_map /= memv_img //. exact: (polyOverP F0p). have{splitLp} splitLpz: splittingFieldFor 1 pz imL. have [r def_p defL] := splitLp; exists (map inLz r) => [|{def_p}]. move: def_p; rewrite -(eqp_map inLz) rmorph_prod. rewrite big_map; congr (_ %= _); apply: eq_big => //= y _. by rewrite rmorphB /= map_polyX map_polyC. apply/eqP; rewrite eqEsubv /= -{2}defL {defL}; apply/andP; split. by apply/Fadjoin_seqP; rewrite sub1v; split=> // _ /mapP[y r_y ->]. elim/last_ind: r => [|r y IHr] /=; first by rewrite !Fadjoin_nil aimg1. rewrite map_rcons !adjoin_rcons /=. apply/subvP=> _ /memv_imgP[_ /Fadjoin_polyP[p1 r_p1 ->] ->]. rewrite -horner_map /= mempx_Fadjoin //=; apply/polyOverP=> i. by rewrite coef_map (subvP IHr) //= memv_img ?(polyOverP r_p1). have [f homLf fxz]: exists2 f : 'End(Lz), kHom 1 imL f & f (inLz x) = z. pose q1z := minPoly 1 (inLz x). have Dq1z: map_poly inLz q1 %| q1z. have F0q1z i: exists a, q1z`_i = a%:A by apply/vlineP/polyOverP/minPolyOver. have [q2 Dq2]: exists q2, q1z = map_poly inLz q2. exists (\poly_(i < size q1z) (sval (sig_eqW (F0q1z i)))%:A). rewrite -{1}[q1z]coefK; apply/polyP=> i; rewrite coef_map !{1}coef_poly. by case: sig_eqW => a; case: ifP; rewrite /= ?rmorph0 ?rmorph_alg. rewrite Dq2 dvdp_map minPoly_dvdp //. apply/polyOverP=> i; have[a] := F0q1z i. rewrite -(rmorph_alg inLz) Dq2 coef_map /= => /fmorph_inj->. exact/rpredZ/mem1v. by rewrite -(fmorph_root inLz) -Dq2 root_minPoly. have q1z_z: root q1z z. rewrite !root_factor_theorem in qz0 *. by apply: dvdp_trans qz0 (dvdp_trans _ Dq1z); rewrite dvdp_map. have map1q1z_z: root (map_poly \1%VF q1z) z. by rewrite map_poly_id => // ? _; rewrite lfunE. pose f0 := kHomExtend 1 \1 (inLz x) z. have{map1q1z_z} hom_f0 : kHom 1 <<1; inLz x>> f0. by apply: kHomExtendP map1q1z_z => //; apply: kHom1. have{} splitLpz: splittingFieldFor <<1; inLz x>> pz imL. have [r def_pz defLz] := splitLpz; exists r => //. apply/eqP; rewrite eqEsubv -{2}defLz adjoin_seqSl ?sub1v // andbT. apply/Fadjoin_seqP; split; last first. by rewrite /= -[limg _]defLz; apply: seqv_sub_adjoin. by apply/FadjoinP/andP; rewrite sub1v memv_img ?memvf. have [f homLzf Df] := kHom_extends (sub1v _) hom_f0 F0pz splitLpz. have [-> | x'z] := eqVneq (inLz x) z. by exists \1%VF; rewrite ?lfunE ?kHom1. exists f => //; rewrite -Df ?memv_adjoin ?(kHomExtend_val (kHom1 1 1)) //. by rewrite lfun1_poly. pose f1 := (inLz^-1 \o f \o inLz)%VF; have /kHomP_tmp[fFid fM] := homLf. have Df1 u: inLz (f1 u) = f (inLz u). rewrite !comp_lfunE limg_lfunVK //= -[limg _]/(asval imL). have [r def_pz defLz] := splitLpz; set r1 := r. have: inLz u \in <<1 & r1>>%VS by rewrite defLz. have: all [in r] r1 by apply/allP. elim/last_ind: r1 {u}(inLz u) => [|r1 y IHr1] u. by rewrite Fadjoin_nil => _ Fu; rewrite fFid // (subvP (sub1v _)). rewrite all_rcons adjoin_rcons => /andP[rr1 ry] /Fadjoin_polyP[pu r1pu ->]. rewrite (kHom_horner homLf) -defLz; last exact: seqv_sub_adjoin; last first. by apply: polyOverS r1pu; apply/subvP/adjoin_seqSr/allP. apply: rpred_horner. by apply/polyOverP=> i; rewrite coef_map /= defLz IHr1 ?(polyOverP r1pu). rewrite seqv_sub_adjoin // -root_prod_XsubC -(eqp_root def_pz). rewrite (kHom_root_id _ homLf) ?sub1v //. by rewrite -defLz seqv_sub_adjoin. by rewrite (eqp_root def_pz) root_prod_XsubC. suffices f1_is_ahom : ahom_in {:L} f1. apply/hasP; exists (AHom f1_is_ahom); first exact: DautL. by rewrite /fx_root -(fmorph_root inLz) /= Df1 fxz. apply/ahom_inP; split=> [a b _ _|]; apply: (fmorph_inj inLz). by rewrite rmorphM /= !Df1 rmorphM fM ?in_imL. by rewrite /= Df1 /= fFid ?rmorph1 ?mem1v. Qed. Lemma kHom_to_AEnd K E f : kHom K E f -> {g : 'AEnd(L) | {in E, f =1 val g}}. Proof. move=> homKf; have{homKf} [homFf sFE] := (kHomSl (sub1v K) homKf, sub1v E). have [p Fp /(splittingFieldForS sFE (subvf E))splitLp] := splittingPoly. have [g0 homLg0 eq_fg] := kHom_extends sFE homFf Fp splitLp. by apply: exist (Sub g0 _) _ => //; apply/ahomP_tmp/kHom_monoid_morphism. Qed. End SplittingFieldTheory. (* Hide the finGroup structure on 'AEnd(L) in a module so that we can control *) (* when it is exported. Most people will want to use the finGroup structure *) (* on 'Gal(E / K) and will not need this module. *) Module Import AEnd_FinGroup. Section AEnd_FinGroup. Variables (F : fieldType) (L : splittingFieldType F). Implicit Types (U V W : {vspace L}) (K M E : {subfield L}). Definition inAEnd f := SeqSub (svalP (enum_AEnd L) f). Fact inAEndK : cancel inAEnd val. Proof. by []. Qed. HB.instance Definition _ := Countable.copy 'AEnd(L) (can_type inAEndK). HB.instance Definition _ := isFinite.Build 'AEnd(L) (pcan_enumP (can_pcan inAEndK)). (* the group operation is the categorical composition operation *) Definition comp_AEnd (f g : 'AEnd(L)) : 'AEnd(L) := (g \o f)%AF. Fact comp_AEndA : associative comp_AEnd. Proof. by move=> f g h; apply: val_inj; symmetry; apply: comp_lfunA. Qed. Fact comp_AEnd1l : left_id \1%AF comp_AEnd. Proof. by move=> f; apply/val_inj/comp_lfun1r. Qed. Fact comp_AEndK : left_inverse \1%AF (@inv_ahom _ L) comp_AEnd. Proof. by move=> f; apply/val_inj; rewrite /= lker0_compfV ?AEnd_lker0. Qed. HB.instance Definition _:= isMulGroup.Build 'AEnd(L) comp_AEndA comp_AEnd1l comp_AEndK. Definition kAEnd U V := [set f : 'AEnd(L) | kAut U V f]. Definition kAEndf U := kAEnd U {:L}. Lemma kAEnd_group_set K E : group_set (kAEnd K E). Proof. apply/group_setP; split=> [|f g]; first by rewrite inE /kAut kHom1 lim1g eqxx. rewrite !inE !kAutE => /andP[homKf EfE] /andP[/(kHomSr EfE)homKg EgE]. by rewrite (comp_kHom_img homKg homKf) limg_comp (subv_trans _ EgE) ?limgS. Qed. Canonical kAEnd_group K E := group (kAEnd_group_set K E). Canonical kAEndf_group K := [group of kAEndf K]. Lemma kAEnd_norm K E : kAEnd K E \subset 'N(kAEndf E)%g. Proof. apply/subsetP=> x; rewrite -groupV 2!in_set => /andP[_ /eqP ExE]. apply/subsetP=> _ /imsetP[y homEy ->]; rewrite !in_set !kAutfE in homEy *. apply/kAHomP=> u Eu; have idEy := kAHomP homEy; rewrite -ExE in idEy. rewrite !(@lfunE _ _ L) /= (@lfunE _ _ L) /= idEy ?memv_img //. by rewrite lker0_lfunVK ?AEnd_lker0. Qed. Lemma mem_kAut_coset K E (g : 'AEnd(L)) : kAut K E g -> g \in coset (kAEndf E) g. Proof. move=> autEg; rewrite val_coset ?rcoset_refl //. by rewrite (subsetP (kAEnd_norm K E)) // inE. Qed. Lemma aut_mem_eqP E (x y : coset_of (kAEndf E)) f g : f \in x -> g \in y -> reflect {in E, f =1 g} (x == y). Proof. move=> x_f y_g; rewrite -(coset_mem x_f) -(coset_mem y_g). have [Nf Ng] := (subsetP (coset_norm x) f x_f, subsetP (coset_norm y) g y_g). rewrite (sameP eqP (rcoset_kercosetP Nf Ng)) mem_rcoset inE kAutfE. apply: (iffP kAHomP) => idEfg u Eu. by rewrite -(mulgKV g f) lfunE /= idEfg. by rewrite (@lfunE _ _ L) /= idEfg // lker0_lfunK ?AEnd_lker0. Qed. End AEnd_FinGroup. End AEnd_FinGroup. Section GaloisTheory. Variables (F : fieldType) (L : splittingFieldType F). Implicit Types (U V W : {vspace L}). Implicit Types (K M E : {subfield L}). (* We take Galois automorphisms for a subfield E to be automorphisms of the *) (* full field {:L} that operate in E taken modulo those that fix E pointwise. *) (* The type of Galois automorphisms of E is then the subtype of elements of *) (* the quotient kAEnd 1 E / kAEndf E, which we encapsulate in a specific *) (* wrapper to ensure stability of the gal_repr coercion insertion. *) Section gal_of_Definition. Variable V : {vspace L}. (* The <<_>>, which becomes redundant when V is a {subfield L}, ensures that *) (* the argument of [subg _] is syntactically a group. *) Inductive gal_of := Gal of [subg kAEnd_group 1 <<V>> / kAEndf (agenv V)]. Definition gal (f : 'AEnd(L)) := Gal (subg _ (coset _ f)). Definition gal_sgval x := let: Gal u := x in u. Fact gal_sgvalK : cancel gal_sgval Gal. Proof. by case. Qed. Let gal_sgval_inj := can_inj gal_sgvalK. HB.instance Definition _ := Countable.copy gal_of (can_type gal_sgvalK). HB.instance Definition _ := isFinite.Build gal_of (pcan_enumP (can_pcan gal_sgvalK)). Definition gal_one := Gal 1%g. Definition gal_inv x := Gal (gal_sgval x)^-1. Definition gal_mul x y := Gal (gal_sgval x * gal_sgval y). Fact gal_oneP : left_id gal_one gal_mul. Proof. by move=> x; apply/gal_sgval_inj/mul1g. Qed. Fact gal_invP : left_inverse gal_one gal_inv gal_mul. Proof. by move=> x; apply/gal_sgval_inj/mulVg. Qed. Fact gal_mulP : associative gal_mul. Proof. by move=> x y z; apply/gal_sgval_inj/mulgA. Qed. HB.instance Definition _ := isMulGroup.Build gal_of gal_mulP gal_oneP gal_invP. Coercion gal_repr u : 'AEnd(L) := repr (sgval (gal_sgval u)). Fact gal_is_morphism : {in kAEnd 1 (agenv V) &, {morph gal : x y / x * y}%g}. Proof. move=> f g /= autEa autEb; congr (Gal _). by rewrite !morphM ?mem_morphim // (subsetP (kAEnd_norm 1 _)). Qed. Canonical gal_morphism := Morphism gal_is_morphism. Lemma gal_reprK : cancel gal_repr gal. Proof. by case=> x; rewrite /gal coset_reprK sgvalK. Qed. Lemma gal_repr_inj : injective gal_repr. Proof. exact: can_inj gal_reprK. Qed. Lemma gal_AEnd x : gal_repr x \in kAEnd 1 (agenv V). Proof. rewrite /gal_repr; case/gal_sgval: x => _ /=/morphimP[g Ng autEg ->]. rewrite val_coset //=; case: repr_rcosetP => f; rewrite groupMr // !inE kAut1E. by rewrite kAutE -andbA => /and3P[_ /fixedSpace_limg-> _]. Qed. End gal_of_Definition. Prenex Implicits gal_repr. Lemma gal_eqP E {x y : gal_of E} : reflect {in E, x =1 y} (x == y). Proof. by rewrite -{1}(subfield_closed E); apply: aut_mem_eqP; apply: mem_repr_coset. Qed. Lemma galK E (f : 'AEnd(L)) : (f @: E <= E)%VS -> {in E, gal E f =1 f}. Proof. rewrite -kAut1E -{1 2}(subfield_closed E) => autEf. apply: (aut_mem_eqP (mem_repr_coset _) _ (eqxx _)). by rewrite subgK /= ?(mem_kAut_coset autEf) // ?mem_quotient ?inE. Qed. Lemma eq_galP E (f g : 'AEnd(L)) : (f @: E <= E)%VS -> (g @: E <= E)%VS -> reflect {in E, f =1 g} (gal E f == gal E g). Proof. move=> EfE EgE. by apply: (iffP gal_eqP) => Dfg a Ea; have:= Dfg a Ea; rewrite !{1}galK. Qed. Lemma limg_gal E (x : gal_of E) : (x @: E)%VS = E. Proof. by have:= gal_AEnd x; rewrite inE subfield_closed => /andP[_ /eqP]. Qed. Lemma memv_gal E (x : gal_of E) a : a \in E -> x a \in E. Proof. by move/(memv_img x); rewrite limg_gal. Qed. Lemma gal_id E a : (1 : gal_of E)%g a = a. Proof. by rewrite /gal_repr repr_coset1 id_lfunE. Qed. Lemma galM E (x y : gal_of E) a : a \in E -> (x * y)%g a = y (x a). Proof. rewrite /= -comp_lfunE; apply/eq_galP; rewrite ?limg_comp ?limg_gal //. by rewrite morphM /= ?gal_reprK ?gal_AEnd. Qed. Lemma galV E (x : gal_of E) : {in E, (x^-1)%g =1 x^-1%VF}. Proof. move=> a Ea; apply: canRL (lker0_lfunK (AEnd_lker0 _)) _. by rewrite -galM // mulVg gal_id. Qed. (* Standard mathematical notation for 'Gal(E / K) puts the larger field first.*) Definition galoisG V U := gal V @* <<kAEnd (U :&: V) V>>. Local Notation "''Gal' ( V / U )" := (galoisG V U) : group_scope. Canonical galoisG_group E U := Eval hnf in [group of (galoisG E U)]. Local Notation "''Gal' ( V / U )" := (galoisG_group V U) : Group_scope. Section Automorphism. Lemma gal_cap U V : 'Gal(V / U) = 'Gal(V / U :&: V). Proof. by rewrite /galoisG -capvA capvv. Qed. Lemma gal_kAut K E x : (K <= E)%VS -> (x \in 'Gal(E / K)) = kAut K E x. Proof. move=> sKE; apply/morphimP/idP=> /= [[g EgE KautEg ->{x}] | KautEx]. rewrite genGid !inE kAut1E /= subfield_closed (capv_idPl sKE) in KautEg EgE. by apply: etrans KautEg; apply/(kAut_eq sKE); apply: galK. exists (x : 'AEnd(L)); rewrite ?gal_reprK ?gal_AEnd //. by rewrite (capv_idPl sKE) mem_gen ?inE. Qed. Lemma gal_kHom K E x : (K <= E)%VS -> (x \in 'Gal(E / K)) = kHom K E x. Proof. by move/gal_kAut->; rewrite /kAut limg_gal eqxx andbT. Qed. Lemma kAut_to_gal K E f : kAut K E f -> {x : gal_of E | x \in 'Gal(E / K) & {in E, f =1 x}}. Proof. case/andP=> homKf EfE; have [g Df] := kHom_to_AEnd homKf. have{homKf EfE} autEg: kAut (K :&: E) E g. rewrite /kAut -(kHom_eq (capvSr _ _) Df) (kHomSl (capvSl _ _) homKf) /=. by rewrite -(eq_in_limg Df). have FautEg := kAutS (sub1v _) autEg. exists (gal E g) => [|a Ea]; last by rewrite {f}Df // galK // -kAut1E. by rewrite mem_morphim /= ?subfield_closed ?genGid ?inE. Qed. Lemma fixed_gal K E x a : (K <= E)%VS -> x \in 'Gal(E / K) -> a \in K -> x a = a. Proof. by move/gal_kHom=> -> /kAHomP idKx /idKx. Qed. Lemma fixedPoly_gal K E x p : (K <= E)%VS -> x \in 'Gal(E / K) -> p \is a polyOver K -> map_poly x p = p. Proof. move=> sKE galEKx /polyOverP Kp; apply/polyP => i. by rewrite coef_map /= (fixed_gal sKE). Qed. Lemma root_minPoly_gal K E x a : (K <= E)%VS -> x \in 'Gal(E / K) -> a \in E -> root (minPoly K a) (x a). Proof. move=> sKE galEKx Ea; have homKx: kHom K E x by rewrite -gal_kHom. have K_Pa := minPolyOver K a; rewrite -[minPoly K a](fixedPoly_gal _ galEKx) //. by rewrite (kHom_root homKx) ?root_minPoly // (polyOverS (subvP sKE)). Qed. End Automorphism. Lemma gal_adjoin_eq K a x y : x \in 'Gal(<<K; a>> / K) -> y \in 'Gal(<<K; a>> / K) -> (x == y) = (x a == y a). Proof. move=> galKa_x galKa_y; apply/idP/eqP=> [/eqP-> // | eq_xy_a]. apply/gal_eqP => _ /Fadjoin_polyP[p Kp ->]. by rewrite -!horner_map !(fixedPoly_gal (subv_adjoin K a)) //= eq_xy_a. Qed. Lemma galS K M E : (K <= M)%VS -> 'Gal(E / M) \subset 'Gal(E / K). Proof. rewrite gal_cap (gal_cap K E) => sKM; apply/subsetP=> x. by rewrite !gal_kAut ?capvSr //; apply: kAutS; apply: capvS. Qed. Lemma gal_conjg K E x : 'Gal(E / K) :^ x = 'Gal(E / x @: K). Proof. without loss sKE: K / (K <= E)%VS. move=> IH_K; rewrite gal_cap {}IH_K ?capvSr //. transitivity 'Gal(E / x @: K :&: x @: E); last by rewrite limg_gal -gal_cap. congr 'Gal(E / _); apply/eqP; rewrite eqEsubv limg_cap; apply/subvP=> a. rewrite memv_cap => /andP[/memv_imgP[b Kb ->] /memv_imgP[c Ec] eq_bc]. by rewrite memv_img // memv_cap Kb (lker0P (AEnd_lker0 _) _ _ eq_bc). wlog suffices IHx: x K sKE / 'Gal(E / K) :^ x \subset 'Gal(E / x @: K). apply/eqP; rewrite eqEsubset IHx // -sub_conjgV (subset_trans (IHx _ _ _)) //. by apply/subvP=> _ /memv_imgP[a Ka ->]; rewrite memv_gal ?(subvP sKE). rewrite -limg_comp (etrans (eq_in_limg _) (lim1g _)) // => a /(subvP sKE)Ka. by rewrite !(@lfunE _ _ L) /= -galM // mulgV gal_id. apply/subsetP=> _ /imsetP[y galEy ->]; rewrite gal_cap gal_kHom ?capvSr //=. apply/kAHomP=> _ /memv_capP[/memv_imgP[a Ka ->] _]; have Ea := subvP sKE a Ka. by rewrite -galM // -conjgC galM // (fixed_gal sKE galEy). Qed. Definition fixedField V (A : {set gal_of V}) := (V :&: \bigcap_(x in A) fixedSpace x)%VS. Lemma fixedFieldP E {A : {set gal_of E}} a : a \in E -> reflect (forall x, x \in A -> x a = a) (a \in fixedField A). Proof. by rewrite memv_cap => ->; apply: (iffP subv_bigcapP) => cAa x /cAa/fixedSpaceP. Qed. Lemma mem_fixedFieldP E (A : {set gal_of E}) a : a \in fixedField A -> a \in E /\ (forall x, x \in A -> x a = a). Proof. by move=> fixAa; have [Ea _] := memv_capP fixAa; have:= fixedFieldP Ea fixAa. Qed. Fact fixedField_is_aspace E (A : {set gal_of E}) : is_aspace (fixedField A). Proof. rewrite /fixedField; elim/big_rec: _ {1}E => [|x K _ IH_K] M. exact: (valP (M :&: _)%AS). by rewrite capvA IH_K. Qed. Canonical fixedField_aspace E A : {subfield L} := ASpace (@fixedField_is_aspace E A). Lemma fixedField_bound E (A : {set gal_of E}) : (fixedField A <= E)%VS. Proof. exact: capvSl. Qed. Lemma fixedFieldS E (A B : {set gal_of E}) : A \subset B -> (fixedField B <= fixedField A)%VS. Proof. move/subsetP=> sAB; apply/subvP => a /mem_fixedFieldP[Ea cBa]. by apply/fixedFieldP; last apply: sub_in1 cBa. Qed. Lemma galois_connection_subv K E : (K <= E)%VS -> (K <= fixedField ('Gal(E / K)))%VS. Proof. move=> sKE; apply/subvP => a Ka; have Ea := subvP sKE a Ka. by apply/fixedFieldP=> // x galEx; apply: (fixed_gal sKE). Qed. Lemma galois_connection_subset E (A : {set gal_of E}): A \subset 'Gal(E / fixedField A). Proof. apply/subsetP => x Ax; rewrite gal_kAut ?capvSl // kAutE limg_gal subvv andbT. by apply/kAHomP=> a /mem_fixedFieldP[_ ->]. Qed. Lemma galois_connection K E (A : {set gal_of E}): (K <= E)%VS -> (A \subset 'Gal(E / K)) = (K <= fixedField A)%VS. Proof. move=> sKE; apply/idP/idP => [/fixedFieldS | /(galS E)]. exact/subv_trans/galois_connection_subv. exact/subset_trans/galois_connection_subset. Qed. Definition galTrace U V a := \sum_(x in 'Gal(V / U)) (x a). Definition galNorm U V a := \prod_(x in 'Gal(V / U)) (x a). Section TraceAndNormMorphism. Variables U V : {vspace L}. Fact galTrace_is_zmod_morphism : zmod_morphism (galTrace U V). Proof. by move=> a b /=; rewrite -sumrB; apply: eq_bigr => x _; rewrite rmorphB. Qed. #[deprecated(since="mathcomp 2.5.0", note="use `galTrace_is_zmod_morphism` instead")] Definition galTrace_is_additive := galTrace_is_zmod_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build L L (galTrace U V) galTrace_is_zmod_morphism. Lemma galNorm1 : galNorm U V 1 = 1. Proof. by apply: big1 => x _; rewrite rmorph1. Qed. Lemma galNormM : {morph galNorm U V : a b / a * b}. Proof. by move=> a b /=; rewrite -big_split; apply: eq_bigr => x _; rewrite rmorphM. Qed. Lemma galNormV : {morph galNorm U V : a / a^-1}. Proof. by move=> a /=; rewrite -prodfV; apply: eq_bigr => x _; rewrite fmorphV. Qed. Lemma galNormX n : {morph galNorm U V : a / a ^+ n}. Proof. move=> a; elim: n => [|n IHn]; first exact: galNorm1. by rewrite !exprS galNormM IHn. Qed. Lemma galNorm_prod (I : Type) (r : seq I) (P : pred I) (B : I -> L) : galNorm U V (\prod_(i <- r | P i) B i) = \prod_(i <- r | P i) galNorm U V (B i). Proof. exact: (big_morph _ galNormM galNorm1). Qed. Lemma galNorm0 : galNorm U V 0 = 0. Proof. by rewrite /galNorm (bigD1 1%g) ?group1 // rmorph0 /= mul0r. Qed. Lemma galNorm_eq0 a : (galNorm U V a == 0) = (a == 0). Proof. apply/idP/eqP=> [/prodf_eq0[x _] | ->]; last by rewrite galNorm0. by rewrite fmorph_eq0 => /eqP. Qed. End TraceAndNormMorphism. Section TraceAndNormField. Variables K E : {subfield L}. Lemma galTrace_fixedField a : a \in E -> galTrace K E a \in fixedField 'Gal(E / K). Proof. move=> Ea; apply/fixedFieldP=> [|x galEx]. by apply: rpred_sum => x _; apply: memv_gal. rewrite {2}/galTrace (reindex_acts 'R _ galEx) ?astabsR //=. by rewrite rmorph_sum; apply: eq_bigr => y _; rewrite galM ?lfunE. Qed. Lemma galTrace_gal a x : a \in E -> x \in 'Gal(E / K) -> galTrace K E (x a) = galTrace K E a. Proof. move=> Ea galEx; rewrite {2}/galTrace (reindex_inj (mulgI x)). by apply: eq_big => [b | b _]; rewrite ?groupMl // galM ?lfunE. Qed. Lemma galNorm_fixedField a : a \in E -> galNorm K E a \in fixedField 'Gal(E / K). Proof. move=> Ea; apply/fixedFieldP=> [|x galEx]. by apply: rpred_prod => x _; apply: memv_gal. rewrite {2}/galNorm (reindex_acts 'R _ galEx) ?astabsR //=. by rewrite rmorph_prod; apply: eq_bigr => y _; rewrite galM ?lfunE. Qed. Lemma galNorm_gal a x : a \in E -> x \in 'Gal(E / K) -> galNorm K E (x a) = galNorm K E a. Proof. move=> Ea galEx; rewrite {2}/galNorm (reindex_inj (mulgI x)). by apply: eq_big => [b | b _]; rewrite ?groupMl // galM ?lfunE. Qed. End TraceAndNormField. Definition normalField U V := [forall x in kAEndf U, x @: V == V]%VS. Lemma normalField_kAut K M E f : (K <= M <= E)%VS -> normalField K M -> kAut K E f -> kAut K M f. Proof. case/andP=> sKM sME nKM /kAut_to_gal[x galEx /(sub_in1 (subvP sME))Df]. have sKE := subv_trans sKM sME; rewrite gal_kHom // in galEx. rewrite (kAut_eq sKM Df) /kAut (kHomSr sME) //= (forall_inP nKM) // inE. by rewrite kAutfE; apply/kAHomP; apply: (kAHomP galEx). Qed. Lemma normalFieldP K E : reflect {in E, forall a, exists2 r, all [in E] r & minPoly K a = \prod_(b <- r) ('X - b%:P)} (normalField K E). Proof. apply: (iffP eqfun_inP) => [nKE a Ea | nKE x]; last first. rewrite inE kAutfE => homKx; suffices: kAut K E x by case/andP=> _ /eqP. rewrite kAutE (kHomSr (subvf E)) //=; apply/subvP=> _ /memv_imgP[a Ea ->]. have [r /allP/=srE splitEa] := nKE a Ea. rewrite srE // -root_prod_XsubC -splitEa. by rewrite -(kHom_poly_id homKx (minPolyOver K a)) fmorph_root root_minPoly. have [r /eqP splitKa] := splitting_field_normal K a. exists r => //; apply/allP => b; rewrite -root_prod_XsubC -splitKa => pKa_b_0. pose y := kHomExtend K \1 a b; have [hom1K lf1p] := (kHom1 K K, lfun1_poly). have homKy: kHom K <<K; a>> y by apply/kHomExtendP; rewrite ?lf1p. have [[g Dy] [idKy _]] := (kHom_to_AEnd homKy, kHomP_tmp homKy). have <-: g a = b by rewrite -Dy ?memv_adjoin // (kHomExtend_val hom1K) ?lf1p. suffices /nKE <-: g \in kAEndf K by apply: memv_img. by rewrite inE kAutfE; apply/kAHomP=> c Kc; rewrite -Dy ?subvP_adjoin ?idKy. Qed. Lemma normalFieldf K : normalField K {:L}. Proof. apply/normalFieldP=> a _; have [r /eqP->] := splitting_field_normal K a. by exists r => //; apply/allP=> b; rewrite /= memvf. Qed. Lemma normalFieldS K M E : (K <= M)%VS -> normalField K E -> normalField M E. Proof. move=> sKM /normalFieldP nKE; apply/normalFieldP=> a Ea. have [r /allP Er splitKa] := nKE a Ea. have /dvdp_prod_XsubC[m splitMa]: minPoly M a %| \prod_(b <- r) ('X - b%:P). by rewrite -splitKa minPolyS. exists (mask m r); first by apply/allP=> b /mem_mask/Er. by apply/eqP; rewrite -eqp_monic ?monic_prod_XsubC ?monic_minPoly. Qed. Lemma splitting_normalField E K : (K <= E)%VS -> reflect (exists2 p, p \is a polyOver K & splittingFieldFor K p E) (normalField K E). Proof. move=> sKE; apply: (iffP idP) => [nKE| [p Kp [rs Dp defE]]]; last first. apply/forall_inP=> g /[!(inE, kAutE)] /andP[homKg _]. rewrite -dimv_leqif_eq ?limg_dim_eq ?(eqP (AEnd_lker0 g)) ?capv0 //. rewrite -defE aimg_adjoin_seq; have [_ /fixedSpace_limg->] := andP homKg. apply/adjoin_seqSr=> _ /mapP[a rs_a ->]. rewrite -!root_prod_XsubC -!(eqp_root Dp) in rs_a *. by apply: kHom_root_id homKg Kp _ rs_a; rewrite ?subvf ?memvf. pose splitK a r := minPoly K a = \prod_(b <- r) ('X - b%:P). have{nKE} rK_ a: {r | a \in E -> all [in E] r /\ splitK a r}. case Ea: (a \in E); last by exists [::]. by have /sig2_eqW[r] := normalFieldP _ _ nKE a Ea; exists r. have sXE := basis_mem (vbasisP E); set X : seq L := vbasis E in sXE. exists (\prod_(a <- X) minPoly K a). by apply: rpred_prod => a _; apply: minPolyOver. exists (flatten [seq (sval (rK_ a)) | a <- X]). move/allP: sXE; elim: X => [|a X IHX]; first by rewrite !big_nil eqpxx. rewrite big_cons /= big_cat /= => /andP[Ea sXE]. by case: (rK_ a) => /= r [] // _ <-; apply/eqp_mull/IHX. apply/eqP; rewrite eqEsubv; apply/andP; split. apply/Fadjoin_seqP; split=> // b /flatten_mapP[a /sXE Ea]. by apply/allP; case: rK_ => r /= []. rewrite -{1}(span_basis (vbasisP E)); apply/span_subvP=> a Xa. apply/seqv_sub_adjoin/flatten_mapP; exists a => //; rewrite -root_prod_XsubC. by case: rK_ => /= r [| _ <-]; rewrite ?sXE ?root_minPoly. Qed. Lemma kHom_to_gal K M E f : (K <= M <= E)%VS -> normalField K E -> kHom K M f -> {x | x \in 'Gal(E / K) & {in M, f =1 x}}. Proof. case/andP=> /subvP sKM /subvP sME nKE KhomMf. have [[g Df] [idKf _]] := (kHom_to_AEnd KhomMf, kHomP_tmp KhomMf). suffices /kAut_to_gal[x galEx Dg]: kAut K E g. by exists x => //= a Ma; rewrite Df // Dg ?sME. have homKg: kHom K {:L} g by apply/kAHomP=> a Ka; rewrite -Df ?sKM ?idKf. by rewrite /kAut (kHomSr (subvf _)) // (forall_inP nKE) // inE kAutfE. Qed. Lemma normalField_root_minPoly K E a b : (K <= E)%VS -> normalField K E -> a \in E -> root (minPoly K a) b -> exists2 x, x \in 'Gal(E / K) & x a = b. Proof. move=> sKE nKE Ea pKa_b_0; pose f := kHomExtend K \1 a b. have homKa_f: kHom K <<K; a>> f. by apply: kHomExtendP; rewrite ?kHom1 ?lfun1_poly. have sK_Ka_E: (K <= <<K; a>> <= E)%VS. by rewrite subv_adjoin; apply/FadjoinP; rewrite sKE Ea. have [x galEx Df] := kHom_to_gal sK_Ka_E nKE homKa_f; exists x => //. by rewrite -Df ?memv_adjoin // (kHomExtend_val (kHom1 K K)) ?lfun1_poly. Qed. Arguments normalFieldP {K E}. Lemma normalField_factors K E : (K <= E)%VS -> reflect {in E, forall a, exists2 r : seq (gal_of E), r \subset 'Gal(E / K) & minPoly K a = \prod_(x <- r) ('X - (x a)%:P)} (normalField K E). Proof. move=> sKE; apply: (iffP idP) => [nKE a Ea | nKE]; last first. apply/normalFieldP=> a Ea; have [r _ ->] := nKE a Ea. exists [seq x a | x : gal_of E <- r]; last by rewrite big_map. by rewrite all_map; apply/allP=> b _; apply: memv_gal. have [r Er splitKa] := normalFieldP nKE a Ea. pose f b := [pick x in 'Gal(E / K) | x a == b]. exists (pmap f r). apply/subsetP=> x; rewrite mem_pmap /f => /mapP[b _]. by case: (pickP _) => // c /andP[galEc _] [->]. rewrite splitKa; have{splitKa}: all (root (minPoly K a)) r. by apply/allP => b; rewrite splitKa root_prod_XsubC. elim: r Er => /= [|b r IHr]; first by rewrite !big_nil. case/andP=> Eb Er /andP[pKa_b_0 /(IHr Er){Er}IHr]. have [x galE /eqP xa_b] := normalField_root_minPoly sKE nKE Ea pKa_b_0. rewrite /(f b); case: (pickP _) => [y /andP[_ /eqP<-]|/(_ x)/andP[]//]. by rewrite !big_cons IHr. Qed. Definition galois U V := [&& (U <= V)%VS, separable U V & normalField U V]. Lemma galoisS K M E : (K <= M <= E)%VS -> galois K E -> galois M E. Proof. case/andP=> sKM sME /and3P[_ sepUV nUV]. by rewrite /galois sME (separableSl sKM) ?(normalFieldS sKM). Qed. Lemma galois_dim K E : galois K E -> \dim_K E = #|'Gal(E / K)|. Proof. case/and3P=> sKE /eq_adjoin_separable_generator-> // nKE. set a := separable_generator K E in nKE *. have [r /allP/=Er splitKa] := normalFieldP nKE a (memv_adjoin K a). rewrite (dim_sup_field (subv_adjoin K a)) mulnK ?adim_gt0 //. apply/eqP; rewrite -eqSS -adjoin_degreeE -size_minPoly splitKa size_prod_XsubC. set n := size r; rewrite eqSS -[n]card_ord. have x_ (i : 'I_n): {x | x \in 'Gal(<<K; a>> / K) & x a = r`_i}. apply/sig2_eqW/normalField_root_minPoly; rewrite ?subv_adjoin ?memv_adjoin //. by rewrite splitKa root_prod_XsubC mem_nth. have /card_image <-: injective (fun i => s2val (x_ i)). move=> i j /eqP; case: (x_ i) (x_ j) => y /= galEy Dya [z /= galEx Dza]. rewrite gal_adjoin_eq // Dya Dza nth_uniq // => [/(i =P j)//|]. by rewrite -separable_prod_XsubC -splitKa; apply: separable_generatorP. apply/eqP/eq_card=> x; apply/codomP/idP=> [[i ->] | galEx]; first by case: x_. have /(nthP 0) [i ltin Dxa]: x a \in r. rewrite -root_prod_XsubC -splitKa. by rewrite root_minPoly_gal ?memv_adjoin ?subv_adjoin. exists (Ordinal ltin); apply/esym/eqP. by case: x_ => y /= galEy /eqP; rewrite Dxa gal_adjoin_eq. Qed. Lemma galois_factors K E : (K <= E)%VS -> reflect {in E, forall a, exists r, let r_a := [seq x a | x : gal_of E <- r] in [/\ r \subset 'Gal(E / K), uniq r_a & minPoly K a = \prod_(b <- r_a) ('X - b%:P)]} (galois K E). Proof. move=> sKE; apply: (iffP and3P) => [[_ sepKE nKE] a Ea | galKE]. have [r galEr splitEa] := normalField_factors sKE nKE a Ea. exists r; rewrite /= -separable_prod_XsubC !big_map -splitEa. by split=> //; apply: separableP Ea. split=> //. apply/separableP => a /galKE[r [_ Ur_a splitKa]]. by rewrite /separable_element splitKa separable_prod_XsubC. apply/(normalField_factors sKE)=> a /galKE[r [galEr _ ->]]. by rewrite big_map; exists r. Qed. Lemma splitting_galoisField K E : reflect (exists p, [/\ p \is a polyOver K, separable_poly p & splittingFieldFor K p E]) (galois K E). Proof. apply: (iffP and3P) => [[sKE sepKE nKE]|[p [Kp sep_p [r Dp defE]]]]. rewrite (eq_adjoin_separable_generator sepKE) // in nKE *. set a := separable_generator K E in nKE *; exists (minPoly K a). split; first 1 [exact: minPolyOver | exact/separable_generatorP]. have [r /= /allP Er splitKa] := normalFieldP nKE a (memv_adjoin _ _). exists r; first by rewrite splitKa eqpxx. apply/eqP; rewrite eqEsubv; apply/andP; split. by apply/Fadjoin_seqP; split => //; apply: subv_adjoin. apply/FadjoinP; split; first exact: subv_adjoin_seq. by rewrite seqv_sub_adjoin // -root_prod_XsubC -splitKa root_minPoly. have sKE: (K <= E)%VS by rewrite -defE subv_adjoin_seq. split=> //; last by apply/splitting_normalField=> //; exists p; last exists r. rewrite -defE; apply/separable_Fadjoin_seq/allP=> a r_a. by apply/separable_elementP; exists p; rewrite (eqp_root Dp) root_prod_XsubC. Qed. Lemma galois_fixedField K E : reflect (fixedField 'Gal(E / K) = K) (galois K E). Proof. apply: (iffP idP) => [/and3P[sKE /separableP sepKE nKE] | fixedKE]. apply/eqP; rewrite eqEsubv galois_connection_subv ?andbT //. apply/subvP=> a /mem_fixedFieldP[Ea fixEa]; rewrite -adjoin_deg_eq1. have [r /allP Er splitKa] := normalFieldP nKE a Ea. rewrite -eqSS -size_minPoly splitKa size_prod_XsubC eqSS -[1]/(size [:: a]). have Ur: uniq r by rewrite -separable_prod_XsubC -splitKa; apply: sepKE. rewrite -uniq_size_uniq {Ur}// => b; rewrite inE -root_prod_XsubC -splitKa. apply/eqP/idP=> [-> | pKa_b_0]; first exact: root_minPoly. by have [x /fixEa-> ->] := normalField_root_minPoly sKE nKE Ea pKa_b_0. have sKE: (K <= E)%VS by rewrite -fixedKE capvSl. apply/galois_factors=> // a Ea. pose r_pKa := [seq x a | x : gal_of E in 'Gal(E / K)]. have /fin_all_exists2[x_ galEx_ Dx_a] (b : seq_sub r_pKa) := imageP (valP b). exists (codom x_); rewrite -map_comp; set r := map _ _. have r_xa x: x \in 'Gal(E / K) -> x a \in r. move=> galEx; have r_pKa_xa: x a \in r_pKa by apply/imageP; exists x. by rewrite [x a](Dx_a (SeqSub r_pKa_xa)); apply: codom_f. have Ur: uniq r by apply/injectiveP=> b c /=; rewrite -!Dx_a => /val_inj. split=> //; first by apply/subsetP=> _ /codomP[b ->]. apply/eqP; rewrite -eqp_monic ?monic_minPoly ?monic_prod_XsubC //. apply/andP; split; last first. rewrite uniq_roots_dvdp ?uniq_rootsE // all_map. by apply/allP=> b _ /=; rewrite root_minPoly_gal. apply: minPoly_dvdp; last by rewrite root_prod_XsubC -(gal_id E a) r_xa ?group1. rewrite -fixedKE; apply/polyOverP => i; apply/fixedFieldP=> [|x galEx]. rewrite (polyOverP _) // big_map rpred_prod // => b _. by rewrite polyOverXsubC memv_gal. rewrite -coef_map rmorph_prod; congr (_ : {poly _})`_i. symmetry; rewrite (perm_big (map x r)) /= ?(big_map x). by apply: eq_bigr => b _; rewrite rmorphB /= map_polyX map_polyC. have Uxr: uniq (map x r) by rewrite map_inj_uniq //; apply: fmorph_inj. have /uniq_min_size: {subset map x r <= r}. by rewrite -map_comp => _ /codomP[b ->] /=; rewrite -galM // r_xa ?groupM. by rewrite (size_map x) perm_sym; case=> // _ /uniq_perm->. Qed. Lemma mem_galTrace K E a : galois K E -> a \in E -> galTrace K E a \in K. Proof. by move/galois_fixedField => {2}<- /galTrace_fixedField. Qed. Lemma mem_galNorm K E a : galois K E -> a \in E -> galNorm K E a \in K. Proof. by move/galois_fixedField=> {2}<- /galNorm_fixedField. Qed. Lemma gal_independent_contra E (P : pred (gal_of E)) (c_ : gal_of E -> L) x : P x -> c_ x != 0 -> exists2 a, a \in E & \sum_(y | P y) c_ y * y a != 0. Proof. have [n] := ubnP #|P|; elim: n c_ x P => // n IHn c_ x P lePn Px nz_cx. rewrite ltnS (cardD1x Px) in lePn; move/IHn: lePn => {n IHn}/=IH_P. have [/eqfun_inP c_Px'_0 | ] := boolP [forall (y | P y && (y != x)), c_ y == 0]. exists 1; rewrite ?mem1v // (bigD1 x Px) /= rmorph1 mulr1. by rewrite big1 ?addr0 // => y /c_Px'_0->; rewrite mul0r. case/forall_inPn => y Px'y nz_cy. have [Py /gal_eqP/eqlfun_inP/subvPn[a Ea]] := andP Px'y. rewrite memv_ker !lfun_simp => nz_yxa; pose d_ y := c_ y * (y a - x a). have /IH_P[//|b Eb nz_sumb]: d_ y != 0 by rewrite mulf_neq0. have [sumb_0|] := eqVneq (\sum_(z | P z) c_ z * z b) 0; last by exists b. exists (a * b); first exact: rpredM. rewrite -subr_eq0 -[z in _ - z](mulr0 (x a)) -[in z in _ - z]sumb_0. rewrite mulr_sumr -sumrB (bigD1 x Px) rmorphM /= mulrCA subrr add0r. congr (_ != 0): nz_sumb; apply: eq_bigr => z _. by rewrite mulrCA rmorphM -mulrBr -mulrBl mulrA. Qed. Lemma gal_independent E (P : pred (gal_of E)) (c_ : gal_of E -> L) : (forall a, a \in E -> \sum_(x | P x) c_ x * x a = 0) -> (forall x, P x -> c_ x = 0). Proof. move=> sum_cP_0 x Px; apply/eqP/idPn=> /(gal_independent_contra Px)[a Ea]. by rewrite sum_cP_0 ?eqxx. Qed. Lemma Hilbert's_theorem_90 K E x a : generator 'Gal(E / K) x -> a \in E -> reflect (exists2 b, b \in E /\ b != 0 & a = b / x b) (galNorm K E a == 1). Proof. move/(_ =P <[x]>)=> DgalE Ea. have galEx: x \in 'Gal(E / K) by rewrite DgalE cycle_id. apply: (iffP eqP) => [normEa1 | [b [Eb nzb] ->]]; last first. by rewrite galNormM galNormV galNorm_gal // mulfV // galNorm_eq0. have [x1 | ntx] := eqVneq x 1%g. exists 1; first by rewrite mem1v oner_neq0. by rewrite -{1}normEa1 /galNorm DgalE x1 cycle1 big_set1 !gal_id divr1. pose c_ y := \prod_(i < invm (injm_Zpm x) y) (x ^+ i)%g a. have nz_c1: c_ 1%g != 0 by rewrite /c_ morph1 big_ord0 oner_neq0. have [d] := @gal_independent_contra _ [in 'Gal(E / K)] _ _ (group1 _) nz_c1. set b := \sum_(y in _) _ => Ed nz_b; exists b. split=> //; apply: rpred_sum => y galEy. by apply: rpredM; first apply: rpred_prod => i _; apply: memv_gal. apply: canRL (mulfK _) _; first by rewrite fmorph_eq0. rewrite rmorph_sum mulr_sumr [b](reindex_acts 'R _ galEx) ?astabsR //=. apply: eq_bigr => y galEy; rewrite galM // rmorphM mulrA; congr (_ * _). have /morphimP[/= i _ _ ->] /=: y \in Zpm @* Zp #[x] by rewrite im_Zpm -DgalE. have <-: Zpm (i + 1) = (Zpm i * x)%g by rewrite morphM ?mem_Zp ?order_gt1. rewrite /c_ !invmE ?mem_Zp ?order_gt1 //= addn1; set n := _.+2. transitivity (\prod_(j < i.+1) (x ^+ j)%g a). rewrite big_ord_recl gal_id rmorph_prod; congr (_ * _). by apply: eq_bigr => j _; rewrite expgSr galM ?lfunE. have [/modn_small->//||->] := ltngtP i.+1 n; first by rewrite ltnNge ltn_ord. rewrite modnn big_ord0; apply: etrans normEa1; rewrite /galNorm DgalE -im_Zpm. rewrite morphimEdom big_imset /=; last exact/injmP/injm_Zpm. by apply: eq_bigl => j /=; rewrite mem_Zp ?order_gt1. Qed. Section Matrix. Variable (E : {subfield L}) (A : {set gal_of E}). Let K := fixedField A. Lemma gal_matrix : {w : #|A|.-tuple L | {subset w <= E} /\ 0 \notin w & [/\ \matrix_(i, j < #|A|) enum_val i (tnth w j) \in unitmx, directv (\sum_i K * <[tnth w i]>) & group_set A -> (\sum_i K * <[tnth w i]>)%VS = E] }. Proof. pose nzE (w : #|A|.-tuple L) := {subset w <= E} /\ 0 \notin w. pose M w := \matrix_(i, j < #|A|) nth 1%g (enum A) i (tnth w j). have [w [Ew nzw] uM]: {w : #|A|.-tuple L | nzE w & M w \in unitmx}. rewrite {}/nzE {}/M cardE; have: uniq (enum A) := enum_uniq _. elim: (enum A) => [|x s IHs] Uxs. by exists [tuple]; rewrite // flatmx0 -(flatmx0 1%:M) unitmx1. have [s'x Us]: x \notin s /\ uniq s by apply/andP. have{IHs} [w [Ew nzw] uM] := IHs Us; set M := \matrix_(i, j) _ in uM. pose a := \row_i x (tnth w i) *m invmx M. pose c_ y := oapp (a 0) (-1) (insub (index y s)). have cx_n1 : c_ x = -1 by rewrite /c_ insubN ?index_mem. have nz_cx : c_ x != 0 by rewrite cx_n1 oppr_eq0 oner_neq0. have Px: [pred y in x :: s] x := mem_head x s. have{Px nz_cx} /sig2W[w0 Ew0 nzS] := gal_independent_contra Px nz_cx. exists [tuple of cons w0 w]. split; first by apply/allP; rewrite /= Ew0; apply/allP. rewrite inE negb_or (contraNneq _ nzS) // => <-. by rewrite big1 // => y _; rewrite rmorph0 mulr0. rewrite unitmxE -[\det _]mul1r; set M1 := \matrix_(i, j < 1 + size s) _. have <-: \det (block_mx 1 (- a) 0 1%:M) = 1 by rewrite det_ublock !det1 mulr1. rewrite -det_mulmx -[M1]submxK mulmx_block !mul0mx !mul1mx !add0r !mulNmx. have ->: drsubmx M1 = M by apply/matrixP => i j; rewrite !mxE !(tnth_nth 0). have ->: ursubmx M1 - a *m M = 0. by apply/rowP=> i; rewrite mulmxKV // !mxE !(tnth_nth 0) subrr. rewrite det_lblock unitrM andbC -(unitmxE M) uM unitfE -oppr_eq0. congr (_ != 0): nzS; rewrite [_ - _]mx11_scalar det_scalar !mxE opprB /=. rewrite -big_uniq // big_cons /= cx_n1 mulN1r addrC; congr (_ + _). rewrite (big_nth 1%g) big_mkord; apply: eq_bigr => j _. by rewrite /c_ index_uniq // valK; congr (_ * _); rewrite !mxE. exists w => [//|]; split=> [||gA]. - by congr (_ \in unitmx): uM; apply/matrixP=> i j; rewrite !mxE -enum_val_nth. - apply/directv_sum_independent=> kw_ Kw_kw sum_kw_0 j _. have /fin_all_exists2[k_ Kk_ Dk_] i := memv_cosetP (Kw_kw i isT). pose kv := \col_i k_ i. transitivity (kv j 0 * tnth w j); first by rewrite !mxE. suffices{j}/(canRL (mulKmx uM))->: M w *m kv = 0 by rewrite mulmx0 mxE mul0r. apply/colP=> i /[!mxE]; pose Ai := nth 1%g (enum A) i. transitivity (Ai (\sum_j kw_ j)); last by rewrite sum_kw_0 rmorph0. rewrite rmorph_sum; apply: eq_bigr => j _; rewrite !mxE /= -/Ai. rewrite Dk_ mulrC rmorphM /=; congr (_ * _). by have /mem_fixedFieldP[_ -> //] := Kk_ j; rewrite -mem_enum mem_nth -?cardE. pose G := group gA; have G_1 := group1 G; pose iG := enum_rank_in G_1. apply/eqP; rewrite eqEsubv; apply/andP; split. apply/subv_sumP=> i _; apply: subv_trans (asubv _). by rewrite prodvS ?capvSl // -memvE Ew ?mem_tnth. apply/subvP=> w0 Ew0; apply/memv_sumP. pose wv := \col_(i < #|A|) enum_val i w0; pose v := invmx (M w) *m wv. exists (fun i => tnth w i * v i 0) => [i _|]; last first. transitivity (wv (iG 1%g) 0); first by rewrite mxE enum_rankK_in ?gal_id. rewrite -[wv](mulKVmx uM) -/v mxE; apply: eq_bigr => i _. by congr (_ * _); rewrite !mxE -enum_val_nth enum_rankK_in ?gal_id. rewrite mulrC memv_mul ?memv_line //; apply/fixedFieldP=> [|x Gx]. rewrite mxE rpred_sum // => j _; rewrite !mxE rpredM //; last exact: memv_gal. have E_M k l: M w k l \in E by rewrite mxE memv_gal // Ew ?mem_tnth. have Edet n (N : 'M_n) (E_N : forall i j, N i j \in E): \det N \in E. by apply: rpred_sum => sigma _; rewrite rpredMsign rpred_prod. rewrite /invmx uM 2!mxE mulrC rpred_div ?Edet //. by rewrite rpredMsign Edet // => k l; rewrite 2!mxE. suffices{i} {2}<-: map_mx x v = v by rewrite [map_mx x v i 0]mxE. have uMx: map_mx x (M w) \in unitmx by rewrite map_unitmx. rewrite map_mxM map_invmx /=; apply: canLR {uMx}(mulKmx uMx) _. apply/colP=> i /[!mxE]; pose ix := iG (enum_val i * x)%g. have Dix b: b \in E -> enum_val ix b = x (enum_val i b). by move=> Eb; rewrite enum_rankK_in ?groupM ?enum_valP // galM ?lfunE. transitivity ((M w *m v) ix 0); first by rewrite mulKVmx // mxE Dix. rewrite mxE; apply: eq_bigr => j _; congr (_ * _). by rewrite !mxE -!enum_val_nth Dix // ?Ew ?mem_tnth. Qed. End Matrix. Lemma dim_fixedField E (G : {group gal_of E}) : #|G| = \dim_(fixedField G) E. Proof. have [w [_ nzw] [_ Edirect /(_ (groupP G))defE]] := gal_matrix G. set n := #|G|; set m := \dim (fixedField G); rewrite -defE (directvP Edirect). rewrite -[n]card_ord -(@mulnK #|'I_n| m) ?adim_gt0 //= -sum_nat_const. congr (_ %/ _)%N; apply: eq_bigr => i _. by rewrite dim_cosetv ?(memPn nzw) ?mem_tnth. Qed. Lemma dim_fixed_galois K E (G : {group gal_of E}) : galois K E -> G \subset 'Gal(E / K) -> \dim_K (fixedField G) = #|'Gal(E / K) : G|. Proof. move=> galE sGgal; have [sFE _ _] := and3P galE; apply/eqP. rewrite -divgS // eqn_div ?cardSg // dim_fixedField -galois_dim //. by rewrite mulnC muln_divA ?divnK ?field_dimS ?capvSl -?galois_connection. Qed. Lemma gal_fixedField E (G : {group gal_of E}): 'Gal(E / fixedField G) = G. Proof. apply/esym/eqP; rewrite eqEcard galois_connection_subset /= (dim_fixedField G). rewrite galois_dim //; apply/galois_fixedField/eqP. rewrite eqEsubv galois_connection_subv ?capvSl //. by rewrite fixedFieldS ?galois_connection_subset. Qed. Lemma gal_generated E (A : {set gal_of E}) : 'Gal(E / fixedField A) = <<A>>. Proof. apply/eqP; rewrite eqEsubset gen_subG galois_connection_subset. by rewrite -[<<A>>]gal_fixedField galS // fixedFieldS // subset_gen. Qed. Lemma fixedField_galois E (A : {set gal_of E}): galois (fixedField A) E. Proof. have: galois (fixedField <<A>>) E. by apply/galois_fixedField; rewrite gal_fixedField. by apply: galoisS; rewrite capvSl fixedFieldS // subset_gen. Qed. Section FundamentalTheoremOfGaloisTheory. Variables E K : {subfield L}. Hypothesis galKE : galois K E. Section IntermediateField. Variable M : {subfield L}. Hypothesis (sKME : (K <= M <= E)%VS) (nKM : normalField K M). Lemma normalField_galois : galois K M. Proof. have [[sKM sME] [_ sepKE nKE]] := (andP sKME, and3P galKE). by rewrite /galois sKM (separableSr sME). Qed. Definition normalField_cast (x : gal_of E) : gal_of M := gal M x. Lemma normalField_cast_eq x : x \in 'Gal(E / K) -> {in M, normalField_cast x =1 x}. Proof. have [sKM sME] := andP sKME; have sKE := subv_trans sKM sME. rewrite gal_kAut // => /(normalField_kAut sKME nKM). by rewrite kAutE => /andP[_ /galK]. Qed. Lemma normalField_castM : {in 'Gal(E / K) &, {morph normalField_cast : x y / (x * y)%g}}. Proof. move=> x y galEx galEy /=; apply/eqP/gal_eqP => a Ma. have Ea: a \in E by have [_ /subvP->] := andP sKME. rewrite normalField_cast_eq ?groupM ?galM //=. by rewrite normalField_cast_eq ?memv_gal // normalField_cast_eq. Qed. Canonical normalField_cast_morphism := Morphism normalField_castM. Lemma normalField_ker : 'ker normalField_cast = 'Gal(E / M). Proof. have [sKM sME] := andP sKME. apply/setP=> x; apply/idP/idP=> [kerMx | galEMx]. rewrite gal_kHom //; apply/kAHomP=> a Ma. by rewrite -normalField_cast_eq ?(dom_ker kerMx) // (mker kerMx) gal_id. have galEM: x \in 'Gal(E / K) := subsetP (galS E sKM) x galEMx. apply/kerP=> //; apply/eqP/gal_eqP=> a Ma. by rewrite normalField_cast_eq // gal_id (fixed_gal sME). Qed. Lemma normalField_normal : 'Gal(E / M) <| 'Gal(E / K). Proof. by rewrite -normalField_ker ker_normal. Qed. Lemma normalField_img : normalField_cast @* 'Gal(E / K) = 'Gal(M / K). Proof. have [[sKM sME] [sKE _ nKE]] := (andP sKME, and3P galKE). apply/setP=> x; apply/idP/idP=> [/morphimP[{}x galEx _ ->] | galMx]. rewrite gal_kHom //; apply/kAHomP=> a Ka; have Ma := subvP sKM a Ka. by rewrite normalField_cast_eq // (fixed_gal sKE). have /(kHom_to_gal sKME nKE)[y galEy eq_xy]: kHom K M x by rewrite -gal_kHom. apply/morphimP; exists y => //; apply/eqP/gal_eqP => a Ha. by rewrite normalField_cast_eq // eq_xy. Qed. Lemma normalField_isom : {f : {morphism ('Gal(E / K) / 'Gal(E / M)) >-> gal_of M} | isom ('Gal(E / K) / 'Gal (E / M)) 'Gal(M / K) f & (forall A, f @* (A / 'Gal(E / M)) = normalField_cast @* A) /\ {in 'Gal(E / K) & M, forall x, f (coset 'Gal (E / M) x) =1 x} }%g. Proof. have:= first_isom normalField_cast_morphism; rewrite normalField_ker. case=> f injf Df; exists f; first by apply/isomP; rewrite Df normalField_img. split=> [//|x a galEx /normalField_cast_eq<- //]; congr ((_ : gal_of M) a). apply: set1_inj; rewrite -!morphim_set1 ?mem_quotient ?Df //. by rewrite (subsetP (normal_norm normalField_normal)). Qed. Lemma normalField_isog : 'Gal(E / K) / 'Gal(E / M) \isog 'Gal(M / K). Proof. by rewrite -normalField_ker -normalField_img first_isog. Qed. End IntermediateField. Section IntermediateGroup. Variable G : {group gal_of E}. Hypothesis nsGgalE : G <| 'Gal(E / K). Lemma normal_fixedField_galois : galois K (fixedField G). Proof. have [[sKE sepKE nKE] [sGgal nGgal]] := (and3P galKE, andP nsGgalE). rewrite /galois -(galois_connection _ sKE) sGgal. rewrite (separableSr _ sepKE) ?capvSl //; apply/forall_inP=> f autKf. rewrite eqEdim limg_dim_eq ?(eqP (AEnd_lker0 _)) ?capv0 // leqnn andbT. apply/subvP => _ /memv_imgP[a /mem_fixedFieldP[Ea cGa] ->]. have /kAut_to_gal[x galEx -> //]: kAut K E f. rewrite /kAut (forall_inP nKE) // andbT; apply/kAHomP. by move: autKf; rewrite inE kAutfE => /kHomP_tmp[]. apply/fixedFieldP=> [|y Gy]; first exact: memv_gal. by rewrite -galM // conjgCV galM //= cGa // memJ_norm ?groupV ?(subsetP nGgal). Qed. End IntermediateGroup. End FundamentalTheoremOfGaloisTheory. End GaloisTheory. Prenex Implicits gal_repr gal gal_reprK. Arguments gal_repr_inj {F L V} [x1 x2]. Notation "''Gal' ( V / U )" := (galoisG V U) : group_scope. Notation "''Gal' ( V / U )" := (galoisG_group V U) : Group_scope. Arguments fixedFieldP {F L E A a}. Arguments normalFieldP {F L K E}. Arguments splitting_galoisField {F L K E}. Arguments galois_fixedField {F L K E}.
Basic.lean
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Johan Commelin, Andrew Yang, Joël Riou -/ import Mathlib.Algebra.Group.Basic import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero import Mathlib.CategoryTheory.Monoidal.End import Mathlib.CategoryTheory.Monoidal.Discrete /-! # Shift A `Shift` on a category `C` indexed by a monoid `A` is nothing more than a monoidal functor from `A` to `C ⥤ C`. A typical example to keep in mind might be the category of complexes `⋯ → C_{n-1} → C_n → C_{n+1} → ⋯`. It has a shift indexed by `ℤ`, where we assign to each `n : ℤ` the functor `C ⥤ C` that re-indexes the terms, so the degree `i` term of `Shift n C` would be the degree `i+n`-th term of `C`. ## Main definitions * `HasShift`: A typeclass asserting the existence of a shift functor. * `shiftEquiv`: When the indexing monoid is a group, then the functor indexed by `n` and `-n` forms a self-equivalence of `C`. * `shiftComm`: When the indexing monoid is commutative, then shifts commute as well. ## Implementation Notes `[HasShift C A]` is implemented using monoidal functors from `Discrete A` to `C ⥤ C`. However, the API of monoidal functors is used only internally: one should use the API of shifts functors which includes `shiftFunctor C a : C ⥤ C` for `a : A`, `shiftFunctorZero C A : shiftFunctor C (0 : A) ≅ 𝟭 C` and `shiftFunctorAdd C i j : shiftFunctor C (i + j) ≅ shiftFunctor C i ⋙ shiftFunctor C j` (and its variant `shiftFunctorAdd'`). These isomorphisms satisfy some coherence properties which are stated in lemmas like `shiftFunctorAdd'_assoc`, `shiftFunctorAdd'_zero_add` and `shiftFunctorAdd'_add_zero`. -/ namespace CategoryTheory open Functor noncomputable section universe v u variable (C : Type u) (A : Type*) [Category.{v} C] attribute [local instance] endofunctorMonoidalCategory variable {A C} section Defs variable (A C) [AddMonoid A] /-- A category has a shift indexed by an additive monoid `A` if there is a monoidal functor from `A` to `C ⥤ C`. -/ class HasShift (C : Type u) (A : Type*) [Category.{v} C] [AddMonoid A] where /-- a shift is a monoidal functor from `A` to `C ⥤ C` -/ shift : Discrete A ⥤ C ⥤ C /-- `shift` is monoidal -/ shiftMonoidal : shift.Monoidal := by infer_instance /-- A helper structure to construct the shift functor `(Discrete A) ⥤ (C ⥤ C)`. -/ structure ShiftMkCore where /-- the family of shift functors -/ F : A → C ⥤ C /-- the shift by 0 identifies to the identity functor -/ zero : F 0 ≅ 𝟭 C /-- the composition of shift functors identifies to the shift by the sum -/ add : ∀ n m : A, F (n + m) ≅ F n ⋙ F m /-- compatibility with the associativity -/ assoc_hom_app : ∀ (m₁ m₂ m₃ : A) (X : C), (add (m₁ + m₂) m₃).hom.app X ≫ (F m₃).map ((add m₁ m₂).hom.app X) = eqToHom (by rw [add_assoc]) ≫ (add m₁ (m₂ + m₃)).hom.app X ≫ (add m₂ m₃).hom.app ((F m₁).obj X) := by cat_disch /-- compatibility with the left addition with 0 -/ zero_add_hom_app : ∀ (n : A) (X : C), (add 0 n).hom.app X = eqToHom (by dsimp; rw [zero_add]) ≫ (F n).map (zero.inv.app X) := by cat_disch /-- compatibility with the right addition with 0 -/ add_zero_hom_app : ∀ (n : A) (X : C), (add n 0).hom.app X = eqToHom (by dsimp; rw [add_zero]) ≫ zero.inv.app ((F n).obj X) := by cat_disch namespace ShiftMkCore variable {C A} attribute [reassoc] assoc_hom_app @[reassoc] lemma assoc_inv_app (h : ShiftMkCore C A) (m₁ m₂ m₃ : A) (X : C) : (h.F m₃).map ((h.add m₁ m₂).inv.app X) ≫ (h.add (m₁ + m₂) m₃).inv.app X = (h.add m₂ m₃).inv.app ((h.F m₁).obj X) ≫ (h.add m₁ (m₂ + m₃)).inv.app X ≫ eqToHom (by rw [add_assoc]) := by rw [← cancel_mono ((h.add (m₁ + m₂) m₃).hom.app X ≫ (h.F m₃).map ((h.add m₁ m₂).hom.app X)), Category.assoc, Category.assoc, Category.assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id, h.assoc_hom_app, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app] rfl lemma zero_add_inv_app (h : ShiftMkCore C A) (n : A) (X : C) : (h.add 0 n).inv.app X = (h.F n).map (h.zero.hom.app X) ≫ eqToHom (by dsimp; rw [zero_add]) := by rw [← cancel_epi ((h.add 0 n).hom.app X), Iso.hom_inv_id_app, h.zero_add_hom_app, Category.assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, Functor.map_id, Category.id_comp, eqToHom_trans, eqToHom_refl] lemma add_zero_inv_app (h : ShiftMkCore C A) (n : A) (X : C) : (h.add n 0).inv.app X = h.zero.hom.app ((h.F n).obj X) ≫ eqToHom (by dsimp; rw [add_zero]) := by rw [← cancel_epi ((h.add n 0).hom.app X), Iso.hom_inv_id_app, h.add_zero_hom_app, Category.assoc, Iso.inv_hom_id_app_assoc, eqToHom_trans, eqToHom_refl] end ShiftMkCore section attribute [local simp] eqToHom_map instance (h : ShiftMkCore C A) : (Discrete.functor h.F).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := h.zero.symm μIso := fun m n ↦ (h.add m.as n.as).symm μIso_hom_natural_left := by rintro ⟨X⟩ ⟨Y⟩ ⟨⟨⟨rfl⟩⟩⟩ ⟨X'⟩ ext simp μIso_hom_natural_right := by rintro ⟨X⟩ ⟨Y⟩ ⟨X'⟩ ⟨⟨⟨rfl⟩⟩⟩ ext simp associativity := by rintro ⟨m₁⟩ ⟨m₂⟩ ⟨m₃⟩ ext X simp [endofunctorMonoidalCategory, h.assoc_inv_app_assoc] left_unitality := by rintro ⟨n⟩ ext X simp [endofunctorMonoidalCategory, h.zero_add_inv_app, ← Functor.map_comp] right_unitality := by rintro ⟨n⟩ ext X simp [endofunctorMonoidalCategory, h.add_zero_inv_app] } /-- Constructs a `HasShift C A` instance from `ShiftMkCore`. -/ def hasShiftMk (h : ShiftMkCore C A) : HasShift C A where shift := Discrete.functor h.F end section variable [HasShift C A] /-- The monoidal functor from `A` to `C ⥤ C` given a `HasShift` instance. -/ def shiftMonoidalFunctor : Discrete A ⥤ C ⥤ C := HasShift.shift instance : (shiftMonoidalFunctor C A).Monoidal := HasShift.shiftMonoidal variable {A} open Functor.Monoidal /-- The shift autoequivalence, moving objects and morphisms 'up'. -/ def shiftFunctor (i : A) : C ⥤ C := (shiftMonoidalFunctor C A).obj ⟨i⟩ /-- Shifting by `i + j` is the same as shifting by `i` and then shifting by `j`. -/ def shiftFunctorAdd (i j : A) : shiftFunctor C (i + j) ≅ shiftFunctor C i ⋙ shiftFunctor C j := (μIso (shiftMonoidalFunctor C A) ⟨i⟩ ⟨j⟩).symm /-- When `k = i + j`, shifting by `k` is the same as shifting by `i` and then shifting by `j`. -/ def shiftFunctorAdd' (i j k : A) (h : i + j = k) : shiftFunctor C k ≅ shiftFunctor C i ⋙ shiftFunctor C j := eqToIso (by rw [h]) ≪≫ shiftFunctorAdd C i j lemma shiftFunctorAdd'_eq_shiftFunctorAdd (i j : A) : shiftFunctorAdd' C i j (i+j) rfl = shiftFunctorAdd C i j := by ext1 apply Category.id_comp variable (A) in /-- Shifting by zero is the identity functor. -/ def shiftFunctorZero : shiftFunctor C (0 : A) ≅ 𝟭 C := (εIso (shiftMonoidalFunctor C A)).symm /-- Shifting by `a` such that `a = 0` identifies to the identity functor. -/ def shiftFunctorZero' (a : A) (ha : a = 0) : shiftFunctor C a ≅ 𝟭 C := eqToIso (by rw [ha]) ≪≫ shiftFunctorZero C A end variable {C A} lemma ShiftMkCore.shiftFunctor_eq (h : ShiftMkCore C A) (a : A) : letI := hasShiftMk C A h shiftFunctor C a = h.F a := rfl lemma ShiftMkCore.shiftFunctorZero_eq (h : ShiftMkCore C A) : letI := hasShiftMk C A h shiftFunctorZero C A = h.zero := rfl lemma ShiftMkCore.shiftFunctorAdd_eq (h : ShiftMkCore C A) (a b : A) : letI := hasShiftMk C A h shiftFunctorAdd C a b = h.add a b := rfl set_option quotPrecheck false in /-- shifting an object `X` by `n` is obtained by the notation `X⟦n⟧` -/ notation -- Any better notational suggestions? X "⟦" n "⟧" => (shiftFunctor _ n).obj X set_option quotPrecheck false in /-- shifting a morphism `f` by `n` is obtained by the notation `f⟦n⟧'` -/ notation f "⟦" n "⟧'" => (shiftFunctor _ n).map f variable (C) variable [HasShift C A] lemma shiftFunctorAdd'_zero_add (a : A) : shiftFunctorAdd' C 0 a a (zero_add a) = (leftUnitor _).symm ≪≫ isoWhiskerRight (shiftFunctorZero C A).symm (shiftFunctor C a) := by ext X dsimp [shiftFunctorAdd', shiftFunctorZero, shiftFunctor] simp only [eqToHom_app, obj_ε_app, Discrete.addMonoidal_leftUnitor, eqToIso.inv, eqToHom_map, Category.id_comp] rfl lemma shiftFunctorAdd'_add_zero (a : A) : shiftFunctorAdd' C a 0 a (add_zero a) = (rightUnitor _).symm ≪≫ isoWhiskerLeft (shiftFunctor C a) (shiftFunctorZero C A).symm := by ext dsimp [shiftFunctorAdd', shiftFunctorZero, shiftFunctor] simp only [eqToHom_app, ε_app_obj, Discrete.addMonoidal_rightUnitor, eqToIso.inv, eqToHom_map, Category.id_comp] rfl lemma shiftFunctorAdd'_assoc (a₁ a₂ a₃ a₁₂ a₂₃ a₁₂₃ : A) (h₁₂ : a₁ + a₂ = a₁₂) (h₂₃ : a₂ + a₃ = a₂₃) (h₁₂₃ : a₁ + a₂ + a₃ = a₁₂₃) : shiftFunctorAdd' C a₁₂ a₃ a₁₂₃ (by rw [← h₁₂, h₁₂₃]) ≪≫ isoWhiskerRight (shiftFunctorAdd' C a₁ a₂ a₁₂ h₁₂) _ ≪≫ associator _ _ _ = shiftFunctorAdd' C a₁ a₂₃ a₁₂₃ (by rw [← h₂₃, ← add_assoc, h₁₂₃]) ≪≫ isoWhiskerLeft _ (shiftFunctorAdd' C a₂ a₃ a₂₃ h₂₃) := by subst h₁₂ h₂₃ h₁₂₃ ext X dsimp simp only [shiftFunctorAdd'_eq_shiftFunctorAdd, Category.comp_id] dsimp [shiftFunctorAdd'] simp only [eqToHom_app] dsimp [shiftFunctorAdd, shiftFunctor] simp only [obj_μ_inv_app, Discrete.addMonoidal_associator, eqToIso.hom, eqToHom_map, eqToHom_app] erw [δ_μ_app_assoc, Category.assoc] rfl lemma shiftFunctorAdd_assoc (a₁ a₂ a₃ : A) : shiftFunctorAdd C (a₁ + a₂) a₃ ≪≫ isoWhiskerRight (shiftFunctorAdd C a₁ a₂) _ ≪≫ associator _ _ _ = shiftFunctorAdd' C a₁ (a₂ + a₃) _ (add_assoc a₁ a₂ a₃).symm ≪≫ isoWhiskerLeft _ (shiftFunctorAdd C a₂ a₃) := by ext X simpa [shiftFunctorAdd'_eq_shiftFunctorAdd] using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_assoc C a₁ a₂ a₃ _ _ _ rfl rfl rfl)) X variable {C} lemma shiftFunctorAdd'_zero_add_hom_app (a : A) (X : C) : (shiftFunctorAdd' C 0 a a (zero_add a)).hom.app X = ((shiftFunctorZero C A).inv.app X)⟦a⟧' := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_zero_add C a)) X lemma shiftFunctorAdd_zero_add_hom_app (a : A) (X : C) : (shiftFunctorAdd C 0 a).hom.app X = eqToHom (by dsimp; rw [zero_add]) ≫ ((shiftFunctorZero C A).inv.app X)⟦a⟧' := by simp [← shiftFunctorAdd'_zero_add_hom_app, shiftFunctorAdd'] lemma shiftFunctorAdd'_zero_add_inv_app (a : A) (X : C) : (shiftFunctorAdd' C 0 a a (zero_add a)).inv.app X = ((shiftFunctorZero C A).hom.app X)⟦a⟧' := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd'_zero_add C a)) X lemma shiftFunctorAdd_zero_add_inv_app (a : A) (X : C) : (shiftFunctorAdd C 0 a).inv.app X = ((shiftFunctorZero C A).hom.app X)⟦a⟧' ≫ eqToHom (by dsimp; rw [zero_add]) := by simp [← shiftFunctorAdd'_zero_add_inv_app, shiftFunctorAdd'] lemma shiftFunctorAdd'_add_zero_hom_app (a : A) (X : C) : (shiftFunctorAdd' C a 0 a (add_zero a)).hom.app X = (shiftFunctorZero C A).inv.app (X⟦a⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_add_zero C a)) X lemma shiftFunctorAdd_add_zero_hom_app (a : A) (X : C) : (shiftFunctorAdd C a 0).hom.app X = eqToHom (by dsimp; rw [add_zero]) ≫ (shiftFunctorZero C A).inv.app (X⟦a⟧) := by simp [← shiftFunctorAdd'_add_zero_hom_app, shiftFunctorAdd'] lemma shiftFunctorAdd'_add_zero_inv_app (a : A) (X : C) : (shiftFunctorAdd' C a 0 a (add_zero a)).inv.app X = (shiftFunctorZero C A).hom.app (X⟦a⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd'_add_zero C a)) X lemma shiftFunctorAdd_add_zero_inv_app (a : A) (X : C) : (shiftFunctorAdd C a 0).inv.app X = (shiftFunctorZero C A).hom.app (X⟦a⟧) ≫ eqToHom (by dsimp; rw [add_zero]) := by simp [← shiftFunctorAdd'_add_zero_inv_app, shiftFunctorAdd'] @[reassoc] lemma shiftFunctorAdd'_assoc_hom_app (a₁ a₂ a₃ a₁₂ a₂₃ a₁₂₃ : A) (h₁₂ : a₁ + a₂ = a₁₂) (h₂₃ : a₂ + a₃ = a₂₃) (h₁₂₃ : a₁ + a₂ + a₃ = a₁₂₃) (X : C) : (shiftFunctorAdd' C a₁₂ a₃ a₁₂₃ (by rw [← h₁₂, h₁₂₃])).hom.app X ≫ ((shiftFunctorAdd' C a₁ a₂ a₁₂ h₁₂).hom.app X)⟦a₃⟧' = (shiftFunctorAdd' C a₁ a₂₃ a₁₂₃ (by rw [← h₂₃, ← add_assoc, h₁₂₃])).hom.app X ≫ (shiftFunctorAdd' C a₂ a₃ a₂₃ h₂₃).hom.app (X⟦a₁⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd'_assoc C _ _ _ _ _ _ h₁₂ h₂₃ h₁₂₃)) X @[reassoc] lemma shiftFunctorAdd'_assoc_inv_app (a₁ a₂ a₃ a₁₂ a₂₃ a₁₂₃ : A) (h₁₂ : a₁ + a₂ = a₁₂) (h₂₃ : a₂ + a₃ = a₂₃) (h₁₂₃ : a₁ + a₂ + a₃ = a₁₂₃) (X : C) : ((shiftFunctorAdd' C a₁ a₂ a₁₂ h₁₂).inv.app X)⟦a₃⟧' ≫ (shiftFunctorAdd' C a₁₂ a₃ a₁₂₃ (by rw [← h₁₂, h₁₂₃])).inv.app X = (shiftFunctorAdd' C a₂ a₃ a₂₃ h₂₃).inv.app (X⟦a₁⟧) ≫ (shiftFunctorAdd' C a₁ a₂₃ a₁₂₃ (by rw [← h₂₃, ← add_assoc, h₁₂₃])).inv.app X := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd'_assoc C _ _ _ _ _ _ h₁₂ h₂₃ h₁₂₃)) X @[reassoc] lemma shiftFunctorAdd_assoc_hom_app (a₁ a₂ a₃ : A) (X : C) : (shiftFunctorAdd C (a₁ + a₂) a₃).hom.app X ≫ ((shiftFunctorAdd C a₁ a₂).hom.app X)⟦a₃⟧' = (shiftFunctorAdd' C a₁ (a₂ + a₃) (a₁ + a₂ + a₃) (add_assoc _ _ _).symm).hom.app X ≫ (shiftFunctorAdd C a₂ a₃).hom.app (X⟦a₁⟧) := by simpa using NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorAdd_assoc C a₁ a₂ a₃)) X @[reassoc] lemma shiftFunctorAdd_assoc_inv_app (a₁ a₂ a₃ : A) (X : C) : ((shiftFunctorAdd C a₁ a₂).inv.app X)⟦a₃⟧' ≫ (shiftFunctorAdd C (a₁ + a₂) a₃).inv.app X = (shiftFunctorAdd C a₂ a₃).inv.app (X⟦a₁⟧) ≫ (shiftFunctorAdd' C a₁ (a₂ + a₃) (a₁ + a₂ + a₃) (add_assoc _ _ _).symm).inv.app X := by simpa using NatTrans.congr_app (congr_arg Iso.inv (shiftFunctorAdd_assoc C a₁ a₂ a₃)) X end Defs section AddMonoid variable [AddMonoid A] [HasShift C A] (X Y : C) (f : X ⟶ Y) --@[simp] --theorem HasShift.shift_obj_obj (n : A) (X : C) : (HasShift.shift.obj ⟨n⟩).obj X = X⟦n⟧ := -- rfl /-- Shifting by `i + j` is the same as shifting by `i` and then shifting by `j`. -/ abbrev shiftAdd (i j : A) : X⟦i + j⟧ ≅ X⟦i⟧⟦j⟧ := (shiftFunctorAdd C i j).app _ theorem shift_shift' (i j : A) : f⟦i⟧'⟦j⟧' = (shiftAdd X i j).inv ≫ f⟦i + j⟧' ≫ (shiftAdd Y i j).hom := by simp variable (A) /-- Shifting by zero is the identity functor. -/ abbrev shiftZero : X⟦(0 : A)⟧ ≅ X := (shiftFunctorZero C A).app _ theorem shiftZero' : f⟦(0 : A)⟧' = (shiftZero A X).hom ≫ f ≫ (shiftZero A Y).inv := by symm rw [Iso.app_inv, Iso.app_hom] apply NatIso.naturality_2 variable (C) {A} /-- When `i + j = 0`, shifting by `i` and by `j` gives the identity functor -/ def shiftFunctorCompIsoId (i j : A) (h : i + j = 0) : shiftFunctor C i ⋙ shiftFunctor C j ≅ 𝟭 C := (shiftFunctorAdd' C i j 0 h).symm ≪≫ shiftFunctorZero C A end AddMonoid section AddGroup variable (C) variable [AddGroup A] [HasShift C A] /-- Shifting by `i` and shifting by `j` forms an equivalence when `i + j = 0`. -/ @[simps] def shiftEquiv' (i j : A) (h : i + j = 0) : C ≌ C where functor := shiftFunctor C i inverse := shiftFunctor C j unitIso := (shiftFunctorCompIsoId C i j h).symm counitIso := shiftFunctorCompIsoId C j i (by rw [← add_left_inj j, add_assoc, h, zero_add, add_zero]) functor_unitIso_comp X := by convert (equivOfTensorIsoUnit (shiftMonoidalFunctor C A) ⟨i⟩ ⟨j⟩ (Discrete.eqToIso h) (Discrete.eqToIso (by dsimp; rw [← add_left_inj j, add_assoc, h, zero_add, add_zero])) (Subsingleton.elim _ _)).functor_unitIso_comp X all_goals ext X dsimp [shiftFunctorCompIsoId, unitOfTensorIsoUnit, shiftFunctorAdd'] simp only [Category.assoc, eqToHom_map] rfl /-- Shifting by `n` and shifting by `-n` forms an equivalence. -/ abbrev shiftEquiv (n : A) : C ≌ C := shiftEquiv' C n (-n) (add_neg_cancel n) variable (X Y : C) (f : X ⟶ Y) /-- Shifting by `i` is an equivalence. -/ instance (i : A) : (shiftFunctor C i).IsEquivalence := by change (shiftEquiv C i).functor.IsEquivalence infer_instance variable {C} /-- Shifting by `i` and then shifting by `-i` is the identity. -/ abbrev shiftShiftNeg (i : A) : X⟦i⟧⟦-i⟧ ≅ X := (shiftEquiv C i).unitIso.symm.app X /-- Shifting by `-i` and then shifting by `i` is the identity. -/ abbrev shiftNegShift (i : A) : X⟦-i⟧⟦i⟧ ≅ X := (shiftEquiv C i).counitIso.app X variable {X Y} theorem shift_shift_neg' (i : A) : f⟦i⟧'⟦-i⟧' = (shiftFunctorCompIsoId C i (-i) (add_neg_cancel i)).hom.app X ≫ f ≫ (shiftFunctorCompIsoId C i (-i) (add_neg_cancel i)).inv.app Y := (NatIso.naturality_2 (shiftFunctorCompIsoId C i (-i) (add_neg_cancel i)) f).symm theorem shift_neg_shift' (i : A) : f⟦-i⟧'⟦i⟧' = (shiftFunctorCompIsoId C (-i) i (neg_add_cancel i)).hom.app X ≫ f ≫ (shiftFunctorCompIsoId C (-i) i (neg_add_cancel i)).inv.app Y := (NatIso.naturality_2 (shiftFunctorCompIsoId C (-i) i (neg_add_cancel i)) f).symm theorem shift_equiv_triangle (n : A) (X : C) : (shiftShiftNeg X n).inv⟦n⟧' ≫ (shiftNegShift (X⟦n⟧) n).hom = 𝟙 (X⟦n⟧) := (shiftEquiv C n).functor_unitIso_comp X section theorem shift_shiftFunctorCompIsoId_hom_app (n m : A) (h : n + m = 0) (X : C) : ((shiftFunctorCompIsoId C n m h).hom.app X)⟦n⟧' = (shiftFunctorCompIsoId C m n (by rw [← neg_eq_of_add_eq_zero_left h, add_neg_cancel])).hom.app (X⟦n⟧) := by dsimp [shiftFunctorCompIsoId] simpa only [Functor.map_comp, ← shiftFunctorAdd'_zero_add_inv_app n X, ← shiftFunctorAdd'_add_zero_inv_app n X] using shiftFunctorAdd'_assoc_inv_app n m n 0 0 n h (by rw [← neg_eq_of_add_eq_zero_left h, add_neg_cancel]) (by rw [h, zero_add]) X theorem shift_shiftFunctorCompIsoId_inv_app (n m : A) (h : n + m = 0) (X : C) : ((shiftFunctorCompIsoId C n m h).inv.app X)⟦n⟧' = ((shiftFunctorCompIsoId C m n (by rw [← neg_eq_of_add_eq_zero_left h, add_neg_cancel])).inv.app (X⟦n⟧)) := by rw [← cancel_mono (((shiftFunctorCompIsoId C n m h).hom.app X)⟦n⟧'), ← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id, shift_shiftFunctorCompIsoId_hom_app, Iso.inv_hom_id_app] rfl theorem shift_shiftFunctorCompIsoId_add_neg_cancel_hom_app (n : A) (X : C) : ((shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).hom.app X)⟦n⟧' = (shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).hom.app (X⟦n⟧) := by apply shift_shiftFunctorCompIsoId_hom_app theorem shift_shiftFunctorCompIsoId_add_neg_cancel_inv_app (n : A) (X : C) : ((shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).inv.app X)⟦n⟧' = (shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).inv.app (X⟦n⟧) := by apply shift_shiftFunctorCompIsoId_inv_app theorem shift_shiftFunctorCompIsoId_neg_add_cancel_hom_app (n : A) (X : C) : ((shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).hom.app X)⟦-n⟧' = (shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).hom.app (X⟦-n⟧) := by apply shift_shiftFunctorCompIsoId_hom_app theorem shift_shiftFunctorCompIsoId_neg_add_cancel_inv_app (n : A) (X : C) : ((shiftFunctorCompIsoId C (-n) n (neg_add_cancel n)).inv.app X)⟦-n⟧' = (shiftFunctorCompIsoId C n (-n) (add_neg_cancel n)).inv.app (X⟦-n⟧) := by apply shift_shiftFunctorCompIsoId_inv_app end section variable (A) lemma shiftFunctorCompIsoId_zero_zero_hom_app (X : C) : (shiftFunctorCompIsoId C 0 0 (add_zero 0)).hom.app X = ((shiftFunctorZero C A).hom.app X)⟦0⟧' ≫ (shiftFunctorZero C A).hom.app X := by simp [shiftFunctorCompIsoId, shiftFunctorAdd'_zero_add_inv_app] lemma shiftFunctorCompIsoId_zero_zero_inv_app (X : C) : (shiftFunctorCompIsoId C 0 0 (add_zero 0)).inv.app X = (shiftFunctorZero C A).inv.app X ≫ ((shiftFunctorZero C A).inv.app X)⟦0⟧' := by simp [shiftFunctorCompIsoId, shiftFunctorAdd'_zero_add_hom_app] end section variable (m n p m' n' p' : A) (hm : m' + m = 0) (hn : n' + n = 0) (hp : p' + p = 0) (h : m + n = p) lemma shiftFunctorCompIsoId_add'_inv_app : (shiftFunctorCompIsoId C p' p hp).inv.app X = (shiftFunctorCompIsoId C n' n hn).inv.app X ≫ (shiftFunctorCompIsoId C m' m hm).inv.app (X⟦n'⟧)⟦n⟧' ≫ (shiftFunctorAdd' C m n p h).inv.app (X⟦n'⟧⟦m'⟧) ≫ ((shiftFunctorAdd' C n' m' p' (by rw [← add_left_inj p, hp, ← h, add_assoc, ← add_assoc m', hm, zero_add, hn])).inv.app X)⟦p⟧' := by dsimp [shiftFunctorCompIsoId] simp only [Functor.map_comp, Category.assoc] congr 1 rw [← NatTrans.naturality] dsimp rw [← cancel_mono ((shiftFunctorAdd' C p' p 0 hp).inv.app X), Iso.hom_inv_id_app, Category.assoc, Category.assoc, Category.assoc, Category.assoc, ← shiftFunctorAdd'_assoc_inv_app p' m n n' p 0 (by rw [← add_left_inj n, hn, add_assoc, h, hp]) h (by rw [add_assoc, h, hp]), ← Functor.map_comp_assoc, ← Functor.map_comp_assoc, ← Functor.map_comp_assoc, Category.assoc, Category.assoc, shiftFunctorAdd'_assoc_inv_app n' m' m p' 0 n' _ _ (by rw [add_assoc, hm, add_zero]), Iso.hom_inv_id_app_assoc, ← shiftFunctorAdd'_add_zero_hom_app, Iso.hom_inv_id_app, Functor.map_id, Category.id_comp, Iso.hom_inv_id_app] lemma shiftFunctorCompIsoId_add'_hom_app : (shiftFunctorCompIsoId C p' p hp).hom.app X = ((shiftFunctorAdd' C n' m' p' (by rw [← add_left_inj p, hp, ← h, add_assoc, ← add_assoc m', hm, zero_add, hn])).hom.app X)⟦p⟧' ≫ (shiftFunctorAdd' C m n p h).hom.app (X⟦n'⟧⟦m'⟧) ≫ (shiftFunctorCompIsoId C m' m hm).hom.app (X⟦n'⟧)⟦n⟧' ≫ (shiftFunctorCompIsoId C n' n hn).hom.app X := by rw [← cancel_mono ((shiftFunctorCompIsoId C p' p hp).inv.app X), Iso.hom_inv_id_app, shiftFunctorCompIsoId_add'_inv_app m n p m' n' p' hm hn hp h, Category.assoc, Category.assoc, Category.assoc, Iso.hom_inv_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app] dsimp rw [Functor.map_id, Category.id_comp, Iso.hom_inv_id_app_assoc, ← Functor.map_comp, Iso.hom_inv_id_app, Functor.map_id] end open CategoryTheory.Limits variable [HasZeroMorphisms C] theorem shift_zero_eq_zero (X Y : C) (n : A) : (0 : X ⟶ Y)⟦n⟧' = (0 : X⟦n⟧ ⟶ Y⟦n⟧) := CategoryTheory.Functor.map_zero _ _ _ end AddGroup section AddCommMonoid variable [AddCommMonoid A] [HasShift C A] variable (C) /-- When shifts are indexed by an additive commutative monoid, then shifts commute. -/ def shiftFunctorComm (i j : A) : shiftFunctor C i ⋙ shiftFunctor C j ≅ shiftFunctor C j ⋙ shiftFunctor C i := (shiftFunctorAdd C i j).symm ≪≫ shiftFunctorAdd' C j i (i + j) (add_comm j i) lemma shiftFunctorComm_eq (i j k : A) (h : i + j = k) : shiftFunctorComm C i j = (shiftFunctorAdd' C i j k h).symm ≪≫ shiftFunctorAdd' C j i k (by rw [add_comm j i, h]) := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd] rfl @[simp] lemma shiftFunctorComm_eq_refl (i : A) : shiftFunctorComm C i i = Iso.refl _ := by rw [shiftFunctorComm_eq C i i (i + i) rfl, Iso.symm_self_id] lemma shiftFunctorComm_symm (i j : A) : (shiftFunctorComm C i j).symm = shiftFunctorComm C j i := by ext1 dsimp rw [shiftFunctorComm_eq C i j (i+j) rfl, shiftFunctorComm_eq C j i (i+j) (add_comm j i)] rfl variable {C} variable (X Y : C) (f : X ⟶ Y) /-- When shifts are indexed by an additive commutative monoid, then shifts commute. -/ abbrev shiftComm (i j : A) : X⟦i⟧⟦j⟧ ≅ X⟦j⟧⟦i⟧ := (shiftFunctorComm C i j).app X @[simp] theorem shiftComm_symm (i j : A) : (shiftComm X i j).symm = shiftComm X j i := by ext exact NatTrans.congr_app (congr_arg Iso.hom (shiftFunctorComm_symm C i j)) X variable {X Y} /-- When shifts are indexed by an additive commutative monoid, then shifts commute. -/ theorem shiftComm' (i j : A) : f⟦i⟧'⟦j⟧' = (shiftComm _ _ _).hom ≫ f⟦j⟧'⟦i⟧' ≫ (shiftComm _ _ _).hom := by erw [← shiftComm_symm Y i j, ← ((shiftFunctorComm C i j).hom.naturality_assoc f)] dsimp simp only [Iso.hom_inv_id_app, Functor.comp_obj, Category.comp_id] @[reassoc] theorem shiftComm_hom_comp (i j : A) : (shiftComm X i j).hom ≫ f⟦j⟧'⟦i⟧' = f⟦i⟧'⟦j⟧' ≫ (shiftComm Y i j).hom := by rw [shiftComm', ← shiftComm_symm, Iso.symm_hom, Iso.inv_hom_id_assoc] lemma shiftFunctorZero_hom_app_shift (n : A) : (shiftFunctorZero C A).hom.app (X⟦n⟧) = (shiftFunctorComm C n 0).hom.app X ≫ ((shiftFunctorZero C A).hom.app X)⟦n⟧' := by rw [← shiftFunctorAdd'_zero_add_inv_app n X, shiftFunctorComm_eq C n 0 n (add_zero n)] dsimp rw [Category.assoc, Iso.hom_inv_id_app, Category.comp_id, shiftFunctorAdd'_add_zero_inv_app] lemma shiftFunctorZero_inv_app_shift (n : A) : (shiftFunctorZero C A).inv.app (X⟦n⟧) = ((shiftFunctorZero C A).inv.app X)⟦n⟧' ≫ (shiftFunctorComm C n 0).inv.app X := by rw [← cancel_mono ((shiftFunctorZero C A).hom.app (X⟦n⟧)), Category.assoc, Iso.inv_hom_id_app, shiftFunctorZero_hom_app_shift, Iso.inv_hom_id_app_assoc, ← Functor.map_comp, Iso.inv_hom_id_app] dsimp rw [Functor.map_id] lemma shiftFunctorComm_zero_hom_app (a : A) : (shiftFunctorComm C a 0).hom.app X = (shiftFunctorZero C A).hom.app (X⟦a⟧) ≫ ((shiftFunctorZero C A).inv.app X)⟦a⟧' := by simp only [shiftFunctorZero_hom_app_shift, Category.assoc, ← Functor.map_comp, Iso.hom_inv_id_app, Functor.map_id, Functor.comp_obj, Category.comp_id] @[reassoc] lemma shiftFunctorComm_hom_app_comp_shift_shiftFunctorAdd_hom_app (m₁ m₂ m₃ : A) (X : C) : (shiftFunctorComm C m₁ (m₂ + m₃)).hom.app X ≫ ((shiftFunctorAdd C m₂ m₃).hom.app X)⟦m₁⟧' = (shiftFunctorAdd C m₂ m₃).hom.app (X⟦m₁⟧) ≫ ((shiftFunctorComm C m₁ m₂).hom.app X)⟦m₃⟧' ≫ (shiftFunctorComm C m₁ m₃).hom.app (X⟦m₂⟧) := by rw [← cancel_mono ((shiftFunctorComm C m₁ m₃).inv.app (X⟦m₂⟧)), ← cancel_mono (((shiftFunctorComm C m₁ m₂).inv.app X)⟦m₃⟧')] simp only [Category.assoc, Iso.hom_inv_id_app] dsimp simp only [Category.id_comp, ← Functor.map_comp, Iso.hom_inv_id_app] dsimp simp only [Functor.map_id, Category.comp_id, shiftFunctorComm_eq C _ _ _ rfl, ← shiftFunctorAdd'_eq_shiftFunctorAdd] dsimp simp only [Category.assoc, Iso.hom_inv_id_app_assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp, shiftFunctorAdd'_assoc_hom_app_assoc m₂ m₃ m₁ (m₂ + m₃) (m₁ + m₃) (m₁ + (m₂ + m₃)) rfl (add_comm m₃ m₁) (add_comm _ m₁) X, ← shiftFunctorAdd'_assoc_hom_app_assoc m₂ m₁ m₃ (m₁ + m₂) (m₁ + m₃) (m₁ + (m₂ + m₃)) (add_comm _ _) rfl (by rw [add_comm m₂ m₁, add_assoc]) X, shiftFunctorAdd'_assoc_hom_app m₁ m₂ m₃ (m₁ + m₂) (m₂ + m₃) (m₁ + (m₂ + m₃)) rfl rfl (add_assoc _ _ _) X] end AddCommMonoid namespace Functor.FullyFaithful variable {D : Type*} [Category D] [AddMonoid A] [HasShift D A] variable {F : C ⥤ D} (hF : F.FullyFaithful) variable (s : A → C ⥤ C) (i : ∀ i, s i ⋙ F ≅ F ⋙ shiftFunctor D i) namespace hasShift /-- auxiliary definition for `FullyFaithful.hasShift` -/ def zero : s 0 ≅ 𝟭 C := (hF.whiskeringRight C).preimageIso ((i 0) ≪≫ isoWhiskerLeft F (shiftFunctorZero D A) ≪≫ rightUnitor _ ≪≫ (leftUnitor _).symm) @[simp] lemma map_zero_hom_app (X : C) : F.map ((zero hF s i).hom.app X) = (i 0).hom.app X ≫ (shiftFunctorZero D A).hom.app (F.obj X) := by simp [zero] @[simp] lemma map_zero_inv_app (X : C) : F.map ((zero hF s i).inv.app X) = (shiftFunctorZero D A).inv.app (F.obj X) ≫ (i 0).inv.app X := by simp [zero] /-- auxiliary definition for `FullyFaithful.hasShift` -/ def add (a b : A) : s (a + b) ≅ s a ⋙ s b := (hF.whiskeringRight C).preimageIso (i (a + b) ≪≫ isoWhiskerLeft _ (shiftFunctorAdd D a b) ≪≫ (associator _ _ _).symm ≪≫ (isoWhiskerRight (i a).symm _) ≪≫ associator _ _ _ ≪≫ (isoWhiskerLeft _ (i b).symm) ≪≫ (associator _ _ _).symm) @[simp] lemma map_add_hom_app (a b : A) (X : C) : F.map ((add hF s i a b).hom.app X) = (i (a + b)).hom.app X ≫ (shiftFunctorAdd D a b).hom.app (F.obj X) ≫ ((i a).inv.app X)⟦b⟧' ≫ (i b).inv.app ((s a).obj X) := by dsimp [add] simp @[simp] lemma map_add_inv_app (a b : A) (X : C) : F.map ((add hF s i a b).inv.app X) = (i b).hom.app ((s a).obj X) ≫ ((i a).hom.app X)⟦b⟧' ≫ (shiftFunctorAdd D a b).inv.app (F.obj X) ≫ (i (a + b)).inv.app X := by dsimp [add] simp end hasShift open hasShift in /-- Given a family of endomorphisms of `C` which are intertwined by a fully faithful `F : C ⥤ D` with shift functors on `D`, we can promote that family to shift functors on `C`. -/ def hasShift : HasShift C A := hasShiftMk C A { F := s zero := zero hF s i add := add hF s i assoc_hom_app := fun m₁ m₂ m₃ X => hF.map_injective (by have h := shiftFunctorAdd'_assoc_hom_app m₁ m₂ m₃ _ _ (m₁+m₂+m₃) rfl rfl rfl (F.obj X) simp only [shiftFunctorAdd'_eq_shiftFunctorAdd] at h rw [← cancel_mono ((i m₃).hom.app ((s m₂).obj ((s m₁).obj X)))] simp only [Functor.comp_obj, Functor.map_comp, map_add_hom_app, Category.assoc, Iso.inv_hom_id_app_assoc, NatTrans.naturality_assoc, Functor.comp_map, Iso.inv_hom_id_app, Category.comp_id] erw [(i m₃).hom.naturality] rw [Functor.comp_map, map_add_hom_app, Functor.map_comp, Functor.map_comp, Iso.inv_hom_id_app_assoc, ← Functor.map_comp_assoc _ ((i (m₁ + m₂)).inv.app X), Iso.inv_hom_id_app, Functor.map_id, Category.id_comp, reassoc_of% h, dcongr_arg (fun a => (i a).hom.app X) (add_assoc m₁ m₂ m₃)] simp [shiftFunctorAdd', eqToHom_map]) zero_add_hom_app := fun n X => hF.map_injective (by have this := dcongr_arg (fun a => (i a).hom.app X) (zero_add n) rw [← cancel_mono ((i n).hom.app ((s 0).obj X)) ] simp [this, map_add_hom_app, shiftFunctorAdd_zero_add_hom_app, eqToHom_map] congr 1 erw [(i n).hom.naturality] simp) add_zero_hom_app := fun n X => hF.map_injective (by have := dcongr_arg (fun a => (i a).hom.app X) (add_zero n) simp [this, ← NatTrans.naturality_assoc, eqToHom_map, shiftFunctorAdd_add_zero_hom_app]) } end Functor.FullyFaithful end end CategoryTheory
ssrmatching.v
From Corelib Require Export ssrmatching.
Fin.lean
/- Copyright (c) 2025 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Limits.Shapes.IsTerminal import Mathlib.Order.Fin.Basic /-! # Limits and colimits indexed by `Fin` In this file, we show that `0 : Fin (n + 1)` is an initial object and `Fin.last n` is a terminal object. This allows to compute limits and colimits indexed by `Fin (n + 1)`, see `limitOfDiagramInitial` and `colimitOfDiagramTerminal` in the file `Limits.Shapes.IsTerminal`. -/ universe v v' u u' w open CategoryTheory Limits namespace Fin variable (n : ℕ) /-- `0` is an initial object in `Fin n` when `n ≠ 0`. -/ def isInitialZero [NeZero n] : IsInitial (0 : Fin n) := isInitialBot /-- `Fin.last n` is a terminal object in `Fin (n + 1)`. -/ def isTerminalLast : IsTerminal (Fin.last n) := isTerminalTop end Fin
burnside_app.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div. From mathcomp Require Import choice fintype tuple finfun bigop finset fingroup. From mathcomp Require Import action perm primitive_action ssrAC. (* Application of the Burside formula to count the number of distinct *) (* colorings of the vertices of a square and a cube. *) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Lemma burnside_formula : forall (gT : finGroupType) s (G : {group gT}), uniq s -> s =i G -> forall (sT : finType) (to : {action gT &-> sT}), (#|orbit to G @: setT| * size s)%N = \sum_(p <- s) #|'Fix_to[p]|. Proof. move=> gT s G Us sG sT to. rewrite big_uniq // -(card_uniqP Us) (eq_card sG) -Frobenius_Cauchy. by apply: eq_big => // p _; rewrite setTI. by apply/actsP=> ? _ ?; rewrite !inE. Qed. Arguments burnside_formula {gT}. Section colouring. Variable n : nat. Definition colors := 'I_n. HB.instance Definition _ := Finite.on colors. Section square_colouring. Definition square := 'I_4. HB.instance Definition _ := SubType.on square. HB.instance Definition _ := Finite.on square. Definition mksquare i : square := Sub (i %% _) (ltn_mod i 4). Definition c0 := mksquare 0. Definition c1 := mksquare 1. Definition c2 := mksquare 2. Definition c3 := mksquare 3. (*rotations*) Definition R1 (sc : square) : square := tnth [tuple c1; c2; c3; c0] sc. Definition R2 (sc : square) : square := tnth [tuple c2; c3; c0; c1] sc. Definition R3 (sc : square) : square := tnth [tuple c3; c0; c1; c2] sc. Ltac get_inv elt l := match l with | (_, (elt, ?x)) => x | (elt, ?x) => x | (?x, _) => get_inv elt x end. Definition rot_inv := ((R1, R3), (R2, R2), (R3, R1)). Ltac inj_tac := move: (erefl rot_inv); unfold rot_inv; match goal with |- ?X = _ -> injective ?Y => move=> _; let x := get_inv Y X in apply: (can_inj (g:=x)); move=> [val H1] end. Lemma R1_inj : injective R1. Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed. Lemma R2_inj : injective R2. Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed. Lemma R3_inj : injective R3. Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed. Definition r1 := (perm R1_inj). Definition r2 := (perm R2_inj). Definition r3 := (perm R3_inj). Definition id1 := (1 : {perm square}). Definition is_rot (r : {perm _}) := (r * r1 == r1 * r). Definition rot := [set r | is_rot r]. Lemma group_set_rot : group_set rot. Proof. apply/group_setP; split; first by rewrite /rot inE /is_rot mulg1 mul1g. move=> x1 y; rewrite /rot !inE /= /is_rot; move/eqP => hx1; move/eqP => hy. by rewrite -mulgA hy !mulgA hx1. Qed. Canonical rot_group := Group group_set_rot. Definition rotations := [set id1; r1; r2; r3]. Lemma rot_eq_c0 : forall r s : {perm square}, is_rot r -> is_rot s -> r c0 = s c0 -> r = s. Proof. rewrite /is_rot => r s; move/eqP => hr; move/eqP=> hs hrs; apply/permP => a. have ->: a = (r1 ^+ a) c0 by apply/eqP; case: a; do 4?case=> //=; rewrite ?permM !permE. by rewrite -!permM -!commuteX // !permM hrs. Qed. Lemma rot_r1 : forall r, is_rot r -> r = r1 ^+ (r c0). Proof. move=> r hr; apply: rot_eq_c0 => //; apply/eqP. by symmetry; apply: commuteX. by case: (r c0); do 4?case=> //=; rewrite ?permM !permE /=. Qed. Lemma rotations_is_rot : forall r, r \in rotations -> is_rot r. Proof. move=> r Dr; apply/eqP; apply/permP => a; rewrite !inE -!orbA !permM in Dr *. by case/or4P: Dr; move/eqP->; rewrite !permE //; case: a; do 4?case. Qed. Lemma rot_is_rot : rot = rotations. Proof. apply/setP=> r; apply/idP/idP => [|/rotations_is_rot] /[!inE]// h. have -> : r = r1 ^+ (r c0) by apply: rot_eq_c0; rewrite // -rot_r1. have e2: 2 = r2 c0 by rewrite permE /=. have e3: 3 = r3 c0 by rewrite permE /=. case (r c0); do 4?[case] => // ?; rewrite ?(expg1, eqxx, orbT) //. by rewrite [nat_of_ord _]/= e2 -rot_r1 ?(eqxx, orbT, rotations_is_rot, inE). by rewrite [nat_of_ord _]/= e3 -rot_r1 ?(eqxx, orbT, rotations_is_rot, inE). Qed. (*symmetries*) Definition Sh (sc : square) : square := tnth [tuple c1; c0; c3; c2] sc. Lemma Sh_inj : injective Sh. Proof. by apply: (can_inj (g:= Sh)); case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sh := (perm Sh_inj). Lemma sh_inv : sh^-1 = sh. Proof. apply: (mulIg sh); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Definition Sv (sc : square) : square := tnth [tuple c3; c2; c1; c0] sc. Lemma Sv_inj : injective Sv. Proof. by apply: (can_inj (g:= Sv)); case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sv := (perm Sv_inj). Lemma sv_inv : sv^-1 = sv. Proof. apply: (mulIg sv); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Definition Sd1 (sc : square) : square := tnth [tuple c0; c3; c2; c1] sc. Lemma Sd1_inj : injective Sd1. Proof. by apply: can_inj Sd1 _; case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sd1 := (perm Sd1_inj). Lemma sd1_inv : sd1^-1 = sd1. Proof. apply: (mulIg sd1); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Definition Sd2 (sc : square) : square := tnth [tuple c2; c1; c0; c3] sc. Lemma Sd2_inj : injective Sd2. Proof. by apply: can_inj Sd2 _; case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sd2 := (perm Sd2_inj). Lemma sd2_inv : sd2^-1 = sd2. Proof. apply: (mulIg sd2); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Lemma ord_enum4 : enum 'I_4 = [:: c0; c1; c2; c3]. Proof. by apply: (inj_map val_inj); rewrite val_enum_ord. Qed. Lemma diff_id_sh : 1 != sh. Proof. by apply/eqP; move/(congr1 (fun p : {perm square} => p c0)); rewrite !permE. Qed. Definition isometries2 := [set 1; sh]. Lemma card_iso2 : #|isometries2| = 2. Proof. by rewrite cards2 diff_id_sh. Qed. Lemma group_set_iso2 : group_set isometries2. Proof. apply/group_setP; split => [|x y]; rewrite !inE ?eqxx //. do 2![case/orP; move/eqP->]; rewrite ?(mul1g, mulg1) ?eqxx ?orbT//. by rewrite -/sh -{1}sh_inv mulVg eqxx. Qed. Canonical iso2_group := Group group_set_iso2. Definition isometries := [set p | [|| p == 1, p == r1, p == r2, p == r3, p == sh, p == sv, p == sd1 | p == sd2 ]]. Definition opp (sc : square) := tnth [tuple c2; c3; c0; c1] sc. Definition is_iso (p : {perm square}) := forall ci, p (opp ci) = opp (p ci). Lemma isometries_iso : forall p, p \in isometries -> is_iso p. Proof. move=> p; rewrite inE. by do ?case/orP; move/eqP=> -> a; rewrite !permE; case: a; do 4?case. Qed. Ltac non_inj p a1 a2 heq1 heq2 := let h1:= fresh "h1" in (absurd (p a1 = p a2); first (by red => - h1; move: (perm_inj h1)); by rewrite heq1 heq2; apply/eqP). Ltac is_isoPtac p f e0 e1 e2 e3 := suff ->: p = f by [rewrite inE eqxx ?orbT]; let e := fresh "e" in apply/permP; (do 5?[case] => // ?; [move: e0 | move: e1 | move: e2 | move: e3]) => e; apply: etrans (congr1 p _) (etrans e _); apply/eqP; rewrite // permE. Lemma is_isoP : forall p, reflect (is_iso p) (p \in isometries). Proof. move=> p; apply: (iffP idP) => [|iso_p]; first exact: isometries_iso. move e1: (p c1) (iso_p c1) => k1; move e0: (p c0) (iso_p c0) k1 e1 => k0. case: k0 e0; do 4?[case] => //= ? e0 e2; do 5?[case] => //= ? e1 e3; try by [non_inj p c0 c1 e0 e1 | non_inj p c0 c3 e0 e3]. by is_isoPtac p id1 e0 e1 e2 e3. by is_isoPtac p sd1 e0 e1 e2 e3. by is_isoPtac p sh e0 e1 e2 e3. by is_isoPtac p r1 e0 e1 e2 e3. by is_isoPtac p sd2 e0 e1 e2 e3. by is_isoPtac p r2 e0 e1 e2 e3. by is_isoPtac p r3 e0 e1 e2 e3. by is_isoPtac p sv e0 e1 e2 e3. Qed. Lemma group_set_iso : group_set isometries. Proof. apply/group_setP; split; first by rewrite inE eqxx /=. by move=> x y hx hy; apply/is_isoP => ci; rewrite !permM !isometries_iso. Qed. Canonical iso_group := Group group_set_iso. Lemma card_rot : #|rot| = 4. Proof. rewrite -[4]/(size [:: id1; r1; r2; r3]) -(card_uniqP _). by apply: eq_card => x; rewrite rot_is_rot !inE -!orbA. by apply: map_uniq (fun p : {perm square} => p c0) _ _; rewrite /= !permE. Qed. Lemma group_set_rotations : group_set rotations. Proof. by rewrite -rot_is_rot group_set_rot. Qed. Canonical rotations_group := Group group_set_rotations. Notation col_squares := {ffun square -> colors}. Definition act_f (sc : col_squares) (p : {perm square}) : col_squares := [ffun z => sc (p^-1 z)]. Lemma act_f_1 : forall k, act_f k 1 = k. Proof. by move=> k; apply/ffunP=> a; rewrite ffunE invg1 permE. Qed. Lemma act_f_morph : forall k x y, act_f k (x * y) = act_f (act_f k x) y. Proof. by move=> k x y; apply/ffunP=> a; rewrite !ffunE invMg permE. Qed. Definition to := TotalAction act_f_1 act_f_morph. Definition square_coloring_number2 := #|orbit to isometries2 @: setT|. Definition square_coloring_number4 := #|orbit to rotations @: setT|. Definition square_coloring_number8 := #|orbit to isometries @: setT|. Lemma Fid : 'Fix_to(1) = setT. Proof. by apply/setP=> x /=; rewrite in_setT; apply/afix1P; apply: act1. Qed. Lemma card_Fid : #|'Fix_to(1)| = (n ^ 4)%N. Proof. rewrite -[4]card_ord -[n]card_ord -card_ffun_on Fid cardsE. by symmetry; apply: eq_card => f; apply/ffun_onP. Qed. Definition coin0 (sc : col_squares) : colors := sc c0. Definition coin1 (sc : col_squares) : colors := sc c1. Definition coin2 (sc : col_squares) : colors := sc c2. Definition coin3 (sc : col_squares) : colors := sc c3. Lemma eqperm_map : forall p1 p2 : col_squares, (p1 == p2) = all (fun s => p1 s == p2 s) [:: c0; c1; c2; c3]. Proof. move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/ffunP=> x. by apply/eqP; apply Ep12; case: x; do 4!case=> //. Qed. Lemma F_Sh : 'Fix_to[sh] = [set x | (coin0 x == coin1 x) && (coin2 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f sh_inv !ffunE !permE /=. by rewrite eq_sym (eq_sym (x c3)) andbT andbA !andbb. Qed. Lemma F_Sv : 'Fix_to[sv] = [set x | (coin0 x == coin3 x) && (coin2 x == coin1 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f sv_inv !ffunE !permE /=. by rewrite eq_sym andbT andbC (eq_sym (x c1)) andbA -andbA !andbb andbC. Qed. Ltac inv_tac := apply: esym (etrans _ (mul1g _)); apply: canRL (mulgK _) _; let a := fresh "a" in apply/permP => a; apply/eqP; rewrite permM !permE; case: a; do 4?case. Lemma r1_inv : r1^-1 = r3. Proof. by inv_tac. Qed. Lemma r2_inv : r2^-1 = r2. Proof. by inv_tac. Qed. Lemma r3_inv : r3^-1 = r1. Proof. by inv_tac. Qed. Lemma F_r2 : 'Fix_to[r2] = [set x | (coin0 x == coin2 x) && (coin1 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f r2_inv !ffunE !permE /=. by rewrite eq_sym andbT andbCA andbC (eq_sym (x c3)) andbA -andbA !andbb andbC. Qed. Lemma F_r1 : 'Fix_to[r1] = [set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&&(coin2 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f r1_inv !ffunE !permE andbC. by do 3![case E: {+}(_ == _); rewrite // {E}(eqP E)]; rewrite eqxx. Qed. Lemma F_r3 : 'Fix_to[r3] = [set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&&(coin2 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f r3_inv !ffunE !permE /=. by do 3![case: eqVneq=> // <-]. Qed. Lemma card_n2 : forall x y z t : square, uniq [:: x; y; z; t] -> #|[set p : col_squares | (p x == p y) && (p z == p t)]| = (n ^ 2)%N. Proof. move=> x y z t Uxt; rewrite -[n]card_ord. pose f (p : col_squares) := (p x, p z); rewrite -(@card_in_image _ _ f). rewrite -mulnn -card_prod; apply: eq_card => [] [c d] /=; apply/imageP. rewrite (cat_uniq [::x; y]) in Uxt; case/and3P: Uxt => _. rewrite /= !orbF !andbT => /norP[] /[!inE] nxzt nyzt _. exists [ffun i => if pred2 x y i then c else d]. by rewrite inE !ffunE /= !eqxx orbT (negbTE nxzt) (negbTE nyzt) !eqxx. by rewrite {}/f !ffunE /= eqxx (negbTE nxzt). move=> p1 p2 /[!inE] /andP[p1y p1t] /andP[p2y p2t] [px pz]. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t]. by rewrite /= -(eqP p1y) -(eqP p1t) -(eqP p2y) -(eqP p2t) px pz !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxt) card_ord. Qed. Lemma card_n : #|[set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&& (coin2 x == coin3 x)]| = n. Proof. rewrite -[n]card_ord /coin0 /coin1 /coin2 /coin3. pose f (p : col_squares) := p c3; rewrite -(@card_in_image _ _ f). apply: eq_card => c /=; apply/imageP. exists ([ffun => c] : col_squares); last by rewrite /f ffunE. by rewrite /= inE !ffunE !eqxx. move=> p1 p2; rewrite /= !inE /f -!andbA => eqp1 eqp2 eqp12. apply/eqP; rewrite eqperm_map /= andbT. case/and3P: eqp1; do 3!move/eqP->; case/and3P: eqp2; do 3!move/eqP->. by rewrite !andbb eqp12. Qed. Lemma burnside_app2 : (square_coloring_number2 * 2 = n ^ 4 + n ^ 2)%N. Proof. rewrite (burnside_formula [:: id1; sh]) => [||p]; last first. - by rewrite !inE. - by rewrite /= inE diff_id_sh. by rewrite 2!big_cons big_nil addn0 {1}card_Fid F_Sh card_n2. Qed. Lemma burnside_app_rot : (square_coloring_number4 * 4 = n ^ 4 + n ^ 2 + 2 * n)%N. Proof. rewrite (burnside_formula [:: id1; r1; r2; r3]) => [||p]; last first. - by rewrite !inE !orbA. - by apply: map_uniq (fun p : {perm square} => p c0) _ _; rewrite /= !permE. rewrite !big_cons big_nil /= addn0 {1}card_Fid F_r1 F_r2 F_r3. by rewrite card_n card_n2 //= [n + _]addnC !addnA addn0. Qed. Lemma F_Sd1 : 'Fix_to[sd1] = [set x | coin1 x == coin3 x]. Proof. apply/setP => x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f sd1_inv !ffunE !permE /=. by rewrite !eqxx !andbT eq_sym /= andbb. Qed. Lemma card_n3 : forall x y : square, x != y -> #|[set k : col_squares | k x == k y]| = (n ^ 3)%N. Proof. move=> x y nxy; apply/eqP; case: (posnP n) => [n0|]. by rewrite n0; apply/existsP=> [] [p _]; case: (p c0) => i; rewrite n0. move/eqn_pmul2l <-; rewrite -expnS -card_Fid Fid cardsT. rewrite -{1}[n]card_ord -cardX. pose pk k := [ffun i => k (if i == y then x else i) : colors]. rewrite -(@card_image _ _ (fun k : col_squares => (k y, pk k))). apply/eqP; apply: eq_card => ck /=; rewrite inE /= [_ \in _]inE. apply/eqP/imageP; last first. by case=> k _ -> /=; rewrite !ffunE if_same eqxx. case: ck => c k /= kxy. exists [ffun i => if i == y then c else k i]; first by rewrite inE. rewrite !ffunE eqxx; congr (_, _); apply/ffunP=> i; rewrite !ffunE. case Eiy: (i == y); last by rewrite Eiy. by rewrite (negbTE nxy) (eqP Eiy). move=> k1 k2 [Eky Epk]; apply/ffunP=> i. have{Epk}: pk k1 i = pk k2 i by rewrite Epk. by rewrite !ffunE; case: eqP => // ->. Qed. Lemma F_Sd2 : 'Fix_to[sd2] = [set x | coin0 x == coin2 x]. Proof. apply/setP => x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. by rewrite /act_f sd2_inv !ffunE !permE /= !eqxx !andbT eq_sym /= andbb. Qed. Lemma burnside_app_iso : (square_coloring_number8 * 8 = n ^ 4 + 2 * n ^ 3 + 3 * n ^ 2 + 2 * n)%N. Proof. pose iso_list := [:: id1; r1; r2; r3; sh; sv; sd1; sd2]. rewrite (burnside_formula iso_list) => [||p]; last first. - by rewrite /= !inE. - apply: map_uniq (fun p : {perm square} => (p c0, p c1)) _ _. by rewrite /= !permE. rewrite !big_cons big_nil {1}card_Fid F_r1 F_r2 F_r3 F_Sh F_Sv F_Sd1 F_Sd2. rewrite card_n !card_n3 // !card_n2 //= !addnA !addn0. by rewrite [LHS]addn.[ACl 1 * 7 * 8 * 3 * 5 * 6 * 2 * 4]. Qed. End square_colouring. Section cube_colouring. Definition cube := 'I_6. HB.instance Definition _ := SubType.on cube. HB.instance Definition _ := Finite.on cube. Definition mkFcube i : cube := Sub (i %% 6) (ltn_mod i 6). Definition F0 := mkFcube 0. Definition F1 := mkFcube 1. Definition F2 := mkFcube 2. Definition F3 := mkFcube 3. Definition F4 := mkFcube 4. Definition F5 := mkFcube 5. (* axial symetries*) Definition S05 := [:: F0; F4; F3; F2; F1; F5]. Definition S05f (sc : cube) : cube := tnth [tuple of S05] sc. Definition S14 := [:: F5; F1; F3; F2; F4; F0]. Definition S14f (sc : cube) : cube := tnth [tuple of S14] sc. Definition S23 := [:: F5; F4; F2; F3; F1; F0]. Definition S23f (sc : cube) : cube := tnth [tuple of S23] sc. (* rotations 90 *) Definition R05 := [:: F0; F2; F4; F1; F3; F5]. Definition R05f (sc : cube) : cube := tnth [tuple of R05] sc. Definition R50 := [:: F0; F3; F1; F4; F2; F5]. Definition R50f (sc : cube) : cube := tnth [tuple of R50] sc. Definition R14 := [:: F3; F1; F0; F5; F4; F2]. Definition R14f (sc : cube) : cube := tnth [tuple of R14] sc. Definition R41 := [:: F2; F1; F5; F0; F4; F3]. Definition R41f (sc : cube) : cube := tnth [tuple of R41] sc. Definition R23 := [:: F1; F5; F2; F3; F0; F4]. Definition R23f (sc : cube) : cube := tnth [tuple of R23] sc. Definition R32 := [:: F4; F0; F2; F3; F5; F1]. Definition R32f (sc : cube) : cube := tnth [tuple of R32] sc. (* rotations 120 *) Definition R024 := [:: F2; F5; F4; F1; F0; F3]. Definition R024f (sc : cube) : cube := tnth [tuple of R024] sc. Definition R042 := [:: F4; F3; F0; F5; F2; F1]. Definition R042f (sc : cube) : cube := tnth [tuple of R042] sc. Definition R012 := [:: F1; F2; F0; F5; F3; F4]. Definition R012f (sc : cube) : cube := tnth [tuple of R012] sc. Definition R021 := [:: F2; F0; F1; F4; F5; F3]. Definition R021f (sc : cube) : cube := tnth [tuple of R021] sc. Definition R031 := [:: F3; F0; F4; F1; F5; F2]. Definition R031f (sc : cube) : cube := tnth [tuple of R031] sc. Definition R013 := [:: F1; F3; F5; F0; F2; F4]. Definition R013f (sc : cube) : cube := tnth [tuple of R013] sc. Definition R043 := [:: F4; F2; F5; F0; F3; F1]. Definition R043f (sc : cube) : cube := tnth [tuple of R043] sc. Definition R034 := [:: F3; F5; F1; F4; F0; F2]. Definition R034f (sc : cube) : cube := tnth [tuple of R034] sc. (* last symmetries*) Definition S1 := [:: F5; F2; F1; F4; F3; F0]. Definition S1f (sc : cube) : cube := tnth [tuple of S1] sc. Definition S2 := [:: F5; F3; F4; F1; F2; F0]. Definition S2f (sc : cube) : cube := tnth [tuple of S2] sc. Definition S3 := [:: F1; F0; F3; F2; F5; F4]. Definition S3f (sc : cube) : cube := tnth [tuple of S3] sc. Definition S4 := [:: F4; F5; F3; F2; F0; F1]. Definition S4f (sc : cube) : cube := tnth [tuple of S4] sc. Definition S5 := [:: F2; F4; F0; F5; F1; F3]. Definition S5f (sc : cube) : cube := tnth [tuple of S5] sc. Definition S6 := [::F3; F4; F5; F0; F1; F2]. Definition S6f (sc : cube) : cube := tnth [tuple of S6] sc. Lemma S1_inv : involutive S1f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S2_inv : involutive S2f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S3_inv : involutive S3f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S4_inv : involutive S4f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S5_inv : involutive S5f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S6_inv : involutive S6f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S05_inj : injective S05f. Proof. by apply: can_inj S05f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma S14_inj : injective S14f. Proof. by apply: can_inj S14f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma S23_inv : involutive S23f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma R05_inj : injective R05f. Proof. by apply: can_inj R50f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R14_inj : injective R14f. Proof. by apply: can_inj R41f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R23_inj : injective R23f. Proof. by apply: can_inj R32f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R50_inj : injective R50f. Proof. by apply: can_inj R05f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R41_inj : injective R41f. Proof. by apply: can_inj R14f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R32_inj : injective R32f. Proof. by apply: can_inj R23f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R024_inj : injective R024f. Proof. by apply: can_inj R042f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R042_inj : injective R042f. Proof. by apply: can_inj R024f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R012_inj : injective R012f. Proof. by apply: can_inj R021f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R021_inj : injective R021f. Proof. by apply: can_inj R012f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R031_inj : injective R031f. Proof. by apply: can_inj R013f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R013_inj : injective R013f. Proof. by apply: can_inj R031f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R043_inj : injective R043f. Proof. by apply: can_inj R034f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R034_inj : injective R034f. Proof. by apply: can_inj R043f _ => z; apply/eqP; case: z; do 6?case. Qed. Definition id3 := 1 : {perm cube}. Definition s05 := (perm S05_inj). Definition s14 : {perm cube}. Proof. apply: (@perm _ S14f); apply: can_inj S14f _ => z. by apply/eqP; case: z; do 6?case. Defined. Definition s23 := (perm (inv_inj S23_inv)). Definition r05 := (perm R05_inj). Definition r14 := (perm R14_inj). Definition r23 := (perm R23_inj). Definition r50 := (perm R50_inj). Definition r41 := (perm R41_inj). Definition r32 := (perm R32_inj). Definition r024 := (perm R024_inj). Definition r042 := (perm R042_inj). Definition r012 := (perm R012_inj). Definition r021 := (perm R021_inj). Definition r031 := (perm R031_inj). Definition r013 := (perm R013_inj). Definition r043 := (perm R043_inj). Definition r034 := (perm R034_inj). Definition s1 := (perm (inv_inj S1_inv)). Definition s2 := (perm (inv_inj S2_inv)). Definition s3 := (perm (inv_inj S3_inv)). Definition s4 := (perm (inv_inj S4_inv)). Definition s5 := (perm (inv_inj S5_inv)). Definition s6 := (perm (inv_inj S6_inv)). Definition dir_iso3 := [set p | [|| id3 == p, s05 == p, s14 == p, s23 == p, r05 == p, r14 == p, r23 == p, r50 == p, r41 == p, r32 == p, r024 == p, r042 == p, r012 == p, r021 == p, r031 == p, r013 == p, r043 == p, r034 == p, s1 == p, s2 == p, s3 == p, s4 == p, s5 == p | s6 == p]]. Definition dir_iso3l := [:: id3; s05; s14; s23; r05; r14; r23; r50; r41; r32; r024; r042; r012; r021; r031; r013; r043; r034; s1; s2; s3; s4; s5; s6]. Definition S0 := [:: F5; F4; F3; F2; F1; F0]. Definition S0f (sc : cube) : cube := tnth [tuple of S0] sc. Lemma S0_inv : involutive S0f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Definition s0 := (perm (inv_inj S0_inv)). Definition is_iso3 (p : {perm cube}) := forall fi, p (s0 fi) = s0 (p fi). Lemma dir_iso_iso3 : forall p, p \in dir_iso3 -> is_iso3 p. Proof. move=> p; rewrite inE. by do ?case/orP; move/eqP=> <- a; rewrite !permE; case: a; do 6?case. Qed. Lemma iso3_ndir : forall p, p \in dir_iso3 -> is_iso3 (s0 * p). Proof. move=> p; rewrite inE. by do ?case/orP; move/eqP=> <- a; rewrite !(permM, permE); case: a; do 6?case. Qed. Definition sop (p : {perm cube}) : seq cube := fgraph (val p). Lemma sop_inj : injective sop. Proof. by move=> p1 p2 /val_inj/(can_inj fgraphK)/val_inj. Qed. Definition prod_tuple (t1 t2 : seq cube) := map (fun n : 'I_6 => nth F0 t2 n) t1. Lemma sop_spec x (n0 : 'I_6): nth F0 (sop x) n0 = x n0. Proof. by rewrite nth_fgraph_ord pvalE. Qed. Lemma prod_t_correct : forall (x y : {perm cube}) (i : cube), (x * y) i = nth F0 (prod_tuple (sop x) (sop y)) i. Proof. move=> x y i; rewrite permM -!sop_spec [RHS](nth_map F0) // size_tuple /=. by rewrite card_ord ltn_ord. Qed. Lemma sop_morph : {morph sop : x y / x * y >-> prod_tuple x y}. Proof. move=> x y; apply: (@eq_from_nth _ F0) => [|/= i]. by rewrite size_map !size_tuple. rewrite size_tuple card_ord => lti6. by rewrite -[i]/(val (Ordinal lti6)) sop_spec -prod_t_correct. Qed. Definition ecubes : seq cube := [:: F0; F1; F2; F3; F4; F5]. Lemma ecubes_def : ecubes = enum (@predT cube). Proof. by apply: (inj_map val_inj); rewrite val_enum_ord. Qed. Definition seq_iso_L := [:: [:: F0; F1; F2; F3; F4; F5]; S05; S14; S23; R05; R14; R23; R50; R41; R32; R024; R042; R012; R021; R031; R013; R043; R034; S1; S2; S3; S4; S5; S6]. Lemma seqs1 : forall f injf, sop (@perm _ f injf) = map f ecubes. Proof. move=> f ?; rewrite ecubes_def /sop /= -codom_ffun pvalE. by apply: eq_codom; apply: permE. Qed. Lemma Lcorrect : seq_iso_L == map sop [:: id3; s05; s14; s23; r05; r14; r23; r50; r41; r32; r024; r042; r012; r021; r031; r013; r043; r034; s1; s2; s3; s4; s5; s6]. Proof. by rewrite /= !seqs1. Qed. Lemma iso0_1 : dir_iso3 =i dir_iso3l. Proof. by move=> p; rewrite /= !inE /= -!(eq_sym p). Qed. Lemma L_iso : forall p, (p \in dir_iso3) = (sop p \in seq_iso_L). Proof. by move=> p; rewrite (eqP Lcorrect) mem_map ?iso0_1 //; apply: sop_inj. Qed. Lemma stable : forall x y, x \in dir_iso3 -> y \in dir_iso3 -> x * y \in dir_iso3. Proof. move=> x y; rewrite !L_iso sop_morph => Hx Hy. by move/sop: y Hy; apply/allP; move/sop: x Hx; apply/allP; vm_compute. Qed. Lemma iso_eq_F0_F1 : forall r s : {perm cube}, r \in dir_iso3 -> s \in dir_iso3 -> r F0 = s F0 -> r F1 = s F1 -> r = s. Proof. move=> r s; rewrite !L_iso => hr hs hrs0 hrs1; apply: sop_inj; apply/eqP. move/eqP: hrs0; apply/implyP; move/eqP: hrs1; apply/implyP; rewrite -!sop_spec. by move/sop: r hr; apply/allP; move/sop: s hs; apply/allP; vm_compute. Qed. Lemma ndir_s0p : forall p, p \in dir_iso3 -> s0 * p \notin dir_iso3. Proof. move=> p; rewrite !L_iso sop_morph seqs1. by move/sop: p; apply/allP; vm_compute. Qed. Definition indir_iso3l := map (mulg s0) dir_iso3l. Definition iso3l := dir_iso3l ++ indir_iso3l. Definition seq_iso3_L := map sop iso3l. Lemma eqperm : forall p1 p2 : {perm cube}, (p1 == p2) = all (fun s => p1 s == p2 s) ecubes. Proof. move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/permP=> x. by apply/eqP; rewrite Ep12 // ecubes_def mem_enum. Qed. Lemma iso_eq_F0_F1_F2 : forall r s : {perm cube}, is_iso3 r -> is_iso3 s -> r F0 = s F0 -> r F1 = s F1 -> r F2 = s F2 -> r = s. Proof. move=> r s hr hs hrs0 hrs1 hrs2. have:= hrs0; have:= hrs1; have:= hrs2. have e23: F2 = s0 F3 by apply/eqP; rewrite permE /S0f (tnth_nth F0). have e14: F1 = s0 F4 by apply/eqP; rewrite permE /S0f (tnth_nth F0). have e05: F0 = s0 F5 by apply/eqP; rewrite permE /S0f (tnth_nth F0). rewrite e23 e14 e05; rewrite !hr !hs. move/perm_inj=> hrs3; move/perm_inj=> hrs4; move/perm_inj=> hrs5. by apply/eqP; rewrite eqperm /= hrs0 hrs1 hrs2 hrs3 hrs4 hrs5 !eqxx. Qed. Ltac iso_tac := let a := fresh "a" in apply/permP => a; apply/eqP; rewrite !permM !permE; case: a; do 6?case. Ltac inv_tac := apply: esym (etrans _ (mul1g _)); apply: canRL (mulgK _) _; iso_tac. Lemma dir_s0p : forall p, (s0 * p) \in dir_iso3 -> p \notin dir_iso3. Proof. move=> p Hs0p; move: (ndir_s0p Hs0p); rewrite mulgA. have e: (s0^-1=s0) by inv_tac. by rewrite -{1}e mulVg mul1g. Qed. Definition is_iso3b p := (p * s0 == s0 * p). Definition iso3 := [set p | is_iso3b p]. Lemma is_iso3P : forall p, reflect (is_iso3 p) (p \in iso3). Proof. move=> p; apply: (iffP idP); rewrite inE /iso3 /is_iso3b /is_iso3 => e. by move=> fi; rewrite -!permM (eqP e). by apply/eqP; apply/permP=> z; rewrite !permM (e z). Qed. Lemma group_set_iso3 : group_set iso3. Proof. apply/group_setP; split. by apply/is_iso3P => fi; rewrite -!permM mulg1 mul1g. move=> x1 y; rewrite /iso3 !inE /= /is_iso3. rewrite /is_iso3b. rewrite -mulgA. move/eqP => hx1; move/eqP => hy. rewrite hy !mulgA. by rewrite -hx1. Qed. Canonical iso_group3 := Group group_set_iso3. Lemma group_set_diso3 : group_set dir_iso3. Proof. apply/group_setP; split; first by rewrite inE eqxx /=. by apply: stable. Qed. Canonical diso_group3 := Group group_set_diso3. Lemma gen_diso3 : dir_iso3 = <<[set r05; r14]>>. Proof. apply/setP/subset_eqP/andP; split; first last. rewrite gen_subG; apply/subsetP. by move=> x /[!inE] /orP[] /eqP->; rewrite !eqxx !orbT. apply/subsetP => x /[!inE]. have -> : s05 = r05 * r05 by iso_tac. have -> : s14 = r14 * r14 by iso_tac. have -> : s23 = r14 * r14 * r05 * r05 by iso_tac. have -> : r23 = r05 * r14 * r05 * r14 * r14 by iso_tac. have -> : r50 = r05 * r05 * r05 by iso_tac. have -> : r41 = r14 * r14 * r14 by iso_tac. have -> : r32 = r14 * r14 * r14 * r05* r14 by iso_tac. have -> : r024 = r05 * r14 * r14 * r14 by iso_tac. have -> : r042 = r14 * r05 * r05 * r05 by iso_tac. have -> : r012 = r14 * r05 by iso_tac. have -> : r021 = r05 * r14 * r05 * r05 by iso_tac. have -> : r031 = r05 * r14 by iso_tac. have -> : r013 = r05 * r05 * r14 * r05 by iso_tac. have -> : r043 = r14 * r14 * r14 * r05 by iso_tac. have -> : r034 = r05 * r05 * r05 * r14 by iso_tac. have -> : s1 = r14 * r14 * r05 by iso_tac. have -> : s2 = r05 * r14 * r14 by iso_tac. have -> : s3 = r05 * r14 * r05 by iso_tac. have -> : s4 = r05 * r14 * r14 * r14 * r05 by iso_tac. have -> : s5 = r14 * r05 * r05 by iso_tac. have -> : s6 = r05 * r05 * r14 by iso_tac. by do ?case/predU1P=> [<-|]; first exact: group1; last (move/eqP<-); rewrite ?groupMl ?mem_gen // !inE eqxx ?orbT. Qed. Notation col_cubes := {ffun cube -> colors}. Definition act_g (sc : col_cubes) (p : {perm cube}) : col_cubes := [ffun z => sc (p^-1 z)]. Lemma act_g_1 : forall k, act_g k 1 = k. Proof. by move=> k; apply/ffunP=> a; rewrite ffunE invg1 permE. Qed. Lemma act_g_morph : forall k x y, act_g k (x * y) = act_g (act_g k x) y. Proof. by move=> k x y; apply/ffunP=> a; rewrite !ffunE invMg permE. Qed. Definition to_g := TotalAction act_g_1 act_g_morph. Definition cube_coloring_number24 := #|orbit to_g diso_group3 @: setT|. Lemma Fid3 : 'Fix_to_g[1] = setT. Proof. by apply/setP=> x /=; rewrite (sameP afix1P eqP) !inE act1 eqxx. Qed. Lemma card_Fid3 : #|'Fix_to_g[1]| = (n ^ 6)%N. Proof. rewrite -[6]card_ord -[n]card_ord -card_ffun_on Fid3 cardsT. by symmetry; apply: eq_card => ff; apply/ffun_onP. Qed. Definition col0 (sc : col_cubes) : colors := sc F0. Definition col1 (sc : col_cubes) : colors := sc F1. Definition col2 (sc : col_cubes) : colors := sc F2. Definition col3 (sc : col_cubes) : colors := sc F3. Definition col4 (sc : col_cubes) : colors := sc F4. Definition col5 (sc : col_cubes) : colors := sc F5. Lemma eqperm_map2 : forall p1 p2 : col_cubes, (p1 == p2) = all (fun s => p1 s == p2 s) [:: F0; F1; F2; F3; F4; F5]. Proof. move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/ffunP=> x. by apply/eqP; apply Ep12; case: x; do 6?case. Qed. Notation infE := (sameP afix1P eqP). Lemma F_s05 : 'Fix_to_g[s05] = [set x | (col1 x == col4 x) && (col2 x == col3 x)]. Proof. have s05_inv: s05^-1=s05 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s05_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0. by do 2![rewrite eq_sym; case: {+}(_ == _)=> //= ]. Qed. Lemma F_s14 : 'Fix_to_g[s14]= [set x | (col0 x == col5 x) && (col2 x == col3 x)]. Proof. have s14_inv: s14^-1=s14 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s14_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0. by do 2![rewrite eq_sym; case: {+}(_ == _)=> //= ]. Qed. Lemma r05_inv : r05^-1 = r50. Proof. by inv_tac. Qed. Lemma r50_inv : r50^-1 = r05. Proof. by inv_tac. Qed. Lemma r14_inv : r14^-1 = r41. Proof. by inv_tac. Qed. Lemma r41_inv : r41^-1 = r14. Proof. by inv_tac. Qed. Lemma s23_inv : s23^-1 = s23. Proof. by inv_tac. Qed. Lemma F_s23 : 'Fix_to_g[s23] = [set x | (col0 x == col5 x) && (col1 x == col4 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s23_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0. by do 2![rewrite eq_sym; case: {+}(_ == _)=> //=]. Qed. Lemma F_r05 : 'Fix_to_g[r05]= [set x | (col1 x == col2 x) && (col2 x == col3 x) && (col3 x == col4 x)]. Proof. apply sym_equal. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r05_inv !ffunE !permE /=. rewrite !eqxx /= !andbT /col1/col2/col3/col4/col5/col0. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r50 : 'Fix_to_g[r50]= [set x | (col1 x == col2 x) && (col2 x == col3 x) && (col3 x == col4 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r50_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col1/col2/col3/col4. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r23 : 'Fix_to_g[r23] = [set x | (col0 x == col1 x) && (col1 x == col4 x) && (col4 x == col5 x)]. Proof. have r23_inv: r23^-1 = r32 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r23_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col1/col0/col5/col4. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r32 : 'Fix_to_g[r32] = [set x | (col0 x == col1 x) && (col1 x == col4 x) && (col4 x == col5 x)]. Proof. have r32_inv: r32^-1 = r23 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r32_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col1/col0/col5/col4. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r14 : 'Fix_to_g[r14] = [set x | (col0 x == col2 x) && (col2 x == col3 x) && (col3 x == col5 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r14_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col2/col0/col5/col3. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r41 : 'Fix_to_g[r41] = [set x | (col0 x == col2 x) && (col2 x == col3 x) && (col3 x == col5 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r41_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col2/col0/col5/col3. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r024 : 'Fix_to_g[r024] = [set x | (col0 x == col4 x) && (col4 x == col2 x) && (col1 x == col3 x) && (col3 x == col5 x) ]. Proof. have r024_inv: r024^-1 = r042 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r024_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r042 : 'Fix_to_g[r042] = [set x | (col0 x == col4 x) && (col4 x == col2 x) && (col1 x == col3 x) && (col3 x == col5 x)]. Proof. have r042_inv: r042^-1 = r024 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r042_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r012 : 'Fix_to_g[r012] = [set x | (col0 x == col2 x) && (col2 x == col1 x) && (col3 x == col4 x) && (col4 x == col5 x)]. Proof. have r012_inv: r012^-1 = r021 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r012_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r021 : 'Fix_to_g[r021] = [set x | (col0 x == col2 x) && (col2 x == col1 x) && (col3 x == col4 x) && (col4 x == col5 x)]. Proof. have r021_inv: r021^-1 = r012 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r021_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r031 : 'Fix_to_g[r031] = [set x | (col0 x == col3 x) && (col3 x == col1 x) && (col2 x == col4 x) && (col4 x == col5 x)]. Proof. have r031_inv: r031^-1 = r013 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r031_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r013 : 'Fix_to_g[r013] = [set x | (col0 x == col3 x) && (col3 x == col1 x) && (col2 x == col4 x) && (col4 x == col5 x)]. Proof. have r013_inv: r013^-1 = r031 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r013_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r043 : 'Fix_to_g[r043] = [set x | (col0 x == col4 x) && (col4 x == col3 x) && (col1 x == col2 x) && (col2 x == col5 x)]. Proof. have r043_inv: r043^-1 = r034 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r043_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r034 : 'Fix_to_g[r034] = [set x | (col0 x == col4 x) && (col4 x == col3 x) && (col1 x == col2 x) && (col2 x == col5 x)]. Proof. have r034_inv: r034^-1 = r043 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r034_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s1 : 'Fix_to_g[s1] = [set x | (col0 x == col5 x) && (col1 x == col2 x) && (col3 x == col4 x)]. Proof. have s1_inv: s1^-1 = s1 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s1_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s2 : 'Fix_to_g[s2] = [set x | (col0 x == col5 x) && (col1 x == col3 x) && (col2 x == col4 x)]. Proof. have s2_inv: s2^-1 = s2 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s2_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s3 : 'Fix_to_g[s3] = [set x | (col0 x == col1 x) && (col2 x == col3 x) && (col4 x == col5 x)]. Proof. have s3_inv: s3^-1 = s3 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s3_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s4 : 'Fix_to_g[s4] = [set x | (col0 x == col4 x) && (col1 x == col5 x) && (col2 x == col3 x)]. Proof. have s4_inv: s4^-1 = s4 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s4_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s5 : 'Fix_to_g[s5] = [set x | (col0 x == col2 x) && (col1 x == col4 x) && (col3 x == col5 x)]. Proof. have s5_inv: s5^-1 = s5 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s5_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s6 : 'Fix_to_g[s6] = [set x | (col0 x == col3 x) && (col1 x == col4 x) && (col2 x == col5 x)]. Proof. have s6_inv: s6^-1 = s6 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s6_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma uniq4_uniq6 : forall x y z t : cube, uniq [:: x; y; z; t] -> exists u, exists v, uniq [:: x; y; z; t; u; v]. Proof. move=> x y z t Uxt; move: (cardC [in [:: x; y; z; t]]). rewrite card_ord (card_uniq_tuple Uxt) => hcard. have hcard2: #|[predC [:: x; y; z; t]]| = 2. by apply: (@addnI 4); rewrite /injective hcard. have: #|[predC [:: x; y; z; t]]| != 0 by rewrite hcard2. case/existsP=> u Hu; exists u. move: (cardC [in [:: x; y; z; t; u]]); rewrite card_ord => hcard5. have: #|[predC [:: x; y; z; t; u]]| !=0. rewrite -lt0n -(ltn_add2l #|[:: x; y; z; t; u]|) hcard5 addn0. by apply: (leq_ltn_trans (card_size [:: x; y; z; t; u])). case/existsP => v; rewrite (mem_cat _ [:: _; _; _; _]) => /norP[Hv Huv]. exists v; rewrite (cat_uniq [:: x; y; z; t]) Uxt andTb -rev_uniq /= orbF. by rewrite negb_or Hu Hv Huv. Qed. Lemma card_n4 : forall x y z t : cube, uniq [:: x; y; z; t] -> #|[set p : col_cubes | (p x == p y) && (p z == p t)]| = (n ^ 4)%N. Proof. move=> x y z t Uxt; rewrite -[n]card_ord. case: (uniq4_uniq6 Uxt) => u [v Uxv]. pose ff (p : col_cubes) := (p x, p z, p u, p v). rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE] /andP[p1y p1t] /andP[p2y p2t] [px pz] pu pv. have eqp12 : all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -(eqP p1y) -(eqP p1t) -(eqP p2y) -(eqP p2t) px pz pu pv !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. have -> : forall n, (n ^ 4 = n * n * n * n)%N by move=> ?; rewrite -!mulnA. rewrite -!card_prod; apply: eq_card => [] [[[c d] e] g] /=; apply/imageP => /=. move: Uxv; rewrite (cat_uniq [:: x; y; z; t]) => /and3P[_]/=; rewrite orbF. move=> /norP[] /[!inE] + + /andP[/negPf nuv _]. rewrite orbA => /norP[/negPf nxyu /negPf nztu]. rewrite orbA => /norP[/negPf nxyv /negPf nztv]. move: Uxt; rewrite (cat_uniq [::x; y]) => /and3P[_]/= /[!(andbT, orbF)]. move=> /norP[] /[!inE] /negPf nxyz /negPf nxyt _. exists [ffun i => if pred2 x y i then c else if pred2 z t i then d else if u == i then e else g]. by rewrite !(inE, ffunE, eqxx,orbT)//= nxyz nxyt. by rewrite {}/ff !ffunE /= !eqxx /= nxyz nxyu nztu nxyv nztv nuv. Qed. Lemma card_n3_3 : forall x y z t: cube, uniq [:: x; y; z; t] -> #|[set p : col_cubes | (p x == p y) && (p y == p z)&& (p z == p t)]| = (n ^ 3)%N. Proof. move=> x y z t Uxt; rewrite -[n]card_ord. case: (uniq4_uniq6 Uxt) => u [v Uxv]. pose ff (p : col_cubes) := (p x, p u, p v); rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE]; rewrite -!andbA. move=> /and3P[/eqP p1xy /eqP p1yz /eqP p1zt]. move=> /and3P[/eqP p2xy /eqP p2yz /eqP p2zt] [px pu] pv. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -p1zt -p2zt -p1yz -p2yz -p1xy -p2xy px pu pv !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. have -> : forall n, (n ^ 3 = n * n * n)%N by move=> ?; rewrite -!mulnA. rewrite -!card_prod; apply: eq_card => [] [[c d] e] /=; apply/imageP. move: Uxv; rewrite (cat_uniq [::x; y; z; t]) => /and3P[_ hasxt]. rewrite /uniq !inE !andbT => /negPf nuv. exists [ffun i => if i \in [:: x; y; z; t] then c else if u == i then d else e]. by rewrite /= !(inE, ffunE, eqxx, orbT). rewrite {}/ff !(ffunE, inE, eqxx) /=; move: hasxt; rewrite nuv. by do 8![case E: ( _ == _ ); rewrite ?(eqP E)/= ?inE ?eqxx //= ?E {E}]. Qed. Lemma card_n2_3 : forall x y z t u v: cube, uniq [:: x; y; z; t; u; v] -> #|[set p : col_cubes | (p x == p y) && (p y == p z)&& (p t == p u ) && (p u== p v)]| = (n ^ 2)%N. Proof. move=> x y z t u v Uxv; rewrite -[n]card_ord . pose ff (p : col_cubes) := (p x, p t). rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE]; rewrite -!andbA. move=> /and4P[/eqP p1xy /eqP p1yz /eqP p1tu /eqP p1uv]. move=> /and4P[/eqP p2xy/eqP p2yz /eqP p2tu /eqP p2uv] [px pu]. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -p1yz -p2yz -p1xy -p2xy -p1uv -p2uv -p1tu -p2tu px pu !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. rewrite -mulnn -!card_prod; apply: eq_card => [] [c d]/=; apply/imageP. move: Uxv; rewrite (cat_uniq [::x; y; z]) => /= /and3P[Uxt + nuv]. move=> /[!orbF] /norP[] /[!inE] /negPf nxyzt /norP[/negPf nxyzu /negPf nxyzv]. exists [ffun i => if (i \in [:: x; y; z] ) then c else d]. by rewrite /= !(inE, ffunE, eqxx, orbT, nxyzt, nxyzu, nxyzv). by rewrite {}/ff !ffunE !inE /= !eqxx /= nxyzt. Qed. Lemma card_n3s : forall x y z t u v: cube, uniq [:: x; y; z; t; u; v] -> #|[set p : col_cubes | (p x == p y) && (p z == p t)&& (p u == p v )]| = (n ^ 3)%N. Proof. move=> x y z t u v Uxv; rewrite -[n]card_ord . pose ff (p : col_cubes) := (p x, p z, p u). rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE]; rewrite -!andbA. move=> /and3P[/eqP p1xy /eqP p1zt /eqP p1uv]. move=> /and3P[/eqP p2xy /eqP p2zt /eqP p2uv] [px pz] pu. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -p1xy -p2xy -p1zt -p2zt -p1uv -p2uv px pz pu !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. have -> : forall n, (n ^ 3 = n * n * n)%N by move=> ?; rewrite -!mulnA. rewrite -!card_prod; apply: eq_card => [] [[c d] e] /=; apply/imageP. move: Uxv; rewrite (cat_uniq [::x; y; z; t]) => /and3P[Uxt + nuv]. move=> /= /[!orbF] /norP[] /[!inE]. rewrite orbA => /norP[/negPf nxyu /negPf nztu]. rewrite orbA => /norP[/negPf nxyv /negPf nztv]. move: Uxt; rewrite (cat_uniq [::x; y]) => /and3P[_]. rewrite /= !orbF !andbT => /norP[] /[!inE] /negPf nxyz /negPf nxyt _. exists [ffun i => if i \in [:: x; y] then c else if i \in [:: z; t] then d else e]. by rewrite !(inE, ffunE, eqxx,orbT)//= nxyz nxyt nxyu nztu nxyv nztv !eqxx. by rewrite {}/ff !ffunE !inE /= !eqxx nxyz nxyu nztu. Qed. Lemma burnside_app_iso3 : (cube_coloring_number24 * 24 = n ^ 6 + 6 * n ^ 3 + 3 * n ^ 4 + 8 * (n ^ 2) + 6 * n ^ 3)%N. Proof. pose iso_list := [:: id3; s05; s14; s23; r05; r14; r23; r50; r41; r32; r024; r042; r012; r021; r031; r013; r043; r034; s1; s2; s3; s4; s5; s6]. rewrite (burnside_formula iso_list); last first. - by move=> p; rewrite !inE /= !(eq_sym _ p). - apply: map_uniq (fun p : {perm cube} => (p F0, p F1)) _ _. have bsr : (fun p : {perm cube} => (p F0, p F1)) =1 (fun p => (nth F0 p F0, nth F0 p F1)) \o sop. by move=> x; rewrite /= -2!sop_spec. by rewrite (eq_map bsr) map_comp -(eqP Lcorrect); vm_compute. rewrite !big_cons big_nil {1}card_Fid3 /= F_s05 F_s14 F_s23 F_r05 F_r14 F_r23 F_r50 F_r41 F_r32 F_r024 F_r042 F_r012 F_r021 F_r031 F_r013 F_r043 F_r034 F_s1 F_s2 F_s3 F_s4 F_s5 F_s6. rewrite !card_n4 // !card_n3_3 // !card_n2_3 // !card_n3s //. by rewrite [RHS]addn.[ACl 1 * 3 * 2 * 4 * 5] !addnA !addn0. Qed. End cube_colouring. End colouring. Corollary burnside_app_iso_3_3col: cube_coloring_number24 3 = 57. Proof. by apply/eqP; rewrite -(@eqn_pmul2r 24) // burnside_app_iso3. Qed. Corollary burnside_app_iso_2_4col: square_coloring_number8 4 = 55. Proof. by apply/eqP; rewrite -(@eqn_pmul2r 8) // burnside_app_iso. Qed.
NormPow.lean
/- Copyright (c) 2024 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Calculus import Mathlib.Analysis.SpecialFunctions.Pow.Deriv /-! # Properties about the powers of the norm In this file we prove that `x ↦ ‖x‖ ^ p` is continuously differentiable for an inner product space and for a real number `p > 1`. ## TODO * `x ↦ ‖x‖ ^ p` should be `C^n` for `p > n`. -/ section ContDiffNormPow open Asymptotics Real Topology open scoped NNReal variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] theorem hasFDerivAt_norm_rpow (x : E) {p : ℝ} (hp : 1 < p) : HasFDerivAt (fun x : E ↦ ‖x‖ ^ p) ((p * ‖x‖ ^ (p - 2)) • innerSL ℝ x) x := by by_cases hx : x = 0 · simp only [hx, norm_zero, map_zero, smul_zero] have h2p : 0 < p - 1 := sub_pos.mpr hp rw [HasFDerivAt, hasFDerivAtFilter_iff_isLittleO] calc (fun x : E ↦ ‖x‖ ^ p - ‖(0 : E)‖ ^ p - 0) = (fun x : E ↦ ‖x‖ ^ p) := by simp [zero_lt_one.trans hp |>.ne'] _ = (fun x : E ↦ ‖x‖ * ‖x‖ ^ (p - 1)) := by ext x rw [← rpow_one_add' (norm_nonneg x) (by positivity)] ring_nf _ =o[𝓝 0] (fun x : E ↦ ‖x‖ * 1) := by refine (isBigO_refl _ _).mul_isLittleO <| (isLittleO_const_iff <| by simp).mpr ?_ convert continuousAt_id.norm.rpow_const (.inr h2p.le) |>.tendsto simp [h2p.ne'] _ =O[𝓝 0] (fun (x : E) ↦ x - 0) := by simp_rw [mul_one, isBigO_norm_left (f' := fun x ↦ x), sub_zero, isBigO_refl] · apply HasStrictFDerivAt.hasFDerivAt convert (hasStrictFDerivAt_norm_sq x).rpow_const (p := p / 2) (by simp [hx]) using 0 simp_rw [← Real.rpow_natCast_mul (norm_nonneg _), ← Nat.cast_smul_eq_nsmul ℝ, smul_smul] ring_nf theorem differentiable_norm_rpow {p : ℝ} (hp : 1 < p) : Differentiable ℝ (fun x : E ↦ ‖x‖ ^ p) := fun x ↦ hasFDerivAt_norm_rpow x hp |>.differentiableAt theorem hasDerivAt_norm_rpow (x : ℝ) {p : ℝ} (hp : 1 < p) : HasDerivAt (fun x : ℝ ↦ ‖x‖ ^ p) (p * ‖x‖ ^ (p - 2) * x) x := by convert hasFDerivAt_norm_rpow x hp |>.hasDerivAt using 1; simp theorem hasDerivAt_abs_rpow (x : ℝ) {p : ℝ} (hp : 1 < p) : HasDerivAt (fun x : ℝ ↦ |x| ^ p) (p * |x| ^ (p - 2) * x) x := by simpa using hasDerivAt_norm_rpow x hp theorem fderiv_norm_rpow (x : E) {p : ℝ} (hp : 1 < p) : fderiv ℝ (fun x ↦ ‖x‖ ^ p) x = (p * ‖x‖ ^ (p - 2)) • innerSL ℝ x := hasFDerivAt_norm_rpow x hp |>.fderiv theorem Differentiable.fderiv_norm_rpow {f : F → E} (hf : Differentiable ℝ f) {x : F} {p : ℝ} (hp : 1 < p) : fderiv ℝ (fun x ↦ ‖f x‖ ^ p) x = (p * ‖f x‖ ^ (p - 2)) • (innerSL ℝ (f x)).comp (fderiv ℝ f x) := hasFDerivAt_norm_rpow (f x) hp |>.comp x (hf x).hasFDerivAt |>.fderiv theorem norm_fderiv_norm_rpow_le {f : F → E} (hf : Differentiable ℝ f) {x : F} {p : ℝ} (hp : 1 < p) : ‖fderiv ℝ (fun x ↦ ‖f x‖ ^ p) x‖ ≤ p * ‖f x‖ ^ (p - 1) * ‖fderiv ℝ f x‖ := by rw [hf.fderiv_norm_rpow hp, norm_smul, norm_mul] simp_rw [norm_rpow_of_nonneg (norm_nonneg _), norm_norm, norm_eq_abs, abs_eq_self.mpr <| zero_le_one.trans hp.le, mul_assoc] gcongr _ * ?_ refine mul_le_mul_of_nonneg_left (ContinuousLinearMap.opNorm_comp_le ..) (by positivity) |>.trans_eq ?_ rw [innerSL_apply_norm, ← mul_assoc, ← Real.rpow_add_one' (by positivity) (by linarith)] ring_nf theorem norm_fderiv_norm_id_rpow (x : E) {p : ℝ} (hp : 1 < p) : ‖fderiv ℝ (fun x ↦ ‖x‖ ^ p) x‖ = p * ‖x‖ ^ (p - 1) := by rw [fderiv_norm_rpow x hp, norm_smul, norm_mul] simp_rw [norm_rpow_of_nonneg (norm_nonneg _), norm_norm, norm_eq_abs, abs_eq_self.mpr <| zero_le_one.trans hp.le, mul_assoc, innerSL_apply_norm] rw [← Real.rpow_add_one' (by positivity) (by linarith)] ring_nf theorem nnnorm_fderiv_norm_rpow_le {f : F → E} (hf : Differentiable ℝ f) {x : F} {p : ℝ≥0} (hp : 1 < p) : ‖fderiv ℝ (fun x ↦ ‖f x‖ ^ (p : ℝ)) x‖₊ ≤ p * ‖f x‖₊ ^ ((p : ℝ) - 1) * ‖fderiv ℝ f x‖₊ := norm_fderiv_norm_rpow_le hf hp lemma enorm_fderiv_norm_rpow_le {f : F → E} (hf : Differentiable ℝ f) {x : F} {p : ℝ≥0} (hp : 1 < p) : ‖fderiv ℝ (fun x ↦ ‖f x‖ ^ (p : ℝ)) x‖ₑ ≤ p * ‖f x‖ₑ ^ ((p : ℝ) - 1) * ‖fderiv ℝ f x‖ₑ := by simpa [enorm, ← ENNReal.coe_rpow_of_nonneg _ (sub_nonneg.2 <| NNReal.one_le_coe.2 hp.le), ← ENNReal.coe_mul] using nnnorm_fderiv_norm_rpow_le hf hp theorem contDiff_norm_rpow {p : ℝ} (hp : 1 < p) : ContDiff ℝ 1 (fun x : E ↦ ‖x‖ ^ p) := by rw [contDiff_one_iff_fderiv] refine ⟨fun x ↦ hasFDerivAt_norm_rpow x hp |>.differentiableAt, ?_⟩ simp_rw [continuous_iff_continuousAt] intro x by_cases hx : x = 0 · simp_rw [hx, ContinuousAt, fderiv_norm_rpow (0 : E) hp, norm_zero, map_zero, smul_zero] rw [tendsto_zero_iff_norm_tendsto_zero] refine tendsto_of_tendsto_of_tendsto_of_le_of_le (tendsto_const_nhds) ?_ (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_fderiv_norm_id_rpow _ hp |>.le) suffices ContinuousAt (fun x : E ↦ p * ‖x‖ ^ (p - 1)) 0 by simpa [ContinuousAt, sub_ne_zero_of_ne hp.ne'] using this fun_prop (discharger := simp [hp.le]) · simp_rw [funext fun x ↦ fderiv_norm_rpow (E := E) (x := x) hp] fun_prop (discharger := simp [hx]) theorem ContDiff.norm_rpow {f : F → E} (hf : ContDiff ℝ 1 f) {p : ℝ} (hp : 1 < p) : ContDiff ℝ 1 (fun x ↦ ‖f x‖ ^ p) := contDiff_norm_rpow hp |>.comp hf theorem Differentiable.norm_rpow {f : F → E} (hf : Differentiable ℝ f) {p : ℝ} (hp : 1 < p) : Differentiable ℝ (fun x ↦ ‖f x‖ ^ p) := contDiff_norm_rpow hp |>.differentiable le_rfl |>.comp hf end ContDiffNormPow
WithSeminorms.lean
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Anatole Dedecker -/ import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.Seminorm import Mathlib.Data.Real.Sqrt import Mathlib.Topology.Algebra.Equicontinuity import Mathlib.Topology.MetricSpace.Equicontinuity import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.Module.LocallyConvex /-! # Topology induced by a family of seminorms ## Main definitions * `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms. * `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls. * `Seminorm.IsBounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be bounded by a finite number of seminorms in `E`. ## Main statements * `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally convex. * `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a countable family of seminorms. ## Continuity of semilinear maps If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then we have a direct method to prove that a linear map is continuous: * `Seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous. If the topology of a space `E` is induced by a family of seminorms, then we can characterize von Neumann boundedness in terms of that seminorm family. Together with `LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity. * `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.isVonNBounded_iff_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded` ## Tags seminorm, locally convex -/ open NormedField Set Seminorm TopologicalSpace Filter List Bornology open NNReal Pointwise Topology Uniformity variable {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*} section FilterBasis variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable (𝕜 E ι) /-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/ abbrev SeminormFamily := ι → Seminorm 𝕜 E variable {𝕜 E ι} namespace SeminormFamily /-- The sets of a filter basis for the neighborhood filter of 0. -/ def basisSets (p : SeminormFamily 𝕜 E ι) : Set (Set E) := ⋃ (s : Finset ι) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r) variable (p : SeminormFamily 𝕜 E ι) theorem basisSets_iff {U : Set E} : U ∈ p.basisSets ↔ ∃ (i : Finset ι) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff] theorem basisSets_mem (i : Finset ι) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨i, _, hr, rfl⟩ theorem basisSets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩ theorem basisSets_univ_mem : univ ∈ p.basisSets := (basisSets_iff _).mpr ⟨∅, _, one_pos, by rw [Finset.sup_empty, Seminorm.bot_eq_zero, ball_zero' _ one_pos]⟩ theorem basisSets_nonempty : p.basisSets.Nonempty := by refine nonempty_def.mpr ⟨univ, basisSets_univ_mem _⟩ theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) : ∃ z ∈ p.basisSets, z ⊆ U ∩ V := by classical rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩ rcases p.basisSets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩ use ((s ∪ t).sup p).ball 0 (min r₁ r₂) refine ⟨p.basisSets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ?_⟩ rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hr₂] exact Set.subset_inter (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩) (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩) theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩ rw [hU, mem_ball_zero, map_zero] exact hr theorem basisSets_add (U) (hU : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V + V ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ use (s.sup p).ball 0 (r / 2) refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩ refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_ rw [hU, add_zero, add_halves] theorem basisSets_neg (U) (hU' : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V ⊆ (fun x : E => -x) ⁻¹' U := by rcases p.basisSets_iff.mp hU' with ⟨s, r, _, hU⟩ rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero] exact ⟨U, hU', Eq.subset hU⟩ /-- The `addGroupFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/ protected def addGroupFilterBasis : AddGroupFilterBasis E := addGroupFilterBasisOfComm p.basisSets p.basisSets_nonempty p.basisSets_intersect p.basisSets_zero p.basisSets_add p.basisSets_neg theorem basisSets_smul_right (v : E) (U : Set E) (hU : U ∈ p.basisSets) : ∀ᶠ x : 𝕜 in 𝓝 0, x • v ∈ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU, Filter.eventually_iff] simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul] by_cases h : 0 < (s.sup p) v · simp_rw [(lt_div_iff₀ h).symm] rw [← _root_.ball_zero_eq] exact Metric.ball_mem_nhds 0 (div_pos hr h) simp_rw [le_antisymm (not_lt.mp h) (apply_nonneg _ v), mul_zero, hr] exact IsOpen.mem_nhds isOpen_univ (mem_univ 0) theorem basisSets_smul (U) (hU : U ∈ p.basisSets) : ∃ V ∈ 𝓝 (0 : 𝕜), ∃ W ∈ p.addGroupFilterBasis.sets, V • W ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ refine ⟨Metric.ball 0 √r, Metric.ball_mem_nhds 0 (Real.sqrt_pos.mpr hr), ?_⟩ refine ⟨(s.sup p).ball 0 √r, p.basisSets_mem s (Real.sqrt_pos.mpr hr), ?_⟩ refine Set.Subset.trans (ball_smul_ball (s.sup p) √r √r) ?_ rw [hU, Real.mul_self_sqrt (le_of_lt hr)] theorem basisSets_smul_left (x : 𝕜) (U : Set E) (hU : U ∈ p.basisSets) : ∃ V ∈ p.addGroupFilterBasis.sets, V ⊆ (fun y : E => x • y) ⁻¹' U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU] by_cases h : x ≠ 0 · rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero] use (s.sup p).ball 0 (r / ‖x‖) exact ⟨p.basisSets_mem s (div_pos hr (norm_pos_iff.mpr h)), Subset.rfl⟩ refine ⟨(s.sup p).ball 0 r, p.basisSets_mem s hr, ?_⟩ simp only [not_ne_iff.mp h, Set.subset_def, mem_ball_zero, hr, mem_univ, map_zero, imp_true_iff, preimage_const_of_mem, zero_smul] /-- The `moduleFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/ protected def moduleFilterBasis : ModuleFilterBasis 𝕜 E where toAddGroupFilterBasis := p.addGroupFilterBasis smul' := p.basisSets_smul _ smul_left' := p.basisSets_smul_left smul_right' := p.basisSets_smul_right theorem filter_eq_iInf (p : SeminormFamily 𝕜 E ι) : p.moduleFilterBasis.toFilterBasis.filter = ⨅ i, (𝓝 0).comap (p i) := by refine le_antisymm (le_iInf fun i => ?_) ?_ · rw [p.moduleFilterBasis.toFilterBasis.hasBasis.le_basis_iff (Metric.nhds_basis_ball.comap _)] intro ε hε refine ⟨(p i).ball 0 ε, ?_, ?_⟩ · rw [← (Finset.sup_singleton : _ = p i)] exact p.basisSets_mem {i} hε · rw [id, (p i).ball_zero_eq_preimage_ball] · rw [p.moduleFilterBasis.toFilterBasis.hasBasis.ge_iff] rintro U (hU : U ∈ p.basisSets) rcases p.basisSets_iff.mp hU with ⟨s, r, hr, rfl⟩ rw [id, Seminorm.ball_finset_sup_eq_iInter _ _ _ hr, s.iInter_mem_sets] exact fun i _ => Filter.mem_iInf_of_mem i ⟨Metric.ball 0 r, Metric.ball_mem_nhds 0 hr, Eq.subset (p i).ball_zero_eq_preimage_ball.symm⟩ /-- If a family of seminorms is continuous, then their basis sets are neighborhoods of zero. -/ lemma basisSets_mem_nhds {𝕜 E ι : Type*} [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] (p : SeminormFamily 𝕜 E ι) (hp : ∀ i, Continuous (p i)) (U : Set E) (hU : U ∈ p.basisSets) : U ∈ 𝓝 (0 : E) := by obtain ⟨s, r, hr, rfl⟩ := p.basisSets_iff.mp hU clear hU refine Seminorm.ball_mem_nhds ?_ hr classical induction s using Finset.induction_on with | empty => simpa using continuous_zero | insert a s _ hs => simp only [Finset.sup_insert, coe_sup] exact Continuous.max (hp a) hs end SeminormFamily end FilterBasis section Bounded namespace Seminorm variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [NormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] -- Todo: This should be phrased entirely in terms of the von Neumann bornology. /-- The proposition that a linear map is bounded between spaces with families of seminorms. -/ def IsBounded (p : ι → Seminorm 𝕜 E) (q : ι' → Seminorm 𝕜₂ F) (f : E →ₛₗ[σ₁₂] F) : Prop := ∀ i, ∃ s : Finset ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • s.sup p theorem isBounded_const (ι' : Type*) [Nonempty ι'] {p : ι → Seminorm 𝕜 E} {q : Seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) : IsBounded p (fun _ : ι' => q) f ↔ ∃ (s : Finset ι) (C : ℝ≥0), q.comp f ≤ C • s.sup p := by simp only [IsBounded, forall_const] theorem const_isBounded (ι : Type*) [Nonempty ι] {p : Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) : IsBounded (fun _ : ι => p) q f ↔ ∀ i, ∃ C : ℝ≥0, (q i).comp f ≤ C • p := by constructor <;> intro h i · rcases h i with ⟨s, C, h⟩ exact ⟨C, le_trans h (smul_le_smul (Finset.sup_le fun _ _ => le_rfl) le_rfl)⟩ use {Classical.arbitrary ι} simp only [h, Finset.sup_singleton] theorem isBounded_sup {p : ι → Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} {f : E →ₛₗ[σ₁₂] F} (hf : IsBounded p q f) (s' : Finset ι') : ∃ (C : ℝ≥0) (s : Finset ι), (s'.sup q).comp f ≤ C • s.sup p := by classical obtain rfl | _ := s'.eq_empty_or_nonempty · exact ⟨1, ∅, by simp [Seminorm.bot_eq_zero]⟩ choose fₛ fC hf using hf use s'.card • s'.sup fC, Finset.biUnion s' fₛ have hs : ∀ i : ι', i ∈ s' → (q i).comp f ≤ s'.sup fC • (Finset.biUnion s' fₛ).sup p := by intro i hi refine (hf i).trans (smul_le_smul ?_ (Finset.le_sup hi)) exact Finset.sup_mono (Finset.subset_biUnion_of_mem fₛ hi) refine (comp_mono f (finset_sup_le_sum q s')).trans ?_ simp_rw [← pullback_apply, map_sum, pullback_apply] refine (Finset.sum_le_sum hs).trans ?_ rw [Finset.sum_const, smul_assoc] end Seminorm end Bounded section Topology variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] /-- The proposition that the topology of `E` is induced by a family of seminorms `p`. -/ structure WithSeminorms (p : SeminormFamily 𝕜 E ι) [topology : TopologicalSpace E] : Prop where topology_eq_withSeminorms : topology = p.moduleFilterBasis.topology theorem WithSeminorms.withSeminorms_eq {p : SeminormFamily 𝕜 E ι} [t : TopologicalSpace E] (hp : WithSeminorms p) : t = p.moduleFilterBasis.topology := hp.1 variable [TopologicalSpace E] variable {p : SeminormFamily 𝕜 E ι} theorem WithSeminorms.topologicalAddGroup (hp : WithSeminorms p) : IsTopologicalAddGroup E := by rw [hp.withSeminorms_eq] exact AddGroupFilterBasis.isTopologicalAddGroup _ theorem WithSeminorms.continuousSMul (hp : WithSeminorms p) : ContinuousSMul 𝕜 E := by rw [hp.withSeminorms_eq] exact ModuleFilterBasis.continuousSMul _ theorem WithSeminorms.hasBasis (hp : WithSeminorms p) : (𝓝 (0 : E)).HasBasis (fun s : Set E => s ∈ p.basisSets) id := by rw [congr_fun (congr_arg (@nhds E) hp.1) 0] exact AddGroupFilterBasis.nhds_zero_hasBasis _ theorem WithSeminorms.hasBasis_zero_ball (hp : WithSeminorms p) : (𝓝 (0 : E)).HasBasis (fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball 0 sr.2 := by refine ⟨fun V => ?_⟩ simp only [hp.hasBasis.mem_iff, SeminormFamily.basisSets_iff, Prod.exists] grind theorem WithSeminorms.hasBasis_ball (hp : WithSeminorms p) {x : E} : (𝓝 (x : E)).HasBasis (fun sr : Finset ι × ℝ => 0 < sr.2) fun sr => (sr.1.sup p).ball x sr.2 := by have : IsTopologicalAddGroup E := hp.topologicalAddGroup rw [← map_add_left_nhds_zero] convert hp.hasBasis_zero_ball.map (x + ·) using 1 ext sr : 1 -- Porting note: extra type ascriptions needed on `0` have : (sr.fst.sup p).ball (x +ᵥ (0 : E)) sr.snd = x +ᵥ (sr.fst.sup p).ball 0 sr.snd := Eq.symm (Seminorm.vadd_ball (sr.fst.sup p)) rwa [vadd_eq_add, add_zero] at this /-- The `x`-neighbourhoods of a space whose topology is induced by a family of seminorms are exactly the sets which contain seminorm balls around `x`. -/ theorem WithSeminorms.mem_nhds_iff (hp : WithSeminorms p) (x : E) (U : Set E) : U ∈ 𝓝 x ↔ ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by rw [hp.hasBasis_ball.mem_iff, Prod.exists] /-- The open sets of a space whose topology is induced by a family of seminorms are exactly the sets which contain seminorm balls around all of their points. -/ theorem WithSeminorms.isOpen_iff_mem_balls (hp : WithSeminorms p) (U : Set E) : IsOpen U ↔ ∀ x ∈ U, ∃ s : Finset ι, ∃ r > 0, (s.sup p).ball x r ⊆ U := by simp_rw [← WithSeminorms.mem_nhds_iff hp _ U, isOpen_iff_mem_nhds] /- Note that through the following lemmas, one also immediately has that separating families of seminorms induce T₂ and T₃ topologies by `IsTopologicalAddGroup.t2Space` and `IsTopologicalAddGroup.t3Space` -/ /-- A separating family of seminorms induces a T₁ topology. -/ theorem WithSeminorms.T1_of_separating (hp : WithSeminorms p) (h : ∀ x, x ≠ 0 → ∃ i, p i x ≠ 0) : T1Space E := by have := hp.topologicalAddGroup refine IsTopologicalAddGroup.t1Space _ ?_ rw [← isOpen_compl_iff, hp.isOpen_iff_mem_balls] rintro x (hx : x ≠ 0) obtain ⟨i, pi_nonzero⟩ := h x hx refine ⟨{i}, p i x, by positivity, subset_compl_singleton_iff.mpr ?_⟩ rw [Finset.sup_singleton, mem_ball, zero_sub, map_neg_eq_map, not_lt] /-- A family of seminorms inducing a T₁ topology is separating. -/ theorem WithSeminorms.separating_of_T1 [T1Space E] (hp : WithSeminorms p) (x : E) (hx : x ≠ 0) : ∃ i, p i x ≠ 0 := by have := ((t1Space_TFAE E).out 0 9).mp (inferInstanceAs <| T1Space E) by_contra! h refine hx (this ?_) rw [hp.hasBasis_zero_ball.specializes_iff] rintro ⟨s, r⟩ (hr : 0 < r) simp only [ball_finset_sup_eq_iInter _ _ _ hr, mem_iInter₂, mem_ball_zero, h, hr, forall_true_iff] /-- A family of seminorms is separating iff it induces a T₁ topology. -/ theorem WithSeminorms.separating_iff_T1 (hp : WithSeminorms p) : (∀ x, x ≠ 0 → ∃ i, p i x ≠ 0) ↔ T1Space E := by refine ⟨WithSeminorms.T1_of_separating hp, ?_⟩ intro exact WithSeminorms.separating_of_T1 hp end Topology section Tendsto variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] variable {p : SeminormFamily 𝕜 E ι} /-- Convergence along filters for `WithSeminorms`. Variant with `Finset.sup`. -/ theorem WithSeminorms.tendsto_nhds' (hp : WithSeminorms p) (u : F → E) {f : Filter F} (y₀ : E) : Filter.Tendsto u f (𝓝 y₀) ↔ ∀ (s : Finset ι) (ε), 0 < ε → ∀ᶠ x in f, s.sup p (u x - y₀) < ε := by simp [hp.hasBasis_ball.tendsto_right_iff] /-- Convergence along filters for `WithSeminorms`. -/ theorem WithSeminorms.tendsto_nhds (hp : WithSeminorms p) (u : F → E) {f : Filter F} (y₀ : E) : Filter.Tendsto u f (𝓝 y₀) ↔ ∀ i ε, 0 < ε → ∀ᶠ x in f, p i (u x - y₀) < ε := by rw [hp.tendsto_nhds' u y₀] exact ⟨fun h i => by simpa only [Finset.sup_singleton] using h {i}, fun h s ε hε => (s.eventually_all.2 fun i _ => h i ε hε).mono fun _ => finset_sup_apply_lt hε⟩ variable [SemilatticeSup F] [Nonempty F] /-- Limit `→ ∞` for `WithSeminorms`. -/ theorem WithSeminorms.tendsto_nhds_atTop (hp : WithSeminorms p) (u : F → E) (y₀ : E) : Filter.Tendsto u Filter.atTop (𝓝 y₀) ↔ ∀ i ε, 0 < ε → ∃ x₀, ∀ x, x₀ ≤ x → p i (u x - y₀) < ε := by rw [hp.tendsto_nhds u y₀] exact forall₃_congr fun _ _ _ => Filter.eventually_atTop end Tendsto section IsTopologicalAddGroup variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] section TopologicalSpace variable [t : TopologicalSpace E] theorem SeminormFamily.withSeminorms_of_nhds [IsTopologicalAddGroup E] (p : SeminormFamily 𝕜 E ι) (h : 𝓝 (0 : E) = p.moduleFilterBasis.toFilterBasis.filter) : WithSeminorms p := by refine ⟨IsTopologicalAddGroup.ext inferInstance p.addGroupFilterBasis.isTopologicalAddGroup ?_⟩ rw [AddGroupFilterBasis.nhds_zero_eq] exact h theorem SeminormFamily.withSeminorms_of_hasBasis [IsTopologicalAddGroup E] (p : SeminormFamily 𝕜 E ι) (h : (𝓝 (0 : E)).HasBasis (fun s : Set E => s ∈ p.basisSets) id) : WithSeminorms p := p.withSeminorms_of_nhds <| Filter.HasBasis.eq_of_same_basis h p.addGroupFilterBasis.toFilterBasis.hasBasis theorem SeminormFamily.withSeminorms_iff_nhds_eq_iInf [IsTopologicalAddGroup E] (p : SeminormFamily 𝕜 E ι) : WithSeminorms p ↔ (𝓝 (0 : E)) = ⨅ i, (𝓝 0).comap (p i) := by rw [← p.filter_eq_iInf] refine ⟨fun h => ?_, p.withSeminorms_of_nhds⟩ rw [h.topology_eq_withSeminorms] exact AddGroupFilterBasis.nhds_zero_eq _ /-- The topology induced by a family of seminorms is exactly the infimum of the ones induced by each seminorm individually. We express this as a characterization of `WithSeminorms p`. -/ theorem SeminormFamily.withSeminorms_iff_topologicalSpace_eq_iInf [IsTopologicalAddGroup E] (p : SeminormFamily 𝕜 E ι) : WithSeminorms p ↔ t = ⨅ i, (p i).toSeminormedAddCommGroup.toUniformSpace.toTopologicalSpace := by rw [p.withSeminorms_iff_nhds_eq_iInf, IsTopologicalAddGroup.ext_iff inferInstance (topologicalAddGroup_iInf fun i => inferInstance), nhds_iInf] congrm _ = ⨅ i, ?_ exact @comap_norm_nhds_zero _ (p i).toSeminormedAddGroup theorem WithSeminorms.continuous_seminorm {p : SeminormFamily 𝕜 E ι} (hp : WithSeminorms p) (i : ι) : Continuous (p i) := by have := hp.topologicalAddGroup rw [p.withSeminorms_iff_topologicalSpace_eq_iInf.mp hp] exact continuous_iInf_dom (@continuous_norm _ (p i).toSeminormedAddGroup) end TopologicalSpace /-- The uniform structure induced by a family of seminorms is exactly the infimum of the ones induced by each seminorm individually. We express this as a characterization of `WithSeminorms p`. -/ theorem SeminormFamily.withSeminorms_iff_uniformSpace_eq_iInf [u : UniformSpace E] [IsUniformAddGroup E] (p : SeminormFamily 𝕜 E ι) : WithSeminorms p ↔ u = ⨅ i, (p i).toSeminormedAddCommGroup.toUniformSpace := by rw [p.withSeminorms_iff_nhds_eq_iInf, IsUniformAddGroup.ext_iff inferInstance (isUniformAddGroup_iInf fun i => inferInstance), UniformSpace.toTopologicalSpace_iInf, nhds_iInf] congrm _ = ⨅ i, ?_ exact @comap_norm_nhds_zero _ (p i).toAddGroupSeminorm.toSeminormedAddGroup end IsTopologicalAddGroup section NormedSpace /-- The topology of a `NormedSpace 𝕜 E` is induced by the seminorm `normSeminorm 𝕜 E`. -/ theorem norm_withSeminorms (𝕜 E) [NormedField 𝕜] [SeminormedAddCommGroup E] [NormedSpace 𝕜 E] : WithSeminorms fun _ : Fin 1 => normSeminorm 𝕜 E := by rw [SeminormFamily.withSeminorms_iff_nhds_eq_iInf, iInf_const, ← comap_norm_nhds_zero] rfl end NormedSpace section NontriviallyNormedField variable [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable {p : SeminormFamily 𝕜 E ι} variable [TopologicalSpace E] theorem WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded {s : Set E} (hp : WithSeminorms p) : IsVonNBounded 𝕜 s ↔ ∀ I : Finset ι, ∃ r > 0, ∀ x ∈ s, I.sup p x < r := by rw [hp.hasBasis.isVonNBounded_iff] constructor · intro h I simp only [id] at h specialize h ((I.sup p).ball 0 1) (p.basisSets_mem I zero_lt_one) rcases h.exists_pos with ⟨r, hr, h⟩ obtain ⟨a, ha⟩ := NormedField.exists_lt_norm 𝕜 r specialize h a (le_of_lt ha) rw [Seminorm.smul_ball_zero (norm_pos_iff.1 <| hr.trans ha), mul_one] at h refine ⟨‖a‖, lt_trans hr ha, ?_⟩ intro x hx specialize h hx exact (Finset.sup I p).mem_ball_zero.mp h intro h s' hs' rcases p.basisSets_iff.mp hs' with ⟨I, r, hr, hs'⟩ rw [id, hs'] rcases h I with ⟨r', _, h'⟩ simp_rw [← (I.sup p).mem_ball_zero] at h' refine Absorbs.mono_right ?_ h' exact (Finset.sup I p).ball_zero_absorbs_ball_zero hr theorem WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded (f : G → E) {s : Set G} (hp : WithSeminorms p) : IsVonNBounded 𝕜 (f '' s) ↔ ∀ I : Finset ι, ∃ r > 0, ∀ x ∈ s, I.sup p (f x) < r := by simp_rw [hp.isVonNBounded_iff_finset_seminorm_bounded, Set.forall_mem_image] theorem WithSeminorms.isVonNBounded_iff_seminorm_bounded {s : Set E} (hp : WithSeminorms p) : IsVonNBounded 𝕜 s ↔ ∀ i : ι, ∃ r > 0, ∀ x ∈ s, p i x < r := by rw [hp.isVonNBounded_iff_finset_seminorm_bounded] constructor · intro hI i convert hI {i} rw [Finset.sup_singleton] intro hi I by_cases hI : I.Nonempty · choose r hr h using hi have h' : 0 < I.sup' hI r := by rcases hI with ⟨i, hi⟩ exact lt_of_lt_of_le (hr i) (Finset.le_sup' r hi) refine ⟨I.sup' hI r, h', fun x hx => finset_sup_apply_lt h' fun i hi => ?_⟩ refine lt_of_lt_of_le (h i x hx) ?_ simp only [Finset.le_sup'_iff] exact ⟨i, hi, (Eq.refl _).le⟩ simp only [Finset.not_nonempty_iff_eq_empty.mp hI, Finset.sup_empty, coe_bot, Pi.zero_apply] exact ⟨1, zero_lt_one, fun _ _ => zero_lt_one⟩ theorem WithSeminorms.image_isVonNBounded_iff_seminorm_bounded (f : G → E) {s : Set G} (hp : WithSeminorms p) : IsVonNBounded 𝕜 (f '' s) ↔ ∀ i : ι, ∃ r > 0, ∀ x ∈ s, p i (f x) < r := by simp_rw [hp.isVonNBounded_iff_seminorm_bounded, Set.forall_mem_image] /-- In a topological vector space, the topology is generated by a single seminorm `p` iff the unit ball for this seminorm is a bounded neighborhood of `0`. -/ theorem withSeminorms_iff_mem_nhds_isVonNBounded [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} : WithSeminorms (fun (_ : Fin 1) ↦ p) ↔ p.ball 0 1 ∈ 𝓝 0 ∧ IsVonNBounded 𝕜 (p.ball 0 1) := by /- The nontrivial direction is from right to left. With `SeminormFamily.withSeminorms_of_nhds`, we need to see that the neighborhoods of zero for the initial topology and for `p` coincide. -/ refine ⟨fun h ↦ ⟨?_, ?_⟩, ?_⟩ · apply (h.mem_nhds_iff _ _).2 exact ⟨Finset.univ, 1, zero_lt_one, by simp⟩ · apply h.isVonNBounded_iff_seminorm_bounded.2 (fun i ↦ ?_) exact ⟨1, zero_lt_one, by simp⟩ rintro ⟨h, h'⟩ apply SeminormFamily.withSeminorms_of_nhds ext s refine ⟨fun hs ↦ ?_, fun hs ↦ ?_⟩ · /- Show that a neighborhood `s` of zero for the topology is a neighborhood for `p`, by using the boundedess of `p.ball 0 1`: this ensures that, for some nonzero `c`, we have `p.ball 0 1 ⊆ c • s`, and therefore `p.ball 0 (‖c‖⁻¹) ⊆ s`. -/ obtain ⟨c, hc, c_ne⟩ : ∃ (c : 𝕜), p.ball 0 1 ⊆ c • s ∧ c ≠ 0 := ((h' hs).and (eventually_ne_cobounded 0)).exists have : p.ball 0 (‖c⁻¹‖) ⊆ s := by have : c • p.ball 0 (‖c⁻¹‖) ⊆ c • s := by simpa [smul_ball_zero c_ne, ← norm_mul, c_ne] using hc rwa [smul_set_subset_smul_set_iff₀ c_ne] at this apply Filter.mem_of_superset _ this apply FilterBasis.mem_filter_of_mem change p.ball 0 (‖c⁻¹‖) ∈ SeminormFamily.basisSets (fun (i : Fin 1) ↦ p) apply SeminormFamily.basisSets_singleton_mem _ 0 simpa using c_ne · /- Show that a neighborhood `s` for `p` is a neighborhood for the topology, by using the fact that `p.ball 0 1` is a neighborhood of `0`. Indeed, `s` contains a ball `p.ball 0 r`, which contains `c • p.ball 0 1` for some nonzero `c`. The latter set is a neighborhood of zero for the topology thanks to the topological vector space assumption. -/ rcases (FilterBasis.mem_filter_iff _).1 hs with ⟨t, ht, ts⟩ suffices t ∈ 𝓝 0 from Filter.mem_of_superset this ts rcases (SeminormFamily.basisSets_iff _).1 ht with ⟨w, r, r_pos, hw⟩ rcases eq_or_ne w ∅ with rfl | w_ne · simp only [ball, Finset.sup_empty, sub_zero, coe_bot, Pi.zero_apply, r_pos, setOf_true] at hw simp [hw] have : t = p.ball 0 r := by have : w = Finset.univ := by rcases Finset.nonempty_of_ne_empty w_ne with ⟨i, hi⟩ ext j simp only [Subsingleton.elim j i, hi, Finset.mem_univ] simpa only [this, Finset.univ_unique, Fin.default_eq_zero, Fin.isValue, Finset.sup_singleton] using hw rw [this] obtain ⟨c, c_pos, hc⟩ : ∃ (c : 𝕜), 0 < ‖c‖ ∧ ‖c‖ < r := exists_norm_lt 𝕜 r_pos have c_ne : c ≠ 0 := (by simpa using c_pos) have : c • p.ball 0 1 ⊆ p.ball 0 r := by rw [smul_ball_zero c_ne] exact ball_mono (by simpa using hc.le) apply Filter.mem_of_superset ?_ this simpa using smul_mem_nhds_smul₀ c_ne h end NontriviallyNormedField -- TODO: the names in this section are not very predictable section continuous_of_bounded namespace Seminorm variable [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [NormedField 𝕝] [Module 𝕝 E] variable [NontriviallyNormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F] variable [NormedField 𝕝₂] [Module 𝕝₂ F] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] variable {τ₁₂ : 𝕝 →+* 𝕝₂} [RingHomIsometric τ₁₂] theorem continuous_of_continuous_comp {q : SeminormFamily 𝕝₂ F ι'} [TopologicalSpace E] [IsTopologicalAddGroup E] [TopologicalSpace F] (hq : WithSeminorms q) (f : E →ₛₗ[τ₁₂] F) (hf : ∀ i, Continuous ((q i).comp f)) : Continuous f := by have : IsTopologicalAddGroup F := hq.topologicalAddGroup refine continuous_of_continuousAt_zero f ?_ simp_rw [ContinuousAt, f.map_zero, q.withSeminorms_iff_nhds_eq_iInf.mp hq, Filter.tendsto_iInf, Filter.tendsto_comap_iff] intro i convert (hf i).continuousAt.tendsto exact (map_zero _).symm theorem continuous_iff_continuous_comp {q : SeminormFamily 𝕜₂ F ι'} [TopologicalSpace E] [IsTopologicalAddGroup E] [TopologicalSpace F] (hq : WithSeminorms q) (f : E →ₛₗ[σ₁₂] F) : Continuous f ↔ ∀ i, Continuous ((q i).comp f) := ⟨fun h i => (hq.continuous_seminorm i).comp h, continuous_of_continuous_comp hq f⟩ theorem continuous_from_bounded {p : SeminormFamily 𝕝 E ι} {q : SeminormFamily 𝕝₂ F ι'} {_ : TopologicalSpace E} (hp : WithSeminorms p) {_ : TopologicalSpace F} (hq : WithSeminorms q) (f : E →ₛₗ[τ₁₂] F) (hf : Seminorm.IsBounded p q f) : Continuous f := by have : IsTopologicalAddGroup E := hp.topologicalAddGroup refine continuous_of_continuous_comp hq _ fun i => ?_ rcases hf i with ⟨s, C, hC⟩ rw [← Seminorm.finset_sup_smul] at hC -- Note: we deduce continuouty of `s.sup (C • p)` from that of `∑ i ∈ s, C • p i`. -- The reason is that there is no `continuous_finset_sup`, and even if it were we couldn't -- really use it since `ℝ` is not an `OrderBot`. refine Seminorm.continuous_of_le ?_ (hC.trans <| Seminorm.finset_sup_le_sum _ _) change Continuous (fun x ↦ Seminorm.coeFnAddMonoidHom _ _ (∑ i ∈ s, C • p i) x) simp_rw [map_sum, Finset.sum_apply] exact (continuous_finset_sum _ fun i _ ↦ (hp.continuous_seminorm i).const_smul (C : ℝ)) theorem cont_withSeminorms_normedSpace (F) [SeminormedAddCommGroup F] [NormedSpace 𝕝₂ F] [TopologicalSpace E] {p : ι → Seminorm 𝕝 E} (hp : WithSeminorms p) (f : E →ₛₗ[τ₁₂] F) (hf : ∃ (s : Finset ι) (C : ℝ≥0), (normSeminorm 𝕝₂ F).comp f ≤ C • s.sup p) : Continuous f := by rw [← Seminorm.isBounded_const (Fin 1)] at hf exact continuous_from_bounded hp (norm_withSeminorms 𝕝₂ F) f hf theorem cont_normedSpace_to_withSeminorms (E) [SeminormedAddCommGroup E] [NormedSpace 𝕝 E] [TopologicalSpace F] {q : ι → Seminorm 𝕝₂ F} (hq : WithSeminorms q) (f : E →ₛₗ[τ₁₂] F) (hf : ∀ i : ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • normSeminorm 𝕝 E) : Continuous f := by rw [← Seminorm.const_isBounded (Fin 1)] at hf exact continuous_from_bounded (norm_withSeminorms 𝕝 E) hq f hf /-- Let `E` and `F` be two topological vector spaces over a `NontriviallyNormedField`, and assume that the topology of `F` is generated by some family of seminorms `q`. For a family `f` of linear maps from `E` to `F`, the following are equivalent: * `f` is equicontinuous at `0`. * `f` is equicontinuous. * `f` is uniformly equicontinuous. * For each `q i`, the family of seminorms `k ↦ (q i) ∘ (f k)` is bounded by some continuous seminorm `p` on `E`. * For each `q i`, the seminorm `⊔ k, (q i) ∘ (f k)` is well-defined and continuous. In particular, if you can determine all continuous seminorms on `E`, that gives you a complete characterization of equicontinuity for linear maps from `E` to `F`. For example `E` and `F` are both normed spaces, you get `NormedSpace.equicontinuous_TFAE`. -/ protected theorem _root_.WithSeminorms.equicontinuous_TFAE {κ : Type*} {q : SeminormFamily 𝕜₂ F ι'} [UniformSpace E] [IsUniformAddGroup E] [u : UniformSpace F] [hu : IsUniformAddGroup F] (hq : WithSeminorms q) [ContinuousSMul 𝕜 E] (f : κ → E →ₛₗ[σ₁₂] F) : TFAE [ EquicontinuousAt ((↑) ∘ f) 0, Equicontinuous ((↑) ∘ f), UniformEquicontinuous ((↑) ∘ f), ∀ i, ∃ p : Seminorm 𝕜 E, Continuous p ∧ ∀ k, (q i).comp (f k) ≤ p, ∀ i, BddAbove (range fun k ↦ (q i).comp (f k)) ∧ Continuous (⨆ k, (q i).comp (f k)) ] := by -- We start by reducing to the case where the target is a seminormed space rw [q.withSeminorms_iff_uniformSpace_eq_iInf.mp hq, uniformEquicontinuous_iInf_rng, equicontinuous_iInf_rng, equicontinuousAt_iInf_rng] refine forall_tfae [_, _, _, _, _] fun i ↦ ?_ let _ : SeminormedAddCommGroup F := (q i).toSeminormedAddCommGroup clear u hu hq -- Now we can prove the equivalence in this setting simp only [List.map] tfae_have 1 → 3 := uniformEquicontinuous_of_equicontinuousAt_zero f tfae_have 3 → 2 := UniformEquicontinuous.equicontinuous tfae_have 2 → 1 := fun H ↦ H 0 tfae_have 3 → 5 | H => by have : ∀ᶠ x in 𝓝 0, ∀ k, q i (f k x) ≤ 1 := by filter_upwards [Metric.equicontinuousAt_iff_right.mp (H.equicontinuous 0) 1 one_pos] with x hx k simpa using (hx k).le have bdd : BddAbove (range fun k ↦ (q i).comp (f k)) := Seminorm.bddAbove_of_absorbent (absorbent_nhds_zero this) (fun x hx ↦ ⟨1, forall_mem_range.mpr hx⟩) rw [← Seminorm.coe_iSup_eq bdd] refine ⟨bdd, Seminorm.continuous' (r := 1) ?_⟩ filter_upwards [this] with x hx simpa only [closedBall_iSup bdd _ one_pos, mem_iInter, mem_closedBall_zero] using hx tfae_have 5 → 4 := fun H ↦ ⟨⨆ k, (q i).comp (f k), Seminorm.coe_iSup_eq H.1 ▸ H.2, le_ciSup H.1⟩ tfae_have 4 → 1 -- This would work over any `NormedField` | ⟨p, hp, hfp⟩ => Metric.equicontinuousAt_of_continuity_modulus p (map_zero p ▸ hp.tendsto 0) _ <| Eventually.of_forall fun x k ↦ by simpa using hfp k x tfae_finish theorem _root_.WithSeminorms.uniformEquicontinuous_iff_exists_continuous_seminorm {κ : Type*} {q : SeminormFamily 𝕜₂ F ι'} [UniformSpace E] [IsUniformAddGroup E] [u : UniformSpace F] [IsUniformAddGroup F] (hq : WithSeminorms q) [ContinuousSMul 𝕜 E] (f : κ → E →ₛₗ[σ₁₂] F) : UniformEquicontinuous ((↑) ∘ f) ↔ ∀ i, ∃ p : Seminorm 𝕜 E, Continuous p ∧ ∀ k, (q i).comp (f k) ≤ p := (hq.equicontinuous_TFAE f).out 2 3 theorem _root_.WithSeminorms.uniformEquicontinuous_iff_bddAbove_and_continuous_iSup {κ : Type*} {q : SeminormFamily 𝕜₂ F ι'} [UniformSpace E] [IsUniformAddGroup E] [u : UniformSpace F] [IsUniformAddGroup F] (hq : WithSeminorms q) [ContinuousSMul 𝕜 E] (f : κ → E →ₛₗ[σ₁₂] F) : UniformEquicontinuous ((↑) ∘ f) ↔ ∀ i, BddAbove (range fun k ↦ (q i).comp (f k)) ∧ Continuous (⨆ k, (q i).comp (f k)) := (hq.equicontinuous_TFAE f).out 2 4 end Seminorm section Congr namespace WithSeminorms variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [NormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] /-- Two families of seminorms `p` and `q` on the same space generate the same topology if each `p i` is bounded by some `C • Finset.sup s q` and vice-versa. We formulate these boundedness assumptions as `Seminorm.IsBounded q p LinearMap.id` (and vice-versa) to reuse the API. Furthermore, we don't actually state it as an equality of topologies but as a way to deduce `WithSeminorms q` from `WithSeminorms p`, since this should be more useful in practice. -/ protected theorem congr {p : SeminormFamily 𝕜 E ι} {q : SeminormFamily 𝕜 E ι'} [t : TopologicalSpace E] (hp : WithSeminorms p) (hpq : Seminorm.IsBounded p q LinearMap.id) (hqp : Seminorm.IsBounded q p LinearMap.id) : WithSeminorms q := by constructor rw [hp.topology_eq_withSeminorms] clear hp t refine le_antisymm ?_ ?_ <;> rw [← continuous_id_iff_le] <;> refine continuous_from_bounded (.mk (topology := _) rfl) (.mk (topology := _) rfl) LinearMap.id (by assumption) protected theorem finset_sups {p : SeminormFamily 𝕜 E ι} [TopologicalSpace E] (hp : WithSeminorms p) : WithSeminorms (fun s : Finset ι ↦ s.sup p) := by refine hp.congr ?_ ?_ · intro s refine ⟨s, 1, ?_⟩ rw [one_smul] rfl · intro i refine ⟨{{i}}, 1, ?_⟩ rw [Finset.sup_singleton, Finset.sup_singleton, one_smul] rfl protected theorem partial_sups [Preorder ι] [LocallyFiniteOrderBot ι] {p : SeminormFamily 𝕜 E ι} [TopologicalSpace E] (hp : WithSeminorms p) : WithSeminorms (fun i ↦ (Finset.Iic i).sup p) := by refine hp.congr ?_ ?_ · intro i refine ⟨Finset.Iic i, 1, ?_⟩ rw [one_smul] rfl · intro i refine ⟨{i}, 1, ?_⟩ rw [Finset.sup_singleton, one_smul] exact (Finset.le_sup (Finset.mem_Iic.mpr le_rfl) : p i ≤ (Finset.Iic i).sup p) protected theorem congr_equiv {p : SeminormFamily 𝕜 E ι} [t : TopologicalSpace E] (hp : WithSeminorms p) (e : ι' ≃ ι) : WithSeminorms (p ∘ e) := by refine hp.congr ?_ ?_ <;> intro i <;> [use {e i}, 1; use {e.symm i}, 1] <;> simp end WithSeminorms end Congr end continuous_of_bounded section bounded_of_continuous namespace Seminorm variable [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [SeminormedAddCommGroup F] [NormedSpace 𝕜 F] {p : SeminormFamily 𝕜 E ι} /-- In a semi-`NormedSpace`, a continuous seminorm is zero on elements of norm `0`. -/ lemma map_eq_zero_of_norm_zero (q : Seminorm 𝕜 F) (hq : Continuous q) {x : F} (hx : ‖x‖ = 0) : q x = 0 := (map_zero q) ▸ ((specializes_iff_mem_closure.mpr <| mem_closure_zero_iff_norm.mpr hx).map hq).eq.symm /-- Let `F` be a semi-`NormedSpace` over a `NontriviallyNormedField`, and let `q` be a seminorm on `F`. If `q` is continuous, then it is uniformly controlled by the norm, that is there is some `C > 0` such that `∀ x, q x ≤ C * ‖x‖`. The continuity ensures boundedness on a ball of some radius `ε`. The nontriviality of the norm is then used to rescale any element into an element of norm in `[ε/C, ε[`, thus with a controlled image by `q`. The control of `q` at the original element follows by rescaling. -/ lemma bound_of_continuous_normedSpace (q : Seminorm 𝕜 F) (hq : Continuous q) : ∃ C, 0 < C ∧ (∀ x : F, q x ≤ C * ‖x‖) := by have hq' : Tendsto q (𝓝 0) (𝓝 0) := map_zero q ▸ hq.tendsto 0 rcases NormedAddCommGroup.nhds_zero_basis_norm_lt.mem_iff.mp (hq' <| Iio_mem_nhds one_pos) with ⟨ε, ε_pos, hε⟩ rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ have : 0 < ‖c‖ / ε := by positivity refine ⟨‖c‖ / ε, this, fun x ↦ ?_⟩ by_cases hx : ‖x‖ = 0 · rw [hx, mul_zero] exact le_of_eq (map_eq_zero_of_norm_zero q hq hx) · refine (normSeminorm 𝕜 F).bound_of_shell q ε_pos hc (fun x hle hlt ↦ ?_) hx refine (le_of_lt <| show q x < _ from hε hlt).trans ?_ rwa [← div_le_iff₀' this, one_div_div] /-- Let `E` be a topological vector space (over a `NontriviallyNormedField`) whose topology is generated by some family of seminorms `p`, and let `q` be a seminorm on `E`. If `q` is continuous, then it is uniformly controlled by *finitely many* seminorms of `p`, that is there is some finset `s` of the index set and some `C > 0` such that `q ≤ C • s.sup p`. -/ lemma bound_of_continuous [t : TopologicalSpace E] (hp : WithSeminorms p) (q : Seminorm 𝕜 E) (hq : Continuous q) : ∃ s : Finset ι, ∃ C : ℝ≥0, C ≠ 0 ∧ q ≤ C • s.sup p := by -- The continuity of `q` gives us a finset `s` and a real `ε > 0` -- such that `hε : (s.sup p).ball 0 ε ⊆ q.ball 0 1`. rcases hp.hasBasis.mem_iff.mp (ball_mem_nhds hq one_pos) with ⟨V, hV, hε⟩ rcases p.basisSets_iff.mp hV with ⟨s, ε, ε_pos, rfl⟩ -- Now forget that `E` already had a topology and view it as the (semi)normed space -- `(E, s.sup p)`. clear hp hq t let _ : SeminormedAddCommGroup E := (s.sup p).toSeminormedAddCommGroup let _ : NormedSpace 𝕜 E := { norm_smul_le := fun a b ↦ le_of_eq (map_smul_eq_mul (s.sup p) a b) } -- The inclusion `hε` tells us exactly that `q` is *still* continuous for this new topology have : Continuous q := Seminorm.continuous (r := 1) (mem_of_superset (Metric.ball_mem_nhds _ ε_pos) hε) -- Hence we can conclude by applying `bound_of_continuous_normedSpace`. rcases bound_of_continuous_normedSpace q this with ⟨C, C_pos, hC⟩ exact ⟨s, ⟨C, C_pos.le⟩, fun H ↦ C_pos.ne.symm (congr_arg NNReal.toReal H), hC⟩ -- Note that the key ingredient for this proof is that, by scaling arguments hidden in -- `Seminorm.continuous`, we only have to look at the `q`-ball of radius one, and the `s` we get -- from that will automatically work for all other radii. end Seminorm end bounded_of_continuous section LocallyConvexSpace open LocallyConvexSpace variable [NormedField 𝕜] [NormedSpace ℝ 𝕜] [AddCommGroup E] [Module 𝕜 E] [Module ℝ E] [IsScalarTower ℝ 𝕜 E] [TopologicalSpace E] theorem WithSeminorms.toLocallyConvexSpace {p : SeminormFamily 𝕜 E ι} (hp : WithSeminorms p) : LocallyConvexSpace ℝ E := by have := hp.topologicalAddGroup apply ofBasisZero ℝ E id fun s => s ∈ p.basisSets · rw [hp.1, AddGroupFilterBasis.nhds_eq _, AddGroupFilterBasis.N_zero] exact FilterBasis.hasBasis _ · intro s hs change s ∈ Set.iUnion _ at hs simp_rw [Set.mem_iUnion, Set.mem_singleton_iff] at hs rcases hs with ⟨I, r, _, rfl⟩ exact convex_ball _ _ _ end LocallyConvexSpace section NormedSpace variable (𝕜) [NormedField 𝕜] [NormedSpace ℝ 𝕜] [SeminormedAddCommGroup E] /-- Not an instance since `𝕜` can't be inferred. See `NormedSpace.toLocallyConvexSpace` for a slightly weaker instance version. -/ theorem NormedSpace.toLocallyConvexSpace' [NormedSpace 𝕜 E] [Module ℝ E] [IsScalarTower ℝ 𝕜 E] : LocallyConvexSpace ℝ E := (norm_withSeminorms 𝕜 E).toLocallyConvexSpace /-- See `NormedSpace.toLocallyConvexSpace'` for a slightly stronger version which is not an instance. -/ instance NormedSpace.toLocallyConvexSpace [NormedSpace ℝ E] : LocallyConvexSpace ℝ E := NormedSpace.toLocallyConvexSpace' ℝ end NormedSpace section TopologicalConstructions variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [NormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] /-- The family of seminorms obtained by composing each seminorm by a linear map. -/ def SeminormFamily.comp (q : SeminormFamily 𝕜₂ F ι) (f : E →ₛₗ[σ₁₂] F) : SeminormFamily 𝕜 E ι := fun i => (q i).comp f theorem SeminormFamily.comp_apply (q : SeminormFamily 𝕜₂ F ι) (i : ι) (f : E →ₛₗ[σ₁₂] F) : q.comp f i = (q i).comp f := rfl theorem SeminormFamily.finset_sup_comp (q : SeminormFamily 𝕜₂ F ι) (s : Finset ι) (f : E →ₛₗ[σ₁₂] F) : (s.sup q).comp f = s.sup (q.comp f) := by ext x rw [Seminorm.comp_apply, Seminorm.finset_sup_apply, Seminorm.finset_sup_apply] rfl variable [TopologicalSpace F] theorem LinearMap.withSeminorms_induced {q : SeminormFamily 𝕜₂ F ι} (hq : WithSeminorms q) (f : E →ₛₗ[σ₁₂] F) : WithSeminorms (topology := induced f inferInstance) (q.comp f) := by have := hq.topologicalAddGroup let _ : TopologicalSpace E := induced f inferInstance have : IsTopologicalAddGroup E := topologicalAddGroup_induced f rw [(q.comp f).withSeminorms_iff_nhds_eq_iInf, nhds_induced, map_zero, q.withSeminorms_iff_nhds_eq_iInf.mp hq, Filter.comap_iInf] refine iInf_congr fun i => ?_ exact Filter.comap_comap lemma Topology.IsInducing.withSeminorms {q : SeminormFamily 𝕜₂ F ι} (hq : WithSeminorms q) [TopologicalSpace E] {f : E →ₛₗ[σ₁₂] F} (hf : IsInducing f) : WithSeminorms (q.comp f) := by rw [hf.eq_induced] exact f.withSeminorms_induced hq /-- (Disjoint) union of seminorm families. -/ protected def SeminormFamily.sigma {κ : ι → Type*} (p : (i : ι) → SeminormFamily 𝕜 E (κ i)) : SeminormFamily 𝕜 E ((i : ι) × κ i) := fun ⟨i, k⟩ => p i k theorem withSeminorms_iInf {κ : ι → Type*} {p : (i : ι) → SeminormFamily 𝕜 E (κ i)} {t : ι → TopologicalSpace E} (hp : ∀ i, WithSeminorms (topology := t i) (p i)) : WithSeminorms (topology := ⨅ i, t i) (SeminormFamily.sigma p) := by have : ∀ i, @IsTopologicalAddGroup E (t i) _ := fun i ↦ @WithSeminorms.topologicalAddGroup _ _ _ _ _ _ (t i) _ (hp i) have : @IsTopologicalAddGroup E (⨅ i, t i) _ := topologicalAddGroup_iInf inferInstance simp_rw [@SeminormFamily.withSeminorms_iff_topologicalSpace_eq_iInf _ _ _ _ _ _ _ (_)] at hp ⊢ rw [iInf_sigma] exact iInf_congr hp theorem withSeminorms_pi {κ : ι → Type*} {E : ι → Type*} [∀ i, AddCommGroup (E i)] [∀ i, Module 𝕜 (E i)] [∀ i, TopologicalSpace (E i)] {p : (i : ι) → SeminormFamily 𝕜 (E i) (κ i)} (hp : ∀ i, WithSeminorms (p i)) : WithSeminorms (SeminormFamily.sigma (fun i ↦ (p i).comp (LinearMap.proj i))) := withSeminorms_iInf fun i ↦ (LinearMap.proj i).withSeminorms_induced (hp i) end TopologicalConstructions section TopologicalProperties variable [NontriviallyNormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [Countable ι] variable {p : SeminormFamily 𝕜 E ι} variable [TopologicalSpace E] /-- If the topology of a space is induced by a countable family of seminorms, then the topology is first countable. -/ theorem WithSeminorms.firstCountableTopology (hp : WithSeminorms p) : FirstCountableTopology E := by have := hp.topologicalAddGroup let _ : UniformSpace E := IsTopologicalAddGroup.toUniformSpace E have : IsUniformAddGroup E := isUniformAddGroup_of_addCommGroup have : (𝓝 (0 : E)).IsCountablyGenerated := by rw [p.withSeminorms_iff_nhds_eq_iInf.mp hp] exact Filter.iInf.isCountablyGenerated _ have : (uniformity E).IsCountablyGenerated := IsUniformAddGroup.uniformity_countably_generated exact UniformSpace.firstCountableTopology E end TopologicalProperties
Hom.lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.Algebra.Group.Hom.Defs import Mathlib.GroupTheory.Congruence.Defs /-! # Congruence relations and homomorphisms This file contains elementary definitions involving congruence relations and morphisms. ## Main definitions * `Con.ker`: the kernel of a monoid homomorphism as a congruence relation * `Con.mk'`: the map from a monoid to its quotient by a congruence relation * `Con.lift`: the homomorphism on the quotient given that the congruence is in the kernel * `Con.map`: homomorphism from a smaller to a larger quotient ## Tags congruence, congruence relation, quotient, quotient by congruence relation, monoid, quotient monoid -/ variable (M : Type*) {N : Type*} {P : Type*} open Function Setoid variable {M} namespace Con section Mul variable {F} [Mul M] [Mul N] [Mul P] [FunLike F M N] [MulHomClass F M N] /-- The natural homomorphism from a magma to its quotient by a congruence relation. -/ @[to_additive (attr := simps)/-- The natural homomorphism from an additive magma to its quotient by an additive congruence relation. -/] def mkMulHom (c : Con M) : MulHom M c.Quotient where toFun := (↑) map_mul' _ _ := rfl /-- The kernel of a multiplicative homomorphism as a congruence relation. -/ @[to_additive /-- The kernel of an additive homomorphism as an additive congruence relation. -/] def ker (f : F) : Con M where toSetoid := Setoid.ker f mul' h1 h2 := by dsimp [Setoid.ker, onFun] at * rw [map_mul, h1, h2, map_mul] @[to_additive (attr := norm_cast)] theorem ker_coeMulHom (f : F) : ker (f : MulHom M N) = ker f := rfl /-- The definition of the congruence relation defined by a monoid homomorphism's kernel. -/ @[to_additive (attr := simp) /-- The definition of the additive congruence relation defined by an `AddMonoid` homomorphism's kernel. -/] theorem ker_rel (f : F) {x y} : ker f x y ↔ f x = f y := Iff.rfl @[to_additive (attr := simp) /-- The kernel of the quotient map induced by an additive congruence relation `c` equals `c`. -/] theorem ker_mkMulHom_eq (c : Con M) : ker (mkMulHom c) = c := ext fun _ _ => Quotient.eq'' /-- The kernel of a multiplication-preserving function as a congruence relation. -/ @[to_additive /-- The kernel of an addition-preserving function as an additive congruence relation. -/] abbrev mulKer (f : M → P) (h : ∀ x y, f (x * y) = f x * f y) : Con M := ker <| MulHom.mk f h attribute [deprecated Con.ker (since := "2025-03-23")] mulKer attribute [deprecated AddCon.ker (since := "2025-03-23")] AddCon.addKer set_option linter.deprecated false in /-- The kernel of the quotient map induced by a congruence relation `c` equals `c`. -/ @[to_additive (attr := simp) /-- The kernel of the quotient map induced by an additive congruence relation `c` equals `c`. -/] theorem mul_ker_mk_eq {c : Con M} : (mulKer ((↑) : M → c.Quotient) fun _ _ => rfl) = c := ext fun _ _ => Quotient.eq'' attribute [deprecated Con.ker_mkMulHom_eq (since := "2025-03-23")] mul_ker_mk_eq attribute [deprecated AddCon.ker_mkAddHom_eq (since := "2025-03-23")] AddCon.add_ker_mk_eq /-- Given a function `f`, the smallest congruence relation containing the binary relation on `f`'s image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by a congruence relation `c`.' -/ @[to_additive /-- Given a function `f`, the smallest additive congruence relation containing the binary relation on `f`'s image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by an additive congruence relation `c`.' -/] def mapGen {c : Con M} (f : M → N) : Con N := conGen <| Relation.Map c f f /-- Given a surjective multiplicative-preserving function `f` whose kernel is contained in a congruence relation `c`, the congruence relation on `f`'s codomain defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by `c`.' -/ @[to_additive /-- Given a surjective addition-preserving function `f` whose kernel is contained in an additive congruence relation `c`, the additive congruence relation on `f`'s codomain defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by `c`.' -/] def mapOfSurjective {c : Con M} (f : F) (h : ker f ≤ c) (hf : Surjective f) : Con N where __ := c.toSetoid.mapOfSurjective f h hf mul' h₁ h₂ := by rcases h₁ with ⟨a, b, h1, rfl, rfl⟩ rcases h₂ with ⟨p, q, h2, rfl, rfl⟩ exact ⟨a * p, b * q, c.mul h1 h2, map_mul f _ _, map_mul f _ _⟩ /-- A specialization of 'the smallest congruence relation containing a congruence relation `c` equals `c`'. -/ @[to_additive /-- A specialization of 'the smallest additive congruence relation containing an additive congruence relation `c` equals `c`'. -/] theorem mapOfSurjective_eq_mapGen {c : Con M} {f : F} (h : ker f ≤ c) (hf : Surjective f) : c.mapGen f = c.mapOfSurjective f h hf := by rw [← conGen_of_con (c.mapOfSurjective f h hf)]; rfl /-- Given a congruence relation `c` on a type `M` with a multiplication, the order-preserving bijection between the set of congruence relations containing `c` and the congruence relations on the quotient of `M` by `c`. -/ @[to_additive /-- Given an additive congruence relation `c` on a type `M` with an addition, the order-preserving bijection between the set of additive congruence relations containing `c` and the additive congruence relations on the quotient of `M` by `c`. -/] def correspondence {c : Con M} : { d // c ≤ d } ≃o Con c.Quotient where toFun d := d.1.mapOfSurjective (mkMulHom c) (by rw [Con.ker_mkMulHom_eq]; exact d.2) <| Quotient.mk_surjective invFun d := ⟨comap ((↑) : M → c.Quotient) (fun _ _ => rfl) d, fun x y h => show d x y by rw [c.eq.2 h]; exact d.refl _⟩ left_inv d := Subtype.ext_iff_val.2 <| ext fun x y => ⟨fun ⟨a, b, H, hx, hy⟩ => d.1.trans (d.1.symm <| d.2 <| c.eq.1 hx) <| d.1.trans H <| d.2 <| c.eq.1 hy, fun h => ⟨_, _, h, rfl, rfl⟩⟩ right_inv d := ext fun x y => ⟨fun ⟨_, _, H, hx, hy⟩ => hx ▸ hy ▸ H, Con.induction_on₂ x y fun w z h => ⟨w, z, h, rfl, rfl⟩⟩ map_rel_iff' {s t} := by constructor · intros h x y hs rcases h ⟨x, y, hs, rfl, rfl⟩ with ⟨a, b, ht, hx, hy⟩ exact t.1.trans (t.1.symm <| t.2 <| c.eq.1 hx) (t.1.trans ht (t.2 <| c.eq.1 hy)) · exact Relation.map_mono end Mul section MulOneClass variable [MulOneClass M] [MulOneClass N] [MulOneClass P] {c : Con M} variable (c) /-- The natural homomorphism from a monoid to its quotient by a congruence relation. -/ @[to_additive /-- The natural homomorphism from an `AddMonoid` to its quotient by an additive congruence relation. -/] def mk' : M →* c.Quotient where __ := mkMulHom c map_one' := rfl variable (x y : M) /-- The kernel of the natural homomorphism from a monoid to its quotient by a congruence relation `c` equals `c`. -/ @[to_additive (attr := simp) /-- The kernel of the natural homomorphism from an `AddMonoid` to its quotient by an additive congruence relation `c` equals `c`. -/] theorem mk'_ker : ker c.mk' = c := ext fun _ _ => c.eq variable {c} /-- The natural homomorphism from a monoid to its quotient by a congruence relation is surjective. -/ @[to_additive /-- The natural homomorphism from an `AddMonoid` to its quotient by a congruence relation is surjective. -/] theorem mk'_surjective : Surjective c.mk' := Quotient.mk''_surjective @[to_additive (attr := simp)] theorem coe_mk' : (c.mk' : M → c.Quotient) = ((↑) : M → c.Quotient) := rfl @[to_additive] theorem ker_apply {f : M →* P} {x y} : ker f x y ↔ f x = f y := Iff.rfl /-- Given a monoid homomorphism `f : N → M` and a congruence relation `c` on `M`, the congruence relation induced on `N` by `f` equals the kernel of `c`'s quotient homomorphism composed with `f`. -/ @[to_additive /-- Given an `AddMonoid` homomorphism `f : N → M` and an additive congruence relation `c` on `M`, the additive congruence relation induced on `N` by `f` equals the kernel of `c`'s quotient homomorphism composed with `f`. -/] theorem comap_eq {f : N →* M} : comap f f.map_mul c = ker (c.mk'.comp f) := ext fun x y => show c _ _ ↔ c.mk' _ = c.mk' _ by rw [← c.eq]; rfl variable (c) (f : M →* P) /-- The homomorphism on the quotient of a monoid by a congruence relation `c` induced by a homomorphism constant on `c`'s equivalence classes. -/ @[to_additive /-- The homomorphism on the quotient of an `AddMonoid` by an additive congruence relation `c` induced by a homomorphism constant on `c`'s equivalence classes. -/] def lift (H : c ≤ ker f) : c.Quotient →* P where toFun x := (Con.liftOn x f) fun _ _ h => H h map_one' := by rw [← f.map_one]; rfl map_mul' x y := Con.induction_on₂ x y fun m n => by dsimp only [← coe_mul, Con.liftOn_coe] rw [map_mul] variable {c f} /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[to_additive /-- The diagram describing the universal property for quotients of `AddMonoid`s commutes. -/] theorem lift_mk' (H : c ≤ ker f) (x) : c.lift f H (c.mk' x) = f x := rfl /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[to_additive (attr := simp) /-- The diagram describing the universal property for quotients of `AddMonoid`s commutes. -/] theorem lift_coe (H : c ≤ ker f) (x : M) : c.lift f H x = f x := rfl /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[to_additive (attr := simp) /-- The diagram describing the universal property for quotients of `AddMonoid`s commutes. -/] theorem lift_comp_mk' (H : c ≤ ker f) : (c.lift f H).comp c.mk' = f := by ext; rfl /-- Given a homomorphism `f` from the quotient of a monoid by a congruence relation, `f` equals the homomorphism on the quotient induced by `f` composed with the natural map from the monoid to the quotient. -/ @[to_additive (attr := simp) /-- Given a homomorphism `f` from the quotient of an `AddMonoid` by an additive congruence relation, `f` equals the homomorphism on the quotient induced by `f` composed with the natural map from the `AddMonoid` to the quotient. -/] theorem lift_apply_mk' (f : c.Quotient →* P) : (c.lift (f.comp c.mk') fun x y h => show f ↑x = f ↑y by rw [c.eq.2 h]) = f := by ext x; rcases x with ⟨⟩; rfl /-- Homomorphisms on the quotient of a monoid by a congruence relation `c` are equal if their compositions with `c.mk'` are equal. -/ @[to_additive (attr := ext) /-- Homomorphisms on the quotient of an `AddMonoid` by an additive congruence relation `c` are equal if their compositions with `c.mk'` are equal. -/] lemma hom_ext {f g : c.Quotient →* P} (h : f.comp c.mk' = g.comp c.mk') : f = g := by rw [← lift_apply_mk' f, ← lift_apply_mk' g] congr 1 /-- Homomorphisms on the quotient of a monoid by a congruence relation are equal if they are equal on elements that are coercions from the monoid. -/ @[to_additive /-- Homomorphisms on the quotient of an `AddMonoid` by an additive congruence relation are equal if they are equal on elements that are coercions from the `AddMonoid`. -/] theorem lift_funext (f g : c.Quotient →* P) (h : ∀ a : M, f a = g a) : f = g := hom_ext <| DFunLike.ext _ _ h /-- The uniqueness part of the universal property for quotients of monoids. -/ @[to_additive /-- The uniqueness part of the universal property for quotients of `AddMonoid`s. -/] theorem lift_unique (H : c ≤ ker f) (g : c.Quotient →* P) (Hg : g.comp c.mk' = f) : g = c.lift f H := hom_ext Hg /-- Surjective monoid homomorphisms constant on a congruence relation `c`'s equivalence classes induce a surjective homomorphism on `c`'s quotient. -/ @[to_additive /-- Surjective `AddMonoid` homomorphisms constant on an additive congruence relation `c`'s equivalence classes induce a surjective homomorphism on `c`'s quotient. -/] theorem lift_surjective_of_surjective (h : c ≤ ker f) (hf : Surjective f) : Surjective (c.lift f h) := fun y => (Exists.elim (hf y)) fun w hw => ⟨w, (lift_mk' h w).symm ▸ hw⟩ variable (c f) /-- Given a monoid homomorphism `f` from `M` to `P`, the kernel of `f` is the unique congruence relation on `M` whose induced map from the quotient of `M` to `P` is injective. -/ @[to_additive /-- Given an `AddMonoid` homomorphism `f` from `M` to `P`, the kernel of `f` is the unique additive congruence relation on `M` whose induced map from the quotient of `M` to `P` is injective. -/] theorem ker_eq_lift_of_injective (H : c ≤ ker f) (h : Injective (c.lift f H)) : ker f = c := toSetoid_inj <| Setoid.ker_eq_lift_of_injective f H h variable {c} /-- The homomorphism induced on the quotient of a monoid by the kernel of a monoid homomorphism. -/ @[to_additive /-- The homomorphism induced on the quotient of an `AddMonoid` by the kernel of an `AddMonoid` homomorphism. -/] def kerLift : (ker f).Quotient →* P := ((ker f).lift f) fun _ _ => id variable {f} /-- The diagram described by the universal property for quotients of monoids, when the congruence relation is the kernel of the homomorphism, commutes. -/ @[to_additive (attr := simp) /-- The diagram described by the universal property for quotients of `AddMonoid`s, when the additive congruence relation is the kernel of the homomorphism, commutes. -/] theorem kerLift_mk (x : M) : kerLift f x = f x := rfl /-- A monoid homomorphism `f` induces an injective homomorphism on the quotient by `f`'s kernel. -/ @[to_additive /-- An `AddMonoid` homomorphism `f` induces an injective homomorphism on the quotient by `f`'s kernel. -/] theorem kerLift_injective (f : M →* P) : Injective (kerLift f) := fun x y => Quotient.inductionOn₂' x y fun _ _ => (ker f).eq.2 /-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, `d`'s quotient map induces a homomorphism from the quotient by `c` to the quotient by `d`. -/ @[to_additive /-- Given additive congruence relations `c, d` on an `AddMonoid` such that `d` contains `c`, `d`'s quotient map induces a homomorphism from the quotient by `c` to the quotient by `d`. -/] def map (c d : Con M) (h : c ≤ d) : c.Quotient →* d.Quotient := (c.lift d.mk') fun x y hc => show (ker d.mk') x y from (mk'_ker d).symm ▸ h hc /-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, the definition of the homomorphism from the quotient by `c` to the quotient by `d` induced by `d`'s quotient map. -/ @[to_additive /-- Given additive congruence relations `c, d` on an `AddMonoid` such that `d` contains `c`, the definition of the homomorphism from the quotient by `c` to the quotient by `d` induced by `d`'s quotient map. -/] theorem map_apply {c d : Con M} (h : c ≤ d) (x) : c.map d h x = c.lift d.mk' (fun _ _ hc => d.eq.2 <| h hc) x := rfl end MulOneClass end Con
ExpLog.lean
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv import Mathlib.Data.Complex.FiniteDimensional import Mathlib.NumberTheory.EulerProduct.Basic /-! # Logarithms of Euler Products We consider `f : ℕ →*₀ ℂ` and show that `exp (∑ p in Primes, log (1 - f p)⁻¹) = ∑ n : ℕ, f n` under suitable conditions on `f`. This can be seen as a logarithmic version of the Euler product for `f`. -/ open Complex open Topology in /-- If `f : α → ℂ` is summable, then so is `n ↦ log (1 - f n)`. -/ lemma Summable.clog_one_sub {α : Type*} {f : α → ℂ} (hsum : Summable f) : Summable fun n ↦ log (1 - f n) := by have hg : DifferentiableAt ℂ (fun z ↦ log (1 - z)) 0 := by have : 1 - 0 ∈ slitPlane := (sub_zero (1 : ℂ)).symm ▸ one_mem_slitPlane fun_prop (disch := assumption) have : (fun z ↦ log (1 - z)) =O[𝓝 0] id := by simpa only [sub_zero, log_one] using hg.isBigO_sub exact this.comp_summable hsum namespace EulerProduct /-- A variant of the Euler Product formula in terms of the exponential of a sum of logarithms. -/ theorem exp_tsum_primes_log_eq_tsum {f : ℕ →*₀ ℂ} (hsum : Summable (‖f ·‖)) : exp (∑' p : Nat.Primes, -log (1 - f p)) = ∑' n : ℕ, f n := by have hs {p : ℕ} (hp : 1 < p) : ‖f p‖ < 1 := hsum.of_norm.norm_lt_one (f := f.toMonoidHom) hp have hp (p : Nat.Primes) : 1 - f p ≠ 0 := fun h ↦ (norm_one (α := ℂ) ▸ (sub_eq_zero.mp h) ▸ hs p.prop.one_lt).false have H := hsum.of_norm.clog_one_sub.neg.subtype {p | p.Prime} |>.hasSum.cexp.tprod_eq simp only [Set.coe_setOf, Set.mem_setOf_eq, Function.comp_apply, exp_neg, exp_log (hp _)] at H exact H.symm.trans <| eulerProduct_completely_multiplicative_tprod hsum end EulerProduct
mxabelem.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path. From mathcomp Require Import div choice fintype tuple finfun bigop prime. From mathcomp Require Import ssralg poly finset fingroup morphism perm. From mathcomp Require Import automorphism quotient gproduct action finalg. From mathcomp Require Import zmodp commutator cyclic center pgroup gseries. From mathcomp Require Import nilpotent sylow maximal abelian matrix. From mathcomp Require Import mxalgebra mxrepresentation. (******************************************************************************) (* This file completes the theory developed in mxrepresentation.v with the *) (* construction and properties of linear representations over finite fields, *) (* and in particular the correspondence between internal action on a (normal) *) (* elementary abelian p-subgroup and a linear representation on an Fp-module. *) (* We provide the following next constructions for a finite field F: *) (* 'Zm%act == the action of {unit F} on 'M[F]_(m, n). *) (* rowg A == the additive group of 'rV[F]_n spanned by the row space *) (* of the matrix A. *) (* rowg_mx L == the partial inverse to rowg; for any 'Zm-stable group L *) (* of 'rV[F]_n we have rowg (rowg_mx L) = L. *) (* GLrepr F n == the natural, faithful representation of 'GL_n[F]. *) (* reprGLm rG == the morphism G >-> 'GL_n[F] equivalent to the *) (* representation r of G (with rG : mx_repr r G). *) (* ('MR rG)%act == the action of G on 'rV[F]_n equivalent to the *) (* representation r of G (with rG : mx_repr r G). *) (* The second set of constructions defines the interpretation of a normal *) (* non-trivial elementary abelian p-subgroup as an 'F_p module. We assume *) (* abelE : p.-abelem E and ntE : E != 1, throughout, as these are needed to *) (* build the isomorphism between E and a nontrivial 'rV['F_p]_n. *) (* 'rV(E) == the type of row vectors of the 'F_p module equivalent *) (* to E when E is a non-trivial p.-abelem group. *) (* 'M(E) == the type of matrices corresponding to E. *) (* 'dim E == the width of vectors/matrices in 'rV(E) / 'M(E). *) (* abelem_rV abelE ntE == the one-to-one injection of E onto 'rV(E). *) (* rVabelem abelE ntE == the one-to-one projection of 'rV(E) onto E. *) (* abelem_repr abelE ntE nEG == the representation of G on 'rV(E) that is *) (* equivalent to conjugation by G in E; here abelE, ntE are *) (* as above, and G \subset 'N(E). *) (* This file end with basic results on p-modular representations of p-groups, *) (* and theorems giving the structure of the representation of extraspecial *) (* groups; these results use somewhat more advanced group theory than the *) (* rest of mxrepresentation, in particular, results of sylow.v and maximal.v. *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope abelem_scope. Import GroupScope GRing.Theory FinRing.Theory. Local Open Scope ring_scope. (* Special results for representations on a finite field. In this case, the *) (* representation is equivalent to a morphism into the general linear group *) (* 'GL_n[F]. It is furthermore equivalent to a group action on the finite *) (* additive group of the corresponding row space 'rV_n. In addition, row *) (* spaces of matrices in 'M[F]_n correspond to subgroups of that vector group *) (* (this is only surjective when F is a prime field 'F_p), with moduleules *) (* corresponding to subgroups stabilized by the external action. *) Section FinNzRingRepr. Variable (R : finComUnitRingType) (gT : finGroupType). Variables (G : {group gT}) (n : nat) (rG : mx_representation R G n). Definition mx_repr_act (u : 'rV_n) x := u *m rG (val (subg G x)). Lemma mx_repr_actE u x : x \in G -> mx_repr_act u x = u *m rG x. Proof. by move=> Gx; rewrite /mx_repr_act /= subgK. Qed. Fact mx_repr_is_action : is_action G mx_repr_act. Proof. split=> [x | u x y Gx Gy]; first exact: can_inj (repr_mxK _ (subgP _)). by rewrite !mx_repr_actE ?groupM // -mulmxA repr_mxM. Qed. Canonical Structure mx_repr_action := Action mx_repr_is_action. Fact mx_repr_is_groupAction : is_groupAction [set: 'rV[R]_n] mx_repr_action. Proof. move=> x Gx /[!inE]; apply/andP; split; first by apply/subsetP=> u /[!inE]. by apply/morphicP=> /= u v _ _; rewrite !actpermE /= /mx_repr_act mulmxDl. Qed. Canonical Structure mx_repr_groupAction := GroupAction mx_repr_is_groupAction. End FinNzRingRepr. Notation "''MR' rG" := (mx_repr_action rG) (at level 10, rG at level 8) : action_scope. Notation "''MR' rG" := (mx_repr_groupAction rG) : groupAction_scope. Section FinFieldRepr. Variable F : finFieldType. (* The external group action (by scaling) of the multiplicative unit group *) (* of the finite field, and the correspondence between additive subgroups *) (* of row vectors that are stable by this action, and the matrix row spaces. *) Section ScaleAction. Variables m n : nat. Definition scale_act (A : 'M[F]_(m, n)) (a : {unit F}) := val a *: A. Lemma scale_actE A a : scale_act A a = val a *: A. Proof. by []. Qed. Fact scale_is_action : is_action setT scale_act. Proof. apply: is_total_action=> [A | A a b]; rewrite /scale_act ?scale1r //. by rewrite ?scalerA mulrC. Qed. Canonical scale_action := Action scale_is_action. Fact scale_is_groupAction : is_groupAction setT scale_action. Proof. move=> a _ /[1!inE]; apply/andP; split; first by apply/subsetP=> A /[!inE]. by apply/morphicP=> u A _ _ /=; rewrite !actpermE /= /scale_act scalerDr. Qed. Canonical scale_groupAction := GroupAction scale_is_groupAction. Lemma astab1_scale_act A : A != 0 -> 'C[A | scale_action] = 1%g. Proof. rewrite -mxrank_eq0=> nzA; apply/trivgP/subsetP=> a; apply: contraLR. rewrite !inE -val_eqE -subr_eq0 sub1set !inE => nz_a1. by rewrite -subr_eq0 -scaleN1r -scalerDl -mxrank_eq0 eqmx_scale. Qed. End ScaleAction. Local Notation "'Zm" := (scale_action _ _) : action_scope. Section RowGroup. Variable n : nat. Local Notation rVn := 'rV[F]_n. Definition rowg m (A : 'M[F]_(m, n)) : {set rVn} := [set u | u <= A]%MS. Lemma mem_rowg m A v : (v \in @rowg m A) = (v <= A)%MS. Proof. by rewrite inE. Qed. Fact rowg_group_set m A : group_set (@rowg m A). Proof. by apply/group_setP; split=> [|u v]; rewrite !inE ?sub0mx //; apply: addmx_sub. Qed. Canonical rowg_group m A := Group (@rowg_group_set m A). Lemma rowg_stable m (A : 'M_(m, n)) : [acts setT, on rowg A | 'Zm]. Proof. by apply/actsP=> a _ v; rewrite !inE eqmx_scale // -unitfE (valP a). Qed. Lemma rowgS m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (rowg A \subset rowg B) = (A <= B)%MS. Proof. apply/subsetP/idP=> sAB => [|u /[!inE] suA]; last exact: submx_trans sAB. by apply/row_subP=> i; have /[!(inE, row_sub)]-> := sAB (row i A). Qed. Lemma eq_rowg m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (A :=: B)%MS -> rowg A = rowg B. Proof. by move=> eqAB; apply/eqP; rewrite eqEsubset !rowgS !eqAB andbb. Qed. Lemma rowg0 m : rowg (0 : 'M_(m, n)) = 1%g. Proof. by apply/trivgP/subsetP=> v; rewrite !inE eqmx0 submx0. Qed. Lemma rowg1 : rowg 1%:M = setT. Proof. by apply/setP=> x; rewrite !inE submx1. Qed. Lemma trivg_rowg m (A : 'M_(m, n)) : (rowg A == 1%g) = (A == 0). Proof. by rewrite -submx0 -rowgS rowg0 (sameP trivgP eqP). Qed. Definition rowg_mx (L : {set rVn}) := <<\matrix_(i < #|L|) enum_val i>>%MS. Lemma rowgK m (A : 'M_(m, n)) : (rowg_mx (rowg A) :=: A)%MS. Proof. apply/eqmxP; rewrite !genmxE; apply/andP; split. by apply/row_subP=> i; rewrite rowK; have /[!inE] := enum_valP i. apply/row_subP=> i; set v := row i A. have Av: v \in rowg A by rewrite inE row_sub. by rewrite (eq_row_sub (enum_rank_in Av v)) // rowK enum_rankK_in. Qed. Lemma rowg_mxS (L M : {set 'rV[F]_n}) : L \subset M -> (rowg_mx L <= rowg_mx M)%MS. Proof. move/subsetP=> sLM; rewrite !genmxE; apply/row_subP=> i. rewrite rowK; move: (enum_val i) (sLM _ (enum_valP i)) => v Mv. by rewrite (eq_row_sub (enum_rank_in Mv v)) // rowK enum_rankK_in. Qed. Lemma sub_rowg_mx (L : {set rVn}) : L \subset rowg (rowg_mx L). Proof. apply/subsetP=> v Lv; rewrite inE genmxE. by rewrite (eq_row_sub (enum_rank_in Lv v)) // rowK enum_rankK_in. Qed. Lemma stable_rowg_mxK (L : {group rVn}) : [acts setT, on L | 'Zm] -> rowg (rowg_mx L) = L. Proof. move=> linL; apply/eqP; rewrite eqEsubset sub_rowg_mx andbT. apply/subsetP=> v; rewrite inE genmxE => /submxP[u ->{v}]. rewrite mulmx_sum_row group_prod // => i _. rewrite rowK; move: (enum_val i) (enum_valP i) => v Lv. have [->|] := eqVneq (u 0 i) 0; first by rewrite scale0r group1. by rewrite -unitfE => aP; rewrite ((actsP linL) (FinRing.Unit aP)) ?inE. Qed. Lemma rowg_mx1 : rowg_mx 1%g = 0. Proof. by apply/eqP; rewrite -submx0 -(rowg0 0) rowgK sub0mx. Qed. Lemma rowg_mx_eq0 (L : {group rVn}) : (rowg_mx L == 0) = (L :==: 1%g). Proof. rewrite -trivg_rowg; apply/idP/eqP=> [|->]; last by rewrite rowg_mx1 rowg0. exact/contraTeq/subG1_contra/sub_rowg_mx. Qed. Lemma rowgI m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : rowg (A :&: B)%MS = rowg A :&: rowg B. Proof. by apply/setP=> u; rewrite !inE sub_capmx. Qed. Lemma card_rowg m (A : 'M_(m, n)) : #|rowg A| = (#|F| ^ \rank A)%N. Proof. rewrite -[\rank A]mul1n -card_mx. have injA: injective (mulmxr (row_base A)). have /row_freeP[A' A'K] := row_base_free A. by move=> ?; apply: can_inj (mulmxr A') _ => u; rewrite /= -mulmxA A'K mulmx1. rewrite -(card_image (injA _)); apply: eq_card => v. by rewrite inE -(eq_row_base A) (sameP submxP codomP). Qed. Lemma rowgD m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : rowg (A + B)%MS = (rowg A * rowg B)%g. Proof. apply/eqP; rewrite eq_sym eqEcard mulG_subG /= !rowgS. rewrite addsmxSl addsmxSr -(@leq_pmul2r #|rowg A :&: rowg B|) ?cardG_gt0 //=. by rewrite -mul_cardG -rowgI !card_rowg -!expnD mxrank_sum_cap. Qed. Lemma cprod_rowg m1 m2 (A : 'M_(m1, n)) (B : 'M_(m2, n)) : (rowg A \* rowg B)%g = rowg (A + B)%MS. Proof. by rewrite rowgD cprodE // (sub_abelian_cent2 (zmod_abelian setT)). Qed. Lemma dprod_rowg m1 m2 (A : 'M[F]_(m1, n)) (B : 'M[F]_(m2, n)) : mxdirect (A + B) -> rowg A \x rowg B = rowg (A + B)%MS. Proof. rewrite (sameP mxdirect_addsP eqP) -trivg_rowg rowgI => /eqP tiAB. by rewrite -cprod_rowg dprodEcp. Qed. Lemma bigcprod_rowg m I r (P : pred I) (A : I -> 'M[F]_n) (B : 'M[F]_(m, n)) : (\sum_(i <- r | P i) A i :=: B)%MS -> \big[cprod/1%g]_(i <- r | P i) rowg (A i) = rowg B. Proof. by move/eq_rowg <-; apply/esym/big_morph=> [? ?|]; rewrite (rowg0, cprod_rowg). Qed. Lemma bigdprod_rowg m (I : finType) (P : pred I) A (B : 'M[F]_(m, n)) : let S := (\sum_(i | P i) A i)%MS in (S :=: B)%MS -> mxdirect S -> \big[dprod/1%g]_(i | P i) rowg (A i) = rowg B. Proof. move=> S defS; rewrite mxdirectE defS /= => /eqP rankB. apply: bigcprod_card_dprod (bigcprod_rowg defS) (eq_leq _). by rewrite card_rowg rankB expn_sum; apply: eq_bigr => i; rewrite card_rowg. Qed. End RowGroup. Variables (gT : finGroupType) (G : {group gT}) (n' : nat). Local Notation n := n'.+1. Variable (rG : mx_representation F G n). Fact GL_mx_repr : mx_repr 'GL_n[F] GLval. Proof. by []. Qed. Canonical GLrepr := MxRepresentation GL_mx_repr. Lemma GLmx_faithful : mx_faithful GLrepr. Proof. by apply/subsetP=> A; rewrite !inE mul1mx. Qed. Definition reprGLm x : {'GL_n[F]} := insubd (1%g : {'GL_n[F]}) (rG x). Lemma val_reprGLm x : x \in G -> val (reprGLm x) = rG x. Proof. by move=> Gx; rewrite val_insubd (repr_mx_unitr rG). Qed. Lemma comp_reprGLm : {in G, GLval \o reprGLm =1 rG}. Proof. exact: val_reprGLm. Qed. Lemma reprGLmM : {in G &, {morph reprGLm : x y / x * y}}%g. Proof. by move=> x y Gx Gy; apply: val_inj; rewrite /= !val_reprGLm ?groupM ?repr_mxM. Qed. Canonical reprGL_morphism := Morphism reprGLmM. Lemma ker_reprGLm : 'ker reprGLm = rker rG. Proof. apply/setP=> x; rewrite !inE mul1mx; apply: andb_id2l => Gx. by rewrite -val_eqE val_reprGLm. Qed. Lemma astab_rowg_repr m (A : 'M_(m, n)) : 'C(rowg A | 'MR rG) = rstab rG A. Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx. apply/subsetP/eqP=> cAx => [|u]; last first. by rewrite !inE mx_repr_actE // => /submxP[u' ->]; rewrite -mulmxA cAx. apply/row_matrixP=> i; apply/eqP; move/implyP: (cAx (row i A)). by rewrite !inE row_sub mx_repr_actE //= row_mul. Qed. Lemma astabs_rowg_repr m (A : 'M_(m, n)) : 'N(rowg A | 'MR rG) = rstabs rG A. Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx. apply/subsetP/idP=> nAx => [|u]; last first. by rewrite !inE mx_repr_actE // => Au; apply: (submx_trans (submxMr _ Au)). apply/row_subP=> i; move/implyP: (nAx (row i A)). by rewrite !inE row_sub mx_repr_actE //= row_mul. Qed. Lemma acts_rowg (A : 'M_n) : [acts G, on rowg A | 'MR rG] = mxmodule rG A. Proof. by rewrite astabs_rowg_repr. Qed. Lemma astab_setT_repr : 'C(setT | 'MR rG) = rker rG. Proof. by rewrite -rowg1 astab_rowg_repr. Qed. Lemma mx_repr_action_faithful : [faithful G, on setT | 'MR rG] = mx_faithful rG. Proof. by rewrite /faithful astab_setT_repr (setIidPr _) // [rker _]setIdE subsetIl. Qed. Lemma afix_repr (H : {set gT}) : H \subset G -> 'Fix_('MR rG)(H) = rowg (rfix_mx rG H). Proof. move/subsetP=> sHG; apply/setP=> /= u; rewrite !inE. apply/subsetP/rfix_mxP=> cHu x Hx; have:= cHu x Hx; by rewrite !inE /= => /eqP; rewrite mx_repr_actE ?sHG. Qed. Lemma gacent_repr (H : {set gT}) : H \subset G -> 'C_(| 'MR rG)(H) = rowg (rfix_mx rG H). Proof. by move=> sHG; rewrite gacentE // setTI afix_repr. Qed. End FinFieldRepr. Arguments rowg_mx {F n%_N} L%_g. Notation "''Zm'" := (scale_action _ _ _) : action_scope. Notation "''Zm'" := (scale_groupAction _ _ _) : groupAction_scope. Section MatrixGroups. Implicit Types m n p q : nat. Lemma exponent_mx_group m n q : m > 0 -> n > 0 -> q > 1 -> exponent [set: 'M['Z_q]_(m, n)] = q. Proof. move=> m_gt0 n_gt0 q_gt1; apply/eqP; rewrite eqn_dvd; apply/andP; split. apply/exponentP=> x _; apply/matrixP=> i j; rewrite mulmxnE !mxE. by rewrite -mulr_natr -Zp_nat_mod // modnn mulr0. pose cmx1 := const_mx 1%R : 'M['Z_q]_(m, n). apply: dvdn_trans (dvdn_exponent (in_setT cmx1)). have/matrixP/(_ (Ordinal m_gt0))/(_ (Ordinal n_gt0))/eqP := expg_order cmx1. by rewrite mulmxnE !mxE -order_dvdn order_Zp1 Zp_cast. Qed. Lemma rank_mx_group m n q : 'r([set: 'M['Z_q]_(m, n)]) = (m * n)%N. Proof. wlog q_gt1: q / q > 1 by case: q => [|[|q -> //]] /(_ 2)->. set G := setT; have cGG: abelian G := zmod_abelian _. have [mn0 | ] := posnP (m * n). by rewrite [G](card1_trivg _) ?rank1 // cardsT card_mx mn0. rewrite muln_gt0 => /andP[m_gt0 n_gt0]. have expG: exponent G = q := exponent_mx_group m_gt0 n_gt0 q_gt1. apply/eqP; rewrite eqn_leq andbC -(leq_exp2l _ _ q_gt1) -{2}expG. have ->: (q ^ (m * n))%N = #|G| by rewrite cardsT card_mx card_ord Zp_cast. rewrite max_card_abelian //= -grank_abelian //= -/G. pose B : {set 'M['Z_q]_(m, n)} := [set delta_mx ij.1 ij.2 | ij : 'I_m * 'I_n]. suffices ->: G = <<B>>. have ->: (m * n)%N = #|{: 'I_m * 'I_n}| by rewrite card_prod !card_ord. exact: leq_trans (grank_min _) (leq_imset_card _ _). apply/setP=> v; rewrite inE (matrix_sum_delta v). rewrite group_prod // => i _; rewrite group_prod // => j _. rewrite -[v i j]natr_Zp scaler_nat groupX // mem_gen //. by apply/imsetP; exists (i, j). Qed. Lemma mx_group_homocyclic m n q : homocyclic [set: 'M['Z_q]_(m, n)]. Proof. wlog q_gt1: q / q > 1 by case: q => [|[|q -> //]] /(_ 2)->. set G := setT; have cGG: abelian G := zmod_abelian _. rewrite -max_card_abelian //= rank_mx_group cardsT card_mx card_ord -/G. rewrite {1}Zp_cast //; have [-> // | ] := posnP (m * n). by rewrite muln_gt0 => /andP[m_gt0 n_gt0]; rewrite exponent_mx_group. Qed. Lemma abelian_type_mx_group m n q : q > 1 -> abelian_type [set: 'M['Z_q]_(m, n)] = nseq (m * n) q. Proof. rewrite (abelian_type_homocyclic (mx_group_homocyclic m n q)) rank_mx_group. have [-> // | ] := posnP (m * n); rewrite muln_gt0 => /andP[m_gt0 n_gt0] q_gt1. by rewrite exponent_mx_group. Qed. End MatrixGroups. Delimit Scope abelem_scope with Mg. Open Scope abelem_scope. Definition abelem_dim' (gT : finGroupType) (E : {set gT}) := (logn (pdiv #|E|) #|E|).-1. Arguments abelem_dim' {gT} E%_g. Notation "''dim' E" := (abelem_dim' E).+1 (at level 10, E at level 8, format "''dim' E") : abelem_scope. Notation "''rV' ( E )" := 'rV_('dim E) (format "''rV' ( E )") : abelem_scope. Notation "''M' ( E )" := 'M_('dim E) (format "''M' ( E )") : abelem_scope. Notation "''rV[' F ] ( E )" := 'rV[F]_('dim E) (only parsing) : abelem_scope. Notation "''M[' F ] ( E )" := 'M[F]_('dim E) (only parsing) : abelem_scope. Section AbelemRepr. Section FpMatrix. Variables p m n : nat. Local Notation Mmn := 'M['F_p]_(m, n). Lemma mx_Fp_abelem : prime p -> p.-abelem [set: Mmn]. Proof. exact: fin_Fp_lmod_abelem. Qed. Lemma mx_Fp_stable (L : {group Mmn}) : [acts setT, on L | 'Zm]. Proof. apply/subsetP=> a _ /[!inE]; apply/subsetP=> A L_A. by rewrite inE /= /scale_act -[val _]natr_Zp scaler_nat groupX. Qed. End FpMatrix. Section FpRow. Variables p n : nat. Local Notation rVn := 'rV['F_p]_n. Lemma rowg_mxK (L : {group rVn}) : rowg (rowg_mx L) = L. Proof. by apply: stable_rowg_mxK; apply: mx_Fp_stable. Qed. Lemma rowg_mxSK (L : {set rVn}) (M : {group rVn}) : (rowg_mx L <= rowg_mx M)%MS = (L \subset M). Proof. apply/idP/idP; last exact: rowg_mxS. by rewrite -rowgS rowg_mxK; apply/subset_trans/sub_rowg_mx. Qed. Lemma mxrank_rowg (L : {group rVn}) : prime p -> \rank (rowg_mx L) = logn p #|L|. Proof. by move=> p_pr; rewrite -{2}(rowg_mxK L) card_rowg card_Fp ?pfactorK. Qed. End FpRow. Variables (p : nat) (gT : finGroupType) (E : {group gT}). Hypotheses (abelE : p.-abelem E) (ntE : E :!=: 1%g). Let pE : p.-group E := abelem_pgroup abelE. Let p_pr : prime p. Proof. by have [] := pgroup_pdiv pE ntE. Qed. Local Notation n' := (abelem_dim' (gval E)). Local Notation n := n'.+1. Local Notation rVn := 'rV['F_p](gval E). Lemma dim_abelemE : n = logn p #|E|. Proof. rewrite /n'; have [_ _ [k ->]] := pgroup_pdiv pE ntE. by rewrite /pdiv primesX ?primes_prime // pfactorK. Qed. Lemma card_abelem_rV : #|rVn| = #|E|. Proof. by rewrite dim_abelemE card_mx mul1n card_Fp // -p_part part_pnat_id. Qed. Lemma isog_abelem_rV : E \isog [set: rVn]. Proof. by rewrite (isog_abelem_card _ abelE) cardsT card_abelem_rV mx_Fp_abelem /=. Qed. Local Notation ab_rV_P := (existsP isog_abelem_rV). Definition abelem_rV : gT -> rVn := xchoose ab_rV_P. Local Notation ErV := abelem_rV. Lemma abelem_rV_M : {in E &, {morph ErV : x y / (x * y)%g >-> x + y}}. Proof. by case/misomP: (xchooseP ab_rV_P) => fM _; move/morphicP: fM. Qed. Canonical abelem_rV_morphism := Morphism abelem_rV_M. Lemma abelem_rV_isom : isom E setT ErV. Proof. by case/misomP: (xchooseP ab_rV_P). Qed. Lemma abelem_rV_injm : 'injm ErV. Proof. by case/isomP: abelem_rV_isom. Qed. Lemma abelem_rV_inj : {in E &, injective ErV}. Proof. by apply/injmP; apply: abelem_rV_injm. Qed. Lemma im_abelem_rV : ErV @* E = setT. Proof. by case/isomP: abelem_rV_isom. Qed. Lemma mem_im_abelem_rV u : u \in ErV @* E. Proof. by rewrite im_abelem_rV inE. Qed. Lemma sub_im_abelem_rV mA : subset mA (mem (ErV @* E)). Proof. by rewrite unlock; apply/pred0P=> v /=; rewrite mem_im_abelem_rV. Qed. Hint Resolve mem_im_abelem_rV sub_im_abelem_rV : core. Lemma abelem_rV_1 : ErV 1 = 0%R. Proof. by rewrite morph1. Qed. Lemma abelem_rV_X x i : x \in E -> ErV (x ^+ i) = i%:R *: ErV x. Proof. by move=> Ex; rewrite morphX // scaler_nat. Qed. Lemma abelem_rV_V x : x \in E -> ErV x^-1 = - ErV x. Proof. by move=> Ex; rewrite morphV. Qed. Definition rVabelem : rVn -> gT := invm abelem_rV_injm. Canonical rVabelem_morphism := [morphism of rVabelem]. Local Notation rV_E := rVabelem. Lemma rVabelem0 : rV_E 0 = 1%g. Proof. exact: morph1. Qed. Lemma rVabelemD : {morph rV_E : u v / u + v >-> (u * v)%g}. Proof. by move=> u v /=; rewrite -morphM. Qed. Lemma rVabelemN : {morph rV_E: u / - u >-> (u^-1)%g}. Proof. by move=> u /=; rewrite -morphV. Qed. Lemma rVabelemZ (m : 'F_p) : {morph rV_E : u / m *: u >-> (u ^+ m)%g}. Proof. by move=> u; rewrite /= -morphX -?[(u ^+ m)%g]scaler_nat ?natr_Zp. Qed. Lemma abelem_rV_K : {in E, cancel ErV rV_E}. Proof. exact: invmE. Qed. Lemma rVabelemK : cancel rV_E ErV. Proof. by move=> u; rewrite invmK. Qed. Lemma rVabelem_inj : injective rV_E. Proof. exact: can_inj rVabelemK. Qed. Lemma rVabelem_injm : 'injm rV_E. Proof. exact: injm_invm abelem_rV_injm. Qed. Lemma im_rVabelem : rV_E @* setT = E. Proof. by rewrite -im_abelem_rV im_invm. Qed. Lemma mem_rVabelem u : rV_E u \in E. Proof. by rewrite -im_rVabelem mem_morphim. Qed. Lemma sub_rVabelem L : rV_E @* L \subset E. Proof. by rewrite -[_ @* L]morphimIim im_invm subsetIl. Qed. Hint Resolve mem_rVabelem sub_rVabelem : core. Lemma card_rVabelem L : #|rV_E @* L| = #|L|. Proof. by rewrite card_injm ?rVabelem_injm. Qed. Lemma abelem_rV_mK (H : {set gT}) : H \subset E -> rV_E @* (ErV @* H) = H. Proof. exact: morphim_invm abelem_rV_injm H. Qed. Lemma rVabelem_mK L : ErV @* (rV_E @* L) = L. Proof. by rewrite morphim_invmE morphpreK. Qed. Lemma rVabelem_minj : injective (morphim (MorPhantom rV_E)). Proof. exact: can_inj rVabelem_mK. Qed. Lemma rVabelemS L M : (rV_E @* L \subset rV_E @* M) = (L \subset M). Proof. by rewrite injmSK ?rVabelem_injm. Qed. Lemma abelem_rV_S (H K : {set gT}) : H \subset E -> (ErV @* H \subset ErV @* K) = (H \subset K). Proof. by move=> sHE; rewrite injmSK ?abelem_rV_injm. Qed. Lemma sub_rVabelem_im L (H : {set gT}) : (rV_E @* L \subset H) = (L \subset ErV @* H). Proof. by rewrite sub_morphim_pre ?morphpre_invm. Qed. Lemma sub_abelem_rV_im (H : {set gT}) (L : {set 'rV['F_p]_n}) : H \subset E -> (ErV @* H \subset L) = (H \subset rV_E @* L). Proof. by move=> sHE; rewrite sub_morphim_pre ?morphim_invmE. Qed. Section OneGroup. Variable G : {group gT}. Definition abelem_mx_fun (g : subg_of G) v := ErV ((rV_E v) ^ val g). Definition abelem_mx of G \subset 'N(E) := fun x => lin1_mx (abelem_mx_fun (subg G x)). Hypothesis nEG : G \subset 'N(E). Local Notation r := (abelem_mx nEG). Fact abelem_mx_linear_proof g : linear (abelem_mx_fun g). Proof. rewrite /abelem_mx_fun; case: g => x /= /(subsetP nEG) Nx /= m u v. rewrite rVabelemD rVabelemZ conjMg conjXg. by rewrite abelem_rV_M ?abelem_rV_X ?groupX ?memJ_norm // natr_Zp. Qed. HB.instance Definition _ (g : [subg G]) := GRing.isSemilinear.Build 'F_p rVn rVn _ (abelem_mx_fun g) (GRing.semilinear_linear (abelem_mx_linear_proof g)). Let rVabelemJmx v x : x \in G -> rV_E (v *m r x) = (rV_E v) ^ x. Proof. move=> Gx; rewrite /= mul_rV_lin1 /= /abelem_mx_fun subgK //. by rewrite abelem_rV_K // memJ_norm // (subsetP nEG). Qed. Fact abelem_mx_repr : mx_repr G r. Proof. split=> [|x y Gx Gy]; apply/row_matrixP=> i; apply: rVabelem_inj. by rewrite rowE -row1 rVabelemJmx // conjg1. by rewrite !rowE mulmxA !rVabelemJmx ?groupM // conjgM. Qed. Canonical abelem_repr := MxRepresentation abelem_mx_repr. Let rG := abelem_repr. Lemma rVabelemJ v x : x \in G -> rV_E (v *m rG x) = (rV_E v) ^ x. Proof. exact: rVabelemJmx. Qed. Lemma abelem_rV_J : {in E & G, forall x y, ErV (x ^ y) = ErV x *m rG y}. Proof. by move=> x y Ex Gy; rewrite -{1}(abelem_rV_K Ex) -rVabelemJ ?rVabelemK. Qed. Lemma abelem_rowgJ m (A : 'M_(m, n)) x : x \in G -> rV_E @* rowg (A *m rG x) = (rV_E @* rowg A) :^ x. Proof. move=> Gx; apply: (canRL (conjsgKV _)); apply/setP=> y. rewrite mem_conjgV !morphim_invmE !inE memJ_norm ?(subsetP nEG) //=. apply: andb_id2l => Ey; rewrite abelem_rV_J //. by rewrite submxMfree // row_free_unit (repr_mx_unit rG). Qed. Lemma rV_abelem_sJ (L : {group gT}) x : x \in G -> L \subset E -> ErV @* (L :^ x) = rowg (rowg_mx (ErV @* L) *m rG x). Proof. move=> Gx sLE; apply: rVabelem_minj; rewrite abelem_rowgJ //. by rewrite rowg_mxK !morphim_invm // -(normsP nEG x Gx) conjSg. Qed. Lemma rstab_abelem m (A : 'M_(m, n)) : rstab rG A = 'C_G(rV_E @* rowg A). Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx; apply/eqP/centP => cAx. move=> _ /morphimP[u _ + ->] => /[1!inE] /submxP[{}u ->]. by apply/esym/commgP/conjg_fixP; rewrite -rVabelemJ -?mulmxA ?cAx. apply/row_matrixP=> i; apply: rVabelem_inj. by rewrite row_mul rVabelemJ // /conjg -cAx ?mulKg ?mem_morphim // inE row_sub. Qed. Lemma rstabs_abelem m (A : 'M_(m, n)) : rstabs rG A = 'N_G(rV_E @* rowg A). Proof. apply/setP=> x /[!inE]/=; apply: andb_id2l => Gx. by rewrite -rowgS -rVabelemS abelem_rowgJ. Qed. Lemma rstabs_abelemG (L : {group gT}) : L \subset E -> rstabs rG (rowg_mx (ErV @* L)) = 'N_G(L). Proof. by move=> sLE; rewrite rstabs_abelem rowg_mxK morphim_invm. Qed. Lemma mxmodule_abelem m (U : 'M['F_p]_(m, n)) : mxmodule rG U = (G \subset 'N(rV_E @* rowg U)). Proof. by rewrite -subsetIidl -rstabs_abelem. Qed. Lemma mxmodule_abelemG (L : {group gT}) : L \subset E -> mxmodule rG (rowg_mx (ErV @* L)) = (G \subset 'N(L)). Proof. by move=> sLE; rewrite -subsetIidl -rstabs_abelemG. Qed. Lemma mxsimple_abelemP (U : 'M['F_p]_n) : reflect (mxsimple rG U) (minnormal (rV_E @* rowg U) G). Proof. apply: (iffP mingroupP) => [[/andP[ntU modU] minU] | [modU ntU minU]]. split=> [||V modV sVU ntV]; first by rewrite mxmodule_abelem. by apply: contraNneq ntU => ->; rewrite /= rowg0 morphim1. rewrite -rowgS -rVabelemS [_ @* rowg V]minU //. rewrite -subG1 sub_rVabelem_im morphim1 subG1 trivg_rowg ntV /=. by rewrite -mxmodule_abelem. by rewrite rVabelemS rowgS. split=> [|D /andP[ntD nDG sDU]]. rewrite -subG1 sub_rVabelem_im morphim1 subG1 trivg_rowg ntU /=. by rewrite -mxmodule_abelem. apply/eqP; rewrite eqEsubset sDU sub_rVabelem_im /= -rowg_mxSK rowgK. have sDE: D \subset E := subset_trans sDU (sub_rVabelem _). rewrite minU ?mxmodule_abelemG //. by rewrite -rowgS rowg_mxK sub_abelem_rV_im. by rewrite rowg_mx_eq0 (morphim_injm_eq1 abelem_rV_injm). Qed. Lemma mxsimple_abelemGP (L : {group gT}) : L \subset E -> reflect (mxsimple rG (rowg_mx (ErV @* L))) (minnormal L G). Proof. move/abelem_rV_mK=> {2}<-; rewrite -{2}[_ @* L]rowg_mxK. exact: mxsimple_abelemP. Qed. Lemma abelem_mx_irrP : reflect (mx_irreducible rG) (minnormal E G). Proof. by rewrite -[E in minnormal E G]im_rVabelem -rowg1; apply: mxsimple_abelemP. Qed. Lemma rfix_abelem (H : {set gT}) : H \subset G -> (rfix_mx rG H :=: rowg_mx (ErV @* 'C_E(H)%g))%MS. Proof. move/subsetP=> sHG; apply/eqmxP/andP; split. rewrite -rowgS rowg_mxK -sub_rVabelem_im // subsetI sub_rVabelem /=. apply/centsP=> y /morphimP[v _] /[1!inE] cGv ->{y} x Gx. by apply/commgP/conjg_fixP; rewrite /= -rVabelemJ ?sHG ?(rfix_mxP H _). rewrite genmxE; apply/rfix_mxP=> x Hx; apply/row_matrixP=> i. rewrite row_mul rowK; case/morphimP: (enum_valP i) => z Ez /setIP[_ cHz] ->. by rewrite -abelem_rV_J ?sHG // conjgE (centP cHz) ?mulKg. Qed. Lemma rker_abelem : rker rG = 'C_G(E). Proof. by rewrite /rker rstab_abelem rowg1 im_rVabelem. Qed. Lemma abelem_mx_faithful : 'C_G(E) = 1%g -> mx_faithful rG. Proof. by rewrite /mx_faithful rker_abelem => ->. Qed. End OneGroup. Section SubGroup. Variables G H : {group gT}. Hypotheses (nEG : G \subset 'N(E)) (sHG : H \subset G). Let nEH := subset_trans sHG nEG. Local Notation rG := (abelem_repr nEG). Local Notation rHG := (subg_repr rG sHG). Local Notation rH := (abelem_repr nEH). Lemma eq_abelem_subg_repr : {in H, rHG =1 rH}. Proof. move=> x Hx; apply/row_matrixP=> i; rewrite !rowE !mul_rV_lin1 /=. by rewrite /abelem_mx_fun !subgK ?(subsetP sHG). Qed. Lemma rsim_abelem_subg : mx_rsim rHG rH. Proof. exists 1%:M => [//| |x Hx]; first by rewrite row_free_unit unitmx1. by rewrite mul1mx mulmx1 eq_abelem_subg_repr. Qed. Lemma mxmodule_abelem_subg m (U : 'M_(m, n)) : mxmodule rHG U = mxmodule rH U. Proof. apply: eq_subset_r => x. rewrite [LHS]inE inE; apply: andb_id2l => Hx. by rewrite eq_abelem_subg_repr. Qed. Lemma mxsimple_abelem_subg U : mxsimple rHG U <-> mxsimple rH U. Proof. have eq_modH := mxmodule_abelem_subg; rewrite /mxsimple eq_modH. by split=> [] [-> -> minU]; split=> [//|//|V]; have:= minU V; rewrite eq_modH. Qed. End SubGroup. End AbelemRepr. Arguments rVabelem_inj {p%_N gT E%_G} abelE ntE [v1%_R v2%_R] : rename. Section ModularRepresentation. Variables (F : fieldType) (p : nat) (gT : finGroupType). Hypothesis pcharFp : p \in [pchar F]. Implicit Types G H : {group gT}. (* This is Gorenstein, Lemma 2.6.3. *) Lemma rfix_pgroup_pchar G H n (rG : mx_representation F G n) : n > 0 -> p.-group H -> H \subset G -> rfix_mx rG H != 0. Proof. move=> n_gt0 pH sHG; rewrite -(rfix_subg rG sHG). move: {2}_.+1 (ltnSn (n + #|H|)) {rG G sHG}(subg_repr _ _) => m. elim: m gT H pH => // m IHm gT' G pG in n n_gt0 *; rewrite ltnS => le_nG_m rG. apply/eqP=> Gregular; have irrG: mx_irreducible rG. apply/mx_irrP; split=> // U modU; rewrite -mxrank_eq0 -lt0n => Unz. rewrite /row_full eqn_leq rank_leq_col leqNgt; apply/negP=> ltUn. have: rfix_mx (submod_repr modU) G != 0. by apply: IHm => //; apply: leq_trans le_nG_m; rewrite ltn_add2r. by rewrite -mxrank_eq0 (rfix_submod modU) // Gregular capmx0 linear0 mxrank0. have{m le_nG_m IHm} faithfulG: mx_faithful rG. apply/trivgP/eqP/idPn; set C := _ rG => ntC. suffices: rfix_mx (kquo_repr rG) (G / _)%g != 0. by rewrite -mxrank_eq0 rfix_quo // Gregular mxrank0. apply: (IHm _ _ (morphim_pgroup _ _)) => //. by apply: leq_trans le_nG_m; rewrite ltn_add2l ltn_quotient // rstab_sub. have{Gregular} ntG: G :!=: 1%g. apply: contraL n_gt0; move/eqP=> G1; rewrite -leqNgt -(mxrank1 F n). rewrite -(mxrank0 F n n) -Gregular mxrankS //; apply/rfix_mxP=> x. by rewrite {1}G1 mul1mx => /set1P->; rewrite repr_mx1. have p_pr: prime p by case/andP: pcharFp. have{ntG pG} [z]: {z | z \in 'Z(G) & #[z] = p}; last case/setIP=> Gz cGz ozp. apply: Cauchy => //; apply: contraR ntG; rewrite -p'natE // => p'Z. have pZ: p.-group 'Z(G) by rewrite (pgroupS (center_sub G)). by rewrite (trivg_center_pgroup pG (card1_trivg (pnat_1 pZ p'Z))). have{cGz} cGz1: centgmx rG (rG z - 1%:M). apply/centgmxP=> x Gx; rewrite mulmxBl mulmxBr mulmx1 mul1mx. by rewrite -!repr_mxM // (centP cGz). have{irrG faithfulG cGz1} Urz1: rG z - 1%:M \in unitmx. apply: (mx_Schur irrG) cGz1 _; rewrite subr_eq0. move/implyP: (subsetP faithfulG z). by rewrite !inE Gz mul1mx -order_eq1 ozp -implybNN neq_ltn orbC prime_gt1. do [case: n n_gt0 => // n' _; set n := n'.+1] in rG Urz1 *. have pcharMp: p \in [pchar 'M[F]_n]. exact: (rmorph_pchar (@scalar_mx F n)). have{Urz1}: pFrobenius_aut pcharMp (rG z - 1) \in GRing.unit by rewrite unitrX. rewrite (pFrobenius_autB_comm _ (commr1 _)) pFrobenius_aut1. by rewrite -[_ (rG z)](repr_mxX rG) // -ozp expg_order repr_mx1 subrr unitr0. Qed. Variables (G : {group gT}) (n : nat) (rG : mx_representation F G n). Lemma pcore_sub_rstab_mxsimple_pchar M : mxsimple rG M -> 'O_p(G) \subset rstab rG M. Proof. case=> modM nzM simM; have sGpG := pcore_sub p G. rewrite rfix_mx_rstabC //; set U := rfix_mx _ _. have:= simM (M :&: U)%MS; rewrite sub_capmx submx_refl. apply; rewrite ?capmxSl //. by rewrite capmx_module // normal_rfix_mx_module ?pcore_normal. rewrite -(in_submodK (capmxSl _ _)) val_submod_eq0 -submx0. rewrite -(rfix_submod modM) // submx0 rfix_pgroup_pchar ?pcore_pgroup //. by rewrite lt0n mxrank_eq0. Qed. Lemma pcore_sub_rker_mx_irr_pchar : mx_irreducible rG -> 'O_p(G) \subset rker rG. Proof. exact: pcore_sub_rstab_mxsimple_pchar. Qed. (* This is Gorenstein, Lemma 3.1.3. *) Lemma pcore_faithful_mx_irr_pchar : mx_irreducible rG -> mx_faithful rG -> 'O_p(G) = 1%g. Proof. move=> irrG ffulG; apply/trivgP; apply: subset_trans ffulG. exact: pcore_sub_rstab_mxsimple_pchar. Qed. End ModularRepresentation. #[deprecated(since="mathcomp 2.4.0", note="Use rfix_pgroup_pchar instead.")] Notation rfix_pgroup_char := (rfix_pgroup_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcore_sub_rstab_mxsimple_pchar instead.")] Notation pcore_sub_rstab_mxsimple := (pcore_sub_rstab_mxsimple_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcore_sub_rker_mx_irr_pchar instead.")] Notation pcore_sub_rker_mx_irr := (pcore_sub_rker_mx_irr_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use pcore_faithful_mx_irr_pchar instead.")] Notation pcore_faithful_mx_irr := (pcore_faithful_mx_irr_pchar) (only parsing). Section Extraspecial. Variables (F : fieldType) (gT : finGroupType) (S : {group gT}) (p n : nat). Hypotheses (pS : p.-group S) (esS : extraspecial S). Hypothesis oSpn : #|S| = (p ^ n.*2.+1)%N. Hypotheses (splitF : group_splitting_field F S) (F'S : [pchar F]^'.-group S). Let p_pr := extraspecial_prime pS esS. Let p_gt0 := prime_gt0 p_pr. Let p_gt1 := prime_gt1 p_pr. Let oZp := card_center_extraspecial pS esS. Let modIp' (i : 'I_p.-1) : (i.+1 %% p = i.+1)%N. Proof. by case: i => i; rewrite /= -ltnS prednK //; apply: modn_small. Qed. (* This is Aschbacher (34.9), parts (1)-(4). *) Theorem extraspecial_repr_structure_pchar (sS : irrType F S) : [/\ #|linear_irr sS| = (p ^ n.*2)%N, exists iphi : 'I_p.-1 -> sS, let phi i := irr_repr (iphi i) in [/\ injective iphi, codom iphi =i ~: linear_irr sS, forall i, mx_faithful (phi i), forall z, z \in 'Z(S)^# -> exists2 w, primitive_root_of_unity p w & forall i, phi i z = (w ^+ i.+1)%:M & forall i, irr_degree (iphi i) = (p ^ n)%N] & #|sS| = (p ^ n.*2 + p.-1)%N]. Proof. have [[defPhiS defS'] prZ] := esS; set linS := linear_irr sS. have nb_lin: #|linS| = (p ^ n.*2)%N. rewrite card_linear_irr // -divgS ?der_sub //=. by rewrite oSpn defS' oZp expnS mulKn. have nb_irr: #|sS| = (p ^ n.*2 + p.-1)%N. pose Zcl := classes S ::&: 'Z(S). have cardZcl: #|Zcl| = p. transitivity #|[set [set z] | z in 'Z(S)]|; last first. by rewrite card_imset //; apply: set1_inj. apply: eq_card => zS; apply/setIdP/imsetP=> [[] | [z]]. case/imsetP=> z Sz ->{zS} szSZ. have Zz: z \in 'Z(S) by rewrite (subsetP szSZ) ?class_refl. exists z => //; rewrite inE Sz in Zz. apply/eqP; rewrite eq_sym eqEcard sub1set class_refl cards1. by rewrite -index_cent1 (setIidPl _) ?indexgg // sub_cent1. case/setIP=> Sz cSz ->{zS}; rewrite sub1set inE Sz; split=> //. apply/imsetP; exists z; rewrite //. apply/eqP; rewrite eqEcard sub1set class_refl cards1. by rewrite -index_cent1 (setIidPl _) ?indexgg // sub_cent1. move/eqP: (class_formula S); rewrite (bigID [in Zcl]) /=. rewrite (eq_bigr (fun _ => 1)) => [|zS]; last first. case/andP=> _ /setIdP[/imsetP[z Sz ->{zS}] /subsetIP[_ cSzS]]. rewrite (setIidPl _) ?indexgg // sub_cent1 (subsetP cSzS) //. exact: mem_repr (class_refl S z). rewrite sum1dep_card setIdE (setIidPr _) 1?cardsE ?cardZcl; last first. by apply/subsetP=> zS /[!inE] /andP[]. have pn_gt0: p ^ n.*2 > 0 by rewrite expn_gt0 p_gt0. rewrite card_irr_pchar // oSpn expnS -(prednK pn_gt0) mulnS eqn_add2l. rewrite (eq_bigr (fun _ => p)) => [|xS]; last first. case/andP=> SxS; rewrite inE SxS; case/imsetP: SxS => x Sx ->{xS} notZxS. have [y Sy ->] := repr_class S x; apply: p_maximal_index => //. apply: cent1_extraspecial_maximal => //; first exact: groupJ. apply: contra notZxS => Zxy; rewrite -{1}(lcoset_id Sy) class_lcoset. rewrite ((_ ^: _ =P [set x ^ y])%g _) ?sub1set // eq_sym eqEcard. rewrite sub1set class_refl cards1 -index_cent1 (setIidPl _) ?indexgg //. by rewrite sub_cent1; apply: subsetP Zxy; apply: subsetIr. rewrite sum_nat_cond_const mulnC eqn_pmul2l //; move/eqP <-. rewrite addSnnS prednK // -cardZcl -[card _](cardsID Zcl) /= addnC. by congr (_ + _)%N; apply: eq_card => t; rewrite !inE andbC // andbAC andbb. have fful_nlin i: i \in ~: linS -> mx_faithful (irr_repr i). rewrite !inE => nlin_phi. apply/trivgP; apply: (TI_center_nil (pgroup_nil pS) (rker_normal _)). rewrite setIC; apply: (prime_TIg prZ); rewrite /= -defS' der1_sub_rker //. exact: socle_irr. have [i0 nlin_i0]: exists i0, i0 \in ~: linS. by apply/card_gt0P; rewrite cardsCs setCK nb_irr nb_lin addKn -subn1 subn_gt0. have [z defZ]: exists z, 'Z(S) = <[z]> by apply/cyclicP; rewrite prime_cyclic. have Zz: z \in 'Z(S) by [rewrite defZ cycle_id]; have [Sz cSz] := setIP Zz. have ozp: #[z] = p by rewrite -oZp defZ. have ntz: z != 1%g by rewrite -order_gt1 ozp. pose phi := irr_repr i0; have irr_phi: mx_irreducible phi := socle_irr i0. pose w := irr_mode i0 z. have phi_z: phi z = w%:M by rewrite /phi irr_center_scalar. have phi_ze e: phi (z ^+ e)%g = (w ^+ e)%:M. by rewrite /phi irr_center_scalar ?groupX ?irr_modeX. have wp1: w ^+ p = 1 by rewrite -irr_modeX // -ozp expg_order irr_mode1. have injw: {in 'Z(S) &, injective (irr_mode i0)}. move=> x y Zx Zy /= eq_xy; have [[Sx _] [Sy _]] := (setIP Zx, setIP Zy). apply: mx_faithful_inj (fful_nlin _ nlin_i0) _ _ Sx Sy _. by rewrite !{1}irr_center_scalar ?eq_xy; first by split. have prim_w e: 0 < e < p -> p.-primitive_root (w ^+ e). case/andP=> e_gt0 lt_e_p; apply/andP; split=> //. apply/eqfunP=> -[d ltdp] /=; rewrite unity_rootE -exprM. rewrite -(irr_mode1 i0) -irr_modeX // (inj_in_eq injw) ?groupX ?group1 //. rewrite -order_dvdn ozp Euclid_dvdM // gtnNdvd //=. move: ltdp; rewrite leq_eqVlt. by case: eqP => [-> _ | _ ltd1p]; rewrite (dvdnn, gtnNdvd). have /cyclicP[a defAutZ]: cyclic (Aut 'Z(S)) by rewrite Aut_prime_cyclic ?ozp. have phi_unitP (i : 'I_p.-1): (i.+1%:R : 'Z_#[z]) \in GRing.unit. by rewrite unitZpE ?order_gt1 // ozp prime_coprime // -lt0n !modIp'. pose ephi i := invm (injm_Zpm a) (Zp_unitm (FinRing.Unit (phi_unitP i))). pose j : 'Z_#[z] := val (invm (injm_Zp_unitm z) a). have co_j_p: coprime j p. rewrite coprime_sym /j; case: (invm _ a) => /=. by rewrite ozp /GRing.unit /= Zp_cast. have [alpha Aut_alpha alphaZ] := center_aut_extraspecial pS esS co_j_p. have alpha_i_z i: ((alpha ^+ ephi i) z = z ^+ i.+1)%g. transitivity ((a ^+ ephi i) z)%g. elim: (ephi i : nat) => // e IHe; rewrite !expgS !permM alphaZ //. have Aut_a: a \in Aut 'Z(S) by rewrite defAutZ cycle_id. rewrite -{2}[a](invmK (injm_Zp_unitm z)); last by rewrite im_Zp_unitm -defZ. rewrite /= autE ?cycle_id // -/j /= /cyclem. rewrite -(autmE (groupX _ Aut_a)) -(autmE (groupX _ Aut_alpha)). by rewrite !morphX //= !autmE IHe. rewrite [(a ^+ _)%g](invmK (injm_Zpm a)) /=; last first. by rewrite im_Zpm -defAutZ defZ Aut_aut. by rewrite autE ?cycle_id //= val_Zp_nat ozp ?modIp'. have rphiP i: S :==: autm (groupX (ephi i) Aut_alpha) @* S by rewrite im_autm. pose rphi i := morphim_repr (eqg_repr phi (rphiP i)) (subxx S). have rphi_irr i: mx_irreducible (rphi i) by apply/morphim_mx_irr/eqg_mx_irr. have rphi_fful i: mx_faithful (rphi i). rewrite /mx_faithful rker_morphim rker_eqg. by rewrite (trivgP (fful_nlin _ nlin_i0)) morphpreIdom; apply: injm_autm. have rphi_z i: rphi i z = (w ^+ i.+1)%:M. by rewrite /rphi [phi]lock /= /morphim_mx autmE alpha_i_z -lock phi_ze. pose iphi i := irr_comp sS (rphi i); pose phi_ i := irr_repr (iphi i). have{} phi_ze i e: phi_ i (z ^+ e)%g = (w ^+ (e * i.+1)%N)%:M. rewrite /phi_ !{1}irr_center_scalar ?groupX ?irr_modeX //. suffices ->: irr_mode (iphi i) z = w ^+ i.+1 by rewrite mulnC exprM. have:= mx_rsim_sym (rsim_irr_comp_pchar sS F'S (rphi_irr i)). case/mx_rsim_def=> B [B' _ homB]; rewrite /irr_mode homB // rphi_z. rewrite -{1}scalemx1 -scalemxAr -scalemxAl -{1}(repr_mx1 (rphi i)). by rewrite -homB // repr_mx1 scalemx1 mxE. have inj_iphi: injective iphi. move=> i1 i2 eqi12; apply/eqP. move/eqP: (congr1 (fun i => irr_mode i (z ^+ 1)) eqi12). rewrite /irr_mode !{1}[irr_repr _ _]phi_ze !{1}mxE !mul1n. by rewrite (eq_prim_root_expr (prim_w 1 p_gt1)) !modIp'. have deg_phi i: irr_degree (iphi i) = irr_degree i0. by case: (rsim_irr_comp_pchar sS F'S (rphi_irr i)). have im_iphi: codom iphi =i ~: linS. apply/subset_cardP; last apply/subsetP=> _ /codomP[i ->]. by rewrite card_image // card_ord cardsCs setCK nb_irr nb_lin addKn. by rewrite !inE /= (deg_phi i) in nlin_i0 *. split=> //; exists iphi; rewrite -/phi_. split=> // [i | ze | i]. - have sim_i := rsim_irr_comp_pchar sS F'S (rphi_irr i). by rewrite -(mx_rsim_faithful sim_i) rphi_fful. - rewrite {1}defZ 2!inE andbC; case/andP. case/cyclePmin=> e; rewrite ozp => lt_e_p ->{ze}. case: (posnP e) => [-> | e_gt0 _]; first by rewrite eqxx. exists (w ^+ e) => [|i]; first by rewrite prim_w ?e_gt0. by rewrite phi_ze exprM. rewrite deg_phi {i}; set d := irr_degree i0. apply/eqP; move/eqP: (sum_irr_degree_pchar sS F'S splitF). rewrite (bigID [in linS]) /= -/irr_degree. rewrite (eq_bigr (fun=> 1)) => [|i]; last by rewrite !inE; move/eqP->. rewrite sum1_card nb_lin. rewrite (eq_bigl [in codom iphi]) // => [|i]; last first. by rewrite -in_setC -im_iphi. rewrite (eq_bigr (fun=> d ^ 2))%N => [|_ /codomP[i ->]]; last first. by rewrite deg_phi. rewrite sum_nat_const card_image // card_ord oSpn (expnS p) -{3}[p]prednK //. rewrite mulSn eqn_add2l eqn_pmul2l; last by rewrite -ltnS prednK. by rewrite -muln2 expnM eqn_sqr. Qed. (* This is the corolloray of the above that is actually used in the proof of *) (* B & G, Theorem 2.5. It encapsulates the dependency on a socle of the *) (* regular representation. *) Variables (m : nat) (rS : mx_representation F S m) (U : 'M[F]_m). Hypotheses (simU : mxsimple rS U) (ffulU : rstab rS U == 1%g). Let sZS := center_sub S. Let rZ := subg_repr rS sZS. Lemma faithful_repr_extraspecial_pchar : \rank U = (p ^ n)%N /\ (forall V, mxsimple rS V -> mx_iso rZ U V -> mx_iso rS U V). Proof. suffices IH V: mxsimple rS V -> mx_iso rZ U V -> [&& \rank U == (p ^ n)%N & mxsimple_iso rS U V]. - split=> [|/= V simV isoUV]. by case/andP: (IH U simU (mx_iso_refl _ _)) => /eqP. by case/andP: (IH V simV isoUV) => _ /(mxsimple_isoP simU). move=> simV isoUV; wlog sS: / irrType F S by apply: socle_exists. have [[_ defS'] prZ] := esS. have{prZ} ntZ: 'Z(S) :!=: 1%g by case: eqP prZ => // ->; rewrite cards1. have [_ [iphi]] := extraspecial_repr_structure_pchar sS. set phi := fun i => _ => [] [inj_phi im_phi _ phiZ dim_phi] _. have [modU nzU _]:= simU; pose rU := submod_repr modU. have nlinU: \rank U != 1. apply/eqP=> /(rker_linear rU); apply/negP; rewrite /rker rstab_submod. by rewrite (eqmx_rstab _ (val_submod1 _)) (eqP ffulU) defS' subG1. have irrU: mx_irreducible rU by apply/submod_mx_irr. have rsimU := rsim_irr_comp_pchar sS F'S irrU. set iU := irr_comp sS rU in rsimU; have [_ degU _ _]:= rsimU. have phiUP: iU \in codom iphi by rewrite im_phi !inE -degU. rewrite degU -(f_iinv phiUP) dim_phi eqxx /=; apply/(mxsimple_isoP simU). have [modV _ _]:= simV; pose rV := submod_repr modV. have irrV: mx_irreducible rV by apply/submod_mx_irr. have rsimV := rsim_irr_comp_pchar sS F'S irrV. set iV := irr_comp sS rV in rsimV; have [_ degV _ _]:= rsimV. have phiVP: iV \in codom iphi by rewrite im_phi !inE -degV -(mxrank_iso isoUV). pose jU := iinv phiUP; pose jV := iinv phiVP. have [z Zz ntz]:= trivgPn _ ntZ. have [|w prim_w phi_z] := phiZ z; first by rewrite 2!inE ntz. suffices eqjUV: jU == jV. apply/(mx_rsim_iso modU modV); apply: mx_rsim_trans rsimU _. by rewrite -(f_iinv phiUP) -/jU (eqP eqjUV) f_iinv; apply: mx_rsim_sym. have rsimUV: mx_rsim (subg_repr (phi jU) sZS) (subg_repr (phi jV) sZS). have [bU _ bUfree bUhom] := mx_rsim_sym rsimU. have [bV _ bVfree bVhom] := rsimV. have modUZ := mxmodule_subg sZS modU; have modVZ := mxmodule_subg sZS modV. case/(mx_rsim_iso modUZ modVZ): isoUV => [bZ degZ bZfree bZhom]. rewrite /phi !f_iinv; exists (bU *m bZ *m bV)=> [||x Zx]. - by rewrite -degU degZ degV. - by rewrite /row_free !mxrankMfree. have Sx := subsetP sZS x Zx. rewrite 2!mulmxA bUhom // -(mulmxA _ _ bZ) bZhom //. by rewrite -!(mulmxA bU) -!(mulmxA bZ) bVhom. have{rsimUV} [B [B' _ homB]] := mx_rsim_def rsimUV. have:= eqxx (irr_mode (iphi jU) z); rewrite /irr_mode; set i0 := Ordinal _. rewrite {2}[_ z]homB // ![_ z]phi_z mxE mulr1n -scalemx1 -scalemxAr -scalemxAl. rewrite -(repr_mx1 (subg_repr (phi jV) sZS)) -{B B'}homB // repr_mx1 scalemx1. by rewrite mxE (eq_prim_root_expr prim_w) !modIp'. Qed. End Extraspecial. #[deprecated(since="mathcomp 2.4.0", note="Use extraspecial_repr_structure_pchar instead.")] Notation extraspecial_repr_structure := (extraspecial_repr_structure_pchar) (only parsing). #[deprecated(since="mathcomp 2.4.0", note="Use faithful_repr_extraspecial_pchar instead.")] Notation faithful_repr_extraspecial := (faithful_repr_extraspecial_pchar) (only parsing).
SingleFunctors.lean
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory.Shift import Mathlib.CategoryTheory.Shift.SingleFunctors /-! # Single functors from the homotopy category Let `C` be a preadditive category with a zero object. In this file, we put together all the single functors `C ⥤ CochainComplex C ℤ` along with their compatibilities with shifts into the definition `CochainComplex.singleFunctors C : SingleFunctors C (CochainComplex C ℤ) ℤ`. Similarly, we define `HomotopyCategory.singleFunctors C : SingleFunctors C (HomotopyCategory C (ComplexShape.up ℤ)) ℤ`. -/ assert_not_exists TwoSidedIdeal universe v' u' v u open CategoryTheory Category Limits variable (C : Type u) [Category.{v} C] [Preadditive C] [HasZeroObject C] namespace CochainComplex open HomologicalComplex /-- The collection of all single functors `C ⥤ CochainComplex C ℤ` along with their compatibilites with shifts. (This definition has purposely no `simps` attribute, as the generated lemmas would not be very useful.) -/ noncomputable def singleFunctors : SingleFunctors C (CochainComplex C ℤ) ℤ where functor n := single _ _ n shiftIso n a a' ha' := NatIso.ofComponents (fun X => Hom.isoOfComponents (fun i => eqToIso (by obtain rfl : a' = a + n := by omega by_cases h : i = a · subst h simp only [Functor.comp_obj, shiftFunctor_obj_X', single_obj_X_self] · dsimp [single] rw [if_neg h, if_neg (fun h' => h (by omega))]))) (fun {X Y} f => by obtain rfl : a' = a + n := by omega ext simp [single]) shiftIso_zero a := by ext dsimp simp only [single, shiftFunctorZero_eq, shiftFunctorZero'_hom_app_f, XIsoOfEq, eqToIso.hom] shiftIso_add n m a a' a'' ha' ha'' := by ext dsimp simp only [shiftFunctorAdd_eq, shiftFunctorAdd'_hom_app_f, XIsoOfEq, eqToIso.hom, eqToHom_trans, id_comp] instance (n : ℤ) : ((singleFunctors C).functor n).Additive := by dsimp only [singleFunctors] infer_instance /-- The single functor `C ⥤ CochainComplex C ℤ` which sends `X` to the complex consisting of `X` in degree `n : ℤ` and zero otherwise. (This is definitionally equal to `HomologicalComplex.single C (up ℤ) n`, but `singleFunctor C n` is the preferred term when interactions with shifts are relevant.) -/ noncomputable abbrev singleFunctor (n : ℤ) := (singleFunctors C).functor n instance (n : ℤ) : (singleFunctor C n).Full := inferInstanceAs (single _ _ _).Full instance (n : ℤ) : (singleFunctor C n).Faithful := inferInstanceAs (single _ _ _).Faithful end CochainComplex namespace HomotopyCategory /-- The collection of all single functors `C ⥤ HomotopyCategory C (ComplexShape.up ℤ))` for `n : ℤ` along with their compatibilites with shifts. -/ noncomputable def singleFunctors : SingleFunctors C (HomotopyCategory C (ComplexShape.up ℤ)) ℤ := (CochainComplex.singleFunctors C).postcomp (HomotopyCategory.quotient _ _) /-- The single functor `C ⥤ HomotopyCategory C (ComplexShape.up ℤ)` which sends `X` to the complex consisting of `X` in degree `n : ℤ` and zero otherwise. -/ noncomputable abbrev singleFunctor (n : ℤ) : C ⥤ HomotopyCategory C (ComplexShape.up ℤ) := (singleFunctors C).functor n instance (n : ℤ) : (singleFunctor C n).Additive := by dsimp only [singleFunctor, singleFunctors, SingleFunctors.postcomp] infer_instance /-- The isomorphism given by the very definition of `singleFunctors C`. -/ noncomputable def singleFunctorsPostcompQuotientIso : singleFunctors C ≅ (CochainComplex.singleFunctors C).postcomp (HomotopyCategory.quotient _ _) := Iso.refl _ /-- `HomotopyCategory.singleFunctor C n` is induced by `CochainComplex.singleFunctor C n`. -/ noncomputable def singleFunctorPostcompQuotientIso (n : ℤ) : singleFunctor C n ≅ CochainComplex.singleFunctor C n ⋙ quotient _ _ := (SingleFunctors.evaluation _ _ n).mapIso (singleFunctorsPostcompQuotientIso C) end HomotopyCategory
RationalMap.lean
/- Copyright (c) 2024 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.AlgebraicGeometry.SpreadingOut import Mathlib.AlgebraicGeometry.FunctionField import Mathlib.AlgebraicGeometry.Morphisms.Separated /-! # Rational maps between schemes ## Main definitions * `AlgebraicGeometry.Scheme.PartialMap`: A partial map from `X` to `Y` (`X.PartialMap Y`) is a morphism into `Y` defined on a dense open subscheme of `X`. * `AlgebraicGeometry.Scheme.PartialMap.equiv`: Two partial maps are equivalent if they are equal on a dense open subscheme. * `AlgebraicGeometry.Scheme.RationalMap`: A rational map from `X` to `Y` (`X ⤏ Y`) is an equivalence class of partial maps. * `AlgebraicGeometry.Scheme.RationalMap.equivFunctionFieldOver`: Given `S`-schemes `X` and `Y` such that `Y` is locally of finite type and `X` is integral, `S`-morphisms `Spec K(X) ⟶ Y` correspond bijectively to `S`-rational maps from `X` to `Y`. * `AlgebraicGeometry.Scheme.RationalMap.toPartialMap`: If `X` is integral and `Y` is separated, then any `f : X ⤏ Y` can be realized as a partial map on `f.domain`, the domain of definition of `f`. -/ universe u open CategoryTheory hiding Quotient namespace AlgebraicGeometry variable {X Y Z S : Scheme.{u}} (sX : X ⟶ S) (sY : Y ⟶ S) namespace Scheme /-- A partial map from `X` to `Y` (`X.PartialMap Y`) is a morphism into `Y` defined on a dense open subscheme of `X`. -/ structure PartialMap (X Y : Scheme.{u}) where /-- The domain of definition of a partial map. -/ domain : X.Opens dense_domain : Dense (domain : Set X) /-- The underlying morphism of a partial map. -/ hom : ↑domain ⟶ Y variable (S) in /-- A partial map is a `S`-map if the underlying morphism is. -/ abbrev PartialMap.IsOver [X.Over S] [Y.Over S] (f : X.PartialMap Y) := f.hom.IsOver S namespace PartialMap lemma ext_iff (f g : X.PartialMap Y) : f = g ↔ ∃ e : f.domain = g.domain, f.hom = (X.isoOfEq e).hom ≫ g.hom := by constructor · rintro rfl simp only [exists_true_left, Scheme.isoOfEq_rfl, Iso.refl_hom, Category.id_comp] · obtain ⟨U, hU, f⟩ := f obtain ⟨V, hV, g⟩ := g rintro ⟨rfl : U = V, e⟩ congr 1 simpa using e @[ext] lemma ext (f g : X.PartialMap Y) (e : f.domain = g.domain) (H : f.hom = (X.isoOfEq e).hom ≫ g.hom) : f = g := by rw [ext_iff] exact ⟨e, H⟩ /-- The restriction of a partial map to a smaller domain. -/ @[simps hom domain] noncomputable def restrict (f : X.PartialMap Y) (U : X.Opens) (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) : X.PartialMap Y where domain := U dense_domain := hU hom := X.homOfLE hU' ≫ f.hom @[simp] lemma restrict_id (f : X.PartialMap Y) : f.restrict f.domain f.dense_domain le_rfl = f := by ext1 <;> simp [restrict_domain] lemma restrict_id_hom (f : X.PartialMap Y) : (f.restrict f.domain f.dense_domain le_rfl).hom = f.hom := by simp @[simp] lemma restrict_restrict (f : X.PartialMap Y) (U : X.Opens) (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) (V : X.Opens) (hV : Dense (V : Set X)) (hV' : V ≤ U) : (f.restrict U hU hU').restrict V hV hV' = f.restrict V hV (hV'.trans hU') := by ext1 <;> simp [restrict_domain] lemma restrict_restrict_hom (f : X.PartialMap Y) (U : X.Opens) (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) (V : X.Opens) (hV : Dense (V : Set X)) (hV' : V ≤ U) : ((f.restrict U hU hU').restrict V hV hV').hom = (f.restrict V hV (hV'.trans hU')).hom := by simp instance [X.Over S] [Y.Over S] (f : X.PartialMap Y) [f.IsOver S] (U : X.Opens) (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) : (f.restrict U hU hU').IsOver S where /-- The composition of a partial map and a morphism on the right. -/ @[simps] def compHom (f : X.PartialMap Y) (g : Y ⟶ Z) : X.PartialMap Z where domain := f.domain dense_domain := f.dense_domain hom := f.hom ≫ g instance [X.Over S] [Y.Over S] [Z.Over S] (f : X.PartialMap Y) (g : Y ⟶ Z) [f.IsOver S] [g.IsOver S] : (f.compHom g).IsOver S where /-- A scheme morphism as a partial map. -/ @[simps] def _root_.AlgebraicGeometry.Scheme.Hom.toPartialMap (f : X.Hom Y) : X.PartialMap Y := ⟨⊤, dense_univ, X.topIso.hom ≫ f⟩ instance [X.Over S] [Y.Over S] (f : X ⟶ Y) [f.IsOver S] : f.toPartialMap.IsOver S where lemma isOver_iff [X.Over S] [Y.Over S] {f : X.PartialMap Y} : f.IsOver S ↔ (f.compHom (Y ↘ S)).hom = f.domain.ι ≫ X ↘ S := by simp lemma isOver_iff_eq_restrict [X.Over S] [Y.Over S] {f : X.PartialMap Y} : f.IsOver S ↔ f.compHom (Y ↘ S) = (X ↘ S).toPartialMap.restrict _ f.dense_domain (by simp) := by simp [PartialMap.ext_iff] /-- If `x` is in the domain of a partial map `f`, then `f` restricts to a map from `Spec 𝒪_x`. -/ noncomputable def fromSpecStalkOfMem (f : X.PartialMap Y) {x} (hx : x ∈ f.domain) : Spec (X.presheaf.stalk x) ⟶ Y := f.domain.fromSpecStalkOfMem x hx ≫ f.hom /-- A partial map restricts to a map from `Spec K(X)`. -/ noncomputable abbrev fromFunctionField [IrreducibleSpace X] (f : X.PartialMap Y) : Spec X.functionField ⟶ Y := f.fromSpecStalkOfMem ((genericPoint_specializes _).mem_open f.domain.2 f.dense_domain.nonempty.choose_spec) lemma fromSpecStalkOfMem_restrict (f : X.PartialMap Y) {U : X.Opens} (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) {x} (hx : x ∈ U) : (f.restrict U hU hU').fromSpecStalkOfMem hx = f.fromSpecStalkOfMem (hU' hx) := by dsimp only [fromSpecStalkOfMem, restrict, Scheme.Opens.fromSpecStalkOfMem] have e : ⟨x, hU' hx⟩ = (X.homOfLE hU').base ⟨x, hx⟩ := by rw [Scheme.homOfLE_base] rfl rw [Category.assoc, ← Spec_map_stalkMap_fromSpecStalk_assoc, ← Spec_map_stalkSpecializes_fromSpecStalk (Inseparable.of_eq e).specializes, ← TopCat.Presheaf.stalkCongr_inv _ (Inseparable.of_eq e)] simp only [← Category.assoc, ← Spec.map_comp] congr 3 rw [Iso.eq_inv_comp, ← Category.assoc, IsIso.comp_inv_eq, IsIso.eq_inv_comp, stalkMap_congr_hom _ _ (X.homOfLE_ι hU').symm] simp only [TopCat.Presheaf.stalkCongr_hom] rw [← stalkSpecializes_stalkMap_assoc, stalkMap_comp] lemma fromFunctionField_restrict (f : X.PartialMap Y) [IrreducibleSpace X] {U : X.Opens} (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) : (f.restrict U hU hU').fromFunctionField = f.fromFunctionField := fromSpecStalkOfMem_restrict f _ _ _ /-- Given `S`-schemes `X` and `Y` such that `Y` is locally of finite type and `X` is irreducible germ-injective at `x` (e.g. when `X` is integral), any `S`-morphism `Spec 𝒪ₓ ⟶ Y` spreads out to a partial map from `X` to `Y`. -/ noncomputable def ofFromSpecStalk [IrreducibleSpace X] [LocallyOfFiniteType sY] {x : X} [X.IsGermInjectiveAt x] (φ : Spec (X.presheaf.stalk x) ⟶ Y) (h : φ ≫ sY = X.fromSpecStalk x ≫ sX) : X.PartialMap Y where hom := (spread_out_of_isGermInjective' sX sY φ h).choose_spec.choose_spec.choose domain := (spread_out_of_isGermInjective' sX sY φ h).choose dense_domain := (spread_out_of_isGermInjective' sX sY φ h).choose.2.dense ⟨_, (spread_out_of_isGermInjective' sX sY φ h).choose_spec.choose⟩ lemma ofFromSpecStalk_comp [IrreducibleSpace X] [LocallyOfFiniteType sY] {x : X} [X.IsGermInjectiveAt x] (φ : Spec (X.presheaf.stalk x) ⟶ Y) (h : φ ≫ sY = X.fromSpecStalk x ≫ sX) : (ofFromSpecStalk sX sY φ h).hom ≫ sY = (ofFromSpecStalk sX sY φ h).domain.ι ≫ sX := (spread_out_of_isGermInjective' sX sY φ h).choose_spec.choose_spec.choose_spec.2 lemma mem_domain_ofFromSpecStalk [IrreducibleSpace X] [LocallyOfFiniteType sY] {x : X} [X.IsGermInjectiveAt x] (φ : Spec (X.presheaf.stalk x) ⟶ Y) (h : φ ≫ sY = X.fromSpecStalk x ≫ sX) : x ∈ (ofFromSpecStalk sX sY φ h).domain := (spread_out_of_isGermInjective' sX sY φ h).choose_spec.choose lemma fromSpecStalkOfMem_ofFromSpecStalk [IrreducibleSpace X] [LocallyOfFiniteType sY] {x : X} [X.IsGermInjectiveAt x] (φ : Spec (X.presheaf.stalk x) ⟶ Y) (h : φ ≫ sY = X.fromSpecStalk x ≫ sX) : (ofFromSpecStalk sX sY φ h).fromSpecStalkOfMem (mem_domain_ofFromSpecStalk sX sY φ h) = φ := (spread_out_of_isGermInjective' sX sY φ h).choose_spec.choose_spec.choose_spec.1.symm @[simp] lemma fromSpecStalkOfMem_compHom (f : X.PartialMap Y) (g : Y ⟶ Z) (x) (hx) : (f.compHom g).fromSpecStalkOfMem (x := x) hx = f.fromSpecStalkOfMem hx ≫ g := by simp [fromSpecStalkOfMem] @[simp] lemma fromSpecStalkOfMem_toPartialMap (f : X ⟶ Y) (x) : f.toPartialMap.fromSpecStalkOfMem (x := x) trivial = X.fromSpecStalk x ≫ f := by simp [fromSpecStalkOfMem] /-- Two partial maps are equivalent if they are equal on a dense open subscheme. -/ protected noncomputable def equiv (f g : X.PartialMap Y) : Prop := ∃ (W : X.Opens) (hW : Dense (W : Set X)) (hWl : W ≤ f.domain) (hWr : W ≤ g.domain), (f.restrict W hW hWl).hom = (g.restrict W hW hWr).hom lemma equivalence_rel : Equivalence (@Scheme.PartialMap.equiv X Y) where refl f := ⟨f.domain, f.dense_domain, by simp⟩ symm {f g} := by intro ⟨W, hW, hWl, hWr, e⟩ exact ⟨W, hW, hWr, hWl, e.symm⟩ trans {f g h} := by intro ⟨W₁, hW₁, hW₁l, hW₁r, e₁⟩ ⟨W₂, hW₂, hW₂l, hW₂r, e₂⟩ refine ⟨W₁ ⊓ W₂, hW₁.inter_of_isOpen_left hW₂ W₁.2, inf_le_left.trans hW₁l, inf_le_right.trans hW₂r, ?_⟩ dsimp at e₁ e₂ simp only [restrict_domain, restrict_hom, ← X.homOfLE_homOfLE (U := W₁ ⊓ W₂) inf_le_left hW₁l, Category.assoc, e₁, ← X.homOfLE_homOfLE (U := W₁ ⊓ W₂) inf_le_right hW₂r, ← e₂] simp only [homOfLE_homOfLE_assoc] instance : Setoid (X.PartialMap Y) := ⟨@PartialMap.equiv X Y, equivalence_rel⟩ lemma restrict_equiv (f : X.PartialMap Y) (U : X.Opens) (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) : (f.restrict U hU hU').equiv f := ⟨U, hU, le_rfl, hU', by simp⟩ lemma equiv_of_fromSpecStalkOfMem_eq [IrreducibleSpace X] {x : X} [X.IsGermInjectiveAt x] (f g : X.PartialMap Y) (hxf : x ∈ f.domain) (hxg : x ∈ g.domain) (H : f.fromSpecStalkOfMem hxf = g.fromSpecStalkOfMem hxg) : f.equiv g := by have hdense : Dense ((f.domain ⊓ g.domain) : Set X) := f.dense_domain.inter_of_isOpen_left g.dense_domain f.domain.2 have := (isGermInjectiveAt_iff_of_isOpenImmersion (f := (f.domain ⊓ g.domain).ι) (x := ⟨x, hxf, hxg⟩)).mp ‹_› have := spread_out_unique_of_isGermInjective' (X := (f.domain ⊓ g.domain).toScheme) (X.homOfLE inf_le_left ≫ f.hom) (X.homOfLE inf_le_right ≫ g.hom) (x := ⟨x, hxf, hxg⟩) ?_ · obtain ⟨U, hxU, e⟩ := this refine ⟨(f.domain ⊓ g.domain).ι ''ᵁ U, ((f.domain ⊓ g.domain).ι ''ᵁ U).2.dense ⟨_, ⟨_, hxU, rfl⟩⟩, ((Set.image_subset_range _ _).trans_eq (Subtype.range_val)).trans inf_le_left, ((Set.image_subset_range _ _).trans_eq (Subtype.range_val)).trans inf_le_right, ?_⟩ rw [← cancel_epi (Scheme.Hom.isoImage _ _).hom] simp only [restrict_hom, ← Category.assoc] at e ⊢ convert e using 2 <;> rw [← cancel_mono (Scheme.Opens.ι _)] <;> simp · rw [← f.fromSpecStalkOfMem_restrict hdense inf_le_left ⟨hxf, hxg⟩, ← g.fromSpecStalkOfMem_restrict hdense inf_le_right ⟨hxf, hxg⟩] at H simpa only [fromSpecStalkOfMem, restrict_domain, Opens.fromSpecStalkOfMem, Spec.map_inv, restrict_hom, Category.assoc, IsIso.eq_inv_comp, IsIso.hom_inv_id_assoc] using H instance (U : X.Opens) [IsReduced X] : IsReduced U := isReduced_of_isOpenImmersion U.ι lemma Opens.isDominant_ι {U : X.Opens} (hU : Dense (X := X) U) : IsDominant U.ι := ⟨by simpa [DenseRange] using hU⟩ lemma Opens.isDominant_homOfLE {U V : X.Opens} (hU : Dense (X := X) U) (hU' : U ≤ V) : IsDominant (X.homOfLE hU') := have : IsDominant (X.homOfLE hU' ≫ Opens.ι _) := by simpa using Opens.isDominant_ι hU IsDominant.of_comp_of_isOpenImmersion (g := Opens.ι _) _ /-- Two partial maps from reduced schemes to separated schemes are equivalent if and only if they are equal on **any** open dense subset. -/ lemma equiv_iff_of_isSeparated_of_le [X.Over S] [Y.Over S] [IsReduced X] [IsSeparated (Y ↘ S)] {f g : X.PartialMap Y} [f.IsOver S] [g.IsOver S] {W : X.Opens} (hW : Dense (X := X) W) (hWl : W ≤ f.domain) (hWr : W ≤ g.domain) : f.equiv g ↔ (f.restrict W hW hWl).hom = (g.restrict W hW hWr).hom := by refine ⟨fun ⟨V, hV, hVl, hVr, e⟩ ↦ ?_, fun e ↦ ⟨_, _, _, _, e⟩⟩ have : IsDominant (X.homOfLE (inf_le_left : W ⊓ V ≤ W)) := Opens.isDominant_homOfLE (hW.inter_of_isOpen_left hV W.2) _ apply ext_of_isDominant_of_isSeparated' S (X.homOfLE (inf_le_left : W ⊓ V ≤ W)) simpa using congr(X.homOfLE (inf_le_right : W ⊓ V ≤ V) ≫ $e) /-- Two partial maps from reduced schemes to separated schemes are equivalent if and only if they are equal on the intersection of the domains. -/ lemma equiv_iff_of_isSeparated [X.Over S] [Y.Over S] [IsReduced X] [IsSeparated (Y ↘ S)] {f g : X.PartialMap Y} [f.IsOver S] [g.IsOver S] : f.equiv g ↔ (f.restrict _ (f.2.inter_of_isOpen_left g.2 f.domain.2) inf_le_left).hom = (g.restrict _ (f.2.inter_of_isOpen_left g.2 f.domain.2) inf_le_right).hom := equiv_iff_of_isSeparated_of_le (S := S) _ _ _ /-- Two partial maps from reduced schemes to separated schemes with the same domain are equivalent if and only if they are equal. -/ lemma equiv_iff_of_domain_eq_of_isSeparated [X.Over S] [Y.Over S] [IsReduced X] [IsSeparated (Y ↘ S)] {f g : X.PartialMap Y} (hfg : f.domain = g.domain) [f.IsOver S] [g.IsOver S] : f.equiv g ↔ f = g := by rw [equiv_iff_of_isSeparated_of_le (S := S) f.dense_domain le_rfl hfg.le] obtain ⟨Uf, _, f⟩ := f obtain ⟨Ug, _, g⟩ := g obtain rfl : Uf = Ug := hfg simp /-- A partial map from a reduced scheme to a separated scheme is equivalent to a morphism if and only if it is equal to the restriction of the morphism. -/ lemma equiv_toPartialMap_iff_of_isSeparated [X.Over S] [Y.Over S] [IsReduced X] [IsSeparated (Y ↘ S)] {f : X.PartialMap Y} {g : X ⟶ Y} [f.IsOver S] [g.IsOver S] : f.equiv g.toPartialMap ↔ f.hom = f.domain.ι ≫ g := by rw [equiv_iff_of_isSeparated (S := S), ← cancel_epi (X.isoOfEq (inf_top_eq f.domain)).hom] simp rfl end PartialMap /-- A rational map from `X` to `Y` (`X ⤏ Y`) is an equivalence class of partial maps, where two partial maps are equivalent if they are equal on a dense open subscheme. -/ def RationalMap (X Y : Scheme.{u}) : Type u := @Quotient (X.PartialMap Y) inferInstance /-- The notation for rational maps. -/ scoped[AlgebraicGeometry] infix:10 " ⤏ " => Scheme.RationalMap /-- A partial map as a rational map. -/ def PartialMap.toRationalMap (f : X.PartialMap Y) : X ⤏ Y := Quotient.mk _ f /-- A scheme morphism as a rational map. -/ abbrev Hom.toRationalMap (f : X.Hom Y) : X ⤏ Y := f.toPartialMap.toRationalMap variable (S) in /-- A rational map is a `S`-map if some partial map in the equivalence class is a `S`-map. -/ class RationalMap.IsOver [X.Over S] [Y.Over S] (f : X ⤏ Y) : Prop where exists_partialMap_over : ∃ g : X.PartialMap Y, g.IsOver S ∧ g.toRationalMap = f lemma PartialMap.toRationalMap_surjective : Function.Surjective (@toRationalMap X Y) := Quotient.exists_rep lemma RationalMap.exists_rep (f : X ⤏ Y) : ∃ g : X.PartialMap Y, g.toRationalMap = f := Quotient.exists_rep f lemma PartialMap.toRationalMap_eq_iff {f g : X.PartialMap Y} : f.toRationalMap = g.toRationalMap ↔ f.equiv g := Quotient.eq @[simp] lemma PartialMap.restrict_toRationalMap (f : X.PartialMap Y) (U : X.Opens) (hU : Dense (U : Set X)) (hU' : U ≤ f.domain) : (f.restrict U hU hU').toRationalMap = f.toRationalMap := toRationalMap_eq_iff.mpr (f.restrict_equiv U hU hU') instance [X.Over S] [Y.Over S] (f : X.PartialMap Y) [f.IsOver S] : f.toRationalMap.IsOver S := ⟨f, ‹_›, rfl⟩ variable (S) in lemma RationalMap.exists_partialMap_over [X.Over S] [Y.Over S] (f : X ⤏ Y) [f.IsOver S] : ∃ g : X.PartialMap Y, g.IsOver S ∧ g.toRationalMap = f := IsOver.exists_partialMap_over /-- The composition of a rational map and a morphism on the right. -/ def RationalMap.compHom (f : X ⤏ Y) (g : Y ⟶ Z) : X ⤏ Z := by refine Quotient.map (PartialMap.compHom · g) ?_ f intro f₁ f₂ ⟨W, hW, hWl, hWr, e⟩ refine ⟨W, hW, hWl, hWr, ?_⟩ simp only [PartialMap.restrict_domain, PartialMap.restrict_hom, PartialMap.compHom_domain, PartialMap.compHom_hom] at e ⊢ rw [reassoc_of% e] @[simp] lemma RationalMap.compHom_toRationalMap (f : X.PartialMap Y) (g : Y ⟶ Z) : (f.compHom g).toRationalMap = f.toRationalMap.compHom g := rfl instance [X.Over S] [Y.Over S] [Z.Over S] (f : X ⤏ Y) (g : Y ⟶ Z) [f.IsOver S] [g.IsOver S] : (f.compHom g).IsOver S where exists_partialMap_over := by obtain ⟨f, hf, rfl⟩ := f.exists_partialMap_over S exact ⟨f.compHom g, inferInstance, rfl⟩ variable (S) in lemma PartialMap.exists_restrict_isOver [X.Over S] [Y.Over S] (f : X.PartialMap Y) [f.toRationalMap.IsOver S] : ∃ U hU hU', (f.restrict U hU hU').IsOver S := by obtain ⟨f', hf₁, hf₂⟩ := RationalMap.IsOver.exists_partialMap_over (S := S) (f := f.toRationalMap) obtain ⟨U, hU, hUl, hUr, e⟩ := PartialMap.toRationalMap_eq_iff.mp hf₂ exact ⟨U, hU, hUr, by rw [IsOver, ← e]; infer_instance⟩ lemma RationalMap.isOver_iff [X.Over S] [Y.Over S] {f : X ⤏ Y} : f.IsOver S ↔ f.compHom (Y ↘ S) = (X ↘ S).toRationalMap := by constructor · intro h obtain ⟨g, hg, e⟩ := f.exists_partialMap_over S rw [← e, Hom.toRationalMap, ← compHom_toRationalMap, PartialMap.isOver_iff_eq_restrict.mp hg, PartialMap.restrict_toRationalMap] · intro e obtain ⟨f, rfl⟩ := PartialMap.toRationalMap_surjective f obtain ⟨U, hU, hUl, hUr, e⟩ := PartialMap.toRationalMap_eq_iff.mp e exact ⟨⟨f.restrict U hU hUl, by simpa using e, by simp⟩⟩ lemma PartialMap.isOver_toRationalMap_iff_of_isSeparated [X.Over S] [Y.Over S] [IsReduced X] [S.IsSeparated] {f : X.PartialMap Y} : f.toRationalMap.IsOver S ↔ f.IsOver S := by refine ⟨fun _ ↦ ?_, fun _ ↦ inferInstance⟩ obtain ⟨U, hU, hU', H⟩ := f.exists_restrict_isOver (S := S) rw [isOver_iff] have : IsDominant (X.homOfLE hU') := Opens.isDominant_homOfLE hU _ exact ext_of_isDominant (ι := X.homOfLE hU') (by simpa using H.1) section functionField /-- A rational map restricts to a map from `Spec K(X)`. -/ noncomputable def RationalMap.fromFunctionField [IrreducibleSpace X] (f : X ⤏ Y) : Spec X.functionField ⟶ Y := by refine Quotient.lift PartialMap.fromFunctionField ?_ f intro f g ⟨W, hW, hWl, hWr, e⟩ have : f.restrict W hW hWl = g.restrict W hW hWr := by ext1; rfl; rw [e]; simp rw [← f.fromFunctionField_restrict hW hWl, this, g.fromFunctionField_restrict] @[simp] lemma RationalMap.fromFunctionField_toRationalMap [IrreducibleSpace X] (f : X.PartialMap Y) : f.toRationalMap.fromFunctionField = f.fromFunctionField := rfl /-- Given `S`-schemes `X` and `Y` such that `Y` is locally of finite type and `X` is integral, any `S`-morphism `Spec K(X) ⟶ Y` spreads out to a rational map from `X` to `Y`. -/ noncomputable def RationalMap.ofFunctionField [IsIntegral X] [LocallyOfFiniteType sY] (f : Spec X.functionField ⟶ Y) (h : f ≫ sY = X.fromSpecStalk _ ≫ sX) : X ⤏ Y := (PartialMap.ofFromSpecStalk sX sY f h).toRationalMap lemma RationalMap.fromFunctionField_ofFunctionField [IsIntegral X] [LocallyOfFiniteType sY] (f : Spec X.functionField ⟶ Y) (h : f ≫ sY = X.fromSpecStalk _ ≫ sX) : (ofFunctionField sX sY f h).fromFunctionField = f := PartialMap.fromSpecStalkOfMem_ofFromSpecStalk sX sY _ _ lemma RationalMap.eq_of_fromFunctionField_eq [IsIntegral X] (f g : X.RationalMap Y) (H : f.fromFunctionField = g.fromFunctionField) : f = g := by obtain ⟨f, rfl⟩ := f.exists_rep obtain ⟨g, rfl⟩ := g.exists_rep refine PartialMap.toRationalMap_eq_iff.mpr ?_ exact PartialMap.equiv_of_fromSpecStalkOfMem_eq _ _ _ _ H /-- Given `S`-schemes `X` and `Y` such that `Y` is locally of finite type and `X` is integral, `S`-morphisms `Spec K(X) ⟶ Y` correspond bijectively to `S`-rational maps from `X` to `Y`. -/ noncomputable def RationalMap.equivFunctionField [IsIntegral X] [LocallyOfFiniteType sY] : { f : Spec X.functionField ⟶ Y // f ≫ sY = X.fromSpecStalk _ ≫ sX } ≃ { f : X ⤏ Y // f.compHom sY = sX.toRationalMap } where toFun f := ⟨.ofFunctionField sX sY f f.2, PartialMap.toRationalMap_eq_iff.mpr ⟨_, PartialMap.dense_domain _, le_rfl, le_top, by simp [PartialMap.ofFromSpecStalk_comp]⟩⟩ invFun f := ⟨f.1.fromFunctionField, by obtain ⟨f, hf⟩ := f obtain ⟨f, rfl⟩ := f.exists_rep simpa [fromFunctionField_toRationalMap] using congr(RationalMap.fromFunctionField $hf)⟩ left_inv f := Subtype.ext (RationalMap.fromFunctionField_ofFunctionField _ _ _ _) right_inv f := Subtype.ext (RationalMap.eq_of_fromFunctionField_eq (ofFunctionField sX sY f.1.fromFunctionField _) f (RationalMap.fromFunctionField_ofFunctionField _ _ _ _)) /-- Given `S`-schemes `X` and `Y` such that `Y` is locally of finite type and `X` is integral, `S`-morphisms `Spec K(X) ⟶ Y` correspond bijectively to `S`-rational maps from `X` to `Y`. -/ noncomputable def RationalMap.equivFunctionFieldOver [X.Over S] [Y.Over S] [IsIntegral X] [LocallyOfFiniteType (Y ↘ S)] : { f : Spec X.functionField ⟶ Y // f.IsOver S } ≃ { f : X ⤏ Y // f.IsOver S } := ((Equiv.subtypeEquivProp (by simp only [Hom.isOver_iff]; rfl)).trans (RationalMap.equivFunctionField (X ↘ S) (Y ↘ S))).trans (Equiv.subtypeEquivProp (by ext f; rw [RationalMap.isOver_iff])) end functionField section domain /-- The domain of definition of a rational map. -/ def RationalMap.domain (f : X ⤏ Y) : X.Opens := sSup { PartialMap.domain g | (g) (_ : g.toRationalMap = f) } lemma PartialMap.le_domain_toRationalMap (f : X.PartialMap Y) : f.domain ≤ f.toRationalMap.domain := le_sSup ⟨f, rfl, rfl⟩ lemma RationalMap.mem_domain {f : X ⤏ Y} {x} : x ∈ f.domain ↔ ∃ g : X.PartialMap Y, x ∈ g.domain ∧ g.toRationalMap = f := TopologicalSpace.Opens.mem_sSup.trans (by simp [@and_comm (x ∈ _)]) lemma RationalMap.dense_domain (f : X ⤏ Y) : Dense (X := X) f.domain := f.inductionOn (fun g ↦ g.dense_domain.mono g.le_domain_toRationalMap) /-- The open cover of the domain of `f : X ⤏ Y`, consisting of all the domains of the partial maps in the equivalence class. -/ noncomputable def RationalMap.openCoverDomain (f : X ⤏ Y) : f.domain.toScheme.OpenCover where J := { PartialMap.domain g | (g) (_ : g.toRationalMap = f) } obj U := U.1.toScheme map U := X.homOfLE (le_sSup U.2) f x := ⟨_, (TopologicalSpace.Opens.mem_sSup.mp x.2).choose_spec.1⟩ covers x := ⟨⟨x.1, (TopologicalSpace.Opens.mem_sSup.mp x.2).choose_spec.2⟩, Subtype.ext (by simp)⟩ /-- If `f : X ⤏ Y` is a rational map from a reduced scheme to a separated scheme, then `f` can be represented as a partial map on its domain of definition. -/ noncomputable def RationalMap.toPartialMap [IsReduced X] [Y.IsSeparated] (f : X ⤏ Y) : X.PartialMap Y := by refine ⟨f.domain, f.dense_domain, f.openCoverDomain.glueMorphisms (fun x ↦ (X.isoOfEq x.2.choose_spec.2).inv ≫ x.2.choose.hom) ?_⟩ intros x y let g (x : f.openCoverDomain.J) := x.2.choose have hg₁ (x) : (g x).toRationalMap = f := x.2.choose_spec.1 have hg₂ (x) : (g x).domain = x.1 := x.2.choose_spec.2 refine (cancel_epi (isPullback_opens_inf_le (le_sSup x.2) (le_sSup y.2)).isoPullback.hom).mp ?_ simp only [openCoverDomain, IsPullback.isoPullback_hom_fst_assoc, IsPullback.isoPullback_hom_snd_assoc] change _ ≫ _ ≫ (g x).hom = _ ≫ _ ≫ (g y).hom simp_rw [← cancel_epi (X.isoOfEq congr($(hg₂ x) ⊓ $(hg₂ y))).hom, ← Category.assoc] convert (PartialMap.equiv_iff_of_isSeparated (S := ⊤_ _) (f := g x) (g := g y)).mp ?_ using 1 · dsimp; congr 1; simp [g, ← cancel_mono (Opens.ι _)] · dsimp; congr 1; simp [g, ← cancel_mono (Opens.ι _)] · rw [← PartialMap.toRationalMap_eq_iff, hg₁, hg₁] lemma PartialMap.toPartialMap_toRationalMap_restrict [IsReduced X] [Y.IsSeparated] (f : X.PartialMap Y) : (f.toRationalMap.toPartialMap.restrict _ f.dense_domain f.le_domain_toRationalMap).hom = f.hom := by dsimp [RationalMap.toPartialMap] refine (f.toRationalMap.openCoverDomain.ι_glueMorphisms _ _ ⟨_, f, rfl, rfl⟩).trans ?_ generalize_proofs _ _ H _ have : H.choose = f := (equiv_iff_of_domain_eq_of_isSeparated (S := ⊤_ _) H.choose_spec.2).mp (toRationalMap_eq_iff.mp H.choose_spec.1) exact ((ext_iff _ _).mp this.symm).choose_spec.symm @[simp] lemma RationalMap.toRationalMap_toPartialMap [IsReduced X] [Y.IsSeparated] (f : X ⤏ Y) : f.toPartialMap.toRationalMap = f := by obtain ⟨f, rfl⟩ := PartialMap.toRationalMap_surjective f trans (f.toRationalMap.toPartialMap.restrict _ f.dense_domain f.le_domain_toRationalMap).toRationalMap · simp · congr 1 exact PartialMap.ext _ f rfl (by simpa using f.toPartialMap_toRationalMap_restrict) instance [IsReduced X] [Y.IsSeparated] [S.IsSeparated] [X.Over S] [Y.Over S] (f : X ⤏ Y) [f.IsOver S] : f.toPartialMap.IsOver S := by rw [← PartialMap.isOver_toRationalMap_iff_of_isSeparated, f.toRationalMap_toPartialMap] infer_instance end domain end Scheme end AlgebraicGeometry
Hilbert90.lean
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.FieldTheory.Fixed import Mathlib.RepresentationTheory.Homological.GroupCohomology.LowDegree /-! # Hilbert's Theorem 90 Let `L/K` be a finite extension of fields. Then this file proves Noether's generalization of Hilbert's Theorem 90: that the 1st group cohomology $H^1(Aut_K(L), L^\times)$ is trivial. We state it both in terms of $H^1$ and in terms of cocycles being coboundaries. Hilbert's original statement was that if $L/K$ is Galois, and $Gal(L/K)$ is cyclic, generated by an element `σ`, then for every `x : L` such that $N_{L/K}(x) = 1,$ there exists `y : L` such that $x = y/σ(y).$ This can be deduced from the fact that the function $Gal(L/K) → L^\times$ sending $σ^i \mapsto xσ(x)σ^2(x)...σ^{i-1}(x)$ is a 1-cocycle. Alternatively, we can derive it by analyzing the cohomology of finite cyclic groups in general. Noether's generalization also holds for infinite Galois extensions. ## Main statements * `groupCohomology.isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units`: Noether's generalization of Hilbert's Theorem 90: for all $f: Aut_K(L) \to L^\times$ satisfying the 1-cocycle condition, there exists `β : Lˣ` such that $g(β)/β = f(g)$ for all `g : Aut_K(L)`. * `groupCohomology.H1ofAutOnUnitsUnique`: Noether's generalization of Hilbert's Theorem 90: $H^1(Aut_K(L), L^\times)$ is trivial. ## Implementation notes Given a commutative ring `k` and a group `G`, group cohomology is developed in terms of `k`-linear `G`-representations on `k`-modules. Therefore stating Noether's generalization of Hilbert 90 in terms of `H¹` requires us to turn the natural action of `Aut_K(L)` on `Lˣ` into a morphism `Aut_K(L) →* (Additive Lˣ →ₗ[ℤ] Additive Lˣ)`. Thus we provide the non-`H¹` version too, as its statement is clearer. ## TODO * The original Hilbert's Theorem 90, deduced from the cohomology of general finite cyclic groups. * Develop Galois cohomology to extend Noether's result to infinite Galois extensions. * "Additive Hilbert 90": let `L/K` be a finite Galois extension. Then $H^n(Gal(L/K), L)$ is trivial for all $1 ≤ n.$ -/ namespace groupCohomology namespace Hilbert90 variable {K L : Type*} [Field K] [Field L] [Algebra K L] [FiniteDimensional K L] /-- Given `f : Aut_K(L) → Lˣ`, the sum `∑ f(φ) • φ` for `φ ∈ Aut_K(L)`, as a function `L → L`. -/ noncomputable def aux (f : (L ≃ₐ[K] L) → Lˣ) : L → L := Finsupp.linearCombination L (fun φ : L ≃ₐ[K] L ↦ (φ : L → L)) (Finsupp.equivFunOnFinite.symm (fun φ => (f φ : L))) theorem aux_ne_zero (f : (L ≃ₐ[K] L) → Lˣ) : aux f ≠ 0 := /- the set `Aut_K(L)` is linearly independent in the `L`-vector space `L → L`, by Dedekind's linear independence of characters -/ have : LinearIndependent L (fun (f : L ≃ₐ[K] L) => (f : L → L)) := LinearIndependent.comp (ι' := L ≃ₐ[K] L) (linearIndependent_monoidHom L L) (fun f => f) (fun x y h => by ext; exact DFunLike.ext_iff.1 h _) have h := linearIndependent_iff.1 this (Finsupp.equivFunOnFinite.symm (fun φ => (f φ : L))) fun H => Units.ne_zero (f 1) (DFunLike.ext_iff.1 (h H) 1) end Hilbert90 section open Hilbert90 variable {K L : Type*} [Field K] [Field L] [Algebra K L] [FiniteDimensional K L] /-- Noether's generalization of Hilbert's Theorem 90: given a finite extension of fields and a function `f : Aut_K(L) → Lˣ` satisfying `f(gh) = g(f(h)) * f(g)` for all `g, h : Aut_K(L)`, there exists `β : Lˣ` such that `g(β)/β = f(g)` for all `g : Aut_K(L).` -/ theorem isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units (f : (L ≃ₐ[K] L) → Lˣ) (hf : IsMulCocycle₁ f) : IsMulCoboundary₁ f := by /- Let `z : L` be such that `∑ f(h) * h(z) ≠ 0`, for `h ∈ Aut_K(L)` -/ obtain ⟨z, hz⟩ : ∃ z, aux f z ≠ 0 := not_forall.1 (fun H => aux_ne_zero f <| funext <| fun x => H x) have : aux f z = ∑ h, f h * h z := by simp [aux, Finsupp.linearCombination, Finsupp.sum_fintype] /- Let `β = (∑ f(h) * h(z))⁻¹.` -/ use (Units.mk0 (aux f z) hz)⁻¹ intro g /- Then the equality follows from the hypothesis that `f` is a 1-cocycle. -/ simp only [IsMulCocycle₁, AlgEquiv.smul_units_def, map_inv, div_inv_eq_mul, inv_mul_eq_iff_eq_mul, Units.ext_iff, this, Units.val_mul, Units.coe_map, Units.val_mk0, MonoidHom.coe_coe] at hf ⊢ simp_rw [map_sum, map_mul, Finset.sum_mul, mul_assoc, mul_comm _ (f _ : L), ← mul_assoc, ← hf g] exact eq_comm.1 (Fintype.sum_bijective (fun i => g * i) (Group.mulLeft_bijective g) _ _ (fun i => rfl)) @[deprecated (since := "2025-06-26")] alias isMulOneCoboundary_of_isMulOneCocycle_of_aut_to_units := isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units end variable (K L : Type) [Field K] [Field L] [Algebra K L] [FiniteDimensional K L] /-- Noether's generalization of Hilbert's Theorem 90: given a finite extension of fields `L/K`, the first group cohomology `H¹(Aut_K(L), Lˣ)` is trivial. -/ noncomputable instance H1ofAutOnUnitsUnique : Unique (H1 (Rep.ofAlgebraAutOnUnits K L)) where default := 0 uniq := fun a => H1_induction_on a fun x => (H1π_eq_zero_iff _).2 <| by refine (coboundariesOfIsMulCoboundary₁ ?_).2 rcases isMulCoboundary₁_of_isMulCocycle₁_of_aut_to_units x.1 (isMulCocycle₁_of_mem_cocycles₁ _ x.2) with ⟨β, hβ⟩ use β end groupCohomology
Mul.lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Analytic.Constructions import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.FDeriv.Bilinear /-! # Multiplicative operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Mathlib/Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * multiplication of a function by a scalar function * product of finitely many scalar functions * taking the pointwise multiplicative inverse (i.e. `Inv.inv` or `Ring.inverse`) of a function -/ open Asymptotics ContinuousLinearMap Topology section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {f : E → F} variable {f' : E →L[𝕜] F} variable {x : E} variable {s : Set E} section CLMCompApply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ variable {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {c : E → G →L[𝕜] H} {c' : E →L[𝕜] G →L[𝕜] H} {d : E → F →L[𝕜] G} {d' : E →L[𝕜] F →L[𝕜] G} {u : E → G} {u' : E →L[𝕜] G} @[fun_prop] theorem HasStrictFDerivAt.clm_comp (hc : HasStrictFDerivAt c c' x) (hd : HasStrictFDerivAt d d' x) : HasStrictFDerivAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := (isBoundedBilinearMap_comp.hasStrictFDerivAt (c x, d x)).comp x (hc.prodMk hd) @[fun_prop] theorem HasFDerivWithinAt.clm_comp (hc : HasFDerivWithinAt c c' s x) (hd : HasFDerivWithinAt d d' s x) : HasFDerivWithinAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') s x := by -- `by exact` to solve unification issues. exact (isBoundedBilinearMap_comp.hasFDerivAt (c x, d x)).comp_hasFDerivWithinAt x (hc.prodMk hd) @[fun_prop] theorem HasFDerivAt.clm_comp (hc : HasFDerivAt c c' x) (hd : HasFDerivAt d d' x) : HasFDerivAt (fun y => (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := by -- `by exact` to solve unification issues. exact (isBoundedBilinearMap_comp.hasFDerivAt (c x, d x)).comp x <| hc.prodMk hd @[fun_prop] theorem DifferentiableWithinAt.clm_comp (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : DifferentiableWithinAt 𝕜 (fun y => (c y).comp (d y)) s x := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : DifferentiableAt 𝕜 (fun y => (c y).comp (d y)) x := (hc.hasFDerivAt.clm_comp hd.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.clm_comp (hc : DifferentiableOn 𝕜 c s) (hd : DifferentiableOn 𝕜 d s) : DifferentiableOn 𝕜 (fun y => (c y).comp (d y)) s := fun x hx => (hc x hx).clm_comp (hd x hx) @[fun_prop] theorem Differentiable.clm_comp (hc : Differentiable 𝕜 c) (hd : Differentiable 𝕜 d) : Differentiable 𝕜 fun y => (c y).comp (d y) := fun x => (hc x).clm_comp (hd x) theorem fderivWithin_clm_comp (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : fderivWithin 𝕜 (fun y => (c y).comp (d y)) s x = (compL 𝕜 F G H (c x)).comp (fderivWithin 𝕜 d s x) + ((compL 𝕜 F G H).flip (d x)).comp (fderivWithin 𝕜 c s x) := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : fderiv 𝕜 (fun y => (c y).comp (d y)) x = (compL 𝕜 F G H (c x)).comp (fderiv 𝕜 d x) + ((compL 𝕜 F G H).flip (d x)).comp (fderiv 𝕜 c x) := (hc.hasFDerivAt.clm_comp hd.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.clm_apply (hc : HasStrictFDerivAt c c' x) (hu : HasStrictFDerivAt u u' x) : HasStrictFDerivAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (isBoundedBilinearMap_apply.hasStrictFDerivAt (c x, u x)).comp x (hc.prodMk hu) @[fun_prop] theorem HasFDerivWithinAt.clm_apply (hc : HasFDerivWithinAt c c' s x) (hu : HasFDerivWithinAt u u' s x) : HasFDerivWithinAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) s x := by -- `by exact` to solve unification issues. exact (isBoundedBilinearMap_apply.hasFDerivAt (c x, u x)).comp_hasFDerivWithinAt x (hc.prodMk hu) @[fun_prop] theorem HasFDerivAt.clm_apply (hc : HasFDerivAt c c' x) (hu : HasFDerivAt u u' x) : HasFDerivAt (fun y => (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := by -- `by exact` to solve unification issues. exact (isBoundedBilinearMap_apply.hasFDerivAt (c x, u x)).comp x (hc.prodMk hu) @[fun_prop] theorem DifferentiableWithinAt.clm_apply (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : DifferentiableWithinAt 𝕜 (fun y => (c y) (u y)) s x := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : DifferentiableAt 𝕜 (fun y => (c y) (u y)) x := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.clm_apply (hc : DifferentiableOn 𝕜 c s) (hu : DifferentiableOn 𝕜 u s) : DifferentiableOn 𝕜 (fun y => (c y) (u y)) s := fun x hx => (hc x hx).clm_apply (hu x hx) @[fun_prop] theorem Differentiable.clm_apply (hc : Differentiable 𝕜 c) (hu : Differentiable 𝕜 u) : Differentiable 𝕜 fun y => (c y) (u y) := fun x => (hc x).clm_apply (hu x) theorem fderivWithin_clm_apply (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : fderivWithin 𝕜 (fun y => (c y) (u y)) s x = (c x).comp (fderivWithin 𝕜 u s x) + (fderivWithin 𝕜 c s x).flip (u x) := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : fderiv 𝕜 (fun y => (c y) (u y)) x = (c x).comp (fderiv 𝕜 u x) + (fderiv 𝕜 c x).flip (u x) := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).fderiv end CLMCompApply section ContinuousMultilinearApplyConst /-! ### Derivative of the application of continuous multilinear maps to a constant -/ variable {ι : Type*} [Fintype ι] {M : ι → Type*} [∀ i, NormedAddCommGroup (M i)] [∀ i, NormedSpace 𝕜 (M i)] {H : Type*} [NormedAddCommGroup H] [NormedSpace 𝕜 H] {c : E → ContinuousMultilinearMap 𝕜 M H} {c' : E →L[𝕜] ContinuousMultilinearMap 𝕜 M H} @[fun_prop] theorem HasStrictFDerivAt.continuousMultilinear_apply_const (hc : HasStrictFDerivAt c c' x) (u : ∀ i, M i) : HasStrictFDerivAt (fun y ↦ (c y) u) (c'.flipMultilinear u) x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasStrictFDerivAt.comp x hc @[fun_prop] theorem HasFDerivWithinAt.continuousMultilinear_apply_const (hc : HasFDerivWithinAt c c' s x) (u : ∀ i, M i) : HasFDerivWithinAt (fun y ↦ (c y) u) (c'.flipMultilinear u) s x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasFDerivAt.comp_hasFDerivWithinAt x hc @[fun_prop] theorem HasFDerivAt.continuousMultilinear_apply_const (hc : HasFDerivAt c c' x) (u : ∀ i, M i) : HasFDerivAt (fun y ↦ (c y) u) (c'.flipMultilinear u) x := (ContinuousMultilinearMap.apply 𝕜 M H u).hasFDerivAt.comp x hc @[fun_prop] theorem DifferentiableWithinAt.continuousMultilinear_apply_const (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) : DifferentiableWithinAt 𝕜 (fun y ↦ (c y) u) s x := (hc.hasFDerivWithinAt.continuousMultilinear_apply_const u).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.continuousMultilinear_apply_const (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) : DifferentiableAt 𝕜 (fun y ↦ (c y) u) x := (hc.hasFDerivAt.continuousMultilinear_apply_const u).differentiableAt @[fun_prop] theorem DifferentiableOn.continuousMultilinear_apply_const (hc : DifferentiableOn 𝕜 c s) (u : ∀ i, M i) : DifferentiableOn 𝕜 (fun y ↦ (c y) u) s := fun x hx ↦ (hc x hx).continuousMultilinear_apply_const u @[fun_prop] theorem Differentiable.continuousMultilinear_apply_const (hc : Differentiable 𝕜 c) (u : ∀ i, M i) : Differentiable 𝕜 fun y ↦ (c y) u := fun x ↦ (hc x).continuousMultilinear_apply_const u theorem fderivWithin_continuousMultilinear_apply_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) : fderivWithin 𝕜 (fun y ↦ (c y) u) s x = ((fderivWithin 𝕜 c s x).flipMultilinear u) := (hc.hasFDerivWithinAt.continuousMultilinear_apply_const u).fderivWithin hxs theorem fderiv_continuousMultilinear_apply_const (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) : (fderiv 𝕜 (fun y ↦ (c y) u) x) = (fderiv 𝕜 c x).flipMultilinear u := (hc.hasFDerivAt.continuousMultilinear_apply_const u).fderiv /-- Application of a `ContinuousMultilinearMap` to a constant commutes with `fderivWithin`. -/ theorem fderivWithin_continuousMultilinear_apply_const_apply (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (u : ∀ i, M i) (m : E) : (fderivWithin 𝕜 (fun y ↦ (c y) u) s x) m = (fderivWithin 𝕜 c s x) m u := by simp [fderivWithin_continuousMultilinear_apply_const hxs hc] /-- Application of a `ContinuousMultilinearMap` to a constant commutes with `fderiv`. -/ theorem fderiv_continuousMultilinear_apply_const_apply (hc : DifferentiableAt 𝕜 c x) (u : ∀ i, M i) (m : E) : (fderiv 𝕜 (fun y ↦ (c y) u) x) m = (fderiv 𝕜 c x) m u := by simp [fderiv_continuousMultilinear_apply_const hc] end ContinuousMultilinearApplyConst section SMul /-! ### Derivative of the product of a scalar-valued function and a vector-valued function If `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued function, then `fun x ↦ c x • f x` is differentiable as well. Lemmas in this section works for function `c` taking values in the base field, as well as in a normed algebra over the base field: e.g., they work for `c : E → ℂ` and `f : E → F` provided that `F` is a complex normed vector space. -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] variable {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'} @[fun_prop] theorem HasStrictFDerivAt.fun_smul (hc : HasStrictFDerivAt c c' x) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) x := (isBoundedBilinearMap_smul.hasStrictFDerivAt (c x, f x)).comp x <| hc.prodMk hf @[fun_prop] theorem HasStrictFDerivAt.smul (hc : HasStrictFDerivAt c c' x) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (c • f) (c x • f' + c'.smulRight (f x)) x := (isBoundedBilinearMap_smul.hasStrictFDerivAt (c x, f x)).comp x <| hc.prodMk hf @[fun_prop] theorem HasFDerivWithinAt.fun_smul (hc : HasFDerivWithinAt c c' s x) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) s x := by -- `by exact` to solve unification issues. exact (isBoundedBilinearMap_smul.hasFDerivAt (𝕜 := 𝕜) (c x, f x)).comp_hasFDerivWithinAt x <| hc.prodMk hf @[fun_prop] theorem HasFDerivWithinAt.smul (hc : HasFDerivWithinAt c c' s x) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (c • f) (c x • f' + c'.smulRight (f x)) s x := hc.fun_smul hf @[fun_prop] theorem HasFDerivAt.fun_smul (hc : HasFDerivAt c c' x) (hf : HasFDerivAt f f' x) : HasFDerivAt (fun y => c y • f y) (c x • f' + c'.smulRight (f x)) x := by -- `by exact` to solve unification issues. exact (isBoundedBilinearMap_smul.hasFDerivAt (𝕜 := 𝕜) (c x, f x)).comp x <| hc.prodMk hf @[fun_prop] theorem HasFDerivAt.smul (hc : HasFDerivAt c c' x) (hf : HasFDerivAt f f' x) : HasFDerivAt (c • f) (c x • f' + c'.smulRight (f x)) x := hc.fun_smul hf @[fun_prop] theorem DifferentiableWithinAt.fun_smul (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => c y • f y) s x := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).differentiableWithinAt @[fun_prop] theorem DifferentiableWithinAt.smul (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (c • f) s x := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.fun_smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => c y • f y) x := (hc.hasFDerivAt.smul hf.hasFDerivAt).differentiableAt @[simp, fun_prop] theorem DifferentiableAt.smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (c • f) x := (hc.hasFDerivAt.smul hf.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.fun_smul (hc : DifferentiableOn 𝕜 c s) (hf : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => c y • f y) s := fun x hx => (hc x hx).smul (hf x hx) @[fun_prop] theorem DifferentiableOn.smul (hc : DifferentiableOn 𝕜 c s) (hf : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (c • f) s := fun x hx => (hc x hx).smul (hf x hx) @[simp, fun_prop] theorem Differentiable.fun_smul (hc : Differentiable 𝕜 c) (hf : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => c y • f y := fun x => (hc x).smul (hf x) @[simp, fun_prop] theorem Differentiable.smul (hc : Differentiable 𝕜 c) (hf : Differentiable 𝕜 f) : Differentiable 𝕜 (c • f) := fun x => (hc x).smul (hf x) theorem fderivWithin_fun_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (fun y => c y • f y) s x = c x • fderivWithin 𝕜 f s x + (fderivWithin 𝕜 c s x).smulRight (f x) := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).fderivWithin hxs theorem fderivWithin_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (c • f) s x = c x • fderivWithin 𝕜 f s x + (fderivWithin 𝕜 c s x).smulRight (f x) := (hc.hasFDerivWithinAt.smul hf.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_fun_smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (fun y => c y • f y) x = c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smulRight (f x) := (hc.hasFDerivAt.smul hf.hasFDerivAt).fderiv theorem fderiv_smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (c • f) x = c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smulRight (f x) := (hc.hasFDerivAt.smul hf.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.smul_const (hc : HasStrictFDerivAt c c' x) (f : F) : HasStrictFDerivAt (fun y => c y • f) (c'.smulRight f) x := by simpa only [smul_zero, zero_add] using hc.smul (hasStrictFDerivAt_const f x) @[fun_prop] theorem HasFDerivWithinAt.smul_const (hc : HasFDerivWithinAt c c' s x) (f : F) : HasFDerivWithinAt (fun y => c y • f) (c'.smulRight f) s x := by simpa only [smul_zero, zero_add] using hc.smul (hasFDerivWithinAt_const f x s) @[fun_prop] theorem HasFDerivAt.smul_const (hc : HasFDerivAt c c' x) (f : F) : HasFDerivAt (fun y => c y • f) (c'.smulRight f) x := by simpa only [smul_zero, zero_add] using hc.smul (hasFDerivAt_const f x) @[fun_prop] theorem DifferentiableWithinAt.smul_const (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : DifferentiableWithinAt 𝕜 (fun y => c y • f) s x := (hc.hasFDerivWithinAt.smul_const f).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : DifferentiableAt 𝕜 (fun y => c y • f) x := (hc.hasFDerivAt.smul_const f).differentiableAt @[fun_prop] theorem DifferentiableOn.smul_const (hc : DifferentiableOn 𝕜 c s) (f : F) : DifferentiableOn 𝕜 (fun y => c y • f) s := fun x hx => (hc x hx).smul_const f @[fun_prop] theorem Differentiable.smul_const (hc : Differentiable 𝕜 c) (f : F) : Differentiable 𝕜 fun y => c y • f := fun x => (hc x).smul_const f theorem fderivWithin_smul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : fderivWithin 𝕜 (fun y => c y • f) s x = (fderivWithin 𝕜 c s x).smulRight f := (hc.hasFDerivWithinAt.smul_const f).fderivWithin hxs theorem fderiv_smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : fderiv 𝕜 (fun y => c y • f) x = (fderiv 𝕜 c x).smulRight f := (hc.hasFDerivAt.smul_const f).fderiv end SMul section Mul /-! ### Derivative of the product of two functions -/ open scoped RightActions variable {𝔸 𝔸' : Type*} [NormedRing 𝔸] [NormedCommRing 𝔸'] [NormedAlgebra 𝕜 𝔸] [NormedAlgebra 𝕜 𝔸'] {a b : E → 𝔸} {a' b' : E →L[𝕜] 𝔸} {c d : E → 𝔸'} {c' d' : E →L[𝕜] 𝔸'} @[fun_prop] theorem HasStrictFDerivAt.fun_mul' {x : E} (ha : HasStrictFDerivAt a a' x) (hb : HasStrictFDerivAt b b' x) : HasStrictFDerivAt (fun y => a y * b y) (a x • b' + a' <• b x) x := ((ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.hasStrictFDerivAt (a x, b x)).comp x (ha.prodMk hb) @[fun_prop] theorem HasStrictFDerivAt.mul' {x : E} (ha : HasStrictFDerivAt a a' x) (hb : HasStrictFDerivAt b b' x) : HasStrictFDerivAt (a * b) (a x • b' + a' <• b x) x := ((ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.hasStrictFDerivAt (a x, b x)).comp x (ha.prodMk hb) @[fun_prop] theorem HasStrictFDerivAt.fun_mul (hc : HasStrictFDerivAt c c' x) (hd : HasStrictFDerivAt d d' x) : HasStrictFDerivAt (fun y => c y * d y) (c x • d' + d x • c') x := by convert hc.mul' hd ext z apply mul_comm @[fun_prop] theorem HasStrictFDerivAt.mul (hc : HasStrictFDerivAt c c' x) (hd : HasStrictFDerivAt d d' x) : HasStrictFDerivAt (c * d) (c x • d' + d x • c') x := by convert hc.mul' hd ext z apply mul_comm @[fun_prop] theorem HasFDerivWithinAt.fun_mul' (ha : HasFDerivWithinAt a a' s x) (hb : HasFDerivWithinAt b b' s x) : HasFDerivWithinAt (fun y => a y * b y) (a x • b' + a' <• b x) s x := by -- `by exact` to solve unification issues. exact ((ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.hasFDerivAt (a x, b x)).comp_hasFDerivWithinAt x (ha.prodMk hb) @[fun_prop] theorem HasFDerivWithinAt.mul' (ha : HasFDerivWithinAt a a' s x) (hb : HasFDerivWithinAt b b' s x) : HasFDerivWithinAt (a * b) (a x • b' + a' <• b x) s x := ha.fun_mul' hb @[fun_prop] theorem HasFDerivWithinAt.fun_mul (hc : HasFDerivWithinAt c c' s x) (hd : HasFDerivWithinAt d d' s x) : HasFDerivWithinAt (fun y => c y * d y) (c x • d' + d x • c') s x := by convert hc.mul' hd ext z apply mul_comm @[fun_prop] theorem HasFDerivWithinAt.mul (hc : HasFDerivWithinAt c c' s x) (hd : HasFDerivWithinAt d d' s x) : HasFDerivWithinAt (c * d) (c x • d' + d x • c') s x := hc.fun_mul hd @[fun_prop] theorem HasFDerivAt.fun_mul' (ha : HasFDerivAt a a' x) (hb : HasFDerivAt b b' x) : HasFDerivAt (fun y => a y * b y) (a x • b' + a' <• b x) x := by -- `by exact` to solve unification issues. exact ((ContinuousLinearMap.mul 𝕜 𝔸).isBoundedBilinearMap.hasFDerivAt (a x, b x)).comp x (ha.prodMk hb) @[fun_prop] theorem HasFDerivAt.mul' (ha : HasFDerivAt a a' x) (hb : HasFDerivAt b b' x) : HasFDerivAt (a * b) (a x • b' + a' <• b x) x := ha.fun_mul' hb @[fun_prop] theorem HasFDerivAt.fun_mul (hc : HasFDerivAt c c' x) (hd : HasFDerivAt d d' x) : HasFDerivAt (fun y => c y * d y) (c x • d' + d x • c') x := by convert hc.mul' hd ext z apply mul_comm @[fun_prop] theorem HasFDerivAt.mul (hc : HasFDerivAt c c' x) (hd : HasFDerivAt d d' x) : HasFDerivAt (c * d) (c x • d' + d x • c') x := hc.fun_mul hd @[fun_prop] theorem DifferentiableWithinAt.fun_mul (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : DifferentiableWithinAt 𝕜 (fun y => a y * b y) s x := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).differentiableWithinAt @[fun_prop] theorem DifferentiableWithinAt.mul (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : DifferentiableWithinAt 𝕜 (a * b) s x := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.fun_mul (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : DifferentiableAt 𝕜 (fun y => a y * b y) x := (ha.hasFDerivAt.mul' hb.hasFDerivAt).differentiableAt @[simp, fun_prop] theorem DifferentiableAt.mul (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : DifferentiableAt 𝕜 (a * b) x := (ha.hasFDerivAt.mul' hb.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.fun_mul (ha : DifferentiableOn 𝕜 a s) (hb : DifferentiableOn 𝕜 b s) : DifferentiableOn 𝕜 (fun y => a y * b y) s := fun x hx => (ha x hx).mul (hb x hx) @[fun_prop] theorem DifferentiableOn.mul (ha : DifferentiableOn 𝕜 a s) (hb : DifferentiableOn 𝕜 b s) : DifferentiableOn 𝕜 (a * b) s := fun x hx => (ha x hx).mul (hb x hx) @[simp, fun_prop] theorem Differentiable.fun_mul (ha : Differentiable 𝕜 a) (hb : Differentiable 𝕜 b) : Differentiable 𝕜 fun y => a y * b y := fun x => (ha x).mul (hb x) @[simp, fun_prop] theorem Differentiable.mul (ha : Differentiable 𝕜 a) (hb : Differentiable 𝕜 b) : Differentiable 𝕜 (a * b) := fun x => (ha x).mul (hb x) theorem fderivWithin_fun_mul' (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : fderivWithin 𝕜 (fun y => a y * b y) s x = a x • fderivWithin 𝕜 b s x + fderivWithin 𝕜 a s x <• b x := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).fderivWithin hxs theorem fderivWithin_mul' (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (hb : DifferentiableWithinAt 𝕜 b s x) : fderivWithin 𝕜 (a * b) s x = a x • fderivWithin 𝕜 b s x + fderivWithin 𝕜 a s x <• b x := (ha.hasFDerivWithinAt.mul' hb.hasFDerivWithinAt).fderivWithin hxs theorem fderivWithin_fun_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : fderivWithin 𝕜 (fun y => c y * d y) s x = c x • fderivWithin 𝕜 d s x + d x • fderivWithin 𝕜 c s x := (hc.hasFDerivWithinAt.mul hd.hasFDerivWithinAt).fderivWithin hxs theorem fderivWithin_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : fderivWithin 𝕜 (c * d) s x = c x • fderivWithin 𝕜 d s x + d x • fderivWithin 𝕜 c s x := (hc.hasFDerivWithinAt.mul hd.hasFDerivWithinAt).fderivWithin hxs theorem fderiv_fun_mul' (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : fderiv 𝕜 (fun y => a y * b y) x = a x • fderiv 𝕜 b x + fderiv 𝕜 a x <• b x := (ha.hasFDerivAt.mul' hb.hasFDerivAt).fderiv theorem fderiv_mul' (ha : DifferentiableAt 𝕜 a x) (hb : DifferentiableAt 𝕜 b x) : fderiv 𝕜 (a * b) x = a x • fderiv 𝕜 b x + fderiv 𝕜 a x <• b x := (ha.hasFDerivAt.mul' hb.hasFDerivAt).fderiv theorem fderiv_fun_mul (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : fderiv 𝕜 (fun y => c y * d y) x = c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x := (hc.hasFDerivAt.mul hd.hasFDerivAt).fderiv theorem fderiv_mul (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : fderiv 𝕜 (c * d) x = c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x := (hc.hasFDerivAt.mul hd.hasFDerivAt).fderiv @[fun_prop] theorem HasStrictFDerivAt.mul_const' (ha : HasStrictFDerivAt a a' x) (b : 𝔸) : HasStrictFDerivAt (fun y => a y * b) (a' <• b) x := ((ContinuousLinearMap.mul 𝕜 𝔸).flip b).hasStrictFDerivAt.comp x ha @[fun_prop] theorem HasStrictFDerivAt.mul_const (hc : HasStrictFDerivAt c c' x) (d : 𝔸') : HasStrictFDerivAt (fun y => c y * d) (d • c') x := by convert hc.mul_const' d ext z apply mul_comm @[fun_prop] theorem HasFDerivWithinAt.mul_const' (ha : HasFDerivWithinAt a a' s x) (b : 𝔸) : HasFDerivWithinAt (fun y => a y * b) (a' <• b) s x := ((ContinuousLinearMap.mul 𝕜 𝔸).flip b).hasFDerivAt.comp_hasFDerivWithinAt x ha @[fun_prop] theorem HasFDerivWithinAt.mul_const (hc : HasFDerivWithinAt c c' s x) (d : 𝔸') : HasFDerivWithinAt (fun y => c y * d) (d • c') s x := by convert hc.mul_const' d ext z apply mul_comm @[fun_prop] theorem HasFDerivAt.mul_const' (ha : HasFDerivAt a a' x) (b : 𝔸) : HasFDerivAt (fun y => a y * b) (a' <• b) x := ((ContinuousLinearMap.mul 𝕜 𝔸).flip b).hasFDerivAt.comp x ha @[fun_prop] theorem HasFDerivAt.mul_const (hc : HasFDerivAt c c' x) (d : 𝔸') : HasFDerivAt (fun y => c y * d) (d • c') x := by convert hc.mul_const' d ext z apply mul_comm @[fun_prop] theorem DifferentiableWithinAt.mul_const (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : DifferentiableWithinAt 𝕜 (fun y => a y * b) s x := (ha.hasFDerivWithinAt.mul_const' b).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.mul_const (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : DifferentiableAt 𝕜 (fun y => a y * b) x := (ha.hasFDerivAt.mul_const' b).differentiableAt @[fun_prop] theorem DifferentiableOn.mul_const (ha : DifferentiableOn 𝕜 a s) (b : 𝔸) : DifferentiableOn 𝕜 (fun y => a y * b) s := fun x hx => (ha x hx).mul_const b @[fun_prop] theorem Differentiable.mul_const (ha : Differentiable 𝕜 a) (b : 𝔸) : Differentiable 𝕜 fun y => a y * b := fun x => (ha x).mul_const b theorem fderivWithin_mul_const' (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : fderivWithin 𝕜 (fun y => a y * b) s x = fderivWithin 𝕜 a s x <• b := (ha.hasFDerivWithinAt.mul_const' b).fderivWithin hxs theorem fderivWithin_mul_const (hxs : UniqueDiffWithinAt 𝕜 s x) (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝔸') : fderivWithin 𝕜 (fun y => c y * d) s x = d • fderivWithin 𝕜 c s x := (hc.hasFDerivWithinAt.mul_const d).fderivWithin hxs theorem fderiv_mul_const' (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (fun y => a y * b) x = fderiv 𝕜 a x <• b := (ha.hasFDerivAt.mul_const' b).fderiv theorem fderiv_mul_const (hc : DifferentiableAt 𝕜 c x) (d : 𝔸') : fderiv 𝕜 (fun y => c y * d) x = d • fderiv 𝕜 c x := (hc.hasFDerivAt.mul_const d).fderiv @[fun_prop] theorem HasStrictFDerivAt.const_mul (ha : HasStrictFDerivAt a a' x) (b : 𝔸) : HasStrictFDerivAt (fun y => b * a y) (b • a') x := ((ContinuousLinearMap.mul 𝕜 𝔸) b).hasStrictFDerivAt.comp x ha @[fun_prop] theorem HasFDerivWithinAt.const_mul (ha : HasFDerivWithinAt a a' s x) (b : 𝔸) : HasFDerivWithinAt (fun y => b * a y) (b • a') s x := ((ContinuousLinearMap.mul 𝕜 𝔸) b).hasFDerivAt.comp_hasFDerivWithinAt x ha @[fun_prop] theorem HasFDerivAt.const_mul (ha : HasFDerivAt a a' x) (b : 𝔸) : HasFDerivAt (fun y => b * a y) (b • a') x := ((ContinuousLinearMap.mul 𝕜 𝔸) b).hasFDerivAt.comp x ha @[fun_prop] theorem DifferentiableWithinAt.const_mul (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : DifferentiableWithinAt 𝕜 (fun y => b * a y) s x := (ha.hasFDerivWithinAt.const_mul b).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.const_mul (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : DifferentiableAt 𝕜 (fun y => b * a y) x := (ha.hasFDerivAt.const_mul b).differentiableAt @[fun_prop] theorem DifferentiableOn.const_mul (ha : DifferentiableOn 𝕜 a s) (b : 𝔸) : DifferentiableOn 𝕜 (fun y => b * a y) s := fun x hx => (ha x hx).const_mul b @[fun_prop] theorem Differentiable.const_mul (ha : Differentiable 𝕜 a) (b : 𝔸) : Differentiable 𝕜 fun y => b * a y := fun x => (ha x).const_mul b theorem fderivWithin_const_mul (hxs : UniqueDiffWithinAt 𝕜 s x) (ha : DifferentiableWithinAt 𝕜 a s x) (b : 𝔸) : fderivWithin 𝕜 (fun y => b * a y) s x = b • fderivWithin 𝕜 a s x := (ha.hasFDerivWithinAt.const_mul b).fderivWithin hxs theorem fderiv_const_mul (ha : DifferentiableAt 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (fun y => b * a y) x = b • fderiv 𝕜 a x := (ha.hasFDerivAt.const_mul b).fderiv end Mul section Prod open scoped RightActions /-! ### Derivative of a finite product of functions -/ variable {ι : Type*} {𝔸 𝔸' : Type*} [NormedRing 𝔸] [NormedCommRing 𝔸'] [NormedAlgebra 𝕜 𝔸] [NormedAlgebra 𝕜 𝔸'] {u : Finset ι} {f : ι → E → 𝔸} {f' : ι → E →L[𝕜] 𝔸} {g : ι → E → 𝔸'} {g' : ι → E →L[𝕜] 𝔸'} @[fun_prop] theorem hasStrictFDerivAt_list_prod' [Fintype ι] {l : List ι} {x : ι → 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.map x).prod) (∑ i : Fin l.length, ((l.take i).map x).prod • proj l[i] <• ((l.drop (.succ i)).map x).prod) x := by induction l with | nil => simp [hasStrictFDerivAt_const] | cons a l IH => simp only [List.map_cons, List.prod_cons, ← proj_apply (R := 𝕜) (φ := fun _ : ι ↦ 𝔸) a] exact .congr_fderiv (.mul' (ContinuousLinearMap.hasStrictFDerivAt _) IH) (by ext; simp [Fin.sum_univ_succ, Finset.mul_sum, mul_assoc, add_comm]) @[fun_prop] theorem hasStrictFDerivAt_list_prod_finRange' {n : ℕ} {x : Fin n → 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ ((List.finRange n).map x).prod) (∑ i : Fin n, (((List.finRange n).take i).map x).prod • proj i <• (((List.finRange n).drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.congr_fderiv <| Finset.sum_equiv (finCongr List.length_finRange) (by simp) (by simp) @[fun_prop] theorem hasStrictFDerivAt_list_prod_attach' {l : List ι} {x : {i // i ∈ l} → 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.attach.map x).prod) (∑ i : Fin l.length, ((l.attach.take i).map x).prod • proj l.attach[i.cast List.length_attach.symm] <• ((l.attach.drop (.succ i)).map x).prod) x := by classical exact hasStrictFDerivAt_list_prod'.congr_fderiv <| Eq.symm <| Finset.sum_equiv (finCongr List.length_attach.symm) (by simp) (by simp) @[fun_prop] theorem hasFDerivAt_list_prod' [Fintype ι] {l : List ι} {x : ι → 𝔸'} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.map x).prod) (∑ i : Fin l.length, ((l.take i).map x).prod • proj l[i] <• ((l.drop (.succ i)).map x).prod) x := hasStrictFDerivAt_list_prod'.hasFDerivAt @[fun_prop] theorem hasFDerivAt_list_prod_finRange' {n : ℕ} {x : Fin n → 𝔸} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ ((List.finRange n).map x).prod) (∑ i : Fin n, (((List.finRange n).take i).map x).prod • proj i <• (((List.finRange n).drop (.succ i)).map x).prod) x := (hasStrictFDerivAt_list_prod_finRange').hasFDerivAt @[fun_prop] theorem hasFDerivAt_list_prod_attach' {l : List ι} {x : {i // i ∈ l} → 𝔸} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.attach.map x).prod) (∑ i : Fin l.length, ((l.attach.take i).map x).prod • (proj l.attach[i.cast List.length_attach.symm]) <• ((l.attach.drop (.succ i)).map x).prod) x := by classical exact hasStrictFDerivAt_list_prod_attach'.hasFDerivAt /-- Auxiliary lemma for `hasStrictFDerivAt_multiset_prod`. For `NormedCommRing 𝔸'`, can rewrite as `Multiset` using `Multiset.prod_coe`. -/ @[fun_prop] theorem hasStrictFDerivAt_list_prod [DecidableEq ι] [Fintype ι] {l : List ι} {x : ι → 𝔸'} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (l.map x).prod) (l.map fun i ↦ ((l.erase i).map x).prod • proj i).sum x := by refine hasStrictFDerivAt_list_prod'.congr_fderiv ?_ conv_rhs => arg 1; arg 2; rw [← List.finRange_map_get l] simp only [List.map_map, ← List.sum_toFinset _ (List.nodup_finRange _), List.toFinset_finRange, Function.comp_def, ((List.erase_getElem _).map _).prod_eq, List.eraseIdx_eq_take_drop_succ, List.map_append, List.prod_append, List.get_eq_getElem, Fin.getElem_fin, Nat.succ_eq_add_one] exact Finset.sum_congr rfl fun i _ ↦ by ext; simp only [smul_apply, op_smul_eq_smul, smul_eq_mul]; ring @[fun_prop] theorem hasStrictFDerivAt_multiset_prod [DecidableEq ι] [Fintype ι] {u : Multiset ι} {x : ι → 𝔸'} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ (u.map x).prod) (u.map (fun i ↦ ((u.erase i).map x).prod • proj i)).sum x := u.inductionOn fun l ↦ by simpa using hasStrictFDerivAt_list_prod @[fun_prop] theorem hasFDerivAt_multiset_prod [DecidableEq ι] [Fintype ι] {u : Multiset ι} {x : ι → 𝔸'} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ (u.map x).prod) (Multiset.sum (u.map (fun i ↦ ((u.erase i).map x).prod • proj i))) x := hasStrictFDerivAt_multiset_prod.hasFDerivAt theorem hasStrictFDerivAt_finset_prod [DecidableEq ι] [Fintype ι] {x : ι → 𝔸'} : HasStrictFDerivAt (𝕜 := 𝕜) (∏ i ∈ u, · i) (∑ i ∈ u, (∏ j ∈ u.erase i, x j) • proj i) x := by simp only [Finset.sum_eq_multiset_sum, Finset.prod_eq_multiset_prod] exact hasStrictFDerivAt_multiset_prod theorem hasFDerivAt_finset_prod [DecidableEq ι] [Fintype ι] {x : ι → 𝔸'} : HasFDerivAt (𝕜 := 𝕜) (∏ i ∈ u, · i) (∑ i ∈ u, (∏ j ∈ u.erase i, x j) • proj i) x := hasStrictFDerivAt_finset_prod.hasFDerivAt section Comp @[fun_prop] theorem HasStrictFDerivAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasStrictFDerivAt (f i ·) (f' i) x) : HasStrictFDerivAt (fun x ↦ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • f' l[i] <• ((l.drop (.succ i)).map (f · x)).prod) x := by simp_rw [Fin.getElem_fin, ← l.get_eq_getElem, ← List.finRange_map_get l, List.map_map] -- After #19108, we have to be optimistic with `:)`s; otherwise Lean decides it need to find -- `NormedAddCommGroup (List 𝔸)` which is nonsense. refine .congr_fderiv (hasStrictFDerivAt_list_prod_finRange'.comp x (hasStrictFDerivAt_pi.mpr fun i ↦ h (l.get i) (List.getElem_mem ..)) :) ?_ ext m simp_rw [List.map_take, List.map_drop, List.map_map, comp_apply, sum_apply, smul_apply, proj_apply, pi_apply, Function.comp_def] /-- Unlike `HasFDerivAt.finset_prod`, supports non-commutative multiply and duplicate elements. -/ @[fun_prop] theorem HasFDerivAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasFDerivAt (f i ·) (f' i) x) : HasFDerivAt (fun x ↦ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • f' l[i] <• ((l.drop (.succ i)).map (f · x)).prod) x := by simp_rw [Fin.getElem_fin, ← l.get_eq_getElem, ← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasFDerivAt_list_prod_finRange'.comp x (hasFDerivAt_pi.mpr fun i ↦ h (l.get i) (l.get_mem i)) :) ?_ ext m simp_rw [List.map_take, List.map_drop, List.map_map, comp_apply, sum_apply, smul_apply, proj_apply, pi_apply, Function.comp_def] @[fun_prop] theorem HasFDerivWithinAt.list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, HasFDerivWithinAt (f i ·) (f' i) s x) : HasFDerivWithinAt (fun x ↦ (l.map (f · x)).prod) (∑ i : Fin l.length, ((l.take i).map (f · x)).prod • f' l[i] <• ((l.drop (.succ i)).map (f · x)).prod) s x := by simp_rw [Fin.getElem_fin, ← l.get_eq_getElem, ← List.finRange_map_get l, List.map_map] refine .congr_fderiv (hasFDerivAt_list_prod_finRange'.comp_hasFDerivWithinAt x (hasFDerivWithinAt_pi.mpr fun i ↦ h (l.get i) (l.get_mem i)) :) ?_ ext m simp_rw [List.map_take, List.map_drop, List.map_map, comp_apply, sum_apply, smul_apply, proj_apply, pi_apply, Function.comp_def] theorem fderiv_list_prod' {l : List ι} {x : E} (h : ∀ i ∈ l, DifferentiableAt 𝕜 (f i ·) x) : fderiv 𝕜 (fun x ↦ (l.map (f · x)).prod) x = ∑ i : Fin l.length, ((l.take i).map (f · x)).prod • (fderiv 𝕜 (fun x ↦ f l[i] x) x) <• ((l.drop (.succ i)).map (f · x)).prod := (HasFDerivAt.list_prod' fun i hi ↦ (h i hi).hasFDerivAt).fderiv theorem fderivWithin_list_prod' {l : List ι} {x : E} (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ l, DifferentiableWithinAt 𝕜 (f i ·) s x) : fderivWithin 𝕜 (fun x ↦ (l.map (f · x)).prod) s x = ∑ i : Fin l.length, ((l.take i).map (f · x)).prod • (fderivWithin 𝕜 (fun x ↦ f l[i] x) s x) <• ((l.drop (.succ i)).map (f · x)).prod := (HasFDerivWithinAt.list_prod' fun i hi ↦ (h i hi).hasFDerivWithinAt).fderivWithin hxs @[fun_prop] theorem HasStrictFDerivAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasStrictFDerivAt (g i ·) (g' i) x) : HasStrictFDerivAt (fun x ↦ (u.map (g · x)).prod) (u.map fun i ↦ ((u.erase i).map (g · x)).prod • g' i).sum x := by simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasStrictFDerivAt_multiset_prod.comp x <| hasStrictFDerivAt_pi.mpr fun i ↦ h (Subtype.val i) i.prop :) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)]) /-- Unlike `HasFDerivAt.finset_prod`, supports duplicate elements. -/ @[fun_prop] theorem HasFDerivAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasFDerivAt (g i ·) (g' i) x) : HasFDerivAt (fun x ↦ (u.map (g · x)).prod) (u.map fun i ↦ ((u.erase i).map (g · x)).prod • g' i).sum x := by simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasFDerivAt_multiset_prod.comp x <| hasFDerivAt_pi.mpr fun i ↦ h (Subtype.val i) i.prop :) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)]) @[fun_prop] theorem HasFDerivWithinAt.multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, HasFDerivWithinAt (g i ·) (g' i) s x) : HasFDerivWithinAt (fun x ↦ (u.map (g · x)).prod) (u.map fun i ↦ ((u.erase i).map (g · x)).prod • g' i).sum s x := by simp only [← Multiset.attach_map_val u, Multiset.map_map] exact .congr_fderiv (hasFDerivAt_multiset_prod.comp_hasFDerivWithinAt x <| hasFDerivWithinAt_pi.mpr fun i ↦ h (Subtype.val i) i.prop :) (by ext; simp [Finset.sum_multiset_map_count, u.erase_attach_map (g · x)]) theorem fderiv_multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (h : ∀ i ∈ u, DifferentiableAt 𝕜 (g i ·) x) : fderiv 𝕜 (fun x ↦ (u.map (g · x)).prod) x = (u.map fun i ↦ ((u.erase i).map (g · x)).prod • fderiv 𝕜 (g i) x).sum := (HasFDerivAt.multiset_prod fun i hi ↦ (h i hi).hasFDerivAt).fderiv theorem fderivWithin_multiset_prod [DecidableEq ι] {u : Multiset ι} {x : E} (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (g i ·) s x) : fderivWithin 𝕜 (fun x ↦ (u.map (g · x)).prod) s x = (u.map fun i ↦ ((u.erase i).map (g · x)).prod • fderivWithin 𝕜 (g i) s x).sum := (HasFDerivWithinAt.multiset_prod fun i hi ↦ (h i hi).hasFDerivWithinAt).fderivWithin hxs theorem HasStrictFDerivAt.finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, HasStrictFDerivAt (g i) (g' i) x) : HasStrictFDerivAt (∏ i ∈ u, g i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, g j x) • g' i) x := by simpa [← Finset.prod_attach u] using .congr_fderiv (hasStrictFDerivAt_finset_prod.comp x <| hasStrictFDerivAt_pi.mpr fun i ↦ hg i i.prop) (by ext; simp [Finset.prod_erase_attach (g · x), ← u.sum_attach]) theorem HasFDerivAt.finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, HasFDerivAt (g i) (g' i) x) : HasFDerivAt (∏ i ∈ u, g i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, g j x) • g' i) x := by simpa [← Finset.prod_attach u] using .congr_fderiv (hasFDerivAt_finset_prod.comp x <| hasFDerivAt_pi.mpr fun i ↦ hg (Subtype.val i) i.prop :) (by ext; simp [Finset.prod_erase_attach (g · x), ← u.sum_attach]) theorem HasFDerivWithinAt.finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, HasFDerivWithinAt (g i) (g' i) s x) : HasFDerivWithinAt (∏ i ∈ u, g i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, g j x) • g' i) s x := by simpa [← Finset.prod_attach u] using .congr_fderiv (hasFDerivAt_finset_prod.comp_hasFDerivWithinAt x <| hasFDerivWithinAt_pi.mpr fun i ↦ hg (Subtype.val i) i.prop :) (by ext; simp [Finset.prod_erase_attach (g · x), ← u.sum_attach]) theorem fderiv_finset_prod [DecidableEq ι] {x : E} (hg : ∀ i ∈ u, DifferentiableAt 𝕜 (g i) x) : fderiv 𝕜 (∏ i ∈ u, g i ·) x = ∑ i ∈ u, (∏ j ∈ u.erase i, (g j x)) • fderiv 𝕜 (g i) x := (HasFDerivAt.finset_prod fun i hi ↦ (hg i hi).hasFDerivAt).fderiv theorem fderivWithin_finset_prod [DecidableEq ι] {x : E} (hxs : UniqueDiffWithinAt 𝕜 s x) (hg : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (g i) s x) : fderivWithin 𝕜 (∏ i ∈ u, g i ·) s x = ∑ i ∈ u, (∏ j ∈ u.erase i, (g j x)) • fderivWithin 𝕜 (g i) s x := (HasFDerivWithinAt.finset_prod fun i hi ↦ (hg i hi).hasFDerivWithinAt).fderivWithin hxs end Comp end Prod section AlgebraInverse variable {R : Type*} [NormedRing R] [HasSummableGeomSeries R] [NormedAlgebra 𝕜 R] open NormedRing ContinuousLinearMap Ring /-- At an invertible element `x` of a normed algebra `R`, the Fréchet derivative of the inversion operation is the linear map `fun t ↦ - x⁻¹ * t * x⁻¹`. TODO (low prio): prove a version without assumption `[HasSummableGeomSeries R]` but within the set of units. -/ @[fun_prop] theorem hasFDerivAt_ringInverse (x : Rˣ) : HasFDerivAt Ring.inverse (-mulLeftRight 𝕜 R ↑x⁻¹ ↑x⁻¹) x := have : (fun t : R => Ring.inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) =o[𝓝 0] id := (inverse_add_norm_diff_second_order x).trans_isLittleO (isLittleO_norm_pow_id one_lt_two) by simpa [hasFDerivAt_iff_isLittleO_nhds_zero] using this @[deprecated (since := "2025-04-22")] alias hasFDerivAt_ring_inverse := hasFDerivAt_ringInverse @[fun_prop] theorem differentiableAt_inverse {x : R} (hx : IsUnit x) : DifferentiableAt 𝕜 (@Ring.inverse R _) x := let ⟨u, hu⟩ := hx; hu ▸ (hasFDerivAt_ringInverse u).differentiableAt @[fun_prop] theorem differentiableWithinAt_inverse {x : R} (hx : IsUnit x) (s : Set R) : DifferentiableWithinAt 𝕜 (@Ring.inverse R _) s x := (differentiableAt_inverse hx).differentiableWithinAt @[fun_prop] theorem differentiableOn_inverse : DifferentiableOn 𝕜 (@Ring.inverse R _) {x | IsUnit x} := fun _x hx => differentiableWithinAt_inverse hx _ theorem fderiv_inverse (x : Rˣ) : fderiv 𝕜 (@Ring.inverse R _) x = -mulLeftRight 𝕜 R ↑x⁻¹ ↑x⁻¹ := (hasFDerivAt_ringInverse x).fderiv theorem hasStrictFDerivAt_ringInverse (x : Rˣ) : HasStrictFDerivAt Ring.inverse (-mulLeftRight 𝕜 R ↑x⁻¹ ↑x⁻¹) x := by convert (analyticAt_inverse (𝕜 := 𝕜) x).hasStrictFDerivAt exact (fderiv_inverse x).symm @[deprecated (since := "2025-04-22")] alias hasStrictFDerivAt_ring_inverse := hasStrictFDerivAt_ringInverse variable {h : E → R} {z : E} {S : Set E} @[fun_prop] theorem DifferentiableWithinAt.inverse (hf : DifferentiableWithinAt 𝕜 h S z) (hz : IsUnit (h z)) : DifferentiableWithinAt 𝕜 (fun x => Ring.inverse (h x)) S z := (differentiableAt_inverse hz).comp_differentiableWithinAt z hf @[simp, fun_prop] theorem DifferentiableAt.inverse (hf : DifferentiableAt 𝕜 h z) (hz : IsUnit (h z)) : DifferentiableAt 𝕜 (fun x => Ring.inverse (h x)) z := (differentiableAt_inverse hz).comp z hf @[fun_prop] theorem DifferentiableOn.inverse (hf : DifferentiableOn 𝕜 h S) (hz : ∀ x ∈ S, IsUnit (h x)) : DifferentiableOn 𝕜 (fun x => Ring.inverse (h x)) S := fun x h => (hf x h).inverse (hz x h) @[simp, fun_prop] theorem Differentiable.inverse (hf : Differentiable 𝕜 h) (hz : ∀ x, IsUnit (h x)) : Differentiable 𝕜 fun x => Ring.inverse (h x) := fun x => (hf x).inverse (hz x) end AlgebraInverse /-! ### Derivative of the inverse in a division ring Note that some lemmas are primed as they are expressed without commutativity, whereas their counterparts in commutative fields involve simpler expressions, and are given in `Mathlib/Analysis/Calculus/Deriv/Inv.lean`. -/ section DivisionRingInverse variable {R : Type*} [NormedDivisionRing R] [NormedAlgebra 𝕜 R] open NormedRing ContinuousLinearMap Ring /-- At an invertible element `x` of a normed division algebra `R`, the inversion is strictly differentiable, with derivative the linear map `fun t ↦ - x⁻¹ * t * x⁻¹`. For a nicer formula in the commutative case, see `hasStrictFDerivAt_inv`. -/ theorem hasStrictFDerivAt_inv' {x : R} (hx : x ≠ 0) : HasStrictFDerivAt Inv.inv (-mulLeftRight 𝕜 R x⁻¹ x⁻¹) x := by simpa using hasStrictFDerivAt_ringInverse (Units.mk0 _ hx) /-- At an invertible element `x` of a normed division algebra `R`, the Fréchet derivative of the inversion operation is the linear map `fun t ↦ - x⁻¹ * t * x⁻¹`. For a nicer formula in the commutative case, see `hasFDerivAt_inv`. -/ @[fun_prop] theorem hasFDerivAt_inv' {x : R} (hx : x ≠ 0) : HasFDerivAt Inv.inv (-mulLeftRight 𝕜 R x⁻¹ x⁻¹) x := by simpa using hasFDerivAt_ringInverse (Units.mk0 _ hx) @[fun_prop] theorem differentiableAt_inv {x : R} (hx : x ≠ 0) : DifferentiableAt 𝕜 Inv.inv x := (hasFDerivAt_inv' hx).differentiableAt @[fun_prop] theorem differentiableWithinAt_inv {x : R} (hx : x ≠ 0) (s : Set R) : DifferentiableWithinAt 𝕜 (fun x => x⁻¹) s x := (differentiableAt_inv hx).differentiableWithinAt @[fun_prop] theorem differentiableOn_inv : DifferentiableOn 𝕜 (fun x : R => x⁻¹) {x | x ≠ 0} := fun _x hx => differentiableWithinAt_inv hx _ /-- Non-commutative version of `fderiv_inv` -/ theorem fderiv_inv' {x : R} (hx : x ≠ 0) : fderiv 𝕜 Inv.inv x = -mulLeftRight 𝕜 R x⁻¹ x⁻¹ := (hasFDerivAt_inv' hx).fderiv /-- Non-commutative version of `fderivWithin_inv` -/ theorem fderivWithin_inv' {s : Set R} {x : R} (hx : x ≠ 0) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x => x⁻¹) s x = -mulLeftRight 𝕜 R x⁻¹ x⁻¹ := by rw [DifferentiableAt.fderivWithin (differentiableAt_inv hx) hxs] exact fderiv_inv' hx variable {h : E → R} {z : E} {S : Set E} @[fun_prop] theorem DifferentiableWithinAt.fun_inv (hf : DifferentiableWithinAt 𝕜 h S z) (hz : h z ≠ 0) : DifferentiableWithinAt 𝕜 (fun x => (h x)⁻¹) S z := (differentiableAt_inv hz).comp_differentiableWithinAt z hf @[fun_prop] theorem DifferentiableWithinAt.inv (hf : DifferentiableWithinAt 𝕜 h S z) (hz : h z ≠ 0) : DifferentiableWithinAt 𝕜 (h⁻¹) S z := (differentiableAt_inv hz).comp_differentiableWithinAt z hf @[simp, fun_prop] theorem DifferentiableAt.fun_inv (hf : DifferentiableAt 𝕜 h z) (hz : h z ≠ 0) : DifferentiableAt 𝕜 (fun x => (h x)⁻¹) z := (differentiableAt_inv hz).comp z hf @[simp, fun_prop] theorem DifferentiableAt.inv (hf : DifferentiableAt 𝕜 h z) (hz : h z ≠ 0) : DifferentiableAt 𝕜 (h⁻¹) z := (differentiableAt_inv hz).comp z hf @[fun_prop] theorem DifferentiableOn.fun_inv (hf : DifferentiableOn 𝕜 h S) (hz : ∀ x ∈ S, h x ≠ 0) : DifferentiableOn 𝕜 (fun x => (h x)⁻¹) S := fun x h => (hf x h).inv (hz x h) @[fun_prop] theorem DifferentiableOn.inv (hf : DifferentiableOn 𝕜 h S) (hz : ∀ x ∈ S, h x ≠ 0) : DifferentiableOn 𝕜 (h⁻¹) S := fun x h => (hf x h).inv (hz x h) @[simp, fun_prop] theorem Differentiable.fun_inv (hf : Differentiable 𝕜 h) (hz : ∀ x, h x ≠ 0) : Differentiable 𝕜 fun x => (h x)⁻¹ := fun x => (hf x).inv (hz x) @[simp, fun_prop] theorem Differentiable.inv (hf : Differentiable 𝕜 h) (hz : ∀ x, h x ≠ 0) : Differentiable 𝕜 (h⁻¹) := fun x => (hf x).inv (hz x) end DivisionRingInverse end
AlexandrovDiscrete.lean
/- Copyright (c) 2025 Miyahara Kō. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Miyahara Kō -/ import Mathlib.Topology.Separation.Basic import Mathlib.Topology.AlexandrovDiscrete /-! # T1 Alexandrov-discrete topology is discrete -/ open Filter variable {X : Type*} [TopologicalSpace X] @[simp] lemma nhdsKer_eq_of_t1Space [T1Space X] (s : Set X) : nhdsKer s = s := by ext; simp [mem_nhdsKer_iff_specializes] instance (priority := low) [AlexandrovDiscrete X] [T1Space X] : DiscreteTopology X := by simp [discreteTopology_iff_nhds, ← principal_nhdsKer_singleton]
Pow.lean
/- Copyright (c) 2025 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # Fréchet Derivative of `f x ^ n`, `n : ℕ` In this file we prove that the Fréchet derivative of `fun x => f x ^ n`, where `n` is a natural number, is `n • f x ^ (n - 1)) • f'`. Additionally, we prove the case for non-commutative rings (with primed names like `fderiv_pow'`), where the result is instead `∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> f' <• f x ^ i`. For detailed documentation of the Fréchet derivative, see the module docstring of `Mathlib/Analysis/Calculus/FDeriv/Basic.lean`. ## Keywords derivative, power -/ variable {𝕜 𝔸 E : Type*} section NormedRing variable [NontriviallyNormedField 𝕜] [NormedRing 𝔸] [NormedAddCommGroup E] variable [NormedAlgebra 𝕜 𝔸] [NormedSpace 𝕜 E] {f : E → 𝔸} {f' : E →L[𝕜] 𝔸} {x : E} {s : Set E} open scoped RightActions private theorem aux (f : E → 𝔸) (f' : E →L[𝕜] 𝔸) (x : E) (n : ℕ) : f x •> ∑ i ∈ Finset.range (n + 1), f x ^ ((n + 1).pred - i) •> f' <• f x ^ i + f' <• (f x ^ (n + 1)) = ∑ i ∈ Finset.range (n + 1 + 1), f x ^ ((n + 1 + 1).pred - i) •> f' <• f x ^ i := by rw [Finset.sum_range_succ _ (n + 1), Finset.smul_sum] simp only [Nat.pred_eq_sub_one, add_tsub_cancel_right, tsub_self, pow_zero, one_smul] simp_rw [smul_comm (_ : 𝔸) (_ : 𝔸ᵐᵒᵖ), smul_smul, ← pow_succ'] congr! 5 with x hx simp [Nat.lt_succ_iff] at hx rw [tsub_add_eq_add_tsub hx] theorem HasStrictFDerivAt.fun_pow' (h : HasStrictFDerivAt f f' x) (n : ℕ) : HasStrictFDerivAt (fun x ↦ f x ^ n) (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> f' <• f x ^ i) x := match n with | 0 => by simpa using hasStrictFDerivAt_const 1 x | 1 => by simpa using h | n + 1 + 1 => by have := h.mul' (h.fun_pow' (n + 1)) simp_rw [pow_succ' _ (n + 1)] refine this.congr_fderiv <| aux _ _ _ _ theorem HasStrictFDerivAt.pow' (h : HasStrictFDerivAt f f' x) (n : ℕ) : HasStrictFDerivAt (f ^ n) (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> f' <• f x ^ i) x := h.fun_pow' n theorem hasStrictFDerivAt_pow' (n : ℕ) {x : 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x ↦ x ^ n) (∑ i ∈ Finset.range n, x ^ (n.pred - i) •> ContinuousLinearMap.id 𝕜 _ <• x ^ i) x := hasStrictFDerivAt_id _ |>.pow' n theorem HasFDerivWithinAt.fun_pow' (h : HasFDerivWithinAt f f' s x) (n : ℕ) : HasFDerivWithinAt (fun x ↦ f x ^ n) (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> f' <• f x ^ i) s x := match n with | 0 => by simpa using hasFDerivWithinAt_const 1 x s | 1 => by simpa using h | n + 1 + 1 => by have := h.mul' (h.fun_pow' (n + 1)) simp_rw [pow_succ' _ (n + 1)] exact this.congr_fderiv <| aux _ _ _ _ theorem HasFDerivWithinAt.pow' (h : HasFDerivWithinAt f f' s x) (n : ℕ) : HasFDerivWithinAt (f ^ n) (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> f' <• f x ^ i) s x := h.fun_pow' n theorem hasFDerivWithinAt_pow' (n : ℕ) {x : 𝔸} {s : Set 𝔸} : HasFDerivWithinAt (𝕜 := 𝕜) (fun x ↦ x ^ n) (∑ i ∈ Finset.range n, x ^ (n.pred - i) •> ContinuousLinearMap.id 𝕜 _ <• x ^ i) s x := hasFDerivWithinAt_id _ _ |>.pow' n theorem HasFDerivAt.fun_pow' (h : HasFDerivAt f f' x) (n : ℕ) : HasFDerivAt (fun x ↦ f x ^ n) (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> f' <• f x ^ i) x := match n with | 0 => by simpa using hasFDerivAt_const 1 x | 1 => by simpa using h | n + 1 + 1 => by have := h.mul' (h.fun_pow' (n + 1)) simp_rw [pow_succ' _ (n + 1)] exact this.congr_fderiv <| aux _ _ _ _ theorem HasFDerivAt.pow' (h : HasFDerivAt f f' x) (n : ℕ) : HasFDerivAt (f ^ n) (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> f' <• f x ^ i) x := h.fun_pow' n theorem hasFDerivAt_pow' (n : ℕ) {x : 𝔸} : HasFDerivAt (𝕜 := 𝕜) (fun x ↦ x ^ n) (∑ i ∈ Finset.range n, x ^ (n.pred - i) •> ContinuousLinearMap.id 𝕜 _ <• x ^ i) x := hasFDerivAt_id _ |>.pow' n @[fun_prop] theorem DifferentiableWithinAt.fun_pow (hf : DifferentiableWithinAt 𝕜 f s x) (n : ℕ) : DifferentiableWithinAt 𝕜 (fun x => f x ^ n) s x := let ⟨_, hf'⟩ := hf; ⟨_, hf'.pow' n⟩ @[fun_prop] theorem DifferentiableWithinAt.pow (hf : DifferentiableWithinAt 𝕜 f s x) : ∀ n : ℕ, DifferentiableWithinAt 𝕜 (f ^ n) s x := hf.fun_pow theorem differentiableWithinAt_pow (n : ℕ) {x : 𝔸} {s : Set 𝔸} : DifferentiableWithinAt 𝕜 (fun x : 𝔸 => x ^ n) s x := differentiableWithinAt_id.pow _ @[simp, fun_prop] theorem DifferentiableAt.fun_pow (hf : DifferentiableAt 𝕜 f x) (n : ℕ) : DifferentiableAt 𝕜 (fun x => f x ^ n) x := differentiableWithinAt_univ.mp <| hf.differentiableWithinAt.pow n @[simp, fun_prop] theorem DifferentiableAt.pow (hf : DifferentiableAt 𝕜 f x) (n : ℕ) : DifferentiableAt 𝕜 (f ^ n) x := hf.fun_pow n theorem differentiableAt_pow (n : ℕ) {x : 𝔸} : DifferentiableAt 𝕜 (fun x : 𝔸 => x ^ n) x := differentiableAt_id.pow _ @[fun_prop] theorem DifferentiableOn.fun_pow (hf : DifferentiableOn 𝕜 f s) (n : ℕ) : DifferentiableOn 𝕜 (fun x => f x ^ n) s := fun x h => (hf x h).pow n @[fun_prop] theorem DifferentiableOn.pow (hf : DifferentiableOn 𝕜 f s) (n : ℕ) : DifferentiableOn 𝕜 (f ^ n) s := hf.fun_pow n theorem differentiableOn_pow (n : ℕ) {s : Set 𝔸} : DifferentiableOn 𝕜 (fun x : 𝔸 => x ^ n) s := differentiableOn_id.pow n @[simp, fun_prop] theorem Differentiable.fun_pow (hf : Differentiable 𝕜 f) (n : ℕ) : Differentiable 𝕜 fun x => f x ^ n := fun x => (hf x).pow n @[simp, fun_prop] theorem Differentiable.pow (hf : Differentiable 𝕜 f) (n : ℕ) : Differentiable 𝕜 (f ^ n) := hf.fun_pow n theorem differentiable_pow (n : ℕ) : Differentiable 𝕜 fun x : 𝔸 => x ^ n := differentiable_id.pow _ theorem fderiv_fun_pow' (n : ℕ) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (fun x ↦ f x ^ n) x = (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> fderiv 𝕜 f x <• f x ^ i) := hf.hasFDerivAt.pow' n |>.fderiv theorem fderiv_pow' (n : ℕ) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (f ^ n) x = (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> fderiv 𝕜 f x <• f x ^ i) := fderiv_fun_pow' n hf theorem fderiv_pow_ring' {x : 𝔸} (n : ℕ) : fderiv 𝕜 (fun x : 𝔸 ↦ x ^ n) x = (∑ i ∈ Finset.range n, x ^ (n.pred - i) •> .id _ _ <• x ^ i) := by rw [fderiv_fun_pow' n differentiableAt_fun_id, fderiv_id'] theorem fderivWithin_fun_pow' (hxs : UniqueDiffWithinAt 𝕜 s x) (n : ℕ) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (fun x ↦ f x ^ n) s x = (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> fderivWithin 𝕜 f s x <• f x ^ i) := hf.hasFDerivWithinAt.pow' n |>.fderivWithin hxs theorem fderivWithin_pow' (hxs : UniqueDiffWithinAt 𝕜 s x) (n : ℕ) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (f ^ n) s x = (∑ i ∈ Finset.range n, f x ^ (n.pred - i) •> fderivWithin 𝕜 f s x <• f x ^ i) := fderivWithin_fun_pow' hxs n hf theorem fderivWithin_pow_ring' {s : Set 𝔸} {x : 𝔸} (n : ℕ) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x : 𝔸 ↦ x ^ n) s x = (∑ i ∈ Finset.range n, x ^ (n.pred - i) •> .id _ _ <• x ^ i) := by rw [fderivWithin_fun_pow' hxs n differentiableAt_fun_id.differentiableWithinAt, fderivWithin_id' hxs] end NormedRing section NormedCommRing variable [NontriviallyNormedField 𝕜] [NormedCommRing 𝔸] [NormedAddCommGroup E] variable [NormedAlgebra 𝕜 𝔸] [NormedSpace 𝕜 E] {f : E → 𝔸} {f' : E →L[𝕜] 𝔸} {x : E} {s : Set E} private theorem aux_sum_eq_pow (n : ℕ) : ∑ i ∈ Finset.range n, MulOpposite.op (f x ^ i) • f x ^ (n.pred - i) • f' = (n • f x ^ (n - 1)) • f' := by simp_rw [op_smul_eq_smul, smul_smul, ← pow_add, ← Finset.sum_smul] rw [Finset.sum_eq_card_nsmul, Finset.card_range, smul_assoc] intros a ha congr exact add_tsub_cancel_of_le (Nat.le_pred_of_lt <| Finset.mem_range.1 ha) theorem HasStrictFDerivAt.pow (h : HasStrictFDerivAt f f' x) (n : ℕ) : HasStrictFDerivAt (fun x ↦ f x ^ n) ((n • f x ^ (n - 1)) • f') x := h.pow' n |>.congr_fderiv <| aux_sum_eq_pow _ theorem hasStrictFDerivAt_pow (n : ℕ) {x : 𝔸} : HasStrictFDerivAt (𝕜 := 𝕜) (fun x : 𝔸 ↦ x ^ n) ((n • x ^ (n - 1)) • ContinuousLinearMap.id 𝕜 𝔸) x := hasStrictFDerivAt_id _ |>.pow n theorem HasFDerivWithinAt.pow (h : HasFDerivWithinAt f f' s x) (n : ℕ) : HasFDerivWithinAt (fun x ↦ f x ^ n) ((n • f x ^ (n - 1)) • f') s x := h.pow' n |>.congr_fderiv <| aux_sum_eq_pow _ theorem hasFDerivWithinAt_pow (n : ℕ) {x : 𝔸} {s : Set 𝔸} : HasFDerivWithinAt (𝕜 := 𝕜) (fun x : 𝔸 ↦ x ^ n) ((n • x ^ (n - 1)) • ContinuousLinearMap.id 𝕜 𝔸) s x := hasFDerivWithinAt_id _ _ |>.pow n theorem HasFDerivAt.pow (h : HasFDerivAt f f' x) (n : ℕ) : HasFDerivAt (fun x ↦ f x ^ n) ((n • f x ^ (n - 1)) • f') x := h.pow' n |>.congr_fderiv <| aux_sum_eq_pow _ theorem hasFDerivAt_pow (n : ℕ) {x : 𝔸} : HasFDerivAt (𝕜 := 𝕜) (fun x : 𝔸 ↦ x ^ n) ((n • x ^ (n - 1)) • ContinuousLinearMap.id 𝕜 𝔸) x := hasFDerivAt_id _ |>.pow n theorem fderiv_fun_pow (n : ℕ) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (fun x ↦ f x ^ n) x = (n • f x ^ (n - 1)) • fderiv 𝕜 f x := hf.hasFDerivAt.pow n |>.fderiv theorem fderiv_pow (n : ℕ) (hf : DifferentiableAt 𝕜 f x) : fderiv 𝕜 (fun x ↦ f x ^ n) x = (n • f x ^ (n - 1)) • fderiv 𝕜 f x := fderiv_fun_pow n hf theorem fderiv_pow_ring {x : 𝔸} (n : ℕ) : fderiv 𝕜 (fun x : 𝔸 ↦ x ^ n) x = (n • x ^ (n - 1)) • .id _ _ := by rw [fderiv_fun_pow n differentiableAt_fun_id, fderiv_id'] theorem fderivWithin_fun_pow (hxs : UniqueDiffWithinAt 𝕜 s x) (n : ℕ) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (fun x ↦ f x ^ n) s x = (n • f x ^ (n - 1)) • fderivWithin 𝕜 f s x := hf.hasFDerivWithinAt.pow n |>.fderivWithin hxs theorem fderivWithin_pow (hxs : UniqueDiffWithinAt 𝕜 s x) (n : ℕ) (hf : DifferentiableWithinAt 𝕜 f s x) : fderivWithin 𝕜 (f ^ n) s x = (n • f x ^ (n - 1)) • fderivWithin 𝕜 f s x := fderivWithin_fun_pow hxs n hf theorem fderivWithin_pow_ring {s : Set 𝔸} {x : 𝔸} (n : ℕ) (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun x : 𝔸 ↦ x ^ n) s x = (n • x ^ (n - 1)) • .id _ _ := by rw [fderivWithin_fun_pow hxs n differentiableAt_fun_id.differentiableWithinAt, fderivWithin_id' hxs] end NormedCommRing
Basic.lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro -/ import Mathlib.Data.Subtype import Mathlib.Order.Defs.LinearOrder import Mathlib.Order.Notation import Mathlib.Tactic.GCongr.Core import Mathlib.Tactic.Spread import Mathlib.Tactic.Convert import Mathlib.Tactic.Inhabit import Mathlib.Tactic.SimpRw /-! # Basic definitions about `≤` and `<` This file proves basic results about orders, provides extensive dot notation, defines useful order classes and allows to transfer order instances. ## Type synonyms * `OrderDual α` : A type synonym reversing the meaning of all inequalities, with notation `αᵒᵈ`. * `AsLinearOrder α`: A type synonym to promote `PartialOrder α` to `LinearOrder α` using `IsTotal α (≤)`. ### Transferring orders - `Order.Preimage`, `Preorder.lift`: Transfers a (pre)order on `β` to an order on `α` using a function `f : α → β`. - `PartialOrder.lift`, `LinearOrder.lift`: Transfers a partial (resp., linear) order on `β` to a partial (resp., linear) order on `α` using an injective function `f`. ### Extra class * `DenselyOrdered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such that `a < c < b`. ## Notes `≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos. Dot notation is particularly useful on `≤` (`LE.le`) and `<` (`LT.lt`). To that end, we provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with `LE.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`, `hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `LE.le.trans_lt` and can be used to construct `hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`. ## TODO - expand module docs - automatic construction of dual definitions / theorems ## Tags preorder, order, partial order, poset, linear order, chain -/ open Function variable {ι α β : Type*} {π : ι → Type*} /-! ### Bare relations -/ attribute [ext] LE section LE variable [LE α] {a b c : α} protected lemma LE.le.ge (h : a ≤ b) : b ≥ a := h protected lemma GE.ge.le (h : a ≥ b) : b ≤ a := h theorem le_of_le_of_eq' : b ≤ c → a = b → a ≤ c := flip le_of_eq_of_le theorem le_of_eq_of_le' : b = c → a ≤ b → a ≤ c := flip le_of_le_of_eq alias LE.le.trans_eq := le_of_le_of_eq alias LE.le.trans_eq' := le_of_le_of_eq' alias Eq.trans_le := le_of_eq_of_le alias Eq.trans_ge := le_of_eq_of_le' end LE section LT variable [LT α] {a b c : α} protected lemma LT.lt.gt (h : a < b) : b > a := h protected lemma GT.gt.lt (h : a > b) : b < a := h theorem lt_of_lt_of_eq' : b < c → a = b → a < c := flip lt_of_eq_of_lt theorem lt_of_eq_of_lt' : b = c → a < b → a < c := flip lt_of_lt_of_eq alias LT.lt.trans_eq := lt_of_lt_of_eq alias LT.lt.trans_eq' := lt_of_lt_of_eq' alias Eq.trans_lt := lt_of_eq_of_lt alias Eq.trans_gt := lt_of_eq_of_lt' end LT /-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `RelEmbedding` (assuming `f` is injective). -/ @[simp] def Order.Preimage (f : α → β) (s : β → β → Prop) (x y : α) : Prop := s (f x) (f y) @[inherit_doc] infixl:80 " ⁻¹'o " => Order.Preimage /-- The preimage of a decidable order is decidable. -/ instance Order.Preimage.decidable (f : α → β) (s : β → β → Prop) [H : DecidableRel s] : DecidableRel (f ⁻¹'o s) := fun _ _ ↦ H _ _ /-! ### Preorders -/ section Preorder variable [Preorder α] {a b c d : α} theorem not_lt_iff_not_le_or_ge : ¬a < b ↔ ¬a ≤ b ∨ b ≤ a := by rw [lt_iff_le_not_ge, Classical.not_and_iff_not_or_not, Classical.not_not] -- Unnecessary brackets are here for readability lemma not_lt_iff_le_imp_ge : ¬ a < b ↔ (a ≤ b → b ≤ a) := by simp [not_lt_iff_not_le_or_ge, or_iff_not_imp_left] @[deprecated (since := "2025-05-11")] alias not_lt_iff_le_imp_le := not_lt_iff_le_imp_ge lemma ge_of_eq (h : a = b) : b ≤ a := le_of_eq h.symm @[simp] lemma lt_self_iff_false (x : α) : x < x ↔ False := ⟨lt_irrefl x, False.elim⟩ alias le_trans' := ge_trans alias lt_trans' := gt_trans alias LE.le.trans := le_trans alias LE.le.trans' := le_trans' alias LT.lt.trans := lt_trans alias LT.lt.trans' := lt_trans' alias LE.le.trans_lt := lt_of_le_of_lt alias LE.le.trans_lt' := lt_of_le_of_lt' alias LT.lt.trans_le := lt_of_lt_of_le alias LT.lt.trans_le' := lt_of_lt_of_le' alias LE.le.lt_of_not_ge := lt_of_le_not_ge alias LT.lt.le := le_of_lt alias LT.lt.ne := ne_of_lt alias Eq.le := le_of_eq alias Eq.ge := ge_of_eq alias LT.lt.asymm := lt_asymm alias LT.lt.not_gt := lt_asymm @[deprecated (since := "2025-05-11")] alias LE.le.lt_of_not_le := LE.le.lt_of_not_ge @[deprecated (since := "2025-06-07")] alias LT.lt.not_lt := LT.lt.not_gt theorem ne_of_not_le (h : ¬a ≤ b) : a ≠ b := fun hab ↦ h (le_of_eq hab) protected lemma Eq.not_lt (hab : a = b) : ¬a < b := fun h' ↦ h'.ne hab protected lemma Eq.not_gt (hab : a = b) : ¬b < a := hab.symm.not_lt @[simp] lemma le_of_subsingleton [Subsingleton α] : a ≤ b := (Subsingleton.elim a b).le -- Making this a @[simp] lemma causes confluence problems downstream. @[nontriviality] lemma not_lt_of_subsingleton [Subsingleton α] : ¬a < b := (Subsingleton.elim a b).not_lt namespace LT.lt protected theorem false : a < a → False := lt_irrefl a theorem ne' (h : a < b) : b ≠ a := h.ne.symm end LT.lt theorem le_of_forall_le (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b := H _ le_rfl theorem le_of_forall_ge (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a := H _ le_rfl theorem forall_le_iff_le : (∀ ⦃c⦄, c ≤ a → c ≤ b) ↔ a ≤ b := ⟨le_of_forall_le, fun h _ hca ↦ le_trans hca h⟩ theorem forall_ge_iff_le : (∀ ⦃c⦄, a ≤ c → b ≤ c) ↔ b ≤ a := ⟨le_of_forall_ge, fun h _ hca ↦ le_trans h hca⟩ @[deprecated (since := "2025-07-27")] alias forall_le_iff_ge := forall_ge_iff_le /-- monotonicity of `≤` with respect to `→` -/ @[gcongr] theorem le_imp_le_of_le_of_le (h₁ : c ≤ a) (h₂ : b ≤ d) : a ≤ b → c ≤ d := fun hab ↦ (h₁.trans hab).trans h₂ @[deprecated (since := "2025-07-31")] alias le_implies_le_of_le_of_le := le_imp_le_of_le_of_le /-- monotonicity of `<` with respect to `→` -/ @[gcongr] theorem lt_imp_lt_of_le_of_le (h₁ : c ≤ a) (h₂ : b ≤ d) : a < b → c < d := fun hab ↦ (h₁.trans_lt hab).trans_le h₂ namespace Mathlib.Tactic.GCongr @[gcongr] theorem gt_imp_gt (h₁ : a ≤ c) (h₂ : d ≤ b) : a > b → c > d := lt_imp_lt_of_le_of_le h₂ h₁ /-- See if the term is `a < b` and the goal is `a ≤ b`. -/ @[gcongr_forward] def exactLeOfLt : ForwardExt where eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``le_of_lt #[h]) end Mathlib.Tactic.GCongr end Preorder /-! ### Partial order -/ section PartialOrder variable [PartialOrder α] {a b : α} theorem ge_antisymm : a ≤ b → b ≤ a → b = a := flip le_antisymm theorem lt_of_le_of_ne' : a ≤ b → b ≠ a → a < b := fun h₁ h₂ ↦ lt_of_le_of_ne h₁ h₂.symm theorem Ne.lt_of_le : a ≠ b → a ≤ b → a < b := flip lt_of_le_of_ne theorem Ne.lt_of_le' : b ≠ a → a ≤ b → a < b := flip lt_of_le_of_ne' alias LE.le.antisymm := le_antisymm alias LE.le.antisymm' := ge_antisymm alias LE.le.lt_of_ne := lt_of_le_of_ne alias LE.le.lt_of_ne' := lt_of_le_of_ne' -- Unnecessary brackets are here for readability lemma le_imp_eq_iff_le_imp_ge' : (a ≤ b → b = a) ↔ (a ≤ b → b ≤ a) where mp h hab := (h hab).le mpr h hab := (h hab).antisymm hab @[deprecated (since := "2025-05-11")] alias le_imp_eq_iff_le_imp_le := le_imp_eq_iff_le_imp_ge' -- Unnecessary brackets are here for readability lemma le_imp_eq_iff_le_imp_ge : (a ≤ b → a = b) ↔ (a ≤ b → b ≤ a) where mp h hab := (h hab).ge mpr h hab := hab.antisymm (h hab) @[deprecated (since := "2025-05-11")] alias ge_imp_eq_iff_le_imp_le := le_imp_eq_iff_le_imp_ge namespace LE.le theorem lt_iff_ne (h : a ≤ b) : a < b ↔ a ≠ b := ⟨fun h ↦ h.ne, h.lt_of_ne⟩ theorem lt_iff_ne' (h : a ≤ b) : a < b ↔ b ≠ a := ⟨fun h ↦ h.ne.symm, h.lt_of_ne'⟩ theorem not_lt_iff_eq (h : a ≤ b) : ¬a < b ↔ a = b := h.lt_iff_ne.not_left theorem not_lt_iff_eq' (h : a ≤ b) : ¬a < b ↔ b = a := h.lt_iff_ne'.not_left theorem ge_iff_eq (h : a ≤ b) : b ≤ a ↔ a = b := ⟨h.antisymm, Eq.ge⟩ theorem ge_iff_eq' (h : a ≤ b) : b ≤ a ↔ b = a := ⟨fun h' ↦ h'.antisymm h, Eq.le⟩ @[deprecated (since := "2025-06-08")] alias gt_iff_ne := lt_iff_ne' @[deprecated (since := "2025-06-08")] alias le_iff_eq := ge_iff_eq' @[deprecated (since := "2025-06-08")] alias not_gt_iff_eq := not_lt_iff_eq' end LE.le -- See Note [decidable namespace] protected theorem Decidable.le_iff_eq_or_lt [DecidableLE α] : a ≤ b ↔ a = b ∨ a < b := Decidable.le_iff_lt_or_eq.trans or_comm theorem le_iff_eq_or_lt : a ≤ b ↔ a = b ∨ a < b := le_iff_lt_or_eq.trans or_comm theorem lt_iff_le_and_ne : a < b ↔ a ≤ b ∧ a ≠ b := ⟨fun h ↦ ⟨le_of_lt h, ne_of_lt h⟩, fun ⟨h1, h2⟩ ↦ h1.lt_of_ne h2⟩ @[deprecated LE.le.not_lt_iff_eq (since := "2025-06-08")] lemma eq_iff_not_lt_of_le (hab : a ≤ b) : a = b ↔ ¬ a < b := hab.not_lt_iff_eq.symm @[deprecated (since := "2025-06-08")] alias LE.le.eq_iff_not_lt := eq_iff_not_lt_of_le -- See Note [decidable namespace] protected theorem Decidable.eq_iff_le_not_lt [DecidableLE α] : a = b ↔ a ≤ b ∧ ¬a < b := ⟨fun h ↦ ⟨h.le, h ▸ lt_irrefl _⟩, fun ⟨h₁, h₂⟩ ↦ h₁.antisymm <| Decidable.byContradiction fun h₃ ↦ h₂ (h₁.lt_of_not_ge h₃)⟩ theorem eq_iff_le_not_lt : a = b ↔ a ≤ b ∧ ¬a < b := open scoped Classical in Decidable.eq_iff_le_not_lt -- See Note [decidable namespace] protected theorem Decidable.eq_or_lt_of_le [DecidableLE α] (h : a ≤ b) : a = b ∨ a < b := (Decidable.lt_or_eq_of_le h).symm theorem eq_or_lt_of_le (h : a ≤ b) : a = b ∨ a < b := (lt_or_eq_of_le h).symm theorem eq_or_lt_of_le' (h : a ≤ b) : b = a ∨ a < b := (eq_or_lt_of_le h).imp Eq.symm id theorem lt_or_eq_of_le' (h : a ≤ b) : a < b ∨ b = a := (eq_or_lt_of_le' h).symm alias LE.le.lt_or_eq_dec := Decidable.lt_or_eq_of_le alias LE.le.eq_or_lt_dec := Decidable.eq_or_lt_of_le alias LE.le.lt_or_eq := lt_or_eq_of_le alias LE.le.eq_or_lt := eq_or_lt_of_le alias LE.le.eq_or_lt' := eq_or_lt_of_le' alias LE.le.lt_or_eq' := lt_or_eq_of_le' @[deprecated (since := "2025-06-08")] alias eq_or_gt_of_le := eq_or_lt_of_le' @[deprecated (since := "2025-06-08")] alias gt_or_eq_of_le := lt_or_eq_of_le' @[deprecated (since := "2025-06-08")] alias LE.le.eq_or_gt := LE.le.eq_or_lt' @[deprecated (since := "2025-06-08")] alias LE.le.gt_or_eq := LE.le.lt_or_eq' theorem eq_of_le_of_not_lt (h₁ : a ≤ b) (h₂ : ¬a < b) : a = b := h₁.eq_or_lt.resolve_right h₂ theorem eq_of_le_of_not_lt' (h₁ : a ≤ b) (h₂ : ¬a < b) : b = a := (eq_of_le_of_not_lt h₁ h₂).symm alias LE.le.eq_of_not_lt := eq_of_le_of_not_lt alias LE.le.eq_of_not_lt' := eq_of_le_of_not_lt' @[deprecated (since := "2025-06-08")] alias eq_of_ge_of_not_gt := eq_of_le_of_not_lt' @[deprecated (since := "2025-06-08")] alias LE.le.eq_of_not_gt := LE.le.eq_of_not_lt' theorem Ne.le_iff_lt (h : a ≠ b) : a ≤ b ↔ a < b := ⟨fun h' ↦ lt_of_le_of_ne h' h, fun h ↦ h.le⟩ theorem Ne.not_le_or_not_ge (h : a ≠ b) : ¬a ≤ b ∨ ¬b ≤ a := not_and_or.1 <| le_antisymm_iff.not.1 h @[deprecated (since := "2025-06-07")] alias Ne.not_le_or_not_le := Ne.not_le_or_not_ge -- See Note [decidable namespace] protected theorem Decidable.ne_iff_lt_iff_le [DecidableEq α] : (a ≠ b ↔ a < b) ↔ a ≤ b := ⟨fun h ↦ Decidable.byCases le_of_eq (le_of_lt ∘ h.mp), fun h ↦ ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩ @[simp] theorem ne_iff_lt_iff_le : (a ≠ b ↔ a < b) ↔ a ≤ b := haveI := Classical.dec Decidable.ne_iff_lt_iff_le lemma eq_of_forall_le_iff (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b := ((H _).1 le_rfl).antisymm ((H _).2 le_rfl) lemma eq_of_forall_ge_iff (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b := ((H _).2 le_rfl).antisymm ((H _).1 le_rfl) /-- To prove commutativity of a binary operation `○`, we only to check `a ○ b ≤ b ○ a` for all `a`, `b`. -/ lemma commutative_of_le {f : β → β → α} (comm : ∀ a b, f a b ≤ f b a) : ∀ a b, f a b = f b a := fun _ _ ↦ (comm _ _).antisymm <| comm _ _ /-- To prove associativity of a commutative binary operation `○`, we only to check `(a ○ b) ○ c ≤ a ○ (b ○ c)` for all `a`, `b`, `c`. -/ lemma associative_of_commutative_of_le {f : α → α → α} (comm : Std.Commutative f) (assoc : ∀ a b c, f (f a b) c ≤ f a (f b c)) : Std.Associative f where assoc a b c := le_antisymm (assoc _ _ _) <| by rw [comm.comm, comm.comm b, comm.comm _ c, comm.comm a] exact assoc .. end PartialOrder section LinearOrder variable [LinearOrder α] {a b : α} namespace LE.le lemma gt_or_le (h : a ≤ b) (c : α) : a < c ∨ c ≤ b := (lt_or_ge a c).imp id h.trans' lemma ge_or_lt (h : a ≤ b) (c : α) : a ≤ c ∨ c < b := (le_or_gt a c).imp id h.trans_lt' lemma ge_or_le (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b := (h.gt_or_le c).imp le_of_lt id @[deprecated (since := "2025-05-11")] alias lt_or_le := gt_or_le @[deprecated (since := "2025-05-11")] alias le_or_lt := ge_or_lt @[deprecated (since := "2025-05-11")] alias le_or_le := ge_or_le end LE.le namespace LT.lt lemma gt_or_lt (h : a < b) (c : α) : a < c ∨ c < b := (le_or_gt b c).imp h.trans_le id @[deprecated (since := "2025-06-07")] alias lt_or_lt := gt_or_lt end LT.lt -- Variant of `min_def` with the branches reversed. theorem min_def' (a b : α) : min a b = if b ≤ a then b else a := by rw [min_def] rcases lt_trichotomy a b with (lt | eq | gt) · rw [if_pos lt.le, if_neg (not_le.mpr lt)] · rw [if_pos eq.le, if_pos eq.ge, eq] · rw [if_neg (not_le.mpr gt.gt), if_pos gt.le] -- Variant of `min_def` with the branches reversed. -- This is sometimes useful as it used to be the default. theorem max_def' (a b : α) : max a b = if b ≤ a then a else b := by rw [max_def] rcases lt_trichotomy a b with (lt | eq | gt) · rw [if_pos lt.le, if_neg (not_le.mpr lt)] · rw [if_pos eq.le, if_pos eq.ge, eq] · rw [if_neg (not_le.mpr gt.gt), if_pos gt.le] @[deprecated (since := "2025-05-11")] alias lt_of_not_le := lt_of_not_ge @[deprecated (since := "2025-05-11")] alias lt_iff_not_le := lt_iff_not_ge theorem Ne.lt_or_gt (h : a ≠ b) : a < b ∨ b < a := lt_or_gt_of_ne h @[deprecated (since := "2025-06-07")] alias Ne.lt_or_lt := Ne.lt_or_gt /-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/ @[simp] theorem lt_or_lt_iff_ne : a < b ∨ b < a ↔ a ≠ b := ne_iff_lt_or_gt.symm theorem not_lt_iff_eq_or_lt : ¬a < b ↔ a = b ∨ b < a := not_lt.trans <| Decidable.le_iff_eq_or_lt.trans <| or_congr eq_comm Iff.rfl theorem exists_ge_of_linear (a b : α) : ∃ c, a ≤ c ∧ b ≤ c := match le_total a b with | Or.inl h => ⟨_, h, le_rfl⟩ | Or.inr h => ⟨_, le_rfl, h⟩ lemma exists_forall_ge_and {p q : α → Prop} : (∃ i, ∀ j ≥ i, p j) → (∃ i, ∀ j ≥ i, q j) → ∃ i, ∀ j ≥ i, p j ∧ q j | ⟨a, ha⟩, ⟨b, hb⟩ => let ⟨c, hac, hbc⟩ := exists_ge_of_linear a b ⟨c, fun _d hcd ↦ ⟨ha _ <| hac.trans hcd, hb _ <| hbc.trans hcd⟩⟩ theorem le_of_forall_lt (H : ∀ c, c < a → c < b) : a ≤ b := le_of_not_gt fun h ↦ lt_irrefl _ (H _ h) theorem forall_lt_iff_le : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b := ⟨le_of_forall_lt, fun h _ hca ↦ lt_of_lt_of_le hca h⟩ theorem le_of_forall_gt (H : ∀ c, a < c → b < c) : b ≤ a := le_of_not_gt fun h ↦ lt_irrefl _ (H _ h) theorem forall_gt_iff_le : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a := ⟨le_of_forall_gt, fun h _ hac ↦ lt_of_le_of_lt h hac⟩ @[deprecated (since := "2025-06-07")] alias le_of_forall_lt' := le_of_forall_gt @[deprecated (since := "2025-06-07")] alias forall_lt_iff_le' := forall_gt_iff_le theorem eq_of_forall_lt_iff (h : ∀ c, c < a ↔ c < b) : a = b := (le_of_forall_lt fun _ ↦ (h _).1).antisymm <| le_of_forall_lt fun _ ↦ (h _).2 theorem eq_of_forall_gt_iff (h : ∀ c, a < c ↔ b < c) : a = b := (le_of_forall_gt fun _ ↦ (h _).2).antisymm <| le_of_forall_gt fun _ ↦ (h _).1 section ltByCases variable {P : Sort*} {x y : α} set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_lt (h : x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} : ltByCases x y h₁ h₂ h₃ = h₁ h := dif_pos h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_gt (h : y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} : ltByCases x y h₁ h₂ h₃ = h₃ h := (dif_neg h.not_gt).trans (dif_pos h) set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_eq (h : x = y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} : ltByCases x y h₁ h₂ h₃ = h₂ h := (dif_neg h.not_lt).trans (dif_neg h.not_gt) set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_not_lt (h : ¬ x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : ¬ y < x → x = y := fun h' => (le_antisymm (le_of_not_gt h') (le_of_not_gt h))) : ltByCases x y h₁ h₂ h₃ = if h' : y < x then h₃ h' else h₂ (p h') := dif_neg h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_not_gt (h : ¬ y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : ¬ x < y → x = y := fun h' => (le_antisymm (le_of_not_gt h) (le_of_not_gt h'))) : ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₂ (p h') := dite_congr rfl (fun _ => rfl) (fun _ => dif_neg h) set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_ne (h : x ≠ y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : ¬ x < y → y < x := fun h' => h.lt_or_gt.resolve_left h') : ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₃ (p h') := dite_congr rfl (fun _ => rfl) (fun _ => dif_pos _) set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_comm {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : y = x → x = y := fun h' => h'.symm) : ltByCases x y h₁ h₂ h₃ = ltByCases y x h₃ (h₂ ∘ p) h₁ := by refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_) · rw [ltByCases_lt h, ltByCases_gt h] · rw [ltByCases_eq h, ltByCases_eq h.symm, comp_apply] · rw [ltByCases_lt h, ltByCases_gt h] lemma eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt {x' y' : α} (ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) : x = y ↔ x' = y' := by simp_rw [eq_iff_le_not_lt, ← not_lt, ltc, gtc] set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_rec {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : P) (hlt : (h : x < y) → h₁ h = p) (heq : (h : x = y) → h₂ h = p) (hgt : (h : y < x) → h₃ h = p) : ltByCases x y h₁ h₂ h₃ = p := ltByCases x y (fun h => ltByCases_lt h ▸ hlt h) (fun h => ltByCases_eq h ▸ heq h) (fun h => ltByCases_gt h ▸ hgt h) set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_eq_iff {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {p : P} : ltByCases x y h₁ h₂ h₃ = p ↔ (∃ h, h₁ h = p) ∨ (∃ h, h₂ h = p) ∨ (∃ h, h₃ h = p) := by refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_) · simp only [ltByCases_lt, exists_prop_of_true, h, h.not_gt, not_false_eq_true, exists_prop_of_false, or_false, h.ne] · simp only [h, lt_self_iff_false, ltByCases_eq, not_false_eq_true, exists_prop_of_false, exists_prop_of_true, or_false, false_or] · simp only [ltByCases_gt, exists_prop_of_true, h, h.not_gt, not_false_eq_true, exists_prop_of_false, false_or, h.ne'] set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltByCases_congr {x' y' : α} {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {h₁' : x' < y' → P} {h₂' : x' = y' → P} {h₃' : y' < x' → P} (ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) (hh'₁ : ∀ (h : x' < y'), h₁ (ltc.mpr h) = h₁' h) (hh'₂ : ∀ (h : x' = y'), h₂ ((eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc).mpr h) = h₂' h) (hh'₃ : ∀ (h : y' < x'), h₃ (gtc.mpr h) = h₃' h) : ltByCases x y h₁ h₂ h₃ = ltByCases x' y' h₁' h₂' h₃' := by refine ltByCases_rec _ (fun h => ?_) (fun h => ?_) (fun h => ?_) · rw [ltByCases_lt (ltc.mp h), hh'₁] · rw [eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc] at h rw [ltByCases_eq h, hh'₂] · rw [ltByCases_gt (gtc.mp h), hh'₃] set_option linter.deprecated false in /-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order, non-dependently. -/ @[deprecated lt_trichotomy (since := "2025-04-21")] abbrev ltTrichotomy (x y : α) (p q r : P) := ltByCases x y (fun _ => p) (fun _ => q) (fun _ => r) variable {p q r s : P} set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_lt (h : x < y) : ltTrichotomy x y p q r = p := ltByCases_lt h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_gt (h : y < x) : ltTrichotomy x y p q r = r := ltByCases_gt h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_eq (h : x = y) : ltTrichotomy x y p q r = q := ltByCases_eq h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_not_lt (h : ¬ x < y) : ltTrichotomy x y p q r = if y < x then r else q := ltByCases_not_lt h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_not_gt (h : ¬ y < x) : ltTrichotomy x y p q r = if x < y then p else q := ltByCases_not_gt h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_ne (h : x ≠ y) : ltTrichotomy x y p q r = if x < y then p else r := ltByCases_ne h set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_comm : ltTrichotomy x y p q r = ltTrichotomy y x r q p := ltByCases_comm set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_self {p : P} : ltTrichotomy x y p p p = p := ltByCases_rec p (fun _ => rfl) (fun _ => rfl) (fun _ => rfl) set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_eq_iff : ltTrichotomy x y p q r = s ↔ (x < y ∧ p = s) ∨ (x = y ∧ q = s) ∨ (y < x ∧ r = s) := by refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_) · simp only [ltTrichotomy_lt, false_and, true_and, or_false, h, h.not_gt, h.ne] · simp only [ltTrichotomy_eq, false_and, true_and, or_false, false_or, h, lt_irrefl] · simp only [ltTrichotomy_gt, false_and, true_and, false_or, h, h.not_gt, h.ne'] set_option linter.deprecated false in @[deprecated lt_trichotomy (since := "2025-04-21")] lemma ltTrichotomy_congr {x' y' : α} {p' q' r' : P} (ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) (hh'₁ : x' < y' → p = p') (hh'₂ : x' = y' → q = q') (hh'₃ : y' < x' → r = r') : ltTrichotomy x y p q r = ltTrichotomy x' y' p' q' r' := ltByCases_congr ltc gtc hh'₁ hh'₂ hh'₃ end ltByCases /-! #### `min`/`max` recursors -/ section MinMaxRec variable {p : α → Prop} lemma min_rec (ha : a ≤ b → p a) (hb : b ≤ a → p b) : p (min a b) := by obtain hab | hba := le_total a b <;> simp [min_eq_left, min_eq_right, *] lemma max_rec (ha : b ≤ a → p a) (hb : a ≤ b → p b) : p (max a b) := by obtain hab | hba := le_total a b <;> simp [max_eq_left, max_eq_right, *] lemma min_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (min a b) := min_rec (fun _ ↦ ha) fun _ ↦ hb lemma max_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (max a b) := max_rec (fun _ ↦ ha) fun _ ↦ hb lemma min_def_lt (a b : α) : min a b = if a < b then a else b := by rw [min_comm, min_def, ← ite_not]; simp only [not_le] lemma max_def_lt (a b : α) : max a b = if a < b then b else a := by rw [max_comm, max_def, ← ite_not]; simp only [not_le] end MinMaxRec end LinearOrder /-! ### Implications -/ lemma lt_imp_lt_of_le_imp_le {β} [LinearOrder α] [Preorder β] {a b : α} {c d : β} (H : a ≤ b → c ≤ d) (h : d < c) : b < a := lt_of_not_ge fun h' ↦ (H h').not_gt h lemma le_imp_le_iff_lt_imp_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} : a ≤ b → c ≤ d ↔ d < c → b < a := ⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩ lemma lt_iff_lt_of_le_iff_le' {β} [Preorder α] [Preorder β] {a b : α} {c d : β} (H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c := lt_iff_le_not_ge.trans <| (and_congr H' (not_congr H)).trans lt_iff_le_not_ge.symm lemma lt_iff_lt_of_le_iff_le {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} (H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c := not_le.symm.trans <| (not_congr H).trans <| not_le lemma le_iff_le_iff_lt_iff_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} : (a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) := ⟨lt_iff_lt_of_le_iff_le, fun H ↦ not_lt.symm.trans <| (not_congr H).trans <| not_lt⟩ /-- A symmetric relation implies two values are equal, when it implies they're less-equal. -/ lemma rel_imp_eq_of_rel_imp_le [PartialOrder β] (r : α → α → Prop) [IsSymm α r] {f : α → β} (h : ∀ a b, r a b → f a ≤ f b) {a b : α} : r a b → f a = f b := fun hab ↦ le_antisymm (h a b hab) (h b a <| symm hab) /-! ### Extensionality lemmas -/ @[ext] lemma Preorder.toLE_injective : Function.Injective (@Preorder.toLE α) := fun | { lt := A_lt, lt_iff_le_not_ge := A_iff, .. }, { lt := B_lt, lt_iff_le_not_ge := B_iff, .. } => by rintro ⟨⟩ have : A_lt = B_lt := by funext a b rw [A_iff, B_iff] cases this congr @[ext] lemma PartialOrder.toPreorder_injective : Function.Injective (@PartialOrder.toPreorder α) := by rintro ⟨⟩ ⟨⟩ ⟨⟩; congr @[ext] lemma LinearOrder.toPartialOrder_injective : Function.Injective (@LinearOrder.toPartialOrder α) := fun | { le := A_le, lt := A_lt, toDecidableLE := A_decidableLE, toDecidableEq := A_decidableEq, toDecidableLT := A_decidableLT min := A_min, max := A_max, min_def := A_min_def, max_def := A_max_def, compare := A_compare, compare_eq_compareOfLessAndEq := A_compare_canonical, .. }, { le := B_le, lt := B_lt, toDecidableLE := B_decidableLE, toDecidableEq := B_decidableEq, toDecidableLT := B_decidableLT min := B_min, max := B_max, min_def := B_min_def, max_def := B_max_def, compare := B_compare, compare_eq_compareOfLessAndEq := B_compare_canonical, .. } => by rintro ⟨⟩ obtain rfl : A_decidableLE = B_decidableLE := Subsingleton.elim _ _ obtain rfl : A_decidableEq = B_decidableEq := Subsingleton.elim _ _ obtain rfl : A_decidableLT = B_decidableLT := Subsingleton.elim _ _ have : A_min = B_min := by funext a b exact (A_min_def _ _).trans (B_min_def _ _).symm cases this have : A_max = B_max := by funext a b exact (A_max_def _ _).trans (B_max_def _ _).symm cases this have : A_compare = B_compare := by funext a b exact (A_compare_canonical _ _).trans (B_compare_canonical _ _).symm congr lemma Preorder.ext {A B : Preorder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by ext x y; exact H x y lemma PartialOrder.ext {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by ext x y; exact H x y lemma PartialOrder.ext_lt {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) : A = B := by ext x y; rw [le_iff_lt_or_eq, @le_iff_lt_or_eq _ A, H] lemma LinearOrder.ext {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by ext x y; exact H x y lemma LinearOrder.ext_lt {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) : A = B := LinearOrder.toPartialOrder_injective (PartialOrder.ext_lt H) /-! ### Order dual -/ /-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. `αᵒᵈ` is notation for `OrderDual α`. -/ def OrderDual (α : Type*) : Type _ := α @[inherit_doc] notation:max α "ᵒᵈ" => OrderDual α namespace OrderDual instance (α : Type*) [h : Nonempty α] : Nonempty αᵒᵈ := h instance (α : Type*) [h : Subsingleton α] : Subsingleton αᵒᵈ := h instance (α : Type*) [LE α] : LE αᵒᵈ := ⟨fun x y : α ↦ y ≤ x⟩ instance (α : Type*) [LT α] : LT αᵒᵈ := ⟨fun x y : α ↦ y < x⟩ instance instOrd (α : Type*) [Ord α] : Ord αᵒᵈ where compare := fun (a b : α) ↦ compare b a instance instSup (α : Type*) [Min α] : Max αᵒᵈ := ⟨((· ⊓ ·) : α → α → α)⟩ instance instInf (α : Type*) [Max α] : Min αᵒᵈ := ⟨((· ⊔ ·) : α → α → α)⟩ instance instPreorder (α : Type*) [Preorder α] : Preorder αᵒᵈ where le_refl := fun _ ↦ le_refl _ le_trans := fun _ _ _ hab hbc ↦ hbc.trans hab lt_iff_le_not_ge := fun _ _ ↦ lt_iff_le_not_ge instance instPartialOrder (α : Type*) [PartialOrder α] : PartialOrder αᵒᵈ where __ := inferInstanceAs (Preorder αᵒᵈ) le_antisymm := fun a b hab hba ↦ @le_antisymm α _ a b hba hab instance instLinearOrder (α : Type*) [LinearOrder α] : LinearOrder αᵒᵈ where __ := inferInstanceAs (PartialOrder αᵒᵈ) __ := inferInstanceAs (Ord αᵒᵈ) le_total := fun a b : α ↦ le_total b a max := fun a b ↦ (min a b : α) min := fun a b ↦ (max a b : α) min_def := fun a b ↦ show (max .. : α) = _ by rw [max_comm, max_def]; rfl max_def := fun a b ↦ show (min .. : α) = _ by rw [min_comm, min_def]; rfl toDecidableLE := (inferInstance : DecidableRel (fun a b : α ↦ b ≤ a)) toDecidableLT := (inferInstance : DecidableRel (fun a b : α ↦ b < a)) toDecidableEq := (inferInstance : DecidableEq α) compare_eq_compareOfLessAndEq a b := by simp only [compare, LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq, eq_comm] rfl /-- The opposite linear order to a given linear order -/ def _root_.LinearOrder.swap (α : Type*) (_ : LinearOrder α) : LinearOrder α := inferInstanceAs <| LinearOrder (OrderDual α) instance : ∀ [Inhabited α], Inhabited αᵒᵈ := fun [x : Inhabited α] => x theorem Ord.dual_dual (α : Type*) [H : Ord α] : OrderDual.instOrd αᵒᵈ = H := rfl theorem Preorder.dual_dual (α : Type*) [H : Preorder α] : OrderDual.instPreorder αᵒᵈ = H := rfl theorem instPartialOrder.dual_dual (α : Type*) [H : PartialOrder α] : OrderDual.instPartialOrder αᵒᵈ = H := rfl theorem instLinearOrder.dual_dual (α : Type*) [H : LinearOrder α] : OrderDual.instLinearOrder αᵒᵈ = H := rfl end OrderDual /-! ### `HasCompl` -/ instance Prop.hasCompl : HasCompl Prop := ⟨Not⟩ instance Pi.hasCompl [∀ i, HasCompl (π i)] : HasCompl (∀ i, π i) := ⟨fun x i ↦ (x i)ᶜ⟩ theorem Pi.compl_def [∀ i, HasCompl (π i)] (x : ∀ i, π i) : xᶜ = fun i ↦ (x i)ᶜ := rfl @[simp] theorem Pi.compl_apply [∀ i, HasCompl (π i)] (x : ∀ i, π i) (i : ι) : xᶜ i = (x i)ᶜ := rfl instance IsIrrefl.compl (r) [IsIrrefl α r] : IsRefl α rᶜ := ⟨@irrefl α r _⟩ instance IsRefl.compl (r) [IsRefl α r] : IsIrrefl α rᶜ := ⟨fun a ↦ not_not_intro (refl a)⟩ theorem compl_lt [LinearOrder α] : (· < · : α → α → _)ᶜ = (· ≥ ·) := by ext; simp [compl] theorem compl_le [LinearOrder α] : (· ≤ · : α → α → _)ᶜ = (· > ·) := by ext; simp [compl] theorem compl_gt [LinearOrder α] : (· > · : α → α → _)ᶜ = (· ≤ ·) := by ext; simp [compl] theorem compl_ge [LinearOrder α] : (· ≥ · : α → α → _)ᶜ = (· < ·) := by ext; simp [compl] instance Ne.instIsEquiv_compl : IsEquiv α (· ≠ ·)ᶜ := by convert eq_isEquiv α simp [compl] /-! ### Order instances on the function space -/ instance Pi.hasLe [∀ i, LE (π i)] : LE (∀ i, π i) where le x y := ∀ i, x i ≤ y i theorem Pi.le_def [∀ i, LE (π i)] {x y : ∀ i, π i} : x ≤ y ↔ ∀ i, x i ≤ y i := Iff.rfl instance Pi.preorder [∀ i, Preorder (π i)] : Preorder (∀ i, π i) where __ := inferInstanceAs (LE (∀ i, π i)) le_refl := fun a i ↦ le_refl (a i) le_trans := fun _ _ _ h₁ h₂ i ↦ le_trans (h₁ i) (h₂ i) theorem Pi.lt_def [∀ i, Preorder (π i)] {x y : ∀ i, π i} : x < y ↔ x ≤ y ∧ ∃ i, x i < y i := by simp +contextual [lt_iff_le_not_ge, Pi.le_def] instance Pi.partialOrder [∀ i, PartialOrder (π i)] : PartialOrder (∀ i, π i) where __ := Pi.preorder le_antisymm := fun _ _ h1 h2 ↦ funext fun b ↦ (h1 b).antisymm (h2 b) namespace Sum variable {α₁ α₂ : Type*} [LE β] @[simp] lemma elim_le_elim_iff {u₁ v₁ : α₁ → β} {u₂ v₂ : α₂ → β} : Sum.elim u₁ u₂ ≤ Sum.elim v₁ v₂ ↔ u₁ ≤ v₁ ∧ u₂ ≤ v₂ := Sum.forall lemma const_le_elim_iff {b : β} {v₁ : α₁ → β} {v₂ : α₂ → β} : Function.const _ b ≤ Sum.elim v₁ v₂ ↔ Function.const _ b ≤ v₁ ∧ Function.const _ b ≤ v₂ := elim_const_const b ▸ elim_le_elim_iff .. lemma elim_le_const_iff {b : β} {u₁ : α₁ → β} {u₂ : α₂ → β} : Sum.elim u₁ u₂ ≤ Function.const _ b ↔ u₁ ≤ Function.const _ b ∧ u₂ ≤ Function.const _ b := elim_const_const b ▸ elim_le_elim_iff .. end Sum section Pi /-- A function `a` is strongly less than a function `b` if `a i < b i` for all `i`. -/ def StrongLT [∀ i, LT (π i)] (a b : ∀ i, π i) : Prop := ∀ i, a i < b i @[inherit_doc] local infixl:50 " ≺ " => StrongLT variable [∀ i, Preorder (π i)] {a b c : ∀ i, π i} theorem le_of_strongLT (h : a ≺ b) : a ≤ b := fun _ ↦ (h _).le theorem lt_of_strongLT [Nonempty ι] (h : a ≺ b) : a < b := by inhabit ι exact Pi.lt_def.2 ⟨le_of_strongLT h, default, h _⟩ theorem strongLT_of_strongLT_of_le (hab : a ≺ b) (hbc : b ≤ c) : a ≺ c := fun _ ↦ (hab _).trans_le <| hbc _ theorem strongLT_of_le_of_strongLT (hab : a ≤ b) (hbc : b ≺ c) : a ≺ c := fun _ ↦ (hab _).trans_lt <| hbc _ alias StrongLT.le := le_of_strongLT alias StrongLT.lt := lt_of_strongLT alias StrongLT.trans_le := strongLT_of_strongLT_of_le alias LE.le.trans_strongLT := strongLT_of_le_of_strongLT end Pi section Function variable [DecidableEq ι] [∀ i, Preorder (π i)] {x y : ∀ i, π i} {i : ι} {a b : π i} theorem le_update_iff : x ≤ Function.update y i a ↔ x i ≤ a ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := Function.forall_update_iff _ fun j z ↦ x j ≤ z theorem update_le_iff : Function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := Function.forall_update_iff _ fun j z ↦ z ≤ y j theorem update_le_update_iff : Function.update x i a ≤ Function.update y i b ↔ a ≤ b ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := by simp +contextual [update_le_iff] @[simp] theorem update_le_update_iff' : update x i a ≤ update x i b ↔ a ≤ b := by simp [update_le_update_iff] @[simp] theorem update_lt_update_iff : update x i a < update x i b ↔ a < b := lt_iff_lt_of_le_iff_le' update_le_update_iff' update_le_update_iff' @[simp] theorem le_update_self_iff : x ≤ update x i a ↔ x i ≤ a := by simp [le_update_iff] @[simp] theorem update_le_self_iff : update x i a ≤ x ↔ a ≤ x i := by simp [update_le_iff] @[simp] theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_not_ge] @[simp] theorem update_lt_self_iff : update x i a < x ↔ a < x i := by simp [lt_iff_le_not_ge] end Function instance Pi.sdiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) := ⟨fun x y i ↦ x i \ y i⟩ theorem Pi.sdiff_def [∀ i, SDiff (π i)] (x y : ∀ i, π i) : x \ y = fun i ↦ x i \ y i := rfl @[simp] theorem Pi.sdiff_apply [∀ i, SDiff (π i)] (x y : ∀ i, π i) (i : ι) : (x \ y) i = x i \ y i := rfl namespace Function variable [Preorder α] [Nonempty β] {a b : α} @[simp] theorem const_le_const : const β a ≤ const β b ↔ a ≤ b := by simp [Pi.le_def] @[simp] theorem const_lt_const : const β a < const β b ↔ a < b := by simpa [Pi.lt_def] using le_of_lt end Function /-! ### Lifts of order instances -/ /-- Transfer a `Preorder` on `β` to a `Preorder` on `α` using a function `f : α → β`. See note [reducible non-instances]. -/ abbrev Preorder.lift [Preorder β] (f : α → β) : Preorder α where le x y := f x ≤ f y le_refl _ := le_rfl le_trans _ _ _ := _root_.le_trans lt x y := f x < f y lt_iff_le_not_ge _ _ := _root_.lt_iff_le_not_ge /-- Transfer a `PartialOrder` on `β` to a `PartialOrder` on `α` using an injective function `f : α → β`. See note [reducible non-instances]. -/ abbrev PartialOrder.lift [PartialOrder β] (f : α → β) (inj : Injective f) : PartialOrder α := { Preorder.lift f with le_antisymm := fun _ _ h₁ h₂ ↦ inj (h₁.antisymm h₂) } theorem compare_of_injective_eq_compareOfLessAndEq (a b : α) [LinearOrder β] [DecidableEq α] (f : α → β) (inj : Injective f) [Decidable (LT.lt (self := PartialOrder.lift f inj |>.toLT) a b)] : compare (f a) (f b) = @compareOfLessAndEq _ a b (PartialOrder.lift f inj |>.toLT) _ _ := by have h := LinearOrder.compare_eq_compareOfLessAndEq (f a) (f b) simp only [h, compareOfLessAndEq] split_ifs <;> try (first | rfl | contradiction) · have : ¬ f a = f b := by rename_i h; exact inj.ne h contradiction · grind /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses them for `max` and `min` fields. See `LinearOrder.lift'` for a version that autogenerates `min` and `max` fields, and `LinearOrder.liftWithOrd` for one that does not auto-generate `compare` fields. See note [reducible non-instances]. -/ abbrev LinearOrder.lift [LinearOrder β] [Max α] [Min α] (f : α → β) (inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) : LinearOrder α := letI instOrdα : Ord α := ⟨fun a b ↦ compare (f a) (f b)⟩ letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y)) letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y)) letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff { PartialOrder.lift f inj, instOrdα with le_total := fun x y ↦ le_total (f x) (f y) toDecidableLE := decidableLE toDecidableLT := decidableLT toDecidableEq := decidableEq min := (· ⊓ ·) max := (· ⊔ ·) min_def := by intros x y apply inj rw [apply_ite f] exact (hinf _ _).trans (min_def _ _) max_def := by intros x y apply inj rw [apply_ite f] exact (hsup _ _).trans (max_def _ _) compare_eq_compareOfLessAndEq := fun a b ↦ compare_of_injective_eq_compareOfLessAndEq a b f inj } /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version autogenerates `min` and `max` fields. See `LinearOrder.lift` for a version that takes `[Max α]` and `[Min α]`, then uses them as `max` and `min`. See `LinearOrder.liftWithOrd'` for a version which does not auto-generate `compare` fields. See note [reducible non-instances]. -/ abbrev LinearOrder.lift' [LinearOrder β] (f : α → β) (inj : Injective f) : LinearOrder α := @LinearOrder.lift α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩ ⟨fun x y ↦ if f x ≤ f y then x else y⟩ f inj (fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm) fun _ _ ↦ (apply_ite f _ _ _).trans (min_def _ _).symm /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses them for `max` and `min` fields. It also takes `[Ord α]` as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and `LinearOrder.liftWithOrd'` for one that auto-generates `min` and `max` fields. fields. See note [reducible non-instances]. -/ abbrev LinearOrder.liftWithOrd [LinearOrder β] [Max α] [Min α] [Ord α] (f : α → β) (inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) (compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α := letI decidableLE := fun x y ↦ (inferInstance : Decidable (f x ≤ f y)) letI decidableLT := fun x y ↦ (inferInstance : Decidable (f x < f y)) letI decidableEq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff { PartialOrder.lift f inj with le_total := fun x y ↦ le_total (f x) (f y) toDecidableLE := decidableLE toDecidableLT := decidableLT toDecidableEq := decidableEq min := (· ⊓ ·) max := (· ⊔ ·) min_def := by intros x y apply inj rw [apply_ite f] exact (hinf _ _).trans (min_def _ _) max_def := by intros x y apply inj rw [apply_ite f] exact (hsup _ _).trans (max_def _ _) compare_eq_compareOfLessAndEq := fun a b ↦ (compare_f a b).trans <| compare_of_injective_eq_compareOfLessAndEq a b f inj } /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version auto-generates `min` and `max` fields. It also takes `[Ord α]` as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and `LinearOrder.liftWithOrd` for one that doesn't auto-generate `min` and `max` fields. fields. See note [reducible non-instances]. -/ abbrev LinearOrder.liftWithOrd' [LinearOrder β] [Ord α] (f : α → β) (inj : Injective f) (compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α := @LinearOrder.liftWithOrd α β _ ⟨fun x y ↦ if f x ≤ f y then y else x⟩ ⟨fun x y ↦ if f x ≤ f y then x else y⟩ _ f inj (fun _ _ ↦ (apply_ite f _ _ _).trans (max_def _ _).symm) (fun _ _ ↦ (apply_ite f _ _ _).trans (min_def _ _).symm) compare_f /-! ### Subtype of an order -/ namespace Subtype @[simp] theorem mk_le_mk [LE α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} : (⟨x, hx⟩ : Subtype p) ≤ ⟨y, hy⟩ ↔ x ≤ y := Iff.rfl @[gcongr] alias ⟨_, GCongr.mk_le_mk⟩ := mk_le_mk @[simp] theorem mk_lt_mk [LT α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} : (⟨x, hx⟩ : Subtype p) < ⟨y, hy⟩ ↔ x < y := Iff.rfl @[gcongr] alias ⟨_, GCongr.mk_lt_mk⟩ := mk_lt_mk @[simp, norm_cast] theorem coe_le_coe [LE α] {p : α → Prop} {x y : Subtype p} : (x : α) ≤ y ↔ x ≤ y := Iff.rfl @[gcongr] alias ⟨_, GCongr.coe_le_coe⟩ := coe_le_coe @[simp, norm_cast] theorem coe_lt_coe [LT α] {p : α → Prop} {x y : Subtype p} : (x : α) < y ↔ x < y := Iff.rfl @[gcongr] alias ⟨_, GCongr.coe_lt_coe⟩ := coe_lt_coe instance preorder [Preorder α] (p : α → Prop) : Preorder (Subtype p) := Preorder.lift (fun (a : Subtype p) ↦ (a : α)) instance partialOrder [PartialOrder α] (p : α → Prop) : PartialOrder (Subtype p) := PartialOrder.lift (fun (a : Subtype p) ↦ (a : α)) Subtype.coe_injective instance decidableLE [Preorder α] [h : DecidableLE α] {p : α → Prop} : DecidableLE (Subtype p) := fun a b ↦ h a b instance decidableLT [Preorder α] [h : DecidableLT α] {p : α → Prop} : DecidableLT (Subtype p) := fun a b ↦ h a b /-- A subtype of a linear order is a linear order. We explicitly give the proofs of decidable equality and decidable order in order to ensure the decidability instances are all definitionally equal. -/ instance instLinearOrder [LinearOrder α] (p : α → Prop) : LinearOrder (Subtype p) := @LinearOrder.lift (Subtype p) _ _ ⟨fun x y ↦ ⟨max x y, max_rec' _ x.2 y.2⟩⟩ ⟨fun x y ↦ ⟨min x y, min_rec' _ x.2 y.2⟩⟩ (fun (a : Subtype p) ↦ (a : α)) Subtype.coe_injective (fun _ _ ↦ rfl) fun _ _ ↦ rfl end Subtype /-! ### Pointwise order on `α × β` The lexicographic order is defined in `Data.Prod.Lex`, and the instances are available via the type synonym `α ×ₗ β = α × β`. -/ namespace Prod section LE variable [LE α] [LE β] {x y : α × β} {a a₁ a₂ : α} {b b₁ b₂ : β} instance : LE (α × β) where le p q := p.1 ≤ q.1 ∧ p.2 ≤ q.2 instance instDecidableLE [Decidable (x.1 ≤ y.1)] [Decidable (x.2 ≤ y.2)] : Decidable (x ≤ y) := inferInstanceAs (Decidable (x.1 ≤ y.1 ∧ x.2 ≤ y.2)) lemma le_def : x ≤ y ↔ x.1 ≤ y.1 ∧ x.2 ≤ y.2 := .rfl @[simp] lemma mk_le_mk : (a₁, b₁) ≤ (a₂, b₂) ↔ a₁ ≤ a₂ ∧ b₁ ≤ b₂ := .rfl @[gcongr] lemma GCongr.mk_le_mk (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) : (a₁, b₁) ≤ (a₂, b₂) := ⟨ha, hb⟩ @[simp] lemma swap_le_swap : x.swap ≤ y.swap ↔ x ≤ y := and_comm @[simp] lemma swap_le_mk : x.swap ≤ (b, a) ↔ x ≤ (a, b) := and_comm @[simp] lemma mk_le_swap : (b, a) ≤ x.swap ↔ (a, b) ≤ x := and_comm end LE section Preorder variable [Preorder α] [Preorder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β} instance : Preorder (α × β) where __ := inferInstanceAs (LE (α × β)) le_refl := fun ⟨a, b⟩ ↦ ⟨le_refl a, le_refl b⟩ le_trans := fun ⟨_, _⟩ ⟨_, _⟩ ⟨_, _⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩ ↦ ⟨le_trans hac hce, le_trans hbd hdf⟩ @[simp] theorem swap_lt_swap : x.swap < y.swap ↔ x < y := and_congr swap_le_swap (not_congr swap_le_swap) @[simp] lemma swap_lt_mk : x.swap < (b, a) ↔ x < (a, b) := by rw [← swap_lt_swap]; simp @[simp] lemma mk_lt_swap : (b, a) < x.swap ↔ (a, b) < x := by rw [← swap_lt_swap]; simp theorem mk_le_mk_iff_left : (a₁, b) ≤ (a₂, b) ↔ a₁ ≤ a₂ := and_iff_left le_rfl theorem mk_le_mk_iff_right : (a, b₁) ≤ (a, b₂) ↔ b₁ ≤ b₂ := and_iff_right le_rfl @[gcongr] alias ⟨_, GCongr.mk_le_mk_left⟩ := mk_le_mk_iff_left @[gcongr] alias ⟨_, GCongr.mk_le_mk_right⟩ := mk_le_mk_iff_right theorem mk_lt_mk_iff_left : (a₁, b) < (a₂, b) ↔ a₁ < a₂ := lt_iff_lt_of_le_iff_le' mk_le_mk_iff_left mk_le_mk_iff_left theorem mk_lt_mk_iff_right : (a, b₁) < (a, b₂) ↔ b₁ < b₂ := lt_iff_lt_of_le_iff_le' mk_le_mk_iff_right mk_le_mk_iff_right theorem lt_iff : x < y ↔ x.1 < y.1 ∧ x.2 ≤ y.2 ∨ x.1 ≤ y.1 ∧ x.2 < y.2 := by refine ⟨fun h ↦ ?_, ?_⟩ · by_cases h₁ : y.1 ≤ x.1 · exact Or.inr ⟨h.1.1, LE.le.lt_of_not_ge h.1.2 fun h₂ ↦ h.2 ⟨h₁, h₂⟩⟩ · exact Or.inl ⟨LE.le.lt_of_not_ge h.1.1 h₁, h.1.2⟩ · rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩) · exact ⟨⟨h₁.le, h₂⟩, fun h ↦ h₁.not_ge h.1⟩ · exact ⟨⟨h₁, h₂.le⟩, fun h ↦ h₂.not_ge h.2⟩ @[simp] theorem mk_lt_mk : (a₁, b₁) < (a₂, b₂) ↔ a₁ < a₂ ∧ b₁ ≤ b₂ ∨ a₁ ≤ a₂ ∧ b₁ < b₂ := lt_iff protected lemma lt_of_lt_of_le (h₁ : x.1 < y.1) (h₂ : x.2 ≤ y.2) : x < y := by simp [lt_iff, *] protected lemma lt_of_le_of_lt (h₁ : x.1 ≤ y.1) (h₂ : x.2 < y.2) : x < y := by simp [lt_iff, *] lemma mk_lt_mk_of_lt_of_le (h₁ : a₁ < a₂) (h₂ : b₁ ≤ b₂) : (a₁, b₁) < (a₂, b₂) := by simp [lt_iff, *] lemma mk_lt_mk_of_le_of_lt (h₁ : a₁ ≤ a₂) (h₂ : b₁ < b₂) : (a₁, b₁) < (a₂, b₂) := by simp [lt_iff, *] end Preorder /-- The pointwise partial order on a product. (The lexicographic ordering is defined in `Order.Lexicographic`, and the instances are available via the type synonym `α ×ₗ β = α × β`.) -/ instance instPartialOrder (α β : Type*) [PartialOrder α] [PartialOrder β] : PartialOrder (α × β) where __ := inferInstanceAs (Preorder (α × β)) le_antisymm := fun _ _ ⟨hac, hbd⟩ ⟨hca, hdb⟩ ↦ Prod.ext (hac.antisymm hca) (hbd.antisymm hdb) end Prod /-! ### Additional order classes -/ /-- An order is dense if there is an element between any pair of distinct comparable elements. -/ class DenselyOrdered (α : Type*) [LT α] : Prop where /-- An order is dense if there is an element between any pair of distinct elements. -/ dense : ∀ a₁ a₂ : α, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ theorem exists_between [LT α] [DenselyOrdered α] : ∀ {a₁ a₂ : α}, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ := DenselyOrdered.dense _ _ instance OrderDual.denselyOrdered (α : Type*) [LT α] [h : DenselyOrdered α] : DenselyOrdered αᵒᵈ := ⟨fun _ _ ha ↦ (@exists_between α _ h _ _ ha).imp fun _ ↦ And.symm⟩ @[simp] theorem denselyOrdered_orderDual [LT α] : DenselyOrdered αᵒᵈ ↔ DenselyOrdered α := ⟨by convert @OrderDual.denselyOrdered αᵒᵈ _, @OrderDual.denselyOrdered α _⟩ /-- Any ordered subsingleton is densely ordered. Not an instance to avoid a heavy subsingleton typeclass search. -/ lemma Subsingleton.instDenselyOrdered {X : Type*} [Subsingleton X] [LT X] : DenselyOrdered X := ⟨fun _ _ h ↦ ⟨_, h.trans_eq (Subsingleton.elim _ _), h⟩⟩ instance [Preorder α] [Preorder β] [DenselyOrdered α] [DenselyOrdered β] : DenselyOrdered (α × β) := ⟨fun a b ↦ by simp_rw [Prod.lt_iff] rintro (⟨h₁, h₂⟩ | ⟨h₁, h₂⟩) · obtain ⟨c, ha, hb⟩ := exists_between h₁ exact ⟨(c, _), Or.inl ⟨ha, h₂⟩, Or.inl ⟨hb, le_rfl⟩⟩ · obtain ⟨c, ha, hb⟩ := exists_between h₂ exact ⟨(_, c), Or.inr ⟨h₁, ha⟩, Or.inr ⟨le_rfl, hb⟩⟩⟩ instance [∀ i, Preorder (π i)] [∀ i, DenselyOrdered (π i)] : DenselyOrdered (∀ i, π i) := ⟨fun a b ↦ by classical simp_rw [Pi.lt_def] rintro ⟨hab, i, hi⟩ obtain ⟨c, ha, hb⟩ := exists_between hi exact ⟨Function.update a i c, ⟨le_update_iff.2 ⟨ha.le, fun _ _ ↦ le_rfl⟩, i, by rwa [update_self]⟩, update_le_iff.2 ⟨hb.le, fun _ _ ↦ hab _⟩, i, by rwa [update_self]⟩⟩ section LinearOrder variable [LinearOrder α] [DenselyOrdered α] {a₁ a₂ : α} theorem le_of_forall_gt_imp_ge_of_dense (h : ∀ a, a₂ < a → a₁ ≤ a) : a₁ ≤ a₂ := le_of_not_gt fun ha ↦ let ⟨a, ha₁, ha₂⟩ := exists_between ha lt_irrefl a <| lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›) lemma forall_gt_imp_ge_iff_le_of_dense : (∀ a, a₂ < a → a₁ ≤ a) ↔ a₁ ≤ a₂ := ⟨le_of_forall_gt_imp_ge_of_dense, fun ha _a ha₂ ↦ ha.trans ha₂.le⟩ lemma eq_of_le_of_forall_lt_imp_le_of_dense (h₁ : a₂ ≤ a₁) (h₂ : ∀ a, a₂ < a → a₁ ≤ a) : a₁ = a₂ := le_antisymm (le_of_forall_gt_imp_ge_of_dense h₂) h₁ theorem le_of_forall_lt_imp_le_of_dense (h : ∀ a < a₁, a ≤ a₂) : a₁ ≤ a₂ := le_of_not_gt fun ha ↦ let ⟨a, ha₁, ha₂⟩ := exists_between ha lt_irrefl a <| lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a› lemma forall_lt_imp_le_iff_le_of_dense : (∀ a < a₁, a ≤ a₂) ↔ a₁ ≤ a₂ := ⟨le_of_forall_lt_imp_le_of_dense, fun ha _a ha₁ ↦ ha₁.le.trans ha⟩ theorem eq_of_le_of_forall_gt_imp_ge_of_dense (h₁ : a₂ ≤ a₁) (h₂ : ∀ a < a₁, a ≤ a₂) : a₁ = a₂ := (le_of_forall_lt_imp_le_of_dense h₂).antisymm h₁ end LinearOrder theorem dense_or_discrete [LinearOrder α] (a₁ a₂ : α) : (∃ a, a₁ < a ∧ a < a₂) ∨ (∀ a, a₁ < a → a₂ ≤ a) ∧ ∀ a < a₂, a ≤ a₁ := or_iff_not_imp_left.2 fun h ↦ ⟨fun a ha₁ ↦ le_of_not_gt fun ha₂ ↦ h ⟨a, ha₁, ha₂⟩, fun a ha₂ ↦ le_of_not_gt fun ha₁ ↦ h ⟨a, ha₁, ha₂⟩⟩ /-- If a linear order has no elements `x < y < z`, then it has at most two elements. -/ lemma eq_or_eq_or_eq_of_forall_not_lt_lt [LinearOrder α] (h : ∀ ⦃x y z : α⦄, x < y → y < z → False) (x y z : α) : x = y ∨ y = z ∨ x = z := by by_contra hne simp only [not_or, ← Ne.eq_def] at hne rcases hne.1.lt_or_gt with h₁ | h₁ <;> rcases hne.2.1.lt_or_gt with h₂ | h₂ <;> rcases hne.2.2.lt_or_gt with h₃ | h₃ exacts [h h₁ h₂, h h₂ h₃, h h₃ h₂, h h₃ h₁, h h₁ h₃, h h₂ h₃, h h₁ h₃, h h₂ h₁] namespace PUnit variable (a b : PUnit) instance instLinearOrder : LinearOrder PUnit where le := fun _ _ ↦ True lt := fun _ _ ↦ False max := fun _ _ ↦ unit min := fun _ _ ↦ unit toDecidableEq := inferInstance toDecidableLE := fun _ _ ↦ Decidable.isTrue trivial toDecidableLT := fun _ _ ↦ Decidable.isFalse id le_refl := by intros; trivial le_trans := by intros; trivial le_total := by intros; exact Or.inl trivial le_antisymm := by intros; rfl lt_iff_le_not_ge := by simp only [not_true, and_false, forall_const] theorem max_eq : max a b = unit := rfl theorem min_eq : min a b = unit := rfl protected theorem le : a ≤ b := trivial theorem not_lt : ¬a < b := not_false instance : DenselyOrdered PUnit := ⟨fun _ _ ↦ False.elim⟩ end PUnit section «Prop» /-- Propositions form a complete boolean algebra, where the `≤` relation is given by implication. -/ instance Prop.le : LE Prop := ⟨(· → ·)⟩ @[simp] theorem le_Prop_eq : ((· ≤ ·) : Prop → Prop → Prop) = (· → ·) := rfl theorem subrelation_iff_le {r s : α → α → Prop} : Subrelation r s ↔ r ≤ s := Iff.rfl instance Prop.partialOrder : PartialOrder Prop where __ := Prop.le le_refl _ := id le_trans _ _ _ f g := g ∘ f le_antisymm _ _ Hab Hba := propext ⟨Hab, Hba⟩ end «Prop» /-! ### Linear order from a total partial order -/ /-- Type synonym to create an instance of `LinearOrder` from a `PartialOrder` and `IsTotal α (≤)` -/ def AsLinearOrder (α : Type*) := α instance [Inhabited α] : Inhabited (AsLinearOrder α) := ⟨(default : α)⟩ noncomputable instance AsLinearOrder.linearOrder [PartialOrder α] [IsTotal α (· ≤ ·)] : LinearOrder (AsLinearOrder α) where __ := inferInstanceAs (PartialOrder α) le_total := @total_of α (· ≤ ·) _ toDecidableLE := Classical.decRel _
Path.lean
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Connectivity.Connected import Mathlib.Combinatorics.SimpleGraph.Paths deprecated_module (since := "2025-06-13")
falgebra.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path. From mathcomp Require Import choice fintype div tuple finfun bigop ssralg. From mathcomp Require Import finalg zmodp matrix vector poly. (******************************************************************************) (* Finite dimensional free algebras, usually known as F-algebras *) (* *) (* falgType K == the interface type for F-algebras over K; it simply *) (* joins the unitAlgType K and vectType K interfaces *) (* The HB class is called Falgebra. *) (* Any aT with an falgType structure inherits all the Vector, NzRing and *) (* Algebra operations, and supports the following additional operations: *) (* \dim_A M == (\dim M %/ dim A)%N -- free module dimension *) (* amull u == the linear function v |-> u * v, for u, v : aT *) (* amulr u == the linear function v |-> v * u, for u, v : aT *) (* 1, f * g, f ^+ n == the identity function, the composite g \o f, the nth *) (* iterate of f, for 1, f, g in 'End(aT) *) (* This is just the usual F-algebra structure on *) (* 'End(aT). It is NOT canonical by default, but can be *) (* activated by the line Import FalgLfun. Beware also *) (* that (f^-1)%VF is the linear function inverse, not *) (* the ring inverse of f (though they do coincide when *) (* f is injective). *) (* 1%VS == the line generated by 1 : aT *) (* (U * V)%VS == the smallest subspace of aT that contains all *) (* products u * v for u in U, v in V *) (* (U ^+ n)%VS == (U * U * ... * U), n-times. U ^+ 0 = 1%VS *) (* 'C[u]%VS == the centraliser subspace of the vector u *) (* 'C_U[v]%VS := (U :&: 'C[v])%VS *) (* 'C(V)%VS == the centraliser subspace of the subspace V *) (* 'C_U(V)%VS := (U :&: 'C(V))%VS *) (* 'Z(V)%VS == the center subspace of the subspace V *) (* agenv U == the smallest subalgebra containing U ^+ n for all n *) (* <<U; v>>%VS == agenv (U + <[v]>) (adjoin v to U) *) (* <<U & vs>>%VS == agenv (U + <<vs>>) (adjoin vs to U) *) (* {aspace aT} == a subType of {vspace aT} consisting of sub-algebras *) (* of aT (see below); for A : {aspace aT}, subvs_of A *) (* has a canonical falgType K structure *) (* is_aspace U <=> the characteristic predicate of {aspace aT} stating *) (* that U is closed under product and contains an *) (* identity element, := has_algid U && (U * U <= U)%VS *) (* algid A == the identity element of A : {aspace aT}, which need *) (* not be equal to 1 (indeed, in a Wedderburn *) (* decomposition it is not even a unit in aT) *) (* is_algid U e <-> e : aT is an identity element for the subspace U: *) (* e in U, e != 0 & e * u = u * e = u for all u in U *) (* has_algid U <=> there is an e such that is_algid U e *) (* [aspace of U] == a clone of an existing {aspace aT} structure on *) (* U : {vspace aT} (more instances of {aspace aT} will *) (* be defined in extFieldType) *) (* [aspace of U for A] == a clone of A : {aspace aT} for U : {vspace aT} *) (* 1%AS == the canonical sub-algebra 1%VS *) (* {:aT}%AS == the canonical full algebra *) (* <<U>>%AS == the canonical algebra for agenv U; note that this is *) (* unrelated to <<vs>>%VS, the subspace spanned by vs *) (* <<U; v>>%AS == the canonical algebra for <<U; v>>%VS *) (* <<U & vs>>%AS == the canonical algebra for <<U & vs>>%VS *) (* ahom_in U f <=> f : 'Hom(aT, rT) is a multiplicative homomorphism *) (* inside U, and in addition f 1 = 1 (even if U doesn't *) (* contain 1) *) (* Note that f @: U need not be a subalgebra when U is, *) (* as f could annilate U. *) (* 'AHom(aT, rT) == the type of algebra homomorphisms from aT to rT, *) (* where aT and rT ARE falgType structures. Elements of *) (* 'AHom(aT, rT) coerce to 'End(aT, rT) and aT -> rT *) (* 'AEnd(aT) == algebra endomorphisms of aT (:= 'AHom(aT, aT)) *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope aspace_scope. Declare Scope lrfun_scope. Local Open Scope ring_scope. Reserved Notation "{ 'aspace' T }" (format "{ 'aspace' T }"). Reserved Notation "<< U & vs >>" (format "<< U & vs >>"). Reserved Notation "<< U ; x >>" (format "<< U ; x >>"). Reserved Notation "''AHom' ( T , rT )" (format "''AHom' ( T , rT )"). Reserved Notation "''AEnd' ( T )" (format "''AEnd' ( T )"). Notation "\dim_ E V" := (divn (\dim V) (\dim E)) (at level 10, E at level 2, V at level 8, format "\dim_ E V") : nat_scope. Import GRing.Theory. (* Finite dimensional algebra *) #[short(type="falgType")] HB.structure Definition Falgebra (R : nzRingType) := { A of Vector R A & GRing.UnitAlgebra R A }. #[deprecated(since="mathcomp 2.0.0", note="Use falgType instead.")] Notation FalgType := falgType. (* Supply a default unitRing mixin for the default unitAlgType base type. *) HB.factory Record Algebra_isFalgebra (K : fieldType) A of Vector K A & GRing.Algebra K A := {}. HB.builders Context K A of Algebra_isFalgebra K A. Let vA : Vector.type K := A. Let am u := linfun (u \o* idfun : vA -> vA). Let uam := [pred u | lker (am u) == 0%VS]. Let vam := [fun u => if u \in uam then (am u)^-1%VF 1 else u]. Lemma amE u v : am u v = v * u. Proof. by rewrite lfunE. Qed. Lemma mulVr : {in uam, left_inverse 1 vam *%R}. Proof. by move=> u Uu; rewrite /= Uu -amE lker0_lfunVK. Qed. Lemma divrr : {in uam, right_inverse 1 vam *%R}. Proof. by move=> u Uu; apply/(lker0P Uu); rewrite !amE -mulrA mulVr // mul1r mulr1. Qed. Lemma unitrP : forall x y, y * x = 1 /\ x * y = 1 -> uam x. Proof. move=> u v [_ uv1]. by apply/lker0P=> w1 w2 /(congr1 (am v)); rewrite !amE -!mulrA uv1 !mulr1. Qed. Lemma invr_out : {in [predC uam], vam =1 id}. Proof. by move=> u /negbTE/= ->. Qed. HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build A mulVr divrr unitrP invr_out. HB.end. Module FalgebraExports. Bind Scope ring_scope with sort. End FalgebraExports. HB.export FalgebraExports. Notation "1" := (vline 1) : vspace_scope. HB.instance Definition _ (K : fieldType) n := Algebra_isFalgebra.Build K 'M[K]_n.+1. HB.instance Definition _ (R : comUnitRingType) := GRing.UnitAlgebra.on R^o. (* FIXME: remove once https://github.com/math-comp/hierarchy-builder/issues/197 is fixed *) Lemma regular_fullv (K : fieldType) : (fullv = 1 :> {vspace K^o})%VS. Proof. by apply/esym/eqP; rewrite eqEdim subvf dim_vline oner_eq0 dimvf. Qed. Section Proper. Variables (R : nzRingType) (aT : falgType R). Import VectorInternalTheory. Lemma FalgType_proper : dim aT > 0. Proof. rewrite lt0n; apply: contraNneq (oner_neq0 aT) => aT0. by apply/eqP/v2r_inj; do 2!move: (v2r _); rewrite aT0 => u v; rewrite !thinmx0. Qed. End Proper. Module FalgLfun. Section FalgLfun. Variable (R : comNzRingType) (aT : falgType R). Implicit Types f g : 'End(aT). HB.instance Definition _ := GRing.Algebra.copy 'End(aT) (lfun_algType (FalgType_proper aT)). Lemma lfun_mulE f g u : (f * g) u = g (f u). Proof. exact: lfunE. Qed. Lemma lfun_compE f g : (g \o f)%VF = f * g. Proof. by []. Qed. End FalgLfun. Section InvLfun. Variable (K : fieldType) (aT : falgType K). Implicit Types f g : 'End(aT). Definition lfun_invr f := if lker f == 0%VS then f^-1%VF else f. Lemma lfun_mulVr f : lker f == 0%VS -> f^-1%VF * f = 1. Proof. exact: lker0_compfV. Qed. Lemma lfun_mulrV f : lker f == 0%VS -> f * f^-1%VF = 1. Proof. exact: lker0_compVf. Qed. Fact lfun_mulRVr f : lker f == 0%VS -> lfun_invr f * f = 1. Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulVr. Qed. Fact lfun_mulrRV f : lker f == 0%VS -> f * lfun_invr f = 1. Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulrV. Qed. Fact lfun_unitrP f g : g * f = 1 /\ f * g = 1 -> lker f == 0%VS. Proof. case=> _ fK; apply/lker0P; apply: can_inj (g) _ => u. by rewrite -lfun_mulE fK lfunE. Qed. Lemma lfun_invr_out f : lker f != 0%VS -> lfun_invr f = f. Proof. by rewrite /lfun_invr => /negPf->. Qed. HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build 'End(aT) lfun_mulRVr lfun_mulrRV lfun_unitrP lfun_invr_out. Lemma lfun_invE f : lker f == 0%VS -> f^-1%VF = f^-1. Proof. by rewrite /f^-1 /= /lfun_invr => ->. Qed. End InvLfun. End FalgLfun. Section FalgebraTheory. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v : aT) (U V W : {vspace aT}). Import FalgLfun. Definition amull u : 'End(aT) := linfun (u \*o @idfun aT). Definition amulr u : 'End(aT) := linfun (u \o* @idfun aT). Lemma amull_inj : injective amull. Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mulr1. Qed. Lemma amulr_inj : injective amulr. Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mul1r. Qed. Fact amull_is_linear : linear amull. Proof. move=> a u v; apply/lfunP => w. by rewrite !lfunE /= scale_lfunE !lfunE /= mulrDl scalerAl. Qed. #[hnf] HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amull (GRing.semilinear_linear amull_is_linear). (* amull is a converse ring morphism *) Lemma amull1 : amull 1 = \1%VF. Proof. by apply/lfunP => z; rewrite id_lfunE lfunE /= mul1r. Qed. Lemma amullM u v : (amull (u * v) = amull v * amull u)%VF. Proof. by apply/lfunP => w; rewrite comp_lfunE !lfunE /= mulrA. Qed. Lemma amulr_is_linear : linear amulr. Proof. move=> a u v; apply/lfunP => w. by rewrite !lfunE /= !lfunE /= lfunE mulrDr /= scalerAr. Qed. Lemma amulr_is_monoid_morphism : monoid_morphism amulr. Proof. split=> [|x y]; first by apply/lfunP => w; rewrite id_lfunE !lfunE /= mulr1. by apply/lfunP=> w; rewrite comp_lfunE !lfunE /= mulrA. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `amulr_is_monoid_morphism` instead")] Definition amulr_is_multiplicative := (fun p => (p.2, p.1)) amulr_is_monoid_morphism. #[hnf] HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amulr (GRing.semilinear_linear amulr_is_linear). #[hnf] HB.instance Definition _ := GRing.isMonoidMorphism.Build aT (hom aT aT) amulr amulr_is_monoid_morphism. Lemma lker0_amull u : u \is a GRing.unit -> lker (amull u) == 0%VS. Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulrI. Qed. Lemma lker0_amulr u : u \is a GRing.unit -> lker (amulr u) == 0%VS. Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulIr. Qed. Lemma lfun1_poly (p : {poly aT}) : map_poly \1%VF p = p. Proof. by apply: map_poly_id => u _; apply: id_lfunE. Qed. Fact prodv_key : unit. Proof. by []. Qed. Definition prodv := locked_with prodv_key (fun U V => <<allpairs *%R (vbasis U) (vbasis V)>>%VS). Canonical prodv_unlockable := [unlockable fun prodv]. Local Notation "A * B" := (prodv A B) : vspace_scope. Lemma memv_mul U V : {in U & V, forall u v, u * v \in (U * V)%VS}. Proof. move=> u v /coord_vbasis-> /coord_vbasis->. rewrite mulr_suml; apply: memv_suml => i _. rewrite mulr_sumr; apply: memv_suml => j _. rewrite -scalerAl -scalerAr !memvZ // [prodv]unlock memv_span //. by apply/allpairsP; exists ((vbasis U)`_i, (vbasis V)`_j); rewrite !memt_nth. Qed. Lemma prodvP {U V W} : reflect {in U & V, forall u v, u * v \in W} (U * V <= W)%VS. Proof. apply: (iffP idP) => [sUVW u v Uu Vv | sUVW]. by rewrite (subvP sUVW) ?memv_mul. rewrite [prodv]unlock; apply/span_subvP=> _ /allpairsP[[u v] /= [Uu Vv ->]]. by rewrite sUVW ?vbasis_mem. Qed. Lemma prodv_line u v : (<[u]> * <[v]> = <[u * v]>)%VS. Proof. apply: subv_anti; rewrite -memvE memv_mul ?memv_line // andbT. apply/prodvP=> _ _ /vlineP[a ->] /vlineP[b ->]. by rewrite -scalerAr -scalerAl !memvZ ?memv_line. Qed. Lemma dimv1: \dim (1%VS : {vspace aT}) = 1. Proof. by rewrite dim_vline oner_neq0. Qed. Lemma dim_prodv U V : \dim (U * V) <= \dim U * \dim V. Proof. by rewrite unlock (leq_trans (dim_span _)) ?size_tuple. Qed. Lemma vspace1_neq0 : (1 != 0 :> {vspace aT})%VS. Proof. by rewrite -dimv_eq0 dimv1. Qed. Lemma vbasis1 : exists2 k, k != 0 & vbasis 1 = [:: k%:A] :> seq aT. Proof. move: (vbasis 1) (@vbasisP K aT 1); rewrite dim_vline oner_neq0. case/tupleP=> x X0; rewrite {X0}tuple0 => defX; have Xx := mem_head x nil. have /vlineP[k def_x] := basis_mem defX Xx; exists k; last by rewrite def_x. by have:= basis_not0 defX Xx; rewrite def_x scaler_eq0 oner_eq0 orbF. Qed. Lemma prod0v : left_zero 0%VS prodv. Proof. move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv 0 U)) //. by rewrite dimv0. Qed. Lemma prodv0 : right_zero 0%VS prodv. Proof. move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv U 0)) //. by rewrite dimv0 muln0. Qed. HB.instance Definition _ := Monoid.isMulLaw.Build {vspace aT} 0%VS prodv prod0v prodv0. Lemma prod1v : left_id 1%VS prodv. Proof. move=> U; apply/subv_anti/andP; split. by apply/prodvP=> _ u /vlineP[a ->] Uu; rewrite mulr_algl memvZ. by apply/subvP=> u Uu; rewrite -[u]mul1r memv_mul ?memv_line. Qed. Lemma prodv1 : right_id 1%VS prodv. Proof. move=> U; apply/subv_anti/andP; split. by apply/prodvP=> u _ Uu /vlineP[a ->]; rewrite mulr_algr memvZ. by apply/subvP=> u Uu; rewrite -[u]mulr1 memv_mul ?memv_line. Qed. Lemma prodvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 * V1 <= U2 * V2)%VS. Proof. move/subvP=> sU12 /subvP sV12; apply/prodvP=> u v Uu Vv. by rewrite memv_mul ?sU12 ?sV12. Qed. Lemma prodvSl U1 U2 V : (U1 <= U2 -> U1 * V <= U2 * V)%VS. Proof. by move/prodvS->. Qed. Lemma prodvSr U V1 V2 : (V1 <= V2 -> U * V1 <= U * V2)%VS. Proof. exact: prodvS. Qed. Lemma prodvDl : left_distributive prodv addv. Proof. move=> U1 U2 V; apply/esym/subv_anti/andP; split. by rewrite subv_add 2?prodvS ?addvSl ?addvSr. apply/prodvP=> _ v /memv_addP[u1 Uu1 [u2 Uu2 ->]] Vv. by rewrite mulrDl memv_add ?memv_mul. Qed. Lemma prodvDr : right_distributive prodv addv. Proof. move=> U V1 V2; apply/esym/subv_anti/andP; split. by rewrite subv_add 2?prodvS ?addvSl ?addvSr. apply/prodvP=> u _ Uu /memv_addP[v1 Vv1 [v2 Vv2 ->]]. by rewrite mulrDr memv_add ?memv_mul. Qed. HB.instance Definition _ := Monoid.isAddLaw.Build {vspace aT} prodv addv prodvDl prodvDr. Lemma prodvA : associative prodv. Proof. move=> U V W; rewrite -(span_basis (vbasisP U)) span_def !big_distrl /=. apply: eq_bigr => u _; rewrite -(span_basis (vbasisP W)) span_def !big_distrr. apply: eq_bigr => w _; rewrite -(span_basis (vbasisP V)) span_def /=. rewrite !(big_distrl, big_distrr) /=; apply: eq_bigr => v _. by rewrite !prodv_line mulrA. Qed. HB.instance Definition _ := Monoid.isLaw.Build {vspace aT} 1%VS prodv prodvA prod1v prodv1. Definition expv U n := iterop n.+1.-1 prodv U 1%VS. Local Notation "A ^+ n" := (expv A n) : vspace_scope. Lemma expv0 U : (U ^+ 0 = 1)%VS. Proof. by []. Qed. Lemma expv1 U : (U ^+ 1 = U)%VS. Proof. by []. Qed. Lemma expv2 U : (U ^+ 2 = U * U)%VS. Proof. by []. Qed. Lemma expvSl U n : (U ^+ n.+1 = U * U ^+ n)%VS. Proof. by case: n => //; rewrite prodv1. Qed. Lemma expv0n n : (0 ^+ n = if n is _.+1 then 0 else 1)%VS. Proof. by case: n => // n; rewrite expvSl prod0v. Qed. Lemma expv1n n : (1 ^+ n = 1)%VS. Proof. by elim: n => // n IHn; rewrite expvSl IHn prodv1. Qed. Lemma expvD U m n : (U ^+ (m + n) = U ^+ m * U ^+ n)%VS. Proof. by elim: m => [|m IHm]; rewrite ?prod1v // !expvSl IHm prodvA. Qed. Lemma expvSr U n : (U ^+ n.+1 = U ^+ n * U)%VS. Proof. by rewrite -addn1 expvD. Qed. Lemma expvM U m n : (U ^+ (m * n) = U ^+ m ^+ n)%VS. Proof. by elim: n => [|n IHn]; rewrite ?muln0 // mulnS expvD IHn expvSl. Qed. Lemma expvS U V n : (U <= V -> U ^+ n <= V ^+ n)%VS. Proof. move=> sUV; elim: n => [|n IHn]; first by rewrite !expv0 subvv. by rewrite !expvSl prodvS. Qed. Lemma expv_line u n : (<[u]> ^+ n = <[u ^+ n]>)%VS. Proof. elim: n => [|n IH]; first by rewrite expr0 expv0. by rewrite exprS expvSl IH prodv_line. Qed. (* Centralisers and centers. *) Definition centraliser1_vspace u := lker (amulr u - amull u). Local Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope. Definition centraliser_vspace V := (\bigcap_i 'C[tnth (vbasis V) i])%VS. Local Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope. Definition center_vspace V := (V :&: 'C(V))%VS. Local Notation "'Z ( V )" := (center_vspace V) : vspace_scope. Lemma cent1vP u v : reflect (u * v = v * u) (u \in 'C[v]%VS). Proof. by rewrite (sameP eqlfunP eqP) !lfunE /=; apply: eqP. Qed. Lemma cent1v1 u : 1 \in 'C[u]%VS. Proof. by apply/cent1vP; rewrite commr1. Qed. Lemma cent1v_id u : u \in 'C[u]%VS. Proof. exact/cent1vP. Qed. Lemma cent1vX u n : u ^+ n \in 'C[u]%VS. Proof. exact/cent1vP/esym/commrX. Qed. Lemma cent1vC u v : (u \in 'C[v])%VS = (v \in 'C[u])%VS. Proof. exact/cent1vP/cent1vP. Qed. Lemma centvP u V : reflect {in V, forall v, u * v = v * u} (u \in 'C(V))%VS. Proof. apply: (iffP subv_bigcapP) => [cVu y /coord_vbasis-> | cVu i _]. apply/esym/cent1vP/rpred_sum=> i _; apply: rpredZ. by rewrite -tnth_nth cent1vC memvE cVu. exact/cent1vP/cVu/vbasis_mem/mem_tnth. Qed. Lemma centvsP U V : reflect {in U & V, commutative *%R} (U <= 'C(V))%VS. Proof. by apply: (iffP subvP) => [cUV u v | cUV u] /cUV-/centvP; apply. Qed. Lemma subv_cent1 U v : (U <= 'C[v])%VS = (v \in 'C(U)%VS). Proof. by apply/subvP/centvP=> cUv u Uu; apply/cent1vP; rewrite 1?cent1vC cUv. Qed. Lemma centv1 V : 1 \in 'C(V)%VS. Proof. by apply/centvP=> v _; rewrite commr1. Qed. Lemma centvX V u n : u \in 'C(V)%VS -> u ^+ n \in 'C(V)%VS. Proof. by move/centvP=> cVu; apply/centvP=> v /cVu/esym/commrX->. Qed. Lemma centvC U V : (U <= 'C(V))%VS = (V <= 'C(U))%VS. Proof. by apply/centvsP/centvsP=> cUV u v UVu /cUV->. Qed. Lemma centerv_sub V : ('Z(V) <= V)%VS. Proof. exact: capvSl. Qed. Lemma cent_centerv V : (V <= 'C('Z(V)))%VS. Proof. by rewrite centvC capvSr. Qed. (* Building the predicate that checks is a vspace has a unit *) Definition is_algid e U := [/\ e \in U, e != 0 & {in U, forall u, e * u = u /\ u * e = u}]. Fact algid_decidable U : decidable (exists e, is_algid e U). Proof. have [-> | nzU] := eqVneq U 0%VS. by right=> [[e []]]; rewrite memv0 => ->. pose X := vbasis U; pose feq f1 f2 := [tuple of map f1 X ++ map f2 X]. have feqL f i: tnth (feq _ f _) (lshift _ i) = f X`_i. set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple. by rewrite ltn_ord (nth_map 0) ?size_tuple. have feqR f i: tnth (feq _ _ f) (rshift _ i) = f X`_i. set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple. by rewrite ltnNge leq_addr addKn /= (nth_map 0) ?size_tuple. apply: decP (vsolve_eq (feq _ amulr amull) (feq _ id id) U) _. apply: (iffP (vsolve_eqP _ _ _)) => [[e Ue id_e] | [e [Ue _ id_e]]]. suffices idUe: {in U, forall u, e * u = u /\ u * e = u}. exists e; split=> //; apply: contraNneq nzU => e0; rewrite -subv0. by apply/subvP=> u /idUe[<- _]; rewrite e0 mul0r mem0v. move=> u /coord_vbasis->; rewrite mulr_sumr mulr_suml. split; apply/eq_bigr=> i _; rewrite -(scalerAr, scalerAl); congr (_ *: _). by have:= id_e (lshift _ i); rewrite !feqL lfunE. by have:= id_e (rshift _ i); rewrite !feqR lfunE. have{id_e} /all_and2[ideX idXe]:= id_e _ (vbasis_mem (mem_tnth _ X)). exists e => // k; rewrite -[k]splitK. by case: (split k) => i; rewrite !(feqL, feqR) lfunE /= -tnth_nth. Qed. Definition has_algid : pred {vspace aT} := algid_decidable. Lemma has_algidP {U} : reflect (exists e, is_algid e U) (has_algid U). Proof. exact: sumboolP. Qed. Lemma has_algid1 U : 1 \in U -> has_algid U. Proof. move=> U1; apply/has_algidP; exists 1; split; rewrite ?oner_eq0 // => u _. by rewrite mulr1 mul1r. Qed. Definition is_aspace U := has_algid U && (U * U <= U)%VS. Structure aspace := ASpace {asval :> {vspace aT}; _ : is_aspace asval}. HB.instance Definition _ := [isSub for asval]. HB.instance Definition _ := [Choice of aspace by <:]. Definition clone_aspace U (A : aspace) := fun algU & phant_id algU (valP A) => @ASpace U algU : aspace. Fact aspace1_subproof : is_aspace 1. Proof. by rewrite /is_aspace prod1v -memvE has_algid1 memv_line. Qed. Canonical aspace1 : aspace := ASpace aspace1_subproof. Lemma aspacef_subproof : is_aspace fullv. Proof. by rewrite /is_aspace subvf has_algid1 ?memvf. Qed. Canonical aspacef : aspace := ASpace aspacef_subproof. Lemma polyOver1P p : reflect (exists q, p = map_poly (in_alg aT) q) (p \is a polyOver 1%VS). Proof. apply: (iffP idP) => [/allP/=Qp | [q ->]]; last first. by apply/polyOverP=> j; rewrite coef_map rpredZ ?memv_line. exists (map_poly (coord [tuple 1] 0) p). rewrite -map_poly_comp map_poly_id // => _ /Qp/vlineP[a ->] /=. by rewrite linearZ /= (coord_free 0) ?mulr1 // seq1_free ?oner_eq0. Qed. End FalgebraTheory. Delimit Scope aspace_scope with AS. Bind Scope aspace_scope with aspace. Arguments asval {K aT} a%_AS. Arguments aspace [K]%_type aT%_type. Arguments clone_aspace [K aT U%_VS A%_AS algU] _. Notation "{ 'aspace' T }" := (aspace T) : type_scope. Notation "A * B" := (prodv A B) : vspace_scope. Notation "A ^+ n" := (expv A n) : vspace_scope. Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope. Notation "'C_ U [ v ]" := (capv U 'C[v]) : vspace_scope. Notation "'C_ ( U ) [ v ]" := (capv U 'C[v]) (only parsing) : vspace_scope. Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope. Notation "'C_ U ( V )" := (capv U 'C(V)) : vspace_scope. Notation "'C_ ( U ) ( V )" := (capv U 'C(V)) (only parsing) : vspace_scope. Notation "'Z ( V )" := (center_vspace V) : vspace_scope. Notation "1" := (aspace1 _) : aspace_scope. Notation "{ : aT }" := (aspacef aT) : aspace_scope. Notation "[ 'aspace' 'of' U ]" := (@clone_aspace _ _ U _ _ id) (format "[ 'aspace' 'of' U ]") : form_scope. Notation "[ 'aspace' 'of' U 'for' A ]" := (@clone_aspace _ _ U A _ idfun) (format "[ 'aspace' 'of' U 'for' A ]") : form_scope. Arguments prodvP {K aT U V W}. Arguments cent1vP {K aT u v}. Arguments centvP {K aT u V}. Arguments centvsP {K aT U V}. Arguments has_algidP {K aT U}. Arguments polyOver1P {K aT p}. Section AspaceTheory. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v e : aT) (U V : {vspace aT}) (A B : {aspace aT}). Import FalgLfun. Lemma algid_subproof U : {e | e \in U & has_algid U ==> (U <= lker (amull e - 1) :&: lker (amulr e - 1))%VS}. Proof. apply: sig2W; case: has_algidP => [[e]|]; last by exists 0; rewrite ?mem0v. case=> Ae _ idAe; exists e => //; apply/subvP=> u /idAe[eu_u ue_u]. by rewrite memv_cap !memv_ker !lfun_simp /= eu_u ue_u subrr eqxx. Qed. Definition algid U := s2val (algid_subproof U). Lemma memv_algid U : algid U \in U. Proof. by rewrite /algid; case: algid_subproof. Qed. Lemma algidl A : {in A, left_id (algid A) *%R}. Proof. rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A. move/subvP=> idAe u /idAe/memv_capP[]. by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP. Qed. Lemma algidr A : {in A, right_id (algid A) *%R}. Proof. rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A. move/subvP=> idAe u /idAe/memv_capP[_]. by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP. Qed. Lemma unitr_algid1 A u : u \in A -> u \is a GRing.unit -> algid A = 1. Proof. by move=> Eu /mulrI; apply; rewrite mulr1 algidr. Qed. Lemma algid_eq1 A : (algid A == 1) = (1 \in A). Proof. by apply/eqP/idP=> [<- | /algidr <-]; rewrite ?memv_algid ?mul1r. Qed. Lemma algid_neq0 A : algid A != 0. Proof. have /andP[/has_algidP[u [Au nz_u _]] _] := valP A. by apply: contraNneq nz_u => e0; rewrite -(algidr Au) e0 mulr0. Qed. Lemma dim_algid A : \dim <[algid A]> = 1%N. Proof. by rewrite dim_vline algid_neq0. Qed. Lemma adim_gt0 A : (0 < \dim A)%N. Proof. by rewrite -(dim_algid A) dimvS // -memvE ?memv_algid. Qed. Lemma not_asubv0 A : ~~ (A <= 0)%VS. Proof. by rewrite subv0 -dimv_eq0 -lt0n adim_gt0. Qed. Lemma adim1P {A} : reflect (A = <[algid A]>%VS :> {vspace aT}) (\dim A == 1%N). Proof. rewrite eqn_leq adim_gt0 -(memv_algid A) andbC -(dim_algid A) -eqEdim eq_sym. exact: eqP. Qed. Lemma asubv A : (A * A <= A)%VS. Proof. by have /andP[] := valP A. Qed. Lemma memvM A : {in A &, forall u v, u * v \in A}. Proof. exact/prodvP/asubv. Qed. Lemma prodv_id A : (A * A)%VS = A. Proof. apply/eqP; rewrite eqEsubv asubv; apply/subvP=> u Au. by rewrite -(algidl Au) memv_mul // memv_algid. Qed. Lemma prodv_sub U V A : (U <= A -> V <= A -> U * V <= A)%VS. Proof. by move=> sUA sVA; rewrite -prodv_id prodvS. Qed. Lemma expv_id A n : (A ^+ n.+1)%VS = A. Proof. by elim: n => // n IHn; rewrite !expvSl prodvA prodv_id -expvSl. Qed. Lemma limg_amulr U v : (amulr v @: U = U * <[v]>)%VS. Proof. rewrite -(span_basis (vbasisP U)) limg_span !span_def big_distrl /= big_map. by apply: eq_bigr => u; rewrite prodv_line lfunE. Qed. Lemma memv_cosetP {U v w} : reflect (exists2 u, u\in U & w = u * v) (w \in U * <[v]>)%VS. Proof. rewrite -limg_amulr. by apply: (iffP memv_imgP) => [] [u] Uu ->; exists u; rewrite ?lfunE. Qed. Lemma dim_cosetv_unit V u : u \is a GRing.unit -> \dim (V * <[u]>) = \dim V. Proof. by move/lker0_amulr/eqP=> Uu; rewrite -limg_amulr limg_dim_eq // Uu capv0. Qed. Lemma memvV A u : (u^-1 \in A) = (u \in A). Proof. suffices{u} invA: invr_closed A by apply/idP/idP=> /invA; rewrite ?invrK. move=> u Au; have [Uu | /invr_out-> //] := boolP (u \is a GRing.unit). rewrite memvE -(limg_ker0 _ _ (lker0_amulr Uu)) limg_line lfunE /= mulVr //. suff ->: (amulr u @: A)%VS = A by rewrite -memvE -algid_eq1 (unitr_algid1 Au). by apply/eqP; rewrite limg_amulr -dimv_leqif_eq ?prodv_sub ?dim_cosetv_unit. Qed. Fact aspace_cap_subproof A B : algid A \in B -> is_aspace (A :&: B). Proof. move=> BeA; apply/andP. split; [apply/has_algidP | by rewrite subv_cap !prodv_sub ?capvSl ?capvSr]. exists (algid A); rewrite /is_algid algid_neq0 memv_cap memv_algid. by split=> // u /memv_capP[Au _]; rewrite ?algidl ?algidr. Qed. Definition aspace_cap A B BeA := ASpace (@aspace_cap_subproof A B BeA). Fact centraliser1_is_aspace u : is_aspace 'C[u]. Proof. rewrite /is_aspace has_algid1 ?cent1v1 //=. apply/prodvP=> v w /cent1vP-cuv /cent1vP-cuw. by apply/cent1vP; rewrite -mulrA cuw !mulrA cuv. Qed. Canonical centraliser1_aspace u := ASpace (centraliser1_is_aspace u). Fact centraliser_is_aspace V : is_aspace 'C(V). Proof. rewrite /is_aspace has_algid1 ?centv1 //=. apply/prodvP=> u w /centvP-cVu /centvP-cVw. by apply/centvP=> v Vv; rewrite /= -mulrA cVw // !mulrA cVu. Qed. Canonical centraliser_aspace V := ASpace (centraliser_is_aspace V). Lemma centv_algid A : algid A \in 'C(A)%VS. Proof. by apply/centvP=> u Au; rewrite algidl ?algidr. Qed. Canonical center_aspace A := [aspace of 'Z(A) for aspace_cap (centv_algid A)]. Lemma algid_center A : algid 'Z(A) = algid A. Proof. rewrite -(algidl (subvP (centerv_sub A) _ (memv_algid _))) algidr //=. by rewrite memv_cap memv_algid centv_algid. Qed. Lemma Falgebra_FieldMixin : GRing.integral_domain_axiom aT -> GRing.field_axiom aT. Proof. move=> domT u nz_u; apply/unitrP. have kerMu: lker (amulr u) == 0%VS. rewrite eqEsubv sub0v andbT; apply/subvP=> v; rewrite memv_ker lfunE /=. by move/eqP/domT; rewrite (negPf nz_u) orbF memv0. have /memv_imgP[v _ vu1]: 1 \in limg (amulr u); last rewrite lfunE /= in vu1. suffices /eqP->: limg (amulr u) == fullv by rewrite memvf. by rewrite -dimv_leqif_eq ?subvf ?limg_dim_eq // (eqP kerMu) capv0. exists v; split=> //; apply: (lker0P kerMu). by rewrite !lfunE /= -mulrA -vu1 mulr1 mul1r. Qed. Section SkewField. Hypothesis fieldT : GRing.field_axiom aT. Lemma skew_field_algid1 A : algid A = 1. Proof. by rewrite (unitr_algid1 (memv_algid A)) ?fieldT ?algid_neq0. Qed. Lemma skew_field_module_semisimple A M : let sumA X := (\sum_(x <- X) A * <[x]>)%VS in (A * M <= M)%VS -> {X | [/\ sumA X = M, directv (sumA X) & 0 \notin X]}. Proof. move=> sumA sAM_M; pose X := Nil aT; pose k := (\dim (A * M) - \dim (sumA X))%N. have: (\dim (A * M) - \dim (sumA X) < k.+1)%N by []. have: [/\ (sumA X <= A * M)%VS, directv (sumA X) & 0 \notin X]. by rewrite /sumA directvE /= !big_nil sub0v dimv0. elim: {X k}k.+1 (X) => // k IHk X [sAX_AM dxAX nzX]; rewrite ltnS => leAXk. have [sM_AX | /subvPn/sig2W[y My notAXy]] := boolP (M <= sumA X)%VS. by exists X; split=> //; apply/eqP; rewrite eqEsubv (subv_trans sAX_AM). have nz_y: y != 0 by rewrite (memPnC notAXy) ?mem0v. pose AY := sumA (y :: X). have sAY_AM: (AY <= A * M)%VS by rewrite [AY]big_cons subv_add ?prodvSr. have dxAY: directv AY. rewrite directvE /= !big_cons [_ == _]directv_addE dxAX directvE eqxx /=. rewrite -/(sumA X) eqEsubv sub0v andbT -limg_amulr. apply/subvP=> _ /memv_capP[/memv_imgP[a Aa ->]]/[!lfunE]/= AXay. rewrite memv0 (mulIr_eq0 a (mulIr _)) ?fieldT //. apply: contraR notAXy => /fieldT-Ua; rewrite -[y](mulKr Ua) /sumA. by rewrite -big_distrr -(prodv_id A) /= -prodvA big_distrr memv_mul ?memvV. apply: (IHk (y :: X)); first by rewrite !inE eq_sym negb_or nz_y. rewrite -subSn ?dimvS // (directvP dxAY) /= big_cons -(directvP dxAX) /=. rewrite subnDA (leq_trans _ leAXk) ?leq_sub2r // leq_subLR -add1n leq_add2r. by rewrite dim_cosetv_unit ?fieldT ?adim_gt0. Qed. Lemma skew_field_module_dimS A M : (A * M <= M)%VS -> \dim A %| \dim M. Proof. case/skew_field_module_semisimple=> X [<- /directvP-> nzX] /=. rewrite big_seq prime.dvdn_sum // => x /(memPn nzX)nz_x. by rewrite dim_cosetv_unit ?fieldT. Qed. Lemma skew_field_dimS A B : (A <= B)%VS -> \dim A %| \dim B. Proof. by move=> sAB; rewrite skew_field_module_dimS ?prodv_sub. Qed. End SkewField. End AspaceTheory. (* Note that local centraliser might not be proper sub-algebras. *) Notation "'C [ u ]" := (centraliser1_aspace u) : aspace_scope. Notation "'C ( V )" := (centraliser_aspace V) : aspace_scope. Notation "'Z ( A )" := (center_aspace A) : aspace_scope. Arguments adim1P {K aT A}. Arguments memv_cosetP {K aT U v w}. Section Closure. Variables (K : fieldType) (aT : falgType K). Implicit Types (u v : aT) (U V W : {vspace aT}). (* Subspaces of an F-algebra form a Kleene algebra *) Definition agenv U := (\sum_(i < \dim {:aT}) U ^+ i)%VS. Local Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope. Local Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope. Lemma agenvEl U : agenv U = (1 + U * agenv U)%VS. Proof. pose f V := (1 + U * V)%VS; rewrite -/(f _); pose n := \dim {:aT}. have ->: agenv U = iter n f 0%VS. rewrite /agenv -/n; elim: n => [|n IHn]; first by rewrite big_ord0. rewrite big_ord_recl /= -{}IHn; congr (1 + _)%VS; rewrite big_distrr /=. by apply: eq_bigr => i; rewrite expvSl. have fS i j: i <= j -> (iter i f 0 <= iter j f 0)%VS. by elim: i j => [|i IHi] [|j] leij; rewrite ?sub0v //= addvS ?prodvSr ?IHi. suffices /(@trajectP _ f _ n.+1)[i le_i_n Dfi]: looping f 0%VS n.+1. by apply/eqP; rewrite eqEsubv -iterS fS // Dfi fS. apply: contraLR (dimvS (subvf (iter n.+1 f 0%VS))); rewrite -/n -ltnNge. rewrite -looping_uniq; elim: n.+1 => // i IHi; rewrite trajectSr rcons_uniq. rewrite {1}trajectSr mem_rcons inE negb_or eq_sym eqEdim fS ?leqW // -ltnNge. by rewrite -andbA => /and3P[lt_fi _ /IHi/leq_ltn_trans->]. Qed. Lemma agenvEr U : agenv U = (1 + agenv U * U)%VS. Proof. rewrite [lhs in lhs = _]agenvEl big_distrr big_distrl /=; congr (_ + _)%VS. by apply: eq_bigr => i _ /=; rewrite -expvSr -expvSl. Qed. Lemma agenv_modl U V : (U * V <= V -> agenv U * V <= V)%VS. Proof. rewrite big_distrl /= => idlU_V; apply/subv_sumP=> [[i _] /= _]. elim: i => [|i]; first by rewrite expv0 prod1v. by apply: subv_trans; rewrite expvSr -prodvA prodvSr. Qed. Lemma agenv_modr U V : (V * U <= V -> V * agenv U <= V)%VS. Proof. rewrite big_distrr /= => idrU_V; apply/subv_sumP=> [[i _] /= _]. elim: i => [|i]; first by rewrite expv0 prodv1. by apply: subv_trans; rewrite expvSl prodvA prodvSl. Qed. Fact agenv_is_aspace U : is_aspace (agenv U). Proof. rewrite /is_aspace has_algid1; last by rewrite memvE agenvEl addvSl. by rewrite agenv_modl // [V in (_ <= V)%VS]agenvEl addvSr. Qed. Canonical agenv_aspace U : {aspace aT} := ASpace (agenv_is_aspace U). Lemma agenvE U : agenv U = agenv_aspace U. Proof. by []. Qed. (* Kleene algebra properties *) Lemma agenvM U : (agenv U * agenv U)%VS = agenv U. Proof. exact: prodv_id. Qed. Lemma agenvX n U : (agenv U ^+ n.+1)%VS = agenv U. Proof. exact: expv_id. Qed. Lemma sub1_agenv U : (1 <= agenv U)%VS. Proof. by rewrite agenvEl addvSl. Qed. Lemma sub_agenv U : (U <= agenv U)%VS. Proof. by rewrite 2!agenvEl addvC prodvDr prodv1 -addvA addvSl. Qed. Lemma subX_agenv U n : (U ^+ n <= agenv U)%VS. Proof. by case: n => [|n]; rewrite ?sub1_agenv // -(agenvX n) expvS // sub_agenv. Qed. Lemma agenv_sub_modl U V : (1 <= V -> U * V <= V -> agenv U <= V)%VS. Proof. move=> s1V /agenv_modl; apply: subv_trans. by rewrite -[Us in (Us <= _)%VS]prodv1 prodvSr. Qed. Lemma agenv_sub_modr U V : (1 <= V -> V * U <= V -> agenv U <= V)%VS. Proof. move=> s1V /agenv_modr; apply: subv_trans. by rewrite -[Us in (Us <= _)%VS]prod1v prodvSl. Qed. Lemma agenv_id U : agenv (agenv U) = agenv U. Proof. apply/eqP; rewrite eqEsubv sub_agenv andbT. by rewrite agenv_sub_modl ?sub1_agenv ?agenvM. Qed. Lemma agenvS U V : (U <= V -> agenv U <= agenv V)%VS. Proof. move=> sUV; rewrite agenv_sub_modl ?sub1_agenv //. by rewrite -[Vs in (_ <= Vs)%VS]agenvM prodvSl ?(subv_trans sUV) ?sub_agenv. Qed. Lemma agenv_add_id U V : agenv (agenv U + V) = agenv (U + V). Proof. apply/eqP; rewrite eqEsubv andbC agenvS ?addvS ?sub_agenv //=. rewrite agenv_sub_modl ?sub1_agenv //. rewrite -[rhs in (_ <= rhs)%VS]agenvM prodvSl // subv_add agenvS ?addvSl //=. exact: subv_trans (addvSr U V) (sub_agenv _). Qed. Lemma subv_adjoin U x : (U <= <<U; x>>)%VS. Proof. by rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSl. Qed. Lemma subv_adjoin_seq U xs : (U <= <<U & xs>>)%VS. Proof. by rewrite (subv_trans (sub_agenv _)) // ?agenvS ?addvSl. Qed. Lemma memv_adjoin U x : x \in <<U; x>>%VS. Proof. by rewrite memvE (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed. Lemma seqv_sub_adjoin U xs : {subset xs <= <<U & xs>>%VS}. Proof. by apply/span_subvP; rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed. Lemma subvP_adjoin U x y : y \in U -> y \in <<U; x>>%VS. Proof. exact/subvP/subv_adjoin. Qed. Lemma adjoin_nil V : <<V & [::]>>%VS = agenv V. Proof. by rewrite span_nil addv0. Qed. Lemma adjoin_cons V x rs : <<V & x :: rs>>%VS = << <<V; x>> & rs>>%VS. Proof. by rewrite span_cons addvA agenv_add_id. Qed. Lemma adjoin_rcons V rs x : <<V & rcons rs x>>%VS = << <<V & rs>>%VS; x>>%VS. Proof. by rewrite -cats1 span_cat addvA span_seq1 agenv_add_id. Qed. Lemma adjoin_seq1 V x : <<V & [:: x]>>%VS = <<V; x>>%VS. Proof. by rewrite adjoin_cons adjoin_nil agenv_id. Qed. Lemma adjoinC V x y : << <<V; x>>; y>>%VS = << <<V; y>>; x>>%VS. Proof. by rewrite !agenv_add_id -!addvA (addvC <[x]>%VS). Qed. Lemma adjoinSl U V x : (U <= V -> <<U; x>> <= <<V; x>>)%VS. Proof. by move=> sUV; rewrite agenvS ?addvS. Qed. Lemma adjoin_seqSl U V rs : (U <= V -> <<U & rs>> <= <<V & rs>>)%VS. Proof. by move=> sUV; rewrite agenvS ?addvS. Qed. Lemma adjoin_seqSr U rs1 rs2 : {subset rs1 <= rs2} -> (<<U & rs1>> <= <<U & rs2>>)%VS. Proof. by move/sub_span=> s_rs12; rewrite agenvS ?addvS. Qed. End Closure. Notation "<< U >>" := (agenv_aspace U) : aspace_scope. Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope. Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope. Notation "<< U & vs >>" := << U + <<vs>> >>%AS : aspace_scope. Notation "<< U ; x >>" := << U + <[x]> >>%AS : aspace_scope. Section SubFalgType. (* The falgType structure of subvs_of A for A : {aspace aT}. *) (* We can't use the rpred-based mixin, because A need not contain 1. *) Variable (K : fieldType) (aT : falgType K) (A : {aspace aT}). Definition subvs_one := Subvs (memv_algid A). Definition subvs_mul (u v : subvs_of A) := Subvs (subv_trans (memv_mul (subvsP u) (subvsP v)) (asubv _)). Fact subvs_mulA : associative subvs_mul. Proof. by move=> x y z; apply/val_inj/mulrA. Qed. Fact subvs_mu1l : left_id subvs_one subvs_mul. Proof. by move=> x; apply/val_inj/algidl/(valP x). Qed. Fact subvs_mul1 : right_id subvs_one subvs_mul. Proof. by move=> x; apply/val_inj/algidr/(valP x). Qed. Fact subvs_mulDl : left_distributive subvs_mul +%R. Proof. move=> x y z; apply/val_inj/mulrDl. Qed. Fact subvs_mulDr : right_distributive subvs_mul +%R. Proof. move=> x y z; apply/val_inj/mulrDr. Qed. HB.instance Definition _ := GRing.Zmodule_isNzRing.Build (subvs_of A) subvs_mulA subvs_mu1l subvs_mul1 subvs_mulDl subvs_mulDr (algid_neq0 _). Lemma subvs_scaleAl k (x y : subvs_of A) : k *: (x * y) = (k *: x) * y. Proof. exact/val_inj/scalerAl. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build K (subvs_of A) subvs_scaleAl. Lemma subvs_scaleAr k (x y : subvs_of A) : k *: (x * y) = x * (k *: y). Proof. exact/val_inj/scalerAr. Qed. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build K (subvs_of A) subvs_scaleAr. HB.instance Definition _ := Algebra_isFalgebra.Build K (subvs_of A). Implicit Type w : subvs_of A. Lemma vsval_unitr w : vsval w \is a GRing.unit -> w \is a GRing.unit. Proof. case: w => /= u Au Uu; have Au1: u^-1 \in A by rewrite memvV. apply/unitrP; exists (Subvs Au1). by split; apply: val_inj; rewrite /= ?mulrV ?mulVr ?(unitr_algid1 Au). Qed. Lemma vsval_invr w : vsval w \is a GRing.unit -> val w^-1 = (val w)^-1. Proof. move=> Uu; have def_w: w / w * w = w by rewrite divrK ?vsval_unitr. by apply: (mulrI Uu); rewrite -[in u in u / _]def_w ?mulrK. Qed. End SubFalgType. Section AHom. Variable K : fieldType. Section Class_Def. Variables aT rT : falgType K. Definition ahom_in (U : {vspace aT}) (f : 'Hom(aT, rT)) := all2rel (fun x y : aT => f (x * y) == f x * f y) (vbasis U) && (f 1 == 1). Lemma ahom_inP {f : 'Hom(aT, rT)} {U : {vspace aT}} : reflect ({in U &, {morph f : x y / x * y >-> x * y}} * (f 1 = 1)) (ahom_in U f). Proof. apply: (iffP andP) => [[/allrelP fM /eqP f1] | [fM f1]]; last first. rewrite f1; split=> //; apply/allrelP => x y Ax Ay. by rewrite fM // vbasis_mem. split=> // x y /coord_vbasis -> /coord_vbasis ->. rewrite !mulr_suml ![f _]linear_sum mulr_suml; apply: eq_bigr => i _ /=. rewrite !mulr_sumr linear_sum; apply: eq_bigr => j _ /=. rewrite !linearZ -!scalerAr -!scalerAl 2!linearZ /=; congr (_ *: (_ *: _)). by apply/eqP/fM; apply: memt_nth. Qed. Lemma ahomP_tmp {f : 'Hom(aT, rT)} : reflect (monoid_morphism f) (ahom_in {:aT} f). Proof. apply: (iffP ahom_inP) => [[fM f1] | fRM_P]; last first. by split=> [x y|]; [rewrite fRM_P.2|rewrite fRM_P.1]. by split=> // x y; rewrite fM ?memvf. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ahomP_tmp` instead")] Lemma ahomP {f : 'Hom(aT, rT)} : reflect (multiplicative f) (ahom_in {:aT} f). Proof. by apply: (iffP ahomP_tmp) => [][]. Qed. Structure ahom := AHom {ahval :> 'Hom(aT, rT); _ : ahom_in {:aT} ahval}. HB.instance Definition _ := [isSub for ahval]. HB.instance Definition _ := [Equality of ahom by <:]. HB.instance Definition _ := [Choice of ahom by <:]. Fact linfun_is_ahom (f : {lrmorphism aT -> rT}) : ahom_in {:aT} (linfun f). Proof. by apply/ahom_inP; split=> [x y|]; rewrite !lfunE ?rmorphM ?rmorph1. Qed. Canonical linfun_ahom f := AHom (linfun_is_ahom f). End Class_Def. Arguments ahom_in [aT rT]. Arguments ahom_inP {aT rT f U}. #[warning="-deprecated-since-mathcomp-2.5.0"] Arguments ahomP {aT rT f}. Arguments ahomP_tmp {aT rT f}. Section LRMorphism. Variables aT rT sT : falgType K. Fact ahom_is_monoid_morphism (f : ahom aT rT) : monoid_morphism f. Proof. by apply/ahomP_tmp; case: f. Qed. #[hnf] HB.instance Definition _ (f : ahom aT rT) := GRing.isMonoidMorphism.Build aT rT f (ahom_is_monoid_morphism f). #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `ahom_is_monoid_morphism` instead")] Definition ahom_is_multiplicative (f : ahom aT rT) : multiplicative f := (fun p => (p.2, p.1)) (ahom_is_monoid_morphism f). Lemma ahomWin (f : ahom aT rT) U : ahom_in U f. Proof. by apply/ahom_inP; split; [apply: in2W (rmorphM _) | apply: rmorph1]. Qed. Lemma id_is_ahom (V : {vspace aT}) : ahom_in V \1. Proof. by apply/ahom_inP; split=> [x y|] /=; rewrite !id_lfunE. Qed. Canonical id_ahom := AHom (id_is_ahom (aspacef aT)). Lemma comp_is_ahom (V : {vspace aT}) (f : 'Hom(rT, sT)) (g : 'Hom(aT, rT)) : ahom_in {:rT} f -> ahom_in V g -> ahom_in V (f \o g). Proof. move=> /ahom_inP fM /ahom_inP gM; apply/ahom_inP. by split=> [x y Vx Vy|] /=; rewrite !comp_lfunE gM // fM ?memvf. Qed. Canonical comp_ahom (f : ahom rT sT) (g : ahom aT rT) := AHom (comp_is_ahom (valP f) (valP g)). Lemma aimgM (f : ahom aT rT) U V : (f @: (U * V) = f @: U * f @: V)%VS. Proof. apply/eqP; rewrite eqEsubv; apply/andP; split; last first. apply/prodvP=> _ _ /memv_imgP[u Hu ->] /memv_imgP[v Hv ->]. by rewrite -rmorphM memv_img // memv_mul. apply/subvP=> _ /memv_imgP[w UVw ->]; rewrite memv_preim (subvP _ w UVw) //. by apply/prodvP=> u v Uu Vv; rewrite -memv_preim rmorphM memv_mul // memv_img. Qed. Lemma aimg1 (f : ahom aT rT) : (f @: 1 = 1)%VS. Proof. by rewrite limg_line rmorph1. Qed. Lemma aimgX (f : ahom aT rT) U n : (f @: (U ^+ n) = f @: U ^+ n)%VS. Proof. elim: n => [|n IH]; first by rewrite !expv0 aimg1. by rewrite !expvSl aimgM IH. Qed. Lemma aimg_agen (f : ahom aT rT) U : (f @: agenv U)%VS = agenv (f @: U). Proof. apply/eqP; rewrite eqEsubv; apply/andP; split. by rewrite limg_sum; apply/subv_sumP => i _; rewrite aimgX subX_agenv. apply: agenv_sub_modl; first by rewrite -(aimg1 f) limgS // sub1_agenv. by rewrite -aimgM limgS // [rhs in (_ <= rhs)%VS]agenvEl addvSr. Qed. Lemma aimg_adjoin (f : ahom aT rT) U x : (f @: <<U; x>> = <<f @: U; f x>>)%VS. Proof. by rewrite aimg_agen limgD limg_line. Qed. Lemma aimg_adjoin_seq (f : ahom aT rT) U xs : (f @: <<U & xs>> = <<f @: U & map f xs>>)%VS. Proof. by rewrite aimg_agen limgD limg_span. Qed. Fact ker_sub_ahom_is_aspace (f g : ahom aT rT) : is_aspace (lker (ahval f - ahval g)). Proof. rewrite /is_aspace has_algid1; last by apply/eqlfunP; rewrite !rmorph1. apply/prodvP=> a b /eqlfunP Dfa /eqlfunP Dfb. by apply/eqlfunP; rewrite !rmorphM /= Dfa Dfb. Qed. Canonical ker_sub_ahom_aspace f g := ASpace (ker_sub_ahom_is_aspace f g). End LRMorphism. Canonical fixedSpace_aspace aT (f : ahom aT aT) := [aspace of fixedSpace f]. End AHom. Arguments ahom_in [K aT rT]. Notation "''AHom' ( aT , rT )" := (ahom aT rT) : type_scope. Notation "''AEnd' ( aT )" := (ahom aT aT) : type_scope. Delimit Scope lrfun_scope with AF. Bind Scope lrfun_scope with ahom. Notation "\1" := (@id_ahom _ _) : lrfun_scope. Notation "f \o g" := (comp_ahom f g) : lrfun_scope.
Basis.lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.LinearAlgebra.Basis.Submodule import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.LinearAlgebra.Matrix.ToLin /-! # Bases and matrices This file defines the map `Basis.toMatrix` that sends a family of vectors to the matrix of their coordinates with respect to some basis. ## Main definitions * `Basis.toMatrix e v` is the matrix whose `i, j`th entry is `e.repr (v j) i` * `basis.toMatrixEquiv` is `Basis.toMatrix` bundled as a linear equiv ## Main results * `LinearMap.toMatrix_id_eq_basis_toMatrix`: `LinearMap.toMatrix b c id` is equal to `Basis.toMatrix b c` * `Basis.toMatrix_mul_toMatrix`: multiplying `Basis.toMatrix` with another `Basis.toMatrix` gives a `Basis.toMatrix` ## Tags matrix, basis -/ noncomputable section open Function LinearMap Matrix Module Set Submodule variable {ι ι' κ κ' : Type*} variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] variable {R₂ M₂ : Type*} [CommRing R₂] [AddCommGroup M₂] [Module R₂ M₂] namespace Module.Basis /-- From a basis `e : ι → M` and a family of vectors `v : ι' → M`, make the matrix whose columns are the vectors `v i` written in the basis `e`. -/ def toMatrix (e : Basis ι R M) (v : ι' → M) : Matrix ι ι' R := fun i j ↦ e.repr (v j) i variable (e : Basis ι R M) (v : ι' → M) (i : ι) (j : ι') theorem toMatrix_apply : e.toMatrix v i j = e.repr (v j) i := rfl theorem toMatrix_transpose_apply : (e.toMatrix v)ᵀ j = e.repr (v j) := funext fun _ => rfl theorem toMatrix_eq_toMatrix_constr [Fintype ι] [DecidableEq ι] (v : ι → M) : e.toMatrix v = LinearMap.toMatrix e e (e.constr ℕ v) := by ext rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Basis.constr_basis] -- TODO (maybe) Adjust the definition of `Basis.toMatrix` to eliminate the transpose. theorem coePiBasisFun.toMatrix_eq_transpose [Finite ι] : ((Pi.basisFun R ι).toMatrix : Matrix ι ι R → Matrix ι ι R) = Matrix.transpose := by ext M i j rfl @[simp] theorem toMatrix_self [DecidableEq ι] : e.toMatrix e = 1 := by unfold Basis.toMatrix ext i j simp [Matrix.one_apply, Finsupp.single_apply, eq_comm] theorem toMatrix_update [DecidableEq ι'] (x : M) : e.toMatrix (Function.update v j x) = Matrix.updateCol (e.toMatrix v) j (e.repr x) := by ext i' k rw [Basis.toMatrix, Matrix.updateCol_apply, e.toMatrix_apply] split_ifs with h · rw [h, update_self j x v] · rw [update_of_ne h] /-- The basis constructed by `unitsSMul` has vectors given by a diagonal matrix. -/ @[simp] theorem toMatrix_unitsSMul [DecidableEq ι] (e : Basis ι R₂ M₂) (w : ι → R₂ˣ) : e.toMatrix (e.unitsSMul w) = diagonal ((↑) ∘ w) := by ext i j by_cases h : i = j · simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def] · simp [h, toMatrix_apply, unitsSMul_apply, Units.smul_def, Ne.symm h] /-- The basis constructed by `isUnitSMul` has vectors given by a diagonal matrix. -/ @[simp] theorem toMatrix_isUnitSMul [DecidableEq ι] (e : Basis ι R₂ M₂) {w : ι → R₂} (hw : ∀ i, IsUnit (w i)) : e.toMatrix (e.isUnitSMul hw) = diagonal w := e.toMatrix_unitsSMul _ theorem toMatrix_smul_left {G} [Group G] [DistribMulAction G M] [SMulCommClass G R M] (g : G) : (g • e).toMatrix v = e.toMatrix (g⁻¹ • v) := rfl @[simp] theorem sum_toMatrix_smul_self [Fintype ι] : ∑ i : ι, e.toMatrix v i j • e i = v j := by simp_rw [e.toMatrix_apply, e.sum_repr] theorem toMatrix_smul {R₁ S : Type*} [CommSemiring R₁] [Semiring S] [Algebra R₁ S] [Fintype ι] [DecidableEq ι] (x : S) (b : Basis ι R₁ S) (w : ι → S) : (b.toMatrix (x • w)) = (Algebra.leftMulMatrix b x) * (b.toMatrix w) := by ext rw [Basis.toMatrix_apply, Pi.smul_apply, smul_eq_mul, ← Algebra.leftMulMatrix_mulVec_repr] rfl theorem toMatrix_map_vecMul {S : Type*} [Semiring S] [Algebra R S] [Fintype ι] (b : Basis ι R S) (v : ι' → S) : b ᵥ* ((b.toMatrix v).map <| algebraMap R S) = v := by ext i simp_rw [vecMul, dotProduct, Matrix.map_apply, ← Algebra.commutes, ← Algebra.smul_def, sum_toMatrix_smul_self] @[simp] theorem toLin_toMatrix [Finite ι] [Fintype ι'] [DecidableEq ι'] (v : Basis ι' R M) : Matrix.toLin v e (e.toMatrix v) = LinearMap.id := v.ext fun i => by cases nonempty_fintype ι; rw [toLin_self, id_apply, e.sum_toMatrix_smul_self] /-- From a basis `e : ι → M`, build a linear equivalence between families of vectors `v : ι → M`, and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/ def toMatrixEquiv [Fintype ι] (e : Basis ι R M) : (ι → M) ≃ₗ[R] Matrix ι ι R where toFun := e.toMatrix map_add' v w := by ext i j rw [Matrix.add_apply, e.toMatrix_apply, Pi.add_apply, LinearEquiv.map_add] rfl map_smul' := by intro c v ext i j dsimp only [] rw [e.toMatrix_apply, Pi.smul_apply, LinearEquiv.map_smul] rfl invFun m j := ∑ i, m i j • e i left_inv := by intro v ext j exact e.sum_toMatrix_smul_self v j right_inv := by intro m ext k l simp only [e.toMatrix_apply, ← e.equivFun_apply, ← e.equivFun_symm_apply, LinearEquiv.apply_symm_apply] variable (R₂) in theorem restrictScalars_toMatrix [Fintype ι] [DecidableEq ι] {S : Type*} [CommRing S] [Nontrivial S] [Algebra R₂ S] [Module S M₂] [IsScalarTower R₂ S M₂] [NoZeroSMulDivisors R₂ S] (b : Basis ι S M₂) (v : ι → span R₂ (Set.range b)) : (algebraMap R₂ S).mapMatrix ((b.restrictScalars R₂).toMatrix v) = b.toMatrix (fun i ↦ (v i : M₂)) := by ext rw [RingHom.mapMatrix_apply, Matrix.map_apply, Basis.toMatrix_apply, Basis.restrictScalars_repr_apply, Basis.toMatrix_apply] end Module.Basis section MulLinearMapToMatrix variable {N : Type*} [AddCommMonoid N] [Module R N] variable (b : Basis ι R M) (b' : Basis ι' R M) (c : Basis κ R N) (c' : Basis κ' R N) variable (f : M →ₗ[R] N) open LinearMap section Fintype /-- A generalization of `LinearMap.toMatrix_id`. -/ @[simp] theorem LinearMap.toMatrix_id_eq_basis_toMatrix [Fintype ι] [DecidableEq ι] [Finite ι'] : LinearMap.toMatrix b b' id = b'.toMatrix b := by ext i apply LinearMap.toMatrix_apply variable [Fintype ι'] @[simp] theorem basis_toMatrix_mul_linearMap_toMatrix [Finite κ] [Fintype κ'] [DecidableEq ι'] : c.toMatrix c' * LinearMap.toMatrix b' c' f = LinearMap.toMatrix b' c f := (Matrix.toLin b' c).injective <| by haveI := Classical.decEq κ' rw [toLin_toMatrix, toLin_mul b' c' c, toLin_toMatrix, c.toLin_toMatrix, LinearMap.id_comp] theorem basis_toMatrix_mul [Fintype κ] [Finite ι] [DecidableEq κ] (b₁ : Basis ι R M) (b₂ : Basis ι' R M) (b₃ : Basis κ R N) (A : Matrix ι' κ R) : b₁.toMatrix b₂ * A = LinearMap.toMatrix b₃ b₁ (toLin b₃ b₂ A) := by have := basis_toMatrix_mul_linearMap_toMatrix b₃ b₁ b₂ (Matrix.toLin b₃ b₂ A) rwa [LinearMap.toMatrix_toLin] at this variable [Finite κ] [Fintype ι] @[simp] theorem linearMap_toMatrix_mul_basis_toMatrix [Finite κ'] [DecidableEq ι] [DecidableEq ι'] : LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c' f := (Matrix.toLin b c').injective <| by rw [toLin_toMatrix, toLin_mul b b' c', toLin_toMatrix, b'.toLin_toMatrix, LinearMap.comp_id] theorem basis_toMatrix_mul_linearMap_toMatrix_mul_basis_toMatrix [Fintype κ'] [DecidableEq ι] [DecidableEq ι'] : c.toMatrix c' * LinearMap.toMatrix b' c' f * b'.toMatrix b = LinearMap.toMatrix b c f := by cases nonempty_fintype κ rw [basis_toMatrix_mul_linearMap_toMatrix, linearMap_toMatrix_mul_basis_toMatrix] theorem mul_basis_toMatrix [DecidableEq ι] [DecidableEq ι'] (b₁ : Basis ι R M) (b₂ : Basis ι' R M) (b₃ : Basis κ R N) (A : Matrix κ ι R) : A * b₁.toMatrix b₂ = LinearMap.toMatrix b₂ b₃ (toLin b₁ b₃ A) := by cases nonempty_fintype κ have := linearMap_toMatrix_mul_basis_toMatrix b₂ b₁ b₃ (Matrix.toLin b₁ b₃ A) rwa [LinearMap.toMatrix_toLin] at this theorem basis_toMatrix_basisFun_mul (b : Basis ι R (ι → R)) (A : Matrix ι ι R) : b.toMatrix (Pi.basisFun R ι) * A = of fun i j => b.repr (A.col j) i := by classical simp only [basis_toMatrix_mul _ _ (Pi.basisFun R ι), Matrix.toLin_eq_toLin'] ext i j rw [LinearMap.toMatrix_apply, Matrix.toLin'_apply, Pi.basisFun_apply, Matrix.mulVec_single_one, Matrix.of_apply] namespace Module.Basis /-- See also `Basis.toMatrix_reindex` which gives the `simp` normal form of this result. -/ theorem toMatrix_reindex' [DecidableEq ι] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M) (e : ι ≃ ι') : (b.reindex e).toMatrix v = Matrix.reindexAlgEquiv R R e (b.toMatrix (v ∘ e)) := by ext simp only [Basis.toMatrix_apply, Basis.repr_reindex, Matrix.reindexAlgEquiv_apply, Matrix.reindex_apply, Matrix.submatrix_apply, Function.comp_apply, e.apply_symm_apply, Finsupp.mapDomain_equiv_apply] omit [Fintype ι'] in @[simp] lemma toMatrix_mulVec_repr [Finite ι'] (m : M) : b'.toMatrix b *ᵥ b.repr m = b'.repr m := by classical cases nonempty_fintype ι' simp [← LinearMap.toMatrix_id_eq_basis_toMatrix, LinearMap.toMatrix_mulVec_repr] end Module.Basis end Fintype namespace Module.Basis /-- A generalization of `Basis.toMatrix_self`, in the opposite direction. -/ @[simp] theorem toMatrix_mul_toMatrix {ι'' : Type*} [Fintype ι'] (b'' : ι'' → M) : b.toMatrix b' * b'.toMatrix b'' = b.toMatrix b'' := by haveI := Classical.decEq ι haveI := Classical.decEq ι' haveI := Classical.decEq ι'' ext i j simp only [Matrix.mul_apply, toMatrix_apply, sum_repr_mul_repr] /-- `b.toMatrix b'` and `b'.toMatrix b` are inverses. -/ theorem toMatrix_mul_toMatrix_flip [DecidableEq ι] [Fintype ι'] : b.toMatrix b' * b'.toMatrix b = 1 := by rw [toMatrix_mul_toMatrix, toMatrix_self] /-- A matrix whose columns form a basis `b'`, expressed w.r.t. a basis `b`, is invertible. -/ def invertibleToMatrix [DecidableEq ι] [Fintype ι] (b b' : Basis ι R₂ M₂) : Invertible (b.toMatrix b') := ⟨b'.toMatrix b, toMatrix_mul_toMatrix_flip _ _, toMatrix_mul_toMatrix_flip _ _⟩ @[simp] theorem toMatrix_reindex (b : Basis ι R M) (v : ι' → M) (e : ι ≃ ι') : (b.reindex e).toMatrix v = (b.toMatrix v).submatrix e.symm _root_.id := by ext simp only [toMatrix_apply, repr_reindex, Matrix.submatrix_apply, _root_.id, Finsupp.mapDomain_equiv_apply] @[simp] theorem toMatrix_map (b : Basis ι R M) (f : M ≃ₗ[R] N) (v : ι → N) : (b.map f).toMatrix v = b.toMatrix (f.symm ∘ v) := by ext simp only [toMatrix_apply, Basis.map, LinearEquiv.trans_apply, (· ∘ ·)] end Module.Basis end MulLinearMapToMatrix
qpoly.v
From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype tuple bigop binomial finset finfun ssralg. From mathcomp Require Import countalg finalg poly polydiv perm fingroup matrix. From mathcomp Require Import mxalgebra mxpoly vector countalg. (******************************************************************************) (* This file defines the algebras R[X]/<p> and their theory. *) (* It mimics the zmod file for polynomials *) (* First, it defines polynomials of bounded size (equivalent of 'I_n), *) (* gives it a structure of choice, finite and countable ring, ..., and *) (* lmodule, when possible. *) (* Internally, the construction uses poly_rV and rVpoly, but they should not *) (* be exposed. *) (* We provide two bases: the 'X^i and the lagrange polynomials. *) (* {poly_n R} == the type of polynomial of size at most n *) (* irreducibleb p == boolean decision procedure for irreducibility *) (* of a bounded size polynomial over a finite idomain *) (* Considering {poly_n F} over a field F, it is a vectType and *) (* 'nX^i == 'X^i as an element of {poly_n R} *) (* polynX == [tuple 'X^0, ..., 'X^(n - 1)], basis of {poly_n R} *) (* x.-lagrange == lagrange basis of {poly_n R} wrt x : nat -> F *) (* x.-lagrange_ i == the ith lagrange polynomial wrt the sampling points x *) (* Second, it defines polynomials quotiented by a poly (equivalent of 'Z_p), *) (* as bounded polynomial. As we are aiming to build a ring structure we need *) (* the polynomial to be monic and of size greater than one. If it is not the *) (* case we quotient by 'X *) (* mk_monic p == the actual polynomial on which we quotient *) (* if p is monic and of size > 1 it is p otherwise 'X *) (* {poly %/ p} == defined as {poly_(size (mk_poly p)).-1 R} on which *) (* there is a ring structure *) (* in_qpoly q == turn the polynomial q into an element of {poly %/ p} by *) (* taking a modulo *) (* 'qX == in_qpoly 'X *) (* The last part that defines the field structure when the quotient is an *) (* irreducible polynomial is defined in field/qfpoly *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GRing.Theory. Import Pdiv.CommonRing. Import Pdiv.RingMonic. Import Pdiv.Field. Import FinRing.Theory. Local Open Scope ring_scope. Reserved Notation "'{poly_' n R }" (n at level 2, format "'{poly_' n R }"). Reserved Notation "''nX^' i" (at level 1, format "''nX^' i"). Reserved Notation "x .-lagrange" (format "x .-lagrange"). Reserved Notation "x .-lagrange_" (format "x .-lagrange_"). Reserved Notation "'qX". Reserved Notation "{ 'poly' '%/' p }" (p at level 2, format "{ 'poly' '%/' p }"). Section poly_of_size_zmod. Context {R : nzRingType}. Implicit Types (n : nat). Section poly_of_size. Variable (n : nat). Definition poly_of_size_pred := fun p : {poly R} => size p <= n. Arguments poly_of_size_pred _ /. Definition poly_of_size := [qualify a p | poly_of_size_pred p]. Lemma npoly_submod_closed : submod_closed poly_of_size. Proof. split=> [|x p q sp sq]; rewrite qualifE/= ?size_polyC ?eqxx//. rewrite (leq_trans (size_polyD _ _)) // geq_max. by rewrite (leq_trans (size_scale_leq _ _)). Qed. HB.instance Definition _ := GRing.isSubmodClosed.Build R {poly R} poly_of_size_pred npoly_submod_closed. End poly_of_size. Arguments poly_of_size_pred _ _ /. Section npoly. Variable (n : nat). Record npoly : predArgType := NPoly { polyn :> {poly R}; _ : polyn \is a poly_of_size n }. HB.instance Definition _ := [isSub for @polyn]. Lemma npoly_is_a_poly_of_size (p : npoly) : val p \is a poly_of_size n. Proof. by case: p. Qed. Hint Resolve npoly_is_a_poly_of_size : core. Lemma size_npoly (p : npoly) : size p <= n. Proof. exact: npoly_is_a_poly_of_size. Qed. Hint Resolve size_npoly : core. HB.instance Definition _ := [Choice of npoly by <:]. HB.instance Definition _ := [SubChoice_isSubLmodule of npoly by <:]. Definition npoly_rV : npoly -> 'rV[R]_n := poly_rV \o val. Definition rVnpoly : 'rV[R]_n -> npoly := insubd (0 : npoly) \o rVpoly. Arguments rVnpoly /. Arguments npoly_rV /. Lemma npoly_rV_K : cancel npoly_rV rVnpoly. Proof. move=> p /=; apply/val_inj. by rewrite val_insubd [_ \is a _]size_poly ?poly_rV_K. Qed. Lemma rVnpolyK : cancel rVnpoly npoly_rV. Proof. by move=> p /=; rewrite val_insubd [_ \is a _]size_poly rVpolyK. Qed. Hint Resolve npoly_rV_K rVnpolyK : core. Lemma npoly_vect_axiom : Vector.axiom n npoly. Proof. by exists npoly_rV; [exact:linearPZ | exists rVnpoly]. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build R npoly npoly_vect_axiom. End npoly. End poly_of_size_zmod. Arguments npoly {R}%_type n%_N. Notation "'{poly_' n R }" := (@npoly R n) : type_scope. #[global] Hint Resolve size_npoly npoly_is_a_poly_of_size : core. Arguments poly_of_size_pred _ _ _ /. Arguments npoly : clear implicits. HB.instance Definition _ (R : countNzRingType) n := [Countable of {poly_n R} by <:]. HB.instance Definition _ (R : finNzRingType) n : isFinite {poly_n R} := CanIsFinite (@npoly_rV_K R n). Section npoly_theory. Context (R : nzRingType) {n : nat}. Lemma polyn_is_linear : linear (@polyn _ _ : {poly_n R} -> _). Proof. by []. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly_n R} {poly R} _ (polyn (n:=n)) (GRing.semilinear_linear polyn_is_linear). Canonical mk_npoly (E : nat -> R) : {poly_n R} := @NPoly R _ (\poly_(i < n) E i) (size_poly _ _). Fact size_npoly0 : size (0 : {poly R}) <= n. Proof. by rewrite size_poly0. Qed. Definition npoly0 := NPoly (size_npoly0). Fact npolyp_key : unit. Proof. exact: tt. Qed. Definition npolyp : {poly R} -> {poly_n R} := locked_with npolyp_key (mk_npoly \o (nth 0)). Definition npoly_of_seq := npolyp \o Poly. Lemma npolyP (p q : {poly_n R}) : nth 0 p =1 nth 0 q <-> p = q. Proof. by split => [/polyP/val_inj|->]. Qed. Lemma coef_npolyp (p : {poly R}) i : (npolyp p)`_i = if i < n then p`_i else 0. Proof. by rewrite /npolyp unlock /= coef_poly. Qed. Lemma big_coef_npoly (p : {poly_n R}) i : n <= i -> p`_i = 0. Proof. by move=> i_big; rewrite nth_default // (leq_trans _ i_big) ?size_npoly. Qed. Lemma npolypK (p : {poly R}) : size p <= n -> npolyp p = p :> {poly R}. Proof. move=> spn; apply/polyP=> i; rewrite coef_npolyp. by have [i_big|i_small] // := ltnP; rewrite nth_default ?(leq_trans spn). Qed. Lemma coefn_sum (I : Type) (r : seq I) (P : pred I) (F : I -> {poly_n R}) (k : nat) : (\sum_(i <- r | P i) F i)`_k = \sum_(i <- r | P i) (F i)`_k. Proof. by rewrite !raddf_sum //= coef_sum. Qed. End npoly_theory. Arguments mk_npoly {R} n E. Arguments npolyp {R} n p. Section fin_npoly. Variable R : finNzRingType. Variable n : nat. Implicit Types p q : {poly_n R}. Definition npoly_enum : seq {poly_n R} := if n isn't n.+1 then [:: npoly0 _] else pmap insub [seq \poly_(i < n.+1) c (inord i) | c : (R ^ n.+1)%type]. Lemma npoly_enum_uniq : uniq npoly_enum. Proof. rewrite /npoly_enum; case: n=> [|k] //. rewrite pmap_sub_uniq // map_inj_uniq => [|f g eqfg]; rewrite ?enum_uniq //. apply/ffunP => /= i; have /(congr1 (fun p : {poly _} => p`_i)) := eqfg. by rewrite !coef_poly ltn_ord inord_val. Qed. Lemma mem_npoly_enum p : p \in npoly_enum. Proof. rewrite /npoly_enum; case: n => [|k] // in p *. case: p => [p sp] /=. by rewrite in_cons -val_eqE /= -size_poly_leq0 [size _ <= _]sp. rewrite mem_pmap_sub; apply/mapP. eexists [ffun i : 'I__ => p`_i]; first by rewrite mem_enum. apply/polyP => i; rewrite coef_poly. have [i_small|i_big] := ltnP; first by rewrite ffunE /= inordK. by rewrite nth_default // 1?(leq_trans _ i_big) // size_npoly. Qed. Lemma card_npoly : #|{poly_n R}| = (#|R| ^ n)%N. Proof. rewrite -(card_imset _ (can_inj (@npoly_rV_K _ _))) eq_cardT. by rewrite -cardT /= card_mx mul1n. by move=> v; apply/imsetP; exists (rVnpoly v); rewrite ?rVnpolyK //. Qed. End fin_npoly. Section Irreducible. Variable R : finIdomainType. Variable p : {poly R}. Definition irreducibleb := ((1 < size p) && [forall q : {poly_((size p).-1) R}, (Pdiv.Ring.rdvdp q p)%R ==> (size q <= 1)])%N. Lemma irreducibleP : reflect (irreducible_poly p) irreducibleb. Proof. rewrite /irreducibleb /irreducible_poly. apply: (iffP idP) => [/andP[sp /'forall_implyP /= Fp]|[sp Fpoly]]. have sp_gt0 : size p > 0 by case: size sp. have p_neq0 : p != 0 by rewrite -size_poly_eq0; case: size sp. split => // q sq_neq1 dvd_qp; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=. apply: contraNT sq_neq1; rewrite -ltnNge => sq_lt_sp. have q_small: (size q <= (size p).-1)%N by rewrite -ltnS prednK. rewrite Pdiv.Idomain.dvdpE in dvd_qp. have /= := Fp (NPoly q_small) dvd_qp. rewrite leq_eqVlt ltnS => /orP[//|]; rewrite size_poly_leq0 => /eqP q_eq0. by rewrite -Pdiv.Idomain.dvdpE q_eq0 dvd0p (negPf p_neq0) in dvd_qp. have sp_gt0 : size p > 0 by case: size sp. rewrite sp /=; apply/'forall_implyP => /= q. rewrite -Pdiv.Idomain.dvdpE=> dvd_qp. have [/eqP->//|/Fpoly/(_ dvd_qp)/eqp_size sq_eq_sp] := boolP (size q == 1%N). by have := size_npoly q; rewrite sq_eq_sp -ltnS prednK ?ltnn. Qed. End Irreducible. Section Vspace. Variable (K : fieldType) (n : nat). Lemma dim_polyn : \dim (fullv : {vspace {poly_n K}}) = n. Proof. by rewrite [LHS]mxrank_gen mxrank1. Qed. Definition npolyX : n.-tuple {poly_n K} := [tuple npolyp n 'X^i | i < n]. Notation "''nX^' i" := (tnth npolyX i). Lemma npolyXE (i : 'I_n) : 'nX^i = 'X^i :> {poly _}. Proof. by rewrite tnth_map tnth_ord_tuple npolypK // size_polyXn. Qed. Lemma nth_npolyX (i : 'I_n) : npolyX`_i = 'nX^i. Proof. by rewrite -tnth_nth. Qed. Lemma npolyX_free : free npolyX. Proof. apply/freeP=> u /= sum_uX_eq0 i; have /npolyP /(_ i) := sum_uX_eq0. rewrite (@big_morph _ _ _ 0%R +%R) // coef_sum coef0. rewrite (bigD1 i) ?big1 /= ?addr0 ?coefZ ?(nth_map 0%N) ?size_iota //. by rewrite nth_npolyX npolyXE coefXn eqxx mulr1. move=> j; rewrite -val_eqE /= => neq_ji. by rewrite nth_npolyX npolyXE coefZ coefXn eq_sym (negPf neq_ji) mulr0. Qed. Lemma npolyX_full : basis_of fullv npolyX. Proof. by rewrite basisEfree npolyX_free subvf size_map size_enum_ord dim_polyn /=. Qed. Lemma npolyX_coords (p : {poly_n K}) i : coord npolyX i p = p`_i. Proof. rewrite [p in RHS](coord_basis npolyX_full) ?memvf // coefn_sum. rewrite (bigD1 i) //= coefZ nth_npolyX npolyXE coefXn eqxx mulr1 big1 ?addr0//. move=> j; rewrite -val_eqE => /= neq_ji. by rewrite coefZ nth_npolyX npolyXE coefXn eq_sym (negPf neq_ji) mulr0. Qed. Lemma npolyX_gen (p : {poly K}) : (size p <= n)%N -> p = \sum_(i < n) p`_i *: 'nX^i. Proof. move=> sp; rewrite -[p](@npolypK _ n) //. rewrite [npolyp _ _ in LHS](coord_basis npolyX_full) ?memvf //. rewrite (@big_morph _ _ _ 0%R +%R) // !raddf_sum. by apply: eq_bigr=> i _; rewrite npolyX_coords //= nth_npolyX npolyXE. Qed. Section lagrange. Variables (x : nat -> K). Notation lagrange_def := (fun i :'I_n => let k := i in let p := \prod_(j < n | j != k) ('X - (x j)%:P) in (p.[x k]^-1)%:P * p). Fact lagrange_key : unit. Proof. exact: tt. Qed. Definition lagrange := locked_with lagrange_key [tuple npolyp n (lagrange_def i) | i < n]. Notation lagrange_ := (tnth lagrange). Hypothesis n_gt0 : (0 < n)%N. Hypothesis x_inj : injective x. Let lagrange_def_sample (i j : 'I_n) : (lagrange_def i).[x j] = (i == j)%:R. Proof. clear n_gt0; rewrite hornerM hornerC; set p := (\prod_(_ < _ | _) _). have [<-|neq_ij] /= := altP eqP. rewrite mulVf // horner_prod; apply/prodf_neq0 => k neq_ki. by rewrite hornerXsubC subr_eq0 inj_eq // eq_sym. rewrite [X in _ * X]horner_prod (bigD1 j) 1?eq_sym //=. by rewrite hornerXsubC subrr mul0r mulr0. Qed. Let size_lagrange_def i : size (lagrange_def i) = n. Proof. rewrite size_Cmul; last first. suff : (lagrange_def i).[x i] != 0. by rewrite hornerE mulf_eq0 => /norP []. by rewrite lagrange_def_sample ?eqxx ?oner_eq0. rewrite size_prod /=; last first. by move=> j neq_ji; rewrite polyXsubC_eq0. rewrite (eq_bigr (fun=> (2 * 1)%N)); last first. by move=> j neq_ji; rewrite size_XsubC. rewrite -big_distrr /= sum1_card cardC1 card_ord /=. by case: (n) {i} n_gt0 => ?; rewrite mul2n -addnn -addSn addnK. Qed. Lemma lagrangeE i : lagrange_ i = lagrange_def i :> {poly _}. Proof. rewrite [lagrange]unlock tnth_map. by rewrite [val _]npolypK tnth_ord_tuple // size_lagrange_def. Qed. Lemma nth_lagrange (i : 'I_n) : lagrange`_i = lagrange_ i. Proof. by rewrite -tnth_nth. Qed. Lemma size_lagrange_ i : size (lagrange_ i) = n. Proof. by rewrite lagrangeE size_lagrange_def. Qed. Lemma size_lagrange : size lagrange = n. Proof. by rewrite size_tuple. Qed. Lemma lagrange_sample (i j : 'I_n) : (lagrange_ i).[x j] = (i == j)%:R. Proof. by rewrite lagrangeE lagrange_def_sample. Qed. Lemma lagrange_free : free lagrange. Proof. apply/freeP=> lambda eq_l i. have /(congr1 (fun p : {poly__ _} => p.[x i])) := eq_l. rewrite (@big_morph _ _ _ 0%R +%R) // horner_sum horner0. rewrite (bigD1 i) // big1 => [|j /= /negPf ji] /=; by rewrite ?hornerE nth_lagrange lagrange_sample ?eqxx ?ji ?mulr1 ?mulr0. Qed. Lemma lagrange_full : basis_of fullv lagrange. Proof. by rewrite basisEfree lagrange_free subvf size_lagrange dim_polyn /=. Qed. Lemma lagrange_coords (p : {poly_n K}) i : coord lagrange i p = p.[x i]. Proof. rewrite [p in RHS](coord_basis lagrange_full) ?memvf //. rewrite (@big_morph _ _ _ 0%R +%R) // horner_sum. rewrite (bigD1 i) // big1 => [|j /= /negPf ji] /=; by rewrite ?hornerE nth_lagrange lagrange_sample ?eqxx ?ji ?mulr1 ?mulr0. Qed. Lemma lagrange_gen (p : {poly K}) : (size p <= n)%N -> p = \sum_(i < n) p.[x i]%:P * lagrange_ i. Proof. move=> sp; rewrite -[p](@npolypK _ n) //. rewrite [npolyp _ _ in LHS](coord_basis lagrange_full) ?memvf //. rewrite (@big_morph _ _ _ 0%R +%R) //; apply: eq_bigr=> i _. by rewrite lagrange_coords mul_polyC nth_lagrange. Qed. End lagrange. End Vspace. Notation "''nX^' i" := (tnth (npolyX _) i) : ring_scope. Notation "x .-lagrange" := (lagrange x) : ring_scope. Notation "x .-lagrange_" := (tnth x.-lagrange) : ring_scope. Section Qpoly. Variable R : nzRingType. Variable h : {poly R}. Definition mk_monic := if (1 < size h)%N && (h \is monic) then h else 'X. Definition qpoly := {poly_(size mk_monic).-1 R}. End Qpoly. Notation "{ 'poly' '%/' p }" := (qpoly p) : type_scope. Section QpolyProp. Variable R : nzRingType. Variable h : {poly R}. Lemma monic_mk_monic : (mk_monic h) \is monic. Proof. rewrite /mk_monic; case: leqP=> [_|/=]; first by apply: monicX. by case E : (h \is monic) => [->//|] => _; apply: monicX. Qed. Lemma size_mk_monic_gt1 : (1 < size (mk_monic h))%N. Proof. by rewrite !fun_if size_polyX; case: leqP => //=; rewrite if_same. Qed. Lemma size_mk_monic_gt0 : (0 < size (mk_monic h))%N. Proof. by rewrite (leq_trans _ size_mk_monic_gt1). Qed. Lemma mk_monic_neq0 : mk_monic h != 0. Proof. by rewrite -size_poly_gt0 size_mk_monic_gt0. Qed. Lemma size_mk_monic (p : {poly %/ h}) : size p < size (mk_monic h). Proof. have: (p : {poly R}) \is a poly_of_size (size (mk_monic h)).-1 by case: p. by rewrite qualifE/= -ltnS prednK // size_mk_monic_gt0. Qed. (* standard inject *) Lemma poly_of_size_mod p : rmodp p (mk_monic h) \is a poly_of_size (size (mk_monic h)).-1. Proof. rewrite qualifE/= -ltnS prednK ?size_mk_monic_gt0 //. by apply: ltn_rmodpN0; rewrite mk_monic_neq0. Qed. Definition in_qpoly p : {poly %/ h} := NPoly (poly_of_size_mod p). Lemma in_qpoly_small (p : {poly R}) : size p < size (mk_monic h) -> in_qpoly p = p :> {poly R}. Proof. exact: rmodp_small. Qed. Lemma in_qpoly0 : in_qpoly 0 = 0. Proof. by apply/val_eqP; rewrite /= rmod0p. Qed. Lemma in_qpolyD p q : in_qpoly (p + q) = in_qpoly p + in_qpoly q. Proof. by apply/val_eqP=> /=; rewrite rmodpD ?monic_mk_monic. Qed. Lemma in_qpolyZ a p : in_qpoly (a *: p) = a *: in_qpoly p. Proof. apply/val_eqP=> /=; rewrite rmodpZ ?monic_mk_monic //. Qed. Fact in_qpoly_is_linear : linear in_qpoly. Proof. by move=> k p q; rewrite in_qpolyD in_qpolyZ. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly_(size (mk_monic h)).-1 R} _ in_qpoly (GRing.semilinear_linear in_qpoly_is_linear). Lemma qpolyC_proof k : (k%:P : {poly R}) \is a poly_of_size (size (mk_monic h)).-1. Proof. rewrite qualifE/= -ltnS size_polyC prednK ?size_mk_monic_gt0 //. by rewrite (leq_ltn_trans _ size_mk_monic_gt1) //; case: eqP. Qed. Definition qpolyC k : {poly %/ h} := NPoly (qpolyC_proof k). Lemma qpolyCE k : qpolyC k = k%:P :> {poly R}. Proof. by []. Qed. Lemma qpolyC0 : qpolyC 0 = 0. Proof. by apply/val_eqP/eqP. Qed. Definition qpoly1 := qpolyC 1. Definition qpoly_mul (q1 q2 : {poly %/ h}) : {poly %/ h} := in_qpoly ((q1 : {poly R}) * q2). Lemma qpoly_mul1z : left_id qpoly1 qpoly_mul. Proof. by move=> x; apply: val_inj; rewrite /= mul1r rmodp_small // size_mk_monic. Qed. Lemma qpoly_mulz1 : right_id qpoly1 qpoly_mul. Proof. by move=> x; apply: val_inj; rewrite /= mulr1 rmodp_small // size_mk_monic. Qed. Lemma qpoly_nontrivial : qpoly1 != 0. Proof. by apply/eqP/val_eqP; rewrite /= oner_eq0. Qed. Definition qpolyX := in_qpoly 'X. Notation "'qX" := qpolyX. Lemma qpolyXE : 2 < size h -> h \is monic -> 'qX = 'X :> {poly R}. Proof. move=> sh_gt2 h_mo. by rewrite in_qpoly_small // size_polyX /mk_monic ifT // (ltn_trans _ sh_gt2). Qed. End QpolyProp. Notation "'qX" := (qpolyX _) : ring_scope. Lemma mk_monic_X (R : nzRingType) : mk_monic 'X = 'X :> {poly R}. Proof. by rewrite /mk_monic size_polyX monicX. Qed. Lemma mk_monic_Xn (R : nzRingType) n : mk_monic 'X^n = 'X^(n.-1.+1) :> {poly R}. Proof. by case: n => [|n]; rewrite /mk_monic size_polyXn monicXn /= ?expr1. Qed. Lemma card_qpoly (R : finNzRingType) (h : {poly R}): #|{poly %/ h}| = #|R| ^ (size (mk_monic h)).-1. Proof. by rewrite card_npoly. Qed. Lemma card_monic_qpoly (R : finNzRingType) (h : {poly R}): 1 < size h -> h \is monic -> #|{poly %/ h}| = #|R| ^ (size h).-1. Proof. by move=> sh_gt1 hM; rewrite card_qpoly /mk_monic sh_gt1 hM. Qed. Section QRing. Variable A : comNzRingType. Variable h : {poly A}. (* Ring operations *) Lemma qpoly_mulC : commutative (@qpoly_mul A h). Proof. by move=> p q; apply: val_inj; rewrite /= mulrC. Qed. Lemma qpoly_mulA : associative (@qpoly_mul A h). Proof. have rPM := monic_mk_monic h; move=> p q r; apply: val_inj. by rewrite /= rmodp_mulml // rmodp_mulmr // mulrA. Qed. Lemma qpoly_mul_addr : right_distributive (@qpoly_mul A h) +%R. Proof. have rPM := monic_mk_monic h; move=> p q r; apply: val_inj. by rewrite /= !(mulrDr, rmodp_mulmr, rmodpD). Qed. Lemma qpoly_mul_addl : left_distributive (@qpoly_mul A h) +%R. Proof. by move=> p q r; rewrite -!(qpoly_mulC r) qpoly_mul_addr. Qed. HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build {poly__ A} qpoly_mulA qpoly_mulC (@qpoly_mul1z _ h) qpoly_mul_addl (@qpoly_nontrivial _ h). HB.instance Definition _ := GRing.ComNzRing.on {poly %/ h}. Lemma in_qpoly1 : in_qpoly h 1 = 1. Proof. apply/val_eqP/eqP/in_qpoly_small. by rewrite size_polyC oner_eq0 /= size_mk_monic_gt1. Qed. Lemma in_qpolyM q1 q2 : in_qpoly h (q1 * q2) = in_qpoly h q1 * in_qpoly h q2. Proof. apply/val_eqP => /=. by rewrite rmodp_mulml ?rmodp_mulmr // monic_mk_monic. Qed. Fact in_qpoly_monoid_morphism : monoid_morphism (in_qpoly h). Proof. by split; [ apply: in_qpoly1 | apply: in_qpolyM]. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `in_qpoly_is_monoid_morphism` instead")] Definition in_qpoly_is_multiplicative := (fun g => (g.2,g.1)) in_qpoly_monoid_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly A} {poly %/ h} (in_qpoly h) in_qpoly_monoid_morphism. Lemma poly_of_qpoly_sum I (r : seq I) (P1 : pred I) (F : I -> {poly %/ h}) : ((\sum_(i <- r | P1 i) F i) = \sum_(p <- r | P1 p) ((F p) : {poly A}) :> {poly A})%R. Proof. by elim/big_rec2: _ => // i p q IH <-. Qed. Lemma poly_of_qpolyD (p q : {poly %/ h}) : p + q= (p : {poly A}) + q :> {poly A}. Proof. by []. Qed. Lemma qpolyC_natr p : (p%:R : {poly %/ h}) = p%:R :> {poly A}. Proof. by elim: p => //= p IH; rewrite !mulrS poly_of_qpolyD IH. Qed. Lemma pchar_qpoly : [pchar {poly %/ h}] =i [pchar A]. Proof. move=> p; rewrite !inE; congr (_ && _). apply/eqP/eqP=> [/(congr1 val) /=|pE]; last first. by apply: val_inj => //=; rewrite qpolyC_natr /= -polyC_natr pE. rewrite !qpolyC_natr -!polyC_natr => /(congr1 val) /=. by rewrite polyseqC polyseq0; case: eqP. Qed. Lemma poly_of_qpolyM (p q : {poly %/ h}) : p * q = rmodp ((p : {poly A}) * q) (mk_monic h) :> {poly A}. Proof. by []. Qed. Lemma poly_of_qpolyX (p : {poly %/ h}) n : p ^+ n = rmodp ((p : {poly A}) ^+ n) (mk_monic h) :> {poly A}. Proof. have HhQ := monic_mk_monic h. elim: n => //= [|n IH]. rewrite rmodp_small // size_polyC ?(leq_ltn_trans _ (size_mk_monic_gt1 _)) //. by case: eqP. by rewrite exprS /= IH // rmodp_mulmr // -exprS. Qed. Lemma qpolyCN (a : A) : qpolyC h (- a) = -(qpolyC h a). Proof. apply: val_inj; rewrite /= raddfN //= raddfN. Qed. Lemma qpolyCD : {morph (qpolyC h) : a b / a + b >-> a + b}%R. Proof. by move=> a b; apply/val_eqP/eqP=> /=; rewrite -!raddfD. Qed. Lemma qpolyCM : {morph (qpolyC h) : a b / a * b >-> a * b}%R. Proof. move=> a b; apply/val_eqP/eqP=> /=; rewrite -polyCM rmodp_small //=. have := qpolyC_proof h (a * b). by rewrite qualifE/= -ltnS prednK // size_mk_monic_gt0. Qed. Lemma qpolyC_is_zmod_morphism : zmod_morphism (qpolyC h). Proof. by move=> x y; rewrite qpolyCD qpolyCN. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `qpolyC_is_zmod_morphism` instead")] Definition qpolyC_is_additive := qpolyC_is_zmod_morphism. Lemma qpolyC_is_monoid_morphism : monoid_morphism (qpolyC h). Proof. by split=> // x y; rewrite qpolyCM. Qed. #[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0", note="use `qpolyC_is_monoid_morphism` instead")] Definition qpolyC_is_multiplicative := (fun g => (g.2,g.1)) qpolyC_is_monoid_morphism. HB.instance Definition _ := GRing.isZmodMorphism.Build A {poly %/ h} (qpolyC h) qpolyC_is_zmod_morphism. HB.instance Definition _ := GRing.isMonoidMorphism.Build A {poly %/ h} (qpolyC h) qpolyC_is_monoid_morphism. Definition qpoly_scale k (p : {poly %/ h}) : {poly %/ h} := (k *: p)%R. Fact qpoly_scaleA a b p : qpoly_scale a (qpoly_scale b p) = qpoly_scale (a * b) p. Proof. by apply/val_eqP; rewrite /= scalerA. Qed. Fact qpoly_scale1l : left_id 1%R qpoly_scale. Proof. by move=> p; apply/val_eqP; rewrite /= scale1r. Qed. Fact qpoly_scaleDr a : {morph qpoly_scale a : p q / (p + q)%R}. Proof. by move=> p q; apply/val_eqP; rewrite /= scalerDr. Qed. Fact qpoly_scaleDl p : {morph qpoly_scale^~ p : a b / a + b}%R. Proof. by move=> a b; apply/val_eqP; rewrite /= scalerDl. Qed. Fact qpoly_scaleAl a p q : qpoly_scale a (p * q) = (qpoly_scale a p * q). Proof. by apply/val_eqP; rewrite /= -scalerAl rmodpZ // monic_mk_monic. Qed. Fact qpoly_scaleAr a p q : qpoly_scale a (p * q) = p * (qpoly_scale a q). Proof. by apply/val_eqP; rewrite /= -scalerAr rmodpZ // monic_mk_monic. Qed. HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build A {poly__ A} qpoly_scaleAl. HB.instance Definition _ := GRing.Lalgebra.on {poly %/ h}. HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build A {poly__ A} qpoly_scaleAr. HB.instance Definition _ := GRing.Algebra.on {poly %/ h}. Lemma poly_of_qpolyZ (p : {poly %/ h}) a : a *: p = a *: (p : {poly A}) :> {poly A}. Proof. by []. Qed. End QRing. #[deprecated(since="mathcomp 2.4.0", note="Use pchar_qpoly instead.")] Notation char_qpoly := (pchar_qpoly) (only parsing). Section Field. Variable R : fieldType. Variable h : {poly R}. Local Notation hQ := (mk_monic h). Definition qpoly_inv (p : {poly %/ h}) := if coprimep hQ p then let v : {poly %/ h} := in_qpoly h (egcdp hQ p).2 in ((lead_coef (v * p)) ^-1 *: v) else p. (* Ugly *) Lemma qpoly_mulVz (p : {poly %/ h}) : coprimep hQ p -> (qpoly_inv p * p = 1)%R. Proof. have hQM := monic_mk_monic h. move=> hCp; apply: val_inj; rewrite /qpoly_inv /in_qpoly hCp /=. have p_neq0 : p != 0%R. apply/eqP=> pZ; move: hCp; rewrite pZ. rewrite coprimep0 -size_poly_eq1. by case: size (size_mk_monic_gt1 h) => [|[]]. have F : (egcdp hQ p).1 * hQ + (egcdp hQ p).2 * p %= 1. apply: eqp_trans _ (_ : gcdp hQ p %= _). rewrite eqp_sym. by case: (egcdpP (mk_monic_neq0 h) p_neq0). by rewrite -size_poly_eq1. rewrite rmodp_mulml // -scalerAl rmodpZ // rmodp_mulml //. rewrite -[rmodp]/Pdiv.Ring.rmodp -!Pdiv.IdomainMonic.modpE //. have := eqp_modpl hQ F. rewrite modpD // modp_mull add0r // . rewrite [(1 %% _)%R]modp_small => // [egcdE|]; last first. by rewrite size_polyC oner_eq0 size_mk_monic_gt1. rewrite {2}(eqpfP egcdE) lead_coefC divr1 alg_polyC scale_polyC mulVf //. rewrite lead_coef_eq0. apply/eqP => egcdZ. by move: egcdE; rewrite -size_poly_eq1 egcdZ size_polyC eq_sym eqxx. Qed. Lemma qpoly_mulzV (p : {poly %/ h}) : coprimep hQ p -> (p * (qpoly_inv p) = 1)%R. Proof. by move=> hCp; rewrite /= mulrC qpoly_mulVz. Qed. Lemma qpoly_intro_unit (p q : {poly %/ h}) : (q * p = 1)%R -> coprimep hQ p. Proof. have hQM := monic_mk_monic h. case; rewrite -[rmodp]/Pdiv.Ring.rmodp -!Pdiv.IdomainMonic.modpE // => qp1. have:= coprimep1 hQ. rewrite -coprimep_modr -[1%R]qp1 !coprimep_modr coprimepMr; by case/andP. Qed. Lemma qpoly_inv_out (p : {poly %/ h}) : ~~ coprimep hQ p -> qpoly_inv p = p. Proof. by rewrite /qpoly_inv => /negPf->. Qed. HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build {poly__ _} qpoly_mulVz qpoly_intro_unit qpoly_inv_out. HB.instance Definition _ := GRing.ComUnitAlgebra.on {poly %/ h}. Lemma irreducible_poly_coprime (A : idomainType) (p q : {poly A}) : irreducible_poly p -> coprimep p q = ~~(p %| q)%R. Proof. case => H1 H2; apply/coprimepP/negP. move=> sPq H. by have := sPq p (dvdpp _) H; rewrite -size_poly_eq1; case: size H1 => [|[]]. move=> pNDq d dDp dPq. rewrite -size_poly_eq1; case: eqP => // /eqP /(H2 _) => /(_ dDp) dEp. by case: pNDq; rewrite -(eqp_dvdl _ dEp). Qed. End Field.
CompatibleSheafification.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.CompatiblePlus import Mathlib.CategoryTheory.Sites.ConcreteSheafification /-! In this file, we prove that sheafification is compatible with functors which preserve the correct limits and colimits. -/ namespace CategoryTheory.GrothendieckTopology open CategoryTheory open CategoryTheory.Limits CategoryTheory.Functor open Opposite universe w₁ w₂ v u variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C) variable {D : Type w₁} [Category.{max v u} D] variable {E : Type w₂} [Category.{max v u} E] variable (F : D ⥤ E) variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) D] variable [∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) E] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D] variable [∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ E] variable [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] variable [∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] variable (P : Cᵒᵖ ⥤ D) /-- The isomorphism between the sheafification of `P` composed with `F` and the sheafification of `P ⋙ F`. Use the lemmas `whisker_right_to_sheafify_sheafify_comp_iso_hom`, `to_sheafify_comp_sheafify_comp_iso_inv` and `sheafify_comp_iso_inv_eq_sheafify_lift` to reduce the components of this isomorphisms to a state that can be handled using the universal property of sheafification. -/ noncomputable def sheafifyCompIso : J.sheafify P ⋙ F ≅ J.sheafify (P ⋙ F) := J.plusCompIso _ _ ≪≫ (J.plusFunctor _).mapIso (J.plusCompIso _ _) /-- The isomorphism between the sheafification of `P` composed with `F` and the sheafification of `P ⋙ F`, functorially in `F`. -/ noncomputable def sheafificationWhiskerLeftIso (P : Cᵒᵖ ⥤ D) [∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] : (whiskeringLeft _ _ E).obj (J.sheafify P) ≅ (whiskeringLeft _ _ _).obj P ⋙ J.sheafification E := by refine J.plusFunctorWhiskerLeftIso _ ≪≫ ?_ ≪≫ associator _ _ _ refine isoWhiskerRight ?_ _ exact J.plusFunctorWhiskerLeftIso _ @[simp] theorem sheafificationWhiskerLeftIso_hom_app (P : Cᵒᵖ ⥤ D) (F : D ⥤ E) [∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] : (sheafificationWhiskerLeftIso J P).hom.app F = (J.sheafifyCompIso F P).hom := by dsimp [sheafificationWhiskerLeftIso, sheafifyCompIso] rw [Category.comp_id] @[simp] theorem sheafificationWhiskerLeftIso_inv_app (P : Cᵒᵖ ⥤ D) (F : D ⥤ E) [∀ (F : D ⥤ E) (X : C), PreservesColimitsOfShape (J.Cover X)ᵒᵖ F] [∀ (F : D ⥤ E) (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F] : (sheafificationWhiskerLeftIso J P).inv.app F = (J.sheafifyCompIso F P).inv := by dsimp [sheafificationWhiskerLeftIso, sheafifyCompIso] erw [Category.id_comp] /-- The isomorphism between the sheafification of `P` composed with `F` and the sheafification of `P ⋙ F`, functorially in `P`. -/ noncomputable def sheafificationWhiskerRightIso : J.sheafification D ⋙ (whiskeringRight _ _ _).obj F ≅ (whiskeringRight _ _ _).obj F ⋙ J.sheafification E := by refine associator _ _ _ ≪≫ ?_ refine isoWhiskerLeft (J.plusFunctor D) (J.plusFunctorWhiskerRightIso _) ≪≫ ?_ refine ?_ ≪≫ associator _ _ _ refine (associator _ _ _).symm ≪≫ ?_ exact isoWhiskerRight (J.plusFunctorWhiskerRightIso _) (J.plusFunctor E) @[simp] theorem sheafificationWhiskerRightIso_hom_app : (J.sheafificationWhiskerRightIso F).hom.app P = (J.sheafifyCompIso F P).hom := by dsimp [sheafificationWhiskerRightIso, sheafifyCompIso] simp only [Category.id_comp, Category.comp_id] erw [Category.id_comp] @[simp] theorem sheafificationWhiskerRightIso_inv_app : (J.sheafificationWhiskerRightIso F).inv.app P = (J.sheafifyCompIso F P).inv := by dsimp [sheafificationWhiskerRightIso, sheafifyCompIso] simp only [Category.comp_id] erw [Category.id_comp] @[simp, reassoc] theorem whiskerRight_toSheafify_sheafifyCompIso_hom : whiskerRight (J.toSheafify _) _ ≫ (J.sheafifyCompIso F P).hom = J.toSheafify _ := by dsimp [sheafifyCompIso] erw [whiskerRight_comp, Category.assoc] slice_lhs 2 3 => rw [plusCompIso_whiskerRight] rw [Category.assoc, ← J.plusMap_comp, whiskerRight_toPlus_comp_plusCompIso_hom, ← Category.assoc, whiskerRight_toPlus_comp_plusCompIso_hom] rfl @[simp, reassoc] theorem toSheafify_comp_sheafifyCompIso_inv : J.toSheafify _ ≫ (J.sheafifyCompIso F P).inv = whiskerRight (J.toSheafify _) _ := by rw [Iso.comp_inv_eq]; simp section -- We will sheafify `D`-valued presheaves in this section. variable {FD : D → D → Type*} {CD : D → Type (max v u)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] variable [ConcreteCategory.{max v u} D FD] [PreservesLimits (forget D)] [∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)] [(forget D).ReflectsIsomorphisms] @[simp] theorem sheafifyCompIso_inv_eq_sheafifyLift : (J.sheafifyCompIso F P).inv = J.sheafifyLift (whiskerRight (J.toSheafify P) F) (HasSheafCompose.isSheaf _ ((J.sheafify_isSheaf _))) := by apply J.sheafifyLift_unique rw [Iso.comp_inv_eq] simp end end CategoryTheory.GrothendieckTopology
Convolution.lean
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.MeasureTheory.Measure.MeasureSpace import Mathlib.MeasureTheory.Measure.Prod /-! # The multiplicative and additive convolution of measures In this file we define and prove properties about the convolutions of two measures. ## Main definitions * `MeasureTheory.Measure.mconv`: The multiplicative convolution of two measures: the map of `*` under the product measure. * `MeasureTheory.Measure.conv`: The additive convolution of two measures: the map of `+` under the product measure. -/ namespace MeasureTheory namespace Measure open scoped ENNReal variable {M : Type*} [Monoid M] [MeasurableSpace M] /-- Multiplicative convolution of measures. -/ @[to_additive /-- Additive convolution of measures. -/] noncomputable def mconv (μ : Measure M) (ν : Measure M) : Measure M := Measure.map (fun x : M × M ↦ x.1 * x.2) (μ.prod ν) /-- Scoped notation for the multiplicative convolution of measures. -/ scoped[MeasureTheory] infixr:80 " ∗ₘ " => MeasureTheory.Measure.mconv /-- Scoped notation for the additive convolution of measures. -/ scoped[MeasureTheory] infixr:80 " ∗ " => MeasureTheory.Measure.conv @[to_additive] theorem lintegral_mconv_eq_lintegral_prod [MeasurableMul₂ M] {μ ν : Measure M} {f : M → ℝ≥0∞} (hf : Measurable f) : ∫⁻ z, f z ∂(μ ∗ₘ ν) = ∫⁻ z, f (z.1 * z.2) ∂(μ.prod ν) := by rw [mconv, lintegral_map hf measurable_mul] @[to_additive] theorem lintegral_mconv [MeasurableMul₂ M] {μ ν : Measure M} [SFinite ν] {f : M → ℝ≥0∞} (hf : Measurable f) : ∫⁻ z, f z ∂(μ ∗ₘ ν) = ∫⁻ x, ∫⁻ y, f (x * y) ∂ν ∂μ := by rw [lintegral_mconv_eq_lintegral_prod hf, lintegral_prod _ (by fun_prop)] @[to_additive] lemma dirac_mconv [MeasurableMul₂ M] (x : M) (μ : Measure M) [SFinite μ] : (Measure.dirac x) ∗ₘ μ = μ.map (fun y ↦ x * y) := by unfold mconv rw [Measure.dirac_prod, map_map (by fun_prop) (by fun_prop)] simp [Function.comp_def] @[to_additive] lemma mconv_dirac [MeasurableMul₂ M] (μ : Measure M) [SFinite μ] (x : M) : μ ∗ₘ (Measure.dirac x) = μ.map (fun y ↦ y * x) := by unfold mconv rw [Measure.prod_dirac, map_map (by fun_prop) (by fun_prop)] simp [Function.comp_def] /-- Convolution of the dirac measure at 1 with a measure μ returns μ. -/ @[to_additive (attr := simp) /-- Convolution of the dirac measure at 0 with a measure μ returns μ. -/] theorem dirac_one_mconv [MeasurableMul₂ M] (μ : Measure M) [SFinite μ] : (Measure.dirac 1) ∗ₘ μ = μ := by simp [dirac_mconv] /-- Convolution of a measure μ with the dirac measure at 1 returns μ. -/ @[to_additive (attr := simp) /-- Convolution of a measure μ with the dirac measure at 0 returns μ. -/] theorem mconv_dirac_one [MeasurableMul₂ M] (μ : Measure M) [SFinite μ] : μ ∗ₘ (Measure.dirac 1) = μ := by simp [mconv_dirac] /-- Convolution of the zero measure with a measure μ returns the zero measure. -/ @[to_additive (attr := simp) /-- Convolution of the zero measure with a measure μ returns the zero measure. -/] theorem zero_mconv (μ : Measure M) : (0 : Measure M) ∗ₘ μ = (0 : Measure M) := by unfold mconv simp /-- Convolution of a measure μ with the zero measure returns the zero measure. -/ @[to_additive (attr := simp) /-- Convolution of a measure μ with the zero measure returns the zero measure. -/] theorem mconv_zero (μ : Measure M) : μ ∗ₘ (0 : Measure M) = (0 : Measure M) := by unfold mconv simp @[to_additive] theorem mconv_add [MeasurableMul₂ M] (μ : Measure M) (ν : Measure M) (ρ : Measure M) [SFinite μ] [SFinite ν] [SFinite ρ] : μ ∗ₘ (ν + ρ) = μ ∗ₘ ν + μ ∗ₘ ρ := by unfold mconv rw [prod_add, Measure.map_add] fun_prop @[to_additive] theorem add_mconv [MeasurableMul₂ M] (μ : Measure M) (ν : Measure M) (ρ : Measure M) [SFinite μ] [SFinite ν] [SFinite ρ] : (μ + ν) ∗ₘ ρ = μ ∗ₘ ρ + ν ∗ₘ ρ := by unfold mconv rw [add_prod, Measure.map_add] fun_prop /-- To get commutativity, we need the underlying multiplication to be commutative. -/ @[to_additive /-- To get commutativity, we need the underlying addition to be commutative. -/] theorem mconv_comm {M : Type*} [CommMonoid M] [MeasurableSpace M] [MeasurableMul₂ M] (μ : Measure M) (ν : Measure M) [SFinite μ] [SFinite ν] : μ ∗ₘ ν = ν ∗ₘ μ := by unfold mconv rw [← prod_swap, map_map (by fun_prop)] · simp [Function.comp_def, mul_comm] fun_prop /-- The convolution of s-finite measures is s-finite. -/ @[to_additive /-- The convolution of s-finite measures is s-finite. -/] instance sfinite_mconv_of_sfinite (μ : Measure M) (ν : Measure M) [SFinite μ] [SFinite ν] : SFinite (μ ∗ₘ ν) := inferInstanceAs <| SFinite ((μ.prod ν).map fun (x : M × M) ↦ x.1 * x.2) @[to_additive] instance finite_of_finite_mconv (μ : Measure M) (ν : Measure M) [IsFiniteMeasure μ] [IsFiniteMeasure ν] : IsFiniteMeasure (μ ∗ₘ ν) := by have h : (μ ∗ₘ ν) Set.univ < ⊤ := by unfold mconv exact IsFiniteMeasure.measure_univ_lt_top exact {measure_univ_lt_top := h} /-- Convolution is associative. -/ @[to_additive /-- Convolution is associative. -/] theorem mconv_assoc [MeasurableMul₂ M] (μ ν ρ : Measure M) [SFinite ν] [SFinite ρ] : (μ ∗ₘ ν) ∗ₘ ρ = μ ∗ₘ (ν ∗ₘ ρ) := by refine ext_of_lintegral _ fun f hf ↦ ?_ repeat rw [lintegral_mconv (by fun_prop)] refine lintegral_congr fun x ↦ ?_ rw [lintegral_mconv (by fun_prop)] repeat refine lintegral_congr fun x ↦ ?_ simp [mul_assoc] @[to_additive] instance probabilitymeasure_of_probabilitymeasures_mconv (μ : Measure M) (ν : Measure M) [MeasurableMul₂ M] [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] : IsProbabilityMeasure (μ ∗ₘ ν) := MeasureTheory.isProbabilityMeasure_map (by fun_prop) @[to_additive] lemma map_mconv_monoidHom {M M' : Type*} {mM : MeasurableSpace M} [Monoid M] [MeasurableMul₂ M] {mM' : MeasurableSpace M'} [Monoid M'] [MeasurableMul₂ M'] {μ ν : Measure M} [SFinite μ] [SFinite ν] (L : M →* M') (hL : Measurable L) : (μ ∗ₘ ν).map L = (μ.map L) ∗ₘ (ν.map L) := by unfold Measure.mconv rw [Measure.map_map (by fun_prop) (by fun_prop)] have : (L ∘ fun p : M × M ↦ p.1 * p.2) = (fun p : M' × M' ↦ p.1 * p.2) ∘ (Prod.map L L) := by ext; simp rw [this, ← Measure.map_map (by fun_prop) (by fun_prop), ← Measure.map_prod_map _ _ (by fun_prop) (by fun_prop)] lemma map_conv_continuousLinearMap {E F : Type*} [AddCommMonoid E] [AddCommMonoid F] [Module ℝ E] [Module ℝ F] [TopologicalSpace E] [TopologicalSpace F] {mE : MeasurableSpace E} [MeasurableAdd₂ E] {mF : MeasurableSpace F} [MeasurableAdd₂ F] [OpensMeasurableSpace E] [BorelSpace F] {μ ν : Measure E} [SFinite μ] [SFinite ν] (L : E →L[ℝ] F) : (μ ∗ ν).map L = (μ.map L) ∗ (ν.map L) := by suffices (μ ∗ ν).map (L : E →+ F) = (μ.map (L : E →+ F)) ∗ (ν.map (L : E →+ F)) by simpa rw [map_conv_addMonoidHom] rw [AddMonoidHom.coe_coe] fun_prop end Measure end MeasureTheory
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.
AlgebraMap.lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.Algebra.Prod import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.Algebra.Polynomial.Eval.Algebra import Mathlib.Algebra.Polynomial.Eval.Degree import Mathlib.Algebra.Polynomial.Monomial /-! # Theory of univariate polynomials We show that `A[X]` is an R-algebra when `A` is an R-algebra. We promote `eval₂` to an algebra hom in `aeval`. -/ assert_not_exists Ideal noncomputable section open Finset open Polynomial namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {A' B : Type*} {a b : R} {n : ℕ} section CommSemiring variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] variable {p q r : R[X]} /-- Note that this instance also provides `Algebra R R[X]`. -/ instance algebraOfAlgebra : Algebra R A[X] where smul_def' r p := toFinsupp_injective <| by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply] rw [toFinsupp_smul, toFinsupp_mul, toFinsupp_C] exact Algebra.smul_def' _ _ commutes' r p := toFinsupp_injective <| by dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply] simp_rw [toFinsupp_mul, toFinsupp_C] convert Algebra.commutes' r p.toFinsupp algebraMap := C.comp (algebraMap R A) @[simp] theorem algebraMap_apply (r : R) : algebraMap R A[X] r = C (algebraMap R A r) := rfl @[simp] theorem toFinsupp_algebraMap (r : R) : (algebraMap R A[X] r).toFinsupp = algebraMap R _ r := show toFinsupp (C (algebraMap _ _ r)) = _ by rw [toFinsupp_C] rfl theorem ofFinsupp_algebraMap (r : R) : (⟨algebraMap R _ r⟩ : A[X]) = algebraMap R A[X] r := toFinsupp_injective (toFinsupp_algebraMap _).symm /-- When we have `[CommSemiring R]`, the function `C` is the same as `algebraMap R R[X]`. (But note that `C` is defined when `R` is not necessarily commutative, in which case `algebraMap` is not available.) -/ theorem C_eq_algebraMap (r : R) : C r = algebraMap R R[X] r := rfl @[simp] theorem algebraMap_eq : algebraMap R R[X] = C := rfl /-- `Polynomial.C` as an `AlgHom`. -/ @[simps! apply] def CAlgHom : A →ₐ[R] A[X] where toRingHom := C commutes' _ := rfl /-- Extensionality lemma for algebra maps out of `A'[X]` over a smaller base ring than `A'` -/ @[ext 1100] theorem algHom_ext' {f g : A[X] →ₐ[R] B} (hC : f.comp CAlgHom = g.comp CAlgHom) (hX : f X = g X) : f = g := AlgHom.coe_ringHom_injective (ringHom_ext' (congr_arg AlgHom.toRingHom hC) hX) variable (R) in open AddMonoidAlgebra in /-- Algebra isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps!] def toFinsuppIsoAlg : R[X] ≃ₐ[R] R[ℕ] := { toFinsuppIso R with commutes' := fun r => by dsimp } instance subalgebraNontrivial [Nontrivial A] : Nontrivial (Subalgebra R A[X]) := ⟨⟨⊥, ⊤, by rw [Ne, SetLike.ext_iff, not_forall] refine ⟨X, ?_⟩ simp only [Algebra.mem_bot, not_exists, Set.mem_range, iff_true, Algebra.mem_top, algebraMap_apply] intro x rw [ext_iff, not_forall] refine ⟨1, ?_⟩ simp⟩⟩ @[simp] theorem algHom_eval₂_algebraMap {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] (p : R[X]) (f : A →ₐ[R] B) (a : A) : f (eval₂ (algebraMap R A) a p) = eval₂ (algebraMap R B) (f a) p := by simp only [eval₂_eq_sum, sum_def] simp only [map_sum, map_mul, map_pow, AlgHom.commutes] @[simp] theorem eval₂_algebraMap_X {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] (p : R[X]) (f : R[X] →ₐ[R] A) : eval₂ (algebraMap R A) (f X) p = f p := by conv_rhs => rw [← Polynomial.sum_C_mul_X_pow_eq p] simp only [eval₂_eq_sum, sum_def] simp only [map_sum, map_mul, map_pow] simp [Polynomial.C_eq_algebraMap] -- these used to be about `algebraMap ℤ R`, but now the simp-normal form is `Int.castRingHom R`. @[simp] theorem ringHom_eval₂_intCastRingHom {R S : Type*} [Ring R] [Ring S] (p : ℤ[X]) (f : R →+* S) (r : R) : f (eval₂ (Int.castRingHom R) r p) = eval₂ (Int.castRingHom S) (f r) p := algHom_eval₂_algebraMap p f.toIntAlgHom r @[simp] theorem eval₂_intCastRingHom_X {R : Type*} [Ring R] (p : ℤ[X]) (f : ℤ[X] →+* R) : eval₂ (Int.castRingHom R) (f X) p = f p := eval₂_algebraMap_X p f.toIntAlgHom /-- `Polynomial.eval₂` as an `AlgHom` for noncommutative algebras. This is `Polynomial.eval₂RingHom'` for `AlgHom`s. -/ @[simps!] def eval₂AlgHom' (f : A →ₐ[R] B) (b : B) (hf : ∀ a, Commute (f a) b) : A[X] →ₐ[R] B where toRingHom := eval₂RingHom' f b hf commutes' _ := (eval₂_C _ _).trans (f.commutes _) section Map /-- `Polynomial.map` as an `AlgHom` for noncommutative algebras. This is the algebra version of `Polynomial.mapRingHom`. -/ def mapAlgHom (f : A →ₐ[R] B) : Polynomial A →ₐ[R] Polynomial B where toRingHom := mapRingHom f.toRingHom commutes' := by simp @[simp] theorem coe_mapAlgHom (f : A →ₐ[R] B) : ⇑(mapAlgHom f) = map f := rfl @[simp] theorem mapAlgHom_id : mapAlgHom (AlgHom.id R A) = AlgHom.id R (Polynomial A) := AlgHom.ext fun _x => map_id @[simp] theorem mapAlgHom_coe_ringHom (f : A →ₐ[R] B) : ↑(mapAlgHom f : _ →ₐ[R] Polynomial B) = (mapRingHom ↑f : Polynomial A →+* Polynomial B) := rfl @[simp] theorem mapAlgHom_comp (C : Type*) [Semiring C] [Algebra R C] (f : B →ₐ[R] C) (g : A →ₐ[R] B) : (mapAlgHom f).comp (mapAlgHom g) = mapAlgHom (f.comp g) := by ext <;> simp theorem mapAlgHom_eq_eval₂AlgHom'_CAlgHom (f : A →ₐ[R] B) : mapAlgHom f = eval₂AlgHom' (CAlgHom.comp f) X (fun a => (commute_X (C (f a))).symm) := by apply AlgHom.ext intro x congr /-- If `A` and `B` are isomorphic as `R`-algebras, then so are their polynomial rings -/ def mapAlgEquiv (f : A ≃ₐ[R] B) : Polynomial A ≃ₐ[R] Polynomial B := AlgEquiv.ofAlgHom (mapAlgHom f.toAlgHom) (mapAlgHom f.symm.toAlgHom) (by simp) (by simp) @[simp] theorem coe_mapAlgEquiv (f : A ≃ₐ[R] B) : ⇑(mapAlgEquiv f) = map f := rfl @[simp] theorem mapAlgEquiv_id : mapAlgEquiv (@AlgEquiv.refl R A _ _ _) = AlgEquiv.refl := AlgEquiv.ext fun _x => map_id @[simp] theorem mapAlgEquiv_coe_ringHom (f : A ≃ₐ[R] B) : ↑(mapAlgEquiv f : _ ≃ₐ[R] Polynomial B) = (mapRingHom ↑f : Polynomial A →+* Polynomial B) := rfl @[simp] theorem mapAlgEquiv_toAlgHom (f : A ≃ₐ[R] B) : (mapAlgEquiv f : Polynomial A →ₐ[R] Polynomial B) = mapAlgHom f := rfl @[simp] theorem mapAlgEquiv_comp (C : Type*) [Semiring C] [Algebra R C] (f : A ≃ₐ[R] B) (g : B ≃ₐ[R] C) : (mapAlgEquiv f).trans (mapAlgEquiv g) = mapAlgEquiv (f.trans g) := by ext simp end Map end CommSemiring section aeval variable [CommSemiring R] [Semiring A] [CommSemiring A'] [Semiring B] variable [Algebra R A] [Algebra R B] variable {p q : R[X]} (x : A) /-- Given a valuation `x` of the variable in an `R`-algebra `A`, `aeval R A x` is the unique `R`-algebra homomorphism from `R[X]` to `A` sending `X` to `x`. This is a stronger variant of the linear map `Polynomial.leval`. -/ def aeval : R[X] →ₐ[R] A := eval₂AlgHom' (Algebra.ofId _ _) x (Algebra.commutes · _) /-- The map `R[X] → S[X]` as an algebra homomorphism. -/ def mapAlg (R : Type u) [CommSemiring R] (S : Type v) [Semiring S] [Algebra R S] : R[X] →ₐ[R] S[X] := @aeval _ S[X] _ _ _ (X : S[X]) @[ext 1200] theorem algHom_ext {f g : R[X] →ₐ[R] B} (hX : f X = g X) : f = g := algHom_ext' (Subsingleton.elim _ _) hX theorem aeval_def (p : R[X]) : aeval x p = eval₂ (algebraMap R A) x p := rfl @[simp] lemma eval_map_algebraMap (P : R[X]) (b : B) : (map (algebraMap R B) P).eval b = aeval b P := by rw [aeval_def, eval_map] /-- `mapAlg` is the morphism induced by `R → S`. -/ theorem mapAlg_eq_map (S : Type v) [Semiring S] [Algebra R S] (p : R[X]) : mapAlg R S p = map (algebraMap R S) p := by simp only [mapAlg, aeval_def, eval₂_eq_sum, map, algebraMap_apply, RingHom.coe_comp] ext; congr theorem aeval_zero : aeval x (0 : R[X]) = 0 := map_zero (aeval x) @[simp] theorem aeval_X : aeval x (X : R[X]) = x := eval₂_X _ x @[simp] theorem aeval_C (r : R) : aeval x (C r) = algebraMap R A r := eval₂_C _ x @[simp] theorem aeval_monomial {n : ℕ} {r : R} : aeval x (monomial n r) = algebraMap _ _ r * x ^ n := eval₂_monomial _ _ theorem aeval_X_pow {n : ℕ} : aeval x ((X : R[X]) ^ n) = x ^ n := eval₂_X_pow _ _ theorem aeval_add : aeval x (p + q) = aeval x p + aeval x q := map_add _ _ _ theorem aeval_one : aeval x (1 : R[X]) = 1 := map_one _ theorem aeval_natCast (n : ℕ) : aeval x (n : R[X]) = n := map_natCast _ _ theorem aeval_mul : aeval x (p * q) = aeval x p * aeval x q := map_mul _ _ _ theorem comp_eq_aeval : p.comp q = aeval q p := rfl theorem aeval_comp {A : Type*} [Semiring A] [Algebra R A] (x : A) : aeval x (p.comp q) = aeval (aeval x q) p := eval₂_comp' x p q section IsScalarTower variable {A : Type*} (B C : Type*) [CommSemiring A] [CommSemiring B] [Semiring C] [Algebra A B] [Algebra A C] [Algebra B C] [IsScalarTower A B C] theorem mapAlg_comp (p : A[X]) : (mapAlg A C) p = (mapAlg B C) (mapAlg A B p) := by simp [mapAlg_eq_map, map_map, IsScalarTower.algebraMap_eq A B C] theorem coeff_zero_of_isScalarTower (p : A[X]) : (algebraMap B C) ((algebraMap A B) (p.coeff 0)) = (mapAlg A C p).coeff 0 := by have h : algebraMap A C = (algebraMap B C).comp (algebraMap A B) := by ext a simp [Algebra.algebraMap_eq_smul_one, RingHom.coe_comp, Function.comp_apply] rw [mapAlg_eq_map, coeff_map, h, RingHom.comp_apply] end IsScalarTower /-- Two polynomials `p` and `q` such that `p(q(X))=X` and `q(p(X))=X` induces an automorphism of the polynomial algebra. -/ @[simps!] def algEquivOfCompEqX (p q : R[X]) (hpq : p.comp q = X) (hqp : q.comp p = X) : R[X] ≃ₐ[R] R[X] := by refine AlgEquiv.ofAlgHom (aeval p) (aeval q) ?_ ?_ <;> exact AlgHom.ext fun _ ↦ by simp [← comp_eq_aeval, comp_assoc, hpq, hqp] @[simp] theorem algEquivOfCompEqX_eq_iff (p q p' q' : R[X]) (hpq : p.comp q = X) (hqp : q.comp p = X) (hpq' : p'.comp q' = X) (hqp' : q'.comp p' = X) : algEquivOfCompEqX p q hpq hqp = algEquivOfCompEqX p' q' hpq' hqp' ↔ p = p' := ⟨fun h ↦ by simpa using congr($h X), fun h ↦ by ext1; simp [h]⟩ @[simp] theorem algEquivOfCompEqX_symm (p q : R[X]) (hpq : p.comp q = X) (hqp : q.comp p = X) : (algEquivOfCompEqX p q hpq hqp).symm = algEquivOfCompEqX q p hqp hpq := rfl /-- The automorphism of the polynomial algebra given by `p(X) ↦ p(a * X + b)`, with inverse `p(X) ↦ p(a⁻¹ * (X - b))`. -/ @[simps!] def algEquivCMulXAddC {R : Type*} [CommRing R] (a b : R) [Invertible a] : R[X] ≃ₐ[R] R[X] := algEquivOfCompEqX (C a * X + C b) (C ⅟a * (X - C b)) (by simp [← C_mul, ← mul_assoc]) (by simp [← C_mul, ← mul_assoc]) theorem algEquivCMulXAddC_symm_eq {R : Type*} [CommRing R] (a b : R) [Invertible a] : (algEquivCMulXAddC a b).symm = algEquivCMulXAddC (⅟a) (- ⅟a * b) := by ext p : 1 simp only [algEquivCMulXAddC_symm_apply, neg_mul, algEquivCMulXAddC_apply, map_neg, map_mul] congr simp [mul_add, sub_eq_add_neg] /-- The automorphism of the polynomial algebra given by `p(X) ↦ p(X+t)`, with inverse `p(X) ↦ p(X-t)`. -/ @[simps!] def algEquivAevalXAddC {R : Type*} [CommRing R] (t : R) : R[X] ≃ₐ[R] R[X] := algEquivOfCompEqX (X + C t) (X - C t) (by simp) (by simp) @[simp] theorem algEquivAevalXAddC_eq_iff {R : Type*} [CommRing R] (t t' : R) : algEquivAevalXAddC t = algEquivAevalXAddC t' ↔ t = t' := by simp [algEquivAevalXAddC] @[simp] theorem algEquivAevalXAddC_symm {R : Type*} [CommRing R] (t : R) : (algEquivAevalXAddC t).symm = algEquivAevalXAddC (-t) := by simp [algEquivAevalXAddC, sub_eq_add_neg] /-- The involutive automorphism of the polynomial algebra given by `p(X) ↦ p(-X)`. -/ @[simps!] def algEquivAevalNegX {R : Type*} [CommRing R] : R[X] ≃ₐ[R] R[X] := algEquivOfCompEqX (-X) (-X) (by simp) (by simp) theorem comp_neg_X_comp_neg_X {R : Type*} [CommRing R] (p : R[X]) : (p.comp (-X)).comp (-X) = p := by rw [comp_assoc] simp only [neg_comp, X_comp, neg_neg, comp_X] theorem aeval_algHom (f : A →ₐ[R] B) (x : A) : aeval (f x) = f.comp (aeval x) := algHom_ext <| by simp only [aeval_X, AlgHom.comp_apply] @[simp] theorem aeval_X_left : aeval (X : R[X]) = AlgHom.id R R[X] := algHom_ext <| aeval_X X theorem aeval_X_left_apply (p : R[X]) : aeval X p = p := AlgHom.congr_fun (@aeval_X_left R _) p theorem eval_unique (φ : R[X] →ₐ[R] A) (p) : φ p = eval₂ (algebraMap R A) (φ X) p := by rw [← aeval_def, aeval_algHom, aeval_X_left, AlgHom.comp_id] theorem aeval_algHom_apply {F : Type*} [FunLike F A B] [AlgHomClass F R A B] (f : F) (x : A) (p : R[X]) : aeval (f x) p = f (aeval x p) := by refine Polynomial.induction_on p (by simp [AlgHomClass.commutes]) (fun p q hp hq => ?_) (by simp [AlgHomClass.commutes]) rw [map_add, hp, hq, ← map_add, ← map_add] @[simp] lemma coe_aeval_mk_apply {S : Subalgebra R A} (h : x ∈ S) : (aeval (⟨x, h⟩ : S) p : A) = aeval x p := (aeval_algHom_apply S.val (⟨x, h⟩ : S) p).symm theorem aeval_algEquiv (f : A ≃ₐ[R] B) (x : A) : aeval (f x) = (f : A →ₐ[R] B).comp (aeval x) := aeval_algHom (f : A →ₐ[R] B) x theorem aeval_algebraMap_apply_eq_algebraMap_eval (x : R) (p : R[X]) : aeval (algebraMap R A x) p = algebraMap R A (p.eval x) := aeval_algHom_apply (Algebra.ofId R A) x p /-- Polynomial evaluation on a pair is a product of the evaluations on the components. -/ theorem aeval_prod (x : A × B) : aeval (R := R) x = (aeval x.1).prod (aeval x.2) := aeval_algHom (.fst R A B) x ▸ aeval_algHom (.snd R A B) x ▸ (aeval x).prod_comp (.fst R A B) (.snd R A B) /-- Polynomial evaluation on a pair is a pair of evaluations. -/ theorem aeval_prod_apply (x : A × B) (p : Polynomial R) : p.aeval x = (p.aeval x.1, p.aeval x.2) := by simp [aeval_prod] section Pi variable {I : Type*} {A : I → Type*} [∀ i, Semiring (A i)] [∀ i, Algebra R (A i)] variable (x : Π i, A i) (p : R[X]) /-- Polynomial evaluation on an indexed tuple is the indexed product of the evaluations on the components. Generalizes `Polynomial.aeval_prod` to indexed products. -/ theorem aeval_pi (x : Π i, A i) : aeval (R := R) x = Pi.algHom R A (fun i ↦ aeval (x i)) := (funext fun i ↦ aeval_algHom (Pi.evalAlgHom R A i) x) ▸ (Pi.algHom_comp R A (Pi.evalAlgHom R A) (aeval x)) theorem aeval_pi_apply₂ (j : I) : p.aeval x j = p.aeval (x j) := aeval_pi (R := R) x ▸ Pi.algHom_apply R A (fun i ↦ aeval (x i)) p j /-- Polynomial evaluation on an indexed tuple is the indexed tuple of the evaluations on the components. Generalizes `Polynomial.aeval_prod_apply` to indexed products. -/ theorem aeval_pi_apply : p.aeval x = fun j ↦ p.aeval (x j) := funext fun j ↦ aeval_pi_apply₂ x p j end Pi @[simp] theorem coe_aeval_eq_eval (r : R) : (aeval r : R[X] → R) = eval r := rfl @[simp] theorem coe_aeval_eq_evalRingHom (x : R) : ((aeval x : R[X] →ₐ[R] R) : R[X] →+* R) = evalRingHom x := rfl @[simp] theorem aeval_fn_apply {X : Type*} (g : R[X]) (f : X → R) (x : X) : ((aeval f) g) x = aeval (f x) g := (aeval_algHom_apply (Pi.evalAlgHom R (fun _ => R) x) f g).symm @[norm_cast] theorem aeval_subalgebra_coe (g : R[X]) {A : Type*} [Semiring A] [Algebra R A] (s : Subalgebra R A) (f : s) : (aeval f g : A) = aeval (f : A) g := (aeval_algHom_apply s.val f g).symm theorem coeff_zero_eq_aeval_zero (p : R[X]) : p.coeff 0 = aeval 0 p := by simp [coeff_zero_eq_eval_zero] theorem coeff_zero_eq_aeval_zero' (p : R[X]) : algebraMap R A (p.coeff 0) = aeval (0 : A) p := by simp [aeval_def] theorem map_aeval_eq_aeval_map {S T U : Type*} [Semiring S] [CommSemiring T] [Semiring U] [Algebra R S] [Algebra T U] {φ : R →+* T} {ψ : S →+* U} (h : (algebraMap T U).comp φ = ψ.comp (algebraMap R S)) (p : R[X]) (a : S) : ψ (aeval a p) = aeval (ψ a) (p.map φ) := by conv_rhs => rw [aeval_def, ← eval_map] rw [map_map, h, ← map_map, eval_map, eval₂_at_apply, aeval_def, eval_map] theorem aeval_eq_zero_of_dvd_aeval_eq_zero [CommSemiring S] [CommSemiring T] [Algebra S T] {p q : S[X]} (h₁ : p ∣ q) {a : T} (h₂ : aeval a p = 0) : aeval a q = 0 := by rw [aeval_def, ← eval_map] at h₂ ⊢ exact eval_eq_zero_of_dvd_of_eval_eq_zero (Polynomial.map_dvd (algebraMap S T) h₁) h₂ section Semiring variable [Semiring S] {f : R →+* S} theorem aeval_eq_sum_range [Algebra R S] {p : R[X]} (x : S) : aeval x p = ∑ i ∈ Finset.range (p.natDegree + 1), p.coeff i • x ^ i := by simp_rw [Algebra.smul_def] exact eval₂_eq_sum_range (algebraMap R S) x theorem aeval_eq_sum_range' [Algebra R S] {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : S) : aeval x p = ∑ i ∈ Finset.range n, p.coeff i • x ^ i := by simp_rw [Algebra.smul_def] exact eval₂_eq_sum_range' (algebraMap R S) hn x theorem isRoot_of_eval₂_map_eq_zero (hf : Function.Injective f) {r : R} : eval₂ f (f r) p = 0 → p.IsRoot r := by intro h apply hf rw [← eval₂_hom, h, f.map_zero] theorem isRoot_of_aeval_algebraMap_eq_zero [Algebra R S] {p : R[X]} (inj : Function.Injective (algebraMap R S)) {r : R} (hr : aeval (algebraMap R S r) p = 0) : p.IsRoot r := isRoot_of_eval₂_map_eq_zero inj hr end Semiring section CommSemiring section aevalTower variable [CommSemiring S] [Algebra S R] [Algebra S A'] [Algebra S B] /-- Version of `aeval` for defining algebra homs out of `R[X]` over a smaller base ring than `R`. -/ def aevalTower (f : R →ₐ[S] A') (x : A') : R[X] →ₐ[S] A' := eval₂AlgHom' f x fun _ => Commute.all _ _ variable (g : R →ₐ[S] A') (y : A') @[simp] theorem aevalTower_X : aevalTower g y X = y := eval₂_X _ _ @[simp] theorem aevalTower_C (x : R) : aevalTower g y (C x) = g x := eval₂_C _ _ @[simp] theorem aevalTower_comp_C : (aevalTower g y : R[X] →+* A').comp C = g := RingHom.ext <| aevalTower_C _ _ theorem aevalTower_algebraMap (x : R) : aevalTower g y (algebraMap R R[X] x) = g x := eval₂_C _ _ theorem aevalTower_comp_algebraMap : (aevalTower g y : R[X] →+* A').comp (algebraMap R R[X]) = g := aevalTower_comp_C _ _ theorem aevalTower_toAlgHom (x : R) : aevalTower g y (IsScalarTower.toAlgHom S R R[X] x) = g x := aevalTower_algebraMap _ _ _ @[simp] theorem aevalTower_comp_toAlgHom : (aevalTower g y).comp (IsScalarTower.toAlgHom S R R[X]) = g := AlgHom.coe_ringHom_injective <| aevalTower_comp_algebraMap _ _ @[simp] theorem aevalTower_id : aevalTower (AlgHom.id S S) = aeval := by ext s simp only [eval_X, aevalTower_X, coe_aeval_eq_eval] @[simp] theorem aevalTower_ofId : aevalTower (Algebra.ofId S A') = aeval := by ext simp only [aeval_X, aevalTower_X] end aevalTower end CommSemiring section CommRing variable [CommRing S] {f : R →+* S} theorem dvd_term_of_dvd_eval_of_dvd_terms {z p : S} {f : S[X]} (i : ℕ) (dvd_eval : p ∣ f.eval z) (dvd_terms : ∀ j ≠ i, p ∣ f.coeff j * z ^ j) : p ∣ f.coeff i * z ^ i := by by_cases hi : i ∈ f.support · rw [eval, eval₂_eq_sum, sum_def] at dvd_eval rw [← Finset.insert_erase hi, Finset.sum_insert (Finset.notMem_erase _ _)] at dvd_eval refine (dvd_add_left ?_).mp dvd_eval apply Finset.dvd_sum intro j hj exact dvd_terms j (Finset.ne_of_mem_erase hj) · convert dvd_zero p rw [notMem_support_iff] at hi simp [hi] theorem dvd_term_of_isRoot_of_dvd_terms {r p : S} {f : S[X]} (i : ℕ) (hr : f.IsRoot r) (h : ∀ j ≠ i, p ∣ f.coeff j * r ^ j) : p ∣ f.coeff i * r ^ i := dvd_term_of_dvd_eval_of_dvd_terms i (Eq.symm hr ▸ dvd_zero p) h end CommRing end aeval section Ring variable [Ring R] /-- The evaluation map is not generally multiplicative when the coefficient ring is noncommutative, but nevertheless any polynomial of the form `p * (X - monomial 0 r)` is sent to zero when evaluated at `r`. This is the key step in our proof of the Cayley-Hamilton theorem. -/ theorem eval_mul_X_sub_C {p : R[X]} (r : R) : (p * (X - C r)).eval r = 0 := by simp only [eval, eval₂_eq_sum, RingHom.id_apply] have bound := calc (p * (X - C r)).natDegree ≤ p.natDegree + (X - C r).natDegree := natDegree_mul_le _ ≤ p.natDegree + 1 := add_le_add_left (natDegree_X_sub_C_le _) _ _ < p.natDegree + 2 := lt_add_one _ rw [sum_over_range' _ _ (p.natDegree + 2) bound] swap · simp rw [sum_range_succ'] conv_lhs => congr arg 2 simp [coeff_mul_X_sub_C, sub_mul, mul_assoc, ← pow_succ'] rw [sum_range_sub'] simp theorem not_isUnit_X_sub_C [Nontrivial R] (r : R) : ¬IsUnit (X - C r) := fun ⟨⟨_, g, _hfg, hgf⟩, rfl⟩ => zero_ne_one' R <| by rw [← eval_mul_X_sub_C, hgf, eval_one] end Ring section CommRing variable [CommRing R] {p : R[X]} {t : R} @[simp] theorem aeval_neg {p : R[X]} [Ring A] [Algebra R A] (x : A) : aeval x (- p) = - aeval x p := map_neg .. @[simp] theorem aeval_sub {p q : R[X]} [Ring A] [Algebra R A] (x : A) : aeval x (p - q) = aeval x p - aeval x q := map_sub .. theorem aeval_endomorphism {M : Type*} [AddCommGroup M] [Module R M] (f : M →ₗ[R] M) (v : M) (p : R[X]) : aeval f p v = p.sum fun n b => b • (f ^ n) v := by rw [aeval_def, eval₂_eq_sum] exact map_sum (LinearMap.applyₗ v) _ _ lemma X_sub_C_pow_dvd_iff {n : ℕ} : (X - C t) ^ n ∣ p ↔ X ^ n ∣ p.comp (X + C t) := by convert (map_dvd_iff <| algEquivAevalXAddC t).symm using 2 simp [C_eq_algebraMap] lemma comp_X_add_C_eq_zero_iff : p.comp (X + C t) = 0 ↔ p = 0 := EmbeddingLike.map_eq_zero_iff (f := algEquivAevalXAddC t) lemma comp_X_add_C_ne_zero_iff : p.comp (X + C t) ≠ 0 ↔ p ≠ 0 := comp_X_add_C_eq_zero_iff.not lemma dvd_comp_C_mul_X_add_C_iff (p q : R[X]) (a b : R) [Invertible a] : p ∣ q.comp (C a * X + C b) ↔ p.comp (C ⅟a * (X - C b)) ∣ q := by convert map_dvd_iff <| algEquivCMulXAddC a b using 2 simp [← comp_eq_aeval, comp_assoc, ← mul_assoc, ← C_mul] lemma dvd_comp_X_sub_C_iff (p q : R[X]) (a : R) : p ∣ q.comp (X - C a) ↔ p.comp (X + C a) ∣ q := by let _ := invertibleOne (α := R) simpa using dvd_comp_C_mul_X_add_C_iff p q 1 (-a) lemma dvd_comp_X_add_C_iff (p q : R[X]) (a : R) : p ∣ q.comp (X + C a) ↔ p.comp (X - C a) ∣ q := by simpa using dvd_comp_X_sub_C_iff p q (-a) lemma dvd_comp_neg_X_iff (p q : R[X]) : p ∣ q.comp (-X) ↔ p.comp (-X) ∣ q := by let _ := invertibleOne (α := R) let _ := invertibleNeg (R := R) 1 simpa using dvd_comp_C_mul_X_add_C_iff p q (-1) 0 variable [IsDomain R] lemma units_coeff_zero_smul (c : R[X]ˣ) (p : R[X]) : (c : R[X]).coeff 0 • p = c * p := by rw [← Polynomial.C_mul', ← Polynomial.eq_C_of_degree_eq_zero (degree_coe_units c)] end CommRing section StableSubmodule variable {M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] {q : Submodule R M} {m : M} lemma aeval_apply_smul_mem_of_le_comap' [Semiring A] [Algebra R A] [Module A M] [IsScalarTower R A M] (hm : m ∈ q) (p : R[X]) (a : A) (hq : q ≤ q.comap (Algebra.lsmul R R M a)) : aeval a p • m ∈ q := by induction p using Polynomial.induction_on with | C a => simpa using SMulMemClass.smul_mem a hm | add f₁ f₂ h₁ h₂ => simp_rw [map_add, add_smul] exact Submodule.add_mem q h₁ h₂ | monomial n t hmq => dsimp only at hmq ⊢ rw [pow_succ', mul_left_comm, map_mul, aeval_X, mul_smul] solve_by_elim lemma aeval_apply_smul_mem_of_le_comap (hm : m ∈ q) (p : R[X]) (f : Module.End R M) (hq : q ≤ q.comap f) : aeval f p m ∈ q := aeval_apply_smul_mem_of_le_comap' hm p f hq end StableSubmodule section CommSemiring variable [CommSemiring R] {a p : R[X]} theorem eq_zero_of_mul_eq_zero_of_smul (P : R[X]) (h : ∀ r : R, r • P = 0 → r = 0) (Q : R[X]) (hQ : P * Q = 0) : Q = 0 := by suffices ∀ i, P.coeff i • Q = 0 by rw [← leadingCoeff_eq_zero] apply h simpa [ext_iff, mul_comm Q.leadingCoeff] using fun i ↦ congr_arg (·.coeff Q.natDegree) (this i) apply Nat.strong_decreasing_induction · use P.natDegree intro i hi rw [coeff_eq_zero_of_natDegree_lt hi, zero_smul] intro l IH obtain _ | hl := (natDegree_smul_le (P.coeff l) Q).lt_or_eq · apply eq_zero_of_mul_eq_zero_of_smul _ h (P.coeff l • Q) rw [smul_eq_C_mul, mul_left_comm, hQ, mul_zero] suffices P.coeff l * Q.leadingCoeff = 0 by rwa [← leadingCoeff_eq_zero, ← coeff_natDegree, coeff_smul, hl, coeff_natDegree, smul_eq_mul] let m := Q.natDegree suffices (P * Q).coeff (l + m) = P.coeff l * Q.leadingCoeff by rw [← this, hQ, coeff_zero] rw [coeff_mul] apply Finset.sum_eq_single (l, m) _ (by simp) simp only [Finset.mem_antidiagonal, ne_eq, Prod.forall, Prod.mk.injEq, not_and] intro i j hij H obtain hi | rfl | hi := lt_trichotomy i l · have hj : m < j := by omega rw [coeff_eq_zero_of_natDegree_lt hj, mul_zero] · omega · rw [← coeff_C_mul, ← smul_eq_C_mul, IH _ hi, coeff_zero] termination_by Q.natDegree open nonZeroDivisors /-- *McCoy theorem*: a polynomial `P : R[X]` is a zerodivisor if and only if there is `a : R` such that `a ≠ 0` and `a • P = 0`. -/ theorem notMem_nonZeroDivisors_iff {P : R[X]} : P ∉ R[X]⁰ ↔ ∃ a : R, a ≠ 0 ∧ a • P = 0 := by refine ⟨fun hP ↦ ?_, fun ⟨a, ha, h⟩ h1 ↦ ha <| C_eq_zero.1 <| (h1.2 _) <| smul_eq_C_mul a ▸ h⟩ by_contra! h obtain ⟨Q, hQ⟩ := notMem_nonZeroDivisors_iff_right.1 hP refine hQ.2 (eq_zero_of_mul_eq_zero_of_smul P (fun a ha ↦ ?_) Q (mul_comm P _ ▸ hQ.1)) contrapose! ha exact h a ha @[deprecated (since := "2025-05-24")] alias nmem_nonZeroDivisors_iff := notMem_nonZeroDivisors_iff protected lemma mem_nonZeroDivisors_iff {P : R[X]} : P ∈ R[X]⁰ ↔ ∀ a : R, a • P = 0 → a = 0 := by simpa [not_imp_not] using (notMem_nonZeroDivisors_iff (P := P)).not lemma mem_nonzeroDivisors_of_coeff_mem {p : R[X]} (n : ℕ) (hp : p.coeff n ∈ R⁰) : p ∈ R[X]⁰ := Polynomial.mem_nonZeroDivisors_iff.mpr fun r hr ↦ hp.2 _ (by simpa using congr(coeff $hr n)) lemma X_mem_nonzeroDivisors : X ∈ R[X]⁰ := mem_nonzeroDivisors_of_coeff_mem 1 (by simp [one_mem]) end CommSemiring end Polynomial
UniformConvergence.lean
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.UniformConvergence /-! # Algebraic facts about the topology of uniform convergence This file contains algebraic compatibility results about the uniform structure of uniform convergence / `𝔖`-convergence. They will mostly be useful for defining strong topologies on the space of continuous linear maps between two topological vector spaces. ## Main statements * `UniformOnFun.continuousSMul_induced_of_image_bounded` : let `E` be a TVS, `𝔖 : Set (Set α)` and `H` a submodule of `α →ᵤ[𝔖] E`. If the image of any `S ∈ 𝔖` by any `u ∈ H` is bounded (in the sense of `Bornology.IsVonNBounded`), then `H`, equipped with the topology induced from `α →ᵤ[𝔖] E`, is a TVS. ## Implementation notes Like in `Mathlib/Topology/UniformSpace/UniformConvergenceTopology.lean`, we use the type aliases `UniformFun` (denoted `α →ᵤ β`) and `UniformOnFun` (denoted `α →ᵤ[𝔖] β`) for functions from `α` to `β` endowed with the structures of uniform convergence and `𝔖`-convergence. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] * [N. Bourbaki, *Topological Vector Spaces*][bourbaki1987] ## Tags uniform convergence, strong dual -/ open Filter Topology open scoped Pointwise UniformConvergence Uniformity section Module variable (𝕜 α E H : Type*) {hom : Type*} [NormedField 𝕜] [AddCommGroup H] [Module 𝕜 H] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace H] [UniformSpace E] [IsUniformAddGroup E] [ContinuousSMul 𝕜 E] {𝔖 : Set <| Set α} [FunLike hom H (α → E)] [LinearMapClass hom 𝕜 H (α → E)] /-- Let `E` be a topological vector space over a normed field `𝕜`, let `α` be any type. Let `H` be a submodule of `α →ᵤ E` such that the range of each `f ∈ H` is von Neumann bounded. Then `H` is a topological vector space over `𝕜`, i.e., the pointwise scalar multiplication is continuous in both variables. For convenience we require that `H` is a vector space over `𝕜` with a topology induced by `UniformFun.ofFun ∘ φ`, where `φ : H →ₗ[𝕜] (α → E)`. -/ lemma UniformFun.continuousSMul_induced_of_range_bounded (φ : hom) (hφ : IsInducing (ofFun ∘ φ)) (h : ∀ u : H, Bornology.IsVonNBounded 𝕜 (Set.range (φ u))) : ContinuousSMul 𝕜 H := by have : IsTopologicalAddGroup H := let ofFun' : (α → E) →+ (α →ᵤ E) := AddMonoidHom.id _ IsInducing.topologicalAddGroup (ofFun'.comp (φ : H →+ (α → E))) hφ have hb : (𝓝 (0 : H)).HasBasis (· ∈ 𝓝 (0 : E)) fun V ↦ {u | ∀ x, φ u x ∈ V} := by simp only [hφ.nhds_eq_comap, Function.comp_apply, map_zero] exact UniformFun.hasBasis_nhds_zero.comap _ apply ContinuousSMul.of_basis_zero hb · intro U hU have : Tendsto (fun x : 𝕜 × E ↦ x.1 • x.2) (𝓝 0) (𝓝 0) := continuous_smul.tendsto' _ _ (zero_smul _ _) rcases ((Filter.basis_sets _).prod_nhds (Filter.basis_sets _)).tendsto_left_iff.1 this U hU with ⟨⟨V, W⟩, ⟨hV, hW⟩, hVW⟩ refine ⟨V, hV, W, hW, Set.smul_subset_iff.2 fun a ha u hu x ↦ ?_⟩ rw [map_smul] exact hVW (Set.mk_mem_prod ha (hu x)) · intro c U hU have : Tendsto (c • · : E → E) (𝓝 0) (𝓝 0) := (continuous_const_smul c).tendsto' _ _ (smul_zero _) refine ⟨_, this hU, fun u hu x ↦ ?_⟩ simpa only [map_smul] using hu x · intro u U hU simp only [Set.mem_setOf_eq, map_smul, Pi.smul_apply] simpa only [Set.mapsTo_range_iff] using (h u hU).eventually_nhds_zero (mem_of_mem_nhds hU) /-- Let `E` be a TVS, `𝔖 : Set (Set α)` and `H` a submodule of `α →ᵤ[𝔖] E`. If the image of any `S ∈ 𝔖` by any `u ∈ H` is bounded (in the sense of `Bornology.IsVonNBounded`), then `H`, equipped with the topology of `𝔖`-convergence, is a TVS. For convenience, we don't literally ask for `H : Submodule (α →ᵤ[𝔖] E)`. Instead, we prove the result for any vector space `H` equipped with a linear inducing to `α →ᵤ[𝔖] E`, which is often easier to use. We also state the `Submodule` version as `UniformOnFun.continuousSMul_submodule_of_image_bounded`. -/ lemma UniformOnFun.continuousSMul_induced_of_image_bounded (φ : hom) (hφ : IsInducing (ofFun 𝔖 ∘ φ)) (h : ∀ u : H, ∀ s ∈ 𝔖, Bornology.IsVonNBounded 𝕜 ((φ u : α → E) '' s)) : ContinuousSMul 𝕜 H := by obtain rfl := hφ.eq_induced; clear hφ simp only [induced_iInf, UniformOnFun.topologicalSpace_eq, induced_compose] refine continuousSMul_iInf fun s ↦ continuousSMul_iInf fun hs ↦ ?_ letI : TopologicalSpace H := .induced (UniformFun.ofFun ∘ s.restrict ∘ φ) (UniformFun.topologicalSpace s E) set φ' : H →ₗ[𝕜] (s → E) := { toFun := s.restrict ∘ φ, map_smul' := fun c x ↦ by exact congr_arg s.restrict (map_smul φ c x), map_add' := fun x y ↦ by exact congr_arg s.restrict (map_add φ x y) } refine UniformFun.continuousSMul_induced_of_range_bounded 𝕜 s E H φ' ⟨rfl⟩ fun u ↦ ?_ simpa only [Set.image_eq_range] using h u s hs /-- Let `E` be a TVS, `𝔖 : Set (Set α)` and `H` a submodule of `α →ᵤ[𝔖] E`. If the image of any `S ∈ 𝔖` by any `u ∈ H` is bounded (in the sense of `Bornology.IsVonNBounded`), then `H`, equipped with the topology of `𝔖`-convergence, is a TVS. If you have a hard time using this lemma, try the one above instead. -/ theorem UniformOnFun.continuousSMul_submodule_of_image_bounded (H : Submodule 𝕜 (α →ᵤ[𝔖] E)) (h : ∀ u ∈ H, ∀ s ∈ 𝔖, Bornology.IsVonNBounded 𝕜 (u '' s)) : @ContinuousSMul 𝕜 H _ _ ((UniformOnFun.topologicalSpace α E 𝔖).induced ((↑) : H → α →ᵤ[𝔖] E)) := UniformOnFun.continuousSMul_induced_of_image_bounded 𝕜 α E H (LinearMap.id.domRestrict H : H →ₗ[𝕜] α → E) IsInducing.subtypeVal fun ⟨u, hu⟩ => h u hu end Module
SesquilinearForm.lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Moritz Doll -/ import Mathlib.Algebra.GroupWithZero.Action.Opposite import Mathlib.LinearAlgebra.Finsupp.VectorSpace import Mathlib.LinearAlgebra.Matrix.Basis import Mathlib.LinearAlgebra.Matrix.Nondegenerate import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv import Mathlib.LinearAlgebra.SesquilinearForm import Mathlib.LinearAlgebra.Basis.Bilinear /-! # Sesquilinear form This file defines the conversion between sesquilinear maps and matrices. ## Main definitions * `Matrix.toLinearMap₂` given a basis define a bilinear map * `Matrix.toLinearMap₂'` define the bilinear map on `n → R` * `LinearMap.toMatrix₂`: calculate the matrix coefficients of a bilinear map * `LinearMap.toMatrix₂'`: calculate the matrix coefficients of a bilinear map on `n → R` ## TODO At the moment this is quite a literal port from `Matrix.BilinearForm`. Everything should be generalized to fully semibilinear forms. ## Tags Sesquilinear form, Sesquilinear map, matrix, basis -/ open Finset LinearMap Matrix Module open scoped RightActions variable {R R₁ S₁ R₂ S₂ M₁ M₂ M₁' M₂' N₂ n m n' m' ι : Type*} section AuxToLinearMap variable [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂] [AddCommMonoid N₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₂ S₁ N₂] variable [Fintype n] [Fintype m] variable (σ₁ : R₁ →+* S₁) (σ₂ : R₂ →+* S₂) /-- The map from `Matrix n n R` to bilinear maps on `n → R`. This is an auxiliary definition for the equivalence `Matrix.toLinearMap₂'`. -/ def Matrix.toLinearMap₂'Aux (f : Matrix n m N₂) : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ := -- porting note: we don't seem to have `∑ i j` as valid notation yet mk₂'ₛₗ σ₁ σ₂ (fun (v : n → R₁) (w : m → R₂) => ∑ i, ∑ j, σ₂ (w j) • σ₁ (v i) • f i j) (fun _ _ _ => by simp only [Pi.add_apply, map_add, smul_add, sum_add_distrib, add_smul]) (fun c v w => by simp only [Pi.smul_apply, smul_sum, smul_eq_mul, σ₁.map_mul, ← smul_comm _ (σ₁ c), MulAction.mul_smul]) (fun _ _ _ => by simp only [Pi.add_apply, map_add, add_smul, sum_add_distrib]) (fun _ v w => by simp only [Pi.smul_apply, smul_eq_mul, map_mul, MulAction.mul_smul, smul_sum]) variable [DecidableEq n] [DecidableEq m] theorem Matrix.toLinearMap₂'Aux_single (f : Matrix n m N₂) (i : n) (j : m) : f.toLinearMap₂'Aux σ₁ σ₂ (Pi.single i 1) (Pi.single j 1) = f i j := by rw [Matrix.toLinearMap₂'Aux, mk₂'ₛₗ_apply] have : (∑ i', ∑ j', (if i = i' then (1 : S₁) else (0 : S₁)) • (if j = j' then (1 : S₂) else (0 : S₂)) • f i' j') = f i j := by simp_rw [← Finset.smul_sum] simp only [ite_smul, one_smul, zero_smul, sum_ite_eq, mem_univ, ↓reduceIte] rw [← this] exact Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by aesop end AuxToLinearMap section AuxToMatrix section CommSemiring variable [CommSemiring R] [Semiring R₁] [Semiring S₁] [Semiring R₂] [Semiring S₂] variable [AddCommMonoid M₁] [Module R₁ M₁] [AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid N₂] [Module R N₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂] [SMulCommClass S₂ S₁ N₂] variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂} variable (R) /-- The linear map from sesquilinear maps to `Matrix n m N₂` given an `n`-indexed basis for `M₁` and an `m`-indexed basis for `M₂`. This is an auxiliary definition for the equivalence `Matrix.toLinearMapₛₗ₂'`. -/ def LinearMap.toMatrix₂Aux (b₁ : n → M₁) (b₂ : m → M₂) : (M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) →ₗ[R] Matrix n m N₂ where toFun f := of fun i j => f (b₁ i) (b₂ j) map_add' _f _g := rfl map_smul' _f _g := rfl @[simp] theorem LinearMap.toMatrix₂Aux_apply (f : M₁ →ₛₗ[σ₁] M₂ →ₛₗ[σ₂] N₂) (b₁ : n → M₁) (b₂ : m → M₂) (i : n) (j : m) : LinearMap.toMatrix₂Aux R b₁ b₂ f i j = f (b₁ i) (b₂ j) := rfl variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] theorem LinearMap.toLinearMap₂'Aux_toMatrix₂Aux (f : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) : Matrix.toLinearMap₂'Aux σ₁ σ₂ (LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) f) = f := by refine ext_basis (Pi.basisFun R₁ n) (Pi.basisFun R₂ m) fun i j => ?_ simp_rw [Pi.basisFun_apply, Matrix.toLinearMap₂'Aux_single, LinearMap.toMatrix₂Aux_apply] theorem Matrix.toMatrix₂Aux_toLinearMap₂'Aux (f : Matrix n m N₂) : LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) (f.toLinearMap₂'Aux σ₁ σ₂) = f := by ext i j simp_rw [LinearMap.toMatrix₂Aux_apply, Matrix.toLinearMap₂'Aux_single] end CommSemiring end AuxToMatrix section ToMatrix' /-! ### Bilinear maps over `n → R` This section deals with the conversion between matrices and sesquilinear maps on `n → R`. -/ variable [CommSemiring R] [AddCommMonoid N₂] [Module R N₂] [Semiring R₁] [Semiring R₂] [Semiring S₁] [Semiring S₂] [Module S₁ N₂] [Module S₂ N₂] [SMulCommClass S₁ R N₂] [SMulCommClass S₂ R N₂] [SMulCommClass S₂ S₁ N₂] variable {σ₁ : R₁ →+* S₁} {σ₂ : R₂ →+* S₂} variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable (R) /-- The linear equivalence between sesquilinear maps and `n × m` matrices -/ def LinearMap.toMatrixₛₗ₂' : ((n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) ≃ₗ[R] Matrix n m N₂ := { LinearMap.toMatrix₂Aux R (fun i => Pi.single i 1) (fun j => Pi.single j 1) with toFun := LinearMap.toMatrix₂Aux R _ _ invFun := Matrix.toLinearMap₂'Aux σ₁ σ₂ left_inv := LinearMap.toLinearMap₂'Aux_toMatrix₂Aux R right_inv := Matrix.toMatrix₂Aux_toLinearMap₂'Aux R } /-- The linear equivalence between bilinear maps and `n × m` matrices -/ def LinearMap.toMatrix₂' : ((n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) ≃ₗ[R] Matrix n m N₂ := LinearMap.toMatrixₛₗ₂' R variable (σ₁ σ₂) /-- The linear equivalence between `n × n` matrices and sesquilinear maps on `n → R` -/ def Matrix.toLinearMapₛₗ₂' : Matrix n m N₂ ≃ₗ[R] (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂ := (LinearMap.toMatrixₛₗ₂' R).symm /-- The linear equivalence between `n × n` matrices and bilinear maps on `n → R` -/ def Matrix.toLinearMap₂' : Matrix n m N₂ ≃ₗ[R] (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂ := (LinearMap.toMatrix₂' R).symm variable {R} theorem Matrix.toLinearMapₛₗ₂'_aux_eq (M : Matrix n m N₂) : Matrix.toLinearMap₂'Aux σ₁ σ₂ M = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M := rfl theorem Matrix.toLinearMapₛₗ₂'_apply (M : Matrix n m N₂) (x : n → R₁) (y : m → R₂) : -- porting note: we don't seem to have `∑ i j` as valid notation yet Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M x y = ∑ i, ∑ j, σ₁ (x i) • σ₂ (y j) • M i j := by rw [toLinearMapₛₗ₂', toMatrixₛₗ₂', LinearEquiv.coe_symm_mk, toLinearMap₂'Aux, mk₂'ₛₗ_apply] apply Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [smul_comm] theorem Matrix.toLinearMap₂'_apply (M : Matrix n m N₂) (x : n → S₁) (y : m → S₂) : -- porting note: we don't seem to have `∑ i j` as valid notation yet Matrix.toLinearMap₂' R M x y = ∑ i, ∑ j, x i • y j • M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => by rw [RingHom.id_apply, RingHom.id_apply, smul_comm] theorem Matrix.toLinearMap₂'_apply' {T : Type*} [CommSemiring T] (M : Matrix n m T) (v : n → T) (w : m → T) : Matrix.toLinearMap₂' T M v w = v ⬝ᵥ (M *ᵥ w) := by simp_rw [Matrix.toLinearMap₂'_apply, dotProduct, Matrix.mulVec, dotProduct] refine Finset.sum_congr rfl fun _ _ => ?_ rw [Finset.mul_sum] refine Finset.sum_congr rfl fun _ _ => ?_ rw [smul_eq_mul, smul_eq_mul, mul_comm (w _), ← mul_assoc] @[simp] theorem Matrix.toLinearMapₛₗ₂'_single (M : Matrix n m N₂) (i : n) (j : m) : Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMap₂'Aux_single σ₁ σ₂ M i j @[simp] theorem Matrix.toLinearMap₂'_single (M : Matrix n m N₂) (i : n) (j : m) : Matrix.toLinearMap₂' R M (Pi.single i 1) (Pi.single j 1) = M i j := Matrix.toLinearMap₂'Aux_single _ _ M i j @[simp] theorem LinearMap.toMatrixₛₗ₂'_symm : ((LinearMap.toMatrixₛₗ₂' R).symm : Matrix n m N₂ ≃ₗ[R] _) = Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ := rfl @[simp] theorem Matrix.toLinearMapₛₗ₂'_symm : ((Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).symm : _ ≃ₗ[R] Matrix n m N₂) = LinearMap.toMatrixₛₗ₂' R := (LinearMap.toMatrixₛₗ₂' R).symm_symm @[simp] theorem Matrix.toLinearMapₛₗ₂'_toMatrix' (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) : Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ (LinearMap.toMatrixₛₗ₂' R B) = B := (Matrix.toLinearMapₛₗ₂' R σ₁ σ₂).apply_symm_apply B @[simp] theorem Matrix.toLinearMap₂'_toMatrix' (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) : Matrix.toLinearMap₂' R (LinearMap.toMatrix₂' R B) = B := (Matrix.toLinearMap₂' R).apply_symm_apply B @[simp] theorem LinearMap.toMatrix'_toLinearMapₛₗ₂' (M : Matrix n m N₂) : LinearMap.toMatrixₛₗ₂' R (Matrix.toLinearMapₛₗ₂' R σ₁ σ₂ M) = M := (LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrix'_toLinearMap₂' (M : Matrix n m N₂) : LinearMap.toMatrix₂' R (Matrix.toLinearMap₂' R (S₁ := S₁) (S₂ := S₂) M) = M := (LinearMap.toMatrixₛₗ₂' R).apply_symm_apply M @[simp] theorem LinearMap.toMatrixₛₗ₂'_apply (B : (n → R₁) →ₛₗ[σ₁] (m → R₂) →ₛₗ[σ₂] N₂) (i : n) (j : m) : LinearMap.toMatrixₛₗ₂' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl @[simp] theorem LinearMap.toMatrix₂'_apply (B : (n → S₁) →ₗ[S₁] (m → S₂) →ₗ[S₂] N₂) (i : n) (j : m) : LinearMap.toMatrix₂' R B i j = B (Pi.single i 1) (Pi.single j 1) := rfl end ToMatrix' section CommToMatrix' -- TODO: Introduce matrix multiplication by matrices of scalars variable {R : Type*} [CommSemiring R] variable [Fintype n] [Fintype m] variable [DecidableEq n] [DecidableEq m] variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] @[simp] theorem LinearMap.toMatrix₂'_compl₁₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (l : (n' → R) →ₗ[R] n → R) (r : (m' → R) →ₗ[R] m → R) : toMatrix₂' R (B.compl₁₂ l r) = (toMatrix' l)ᵀ * toMatrix₂' R B * toMatrix' r := by ext i j simp only [LinearMap.toMatrix₂'_apply, LinearMap.compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix', LinearEquiv.coe_mk, LinearMap.coe_mk, AddHom.coe_mk, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul (Pi.basisFun R n) (Pi.basisFun R m) (l _) (r _)] rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro j' - simp only [smul_eq_mul, Pi.basisFun_repr, mul_assoc, mul_comm, mul_left_comm, Pi.basisFun_apply, of_apply] · intros simp only [zero_smul, smul_zero] · intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrix₂'_comp (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (n' → R) →ₗ[R] n → R) : toMatrix₂' R (B.comp f) = (toMatrix' f)ᵀ * toMatrix₂' R B := by rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂] simp theorem LinearMap.toMatrix₂'_compl₂ (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (f : (m' → R) →ₗ[R] m → R) : toMatrix₂' R (B.compl₂ f) = toMatrix₂' R B * toMatrix' f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂] simp theorem LinearMap.mul_toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * toMatrix₂' R B * N = toMatrix₂' R (B.compl₁₂ (toLin' Mᵀ) (toLin' N)) := by simp theorem LinearMap.mul_toMatrix' (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix n' n R) : M * toMatrix₂' R B = toMatrix₂' R (B.comp <| toLin' Mᵀ) := by simp only [B.toMatrix₂'_comp, transpose_transpose, toMatrix'_toLin'] theorem LinearMap.toMatrix₂'_mul (B : (n → R) →ₗ[R] (m → R) →ₗ[R] R) (M : Matrix m m' R) : toMatrix₂' R B * M = toMatrix₂' R (B.compl₂ <| toLin' M) := by simp only [B.toMatrix₂'_compl₂, toMatrix'_toLin'] theorem Matrix.toLinearMap₂'_comp (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : LinearMap.compl₁₂ (Matrix.toLinearMap₂' R M) (toLin' P) (toLin' Q) = toLinearMap₂' R (Pᵀ * M * Q) := (LinearMap.toMatrix₂' R).injective (by simp) end CommToMatrix' section ToMatrix /-! ### Bilinear maps over arbitrary vector spaces This section deals with the conversion between matrices and bilinear maps on a module with a fixed basis. -/ variable [CommSemiring R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] [AddCommMonoid N₂] [Module R N₂] variable [DecidableEq n] [Fintype n] variable [DecidableEq m] [Fintype m] section variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂) /-- `LinearMap.toMatrix₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`, respectively. -/ noncomputable def LinearMap.toMatrix₂ : (M₁ →ₗ[R] M₂ →ₗ[R] N₂) ≃ₗ[R] Matrix n m N₂ := (b₁.equivFun.arrowCongr (b₂.equivFun.arrowCongr (LinearEquiv.refl R N₂))).trans (LinearMap.toMatrix₂' R) /-- `Matrix.toLinearMap₂ b₁ b₂` is the equivalence between `R`-bilinear maps on `M` and `n`-by-`m` matrices with entries in `R`, if `b₁` and `b₂` are `R`-bases for `M₁` and `M₂`, respectively; this is the reverse direction of `LinearMap.toMatrix₂ b₁ b₂`. -/ noncomputable def Matrix.toLinearMap₂ : Matrix n m N₂ ≃ₗ[R] M₁ →ₗ[R] M₂ →ₗ[R] N₂ := (LinearMap.toMatrix₂ b₁ b₂).symm -- We make this and not `LinearMap.toMatrix₂` a `simp` lemma to avoid timeouts @[simp] theorem LinearMap.toMatrix₂_apply (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) (i : n) (j : m) : LinearMap.toMatrix₂ b₁ b₂ B i j = B (b₁ i) (b₂ j) := by simp only [toMatrix₂, LinearEquiv.trans_apply, toMatrix₂'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Pi.single_apply, ite_smul, one_smul, zero_smul, sum_ite_eq', mem_univ, ↓reduceIte, LinearEquiv.refl_apply] @[simp] theorem Matrix.toLinearMap₂_apply (M : Matrix n m N₂) (x : M₁) (y : M₂) : Matrix.toLinearMap₂ b₁ b₂ M x y = ∑ i, ∑ j, b₁.repr x i • b₂.repr y j • M i j := Finset.sum_congr rfl fun _ _ => Finset.sum_congr rfl fun _ _ => smul_algebra_smul_comm ((RingHom.id R) ((Basis.equivFun b₁) x _)) ((RingHom.id R) ((Basis.equivFun b₂) y _)) (M _ _) -- Not a `simp` lemma since `LinearMap.toMatrix₂` needs an extra argument theorem LinearMap.toMatrix₂Aux_eq (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) : LinearMap.toMatrix₂Aux R b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B := Matrix.ext fun i j => by rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂Aux_apply] @[simp] theorem LinearMap.toMatrix₂_symm : (LinearMap.toMatrix₂ b₁ b₂).symm = Matrix.toLinearMap₂ (N₂ := N₂) b₁ b₂ := rfl @[simp] theorem Matrix.toLinearMap₂_symm : (Matrix.toLinearMap₂ b₁ b₂).symm = LinearMap.toMatrix₂ (N₂ := N₂) b₁ b₂ := (LinearMap.toMatrix₂ b₁ b₂).symm_symm theorem Matrix.toLinearMap₂_basisFun : Matrix.toLinearMap₂ (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLinearMap₂' R (N₂ := N₂) := by ext M simp only [coe_comp, coe_single, Function.comp_apply, toLinearMap₂_apply, Pi.basisFun_repr, toLinearMap₂'_apply] theorem LinearMap.toMatrix₂_basisFun : LinearMap.toMatrix₂ (Pi.basisFun R n) (Pi.basisFun R m) = LinearMap.toMatrix₂' R (N₂ := N₂) := by ext B rw [LinearMap.toMatrix₂_apply, LinearMap.toMatrix₂'_apply, Pi.basisFun_apply, Pi.basisFun_apply] @[simp] theorem Matrix.toLinearMap₂_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] N₂) : Matrix.toLinearMap₂ b₁ b₂ (LinearMap.toMatrix₂ b₁ b₂ B) = B := (Matrix.toLinearMap₂ b₁ b₂).apply_symm_apply B @[simp] theorem LinearMap.toMatrix₂_toLinearMap₂ (M : Matrix n m N₂) : LinearMap.toMatrix₂ b₁ b₂ (Matrix.toLinearMap₂ b₁ b₂ M) = M := (LinearMap.toMatrix₂ b₁ b₂).apply_symm_apply M variable (b₁ : Basis n R M₁) (b₂ : Basis m R M₂) variable [AddCommMonoid M₁'] [Module R M₁'] variable [AddCommMonoid M₂'] [Module R M₂'] variable (b₁' : Basis n' R M₁') variable (b₂' : Basis m' R M₂') variable [Fintype n'] [Fintype m'] variable [DecidableEq n'] [DecidableEq m'] -- Cannot be a `simp` lemma because `b₁` and `b₂` must be inferred. theorem LinearMap.toMatrix₂_compl₁₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (l : M₁' →ₗ[R] M₁) (r : M₂' →ₗ[R] M₂) : LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ l r) = (toMatrix b₁' b₁ l)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ r := by ext i j simp only [LinearMap.toMatrix₂_apply, compl₁₂_apply, transpose_apply, Matrix.mul_apply, LinearMap.toMatrix_apply, sum_mul] rw [sum_comm] conv_lhs => rw [← LinearMap.sum_repr_mul_repr_mul b₁ b₂] rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro i' - rw [Finsupp.sum_fintype] · apply sum_congr rfl rintro j' - simp only [smul_eq_mul, mul_assoc, mul_comm, mul_left_comm] · intros simp only [zero_smul, smul_zero] · intros simp only [zero_smul, Finsupp.sum_zero] theorem LinearMap.toMatrix₂_comp (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₁' →ₗ[R] M₁) : LinearMap.toMatrix₂ b₁' b₂ (B.comp f) = (toMatrix b₁' b₁ f)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B := by rw [← LinearMap.compl₂_id (B.comp f), ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂] simp theorem LinearMap.toMatrix₂_compl₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (f : M₂' →ₗ[R] M₂) : LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ f) = LinearMap.toMatrix₂ b₁ b₂ B * toMatrix b₂' b₂ f := by rw [← LinearMap.comp_id B, ← LinearMap.compl₁₂, LinearMap.toMatrix₂_compl₁₂ b₁ b₂] simp @[simp] theorem LinearMap.toMatrix₂_mul_basis_toMatrix (c₁ : Basis n' R M₁) (c₂ : Basis m' R M₂) (B : M₁ →ₗ[R] M₂ →ₗ[R] R) : (b₁.toMatrix c₁)ᵀ * LinearMap.toMatrix₂ b₁ b₂ B * b₂.toMatrix c₂ = LinearMap.toMatrix₂ c₁ c₂ B := by simp_rw [← LinearMap.toMatrix_id_eq_basis_toMatrix] rw [← LinearMap.toMatrix₂_compl₁₂, LinearMap.compl₁₂_id_id] theorem LinearMap.mul_toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R) (N : Matrix m m' R) : M * LinearMap.toMatrix₂ b₁ b₂ B * N = LinearMap.toMatrix₂ b₁' b₂' (B.compl₁₂ (toLin b₁' b₁ Mᵀ) (toLin b₂' b₂ N)) := by simp_rw [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, toMatrix_toLin, transpose_transpose] theorem LinearMap.mul_toMatrix₂ (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix n' n R) : M * LinearMap.toMatrix₂ b₁ b₂ B = LinearMap.toMatrix₂ b₁' b₂ (B.comp (toLin b₁' b₁ Mᵀ)) := by rw [LinearMap.toMatrix₂_comp b₁, toMatrix_toLin, transpose_transpose] theorem LinearMap.toMatrix₂_mul (B : M₁ →ₗ[R] M₂ →ₗ[R] R) (M : Matrix m m' R) : LinearMap.toMatrix₂ b₁ b₂ B * M = LinearMap.toMatrix₂ b₁ b₂' (B.compl₂ (toLin b₂' b₂ M)) := by rw [LinearMap.toMatrix₂_compl₂ b₁ b₂, toMatrix_toLin] theorem Matrix.toLinearMap₂_compl₁₂ (M : Matrix n m R) (P : Matrix n n' R) (Q : Matrix m m' R) : (Matrix.toLinearMap₂ b₁ b₂ M).compl₁₂ (toLin b₁' b₁ P) (toLin b₂' b₂ Q) = Matrix.toLinearMap₂ b₁' b₂' (Pᵀ * M * Q) := (LinearMap.toMatrix₂ b₁' b₂').injective (by simp only [LinearMap.toMatrix₂_compl₁₂ b₁ b₂, LinearMap.toMatrix₂_toLinearMap₂, toMatrix_toLin]) end end ToMatrix /-! ### Adjoint pairs -/ section MatrixAdjoints open Matrix variable [CommRing R] variable [AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂] variable [Fintype n] [Fintype n'] variable (b₁ : Basis n R M₁) (b₂ : Basis n' R M₂) variable (J J₂ : Matrix n n R) (J' : Matrix n' n' R) variable (A : Matrix n' n R) (A' : Matrix n n' R) variable (A₁ A₂ : Matrix n n R) /-- The condition for the matrices `A`, `A'` to be an adjoint pair with respect to the square matrices `J`, `J₃`. -/ def Matrix.IsAdjointPair := Aᵀ * J' = J * A' /-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix `J`. -/ def Matrix.IsSelfAdjoint := Matrix.IsAdjointPair J J A₁ A₁ /-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix `J`. -/ def Matrix.IsSkewAdjoint := Matrix.IsAdjointPair J J A₁ (-A₁) variable [DecidableEq n] [DecidableEq n'] @[simp] theorem isAdjointPair_toLinearMap₂' : LinearMap.IsAdjointPair (Matrix.toLinearMap₂' R J) (Matrix.toLinearMap₂' R J') (Matrix.toLin' A) (Matrix.toLin' A') ↔ Matrix.IsAdjointPair J J' A A' := by rw [isAdjointPair_iff_comp_eq_compl₂] have h : ∀ B B' : (n → R) →ₗ[R] (n' → R) →ₗ[R] R, B = B' ↔ LinearMap.toMatrix₂' R B = LinearMap.toMatrix₂' R B' := by intro B B' constructor <;> intro h · rw [h] · exact (LinearMap.toMatrix₂' R).injective h simp_rw [h, LinearMap.toMatrix₂'_comp, LinearMap.toMatrix₂'_compl₂, LinearMap.toMatrix'_toLin', LinearMap.toMatrix'_toLinearMap₂'] rfl @[simp] theorem isAdjointPair_toLinearMap₂ : LinearMap.IsAdjointPair (Matrix.toLinearMap₂ b₁ b₁ J) (Matrix.toLinearMap₂ b₂ b₂ J') (Matrix.toLin b₁ b₂ A) (Matrix.toLin b₂ b₁ A') ↔ Matrix.IsAdjointPair J J' A A' := by rw [isAdjointPair_iff_comp_eq_compl₂] have h : ∀ B B' : M₁ →ₗ[R] M₂ →ₗ[R] R, B = B' ↔ LinearMap.toMatrix₂ b₁ b₂ B = LinearMap.toMatrix₂ b₁ b₂ B' := by intro B B' constructor <;> intro h · rw [h] · exact (LinearMap.toMatrix₂ b₁ b₂).injective h simp_rw [h, LinearMap.toMatrix₂_comp b₂ b₂, LinearMap.toMatrix₂_compl₂ b₁ b₁, LinearMap.toMatrix_toLin, LinearMap.toMatrix₂_toLinearMap₂] rfl theorem Matrix.isAdjointPair_equiv (P : Matrix n n R) (h : IsUnit P) : (Pᵀ * J * P).IsAdjointPair (Pᵀ * J * P) A₁ A₂ ↔ J.IsAdjointPair J (P * A₁ * P⁻¹) (P * A₂ * P⁻¹) := by have h' : IsUnit P.det := P.isUnit_iff_isUnit_det.mp h let u := P.nonsingInvUnit h' let v := Pᵀ.nonsingInvUnit (P.isUnit_det_transpose h') let x := A₁ᵀ * Pᵀ * J let y := J * P * A₂ suffices x * u = v * y ↔ v⁻¹ * x = y * u⁻¹ by dsimp only [Matrix.IsAdjointPair] simp only [Matrix.transpose_mul] simp only [← mul_assoc, P.transpose_nonsing_inv] convert this using 2 · rw [mul_assoc, mul_assoc, ← mul_assoc J] rfl · rw [mul_assoc, mul_assoc, ← mul_assoc _ _ J] rfl rw [Units.eq_mul_inv_iff_mul_eq] conv_rhs => rw [mul_assoc] rw [v.inv_mul_eq_iff_eq_mul] /-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to given matrices `J`, `J₂`. -/ def pairSelfAdjointMatricesSubmodule : Submodule R (Matrix n n R) := (isPairSelfAdjointSubmodule (Matrix.toLinearMap₂' R J) (Matrix.toLinearMap₂' R J₂)).map ((LinearMap.toMatrix' : ((n → R) →ₗ[R] n → R) ≃ₗ[R] Matrix n n R) : ((n → R) →ₗ[R] n → R) →ₗ[R] Matrix n n R) @[simp] theorem mem_pairSelfAdjointMatricesSubmodule : A₁ ∈ pairSelfAdjointMatricesSubmodule J J₂ ↔ Matrix.IsAdjointPair J J₂ A₁ A₁ := by simp only [pairSelfAdjointMatricesSubmodule, Submodule.mem_map_equiv, mem_isPairSelfAdjointSubmodule, toMatrix'_symm, ← isAdjointPair_toLinearMap₂', IsPairSelfAdjoint, toLin'_apply'] /-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to the matrix `J`. -/ def selfAdjointMatricesSubmodule : Submodule R (Matrix n n R) := pairSelfAdjointMatricesSubmodule J J @[simp] theorem mem_selfAdjointMatricesSubmodule : A₁ ∈ selfAdjointMatricesSubmodule J ↔ J.IsSelfAdjoint A₁ := by rw [selfAdjointMatricesSubmodule, mem_pairSelfAdjointMatricesSubmodule, Matrix.IsSelfAdjoint] /-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to the matrix `J`. -/ def skewAdjointMatricesSubmodule : Submodule R (Matrix n n R) := pairSelfAdjointMatricesSubmodule (-J) J @[simp] theorem mem_skewAdjointMatricesSubmodule : A₁ ∈ skewAdjointMatricesSubmodule J ↔ J.IsSkewAdjoint A₁ := by rw [skewAdjointMatricesSubmodule, mem_pairSelfAdjointMatricesSubmodule] simp [Matrix.IsSkewAdjoint, Matrix.IsAdjointPair] end MatrixAdjoints namespace LinearMap /-! ### Nondegenerate bilinear forms -/ section Det open Matrix variable [CommRing R₁] [AddCommMonoid M₁] [Module R₁ M₁] variable [DecidableEq ι] [Fintype ι] theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂ {M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ (Matrix.toLinearMap₂ b b M).SeparatingLeft := (separatingLeft_congr_iff b.equivFun.symm b.equivFun.symm).symm -- Lemmas transferring nondegeneracy between a matrix and its associated bilinear form theorem _root_.Matrix.Nondegenerate.toLinearMap₂' {M : Matrix ι ι R₁} (h : M.Nondegenerate) : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) := fun x hx => h.eq_zero_of_ortho fun y => by simpa only [toLinearMap₂'_apply'] using hx y @[simp] theorem _root_.Matrix.separatingLeft_toLinearMap₂'_iff {M : Matrix ι ι R₁} : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.Nondegenerate := by refine ⟨fun h ↦ Matrix.nondegenerate_def.mpr ?_, Matrix.Nondegenerate.toLinearMap₂'⟩ exact fun v hv => h v fun w => (M.toLinearMap₂'_apply' _ _).trans <| hv w theorem _root_.Matrix.Nondegenerate.toLinearMap₂ {M : Matrix ι ι R₁} (h : M.Nondegenerate) (b : Basis ι R₁ M₁) : (toLinearMap₂ b b M).SeparatingLeft := (Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂ b).mp h.toLinearMap₂' @[simp] theorem _root_.Matrix.separatingLeft_toLinearMap₂_iff {M : Matrix ι ι R₁} (b : Basis ι R₁ M₁) : (toLinearMap₂ b b M).SeparatingLeft ↔ M.Nondegenerate := by rw [← Matrix.separatingLeft_toLinearMap₂'_iff_separatingLeft_toLinearMap₂, Matrix.separatingLeft_toLinearMap₂'_iff] -- Lemmas transferring nondegeneracy between a bilinear form and its associated matrix @[simp] theorem nondegenerate_toMatrix₂'_iff {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} : (LinearMap.toMatrix₂' R₁ B).Nondegenerate ↔ B.SeparatingLeft := Matrix.separatingLeft_toLinearMap₂'_iff.symm.trans <| (Matrix.toLinearMap₂'_toMatrix' (R := R₁) B).symm ▸ Iff.rfl theorem SeparatingLeft.toMatrix₂' {B : (ι → R₁) →ₗ[R₁] (ι → R₁) →ₗ[R₁] R₁} (h : B.SeparatingLeft) : (LinearMap.toMatrix₂' R₁ B).Nondegenerate := nondegenerate_toMatrix₂'_iff.mpr h @[simp] theorem nondegenerate_toMatrix_iff {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) : (toMatrix₂ b b B).Nondegenerate ↔ B.SeparatingLeft := (Matrix.separatingLeft_toLinearMap₂_iff b).symm.trans <| (Matrix.toLinearMap₂_toMatrix₂ b b B).symm ▸ Iff.rfl theorem SeparatingLeft.toMatrix₂ {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (h : B.SeparatingLeft) (b : Basis ι R₁ M₁) : (toMatrix₂ b b B).Nondegenerate := (nondegenerate_toMatrix_iff b).mpr h -- Some shorthands for combining the above with `Matrix.nondegenerate_of_det_ne_zero` variable [IsDomain R₁] theorem separatingLeft_toLinearMap₂'_iff_det_ne_zero {M : Matrix ι ι R₁} : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) ↔ M.det ≠ 0 := by rw [Matrix.separatingLeft_toLinearMap₂'_iff, Matrix.nondegenerate_iff_det_ne_zero] theorem separatingLeft_toLinearMap₂'_of_det_ne_zero' (M : Matrix ι ι R₁) (h : M.det ≠ 0) : (Matrix.toLinearMap₂' R₁ M).SeparatingLeft (R := R₁) := separatingLeft_toLinearMap₂'_iff_det_ne_zero.mpr h theorem separatingLeft_iff_det_ne_zero {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) : B.SeparatingLeft ↔ (toMatrix₂ b b B).det ≠ 0 := by rw [← Matrix.nondegenerate_iff_det_ne_zero, nondegenerate_toMatrix_iff] theorem separatingLeft_of_det_ne_zero {B : M₁ →ₗ[R₁] M₁ →ₗ[R₁] R₁} (b : Basis ι R₁ M₁) (h : (toMatrix₂ b b B).det ≠ 0) : B.SeparatingLeft := (separatingLeft_iff_det_ne_zero b).mpr h end Det end LinearMap
Matrix.lean
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.OfAssociative import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.LinearAlgebra.Matrix.ToLinearEquiv /-! # Lie algebras of matrices An important class of Lie algebras are those arising from the associative algebra structure on square matrices over a commutative ring. This file provides some very basic definitions whose primary value stems from their utility when constructing the classical Lie algebras using matrices. ## Main definitions * `lieEquivMatrix'` * `Matrix.lieConj` * `Matrix.reindexLieEquiv` ## Tags lie algebra, matrix -/ universe u v w w₁ w₂ section Matrices open scoped Matrix variable {R : Type u} [CommRing R] variable {n : Type w} [DecidableEq n] [Fintype n] /-- The natural equivalence between linear endomorphisms of finite free modules and square matrices is compatible with the Lie algebra structures. -/ def lieEquivMatrix' : Module.End R (n → R) ≃ₗ⁅R⁆ Matrix n n R := { LinearMap.toMatrix' with map_lie' := fun {T S} => by let f := @LinearMap.toMatrix' R _ n n _ _ change f (T.comp S - S.comp T) = f T * f S - f S * f T have h : ∀ T S : Module.End R _, f (T.comp S) = f T * f S := LinearMap.toMatrix'_comp rw [map_sub, h, h] } @[simp] theorem lieEquivMatrix'_apply (f : Module.End R (n → R)) : lieEquivMatrix' f = LinearMap.toMatrix' f := rfl @[simp] theorem lieEquivMatrix'_symm_apply (A : Matrix n n R) : (@lieEquivMatrix' R _ n _ _).symm A = Matrix.toLin' A := rfl namespace Matrix /-- An invertible matrix induces a Lie algebra equivalence from the space of matrices to itself. -/ def lieConj (P : Matrix n n R) (h : Invertible P) : Matrix n n R ≃ₗ⁅R⁆ Matrix n n R := ((@lieEquivMatrix' R _ n _ _).symm.trans (P.toLinearEquiv' h).lieConj).trans lieEquivMatrix' @[simp] theorem lieConj_apply (P A : Matrix n n R) (h : Invertible P) : P.lieConj h A = P * A * P⁻¹ := by simp [LinearEquiv.conj_apply, Matrix.lieConj, LinearMap.toMatrix'_comp, LinearMap.toMatrix'_toLin'] @[simp] theorem lieConj_symm_apply (P A : Matrix n n R) (h : Invertible P) : (P.lieConj h).symm A = P⁻¹ * A * P := by simp [LinearEquiv.symm_conj_apply, Matrix.lieConj, LinearMap.toMatrix'_comp, LinearMap.toMatrix'_toLin'] variable {m : Type w₁} [DecidableEq m] [Fintype m] (e : n ≃ m) /-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent types, `Matrix.reindex`, is an equivalence of Lie algebras. -/ def reindexLieEquiv : Matrix n n R ≃ₗ⁅R⁆ Matrix m m R := { Matrix.reindexLinearEquiv R R e e with toFun := Matrix.reindex e e map_lie' := fun {_ _} => by simp only [LieRing.of_associative_ring_bracket, Matrix.reindex_apply, Matrix.submatrix_mul_equiv, Matrix.submatrix_sub, Pi.sub_apply] } @[simp] theorem reindexLieEquiv_apply (M : Matrix n n R) : Matrix.reindexLieEquiv e M = Matrix.reindex e e M := rfl @[simp] theorem reindexLieEquiv_symm : (Matrix.reindexLieEquiv e : _ ≃ₗ⁅R⁆ _).symm = Matrix.reindexLieEquiv e.symm := rfl instance : LieRingModule (Matrix n n R) (n → R) where bracket := mulVec add_lie := add_mulVec lie_add := mulVec_add leibniz_lie x y v := by simp only [Ring.lie_def, mulVec_mulVec, sub_mulVec, sub_add_cancel] instance : LieModule R (Matrix n n R) (n → R) where smul_lie := smul_mulVec lie_smul t A := mulVec_smul A t @[simp] lemma lie_apply (A : Matrix n n R) (v : n → R) : ⁅A, v⁆ = A *ᵥ v := rfl end Matrix namespace LieModule @[simp] theorem toEnd_matrix : toEnd R (Matrix n n R) (n → R) = (lieEquivMatrix' (R := R) (n := n)).symm := by ext; simp instance : IsFaithful R (Matrix n n R) (n → R) where injective_toEnd := by simpa using EmbeddingLike.injective _ end LieModule end Matrices
AbsoluteValue.lean
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.Algebra.Module.Basic import Mathlib.Algebra.Order.AbsoluteValue.Basic /-! # Absolute values and the integers This file contains some results on absolute values applied to integers. ## Main results * `AbsoluteValue.map_units_int`: an absolute value sends all units of `ℤ` to `1` -/ variable {R S : Type*} [Ring R] [CommRing S] [LinearOrder S] [IsStrictOrderedRing S] @[simp] theorem AbsoluteValue.map_units_int (abv : AbsoluteValue ℤ S) (x : ℤˣ) : abv x = 1 := by rcases Int.units_eq_one_or x with (rfl | rfl) <;> simp @[simp] theorem AbsoluteValue.map_units_intCast [Nontrivial R] (abv : AbsoluteValue R S) (x : ℤˣ) : abv ((x : ℤ) : R) = 1 := by rcases Int.units_eq_one_or x with (rfl | rfl) <;> simp @[simp] theorem AbsoluteValue.map_units_int_smul (abv : AbsoluteValue R S) (x : ℤˣ) (y : R) : abv (x • y) = abv y := by rcases Int.units_eq_one_or x with (rfl | rfl) <;> simp
Fintype.lean
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Data.Fintype.Card import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Multiset coercion to type This module defines a `CoeSort` instance for multisets and gives it a `Fintype` instance. It also defines `Multiset.toEnumFinset`, which is another way to enumerate the elements of a multiset. These coercions and definitions make it easier to sum over multisets using existing `Finset` theory. ## Main definitions * A coercion from `m : Multiset α` to a `Type*`. Each `x : m` has two components. The first, `x.1`, can be obtained via the coercion `↑x : α`, and it yields the underlying element of the multiset. The second, `x.2`, is a term of `Fin (m.count x)`, and its function is to ensure each term appears with the correct multiplicity. Note that this coercion requires `DecidableEq α` due to the definition using `Multiset.count`. * `Multiset.toEnumFinset` is a `Finset` version of this. * `Multiset.coeEmbedding` is the embedding `m ↪ α × ℕ`, whose first component is the coercion and whose second component enumerates elements with multiplicity. * `Multiset.coeEquiv` is the equivalence `m ≃ m.toEnumFinset`. ## Tags multiset enumeration -/ variable {α β : Type*} [DecidableEq α] [DecidableEq β] {m : Multiset α} namespace Multiset /-- Auxiliary definition for the `CoeSort` instance. This prevents the `CoeOut m α` instance from inadvertently applying to other sigma types. -/ def ToType (m : Multiset α) : Type _ := (x : α) × Fin (m.count x) /-- Create a type that has the same number of elements as the multiset. Terms of this type are triples `⟨x, ⟨i, h⟩⟩` where `x : α`, `i : ℕ`, and `h : i < m.count x`. This way repeated elements of a multiset appear multiple times from different values of `i`. -/ instance : CoeSort (Multiset α) (Type _) := ⟨Multiset.ToType⟩ example : DecidableEq m := inferInstanceAs <| DecidableEq ((x : α) × Fin (m.count x)) /-- Constructor for terms of the coercion of `m` to a type. This helps Lean pick up the correct instances. -/ @[reducible, match_pattern] def mkToType (m : Multiset α) (x : α) (i : Fin (m.count x)) : m := ⟨x, i⟩ /-- As a convenience, there is a coercion from `m : Type*` to `α` by projecting onto the first component. -/ instance instCoeSortMultisetType.instCoeOutToType : CoeOut m α := ⟨fun x ↦ x.1⟩ theorem coe_mk {x : α} {i : Fin (m.count x)} : ↑(m.mkToType x i) = x := rfl @[simp] lemma coe_mem {x : m} : ↑x ∈ m := Multiset.count_pos.mp (by have := x.2.2; omega) @[simp] protected theorem forall_coe (p : m → Prop) : (∀ x : m, p x) ↔ ∀ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.forall @[simp] protected theorem exists_coe (p : m → Prop) : (∃ x : m, p x) ↔ ∃ (x : α) (i : Fin (m.count x)), p ⟨x, i⟩ := Sigma.exists instance : Fintype { p : α × ℕ | p.2 < m.count p.1 } := Fintype.ofFinset (m.toFinset.biUnion fun x ↦ (Finset.range (m.count x)).map ⟨_, Prod.mk_right_injective x⟩) (by rintro ⟨x, i⟩ simp only [Finset.mem_biUnion, Multiset.mem_toFinset, Finset.mem_map, Finset.mem_range, Function.Embedding.coeFn_mk, Prod.mk_inj, Set.mem_setOf_eq] simp only [← and_assoc, exists_eq_right, and_iff_right_iff_imp] exact fun h ↦ Multiset.count_pos.mp (by omega)) /-- Construct a finset whose elements enumerate the elements of the multiset `m`. The `ℕ` component is used to differentiate between equal elements: if `x` appears `n` times then `(x, 0)`, ..., and `(x, n-1)` appear in the `Finset`. -/ def toEnumFinset (m : Multiset α) : Finset (α × ℕ) := { p : α × ℕ | p.2 < m.count p.1 }.toFinset @[simp] theorem mem_toEnumFinset (m : Multiset α) (p : α × ℕ) : p ∈ m.toEnumFinset ↔ p.2 < m.count p.1 := Set.mem_toFinset theorem mem_of_mem_toEnumFinset {p : α × ℕ} (h : p ∈ m.toEnumFinset) : p.1 ∈ m := have := (m.mem_toEnumFinset p).mp h; Multiset.count_pos.mp (by omega) @[simp] lemma toEnumFinset_filter_eq (m : Multiset α) (a : α) : {x ∈ m.toEnumFinset | x.1 = a} = {a} ×ˢ Finset.range (m.count a) := by aesop @[simp] lemma map_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.val.map Prod.fst = m := by ext a; simp [count_map, ← Finset.filter_val, eq_comm (a := a)] @[simp] lemma image_toEnumFinset_fst (m : Multiset α) : m.toEnumFinset.image Prod.fst = m.toFinset := by rw [Finset.image, Multiset.map_toEnumFinset_fst] @[simp] lemma map_fst_le_of_subset_toEnumFinset {s : Finset (α × ℕ)} (hsm : s ⊆ m.toEnumFinset) : s.1.map Prod.fst ≤ m := by simp_rw [le_iff_count, count_map] rintro a obtain ha | ha := (s.1.filter fun x ↦ a = x.1).card.eq_zero_or_pos · rw [ha] exact Nat.zero_le _ obtain ⟨n, han, hn⟩ : ∃ n ≥ card (s.1.filter fun x ↦ a = x.1) - 1, (a, n) ∈ s := by by_contra! h replace h : {x ∈ s | x.1 = a} ⊆ {a} ×ˢ .range (card (s.1.filter fun x ↦ a = x.1) - 1) := by simpa +contextual [forall_swap (β := _ = a), Finset.subset_iff, imp_not_comm, not_le, Nat.lt_sub_iff_add_lt] using h have : card (s.1.filter fun x ↦ a = x.1) ≤ card (s.1.filter fun x ↦ a = x.1) - 1 := by simpa [Finset.card, eq_comm] using Finset.card_mono h omega exact Nat.le_of_pred_lt (han.trans_lt <| by simpa using hsm hn) @[mono] theorem toEnumFinset_mono {m₁ m₂ : Multiset α} (h : m₁ ≤ m₂) : m₁.toEnumFinset ⊆ m₂.toEnumFinset := by intro p simp only [Multiset.mem_toEnumFinset] exact lt_of_le_of_lt' (Multiset.le_iff_count.mp h p.1) @[simp] theorem toEnumFinset_subset_iff {m₁ m₂ : Multiset α} : m₁.toEnumFinset ⊆ m₂.toEnumFinset ↔ m₁ ≤ m₂ := ⟨fun h ↦ by simpa using map_fst_le_of_subset_toEnumFinset h, Multiset.toEnumFinset_mono⟩ /-- The embedding from a multiset into `α × ℕ` where the second coordinate enumerates repeats. If you are looking for the function `m → α`, that would be plain `(↑)`. -/ @[simps] def coeEmbedding (m : Multiset α) : m ↪ α × ℕ where toFun x := (x, x.2) inj' := by intro ⟨x, i, hi⟩ ⟨y, j, hj⟩ rintro ⟨⟩ rfl /-- Another way to coerce a `Multiset` to a type is to go through `m.toEnumFinset` and coerce that `Finset` to a type. -/ @[simps] def coeEquiv (m : Multiset α) : m ≃ m.toEnumFinset where toFun x := ⟨m.coeEmbedding x, by rw [Multiset.mem_toEnumFinset] exact x.2.2⟩ invFun x := ⟨x.1.1, x.1.2, by rw [← Multiset.mem_toEnumFinset] exact x.2⟩ @[simp] theorem toEmbedding_coeEquiv_trans (m : Multiset α) : m.coeEquiv.toEmbedding.trans (Function.Embedding.subtype _) = m.coeEmbedding := by ext <;> rfl @[irreducible] instance fintypeCoe : Fintype m := Fintype.ofEquiv m.toEnumFinset m.coeEquiv.symm theorem map_univ_coeEmbedding (m : Multiset α) : (Finset.univ : Finset m).map m.coeEmbedding = m.toEnumFinset := by ext ⟨x, i⟩ simp only [Fin.exists_iff, Finset.mem_map, Finset.mem_univ, Multiset.coeEmbedding_apply, Prod.mk_inj, Multiset.exists_coe, Multiset.coe_mk, exists_prop, exists_eq_right_right, exists_eq_right, Multiset.mem_toEnumFinset, true_and] @[simp] theorem map_univ_coe (m : Multiset α) : (Finset.univ : Finset m).val.map (fun x : m ↦ (x : α)) = m := by have := m.map_toEnumFinset_fst rw [← m.map_univ_coeEmbedding] at this simpa only [Finset.map_val, Multiset.coeEmbedding_apply, Multiset.map_map, Function.comp_apply] using this theorem map_univ_comp_coe {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map (f ∘ (fun x : m ↦ (x : α)))) = m.map f := by rw [← Multiset.map_map, Multiset.map_univ_coe] @[simp] theorem map_univ {β : Type*} (m : Multiset α) (f : α → β) : ((Finset.univ : Finset m).val.map fun (x : m) ↦ f (x : α)) = m.map f := by simp_rw [← Function.comp_apply (f := f)] exact map_univ_comp_coe m f @[simp] theorem card_toEnumFinset (m : Multiset α) : m.toEnumFinset.card = Multiset.card m := by rw [Finset.card, ← Multiset.card_map Prod.fst m.toEnumFinset.val] congr exact m.map_toEnumFinset_fst @[simp] theorem card_coe (m : Multiset α) : Fintype.card m = Multiset.card m := by rw [Fintype.card_congr m.coeEquiv] simp only [Fintype.card_coe, card_toEnumFinset] @[to_additive] theorem prod_eq_prod_coe [CommMonoid α] (m : Multiset α) : m.prod = ∏ x : m, (x : α) := by congr simp @[to_additive] theorem prod_eq_prod_toEnumFinset [CommMonoid α] (m : Multiset α) : m.prod = ∏ x ∈ m.toEnumFinset, x.1 := by congr simp @[to_additive] theorem prod_toEnumFinset {β : Type*} [CommMonoid β] (m : Multiset α) (f : α → ℕ → β) : ∏ x ∈ m.toEnumFinset, f x.1 x.2 = ∏ x : m, f x x.2 := by rw [Fintype.prod_equiv m.coeEquiv (fun x ↦ f x x.2) fun x ↦ f x.1.1 x.1.2] · rw [← m.toEnumFinset.prod_coe_sort fun x ↦ f x.1 x.2] · intro x rfl /-- If `s = t` then there's an equivalence between the appropriate types. -/ @[simps] def cast {s t : Multiset α} (h : s = t) : s ≃ t where toFun x := ⟨x.1, x.2.cast (by simp [h])⟩ invFun x := ⟨x.1, x.2.cast (by simp [h])⟩ instance : IsEmpty (0 : Multiset α) := Fintype.card_eq_zero_iff.mp (by simp) instance : IsEmpty (∅ : Multiset α) := Fintype.card_eq_zero_iff.mp (by simp) /-- `v ::ₘ m` is equivalent to `Option m` by mapping one `v` to `none` and everything else to `m`. -/ def consEquiv {v : α} : v ::ₘ m ≃ Option m where toFun x := if h : x.1 = v ∧ x.2.val = m.count v then none else some ⟨x.1, ⟨x.2, by by_cases hv : x.1 = v · simp only [hv, true_and] at h ⊢ apply lt_of_le_of_ne (Nat.le_of_lt_add_one _) h convert x.2.2 using 1 simp [hv] · convert x.2.2 using 1 exact (count_cons_of_ne hv _).symm ⟩⟩ invFun x := x.elim ⟨v, ⟨m.count v, by simp⟩⟩ (fun x ↦ ⟨x.1, x.2.castLE (count_le_count_cons ..)⟩) left_inv := by rintro ⟨x, hx⟩ dsimp only split · rename_i h obtain ⟨rfl, h2⟩ := h simp [← h2] · simp right_inv := by rintro (_ | x) · simp · simp only [Option.elim_some, Fin.coe_castLE, Fin.eta, Sigma.eta, dite_eq_ite, ite_eq_right_iff, reduceCtorEq, imp_false, not_and] rintro rfl exact x.2.2.ne @[simp] lemma consEquiv_symm_none {v : α} : (consEquiv (m := m) (v := v)).symm none = ⟨v, ⟨m.count v, (count_cons_self v m) ▸ (Nat.lt_add_one _)⟩⟩ := rfl @[simp] lemma consEquiv_symm_some {v : α} {x : m} : (consEquiv (v := v)).symm (some x) = ⟨x, x.2.castLE (count_le_count_cons ..)⟩ := rfl lemma coe_consEquiv_of_ne {v : α} (x : v ::ₘ m) (hx : ↑x ≠ v) : consEquiv x = some ⟨x.1, x.2.cast (by simp [hx])⟩ := by simp [consEquiv, hx] rfl lemma coe_consEquiv_of_eq_of_eq {v : α} (x : v ::ₘ m) (hx : ↑x = v) (hx2 : x.2 = m.count v) : consEquiv x = none := by simp [consEquiv, hx, hx2] lemma coe_consEquiv_of_eq_of_lt {v : α} (x : v ::ₘ m) (hx : ↑x = v) (hx2 : x.2 < m.count v) : consEquiv x = some ⟨x.1, ⟨x.2, by simpa [hx]⟩⟩ := by simp [consEquiv, hx, hx2.ne] /-- There is some equivalence between `m` and `m.map f` which respects `f`. -/ def mapEquiv_aux (m : Multiset α) (f : α → β) : Squash { v : m ≃ m.map f // ∀ a : m, v a = f a} := Quotient.recOnSubsingleton m fun l ↦ .mk <| List.recOn l ⟨@Equiv.equivOfIsEmpty _ _ (by dsimp; infer_instance) (by dsimp; infer_instance), by simp⟩ fun a s ⟨v, hv⟩ ↦ ⟨Multiset.consEquiv.trans v.optionCongr |>.trans Multiset.consEquiv.symm |>.trans (Multiset.cast (map_cons f a s)).symm, fun x ↦ by simp only [consEquiv, Equiv.trans_apply, Equiv.coe_fn_mk, Equiv.optionCongr_apply, Equiv.coe_fn_symm_mk] split <;> simp_all⟩ /-- One of the possible equivalences from `Multiset.mapEquiv_aux`, selected using choice. -/ noncomputable def mapEquiv (s : Multiset α) (f : α → β) : s ≃ s.map f := (Multiset.mapEquiv_aux s f).out.1 @[simp] theorem mapEquiv_apply (s : Multiset α) (f : α → β) (v : s) : s.mapEquiv f v = f v := (Multiset.mapEquiv_aux s f).out.2 v end Multiset
WeightedHomogeneous.lean
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Algebra.DirectSum.Decomposition import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.MvPolynomial.Basic import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Data.Finsupp.Weight import Mathlib.RingTheory.GradedAlgebra.Basic /-! # Weighted homogeneous polynomials It is possible to assign weights (in a commutative additive monoid `M`) to the variables of a multivariate polynomial ring, so that monomials of the ring then have a weighted degree with respect to the weights of the variables. The weights are represented by a function `w : σ → M`, where `σ` are the indeterminates. A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials occurring in `φ` have the same weighted degree `m`. ## Main definitions/lemmas * `weightedTotalDegree' w φ` : the weighted total degree of a multivariate polynomial with respect to the weights `w`, taking values in `WithBot M`. * `weightedTotalDegree w φ` : When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. * `IsWeightedHomogeneous w φ m`: a predicate that asserts that `φ` is weighted homogeneous of weighted degree `m` with respect to the weights `w`. * `weightedHomogeneousSubmodule R w m`: the submodule of homogeneous polynomials of weighted degree `m`. * `weightedHomogeneousComponent w m`: the additive morphism that projects polynomials onto their summand that is weighted homogeneous of degree `n` with respect to `w`. * `sum_weightedHomogeneousComponent`: every polynomial is the sum of its weighted homogeneous components. -/ noncomputable section open Set Function Finset Finsupp AddMonoidAlgebra variable {R M : Type*} [CommSemiring R] namespace MvPolynomial variable {σ : Type*} section AddCommMonoid variable [AddCommMonoid M] /-! ### `weight` -/ section SemilatticeSup variable [SemilatticeSup M] /-- The weighted total degree of a multivariate polynomial, taking values in `WithBot M`. -/ def weightedTotalDegree' (w : σ → M) (p : MvPolynomial σ R) : WithBot M := p.support.sup fun s => weight w s /-- The `weightedTotalDegree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/ theorem weightedTotalDegree'_eq_bot_iff (w : σ → M) (p : MvPolynomial σ R) : weightedTotalDegree' w p = ⊥ ↔ p = 0 := by simp only [weightedTotalDegree', Finset.sup_eq_bot_iff, mem_support_iff, WithBot.coe_ne_bot, MvPolynomial.eq_zero_iff] exact forall_congr' fun _ => Classical.not_not /-- The `weightedTotalDegree'` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree'_zero (w : σ → M) : weightedTotalDegree' w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree', support_zero, Finset.sup_empty] section OrderBot variable [OrderBot M] /-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. -/ def weightedTotalDegree (w : σ → M) (p : MvPolynomial σ R) : M := p.support.sup fun s => weight w s /-- This lemma relates `weightedTotalDegree` and `weightedTotalDegree'`. -/ theorem weightedTotalDegree_coe (w : σ → M) (p : MvPolynomial σ R) (hp : p ≠ 0) : weightedTotalDegree' w p = ↑(weightedTotalDegree w p) := by rw [Ne, ← weightedTotalDegree'_eq_bot_iff w p, ← Ne, WithBot.ne_bot_iff_exists] at hp obtain ⟨m, hm⟩ := hp apply le_antisymm · simp only [weightedTotalDegree, weightedTotalDegree', Finset.sup_le_iff, WithBot.coe_le_coe] intro b exact Finset.le_sup · simp only [weightedTotalDegree] have hm' : weightedTotalDegree' w p ≤ m := le_of_eq hm.symm rw [← hm] simpa [weightedTotalDegree'] using hm' /-- The `weightedTotalDegree` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree_zero (w : σ → M) : weightedTotalDegree w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree, support_zero, Finset.sup_empty] theorem le_weightedTotalDegree (w : σ → M) {φ : MvPolynomial σ R} {d : σ →₀ ℕ} (hd : d ∈ φ.support) : weight w d ≤ φ.weightedTotalDegree w := le_sup hd end OrderBot end SemilatticeSup /-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials occurring in `φ` have weighted degree `m`. -/ def IsWeightedHomogeneous (w : σ → M) (φ : MvPolynomial σ R) (m : M) : Prop := ∀ ⦃d⦄, coeff d φ ≠ 0 → weight w d = m variable (R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def weightedHomogeneousSubmodule (w : σ → M) (m : M) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsWeightedHomogeneous w m } smul_mem' r a ha c hc := by rw [coeff_smul] at hc exact ha (right_ne_zero_of_mul hc) zero_mem' _ hd := False.elim (hd <| coeff_zero _) add_mem' {a} {b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h @[simp] theorem mem_weightedHomogeneousSubmodule (w : σ → M) (m : M) (p : MvPolynomial σ R) : p ∈ weightedHomogeneousSubmodule R w m ↔ p.IsWeightedHomogeneous w m := Iff.rfl /-- The submodule `weightedHomogeneousSubmodule R w m` of homogeneous `MvPolynomial`s of degree `n` is equal to the `R`-submodule of all `p : (σ →₀ ℕ) →₀ R` such that `p.support ⊆ {d | weight w d = m}`. While equal, the former has a convenient definitional reduction. -/ theorem weightedHomogeneousSubmodule_eq_finsupp_supported (w : σ → M) (m : M) : weightedHomogeneousSubmodule R w m = Finsupp.supported R R { d | weight w d = m } := by ext x rw [mem_supported, Set.subset_def] simp only [Finsupp.mem_support_iff, mem_coe] rfl variable {R} /-- The submodule generated by products `Pm * Pn` of weighted homogeneous polynomials of degrees `m` and `n` is contained in the submodule of weighted homogeneous polynomials of degree `m + n`. -/ theorem weightedHomogeneousSubmodule_mul (w : σ → M) (m n : M) : weightedHomogeneousSubmodule R w m * weightedHomogeneousSubmodule R w n ≤ weightedHomogeneousSubmodule R w (m + n) := by classical rw [Submodule.mul_le] intro φ hφ ψ hψ c hc rw [coeff_mul] at hc obtain ⟨⟨d, e⟩, hde, H⟩ := Finset.exists_ne_zero_of_sum_ne_zero hc have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0 := by contrapose! H by_cases h : coeff d φ = 0 <;> simp_all only [Ne, not_false_iff, zero_mul, mul_zero] rw [← mem_antidiagonal.mp hde, ← hφ aux.1, ← hψ aux.2, map_add] /-- Monomials are weighted homogeneous. -/ theorem isWeightedHomogeneous_monomial (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M} (hm : weight w d = m) : IsWeightedHomogeneous w (monomial d r) m := by classical intro c hc rw [coeff_monomial] at hc split_ifs at hc with h · subst c exact hm · contradiction /-- A polynomial of weightedTotalDegree `⊥` is weighted_homogeneous of degree `⊥`. -/ theorem isWeightedHomogeneous_of_total_degree_zero [SemilatticeSup M] [OrderBot M] (w : σ → M) {p : MvPolynomial σ R} (hp : weightedTotalDegree w p = (⊥ : M)) : IsWeightedHomogeneous w p (⊥ : M) := by intro d hd have h := weightedTotalDegree_coe w p (MvPolynomial.ne_zero_iff.mpr ⟨d, hd⟩) simp only [weightedTotalDegree', hp] at h rw [eq_bot_iff, ← WithBot.coe_le_coe, ← h] apply Finset.le_sup (mem_support_iff.mpr hd) /-- Constant polynomials are weighted homogeneous of degree 0. -/ theorem isWeightedHomogeneous_C (w : σ → M) (r : R) : IsWeightedHomogeneous w (C r : MvPolynomial σ R) 0 := isWeightedHomogeneous_monomial _ _ _ (map_zero _) variable (R) /-- 0 is weighted homogeneous of any degree. -/ theorem isWeightedHomogeneous_zero (w : σ → M) (m : M) : IsWeightedHomogeneous w (0 : MvPolynomial σ R) m := (weightedHomogeneousSubmodule R w m).zero_mem /-- 1 is weighted homogeneous of degree 0. -/ theorem isWeightedHomogeneous_one (w : σ → M) : IsWeightedHomogeneous w (1 : MvPolynomial σ R) 0 := isWeightedHomogeneous_C _ _ /-- An indeterminate `i : σ` is weighted homogeneous of degree `w i`. -/ theorem isWeightedHomogeneous_X (w : σ → M) (i : σ) : IsWeightedHomogeneous w (X i : MvPolynomial σ R) (w i) := by apply isWeightedHomogeneous_monomial simp only [weight, LinearMap.toAddMonoidHom_coe, linearCombination_single, one_nsmul] namespace IsWeightedHomogeneous variable {R} variable {φ ψ : MvPolynomial σ R} {m n : M} /-- The weighted degree of a weighted homogeneous polynomial controls its support. -/ theorem coeff_eq_zero {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (d : σ →₀ ℕ) (hd : weight w d ≠ n) : coeff d φ = 0 := by have aux := mt (@hφ d) hd rwa [Classical.not_not] at aux /-- The weighted degree of a nonzero weighted homogeneous polynomial is well-defined. -/ theorem inj_right {w : σ → M} (hφ : φ ≠ 0) (hm : IsWeightedHomogeneous w φ m) (hn : IsWeightedHomogeneous w φ n) : m = n := by obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero hφ rw [← hm hd, ← hn hd] /-- The sum of two weighted homogeneous polynomials of degree `n` is weighted homogeneous of weighted degree `n`. -/ theorem add {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (hψ : IsWeightedHomogeneous w ψ n) : IsWeightedHomogeneous w (φ + ψ) n := (weightedHomogeneousSubmodule R w n).add_mem hφ hψ /-- The sum of weighted homogeneous polynomials of degree `n` is weighted homogeneous of weighted degree `n`. -/ theorem sum {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : M) {w : σ → M} (h : ∀ i ∈ s, IsWeightedHomogeneous w (φ i) n) : IsWeightedHomogeneous w (∑ i ∈ s, φ i) n := (weightedHomogeneousSubmodule R w n).sum_mem h /-- The product of weighted homogeneous polynomials of weighted degrees `m` and `n` is weighted homogeneous of weighted degree `m + n`. -/ theorem mul {w : σ → M} (hφ : IsWeightedHomogeneous w φ m) (hψ : IsWeightedHomogeneous w ψ n) : IsWeightedHomogeneous w (φ * ψ) (m + n) := weightedHomogeneousSubmodule_mul w m n <| Submodule.mul_mem_mul hφ hψ theorem pow {w : σ → M} (hφ : IsWeightedHomogeneous w φ m) (n : ℕ) : IsWeightedHomogeneous w (φ ^ n) (n • m) := by induction n with | zero => rw [pow_zero, zero_smul]; exact isWeightedHomogeneous_one R w | succ n ih => rw [pow_succ, succ_nsmul]; exact ih.mul hφ /-- A product of weighted homogeneous polynomials is weighted homogeneous, with weighted degree equal to the sum of the weighted degrees. -/ theorem prod {ι : Type*} (s : Finset ι) (φ : ι → MvPolynomial σ R) (n : ι → M) {w : σ → M} : (∀ i ∈ s, IsWeightedHomogeneous w (φ i) (n i)) → IsWeightedHomogeneous w (∏ i ∈ s, φ i) (∑ i ∈ s, n i) := by classical refine Finset.induction_on s ?_ ?_ · intro simp only [isWeightedHomogeneous_one, Finset.sum_empty, Finset.prod_empty] · intro i s his IH h simp only [his, Finset.prod_insert, Finset.sum_insert, not_false_iff] apply (h i (Finset.mem_insert_self _ _)).mul (IH _) intro j hjs exact h j (Finset.mem_insert_of_mem hjs) /-- A non zero weighted homogeneous polynomial of weighted degree `n` has weighted total degree `n`. -/ theorem weighted_total_degree [SemilatticeSup M] {w : σ → M} (hφ : IsWeightedHomogeneous w φ n) (h : φ ≠ 0) : weightedTotalDegree' w φ = n := by simp only [weightedTotalDegree'] apply le_antisymm · simp only [Finset.sup_le_iff, mem_support_iff, WithBot.coe_le_coe] exact fun d hd => le_of_eq (hφ hd) · obtain ⟨d, hd⟩ : ∃ d, coeff d φ ≠ 0 := exists_coeff_ne_zero h simp only [← hφ hd] replace hd := Finsupp.mem_support_iff.mpr hd apply Finset.le_sup hd end IsWeightedHomogeneous variable {R} /-- The weighted homogeneous submodules form a graded monoid. -/ lemma WeightedHomogeneousSubmodule.gradedMonoid {w : σ → M} : SetLike.GradedMonoid (weightedHomogeneousSubmodule R w) where one_mem := isWeightedHomogeneous_one R w mul_mem _ _ _ _ := IsWeightedHomogeneous.mul /-- `weightedHomogeneousComponent w n φ` is the part of `φ` that is weighted homogeneous of weighted degree `n`, with respect to the weights `w`. See `sum_weightedHomogeneousComponent` for the statement that `φ` is equal to the sum of all its weighted homogeneous components. -/ def weightedHomogeneousComponent (w : σ → M) (n : M) : MvPolynomial σ R →ₗ[R] MvPolynomial σ R := letI := Classical.decEq M (Submodule.subtype _).comp <| Finsupp.restrictDom _ _ { d | weight w d = n } section WeightedHomogeneousComponent variable {w : σ → M} (n : M) (φ ψ : MvPolynomial σ R) theorem coeff_weightedHomogeneousComponent [DecidableEq M] (d : σ →₀ ℕ) : coeff d (weightedHomogeneousComponent w n φ) = if weight w d = n then coeff d φ else 0 := letI := Classical.decEq M Finsupp.filter_apply (fun d : σ →₀ ℕ => weight w d = n) φ d |>.trans <| by convert rfl theorem weightedHomogeneousComponent_apply [DecidableEq M] : weightedHomogeneousComponent w n φ = ∑ d ∈ φ.support with weight w d = n, monomial d (coeff d φ) := letI := Classical.decEq M Finsupp.filter_eq_sum (fun d : σ →₀ ℕ => weight w d = n) φ |>.trans <| by convert rfl /-- The `n` weighted homogeneous component of a polynomial is weighted homogeneous of weighted degree `n`. -/ theorem weightedHomogeneousComponent_isWeightedHomogeneous : (weightedHomogeneousComponent w n φ).IsWeightedHomogeneous w n := by classical intro d hd contrapose! hd rw [coeff_weightedHomogeneousComponent, if_neg hd] theorem weightedHomogeneousComponent_mem (w : σ → M) (φ : MvPolynomial σ R) (m : M) : weightedHomogeneousComponent w m φ ∈ weightedHomogeneousSubmodule R w m := by rw [mem_weightedHomogeneousSubmodule] exact weightedHomogeneousComponent_isWeightedHomogeneous m φ @[simp] theorem weightedHomogeneousComponent_C_mul (n : M) (r : R) : weightedHomogeneousComponent w n (C r * φ) = C r * weightedHomogeneousComponent w n φ := by simp only [C_mul', LinearMap.map_smul] theorem weightedHomogeneousComponent_eq_zero' (h : ∀ d : σ →₀ ℕ, d ∈ φ.support → weight w d ≠ n) : weightedHomogeneousComponent w n φ = 0 := by classical rw [weightedHomogeneousComponent_apply, sum_eq_zero] intro d hd; rw [mem_filter] at hd exfalso; exact h _ hd.1 hd.2 theorem weightedHomogeneousComponent_eq_zero [SemilatticeSup M] [OrderBot M] (h : weightedTotalDegree w φ < n) : weightedHomogeneousComponent w n φ = 0 := by classical rw [weightedHomogeneousComponent_apply, sum_eq_zero] intro d hd rw [Finset.mem_filter] at hd exfalso apply lt_irrefl n nth_rw 1 [← hd.2] exact lt_of_le_of_lt (le_weightedTotalDegree w hd.1) h theorem weightedHomogeneousComponent_finsupp : (Function.support fun m => weightedHomogeneousComponent w m φ).Finite := by apply ((fun d : σ →₀ ℕ => (weight w) d) '' (φ.support : Set (σ →₀ ℕ))).toFinite.subset intro m hm by_contra hm' apply hm (weightedHomogeneousComponent_eq_zero' m φ _) simpa only [Set.mem_image, not_exists, not_and] using hm' variable (w) /-- Every polynomial is the sum of its weighted homogeneous components. -/ theorem sum_weightedHomogeneousComponent : (finsum fun m => weightedHomogeneousComponent w m φ) = φ := by classical rw [finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)] ext1 d simp only [coeff_sum, coeff_weightedHomogeneousComponent] rw [Finset.sum_eq_single (weight w d)] · rw [if_pos rfl] · intro m _ hm' rw [if_neg hm'.symm] · intro hm rw [if_pos rfl] simp only [Finite.mem_toFinset, mem_support, Ne, Classical.not_not] at hm have := coeff_weightedHomogeneousComponent (w := w) (weight w d) φ d rw [hm, if_pos rfl, coeff_zero] at this exact this.symm theorem finsum_weightedHomogeneousComponent : (finsum fun m => weightedHomogeneousComponent w m φ) = φ := by rw [sum_weightedHomogeneousComponent] variable {w} theorem IsWeightedHomogeneous.weightedHomogeneousComponent_same {m : M} {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : weightedHomogeneousComponent w m p = p := by classical ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · split_ifs · rfl rw [zero_coeff] · rw [hp zero_coeff, if_pos rfl] theorem IsWeightedHomogeneous.weightedHomogeneousComponent_ne {m : M} (n : M) {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : n ≠ m → weightedHomogeneousComponent w n p = 0 := by classical intro hn ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · simp [zero_coeff] · rw [if_neg] · rw [coeff_zero] · rw [hp zero_coeff]; exact Ne.symm hn /-- The weighted homogeneous components of a weighted homogeneous polynomial. -/ theorem weightedHomogeneousComponent_of_mem [DecidableEq M] {m n : M} {p : MvPolynomial σ R} (h : p ∈ weightedHomogeneousSubmodule R w n) : weightedHomogeneousComponent w m p = if m = n then p else 0 := by simp only [mem_weightedHomogeneousSubmodule] at h ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · split_ifs <;> simp only [zero_coeff, coeff_zero] · rw [h zero_coeff] simp only [show n = m ↔ m = n from eq_comm] split_ifs with h1 · rfl · simp only [coeff_zero] theorem weightedHomogeneousComponent_of_isWeightedHomogeneous_same {m : M} {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) : weightedHomogeneousComponent w m p = p := by classical ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · simp [zero_coeff] · rw [hp zero_coeff, if_pos rfl] theorem weightedHomogeneousComponent_of_isWeightedHomogeneous_ne {m n : M} {p : MvPolynomial σ R} (hp : IsWeightedHomogeneous w p m) (hn : n ≠ m) : weightedHomogeneousComponent w n p = 0 := by classical ext x rw [coeff_weightedHomogeneousComponent] by_cases zero_coeff : coeff x p = 0 · simp [zero_coeff] · rw [if_neg (by simp only [hp zero_coeff, hn.symm, not_false_eq_true]), coeff_zero] variable (R w) open DirectSum theorem DirectSum.coeLinearMap_eq_dfinsuppSum [DecidableEq σ] [DecidableEq R] [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) : (coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x = DFinsupp.sum x (fun _ x => ↑x) := by rw [_root_.DirectSum.coeLinearMap_eq_dfinsuppSum] theorem DirectSum.coeAddMonoidHom_eq_support_sum [DecidableEq σ] [DecidableEq R] [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) : (DirectSum.coeAddMonoidHom fun i : M => weightedHomogeneousSubmodule R w i) x = DFinsupp.sum x (fun _ x => ↑x) := DirectSum.coeLinearMap_eq_dfinsuppSum R w x theorem DirectSum.coeLinearMap_eq_finsum [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) : (DirectSum.coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x = finsum fun m => x m := by classical rw [DirectSum.coeLinearMap_eq_dfinsuppSum, DFinsupp.sum, finsum_eq_sum_of_support_subset] apply DirectSum.support_subset theorem weightedHomogeneousComponent_directSum [DecidableEq M] (x : DirectSum M fun i : M => ↥(weightedHomogeneousSubmodule R w i)) (m : M) : (weightedHomogeneousComponent w m) ((DirectSum.coeLinearMap fun i : M => weightedHomogeneousSubmodule R w i) x) = x m := by classical rw [DirectSum.coeLinearMap_eq_dfinsuppSum, DFinsupp.sum, map_sum] convert @Finset.sum_eq_single M (MvPolynomial σ R) _ (DFinsupp.support x) _ m _ _ · rw [weightedHomogeneousComponent_of_isWeightedHomogeneous_same (x m).prop] · intro n _ hmn rw [weightedHomogeneousComponent_of_isWeightedHomogeneous_ne (x n).prop hmn.symm] · rw [DFinsupp.notMem_support_iff] intro hm; rw [hm, Submodule.coe_zero, map_zero] end WeightedHomogeneousComponent end AddCommMonoid section OrderedAddCommMonoid variable [AddCommMonoid M] [PartialOrder M] {w : σ → M} (φ : MvPolynomial σ R) /-- If `M` is a canonically `OrderedAddCommMonoid`, then the `weightedHomogeneousComponent` of weighted degree `0` of a polynomial is its constant coefficient. -/ @[simp] theorem weightedHomogeneousComponent_zero [CanonicallyOrderedAdd M] [NoZeroSMulDivisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) : weightedHomogeneousComponent w 0 φ = C (coeff 0 φ) := by classical ext1 d rcases Classical.em (d = 0) with (rfl | hd) · simp only [coeff_weightedHomogeneousComponent, if_pos, map_zero, coeff_zero_C] · rw [coeff_weightedHomogeneousComponent, if_neg, coeff_C, if_neg (Ne.symm hd)] simp only [weight, LinearMap.toAddMonoidHom_coe, Finsupp.linearCombination_apply, Finsupp.sum, sum_eq_zero_iff, Finsupp.mem_support_iff, Ne, smul_eq_zero, not_forall, not_or, and_self_left, exists_prop] simp only [DFunLike.ext_iff, Finsupp.coe_zero, Pi.zero_apply, not_forall] at hd obtain ⟨i, hi⟩ := hd exact ⟨i, hi, hw i⟩ /-- A weight function is nontorsion if its values are not torsion. -/ def NonTorsionWeight (w : σ → M) := ∀ n x, n • w x = (0 : M) → n = 0 omit [PartialOrder M] in theorem nonTorsionWeight_of [NoZeroSMulDivisors ℕ M] (hw : ∀ i : σ, w i ≠ 0) : NonTorsionWeight w := fun _ x hnx => (smul_eq_zero_iff_left (hw x)).mp hnx /-- If `w` is a nontorsion weight function, then the finitely supported function `m : σ →₀ ℕ` has weighted degree zero if and only if `∀ x : σ, m x = 0`. -/ theorem weightedDegree_eq_zero_iff [CanonicallyOrderedAdd M] (hw : NonTorsionWeight w) {m : σ →₀ ℕ} : weight w m = 0 ↔ ∀ x : σ, m x = 0 := by simp only [weight, Finsupp.linearCombination, LinearMap.toAddMonoidHom_coe, coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe, id_eq] rw [Finsupp.sum, Finset.sum_eq_zero_iff] apply forall_congr' intro x rw [Finsupp.mem_support_iff] constructor · intro hx by_contra hx' exact absurd (hw _ _ (hx hx')) hx' · intro hax _ simp only [hax, zero_smul] end OrderedAddCommMonoid section LinearOrderedAddCommMonoid variable [AddCommMonoid M] [LinearOrder M] [OrderBot M] [CanonicallyOrderedAdd M] {w : σ → M} (φ : MvPolynomial σ R) /-- A multivariate polynomial is weighted homogeneous of weighted degree zero if and only if its weighted total degree is equal to zero. -/ theorem isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero {p : MvPolynomial σ R} : IsWeightedHomogeneous w p 0 ↔ p.weightedTotalDegree w = 0 := by rw [weightedTotalDegree, ← bot_eq_zero, Finset.sup_eq_bot_iff, bot_eq_zero, IsWeightedHomogeneous] apply forall_congr' intro m rw [mem_support_iff] /-- If `w` is a nontorsion weight function, then a multivariate polynomial has weighted total degree zero if and only if for every `m ∈ p.support` and `x : σ`, `m x = 0`. -/ theorem weightedTotalDegree_eq_zero_iff (hw : NonTorsionWeight w) (p : MvPolynomial σ R) : p.weightedTotalDegree w = 0 ↔ ∀ (m : σ →₀ ℕ) (_ : m ∈ p.support) (x : σ), m x = 0 := by rw [← isWeightedHomogeneous_zero_iff_weightedTotalDegree_eq_zero, IsWeightedHomogeneous] apply forall_congr' intro m rw [mem_support_iff] apply forall_congr' intro _ exact weightedDegree_eq_zero_iff hw end LinearOrderedAddCommMonoid section GradedAlgebra /- Here, given a weight `w : σ → M`, where `M` is an additive and commutative monoid, we endow the ring of multivariate polynomials `MvPolynomial σ R` with the structure of a graded algebra -/ variable (w : σ → M) [AddCommMonoid M] theorem weightedHomogeneousComponent_eq_zero_of_notMem [DecidableEq M] (φ : MvPolynomial σ R) (i : M) (hi : i ∉ Finset.image (weight w) φ.support) : weightedHomogeneousComponent w i φ = 0 := by apply weightedHomogeneousComponent_eq_zero' simp only [Finset.mem_image, mem_support_iff, ne_eq, not_exists, not_and] at hi exact fun m hm ↦ hi m (mem_support_iff.mp hm) @[deprecated (since := "2025-05-23")] alias weightedHomogeneousComponent_eq_zero_of_not_mem := weightedHomogeneousComponent_eq_zero_of_notMem variable (R) /-- The `decompose'` argument of `weightedDecomposition`. -/ def decompose' [DecidableEq M] := fun φ : MvPolynomial σ R => DirectSum.mk (fun i : M => ↥(weightedHomogeneousSubmodule R w i)) (Finset.image (weight w) φ.support) fun m => ⟨weightedHomogeneousComponent w m φ, weightedHomogeneousComponent_mem w φ m⟩ theorem decompose'_apply [DecidableEq M] (φ : MvPolynomial σ R) (m : M) : (decompose' R w φ m : MvPolynomial σ R) = weightedHomogeneousComponent w m φ := by rw [decompose'] by_cases hm : m ∈ Finset.image (weight w) φ.support · simp only [DirectSum.mk_apply_of_mem hm, Subtype.coe_mk] · rw [DirectSum.mk_apply_of_notMem hm, Submodule.coe_zero, weightedHomogeneousComponent_eq_zero_of_notMem w φ m hm] /-- Given a weight `w`, the decomposition of `MvPolynomial σ R` into weighted homogeneous submodules -/ def weightedDecomposition [DecidableEq M] : DirectSum.Decomposition (weightedHomogeneousSubmodule R w) where decompose' := decompose' R w left_inv φ := by classical conv_rhs => rw [← sum_weightedHomogeneousComponent w φ] rw [← DirectSum.sum_support_of (decompose' R w φ)] simp only [DirectSum.coeAddMonoidHom_of, map_sum, finsum_eq_sum _ (weightedHomogeneousComponent_finsupp φ)] apply Finset.sum_congr _ (fun m _ ↦ by rw [decompose'_apply]) ext m simp only [DFinsupp.mem_support_toFun, ne_eq, Set.Finite.mem_toFinset, Function.mem_support, not_iff_not] conv_lhs => rw [← Subtype.coe_inj] rw [decompose'_apply, Submodule.coe_zero] right_inv x := by classical apply DFinsupp.ext intro m rw [← Subtype.coe_inj, decompose'_apply] exact weightedHomogeneousComponent_directSum R w x m /-- Given a weight, `MvPolynomial` as a graded algebra -/ def weightedGradedAlgebra [DecidableEq M] : GradedAlgebra (weightedHomogeneousSubmodule R w) where toDecomposition := weightedDecomposition R w toGradedMonoid := WeightedHomogeneousSubmodule.gradedMonoid theorem weightedDecomposition.decompose'_eq [DecidableEq M] : (weightedDecomposition R w).decompose' = fun φ : MvPolynomial σ R => DirectSum.mk (fun i : M => ↥(weightedHomogeneousSubmodule R w i)) (Finset.image (weight w) φ.support) fun m => ⟨weightedHomogeneousComponent w m φ, weightedHomogeneousComponent_mem w φ m⟩ := rfl theorem weightedDecomposition.decompose'_apply [DecidableEq M] (φ : MvPolynomial σ R) (m : M) : ((weightedDecomposition R w).decompose' φ m : MvPolynomial σ R) = weightedHomogeneousComponent w m φ := MvPolynomial.decompose'_apply R w φ m end GradedAlgebra end MvPolynomial
Basic.lean
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Normed.Ring.InfiniteSum import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.NumberTheory.SmoothNumbers /-! # Euler Products The main result in this file is `EulerProduct.eulerProduct_hasProd`, which says that if `f : ℕ → R` is norm-summable, where `R` is a complete normed commutative ring and `f` is multiplicative on coprime arguments with `f 0 = 0`, then `∏' p : Primes, ∑' e : ℕ, f (p^e)` converges to `∑' n, f n`. `ArithmeticFunction.IsMultiplicative.eulerProduct_hasProd` is a version for multiplicative arithmetic functions in the sense of `ArithmeticFunction.IsMultiplicative`. There is also a version `EulerProduct.eulerProduct_completely_multiplicative_hasProd`, which states that `∏' p : Primes, (1 - f p)⁻¹` converges to `∑' n, f n` when `f` is completely multiplicative with values in a complete normed field `F` (implemented as `f : ℕ →*₀ F`). There are variants stating the equality of the infinite product and the infinite sum (`EulerProduct.eulerProduct_tprod`, `ArithmeticFunction.IsMultiplicative.eulerProduct_tprod`, `EulerProduct.eulerProduct_completely_multiplicative_tprod`) and also variants stating the convergence of the sequence of partial products over primes `< n` (`EulerProduct.eulerProduct`, `ArithmeticFunction.IsMultiplicative.eulerProduct`, `EulerProduct.eulerProduct_completely_multiplicative`.) An intermediate step is `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum` (and its variant `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric`), which relates the finite product over primes `p ∈ s` to the sum of `f n` over `s`-factored `n`, for `s : Finset ℕ`. ## Tags Euler product, multiplicative function -/ /-- If `f` is multiplicative and summable, then its values at natural numbers `> 1` have norm strictly less than `1`. -/ lemma Summable.norm_lt_one {F : Type*} [NormedDivisionRing F] [CompleteSpace F] {f : ℕ →* F} (hsum : Summable f) {p : ℕ} (hp : 1 < p) : ‖f p‖ < 1 := by refine summable_geometric_iff_norm_lt_one.mp ?_ simp_rw [← map_pow] exact hsum.comp_injective <| Nat.pow_right_injective hp open scoped Topology open Nat Finset section General /-! ### General Euler Products In this section we consider multiplicative (on coprime arguments) functions `f : ℕ → R`, where `R` is a complete normed commutative ring. The main result is `EulerProduct.eulerProduct`. -/ variable {R : Type*} [NormedCommRing R] {f : ℕ → R} -- local instance to speed up typeclass search @[local instance] private lemma instT0Space : T0Space R := MetricSpace.instT0Space variable [CompleteSpace R] namespace EulerProduct variable (hf₁ : f 1 = 1) (hmul : ∀ {m n}, Nat.Coprime m n → f (m * n) = f m * f n) include hf₁ hmul in /-- We relate a finite product over primes in `s` to an infinite sum over `s`-factored numbers. -/ lemma summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum (hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (s : Finset ℕ) : Summable (fun m : factoredNumbers s ↦ ‖f m‖) ∧ HasSum (fun m : factoredNumbers s ↦ f m) (∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n)) := by induction s using Finset.induction with | empty => rw [factoredNumbers_empty] simp only [notMem_empty, IsEmpty.forall_iff, forall_const, filter_true_of_mem, prod_empty] exact ⟨(Set.finite_singleton 1).summable (‖f ·‖), hf₁ ▸ hasSum_singleton 1 f⟩ | insert p s hp ih => rw [filter_insert] split_ifs with hpp · constructor · simp only [← (equivProdNatFactoredNumbers hpp hp).summable_iff, Function.comp_def, equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp] refine Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_mul_le ..) ?_ apply Summable.mul_of_nonneg (hsum hpp) ih.1 <;> exact fun n ↦ norm_nonneg _ · have hp' : p ∉ {p ∈ s | p.Prime} := mt (mem_of_mem_filter p) hp rw [prod_insert hp', ← (equivProdNatFactoredNumbers hpp hp).hasSum_iff, Function.comp_def] conv => enter [1, x] rw [equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp] have : T3Space R := instT3Space -- speeds up the following apply (hsum hpp).of_norm.hasSum.mul ih.2 -- `exact summable_mul_of_summable_norm (hsum hpp) ih.1` gives a time-out apply summable_mul_of_summable_norm (hsum hpp) ih.1 · rwa [factoredNumbers_insert s hpp] include hf₁ hmul in /-- A version of `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum` in terms of the value of the series. -/ lemma prod_filter_prime_tsum_eq_tsum_factoredNumbers (hsum : Summable (‖f ·‖)) (s : Finset ℕ) : ∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n) = ∑' m : factoredNumbers s, f m := (summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul (fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm /-- The following statement says that summing over `s`-factored numbers such that `s` contains `primesBelow N` for large enough `N` gets us arbitrarily close to the sum over all natural numbers (assuming `f` is summable and `f 0 = 0`; the latter since `0` is not `s`-factored). -/ lemma norm_tsum_factoredNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0) {ε : ℝ} (εpos : 0 < ε) : ∃ N : ℕ, ∀ s : Finset ℕ, primesBelow N ≤ s → ‖(∑' m : ℕ, f m) - ∑' m : factoredNumbers s, f m‖ < ε := by obtain ⟨N, hN⟩ := summable_iff_nat_tsum_vanishing.mp hsum (Metric.ball 0 ε) <| Metric.ball_mem_nhds 0 εpos simp_rw [mem_ball_zero_iff] at hN refine ⟨N, fun s hs ↦ ?_⟩ have := hN _ <| factoredNumbers_compl hs rwa [← hsum.tsum_subtype_add_tsum_subtype_compl (factoredNumbers s), add_sub_cancel_left, tsum_eq_tsum_diff_singleton (factoredNumbers s)ᶜ hf₀] -- Versions of the three lemmas above for `smoothNumbers N` include hf₁ hmul in /-- We relate a finite product over primes to an infinite sum over smooth numbers. -/ lemma summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum (hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (N : ℕ) : Summable (fun m : N.smoothNumbers ↦ ‖f m‖) ∧ HasSum (fun m : N.smoothNumbers ↦ f m) (∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n)) := by rw [smoothNumbers_eq_factoredNumbers, primesBelow] exact summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul hsum _ include hf₁ hmul in /-- A version of `EulerProduct.summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum` in terms of the value of the series. -/ lemma prod_primesBelow_tsum_eq_tsum_smoothNumbers (hsum : Summable (‖f ·‖)) (N : ℕ) : ∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n) = ∑' m : N.smoothNumbers, f m := (summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum hf₁ hmul (fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm /-- The following statement says that summing over `N`-smooth numbers for large enough `N` gets us arbitrarily close to the sum over all natural numbers (assuming `f` is norm-summable and `f 0 = 0`; the latter since `0` is not smooth). -/ lemma norm_tsum_smoothNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0) {ε : ℝ} (εpos : 0 < ε) : ∃ N₀ : ℕ, ∀ N ≥ N₀, ‖(∑' m : ℕ, f m) - ∑' m : N.smoothNumbers, f m‖ < ε := by conv => enter [1, N₀, N]; rw [smoothNumbers_eq_factoredNumbers] obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum hf₀ εpos refine ⟨N₀, fun N hN ↦ hN₀ (range N) fun p hp ↦ ?_⟩ exact mem_range.mpr <| (lt_of_mem_primesBelow hp).trans_le hN include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated using `HasProd`. -/ theorem eulerProduct_hasProd (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : HasProd (fun p : Primes ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by let F : ℕ → R := fun n ↦ ∑' e, f (n ^ e) change HasProd (F ∘ Subtype.val) _ rw [hasProd_subtype_iff_mulIndicator, show Set.mulIndicator (fun p : ℕ ↦ Irreducible p) = {p | Nat.Prime p}.mulIndicator from rfl, HasProd, Metric.tendsto_atTop] intro ε hε obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum.of_norm hf₀ hε refine ⟨range N₀, fun s hs ↦ ?_⟩ have : ∏ p ∈ s, {p | Nat.Prime p}.mulIndicator F p = ∏ p ∈ s with p.Prime, F p := prod_mulIndicator_eq_prod_filter s (fun _ ↦ F) _ id rw [this, dist_eq_norm, prod_filter_prime_tsum_eq_tsum_factoredNumbers hf₁ hmul hsum, norm_sub_rev] exact hN₀ s fun p hp ↦ hs <| mem_range.mpr <| lt_of_mem_primesBelow hp include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` i multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : ℕ, if p.Prime then ∑' e, f (p ^ e) else 1 = ∑' n, f n`. This version is stated using `HasProd` and `Set.mulIndicator`. -/ theorem eulerProduct_hasProd_mulIndicator (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : HasProd (Set.mulIndicator {p | Nat.Prime p} fun p ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by rw [← hasProd_subtype_iff_mulIndicator] exact eulerProduct_hasProd hf₁ hmul hsum hf₀ open Filter in include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : {p : ℕ | p.Prime}, ∑' e, f (p ^ e) = ∑' n, f n`. This is a version using convergence of finite partial products. -/ theorem eulerProduct (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, ∑' e, f (p ^ e)) atTop (𝓝 (∑' n, f n)) := by have := (eulerProduct_hasProd_mulIndicator hf₁ hmul hsum hf₀).tendsto_prod_nat let F : ℕ → R := fun p ↦ ∑' (e : ℕ), f (p ^ e) have H (n : ℕ) : ∏ i ∈ range n, Set.mulIndicator {p | Nat.Prime p} F i = ∏ p ∈ primesBelow n, ∑' (e : ℕ), f (p ^ e) := prod_mulIndicator_eq_prod_filter (range n) (fun _ ↦ F) (fun _ ↦ {p | Nat.Prime p}) id simpa only [F, H] include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : {p : ℕ | p.Prime}, ∑' e, f (p ^ e) = ∑' n, f n`. -/ theorem eulerProduct_tprod (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : ∏' p : Primes, ∑' e, f (p ^ e) = ∑' n, f n := (eulerProduct_hasProd hf₁ hmul hsum hf₀).tprod_eq end EulerProduct /-! ### Versions for arithmetic functions -/ namespace ArithmeticFunction open EulerProduct /-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a complete normed commutative ring `R`: if `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated in terms of `HasProd`. -/ nonrec theorem IsMultiplicative.eulerProduct_hasProd {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) : HasProd (fun p : Primes ↦ ∑' e, f (p ^ e)) (∑' n, f n) := eulerProduct_hasProd hf.1 hf.2 hsum f.map_zero open Filter in /-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a complete normed commutative ring `R`: if `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated in the form of convergence of finite partial products. -/ nonrec theorem IsMultiplicative.eulerProduct {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) : Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, ∑' e, f (p ^ e)) atTop (𝓝 (∑' n, f n)) := eulerProduct hf.1 hf.2 hsum f.map_zero /-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a complete normed commutative ring `R`: if `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. -/ nonrec theorem IsMultiplicative.eulerProduct_tprod {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) : ∏' p : Primes, ∑' e, f (p ^ e) = ∑' n, f n := eulerProduct_tprod hf.1 hf.2 hsum f.map_zero end ArithmeticFunction end General section CompletelyMultiplicative /-! ### Euler Products for completely multiplicative functions We now assume that `f` is completely multiplicative and has values in a complete normed field `F`. Then we can use the formula for geometric series to simplify the statement. This leads to `EulerProduct.eulerProduct_completely_multiplicative_hasProd` and variants. -/ variable {F : Type*} [NormedField F] [CompleteSpace F] namespace EulerProduct -- a helper lemma that is useful below lemma one_sub_inv_eq_geometric_of_summable_norm {f : ℕ →*₀ F} {p : ℕ} (hp : p.Prime) (hsum : Summable fun x ↦ ‖f x‖) : (1 - f p)⁻¹ = ∑' (e : ℕ), f (p ^ e) := by simp only [map_pow] refine (tsum_geometric_of_norm_lt_one <| summable_geometric_iff_norm_lt_one.mp ?_).symm refine Summable.of_norm ?_ simpa only [Function.comp_def, map_pow] using hsum.comp_injective <| Nat.pow_right_injective hp.one_lt /-- Given a (completely) multiplicative function `f : ℕ → F`, where `F` is a normed field, such that `‖f p‖ < 1` for all primes `p`, we can express the sum of `f n` over all `s`-factored positive integers `n` as a product of `(1 - f p)⁻¹` over the primes `p ∈ s`. At the same time, we show that the sum involved converges absolutely. -/ lemma summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric {f : ℕ →* F} (h : ∀ {p : ℕ}, p.Prime → ‖f p‖ < 1) (s : Finset ℕ) : Summable (fun m : factoredNumbers s ↦ ‖f m‖) ∧ HasSum (fun m : factoredNumbers s ↦ f m) (∏ p ∈ s with p.Prime, (1 - f p)⁻¹) := by have hmul {m n} (_ : Nat.Coprime m n) := f.map_mul m n have H₁ : ∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n) = ∏ p ∈ s with p.Prime, (1 - f p)⁻¹ := by refine prod_congr rfl fun p hp ↦ ?_ simp only [map_pow] exact tsum_geometric_of_norm_lt_one <| h (mem_filter.mp hp).2 have H₂ : ∀ {p : ℕ}, p.Prime → Summable fun n ↦ ‖f (p ^ n)‖ := by intro p hp simp only [map_pow] refine Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_pow_le ..) ?_ exact summable_geometric_iff_norm_lt_one.mpr <| (norm_norm (f p)).symm ▸ h hp exact H₁ ▸ summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum f.map_one hmul H₂ s /-- A version of `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric` in terms of the value of the series. -/ lemma prod_filter_prime_geometric_eq_tsum_factoredNumbers {f : ℕ →* F} (hsum : Summable f) (s : Finset ℕ) : ∏ p ∈ s with p.Prime, (1 - f p)⁻¹ = ∑' m : factoredNumbers s, f m := by refine (summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric ?_ s).2.tsum_eq.symm exact fun {_} hp ↦ hsum.norm_lt_one hp.one_lt /-- Given a (completely) multiplicative function `f : ℕ → F`, where `F` is a normed field, such that `‖f p‖ < 1` for all primes `p`, we can express the sum of `f n` over all `N`-smooth positive integers `n` as a product of `(1 - f p)⁻¹` over the primes `p < N`. At the same time, we show that the sum involved converges absolutely. -/ lemma summable_and_hasSum_smoothNumbers_prod_primesBelow_geometric {f : ℕ →* F} (h : ∀ {p : ℕ}, p.Prime → ‖f p‖ < 1) (N : ℕ) : Summable (fun m : N.smoothNumbers ↦ ‖f m‖) ∧ HasSum (fun m : N.smoothNumbers ↦ f m) (∏ p ∈ N.primesBelow, (1 - f p)⁻¹) := by rw [smoothNumbers_eq_factoredNumbers, primesBelow] exact summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric h _ /-- A version of `EulerProduct.summable_and_hasSum_smoothNumbers_prod_primesBelow_geometric` in terms of the value of the series. -/ lemma prod_primesBelow_geometric_eq_tsum_smoothNumbers {f : ℕ →* F} (hsum : Summable f) (N : ℕ) : ∏ p ∈ N.primesBelow, (1 - f p)⁻¹ = ∑' m : N.smoothNumbers, f m := by rw [smoothNumbers_eq_factoredNumbers, primesBelow] exact prod_filter_prime_geometric_eq_tsum_factoredNumbers hsum _ /-- The *Euler Product* for completely multiplicative functions. If `f : ℕ →*₀ F`, where `F` is a complete normed field and `‖f ·‖` is summable, then `∏' p : Nat.Primes, (1 - f p)⁻¹ = ∑' n, f n`. This version is stated in terms of `HasProd`. -/ theorem eulerProduct_completely_multiplicative_hasProd {f : ℕ →*₀ F} (hsum : Summable (‖f ·‖)) : HasProd (fun p : Primes ↦ (1 - f p)⁻¹) (∑' n, f n) := by have H : (fun p : Primes ↦ (1 - f p)⁻¹) = fun p : Primes ↦ ∑' (e : ℕ), f (p ^ e) := funext <| fun p ↦ one_sub_inv_eq_geometric_of_summable_norm p.prop hsum simpa only [map_pow, H] using eulerProduct_hasProd f.map_one (fun {m n} _ ↦ f.map_mul m n) hsum f.map_zero /-- The *Euler Product* for completely multiplicative functions. If `f : ℕ →*₀ F`, where `F` is a complete normed field and `‖f ·‖` is summable, then `∏' p : Nat.Primes, (1 - f p)⁻¹ = ∑' n, f n`. -/ theorem eulerProduct_completely_multiplicative_tprod {f : ℕ →*₀ F} (hsum : Summable (‖f ·‖)) : ∏' p : Primes, (1 - f p)⁻¹ = ∑' n, f n := (eulerProduct_completely_multiplicative_hasProd hsum).tprod_eq open Filter in /-- The *Euler Product* for completely multiplicative functions. If `f : ℕ →*₀ F`, where `F` is a complete normed field and `‖f ·‖` is summable, then `∏' p : Nat.Primes, (1 - f p)⁻¹ = ∑' n, f n`. This version is stated in the form of convergence of finite partial products. -/ theorem eulerProduct_completely_multiplicative {f : ℕ →*₀ F} (hsum : Summable (‖f ·‖)) : Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, (1 - f p)⁻¹) atTop (𝓝 (∑' n, f n)) := by have hmul {m n} (_ : Nat.Coprime m n) := f.map_mul m n have := (eulerProduct_hasProd_mulIndicator f.map_one hmul hsum f.map_zero).tendsto_prod_nat have H (n : ℕ) : ∏ p ∈ range n, {p | Nat.Prime p}.mulIndicator (fun p ↦ (1 - f p)⁻¹) p = ∏ p ∈ primesBelow n, (1 - f p)⁻¹ := prod_mulIndicator_eq_prod_filter (range n) (fun _ ↦ fun p ↦ (1 - f p)⁻¹) (fun _ ↦ {p | Nat.Prime p}) id have H' : {p | Nat.Prime p}.mulIndicator (fun p ↦ (1 - f p)⁻¹) = {p | Nat.Prime p}.mulIndicator (fun p ↦ ∑' e : ℕ, f (p ^ e)) := Set.mulIndicator_congr fun p hp ↦ one_sub_inv_eq_geometric_of_summable_norm hp hsum simpa only [← H, H'] using this end EulerProduct end CompletelyMultiplicative
burnside_app.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div. From mathcomp Require Import choice fintype tuple finfun bigop finset fingroup. From mathcomp Require Import action perm primitive_action ssrAC. (* Application of the Burside formula to count the number of distinct *) (* colorings of the vertices of a square and a cube. *) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Import GroupScope. Lemma burnside_formula : forall (gT : finGroupType) s (G : {group gT}), uniq s -> s =i G -> forall (sT : finType) (to : {action gT &-> sT}), (#|orbit to G @: setT| * size s)%N = \sum_(p <- s) #|'Fix_to[p]|. Proof. move=> gT s G Us sG sT to. rewrite big_uniq // -(card_uniqP Us) (eq_card sG) -Frobenius_Cauchy. by apply: eq_big => // p _; rewrite setTI. by apply/actsP=> ? _ ?; rewrite !inE. Qed. Arguments burnside_formula {gT}. Section colouring. Variable n : nat. Definition colors := 'I_n. HB.instance Definition _ := Finite.on colors. Section square_colouring. Definition square := 'I_4. HB.instance Definition _ := SubType.on square. HB.instance Definition _ := Finite.on square. Definition mksquare i : square := Sub (i %% _) (ltn_mod i 4). Definition c0 := mksquare 0. Definition c1 := mksquare 1. Definition c2 := mksquare 2. Definition c3 := mksquare 3. (*rotations*) Definition R1 (sc : square) : square := tnth [tuple c1; c2; c3; c0] sc. Definition R2 (sc : square) : square := tnth [tuple c2; c3; c0; c1] sc. Definition R3 (sc : square) : square := tnth [tuple c3; c0; c1; c2] sc. Ltac get_inv elt l := match l with | (_, (elt, ?x)) => x | (elt, ?x) => x | (?x, _) => get_inv elt x end. Definition rot_inv := ((R1, R3), (R2, R2), (R3, R1)). Ltac inj_tac := move: (erefl rot_inv); unfold rot_inv; match goal with |- ?X = _ -> injective ?Y => move=> _; let x := get_inv Y X in apply: (can_inj (g:=x)); move=> [val H1] end. Lemma R1_inj : injective R1. Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed. Lemma R2_inj : injective R2. Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed. Lemma R3_inj : injective R3. Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed. Definition r1 := (perm R1_inj). Definition r2 := (perm R2_inj). Definition r3 := (perm R3_inj). Definition id1 := (1 : {perm square}). Definition is_rot (r : {perm _}) := (r * r1 == r1 * r). Definition rot := [set r | is_rot r]. Lemma group_set_rot : group_set rot. Proof. apply/group_setP; split; first by rewrite /rot inE /is_rot mulg1 mul1g. move=> x1 y; rewrite /rot !inE /= /is_rot; move/eqP => hx1; move/eqP => hy. by rewrite -mulgA hy !mulgA hx1. Qed. Canonical rot_group := Group group_set_rot. Definition rotations := [set id1; r1; r2; r3]. Lemma rot_eq_c0 : forall r s : {perm square}, is_rot r -> is_rot s -> r c0 = s c0 -> r = s. Proof. rewrite /is_rot => r s; move/eqP => hr; move/eqP=> hs hrs; apply/permP => a. have ->: a = (r1 ^+ a) c0 by apply/eqP; case: a; do 4?case=> //=; rewrite ?permM !permE. by rewrite -!permM -!commuteX // !permM hrs. Qed. Lemma rot_r1 : forall r, is_rot r -> r = r1 ^+ (r c0). Proof. move=> r hr; apply: rot_eq_c0 => //; apply/eqP. by symmetry; apply: commuteX. by case: (r c0); do 4?case=> //=; rewrite ?permM !permE /=. Qed. Lemma rotations_is_rot : forall r, r \in rotations -> is_rot r. Proof. move=> r Dr; apply/eqP; apply/permP => a; rewrite !inE -!orbA !permM in Dr *. by case/or4P: Dr; move/eqP->; rewrite !permE //; case: a; do 4?case. Qed. Lemma rot_is_rot : rot = rotations. Proof. apply/setP=> r; apply/idP/idP => [|/rotations_is_rot] /[!inE]// h. have -> : r = r1 ^+ (r c0) by apply: rot_eq_c0; rewrite // -rot_r1. have e2: 2 = r2 c0 by rewrite permE /=. have e3: 3 = r3 c0 by rewrite permE /=. case (r c0); do 4?[case] => // ?; rewrite ?(expg1, eqxx, orbT) //. by rewrite [nat_of_ord _]/= e2 -rot_r1 ?(eqxx, orbT, rotations_is_rot, inE). by rewrite [nat_of_ord _]/= e3 -rot_r1 ?(eqxx, orbT, rotations_is_rot, inE). Qed. (*symmetries*) Definition Sh (sc : square) : square := tnth [tuple c1; c0; c3; c2] sc. Lemma Sh_inj : injective Sh. Proof. by apply: (can_inj (g:= Sh)); case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sh := (perm Sh_inj). Lemma sh_inv : sh^-1 = sh. Proof. apply: (mulIg sh); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Definition Sv (sc : square) : square := tnth [tuple c3; c2; c1; c0] sc. Lemma Sv_inj : injective Sv. Proof. by apply: (can_inj (g:= Sv)); case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sv := (perm Sv_inj). Lemma sv_inv : sv^-1 = sv. Proof. apply: (mulIg sv); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Definition Sd1 (sc : square) : square := tnth [tuple c0; c3; c2; c1] sc. Lemma Sd1_inj : injective Sd1. Proof. by apply: can_inj Sd1 _; case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sd1 := (perm Sd1_inj). Lemma sd1_inv : sd1^-1 = sd1. Proof. apply: (mulIg sd1); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Definition Sd2 (sc : square) : square := tnth [tuple c2; c1; c0; c3] sc. Lemma Sd2_inj : injective Sd2. Proof. by apply: can_inj Sd2 _; case; do 4?case=> //=; move=> H; apply/eqP. Qed. Definition sd2 := (perm Sd2_inj). Lemma sd2_inv : sd2^-1 = sd2. Proof. apply: (mulIg sd2); rewrite mulVg; apply/permP. by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP. Qed. Lemma ord_enum4 : enum 'I_4 = [:: c0; c1; c2; c3]. Proof. by apply: (inj_map val_inj); rewrite val_enum_ord. Qed. Lemma diff_id_sh : 1 != sh. Proof. by apply/eqP; move/(congr1 (fun p : {perm square} => p c0)); rewrite !permE. Qed. Definition isometries2 := [set 1; sh]. Lemma card_iso2 : #|isometries2| = 2. Proof. by rewrite cards2 diff_id_sh. Qed. Lemma group_set_iso2 : group_set isometries2. Proof. apply/group_setP; split => [|x y]; rewrite !inE ?eqxx //. do 2![case/orP; move/eqP->]; rewrite ?(mul1g, mulg1) ?eqxx ?orbT//. by rewrite -/sh -{1}sh_inv mulVg eqxx. Qed. Canonical iso2_group := Group group_set_iso2. Definition isometries := [set p | [|| p == 1, p == r1, p == r2, p == r3, p == sh, p == sv, p == sd1 | p == sd2 ]]. Definition opp (sc : square) := tnth [tuple c2; c3; c0; c1] sc. Definition is_iso (p : {perm square}) := forall ci, p (opp ci) = opp (p ci). Lemma isometries_iso : forall p, p \in isometries -> is_iso p. Proof. move=> p; rewrite inE. by do ?case/orP; move/eqP=> -> a; rewrite !permE; case: a; do 4?case. Qed. Ltac non_inj p a1 a2 heq1 heq2 := let h1:= fresh "h1" in (absurd (p a1 = p a2); first (by red => - h1; move: (perm_inj h1)); by rewrite heq1 heq2; apply/eqP). Ltac is_isoPtac p f e0 e1 e2 e3 := suff ->: p = f by [rewrite inE eqxx ?orbT]; let e := fresh "e" in apply/permP; (do 5?[case] => // ?; [move: e0 | move: e1 | move: e2 | move: e3]) => e; apply: etrans (congr1 p _) (etrans e _); apply/eqP; rewrite // permE. Lemma is_isoP : forall p, reflect (is_iso p) (p \in isometries). Proof. move=> p; apply: (iffP idP) => [|iso_p]; first exact: isometries_iso. move e1: (p c1) (iso_p c1) => k1; move e0: (p c0) (iso_p c0) k1 e1 => k0. case: k0 e0; do 4?[case] => //= ? e0 e2; do 5?[case] => //= ? e1 e3; try by [non_inj p c0 c1 e0 e1 | non_inj p c0 c3 e0 e3]. by is_isoPtac p id1 e0 e1 e2 e3. by is_isoPtac p sd1 e0 e1 e2 e3. by is_isoPtac p sh e0 e1 e2 e3. by is_isoPtac p r1 e0 e1 e2 e3. by is_isoPtac p sd2 e0 e1 e2 e3. by is_isoPtac p r2 e0 e1 e2 e3. by is_isoPtac p r3 e0 e1 e2 e3. by is_isoPtac p sv e0 e1 e2 e3. Qed. Lemma group_set_iso : group_set isometries. Proof. apply/group_setP; split; first by rewrite inE eqxx /=. by move=> x y hx hy; apply/is_isoP => ci; rewrite !permM !isometries_iso. Qed. Canonical iso_group := Group group_set_iso. Lemma card_rot : #|rot| = 4. Proof. rewrite -[4]/(size [:: id1; r1; r2; r3]) -(card_uniqP _). by apply: eq_card => x; rewrite rot_is_rot !inE -!orbA. by apply: map_uniq (fun p : {perm square} => p c0) _ _; rewrite /= !permE. Qed. Lemma group_set_rotations : group_set rotations. Proof. by rewrite -rot_is_rot group_set_rot. Qed. Canonical rotations_group := Group group_set_rotations. Notation col_squares := {ffun square -> colors}. Definition act_f (sc : col_squares) (p : {perm square}) : col_squares := [ffun z => sc (p^-1 z)]. Lemma act_f_1 : forall k, act_f k 1 = k. Proof. by move=> k; apply/ffunP=> a; rewrite ffunE invg1 permE. Qed. Lemma act_f_morph : forall k x y, act_f k (x * y) = act_f (act_f k x) y. Proof. by move=> k x y; apply/ffunP=> a; rewrite !ffunE invMg permE. Qed. Definition to := TotalAction act_f_1 act_f_morph. Definition square_coloring_number2 := #|orbit to isometries2 @: setT|. Definition square_coloring_number4 := #|orbit to rotations @: setT|. Definition square_coloring_number8 := #|orbit to isometries @: setT|. Lemma Fid : 'Fix_to(1) = setT. Proof. by apply/setP=> x /=; rewrite in_setT; apply/afix1P; apply: act1. Qed. Lemma card_Fid : #|'Fix_to(1)| = (n ^ 4)%N. Proof. rewrite -[4]card_ord -[n]card_ord -card_ffun_on Fid cardsE. by symmetry; apply: eq_card => f; apply/ffun_onP. Qed. Definition coin0 (sc : col_squares) : colors := sc c0. Definition coin1 (sc : col_squares) : colors := sc c1. Definition coin2 (sc : col_squares) : colors := sc c2. Definition coin3 (sc : col_squares) : colors := sc c3. Lemma eqperm_map : forall p1 p2 : col_squares, (p1 == p2) = all (fun s => p1 s == p2 s) [:: c0; c1; c2; c3]. Proof. move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/ffunP=> x. by apply/eqP; apply Ep12; case: x; do 4!case=> //. Qed. Lemma F_Sh : 'Fix_to[sh] = [set x | (coin0 x == coin1 x) && (coin2 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f sh_inv !ffunE !permE /=. by rewrite eq_sym (eq_sym (x c3)) andbT andbA !andbb. Qed. Lemma F_Sv : 'Fix_to[sv] = [set x | (coin0 x == coin3 x) && (coin2 x == coin1 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f sv_inv !ffunE !permE /=. by rewrite eq_sym andbT andbC (eq_sym (x c1)) andbA -andbA !andbb andbC. Qed. Ltac inv_tac := apply: esym (etrans _ (mul1g _)); apply: canRL (mulgK _) _; let a := fresh "a" in apply/permP => a; apply/eqP; rewrite permM !permE; case: a; do 4?case. Lemma r1_inv : r1^-1 = r3. Proof. by inv_tac. Qed. Lemma r2_inv : r2^-1 = r2. Proof. by inv_tac. Qed. Lemma r3_inv : r3^-1 = r1. Proof. by inv_tac. Qed. Lemma F_r2 : 'Fix_to[r2] = [set x | (coin0 x == coin2 x) && (coin1 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f r2_inv !ffunE !permE /=. by rewrite eq_sym andbT andbCA andbC (eq_sym (x c3)) andbA -andbA !andbb andbC. Qed. Lemma F_r1 : 'Fix_to[r1] = [set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&&(coin2 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f r1_inv !ffunE !permE andbC. by do 3![case E: {+}(_ == _); rewrite // {E}(eqP E)]; rewrite eqxx. Qed. Lemma F_r3 : 'Fix_to[r3] = [set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&&(coin2 x == coin3 x)]. Proof. apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f r3_inv !ffunE !permE /=. by do 3![case: eqVneq=> // <-]. Qed. Lemma card_n2 : forall x y z t : square, uniq [:: x; y; z; t] -> #|[set p : col_squares | (p x == p y) && (p z == p t)]| = (n ^ 2)%N. Proof. move=> x y z t Uxt; rewrite -[n]card_ord. pose f (p : col_squares) := (p x, p z); rewrite -(@card_in_image _ _ f). rewrite -mulnn -card_prod; apply: eq_card => [] [c d] /=; apply/imageP. rewrite (cat_uniq [::x; y]) in Uxt; case/and3P: Uxt => _. rewrite /= !orbF !andbT => /norP[] /[!inE] nxzt nyzt _. exists [ffun i => if pred2 x y i then c else d]. by rewrite inE !ffunE /= !eqxx orbT (negbTE nxzt) (negbTE nyzt) !eqxx. by rewrite {}/f !ffunE /= eqxx (negbTE nxzt). move=> p1 p2 /[!inE] /andP[p1y p1t] /andP[p2y p2t] [px pz]. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t]. by rewrite /= -(eqP p1y) -(eqP p1t) -(eqP p2y) -(eqP p2t) px pz !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxt) card_ord. Qed. Lemma card_n : #|[set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&& (coin2 x == coin3 x)]| = n. Proof. rewrite -[n]card_ord /coin0 /coin1 /coin2 /coin3. pose f (p : col_squares) := p c3; rewrite -(@card_in_image _ _ f). apply: eq_card => c /=; apply/imageP. exists ([ffun => c] : col_squares); last by rewrite /f ffunE. by rewrite /= inE !ffunE !eqxx. move=> p1 p2; rewrite /= !inE /f -!andbA => eqp1 eqp2 eqp12. apply/eqP; rewrite eqperm_map /= andbT. case/and3P: eqp1; do 3!move/eqP->; case/and3P: eqp2; do 3!move/eqP->. by rewrite !andbb eqp12. Qed. Lemma burnside_app2 : (square_coloring_number2 * 2 = n ^ 4 + n ^ 2)%N. Proof. rewrite (burnside_formula [:: id1; sh]) => [||p]; last first. - by rewrite !inE. - by rewrite /= inE diff_id_sh. by rewrite 2!big_cons big_nil addn0 {1}card_Fid F_Sh card_n2. Qed. Lemma burnside_app_rot : (square_coloring_number4 * 4 = n ^ 4 + n ^ 2 + 2 * n)%N. Proof. rewrite (burnside_formula [:: id1; r1; r2; r3]) => [||p]; last first. - by rewrite !inE !orbA. - by apply: map_uniq (fun p : {perm square} => p c0) _ _; rewrite /= !permE. rewrite !big_cons big_nil /= addn0 {1}card_Fid F_r1 F_r2 F_r3. by rewrite card_n card_n2 //= [n + _]addnC !addnA addn0. Qed. Lemma F_Sd1 : 'Fix_to[sd1] = [set x | coin1 x == coin3 x]. Proof. apply/setP => x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. rewrite /act_f sd1_inv !ffunE !permE /=. by rewrite !eqxx !andbT eq_sym /= andbb. Qed. Lemma card_n3 : forall x y : square, x != y -> #|[set k : col_squares | k x == k y]| = (n ^ 3)%N. Proof. move=> x y nxy; apply/eqP; case: (posnP n) => [n0|]. by rewrite n0; apply/existsP=> [] [p _]; case: (p c0) => i; rewrite n0. move/eqn_pmul2l <-; rewrite -expnS -card_Fid Fid cardsT. rewrite -{1}[n]card_ord -cardX. pose pk k := [ffun i => k (if i == y then x else i) : colors]. rewrite -(@card_image _ _ (fun k : col_squares => (k y, pk k))). apply/eqP; apply: eq_card => ck /=; rewrite inE /= [_ \in _]inE. apply/eqP/imageP; last first. by case=> k _ -> /=; rewrite !ffunE if_same eqxx. case: ck => c k /= kxy. exists [ffun i => if i == y then c else k i]; first by rewrite inE. rewrite !ffunE eqxx; congr (_, _); apply/ffunP=> i; rewrite !ffunE. case Eiy: (i == y); last by rewrite Eiy. by rewrite (negbTE nxy) (eqP Eiy). move=> k1 k2 [Eky Epk]; apply/ffunP=> i. have{Epk}: pk k1 i = pk k2 i by rewrite Epk. by rewrite !ffunE; case: eqP => // ->. Qed. Lemma F_Sd2 : 'Fix_to[sd2] = [set x | coin0 x == coin2 x]. Proof. apply/setP => x; rewrite (sameP afix1P eqP) !inE eqperm_map /=. by rewrite /act_f sd2_inv !ffunE !permE /= !eqxx !andbT eq_sym /= andbb. Qed. Lemma burnside_app_iso : (square_coloring_number8 * 8 = n ^ 4 + 2 * n ^ 3 + 3 * n ^ 2 + 2 * n)%N. Proof. pose iso_list := [:: id1; r1; r2; r3; sh; sv; sd1; sd2]. rewrite (burnside_formula iso_list) => [||p]; last first. - by rewrite /= !inE. - apply: map_uniq (fun p : {perm square} => (p c0, p c1)) _ _. by rewrite /= !permE. rewrite !big_cons big_nil {1}card_Fid F_r1 F_r2 F_r3 F_Sh F_Sv F_Sd1 F_Sd2. rewrite card_n !card_n3 // !card_n2 //= !addnA !addn0. by rewrite [LHS]addn.[ACl 1 * 7 * 8 * 3 * 5 * 6 * 2 * 4]. Qed. End square_colouring. Section cube_colouring. Definition cube := 'I_6. HB.instance Definition _ := SubType.on cube. HB.instance Definition _ := Finite.on cube. Definition mkFcube i : cube := Sub (i %% 6) (ltn_mod i 6). Definition F0 := mkFcube 0. Definition F1 := mkFcube 1. Definition F2 := mkFcube 2. Definition F3 := mkFcube 3. Definition F4 := mkFcube 4. Definition F5 := mkFcube 5. (* axial symetries*) Definition S05 := [:: F0; F4; F3; F2; F1; F5]. Definition S05f (sc : cube) : cube := tnth [tuple of S05] sc. Definition S14 := [:: F5; F1; F3; F2; F4; F0]. Definition S14f (sc : cube) : cube := tnth [tuple of S14] sc. Definition S23 := [:: F5; F4; F2; F3; F1; F0]. Definition S23f (sc : cube) : cube := tnth [tuple of S23] sc. (* rotations 90 *) Definition R05 := [:: F0; F2; F4; F1; F3; F5]. Definition R05f (sc : cube) : cube := tnth [tuple of R05] sc. Definition R50 := [:: F0; F3; F1; F4; F2; F5]. Definition R50f (sc : cube) : cube := tnth [tuple of R50] sc. Definition R14 := [:: F3; F1; F0; F5; F4; F2]. Definition R14f (sc : cube) : cube := tnth [tuple of R14] sc. Definition R41 := [:: F2; F1; F5; F0; F4; F3]. Definition R41f (sc : cube) : cube := tnth [tuple of R41] sc. Definition R23 := [:: F1; F5; F2; F3; F0; F4]. Definition R23f (sc : cube) : cube := tnth [tuple of R23] sc. Definition R32 := [:: F4; F0; F2; F3; F5; F1]. Definition R32f (sc : cube) : cube := tnth [tuple of R32] sc. (* rotations 120 *) Definition R024 := [:: F2; F5; F4; F1; F0; F3]. Definition R024f (sc : cube) : cube := tnth [tuple of R024] sc. Definition R042 := [:: F4; F3; F0; F5; F2; F1]. Definition R042f (sc : cube) : cube := tnth [tuple of R042] sc. Definition R012 := [:: F1; F2; F0; F5; F3; F4]. Definition R012f (sc : cube) : cube := tnth [tuple of R012] sc. Definition R021 := [:: F2; F0; F1; F4; F5; F3]. Definition R021f (sc : cube) : cube := tnth [tuple of R021] sc. Definition R031 := [:: F3; F0; F4; F1; F5; F2]. Definition R031f (sc : cube) : cube := tnth [tuple of R031] sc. Definition R013 := [:: F1; F3; F5; F0; F2; F4]. Definition R013f (sc : cube) : cube := tnth [tuple of R013] sc. Definition R043 := [:: F4; F2; F5; F0; F3; F1]. Definition R043f (sc : cube) : cube := tnth [tuple of R043] sc. Definition R034 := [:: F3; F5; F1; F4; F0; F2]. Definition R034f (sc : cube) : cube := tnth [tuple of R034] sc. (* last symmetries*) Definition S1 := [:: F5; F2; F1; F4; F3; F0]. Definition S1f (sc : cube) : cube := tnth [tuple of S1] sc. Definition S2 := [:: F5; F3; F4; F1; F2; F0]. Definition S2f (sc : cube) : cube := tnth [tuple of S2] sc. Definition S3 := [:: F1; F0; F3; F2; F5; F4]. Definition S3f (sc : cube) : cube := tnth [tuple of S3] sc. Definition S4 := [:: F4; F5; F3; F2; F0; F1]. Definition S4f (sc : cube) : cube := tnth [tuple of S4] sc. Definition S5 := [:: F2; F4; F0; F5; F1; F3]. Definition S5f (sc : cube) : cube := tnth [tuple of S5] sc. Definition S6 := [::F3; F4; F5; F0; F1; F2]. Definition S6f (sc : cube) : cube := tnth [tuple of S6] sc. Lemma S1_inv : involutive S1f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S2_inv : involutive S2f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S3_inv : involutive S3f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S4_inv : involutive S4f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S5_inv : involutive S5f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S6_inv : involutive S6f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma S05_inj : injective S05f. Proof. by apply: can_inj S05f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma S14_inj : injective S14f. Proof. by apply: can_inj S14f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma S23_inv : involutive S23f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Lemma R05_inj : injective R05f. Proof. by apply: can_inj R50f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R14_inj : injective R14f. Proof. by apply: can_inj R41f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R23_inj : injective R23f. Proof. by apply: can_inj R32f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R50_inj : injective R50f. Proof. by apply: can_inj R05f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R41_inj : injective R41f. Proof. by apply: can_inj R14f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R32_inj : injective R32f. Proof. by apply: can_inj R23f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R024_inj : injective R024f. Proof. by apply: can_inj R042f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R042_inj : injective R042f. Proof. by apply: can_inj R024f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R012_inj : injective R012f. Proof. by apply: can_inj R021f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R021_inj : injective R021f. Proof. by apply: can_inj R012f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R031_inj : injective R031f. Proof. by apply: can_inj R013f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R013_inj : injective R013f. Proof. by apply: can_inj R031f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R043_inj : injective R043f. Proof. by apply: can_inj R034f _ => z; apply/eqP; case: z; do 6?case. Qed. Lemma R034_inj : injective R034f. Proof. by apply: can_inj R043f _ => z; apply/eqP; case: z; do 6?case. Qed. Definition id3 := 1 : {perm cube}. Definition s05 := (perm S05_inj). Definition s14 : {perm cube}. Proof. apply: (@perm _ S14f); apply: can_inj S14f _ => z. by apply/eqP; case: z; do 6?case. Defined. Definition s23 := (perm (inv_inj S23_inv)). Definition r05 := (perm R05_inj). Definition r14 := (perm R14_inj). Definition r23 := (perm R23_inj). Definition r50 := (perm R50_inj). Definition r41 := (perm R41_inj). Definition r32 := (perm R32_inj). Definition r024 := (perm R024_inj). Definition r042 := (perm R042_inj). Definition r012 := (perm R012_inj). Definition r021 := (perm R021_inj). Definition r031 := (perm R031_inj). Definition r013 := (perm R013_inj). Definition r043 := (perm R043_inj). Definition r034 := (perm R034_inj). Definition s1 := (perm (inv_inj S1_inv)). Definition s2 := (perm (inv_inj S2_inv)). Definition s3 := (perm (inv_inj S3_inv)). Definition s4 := (perm (inv_inj S4_inv)). Definition s5 := (perm (inv_inj S5_inv)). Definition s6 := (perm (inv_inj S6_inv)). Definition dir_iso3 := [set p | [|| id3 == p, s05 == p, s14 == p, s23 == p, r05 == p, r14 == p, r23 == p, r50 == p, r41 == p, r32 == p, r024 == p, r042 == p, r012 == p, r021 == p, r031 == p, r013 == p, r043 == p, r034 == p, s1 == p, s2 == p, s3 == p, s4 == p, s5 == p | s6 == p]]. Definition dir_iso3l := [:: id3; s05; s14; s23; r05; r14; r23; r50; r41; r32; r024; r042; r012; r021; r031; r013; r043; r034; s1; s2; s3; s4; s5; s6]. Definition S0 := [:: F5; F4; F3; F2; F1; F0]. Definition S0f (sc : cube) : cube := tnth [tuple of S0] sc. Lemma S0_inv : involutive S0f. Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed. Definition s0 := (perm (inv_inj S0_inv)). Definition is_iso3 (p : {perm cube}) := forall fi, p (s0 fi) = s0 (p fi). Lemma dir_iso_iso3 : forall p, p \in dir_iso3 -> is_iso3 p. Proof. move=> p; rewrite inE. by do ?case/orP; move/eqP=> <- a; rewrite !permE; case: a; do 6?case. Qed. Lemma iso3_ndir : forall p, p \in dir_iso3 -> is_iso3 (s0 * p). Proof. move=> p; rewrite inE. by do ?case/orP; move/eqP=> <- a; rewrite !(permM, permE); case: a; do 6?case. Qed. Definition sop (p : {perm cube}) : seq cube := fgraph (val p). Lemma sop_inj : injective sop. Proof. by move=> p1 p2 /val_inj/(can_inj fgraphK)/val_inj. Qed. Definition prod_tuple (t1 t2 : seq cube) := map (fun n : 'I_6 => nth F0 t2 n) t1. Lemma sop_spec x (n0 : 'I_6): nth F0 (sop x) n0 = x n0. Proof. by rewrite nth_fgraph_ord pvalE. Qed. Lemma prod_t_correct : forall (x y : {perm cube}) (i : cube), (x * y) i = nth F0 (prod_tuple (sop x) (sop y)) i. Proof. move=> x y i; rewrite permM -!sop_spec [RHS](nth_map F0) // size_tuple /=. by rewrite card_ord ltn_ord. Qed. Lemma sop_morph : {morph sop : x y / x * y >-> prod_tuple x y}. Proof. move=> x y; apply: (@eq_from_nth _ F0) => [|/= i]. by rewrite size_map !size_tuple. rewrite size_tuple card_ord => lti6. by rewrite -[i]/(val (Ordinal lti6)) sop_spec -prod_t_correct. Qed. Definition ecubes : seq cube := [:: F0; F1; F2; F3; F4; F5]. Lemma ecubes_def : ecubes = enum (@predT cube). Proof. by apply: (inj_map val_inj); rewrite val_enum_ord. Qed. Definition seq_iso_L := [:: [:: F0; F1; F2; F3; F4; F5]; S05; S14; S23; R05; R14; R23; R50; R41; R32; R024; R042; R012; R021; R031; R013; R043; R034; S1; S2; S3; S4; S5; S6]. Lemma seqs1 : forall f injf, sop (@perm _ f injf) = map f ecubes. Proof. move=> f ?; rewrite ecubes_def /sop /= -codom_ffun pvalE. by apply: eq_codom; apply: permE. Qed. Lemma Lcorrect : seq_iso_L == map sop [:: id3; s05; s14; s23; r05; r14; r23; r50; r41; r32; r024; r042; r012; r021; r031; r013; r043; r034; s1; s2; s3; s4; s5; s6]. Proof. by rewrite /= !seqs1. Qed. Lemma iso0_1 : dir_iso3 =i dir_iso3l. Proof. by move=> p; rewrite /= !inE /= -!(eq_sym p). Qed. Lemma L_iso : forall p, (p \in dir_iso3) = (sop p \in seq_iso_L). Proof. by move=> p; rewrite (eqP Lcorrect) mem_map ?iso0_1 //; apply: sop_inj. Qed. Lemma stable : forall x y, x \in dir_iso3 -> y \in dir_iso3 -> x * y \in dir_iso3. Proof. move=> x y; rewrite !L_iso sop_morph => Hx Hy. by move/sop: y Hy; apply/allP; move/sop: x Hx; apply/allP; vm_compute. Qed. Lemma iso_eq_F0_F1 : forall r s : {perm cube}, r \in dir_iso3 -> s \in dir_iso3 -> r F0 = s F0 -> r F1 = s F1 -> r = s. Proof. move=> r s; rewrite !L_iso => hr hs hrs0 hrs1; apply: sop_inj; apply/eqP. move/eqP: hrs0; apply/implyP; move/eqP: hrs1; apply/implyP; rewrite -!sop_spec. by move/sop: r hr; apply/allP; move/sop: s hs; apply/allP; vm_compute. Qed. Lemma ndir_s0p : forall p, p \in dir_iso3 -> s0 * p \notin dir_iso3. Proof. move=> p; rewrite !L_iso sop_morph seqs1. by move/sop: p; apply/allP; vm_compute. Qed. Definition indir_iso3l := map (mulg s0) dir_iso3l. Definition iso3l := dir_iso3l ++ indir_iso3l. Definition seq_iso3_L := map sop iso3l. Lemma eqperm : forall p1 p2 : {perm cube}, (p1 == p2) = all (fun s => p1 s == p2 s) ecubes. Proof. move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/permP=> x. by apply/eqP; rewrite Ep12 // ecubes_def mem_enum. Qed. Lemma iso_eq_F0_F1_F2 : forall r s : {perm cube}, is_iso3 r -> is_iso3 s -> r F0 = s F0 -> r F1 = s F1 -> r F2 = s F2 -> r = s. Proof. move=> r s hr hs hrs0 hrs1 hrs2. have:= hrs0; have:= hrs1; have:= hrs2. have e23: F2 = s0 F3 by apply/eqP; rewrite permE /S0f (tnth_nth F0). have e14: F1 = s0 F4 by apply/eqP; rewrite permE /S0f (tnth_nth F0). have e05: F0 = s0 F5 by apply/eqP; rewrite permE /S0f (tnth_nth F0). rewrite e23 e14 e05; rewrite !hr !hs. move/perm_inj=> hrs3; move/perm_inj=> hrs4; move/perm_inj=> hrs5. by apply/eqP; rewrite eqperm /= hrs0 hrs1 hrs2 hrs3 hrs4 hrs5 !eqxx. Qed. Ltac iso_tac := let a := fresh "a" in apply/permP => a; apply/eqP; rewrite !permM !permE; case: a; do 6?case. Ltac inv_tac := apply: esym (etrans _ (mul1g _)); apply: canRL (mulgK _) _; iso_tac. Lemma dir_s0p : forall p, (s0 * p) \in dir_iso3 -> p \notin dir_iso3. Proof. move=> p Hs0p; move: (ndir_s0p Hs0p); rewrite mulgA. have e: (s0^-1=s0) by inv_tac. by rewrite -{1}e mulVg mul1g. Qed. Definition is_iso3b p := (p * s0 == s0 * p). Definition iso3 := [set p | is_iso3b p]. Lemma is_iso3P : forall p, reflect (is_iso3 p) (p \in iso3). Proof. move=> p; apply: (iffP idP); rewrite inE /iso3 /is_iso3b /is_iso3 => e. by move=> fi; rewrite -!permM (eqP e). by apply/eqP; apply/permP=> z; rewrite !permM (e z). Qed. Lemma group_set_iso3 : group_set iso3. Proof. apply/group_setP; split. by apply/is_iso3P => fi; rewrite -!permM mulg1 mul1g. move=> x1 y; rewrite /iso3 !inE /= /is_iso3. rewrite /is_iso3b. rewrite -mulgA. move/eqP => hx1; move/eqP => hy. rewrite hy !mulgA. by rewrite -hx1. Qed. Canonical iso_group3 := Group group_set_iso3. Lemma group_set_diso3 : group_set dir_iso3. Proof. apply/group_setP; split; first by rewrite inE eqxx /=. by apply: stable. Qed. Canonical diso_group3 := Group group_set_diso3. Lemma gen_diso3 : dir_iso3 = <<[set r05; r14]>>. Proof. apply/setP/subset_eqP/andP; split; first last. rewrite gen_subG; apply/subsetP. by move=> x /[!inE] /orP[] /eqP->; rewrite !eqxx !orbT. apply/subsetP => x /[!inE]. have -> : s05 = r05 * r05 by iso_tac. have -> : s14 = r14 * r14 by iso_tac. have -> : s23 = r14 * r14 * r05 * r05 by iso_tac. have -> : r23 = r05 * r14 * r05 * r14 * r14 by iso_tac. have -> : r50 = r05 * r05 * r05 by iso_tac. have -> : r41 = r14 * r14 * r14 by iso_tac. have -> : r32 = r14 * r14 * r14 * r05* r14 by iso_tac. have -> : r024 = r05 * r14 * r14 * r14 by iso_tac. have -> : r042 = r14 * r05 * r05 * r05 by iso_tac. have -> : r012 = r14 * r05 by iso_tac. have -> : r021 = r05 * r14 * r05 * r05 by iso_tac. have -> : r031 = r05 * r14 by iso_tac. have -> : r013 = r05 * r05 * r14 * r05 by iso_tac. have -> : r043 = r14 * r14 * r14 * r05 by iso_tac. have -> : r034 = r05 * r05 * r05 * r14 by iso_tac. have -> : s1 = r14 * r14 * r05 by iso_tac. have -> : s2 = r05 * r14 * r14 by iso_tac. have -> : s3 = r05 * r14 * r05 by iso_tac. have -> : s4 = r05 * r14 * r14 * r14 * r05 by iso_tac. have -> : s5 = r14 * r05 * r05 by iso_tac. have -> : s6 = r05 * r05 * r14 by iso_tac. by do ?case/predU1P=> [<-|]; first exact: group1; last (move/eqP<-); rewrite ?groupMl ?mem_gen // !inE eqxx ?orbT. Qed. Notation col_cubes := {ffun cube -> colors}. Definition act_g (sc : col_cubes) (p : {perm cube}) : col_cubes := [ffun z => sc (p^-1 z)]. Lemma act_g_1 : forall k, act_g k 1 = k. Proof. by move=> k; apply/ffunP=> a; rewrite ffunE invg1 permE. Qed. Lemma act_g_morph : forall k x y, act_g k (x * y) = act_g (act_g k x) y. Proof. by move=> k x y; apply/ffunP=> a; rewrite !ffunE invMg permE. Qed. Definition to_g := TotalAction act_g_1 act_g_morph. Definition cube_coloring_number24 := #|orbit to_g diso_group3 @: setT|. Lemma Fid3 : 'Fix_to_g[1] = setT. Proof. by apply/setP=> x /=; rewrite (sameP afix1P eqP) !inE act1 eqxx. Qed. Lemma card_Fid3 : #|'Fix_to_g[1]| = (n ^ 6)%N. Proof. rewrite -[6]card_ord -[n]card_ord -card_ffun_on Fid3 cardsT. by symmetry; apply: eq_card => ff; apply/ffun_onP. Qed. Definition col0 (sc : col_cubes) : colors := sc F0. Definition col1 (sc : col_cubes) : colors := sc F1. Definition col2 (sc : col_cubes) : colors := sc F2. Definition col3 (sc : col_cubes) : colors := sc F3. Definition col4 (sc : col_cubes) : colors := sc F4. Definition col5 (sc : col_cubes) : colors := sc F5. Lemma eqperm_map2 : forall p1 p2 : col_cubes, (p1 == p2) = all (fun s => p1 s == p2 s) [:: F0; F1; F2; F3; F4; F5]. Proof. move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/ffunP=> x. by apply/eqP; apply Ep12; case: x; do 6?case. Qed. Notation infE := (sameP afix1P eqP). Lemma F_s05 : 'Fix_to_g[s05] = [set x | (col1 x == col4 x) && (col2 x == col3 x)]. Proof. have s05_inv: s05^-1=s05 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s05_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0. by do 2![rewrite eq_sym; case: {+}(_ == _)=> //= ]. Qed. Lemma F_s14 : 'Fix_to_g[s14]= [set x | (col0 x == col5 x) && (col2 x == col3 x)]. Proof. have s14_inv: s14^-1=s14 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s14_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0. by do 2![rewrite eq_sym; case: {+}(_ == _)=> //= ]. Qed. Lemma r05_inv : r05^-1 = r50. Proof. by inv_tac. Qed. Lemma r50_inv : r50^-1 = r05. Proof. by inv_tac. Qed. Lemma r14_inv : r14^-1 = r41. Proof. by inv_tac. Qed. Lemma r41_inv : r41^-1 = r14. Proof. by inv_tac. Qed. Lemma s23_inv : s23^-1 = s23. Proof. by inv_tac. Qed. Lemma F_s23 : 'Fix_to_g[s23] = [set x | (col0 x == col5 x) && (col1 x == col4 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s23_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0. by do 2![rewrite eq_sym; case: {+}(_ == _)=> //=]. Qed. Lemma F_r05 : 'Fix_to_g[r05]= [set x | (col1 x == col2 x) && (col2 x == col3 x) && (col3 x == col4 x)]. Proof. apply sym_equal. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r05_inv !ffunE !permE /=. rewrite !eqxx /= !andbT /col1/col2/col3/col4/col5/col0. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r50 : 'Fix_to_g[r50]= [set x | (col1 x == col2 x) && (col2 x == col3 x) && (col3 x == col4 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r50_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col1/col2/col3/col4. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r23 : 'Fix_to_g[r23] = [set x | (col0 x == col1 x) && (col1 x == col4 x) && (col4 x == col5 x)]. Proof. have r23_inv: r23^-1 = r32 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r23_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col1/col0/col5/col4. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r32 : 'Fix_to_g[r32] = [set x | (col0 x == col1 x) && (col1 x == col4 x) && (col4 x == col5 x)]. Proof. have r32_inv: r32^-1 = r23 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r32_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col1/col0/col5/col4. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r14 : 'Fix_to_g[r14] = [set x | (col0 x == col2 x) && (col2 x == col3 x) && (col3 x == col5 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r14_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col2/col0/col5/col3. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r41 : 'Fix_to_g[r41] = [set x | (col0 x == col2 x) && (col2 x == col3 x) && (col3 x == col5 x)]. Proof. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r41_inv !ffunE !permE /=. apply sym_equal; rewrite !eqxx /= !andbT /col2/col0/col5/col3. by do 3![case: eqVneq; rewrite ?andbF // => <-]. Qed. Lemma F_r024 : 'Fix_to_g[r024] = [set x | (col0 x == col4 x) && (col4 x == col2 x) && (col1 x == col3 x) && (col3 x == col5 x) ]. Proof. have r024_inv: r024^-1 = r042 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r024_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r042 : 'Fix_to_g[r042] = [set x | (col0 x == col4 x) && (col4 x == col2 x) && (col1 x == col3 x) && (col3 x == col5 x)]. Proof. have r042_inv: r042^-1 = r024 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r042_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r012 : 'Fix_to_g[r012] = [set x | (col0 x == col2 x) && (col2 x == col1 x) && (col3 x == col4 x) && (col4 x == col5 x)]. Proof. have r012_inv: r012^-1 = r021 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r012_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r021 : 'Fix_to_g[r021] = [set x | (col0 x == col2 x) && (col2 x == col1 x) && (col3 x == col4 x) && (col4 x == col5 x)]. Proof. have r021_inv: r021^-1 = r012 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r021_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r031 : 'Fix_to_g[r031] = [set x | (col0 x == col3 x) && (col3 x == col1 x) && (col2 x == col4 x) && (col4 x == col5 x)]. Proof. have r031_inv: r031^-1 = r013 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r031_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r013 : 'Fix_to_g[r013] = [set x | (col0 x == col3 x) && (col3 x == col1 x) && (col2 x == col4 x) && (col4 x == col5 x)]. Proof. have r013_inv: r013^-1 = r031 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r013_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r043 : 'Fix_to_g[r043] = [set x | (col0 x == col4 x) && (col4 x == col3 x) && (col1 x == col2 x) && (col2 x == col5 x)]. Proof. have r043_inv: r043^-1 = r034 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r043_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_r034 : 'Fix_to_g[r034] = [set x | (col0 x == col4 x) && (col4 x == col3 x) && (col1 x == col2 x) && (col2 x == col5 x)]. Proof. have r034_inv: r034^-1 = r043 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r034_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s1 : 'Fix_to_g[s1] = [set x | (col0 x == col5 x) && (col1 x == col2 x) && (col3 x == col4 x)]. Proof. have s1_inv: s1^-1 = s1 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s1_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s2 : 'Fix_to_g[s2] = [set x | (col0 x == col5 x) && (col1 x == col3 x) && (col2 x == col4 x)]. Proof. have s2_inv: s2^-1 = s2 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s2_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s3 : 'Fix_to_g[s3] = [set x | (col0 x == col1 x) && (col2 x == col3 x) && (col4 x == col5 x)]. Proof. have s3_inv: s3^-1 = s3 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s3_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s4 : 'Fix_to_g[s4] = [set x | (col0 x == col4 x) && (col1 x == col5 x) && (col2 x == col3 x)]. Proof. have s4_inv: s4^-1 = s4 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s4_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s5 : 'Fix_to_g[s5] = [set x | (col0 x == col2 x) && (col1 x == col4 x) && (col3 x == col5 x)]. Proof. have s5_inv: s5^-1 = s5 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s5_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma F_s6 : 'Fix_to_g[s6] = [set x | (col0 x == col3 x) && (col1 x == col4 x) && (col2 x == col5 x)]. Proof. have s6_inv: s6^-1 = s6 by inv_tac. apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s6_inv !ffunE !permE /=. apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5. by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E]. Qed. Lemma uniq4_uniq6 : forall x y z t : cube, uniq [:: x; y; z; t] -> exists u, exists v, uniq [:: x; y; z; t; u; v]. Proof. move=> x y z t Uxt; move: (cardC [in [:: x; y; z; t]]). rewrite card_ord (card_uniq_tuple Uxt) => hcard. have hcard2: #|[predC [:: x; y; z; t]]| = 2. by apply: (@addnI 4); rewrite /injective hcard. have: #|[predC [:: x; y; z; t]]| != 0 by rewrite hcard2. case/existsP=> u Hu; exists u. move: (cardC [in [:: x; y; z; t; u]]); rewrite card_ord => hcard5. have: #|[predC [:: x; y; z; t; u]]| !=0. rewrite -lt0n -(ltn_add2l #|[:: x; y; z; t; u]|) hcard5 addn0. by apply: (leq_ltn_trans (card_size [:: x; y; z; t; u])). case/existsP => v; rewrite (mem_cat _ [:: _; _; _; _]) => /norP[Hv Huv]. exists v; rewrite (cat_uniq [:: x; y; z; t]) Uxt andTb -rev_uniq /= orbF. by rewrite negb_or Hu Hv Huv. Qed. Lemma card_n4 : forall x y z t : cube, uniq [:: x; y; z; t] -> #|[set p : col_cubes | (p x == p y) && (p z == p t)]| = (n ^ 4)%N. Proof. move=> x y z t Uxt; rewrite -[n]card_ord. case: (uniq4_uniq6 Uxt) => u [v Uxv]. pose ff (p : col_cubes) := (p x, p z, p u, p v). rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE] /andP[p1y p1t] /andP[p2y p2t] [px pz] pu pv. have eqp12 : all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -(eqP p1y) -(eqP p1t) -(eqP p2y) -(eqP p2t) px pz pu pv !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. have -> : forall n, (n ^ 4 = n * n * n * n)%N by move=> ?; rewrite -!mulnA. rewrite -!card_prod; apply: eq_card => [] [[[c d] e] g] /=; apply/imageP => /=. move: Uxv; rewrite (cat_uniq [:: x; y; z; t]) => /and3P[_]/=; rewrite orbF. move=> /norP[] /[!inE] + + /andP[/negPf nuv _]. rewrite orbA => /norP[/negPf nxyu /negPf nztu]. rewrite orbA => /norP[/negPf nxyv /negPf nztv]. move: Uxt; rewrite (cat_uniq [::x; y]) => /and3P[_]/= /[!(andbT, orbF)]. move=> /norP[] /[!inE] /negPf nxyz /negPf nxyt _. exists [ffun i => if pred2 x y i then c else if pred2 z t i then d else if u == i then e else g]. by rewrite !(inE, ffunE, eqxx,orbT)//= nxyz nxyt. by rewrite {}/ff !ffunE /= !eqxx /= nxyz nxyu nztu nxyv nztv nuv. Qed. Lemma card_n3_3 : forall x y z t: cube, uniq [:: x; y; z; t] -> #|[set p : col_cubes | (p x == p y) && (p y == p z)&& (p z == p t)]| = (n ^ 3)%N. Proof. move=> x y z t Uxt; rewrite -[n]card_ord. case: (uniq4_uniq6 Uxt) => u [v Uxv]. pose ff (p : col_cubes) := (p x, p u, p v); rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE]; rewrite -!andbA. move=> /and3P[/eqP p1xy /eqP p1yz /eqP p1zt]. move=> /and3P[/eqP p2xy /eqP p2yz /eqP p2zt] [px pu] pv. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -p1zt -p2zt -p1yz -p2yz -p1xy -p2xy px pu pv !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. have -> : forall n, (n ^ 3 = n * n * n)%N by move=> ?; rewrite -!mulnA. rewrite -!card_prod; apply: eq_card => [] [[c d] e] /=; apply/imageP. move: Uxv; rewrite (cat_uniq [::x; y; z; t]) => /and3P[_ hasxt]. rewrite /uniq !inE !andbT => /negPf nuv. exists [ffun i => if i \in [:: x; y; z; t] then c else if u == i then d else e]. by rewrite /= !(inE, ffunE, eqxx, orbT). rewrite {}/ff !(ffunE, inE, eqxx) /=; move: hasxt; rewrite nuv. by do 8![case E: ( _ == _ ); rewrite ?(eqP E)/= ?inE ?eqxx //= ?E {E}]. Qed. Lemma card_n2_3 : forall x y z t u v: cube, uniq [:: x; y; z; t; u; v] -> #|[set p : col_cubes | (p x == p y) && (p y == p z)&& (p t == p u ) && (p u== p v)]| = (n ^ 2)%N. Proof. move=> x y z t u v Uxv; rewrite -[n]card_ord . pose ff (p : col_cubes) := (p x, p t). rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE]; rewrite -!andbA. move=> /and4P[/eqP p1xy /eqP p1yz /eqP p1tu /eqP p1uv]. move=> /and4P[/eqP p2xy/eqP p2yz /eqP p2tu /eqP p2uv] [px pu]. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -p1yz -p2yz -p1xy -p2xy -p1uv -p2uv -p1tu -p2tu px pu !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. rewrite -mulnn -!card_prod; apply: eq_card => [] [c d]/=; apply/imageP. move: Uxv; rewrite (cat_uniq [::x; y; z]) => /= /and3P[Uxt + nuv]. move=> /[!orbF] /norP[] /[!inE] /negPf nxyzt /norP[/negPf nxyzu /negPf nxyzv]. exists [ffun i => if (i \in [:: x; y; z] ) then c else d]. by rewrite /= !(inE, ffunE, eqxx, orbT, nxyzt, nxyzu, nxyzv). by rewrite {}/ff !ffunE !inE /= !eqxx /= nxyzt. Qed. Lemma card_n3s : forall x y z t u v: cube, uniq [:: x; y; z; t; u; v] -> #|[set p : col_cubes | (p x == p y) && (p z == p t)&& (p u == p v )]| = (n ^ 3)%N. Proof. move=> x y z t u v Uxv; rewrite -[n]card_ord . pose ff (p : col_cubes) := (p x, p z, p u). rewrite -(@card_in_image _ _ ff); first last. move=> p1 p2 /[!inE]; rewrite -!andbA. move=> /and3P[/eqP p1xy /eqP p1zt /eqP p1uv]. move=> /and3P[/eqP p2xy /eqP p2zt /eqP p2uv] [px pz] pu. have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v]. by rewrite /= -p1xy -p2xy -p1zt -p2zt -p1uv -p2uv px pz pu !eqxx. apply/ffunP=> i; apply/eqP; apply: (allP eqp12). by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord. have -> : forall n, (n ^ 3 = n * n * n)%N by move=> ?; rewrite -!mulnA. rewrite -!card_prod; apply: eq_card => [] [[c d] e] /=; apply/imageP. move: Uxv; rewrite (cat_uniq [::x; y; z; t]) => /and3P[Uxt + nuv]. move=> /= /[!orbF] /norP[] /[!inE]. rewrite orbA => /norP[/negPf nxyu /negPf nztu]. rewrite orbA => /norP[/negPf nxyv /negPf nztv]. move: Uxt; rewrite (cat_uniq [::x; y]) => /and3P[_]. rewrite /= !orbF !andbT => /norP[] /[!inE] /negPf nxyz /negPf nxyt _. exists [ffun i => if i \in [:: x; y] then c else if i \in [:: z; t] then d else e]. by rewrite !(inE, ffunE, eqxx,orbT)//= nxyz nxyt nxyu nztu nxyv nztv !eqxx. by rewrite {}/ff !ffunE !inE /= !eqxx nxyz nxyu nztu. Qed. Lemma burnside_app_iso3 : (cube_coloring_number24 * 24 = n ^ 6 + 6 * n ^ 3 + 3 * n ^ 4 + 8 * (n ^ 2) + 6 * n ^ 3)%N. Proof. pose iso_list := [:: id3; s05; s14; s23; r05; r14; r23; r50; r41; r32; r024; r042; r012; r021; r031; r013; r043; r034; s1; s2; s3; s4; s5; s6]. rewrite (burnside_formula iso_list); last first. - by move=> p; rewrite !inE /= !(eq_sym _ p). - apply: map_uniq (fun p : {perm cube} => (p F0, p F1)) _ _. have bsr : (fun p : {perm cube} => (p F0, p F1)) =1 (fun p => (nth F0 p F0, nth F0 p F1)) \o sop. by move=> x; rewrite /= -2!sop_spec. by rewrite (eq_map bsr) map_comp -(eqP Lcorrect); vm_compute. rewrite !big_cons big_nil {1}card_Fid3 /= F_s05 F_s14 F_s23 F_r05 F_r14 F_r23 F_r50 F_r41 F_r32 F_r024 F_r042 F_r012 F_r021 F_r031 F_r013 F_r043 F_r034 F_s1 F_s2 F_s3 F_s4 F_s5 F_s6. rewrite !card_n4 // !card_n3_3 // !card_n2_3 // !card_n3s //. by rewrite [RHS]addn.[ACl 1 * 3 * 2 * 4 * 5] !addnA !addn0. Qed. End cube_colouring. End colouring. Corollary burnside_app_iso_3_3col: cube_coloring_number24 3 = 57. Proof. by apply/eqP; rewrite -(@eqn_pmul2r 24) // burnside_app_iso3. Qed. Corollary burnside_app_iso_2_4col: square_coloring_number8 4 = 55. Proof. by apply/eqP; rewrite -(@eqn_pmul2r 8) // burnside_app_iso. Qed.
LocalCohomology.lean
/- Copyright (c) 2023 Emily Witt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Emily Witt, Kim Morrison, Jake Levinson, Sam van Gool -/ import Mathlib.Algebra.Category.ModuleCat.Colimits import Mathlib.Algebra.Category.ModuleCat.Projective import Mathlib.CategoryTheory.Abelian.Ext import Mathlib.CategoryTheory.Limits.Final import Mathlib.RingTheory.Finiteness.Ideal import Mathlib.RingTheory.Ideal.Basic import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.RingTheory.Noetherian.Defs /-! # Local cohomology. This file defines the `i`-th local cohomology module of an `R`-module `M` with support in an ideal `I` of `R`, where `R` is a commutative ring, as the direct limit of Ext modules: Given a collection of ideals cofinal with the powers of `I`, consider the directed system of quotients of `R` by these ideals, and take the direct limit of the system induced on the `i`-th Ext into `M`. One can, of course, take the collection to simply be the integral powers of `I`. ## References * [M. Hochster, *Local cohomology*][hochsterunpublished] <https://dept.math.lsa.umich.edu/~hochster/615W22/lcc.pdf> * [R. Hartshorne, *Local cohomology: A seminar given by A. Grothendieck*][hartshorne61] * [M. Brodmann and R. Sharp, *Local cohomology: An algebraic introduction with geometric applications*][brodmannsharp13] * [S. Iyengar, G. Leuschke, A. Leykin, Anton, C. Miller, E. Miller, A. Singh, U. Walther, *Twenty-four hours of local cohomology*][iyengaretal13] ## Tags local cohomology, local cohomology modules ## Future work * Prove that this definition is equivalent to: * the right-derived functor definition * the characterization as the limit of Koszul homology * the characterization as the cohomology of a Cech-like complex * Establish long exact sequence(s) in local cohomology -/ open Opposite open CategoryTheory open CategoryTheory.Limits noncomputable section universe u v v' namespace localCohomology -- We define local cohomology, implemented as a direct limit of `Ext(R/J, -)`. section variable {R : Type u} [CommRing R] {D : Type v} [SmallCategory D] /-- The directed system of `R`-modules of the form `R/J`, where `J` is an ideal of `R`, determined by the functor `I` -/ def ringModIdeals (I : D ⥤ Ideal R) : D ⥤ ModuleCat.{u} R where obj t := ModuleCat.of R <| R ⧸ I.obj t map w := ModuleCat.ofHom <| Submodule.mapQ _ _ LinearMap.id (I.map w).down.down /-- The diagram we will take the colimit of to define local cohomology, corresponding to the directed system determined by the functor `I` -/ def diagram (I : D ⥤ Ideal R) (i : ℕ) : Dᵒᵖ ⥤ ModuleCat.{u} R ⥤ ModuleCat.{u} R := (ringModIdeals I).op ⋙ Ext R (ModuleCat.{u} R) i end section -- We momentarily need to work with a type inequality, as later we will take colimits -- along diagrams either in Type, or in the same universe as the ring, and we need to cover both. variable {R : Type max u v} [CommRing R] {D : Type v} [SmallCategory D] lemma hasColimitDiagram (I : D ⥤ Ideal R) (i : ℕ) : HasColimit (diagram I i) := inferInstance /- In this definition we do not assume any special property of the diagram `I`, but the relevant case will be where `I` is (cofinal with) the diagram of powers of a single given ideal. Below, we give two equivalent definitions of the usual local cohomology with support in an ideal `J`, `localCohomology` and `localCohomology.ofSelfLERadical`. -/ /-- `localCohomology.ofDiagram I i` is the functor sending a module `M` over a commutative ring `R` to the direct limit of `Ext^i(R/J, M)`, where `J` ranges over a collection of ideals of `R`, represented as a functor `I`. -/ def ofDiagram (I : D ⥤ Ideal R) (i : ℕ) : ModuleCat.{max u v} R ⥤ ModuleCat.{max u v} R := have := hasColimitDiagram.{u, v} I i colimit (diagram I i) end section variable {R : Type max u v v'} [CommRing R] {D : Type v} [SmallCategory D] variable {E : Type v'} [SmallCategory E] (I' : E ⥤ D) (I : D ⥤ Ideal R) /-- Local cohomology along a composition of diagrams. -/ def diagramComp (i : ℕ) : diagram (I' ⋙ I) i ≅ I'.op ⋙ diagram I i := Iso.refl _ /-- Local cohomology agrees along precomposition with a cofinal diagram. -/ @[nolint unusedHavesSuffices] def isoOfFinal [Functor.Initial I'] (i : ℕ) : ofDiagram.{max u v, v'} (I' ⋙ I) i ≅ ofDiagram.{max u v', v} I i := have := hasColimitDiagram.{max u v', v} I i have := hasColimitDiagram.{max u v, v'} (I' ⋙ I) i HasColimit.isoOfNatIso (diagramComp.{u} I' I i) ≪≫ Functor.Final.colimitIso _ _ end section Diagrams variable {R : Type u} [CommRing R] /-- The functor sending a natural number `i` to the `i`-th power of the ideal `J` -/ def idealPowersDiagram (J : Ideal R) : ℕᵒᵖ ⥤ Ideal R where obj t := J ^ unop t map w := ⟨⟨Ideal.pow_le_pow_right w.unop.down.down⟩⟩ /-- The full subcategory of all ideals with radical containing `J` -/ def SelfLERadical (J : Ideal R) : Type u := ObjectProperty.FullSubcategory fun J' : Ideal R => J ≤ J'.radical deriving Category instance SelfLERadical.inhabited (J : Ideal R) : Inhabited (SelfLERadical J) where default := ⟨J, Ideal.le_radical⟩ /-- The diagram of all ideals with radical containing `J`, represented as a functor. This is the "largest" diagram that computes local cohomology with support in `J`. -/ def selfLERadicalDiagram (J : Ideal R) : SelfLERadical J ⥤ Ideal R := ObjectProperty.ι _ end Diagrams end localCohomology /-! We give two models for the local cohomology with support in an ideal `J`: first in terms of the powers of `J` (`localCohomology`), then in terms of *all* ideals with radical containing `J` (`localCohomology.ofSelfLERadical`). -/ section ModelsForLocalCohomology open localCohomology variable {R : Type u} [CommRing R] /-- `localCohomology J i` is `i`-th the local cohomology module of a module `M` over a commutative ring `R` with support in the ideal `J` of `R`, defined as the direct limit of `Ext^i(R/J^t, M)` over all powers `t : ℕ`. -/ def localCohomology (J : Ideal R) (i : ℕ) : ModuleCat.{u} R ⥤ ModuleCat.{u} R := ofDiagram (idealPowersDiagram J) i /-- Local cohomology as the direct limit of `Ext^i(R/J', M)` over *all* ideals `J'` with radical containing `J`. -/ def localCohomology.ofSelfLERadical (J : Ideal R) (i : ℕ) : ModuleCat.{u} R ⥤ ModuleCat.{u} R := ofDiagram.{u} (selfLERadicalDiagram.{u} J) i end ModelsForLocalCohomology namespace localCohomology /-! Showing equivalence of different definitions of local cohomology. * `localCohomology.isoSelfLERadical` gives the isomorphism `localCohomology J i ≅ localCohomology.ofSelfLERadical J i` * `localCohomology.isoOfSameRadical` gives the isomorphism `localCohomology J i ≅ localCohomology K i` when `J.radical = K.radical`. -/ section LocalCohomologyEquiv variable {R : Type u} [CommRing R] /-- Lifting `idealPowersDiagram J` from a diagram valued in `ideals R` to a diagram valued in `SelfLERadical J`. -/ def idealPowersToSelfLERadical (J : Ideal R) : ℕᵒᵖ ⥤ SelfLERadical J := ObjectProperty.lift _ (idealPowersDiagram J) fun k => by change _ ≤ (J ^ unop k).radical rcases unop k with - | n · simp [Ideal.radical_top, pow_zero, Ideal.one_eq_top, le_top] · simp only [J.radical_pow n.succ_ne_zero, Ideal.le_radical] variable {I J K : Ideal R} /-- The diagram of powers of `J` is initial in the diagram of all ideals with radical containing `J`. This uses noetherianness. -/ instance ideal_powers_initial [hR : IsNoetherian R R] : Functor.Initial (idealPowersToSelfLERadical J) where out J' := by apply (config := { allowSynthFailures := true }) zigzag_isConnected · obtain ⟨k, hk⟩ := Ideal.exists_pow_le_of_le_radical_of_fg J'.2 (isNoetherian_def.mp hR _) exact ⟨CostructuredArrow.mk (⟨⟨hk⟩⟩ : (idealPowersToSelfLERadical J).obj (op k) ⟶ J')⟩ · intro j1 j2 apply Relation.ReflTransGen.single -- The inclusions `J^n1 ≤ J'` and `J^n2 ≤ J'` always form a triangle, based on -- which exponent is larger. rcases le_total (unop j1.left) (unop j2.left) with h | h · right; exact ⟨CostructuredArrow.homMk (homOfLE h).op rfl⟩ · left; exact ⟨CostructuredArrow.homMk (homOfLE h).op rfl⟩ example : HasColimitsOfSize.{0, 0, u, u + 1} (ModuleCat.{u, u} R) := inferInstance /-- Local cohomology (defined in terms of powers of `J`) agrees with local cohomology computed over all ideals with radical containing `J`. -/ def isoSelfLERadical (J : Ideal.{u} R) [IsNoetherian.{u, u} R R] (i : ℕ) : localCohomology.ofSelfLERadical.{u} J i ≅ localCohomology.{u} J i := (localCohomology.isoOfFinal.{u, u, 0} (idealPowersToSelfLERadical.{u} J) (selfLERadicalDiagram.{u} J) i).symm ≪≫ HasColimit.isoOfNatIso.{0,0,u+1,u+1} (Iso.refl.{u+1,u+1} _) /-- Casting from the full subcategory of ideals with radical containing `J` to the full subcategory of ideals with radical containing `K`. -/ def SelfLERadical.cast (hJK : J.radical = K.radical) : SelfLERadical J ⥤ SelfLERadical K := ObjectProperty.ιOfLE fun L hL => by rw [← Ideal.radical_le_radical_iff] at hL ⊢ exact hJK.symm.trans_le hL -- TODO generalize this to the equivalence of full categories for any `iff`. /-- The equivalence of categories `SelfLERadical J ≌ SelfLERadical K` when `J.radical = K.radical`. -/ def SelfLERadical.castEquivalence (hJK : J.radical = K.radical) : SelfLERadical J ≌ SelfLERadical K where functor := SelfLERadical.cast hJK inverse := SelfLERadical.cast hJK.symm unitIso := Iso.refl _ counitIso := Iso.refl _ instance SelfLERadical.cast_isEquivalence (hJK : J.radical = K.radical) : (SelfLERadical.cast hJK).IsEquivalence := (castEquivalence hJK).isEquivalence_functor /-- The natural isomorphism between local cohomology defined using the `of_self_le_radical` diagram, assuming `J.radical = K.radical`. -/ def SelfLERadical.isoOfSameRadical (hJK : J.radical = K.radical) (i : ℕ) : ofSelfLERadical J i ≅ ofSelfLERadical K i := (isoOfFinal.{u, u, u} (SelfLERadical.cast hJK.symm) _ _).symm /-- Local cohomology agrees on ideals with the same radical. -/ def isoOfSameRadical [IsNoetherian R R] (hJK : J.radical = K.radical) (i : ℕ) : localCohomology J i ≅ localCohomology K i := (isoSelfLERadical J i).symm ≪≫ SelfLERadical.isoOfSameRadical hJK i ≪≫ isoSelfLERadical K i end LocalCohomologyEquiv end localCohomology
lpSpace.lean
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.MeanInequalities import Mathlib.Analysis.MeanInequalitiesPow import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Data.Set.Image import Mathlib.Topology.Algebra.ContinuousMonoidHom /-! # ℓp space This file describes properties of elements `f` of a pi-type `∀ i, E i` with finite "norm", defined for `p : ℝ≥0∞` as the size of the support of `f` if `p=0`, `(∑' a, ‖f a‖^p) ^ (1/p)` for `0 < p < ∞` and `⨆ a, ‖f a‖` for `p=∞`. The Prop-valued `Memℓp f p` states that a function `f : ∀ i, E i` has finite norm according to the above definition; that is, `f` has finite support if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if `0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if `p = ∞`. The space `lp E p` is the subtype of elements of `∀ i : α, E i` which satisfy `Memℓp f p`. For `1 ≤ p`, the "norm" is genuinely a norm and `lp` is a complete metric space. ## Main definitions * `Memℓp f p` : property that the function `f` satisfies, as appropriate, `f` finitely supported if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if `0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if `p = ∞`. * `lp E p` : elements of `∀ i : α, E i` such that `Memℓp f p`. Defined as an `AddSubgroup` of a type synonym `PreLp` for `∀ i : α, E i`, and equipped with a `NormedAddCommGroup` structure. Under appropriate conditions, this is also equipped with the instances `lp.normedSpace`, `lp.completeSpace`. For `p=∞`, there is also `lp.inftyNormedRing`, `lp.inftyNormedAlgebra`, `lp.inftyStarRing` and `lp.inftyCStarRing`. ## Main results * `Memℓp.of_exponent_ge`: For `q ≤ p`, a function which is `Memℓp` for `q` is also `Memℓp` for `p`. * `lp.memℓp_of_tendsto`, `lp.norm_le_of_tendsto`: A pointwise limit of functions in `lp`, all with `lp` norm `≤ C`, is itself in `lp` and has `lp` norm `≤ C`. * `lp.tsum_mul_le_mul_norm`: basic form of Hölder's inequality ## Implementation Since `lp` is defined as an `AddSubgroup`, dot notation does not work. Use `lp.norm_neg f` to say that `‖-f‖ = ‖f‖`, instead of the non-working `f.norm_neg`. ## TODO * More versions of Hölder's inequality (for example: the case `p = 1`, `q = ∞`; a version for normed rings which has `‖∑' i, f i * g i‖` rather than `∑' i, ‖f i‖ * g i‖` on the RHS; a version for three exponents satisfying `1 / r = 1 / p + 1 / q`) -/ noncomputable section open scoped NNReal ENNReal Function variable {𝕜 𝕜' : Type*} {α : Type*} {E : α → Type*} {p q : ℝ≥0∞} [∀ i, NormedAddCommGroup (E i)] /-! ### `Memℓp` predicate -/ /-- The property that `f : ∀ i : α, E i` * is finitely supported, if `p = 0`, or * admits an upper bound for `Set.range (fun i ↦ ‖f i‖)`, if `p = ∞`, or * has the series `∑' i, ‖f i‖ ^ p` be summable, if `0 < p < ∞`. -/ def Memℓp (f : ∀ i, E i) (p : ℝ≥0∞) : Prop := if p = 0 then Set.Finite { i | f i ≠ 0 } else if p = ∞ then BddAbove (Set.range fun i => ‖f i‖) else Summable fun i => ‖f i‖ ^ p.toReal theorem memℓp_zero_iff {f : ∀ i, E i} : Memℓp f 0 ↔ Set.Finite { i | f i ≠ 0 } := by dsimp [Memℓp] rw [if_pos rfl] theorem memℓp_zero {f : ∀ i, E i} (hf : Set.Finite { i | f i ≠ 0 }) : Memℓp f 0 := memℓp_zero_iff.2 hf theorem memℓp_infty_iff {f : ∀ i, E i} : Memℓp f ∞ ↔ BddAbove (Set.range fun i => ‖f i‖) := by simp [Memℓp] theorem memℓp_infty {f : ∀ i, E i} (hf : BddAbove (Set.range fun i => ‖f i‖)) : Memℓp f ∞ := memℓp_infty_iff.2 hf theorem memℓp_gen_iff (hp : 0 < p.toReal) {f : ∀ i, E i} : Memℓp f p ↔ Summable fun i => ‖f i‖ ^ p.toReal := by rw [ENNReal.toReal_pos_iff] at hp dsimp [Memℓp] rw [if_neg hp.1.ne', if_neg hp.2.ne] theorem memℓp_gen {f : ∀ i, E i} (hf : Summable fun i => ‖f i‖ ^ p.toReal) : Memℓp f p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf exact (Set.Finite.of_summable_const (by simp) H).subset (Set.subset_univ _) · apply memℓp_infty have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf simpa using ((Set.Finite.of_summable_const (by simp) H).image fun i => ‖f i‖).bddAbove exact (memℓp_gen_iff hp).2 hf theorem memℓp_gen' {C : ℝ} {f : ∀ i, E i} (hf : ∀ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ C) : Memℓp f p := by apply memℓp_gen use ⨆ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal apply hasSum_of_isLUB_of_nonneg · intro b exact Real.rpow_nonneg (norm_nonneg _) _ apply isLUB_ciSup use C rintro - ⟨s, rfl⟩ exact hf s theorem zero_memℓp : Memℓp (0 : ∀ i, E i) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero simp · apply memℓp_infty simp only [norm_zero, Pi.zero_apply] exact bddAbove_singleton.mono Set.range_const_subset · apply memℓp_gen simp [Real.zero_rpow hp.ne', summable_zero] theorem zero_mem_ℓp' : Memℓp (fun i : α => (0 : E i)) p := zero_memℓp namespace Memℓp theorem finite_dsupport {f : ∀ i, E i} (hf : Memℓp f 0) : Set.Finite { i | f i ≠ 0 } := memℓp_zero_iff.1 hf theorem bddAbove {f : ∀ i, E i} (hf : Memℓp f ∞) : BddAbove (Set.range fun i => ‖f i‖) := memℓp_infty_iff.1 hf theorem summable (hp : 0 < p.toReal) {f : ∀ i, E i} (hf : Memℓp f p) : Summable fun i => ‖f i‖ ^ p.toReal := (memℓp_gen_iff hp).1 hf theorem neg {f : ∀ i, E i} (hf : Memℓp f p) : Memℓp (-f) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero simp [hf.finite_dsupport] · apply memℓp_infty simpa using hf.bddAbove · apply memℓp_gen simpa using hf.summable hp @[simp] theorem neg_iff {f : ∀ i, E i} : Memℓp (-f) p ↔ Memℓp f p := ⟨fun h => neg_neg f ▸ h.neg, Memℓp.neg⟩ theorem of_exponent_ge {p q : ℝ≥0∞} {f : ∀ i, E i} (hfq : Memℓp f q) (hpq : q ≤ p) : Memℓp f p := by rcases ENNReal.trichotomy₂ hpq with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, hp⟩ | ⟨rfl, rfl⟩ | ⟨hq, rfl⟩ | ⟨hq, _, hpq'⟩) · exact hfq · apply memℓp_infty obtain ⟨C, hC⟩ := (hfq.finite_dsupport.image fun i => ‖f i‖).bddAbove use max 0 C rintro x ⟨i, rfl⟩ by_cases hi : f i = 0 · simp [hi] · exact (hC ⟨i, hi, rfl⟩).trans (le_max_right _ _) · apply memℓp_gen have : ∀ i ∉ hfq.finite_dsupport.toFinset, ‖f i‖ ^ p.toReal = 0 := by intro i hi have : f i = 0 := by simpa using hi simp [this, Real.zero_rpow hp.ne'] exact summable_of_ne_finset_zero this · exact hfq · apply memℓp_infty obtain ⟨A, hA⟩ := (hfq.summable hq).tendsto_cofinite_zero.bddAbove_range_of_cofinite use A ^ q.toReal⁻¹ rintro x ⟨i, rfl⟩ have : 0 ≤ ‖f i‖ ^ q.toReal := by positivity simpa [← Real.rpow_mul, mul_inv_cancel₀ hq.ne'] using Real.rpow_le_rpow this (hA ⟨i, rfl⟩) (inv_nonneg.mpr hq.le) · apply memℓp_gen have hf' := hfq.summable hq refine .of_norm_bounded_eventually hf' (@Set.Finite.subset _ { i | 1 ≤ ‖f i‖ } ?_ _ ?_) · have H : { x : α | 1 ≤ ‖f x‖ ^ q.toReal }.Finite := by simpa using hf'.tendsto_cofinite_zero.eventually_lt_const (by simp) exact H.subset fun i hi => Real.one_le_rpow hi hq.le · change ∀ i, ¬|‖f i‖ ^ p.toReal| ≤ ‖f i‖ ^ q.toReal → 1 ≤ ‖f i‖ intro i hi have : 0 ≤ ‖f i‖ ^ p.toReal := Real.rpow_nonneg (norm_nonneg _) p.toReal simp only [abs_of_nonneg, this] at hi contrapose! hi exact Real.rpow_le_rpow_of_exponent_ge' (norm_nonneg _) hi.le hq.le hpq' theorem add {f g : ∀ i, E i} (hf : Memℓp f p) (hg : Memℓp g p) : Memℓp (f + g) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero refine (hf.finite_dsupport.union hg.finite_dsupport).subset fun i => ?_ simp only [Pi.add_apply, Ne, Set.mem_union, Set.mem_setOf_eq] contrapose! rintro ⟨hf', hg'⟩ simp [hf', hg'] · apply memℓp_infty obtain ⟨A, hA⟩ := hf.bddAbove obtain ⟨B, hB⟩ := hg.bddAbove refine ⟨A + B, ?_⟩ rintro a ⟨i, rfl⟩ exact le_trans (norm_add_le _ _) (add_le_add (hA ⟨i, rfl⟩) (hB ⟨i, rfl⟩)) apply memℓp_gen let C : ℝ := if p.toReal < 1 then 1 else (2 : ℝ) ^ (p.toReal - 1) refine .of_nonneg_of_le ?_ (fun i => ?_) (((hf.summable hp).add (hg.summable hp)).mul_left C) · intro; positivity · refine (Real.rpow_le_rpow (norm_nonneg _) (norm_add_le _ _) hp.le).trans ?_ dsimp only [C] split_ifs with h · simpa using NNReal.coe_le_coe.2 (NNReal.rpow_add_le_add_rpow ‖f i‖₊ ‖g i‖₊ hp.le h.le) · let F : Fin 2 → ℝ≥0 := ![‖f i‖₊, ‖g i‖₊] simp only [not_lt] at h simpa [Fin.sum_univ_succ] using Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg Finset.univ h fun i _ => (F i).coe_nonneg theorem sub {f g : ∀ i, E i} (hf : Memℓp f p) (hg : Memℓp g p) : Memℓp (f - g) p := by rw [sub_eq_add_neg]; exact hf.add hg.neg theorem finset_sum {ι} (s : Finset ι) {f : ι → ∀ i, E i} (hf : ∀ i ∈ s, Memℓp (f i) p) : Memℓp (fun a => ∑ i ∈ s, f i a) p := by haveI : DecidableEq ι := Classical.decEq _ revert hf refine Finset.induction_on s ?_ ?_ · simp only [zero_mem_ℓp', Finset.sum_empty, imp_true_iff] · intro i s his ih hf simp only [his, Finset.sum_insert, not_false_iff] exact (hf i (s.mem_insert_self i)).add (ih fun j hj => hf j (Finset.mem_insert_of_mem hj)) section IsBoundedSMul variable [NormedRing 𝕜] [∀ i, Module 𝕜 (E i)] [∀ i, IsBoundedSMul 𝕜 (E i)] theorem const_smul {f : ∀ i, E i} (hf : Memℓp f p) (c : 𝕜) : Memℓp (c • f) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero refine hf.finite_dsupport.subset fun i => (?_ : ¬c • f i = 0 → ¬f i = 0) exact not_imp_not.mpr fun hf' => hf'.symm ▸ smul_zero c · obtain ⟨A, hA⟩ := hf.bddAbove refine memℓp_infty ⟨‖c‖ * A, ?_⟩ rintro a ⟨i, rfl⟩ dsimp only [Pi.smul_apply] refine (norm_smul_le _ _).trans ?_ gcongr exact hA ⟨i, rfl⟩ · apply memℓp_gen dsimp only [Pi.smul_apply] have := (hf.summable hp).mul_left (↑(‖c‖₊ ^ p.toReal) : ℝ) simp_rw [← coe_nnnorm, ← NNReal.coe_rpow, ← NNReal.coe_mul, NNReal.summable_coe, ← NNReal.mul_rpow] at this ⊢ refine NNReal.summable_of_le ?_ this intro i gcongr apply nnnorm_smul_le theorem const_mul {f : α → 𝕜} (hf : Memℓp f p) (c : 𝕜) : Memℓp (fun x => c * f x) p := hf.const_smul c end IsBoundedSMul end Memℓp /-! ### lp space The space of elements of `∀ i, E i` satisfying the predicate `Memℓp`. -/ /-- We define `PreLp E` to be a type synonym for `∀ i, E i` which, importantly, does not inherit the `pi` topology on `∀ i, E i` (otherwise this topology would descend to `lp E p` and conflict with the normed group topology we will later equip it with.) We choose to deal with this issue by making a type synonym for `∀ i, E i` rather than for the `lp` subgroup itself, because this allows all the spaces `lp E p` (for varying `p`) to be subgroups of the same ambient group, which permits lemma statements like `lp.monotone` (below). -/ @[nolint unusedArguments] def PreLp (E : α → Type*) [∀ i, NormedAddCommGroup (E i)] : Type _ := ∀ i, E i --deriving AddCommGroup instance : AddCommGroup (PreLp E) := by unfold PreLp; infer_instance instance PreLp.unique [IsEmpty α] : Unique (PreLp E) := Pi.uniqueOfIsEmpty E /-- lp space The `p=∞` case has notation `ℓ^∞(ι, E)` resp. `ℓ^∞(ι)` (for `E = ℝ`) in the `lp` namespace. -/ def lp (E : α → Type*) [∀ i, NormedAddCommGroup (E i)] (p : ℝ≥0∞) : AddSubgroup (PreLp E) where carrier := { f | Memℓp f p } zero_mem' := zero_memℓp add_mem' := Memℓp.add neg_mem' := Memℓp.neg @[inherit_doc] scoped[lp] notation "ℓ^∞(" ι ", " E ")" => lp (fun i : ι => E) ∞ @[inherit_doc] scoped[lp] notation "ℓ^∞(" ι ")" => lp (fun i : ι => ℝ) ∞ namespace lp instance : CoeOut (lp E p) (∀ i, E i) := ⟨Subtype.val (α := ∀ i, E i)⟩ instance coeFun : CoeFun (lp E p) fun _ => ∀ i, E i := ⟨fun f => (f : ∀ i, E i)⟩ @[ext] theorem ext {f g : lp E p} (h : (f : ∀ i, E i) = g) : f = g := Subtype.ext h theorem eq_zero' [IsEmpty α] (f : lp E p) : f = 0 := Subsingleton.elim f 0 protected theorem monotone {p q : ℝ≥0∞} (hpq : q ≤ p) : lp E q ≤ lp E p := fun _ hf => Memℓp.of_exponent_ge hf hpq protected theorem memℓp (f : lp E p) : Memℓp f p := f.prop variable (E p) @[simp] theorem coeFn_zero : ⇑(0 : lp E p) = 0 := rfl variable {E p} @[simp] theorem coeFn_neg (f : lp E p) : ⇑(-f) = -f := rfl @[simp] theorem coeFn_add (f g : lp E p) : ⇑(f + g) = f + g := rfl variable (p E) in /-- Coercion to function as an `AddMonoidHom`. -/ def coeFnAddMonoidHom : lp E p →+ (∀ i, E i) where toFun := (⇑) __ := AddSubgroup.subtype _ @[simp] theorem coeFnAddMonoidHom_apply (x : lp E p) : coeFnAddMonoidHom E p x = ⇑x := rfl theorem coeFn_sum {ι : Type*} (f : ι → lp E p) (s : Finset ι) : ⇑(∑ i ∈ s, f i) = ∑ i ∈ s, ⇑(f i) := by simp @[simp] theorem coeFn_sub (f g : lp E p) : ⇑(f - g) = f - g := rfl instance : Norm (lp E p) where norm f := if hp : p = 0 then by subst hp exact ((lp.memℓp f).finite_dsupport.toFinset.card : ℝ) else if p = ∞ then ⨆ i, ‖f i‖ else (∑' i, ‖f i‖ ^ p.toReal) ^ (1 / p.toReal) theorem norm_eq_card_dsupport (f : lp E 0) : ‖f‖ = (lp.memℓp f).finite_dsupport.toFinset.card := dif_pos rfl theorem norm_eq_ciSup (f : lp E ∞) : ‖f‖ = ⨆ i, ‖f i‖ := rfl theorem isLUB_norm [Nonempty α] (f : lp E ∞) : IsLUB (Set.range fun i => ‖f i‖) ‖f‖ := by rw [lp.norm_eq_ciSup] exact isLUB_ciSup (lp.memℓp f) theorem norm_eq_tsum_rpow (hp : 0 < p.toReal) (f : lp E p) : ‖f‖ = (∑' i, ‖f i‖ ^ p.toReal) ^ (1 / p.toReal) := by dsimp [norm] rw [ENNReal.toReal_pos_iff] at hp rw [dif_neg hp.1.ne', if_neg hp.2.ne] theorem norm_rpow_eq_tsum (hp : 0 < p.toReal) (f : lp E p) : ‖f‖ ^ p.toReal = ∑' i, ‖f i‖ ^ p.toReal := by rw [norm_eq_tsum_rpow hp, ← Real.rpow_mul] · field_simp apply tsum_nonneg intro i calc (0 : ℝ) = (0 : ℝ) ^ p.toReal := by rw [Real.zero_rpow hp.ne'] _ ≤ _ := by gcongr; apply norm_nonneg theorem hasSum_norm (hp : 0 < p.toReal) (f : lp E p) : HasSum (fun i => ‖f i‖ ^ p.toReal) (‖f‖ ^ p.toReal) := by rw [norm_rpow_eq_tsum hp] exact ((lp.memℓp f).summable hp).hasSum theorem norm_nonneg' (f : lp E p) : 0 ≤ ‖f‖ := by rcases p.trichotomy with (rfl | rfl | hp) · simp [lp.norm_eq_card_dsupport f] · rcases isEmpty_or_nonempty α with _i | _i · rw [lp.norm_eq_ciSup] simp [Real.iSup_of_isEmpty] inhabit α exact (norm_nonneg (f default)).trans ((lp.isLUB_norm f).1 ⟨default, rfl⟩) · rw [lp.norm_eq_tsum_rpow hp f] refine Real.rpow_nonneg (tsum_nonneg ?_) _ exact fun i => Real.rpow_nonneg (norm_nonneg _) _ @[simp] theorem norm_zero : ‖(0 : lp E p)‖ = 0 := by rcases p.trichotomy with (rfl | rfl | hp) · simp [lp.norm_eq_card_dsupport] · simp [lp.norm_eq_ciSup] · rw [lp.norm_eq_tsum_rpow hp] have hp' : 1 / p.toReal ≠ 0 := one_div_ne_zero hp.ne' simpa [Real.zero_rpow hp.ne'] using Real.zero_rpow hp' theorem norm_eq_zero_iff {f : lp E p} : ‖f‖ = 0 ↔ f = 0 := by refine ⟨fun h => ?_, by rintro rfl; exact norm_zero⟩ rcases p.trichotomy with (rfl | rfl | hp) · ext i have : { i : α | ¬f i = 0 } = ∅ := by simpa [lp.norm_eq_card_dsupport f] using h have : (¬f i = 0) = False := congr_fun this i tauto · rcases isEmpty_or_nonempty α with _i | _i · simp [eq_iff_true_of_subsingleton] have H : IsLUB (Set.range fun i => ‖f i‖) 0 := by simpa [h] using lp.isLUB_norm f ext i have : ‖f i‖ = 0 := le_antisymm (H.1 ⟨i, rfl⟩) (norm_nonneg _) simpa using this · have hf : HasSum (fun i : α => ‖f i‖ ^ p.toReal) 0 := by have := lp.hasSum_norm hp f rwa [h, Real.zero_rpow hp.ne'] at this have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _ rw [hasSum_zero_iff_of_nonneg this] at hf ext i have : f i = 0 ∧ p.toReal ≠ 0 := by simpa [Real.rpow_eq_zero_iff_of_nonneg (norm_nonneg (f i))] using congr_fun hf i exact this.1 theorem eq_zero_iff_coeFn_eq_zero {f : lp E p} : f = 0 ↔ ⇑f = 0 := by rw [lp.ext_iff, coeFn_zero] @[simp] theorem norm_neg ⦃f : lp E p⦄ : ‖-f‖ = ‖f‖ := by rcases p.trichotomy with (rfl | rfl | hp) · simp only [norm_eq_card_dsupport, coeFn_neg, Pi.neg_apply, ne_eq, neg_eq_zero] · cases isEmpty_or_nonempty α · simp only [lp.eq_zero' f, neg_zero, norm_zero] apply (lp.isLUB_norm (-f)).unique simpa only [coeFn_neg, Pi.neg_apply, norm_neg] using lp.isLUB_norm f · suffices ‖-f‖ ^ p.toReal = ‖f‖ ^ p.toReal by exact Real.rpow_left_injOn hp.ne' (norm_nonneg' _) (norm_nonneg' _) this apply (lp.hasSum_norm hp (-f)).unique simpa only [coeFn_neg, Pi.neg_apply, _root_.norm_neg] using lp.hasSum_norm hp f instance normedAddCommGroup [hp : Fact (1 ≤ p)] : NormedAddCommGroup (lp E p) := AddGroupNorm.toNormedAddCommGroup { toFun := norm map_zero' := norm_zero neg' := norm_neg add_le' := fun f g => by rcases p.dichotomy with (rfl | hp') · cases isEmpty_or_nonempty α · simp only [lp.eq_zero' f, zero_add, norm_zero, le_refl] refine (lp.isLUB_norm (f + g)).2 ?_ rintro x ⟨i, rfl⟩ refine le_trans ?_ (add_mem_upperBounds_add (lp.isLUB_norm f).1 (lp.isLUB_norm g).1 ⟨_, ⟨i, rfl⟩, _, ⟨i, rfl⟩, rfl⟩) exact norm_add_le (f i) (g i) · have hp'' : 0 < p.toReal := zero_lt_one.trans_le hp' have hf₁ : ∀ i, 0 ≤ ‖f i‖ := fun i => norm_nonneg _ have hg₁ : ∀ i, 0 ≤ ‖g i‖ := fun i => norm_nonneg _ have hf₂ := lp.hasSum_norm hp'' f have hg₂ := lp.hasSum_norm hp'' g -- apply Minkowski's inequality obtain ⟨C, hC₁, hC₂, hCfg⟩ := Real.Lp_add_le_hasSum_of_nonneg hp' hf₁ hg₁ (norm_nonneg' _) (norm_nonneg' _) hf₂ hg₂ refine le_trans ?_ hC₂ rw [← Real.rpow_le_rpow_iff (norm_nonneg' (f + g)) hC₁ hp''] refine hasSum_le ?_ (lp.hasSum_norm hp'' (f + g)) hCfg intro i gcongr apply norm_add_le eq_zero_of_map_eq_zero' := fun _ => norm_eq_zero_iff.1 } -- TODO: define an `ENNReal` version of `HolderConjugate`, and then express this inequality -- in a better version which also covers the case `p = 1, q = ∞`. /-- Hölder inequality -/ protected theorem tsum_mul_le_mul_norm {p q : ℝ≥0∞} (hpq : p.toReal.HolderConjugate q.toReal) (f : lp E p) (g : lp E q) : (Summable fun i => ‖f i‖ * ‖g i‖) ∧ ∑' i, ‖f i‖ * ‖g i‖ ≤ ‖f‖ * ‖g‖ := by have hf₁ : ∀ i, 0 ≤ ‖f i‖ := fun i => norm_nonneg _ have hg₁ : ∀ i, 0 ≤ ‖g i‖ := fun i => norm_nonneg _ have hf₂ := lp.hasSum_norm hpq.pos f have hg₂ := lp.hasSum_norm hpq.symm.pos g obtain ⟨C, -, hC', hC⟩ := Real.inner_le_Lp_mul_Lq_hasSum_of_nonneg hpq (norm_nonneg' _) (norm_nonneg' _) hf₁ hg₁ hf₂ hg₂ rw [← hC.tsum_eq] at hC' exact ⟨hC.summable, hC'⟩ protected theorem summable_mul {p q : ℝ≥0∞} (hpq : p.toReal.HolderConjugate q.toReal) (f : lp E p) (g : lp E q) : Summable fun i => ‖f i‖ * ‖g i‖ := (lp.tsum_mul_le_mul_norm hpq f g).1 protected theorem tsum_mul_le_mul_norm' {p q : ℝ≥0∞} (hpq : p.toReal.HolderConjugate q.toReal) (f : lp E p) (g : lp E q) : ∑' i, ‖f i‖ * ‖g i‖ ≤ ‖f‖ * ‖g‖ := (lp.tsum_mul_le_mul_norm hpq f g).2 section ComparePointwise theorem norm_apply_le_norm (hp : p ≠ 0) (f : lp E p) (i : α) : ‖f i‖ ≤ ‖f‖ := by rcases eq_or_ne p ∞ with (rfl | hp') · haveI : Nonempty α := ⟨i⟩ exact (isLUB_norm f).1 ⟨i, rfl⟩ have hp'' : 0 < p.toReal := ENNReal.toReal_pos hp hp' have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _ rw [← Real.rpow_le_rpow_iff (norm_nonneg _) (norm_nonneg' _) hp''] convert le_hasSum (hasSum_norm hp'' f) i fun i _ => this i theorem sum_rpow_le_norm_rpow (hp : 0 < p.toReal) (f : lp E p) (s : Finset α) : ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ ‖f‖ ^ p.toReal := by rw [lp.norm_rpow_eq_tsum hp f] have : ∀ i, 0 ≤ ‖f i‖ ^ p.toReal := fun i => Real.rpow_nonneg (norm_nonneg _) _ refine Summable.sum_le_tsum _ (fun i _ => this i) ?_ exact (lp.memℓp f).summable hp theorem norm_le_of_forall_le' [Nonempty α] {f : lp E ∞} (C : ℝ) (hCf : ∀ i, ‖f i‖ ≤ C) : ‖f‖ ≤ C := by refine (isLUB_norm f).2 ?_ rintro - ⟨i, rfl⟩ exact hCf i theorem norm_le_of_forall_le {f : lp E ∞} {C : ℝ} (hC : 0 ≤ C) (hCf : ∀ i, ‖f i‖ ≤ C) : ‖f‖ ≤ C := by cases isEmpty_or_nonempty α · simpa [eq_zero' f] using hC · exact norm_le_of_forall_le' C hCf theorem norm_le_of_tsum_le (hp : 0 < p.toReal) {C : ℝ} (hC : 0 ≤ C) {f : lp E p} (hf : ∑' i, ‖f i‖ ^ p.toReal ≤ C ^ p.toReal) : ‖f‖ ≤ C := by rw [← Real.rpow_le_rpow_iff (norm_nonneg' _) hC hp, norm_rpow_eq_tsum hp] exact hf theorem norm_le_of_forall_sum_le (hp : 0 < p.toReal) {C : ℝ} (hC : 0 ≤ C) {f : lp E p} (hf : ∀ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ C ^ p.toReal) : ‖f‖ ≤ C := norm_le_of_tsum_le hp hC (((lp.memℓp f).summable hp).tsum_le_of_sum_le hf) end ComparePointwise section IsBoundedSMul variable [NormedRing 𝕜] [NormedRing 𝕜'] variable [∀ i, Module 𝕜 (E i)] [∀ i, Module 𝕜' (E i)] instance : Module 𝕜 (PreLp E) := Pi.module α E 𝕜 instance [∀ i, SMulCommClass 𝕜' 𝕜 (E i)] : SMulCommClass 𝕜' 𝕜 (PreLp E) := Pi.smulCommClass instance [SMul 𝕜' 𝕜] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)] : IsScalarTower 𝕜' 𝕜 (PreLp E) := Pi.isScalarTower instance [∀ i, Module 𝕜ᵐᵒᵖ (E i)] [∀ i, IsCentralScalar 𝕜 (E i)] : IsCentralScalar 𝕜 (PreLp E) := Pi.isCentralScalar variable [∀ i, IsBoundedSMul 𝕜 (E i)] [∀ i, IsBoundedSMul 𝕜' (E i)] theorem mem_lp_const_smul (c : 𝕜) (f : lp E p) : c • (f : PreLp E) ∈ lp E p := (lp.memℓp f).const_smul c variable (𝕜 E p) /-- The `𝕜`-submodule of elements of `∀ i : α, E i` whose `lp` norm is finite. This is `lp E p`, with extra structure. -/ def _root_.lpSubmodule : Submodule 𝕜 (PreLp E) := { lp E p with smul_mem' := fun c f hf => by simpa using mem_lp_const_smul c ⟨f, hf⟩ } variable {𝕜 E p} theorem coe_lpSubmodule : (lpSubmodule 𝕜 E p).toAddSubgroup = lp E p := rfl instance : Module 𝕜 (lp E p) := { (lpSubmodule 𝕜 E p).module with } @[simp] theorem coeFn_smul (c : 𝕜) (f : lp E p) : ⇑(c • f) = c • ⇑f := rfl instance [∀ i, SMulCommClass 𝕜' 𝕜 (E i)] : SMulCommClass 𝕜' 𝕜 (lp E p) := ⟨fun _ _ _ => Subtype.ext <| smul_comm _ _ _⟩ instance [SMul 𝕜' 𝕜] [∀ i, IsScalarTower 𝕜' 𝕜 (E i)] : IsScalarTower 𝕜' 𝕜 (lp E p) := ⟨fun _ _ _ => Subtype.ext <| smul_assoc _ _ _⟩ instance [∀ i, Module 𝕜ᵐᵒᵖ (E i)] [∀ i, IsCentralScalar 𝕜 (E i)] : IsCentralScalar 𝕜 (lp E p) := ⟨fun _ _ => Subtype.ext <| op_smul_eq_smul _ _⟩ theorem norm_const_smul_le (hp : p ≠ 0) (c : 𝕜) (f : lp E p) : ‖c • f‖ ≤ ‖c‖ * ‖f‖ := by rcases p.trichotomy with (rfl | rfl | hp) · exact absurd rfl hp · cases isEmpty_or_nonempty α · simp [lp.eq_zero' f] have hcf := lp.isLUB_norm (c • f) have hfc := (lp.isLUB_norm f).mul_left (norm_nonneg c) simp_rw [← Set.range_comp, Function.comp_def] at hfc -- TODO: some `IsLUB` API should make it a one-liner from here. refine hcf.right ?_ have := hfc.left simp_rw [mem_upperBounds, Set.mem_range, forall_exists_index, forall_apply_eq_imp_iff] at this ⊢ intro a exact (norm_smul_le _ _).trans (this a) · letI inst : NNNorm (lp E p) := ⟨fun f => ⟨‖f‖, norm_nonneg' _⟩⟩ have coe_nnnorm : ∀ f : lp E p, ↑‖f‖₊ = ‖f‖ := fun _ => rfl suffices ‖c • f‖₊ ^ p.toReal ≤ (‖c‖₊ * ‖f‖₊) ^ p.toReal by rwa [NNReal.rpow_le_rpow_iff hp] at this clear_value inst rw [NNReal.mul_rpow] have hLHS := lp.hasSum_norm hp (c • f) have hRHS := (lp.hasSum_norm hp f).mul_left (‖c‖ ^ p.toReal) simp_rw [← coe_nnnorm, ← _root_.coe_nnnorm, ← NNReal.coe_rpow, ← NNReal.coe_mul, NNReal.hasSum_coe] at hRHS hLHS refine hasSum_mono hLHS hRHS fun i => ?_ dsimp only rw [← NNReal.mul_rpow] -- Porting note: added rw [lp.coeFn_smul, Pi.smul_apply] gcongr apply nnnorm_smul_le instance [Fact (1 ≤ p)] : IsBoundedSMul 𝕜 (lp E p) := IsBoundedSMul.of_norm_smul_le <| norm_const_smul_le (zero_lt_one.trans_le <| Fact.out).ne' end IsBoundedSMul section DivisionRing variable [NormedDivisionRing 𝕜] [∀ i, Module 𝕜 (E i)] [∀ i, IsBoundedSMul 𝕜 (E i)] theorem norm_const_smul (hp : p ≠ 0) {c : 𝕜} (f : lp E p) : ‖c • f‖ = ‖c‖ * ‖f‖ := by obtain rfl | hc := eq_or_ne c 0 · simp refine le_antisymm (norm_const_smul_le hp c f) ?_ have := mul_le_mul_of_nonneg_left (norm_const_smul_le hp c⁻¹ (c • f)) (norm_nonneg c) rwa [inv_smul_smul₀ hc, norm_inv, mul_inv_cancel_left₀ (norm_ne_zero_iff.mpr hc)] at this end DivisionRing section NormedSpace variable [NormedField 𝕜] [∀ i, NormedSpace 𝕜 (E i)] instance instNormedSpace [Fact (1 ≤ p)] : NormedSpace 𝕜 (lp E p) where norm_smul_le c f := norm_smul_le c f end NormedSpace section NormedStarGroup variable [∀ i, StarAddMonoid (E i)] [∀ i, NormedStarGroup (E i)] theorem _root_.Memℓp.star_mem {f : ∀ i, E i} (hf : Memℓp f p) : Memℓp (star f) p := by rcases p.trichotomy with (rfl | rfl | hp) · apply memℓp_zero simp [hf.finite_dsupport] · apply memℓp_infty simpa using hf.bddAbove · apply memℓp_gen simpa using hf.summable hp @[simp] theorem _root_.Memℓp.star_iff {f : ∀ i, E i} : Memℓp (star f) p ↔ Memℓp f p := ⟨fun h => star_star f ▸ Memℓp.star_mem h, Memℓp.star_mem⟩ instance : Star (lp E p) where star f := ⟨(star f : ∀ i, E i), f.property.star_mem⟩ @[simp] theorem coeFn_star (f : lp E p) : ⇑(star f) = star (⇑f) := rfl @[simp] protected theorem star_apply (f : lp E p) (i : α) : star f i = star (f i) := rfl instance instInvolutiveStar : InvolutiveStar (lp E p) where star_involutive x := by simp [star] instance instStarAddMonoid : StarAddMonoid (lp E p) where star_add _f _g := ext <| star_add (R := ∀ i, E i) _ _ instance [hp : Fact (1 ≤ p)] : NormedStarGroup (lp E p) where norm_star_le f := le_of_eq <| by rcases p.trichotomy with (rfl | rfl | h) · exfalso have := ENNReal.toReal_mono ENNReal.zero_ne_top hp.elim norm_num at this · simp only [lp.norm_eq_ciSup, lp.star_apply, norm_star] · simp only [lp.norm_eq_tsum_rpow h, lp.star_apply, norm_star] variable [Star 𝕜] [NormedRing 𝕜] variable [∀ i, Module 𝕜 (E i)] [∀ i, IsBoundedSMul 𝕜 (E i)] [∀ i, StarModule 𝕜 (E i)] instance : StarModule 𝕜 (lp E p) where star_smul _r _f := ext <| star_smul (A := ∀ i, E i) _ _ end NormedStarGroup section NonUnitalNormedRing variable {I : Type*} {B : I → Type*} [∀ i, NonUnitalNormedRing (B i)] theorem _root_.Memℓp.infty_mul {f g : ∀ i, B i} (hf : Memℓp f ∞) (hg : Memℓp g ∞) : Memℓp (f * g) ∞ := by rw [memℓp_infty_iff] obtain ⟨⟨Cf, hCf⟩, ⟨Cg, hCg⟩⟩ := hf.bddAbove, hg.bddAbove refine ⟨Cf * Cg, ?_⟩ rintro _ ⟨i, rfl⟩ calc ‖(f * g) i‖ ≤ ‖f i‖ * ‖g i‖ := norm_mul_le (f i) (g i) _ ≤ Cf * Cg := mul_le_mul (hCf ⟨i, rfl⟩) (hCg ⟨i, rfl⟩) (norm_nonneg _) ((norm_nonneg _).trans (hCf ⟨i, rfl⟩)) instance : Mul (lp B ∞) where mul f g := ⟨HMul.hMul (α := ∀ i, B i) _ _ , f.property.infty_mul g.property⟩ @[simp] theorem infty_coeFn_mul (f g : lp B ∞) : ⇑(f * g) = ⇑f * ⇑g := rfl instance nonUnitalRing : NonUnitalRing (lp B ∞) := Function.Injective.nonUnitalRing lp.coeFun.coe Subtype.coe_injective (lp.coeFn_zero B ∞) lp.coeFn_add infty_coeFn_mul lp.coeFn_neg lp.coeFn_sub (fun _ _ => rfl) fun _ _ => rfl instance nonUnitalNormedRing : NonUnitalNormedRing (lp B ∞) := { lp.normedAddCommGroup, lp.nonUnitalRing with norm_mul_le f g := lp.norm_le_of_forall_le (by positivity) fun i ↦ calc ‖(f * g) i‖ ≤ ‖f i‖ * ‖g i‖ := norm_mul_le _ _ _ ≤ ‖f‖ * ‖g‖ := mul_le_mul (lp.norm_apply_le_norm ENNReal.top_ne_zero f i) (lp.norm_apply_le_norm ENNReal.top_ne_zero g i) (norm_nonneg _) (norm_nonneg _) } instance nonUnitalNormedCommRing {B : I → Type*} [∀ i, NonUnitalNormedCommRing (B i)] : NonUnitalNormedCommRing (lp B ∞) where mul_comm _ _ := ext <| mul_comm .. -- we also want a `NonUnitalNormedCommRing` instance, but this has to wait for https://github.com/leanprover-community/mathlib3/pull/13719 instance infty_isScalarTower {𝕜} [NormedRing 𝕜] [∀ i, Module 𝕜 (B i)] [∀ i, IsBoundedSMul 𝕜 (B i)] [∀ i, IsScalarTower 𝕜 (B i) (B i)] : IsScalarTower 𝕜 (lp B ∞) (lp B ∞) := ⟨fun r f g => lp.ext <| smul_assoc (N := ∀ i, B i) (α := ∀ i, B i) r (⇑f) (⇑g)⟩ instance infty_smulCommClass {𝕜} [NormedRing 𝕜] [∀ i, Module 𝕜 (B i)] [∀ i, IsBoundedSMul 𝕜 (B i)] [∀ i, SMulCommClass 𝕜 (B i) (B i)] : SMulCommClass 𝕜 (lp B ∞) (lp B ∞) := ⟨fun r f g => lp.ext <| smul_comm (N := ∀ i, B i) (α := ∀ i, B i) r (⇑f) (⇑g)⟩ section StarRing variable [∀ i, StarRing (B i)] [∀ i, NormedStarGroup (B i)] instance inftyStarRing : StarRing (lp B ∞) := { lp.instStarAddMonoid with star_mul := fun _f _g => ext <| star_mul (R := ∀ i, B i) _ _ } instance inftyCStarRing [∀ i, CStarRing (B i)] : CStarRing (lp B ∞) where norm_mul_self_le f := by rw [← sq, ← Real.le_sqrt (norm_nonneg _) (norm_nonneg _)] refine lp.norm_le_of_forall_le ‖star f * f‖.sqrt_nonneg fun i => ?_ rw [Real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ← CStarRing.norm_star_mul_self] exact lp.norm_apply_le_norm ENNReal.top_ne_zero (star f * f) i end StarRing end NonUnitalNormedRing section NormedRing variable {I : Type*} {B : I → Type*} [∀ i, NormedRing (B i)] instance _root_.PreLp.ring : Ring (PreLp B) := Pi.ring variable [∀ i, NormOneClass (B i)] theorem _root_.one_memℓp_infty : Memℓp (1 : ∀ i, B i) ∞ := ⟨1, by rintro i ⟨i, rfl⟩; exact norm_one.le⟩ variable (B) in /-- The `𝕜`-subring of elements of `∀ i : α, B i` whose `lp` norm is finite. This is `lp E ∞`, with extra structure. -/ def _root_.lpInftySubring : Subring (PreLp B) := { lp B ∞ with carrier := { f | Memℓp f ∞ } one_mem' := one_memℓp_infty mul_mem' := Memℓp.infty_mul } instance inftyRing : Ring (lp B ∞) := (lpInftySubring B).toRing theorem _root_.Memℓp.infty_pow {f : ∀ i, B i} (hf : Memℓp f ∞) (n : ℕ) : Memℓp (f ^ n) ∞ := (lpInftySubring B).pow_mem hf n theorem _root_.natCast_memℓp_infty (n : ℕ) : Memℓp (n : ∀ i, B i) ∞ := natCast_mem (lpInftySubring B) n theorem _root_.intCast_memℓp_infty (z : ℤ) : Memℓp (z : ∀ i, B i) ∞ := intCast_mem (lpInftySubring B) z @[simp] theorem infty_coeFn_one : ⇑(1 : lp B ∞) = 1 := rfl @[simp] theorem infty_coeFn_pow (f : lp B ∞) (n : ℕ) : ⇑(f ^ n) = (⇑f) ^ n := rfl @[simp] theorem infty_coeFn_natCast (n : ℕ) : ⇑(n : lp B ∞) = n := rfl @[simp] theorem infty_coeFn_intCast (z : ℤ) : ⇑(z : lp B ∞) = z := rfl instance [Nonempty I] : NormOneClass (lp B ∞) where norm_one := by simp_rw [lp.norm_eq_ciSup, infty_coeFn_one, Pi.one_apply, norm_one, ciSup_const] instance inftyNormedRing : NormedRing (lp B ∞) := { lp.inftyRing, lp.nonUnitalNormedRing with } end NormedRing section NormedCommRing variable {I : Type*} {B : I → Type*} [∀ i, NormedCommRing (B i)] [∀ i, NormOneClass (B i)] instance inftyNormedCommRing : NormedCommRing (lp B ∞) where mul_comm := mul_comm end NormedCommRing section Algebra variable {I : Type*} {B : I → Type*} variable [NormedField 𝕜] [∀ i, NormedRing (B i)] [∀ i, NormedAlgebra 𝕜 (B i)] /-- A variant of `Pi.algebra` that lean can't find otherwise. -/ instance _root_.Pi.algebraOfNormedAlgebra : Algebra 𝕜 (∀ i, B i) := @Pi.algebra I 𝕜 B _ _ fun _ => NormedAlgebra.toAlgebra instance _root_.PreLp.algebra : Algebra 𝕜 (PreLp B) := Pi.algebraOfNormedAlgebra variable [∀ i, NormOneClass (B i)] theorem _root_.algebraMap_memℓp_infty (k : 𝕜) : Memℓp (algebraMap 𝕜 (∀ i, B i) k) ∞ := by rw [Algebra.algebraMap_eq_smul_one] exact (one_memℓp_infty.const_smul k : Memℓp (k • (1 : ∀ i, B i)) ∞) variable (𝕜 B) /-- The `𝕜`-subalgebra of elements of `∀ i : α, B i` whose `lp` norm is finite. This is `lp E ∞`, with extra structure. -/ def _root_.lpInftySubalgebra : Subalgebra 𝕜 (PreLp B) := { lpInftySubring B with carrier := { f | Memℓp f ∞ } algebraMap_mem' := algebraMap_memℓp_infty } variable {𝕜 B} instance inftyNormedAlgebra : NormedAlgebra 𝕜 (lp B ∞) := { (lpInftySubalgebra 𝕜 B).algebra, (lp.instNormedSpace : NormedSpace 𝕜 (lp B ∞)) with } end Algebra section Single variable [NormedRing 𝕜] [∀ i, Module 𝕜 (E i)] [∀ i, IsBoundedSMul 𝕜 (E i)] variable [DecidableEq α] /-- The element of `lp E p` which is `a : E i` at the index `i`, and zero elsewhere. -/ protected def single (p) (i : α) (a : E i) : lp E p := ⟨Pi.single i a, by refine (memℓp_zero ?_).of_exponent_ge (zero_le p) refine (Set.finite_singleton i).subset ?_ intro j simp only [Set.mem_singleton_iff, Ne, Set.mem_setOf_eq] rw [not_imp_comm] intro h exact Pi.single_eq_of_ne h _⟩ @[norm_cast] protected theorem coeFn_single (p) (i : α) (a : E i) : ⇑(lp.single p i a) = Pi.single i a := rfl @[simp] protected theorem single_apply (p) (i : α) (a : E i) (j : α) : lp.single p i a j = Pi.single i a j := rfl protected theorem single_apply_self (p) (i : α) (a : E i) : lp.single p i a i = a := Pi.single_eq_same _ _ protected theorem single_apply_ne (p) (i : α) (a : E i) {j : α} (hij : j ≠ i) : lp.single p i a j = 0 := Pi.single_eq_of_ne hij _ @[simp] protected theorem single_zero (p) (i : α) : lp.single p i (0 : E i) = 0 := ext <| Pi.single_zero _ @[simp] protected theorem single_add (p) (i : α) (a b : E i) : lp.single p i (a + b) = lp.single p i a + lp.single p i b := ext <| Pi.single_add _ _ _ /-- `single` as an `AddMonoidHom`. -/ @[simps] def singleAddMonoidHom (p) (i : α) : E i →+ lp E p where toFun := lp.single p i map_zero' := lp.single_zero _ _ map_add' := lp.single_add _ _ @[simp] protected theorem single_neg (p) (i : α) (a : E i) : lp.single p i (-a) = -lp.single p i a := ext <| Pi.single_neg _ _ @[simp] protected theorem single_sub (p) (i : α) (a b : E i) : lp.single p i (a - b) = lp.single p i a - lp.single p i b := ext <| Pi.single_sub _ _ _ @[simp] protected theorem single_smul (p) (i : α) (c : 𝕜) (a : E i) : lp.single p i (c • a) = c • lp.single p i a := ext <| Pi.single_smul _ _ _ /-- `single` as a `LinearMap`. -/ @[simps] def lsingle (p) (i : α) : E i →ₗ[𝕜] lp E p where toFun := lp.single p i __ := singleAddMonoidHom p i map_smul' := lp.single_smul p i protected theorem norm_sum_single (hp : 0 < p.toReal) (f : ∀ i, E i) (s : Finset α) : ‖∑ i ∈ s, lp.single p i (f i)‖ ^ p.toReal = ∑ i ∈ s, ‖f i‖ ^ p.toReal := by refine (hasSum_norm hp (∑ i ∈ s, lp.single p i (f i))).unique ?_ simp only [lp.coeFn_single, coeFn_sum, Finset.sum_apply, Finset.sum_pi_single] have h : ∀ i ∉ s, ‖ite (i ∈ s) (f i) 0‖ ^ p.toReal = 0 := fun i hi ↦ by simp [if_neg hi, Real.zero_rpow hp.ne'] have h' : ∀ i ∈ s, ‖f i‖ ^ p.toReal = ‖ite (i ∈ s) (f i) 0‖ ^ p.toReal := by intro i hi rw [if_pos hi] simpa [Finset.sum_congr rfl h'] using hasSum_sum_of_ne_finset_zero h @[simp] protected theorem norm_single (hp : 0 < p) (i : α) (x : E i) : ‖lp.single p i x‖ = ‖x‖ := by haveI : Nonempty α := ⟨i⟩ induction p with | top => simp only [norm_eq_ciSup, lp.coeFn_single] refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun j => ?_) fun n hn => ⟨i, hn.trans_eq ?_⟩ · obtain rfl | hij := Decidable.eq_or_ne i j · rw [Pi.single_eq_same] · rw [Pi.single_eq_of_ne' hij, _root_.norm_zero] exact norm_nonneg _ · rw [Pi.single_eq_same] | coe p => have : 0 < (p : ℝ≥0∞).toReal := by simpa using hp rw [norm_eq_tsum_rpow this, tsum_eq_single i, lp.coeFn_single, one_div, Real.rpow_rpow_inv _ this.ne', Pi.single_eq_same] · exact norm_nonneg _ · intro j hji rw [lp.coeFn_single, Pi.single_eq_of_ne hji, _root_.norm_zero, Real.zero_rpow this.ne'] theorem isometry_single [Fact (1 ≤ p)] (i : α) : Isometry (lp.single (E := E) p i) := AddMonoidHomClass.isometry_of_norm (lp.singleAddMonoidHom (E := E) p i) fun _ ↦ lp.norm_single (zero_lt_one.trans_le Fact.out) _ _ variable (p E) in /-- `lp.single` as a continuous morphism of additive monoids. -/ def singleContinuousAddMonoidHom [Fact (1 ≤ p)] (i : α) : ContinuousAddMonoidHom (E i) (lp E p) where __ := singleAddMonoidHom p i continuous_toFun := isometry_single i |>.continuous @[simp] theorem singleContinuousAddMonoidHom_apply [Fact (1 ≤ p)] (i : α) (x : E i) : singleContinuousAddMonoidHom E p i x = lp.single p i x := rfl variable (𝕜 p E) in /-- `lp.single` as a continuous linear map. -/ def singleContinuousLinearMap [Fact (1 ≤ p)] (i : α) : E i →L[𝕜] lp E p where __ := lsingle p i cont := isometry_single i |>.continuous @[simp] theorem singleContinuousLinearMap_apply [Fact (1 ≤ p)] (i : α) (x : E i) : singleContinuousLinearMap 𝕜 E p i x = lp.single p i x := rfl protected theorem norm_sub_norm_compl_sub_single (hp : 0 < p.toReal) (f : lp E p) (s : Finset α) : ‖f‖ ^ p.toReal - ‖f - ∑ i ∈ s, lp.single p i (f i)‖ ^ p.toReal = ∑ i ∈ s, ‖f i‖ ^ p.toReal := by refine ((hasSum_norm hp f).sub (hasSum_norm hp (f - ∑ i ∈ s, lp.single p i (f i)))).unique ?_ let F : α → ℝ := fun i => ‖f i‖ ^ p.toReal - ‖(f - ∑ i ∈ s, lp.single p i (f i)) i‖ ^ p.toReal have hF : ∀ i ∉ s, F i = 0 := by intro i hi suffices ‖f i‖ ^ p.toReal - ‖f i - ite (i ∈ s) (f i) 0‖ ^ p.toReal = 0 by simpa only [coeFn_sub, coeFn_sum, lp.coeFn_single, Pi.sub_apply, Finset.sum_apply, Finset.sum_pi_single, F] using this simp only [if_neg hi, sub_zero, sub_self] have hF' : ∀ i ∈ s, F i = ‖f i‖ ^ p.toReal := by intro i hi simp only [F, coeFn_sum, lp.single_apply, if_pos hi, sub_self, coeFn_sub, Pi.sub_apply, Finset.sum_apply, Finset.sum_pi_single, sub_eq_self] simp [Real.zero_rpow hp.ne'] have : HasSum F (∑ i ∈ s, F i) := hasSum_sum_of_ne_finset_zero hF rwa [Finset.sum_congr rfl hF'] at this protected theorem norm_compl_sum_single (hp : 0 < p.toReal) (f : lp E p) (s : Finset α) : ‖f - ∑ i ∈ s, lp.single p i (f i)‖ ^ p.toReal = ‖f‖ ^ p.toReal - ∑ i ∈ s, ‖f i‖ ^ p.toReal := by linarith [lp.norm_sub_norm_compl_sub_single hp f s] /-- The canonical finitely-supported approximations to an element `f` of `lp` converge to it, in the `lp` topology. -/ protected theorem hasSum_single [Fact (1 ≤ p)] (hp : p ≠ ⊤) (f : lp E p) : HasSum (fun i : α => lp.single p i (f i : E i)) f := by have hp₀ : 0 < p := zero_lt_one.trans_le Fact.out have hp' : 0 < p.toReal := ENNReal.toReal_pos hp₀.ne' hp have := lp.hasSum_norm hp' f rw [HasSum, Metric.tendsto_nhds] at this ⊢ intro ε hε refine (this _ (Real.rpow_pos_of_pos hε p.toReal)).mono ?_ intro s hs rw [← Real.rpow_lt_rpow_iff dist_nonneg (le_of_lt hε) hp'] rw [dist_comm] at hs simp only [dist_eq_norm, Real.norm_eq_abs] at hs ⊢ have H : ‖(∑ i ∈ s, lp.single p i (f i : E i)) - f‖ ^ p.toReal = ‖f‖ ^ p.toReal - ∑ i ∈ s, ‖f i‖ ^ p.toReal := by simpa only [coeFn_neg, Pi.neg_apply, lp.single_neg, Finset.sum_neg_distrib, neg_sub_neg, norm_neg, _root_.norm_neg] using lp.norm_compl_sum_single hp' (-f) s rw [← H] at hs have : |‖(∑ i ∈ s, lp.single p i (f i : E i)) - f‖ ^ p.toReal| = ‖(∑ i ∈ s, lp.single p i (f i : E i)) - f‖ ^ p.toReal := by simp only [Real.abs_rpow_of_nonneg (norm_nonneg _), abs_norm] exact this ▸ hs /-- Two continuous additive maps from `lp E p` agree if they agree on `lp.single`. See note [partially-applied ext lemmas]. -/ @[local ext] -- not globally `ext` due to `hp` theorem ext_continuousAddMonoidHom {F : Type*} [AddCommMonoid F] [TopologicalSpace F] [T2Space F] [Fact (1 ≤ p)] (hp : p ≠ ⊤) ⦃f g : ContinuousAddMonoidHom (lp E p) F⦄ (h : ∀ i, f.comp (singleContinuousAddMonoidHom E p i) = g.comp (singleContinuousAddMonoidHom E p i)) : f = g := by ext x classical have := lp.hasSum_single hp x rw [← (this.map f f.continuous).tsum_eq, ← (this.map g g.continuous).tsum_eq] congr! 2 with i exact DFunLike.congr_fun (h i) (x i) /-- Two continuous linear maps from `lp E p` agree if they agree on `lp.single`. See note [partially-applied ext lemmas]. -/ @[local ext] -- not globally `ext` due to `hp` theorem ext_continuousLinearMap {F : Type*} [AddCommMonoid F] [Module 𝕜 F] [TopologicalSpace F] [T2Space F] [Fact (1 ≤ p)] (hp : p ≠ ⊤) ⦃f g : lp E p →L[𝕜] F⦄ (h : ∀ i, f.comp (singleContinuousLinearMap 𝕜 E p i) = g.comp (singleContinuousLinearMap 𝕜 E p i)) : f = g := ContinuousLinearMap.toContinuousAddMonoidHom_injective <| ext_continuousAddMonoidHom hp fun i => ContinuousLinearMap.toContinuousAddMonoidHom_inj.2 (h i) end Single section Topology open Filter open scoped Topology uniformity /-- The coercion from `lp E p` to `∀ i, E i` is uniformly continuous. -/ theorem uniformContinuous_coe [_i : Fact (1 ≤ p)] : UniformContinuous (α := lp E p) ((↑) : lp E p → ∀ i, E i) := by have hp : p ≠ 0 := (zero_lt_one.trans_le _i.elim).ne' rw [uniformContinuous_pi] intro i rw [NormedAddCommGroup.uniformity_basis_dist.uniformContinuous_iff NormedAddCommGroup.uniformity_basis_dist] intro ε hε refine ⟨ε, hε, ?_⟩ rintro f g (hfg : ‖f - g‖ < ε) have : ‖f i - g i‖ ≤ ‖f - g‖ := norm_apply_le_norm hp (f - g) i exact this.trans_lt hfg variable {ι : Type*} {l : Filter ι} [Filter.NeBot l] theorem norm_apply_le_of_tendsto {C : ℝ} {F : ι → lp E ∞} (hCF : ∀ᶠ k in l, ‖F k‖ ≤ C) {f : ∀ a, E a} (hf : Tendsto (id fun i => F i : ι → ∀ a, E a) l (𝓝 f)) (a : α) : ‖f a‖ ≤ C := by have : Tendsto (fun k => ‖F k a‖) l (𝓝 ‖f a‖) := (Tendsto.comp (continuous_apply a).continuousAt hf).norm refine le_of_tendsto this (hCF.mono ?_) intro k hCFk exact (norm_apply_le_norm ENNReal.top_ne_zero (F k) a).trans hCFk variable [_i : Fact (1 ≤ p)] theorem sum_rpow_le_of_tendsto (hp : p ≠ ∞) {C : ℝ} {F : ι → lp E p} (hCF : ∀ᶠ k in l, ‖F k‖ ≤ C) {f : ∀ a, E a} (hf : Tendsto (id fun i => F i : ι → ∀ a, E a) l (𝓝 f)) (s : Finset α) : ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ C ^ p.toReal := by have hp' : p ≠ 0 := (zero_lt_one.trans_le _i.elim).ne' have hp'' : 0 < p.toReal := ENNReal.toReal_pos hp' hp let G : (∀ a, E a) → ℝ := fun f => ∑ a ∈ s, ‖f a‖ ^ p.toReal have hG : Continuous G := by refine continuous_finset_sum s ?_ intro a _ have : Continuous fun f : ∀ a, E a => f a := continuous_apply a exact this.norm.rpow_const fun _ => Or.inr hp''.le refine le_of_tendsto (hG.continuousAt.tendsto.comp hf) ?_ refine hCF.mono ?_ intro k hCFk refine (lp.sum_rpow_le_norm_rpow hp'' (F k) s).trans ?_ gcongr /-- "Semicontinuity of the `lp` norm": If all sufficiently large elements of a sequence in `lp E p` have `lp` norm `≤ C`, then the pointwise limit, if it exists, also has `lp` norm `≤ C`. -/ theorem norm_le_of_tendsto {C : ℝ} {F : ι → lp E p} (hCF : ∀ᶠ k in l, ‖F k‖ ≤ C) {f : lp E p} (hf : Tendsto (id fun i => F i : ι → ∀ a, E a) l (𝓝 f)) : ‖f‖ ≤ C := by obtain ⟨i, hi⟩ := hCF.exists have hC : 0 ≤ C := (norm_nonneg _).trans hi rcases eq_top_or_lt_top p with (rfl | hp) · apply norm_le_of_forall_le hC exact norm_apply_le_of_tendsto hCF hf · have : 0 < p := zero_lt_one.trans_le _i.elim have hp' : 0 < p.toReal := ENNReal.toReal_pos this.ne' hp.ne apply norm_le_of_forall_sum_le hp' hC exact sum_rpow_le_of_tendsto hp.ne hCF hf /-- If `f` is the pointwise limit of a bounded sequence in `lp E p`, then `f` is in `lp E p`. -/ theorem memℓp_of_tendsto {F : ι → lp E p} (hF : Bornology.IsBounded (Set.range F)) {f : ∀ a, E a} (hf : Tendsto (id fun i => F i : ι → ∀ a, E a) l (𝓝 f)) : Memℓp f p := by obtain ⟨C, hCF⟩ : ∃ C, ∀ k, ‖F k‖ ≤ C := hF.exists_norm_le.imp fun _ ↦ Set.forall_mem_range.1 rcases eq_top_or_lt_top p with (rfl | hp) · apply memℓp_infty use C rintro _ ⟨a, rfl⟩ exact norm_apply_le_of_tendsto (Eventually.of_forall hCF) hf a · apply memℓp_gen' exact sum_rpow_le_of_tendsto hp.ne (Eventually.of_forall hCF) hf /-- If a sequence is Cauchy in the `lp E p` topology and pointwise convergent to an element `f` of `lp E p`, then it converges to `f` in the `lp E p` topology. -/ theorem tendsto_lp_of_tendsto_pi {F : ℕ → lp E p} (hF : CauchySeq F) {f : lp E p} (hf : Tendsto (id fun i => F i : ℕ → ∀ a, E a) atTop (𝓝 f)) : Tendsto F atTop (𝓝 f) := by rw [Metric.nhds_basis_closedBall.tendsto_right_iff] intro ε hε have hε' : { p : lp E p × lp E p | ‖p.1 - p.2‖ < ε } ∈ uniformity (lp E p) := NormedAddCommGroup.uniformity_basis_dist.mem_of_mem hε refine (hF.eventually_eventually hε').mono ?_ rintro n (hn : ∀ᶠ l in atTop, ‖(fun f => F n - f) (F l)‖ < ε) refine norm_le_of_tendsto (hn.mono fun k hk => hk.le) ?_ rw [tendsto_pi_nhds] intro a exact (hf.apply_nhds a).const_sub (F n a) variable [∀ a, CompleteSpace (E a)] instance completeSpace : CompleteSpace (lp E p) := Metric.complete_of_cauchySeq_tendsto (by intro F hF -- A Cauchy sequence in `lp E p` is pointwise convergent; let `f` be the pointwise limit. obtain ⟨f, hf⟩ := cauchySeq_tendsto_of_complete ((uniformContinuous_coe (p := p)).comp_cauchySeq hF) -- Since the Cauchy sequence is bounded, its pointwise limit `f` is in `lp E p`. have hf' : Memℓp f p := memℓp_of_tendsto hF.isBounded_range hf -- And therefore `f` is its limit in the `lp E p` topology as well as pointwise. exact ⟨⟨f, hf'⟩, tendsto_lp_of_tendsto_pi hF hf⟩) end Topology end lp section Lipschitz open ENNReal lp variable {ι : Type*} lemma LipschitzWith.uniformly_bounded [PseudoMetricSpace α] (g : α → ι → ℝ) {K : ℝ≥0} (hg : ∀ i, LipschitzWith K (g · i)) (a₀ : α) (hga₀b : Memℓp (g a₀) ∞) (a : α) : Memℓp (g a) ∞ := by rcases hga₀b with ⟨M, hM⟩ use ↑K * dist a a₀ + M rintro - ⟨i, rfl⟩ calc |g a i| = |g a i - g a₀ i + g a₀ i| := by simp _ ≤ |g a i - g a₀ i| + |g a₀ i| := abs_add _ _ _ ≤ ↑K * dist a a₀ + M := by gcongr · exact lipschitzWith_iff_dist_le_mul.1 (hg i) a a₀ · exact hM ⟨i, rfl⟩ theorem LipschitzOnWith.coordinate [PseudoMetricSpace α] (f : α → ℓ^∞(ι)) (s : Set α) (K : ℝ≥0) : LipschitzOnWith K f s ↔ ∀ i : ι, LipschitzOnWith K (fun a : α ↦ f a i) s := by simp_rw [lipschitzOnWith_iff_dist_le_mul] constructor · intro hfl i x hx y hy calc dist (f x i) (f y i) ≤ dist (f x) (f y) := lp.norm_apply_le_norm top_ne_zero (f x - f y) i _ ≤ K * dist x y := hfl x hx y hy · intro hgl x hx y hy apply lp.norm_le_of_forall_le · positivity intro i apply hgl i x hx y hy theorem LipschitzWith.coordinate [PseudoMetricSpace α] {f : α → ℓ^∞(ι)} (K : ℝ≥0) : LipschitzWith K f ↔ ∀ i : ι, LipschitzWith K (fun a : α ↦ f a i) := by simp_rw [← lipschitzOnWith_univ] apply LipschitzOnWith.coordinate end Lipschitz
test_ssrAC.v
From mathcomp Require Import all_boot ssralg. Section Tests. Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d). Proof. time by rewrite orbACA. Abort. Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d). Proof. time by rewrite (AC (2*2) ((1*3)*(2*4))). Abort. Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d). Proof. time by rewrite orb.[AC (2*2) ((1*3)*(2*4))]. Qed. Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d. Proof. time by rewrite -addnA addnAC addnA addnAC. Abort. Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d. Proof. time by rewrite (ACl (1*3*2*4)). Abort. Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d. Proof. time by rewrite addn.[ACl 1*3*2*4]. Qed. Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R. Proof. time by rewrite -GRing.addrA GRing.addrAC GRing.addrA GRing.addrAC. Abort. Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R. Proof. time by rewrite (ACl (1*3*2*4)). Abort. Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R. Proof. time by rewrite (@GRing.add R).[ACl 1*3*2*4]. Qed. Local Open Scope ring_scope. Import GRing.Theory. Lemma test_mulr (R : comRingType) (x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 : R) (x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 : R) : (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) = (x0 * x2 * x4 * x9) * (x1 * x3 * x5 * x7) * x6 * x8 * (x10 * x12 * x14 * x19) * (x11 * x13 * x15 * x17) * x16 * x18 * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9)* (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) . Proof. pose s := ((2 * 4 * 9 * 1 * 3 * 5 * 7 * 6 * 8 * 20 * 21 * 22 * 23) * 25 * 26 * 27 * 28 * (29 * 30 * 31) * 32 * 33 * 34 * 35 * 36 * 37 * 38 * 39 * 40 * 41 * (10 * 12 * 14 * 19 * 11 * 13 * 15 * 17 * 16 * 18 * 24) * (42 * 43 * 44 * 45 * 46 * 47 * 48 * 49) * 50 * 52 * 53 * 54 * 55 * 56 * 57 * 58 * 59 * 51* 60 * 62 * 63 * 64 * 65 * 66 * 67 * 68 * 69 * 61* 70 * 72 * 73 * 74 * 75 * 76 * 77 * 78 * 79 * 71 * 80 * 82 * 83 * 84 * 85 * 86 * 87 * 88 * 89 * 81* 90 * 92 * 93 * 94 * 95 * 96 * 97 * 98 * 99 * 91 * 100 * ((102 * 104 * 109 * 101 * 103 * 105 * 107 * 106 * 108 * 120 * 121 * 122 * 123) * 125 * 126 * 127 * 128 * (129 * 130 * 131) * 132 * 133 * 134 * 135 * 136 * 137 * 138 * 139 * 140 * 141 * (110 * 112 * 114 * 119 * 111 * 113 * 115 * 117 * 116 * 118 * 124) * (142 * 143 * 144 * 145 * 146 * 147 * 148 * 149) * 150 * 152 * 153 * 154 * 155 * 156 * 157 * 158 * 159 * 151* 160 * 162 * 163 * 164 * 165 * 166 * 167 * 168 * 169 * 161* 170 * 172 * 173 * 174 * 175 * 176 * 177 * 178 * 179 * 171 * 180 * 182 * 183 * 184 * 185 * 186 * 187 * 188 * 189 * 181* 190 * 192 * 193 * 194 * 195 * 196 * 197 * 198 * 199 * 191) )%AC. time have := (@GRing.mul R).[ACl s]. time rewrite (@GRing.mul R).[ACl s]. Abort. End Tests.
vector.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice. From mathcomp Require Import fintype bigop finfun tuple. From mathcomp Require Import ssralg matrix mxalgebra zmodp. (******************************************************************************) (* Finite dimensional vector spaces *) (* *) (* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *) (* *) (* vectType R == interface structure for finite dimensional (more *) (* precisely, detachable) vector spaces over R, which *) (* should be at least a nzRingType *) (* The HB class is called Vector. *) (* Vector.axiom n M <-> type M is linearly isomorphic to 'rV_n *) (* := {v2r : M -> 'rV_n| linear v2r & bijective v2r} *) (* {vspace vT} == the type of (detachable) subspaces of vT; vT *) (* should have a vectType structure over a fieldType *) (* subvs_of U == the subtype of elements of V in the subspace U *) (* This is canonically a vectType. *) (* vsval u == linear injection of u : subvs_of U into V *) (* vsproj U v == linear projection of v : V in subvs U *) (* rVof e v == row vector in 'rV_(\dim vT) of coordinates of *) (* v : vT in the basis e *) (* vecof e v == vector in vT whose coordinates in the basis e are *) (* given by v : 'rV_(\dim vT) *) (* Note that this is the inverse of rVof. *) (* mxof e e' f == \dim uT * \dim vT matrix of the linear function *) (* f : 'Hom(uT, vT) in the bases e of uT and e' of vT,*) (* acting on row vectors *) (* hommx e f M == linear function in 'Hom(uT, vT) whose matrix *) (* in the bases e and f is M : 'M_(\dim uT, \dim vT) *) (* Note that this is the inverse of mxof. *) (* vsof e M == the subspace of vT generated by the rows of M, *) (* seen as coordinates in the basis e *) (* msof e U == matrix whose rows, seen as coordinates in the *) (* basis e, generate the subspace U of vT *) (* Note that this is the inverse of vsof. *) (* 'Hom(aT, rT) == the type of linear functions (homomorphisms) from *) (* aT to rT, where aT and rT are vectType structures *) (* Elements of 'Hom(aT, rT) coerce to Coq functions. *) (* linfun f == a vector linear function in 'Hom(aT, rT) that *) (* coincides with f : aT -> rT when f is linear *) (* 'End(vT) == endomorphisms of vT (:= 'Hom(vT, vT)) *) (* --> The types subvs_of U, 'Hom(aT, rT), 'End(vT), K^o, 'M[K]_(m, n), *) (* vT * wT, {ffun I -> vT}, vT ^ n all have canonical vectType instances. *) (* *) (* Functions: *) (* <[v]>%VS == the vector space generated by v (a line if v != 0) *) (* 0%VS == the trivial vector subspace *) (* fullv, {:vT} == the complete vector subspace (displays as fullv) *) (* (U + V)%VS == the join (sum) of two subspaces U and V *) (* (U :&: V)%VS == intersection of vector subspaces U and V *) (* (U^C)%VS == a complement of the vector subspace U *) (* (U :\: V)%VS == a local complement to U :& V in the subspace U *) (* \dim U == dimension of a vector space U *) (* span X, <<X>>%VS == the subspace spanned by the vector sequence X *) (* coord X i v == i'th coordinate of v on X, when v \in <<X>>%VS and *) (* where X : n.-tuple vT and i : 'I_n *) (* Note that coord X i is a scalar function. *) (* vpick U == a nonzero element of U if U= 0%VS, or 0 if U = 0 *) (* vbasis U == a (\dim U).-tuple that is a basis of U *) (* \1%VF == the identity linear function *) (* (f \o g)%VF == the composite of two linear functions f and g *) (* (f^-1)%VF == a linear function that is a right inverse to the *) (* linear function f on the codomain of f *) (* (f @: U)%VS == the image of U by the linear function f *) (* (f @^-1: U)%VS == the pre-image of U by the linear function f *) (* lker f == the kernel of the linear function f *) (* limg f == the image of the linear function f *) (* fixedSpace f == the fixed space of a linear endomorphism f *) (* daddv_pi U V == projection onto U along V if U and V are disjoint; *) (* daddv_pi U V + daddv_pi V U is then a projection *) (* onto the direct sum (U + V)%VS *) (* projv U == projection onto U (along U^C, := daddv_pi U U^C) *) (* addv_pi1 U V == projection onto the subspace U :\: V of U along V *) (* addv_pi2 U V == projection onto V along U :\: V; note that *) (* addv_pi1 U V and addv_pi2 U V are (asymmetrical) *) (* complementary projections on (U + V)%VS *) (* sumv_pi_for defV i == for defV : V = (V \sum_(j <- r | P j) Vs j)%VS, *) (* j ranging over an eqType, this is a projection on *) (* a subspace of Vs i, along a complement in V, such *) (* that \sum_(j <- r | P j) sumv_pi_for defV j is a *) (* projection onto V if filter P r is duplicate-free *) (* (e.g., when V := \sum_(j | P j) Vs j) *) (* sumv_pi V i == notation the above when defV == erefl V, and V is *) (* convertible to \sum_(j <- r | P j) Vs j)%VS *) (* leigenspace f a == linear eigenspace of the linear function f for *) (* the (potential) eigenvalue a *) (* *) (* Predicates: *) (* v \in U == v belongs to U (:= (<[v]> <= U)%VS) *) (* (U <= V)%VS == U is a subspace of V *) (* free B == B is a sequence of nonzero linearly independent *) (* vectors *) (* basis_of U b == b is a basis of the subspace U *) (* directv S == S is the expression for a direct sum of subspaces *) (* leigenvalue f a == a is a linear eigenvalue of the linear function f *) (******************************************************************************) Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Declare Scope vspace_scope. Declare Scope lfun_scope. Local Open Scope ring_scope. Reserved Notation "{ 'vspace' T }" (format "{ 'vspace' T }"). Reserved Notation "''Hom' ( T , rT )" (format "''Hom' ( T , rT )"). Reserved Notation "''End' ( T )" (format "''End' ( T )"). Reserved Notation "\dim A" (at level 10, A at level 8, format "\dim A"). Delimit Scope vspace_scope with VS. Import GRing.Theory. (* Finite dimension vector space *) Definition vector_axiom_def (R : nzRingType) n (V : lmodType R) := {v2r : V -> 'rV[R]_n | linear v2r & bijective v2r}. Arguments vector_axiom_def [R] n%_N V%_type. HB.mixin Record Lmodule_hasFinDim (R : nzRingType) (V : Type) of GRing.Lmodule R V := { dim : nat; vector_subdef : vector_axiom_def dim V }. #[mathcomp(axiom="vector_axiom_def"), short(type="vectType")] HB.structure Definition Vector (R : nzRingType) := { V of Lmodule_hasFinDim R V & GRing.Lmodule R V }. #[deprecated(since="mathcomp 2.2.0", note="Use Vector.axiom instead.")] Notation vector_axiom := Vector.axiom. Arguments dim {R} s. (* FIXME: S/space and H/hom were defined behind the module Vector * * Perhaps we should change their names to avoid conflicts. *) Section OtherDefs. Local Coercion dim : Vector.type >-> nat. Inductive space (K : fieldType) (vT : Vector.type K) := Space (mx : 'M[K]_vT) & <<mx>>%MS == mx. Inductive hom (R : nzRingType) (vT wT : Vector.type R) := Hom of 'M[R]_(vT, wT). End OtherDefs. (* /FIXME *) Module Import VectorExports. Bind Scope ring_scope with Vector.sort. Arguments space [K] vT%_type. Notation "{ 'vspace' vT }" := (space vT) : type_scope. Notation "''Hom' ( aT , rT )" := (hom aT rT) : type_scope. Notation "''End' ( vT )" := (hom vT vT) : type_scope. Prenex Implicits Hom. Delimit Scope vspace_scope with VS. Bind Scope vspace_scope with space. Delimit Scope lfun_scope with VF. Bind Scope lfun_scope with hom. End VectorExports. (* The contents of this module exposes the matrix encodings, and should *) (* therefore not be used outside of the vector library implementation. *) Module VectorInternalTheory. Section Iso. Variables (R : nzRingType) (vT rT : vectType R). Local Coercion dim : Vector.type >-> nat. Fact v2r_subproof : Vector.axiom vT vT. Proof. exact: vector_subdef. Qed. Definition v2r := s2val v2r_subproof. Let v2r_bij : bijective v2r := s2valP' v2r_subproof. Fact r2v_subproof : {r2v | cancel r2v v2r}. Proof. have r2vP r: {v | v2r v = r}. by apply: sig_eqW; have [v _ vK] := v2r_bij; exists (v r). by exists (fun r => sval (r2vP r)) => r; case: (r2vP r). Qed. Definition r2v := sval r2v_subproof. Lemma r2vK : cancel r2v v2r. Proof. exact: svalP r2v_subproof. Qed. Lemma r2v_inj : injective r2v. Proof. exact: can_inj r2vK. Qed. Lemma v2rK : cancel v2r r2v. Proof. by have/bij_can_sym:= r2vK; apply. Qed. Lemma v2r_inj : injective v2r. Proof. exact: can_inj v2rK. Qed. HB.instance Definition _ := GRing.isSemilinear.Build R vT 'rV_vT _ v2r (GRing.semilinear_linear (s2valP v2r_subproof)). HB.instance Definition _ := GRing.isSemilinear.Build R 'rV_vT vT _ r2v (GRing.semilinear_linear (can2_linear v2rK r2vK)). End Iso. Section Vspace. Variables (K : fieldType) (vT : vectType K). Local Coercion dim : Vector.type >-> nat. Definition b2mx n (X : n.-tuple vT) := \matrix_i v2r (tnth X i). Lemma b2mxK n (X : n.-tuple vT) i : r2v (row i (b2mx X)) = X`_i. Proof. by rewrite rowK v2rK -tnth_nth. Qed. Definition vs2mx (U : @space K vT) := let: Space mx _ := U in mx. Lemma gen_vs2mx (U : {vspace vT}) : <<vs2mx U>>%MS = vs2mx U. Proof. by apply/eqP; rewrite /vs2mx; case: U. Qed. Fact mx2vs_subproof m (A : 'M[K]_(m, vT)) : <<(<<A>>)>>%MS == <<A>>%MS. Proof. by rewrite genmx_id. Qed. Definition mx2vs {m} A : {vspace vT} := Space (@mx2vs_subproof m A). HB.instance Definition _ := [isSub of {vspace vT} for vs2mx]. Lemma vs2mxK : cancel vs2mx mx2vs. Proof. by move=> v; apply: val_inj; rewrite /= gen_vs2mx. Qed. Lemma mx2vsK m (M : 'M_(m, vT)) : (vs2mx (mx2vs M) :=: M)%MS. Proof. exact: genmxE. Qed. End Vspace. Section Hom. Variables (R : nzRingType) (aT rT : vectType R). Definition f2mx (f : 'Hom(aT, rT)) := let: Hom A := f in A. HB.instance Definition _ : isSub _ _ 'Hom(aT, rT) := [isNew for f2mx]. End Hom. Arguments mx2vs {K vT m%_N} A%_MS. Prenex Implicits v2r r2v v2rK r2vK b2mx vs2mx vs2mxK f2mx. End VectorInternalTheory. Export VectorExports. Import VectorInternalTheory. Section VspaceDefs. Variables (K : fieldType) (vT : vectType K). Implicit Types (u : vT) (X : seq vT) (U V : {vspace vT}). HB.instance Definition _ := [Choice of {vspace vT} by <:]. Definition dimv U := \rank (vs2mx U). Definition subsetv U V := (vs2mx U <= vs2mx V)%MS. Definition vline u := mx2vs (v2r u). (* Vspace membership is defined as line inclusion. *) Definition pred_of_vspace (U : space vT) : {pred vT} := fun v => (vs2mx (vline v) <= vs2mx U)%MS. Canonical vspace_predType := @PredType _ (unkeyed {vspace vT}) pred_of_vspace. Definition fullv : {vspace vT} := mx2vs 1%:M. Definition addv U V := mx2vs (vs2mx U + vs2mx V). Definition capv U V := mx2vs (vs2mx U :&: vs2mx V). Definition complv U := mx2vs (vs2mx U)^C. Definition diffv U V := mx2vs (vs2mx U :\: vs2mx V). Definition vpick U := r2v (nz_row (vs2mx U)). Fact span_key : unit. Proof. by []. Qed. Definition span_expanded_def X := mx2vs (b2mx (in_tuple X)). Definition span := locked_with span_key span_expanded_def. Canonical span_unlockable := [unlockable fun span]. Definition vbasis_def U := [tuple r2v (row i (row_base (vs2mx U))) | i < dimv U]. Definition vbasis := locked_with span_key vbasis_def. Canonical vbasis_unlockable := [unlockable fun vbasis]. (* coord and directv are defined in the VectorTheory section. *) Definition free X := dimv (span X) == size X. Definition basis_of U X := (span X == U) && free X. End VspaceDefs. Coercion pred_of_vspace : space >-> pred_sort. Notation "\dim U" := (dimv U) : nat_scope. Notation "U <= V" := (subsetv U V) : vspace_scope. Notation "U <= V <= W" := (subsetv U V && subsetv V W) : vspace_scope. Notation "<[ v ] >" := (vline v) : vspace_scope. Notation "<< X >>" := (span X) : vspace_scope. Notation "0" := (vline 0) : vspace_scope. Arguments fullv {K vT}. Prenex Implicits subsetv addv capv complv diffv span free basis_of. Notation "U + V" := (addv U V) : vspace_scope. Notation "U :&: V" := (capv U V) : vspace_scope. Notation "U ^C" := (complv U) : vspace_scope. Notation "U :\: V" := (diffv U V) : vspace_scope. Notation "{ : vT }" := (@fullv _ vT) (only parsing) : vspace_scope. Notation "\sum_ ( i <- r | P ) U" := (\big[addv/0%VS]_(i <- r | P%B) U%VS) : vspace_scope. Notation "\sum_ ( i <- r ) U" := (\big[addv/0%VS]_(i <- r) U%VS) : vspace_scope. Notation "\sum_ ( m <= i < n | P ) U" := (\big[addv/0%VS]_(m <= i < n | P%B) U%VS) : vspace_scope. Notation "\sum_ ( m <= i < n ) U" := (\big[addv/0%VS]_(m <= i < n) U%VS) : vspace_scope. Notation "\sum_ ( i | P ) U" := (\big[addv/0%VS]_(i | P%B) U%VS) : vspace_scope. Notation "\sum_ i U" := (\big[addv/0%VS]_i U%VS) : vspace_scope. Notation "\sum_ ( i : t | P ) U" := (\big[addv/0%VS]_(i : t | P%B) U%VS) (only parsing) : vspace_scope. Notation "\sum_ ( i : t ) U" := (\big[addv/0%VS]_(i : t) U%VS) (only parsing) : vspace_scope. Notation "\sum_ ( i < n | P ) U" := (\big[addv/0%VS]_(i < n | P%B) U%VS) : vspace_scope. Notation "\sum_ ( i < n ) U" := (\big[addv/0%VS]_(i < n) U%VS) : vspace_scope. Notation "\sum_ ( i 'in' A | P ) U" := (\big[addv/0%VS]_(i in A | P%B) U%VS) : vspace_scope. Notation "\sum_ ( i 'in' A ) U" := (\big[addv/0%VS]_(i in A) U%VS) : vspace_scope. Notation "\bigcap_ ( i <- r | P ) U" := (\big[capv/fullv]_(i <- r | P%B) U%VS) : vspace_scope. Notation "\bigcap_ ( i <- r ) U" := (\big[capv/fullv]_(i <- r) U%VS) : vspace_scope. Notation "\bigcap_ ( m <= i < n | P ) U" := (\big[capv/fullv]_(m <= i < n | P%B) U%VS) : vspace_scope. Notation "\bigcap_ ( m <= i < n ) U" := (\big[capv/fullv]_(m <= i < n) U%VS) : vspace_scope. Notation "\bigcap_ ( i | P ) U" := (\big[capv/fullv]_(i | P%B) U%VS) : vspace_scope. Notation "\bigcap_ i U" := (\big[capv/fullv]_i U%VS) : vspace_scope. Notation "\bigcap_ ( i : t | P ) U" := (\big[capv/fullv]_(i : t | P%B) U%VS) (only parsing) : vspace_scope. Notation "\bigcap_ ( i : t ) U" := (\big[capv/fullv]_(i : t) U%VS) (only parsing) : vspace_scope. Notation "\bigcap_ ( i < n | P ) U" := (\big[capv/fullv]_(i < n | P%B) U%VS) : vspace_scope. Notation "\bigcap_ ( i < n ) U" := (\big[capv/fullv]_(i < n) U%VS) : vspace_scope. Notation "\bigcap_ ( i 'in' A | P ) U" := (\big[capv/fullv]_(i in A | P%B) U%VS) : vspace_scope. Notation "\bigcap_ ( i 'in' A ) U" := (\big[capv/fullv]_(i in A) U%VS) : vspace_scope. Section VectorTheory. Variables (K : fieldType) (vT : vectType K). Implicit Types (a : K) (u v w : vT) (X Y : seq vT) (U V W : {vspace vT}). Local Notation subV := (@subsetv K vT) (only parsing). Local Notation addV := (@addv K vT) (only parsing). Local Notation capV := (@capv K vT) (only parsing). (* begin hide *) (* Internal theory facts *) Let vs2mxP U V : reflect (U = V) (vs2mx U == vs2mx V)%MS. Proof. by rewrite (sameP genmxP eqP) !gen_vs2mx; apply: eqP. Qed. Let memvK v U : (v \in U) = (v2r v <= vs2mx U)%MS. Proof. by rewrite -genmxE. Qed. Let mem_r2v rv U : (r2v rv \in U) = (rv <= vs2mx U)%MS. Proof. by rewrite memvK r2vK. Qed. Let vs2mx0 : @vs2mx K vT 0 = 0. Proof. by rewrite /= linear0 genmx0. Qed. Let vs2mxD U V : vs2mx (U + V) = (vs2mx U + vs2mx V)%MS. Proof. by rewrite /= genmx_adds !gen_vs2mx. Qed. Let vs2mx_sum := big_morph _ vs2mxD vs2mx0. Let vs2mxI U V : vs2mx (U :&: V) = (vs2mx U :&: vs2mx V)%MS. Proof. by rewrite /= genmx_cap !gen_vs2mx. Qed. Let vs2mxF : vs2mx {:vT} = 1%:M. Proof. by rewrite /= genmx1. Qed. Let row_b2mx n (X : n.-tuple vT) i : row i (b2mx X) = v2r X`_i. Proof. by rewrite -tnth_nth rowK. Qed. Let span_b2mx n (X : n.-tuple vT) : span X = mx2vs (b2mx X). Proof. by rewrite unlock tvalK; case: _ / (esym _). Qed. Let mul_b2mx n (X : n.-tuple vT) (rk : 'rV_n) : \sum_i rk 0 i *: X`_i = r2v (rk *m b2mx X). Proof. rewrite mulmx_sum_row linear_sum; apply: eq_bigr => i _. by rewrite row_b2mx linearZ /= v2rK. Qed. Let lin_b2mx n (X : n.-tuple vT) k : \sum_(i < n) k i *: X`_i = r2v (\row_i k i *m b2mx X). Proof. by rewrite -mul_b2mx; apply: eq_bigr => i _; rewrite mxE. Qed. Let free_b2mx n (X : n.-tuple vT) : free X = row_free (b2mx X). Proof. by rewrite /free /dimv span_b2mx genmxE size_tuple. Qed. (* end hide *) Lemma memvE v U : (v \in U) = (<[v]> <= U)%VS. Proof. by []. Qed. Lemma vlineP v1 v2 : reflect (exists k, v1 = k *: v2) (v1 \in <[v2]>)%VS. Proof. apply: (iffP idP) => [|[k ->]]; rewrite memvK genmxE ?linearZ ?scalemx_sub //. by case/sub_rVP=> k; rewrite -linearZ => /v2r_inj->; exists k. Qed. Fact memv_submod_closed U : submod_closed U. Proof. split=> [|a u v]; rewrite !memvK 1?linear0 1?sub0mx // => Uu Uv. by rewrite linearP addmx_sub ?scalemx_sub. Qed. HB.instance Definition _ (U : {vspace vT}) := GRing.isSubmodClosed.Build K vT (pred_of_vspace U) (memv_submod_closed U). Lemma mem0v U : 0 \in U. Proof. exact: rpred0. Qed. Lemma memvN U v : (- v \in U) = (v \in U). Proof. exact: rpredN. Qed. Lemma memvD U : {in U &, forall u v, u + v \in U}. Proof. exact: rpredD. Qed. Lemma memvB U : {in U &, forall u v, u - v \in U}. Proof. exact: rpredB. Qed. Lemma memvZ U k : {in U, forall v, k *: v \in U}. Proof. exact: rpredZ. Qed. Lemma memv_suml I r (P : pred I) vs U : (forall i, P i -> vs i \in U) -> \sum_(i <- r | P i) vs i \in U. Proof. exact: rpred_sum. Qed. Lemma memv_line u : u \in <[u]>%VS. Proof. by apply/vlineP; exists 1; rewrite scale1r. Qed. Lemma subvP U V : reflect {subset U <= V} (U <= V)%VS. Proof. apply: (iffP rV_subP) => sU12 u. by rewrite !memvE /subsetv !genmxE => /sU12. by have:= sU12 (r2v u); rewrite !memvE /subsetv !genmxE r2vK. Qed. Lemma subvv U : (U <= U)%VS. Proof. exact/subvP. Qed. Hint Resolve subvv : core. Lemma subv_trans : transitive subV. Proof. by move=> U V W /subvP sUV /subvP sVW; apply/subvP=> u /sUV/sVW. Qed. Lemma subv_anti : antisymmetric subV. Proof. by move=> U V; apply/vs2mxP. Qed. Lemma eqEsubv U V : (U == V) = (U <= V <= U)%VS. Proof. by apply/eqP/idP=> [-> | /subv_anti//]; rewrite subvv. Qed. Lemma vspaceP U V : U =i V <-> U = V. Proof. split=> [eqUV | -> //]; apply/subv_anti/andP. by split; apply/subvP=> v; rewrite eqUV. Qed. Lemma subvPn {U V} : reflect (exists2 u, u \in U & u \notin V) (~~ (U <= V)%VS). Proof. apply: (iffP idP) => [|[u Uu]]; last by apply: contra => /subvP->. case/row_subPn=> i; set vi := row i _ => V'vi. by exists (r2v vi); rewrite memvK r2vK ?row_sub. Qed. (* Empty space. *) Lemma sub0v U : (0 <= U)%VS. Proof. exact: mem0v. Qed. Lemma subv0 U : (U <= 0)%VS = (U == 0%VS). Proof. by rewrite eqEsubv sub0v andbT. Qed. Lemma memv0 v : v \in 0%VS = (v == 0). Proof. by apply/idP/eqP=> [/vlineP[k ->] | ->]; rewrite (scaler0, mem0v). Qed. (* Full space *) Lemma subvf U : (U <= fullv)%VS. Proof. by rewrite /subsetv vs2mxF submx1. Qed. Lemma memvf v : v \in fullv. Proof. exact: subvf. Qed. (* Picking a non-zero vector in a subspace. *) Lemma memv_pick U : vpick U \in U. Proof. by rewrite mem_r2v nz_row_sub. Qed. Lemma vpick0 U : (vpick U == 0) = (U == 0%VS). Proof. by rewrite -memv0 mem_r2v -subv0 /subV vs2mx0 !submx0 nz_row_eq0. Qed. (* Sum of subspaces. *) Lemma subv_add U V W : (U + V <= W)%VS = (U <= W)%VS && (V <= W)%VS. Proof. by rewrite /subV vs2mxD addsmx_sub. Qed. Lemma addvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 + V1 <= U2 + V2)%VS. Proof. by rewrite /subV !vs2mxD; apply: addsmxS. Qed. Lemma addvSl U V : (U <= U + V)%VS. Proof. by rewrite /subV vs2mxD addsmxSl. Qed. Lemma addvSr U V : (V <= U + V)%VS. Proof. by rewrite /subV vs2mxD addsmxSr. Qed. Lemma addvC : commutative addV. Proof. by move=> U V; apply/vs2mxP; rewrite !vs2mxD addsmxC submx_refl. Qed. Lemma addvA : associative addV. Proof. by move=> U V W; apply/vs2mxP; rewrite !vs2mxD addsmxA submx_refl. Qed. Lemma addv_idPl {U V}: reflect (U + V = U)%VS (V <= U)%VS. Proof. by rewrite /subV (sameP addsmx_idPl eqmxP) -vs2mxD; apply: vs2mxP. Qed. Lemma addv_idPr {U V} : reflect (U + V = V)%VS (U <= V)%VS. Proof. by rewrite addvC; apply: addv_idPl. Qed. Lemma addvv : idempotent_op addV. Proof. by move=> U; apply/addv_idPl. Qed. Lemma add0v : left_id 0%VS addV. Proof. by move=> U; apply/addv_idPr/sub0v. Qed. Lemma addv0 : right_id 0%VS addV. Proof. by move=> U; apply/addv_idPl/sub0v. Qed. Lemma sumfv : left_zero fullv addV. Proof. by move=> U; apply/addv_idPl/subvf. Qed. Lemma addvf : right_zero fullv addV. Proof. by move=> U; apply/addv_idPr/subvf. Qed. HB.instance Definition _ := Monoid.isComLaw.Build {vspace vT} 0%VS addv addvA addvC add0v. Lemma memv_add u v U V : u \in U -> v \in V -> u + v \in (U + V)%VS. Proof. by rewrite !memvK genmxE linearD; apply: addmx_sub_adds. Qed. Lemma memv_addP {w U V} : reflect (exists2 u, u \in U & exists2 v, v \in V & w = u + v) (w \in U + V)%VS. Proof. apply: (iffP idP) => [|[u Uu [v Vv ->]]]; last exact: memv_add. rewrite memvK genmxE => /sub_addsmxP[r /(canRL v2rK)->]. rewrite linearD /=; set u := r2v _; set v := r2v _. by exists u; last exists v; rewrite // mem_r2v submxMl. Qed. Section BigSum. Variable I : finType. Implicit Type P : pred I. Lemma sumv_sup i0 P U Vs : P i0 -> (U <= Vs i0)%VS -> (U <= \sum_(i | P i) Vs i)%VS. Proof. by move=> Pi0 /subv_trans-> //; rewrite (bigD1 i0) ?addvSl. Qed. Arguments sumv_sup i0 [P U Vs]. Lemma subv_sumP {P Us V} : reflect (forall i, P i -> Us i <= V)%VS (\sum_(i | P i) Us i <= V)%VS. Proof. apply: (iffP idP) => [sUV i Pi | sUV]. by apply: subv_trans sUV; apply: sumv_sup Pi _. by elim/big_rec: _ => [|i W Pi sWV]; rewrite ?sub0v // subv_add sUV. Qed. Lemma memv_sumr P vs (Us : I -> {vspace vT}) : (forall i, P i -> vs i \in Us i) -> \sum_(i | P i) vs i \in (\sum_(i | P i) Us i)%VS. Proof. by move=> Uv; apply/rpred_sum=> i Pi; apply/(sumv_sup i Pi)/Uv. Qed. Lemma memv_sumP {P} {Us : I -> {vspace vT}} {v} : reflect (exists2 vs, forall i, P i -> vs i \in Us i & v = \sum_(i | P i) vs i) (v \in \sum_(i | P i) Us i)%VS. Proof. apply: (iffP idP) => [|[vs Uv ->]]; last exact: memv_sumr. rewrite memvK vs2mx_sum => /sub_sumsmxP[r /(canRL v2rK)->]. pose f i := r2v (r i *m vs2mx (Us i)); rewrite linear_sum /=. by exists f => //= i _; rewrite mem_r2v submxMl. Qed. End BigSum. (* Intersection *) Lemma subv_cap U V W : (U <= V :&: W)%VS = (U <= V)%VS && (U <= W)%VS. Proof. by rewrite /subV vs2mxI sub_capmx. Qed. Lemma capvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 :&: V1 <= U2 :&: V2)%VS. Proof. by rewrite /subV !vs2mxI; apply: capmxS. Qed. Lemma capvSl U V : (U :&: V <= U)%VS. Proof. by rewrite /subV vs2mxI capmxSl. Qed. Lemma capvSr U V : (U :&: V <= V)%VS. Proof. by rewrite /subV vs2mxI capmxSr. Qed. Lemma capvC : commutative capV. Proof. by move=> U V; apply/vs2mxP; rewrite !vs2mxI capmxC submx_refl. Qed. Lemma capvA : associative capV. Proof. by move=> U V W; apply/vs2mxP; rewrite !vs2mxI capmxA submx_refl. Qed. Lemma capv_idPl {U V} : reflect (U :&: V = U)%VS (U <= V)%VS. Proof. by rewrite /subV(sameP capmx_idPl eqmxP) -vs2mxI; apply: vs2mxP. Qed. Lemma capv_idPr {U V} : reflect (U :&: V = V)%VS (V <= U)%VS. Proof. by rewrite capvC; apply: capv_idPl. Qed. Lemma capvv : idempotent_op capV. Proof. by move=> U; apply/capv_idPl. Qed. Lemma cap0v : left_zero 0%VS capV. Proof. by move=> U; apply/capv_idPl/sub0v. Qed. Lemma capv0 : right_zero 0%VS capV. Proof. by move=> U; apply/capv_idPr/sub0v. Qed. Lemma capfv : left_id fullv capV. Proof. by move=> U; apply/capv_idPr/subvf. Qed. Lemma capvf : right_id fullv capV. Proof. by move=> U; apply/capv_idPl/subvf. Qed. HB.instance Definition _ := Monoid.isComLaw.Build {vspace vT} fullv capv capvA capvC capfv. Lemma memv_cap w U V : (w \in U :&: V)%VS = (w \in U) && (w \in V). Proof. by rewrite !memvE subv_cap. Qed. Lemma memv_capP {w U V} : reflect (w \in U /\ w \in V) (w \in U :&: V)%VS. Proof. by rewrite memv_cap; apply: andP. Qed. Lemma vspace_modl U V W : (U <= W -> U + (V :&: W) = (U + V) :&: W)%VS. Proof. by move=> sUV; apply/vs2mxP; rewrite !(vs2mxD, vs2mxI); apply/eqmxP/matrix_modl. Qed. Lemma vspace_modr U V W : (W <= U -> (U :&: V) + W = U :&: (V + W))%VS. Proof. by rewrite -!(addvC W) !(capvC U); apply: vspace_modl. Qed. Section BigCap. Variable I : finType. Implicit Type P : pred I. Lemma bigcapv_inf i0 P Us V : P i0 -> (Us i0 <= V -> \bigcap_(i | P i) Us i <= V)%VS. Proof. by move=> Pi0; apply: subv_trans; rewrite (bigD1 i0) ?capvSl. Qed. Lemma subv_bigcapP {P U Vs} : reflect (forall i, P i -> U <= Vs i)%VS (U <= \bigcap_(i | P i) Vs i)%VS. Proof. apply: (iffP idP) => [sUV i Pi | sUV]. by rewrite (subv_trans sUV) ?(bigcapv_inf Pi). by elim/big_rec: _ => [|i W Pi]; rewrite ?subvf // subv_cap sUV. Qed. End BigCap. (* Complement *) Lemma addv_complf U : (U + U^C)%VS = fullv. Proof. apply/vs2mxP; rewrite vs2mxD -gen_vs2mx -genmx_adds !genmxE submx1 sub1mx. exact: addsmx_compl_full. Qed. Lemma capv_compl U : (U :&: U^C = 0)%VS. Proof. apply/val_inj; rewrite [val]/= vs2mx0 vs2mxI -gen_vs2mx -genmx_cap. by rewrite capmx_compl genmx0. Qed. (* Difference *) Lemma diffvSl U V : (U :\: V <= U)%VS. Proof. by rewrite /subV genmxE diffmxSl. Qed. Lemma capv_diff U V : ((U :\: V) :&: V = 0)%VS. Proof. apply/val_inj; rewrite [val]/= vs2mx0 vs2mxI -(gen_vs2mx V) -genmx_cap. by rewrite capmx_diff genmx0. Qed. Lemma addv_diff_cap U V : (U :\: V + U :&: V)%VS = U. Proof. apply/vs2mxP; rewrite vs2mxD -genmx_adds !genmxE. exact/eqmxP/addsmx_diff_cap_eq. Qed. Lemma addv_diff U V : (U :\: V + V = U + V)%VS. Proof. by rewrite -{2}(addv_diff_cap U V) -addvA (addv_idPr (capvSr U V)). Qed. (* Subspace dimension. *) Lemma dimv0 : \dim (0%VS : {vspace vT}) = 0. Proof. by rewrite /dimv vs2mx0 mxrank0. Qed. Lemma dimv_eq0 U : (\dim U == 0) = (U == 0%VS). Proof. by rewrite /dimv /= mxrank_eq0 [in RHS]/eq_op /= linear0 genmx0. Qed. Lemma dimvf : \dim {:vT} = dim vT. Proof. by rewrite /dimv vs2mxF mxrank1. Qed. Lemma dim_vline v : \dim <[v]> = (v != 0). Proof. by rewrite /dimv mxrank_gen rank_rV (can2_eq v2rK r2vK) linear0. Qed. Lemma dimvS U V : (U <= V)%VS -> \dim U <= \dim V. Proof. exact: mxrankS. Qed. Lemma dimv_leqif_sup U V : (U <= V)%VS -> \dim U <= \dim V ?= iff (V <= U)%VS. Proof. exact: mxrank_leqif_sup. Qed. Lemma dimv_leqif_eq U V : (U <= V)%VS -> \dim U <= \dim V ?= iff (U == V). Proof. by rewrite eqEsubv; apply: mxrank_leqif_eq. Qed. Lemma eqEdim U V : (U == V) = (U <= V)%VS && (\dim V <= \dim U). Proof. by apply/idP/andP=> [/eqP | [/dimv_leqif_eq/geq_leqif]] ->. Qed. Lemma dimv_compl U : \dim U^C = (\dim {:vT} - \dim U)%N. Proof. by rewrite dimvf /dimv mxrank_gen mxrank_compl. Qed. Lemma dimv_cap_compl U V : (\dim (U :&: V) + \dim (U :\: V))%N = \dim U. Proof. by rewrite /dimv !mxrank_gen mxrank_cap_compl. Qed. Lemma dimv_sum_cap U V : (\dim (U + V) + \dim (U :&: V) = \dim U + \dim V)%N. Proof. by rewrite /dimv !mxrank_gen mxrank_sum_cap. Qed. Lemma dimv_disjoint_sum U V : (U :&: V = 0)%VS -> \dim (U + V) = (\dim U + \dim V)%N. Proof. by move=> dxUV; rewrite -dimv_sum_cap dxUV dimv0 addn0. Qed. Lemma dimv_add_leqif U V : \dim (U + V) <= \dim U + \dim V ?= iff (U :&: V <= 0)%VS. Proof. by rewrite /dimv /subV !mxrank_gen vs2mx0 genmxE; apply: mxrank_adds_leqif. Qed. Lemma diffv_eq0 U V : (U :\: V == 0)%VS = (U <= V)%VS. Proof. rewrite -dimv_eq0 -(eqn_add2l (\dim (U :&: V))) addn0 dimv_cap_compl eq_sym. by rewrite (dimv_leqif_eq (capvSl _ _)) (sameP capv_idPl eqP). Qed. Lemma dimv_leq_sum I r (P : pred I) (Us : I -> {vspace vT}) : \dim (\sum_(i <- r | P i) Us i) <= \sum_(i <- r | P i) \dim (Us i). Proof. elim/big_rec2: _ => [|i d vs _ le_vs_d]; first by rewrite dim_vline eqxx. by apply: (leq_trans (dimv_add_leqif _ _)); rewrite leq_add2l. Qed. Section SumExpr. (* The vector direct sum theory clones the interface types of the matrix *) (* direct sum theory (see mxalgebra for the technical details), but *) (* nevetheless reuses much of the matrix theory. *) Structure addv_expr := Sumv { addv_val :> wrapped {vspace vT}; addv_dim : wrapped nat; _ : mxsum_spec (vs2mx (unwrap addv_val)) (unwrap addv_dim) }. (* Piggyback on mxalgebra theory. *) Definition vs2mx_sum_expr_subproof (S : addv_expr) : mxsum_spec (vs2mx (unwrap S)) (unwrap (addv_dim S)). Proof. by case: S. Qed. Canonical vs2mx_sum_expr S := ProperMxsumExpr (vs2mx_sum_expr_subproof S). Canonical trivial_addv U := @Sumv (Wrap U) (Wrap (\dim U)) (TrivialMxsum _). Structure proper_addv_expr := ProperSumvExpr { proper_addv_val :> {vspace vT}; proper_addv_dim :> nat; _ : mxsum_spec (vs2mx proper_addv_val) proper_addv_dim }. Definition proper_addvP (S : proper_addv_expr) := let: ProperSumvExpr _ _ termS := S return mxsum_spec (vs2mx S) S in termS. Canonical proper_addv (S : proper_addv_expr) := @Sumv (wrap (S : {vspace vT})) (wrap (S : nat)) (proper_addvP S). Section Binary. Variables S1 S2 : addv_expr. Fact binary_addv_subproof : mxsum_spec (vs2mx (unwrap S1 + unwrap S2)) (unwrap (addv_dim S1) + unwrap (addv_dim S2)). Proof. by rewrite vs2mxD; apply: proper_mxsumP. Qed. Canonical binary_addv_expr := ProperSumvExpr binary_addv_subproof. End Binary. Section Nary. Variables (I : Type) (r : seq I) (P : pred I) (S_ : I -> addv_expr). Fact nary_addv_subproof : mxsum_spec (vs2mx (\sum_(i <- r | P i) unwrap (S_ i))) (\sum_(i <- r | P i) unwrap (addv_dim (S_ i))). Proof. by rewrite vs2mx_sum; apply: proper_mxsumP. Qed. Canonical nary_addv_expr := ProperSumvExpr nary_addv_subproof. End Nary. Definition directv_def S of phantom {vspace vT} (unwrap (addv_val S)) := \dim (unwrap S) == unwrap (addv_dim S). End SumExpr. Local Notation directv A := (directv_def (Phantom {vspace _} A%VS)). Lemma directvE (S : addv_expr) : directv (unwrap S) = (\dim (unwrap S) == unwrap (addv_dim S)). Proof. by []. Qed. Lemma directvP {S : proper_addv_expr} : reflect (\dim S = S :> nat) (directv S). Proof. exact: eqnP. Qed. Lemma directv_trivial U : directv (unwrap (@trivial_addv U)). Proof. exact: eqxx. Qed. Lemma dimv_sum_leqif (S : addv_expr) : \dim (unwrap S) <= unwrap (addv_dim S) ?= iff directv (unwrap S). Proof. rewrite directvE; case: S => [[U] [d] /= defUd]; split=> //=. rewrite /dimv; elim: {1}_ {U}_ d / defUd => // m1 m2 A1 A2 r1 r2 _ leA1 _ leA2. by apply: leq_trans (leq_add leA1 leA2); rewrite mxrank_adds_leqif. Qed. Lemma directvEgeq (S : addv_expr) : directv (unwrap S) = (\dim (unwrap S) >= unwrap (addv_dim S)). Proof. by rewrite leq_eqVlt ltnNge eq_sym !dimv_sum_leqif orbF. Qed. Section BinaryDirect. Lemma directv_addE (S1 S2 : addv_expr) : directv (unwrap S1 + unwrap S2) = [&& directv (unwrap S1), directv (unwrap S2) & unwrap S1 :&: unwrap S2 == 0]%VS. Proof. by rewrite /directv_def /dimv vs2mxD -mxdirectE mxdirect_addsE -vs2mxI -vs2mx0. Qed. Lemma directv_addP {U V} : reflect (U :&: V = 0)%VS (directv (U + V)). Proof. by rewrite directv_addE !directv_trivial; apply: eqP. Qed. Lemma directv_add_unique {U V} : reflect (forall u1 u2 v1 v2, u1 \in U -> u2 \in U -> v1 \in V -> v2 \in V -> (u1 + v1 == u2 + v2) = ((u1, v1) == (u2, v2))) (directv (U + V)). Proof. apply: (iffP directv_addP) => [dxUV u1 u2 v1 v2 Uu1 Uu2 Vv1 Vv2 | dxUV]. apply/idP/idP=> [| /eqP[-> ->] //]; rewrite -subr_eq0 opprD addrACA addr_eq0. move/eqP=> eq_uv; rewrite xpair_eqE -subr_eq0 eq_uv oppr_eq0 subr_eq0 andbb. by rewrite -subr_eq0 -memv0 -dxUV memv_cap -memvN -eq_uv !memvB. apply/eqP; rewrite -subv0; apply/subvP=> v /memv_capP[U1v U2v]. by rewrite memv0 -[v == 0]andbb {1}eq_sym -xpair_eqE -dxUV ?mem0v // addrC. Qed. End BinaryDirect. Section NaryDirect. Context {I : finType} {P : pred I}. Lemma directv_sumP {Us : I -> {vspace vT}} : reflect (forall i, P i -> Us i :&: (\sum_(j | P j && (j != i)) Us j) = 0)%VS (directv (\sum_(i | P i) Us i)). Proof. rewrite directvE /= /dimv vs2mx_sum -mxdirectE; apply: (equivP mxdirect_sumsP). by do [split=> dxU i /dxU; rewrite -vs2mx_sum -vs2mxI -vs2mx0] => [/val_inj|->]. Qed. Lemma directv_sumE {Ss : I -> addv_expr} (xunwrap := unwrap) : reflect [/\ forall i, P i -> directv (unwrap (Ss i)) & directv (\sum_(i | P i) xunwrap (Ss i))] (directv (\sum_(i | P i) unwrap (Ss i))). Proof. by rewrite !directvE /= /dimv 2!{1}vs2mx_sum -!mxdirectE; apply: mxdirect_sumsE. Qed. Lemma directv_sum_independent {Us : I -> {vspace vT}} : reflect (forall us, (forall i, P i -> us i \in Us i) -> \sum_(i | P i) us i = 0 -> (forall i, P i -> us i = 0)) (directv (\sum_(i | P i) Us i)). Proof. apply: (iffP directv_sumP) => [dxU us Uu u_0 i Pi | dxU i Pi]. apply/eqP; rewrite -memv0 -(dxU i Pi) memv_cap Uu //= -memvN -sub0r -{1}u_0. by rewrite (bigD1 i) //= [_ - us i]addrC addKr memv_sumr // => j /andP[/Uu]. apply/eqP; rewrite -subv0; apply/subvP=> v. rewrite memv_cap memv0 => /andP[Uiv /memv_sumP[us Uu Dv]]. have: \sum_(j | P j) [eta us with i |-> - v] j = 0. rewrite (bigD1 i) //= eqxx {1}Dv addrC -sumrB big1 // => j /andP[_ i'j]. by rewrite (negPf i'j) subrr. move/dxU/(_ i Pi); rewrite /= eqxx -oppr_eq0 => -> // j Pj. by have [-> | i'j] := eqVneq; rewrite ?memvN // Uu ?Pj. Qed. Lemma directv_sum_unique {Us : I -> {vspace vT}} : reflect (forall us vs, (forall i, P i -> us i \in Us i) -> (forall i, P i -> vs i \in Us i) -> (\sum_(i | P i) us i == \sum_(i | P i) vs i) = [forall (i | P i), us i == vs i]) (directv (\sum_(i | P i) Us i)). Proof. apply: (iffP directv_sum_independent) => [dxU us vs Uu Uv | dxU us Uu u_0 i Pi]. apply/idP/forall_inP=> [|eq_uv]; last by apply/eqP/eq_bigr => i /eq_uv/eqP. rewrite -subr_eq0 -sumrB => /eqP/dxU eq_uv i Pi. by rewrite -subr_eq0 eq_uv // => j Pj; apply: memvB; move: j Pj. apply/eqP; have:= esym (dxU us \0 Uu _); rewrite u_0 big1_eq eqxx. by move/(_ _)/forall_inP=> -> // j _; apply: mem0v. Qed. End NaryDirect. (* Linear span generated by a list of vectors *) Lemma memv_span X v : v \in X -> v \in <<X>>%VS. Proof. by case/seq_tnthP=> i {v}->; rewrite unlock memvK genmxE (eq_row_sub i) // rowK. Qed. Lemma memv_span1 v : v \in <<[:: v]>>%VS. Proof. by rewrite memv_span ?mem_head. Qed. Lemma dim_span X : \dim <<X>> <= size X. Proof. by rewrite unlock /dimv genmxE rank_leq_row. Qed. Lemma span_subvP {X U} : reflect {subset X <= U} (<<X>> <= U)%VS. Proof. rewrite /subV [@span _ _]unlock genmxE. apply: (iffP row_subP) => /= [sXU | sXU i]. by move=> _ /seq_tnthP[i ->]; have:= sXU i; rewrite rowK memvK. by rewrite rowK -memvK sXU ?mem_tnth. Qed. Lemma sub_span X Y : {subset X <= Y} -> (<<X>> <= <<Y>>)%VS. Proof. by move=> sXY; apply/span_subvP=> v /sXY/memv_span. Qed. Lemma eq_span X Y : X =i Y -> (<<X>> = <<Y>>)%VS. Proof. by move=> eqXY; apply: subv_anti; rewrite !sub_span // => u; rewrite eqXY. Qed. Lemma span_def X : span X = (\sum_(u <- X) <[u]>)%VS. Proof. apply/subv_anti/andP; split. by apply/span_subvP=> v Xv; rewrite (big_rem v) // memvE addvSl. by rewrite big_tnth; apply/subv_sumP=> i _; rewrite -memvE memv_span ?mem_tnth. Qed. Lemma span_nil : (<<Nil vT>> = 0)%VS. Proof. by rewrite span_def big_nil. Qed. Lemma span_seq1 v : (<<[:: v]>> = <[v]>)%VS. Proof. by rewrite span_def big_seq1. Qed. Lemma span_cons v X : (<<v :: X>> = <[v]> + <<X>>)%VS. Proof. by rewrite !span_def big_cons. Qed. Lemma span_cat X Y : (<<X ++ Y>> = <<X>> + <<Y>>)%VS. Proof. by rewrite !span_def big_cat. Qed. (* Coordinates function; should perhaps be generalized to nat indices. *) Definition coord_expanded_def n (X : n.-tuple vT) i v := (v2r v *m pinvmx (b2mx X)) 0 i. Definition coord := locked_with span_key coord_expanded_def. Canonical coord_unlockable := [unlockable fun coord]. Fact coord_is_scalar n (X : n.-tuple vT) i : scalar (coord X i). Proof. by move=> k u v; rewrite unlock linearP mulmxDl -scalemxAl !mxE. Qed. HB.instance Definition _ n Xn i := GRing.isSemilinear.Build K vT K _ (coord Xn i) (GRing.semilinear_linear (@coord_is_scalar n Xn i)). Lemma coord_span n (X : n.-tuple vT) v : v \in span X -> v = \sum_i coord X i v *: X`_i. Proof. rewrite memvK span_b2mx genmxE => Xv. by rewrite unlock_with mul_b2mx mulmxKpV ?v2rK. Qed. Lemma coord0 i v : coord [tuple 0] i v = 0. Proof. rewrite unlock /pinvmx rank_rV; case: negP => [[] | _]. by apply/eqP/rowP=> j; rewrite !mxE (tnth_nth 0) /= linear0 mxE. by rewrite pid_mx_0 !(mulmx0, mul0mx) mxE. Qed. (* Free generator sequences. *) Lemma nil_free : free (Nil vT). Proof. by rewrite /free span_nil dimv0. Qed. Lemma seq1_free v : free [:: v] = (v != 0). Proof. by rewrite /free span_seq1 dim_vline; case: (~~ _). Qed. Lemma perm_free X Y : perm_eq X Y -> free X = free Y. Proof. by move=> eqXY; rewrite /free (perm_size eqXY) (eq_span (perm_mem eqXY)). Qed. Lemma free_directv X : free X = (0 \notin X) && directv (\sum_(v <- X) <[v]>). Proof. have leXi i (v := tnth (in_tuple X) i): true -> \dim <[v]> <= 1 ?= iff (v != 0). by rewrite -seq1_free -span_seq1 => _; apply/leqif_eq/dim_span. have [_ /=] := leqif_trans (dimv_sum_leqif _) (leqif_sum leXi). rewrite sum1_card card_ord !directvE /= /free andbC span_def !(big_tnth _ _ X). by congr (_ = _ && _); rewrite -has_pred1 -all_predC -big_all big_tnth big_andE. Qed. Lemma free_not0 v X : free X -> v \in X -> v != 0. Proof. by rewrite free_directv andbC => /andP[_ /memPn]; apply. Qed. Lemma freeP n (X : n.-tuple vT) : reflect (forall k, \sum_(i < n) k i *: X`_i = 0 -> (forall i, k i = 0)) (free X). Proof. rewrite free_b2mx; apply: (iffP idP) => [t_free k kt0 i | t_free]. suffices /rowP/(_ i): \row_i k i = 0 by rewrite !mxE. by apply/(row_free_inj t_free)/r2v_inj; rewrite mul0mx -lin_b2mx kt0 linear0. rewrite -kermx_eq0; apply/rowV0P=> rk /sub_kermxP kt0. by apply/rowP=> i; rewrite mxE {}t_free // mul_b2mx kt0 linear0. Qed. Lemma coord_free n (X : n.-tuple vT) (i j : 'I_n) : free X -> coord X j (X`_i) = (i == j)%:R. Proof. rewrite unlock free_b2mx => /row_freeP[Ct CtK]; rewrite -row_b2mx. rewrite -row_mul -[pinvmx _]mulmx1 -CtK (mulmxA (b2mx X)) (mulmxA _ _ Ct). by rewrite mulmxKpV // CtK !mxE. Qed. Lemma coord_sum_free n (X : n.-tuple vT) k j : free X -> coord X j (\sum_(i < n) k i *: X`_i) = k j. Proof. move=> Xfree; rewrite linear_sum (bigD1 j) 1?linearZ //= coord_free // eqxx. rewrite mulr1 big1 ?addr0 // => i /negPf j'i. by rewrite linearZ /= coord_free // j'i mulr0. Qed. Lemma cat_free X Y : free (X ++ Y) = [&& free X, free Y & directv (<<X>> + <<Y>>)]. Proof. rewrite !free_directv mem_cat directvE /= !big_cat -directvE /= directv_addE /=. rewrite negb_or -!andbA; do !bool_congr; rewrite -!span_def. by rewrite (sameP eqP directv_addP). Qed. Lemma catl_free Y X : free (X ++ Y) -> free X. Proof. by rewrite cat_free => /and3P[]. Qed. Lemma catr_free X Y : free (X ++ Y) -> free Y. Proof. by rewrite cat_free => /and3P[]. Qed. Lemma filter_free p X : free X -> free (filter p X). Proof. rewrite -(perm_free (etrans (perm_filterC p X _) (perm_refl X))). exact: catl_free. Qed. Lemma free_cons v X : free (v :: X) = (v \notin <<X>>)%VS && free X. Proof. rewrite (cat_free [:: v]) seq1_free directvEgeq /= span_seq1 dim_vline. case: eqP => [-> | _] /=; first by rewrite mem0v. rewrite andbC ltnNge (geq_leqif (dimv_leqif_sup _)) ?addvSr //. by rewrite subv_add subvv andbT -memvE. Qed. Lemma freeE n (X : n.-tuple vT) : free X = [forall i : 'I_n, X`_i \notin <<drop i.+1 X>>%VS]. Proof. case: X => X /= /eqP <-{n}; rewrite -(big_andE xpredT) /=. elim: X => [|v X IH_X] /=; first by rewrite nil_free big_ord0. by rewrite free_cons IH_X big_ord_recl drop0. Qed. Lemma freeNE n (X : n.-tuple vT) : ~~ free X = [exists i : 'I_n, X`_i \in <<drop i.+1 X>>%VS]. Proof. by rewrite freeE -negb_exists negbK. Qed. Lemma free_uniq X : free X -> uniq X. Proof. elim: X => //= v b IH_X; rewrite free_cons => /andP[X'v /IH_X->]. by rewrite (contra _ X'v) // => /memv_span. Qed. Lemma free_span X v (sumX := fun k => \sum_(x <- X) k x *: x) : free X -> v \in <<X>>%VS -> {k | v = sumX k & forall k1, v = sumX k1 -> {in X, k1 =1 k}}. Proof. rewrite -{2}[X]in_tupleE => freeX /coord_span def_v. pose k x := oapp (fun i => coord (in_tuple X) i v) 0 (insub (index x X)). exists k => [|k1 {}def_v _ /(nthP 0)[i ltiX <-]]. rewrite /sumX (big_nth 0) big_mkord def_v; apply: eq_bigr => i _. by rewrite /k index_uniq ?free_uniq // valK. rewrite /k /= index_uniq ?free_uniq // insubT //= def_v. by rewrite /sumX (big_nth 0) big_mkord coord_sum_free. Qed. Lemma linear_of_free (rT : lmodType K) X (fX : seq rT) : {f : {linear vT -> rT} | free X -> size fX = size X -> map f X = fX}. Proof. pose f u := \sum_i coord (in_tuple X) i u *: fX`_i. have lin_f: linear f. move=> k u v; rewrite scaler_sumr -big_split; apply: eq_bigr => i _. by rewrite /= scalerA -scalerDl linearP. pose flM := GRing.isLinear.Build _ _ _ _ f lin_f. pose fL : {linear _ -> _} := HB.pack f flM. exists fL => freeX eq_szX. apply/esym/(@eq_from_nth _ 0); rewrite ?size_map eq_szX // => i ltiX. rewrite (nth_map 0) //= /f (bigD1 (Ordinal ltiX)) //=. rewrite big1 => [|j /negbTE neqji]; rewrite (coord_free (Ordinal _)) //. by rewrite eqxx scale1r addr0. by rewrite eq_sym neqji scale0r. Qed. (* Subspace bases *) Lemma span_basis U X : basis_of U X -> <<X>>%VS = U. Proof. by case/andP=> /eqP. Qed. Lemma basis_free U X : basis_of U X -> free X. Proof. by case/andP. Qed. Lemma coord_basis U n (X : n.-tuple vT) v : basis_of U X -> v \in U -> v = \sum_i coord X i v *: X`_i. Proof. by move/span_basis <-; apply: coord_span. Qed. Lemma nil_basis : basis_of 0 (Nil vT). Proof. by rewrite /basis_of span_nil eqxx nil_free. Qed. Lemma seq1_basis v : v != 0 -> basis_of <[v]> [:: v]. Proof. by move=> nz_v; rewrite /basis_of span_seq1 // eqxx seq1_free. Qed. Lemma basis_not0 x U X : basis_of U X -> x \in X -> x != 0. Proof. by move/basis_free/free_not0; apply. Qed. Lemma basis_mem x U X : basis_of U X -> x \in X -> x \in U. Proof. by move/span_basis=> <- /memv_span. Qed. Lemma cat_basis U V X Y : directv (U + V) -> basis_of U X -> basis_of V Y -> basis_of (U + V) (X ++ Y). Proof. move=> dxUV /andP[/eqP defU freeX] /andP[/eqP defV freeY]. by rewrite /basis_of span_cat cat_free defU defV // eqxx freeX freeY. Qed. Lemma size_basis U n (X : n.-tuple vT) : basis_of U X -> \dim U = n. Proof. by case/andP=> /eqP <- /eqnP->; apply: size_tuple. Qed. Lemma basisEdim X U : basis_of U X = (U <= <<X>>)%VS && (size X <= \dim U). Proof. apply/andP/idP=> [[defU /eqnP <-]| ]; first by rewrite -eqEdim eq_sym. case/andP=> sUX leXU; have leXX := dim_span X. rewrite /free eq_sym eqEdim sUX eqn_leq !(leq_trans leXX) //. by rewrite (leq_trans leXU) ?dimvS. Qed. Lemma basisEfree X U : basis_of U X = [&& free X, (<<X>> <= U)%VS & \dim U <= size X]. Proof. by rewrite andbC; apply: andb_id2r => freeX; rewrite eqEdim (eqnP freeX). Qed. Lemma perm_basis X Y U : perm_eq X Y -> basis_of U X = basis_of U Y. Proof. move=> eqXY; congr ((_ == _) && _); last exact: perm_free. exact/eq_span/perm_mem. Qed. Lemma vbasisP U : basis_of U (vbasis U). Proof. rewrite /basis_of free_b2mx span_b2mx (sameP eqP (vs2mxP _ _)) !genmxE. have ->: b2mx (vbasis U) = row_base (vs2mx U). by apply/row_matrixP=> i; rewrite unlock rowK tnth_mktuple r2vK. by rewrite row_base_free !eq_row_base submx_refl. Qed. Lemma vbasis_mem v U : v \in (vbasis U) -> v \in U. Proof. exact: basis_mem (vbasisP _). Qed. Lemma coord_vbasis v U : v \in U -> v = \sum_(i < \dim U) coord (vbasis U) i v *: (vbasis U)`_i. Proof. exact: coord_basis (vbasisP U). Qed. Section BigSumBasis. Variables (I : finType) (P : pred I) (Xs : I -> seq vT). Lemma span_bigcat : (<<\big[cat/[::]]_(i | P i) Xs i>> = \sum_(i | P i) <<Xs i>>)%VS. Proof. by rewrite (big_morph _ span_cat span_nil). Qed. Lemma bigcat_free : directv (\sum_(i | P i) <<Xs i>>) -> (forall i, P i -> free (Xs i)) -> free (\big[cat/[::]]_(i | P i) Xs i). Proof. rewrite /free directvE /= span_bigcat => /directvP-> /= freeXs. rewrite (big_morph _ (@size_cat _) (erefl _)) /=. by apply/eqP/eq_bigr=> i /freeXs/eqP. Qed. Lemma bigcat_basis Us (U := (\sum_(i | P i) Us i)%VS) : directv U -> (forall i, P i -> basis_of (Us i) (Xs i)) -> basis_of U (\big[cat/[::]]_(i | P i) Xs i). Proof. move=> dxU XsUs; rewrite /basis_of span_bigcat. have defUs i: P i -> span (Xs i) = Us i by case/XsUs/andP=> /eqP. rewrite (eq_bigr _ defUs) eqxx bigcat_free // => [|_ /XsUs/andP[]//]. apply/directvP; rewrite /= (eq_bigr _ defUs) (directvP dxU) /=. by apply/eq_bigr=> i /defUs->. Qed. End BigSumBasis. End VectorTheory. #[global] Hint Resolve subvv : core. Arguments subvP {K vT U V}. Arguments addv_idPl {K vT U V}. Arguments addv_idPr {K vT U V}. Arguments memv_addP {K vT w U V }. Arguments sumv_sup [K vT I] i0 [P U Vs]. Arguments memv_sumP {K vT I P Us v}. Arguments subv_sumP {K vT I P Us V}. Arguments capv_idPl {K vT U V}. Arguments capv_idPr {K vT U V}. Arguments memv_capP {K vT w U V}. Arguments bigcapv_inf [K vT I] i0 [P Us V]. Arguments subv_bigcapP {K vT I P U Vs}. Arguments directvP {K vT S}. Arguments directv_addP {K vT U V}. Arguments directv_add_unique {K vT U V}. Arguments directv_sumP {K vT I P Us}. Arguments directv_sumE {K vT I P Ss}. Arguments directv_sum_independent {K vT I P Us}. Arguments directv_sum_unique {K vT I P Us}. Arguments span_subvP {K vT X U}. Arguments freeP {K vT n X}. Prenex Implicits coord. Notation directv S := (directv_def (Phantom _ S%VS)). (* Linear functions over a vectType *) Section LfunDefs. Variable R : nzRingType. Implicit Types aT vT rT : vectType R. Fact lfun_key : unit. Proof. by []. Qed. Definition fun_of_lfun_def aT rT (f : 'Hom(aT, rT)) := r2v \o mulmxr (f2mx f) \o v2r. Definition fun_of_lfun := locked_with lfun_key fun_of_lfun_def. Canonical fun_of_lfun_unlockable := [unlockable fun fun_of_lfun]. Definition linfun_def aT rT (f : aT -> rT) := Hom (lin1_mx (v2r \o f \o r2v)). Definition linfun := locked_with lfun_key linfun_def. Canonical linfun_unlockable := [unlockable fun linfun]. Definition id_lfun vT := @linfun vT vT idfun. Definition comp_lfun aT vT rT (f : 'Hom(vT, rT)) (g : 'Hom(aT, vT)) := linfun (fun_of_lfun f \o fun_of_lfun g). End LfunDefs. Coercion fun_of_lfun : hom >-> Funclass. Notation "\1" := (@id_lfun _ _) : lfun_scope. Notation "f \o g" := (comp_lfun f g) : lfun_scope. Section LfunVspaceDefs. Variable K : fieldType. Implicit Types aT rT : vectType K. Definition inv_lfun aT rT (f : 'Hom(aT, rT)) := Hom (pinvmx (f2mx f)). Definition lker aT rT (f : 'Hom(aT, rT)) := mx2vs (kermx (f2mx f)). Fact lfun_img_key : unit. Proof. by []. Qed. Definition lfun_img_def aT rT f (U : {vspace aT}) : {vspace rT} := mx2vs (vs2mx U *m f2mx f). Definition lfun_img := locked_with lfun_img_key lfun_img_def. Canonical lfun_img_unlockable := [unlockable fun lfun_img]. Definition lfun_preim aT rT (f : 'Hom(aT, rT)) W := (lfun_img (inv_lfun f) (W :&: lfun_img f fullv) + lker f)%VS. End LfunVspaceDefs. Prenex Implicits linfun lfun_img lker lfun_preim. Notation "f ^-1" := (inv_lfun f) : lfun_scope. Notation "f @: U" := (lfun_img f%VF%R U) (at level 24) : vspace_scope. Notation "f @^-1: W" := (lfun_preim f%VF%R W) (at level 24) : vspace_scope. Notation limg f := (lfun_img f fullv). Section LfunZmodType. Variables (R : nzRingType) (aT rT : vectType R). Implicit Types f g h : 'Hom(aT, rT). HB.instance Definition _ := [Choice of 'Hom(aT, rT) by <:]. Fact lfun_is_linear f : linear f. Proof. by rewrite unlock; apply: linearP. Qed. HB.instance Definition _ (f : hom aT rT) := GRing.isSemilinear.Build R aT rT _ f (GRing.semilinear_linear (lfun_is_linear f)). Lemma lfunE (ff : {linear aT -> rT}) : linfun ff =1 ff. Proof. by move=> v; rewrite 2!unlock /= mul_rV_lin1 /= !v2rK. Qed. Lemma fun_of_lfunK : cancel (@fun_of_lfun R aT rT) linfun. Proof. move=> f; apply/val_inj/row_matrixP=> i. by rewrite 2!unlock /= !rowE mul_rV_lin1 /= !r2vK. Qed. Lemma lfunP f g : f =1 g <-> f = g. Proof. split=> [eq_fg | -> //]; rewrite -[f]fun_of_lfunK -[g]fun_of_lfunK unlock. by apply/val_inj/row_matrixP=> i; rewrite !rowE !mul_rV_lin1 /= eq_fg. Qed. Definition zero_lfun : 'Hom(aT, rT) := linfun \0. Definition add_lfun f g := linfun (f \+ g). Definition opp_lfun f := linfun (-%R \o f). Fact lfun_addA : associative add_lfun. Proof. by move=> f g h; apply/lfunP=> v; rewrite !lfunE /= !lfunE addrA. Qed. Fact lfun_addC : commutative add_lfun. Proof. by move=> f g; apply/lfunP=> v; rewrite !lfunE /= addrC. Qed. Fact lfun_add0 : left_id zero_lfun add_lfun. Proof. by move=> f; apply/lfunP=> v; rewrite lfunE /= lfunE add0r. Qed. Lemma lfun_addN : left_inverse zero_lfun opp_lfun add_lfun. Proof. by move=> f; apply/lfunP=> v; rewrite !lfunE /= lfunE addNr. Qed. HB.instance Definition _ := GRing.isZmodule.Build 'Hom(aT, rT) lfun_addA lfun_addC lfun_add0 lfun_addN. Lemma zero_lfunE x : (0 : 'Hom(aT, rT)) x = 0. Proof. exact: lfunE. Qed. Lemma add_lfunE f g x : (f + g) x = f x + g x. Proof. exact: lfunE. Qed. Lemma opp_lfunE f x : (- f) x = - f x. Proof. exact: lfunE. Qed. Lemma sum_lfunE I (r : seq I) (P : pred I) (fs : I -> 'Hom(aT, rT)) x : (\sum_(i <- r | P i) fs i) x = \sum_(i <- r | P i) fs i x. Proof. by elim/big_rec2: _ => [|i _ f _ <-]; rewrite lfunE. Qed. End LfunZmodType. Arguments fun_of_lfunK {R aT rT}. Section LfunVectType. Variables (R : comNzRingType) (aT rT : vectType R). Implicit Types f : 'Hom(aT, rT). Definition scale_lfun k f := linfun (k \*: f). Local Infix "*:l" := scale_lfun (at level 40). Fact lfun_scaleA k1 k2 f : k1 *:l (k2 *:l f) = (k1 * k2) *:l f. Proof. by apply/lfunP=> v; rewrite !lfunE /= lfunE scalerA. Qed. Fact lfun_scale1 f : 1 *:l f = f. Proof. by apply/lfunP=> v; rewrite lfunE /= scale1r. Qed. Fact lfun_scaleDr k f1 f2 : k *:l (f1 + f2) = k *:l f1 + k *:l f2. Proof. by apply/lfunP=> v; rewrite !lfunE /= !lfunE scalerDr. Qed. Fact lfun_scaleDl f k1 k2 : (k1 + k2) *:l f = k1 *:l f + k2 *:l f. Proof. by apply/lfunP=> v; rewrite !lfunE /= !lfunE scalerDl. Qed. HB.instance Definition _ := GRing.Zmodule_isLmodule.Build _ 'Hom(aT, rT) lfun_scaleA lfun_scale1 lfun_scaleDr lfun_scaleDl. Lemma scale_lfunE k f x : (k *: f) x = k *: f x. Proof. exact: lfunE. Qed. Fact lfun_vect_iso : Vector.axiom (dim aT * dim rT) 'Hom(aT, rT). Proof. exists (mxvec \o f2mx) => [a f g|]. rewrite /= -linearP /= -[A in _ = mxvec A]/(f2mx (Hom _)). congr (mxvec (f2mx _)); apply/lfunP=> v; do 2!rewrite lfunE /=. by rewrite unlock /= -linearP mulmxDr scalemxAr. apply: Bijective (Hom \o vec_mx) _ _ => [[A]|A] /=; last exact: vec_mxK. by rewrite mxvecK. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build _ 'Hom(aT, rT) lfun_vect_iso. End LfunVectType. Section CompLfun. Variables (R : nzRingType) (wT aT vT rT : vectType R). Implicit Types (f : 'Hom(vT, rT)) (g : 'Hom(aT, vT)) (h : 'Hom(wT, aT)). Lemma id_lfunE u: \1%VF u = u :> aT. Proof. exact: lfunE. Qed. Lemma comp_lfunE f g u : (f \o g)%VF u = f (g u). Proof. exact: lfunE. Qed. Lemma comp_lfunA f g h : (f \o (g \o h) = (f \o g) \o h)%VF. Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed. Lemma comp_lfun1l f : (\1 \o f)%VF = f. Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed. Lemma comp_lfun1r f : (f \o \1)%VF = f. Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed. Lemma comp_lfun0l g : (0 \o g)%VF = 0 :> 'Hom(aT, rT). Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed. Lemma comp_lfun0r f : (f \o 0)%VF = 0 :> 'Hom(aT, rT). Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linear0. Qed. Lemma comp_lfunDl f1 f2 g : ((f1 + f2) \o g = (f1 \o g) + (f2 \o g))%VF. Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed. Lemma comp_lfunDr f g1 g2 : (f \o (g1 + g2) = (f \o g1) + (f \o g2))%VF. Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linearD. Qed. Lemma comp_lfunNl f g : ((- f) \o g = - (f \o g))%VF. Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed. Lemma comp_lfunNr f g : (f \o (- g) = - (f \o g))%VF. Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linearN. Qed. End CompLfun. Definition lfun_simp := (comp_lfunE, scale_lfunE, opp_lfunE, add_lfunE, sum_lfunE, lfunE). Section ScaleCompLfun. Variables (R : comNzRingType) (aT vT rT : vectType R). Implicit Types (f : 'Hom(vT, rT)) (g : 'Hom(aT, vT)). Lemma comp_lfunZl k f g : (k *: (f \o g) = (k *: f) \o g)%VF. Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed. Lemma comp_lfunZr k f g : (k *: (f \o g) = f \o (k *: g))%VF. Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linearZ. Qed. End ScaleCompLfun. Section LinearImage. Variables (K : fieldType) (aT rT : vectType K). Implicit Types (f g : 'Hom(aT, rT)) (U V : {vspace aT}) (W : {vspace rT}). Lemma limgS f U V : (U <= V)%VS -> (f @: U <= f @: V)%VS. Proof. by rewrite unlock /subsetv !genmxE; apply: submxMr. Qed. Lemma limg_line f v : (f @: <[v]> = <[f v]>)%VS. Proof. apply/eqP; rewrite 2!unlock eqEsubv /subsetv /= r2vK !genmxE. by rewrite !(eqmxMr _ (genmxE _)) submx_refl. Qed. Lemma limg0 f : (f @: 0 = 0)%VS. Proof. by rewrite limg_line linear0. Qed. Lemma memv_img f v U : v \in U -> f v \in (f @: U)%VS. Proof. by move=> Uv; rewrite memvE -limg_line limgS. Qed. Lemma memv_imgP f w U : reflect (exists2 u, u \in U & w = f u) (w \in f @: U)%VS. Proof. apply: (iffP idP) => [|[u Uu ->]]; last exact: memv_img. rewrite 2!unlock memvE /subsetv !genmxE => /submxP[ku Drw]. exists (r2v (ku *m vs2mx U)); last by rewrite /= r2vK -mulmxA -Drw v2rK. by rewrite memvE /subsetv !genmxE r2vK submxMl. Qed. Lemma lim0g U : (0 @: U = 0 :> {vspace rT})%VS. Proof. apply/eqP; rewrite -subv0; apply/subvP=> _ /memv_imgP[u _ ->]. by rewrite lfunE rpred0. Qed. Lemma eq_in_limg V f g : {in V, f =1 g} -> (f @: V = g @: V)%VS. Proof. move=> eq_fg; apply/vspaceP=> y. by apply/memv_imgP/memv_imgP=> [][x Vx ->]; exists x; rewrite ?eq_fg. Qed. Lemma limgD f : {morph lfun_img f : U V / U + V}%VS. Proof. move=> U V; apply/eqP; rewrite unlock eqEsubv /subsetv /= -genmx_adds. by rewrite !genmxE !(eqmxMr _ (genmxE _)) !addsmxMr submx_refl. Qed. Lemma limg_sum f I r (P : pred I) Us : (f @: (\sum_(i <- r | P i) Us i) = \sum_(i <- r | P i) f @: Us i)%VS. Proof. exact: (big_morph _ (limgD f) (limg0 f)). Qed. Lemma limg_cap f U V : (f @: (U :&: V) <= f @: U :&: f @: V)%VS. Proof. by rewrite subv_cap !limgS ?capvSl ?capvSr. Qed. Lemma limg_bigcap f I r (P : pred I) Us : (f @: (\bigcap_(i <- r | P i) Us i) <= \bigcap_(i <- r | P i) f @: Us i)%VS. Proof. elim/big_rec2: _ => [|i V U _ sUV]; first exact: subvf. by rewrite (subv_trans (limg_cap f _ U)) ?capvS. Qed. Lemma limg_span f X : (f @: <<X>> = <<map f X>>)%VS. Proof. by rewrite !span_def big_map limg_sum; apply: eq_bigr => x _; rewrite limg_line. Qed. Lemma subset_limgP f U (r : seq rT) : {subset r <= (f @: U)%VS} <-> (exists2 a, all (mem U) a & r = map f a). Proof. split => [|[{}r /allP/= rE ->] _ /mapP[x xr ->]]; last by rewrite memv_img ?rE. move=> /(_ _ _)/memv_imgP/sig2_eqW-/(all_sig_cond (0 : aT))[f' f'P]. exists (map f' r); first by apply/allP => _ /mapP [x /f'P[? ?] ->]. by symmetry; rewrite -map_comp; apply: map_id_in => x /f'P[]. Qed. Lemma lfunPn f g : reflect (exists u, f u != g u) (f != g). Proof. apply: (iffP idP) => [f'g|[x]]; last by apply: contraNneq => /lfunP->. suffices /subvPn[_ /memv_imgP[u _ ->]]: ~~ (limg (f - g) <= 0)%VS. by rewrite lfunE /= lfunE /= memv0 subr_eq0; exists u. apply: contra f'g => /subvP fg0; apply/eqP/lfunP=> u; apply/eqP. by rewrite -subr_eq0 -opp_lfunE -add_lfunE -memv0 fg0 ?memv_img ?memvf. Qed. Lemma inv_lfun_def f : (f \o f^-1 \o f)%VF = f. Proof. apply/lfunP=> u; do !rewrite lfunE /=; rewrite unlock /= !r2vK. by rewrite mulmxKpV ?submxMl. Qed. Lemma limg_lfunVK f : {in limg f, cancel f^-1%VF f}. Proof. by move=> _ /memv_imgP[u _ ->]; rewrite -!comp_lfunE inv_lfun_def. Qed. Lemma lkerE f U : (U <= lker f)%VS = (f @: U == 0)%VS. Proof. rewrite unlock -dimv_eq0 /dimv /subsetv !genmxE mxrank_eq0. by rewrite (sameP sub_kermxP eqP). Qed. Lemma memv_ker f v : (v \in lker f) = (f v == 0). Proof. by rewrite -memv0 !memvE subv0 lkerE limg_line. Qed. Lemma eqlfunP f g v : reflect (f v = g v) (v \in lker (f - g)). Proof. by rewrite memv_ker !lfun_simp subr_eq0; apply: eqP. Qed. Lemma eqlfun_inP V f g : reflect {in V, f =1 g} (V <= lker (f - g))%VS. Proof. by apply: (iffP subvP) => E x /E/eqlfunP. Qed. Lemma limg_ker_compl f U : (f @: (U :\: lker f) = f @: U)%VS. Proof. rewrite -{2}(addv_diff_cap U (lker f)) limgD; apply/esym/addv_idPl. by rewrite (subv_trans _ (sub0v _)) // subv0 -lkerE capvSr. Qed. Lemma limg_ker_dim f U : (\dim (U :&: lker f) + \dim (f @: U) = \dim U)%N. Proof. rewrite unlock /dimv /= genmx_cap genmx_id -genmx_cap !genmxE. by rewrite addnC mxrank_mul_ker. Qed. Lemma limg_dim_eq f U : (U :&: lker f = 0)%VS -> \dim (f @: U) = \dim U. Proof. by rewrite -(limg_ker_dim f U) => ->; rewrite dimv0. Qed. Lemma limg_basis_of f U X : (U :&: lker f = 0)%VS -> basis_of U X -> basis_of (f @: U) (map f X). Proof. move=> injUf /andP[/eqP defU /eqnP freeX]. by rewrite /basis_of /free size_map -limg_span -freeX defU limg_dim_eq ?eqxx. Qed. Lemma lker0P f : reflect (injective f) (lker f == 0%VS). Proof. rewrite -subv0; apply: (iffP subvP) => [injf u v eq_fuv | injf u]. apply/eqP; rewrite -subr_eq0 -memv0 injf //. by rewrite memv_ker linearB /= eq_fuv subrr. by rewrite memv_ker memv0 -(inj_eq injf) linear0. Qed. Lemma limg_ker0 f U V : lker f == 0%VS -> (f @: U <= f @: V)%VS = (U <= V)%VS. Proof. move/lker0P=> injf; apply/idP/idP=> [/subvP sfUV | ]; last exact: limgS. by apply/subvP=> u Uu; have /memv_imgP[v Vv /injf->] := sfUV _ (memv_img f Uu). Qed. Lemma eq_limg_ker0 f U V : lker f == 0%VS -> (f @: U == f @: V)%VS = (U == V). Proof. by move=> injf; rewrite !eqEsubv !limg_ker0. Qed. Lemma lker0_lfunK f : lker f == 0%VS -> cancel f f^-1%VF. Proof. by move/lker0P=> injf u; apply: injf; rewrite limg_lfunVK ?memv_img ?memvf. Qed. Lemma lker0_compVf f : lker f == 0%VS -> (f^-1 \o f = \1)%VF. Proof. by move/lker0_lfunK=> fK; apply/lfunP=> u; rewrite !lfunE /= fK. Qed. Lemma lker0_img_cap f U V : lker f == 0%VS -> (f @: (U :&: V) = f @: U :&: f @: V)%VS. Proof. move=> kf0; apply/eqP; rewrite eqEsubv limg_cap/=; apply/subvP => x. rewrite memv_cap => /andP[/memv_imgP[u uU ->]] /memv_imgP[v vV]. by move=> /(lker0P _ kf0) eq_uv; rewrite memv_img// memv_cap uU eq_uv vV. Qed. End LinearImage. Arguments memv_imgP {K aT rT f w U}. Arguments lfunPn {K aT rT f g}. Arguments lker0P {K aT rT f}. Arguments eqlfunP {K aT rT f g v}. Arguments eqlfun_inP {K aT rT V f g}. Arguments limg_lfunVK {K aT rT f} [x] f_x. Section FixedSpace. Variables (K : fieldType) (vT : vectType K). Implicit Types (f : 'End(vT)) (U : {vspace vT}). Definition fixedSpace f : {vspace vT} := lker (f - \1%VF). Lemma fixedSpaceP f a : reflect (f a = a) (a \in fixedSpace f). Proof. by rewrite memv_ker add_lfunE opp_lfunE id_lfunE subr_eq0; apply: eqP. Qed. Lemma fixedSpacesP f U : reflect {in U, f =1 id} (U <= fixedSpace f)%VS. Proof. by apply: (iffP subvP) => cUf x /cUf/fixedSpaceP. Qed. Lemma fixedSpace_limg f U : (U <= fixedSpace f -> f @: U = U)%VS. Proof. move/fixedSpacesP=> cUf; apply/vspaceP=> x. by apply/memv_imgP/idP=> [[{}x Ux ->] | Ux]; last exists x; rewrite ?cUf. Qed. Lemma fixedSpace_id : fixedSpace \1 = {:vT}%VS. Proof. by apply/vspaceP=> x; rewrite memvf; apply/fixedSpaceP; rewrite lfunE. Qed. End FixedSpace. Arguments fixedSpaceP {K vT f a}. Arguments fixedSpacesP {K vT f U}. Section LinAut. Variables (K : fieldType) (vT : vectType K) (f : 'End(vT)). Hypothesis kerf0 : lker f == 0%VS. Lemma lker0_limgf : limg f = fullv. Proof. by apply/eqP; rewrite eqEdim subvf limg_dim_eq //= (eqP kerf0) capv0. Qed. Lemma lker0_lfunVK : cancel f^-1%VF f. Proof. by move=> u; rewrite limg_lfunVK // lker0_limgf memvf. Qed. Lemma lker0_compfV : (f \o f^-1 = \1)%VF. Proof. by apply/lfunP=> u; rewrite !lfunE /= lker0_lfunVK. Qed. Lemma lker0_compVKf aT g : (f \o (f^-1 \o g))%VF = g :> 'Hom(aT, vT). Proof. by rewrite comp_lfunA lker0_compfV comp_lfun1l. Qed. Lemma lker0_compKf aT g : (f^-1 \o (f \o g))%VF = g :> 'Hom(aT, vT). Proof. by rewrite comp_lfunA lker0_compVf ?comp_lfun1l. Qed. Lemma lker0_compfK rT h : ((h \o f) \o f^-1)%VF = h :> 'Hom(vT, rT). Proof. by rewrite -comp_lfunA lker0_compfV comp_lfun1r. Qed. Lemma lker0_compfVK rT h : ((h \o f^-1) \o f)%VF = h :> 'Hom(vT, rT). Proof. by rewrite -comp_lfunA lker0_compVf ?comp_lfun1r. Qed. End LinAut. Section LinearImageComp. Variables (K : fieldType) (aT vT rT : vectType K). Implicit Types (f : 'Hom(aT, vT)) (g : 'Hom(vT, rT)) (U : {vspace aT}). Lemma lim1g U : (\1 @: U)%VS = U. Proof. have /andP[/eqP <- _] := vbasisP U; rewrite limg_span map_id_in // => u _. by rewrite lfunE. Qed. Lemma limg_comp f g U : ((g \o f) @: U = g @: (f @: U))%VS. Proof. have /andP[/eqP <- _] := vbasisP U; rewrite !limg_span; congr (span _). by rewrite -map_comp; apply/eq_map => u; rewrite lfunE. Qed. End LinearImageComp. Section LinearPreimage. Variables (K : fieldType) (aT rT : vectType K). Implicit Types (f : 'Hom(aT, rT)) (U : {vspace aT}) (V W : {vspace rT}). Lemma lpreim_cap_limg f W : (f @^-1: (W :&: limg f))%VS = (f @^-1: W)%VS. Proof. by rewrite /lfun_preim -capvA capvv. Qed. Lemma lpreim0 f : (f @^-1: 0)%VS = lker f. Proof. by rewrite /lfun_preim cap0v limg0 add0v. Qed. Lemma lpreimS f V W : (V <= W)%VS-> (f @^-1: V <= f @^-1: W)%VS. Proof. by move=> sVW; rewrite addvS // limgS // capvS. Qed. Lemma lpreimK f W : (W <= limg f)%VS -> (f @: (f @^-1: W))%VS = W. Proof. move=> sWf; rewrite limgD (capv_idPl sWf) // -limg_comp. have /eqP->: (f @: lker f == 0)%VS by rewrite -lkerE. have /andP[/eqP defW _] := vbasisP W; rewrite addv0 -defW limg_span. rewrite map_id_in // => x Xx; rewrite lfunE /= limg_lfunVK //. by apply: span_subvP Xx; rewrite defW. Qed. Lemma memv_preim f u W : (f u \in W) = (u \in f @^-1: W)%VS. Proof. apply/idP/idP=> [Wfu | /(memv_img f)]; last first. by rewrite -lpreim_cap_limg lpreimK ?capvSr // => /memv_capP[]. rewrite -[u](addNKr (f^-1%VF (f u))) memv_add ?memv_img //. by rewrite memv_cap Wfu memv_img ?memvf. by rewrite memv_ker addrC linearB /= subr_eq0 limg_lfunVK ?memv_img ?memvf. Qed. End LinearPreimage. Arguments lpreimK {K aT rT f} [W] fW. Section LfunAlgebra. (* This section is a bit of a place holder: the instances we build here can't *) (* be canonical because we are missing an interface for proper vectTypes, *) (* would sit between Vector and Falgebra. For now, we just supply structure *) (* definitions here and supply actual instances for F-algebras in a submodule *) (* of the algebra library (there is currently no actual use of the End(vT) *) (* algebra structure). Also note that the unit ring structure is missing. *) Variables (R : comNzRingType) (vT : vectType R). Hypothesis vT_proper : dim vT > 0. Fact lfun1_neq0 : \1%VF != 0 :> 'End(vT). Proof. apply/eqP=> /lfunP/(_ (r2v (const_mx 1))); rewrite !lfunE /= => /(canRL r2vK). by move=> /rowP/(_ (Ordinal vT_proper))/eqP; rewrite linear0 !mxE oner_eq0. Qed. Prenex Implicits comp_lfunA comp_lfun1l comp_lfun1r comp_lfunDl comp_lfunDr. (* FIXME: as explained above, the following structures should not be declared * * as canonical, so mixins and structures are built separately, and we * * don't use HB.instance Definition _ := ... * * This is ok, but maybe we could introduce an alias *) Definition lfun_comp_nzRingMixin := GRing.Zmodule_isNzRing.Build 'End(vT) comp_lfunA comp_lfun1l comp_lfun1r comp_lfunDl comp_lfunDr lfun1_neq0. #[deprecated(since="mathcomp 2.4.0", note="Use lfun_comp_nzRingMixin instead.")] Notation lfun_comp_ringMixin := (lfun_comp_nzRingMixin) (only parsing). Definition lfun_comp_nzRingType : nzRingType := HB.pack 'End(vT) lfun_comp_nzRingMixin. #[deprecated(since="mathcomp 2.4.0", note="Use lfun_comp_nzRingType instead.")] Notation lfun_comp_ringType := (lfun_comp_nzRingType) (only parsing). (* In the standard endomorphism ring product is categorical composition. *) Definition lfun_nzRingType : nzRingType := lfun_comp_nzRingType^c. #[deprecated(since="mathcomp 2.4.0", note="Use lfun_nzRingType instead.")] Notation lfun_ringType := (lfun_nzRingType) (only parsing). Definition lfun_lalgMixin := GRing.Lmodule_isLalgebra.Build R lfun_nzRingType (fun k x y => comp_lfunZr k y x). Definition lfun_lalgType : lalgType R := HB.pack 'End(vT) lfun_nzRingType lfun_lalgMixin. Definition lfun_algMixin := GRing.Lalgebra_isAlgebra.Build R lfun_lalgType (fun k x y => comp_lfunZl k y x). Definition lfun_algType : algType R := HB.pack 'End(vT) lfun_lalgType lfun_algMixin. End LfunAlgebra. Section Projection. Variables (K : fieldType) (vT : vectType K). Implicit Types U V : {vspace vT}. Definition daddv_pi U V := Hom (proj_mx (vs2mx U) (vs2mx V)). Definition projv U := daddv_pi U U^C. Definition addv_pi1 U V := daddv_pi (U :\: V) V. Definition addv_pi2 U V := daddv_pi V (U :\: V). Lemma memv_pi U V w : (daddv_pi U V) w \in U. Proof. by rewrite unlock memvE /subsetv genmxE /= r2vK proj_mx_sub. Qed. Lemma memv_proj U w : projv U w \in U. Proof. exact: memv_pi. Qed. Lemma memv_pi1 U V w : (addv_pi1 U V) w \in U. Proof. by rewrite (subvP (diffvSl U V)) ?memv_pi. Qed. Lemma memv_pi2 U V w : (addv_pi2 U V) w \in V. Proof. exact: memv_pi. Qed. Lemma daddv_pi_id U V u : (U :&: V = 0)%VS -> u \in U -> daddv_pi U V u = u. Proof. move/eqP; rewrite -dimv_eq0 memvE /subsetv /dimv !genmxE mxrank_eq0 => /eqP. by move=> dxUV Uu; rewrite unlock /= proj_mx_id ?v2rK. Qed. Lemma daddv_pi_proj U V w (pi := daddv_pi U V) : (U :&: V = 0)%VS -> pi (pi w) = pi w. Proof. by move/daddv_pi_id=> -> //; apply: memv_pi. Qed. Lemma daddv_pi_add U V w : (U :&: V = 0)%VS -> (w \in U + V)%VS -> daddv_pi U V w + daddv_pi V U w = w. Proof. move/eqP; rewrite -dimv_eq0 memvE /subsetv /dimv !genmxE mxrank_eq0 => /eqP. by move=> dxUW UVw; rewrite unlock /= -linearD /= add_proj_mx ?v2rK. Qed. Lemma projv_id U u : u \in U -> projv U u = u. Proof. exact: daddv_pi_id (capv_compl _). Qed. Lemma projv_proj U w : projv U (projv U w) = projv U w. Proof. exact: daddv_pi_proj (capv_compl _). Qed. Lemma memv_projC U w : w - projv U w \in (U^C)%VS. Proof. rewrite -{1}[w](daddv_pi_add (capv_compl U)) ?addv_complf ?memvf //. by rewrite addrC addKr memv_pi. Qed. Lemma limg_proj U : limg (projv U) = U. Proof. apply/vspaceP=> u; apply/memv_imgP/idP=> [[u1 _ ->] | ]; first exact: memv_proj. by exists (projv U u); rewrite ?projv_id ?memv_img ?memvf. Qed. Lemma lker_proj U : lker (projv U) = (U^C)%VS. Proof. apply/eqP; rewrite eqEdim andbC; apply/andP; split. by rewrite dimv_compl -(limg_ker_dim (projv U) fullv) limg_proj addnK capfv. by apply/subvP=> v; rewrite memv_ker -{2}[v]subr0 => /eqP <-; apply: memv_projC. Qed. Lemma addv_pi1_proj U V w (pi1 := addv_pi1 U V) : pi1 (pi1 w) = pi1 w. Proof. by rewrite daddv_pi_proj // capv_diff. Qed. Lemma addv_pi2_id U V v : v \in V -> addv_pi2 U V v = v. Proof. by apply: daddv_pi_id; rewrite capvC capv_diff. Qed. Lemma addv_pi2_proj U V w (pi2 := addv_pi2 U V) : pi2 (pi2 w) = pi2 w. Proof. by rewrite addv_pi2_id ?memv_pi2. Qed. Lemma addv_pi1_pi2 U V w : w \in (U + V)%VS -> addv_pi1 U V w + addv_pi2 U V w = w. Proof. by rewrite -addv_diff; exact/daddv_pi_add/capv_diff. Qed. Section Sumv_Pi. Variables (I : eqType) (r0 : seq I) (P : pred I) (Vs : I -> {vspace vT}). Let sumv_pi_rec i := fix loop r := if r is j :: r1 then let V1 := (\sum_(k <- r1) Vs k)%VS in if j == i then addv_pi1 (Vs j) V1 else (loop r1 \o addv_pi2 (Vs j) V1)%VF else 0. Notation sumV := (\sum_(i <- r0 | P i) Vs i)%VS. Definition sumv_pi_for V of V = sumV := fun i => sumv_pi_rec i (filter P r0). Variables (V : {vspace vT}) (defV : V = sumV). Lemma memv_sum_pi i v : sumv_pi_for defV i v \in Vs i. Proof. rewrite /sumv_pi_for. elim: (filter P r0) v => [|j r IHr] v /=; first by rewrite lfunE mem0v. by case: eqP => [->|_]; rewrite ?lfunE ?memv_pi1 /=. Qed. Lemma sumv_pi_uniq_sum v : uniq (filter P r0) -> v \in V -> \sum_(i <- r0 | P i) sumv_pi_for defV i v = v. Proof. rewrite /sumv_pi_for defV -!(big_filter r0 P). elim: (filter P r0) v => [|i r IHr] v /= => [_ | /andP[r'i /IHr{}IHr]]. by rewrite !big_nil memv0 => /eqP. rewrite !big_cons eqxx => /addv_pi1_pi2; congr (_ + _ = v). rewrite -[_ v]IHr ?memv_pi2 //; apply: eq_big_seq => j /=. by case: eqP => [<- /idPn | _]; rewrite ?lfunE. Qed. End Sumv_Pi. End Projection. Prenex Implicits daddv_pi projv addv_pi1 addv_pi2. Notation sumv_pi V := (sumv_pi_for (erefl V)). Section SumvPi. Variable (K : fieldType) (vT : vectType K). Lemma sumv_pi_sum (I : finType) (P : pred I) Vs v (V : {vspace vT}) (defV : V = (\sum_(i | P i) Vs i)%VS) : v \in V -> \sum_(i | P i) sumv_pi_for defV i v = v :> vT. Proof. by apply: sumv_pi_uniq_sum; have [e _ []] := big_enumP. Qed. Lemma sumv_pi_nat_sum m n (P : pred nat) Vs v (V : {vspace vT}) (defV : V = (\sum_(m <= i < n | P i) Vs i)%VS) : v \in V -> \sum_(m <= i < n | P i) sumv_pi_for defV i v = v :> vT. Proof. by apply: sumv_pi_uniq_sum; apply/filter_uniq/iota_uniq. Qed. End SumvPi. Section SubVector. (* Turn a {vspace V} into a vectType *) Variable (K : fieldType) (vT : vectType K) (U : {vspace vT}). Inductive subvs_of : predArgType := Subvs u & u \in U. Definition vsval w : vT := let: Subvs u _ := w in u. HB.instance Definition _ := [isSub of subvs_of for vsval]. HB.instance Definition _ := [Choice of subvs_of by <:]. HB.instance Definition _ := [SubChoice_isSubZmodule of subvs_of by <:]. HB.instance Definition _ := [SubZmodule_isSubLmodule of subvs_of by <:]. Lemma subvsP w : vsval w \in U. Proof. exact: valP. Qed. Lemma subvs_inj : injective vsval. Proof. exact: val_inj. Qed. Lemma congr_subvs u v : u = v -> vsval u = vsval v. Proof. exact: congr1. Qed. Lemma vsval_is_linear : linear vsval. Proof. by []. Qed. HB.instance Definition _ := GRing.isSemilinear.Build K subvs_of vT _ vsval (GRing.semilinear_linear vsval_is_linear). Fact vsproj_key : unit. Proof. by []. Qed. Definition vsproj_def u := Subvs (memv_proj U u). Definition vsproj := locked_with vsproj_key vsproj_def. Canonical vsproj_unlockable := [unlockable fun vsproj]. Lemma vsprojK : {in U, cancel vsproj vsval}. Proof. by rewrite unlock; apply: projv_id. Qed. Lemma vsvalK : cancel vsval vsproj. Proof. by move=> w; apply/val_inj/vsprojK/subvsP. Qed. Lemma vsproj_is_linear : linear vsproj. Proof. by move=> k w1 w2; apply: val_inj; rewrite unlock /= linearP. Qed. HB.instance Definition _ := GRing.isSemilinear.Build K vT subvs_of _ vsproj (GRing.semilinear_linear vsproj_is_linear). Fact subvs_vect_iso : Vector.axiom (\dim U) subvs_of. Proof. exists (fun w => \row_i coord (vbasis U) i (vsval w)). by move=> k w1 w2; apply/rowP=> i; rewrite !mxE linearP. exists (fun rw : 'rV_(\dim U) => vsproj (\sum_i rw 0 i *: (vbasis U)`_i)). move=> w /=; congr (vsproj _ = w): (vsvalK w). by rewrite {1}(coord_vbasis (subvsP w)); apply: eq_bigr => i _; rewrite mxE. move=> rw; apply/rowP=> i; rewrite mxE vsprojK. by rewrite coord_sum_free ?(basis_free (vbasisP U)). by apply: rpred_sum => j _; rewrite rpredZ ?vbasis_mem ?memt_nth. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build K subvs_of subvs_vect_iso. Lemma SubvsE x (xU : x \in U) : Subvs xU = vsproj x. Proof. by apply/val_inj; rewrite /= vsprojK. Qed. End SubVector. Prenex Implicits vsval vsproj vsvalK. Arguments subvs_inj {K vT U} [x1 x2]. Arguments vsprojK {K vT U} [x] Ux. Section MatrixVectType. Variables (R : nzRingType) (m n : nat). (* The apparently useless => /= in line 1 of the proof performs some evar *) (* expansions that the Ltac interpretation of exists is incapable of doing. *) Fact matrix_vect_iso : Vector.axiom (m * n) 'M[R]_(m, n). Proof. exists mxvec => /=; first exact: linearP. by exists vec_mx; [apply: mxvecK | apply: vec_mxK]. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build _ 'M[R]_(m, n) matrix_vect_iso. Lemma dim_matrix : dim 'M[R]_(m, n) = m * n. Proof. by []. Qed. End MatrixVectType. (* A ring is a one-dimension vector space *) Section RegularVectType. Variable R : nzRingType. Fact regular_vect_iso : Vector.axiom 1 R^o. Proof. exists (fun a => a%:M) => [a b c|]; first by rewrite rmorphD scale_scalar_mx. by exists (fun A : 'M_1 => A 0 0) => [a | A]; rewrite ?mxE // -mx11_scalar. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build _ R^o regular_vect_iso. End RegularVectType. (* External direct product of two vectTypes. *) Section ProdVector. Variables (R : nzRingType) (vT1 vT2 : vectType R). Fact pair_vect_iso : Vector.axiom (dim vT1 + dim vT2) (vT1 * vT2). Proof. pose p2r (u : vT1 * vT2) := row_mx (v2r u.1) (v2r u.2). pose r2p w := (r2v (lsubmx w) : vT1, r2v (rsubmx w) : vT2). have r2pK : cancel r2p p2r by move=> w; rewrite /p2r !r2vK hsubmxK. have p2rK : cancel p2r r2p by case=> u v; rewrite /r2p row_mxKl row_mxKr !v2rK. have r2p_lin: linear r2p by move=> a u v; congr (_ , _); rewrite /= !linearP. pose r2plM := GRing.isLinear.Build _ _ _ _ r2p r2p_lin. pose r2pL : {linear _ -> _} := HB.pack r2p r2plM. by exists p2r; [apply: (@can2_linear _ _ _ r2pL) | exists r2p]. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build _ (vT1 * vT2)%type pair_vect_iso. End ProdVector. (* Function from a finType into a ring form a vectype. *) Section FunVectType. Variable (I : finType) (R : nzRingType) (vT : vectType R). (* Type unification with exist is again a problem in this proof. *) Fact ffun_vect_iso : Vector.axiom (#|I| * dim vT) {ffun I -> vT}. Proof. pose fr (f : {ffun I -> vT}) := mxvec (\matrix_(i < #|I|) v2r (f (enum_val i))). exists fr => /= [k f g|]. rewrite -linearP; congr mxvec; apply/matrixP=> i j. by rewrite !mxE !ffunE linearP !mxE. exists (fun r => [ffun i => r2v (row (enum_rank i) (vec_mx r)) : vT]) => [g|r]. by apply/ffunP=> i; rewrite ffunE mxvecK rowK v2rK enum_rankK. by apply/(canLR vec_mxK)/matrixP=> i j; rewrite mxE ffunE r2vK enum_valK mxE. Qed. HB.instance Definition _ := Lmodule_hasFinDim.Build _ {ffun I -> vT} ffun_vect_iso. End FunVectType. (* Solving a tuple of linear equations. *) Section Solver. Variable (K : fieldType) (vT : vectType K). Variables (n : nat) (lhs : n.-tuple 'End(vT)) (rhs : n.-tuple vT). Let lhsf u := finfun ((tnth lhs)^~ u). Definition vsolve_eq U := finfun (tnth rhs) \in (linfun lhsf @: U)%VS. Lemma vsolve_eqP (U : {vspace vT}) : reflect (exists2 u, u \in U & forall i, tnth lhs i u = tnth rhs i) (vsolve_eq U). Proof. have lhsZ: linear lhsf by move=> a u v; apply/ffunP=> i; rewrite !ffunE linearP. pose lhslM := GRing.isLinear.Build _ _ _ _ lhsf lhsZ. pose lhsL : {linear _ -> _} := HB.pack lhsf lhslM. apply: (iffP memv_imgP) => [] [u Uu sol_u]; exists u => //. by move=> i; rewrite -[tnth rhs i]ffunE sol_u (lfunE lhsL) ffunE. by apply/ffunP=> i; rewrite (lfunE lhsL) !ffunE sol_u. Qed. End Solver. Section lfunP. Variable (F : fieldType). Context {uT vT : vectType F}. Local Notation m := (\dim {:uT}). Local Notation n := (\dim {:vT}). Lemma span_lfunP (U : seq uT) (phi psi : 'Hom(uT,vT)) : {in <<U>>%VS, phi =1 psi} <-> {in U, phi =1 psi}. Proof. split=> eq_phi_psi u uU; first by rewrite eq_phi_psi ?memv_span. rewrite [u](@coord_span _ _ _ (in_tuple U))// !linear_sum/=. by apply: eq_bigr=> i _; rewrite 2!linearZ/= eq_phi_psi// ?mem_nth. Qed. Lemma fullv_lfunP (U : seq uT) (phi psi : 'Hom(uT,vT)) : <<U>>%VS = fullv -> phi = psi <-> {in U, phi =1 psi}. Proof. by move=> Uf; split=> [->//|/span_lfunP]; rewrite Uf=> /(_ _ (memvf _))-/lfunP. Qed. End lfunP. Module passmx. Section passmx. Variable (F : fieldType). Section vecmx. Context {vT : vectType F}. Local Notation n := (\dim {:vT}). Variables (e : n.-tuple vT). Definition rVof (v : vT) := \row_i coord e i v. Lemma rVof_linear : linear rVof. Proof. by move=> x v1 v2; apply/rowP=> i; rewrite !mxE linearP. Qed. HB.instance Definition _ := GRing.isSemilinear.Build F _ _ _ rVof (GRing.semilinear_linear rVof_linear). Lemma coord_rVof i v : coord e i v = rVof v 0 i. Proof. by rewrite !mxE. Qed. Definition vecof (v : 'rV_n) := \sum_i v 0 i *: e`_i. Lemma vecof_delta i : vecof (delta_mx 0 i) = e`_i. Proof. rewrite /vecof (bigD1 i)//= mxE !eqxx scale1r big1 ?addr0// => j neq_ji. by rewrite mxE (negPf neq_ji) andbF scale0r. Qed. Lemma vecof_linear : linear vecof. Proof. move=> x v1 v2; rewrite linear_sum -big_split/=. by apply: eq_bigr => i _/=; rewrite !mxE scalerDl scalerA. Qed. HB.instance Definition _ := GRing.isSemilinear.Build F _ _ _ vecof (GRing.semilinear_linear vecof_linear). Variable e_basis : basis_of {:vT} e. Lemma rVofK : cancel rVof vecof. Proof. move=> v; rewrite [v in RHS](coord_basis e_basis) ?memvf//. by apply: eq_bigr => i; rewrite !mxE. Qed. Lemma vecofK : cancel vecof rVof. Proof. move=> v; apply/rowP=> i; rewrite !(lfunE, mxE). by rewrite coord_sum_free ?(basis_free e_basis). Qed. Lemma rVofE (i : 'I_n) : rVof e`_i = delta_mx 0 i. Proof. apply/rowP=> k; rewrite !mxE. by rewrite eqxx coord_free ?(basis_free e_basis)// eq_sym. Qed. Lemma coord_vecof i v : coord e i (vecof v) = v 0 i. Proof. by rewrite coord_rVof vecofK. Qed. Lemma rVof_eq0 v : (rVof v == 0) = (v == 0). Proof. by rewrite -(inj_eq (can_inj vecofK)) rVofK linear0. Qed. Lemma vecof_eq0 v : (vecof v == 0) = (v == 0). Proof. by rewrite -(inj_eq (can_inj rVofK)) vecofK linear0. Qed. End vecmx. Section hommx. Context {uT vT : vectType F}. Local Notation m := (\dim {:uT}). Local Notation n := (\dim {:vT}). Variables (e : m.-tuple uT) (e' : n.-tuple vT). Definition mxof (h : 'Hom(uT, vT)) := lin1_mx (rVof e' \o h \o vecof e). Lemma mxof_linear : linear mxof. Proof. move=> x h1 h2; apply/matrixP=> i j; do !rewrite ?lfunE/= ?mxE. by rewrite linearP. Qed. HB.instance Definition _ := GRing.isSemilinear.Build F _ _ _ mxof (GRing.semilinear_linear mxof_linear). Definition funmx (M : 'M[F]_(m, n)) u := vecof e' (rVof e u *m M). Lemma funmx_linear M : linear (funmx M). Proof. by rewrite /funmx => x u v; rewrite linearP mulmxDl -scalemxAl linearP. Qed. HB.instance Definition _ M := GRing.isSemilinear.Build F _ _ _ (funmx M) (GRing.semilinear_linear (funmx_linear M)). Definition hommx M : 'Hom(uT, vT) := linfun (funmx M). Lemma hommx_linear : linear hommx. Proof. rewrite /hommx; move=> x A B; apply/lfunP=> u; do !rewrite lfunE/=. by rewrite /funmx mulmxDr -scalemxAr linearP. Qed. HB.instance Definition _ M := GRing.isSemilinear.Build F _ _ _ hommx (GRing.semilinear_linear hommx_linear). Hypothesis e_basis: basis_of {:uT} e. Hypothesis f_basis: basis_of {:vT} e'. Lemma mxofK : cancel mxof hommx. Proof. by move=> h; apply/lfunP=> u; rewrite lfunE/= /funmx mul_rV_lin1/= !rVofK. Qed. Lemma hommxK : cancel hommx mxof. Proof. move=> M; apply/matrixP => i j; rewrite !mxE/= lfunE/=. by rewrite /funmx vecofK// -rowE coord_vecof// mxE. Qed. Lemma mul_mxof phi u : u *m mxof phi = rVof e' (phi (vecof e u)). Proof. by rewrite mul_rV_lin1/=. Qed. Lemma hommxE M u : hommx M u = vecof e' (rVof e u *m M). Proof. by rewrite -[M in RHS]hommxK mul_mxof !rVofK//. Qed. Lemma rVof_mul M u : rVof e u *m M = rVof e' (hommx M u). Proof. by rewrite hommxE vecofK. Qed. Lemma hom_vecof (phi : 'Hom(uT, vT)) u : phi (vecof e u) = vecof e' (u *m mxof phi). Proof. by rewrite mul_mxof rVofK. Qed. Lemma rVof_app (phi : 'Hom(uT, vT)) u : rVof e' (phi u) = rVof e u *m mxof phi. Proof. by rewrite mul_mxof !rVofK. Qed. Lemma vecof_mul M u : vecof e' (u *m M) = hommx M (vecof e u). Proof. by rewrite hommxE vecofK. Qed. Lemma mxof_eq0 phi : (mxof phi == 0) = (phi == 0). Proof. by rewrite -(inj_eq (can_inj hommxK)) mxofK linear0. Qed. Lemma hommx_eq0 M : (hommx M == 0) = (M == 0). Proof. by rewrite -(inj_eq (can_inj mxofK)) hommxK linear0. Qed. End hommx. Section hommx_comp. Context {uT vT wT : vectType F}. Local Notation m := (\dim {:uT}). Local Notation n := (\dim {:vT}). Local Notation p := (\dim {:wT}). Variables (e : m.-tuple uT) (f : n.-tuple vT) (g : p.-tuple wT). Hypothesis e_basis: basis_of {:uT} e. Hypothesis f_basis: basis_of {:vT} f. Hypothesis g_basis: basis_of {:wT} g. Lemma mxof_comp (phi : 'Hom(uT, vT)) (psi : 'Hom(vT, wT)) : mxof e g (psi \o phi)%VF = mxof e f phi *m mxof f g psi. Proof. apply/matrixP => i k; rewrite !(mxE, comp_lfunE, lfunE) /=. rewrite [phi _](coord_basis f_basis) ?memvf// 2!linear_sum/=. by apply: eq_bigr => j _ /=; rewrite !mxE !linearZ/= !vecof_delta. Qed. Lemma hommx_mul (A : 'M_(m,n)) (B : 'M_(n, p)) : hommx e g (A *m B) = (hommx f g B \o hommx e f A)%VF. Proof. by apply: (can_inj (mxofK e_basis g_basis)); rewrite mxof_comp !hommxK. Qed. End hommx_comp. Section vsms. Context {vT : vectType F}. Local Notation n := (\dim {:vT}). Variables (e : n.-tuple vT). Definition msof (V : {vspace vT}) : 'M_n := mxof e e (projv V). (* alternative *) (* (\sum_(v <- vbasis V) <<rVof e v>>)%MS. *) Definition vsof (M : 'M[F]_n) := limg (hommx e e M). (* alternative *) (* <<[seq vecof e (row i M) | i : 'I_n]>>%VS. *) Lemma mxof1 : free e -> mxof e e \1 = 1%:M. Proof. by move=> eF; apply/matrixP=> i j; rewrite !mxE vecof_delta lfunE coord_free. Qed. Hypothesis e_basis : basis_of {:vT} e. Lemma hommx1 : hommx e e 1%:M = \1%VF. Proof. by rewrite -mxof1 ?(basis_free e_basis)// mxofK. Qed. Lemma msofK : cancel msof vsof. Proof. by rewrite /msof /vsof; move=> V; rewrite mxofK// limg_proj. Qed. Lemma mem_vecof u (V : {vspace vT}) : (vecof e u \in V) = (u <= msof V)%MS. Proof. apply/idP/submxP=> [|[v ->{u}]]; last by rewrite -hom_vecof// memv_proj. rewrite -[V in X in X -> _]msofK => /memv_imgP[v _]. by move=> /(canRL (vecofK _)) ->//; rewrite -rVof_mul//; eexists. Qed. Lemma rVof_sub u M : (rVof e u <= M)%MS = (u \in vsof M). Proof. apply/submxP/memv_imgP => [[v /(canRL (rVofK _)) ->//]|[v _ ->]]{u}. by exists (vecof e v); rewrite ?memvf// -vecof_mul. by exists (rVof e v); rewrite -rVof_mul. Qed. Lemma vsof_sub M V : (vsof M <= V)%VS = (M <= msof V)%MS. Proof. apply/subvP/rV_subP => [MsubV _/submxP[u ->]|VsubM _/memv_imgP[u _ ->]]. by rewrite -mem_vecof MsubV// -rVof_sub vecofK// submxMl. by rewrite -[V]msofK -rVof_sub VsubM// -rVof_mul// submxMl. Qed. Lemma msof_sub V M : (msof V <= M)%MS = (V <= vsof M)%VS. Proof. apply/rV_subP/subvP => [VsubM v vV|MsubV _/submxP[u ->]]. by rewrite -rVof_sub VsubM// -mem_vecof rVofK. by rewrite mul_mxof rVof_sub MsubV// memv_proj. Qed. Lemma vsofK M : (msof (vsof M) == M)%MS. Proof. by rewrite msof_sub -vsof_sub subvv. Qed. Lemma sub_msof : {mono msof : V V' / (V <= V')%VS >-> (V <= V')%MS}. Proof. by move=> V V'; rewrite msof_sub msofK. Qed. Lemma sub_vsof : {mono vsof : M M' / (M <= M')%MS >-> (M <= M')%VS}. Proof. by move=> M M'; rewrite vsof_sub (eqmxP (vsofK _)). Qed. Lemma msof0 : msof 0 = 0. Proof. apply/eqP; rewrite -submx0; apply/rV_subP => v. by rewrite -mem_vecof memv0 vecof_eq0// => /eqP->; rewrite sub0mx. Qed. Lemma vsof0 : vsof 0 = 0%VS. Proof. by apply/vspaceP=> v; rewrite memv0 -rVof_sub submx0 rVof_eq0. Qed. Lemma msof_eq0 V : (msof V == 0) = (V == 0%VS). Proof. by rewrite -(inj_eq (can_inj msofK)) msof0. Qed. Lemma vsof_eq0 M : (vsof M == 0%VS) = (M == 0). Proof. rewrite (sameP eqP eqmx0P) -!(eqmxP (vsofK M)) (sameP eqmx0P eqP) -msof0. by rewrite (inj_eq (can_inj msofK)). Qed. End vsms. Section eigen. Context {uT : vectType F}. Definition leigenspace (phi : 'End(uT)) a := lker (phi - a *: \1%VF). Definition leigenvalue phi a := leigenspace phi a != 0%VS. Local Notation m := (\dim {:uT}). Variables (e : m.-tuple uT). Hypothesis e_basis: basis_of {:uT} e. Let e_free := basis_free e_basis. Lemma lker_ker phi : lker phi = vsof e (kermx (mxof e e phi)). Proof. apply/vspaceP => v; rewrite memv_ker -rVof_sub// (sameP sub_kermxP eqP). by rewrite -rVof_app// rVof_eq0. Qed. Lemma limgE phi : limg phi = vsof e (mxof e e phi). Proof. apply/vspaceP => v; rewrite -rVof_sub//. apply/memv_imgP/submxP => [[u _ ->]|[u /(canRL (rVofK _)) ->//]]. by exists (rVof e u); rewrite -rVof_app. by exists (vecof e u); rewrite ?memvf// -hom_vecof. Qed. Lemma leigenspaceE f a : leigenspace f a = vsof e (eigenspace (mxof e e f) a). Proof. by rewrite [LHS]lker_ker linearB linearZ/= mxof1// scalemx1. Qed. End eigen. End passmx. End passmx.
Symmetric.lean
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.IteratedFDeriv import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.MeanValue import Mathlib.Analysis.Calculus.ContDiff.Basic /-! # Symmetry of the second derivative We show that, over the reals, the second derivative is symmetric. The most precise result is `Convex.second_derivative_within_at_symmetric`. It asserts that, if a function is differentiable inside a convex set `s` with nonempty interior, and has a second derivative within `s` at a point `x`, then this second derivative at `x` is symmetric. Note that this result does not require continuity of the first derivative. The following particular cases of this statement are especially relevant: `second_derivative_symmetric_of_eventually` asserts that, if a function is differentiable on a neighborhood of `x`, and has a second derivative at `x`, then this second derivative is symmetric. `second_derivative_symmetric` asserts that, if a function is differentiable, and has a second derivative at `x`, then this second derivative is symmetric. There statements are given over `ℝ` or `ℂ`, the general version being deduced from the real version. We also give statements in terms of `fderiv` and `fderivWithin`, called respectively `ContDiffAt.isSymmSndFDerivAt` and `ContDiffWithinAt.isSymmSndFDerivWithinAt` (the latter requiring that the point under consideration is accumulated by points in the interior of the set). These are written using ad hoc predicates `IsSymmSndFDerivAt` and `IsSymmSndFDerivWithinAt`, which increase readability of statements in differential geometry where they show up a lot. We also deduce statements over an arbitrary field, requiring that the function is `C^2` if the field is `ℝ` or `ℂ`, and analytic otherwise. Formally, we assume that the function is `C^n` with `minSmoothness 𝕜 2 ≤ n`, where `minSmoothness 𝕜 i` is `i` if `𝕜` is `ℝ` or `ℂ`, and `ω` otherwise. ## Implementation note For the proof, we obtain an asymptotic expansion to order two of `f (x + v + w) - f (x + v)`, by using the mean value inequality applied to a suitable function along the segment `[x + v, x + v + w]`. This expansion involves `f'' ⬝ w` as we move along a segment directed by `w` (see `Convex.taylor_approx_two_segment`). Consider the alternate sum `f (x + v + w) + f x - f (x + v) - f (x + w)`, corresponding to the values of `f` along a rectangle based at `x` with sides `v` and `w`. One can write it using the two sides directed by `w`, as `(f (x + v + w) - f (x + v)) - (f (x + w) - f x)`. Together with the previous asymptotic expansion, one deduces that it equals `f'' v w + o(1)` when `v, w` tends to `0`. Exchanging the roles of `v` and `w`, one instead gets an asymptotic expansion `f'' w v`, from which the equality `f'' v w = f'' w v` follows. In our most general statement, we only assume that `f` is differentiable inside a convex set `s`, so a few modifications have to be made. Since we don't assume continuity of `f` at `x`, we consider instead the rectangle based at `x + v + w` with sides `v` and `w`, in `Convex.isLittleO_alternate_sum_square`, but the argument is essentially the same. It only works when `v` and `w` both point towards the interior of `s`, to make sure that all the sides of the rectangle are contained in `s` by convexity. The general case follows by linearity, though. -/ open Asymptotics Set Filter open scoped Topology ContDiff section General variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E F : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] {s t : Set E} {f : E → F} {x : E} variable (𝕜) in /-- Definition recording that a function has a symmetric second derivative within a set at a point. This is automatic in most cases of interest (open sets over real or complex vector fields, or general case for analytic functions), but we can express theorems of calculus using this as a general assumption, and then specialize to these situations. -/ def IsSymmSndFDerivWithinAt (f : E → F) (s : Set E) (x : E) : Prop := ∀ v w, fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x v w = fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x w v variable (𝕜) in /-- Definition recording that a function has a symmetric second derivative at a point. This is automatic in most cases of interest (open sets over real or complex vector fields, or general case for analytic functions), but we can express theorems of calculus using this as a general assumption, and then specialize to these situations. -/ def IsSymmSndFDerivAt (f : E → F) (x : E) : Prop := ∀ v w, fderiv 𝕜 (fderiv 𝕜 f) x v w = fderiv 𝕜 (fderiv 𝕜 f) x w v protected lemma IsSymmSndFDerivWithinAt.eq (h : IsSymmSndFDerivWithinAt 𝕜 f s x) (v w : E) : fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x v w = fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x w v := h v w protected lemma IsSymmSndFDerivAt.eq (h : IsSymmSndFDerivAt 𝕜 f x) (v w : E) : fderiv 𝕜 (fderiv 𝕜 f) x v w = fderiv 𝕜 (fderiv 𝕜 f) x w v := h v w lemma fderivWithin_fderivWithin_eq_of_mem_nhdsWithin (h : t ∈ 𝓝[s] x) (hf : ContDiffWithinAt 𝕜 2 f t x) (hs : UniqueDiffOn 𝕜 s) (ht : UniqueDiffOn 𝕜 t) (hx : x ∈ s) : fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x = fderivWithin 𝕜 (fderivWithin 𝕜 f t) t x := by have A : ∀ᶠ y in 𝓝[s] x, fderivWithin 𝕜 f s y = fderivWithin 𝕜 f t y := by have : ∀ᶠ y in 𝓝[s] x, ContDiffWithinAt 𝕜 2 f t y := nhdsWithin_le_iff.2 h (nhdsWithin_mono _ (subset_insert x t) (hf.eventually (by simp))) filter_upwards [self_mem_nhdsWithin, this, eventually_eventually_nhdsWithin.2 h] with y hy h'y h''y exact fderivWithin_of_mem_nhdsWithin h''y (hs y hy) (h'y.differentiableWithinAt one_le_two) have : fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x = fderivWithin 𝕜 (fderivWithin 𝕜 f t) s x := by apply Filter.EventuallyEq.fderivWithin_eq A exact fderivWithin_of_mem_nhdsWithin h (hs x hx) (hf.differentiableWithinAt one_le_two) rw [this] apply fderivWithin_of_mem_nhdsWithin h (hs x hx) exact (hf.fderivWithin_right (m := 1) ht le_rfl (mem_of_mem_nhdsWithin hx h)).differentiableWithinAt le_rfl lemma fderivWithin_fderivWithin_eq_of_eventuallyEq (h : s =ᶠ[𝓝 x] t) : fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x = fderivWithin 𝕜 (fderivWithin 𝕜 f t) t x := calc fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x = fderivWithin 𝕜 (fderivWithin 𝕜 f t) s x := (fderivWithin_eventually_congr_set h).fderivWithin_eq_of_nhds _ = fderivWithin 𝕜 (fderivWithin 𝕜 f t) t x := fderivWithin_congr_set h lemma fderivWithin_fderivWithin_eq_of_mem_nhds {f : E → F} {x : E} {s : Set E} (h : s ∈ 𝓝 x) : fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x = fderiv 𝕜 (fderiv 𝕜 f) x := by simp only [← fderivWithin_univ] apply fderivWithin_fderivWithin_eq_of_eventuallyEq simp [h] @[simp] lemma isSymmSndFDerivWithinAt_univ : IsSymmSndFDerivWithinAt 𝕜 f univ x ↔ IsSymmSndFDerivAt 𝕜 f x := by simp [IsSymmSndFDerivWithinAt, IsSymmSndFDerivAt] theorem IsSymmSndFDerivWithinAt.mono_of_mem_nhdsWithin (h : IsSymmSndFDerivWithinAt 𝕜 f t x) (hst : t ∈ 𝓝[s] x) (hf : ContDiffWithinAt 𝕜 2 f t x) (hs : UniqueDiffOn 𝕜 s) (ht : UniqueDiffOn 𝕜 t) (hx : x ∈ s) : IsSymmSndFDerivWithinAt 𝕜 f s x := by intro v w rw [fderivWithin_fderivWithin_eq_of_mem_nhdsWithin hst hf hs ht hx] exact h v w theorem IsSymmSndFDerivWithinAt.congr_set (h : IsSymmSndFDerivWithinAt 𝕜 f s x) (hst : s =ᶠ[𝓝 x] t) : IsSymmSndFDerivWithinAt 𝕜 f t x := by intro v w rw [fderivWithin_fderivWithin_eq_of_eventuallyEq hst.symm] exact h v w theorem isSymmSndFDerivWithinAt_congr_set (hst : s =ᶠ[𝓝 x] t) : IsSymmSndFDerivWithinAt 𝕜 f s x ↔ IsSymmSndFDerivWithinAt 𝕜 f t x := ⟨fun h ↦ h.congr_set hst, fun h ↦ h.congr_set hst.symm⟩ theorem IsSymmSndFDerivAt.isSymmSndFDerivWithinAt (h : IsSymmSndFDerivAt 𝕜 f x) (hf : ContDiffAt 𝕜 2 f x) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : IsSymmSndFDerivWithinAt 𝕜 f s x := by simp only [← isSymmSndFDerivWithinAt_univ, ← contDiffWithinAt_univ] at h hf exact h.mono_of_mem_nhdsWithin univ_mem hf hs uniqueDiffOn_univ hx theorem isSymmSndFDerivWithinAt_iff_iteratedFDerivWithin (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : IsSymmSndFDerivWithinAt 𝕜 f s x ↔ (iteratedFDerivWithin 𝕜 2 f s x).domDomCongr Fin.revPerm = iteratedFDerivWithin 𝕜 2 f s x := by simp_rw [IsSymmSndFDerivWithinAt, ContinuousMultilinearMap.ext_iff, Fin.forall_fin_succ_pi, Fin.forall_fin_zero_pi] simp [iteratedFDerivWithin_two_apply f hs hx, eq_comm] theorem isSymmSndFDerivAt_iff_iteratedFDeriv : IsSymmSndFDerivAt 𝕜 f x ↔ (iteratedFDeriv 𝕜 2 f x).domDomCongr Fin.revPerm = iteratedFDeriv 𝕜 2 f x := by simp only [← isSymmSndFDerivWithinAt_univ, ← iteratedFDerivWithin_univ] exact isSymmSndFDerivWithinAt_iff_iteratedFDerivWithin uniqueDiffOn_univ (mem_univ _) theorem IsSymmSndFDerivWithinAt.iteratedFDerivWithin_cons {x v w : E} {hf : IsSymmSndFDerivWithinAt 𝕜 f s x} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 2 f s x ![v, w] = iteratedFDerivWithin 𝕜 2 f s x ![w, v] := by simp_rw [isSymmSndFDerivWithinAt_iff_iteratedFDerivWithin hs hx, ContinuousMultilinearMap.ext_iff, ContinuousMultilinearMap.domDomCongr_apply] at hf convert hf ![w, v] using 2 ext i fin_cases i <;> simp theorem IsSymmSndFDerivAt.iteratedFDeriv_cons {x v w : E} {hf : IsSymmSndFDerivAt 𝕜 f x} : iteratedFDeriv 𝕜 2 f x ![v, w] = iteratedFDeriv 𝕜 2 f x ![w, v] := by simp only [← isSymmSndFDerivWithinAt_univ, ← iteratedFDerivWithin_univ] at * exact hf.iteratedFDerivWithin_cons uniqueDiffOn_univ (mem_univ _) /-- If a function is analytic within a set at a point, then its second derivative is symmetric. -/ theorem ContDiffWithinAt.isSymmSndFDerivWithinAt_of_omega (hf : ContDiffWithinAt 𝕜 ω f s x) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : IsSymmSndFDerivWithinAt 𝕜 f s x := by rw [isSymmSndFDerivWithinAt_iff_iteratedFDerivWithin hs hx] exact hf.domDomCongr_iteratedFDerivWithin hs hx _ /-- If a function is analytic at a point, then its second derivative is symmetric. -/ theorem ContDiffAt.isSymmSndFDerivAt_of_omega (hf : ContDiffAt 𝕜 ω f x) : IsSymmSndFDerivAt 𝕜 f x := by simp only [← isSymmSndFDerivWithinAt_univ, ← contDiffWithinAt_univ] at hf ⊢ exact hf.isSymmSndFDerivWithinAt_of_omega uniqueDiffOn_univ (mem_univ _) end General section Real variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {s : Set E} (s_conv : Convex ℝ s) {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ x ∈ interior s, HasFDerivAt f (f' x) x) {x : E} (xs : x ∈ s) (hx : HasFDerivWithinAt f' f'' (interior s) x) section include s_conv hf xs hx /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one can Taylor-expand to order two the function `f` on the segment `[x + h v, x + h (v + w)]`, giving a bilinear estimate for `f (x + hv + hw) - f (x + hv)` in terms of `f' w` and of `f'' ⬝ w`, up to `o(h^2)`. This is a technical statement used to show that the second derivative is symmetric. -/ theorem Convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s) (hw : x + v + w ∈ interior s) : (fun h : ℝ => f (x + h • v + h • w) - f (x + h • v) - h • f' x w - h ^ 2 • f'' v w - (h ^ 2 / 2) • f'' w w) =o[𝓝[>] 0] fun h => h ^ 2 := by -- it suffices to check that the expression is bounded by `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2` for -- small enough `h`, for any positive `ε`. refine IsLittleO.trans_isBigO (isLittleO_iff.2 fun ε εpos => ?_) (isBigO_const_mul_self ((‖v‖ + ‖w‖) * ‖w‖) _ _) -- consider a ball of radius `δ` around `x` in which the Taylor approximation for `f''` is -- good up to `δ`. rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff] at hx rcases Metric.mem_nhdsWithin_iff.1 (hx εpos) with ⟨δ, δpos, sδ⟩ have E1 : ∀ᶠ h in 𝓝[>] (0 : ℝ), h * (‖v‖ + ‖w‖) < δ := by have : Filter.Tendsto (fun h => h * (‖v‖ + ‖w‖)) (𝓝[>] (0 : ℝ)) (𝓝 (0 * (‖v‖ + ‖w‖))) := (continuous_id.mul continuous_const).continuousWithinAt apply (tendsto_order.1 this).2 δ simpa only [zero_mul] using δpos have E2 : ∀ᶠ h in 𝓝[>] (0 : ℝ), (h : ℝ) < 1 := mem_nhdsWithin_of_mem_nhds <| Iio_mem_nhds zero_lt_one filter_upwards [E1, E2, self_mem_nhdsWithin] with h hδ h_lt_1 hpos -- we consider `h` small enough that all points under consideration belong to this ball, -- and also with `0 < h < 1`. replace hpos : 0 < h := hpos have xt_mem : ∀ t ∈ Icc (0 : ℝ) 1, x + h • v + (t * h) • w ∈ interior s := by intro t ht have : x + h • v ∈ interior s := s_conv.add_smul_mem_interior xs hv ⟨hpos, h_lt_1.le⟩ rw [← smul_smul] apply s_conv.interior.add_smul_mem this _ ht rw [add_assoc] at hw convert s_conv.add_smul_mem_interior xs hw ⟨hpos, h_lt_1.le⟩ using 1 module -- define a function `g` on `[0,1]` (identified with `[v, v + w]`) such that `g 1 - g 0` is the -- quantity to be estimated. We will check that its derivative is given by an explicit -- expression `g'`, that we can bound. Then the desired bound for `g 1 - g 0` follows from the -- mean value inequality. let g t := f (x + h • v + (t * h) • w) - (t * h) • f' x w - (t * h ^ 2) • f'' v w - ((t * h) ^ 2 / 2) • f'' w w set g' := fun t => f' (x + h • v + (t * h) • w) (h • w) - h • f' x w - h ^ 2 • f'' v w - (t * h ^ 2) • f'' w w with hg' -- check that `g'` is the derivative of `g`, by a straightforward computation have g_deriv : ∀ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt g (g' t) (Icc 0 1) t := by intro t ht apply_rules [HasDerivWithinAt.sub, HasDerivWithinAt.add] · refine (hf _ ?_).comp_hasDerivWithinAt _ ?_ · exact xt_mem t ht apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.const_add, HasDerivAt.smul_const, hasDerivAt_mul_const] · apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_mul_const] · apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_mul_const] · suffices H : HasDerivWithinAt (fun u => ((u * h) ^ 2 / 2) • f'' w w) ((((2 : ℕ) : ℝ) * (t * h) ^ (2 - 1) * (1 * h) / 2) • f'' w w) (Icc 0 1) t by convert H using 2 ring apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_id', HasDerivAt.pow, HasDerivAt.mul_const] -- check that `g'` is uniformly bounded, with a suitable bound `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2`. have g'_bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖g' t‖ ≤ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by intro t ht have I : ‖h • v + (t * h) • w‖ ≤ h * (‖v‖ + ‖w‖) := calc ‖h • v + (t * h) • w‖ ≤ ‖h • v‖ + ‖(t * h) • w‖ := norm_add_le _ _ _ = h * ‖v‖ + t * (h * ‖w‖) := by simp only [norm_smul, Real.norm_eq_abs, hpos.le, abs_of_nonneg, abs_mul, ht.left, mul_assoc] _ ≤ h * ‖v‖ + 1 * (h * ‖w‖) := by gcongr; exact ht.2.le _ = h * (‖v‖ + ‖w‖) := by ring calc ‖g' t‖ = ‖(f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)) (h • w)‖ := by rw [hg'] congrm ‖?_‖ simp only [ContinuousLinearMap.sub_apply, ContinuousLinearMap.add_apply, ContinuousLinearMap.smul_apply, map_add, map_smul] module _ ≤ ‖f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)‖ * ‖h • w‖ := (ContinuousLinearMap.le_opNorm _ _) _ ≤ ε * ‖h • v + (t * h) • w‖ * ‖h • w‖ := by gcongr have H : x + h • v + (t * h) • w ∈ Metric.ball x δ ∩ interior s := by refine ⟨?_, xt_mem t ⟨ht.1, ht.2.le⟩⟩ rw [add_assoc, add_mem_ball_iff_norm] exact I.trans_lt hδ simpa only [mem_setOf_eq, add_assoc x, add_sub_cancel_left] using sδ H _ ≤ ε * (‖h • v‖ + ‖h • w‖) * ‖h • w‖ := by gcongr apply (norm_add_le _ _).trans gcongr simp only [norm_smul, Real.norm_eq_abs, abs_mul, abs_of_nonneg, ht.1, hpos.le, mul_assoc] exact mul_le_of_le_one_left (by positivity) ht.2.le _ = ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by simp only [norm_smul, Real.norm_eq_abs, abs_of_nonneg, hpos.le]; ring -- conclude using the mean value inequality have I : ‖g 1 - g 0‖ ≤ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by simpa only [mul_one, sub_zero] using norm_image_sub_le_of_norm_deriv_le_segment' g_deriv g'_bound 1 (right_mem_Icc.2 zero_le_one) convert I using 1 · congr 1 simp only [g, add_zero, one_mul, zero_div, zero_mul, sub_zero, zero_smul, Ne, not_false_iff, zero_pow, reduceCtorEq] abel · simp (discharger := positivity) only [Real.norm_eq_abs, abs_of_nonneg] ring /-- One can get `f'' v w` as the limit of `h ^ (-2)` times the alternate sum of the values of `f` along the vertices of a quadrilateral with sides `h v` and `h w` based at `x`. In a setting where `f` is not guaranteed to be continuous at `f`, we can still get this if we use a quadrilateral based at `h v + h w`. -/ theorem Convex.isLittleO_alternate_sum_square {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : (fun h : ℝ => f (x + h • (2 • v + 2 • w)) + f (x + h • (v + w)) - f (x + h • (2 • v + w)) - f (x + h • (v + 2 • w)) - h ^ 2 • f'' v w) =o[𝓝[>] 0] fun h => h ^ 2 := by have A : (1 : ℝ) / 2 ∈ Ioc (0 : ℝ) 1 := ⟨by simp, by norm_num⟩ have B : (1 : ℝ) / 2 ∈ Icc (0 : ℝ) 1 := ⟨by simp, by norm_num⟩ have h2v2w : x + (2 : ℝ) • v + (2 : ℝ) • w ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h4v h4w B using 1 module have h2vww : x + (2 • v + w) + w ∈ interior s := by convert h2v2w using 1 module have h2v : x + (2 : ℝ) • v ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h4v A using 1 module have h2w : x + (2 : ℝ) • w ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h4w A using 1 module have hvw : x + (v + w) ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h2v2w A using 1 module have h2vw : x + (2 • v + w) ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h2v h2v2w B using 1 module have hvww : x + (v + w) + w ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h2w h2v2w B using 1 module have TA1 := s_conv.taylor_approx_two_segment hf xs hx h2vw h2vww have TA2 := s_conv.taylor_approx_two_segment hf xs hx hvw hvww convert TA1.sub TA2 using 1 ext h simp only [two_smul, smul_add, ← add_assoc, ContinuousLinearMap.map_add, ContinuousLinearMap.add_apply] abel /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one has `f'' v w = f'' w v`. Superseded by `Convex.second_derivative_within_at_symmetric`, which removes the assumption that `v` and `w` point inside `s`. -/ theorem Convex.second_derivative_within_at_symmetric_of_mem_interior {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : f'' w v = f'' v w := by have A : (fun h : ℝ => h ^ 2 • (f'' w v - f'' v w)) =o[𝓝[>] 0] fun h => h ^ 2 := by convert (s_conv.isLittleO_alternate_sum_square hf xs hx h4v h4w).sub (s_conv.isLittleO_alternate_sum_square hf xs hx h4w h4v) using 1 ext h simp only [add_comm, smul_add, smul_sub] abel have B : (fun _ : ℝ => f'' w v - f'' v w) =o[𝓝[>] 0] fun _ => (1 : ℝ) := by have : (fun h : ℝ => 1 / h ^ 2) =O[𝓝[>] 0] fun h => 1 / h ^ 2 := isBigO_refl _ _ have C := this.smul_isLittleO A apply C.congr' _ _ · filter_upwards [self_mem_nhdsWithin] intro h (hpos : 0 < h) match_scalars <;> field_simp · filter_upwards [self_mem_nhdsWithin] with h (hpos : 0 < h) field_simp simpa only [sub_eq_zero] using isLittleO_const_const_iff.1 B end /-- If a function is differentiable inside a convex set with nonempty interior, and has a second derivative at a point of this convex set, then this second derivative is symmetric. -/ theorem Convex.second_derivative_within_at_symmetric {s : Set E} (s_conv : Convex ℝ s) (hne : (interior s).Nonempty) {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ x ∈ interior s, HasFDerivAt f (f' x) x) {x : E} (xs : x ∈ s) (hx : HasFDerivWithinAt f' f'' (interior s) x) (v w : E) : f'' v w = f'' w v := by /- we work around a point `x + 4 z` in the interior of `s`. For any vector `m`, then `x + 4 (z + t m)` also belongs to the interior of `s` for small enough `t`. This means that we will be able to apply `second_derivative_within_at_symmetric_of_mem_interior` to show that `f''` is symmetric, after cancelling all the contributions due to `z`. -/ rcases hne with ⟨y, hy⟩ obtain ⟨z, hz⟩ : ∃ z, z = ((1 : ℝ) / 4) • (y - x) := ⟨((1 : ℝ) / 4) • (y - x), rfl⟩ have A : ∀ m : E, Filter.Tendsto (fun t : ℝ => x + (4 : ℝ) • (z + t • m)) (𝓝 0) (𝓝 y) := by intro m have : x + (4 : ℝ) • (z + (0 : ℝ) • m) = y := by simp [hz] rw [← this] refine tendsto_const_nhds.add <| tendsto_const_nhds.smul <| tendsto_const_nhds.add ?_ exact continuousAt_id.smul continuousAt_const have B : ∀ m : E, ∀ᶠ t in 𝓝[>] (0 : ℝ), x + (4 : ℝ) • (z + t • m) ∈ interior s := by intro m apply nhdsWithin_le_nhds apply A m rw [mem_interior_iff_mem_nhds] at hy exact interior_mem_nhds.2 hy -- we choose `t m > 0` such that `x + 4 (z + (t m) m)` belongs to the interior of `s`, for any -- vector `m`. choose t ts tpos using fun m => ((B m).and self_mem_nhdsWithin).exists -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z` -- and `z + (t m) m`, we deduce that `f'' m z = f'' z m` for all `m`. have C : ∀ m : E, f'' m z = f'' z m := by intro m have : f'' (z + t m • m) (z + t 0 • (0 : E)) = f'' (z + t 0 • (0 : E)) (z + t m • m) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts 0) (ts m) simp only [ContinuousLinearMap.map_add, ContinuousLinearMap.map_smul, add_right_inj, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', add_zero, smul_zero] at this exact smul_right_injective F (tpos m).ne' this -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z + (t v) v` -- and `z + (t w) w`, we deduce that `f'' v w = f'' w v`. Cross terms involving `z` can be -- eliminated thanks to the fact proved above that `f'' m z = f'' z m`. have : f'' (z + t v • v) (z + t w • w) = f'' (z + t w • w) (z + t v • v) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts w) (ts v) simp only [ContinuousLinearMap.map_add, ContinuousLinearMap.map_smul, smul_smul, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', C] at this have : (t v * t w) • (f'' v) w = (t v * t w) • (f'' w) v := by linear_combination (norm := module) this apply smul_right_injective F _ this simp [(tpos v).ne', (tpos w).ne'] /-- If a function is differentiable around `x`, and has two derivatives at `x`, then the second derivative is symmetric. Version over `ℝ`. See `second_derivative_symmetric_of_eventually` for a version over `ℝ` or `ℂ`. -/ theorem second_derivative_symmetric_of_eventually_of_real {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ᶠ y in 𝓝 x, HasFDerivAt f (f' y) y) (hx : HasFDerivAt f' f'' x) (v w : E) : f'' v w = f'' w v := by rcases Metric.mem_nhds_iff.1 hf with ⟨ε, εpos, hε⟩ have A : (interior (Metric.ball x ε)).Nonempty := by rwa [Metric.isOpen_ball.interior_eq, Metric.nonempty_ball] exact Convex.second_derivative_within_at_symmetric (convex_ball x ε) A (fun y hy => hε (interior_subset hy)) (Metric.mem_ball_self εpos) hx.hasFDerivWithinAt v w end Real section IsRCLikeNormedField variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E F : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] {s : Set E} {f : E → F} {x : E} theorem second_derivative_symmetric_of_eventually [IsRCLikeNormedField 𝕜] {f' : E → E →L[𝕜] F} {x : E} {f'' : E →L[𝕜] E →L[𝕜] F} (hf : ∀ᶠ y in 𝓝 x, HasFDerivAt f (f' y) y) (hx : HasFDerivAt f' f'' x) (v w : E) : f'' v w = f'' w v := by let _ := IsRCLikeNormedField.rclike 𝕜 let _ : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ 𝕜 E let _ : NormedSpace ℝ F := NormedSpace.restrictScalars ℝ 𝕜 F let _ : LinearMap.CompatibleSMul E F ℝ 𝕜 := LinearMap.IsScalarTower.compatibleSMul let _ : LinearMap.CompatibleSMul E (E →L[𝕜] F) ℝ 𝕜 := LinearMap.IsScalarTower.compatibleSMul let f'R : E → E →L[ℝ] F := fun x ↦ (f' x).restrictScalars ℝ have hfR : ∀ᶠ y in 𝓝 x, HasFDerivAt f (f'R y) y := by filter_upwards [hf] with y hy using HasFDerivAt.restrictScalars ℝ hy let f''Rl : E →ₗ[ℝ] E →ₗ[ℝ] F := { toFun := fun x ↦ { toFun := fun y ↦ f'' x y map_add' := by simp map_smul' := by simp } map_add' := by intros; ext; simp map_smul' := by intros; ext; simp } let f''R : E →L[ℝ] E →L[ℝ] F := by refine LinearMap.mkContinuous₂ f''Rl (‖f''‖) (fun x y ↦ ?_) simp only [LinearMap.coe_mk, AddHom.coe_mk, f''Rl] exact ContinuousLinearMap.le_opNorm₂ f'' x y have : HasFDerivAt f'R f''R x := by simp only [hasFDerivAt_iff_tendsto] at hx ⊢ exact hx change f''R v w = f''R w v exact second_derivative_symmetric_of_eventually_of_real hfR this v w /-- If a function is differentiable, and has two derivatives at `x`, then the second derivative is symmetric. -/ theorem second_derivative_symmetric [IsRCLikeNormedField 𝕜] {f' : E → E →L[𝕜] F} {f'' : E →L[𝕜] E →L[𝕜] F} {x : E} (hf : ∀ y, HasFDerivAt f (f' y) y) (hx : HasFDerivAt f' f'' x) (v w : E) : f'' v w = f'' w v := second_derivative_symmetric_of_eventually (Filter.Eventually.of_forall hf) hx v w open scoped Classical in variable (𝕜) in /-- `minSmoothness 𝕜 n` is the minimal smoothness exponent larger than or equal to `n` for which one can do serious calculus in `𝕜`. If `𝕜` is `ℝ` or `ℂ`, this is just `n`. Otherwise, this is `ω` as only analytic functions are well behaved on `ℚₚ`, say. -/ noncomputable irreducible_def minSmoothness (n : WithTop ℕ∞) := if IsRCLikeNormedField 𝕜 then n else ω @[simp] lemma minSmoothness_of_isRCLikeNormedField [h : IsRCLikeNormedField 𝕜] {n : WithTop ℕ∞} : minSmoothness 𝕜 n = n := by simp [minSmoothness, h] lemma le_minSmoothness {n : WithTop ℕ∞} : n ≤ minSmoothness 𝕜 n := by simp only [minSmoothness] split_ifs <;> simp lemma minSmoothness_add {n m : WithTop ℕ∞} : minSmoothness 𝕜 (n + m) = minSmoothness 𝕜 n + m := by simp only [minSmoothness] split_ifs <;> simp lemma minSmoothness_monotone : Monotone (minSmoothness 𝕜) := by intro m n hmn simp only [minSmoothness] split_ifs <;> simp [hmn] @[simp] lemma minSmoothness_eq_infty {n : WithTop ℕ∞} : minSmoothness 𝕜 n = ∞ ↔ (n = ∞ ∧ IsRCLikeNormedField 𝕜) := by simp only [minSmoothness] split_ifs with h <;> simp [h] /-- If `minSmoothness 𝕜 m ≤ n` for some (finite) integer `m`, then one can find `n' ∈ [minSmoothness 𝕜 m, n]` which is not `∞`: over `ℝ` or `ℂ`, just take `m`, and otherwise just take `ω`. The interest of this technical lemma is that, if a function is `C^{n'}` at a point for `n' ≠ ∞`, then it is `C^{n'}` on a neighborhood of the point (this property fails only in `C^∞` smoothness, see `ContDiffWithinAt.contDiffOn`). -/ lemma exist_minSmoothness_le_ne_infty {n : WithTop ℕ∞} {m : ℕ} (hm : minSmoothness 𝕜 m ≤ n) : ∃ n', minSmoothness 𝕜 m ≤ n' ∧ n' ≤ n ∧ n' ≠ ∞ := by simp only [minSmoothness] at hm ⊢ split_ifs with h · simp only [h, ↓reduceIte] at hm exact ⟨m, le_rfl, hm, by simp⟩ · simp only [h, ↓reduceIte, top_le_iff] at hm refine ⟨ω, le_rfl, by simp [hm], by simp⟩ /-- If a function is `C^2` at a point, then its second derivative there is symmetric. Over a field different from `ℝ` or `ℂ`, we should require that the function is analytic. -/ theorem ContDiffAt.isSymmSndFDerivAt {n : WithTop ℕ∞} (hf : ContDiffAt 𝕜 n f x) (hn : minSmoothness 𝕜 2 ≤ n) : IsSymmSndFDerivAt 𝕜 f x := by by_cases h : IsRCLikeNormedField 𝕜 -- First deal with the `ℝ` or `ℂ` case, where `C^2` is enough. · intro v w apply second_derivative_symmetric_of_eventually (f := f) (f' := fderiv 𝕜 f) (x := x) · obtain ⟨u, hu, h'u⟩ : ∃ u ∈ 𝓝 x, ContDiffOn 𝕜 2 f u := (hf.of_le hn).contDiffOn (m := 2) le_minSmoothness (by simp) rcases mem_nhds_iff.1 hu with ⟨v, vu, v_open, xv⟩ filter_upwards [v_open.mem_nhds xv] with y hy have : DifferentiableAt 𝕜 f y := by have := (h'u.mono vu y hy).contDiffAt (v_open.mem_nhds hy) exact this.differentiableAt one_le_two exact DifferentiableAt.hasFDerivAt this · have : DifferentiableAt 𝕜 (fderiv 𝕜 f) x := by apply ContDiffAt.differentiableAt _ le_rfl exact hf.fderiv_right (le_minSmoothness.trans hn) exact DifferentiableAt.hasFDerivAt this -- then deal with the case of an arbitrary field, with analytic functions. · simp only [minSmoothness, h, ↓reduceIte, top_le_iff] at hn apply ContDiffAt.isSymmSndFDerivAt_of_omega simpa [hn] using hf /-- If a function is `C^2` within a set at a point, and accumulated by points in the interior of the set, then its second derivative there is symmetric. Over a field different from `ℝ` or `ℂ`, we should require that the function is analytic. -/ theorem ContDiffWithinAt.isSymmSndFDerivWithinAt {n : WithTop ℕ∞} (hf : ContDiffWithinAt 𝕜 n f s x) (hn : minSmoothness 𝕜 2 ≤ n) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ closure (interior s)) (h'x : x ∈ s) : IsSymmSndFDerivWithinAt 𝕜 f s x := by /- We argue that, at interior points, the second derivative is symmetric, and moreover by continuity it converges to the second derivative at `x`. Therefore, the latter is also symmetric. -/ obtain ⟨m, hm, hmn, m_ne⟩ := exist_minSmoothness_le_ne_infty hn rcases (hf.of_le hmn).contDiffOn' le_rfl (by simp [m_ne]) with ⟨u, u_open, xu, hu⟩ simp only [insert_eq_of_mem h'x] at hu have h'u : UniqueDiffOn 𝕜 (s ∩ u) := hs.inter u_open obtain ⟨y, hy, y_lim⟩ : ∃ y, (∀ (n : ℕ), y n ∈ interior s) ∧ Tendsto y atTop (𝓝 x) := mem_closure_iff_seq_limit.1 hx have L : ∀ᶠ k in atTop, y k ∈ u := y_lim (u_open.mem_nhds xu) have I : ∀ᶠ k in atTop, IsSymmSndFDerivWithinAt 𝕜 f s (y k) := by filter_upwards [L] with k hk have s_mem : s ∈ 𝓝 (y k) := by apply mem_of_superset (isOpen_interior.mem_nhds (hy k)) exact interior_subset have : IsSymmSndFDerivAt 𝕜 f (y k) := by apply ContDiffAt.isSymmSndFDerivAt _ (n := m) hm apply (hu (y k) ⟨(interior_subset (hy k)), hk⟩).contDiffAt exact inter_mem s_mem (u_open.mem_nhds hk) intro v w rw [fderivWithin_fderivWithin_eq_of_mem_nhds s_mem] exact this v w have A : ContinuousOn (fderivWithin 𝕜 (fderivWithin 𝕜 f s) s) (s ∩ u) := by have : ContinuousOn (fderivWithin 𝕜 (fderivWithin 𝕜 f (s ∩ u)) (s ∩ u)) (s ∩ u) := ((hu.fderivWithin h'u (m := 1) (le_minSmoothness.trans hm)).fderivWithin h'u (m := 0) le_rfl).continuousOn apply this.congr intro y hy apply fderivWithin_fderivWithin_eq_of_eventuallyEq filter_upwards [u_open.mem_nhds hy.2] with z hz change (z ∈ s) = (z ∈ s ∩ u) aesop have B : Tendsto (fun k ↦ fderivWithin 𝕜 (fderivWithin 𝕜 f s) s (y k)) atTop (𝓝 (fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x)) := by have : Tendsto y atTop (𝓝[s ∩ u] x) := by apply tendsto_nhdsWithin_iff.2 ⟨y_lim, ?_⟩ filter_upwards [L] with k hk using ⟨interior_subset (hy k), hk⟩ exact (A x ⟨h'x, xu⟩ ).tendsto.comp this have C (v w : E) : Tendsto (fun k ↦ fderivWithin 𝕜 (fderivWithin 𝕜 f s) s (y k) v w) atTop (𝓝 (fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x v w)) := by have : Continuous (fun (A : E →L[𝕜] E →L[𝕜] F) ↦ A v w) := by fun_prop exact (this.tendsto _).comp B have C' (v w : E) : Tendsto (fun k ↦ fderivWithin 𝕜 (fderivWithin 𝕜 f s) s (y k) w v) atTop (𝓝 (fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x v w)) := by apply (C v w).congr' filter_upwards [I] with k hk using hk v w intro v w exact tendsto_nhds_unique (C v w) (C' w v) end IsRCLikeNormedField
alt.v
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *) (* Distributed under the terms of CeCILL-B. *) From HB Require Import structures. From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice. From mathcomp Require Import div fintype tuple tuple bigop prime finset ssralg. From mathcomp Require Import zmodp fingroup morphism perm automorphism quotient. From mathcomp Require Import action cyclic pgroup gseries sylow. From mathcomp Require Import primitive_action nilpotent maximal. (******************************************************************************) (* Definitions of the symmetric and alternate groups, and some properties. *) (* 'Sym_T == The symmetric group over type T (which must have a finType *) (* structure). *) (* := [set: {perm T}] *) (* 'Alt_T == The alternating group over type T. *) (******************************************************************************) Unset Printing Implicit Defensive. Set Implicit Arguments. Unset Strict Implicit. Import GroupScope GRing. HB.instance Definition _ := isMulGroup.Build bool addbA addFb addbb. Section SymAltDef. Variable T : finType. Implicit Types (s : {perm T}) (x y z : T). (** Definitions of the alternate groups and some Properties **) Definition Sym : {set {perm T}} := setT. Canonical Sym_group := Eval hnf in [group of Sym]. Local Notation "'Sym_T" := Sym. Canonical sign_morph := @Morphism _ _ 'Sym_T _ (in2W (@odd_permM _)). Definition Alt := 'ker (@odd_perm T). Canonical Alt_group := Eval hnf in [group of Alt]. Local Notation "'Alt_T" := Alt. Lemma Alt_even p : (p \in 'Alt_T) = ~~ p. Proof. by rewrite !inE /=; case: odd_perm. Qed. Lemma Alt_subset : 'Alt_T \subset 'Sym_T. Proof. exact: subsetT. Qed. Lemma Alt_normal : 'Alt_T <| 'Sym_T. Proof. exact: ker_normal. Qed. Lemma Alt_norm : 'Sym_T \subset 'N('Alt_T). Proof. by case/andP: Alt_normal. Qed. Let n := #|T|. Lemma Alt_index : 1 < n -> #|'Sym_T : 'Alt_T| = 2. Proof. move=> lt1n; rewrite -card_quotient ?Alt_norm //=. have : ('Sym_T / 'Alt_T) \isog (@odd_perm T @* 'Sym_T) by apply: first_isog. case/isogP=> g /injmP/card_in_imset <-. rewrite /morphim setIid=> ->; rewrite -card_bool; apply: eq_card => b. apply/imsetP; case: b => /=; last first. by exists (1 : {perm T}); [rewrite setIid inE | rewrite odd_perm1]. case: (pickP T) lt1n => [x1 _ | d0]; last by rewrite /n eq_card0. rewrite /n (cardD1 x1) ltnS lt0n => /existsP[x2 /=]. by rewrite eq_sym andbT -odd_tperm; exists (tperm x1 x2); rewrite ?inE. Qed. Lemma card_Sym : #|'Sym_T| = n`!. Proof. rewrite -[n]cardsE -card_perm; apply: eq_card => p. by apply/idP/subsetP=> [? ?|]; rewrite !inE. Qed. Lemma card_Alt : 1 < n -> (2 * #|'Alt_T|)%N = n`!. Proof. by move/Alt_index <-; rewrite mulnC (Lagrange Alt_subset) card_Sym. Qed. Lemma Sym_trans : [transitive^n 'Sym_T, on setT | 'P]. Proof. apply/imsetP; pose t1 := [tuple of enum T]. have dt1: t1 \in n.-dtuple(setT) by rewrite inE enum_uniq; apply/subsetP. exists t1 => //; apply/setP=> t; apply/idP/imsetP=> [|[a _ ->{t}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> x; rewrite !inE. case/dtuple_onP=> injt _; have injf := inj_comp injt enum_rank_inj. exists (perm injf); first by rewrite inE. apply: eq_from_tnth => i; rewrite tnth_map /= [aperm _ _]permE; congr tnth. by rewrite (tnth_nth (enum_default i)) enum_valK. Qed. Lemma Alt_trans : [transitive^n.-2 'Alt_T, on setT | 'P]. Proof. case n_m2: n Sym_trans => [|[|m]] /= tr_m2; try exact: ntransitive0. have tr_m := ntransitive_weak (leqW (leqnSn m)) tr_m2. case/imsetP: tr_m2; case/tupleP=> x; case/tupleP=> y t. rewrite !dtuple_on_add 2![x \in _]inE inE negb_or /= -!andbA. case/and4P=> nxy ntx nty dt _; apply/imsetP; exists t => //; apply/setP=> u. apply/idP/imsetP=> [|[a _ ->{u}]]; last first. by apply: n_act_dtuple => //; apply/astabsP=> z; rewrite !inE. case/(atransP2 tr_m dt)=> /= a _ ->{u}. case odd_a: (odd_perm a); last by exists a => //; rewrite !inE /= odd_a. exists (tperm x y * a); first by rewrite !inE /= odd_permM odd_tperm nxy odd_a. apply/val_inj/eq_in_map => z tz; rewrite actM /= /aperm; congr (a _). by case: tpermP ntx nty => // <-; rewrite tz. Qed. Lemma aperm_faithful (A : {group {perm T}}) : [faithful A, on setT | 'P]. Proof. by apply/faithfulP=> /= p _ np1; apply/eqP/perm_act1P=> y; rewrite np1 ?inE. Qed. End SymAltDef. Arguments Sym T%_type. Arguments Sym_group T%_type. Arguments Alt T%_type. Arguments Alt_group T%_type. Notation "''Sym_' T" := (Sym T) (at level 8, T at level 2, format "''Sym_' T") : group_scope. Notation "''Sym_' T" := (Sym_group T) : Group_scope. Notation "''Alt_' T" := (Alt T) (at level 8, T at level 2, format "''Alt_' T") : group_scope. Notation "''Alt_' T" := (Alt_group T) : Group_scope. Lemma trivial_Alt_2 (T : finType) : #|T| <= 2 -> 'Alt_T = 1. Proof. rewrite leq_eqVlt => /predU1P[] oT. by apply: card_le1_trivg; rewrite -leq_double -mul2n card_Alt oT. suffices Sym1: 'Sym_T = 1 by apply/trivgP; rewrite -Sym1 subsetT. by apply: card1_trivg; rewrite card_Sym; case: #|T| oT; do 2?case. Qed. Lemma simple_Alt_3 (T : finType) : #|T| = 3 -> simple 'Alt_T. Proof. move=> T3; have{T3} oA: #|'Alt_T| = 3. by apply: double_inj; rewrite -mul2n card_Alt T3. apply/simpleP; split=> [|K]; [by rewrite trivg_card1 oA | case/andP=> sKH _]. have:= cardSg sKH; rewrite oA dvdn_divisors // !inE orbC /= -oA. case/pred2P=> eqK; [right | left]; apply/eqP. by rewrite eqEcard sKH eqK leqnn. by rewrite eq_sym eqEcard sub1G eqK cards1. Qed. Lemma not_simple_Alt_4 (T : finType) : #|T| = 4 -> ~~ simple 'Alt_T. Proof. move=> oT; set A := 'Alt_T. have oA: #|A| = 12 by apply: double_inj; rewrite -mul2n card_Alt oT. suffices [p]: exists p, [/\ prime p, 1 < #|A|`_p < #|A| & #|'Syl_p(A)| == 1%N]. case=> p_pr pA_int; rewrite /A; case/normal_sylowP=> P; case/pHallP. rewrite /= -/A => sPA pP nPA; apply/simpleP=> [] [_]; rewrite -pP in pA_int. by case/(_ P)=> // defP; rewrite defP oA ?cards1 in pA_int. have: #|'Syl_3(A)| \in filter [pred d | d %% 3 == 1%N] (divisors 12). by rewrite mem_filter -dvdn_divisors //= -oA card_Syl_dvd ?card_Syl_mod. rewrite /= oA mem_seq2 orbC. case/predU1P=> [oQ3|]; [exists 2 | exists 3]; split; rewrite ?p_part //. pose A3 := [set x : {perm T} | #[x] == 3]; suffices oA3: #|A :&: A3| = 8. have sQ2 P: P \in 'Syl_2(A) -> P :=: A :\: A3. rewrite inE pHallE oA p_part -natTrecE /= => /andP[sPA /eqP oP]. apply/eqP; rewrite eqEcard -(leq_add2l 8) -{1}oA3 cardsID oA oP. rewrite andbT subsetD sPA; apply/exists_inP=> -[x] /= Px. by rewrite inE => /eqP ox; have:= order_dvdG Px; rewrite oP ox. have [/= P sylP] := Sylow_exists 2 [group of A]. rewrite -(([set P] =P 'Syl_2(A)) _) ?cards1 // eqEsubset sub1set inE sylP. by apply/subsetP=> Q sylQ; rewrite inE -val_eqE /= !sQ2 // inE. rewrite -[8]/(4 * 2)%N -{}oQ3 -sum1_card -sum_nat_const. rewrite (partition_big (fun x => <[x]>%G) [in 'Syl_3(A)]) => [|x]; last first. by case/setIP=> Ax; rewrite /= !inE pHallE p_part cycle_subG Ax oA. apply: eq_bigr => Q; rewrite inE pHallE oA p_part -?natTrecE //=. case/andP=> sQA /eqP oQ; have:= oQ. rewrite (cardsD1 1) group1 -sum1_card => [[/= <-]]; apply: eq_bigl => x. rewrite setIC -val_eqE /= 2!inE in_setD1 -andbA -{4}[x]expg1 -order_dvdn dvdn1. apply/and3P/andP=> [[/eqP-> _ /eqP <-] | [ntx Qx]]; first by rewrite cycle_id. have:= order_dvdG Qx; rewrite oQ dvdn_divisors // mem_seq2 (negPf ntx) /=. by rewrite eqEcard cycle_subG Qx (subsetP sQA) // oQ /order => /eqP->. Qed. Lemma simple_Alt5_base (T : finType) : #|T| = 5 -> simple 'Alt_T. Proof. move=> oT. have F1: #|'Alt_T| = 60 by apply: double_inj; rewrite -mul2n card_Alt oT. have FF (H : {group {perm T}}): H <| 'Alt_T -> H :<>: 1 -> 20 %| #|H|. - move=> Hh1 Hh3. have [x _]: exists x, x \in T by apply/existsP/eqP; rewrite oT. have F2 := Alt_trans T; rewrite oT /= in F2. have F3: [transitive 'Alt_T, on setT | 'P] by apply: ntransitive1 F2. have F4: [primitive 'Alt_T, on setT | 'P] by apply: ntransitive_primitive F2. case: (prim_trans_norm F4 Hh1) => F5. by case: Hh3; apply/trivgP; apply: subset_trans F5 (aperm_faithful _). have F6: 5 %| #|H| by rewrite -oT -cardsT (atrans_dvd F5). have F7: 4 %| #|H|. have F7: #|[set~ x]| = 4 by rewrite cardsC1 oT. case: (pickP [in [set~ x]]) => [y Hy | ?]; last by rewrite eq_card0 in F7. pose K := 'C_H[x | 'P]%G. have F8 : K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]%G. have F9: [transitive^2 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. exact: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. exact: ntransitive_primitive F9. have F12: K \subset Gx by apply: setSI; apply: normal_sub. have F13: K <| Gx by rewrite /(K <| _) F12 normsIG // normal_norm. case: (prim_trans_norm F11 F13) => Ksub; last first. by apply: dvdn_trans (cardSg F8); rewrite -F7; apply: atrans_dvd Ksub. have F14: [faithful Gx, on [set~ x] | 'P]. apply/subsetP=> g; do 2![case/setIP] => Altg cgx cgx'. apply: (subsetP (aperm_faithful 'Alt_T)). rewrite inE Altg /=; apply/astabP=> z _. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> nxz; rewrite (astabP cgx') ?inE //. have Hreg g (z : T): g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite (trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by case/normalP: Hh1 => _ nH1; rewrite -(nH1 _ Hg1) memJ_conjg. clear K F8 F12 F13 Ksub F14. case: (Cauchy _ F6) => // h Hh /eqP Horder. have diff_hnx_x n: 0 < n -> n < 5 -> x != (h ^+ n) x. move=> Hn1 Hn2; rewrite eq_sym; apply/negP => HH. have: #[h ^+ n] = 5. rewrite orderXgcd // (eqP Horder). by move: Hn1 Hn2 {HH}; do 5 (case: n => [|n] //). have Hhd2: h ^+ n \in H by rewrite groupX. by rewrite (Hreg _ _ Hhd2 (eqP HH)) order1. pose S1 := [tuple x; h x; (h ^+ 3) x]. have DnS1: S1 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. pose S2 := [tuple x; h x; (h ^+ 2) x]. have DnS2: S2 \in 3.-dtuple(setT). rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT. rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM. by rewrite (inj_eq perm_inj) diff_hnx_x. case: (atransP2 F2 DnS1 DnS2) => g Hg [/=]. rewrite /aperm => Hgx Hghx Hgh3x. have h_g_com: h * g = g * h. suff HH: (g * h * g^-1) * h^-1 = 1 by rewrite -[h * g]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hgx Hghx -!permM mulKVg mulgV perm1. rewrite groupM // ?groupV // (conjgCV g) mulgK -mem_conjg. by case/normalP: Hh1 => _ ->. have: (g * (h ^+ 2) * g ^-1) x = (h ^+ 3) x. rewrite !permM -Hgx. have ->: h (h x) = (h ^+ 2) x by rewrite /= permM. by rewrite {1}Hgh3x -!permM /= mulgV mulg1 -expgSr. rewrite commuteX // mulgK {1}[expgn]lock expgS permM -lock. by move/perm_inj=> eqxhx; case/eqP: (diff_hnx_x 1%N isT isT); rewrite expg1. by rewrite (@Gauss_dvd 4 5) // F7. apply/simpleP; split => [|H Hnorm]; first by rewrite trivg_card1 F1. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case Hcard60: (#|H| == 60); move/eqP: Hcard60 => Hcard60. by apply/eqP; rewrite eqEcard Hcard60 F1 andbT; case/andP: Hnorm. have {Hcard1 Hcard60} Hcard20: #|H| = 20. have Hdiv: 20 %| #|H| by apply: FF => // HH; case Hcard1; rewrite HH cards1. case H20: (#|H| == 20); first exact/eqP. case: Hcard60; case/andP: Hnorm; move/cardSg; rewrite F1 => Hdiv1 _. by case/dvdnP: Hdiv H20 Hdiv1 => n ->; move: n; do 4!case=> //. have prime_5: prime 5 by []. have nSyl5: #|'Syl_5(H)| = 1%N. move: (card_Syl_dvd 5 H) (card_Syl_mod H prime_5). rewrite Hcard20; case: (card _) => // n Hdiv. move: (dvdn_leq (isT: (0 < 20)%N) Hdiv). by move: (n) Hdiv; do 20 (case=> //). case: (Sylow_exists 5 H) => S; case/pHallP=> sSH oS. have{} oS: #|S| = 5 by rewrite oS p_part Hcard20. suff: 20 %| #|S| by rewrite oS. apply: FF => [|S1]; last by rewrite S1 cards1 in oS. apply: char_normal_trans Hnorm; apply: lone_subgroup_char => // Q sQH isoQS. rewrite subEproper; apply/norP=> [[nQS _]]; move: nSyl5. rewrite (cardsD1 S) (cardsD1 Q) 4!{1}inE nQS !pHallE sQH sSH Hcard20 p_part. by rewrite (card_isog isoQS) oS. Qed. Section Restrict. Variables (T : finType) (x : T). Notation T' := {y | y != x}. Lemma rfd_funP (p : {perm T}) (u : T') : let p1 := if p x == x then p else 1 in p1 (val u) != x. Proof. case: (p x =P x) => /= [pxx | _]; last by rewrite perm1 (valP u). by rewrite -[x in _ != x]pxx (inj_eq perm_inj); apply: (valP u). Qed. Definition rfd_fun p := [fun u => Sub ((_ : {perm T}) _) (rfd_funP p u) : T']. Lemma rfdP p : injective (rfd_fun p). Proof. apply: can_inj (rfd_fun p^-1) _ => u; apply: val_inj => /=. rewrite -(can_eq (permK p)) permKV eq_sym. by case: eqP => _; rewrite !(perm1, permK). Qed. Definition rfd p := perm (@rfdP p). Hypothesis card_T : 2 < #|T|. Lemma rfd_morph : {in 'C_('Sym_T)[x | 'P] &, {morph rfd : y z / y * z}}. Proof. move=> p q; rewrite !setIA !setIid; move/astab1P=> p_x; move/astab1P=> q_x. apply/permP=> u; apply: val_inj. by rewrite permE /= !permM !permE /= [p x]p_x [q x]q_x eqxx permM /=. Qed. Canonical rfd_morphism := Morphism rfd_morph. Definition rgd_fun (p : {perm T'}) := [fun x1 => if insub x1 is Some u then sval (p u) else x]. Lemma rgdP p : injective (rgd_fun p). Proof. apply: can_inj (rgd_fun p^-1) _ => y /=. case: (insubP _ y) => [u _ val_u|]; first by rewrite valK permK. by rewrite negbK; move/eqP->; rewrite insubF //= eqxx. Qed. Definition rgd p := perm (@rgdP p). Lemma rfd_odd (p : {perm T}) : p x = x -> rfd p = p :> bool. Proof. have rfd1: rfd 1 = 1. by apply/permP => u; apply: val_inj; rewrite permE /= if_same !perm1. have [n] := ubnP #|[set x | p x != x]|; elim: n p => // n IHn p le_p_n px_x. have [p_id | [x1 Hx1]] := set_0Vmem [set x | p x != x]. suffices ->: p = 1 by rewrite rfd1 !odd_perm1. by apply/permP => z; apply: contraFeq (in_set0 z); rewrite perm1 -p_id inE. have nx1x: x1 != x by apply: contraTneq Hx1 => ->; rewrite inE px_x eqxx. have npxx1: p x != x1 by apply: contraNneq nx1x => <-; rewrite px_x. have npx1x: p x1 != x by rewrite -px_x (inj_eq perm_inj). pose p1 := p * tperm x1 (p x1). have fix_p1 y: p y = y -> p1 y = y. by move=> pyy; rewrite permM; have [<-|/perm_inj<-|] := tpermP; rewrite ?pyy. have p1x_x: p1 x = x by apply: fix_p1. have{le_p_n} lt_p1_n: #|[set x | p1 x != x]| < n. move: le_p_n; rewrite ltnS (cardsD1 x1) Hx1; apply/leq_trans/subset_leq_card. rewrite subsetD1 inE permM tpermR eqxx andbT. by apply/subsetP=> y /[!inE]; apply: contraNneq=> /fix_p1->. transitivity (p1 (+) true); last first. by rewrite odd_permM odd_tperm -Hx1 inE eq_sym addbK. have ->: p = p1 * tperm x1 (p x1) by rewrite -tpermV mulgK. rewrite morphM; last 2 first; first by rewrite 2!inE; apply/astab1P. by rewrite 2!inE; apply/astab1P; rewrite -[RHS]p1x_x permM px_x. rewrite odd_permM IHn //=; congr (_ (+) _). pose x2 : T' := Sub x1 nx1x; pose px2 : T' := Sub (p x1) npx1x. suffices ->: rfd (tperm x1 (p x1)) = tperm x2 px2. by rewrite odd_tperm eq_sym; rewrite inE in Hx1. apply/permP => z; apply/val_eqP; rewrite permE /= tpermD // eqxx. by rewrite !permE /= -!val_eqE /= !(fun_if sval) /=. Qed. Lemma rfd_iso : 'C_('Alt_T)[x | 'P] \isog 'Alt_T'. Proof. have rgd_x p: rgd p x = x by rewrite permE /= insubF //= eqxx. have rfd_rgd p: rfd (rgd p) = p. apply/permP => [[z Hz]]; apply/val_eqP; rewrite !permE. by rewrite /= [rgd _ _]permE /= insubF eqxx // permE /= insubT. have sSd: 'C_('Alt_T)[x | 'P] \subset 'dom rfd. by apply/subsetP=> p /[!inE]/= /andP[]. apply/isogP; exists [morphism of restrm sSd rfd] => /=; last first. rewrite morphim_restrm setIid; apply/setP=> z; apply/morphimP/idP=> [[p _]|]. case/setIP; rewrite Alt_even => Hp; move/astab1P=> Hp1 ->. by rewrite Alt_even rfd_odd. have dz': rgd z x == x by rewrite rgd_x. move=> kz; exists (rgd z); last by rewrite /= rfd_rgd. by rewrite 2!inE (sameP astab1P eqP). rewrite 4!inE /= (sameP astab1P eqP) dz' -rfd_odd; last exact/eqP. by rewrite rfd_rgd mker // ?set11. apply/injmP=> x1 y1 /=. case/setIP=> Hax1; move/astab1P; rewrite /= /aperm => Hx1. case/setIP=> Hay1; move/astab1P; rewrite /= /aperm => Hy1 Hr. apply/permP => z. case (z =P x) => [->|]; [by rewrite Hx1 | move/eqP => nzx]. move: (congr1 (fun q : {perm T'} => q (Sub z nzx)) Hr). by rewrite !permE => [[]]; rewrite Hx1 Hy1 !eqxx. Qed. End Restrict. Lemma simple_Alt5 (T : finType) : #|T| >= 5 -> simple 'Alt_T. Proof. suff F1 n: #|T| = n + 5 -> simple 'Alt_T by move/subnK/esym/F1. elim: n T => [| n Hrec T Hde]; first exact: simple_Alt5_base. have oT: 5 < #|T| by rewrite Hde addnC. apply/simpleP; split=> [|H Hnorm]; last have [Hh1 nH] := andP Hnorm. rewrite trivg_card1 -[#|_|]half_double -mul2n card_Alt Hde addnC //. by rewrite addSn factS mulnC -(prednK (fact_gt0 _)). case E1: (pred0b T); first by rewrite /pred0b in E1; rewrite (eqP E1) in oT. case/pred0Pn: E1 => x _; have Hx := in_setT x. have F2: [transitive^4 'Alt_T, on setT | 'P]. by apply: ntransitive_weak (Alt_trans T); rewrite -(subnKC oT). have F3 := ntransitive1 (isT: 0 < 4) F2. have F4 := ntransitive_primitive (isT: 1 < 4) F2. case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1. by left; apply: card1_trivg; rewrite Hcard1. right; case: (prim_trans_norm F4 Hnorm) => F5. by rewrite (trivGP (subset_trans F5 (aperm_faithful _))) cards1 in Hcard1. case E1: (pred0b (predD1 T x)). rewrite /pred0b in E1; move: oT. by rewrite (cardD1 x) (eqP E1); case: (T x). case/pred0Pn: E1 => y Hdy; case/andP: (Hdy) => diff_x_y Hy. pose K := 'C_H[x | 'P]%G. have F8: K \subset H by apply: subsetIl. pose Gx := 'C_('Alt_T)[x | 'P]. have F9: [transitive^3 Gx, on [set~ x] | 'P]. by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE. have F10: [transitive Gx, on [set~ x] | 'P]. by apply: ntransitive1 F9. have F11: [primitive Gx, on [set~ x] | 'P]. by apply: ntransitive_primitive F9. have F12: K \subset Gx by rewrite setSI // normal_sub. have F13: K <| Gx by apply/andP; rewrite normsIG. have:= prim_trans_norm F11; case/(_ K) => //= => Ksub; last first. have F14: Gx * H = 'Alt_T by apply/(subgroup_transitiveP _ _ F3). have: simple Gx. by rewrite (isog_simple (rfd_iso x)) Hrec //= card_sig cardC1 Hde. case/simpleP=> _ simGx; case/simGx: F13 => /= HH2. case Ez: (pred0b (predD1 (predD1 T x) y)). move: oT; rewrite /pred0b in Ez. by rewrite (cardD1 x) (cardD1 y) (eqP Ez) inE /= inE /= diff_x_y. case/pred0Pn: Ez => z; case/andP => diff_y_z Hdz. have [diff_x_z Hz] := andP Hdz. have: z \in [set~ x] by rewrite !inE. rewrite -(atransP Ksub y) ?inE //; case/imsetP => g. rewrite /= HH2 inE; move/eqP=> -> HH4. by case/negP: diff_y_z; rewrite HH4 act1. by rewrite /= -F14 -[Gx]HH2 (mulSGid F8). have F14: [faithful Gx, on [set~ x] | 'P]. apply: subset_trans (aperm_faithful 'Sym_T); rewrite subsetI subsetT. apply/subsetP=> g; do 2![case/setIP]=> _ cgx cgx'; apply/astabP=> z _ /=. case: (z =P x) => [->|]; first exact: (astab1P cgx). by move/eqP=> zx; rewrite [_ g](astabP cgx') ?inE. have Hreg g z: g \in H -> g z = z -> g = 1. have F15 h: h \in H -> h x = x -> h = 1. move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P. by rewrite [K](trivGP (subset_trans Ksub F14)) => /set1P. move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //. case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g. apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz. by rewrite memJ_norm ?(subsetP nH). clear K F8 F12 F13 Ksub F14. have Hcard: 5 < #|H|. apply: (leq_trans oT); apply: dvdn_leq; first exact: cardG_gt0. by rewrite -cardsT (atrans_dvd F5). case Eh: (pred0b [predD1 H & 1]). by move: Hcard; rewrite /pred0b in Eh; rewrite (cardD1 1) group1 (eqP Eh). case/pred0Pn: Eh => h; case/andP => diff_1_h /= Hh. case Eg: (pred0b (predD1 (predD1 [predD1 H & 1] h) h^-1)). move: Hcard; rewrite ltnNge; case/negP. rewrite (cardD1 1) group1 (cardD1 h) (cardD1 h^-1) (eqnP Eg). by do 2!case: (_ \in _). case/pred0Pn: Eg => g; case/andP => diff_h1_g; case/andP => diff_h_g. case/andP => diff_1_g /= Hg. case diff_hx_x: (h x == x). by case/negP: diff_1_h; apply/eqP; apply: (Hreg _ _ Hh (eqP diff_hx_x)). case diff_gx_x: (g x == x). case/negP: diff_1_g; apply/eqP; apply: (Hreg _ _ Hg (eqP diff_gx_x)). case diff_gx_hx: (g x == h x). case/negP: diff_h_g; apply/eqP; symmetry; apply: (mulIg g^-1); rewrite gsimp. apply: (Hreg _ x); first by rewrite groupM // groupV. by rewrite permM -(eqP diff_gx_hx) -permM mulgV perm1. case diff_hgx_x: ((h * g) x == x). case/negP: diff_h1_g; apply/eqP; apply: (mulgI h); rewrite !gsimp. by apply: (Hreg _ x); [apply: groupM | apply/eqP]. case diff_hgx_hx: ((h * g) x == h x). case/negP: diff_1_g; apply/eqP. by apply: (Hreg _ (h x)) => //; apply/eqP; rewrite -permM. case diff_hgx_gx: ((h * g) x == g x). by case/idP: diff_hx_x; rewrite -(can_eq (permK g)) -permM. case Ez: (pred0b (predD1 (predD1 (predD1 (predD1 T x) (h x)) (g x)) ((h * g) x))). - move: oT; rewrite /pred0b in Ez. rewrite (cardD1 x) (cardD1 (h x)) (cardD1 (g x)) (cardD1 ((h * g) x)). by rewrite (eqP Ez) addnC; do 3!case: (_ x \in _). case/pred0Pn: Ez => z. case/and5P=> diff_hgx_z diff_gx_z diff_hx_z diff_x_z /= Hz. pose S1 := [tuple x; h x; g x; z]. have DnS1: S1 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT. rewrite -!(eq_sym z) diff_gx_z diff_x_z diff_hx_z. by rewrite !(eq_sym x) diff_hx_x diff_gx_x eq_sym diff_gx_hx. pose S2 := [tuple x; h x; g x; (h * g) x]. have DnS2: S2 \in 4.-dtuple(setT). rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT !(eq_sym x). rewrite diff_hx_x diff_gx_x diff_hgx_x. by rewrite !(eq_sym (h x)) diff_gx_hx diff_hgx_hx eq_sym diff_hgx_gx. case: (atransP2 F2 DnS1 DnS2) => k Hk [/=]. rewrite /aperm => Hkx Hkhx Hkgx Hkhgx. have h_k_com: h * k = k * h. suff HH: (k * h * k^-1) * h^-1 = 1 by rewrite -[h * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkhx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have g_k_com: g * k = k * g. suff HH: (k * g * k^-1) * g^-1 = 1 by rewrite -[g * k]mul1g -HH !gnorm. apply: (Hreg _ x); last first. by rewrite !permM -Hkx Hkgx -!permM mulKVg mulgV perm1. by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH). have HH: (k * (h * g) * k ^-1) x = z. by rewrite 2!permM -Hkx Hkhgx -permM mulgV perm1. case/negP: diff_hgx_z. rewrite -HH !mulgA -h_k_com -!mulgA [k * _]mulgA. by rewrite -g_k_com -!mulgA mulgV mulg1. Qed. Lemma gen_tperm_circular_shift (X : finType) x y c : prime #|X| -> x != y -> #[c]%g = #|X| -> <<[set tperm x y; c]>>%g = ('Sym_X)%g. Proof. move=> Xprime neq_xy ord_c; apply/eqP; rewrite eqEsubset subsetT/=. have c_gt1 : (1 < #[c]%g)%N by rewrite ord_c prime_gt1. have cppSS : #[c]%g.-2.+2 = #|X| by rewrite ?prednK ?ltn_predRL. pose f (i : 'Z_#[c]%g) : X := Zpm i x. have [g fK gK] : bijective f. apply: inj_card_bij; rewrite ?cppSS ?card_ord// /f /Zpm => i j cijx. pose stabx := ('C_<[c]>[x | 'P])%g. have cjix : (c ^+ (j - i)%R)%g x = x. by apply: (@perm_inj _ (c ^+ i)%g); rewrite -permM -expgD_Zp// addrNK. have : (c ^+ (j - i)%R)%g \in stabx. by rewrite !inE ?groupX ?mem_gen ?sub1set ?inE// ['P%act _ _]cjix eqxx. rewrite [stabx]perm_prime_astab// => /set1gP. move=> /(congr1 (mulg (c ^+ i))); rewrite -expgD_Zp// addrC addrNK mulg1. by move=> /eqP; rewrite eq_expg_ord// ?cppSS ?ord_c// => /eqP->. pose gsf s := g \o s \o f. have gsf_inj (s : {perm X}) : injective (gsf s). apply: inj_comp; last exact: can_inj fK. by apply: inj_comp; [exact: can_inj gK|exact: perm_inj]. pose fsg s := f \o s \o g. have fsg_inj (s : {perm _}) : injective (fsg s). apply: inj_comp; last exact: can_inj gK. by apply: inj_comp; [exact: can_inj fK|exact: perm_inj]. have gsf_morphic : morphic 'Sym_X (fun s => perm (gsf_inj s)). apply/morphicP => u v _ _; apply/permP => /= i. by rewrite !permE/= !permE /gsf /= gK permM. pose phi := morphm gsf_morphic; rewrite /= in phi. have phi_inj : ('injm phi)%g. apply/subsetP => /= u /mker/=; rewrite morphmE => gsfu1. apply/set1gP/permP=> z; have /permP/(_ (g z)) := gsfu1. by rewrite !perm1 permE /gsf/= gK => /(can_inj gK). have phiT : (phi @* 'Sym_X)%g = [set: {perm 'Z_#[c]%g}]. apply/eqP; rewrite eqEsubset subsetT/=; apply/subsetP => /= u _. apply/morphimP; exists (perm (fsg_inj u)); rewrite ?in_setT//. by apply/permP => /= i; rewrite morphmE permE /gsf/fsg/= permE/= !fK. have f0 : f 0%R = x by rewrite /f /Zpm permX. pose k := g y; have k_gt0 : (k > 0)%N. by rewrite lt0n (val_eqE k 0%R) -(can_eq fK) eq_sym gK f0. have phixy : phi (tperm x y) = tperm (0%R : 'Z_#[c]) k. apply/permP => i; rewrite permE/= /gsf/=; apply: (canLR fK). by rewrite !permE/= -f0 -[y]gK !(can_eq fK) -!fun_if. have phic : phi c = perm (addrI (1%R : 'Z_#[c])). apply/permP => i; rewrite /phi morphmE !permE /gsf/=; apply: (canLR fK). by rewrite /f /Zpm -permM addrC expgD_Zp. rewrite -(injmSK phi_inj)//= morphim_gen/= ?subsetT//= -/phi. rewrite phiT /morphim !setTI/= -/phi imsetU1 imset_set1/= phixy phic. suff /gen_tpermn_circular_shift<- : coprime #[c]%g.-2.+2 (k - 0)%R by []. by rewrite subr0 prime_coprime ?gtnNdvd// ?cppSS. Qed. Section Perm_solvable. Local Open Scope nat_scope. Variable T : finType. Lemma solvable_AltF : 4 < #|T| -> solvable 'Alt_T = false. Proof. move=> card_T; apply/negP => Alt_solvable. have/simple_Alt5 Alt_simple := card_T. have := simple_sol_prime Alt_solvable Alt_simple. have lt_T n : n <= 4 -> n < #|T| by move/leq_ltn_trans; apply. have -> : #|('Alt_T)%G| = #|T|`! %/ 2 by rewrite -card_Alt ?mulKn ?lt_T. move/even_prime => [/eqP|]; apply/negP. rewrite neq_ltn leq_divRL // mulnC -[2 * 3]/(3`!). by apply/orP; right; apply/ltnW/ltn_fact/lt_T. by rewrite -dvdn2 dvdn_divRL dvdn_fact //=; apply/ltnW/lt_T. Qed. Lemma solvable_SymF : 4 < #|T| -> solvable 'Sym_T = false. Proof. by rewrite (series_sol (Alt_normal T)) => /solvable_AltF->. Qed. End Perm_solvable.
Dedup.lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Lattice import Batteries.Data.List.Pairwise /-! # Erasure of duplicates in a list This file proves basic results about `List.dedup` (definition in `Data.List.Defs`). `dedup l` returns `l` without its duplicates. It keeps the earliest (that is, rightmost) occurrence of each. ## Tags duplicate, multiplicity, nodup, `nub` -/ universe u namespace List variable {α β : Type*} [DecidableEq α] @[simp] theorem dedup_nil : dedup [] = ([] : List α) := rfl theorem dedup_cons_of_mem' {a : α} {l : List α} (h : a ∈ dedup l) : dedup (a :: l) = dedup l := pwFilter_cons_of_neg <| by simpa only [forall_mem_ne, not_not] using h theorem dedup_cons_of_notMem' {a : α} {l : List α} (h : a ∉ dedup l) : dedup (a :: l) = a :: dedup l := pwFilter_cons_of_pos <| by simpa only [forall_mem_ne] using h @[deprecated (since := "2025-05-23")] alias dedup_cons_of_not_mem' := dedup_cons_of_notMem' @[simp] theorem mem_dedup {a : α} {l : List α} : a ∈ dedup l ↔ a ∈ l := by have := not_congr (@forall_mem_pwFilter α (· ≠ ·) _ ?_ a l) · simpa only [dedup, forall_mem_ne, not_not] using this · intros x y z xz exact not_and_or.1 <| mt (fun h ↦ h.1.trans h.2) xz @[simp] theorem dedup_cons_of_mem {a : α} {l : List α} (h : a ∈ l) : dedup (a :: l) = dedup l := dedup_cons_of_mem' <| mem_dedup.2 h @[simp] theorem dedup_cons_of_notMem {a : α} {l : List α} (h : a ∉ l) : dedup (a :: l) = a :: dedup l := dedup_cons_of_notMem' <| mt mem_dedup.1 h @[deprecated (since := "2025-05-23")] alias dedup_cons_of_not_mem := dedup_cons_of_notMem theorem dedup_sublist : ∀ l : List α, dedup l <+ l := pwFilter_sublist theorem dedup_subset : ∀ l : List α, dedup l ⊆ l := pwFilter_subset theorem subset_dedup (l : List α) : l ⊆ dedup l := fun _ => mem_dedup.2 theorem nodup_dedup : ∀ l : List α, Nodup (dedup l) := pairwise_pwFilter theorem headI_dedup [Inhabited α] (l : List α) : l.dedup.headI = if l.headI ∈ l.tail then l.tail.dedup.headI else l.headI := match l with | [] => rfl | a :: l => by by_cases ha : a ∈ l <;> simp [ha, List.dedup_cons_of_mem] theorem tail_dedup [Inhabited α] (l : List α) : l.dedup.tail = if l.headI ∈ l.tail then l.tail.dedup.tail else l.tail.dedup := match l with | [] => rfl | a :: l => by by_cases ha : a ∈ l <;> simp [ha, List.dedup_cons_of_mem] theorem dedup_eq_self {l : List α} : dedup l = l ↔ Nodup l := pwFilter_eq_self theorem dedup_eq_cons (l : List α) (a : α) (l' : List α) : l.dedup = a :: l' ↔ a ∈ l ∧ a ∉ l' ∧ l.dedup.tail = l' := by refine ⟨fun h => ?_, fun h => ?_⟩ · refine ⟨mem_dedup.1 (h.symm ▸ mem_cons_self), fun ha => ?_, by rw [h, tail_cons]⟩ have := count_pos_iff.2 ha have : count a l.dedup ≤ 1 := nodup_iff_count_le_one.1 (nodup_dedup l) a rw [h, count_cons_self] at this omega · have := @List.cons_head!_tail α ⟨a⟩ _ (ne_nil_of_mem (mem_dedup.2 h.1)) have hal : a ∈ l.dedup := mem_dedup.2 h.1 rw [← this, mem_cons, or_iff_not_imp_right] at hal exact this ▸ h.2.2.symm ▸ cons_eq_cons.2 ⟨(hal (h.2.2.symm ▸ h.2.1)).symm, rfl⟩ @[simp] theorem dedup_eq_nil (l : List α) : l.dedup = [] ↔ l = [] := by induction l with | nil => exact Iff.rfl | cons a l hl => by_cases h : a ∈ l · simp only [List.dedup_cons_of_mem h, hl, List.ne_nil_of_mem h, reduceCtorEq] · simp only [List.dedup_cons_of_notMem h, List.cons_ne_nil] protected theorem Nodup.dedup {l : List α} (h : l.Nodup) : l.dedup = l := List.dedup_eq_self.2 h @[simp] theorem dedup_idem {l : List α} : dedup (dedup l) = dedup l := pwFilter_idem theorem dedup_append (l₁ l₂ : List α) : dedup (l₁ ++ l₂) = l₁ ∪ dedup l₂ := by induction l₁ with | nil => rfl | cons a l₁ IH => ?_ simp only [cons_union] at * rw [← IH, cons_append] by_cases h : a ∈ dedup (l₁ ++ l₂) · rw [dedup_cons_of_mem' h, insert_of_mem h] · rw [dedup_cons_of_notMem' h, insert_of_not_mem h] theorem dedup_map_of_injective [DecidableEq β] {f : α → β} (hf : Function.Injective f) (xs : List α) : (xs.map f).dedup = xs.dedup.map f := by induction xs with | nil => simp | cons x xs ih => rw [map_cons] by_cases h : x ∈ xs · rw [dedup_cons_of_mem h, dedup_cons_of_mem (mem_map_of_mem h), ih] · rw [dedup_cons_of_notMem h, dedup_cons_of_notMem <| (mem_map_of_injective hf).not.mpr h, ih, map_cons] /-- Note that the weaker `List.Subset.dedup_append_left` is proved later. -/ theorem Subset.dedup_append_right {xs ys : List α} (h : xs ⊆ ys) : dedup (xs ++ ys) = dedup ys := by rw [List.dedup_append, Subset.union_eq_right (List.Subset.trans h <| subset_dedup _)] theorem Disjoint.union_eq {xs ys : List α} (h : Disjoint xs ys) : xs ∪ ys = xs.dedup ++ ys := by induction xs with | nil => simp | cons x xs ih => rw [cons_union] rw [disjoint_cons_left] at h by_cases hx : x ∈ xs · rw [dedup_cons_of_mem hx, insert_of_mem (mem_union_left hx _), ih h.2] · rw [dedup_cons_of_notMem hx, insert_of_not_mem, ih h.2, cons_append] rw [mem_union_iff, not_or] exact ⟨hx, h.1⟩ theorem Disjoint.dedup_append {xs ys : List α} (h : Disjoint xs ys) : dedup (xs ++ ys) = dedup xs ++ dedup ys := by rw [List.dedup_append, Disjoint.union_eq] intro a hx hy exact h hx (mem_dedup.mp hy) theorem replicate_dedup {x : α} : ∀ {k}, k ≠ 0 → (replicate k x).dedup = [x] | 0, h => (h rfl).elim | 1, _ => rfl | n + 2, _ => by rw [replicate_succ, dedup_cons_of_mem (mem_replicate.2 ⟨n.succ_ne_zero, rfl⟩), replicate_dedup n.succ_ne_zero] theorem count_dedup (l : List α) (a : α) : l.dedup.count a = if a ∈ l then 1 else 0 := by simp_rw [count_eq_of_nodup <| nodup_dedup l, mem_dedup] theorem Perm.dedup {l₁ l₂ : List α} (p : l₁ ~ l₂) : dedup l₁ ~ dedup l₂ := perm_iff_count.2 fun a => if h : a ∈ l₁ then by simp [h, nodup_dedup, p.subset h] else by simp [h, count_eq_zero_of_not_mem, mt p.mem_iff.2] end List
module.lean
/- Copyright (c) 2024 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Algebra.Order.Field.Defs import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.LinearCombination import Mathlib.Tactic.Module import Mathlib.Tactic.NoncommRing import Mathlib.Tactic.Positivity /-! # Tests for the module-normalization tactic -/ open Mathlib.Tactic.LinearCombination variable {V : Type*} {K : Type*} {t u v w x y z : V} {a b c d e f μ ν ρ : K} /-! ### `ℕ` (most tests copied from the `abel` tactic) -/ section Nat variable [AddCommMonoid V] example : x + (y + x) = x + x + y := by module example : (3 : ℕ) • x = x + (2 : ℕ) • x := by module example : 0 + x = x := by module example (n : ℕ) : n • x = n • x := by module example (n : ℕ) : 0 + n • x = n • x := by module example : x + (y + (x + (z + (x + (u + (x + v)))))) = v + u + z + y + 4 • x := by module example : x + y = y + x := by module example : x + 2 • x = 2 • x + x := by module example : x + (y + x) = x + x + y ∨ False := by left module /-- error: unsolved goals V : Type u_1 K : Type u_2 t u v w x y z : V a b c d e f μ ν ρ : K inst✝ : AddCommMonoid V ⊢ 1 = 1 V : Type u_1 K : Type u_2 t u v w x y z : V a b c d e f μ ν ρ : K inst✝ : AddCommMonoid V ⊢ 1 = 2 * 1 -/ #guard_msgs in example : x + y = x + 2 • y := by match_scalars /-- error: ring failed, ring expressions not equal V : Type u_1 K : Type u_2 t u v w x y z : V a b c d e f μ ν ρ : K inst✝ : AddCommMonoid V ⊢ 1 = 2 -/ #guard_msgs in example : x + y = x + 2 • y := by module /-- error: goal x ≠ y is not an equality -/ #guard_msgs in example : x ≠ y := by module end Nat /-! ### `ℤ` (most tests copied from the `abel` tactic) -/ variable [AddCommGroup V] example : (x + y) - ((y + x) + x) = -x := by module example : x - 0 = x := by module example : (3 : ℤ) • x = x + (2 : ℤ) • x := by module example : x - 2 • y = x - 2 • y := by module example : (x + y) - ((y + x) + x) = -x := by module example : x + y + (z + w - x) = y + z + w := by module example : x + y + z + (z - x - x) = (-1) • x + y + 2 • z := by module example : -x + x = 0 := by module example : x - (0 - 0) = x := by module example : x + (y - x) = y := by module example : -y + (z - x) = z - y - x := by module example : x + y = y + x ∧ (↑((1:ℕ) + 1) : ℚ) = 2 := by constructor module -- do not focus this tactic: the double goal is the point of the test guard_target =ₐ (↑((1:ℕ) + 1) : ℚ) = 2 norm_cast -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Interaction.20of.20abel.20with.20casting/near/319895001 example : True := by have : ∀ (p q r s : V), s + p - q = s - r - (q - r - p) := by intro p q r s module trivial example : True := by have : ∀ (p q r s : V), s + p - q = s - r - (q - r - p) := by intro p q r s match_scalars · decide · decide · decide · decide trivial -- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Interaction.20of.20abel.20with.20casting/near/319897374 example : y = x + z - (x - y + z) := by have : True := trivial module example : y = x + z - (x - y + z) := by have : True := trivial match_scalars <;> decide /-- error: unsolved goals V : Type u_1 K : Type u_2 t u v w x y z : V a b c d e f μ ν ρ : K inst✝ : AddCommGroup V ⊢ -1 + 1 = 0 -/ #guard_msgs in example : -x + x = 0 := by match_scalars /-! ### Commutative ring -/ section CommRing variable [CommRing K] [Module K V] example : a • x + b • x = (a + b) • x := by module example : a • x - b • x = (a - b) • x := by module example : a • x - b • y = a • x + (-b) • y := by module example : 2 • a • x = a • 2 • x := by module example : a • x - b • y = a • x + (-b) • y := by module example : (μ - ν) • a • x = (a • μ • x + b • ν • y) - ν • (a • x + b • y) := by module example : (μ - ν) • b • y = μ • (a • x + b • y) - (a • μ • x + b • ν • y) := by module -- from https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/smul.20diamond/near/457163013 example : (4 : ℤ) • v = (4 : K) • v := by module example : (4 : ℕ) • v = (4 : K) • v := by module -- from https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/linear_combination.20for.20groups/near/437042918 example : (1 + a ^ 2) • (v + w) - a • (a • v - w) = v + (1 + a + a ^ 2) • w := by module example (h : a = b) : a • x = b • x := by match_scalars linear_combination h example (h : a = b) : a • x = b • x := by linear_combination (norm := module) h • x example (h : a ^ 2 + b ^ 2 = 1) : a • (a • x - b • y) + (b • a • y + b • b • x) = x := by match_scalars · linear_combination h · ring example (h : a ^ 2 + b ^ 2 = 1) : a • (a • x - b • y) + (b • a • y + b • b • x) = x := by linear_combination (norm := module) h • x example (h1 : a • x + b • y = 0) (h2 : a • μ • x + b • ν • y = 0) : (μ - ν) • a • x = 0 ∧ (μ - ν) • b • y = 0 := by constructor · linear_combination (norm := module) h2 - ν • h1 · linear_combination (norm := module) μ • h1 - h2 example (h1 : 0 • z + a • x + b • y = 0) (h2 : 0 • ρ • z + a • μ • x + b • ν • y = 0) : (μ - ν) • a • x = 0 := by linear_combination (norm := module) h2 - ν • h1 example (h1 : a • x + b • y + c • z = 0) (h2 : a • μ • x + b • ν • y + c • ρ • z = 0) (h3 : a • μ • μ • x + b • ν • ν • y + c • ρ • ρ • z = 0) : (μ - ν) • (μ - ρ) • a • x = 0 ∧ (μ - ν) • (ν - ρ) • b • y = 0 ∧ (μ - ρ) • (ν - ρ) • c • z = 0 := by refine ⟨?_, ?_, ?_⟩ · linear_combination (norm := module) h3 - (ν + ρ) • h2 + ν • ρ • h1 · linear_combination (norm := module) - h3 + (μ + ρ) • h2 - μ • ρ • h1 · linear_combination (norm := module) h3 - (μ + ν) • h2 + μ • ν • h1 /-- error: ring failed, ring expressions not equal V : Type u_1 K : Type u_2 t u v w x y z : V a b c d e f μ ν ρ : K inst✝² : AddCommGroup V inst✝¹ : CommRing K inst✝ : Module K V ⊢ a * 2 = 2 -/ #guard_msgs in example : 2 • a • x = 2 • x := by module end CommRing /-! ### (Noncommutative) ring -/ section Ring variable [Ring K] [Module K V] example : a • x + b • x = (b + a) • x := by match_scalars noncomm_ring example : 2 • a • x = a • (2:ℤ) • x := by match_scalars noncomm_ring example (h : a = b) : a • x = b • x := by match_scalars simp [h] example : (a - b) • a • x + b • b • x = a • a • x + b • (-a + b) • x := by match_scalars noncomm_ring end Ring /-! ### Characteristic-zero field -/ section CharZeroField variable [Field K] [CharZero K] [Module K V] example : (2:K)⁻¹ • x + (3:K)⁻¹ • x + (6:K)⁻¹ • x = x := by module example (h₁ : t - u = -(v - w)) (h₂ : t + u = v + w) : t = w := by linear_combination (norm := module) (2:K)⁻¹ • h₁ + (2:K)⁻¹ • h₂ end CharZeroField /-! ### Linearly ordered field -/ section LinearOrderedField variable [Field K] [LinearOrder K] [IsStrictOrderedRing K] [Module K V] example (ha : 0 ≤ a) (hb : 0 < b) : x = (a / (a + b)) • y + (b / (a + b)) • (x + (a / b) • (x - y)) := by match_scalars · field_simp ring · field_simp ring -- From Analysis.Convex.StoneSeparation example (hab : 0 < a * b + c * d) : (a * b / (a * b + c * d) * e) • u + (c * d / (a * b + c * d) * f) • v + ((a * b / (a * b + c * d)) • d • x + (c * d / (a * b + c * d)) • b • y) = (a * b + c * d)⁻¹ • ((a * b * e) • u + ((c * d * f) • v + ((a * b) • d • x + (c * d) • b • y))) := by match_scalars · field_simp · field_simp · field_simp · field_simp example (h₁ : 1 = a ^ 2 + b ^ 2) (h₂ : 1 - a ≠ 0) : ((2 / (1 - a)) ^ 2 * b ^ 2 + 4)⁻¹ • (4:K) • ((2 / (1 - a)) • y) + ((2 / (1 - a)) ^ 2 * b ^ 2 + 4)⁻¹ • ((2 / (1 - a)) ^ 2 * b ^ 2 - 4) • x = a • x + y := by linear_combination (norm := skip) (h₁ * (b ^ 2 + (1 - a) ^ 2)⁻¹) • (y + (a - 1) • x) match_scalars · field_simp ring · field_simp ring example (h₁ : 1 = a ^ 2 + b ^ 2) (h₂ : 1 - a ≠ 0) : ((2 / (1 - a)) ^ 2 * b ^ 2 + 4)⁻¹ • (4:K) • ((2 / (1 - a)) • y) + ((2 / (1 - a)) ^ 2 * b ^ 2 + 4)⁻¹ • ((2 / (1 - a)) ^ 2 * b ^ 2 - 4) • x = a • x + y := by match_scalars · field_simp linear_combination 4 * (1 - a) * h₁ · field_simp linear_combination 4 * (a - 1) ^ 3 * h₁ end LinearOrderedField
Rademacher.lean
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.LineDeriv.Measurable import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.Analysis.BoundedVariation import Mathlib.MeasureTheory.Group.Integral import Mathlib.Analysis.Distribution.AEEqOfIntegralContDiff import Mathlib.MeasureTheory.Measure.Haar.Disintegration /-! # Rademacher's theorem: a Lipschitz function is differentiable almost everywhere This file proves Rademacher's theorem: a Lipschitz function between finite-dimensional real vector spaces is differentiable almost everywhere with respect to the Lebesgue measure. This is the content of `LipschitzWith.ae_differentiableAt`. Versions for functions which are Lipschitz on sets are also given (see `LipschitzOnWith.ae_differentiableWithinAt`). ## Implementation There are many proofs of Rademacher's theorem. We follow the one by Morrey, which is not the most elementary but maybe the most elegant once necessary prerequisites are set up. * Step 0: without loss of generality, one may assume that `f` is real-valued. * Step 1: Since a one-dimensional Lipschitz function has bounded variation, it is differentiable almost everywhere. With a Fubini argument, it follows that given any vector `v` then `f` is ae differentiable in the direction of `v`. See `LipschitzWith.ae_lineDifferentiableAt`. * Step 2: the line derivative `LineDeriv ℝ f x v` is ae linear in `v`. Morrey proves this by a duality argument, integrating against a smooth compactly supported function `g`, passing the derivative to `g` by integration by parts, and using the linearity of the derivative of `g`. See `LipschitzWith.ae_lineDeriv_sum_eq`. * Step 3: consider a countable dense set `s` of directions. Almost everywhere, the function `f` is line-differentiable in all these directions and the line derivative is linear. Approximating any direction by a direction in `s` and using the fact that `f` is Lipschitz to control the error, it follows that `f` is Fréchet-differentiable at these points. See `LipschitzWith.hasFDerivAt_of_hasLineDerivAt_of_closure`. ## References * [Pertti Mattila, Geometry of sets and measures in Euclidean spaces, Theorem 7.3][Federer1996] -/ open Filter MeasureTheory Measure Module Metric Set Asymptotics open scoped NNReal ENNReal Topology variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {C D : ℝ≥0} {f g : E → ℝ} {s : Set E} {μ : Measure E} namespace LipschitzWith /-! ### Step 1: A Lipschitz function is ae differentiable in any given direction This follows from the one-dimensional result that a Lipschitz function on `ℝ` has bounded variation, and is therefore ae differentiable, together with a Fubini argument. -/ theorem memLp_lineDeriv (hf : LipschitzWith C f) (v : E) : MemLp (fun x ↦ lineDeriv ℝ f x v) ∞ μ := memLp_top_of_bound (aestronglyMeasurable_lineDeriv hf.continuous μ) (C * ‖v‖) (.of_forall fun _x ↦ norm_lineDeriv_le_of_lipschitz ℝ hf) @[deprecated (since := "2025-02-21")] alias memℒp_lineDeriv := memLp_lineDeriv variable [FiniteDimensional ℝ E] [IsAddHaarMeasure μ] theorem ae_lineDifferentiableAt (hf : LipschitzWith C f) (v : E) : ∀ᵐ p ∂μ, LineDifferentiableAt ℝ f p v := by let L : ℝ →L[ℝ] E := ContinuousLinearMap.smulRight (1 : ℝ →L[ℝ] ℝ) v suffices A : ∀ p, ∀ᵐ (t : ℝ) ∂volume, LineDifferentiableAt ℝ f (p + t • v) v from ae_mem_of_ae_add_linearMap_mem L.toLinearMap volume μ (measurableSet_lineDifferentiableAt hf.continuous) A intro p have : ∀ᵐ (s : ℝ), DifferentiableAt ℝ (fun t ↦ f (p + t • v)) s := (hf.comp ((LipschitzWith.const p).add L.lipschitz)).ae_differentiableAt_real filter_upwards [this] with s hs have h's : DifferentiableAt ℝ (fun t ↦ f (p + t • v)) (s + 0) := by simpa using hs have : DifferentiableAt ℝ (fun t ↦ s + t) 0 := differentiableAt_id.const_add _ simp only [LineDifferentiableAt] convert h's.comp 0 this with _ t simp only [add_assoc, Function.comp_apply, add_smul] theorem locallyIntegrable_lineDeriv (hf : LipschitzWith C f) (v : E) : LocallyIntegrable (fun x ↦ lineDeriv ℝ f x v) μ := (hf.memLp_lineDeriv v).locallyIntegrable le_top /-! ### Step 2: the ae line derivative is linear Surprisingly, this is the hardest step. We prove it using an elegant but slightly sophisticated argument by Morrey, with a distributional flavor: we integrate against a smooth function, and push the derivative to the smooth function by integration by parts. As the derivative of a smooth function is linear, this gives the result. -/ theorem integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul (hf : LipschitzWith C f) (hg : Integrable g μ) (v : E) : Tendsto (fun (t : ℝ) ↦ ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂μ) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ f x v * g x ∂μ)) := by apply tendsto_integral_filter_of_dominated_convergence (fun x ↦ (C * ‖v‖) * ‖g x‖) · filter_upwards with t apply AEStronglyMeasurable.mul ?_ hg.aestronglyMeasurable apply aestronglyMeasurable_const.smul apply AEStronglyMeasurable.sub _ hf.continuous.measurable.aestronglyMeasurable apply AEMeasurable.aestronglyMeasurable exact hf.continuous.measurable.comp_aemeasurable' (aemeasurable_id'.add_const _) · filter_upwards [self_mem_nhdsWithin] with t (ht : 0 < t) filter_upwards with x calc ‖t⁻¹ • (f (x + t • v) - f x) * g x‖ = (t⁻¹ * ‖f (x + t • v) - f x‖) * ‖g x‖ := by simp [norm_mul, ht.le] _ ≤ (t⁻¹ * (C * ‖(x + t • v) - x‖)) * ‖g x‖ := by gcongr; exact LipschitzWith.norm_sub_le hf (x + t • v) x _ = (C * ‖v‖) *‖g x‖ := by field_simp [norm_smul, abs_of_nonneg ht.le]; ring · exact hg.norm.const_mul _ · filter_upwards [hf.ae_lineDifferentiableAt v] with x hx exact hx.hasLineDerivAt.tendsto_slope_zero_right.mul tendsto_const_nhds theorem integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul' (hf : LipschitzWith C f) (h'f : HasCompactSupport f) (hg : Continuous g) (v : E) : Tendsto (fun (t : ℝ) ↦ ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂μ) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ f x v * g x ∂μ)) := by let K := cthickening (‖v‖) (tsupport f) have K_compact : IsCompact K := IsCompact.cthickening h'f apply tendsto_integral_filter_of_dominated_convergence (K.indicator (fun x ↦ (C * ‖v‖) * ‖g x‖)) · filter_upwards with t apply AEStronglyMeasurable.mul ?_ hg.aestronglyMeasurable apply aestronglyMeasurable_const.smul apply AEStronglyMeasurable.sub _ hf.continuous.measurable.aestronglyMeasurable apply AEMeasurable.aestronglyMeasurable exact hf.continuous.measurable.comp_aemeasurable' (aemeasurable_id'.add_const _) · filter_upwards [Ioc_mem_nhdsGT zero_lt_one] with t ht have t_pos : 0 < t := ht.1 filter_upwards with x by_cases hx : x ∈ K · calc ‖t⁻¹ • (f (x + t • v) - f x) * g x‖ = (t⁻¹ * ‖f (x + t • v) - f x‖) * ‖g x‖ := by simp [norm_mul, t_pos.le] _ ≤ (t⁻¹ * (C * ‖(x + t • v) - x‖)) * ‖g x‖ := by gcongr; exact LipschitzWith.norm_sub_le hf (x + t • v) x _ = (C * ‖v‖) *‖g x‖ := by field_simp [norm_smul, abs_of_nonneg t_pos.le]; ring _ = K.indicator (fun x ↦ (C * ‖v‖) * ‖g x‖) x := by rw [indicator_of_mem hx] · have A : f x = 0 := by rw [← Function.notMem_support] contrapose! hx exact self_subset_cthickening _ (subset_tsupport _ hx) have B : f (x + t • v) = 0 := by rw [← Function.notMem_support] contrapose! hx apply mem_cthickening_of_dist_le _ _ (‖v‖) (tsupport f) (subset_tsupport _ hx) simp only [dist_eq_norm, sub_add_cancel_left, norm_neg, norm_smul, Real.norm_eq_abs, abs_of_nonneg t_pos.le] exact mul_le_of_le_one_left (norm_nonneg v) ht.2 simp only [B, A, _root_.sub_self, smul_eq_mul, mul_zero, zero_mul, norm_zero] exact indicator_nonneg (fun y _hy ↦ by positivity) _ · rw [integrable_indicator_iff K_compact.measurableSet] apply ContinuousOn.integrableOn_compact K_compact exact (Continuous.mul continuous_const hg.norm).continuousOn · filter_upwards [hf.ae_lineDifferentiableAt v] with x hx exact hx.hasLineDerivAt.tendsto_slope_zero_right.mul tendsto_const_nhds /-- Integration by parts formula for the line derivative of Lipschitz functions, assuming one of them is compactly supported. -/ theorem integral_lineDeriv_mul_eq (hf : LipschitzWith C f) (hg : LipschitzWith D g) (h'g : HasCompactSupport g) (v : E) : ∫ x, lineDeriv ℝ f x v * g x ∂μ = ∫ x, lineDeriv ℝ g x (-v) * f x ∂μ := by /- Write down the line derivative as the limit of `(f (x + t v) - f x) / t` and `(g (x - t v) - g x) / t`, and therefore the integrals as limits of the corresponding integrals thanks to the dominated convergence theorem. At fixed positive `t`, the integrals coincide (with the change of variables `y = x + t v`), so the limits also coincide. -/ have A : Tendsto (fun (t : ℝ) ↦ ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂μ) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ f x v * g x ∂μ)) := integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul hf (hg.continuous.integrable_of_hasCompactSupport h'g) v have B : Tendsto (fun (t : ℝ) ↦ ∫ x, (t⁻¹ • (g (x + t • (-v)) - g x)) * f x ∂μ) (𝓝[>] 0) (𝓝 (∫ x, lineDeriv ℝ g x (-v) * f x ∂μ)) := integral_inv_smul_sub_mul_tendsto_integral_lineDeriv_mul' hg h'g hf.continuous (-v) suffices S1 : ∀ (t : ℝ), ∫ x, (t⁻¹ • (f (x + t • v) - f x)) * g x ∂μ = ∫ x, (t⁻¹ • (g (x + t • (-v)) - g x)) * f x ∂μ by simp only [S1] at A; exact tendsto_nhds_unique A B intro t suffices S2 : ∫ x, (f (x + t • v) - f x) * g x ∂μ = ∫ x, f x * (g (x + t • (-v)) - g x) ∂μ by simp only [smul_eq_mul, mul_assoc, integral_const_mul, S2, mul_comm (f _)] have S3 : ∫ x, f (x + t • v) * g x ∂μ = ∫ x, f x * g (x + t • (-v)) ∂μ := by rw [← integral_add_right_eq_self _ (t • (-v))]; simp simp_rw [_root_.sub_mul, _root_.mul_sub] rw [integral_sub, integral_sub, S3] · apply Continuous.integrable_of_hasCompactSupport · exact hf.continuous.mul (hg.continuous.comp (continuous_add_right _)) · exact (h'g.comp_homeomorph (Homeomorph.addRight (t • (-v)))).mul_left · exact (hf.continuous.mul hg.continuous).integrable_of_hasCompactSupport h'g.mul_left · apply Continuous.integrable_of_hasCompactSupport · exact (hf.continuous.comp (continuous_add_right _)).mul hg.continuous · exact h'g.mul_left · exact (hf.continuous.mul hg.continuous).integrable_of_hasCompactSupport h'g.mul_left /-- The line derivative of a Lipschitz function is almost everywhere linear with respect to fixed coefficients. -/ theorem ae_lineDeriv_sum_eq (hf : LipschitzWith C f) {ι : Type*} (s : Finset ι) (a : ι → ℝ) (v : ι → E) : ∀ᵐ x ∂μ, lineDeriv ℝ f x (∑ i ∈ s, a i • v i) = ∑ i ∈ s, a i • lineDeriv ℝ f x (v i) := by /- Clever argument by Morrey: integrate against a smooth compactly supported function `g`, switch the derivative to `g` by integration by parts, and use the linearity of the derivative of `g` to conclude that the initial integrals coincide. -/ apply ae_eq_of_integral_contDiff_smul_eq (hf.locallyIntegrable_lineDeriv _) (locallyIntegrable_finset_sum _ (fun i hi ↦ (hf.locallyIntegrable_lineDeriv (v i)).smul (a i))) (fun g g_smooth g_comp ↦ ?_) simp_rw [Finset.smul_sum] have A : ∀ i ∈ s, Integrable (fun x ↦ g x • (a i • fun x ↦ lineDeriv ℝ f x (v i)) x) μ := fun i hi ↦ (g_smooth.continuous.integrable_of_hasCompactSupport g_comp).smul_of_top_left ((hf.memLp_lineDeriv (v i)).const_smul (a i)) rw [integral_finset_sum _ A] suffices S1 : ∫ x, lineDeriv ℝ f x (∑ i ∈ s, a i • v i) * g x ∂μ = ∑ i ∈ s, a i * ∫ x, lineDeriv ℝ f x (v i) * g x ∂μ by dsimp only [smul_eq_mul, Pi.smul_apply] simp_rw [← mul_assoc, mul_comm _ (a _), mul_assoc, integral_const_mul, mul_comm (g _), S1] suffices S2 : ∫ x, (∑ i ∈ s, a i * fderiv ℝ g x (v i)) * f x ∂μ = ∑ i ∈ s, a i * ∫ x, fderiv ℝ g x (v i) * f x ∂μ by obtain ⟨D, g_lip⟩ : ∃ D, LipschitzWith D g := ContDiff.lipschitzWith_of_hasCompactSupport g_comp g_smooth (mod_cast le_top) simp_rw [integral_lineDeriv_mul_eq hf g_lip g_comp] simp_rw [(g_smooth.differentiable (mod_cast le_top)).differentiableAt.lineDeriv_eq_fderiv] simp only [map_neg, _root_.map_sum, map_smul, smul_eq_mul, neg_mul] simp only [integral_neg, mul_neg, Finset.sum_neg_distrib, neg_inj] exact S2 suffices B : ∀ i ∈ s, Integrable (fun x ↦ a i * (fderiv ℝ g x (v i) * f x)) μ by simp_rw [Finset.sum_mul, mul_assoc, integral_finset_sum s B, integral_const_mul] intro i _hi let L : (E →L[ℝ] ℝ) → ℝ := fun f ↦ f (v i) change Integrable (fun x ↦ a i * ((L ∘ (fderiv ℝ g)) x * f x)) μ refine (Continuous.integrable_of_hasCompactSupport ?_ ?_).const_mul _ · exact ((g_smooth.continuous_fderiv (mod_cast le_top)).clm_apply continuous_const).mul hf.continuous · exact ((g_comp.fderiv ℝ).comp_left rfl).mul_right /-! ### Step 3: construct the derivative using the line derivatives along a basis -/ theorem ae_exists_fderiv_of_countable (hf : LipschitzWith C f) {s : Set E} (hs : s.Countable) : ∀ᵐ x ∂μ, ∃ (L : E →L[ℝ] ℝ), ∀ v ∈ s, HasLineDerivAt ℝ f (L v) x v := by have B := Basis.ofVectorSpace ℝ E have I1 : ∀ᵐ (x : E) ∂μ, ∀ v ∈ s, lineDeriv ℝ f x (∑ i, (B.repr v i) • B i) = ∑ i, B.repr v i • lineDeriv ℝ f x (B i) := (ae_ball_iff hs).2 (fun v _ ↦ hf.ae_lineDeriv_sum_eq _ _ _) have I2 : ∀ᵐ (x : E) ∂μ, ∀ v ∈ s, LineDifferentiableAt ℝ f x v := (ae_ball_iff hs).2 (fun v _ ↦ hf.ae_lineDifferentiableAt v) filter_upwards [I1, I2] with x hx h'x let L : E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (B.constr ℝ (fun i ↦ lineDeriv ℝ f x (B i))) refine ⟨L, fun v hv ↦ ?_⟩ have J : L v = lineDeriv ℝ f x v := by convert (hx v hv).symm <;> simp [L, B.sum_repr v] simpa [J] using (h'x v hv).hasLineDerivAt omit [MeasurableSpace E] in /-- If a Lipschitz functions has line derivatives in a dense set of directions, all of them given by a single continuous linear map `L`, then it admits `L` as Fréchet derivative. -/ theorem hasFDerivAt_of_hasLineDerivAt_of_closure {f : E → F} (hf : LipschitzWith C f) {s : Set E} (hs : sphere 0 1 ⊆ closure s) {L : E →L[ℝ] F} {x : E} (hL : ∀ v ∈ s, HasLineDerivAt ℝ f (L v) x v) : HasFDerivAt f L x := by rw [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff] intro ε εpos obtain ⟨δ, δpos, hδ⟩ : ∃ δ, 0 < δ ∧ (C + ‖L‖ + 1) * δ = ε := ⟨ε / (C + ‖L‖ + 1), by positivity, mul_div_cancel₀ ε (by positivity)⟩ obtain ⟨q, hqs, q_fin, hq⟩ : ∃ q, q ⊆ s ∧ q.Finite ∧ sphere 0 1 ⊆ ⋃ y ∈ q, ball y δ := by have : sphere 0 1 ⊆ ⋃ y ∈ s, ball y δ := by apply hs.trans (fun z hz ↦ ?_) obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, dist z y < δ := Metric.mem_closure_iff.1 hz δ δpos exact mem_biUnion ys hy exact (isCompact_sphere 0 1).elim_finite_subcover_image (fun y _hy ↦ isOpen_ball) this have I : ∀ᶠ t in 𝓝 (0 : ℝ), ∀ v ∈ q, ‖f (x + t • v) - f x - t • L v‖ ≤ δ * ‖t‖ := by apply (Finite.eventually_all q_fin).2 (fun v hv ↦ ?_) apply Asymptotics.IsLittleO.def ?_ δpos exact hasLineDerivAt_iff_isLittleO_nhds_zero.1 (hL v (hqs hv)) obtain ⟨r, r_pos, hr⟩ : ∃ (r : ℝ), 0 < r ∧ ∀ (t : ℝ), ‖t‖ < r → ∀ v ∈ q, ‖f (x + t • v) - f x - t • L v‖ ≤ δ * ‖t‖ := by rcases Metric.mem_nhds_iff.1 I with ⟨r, r_pos, hr⟩ exact ⟨r, r_pos, fun t ht v hv ↦ hr (mem_ball_zero_iff.2 ht) v hv⟩ apply Metric.mem_nhds_iff.2 ⟨r, r_pos, fun v hv ↦ ?_⟩ rcases eq_or_ne v 0 with rfl | v_ne · simp obtain ⟨w, ρ, w_mem, hvw, hρ⟩ : ∃ w ρ, w ∈ sphere 0 1 ∧ v = ρ • w ∧ ρ = ‖v‖ := by refine ⟨‖v‖⁻¹ • v, ‖v‖, by simp [norm_smul, inv_mul_cancel₀ (norm_ne_zero_iff.2 v_ne)], ?_, rfl⟩ simp [smul_smul, mul_inv_cancel₀ (norm_ne_zero_iff.2 v_ne)] have norm_rho : ‖ρ‖ = ρ := by rw [hρ, norm_norm] have rho_pos : 0 ≤ ρ := by simp [hρ] obtain ⟨y, yq, hy⟩ : ∃ y ∈ q, ‖w - y‖ < δ := by simpa [← dist_eq_norm] using hq w_mem have : ‖y - w‖ < δ := by rwa [norm_sub_rev] calc ‖f (x + v) - f x - L v‖ = ‖f (x + ρ • w) - f x - ρ • L w‖ := by simp [hvw] _ = ‖(f (x + ρ • w) - f (x + ρ • y)) + (ρ • L y - ρ • L w) + (f (x + ρ • y) - f x - ρ • L y)‖ := by congr; abel _ ≤ ‖f (x + ρ • w) - f (x + ρ • y)‖ + ‖ρ • L y - ρ • L w‖ + ‖f (x + ρ • y) - f x - ρ • L y‖ := norm_add₃_le _ ≤ C * ‖(x + ρ • w) - (x + ρ • y)‖ + ρ * (‖L‖ * ‖y - w‖) + δ * ρ := by gcongr · exact hf.norm_sub_le _ _ · rw [← smul_sub, norm_smul, norm_rho] gcongr exact L.lipschitz.norm_sub_le _ _ · conv_rhs => rw [← norm_rho] apply hr _ _ _ yq simpa [norm_rho, hρ] using hv _ ≤ C * (ρ * δ) + ρ * (‖L‖ * δ) + δ * ρ := by simp only [add_sub_add_left_eq_sub, ← smul_sub, norm_smul, norm_rho]; gcongr _ = ((C + ‖L‖ + 1) * δ) * ρ := by ring _ = ε * ‖v‖ := by rw [hδ, hρ] /-- A real-valued function on a finite-dimensional space which is Lipschitz is differentiable almost everywere. Superseded by `LipschitzWith.ae_differentiableAt` which works for functions taking value in any finite-dimensional space. -/ theorem ae_differentiableAt_of_real (hf : LipschitzWith C f) : ∀ᵐ x ∂μ, DifferentiableAt ℝ f x := by obtain ⟨s, s_count, s_dense⟩ : ∃ (s : Set E), s.Countable ∧ Dense s := TopologicalSpace.exists_countable_dense E have hs : sphere 0 1 ⊆ closure s := by rw [s_dense.closure_eq]; exact subset_univ _ filter_upwards [hf.ae_exists_fderiv_of_countable s_count] rintro x ⟨L, hL⟩ exact (hf.hasFDerivAt_of_hasLineDerivAt_of_closure hs hL).differentiableAt end LipschitzWith variable [FiniteDimensional ℝ E] [FiniteDimensional ℝ F] [IsAddHaarMeasure μ] namespace LipschitzOnWith /-- A real-valued function on a finite-dimensional space which is Lipschitz on a set is differentiable almost everywere in this set. Superseded by `LipschitzOnWith.ae_differentiableWithinAt_of_mem` which works for functions taking value in any finite-dimensional space. -/ theorem ae_differentiableWithinAt_of_mem_of_real (hf : LipschitzOnWith C f s) : ∀ᵐ x ∂μ, x ∈ s → DifferentiableWithinAt ℝ f s x := by obtain ⟨g, g_lip, hg⟩ : ∃ (g : E → ℝ), LipschitzWith C g ∧ EqOn f g s := hf.extend_real filter_upwards [g_lip.ae_differentiableAt_of_real] with x hx xs exact hx.differentiableWithinAt.congr hg (hg xs) /-- A function on a finite-dimensional space which is Lipschitz on a set and taking values in a product space is differentiable almost everywere in this set. Superseded by `LipschitzOnWith.ae_differentiableWithinAt_of_mem` which works for functions taking value in any finite-dimensional space. -/ theorem ae_differentiableWithinAt_of_mem_pi {ι : Type*} [Fintype ι] {f : E → ι → ℝ} {s : Set E} (hf : LipschitzOnWith C f s) : ∀ᵐ x ∂μ, x ∈ s → DifferentiableWithinAt ℝ f s x := by have A : ∀ i : ι, LipschitzWith 1 (fun x : ι → ℝ ↦ x i) := fun i => LipschitzWith.eval i have : ∀ i : ι, ∀ᵐ x ∂μ, x ∈ s → DifferentiableWithinAt ℝ (fun x : E ↦ f x i) s x := fun i ↦ by apply ae_differentiableWithinAt_of_mem_of_real exact LipschitzWith.comp_lipschitzOnWith (A i) hf filter_upwards [ae_all_iff.2 this] with x hx xs exact differentiableWithinAt_pi.2 (fun i ↦ hx i xs) /-- *Rademacher's theorem*: a function between finite-dimensional real vector spaces which is Lipschitz on a set is differentiable almost everywere in this set. -/ theorem ae_differentiableWithinAt_of_mem {f : E → F} (hf : LipschitzOnWith C f s) : ∀ᵐ x ∂μ, x ∈ s → DifferentiableWithinAt ℝ f s x := by have A := (Basis.ofVectorSpace ℝ F).equivFun.toContinuousLinearEquiv suffices H : ∀ᵐ x ∂μ, x ∈ s → DifferentiableWithinAt ℝ (A ∘ f) s x by filter_upwards [H] with x hx xs have : f = (A.symm ∘ A) ∘ f := by simp only [ContinuousLinearEquiv.symm_comp_self, Function.id_comp] rw [this] exact A.symm.differentiableAt.comp_differentiableWithinAt x (hx xs) apply ae_differentiableWithinAt_of_mem_pi exact A.lipschitz.comp_lipschitzOnWith hf /-- *Rademacher's theorem*: a function between finite-dimensional real vector spaces which is Lipschitz on a set is differentiable almost everywere in this set. -/ theorem ae_differentiableWithinAt {f : E → F} (hf : LipschitzOnWith C f s) (hs : MeasurableSet s) : ∀ᵐ x ∂(μ.restrict s), DifferentiableWithinAt ℝ f s x := by rw [ae_restrict_iff' hs] exact hf.ae_differentiableWithinAt_of_mem end LipschitzOnWith /-- *Rademacher's theorem*: a Lipschitz function between finite-dimensional real vector spaces is differentiable almost everywhere. -/ theorem LipschitzWith.ae_differentiableAt {f : E → F} (h : LipschitzWith C f) : ∀ᵐ x ∂μ, DifferentiableAt ℝ f x := by rw [← lipschitzOnWith_univ] at h simpa [differentiableWithinAt_univ] using h.ae_differentiableWithinAt_of_mem /-- In a real finite-dimensional normed vector space, the norm is almost everywhere differentiable. -/ theorem ae_differentiableAt_norm : ∀ᵐ x ∂μ, DifferentiableAt ℝ (‖·‖) x := lipschitzWith_one_norm.ae_differentiableAt omit [MeasurableSpace E] in /-- In a real finite-dimensional normed vector space, the set of points where the norm is differentiable at is dense. -/ theorem dense_differentiableAt_norm : Dense {x : E | DifferentiableAt ℝ (‖·‖) x} := let _ : MeasurableSpace E := borel E have _ : BorelSpace E := ⟨rfl⟩ let w := Basis.ofVectorSpace ℝ E MeasureTheory.Measure.dense_of_ae (ae_differentiableAt_norm (μ := w.addHaar))
TietzeExtension.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.Order.Interval.Set.IsoIoo import Mathlib.Topology.ContinuousMap.Bounded.Normed import Mathlib.Topology.UrysohnsBounded /-! # Tietze extension theorem In this file we prove a few version of the Tietze extension theorem. The theorem says that a continuous function `s → ℝ` defined on a closed set in a normal topological space `Y` can be extended to a continuous function on the whole space. Moreover, if all values of the original function belong to some (finite or infinite, open or closed) interval, then the extension can be chosen so that it takes values in the same interval. In particular, if the original function is a bounded function, then there exists a bounded extension of the same norm. The proof mostly follows <https://ncatlab.org/nlab/show/Tietze+extension+theorem>. We patch a small gap in the proof for unbounded functions, see `exists_extension_forall_exists_le_ge_of_isClosedEmbedding`. In addition we provide a class `TietzeExtension` encoding the idea that a topological space satisfies the Tietze extension theorem. This allows us to get a version of the Tietze extension theorem that simultaneously applies to `ℝ`, `ℝ × ℝ`, `ℂ`, `ι → ℝ`, `ℝ≥0` et cetera. At some point in the future, it may be desirable to provide instead a more general approach via *absolute retracts*, but the current implementation covers the most common use cases easily. ## Implementation notes We first prove the theorems for a closed embedding `e : X → Y` of a topological space into a normal topological space, then specialize them to the case `X = s : Set Y`, `e = (↑)`. ## Tags Tietze extension theorem, Urysohn's lemma, normal topological space -/ open Topology /-! ### The `TietzeExtension` class -/ section TietzeExtensionClass universe u u₁ u₂ v w -- TODO: define *absolute retracts* and then prove they satisfy Tietze extension. -- Then make instances of that instead and remove this class. /-- A class encoding the concept that a space satisfies the Tietze extension property. -/ class TietzeExtension (Y : Type v) [TopologicalSpace Y] : Prop where exists_restrict_eq' {X : Type u} [TopologicalSpace X] [NormalSpace X] (s : Set X) (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f variable {X₁ : Type u₁} [TopologicalSpace X₁] variable {X : Type u} [TopologicalSpace X] [NormalSpace X] {s : Set X} variable {e : X₁ → X} variable {Y : Type v} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] /-- **Tietze extension theorem** for `TietzeExtension` spaces, a version for a closed set. Let `s` be a closed set in a normal topological space `X`. Let `f` be a continuous function on `s` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g.restrict s = f`. -/ theorem ContinuousMap.exists_restrict_eq (hs : IsClosed s) (f : C(s, Y)) : ∃ (g : C(X, Y)), g.restrict s = f := TietzeExtension.exists_restrict_eq' s hs f /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. -/ theorem ContinuousMap.exists_extension (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g.comp ⟨e, he.continuous⟩ = f := by let e' : X₁ ≃ₜ Set.range e := he.isEmbedding.toHomeomorph obtain ⟨g, hg⟩ := (f.comp e'.symm).exists_restrict_eq he.isClosed_range exact ⟨g, by ext x; simpa using congr($(hg) ⟨e' x, x, rfl⟩)⟩ /-- **Tietze extension theorem** for `TietzeExtension` spaces. Let `e` be a closed embedding of a nonempty topological space `X₁` into a normal topological space `X`. Let `f` be a continuous function on `X₁` with values in a `TietzeExtension` space `Y`. Then there exists a continuous function `g : C(X, Y)` such that `g ∘ e = f`. This version is provided for convenience and backwards compatibility. Here the composition is phrased in terms of bare functions. -/ theorem ContinuousMap.exists_extension' (he : IsClosedEmbedding e) (f : C(X₁, Y)) : ∃ (g : C(X, Y)), g ∘ e = f := f.exists_extension he |>.imp fun g hg ↦ by ext x; congrm($(hg) x) /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_forall_mem_restrict_eq (hs : IsClosed s) {Y : Type v} [TopologicalSpace Y] (f : C(s, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.restrict s = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_restrict_eq hs exact ⟨comp ⟨Subtype.val, by fun_prop⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ /-- This theorem is not intended to be used directly because it is rare for a set alone to satisfy `[TietzeExtension t]`. For example, `Metric.ball` in `ℝ` only satisfies it when the radius is strictly positive, so finding this as an instance will fail. Instead, it is intended to be used as a constructor for theorems about sets which *do* satisfy `[TietzeExtension t]` under some hypotheses. -/ theorem ContinuousMap.exists_extension_forall_mem (he : IsClosedEmbedding e) {Y : Type v} [TopologicalSpace Y] (f : C(X₁, Y)) {t : Set Y} (hf : ∀ x, f x ∈ t) [ht : TietzeExtension.{u, v} t] : ∃ (g : C(X, Y)), (∀ x, g x ∈ t) ∧ g.comp ⟨e, he.continuous⟩ = f := by obtain ⟨g, hg⟩ := mk _ (map_continuous f |>.codRestrict hf) |>.exists_extension he exact ⟨comp ⟨Subtype.val, by fun_prop⟩ g, by simp, by ext x; congrm(($(hg) x : Y))⟩ instance Pi.instTietzeExtension {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [∀ i, TietzeExtension.{u} (Y i)] : TietzeExtension.{u} (∀ i, Y i) where exists_restrict_eq' s hs f := by obtain ⟨g', hg'⟩ := Classical.skolem.mp <| fun i ↦ ContinuousMap.exists_restrict_eq hs (ContinuousMap.piEquiv _ _ |>.symm f i) exact ⟨ContinuousMap.piEquiv _ _ g', by ext x i; congrm($(hg' i) x)⟩ instance Prod.instTietzeExtension {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TietzeExtension.{u, v} Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] : TietzeExtension.{u, max w v} (Y × Z) where exists_restrict_eq' s hs f := by obtain ⟨g₁, hg₁⟩ := (ContinuousMap.fst.comp f).exists_restrict_eq hs obtain ⟨g₂, hg₂⟩ := (ContinuousMap.snd.comp f).exists_restrict_eq hs exact ⟨g₁.prodMk g₂, by ext1 x; congrm(($(hg₁) x), $(hg₂) x)⟩ instance Unique.instTietzeExtension {Y : Type v} [TopologicalSpace Y] [Nonempty Y] [Subsingleton Y] : TietzeExtension.{u, v} Y where exists_restrict_eq' _ _ f := ‹Nonempty Y›.elim fun y ↦ ⟨.const _ y, by ext; subsingleton⟩ /-- Any retract of a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_retract {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (ι : C(Y, Z)) (r : C(Z, Y)) (h : r.comp ι = .id Y) : TietzeExtension.{u, v} Y where exists_restrict_eq' s hs f := by obtain ⟨g, hg⟩ := (ι.comp f).exists_restrict_eq hs use r.comp g ext1 x have := congr(r.comp $(hg)) rw [← r.comp_assoc ι, h, f.id_comp] at this congrm($this x) /-- Any homeomorphism from a `TietzeExtension` space is one itself. -/ theorem TietzeExtension.of_homeo {Y : Type v} {Z : Type w} [TopologicalSpace Y] [TopologicalSpace Z] [TietzeExtension.{u, w} Z] (e : Y ≃ₜ Z) : TietzeExtension.{u, v} Y := .of_retract (e : C(Y, Z)) (e.symm : C(Z, Y)) <| by simp end TietzeExtensionClass /-! The Tietze extension theorem for `ℝ`. -/ variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [NormalSpace Y] open Metric Set Filter open BoundedContinuousFunction Topology noncomputable section namespace BoundedContinuousFunction /-- One step in the proof of the Tietze extension theorem. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the norm `‖g‖ ≤ ‖f‖ / 3` such that the distance between `g ∘ e` and `f` is at most `(2 / 3) * ‖f‖`. -/ theorem tietze_extension_step (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ ≤ ‖f‖ / 3 ∧ dist (g.compContinuous e) f ≤ 2 / 3 * ‖f‖ := by have h3 : (0 : ℝ) < 3 := by norm_num1 have h23 : 0 < (2 / 3 : ℝ) := by norm_num1 -- In the trivial case `f = 0`, we take `g = 0` rcases eq_or_ne f 0 with (rfl | hf) · use 0 simp replace hf : 0 < ‖f‖ := norm_pos_iff.2 hf /- Otherwise, the closed sets `e '' (f ⁻¹' (Iic (-‖f‖ / 3)))` and `e '' (f ⁻¹' (Ici (‖f‖ / 3)))` are disjoint, hence by Urysohn's lemma there exists a function `g` that is equal to `-‖f‖ / 3` on the former set and is equal to `‖f‖ / 3` on the latter set. This function `g` satisfies the assertions of the lemma. -/ have hf3 : -‖f‖ / 3 < ‖f‖ / 3 := (div_lt_div_iff_of_pos_right h3).2 (Left.neg_lt_self hf) have hc₁ : IsClosed (e '' (f ⁻¹' Iic (-‖f‖ / 3))) := he.isClosedMap _ (isClosed_Iic.preimage f.continuous) have hc₂ : IsClosed (e '' (f ⁻¹' Ici (‖f‖ / 3))) := he.isClosedMap _ (isClosed_Ici.preimage f.continuous) have hd : Disjoint (e '' (f ⁻¹' Iic (-‖f‖ / 3))) (e '' (f ⁻¹' Ici (‖f‖ / 3))) := by refine disjoint_image_of_injective he.injective (Disjoint.preimage _ ?_) rwa [Iic_disjoint_Ici, not_le] rcases exists_bounded_mem_Icc_of_closed_of_le hc₁ hc₂ hd hf3.le with ⟨g, hg₁, hg₂, hgf⟩ refine ⟨g, ?_, ?_⟩ · refine (norm_le <| div_nonneg hf.le h3.le).mpr fun y => ?_ simpa [abs_le, neg_div] using hgf y · refine (dist_le <| mul_nonneg h23.le hf.le).mpr fun x => ?_ have hfx : -‖f‖ ≤ f x ∧ f x ≤ ‖f‖ := by simpa only [Real.norm_eq_abs, abs_le] using f.norm_coe_le_norm x rcases le_total (f x) (-‖f‖ / 3) with hle₁ | hle₁ · calc |g (e x) - f x| = -‖f‖ / 3 - f x := by rw [hg₁ (mem_image_of_mem _ hle₁), Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₁)] _ ≤ 2 / 3 * ‖f‖ := by linarith · rcases le_total (f x) (‖f‖ / 3) with hle₂ | hle₂ · simp only [neg_div] at * calc dist (g (e x)) (f x) ≤ |g (e x)| + |f x| := dist_le_norm_add_norm _ _ _ ≤ ‖f‖ / 3 + ‖f‖ / 3 := (add_le_add (abs_le.2 <| hgf _) (abs_le.2 ⟨hle₁, hle₂⟩)) _ = 2 / 3 * ‖f‖ := by linarith · calc |g (e x) - f x| = f x - ‖f‖ / 3 := by rw [hg₂ (mem_image_of_mem _ hle₂), abs_sub_comm, Function.const_apply, abs_of_nonneg (sub_nonneg.2 hle₂)] _ ≤ 2 / 3 * ‖f‖ := by linarith /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and bundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/ theorem exists_extension_norm_eq_of_isClosedEmbedding' (f : X →ᵇ ℝ) (e : C(X, Y)) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g.compContinuous e = f := by /- For the proof, we iterate `tietze_extension_step`. Each time we apply it to the difference between the previous approximation and `f`. -/ choose F hF_norm hF_dist using fun f : X →ᵇ ℝ => tietze_extension_step f e he set g : ℕ → Y →ᵇ ℝ := fun n => (fun g => g + F (f - g.compContinuous e))^[n] 0 have g0 : g 0 = 0 := rfl have g_succ : ∀ n, g (n + 1) = g n + F (f - (g n).compContinuous e) := fun n => Function.iterate_succ_apply' _ _ _ have hgf : ∀ n, dist ((g n).compContinuous e) f ≤ (2 / 3) ^ n * ‖f‖ := by intro n induction n with | zero => simp [g0] | succ n ihn => rw [g_succ n, add_compContinuous, ← dist_sub_right, add_sub_cancel_left, pow_succ', mul_assoc] refine (hF_dist _).trans (mul_le_mul_of_nonneg_left ?_ (by norm_num1)) rwa [← dist_eq_norm'] have hg_dist : ∀ n, dist (g n) (g (n + 1)) ≤ 1 / 3 * ‖f‖ * (2 / 3) ^ n := by intro n calc dist (g n) (g (n + 1)) = ‖F (f - (g n).compContinuous e)‖ := by rw [g_succ, dist_eq_norm', add_sub_cancel_left] _ ≤ ‖f - (g n).compContinuous e‖ / 3 := hF_norm _ _ = 1 / 3 * dist ((g n).compContinuous e) f := by rw [dist_eq_norm', one_div, div_eq_inv_mul] _ ≤ 1 / 3 * ((2 / 3) ^ n * ‖f‖) := mul_le_mul_of_nonneg_left (hgf n) (by norm_num1) _ = 1 / 3 * ‖f‖ * (2 / 3) ^ n := by ac_rfl have hg_cau : CauchySeq g := cauchySeq_of_le_geometric _ _ (by norm_num1) hg_dist have : Tendsto (fun n => (g n).compContinuous e) atTop (𝓝 <| (limUnder atTop g).compContinuous e) := ((continuous_compContinuous e).tendsto _).comp hg_cau.tendsto_limUnder have hge : (limUnder atTop g).compContinuous e = f := by refine tendsto_nhds_unique this (tendsto_iff_dist_tendsto_zero.2 ?_) refine squeeze_zero (fun _ => dist_nonneg) hgf ?_ rw [← zero_mul ‖f‖] refine (tendsto_pow_atTop_nhds_zero_of_lt_one ?_ ?_).mul tendsto_const_nhds <;> norm_num1 refine ⟨limUnder atTop g, le_antisymm ?_ ?_, hge⟩ · rw [← dist_zero_left, ← g0] refine (dist_le_of_le_geometric_of_tendsto₀ _ _ (by norm_num1) hg_dist hg_cau.tendsto_limUnder).trans_eq ?_ field_simp [show (3 - 2 : ℝ) = 1 by norm_num1] · rw [← hge] exact norm_compContinuous_le _ _ /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version with a closed embedding and unbundled composition. If `e : C(X, Y)` is a closed embedding of a topological space into a normal topological space and `f : X →ᵇ ℝ` is a bounded continuous function, then there exists a bounded continuous function `g : Y →ᵇ ℝ` of the same norm such that `g ∘ e = f`. -/ theorem exists_extension_norm_eq_of_isClosedEmbedding (f : X →ᵇ ℝ) {e : X → Y} (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g ∘ e = f := by rcases exists_extension_norm_eq_of_isClosedEmbedding' f ⟨e, he.continuous⟩ he with ⟨g, hg, rfl⟩ exact ⟨g, hg, rfl⟩ /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed set. If `f` is a bounded continuous real-valued function defined on a closed set in a normal topological space, then it can be extended to a bounded continuous function of the same norm defined on the whole space. -/ theorem exists_norm_eq_restrict_eq_of_closed {s : Set Y} (f : s →ᵇ ℝ) (hs : IsClosed s) : ∃ g : Y →ᵇ ℝ, ‖g‖ = ‖f‖ ∧ g.restrict s = f := exists_extension_norm_eq_of_isClosedEmbedding' f ((ContinuousMap.id _).restrict s) hs.isClosedEmbedding_subtypeVal /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed embedding and a bounded continuous function that takes values in a non-trivial closed interval. See also `exists_extension_forall_mem_of_isClosedEmbedding` for a more general statement that works for any interval (finite or infinite, open or closed). If `e : X → Y` is a closed embedding and `f : X →ᵇ ℝ` is a bounded continuous function such that `f x ∈ [a, b]` for all `x`, where `a ≤ b`, then there exists a bounded continuous function `g : Y →ᵇ ℝ` such that `g y ∈ [a, b]` for all `y` and `g ∘ e = f`. -/ theorem exists_extension_forall_mem_Icc_of_isClosedEmbedding (f : X →ᵇ ℝ) {a b : ℝ} {e : X → Y} (hf : ∀ x, f x ∈ Icc a b) (hle : a ≤ b) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, (∀ y, g y ∈ Icc a b) ∧ g ∘ e = f := by rcases exists_extension_norm_eq_of_isClosedEmbedding (f - const X ((a + b) / 2)) he with ⟨g, hgf, hge⟩ refine ⟨const Y ((a + b) / 2) + g, fun y => ?_, ?_⟩ · suffices ‖f - const X ((a + b) / 2)‖ ≤ (b - a) / 2 by simpa [Real.Icc_eq_closedBall, add_mem_closedBall_iff_norm] using (norm_coe_le_norm g y).trans (hgf.trans_le this) refine (norm_le <| div_nonneg (sub_nonneg.2 hle) zero_le_two).2 fun x => ?_ simpa only [Real.Icc_eq_closedBall] using hf x · ext x have : g (e x) = f x - (a + b) / 2 := congr_fun hge x simp [this] /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed embedding. Let `e` be a closed embedding of a nonempty topological space `X` into a normal topological space `Y`. Let `f` be a bounded continuous real-valued function on `X`. Then there exists a bounded continuous function `g : Y →ᵇ ℝ` such that `g ∘ e = f` and each value `g y` belongs to a closed interval `[f x₁, f x₂]` for some `x₁` and `x₂`. -/ theorem exists_extension_forall_exists_le_ge_of_isClosedEmbedding [Nonempty X] (f : X →ᵇ ℝ) {e : X → Y} (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, (∀ y, ∃ x₁ x₂, g y ∈ Icc (f x₁) (f x₂)) ∧ g ∘ e = f := by inhabit X -- Put `a = ⨅ x, f x` and `b = ⨆ x, f x` obtain ⟨a, ha⟩ : ∃ a, IsGLB (range f) a := ⟨_, isGLB_ciInf f.isBounded_range.bddBelow⟩ obtain ⟨b, hb⟩ : ∃ b, IsLUB (range f) b := ⟨_, isLUB_ciSup f.isBounded_range.bddAbove⟩ -- Then `f x ∈ [a, b]` for all `x` have hmem : ∀ x, f x ∈ Icc a b := fun x => ⟨ha.1 ⟨x, rfl⟩, hb.1 ⟨x, rfl⟩⟩ -- Rule out the trivial case `a = b` have hle : a ≤ b := (hmem default).1.trans (hmem default).2 rcases hle.eq_or_lt with (rfl | hlt) · have : ∀ x, f x = a := by simpa using hmem use const Y a simp [this, funext_iff] -- Put `c = (a + b) / 2`. Then `a < c < b` and `c - a = b - c`. set c := (a + b) / 2 have hac : a < c := left_lt_add_div_two.2 hlt have hcb : c < b := add_div_two_lt_right.2 hlt have hsub : c - a = b - c := by simp [c] ring /- Due to `exists_extension_forall_mem_Icc_of_isClosedEmbedding`, there exists an extension `g` such that `g y ∈ [a, b]` for all `y`. However, if `a` and/or `b` do not belong to the range of `f`, then we need to ensure that these points do not belong to the range of `g`. This is done in two almost identical steps. First we deal with the case `∀ x, f x ≠ a`. -/ obtain ⟨g, hg_mem, hgf⟩ : ∃ g : Y →ᵇ ℝ, (∀ y, ∃ x, g y ∈ Icc (f x) b) ∧ g ∘ e = f := by rcases exists_extension_forall_mem_Icc_of_isClosedEmbedding f hmem hle he with ⟨g, hg_mem, hgf⟩ -- If `a ∈ range f`, then we are done. rcases em (∃ x, f x = a) with (⟨x, rfl⟩ | ha') · exact ⟨g, fun y => ⟨x, hg_mem _⟩, hgf⟩ /- Otherwise, `g ⁻¹' {a}` is disjoint with `range e ∪ g ⁻¹' (Ici c)`, hence there exists a function `dg : Y → ℝ` such that `dg ∘ e = 0`, `dg y = 0` whenever `c ≤ g y`, `dg y = c - a` whenever `g y = a`, and `0 ≤ dg y ≤ c - a` for all `y`. -/ have hd : Disjoint (range e ∪ g ⁻¹' Ici c) (g ⁻¹' {a}) := by refine disjoint_union_left.2 ⟨?_, Disjoint.preimage _ ?_⟩ · rw [Set.disjoint_left] rintro _ ⟨x, rfl⟩ (rfl : g (e x) = a) exact ha' ⟨x, (congr_fun hgf x).symm⟩ · exact Set.disjoint_singleton_right.2 hac.not_ge rcases exists_bounded_mem_Icc_of_closed_of_le (he.isClosed_range.union <| isClosed_Ici.preimage g.continuous) (isClosed_singleton.preimage g.continuous) hd (sub_nonneg.2 hac.le) with ⟨dg, dg0, dga, dgmem⟩ replace hgf : ∀ x, (g + dg) (e x) = f x := by intro x simp [dg0 (Or.inl <| mem_range_self _), ← hgf] refine ⟨g + dg, fun y => ?_, funext hgf⟩ have hay : a < (g + dg) y := by rcases (hg_mem y).1.eq_or_lt with (rfl | hlt) · refine (lt_add_iff_pos_right _).2 ?_ calc 0 < c - g y := sub_pos.2 hac _ = dg y := (dga rfl).symm · exact hlt.trans_le (le_add_of_nonneg_right (dgmem y).1) rcases ha.exists_between hay with ⟨_, ⟨x, rfl⟩, _, hxy⟩ refine ⟨x, hxy.le, ?_⟩ rcases le_total c (g y) with hc | hc · simp [dg0 (Or.inr hc), (hg_mem y).2] · calc g y + dg y ≤ c + (c - a) := add_le_add hc (dgmem _).2 _ = b := by rw [hsub, add_sub_cancel] /- Now we deal with the case `∀ x, f x ≠ b`. The proof is the same as in the first case, with minor modifications that make it hard to deduplicate code. -/ choose xl hxl hgb using hg_mem rcases em (∃ x, f x = b) with (⟨x, rfl⟩ | hb') · exact ⟨g, fun y => ⟨xl y, x, hxl y, hgb y⟩, hgf⟩ have hd : Disjoint (range e ∪ g ⁻¹' Iic c) (g ⁻¹' {b}) := by refine disjoint_union_left.2 ⟨?_, Disjoint.preimage _ ?_⟩ · rw [Set.disjoint_left] rintro _ ⟨x, rfl⟩ (rfl : g (e x) = b) exact hb' ⟨x, (congr_fun hgf x).symm⟩ · exact Set.disjoint_singleton_right.2 hcb.not_ge rcases exists_bounded_mem_Icc_of_closed_of_le (he.isClosed_range.union <| isClosed_Iic.preimage g.continuous) (isClosed_singleton.preimage g.continuous) hd (sub_nonneg.2 hcb.le) with ⟨dg, dg0, dgb, dgmem⟩ replace hgf : ∀ x, (g - dg) (e x) = f x := by intro x simp [dg0 (Or.inl <| mem_range_self _), ← hgf] refine ⟨g - dg, fun y => ?_, funext hgf⟩ have hyb : (g - dg) y < b := by rcases (hgb y).eq_or_lt with (rfl | hlt) · refine (sub_lt_self_iff _).2 ?_ calc 0 < g y - c := sub_pos.2 hcb _ = dg y := (dgb rfl).symm · exact ((sub_le_self_iff _).2 (dgmem _).1).trans_lt hlt rcases hb.exists_between hyb with ⟨_, ⟨xu, rfl⟩, hyxu, _⟩ rcases lt_or_ge c (g y) with hc | hc · rcases em (a ∈ range f) with (⟨x, rfl⟩ | _) · refine ⟨x, xu, ?_, hyxu.le⟩ calc f x = c - (b - c) := by rw [← hsub, sub_sub_cancel] _ ≤ g y - dg y := sub_le_sub hc.le (dgmem _).2 · have hay : a < (g - dg) y := by calc a = c - (b - c) := by rw [← hsub, sub_sub_cancel] _ < g y - (b - c) := sub_lt_sub_right hc _ _ ≤ g y - dg y := sub_le_sub_left (dgmem _).2 _ rcases ha.exists_between hay with ⟨_, ⟨x, rfl⟩, _, hxy⟩ exact ⟨x, xu, hxy.le, hyxu.le⟩ · refine ⟨xl y, xu, ?_, hyxu.le⟩ simp [dg0 (Or.inr hc), hxl] /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed embedding. Let `e` be a closed embedding of a nonempty topological space `X` into a normal topological space `Y`. Let `f` be a bounded continuous real-valued function on `X`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x`. Then there exists a bounded continuous real-valued function `g : Y →ᵇ ℝ` such that `g y ∈ t` for all `y` and `g ∘ e = f`. -/ theorem exists_extension_forall_mem_of_isClosedEmbedding (f : X →ᵇ ℝ) {t : Set ℝ} {e : X → Y} [hs : OrdConnected t] (hf : ∀ x, f x ∈ t) (hne : t.Nonempty) (he : IsClosedEmbedding e) : ∃ g : Y →ᵇ ℝ, (∀ y, g y ∈ t) ∧ g ∘ e = f := by cases isEmpty_or_nonempty X · rcases hne with ⟨c, hc⟩ exact ⟨const Y c, fun _ => hc, funext fun x => isEmptyElim x⟩ rcases exists_extension_forall_exists_le_ge_of_isClosedEmbedding f he with ⟨g, hg, hgf⟩ refine ⟨g, fun y => ?_, hgf⟩ rcases hg y with ⟨xl, xu, h⟩ exact hs.out (hf _) (hf _) h /-- **Tietze extension theorem** for real-valued bounded continuous maps, a version for a closed set. Let `s` be a closed set in a normal topological space `Y`. Let `f` be a bounded continuous real-valued function on `s`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x : s`. Then there exists a bounded continuous real-valued function `g : Y →ᵇ ℝ` such that `g y ∈ t` for all `y` and `g.restrict s = f`. -/ theorem exists_forall_mem_restrict_eq_of_closed {s : Set Y} (f : s →ᵇ ℝ) (hs : IsClosed s) {t : Set ℝ} [OrdConnected t] (hf : ∀ x, f x ∈ t) (hne : t.Nonempty) : ∃ g : Y →ᵇ ℝ, (∀ y, g y ∈ t) ∧ g.restrict s = f := by obtain ⟨g, hg, hgf⟩ := exists_extension_forall_mem_of_isClosedEmbedding f hf hne hs.isClosedEmbedding_subtypeVal exact ⟨g, hg, DFunLike.coe_injective hgf⟩ end BoundedContinuousFunction namespace ContinuousMap /-- **Tietze extension theorem** for real-valued continuous maps, a version for a closed embedding. Let `e` be a closed embedding of a nonempty topological space `X` into a normal topological space `Y`. Let `f` be a continuous real-valued function on `X`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x`. Then there exists a continuous real-valued function `g : C(Y, ℝ)` such that `g y ∈ t` for all `y` and `g ∘ e = f`. -/ theorem exists_extension_forall_mem_of_isClosedEmbedding (f : C(X, ℝ)) {t : Set ℝ} {e : X → Y} [hs : OrdConnected t] (hf : ∀ x, f x ∈ t) (hne : t.Nonempty) (he : IsClosedEmbedding e) : ∃ g : C(Y, ℝ), (∀ y, g y ∈ t) ∧ g ∘ e = f := by have h : ℝ ≃o Ioo (-1 : ℝ) 1 := orderIsoIooNegOneOne ℝ let F : X →ᵇ ℝ := { toFun := (↑) ∘ h ∘ f continuous_toFun := continuous_subtype_val.comp (h.continuous.comp f.continuous) map_bounded' := isBounded_range_iff.1 ((isBounded_Ioo (-1 : ℝ) 1).subset <| range_subset_iff.2 fun x => (h (f x)).2) } let t' : Set ℝ := (↑) ∘ h '' t have ht_sub : t' ⊆ Ioo (-1 : ℝ) 1 := image_subset_iff.2 fun x _ => (h x).2 have : OrdConnected t' := by constructor rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ z hz lift z to Ioo (-1 : ℝ) 1 using Icc_subset_Ioo (h x).2.1 (h y).2.2 hz change z ∈ Icc (h x) (h y) at hz rw [← h.image_Icc] at hz rcases hz with ⟨z, hz, rfl⟩ exact ⟨z, hs.out hx hy hz, rfl⟩ have hFt : ∀ x, F x ∈ t' := fun x => mem_image_of_mem _ (hf x) rcases F.exists_extension_forall_mem_of_isClosedEmbedding hFt (hne.image _) he with ⟨G, hG, hGF⟩ let g : C(Y, ℝ) := ⟨h.symm ∘ codRestrict G _ fun y => ht_sub (hG y), h.symm.continuous.comp <| G.continuous.subtype_mk _⟩ have hgG : ∀ {y a}, g y = a ↔ G y = h a := @fun y a => h.toEquiv.symm_apply_eq.trans Subtype.ext_iff refine ⟨g, fun y => ?_, ?_⟩ · rcases hG y with ⟨a, ha, hay⟩ convert ha exact hgG.2 hay.symm · ext x exact hgG.2 (congr_fun hGF _) /-- **Tietze extension theorem** for real-valued continuous maps, a version for a closed set. Let `s` be a closed set in a normal topological space `Y`. Let `f` be a continuous real-valued function on `s`. Let `t` be a nonempty convex set of real numbers (we use `OrdConnected` instead of `Convex` to automatically deduce this argument by typeclass search) such that `f x ∈ t` for all `x : s`. Then there exists a continuous real-valued function `g : C(Y, ℝ)` such that `g y ∈ t` for all `y` and `g.restrict s = f`. -/ theorem exists_restrict_eq_forall_mem_of_closed {s : Set Y} (f : C(s, ℝ)) {t : Set ℝ} [OrdConnected t] (ht : ∀ x, f x ∈ t) (hne : t.Nonempty) (hs : IsClosed s) : ∃ g : C(Y, ℝ), (∀ y, g y ∈ t) ∧ g.restrict s = f := let ⟨g, hgt, hgf⟩ := exists_extension_forall_mem_of_isClosedEmbedding f ht hne hs.isClosedEmbedding_subtypeVal ⟨g, hgt, coe_injective hgf⟩ end ContinuousMap /-- **Tietze extension theorem** for real-valued continuous maps. `ℝ` is a `TietzeExtension` space. -/ instance Real.instTietzeExtension : TietzeExtension ℝ where exists_restrict_eq' _s hs f := f.exists_restrict_eq_forall_mem_of_closed (fun _ => mem_univ _) univ_nonempty hs |>.imp fun _ ↦ (And.right ·) open NNReal in /-- **Tietze extension theorem** for nonnegative real-valued continuous maps. `ℝ≥0` is a `TietzeExtension` space. -/ instance NNReal.instTietzeExtension : TietzeExtension ℝ≥0 := .of_retract ⟨((↑) : ℝ≥0 → ℝ), by continuity⟩ ⟨Real.toNNReal, continuous_real_toNNReal⟩ <| by ext; simp
MonoOver.lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Kim Morrison -/ import Mathlib.CategoryTheory.Comma.Over.Pullback import Mathlib.CategoryTheory.Adjunction.Reflective import Mathlib.CategoryTheory.Adjunction.Restrict import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic /-! # Monomorphisms over a fixed object As preparation for defining `Subobject X`, we set up the theory for `MonoOver X := { f : Over X // Mono f.hom}`. Here `MonoOver X` is a thin category (a pair of objects has at most one morphism between them), so we can think of it as a preorder. However as it is not skeletal, it is not yet a partial order. `Subobject X` will be defined as the skeletalization of `MonoOver X`. We provide * `def pullback [HasPullbacks C] (f : X ⟶ Y) : MonoOver Y ⥤ MonoOver X` * `def map (f : X ⟶ Y) [Mono f] : MonoOver X ⥤ MonoOver Y` * `def «exists» [HasImages C] (f : X ⟶ Y) : MonoOver X ⥤ MonoOver Y` and prove their basic properties and relationships. ## Notes This development originally appeared in Bhavik Mehta's "Topos theory for Lean" repository, and was ported to mathlib by Kim Morrison. -/ universe v₁ v₂ u₁ u₂ noncomputable section namespace CategoryTheory open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Functor variable {C : Type u₁} [Category.{v₁} C] {X Y Z : C} variable {D : Type u₂} [Category.{v₂} D] /-- The category of monomorphisms into `X` as a full subcategory of the over category. This isn't skeletal, so it's not a partial order. Later we define `Subobject X` as the quotient of this by isomorphisms. -/ def MonoOver (X : C) := ObjectProperty.FullSubcategory fun f : Over X => Mono f.hom instance (X : C) : Category (MonoOver X) := ObjectProperty.FullSubcategory.category _ namespace MonoOver instance mono_obj_hom (S : MonoOver X) : Mono S.obj.hom := S.2 /-- Construct a `MonoOver X`. -/ @[simps] def mk' {X A : C} (f : A ⟶ X) [hf : Mono f] : MonoOver X where obj := Over.mk f property := hf /-- The inclusion from monomorphisms over X to morphisms over X. -/ def forget (X : C) : MonoOver X ⥤ Over X := ObjectProperty.ι _ instance : CoeOut (MonoOver X) C where coe Y := Y.obj.left @[simp] theorem forget_obj_left {f} : ((forget X).obj f).left = (f : C) := rfl @[simp] theorem mk'_coe' {X A : C} (f : A ⟶ X) [Mono f] : (mk' f : C) = A := rfl /-- Convenience notation for the underlying arrow of a monomorphism over X. -/ abbrev arrow (f : MonoOver X) : (f : C) ⟶ X := ((forget X).obj f).hom @[simp] theorem mk'_arrow {X A : C} (f : A ⟶ X) [Mono f] : (mk' f).arrow = f := rfl @[simp] theorem forget_obj_hom {f} : ((forget X).obj f).hom = f.arrow := rfl /-- The forget functor `MonoOver X ⥤ Over X` is fully faithful. -/ def fullyFaithfulForget (X : C) : (forget X).FullyFaithful := ObjectProperty.fullyFaithfulι _ instance : (forget X).Full := ObjectProperty.full_ι _ instance : (forget X).Faithful := ObjectProperty.faithful_ι _ instance mono (f : MonoOver X) : Mono f.arrow := f.property instance {X : C} {f : MonoOver X} : Mono ((MonoOver.forget X).obj f).hom := f.mono /-- The category of monomorphisms over X is a thin category,s which makes defining its skeleton easy. -/ instance isThin {X : C} : Quiver.IsThin (MonoOver X) := fun f g => ⟨by intro h₁ h₂ apply Over.OverMorphism.ext rw [← cancel_mono g.arrow] erw [Over.w h₁] erw [Over.w h₂]⟩ @[reassoc] theorem w {f g : MonoOver X} (k : f ⟶ g) : k.left ≫ g.arrow = f.arrow := Over.w _ /-- Convenience constructor for a morphism in monomorphisms over `X`. -/ abbrev homMk {f g : MonoOver X} (h : f.obj.left ⟶ g.obj.left) (w : h ≫ g.arrow = f.arrow := by cat_disch) : f ⟶ g := Over.homMk h w /-- Convenience constructor for an isomorphism in monomorphisms over `X`. -/ @[simps] def isoMk {f g : MonoOver X} (h : f.obj.left ≅ g.obj.left) (w : h.hom ≫ g.arrow = f.arrow := by cat_disch) : f ≅ g where hom := homMk h.hom w inv := homMk h.inv (by rw [h.inv_comp_eq, w]) /-- If `f : MonoOver X`, then `mk' f.arrow` is of course just `f`, but not definitionally, so we package it as an isomorphism. -/ @[simps!] def mk'ArrowIso {X : C} (f : MonoOver X) : mk' f.arrow ≅ f := isoMk (Iso.refl _) instance {A B : MonoOver X} (f : A ⟶ B) [IsIso f] : IsIso f.left := inferInstanceAs (IsIso ((MonoOver.forget _ ⋙ Over.forget _).map f)) lemma isIso_iff_isIso_left {A B : MonoOver X} (f : A ⟶ B) : IsIso f ↔ IsIso f.left := (isIso_iff_of_reflects_iso _ (MonoOver.forget X ⋙ Over.forget _)).symm /-- Lift a functor between over categories to a functor between `MonoOver` categories, given suitable evidence that morphisms are taken to monomorphisms. -/ @[simps] def lift {Y : D} (F : Over Y ⥤ Over X) (h : ∀ f : MonoOver Y, Mono (F.obj ((MonoOver.forget Y).obj f)).hom) : MonoOver Y ⥤ MonoOver X where obj f := ⟨_, h f⟩ map k := (MonoOver.forget Y ⋙ F).map k /-- Isomorphic functors `Over Y ⥤ Over X` lift to isomorphic functors `MonoOver Y ⥤ MonoOver X`. -/ def liftIso {Y : D} {F₁ F₂ : Over Y ⥤ Over X} (h₁ h₂) (i : F₁ ≅ F₂) : lift F₁ h₁ ≅ lift F₂ h₂ := Functor.fullyFaithfulCancelRight (MonoOver.forget X) (isoWhiskerLeft (MonoOver.forget Y) i) /-- `MonoOver.lift` commutes with composition of functors. -/ def liftComp {X Z : C} {Y : D} (F : Over X ⥤ Over Y) (G : Over Y ⥤ Over Z) (h₁ h₂) : lift F h₁ ⋙ lift G h₂ ≅ lift (F ⋙ G) fun f => h₂ ⟨_, h₁ f⟩ := Functor.fullyFaithfulCancelRight (MonoOver.forget _) (Iso.refl _) /-- `MonoOver.lift` preserves the identity functor. -/ def liftId : (lift (𝟭 (Over X)) fun f => f.2) ≅ 𝟭 _ := Functor.fullyFaithfulCancelRight (MonoOver.forget _) (Iso.refl _) @[simp] theorem lift_comm (F : Over Y ⥤ Over X) (h : ∀ f : MonoOver Y, Mono (F.obj ((MonoOver.forget Y).obj f)).hom) : lift F h ⋙ MonoOver.forget X = MonoOver.forget Y ⋙ F := rfl @[simp] theorem lift_obj_arrow {Y : D} (F : Over Y ⥤ Over X) (h : ∀ f : MonoOver Y, Mono (F.obj ((MonoOver.forget Y).obj f)).hom) (f : MonoOver Y) : ((lift F h).obj f).arrow = (F.obj ((forget Y).obj f)).hom := rfl /-- Monomorphisms over an object `f : Over A` in an over category are equivalent to monomorphisms over the source of `f`. -/ def slice {A : C} {f : Over A} (h₁ : ∀ (g : MonoOver f), Mono ((Over.iteratedSliceEquiv f).functor.obj ((forget f).obj g)).hom) (h₂ : ∀ (g : MonoOver f.left), Mono ((Over.iteratedSliceEquiv f).inverse.obj ((forget f.left).obj g)).hom) : MonoOver f ≌ MonoOver f.left where functor := MonoOver.lift f.iteratedSliceEquiv.functor h₁ inverse := MonoOver.lift f.iteratedSliceEquiv.inverse h₂ unitIso := MonoOver.liftId.symm ≪≫ MonoOver.liftIso _ _ f.iteratedSliceEquiv.unitIso ≪≫ (MonoOver.liftComp _ _ _ _).symm counitIso := MonoOver.liftComp _ _ _ _ ≪≫ MonoOver.liftIso _ _ f.iteratedSliceEquiv.counitIso ≪≫ MonoOver.liftId section Pullback variable [HasPullbacks C] /-- When `C` has pullbacks, a morphism `f : X ⟶ Y` induces a functor `MonoOver Y ⥤ MonoOver X`, by pulling back a monomorphism along `f`. -/ def pullback (f : X ⟶ Y) : MonoOver Y ⥤ MonoOver X := MonoOver.lift (Over.pullback f) (fun g => by haveI : Mono ((forget Y).obj g).hom := (inferInstance : Mono g.arrow) apply pullback.snd_of_mono) /-- pullback commutes with composition (up to a natural isomorphism) -/ def pullbackComp (f : X ⟶ Y) (g : Y ⟶ Z) : pullback (f ≫ g) ≅ pullback g ⋙ pullback f := liftIso _ _ (Over.pullbackComp _ _) ≪≫ (liftComp _ _ _ _).symm /-- pullback preserves the identity (up to a natural isomorphism) -/ def pullbackId : pullback (𝟙 X) ≅ 𝟭 _ := liftIso _ _ Over.pullbackId ≪≫ liftId @[simp] theorem pullback_obj_left (f : X ⟶ Y) (g : MonoOver Y) : ((pullback f).obj g : C) = Limits.pullback g.arrow f := rfl @[simp] theorem pullback_obj_arrow (f : X ⟶ Y) (g : MonoOver Y) : ((pullback f).obj g).arrow = pullback.snd _ _ := rfl end Pullback section IsPullback /-- Given two monomorphisms `S` and `T` over `X` and `Y` and two morphisms `f` and `f'` between them forming the following pullback square: ``` (T : C) -f'-> (S : C) | | T.arrow S.arrow | | v v Y -----f----> X ``` we get an isomorphism between `T` and the pullback of `S` along `f` through the `pullback` functor. -/ def pullbackObjIsoOfIsPullback [HasPullbacks C] {X Y : C} (f : Y ⟶ X) (S : MonoOver X) (T : MonoOver Y) (f' : (T : C) ⟶ (S : C)) (h : IsPullback f' T.arrow S.arrow f) : (pullback f).obj S ≅ T := isoMk ((IsPullback.isoPullback h).symm) (by simp) end IsPullback section Map /-- We can map monomorphisms over `X` to monomorphisms over `Y` by post-composition with a monomorphism `f : X ⟶ Y`. -/ def map (f : X ⟶ Y) [Mono f] : MonoOver X ⥤ MonoOver Y := lift (Over.map f) fun g => mono_comp g.arrow f /-- `MonoOver.map` commutes with composition (up to a natural isomorphism). -/ def mapComp (f : X ⟶ Y) (g : Y ⟶ Z) [Mono f] [Mono g] : map (f ≫ g) ≅ map f ⋙ map g := liftIso _ _ (Over.mapComp _ _) ≪≫ (liftComp _ _ _ _).symm variable (X) in /-- `MonoOver.map` preserves the identity (up to a natural isomorphism). -/ def mapId : map (𝟙 X) ≅ 𝟭 _ := liftIso _ _ (Over.mapId X) ≪≫ liftId @[simp] theorem map_obj_left (f : X ⟶ Y) [Mono f] (g : MonoOver X) : ((map f).obj g : C) = g.obj.left := rfl @[simp] theorem map_obj_arrow (f : X ⟶ Y) [Mono f] (g : MonoOver X) : ((map f).obj g).arrow = g.arrow ≫ f := rfl instance full_map (f : X ⟶ Y) [Mono f] : Functor.Full (map f) where map_surjective {g h} e := by refine ⟨homMk e.left ?_, rfl⟩ · rw [← cancel_mono f, assoc] apply w e instance faithful_map (f : X ⟶ Y) [Mono f] : Functor.Faithful (map f) where /-- Isomorphic objects have equivalent `MonoOver` categories. -/ @[simps] def mapIso {A B : C} (e : A ≅ B) : MonoOver A ≌ MonoOver B where functor := map e.hom inverse := map e.inv unitIso := ((mapComp _ _).symm ≪≫ eqToIso (by simp) ≪≫ (mapId _)).symm counitIso := (mapComp _ _).symm ≪≫ eqToIso (by simp) ≪≫ (mapId _) section variable (X) /-- An equivalence of categories `e` between `C` and `D` induces an equivalence between `MonoOver X` and `MonoOver (e.functor.obj X)` whenever `X` is an object of `C`. -/ @[simps] def congr (e : C ≌ D) : MonoOver X ≌ MonoOver (e.functor.obj X) where functor := lift (Over.post e.functor) fun f => by dsimp infer_instance inverse := (lift (Over.post e.inverse) fun f => by dsimp infer_instance) ⋙ (mapIso (e.unitIso.symm.app X)).functor unitIso := NatIso.ofComponents fun Y => isoMk (e.unitIso.app Y) counitIso := NatIso.ofComponents fun Y => isoMk (e.counitIso.app Y) end section variable [HasPullbacks C] /-- `map f` is left adjoint to `pullback f` when `f` is a monomorphism -/ def mapPullbackAdj (f : X ⟶ Y) [Mono f] : map f ⊣ pullback f := (Over.mapPullbackAdj f).restrictFullyFaithful (fullyFaithfulForget X) (fullyFaithfulForget Y) (Iso.refl _) (Iso.refl _) /-- `MonoOver.map f` followed by `MonoOver.pullback f` is the identity. -/ def pullbackMapSelf (f : X ⟶ Y) [Mono f] : map f ⋙ pullback f ≅ 𝟭 _ := (asIso (MonoOver.mapPullbackAdj f).unit).symm end end Map section Image variable (f : X ⟶ Y) [HasImage f] /-- The `MonoOver Y` for the image inclusion for a morphism `f : X ⟶ Y`. -/ def imageMonoOver (f : X ⟶ Y) [HasImage f] : MonoOver Y := MonoOver.mk' (image.ι f) @[simp] theorem imageMonoOver_arrow (f : X ⟶ Y) [HasImage f] : (imageMonoOver f).arrow = image.ι f := rfl end Image section Image variable [HasImages C] /-- Taking the image of a morphism gives a functor `Over X ⥤ MonoOver X`. -/ @[simps] def image : Over X ⥤ MonoOver X where obj f := imageMonoOver f.hom map {f g} k := by apply (forget X).preimage _ apply Over.homMk _ _ · exact image.lift { I := Limits.image _ m := image.ι g.hom e := k.left ≫ factorThruImage g.hom } · apply image.lift_fac /-- `MonoOver.image : Over X ⥤ MonoOver X` is left adjoint to `MonoOver.forget : MonoOver X ⥤ Over X` -/ def imageForgetAdj : image ⊣ forget X := Adjunction.mkOfHomEquiv { homEquiv := fun f g => { toFun := fun k => by apply Over.homMk (factorThruImage f.hom ≫ k.left) _ change (factorThruImage f.hom ≫ k.left) ≫ _ = f.hom rw [assoc, Over.w k] apply image.fac invFun := fun k => by refine Over.homMk ?_ ?_ · exact image.lift { I := g.obj.left m := g.arrow e := k.left fac := Over.w k } · apply image.lift_fac left_inv := fun _ => Subsingleton.elim _ _ right_inv := fun k => by ext simp } } instance : (forget X).IsRightAdjoint := ⟨_, ⟨imageForgetAdj⟩⟩ instance reflective : Reflective (forget X) where L := image adj := imageForgetAdj /-- Forgetting that a monomorphism over `X` is a monomorphism, then taking its image, is the identity functor. -/ def forgetImage : forget X ⋙ image ≅ 𝟭 (MonoOver X) := asIso (Adjunction.counit imageForgetAdj) end Image section Exists variable [HasImages C] /-- In the case where `f` is not a monomorphism but `C` has images, we can still take the "forward map" under it, which agrees with `MonoOver.map f`. -/ def «exists» (f : X ⟶ Y) : MonoOver X ⥤ MonoOver Y := forget _ ⋙ Over.map f ⋙ image instance faithful_exists (f : X ⟶ Y) : Functor.Faithful («exists» f) where /-- When `f : X ⟶ Y` is a monomorphism, `exists f` agrees with `map f`. -/ def existsIsoMap (f : X ⟶ Y) [Mono f] : «exists» f ≅ map f := NatIso.ofComponents (by intro Z suffices (forget _).obj ((«exists» f).obj Z) ≅ (forget _).obj ((map f).obj Z) by apply (forget _).preimageIso this apply Over.isoMk _ _ · apply imageMonoIsoSource (Z.arrow ≫ f) · apply imageMonoIsoSource_hom_self) /-- `exists` is adjoint to `pullback` when images exist -/ def existsPullbackAdj (f : X ⟶ Y) [HasPullbacks C] : «exists» f ⊣ pullback f := ((Over.mapPullbackAdj f).comp imageForgetAdj).restrictFullyFaithful (fullyFaithfulForget X) (Functor.FullyFaithful.id _) (Iso.refl _) (Iso.refl _) end Exists end MonoOver end CategoryTheory