filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
Encoding.lean
|
/-
Copyright (c) 2020 Pim Spelier, Daan van Gent. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Pim Spelier, Daan van Gent
-/
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Num.Lemmas
import Mathlib.Data.Option.Basic
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Tactic.DeriveFintype
/-!
# Encodings
This file contains the definition of a (finite) encoding, a map from a type to
strings in an alphabet, used in defining computability by Turing machines.
It also contains several examples:
## Examples
- `finEncodingNatBool` : a binary encoding of ℕ in a simple alphabet.
- `finEncodingNatΓ'` : a binary encoding of ℕ in the alphabet used for TM's.
- `unaryFinEncodingNat` : a unary encoding of ℕ
- `finEncodingBoolBool` : an encoding of bool.
-/
universe u v
open Cardinal
namespace Computability
/-- An encoding of a type in a certain alphabet, together with a decoding. -/
structure Encoding (α : Type u) where
/-- The alphabet of the encoding -/
Γ : Type v
/-- The encoding function -/
encode : α → List Γ
/-- The decoding function -/
decode : List Γ → Option α
/-- Decoding and encoding are inverses of each other. -/
decode_encode : ∀ x, decode (encode x) = some x
theorem Encoding.encode_injective {α : Type u} (e : Encoding α) : Function.Injective e.encode := by
refine fun _ _ h => Option.some_injective _ ?_
rw [← e.decode_encode, ← e.decode_encode, h]
/-- An encoding plus a guarantee of finiteness of the alphabet. -/
structure FinEncoding (α : Type u) extends Encoding.{u, 0} α where
/-- The alphabet of the encoding is finite -/
ΓFin : Fintype Γ
instance Γ.fintype {α : Type u} (e : FinEncoding α) : Fintype e.toEncoding.Γ :=
e.ΓFin
/-- A standard Turing machine alphabet, consisting of blank,bit0,bit1,bra,ket,comma. -/
inductive Γ'
| blank
| bit (b : Bool)
| bra
| ket
| comma
deriving DecidableEq, Fintype
instance inhabitedΓ' : Inhabited Γ' :=
⟨Γ'.blank⟩
/-- The natural inclusion of bool in Γ'. -/
def inclusionBoolΓ' : Bool → Γ' :=
Γ'.bit
/-- An arbitrary section of the natural inclusion of bool in Γ'. -/
def sectionΓ'Bool : Γ' → Bool
| Γ'.bit b => b
| _ => Inhabited.default
@[simp]
theorem sectionΓ'Bool_inclusionBoolΓ' {b} : sectionΓ'Bool (inclusionBoolΓ' b) = b := by
cases b <;> rfl
theorem inclusionBoolΓ'_injective : Function.Injective inclusionBoolΓ' :=
Function.HasLeftInverse.injective ⟨_, (fun _ => sectionΓ'Bool_inclusionBoolΓ')⟩
/-- An encoding function of the positive binary numbers in bool. -/
def encodePosNum : PosNum → List Bool
| PosNum.one => [true]
| PosNum.bit0 n => false :: encodePosNum n
| PosNum.bit1 n => true :: encodePosNum n
/-- An encoding function of the binary numbers in bool. -/
def encodeNum : Num → List Bool
| Num.zero => []
| Num.pos n => encodePosNum n
/-- An encoding function of ℕ in bool. -/
def encodeNat (n : ℕ) : List Bool :=
encodeNum n
/-- A decoding function from `List Bool` to the positive binary numbers. -/
def decodePosNum : List Bool → PosNum
| false :: l => PosNum.bit0 (decodePosNum l)
| true :: l => ite (l = []) PosNum.one (PosNum.bit1 (decodePosNum l))
| _ => PosNum.one
/-- A decoding function from `List Bool` to the binary numbers. -/
def decodeNum : List Bool → Num := fun l => ite (l = []) Num.zero <| decodePosNum l
/-- A decoding function from `List Bool` to ℕ. -/
def decodeNat : List Bool → Nat := fun l => decodeNum l
theorem encodePosNum_nonempty (n : PosNum) : encodePosNum n ≠ [] :=
PosNum.casesOn n (List.cons_ne_nil _ _) (fun _m => List.cons_ne_nil _ _) fun _m =>
List.cons_ne_nil _ _
@[simp] theorem decode_encodePosNum (n) : decodePosNum (encodePosNum n) = n := by
induction n with unfold encodePosNum decodePosNum
| one => rfl
| bit1 m hm =>
rw [hm]
exact if_neg (encodePosNum_nonempty m)
| bit0 m hm => exact congr_arg PosNum.bit0 hm
@[simp] theorem decode_encodeNum (n) : decodeNum (encodeNum n) = n := by
obtain - | n := n <;> unfold encodeNum decodeNum
· rfl
rw [decode_encodePosNum n]
rw [PosNum.cast_to_num]
exact if_neg (encodePosNum_nonempty n)
@[simp] theorem decode_encodeNat (n) : decodeNat (encodeNat n) = n := by
conv_rhs => rw [← Num.to_of_nat n]
exact congr_arg ((↑) : Num → ℕ) (decode_encodeNum n)
/-- A binary encoding of ℕ in bool. -/
def encodingNatBool : Encoding ℕ where
Γ := Bool
encode := encodeNat
decode n := some (decodeNat n)
decode_encode n := congr_arg _ (decode_encodeNat n)
/-- A binary fin_encoding of ℕ in bool. -/
def finEncodingNatBool : FinEncoding ℕ :=
⟨encodingNatBool, Bool.fintype⟩
/-- A binary encoding of ℕ in Γ'. -/
def encodingNatΓ' : Encoding ℕ where
Γ := Γ'
encode x := List.map inclusionBoolΓ' (encodeNat x)
decode x := some (decodeNat (List.map sectionΓ'Bool x))
decode_encode x := congr_arg _ <| by simp [Function.comp_def]
/-- A binary FinEncoding of ℕ in Γ'. -/
def finEncodingNatΓ' : FinEncoding ℕ :=
⟨encodingNatΓ', inferInstanceAs (Fintype Γ')⟩
/-- A unary encoding function of ℕ in bool. -/
def unaryEncodeNat : Nat → List Bool
| 0 => []
| n + 1 => true :: unaryEncodeNat n
/-- A unary decoding function from `List Bool` to ℕ. -/
def unaryDecodeNat : List Bool → Nat :=
List.length
@[simp] theorem unary_decode_encode_nat : ∀ n, unaryDecodeNat (unaryEncodeNat n) = n := fun n =>
Nat.rec rfl (fun (_m : ℕ) hm => (congr_arg Nat.succ hm.symm).symm) n
/-- A unary fin_encoding of ℕ. -/
def unaryFinEncodingNat : FinEncoding ℕ where
Γ := Bool
encode := unaryEncodeNat
decode n := some (unaryDecodeNat n)
decode_encode n := congr_arg _ (unary_decode_encode_nat n)
ΓFin := Bool.fintype
/-- An encoding function of bool in bool. -/
def encodeBool : Bool → List Bool := pure
/-- A decoding function from `List Bool` to bool. -/
def decodeBool : List Bool → Bool
| b :: _ => b
| _ => Inhabited.default
@[simp] theorem decode_encodeBool (b : Bool) : decodeBool (encodeBool b) = b := rfl
/-- A fin_encoding of bool in bool. -/
def finEncodingBoolBool : FinEncoding Bool where
Γ := Bool
encode := encodeBool
decode x := some (decodeBool x)
decode_encode x := congr_arg _ (decode_encodeBool x)
ΓFin := Bool.fintype
instance inhabitedFinEncoding : Inhabited (FinEncoding Bool) :=
⟨finEncodingBoolBool⟩
instance inhabitedEncoding : Inhabited (Encoding Bool) :=
⟨finEncodingBoolBool.toEncoding⟩
theorem Encoding.card_le_card_list {α : Type u} (e : Encoding.{u, v} α) :
Cardinal.lift.{v} #α ≤ Cardinal.lift.{u} #(List e.Γ) :=
Cardinal.lift_mk_le'.2 ⟨⟨e.encode, e.encode_injective⟩⟩
theorem Encoding.card_le_aleph0 {α : Type u} (e : Encoding.{u, v} α) [Countable e.Γ] :
#α ≤ ℵ₀ :=
haveI : Countable α := e.encode_injective.countable
Cardinal.mk_le_aleph0
theorem FinEncoding.card_le_aleph0 {α : Type u} (e : FinEncoding α) : #α ≤ ℵ₀ :=
e.toEncoding.card_le_aleph0
end Computability
|
classfun.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient finalg action gproduct zmodp.
From mathcomp Require Import commutator cyclic center pgroup sylow matrix.
From mathcomp Require Import vector falgebra ssrnum algC algnum archimedean.
(******************************************************************************)
(* This file contains the basic theory of class functions: *)
(* 'CF(G) == the type of class functions on G : {group gT}, i.e., *)
(* which map gT to the type algC of complex algebraics, *)
(* have support in G, and are constant on each conjugacy *)
(* class of G. 'CF(G) implements the falgType interface of *)
(* finite-dimensional F-algebras. *)
(* The identity 1 : 'CF(G) is the indicator function of G, *)
(* and (later) the principal character. *)
(* --> The %CF scope (cfun_scope) is bound to the 'CF(_) types. *)
(* 'CF(G)%VS == the (total) vector space of 'CF(G). *)
(* 'CF(G, A) == the subspace of functions in 'CF(G) with support in A. *)
(* phi x == the image of x : gT under phi : 'CF(G). *)
(* #[phi]%CF == the multiplicative order of phi : 'CF(G). *)
(* cfker phi == the kernel of phi : 'CF(G); note that cfker phi <| G. *)
(* cfaithful phi <=> phi : 'CF(G) is faithful (has a trivial kernel). *)
(* '1_A == the indicator function of A as a function of 'CF(G). *)
(* (Provided A <| G; G is determined by the context.) *)
(* phi^*%CF == the function conjugate to phi : 'CF(G). *)
(* cfAut u phi == the function conjugate to phi by an algC-automorphism u *)
(* phi^u The notation "_ ^u" is only reserved; it is up to *)
(* clients to set Notation "phi ^u" := (cfAut u phi). *)
(* '[phi, psi] == the convolution of phi, psi : 'CF(G) over G, normalised *)
(* '[phi, psi]_G by #|G| so that '[1, 1]_G = 1 (G is usually inferred). *)
(* cfdotr psi phi == '[phi, psi] (self-expanding). *)
(* '[phi], '[phi]_G == the squared norm '[phi, phi] of phi : 'CF(G). *)
(* orthogonal R S <=> each phi in R : seq 'CF(G) is orthogonal to each psi in *)
(* S, i.e., '[phi, psi] = 0. As 'CF(G) coerces to seq, one *)
(* can write orthogonal phi S and orthogonal phi psi. *)
(* pairwise_orthogonal S <=> the class functions in S are pairwise orthogonal *)
(* AND non-zero. *)
(* orthonormal S <=> S is pairwise orthogonal and all class functions in S *)
(* have norm 1. *)
(* isometry tau <-> tau : 'CF(D) -> 'CF(R) is an isometry, mapping *)
(* '[_, _]_D to '[_, _]_R. *)
(* {in CD, isometry tau, to CR} <-> in the domain CD, tau is an isometry *)
(* whose range is contained in CR. *)
(* cfReal phi <=> phi is real, i.e., phi^* == phi. *)
(* cfAut_closed u S <-> S : seq 'CF(G) is closed under conjugation by u. *)
(* cfConjC_closed S <-> S : seq 'CF(G) is closed under complex conjugation. *)
(* conjC_subset S1 S2 <-> S1 : seq 'CF(G) represents a subset of S2 closed *)
(* under complex conjugation. *)
(* := [/\ uniq S1, {subset S1 <= S2} & cfConjC_closed S1]. *)
(* 'Res[H] phi == the restriction of phi : 'CF(G) to a function of 'CF(H) *)
(* 'Res[H, G] phi 'Res[H] phi x = phi x if x \in H (when H \subset G), *)
(* 'Res phi 'Res[H] phi x = 0 if x \notin H. The syntax variants *)
(* allow H and G to be inferred; the default is to specify *)
(* H explicitly, and infer G from the type of phi. *)
(* 'Ind[G] phi == the class function of 'CF(G) induced by phi : 'CF(H), *)
(* 'Ind[G, H] phi when H \subset G. As with 'Res phi, both G and H can *)
(* 'Ind phi be inferred, though usually G isn't. *)
(* cfMorph phi == the class function in 'CF(G) that maps x to phi (f x), *)
(* where phi : 'CF(f @* G), provided G \subset 'dom f. *)
(* cfIsom isoGR phi == the class function in 'CF(R) that maps f x to phi x, *)
(* given isoGR : isom G R f, f : {morphism G >-> rT} and *)
(* phi : 'CF(G). *)
(* (phi %% H)%CF == special case of cfMorph phi, when phi : 'CF(G / H). *)
(* (phi / H)%CF == the class function in 'CF(G / H) that coincides with *)
(* phi : 'CF(G) on cosets of H \subset cfker phi. *)
(* For a group G that is a semidirect product (defG : K ><| H = G), we have *)
(* cfSdprod KxH phi == for phi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* For a group G that is a direct product (with KxH : K \x H = G), we have *)
(* cfDprodl KxH phi == for phi : 'CF(K), the class function of 'CF(G) that *)
(* maps k * h to phi k when k \in K and h \in H. *)
(* cfDprodr KxH psi == for psi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* cfDprod KxH phi psi == for phi : 'CF(K), psi : 'CF(H), the class function *)
(* of 'CF(G) that maps k * h to phi k * psi h (this is *)
(* the product of the two functions above). *)
(* Finally, given defG : \big[dprod/1]_(i | P i) A i = G, with G and A i *)
(* groups and i ranges over a finType, we have *)
(* cfBigdprodi defG phi == for phi : 'CF(A i) s.t. P i, the class function *)
(* of 'CF(G) that maps x to phi x_i, where x_i is the *)
(* (A i)-component of x : G. *)
(* cfBigdprod defG phi == for phi : forall i, 'CF(A i), the class function *)
(* of 'CF(G) that maps x to \prod_(i | P i) phi i x_i, *)
(* where x_i is the (A i)-component of x : G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope cfun_scope.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Delimit Scope cfun_scope with CF.
Reserved Notation "''CF' ( G , A )" (format "''CF' ( G , A )").
Reserved Notation "''CF' ( G )" (format "''CF' ( G )").
Reserved Notation "''1_' G" (at level 8, G at level 2, format "''1_' G").
Reserved Notation "''Res[' H , G ]". (* only parsing *)
Reserved Notation "''Res[' H ]" (format "''Res[' H ]").
Reserved Notation "''Res'". (* only parsing *)
Reserved Notation "''Ind[' G , H ]". (* only parsing *)
Reserved Notation "''Ind[' G ]". (* only "''Ind[' G ]" *)
Reserved Notation "''Ind'". (* only parsing *)
Reserved Notation "'[ phi , psi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "'[ phi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "phi ^u" (format "phi ^u").
Section AlgC.
(* Arithmetic properties of group orders in the characteristic 0 field algC. *)
Variable (gT : finGroupType).
Implicit Types (G : {group gT}) (B : {set gT}).
Lemma neq0CG G : (#|G|)%:R != 0 :> algC. Proof. exact: natrG_neq0. Qed.
Lemma neq0CiG G B : (#|G : B|)%:R != 0 :> algC.
Proof. exact: natr_indexg_neq0. Qed.
Lemma gt0CG G : 0 < #|G|%:R :> algC. Proof. exact: natrG_gt0. Qed.
Lemma gt0CiG G B : 0 < #|G : B|%:R :> algC. Proof. exact: natr_indexg_gt0. Qed.
Lemma algC'G_pchar G : [pchar algC]^'.-group G.
Proof. by apply/pgroupP=> p _; rewrite inE /= pchar_num. Qed.
End AlgC.
#[deprecated(since="mathcomp 2.4.0", note="Use algC'G_pchar instead.")]
Notation algC'G := (algC'G_pchar) (only parsing).
Section Defs.
Variable gT : finGroupType.
Definition is_class_fun (B : {set gT}) (f : {ffun gT -> algC}) :=
[forall x, forall y in B, f (x ^ y) == f x] && (support f \subset B).
Lemma intro_class_fun (G : {group gT}) f :
{in G &, forall x y, f (x ^ y) = f x} ->
(forall x, x \notin G -> f x = 0) ->
is_class_fun G (finfun f).
Proof.
move=> fJ Gf; apply/andP; split; last first.
by apply/supportP=> x notAf; rewrite ffunE Gf.
apply/'forall_eqfun_inP=> x y Gy; rewrite !ffunE.
by have [/fJ-> // | notGx] := boolP (x \in G); rewrite !Gf ?groupJr.
Qed.
Variable B : {set gT}.
Local Notation G := <<B>>.
Record classfun : predArgType :=
Classfun {cfun_val; _ : is_class_fun G cfun_val}.
Implicit Types phi psi xi : classfun.
(* The default expansion lemma cfunE requires key = 0. *)
Fact classfun_key : unit. Proof. by []. Qed.
Definition Cfun := locked_with classfun_key (fun flag : nat => Classfun).
HB.instance Definition _ := [isSub for cfun_val].
HB.instance Definition _ := [Choice of classfun by <:].
Definition cfun_eqType : eqType := classfun.
Definition fun_of_cfun phi := cfun_val phi : gT -> algC.
Coercion fun_of_cfun : classfun >-> Funclass.
Lemma cfunElock k f fP : @Cfun k (finfun f) fP =1 f.
Proof. by rewrite locked_withE; apply: ffunE. Qed.
Lemma cfunE f fP : @Cfun 0 (finfun f) fP =1 f.
Proof. exact: cfunElock. Qed.
Lemma cfunP phi psi : phi =1 psi <-> phi = psi.
Proof. by split=> [/ffunP/val_inj | ->]. Qed.
Lemma cfun0gen phi x : x \notin G -> phi x = 0.
Proof. by case: phi => f fP; case: (andP fP) => _ /supportP; apply. Qed.
Lemma cfun_in_genP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof.
move=> eq_phi; apply/cfunP=> x.
by have [/eq_phi-> // | notAx] := boolP (x \in G); rewrite !cfun0gen.
Qed.
Lemma cfunJgen phi x y : y \in G -> phi (x ^ y) = phi x.
Proof.
case: phi => f fP Gy; apply/eqP.
by case: (andP fP) => /'forall_forall_inP->.
Qed.
Fact cfun_zero_subproof : is_class_fun G (0 : {ffun _}).
Proof. exact: intro_class_fun. Qed.
Definition cfun_zero := Cfun 0 cfun_zero_subproof.
Fact cfun_comp_subproof f phi :
f 0 = 0 -> is_class_fun G [ffun x => f (phi x)].
Proof.
by move=> f0; apply: intro_class_fun => [x y _ /cfunJgen | x /cfun0gen] ->.
Qed.
Definition cfun_comp f f0 phi := Cfun 0 (@cfun_comp_subproof f phi f0).
Definition cfun_opp := cfun_comp (oppr0 _).
Fact cfun_add_subproof phi psi : is_class_fun G [ffun x => phi x + psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite !cfun0gen ?add0r.
Qed.
Definition cfun_add phi psi := Cfun 0 (cfun_add_subproof phi psi).
Fact cfun_indicator_subproof (A : {set gT}) :
is_class_fun G [ffun x => ((x \in G) && (x ^: G \subset A))%:R].
Proof.
apply: intro_class_fun => [x y Gx Gy | x /negbTE/= -> //].
by rewrite groupJr ?classGidl.
Qed.
Definition cfun_indicator A := Cfun 1 (cfun_indicator_subproof A).
Local Notation "''1_' A" := (cfun_indicator A) : ring_scope.
Lemma cfun1Egen x : '1_G x = (x \in G)%:R.
Proof. by rewrite cfunElock andb_idr // => /class_subG->. Qed.
Fact cfun_mul_subproof phi psi : is_class_fun G [ffun x => phi x * psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite cfun0gen ?mul0r.
Qed.
Definition cfun_mul phi psi := Cfun 0 (cfun_mul_subproof phi psi).
Definition cfun_unit := [pred phi : classfun | [forall x in G, phi x != 0]].
Definition cfun_inv phi :=
if phi \in cfun_unit then cfun_comp (invr0 _) phi else phi.
Definition cfun_scale a := cfun_comp (mulr0 a).
Fact cfun_addA : associative cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE addrA. Qed.
Fact cfun_addC : commutative cfun_add.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE addrC. Qed.
Fact cfun_add0 : left_id cfun_zero cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE add0r. Qed.
Fact cfun_addN : left_inverse cfun_zero cfun_opp cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build classfun
cfun_addA cfun_addC cfun_add0 cfun_addN.
Lemma muln_cfunE phi n x : (phi *+ n) x = phi x *+ n.
Proof. by elim: n => [|n IHn]; rewrite ?mulrS !cfunE ?IHn. Qed.
Lemma sum_cfunE I r (P : pred I) (phi : I -> classfun) x :
(\sum_(i <- r | P i) phi i) x = \sum_(i <- r | P i) (phi i) x.
Proof. by elim/big_rec2: _ => [|i _ psi _ <-]; rewrite cfunE. Qed.
Fact cfun_mulA : associative cfun_mul.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_mulC : commutative cfun_mul.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE mulrC. Qed.
Fact cfun_mul1 : left_id '1_G cfun_mul.
Proof.
by move=> phi; apply: cfun_in_genP => x Gx; rewrite !cfunE cfun1Egen Gx mul1r.
Qed.
Fact cfun_mulD : left_distributive cfun_mul cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
Fact cfun_nz1 : '1_G != 0.
Proof.
by apply/eqP=> /cfunP/(_ 1%g)/eqP; rewrite cfun1Egen cfunE group1 oner_eq0.
Qed.
HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build classfun
cfun_mulA cfun_mulC cfun_mul1 cfun_mulD cfun_nz1.
Definition cfun_nzRingType : nzRingType := classfun.
#[deprecated(since="mathcomp 2.4.0",
note="Use cfun_nzRingType instead.")]
Notation cfun_ringType := (cfun_nzRingType) (only parsing).
Lemma expS_cfunE phi n x : (phi ^+ n.+1) x = phi x ^+ n.+1.
Proof. by elim: n => //= n IHn; rewrite !cfunE IHn. Qed.
Fact cfun_mulV : {in cfun_unit, left_inverse 1 cfun_inv *%R}.
Proof.
move=> phi Uphi; rewrite /cfun_inv Uphi; apply/cfun_in_genP=> x Gx.
by rewrite !cfunE cfun1Egen Gx mulVf ?(forall_inP Uphi).
Qed.
Fact cfun_unitP phi psi : psi * phi = 1 -> phi \in cfun_unit.
Proof.
move/cfunP=> phiK; apply/forall_inP=> x Gx; rewrite -unitfE; apply/unitrP.
by exists (psi x); have:= phiK x; rewrite !cfunE cfun1Egen Gx mulrC.
Qed.
Fact cfun_inv0id : {in [predC cfun_unit], cfun_inv =1 id}.
Proof. by rewrite /cfun_inv => phi /negbTE/= ->. Qed.
HB.instance Definition _ :=
GRing.ComNzRing_hasMulInverse.Build classfun cfun_mulV cfun_unitP cfun_inv0id.
Fact cfun_scaleA a b phi :
cfun_scale a (cfun_scale b phi) = cfun_scale (a * b) phi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scale1 : left_id 1 cfun_scale.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE mul1r. Qed.
Fact cfun_scaleDr : right_distributive cfun_scale +%R.
Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunE mulrDr. Qed.
Fact cfun_scaleDl phi : {morph cfun_scale^~ phi : a b / a + b}.
Proof. by move=> a b; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build algC classfun
cfun_scaleA cfun_scale1 cfun_scaleDr cfun_scaleDl.
Fact cfun_scaleAl a phi psi : a *: (phi * psi) = (a *: phi) * psi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scaleAr a phi psi : a *: (phi * psi) = phi * (a *: psi).
Proof. by rewrite !(mulrC phi) cfun_scaleAl. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build algC classfun
cfun_scaleAl.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build algC classfun
cfun_scaleAr.
Section Automorphism.
Variable u : {rmorphism algC -> algC}.
Definition cfAut := cfun_comp (rmorph0 u).
Lemma cfAut_cfun1i A : cfAut '1_A = '1_A.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cfAutZ a phi : cfAut (a *: phi) = u a *: cfAut phi.
Proof. by apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
Lemma cfAut_is_zmod_morphism : zmod_morphism cfAut.
Proof.
by move=> phi psi; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE /= rmorphB.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_zmod_morphism` instead")]
Definition cfAut_is_additive := cfAut_is_zmod_morphism.
Lemma cfAut_is_monoid_morphism : monoid_morphism cfAut.
Proof.
by split=> [|phi psi]; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE rmorphM.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_monoid_morphism` instead")]
Definition cfAut_is_multiplicative :=
(fun g => (g.2,g.1)) cfAut_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build classfun classfun cfAut
cfAut_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build classfun classfun cfAut
cfAut_is_monoid_morphism.
Lemma cfAut_cfun1 : cfAut 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfAut_scalable : scalable_for (u \; *:%R) cfAut.
Proof. by move=> a phi; apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build algC classfun classfun (u \; *:%R) cfAut
cfAut_scalable.
Definition cfAut_closed (S : seq classfun) :=
{in S, forall phi, cfAut phi \in S}.
End Automorphism.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Definition cfReal phi := cfAut conjC phi == phi.
Definition cfConjC_subset (S1 S2 : seq classfun) :=
[/\ uniq S1, {subset S1 <= S2} & cfAut_closed conjC S1].
Fact cfun_vect_iso : Vector.axiom #|classes G| classfun.
Proof.
exists (fun phi => \row_i phi (repr (enum_val i))) => [a phi psi|].
by apply/rowP=> i; rewrite !(mxE, cfunE).
set n := #|_|; pose eK x : 'I_n := enum_rank_in (classes1 _) (x ^: G).
have rV2vP v : is_class_fun G [ffun x => v (eK x) *+ (x \in G)].
apply: intro_class_fun => [x y Gx Gy | x /negbTE/=-> //].
by rewrite groupJr // /eK classGidl.
exists (fun v : 'rV_n => Cfun 0 (rV2vP (v 0))) => [phi | v].
apply/cfun_in_genP=> x Gx; rewrite cfunE Gx mxE enum_rankK_in ?mem_classes //.
by have [y Gy ->] := repr_class <<B>> x; rewrite cfunJgen.
apply/rowP=> i; rewrite mxE cfunE; have /imsetP[x Gx def_i] := enum_valP i.
rewrite def_i; have [y Gy ->] := repr_class <<B>> x.
by rewrite groupJ // /eK classGidl // -def_i enum_valK_in.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build algC classfun cfun_vect_iso.
Definition cfun_vectType : vectType _ := classfun.
Definition cfun_base A : #|classes B ::&: A|.-tuple classfun :=
[tuple of [seq '1_xB | xB in classes B ::&: A]].
Definition classfun_on A := <<cfun_base A>>%VS.
Definition cfdot phi psi := #|B|%:R^-1 * \sum_(x in B) phi x * (psi x)^*.
Definition cfdotr psi phi := cfdot phi psi.
Definition cfnorm phi := cfdot phi phi.
Coercion seq_of_cfun phi := [:: phi].
Definition cforder phi := \big[lcmn/1]_(x in <<B>>) #[phi x]%C.
End Defs.
Bind Scope cfun_scope with classfun.
Arguments classfun {gT} B%_g.
Arguments classfun_on {gT} B%_g A%_g.
Arguments cfun_indicator {gT} B%_g.
Arguments cfAut {gT B%_g} u phi%_CF.
Arguments cfReal {gT B%_g} phi%_CF.
Arguments cfdot {gT B%_g} phi%_CF psi%_CF.
Arguments cfdotr {gT B%_g} psi%_CF phi%_CF /.
Arguments cfnorm {gT B%_g} phi%_CF /.
Notation "''CF' ( G )" := (classfun G) : type_scope.
Notation "''CF' ( G )" := (@fullv _ (cfun_vectType G)) : vspace_scope.
Notation "''1_' A" := (cfun_indicator _ A) : ring_scope.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Notation "1" := (@GRing.one (cfun_nzRingType _)) (only parsing) : cfun_scope.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Notation "phi ^*" := (cfAut conjC phi) : cfun_scope.
Notation cfConjC_closed := (cfAut_closed conjC).
Prenex Implicits cfReal.
(* Workaround for overeager projection reduction. *)
Notation eqcfP := (@eqP (cfun_eqType _) _ _) (only parsing).
Notation "#[ phi ]" := (cforder phi) : cfun_scope.
Notation "''[' u , v ]_ G":= (@cfdot _ G u v) (only parsing) : ring_scope.
Notation "''[' u , v ]" := (cfdot u v) : ring_scope.
Notation "''[' u ]_ G" := '[u, u]_G (only parsing) : ring_scope.
Notation "''[' u ]" := '[u, u] : ring_scope.
Section Predicates.
Variables (gT rT : finGroupType) (D : {set gT}) (R : {set rT}).
Implicit Types (phi psi : 'CF(D)) (S : seq 'CF(D)) (tau : 'CF(D) -> 'CF(R)).
Definition cfker phi := [set x in D | [forall y, phi (x * y)%g == phi y]].
Definition cfaithful phi := cfker phi \subset [1].
Definition ortho_rec S1 S2 :=
all [pred phi | all [pred psi | '[phi, psi] == 0] S2] S1.
Definition orthogonal := ortho_rec.
Arguments orthogonal : simpl never.
Fixpoint pair_ortho_rec S :=
if S is psi :: S' then ortho_rec psi S' && pair_ortho_rec S' else true.
(* We exclude 0 from pairwise orthogonal sets. *)
Definition pairwise_orthogonal S := (0 \notin S) && pair_ortho_rec S.
Definition orthonormal S := all [pred psi | '[psi] == 1] S && pair_ortho_rec S.
Definition isometry tau := forall phi psi, '[tau phi, tau psi] = '[phi, psi].
Definition isometry_from_to mCFD tau mCFR :=
prop_in2 mCFD (inPhantom (isometry tau))
/\ prop_in1 mCFD (inPhantom (forall phi, in_mem (tau phi) mCFR)).
End Predicates.
Arguments orthogonal : simpl never.
Arguments cfker {gT D%_g} phi%_CF.
Arguments cfaithful {gT D%_g} phi%_CF.
Arguments orthogonal {gT D%_g} S1%_CF S2%_CF.
Arguments pairwise_orthogonal {gT D%_g} S%_CF.
Arguments orthonormal {gT D%_g} S%_CF.
Arguments isometry {gT rT D%_g R%_g} tau%_CF.
Notation "{ 'in' CFD , 'isometry' tau , 'to' CFR }" :=
(isometry_from_to (mem CFD) tau (mem CFR))
(format "{ 'in' CFD , 'isometry' tau , 'to' CFR }")
: type_scope.
Section ClassFun.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (A B : {set gT}) (H K : {group gT}) (phi psi xi : 'CF(G)).
Local Notation "''1_' A" := (cfun_indicator G A).
Lemma cfun0 phi x : x \notin G -> phi x = 0.
Proof. by rewrite -{1}(genGid G) => /(cfun0gen phi). Qed.
Lemma support_cfun phi : support phi \subset G.
Proof. by apply/subsetP=> g; apply: contraR => /cfun0->. Qed.
Lemma cfunJ phi x y : y \in G -> phi (x ^ y) = phi x.
Proof. by rewrite -{1}(genGid G) => /(cfunJgen phi)->. Qed.
Lemma cfun_repr phi x : phi (repr (x ^: G)) = phi x.
Proof. by have [y Gy ->] := repr_class G x; apply: cfunJ. Qed.
Lemma cfun_inP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof. by rewrite -{1}genGid => /cfun_in_genP. Qed.
Lemma cfuniE A x : A <| G -> '1_A x = (x \in A)%:R.
Proof.
case/andP=> sAG nAG; rewrite cfunElock genGid.
by rewrite class_sub_norm // andb_idl // => /(subsetP sAG).
Qed.
Lemma support_cfuni A : A <| G -> support '1_A =i A.
Proof. by move=> nsAG x; rewrite !inE cfuniE // pnatr_eq0 -lt0n lt0b. Qed.
Lemma eq_mul_cfuni A phi : A <| G -> {in A, phi * '1_A =1 phi}.
Proof. by move=> nsAG x Ax; rewrite cfunE cfuniE // Ax mulr1. Qed.
Lemma eq_cfuni A : A <| G -> {in A, '1_A =1 (1 : 'CF(G))}.
Proof. by rewrite -['1_A]mul1r; apply: eq_mul_cfuni. Qed.
Lemma cfuniG : '1_G = 1.
Proof. by rewrite -[G in '1_G]genGid. Qed.
Lemma cfun1E g : (1 : 'CF(G)) g = (g \in G)%:R.
Proof. by rewrite -cfuniG cfuniE. Qed.
Lemma cfun11 : (1 : 'CF(G)) 1%g = 1.
Proof. by rewrite cfun1E group1. Qed.
Lemma prod_cfunE I r (P : pred I) (phi : I -> 'CF(G)) x :
x \in G -> (\prod_(i <- r | P i) phi i) x = \prod_(i <- r | P i) (phi i) x.
Proof.
by move=> Gx; elim/big_rec2: _ => [|i _ psi _ <-]; rewrite ?cfunE ?cfun1E ?Gx.
Qed.
Lemma exp_cfunE phi n x : x \in G -> (phi ^+ n) x = phi x ^+ n.
Proof. by rewrite -[n]card_ord -!prodr_const; apply: prod_cfunE. Qed.
Lemma mul_cfuni A B : '1_A * '1_B = '1_(A :&: B) :> 'CF(G).
Proof.
apply/cfunP=> g; rewrite !cfunElock -natrM mulnb subsetI.
by rewrite andbCA !andbA andbb.
Qed.
Lemma cfun_classE x y : '1_(x ^: G) y = ((x \in G) && (y \in x ^: G))%:R.
Proof.
rewrite cfunElock genGid class_sub_norm ?class_norm //; congr (_ : bool)%:R.
by apply: andb_id2r => /imsetP[z Gz ->]; rewrite groupJr.
Qed.
Lemma cfun_on_sum A :
'CF(G, A) = (\sum_(xG in classes G | xG \subset A) <['1_xG]>)%VS.
Proof.
by rewrite ['CF(G, A)]span_def big_image; apply: eq_bigl => xG; rewrite !inE.
Qed.
Lemma cfun_onP A phi :
reflect (forall x, x \notin A -> phi x = 0) (phi \in 'CF(G, A)).
Proof.
apply: (iffP idP) => [/coord_span-> x notAx | Aphi].
set b := cfun_base G A; rewrite sum_cfunE big1 // => i _; rewrite cfunE.
have /mapP[xG]: b`_i \in b by rewrite -tnth_nth mem_tnth.
rewrite mem_enum => /setIdP[/imsetP[y Gy ->] Ay] ->.
by rewrite cfun_classE Gy (contraNF (subsetP Ay x)) ?mulr0.
suffices <-: \sum_(xG in classes G) phi (repr xG) *: '1_xG = phi.
apply: memv_suml => _ /imsetP[x Gx ->]; rewrite rpredZeq cfun_repr.
have [s_xG_A | /subsetPn[_ /imsetP[y Gy ->]]] := boolP (x ^: G \subset A).
by rewrite cfun_on_sum [_ \in _](sumv_sup (x ^: G)) ?mem_classes ?orbT.
by move/Aphi; rewrite cfunJ // => ->; rewrite eqxx.
apply/cfun_inP=> x Gx; rewrite sum_cfunE (bigD1 (x ^: G)) ?mem_classes //=.
rewrite cfunE cfun_repr cfun_classE Gx class_refl mulr1.
rewrite big1 ?addr0 // => _ /andP[/imsetP[y Gy ->]]; apply: contraNeq.
rewrite cfunE cfun_repr cfun_classE Gy mulf_eq0 => /norP[_].
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Arguments cfun_onP {A phi}.
Lemma cfun_on0 A phi x : phi \in 'CF(G, A) -> x \notin A -> phi x = 0.
Proof. by move/cfun_onP; apply. Qed.
Lemma sum_by_classes (R : nzRingType) (F : gT -> R) :
{in G &, forall g h, F (g ^ h) = F g} ->
\sum_(g in G) F g = \sum_(xG in classes G) #|xG|%:R * F (repr xG).
Proof.
move=> FJ; rewrite {1}(partition_big _ _ ((@mem_classes gT)^~ G)) /=.
apply: eq_bigr => _ /imsetP[x Gx ->]; have [y Gy ->] := repr_class G x.
rewrite mulr_natl -sumr_const FJ {y Gy}//; apply/esym/eq_big=> y /=.
apply/idP/andP=> [xGy | [Gy /eqP<-]]; last exact: class_refl.
by rewrite (class_eqP xGy) (subsetP (class_subG Gx (subxx _))).
by case/imsetP=> z Gz ->; rewrite FJ.
Qed.
Lemma cfun_base_free A : free (cfun_base G A).
Proof.
have b_i (i : 'I_#|classes G ::&: A|) : (cfun_base G A)`_i = '1_(enum_val i).
by rewrite /enum_val -!tnth_nth tnth_map.
apply/freeP => s S0 i; move/cfunP/(_ (repr (enum_val i))): S0.
rewrite sum_cfunE (bigD1 i) //= big1 ?addr0 => [|j].
rewrite b_i !cfunE; have /setIdP[/imsetP[x Gx ->] _] := enum_valP i.
by rewrite cfun_repr cfun_classE Gx class_refl mulr1.
apply: contraNeq; rewrite b_i !cfunE mulf_eq0 => /norP[_].
rewrite -(inj_eq enum_val_inj).
have /setIdP[/imsetP[x _ ->] _] := enum_valP i; rewrite cfun_repr.
have /setIdP[/imsetP[y Gy ->] _] := enum_valP j; rewrite cfun_classE Gy.
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Lemma dim_cfun : \dim 'CF(G) = #|classes G|.
Proof. by rewrite dimvf /dim /= genGid. Qed.
Lemma dim_cfun_on A : \dim 'CF(G, A) = #|classes G ::&: A|.
Proof. by rewrite (eqnP (cfun_base_free A)) size_tuple. Qed.
Lemma dim_cfun_on_abelian A : abelian G -> A \subset G -> \dim 'CF(G, A) = #|A|.
Proof.
move/abelian_classP=> cGG sAG; rewrite -(card_imset _ set1_inj) dim_cfun_on.
apply/eq_card=> xG; rewrite !inE.
apply/andP/imsetP=> [[/imsetP[x Gx ->] Ax] | [x Ax ->]] {xG}.
by rewrite cGG ?sub1set // in Ax *; exists x.
by rewrite -{1}(cGG x) ?mem_classes ?(subsetP sAG) ?sub1set.
Qed.
Lemma cfuni_on A : '1_A \in 'CF(G, A).
Proof.
apply/cfun_onP=> x notAx; rewrite cfunElock genGid.
by case: andP => // [[_ s_xG_A]]; rewrite (subsetP s_xG_A) ?class_refl in notAx.
Qed.
Lemma mul_cfuni_on A phi : phi * '1_A \in 'CF(G, A).
Proof.
by apply/cfun_onP=> x /(cfun_onP (cfuni_on A)) Ax0; rewrite cfunE Ax0 mulr0.
Qed.
Lemma cfun_onE phi A : (phi \in 'CF(G, A)) = (support phi \subset A).
Proof. exact: (sameP cfun_onP supportP). Qed.
Lemma cfun_onT phi : phi \in 'CF(G, [set: gT]).
Proof. by rewrite cfun_onE. Qed.
Lemma cfun_onD1 phi A :
(phi \in 'CF(G, A^#)) = (phi \in 'CF(G, A)) && (phi 1%g == 0).
Proof.
by rewrite !cfun_onE -!(eq_subset (in_set (support _))) subsetD1 !inE negbK.
Qed.
Lemma cfun_onG phi : phi \in 'CF(G, G).
Proof. by rewrite cfun_onE support_cfun. Qed.
Lemma cfunD1E phi : (phi \in 'CF(G, G^#)) = (phi 1%g == 0).
Proof. by rewrite cfun_onD1 cfun_onG. Qed.
Lemma cfunGid : 'CF(G, G) = 'CF(G)%VS.
Proof. by apply/vspaceP=> phi; rewrite cfun_onG memvf. Qed.
Lemma cfun_onS A B phi : B \subset A -> phi \in 'CF(G, B) -> phi \in 'CF(G, A).
Proof. by rewrite !cfun_onE => sBA /subset_trans->. Qed.
Lemma cfun_complement A :
A <| G -> ('CF(G, A) + 'CF(G, G :\: A)%SET = 'CF(G))%VS.
Proof.
case/andP=> sAG nAG; rewrite -cfunGid [rhs in _ = rhs]cfun_on_sum.
rewrite (bigID (fun B => B \subset A)) /=.
congr (_ + _)%VS; rewrite cfun_on_sum; apply: eq_bigl => /= xG.
rewrite andbAC; apply/esym/andb_idr=> /andP[/imsetP[x Gx ->] _].
by rewrite class_subG.
rewrite -andbA; apply: andb_id2l => /imsetP[x Gx ->].
by rewrite !class_sub_norm ?normsD ?normG // inE andbC.
Qed.
Lemma cfConjCE phi x : ( phi^* )%CF x = (phi x)^*.
Proof. by rewrite cfunE. Qed.
Lemma cfConjCK : involutive (fun phi => phi^* )%CF.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= conjCK. Qed.
Lemma cfConjC_cfun1 : ( 1^* )%CF = 1 :> 'CF(G).
Proof. exact: rmorph1. Qed.
(* Class function kernel and faithful class functions *)
Fact cfker_is_group phi : group_set (cfker phi).
Proof.
apply/group_setP; split=> [|x y]; rewrite !inE ?group1.
by apply/forallP=> y; rewrite mul1g.
case/andP=> Gx /forallP-Kx /andP[Gy /forallP-Ky]; rewrite groupM //.
by apply/forallP=> z; rewrite -mulgA (eqP (Kx _)) Ky.
Qed.
Canonical cfker_group phi := Group (cfker_is_group phi).
Lemma cfker_sub phi : cfker phi \subset G.
Proof. by rewrite /cfker setIdE subsetIl. Qed.
Lemma cfker_norm phi : G \subset 'N(cfker phi).
Proof.
apply/subsetP=> z Gz; have phiJz := cfunJ phi _ (groupVr Gz).
rewrite inE; apply/subsetP=> _ /imsetP[x /setIdP[Gx /forallP-Kx] ->].
rewrite inE groupJ //; apply/forallP=> y.
by rewrite -(phiJz y) -phiJz conjMg conjgK Kx.
Qed.
Lemma cfker_normal phi : cfker phi <| G.
Proof. by rewrite /normal cfker_sub cfker_norm. Qed.
Lemma cfkerMl phi x y : x \in cfker phi -> phi (x * y)%g = phi y.
Proof. by case/setIdP=> _ /eqfunP->. Qed.
Lemma cfkerMr phi x y : x \in cfker phi -> phi (y * x)%g = phi y.
Proof.
by move=> Kx; rewrite conjgC cfkerMl ?cfunJ ?(subsetP (cfker_sub phi)).
Qed.
Lemma cfker1 phi x : x \in cfker phi -> phi x = phi 1%g.
Proof. by move=> Kx; rewrite -[x]mulg1 cfkerMl. Qed.
Lemma cfker_cfun0 : @cfker _ G 0 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfunE.
Qed.
Lemma cfker_add phi psi : cfker phi :&: cfker psi \subset cfker (phi + psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_sum I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\sum_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun0.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_add _ _).
Qed.
Lemma cfker_scale a phi : cfker phi \subset cfker (a *: phi).
Proof.
apply/subsetP=> x Kphi_x; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE cfkerMl.
Qed.
Lemma cfker_scale_nz a phi : a != 0 -> cfker (a *: phi) = cfker phi.
Proof.
move=> nz_a; apply/eqP.
by rewrite eqEsubset -{2}(scalerK nz_a phi) !cfker_scale.
Qed.
Lemma cfker_opp phi : cfker (- phi) = cfker phi.
Proof. by rewrite -scaleN1r cfker_scale_nz // oppr_eq0 oner_eq0. Qed.
Lemma cfker_cfun1 : @cfker _ G 1 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfun1E groupMl.
Qed.
Lemma cfker_mul phi psi : cfker phi :&: cfker psi \subset cfker (phi * psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_prod I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\prod_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun1.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_mul _ _).
Qed.
Lemma cfaithfulE phi : cfaithful phi = (cfker phi \subset [1]).
Proof. by []. Qed.
End ClassFun.
Arguments classfun_on {gT} B%_g A%_g.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Arguments cfun_onP {gT G A phi}.
Arguments cfConjCK {gT G} phi : rename.
#[global] Hint Resolve cfun_onT : core.
Section DotProduct.
Variable (gT : finGroupType) (G : {group gT}).
Implicit Types (M : {group gT}) (phi psi xi : 'CF(G)) (R S : seq 'CF(G)).
Lemma cfdotE phi psi :
'[phi, psi] = #|G|%:R^-1 * \sum_(x in G) phi x * (psi x)^*.
Proof. by []. Qed.
Lemma cfdotElr A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A :&: B) phi x * (psi x)^*.
Proof.
move=> Aphi Bpsi; rewrite (big_setID G)/= cfdotE (big_setID (A :&: B))/= setIC.
congr (_ * (_ + _)); rewrite !big1 // => x /setDP[_].
by move/cfun0->; rewrite mul0r.
rewrite inE; case/nandP=> notABx; first by rewrite (cfun_on0 Aphi) ?mul0r.
by rewrite (cfun_on0 Bpsi) // rmorph0 mulr0.
Qed.
Lemma cfdotEl A phi psi :
phi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Aphi; rewrite (cfdotElr Aphi (cfun_onT psi)) setIT. Qed.
Lemma cfdotEr A phi psi :
psi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Apsi; rewrite (cfdotElr (cfun_onT phi) Apsi) setTI. Qed.
Lemma cfdot_complement A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, G :\: A) -> '[phi, psi] = 0.
Proof.
move=> Aphi A'psi; rewrite (cfdotElr Aphi A'psi).
by rewrite setDE setICA setICr setI0 big_set0 mulr0.
Qed.
Lemma cfnormE A phi :
phi \in 'CF(G, A) -> '[phi] = #|G|%:R^-1 * (\sum_(x in A) `|phi x| ^+ 2).
Proof. by move/cfdotEl->; rewrite (eq_bigr _ (fun _ _ => normCK _)). Qed.
Lemma eq_cfdotl A phi1 phi2 psi :
psi \in 'CF(G, A) -> {in A, phi1 =1 phi2} -> '[phi1, psi] = '[phi2, psi].
Proof.
move/cfdotEr=> eq_dot eq_phi; rewrite !eq_dot; congr (_ * _).
by apply: eq_bigr => x Ax; rewrite eq_phi.
Qed.
Lemma cfdot_cfuni A B :
A <| G -> B <| G -> '['1_A, '1_B]_G = #|A :&: B|%:R / #|G|%:R.
Proof.
move=> nsAG nsBG; rewrite (cfdotElr (cfuni_on G A) (cfuni_on G B)) mulrC.
congr (_ / _); rewrite -sumr_const; apply: eq_bigr => x /setIP[Ax Bx].
by rewrite !cfuniE // Ax Bx mul1r rmorph1.
Qed.
Lemma cfnorm1 : '[1]_G = 1.
Proof. by rewrite cfdot_cfuni ?genGid // setIid divff ?neq0CG. Qed.
Lemma cfdotrE psi phi : cfdotr psi phi = '[phi, psi]. Proof. by []. Qed.
Lemma cfdotr_is_linear xi : linear (cfdotr xi : 'CF(G) -> algC^o).
Proof.
move=> a phi psi; rewrite scalerAr -mulrDr; congr (_ * _).
rewrite linear_sum -big_split; apply: eq_bigr => x _ /=.
by rewrite !cfunE mulrDl -mulrA.
Qed.
HB.instance Definition _ xi := GRing.isSemilinear.Build algC _ _ _ (cfdotr xi)
(GRing.semilinear_linear (cfdotr_is_linear xi)).
Lemma cfdot0l xi : '[0, xi] = 0.
Proof. by rewrite -cfdotrE linear0. Qed.
Lemma cfdotNl xi phi : '[- phi, xi] = - '[phi, xi].
Proof. by rewrite -!cfdotrE linearN. Qed.
Lemma cfdotDl xi phi psi : '[phi + psi, xi] = '[phi, xi] + '[psi, xi].
Proof. by rewrite -!cfdotrE linearD. Qed.
Lemma cfdotBl xi phi psi : '[phi - psi, xi] = '[phi, xi] - '[psi, xi].
Proof. by rewrite -!cfdotrE linearB. Qed.
Lemma cfdotMnl xi phi n : '[phi *+ n, xi] = '[phi, xi] *+ n.
Proof. by rewrite -!cfdotrE linearMn. Qed.
Lemma cfdot_suml xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[\sum_(i <- r | P i) phi i, xi] = \sum_(i <- r | P i) '[phi i, xi].
Proof. by rewrite -!cfdotrE linear_sum. Qed.
Lemma cfdotZl xi a phi : '[a *: phi, xi] = a * '[phi, xi].
Proof. by rewrite -!cfdotrE linearZ. Qed.
Lemma cfdotC phi psi : '[phi, psi] = ('[psi, phi])^*.
Proof.
rewrite /cfdot rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr=> x _; rewrite rmorphM /= conjCK mulrC.
Qed.
Lemma eq_cfdotr A phi psi1 psi2 :
phi \in 'CF(G, A) -> {in A, psi1 =1 psi2} -> '[phi, psi1] = '[phi, psi2].
Proof. by move=> Aphi /eq_cfdotl eq_dot; rewrite cfdotC eq_dot // -cfdotC. Qed.
Lemma cfdotBr xi phi psi : '[xi, phi - psi] = '[xi, phi] - '[xi, psi].
Proof. by rewrite !(cfdotC xi) -rmorphB cfdotBl. Qed.
HB.instance Definition _ xi :=
GRing.isZmodMorphism.Build _ _ (cfdot xi) (cfdotBr xi).
Lemma cfdot0r xi : '[xi, 0] = 0. Proof. exact: raddf0. Qed.
Lemma cfdotNr xi phi : '[xi, - phi] = - '[xi, phi].
Proof. exact: raddfN. Qed.
Lemma cfdotDr xi phi psi : '[xi, phi + psi] = '[xi, phi] + '[xi, psi].
Proof. exact: raddfD. Qed.
Lemma cfdotMnr xi phi n : '[xi, phi *+ n] = '[xi, phi] *+ n.
Proof. exact: raddfMn. Qed.
Lemma cfdot_sumr xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[xi, \sum_(i <- r | P i) phi i] = \sum_(i <- r | P i) '[xi, phi i].
Proof. exact: raddf_sum. Qed.
Lemma cfdotZr a xi phi : '[xi, a *: phi] = a^* * '[xi, phi].
Proof. by rewrite !(cfdotC xi) cfdotZl rmorphM. Qed.
Lemma cfdot_cfAut (u : {rmorphism algC -> algC}) phi psi :
{in image psi G, {morph u : x / x^*}} ->
'[cfAut u phi, cfAut u psi] = u '[phi, psi].
Proof.
move=> uC; rewrite rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr => x Gx; rewrite !cfunE rmorphM /= uC ?map_f ?mem_enum.
Qed.
Lemma cfdot_conjC phi psi : '[phi^*, psi^*] = '[phi, psi]^*.
Proof. by rewrite cfdot_cfAut. Qed.
Lemma cfdot_conjCl phi psi : '[phi^*, psi] = '[phi, psi^*]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfdot_conjCr phi psi : '[phi, psi^*] = '[phi^*, psi]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfnorm_ge0 phi : 0 <= '[phi].
Proof.
by rewrite mulr_ge0 ?invr_ge0 ?ler0n ?sumr_ge0 // => x _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_eq0 phi : ('[phi] == 0) = (phi == 0).
Proof.
apply/idP/eqP=> [|->]; last by rewrite cfdot0r.
rewrite mulf_eq0 invr_eq0 (negbTE (neq0CG G)) /= => /eqP/psumr_eq0P phi0.
apply/cfun_inP=> x Gx; apply/eqP; rewrite cfunE -mul_conjC_eq0.
by rewrite phi0 // => y _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_gt0 phi : ('[phi] > 0) = (phi != 0).
Proof. by rewrite lt_def cfnorm_ge0 cfnorm_eq0 andbT. Qed.
Lemma sqrt_cfnorm_ge0 phi : 0 <= sqrtC '[phi].
Proof. by rewrite sqrtC_ge0 cfnorm_ge0. Qed.
Lemma sqrt_cfnorm_eq0 phi : (sqrtC '[phi] == 0) = (phi == 0).
Proof. by rewrite sqrtC_eq0 cfnorm_eq0. Qed.
Lemma sqrt_cfnorm_gt0 phi : (sqrtC '[phi] > 0) = (phi != 0).
Proof. by rewrite sqrtC_gt0 cfnorm_gt0. Qed.
Lemma cfnormZ a phi : '[a *: phi]= `|a| ^+ 2 * '[phi]_G.
Proof. by rewrite cfdotZl cfdotZr mulrA normCK. Qed.
Lemma cfnormN phi : '[- phi] = '[phi].
Proof. by rewrite cfdotNl raddfN opprK. Qed.
Lemma cfnorm_sign n phi : '[(-1) ^+ n *: phi] = '[phi].
Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?cfnormN. Qed.
Lemma cfnormD phi psi :
let d := '[phi, psi] in '[phi + psi] = '[phi] + '[psi] + ( d + d^* ).
Proof. by rewrite /= addrAC -cfdotC cfdotDl !cfdotDr !addrA. Qed.
Lemma cfnormB phi psi :
let d := '[phi, psi] in '[phi - psi] = '[phi] + '[psi] - ( d + d^* ).
Proof. by rewrite /= cfnormD cfnormN cfdotNr rmorphN -opprD. Qed.
Lemma cfnormDd phi psi : '[phi, psi] = 0 -> '[phi + psi] = '[phi] + '[psi].
Proof. by move=> ophipsi; rewrite cfnormD ophipsi rmorph0 !addr0. Qed.
Lemma cfnormBd phi psi : '[phi, psi] = 0 -> '[phi - psi] = '[phi] + '[psi].
Proof.
by move=> ophipsi; rewrite cfnormDd ?cfnormN // cfdotNr ophipsi oppr0.
Qed.
Lemma cfnorm_conjC phi : '[phi^*] = '[phi].
Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed.
Lemma cfCauchySchwarz phi psi :
`|'[phi, psi]| ^+ 2 <= '[phi] * '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_psi] /= := eqVneq psi 0.
by apply/leifP; rewrite !cfdot0r normCK mul0r mulr0.
without loss ophi: phi / '[phi, psi] = 0.
move=> IHo; pose a := '[phi, psi] / '[psi]; pose phi1 := phi - a *: psi.
have ophi: '[phi1, psi] = 0.
by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr.
rewrite (canRL (subrK _) (erefl phi1)) rpredDr ?rpredZ ?memv_line //.
rewrite cfdotDl ophi add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)).
rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ophi mulr0.
by have:= IHo _ ophi; rewrite mulrDl -leifBLR subrr ophi normCK mul0r.
rewrite ophi normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0.
rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_psi) /=.
apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ophi mulr0.
by rewrite cfnorm_eq0 => /eqP->; apply: rpred0.
Qed.
Lemma cfCauchySchwarz_sqrt phi psi :
`|'[phi, psi]| <= sqrtC '[phi] * sqrtC '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?qualifE/= ?cfnorm_ge0 //.
rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM ?qualifE/= ?cfnorm_ge0 //;
[ exact: cfCauchySchwarz | exact: O.. ].
Qed.
Lemma cf_triangle_leif phi psi :
sqrtC '[phi + psi] <= sqrtC '[phi] + sqrtC '[psi]
?= iff ~~ free (phi :: psi) && (0 <= coord [tuple psi] 0 phi).
Proof.
rewrite -(mono_in_leif ler_sqr) ?rpredD ?qualifE/= ?sqrtC_ge0 ?cfnorm_ge0 //;
[| exact: O.. ].
rewrite andbC sqrrD !sqrtCK addrAC cfnormD (mono_leif (lerD2l _)).
rewrite -mulr_natr -[_ + _](divfK (negbT (eqC_nat 2 0))) -/('Re _).
rewrite (mono_leif (ler_pM2r _)) ?ltr0n //.
have:= leif_trans (leif_Re_Creal '[phi, psi]) (cfCauchySchwarz_sqrt phi psi).
congr (_ <= _ ?= iff _); first by rewrite ReE.
apply: andb_id2r; rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC /=.
have [-> | nz_psi] := eqVneq psi 0; first by rewrite cfdot0r coord0.
case/vlineP=> [x ->]; rewrite cfdotZl linearZ pmulr_lge0 ?cfnorm_gt0 //=.
by rewrite (coord_free 0) ?seq1_free // eqxx mulr1.
Qed.
Lemma orthogonal_cons phi R S :
orthogonal (phi :: R) S = orthogonal phi S && orthogonal R S.
Proof. by rewrite /orthogonal /= andbT. Qed.
Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal phi psi).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthogonalP S R :
reflect {in S & R, forall phi psi, '[phi, psi] = 0} (orthogonal S R).
Proof.
apply: (iffP allP) => oSR phi => [psi /oSR/allP opS /opS/eqP // | /oSR opS].
by apply/allP=> psi /= /opS->.
Qed.
Lemma orthoPl phi S :
reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal phi S).
Proof.
by rewrite [orthogonal _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP.
Qed.
Arguments orthoPl {phi S}.
Lemma orthogonal_sym : symmetric (@orthogonal _ G).
Proof.
apply: symmetric_from_pre => R S /orthogonalP oRS.
by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite cfdotC oRS ?rmorph0.
Qed.
Lemma orthoPr S psi :
reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal S psi).
Proof.
rewrite orthogonal_sym.
by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite cfdotC oSpsi ?conjC0.
Qed.
Lemma eq_orthogonal R1 R2 S1 S2 :
R1 =i R2 -> S1 =i S2 -> orthogonal R1 S1 = orthogonal R2 S2.
Proof.
move=> eqR eqS; rewrite [orthogonal _ _](eq_all_r eqR).
by apply: eq_all => psi /=; apply: eq_all_r.
Qed.
Lemma orthogonal_catl R1 R2 S :
orthogonal (R1 ++ R2) S = orthogonal R1 S && orthogonal R2 S.
Proof. exact: all_cat. Qed.
Lemma orthogonal_catr R S1 S2 :
orthogonal R (S1 ++ S2) = orthogonal R S1 && orthogonal R S2.
Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed.
Lemma span_orthogonal S1 S2 phi1 phi2 :
orthogonal S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS ->
'[phi1, phi2] = 0.
Proof.
move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->.
rewrite cfdot_suml big1 // => i _; rewrite cfdot_sumr big1 // => j _.
by rewrite cfdotZl cfdotZr oS12 ?mem_nth ?mulr0.
Qed.
Lemma orthogonal_split S beta :
{X : 'CF(G) & X \in <<S>>%VS &
{Y | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal Y S]}}.
Proof.
suffices [X S_X [Y -> oYS]]:
{X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal Y S}}.
- exists X => //; exists Y.
by rewrite cfdotC (span_orthogonal oYS) ?memv_span1 ?conjC0.
elim: S beta => [|phi S IHS] beta.
by exists 0; last exists beta; rewrite ?mem0v ?add0r.
have [[U S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta).
pose Z := '[Y, V] / '[V] *: V; exists (X + Z).
rewrite /Z -{4}(addKr U V) scalerDr scalerN addrA addrC span_cons.
by rewrite memv_add ?memvB ?memvZ ?memv_line.
exists (Y - Z); first by rewrite addrCA !addrA addrK addrC.
apply/orthoPl=> psi /[!inE] /predU1P[-> | Spsi]; last first.
by rewrite cfdotBl cfdotZl (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS).
rewrite cfdotBl !cfdotDr (span_orthogonal oYS) // ?memv_span ?mem_head //.
rewrite !cfdotZl (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //.
have [-> | nzV] := eqVneq V 0; first by rewrite cfdot0r !mul0r subrr.
by rewrite divfK ?cfnorm_eq0 ?subrr.
Qed.
Lemma map_orthogonal M (nu : 'CF(G) -> 'CF(M)) S R (A : {pred 'CF(G)}) :
{in A &, isometry nu} -> {subset S <= A} -> {subset R <= A} ->
orthogonal (map nu S) (map nu R) = orthogonal S R.
Proof.
move=> Inu sSA sRA; rewrite [orthogonal _ _]all_map.
apply: eq_in_all => phi Sphi; rewrite /= all_map.
by apply: eq_in_all => psi Rpsi; rewrite /= Inu ?(sSA phi) ?(sRA psi).
Qed.
Lemma orthogonal_oppr S R : orthogonal S (map -%R R) = orthogonal S R.
Proof.
wlog suffices IH: S R / orthogonal S R -> orthogonal S (map -%R R).
by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK.
move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->].
by rewrite cfdotNr oSR ?oppr0.
Qed.
Lemma orthogonal_oppl S R : orthogonal (map -%R S) R = orthogonal S R.
Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed.
Lemma pairwise_orthogonalP S :
reflect (uniq (0 :: S)
/\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0})
(pairwise_orthogonal S).
Proof.
rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case.
elim: S notS0 => [|phi S IH] /=; first by left.
rewrite inE eq_sym andbT => /norP[nz_phi /IH{}IH].
have [opS | not_opS] := allP; last first.
right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=.
by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp).
rewrite (contra (opS _)) /= ?cfnorm_eq0 //.
apply: (iffP IH) => [] [uniqS oSS]; last first.
by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead.
split=> // psi xi /[!inE] /predU1P[-> // | Spsi].
by case/predU1P=> [-> | /opS] /eqP.
case/predU1P=> [-> _ | Sxi /oSS-> //].
by apply/eqP; rewrite cfdotC conjC_eq0 [_ == 0]opS.
Qed.
Lemma pairwise_orthogonal_cat R S :
pairwise_orthogonal (R ++ S) =
[&& pairwise_orthogonal R, pairwise_orthogonal S & orthogonal R S].
Proof.
rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr.
elim: R => [|phi R /= ->]; rewrite ?andbT // orthogonal_cons all_cat -!andbA /=.
by do !bool_congr.
Qed.
Lemma eq_pairwise_orthogonal R S :
perm_eq R S -> pairwise_orthogonal R = pairwise_orthogonal S.
Proof.
apply: catCA_perm_subst R S => R S S'.
rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA.
by do !bool_congr.
Qed.
Lemma sub_pairwise_orthogonal S1 S2 :
{subset S1 <= S2} -> uniq S1 ->
pairwise_orthogonal S2 -> pairwise_orthogonal S1.
Proof.
move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2].
apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //.
by split=> //; apply: sub_in2 oS2.
Qed.
Lemma orthogonal_free S : pairwise_orthogonal S -> free S.
Proof.
case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS].
rewrite -(in_tupleE S); apply/freeP => a aS0 i.
have S_i: S`_i \in S by apply: mem_nth.
have /eqP: '[S`_i, 0]_G = 0 := cfdot0r _.
rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first.
by rewrite cfdotZr oSS ?mulr0 ?mem_nth // eq_sym nth_uniq.
rewrite addr0 cfdotZr mulf_eq0 conjC_eq0 cfnorm_eq0.
by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0.
Qed.
Lemma filter_pairwise_orthogonal S p :
pairwise_orthogonal S -> pairwise_orthogonal (filter p S).
Proof.
move=> orthoS; apply: sub_pairwise_orthogonal (orthoS).
exact: mem_subseq (filter_subseq p S).
exact/filter_uniq/free_uniq/orthogonal_free.
Qed.
Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S.
Proof.
by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= cfdot0r eq_sym oner_eq0.
Qed.
Lemma orthonormalE S :
orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S.
Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed.
Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S.
Proof. by rewrite orthonormalE => /andP[_]. Qed.
Lemma orthonormal_cat R S :
orthonormal (R ++ S) = [&& orthonormal R, orthonormal S & orthogonal R S].
Proof.
rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA.
by do !bool_congr.
Qed.
Lemma eq_orthonormal R S : perm_eq R S -> orthonormal R = orthonormal S.
Proof.
move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)).
by rewrite (eq_pairwise_orthogonal eqRS).
Qed.
Lemma orthonormal_free S : orthonormal S -> free S.
Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed.
Lemma orthonormalP S :
reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi]_G = (phi == psi)%:R})
(orthonormal S).
Proof.
rewrite orthonormalE; have [/= normS | not_normS] := allP; last first.
by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx.
apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS].
split=> // [|phi psi]; first by case/andP: uniqS.
by have [-> _ /normS/eqP | /oSS] := eqVneq.
split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->.
by rewrite /= (contra (normS _)) // cfdot0r eq_sym oner_eq0.
Qed.
Lemma sub_orthonormal S1 S2 :
{subset S1 <= S2} -> uniq S1 -> orthonormal S2 -> orthonormal S1.
Proof.
move=> sS12 uniqS1 /orthonormalP[_ oS1].
by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _.
Qed.
Lemma orthonormal2P phi psi :
reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1]
(orthonormal [:: phi; psi]).
Proof.
rewrite /orthonormal /= !andbT andbC.
by apply: (iffP and3P) => [] []; do 3!move/eqP->.
Qed.
Lemma conjC_pair_orthogonal S chi :
cfConjC_closed S -> ~~ has cfReal S -> pairwise_orthogonal S -> chi \in S ->
pairwise_orthogonal (chi :: chi^*%CF).
Proof.
move=> ccS /hasPn nrS oSS Schi; apply: sub_pairwise_orthogonal oSS.
by apply/allP; rewrite /= Schi ccS.
by rewrite /= inE eq_sym nrS.
Qed.
Lemma cfdot_real_conjC phi psi : cfReal phi -> '[phi, psi^*]_G = '[phi, psi]^*.
Proof. by rewrite -cfdot_conjC => /eqcfP->. Qed.
Lemma extend_cfConjC_subset S X phi :
cfConjC_closed S -> ~~ has cfReal S -> phi \in S -> phi \notin X ->
cfConjC_subset X S -> cfConjC_subset [:: phi, phi^* & X]%CF S.
Proof.
move=> ccS nrS Sphi X'phi [uniqX /allP-sXS ccX].
split; last 1 [by apply/allP; rewrite /= Sphi ccS | apply/allP]; rewrite /= inE.
by rewrite negb_or X'phi eq_sym (hasPn nrS) // (contra (ccX _)) ?cfConjCK.
by rewrite cfConjCK !mem_head orbT; apply/allP=> xi Xxi; rewrite !inE ccX ?orbT.
Qed.
(* Note: other isometry lemmas, and the dot product lemmas for orthogonal *)
(* and orthonormal sequences are in vcharacter, because we need the 'Z[S] *)
(* notation for the isometry domains. Alternatively, this could be moved to *)
(* cfun. *)
End DotProduct.
Arguments orthoP {gT G phi psi}.
Arguments orthoPl {gT G phi S}.
Arguments orthoPr {gT G S psi}.
Arguments orthogonalP {gT G S R}.
Arguments pairwise_orthogonalP {gT G S}.
Arguments orthonormalP {gT G S}.
Section CfunOrder.
Variables (gT : finGroupType) (G : {group gT}) (phi : 'CF(G)).
Lemma dvdn_cforderP n :
reflect {in G, forall x, phi x ^+ n = 1} (#[phi]%CF %| n)%N.
Proof.
apply: (iffP (dvdn_biglcmP _ _ _)); rewrite genGid => phiG1 x Gx.
by apply/eqP; rewrite -dvdn_orderC phiG1.
by rewrite dvdn_orderC phiG1.
Qed.
Lemma dvdn_cforder n : (#[phi]%CF %| n) = (phi ^+ n == 1).
Proof.
apply/dvdn_cforderP/eqP=> phi_n_1 => [|x Gx].
by apply/cfun_inP=> x Gx; rewrite exp_cfunE // cfun1E Gx phi_n_1.
by rewrite -exp_cfunE // phi_n_1 // cfun1E Gx.
Qed.
Lemma exp_cforder : phi ^+ #[phi]%CF = 1.
Proof. by apply/eqP; rewrite -dvdn_cforder. Qed.
End CfunOrder.
Arguments dvdn_cforderP {gT G phi n}.
Section MorphOrder.
Variables (aT rT : finGroupType) (G : {group aT}) (R : {group rT}).
Variable f : {rmorphism 'CF(G) -> 'CF(R)}.
Lemma cforder_rmorph phi : #[f phi]%CF %| #[phi]%CF.
Proof. by rewrite dvdn_cforder -rmorphXn exp_cforder rmorph1. Qed.
Lemma cforder_inj_rmorph phi : injective f -> #[f phi]%CF = #[phi]%CF.
Proof.
move=> inj_f; apply/eqP; rewrite eqn_dvd cforder_rmorph dvdn_cforder /=.
by rewrite -(rmorph_eq1 _ inj_f) rmorphXn exp_cforder.
Qed.
End MorphOrder.
Section BuildIsometries.
Variable (gT : finGroupType) (L G : {group gT}).
Implicit Types (phi psi xi : 'CF(L)) (R S : seq 'CF(L)).
Implicit Types (U : {pred 'CF(L)}) (W : {pred 'CF(G)}).
Lemma sub_iso_to U1 U2 W1 W2 tau :
{subset U2 <= U1} -> {subset W1 <= W2} ->
{in U1, isometry tau, to W1} -> {in U2, isometry tau, to W2}.
Proof.
by move=> sU sW [Itau Wtau]; split=> [|u /sU/Wtau/sW //]; apply: sub_in2 Itau.
Qed.
Lemma isometry_of_free S f :
free S -> {in S &, isometry f} ->
{tau : {linear 'CF(L) -> 'CF(G)} |
{in S, tau =1 f} & {in <<S>>%VS &, isometry tau}}.
Proof.
move=> freeS If; have defS := free_span freeS.
have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S).
have{} Dtau: {in S, tau =1 f}.
by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau.
exists tau => // _ _ /defS[a -> _] /defS[b -> _].
rewrite !{1}linear_sum !{1}cfdot_suml; apply/eq_big_seq=> xi1 Sxi1.
rewrite !{1}cfdot_sumr; apply/eq_big_seq=> xi2 Sxi2.
by rewrite !linearZ /= !Dtau // !cfdotZl !cfdotZr If.
Qed.
Lemma isometry_of_cfnorm S tauS :
pairwise_orthogonal S -> pairwise_orthogonal tauS ->
map cfnorm tauS = map cfnorm S ->
{tau : {linear 'CF(L) -> 'CF(G)} | map tau S = tauS
& {in <<S>>%VS &, isometry tau}}.
Proof.
move=> oS oT eq_nST; have freeS := orthogonal_free oS.
have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map.
have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)).
exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=.
apply: eq_bigr => i _ /=; rewrite linearZ !cfdotZr !cfdot_suml; congr (_ * _).
apply: eq_bigr => j _ /=; rewrite linearZ !cfdotZl; congr (_ * _).
rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i.
by rewrite -!['[_]](nth_map 0 0 cfnorm) ?eq_sz // eq_nST.
have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS.
have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT.
by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz.
Qed.
Lemma isometry_raddf_inj U (tau : {additive 'CF(L) -> 'CF(G)}) :
{in U &, isometry tau} -> {in U &, forall u v, u - v \in U} ->
{in U &, injective tau}.
Proof.
move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB.
by rewrite -cfnorm_eq0 Itau ?linU // cfnorm_eq0 subr_eq0 => /eqP.
Qed.
Lemma opp_isometry : @isometry _ _ G G -%R.
Proof. by move=> x y; rewrite cfdotNl cfdotNr opprK. Qed.
End BuildIsometries.
Section Restrict.
Variables (gT : finGroupType) (A B : {set gT}).
Local Notation H := <<A>>.
Local Notation G := <<B>>.
Fact cfRes_subproof (phi : 'CF(B)) :
is_class_fun H [ffun x => phi (if H \subset G then x else 1%g) *+ (x \in H)].
Proof.
apply: intro_class_fun => /= [x y Hx Hy | x /negbTE/=-> //].
by rewrite Hx (groupJ Hx) //; case: subsetP => // sHG; rewrite cfunJgen ?sHG.
Qed.
Definition cfRes phi := Cfun 1 (cfRes_subproof phi).
Lemma cfResE phi : A \subset B -> {in A, cfRes phi =1 phi}.
Proof. by move=> sAB x Ax; rewrite cfunElock mem_gen ?genS. Qed.
Lemma cfRes1 phi : cfRes phi 1%g = phi 1%g.
Proof. by rewrite cfunElock if_same group1. Qed.
Lemma cfRes_is_linear : linear cfRes.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfRes
(GRing.semilinear_linear cfRes_is_linear).
Lemma cfRes_cfun1 : cfRes 1 = 1.
Proof.
apply: cfun_in_genP => x Hx; rewrite cfunElock Hx !cfun1Egen Hx.
by case: subsetP => [-> // | _]; rewrite group1.
Qed.
Lemma cfRes_is_monoid_morphism : monoid_morphism cfRes.
Proof.
split=> [|phi psi]; [exact: cfRes_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfRes_is_monoid_morphism` instead")]
Definition cfRes_is_multiplicative :=
(fun g => (g.2,g.1)) cfRes_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfRes
cfRes_is_monoid_morphism.
End Restrict.
Arguments cfRes {gT} A%_g {B%_g} phi%_CF.
Notation "''Res[' H , G ]" := (@cfRes _ H G) (only parsing) : ring_scope.
Notation "''Res[' H ]" := 'Res[H, _] : ring_scope.
Notation "''Res'" := 'Res[_] (only parsing) : ring_scope.
Section MoreRestrict.
Variables (gT : finGroupType) (G H : {group gT}).
Implicit Types (A : {set gT}) (phi : 'CF(G)).
Lemma cfResEout phi : ~~ (H \subset G) -> 'Res[H] phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x.
by rewrite cfunE cfun1E mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfResRes A phi :
A \subset H -> H \subset G -> 'Res[A] ('Res[H] phi) = 'Res[A] phi.
Proof.
move=> sAH sHG; apply/cfunP=> x; rewrite !cfunElock !genGid !gen_subG sAH sHG.
by rewrite (subset_trans sAH) // -mulrnA mulnb -in_setI (setIidPr _) ?gen_subG.
Qed.
Lemma cfRes_id A psi : 'Res[A] psi = psi.
Proof. by apply/cfun_in_genP=> x Ax; rewrite cfunElock Ax subxx. Qed.
Lemma sub_cfker_Res A phi :
A \subset H -> A \subset cfker phi -> A \subset cfker ('Res[H, G] phi).
Proof.
move=> sAH kerA; apply/subsetP=> x Ax; have Hx := subsetP sAH x Ax.
rewrite inE Hx; apply/forallP=> y; rewrite !cfunElock !genGid groupMl //.
by rewrite !(fun_if phi) cfkerMl // (subsetP kerA).
Qed.
Lemma eq_cfker_Res phi : H \subset cfker phi -> cfker ('Res[H, G] phi) = H.
Proof. by move=> kH; apply/eqP; rewrite eqEsubset cfker_sub sub_cfker_Res. Qed.
Lemma cfRes_sub_ker phi : H \subset cfker phi -> 'Res[H, G] phi = (phi 1%g)%:A.
Proof.
move=> kerHphi; have sHG := subset_trans kerHphi (cfker_sub phi).
apply/cfun_inP=> x Hx; have ker_x := subsetP kerHphi x Hx.
by rewrite cfResE // cfunE cfun1E Hx mulr1 cfker1.
Qed.
Lemma cforder_Res phi : #['Res[H] phi]%CF %| #[phi]%CF.
Proof. exact: cforder_rmorph. Qed.
End MoreRestrict.
Section Morphim.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Section Main.
Variable G : {group aT}.
Implicit Type phi : 'CF(f @* G).
Fact cfMorph_subproof phi :
is_class_fun <<G>>
[ffun x => phi (if G \subset D then f x else 1%g) *+ (x \in G)].
Proof.
rewrite genGid; apply: intro_class_fun => [x y Gx Gy | x /negPf-> //].
rewrite Gx groupJ //; case subsetP => // sGD.
by rewrite morphJ ?cfunJ ?mem_morphim ?sGD.
Qed.
Definition cfMorph phi := Cfun 1 (cfMorph_subproof phi).
Lemma cfMorphE phi x : G \subset D -> x \in G -> cfMorph phi x = phi (f x).
Proof. by rewrite cfunElock => -> ->. Qed.
Lemma cfMorph1 phi : cfMorph phi 1%g = phi 1%g.
Proof. by rewrite cfunElock morph1 if_same group1. Qed.
Lemma cfMorphEout phi : ~~ (G \subset D) -> cfMorph phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sGD; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_sGD.
Qed.
Lemma cfMorph_cfun1 : cfMorph 1 = 1.
Proof.
apply/cfun_inP=> x Gx; rewrite cfunElock !cfun1E Gx.
by case: subsetP => [sGD | _]; rewrite ?group1 // mem_morphim ?sGD.
Qed.
Fact cfMorph_is_linear : linear cfMorph.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr -mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfMorph
(GRing.semilinear_linear cfMorph_is_linear).
Fact cfMorph_is_monoid_morphism : monoid_morphism cfMorph.
Proof.
split=> [|phi psi]; [exact: cfMorph_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfMorph
cfMorph_is_monoid_morphism.
Hypothesis sGD : G \subset D.
Lemma cfMorph_inj : injective cfMorph.
Proof.
move=> phi1 phi2 eq_phi; apply/cfun_inP=> _ /morphimP[x Dx Gx ->].
by rewrite -!cfMorphE // eq_phi.
Qed.
Lemma cfMorph_eq1 phi : (cfMorph phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfMorph_inj. Qed.
Lemma cfker_morph phi : cfker (cfMorph phi) = G :&: f @*^-1 (cfker phi).
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
have Dx := subsetP sGD x Gx; rewrite Dx mem_morphim //=.
apply/forallP/forallP=> Kx y.
have [{y} /morphimP[y Dy Gy ->] | fG'y] := boolP (y \in f @* G).
by rewrite -morphM // -!(cfMorphE phi) ?groupM.
by rewrite !cfun0 ?groupMl // mem_morphim.
have [Gy | G'y] := boolP (y \in G); last by rewrite !cfun0 ?groupMl.
by rewrite !cfMorphE ?groupM ?morphM // (subsetP sGD).
Qed.
Lemma cfker_morph_im phi : f @* cfker (cfMorph phi) = cfker phi.
Proof. by rewrite cfker_morph // morphim_setIpre (setIidPr (cfker_sub _)). Qed.
Lemma sub_cfker_morph phi (A : {set aT}) :
(A \subset cfker (cfMorph phi)) = (A \subset G) && (f @* A \subset cfker phi).
Proof.
rewrite cfker_morph // subsetI; apply: andb_id2l => sAG.
by rewrite sub_morphim_pre // (subset_trans sAG).
Qed.
Lemma sub_morphim_cfker phi (A : {set aT}) :
A \subset G -> (f @* A \subset cfker phi) = (A \subset cfker (cfMorph phi)).
Proof. by move=> sAG; rewrite sub_cfker_morph ?sAG. Qed.
Lemma cforder_morph phi : #[cfMorph phi]%CF = #[phi]%CF.
Proof. exact/cforder_inj_rmorph/cfMorph_inj. Qed.
End Main.
Lemma cfResMorph (G H : {group aT}) (phi : 'CF(f @* G)) :
H \subset G -> G \subset D -> 'Res (cfMorph phi) = cfMorph ('Res[f @* H] phi).
Proof.
move=> sHG sGD; have sHD := subset_trans sHG sGD.
apply/cfun_inP=> x Hx; have [Gx Dx] := (subsetP sHG x Hx, subsetP sHD x Hx).
by rewrite !(cfMorphE, cfResE) ?morphimS ?mem_morphim //.
Qed.
End Morphim.
Prenex Implicits cfMorph.
Section Isomorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Let defR := isom_im isoGR.
Local Notation G1 := (isom_inv isoGR @* R).
Let defG : G1 = G := isom_im (isom_sym isoGR).
Fact cfIsom_key : unit. Proof. by []. Qed.
Definition cfIsom :=
locked_with cfIsom_key (cfMorph \o 'Res[G1] : 'CF(G) -> 'CF(R)).
Canonical cfIsom_unlockable := [unlockable of cfIsom].
Lemma cfIsomE phi (x : aT : finType) : x \in G -> cfIsom phi (f x) = phi x.
Proof.
move=> Gx; rewrite unlock cfMorphE //= /restrm ?defG ?cfRes_id ?invmE //.
by rewrite -defR mem_morphim.
Qed.
Lemma cfIsom1 phi : cfIsom phi 1%g = phi 1%g.
Proof. by rewrite -(morph1 f) cfIsomE. Qed.
Lemma cfIsom_is_zmod_morphism : zmod_morphism cfIsom.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_zmod_morphism` instead")]
Definition cfIsom_is_additive := cfIsom_is_zmod_morphism.
Lemma cfIsom_is_monoid_morphism : monoid_morphism cfIsom.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_monoid_morphism` instead")]
Definition cfIsom_is_multiplicative :=
(fun g => (g.2,g.1)) cfIsom_is_monoid_morphism.
Lemma cfIsom_is_scalable : scalable cfIsom.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfIsom cfIsom_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfIsom
cfIsom_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfIsom
cfIsom_is_scalable.
Lemma cfIsom_cfun1 : cfIsom 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_isom phi : cfker (cfIsom phi) = f @* cfker phi.
Proof.
rewrite unlock cfker_morph // defG cfRes_id morphpre_restrm morphpre_invm.
by rewrite -defR !morphimIim.
Qed.
End Isomorphism.
Prenex Implicits cfIsom.
Section InvMorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Lemma cfIsomK : cancel (cfIsom isoGR) (cfIsom (isom_sym isoGR)).
Proof.
move=> phi; apply/cfun_inP=> x Gx; rewrite -{1}(invmE (isom_inj isoGR) Gx).
by rewrite !cfIsomE // -(isom_im isoGR) mem_morphim.
Qed.
Lemma cfIsomKV : cancel (cfIsom (isom_sym isoGR)) (cfIsom isoGR).
Proof.
move=> phi; apply/cfun_inP=> y Ry; pose injGR := isom_inj isoGR.
rewrite -{1}[y](invmK injGR) ?(isom_im isoGR) //.
suffices /morphpreP[fGy Gf'y]: y \in invm injGR @*^-1 G by rewrite !cfIsomE.
by rewrite morphpre_invm (isom_im isoGR).
Qed.
Lemma cfIsom_inj : injective (cfIsom isoGR). Proof. exact: can_inj cfIsomK. Qed.
Lemma cfIsom_eq1 phi : (cfIsom isoGR phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfIsom_inj. Qed.
Lemma cforder_isom phi : #[cfIsom isoGR phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfIsom_inj. Qed.
End InvMorphism.
Arguments cfIsom_inj {aT rT G f R} isoGR [phi1 phi2] : rename.
Section Coset.
Variables (gT : finGroupType) (G : {group gT}) (B : {set gT}).
Implicit Type rT : finGroupType.
Local Notation H := <<B>>%g.
Definition cfMod : 'CF(G / B) -> 'CF(G) := cfMorph.
Definition ffun_Quo (phi : 'CF(G)) :=
[ffun Hx : coset_of B =>
phi (if B \subset cfker phi then repr Hx else 1%g) *+ (Hx \in G / B)%g].
Fact cfQuo_subproof phi : is_class_fun <<G / B>> (ffun_Quo phi).
Proof.
rewrite genGid; apply: intro_class_fun => [|Hx /negPf-> //].
move=> _ _ /morphimP[x Nx Gx ->] /morphimP[z Nz Gz ->].
rewrite -morphJ ?mem_morphim ?val_coset_prim ?groupJ //= -gen_subG.
case: subsetP => // KphiH; do 2!case: repr_rcosetP => _ /KphiH/cfkerMl->.
by rewrite cfunJ.
Qed.
Definition cfQuo phi := Cfun 1 (cfQuo_subproof phi).
Local Notation "phi / 'B'" := (cfQuo phi)
(at level 40, left associativity) : cfun_scope.
Local Notation "phi %% 'B'" := (cfMod phi) (at level 40) : cfun_scope.
(* We specialize the cfMorph lemmas to cfMod by strengthening the domain *)
(* condition G \subset 'N(H) to H <| G; the cfMorph lemmas can be used if the *)
(* stronger results are needed. *)
Lemma cfModE phi x : B <| G -> x \in G -> (phi %% B)%CF x = phi (coset B x).
Proof. by move/normal_norm=> nBG; apply: cfMorphE. Qed.
Lemma cfMod1 phi : (phi %% B)%CF 1%g = phi 1%g. Proof. exact: cfMorph1. Qed.
HB.instance Definition _ := GRing.LRMorphism.on cfMod.
Lemma cfMod_cfun1 : (1 %% B)%CF = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_mod phi : B <| G -> B \subset cfker (phi %% B).
Proof.
case/andP=> sBG nBG; rewrite cfker_morph // subsetI sBG.
apply: subset_trans _ (ker_sub_pre _ _); rewrite ker_coset_prim subsetI.
by rewrite (subset_trans sBG nBG) sub_gen.
Qed.
(* Note that cfQuo is nondegenerate even when G does not normalize B. *)
Lemma cfQuoEnorm (phi : 'CF(G)) x :
B \subset cfker phi -> x \in 'N_G(B) -> (phi / B)%CF (coset B x) = phi x.
Proof.
rewrite cfunElock -gen_subG => sHK /setIP[Gx nHx]; rewrite sHK /=.
rewrite mem_morphim // val_coset_prim //.
by case: repr_rcosetP => _ /(subsetP sHK)/cfkerMl->.
Qed.
Lemma cfQuoE (phi : 'CF(G)) x :
B <| G -> B \subset cfker phi -> x \in G -> (phi / B)%CF (coset B x) = phi x.
Proof. by case/andP=> _ nBG sBK Gx; rewrite cfQuoEnorm // (setIidPl _). Qed.
Lemma cfQuo1 (phi : 'CF(G)) : (phi / B)%CF 1%g = phi 1%g.
Proof. by rewrite cfunElock repr_coset1 group1 if_same. Qed.
Lemma cfQuoEout (phi : 'CF(G)) :
~~ (B \subset cfker phi) -> (phi / B)%CF = (phi 1%g)%:A.
Proof.
move/negPf=> not_kerB; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_kerB.
Qed.
(* cfQuo is only linear on the class functions that have H in their kernel. *)
Lemma cfQuo_cfun1 : (1 / B)%CF = 1.
Proof.
apply/cfun_inP=> Hx G_Hx; rewrite cfunElock !cfun1E G_Hx cfker_cfun1 -gen_subG.
have [x nHx Gx ->] := morphimP G_Hx.
case: subsetP=> [sHG | _]; last by rewrite group1.
by rewrite val_coset_prim //; case: repr_rcosetP => y /sHG/groupM->.
Qed.
(* Cancellation properties *)
Lemma cfModK : B <| G -> cancel cfMod cfQuo.
Proof.
move=> nsBG phi; apply/cfun_inP=> _ /morphimP[x Nx Gx ->] //.
by rewrite cfQuoE ?cfker_mod ?cfModE.
Qed.
Lemma cfQuoK :
B <| G -> forall phi, B \subset cfker phi -> (phi / B %% B)%CF = phi.
Proof.
by move=> nsHG phi sHK; apply/cfun_inP=> x Gx; rewrite cfModE ?cfQuoE.
Qed.
Lemma cfMod_eq1 psi : B <| G -> (psi %% B == 1)%CF = (psi == 1).
Proof. by move/cfModK/can_eq <-; rewrite rmorph1. Qed.
Lemma cfQuo_eq1 phi :
B <| G -> B \subset cfker phi -> (phi / B == 1)%CF = (phi == 1).
Proof. by move=> nsBG kerH; rewrite -cfMod_eq1 // cfQuoK. Qed.
End Coset.
Arguments cfQuo {gT G%_G} B%_g phi%_CF.
Arguments cfMod {gT G%_G B%_g} phi%_CF.
Notation "phi / H" := (cfQuo H phi) : cfun_scope.
Notation "phi %% H" := (@cfMod _ _ H phi) : cfun_scope.
Section MoreCoset.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (H K : {group gT}) (phi : 'CF(G)).
Lemma cfResMod H K (psi : 'CF(G / K)) :
H \subset G -> K <| G -> ('Res (psi %% K) = 'Res[H / K] psi %% K)%CF.
Proof. by move=> sHG /andP[_]; apply: cfResMorph. Qed.
Lemma quotient_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> (cfker (psi %% K) / K)%g = cfker psi.
Proof. by case/andP=> _ /cfker_morph_im <-. Qed.
Lemma sub_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> A \subset 'N(K) ->
(A \subset cfker (psi %% K)) = (A / K \subset cfker psi)%g.
Proof.
by move=> nsKG nKA; rewrite -(quotientSGK nKA) ?quotient_cfker_mod// cfker_mod.
Qed.
Lemma cfker_quo H phi :
H <| G -> H \subset cfker (phi) -> cfker (phi / H) = (cfker phi / H)%g.
Proof.
move=> nsHG /cfQuoK {2}<- //; have [sHG nHG] := andP nsHG.
by rewrite cfker_morph 1?quotientGI // cosetpreK (setIidPr _) ?cfker_sub.
Qed.
Lemma cfQuoEker phi x :
x \in G -> (phi / cfker phi)%CF (coset (cfker phi) x) = phi x.
Proof. by move/cfQuoE->; rewrite ?cfker_normal. Qed.
Lemma cfaithful_quo phi : cfaithful (phi / cfker phi).
Proof. by rewrite cfaithfulE cfker_quo ?cfker_normal ?trivg_quotient. Qed.
(* Note that there is no requirement that K be normal in H or G. *)
Lemma cfResQuo H K phi :
K \subset cfker phi -> K \subset H -> H \subset G ->
('Res[H / K] (phi / K) = 'Res[H] phi / K)%CF.
Proof.
move=> kerK sKH sHG; apply/cfun_inP=> xb Hxb; rewrite cfResE ?quotientS //.
have{xb Hxb} [x nKx Hx ->] := morphimP Hxb.
by rewrite !cfQuoEnorm ?cfResE// 1?inE ?Hx ?(subsetP sHG)// sub_cfker_Res.
Qed.
Lemma cfQuoInorm K phi :
K \subset cfker phi -> (phi / K)%CF = 'Res ('Res['N_G(K)] phi / K)%CF.
Proof.
move=> kerK; rewrite -cfResQuo ?subsetIl ?quotientInorm ?cfRes_id //.
by rewrite subsetI normG (subset_trans kerK) ?cfker_sub.
Qed.
Lemma cforder_mod H (psi : 'CF(G / H)) : H <| G -> #[psi %% H]%CF = #[psi]%CF.
Proof. by move/cfModK/can_inj/cforder_inj_rmorph->. Qed.
Lemma cforder_quo H phi :
H <| G -> H \subset cfker phi -> #[phi / H]%CF = #[phi]%CF.
Proof. by move=> nsHG kerHphi; rewrite -cforder_mod ?cfQuoK. Qed.
End MoreCoset.
Section Product.
Variable (gT : finGroupType) (G : {group gT}).
Lemma cfunM_onI A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) -> phi * psi \in 'CF(G, A :&: B).
Proof.
rewrite !cfun_onE => Aphi Bpsi; apply/subsetP=> x; rewrite !inE cfunE mulf_eq0.
by case/norP=> /(subsetP Aphi)-> /(subsetP Bpsi).
Qed.
Lemma cfunM_on A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, A) -> phi * psi \in 'CF(G, A).
Proof. by move=> Aphi Bpsi; rewrite -[A]setIid cfunM_onI. Qed.
End Product.
Section SDproduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis defG : K ><| H = G.
Fact cfSdprodKey : unit. Proof. by []. Qed.
Definition cfSdprod :=
locked_with cfSdprodKey
(cfMorph \o cfIsom (tagged (sdprod_isom defG)) : 'CF(H) -> 'CF(G)).
Canonical cfSdprod_unlockable := [unlockable of cfSdprod].
Lemma cfSdprod_is_zmod_morphism : zmod_morphism cfSdprod.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_zmod_morphism` instead")]
Definition cfSdprod_is_additive := cfSdprod_is_zmod_morphism.
Lemma cfSdprod_is_monoid_morphism : monoid_morphism cfSdprod.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_monoid_morphism` instead")]
Definition cfSdprod_is_multiplicative :=
(fun g => (g.2,g.1)) cfSdprod_is_monoid_morphism.
Lemma cfSdprod_is_scalable : scalable cfSdprod.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfSdprod cfSdprod_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfSdprod
cfSdprod_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfSdprod
cfSdprod_is_scalable.
Lemma cfSdprod1 phi : cfSdprod phi 1%g = phi 1%g.
Proof. by rewrite unlock /= cfMorph1 cfIsom1. Qed.
Let nsKG : K <| G. Proof. by have [] := sdprod_context defG. Qed.
Let sHG : H \subset G. Proof. by have [] := sdprod_context defG. Qed.
Let sKG : K \subset G. Proof. by have [] := andP nsKG. Qed.
Lemma cfker_sdprod phi : K \subset cfker (cfSdprod phi).
Proof. by rewrite unlock_with cfker_mod. Qed.
Lemma cfSdprodEr phi : {in H, cfSdprod phi =1 phi}.
Proof. by move=> y Hy; rewrite unlock cfModE ?cfIsomE ?(subsetP sHG). Qed.
Lemma cfSdprodE phi : {in K & H, forall x y, cfSdprod phi (x * y)%g = phi y}.
Proof.
by move=> x y Kx Hy; rewrite /= cfkerMl ?(subsetP (cfker_sdprod _)) ?cfSdprodEr.
Qed.
Lemma cfSdprodK : cancel cfSdprod 'Res[H].
Proof. by move=> phi; apply/cfun_inP=> x Hx; rewrite cfResE ?cfSdprodEr. Qed.
Lemma cfSdprod_inj : injective cfSdprod. Proof. exact: can_inj cfSdprodK. Qed.
Lemma cfSdprod_eq1 phi : (cfSdprod phi == 1) = (phi == 1).
Proof. exact: rmorph_eq1 cfSdprod_inj. Qed.
Lemma cfRes_sdprodK phi : K \subset cfker phi -> cfSdprod ('Res[H] phi) = phi.
Proof.
move=> kerK; apply/cfun_inP=> _ /(mem_sdprod defG)[x [y [Kx Hy -> _]]].
by rewrite cfSdprodE // cfResE // cfkerMl ?(subsetP kerK).
Qed.
Lemma sdprod_cfker phi : K ><| cfker phi = cfker (cfSdprod phi).
Proof.
have [skerH [_ _ nKH tiKH]] := (cfker_sub phi, sdprodP defG).
rewrite unlock cfker_morph ?normal_norm // cfker_isom restrmEsub //=.
rewrite -(sdprod_modl defG) ?sub_cosetpre //=; congr (_ ><| _).
by rewrite quotientK ?(subset_trans skerH) // -group_modr //= setIC tiKH mul1g.
Qed.
Lemma cforder_sdprod phi : #[cfSdprod phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfSdprod_inj. Qed.
End SDproduct.
Section DProduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis KxH : K \x H = G.
Lemma reindex_dprod R idx (op : Monoid.com_law idx) (F : gT -> R) :
\big[op/idx]_(g in G) F g =
\big[op/idx]_(k in K) \big[op/idx]_(h in H) F (k * h)%g.
Proof.
have /mulgmP/misomP[fM /isomP[injf im_f]] := KxH.
rewrite pair_big_dep -im_f morphimEdom big_imset; last exact/injmP.
by apply: eq_big => [][x y]; rewrite ?inE.
Qed.
Definition cfDprodr := cfSdprod (dprodWsd KxH).
Definition cfDprodl := cfSdprod (dprodWsdC KxH).
Definition cfDprod phi psi := cfDprodl phi * cfDprodr psi.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodl.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodr.
Lemma cfDprodl1 phi : cfDprodl phi 1%g = phi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprodr1 psi : cfDprodr psi 1%g = psi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprod1 phi psi : cfDprod phi psi 1%g = phi 1%g * psi 1%g.
Proof. by rewrite cfunE /= !cfSdprod1. Qed.
Lemma cfDprodl_eq1 phi : (cfDprodl phi == 1) = (phi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprodr_eq1 psi : (cfDprodr psi == 1) = (psi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprod_cfun1r phi : cfDprod phi 1 = cfDprodl phi.
Proof. by rewrite /cfDprod rmorph1 mulr1. Qed.
Lemma cfDprod_cfun1l psi : cfDprod 1 psi = cfDprodr psi.
Proof. by rewrite /cfDprod rmorph1 mul1r. Qed.
Lemma cfDprod_cfun1 : cfDprod 1 1 = 1.
Proof. by rewrite cfDprod_cfun1l rmorph1. Qed.
Lemma cfDprod_split phi psi : cfDprod phi psi = cfDprod phi 1 * cfDprod 1 psi.
Proof. by rewrite cfDprod_cfun1l cfDprod_cfun1r. Qed.
Let nsKG : K <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let nsHG : H <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let cKH : H \subset 'C(K). Proof. by have [] := dprodP KxH. Qed.
Let sKG := normal_sub nsKG.
Let sHG := normal_sub nsHG.
Lemma cfDprodlK : cancel cfDprodl 'Res[K]. Proof. exact: cfSdprodK. Qed.
Lemma cfDprodrK : cancel cfDprodr 'Res[H]. Proof. exact: cfSdprodK. Qed.
Lemma cfker_dprodl phi : cfker phi \x H = cfker (cfDprodl phi).
Proof.
by rewrite dprodC -sdprod_cfker dprodEsd // centsC (centsS (cfker_sub _)).
Qed.
Lemma cfker_dprodr psi : K \x cfker psi = cfker (cfDprodr psi).
Proof. by rewrite -sdprod_cfker dprodEsd // (subset_trans (cfker_sub _)). Qed.
Lemma cfDprodEl phi : {in K & H, forall k h, cfDprodl phi (k * h)%g = phi k}.
Proof. by move=> k h Kk Hh /=; rewrite -(centsP cKH) // cfSdprodE. Qed.
Lemma cfDprodEr psi : {in K & H, forall k h, cfDprodr psi (k * h)%g = psi h}.
Proof. exact: cfSdprodE. Qed.
Lemma cfDprodE phi psi :
{in K & H, forall h k, cfDprod phi psi (h * k)%g = phi h * psi k}.
Proof. by move=> k h Kk Hh /=; rewrite cfunE cfDprodEl ?cfDprodEr. Qed.
Lemma cfDprod_Resl phi psi : 'Res[K] (cfDprod phi psi) = psi 1%g *: phi.
Proof.
by apply/cfun_inP=> x Kx; rewrite cfunE cfResE // -{1}[x]mulg1 mulrC cfDprodE.
Qed.
Lemma cfDprod_Resr phi psi : 'Res[H] (cfDprod phi psi) = phi 1%g *: psi.
Proof.
by apply/cfun_inP=> y Hy; rewrite cfunE cfResE // -{1}[y]mul1g cfDprodE.
Qed.
Lemma cfDprodKl (psi : 'CF(H)) : psi 1%g = 1 -> cancel (cfDprod^~ psi) 'Res.
Proof. by move=> psi1 phi; rewrite cfDprod_Resl psi1 scale1r. Qed.
Lemma cfDprodKr (phi : 'CF(K)) : phi 1%g = 1 -> cancel (cfDprod phi) 'Res.
Proof. by move=> phi1 psi; rewrite cfDprod_Resr phi1 scale1r. Qed.
(* Note that equality holds here iff either cfker phi = K and cfker psi = H, *)
(* or else phi != 0, psi != 0 and coprime #|K : cfker phi| #|H : cfker phi|. *)
Lemma cfker_dprod phi psi :
cfker phi <*> cfker psi \subset cfker (cfDprod phi psi).
Proof.
rewrite -genM_join gen_subG; apply/subsetP=> _ /mulsgP[x y kKx kHy ->] /=.
have [[Kx _] [Hy _]] := (setIdP kKx, setIdP kHy).
have Gxy: (x * y)%g \in G by rewrite -(dprodW KxH) mem_mulg.
rewrite inE Gxy; apply/forallP=> g.
have [Gg | G'g] := boolP (g \in G); last by rewrite !cfun0 1?groupMl.
have{g Gg} [k [h [Kk Hh -> _]]] := mem_dprod KxH Gg.
rewrite mulgA -(mulgA x) (centsP cKH y) // mulgA -mulgA !cfDprodE ?groupM //.
by rewrite !cfkerMl.
Qed.
Lemma cfdot_dprod phi1 phi2 psi1 psi2 :
'[cfDprod phi1 psi1, cfDprod phi2 psi2] = '[phi1, phi2] * '[psi1, psi2].
Proof.
rewrite !cfdotE mulrCA -mulrA mulrCA mulrA -invfM -natrM (dprod_card KxH).
congr (_ * _); rewrite big_distrl reindex_dprod /=; apply: eq_bigr => k Kk.
rewrite big_distrr; apply: eq_bigr => h Hh /=.
by rewrite mulrCA -mulrA -rmorphM mulrCA mulrA !cfDprodE.
Qed.
Lemma cfDprodl_iso : isometry cfDprodl.
Proof.
by move=> phi1 phi2; rewrite -!cfDprod_cfun1r cfdot_dprod cfnorm1 mulr1.
Qed.
Lemma cfDprodr_iso : isometry cfDprodr.
Proof.
by move=> psi1 psi2; rewrite -!cfDprod_cfun1l cfdot_dprod cfnorm1 mul1r.
Qed.
Lemma cforder_dprodl phi : #[cfDprodl phi]%CF = #[phi]%CF.
Proof. exact: cforder_sdprod. Qed.
Lemma cforder_dprodr psi : #[cfDprodr psi]%CF = #[psi]%CF.
Proof. exact: cforder_sdprod. Qed.
End DProduct.
Lemma cfDprodC (gT : finGroupType) (G K H : {group gT})
(KxH : K \x H = G) (HxK : H \x K = G) chi psi :
cfDprod KxH chi psi = cfDprod HxK psi chi.
Proof.
rewrite /cfDprod mulrC.
by congr (_ * _); congr (cfSdprod _ _); apply: eq_irrelevance.
Qed.
Section Bigdproduct.
Variables (gT : finGroupType) (I : finType) (P : pred I).
Variables (A : I -> {group gT}) (G : {group gT}).
Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G.
Let sAG i : P i -> A i \subset G.
Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed.
Fact cfBigdprodi_subproof i :
gval (if P i then A i else 1%G) \x <<\bigcup_(j | P j && (j != i)) A j>> = G.
Proof.
have:= defG; rewrite fun_if big_mkcond (bigD1 i) // -big_mkcondl /= => defGi.
by have [[_ Gi' _ defGi']] := dprodP defGi; rewrite (bigdprodWY defGi') -defGi'.
Qed.
Definition cfBigdprodi i := cfDprodl (cfBigdprodi_subproof i) \o 'Res[_, A i].
HB.instance Definition _ i := GRing.LRMorphism.on (@cfBigdprodi i).
Lemma cfBigdprodi1 i (phi : 'CF(A i)) : cfBigdprodi phi 1%g = phi 1%g.
Proof. by rewrite cfDprodl1 cfRes1. Qed.
Lemma cfBigdprodi_eq1 i (phi : 'CF(A i)) :
P i -> (cfBigdprodi phi == 1) = (phi == 1).
Proof. by move=> Pi; rewrite cfSdprod_eq1 Pi cfRes_id. Qed.
Lemma cfBigdprodiK i : P i -> cancel (@cfBigdprodi i) 'Res[A i].
Proof.
move=> Pi phi; have:= cfDprodlK (cfBigdprodi_subproof i) ('Res phi).
by rewrite -[cfDprodl _ _]/(cfBigdprodi phi) Pi cfRes_id.
Qed.
Lemma cfBigdprodi_inj i : P i -> injective (@cfBigdprodi i).
Proof. by move/cfBigdprodiK; apply: can_inj. Qed.
Lemma cfBigdprodEi i (phi : 'CF(A i)) x :
P i -> (forall j, P j -> x j \in A j) ->
cfBigdprodi phi (\prod_(j | P j) x j)%g = phi (x i).
Proof.
have [r big_r [Ur mem_r] _] := big_enumP P => Pi AxP.
have:= bigdprodWcp defG; rewrite -!big_r => defGr.
have{AxP} [r_i Axr]: i \in r /\ {in r, forall j, x j \in A j}.
by split=> [|j]; rewrite mem_r // => /AxP.
rewrite (perm_bigcprod defGr Axr (perm_to_rem r_i)) big_cons.
rewrite cfDprodEl ?Pi ?cfRes_id ?Axr // big_seq group_prod // => j.
rewrite mem_rem_uniq // => /andP[i'j /= r_j].
by apply/mem_gen/bigcupP; exists j; [rewrite -mem_r r_j | apply: Axr].
Qed.
Lemma cfBigdprodi_iso i : P i -> isometry (@cfBigdprodi i).
Proof. by move=> Pi phi psi; rewrite cfDprodl_iso Pi !cfRes_id. Qed.
Definition cfBigdprod (phi : forall i, 'CF(A i)) :=
\prod_(i | P i) cfBigdprodi (phi i).
Lemma cfBigdprodE phi x :
(forall i, P i -> x i \in A i) ->
cfBigdprod phi (\prod_(i | P i) x i)%g = \prod_(i | P i) phi i (x i).
Proof.
move=> Ax; rewrite prod_cfunE; last by rewrite -(bigdprodW defG) mem_prodg.
by apply: eq_bigr => i Pi; rewrite cfBigdprodEi.
Qed.
Lemma cfBigdprod1 phi : cfBigdprod phi 1%g = \prod_(i | P i) phi i 1%g.
Proof. by rewrite prod_cfunE //; apply/eq_bigr=> i _; apply: cfBigdprodi1. Qed.
Lemma cfBigdprodK phi (Phi := cfBigdprod phi) i (a := phi i 1%g / Phi 1%g) :
Phi 1%g != 0 -> P i -> a != 0 /\ a *: 'Res[A i] Phi = phi i.
Proof.
move=> nzPhi Pi; split.
rewrite mulf_neq0 ?invr_eq0 // (contraNneq _ nzPhi) // => phi_i0.
by rewrite cfBigdprod1 (bigD1 i) //= phi_i0 mul0r.
apply/cfun_inP=> x Aix; rewrite cfunE cfResE ?sAG // mulrAC.
have {1}->: x = (\prod_(j | P j) (if j == i then x else 1))%g.
rewrite -big_mkcondr (big_pred1 i) ?eqxx // => j /=.
by apply: andb_idl => /eqP->.
rewrite cfBigdprodE => [|j _]; last by case: eqP => // ->.
apply: canLR (mulfK nzPhi) _; rewrite cfBigdprod1 !(bigD1 i Pi) /= eqxx.
by rewrite mulrCA !mulrA; congr (_ * _); apply: eq_bigr => j /andP[_ /negPf->].
Qed.
Lemma cfdot_bigdprod phi psi :
'[cfBigdprod phi, cfBigdprod psi] = \prod_(i | P i) '[phi i, psi i].
Proof.
apply: canLR (mulKf (neq0CG G)) _; rewrite -(bigdprod_card defG).
rewrite (big_morph _ (@natrM _) (erefl _)) -big_split /=.
rewrite (eq_bigr _ (fun i _ => mulVKf (neq0CG _) _)) (big_distr_big_dep 1%g) /=.
set F := pfamily _ _ _; pose h (f : {ffun I -> gT}) := (\prod_(i | P i) f i)%g.
pose is_hK x f := forall f1, (f1 \in F) && (h f1 == x) = (f == f1).
have /fin_all_exists[h1 Dh1] x: exists f, x \in G -> is_hK x f.
case Gx: (x \in G); last by exists [ffun _ => x].
have [f [Af fK Uf]] := mem_bigdprod defG Gx.
exists [ffun i => if P i then f i else 1%g] => _ f1.
apply/andP/eqP=> [[/pfamilyP[Pf1 Af1] /eqP Dx] | <-].
by apply/ffunP=> i; rewrite ffunE; case: ifPn => [/Uf-> | /(supportP Pf1)].
split; last by rewrite fK; apply/eqP/eq_bigr=> i Pi; rewrite ffunE Pi.
by apply/familyP=> i; rewrite ffunE !unfold_in; case: ifP => //= /Af.
rewrite (reindex_onto h h1) /= => [|x /Dh1/(_ (h1 x))]; last first.
by rewrite eqxx => /andP[_ /eqP].
apply/eq_big => [f | f /andP[/Dh1<- /andP[/pfamilyP[_ Af] _]]]; last first.
by rewrite !cfBigdprodE // rmorph_prod -big_split /=.
apply/idP/idP=> [/andP[/Dh1<-] | Ff]; first by rewrite eqxx andbT.
have /pfamilyP[_ Af] := Ff; suffices Ghf: h f \in G by rewrite -Dh1 ?Ghf ?Ff /=.
by apply/group_prod=> i Pi; rewrite (subsetP (sAG Pi)) ?Af.
Qed.
End Bigdproduct.
Section MorphIsometry.
Variable gT : finGroupType.
Implicit Types (D G H K : {group gT}) (aT rT : finGroupType).
Lemma cfMorph_iso aT rT (G D : {group aT}) (f : {morphism D >-> rT}) :
G \subset D -> isometry (cfMorph : 'CF(f @* G) -> 'CF(G)).
Proof.
move=> sGD phi psi; rewrite !cfdotE card_morphim (setIidPr sGD).
rewrite -(LagrangeI G ('ker f)) /= mulnC natrM invfM -mulrA.
congr (_ * _); apply: (canLR (mulKf (neq0CG _))).
rewrite mulr_sumr (partition_big_imset f) /= -morphimEsub //.
apply: eq_bigr => _ /morphimP[x Dx Gx ->].
rewrite -(card_rcoset _ x) mulr_natl -sumr_const.
apply/eq_big => [y | y /andP[Gy /eqP <-]]; last by rewrite !cfMorphE.
rewrite mem_rcoset inE groupMr ?groupV // -mem_rcoset.
by apply: andb_id2l => /(subsetP sGD) Dy; apply: sameP eqP (rcoset_kerP f _ _).
Qed.
Lemma cfIsom_iso rT G (R : {group rT}) (f : {morphism G >-> rT}) :
forall isoG : isom G R f, isometry (cfIsom isoG).
Proof.
move=> isoG phi psi; rewrite unlock cfMorph_iso //; set G1 := _ @* R.
by rewrite -(isom_im (isom_sym isoG)) -/G1 in phi psi *; rewrite !cfRes_id.
Qed.
Lemma cfMod_iso H G : H <| G -> isometry (@cfMod _ G H).
Proof. by case/andP=> _; apply: cfMorph_iso. Qed.
Lemma cfQuo_iso H G :
H <| G -> {in [pred phi | H \subset cfker phi] &, isometry (@cfQuo _ G H)}.
Proof.
by move=> nsHG phi psi sHkphi sHkpsi; rewrite -(cfMod_iso nsHG) !cfQuoK.
Qed.
Lemma cfnorm_quo H G phi :
H <| G -> H \subset cfker phi -> '[phi / H] = '[phi]_G.
Proof. by move=> nsHG sHker; apply: cfQuo_iso. Qed.
Lemma cfSdprod_iso K H G (defG : K ><| H = G) : isometry (cfSdprod defG).
Proof.
move=> phi psi; have [/andP[_ nKG] _ _ _ _] := sdprod_context defG.
by rewrite [cfSdprod _]locked_withE cfMorph_iso ?cfIsom_iso.
Qed.
End MorphIsometry.
Section Induced.
Variable gT : finGroupType.
Section Def.
Variables B A : {set gT}.
Local Notation G := <<B>>.
Local Notation H := <<A>>.
(* The default value for the ~~ (H \subset G) case matches the one for cfRes *)
(* so that Frobenius reciprocity holds even in this degenerate case. *)
Definition ffun_cfInd (phi : 'CF(A)) :=
[ffun x => if H \subset G then #|A|%:R^-1 * (\sum_(y in G) phi (x ^ y))
else #|G|%:R * '[phi, 1] *+ (x == 1%g)].
Fact cfInd_subproof phi : is_class_fun G (ffun_cfInd phi).
Proof.
apply: intro_class_fun => [x y Gx Gy | x H'x]; last first.
case: subsetP => [sHG | _]; last by rewrite (negPf (group1_contra H'x)).
rewrite big1 ?mulr0 // => y Gy; rewrite cfun0gen ?(contra _ H'x) //= => /sHG.
by rewrite memJ_norm ?(subsetP (normG _)).
rewrite conjg_eq1 (reindex_inj (mulgI y^-1)%g); congr (if _ then _ * _ else _).
by apply: eq_big => [z | z Gz]; rewrite ?groupMl ?groupV // -conjgM mulKVg.
Qed.
Definition cfInd phi := Cfun 1 (cfInd_subproof phi).
Lemma cfInd_is_linear : linear cfInd.
Proof.
move=> c phi psi; apply/cfunP=> x; rewrite !cfunElock; case: ifP => _.
rewrite mulrCA -mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * _); apply: eq_bigr => y _; rewrite !cfunE.
rewrite mulrnAr -mulrnDl !(mulrCA c) -!mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * (_ * _) *+ _); apply: eq_bigr => y; rewrite !cfunE mulrA mulrDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfInd
(GRing.semilinear_linear cfInd_is_linear).
End Def.
Local Notation "''Ind[' B , A ]" := (@cfInd B A) : ring_scope.
Local Notation "''Ind[' B ]" := 'Ind[B, _] : ring_scope.
Lemma cfIndE (G H : {group gT}) phi x :
H \subset G -> 'Ind[G, H] phi x = #|H|%:R^-1 * (\sum_(y in G) phi (x ^ y)).
Proof. by rewrite cfunElock !genGid => ->. Qed.
Variables G K H : {group gT}.
Implicit Types (phi : 'CF(H)) (psi : 'CF(G)).
Lemma cfIndEout phi :
~~ (H \subset G) -> 'Ind[G] phi = (#|G|%:R * '[phi, 1]) *: '1_1%G.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x; rewrite cfunE cfuniE ?normal1 // inE.
by rewrite mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfIndEsdprod (phi : 'CF(K)) x :
K ><| H = G -> 'Ind[G] phi x = \sum_(w in H) phi (x ^ w)%g.
Proof.
move=> defG; have [/andP[sKG _] _ mulKH nKH _] := sdprod_context defG.
rewrite cfIndE //; apply: canLR (mulKf (neq0CG _)) _; rewrite -mulKH mulr_sumr.
rewrite (set_partition_big _ (rcosets_partition_mul H K)) ?big_imset /=.
apply: eq_bigr => y Hy; rewrite rcosetE norm_rlcoset ?(subsetP nKH) //.
rewrite -lcosetE mulr_natl big_imset /=; last exact: in2W (mulgI _).
by rewrite -sumr_const; apply: eq_bigr => z Kz; rewrite conjgM cfunJ.
have [{}nKH /isomP[injf _]] := sdprod_isom defG.
apply: can_in_inj (fun Ky => invm injf (coset K (repr Ky))) _ => y Hy.
by rewrite rcosetE -val_coset ?(subsetP nKH) // coset_reprK invmE.
Qed.
Lemma cfInd_on A phi :
H \subset G -> phi \in 'CF(H, A) -> 'Ind[G] phi \in 'CF(G, class_support A G).
Proof.
move=> sHG Af; apply/cfun_onP=> g AG'g; rewrite cfIndE ?big1 ?mulr0 // => h Gh.
apply: (cfun_on0 Af); apply: contra AG'g => Agh.
by rewrite -[g](conjgK h) memJ_class_support // groupV.
Qed.
Lemma cfInd_id phi : 'Ind[H] phi = phi.
Proof.
apply/cfun_inP=> x Hx; rewrite cfIndE // (eq_bigr _ (cfunJ phi x)) sumr_const.
by rewrite -[phi x *+ _]mulr_natl mulKf ?neq0CG.
Qed.
Lemma cfInd_normal phi : H <| G -> 'Ind[G] phi \in 'CF(G, H).
Proof.
case/andP=> sHG nHG; apply: (cfun_onS (class_support_sub_norm (subxx _) nHG)).
by rewrite cfInd_on ?cfun_onG.
Qed.
Lemma cfInd1 phi : H \subset G -> 'Ind[G] phi 1%g = #|G : H|%:R * phi 1%g.
Proof.
move=> sHG; rewrite cfIndE // natf_indexg // -mulrA mulrCA; congr (_ * _).
by rewrite mulr_natl -sumr_const; apply: eq_bigr => x; rewrite conj1g.
Qed.
Lemma cfInd_cfun1 : H <| G -> 'Ind[G, H] 1 = #|G : H|%:R *: '1_H.
Proof.
move=> nsHG; have [sHG nHG] := andP nsHG; rewrite natf_indexg // mulrC.
apply/cfunP=> x; rewrite cfIndE ?cfunE ?cfuniE // -mulrA; congr (_ * _).
rewrite mulr_natl -sumr_const; apply: eq_bigr => y Gy.
by rewrite cfun1E -{1}(normsP nHG y Gy) memJ_conjg.
Qed.
Lemma cfnorm_Ind_cfun1 : H <| G -> '['Ind[G, H] 1] = #|G : H|%:R.
Proof.
move=> nsHG; rewrite cfInd_cfun1 // cfnormZ normr_nat cfdot_cfuni // setIid.
by rewrite expr2 {2}natf_indexg ?normal_sub // !mulrA divfK ?mulfK ?neq0CG.
Qed.
Lemma cfIndInd phi :
K \subset G -> H \subset K -> 'Ind[G] ('Ind[K] phi) = 'Ind[G] phi.
Proof.
move=> sKG sHK; apply/cfun_inP=> x Gx; rewrite !cfIndE ?(subset_trans sHK) //.
apply: canLR (mulKf (neq0CG K)) _; rewrite mulr_sumr mulr_natl.
transitivity (\sum_(y in G) \sum_(z in K) #|H|%:R^-1 * phi ((x ^ y) ^ z)).
by apply: eq_bigr => y Gy; rewrite cfIndE // -mulr_sumr.
symmetry; rewrite exchange_big /= -sumr_const; apply: eq_bigr => z Kz.
rewrite (reindex_inj (mulIg z)).
by apply: eq_big => [y | y _]; rewrite ?conjgM // groupMr // (subsetP sKG).
Qed.
(* This is Isaacs, Lemma (5.2). *)
Lemma Frobenius_reciprocity phi psi : '[phi, 'Res[H] psi] = '['Ind[G] phi, psi].
Proof.
have [sHG | not_sHG] := boolP (H \subset G); last first.
rewrite cfResEout // cfIndEout // cfdotZr cfdotZl mulrAC; congr (_ * _).
rewrite (cfdotEl _ (cfuni_on _ _)) mulVKf ?neq0CG // big_set1.
by rewrite cfuniE ?normal1 ?set11 ?mul1r.
transitivity (#|H|%:R^-1 * \sum_(x in G) phi x * (psi x)^* ).
rewrite (big_setID H) /= (setIidPr sHG) addrC big1 ?add0r; last first.
by move=> x /setDP[_ /cfun0->]; rewrite mul0r.
by congr (_ * _); apply: eq_bigr => x Hx; rewrite cfResE.
set h' := _^-1; apply: canRL (mulKf (neq0CG G)) _.
transitivity (h' * \sum_(y in G) \sum_(x in G) phi (x ^ y) * (psi (x ^ y))^* ).
rewrite mulrCA mulr_natl -sumr_const; congr (_ * _); apply: eq_bigr => y Gy.
by rewrite (reindex_acts 'J _ Gy) ?astabsJ ?normG.
rewrite exchange_big mulr_sumr; apply: eq_bigr => x _; rewrite cfIndE //=.
by rewrite -mulrA mulr_suml; congr (_ * _); apply: eq_bigr => y /(cfunJ psi)->.
Qed.
Definition cfdot_Res_r := Frobenius_reciprocity.
Lemma cfdot_Res_l psi phi : '['Res[H] psi, phi] = '[psi, 'Ind[G] phi].
Proof. by rewrite cfdotC cfdot_Res_r -cfdotC. Qed.
Lemma cfIndM phi psi: H \subset G ->
'Ind[G] (phi * ('Res[H] psi)) = 'Ind[G] phi * psi.
Proof.
move=> HsG; apply/cfun_inP=> x Gx; rewrite !cfIndE // !cfunE !cfIndE // -mulrA.
congr (_ * _); rewrite mulr_suml; apply: eq_bigr=> i iG; rewrite !cfunE.
case: (boolP (x ^ i \in H)) => xJi; last by rewrite cfun0gen ?mul0r ?genGid.
by rewrite !cfResE //; congr (_ * _); rewrite cfunJgen ?genGid.
Qed.
End Induced.
Arguments cfInd {gT} B%_g {A%_g} phi%_CF.
Notation "''Ind[' G , H ]" := (@cfInd _ G H) (only parsing) : ring_scope.
Notation "''Ind[' G ]" := 'Ind[G, _] : ring_scope.
Notation "''Ind'" := 'Ind[_] (only parsing) : ring_scope.
Section MorphInduced.
Variables (aT rT : finGroupType) (D G H : {group aT}) (R S : {group rT}).
Lemma cfIndMorph (f : {morphism D >-> rT}) (phi : 'CF(f @* H)) :
'ker f \subset H -> H \subset G -> G \subset D ->
'Ind[G] (cfMorph phi) = cfMorph ('Ind[f @* G] phi).
Proof.
move=> sKH sHG sGD; have [sHD inD] := (subset_trans sHG sGD, subsetP sGD).
apply/cfun_inP=> /= x Gx; have [Dx sKG] := (inD x Gx, subset_trans sKH sHG).
rewrite cfMorphE ?cfIndE ?morphimS // (partition_big_imset f) -morphimEsub //=.
rewrite card_morphim (setIidPr sHD) natf_indexg // invfM invrK -mulrA.
congr (_ * _); rewrite mulr_sumr; apply: eq_bigr => _ /morphimP[y Dy Gy ->].
rewrite -(card_rcoset _ y) mulr_natl -sumr_const.
apply: eq_big => [z | z /andP[Gz /eqP <-]].
have [Gz | G'z] := boolP (z \in G).
by rewrite (sameP eqP (rcoset_kerP _ _ _)) ?inD.
by case: rcosetP G'z => // [[t Kt ->]]; rewrite groupM // (subsetP sKG).
have [Dz Dxz] := (inD z Gz, inD (x ^ z) (groupJ Gx Gz)); rewrite -morphJ //.
have [Hxz | notHxz] := boolP (x ^ z \in H); first by rewrite cfMorphE.
by rewrite !cfun0 // -sub1set -morphim_set1 // morphimSGK ?sub1set.
Qed.
Variables (g : {morphism G >-> rT}) (h : {morphism H >-> rT}).
Hypotheses (isoG : isom G R g) (isoH : isom H S h) (eq_hg : {in H, h =1 g}).
Hypothesis sHG : H \subset G.
Lemma cfResIsom phi : 'Res[S] (cfIsom isoG phi) = cfIsom isoH ('Res[H] phi).
Proof.
have [[injg defR] [injh defS]] := (isomP isoG, isomP isoH).
rewrite !morphimEdom in defS defR; apply/cfun_inP=> s.
rewrite -{1}defS => /imsetP[x Hx ->] {s}; have Gx := subsetP sHG x Hx.
rewrite {1}eq_hg ?(cfResE, cfIsomE) // -defS -?eq_hg ?imset_f // -defR.
by rewrite (eq_in_imset eq_hg) imsetS.
Qed.
Lemma cfIndIsom phi : 'Ind[R] (cfIsom isoH phi) = cfIsom isoG ('Ind[G] phi).
Proof.
have [[injg defR] [_ defS]] := (isomP isoG, isomP isoH).
rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS.
apply/cfun_inP=> s; rewrite -{1}defR => /morphimP[x _ Gx ->]{s}.
rewrite cfIsomE ?cfIndE // -defR -{1}defS ?morphimS ?card_injm // morphimEdom.
congr (_ * _); rewrite big_imset //=; last exact/injmP.
apply: eq_bigr => y Gy; rewrite -morphJ //.
have [Hxy | H'xy] := boolP (x ^ y \in H); first by rewrite -eq_hg ?cfIsomE.
by rewrite !cfun0 -?defS // -sub1set -morphim_set1 ?injmSK ?sub1set // groupJ.
Qed.
End MorphInduced.
Section FieldAutomorphism.
Variables (u : {rmorphism algC -> algC}) (gT rT : finGroupType).
Variables (G K H : {group gT}) (f : {morphism G >-> rT}) (R : {group rT}).
Implicit Types (phi : 'CF(G)) (S : seq 'CF(G)).
Local Notation "phi ^u" := (cfAut u phi).
Lemma cfAutZ_nat n phi : (n%:R *: phi)^u = n%:R *: phi^u.
Proof. exact: raddfZnat. Qed.
Lemma cfAutZ_Cnat z phi : z \in Num.nat -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_nat. Qed.
Lemma cfAutZ_Cint z phi : z \in Num.int -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_int. Qed.
Lemma cfAutK : cancel (@cfAut gT G u) (cfAut (algC_invaut u)).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_autK. Qed.
Lemma cfAutVK : cancel (cfAut (algC_invaut u)) (@cfAut gT G u).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_invautK. Qed.
Lemma cfAut_inj : injective (@cfAut gT G u).
Proof. exact: can_inj cfAutK. Qed.
Lemma cfAut_eq1 phi : (cfAut u phi == 1) = (phi == 1).
Proof. by rewrite rmorph_eq1 //; apply: cfAut_inj. Qed.
Lemma support_cfAut phi : support phi^u =i support phi.
Proof. by move=> x; rewrite !inE cfunE fmorph_eq0. Qed.
Lemma map_cfAut_free S : cfAut_closed u S -> free S -> free (map (cfAut u) S).
Proof.
set Su := map _ S => sSuS freeS; have uniqS := free_uniq freeS.
have uniqSu: uniq Su by rewrite (map_inj_uniq cfAut_inj).
have{} sSuS: {subset Su <= S} by move=> _ /mapP[phi Sphi ->]; apply: sSuS.
have [|_ eqSuS] := uniq_min_size uniqSu sSuS; first by rewrite size_map.
by rewrite (perm_free (uniq_perm uniqSu uniqS eqSuS)).
Qed.
Lemma cfAut_on A phi : (phi^u \in 'CF(G, A)) = (phi \in 'CF(G, A)).
Proof. by rewrite !cfun_onE (eq_subset (support_cfAut phi)). Qed.
Lemma cfker_aut phi : cfker phi^u = cfker phi.
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
by apply/forallP/forallP=> Kx y;
have:= Kx y; rewrite !cfunE (inj_eq (fmorph_inj u)).
Qed.
Lemma cfAut_cfuni A : ('1_A)^u = '1_A :> 'CF(G).
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cforder_aut phi : #[phi^u]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfAut_inj. Qed.
Lemma cfAutRes phi : ('Res[H] phi)^u = 'Res phi^u.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutMorph (psi : 'CF(f @* H)) : (cfMorph psi)^u = cfMorph psi^u.
Proof. by apply/cfun_inP=> x Hx; rewrite !cfunElock Hx. Qed.
Lemma cfAutIsom (isoGR : isom G R f) phi :
(cfIsom isoGR phi)^u = cfIsom isoGR phi^u.
Proof.
apply/cfun_inP=> y; have [_ {1}<-] := isomP isoGR => /morphimP[x _ Gx ->{y}].
by rewrite !(cfunE, cfIsomE).
Qed.
Lemma cfAutQuo phi : (phi / H)^u = (phi^u / H)%CF.
Proof. by apply/cfunP=> Hx; rewrite !cfunElock cfker_aut rmorphMn. Qed.
Lemma cfAutMod (psi : 'CF(G / H)) : (psi %% H)^u = (psi^u %% H)%CF.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutInd (psi : 'CF(H)) : ('Ind[G] psi)^u = 'Ind psi^u.
Proof.
have [sHG | not_sHG] := boolP (H \subset G).
apply/cfunP=> x; rewrite !(cfunE, cfIndE) // rmorphM /= fmorphV rmorph_nat.
by congr (_ * _); rewrite rmorph_sum; apply: eq_bigr => y; rewrite !cfunE.
rewrite !cfIndEout // linearZ /= cfAut_cfuni rmorphM rmorph_nat /=.
rewrite -cfdot_cfAut ?rmorph1 // => _ /imageP[x Hx ->].
by rewrite cfun1E Hx !rmorph1.
Qed.
Hypothesis KxH : K \x H = G.
Lemma cfAutDprodl (phi : 'CF(K)) : (cfDprodl KxH phi)^u = cfDprodl KxH phi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEl).
Qed.
Lemma cfAutDprodr (psi : 'CF(H)) : (cfDprodr KxH psi)^u = cfDprodr KxH psi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEr).
Qed.
Lemma cfAutDprod (phi : 'CF(K)) (psi : 'CF(H)) :
(cfDprod KxH phi psi)^u = cfDprod KxH phi^u psi^u.
Proof. by rewrite rmorphM /= cfAutDprodl cfAutDprodr. Qed.
End FieldAutomorphism.
Arguments cfAutK u {gT G}.
Arguments cfAutVK u {gT G}.
Arguments cfAut_inj u {gT G} [phi1 phi2] : rename.
Definition conj_cfRes := cfAutRes conjC.
Definition cfker_conjC := cfker_aut conjC.
Definition conj_cfQuo := cfAutQuo conjC.
Definition conj_cfMod := cfAutMod conjC.
Definition conj_cfInd := cfAutInd conjC.
Definition cfconjC_eq1 := cfAut_eq1 conjC.
|
Sort.lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.List.Sort
import Mathlib.Data.Multiset.Range
import Mathlib.Util.Qq
/-!
# Construct a sorted list from a multiset.
-/
variable {α β : Type*}
namespace Multiset
open List
section sort
variable (r : α → α → Prop) [DecidableRel r] [IsTrans α r] [IsAntisymm α r] [IsTotal α r]
variable (r' : β → β → Prop) [DecidableRel r'] [IsTrans β r'] [IsAntisymm β r'] [IsTotal β r']
/-- `sort s` constructs a sorted list from the multiset `s`.
(Uses merge sort algorithm.) -/
def sort (s : Multiset α) : List α :=
Quot.liftOn s (mergeSort · (r · ·)) fun _ _ h =>
eq_of_perm_of_sorted ((mergeSort_perm _ _).trans <| h.trans (mergeSort_perm _ _).symm)
(sorted_mergeSort IsTrans.trans
(fun a b => by simpa using IsTotal.total a b) _)
(sorted_mergeSort IsTrans.trans
(fun a b => by simpa using IsTotal.total a b) _)
@[simp]
theorem coe_sort (l : List α) : sort r l = mergeSort l (r · ·) :=
rfl
@[simp]
theorem sort_sorted (s : Multiset α) : Sorted r (sort r s) :=
Quot.inductionOn s (sorted_mergeSort' _)
@[simp]
theorem sort_eq (s : Multiset α) : ↑(sort r s) = s :=
Quot.inductionOn s fun _ => Quot.sound <| mergeSort_perm _ _
@[simp]
theorem mem_sort {s : Multiset α} {a : α} : a ∈ sort r s ↔ a ∈ s := by rw [← mem_coe, sort_eq]
@[simp]
theorem length_sort {s : Multiset α} : (sort r s).length = card s :=
Quot.inductionOn s <| length_mergeSort
@[simp]
theorem sort_zero : sort r 0 = [] :=
List.mergeSort_nil
@[simp]
theorem sort_singleton (a : α) : sort r {a} = [a] :=
List.mergeSort_singleton a
theorem map_sort (f : α → β) (s : Multiset α)
(hs : ∀ a ∈ s, ∀ b ∈ s, r a b ↔ r' (f a) (f b)) :
(s.sort r).map f = (s.map f).sort r' := by
revert s
exact Quot.ind fun l h => map_mergeSort (l := l) (by simpa using h)
theorem sort_cons (a : α) (s : Multiset α) :
(∀ b ∈ s, r a b) → sort r (a ::ₘ s) = a :: sort r s := by
refine Quot.inductionOn s fun l => ?_
simpa [mergeSort_eq_insertionSort] using insertionSort_cons r (a := a) (l := l)
@[simp]
theorem sort_range (n : ℕ) : sort (· ≤ ·) (range n) = List.range n :=
List.mergeSort_eq_self _ (sorted_le_range n)
end sort
open Qq in
universe u in
unsafe instance {α : Type u} [Lean.ToLevel.{u}] [Lean.ToExpr α] :
Lean.ToExpr (Multiset α) :=
haveI u' := Lean.toLevel.{u}
haveI α' : Q(Type u') := Lean.toTypeExpr α
{ toTypeExpr := q(Multiset $α')
toExpr s := show Q(Multiset $α') from
if Multiset.card s = 0 then
q(0)
else
mkSetLiteralQ (α := q($α')) q(Multiset $α') (s.unquot.map Lean.toExpr)}
-- TODO: use a sort order if available, gh-18166
unsafe instance [Repr α] : Repr (Multiset α) where
reprPrec s _ :=
if Multiset.card s = 0 then
"0"
else
Std.Format.bracket "{" (Std.Format.joinSep (s.unquot.map repr) ("," ++ Std.Format.line)) "}"
end Multiset
|
Chain.lean
|
/-
Copyright (c) 2025 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.RootSystem.Finite.Lemmas
import Mathlib.Order.Interval.Set.OrdConnectedLinear
/-!
# Chains of roots
Given roots `α` and `β`, the `α`-chain through `β` is the set of roots of the form `α + z • β`
for an integer `z`. This is known as a "root chain" and also a "root string". For linearly
independent roots in finite crystallographic root pairings, these chains are always unbroken, i.e.,
of the form: `β - q • α, ..., β - α, β, β + α, ..., β + p • α` for natural numbers `p`, `q`, and the
length, `p + q` is at most 3.
## Main definitions / results:
* `RootPairing.chainTopCoeff`: the natural number `p` in the chain
`β - q • α, ..., β - α, β, β + α, ..., β + p • α`
* `RootPairing.chainTopCoeff`: the natural number `q` in the chain
`β - q • α, ..., β - α, β, β + α, ..., β + p • α`
* `RootPairing.root_add_zsmul_mem_range_iff`: every chain is an interval (aka unbroken).
* `RootPairing.chainBotCoeff_add_chainTopCoeff_le`: every chain has length at most three.
-/
noncomputable section
open FaithfulSMul Function Set Submodule
variable {ι R M N : Type*} [Finite ι] [CommRing R] [CharZero R] [IsDomain R]
[AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
namespace RootPairing
variable {P : RootPairing ι R M N} [P.IsCrystallographic] {i j : ι}
/-- Note that it is often more convenient to use `RootPairing.root_add_zsmul_mem_range_iff` than
to invoke this lemma directly. -/
lemma setOf_root_add_zsmul_eq_Icc_of_linearIndependent
(h : LinearIndependent R ![P.root i, P.root j]) :
∃ᵉ (q ≤ 0) (p ≥ 0), {z : ℤ | P.root j + z • P.root i ∈ range P.root} = Icc q p := by
replace h := LinearIndependent.pair_iff.mp <| h.restrict_scalars' ℤ
set S : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S_def
have hS₀ : 0 ∈ S := by simp [S]
have h_fin : S.Finite := by
suffices Injective (fun z : S ↦ z.property.choose) from Finite.of_injective _ this
intro ⟨z, hz⟩ ⟨z', hz'⟩ hzz
have : z • P.root i = z' • P.root i := by
rwa [← add_right_inj (P.root j), ← hz.choose_spec, ← hz'.choose_spec, P.root.injective.eq_iff]
have _i : NoZeroSMulDivisors ℤ M := have := P.reflexive_left; .int_of_charZero R M
exact Subtype.ext <| smul_left_injective ℤ (P.ne_zero i) this
have h_ne : S.Nonempty := ⟨0, by simp [S_def]⟩
refine ⟨sInf S, csInf_le h_fin.bddBelow hS₀, sSup S, le_csSup h_fin.bddAbove hS₀,
(h_ne.eq_Icc_iff_int h_fin.bddBelow h_fin.bddAbove).mpr fun r ⟨k, hk⟩ s ⟨l, hl⟩ hrs ↦ ?_⟩
by_contra! contra
have hki_notMem : P.root k + P.root i ∉ range P.root := by
replace hk : P.root k + P.root i = P.root j + (r + 1) • P.root i := by rw [hk]; module
replace contra : r + 1 ∉ S := hrs.notMem_of_mem_left <| by simp [contra]
simpa only [hk, S_def, mem_setOf_eq, S] using contra
have hki_ne : P.root k ≠ -P.root i := by
rw [hk]
contrapose! h
replace h : r • P.root i = - P.root j - P.root i := by rw [← sub_eq_of_eq_add h.symm]; module
exact ⟨r + 1, 1, by simp [add_smul, h], by omega⟩
have hli_notMem : P.root l - P.root i ∉ range P.root := by
replace hl : P.root l - P.root i = P.root j + (s - 1) • P.root i := by rw [hl]; module
replace contra : s - 1 ∉ S := hrs.notMem_of_mem_left <| by simp [lt_sub_right_of_add_lt contra]
simpa only [hl, S_def, mem_setOf_eq, S] using contra
have hli_ne : P.root l ≠ P.root i := by
rw [hl]
contrapose! h
replace h : s • P.root i = P.root i - P.root j := by rw [← sub_eq_of_eq_add h.symm]; module
exact ⟨s - 1, 1, by simp [sub_smul, h], by omega⟩
have h₁ : 0 ≤ P.pairingIn ℤ k i := by
have := P.root_add_root_mem_of_pairingIn_neg (i := k) (j := i)
contrapose! this
exact ⟨this, hki_ne, hki_notMem⟩
have h₂ : P.pairingIn ℤ k i = P.pairingIn ℤ j i + r * 2 := by
apply algebraMap_injective ℤ R
rw [algebraMap_pairingIn, map_add, map_mul, algebraMap_pairingIn, ← root_coroot'_eq_pairing, hk]
simp
have h₃ : P.pairingIn ℤ l i ≤ 0 := by
have := P.root_sub_root_mem_of_pairingIn_pos (i := l) (j := i)
contrapose! this
exact ⟨this, fun x ↦ hli_ne (congrArg P.root x), hli_notMem⟩
have h₄ : P.pairingIn ℤ l i = P.pairingIn ℤ j i + s * 2 := by
apply algebraMap_injective ℤ R
rw [algebraMap_pairingIn, map_add, map_mul, algebraMap_pairingIn, ← root_coroot'_eq_pairing, hl]
simp
omega
variable (i j)
open scoped Classical in
/-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the value `p ≥ 0` where
`β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`.
In the absence of linear independence, it takes a junk value. -/
def chainTopCoeff : ℕ :=
if h : LinearIndependent R ![P.root i, P.root j]
then (P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.2.choose.toNat
else 0
open scoped Classical in
/-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the value `q ≥ 0` where
`β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`.
In the absence of linear independence, it takes a junk value. -/
def chainBotCoeff : ℕ :=
if h : LinearIndependent R ![P.root i, P.root j]
then (-(P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose).toNat
else 0
variable {i j}
lemma chainTopCoeff_of_not_linearIndependent (h : ¬ LinearIndependent R ![P.root i, P.root j]) :
P.chainTopCoeff i j = 0 := by
simp only [chainTopCoeff, h, reduceDIte]
lemma chainBotCoeff_of_not_linearIndependent (h : ¬ LinearIndependent R ![P.root i, P.root j]) :
P.chainBotCoeff i j = 0 := by
simp only [chainBotCoeff, h, reduceDIte]
variable (h : LinearIndependent R ![P.root i, P.root j])
include h
lemma root_add_nsmul_mem_range_iff_le_chainTopCoeff {n : ℕ} :
P.root j + n • P.root i ∈ range P.root ↔ n ≤ P.chainTopCoeff i j := by
set S : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S_def
suffices (n : ℤ) ∈ S ↔ n ≤ P.chainTopCoeff i j by
simpa only [S_def, mem_setOf_eq, natCast_zsmul] using this
have aux : P.chainTopCoeff i j =
(P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.2.choose.toNat := by
simp [chainTopCoeff, h]
obtain ⟨hp, h₂ : S = _⟩ :=
(P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.2.choose_spec
rw [aux, h₂, mem_Icc]
have := (P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec.1
omega
lemma root_sub_nsmul_mem_range_iff_le_chainBotCoeff {n : ℕ} :
P.root j - n • P.root i ∈ range P.root ↔ n ≤ P.chainBotCoeff i j := by
set S : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S_def
suffices -(n : ℤ) ∈ S ↔ n ≤ P.chainBotCoeff i j by
simpa only [S_def, mem_setOf_eq, neg_smul, natCast_zsmul, ← sub_eq_add_neg] using this
have aux : P.chainBotCoeff i j =
(-(P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose).toNat := by
simp [chainBotCoeff, h]
obtain ⟨hq, p, hp, h₂ : S = _⟩ :=
(P.setOf_root_add_zsmul_eq_Icc_of_linearIndependent h).choose_spec
rw [aux, h₂, mem_Icc]
omega
lemma Iic_chainTopCoeff_eq :
Iic (P.chainTopCoeff i j) = {k | P.root j + k • P.root i ∈ range P.root} := by
ext; simp [← P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h]
lemma Iic_chainBotCoeff_eq :
Iic (P.chainBotCoeff i j) = {k | P.root j - k • P.root i ∈ range P.root} := by
ext; simp [← P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h]
omit h in
lemma one_le_chainTopCoeff_of_root_add_mem [P.IsReduced] (h : P.root i + P.root j ∈ range P.root) :
1 ≤ P.chainTopCoeff i j := by
have h' := P.linearIndependent_of_add_mem_range_root' h
rwa [← root_add_nsmul_mem_range_iff_le_chainTopCoeff h', one_smul, add_comm]
omit h in
lemma one_le_chainBotCoeff_of_root_add_mem [P.IsReduced] (h : P.root i - P.root j ∈ range P.root) :
1 ≤ P.chainBotCoeff i j := by
have h' := P.linearIndependent_of_sub_mem_range_root' h
rwa [← root_sub_nsmul_mem_range_iff_le_chainBotCoeff h', one_smul, ← neg_mem_range_root_iff,
neg_sub]
lemma root_add_zsmul_mem_range_iff {z : ℤ} :
P.root j + z • P.root i ∈ range P.root ↔
z ∈ Icc (- P.chainBotCoeff i j : ℤ) (P.chainTopCoeff i j) := by
rcases z.eq_nat_or_neg with ⟨n, rfl | rfl⟩
· simp [P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h]
· simp [P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h, ← sub_eq_add_neg]
lemma root_sub_zsmul_mem_range_iff {z : ℤ} :
P.root j - z • P.root i ∈ range P.root ↔
z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) := by
rw [sub_eq_add_neg, ← neg_smul, P.root_add_zsmul_mem_range_iff h, mem_Icc, mem_Icc]
omega
lemma setOf_root_add_zsmul_mem_eq_Icc :
{k : ℤ | P.root j + k • P.root i ∈ range P.root} =
Icc (-P.chainBotCoeff i j : ℤ) (P.chainTopCoeff i j) := by
ext; simp [← P.root_add_zsmul_mem_range_iff h]
lemma setOf_root_sub_zsmul_mem_eq_Icc :
{k : ℤ | P.root j - k • P.root i ∈ range P.root} =
Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) := by
ext; rw [← root_sub_zsmul_mem_range_iff h, mem_setOf_eq]
lemma chainTopCoeff_eq_sSup :
P.chainTopCoeff i j = sSup {k | P.root j + k • P.root i ∈ range P.root} := by
rw [← Iic_chainTopCoeff_eq h, csSup_Iic]
lemma chainBotCoeff_eq_sSup :
P.chainBotCoeff i j = sSup {k | P.root j - k • P.root i ∈ range P.root} := by
rw [← Iic_chainBotCoeff_eq h, csSup_Iic]
lemma coe_chainTopCoeff_eq_sSup :
P.chainTopCoeff i j = sSup {k : ℤ | P.root j + k • P.root i ∈ range P.root} := by
rw [setOf_root_add_zsmul_mem_eq_Icc h]
simp
lemma coe_chainBotCoeff_eq_sSup :
P.chainBotCoeff i j = sSup {k : ℤ | P.root j - k • P.root i ∈ range P.root} := by
rw [setOf_root_sub_zsmul_mem_eq_Icc h]
simp
omit h
private lemma chainCoeff_reflectionPerm_left_aux :
letI := P.indexNeg
Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) =
Icc (-P.chainBotCoeff (-i) j : ℤ) (P.chainTopCoeff (-i) j) := by
letI := P.indexNeg
by_cases h : LinearIndependent R ![P.root i, P.root j]
· have h' : LinearIndependent R ![P.root (-i), P.root j] := by simpa
ext z
rw [← P.root_add_zsmul_mem_range_iff h', indexNeg_neg, root_reflectionPerm, mem_Icc,
reflection_apply_self, smul_neg, ← neg_smul, P.root_add_zsmul_mem_range_iff h, mem_Icc]
omega
· have h' : ¬ LinearIndependent R ![P.root (-i), P.root j] := by simpa
simp only [chainTopCoeff_of_not_linearIndependent h, chainTopCoeff_of_not_linearIndependent h',
chainBotCoeff_of_not_linearIndependent h, chainBotCoeff_of_not_linearIndependent h']
@[deprecated (since := "2025-05-28")]
alias chainCoeff_reflection_perm_left_aux := chainCoeff_reflectionPerm_left_aux
private lemma chainCoeff_reflectionPerm_right_aux :
letI := P.indexNeg
Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) =
Icc (-P.chainBotCoeff i (-j) : ℤ) (P.chainTopCoeff i (-j)) := by
letI := P.indexNeg
by_cases h : LinearIndependent R ![P.root i, P.root j]
· have h' : LinearIndependent R ![P.root i, P.root (-j)] := by simpa
ext z
rw [← P.root_add_zsmul_mem_range_iff h', indexNeg_neg, root_reflectionPerm, mem_Icc,
reflection_apply_self, ← sub_neg_eq_add, ← neg_sub', neg_mem_range_root_iff,
P.root_sub_zsmul_mem_range_iff h, mem_Icc]
· have h' : ¬ LinearIndependent R ![P.root i, P.root (-j)] := by simpa
simp only [chainTopCoeff_of_not_linearIndependent h, chainTopCoeff_of_not_linearIndependent h',
chainBotCoeff_of_not_linearIndependent h, chainBotCoeff_of_not_linearIndependent h']
@[deprecated (since := "2025-05-28")]
alias chainCoeff_reflection_perm_right_aux := chainCoeff_reflectionPerm_right_aux
@[simp]
lemma chainTopCoeff_reflectionPerm_left :
P.chainTopCoeff (P.reflectionPerm i i) j = P.chainBotCoeff i j := by
letI := P.indexNeg
have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔
z ∈ Icc (-P.chainBotCoeff (-i) j : ℤ) (P.chainTopCoeff (-i) j) := by
rw [P.chainCoeff_reflectionPerm_left_aux]
refine le_antisymm ?_ ?_
· simpa using this (P.chainTopCoeff (-i) j)
· simpa using this (P.chainBotCoeff i j)
@[deprecated (since := "2025-05-28")]
alias chainTopCoeff_reflection_perm_left := chainTopCoeff_reflectionPerm_left
@[simp]
lemma chainBotCoeff_reflectionPerm_left :
P.chainBotCoeff (P.reflectionPerm i i) j = P.chainTopCoeff i j := by
letI := P.indexNeg
have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔
z ∈ Icc (-P.chainBotCoeff (-i) j : ℤ) (P.chainTopCoeff (-i) j) := by
rw [P.chainCoeff_reflectionPerm_left_aux]
refine le_antisymm ?_ ?_
· simpa using this (-P.chainBotCoeff (-i) j)
· simpa using this (-P.chainTopCoeff i j)
@[deprecated (since := "2025-05-28")]
alias chainBotCoeff_reflection_perm_left := chainBotCoeff_reflectionPerm_left
@[simp]
lemma chainTopCoeff_reflectionPerm_right :
P.chainTopCoeff i (P.reflectionPerm j j) = P.chainBotCoeff i j := by
letI := P.indexNeg
have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔
z ∈ Icc (-P.chainBotCoeff i (-j) : ℤ) (P.chainTopCoeff i (-j)) := by
rw [P.chainCoeff_reflectionPerm_right_aux]
refine le_antisymm ?_ ?_
· simpa using this (P.chainTopCoeff i (-j))
· simpa using this (P.chainBotCoeff i j)
@[deprecated (since := "2025-05-28")]
alias chainTopCoeff_reflection_perm_right := chainTopCoeff_reflectionPerm_right
@[simp]
lemma chainBotCoeff_reflectionPerm_right :
P.chainBotCoeff i (P.reflectionPerm j j) = P.chainTopCoeff i j := by
letI := P.indexNeg
have (z : ℤ) : z ∈ Icc (-P.chainTopCoeff i j : ℤ) (P.chainBotCoeff i j) ↔
z ∈ Icc (-P.chainBotCoeff i (-j) : ℤ) (P.chainTopCoeff i (-j)) := by
rw [P.chainCoeff_reflectionPerm_right_aux]
refine le_antisymm ?_ ?_
· simpa using this (-P.chainBotCoeff i (-j))
· simpa using this (-P.chainTopCoeff i j)
lemma chainBotCoeff_eq_zero_iff :
P.chainBotCoeff i j = 0 ↔
¬ LinearIndependent R ![P.root i, P.root j] ∨ P.root j - P.root i ∉ range P.root := by
by_cases h : LinearIndependent R ![P.root i, P.root j]
swap; · simp [chainBotCoeff_of_not_linearIndependent h, h]
have : P.chainBotCoeff i j = 0 ↔ Iic (P.chainBotCoeff i j) = {0} := by
simpa [Set.ext_iff, mem_Iic, mem_singleton_iff] using ⟨fun h ↦ by simp [h], fun h ↦ by rw [← h]⟩
simp only [h, not_true_eq_false, false_or, this, Iic_chainBotCoeff_eq h, Set.ext_iff,
mem_setOf_eq, mem_singleton_iff]
refine ⟨fun h' ↦ by simpa using h' 1, fun h' n ↦ ⟨fun h'' ↦ ?_, fun h'' ↦ by simp [h'']⟩⟩
replace h' : 1 ∉ {k | P.root j - k • P.root i ∈ range P.root} := by simpa using h'
rw [← Iic_chainBotCoeff_eq h, mem_Iic, not_le, Nat.lt_one_iff] at h'
rw [root_sub_nsmul_mem_range_iff_le_chainBotCoeff h] at h''
omega
lemma chainTopCoeff_eq_zero_iff :
P.chainTopCoeff i j = 0 ↔
¬ LinearIndependent R ![P.root i, P.root j] ∨ P.root j + P.root i ∉ range P.root := by
rw [← chainBotCoeff_reflectionPerm_left]
simp [-chainBotCoeff_reflectionPerm_left, chainBotCoeff_eq_zero_iff]
include h
lemma chainBotCoeff_of_add {k : ι} (hk : P.root k = P.root j + P.root i) :
P.chainBotCoeff i k = P.chainBotCoeff i j + 1 := by
have h' : LinearIndependent R ![P.root i, P.root k] := by simpa [hk, add_comm]
apply Nat.cast_injective (R := ℤ)
rw [Nat.cast_add, Nat.cast_one, coe_chainBotCoeff_eq_sSup h', coe_chainBotCoeff_eq_sSup h]
have (z : ℤ) : P.root k - z • P.root i = P.root j - (z - 1) • P.root i := by rw [hk]; module
replace this : {z : ℤ | P.root k - z • P.root i ∈ range P.root} =
OrderIso.addRight 1 '' {n | P.root j - n • P.root i ∈ range P.root} := by
simp [this, sub_eq_add_neg]
have bdd : BddAbove {z : ℤ | P.root j - z • P.root i ∈ range P.root} := by
rw [setOf_root_sub_zsmul_mem_eq_Icc h]
exact bddAbove_Icc
rw [this, ← OrderIso.map_csSup' _ ⟨0, by simp⟩ bdd, OrderIso.addRight_apply]
lemma chainTopCoeff_of_sub {k : ι} (hk : P.root k = P.root j - P.root i) :
P.chainTopCoeff i k = P.chainTopCoeff i j + 1 := by
letI := P.indexNeg
replace hk : P.root k = P.root j + P.root (-i) := by simpa [sub_eq_add_neg] using hk
simpa using chainBotCoeff_of_add (by simpa) hk
lemma chainTopCoeff_of_add {k : ι} (hk : P.root k = P.root j + P.root i) :
P.chainTopCoeff i j = P.chainTopCoeff i k + 1 := by
replace h : LinearIndependent R ![P.root i, P.root k] := by rw [hk, add_comm]; simpa
replace hk : P.root j = P.root k - P.root i := by rw [hk]; abel
exact chainTopCoeff_of_sub h hk
omit h
@[deprecated (since := "2025-05-28")]
alias chainBotCoeff_reflection_perm_right := chainBotCoeff_reflectionPerm_right
variable (i j)
open scoped Classical in
/-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the index of the root
`β + p • α` where `β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`.
In the absence of linear independence, it takes a junk value. -/
def chainTopIdx : ι :=
if h : LinearIndependent R ![P.root i, P.root j]
then (P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h).mpr
(le_refl <| P.chainTopCoeff i j) |>.choose
else j
open scoped Classical in
/-- If `α = P.root i` and `β = P.root j` are linearly independent, this is the index of the root
`β - q • α` where `β - q • α, ..., β - α, β, β + α, ..., β + p • α` is the `α`-chain through `β`.
In the absence of linear independence, it takes a junk value. -/
def chainBotIdx : ι :=
if h : LinearIndependent R ![P.root i, P.root j]
then (P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h).mpr
(le_refl <| P.chainBotCoeff i j) |>.choose
else j
variable {i j}
@[simp]
lemma root_chainTopIdx :
P.root (P.chainTopIdx i j) = P.root j + P.chainTopCoeff i j • P.root i := by
by_cases h : LinearIndependent R ![P.root i, P.root j]
· simp only [chainTopIdx, reduceDIte, h]
exact (P.root_add_nsmul_mem_range_iff_le_chainTopCoeff h).mpr
(le_refl <| P.chainTopCoeff i j) |>.choose_spec
· simp only [chainTopIdx, chainTopCoeff, h, reduceDIte, zero_smul, add_zero]
@[simp]
lemma root_chainBotIdx :
P.root (P.chainBotIdx i j) = P.root j - P.chainBotCoeff i j • P.root i := by
by_cases h : LinearIndependent R ![P.root i, P.root j]
· simp only [chainBotIdx, reduceDIte, h]
exact (P.root_sub_nsmul_mem_range_iff_le_chainBotCoeff h).mpr
(le_refl <| P.chainBotCoeff i j) |>.choose_spec
· simp only [chainBotIdx, chainBotCoeff, h, reduceDIte, zero_smul, sub_zero]
include h
lemma chainBotCoeff_sub_chainTopCoeff :
P.chainBotCoeff i j - P.chainTopCoeff i j = P.pairingIn ℤ j i := by
suffices ∀ i j, LinearIndependent R ![P.root i, P.root j] →
P.chainBotCoeff i j - P.chainTopCoeff i j ≤ P.pairingIn ℤ j i by
refine le_antisymm (this i j h) ?_
specialize this (P.reflectionPerm i i) j (by simpa)
simp only [chainBotCoeff_reflectionPerm_left, chainTopCoeff_reflectionPerm_left,
pairingIn_reflectionPerm_self_right] at this
omega
intro i j h
have h₁ : P.reflection i (P.root <| P.chainBotIdx i j) =
P.root j + (P.chainBotCoeff i j - P.pairingIn ℤ j i) • P.root i := by
simp [reflection_apply_root, ← P.algebraMap_pairingIn ℤ]
module
have h₂ : P.reflection i (P.root <| P.chainBotIdx i j) ∈ range P.root := by
rw [← root_reflectionPerm]
exact mem_range_self _
rw [h₁, root_add_zsmul_mem_range_iff h, mem_Icc] at h₂
omega
lemma chainTopCoeff_sub_chainBotCoeff :
P.chainTopCoeff i j - P.chainBotCoeff i j = - P.pairingIn ℤ j i := by
rw [← chainBotCoeff_sub_chainTopCoeff h, neg_sub]
omit h
lemma chainCoeff_chainTopIdx_aux :
P.chainBotCoeff i (P.chainTopIdx i j) = P.chainBotCoeff i j + P.chainTopCoeff i j ∧
P.chainTopCoeff i (P.chainTopIdx i j) = 0 := by
have aux : LinearIndependent R ![P.root i, P.root j] ↔
LinearIndependent R ![P.root i, P.root (P.chainTopIdx i j)] := by
rw [P.root_chainTopIdx, add_comm (P.root j), ← natCast_zsmul,
LinearIndependent.pair_add_smul_right_iff]
by_cases h : LinearIndependent R ![P.root i, P.root j]
swap; · simp [chainTopCoeff_of_not_linearIndependent, chainBotCoeff_of_not_linearIndependent, h]
have h' : LinearIndependent R ![P.root i, P.root (P.chainTopIdx i j)] := by rwa [← aux]
set S₁ : Set ℤ := {z | P.root j + z • P.root i ∈ range P.root} with S₁_def
set S₂ : Set ℤ := {z | P.root (P.chainTopIdx i j) + z • P.root i ∈ range P.root} with S₂_def
have hS₁₂ : S₂ = (fun z ↦ (-P.chainTopCoeff i j : ℤ) + z) '' S₁ := by
ext; simp [S₁_def, S₂_def, root_chainTopIdx, add_smul, add_assoc, natCast_zsmul]
have hS₁ : S₁ = Icc (- P.chainBotCoeff i j : ℤ) (P.chainTopCoeff i j) := by
ext; rw [S₁_def, mem_setOf_eq, root_add_zsmul_mem_range_iff h]
have hS₂ : S₂ = Icc (- P.chainBotCoeff i (P.chainTopIdx i j) : ℤ)
(P.chainTopCoeff i (P.chainTopIdx i j)) := by
ext; rw [S₂_def, mem_setOf_eq, root_add_zsmul_mem_range_iff h']
rw [hS₁, hS₂, image_const_add_Icc, neg_add_cancel, Icc_eq_Icc_iff (by simp), neg_eq_iff_eq_neg,
neg_add_rev, neg_neg, neg_neg] at hS₁₂
norm_cast at hS₁₂
@[simp]
lemma chainBotCoeff_chainTopIdx :
P.chainBotCoeff i (P.chainTopIdx i j) = P.chainBotCoeff i j + P.chainTopCoeff i j :=
chainCoeff_chainTopIdx_aux.1
@[simp]
lemma chainTopCoeff_chainTopIdx :
P.chainTopCoeff i (P.chainTopIdx i j) = 0 :=
chainCoeff_chainTopIdx_aux.2
include h in
lemma chainBotCoeff_add_chainTopCoeff_eq_pairingIn_chainTopIdx :
P.chainBotCoeff i j + P.chainTopCoeff i j = P.pairingIn ℤ (P.chainTopIdx i j) i := by
replace h : LinearIndependent R ![P.root i, P.root (P.chainTopIdx i j)] := by
rwa [P.root_chainTopIdx, add_comm (P.root j), ← natCast_zsmul,
LinearIndependent.pair_add_smul_right_iff]
calc (P.chainBotCoeff i j + P.chainTopCoeff i j : ℤ)
_ = P.chainBotCoeff i (P.chainTopIdx i j) := by simp
_ = P.chainBotCoeff i (P.chainTopIdx i j) - P.chainTopCoeff i (P.chainTopIdx i j) := by simp
_ = P.pairingIn ℤ (P.chainTopIdx i j) i := by rw [P.chainBotCoeff_sub_chainTopCoeff h]
lemma chainBotCoeff_add_chainTopCoeff_le_three [P.IsReduced] :
P.chainBotCoeff i j + P.chainTopCoeff i j ≤ 3 := by
by_cases h : LinearIndependent R ![P.root i, P.root j]
swap; · simp [chainTopCoeff_of_not_linearIndependent, chainBotCoeff_of_not_linearIndependent, h]
rw [← Int.ofNat_le, Nat.cast_add, Nat.cast_ofNat,
chainBotCoeff_add_chainTopCoeff_eq_pairingIn_chainTopIdx h]
have := P.pairingIn_pairingIn_mem_set_of_isCrystal_of_isRed i (P.chainTopIdx i j)
aesop
end RootPairing
|
EffectiveEpimorphic.lean
|
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Sites.Sieves
import Mathlib.CategoryTheory.EffectiveEpi.Basic
/-!
# Effective epimorphic sieves
We define the notion of effective epimorphic (pre)sieves and provide some API for relating the
notion with the notions of effective epimorphism and effective epimorphic family.
More precisely, if `f` is a morphism, then `f` is an effective epi if and only if the sieve
it generates is effective epimorphic; see `CategoryTheory.Sieve.effectiveEpimorphic_singleton`.
The analogous statement for a family of morphisms is in the theorem
`CategoryTheory.Sieve.effectiveEpimorphic_family`.
-/
namespace CategoryTheory
open Limits
variable {C : Type*} [Category C]
/-- A sieve is effective epimorphic if the associated cocone is a colimit cocone. -/
def Sieve.EffectiveEpimorphic {X : C} (S : Sieve X) : Prop :=
Nonempty (IsColimit (S : Presieve X).cocone)
/-- A presieve is effective epimorphic if the cocone associated to the sieve it generates
is a colimit cocone. -/
abbrev Presieve.EffectiveEpimorphic {X : C} (S : Presieve X) : Prop :=
(Sieve.generate S).EffectiveEpimorphic
/--
The sieve of morphisms which factor through a given morphism `f`.
This is equal to `Sieve.generate (Presieve.singleton f)`, but has
more convenient definitional properties.
-/
def Sieve.generateSingleton {X Y : C} (f : Y ⟶ X) : Sieve X where
arrows Z := { g | ∃ (e : Z ⟶ Y), e ≫ f = g }
downward_closed := by
rintro W Z g ⟨e,rfl⟩ q
exact ⟨q ≫ e, by simp⟩
lemma Sieve.generateSingleton_eq {X Y : C} (f : Y ⟶ X) :
Sieve.generate (Presieve.singleton f) = Sieve.generateSingleton f := by
ext Z g
constructor
· rintro ⟨W,i,p,⟨⟩,rfl⟩
exact ⟨i,rfl⟩
· rintro ⟨g,h⟩
exact ⟨Y,g,f,⟨⟩,h⟩
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a single arrow is effective epimorphic if and only if
the arrow is an effective epi.
-/
def isColimitOfEffectiveEpiStruct {X Y : C} (f : Y ⟶ X) (Hf : EffectiveEpiStruct f) :
IsColimit (Sieve.generateSingleton f : Presieve X).cocone :=
letI D := ObjectProperty.FullSubcategory fun T : Over X => Sieve.generateSingleton f T.hom
letI F : D ⥤ _ := (Sieve.generateSingleton f).arrows.diagram
{ desc := fun S => Hf.desc (S.ι.app ⟨Over.mk f, ⟨𝟙 _, by simp⟩⟩) <| by
intro Z g₁ g₂ h
let Y' : D := ⟨Over.mk f, 𝟙 _, by simp⟩
let Z' : D := ⟨Over.mk (g₁ ≫ f), g₁, rfl⟩
let g₁' : Z' ⟶ Y' := Over.homMk g₁
let g₂' : Z' ⟶ Y' := Over.homMk g₂ (by simp [Y', Z', h])
change F.map g₁' ≫ _ = F.map g₂' ≫ _
simp only [Y', F, S.w]
fac := by
rintro S ⟨T,g,hT⟩
dsimp
nth_rewrite 1 [← hT, Category.assoc, Hf.fac]
let y : D := ⟨Over.mk f, 𝟙 _, by simp⟩
let x : D := ⟨Over.mk T.hom, g, hT⟩
let g' : x ⟶ y := Over.homMk g
change F.map g' ≫ _ = _
rw [S.w]
rfl
uniq := by
intro S m hm
dsimp
generalize_proofs h1 h2
apply Hf.uniq _ h2
exact hm ⟨Over.mk f, 𝟙 _, by simp⟩ }
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a single arrow is effective epimorphic if and only if
the arrow is an effective epi.
-/
noncomputable
def effectiveEpiStructOfIsColimit {X Y : C} (f : Y ⟶ X)
(Hf : IsColimit (Sieve.generateSingleton f : Presieve X).cocone) :
EffectiveEpiStruct f :=
let aux {W : C} (e : Y ⟶ W)
(h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) :
Cocone (Sieve.generateSingleton f).arrows.diagram :=
{ pt := W
ι := {
app := fun ⟨_,hT⟩ => hT.choose ≫ e
naturality := by
rintro ⟨A,hA⟩ ⟨B,hB⟩ (q : A ⟶ B)
dsimp; simp only [← Category.assoc, Category.comp_id]
apply h
rw [Category.assoc, hB.choose_spec, hA.choose_spec, Over.w] } }
{ desc := fun {_} e h => Hf.desc (aux e h)
fac := by
intro W e h
dsimp
have := Hf.fac (aux e h) ⟨Over.mk f, 𝟙 _, by simp⟩
dsimp [aux] at this; rw [this]; clear this
nth_rewrite 2 [← Category.id_comp e]
apply h
generalize_proofs hh
rw [hh.choose_spec, Category.id_comp]
uniq := by
intro W e h m hm
dsimp
apply Hf.uniq (aux e h)
rintro ⟨A,g,hA⟩
dsimp
nth_rewrite 1 [← hA, Category.assoc, hm]
apply h
generalize_proofs hh
rwa [hh.choose_spec] }
theorem Sieve.effectiveEpimorphic_singleton {X Y : C} (f : Y ⟶ X) :
(Presieve.singleton f).EffectiveEpimorphic ↔ (EffectiveEpi f) := by
constructor
· intro (h : Nonempty _)
rw [Sieve.generateSingleton_eq] at h
constructor
apply Nonempty.map (effectiveEpiStructOfIsColimit _) h
· rintro ⟨h⟩
change Nonempty _
rw [Sieve.generateSingleton_eq]
apply Nonempty.map (isColimitOfEffectiveEpiStruct _) h
/--
The sieve of morphisms which factor through a morphism in a given family.
This is equal to `Sieve.generate (Presieve.ofArrows X π)`, but has
more convenient definitional properties.
-/
def Sieve.generateFamily {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) :
Sieve B where
arrows Y := { f | ∃ (a : α) (g : Y ⟶ X a), g ≫ π a = f }
downward_closed := by
rintro Y₁ Y₂ g₁ ⟨a,q,rfl⟩ e
exact ⟨a, e ≫ q, by simp⟩
lemma Sieve.generateFamily_eq {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) :
Sieve.generate (Presieve.ofArrows X π) = Sieve.generateFamily X π := by
ext Y g
constructor
· rintro ⟨W, g, f, ⟨a⟩, rfl⟩
exact ⟨a, g, rfl⟩
· rintro ⟨a, g, rfl⟩
exact ⟨_, g, π a, ⟨a⟩, rfl⟩
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a family of arrows is effective epimorphic if and only if
the family is an effective epi.
-/
def isColimitOfEffectiveEpiFamilyStruct {B : C} {α : Type*}
(X : α → C) (π : (a : α) → (X a ⟶ B)) (H : EffectiveEpiFamilyStruct X π) :
IsColimit (Sieve.generateFamily X π : Presieve B).cocone :=
letI D := ObjectProperty.FullSubcategory fun T : Over B => Sieve.generateFamily X π T.hom
letI F : D ⥤ _ := (Sieve.generateFamily X π).arrows.diagram
{ desc := fun S => H.desc (fun a => S.ι.app ⟨Over.mk (π a), ⟨a,𝟙 _, by simp⟩⟩) <| by
intro Z a₁ a₂ g₁ g₂ h
dsimp
let A₁ : D := ⟨Over.mk (π a₁), a₁, 𝟙 _, by simp⟩
let A₂ : D := ⟨Over.mk (π a₂), a₂, 𝟙 _, by simp⟩
let Z' : D := ⟨Over.mk (g₁ ≫ π a₁), a₁, g₁, rfl⟩
let i₁ : Z' ⟶ A₁ := Over.homMk g₁
let i₂ : Z' ⟶ A₂ := Over.homMk g₂
change F.map i₁ ≫ _ = F.map i₂ ≫ _
simp only [F, A₁, A₂, S.w]
fac := by
intro S ⟨T, a, (g : T.left ⟶ X a), hT⟩
dsimp
nth_rewrite 1 [← hT, Category.assoc, H.fac]
let A : D := ⟨Over.mk (π a), a, 𝟙 _, by simp⟩
let B : D := ⟨Over.mk T.hom, a, g, hT⟩
let i : B ⟶ A := Over.homMk g
change F.map i ≫ _ = _
rw [S.w]
rfl
uniq := by
intro S m hm; dsimp
apply H.uniq
intro a
exact hm ⟨Over.mk (π a), a, 𝟙 _, by simp⟩ }
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a family of arrows is effective epimorphic if and only if
the family is an effective epi.
-/
noncomputable
def effectiveEpiFamilyStructOfIsColimit {B : C} {α : Type*}
(X : α → C) (π : (a : α) → (X a ⟶ B))
(H : IsColimit (Sieve.generateFamily X π : Presieve B).cocone) :
EffectiveEpiFamilyStruct X π :=
let aux {W : C} (e : (a : α) → (X a ⟶ W))
(h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂),
g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) :
Cocone (Sieve.generateFamily X π).arrows.diagram := {
pt := W
ι := {
app := fun ⟨_,hT⟩ => hT.choose_spec.choose ≫ e hT.choose
naturality := by
intro ⟨A,a,(g₁ : A.left ⟶ _),ha⟩ ⟨B,b,(g₂ : B.left ⟶ _),hb⟩ (q : A ⟶ B)
dsimp; rw [Category.comp_id, ← Category.assoc]
apply h; rw [Category.assoc]
generalize_proofs h1 h2 h3 h4
rw [h2.choose_spec, h4.choose_spec, Over.w] } }
{ desc := fun {_} e h => H.desc (aux e h)
fac := by
intro W e h a
dsimp
have := H.fac (aux e h) ⟨Over.mk (π a), a, 𝟙 _, by simp⟩
dsimp [aux] at this; rw [this]; clear this
conv_rhs => rw [← Category.id_comp (e a)]
apply h
generalize_proofs h1 h2
rw [h2.choose_spec, Category.id_comp]
uniq := by
intro W e h m hm
apply H.uniq (aux e h)
rintro ⟨T, a, (g : T.left ⟶ _), ha⟩
dsimp
nth_rewrite 1 [← ha, Category.assoc, hm]
apply h
generalize_proofs h1 h2
rwa [h2.choose_spec] }
theorem Sieve.effectiveEpimorphic_family {B : C} {α : Type*}
(X : α → C) (π : (a : α) → (X a ⟶ B)) :
(Presieve.ofArrows X π).EffectiveEpimorphic ↔ EffectiveEpiFamily X π := by
constructor
· intro (h : Nonempty _)
rw [Sieve.generateFamily_eq] at h
constructor
apply Nonempty.map (effectiveEpiFamilyStructOfIsColimit _ _) h
· rintro ⟨h⟩
change Nonempty _
rw [Sieve.generateFamily_eq]
apply Nonempty.map (isColimitOfEffectiveEpiFamilyStruct _ _) h
end CategoryTheory
|
BitVec.lean
|
/-
Copyright (c) 2020 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Harun Khan, Alex Keizer
-/
import Mathlib.Algebra.Ring.InjSurj
import Mathlib.Algebra.Ring.Equiv
import Mathlib.Data.ZMod.Defs
import Mathlib.Data.Int.Cast.Lemmas
/-!
# Basic Theorems About Bitvectors
This file contains theorems about bitvectors which can only be stated in Mathlib or downstream
because they refer to other notions defined in Mathlib.
Please do not extend this file further: material about BitVec needed in downstream projects
can either be PR'd to Lean, or kept downstream if it also relies on Mathlib.
-/
namespace BitVec
variable {w : Nat}
-- TODO: move to the Lean4 repository.
open Fin.CommRing in
theorem ofFin_intCast (z : ℤ) : ofFin (z : Fin (2^w)) = ↑z := by
cases w
case zero =>
simp only [eq_nil]
case succ w =>
apply BitVec.eq_of_toInt_eq
rw [toInt_ofFin, Fin.val_intCast, Int.natCast_pow, Nat.cast_ofNat, Int.ofNat_toNat,
toInt_intCast]
rw [Int.max_eq_left]
· have h : (2 ^ (w + 1) : Int) = (2 ^ (w + 1) : Nat) := by simp
rw [h, Int.emod_bmod]
· omega
open Fin.CommRing in
@[simp] theorem toFin_intCast (z : ℤ) : (z : BitVec w).toFin = ↑z := by
rw [← ofFin_intCast]
/-!
## Injectivity
-/
theorem toNat_injective {n : Nat} : Function.Injective (BitVec.toNat : BitVec n → _)
| ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
theorem toFin_injective {n : Nat} : Function.Injective (toFin : BitVec n → _)
| ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
/-!
## Scalar Multiplication and Powers
-/
open Fin.NatCast
lemma toFin_nsmul (n : ℕ) (x : BitVec w) : toFin (n • x) = n • x.toFin :=
toFin_mul _ _ |>.trans <| by
open scoped Fin.CommRing in
simp only [natCast_eq_ofNat, toFin_ofNat, Fin.ofNat_eq_cast, nsmul_eq_mul]
lemma toFin_zsmul (z : ℤ) (x : BitVec w) : toFin (z • x) = z • x.toFin :=
toFin_mul _ _ |>.trans <| by
open scoped Fin.CommRing in
simp only [zsmul_eq_mul, toFin_intCast]
lemma toFin_pow (x : BitVec w) (n : ℕ) : toFin (x ^ n) = x.toFin ^ n := by
induction n with
| zero => simp
| succ n ih => simp [ih, BitVec.pow_succ, pow_succ]
/-!
## Ring
-/
-- Verify that the `HPow` instance from Lean agrees definitionally with the instance via `Monoid`.
example : @instHPow (Fin (2 ^ w)) ℕ Monoid.toNatPow = Lean.Grind.Fin.instHPowFinNatOfNeZero := rfl
instance : CommSemiring (BitVec w) :=
open Fin.CommRing in
toFin_injective.commSemiring _
toFin_zero
toFin_one
toFin_add
toFin_mul
toFin_nsmul
toFin_pow
toFin_natCast
-- The statement in the new API would be: `n#(k.succ) = ((n / 2)#k).concat (n % 2 != 0)`
instance : CommRing (BitVec w) :=
open Fin.CommRing in
toFin_injective.commRing _
toFin_zero toFin_one toFin_add toFin_mul toFin_neg toFin_sub
toFin_nsmul toFin_zsmul toFin_pow toFin_natCast toFin_intCast
/-- The ring `BitVec m` is isomorphic to `Fin (2 ^ m)`. -/
@[simps]
def equivFin {m : ℕ} : BitVec m ≃+* Fin (2 ^ m) where
toFun a := a.toFin
invFun a := ofFin a
map_mul' := toFin_mul
map_add' := toFin_add
end BitVec
|
Prod.lean
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Grading
import Mathlib.LinearAlgebra.TensorProduct.Graded.Internal
import Mathlib.LinearAlgebra.QuadraticForm.Prod
/-!
# Clifford algebras of a direct sum of two vector spaces
We show that the Clifford algebra of a direct sum is the graded tensor product of the Clifford
algebras, as `CliffordAlgebra.equivProd`.
## Main definitions:
* `CliffordAlgebra.equivProd : CliffordAlgebra (Q₁.prod Q₂) ≃ₐ[R] (evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂)`
## TODO
Introduce morphisms and equivalences of graded algebas, and upgrade `CliffordAlgebra.equivProd` to a
graded algebra equivalence.
-/
suppress_compilation
variable {R M₁ M₂ N : Type*}
variable [CommRing R] [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup N]
variable [Module R M₁] [Module R M₂] [Module R N]
variable (Q₁ : QuadraticForm R M₁) (Q₂ : QuadraticForm R M₂) (Qₙ : QuadraticForm R N)
open scoped TensorProduct
namespace CliffordAlgebra
section map_mul_map
variable {Q₁ Q₂ Qₙ}
variable (f₁ : Q₁ →qᵢ Qₙ) (f₂ : Q₂ →qᵢ Qₙ) (hf : ∀ x y, Qₙ.IsOrtho (f₁ x) (f₂ y))
variable (m₁ : CliffordAlgebra Q₁) (m₂ : CliffordAlgebra Q₂)
include hf
/-- If `m₁` and `m₂` are both homogeneous,
and the quadratic spaces `Q₁` and `Q₂` map into
orthogonal subspaces of `Qₙ` (for instance, when `Qₙ = Q₁.prod Q₂`),
then the product of the embedding in `CliffordAlgebra Q` commutes up to a sign factor. -/
nonrec theorem map_mul_map_of_isOrtho_of_mem_evenOdd
{i₁ i₂ : ZMod 2} (hm₁ : m₁ ∈ evenOdd Q₁ i₁) (hm₂ : m₂ ∈ evenOdd Q₂ i₂) :
map f₁ m₁ * map f₂ m₂ = (-1 : ℤˣ) ^ (i₂ * i₁) • (map f₂ m₂ * map f₁ m₁) := by
-- the strategy; for each variable, induct on powers of `ι`, then on the exponent of each
-- power.
induction hm₁ using Submodule.iSup_induction' with
| zero => rw [map_zero, zero_mul, mul_zero, smul_zero]
| add _ _ _ _ ihx ihy => rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem i₁' m₁' hm₁ =>
obtain ⟨i₁n, rfl⟩ := i₁'
dsimp only at *
induction hm₁ using Submodule.pow_induction_on_left' with
| algebraMap =>
rw [AlgHom.commutes, Nat.cast_zero, mul_zero, uzpow_zero, one_smul, Algebra.commutes]
| add _ _ _ _ _ ihx ihy =>
rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem_mul m₁ hm₁ i x₁ _hx₁ ih₁ =>
obtain ⟨v₁, rfl⟩ := hm₁
-- this is the first interesting goal
rw [map_mul, mul_assoc, ih₁, mul_smul_comm, map_apply_ι, Nat.cast_succ, mul_add_one,
uzpow_add, mul_smul, ← mul_assoc, ← mul_assoc, ← smul_mul_assoc ((-1) ^ i₂)]
clear ih₁
congr 2
induction hm₂ using Submodule.iSup_induction' with
| zero => rw [map_zero, zero_mul, mul_zero, smul_zero]
| add _ _ _ _ ihx ihy => rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem i₂' m₂' hm₂ =>
clear m₂
obtain ⟨i₂n, rfl⟩ := i₂'
dsimp only at *
induction hm₂ using Submodule.pow_induction_on_left' with
| algebraMap =>
rw [AlgHom.commutes, Nat.cast_zero, uzpow_zero, one_smul, Algebra.commutes]
| add _ _ _ _ _ ihx ihy =>
rw [map_add, add_mul, mul_add, ihx, ihy, smul_add]
| mem_mul m₂ hm₂ i x₂ _hx₂ ih₂ =>
obtain ⟨v₂, rfl⟩ := hm₂
-- this is the second interesting goal
rw [map_mul, map_apply_ι, Nat.cast_succ, ← mul_assoc,
ι_mul_ι_comm_of_isOrtho (hf _ _), neg_mul, mul_assoc, ih₂, mul_smul_comm,
← mul_assoc, ← Units.neg_smul, uzpow_add, uzpow_one, mul_neg_one]
theorem commute_map_mul_map_of_isOrtho_of_mem_evenOdd_zero_left
{i₂ : ZMod 2} (hm₁ : m₁ ∈ evenOdd Q₁ 0) (hm₂ : m₂ ∈ evenOdd Q₂ i₂) :
Commute (map f₁ m₁) (map f₂ m₂) :=
(map_mul_map_of_isOrtho_of_mem_evenOdd _ _ hf _ _ hm₁ hm₂).trans <| by simp
theorem commute_map_mul_map_of_isOrtho_of_mem_evenOdd_zero_right
{i₁ : ZMod 2} (hm₁ : m₁ ∈ evenOdd Q₁ i₁) (hm₂ : m₂ ∈ evenOdd Q₂ 0) :
Commute (map f₁ m₁) (map f₂ m₂) :=
(map_mul_map_of_isOrtho_of_mem_evenOdd _ _ hf _ _ hm₁ hm₂).trans <| by simp
theorem map_mul_map_eq_neg_of_isOrtho_of_mem_evenOdd_one
(hm₁ : m₁ ∈ evenOdd Q₁ 1) (hm₂ : m₂ ∈ evenOdd Q₂ 1) :
map f₁ m₁ * map f₂ m₂ = - map f₂ m₂ * map f₁ m₁ := by
simp [map_mul_map_of_isOrtho_of_mem_evenOdd _ _ hf _ _ hm₁ hm₂]
end map_mul_map
/-- The forward direction of `CliffordAlgebra.prodEquiv`. -/
def ofProd : CliffordAlgebra (Q₁.prod Q₂) →ₐ[R] (evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂) :=
lift _ ⟨
LinearMap.coprod
((GradedTensorProduct.includeLeft (evenOdd Q₁) (evenOdd Q₂)).toLinearMap
∘ₗ (evenOdd Q₁ 1).subtype ∘ₗ (ι Q₁).codRestrict _ (ι_mem_evenOdd_one Q₁))
((GradedTensorProduct.includeRight (evenOdd Q₁) (evenOdd Q₂)).toLinearMap
∘ₗ (evenOdd Q₂ 1).subtype ∘ₗ (ι Q₂).codRestrict _ (ι_mem_evenOdd_one Q₂)),
fun m => by
simp_rw [LinearMap.coprod_apply, LinearMap.coe_comp, Function.comp_apply,
AlgHom.toLinearMap_apply, QuadraticMap.prod_apply, Submodule.coe_subtype,
GradedTensorProduct.includeLeft_apply, GradedTensorProduct.includeRight_apply, map_add,
add_mul, mul_add, GradedTensorProduct.algebraMap_def,
GradedTensorProduct.tmul_one_mul_one_tmul, GradedTensorProduct.tmul_one_mul_coe_tmul,
GradedTensorProduct.tmul_coe_mul_one_tmul, GradedTensorProduct.tmul_coe_mul_coe_tmul,
LinearMap.codRestrict_apply, one_mul, uzpow_one, Units.neg_smul, one_smul, ι_sq_scalar,
mul_one, ← GradedTensorProduct.algebraMap_def, ← GradedTensorProduct.algebraMap_def']
abel⟩
@[simp]
lemma ofProd_ι_mk (m₁ : M₁) (m₂ : M₂) :
ofProd Q₁ Q₂ (ι _ (m₁, m₂)) = ι Q₁ m₁ ᵍ⊗ₜ 1 + 1 ᵍ⊗ₜ ι Q₂ m₂ := by
rw [ofProd, lift_ι_apply]
rfl
/-- The reverse direction of `CliffordAlgebra.prodEquiv`. -/
def toProd : evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂ →ₐ[R] CliffordAlgebra (Q₁.prod Q₂) :=
GradedTensorProduct.lift _ _
(CliffordAlgebra.map <| .inl _ _)
(CliffordAlgebra.map <| .inr _ _)
fun _i₁ _i₂ x₁ x₂ => map_mul_map_of_isOrtho_of_mem_evenOdd _ _ (QuadraticMap.IsOrtho.inl_inr) _
_ x₁.prop x₂.prop
@[simp]
lemma toProd_ι_tmul_one (m₁ : M₁) : toProd Q₁ Q₂ (ι _ m₁ ᵍ⊗ₜ 1) = ι _ (m₁, 0) := by
rw [toProd, GradedTensorProduct.lift_tmul, map_one, mul_one, map_apply_ι,
QuadraticMap.Isometry.inl_apply]
@[simp]
lemma toProd_one_tmul_ι (m₂ : M₂) : toProd Q₁ Q₂ (1 ᵍ⊗ₜ ι _ m₂) = ι _ (0, m₂) := by
rw [toProd, GradedTensorProduct.lift_tmul, map_one, one_mul, map_apply_ι,
QuadraticMap.Isometry.inr_apply]
lemma toProd_comp_ofProd : (toProd Q₁ Q₂).comp (ofProd Q₁ Q₂) = AlgHom.id _ _ := by
ext m <;> dsimp
· rw [ofProd_ι_mk, map_add, toProd_one_tmul_ι, toProd_ι_tmul_one, Prod.mk_zero_zero,
LinearMap.map_zero, add_zero]
· rw [ofProd_ι_mk, map_add, toProd_one_tmul_ι, toProd_ι_tmul_one, Prod.mk_zero_zero,
LinearMap.map_zero, zero_add]
lemma ofProd_comp_toProd : (ofProd Q₁ Q₂).comp (toProd Q₁ Q₂) = AlgHom.id _ _ := by
ext <;> simp
/-- The Clifford algebra over an orthogonal direct sum of quadratic vector spaces is isomorphic
as an algebra to the graded tensor product of the Clifford algebras of each space.
This is `CliffordAlgebra.toProd` and `CliffordAlgebra.ofProd` as an equivalence. -/
@[simps!]
def prodEquiv : CliffordAlgebra (Q₁.prod Q₂) ≃ₐ[R] (evenOdd Q₁ ᵍ⊗[R] evenOdd Q₂) :=
AlgEquiv.ofAlgHom (ofProd Q₁ Q₂) (toProd Q₁ Q₂) (ofProd_comp_toProd _ _) (toProd_comp_ofProd _ _)
end CliffordAlgebra
|
Sign.lean
|
/-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import Mathlib.Data.Sign.Defs
deprecated_module (since := "2025-05-11")
|
Opposites.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Thomas Read, Andrew Yang
-/
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.Yoneda
import Mathlib.CategoryTheory.Opposites
/-!
# Opposite adjunctions
This file contains constructions to relate adjunctions of functors to adjunctions of their
opposites.
## Tags
adjunction, opposite, uniqueness
-/
open CategoryTheory
universe v₁ v₂ u₁ u₂
-- morphism levels before object levels. See note [CategoryTheory universes].
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
namespace CategoryTheory.Adjunction
attribute [local simp] homEquiv_unit homEquiv_counit
/-- If `G` is adjoint to `F` then `F.unop` is adjoint to `G.unop`. -/
@[simps]
def unop {F : Cᵒᵖ ⥤ Dᵒᵖ} {G : Dᵒᵖ ⥤ Cᵒᵖ} (h : G ⊣ F) : F.unop ⊣ G.unop where
unit := NatTrans.unop h.counit
counit := NatTrans.unop h.unit
left_triangle_components _ := Quiver.Hom.op_inj (h.right_triangle_components _)
right_triangle_components _ := Quiver.Hom.op_inj (h.left_triangle_components _)
/-- If `G` is adjoint to `F` then `F.op` is adjoint to `G.op`. -/
@[simps]
def op {F : C ⥤ D} {G : D ⥤ C} (h : G ⊣ F) : F.op ⊣ G.op where
unit := NatTrans.op h.counit
counit := NatTrans.op h.unit
left_triangle_components _ := Quiver.Hom.unop_inj (by simp)
right_triangle_components _ := Quiver.Hom.unop_inj (by simp)
/-- If `F` is adjoint to `G.leftOp` then `G` is adjoint to `F.leftOp`. -/
@[simps]
def leftOp {F : C ⥤ Dᵒᵖ} {G : D ⥤ Cᵒᵖ} (a : F ⊣ G.leftOp) : G ⊣ F.leftOp where
unit := NatTrans.unop a.counit
counit := NatTrans.op a.unit
left_triangle_components X := congr($(a.right_triangle_components (.op X)).op)
right_triangle_components X := congr($(a.left_triangle_components X.unop).unop)
/-- If `F.rightOp` is adjoint to `G` then `G.rightOp` is adjoint to `F`. -/
@[simps]
def rightOp {F : Cᵒᵖ ⥤ D} {G : Dᵒᵖ ⥤ C} (a : F.rightOp ⊣ G) : G.rightOp ⊣ F where
unit := NatTrans.unop a.counit
counit := NatTrans.op a.unit
left_triangle_components X := congr($(a.right_triangle_components (.op X)).op)
right_triangle_components X := congr($(a.left_triangle_components X.unop).unop)
lemma leftOp_eq {F : C ⥤ Dᵒᵖ} {G : D ⥤ Cᵒᵖ} (a : F ⊣ G.leftOp) :
a.leftOp = (opOpEquivalence D).symm.toAdjunction.comp a.op := by
ext X; simp [Equivalence.unit]
lemma rightOp_eq {F : Cᵒᵖ ⥤ D} {G : Dᵒᵖ ⥤ C} (a : F.rightOp ⊣ G) :
a.rightOp = (opOpEquivalence D).symm.toAdjunction.comp a.op := by
ext X; simp [Equivalence.unit]
/-- If `F` and `F'` are both adjoint to `G`, there is a natural isomorphism
`F.op ⋙ coyoneda ≅ F'.op ⋙ coyoneda`.
We use this in combination with `fullyFaithfulCancelRight` to show left adjoints are unique.
-/
def leftAdjointsCoyonedaEquiv {F F' : C ⥤ D} {G : D ⥤ C} (adj1 : F ⊣ G) (adj2 : F' ⊣ G) :
F.op ⋙ coyoneda ≅ F'.op ⋙ coyoneda :=
NatIso.ofComponents fun X =>
NatIso.ofComponents fun Y =>
((adj1.homEquiv X.unop Y).trans (adj2.homEquiv X.unop Y).symm).toIso
/-- Given two adjunctions, if the right adjoints are naturally isomorphic, then so are the left
adjoints.
Note: it is generally better to use `Adjunction.natIsoEquiv`, see the file `Adjunction.Unique`.
The reason this definition still exists is that apparently `CategoryTheory.extendAlongYonedaYoneda`
uses its definitional properties (TODO: figure out a way to avoid this).
-/
def natIsoOfRightAdjointNatIso {F F' : C ⥤ D} {G G' : D ⥤ C}
(adj1 : F ⊣ G) (adj2 : F' ⊣ G') (r : G ≅ G') : F ≅ F' :=
NatIso.removeOp ((Coyoneda.fullyFaithful.whiskeringRight _).isoEquiv.symm
(leftAdjointsCoyonedaEquiv adj2 (adj1.ofNatIsoRight r)))
/-- Given two adjunctions, if the left adjoints are naturally isomorphic, then so are the right
adjoints.
Note: it is generally better to use `Adjunction.natIsoEquiv`, see the file `Adjunction.Unique`.
-/
def natIsoOfLeftAdjointNatIso {F F' : C ⥤ D} {G G' : D ⥤ C}
(adj1 : F ⊣ G) (adj2 : F' ⊣ G') (l : F ≅ F') : G ≅ G' :=
NatIso.removeOp (natIsoOfRightAdjointNatIso (op adj2) (op adj1) (NatIso.op l))
end Adjunction
namespace Functor
instance IsLeftAdjoint.op {F : C ⥤ D} [F.IsLeftAdjoint] : F.op.IsRightAdjoint :=
⟨F.rightAdjoint.op, ⟨.op <| .ofIsLeftAdjoint _⟩⟩
instance IsRightAdjoint.op {F : C ⥤ D} [F.IsRightAdjoint] : F.op.IsLeftAdjoint :=
⟨F.leftAdjoint.op, ⟨.op <| .ofIsRightAdjoint _⟩⟩
instance IsLeftAdjoint.leftOp {F : C ⥤ Dᵒᵖ} [F.IsLeftAdjoint] : F.leftOp.IsRightAdjoint :=
⟨F.rightAdjoint.rightOp, ⟨.leftOp <| .ofIsLeftAdjoint _⟩⟩
-- TODO: Do we need to introduce `Adjunction.leftUnop`?
instance IsRightAdjoint.leftOp {F : C ⥤ Dᵒᵖ} [F.IsRightAdjoint] : F.leftOp.IsLeftAdjoint :=
inferInstanceAs (F.op ⋙ (opOpEquivalence D).functor).IsLeftAdjoint
-- TODO: Do we need to introduce `Adjunction.rightUnop`?
instance IsLeftAdjoint.rightOp {F : Cᵒᵖ ⥤ D} [F.IsLeftAdjoint] : F.rightOp.IsRightAdjoint :=
inferInstanceAs ((opOpEquivalence C).inverse ⋙ F.op).IsRightAdjoint
instance IsRightAdjoint.rightOp {F : Cᵒᵖ ⥤ D} [F.IsRightAdjoint] : F.rightOp.IsLeftAdjoint :=
⟨F.leftAdjoint.leftOp, ⟨.rightOp <| .ofIsRightAdjoint _⟩⟩
end Functor
end CategoryTheory
|
Range.lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Data.Finset.Insert
import Mathlib.Data.Multiset.Range
import Mathlib.Order.Interval.Set.Defs
/-!
# Finite sets made of a range of elements.
## Main declarations
### Finset constructions
* `Finset.range`: For any `n : ℕ`, `range n` is equal to `{0, 1, ... , n - 1} ⊆ ℕ`.
This convention is consistent with other languages and normalizes `card (range n) = n`.
Beware, `n` is not in `range n`.
## Tags
finite sets, finset
-/
-- Assert that we define `Finset` without the material on `List.sublists`.
-- Note that we cannot use `List.sublists` itself as that is defined very early.
assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice OrderedCommMonoid
open Multiset Subtype Function
universe u
variable {α : Type*} {β : Type*} {γ : Type*}
namespace Finset
/-! ### range -/
section Range
open Nat
variable {n m l : ℕ}
/-- `range n` is the set of natural numbers less than `n`. -/
def range (n : ℕ) : Finset ℕ :=
⟨_, nodup_range n⟩
@[simp]
theorem range_val (n : ℕ) : (range n).1 = Multiset.range n :=
rfl
@[simp, grind =]
theorem mem_range : m ∈ range n ↔ m < n :=
Multiset.mem_range
@[simp, norm_cast]
theorem coe_range (n : ℕ) : (range n : Set ℕ) = Set.Iio n :=
Set.ext fun _ => mem_range
@[simp]
theorem range_zero : range 0 = ∅ :=
rfl
@[simp]
theorem range_one : range 1 = {0} :=
rfl
theorem range_succ : range (succ n) = insert n (range n) :=
eq_of_veq <| (Multiset.range_succ n).trans <| (ndinsert_of_notMem notMem_range_self).symm
theorem range_add_one : range (n + 1) = insert n (range n) :=
range_succ
theorem notMem_range_self : n ∉ range n :=
Multiset.notMem_range_self
@[deprecated (since := "2025-05-23")] alias not_mem_range_self := notMem_range_self
theorem self_mem_range_succ (n : ℕ) : n ∈ range (n + 1) :=
Multiset.self_mem_range_succ n
@[simp]
theorem range_subset {n m} : range n ⊆ range m ↔ n ≤ m :=
Multiset.range_subset
theorem range_mono : Monotone range := fun _ _ => range_subset.2
@[gcongr] alias ⟨_, _root_.GCongr.finset_range_subset_of_le⟩ := range_subset
theorem mem_range_succ_iff {a b : ℕ} : a ∈ Finset.range b.succ ↔ a ≤ b :=
Finset.mem_range.trans Nat.lt_succ_iff
theorem mem_range_le {n x : ℕ} (hx : x ∈ range n) : x ≤ n :=
(mem_range.1 hx).le
theorem mem_range_sub_ne_zero {n x : ℕ} (hx : x ∈ range n) : n - x ≠ 0 :=
_root_.ne_of_gt <| Nat.sub_pos_of_lt <| mem_range.1 hx
@[simp]
theorem nonempty_range_iff : (range n).Nonempty ↔ n ≠ 0 :=
⟨fun ⟨k, hk⟩ => (k.zero_le.trans_lt <| mem_range.1 hk).ne',
fun h => ⟨0, mem_range.2 <| Nat.pos_iff_ne_zero.2 h⟩⟩
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Aesop.range_nonempty⟩ := nonempty_range_iff
@[simp]
theorem range_eq_empty_iff : range n = ∅ ↔ n = 0 := by
rw [← not_nonempty_iff_eq_empty, nonempty_range_iff, not_not]
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_range_succ : (range <| n + 1).Nonempty :=
nonempty_range_iff.2 n.succ_ne_zero
lemma range_nontrivial {n : ℕ} (hn : 1 < n) : (Finset.range n).Nontrivial := by
rw [Finset.Nontrivial, Finset.coe_range]
exact ⟨0, Nat.zero_lt_one.trans hn, 1, hn, Nat.zero_ne_one⟩
theorem exists_nat_subset_range (s : Finset ℕ) : ∃ n : ℕ, s ⊆ range n :=
s.induction_on (by simp)
fun a _ _ ⟨n, hn⟩ => ⟨max (a + 1) n, insert_subset (by simp) (hn.trans (by simp))⟩
end Range
end Finset
/-- Equivalence between the set of natural numbers which are `≥ k` and `ℕ`, given by `n → n - k`. -/
def notMemRangeEquiv (k : ℕ) : { n // n ∉ range k } ≃ ℕ where
toFun i := i.1 - k
invFun j := ⟨j + k, by simp⟩
left_inv j := by
rw [Subtype.ext_iff_val]
apply Nat.sub_add_cancel
simpa using j.2
right_inv _ := Nat.add_sub_cancel_right _ _
@[simp]
theorem coe_notMemRangeEquiv (k : ℕ) :
(notMemRangeEquiv k : { n // n ∉ range k } → ℕ) = fun (i : { n // n ∉ range k }) => i - k :=
rfl
@[simp]
theorem coe_notMemRangeEquiv_symm (k : ℕ) :
((notMemRangeEquiv k).symm : ℕ → { n // n ∉ range k }) = fun j => ⟨j + k, by simp⟩ :=
rfl
|
SuccOrder.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.Order.LatticeIntervals
import Mathlib.Order.SuccPred.Basic
/-!
# Successors in intervals
If `j` is an element of a partially ordered set equipped
with a successor function, then for any element `i : Set.Iic j`
which is not the maximum, we have `↑(Order.succ i) = Order.succ ↑i`.
-/
namespace Set
variable {J : Type*} [PartialOrder J]
lemma Iic.coe_succ_of_not_isMax
[SuccOrder J] {j : J} {i : Set.Iic j} (hi : ¬ IsMax i) :
(Order.succ i).1 = Order.succ i.1 := by
rw [coe_succ_of_mem]
apply Order.succ_le_of_lt
exact lt_of_le_of_ne (α := Set.Iic j) le_top (by simpa using hi)
lemma Iic.succ_eq_of_not_isMax
[SuccOrder J] {j : J} {i : Set.Iic j} (hi : ¬ IsMax i) :
Order.succ i = ⟨Order.succ i.1, by
rw [← coe_succ_of_not_isMax hi]
apply Subtype.coe_prop⟩ := by
ext
simp only [coe_succ_of_not_isMax hi]
lemma Ici.coe_pred_of_not_isMin
[PredOrder J] {j : J} {i : Set.Ici j} (hi : ¬ IsMin i) :
(Order.pred i).1 = Order.pred i.1 := by
rw [coe_pred_of_mem]
apply Order.le_pred_of_lt
exact lt_of_le_of_ne (α := Set.Ici j) bot_le (Ne.symm (by simpa using hi))
lemma Ici.pred_eq_of_not_isMin
[PredOrder J] {j : J} {i : Set.Ici j} (hi : ¬ IsMin i) :
Order.pred i = ⟨Order.pred i.1, by
rw [← coe_pred_of_not_isMin hi]
apply Subtype.coe_prop⟩ := by
ext
simp only [coe_pred_of_not_isMin hi]
end Set
|
polydiv.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 choice.
From mathcomp Require Import fintype bigop ssralg poly.
(******************************************************************************)
(* This file provides a library for the basic theory of Euclidean and pseudo- *)
(* Euclidean division for polynomials over non trivial ring structures. *)
(* The library defines two versions of the pseudo-euclidean division: one for *)
(* coefficients in a (not necessarily commutative) non-trivial ring structure *)
(* and one for coefficients equipped with a structure of integral domain. *)
(* From the latter we derive the definition of the usual Euclidean division *)
(* for coefficients in a field. Only the definition of the pseudo-division *)
(* for coefficients in an integral domain is exported by default and benefits *)
(* from notations. *)
(* Also, the only theory exported by default is the one of division for *)
(* polynomials with coefficients in a field. *)
(* Other definitions and facts are qualified using name spaces indicating the *)
(* hypotheses made on the structure of coefficients and the properties of the *)
(* polynomial one divides with. *)
(* *)
(* Pdiv.Field (exported by the present library): *)
(* edivp p q == pseudo-division of p by q with p q : {poly R} where *)
(* R is an idomainType. *)
(* Computes (k, quo, rem) : nat * {poly r} * {poly R}, *)
(* such that size rem < size q and: *)
(* + if lead_coef q is not a unit, then: *)
(* (lead_coef q ^+ k) *: p = q * quo + rem *)
(* + else if lead_coef q is a unit, then: *)
(* p = q * quo + rem and k = 0 *)
(* p %/ q == quotient (second component) computed by (edivp p q). *)
(* p %% q == remainder (third component) computed by (edivp p q). *)
(* scalp p q == exponent (first component) computed by (edivp p q). *)
(* p %| q == tests the nullity of the remainder of the *)
(* pseudo-division of p by q. *)
(* rgcdp p q == Pseudo-greater common divisor obtained by performing *)
(* the Euclidean algorithm on p and q using redivp as *)
(* Euclidean division. *)
(* p %= q == p and q are associate polynomials, i.e., p %| q and *)
(* q %| p, or equivalently, p = c *: q for some nonzero *)
(* constant c. *)
(* gcdp p q == Pseudo-greater common divisor obtained by performing *)
(* the Euclidean algorithm on p and q using edivp as *)
(* Euclidean division. *)
(* egcdp p q == The pair of Bezout coefficients: if e := egcdp p q, *)
(* then size e.1 <= size q, size e.2 <= size p, and *)
(* gcdp p q %= e.1 * p + e.2 * q *)
(* coprimep p q == p and q are coprime, i.e., (gcdp p q) is a nonzero *)
(* constant. *)
(* gdcop q p == greatest divisor of p which is coprime to q. *)
(* irreducible_poly p <-> p has only trivial (constant) divisors. *)
(* mup x q == multplicity of x as a root of q *)
(* *)
(* Pdiv.Idomain: theory available for edivp and the related operation under *)
(* the sole assumption that the ring of coefficients is canonically an *)
(* integral domain (R : idomainType). *)
(* *)
(* Pdiv.IdomainMonic: theory available for edivp and the related operations *)
(* under the assumption that the ring of coefficients is canonically *)
(* and integral domain (R : idomainType) an the divisor is monic. *)
(* *)
(* Pdiv.IdomainUnit: theory available for edivp and the related operations *)
(* under the assumption that the ring of coefficients is canonically an *)
(* integral domain (R : idomainType) and the leading coefficient of the *)
(* divisor is a unit. *)
(* *)
(* Pdiv.ClosedField: theory available for edivp and the related operation *)
(* under the sole assumption that the ring of coefficients is canonically *)
(* an algebraically closed field (R : closedField). *)
(* *)
(* Pdiv.Ring : *)
(* redivp p q == pseudo-division of p by q with p q : {poly R} where R is *)
(* a nzRingType. *)
(* Computes (k, quo, rem) : nat * {poly r} * {poly R}, *)
(* such that if rem = 0 then quo * q = p * (lead_coef q ^+ k) *)
(* *)
(* rdivp p q == quotient (second component) computed by (redivp p q). *)
(* rmodp p q == remainder (third component) computed by (redivp p q). *)
(* rscalp p q == exponent (first component) computed by (redivp p q). *)
(* rdvdp p q == tests the nullity of the remainder of the pseudo-division *)
(* of p by q. *)
(* rgcdp p q == analogue of gcdp for coefficients in a nzRingType. *)
(* rgdcop p q == analogue of gdcop for coefficients in a nzRingType. *)
(*rcoprimep p q == analogue of coprimep p q for coefficients in a nzRingType. *)
(* *)
(* Pdiv.RingComRreg : theory of the operations defined in Pdiv.Ring, when the *)
(* ring of coefficients is canonically commutative (R : comNzRingType) and *)
(* the leading coefficient of the divisor is both right regular and *)
(* commutes as a constant polynomial with the divisor itself *)
(* *)
(* Pdiv.RingMonic : theory of the operations defined in Pdiv.Ring, under the *)
(* assumption that the divisor is monic. *)
(* *)
(* Pdiv.UnitRing: theory of the operations defined in Pdiv.Ring, when the *)
(* ring R of coefficients is canonically with units (R : unitRingType). *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory.
Local Open Scope ring_scope.
Reserved Notation "p %= q" (at level 70, no associativity).
Local Notation simp := Monoid.simpm.
Module Pdiv.
Module CommonRing.
Section RingPseudoDivision.
Variable R : nzRingType.
Implicit Types d p q r : {poly R}.
(* Pseudo division, defined on an arbitrary ring *)
Definition redivp_rec (q : {poly R}) :=
let sq := size q in
let cq := lead_coef q in
fix loop (k : nat) (qq r : {poly R})(n : nat) {struct n} :=
if size r < sq then (k, qq, r) else
let m := (lead_coef r) *: 'X^(size r - sq) in
let qq1 := qq * cq%:P + m in
let r1 := r * cq%:P - m * q in
if n is n1.+1 then loop k.+1 qq1 r1 n1 else (k.+1, qq1, r1).
Definition redivp_expanded_def p q :=
if q == 0 then (0, 0, p) else redivp_rec q 0 0 p (size p).
Fact redivp_key : unit. Proof. by []. Qed.
Definition redivp : {poly R} -> {poly R} -> nat * {poly R} * {poly R} :=
locked_with redivp_key redivp_expanded_def.
Canonical redivp_unlockable := [unlockable fun redivp].
Definition rdivp p q := ((redivp p q).1).2.
Definition rmodp p q := (redivp p q).2.
Definition rscalp p q := ((redivp p q).1).1.
Definition rdvdp p q := rmodp q p == 0.
(*Definition rmultp := [rel m d | rdvdp d m].*)
Lemma redivp_def p q : redivp p q = (rscalp p q, rdivp p q, rmodp p q).
Proof. by rewrite /rscalp /rdivp /rmodp; case: (redivp p q) => [[]] /=. Qed.
Lemma rdiv0p p : rdivp 0 p = 0.
Proof.
rewrite /rdivp unlock; case: ifP => // Hp; rewrite /redivp_rec !size_poly0.
by rewrite polySpred ?Hp.
Qed.
Lemma rdivp0 p : rdivp p 0 = 0. Proof. by rewrite /rdivp unlock eqxx. Qed.
Lemma rdivp_small p q : size p < size q -> rdivp p q = 0.
Proof.
rewrite /rdivp unlock; have [-> | _ ltpq] := eqP; first by rewrite size_poly0.
by case: (size p) => [|s]; rewrite /= ltpq.
Qed.
Lemma leq_rdivp p q : size (rdivp p q) <= size p.
Proof.
have [/rdivp_small->|] := ltnP (size p) (size q); first by rewrite size_poly0.
rewrite /rdivp /rmodp /rscalp unlock.
have [->|q0] //= := eqVneq q 0.
have: size (0 : {poly R}) <= size p by rewrite size_poly0.
move: {2 3 4 6}(size p) (leqnn (size p)) => A.
elim: (size p) 0%N (0 : {poly R}) {1 3 4}p (leqnn (size p)) => [|n ihn] k q1 r.
by move/size_poly_leq0P->; rewrite /= size_poly0 size_poly_gt0 q0.
move=> /= hrn hr hq1 hq; case: ltnP => //= hqr.
have sq: 0 < size q by rewrite size_poly_gt0.
have sr: 0 < size r by apply: leq_trans sq hqr.
apply: ihn => //.
- apply/leq_sizeP => j hnj.
rewrite coefB -scalerAl coefZ coefXnM ltn_subRL ltnNge.
have hj : (size r).-1 <= j by apply: leq_trans hnj; rewrite -ltnS prednK.
rewrite [leqLHS]polySpred -?size_poly_gt0 // coefMC.
rewrite (leq_ltn_trans hj) /=; last by rewrite -add1n leq_add2r.
move: hj; rewrite leq_eqVlt prednK // => /predU1P [<- | hj].
by rewrite -subn1 subnAC subKn // !subn1 !lead_coefE subrr.
have/leq_sizeP-> //: size q <= j - (size r - size q).
by rewrite subnBA // leq_psubRL // leq_add2r.
by move/leq_sizeP: (hj) => -> //; rewrite mul0r mulr0 subr0.
- apply: leq_trans (size_polyD _ _) _; rewrite geq_max; apply/andP; split.
apply: leq_trans (size_polyMleq _ _) _.
by rewrite size_polyC lead_coef_eq0 q0 /= addn1.
rewrite size_polyN; apply: leq_trans (size_polyMleq _ _) _.
apply: leq_trans hr; rewrite -subn1 leq_subLR -[in (1 + _)%N](subnK hqr).
by rewrite addnA leq_add2r add1n -(@size_polyXn R) size_scale_leq.
apply: leq_trans (size_polyD _ _) _; rewrite geq_max; apply/andP; split.
apply: leq_trans (size_polyMleq _ _) _.
by rewrite size_polyC lead_coef_eq0 q0 /= addnS addn0.
apply: leq_trans (size_scale_leq _ _) _.
by rewrite size_polyXn -subSn // leq_subLR -add1n leq_add.
Qed.
Lemma rmod0p p : rmodp 0 p = 0.
Proof.
rewrite /rmodp unlock; case: ifP => // Hp; rewrite /redivp_rec !size_poly0.
by rewrite polySpred ?Hp.
Qed.
Lemma rmodp0 p : rmodp p 0 = p. Proof. by rewrite /rmodp unlock eqxx. Qed.
Lemma rscalp_small p q : size p < size q -> rscalp p q = 0.
Proof.
rewrite /rscalp unlock; case: eqP => _ // spq.
by case sp: (size p) => [| s] /=; rewrite spq.
Qed.
Lemma ltn_rmodp p q : (size (rmodp p q) < size q) = (q != 0).
Proof.
rewrite /rdivp /rmodp /rscalp unlock; have [->|q0] := eqVneq q 0.
by rewrite /= size_poly0 ltn0.
elim: (size p) 0%N 0 {1 3}p (leqnn (size p)) => [|n ihn] k q1 r.
move/size_poly_leq0P->.
by rewrite /= size_poly0 size_poly_gt0 q0 size_poly0 size_poly_gt0.
move=> hr /=; case: (ltnP (size r)) => // hsrq; apply/ihn/leq_sizeP => j hnj.
rewrite coefB -scalerAl !coefZ coefXnM coefMC ltn_subRL ltnNge.
have sq: 0 < size q by rewrite size_poly_gt0.
have sr: 0 < size r by apply: leq_trans hsrq.
have hj: (size r).-1 <= j by apply: leq_trans hnj; rewrite -ltnS prednK.
move: (leq_add sq hj); rewrite add1n prednK // => -> /=.
move: hj; rewrite leq_eqVlt prednK // => /predU1P [<- | hj].
by rewrite -predn_sub subKn // !lead_coefE subrr.
have/leq_sizeP -> //: size q <= j - (size r - size q).
by rewrite subnBA // leq_subRL ?leq_add2r // (leq_trans hj) // leq_addr.
by move/leq_sizeP: hj => -> //; rewrite mul0r mulr0 subr0.
Qed.
Lemma ltn_rmodpN0 p q : q != 0 -> size (rmodp p q) < size q.
Proof. by rewrite ltn_rmodp. Qed.
Lemma rmodp1 p : rmodp p 1 = 0.
Proof.
apply/eqP; have := ltn_rmodp p 1.
by rewrite !oner_neq0 -size_poly_eq0 size_poly1 ltnS leqn0.
Qed.
Lemma rmodp_small p q : size p < size q -> rmodp p q = p.
Proof.
rewrite /rmodp unlock; have [->|_] := eqP; first by rewrite size_poly0.
by case sp: (size p) => [| s] Hs /=; rewrite sp Hs /=.
Qed.
Lemma leq_rmodp m d : size (rmodp m d) <= size m.
Proof.
have [/rmodp_small -> //|h] := ltnP (size m) (size d).
have [->|d0] := eqVneq d 0; first by rewrite rmodp0.
by apply: leq_trans h; apply: ltnW; rewrite ltn_rmodp.
Qed.
Lemma rmodpC p c : c != 0 -> rmodp p c%:P = 0.
Proof.
move=> Hc; apply/eqP; rewrite -size_poly_leq0 -ltnS.
have -> : 1%N = nat_of_bool (c != 0) by rewrite Hc.
by rewrite -size_polyC ltn_rmodp polyC_eq0.
Qed.
Lemma rdvdp0 d : rdvdp d 0. Proof. by rewrite /rdvdp rmod0p. Qed.
Lemma rdvd0p n : rdvdp 0 n = (n == 0). Proof. by rewrite /rdvdp rmodp0. Qed.
Lemma rdvd0pP n : reflect (n = 0) (rdvdp 0 n).
Proof. by apply: (iffP idP); rewrite rdvd0p; move/eqP. Qed.
Lemma rdvdpN0 p q : rdvdp p q -> q != 0 -> p != 0.
Proof. by move=> pq hq; apply: contraTneq pq => ->; rewrite rdvd0p. Qed.
Lemma rdvdp1 d : rdvdp d 1 = (size d == 1).
Proof.
rewrite /rdvdp; have [->|] := eqVneq d 0.
by rewrite rmodp0 size_poly0 (negPf (oner_neq0 _)).
rewrite -size_poly_leq0 -ltnS; case: ltngtP => // [|/eqP] hd _.
by rewrite rmodp_small ?size_poly1 // oner_eq0.
have [c cn0 ->] := size_poly1P _ hd.
rewrite /rmodp unlock -size_poly_eq0 size_poly1 /= size_poly1 size_polyC cn0 /=.
by rewrite polyC_eq0 (negPf cn0) !lead_coefC !scale1r subrr !size_poly0.
Qed.
Lemma rdvd1p m : rdvdp 1 m. Proof. by rewrite /rdvdp rmodp1. Qed.
Lemma Nrdvdp_small (n d : {poly R}) :
n != 0 -> size n < size d -> rdvdp d n = false.
Proof. by move=> nn0 hs; rewrite /rdvdp (rmodp_small hs); apply: negPf. Qed.
Lemma rmodp_eq0P p q : reflect (rmodp p q = 0) (rdvdp q p).
Proof. exact: (iffP eqP). Qed.
Lemma rmodp_eq0 p q : rdvdp q p -> rmodp p q = 0. Proof. exact: rmodp_eq0P. Qed.
Lemma rdvdp_leq p q : rdvdp p q -> q != 0 -> size p <= size q.
Proof. by move=> dvd_pq; rewrite leqNgt; apply: contra => /rmodp_small <-. Qed.
Definition rgcdp p q :=
let: (p1, q1) := if size p < size q then (q, p) else (p, q) in
if p1 == 0 then q1 else
let fix loop (n : nat) (pp qq : {poly R}) {struct n} :=
let rr := rmodp pp qq in
if rr == 0 then qq else
if n is n1.+1 then loop n1 qq rr else rr in
loop (size p1) p1 q1.
Lemma rgcd0p : left_id 0 rgcdp.
Proof.
move=> p; rewrite /rgcdp size_poly0 size_poly_gt0 if_neg.
case: ifP => /= [_ | nzp]; first by rewrite eqxx.
by rewrite polySpred !(rmodp0, nzp) //; case: _.-1 => [|m]; rewrite rmod0p eqxx.
Qed.
Lemma rgcdp0 : right_id 0 rgcdp.
Proof.
move=> p; have:= rgcd0p p; rewrite /rgcdp size_poly0 size_poly_gt0.
by case: eqVneq => p0; rewrite ?(eqxx, p0) //= eqxx.
Qed.
Lemma rgcdpE p q :
rgcdp p q = if size p < size q
then rgcdp (rmodp q p) p else rgcdp (rmodp p q) q.
Proof.
pose rgcdp_rec := fix rgcdp_rec (n : nat) (pp qq : {poly R}) {struct n} :=
let rr := rmodp pp qq in
if rr == 0 then qq else
if n is n1.+1 then rgcdp_rec n1 qq rr else rr.
have Irec: forall m n p q, size q <= m -> size q <= n
-> size q < size p -> rgcdp_rec m p q = rgcdp_rec n p q.
+ elim=> [|m Hrec] [|n] //= p1 q1.
- move/size_poly_leq0P=> -> _; rewrite size_poly0 size_poly_gt0 rmodp0.
by move/negPf->; case: n => [|n] /=; rewrite rmod0p eqxx.
- move=> _ /size_poly_leq0P ->; rewrite size_poly0 size_poly_gt0 rmodp0.
by move/negPf->; case: m {Hrec} => [|m] /=; rewrite rmod0p eqxx.
case: eqVneq => Epq Sm Sn Sq //; have [->|nzq] := eqVneq q1 0.
by case: n m {Sm Sn Hrec} => [|m] [|n] //=; rewrite rmod0p eqxx.
apply: Hrec; last by rewrite ltn_rmodp.
by rewrite -ltnS (leq_trans _ Sm) // ltn_rmodp.
by rewrite -ltnS (leq_trans _ Sn) // ltn_rmodp.
have [->|nzp] := eqVneq p 0.
by rewrite rmod0p rmodp0 rgcd0p rgcdp0 if_same.
have [->|nzq] := eqVneq q 0.
by rewrite rmod0p rmodp0 rgcd0p rgcdp0 if_same.
rewrite /rgcdp -/rgcdp_rec !ltn_rmodp (negPf nzp) (negPf nzq) /=.
have [ltpq|leqp] := ltnP; rewrite !(negPf nzp, negPf nzq) //= polySpred //=.
have [->|nzqp] := eqVneq.
by case: (size p) => [|[|s]]; rewrite /= rmodp0 (negPf nzp) // rmod0p eqxx.
apply: Irec => //; last by rewrite ltn_rmodp.
by rewrite -ltnS -polySpred // (leq_trans _ ltpq) ?leqW // ltn_rmodp.
by rewrite ltnW // ltn_rmodp.
have [->|nzpq] := eqVneq.
by case: (size q) => [|[|s]]; rewrite /= rmodp0 (negPf nzq) // rmod0p eqxx.
apply: Irec => //; last by rewrite ltn_rmodp.
by rewrite -ltnS -polySpred // (leq_trans _ leqp) // ltn_rmodp.
by rewrite ltnW // ltn_rmodp.
Qed.
Variant comm_redivp_spec m d : nat * {poly R} * {poly R} -> Type :=
ComEdivnSpec k (q r : {poly R}) of
(GRing.comm d (lead_coef d)%:P -> m * (lead_coef d ^+ k)%:P = q * d + r) &
(d != 0 -> size r < size d) : comm_redivp_spec m d (k, q, r).
Lemma comm_redivpP m d : comm_redivp_spec m d (redivp m d).
Proof.
rewrite unlock; have [->|Hd] := eqVneq d 0.
by constructor; rewrite !(simp, eqxx).
have: GRing.comm d (lead_coef d)%:P -> m * (lead_coef d ^+ 0)%:P = 0 * d + m.
by rewrite !simp.
elim: (size m) 0%N 0 {1 4 6}m (leqnn (size m)) => [|n IHn] k q r Hr /=.
move/size_poly_leq0P: Hr ->.
suff hsd: size (0: {poly R}) < size d by rewrite hsd => /= ?; constructor.
by rewrite size_poly0 size_poly_gt0.
case: ltnP => Hlt Heq; first by constructor.
apply/IHn=> [|Cda]; last first.
rewrite mulrDl addrAC -addrA subrK exprSr polyCM mulrA Heq //.
by rewrite mulrDl -mulrA Cda mulrA.
apply/leq_sizeP => j Hj; rewrite coefB coefMC -scalerAl coefZ coefXnM.
rewrite ltn_subRL ltnNge (leq_trans Hr) /=; last first.
by apply: leq_ltn_trans Hj _; rewrite -add1n leq_add2r size_poly_gt0.
move: Hj; rewrite leq_eqVlt; case/predU1P => [<-{j} | Hj]; last first.
rewrite !nth_default ?simp ?oppr0 ?(leq_trans Hr) //.
by rewrite -{1}(subKn Hlt) leq_sub2r // (leq_trans Hr).
move: Hr; rewrite leq_eqVlt ltnS; case/predU1P=> Hqq; last first.
by rewrite !nth_default ?simp ?oppr0 // -{1}(subKn Hlt) leq_sub2r.
rewrite /lead_coef Hqq polySpred // subSS subKn ?addrN //.
by rewrite -subn1 leq_subLR add1n -Hqq.
Qed.
Lemma rmodpp p : GRing.comm p (lead_coef p)%:P -> rmodp p p = 0.
Proof.
move=> hC; rewrite /rmodp unlock; have [-> //|] := eqVneq.
rewrite -size_poly_eq0 /redivp_rec; case sp: (size p)=> [|n] // _.
rewrite sp ltnn subnn expr0 hC alg_polyC !simp subrr.
by case: n sp => [|n] sp; rewrite size_polyC /= eqxx.
Qed.
Definition rcoprimep (p q : {poly R}) := size (rgcdp p q) == 1.
Fixpoint rgdcop_rec q p n :=
if n is m.+1 then
if rcoprimep p q then p
else rgdcop_rec q (rdivp p (rgcdp p q)) m
else (q == 0)%:R.
Definition rgdcop q p := rgdcop_rec q p (size p).
Lemma rgdcop0 q : rgdcop q 0 = (q == 0)%:R.
Proof. by rewrite /rgdcop size_poly0. Qed.
End RingPseudoDivision.
End CommonRing.
Module RingComRreg.
Import CommonRing.
Section ComRegDivisor.
Variable R : nzRingType.
Variable d : {poly R}.
Hypothesis Cdl : GRing.comm d (lead_coef d)%:P.
Hypothesis Rreg : GRing.rreg (lead_coef d).
Implicit Types p q r : {poly R}.
Lemma redivp_eq q r :
size r < size d ->
let k := (redivp (q * d + r) d).1.1 in
let c := (lead_coef d ^+ k)%:P in
redivp (q * d + r) d = (k, q * c, r * c).
Proof.
move=> lt_rd; case: comm_redivpP=> k q1 r1 /(_ Cdl) Heq.
have dn0: d != 0 by case: (size d) lt_rd (size_poly_eq0 d) => // n _ <-.
move=> /(_ dn0) Hs.
have eC : q * d * (lead_coef d ^+ k)%:P = q * (lead_coef d ^+ k)%:P * d.
by rewrite -mulrA polyC_exp (commrX k Cdl) mulrA.
suff e1 : q1 = q * (lead_coef d ^+ k)%:P.
congr (_, _, _) => //=; move/eqP: Heq.
by rewrite [_ + r1]addrC -subr_eq e1 mulrDl addrAC eC subrr add0r; move/eqP.
have : (q1 - q * (lead_coef d ^+ k)%:P) * d = r * (lead_coef d ^+ k)%:P - r1.
apply: (@addIr _ r1); rewrite subrK.
apply: (@addrI _ ((q * (lead_coef d ^+ k)%:P) * d)).
by rewrite mulrDl mulNr !addrA [_ + (q1 * d)]addrC addrK -eC -mulrDl.
move/eqP; rewrite -[_ == _ - _]subr_eq0 rreg_div0 //.
by case/andP; rewrite subr_eq0; move/eqP.
rewrite size_polyN; apply: (leq_ltn_trans (size_polyD _ _)); rewrite size_polyN.
rewrite gtn_max Hs (leq_ltn_trans (size_polyMleq _ _)) //.
rewrite size_polyC; case: (_ == _); last by rewrite addnS addn0.
by rewrite addn0; apply: leq_ltn_trans lt_rd; case: size.
Qed.
(* this is a bad name *)
Lemma rdivp_eq p :
p * (lead_coef d ^+ (rscalp p d))%:P = (rdivp p d) * d + (rmodp p d).
Proof.
by rewrite /rdivp /rmodp /rscalp; case: comm_redivpP=> k q1 r1 Hc _; apply: Hc.
Qed.
(* section variables impose an inconvenient order on parameters *)
Lemma eq_rdvdp k q1 p:
p * ((lead_coef d)^+ k)%:P = q1 * d -> rdvdp d p.
Proof.
move=> he.
have Hnq0 := rreg_lead0 Rreg; set lq := lead_coef d.
pose v := rscalp p d; pose m := maxn v k.
rewrite /rdvdp -(rreg_polyMC_eq0 _ (@rregX _ _ (m - v) Rreg)).
suff:
((rdivp p d) * (lq ^+ (m - v))%:P - q1 * (lq ^+ (m - k))%:P) * d +
(rmodp p d) * (lq ^+ (m - v))%:P == 0.
rewrite rreg_div0 //; first by case/andP.
by rewrite rreg_size ?ltn_rmodp //; exact: rregX.
rewrite mulrDl addrAC mulNr -!mulrA polyC_exp -(commrX (m-v) Cdl).
rewrite -polyC_exp mulrA -mulrDl -rdivp_eq // [(_ ^+ (m - k))%:P]polyC_exp.
rewrite -(commrX (m-k) Cdl) -polyC_exp mulrA -he -!mulrA -!polyCM -/v.
by rewrite -!exprD addnC subnK ?leq_maxl // addnC subnK ?subrr ?leq_maxr.
Qed.
Variant rdvdp_spec p q : {poly R} -> bool -> Type :=
| Rdvdp k q1 & p * ((lead_coef q)^+ k)%:P = q1 * q : rdvdp_spec p q 0 true
| RdvdpN & rmodp p q != 0 : rdvdp_spec p q (rmodp p q) false.
(* Is that version useable ? *)
Lemma rdvdp_eqP p : rdvdp_spec p d (rmodp p d) (rdvdp d p).
Proof.
case hdvd: (rdvdp d p); last by apply: RdvdpN; move/rmodp_eq0P/eqP: hdvd.
move/rmodp_eq0P: (hdvd)->; apply: (@Rdvdp _ _ (rscalp p d) (rdivp p d)).
by rewrite rdivp_eq //; move/rmodp_eq0P: (hdvd)->; rewrite addr0.
Qed.
Lemma rdvdp_mull p : rdvdp d (p * d).
Proof. by apply: (@eq_rdvdp 0 p); rewrite expr0 mulr1. Qed.
Lemma rmodp_mull p : rmodp (p * d) d = 0. Proof. exact/eqP/rdvdp_mull. Qed.
Lemma rmodpp : rmodp d d = 0.
Proof. by rewrite -[d in rmodp d _]mul1r rmodp_mull. Qed.
Lemma rdivpp : rdivp d d = (lead_coef d ^+ rscalp d d)%:P.
Proof.
have dn0 : d != 0 by rewrite -lead_coef_eq0 rreg_neq0.
move: (rdivp_eq d); rewrite rmodpp addr0.
suff ->: GRing.comm d (lead_coef d ^+ rscalp d d)%:P by move/(rreg_lead Rreg)->.
by rewrite polyC_exp; apply: commrX.
Qed.
Lemma rdvdpp : rdvdp d d. Proof. exact/eqP/rmodpp. Qed.
Lemma rdivpK p : rdvdp d p ->
rdivp p d * d = p * (lead_coef d ^+ rscalp p d)%:P.
Proof. by rewrite rdivp_eq /rdvdp; move/eqP->; rewrite addr0. Qed.
End ComRegDivisor.
End RingComRreg.
Module RingMonic.
Import CommonRing.
Import RingComRreg.
Section RingMonic.
Variable R : nzRingType.
Implicit Types p q r : {poly R}.
Section MonicDivisor.
Variable d : {poly R}.
Hypothesis mond : d \is monic.
Lemma redivp_eq q r : size r < size d ->
let k := (redivp (q * d + r) d).1.1 in
redivp (q * d + r) d = (k, q, r).
Proof.
case: (monic_comreg mond)=> Hc Hr /(redivp_eq Hc Hr q).
by rewrite (eqP mond) => -> /=; rewrite expr1n !mulr1.
Qed.
Lemma rdivp_eq p : p = rdivp p d * d + rmodp p d.
Proof.
rewrite -rdivp_eq (eqP mond); last exact: commr1.
by rewrite expr1n mulr1.
Qed.
Lemma rdivpp : rdivp d d = 1.
Proof.
by case: (monic_comreg mond) => hc hr; rewrite rdivpp // (eqP mond) expr1n.
Qed.
Lemma rdivp_addl_mul_small q r : size r < size d -> rdivp (q * d + r) d = q.
Proof.
by move=> Hd; case: (monic_comreg mond)=> Hc Hr; rewrite /rdivp redivp_eq.
Qed.
Lemma rdivp_addl_mul q r : rdivp (q * d + r) d = q + rdivp r d.
Proof.
case: (monic_comreg mond)=> Hc Hr; rewrite [r in _ * _ + r]rdivp_eq addrA.
by rewrite -mulrDl rdivp_addl_mul_small // ltn_rmodp monic_neq0.
Qed.
Lemma rdivpDl q r : rdvdp d q -> rdivp (q + r) d = rdivp q d + rdivp r d.
Proof.
case: (monic_comreg mond)=> Hc Hr; rewrite [r in q + r]rdivp_eq addrA.
rewrite [q in q + _ + _]rdivp_eq; move/rmodp_eq0P->.
by rewrite addr0 -mulrDl rdivp_addl_mul_small // ltn_rmodp monic_neq0.
Qed.
Lemma rdivpDr q r : rdvdp d r -> rdivp (q + r) d = rdivp q d + rdivp r d.
Proof. by rewrite addrC; move/rdivpDl->; rewrite addrC. Qed.
Lemma rdivp_mull p : rdivp (p * d) d = p.
Proof. by rewrite -[p * d]addr0 rdivp_addl_mul rdiv0p addr0. Qed.
Lemma rmodp_mull p : rmodp (p * d) d = 0.
Proof.
by apply: rmodp_mull; rewrite (eqP mond); [apply: commr1 | apply: rreg1].
Qed.
Lemma rmodpp : rmodp d d = 0.
Proof.
by apply: rmodpp; rewrite (eqP mond); [apply: commr1 | apply: rreg1].
Qed.
Lemma rmodp_addl_mul_small q r : size r < size d -> rmodp (q * d + r) d = r.
Proof.
by move=> Hd; case: (monic_comreg mond)=> Hc Hr; rewrite /rmodp redivp_eq.
Qed.
Lemma rmodp_id (p : {poly R}) : rmodp (rmodp p d) d = rmodp p d.
Proof.
by rewrite rmodp_small // ltn_rmodpN0 // monic_neq0.
Qed.
Lemma rmodpD p q : rmodp (p + q) d = rmodp p d + rmodp q d.
Proof.
rewrite [p in LHS]rdivp_eq [q in LHS]rdivp_eq addrACA -mulrDl.
rewrite rmodp_addl_mul_small //; apply: (leq_ltn_trans (size_polyD _ _)).
by rewrite gtn_max !ltn_rmodp // monic_neq0.
Qed.
Lemma rmodpN p : rmodp (- p) d = - (rmodp p d).
Proof.
rewrite {1}(rdivp_eq p) opprD // -mulNr rmodp_addl_mul_small //.
by rewrite size_polyN ltn_rmodp // monic_neq0.
Qed.
Lemma rmodpB p q : rmodp (p - q) d = rmodp p d - rmodp q d.
Proof. by rewrite rmodpD rmodpN. Qed.
Lemma rmodpZ a p : rmodp (a *: p) d = a *: (rmodp p d).
Proof.
case: (altP (a =P 0%R)) => [-> | cn0]; first by rewrite !scale0r rmod0p.
have -> : ((a *: p) = (a *: (rdivp p d)) * d + a *: (rmodp p d))%R.
by rewrite -scalerAl -scalerDr -rdivp_eq.
rewrite rmodp_addl_mul_small //.
rewrite -mul_polyC; apply: leq_ltn_trans (size_polyMleq _ _) _.
rewrite size_polyC cn0 addSn add0n /= ltn_rmodp.
exact: monic_neq0.
Qed.
Lemma rmodp_sum (I : Type) (r : seq I) (P : pred I) (F : I -> {poly R}) :
rmodp (\sum_(i <- r | P i) F i) d = (\sum_(i <- r | P i) (rmodp (F i) d)).
Proof.
by elim/big_rec2: _ => [|i p q _ <-]; rewrite ?(rmod0p, rmodpD).
Qed.
Lemma rmodp_mulmr p q : rmodp (p * (rmodp q d)) d = rmodp (p * q) d.
Proof.
by rewrite [q in RHS]rdivp_eq mulrDr rmodpD mulrA rmodp_mull add0r.
Qed.
Lemma rdvdpp : rdvdp d d.
Proof.
by apply: rdvdpp; rewrite (eqP mond); [apply: commr1 | apply: rreg1].
Qed.
(* section variables impose an inconvenient order on parameters *)
Lemma eq_rdvdp q1 p : p = q1 * d -> rdvdp d p.
Proof.
(* this probably means I need to specify impl args for comm_rref_rdvdp *)
move=> h; apply: (@eq_rdvdp _ _ _ _ 1 q1); rewrite (eqP mond).
- exact: commr1.
- exact: rreg1.
by rewrite expr1n mulr1.
Qed.
Lemma rdvdp_mull p : rdvdp d (p * d).
Proof.
by apply: rdvdp_mull; rewrite (eqP mond) //; [apply: commr1 | apply: rreg1].
Qed.
Lemma rdvdpP p : reflect (exists qq, p = qq * d) (rdvdp d p).
Proof.
case: (monic_comreg mond)=> Hc Hr; apply: (iffP idP) => [|[qq] /eq_rdvdp //].
by case: rdvdp_eqP=> // k qq; rewrite (eqP mond) expr1n mulr1 => ->; exists qq.
Qed.
Lemma rdivpK p : rdvdp d p -> (rdivp p d) * d = p.
Proof. by move=> dvddp; rewrite [RHS]rdivp_eq rmodp_eq0 ?addr0. Qed.
End MonicDivisor.
Lemma drop_poly_rdivp n p : drop_poly n p = rdivp p 'X^n.
Proof.
rewrite -[p in RHS](poly_take_drop n) addrC rdivp_addl_mul ?monicXn//.
by rewrite rdivp_small ?addr0// size_polyXn ltnS size_take_poly.
Qed.
Lemma take_poly_rmodp n p : take_poly n p = rmodp p 'X^n.
Proof.
have mX := monicXn R n; rewrite -[p in RHS](poly_take_drop n) rmodpD//.
by rewrite rmodp_small ?rmodp_mull ?addr0// size_polyXn ltnS size_take_poly.
Qed.
End RingMonic.
Section ComRingMonic.
Variable R : comNzRingType.
Implicit Types p q r : {poly R}.
Variable d : {poly R}.
Hypothesis mond : d \is monic.
Lemma rmodp_mulml p q : rmodp (rmodp p d * q) d = rmodp (p * q) d.
Proof. by rewrite [in LHS]mulrC [in RHS]mulrC rmodp_mulmr. Qed.
Lemma rmodpX p n : rmodp ((rmodp p d) ^+ n) d = rmodp (p ^+ n) d.
Proof.
elim: n => [|n IH]; first by rewrite !expr0.
rewrite !exprS -rmodp_mulmr // IH rmodp_mulmr //.
by rewrite mulrC rmodp_mulmr // mulrC.
Qed.
Lemma rmodp_compr p q : rmodp (p \Po (rmodp q d)) d = (rmodp (p \Po q) d).
Proof.
elim/poly_ind: p => [|p c IH]; first by rewrite !comp_polyC !rmod0p.
rewrite !comp_polyD !comp_polyM addrC rmodpD //.
rewrite mulrC -rmodp_mulmr // IH rmodp_mulmr //.
rewrite !comp_polyX !comp_polyC.
by rewrite mulrC rmodp_mulmr // -rmodpD // addrC.
Qed.
End ComRingMonic.
End RingMonic.
Module Ring.
Include CommonRing.
Import RingMonic.
Section ExtraMonicDivisor.
Variable R : nzRingType.
Implicit Types d p q r : {poly R}.
Lemma rdivp1 p : rdivp p 1 = p.
Proof. by rewrite -[p in LHS]mulr1 rdivp_mull // monic1. Qed.
Lemma rdvdp_XsubCl p x : rdvdp ('X - x%:P) p = root p x.
Proof.
have [HcX Hr] := monic_comreg (monicXsubC x).
apply/rmodp_eq0P/factor_theorem => [|[p1 ->]]; last exact/rmodp_mull/monicXsubC.
move=> e0; exists (rdivp p ('X - x%:P)).
by rewrite [LHS](rdivp_eq (monicXsubC x)) e0 addr0.
Qed.
Lemma polyXsubCP p x : reflect (p.[x] = 0) (rdvdp ('X - x%:P) p).
Proof. by apply: (iffP idP); rewrite rdvdp_XsubCl; move/rootP. Qed.
Lemma root_factor_theorem p x : root p x = (rdvdp ('X - x%:P) p).
Proof. by rewrite rdvdp_XsubCl. Qed.
End ExtraMonicDivisor.
End Ring.
Module ComRing.
Import Ring.
Import RingComRreg.
Section CommutativeRingPseudoDivision.
Variable R : comNzRingType.
Implicit Types d p q m n r : {poly R}.
Variant redivp_spec (m d : {poly R}) : nat * {poly R} * {poly R} -> Type :=
EdivnSpec k (q r: {poly R}) of
(lead_coef d ^+ k) *: m = q * d + r &
(d != 0 -> size r < size d) : redivp_spec m d (k, q, r).
Lemma redivpP m d : redivp_spec m d (redivp m d).
Proof.
rewrite redivp_def; constructor; last by move=> dn0; rewrite ltn_rmodp.
by rewrite -mul_polyC mulrC rdivp_eq //= /GRing.comm mulrC.
Qed.
Lemma rdivp_eq d p :
(lead_coef d ^+ rscalp p d) *: p = rdivp p d * d + rmodp p d.
Proof.
by rewrite /rdivp /rmodp /rscalp; case: redivpP=> k q1 r1 Hc _; apply: Hc.
Qed.
Lemma rdvdp_eqP d p : rdvdp_spec p d (rmodp p d) (rdvdp d p).
Proof.
case hdvd: (rdvdp d p); last by move/rmodp_eq0P/eqP/RdvdpN: hdvd.
move/rmodp_eq0P: (hdvd)->; apply: (@Rdvdp _ _ _ (rscalp p d) (rdivp p d)).
by rewrite mulrC mul_polyC rdivp_eq; move/rmodp_eq0P: (hdvd)->; rewrite addr0.
Qed.
Lemma rdvdp_eq q p :
rdvdp q p = (lead_coef q ^+ rscalp p q *: p == rdivp p q * q).
Proof.
rewrite rdivp_eq; apply/rmodp_eq0P/eqP => [->|/eqP]; first by rewrite addr0.
by rewrite eq_sym addrC -subr_eq subrr; move/eqP<-.
Qed.
End CommutativeRingPseudoDivision.
End ComRing.
Module UnitRing.
Import Ring.
Section UnitRingPseudoDivision.
Variable R : unitRingType.
Implicit Type p q r d : {poly R}.
Lemma uniq_roots_rdvdp p rs :
all (root p) rs -> uniq_roots rs -> rdvdp (\prod_(z <- rs) ('X - z%:P)) p.
Proof.
move=> rrs /(uniq_roots_prod_XsubC rrs) [q ->].
exact/RingMonic.rdvdp_mull/monic_prod_XsubC.
Qed.
End UnitRingPseudoDivision.
End UnitRing.
Module IdomainDefs.
Import Ring.
Section IDomainPseudoDivisionDefs.
Variable R : idomainType.
Implicit Type p q r d : {poly R}.
Definition edivp_expanded_def p q :=
let: (k, d, r) as edvpq := redivp p q in
if lead_coef q \in GRing.unit then
(0, (lead_coef q)^-k *: d, (lead_coef q)^-k *: r)
else edvpq.
Fact edivp_key : unit. Proof. by []. Qed.
Definition edivp := locked_with edivp_key edivp_expanded_def.
Canonical edivp_unlockable := [unlockable fun edivp].
Definition divp p q := ((edivp p q).1).2.
Definition modp p q := (edivp p q).2.
Definition scalp p q := ((edivp p q).1).1.
Definition dvdp p q := modp q p == 0.
Definition eqp p q := (dvdp p q) && (dvdp q p).
End IDomainPseudoDivisionDefs.
Notation "m %/ d" := (divp m d) : ring_scope.
Notation "m %% d" := (modp m d) : ring_scope.
Notation "p %| q" := (dvdp p q) : ring_scope.
Notation "p %= q" := (eqp p q) : ring_scope.
End IdomainDefs.
Module WeakIdomain.
Import Ring ComRing UnitRing IdomainDefs.
Section WeakTheoryForIDomainPseudoDivision.
Variable R : idomainType.
Implicit Type p q r d : {poly R}.
Lemma edivp_def p q : edivp p q = (scalp p q, divp p q, modp p q).
Proof. by rewrite /scalp /divp /modp; case: (edivp p q) => [[]] /=. Qed.
Lemma edivp_redivp p q : lead_coef q \in GRing.unit = false ->
edivp p q = redivp p q.
Proof. by move=> hu; rewrite unlock hu; case: (redivp p q) => [[? ?] ?]. Qed.
Lemma divpE p q :
p %/ q = if lead_coef q \in GRing.unit
then lead_coef q ^- rscalp p q *: rdivp p q
else rdivp p q.
Proof. by case: ifP; rewrite /divp unlock redivp_def => ->. Qed.
Lemma modpE p q :
p %% q = if lead_coef q \in GRing.unit
then lead_coef q ^- rscalp p q *: (rmodp p q)
else rmodp p q.
Proof. by case: ifP; rewrite /modp unlock redivp_def => ->. Qed.
Lemma scalpE p q :
scalp p q = if lead_coef q \in GRing.unit then 0 else rscalp p q.
Proof. by case: ifP; rewrite /scalp unlock redivp_def => ->. Qed.
Lemma dvdpE p q : p %| q = rdvdp p q.
Proof.
rewrite /dvdp modpE /rdvdp; case ulcq: (lead_coef p \in GRing.unit)=> //.
rewrite -[in LHS]size_poly_eq0 size_scale ?size_poly_eq0 //.
by rewrite invr_eq0 expf_neq0 //; apply: contraTneq ulcq => ->; rewrite unitr0.
Qed.
Lemma lc_expn_scalp_neq0 p q : lead_coef q ^+ scalp p q != 0.
Proof.
have [->|nzq] := eqVneq q 0; last by rewrite expf_neq0 ?lead_coef_eq0.
by rewrite /scalp 2!unlock /= eqxx lead_coef0 unitr0 /= oner_neq0.
Qed.
Hint Resolve lc_expn_scalp_neq0 : core.
Variant edivp_spec (m d : {poly R}) :
nat * {poly R} * {poly R} -> bool -> Type :=
|Redivp_spec k (q r: {poly R}) of
(lead_coef d ^+ k) *: m = q * d + r & lead_coef d \notin GRing.unit &
(d != 0 -> size r < size d) : edivp_spec m d (k, q, r) false
|Fedivp_spec (q r: {poly R}) of m = q * d + r & (lead_coef d \in GRing.unit) &
(d != 0 -> size r < size d) : edivp_spec m d (0, q, r) true.
(* There are several ways to state this fact. The most appropriate statement*)
(* might be polished in light of usage. *)
Lemma edivpP m d : edivp_spec m d (edivp m d) (lead_coef d \in GRing.unit).
Proof.
have hC : GRing.comm d (lead_coef d)%:P by rewrite /GRing.comm mulrC.
case ud: (lead_coef d \in GRing.unit); last first.
rewrite edivp_redivp // redivp_def; constructor; rewrite ?ltn_rmodp // ?ud //.
by rewrite rdivp_eq.
have cdn0: lead_coef d != 0 by apply: contraTneq ud => ->; rewrite unitr0.
rewrite unlock ud redivp_def; constructor => //.
rewrite -scalerAl -scalerDr -mul_polyC.
have hn0 : (lead_coef d ^+ rscalp m d)%:P != 0.
by rewrite polyC_eq0; apply: expf_neq0.
apply: (mulfI hn0); rewrite !mulrA -exprVn !polyC_exp -exprMn -polyCM.
by rewrite divrr // expr1n mul1r -polyC_exp mul_polyC rdivp_eq.
move=> dn0; rewrite size_scale ?ltn_rmodp // -exprVn expf_eq0 negb_and.
by rewrite invr_eq0 cdn0 orbT.
Qed.
Lemma edivp_eq d q r : size r < size d -> lead_coef d \in GRing.unit ->
edivp (q * d + r) d = (0, q, r).
Proof.
have hC : GRing.comm d (lead_coef d)%:P by apply: mulrC.
move=> hsrd hu; rewrite unlock hu; case et: (redivp _ _) => [[s qq] rr].
have cdn0 : lead_coef d != 0 by case: eqP hu => //= ->; rewrite unitr0.
move: (et); rewrite RingComRreg.redivp_eq //; last exact/rregP.
rewrite et /= mulrC (mulrC r) !mul_polyC; case=> <- <-.
by rewrite !scalerA mulVr ?scale1r // unitrX.
Qed.
Lemma divp_eq p q : (lead_coef q ^+ scalp p q) *: p = (p %/ q) * q + (p %% q).
Proof.
rewrite divpE modpE scalpE.
case uq: (lead_coef q \in GRing.unit); last by rewrite rdivp_eq.
rewrite expr0 scale1r; have [->|qn0] := eqVneq q 0.
by rewrite lead_coef0 expr0n /rscalp unlock eqxx invr1 !scale1r rmodp0 !simp.
by rewrite -scalerAl -scalerDr -rdivp_eq scalerA mulVr (scale1r, unitrX).
Qed.
Lemma dvdp_eq q p : (q %| p) = (lead_coef q ^+ scalp p q *: p == (p %/ q) * q).
Proof.
rewrite dvdpE rdvdp_eq scalpE divpE; case: ifP => ulcq //.
rewrite expr0 scale1r -scalerAl; apply/eqP/eqP => [<- | {2}->].
by rewrite scalerA mulVr ?scale1r // unitrX.
by rewrite scalerA mulrV ?scale1r // unitrX.
Qed.
Lemma divpK d p : d %| p -> p %/ d * d = (lead_coef d ^+ scalp p d) *: p.
Proof. by rewrite dvdp_eq; move/eqP->. Qed.
Lemma divpKC d p : d %| p -> d * (p %/ d) = (lead_coef d ^+ scalp p d) *: p.
Proof. by move=> ?; rewrite mulrC divpK. Qed.
Lemma dvdpP q p :
reflect (exists2 cqq, cqq.1 != 0 & cqq.1 *: p = cqq.2 * q) (q %| p).
Proof.
rewrite dvdp_eq; apply: (iffP eqP) => [e | [[c qq] cn0 e]].
by exists (lead_coef q ^+ scalp p q, p %/ q) => //=.
apply/eqP; rewrite -dvdp_eq dvdpE.
have Ecc: c%:P != 0 by rewrite polyC_eq0.
have [->|nz_p] := eqVneq p 0; first by rewrite rdvdp0.
pose p1 : {poly R} := lead_coef q ^+ rscalp p q *: qq - c *: (rdivp p q).
have E1: c *: rmodp p q = p1 * q.
rewrite mulrDl mulNr -scalerAl -e scalerA mulrC -scalerA -scalerAl.
by rewrite -scalerBr rdivp_eq addrC addKr.
suff: p1 * q == 0 by rewrite -E1 -mul_polyC mulf_eq0 (negPf Ecc).
rewrite mulf_eq0; apply/norP; case=> p1_nz q_nz; have:= ltn_rmodp p q.
by rewrite q_nz -(size_scale _ cn0) E1 size_mul // polySpred // ltnNge leq_addl.
Qed.
Lemma mulpK p q : q != 0 -> p * q %/ q = lead_coef q ^+ scalp (p * q) q *: p.
Proof.
move=> qn0; apply: (rregP qn0); rewrite -scalerAl divp_eq.
suff -> : (p * q) %% q = 0 by rewrite addr0.
rewrite modpE RingComRreg.rmodp_mull ?scaler0 ?if_same //.
by red; rewrite mulrC.
by apply/rregP; rewrite lead_coef_eq0.
Qed.
Lemma mulKp p q : q != 0 -> q * p %/ q = lead_coef q ^+ scalp (p * q) q *: p.
Proof. by move=> nzq; rewrite mulrC; apply: mulpK. Qed.
Lemma divpp p : p != 0 -> p %/ p = (lead_coef p ^+ scalp p p)%:P.
Proof.
move=> np0; have := divp_eq p p.
suff -> : p %% p = 0 by rewrite addr0 -mul_polyC; move/(mulIf np0).
rewrite modpE Ring.rmodpp; last by red; rewrite mulrC.
by rewrite scaler0 if_same.
Qed.
End WeakTheoryForIDomainPseudoDivision.
#[global] Hint Resolve lc_expn_scalp_neq0 : core.
End WeakIdomain.
Module CommonIdomain.
Import Ring ComRing UnitRing IdomainDefs WeakIdomain.
Section IDomainPseudoDivision.
Variable R : idomainType.
Implicit Type p q r d m n : {poly R}.
Lemma scalp0 p : scalp p 0 = 0.
Proof. by rewrite /scalp unlock lead_coef0 unitr0 unlock eqxx. Qed.
Lemma divp_small p q : size p < size q -> p %/ q = 0.
Proof.
move=> spq; rewrite /divp unlock redivp_def /=.
by case: ifP; rewrite rdivp_small // scaler0.
Qed.
Lemma leq_divp p q : (size (p %/ q) <= size p).
Proof.
rewrite /divp unlock redivp_def /=; case: ifP => ulcq; rewrite ?leq_rdivp //=.
rewrite size_scale ?leq_rdivp // -exprVn expf_neq0 // invr_eq0.
by case: eqP ulcq => // ->; rewrite unitr0.
Qed.
Lemma div0p p : 0 %/ p = 0.
Proof.
by rewrite /divp unlock redivp_def /=; case: ifP; rewrite rdiv0p // scaler0.
Qed.
Lemma divp0 p : p %/ 0 = 0.
Proof.
by rewrite /divp unlock redivp_def /=; case: ifP; rewrite rdivp0 // scaler0.
Qed.
Lemma divp1 m : m %/ 1 = m.
Proof.
by rewrite divpE lead_coefC unitr1 Ring.rdivp1 expr1n invr1 scale1r.
Qed.
Lemma modp0 p : p %% 0 = p.
Proof.
rewrite /modp unlock redivp_def; case: ifP; rewrite rmodp0 //= lead_coef0.
by rewrite unitr0.
Qed.
Lemma mod0p p : 0 %% p = 0.
Proof.
by rewrite /modp unlock redivp_def /=; case: ifP; rewrite rmod0p // scaler0.
Qed.
Lemma modp1 p : p %% 1 = 0.
Proof.
by rewrite /modp unlock redivp_def /=; case: ifP; rewrite rmodp1 // scaler0.
Qed.
Hint Resolve divp0 divp1 mod0p modp0 modp1 : core.
Lemma modp_small p q : size p < size q -> p %% q = p.
Proof.
move=> spq; rewrite /modp unlock redivp_def; case: ifP; rewrite rmodp_small //.
by rewrite /= rscalp_small // expr0 /= invr1 scale1r.
Qed.
Lemma modpC p c : c != 0 -> p %% c%:P = 0.
Proof.
move=> cn0; rewrite /modp unlock redivp_def /=; case: ifP; rewrite ?rmodpC //.
by rewrite scaler0.
Qed.
Lemma modp_mull p q : (p * q) %% q = 0.
Proof.
have [-> | nq0] := eqVneq q 0; first by rewrite modp0 mulr0.
have rlcq : GRing.rreg (lead_coef q) by apply/rregP; rewrite lead_coef_eq0.
have hC : GRing.comm q (lead_coef q)%:P by red; rewrite mulrC.
rewrite modpE; case: ifP => ulcq; rewrite RingComRreg.rmodp_mull //.
exact: scaler0.
Qed.
Lemma modp_mulr d p : (d * p) %% d = 0. Proof. by rewrite mulrC modp_mull. Qed.
Lemma modpp d : d %% d = 0.
Proof. by rewrite -[d in d %% _]mul1r modp_mull. Qed.
Lemma ltn_modp p q : (size (p %% q) < size q) = (q != 0).
Proof.
rewrite /modp unlock redivp_def /=; case: ifP=> ulcq; rewrite ?ltn_rmodp //=.
rewrite size_scale ?ltn_rmodp // -exprVn expf_neq0 // invr_eq0.
by case: eqP ulcq => // ->; rewrite unitr0.
Qed.
Lemma ltn_divpl d q p : d != 0 ->
(size (q %/ d) < size p) = (size q < size (p * d)).
Proof.
move=> dn0.
have: (lead_coef d) ^+ (scalp q d) != 0 by apply: lc_expn_scalp_neq0.
move/(size_scale q)<-; rewrite divp_eq; have [->|quo0] := eqVneq (q %/ d) 0.
rewrite mul0r add0r size_poly0 size_poly_gt0.
have [->|pn0] := eqVneq p 0; first by rewrite mul0r size_poly0 ltn0.
by rewrite size_mul // (polySpred pn0) addSn ltn_addl // ltn_modp.
rewrite size_polyDl; last first.
by rewrite size_mul // (polySpred quo0) addSn /= ltn_addl // ltn_modp.
have [->|pn0] := eqVneq p 0; first by rewrite mul0r size_poly0 !ltn0.
by rewrite !size_mul ?quo0 // (polySpred dn0) !addnS ltn_add2r.
Qed.
Lemma leq_divpr d p q : d != 0 ->
(size p <= size (q %/ d)) = (size (p * d) <= size q).
Proof. by move=> dn0; rewrite leqNgt ltn_divpl // -leqNgt. Qed.
Lemma divpN0 d p : d != 0 -> (p %/ d != 0) = (size d <= size p).
Proof.
move=> dn0.
by rewrite -[d in RHS]mul1r -leq_divpr // size_polyC oner_eq0 size_poly_gt0.
Qed.
Lemma size_divp p q : q != 0 -> size (p %/ q) = (size p - (size q).-1)%N.
Proof.
move=> nq0; case: (leqP (size q) (size p)) => sqp; last first.
move: (sqp); rewrite -{1}(ltn_predK sqp) ltnS -subn_eq0 divp_small //.
by move/eqP->; rewrite size_poly0.
have np0 : p != 0.
by rewrite -size_poly_gt0; apply: leq_trans sqp; rewrite size_poly_gt0.
have /= := congr1 (size \o @polyseq R) (divp_eq p q).
rewrite size_scale; last by rewrite expf_eq0 lead_coef_eq0 (negPf nq0) andbF.
have [->|qq0] := eqVneq (p %/ q) 0.
by rewrite mul0r add0r=> es; move: nq0; rewrite -(ltn_modp p) -es ltnNge sqp.
rewrite size_polyDl.
by move->; apply/eqP; rewrite size_mul // (polySpred nq0) addnS /= addnK.
rewrite size_mul ?qq0 //.
move: nq0; rewrite -(ltn_modp p); move/leq_trans; apply.
by rewrite (polySpred qq0) addSn /= leq_addl.
Qed.
Lemma ltn_modpN0 p q : q != 0 -> size (p %% q) < size q.
Proof. by rewrite ltn_modp. Qed.
Lemma modp_id p q : (p %% q) %% q = p %% q.
Proof.
by have [->|qn0] := eqVneq q 0; rewrite ?modp0 // modp_small ?ltn_modp.
Qed.
Lemma leq_modp m d : size (m %% d) <= size m.
Proof.
rewrite /modp unlock redivp_def /=; case: ifP; rewrite ?leq_rmodp //.
move=> ud; rewrite size_scale ?leq_rmodp // invr_eq0 expf_neq0 //.
by apply: contraTneq ud => ->; rewrite unitr0.
Qed.
Lemma dvdp0 d : d %| 0. Proof. by rewrite /dvdp mod0p. Qed.
Hint Resolve dvdp0 : core.
Lemma dvd0p p : (0 %| p) = (p == 0). Proof. by rewrite /dvdp modp0. Qed.
Lemma dvd0pP p : reflect (p = 0) (0 %| p).
Proof. by apply: (iffP idP); rewrite dvd0p; move/eqP. Qed.
Lemma dvdpN0 p q : p %| q -> q != 0 -> p != 0.
Proof. by move=> pq hq; apply: contraTneq pq => ->; rewrite dvd0p. Qed.
Lemma dvdp1 d : (d %| 1) = (size d == 1).
Proof.
rewrite /dvdp modpE; case ud: (lead_coef d \in GRing.unit); last exact: rdvdp1.
rewrite -size_poly_eq0 size_scale; first by rewrite size_poly_eq0 -rdvdp1.
by rewrite invr_eq0 expf_neq0 //; apply: contraTneq ud => ->; rewrite unitr0.
Qed.
Lemma dvd1p m : 1 %| m. Proof. by rewrite /dvdp modp1. Qed.
Lemma gtNdvdp p q : p != 0 -> size p < size q -> (q %| p) = false.
Proof.
by move=> nn0 hs; rewrite /dvdp; rewrite (modp_small hs); apply: negPf.
Qed.
Lemma modp_eq0P p q : reflect (p %% q = 0) (q %| p).
Proof. exact: (iffP eqP). Qed.
Lemma modp_eq0 p q : (q %| p) -> p %% q = 0. Proof. exact: modp_eq0P. Qed.
Lemma leq_divpl d p q :
d %| p -> (size (p %/ d) <= size q) = (size p <= size (q * d)).
Proof.
case: (eqVneq d 0) => [-> /dvd0pP -> | nd0 hd].
by rewrite divp0 size_poly0 !leq0n.
rewrite leq_eqVlt ltn_divpl // (leq_eqVlt (size p)).
case lhs: (size p < size (q * d)); rewrite ?orbT ?orbF //.
have: (lead_coef d) ^+ (scalp p d) != 0 by rewrite expf_neq0 // lead_coef_eq0.
move/(size_scale p)<-; rewrite divp_eq; move/modp_eq0P: hd->; rewrite addr0.
have [-> | quon0] := eqVneq (p %/ d) 0.
rewrite mul0r size_poly0 2!(eq_sym 0) !size_poly_eq0.
by rewrite mulf_eq0 (negPf nd0) orbF.
have [-> | nq0] := eqVneq q 0.
by rewrite mul0r size_poly0 !size_poly_eq0 mulf_eq0 (negPf nd0) orbF.
by rewrite !size_mul // (polySpred nd0) !addnS /= eqn_add2r.
Qed.
Lemma dvdp_leq p q : q != 0 -> p %| q -> size p <= size q.
Proof.
move=> nq0 /modp_eq0P.
by case: leqP => // /modp_small -> /eqP; rewrite (negPf nq0).
Qed.
Lemma eq_dvdp c quo q p : c != 0 -> c *: p = quo * q -> q %| p.
Proof.
move=> cn0; case: (eqVneq p 0) => [->|nz_quo def_quo] //.
pose p1 : {poly R} := lead_coef q ^+ scalp p q *: quo - c *: (p %/ q).
have E1: c *: (p %% q) = p1 * q.
rewrite mulrDl mulNr -scalerAl -def_quo scalerA mulrC -scalerA.
by rewrite -scalerAl -scalerBr divp_eq addrAC subrr add0r.
rewrite /dvdp; apply/idPn=> m_nz.
have: p1 * q != 0 by rewrite -E1 -mul_polyC mulf_neq0 // polyC_eq0.
rewrite mulf_eq0; case/norP=> p1_nz q_nz.
have := ltn_modp p q; rewrite q_nz -(size_scale (p %% q) cn0) E1.
by rewrite size_mul // polySpred // ltnNge leq_addl.
Qed.
Lemma dvdpp d : d %| d. Proof. by rewrite /dvdp modpp. Qed.
Hint Resolve dvdpp : core.
Lemma divp_dvd p q : p %| q -> (q %/ p) %| q.
Proof.
have [-> | np0] := eqVneq p 0; first by rewrite divp0.
rewrite dvdp_eq => /eqP h.
apply: (@eq_dvdp ((lead_coef p)^+ (scalp q p)) p); last by rewrite mulrC.
by rewrite expf_neq0 // lead_coef_eq0.
Qed.
Lemma dvdp_mull m d n : d %| n -> d %| m * n.
Proof.
case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite mulr0 dvdpp.
rewrite dvdp_eq => /eqP e.
apply: (@eq_dvdp (lead_coef d ^+ scalp n d) (m * (n %/ d))).
by rewrite expf_neq0 // lead_coef_eq0.
by rewrite scalerAr e mulrA.
Qed.
Lemma dvdp_mulr n d m : d %| m -> d %| m * n.
Proof. by move=> hdm; rewrite mulrC dvdp_mull. Qed.
Hint Resolve dvdp_mull dvdp_mulr : core.
Lemma dvdp_mul d1 d2 m1 m2 : d1 %| m1 -> d2 %| m2 -> d1 * d2 %| m1 * m2.
Proof.
case: (eqVneq d1 0) => [-> /dvd0pP -> | d1n0]; first by rewrite !mul0r dvdpp.
case: (eqVneq d2 0) => [-> _ /dvd0pP -> | d2n0]; first by rewrite !mulr0.
rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Hq1.
rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _; move/eqP=> Hq2.
apply: (@eq_dvdp (c1 * c2) (q1 * q2)).
by rewrite mulf_neq0 // expf_neq0 // lead_coef_eq0.
rewrite -scalerA scalerAr scalerAl Hq1 Hq2 -!mulrA.
by rewrite [d1 * (q2 * _)]mulrCA.
Qed.
Lemma dvdp_addr m d n : d %| m -> (d %| m + n) = (d %| n).
Proof.
case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite add0r.
rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Eq1.
apply/idP/idP; rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _.
have sn0 : c1 * c2 != 0.
by rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 (negPf dn0) andbF.
move/eqP=> Eq2; apply: (@eq_dvdp _ (c1 *: q2 - c2 *: q1) _ _ sn0).
rewrite mulrDl -scaleNr -!scalerAl -Eq1 -Eq2 !scalerA.
by rewrite mulNr mulrC scaleNr -scalerBr addrC addKr.
have sn0 : c1 * c2 != 0.
by rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 (negPf dn0) andbF.
move/eqP=> Eq2; apply: (@eq_dvdp _ (c1 *: q2 + c2 *: q1) _ _ sn0).
by rewrite mulrDl -!scalerAl -Eq1 -Eq2 !scalerA mulrC addrC scalerDr.
Qed.
Lemma dvdp_addl n d m : d %| n -> (d %| m + n) = (d %| m).
Proof. by rewrite addrC; apply: dvdp_addr. Qed.
Lemma dvdp_add d m n : d %| m -> d %| n -> d %| m + n.
Proof. by move/dvdp_addr->. Qed.
Lemma dvdp_add_eq d m n : d %| m + n -> (d %| m) = (d %| n).
Proof. by move=> ?; apply/idP/idP; [move/dvdp_addr <-| move/dvdp_addl <-]. Qed.
Lemma dvdp_subr d m n : d %| m -> (d %| m - n) = (d %| n).
Proof. by move=> ?; apply: dvdp_add_eq; rewrite -addrA addNr simp. Qed.
Lemma dvdp_subl d m n : d %| n -> (d %| m - n) = (d %| m).
Proof. by move/dvdp_addl<-; rewrite subrK. Qed.
Lemma dvdp_sub d m n : d %| m -> d %| n -> d %| m - n.
Proof. by move=> *; rewrite dvdp_subl. Qed.
Lemma dvdp_mod d n m : d %| n -> (d %| m) = (d %| m %% n).
Proof.
have [-> | nn0] := eqVneq n 0; first by rewrite modp0.
case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite modp0.
rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Eq1.
apply/idP/idP; rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _.
have sn0 : c1 * c2 != 0.
by rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 (negPf dn0) andbF.
pose quo := (c1 * lead_coef n ^+ scalp m n) *: q2 - c2 *: (m %/ n) * q1.
move/eqP=> Eq2; apply: (@eq_dvdp _ quo _ _ sn0).
rewrite mulrDl mulNr -!scalerAl -!mulrA -Eq1 -Eq2 -scalerAr !scalerA.
rewrite mulrC [_ * c2]mulrC mulrA -[((_ * _) * _) *: _]scalerA -scalerBr.
by rewrite divp_eq addrC addKr.
have sn0 : c1 * c2 * lead_coef n ^+ scalp m n != 0.
rewrite !mulf_neq0 // expf_eq0 lead_coef_eq0 ?(negPf dn0) ?andbF //.
by rewrite (negPf nn0) andbF.
move/eqP=> Eq2; apply: (@eq_dvdp _ (c2 *: (m %/ n) * q1 + c1 *: q2) _ _ sn0).
rewrite -scalerA divp_eq scalerDr -!scalerA Eq2 scalerAl scalerAr Eq1.
by rewrite scalerAl mulrDl mulrA.
Qed.
Lemma dvdp_trans : transitive (@dvdp R).
Proof.
move=> n d m.
case: (eqVneq d 0) => [-> /dvd0pP -> // | dn0].
case: (eqVneq n 0) => [-> _ /dvd0pP -> // | nn0].
rewrite dvdp_eq; set c1 := _ ^+ _; set q1 := _ %/ _; move/eqP=> Hq1.
rewrite dvdp_eq; set c2 := _ ^+ _; set q2 := _ %/ _; move/eqP=> Hq2.
have sn0 : c1 * c2 != 0 by rewrite mulf_neq0 // expf_neq0 // lead_coef_eq0.
apply: (@eq_dvdp _ (q2 * q1) _ _ sn0).
by rewrite -scalerA Hq2 scalerAr Hq1 mulrA.
Qed.
Lemma dvdp_mulIl p q : p %| p * q. Proof. exact/dvdp_mulr/dvdpp. Qed.
Lemma dvdp_mulIr p q : q %| p * q. Proof. exact/dvdp_mull/dvdpp. Qed.
Lemma dvdp_mul2r r p q : r != 0 -> (p * r %| q * r) = (p %| q).
Proof.
move=> nzr.
have [-> | pn0] := eqVneq p 0.
by rewrite mul0r !dvd0p mulf_eq0 (negPf nzr) orbF.
have [-> | qn0] := eqVneq q 0; first by rewrite mul0r !dvdp0.
apply/idP/idP; last by move=> ?; rewrite dvdp_mul ?dvdpp.
rewrite dvdp_eq; set c := _ ^+ _; set x := _ %/ _; move/eqP=> Hx.
apply: (@eq_dvdp c x); first by rewrite expf_neq0 // lead_coef_eq0 mulf_neq0.
by apply: (mulIf nzr); rewrite -mulrA -scalerAl.
Qed.
Lemma dvdp_mul2l r p q: r != 0 -> (r * p %| r * q) = (p %| q).
Proof. by rewrite ![r * _]mulrC; apply: dvdp_mul2r. Qed.
Lemma ltn_divpr d p q :
d %| q -> (size p < size (q %/ d)) = (size (p * d) < size q).
Proof. by move=> dv_d_q; rewrite !ltnNge leq_divpl. Qed.
Lemma dvdp_exp d k p : 0 < k -> d %| p -> d %| (p ^+ k).
Proof. by case: k => // k _ d_dv_m; rewrite exprS dvdp_mulr. Qed.
Lemma dvdp_exp2l d k l : k <= l -> d ^+ k %| d ^+ l.
Proof. by move/subnK <-; rewrite exprD dvdp_mull // ?lead_coef_exp ?unitrX. Qed.
Lemma dvdp_Pexp2l d k l : 1 < size d -> (d ^+ k %| d ^+ l) = (k <= l).
Proof.
move=> sd; case: leqP => [|gt_n_m]; first exact: dvdp_exp2l.
have dn0 : d != 0 by rewrite -size_poly_gt0; apply: ltn_trans sd.
rewrite gtNdvdp ?expf_neq0 // polySpred ?expf_neq0 // size_exp /=.
rewrite [size (d ^+ k)]polySpred ?expf_neq0 // size_exp ltnS ltn_mul2l.
by move: sd; rewrite -subn_gt0 subn1; move->.
Qed.
Lemma dvdp_exp2r p q k : p %| q -> p ^+ k %| q ^+ k.
Proof.
case: (eqVneq p 0) => [-> /dvd0pP -> // | pn0].
rewrite dvdp_eq; set c := _ ^+ _; set t := _ %/ _; move/eqP=> e.
apply: (@eq_dvdp (c ^+ k) (t ^+ k)); first by rewrite !expf_neq0 ?lead_coef_eq0.
by rewrite -exprMn -exprZn; congr (_ ^+ k).
Qed.
Lemma dvdp_exp_sub p q k l: p != 0 ->
(p ^+ k %| q * p ^+ l) = (p ^+ (k - l) %| q).
Proof.
move=> pn0; case: (leqP k l)=> [|/ltnW] hkl.
move: (hkl); rewrite -subn_eq0; move/eqP->; rewrite expr0 dvd1p.
exact/dvdp_mull/dvdp_exp2l.
by rewrite -[in LHS](subnK hkl) exprD dvdp_mul2r // expf_eq0 (negPf pn0) andbF.
Qed.
Lemma dvdp_XsubCl p x : ('X - x%:P) %| p = root p x.
Proof. by rewrite dvdpE; apply: Ring.rdvdp_XsubCl. Qed.
Lemma root_dvdp p q x : p %| q -> root p x -> root q x.
Proof. by rewrite -!dvdp_XsubCl => /[swap]; exact: dvdp_trans. Qed.
Lemma polyXsubCP p x : reflect (p.[x] = 0) (('X - x%:P) %| p).
Proof. by rewrite dvdpE; apply: Ring.polyXsubCP. Qed.
Lemma eqp_div_XsubC p c :
(p == (p %/ ('X - c%:P)) * ('X - c%:P)) = ('X - c%:P %| p).
Proof. by rewrite dvdp_eq lead_coefXsubC expr1n scale1r. Qed.
Lemma root_factor_theorem p x : root p x = (('X - x%:P) %| p).
Proof. by rewrite dvdp_XsubCl. Qed.
Lemma uniq_roots_dvdp p rs : all (root p) rs -> uniq_roots rs ->
(\prod_(z <- rs) ('X - z%:P)) %| p.
Proof.
move=> rrs; case/(uniq_roots_prod_XsubC rrs)=> q ->.
by apply: dvdp_mull; rewrite // (eqP (monic_prod_XsubC _)) unitr1.
Qed.
Lemma root_bigmul x (ps : seq {poly R}) :
~~root (\big[*%R/1]_(p <- ps) p) x = all (fun p => ~~ root p x) ps.
Proof.
elim: ps => [|p ps ihp]; first by rewrite big_nil root1.
by rewrite big_cons /= rootM negb_or ihp.
Qed.
Lemma eqpP m n :
reflect (exists2 c12, (c12.1 != 0) && (c12.2 != 0) & c12.1 *: m = c12.2 *: n)
(m %= n).
Proof.
apply: (iffP idP) => [| [[c1 c2]/andP[nz_c1 nz_c2 eq_cmn]]]; last first.
rewrite /eqp (@eq_dvdp c2 c1%:P) -?eq_cmn ?mul_polyC // (@eq_dvdp c1 c2%:P)//.
by rewrite eq_cmn mul_polyC.
case: (eqVneq m 0) => [-> /andP [/dvd0pP -> _] | m_nz].
by exists (1, 1); rewrite ?scaler0 // oner_eq0.
case: (eqVneq n 0) => [-> /andP [_ /dvd0pP ->] | n_nz /andP []].
by exists (1, 1); rewrite ?scaler0 // oner_eq0.
rewrite !dvdp_eq; set c1 := _ ^+ _; set c2 := _ ^+ _.
set q1 := _ %/ _; set q2 := _ %/ _; move/eqP => Hq1 /eqP Hq2;
have Hc1 : c1 != 0 by rewrite expf_eq0 lead_coef_eq0 negb_and m_nz orbT.
have Hc2 : c2 != 0 by rewrite expf_eq0 lead_coef_eq0 negb_and n_nz orbT.
have def_q12: q1 * q2 = (c1 * c2)%:P.
apply: (mulIf m_nz); rewrite mulrAC mulrC -Hq1 -scalerAr -Hq2 scalerA.
by rewrite -mul_polyC.
have: q1 * q2 != 0 by rewrite def_q12 -size_poly_eq0 size_polyC mulf_neq0.
rewrite mulf_eq0; case/norP=> nz_q1 nz_q2.
have: size q2 <= 1.
have:= size_mul nz_q1 nz_q2; rewrite def_q12 size_polyC mulf_neq0 //=.
by rewrite polySpred // => ->; rewrite leq_addl.
rewrite leq_eqVlt ltnS size_poly_leq0 (negPf nz_q2) orbF.
case/size_poly1P=> c cn0 cqe; exists (c2, c); first by rewrite Hc2.
by rewrite Hq2 -mul_polyC -cqe.
Qed.
Lemma eqp_eq p q: p %= q -> (lead_coef q) *: p = (lead_coef p) *: q.
Proof.
move=> /eqpP [[c1 c2] /= /andP [nz_c1 nz_c2]] eq.
have/(congr1 lead_coef) := eq; rewrite !lead_coefZ.
move=> eqC; apply/(@mulfI _ c2%:P); rewrite ?polyC_eq0 //.
by rewrite !mul_polyC scalerA -eqC mulrC -scalerA eq !scalerA mulrC.
Qed.
Lemma eqpxx : reflexive (@eqp R). Proof. by move=> p; rewrite /eqp dvdpp. Qed.
Hint Resolve eqpxx : core.
Lemma eqpW p q : p = q -> p %= q. Proof. by move->; rewrite eqpxx. Qed.
Lemma eqp_sym : symmetric (@eqp R).
Proof. by move=> p q; rewrite /eqp andbC. Qed.
Lemma eqp_trans : transitive (@eqp R).
Proof.
move=> p q r; case/andP=> Dp pD; case/andP=> Dq qD.
by rewrite /eqp (dvdp_trans Dp) // (dvdp_trans qD).
Qed.
Lemma eqp_ltrans : left_transitive (@eqp R).
Proof. exact: sym_left_transitive eqp_sym eqp_trans. Qed.
Lemma eqp_rtrans : right_transitive (@eqp R).
Proof. exact: sym_right_transitive eqp_sym eqp_trans. Qed.
Lemma eqp0 p : (p %= 0) = (p == 0).
Proof. by apply/idP/eqP => [/andP [_ /dvd0pP] | -> //]. Qed.
Lemma eqp01 : 0 %= (1 : {poly R}) = false.
Proof. by rewrite eqp_sym eqp0 oner_eq0. Qed.
Lemma eqp_scale p c : c != 0 -> c *: p %= p.
Proof.
move=> c0; apply/eqpP; exists (1, c); first by rewrite c0 oner_eq0.
by rewrite scale1r.
Qed.
Lemma eqp_size p q : p %= q -> size p = size q.
Proof.
have [->|Eq] := eqVneq q 0; first by rewrite eqp0; move/eqP->.
rewrite eqp_sym; have [->|Ep] := eqVneq p 0; first by rewrite eqp0; move/eqP->.
by case/andP => Dp Dq; apply: anti_leq; rewrite !dvdp_leq.
Qed.
Lemma size_poly_eq1 p : (size p == 1) = (p %= 1).
Proof.
apply/size_poly1P/idP=> [[c cn0 ep] |].
by apply/eqpP; exists (1, c); rewrite ?oner_eq0 // alg_polyC scale1r.
by move/eqp_size; rewrite size_poly1; move/eqP/size_poly1P.
Qed.
Lemma polyXsubC_eqp1 (x : R) : ('X - x%:P %= 1) = false.
Proof. by rewrite -size_poly_eq1 size_XsubC. Qed.
Lemma dvdp_eqp1 p q : p %| q -> q %= 1 -> p %= 1.
Proof.
move=> dpq hq.
have sizeq : size q == 1 by rewrite size_poly_eq1.
have n0q : q != 0 by case: eqP hq => // ->; rewrite eqp01.
rewrite -size_poly_eq1 eqn_leq -{1}(eqP sizeq) dvdp_leq //= size_poly_gt0.
by apply/eqP => p0; move: dpq n0q; rewrite p0 dvd0p => ->.
Qed.
Lemma eqp_dvdr q p d: p %= q -> d %| p = (d %| q).
Proof.
suff Hmn m n: m %= n -> (d %| m) -> (d %| n).
by move=> mn; apply/idP/idP; apply: Hmn=> //; rewrite eqp_sym.
by rewrite /eqp; case/andP=> pq qp dp; apply: (dvdp_trans dp).
Qed.
Lemma eqp_dvdl d2 d1 p : d1 %= d2 -> d1 %| p = (d2 %| p).
suff Hmn m n: m %= n -> (m %| p) -> (n %| p).
by move=> ?; apply/idP/idP; apply: Hmn; rewrite // eqp_sym.
by rewrite /eqp; case/andP=> dd' d'd dp; apply: (dvdp_trans d'd).
Qed.
Lemma dvdpZr c m n : c != 0 -> m %| c *: n = (m %| n).
Proof. by move=> cn0; exact/eqp_dvdr/eqp_scale. Qed.
Lemma dvdpZl c m n : c != 0 -> (c *: m %| n) = (m %| n).
Proof. by move=> cn0; exact/eqp_dvdl/eqp_scale. Qed.
Lemma dvdpNl d p : (- d) %| p = (d %| p).
Proof.
by rewrite -scaleN1r; apply/eqp_dvdl/eqp_scale; rewrite oppr_eq0 oner_neq0.
Qed.
Lemma dvdpNr d p : d %| (- p) = (d %| p).
Proof. by apply: eqp_dvdr; rewrite -scaleN1r eqp_scale ?oppr_eq0 ?oner_eq0. Qed.
Lemma eqp_mul2r r p q : r != 0 -> (p * r %= q * r) = (p %= q).
Proof. by move=> nz_r; rewrite /eqp !dvdp_mul2r. Qed.
Lemma eqp_mul2l r p q: r != 0 -> (r * p %= r * q) = (p %= q).
Proof. by move=> nz_r; rewrite /eqp !dvdp_mul2l. Qed.
Lemma eqp_mull r p q: q %= r -> p * q %= p * r.
Proof.
case/eqpP=> [[c d]] /andP [c0 d0 e]; apply/eqpP; exists (c, d); rewrite ?c0 //.
by rewrite scalerAr e -scalerAr.
Qed.
Lemma eqp_mulr q p r : p %= q -> p * r %= q * r.
Proof. by move=> epq; rewrite ![_ * r]mulrC eqp_mull. Qed.
Lemma eqp_exp p q k : p %= q -> p ^+ k %= q ^+ k.
Proof.
move=> pq; elim: k=> [|k ihk]; first by rewrite !expr0 eqpxx.
by rewrite !exprS (@eqp_trans (q * p ^+ k)) // (eqp_mulr, eqp_mull).
Qed.
Lemma polyC_eqp1 (c : R) : (c%:P %= 1) = (c != 0).
Proof.
apply/eqpP/idP => [[[x y]] |nc0] /=.
case: (eqVneq c) => [->|] //= /andP [_] /negPf <- /eqP.
by rewrite alg_polyC scaler0 eq_sym polyC_eq0.
exists (1, c); first by rewrite nc0 /= oner_neq0.
by rewrite alg_polyC scale1r.
Qed.
Lemma dvdUp d p: d %= 1 -> d %| p.
Proof. by move/eqp_dvdl->; rewrite dvd1p. Qed.
Lemma dvdp_size_eqp p q : p %| q -> size p == size q = (p %= q).
Proof.
move=> pq; apply/idP/idP; last by move/eqp_size->.
have [->|Hq] := eqVneq q 0; first by rewrite size_poly0 size_poly_eq0 eqp0.
have [->|Hp] := eqVneq p 0.
by rewrite size_poly0 eq_sym size_poly_eq0 eqp_sym eqp0.
move: pq; rewrite dvdp_eq; set c := _ ^+ _; set x := _ %/ _; move/eqP=> eqpq.
have /= := congr1 (size \o @polyseq R) eqpq.
have cn0 : c != 0 by rewrite expf_neq0 // lead_coef_eq0.
rewrite (@eqp_size _ q); last exact: eqp_scale.
rewrite size_mul ?p0 // => [-> HH|]; last first.
apply/eqP=> HH; move: eqpq; rewrite HH mul0r.
by move/eqP; rewrite scale_poly_eq0 (negPf Hq) (negPf cn0).
suff: size x == 1%N.
case/size_poly1P=> y H1y H2y.
by apply/eqpP; exists (y, c); rewrite ?H1y // eqpq H2y mul_polyC.
case: (size p) HH (size_poly_eq0 p)=> [|n]; first by case: eqP Hp.
by rewrite addnS -add1n eqn_add2r; move/eqP->.
Qed.
Lemma eqp_root p q : p %= q -> root p =1 root q.
Proof.
move/eqpP=> [[c d]] /andP [c0 d0 e] x; move/negPf:c0=>c0; move/negPf:d0=>d0.
by rewrite rootE -[_==_]orFb -c0 -mulf_eq0 -hornerZ e hornerZ mulf_eq0 d0.
Qed.
Lemma eqp_rmod_mod p q : rmodp p q %= modp p q.
Proof.
rewrite modpE eqp_sym; case: ifP => ulcq //.
apply: eqp_scale; rewrite invr_eq0 //.
by apply: expf_neq0; apply: contraTneq ulcq => ->; rewrite unitr0.
Qed.
Lemma eqp_rdiv_div p q : rdivp p q %= divp p q.
Proof.
rewrite divpE eqp_sym; case: ifP=> ulcq//; apply: eqp_scale; rewrite invr_eq0//.
by apply: expf_neq0; apply: contraTneq ulcq => ->; rewrite unitr0.
Qed.
Lemma dvd_eqp_divl d p q (dvd_dp : d %| q) (eq_pq : p %= q) :
p %/ d %= q %/ d.
Proof.
case: (eqVneq q 0) eq_pq=> [->|q_neq0]; first by rewrite eqp0=> /eqP->.
have d_neq0: d != 0 by apply: contraTneq dvd_dp=> ->; rewrite dvd0p.
move=> eq_pq; rewrite -(@eqp_mul2r d) // !divpK // ?(eqp_dvdr _ eq_pq) //.
rewrite (eqp_ltrans (eqp_scale _ _)) ?lc_expn_scalp_neq0 //.
by rewrite (eqp_rtrans (eqp_scale _ _)) ?lc_expn_scalp_neq0.
Qed.
Definition gcdp p q :=
let: (p1, q1) := if size p < size q then (q, p) else (p, q) in
if p1 == 0 then q1 else
let fix loop (n : nat) (pp qq : {poly R}) {struct n} :=
let rr := modp pp qq in
if rr == 0 then qq else
if n is n1.+1 then loop n1 qq rr else rr in
loop (size p1) p1 q1.
Arguments gcdp : simpl never.
Lemma gcd0p : left_id 0 gcdp.
Proof.
move=> p; rewrite /gcdp size_poly0 size_poly_gt0 if_neg.
case: ifP => /= [_ | nzp]; first by rewrite eqxx.
by rewrite polySpred !(modp0, nzp) //; case: _.-1 => [|m]; rewrite mod0p eqxx.
Qed.
Lemma gcdp0 : right_id 0 gcdp.
Proof.
move=> p; have:= gcd0p p; rewrite /gcdp size_poly0 size_poly_gt0.
by case: eqVneq => //= ->; rewrite eqxx.
Qed.
Lemma gcdpE p q :
gcdp p q = if size p < size q
then gcdp (modp q p) p else gcdp (modp p q) q.
Proof.
pose gcdpE_rec := fix gcdpE_rec (n : nat) (pp qq : {poly R}) {struct n} :=
let rr := modp pp qq in
if rr == 0 then qq else
if n is n1.+1 then gcdpE_rec n1 qq rr else rr.
have Irec: forall k l p q, size q <= k -> size q <= l
-> size q < size p -> gcdpE_rec k p q = gcdpE_rec l p q.
+ elim=> [|m Hrec] [|n] //= p1 q1.
- move/size_poly_leq0P=> -> _; rewrite size_poly0 size_poly_gt0 modp0.
by move/negPf ->; case: n => [|n] /=; rewrite mod0p eqxx.
- move=> _ /size_poly_leq0P ->; rewrite size_poly0 size_poly_gt0 modp0.
by move/negPf ->; case: m {Hrec} => [|m] /=; rewrite mod0p eqxx.
case: eqP => Epq Sm Sn Sq //; have [->|nzq] := eqVneq q1 0.
by case: n m {Sm Sn Hrec} => [|m] [|n] //=; rewrite mod0p eqxx.
apply: Hrec; last by rewrite ltn_modp.
by rewrite -ltnS (leq_trans _ Sm) // ltn_modp.
by rewrite -ltnS (leq_trans _ Sn) // ltn_modp.
have [->|nzp] := eqVneq p 0; first by rewrite mod0p modp0 gcd0p gcdp0 if_same.
have [->|nzq] := eqVneq q 0; first by rewrite mod0p modp0 gcd0p gcdp0 if_same.
rewrite /gcdp !ltn_modp !(negPf nzp, negPf nzq) /=.
have [ltpq|leqp] := ltnP; rewrite !(negPf nzp, negPf nzq) /= polySpred //.
have [->|nzqp] := eqVneq.
by case: (size p) => [|[|s]]; rewrite /= modp0 (negPf nzp) // mod0p eqxx.
apply: Irec => //; last by rewrite ltn_modp.
by rewrite -ltnS -polySpred // (leq_trans _ ltpq) ?leqW // ltn_modp.
by rewrite ltnW // ltn_modp.
case: eqVneq => [->|nzpq].
by case: (size q) => [|[|s]]; rewrite /= modp0 (negPf nzq) // mod0p eqxx.
apply: Irec => //; rewrite ?ltn_modp //.
by rewrite -ltnS -polySpred // (leq_trans _ leqp) // ltn_modp.
by rewrite ltnW // ltn_modp.
Qed.
Lemma size_gcd1p p : size (gcdp 1 p) = 1.
Proof.
rewrite gcdpE size_polyC oner_eq0 /= modp1; have [|/size1_polyC ->] := ltnP.
by rewrite gcd0p size_polyC oner_eq0.
have [->|p00] := eqVneq p`_0 0; first by rewrite modp0 gcdp0 size_poly1.
by rewrite modpC // gcd0p size_polyC p00.
Qed.
Lemma size_gcdp1 p : size (gcdp p 1) = 1.
Proof.
rewrite gcdpE size_polyC oner_eq0 /= modp1 ltnS; case: leqP.
by move/size_poly_leq0P->; rewrite gcdp0 modp0 size_polyC oner_eq0.
by rewrite gcd0p size_polyC oner_eq0.
Qed.
Lemma gcdpp : idempotent_op gcdp.
Proof. by move=> p; rewrite gcdpE ltnn modpp gcd0p. Qed.
Lemma dvdp_gcdlr p q : (gcdp p q %| p) && (gcdp p q %| q).
Proof.
have [r] := ubnP (minn (size q) (size p)); elim: r => // r IHr in p q *.
have [-> | nz_p] := eqVneq p 0; first by rewrite gcd0p dvdpp andbT.
have [-> | nz_q] := eqVneq q 0; first by rewrite gcdp0 dvdpp /=.
rewrite ltnS gcdpE; case: leqP => [le_pq | lt_pq] le_qr.
suffices /IHr/andP[E1 E2]: minn (size q) (size (p %% q)) < r.
by rewrite E2 andbT (dvdp_mod _ E2).
by rewrite gtn_min orbC (leq_trans _ le_qr) ?ltn_modp.
suffices /IHr/andP[E1 E2]: minn (size p) (size (q %% p)) < r.
by rewrite E2 (dvdp_mod _ E2).
by rewrite gtn_min orbC (leq_trans _ le_qr) ?ltn_modp.
Qed.
Lemma dvdp_gcdl p q : gcdp p q %| p. Proof. by case/andP: (dvdp_gcdlr p q). Qed.
Lemma dvdp_gcdr p q :gcdp p q %| q. Proof. by case/andP: (dvdp_gcdlr p q). Qed.
Lemma leq_gcdpl p q : p != 0 -> size (gcdp p q) <= size p.
Proof. by move=> pn0; move: (dvdp_gcdl p q); apply: dvdp_leq. Qed.
Lemma leq_gcdpr p q : q != 0 -> size (gcdp p q) <= size q.
Proof. by move=> qn0; move: (dvdp_gcdr p q); apply: dvdp_leq. Qed.
Lemma dvdp_gcd p m n : p %| gcdp m n = (p %| m) && (p %| n).
Proof.
apply/idP/andP=> [dv_pmn | []].
by rewrite ?(dvdp_trans dv_pmn) ?dvdp_gcdl ?dvdp_gcdr.
have [r] := ubnP (minn (size n) (size m)); elim: r => // r IHr in m n *.
have [-> | nz_m] := eqVneq m 0; first by rewrite gcd0p.
have [-> | nz_n] := eqVneq n 0; first by rewrite gcdp0.
rewrite gcdpE ltnS; case: leqP => [le_nm | lt_mn] le_r dv_m dv_n.
apply: IHr => //; last by rewrite -(dvdp_mod _ dv_n).
by rewrite gtn_min orbC (leq_trans _ le_r) ?ltn_modp.
apply: IHr => //; last by rewrite -(dvdp_mod _ dv_m).
by rewrite gtn_min orbC (leq_trans _ le_r) ?ltn_modp.
Qed.
Lemma gcdpC p q : gcdp p q %= gcdp q p.
Proof. by rewrite /eqp !dvdp_gcd !dvdp_gcdl !dvdp_gcdr. Qed.
Lemma gcd1p p : gcdp 1 p %= 1.
Proof.
rewrite -size_poly_eq1 gcdpE size_poly1; case: ltnP.
by rewrite modp1 gcd0p size_poly1 eqxx.
move/size1_polyC=> e; rewrite e.
have [->|p00] := eqVneq p`_0 0; first by rewrite modp0 gcdp0 size_poly1.
by rewrite modpC // gcd0p size_polyC p00.
Qed.
Lemma gcdp1 p : gcdp p 1 %= 1.
Proof. by rewrite (eqp_ltrans (gcdpC _ _)) gcd1p. Qed.
Lemma gcdp_addl_mul p q r: gcdp r (p * r + q) %= gcdp r q.
Proof.
suff h m n d : gcdp d n %| gcdp d (m * d + n).
apply/andP; split => //.
by rewrite {2}(_: q = (-p) * r + (p * r + q)) ?H // mulNr addKr.
by rewrite dvdp_gcd dvdp_gcdl /= dvdp_addr ?dvdp_gcdr ?dvdp_mull ?dvdp_gcdl.
Qed.
Lemma gcdp_addl m n : gcdp m (m + n) %= gcdp m n.
Proof. by rewrite -[m in m + _]mul1r gcdp_addl_mul. Qed.
Lemma gcdp_addr m n : gcdp m (n + m) %= gcdp m n.
Proof. by rewrite addrC gcdp_addl. Qed.
Lemma gcdp_mull m n : gcdp n (m * n) %= n.
Proof.
have [-> | nn0] := eqVneq n 0; first by rewrite gcd0p mulr0 eqpxx.
have [-> | mn0] := eqVneq m 0; first by rewrite mul0r gcdp0 eqpxx.
rewrite gcdpE modp_mull gcd0p size_mul //; case: leqP; last by rewrite eqpxx.
rewrite (polySpred mn0) addSn /= -[leqRHS]add0n leq_add2r -ltnS.
rewrite -polySpred //= leq_eqVlt ltnS size_poly_leq0 (negPf mn0) orbF.
case/size_poly1P=> c cn0 -> {mn0 m}; rewrite mul_polyC.
suff -> : n %% (c *: n) = 0 by rewrite gcd0p; apply: eqp_scale.
by apply/modp_eq0P; rewrite dvdpZl.
Qed.
Lemma gcdp_mulr m n : gcdp n (n * m) %= n.
Proof. by rewrite mulrC gcdp_mull. Qed.
Lemma gcdp_scalel c m n : c != 0 -> gcdp (c *: m) n %= gcdp m n.
Proof.
move=> cn0; rewrite /eqp dvdp_gcd [gcdp m n %| _]dvdp_gcd !dvdp_gcdr !andbT.
apply/andP; split; last first.
by apply: dvdp_trans (dvdp_gcdl _ _) _; rewrite dvdpZr.
by apply: dvdp_trans (dvdp_gcdl _ _) _; rewrite dvdpZl.
Qed.
Lemma gcdp_scaler c m n : c != 0 -> gcdp m (c *: n) %= gcdp m n.
Proof.
move=> cn0; apply: eqp_trans (gcdpC _ _) _.
by apply: eqp_trans (gcdp_scalel _ _ _) _ => //; apply: gcdpC.
Qed.
Lemma dvdp_gcd_idl m n : m %| n -> gcdp m n %= m.
Proof.
have [-> | mn0] := eqVneq m 0.
by rewrite dvd0p => /eqP ->; rewrite gcdp0 eqpxx.
rewrite dvdp_eq; move/eqP/(f_equal (gcdp m)) => h.
apply: eqp_trans (gcdp_mull (n %/ m) _).
by rewrite -h eqp_sym gcdp_scaler // expf_neq0 // lead_coef_eq0.
Qed.
Lemma dvdp_gcd_idr m n : n %| m -> gcdp m n %= n.
Proof. by move/dvdp_gcd_idl; exact/eqp_trans/gcdpC. Qed.
Lemma gcdp_exp p k l : gcdp (p ^+ k) (p ^+ l) %= p ^+ minn k l.
Proof.
case: leqP => [|/ltnW] /subnK <-; rewrite exprD; first exact: gcdp_mull.
exact/(eqp_trans (gcdpC _ _))/gcdp_mull.
Qed.
Lemma gcdp_eq0 p q : gcdp p q == 0 = (p == 0) && (q == 0).
Proof.
apply/idP/idP; last by case/andP => /eqP -> /eqP ->; rewrite gcdp0.
have h m n: gcdp m n == 0 -> (m == 0).
by rewrite -(dvd0p m); move/eqP<-; rewrite dvdp_gcdl.
by move=> ?; rewrite (h _ q) // (h _ p) // -eqp0 (eqp_ltrans (gcdpC _ _)) eqp0.
Qed.
Lemma eqp_gcdr p q r : q %= r -> gcdp p q %= gcdp p r.
Proof.
move=> eqr; rewrite /eqp !(dvdp_gcd, dvdp_gcdl, andbT) /=.
by rewrite -(eqp_dvdr _ eqr) dvdp_gcdr (eqp_dvdr _ eqr) dvdp_gcdr.
Qed.
Lemma eqp_gcdl r p q : p %= q -> gcdp p r %= gcdp q r.
Proof.
move=> eqr; rewrite /eqp !(dvdp_gcd, dvdp_gcdr, andbT) /=.
by rewrite -(eqp_dvdr _ eqr) dvdp_gcdl (eqp_dvdr _ eqr) dvdp_gcdl.
Qed.
Lemma eqp_gcd p1 p2 q1 q2 : p1 %= p2 -> q1 %= q2 -> gcdp p1 q1 %= gcdp p2 q2.
Proof. move=> e1 e2; exact: eqp_trans (eqp_gcdr _ e2) (eqp_gcdl _ e1). Qed.
Lemma eqp_rgcd_gcd p q : rgcdp p q %= gcdp p q.
Proof.
move: {2}(minn (size p) (size q)) (leqnn (minn (size p) (size q))) => n.
elim: n p q => [p q|n ihn p q hs].
rewrite leqn0; case: ltnP => _; rewrite size_poly_eq0; move/eqP->.
by rewrite gcd0p rgcd0p eqpxx.
by rewrite gcdp0 rgcdp0 eqpxx.
have [-> | pn0] := eqVneq p 0; first by rewrite gcd0p rgcd0p eqpxx.
have [-> | qn0] := eqVneq q 0; first by rewrite gcdp0 rgcdp0 eqpxx.
rewrite gcdpE rgcdpE; case: ltnP hs => sp hs.
have e := eqp_rmod_mod q p; apply/eqp_trans/ihn: (eqp_gcdl p e).
by rewrite (eqp_size e) geq_min -ltnS (leq_trans _ hs) ?ltn_modp.
have e := eqp_rmod_mod p q; apply/eqp_trans/ihn: (eqp_gcdl q e).
by rewrite (eqp_size e) geq_min -ltnS (leq_trans _ hs) ?ltn_modp.
Qed.
Lemma gcdp_modl m n : gcdp (m %% n) n %= gcdp m n.
Proof.
have [/modp_small -> // | lenm] := ltnP (size m) (size n).
by rewrite (gcdpE m n) ltnNge lenm.
Qed.
Lemma gcdp_modr m n : gcdp m (n %% m) %= gcdp m n.
Proof.
apply: eqp_trans (gcdpC _ _); apply: eqp_trans (gcdp_modl _ _); exact: gcdpC.
Qed.
Lemma gcdp_def d m n :
d %| m -> d %| n -> (forall d', d' %| m -> d' %| n -> d' %| d) ->
gcdp m n %= d.
Proof.
move=> dm dn h; rewrite /eqp dvdp_gcd dm dn !andbT.
by apply: h; rewrite (dvdp_gcdl, dvdp_gcdr).
Qed.
Definition coprimep p q := size (gcdp p q) == 1%N.
Lemma coprimep_size_gcd p q : coprimep p q -> size (gcdp p q) = 1.
Proof. by rewrite /coprimep=> /eqP. Qed.
Lemma coprimep_def p q : coprimep p q = (size (gcdp p q) == 1).
Proof. done. Qed.
Lemma coprimepZl c m n : c != 0 -> coprimep (c *: m) n = coprimep m n.
Proof. by move=> ?; rewrite !coprimep_def (eqp_size (gcdp_scalel _ _ _)). Qed.
Lemma coprimepZr c m n: c != 0 -> coprimep m (c *: n) = coprimep m n.
Proof. by move=> ?; rewrite !coprimep_def (eqp_size (gcdp_scaler _ _ _)). Qed.
Lemma coprimepp p : coprimep p p = (size p == 1).
Proof. by rewrite coprimep_def gcdpp. Qed.
Lemma gcdp_eqp1 p q : gcdp p q %= 1 = coprimep p q.
Proof. by rewrite coprimep_def size_poly_eq1. Qed.
Lemma coprimep_sym p q : coprimep p q = coprimep q p.
Proof. by rewrite -!gcdp_eqp1; apply: eqp_ltrans; rewrite gcdpC. Qed.
Lemma coprime1p p : coprimep 1 p.
Proof. by rewrite /coprimep -[1%N](size_poly1 R); exact/eqP/eqp_size/gcd1p. Qed.
Lemma coprimep1 p : coprimep p 1.
Proof. by rewrite coprimep_sym; apply: coprime1p. Qed.
Lemma coprimep0 p : coprimep p 0 = (p %= 1).
Proof. by rewrite /coprimep gcdp0 size_poly_eq1. Qed.
Lemma coprime0p p : coprimep 0 p = (p %= 1).
Proof. by rewrite coprimep_sym coprimep0. Qed.
(* This is different from coprimeP in div. shall we keep this? *)
Lemma coprimepP p q :
reflect (forall d, d %| p -> d %| q -> d %= 1) (coprimep p q).
Proof.
rewrite /coprimep; apply: (iffP idP) => [/eqP hs d dvddp dvddq | h].
have/dvdp_eqp1: d %| gcdp p q by rewrite dvdp_gcd dvddp dvddq.
by rewrite -size_poly_eq1 hs; exact.
by rewrite size_poly_eq1; case/andP: (dvdp_gcdlr p q); apply: h.
Qed.
Lemma coprimepPn p q : p != 0 ->
reflect (exists d, (d %| gcdp p q) && ~~ (d %= 1)) (~~ coprimep p q).
Proof.
move=> p0; apply: (iffP idP).
by rewrite -gcdp_eqp1=> ng1; exists (gcdp p q); rewrite dvdpp /=.
case=> d /andP [dg]; apply: contra; rewrite -gcdp_eqp1=> g1.
by move: dg; rewrite (eqp_dvdr _ g1) dvdp1 size_poly_eq1.
Qed.
Lemma coprimep_dvdl q p r : r %| q -> coprimep p q -> coprimep p r.
Proof.
move=> rp /coprimepP cpq'; apply/coprimepP => d dp dr.
exact/cpq'/(dvdp_trans dr).
Qed.
Lemma coprimep_dvdr p q r : r %| p -> coprimep p q -> coprimep r q.
Proof.
by move=> rp; rewrite ![coprimep _ q]coprimep_sym; apply/coprimep_dvdl.
Qed.
Lemma coprimep_modl p q : coprimep (p %% q) q = coprimep p q.
Proof.
rewrite !coprimep_def [in RHS]gcdpE.
by case: ltnP => // hpq; rewrite modp_small // gcdpE hpq.
Qed.
Lemma coprimep_modr q p : coprimep q (p %% q) = coprimep q p.
Proof. by rewrite ![coprimep q _]coprimep_sym coprimep_modl. Qed.
Lemma rcoprimep_coprimep q p : rcoprimep q p = coprimep q p.
Proof. by rewrite /coprimep /rcoprimep (eqp_size (eqp_rgcd_gcd _ _)). Qed.
Lemma eqp_coprimepr p q r : q %= r -> coprimep p q = coprimep p r.
Proof. by rewrite -!gcdp_eqp1; move/(eqp_gcdr p)/eqp_ltrans. Qed.
Lemma eqp_coprimepl p q r : q %= r -> coprimep q p = coprimep r p.
Proof. by rewrite !(coprimep_sym _ p); apply: eqp_coprimepr. Qed.
(* This should be implemented with an extended remainder sequence *)
Fixpoint egcdp_rec p q k {struct k} : {poly R} * {poly R} :=
if k is k'.+1 then
if q == 0 then (1, 0) else
let: (u, v) := egcdp_rec q (p %% q) k' in
(lead_coef q ^+ scalp p q *: v, (u - v * (p %/ q)))
else (1, 0).
Definition egcdp p q :=
if size q <= size p then egcdp_rec p q (size q)
else let e := egcdp_rec q p (size p) in (e.2, e.1).
(* No provable egcd0p *)
Lemma egcdp0 p : egcdp p 0 = (1, 0). Proof. by rewrite /egcdp size_poly0. Qed.
Lemma egcdp_recP : forall k p q, q != 0 -> size q <= k -> size q <= size p ->
let e := (egcdp_rec p q k) in
[/\ size e.1 <= size q, size e.2 <= size p & gcdp p q %= e.1 * p + e.2 * q].
Proof.
elim=> [|k ihk] p q /= qn0; first by rewrite size_poly_leq0 (negPf qn0).
move=> sqSn qsp; rewrite (negPf qn0).
have sp : size p > 0 by apply: leq_trans qsp; rewrite size_poly_gt0.
have [r0 | rn0] /= := eqVneq (p %%q) 0.
rewrite r0 /egcdp_rec; case: k ihk sqSn => [|n] ihn sqSn /=.
rewrite !scaler0 !mul0r subr0 add0r mul1r size_poly0 size_poly1.
by rewrite dvdp_gcd_idr /dvdp ?r0.
rewrite !eqxx mul0r scaler0 /= mul0r add0r subr0 mul1r size_poly0 size_poly1.
by rewrite dvdp_gcd_idr /dvdp ?r0 //.
have h1 : size (p %% q) <= k.
by rewrite -ltnS; apply: leq_trans sqSn; rewrite ltn_modp.
have h2 : size (p %% q) <= size q by rewrite ltnW // ltn_modp.
have := ihk q (p %% q) rn0 h1 h2.
case: (egcdp_rec _ _)=> u v /= => [[ihn'1 ihn'2 ihn'3]].
rewrite gcdpE ltnNge qsp //= (eqp_ltrans (gcdpC _ _)); split; last first.
- apply: (eqp_trans ihn'3).
rewrite mulrBl addrCA -scalerAl scalerAr -mulrA -mulrBr.
by rewrite divp_eq addrAC subrr add0r eqpxx.
- apply: (leq_trans (size_polyD _ _)).
have [-> | vn0] := eqVneq v 0.
rewrite mul0r size_polyN size_poly0 maxn0; apply: leq_trans ihn'1 _.
exact: leq_modp.
have [-> | qqn0] := eqVneq (p %/ q) 0.
rewrite mulr0 size_polyN size_poly0 maxn0; apply: leq_trans ihn'1 _.
exact: leq_modp.
rewrite geq_max (leq_trans ihn'1) ?leq_modp //= size_polyN size_mul //.
move: (ihn'2); rewrite (polySpred vn0) (polySpred qn0).
rewrite -(ltn_add2r (size (p %/ q))) !addSn /= ltnS; move/leq_trans; apply.
rewrite size_divp // addnBA ?addKn //.
by apply: leq_trans qsp; apply: leq_pred.
- by rewrite size_scale // lc_expn_scalp_neq0.
Qed.
Lemma egcdpP p q : p != 0 -> q != 0 -> forall (e := egcdp p q),
[/\ size e.1 <= size q, size e.2 <= size p & gcdp p q %= e.1 * p + e.2 * q].
Proof.
rewrite /egcdp => pn0 qn0; case: (leqP (size q) (size p)) => /= [|/ltnW] hp.
exact: egcdp_recP.
case: (egcdp_recP pn0 (leqnn (size p)) hp) => h1 h2 h3; split => //.
by rewrite (eqp_ltrans (gcdpC _ _)) addrC.
Qed.
Lemma egcdpE p q (e := egcdp p q) : gcdp p q %= e.1 * p + e.2 * q.
Proof.
rewrite {}/e; have [-> /= | qn0] := eqVneq q 0.
by rewrite gcdp0 egcdp0 mul1r mulr0 addr0.
have [-> | pn0] := eqVneq p 0; last by case: (egcdpP pn0 qn0).
by rewrite gcd0p /egcdp size_poly0 size_poly_leq0 (negPf qn0) /= !simp.
Qed.
Lemma Bezoutp p q : exists u, u.1 * p + u.2 * q %= (gcdp p q).
Proof.
have [-> | pn0] := eqVneq p 0.
by rewrite gcd0p; exists (0, 1); rewrite mul0r mul1r add0r.
have [-> | qn0] := eqVneq q 0.
by rewrite gcdp0; exists (1, 0); rewrite mul0r mul1r addr0.
pose e := egcdp p q; exists e; rewrite eqp_sym.
by case: (egcdpP pn0 qn0).
Qed.
Lemma Bezout_coprimepP p q :
reflect (exists u, u.1 * p + u.2 * q %= 1) (coprimep p q).
Proof.
rewrite -gcdp_eqp1; apply: (iffP idP)=> [g1|].
by case: (Bezoutp p q) => [[u v] Puv]; exists (u, v); apply: eqp_trans g1.
case=> [[u v]]; rewrite eqp_sym=> Puv; rewrite /eqp (eqp_dvdr _ Puv).
by rewrite dvdp_addr dvdp_mull ?dvdp_gcdl ?dvdp_gcdr //= dvd1p.
Qed.
Lemma coprimep_root p q x : coprimep p q -> root p x -> q.[x] != 0.
Proof.
case/Bezout_coprimepP=> [[u v] euv] px0.
move/eqpP: euv => [[c1 c2]] /andP /= [c1n0 c2n0 e].
suffices: c1 * (v.[x] * q.[x]) != 0.
by rewrite !mulf_eq0 !negb_or c1n0 /=; case/andP.
have := f_equal (horner^~ x) e; rewrite /= !hornerZ hornerD.
by rewrite !hornerM (eqP px0) mulr0 add0r hornerC mulr1; move->.
Qed.
Lemma Gauss_dvdpl p q d: coprimep d q -> (d %| p * q) = (d %| p).
Proof.
move/Bezout_coprimepP=>[[u v] Puv]; apply/idP/idP; last exact: dvdp_mulr.
move/(eqp_mull p): Puv; rewrite mulr1 mulrDr eqp_sym=> peq dpq.
rewrite (eqp_dvdr _ peq) dvdp_addr; first by rewrite mulrA mulrAC dvdp_mulr.
by rewrite mulrA dvdp_mull ?dvdpp.
Qed.
Lemma Gauss_dvdpr p q d: coprimep d q -> (d %| q * p) = (d %| p).
Proof. by rewrite mulrC; apply: Gauss_dvdpl. Qed.
(* This could be simplified with the introduction of lcmp *)
Lemma Gauss_dvdp m n p : coprimep m n -> (m * n %| p) = (m %| p) && (n %| p).
Proof.
have [-> | mn0] := eqVneq m 0.
by rewrite coprime0p => /eqp_dvdl->; rewrite !mul0r dvd0p dvd1p andbT.
have [-> | nn0] := eqVneq n 0.
by rewrite coprimep0 => /eqp_dvdl->; rewrite !mulr0 dvd1p.
move=> hc; apply/idP/idP => [mnmp | /andP [dmp dnp]].
move/Gauss_dvdpl: hc => <-; move: (dvdp_mull m mnmp); rewrite dvdp_mul2l //.
move->; move: (dvdp_mulr n mnmp); rewrite dvdp_mul2r // andbT.
exact: dvdp_mulr.
move: (dnp); rewrite dvdp_eq.
set c2 := _ ^+ _; set q2 := _ %/ _; move/eqP=> e2.
have/esym := Gauss_dvdpl q2 hc; rewrite -e2.
have -> : m %| c2 *: p by rewrite -mul_polyC dvdp_mull.
rewrite dvdp_eq; set c3 := _ ^+ _; set q3 := _ %/ _; move/eqP=> e3.
apply: (@eq_dvdp (c3 * c2) q3).
by rewrite mulf_neq0 // expf_neq0 // lead_coef_eq0.
by rewrite mulrA -e3 -scalerAl -e2 scalerA.
Qed.
Lemma Gauss_gcdpr p m n : coprimep p m -> gcdp p (m * n) %= gcdp p n.
Proof.
move=> co_pm; apply/eqP; rewrite /eqp !dvdp_gcd !dvdp_gcdl /= andbC.
rewrite dvdp_mull ?dvdp_gcdr // -(@Gauss_dvdpl _ m).
by rewrite mulrC dvdp_gcdr.
apply/coprimepP=> d; rewrite dvdp_gcd; case/andP=> hdp _ hdm.
by move/coprimepP: co_pm; apply.
Qed.
Lemma Gauss_gcdpl p m n : coprimep p n -> gcdp p (m * n) %= gcdp p m.
Proof. by move=> co_pn; rewrite mulrC Gauss_gcdpr. Qed.
Lemma coprimepMr p q r : coprimep p (q * r) = (coprimep p q && coprimep p r).
Proof.
apply/coprimepP/andP=> [hp | [/coprimepP-hq hr]].
by split; apply/coprimepP=> d dp dq; rewrite hp //;
[apply/dvdp_mulr | apply/dvdp_mull].
move=> d dp dqr; move/(_ _ dp) in hq.
rewrite Gauss_dvdpl in dqr; first exact: hq.
by move/coprimep_dvdr: hr; apply.
Qed.
Lemma coprimepMl p q r: coprimep (q * r) p = (coprimep q p && coprimep r p).
Proof. by rewrite ![coprimep _ p]coprimep_sym coprimepMr. Qed.
Lemma modp_coprime k u n : k != 0 -> (k * u) %% n %= 1 -> coprimep k n.
Proof.
move=> kn0 hmod; apply/Bezout_coprimepP.
exists (((lead_coef n)^+(scalp (k * u) n) *: u), (- (k * u %/ n))).
rewrite -scalerAl mulrC (divp_eq (u * k) n) mulNr -addrAC subrr add0r.
by rewrite mulrC.
Qed.
Lemma coprimep_pexpl k m n : 0 < k -> coprimep (m ^+ k) n = coprimep m n.
Proof.
case: k => // k _; elim: k => [|k IHk]; first by rewrite expr1.
by rewrite exprS coprimepMl -IHk andbb.
Qed.
Lemma coprimep_pexpr k m n : 0 < k -> coprimep m (n ^+ k) = coprimep m n.
Proof. by move=> k_gt0; rewrite !(coprimep_sym m) coprimep_pexpl. Qed.
Lemma coprimep_expl k m n : coprimep m n -> coprimep (m ^+ k) n.
Proof. by case: k => [|k] co_pm; rewrite ?coprime1p // coprimep_pexpl. Qed.
Lemma coprimep_expr k m n : coprimep m n -> coprimep m (n ^+ k).
Proof. by rewrite !(coprimep_sym m); apply: coprimep_expl. Qed.
Lemma gcdp_mul2l p q r : gcdp (p * q) (p * r) %= (p * gcdp q r).
Proof.
have [->|hp] := eqVneq p 0; first by rewrite !mul0r gcdp0 eqpxx.
rewrite /eqp !dvdp_gcd !dvdp_mul2l // dvdp_gcdr dvdp_gcdl !andbT.
move: (Bezoutp q r) => [[u v]] huv.
rewrite eqp_sym in huv; rewrite (eqp_dvdr _ (eqp_mull _ huv)).
rewrite mulrDr ![p * (_ * _)]mulrCA.
by apply: dvdp_add; rewrite dvdp_mull// (dvdp_gcdr, dvdp_gcdl).
Qed.
Lemma gcdp_mul2r q r p : gcdp (q * p) (r * p) %= gcdp q r * p.
Proof. by rewrite ![_ * p]mulrC gcdp_mul2l. Qed.
Lemma mulp_gcdr p q r : r * (gcdp p q) %= gcdp (r * p) (r * q).
Proof. by rewrite eqp_sym gcdp_mul2l. Qed.
Lemma mulp_gcdl p q r : (gcdp p q) * r %= gcdp (p * r) (q * r).
Proof. by rewrite eqp_sym gcdp_mul2r. Qed.
Lemma coprimep_div_gcd p q : (p != 0) || (q != 0) ->
coprimep (p %/ (gcdp p q)) (q %/ gcdp p q).
Proof.
rewrite -negb_and -gcdp_eq0 -gcdp_eqp1 => gpq0.
rewrite -(@eqp_mul2r (gcdp p q)) // mul1r (eqp_ltrans (mulp_gcdl _ _ _)).
have: gcdp p q %| p by rewrite dvdp_gcdl.
have: gcdp p q %| q by rewrite dvdp_gcdr.
rewrite !dvdp_eq => /eqP <- /eqP <-.
have lcn0 k : (lead_coef (gcdp p q)) ^+ k != 0.
by rewrite expf_neq0 ?lead_coef_eq0.
by apply: eqp_gcd; rewrite ?eqp_scale.
Qed.
Lemma divp_eq0 p q : (p %/ q == 0) = [|| p == 0, q ==0 | size p < size q].
Proof.
apply/eqP/idP=> [d0|]; last first.
case/or3P; [by move/eqP->; rewrite div0p| by move/eqP->; rewrite divp0|].
by move/divp_small.
case: eqVneq => // _; case: eqVneq => // qn0.
move: (divp_eq p q); rewrite d0 mul0r add0r.
move/(f_equal (fun x : {poly R} => size x)).
by rewrite size_scale ?lc_expn_scalp_neq0 // => ->; rewrite ltn_modp qn0 !orbT.
Qed.
Lemma dvdp_div_eq0 p q : q %| p -> (p %/ q == 0) = (p == 0).
Proof.
move=> dvdp_qp; have [->|p_neq0] := eqVneq p 0; first by rewrite div0p eqxx.
rewrite divp_eq0 ltnNge dvdp_leq // (negPf p_neq0) orbF /=.
by apply: contraTF dvdp_qp=> /eqP ->; rewrite dvd0p.
Qed.
Lemma Bezout_coprimepPn p q : p != 0 -> q != 0 ->
reflect (exists2 uv : {poly R} * {poly R},
(0 < size uv.1 < size q) && (0 < size uv.2 < size p) &
uv.1 * p = uv.2 * q)
(~~ (coprimep p q)).
Proof.
move=> pn0 qn0; apply: (iffP idP); last first.
case=> [[u v] /= /andP [/andP [ps1 s1] /andP [ps2 s2]] e].
have: ~~(size (q * p) <= size (u * p)).
rewrite -ltnNge !size_mul // -?size_poly_gt0 // (polySpred pn0) !addnS.
by rewrite ltn_add2r.
apply: contra => ?; apply: dvdp_leq; rewrite ?mulf_neq0 // -?size_poly_gt0 //.
by rewrite mulrC Gauss_dvdp // dvdp_mull // e dvdp_mull.
rewrite coprimep_def neq_ltn ltnS size_poly_leq0 gcdp_eq0.
rewrite (negPf pn0) (negPf qn0) /=.
case sg: (size (gcdp p q)) => [|n] //; case: n sg=> [|n] // sg _.
move: (dvdp_gcdl p q); rewrite dvdp_eq; set c1 := _ ^+ _; move/eqP=> hu1.
move: (dvdp_gcdr p q); rewrite dvdp_eq; set c2 := _ ^+ _; move/eqP=> hv1.
exists (c1 *: (q %/ gcdp p q), c2 *: (p %/ gcdp p q)); last first.
by rewrite -!scalerAl !scalerAr hu1 hv1 mulrCA.
rewrite !size_scale ?lc_expn_scalp_neq0 //= !size_poly_gt0 !divp_eq0.
rewrite gcdp_eq0 !(negPf pn0) !(negPf qn0) /= -!leqNgt leq_gcdpl //.
rewrite leq_gcdpr //= !ltn_divpl -?size_poly_eq0 ?sg //.
rewrite !size_mul // -?size_poly_eq0 ?sg // ![(_ + n.+2)%N]addnS /=.
by rewrite -!(addn1 (size _)) !leq_add2l.
Qed.
Lemma dvdp_pexp2r m n k : k > 0 -> (m ^+ k %| n ^+ k) = (m %| n).
Proof.
move=> k_gt0; apply/idP/idP; last exact: dvdp_exp2r.
have [-> // | nn0] := eqVneq n 0; have [-> | mn0] := eqVneq m 0.
move/prednK: k_gt0=> {1}<-; rewrite exprS mul0r //= !dvd0p expf_eq0.
by case/andP=> _ ->.
set d := gcdp m n; have := dvdp_gcdr m n; rewrite -/d dvdp_eq.
set c1 := _ ^+ _; set n' := _ %/ _; move/eqP=> def_n.
have := dvdp_gcdl m n; rewrite -/d dvdp_eq.
set c2 := _ ^+ _; set m' := _ %/ _; move/eqP=> def_m.
have dn0 : d != 0 by rewrite gcdp_eq0 negb_and nn0 orbT.
have c1n0 : c1 != 0 by rewrite !expf_neq0 // lead_coef_eq0.
have c2n0 : c2 != 0 by rewrite !expf_neq0 // lead_coef_eq0.
have c2k_n0 : c2 ^+ k != 0 by rewrite !expf_neq0 // lead_coef_eq0.
rewrite -(@dvdpZr (c1 ^+ k)) ?expf_neq0 ?lead_coef_eq0 //.
rewrite -(@dvdpZl (c2 ^+ k)) // -!exprZn def_m def_n !exprMn.
rewrite dvdp_mul2r ?expf_neq0 //.
have: coprimep (m' ^+ k) (n' ^+ k).
by rewrite coprimep_pexpl // coprimep_pexpr // coprimep_div_gcd ?mn0.
move/coprimepP=> hc hd.
have /size_poly1P [c cn0 em'] : size m' == 1.
case: (eqVneq m' 0) def_m => [-> /eqP | m'_n0 def_m].
by rewrite mul0r scale_poly_eq0 (negPf mn0) (negPf c2n0).
have := hc _ (dvdpp _) hd; rewrite -size_poly_eq1.
rewrite polySpred; last by rewrite expf_eq0 negb_and m'_n0 orbT.
by rewrite size_exp eqSS muln_eq0 orbC eqn0Ngt k_gt0 /= -eqSS -polySpred.
rewrite -(@dvdpZl c2) // def_m em' mul_polyC dvdpZl //.
by rewrite -(@dvdpZr c1) // def_n dvdp_mull.
Qed.
Lemma root_gcd p q x : root (gcdp p q) x = root p x && root q x.
Proof.
rewrite /= !root_factor_theorem; apply/idP/andP=> [dg| [dp dq]].
by split; apply: dvdp_trans dg _; rewrite ?(dvdp_gcdl, dvdp_gcdr).
have:= Bezoutp p q => [[[u v]]]; rewrite eqp_sym=> e.
by rewrite (eqp_dvdr _ e) dvdp_addl dvdp_mull.
Qed.
Lemma root_biggcd x (ps : seq {poly R}) :
root (\big[gcdp/0]_(p <- ps) p) x = all (fun p => root p x) ps.
Proof.
elim: ps => [|p ps ihp]; first by rewrite big_nil root0.
by rewrite big_cons /= root_gcd ihp.
Qed.
(* "gdcop Q P" is the Greatest Divisor of P which is coprime to Q *)
(* if P null, we pose that gdcop returns 1 if Q null, 0 otherwise*)
Fixpoint gdcop_rec q p k :=
if k is m.+1 then
if coprimep p q then p
else gdcop_rec q (divp p (gcdp p q)) m
else (q == 0)%:R.
Definition gdcop q p := gdcop_rec q p (size p).
Variant gdcop_spec q p : {poly R} -> Type :=
GdcopSpec r of (dvdp r p) & ((coprimep r q) || (p == 0))
& (forall d, dvdp d p -> coprimep d q -> dvdp d r)
: gdcop_spec q p r.
Lemma gdcop0 q : gdcop q 0 = (q == 0)%:R.
Proof. by rewrite /gdcop size_poly0. Qed.
Lemma gdcop_recP q p k : size p <= k -> gdcop_spec q p (gdcop_rec q p k).
Proof.
elim: k p => [p | k ihk p] /=.
move/size_poly_leq0P->.
have [->|q0] := eqVneq; split; rewrite ?coprime1p // ?eqxx ?orbT //.
by move=> d _; rewrite coprimep0 dvdp1 size_poly_eq1.
move=> hs; case cop : (coprimep _ _); first by split; rewrite ?dvdpp ?cop.
have [-> | p0] := eqVneq p 0.
by rewrite div0p; apply: ihk; rewrite size_poly0 leq0n.
have [-> | q0] := eqVneq q 0.
rewrite gcdp0 divpp ?p0 //= => {hs ihk}; case: k=> /=.
rewrite eqxx; split; rewrite ?dvd1p ?coprimep0 ?eqpxx //=.
by move=> d _; rewrite coprimep0 dvdp1 size_poly_eq1.
move=> n; rewrite coprimep0 polyC_eqp1 //; rewrite lc_expn_scalp_neq0.
split; first by rewrite (@eqp_dvdl 1) ?dvd1p // polyC_eqp1 lc_expn_scalp_neq0.
by rewrite coprimep0 polyC_eqp1 // ?lc_expn_scalp_neq0.
by move=> d _; rewrite coprimep0; move/eqp_dvdl->; rewrite dvd1p.
move: (dvdp_gcdl p q); rewrite dvdp_eq; move/eqP=> e.
have sgp : size (gcdp p q) <= size p.
by apply: dvdp_leq; rewrite ?gcdp_eq0 ?p0 ?q0 // dvdp_gcdl.
have : p %/ gcdp p q != 0; last move/negPf=>p'n0.
apply: dvdpN0 (dvdp_mulIl (p %/ gcdp p q) (gcdp p q)) _.
by rewrite -e scale_poly_eq0 negb_or lc_expn_scalp_neq0.
have gn0 : gcdp p q != 0.
apply: dvdpN0 (dvdp_mulIr (p %/ gcdp p q) (gcdp p q)) _.
by rewrite -e scale_poly_eq0 negb_or lc_expn_scalp_neq0.
have sp' : size (p %/ (gcdp p q)) <= k.
rewrite size_divp ?sgp // leq_subLR (leq_trans hs) // -add1n leq_add2r -subn1.
by rewrite ltn_subRL add1n ltn_neqAle eq_sym [_ == _]cop size_poly_gt0 gn0.
case (ihk _ sp')=> r' dr'p'; first rewrite p'n0 orbF=> cr'q maxr'.
constructor=> //=; rewrite ?(negPf p0) ?orbF //.
exact/(dvdp_trans dr'p')/divp_dvd/dvdp_gcdl.
move=> d dp cdq; apply: maxr'; last by rewrite cdq.
case dpq: (d %| gcdp p q).
move: (dpq); rewrite dvdp_gcd dp /= => dq; apply: dvdUp.
apply: contraLR cdq => nd1; apply/coprimepPn; last first.
by exists d; rewrite dvdp_gcd dvdpp dq nd1.
by apply: contraNneq p0 => d0; move: dp; rewrite d0 dvd0p.
apply: contraLR dp => ndp'.
rewrite (@eqp_dvdr ((lead_coef (gcdp p q) ^+ scalp p (gcdp p q))*:p)).
by rewrite e; rewrite Gauss_dvdpl //; apply: (coprimep_dvdl (dvdp_gcdr _ _)).
by rewrite eqp_sym eqp_scale // lc_expn_scalp_neq0.
Qed.
Lemma gdcopP q p : gdcop_spec q p (gdcop q p).
Proof. by rewrite /gdcop; apply: gdcop_recP. Qed.
Lemma coprimep_gdco p q : (q != 0)%B -> coprimep (gdcop p q) p.
Proof. by move=> q_neq0; case: gdcopP=> d; rewrite (negPf q_neq0) orbF. Qed.
Lemma size2_dvdp_gdco p q d : p != 0 -> size d = 2 ->
(d %| (gdcop q p)) = (d %| p) && ~~(d %| q).
Proof.
have [-> | dn0] := eqVneq d 0; first by rewrite size_poly0.
move=> p0 sd; apply/idP/idP.
case: gdcopP=> r rp crq maxr dr; move/negPf: (p0)=> p0f.
rewrite (dvdp_trans dr) //=.
apply: contraL crq => dq; rewrite p0f orbF; apply/coprimepPn.
by apply: contraNneq p0 => r0; move: rp; rewrite r0 dvd0p.
by exists d; rewrite dvdp_gcd dr dq -size_poly_eq1 sd.
case/andP=> dp dq; case: gdcopP=> r rp crq maxr; apply: maxr=> //.
apply/coprimepP=> x xd xq.
move: (dvdp_leq dn0 xd); rewrite leq_eqVlt sd; case/orP; last first.
rewrite ltnS leq_eqVlt ltnS size_poly_leq0 orbC.
case/predU1P => [x0|]; last by rewrite -size_poly_eq1.
by move: xd; rewrite x0 dvd0p (negPf dn0).
by rewrite -sd dvdp_size_eqp //; move/(eqp_dvdl q); rewrite xq (negPf dq).
Qed.
Lemma dvdp_gdco p q : (gdcop p q) %| q. Proof. by case: gdcopP. Qed.
Lemma root_gdco p q x : p != 0 -> root (gdcop q p) x = root p x && ~~(root q x).
Proof.
move=> p0 /=; rewrite !root_factor_theorem.
apply: size2_dvdp_gdco; rewrite ?p0 //.
by rewrite size_polyDl size_polyX // size_polyN size_polyC ltnS; case: (x != 0).
Qed.
Lemma dvdp_comp_poly r p q : (p %| q) -> (p \Po r) %| (q \Po r).
Proof.
have [-> | pn0] := eqVneq p 0.
by rewrite comp_poly0 !dvd0p; move/eqP->; rewrite comp_poly0.
rewrite dvdp_eq; set c := _ ^+ _; set s := _ %/ _; move/eqP=> Hq.
apply: (@eq_dvdp c (s \Po r)); first by rewrite expf_neq0 // lead_coef_eq0.
by rewrite -comp_polyZ Hq comp_polyM.
Qed.
Lemma gcdp_comp_poly r p q : gcdp p q \Po r %= gcdp (p \Po r) (q \Po r).
Proof.
apply/andP; split.
by rewrite dvdp_gcd !dvdp_comp_poly ?dvdp_gcdl ?dvdp_gcdr.
case: (Bezoutp p q) => [[u v]] /andP [].
move/(dvdp_comp_poly r) => Huv _.
rewrite (dvdp_trans _ Huv) // comp_polyD !comp_polyM.
by rewrite dvdp_add // dvdp_mull //; [ exact: dvdp_gcdl | exact: dvdp_gcdr].
Qed.
Lemma coprimep_comp_poly r p q : coprimep p q -> coprimep (p \Po r) (q \Po r).
Proof.
rewrite -!gcdp_eqp1 -!size_poly_eq1 -!dvdp1; move/(dvdp_comp_poly r).
rewrite comp_polyC => Hgcd.
by apply: dvdp_trans Hgcd; case/andP: (gcdp_comp_poly r p q).
Qed.
Lemma coprimep_addl_mul p q r : coprimep r (p * r + q) = coprimep r q.
Proof. by rewrite !coprimep_def (eqp_size (gcdp_addl_mul _ _ _)). Qed.
Definition irreducible_poly p :=
(size p > 1) * (forall q, size q != 1 -> q %| p -> q %= p) : Prop.
Lemma irredp_neq0 p : irreducible_poly p -> p != 0.
Proof. by rewrite -size_poly_gt0 => [[/ltnW]]. Qed.
Definition apply_irredp p (irr_p : irreducible_poly p) := irr_p.2.
Coercion apply_irredp : irreducible_poly >-> Funclass.
Lemma modp_XsubC p c : p %% ('X - c%:P) = p.[c]%:P.
Proof.
have/factor_theorem [q /(canRL (subrK _)) Dp]: root (p - p.[c]%:P) c.
by rewrite /root !hornerE subrr.
rewrite modpE /= lead_coefXsubC unitr1 expr1n invr1 scale1r [in LHS]Dp.
rewrite RingMonic.rmodp_addl_mul_small // ?monicXsubC// size_XsubC size_polyC.
by case: (p.[c] == 0).
Qed.
Lemma coprimep_XsubC p c : coprimep p ('X - c%:P) = ~~ root p c.
Proof.
rewrite -coprimep_modl modp_XsubC /root -alg_polyC.
have [-> | /coprimepZl->] := eqVneq; last exact: coprime1p.
by rewrite scale0r /coprimep gcd0p size_XsubC.
Qed.
Lemma coprimep_XsubC2 (a b : R) : b - a != 0 ->
coprimep ('X - a%:P) ('X - b%:P).
Proof. by move=> bBa_neq0; rewrite coprimep_XsubC rootE hornerXsubC. Qed.
Lemma coprimepX p : coprimep p 'X = ~~ root p 0.
Proof. by rewrite -['X]subr0 coprimep_XsubC. Qed.
Lemma eqp_monic : {in monic &, forall p q, (p %= q) = (p == q)}.
Proof.
move=> p q monic_p monic_q; apply/idP/eqP=> [|-> //].
case/eqpP=> [[a b] /= /andP[a_neq0 _] eq_pq].
apply: (@mulfI _ a%:P); first by rewrite polyC_eq0.
rewrite !mul_polyC eq_pq; congr (_ *: q); apply: (mulIf (oner_neq0 _)).
by rewrite -[in LHS](monicP monic_q) -(monicP monic_p) -!lead_coefZ eq_pq.
Qed.
Lemma dvdp_mul_XsubC p q c :
(p %| ('X - c%:P) * q) = ((if root p c then p %/ ('X - c%:P) else p) %| q).
Proof.
case: ifPn => [| not_pc0]; last by rewrite Gauss_dvdpr ?coprimep_XsubC.
rewrite root_factor_theorem -eqp_div_XsubC mulrC => /eqP{1}->.
by rewrite dvdp_mul2l ?polyXsubC_eq0.
Qed.
Lemma dvdp_prod_XsubC (I : Type) (r : seq I) (F : I -> R) p :
p %| \prod_(i <- r) ('X - (F i)%:P) ->
{m | p %= \prod_(i <- mask m r) ('X - (F i)%:P)}.
Proof.
elim: r => [|i r IHr] in p *.
by rewrite big_nil dvdp1; exists nil; rewrite // big_nil -size_poly_eq1.
rewrite big_cons dvdp_mul_XsubC root_factor_theorem -eqp_div_XsubC.
case: eqP => [{2}-> | _] /IHr[m Dp]; last by exists (false :: m).
by exists (true :: m); rewrite /= mulrC big_cons eqp_mul2l ?polyXsubC_eq0.
Qed.
Lemma irredp_XsubC (x : R) : irreducible_poly ('X - x%:P).
Proof.
split=> [|d size_d d_dv_Xx]; first by rewrite size_XsubC.
have: ~ d %= 1 by apply/negP; rewrite -size_poly_eq1.
have [|m /=] := @dvdp_prod_XsubC _ [:: x] id d; first by rewrite big_seq1.
by case: m => [|[] [|_ _] /=]; rewrite (big_nil, big_seq1).
Qed.
Lemma irredp_XaddC (x : R) : irreducible_poly ('X + x%:P).
Proof. by rewrite -[x]opprK rmorphN; apply: irredp_XsubC. Qed.
Lemma irredp_XsubCP d p :
irreducible_poly p -> d %| p -> {d %= 1} + {d %= p}.
Proof.
move=> irred_p dvd_dp; have [] := boolP (_ %= 1); first by left.
by rewrite -size_poly_eq1=> /irred_p /(_ dvd_dp); right.
Qed.
Lemma dvdp_exp_XsubCP (p : {poly R}) (c : R) (n : nat) :
reflect (exists2 k, (k <= n)%N & p %= ('X - c%:P) ^+ k)
(p %| ('X - c%:P) ^+ n).
Proof.
apply: (iffP idP) => [|[k lkn /eqp_dvdl->]]; last by rewrite dvdp_exp2l.
move=> /Pdiv.WeakIdomain.dvdpP[[/= a q] a_neq0].
have [m [r]] := multiplicity_XsubC p c; have [->|pN0]/= := eqVneq p 0.
rewrite mulr0 => _ _ /eqP; rewrite scale_poly_eq0 (negPf a_neq0)/=.
by rewrite expf_eq0/= andbC polyXsubC_eq0.
move=> rNc ->; rewrite mulrA => eq_qrm; exists m.
have: ('X - c%:P) ^+ m %| a *: ('X - c%:P) ^+ n by rewrite eq_qrm dvdp_mull.
by rewrite (eqp_dvdr _ (eqp_scale _ _))// dvdp_Pexp2l// size_XsubC.
suff /eqP : size r = 1%N.
by rewrite size_poly_eq1 => /eqp_mulr/eqp_trans->//; rewrite mul1r eqpxx.
have : r %| a *: ('X - c%:P) ^+ n by rewrite eq_qrm mulrAC dvdp_mull.
rewrite (eqp_dvdr _ (eqp_scale _ _))//.
move: rNc; rewrite -coprimep_XsubC => /(coprimep_expr n) /coprimepP.
by move=> /(_ _ (dvdpp _)); rewrite -size_poly_eq1 => /(_ _)/eqP.
Qed.
End IDomainPseudoDivision.
Arguments gcdp : simpl never.
#[global] Hint Resolve eqpxx divp0 divp1 mod0p modp0 modp1 : core.
#[global] Hint Resolve dvdp_mull dvdp_mulr dvdpp dvdp0 : core.
Arguments dvdp_exp_XsubCP {R p c n}.
End CommonIdomain.
Module Idomain.
Include IdomainDefs.
Export IdomainDefs.
Include WeakIdomain.
Include CommonIdomain.
End Idomain.
Module IdomainMonic.
Import Ring ComRing UnitRing IdomainDefs Idomain.
Section IdomainMonic.
Variable R : idomainType.
Implicit Type p d r : {poly R}.
Section MonicDivisor.
Variable q : {poly R}.
Hypothesis monq : q \is monic.
Lemma divpE p : p %/ q = rdivp p q.
Proof. by rewrite divpE (eqP monq) unitr1 expr1n invr1 scale1r. Qed.
Lemma modpE p : p %% q = rmodp p q.
Proof. by rewrite modpE (eqP monq) unitr1 expr1n invr1 scale1r. Qed.
Lemma scalpE p : scalp p q = 0.
Proof. by rewrite scalpE (eqP monq) unitr1. Qed.
Lemma divp_eq p : p = (p %/ q) * q + (p %% q).
Proof. by rewrite -divp_eq (eqP monq) expr1n scale1r. Qed.
Lemma divpp p : q %/ q = 1.
Proof. by rewrite divpp ?monic_neq0 // (eqP monq) expr1n. Qed.
Lemma dvdp_eq p : (q %| p) = (p == (p %/ q) * q).
Proof. by rewrite dvdp_eq (eqP monq) expr1n scale1r. Qed.
Lemma dvdpP p : reflect (exists qq, p = qq * q) (q %| p).
Proof.
apply: (iffP idP); first by rewrite dvdp_eq; move/eqP=> e; exists (p %/ q).
by case=> qq ->; rewrite dvdp_mull // dvdpp.
Qed.
Lemma mulpK p : p * q %/ q = p.
Proof. by rewrite mulpK ?monic_neq0 // (eqP monq) expr1n scale1r. Qed.
Lemma mulKp p : q * p %/ q = p. Proof. by rewrite mulrC mulpK. Qed.
End MonicDivisor.
Lemma drop_poly_divp n p : drop_poly n p = p %/ 'X^n.
Proof. by rewrite RingMonic.drop_poly_rdivp divpE // monicXn. Qed.
Lemma take_poly_modp n p : take_poly n p = p %% 'X^n.
Proof. by rewrite RingMonic.take_poly_rmodp modpE // monicXn. Qed.
End IdomainMonic.
End IdomainMonic.
Module IdomainUnit.
Import Ring ComRing UnitRing IdomainDefs Idomain.
Section UnitDivisor.
Variable R : idomainType.
Variable d : {poly R}.
Hypothesis ulcd : lead_coef d \in GRing.unit.
Implicit Type p q r : {poly R}.
Lemma divp_eq p : p = (p %/ d) * d + (p %% d).
Proof. by have := divp_eq p d; rewrite scalpE ulcd expr0 scale1r. Qed.
Lemma edivpP p q r : p = q * d + r -> size r < size d ->
q = (p %/ d) /\ r = p %% d.
Proof.
move=> ep srd; have := divp_eq p; rewrite [LHS]ep.
move/eqP; rewrite -subr_eq -addrA addrC eq_sym -subr_eq -mulrBl; move/eqP.
have lcdn0 : lead_coef d != 0 by apply: contraTneq ulcd => ->; rewrite unitr0.
have [-> /esym /eqP|abs] := eqVneq (p %/ d) q.
by rewrite subrr mul0r subr_eq0 => /eqP<-.
have hleq : size d <= size ((p %/ d - q) * d).
rewrite size_proper_mul; last first.
by rewrite mulf_eq0 (negPf lcdn0) orbF lead_coef_eq0 subr_eq0.
by move: abs; rewrite -subr_eq0; move/polySpred->; rewrite addSn /= leq_addl.
have hlt : size (r - p %% d) < size d.
apply: leq_ltn_trans (size_polyD _ _) _.
by rewrite gtn_max srd size_polyN ltn_modp -lead_coef_eq0.
by move=> e; have:= leq_trans hlt hleq; rewrite e ltnn.
Qed.
Lemma divpP p q r : p = q * d + r -> size r < size d -> q = (p %/ d).
Proof. by move/edivpP=> h; case/h. Qed.
Lemma modpP p q r : p = q * d + r -> size r < size d -> r = (p %% d).
Proof. by move/edivpP=> h; case/h. Qed.
Lemma ulc_eqpP p q : lead_coef q \is a GRing.unit ->
reflect (exists2 c : R, c != 0 & p = c *: q) (p %= q).
Proof.
have [->|] := eqVneq (lead_coef q) 0; first by rewrite unitr0.
rewrite lead_coef_eq0 => nz_q ulcq; apply: (iffP idP).
have [->|nz_p] := eqVneq p 0; first by rewrite eqp_sym eqp0 (negPf nz_q).
move/eqp_eq=> eq; exists (lead_coef p / lead_coef q).
by rewrite mulf_neq0 // ?invr_eq0 lead_coef_eq0.
by apply/(scaler_injl ulcq); rewrite scalerA mulrCA divrr // mulr1.
by case=> c nz_c ->; apply/eqpP; exists (1, c); rewrite ?scale1r ?oner_eq0.
Qed.
Lemma dvdp_eq p : (d %| p) = (p == p %/ d * d).
Proof.
apply/eqP/eqP=> [modp0 | ->]; last exact: modp_mull.
by rewrite [p in LHS]divp_eq modp0 addr0.
Qed.
Lemma ucl_eqp_eq p q : lead_coef q \is a GRing.unit ->
p %= q -> p = (lead_coef p / lead_coef q) *: q.
Proof.
move=> ulcq /eqp_eq; move/(congr1 ( *:%R (lead_coef q)^-1 )).
by rewrite !scalerA mulrC divrr // scale1r mulrC.
Qed.
Lemma modpZl c p : (c *: p) %% d = c *: (p %% d).
Proof.
have [-> | cn0] := eqVneq c 0; first by rewrite !scale0r mod0p.
have e : (c *: p) = (c *: (p %/ d)) * d + c *: (p %% d).
by rewrite -scalerAl -scalerDr -divp_eq.
suff s: size (c *: (p %% d)) < size d by case: (edivpP e s) => _ ->.
rewrite -mul_polyC; apply: leq_ltn_trans (size_polyMleq _ _) _.
rewrite size_polyC cn0 addSn add0n /= ltn_modp -lead_coef_eq0.
by apply: contraTneq ulcd => ->; rewrite unitr0.
Qed.
Lemma divpZl c p : (c *: p) %/ d = c *: (p %/ d).
Proof.
have [-> | cn0] := eqVneq c 0; first by rewrite !scale0r div0p.
have e : (c *: p) = (c *: (p %/ d)) * d + c *: (p %% d).
by rewrite -scalerAl -scalerDr -divp_eq.
suff s: size (c *: (p %% d)) < size d by case: (edivpP e s) => ->.
rewrite -mul_polyC; apply: leq_ltn_trans (size_polyMleq _ _) _.
rewrite size_polyC cn0 addSn add0n /= ltn_modp -lead_coef_eq0.
by apply: contraTneq ulcd => ->; rewrite unitr0.
Qed.
Lemma eqp_modpl p q : p %= q -> (p %% d) %= (q %% d).
Proof.
case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e].
by apply/eqpP; exists (c1, c2); rewrite ?c1n0 //= -!modpZl e.
Qed.
Lemma eqp_divl p q : p %= q -> (p %/ d) %= (q %/ d).
Proof.
case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e].
by apply/eqpP; exists (c1, c2); rewrite ?c1n0 // -!divpZl e.
Qed.
Lemma modpN p : (- p) %% d = - (p %% d).
Proof. by rewrite -mulN1r -[RHS]mulN1r -polyCN !mul_polyC modpZl. Qed.
Lemma divpN p : (- p) %/ d = - (p %/ d).
Proof. by rewrite -mulN1r -[RHS]mulN1r -polyCN !mul_polyC divpZl. Qed.
Lemma modpD p q : (p + q) %% d = p %% d + q %% d.
Proof.
have/edivpP [] // : (p + q) = (p %/ d + q %/ d) * d + (p %% d + q %% d).
by rewrite mulrDl addrACA -!divp_eq.
apply: leq_ltn_trans (size_polyD _ _) _.
rewrite gtn_max !ltn_modp andbb -lead_coef_eq0.
by apply: contraTneq ulcd => ->; rewrite unitr0.
Qed.
Lemma divpD p q : (p + q) %/ d = p %/ d + q %/ d.
Proof.
have/edivpP [] // : (p + q) = (p %/ d + q %/ d) * d + (p %% d + q %% d).
by rewrite mulrDl addrACA -!divp_eq.
apply: leq_ltn_trans (size_polyD _ _) _.
rewrite gtn_max !ltn_modp andbb -lead_coef_eq0.
by apply: contraTneq ulcd => ->; rewrite unitr0.
Qed.
Lemma mulpK q : (q * d) %/ d = q.
Proof.
case/esym/edivpP: (addr0 (q * d)); rewrite // size_poly0 size_poly_gt0.
by rewrite -lead_coef_eq0; apply: contraTneq ulcd => ->; rewrite unitr0.
Qed.
Lemma mulKp q : (d * q) %/ d = q. Proof. by rewrite mulrC; apply: mulpK. Qed.
Lemma divp_addl_mul_small q r : size r < size d -> (q * d + r) %/ d = q.
Proof. by move=> srd; rewrite divpD (divp_small srd) addr0 mulpK. Qed.
Lemma modp_addl_mul_small q r : size r < size d -> (q * d + r) %% d = r.
Proof. by move=> srd; rewrite modpD modp_mull add0r modp_small. Qed.
Lemma divp_addl_mul q r : (q * d + r) %/ d = q + r %/ d.
Proof. by rewrite divpD mulpK. Qed.
Lemma divpp : d %/ d = 1. Proof. by rewrite -[d in d %/ _]mul1r mulpK. Qed.
Lemma leq_divMp m : size (m %/ d * d) <= size m.
Proof.
case: (eqVneq d 0) ulcd => [->|dn0 _]; first by rewrite lead_coef0 unitr0.
have [->|q0] := eqVneq (m %/ d) 0; first by rewrite mul0r size_poly0 leq0n.
rewrite {2}(divp_eq m) size_polyDl // size_mul // (polySpred q0) addSn /=.
by rewrite ltn_addl // ltn_modp.
Qed.
Lemma dvdpP p : reflect (exists q, p = q * d) (d %| p).
Proof.
apply: (iffP idP) => [| [k ->]]; last by apply/eqP; rewrite modp_mull.
by rewrite dvdp_eq; move/eqP->; exists (p %/ d).
Qed.
Lemma divpK p : d %| p -> p %/ d * d = p.
Proof. by rewrite dvdp_eq; move/eqP. Qed.
Lemma divpKC p : d %| p -> d * (p %/ d) = p.
Proof. by move=> ?; rewrite mulrC divpK. Qed.
Lemma dvdp_eq_div p q : d %| p -> (q == p %/ d) = (q * d == p).
Proof.
move/divpK=> {2}<-; apply/eqP/eqP; first by move->.
apply/mulIf; rewrite -lead_coef_eq0; apply: contraTneq ulcd => ->.
by rewrite unitr0.
Qed.
Lemma dvdp_eq_mul p q : d %| p -> (p == q * d) = (p %/ d == q).
Proof. by move=> dv_d_p; rewrite eq_sym -dvdp_eq_div // eq_sym. Qed.
Lemma divp_mulA p q : d %| q -> p * (q %/ d) = p * q %/ d.
Proof.
move=> hdm; apply/eqP; rewrite eq_sym -dvdp_eq_mul.
by rewrite -mulrA divpK.
by move/divpK: hdm<-; rewrite mulrA dvdp_mull // dvdpp.
Qed.
Lemma divp_mulAC m n : d %| m -> m %/ d * n = m * n %/ d.
Proof. by move=> hdm; rewrite mulrC (mulrC m); apply: divp_mulA. Qed.
Lemma divp_mulCA p q : d %| p -> d %| q -> p * (q %/ d) = q * (p %/ d).
Proof. by move=> hdp hdq; rewrite mulrC divp_mulAC // divp_mulA. Qed.
Lemma modp_mul p q : (p * (q %% d)) %% d = (p * q) %% d.
Proof. by rewrite [q in RHS]divp_eq mulrDr modpD mulrA modp_mull add0r. Qed.
End UnitDivisor.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to leq_divMp.")]
Notation leq_trunc_divp := leq_divMp.
Section MoreUnitDivisor.
Variable R : idomainType.
Variable d : {poly R}.
Hypothesis ulcd : lead_coef d \in GRing.unit.
Implicit Types p q : {poly R}.
Lemma expp_sub m n : n <= m -> (d ^+ (m - n))%N = d ^+ m %/ d ^+ n.
Proof. by move/subnK=> {2}<-; rewrite exprD mulpK // lead_coef_exp unitrX. Qed.
Lemma divp_pmul2l p q : lead_coef q \in GRing.unit -> d * p %/ (d * q) = p %/ q.
Proof.
move=> uq; rewrite {1}(divp_eq uq p) mulrDr mulrCA divp_addl_mul //; last first.
by rewrite lead_coefM unitrM_comm ?ulcd //; red; rewrite mulrC.
have dn0 : d != 0.
by rewrite -lead_coef_eq0; apply: contraTneq ulcd => ->; rewrite unitr0.
have qn0 : q != 0.
by rewrite -lead_coef_eq0; apply: contraTneq uq => ->; rewrite unitr0.
have dqn0 : d * q != 0 by rewrite mulf_eq0 negb_or dn0.
suff : size (d * (p %% q)) < size (d * q).
by rewrite ltnNge -divpN0 // negbK => /eqP ->; rewrite addr0.
have [-> | rn0] := eqVneq (p %% q) 0.
by rewrite mulr0 size_poly0 size_poly_gt0.
by rewrite !size_mul // (polySpred dn0) !addSn /= ltn_add2l ltn_modp.
Qed.
Lemma divp_pmul2r p q : lead_coef p \in GRing.unit -> q * d %/ (p * d) = q %/ p.
Proof. by move=> uq; rewrite -!(mulrC d) divp_pmul2l. Qed.
Lemma divp_divl r p q :
lead_coef r \in GRing.unit -> lead_coef p \in GRing.unit ->
q %/ p %/ r = q %/ (p * r).
Proof.
move=> ulcr ulcp.
have e : q = (q %/ p %/ r) * (p * r) + ((q %/ p) %% r * p + q %% p).
by rewrite addrA (mulrC p) mulrA -mulrDl; rewrite -divp_eq //; apply: divp_eq.
have pn0 : p != 0.
by rewrite -lead_coef_eq0; apply: contraTneq ulcp => ->; rewrite unitr0.
have rn0 : r != 0.
by rewrite -lead_coef_eq0; apply: contraTneq ulcr => ->; rewrite unitr0.
have s : size ((q %/ p) %% r * p + q %% p) < size (p * r).
have [-> | qn0] := eqVneq ((q %/ p) %% r) 0.
rewrite mul0r add0r size_mul // (polySpred rn0) addnS /=.
by apply: leq_trans (leq_addr _ _); rewrite ltn_modp.
rewrite size_polyDl mulrC.
by rewrite !size_mul // (polySpred pn0) !addSn /= ltn_add2l ltn_modp.
rewrite size_mul // (polySpred qn0) addnS /=.
by apply: leq_trans (leq_addr _ _); rewrite ltn_modp.
case: (edivpP _ e s) => //; rewrite lead_coefM unitrM_comm ?ulcp //.
by red; rewrite mulrC.
Qed.
Lemma divpAC p q : lead_coef p \in GRing.unit -> q %/ d %/ p = q %/ p %/ d.
Proof. by move=> ulcp; rewrite !divp_divl // mulrC. Qed.
Lemma modpZr c p : c \in GRing.unit -> p %% (c *: d) = (p %% d).
Proof.
case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !modp0.
have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d).
by rewrite scalerCA scalerA mulVr // scale1r -(divp_eq ulcd).
suff s : size (p %% d) < size (c *: d).
by rewrite (modpP _ e s) // -mul_polyC lead_coefM lead_coefC unitrM cn0.
by rewrite size_scale ?ltn_modp //; apply: contraTneq cn0 => ->; rewrite unitr0.
Qed.
Lemma divpZr c p : c \in GRing.unit -> p %/ (c *: d) = c^-1 *: (p %/ d).
Proof.
case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !divp0 scaler0.
have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d).
by rewrite scalerCA scalerA mulVr // scale1r -(divp_eq ulcd).
suff s : size (p %% d) < size (c *: d).
by rewrite (divpP _ e s) // -mul_polyC lead_coefM lead_coefC unitrM cn0.
by rewrite size_scale ?ltn_modp //; apply: contraTneq cn0 => ->; rewrite unitr0.
Qed.
End MoreUnitDivisor.
End IdomainUnit.
Module Field.
Import Ring ComRing UnitRing.
Include IdomainDefs.
Export IdomainDefs.
Include CommonIdomain.
Section FieldDivision.
Variable F : fieldType.
Implicit Type p q r d : {poly F}.
Lemma divp_eq p q : p = (p %/ q) * q + (p %% q).
Proof.
have [-> | qn0] := eqVneq q 0; first by rewrite modp0 mulr0 add0r.
by apply: IdomainUnit.divp_eq; rewrite unitfE lead_coef_eq0.
Qed.
Lemma divp_modpP p q d r : p = q * d + r -> size r < size d ->
q = (p %/ d) /\ r = p %% d.
Proof.
move=> he hs; apply: IdomainUnit.edivpP => //; rewrite unitfE lead_coef_eq0.
by rewrite -size_poly_gt0; apply: leq_trans hs.
Qed.
Lemma divpP p q d r : p = q * d + r -> size r < size d ->
q = (p %/ d).
Proof. by move/divp_modpP=> h; case/h. Qed.
Lemma modpP p q d r : p = q * d + r -> size r < size d -> r = (p %% d).
Proof. by move/divp_modpP=> h; case/h. Qed.
Lemma eqpfP p q : p %= q -> p = (lead_coef p / lead_coef q) *: q.
Proof.
have [->|nz_q] := eqVneq q 0; first by rewrite eqp0 scaler0 => /eqP ->.
by apply/IdomainUnit.ucl_eqp_eq; rewrite unitfE lead_coef_eq0.
Qed.
Lemma dvdp_eq q p : (q %| p) = (p == p %/ q * q).
Proof.
have [-> | qn0] := eqVneq q 0; first by rewrite dvd0p mulr0 eq_sym.
by apply: IdomainUnit.dvdp_eq; rewrite unitfE lead_coef_eq0.
Qed.
Lemma eqpf_eq p q : reflect (exists2 c, c != 0 & p = c *: q) (p %= q).
Proof.
apply: (iffP idP); last first.
case=> c nz_c ->; apply/eqpP.
by exists (1, c); rewrite ?scale1r ?oner_eq0.
have [->|nz_q] := eqVneq q 0.
by rewrite eqp0=> /eqP ->; exists 1; rewrite ?scale1r ?oner_eq0.
case/IdomainUnit.ulc_eqpP; first by rewrite unitfE lead_coef_eq0.
by move=> c nz_c ->; exists c.
Qed.
Lemma modpZl c p q : (c *: p) %% q = c *: (p %% q).
Proof.
have [-> | qn0] := eqVneq q 0; first by rewrite !modp0.
by apply: IdomainUnit.modpZl; rewrite unitfE lead_coef_eq0.
Qed.
Lemma mulpK p q : q != 0 -> p * q %/ q = p.
Proof. by move=> qn0; rewrite IdomainUnit.mulpK // unitfE lead_coef_eq0. Qed.
Lemma mulKp p q : q != 0 -> q * p %/ q = p.
Proof. by rewrite mulrC; apply: mulpK. Qed.
Lemma divpZl c p q : (c *: p) %/ q = c *: (p %/ q).
Proof.
have [-> | qn0] := eqVneq q 0; first by rewrite !divp0 scaler0.
by apply: IdomainUnit.divpZl; rewrite unitfE lead_coef_eq0.
Qed.
Lemma modpZr c p d : c != 0 -> p %% (c *: d) = (p %% d).
Proof.
case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !modp0.
have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d).
by rewrite scalerCA scalerA mulVf // scale1r -divp_eq.
suff s : size (p %% d) < size (c *: d) by rewrite (modpP e s).
by rewrite size_scale ?ltn_modp.
Qed.
Lemma divpZr c p d : c != 0 -> p %/ (c *: d) = c^-1 *: (p %/ d).
Proof.
case: (eqVneq d 0) => [-> | dn0 cn0]; first by rewrite scaler0 !divp0 scaler0.
have e : p = (c^-1 *: (p %/ d)) * (c *: d) + (p %% d).
by rewrite scalerCA scalerA mulVf // scale1r -divp_eq.
suff s : size (p %% d) < size (c *: d) by rewrite (divpP e s).
by rewrite size_scale ?ltn_modp.
Qed.
Lemma eqp_modpl d p q : p %= q -> (p %% d) %= (q %% d).
Proof.
case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e].
by apply/eqpP; exists (c1, c2); rewrite ?c1n0 // -!modpZl e.
Qed.
Lemma eqp_divl d p q : p %= q -> (p %/ d) %= (q %/ d).
Proof.
case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0 e].
by apply/eqpP; exists (c1, c2); rewrite ?c1n0 // -!divpZl e.
Qed.
Lemma eqp_modpr d p q : p %= q -> (d %% p) %= (d %% q).
Proof.
case/eqpP=> [[c1 c2]] /andP [c1n0 c2n0 e].
have -> : p = (c1^-1 * c2) *: q by rewrite -scalerA -e scalerA mulVf // scale1r.
by rewrite modpZr ?eqpxx // mulf_eq0 negb_or invr_eq0 c1n0.
Qed.
Lemma eqp_mod p1 p2 q1 q2 : p1 %= p2 -> q1 %= q2 -> p1 %% q1 %= p2 %% q2.
Proof. move=> e1 e2; exact: eqp_trans (eqp_modpl _ e1) (eqp_modpr _ e2). Qed.
Lemma eqp_divr (d m n : {poly F}) : m %= n -> (d %/ m) %= (d %/ n).
Proof.
case/eqpP=> [[c1 c2]] /andP [c1n0 c2n0 e].
have -> : m = (c1^-1 * c2) *: n by rewrite -scalerA -e scalerA mulVf // scale1r.
by rewrite divpZr ?eqp_scale // ?invr_eq0 mulf_eq0 negb_or invr_eq0 c1n0.
Qed.
Lemma eqp_div p1 p2 q1 q2 : p1 %= p2 -> q1 %= q2 -> p1 %/ q1 %= p2 %/ q2.
Proof. move=> e1 e2; exact: eqp_trans (eqp_divl _ e1) (eqp_divr _ e2). Qed.
Lemma eqp_gdcor p q r : q %= r -> gdcop p q %= gdcop p r.
Proof.
move=> eqr; rewrite /gdcop (eqp_size eqr).
move: (size r)=> n; elim: n p q r eqr => [|n ihn] p q r; first by rewrite eqpxx.
move=> eqr /=; rewrite (eqp_coprimepl p eqr); case: ifP => _ //.
exact/ihn/eqp_div/eqp_gcdl.
Qed.
Lemma eqp_gdcol p q r : q %= r -> gdcop q p %= gdcop r p.
Proof.
move=> eqr; rewrite /gdcop; move: (size p)=> n.
elim: n p q r eqr {1 3}p (eqpxx p) => [|n ihn] p q r eqr s esp /=.
case: (eqVneq q 0) eqr => [-> | nq0 eqr] /=.
by rewrite eqp_sym eqp0 => ->; rewrite eqpxx.
by case: (eqVneq r 0) eqr nq0 => [->|]; rewrite ?eqpxx // eqp0 => ->.
rewrite (eqp_coprimepr _ eqr) (eqp_coprimepl _ esp); case: ifP=> _ //.
exact/ihn/eqp_div/eqp_gcd.
Qed.
Lemma eqp_rgdco_gdco q p : rgdcop q p %= gdcop q p.
Proof.
rewrite /rgdcop /gdcop; move: (size p)=> n.
elim: n p q {1 3}p {1 3}q (eqpxx p) (eqpxx q) => [|n ihn] p q s t /= sp tq.
case: (eqVneq t 0) tq => [-> | nt0 etq].
by rewrite eqp_sym eqp0 => ->; rewrite eqpxx.
by case: (eqVneq q 0) etq nt0 => [->|]; rewrite ?eqpxx // eqp0 => ->.
rewrite rcoprimep_coprimep (eqp_coprimepl t sp) (eqp_coprimepr p tq).
case: ifP=> // _; apply: ihn => //; apply: eqp_trans (eqp_rdiv_div _ _) _.
by apply: eqp_div => //; apply: eqp_trans (eqp_rgcd_gcd _ _) _; apply: eqp_gcd.
Qed.
Lemma modpD d p q : (p + q) %% d = p %% d + q %% d.
Proof.
have [-> | dn0] := eqVneq d 0; first by rewrite !modp0.
by apply: IdomainUnit.modpD; rewrite unitfE lead_coef_eq0.
Qed.
Lemma modpN p q : (- p) %% q = - (p %% q).
Proof. by apply/eqP; rewrite -addr_eq0 -modpD addNr mod0p. Qed.
Lemma modNp p q : (- p) %% q = - (p %% q). Proof. exact: modpN. Qed.
Lemma divpD d p q : (p + q) %/ d = p %/ d + q %/ d.
Proof.
have [-> | dn0] := eqVneq d 0; first by rewrite !divp0 addr0.
by apply: IdomainUnit.divpD; rewrite unitfE lead_coef_eq0.
Qed.
Lemma divpN p q : (- p) %/ q = - (p %/ q).
Proof. by apply/eqP; rewrite -addr_eq0 -divpD addNr div0p. Qed.
Lemma divp_addl_mul_small d q r : size r < size d -> (q * d + r) %/ d = q.
Proof.
move=> srd; rewrite divpD (divp_small srd) addr0 mulpK // -size_poly_gt0.
exact: leq_trans srd.
Qed.
Lemma modp_addl_mul_small d q r : size r < size d -> (q * d + r) %% d = r.
Proof. by move=> srd; rewrite modpD modp_mull add0r modp_small. Qed.
Lemma divp_addl_mul d q r : d != 0 -> (q * d + r) %/ d = q + r %/ d.
Proof. by move=> dn0; rewrite divpD mulpK. Qed.
Lemma divpp d : d != 0 -> d %/ d = 1.
Proof.
by move=> dn0; apply: IdomainUnit.divpp; rewrite unitfE lead_coef_eq0.
Qed.
Lemma leq_divMp d m : size (m %/ d * d) <= size m.
Proof.
have [-> | dn0] := eqVneq d 0; first by rewrite mulr0 size_poly0.
by apply: IdomainUnit.leq_divMp; rewrite unitfE lead_coef_eq0.
Qed.
Lemma divpK d p : d %| p -> p %/ d * d = p.
Proof.
case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite mulr0.
by apply: IdomainUnit.divpK; rewrite unitfE lead_coef_eq0.
Qed.
Lemma divpKC d p : d %| p -> d * (p %/ d) = p.
Proof. by move=> ?; rewrite mulrC divpK. Qed.
Lemma dvdp_eq_div d p q : d != 0 -> d %| p -> (q == p %/ d) = (q * d == p).
Proof.
by move=> dn0; apply: IdomainUnit.dvdp_eq_div; rewrite unitfE lead_coef_eq0.
Qed.
Lemma dvdp_eq_mul d p q : d != 0 -> d %| p -> (p == q * d) = (p %/ d == q).
Proof. by move=> dn0 dv_d_p; rewrite eq_sym -dvdp_eq_div // eq_sym. Qed.
Lemma divp_mulA d p q : d %| q -> p * (q %/ d) = p * q %/ d.
Proof.
case: (eqVneq d 0) => [-> /dvd0pP -> | dn0]; first by rewrite !divp0 mulr0.
by apply: IdomainUnit.divp_mulA; rewrite unitfE lead_coef_eq0.
Qed.
Lemma divp_mulAC d m n : d %| m -> m %/ d * n = m * n %/ d.
Proof. by move=> hdm; rewrite mulrC (mulrC m); apply: divp_mulA. Qed.
Lemma divp_mulCA d p q : d %| p -> d %| q -> p * (q %/ d) = q * (p %/ d).
Proof. by move=> hdp hdq; rewrite mulrC divp_mulAC // divp_mulA. Qed.
Lemma expp_sub d m n : d != 0 -> m >= n -> (d ^+ (m - n))%N = d ^+ m %/ d ^+ n.
Proof. by move=> dn0 /subnK=> {2}<-; rewrite exprD mulpK // expf_neq0. Qed.
Lemma divp_pmul2l d q p : d != 0 -> q != 0 -> d * p %/ (d * q) = p %/ q.
Proof.
by move=> dn0 qn0; apply: IdomainUnit.divp_pmul2l; rewrite unitfE lead_coef_eq0.
Qed.
Lemma divp_pmul2r d p q : d != 0 -> p != 0 -> q * d %/ (p * d) = q %/ p.
Proof. by move=> dn0 qn0; rewrite -!(mulrC d) divp_pmul2l. Qed.
Lemma divp_divl r p q : q %/ p %/ r = q %/ (p * r).
Proof.
have [-> | rn0] := eqVneq r 0; first by rewrite mulr0 !divp0.
have [-> | pn0] := eqVneq p 0; first by rewrite mul0r !divp0 div0p.
by apply: IdomainUnit.divp_divl; rewrite unitfE lead_coef_eq0.
Qed.
Lemma divpAC d p q : q %/ d %/ p = q %/ p %/ d.
Proof. by rewrite !divp_divl // mulrC. Qed.
Lemma edivp_def p q : edivp p q = (0, p %/ q, p %% q).
Proof.
rewrite Idomain.edivp_def; congr (_, _, _); rewrite /scalp 2!unlock /=.
have [-> | qn0] := eqVneq; first by rewrite lead_coef0 unitr0.
by rewrite unitfE lead_coef_eq0 qn0 /=; case: (redivp_rec _ _ _ _) => [[]].
Qed.
Lemma divpE p q : p %/ q = (lead_coef q)^-(rscalp p q) *: (rdivp p q).
Proof.
have [-> | qn0] := eqVneq q 0; first by rewrite rdivp0 divp0 scaler0.
by rewrite Idomain.divpE unitfE lead_coef_eq0 qn0.
Qed.
Lemma modpE p q : p %% q = (lead_coef q)^-(rscalp p q) *: (rmodp p q).
Proof.
have [-> | qn0] := eqVneq q 0.
by rewrite rmodp0 modp0 /rscalp unlock eqxx lead_coef0 expr0 invr1 scale1r.
by rewrite Idomain.modpE unitfE lead_coef_eq0 qn0.
Qed.
Lemma scalpE p q : scalp p q = 0.
Proof.
have [-> | qn0] := eqVneq q 0; first by rewrite scalp0.
by rewrite Idomain.scalpE unitfE lead_coef_eq0 qn0.
Qed.
(* Just to have it without importing the weak theory *)
Lemma dvdpE p q : p %| q = rdvdp p q. Proof. exact: Idomain.dvdpE. Qed.
Variant edivp_spec m d : nat * {poly F} * {poly F} -> Type :=
EdivpSpec n q r of
m = q * d + r & (d != 0) ==> (size r < size d) : edivp_spec m d (n, q, r).
Lemma edivpP m d : edivp_spec m d (edivp m d).
Proof.
rewrite edivp_def; constructor; first exact: divp_eq.
by apply/implyP=> dn0; rewrite ltn_modp.
Qed.
Lemma edivp_eq d q r : size r < size d -> edivp (q * d + r) d = (0, q, r).
Proof.
move=> srd; apply: Idomain.edivp_eq; rewrite // unitfE lead_coef_eq0.
by rewrite -size_poly_gt0; apply: leq_trans srd.
Qed.
Lemma modp_mul p q m : (p * (q %% m)) %% m = (p * q) %% m.
Proof. by rewrite [in RHS](divp_eq q m) mulrDr modpD mulrA modp_mull add0r. Qed.
Lemma horner_mod p q x : root q x -> (p %% q).[x] = p.[x].
Proof.
by rewrite [in RHS](divp_eq p q) !hornerE => /eqP->; rewrite mulr0 add0r.
Qed.
Lemma dvdpP p q : reflect (exists qq, p = qq * q) (q %| p).
Proof.
have [-> | qn0] := eqVneq q 0; last first.
by apply: IdomainUnit.dvdpP; rewrite unitfE lead_coef_eq0.
by rewrite dvd0p; apply: (iffP eqP) => [->| [? ->]]; [exists 1|]; rewrite mulr0.
Qed.
Lemma Bezout_eq1_coprimepP p q :
reflect (exists u, u.1 * p + u.2 * q = 1) (coprimep p q).
Proof.
apply: (iffP idP)=> [hpq|]; last first.
by case=> -[u v] /= e; apply/Bezout_coprimepP; exists (u, v); rewrite e eqpxx.
case/Bezout_coprimepP: hpq => [[u v]] /=.
case/eqpP=> [[c1 c2]] /andP /= [c1n0 c2n0] e.
exists (c2^-1 *: (c1 *: u), c2^-1 *: (c1 *: v)); rewrite /= -!scalerAl.
by rewrite -!scalerDr e scalerA mulVf // scale1r.
Qed.
Lemma dvdp_gdcor p q : q != 0 -> p %| (gdcop q p) * (q ^+ size p).
Proof.
rewrite /gdcop => nz_q; have [n hsp] := ubnPleq (size p).
elim: n => [|n IHn] /= in p hsp *; first by rewrite (negPf nz_q) mul0r dvdp0.
have [_ | ncop_pq] := ifPn; first by rewrite dvdp_mulr.
have g_gt1: 1 < size (gcdp p q).
rewrite ltn_neqAle eq_sym ncop_pq size_poly_gt0 gcdp_eq0.
by rewrite negb_and nz_q orbT.
have [-> | nz_p] := eqVneq p 0.
by rewrite div0p exprSr mulrA dvdp_mulr // IHn // size_poly0.
have le_d_p: size (p %/ gcdp p q) < size p.
rewrite size_divp -?size_poly_eq0 -(subnKC g_gt1) // add2n /=.
by rewrite polySpred // ltnS subSS leq_subr.
rewrite -[p in p %| _](divpK (dvdp_gcdl p q)) exprSr mulrA.
by rewrite dvdp_mul ?IHn ?dvdp_gcdr // -ltnS (leq_trans le_d_p).
Qed.
Lemma reducible_cubic_root p q :
size p <= 4 -> 1 < size q < size p -> q %| p -> {r | root p r}.
Proof.
move=> p_le4 /andP[]; rewrite leq_eqVlt eq_sym.
have [/poly2_root[x qx0] _ _ | _ /= q_gt2 p_gt_q] := size q =P 2.
by exists x; rewrite -!dvdp_XsubCl in qx0 *; apply: (dvdp_trans qx0).
case/dvdpP/sig_eqW=> r def_p; rewrite def_p.
suffices /poly2_root[x rx0]: size r = 2 by exists x; rewrite rootM rx0.
have /norP[nz_r nz_q]: ~~ [|| r == 0 | q == 0].
by rewrite -mulf_eq0 -def_p -size_poly_gt0 (leq_ltn_trans _ p_gt_q).
rewrite def_p size_mul // -subn1 leq_subLR ltn_subRL in p_gt_q p_le4.
by apply/eqP; rewrite -(eqn_add2r (size q)) eqn_leq (leq_trans p_le4).
Qed.
Lemma cubic_irreducible p :
1 < size p <= 4 -> (forall x, ~~ root p x) -> irreducible_poly p.
Proof.
move=> /andP[p_gt1 p_le4] root'p; split=> // q sz_q_neq1 q_dv_p.
have nz_p: p != 0 by rewrite -size_poly_gt0 ltnW.
have nz_q: q != 0 by apply: contraTneq q_dv_p => ->; rewrite dvd0p.
have q_gt1: size q > 1 by rewrite ltn_neqAle eq_sym sz_q_neq1 size_poly_gt0.
rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //= leqNgt; apply/negP=> p_gt_q.
by have [|x /idPn//] := reducible_cubic_root p_le4 _ q_dv_p; rewrite q_gt1.
Qed.
Section Multiplicity.
Definition mup x q :=
[arg max_(n > (ord0 : 'I_(size q).+1) | ('X - x%:P) ^+ n %| q) n] : nat.
Lemma mup_geq x q n : q != 0 -> (n <= mup x q)%N = (('X - x%:P) ^+ n %| q).
Proof.
move=> q_neq0; rewrite /mup; symmetry.
case: arg_maxnP; rewrite ?expr0 ?dvd1p//= => i i_dvd gti.
case: ltnP => [|/dvdp_exp2l/dvdp_trans]; last exact.
apply: contraTF => dvdq; rewrite -leqNgt.
suff n_small : (n < (size q).+1)%N by exact: (gti (Ordinal n_small)).
by rewrite ltnS ltnW// -(size_exp_XsubC _ x) dvdp_leq.
Qed.
Lemma mup_leq x q n : q != 0 ->
(mup x q <= n)%N = ~~ (('X - x%:P) ^+ n.+1 %| q).
Proof. by move=> qN0; rewrite leqNgt mup_geq. Qed.
Lemma mup_ltn x q n : q != 0 -> (mup x q < n)%N = ~~ (('X - x%:P) ^+ n %| q).
Proof. by move=> qN0; rewrite ltnNge mup_geq. Qed.
Lemma XsubC_dvd x q : q != 0 -> ('X - x%:P %| q) = (0 < mup x q)%N.
Proof. by move=> /mup_geq-/(_ _ 1%N)/esym; apply. Qed.
Lemma mup_XsubCX n x y :
mup x (('X - y%:P) ^+ n) = (if (y == x) then n else 0)%N.
Proof.
have Xxn0 : ('X - y%:P) ^+ n != 0 by rewrite ?expf_neq0 ?polyXsubC_eq0.
apply/eqP; rewrite eqn_leq mup_leq ?mup_geq//.
have [->|Nxy] := eqVneq x y.
by rewrite /= dvdpp ?dvdp_Pexp2l ?size_XsubC ?ltnn.
by rewrite dvd1p dvdp_XsubCl /root horner_exp !hornerE expf_neq0// subr_eq0.
Qed.
Lemma mupNroot x q : ~~ root q x -> mup x q = 0%N.
Proof.
move=> qNx; have qN0 : q != 0 by apply: contraNneq qNx => ->; rewrite root0.
by move: qNx; rewrite -dvdp_XsubCl XsubC_dvd// lt0n negbK => /eqP.
Qed.
Lemma mupMr x q1 q2 : ~~ root q1 x -> mup x (q1 * q2) = mup x q2.
Proof.
move=> q1Nx; have q1N0 : q1 != 0 by apply: contraNneq q1Nx => ->; rewrite root0.
have [->|q2N0] := eqVneq q2 0; first by rewrite mulr0.
apply/esym/eqP; rewrite eqn_leq mup_geq ?mulf_neq0// dvdp_mull -?mup_geq//=.
rewrite mup_leq ?mulf_neq0// Gauss_dvdpr -?mup_ltn//.
by rewrite coprimep_expl// coprimep_sym coprimep_XsubC.
Qed.
Lemma mupMl x q1 q2 : ~~ root q2 x -> mup x (q1 * q2) = mup x q1.
Proof. by rewrite mulrC; apply/mupMr. Qed.
Lemma mupM x q1 q2 : q1 != 0 -> q2 != 0 ->
mup x (q1 * q2) = (mup x q1 + mup x q2)%N.
Proof.
move=> q1N0 q2N0; apply/eqP; rewrite eqn_leq mup_leq ?mulf_neq0//.
rewrite mup_geq ?mulf_neq0// exprD ?dvdp_mul; do ?by rewrite -mup_geq.
have [m1 [r1]] := multiplicity_XsubC q1 x; rewrite q1N0 /= => r1Nx ->.
have [m2 [r2]] := multiplicity_XsubC q2 x; rewrite q2N0 /= => r2Nx ->.
rewrite !mupMr// ?mup_XsubCX eqxx/= mulrACA exprS exprD.
rewrite dvdp_mul2r ?mulf_neq0 ?expf_neq0 ?polyXsubC_eq0//.
by rewrite dvdp_XsubCl rootM negb_or r1Nx r2Nx.
Qed.
Lemma mu_prod_XsubC x (s : seq F) :
mup x (\prod_(y <- s) ('X - y%:P)) = count_mem x s.
Proof.
elim: s => [|y s IHs]; rewrite (big_cons, big_nil)/=.
by rewrite mupNroot// root1.
rewrite mupM ?polyXsubC_eq0// ?monic_neq0 ?monic_prod_XsubC//.
by rewrite IHs (@mup_XsubCX 1).
Qed.
Lemma prod_XsubC_eq (s t : seq F) :
\prod_(x <- s) ('X - x%:P) = \prod_(x <- t) ('X - x%:P) -> perm_eq s t.
Proof.
move=> eq_prod; apply/allP => x _ /=; apply/eqP.
by have /(congr1 (mup x)) := eq_prod; rewrite !mu_prod_XsubC.
Qed.
End Multiplicity.
Section FieldRingMap.
Variable rR : nzRingType.
Variable f : {rmorphism F -> rR}.
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Implicit Type a b : {poly F}.
Lemma redivp_map a b :
redivp a^f b^f = (rscalp a b, (rdivp a b)^f, (rmodp a b)^f).
Proof.
rewrite /rdivp /rscalp /rmodp !unlock map_poly_eq0 size_map_poly.
have [// | q_nz] := ifPn; rewrite -(rmorph0 (map_poly f)) //.
have [m _] := ubnPeq (size a); elim: m 0%N 0 a => [|m IHm] qq r a /=.
rewrite -!mul_polyC !size_map_poly !lead_coef_map // -(map_polyXn f).
by rewrite -!(map_polyC f) -!rmorphM -rmorphB -rmorphD; case: (_ < _).
rewrite -!mul_polyC !size_map_poly !lead_coef_map // -(map_polyXn f).
by rewrite -!(map_polyC f) -!rmorphM -rmorphB -rmorphD /= IHm; case: (_ < _).
Qed.
End FieldRingMap.
Section FieldMap.
Variable rR : idomainType.
Variable f : {rmorphism F -> rR}.
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Implicit Type a b : {poly F}.
Lemma edivp_map a b :
edivp a^f b^f = (0, (a %/ b)^f, (a %% b)^f).
Proof.
have [-> | bn0] := eqVneq b 0.
rewrite (rmorph0 (map_poly f)) WeakIdomain.edivp_def !modp0 !divp0.
by rewrite (rmorph0 (map_poly f)) scalp0.
rewrite unlock redivp_map lead_coef_map rmorph_unit; last first.
by rewrite unitfE lead_coef_eq0.
rewrite modpE divpE !map_polyZ [in RHS]rmorphV ?rmorphXn // unitfE.
by rewrite expf_neq0 // lead_coef_eq0.
Qed.
Lemma scalp_map p q : scalp p^f q^f = scalp p q.
Proof. by rewrite /scalp edivp_map edivp_def. Qed.
Lemma map_divp p q : (p %/ q)^f = p^f %/ q^f.
Proof. by rewrite /divp edivp_map edivp_def. Qed.
Lemma map_modp p q : (p %% q)^f = p^f %% q^f.
Proof. by rewrite /modp edivp_map edivp_def. Qed.
Lemma egcdp_map p q :
egcdp (map_poly f p) (map_poly f q)
= (map_poly f (egcdp p q).1, map_poly f (egcdp p q).2).
Proof.
wlog le_qp: p q / size q <= size p.
move=> IH; have [/IH// | lt_qp] := leqP (size q) (size p).
have /IH := ltnW lt_qp; rewrite /egcdp !size_map_poly ltnW // leqNgt lt_qp /=.
by case: (egcdp_rec _ _ _) => u v [-> ->].
rewrite /egcdp !size_map_poly {}le_qp; move: (size q) => n.
elim: n => /= [|n IHn] in p q *; first by rewrite rmorph1 rmorph0.
rewrite map_poly_eq0; have [_ | nz_q] := ifPn; first by rewrite rmorph1 rmorph0.
rewrite -map_modp (IHn q (p %% q)); case: (egcdp_rec _ _ n) => u v /=.
rewrite map_polyZ lead_coef_map -rmorphXn scalp_map rmorphB rmorphM.
by rewrite -map_divp.
Qed.
Lemma dvdp_map p q : (p^f %| q^f) = (p %| q).
Proof. by rewrite /dvdp -map_modp map_poly_eq0. Qed.
Lemma eqp_map p q : (p^f %= q^f) = (p %= q).
Proof. by rewrite /eqp !dvdp_map. Qed.
Lemma gcdp_map p q : (gcdp p q)^f = gcdp p^f q^f.
Proof.
wlog lt_p_q: p q / size p < size q.
move=> IHpq; case: (ltnP (size p) (size q)) => [|le_q_p]; first exact: IHpq.
rewrite gcdpE (gcdpE p^f) !size_map_poly ltnNge le_q_p /= -map_modp.
have [-> | q_nz] := eqVneq q 0; first by rewrite rmorph0 !gcdp0.
by rewrite IHpq ?ltn_modp.
have [m le_q_m] := ubnP (size q); elim: m => // m IHm in p q lt_p_q le_q_m *.
rewrite gcdpE (gcdpE p^f) !size_map_poly lt_p_q -map_modp.
have [-> | q_nz] := eqVneq p 0; first by rewrite rmorph0 !gcdp0.
by rewrite IHm ?(leq_trans lt_p_q) ?ltn_modp.
Qed.
Lemma coprimep_map p q : coprimep p^f q^f = coprimep p q.
Proof. by rewrite -!gcdp_eqp1 -eqp_map rmorph1 gcdp_map. Qed.
Lemma gdcop_rec_map p q n : (gdcop_rec p q n)^f = gdcop_rec p^f q^f n.
Proof.
elim: n p q => [|n IH] => /= p q.
by rewrite map_poly_eq0; case: eqP; rewrite ?rmorph1 ?rmorph0.
rewrite /coprimep -gcdp_map size_map_poly.
by case: eqP => Hq0 //; rewrite -map_divp -IH.
Qed.
Lemma gdcop_map p q : (gdcop p q)^f = gdcop p^f q^f.
Proof. by rewrite /gdcop gdcop_rec_map !size_map_poly. Qed.
End FieldMap.
End FieldDivision.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to leq_divMp.")]
Notation leq_trunc_divp := leq_divMp.
End Field.
Module ClosedField.
Import Field.
Section closed.
Variable F : closedFieldType.
Lemma root_coprimep (p q : {poly F}) :
(forall x, root p x -> q.[x] != 0) -> coprimep p q.
Proof.
move=> Ncmn; rewrite -gcdp_eqp1 -size_poly_eq1; apply/closed_rootP.
by case=> r; rewrite root_gcd !rootE=> /andP [/Ncmn/negPf->].
Qed.
Lemma coprimepP (p q : {poly F}) :
reflect (forall x, root p x -> q.[x] != 0) (coprimep p q).
Proof. by apply: (iffP idP)=> [/coprimep_root|/root_coprimep]. Qed.
End closed.
End ClosedField.
End Pdiv.
Export Pdiv.Field.
|
ConstructibleSet.lean
|
/-
Copyright (c) 2024 Yaël Dillies, Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Andrew Yang
-/
import Mathlib.Order.SuccPred.WithBot
import Mathlib.RingTheory.Spectrum.Prime.Topology
/-!
# Constructible sets in the prime spectrum
This file provides tooling for manipulating constructible sets in the prime spectrum of a ring.
-/
open Finset Topology
open scoped Polynomial
namespace PrimeSpectrum
variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring T]
variable (R) in
/-- The data of a basic constructible set `s` is a tuple `(f, g₁, ..., gₙ)` -/
@[ext]
structure BasicConstructibleSetData where
/-- Given the data of a basic constructible set `s = V(g₁, ..., gₙ) \ V(f)`, return `f`. -/
protected f : R
/-- Given the data of a basic constructible set `s = V(g₁, ..., gₙ) \ V(f)`, return `n`. -/
protected n : ℕ
/-- Given the data of a basic constructible set `s = V(g₁, ..., gₙ) \ V(f)`, return `g`. -/
protected g : Fin n → R
namespace BasicConstructibleSetData
noncomputable instance : DecidableEq (BasicConstructibleSetData R) := Classical.decEq _
/-- Given the data of the constructible set `s`, build the data of the constructible set
`{I | {x | φ x ∈ I} ∈ s}`. -/
@[simps]
noncomputable def map (φ : R →+* S) (C : BasicConstructibleSetData R) :
BasicConstructibleSetData S where
f := φ C.f
n := C.n
g := φ ∘ C.g
@[simp] lemma map_id (C : BasicConstructibleSetData R) : C.map (.id _) = C := by simp [map]
@[simp] lemma map_id' : map (.id R) = id := by ext : 1; simp
lemma map_comp (φ : S →+* T) (ψ : R →+* S) (C : BasicConstructibleSetData R) :
C.map (φ.comp ψ) = (C.map ψ).map φ := by simp [map, Function.comp_def]
lemma map_comp' (φ : S →+* T) (ψ : R →+* S) : map (φ.comp ψ) = map φ ∘ map ψ := by
ext : 1; simp [map_comp]
/-- Given the data of a basic constructible set `s`, namely a tuple `(f, g₁, ..., gₙ)` such that
`s = V(g₁, ..., gₙ) \ V(f)`, return `s`. -/
def toSet (C : BasicConstructibleSetData R) : Set (PrimeSpectrum R) :=
zeroLocus (Set.range C.g) \ zeroLocus {C.f}
@[simp]
lemma toSet_map (φ : R →+* S) (C : BasicConstructibleSetData R) :
(C.map φ).toSet = comap φ ⁻¹' C.toSet := by simp [toSet, map, ← Set.range_comp]
end BasicConstructibleSetData
variable (R) in
/-- The data of a constructible set `s` in the prime spectrum of a ring is finitely many tuples
`(f, g₁, ..., gₙ)` such that `s = ⋃ (f, g₁, ..., gₙ), V(g₁, ..., gₙ) \ V(f)`.
To obtain `s` from its data, use `PrimeSpectrum.ConstructibleSetData.toSet`. -/
abbrev ConstructibleSetData := Finset (BasicConstructibleSetData R)
namespace ConstructibleSetData
/-- Given the data of the constructible set `s`, build the data of the constructible set
`{I | {x | f x ∈ I} ∈ s}`. -/
noncomputable def map (φ : R →+* S) (s : ConstructibleSetData R) : ConstructibleSetData S :=
s.image (.map φ)
@[simp]
lemma map_id (s : ConstructibleSetData R) : s.map (.id _) = s := by simp [map]
lemma map_comp (f : S →+* T) (g : R →+* S) (s : ConstructibleSetData R) :
s.map (f.comp g) = (s.map g).map f := by
simp [map, image_image, Function.comp_def, BasicConstructibleSetData.map_comp']
/-- Given the data of a constructible set `s`, namely finitely many tuples `(f, g₁, ..., gₙ)` such
that `s = ⋃ (f, g₁, ..., gₙ), V(g₁, ..., gₙ) \ V(f)`, return `s`. -/
def toSet (S : ConstructibleSetData R) : Set (PrimeSpectrum R) := ⋃ C ∈ S, C.toSet
@[simp]
lemma toSet_map (f : R →+* S) (s : ConstructibleSetData R) :
(s.map f).toSet = comap f ⁻¹' s.toSet := by
unfold toSet map
rw [set_biUnion_finset_image]
simp
/-- The degree bound on a constructible set for Chevalley's theorem for the inclusion `R ↪ R[X]`. -/
def degBound (S : ConstructibleSetData R[X]) : ℕ := S.sup fun C ↦ ∑ i, (C.g i).degree.succ
lemma isConstructible_toSet (S : ConstructibleSetData R) :
IsConstructible S.toSet := by
refine .biUnion S.finite_toSet fun _ _ ↦ .sdiff ?_ ?_
· rw [← isConstructible_compl]
exact (isRetrocompact_zeroLocus_compl (Set.finite_range _)).isConstructible
(isClosed_zeroLocus _).isOpen_compl
· rw [← isConstructible_compl]
exact (isRetrocompact_zeroLocus_compl (Set.finite_singleton _)).isConstructible
(isClosed_zeroLocus _).isOpen_compl
end ConstructibleSetData
lemma exists_constructibleSetData_iff {s : Set (PrimeSpectrum R)} :
(∃ S : ConstructibleSetData R, S.toSet = s) ↔ IsConstructible s := by
refine ⟨fun ⟨S, H⟩ ↦ H ▸ S.isConstructible_toSet, fun H ↦ ?_⟩
induction s, H using IsConstructible.induction_of_isTopologicalBasis
_ (isTopologicalBasis_basic_opens (R := R)) with
| isCompact_basis i => exact isCompact_basicOpen _
| sdiff i s hs =>
have : Finite s := hs
refine ⟨{⟨i, Nat.card s, fun i ↦ ((Finite.equivFin s).symm i).1⟩}, ?_⟩
simp only [ConstructibleSetData.toSet, Finset.mem_singleton, BasicConstructibleSetData.toSet,
Set.iUnion_iUnion_eq_left, basicOpen_eq_zeroLocus_compl, ← Set.compl_iInter₂,
compl_sdiff_compl, ← zeroLocus_iUnion₂, Set.biUnion_of_singleton]
congr! 2
ext
simp [← (Finite.equivFin s).exists_congr_right, - Nat.card_coe_set_eq]
| union s hs t ht Hs Ht =>
obtain ⟨S, rfl⟩ := Hs
obtain ⟨T, rfl⟩ := Ht
refine ⟨S ∪ T, ?_⟩
simp only [ConstructibleSetData.toSet, Set.biUnion_union, ← Finset.mem_coe, Finset.coe_union]
universe u in
@[stacks 00F8 "without the finite presentation part"]
-- TODO: show that the constructed `f` is of finite presentation
lemma exists_range_eq_of_isConstructible {R : Type u} [CommRing R]
{s : Set (PrimeSpectrum R)} (hs : IsConstructible s) :
∃ (S : Type u) (_ : CommRing S) (f : R →+* S), Set.range (comap f) = s := by
obtain ⟨s, rfl⟩ := exists_constructibleSetData_iff.mpr hs
refine ⟨Π i : s, Localization.Away (Ideal.Quotient.mk (Ideal.span (Set.range i.1.g)) i.1.f),
inferInstance, algebraMap _ _, ?_⟩
rw [coe_comap, ← iUnion_range_specComap_comp_evalRingHom, ConstructibleSetData.toSet]
simp_rw [← Finset.mem_coe, Set.biUnion_eq_iUnion]
congr! with _ _ C
let I := Ideal.span (Set.range C.1.g)
let f := Ideal.Quotient.mk I C.1.f
trans comap (Ideal.Quotient.mk I) '' (Set.range (comap (algebraMap _ (Localization.Away f))))
· rw [← Set.range_comp]; rfl
· rw [localization_away_comap_range _ f, ← comap_basicOpen, TopologicalSpace.Opens.coe_comap,
Set.image_preimage_eq_inter_range, range_comap_of_surjective _ _ Ideal.Quotient.mk_surjective,
BasicConstructibleSetData.toSet, Set.diff_eq_compl_inter, basicOpen_eq_zeroLocus_compl,
Ideal.mk_ker, zeroLocus_span]
@[stacks 00I0 "(1)"]
lemma isClosed_of_stableUnderSpecialization_of_isConstructible {R : Type*} [CommRing R]
{s : Set (PrimeSpectrum R)} (hs : StableUnderSpecialization s) (hs' : IsConstructible s) :
IsClosed s := by
obtain ⟨S, _, f, rfl⟩ := exists_range_eq_of_isConstructible hs'
exact isClosed_range_of_stableUnderSpecialization _ hs
@[stacks 00I0 "(1)"]
lemma isOpen_of_stableUnderGeneralization_of_isConstructible {R : Type*} [CommRing R]
{s : Set (PrimeSpectrum R)} (hs : StableUnderGeneralization s) (hs' : IsConstructible s) :
IsOpen s := by
rw [← isClosed_compl_iff]
exact isClosed_of_stableUnderSpecialization_of_isConstructible hs.compl hs'.compl
end PrimeSpectrum
|
GoingUp.lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Yongle Hu
-/
import Mathlib.RingTheory.Ideal.Over
import Mathlib.RingTheory.Localization.AtPrime.Basic
import Mathlib.RingTheory.Localization.Integral
/-!
# Ideals over/under ideals in integral extensions
This file proves some going-up results for integral algebras.
## Implementation notes
The proofs of the `comap_ne_bot` and `comap_lt_comap` families use an approach
specific for their situation: we construct an element in `I.comap f` from the
coefficients of a minimal polynomial.
Once mathlib has more material on the localization at a prime ideal, the results
can be proven using more general going-up/going-down theory.
-/
open Polynomial Submodule
open scoped Pointwise
namespace Ideal
section
variable {R : Type*} [CommRing R]
variable {S : Type*} [CommRing S] {f : R →+* S} {I J : Ideal S}
theorem coeff_zero_mem_comap_of_root_mem_of_eval_mem {r : S} (hr : r ∈ I) {p : R[X]}
(hp : p.eval₂ f r ∈ I) : p.coeff 0 ∈ I.comap f := by
rw [← p.divX_mul_X_add, eval₂_add, eval₂_C, eval₂_mul, eval₂_X] at hp
refine mem_comap.mpr ((I.add_mem_iff_right ?_).mp hp)
exact I.mul_mem_left _ hr
theorem coeff_zero_mem_comap_of_root_mem {r : S} (hr : r ∈ I) {p : R[X]} (hp : p.eval₂ f r = 0) :
p.coeff 0 ∈ I.comap f :=
coeff_zero_mem_comap_of_root_mem_of_eval_mem hr (hp.symm ▸ I.zero_mem)
theorem exists_coeff_ne_zero_mem_comap_of_non_zero_divisor_root_mem {r : S}
(r_non_zero_divisor : ∀ {x}, x * r = 0 → x = 0) (hr : r ∈ I) {p : R[X]} :
p ≠ 0 → p.eval₂ f r = 0 → ∃ i, p.coeff i ≠ 0 ∧ p.coeff i ∈ I.comap f := by
refine p.recOnHorner ?_ ?_ ?_
· intro h
contradiction
· intro p a coeff_eq_zero a_ne_zero _ _ hp
refine ⟨0, ?_, coeff_zero_mem_comap_of_root_mem hr hp⟩
simp [coeff_eq_zero, a_ne_zero]
· intro p p_nonzero ih _ hp
rw [eval₂_mul, eval₂_X] at hp
obtain ⟨i, hi, mem⟩ := ih p_nonzero (r_non_zero_divisor hp)
refine ⟨i + 1, ?_, ?_⟩
· simp [hi]
· simpa [hi] using mem
/-- Let `P` be an ideal in `R[x]`. The map
`R[x]/P → (R / (P ∩ R))[x] / (P / (P ∩ R))`
is injective.
-/
theorem injective_quotient_le_comap_map (P : Ideal R[X]) :
Function.Injective <|
Ideal.quotientMap
(Ideal.map (Polynomial.mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P)
(Polynomial.mapRingHom (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))))
le_comap_map := by
refine quotientMap_injective' (le_of_eq ?_)
rw [comap_map_of_surjective (mapRingHom (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))))
(map_surjective (Ideal.Quotient.mk (P.comap (C : R →+* R[X]))) Ideal.Quotient.mk_surjective)]
refine le_antisymm (sup_le le_rfl ?_) (le_sup_of_le_left le_rfl)
refine fun p hp =>
polynomial_mem_ideal_of_coeff_mem_ideal P p fun n => Ideal.Quotient.eq_zero_iff_mem.mp ?_
simpa only [coeff_map, coe_mapRingHom] using ext_iff.mp (Ideal.mem_bot.mp (mem_comap.mp hp)) n
/-- The identity in this lemma asserts that the "obvious" square
```
R → (R / (P ∩ R))
↓ ↓
R[x] / P → (R / (P ∩ R))[x] / (P / (P ∩ R))
```
commutes. It is used, for instance, in the proof of `quotient_mk_comp_C_is_integral_of_jacobson`,
in the file `Mathlib/RingTheory/Jacobson/Polynomial.lean`.
-/
theorem quotient_mk_maps_eq (P : Ideal R[X]) :
((Quotient.mk (map (mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P)).comp C).comp
(Quotient.mk (P.comap (C : R →+* R[X]))) =
(Ideal.quotientMap (map (mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) P)
(mapRingHom (Quotient.mk (P.comap (C : R →+* R[X])))) le_comap_map).comp
((Quotient.mk P).comp C) := by
refine RingHom.ext fun x => ?_
repeat' rw [RingHom.coe_comp, Function.comp_apply]
rw [quotientMap_mk, coe_mapRingHom, map_C]
/-- This technical lemma asserts the existence of a polynomial `p` in an ideal `P ⊂ R[x]`
that is non-zero in the quotient `R / (P ∩ R) [x]`. The assumptions are equivalent to
`P ≠ 0` and `P ∩ R = (0)`.
-/
theorem exists_nonzero_mem_of_ne_bot {P : Ideal R[X]} (Pb : P ≠ ⊥) (hP : ∀ x : R, C x ∈ P → x = 0) :
∃ p : R[X], p ∈ P ∧ Polynomial.map (Quotient.mk (P.comap (C : R →+* R[X]))) p ≠ 0 := by
obtain ⟨m, hm⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr Pb)
refine ⟨m, Submodule.coe_mem m, fun pp0 => hm (Submodule.coe_eq_zero.mp ?_)⟩
refine
(injective_iff_map_eq_zero (Polynomial.mapRingHom (Ideal.Quotient.mk
(P.comap (C : R →+* R[X]))))).mp
?_ _ pp0
refine map_injective _ ((RingHom.injective_iff_ker_eq_bot (Ideal.Quotient.mk (P.comap C))).mpr ?_)
rw [mk_ker]
exact (Submodule.eq_bot_iff _).mpr fun x hx => hP x (mem_comap.mp hx)
end
section IsDomain
variable {R : Type*} [CommRing R]
variable {S : Type*} [CommRing S] {f : R →+* S} {I J : Ideal S}
theorem exists_coeff_ne_zero_mem_comap_of_root_mem [IsDomain S] {r : S} (r_ne_zero : r ≠ 0)
(hr : r ∈ I) {p : R[X]} :
p ≠ 0 → p.eval₂ f r = 0 → ∃ i, p.coeff i ≠ 0 ∧ p.coeff i ∈ I.comap f :=
exists_coeff_ne_zero_mem_comap_of_non_zero_divisor_root_mem
(fun {_} h => Or.resolve_right (mul_eq_zero.mp h) r_ne_zero) hr
theorem exists_coeff_mem_comap_sdiff_comap_of_root_mem_sdiff [IsPrime I] (hIJ : I ≤ J) {r : S}
(hr : r ∈ (J : Set S) \ I) {p : R[X]} (p_ne_zero : p.map (Quotient.mk (I.comap f)) ≠ 0)
(hpI : p.eval₂ f r ∈ I) : ∃ i, p.coeff i ∈ (J.comap f : Set R) \ I.comap f := by
obtain ⟨hrJ, hrI⟩ := hr
have rbar_ne_zero : Ideal.Quotient.mk I r ≠ 0 := mt (Quotient.mk_eq_zero I).mp hrI
have rbar_mem_J : Ideal.Quotient.mk I r ∈ J.map (Ideal.Quotient.mk I) := mem_map_of_mem _ hrJ
have quotient_f : ∀ x ∈ I.comap f, (Ideal.Quotient.mk I).comp f x = 0 := by
simp [Quotient.eq_zero_iff_mem]
have rbar_root :
(p.map (Ideal.Quotient.mk (I.comap f))).eval₂ (Quotient.lift (I.comap f) _ quotient_f)
(Ideal.Quotient.mk I r) =
0 := by
convert Quotient.eq_zero_iff_mem.mpr hpI
exact _root_.trans (eval₂_map _ _ _) (hom_eval₂ p f (Ideal.Quotient.mk I) r).symm
obtain ⟨i, ne_zero, mem⟩ :=
exists_coeff_ne_zero_mem_comap_of_root_mem rbar_ne_zero rbar_mem_J p_ne_zero rbar_root
rw [coeff_map] at ne_zero mem
refine ⟨i, (mem_quotient_iff_mem hIJ).mp ?_, mt ?_ ne_zero⟩
· simpa using mem
simp [Quotient.eq_zero_iff_mem]
theorem comap_lt_comap_of_root_mem_sdiff [I.IsPrime] (hIJ : I ≤ J) {r : S}
(hr : r ∈ (J : Set S) \ I) {p : R[X]} (p_ne_zero : p.map (Quotient.mk (I.comap f)) ≠ 0)
(hp : p.eval₂ f r ∈ I) : I.comap f < J.comap f :=
let ⟨i, hJ, hI⟩ := exists_coeff_mem_comap_sdiff_comap_of_root_mem_sdiff hIJ hr p_ne_zero hp
SetLike.lt_iff_le_and_exists.mpr ⟨comap_mono hIJ, p.coeff i, hJ, hI⟩
theorem mem_of_one_mem (h : (1 : S) ∈ I) (x) : x ∈ I :=
(I.eq_top_iff_one.mpr h).symm ▸ mem_top
theorem comap_lt_comap_of_integral_mem_sdiff [Algebra R S] [hI : I.IsPrime] (hIJ : I ≤ J) {x : S}
(mem : x ∈ (J : Set S) \ I) (integral : IsIntegral R x) :
I.comap (algebraMap R S) < J.comap (algebraMap R S) := by
obtain ⟨p, p_monic, hpx⟩ := integral
refine comap_lt_comap_of_root_mem_sdiff hIJ mem (map_monic_ne_zero p_monic) ?_
convert I.zero_mem
theorem comap_ne_bot_of_root_mem [IsDomain S] {r : S} (r_ne_zero : r ≠ 0) (hr : r ∈ I) {p : R[X]}
(p_ne_zero : p ≠ 0) (hp : p.eval₂ f r = 0) : I.comap f ≠ ⊥ := fun h =>
let ⟨_, hi, mem⟩ := exists_coeff_ne_zero_mem_comap_of_root_mem r_ne_zero hr p_ne_zero hp
absurd (mem_bot.mp (eq_bot_iff.mp h mem)) hi
theorem isMaximal_of_isIntegral_of_isMaximal_comap [Algebra R S] [Algebra.IsIntegral R S]
(I : Ideal S) [I.IsPrime] (hI : IsMaximal (I.comap (algebraMap R S))) : IsMaximal I :=
⟨⟨mt comap_eq_top_iff.mpr hI.1.1, fun _ I_lt_J =>
let ⟨I_le_J, x, hxJ, hxI⟩ := SetLike.lt_iff_le_and_exists.mp I_lt_J
comap_eq_top_iff.1 <|
hI.1.2 _ (comap_lt_comap_of_integral_mem_sdiff I_le_J ⟨hxJ, hxI⟩
(Algebra.IsIntegral.isIntegral x))⟩⟩
theorem isMaximal_of_isIntegral_of_isMaximal_comap' (f : R →+* S) (hf : f.IsIntegral) (I : Ideal S)
[I.IsPrime] (hI : IsMaximal (I.comap f)) : IsMaximal I :=
let _ : Algebra R S := f.toAlgebra
have : Algebra.IsIntegral R S := ⟨hf⟩
isMaximal_of_isIntegral_of_isMaximal_comap (R := R) (S := S) I hI
variable [Algebra R S]
theorem comap_ne_bot_of_algebraic_mem [IsDomain S] {x : S} (x_ne_zero : x ≠ 0) (x_mem : x ∈ I)
(hx : IsAlgebraic R x) : I.comap (algebraMap R S) ≠ ⊥ :=
let ⟨_, p_ne_zero, hp⟩ := hx
comap_ne_bot_of_root_mem x_ne_zero x_mem p_ne_zero hp
theorem comap_ne_bot_of_integral_mem [Nontrivial R] [IsDomain S] {x : S} (x_ne_zero : x ≠ 0)
(x_mem : x ∈ I) (hx : IsIntegral R x) : I.comap (algebraMap R S) ≠ ⊥ :=
comap_ne_bot_of_algebraic_mem x_ne_zero x_mem hx.isAlgebraic
theorem eq_bot_of_comap_eq_bot [Nontrivial R] [IsDomain S] [Algebra.IsIntegral R S]
(hI : I.comap (algebraMap R S) = ⊥) : I = ⊥ := by
refine eq_bot_iff.2 fun x hx => ?_
by_cases hx0 : x = 0
· exact hx0.symm ▸ Ideal.zero_mem ⊥
· exact absurd hI (comap_ne_bot_of_integral_mem hx0 hx (Algebra.IsIntegral.isIntegral x))
theorem isMaximal_comap_of_isIntegral_of_isMaximal [Algebra.IsIntegral R S] (I : Ideal S)
[hI : I.IsMaximal] : IsMaximal (I.comap (algebraMap R S)) := by
refine Ideal.Quotient.maximal_of_isField _ ?_
haveI : IsPrime (I.comap (algebraMap R S)) := comap_isPrime _ _
exact isField_of_isIntegral_of_isField
algebraMap_quotient_injective (by rwa [← Quotient.maximal_ideal_iff_isField_quotient])
theorem isMaximal_comap_of_isIntegral_of_isMaximal' {R S : Type*} [CommRing R] [CommRing S]
(f : R →+* S) (hf : f.IsIntegral) (I : Ideal S) [I.IsMaximal] : IsMaximal (I.comap f) :=
let _ : Algebra R S := f.toAlgebra
have : Algebra.IsIntegral R S := ⟨hf⟩
isMaximal_comap_of_isIntegral_of_isMaximal (R := R) (S := S) I
section IsIntegralClosure
variable (S) {A : Type*} [CommRing A]
variable [Algebra R A] [Algebra A S] [IsScalarTower R A S] [IsIntegralClosure A R S]
include S
theorem IsIntegralClosure.comap_lt_comap {I J : Ideal A} [I.IsPrime] (I_lt_J : I < J) :
I.comap (algebraMap R A) < J.comap (algebraMap R A) :=
let ⟨I_le_J, x, hxJ, hxI⟩ := SetLike.lt_iff_le_and_exists.mp I_lt_J
comap_lt_comap_of_integral_mem_sdiff I_le_J ⟨hxJ, hxI⟩ (IsIntegralClosure.isIntegral R S x)
theorem IsIntegralClosure.isMaximal_of_isMaximal_comap (I : Ideal A) [I.IsPrime]
(hI : IsMaximal (I.comap (algebraMap R A))) : IsMaximal I :=
have : Algebra.IsIntegral R A := IsIntegralClosure.isIntegral_algebra R S
isMaximal_of_isIntegral_of_isMaximal_comap I hI
variable [IsDomain A]
theorem IsIntegralClosure.comap_ne_bot [Nontrivial R] {I : Ideal A} (I_ne_bot : I ≠ ⊥) :
I.comap (algebraMap R A) ≠ ⊥ :=
let ⟨x, x_mem, x_ne_zero⟩ := I.ne_bot_iff.mp I_ne_bot
comap_ne_bot_of_integral_mem x_ne_zero x_mem (IsIntegralClosure.isIntegral R S x)
theorem IsIntegralClosure.eq_bot_of_comap_eq_bot [Nontrivial R] {I : Ideal A} :
I.comap (algebraMap R A) = ⊥ → I = ⊥ := by
-- Porting note: `imp_of_not_imp_not` seems not existing
contrapose; exact (IsIntegralClosure.comap_ne_bot S)
end IsIntegralClosure
theorem IntegralClosure.comap_lt_comap {I J : Ideal (integralClosure R S)} [I.IsPrime]
(I_lt_J : I < J) :
I.comap (algebraMap R (integralClosure R S)) < J.comap (algebraMap R (integralClosure R S)) :=
IsIntegralClosure.comap_lt_comap S I_lt_J
theorem IntegralClosure.isMaximal_of_isMaximal_comap (I : Ideal (integralClosure R S)) [I.IsPrime]
(hI : IsMaximal (I.comap (algebraMap R (integralClosure R S)))) : IsMaximal I :=
IsIntegralClosure.isMaximal_of_isMaximal_comap S I hI
section
variable [IsDomain S]
theorem IntegralClosure.comap_ne_bot [Nontrivial R] {I : Ideal (integralClosure R S)}
(I_ne_bot : I ≠ ⊥) : I.comap (algebraMap R (integralClosure R S)) ≠ ⊥ :=
IsIntegralClosure.comap_ne_bot S I_ne_bot
theorem IntegralClosure.eq_bot_of_comap_eq_bot [Nontrivial R] {I : Ideal (integralClosure R S)} :
I.comap (algebraMap R (integralClosure R S)) = ⊥ → I = ⊥ :=
IsIntegralClosure.eq_bot_of_comap_eq_bot S
/-- `comap (algebraMap R S)` is a surjection from the prime spec of `R` to prime spec of `S`.
`hP : (algebraMap R S).ker ≤ P` is a slight generalization of the extension being injective -/
theorem exists_ideal_over_prime_of_isIntegral_of_isDomain [Algebra.IsIntegral R S] (P : Ideal R)
[IsPrime P] (hP : RingHom.ker (algebraMap R S) ≤ P) :
∃ Q : Ideal S, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by
have hP0 : (0 : S) ∉ Algebra.algebraMapSubmonoid S P.primeCompl := by
rintro ⟨x, ⟨hx, x0⟩⟩
exact absurd (hP x0) hx
let Rₚ := Localization P.primeCompl
let Sₚ := Localization (Algebra.algebraMapSubmonoid S P.primeCompl)
letI : IsDomain (Localization (Algebra.algebraMapSubmonoid S P.primeCompl)) :=
IsLocalization.isDomain_localization (le_nonZeroDivisors_of_noZeroDivisors hP0)
obtain ⟨Qₚ : Ideal Sₚ, Qₚ_maximal⟩ := exists_maximal Sₚ
let _ : Algebra Rₚ Sₚ := localizationAlgebra P.primeCompl S
have : Algebra.IsIntegral Rₚ Sₚ := ⟨isIntegral_localization⟩
have Qₚ_max : IsMaximal (comap _ Qₚ) :=
isMaximal_comap_of_isIntegral_of_isMaximal (R := Rₚ) (S := Sₚ) Qₚ
refine ⟨comap (algebraMap S Sₚ) Qₚ, ⟨comap_isPrime _ Qₚ, ?_⟩⟩
convert Localization.AtPrime.comap_maximalIdeal (I := P)
rw [comap_comap, ← IsLocalRing.eq_maximalIdeal Qₚ_max,
← IsLocalization.map_comp (P := S) (Q := Sₚ) (g := algebraMap R S)
(M := P.primeCompl) (T := Algebra.algebraMapSubmonoid S P.primeCompl) (S := Rₚ)
(fun p hp => Algebra.mem_algebraMapSubmonoid_of_mem ⟨p, hp⟩) ]
rfl
end
/-- More general going-up theorem than `exists_ideal_over_prime_of_isIntegral_of_isDomain`.
TODO: Version of going-up theorem with arbitrary length chains (by induction on this)?
Not sure how best to write an ascending chain in Lean -/
theorem exists_ideal_over_prime_of_isIntegral_of_isPrime
[Algebra.IsIntegral R S] (P : Ideal R) [IsPrime P]
(I : Ideal S) [IsPrime I] (hIP : I.comap (algebraMap R S) ≤ P) :
∃ Q ≥ I, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by
obtain ⟨Q' : Ideal (S ⧸ I), ⟨Q'_prime, hQ'⟩⟩ :=
@exists_ideal_over_prime_of_isIntegral_of_isDomain (R ⧸ I.comap (algebraMap R S)) _ (S ⧸ I) _
Ideal.quotientAlgebra _ _
(map (Ideal.Quotient.mk (I.comap (algebraMap R S))) P)
(map_isPrime_of_surjective Quotient.mk_surjective (by simp [hIP]))
(le_trans (le_of_eq ((RingHom.injective_iff_ker_eq_bot _).1 algebraMap_quotient_injective))
bot_le)
refine ⟨Q'.comap _, le_trans (le_of_eq mk_ker.symm) (ker_le_comap _), ⟨comap_isPrime _ Q', ?_⟩⟩
rw [comap_comap]
refine _root_.trans ?_ (_root_.trans (congr_arg (comap (Ideal.Quotient.mk
(comap (algebraMap R S) I))) hQ') ?_)
· rw [comap_comap]
exact congr_arg (comap · Q') (RingHom.ext fun r => rfl)
· refine _root_.trans (comap_map_of_surjective _ Quotient.mk_surjective _) (sup_eq_left.2 ?_)
simpa [← RingHom.ker_eq_comap_bot] using hIP
theorem exists_ideal_over_prime_of_isIntegral [Algebra.IsIntegral R S] (P : Ideal R) [IsPrime P]
(I : Ideal S) (hIP : I.comap (algebraMap R S) ≤ P) :
∃ Q ≥ I, IsPrime Q ∧ Q.comap (algebraMap R S) = P := by
have ⟨P', hP, hP', hP''⟩ := exists_ideal_comap_le_prime P I hIP
obtain ⟨Q, hQ, hQ', hQ''⟩ := exists_ideal_over_prime_of_isIntegral_of_isPrime P P' hP''
exact ⟨Q, hP.trans hQ, hQ', hQ''⟩
/-- `comap (algebraMap R S)` is a surjection from the max spec of `S` to max spec of `R`.
`hP : (algebraMap R S).ker ≤ P` is a slight generalization of the extension being injective -/
theorem exists_ideal_over_maximal_of_isIntegral [Algebra.IsIntegral R S]
(P : Ideal R) [P_max : IsMaximal P] (hP : RingHom.ker (algebraMap R S) ≤ P) :
∃ Q : Ideal S, IsMaximal Q ∧ Q.comap (algebraMap R S) = P := by
obtain ⟨Q, -, Q_prime, hQ⟩ := exists_ideal_over_prime_of_isIntegral P ⊥ hP
exact ⟨Q, isMaximal_of_isIntegral_of_isMaximal_comap _ (hQ.symm ▸ P_max), hQ⟩
lemma map_eq_top_iff_of_ker_le {R S} [CommRing R] [CommRing S]
(f : R →+* S) {I : Ideal R} (hf₁ : RingHom.ker f ≤ I) (hf₂ : f.IsIntegral) :
I.map f = ⊤ ↔ I = ⊤ := by
constructor; swap
· rintro rfl; exact Ideal.map_top _
contrapose
intro h
obtain ⟨m, _, hm⟩ := Ideal.exists_le_maximal I h
let _ := f.toAlgebra
have : Algebra.IsIntegral _ _ := ⟨hf₂⟩
obtain ⟨m', _, rfl⟩ := exists_ideal_over_maximal_of_isIntegral m (hf₁.trans hm)
rw [← map_le_iff_le_comap] at hm
exact (hm.trans_lt (lt_top_iff_ne_top.mpr (IsMaximal.ne_top ‹_›))).ne
lemma map_eq_top_iff {R S} [CommRing R] [CommRing S]
(f : R →+* S) {I : Ideal R} (hf₁ : Function.Injective f) (hf₂ : f.IsIntegral) :
I.map f = ⊤ ↔ I = ⊤ :=
map_eq_top_iff_of_ker_le f (by simp [(RingHom.injective_iff_ker_eq_bot f).mp hf₁]) hf₂
end IsDomain
section IsIntegral
variable {A : Type*} [CommRing A] {B : Type*} [CommRing B] [Algebra A B] [Algebra.IsIntegral A B]
(P : Ideal B) (p : Ideal A) [P.LiesOver p]
variable (A) in
/-- If `B` is an integral `A`-algebra, `P` is a maximal ideal of `B`, then the pull back of
`P` is also a maximal ideal of `A`. -/
instance IsMaximal.under [P.IsMaximal] : (P.under A).IsMaximal :=
isMaximal_comap_of_isIntegral_of_isMaximal P
theorem IsMaximal.of_liesOver_isMaximal [hpm : p.IsMaximal] [P.IsPrime] : P.IsMaximal := by
rw [P.over_def p] at hpm
exact isMaximal_of_isIntegral_of_isMaximal_comap P hpm
theorem IsMaximal.of_isMaximal_liesOver [P.IsMaximal] : p.IsMaximal := by
rw [P.over_def p]
exact isMaximal_comap_of_isIntegral_of_isMaximal P
/-- `B ⧸ P` is an integral `A ⧸ p`-algebra if `B` is a integral `A`-algebra. -/
instance Quotient.algebra_isIntegral_of_liesOver : Algebra.IsIntegral (A ⧸ p) (B ⧸ P) :=
Algebra.IsIntegral.tower_top A
theorem exists_ideal_liesOver_maximal_of_isIntegral [p.IsMaximal] (B : Type*) [CommRing B]
[Nontrivial B] [Algebra A B] [NoZeroSMulDivisors A B] [Algebra.IsIntegral A B] :
∃ P : Ideal B, P.IsMaximal ∧ P.LiesOver p := by
obtain ⟨P, hm, hP⟩ := exists_ideal_over_maximal_of_isIntegral (S := B) p <| by simp
exact ⟨P, hm, ⟨hP.symm⟩⟩
end IsIntegral
section IsIntegral
variable {A : Type*} [CommRing A] {p : Ideal A} [p.IsMaximal] {B : Type*} [CommRing B]
[Algebra A B] [NoZeroSMulDivisors A B] [Algebra.IsIntegral A B] (Q : primesOver p B)
instance primesOver.isMaximal : Q.1.IsMaximal :=
Ideal.IsMaximal.of_liesOver_isMaximal Q.1 p
variable (A B) in
lemma primesOver_bot [Nontrivial A] [IsDomain B] : primesOver (⊥ : Ideal A) B = {⊥} := by
ext p
refine ⟨fun ⟨_, ⟨h⟩⟩ ↦ p.eq_bot_of_comap_eq_bot h.symm, ?_⟩
rintro rfl
exact ⟨Ideal.bot_prime, Ideal.bot_liesOver_bot A B⟩
end IsIntegral
end Ideal
|
Header.lean
|
/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Tactic.Linter.Header
import Lake
import Mathlib.Tactic.Linter.Header
import /- -/ Mathlib.Tactic -- the `TextBased` linter does not flag this `broadImport`
import Mathlib.Tactic.Have
import Mathlib.Deprecated.Aliases
/--
warning: In the past, importing 'Lake' in mathlib has led to dramatic slow-downs of the linter (see e.g. https://github.com/leanprover-community/mathlib4/pull/13779). Please consider carefully if this import is useful and make sure to benchmark it. If this is fine, feel free to silence this linter.
Note: This linter can be disabled with `set_option linter.style.header false`
---
warning: Files in mathlib cannot import the whole tactic folder.
Note: This linter can be disabled with `set_option linter.style.header false`
---
warning: 'Mathlib.Tactic.Have' defines a deprecated form of the 'have' tactic; please do not use it in mathlib.
Note: This linter can be disabled with `set_option linter.style.header false`
---
warning: Duplicate imports: 'Mathlib.Tactic.Linter.Header' already imported
Note: This linter can be disabled with `set_option linter.style.header false`
---
warning: The module doc-string for a file should be the first command after the imports.
Please, add a module doc-string before `/-!# Tests for the `docModule` linter
-/
`.
Note: This linter can be disabled with `set_option linter.style.header false`
-/
#guard_msgs in
set_option linter.style.header true in
/-!
# Tests for the `docModule` linter
-/
/--
A convenience function that replaces `/` with `|`.
This converts `/-` and `-/` into `|-` and `-|` that no longer interfere with the ending of the
`#guard_msgs` doc-string.
-/
def replaceMultilineComments (s : String) : String :=
s.replace "/" "|"
open Lean Elab Command in
/--
`#check_copyright cop` takes as input the `String` `cop`, expected to be a copyright statement.
It logs details of what the linter would report if the `cop` is "malformed".
-/
elab "#check_copyright " cop:str : command => do
let cop := cop.getString
for (s, m) in Mathlib.Linter.copyrightHeaderChecks cop do
if let some rg := s.getRange? then
logInfo
m!"Text: `{replaceMultilineComments s.getAtomVal}`\n\
Range: {(rg.start, rg.stop)}\n\
Message: '{replaceMultilineComments m}'"
-- well-formed
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName, Name LastName,
Name LastName,
Name LastName,
Name LastName
-/
"
/--
info: Text: ` |-`
Range: (0, 3)
Message: 'Malformed or missing copyright header: `|-` should be alone on its own line.'
-/
#guard_msgs in
#check_copyright
" /-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
-/
"
-- The last line does not end with a newline.
/--
info: Text: `-|`
Range: (149, 151)
Message: 'Malformed or missing copyright header: `-|` should be alone on its own line.'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
-/"
/--
info: Text: `Authors: Name LastName
Here comes an implicit docstring which doesn't belong here!`
Range: (126, 209)
Message: 'If an authors line spans multiple lines, each line but the last must end with a trailing comma'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
Here comes an implicit docstring which doesn't belong here!
-/
"
/--
info: Text: `Authors: Name LastName
Here comes an implicit docstring which shouldn't be here!`
Range: (126, 206)
Message: 'If an authors line spans multiple lines, each line but the last must end with a trailing comma'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
Here comes an implicit docstring which shouldn't be here!
-/
"
/--
info: Text: `-|`
Range: (126, 128)
Message: 'Copyright too short!'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
"
/--
info: Text: `-|`
Range: (1, 3)
Message: 'Copyright too short!'
-/
#guard_msgs in
#check_copyright ""
/--
info: Text: `-|`
Range: (1, 3)
Message: 'Copyright too short!'
-/
#guard_msgs in
#check_copyright ""
/--
info: Text: `Cpyright (c) 202`
Range: (3, 19)
Message: 'Copyright line should start with 'Copyright (c) YYYY''
-/
#guard_msgs in
#check_copyright
"/-
Cpyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
-/
"
/--
info: Text: `a. All rights reserve.`
Range: (34, 56)
Message: 'Copyright line should end with '. All rights reserved.''
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserve.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
-/
"
/--
info: Text: `Rleased under Apache 2.0 license as described in the file LICENSE.`
Range: (58, 124)
Message: 'Second copyright line should be
"Released under Apache 2.0 license as described in the file LICENSE."'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Rleased under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
-/
"
/--
info: Text: `A uthors:`
Range: (126, 135)
Message: 'The authors line should begin with 'Authors: ''
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
A uthors: Name LastName
-/
"
/--
info: Text: ` `
Range: (139, 141)
Message: 'Double spaces are not allowed.'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
-/
"
/--
info: Text: `.`
Range: (148, 149)
Message: 'Please, do not end the authors' line with a period.'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName.
-/
"
/--
info: Text: ` `
Range: (149, 151)
Message: 'Double spaces are not allowed.'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName,
Name LastName
-/
"
-- The `Copyright` and `Authors` lines are allowed to overflow.
#check_copyright
"/-
Copyright (c) 2019 Reid Barton, Johan Commelin, Jesse Michael Han, Chris Hughes, Robert Y. Lewis,
Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Johan Commelin, Jesse Michael Han, Chris Hughes, Robert Y. Lewis,
Patrick Massot
-/
"
-- However, in this case the wrapped lines must end with a comma.
/--
info: Text: `(c) 2024 Damiano Testa`
Range: (13, 35)
Message: 'Copyright line should end with '. All rights reserved.''
---
info: Text: `Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
and others.`
Range: (83, 187)
Message: 'If an authors line spans multiple lines, each line but the last must end with a trailing comma'
---
info: Text: `Released `
Range: (83, 92)
Message: 'The authors line should begin with 'Authors: ''
---
info: Text: ` `
Range: (174, 176)
Message: 'Double spaces are not allowed.'
---
info: Text: ` and `
Range: (175, 180)
Message: 'Please, do not use 'and'; use ',' instead.'
---
info: Text: `.`
Range: (106, 107)
Message: 'Please, do not end the authors' line with a period.'
---
info: Text: ` and many other authors. All rights reserved.`
Range: (36, 82)
Message: 'Second copyright line should be "Released under Apache 2.0 license as described in the file LICENSE."'
-/
#guard_msgs in
#check_copyright
"/-
Copyright (c) 2024 Damiano Testa
and many other authors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Name LastName
and others.
-/
"
|
Basic.lean
|
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Algebra.CharP.Basic
import Mathlib.Algebra.CharP.Lemmas
import Mathlib.Algebra.Ring.Regular
import Mathlib.Data.Fintype.Units
import Mathlib.GroupTheory.OrderOfElement
/-!
# Multiplicative characters of finite rings and fields
Let `R` and `R'` be a commutative rings.
A *multiplicative character* of `R` with values in `R'` is a morphism of
monoids from the multiplicative monoid of `R` into that of `R'`
that sends non-units to zero.
We use the namespace `MulChar` for the definitions and results.
## Main results
We show that the multiplicative characters form a group (if `R'` is commutative);
see `MulChar.commGroup`. We also provide an equivalence with the
homomorphisms `Rˣ →* R'ˣ`; see `MulChar.equivToUnitHom`.
We define a multiplicative character to be *quadratic* if its values
are among `0`, `1` and `-1`, and we prove some properties of quadratic characters.
Finally, we show that the sum of all values of a nontrivial multiplicative
character vanishes; see `MulChar.IsNontrivial.sum_eq_zero`.
## Tags
multiplicative character
-/
/-!
### Definitions related to multiplicative characters
Even though the intended use is when domain and target of the characters
are commutative rings, we define them in the more general setting when
the domain is a commutative monoid and the target is a commutative monoid
with zero. (We need a zero in the target, since non-units are supposed
to map to zero.)
In this setting, there is an equivalence between multiplicative characters
`R → R'` and group homomorphisms `Rˣ → R'ˣ`, and the multiplicative characters
have a natural structure as a commutative group.
-/
section Defi
-- The domain of our multiplicative characters
variable (R : Type*) [CommMonoid R]
-- The target
variable (R' : Type*) [CommMonoidWithZero R']
/-- Define a structure for multiplicative characters.
A multiplicative character from a commutative monoid `R` to a commutative monoid with zero `R'`
is a homomorphism of (multiplicative) monoids that sends non-units to zero. -/
structure MulChar extends MonoidHom R R' where
map_nonunit' : ∀ a : R, ¬IsUnit a → toFun a = 0
instance MulChar.instFunLike : FunLike (MulChar R R') R R' :=
⟨fun χ => χ.toFun,
fun χ₀ χ₁ h => by cases χ₀; cases χ₁; congr; apply MonoidHom.ext (fun _ => congr_fun h _)⟩
/-- This is the corresponding extension of `MonoidHomClass`. -/
class MulCharClass (F : Type*) (R R' : outParam Type*) [CommMonoid R]
[CommMonoidWithZero R'] [FunLike F R R'] : Prop extends MonoidHomClass F R R' where
map_nonunit : ∀ (χ : F) {a : R} (_ : ¬IsUnit a), χ a = 0
initialize_simps_projections MulChar (toFun → apply, -toMonoidHom)
end Defi
namespace MulChar
attribute [scoped simp] MulCharClass.map_nonunit
section Group
-- The domain of our multiplicative characters
variable {R : Type*} [CommMonoid R]
-- The target
variable {R' : Type*} [CommMonoidWithZero R']
variable (R R') in
/-- The trivial multiplicative character. It takes the value `0` on non-units and
the value `1` on units. -/
@[simps]
noncomputable def trivial : MulChar R R' where
toFun := by classical exact fun x => if IsUnit x then 1 else 0
map_nonunit' := by
intro a ha
simp only [ha, if_false]
map_one' := by simp only [isUnit_one, if_true]
map_mul' := by
intro x y
classical
simp only [IsUnit.mul_iff, boole_mul]
split_ifs <;> tauto
@[simp]
theorem coe_mk (f : R →* R') (hf) : (MulChar.mk f hf : R → R') = f :=
rfl
/-- Extensionality. See `ext` below for the version that will actually be used. -/
theorem ext' {χ χ' : MulChar R R'} (h : ∀ a, χ a = χ' a) : χ = χ' := by
cases χ
cases χ'
congr
exact MonoidHom.ext h
instance : MulCharClass (MulChar R R') R R' where
map_mul χ := χ.map_mul'
map_one χ := χ.map_one'
map_nonunit χ := χ.map_nonunit' _
theorem map_nonunit (χ : MulChar R R') {a : R} (ha : ¬IsUnit a) : χ a = 0 :=
χ.map_nonunit' a ha
/-- Extensionality. Since `MulChar`s always take the value zero on non-units, it is sufficient
to compare the values on units. -/
@[ext]
theorem ext {χ χ' : MulChar R R'} (h : ∀ a : Rˣ, χ a = χ' a) : χ = χ' := by
apply ext'
intro a
by_cases ha : IsUnit a
· exact h ha.unit
· rw [map_nonunit χ ha, map_nonunit χ' ha]
/-!
### Equivalence of multiplicative characters with homomorphisms on units
We show that restriction / extension by zero gives an equivalence
between `MulChar R R'` and `Rˣ →* R'ˣ`.
-/
/-- Turn a `MulChar` into a homomorphism between the unit groups. -/
def toUnitHom (χ : MulChar R R') : Rˣ →* R'ˣ :=
Units.map χ
theorem coe_toUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(χ.toUnitHom a) = χ a :=
rfl
/-- Turn a homomorphism between unit groups into a `MulChar`. -/
noncomputable def ofUnitHom (f : Rˣ →* R'ˣ) : MulChar R R' where
toFun := by classical exact fun x => if hx : IsUnit x then f hx.unit else 0
map_one' := by
have h1 : (isUnit_one.unit : Rˣ) = 1 := Units.ext rfl
simp only [h1, dif_pos, Units.val_eq_one, map_one, isUnit_one]
map_mul' := by
classical
intro x y
by_cases hx : IsUnit x
· simp only [hx, IsUnit.mul_iff, true_and, dif_pos]
by_cases hy : IsUnit y
· simp only [hy, dif_pos]
have hm : (hx.mul hy).unit = hx.unit * hy.unit := Units.ext rfl
rw [hm, map_mul]
norm_cast
· simp only [hy, not_false_iff, dif_neg, mul_zero]
· simp only [hx, IsUnit.mul_iff, false_and, not_false_iff, dif_neg, zero_mul]
map_nonunit' := by
intro a ha
simp only [ha, not_false_iff, dif_neg]
theorem ofUnitHom_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : ofUnitHom f ↑a = f a := by simp [ofUnitHom]
/-- The equivalence between multiplicative characters and homomorphisms of unit groups. -/
noncomputable def equivToUnitHom : MulChar R R' ≃ (Rˣ →* R'ˣ) where
toFun := toUnitHom
invFun := ofUnitHom
left_inv := by
intro χ
ext x
rw [ofUnitHom_coe, coe_toUnitHom]
right_inv := by
intro f
ext x
simp only [coe_toUnitHom, ofUnitHom_coe]
@[simp]
theorem toUnitHom_eq (χ : MulChar R R') : toUnitHom χ = equivToUnitHom χ :=
rfl
@[simp]
theorem ofUnitHom_eq (χ : Rˣ →* R'ˣ) : ofUnitHom χ = equivToUnitHom.symm χ :=
rfl
@[simp]
theorem coe_equivToUnitHom (χ : MulChar R R') (a : Rˣ) : ↑(equivToUnitHom χ a) = χ a :=
coe_toUnitHom χ a
@[simp]
theorem equivToUnitHom_symm_coe (f : Rˣ →* R'ˣ) (a : Rˣ) : equivToUnitHom.symm f ↑a = f a :=
ofUnitHom_coe f a
@[simp]
lemma coe_toMonoidHom (χ : MulChar R R')
(x : R) : χ.toMonoidHom x = χ x := rfl
/-!
### Commutative group structure on multiplicative characters
The multiplicative characters `R → R'` form a commutative group.
-/
protected theorem map_one (χ : MulChar R R') : χ (1 : R) = 1 :=
χ.map_one'
/-- If the domain has a zero (and is nontrivial), then `χ 0 = 0`. -/
protected theorem map_zero {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') :
χ (0 : R) = 0 := by rw [map_nonunit χ not_isUnit_zero]
/-- We can convert a multiplicative character into a homomorphism of monoids with zero when
the source has a zero and another element. -/
@[coe, simps]
def toMonoidWithZeroHom {R : Type*} [CommMonoidWithZero R] [Nontrivial R] (χ : MulChar R R') :
R →*₀ R' where
toFun := χ.toFun
map_zero' := χ.map_zero
map_one' := χ.map_one'
map_mul' := χ.map_mul'
/-- If the domain is a ring `R`, then `χ (ringChar R) = 0`. -/
theorem map_ringChar {R : Type*} [CommSemiring R] [Nontrivial R] (χ : MulChar R R') :
χ (ringChar R) = 0 := by rw [ringChar.Nat.cast_ringChar, χ.map_zero]
noncomputable instance hasOne : One (MulChar R R') :=
⟨trivial R R'⟩
noncomputable instance inhabited : Inhabited (MulChar R R') :=
⟨1⟩
/-- Evaluation of the trivial character -/
@[simp]
theorem one_apply_coe (a : Rˣ) : (1 : MulChar R R') a = 1 := by classical exact dif_pos a.isUnit
/-- Evaluation of the trivial character -/
lemma one_apply {x : R} (hx : IsUnit x) : (1 : MulChar R R') x = 1 := one_apply_coe hx.unit
/-- Multiplication of multiplicative characters. (This needs the target to be commutative.) -/
def mul (χ χ' : MulChar R R') : MulChar R R' :=
{ χ.toMonoidHom * χ'.toMonoidHom with
toFun := χ * χ'
map_nonunit' := fun a ha => by simp only [map_nonunit χ ha, zero_mul, Pi.mul_apply] }
instance hasMul : Mul (MulChar R R') :=
⟨mul⟩
theorem mul_apply (χ χ' : MulChar R R') (a : R) : (χ * χ') a = χ a * χ' a :=
rfl
@[simp]
theorem coeToFun_mul (χ χ' : MulChar R R') : ⇑(χ * χ') = χ * χ' :=
rfl
protected theorem one_mul (χ : MulChar R R') : (1 : MulChar R R') * χ = χ := by
ext
simp only [one_mul, Pi.mul_apply, MulChar.coeToFun_mul, MulChar.one_apply_coe]
protected theorem mul_one (χ : MulChar R R') : χ * 1 = χ := by
ext
simp only [mul_one, Pi.mul_apply, MulChar.coeToFun_mul, MulChar.one_apply_coe]
/-- The inverse of a multiplicative character. We define it as `inverse ∘ χ`. -/
noncomputable def inv (χ : MulChar R R') : MulChar R R' :=
{ MonoidWithZero.inverse.toMonoidHom.comp χ.toMonoidHom with
toFun := fun a => MonoidWithZero.inverse (χ a)
map_nonunit' := fun a ha => by simp [map_nonunit _ ha] }
noncomputable instance hasInv : Inv (MulChar R R') :=
⟨inv⟩
/-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`. -/
theorem inv_apply_eq_inv (χ : MulChar R R') (a : R) : χ⁻¹ a = Ring.inverse (χ a) :=
Eq.refl <| inv χ a
/-- The inverse of a multiplicative character `χ`, applied to `a`, is the inverse of `χ a`.
Variant when the target is a field -/
theorem inv_apply_eq_inv' {R' : Type*} [CommGroupWithZero R'] (χ : MulChar R R') (a : R) :
χ⁻¹ a = (χ a)⁻¹ :=
(inv_apply_eq_inv χ a).trans <| Ring.inverse_eq_inv (χ a)
/-- When the domain has a zero, then the inverse of a multiplicative character `χ`,
applied to `a`, is `χ` applied to the inverse of `a`. -/
theorem inv_apply {R : Type*} [CommMonoidWithZero R] (χ : MulChar R R') (a : R) :
χ⁻¹ a = χ (Ring.inverse a) := by
by_cases ha : IsUnit a
· rw [inv_apply_eq_inv]
have h := IsUnit.map χ ha
apply_fun (χ a * ·) using IsUnit.mul_right_injective h
dsimp only
rw [Ring.mul_inverse_cancel _ h, ← map_mul, Ring.mul_inverse_cancel _ ha, map_one]
· revert ha
nontriviality R
intro ha
-- `nontriviality R` by itself doesn't do it
rw [map_nonunit _ ha, Ring.inverse_non_unit a ha, MulChar.map_zero χ]
/-- When the domain has a zero, then the inverse of a multiplicative character `χ`,
applied to `a`, is `χ` applied to the inverse of `a`. -/
theorem inv_apply' {R : Type*} [CommGroupWithZero R] (χ : MulChar R R') (a : R) : χ⁻¹ a = χ a⁻¹ :=
(inv_apply χ a).trans <| congr_arg _ (Ring.inverse_eq_inv a)
/-- The product of a character with its inverse is the trivial character. -/
theorem inv_mul (χ : MulChar R R') : χ⁻¹ * χ = 1 := by
ext x
rw [coeToFun_mul, Pi.mul_apply, inv_apply_eq_inv]
simp only [Ring.inverse_mul_cancel _ (IsUnit.map χ x.isUnit)]
rw [one_apply_coe]
/-- The commutative group structure on `MulChar R R'`. -/
noncomputable instance commGroup : CommGroup (MulChar R R') :=
{ one := 1
mul := (· * ·)
inv := Inv.inv
inv_mul_cancel := inv_mul
mul_assoc := by
intro χ₁ χ₂ χ₃
ext a
simp only [mul_assoc, Pi.mul_apply, MulChar.coeToFun_mul]
mul_comm := by
intro χ₁ χ₂
ext a
simp only [mul_comm, Pi.mul_apply, MulChar.coeToFun_mul]
one_mul := MulChar.one_mul
mul_one := MulChar.mul_one }
/-- If `a` is a unit and `n : ℕ`, then `(χ ^ n) a = (χ a) ^ n`. -/
theorem pow_apply_coe (χ : MulChar R R') (n : ℕ) (a : Rˣ) : (χ ^ n) a = χ a ^ n := by
induction n with
| zero => rw [pow_zero, pow_zero, one_apply_coe]
| succ n ih => rw [pow_succ, pow_succ, mul_apply, ih]
/-- If `n` is positive, then `(χ ^ n) a = (χ a) ^ n`. -/
theorem pow_apply' (χ : MulChar R R') {n : ℕ} (hn : n ≠ 0) (a : R) : (χ ^ n) a = χ a ^ n := by
by_cases ha : IsUnit a
· exact pow_apply_coe χ n ha.unit
· rw [map_nonunit (χ ^ n) ha, map_nonunit χ ha, zero_pow hn]
lemma equivToUnitHom_mul_apply (χ₁ χ₂ : MulChar R R') (a : Rˣ) :
equivToUnitHom (χ₁ * χ₂) a = equivToUnitHom χ₁ a * equivToUnitHom χ₂ a := by
apply_fun ((↑) : R'ˣ → R') using Units.val_injective
push_cast
simp_rw [coe_equivToUnitHom, coeToFun_mul, Pi.mul_apply]
/-- The equivalence between multiplicative characters and homomorphisms of unit groups
as a multiplicative equivalence. -/
noncomputable
def mulEquivToUnitHom : MulChar R R' ≃* (Rˣ →* R'ˣ) :=
{ equivToUnitHom with
map_mul' := by
intro χ ψ
ext
simp only [Equiv.toFun_as_coe, coe_equivToUnitHom, coeToFun_mul, Pi.mul_apply,
MonoidHom.mul_apply, Units.val_mul]
}
end Group
/-!
### Properties of multiplicative characters
We introduce the properties of being nontrivial or quadratic and prove
some basic facts about them.
We now (mostly) assume that the target is a commutative ring.
-/
section Properties
section nontrivial
variable {R : Type*} [CommMonoid R] {R' : Type*} [CommMonoidWithZero R']
lemma eq_one_iff {χ : MulChar R R'} : χ = 1 ↔ ∀ a : Rˣ, χ a = 1 := by
simp only [MulChar.ext_iff, one_apply_coe]
lemma ne_one_iff {χ : MulChar R R'} : χ ≠ 1 ↔ ∃ a : Rˣ, χ a ≠ 1 := by
simp only [Ne, eq_one_iff, not_forall]
end nontrivial
section quadratic_and_comp
variable {R : Type*} [CommMonoid R] {R' : Type*} [CommRing R'] {R'' : Type*} [CommRing R'']
/-- A multiplicative character is *quadratic* if it takes only the values `0`, `1`, `-1`. -/
def IsQuadratic (χ : MulChar R R') : Prop :=
∀ a, χ a = 0 ∨ χ a = 1 ∨ χ a = -1
/-- If two values of quadratic characters with target `ℤ` agree after coercion into a ring
of characteristic not `2`, then they agree in `ℤ`. -/
theorem IsQuadratic.eq_of_eq_coe {χ : MulChar R ℤ} (hχ : IsQuadratic χ) {χ' : MulChar R' ℤ}
(hχ' : IsQuadratic χ') [Nontrivial R''] (hR'' : ringChar R'' ≠ 2) {a : R} {a' : R'}
(h : (χ a : R'') = χ' a') : χ a = χ' a' :=
Int.cast_injOn_of_ringChar_ne_two hR'' (hχ a) (hχ' a') h
/-- We can post-compose a multiplicative character with a ring homomorphism. -/
@[simps]
def ringHomComp (χ : MulChar R R') (f : R' →+* R'') : MulChar R R'' :=
{ f.toMonoidHom.comp χ.toMonoidHom with
toFun := fun a => f (χ a)
map_nonunit' := fun a ha => by simp only [map_nonunit χ ha, map_zero] }
@[simp]
lemma ringHomComp_one (f : R' →+* R'') : (1 : MulChar R R').ringHomComp f = 1 := by
ext1
simp only [MulChar.ringHomComp_apply, MulChar.one_apply_coe, map_one]
lemma ringHomComp_inv {R : Type*} [CommMonoidWithZero R] (χ : MulChar R R') (f : R' →+* R'') :
(χ.ringHomComp f)⁻¹ = χ⁻¹.ringHomComp f := by
ext1
simp only [inv_apply, Ring.inverse_unit, ringHomComp_apply]
lemma ringHomComp_mul (χ φ : MulChar R R') (f : R' →+* R'') :
(χ * φ).ringHomComp f = χ.ringHomComp f * φ.ringHomComp f := by
ext1
simp only [ringHomComp_apply, coeToFun_mul, Pi.mul_apply, map_mul]
lemma ringHomComp_pow (χ : MulChar R R') (f : R' →+* R'') (n : ℕ) :
χ.ringHomComp f ^ n = (χ ^ n).ringHomComp f := by
induction n with
| zero => simp only [pow_zero, ringHomComp_one]
| succ n ih => simp only [pow_succ, ih, ringHomComp_mul]
lemma injective_ringHomComp {f : R' →+* R''} (hf : Function.Injective f) :
Function.Injective (ringHomComp (R := R) · f) := by
simpa
only [Function.Injective, MulChar.ext_iff, ringHomComp, coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
using fun χ χ' h a ↦ hf (h a)
lemma ringHomComp_eq_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} :
χ.ringHomComp f = 1 ↔ χ = 1 := by
conv_lhs => rw [← (show (1 : MulChar R R').ringHomComp f = 1 by ext; simp)]
exact (injective_ringHomComp hf).eq_iff
lemma ringHomComp_ne_one_iff {f : R' →+* R''} (hf : Function.Injective f) {χ : MulChar R R'} :
χ.ringHomComp f ≠ 1 ↔ χ ≠ 1 :=
(ringHomComp_eq_one_iff hf).not
/-- Composition with a ring homomorphism preserves the property of being a quadratic character. -/
theorem IsQuadratic.comp {χ : MulChar R R'} (hχ : χ.IsQuadratic) (f : R' →+* R'') :
(χ.ringHomComp f).IsQuadratic := by
intro a
rcases hχ a with (ha | ha | ha) <;> simp [ha]
/-- The inverse of a quadratic character is itself. → -/
theorem IsQuadratic.inv {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ⁻¹ = χ := by
ext x
rw [inv_apply_eq_inv]
rcases hχ x with (h₀ | h₁ | h₂)
· rw [h₀, Ring.inverse_zero]
· rw [h₁, Ring.inverse_one]
· -- Porting note: was `by norm_cast`
have : (-1 : R') = (-1 : R'ˣ) := by rw [Units.val_neg, Units.val_one]
rw [h₂, this, Ring.inverse_unit (-1 : R'ˣ)]
rfl
/-- The square of a quadratic character is the trivial character. -/
theorem IsQuadratic.sq_eq_one {χ : MulChar R R'} (hχ : χ.IsQuadratic) : χ ^ 2 = 1 := by
rw [← inv_mul_cancel χ, pow_two, hχ.inv]
/-- The `p`th power of a quadratic character is itself, when `p` is the (prime) characteristic
of the target ring. -/
theorem IsQuadratic.pow_char {χ : MulChar R R'} (hχ : χ.IsQuadratic) (p : ℕ) [hp : Fact p.Prime]
[CharP R' p] : χ ^ p = χ := by
ext x
rw [pow_apply_coe]
rcases hχ x with (hx | hx | hx) <;> rw [hx]
· rw [zero_pow (@Fact.out p.Prime).ne_zero]
· rw [one_pow]
· exact neg_one_pow_char R' p
/-- The `n`th power of a quadratic character is the trivial character, when `n` is even. -/
theorem IsQuadratic.pow_even {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Even n) :
χ ^ n = 1 := by
obtain ⟨n, rfl⟩ := even_iff_two_dvd.mp hn
rw [pow_mul, hχ.sq_eq_one, one_pow]
/-- The `n`th power of a quadratic character is itself, when `n` is odd. -/
theorem IsQuadratic.pow_odd {χ : MulChar R R'} (hχ : χ.IsQuadratic) {n : ℕ} (hn : Odd n) :
χ ^ n = χ := by
obtain ⟨n, rfl⟩ := hn
rw [pow_add, pow_one, hχ.pow_even (even_two_mul _), one_mul]
/-- A multiplicative character `χ` into an integral domain is quadratic
if and only if `χ^2 = 1`. -/
lemma isQuadratic_iff_sq_eq_one {M R : Type*} [CommMonoid M] [CommRing R] [NoZeroDivisors R]
[Nontrivial R] {χ : MulChar M R} :
IsQuadratic χ ↔ χ ^ 2 = 1:= by
refine ⟨fun h ↦ ext (fun x ↦ ?_), fun h x ↦ ?_⟩
· rw [one_apply_coe, χ.pow_apply_coe]
rcases h x with H | H | H
· exact (not_isUnit_zero <| H ▸ IsUnit.map χ <| x.isUnit).elim
· simp only [H, one_pow]
· simp only [H, even_two, Even.neg_pow, one_pow]
· by_cases hx : IsUnit x
· refine .inr <| sq_eq_one_iff.mp ?_
rw [← χ.pow_apply' two_ne_zero, h, MulChar.one_apply hx]
· exact .inl <| map_nonunit χ hx
end quadratic_and_comp
end Properties
/-!
### Multiplicative characters with finite domain
-/
section Finite
variable {M : Type*} [CommMonoid M]
variable {R : Type*} [CommMonoidWithZero R]
/-- If `χ` is a multiplicative character on a commutative monoid `M` with finitely many units,
then `χ ^ #Mˣ = 1`. -/
protected lemma pow_card_eq_one [Fintype Mˣ] (χ : MulChar M R) : χ ^ (Fintype.card Mˣ) = 1 := by
ext1
rw [pow_apply_coe, ← map_pow, one_apply_coe, ← Units.val_pow_eq_pow_val, pow_card_eq_one,
Units.val_eq_one.mpr rfl, map_one]
/-- A multiplicative character on a commutative monoid with finitely many units
has finite (= positive) order. -/
lemma orderOf_pos [Finite Mˣ] (χ : MulChar M R) : 0 < orderOf χ := by
cases nonempty_fintype Mˣ
apply IsOfFinOrder.orderOf_pos
exact isOfFinOrder_iff_pow_eq_one.2 ⟨_, Fintype.card_pos, χ.pow_card_eq_one⟩
end Finite
section sum
variable {R : Type*} [CommMonoid R] [Fintype R] {R' : Type*} [CommRing R']
/-- The sum over all values of a nontrivial multiplicative character on a finite ring is zero
(when the target is a domain). -/
theorem sum_eq_zero_of_ne_one [IsDomain R'] {χ : MulChar R R'} (hχ : χ ≠ 1) : ∑ a, χ a = 0 := by
rcases ne_one_iff.mp hχ with ⟨b, hb⟩
refine eq_zero_of_mul_eq_self_left hb ?_
simpa only [Finset.mul_sum, ← map_mul] using b.mulLeft_bijective.sum_comp _
/-- The sum over all values of the trivial multiplicative character on a finite ring is
the cardinality of its unit group. -/
theorem sum_one_eq_card_units [DecidableEq R] :
(∑ a, (1 : MulChar R R') a) = Fintype.card Rˣ := by
calc
(∑ a, (1 : MulChar R R') a) = ∑ a : R, if IsUnit a then 1 else 0 :=
Finset.sum_congr rfl fun a _ => ?_
_ = ((Finset.univ : Finset R).filter IsUnit).card := Finset.sum_boole _ _
_ = (Finset.univ.map ⟨((↑) : Rˣ → R), Units.val_injective⟩).card := ?_
_ = Fintype.card Rˣ := congr_arg _ (Finset.card_map _)
· split_ifs with h
· exact one_apply_coe h.unit
· exact map_nonunit _ h
· congr
ext a
simp [IsUnit]
end sum
/-!
### Multiplicative characters on rings
-/
section Ring
variable {R R' : Type*} [CommRing R] [CommMonoidWithZero R']
/-- If `χ` is of odd order, then `χ(-1) = 1` -/
lemma val_neg_one_eq_one_of_odd_order {χ : MulChar R R'} {n : ℕ} (hn : Odd n) (hχ : χ ^ n = 1) :
χ (-1) = 1 := by
rw [← hn.neg_one_pow, map_pow, ← χ.pow_apply' (Nat.ne_of_odd_add hn), hχ]
exact MulChar.one_apply_coe (-1)
end Ring
end MulChar
|
Partition.lean
|
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Bryan Gin-ge Chen, Patrick Massot, Wen Yang, Johan Commelin
-/
import Mathlib.Data.Set.Finite.Range
import Mathlib.Order.Partition.Finpartition
/-!
# Equivalence relations: partitions
This file comprises properties of equivalence relations viewed as partitions.
There are two implementations of partitions here:
* A collection `c : Set (Set α)` of sets is a partition of `α` if `∅ ∉ c` and each element `a : α`
belongs to a unique set `b ∈ c`. This is expressed as `IsPartition c`
* An indexed partition is a map `s : ι → α` whose image is a partition. This is
expressed as `IndexedPartition s`.
Of course both implementations are related to `Quotient` and `Setoid`.
`Setoid.isPartition.partition` and `Finpartition.isPartition_parts` furnish
a link between `Setoid.IsPartition` and `Finpartition`.
## TODO
Could the design of `Finpartition` inform the one of `Setoid.IsPartition`? Maybe bundling it and
changing it from `Set (Set α)` to `Set α` where `[Lattice α] [OrderBot α]` would make it more
usable.
## Tags
setoid, equivalence, iseqv, relation, equivalence relation, partition, equivalence class
-/
namespace Setoid
variable {α : Type*}
/-- If x ∈ α is in 2 elements of a set of sets partitioning α, those 2 sets are equal. -/
theorem eq_of_mem_eqv_class {c : Set (Set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) {x b b'}
(hc : b ∈ c) (hb : x ∈ b) (hc' : b' ∈ c) (hb' : x ∈ b') : b = b' :=
(H x).unique ⟨hc, hb⟩ ⟨hc', hb'⟩
/-- Makes an equivalence relation from a set of sets partitioning α. -/
def mkClasses (c : Set (Set α)) (H : ∀ a, ∃! b ∈ c, a ∈ b) : Setoid α where
r x y := ∀ s ∈ c, x ∈ s → y ∈ s
iseqv.refl := fun _ _ _ hx => hx
iseqv.symm := fun {x _y} h s hs hy => by
obtain ⟨t, ⟨ht, hx⟩, _⟩ := H x
rwa [eq_of_mem_eqv_class H hs hy ht (h t ht hx)]
iseqv.trans := fun {_x _ _} h1 h2 s hs hx => h2 s hs (h1 s hs hx)
/-- Makes the equivalence classes of an equivalence relation. -/
def classes (r : Setoid α) : Set (Set α) :=
{ s | ∃ y, s = { x | r x y } }
theorem mem_classes (r : Setoid α) (y) : { x | r x y } ∈ r.classes :=
⟨y, rfl⟩
theorem classes_ker_subset_fiber_set {β : Type*} (f : α → β) :
(Setoid.ker f).classes ⊆ Set.range fun y => { x | f x = y } := by
rintro s ⟨x, rfl⟩
rw [Set.mem_range]
exact ⟨f x, rfl⟩
theorem finite_classes_ker {α β : Type*} [Finite β] (f : α → β) : (Setoid.ker f).classes.Finite :=
(Set.finite_range _).subset <| classes_ker_subset_fiber_set f
theorem card_classes_ker_le {α β : Type*} [Fintype β] (f : α → β)
[Fintype (Setoid.ker f).classes] : Fintype.card (Setoid.ker f).classes ≤ Fintype.card β := by
classical exact
le_trans (Set.card_le_card (classes_ker_subset_fiber_set f)) (Fintype.card_range_le _)
/-- Two equivalence relations are equal iff all their equivalence classes are equal. -/
theorem eq_iff_classes_eq {r₁ r₂ : Setoid α} :
r₁ = r₂ ↔ ∀ x, { y | r₁ x y } = { y | r₂ x y } :=
⟨fun h _x => h ▸ rfl, fun h => ext fun x => Set.ext_iff.1 <| h x⟩
theorem rel_iff_exists_classes (r : Setoid α) {x y} : r x y ↔ ∃ c ∈ r.classes, x ∈ c ∧ y ∈ c :=
⟨fun h => ⟨_, r.mem_classes y, h, r.refl' y⟩, fun ⟨c, ⟨z, hz⟩, hx, hy⟩ => by
subst c
exact r.trans' hx (r.symm' hy)⟩
/-- Two equivalence relations are equal iff their equivalence classes are equal. -/
theorem classes_inj {r₁ r₂ : Setoid α} : r₁ = r₂ ↔ r₁.classes = r₂.classes :=
⟨fun h => h ▸ rfl, fun h => ext fun a b => by simp only [rel_iff_exists_classes, h]⟩
/-- The empty set is not an equivalence class. -/
theorem empty_notMem_classes {r : Setoid α} : ∅ ∉ r.classes := fun ⟨y, hy⟩ =>
Set.notMem_empty y <| hy.symm ▸ r.refl' y
@[deprecated (since := "2025-05-23")] alias empty_not_mem_classes := empty_notMem_classes
/-- Equivalence classes partition the type. -/
theorem classes_eqv_classes {r : Setoid α} (a) : ∃! b ∈ r.classes, a ∈ b :=
ExistsUnique.intro { x | r x a } ⟨r.mem_classes a, r.refl' _⟩ <| by
rintro y ⟨⟨_, rfl⟩, ha⟩
ext x
exact ⟨fun hx => r.trans' hx (r.symm' ha), fun hx => r.trans' hx ha⟩
/-- If x ∈ α is in 2 equivalence classes, the equivalence classes are equal. -/
theorem eq_of_mem_classes {r : Setoid α} {x b} (hc : b ∈ r.classes) (hb : x ∈ b) {b'}
(hc' : b' ∈ r.classes) (hb' : x ∈ b') : b = b' :=
eq_of_mem_eqv_class classes_eqv_classes hc hb hc' hb'
/-- The elements of a set of sets partitioning α are the equivalence classes of the
equivalence relation defined by the set of sets. -/
theorem eq_eqv_class_of_mem {c : Set (Set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) {s y}
(hs : s ∈ c) (hy : y ∈ s) : s = { x | mkClasses c H x y } := by
ext x
constructor
· intro hx _s' hs' hx'
rwa [eq_of_mem_eqv_class H hs' hx' hs hx]
· intro hx
obtain ⟨b', ⟨hc, hb'⟩, _⟩ := H x
rwa [eq_of_mem_eqv_class H hs hy hc (hx b' hc hb')]
/-- The equivalence classes of the equivalence relation defined by a set of sets
partitioning α are elements of the set of sets. -/
theorem eqv_class_mem {c : Set (Set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) {y} :
{ x | mkClasses c H x y } ∈ c :=
(H y).elim fun _ hc _ => eq_eqv_class_of_mem H hc.1 hc.2 ▸ hc.1
theorem eqv_class_mem' {c : Set (Set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) {x} :
{ y : α | mkClasses c H x y } ∈ c := by
convert @Setoid.eqv_class_mem _ _ H x using 3
rw [Setoid.comm']
/-- Distinct elements of a set of sets partitioning α are disjoint. -/
theorem eqv_classes_disjoint {c : Set (Set α)} (H : ∀ a, ∃! b ∈ c, a ∈ b) :
c.PairwiseDisjoint id := fun _b₁ h₁ _b₂ h₂ h =>
Set.disjoint_left.2 fun x hx1 hx2 =>
(H x).elim fun _b _hc _hx => h <| eq_of_mem_eqv_class H h₁ hx1 h₂ hx2
/-- A set of disjoint sets covering α partition α (classical). -/
theorem eqv_classes_of_disjoint_union {c : Set (Set α)} (hu : Set.sUnion c = @Set.univ α)
(H : c.PairwiseDisjoint id) (a) : ∃! b ∈ c, a ∈ b :=
let ⟨b, hc, ha⟩ := Set.mem_sUnion.1 <| show a ∈ _ by rw [hu]; exact Set.mem_univ a
ExistsUnique.intro b ⟨hc, ha⟩ fun _ hc' => H.elim_set hc'.1 hc _ hc'.2 ha
/-- Makes an equivalence relation from a set of disjoints sets covering α. -/
def setoidOfDisjointUnion {c : Set (Set α)} (hu : Set.sUnion c = @Set.univ α)
(H : c.PairwiseDisjoint id) : Setoid α :=
Setoid.mkClasses c <| eqv_classes_of_disjoint_union hu H
/-- The equivalence relation made from the equivalence classes of an equivalence relation `r`
equals `r`. -/
theorem mkClasses_classes (r : Setoid α) : mkClasses r.classes classes_eqv_classes = r :=
ext fun x _y =>
⟨fun h => r.symm' (h { z | r z x } (r.mem_classes x) <| r.refl' x), fun h _b hb hx =>
eq_of_mem_classes (r.mem_classes x) (r.refl' x) hb hx ▸ r.symm' h⟩
@[simp]
theorem sUnion_classes (r : Setoid α) : ⋃₀ r.classes = Set.univ :=
Set.eq_univ_of_forall fun x => Set.mem_sUnion.2 ⟨{ y | r y x }, ⟨x, rfl⟩, Setoid.refl _⟩
/-- The equivalence between the quotient by an equivalence relation and its
type of equivalence classes. -/
noncomputable def quotientEquivClasses (r : Setoid α) : Quotient r ≃ Setoid.classes r := by
let f (a : α) : Setoid.classes r := ⟨{ x | r x a }, Setoid.mem_classes r a⟩
have f_respects_relation (a b : α) (a_rel_b : r a b) : f a = f b := by
rw [Subtype.mk.injEq]
exact Setoid.eq_of_mem_classes (Setoid.mem_classes r a) (Setoid.symm a_rel_b)
(Setoid.mem_classes r b) (Setoid.refl b)
apply Equiv.ofBijective (Quot.lift f f_respects_relation)
constructor
· intro (q_a : Quotient r) (q_b : Quotient r) h_eq
induction' q_a using Quotient.ind with a
induction' q_b using Quotient.ind with b
simp only [f, Quotient.lift_mk, Subtype.ext_iff] at h_eq
apply Quotient.sound
change a ∈ { x | r x b }
rw [← h_eq]
exact Setoid.refl a
· rw [Quot.surjective_lift]
intro ⟨c, a, hc⟩
exact ⟨a, Subtype.ext hc.symm⟩
@[simp]
lemma quotientEquivClasses_mk_eq (r : Setoid α) (a : α) :
(quotientEquivClasses r (Quotient.mk r a) : Set α) = { x | r x a } :=
(@Subtype.ext_iff_val _ _ _ ⟨{ x | r x a }, Setoid.mem_classes r a⟩).mp rfl
section Partition
/-- A collection `c : Set (Set α)` of sets is a partition of `α` into pairwise
disjoint sets if `∅ ∉ c` and each element `a : α` belongs to a unique set `b ∈ c`. -/
def IsPartition (c : Set (Set α)) := ∅ ∉ c ∧ ∀ a, ∃! b ∈ c, a ∈ b
/-- A partition of `α` does not contain the empty set. -/
theorem nonempty_of_mem_partition {c : Set (Set α)} (hc : IsPartition c) {s} (h : s ∈ c) :
s.Nonempty :=
Set.nonempty_iff_ne_empty.2 fun hs0 => hc.1 <| hs0 ▸ h
theorem isPartition_classes (r : Setoid α) : IsPartition r.classes :=
⟨empty_notMem_classes, classes_eqv_classes⟩
theorem IsPartition.pairwiseDisjoint {c : Set (Set α)} (hc : IsPartition c) :
c.PairwiseDisjoint id :=
eqv_classes_disjoint hc.2
lemma _root_.Set.PairwiseDisjoint.isPartition_of_exists_of_ne_empty {α : Type*} {s : Set (Set α)}
(h₁ : s.PairwiseDisjoint id) (h₂ : ∀ a : α, ∃ x ∈ s, a ∈ x) (h₃ : ∅ ∉ s) :
Setoid.IsPartition s := by
refine ⟨h₃, fun a ↦ existsUnique_of_exists_of_unique (h₂ a) ?_⟩
intro b₁ b₂ hb₁ hb₂
apply h₁.elim hb₁.1 hb₂.1
simp only [Set.not_disjoint_iff]
exact ⟨a, hb₁.2, hb₂.2⟩
theorem IsPartition.sUnion_eq_univ {c : Set (Set α)} (hc : IsPartition c) : ⋃₀ c = Set.univ :=
Set.eq_univ_of_forall fun x =>
Set.mem_sUnion.2 <|
let ⟨t, ht⟩ := hc.2 x
⟨t, by
simp only at ht
tauto⟩
/-- All elements of a partition of α are the equivalence class of some y ∈ α. -/
theorem exists_of_mem_partition {c : Set (Set α)} (hc : IsPartition c) {s} (hs : s ∈ c) :
∃ y, s = { x | mkClasses c hc.2 x y } :=
let ⟨y, hy⟩ := nonempty_of_mem_partition hc hs
⟨y, eq_eqv_class_of_mem hc.2 hs hy⟩
/-- The equivalence classes of the equivalence relation defined by a partition of α equal
the original partition. -/
theorem classes_mkClasses (c : Set (Set α)) (hc : IsPartition c) :
(mkClasses c hc.2).classes = c := by
ext s
constructor
· rintro ⟨y, rfl⟩
obtain ⟨b, ⟨hb, hy⟩, _⟩ := hc.2 y
rwa [← eq_eqv_class_of_mem _ hb hy]
· exact exists_of_mem_partition hc
/-- Defining `≤` on partitions as the `≤` defined on their induced equivalence relations. -/
instance Partition.le : LE (Subtype (@IsPartition α)) :=
⟨fun x y => mkClasses x.1 x.2.2 ≤ mkClasses y.1 y.2.2⟩
/-- Defining a partial order on partitions as the partial order on their induced
equivalence relations. -/
instance Partition.partialOrder : PartialOrder (Subtype (@IsPartition α)) where
le := (· ≤ ·)
lt x y := x ≤ y ∧ ¬y ≤ x
le_refl _ := @le_refl (Setoid α) _ _
le_trans _ _ _ := @le_trans (Setoid α) _ _ _ _
lt_iff_le_not_ge _ _ := Iff.rfl
le_antisymm x y hx hy := by
let h := @le_antisymm (Setoid α) _ _ _ hx hy
rw [Subtype.ext_iff_val, ← classes_mkClasses x.1 x.2, ← classes_mkClasses y.1 y.2, h]
variable (α) in
/-- The order-preserving bijection between equivalence relations on a type `α`, and
partitions of `α` into subsets. -/
protected def Partition.orderIso : Setoid α ≃o { C : Set (Set α) // IsPartition C } where
toFun r := ⟨r.classes, empty_notMem_classes, classes_eqv_classes⟩
invFun C := mkClasses C.1 C.2.2
left_inv := mkClasses_classes
right_inv C := by rw [Subtype.ext_iff_val, ← classes_mkClasses C.1 C.2]
map_rel_iff' {r s} := by
conv_rhs => rw [← mkClasses_classes r, ← mkClasses_classes s]
rfl
/-- A complete lattice instance for partitions; there is more infrastructure for the
equivalent complete lattice on equivalence relations. -/
instance Partition.completeLattice : CompleteLattice (Subtype (@IsPartition α)) :=
GaloisInsertion.liftCompleteLattice <|
@OrderIso.toGaloisInsertion _ (Subtype (@IsPartition α)) _ (PartialOrder.toPreorder) <|
Partition.orderIso α
end Partition
/-- A finite setoid partition furnishes a finpartition -/
@[simps]
def IsPartition.finpartition {c : Finset (Set α)} (hc : Setoid.IsPartition (c : Set (Set α))) :
Finpartition (Set.univ : Set α) where
parts := c
supIndep := Finset.supIndep_iff_pairwiseDisjoint.mpr <| eqv_classes_disjoint hc.2
sup_parts := c.sup_id_set_eq_sUnion.trans hc.sUnion_eq_univ
bot_notMem := hc.left
end Setoid
/-- A finpartition gives rise to a setoid partition -/
theorem Finpartition.isPartition_parts {α} (f : Finpartition (Set.univ : Set α)) :
Setoid.IsPartition (f.parts : Set (Set α)) :=
⟨f.bot_notMem,
Setoid.eqv_classes_of_disjoint_union (f.parts.sup_id_set_eq_sUnion.symm.trans f.sup_parts)
f.supIndep.pairwiseDisjoint⟩
/-- Constructive information associated with a partition of a type `α` indexed by another type `ι`,
`s : ι → Set α`.
`IndexedPartition.index` sends an element to its index, while `IndexedPartition.some` sends
an index to an element of the corresponding set.
This type is primarily useful for definitional control of `s` - if this is not needed, then
`Setoid.ker index` by itself may be sufficient. -/
structure IndexedPartition {ι α : Type*} (s : ι → Set α) where
/-- two indexes are equal if they are equal in membership -/
eq_of_mem : ∀ {x i j}, x ∈ s i → x ∈ s j → i = j
/-- sends an index to an element of the corresponding set -/
some : ι → α
/-- membership invariance for `some` -/
some_mem : ∀ i, some i ∈ s i
/-- index for type `α` -/
index : α → ι
/-- membership invariance for `index` -/
mem_index : ∀ x, x ∈ s (index x)
open scoped Function -- required for scoped `on` notation
/-- The non-constructive constructor for `IndexedPartition`. -/
noncomputable def IndexedPartition.mk' {ι α : Type*} (s : ι → Set α)
(dis : Pairwise (Disjoint on s)) (nonempty : ∀ i, (s i).Nonempty)
(ex : ∀ x, ∃ i, x ∈ s i) : IndexedPartition s where
eq_of_mem {_x _i _j} hxi hxj := by_contradiction fun h => (dis h).le_bot ⟨hxi, hxj⟩
some i := (nonempty i).some
some_mem i := (nonempty i).choose_spec
index x := (ex x).choose
mem_index x := (ex x).choose_spec
namespace IndexedPartition
open Set
variable {ι α : Type*} {s : ι → Set α}
/-- On a unique index set there is the obvious trivial partition -/
instance [Unique ι] [Inhabited α] : Inhabited (IndexedPartition fun _i : ι => (Set.univ : Set α)) :=
⟨{ eq_of_mem := fun {_x _i _j} _hi _hj => Subsingleton.elim _ _
some := default
some_mem := Set.mem_univ
index := default
mem_index := Set.mem_univ }⟩
attribute [simp] some_mem
variable (hs : IndexedPartition s)
include hs in
theorem exists_mem (x : α) : ∃ i, x ∈ s i :=
⟨hs.index x, hs.mem_index x⟩
include hs in
theorem iUnion : ⋃ i, s i = univ := by
ext x
simp [hs.exists_mem x]
include hs in
theorem disjoint : Pairwise (Disjoint on s) := fun {_i _j} h =>
disjoint_left.mpr fun {_x} hxi hxj => h (hs.eq_of_mem hxi hxj)
theorem mem_iff_index_eq {x i} : x ∈ s i ↔ hs.index x = i :=
⟨fun hxi => (hs.eq_of_mem hxi (hs.mem_index x)).symm, fun h => h ▸ hs.mem_index _⟩
theorem eq (i) : s i = { x | hs.index x = i } :=
Set.ext fun _ => hs.mem_iff_index_eq
/-- The equivalence relation associated to an indexed partition. Two
elements are equivalent if they belong to the same set of the partition. -/
protected abbrev setoid (hs : IndexedPartition s) : Setoid α :=
Setoid.ker hs.index
@[simp]
theorem index_some (i : ι) : hs.index (hs.some i) = i :=
(mem_iff_index_eq _).1 <| hs.some_mem i
theorem some_index (x : α) : hs.setoid (hs.some (hs.index x)) x :=
hs.index_some (hs.index x)
/-- The quotient associated to an indexed partition. -/
protected def Quotient :=
Quotient hs.setoid
/-- The projection onto the quotient associated to an indexed partition. -/
def proj : α → hs.Quotient :=
Quotient.mk''
instance [Inhabited α] : Inhabited hs.Quotient :=
⟨hs.proj default⟩
theorem proj_eq_iff {x y : α} : hs.proj x = hs.proj y ↔ hs.index x = hs.index y :=
Quotient.eq''
@[simp]
theorem proj_some_index (x : α) : hs.proj (hs.some (hs.index x)) = hs.proj x :=
Quotient.eq''.2 (hs.some_index x)
/-- The obvious equivalence between the quotient associated to an indexed partition and
the indexing type. -/
def equivQuotient : ι ≃ hs.Quotient :=
(Setoid.quotientKerEquivOfRightInverse hs.index hs.some <| hs.index_some).symm
@[simp]
theorem equivQuotient_index_apply (x : α) : hs.equivQuotient (hs.index x) = hs.proj x :=
hs.proj_eq_iff.mpr (some_index hs x)
@[simp]
theorem equivQuotient_symm_proj_apply (x : α) : hs.equivQuotient.symm (hs.proj x) = hs.index x :=
rfl
theorem equivQuotient_index : hs.equivQuotient ∘ hs.index = hs.proj :=
funext hs.equivQuotient_index_apply
/-- A map choosing a representative for each element of the quotient associated to an indexed
partition. This is a computable version of `Quotient.out` using `IndexedPartition.some`. -/
def out : hs.Quotient ↪ α :=
hs.equivQuotient.symm.toEmbedding.trans ⟨hs.some, Function.LeftInverse.injective hs.index_some⟩
/-- This lemma is analogous to `Quotient.mk_out'`. -/
@[simp]
theorem out_proj (x : α) : hs.out (hs.proj x) = hs.some (hs.index x) :=
rfl
/-- The indices of `Quotient.out` and `IndexedPartition.out` are equal. -/
theorem index_out (x : hs.Quotient) : hs.index x.out = hs.index (hs.out x) :=
Quotient.inductionOn' x fun x => (Setoid.ker_apply_mk_out x).trans (hs.index_some _).symm
/-- This lemma is analogous to `Quotient.out_eq'`. -/
@[simp]
theorem proj_out (x : hs.Quotient) : hs.proj (hs.out x) = x :=
Quotient.inductionOn' x fun x => Quotient.sound' <| hs.some_index x
theorem class_of {x : α} : setOf (hs.setoid x) = s (hs.index x) :=
Set.ext fun _y => eq_comm.trans hs.mem_iff_index_eq.symm
theorem proj_fiber (x : hs.Quotient) : hs.proj ⁻¹' {x} = s (hs.equivQuotient.symm x) :=
Quotient.inductionOn' x fun x => by
ext y
simp only [Set.mem_preimage, Set.mem_singleton_iff, hs.mem_iff_index_eq]
exact Quotient.eq''
/-- Combine functions with disjoint domains into a new function.
You can use the regular expression `def.*piecewise` to search for
other ways to define piecewise functions in mathlib4. -/
def piecewise {β : Type*} (f : ι → α → β) : α → β := fun x => f (hs.index x) x
lemma piecewise_apply {β : Type*} {f : ι → α → β} (x : α) : hs.piecewise f x = f (hs.index x) x :=
rfl
open Function
/-- A family of injective functions with pairwise disjoint
domains and pairwise disjoint ranges can be glued together
to form an injective function. -/
theorem piecewise_inj {β : Type*} {f : ι → α → β}
(h_injOn : ∀ i, InjOn (f i) (s i))
(h_disjoint : PairwiseDisjoint (univ : Set ι) fun i => (f i) '' (s i)) :
Injective (piecewise hs f) := by
intro x y h
suffices hs.index x = hs.index y by
apply h_injOn (hs.index x) (hs.mem_index x) (this ▸ hs.mem_index y)
simpa only [piecewise_apply, this] using h
apply h_disjoint.elim trivial trivial
contrapose! h
exact h.ne_of_mem (mem_image_of_mem _ (hs.mem_index x)) (mem_image_of_mem _ (hs.mem_index y))
/-- A family of bijective functions with pairwise disjoint
domains and pairwise disjoint ranges can be glued together
to form a bijective function. -/
theorem piecewise_bij {β : Type*} {f : ι → α → β}
{t : ι → Set β} (ht : IndexedPartition t)
(hf : ∀ i, BijOn (f i) (s i) (t i)) :
Bijective (piecewise hs f) := by
set g := piecewise hs f with hg
have hg_bij : ∀ i, BijOn g (s i) (t i) := by
intro i
refine BijOn.congr (hf i) ?_
intro x hx
rw [hg, piecewise_apply, hs.mem_iff_index_eq.mp hx]
have hg_inj : InjOn g (⋃ i, s i) := by
refine injOn_of_injective ?_
refine piecewise_inj hs (fun i ↦ BijOn.injOn (hf i)) ?h_disjoint
simp only [fun i ↦ BijOn.image_eq (hf i)]
rintro i - j - hij
exact ht.disjoint hij
rw [bijective_iff_bijOn_univ, ← hs.iUnion, ← ht.iUnion]
exact bijOn_iUnion hg_bij hg_inj
end IndexedPartition
|
DeriveFintype.lean
|
/-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Tactic.ProxyType
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.Fintype.Sigma
import Mathlib.Data.Fintype.Sum
/-!
# The `Fintype` derive handler
This file defines a derive handler to automatically generate `Fintype` instances
for structures and inductive types.
The following is a prototypical example of what this can handle:
```
inductive MyOption (α : Type*)
| none
| some (x : α)
deriving Fintype
```
This deriving handler does not attempt to process inductive types that are either
recursive or that have indices.
To get debugging information, do `set_option trace.Elab.Deriving.fintype true`
and `set_option Elab.ProxyType true`.
There is a term elaborator `derive_fintype%` implementing the derivation of `Fintype` instances.
This can be useful in cases when there are necessary additional assumptions (like `DecidableEq`).
This is implemented using `Fintype.ofEquiv` and `proxy_equiv%`, which is a term elaborator
that creates an equivalence from a "proxy type" composed of basic type constructors. If Lean
can synthesize a `Fintype` instance for the proxy type, then `derive_fintype%` succeeds.
## Implementation notes
There are two kinds of `Fintype` instances that we generate, depending on the inductive type.
If it is an enum (an inductive type with only 0-ary constructors), then we generate the
complete `List` of all constructors; see `Mathlib.Deriving.Fintype.mkFintypeEnum` for more
details. The proof has $O(n)$ complexity in the number of constructors.
Otherwise, the strategy we take is to generate a "proxy type", define an equivalence between
our type and the proxy type (see `proxy_equiv%`), and then use `Fintype.ofEquiv` to pull a
`Fintype` instance on the proxy type (if one exists) to our inductive type. For example, with
the `MyOption α` type above, we generate `Unit ⊕ α`. While the proxy type is not a finite type
in general, we add `Fintype` instances for every type parameter of our inductive type (and
`Decidable` instances for every `Prop` parameter). Hence, in our example we get
`Fintype (MyOption α)` assuming `Fintype α`.
There is a source of quadratic complexity in this `Fintype` instance from the fact that an
inductive type with `n` constructors has a proxy type of the form `C₁ ⊕ (C₂ ⊕ (⋯ ⊕ Cₙ))`,
so mapping to and from `Cᵢ` requires looking through `i` levels of `Sum` constructors.
Ignoring time spent looking through these constructors, the construction of `Finset.univ`
contributes just linear time with respect to the cardinality of the type since the instances
involved compute the underlying `List` for the `Finset` as `l₁ ++ (l₂ ++ (⋯ ++ lₙ))` with
right associativity.
Note that an alternative design could be that instead of using `Sum` we could create a
function `C : Fin n → Type*` with `C i = ULift Cᵢ` and then use `(i : Fin n) × C i` for
the proxy type, which would save us from the nested `Sum` constructors.
This implementation takes some inspiration from the one by Mario Carneiro for Mathlib 3.
A difference is that the Mathlib 3 version does not explicitly construct the total proxy type,
and instead it opts to construct the underlying `Finset` as a disjoint union of the `Finset.univ`
for each individual constructor's proxy type.
-/
namespace Mathlib.Deriving.Fintype
open Lean Elab Lean.Parser.Term
open Meta Command
/--
The term elaborator `derive_fintype% α` tries to synthesize a `Fintype α` instance
using all the assumptions in the local context; this can be useful, for example, if one
needs an extra `DecidableEq` instance. It works only if `α` is an inductive
type that `proxy_equiv% α` can handle. The elaborator makes use of the
expected type, so `(derive_fintype% _ : Fintype α)` works.
This uses `proxy_equiv% α`, so as a side effect it defines `proxyType` and `proxyTypeEquiv` in
the namespace associated to the inductive type `α`.
-/
macro "derive_fintype% " t:term : term => `(term| Fintype.ofEquiv _ (proxy_equiv% $t))
/-
Creates a `Fintype` instance by adding additional `Fintype` and `Decidable` instance arguments
for every type and prop parameter of the type, then use the `derive_fintype%` elaborator.
-/
def mkFintype (declName : Name) : CommandElabM Bool := do
let indVal ← getConstInfoInduct declName
let cmd ← liftTermElabM do
let header ← Deriving.mkHeader `Fintype 0 indVal
let binders' ← Deriving.mkInstImplicitBinders `Decidable indVal header.argNames
let instCmd ← `(command|
instance $header.binders:bracketedBinder* $(binders'.map TSyntax.mk):bracketedBinder* :
Fintype $header.targetType := derive_fintype% _)
return instCmd
trace[Elab.Deriving.fintype] "instance command:\n{cmd}"
elabCommand cmd
return true
/-- Derive a `Fintype` instance for enum types. These come with a `toCtorIdx` function.
We generate a more optimized instance than the one produced by `mkFintype`.
The strategy is to (1) create a list `enumList` of all the constructors, (2) prove that this
is in `toCtorIdx` order, (3) show that `toCtorIdx` maps `enumList` to `List.range numCtors` to show
the list has no duplicates, and (4) give the `Fintype` instance, using 2 for completeness.
The proofs are all linear complexity, and the main computation is that
`enumList.map toCtorIdx = List.range numCtors`, which is true by `refl`. -/
def mkFintypeEnum (declName : Name) : CommandElabM Unit := do
let indVal ← getConstInfoInduct declName
let levels := indVal.levelParams.map Level.param
let toCtorIdxName := declName.mkStr "toCtorIdx"
let enumListName := declName.mkStr "enumList"
let toCtorThmName := declName.mkStr "enumList_getElem?_to_CtorIdx_eq"
let enumListNodupName := declName.mkStr "enumList_nodup"
liftTermElabM <| Term.withoutErrToSorry do
do -- Define `enumList` enumerating all constructors
trace[Elab.Deriving.fintype] "defining {enumListName}"
let type := mkConst declName levels
let listType ← mkAppM ``List #[type]
let listNil ← mkAppOptM ``List.nil #[some type]
let listCons name xs := mkAppM ``List.cons #[mkConst name levels, xs]
let enumList ← indVal.ctors.foldrM (listCons · ·) listNil
addAndCompile <| Declaration.defnDecl
{ name := enumListName
levelParams := indVal.levelParams
safety := DefinitionSafety.safe
hints := ReducibilityHints.abbrev
type := listType
value := enumList }
setProtected enumListName
addDocStringCore enumListName s!"A list enumerating every element of the type, \
which are all zero-argument constructors. (Generated by the `Fintype` deriving handler.)"
do -- Prove that this list is in `toCtorIdx` order
trace[Elab.Deriving.fintype] "proving {toCtorThmName}"
let goalStx ← `(term| ∀ (x : $(← Term.exprToSyntax <| mkConst declName levels)),
$(mkIdent enumListName)[$(mkIdent toCtorIdxName) x]? = some x)
let goal ← Term.elabTerm goalStx (mkSort .zero)
let pf ← Term.elabTerm (← `(term| by intro x; cases x <;> rfl)) goal
Term.synthesizeSyntheticMVarsNoPostponing
addAndCompile <| Declaration.thmDecl
{ name := toCtorThmName
levelParams := indVal.levelParams
type := ← instantiateMVars goal
value := ← instantiateMVars pf }
setProtected toCtorThmName
do -- Use this theorem to prove `enumList` has no duplicates
trace[Elab.Deriving.fintype] "proving {enumListNodupName}"
let enum ← Term.exprToSyntax <| mkConst enumListName levels
let goal ← Term.elabTerm (← `(term| List.Nodup $enum)) (mkSort .zero)
let n : TSyntax `term := quote indVal.numCtors
let pf ← Term.elabTerm (← `(term| by
apply List.Nodup.of_map $(mkIdent toCtorIdxName)
have h : List.map $(mkIdent toCtorIdxName) $(mkIdent enumListName)
= List.range $n := rfl
exact h ▸ List.nodup_range)) goal
Term.synthesizeSyntheticMVarsNoPostponing
addAndCompile <| Declaration.thmDecl
{ name := enumListNodupName
levelParams := indVal.levelParams
type := ← instantiateMVars goal
value := ← instantiateMVars pf }
setProtected enumListNodupName
-- Make the Fintype instance
trace[Elab.Deriving.fintype] "defining fintype instance"
let cmd ← `(command|
instance : Fintype $(mkIdent declName) where
elems := Finset.mk $(mkIdent enumListName) $(mkIdent enumListNodupName)
complete := by
intro x
rw [Finset.mem_mk, Multiset.mem_coe, List.mem_iff_getElem?]
exact ⟨$(mkIdent toCtorIdxName) x, $(mkIdent toCtorThmName) x⟩)
trace[Elab.Deriving.fintype] "instance command:\n{cmd}"
elabCommand cmd
def mkFintypeInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
if h : declNames.size ≠ 1 then
return false -- mutually inductive types are not supported
else
let declName := declNames[0]
if ← isEnumType declName then
mkFintypeEnum declName
return true
else
mkFintype declName
initialize
registerDerivingHandler ``Fintype mkFintypeInstanceHandler
registerTraceClass `Elab.Deriving.fintype
end Mathlib.Deriving.Fintype
|
ParseCommand.lean
|
/-
Copyright (c) 2024 Matthew Robert Ballard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Matthew Robert Ballard, Damiano Testa
-/
import Lean.Elab.Command
import Mathlib.Init
/-!
# `#parse` -- a command to parse text and log outputs
-/
namespace Mathlib.GuardExceptions
open Lean Parser Elab Command
/-- `captureException env s input` uses the given `Environment` `env` to parse the `String` `input`
using the `ParserFn` `s`.
This is a variation of `Lean.Parser.runParserCategory`.
-/
def captureException (env : Environment) (s : ParserFn) (input : String) : Except String Syntax :=
let ictx := mkInputContext input "<input>"
let s := s.run ictx { env, options := {} } (getTokenTable env) (mkParserState input)
if !s.allErrors.isEmpty then
.error (s.toErrorMsg ictx)
else if ictx.input.atEnd s.pos then
.ok s.stxStack.back
else
.error ((s.mkError "end of input").toErrorMsg ictx)
/-- `#parse parserFnId => str` allows to capture parsing exceptions.
`parserFnId` is the identifier of a `ParserFn` and `str` is the string that
`parserFnId` should parse.
If the parse is successful, then the output is logged;
if the parse is successful, then the output is captured in an exception.
In either case, `#guard_msgs` can then be used to capture the resulting parsing errors.
For instance, `#parse` can be used as follows
```lean
/-- error: <input>:1:3: Stacks tags must be exactly 4 characters -/
#guard_msgs in #parse Mathlib.Stacks.stacksTagFn => "A05"
```
-/
syntax (name := parseCmd) "#parse " ident " => " str : command
@[inherit_doc parseCmd]
elab_rules : command
| `(command| #parse $parserFnId => $str) => do
elabCommand <| ← `(command|
run_cmd do
let exc ← Lean.ofExcept <| captureException (← getEnv) $parserFnId $str
logInfo $str)
end Mathlib.GuardExceptions
|
Lemmas.lean
|
/-
Copyright (c) 2020 Kenji Nakagawa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenji Nakagawa, Anne Baanen, Filippo A. E. Nuccio
-/
import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.Algebra.Squarefree.Basic
import Mathlib.RingTheory.ChainOfDivisors
import Mathlib.RingTheory.DedekindDomain.Ideal.Basic
import Mathlib.RingTheory.Spectrum.Maximal.Localization
import Mathlib.Algebra.Order.GroupWithZero.Unbundled.OrderIso
/-!
# Dedekind domains and ideals
In this file, we prove some results on the unique factorization monoid structure of the ideals.
The unique factorization of ideals and invertibility of fractional ideals can be found in
`Mathlib/RingTheory/DedekindDomain/Ideal/Basic.lean`.
## Main definitions
- `IsDedekindDomain.HeightOneSpectrum` defines the type of nonzero prime ideals of `R`.
## Implementation notes
Often, definitions assume that Dedekind domains are not fields. We found it more practical
to add a `(h : ¬ IsField A)` assumption whenever this is explicitly needed.
## References
* [D. Marcus, *Number Fields*][marcus1977number]
* [J.W.S. Cassels, A. Fröhlich, *Algebraic Number Theory*][cassels1967algebraic]
* [J. Neukirch, *Algebraic Number Theory*][Neukirch1992]
## Tags
dedekind domain, dedekind ring
-/
variable (R A K : Type*) [CommRing R] [CommRing A] [Field K]
open scoped nonZeroDivisors Polynomial
section Inverse
variable [Algebra A K] [IsFractionRing A K]
variable {A K}
namespace FractionalIdeal
open Ideal
theorem exists_notMem_one_of_ne_bot [IsDedekindDomain A] {I : Ideal A} (hI0 : I ≠ ⊥)
(hI1 : I ≠ ⊤) : ∃ x ∈ (I⁻¹ : FractionalIdeal A⁰ K), x ∉ (1 : FractionalIdeal A⁰ K) :=
Set.not_subset.1 <| not_inv_le_one_of_ne_bot hI0 hI1
@[deprecated (since := "2025-05-23")]
alias exists_not_mem_one_of_ne_bot := exists_notMem_one_of_ne_bot
theorem mul_left_strictMono [IsDedekindDomain A] {I : FractionalIdeal A⁰ K} (hI : I ≠ 0) :
StrictMono (I * ·) :=
strictMono_of_le_iff_le fun _ _ => (mul_left_le_iff hI).symm
end FractionalIdeal
end Inverse
section IsDedekindDomain
variable {R A}
variable [IsDedekindDomain A] [Algebra A K] [IsFractionRing A K]
open FractionalIdeal
open Ideal
@[simp]
theorem Ideal.dvd_span_singleton {I : Ideal A} {x : A} : I ∣ Ideal.span {x} ↔ x ∈ I :=
Ideal.dvd_iff_le.trans (Ideal.span_le.trans Set.singleton_subset_iff)
theorem Ideal.isPrime_of_prime {P : Ideal A} (h : Prime P) : IsPrime P := by
refine ⟨?_, fun hxy => ?_⟩
· rintro rfl
rw [← Ideal.one_eq_top] at h
exact h.not_unit isUnit_one
· simp only [← Ideal.dvd_span_singleton, ← Ideal.span_singleton_mul_span_singleton] at hxy ⊢
exact h.dvd_or_dvd hxy
theorem Ideal.prime_of_isPrime {P : Ideal A} (hP : P ≠ ⊥) (h : IsPrime P) : Prime P := by
refine ⟨hP, mt Ideal.isUnit_iff.mp h.ne_top, fun I J hIJ => ?_⟩
simpa only [Ideal.dvd_iff_le] using h.mul_le.mp (Ideal.le_of_dvd hIJ)
/-- In a Dedekind domain, the (nonzero) prime elements of the monoid with zero `Ideal A`
are exactly the prime ideals. -/
theorem Ideal.prime_iff_isPrime {P : Ideal A} (hP : P ≠ ⊥) : Prime P ↔ IsPrime P :=
⟨Ideal.isPrime_of_prime, Ideal.prime_of_isPrime hP⟩
/-- In a Dedekind domain, the prime ideals are the zero ideal together with the prime elements
of the monoid with zero `Ideal A`. -/
theorem Ideal.isPrime_iff_bot_or_prime {P : Ideal A} : IsPrime P ↔ P = ⊥ ∨ Prime P :=
⟨fun hp => (eq_or_ne P ⊥).imp_right fun hp0 => Ideal.prime_of_isPrime hp0 hp, fun hp =>
hp.elim (fun h => h.symm ▸ Ideal.bot_prime) Ideal.isPrime_of_prime⟩
@[simp]
theorem Ideal.prime_span_singleton_iff {a : A} : Prime (Ideal.span {a}) ↔ Prime a := by
rcases eq_or_ne a 0 with rfl | ha
· rw [Set.singleton_zero, span_zero, ← Ideal.zero_eq_bot, ← not_iff_not]
simp only [not_prime_zero, not_false_eq_true]
· have ha' : span {a} ≠ ⊥ := by simpa only [ne_eq, span_singleton_eq_bot] using ha
rw [Ideal.prime_iff_isPrime ha', Ideal.span_singleton_prime ha]
open Submodule.IsPrincipal in
theorem Ideal.prime_generator_of_prime {P : Ideal A} (h : Prime P) [P.IsPrincipal] :
Prime (generator P) :=
have : Ideal.IsPrime P := Ideal.isPrime_of_prime h
prime_generator_of_isPrime _ h.ne_zero
open UniqueFactorizationMonoid in
nonrec theorem Ideal.mem_normalizedFactors_iff {p I : Ideal A} (hI : I ≠ ⊥) :
p ∈ normalizedFactors I ↔ p.IsPrime ∧ I ≤ p := by
rw [← Ideal.dvd_iff_le]
by_cases hp : p = 0
· rw [← zero_eq_bot] at hI
simp only [hp, zero_notMem_normalizedFactors, zero_dvd_iff, hI, false_iff, not_and,
not_false_eq_true, implies_true]
· rwa [mem_normalizedFactors_iff hI, prime_iff_isPrime]
theorem Ideal.pow_right_strictAnti (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) :
StrictAnti (I ^ · : ℕ → Ideal A) :=
strictAnti_nat_of_succ_lt fun e =>
Ideal.dvdNotUnit_iff_lt.mp ⟨pow_ne_zero _ hI0, I, mt isUnit_iff.mp hI1, pow_succ I e⟩
theorem Ideal.pow_lt_self (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) (he : 2 ≤ e) :
I ^ e < I := by
convert I.pow_right_strictAnti hI0 hI1 he
dsimp only
rw [pow_one]
theorem Ideal.exists_mem_pow_notMem_pow_succ (I : Ideal A) (hI0 : I ≠ ⊥) (hI1 : I ≠ ⊤) (e : ℕ) :
∃ x ∈ I ^ e, x ∉ I ^ (e + 1) :=
SetLike.exists_of_lt (I.pow_right_strictAnti hI0 hI1 e.lt_succ_self)
@[deprecated (since := "2025-05-23")]
alias Ideal.exists_mem_pow_not_mem_pow_succ := Ideal.exists_mem_pow_notMem_pow_succ
open UniqueFactorizationMonoid
theorem Ideal.eq_prime_pow_of_succ_lt_of_le {P I : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥)
{i : ℕ} (hlt : P ^ (i + 1) < I) (hle : I ≤ P ^ i) : I = P ^ i := by
refine le_antisymm hle ?_
have P_prime' := Ideal.prime_of_isPrime hP P_prime
have h1 : I ≠ ⊥ := (lt_of_le_of_lt bot_le hlt).ne'
have := pow_ne_zero i hP
have h3 := pow_ne_zero (i + 1) hP
rw [← Ideal.dvdNotUnit_iff_lt, dvdNotUnit_iff_normalizedFactors_lt_normalizedFactors h1 h3,
normalizedFactors_pow, normalizedFactors_irreducible P_prime'.irreducible,
Multiset.nsmul_singleton, Multiset.lt_replicate_succ] at hlt
rw [← Ideal.dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors, normalizedFactors_pow,
normalizedFactors_irreducible P_prime'.irreducible, Multiset.nsmul_singleton]
all_goals assumption
theorem Ideal.pow_succ_lt_pow {P : Ideal A} [P_prime : P.IsPrime] (hP : P ≠ ⊥) (i : ℕ) :
P ^ (i + 1) < P ^ i :=
lt_of_le_of_ne (Ideal.pow_le_pow_right (Nat.le_succ _))
(mt (pow_inj_of_not_isUnit (mt Ideal.isUnit_iff.mp P_prime.ne_top) hP).mp i.succ_ne_self)
theorem Associates.le_singleton_iff (x : A) (n : ℕ) (I : Ideal A) :
Associates.mk I ^ n ≤ Associates.mk (Ideal.span {x}) ↔ x ∈ I ^ n := by
simp_rw [← Associates.dvd_eq_le, ← Associates.mk_pow, Associates.mk_dvd_mk,
Ideal.dvd_span_singleton]
variable {K}
lemma FractionalIdeal.le_inv_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) :
I ≤ J⁻¹ ↔ J ≤ I⁻¹ := by
rw [inv_eq, inv_eq, le_div_iff_mul_le hI, le_div_iff_mul_le hJ, mul_comm]
lemma FractionalIdeal.inv_le_comm {I J : FractionalIdeal A⁰ K} (hI : I ≠ 0) (hJ : J ≠ 0) :
I⁻¹ ≤ J ↔ J⁻¹ ≤ I := by
simpa using le_inv_comm (A := A) (K := K) (inv_ne_zero hI) (inv_ne_zero hJ)
open FractionalIdeal
/-- Strengthening of `IsLocalization.exist_integer_multiples`:
Let `J ≠ ⊤` be an ideal in a Dedekind domain `A`, and `f ≠ 0` a finite collection
of elements of `K = Frac(A)`, then we can multiply the elements of `f` by some `a : K`
to find a collection of elements of `A` that is not completely contained in `J`. -/
theorem Ideal.exist_integer_multiples_notMem {J : Ideal A} (hJ : J ≠ ⊤) {ι : Type*} (s : Finset ι)
(f : ι → K) {j} (hjs : j ∈ s) (hjf : f j ≠ 0) :
∃ a : K,
(∀ i ∈ s, IsLocalization.IsInteger A (a * f i)) ∧
∃ i ∈ s, a * f i ∉ (J : FractionalIdeal A⁰ K) := by
-- Consider the fractional ideal `I` spanned by the `f`s.
let I : FractionalIdeal A⁰ K := spanFinset A s f
have hI0 : I ≠ 0 := spanFinset_ne_zero.mpr ⟨j, hjs, hjf⟩
-- We claim the multiplier `a` we're looking for is in `I⁻¹ \ (J / I)`.
suffices ↑J / I < I⁻¹ by
obtain ⟨_, a, hI, hpI⟩ := SetLike.lt_iff_le_and_exists.mp this
rw [mem_inv_iff hI0] at hI
refine ⟨a, fun i hi => ?_, ?_⟩
-- By definition, `a ∈ I⁻¹` multiplies elements of `I` into elements of `1`,
-- in other words, `a * f i` is an integer.
· exact (mem_one_iff _).mp (hI (f i) (Submodule.subset_span (Set.mem_image_of_mem f hi)))
· contrapose! hpI
-- And if all `a`-multiples of `I` are an element of `J`,
-- then `a` is actually an element of `J / I`, contradiction.
refine (mem_div_iff_of_nonzero hI0).mpr fun y hy => Submodule.span_induction ?_ ?_ ?_ ?_ hy
· rintro _ ⟨i, hi, rfl⟩; exact hpI i hi
· rw [mul_zero]; exact Submodule.zero_mem _
· intro x y _ _ hx hy; rw [mul_add]; exact Submodule.add_mem _ hx hy
· intro b x _ hx; rw [mul_smul_comm]; exact Submodule.smul_mem _ b hx
-- To show the inclusion of `J / I` into `I⁻¹ = 1 / I`, note that `J < I`.
calc
↑J / I = ↑J * I⁻¹ := div_eq_mul_inv (↑J) I
_ < 1 * I⁻¹ := mul_right_strictMono (inv_ne_zero hI0) ?_
_ = I⁻¹ := one_mul _
rw [← coeIdeal_top]
-- And multiplying by `I⁻¹` is indeed strictly monotone.
exact
strictMono_of_le_iff_le (fun _ _ => (coeIdeal_le_coeIdeal K).symm)
(lt_top_iff_ne_top.mpr hJ)
@[deprecated (since := "2025-05-23")]
alias Ideal.exist_integer_multiples_not_mem := Ideal.exist_integer_multiples_notMem
lemma Ideal.mul_iInf (I : Ideal A) {ι : Type*} [Nonempty ι] (J : ι → Ideal A) :
I * ⨅ i, J i = ⨅ i, I * J i := by
by_cases hI : I = 0
· simp [hI]
refine (le_iInf fun i ↦ Ideal.mul_mono_right (iInf_le _ _)).antisymm ?_
have H : ⨅ i, I * J i ≤ I := (iInf_le _ (Nonempty.some ‹_›)).trans Ideal.mul_le_right
obtain ⟨K, hK⟩ := Ideal.dvd_iff_le.mpr H
rw [hK]
refine mul_le_mul_left' ?_ I
rw [le_iInf_iff]
intro i
rw [← mul_le_mul_iff_of_pos_left (a := I), ← hK]
· exact iInf_le _ _
· exact bot_lt_iff_ne_bot.mpr hI
lemma Ideal.iInf_mul (I : Ideal A) {ι : Type*} [Nonempty ι] (J : ι → Ideal A) :
(⨅ i, J i) * I = ⨅ i, J i * I := by
simp only [mul_iInf, mul_comm _ I]
lemma Ideal.mul_inf (I J K : Ideal A) : I * (J ⊓ K) = I * J ⊓ I * K := by
rw [inf_eq_iInf, Ideal.mul_iInf, inf_eq_iInf]
congr! 2 with ⟨⟩
lemma Ideal.inf_mul (I J K : Ideal A) : (I ⊓ J) * K = I * K ⊓ J * K := by
simp only [Ideal.mul_inf, mul_comm _ K]
lemma FractionalIdeal.mul_inf (I J K : FractionalIdeal A⁰ K) : I * (J ⊓ K) = I * J ⊓ I * K :=
mul_inf₀ (zero_le _) _ _
lemma FractionalIdeal.inf_mul (I J K : FractionalIdeal A⁰ K) : (I ⊓ J) * K = I * K ⊓ J * K :=
inf_mul₀ (zero_le _) _ _
section Gcd
namespace Ideal
/-! ### GCD and LCM of ideals in a Dedekind domain
We show that the gcd of two ideals in a Dedekind domain is just their supremum,
and the lcm is their infimum, and use this to instantiate `NormalizedGCDMonoid (Ideal A)`.
-/
@[simp]
theorem sup_mul_inf (I J : Ideal A) : (I ⊔ J) * (I ⊓ J) = I * J := by
letI := UniqueFactorizationMonoid.toNormalizedGCDMonoid (Ideal A)
have hgcd : gcd I J = I ⊔ J := by
rw [gcd_eq_normalize _ _, normalize_eq]
· rw [dvd_iff_le, sup_le_iff, ← dvd_iff_le, ← dvd_iff_le]
exact ⟨gcd_dvd_left _ _, gcd_dvd_right _ _⟩
· rw [dvd_gcd_iff, dvd_iff_le, dvd_iff_le]
simp
have hlcm : lcm I J = I ⊓ J := by
rw [lcm_eq_normalize _ _, normalize_eq]
· rw [lcm_dvd_iff, dvd_iff_le, dvd_iff_le]
simp
· rw [dvd_iff_le, le_inf_iff, ← dvd_iff_le, ← dvd_iff_le]
exact ⟨dvd_lcm_left _ _, dvd_lcm_right _ _⟩
rw [← hgcd, ← hlcm, associated_iff_eq.mp (gcd_mul_lcm _ _)]
/-- Ideals in a Dedekind domain have gcd and lcm operators that (trivially) are compatible with
the normalization operator. -/
noncomputable instance : NormalizedGCDMonoid (Ideal A) :=
{ Ideal.normalizationMonoid with
gcd := (· ⊔ ·)
gcd_dvd_left := fun _ _ => by simpa only [dvd_iff_le] using le_sup_left
gcd_dvd_right := fun _ _ => by simpa only [dvd_iff_le] using le_sup_right
dvd_gcd := by
simp only [dvd_iff_le]
exact fun h1 h2 => @sup_le (Ideal A) _ _ _ _ h1 h2
lcm := (· ⊓ ·)
lcm_zero_left := fun _ => by simp only [zero_eq_bot, bot_inf_eq]
lcm_zero_right := fun _ => by simp only [zero_eq_bot, inf_bot_eq]
gcd_mul_lcm := fun _ _ => by rw [associated_iff_eq, sup_mul_inf]
normalize_gcd := fun _ _ => normalize_eq _
normalize_lcm := fun _ _ => normalize_eq _ }
-- In fact, any lawful gcd and lcm would equal sup and inf respectively.
@[simp]
theorem gcd_eq_sup (I J : Ideal A) : gcd I J = I ⊔ J := rfl
@[simp]
theorem lcm_eq_inf (I J : Ideal A) : lcm I J = I ⊓ J := rfl
theorem isCoprime_iff_gcd {I J : Ideal A} : IsCoprime I J ↔ gcd I J = 1 := by
rw [Ideal.isCoprime_iff_codisjoint, codisjoint_iff, one_eq_top, gcd_eq_sup]
theorem factors_span_eq {p : K[X]} : factors (span {p}) = (factors p).map (fun q ↦ span {q}) := by
rcases eq_or_ne p 0 with rfl | hp; · simpa [Set.singleton_zero] using normalizedFactors_zero
have : ∀ q ∈ (factors p).map (fun q ↦ span {q}), Prime q := fun q hq ↦ by
obtain ⟨r, hr, rfl⟩ := Multiset.mem_map.mp hq
exact prime_span_singleton_iff.mpr <| prime_of_factor r hr
rw [← span_singleton_eq_span_singleton.mpr (factors_prod hp), ← multiset_prod_span_singleton,
factors_eq_normalizedFactors, normalizedFactors_prod_of_prime this]
lemma _root_.FractionalIdeal.sup_mul_inf (I J : FractionalIdeal A⁰ K) :
(I ⊓ J) * (I ⊔ J) = I * J := by
apply mul_left_injective₀ (b := spanSingleton A⁰ (algebraMap A K
(I.den.1 * I.den.1 * J.den.1 * J.den.1))) (by simp [spanSingleton_eq_zero_iff])
have := Ideal.sup_mul_inf (Ideal.span {J.den.1} * I.num) (Ideal.span {I.den.1} * J.num)
simp only [← coeIdeal_inj (K := K), coeIdeal_mul, coeIdeal_sup, coeIdeal_inf,
← den_mul_self_eq_num', coeIdeal_span_singleton] at this
rw [mul_left_comm, ← mul_add, ← mul_add, ← mul_inf₀ (FractionalIdeal.zero_le _),
← mul_inf₀ (FractionalIdeal.zero_le _)] at this
simp only [FractionalIdeal.sup_eq_add, _root_.map_mul, ← spanSingleton_mul_spanSingleton]
convert this using 1 <;> ring
end Ideal
end Gcd
end IsDedekindDomain
section IsDedekindDomain
variable {T : Type*} [CommRing T] [IsDedekindDomain T] {I J : Ideal T}
open Multiset UniqueFactorizationMonoid Ideal
theorem prod_normalizedFactors_eq_self (hI : I ≠ ⊥) : (normalizedFactors I).prod = I :=
associated_iff_eq.1 (prod_normalizedFactors hI)
theorem count_le_of_ideal_ge [DecidableEq (Ideal T)]
{I J : Ideal T} (h : I ≤ J) (hI : I ≠ ⊥) (K : Ideal T) :
count K (normalizedFactors J) ≤ count K (normalizedFactors I) :=
le_iff_count.1 ((dvd_iff_normalizedFactors_le_normalizedFactors (ne_bot_of_le_ne_bot hI h) hI).1
(dvd_iff_le.2 h))
_
theorem sup_eq_prod_inf_factors [DecidableEq (Ideal T)] (hI : I ≠ ⊥) (hJ : J ≠ ⊥) :
I ⊔ J = (normalizedFactors I ∩ normalizedFactors J).prod := by
have H : normalizedFactors (normalizedFactors I ∩ normalizedFactors J).prod =
normalizedFactors I ∩ normalizedFactors J := by
apply normalizedFactors_prod_of_prime
intro p hp
rw [mem_inter] at hp
exact prime_of_normalized_factor p hp.left
have := Multiset.prod_ne_zero_of_prime (normalizedFactors I ∩ normalizedFactors J) fun _ h =>
prime_of_normalized_factor _ (Multiset.mem_inter.1 h).1
apply le_antisymm
· rw [sup_le_iff, ← dvd_iff_le, ← dvd_iff_le]
constructor
· rw [dvd_iff_normalizedFactors_le_normalizedFactors this hI, H]
exact inf_le_left
· rw [dvd_iff_normalizedFactors_le_normalizedFactors this hJ, H]
exact inf_le_right
· rw [← dvd_iff_le, dvd_iff_normalizedFactors_le_normalizedFactors,
normalizedFactors_prod_of_prime, le_iff_count]
· intro a
rw [Multiset.count_inter]
exact le_min (count_le_of_ideal_ge le_sup_left hI a) (count_le_of_ideal_ge le_sup_right hJ a)
· intro p hp
rw [mem_inter] at hp
exact prime_of_normalized_factor p hp.left
· exact ne_bot_of_le_ne_bot hI le_sup_left
· exact this
theorem irreducible_pow_sup [DecidableEq (Ideal T)] (hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ) :
J ^ n ⊔ I = J ^ min ((normalizedFactors I).count J) n := by
rw [sup_eq_prod_inf_factors (pow_ne_zero n hJ.ne_zero) hI, min_comm,
normalizedFactors_of_irreducible_pow hJ, normalize_eq J, replicate_inter, prod_replicate]
theorem irreducible_pow_sup_of_le (hJ : Irreducible J) (n : ℕ) (hn : n ≤ emultiplicity J I) :
J ^ n ⊔ I = J ^ n := by
classical
by_cases hI : I = ⊥
· simp_all
rw [irreducible_pow_sup hI hJ, min_eq_right]
rw [emultiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J] at hn
exact_mod_cast hn
theorem irreducible_pow_sup_of_ge (hI : I ≠ ⊥) (hJ : Irreducible J) (n : ℕ)
(hn : emultiplicity J I ≤ n) : J ^ n ⊔ I = J ^ multiplicity J I := by
classical
rw [irreducible_pow_sup hI hJ, min_eq_left]
· congr
rw [← Nat.cast_inj (R := ℕ∞), ← FiniteMultiplicity.emultiplicity_eq_multiplicity,
emultiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J]
rw [← emultiplicity_lt_top]
apply hn.trans_lt
simp
· rw [emultiplicity_eq_count_normalizedFactors hJ hI, normalize_eq J] at hn
exact_mod_cast hn
theorem Ideal.eq_prime_pow_mul_coprime [DecidableEq (Ideal T)] {I : Ideal T} (hI : I ≠ ⊥)
(P : Ideal T) [hpm : P.IsMaximal] :
∃ Q : Ideal T, P ⊔ Q = ⊤ ∧ I = P ^ (Multiset.count P (normalizedFactors I)) * Q := by
use (filter (¬ P = ·) (normalizedFactors I)).prod
constructor
· refine P.sup_multiset_prod_eq_top (fun p hpi ↦ ?_)
have hp : Prime p := prime_of_normalized_factor p (filter_subset _ (normalizedFactors I) hpi)
exact hpm.coprime_of_ne ((isPrime_of_prime hp).isMaximal hp.ne_zero) (of_mem_filter hpi)
· nth_rw 1 [← prod_normalizedFactors_eq_self hI, ← filter_add_not (P = ·) (normalizedFactors I)]
rw [prod_add, pow_count]
end IsDedekindDomain
/-!
### Height one spectrum of a Dedekind domain
If `R` is a Dedekind domain of Krull dimension 1, the maximal ideals of `R` are exactly its nonzero
prime ideals.
We define `HeightOneSpectrum` and provide lemmas to recover the facts that prime ideals of height
one are prime and irreducible.
-/
namespace IsDedekindDomain
variable [IsDedekindDomain R]
/-- The height one prime spectrum of a Dedekind domain `R` is the type of nonzero prime ideals of
`R`. Note that this equals the maximal spectrum if `R` has Krull dimension 1. -/
@[ext, nolint unusedArguments]
structure HeightOneSpectrum where
asIdeal : Ideal R
isPrime : asIdeal.IsPrime
ne_bot : asIdeal ≠ ⊥
attribute [instance] HeightOneSpectrum.isPrime
variable (v : HeightOneSpectrum R) {R}
namespace HeightOneSpectrum
instance isMaximal : v.asIdeal.IsMaximal := v.isPrime.isMaximal v.ne_bot
theorem prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime
theorem irreducible : Irreducible v.asIdeal :=
UniqueFactorizationMonoid.irreducible_iff_prime.mpr v.prime
theorem associates_irreducible : Irreducible <| Associates.mk v.asIdeal :=
Associates.irreducible_mk.mpr v.irreducible
/-- An equivalence between the height one and maximal spectra for rings of Krull dimension 1. -/
def equivMaximalSpectrum (hR : ¬IsField R) : HeightOneSpectrum R ≃ MaximalSpectrum R where
toFun v := ⟨v.asIdeal, v.isPrime.isMaximal v.ne_bot⟩
invFun v :=
⟨v.asIdeal, v.isMaximal.isPrime, Ring.ne_bot_of_isMaximal_of_not_isField v.isMaximal hR⟩
/-- An ideal of `R` is not the whole ring if and only if it is contained in an element of
`HeightOneSpectrum R` -/
theorem ideal_ne_top_iff_exists (hR : ¬IsField R) (I : Ideal R) :
I ≠ ⊤ ↔ ∃ P : HeightOneSpectrum R, I ≤ P.asIdeal := by
rw [Ideal.ne_top_iff_exists_maximal]
constructor
· rintro ⟨M, hMmax, hIM⟩
exact ⟨(equivMaximalSpectrum hR).symm ⟨M, hMmax⟩, hIM⟩
· rintro ⟨P, hP⟩
exact ⟨((equivMaximalSpectrum hR) P).asIdeal, ((equivMaximalSpectrum hR) P).isMaximal, hP⟩
variable (R)
/-- A Dedekind domain is equal to the intersection of its localizations at all its height one
non-zero prime ideals viewed as subalgebras of its field of fractions. -/
theorem iInf_localization_eq_bot [Algebra R K] [hK : IsFractionRing R K] :
(⨅ v : HeightOneSpectrum R,
Localization.subalgebra.ofField K _ v.asIdeal.primeCompl_le_nonZeroDivisors) = ⊥ := by
ext x
rw [Algebra.mem_iInf]
constructor
on_goal 1 => by_cases hR : IsField R
· rcases Function.bijective_iff_has_inverse.mp
(IsField.localization_map_bijective (Rₘ := K) (flip nonZeroDivisors.ne_zero rfl : 0 ∉ R⁰) hR)
with ⟨algebra_map_inv, _, algebra_map_right_inv⟩
exact fun _ => Algebra.mem_bot.mpr ⟨algebra_map_inv x, algebra_map_right_inv x⟩
all_goals rw [← MaximalSpectrum.iInf_localization_eq_bot, Algebra.mem_iInf]
· exact fun hx ⟨v, hv⟩ => hx ((equivMaximalSpectrum hR).symm ⟨v, hv⟩)
· exact fun hx ⟨v, hv, hbot⟩ => hx ⟨v, hv.isMaximal hbot⟩
end HeightOneSpectrum
end IsDedekindDomain
section
open Ideal
variable {R A}
variable [IsDedekindDomain A] {I : Ideal R} {J : Ideal A}
/-- The map from ideals of `R` dividing `I` to the ideals of `A` dividing `J` induced by
a homomorphism `f : R/I →+* A/J` -/
@[simps]
def idealFactorsFunOfQuotHom {f : R ⧸ I →+* A ⧸ J} (hf : Function.Surjective f) :
{p : Ideal R // p ∣ I} →o {p : Ideal A // p ∣ J} where
toFun X := ⟨comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)), by
have : RingHom.ker (Ideal.Quotient.mk J) ≤
comap (Ideal.Quotient.mk J) (map f (map (Ideal.Quotient.mk I) X)) :=
ker_le_comap (Ideal.Quotient.mk J)
rw [mk_ker] at this
exact dvd_iff_le.mpr this⟩
monotone' := by
rintro ⟨X, hX⟩ ⟨Y, hY⟩ h
rw [← Subtype.coe_le_coe, Subtype.coe_mk, Subtype.coe_mk] at h ⊢
rw [Subtype.coe_mk, comap_le_comap_iff_of_surjective (Ideal.Quotient.mk J)
Ideal.Quotient.mk_surjective, map_le_iff_le_comap, Subtype.coe_mk,
comap_map_of_surjective _ hf (map (Ideal.Quotient.mk I) Y)]
suffices map (Ideal.Quotient.mk I) X ≤ map (Ideal.Quotient.mk I) Y by
exact le_sup_of_le_left this
rwa [map_le_iff_le_comap, comap_map_of_surjective (Ideal.Quotient.mk I)
Ideal.Quotient.mk_surjective, ← RingHom.ker_eq_comap_bot, mk_ker,
sup_eq_left.mpr <| le_of_dvd hY]
@[simp]
theorem idealFactorsFunOfQuotHom_id :
idealFactorsFunOfQuotHom (RingHom.id (A ⧸ J)).surjective = OrderHom.id :=
OrderHom.ext _ _
(funext fun X => by
simp only [idealFactorsFunOfQuotHom, map_id, OrderHom.coe_mk, OrderHom.id_coe, id,
comap_map_of_surjective (Ideal.Quotient.mk J) Ideal.Quotient.mk_surjective, ←
RingHom.ker_eq_comap_bot (Ideal.Quotient.mk J), mk_ker,
sup_eq_left.mpr (dvd_iff_le.mp X.prop), Subtype.coe_eta])
variable {B : Type*} [CommRing B] [IsDedekindDomain B] {L : Ideal B}
theorem idealFactorsFunOfQuotHom_comp {f : R ⧸ I →+* A ⧸ J} {g : A ⧸ J →+* B ⧸ L}
(hf : Function.Surjective f) (hg : Function.Surjective g) :
(idealFactorsFunOfQuotHom hg).comp (idealFactorsFunOfQuotHom hf) =
idealFactorsFunOfQuotHom (show Function.Surjective (g.comp f) from hg.comp hf) := by
refine OrderHom.ext _ _ (funext fun x => ?_)
rw [idealFactorsFunOfQuotHom, idealFactorsFunOfQuotHom, OrderHom.comp_coe, OrderHom.coe_mk,
OrderHom.coe_mk, Function.comp_apply, idealFactorsFunOfQuotHom, OrderHom.coe_mk,
Subtype.mk_eq_mk, Subtype.coe_mk, map_comap_of_surjective (Ideal.Quotient.mk J)
Ideal.Quotient.mk_surjective, map_map]
variable [IsDedekindDomain R] (f : R ⧸ I ≃+* A ⧸ J)
/-- The bijection between ideals of `R` dividing `I` and the ideals of `A` dividing `J` induced by
an isomorphism `f : R/I ≅ A/J`. -/
def idealFactorsEquivOfQuotEquiv : { p : Ideal R | p ∣ I } ≃o { p : Ideal A | p ∣ J } := by
have f_surj : Function.Surjective (f : R ⧸ I →+* A ⧸ J) := f.surjective
have fsym_surj : Function.Surjective (f.symm : A ⧸ J →+* R ⧸ I) := f.symm.surjective
refine OrderIso.ofHomInv (idealFactorsFunOfQuotHom f_surj) (idealFactorsFunOfQuotHom fsym_surj)
?_ ?_
· have := idealFactorsFunOfQuotHom_comp fsym_surj f_surj
simp only [RingEquiv.comp_symm, idealFactorsFunOfQuotHom_id] at this
rw [← this, OrderHom.coe_eq, OrderHom.coe_eq]
· have := idealFactorsFunOfQuotHom_comp f_surj fsym_surj
simp only [RingEquiv.symm_comp, idealFactorsFunOfQuotHom_id] at this
rw [← this, OrderHom.coe_eq, OrderHom.coe_eq]
theorem idealFactorsEquivOfQuotEquiv_symm :
(idealFactorsEquivOfQuotEquiv f).symm = idealFactorsEquivOfQuotEquiv f.symm := rfl
theorem idealFactorsEquivOfQuotEquiv_is_dvd_iso {L M : Ideal R} (hL : L ∣ I) (hM : M ∣ I) :
(idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ : Ideal A) ∣ idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ↔
L ∣ M := by
suffices
idealFactorsEquivOfQuotEquiv f ⟨M, hM⟩ ≤ idealFactorsEquivOfQuotEquiv f ⟨L, hL⟩ ↔
(⟨M, hM⟩ : { p : Ideal R | p ∣ I }) ≤ ⟨L, hL⟩
by rw [dvd_iff_le, dvd_iff_le, Subtype.coe_le_coe, this, Subtype.mk_le_mk]
exact (idealFactorsEquivOfQuotEquiv f).le_iff_le
open UniqueFactorizationMonoid
theorem idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors (hJ : J ≠ ⊥)
{L : Ideal R} (hL : L ∈ normalizedFactors I) :
↑(idealFactorsEquivOfQuotEquiv f ⟨L, dvd_of_mem_normalizedFactors hL⟩)
∈ normalizedFactors J := by
have hI : I ≠ ⊥ := by
intro hI
rw [hI, bot_eq_zero, normalizedFactors_zero, ← Multiset.empty_eq_zero] at hL
exact Finset.notMem_empty _ hL
refine mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors hI hJ hL
(d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_
rintro ⟨l, hl⟩ ⟨l', hl'⟩
rw [Subtype.coe_mk, Subtype.coe_mk]
apply idealFactorsEquivOfQuotEquiv_is_dvd_iso f
/-- The bijection between the sets of normalized factors of I and J induced by a ring
isomorphism `f : R/I ≅ A/J`. -/
def normalizedFactorsEquivOfQuotEquiv (hI : I ≠ ⊥) (hJ : J ≠ ⊥) :
{ L : Ideal R | L ∈ normalizedFactors I } ≃ { M : Ideal A | M ∈ normalizedFactors J } where
toFun j :=
⟨idealFactorsEquivOfQuotEquiv f ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩,
idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f hJ j.prop⟩
invFun j :=
⟨(idealFactorsEquivOfQuotEquiv f).symm ⟨↑j, dvd_of_mem_normalizedFactors j.prop⟩, by
rw [idealFactorsEquivOfQuotEquiv_symm]
exact
idealFactorsEquivOfQuotEquiv_mem_normalizedFactors_of_mem_normalizedFactors f.symm hI
j.prop⟩
left_inv := fun ⟨j, hj⟩ => by simp
right_inv := fun ⟨j, hj⟩ => by simp [-Set.coe_setOf]
@[simp]
theorem normalizedFactorsEquivOfQuotEquiv_symm (hI : I ≠ ⊥) (hJ : J ≠ ⊥) :
(normalizedFactorsEquivOfQuotEquiv f hI hJ).symm =
normalizedFactorsEquivOfQuotEquiv f.symm hJ hI := rfl
/-- The map `normalizedFactorsEquivOfQuotEquiv` preserves multiplicities. -/
theorem normalizedFactorsEquivOfQuotEquiv_emultiplicity_eq_emultiplicity (hI : I ≠ ⊥) (hJ : J ≠ ⊥)
(L : Ideal R) (hL : L ∈ normalizedFactors I) :
emultiplicity (↑(normalizedFactorsEquivOfQuotEquiv f hI hJ ⟨L, hL⟩)) J = emultiplicity L I := by
rw [normalizedFactorsEquivOfQuotEquiv, Equiv.coe_fn_mk, Subtype.coe_mk]
refine emultiplicity_factor_dvd_iso_eq_emultiplicity_of_mem_normalizedFactors hI hJ hL
(d := (idealFactorsEquivOfQuotEquiv f).toEquiv) ?_
exact fun ⟨l, hl⟩ ⟨l', hl'⟩ => idealFactorsEquivOfQuotEquiv_is_dvd_iso f hl hl'
end
section ChineseRemainder
open Ideal UniqueFactorizationMonoid
variable {R}
theorem Ring.DimensionLeOne.prime_le_prime_iff_eq [Ring.DimensionLEOne R] {P Q : Ideal R}
[hP : P.IsPrime] [hQ : Q.IsPrime] (hP0 : P ≠ ⊥) : P ≤ Q ↔ P = Q :=
⟨(hP.isMaximal hP0).eq_of_le hQ.ne_top, Eq.le⟩
section DedekindDomain
variable [IsDedekindDomain R]
theorem Ideal.IsPrime.mul_mem_pow (I : Ideal R) [hI : I.IsPrime] {a b : R} {n : ℕ}
(h : a * b ∈ I ^ n) : a ∈ I ∨ b ∈ I ^ n := by
cases n; · simp
by_cases hI0 : I = ⊥; · simpa [pow_succ, hI0] using h
simp only [← Submodule.span_singleton_le_iff_mem, Ideal.submodule_span_eq, ← Ideal.dvd_iff_le, ←
Ideal.span_singleton_mul_span_singleton] at h ⊢
by_cases ha : I ∣ span {a}
· exact Or.inl ha
rw [mul_comm] at h
exact Or.inr (Prime.pow_dvd_of_dvd_mul_right ((Ideal.prime_iff_isPrime hI0).mpr hI) _ ha h)
theorem Ideal.IsPrime.mem_pow_mul (I : Ideal R) [hI : I.IsPrime] {a b : R} {n : ℕ}
(h : a * b ∈ I ^ n) : a ∈ I ^ n ∨ b ∈ I := by
rw [mul_comm] at h
rw [or_comm]
exact Ideal.IsPrime.mul_mem_pow _ h
section
theorem Ideal.count_normalizedFactors_eq {p x : Ideal R} [hp : p.IsPrime] {n : ℕ} (hle : x ≤ p ^ n)
[DecidableEq (Ideal R)] (hlt : ¬x ≤ p ^ (n + 1)) : (normalizedFactors x).count p = n :=
count_normalizedFactors_eq' ((Ideal.isPrime_iff_bot_or_prime.mp hp).imp_right Prime.irreducible)
(normalize_eq _) (Ideal.dvd_iff_le.mpr hle) (mt Ideal.le_of_dvd hlt)
/-- The number of times an ideal `I` occurs as normalized factor of another ideal `J` is stable
when regarding these ideals as associated elements of the monoid of ideals. -/
theorem count_associates_factors_eq [DecidableEq (Ideal R)] [DecidableEq <| Associates (Ideal R)]
[∀ (p : Associates <| Ideal R), Decidable (Irreducible p)]
{I J : Ideal R} (hI : I ≠ 0) (hJ : J.IsPrime) (hJ₀ : J ≠ ⊥) :
(Associates.mk J).count (Associates.mk I).factors = Multiset.count J (normalizedFactors I) := by
replace hI : Associates.mk I ≠ 0 := Associates.mk_ne_zero.mpr hI
have hJ' : Irreducible (Associates.mk J) := by
simpa only [Associates.irreducible_mk] using (Ideal.prime_of_isPrime hJ₀ hJ).irreducible
apply (Ideal.count_normalizedFactors_eq (p := J) (x := I) _ _).symm
all_goals
rw [← Ideal.dvd_iff_le, ← Associates.mk_dvd_mk, Associates.mk_pow]
simp only [Associates.dvd_eq_le]
rw [Associates.prime_pow_dvd_iff_le hI hJ']
omega
/-- Variant of `UniqueFactorizationMonoid.count_normalizedFactors_eq` for associated Ideals. -/
theorem Ideal.count_associates_eq [DecidableEq (Associates (Ideal R))]
[∀ (p : Associates <| Ideal R), Decidable (Irreducible p)]
{a a₀ x : R} {n : ℕ} (hx : Prime x) (ha : ¬x ∣ a) (heq : a₀ = x ^ n * a) :
(Associates.mk (span {x})).count (Associates.mk (span {a₀})).factors = n := by
have hx0 : x ≠ 0 := Prime.ne_zero hx
classical
rw [count_associates_factors_eq, UniqueFactorizationMonoid.count_normalizedFactors_eq]
· exact (prime_span_singleton_iff.mpr hx).irreducible
· exact normalize_eq _
· simp only [span_singleton_pow, heq, dvd_span_singleton]
exact Ideal.mul_mem_right _ _ (mem_span_singleton_self (x ^ n))
· simp only [span_singleton_pow, heq, dvd_span_singleton, mem_span_singleton]
rw [pow_add, pow_one, mul_dvd_mul_iff_left (pow_ne_zero n hx0)]
exact ha
· simp only [Submodule.zero_eq_bot, ne_eq, span_singleton_eq_bot]
aesop
· exact (span_singleton_prime hx0).mpr hx
· simp only [ne_eq, span_singleton_eq_bot]; exact hx0
/-- Variant of `UniqueFactorizationMonoid.count_normalizedFactors_eq` for associated Ideals. -/
theorem Ideal.count_associates_eq' [DecidableEq (Associates (Ideal R))]
[∀ (p : Associates <| Ideal R), Decidable (Irreducible p)]
{a x : R} (hx : Prime x) {n : ℕ} (hle : x ^ n ∣ a) (hlt : ¬x ^ (n + 1) ∣ a) :
(Associates.mk (span {x})).count (Associates.mk (span {a})).factors = n := by
obtain ⟨q, hq⟩ := hle
apply Ideal.count_associates_eq hx _ hq
contrapose! hlt with hdvd
obtain ⟨q', hq'⟩ := hdvd
use q'
rw [hq, hq']
ring
end
theorem Ideal.le_mul_of_no_prime_factors {I J K : Ideal R}
(coprime : ∀ P, J ≤ P → K ≤ P → ¬IsPrime P) (hJ : I ≤ J) (hK : I ≤ K) : I ≤ J * K := by
simp only [← Ideal.dvd_iff_le] at coprime hJ hK ⊢
by_cases hJ0 : J = 0
· simpa only [hJ0, zero_mul] using hJ
obtain ⟨I', rfl⟩ := hK
rw [mul_comm]
refine mul_dvd_mul_left K
(UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors (b := K) hJ0 ?_ hJ)
exact fun hPJ hPK => mt Ideal.isPrime_of_prime (coprime _ hPJ hPK)
/-- The intersection of distinct prime powers in a Dedekind domain is the product of these
prime powers. -/
theorem IsDedekindDomain.inf_prime_pow_eq_prod {ι : Type*} (s : Finset ι) (f : ι → Ideal R)
(e : ι → ℕ) (prime : ∀ i ∈ s, Prime (f i))
(coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → f i ≠ f j) :
(s.inf fun i => f i ^ e i) = ∏ i ∈ s, f i ^ e i := by
letI := Classical.decEq ι
revert prime coprime
refine s.induction ?_ ?_
· simp
intro a s ha ih prime coprime
specialize
ih (fun i hi => prime i (Finset.mem_insert_of_mem hi)) fun i hi j hj =>
coprime i (Finset.mem_insert_of_mem hi) j (Finset.mem_insert_of_mem hj)
rw [Finset.inf_insert, Finset.prod_insert ha, ih]
refine le_antisymm (Ideal.le_mul_of_no_prime_factors ?_ inf_le_left inf_le_right) Ideal.mul_le_inf
intro P hPa hPs hPp
obtain ⟨b, hb, hPb⟩ := hPp.prod_le.mp hPs
haveI := Ideal.isPrime_of_prime (prime a (Finset.mem_insert_self a s))
haveI := Ideal.isPrime_of_prime (prime b (Finset.mem_insert_of_mem hb))
refine coprime a (Finset.mem_insert_self a s) b (Finset.mem_insert_of_mem hb) ?_ ?_
· exact (ne_of_mem_of_not_mem hb ha).symm
· refine ((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (hPp.le_of_pow_le hPa)).trans
((Ring.DimensionLeOne.prime_le_prime_iff_eq ?_).mp (hPp.le_of_pow_le hPb)).symm
· exact (prime a (Finset.mem_insert_self a s)).ne_zero
· exact (prime b (Finset.mem_insert_of_mem hb)).ne_zero
/-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as
`∏ i, P i ^ e i`, then `R ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`. -/
noncomputable def IsDedekindDomain.quotientEquivPiOfProdEq {ι : Type*} [Fintype ι] (I : Ideal R)
(P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i, Prime (P i))
(coprime : Pairwise fun i j => P i ≠ P j)
(prod_eq : ∏ i, P i ^ e i = I) : R ⧸ I ≃+* ∀ i, R ⧸ P i ^ e i :=
(Ideal.quotEquivOfEq
(by
simp only [← prod_eq, Finset.inf_eq_iInf, Finset.mem_univ, ciInf_pos,
← IsDedekindDomain.inf_prime_pow_eq_prod _ _ _ (fun i _ => prime i)
(coprime.set_pairwise _)])).trans <|
Ideal.quotientInfRingEquivPiQuotient _ fun i j hij => Ideal.coprime_of_no_prime_ge <| by
intro P hPi hPj hPp
haveI := Ideal.isPrime_of_prime (prime i)
haveI := Ideal.isPrime_of_prime (prime j)
exact coprime hij <| ((Ring.DimensionLeOne.prime_le_prime_iff_eq (prime i).ne_zero).mp
(hPp.le_of_pow_le hPi)).trans <| Eq.symm <|
(Ring.DimensionLeOne.prime_le_prime_iff_eq (prime j).ne_zero).mp (hPp.le_of_pow_le hPj)
open scoped Classical in
/-- **Chinese remainder theorem** for a Dedekind domain: `R ⧸ I` factors as `Π i, R ⧸ (P i ^ e i)`,
where `P i` ranges over the prime factors of `I` and `e i` over the multiplicities. -/
noncomputable def IsDedekindDomain.quotientEquivPiFactors {I : Ideal R} (hI : I ≠ ⊥) :
R ⧸ I ≃+* ∀ P : (factors I).toFinset, R ⧸ (P : Ideal R) ^ (Multiset.count ↑P (factors I)) :=
IsDedekindDomain.quotientEquivPiOfProdEq _ _ _
(fun P : (factors I).toFinset => prime_of_factor _ (Multiset.mem_toFinset.mp P.prop))
(fun _ _ hij => Subtype.coe_injective.ne hij)
(calc
(∏ P : (factors I).toFinset, (P : Ideal R) ^ (factors I).count (P : Ideal R)) =
∏ P ∈ (factors I).toFinset, P ^ (factors I).count P :=
(factors I).toFinset.prod_coe_sort fun P => P ^ (factors I).count P
_ = ((factors I).map fun P => P).prod := (Finset.prod_multiset_map_count (factors I) id).symm
_ = (factors I).prod := by rw [Multiset.map_id']
_ = I := associated_iff_eq.mp (factors_prod hI)
)
@[simp]
theorem IsDedekindDomain.quotientEquivPiFactors_mk {I : Ideal R} (hI : I ≠ ⊥) (x : R) :
IsDedekindDomain.quotientEquivPiFactors hI (Ideal.Quotient.mk I x) = fun _P =>
Ideal.Quotient.mk _ x := rfl
/-- **Chinese remainder theorem** for a Dedekind domain: if the ideal `I` factors as
`∏ i ∈ s, P i ^ e i`, then `R ⧸ I` factors as `Π (i : s), R ⧸ (P i ^ e i)`.
This is a version of `IsDedekindDomain.quotientEquivPiOfProdEq` where we restrict
the product to a finite subset `s` of a potentially infinite indexing type `ι`.
-/
noncomputable def IsDedekindDomain.quotientEquivPiOfFinsetProdEq {ι : Type*} {s : Finset ι}
(I : Ideal R) (P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i))
(coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j)
(prod_eq : ∏ i ∈ s, P i ^ e i = I) : R ⧸ I ≃+* ∀ i : s, R ⧸ P i ^ e i :=
IsDedekindDomain.quotientEquivPiOfProdEq I (fun i : s => P i) (fun i : s => e i)
(fun i => prime i i.2) (fun i j h => coprime i i.2 j j.2 (Subtype.coe_injective.ne h))
(_root_.trans (Finset.prod_coe_sort s fun i => P i ^ e i) prod_eq)
/-- Corollary of the Chinese remainder theorem: given elements `x i : R / P i ^ e i`,
we can choose a representative `y : R` such that `y ≡ x i (mod P i ^ e i)`. -/
theorem IsDedekindDomain.exists_representative_mod_finset {ι : Type*} {s : Finset ι}
(P : ι → Ideal R) (e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i))
(coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (x : ∀ i : s, R ⧸ P i ^ e i) :
∃ y, ∀ (i) (hi : i ∈ s), Ideal.Quotient.mk (P i ^ e i) y = x ⟨i, hi⟩ := by
let f := IsDedekindDomain.quotientEquivPiOfFinsetProdEq _ P e prime coprime rfl
obtain ⟨y, rfl⟩ := f.surjective x
obtain ⟨z, rfl⟩ := Ideal.Quotient.mk_surjective y
exact ⟨z, fun i _hi => rfl⟩
/-- Corollary of the Chinese remainder theorem: given elements `x i : R`,
we can choose a representative `y : R` such that `y - x i ∈ P i ^ e i`. -/
theorem IsDedekindDomain.exists_forall_sub_mem_ideal {ι : Type*} {s : Finset ι} (P : ι → Ideal R)
(e : ι → ℕ) (prime : ∀ i ∈ s, Prime (P i))
(coprime : ∀ᵉ (i ∈ s) (j ∈ s), i ≠ j → P i ≠ P j) (x : s → R) :
∃ y, ∀ (i) (hi : i ∈ s), y - x ⟨i, hi⟩ ∈ P i ^ e i := by
obtain ⟨y, hy⟩ :=
IsDedekindDomain.exists_representative_mod_finset P e prime coprime fun i =>
Ideal.Quotient.mk _ (x i)
exact ⟨y, fun i hi => Ideal.Quotient.eq.mp (hy i hi)⟩
end DedekindDomain
end ChineseRemainder
section PID
open UniqueFactorizationMonoid Ideal
variable {R}
variable [IsDomain R] [IsPrincipalIdealRing R]
theorem span_singleton_dvd_span_singleton_iff_dvd {a b : R} :
Ideal.span {a} ∣ Ideal.span ({b} : Set R) ↔ a ∣ b :=
⟨fun h => mem_span_singleton.mp (dvd_iff_le.mp h (mem_span_singleton.mpr (dvd_refl b))), fun h =>
dvd_iff_le.mpr fun _d hd => mem_span_singleton.mpr (dvd_trans h (mem_span_singleton.mp hd))⟩
@[simp]
theorem Ideal.squarefree_span_singleton {a : R} :
Squarefree (span {a}) ↔ Squarefree a := by
refine ⟨fun h x hx ↦ ?_, fun h I hI ↦ ?_⟩
· rw [← span_singleton_dvd_span_singleton_iff_dvd, ← span_singleton_mul_span_singleton] at hx
simpa using h _ hx
· rw [← span_singleton_generator I, span_singleton_mul_span_singleton,
span_singleton_dvd_span_singleton_iff_dvd] at hI
exact isUnit_iff.mpr <| eq_top_of_isUnit_mem _ (Submodule.IsPrincipal.generator_mem I) (h _ hI)
theorem singleton_span_mem_normalizedFactors_of_mem_normalizedFactors [NormalizationMonoid R]
{a b : R} (ha : a ∈ normalizedFactors b) :
Ideal.span ({a} : Set R) ∈ normalizedFactors (Ideal.span ({b} : Set R)) := by
by_cases hb : b = 0
· rw [Ideal.span_singleton_eq_bot.mpr hb, bot_eq_zero, normalizedFactors_zero]
rw [hb, normalizedFactors_zero] at ha
exact absurd ha (Multiset.notMem_zero a)
· suffices Prime (Ideal.span ({a} : Set R)) by
obtain ⟨c, hc, hc'⟩ := exists_mem_normalizedFactors_of_dvd ?_ this.irreducible
(dvd_iff_le.mpr (span_singleton_le_span_singleton.mpr (dvd_of_mem_normalizedFactors ha)))
rwa [associated_iff_eq.mp hc']
· by_contra h
exact hb (span_singleton_eq_bot.mp h)
rw [prime_iff_isPrime]
· exact (span_singleton_prime (prime_of_normalized_factor a ha).ne_zero).mpr
(prime_of_normalized_factor a ha)
· by_contra h
exact (prime_of_normalized_factor a ha).ne_zero (span_singleton_eq_bot.mp h)
theorem emultiplicity_eq_emultiplicity_span {a b : R} :
emultiplicity (Ideal.span {a}) (Ideal.span ({b} : Set R)) = emultiplicity a b := by
by_cases h : FiniteMultiplicity a b
· rw [h.emultiplicity_eq_multiplicity]
apply emultiplicity_eq_of_dvd_of_not_dvd <;>
rw [Ideal.span_singleton_pow, span_singleton_dvd_span_singleton_iff_dvd]
· exact pow_multiplicity_dvd a b
· apply h.not_pow_dvd_of_multiplicity_lt
apply lt_add_one
· suffices ¬FiniteMultiplicity (Ideal.span ({a} : Set R)) (Ideal.span ({b} : Set R)) by
rw [emultiplicity_eq_top.2 h, emultiplicity_eq_top.2 this]
exact FiniteMultiplicity.not_iff_forall.mpr fun n => by
rw [Ideal.span_singleton_pow, span_singleton_dvd_span_singleton_iff_dvd]
exact FiniteMultiplicity.not_iff_forall.mp h n
section NormalizationMonoid
variable [NormalizationMonoid R]
/-- The bijection between the (normalized) prime factors of `r` and the (normalized) prime factors
of `span {r}` -/
noncomputable def normalizedFactorsEquivSpanNormalizedFactors {r : R} (hr : r ≠ 0) :
{ d : R | d ∈ normalizedFactors r } ≃
{ I : Ideal R | I ∈ normalizedFactors (Ideal.span ({r} : Set R)) } := by
refine Equiv.ofBijective ?_ ?_
· exact fun d =>
⟨Ideal.span {↑d}, singleton_span_mem_normalizedFactors_of_mem_normalizedFactors d.prop⟩
· refine ⟨?_, ?_⟩
· rintro ⟨a, ha⟩ ⟨b, hb⟩ h
rw [Subtype.mk_eq_mk, Ideal.span_singleton_eq_span_singleton, Subtype.coe_mk,
Subtype.coe_mk] at h
exact Subtype.mk_eq_mk.mpr (mem_normalizedFactors_eq_of_associated ha hb h)
· rintro ⟨i, hi⟩
have : i.IsPrime := isPrime_of_prime (prime_of_normalized_factor i hi)
have := exists_mem_normalizedFactors_of_dvd hr
(Submodule.IsPrincipal.prime_generator_of_isPrime i
(prime_of_normalized_factor i hi).ne_zero).irreducible ?_
· obtain ⟨a, ha, ha'⟩ := this
use ⟨a, ha⟩
simp only [← span_singleton_eq_span_singleton.mpr ha',
Ideal.span_singleton_generator]
· exact (Submodule.IsPrincipal.mem_iff_generator_dvd i).mp
((show Ideal.span {r} ≤ i from dvd_iff_le.mp (dvd_of_mem_normalizedFactors hi))
(mem_span_singleton.mpr (dvd_refl r)))
/-- The bijection `normalizedFactorsEquivSpanNormalizedFactors` between the set of prime
factors of `r` and the set of prime factors of the ideal `⟨r⟩` preserves multiplicities. See
`count_normalizedFactorsSpan_eq_count` for the version stated in terms of multisets `count`. -/
theorem emultiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_emultiplicity {r d : R}
(hr : r ≠ 0) (hd : d ∈ normalizedFactors r) :
emultiplicity d r =
emultiplicity (normalizedFactorsEquivSpanNormalizedFactors hr ⟨d, hd⟩ : Ideal R)
(Ideal.span {r}) := by
simp only [normalizedFactorsEquivSpanNormalizedFactors, emultiplicity_eq_emultiplicity_span,
Subtype.coe_mk, Equiv.ofBijective_apply]
/-- The bijection `normalized_factors_equiv_span_normalized_factors.symm` between the set of prime
factors of the ideal `⟨r⟩` and the set of prime factors of `r` preserves multiplicities. -/
theorem emultiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_emultiplicity {r : R}
(hr : r ≠ 0) (I : { I : Ideal R | I ∈ normalizedFactors (Ideal.span ({r} : Set R)) }) :
emultiplicity ((normalizedFactorsEquivSpanNormalizedFactors hr).symm I : R) r =
emultiplicity (I : Ideal R) (Ideal.span {r}) := by
obtain ⟨x, hx⟩ := (normalizedFactorsEquivSpanNormalizedFactors hr).surjective I
obtain ⟨a, ha⟩ := x
rw [hx.symm, Equiv.symm_apply_apply, Subtype.coe_mk,
emultiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_emultiplicity hr ha]
variable [DecidableEq R] [DecidableEq (Ideal R)]
/-- The bijection between the set of prime factors of the ideal `⟨r⟩` and the set of prime factors
of `r` preserves `count` of the corresponding multisets. See
`multiplicity_normalizedFactorsEquivSpanNormalizedFactors_eq_multiplicity` for the version
stated in terms of multiplicity. -/
theorem count_span_normalizedFactors_eq {r X : R} (hr : r ≠ 0) (hX : Prime X) :
Multiset.count (Ideal.span {X} : Ideal R) (normalizedFactors (Ideal.span {r})) =
Multiset.count (normalize X) (normalizedFactors r) := by
have := emultiplicity_eq_emultiplicity_span (R := R) (a := X) (b := r)
rw [emultiplicity_eq_count_normalizedFactors (Prime.irreducible hX) hr,
emultiplicity_eq_count_normalizedFactors (Prime.irreducible ?_), normalize_apply,
normUnit_eq_one, Units.val_one, one_eq_top, mul_top, Nat.cast_inj] at this
· simp only [normalize_apply, this]
· simp only [Submodule.zero_eq_bot, ne_eq, span_singleton_eq_bot, hr, not_false_eq_true]
· simpa only [prime_span_singleton_iff]
theorem count_span_normalizedFactors_eq_of_normUnit {r X : R}
(hr : r ≠ 0) (hX₁ : normUnit X = 1) (hX : Prime X) :
Multiset.count (Ideal.span {X} : Ideal R) (normalizedFactors (Ideal.span {r})) =
Multiset.count X (normalizedFactors r) := by
simpa [hX₁, normalize_apply] using count_span_normalizedFactors_eq hr hX
end NormalizationMonoid
end PID
section primesOverFinset
open UniqueFactorizationMonoid Ideal
open scoped Classical in
/-- The finite set of all prime factors of the pushforward of `p`. -/
noncomputable abbrev primesOverFinset {A : Type*} [CommRing A] (p : Ideal A) (B : Type*)
[CommRing B] [IsDedekindDomain B] [Algebra A B] : Finset (Ideal B) :=
(factors (p.map (algebraMap A B))).toFinset
variable {A : Type*} [CommRing A] {p : Ideal A} (hpb : p ≠ ⊥) [hpm : p.IsMaximal]
(B : Type*) [CommRing B] [IsDedekindDomain B] [Algebra A B] [NoZeroSMulDivisors A B]
include hpb in
theorem coe_primesOverFinset : primesOverFinset p B = primesOver p B := by
classical
ext P
rw [primesOverFinset, factors_eq_normalizedFactors, Finset.mem_coe, Multiset.mem_toFinset]
exact (P.mem_normalizedFactors_iff (map_ne_bot_of_ne_bot hpb)).trans <| Iff.intro
(fun ⟨hPp, h⟩ => ⟨hPp, ⟨hpm.eq_of_le (comap_ne_top _ hPp.ne_top) (le_comap_of_map_le h)⟩⟩)
(fun ⟨hPp, h⟩ => ⟨hPp, map_le_of_le_comap h.1.le⟩)
variable (p) [Algebra.IsIntegral A B]
theorem primesOver_finite : (primesOver p B).Finite := by
by_cases hpb : p = ⊥
· rw [hpb] at hpm ⊢
haveI : IsDomain A := IsDomain.of_bot_isPrime A
rw [primesOver_bot A B]
exact Set.finite_singleton ⊥
· rw [← coe_primesOverFinset hpb B]
exact (primesOverFinset p B).finite_toSet
theorem primesOver_ncard_ne_zero : (primesOver p B).ncard ≠ 0 := by
rcases exists_ideal_liesOver_maximal_of_isIntegral p B with ⟨P, hPm, hp⟩
exact Set.ncard_ne_zero_of_mem ⟨hPm.isPrime, hp⟩ (primesOver_finite p B)
theorem one_le_primesOver_ncard : 1 ≤ (primesOver p B).ncard :=
Nat.one_le_iff_ne_zero.mpr (primesOver_ncard_ne_zero p B)
end primesOverFinset
|
AffineScheme.lean
|
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Cover.Open
import Mathlib.AlgebraicGeometry.GammaSpecAdjunction
import Mathlib.AlgebraicGeometry.Restrict
import Mathlib.CategoryTheory.Limits.Opposites
import Mathlib.RingTheory.Localization.InvSubmonoid
import Mathlib.RingTheory.LocalProperties.Basic
import Mathlib.Topology.Sheaves.CommRingCat
/-!
# Affine schemes
We define the category of `AffineScheme`s as the essential image of `Spec`.
We also define predicates about affine schemes and affine open sets.
## Main definitions
* `AlgebraicGeometry.AffineScheme`: The category of affine schemes.
* `AlgebraicGeometry.IsAffine`: A scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an
isomorphism.
* `AlgebraicGeometry.Scheme.isoSpec`: The canonical isomorphism `X ≅ Spec Γ(X)` for an affine
scheme.
* `AlgebraicGeometry.AffineScheme.equivCommRingCat`: The equivalence of categories
`AffineScheme ≌ CommRingᵒᵖ` given by `AffineScheme.Spec : CommRingᵒᵖ ⥤ AffineScheme` and
`AffineScheme.Γ : AffineSchemeᵒᵖ ⥤ CommRingCat`.
* `AlgebraicGeometry.IsAffineOpen`: An open subset of a scheme is affine if the open subscheme is
affine.
* `AlgebraicGeometry.IsAffineOpen.fromSpec`: The immersion `Spec 𝒪ₓ(U) ⟶ X` for an affine `U`.
-/
-- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737
noncomputable section
open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace
universe u
namespace AlgebraicGeometry
open Spec (structureSheaf)
/-- The category of affine schemes -/
def AffineScheme :=
Scheme.Spec.EssImageSubcategory
deriving Category
/-- A Scheme is affine if the canonical map `X ⟶ Spec Γ(X)` is an isomorphism. -/
class IsAffine (X : Scheme) : Prop where
affine : IsIso X.toSpecΓ
attribute [instance] IsAffine.affine
instance (X : Scheme.{u}) [IsAffine X] : IsIso (ΓSpec.adjunction.unit.app X) := @IsAffine.affine X _
/-- The canonical isomorphism `X ≅ Spec Γ(X)` for an affine scheme. -/
@[simps! -isSimp hom]
def Scheme.isoSpec (X : Scheme) [IsAffine X] : X ≅ Spec Γ(X, ⊤) :=
asIso X.toSpecΓ
@[reassoc]
theorem Scheme.isoSpec_hom_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
X.isoSpec.hom ≫ Spec.map (f.appTop) = f ≫ Y.isoSpec.hom := by
simp only [isoSpec, asIso_hom, Scheme.toSpecΓ_naturality]
@[reassoc]
theorem Scheme.isoSpec_inv_naturality {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
Spec.map (f.appTop) ≫ Y.isoSpec.inv = X.isoSpec.inv ≫ f := by
rw [Iso.eq_inv_comp, isoSpec, asIso_hom, ← Scheme.toSpecΓ_naturality_assoc, isoSpec,
asIso_inv, IsIso.hom_inv_id, Category.comp_id]
@[reassoc (attr := simp)]
lemma Scheme.toSpecΓ_isoSpec_inv (X : Scheme.{u}) [IsAffine X] :
X.toSpecΓ ≫ X.isoSpec.inv = 𝟙 _ :=
X.isoSpec.hom_inv_id
@[reassoc (attr := simp)]
lemma Scheme.isoSpec_inv_toSpecΓ (X : Scheme.{u}) [IsAffine X] :
X.isoSpec.inv ≫ X.toSpecΓ = 𝟙 _ :=
X.isoSpec.inv_hom_id
/-- Construct an affine scheme from a scheme and the information that it is affine.
Also see `AffineScheme.of` for a typeclass version. -/
@[simps]
def AffineScheme.mk (X : Scheme) (_ : IsAffine X) : AffineScheme :=
⟨X, ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩
/-- Construct an affine scheme from a scheme. Also see `AffineScheme.mk` for a non-typeclass
version. -/
def AffineScheme.of (X : Scheme) [h : IsAffine X] : AffineScheme :=
AffineScheme.mk X h
/-- Type check a morphism of schemes as a morphism in `AffineScheme`. -/
def AffineScheme.ofHom {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
AffineScheme.of X ⟶ AffineScheme.of Y :=
f
@[simp]
theorem essImage_Spec {X : Scheme} : Scheme.Spec.essImage X ↔ IsAffine X :=
⟨fun h => ⟨Functor.essImage.unit_isIso h⟩,
fun _ => ΓSpec.adjunction.mem_essImage_of_unit_isIso _⟩
@[deprecated (since := "2025-04-08")] alias mem_Spec_essImage := essImage_Spec
instance isAffine_affineScheme (X : AffineScheme.{u}) : IsAffine X.obj :=
⟨Functor.essImage.unit_isIso X.property⟩
instance (R : CommRingCatᵒᵖ) : IsAffine (Scheme.Spec.obj R) :=
AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage R⟩
instance isAffine_Spec (R : CommRingCat) : IsAffine (Spec R) :=
AlgebraicGeometry.isAffine_affineScheme ⟨_, Scheme.Spec.obj_mem_essImage (op R)⟩
theorem IsAffine.of_isIso {X Y : Scheme} (f : X ⟶ Y) [IsIso f] [h : IsAffine Y] : IsAffine X := by
rw [← essImage_Spec] at h ⊢; exact Functor.essImage.ofIso (asIso f).symm h
@[deprecated (since := "2025-03-31")] alias isAffine_of_isIso := IsAffine.of_isIso
/-- If `f : X ⟶ Y` is a morphism between affine schemes, the corresponding arrow is isomorphic
to the arrow of the morphism on prime spectra induced by the map on global sections. -/
noncomputable
def arrowIsoSpecΓOfIsAffine {X Y : Scheme} [IsAffine X] [IsAffine Y] (f : X ⟶ Y) :
Arrow.mk f ≅ Arrow.mk (Spec.map f.appTop) :=
Arrow.isoMk X.isoSpec Y.isoSpec (ΓSpec.adjunction.unit_naturality _)
/-- If `f : A ⟶ B` is a ring homomorphism, the corresponding arrow is isomorphic
to the arrow of the morphism induced on global sections by the map on prime spectra. -/
def arrowIsoΓSpecOfIsAffine {A B : CommRingCat} (f : A ⟶ B) :
Arrow.mk f ≅ Arrow.mk ((Spec.map f).appTop) :=
Arrow.isoMk (Scheme.ΓSpecIso _).symm (Scheme.ΓSpecIso _).symm
(Scheme.ΓSpecIso_inv_naturality f).symm
theorem Scheme.isoSpec_Spec (R : CommRingCat.{u}) :
(Spec R).isoSpec = Scheme.Spec.mapIso (Scheme.ΓSpecIso R).op :=
Iso.ext (SpecMap_ΓSpecIso_hom R).symm
@[simp] theorem Scheme.isoSpec_Spec_hom (R : CommRingCat.{u}) :
(Spec R).isoSpec.hom = Spec.map (Scheme.ΓSpecIso R).hom :=
(SpecMap_ΓSpecIso_hom R).symm
@[simp] theorem Scheme.isoSpec_Spec_inv (R : CommRingCat.{u}) :
(Spec R).isoSpec.inv = Spec.map (Scheme.ΓSpecIso R).inv :=
congr($(isoSpec_Spec R).inv)
lemma ext_of_isAffine {X Y : Scheme} [IsAffine Y] {f g : X ⟶ Y} (e : f.appTop = g.appTop) :
f = g := by
rw [← cancel_mono Y.toSpecΓ, Scheme.toSpecΓ_naturality, Scheme.toSpecΓ_naturality, e]
namespace AffineScheme
/-- The `Spec` functor into the category of affine schemes. -/
def Spec : CommRingCatᵒᵖ ⥤ AffineScheme :=
Scheme.Spec.toEssImage
/-! We copy over instances from `Scheme.Spec.toEssImage`. -/
instance Spec_full : Spec.Full := Functor.Full.toEssImage _
instance Spec_faithful : Spec.Faithful := Functor.Faithful.toEssImage _
instance Spec_essSurj : Spec.EssSurj := Functor.EssSurj.toEssImage (F := _)
/-- The forgetful functor `AffineScheme ⥤ Scheme`. -/
@[simps!]
def forgetToScheme : AffineScheme ⥤ Scheme :=
Scheme.Spec.essImage.ι
/-! We copy over instances from `Scheme.Spec.essImageInclusion`. -/
instance forgetToScheme_full : forgetToScheme.Full :=
inferInstanceAs Scheme.Spec.essImage.ι.Full
instance forgetToScheme_faithful : forgetToScheme.Faithful :=
inferInstanceAs Scheme.Spec.essImage.ι.Faithful
/-- The global section functor of an affine scheme. -/
def Γ : AffineSchemeᵒᵖ ⥤ CommRingCat :=
forgetToScheme.op ⋙ Scheme.Γ
/-- The category of affine schemes is equivalent to the category of commutative rings. -/
def equivCommRingCat : AffineScheme ≌ CommRingCatᵒᵖ :=
equivEssImageOfReflective.symm
instance : Γ.{u}.rightOp.IsEquivalence := equivCommRingCat.isEquivalence_functor
instance : Γ.{u}.rightOp.op.IsEquivalence := equivCommRingCat.op.isEquivalence_functor
instance ΓIsEquiv : Γ.{u}.IsEquivalence :=
inferInstanceAs (Γ.{u}.rightOp.op ⋙ (opOpEquivalence _).functor).IsEquivalence
instance hasColimits : HasColimits AffineScheme.{u} :=
haveI := Adjunction.has_limits_of_equivalence.{u} Γ.{u}
Adjunction.has_colimits_of_equivalence.{u} (opOpEquivalence AffineScheme.{u}).inverse
instance hasLimits : HasLimits AffineScheme.{u} := by
haveI := Adjunction.has_colimits_of_equivalence Γ.{u}
haveI : HasLimits AffineScheme.{u}ᵒᵖᵒᵖ := Limits.hasLimits_op_of_hasColimits
exact Adjunction.has_limits_of_equivalence (opOpEquivalence AffineScheme.{u}).inverse
noncomputable instance Γ_preservesLimits : PreservesLimits Γ.{u}.rightOp := inferInstance
noncomputable instance forgetToScheme_preservesLimits : PreservesLimits forgetToScheme := by
apply (config := { allowSynthFailures := true })
@preservesLimits_of_natIso _ _ _ _ _ _
(Functor.isoWhiskerRight equivCommRingCat.unitIso forgetToScheme).symm
change PreservesLimits (equivCommRingCat.functor ⋙ Scheme.Spec)
infer_instance
end AffineScheme
/-- An open subset of a scheme is affine if the open subscheme is affine. -/
def IsAffineOpen {X : Scheme} (U : X.Opens) : Prop :=
IsAffine U
/-- The set of affine opens as a subset of `opens X`. -/
def Scheme.affineOpens (X : Scheme) : Set X.Opens :=
{U : X.Opens | IsAffineOpen U}
instance {Y : Scheme.{u}} (U : Y.affineOpens) : IsAffine U :=
U.property
theorem isAffineOpen_opensRange {X Y : Scheme} [IsAffine X] (f : X ⟶ Y)
[H : IsOpenImmersion f] : IsAffineOpen (Scheme.Hom.opensRange f) := by
refine .of_isIso (IsOpenImmersion.isoOfRangeEq f (Y.ofRestrict _) ?_).inv
exact Subtype.range_val.symm
theorem isAffineOpen_top (X : Scheme) [IsAffine X] : IsAffineOpen (⊤ : X.Opens) := by
convert isAffineOpen_opensRange (𝟙 X)
ext1
exact Set.range_id.symm
theorem exists_isAffineOpen_mem_and_subset {X : Scheme.{u}} {x : X}
{U : X.Opens} (hxU : x ∈ U) : ∃ W : X.Opens, IsAffineOpen W ∧ x ∈ W ∧ W.1 ⊆ U := by
obtain ⟨R, f, hf⟩ := AlgebraicGeometry.Scheme.exists_affine_mem_range_and_range_subset hxU
exact ⟨Scheme.Hom.opensRange f (H := hf.1),
⟨AlgebraicGeometry.isAffineOpen_opensRange f (H := hf.1), hf.2.1, hf.2.2⟩⟩
instance Scheme.isAffine_affineCover (X : Scheme) (i : X.affineCover.J) :
IsAffine (X.affineCover.obj i) :=
isAffine_Spec _
instance Scheme.isAffine_affineBasisCover (X : Scheme) (i : X.affineBasisCover.J) :
IsAffine (X.affineBasisCover.obj i) :=
isAffine_Spec _
instance Scheme.isAffine_affineOpenCover (X : Scheme) (𝒰 : X.AffineOpenCover) (i : 𝒰.J) :
IsAffine (𝒰.openCover.obj i) :=
inferInstanceAs (IsAffine (Spec (𝒰.obj i)))
instance (X : Scheme) [CompactSpace X] (𝒰 : X.OpenCover) [∀ i, IsAffine (𝒰.obj i)] (i) :
IsAffine (𝒰.finiteSubcover.obj i) :=
inferInstanceAs (IsAffine (𝒰.obj _))
instance {X} [IsAffine X] (i) :
IsAffine ((Scheme.coverOfIsIso (P := @IsOpenImmersion) (𝟙 X)).obj i) := by
dsimp; infer_instance
theorem isBasis_affine_open (X : Scheme) : Opens.IsBasis X.affineOpens := by
rw [Opens.isBasis_iff_nbhd]
rintro U x (hU : x ∈ (U : Set X))
obtain ⟨S, hS, hxS, hSU⟩ := X.affineBasisCover_is_basis.exists_subset_of_mem_open hU U.isOpen
refine ⟨⟨S, X.affineBasisCover_is_basis.isOpen hS⟩, ?_, hxS, hSU⟩
rcases hS with ⟨i, rfl⟩
exact isAffineOpen_opensRange _
theorem iSup_affineOpens_eq_top (X : Scheme) : ⨆ i : X.affineOpens, (i : X.Opens) = ⊤ := by
apply Opens.ext
rw [Opens.coe_iSup]
apply IsTopologicalBasis.sUnion_eq
rw [← Set.image_eq_range]
exact isBasis_affine_open X
theorem Scheme.map_PrimeSpectrum_basicOpen_of_affine
(X : Scheme) [IsAffine X] (f : Γ(X, ⊤)) :
X.isoSpec.hom ⁻¹ᵁ PrimeSpectrum.basicOpen f = X.basicOpen f :=
Scheme.toSpecΓ_preimage_basicOpen _ _
theorem isBasis_basicOpen (X : Scheme) [IsAffine X] :
Opens.IsBasis (Set.range (X.basicOpen : Γ(X, ⊤) → X.Opens)) := by
convert PrimeSpectrum.isBasis_basic_opens.of_isInducing
(TopCat.homeoOfIso (Scheme.forgetToTop.mapIso X.isoSpec)).isInducing using 1
ext V
simp only [Set.mem_range, exists_exists_eq_and, Set.mem_setOf,
← Opens.coe_inj (V := V), ← Scheme.toSpecΓ_preimage_basicOpen]
rfl
/-- The canonical map `U ⟶ Spec Γ(X, U)` for an open `U ⊆ X`. -/
noncomputable
def Scheme.Opens.toSpecΓ {X : Scheme.{u}} (U : X.Opens) :
U.toScheme ⟶ Spec Γ(X, U) :=
U.toScheme.toSpecΓ ≫ Spec.map U.topIso.inv
@[reassoc (attr := simp)]
lemma Scheme.Opens.toSpecΓ_SpecMap_map {X : Scheme} (U V : X.Opens) (h : U ≤ V) :
U.toSpecΓ ≫ Spec.map (X.presheaf.map (homOfLE h).op) = X.homOfLE h ≫ V.toSpecΓ := by
delta Scheme.Opens.toSpecΓ
simp [← Spec.map_comp, ← X.presheaf.map_comp, toSpecΓ_naturality_assoc]
@[simp]
lemma Scheme.Opens.toSpecΓ_top {X : Scheme} :
(⊤ : X.Opens).toSpecΓ = (⊤ : X.Opens).ι ≫ X.toSpecΓ := by
simp [Scheme.Opens.toSpecΓ, toSpecΓ_naturality]; rfl
@[reassoc]
lemma Scheme.Opens.toSpecΓ_appTop {X : Scheme.{u}} (U : X.Opens) :
U.toSpecΓ.appTop = (Scheme.ΓSpecIso Γ(X, U)).hom ≫ U.topIso.inv := by
simp [Scheme.Opens.toSpecΓ]
namespace IsAffineOpen
variable {X Y : Scheme.{u}} {U : X.Opens} (hU : IsAffineOpen U) (f : Γ(X, U))
attribute [-simp] eqToHom_op in
/-- The isomorphism `U ≅ Spec Γ(X, U)` for an affine `U`. -/
@[simps! -isSimp inv]
def isoSpec :
↑U ≅ Spec Γ(X, U) :=
haveI : IsAffine U := hU
U.toScheme.isoSpec ≪≫ Scheme.Spec.mapIso U.topIso.symm.op
lemma isoSpec_hom : hU.isoSpec.hom = U.toSpecΓ := rfl
@[reassoc (attr := simp)]
lemma toSpecΓ_isoSpec_inv : U.toSpecΓ ≫ hU.isoSpec.inv = 𝟙 _ := hU.isoSpec.hom_inv_id
@[reassoc (attr := simp)]
lemma isoSpec_inv_toSpecΓ : hU.isoSpec.inv ≫ U.toSpecΓ = 𝟙 _ := hU.isoSpec.inv_hom_id
open IsLocalRing in
lemma isoSpec_hom_base_apply (x : U) :
hU.isoSpec.hom.base x = (Spec.map (X.presheaf.germ U x x.2)).base (closedPoint _) := by
dsimp [IsAffineOpen.isoSpec_hom, Scheme.isoSpec_hom, Scheme.toSpecΓ_base, Scheme.Opens.toSpecΓ]
rw [← Scheme.comp_base_apply, ← Spec.map_comp,
(Iso.eq_comp_inv _).mpr (Scheme.Opens.germ_stalkIso_hom U (V := ⊤) x trivial),
X.presheaf.germ_res_assoc, Spec.map_comp, Scheme.comp_base_apply]
congr 1
exact IsLocalRing.comap_closedPoint (U.stalkIso x).inv.hom
lemma isoSpec_inv_appTop :
hU.isoSpec.inv.appTop = U.topIso.hom ≫ (Scheme.ΓSpecIso Γ(X, U)).inv := by
simp_rw [Scheme.Opens.toScheme_presheaf_obj, isoSpec_inv, Scheme.isoSpec, asIso_inv,
Scheme.comp_app, Scheme.Opens.topIso_hom, Scheme.ΓSpecIso_inv_naturality,
Scheme.inv_appTop, -- `check_compositions` reports defeq problems starting after this step.
IsIso.inv_comp_eq]
rw [Scheme.toSpecΓ_appTop]
-- We need `erw` here because the goal has
-- `Scheme.ΓSpecIso Γ(↑U, ⊤)).hom ≫ Scheme.ΓSpecIso Γ(X, U.ι ''ᵁ ⊤)).inv`
-- and `Γ(X, U.ι ''ᵁ ⊤)` is non-reducibly defeq to `Γ(↑U, ⊤)`.
erw [Iso.hom_inv_id_assoc]
simp only [Opens.map_top]
lemma isoSpec_hom_appTop :
hU.isoSpec.hom.appTop = (Scheme.ΓSpecIso Γ(X, U)).hom ≫ U.topIso.inv := by
have := congr(inv $hU.isoSpec_inv_appTop)
rw [IsIso.inv_comp, IsIso.Iso.inv_inv, IsIso.Iso.inv_hom] at this
have := (Scheme.Γ.map_inv hU.isoSpec.inv.op).trans this
rwa [← op_inv, IsIso.Iso.inv_inv] at this
/-- The open immersion `Spec Γ(X, U) ⟶ X` for an affine `U`. -/
def fromSpec :
Spec Γ(X, U) ⟶ X :=
haveI : IsAffine U := hU
hU.isoSpec.inv ≫ U.ι
instance isOpenImmersion_fromSpec :
IsOpenImmersion hU.fromSpec := by
delta fromSpec
infer_instance
@[reassoc (attr := simp)]
lemma isoSpec_inv_ι : hU.isoSpec.inv ≫ U.ι = hU.fromSpec := rfl
@[reassoc (attr := simp)]
lemma toSpecΓ_fromSpec : U.toSpecΓ ≫ hU.fromSpec = U.ι := toSpecΓ_isoSpec_inv_assoc _ _
@[simp]
theorem range_fromSpec :
Set.range hU.fromSpec.base = (U : Set X) := by
delta IsAffineOpen.fromSpec; dsimp [IsAffineOpen.isoSpec_inv]
rw [Set.range_comp, Set.range_eq_univ.mpr, Set.image_univ]
· exact Subtype.range_coe
rw [← TopCat.coe_comp, ← TopCat.epi_iff_surjective]
infer_instance
@[simp]
theorem opensRange_fromSpec : hU.fromSpec.opensRange = U := Opens.ext (range_fromSpec hU)
@[reassoc (attr := simp)]
theorem map_fromSpec {V : X.Opens} (hV : IsAffineOpen V) (f : op U ⟶ op V) :
Spec.map (X.presheaf.map f) ≫ hU.fromSpec = hV.fromSpec := by
have : IsAffine U := hU
haveI : IsAffine _ := hV
conv_rhs =>
rw [fromSpec, ← X.homOfLE_ι (V := U) f.unop.le, isoSpec_inv, Category.assoc,
← Scheme.isoSpec_inv_naturality_assoc,
← Spec.map_comp_assoc, Scheme.homOfLE_appTop, ← Functor.map_comp]
rw [fromSpec, isoSpec_inv, Category.assoc, ← Spec.map_comp_assoc, ← Functor.map_comp]
rfl
@[reassoc]
lemma Spec_map_appLE_fromSpec (f : X ⟶ Y) {V : X.Opens} {U : Y.Opens}
(hU : IsAffineOpen U) (hV : IsAffineOpen V) (i : V ≤ f ⁻¹ᵁ U) :
Spec.map (f.appLE U V i) ≫ hU.fromSpec = hV.fromSpec ≫ f := by
have : IsAffine U := hU
simp only [IsAffineOpen.fromSpec, Category.assoc, isoSpec_inv]
simp_rw [← Scheme.homOfLE_ι _ i]
rw [Category.assoc, ← morphismRestrict_ι,
← Category.assoc _ (f ∣_ U) U.ι, ← @Scheme.isoSpec_inv_naturality_assoc,
← Spec.map_comp_assoc, ← Spec.map_comp_assoc, Scheme.comp_appTop, morphismRestrict_appTop,
Scheme.homOfLE_appTop, Scheme.Hom.app_eq_appLE, Scheme.Hom.appLE_map,
Scheme.Hom.appLE_map, Scheme.Hom.appLE_map, Scheme.Hom.map_appLE]
lemma fromSpec_top [IsAffine X] : (isAffineOpen_top X).fromSpec = X.isoSpec.inv := by
rw [fromSpec, isoSpec_inv, Category.assoc, ← @Scheme.isoSpec_inv_naturality,
← Spec.map_comp_assoc, Scheme.Opens.ι_appTop, ← X.presheaf.map_comp, ← op_comp,
eqToHom_comp_homOfLE, ← eqToHom_eq_homOfLE rfl, eqToHom_refl, op_id, X.presheaf.map_id,
Spec.map_id, Category.id_comp]
lemma fromSpec_app_of_le (V : X.Opens) (h : U ≤ V) :
hU.fromSpec.app V = X.presheaf.map (homOfLE h).op ≫
(Scheme.ΓSpecIso Γ(X, U)).inv ≫ (Spec _).presheaf.map (homOfLE le_top).op := by
have : U.ι ⁻¹ᵁ V = ⊤ := eq_top_iff.mpr fun x _ ↦ h x.2
rw [IsAffineOpen.fromSpec, Scheme.comp_app, Scheme.Opens.ι_app, Scheme.app_eq _ this,
← Scheme.Hom.appTop, IsAffineOpen.isoSpec_inv_appTop]
simp only [Scheme.Opens.toScheme_presheaf_map, Scheme.Opens.topIso_hom,
Category.assoc, ← X.presheaf.map_comp_assoc]
rfl
include hU in
protected theorem isCompact :
IsCompact (U : Set X) := by
convert @IsCompact.image _ _ _ _ Set.univ hU.fromSpec.base PrimeSpectrum.compactSpace.1
(by fun_prop)
convert hU.range_fromSpec.symm
exact Set.image_univ
include hU in
theorem image_of_isOpenImmersion (f : X ⟶ Y) [H : IsOpenImmersion f] :
IsAffineOpen (f ''ᵁ U) := by
have : IsAffine _ := hU
convert isAffineOpen_opensRange (U.ι ≫ f)
ext1
exact Set.image_eq_range _ _
theorem preimage_of_isIso {U : Y.Opens} (hU : IsAffineOpen U) (f : X ⟶ Y) [IsIso f] :
IsAffineOpen (f ⁻¹ᵁ U) :=
haveI : IsAffine _ := hU
.of_isIso (f ∣_ U)
theorem _root_.AlgebraicGeometry.Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion
(f : AlgebraicGeometry.Scheme.Hom X Y) [H : IsOpenImmersion f] {U : X.Opens} :
IsAffineOpen (f ''ᵁ U) ↔ IsAffineOpen U where
mp hU := by
refine .of_isIso (IsOpenImmersion.isoOfRangeEq (X.ofRestrict U.isOpenEmbedding ≫ f)
(Y.ofRestrict _) ?_).hom (h := hU)
rw [Scheme.comp_base, TopCat.coe_comp, Set.range_comp]
dsimp [Opens.coe_inclusion', Scheme.restrict]
rw [Subtype.range_coe, Subtype.range_coe]
rfl
mpr hU := hU.image_of_isOpenImmersion f
/-- The affine open sets of an open subscheme corresponds to
the affine open sets containing in the image. -/
@[simps]
def _root_.AlgebraicGeometry.IsOpenImmersion.affineOpensEquiv (f : X ⟶ Y) [H : IsOpenImmersion f] :
X.affineOpens ≃ { U : Y.affineOpens // U ≤ f.opensRange } where
toFun U := ⟨⟨f ''ᵁ U, U.2.image_of_isOpenImmersion f⟩, Set.image_subset_range _ _⟩
invFun U := ⟨f ⁻¹ᵁ U, f.isAffineOpen_iff_of_isOpenImmersion.mp (by
rw [show f ''ᵁ f ⁻¹ᵁ U = U from Opens.ext (Set.image_preimage_eq_of_subset U.2)]; exact U.1.2)⟩
left_inv _ := Subtype.ext (Opens.ext (Set.preimage_image_eq _ H.base_open.injective))
right_inv U := Subtype.ext (Subtype.ext (Opens.ext (Set.image_preimage_eq_of_subset U.2)))
/-- The affine open sets of an open subscheme
corresponds to the affine open sets containing in the subset. -/
@[simps! apply_coe_coe]
def _root_.AlgebraicGeometry.affineOpensRestrict {X : Scheme.{u}} (U : X.Opens) :
U.toScheme.affineOpens ≃ { V : X.affineOpens // V ≤ U } :=
(IsOpenImmersion.affineOpensEquiv U.ι).trans (Equiv.subtypeEquivProp (by simp))
@[simp]
lemma _root_.AlgebraicGeometry.affineOpensRestrict_symm_apply_coe
{X : Scheme.{u}} (U : X.Opens) (V) :
((affineOpensRestrict U).symm V).1 = U.ι ⁻¹ᵁ V := rfl
instance (priority := 100) _root_.AlgebraicGeometry.Scheme.compactSpace_of_isAffine
(X : Scheme) [IsAffine X] :
CompactSpace X :=
⟨(isAffineOpen_top X).isCompact⟩
@[simp]
theorem fromSpec_preimage_self :
hU.fromSpec ⁻¹ᵁ U = ⊤ := by
ext1
rw [Opens.map_coe, Opens.coe_top, ← hU.range_fromSpec, ← Set.image_univ]
exact Set.preimage_image_eq _ PresheafedSpace.IsOpenImmersion.base_open.injective
theorem ΓSpecIso_hom_fromSpec_app :
(Scheme.ΓSpecIso Γ(X, U)).hom ≫ hU.fromSpec.app U =
(Spec Γ(X, U)).presheaf.map (eqToHom hU.fromSpec_preimage_self).op := by
simp only [fromSpec, Scheme.comp_coeBase, Opens.map_comp_obj, Scheme.comp_app,
Scheme.Opens.ι_app_self, eqToHom_op, Scheme.app_eq _ U.ι_preimage_self,
Scheme.Opens.toScheme_presheaf_map, eqToHom_unop, eqToHom_map U.ι.opensFunctor, Opens.map_top,
isoSpec_inv_appTop, Scheme.Opens.topIso_hom, Category.assoc, ← Functor.map_comp_assoc,
eqToHom_trans, eqToHom_refl, X.presheaf.map_id, Category.id_comp, Iso.hom_inv_id_assoc]
@[elementwise]
theorem fromSpec_app_self :
hU.fromSpec.app U = (Scheme.ΓSpecIso Γ(X, U)).inv ≫
(Spec Γ(X, U)).presheaf.map (eqToHom hU.fromSpec_preimage_self).op := by
rw [← hU.ΓSpecIso_hom_fromSpec_app, Iso.inv_hom_id_assoc]
theorem fromSpec_preimage_basicOpen' :
hU.fromSpec ⁻¹ᵁ X.basicOpen f = (Spec Γ(X, U)).basicOpen ((Scheme.ΓSpecIso Γ(X, U)).inv f) := by
rw [Scheme.preimage_basicOpen, hU.fromSpec_app_self]
exact Scheme.basicOpen_res_eq _ _ (eqToHom hU.fromSpec_preimage_self).op
theorem fromSpec_preimage_basicOpen :
hU.fromSpec ⁻¹ᵁ X.basicOpen f = PrimeSpectrum.basicOpen f := by
rw [fromSpec_preimage_basicOpen', ← basicOpen_eq_of_affine]
theorem fromSpec_image_basicOpen :
hU.fromSpec ''ᵁ (PrimeSpectrum.basicOpen f) = X.basicOpen f := by
rw [← hU.fromSpec_preimage_basicOpen]
ext1
change hU.fromSpec.base '' (hU.fromSpec.base ⁻¹' (X.basicOpen f : Set X)) = _
rw [Set.image_preimage_eq_inter_range, Set.inter_eq_left, hU.range_fromSpec]
exact Scheme.basicOpen_le _ _
@[simp]
theorem basicOpen_fromSpec_app :
(Spec Γ(X, U)).basicOpen (hU.fromSpec.app U f) = PrimeSpectrum.basicOpen f := by
rw [← hU.fromSpec_preimage_basicOpen, Scheme.preimage_basicOpen]
include hU in
theorem basicOpen :
IsAffineOpen (X.basicOpen f) := by
rw [← hU.fromSpec_image_basicOpen, Scheme.Hom.isAffineOpen_iff_of_isOpenImmersion]
convert isAffineOpen_opensRange
(Spec.map (CommRingCat.ofHom <| algebraMap Γ(X, U) (Localization.Away f)))
exact Opens.ext (PrimeSpectrum.localization_away_comap_range (Localization.Away f) f).symm
lemma Spec_basicOpen {R : CommRingCat} (f : R) :
IsAffineOpen (X := Spec R) (PrimeSpectrum.basicOpen f) :=
basicOpen_eq_of_affine f ▸ (isAffineOpen_top Spec(R)).basicOpen _
instance [IsAffine X] (r : Γ(X, ⊤)) : IsAffine (X.basicOpen r) :=
(isAffineOpen_top X).basicOpen _
include hU in
theorem ι_basicOpen_preimage (r : Γ(X, ⊤)) :
IsAffineOpen ((X.basicOpen r).ι ⁻¹ᵁ U) := by
apply (X.basicOpen r).ι.isAffineOpen_iff_of_isOpenImmersion.mp
dsimp [Scheme.Hom.opensFunctor, LocallyRingedSpace.IsOpenImmersion.opensFunctor]
rw [Opens.functor_obj_map_obj, Opens.isOpenEmbedding_obj_top, inf_comm,
← Scheme.basicOpen_res _ _ (homOfLE le_top).op]
exact hU.basicOpen _
include hU in
theorem exists_basicOpen_le {V : X.Opens} (x : V) (h : ↑x ∈ U) :
∃ f : Γ(X, U), X.basicOpen f ≤ V ∧ ↑x ∈ X.basicOpen f := by
have : IsAffine _ := hU
obtain ⟨_, ⟨_, ⟨r, rfl⟩, rfl⟩, h₁, h₂⟩ :=
(isBasis_basicOpen U).exists_subset_of_mem_open (x.2 : (⟨x, h⟩ : U) ∈ _)
((Opens.map U.inclusion').obj V).isOpen
have :
U.ι ''ᵁ (U.toScheme.basicOpen r) =
X.basicOpen (X.presheaf.map (eqToHom U.isOpenEmbedding_obj_top.symm).op r) := by
refine (Scheme.image_basicOpen U.ι r).trans ?_
rw [Scheme.basicOpen_res_eq]
simp only [Scheme.Opens.toScheme_presheaf_obj, Scheme.Opens.ι_appIso, Iso.refl_inv,
CommRingCat.id_apply]
use X.presheaf.map (eqToHom U.isOpenEmbedding_obj_top.symm).op r
rw [← this]
exact ⟨Set.image_subset_iff.mpr h₂, ⟨_, h⟩, h₁, rfl⟩
noncomputable
instance {R : CommRingCat} {U} : Algebra R Γ(Spec R, U) :=
((Scheme.ΓSpecIso R).inv ≫ (Spec R).presheaf.map (homOfLE le_top).op).hom.toAlgebra
@[simp]
lemma algebraMap_Spec_obj {R : CommRingCat} {U} : algebraMap R Γ(Spec R, U) =
((Scheme.ΓSpecIso R).inv ≫ (Spec R).presheaf.map (homOfLE le_top).op).hom := rfl
instance {R : CommRingCat} {f : R} :
IsLocalization.Away f Γ(Spec R, PrimeSpectrum.basicOpen f) :=
inferInstanceAs (IsLocalization.Away f
((Spec.structureSheaf R).val.obj (op <| PrimeSpectrum.basicOpen f)))
/-- Given an affine open U and some `f : U`,
this is the canonical map `Γ(𝒪ₓ, D(f)) ⟶ Γ(Spec 𝒪ₓ(U), D(f))`
This is an isomorphism, as witnessed by an `IsIso` instance. -/
def basicOpenSectionsToAffine :
Γ(X, X.basicOpen f) ⟶ Γ(Spec Γ(X, U), PrimeSpectrum.basicOpen f) :=
hU.fromSpec.c.app (op <| X.basicOpen f) ≫
(Spec Γ(X, U)).presheaf.map (eqToHom <| (hU.fromSpec_preimage_basicOpen f).symm).op
instance basicOpenSectionsToAffine_isIso :
IsIso (basicOpenSectionsToAffine hU f) := by
delta basicOpenSectionsToAffine
refine IsIso.comp_isIso' ?_ inferInstance
apply PresheafedSpace.IsOpenImmersion.isIso_of_subset
rw [hU.range_fromSpec]
exact RingedSpace.basicOpen_le _ _
include hU in
theorem isLocalization_basicOpen :
IsLocalization.Away f Γ(X, X.basicOpen f) := by
apply
(IsLocalization.isLocalization_iff_of_ringEquiv (Submonoid.powers f)
(asIso <| basicOpenSectionsToAffine hU f).commRingCatIsoToRingEquiv).mpr
convert StructureSheaf.IsLocalization.to_basicOpen _ f using 1
-- Porting note: more hand holding is required here, the next 3 lines were not necessary
congr 1
dsimp [CommRingCat.ofHom, RingHom.algebraMap_toAlgebra, ← CommRingCat.hom_comp,
basicOpenSectionsToAffine]
rw [hU.fromSpec.naturality_assoc, hU.fromSpec_app_self]
simp only [Category.assoc, ← Functor.map_comp, ← op_comp]
exact CommRingCat.hom_ext_iff.mp (StructureSheaf.toOpen_res _ _ _ _)
instance _root_.AlgebraicGeometry.isLocalization_away_of_isAffine
[IsAffine X] (r : Γ(X, ⊤)) :
IsLocalization.Away r Γ(X, X.basicOpen r) :=
isLocalization_basicOpen (isAffineOpen_top X) r
lemma appLE_eq_away_map {X Y : Scheme.{u}} (f : X ⟶ Y) {U : Y.Opens} (hU : IsAffineOpen U)
{V : X.Opens} (hV : IsAffineOpen V) (e) (r : Γ(Y, U)) :
letI := hU.isLocalization_basicOpen r
letI := hV.isLocalization_basicOpen (f.appLE U V e r)
f.appLE (Y.basicOpen r) (X.basicOpen (f.appLE U V e r)) (by simp [Scheme.Hom.appLE]) =
CommRingCat.ofHom (IsLocalization.Away.map _ _ (f.appLE U V e).hom r) := by
letI := hU.isLocalization_basicOpen r
letI := hV.isLocalization_basicOpen (f.appLE U V e r)
ext : 1
apply IsLocalization.ringHom_ext (.powers r)
rw [IsLocalization.Away.map, CommRingCat.hom_ofHom, IsLocalization.map_comp,
RingHom.algebraMap_toAlgebra, RingHom.algebraMap_toAlgebra, ← CommRingCat.hom_comp,
← CommRingCat.hom_comp, Scheme.Hom.appLE_map, Scheme.Hom.map_appLE]
lemma app_basicOpen_eq_away_map {X Y : Scheme.{u}} (f : X ⟶ Y) {U : Y.Opens}
(hU : IsAffineOpen U) (h : IsAffineOpen (f ⁻¹ᵁ U)) (r : Γ(Y, U)) :
haveI := hU.isLocalization_basicOpen r
haveI := h.isLocalization_basicOpen (f.app U r)
f.app (Y.basicOpen r) =
(CommRingCat.ofHom
(IsLocalization.Away.map Γ(Y, Y.basicOpen r) Γ(X, X.basicOpen (f.app U r)) (f.app U).hom r)
≫ X.presheaf.map (eqToHom (by simp)).op) := by
haveI := hU.isLocalization_basicOpen r
haveI := h.isLocalization_basicOpen (f.app U r)
ext : 1
apply IsLocalization.ringHom_ext (.powers r)
rw [IsLocalization.Away.map, CommRingCat.hom_comp, RingHom.comp_assoc, CommRingCat.hom_ofHom,
IsLocalization.map_comp, RingHom.algebraMap_toAlgebra,
RingHom.algebraMap_toAlgebra, ← RingHom.comp_assoc, ← CommRingCat.hom_comp,
← CommRingCat.hom_comp, ← X.presheaf.map_comp]
simp
/-- `f.app (Y.basicOpen r)` is isomorphic to map induced on localizations
`Γ(Y, Y.basicOpen r) ⟶ Γ(X, X.basicOpen (f.app U r))` -/
def appBasicOpenIsoAwayMap {X Y : Scheme.{u}} (f : X ⟶ Y) {U : Y.Opens}
(hU : IsAffineOpen U) (h : IsAffineOpen (f ⁻¹ᵁ U)) (r : Γ(Y, U)) :
haveI := hU.isLocalization_basicOpen r
haveI := h.isLocalization_basicOpen (f.app U r)
Arrow.mk (f.app (Y.basicOpen r)) ≅
Arrow.mk (CommRingCat.ofHom (IsLocalization.Away.map Γ(Y, Y.basicOpen r)
Γ(X, X.basicOpen (f.app U r)) (f.app U).hom r)) :=
Arrow.isoMk (Iso.refl _) (X.presheaf.mapIso (eqToIso (by simp)).op) <| by
simp [hU.app_basicOpen_eq_away_map f h]
include hU in
theorem isLocalization_of_eq_basicOpen {V : X.Opens} (i : V ⟶ U) (e : V = X.basicOpen f) :
@IsLocalization.Away _ _ f Γ(X, V) _ (X.presheaf.map i.op).hom.toAlgebra := by
subst e; convert isLocalization_basicOpen hU f using 3
instance _root_.AlgebraicGeometry.Γ_restrict_isLocalization
(X : Scheme.{u}) [IsAffine X] (r : Γ(X, ⊤)) :
IsLocalization.Away r Γ(X.basicOpen r, ⊤) :=
(isAffineOpen_top X).isLocalization_of_eq_basicOpen r _ (Opens.isOpenEmbedding_obj_top _)
include hU in
theorem basicOpen_basicOpen_is_basicOpen (g : Γ(X, X.basicOpen f)) :
∃ f' : Γ(X, U), X.basicOpen f' = X.basicOpen g := by
have := isLocalization_basicOpen hU f
obtain ⟨x, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.surj'' (Submonoid.powers f) g
use f * x
rw [Algebra.smul_def, Scheme.basicOpen_mul, Scheme.basicOpen_mul, RingHom.algebraMap_toAlgebra,
Scheme.basicOpen_res]
refine (inf_eq_left.mpr (inf_le_left.trans_eq (Scheme.basicOpen_of_isUnit _ ?_).symm)).symm
exact
Submonoid.leftInv_le_isUnit _
(IsLocalization.toInvSubmonoid (Submonoid.powers f) (Γ(X, X.basicOpen f))
_).prop
include hU in
theorem _root_.AlgebraicGeometry.exists_basicOpen_le_affine_inter
{V : X.Opens} (hV : IsAffineOpen V) (x : X) (hx : x ∈ U ⊓ V) :
∃ (f : Γ(X, U)) (g : Γ(X, V)), X.basicOpen f = X.basicOpen g ∧ x ∈ X.basicOpen f := by
obtain ⟨f, hf₁, hf₂⟩ := hU.exists_basicOpen_le ⟨x, hx.2⟩ hx.1
obtain ⟨g, hg₁, hg₂⟩ := hV.exists_basicOpen_le ⟨x, hf₂⟩ hx.2
obtain ⟨f', hf'⟩ :=
basicOpen_basicOpen_is_basicOpen hU f (X.presheaf.map (homOfLE hf₁ : _ ⟶ V).op g)
replace hf' := (hf'.trans (RingedSpace.basicOpen_res _ _ _)).trans (inf_eq_right.mpr hg₁)
exact ⟨f', g, hf', hf'.symm ▸ hg₂⟩
/-- The prime ideal of `𝒪ₓ(U)` corresponding to a point `x : U`. -/
noncomputable def primeIdealOf (x : U) :
PrimeSpectrum Γ(X, U) :=
hU.isoSpec.hom.base x
theorem fromSpec_primeIdealOf (x : U) :
hU.fromSpec.base (hU.primeIdealOf x) = x.1 := by
dsimp only [IsAffineOpen.fromSpec, Subtype.coe_mk, IsAffineOpen.primeIdealOf]
rw [← Scheme.comp_base_apply, Iso.hom_inv_id_assoc]
rfl
open IsLocalRing in
theorem primeIdealOf_eq_map_closedPoint (x : U) :
hU.primeIdealOf x = (Spec.map (X.presheaf.germ _ x x.2)).base (closedPoint _) :=
hU.isoSpec_hom_base_apply _
theorem isLocalization_stalk' (y : PrimeSpectrum Γ(X, U)) (hy : hU.fromSpec.base y ∈ U) :
@IsLocalization.AtPrime
(R := Γ(X, U))
(S := X.presheaf.stalk <| hU.fromSpec.base y) _ _
((TopCat.Presheaf.algebra_section_stalk X.presheaf _)) y.asIdeal _ := by
apply
(@IsLocalization.isLocalization_iff_of_ringEquiv (R := Γ(X, U))
(S := X.presheaf.stalk (hU.fromSpec.base y)) _ y.asIdeal.primeCompl _
(TopCat.Presheaf.algebra_section_stalk X.presheaf ⟨hU.fromSpec.base y, hy⟩) _ _
(asIso <| hU.fromSpec.stalkMap y).commRingCatIsoToRingEquiv).mpr
convert StructureSheaf.IsLocalization.to_stalk Γ(X, U) y using 1
delta IsLocalization.AtPrime StructureSheaf.stalkAlgebra
rw [RingHom.algebraMap_toAlgebra, RingEquiv.toRingHom_eq_coe,
CategoryTheory.Iso.commRingCatIsoToRingEquiv_toRingHom, asIso_hom, ← CommRingCat.hom_comp,
Scheme.stalkMap_germ, IsAffineOpen.fromSpec_app_self, Category.assoc, TopCat.Presheaf.germ_res]
rfl
theorem isLocalization_stalk (x : U) :
IsLocalization.AtPrime (X.presheaf.stalk x) (hU.primeIdealOf x).asIdeal := by
rcases x with ⟨x, hx⟩
set y := hU.primeIdealOf ⟨x, hx⟩ with hy
have : hU.fromSpec.base y = x := hy ▸ hU.fromSpec_primeIdealOf ⟨x, hx⟩
clear_value y
subst this
exact hU.isLocalization_stalk' y hx
lemma stalkMap_injective (f : X ⟶ Y) {U : Opens Y} (hU : IsAffineOpen U) (x : X)
(hx : f.base x ∈ U)
(h : ∀ g, f.stalkMap x (Y.presheaf.germ U (f.base x) hx g) = 0 →
Y.presheaf.germ U (f.base x) hx g = 0) :
Function.Injective (f.stalkMap x) := by
letI := Y.presheaf.algebra_section_stalk ⟨f.base x, hx⟩
apply (hU.isLocalization_stalk ⟨f.base x, hx⟩).injective_of_map_algebraMap_zero
exact h
include hU in
lemma mem_ideal_iff {s : Γ(X, U)} {I : Ideal Γ(X, U)} :
s ∈ I ↔ ∀ (x : X) (h : x ∈ U), X.presheaf.germ U x h s ∈ I.map (X.presheaf.germ U x h).hom := by
refine ⟨fun hs x hxU ↦ Ideal.mem_map_of_mem _ hs, fun H ↦ ?_⟩
letI (x : _) : Algebra Γ(X, U) (X.presheaf.stalk (hU.fromSpec.base x)) :=
TopCat.Presheaf.algebra_section_stalk X.presheaf _
have (P : Ideal Γ(X, U)) [hP : P.IsPrime] : IsLocalization.AtPrime _ P :=
hU.isLocalization_stalk' ⟨P, hP⟩ (hU.isoSpec.inv.base _).2
have (P : Ideal Γ(X, U)) [hP : P.IsPrime] : IsLocalizedModule P.primeCompl _ :=
(@isLocalizedModule_iff_isLocalization' ..).mpr (this P)
refine Submodule.mem_of_localization_maximal
(fun P hP ↦ X.presheaf.stalk (hU.fromSpec.base ⟨P, hP.isPrime⟩))
(fun P hP ↦ Algebra.linearMap _ _) _ _ ?_
intro P hP
rw [Ideal.localized₀_eq_restrictScalars_map]
exact H _ _
include hU in
lemma ideal_le_iff {I J : Ideal Γ(X, U)} :
I ≤ J ↔ ∀ (x : X) (h : x ∈ U),
I.map (X.presheaf.germ U x h).hom ≤ J.map (X.presheaf.germ U x h).hom :=
⟨fun h _ _ ↦ Ideal.map_mono h,
fun H _ hs ↦ hU.mem_ideal_iff.mpr fun x hx ↦ H x hx (Ideal.mem_map_of_mem _ hs)⟩
include hU in
lemma ideal_ext_iff {I J : Ideal Γ(X, U)} :
I = J ↔ ∀ (x : X) (h : x ∈ U),
I.map (X.presheaf.germ U x h).hom = J.map (X.presheaf.germ U x h).hom := by
simp_rw [le_antisymm_iff, hU.ideal_le_iff, forall_and]
/-- The basic open set of a section `f` on an affine open as an `X.affineOpens`. -/
@[simps]
def _root_.AlgebraicGeometry.Scheme.affineBasicOpen
(X : Scheme) {U : X.affineOpens} (f : Γ(X, U)) : X.affineOpens :=
⟨X.basicOpen f, U.prop.basicOpen f⟩
lemma _root_.AlgebraicGeometry.Scheme.affineBasicOpen_le
(X : Scheme) {V : X.affineOpens} (f : Γ(X, V.1)) : X.affineBasicOpen f ≤ V :=
X.basicOpen_le f
include hU in
/--
In an affine open set `U`, a family of basic open covers `U` iff the sections span `Γ(X, U)`.
See `iSup_basicOpen_of_span_eq_top` for the inverse direction without the affine-ness assumption.
-/
theorem basicOpen_union_eq_self_iff (s : Set Γ(X, U)) :
⨆ f : s, X.basicOpen (f : Γ(X, U)) = U ↔ Ideal.span s = ⊤ := by
trans ⋃ i : s, (PrimeSpectrum.basicOpen i.1).1 = Set.univ
· trans
hU.fromSpec.base ⁻¹' (⨆ f : s, X.basicOpen (f : Γ(X, U))).1 =
hU.fromSpec.base ⁻¹' U.1
· refine ⟨fun h => by rw [h], ?_⟩
intro h
apply_fun Set.image hU.fromSpec.base at h
rw [Set.image_preimage_eq_inter_range, Set.image_preimage_eq_inter_range, hU.range_fromSpec]
at h
simp only [Set.inter_self, Opens.carrier_eq_coe, Set.inter_eq_right] at h
ext1
refine Set.Subset.antisymm ?_ h
simp only [Set.iUnion_subset_iff, SetCoe.forall, Opens.coe_iSup]
intro x _
exact X.basicOpen_le x
· simp only [Opens.iSup_def, Set.preimage_iUnion]
congr! 1
· refine congr_arg (Set.iUnion ·) ?_
ext1 x
exact congr_arg Opens.carrier (hU.fromSpec_preimage_basicOpen _)
· exact congr_arg Opens.carrier hU.fromSpec_preimage_self
· simp only [Opens.carrier_eq_coe, PrimeSpectrum.basicOpen_eq_zeroLocus_compl]
rw [← Set.compl_iInter, Set.compl_univ_iff, ← PrimeSpectrum.zeroLocus_iUnion, ←
PrimeSpectrum.zeroLocus_empty_iff_eq_top, PrimeSpectrum.zeroLocus_span]
simp only [Set.iUnion_singleton_eq_range, Subtype.range_val_subtype, Set.setOf_mem_eq]
include hU in
theorem self_le_basicOpen_union_iff (s : Set Γ(X, U)) :
(U ≤ ⨆ f : s, X.basicOpen f.1) ↔ Ideal.span s = ⊤ := by
rw [← hU.basicOpen_union_eq_self_iff, @comm _ Eq]
refine ⟨fun h => le_antisymm h ?_, le_of_eq⟩
simp only [iSup_le_iff, SetCoe.forall]
intro x _
exact X.basicOpen_le x
end IsAffineOpen
open _root_.PrimeSpectrum in
/-- The restriction of `Spec.map f` to a basic open `D(r)` is isomorphic to `Spec.map` of the
localization of `f` away from `r`. -/
noncomputable
def SpecMapRestrictBasicOpenIso {R S : CommRingCat} (f : R ⟶ S) (r : R) :
Arrow.mk (Spec.map f ∣_ (PrimeSpectrum.basicOpen r)) ≅
Arrow.mk (Spec.map <| CommRingCat.ofHom (Localization.awayMap f.hom r)) := by
letI e₁ : Localization.Away r ≃ₐ[R] Γ(Spec R, basicOpen r) :=
IsLocalization.algEquiv (Submonoid.powers r) _ _
letI e₂ : Localization.Away (f.hom r) ≃ₐ[S] Γ(Spec S, basicOpen (f.hom r)) :=
IsLocalization.algEquiv (Submonoid.powers (f.hom r)) _ _
refine Arrow.isoMk ?_ ?_ ?_
· exact Spec(S).isoOfEq (comap_basicOpen _ _) ≪≫
(IsAffineOpen.Spec_basicOpen (f.hom r)).isoSpec ≪≫ Scheme.Spec.mapIso e₂.toCommRingCatIso.op
· exact (IsAffineOpen.Spec_basicOpen r).isoSpec ≪≫ Scheme.Spec.mapIso e₁.toCommRingCatIso.op
· have := AlgebraicGeometry.IsOpenImmersion.of_isLocalization
(S := (Localization.Away r)) r
rw [← cancel_mono (Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away r))))]
simp only [Arrow.mk_left, Arrow.mk_right, Functor.id_obj, Scheme.isoOfEq_rfl, Iso.refl_trans,
Iso.trans_hom, Functor.mapIso_hom, Iso.op_hom, Scheme.Spec_map, Quiver.Hom.unop_op,
Arrow.mk_hom, Category.assoc, ← Spec.map_comp]
conv =>
congr
· enter [2, 1]; tactic =>
change _ =
(f ≫ (Scheme.ΓSpecIso S).inv ≫ (Spec S).presheaf.map (homOfLE le_top).op)
ext
simp only [Localization.awayMap, IsLocalization.Away.map, AlgEquiv.toRingEquiv_eq_coe,
RingEquiv.toCommRingCatIso_hom, AlgEquiv.toRingEquiv_toRingHom, CommRingCat.hom_comp,
CommRingCat.hom_ofHom, RingHom.comp_apply, IsLocalization.map_eq, RingHom.coe_coe,
AlgEquiv.commutes, IsAffineOpen.algebraMap_Spec_obj]
· enter [2, 2, 1]; tactic =>
change _ = (Scheme.ΓSpecIso R).inv ≫ (Spec R).presheaf.map (homOfLE le_top).op
ext
simp only [AlgEquiv.toRingEquiv_eq_coe, RingEquiv.toCommRingCatIso_hom,
AlgEquiv.toRingEquiv_toRingHom, CommRingCat.hom_comp, CommRingCat.hom_ofHom,
RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, AlgEquiv.commutes,
IsAffineOpen.algebraMap_Spec_obj, homOfLE_leOfHom]
simp only [IsAffineOpen.isoSpec_hom, homOfLE_leOfHom, Spec.map_comp, Category.assoc,
Scheme.Opens.toSpecΓ_SpecMap_map_assoc, Scheme.Opens.toSpecΓ_top, Scheme.homOfLE_ι_assoc,
morphismRestrict_ι_assoc]
simp only [← SpecMap_ΓSpecIso_hom, ← Spec.map_comp, Category.assoc, Iso.inv_hom_id,
Category.comp_id, Category.id_comp]
rfl
lemma stalkMap_injective_of_isAffine {X Y : Scheme} (f : X ⟶ Y) [IsAffine Y] (x : X)
(h : ∀ g, f.stalkMap x (Y.presheaf.Γgerm (f.base x) g) = 0 →
Y.presheaf.Γgerm (f.base x) g = 0) :
Function.Injective (f.stalkMap x) :=
(isAffineOpen_top Y).stalkMap_injective f x trivial h
/--
Given a spanning set of `Γ(X, U)`, the corresponding basic open sets cover `U`.
See `IsAffineOpen.basicOpen_union_eq_self_iff` for the inverse direction for affine open sets.
-/
lemma iSup_basicOpen_of_span_eq_top {X : Scheme} (U) (s : Set Γ(X, U))
(hs : Ideal.span s = ⊤) : (⨆ i ∈ s, X.basicOpen i) = U := by
apply le_antisymm
· rw [iSup₂_le_iff]
exact fun i _ ↦ X.basicOpen_le i
· intro x hx
obtain ⟨_, ⟨V, hV, rfl⟩, hxV, hVU⟩ := (isBasis_affine_open X).exists_subset_of_mem_open hx U.2
refine SetLike.mem_of_subset ?_ hxV
rw [← (hV.basicOpen_union_eq_self_iff (X.presheaf.map (homOfLE hVU).op '' s)).mpr
(by rw [← Ideal.map_span, hs, Ideal.map_top])]
simp only [Opens.iSup_mk, Opens.carrier_eq_coe, Set.iUnion_coe_set, Set.mem_image,
Set.iUnion_exists, Set.biUnion_and', Set.iUnion_iUnion_eq_right, Scheme.basicOpen_res,
Opens.coe_inf, Opens.coe_mk, Set.iUnion_subset_iff]
exact fun i hi ↦ (Set.inter_subset_right.trans
(Set.subset_iUnion₂ (s := fun x _ ↦ (X.basicOpen x : Set X)) i hi))
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.
Then `P` holds for every affine open of `X`.
This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} {P : X.affineOpens → Prop}
{ι} (U : ι → X.affineOpens) (iSup_U : (⨆ i, U i : X.Opens) = ⊤)
(V : X.affineOpens)
(basicOpen : ∀ (U : X.affineOpens) (f : Γ(X, U)), P U → P (X.affineBasicOpen f))
(openCover :
∀ (U : X.affineOpens) (s : Finset (Γ(X, U)))
(_ : Ideal.span (s : Set (Γ(X, U))) = ⊤),
(∀ f : s, P (X.affineBasicOpen f.1)) → P U)
(hU : ∀ i, P (U i)) : P V := by
classical
have : ∀ (x : V.1), ∃ f : Γ(X, V), ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
intro x
obtain ⟨i, hi⟩ := Opens.mem_iSup.mp (show x.1 ∈ (⨆ i, U i : X.Opens) from iSup_U ▸ trivial)
obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop (U i).prop x ⟨x.prop, hi⟩
refine ⟨f, hf, ?_⟩
convert basicOpen _ g (hU i) using 1
ext1
exact e
choose f hf₁ hf₂ using this
suffices Ideal.span (Set.range f) = ⊤ by
obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
apply openCover V t ht₂
rintro ⟨i, hi⟩
obtain ⟨x, rfl⟩ := ht₁ hi
exact hf₂ x
rw [← V.prop.self_le_basicOpen_union_iff]
intro x hx
rw [iSup_range', SetLike.mem_coe, Opens.mem_iSup]
exact ⟨_, hf₁ ⟨x, hx⟩⟩
section ZeroLocus
namespace Scheme
open ConcreteCategory
variable (X : Scheme.{u})
/-- On a scheme `X`, the preimage of the zero locus of the prime spectrum
of `Γ(X, ⊤)` under `X.toSpecΓ : X ⟶ Spec Γ(X, ⊤)` agrees with the associated zero locus on `X`. -/
lemma toSpecΓ_preimage_zeroLocus (s : Set Γ(X, ⊤)) :
X.toSpecΓ.base ⁻¹' PrimeSpectrum.zeroLocus s = X.zeroLocus s :=
LocallyRingedSpace.toΓSpec_preimage_zeroLocus_eq s
/-- If `X` is affine, the image of the zero locus of global sections of `X` under `X.isoSpec`
is the zero locus in terms of the prime spectrum of `Γ(X, ⊤)`. -/
lemma isoSpec_image_zeroLocus [IsAffine X]
(s : Set Γ(X, ⊤)) :
X.isoSpec.hom.base '' X.zeroLocus s = PrimeSpectrum.zeroLocus s := by
rw [← X.toSpecΓ_preimage_zeroLocus]
erw [Set.image_preimage_eq]
exact (bijective_of_isIso X.isoSpec.hom.base).surjective
lemma toSpecΓ_image_zeroLocus [IsAffine X] (s : Set Γ(X, ⊤)) :
X.toSpecΓ.base '' X.zeroLocus s = PrimeSpectrum.zeroLocus s :=
X.isoSpec_image_zeroLocus _
lemma isoSpec_inv_preimage_zeroLocus [IsAffine X] (s : Set Γ(X, ⊤)) :
X.isoSpec.inv.base ⁻¹' X.zeroLocus s = PrimeSpectrum.zeroLocus s := by
rw [← toSpecΓ_preimage_zeroLocus, ← Set.preimage_comp, ← TopCat.coe_comp, ← Scheme.comp_base,
X.isoSpec_inv_toSpecΓ]
rfl
lemma isoSpec_inv_image_zeroLocus [IsAffine X] (s : Set Γ(X, ⊤)) :
X.isoSpec.inv.base '' PrimeSpectrum.zeroLocus s = X.zeroLocus s := by
rw [← isoSpec_inv_preimage_zeroLocus, Set.image_preimage_eq]
exact (bijective_of_isIso X.isoSpec.inv.base).surjective
/-- If `X` is an affine scheme, every closed set of `X` is the zero locus
of a set of global sections. -/
lemma eq_zeroLocus_of_isClosed_of_isAffine [IsAffine X] (s : Set X) :
IsClosed s ↔ ∃ I : Ideal (Γ(X, ⊤)), s = X.zeroLocus (I : Set Γ(X, ⊤)) := by
refine ⟨fun hs ↦ ?_, ?_⟩
· let Z : Set (Spec <| Γ(X, ⊤)) := X.toΓSpecFun '' s
have hZ : IsClosed Z := (X.isoSpec.hom.homeomorph).isClosedMap _ hs
obtain ⟨I, (hI : Z = _)⟩ := (PrimeSpectrum.isClosed_iff_zeroLocus_ideal _).mp hZ
use I
simp only [← Scheme.toSpecΓ_preimage_zeroLocus, ← hI, Z]
symm
exact Set.preimage_image_eq _ (bijective_of_isIso X.isoSpec.hom.base).injective
· rintro ⟨I, rfl⟩
exact zeroLocus_isClosed X I.carrier
open Set.Notation in
lemma Opens.toSpecΓ_preimage_zeroLocus {X : Scheme.{u}} (U : X.Opens)
(s : Set Γ(X, U)) :
U.toSpecΓ.base ⁻¹' PrimeSpectrum.zeroLocus s = U.1 ↓∩ X.zeroLocus s := by
rw [toSpecΓ, Scheme.comp_base, TopCat.coe_comp, Set.preimage_comp, Spec.map_base, hom_ofHom]
erw [PrimeSpectrum.preimage_comap_zeroLocus]
rw [Scheme.toSpecΓ_preimage_zeroLocus]
change _ = U.ι.base ⁻¹' (X.zeroLocus s)
rw [Scheme.preimage_zeroLocus, U.ι_app_self, ← zeroLocus_map_of_eq _ U.ι_preimage_self,
← Set.image_comp, ← RingHom.coe_comp, ← CommRingCat.hom_comp]
congr!
simp [← Functor.map_comp]
rfl
end Scheme
lemma IsAffineOpen.fromSpec_preimage_zeroLocus {X : Scheme.{u}} {U : X.Opens}
(hU : IsAffineOpen U) (s : Set Γ(X, U)) :
hU.fromSpec.base ⁻¹' X.zeroLocus s = PrimeSpectrum.zeroLocus s := by
ext x
suffices (∀ f ∈ s, ¬f ∉ x.asIdeal) ↔ s ⊆ x.asIdeal by
simpa [← hU.fromSpec_image_basicOpen, -not_not] using this
simp_rw [not_not]
rfl
lemma IsAffineOpen.fromSpec_image_zeroLocus {X : Scheme.{u}} {U : X.Opens}
(hU : IsAffineOpen U) (s : Set Γ(X, U)) :
hU.fromSpec.base '' PrimeSpectrum.zeroLocus s = X.zeroLocus s ∩ U := by
rw [← hU.fromSpec_preimage_zeroLocus, Set.image_preimage_eq_inter_range, range_fromSpec]
open Set.Notation in
lemma Scheme.zeroLocus_inf (X : Scheme.{u}) {U : X.Opens} (I J : Ideal Γ(X, U)) :
X.zeroLocus (U := U) ↑(I ⊓ J) = X.zeroLocus (U := U) I ∪ X.zeroLocus (U := U) J := by
suffices U.1 ↓∩ (X.zeroLocus (U := U) ↑(I ⊓ J)) =
U.1 ↓∩ (X.zeroLocus (U := U) I ∪ X.zeroLocus (U := U) J) by
ext x
by_cases hxU : x ∈ U
· simpa [hxU] using congr(⟨x, hxU⟩ ∈ $this)
· simp only [Submodule.inf_coe, Set.mem_union,
codisjoint_iff_compl_le_left.mp (X.codisjoint_zeroLocus (U := U) (I ∩ J)) hxU,
codisjoint_iff_compl_le_left.mp (X.codisjoint_zeroLocus (U := U) I) hxU, true_or]
simp only [← U.toSpecΓ_preimage_zeroLocus, PrimeSpectrum.zeroLocus_inf I J,
Set.preimage_union]
lemma Scheme.zeroLocus_biInf
{X : Scheme.{u}} {U : X.Opens} {ι : Type*}
(I : ι → Ideal Γ(X, U)) {t : Set ι} (ht : t.Finite) :
X.zeroLocus (U := U) ↑(⨅ i ∈ t, I i) = (⋃ i ∈ t, X.zeroLocus (U := U) (I i)) ∪ (↑U)ᶜ := by
refine ht.induction_on _ (by simp) fun {i t} hit ht IH ↦ ?_
simp only [Set.mem_insert_iff, Set.iUnion_iUnion_eq_or_left, ← IH, ← zeroLocus_inf,
Submodule.inf_coe, Set.union_assoc]
congr!
simp
lemma Scheme.zeroLocus_biInf_of_nonempty
{X : Scheme.{u}} {U : X.Opens} {ι : Type*}
(I : ι → Ideal Γ(X, U)) {t : Set ι} (ht : t.Finite) (ht' : t.Nonempty) :
X.zeroLocus (U := U) ↑(⨅ i ∈ t, I i) = ⋃ i ∈ t, X.zeroLocus (U := U) (I i) := by
rw [zeroLocus_biInf I ht, Set.union_eq_left]
obtain ⟨i, hi⟩ := ht'
exact fun x hx ↦ Set.mem_iUnion₂_of_mem hi
(codisjoint_iff_compl_le_left.mp (X.codisjoint_zeroLocus (U := U) (I i)) hx)
lemma Scheme.zeroLocus_iInf
{X : Scheme.{u}} {U : X.Opens} {ι : Type*}
(I : ι → Ideal Γ(X, U)) [Finite ι] :
X.zeroLocus (U := U) ↑(⨅ i, I i) = (⋃ i, X.zeroLocus (U := U) (I i)) ∪ (↑U)ᶜ := by
simpa using zeroLocus_biInf I Set.finite_univ
lemma Scheme.zeroLocus_iInf_of_nonempty
{X : Scheme.{u}} {U : X.Opens} {ι : Type*}
(I : ι → Ideal Γ(X, U)) [Finite ι] [Nonempty ι] :
X.zeroLocus (U := U) ↑(⨅ i, I i) = ⋃ i, X.zeroLocus (U := U) (I i) := by
simpa using zeroLocus_biInf_of_nonempty I Set.finite_univ
end ZeroLocus
section Factorization
variable {X : Scheme.{u}} {A : CommRingCat}
/-- Given `f : X ⟶ Spec A` and some ideal `I ≤ ker(A ⟶ Γ(X, ⊤))`,
this is the lift to `X ⟶ Spec (A ⧸ I)`. -/
def Scheme.Hom.liftQuotient (f : X.Hom (Spec A)) (I : Ideal A)
(hI : I ≤ RingHom.ker ((Scheme.ΓSpecIso A).inv ≫ f.appTop).hom) :
X ⟶ Spec(A ⧸ I) :=
X.toSpecΓ ≫ Spec.map (CommRingCat.ofHom
(Ideal.Quotient.lift _ ((Scheme.ΓSpecIso _).inv ≫ f.appTop).hom hI))
@[reassoc]
lemma Scheme.Hom.liftQuotient_comp (f : X.Hom (Spec A)) (I : Ideal A)
(hI : I ≤ RingHom.ker ((Scheme.ΓSpecIso A).inv ≫ f.appTop).hom) :
f.liftQuotient I hI ≫ Spec.map (CommRingCat.ofHom (Ideal.Quotient.mk _)) = f := by
rw [Scheme.Hom.liftQuotient, Category.assoc, ← Spec.map_comp, ← CommRingCat.ofHom_comp,
Ideal.Quotient.lift_comp_mk]
simp only [CommRingCat.hom_comp, CommRingCat.ofHom_comp, CommRingCat.ofHom_hom, Spec.map_comp, ←
Scheme.toSpecΓ_naturality_assoc, ← SpecMap_ΓSpecIso_hom]
simp only [← Spec.map_comp, Iso.inv_hom_id, Spec.map_id, Category.comp_id]
/-- If `X ⟶ Spec A` is a morphism of schemes, then `Spec` of `A ⧸ specTargetImage f`
is the scheme-theoretic image of `f`. For this quotient as an object of `CommRingCat` see
`specTargetImage` below. -/
def specTargetImageIdeal (f : X ⟶ Spec A) : Ideal A :=
(RingHom.ker <| (((ΓSpec.adjunction).homEquiv X (op A)).symm f).unop.hom)
/-- If `X ⟶ Spec A` is a morphism of schemes, then `Spec` of `specTargetImage f` is the
scheme-theoretic image of `f` and `f` factors as
`specTargetImageFactorization f ≫ Spec.map (specTargetImageRingHom f)`
(see `specTargetImageFactorization_comp`). -/
def specTargetImage (f : X ⟶ Spec A) : CommRingCat :=
CommRingCat.of (A ⧸ specTargetImageIdeal f)
/-- If `f : X ⟶ Spec A` is a morphism of schemes, then `f` factors via
the inclusion of `Spec (specTargetImage f)` into `X`. -/
def specTargetImageFactorization (f : X ⟶ Spec A) : X ⟶ Spec (specTargetImage f) :=
f.liftQuotient _ le_rfl
/-- If `f : X ⟶ Spec A` is a morphism of schemes, the induced morphism on spectra of
`specTargetImageRingHom f` is the inclusion of the scheme-theoretic image of `f` into `Spec A`. -/
def specTargetImageRingHom (f : X ⟶ Spec A) : A ⟶ specTargetImage f :=
CommRingCat.ofHom (Ideal.Quotient.mk (specTargetImageIdeal f))
variable (f : X ⟶ Spec A)
lemma specTargetImageRingHom_surjective : Function.Surjective (specTargetImageRingHom f) :=
Ideal.Quotient.mk_surjective
lemma specTargetImageFactorization_app_injective :
Function.Injective <| (specTargetImageFactorization f).appTop := by
let φ : A ⟶ Γ(X, ⊤) := (((ΓSpec.adjunction).homEquiv X (op A)).symm f).unop
let φ' : specTargetImage f ⟶ Scheme.Γ.obj (op X) := CommRingCat.ofHom (RingHom.kerLift φ.hom)
change Function.Injective <| ((ΓSpec.adjunction.homEquiv X _) φ'.op).appTop
rw [ΓSpec_adjunction_homEquiv_eq]
apply (RingHom.kerLift_injective φ.hom).comp
exact ((ConcreteCategory.isIso_iff_bijective (Scheme.ΓSpecIso _).hom).mp inferInstance).injective
@[reassoc (attr := simp)]
lemma specTargetImageFactorization_comp :
specTargetImageFactorization f ≫ Spec.map (specTargetImageRingHom f) = f :=
f.liftQuotient_comp _ _
open RingHom
end Factorization
section Stalks
/-- Variant of `AlgebraicGeometry.localRingHom_comp_stalkIso` for `Spec.map`. -/
@[elementwise]
lemma Scheme.localRingHom_comp_stalkIso {R S : CommRingCat.{u}} (f : R ⟶ S) (p : PrimeSpectrum S) :
(StructureSheaf.stalkIso R (PrimeSpectrum.comap f.hom p)).hom ≫
(CommRingCat.ofHom <| Localization.localRingHom
(PrimeSpectrum.comap f.hom p).asIdeal p.asIdeal f.hom rfl) ≫
(StructureSheaf.stalkIso S p).inv = (Spec.map f).stalkMap p :=
AlgebraicGeometry.localRingHom_comp_stalkIso f p
/-- Given a morphism of rings `f : R ⟶ S`, the stalk map of `Spec S ⟶ Spec R` at
a prime of `S` is isomorphic to the localized ring homomorphism. -/
def Scheme.arrowStalkMapSpecIso {R S : CommRingCat.{u}} (f : R ⟶ S) (p : PrimeSpectrum S) :
Arrow.mk ((Spec.map f).stalkMap p) ≅ Arrow.mk (CommRingCat.ofHom <| Localization.localRingHom
(PrimeSpectrum.comap f.hom p).asIdeal p.asIdeal f.hom rfl) := Arrow.isoMk
(StructureSheaf.stalkIso R (PrimeSpectrum.comap f.hom p))
(StructureSheaf.stalkIso S p) <| by
rw [← Scheme.localRingHom_comp_stalkIso]
simp
end Stalks
end AlgebraicGeometry
|
Filtration.lean
|
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, Rémy Degenne
-/
import Mathlib.MeasureTheory.Constructions.Cylinders
import Mathlib.MeasureTheory.Function.ConditionalExpectation.Real
import Mathlib.MeasureTheory.MeasurableSpace.PreorderRestrict
/-!
# Filtrations
This file defines filtrations of a measurable space and σ-finite filtrations.
## Main definitions
* `MeasureTheory.Filtration`: a filtration on a measurable space. That is, a monotone sequence of
sub-σ-algebras.
* `MeasureTheory.SigmaFiniteFiltration`: a filtration `f` is σ-finite with respect to a measure
`μ` if for all `i`, `μ.trim (f.le i)` is σ-finite.
* `MeasureTheory.Filtration.natural`: the smallest filtration that makes a process adapted. That
notion `adapted` is not defined yet in this file. See `MeasureTheory.adapted`.
## Main results
* `MeasureTheory.Filtration.instCompleteLattice`: filtrations are a complete lattice.
## Tags
filtration, stochastic process
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
/-- A `Filtration` on a measurable space `Ω` with σ-algebra `m` is a monotone
sequence of sub-σ-algebras of `m`. -/
structure Filtration {Ω : Type*} (ι : Type*) [Preorder ι] (m : MeasurableSpace Ω) where
/-- The sequence of sub-σ-algebras of `m` -/
seq : ι → MeasurableSpace Ω
mono' : Monotone seq
le' : ∀ i : ι, seq i ≤ m
attribute [coe] Filtration.seq
variable {Ω β ι : Type*} {m : MeasurableSpace Ω}
instance [Preorder ι] : CoeFun (Filtration ι m) fun _ => ι → MeasurableSpace Ω :=
⟨fun f => f.seq⟩
namespace Filtration
variable [Preorder ι]
protected theorem mono {i j : ι} (f : Filtration ι m) (hij : i ≤ j) : f i ≤ f j :=
f.mono' hij
protected theorem le (f : Filtration ι m) (i : ι) : f i ≤ m :=
f.le' i
@[ext]
protected theorem ext {f g : Filtration ι m} (h : (f : ι → MeasurableSpace Ω) = g) : f = g := by
cases f; cases g; congr
variable (ι) in
/-- The constant filtration which is equal to `m` for all `i : ι`. -/
def const (m' : MeasurableSpace Ω) (hm' : m' ≤ m) : Filtration ι m :=
⟨fun _ => m', monotone_const, fun _ => hm'⟩
@[simp]
theorem const_apply {m' : MeasurableSpace Ω} {hm' : m' ≤ m} (i : ι) : const ι m' hm' i = m' :=
rfl
instance : Inhabited (Filtration ι m) :=
⟨const ι m le_rfl⟩
instance : LE (Filtration ι m) :=
⟨fun f g => ∀ i, f i ≤ g i⟩
instance : Bot (Filtration ι m) :=
⟨const ι ⊥ bot_le⟩
instance : Top (Filtration ι m) :=
⟨const ι m le_rfl⟩
instance : Max (Filtration ι m) :=
⟨fun f g =>
{ seq := fun i => f i ⊔ g i
mono' := fun _ _ hij =>
sup_le ((f.mono hij).trans le_sup_left) ((g.mono hij).trans le_sup_right)
le' := fun i => sup_le (f.le i) (g.le i) }⟩
@[norm_cast]
theorem coeFn_sup {f g : Filtration ι m} : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g :=
rfl
instance : Min (Filtration ι m) :=
⟨fun f g =>
{ seq := fun i => f i ⊓ g i
mono' := fun _ _ hij =>
le_inf (inf_le_left.trans (f.mono hij)) (inf_le_right.trans (g.mono hij))
le' := fun i => inf_le_left.trans (f.le i) }⟩
@[norm_cast]
theorem coeFn_inf {f g : Filtration ι m} : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g :=
rfl
instance : SupSet (Filtration ι m) :=
⟨fun s =>
{ seq := fun i => sSup ((fun f : Filtration ι m => f i) '' s)
mono' := fun i j hij => by
refine sSup_le fun m' hm' => ?_
rw [Set.mem_image] at hm'
obtain ⟨f, hf_mem, hfm'⟩ := hm'
rw [← hfm']
refine (f.mono hij).trans ?_
have hfj_mem : f j ∈ (fun g : Filtration ι m => g j) '' s := ⟨f, hf_mem, rfl⟩
exact le_sSup hfj_mem
le' := fun i => by
refine sSup_le fun m' hm' => ?_
rw [Set.mem_image] at hm'
obtain ⟨f, _, hfm'⟩ := hm'
rw [← hfm']
exact f.le i }⟩
theorem sSup_def (s : Set (Filtration ι m)) (i : ι) :
sSup s i = sSup ((fun f : Filtration ι m => f i) '' s) :=
rfl
open scoped Classical in
noncomputable instance : InfSet (Filtration ι m) :=
⟨fun s =>
{ seq := fun i => if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m
mono' := fun i j hij => by
by_cases h_nonempty : Set.Nonempty s
swap; · simp only [h_nonempty, if_false, le_refl]
simp only [h_nonempty, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
refine fun f hf_mem => le_trans ?_ (f.mono hij)
have hfi_mem : f i ∈ (fun g : Filtration ι m => g i) '' s := ⟨f, hf_mem, rfl⟩
exact sInf_le hfi_mem
le' := fun i => by
by_cases h_nonempty : Set.Nonempty s
swap; · simp only [h_nonempty, if_false, le_refl]
simp only [h_nonempty, if_true]
obtain ⟨f, hf_mem⟩ := h_nonempty
exact le_trans (sInf_le ⟨f, hf_mem, rfl⟩) (f.le i) }⟩
open scoped Classical in
theorem sInf_def (s : Set (Filtration ι m)) (i : ι) :
sInf s i = if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m :=
rfl
noncomputable instance instCompleteLattice : CompleteLattice (Filtration ι m) where
le := (· ≤ ·)
le_refl _ _ := le_rfl
le_trans _ _ _ h_fg h_gh i := (h_fg i).trans (h_gh i)
le_antisymm _ _ h_fg h_gf := Filtration.ext <| funext fun i => (h_fg i).antisymm (h_gf i)
sup := (· ⊔ ·)
le_sup_left _ _ _ := le_sup_left
le_sup_right _ _ _ := le_sup_right
sup_le _ _ _ h_fh h_gh i := sup_le (h_fh i) (h_gh _)
inf := (· ⊓ ·)
inf_le_left _ _ _ := inf_le_left
inf_le_right _ _ _ := inf_le_right
le_inf _ _ _ h_fg h_fh i := le_inf (h_fg i) (h_fh i)
sSup := sSup
le_sSup _ f hf_mem _ := le_sSup ⟨f, hf_mem, rfl⟩
sSup_le s f h_forall i :=
sSup_le fun m' hm' => by
obtain ⟨g, hg_mem, hfm'⟩ := hm'
rw [← hfm']
exact h_forall g hg_mem i
sInf := sInf
sInf_le s f hf_mem i := by
have hs : s.Nonempty := ⟨f, hf_mem⟩
simp only [sInf_def, hs, if_true]
exact sInf_le ⟨f, hf_mem, rfl⟩
le_sInf s f h_forall i := by
by_cases hs : s.Nonempty
swap; · simp only [sInf_def, hs, if_false]; exact f.le i
simp only [sInf_def, hs, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
exact fun g hg_mem => h_forall g hg_mem i
top := ⊤
bot := ⊥
le_top f i := f.le' i
bot_le _ _ := bot_le
end Filtration
theorem measurableSet_of_filtration [Preorder ι] {f : Filtration ι m} {s : Set Ω} {i : ι}
(hs : MeasurableSet[f i] s) : MeasurableSet[m] s :=
f.le i s hs
/-- A measure is σ-finite with respect to filtration if it is σ-finite with respect
to all the sub-σ-algebra of the filtration. -/
class SigmaFiniteFiltration [Preorder ι] (μ : Measure Ω) (f : Filtration ι m) : Prop where
SigmaFinite : ∀ i : ι, SigmaFinite (μ.trim (f.le i))
instance sigmaFinite_of_sigmaFiniteFiltration [Preorder ι] (μ : Measure Ω) (f : Filtration ι m)
[hf : SigmaFiniteFiltration μ f] (i : ι) : SigmaFinite (μ.trim (f.le i)) :=
hf.SigmaFinite _
instance (priority := 100) IsFiniteMeasure.sigmaFiniteFiltration [Preorder ι] (μ : Measure Ω)
(f : Filtration ι m) [IsFiniteMeasure μ] : SigmaFiniteFiltration μ f :=
⟨fun n => by infer_instance⟩
/-- Given an integrable function `g`, the conditional expectations of `g` with respect to a
filtration is uniformly integrable. -/
theorem Integrable.uniformIntegrable_condExp_filtration [Preorder ι] {μ : Measure Ω}
[IsFiniteMeasure μ] {f : Filtration ι m} {g : Ω → ℝ} (hg : Integrable g μ) :
UniformIntegrable (fun i => μ[g|f i]) 1 μ :=
hg.uniformIntegrable_condExp f.le
theorem Filtration.condExp_condExp [Preorder ι] {E : Type*} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E] (f : Ω → E) {μ : Measure Ω} (ℱ : Filtration ι m)
{i j : ι} (hij : i ≤ j) [SigmaFinite (μ.trim (ℱ.le j))] :
μ[μ[f|ℱ j]|ℱ i] =ᵐ[μ] μ[f|ℱ i] := condExp_condExp_of_le (ℱ.mono hij) (ℱ.le j)
section OfSet
variable [Preorder ι]
/-- Given a sequence of measurable sets `(sₙ)`, `filtrationOfSet` is the smallest filtration
such that `sₙ` is measurable with respect to the `n`-th sub-σ-algebra in `filtrationOfSet`. -/
def filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet (s i)) : Filtration ι m where
seq i := MeasurableSpace.generateFrom {t | ∃ j ≤ i, s j = t}
mono' _ _ hnm := MeasurableSpace.generateFrom_mono fun _ ⟨k, hk₁, hk₂⟩ => ⟨k, hk₁.trans hnm, hk₂⟩
le' _ := MeasurableSpace.generateFrom_le fun _ ⟨k, _, hk₂⟩ => hk₂ ▸ hsm k
theorem measurableSet_filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet[m] (s i)) (i : ι)
{j : ι} (hj : j ≤ i) : MeasurableSet[filtrationOfSet hsm i] (s j) :=
MeasurableSpace.measurableSet_generateFrom ⟨j, hj, rfl⟩
theorem measurableSet_filtrationOfSet' {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet[m] (s n))
(i : ι) : MeasurableSet[filtrationOfSet hsm i] (s i) :=
measurableSet_filtrationOfSet hsm i le_rfl
end OfSet
namespace Filtration
variable [TopologicalSpace β] [MetrizableSpace β] [mβ : MeasurableSpace β] [BorelSpace β]
[Preorder ι]
/-- Given a sequence of functions, the natural filtration is the smallest sequence
of σ-algebras such that that sequence of functions is measurable with respect to
the filtration. -/
def natural (u : ι → Ω → β) (hum : ∀ i, StronglyMeasurable (u i)) : Filtration ι m where
seq i := ⨆ j ≤ i, MeasurableSpace.comap (u j) mβ
mono' _ _ hij := biSup_mono fun _ => ge_trans hij
le' i := by
refine iSup₂_le ?_
rintro j _ s ⟨t, ht, rfl⟩
exact (hum j).measurable ht
section
open MeasurableSpace
theorem filtrationOfSet_eq_natural [MulZeroOneClass β] [Nontrivial β] {s : ι → Set Ω}
(hsm : ∀ i, MeasurableSet[m] (s i)) :
filtrationOfSet hsm = natural (fun i => (s i).indicator (fun _ => 1 : Ω → β)) fun i =>
stronglyMeasurable_one.indicator (hsm i) := by
simp only [filtrationOfSet, natural, measurableSpace_iSup_eq, exists_prop, mk.injEq]
ext1 i
refine le_antisymm (generateFrom_le ?_) (generateFrom_le ?_)
· rintro _ ⟨j, hij, rfl⟩
refine measurableSet_generateFrom ⟨j, measurableSet_generateFrom ⟨hij, ?_⟩⟩
rw [comap_eq_generateFrom]
refine measurableSet_generateFrom ⟨{1}, measurableSet_singleton 1, ?_⟩
ext x
simp
· rintro t ⟨n, ht⟩
suffices MeasurableSpace.generateFrom {t | n ≤ i ∧
MeasurableSet[MeasurableSpace.comap ((s n).indicator (fun _ => 1 : Ω → β)) mβ] t} ≤
MeasurableSpace.generateFrom {t | ∃ (j : ι), j ≤ i ∧ s j = t} by
exact this _ ht
refine generateFrom_le ?_
rintro t ⟨hn, u, _, hu'⟩
obtain heq | heq | heq | heq := Set.indicator_const_preimage (s n) u (1 : β)
on_goal 4 => rw [Set.mem_singleton_iff] at heq
all_goals rw [heq] at hu'; rw [← hu']
exacts [MeasurableSet.univ, measurableSet_generateFrom ⟨n, hn, rfl⟩,
MeasurableSet.compl (measurableSet_generateFrom ⟨n, hn, rfl⟩), measurableSet_empty _]
end
section Limit
variable {E : Type*} [Zero E] [TopologicalSpace E] {ℱ : Filtration ι m} {f : ι → Ω → E}
{μ : Measure Ω}
open scoped Classical in
/-- Given a process `f` and a filtration `ℱ`, if `f` converges to some `g` almost everywhere and
`g` is `⨆ n, ℱ n`-measurable, then `limitProcess f ℱ μ` chooses said `g`, else it returns 0.
This definition is used to phrase the a.e. martingale convergence theorem
`Submartingale.ae_tendsto_limitProcess` where an L¹-bounded submartingale `f` adapted to `ℱ`
converges to `limitProcess f ℱ μ` `μ`-almost everywhere. -/
noncomputable def limitProcess (f : ι → Ω → E) (ℱ : Filtration ι m)
(μ : Measure Ω) :=
if h : ∃ g : Ω → E,
StronglyMeasurable[⨆ n, ℱ n] g ∧ ∀ᵐ ω ∂μ, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) then
Classical.choose h else 0
theorem stronglyMeasurable_limitProcess : StronglyMeasurable[⨆ n, ℱ n] (limitProcess f ℱ μ) := by
rw [limitProcess]
split_ifs with h
exacts [(Classical.choose_spec h).1, stronglyMeasurable_zero]
theorem stronglyMeasurable_limit_process' : StronglyMeasurable[m] (limitProcess f ℱ μ) :=
stronglyMeasurable_limitProcess.mono (sSup_le fun _ ⟨_, hn⟩ => hn ▸ ℱ.le _)
theorem memLp_limitProcess_of_eLpNorm_bdd {R : ℝ≥0} {p : ℝ≥0∞} {F : Type*} [NormedAddCommGroup F]
{ℱ : Filtration ℕ m} {f : ℕ → Ω → F} (hfm : ∀ n, AEStronglyMeasurable (f n) μ)
(hbdd : ∀ n, eLpNorm (f n) p μ ≤ R) : MemLp (limitProcess f ℱ μ) p μ := by
rw [limitProcess]
split_ifs with h
· refine ⟨StronglyMeasurable.aestronglyMeasurable
((Classical.choose_spec h).1.mono (sSup_le fun m ⟨n, hn⟩ => hn ▸ ℱ.le _)),
lt_of_le_of_lt (Lp.eLpNorm_lim_le_liminf_eLpNorm hfm _ (Classical.choose_spec h).2)
(lt_of_le_of_lt ?_ (ENNReal.coe_lt_top : ↑R < ∞))⟩
simp_rw [liminf_eq, eventually_atTop]
exact sSup_le fun b ⟨a, ha⟩ => (ha a le_rfl).trans (hbdd _)
· exact MemLp.zero
@[deprecated (since := "2025-02-21")]
alias memℒp_limitProcess_of_eLpNorm_bdd := memLp_limitProcess_of_eLpNorm_bdd
end Limit
section piLE
/-! ### Filtration of the first events -/
open MeasurableSpace Preorder
variable {X : ι → Type*} [∀ i, MeasurableSpace (X i)]
/-- The canonical filtration on the product space `Π i, X i`, where `piLE i`
consists of measurable sets depending only on coordinates `≤ i`. -/
def piLE : @Filtration (Π i, X i) ι _ pi where
seq i := pi.comap (restrictLe i)
mono' i j hij := by
simp only
rw [← restrictLe₂_comp_restrictLe hij, ← comap_comp]
exact comap_mono (measurable_restrictLe₂ _).comap_le
le' i := (measurable_restrictLe i).comap_le
variable [LocallyFiniteOrderBot ι]
lemma piLE_eq_comap_frestrictLe (i : ι) : piLE (X := X) i = pi.comap (frestrictLe i) := by
apply le_antisymm
· simp_rw [piLE, ← piCongrLeft_comp_frestrictLe, ← MeasurableEquiv.coe_piCongrLeft, ← comap_comp]
exact MeasurableSpace.comap_mono <| Measurable.comap_le (by fun_prop)
· rw [← piCongrLeft_comp_restrictLe, ← MeasurableEquiv.coe_piCongrLeft, ← comap_comp]
exact MeasurableSpace.comap_mono <| Measurable.comap_le (by fun_prop)
end piLE
section piFinset
open MeasurableSpace Finset
variable {ι : Type*} {X : ι → Type*} [∀ i, MeasurableSpace (X i)]
/-- The filtration of events which only depends on finitely many coordinates
on the product space `Π i, X i`, `piFinset s` consists of measurable sets depending only on
coordinates in `s`, where `s : Finset ι`. -/
def piFinset : @Filtration (Π i, X i) (Finset ι) _ pi where
seq s := pi.comap s.restrict
mono' s t hst := by
simp only
rw [← restrict₂_comp_restrict hst, ← comap_comp]
exact comap_mono (measurable_restrict₂ hst).comap_le
le' s := s.measurable_restrict.comap_le
lemma piFinset_eq_comap_restrict (s : Finset ι) :
piFinset (X := X) s = pi.comap s.toSet.restrict := by
apply le_antisymm
· simp_rw [piFinset, ← Set.piCongrLeft_comp_restrict, ← MeasurableEquiv.coe_piCongrLeft,
← comap_comp]
exact MeasurableSpace.comap_mono <| (MeasurableEquiv.measurable _).comap_le
· rw [← piCongrLeft_comp_restrict, ← MeasurableEquiv.coe_piCongrLeft, ← comap_comp]
exact MeasurableSpace.comap_mono <| (MeasurableEquiv.measurable _).comap_le
end piFinset
variable {α : Type*}
/-- The exterior σ-algebras of finite sets of `α` form a cofiltration indexed by `Finset α`. -/
def cylinderEventsCompl : Filtration (Finset α)ᵒᵈ (.pi (X := fun _ : α ↦ Ω)) where
seq Λ := cylinderEvents (↑(OrderDual.ofDual Λ))ᶜ
mono' _ _ h := cylinderEvents_mono <| Set.compl_subset_compl_of_subset h
le' _ := cylinderEvents_le_pi
end Filtration
end MeasureTheory
|
List.lean
|
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Data.Finset.Powerset
import Mathlib.Data.Fintype.Defs
import Mathlib.Data.List.Permutation
/-!
# Fintype instance for nodup lists
The subtype of `{l : List α // l.Nodup}` over a `[Fintype α]`
admits a `Fintype` instance.
## Implementation details
To construct the `Fintype` instance, a function lifting a `Multiset α`
to the `Multiset (List α)` is provided.
This function is applied to the `Finset.powerset` of `Finset.univ`.
-/
variable {α : Type*}
open List
namespace Multiset
/-- Given a `m : Multiset α`, we form the `Multiset` of `l : List α` with the property `⟦l⟧ = m`. -/
def lists : Multiset α → Multiset (List α) := fun s =>
Quotient.liftOn s (fun l => l.permutations) fun l l' (h : l ~ l') => by
simp only
refine coe_eq_coe.mpr ?_
exact Perm.permutations h
@[simp]
theorem lists_coe (l : List α) : lists (l : Multiset α) = l.permutations :=
rfl
@[simp]
theorem lists_nodup_finset (l : Finset α) : (lists (l.val)).Nodup := by
have h_nodup : l.val.Nodup := l.nodup
rw [← Finset.coe_toList l, Multiset.coe_nodup] at h_nodup
rw [← Finset.coe_toList l]
exact nodup_permutations l.val.toList (h_nodup)
@[simp]
theorem mem_lists_iff (s : Multiset α) (l : List α) : l ∈ lists s ↔ s = ⟦l⟧ := by
induction s using Quotient.inductionOn
simpa using perm_comm
end Multiset
instance fintypeNodupList [Fintype α] : Fintype { l : List α // l.Nodup } := by
refine Fintype.ofFinset ?_ ?_
· let univSubsets := ((Finset.univ : Finset α).powerset.1 : (Multiset (Finset α)))
let allPerms := Multiset.bind univSubsets (fun s => (Multiset.lists s.1))
refine ⟨allPerms, Multiset.nodup_bind.mpr ?_⟩
simp only [Multiset.lists_nodup_finset, implies_true, true_and]
unfold Multiset.Pairwise
use ((Finset.univ : Finset α).powerset.toList : (List (Finset α)))
constructor
· simp only [Finset.coe_toList]
rfl
· convert Finset.nodup_toList (Finset.univ.powerset : Finset (Finset α))
ext l
unfold Nodup
refine Pairwise.iff ?_
intro m n
simp only [_root_.Disjoint]
rw [← m.coe_toList, ← n.coe_toList, Multiset.lists_coe, Multiset.lists_coe]
have := Multiset.coe_disjoint m.toList.permutations n.toList.permutations
rw [_root_.Disjoint] at this
rw [this]
simp only [ne_eq]
rw [List.disjoint_iff_ne]
constructor
· intro h
by_contra hc
rw [hc] at h
contrapose! h
use n.toList
simp
· intro h
simp only [mem_permutations]
intro a ha b hb
by_contra hab
absurd h
rw [hab] at ha
exact Finset.perm_toList.mp <| Perm.trans ha.symm hb
· intro l
simp only [Finset.mem_mk, Multiset.mem_bind, Finset.mem_val, Finset.mem_powerset,
Finset.subset_univ, Multiset.mem_lists_iff, Multiset.quot_mk_to_coe, true_and]
constructor
· intro h
rcases h with ⟨f, hf⟩
convert f.nodup
rw [hf]
rfl
· intro h
exact CanLift.prf _ h
|
Int.lean
|
/-
Copyright (c) 2018 Louis Carlin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Louis Carlin, Mario Carneiro
-/
import Mathlib.Algebra.Group.Nat.Defs
import Mathlib.Algebra.EuclideanDomain.Defs
import Mathlib.Algebra.Order.Group.Unbundled.Int
import Mathlib.Algebra.Ring.Int.Defs
/-!
# Instances for Euclidean domains
* `Int.euclideanDomain`: shows that `ℤ` is a Euclidean domain.
-/
instance Int.euclideanDomain : EuclideanDomain ℤ :=
{ inferInstanceAs (CommRing Int), inferInstanceAs (Nontrivial Int) with
quotient := (· / ·), quotient_zero := Int.ediv_zero, remainder := (· % ·),
quotient_mul_add_remainder_eq := Int.ediv_add_emod,
r := fun a b => a.natAbs < b.natAbs,
r_wellFounded := (measure natAbs).wf
remainder_lt := fun a b b0 => Int.ofNat_lt.1 <| by
rw [Int.natAbs_of_nonneg (Int.emod_nonneg _ b0), ← Int.abs_eq_natAbs]
exact Int.emod_lt_abs _ b0
mul_left_not_lt := fun a b b0 =>
not_lt_of_ge <| by
rw [← mul_one a.natAbs, Int.natAbs_mul]
rw [← Int.natAbs_pos] at b0
exact Nat.mul_le_mul_left _ b0 }
|
Bounds.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.Field.Basic
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.NumberTheory.DirichletCharacter.Basic
/-!
# Bounds for values of Dirichlet characters
We consider Dirichlet characters `χ` with values in a normed field `F`.
We show that `‖χ a‖ = 1` if `a` is a unit and `‖χ a‖ ≤ 1` in general.
-/
variable {F : Type*} [NormedField F] {n : ℕ} (χ : DirichletCharacter F n)
namespace DirichletCharacter
/-- The value at a unit of a Dirichlet character with target a normed field has norm `1`. -/
@[simp] lemma unit_norm_eq_one (a : (ZMod n)ˣ) : ‖χ a‖ = 1 := by
refine (pow_eq_one_iff_of_nonneg (norm_nonneg _) (Nat.card_pos (α := (ZMod n)ˣ)).ne').mp ?_
rw [← norm_pow, ← map_pow, ← Units.val_pow_eq_pow_val, pow_card_eq_one', Units.val_one, map_one,
norm_one]
/-- The values of a Dirichlet character with target a normed field have norm bounded by `1`. -/
lemma norm_le_one (a : ZMod n) : ‖χ a‖ ≤ 1 := by
by_cases h : IsUnit a
· exact (χ.unit_norm_eq_one h.unit).le
· rw [χ.map_nonunit h, norm_zero]
exact zero_le_one
end DirichletCharacter
|
MersennePrimes.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.NumberTheory.LucasLehmer
/-!
# Explicit Mersenne primes
We run some Lucas-Lehmer tests to prove the first Mersenne primes are prime.
See the discussion at the end of [Mathlib/NumberTheory/LucasLehmer.lean]
for ideas about extending this to larger Mersenne primes.
-/
-- The Lucas-Lehmer test does not apply to `mersenne 2`
example : ¬ LucasLehmerTest 2 := by norm_num
example : (mersenne 2).Prime := by decide
example : (mersenne 3).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 5).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 7).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : ¬ (mersenne 11).Prime := by
intro h
have := lucas_lehmer_necessity 11 (by norm_num) h
norm_num at this
example : (mersenne 13).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 17).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 19).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : ¬ (mersenne 23).Prime := by
intro h
have := lucas_lehmer_necessity 23 (by norm_num) h
norm_num at this
/-- 2147483647.Prime, Euler (1772) -/
example : (mersenne 31).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
/-- Pervushin (1883), Seelhoff (1886) -/
example : (mersenne 61).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 89).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 107).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
/-- Édouard Lucas (1876) -/
example : (mersenne 127).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
/-- Lehmer and Robinson using SWAC computer, (1952) -/
example : (mersenne 521).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 607).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 1279).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 2203).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 2281).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 3217).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 4253).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
example : (mersenne 4423).Prime :=
lucas_lehmer_sufficiency _ (by simp) (by norm_num)
/-
`mersenne 9689` seems to be system dependent:
locally it works fine, but in CI it fails with `(kernel) deep recursion detected`
-/
-- example : (mersenne 9689).Prime :=
-- lucas_lehmer_sufficiency _ (by norm_num) (by norm_num)
/-
`mersenne 9941` seems to be system dependent:
locally it works fine, but in CI it fails with `(kernel) deep recursion detected`
-/
-- example : (mersenne 9941).Prime :=
-- lucas_lehmer_sufficiency _ (by norm_num) (by norm_num)
/-
`mersenne 11213` fails with `(kernel) deep recursion detected` locally as well.
-/
-- example : (mersenne 11213).Prime :=
-- lucas_lehmer_sufficiency _ (by norm_num) (by norm_num)
|
AlternatingConst.lean
|
/-
Copyright (c) 2025 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex
import Mathlib.Algebra.Module.BigOperators
import Mathlib.AlgebraicTopology.ExtraDegeneracy
/-!
# The alternating constant complex
Given an object `X : C` and endomorphisms `φ, ψ : X ⟶ X` such that `φ ∘ ψ = ψ ∘ φ = 0`, this file
defines the periodic chain and cochain complexes
`... ⟶ X --φ--> X --ψ--> X --φ--> X --ψ--> 0` and `0 ⟶ X --ψ--> X --φ--> X --ψ--> X --φ--> ...`
(or more generally for any complex shape `c` on `ℕ` where `c.Rel i j` implies `i` and `j` have
different parity). We calculate the homology of these periodic complexes.
In particular, we show `... ⟶ X --𝟙--> X --0--> X --𝟙--> X --0--> X ⟶ 0` is homotopy equivalent
to the single complex where `X` is in degree `0`.
-/
universe v u
open CategoryTheory Limits
namespace ComplexShape
lemma up_nat_odd_add {i j : ℕ} (h : (ComplexShape.up ℕ).Rel i j) : Odd (i + j) := by
subst h
norm_num
lemma down_nat_odd_add {i j : ℕ} (h : (ComplexShape.down ℕ).Rel i j) : Odd (i + j) := by
subst h
norm_num
end ComplexShape
namespace HomologicalComplex
open ShortComplex
variable {C : Type*} [Category C] [Limits.HasZeroMorphisms C]
(A : C) {φ : A ⟶ A} {ψ : A ⟶ A} (hOdd : φ ≫ ψ = 0) (hEven : ψ ≫ φ = 0)
/-- Let `c : ComplexShape ℕ` be such that `i j : ℕ` have opposite parity if they are related by
`c`. Let `φ, ψ : A ⟶ A` be such that `φ ∘ ψ = ψ ∘ φ = 0`. This is a complex of shape `c` whose
objects are all `A`. For all `i, j` related by `c`, `dᵢⱼ = φ` when `i` is even, and `dᵢⱼ = ψ` when
`i` is odd. -/
@[simps!]
noncomputable def alternatingConst {c : ComplexShape ℕ} [DecidableRel c.Rel]
(hc : ∀ i j, c.Rel i j → Odd (i + j)) :
HomologicalComplex C c where
X n := A
d i j :=
if hij : c.Rel i j then
if hi : Even i then φ
else ψ
else 0
shape i j := by aesop
d_comp_d' i j k hij hjk := by
have := hc i j hij
split_ifs with hi hj hj
· exact False.elim <| Nat.not_odd_iff_even.2 hi <| by simp_all [Nat.odd_add]
· assumption
· assumption
· exact False.elim <| hj <| by simp_all [Nat.odd_add]
variable {c : ComplexShape ℕ} [DecidableRel c.Rel] (hc : ∀ i j, c.Rel i j → Odd (i + j))
open HomologicalComplex hiding mk
/-- The `i, j, k`th short complex associated to the alternating constant complex on `φ, ψ : A ⟶ A`
is `A --ψ--> A --φ--> A` when `i ~ j, j ~ k` and `j` is even. -/
noncomputable def alternatingConstScIsoEven
{i j k : ℕ} (hij : c.Rel i j) (hjk : c.Rel j k) (h : Even j) :
(alternatingConst A hOdd hEven hc).sc' i j k ≅ ShortComplex.mk ψ φ hEven :=
isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _)
(by
simp_all only [alternatingConst, dite_eq_ite, Iso.refl_hom, Category.id_comp,
shortComplexFunctor'_obj_f, ↓reduceIte, Category.comp_id, right_eq_ite_iff]
intro hi
have := hc i j hij
exact False.elim <| Nat.not_odd_iff_even.2 hi <| by simp_all [Nat.odd_add])
(by simp_all [alternatingConst])
/-- The `i, j, k`th short complex associated to the alternating constant complex on `φ, ψ : A ⟶ A`
is `A --φ--> A --ψ--> A` when `i ~ j, j ~ k` and `j` is even. -/
noncomputable def alternatingConstScIsoOdd
{i j k : ℕ} (hij : c.Rel i j) (hjk : c.Rel j k) (h : Odd j) :
(alternatingConst A hOdd hEven hc).sc' i j k ≅ ShortComplex.mk φ ψ hOdd :=
isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _)
(by
simp_all only [alternatingConst, dite_eq_ite, Iso.refl_hom, Category.id_comp,
shortComplexFunctor'_obj_f, ↓reduceIte, Category.comp_id, left_eq_ite_iff]
intro hi
have := hc i j hij
exact False.elim <| Nat.not_even_iff_odd.2 h <| by simp_all [Nat.odd_add])
(by simp_all [alternatingConst])
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma alternatingConst_iCycles_even_comp [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Even j) :
(alternatingConst A hOdd hEven hc).iCycles j ≫ φ = 0 := by
rw [← cancel_epi (ShortComplex.cyclesMapIso
(alternatingConstScIsoEven A hOdd hEven hc hpj hnj h)).inv]
simpa [HomologicalComplex.iCycles, -Preadditive.IsIso.comp_left_eq_zero, HomologicalComplex.sc,
HomologicalComplex.shortComplexFunctor, alternatingConstScIsoEven,
Category.id_comp (X := (alternatingConst A hOdd hEven hc).X _)]
using (ShortComplex.mk ψ φ hEven).iCycles_g
@[reassoc (attr := simp), elementwise (attr := simp)]
lemma alternatingConst_iCycles_odd_comp [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Odd j) :
(alternatingConst A hOdd hEven hc).iCycles j ≫ ψ = 0 := by
rw [← cancel_epi (ShortComplex.cyclesMapIso
(alternatingConstScIsoOdd A hOdd hEven hc hpj hnj h)).inv]
simpa [HomologicalComplex.iCycles, -Preadditive.IsIso.comp_left_eq_zero, HomologicalComplex.sc,
HomologicalComplex.shortComplexFunctor, alternatingConstScIsoOdd,
Category.id_comp (X := (alternatingConst A hOdd hEven hc).X _)]
using (ShortComplex.mk φ ψ hOdd).iCycles_g
/-- The `j`th homology of the alternating constant complex on `φ, ψ : A ⟶ A` is the homology of
`A --ψ--> A --φ--> A` when `prev(j) ~ j, j ~ next(j)` and `j` is even. -/
noncomputable def alternatingConstHomologyIsoEven [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Even j) :
(alternatingConst A hOdd hEven hc).homology j ≅ (ShortComplex.mk ψ φ hEven).homology :=
ShortComplex.homologyMapIso (alternatingConstScIsoEven A hOdd hEven hc hpj hnj h)
/-- The `j`th homology of the alternating constant complex on `φ, ψ : A ⟶ A` is the homology of
`A --φ--> A --ψ--> A` when `prev(j) ~ j, j ~ next(j)` and `j` is odd. -/
noncomputable def alternatingConstHomologyIsoOdd [CategoryWithHomology C]
{j : ℕ} (hpj : c.Rel (c.prev j) j) (hnj : c.Rel j (c.next j)) (h : Odd j) :
(alternatingConst A hOdd hEven hc).homology j ≅ (ShortComplex.mk φ ψ hOdd).homology :=
ShortComplex.homologyMapIso (alternatingConstScIsoOdd A hOdd hEven hc hpj hnj h)
end HomologicalComplex
open CategoryTheory Limits AlgebraicTopology
variable {C : Type*} [Category C]
namespace ChainComplex
/-- The chain complex `X ←0- X ←𝟙- X ←0- X ←𝟙- X ⋯`.
It is exact away from `0` and has homology `X` at `0`. -/
@[simps]
noncomputable def alternatingConst [HasZeroMorphisms C] : C ⥤ ChainComplex C ℕ where
obj X := HomologicalComplex.alternatingConst X (Category.id_comp 0) (Category.comp_id 0)
(fun _ _ => ComplexShape.down_nat_odd_add)
map {X Y} f := {
f _ := f
comm' i j hij := by by_cases Even i <;> simp_all [-Nat.not_even_iff_odd] }
variable [HasZeroMorphisms C] [HasZeroObject C]
open ZeroObject
/-- The `n`-th homology of the alternating constant complex is zero for non-zero even `n`. -/
noncomputable
def alternatingConstHomologyDataEvenNEZero (X : C) (n : ℕ) (hn : Even n) (h₀ : n ≠ 0) :
((alternatingConst.obj X).sc n).HomologyData :=
.ofIsLimitKernelFork _ (by simp [Nat.even_add_one, hn]) _
(Limits.zeroKernelOfCancelZero _ (by cases n <;> simp_all))
/-- The `n`-th homology of the alternating constant complex is zero for odd `n`. -/
noncomputable
def alternatingConstHomologyDataOdd (X : C) (n : ℕ) (hn : Odd n) :
((alternatingConst.obj X).sc n).HomologyData :=
.ofIsColimitCokernelCofork _ (by simp [hn]) _ (Limits.zeroCokernelOfZeroCancel _ (by simp [hn]))
/-- The `n`-th homology of the alternating constant complex is `X` for `n = 0`. -/
noncomputable
def alternatingConstHomologyDataZero (X : C) (n : ℕ) (hn : n = 0) :
((alternatingConst.obj X).sc n).HomologyData :=
.ofZeros _ (by simp [hn]) (by simp [hn])
instance (X : C) (n : ℕ) : (alternatingConst.obj X).HasHomology n := by
rcases n.even_or_odd with h | h
· rcases n with - | n
· exact ⟨⟨alternatingConstHomologyDataZero X _ rfl⟩⟩
· exact ⟨⟨alternatingConstHomologyDataEvenNEZero X _ h (by simp)⟩⟩
· exact ⟨⟨alternatingConstHomologyDataOdd X _ h⟩⟩
/-- The `n`-th homology of the alternating constant complex is `X` for `n ≠ 0`. -/
lemma alternatingConst_exactAt (X : C) (n : ℕ) (hn : n ≠ 0) :
(alternatingConst.obj X).ExactAt n := by
rcases n.even_or_odd with h | h
· exact ⟨(alternatingConstHomologyDataEvenNEZero X _ h hn), isZero_zero C⟩
· exact ⟨(alternatingConstHomologyDataOdd X _ h), isZero_zero C⟩
/-- The `n`-th homology of the alternating constant complex is `X` for `n = 0`. -/
noncomputable
def alternatingConstHomologyZero (X : C) : (alternatingConst.obj X).homology 0 ≅ X :=
(alternatingConstHomologyDataZero X _ rfl).left.homologyIso
end ChainComplex
variable [Preadditive C] [HasZeroObject C]
/-- The alternating face complex of the constant complex is the alternating constant complex. -/
noncomputable def AlgebraicTopology.alternatingFaceMapComplexConst :
Functor.const _ ⋙ alternatingFaceMapComplex C ≅ ChainComplex.alternatingConst :=
NatIso.ofComponents (fun X ↦ HomologicalComplex.Hom.isoOfComponents (fun _ ↦ Iso.refl _) <| by
rintro _ i rfl
simp [SimplicialObject.δ, ← Finset.sum_smul, Fin.sum_neg_one_pow, Nat.even_add_one,
-Nat.not_even_iff_odd]) (by intros; ext; simp)
namespace ChainComplex
/-- `alternatingConst.obj X` is homotopy equivalent to the chain
complex `(single₀ C).obj X`. -/
noncomputable def alternatingConstHomotopyEquiv (X : C) :
HomotopyEquiv (alternatingConst.obj X) ((single₀ C).obj X) :=
(HomotopyEquiv.ofIso (alternatingFaceMapComplexConst.app X).symm).trans
((SimplicialObject.Augmented.ExtraDegeneracy.const X).homotopyEquiv)
end ChainComplex
|
Relator.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Logic.Function.Defs
/-!
# Relator for functions, pairs, sums, and lists.
-/
namespace Relator
universe u₁ u₂ v₁ v₂
/- TODO(johoelzl):
* should we introduce relators of datatypes as recursive function or as inductive
predicate? For now we stick to the recursor approach.
* relation lift for datatypes, Π, Σ, set, and subtype types
* proof composition and identity laws
* implement method to derive relators from datatype
-/
section
variable {α : Sort u₁} {β : Sort u₂} {γ : Sort v₁} {δ : Sort v₂}
variable (R : α → β → Prop) (S : γ → δ → Prop)
/-- The binary relations `R : α → β → Prop` and `S : γ → δ → Prop` induce a binary
relation on functions `LiftFun : (α → γ) → (β → δ) → Prop`. -/
def LiftFun (f : α → γ) (g : β → δ) : Prop :=
∀ ⦃a b⦄, R a b → S (f a) (g b)
/-- `(R ⇒ S) f g` means `LiftFun R S f g`. -/
scoped infixr:40 " ⇒ " => LiftFun
end
section
variable {α : Type u₁} {β : Type u₂} (R : α → β → Prop)
/-- A relation is "right total" if every element appears on the right. -/
def RightTotal : Prop := ∀ b, ∃ a, R a b
/-- A relation is "left total" if every element appears on the left. -/
def LeftTotal : Prop := ∀ a, ∃ b, R a b
/-- A relation is "bi-total" if it is both right total and left total. -/
def BiTotal : Prop := LeftTotal R ∧ RightTotal R
/-- A relation is "left unique" if every element on the right is paired with at
most one element on the left. -/
def LeftUnique : Prop := ∀ ⦃a b c⦄, R a c → R b c → a = b
/-- A relation is "right unique" if every element on the left is paired with at
most one element on the right. -/
def RightUnique : Prop := ∀ ⦃a b c⦄, R a b → R a c → b = c
/-- A relation is "bi-unique" if it is both left unique and right unique. -/
def BiUnique : Prop := LeftUnique R ∧ RightUnique R
variable {R}
lemma RightTotal.rel_forall (h : RightTotal R) :
((R ⇒ (· → ·)) ⇒ (· → ·)) (fun p => ∀ i, p i) (fun q => ∀ i, q i) :=
fun _ _ Hrel H b => Exists.elim (h b) (fun _ Rab => Hrel Rab (H _))
lemma LeftTotal.rel_exists (h : LeftTotal R) :
((R ⇒ (· → ·)) ⇒ (· → ·)) (fun p => ∃ i, p i) (fun q => ∃ i, q i) :=
fun _ _ Hrel ⟨a, pa⟩ => (h a).imp fun _ Rab => Hrel Rab pa
lemma BiTotal.rel_forall (h : BiTotal R) :
((R ⇒ Iff) ⇒ Iff) (fun p => ∀ i, p i) (fun q => ∀ i, q i) :=
fun _ _ Hrel =>
⟨fun H b => Exists.elim (h.right b) (fun _ Rab => (Hrel Rab).mp (H _)),
fun H a => Exists.elim (h.left a) (fun _ Rab => (Hrel Rab).mpr (H _))⟩
lemma BiTotal.rel_exists (h : BiTotal R) :
((R ⇒ Iff) ⇒ Iff) (fun p => ∃ i, p i) (fun q => ∃ i, q i) :=
fun _ _ Hrel =>
⟨fun ⟨a, pa⟩ => (h.left a).imp fun _ Rab => (Hrel Rab).1 pa,
fun ⟨b, qb⟩ => (h.right b).imp fun _ Rab => (Hrel Rab).2 qb⟩
lemma left_unique_of_rel_eq {eq' : β → β → Prop} (he : (R ⇒ (R ⇒ Iff)) Eq eq') : LeftUnique R :=
fun a b c (ac : R a c) (bc : R b c) => (he ac bc).mpr ((he bc bc).mp rfl)
end
lemma rel_imp : (Iff ⇒ (Iff ⇒ Iff)) (· → ·) (· → ·) :=
fun _ _ h _ _ l => imp_congr h l
lemma rel_not : (Iff ⇒ Iff) Not Not :=
fun _ _ h => not_congr h
lemma bi_total_eq {α : Type u₁} : Relator.BiTotal (@Eq α) :=
{ left := fun a => ⟨a, rfl⟩, right := fun a => ⟨a, rfl⟩ }
variable {α : Type*} {β : Type*} {γ : Type*}
variable {r : α → β → Prop}
lemma LeftUnique.flip (h : LeftUnique r) : RightUnique (flip r) :=
fun _ _ _ h₁ h₂ => h h₁ h₂
lemma rel_and : ((· ↔ ·) ⇒ (· ↔ ·) ⇒ (· ↔ ·)) (· ∧ ·) (· ∧ ·) :=
fun _ _ h₁ _ _ h₂ => and_congr h₁ h₂
lemma rel_or : ((· ↔ ·) ⇒ (· ↔ ·) ⇒ (· ↔ ·)) (· ∨ ·) (· ∨ ·) :=
fun _ _ h₁ _ _ h₂ => or_congr h₁ h₂
lemma rel_iff : ((· ↔ ·) ⇒ (· ↔ ·) ⇒ (· ↔ ·)) (· ↔ ·) (· ↔ ·) :=
fun _ _ h₁ _ _ h₂ => iff_congr h₁ h₂
lemma rel_eq {r : α → β → Prop} (hr : BiUnique r) : (r ⇒ r ⇒ (· ↔ ·)) (· = ·) (· = ·) :=
fun _ _ h₁ _ _ h₂ => ⟨fun h => hr.right h₁ <| h.symm ▸ h₂, fun h => hr.left h₁ <| h.symm ▸ h₂⟩
open Function
variable {r₁₁ : α → α → Prop} {r₁₂ : α → β → Prop} {r₂₁ : β → α → Prop}
{r₂₃ : β → γ → Prop} {r₁₃ : α → γ → Prop}
namespace LeftTotal
protected lemma refl (hr : ∀ a : α, r₁₁ a a) :
LeftTotal r₁₁ :=
fun a ↦ ⟨a, hr _⟩
protected lemma symm (hr : ∀ (a : α) (b : β), r₁₂ a b → r₂₁ b a) :
LeftTotal r₁₂ → RightTotal r₂₁ :=
fun h a ↦ (h a).imp (fun _ ↦ hr _ _)
protected lemma trans (hr : ∀ (a : α) (b : β) (c : γ), r₁₂ a b → r₂₃ b c → r₁₃ a c) :
LeftTotal r₁₂ → LeftTotal r₂₃ → LeftTotal r₁₃ :=
fun h₁ h₂ a ↦ let ⟨b, hab⟩ := h₁ a; let ⟨c, hbc⟩ := h₂ b; ⟨c, hr _ _ _ hab hbc⟩
end LeftTotal
namespace RightTotal
protected lemma refl (hr : ∀ a : α, r₁₁ a a) : RightTotal r₁₁ :=
LeftTotal.refl hr
protected lemma symm (hr : ∀ (a : α) (b : β), r₁₂ a b → r₂₁ b a) :
RightTotal r₁₂ → LeftTotal r₂₁ :=
LeftTotal.symm (fun _ _ ↦ hr _ _)
protected lemma trans (hr : ∀ (a : α) (b : β) (c : γ), r₁₂ a b → r₂₃ b c → r₁₃ a c) :
RightTotal r₁₂ → RightTotal r₂₃ → RightTotal r₁₃ :=
swap <| LeftTotal.trans (fun _ _ _ ↦ swap <| hr _ _ _)
end RightTotal
namespace BiTotal
protected lemma refl (hr : ∀ a : α, r₁₁ a a) :
BiTotal r₁₁ :=
⟨LeftTotal.refl hr, RightTotal.refl hr⟩
protected lemma symm (hr : ∀ (a : α) (b : β), r₁₂ a b → r₂₁ b a) :
BiTotal r₁₂ → BiTotal r₂₁ :=
fun h ↦ ⟨h.2.symm hr, h.1.symm hr⟩
protected lemma trans (hr : ∀ (a : α) (b : β) (c : γ), r₁₂ a b → r₂₃ b c → r₁₃ a c) :
BiTotal r₁₂ → BiTotal r₂₃ → BiTotal r₁₃ :=
fun h₁ h₂ ↦ ⟨h₁.1.trans hr h₂.1, h₁.2.trans hr h₂.2⟩
end BiTotal
end Relator
|
GroupCompletion.lean
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Topology.UniformSpace.Completion
import Mathlib.Topology.Algebra.Group.Pointwise
/-!
# Completion of topological groups:
This files endows the completion of a topological abelian group with a group structure.
More precisely the instance `UniformSpace.Completion.addGroup` builds an abelian group structure
on the completion of an abelian group endowed with a compatible uniform structure.
Then the instance `UniformSpace.Completion.isUniformAddGroup` proves this group structure is
compatible with the completed uniform structure. The compatibility condition is `IsUniformAddGroup`.
## Main declarations:
Beyond the instances explained above (that don't have to be explicitly invoked),
the main constructions deal with continuous group morphisms.
* `AddMonoidHom.extension`: extends a continuous group morphism from `G`
to a complete separated group `H` to `Completion G`.
* `AddMonoidHom.completion`: promotes a continuous group morphism
from `G` to `H` into a continuous group morphism
from `Completion G` to `Completion H`.
-/
noncomputable section
variable {M R α β : Type*}
section Group
open UniformSpace CauchyFilter Filter Set
variable [UniformSpace α]
instance [Zero α] : Zero (Completion α) :=
⟨(0 : α)⟩
instance [Neg α] : Neg (Completion α) :=
⟨Completion.map (fun a ↦ -a : α → α)⟩
instance [Add α] : Add (Completion α) :=
⟨Completion.map₂ (· + ·)⟩
instance [Sub α] : Sub (Completion α) :=
⟨Completion.map₂ Sub.sub⟩
@[norm_cast]
theorem UniformSpace.Completion.coe_zero [Zero α] : ((0 : α) : Completion α) = 0 :=
rfl
@[simp] lemma UniformSpace.Completion.coe_eq_zero_iff [Zero α] [T0Space α] {x : α} :
(x : Completion α) = 0 ↔ x = 0 :=
Completion.coe_inj
end Group
namespace UniformSpace.Completion
open UniformSpace
section Zero
instance [UniformSpace α] [MonoidWithZero M] [Zero α] [MulActionWithZero M α]
[UniformContinuousConstSMul M α] : MulActionWithZero M (Completion α) :=
{ (inferInstance : MulAction M <| Completion α) with
smul_zero := fun r ↦ by rw [← coe_zero, ← coe_smul, MulActionWithZero.smul_zero r]
zero_smul :=
ext' (continuous_const_smul _) continuous_const fun a ↦ by
rw [← coe_smul, zero_smul, coe_zero] }
end Zero
section IsUniformAddGroup
variable [UniformSpace α] [AddGroup α] [IsUniformAddGroup α]
@[norm_cast]
theorem coe_neg (a : α) : ((-a : α) : Completion α) = -a :=
(map_coe uniformContinuous_neg a).symm
@[norm_cast]
theorem coe_sub (a b : α) : ((a - b : α) : Completion α) = a - b :=
(map₂_coe_coe a b Sub.sub uniformContinuous_sub).symm
@[norm_cast]
theorem coe_add (a b : α) : ((a + b : α) : Completion α) = a + b :=
(map₂_coe_coe a b (· + ·) uniformContinuous_add).symm
instance : AddMonoid (Completion α) :=
{ (inferInstance : Zero <| Completion α),
(inferInstance : Add <| Completion α) with
zero_add := fun a ↦
Completion.induction_on a
(isClosed_eq (continuous_map₂ continuous_const continuous_id) continuous_id) fun a ↦
show 0 + (a : Completion α) = a by rw [← coe_zero, ← coe_add, zero_add]
add_zero := fun a ↦
Completion.induction_on a
(isClosed_eq (continuous_map₂ continuous_id continuous_const) continuous_id) fun a ↦
show (a : Completion α) + 0 = a by rw [← coe_zero, ← coe_add, add_zero]
add_assoc := fun a b c ↦
Completion.induction_on₃ a b c
(isClosed_eq
(continuous_map₂ (continuous_map₂ continuous_fst (continuous_fst.comp continuous_snd))
(continuous_snd.comp continuous_snd))
(continuous_map₂ continuous_fst
(continuous_map₂ (continuous_fst.comp continuous_snd)
(continuous_snd.comp continuous_snd))))
fun a b c ↦
show (a : Completion α) + b + c = a + (b + c) by repeat' rw_mod_cast [add_assoc]
nsmul := (· • ·)
nsmul_zero := fun a ↦
Completion.induction_on a (isClosed_eq continuous_map continuous_const) fun a ↦
show 0 • (a : Completion α) = 0 by rw [← coe_smul, ← coe_zero, zero_smul]
nsmul_succ := fun n a ↦
Completion.induction_on a
(isClosed_eq continuous_map <| continuous_map₂ continuous_map continuous_id) fun a ↦
show (n + 1) • (a : Completion α) = n • (a : Completion α) + (a : Completion α) by
rw [← coe_smul, succ_nsmul, coe_add, coe_smul] }
instance : SubNegMonoid (Completion α) :=
{ (inferInstance : AddMonoid <| Completion α),
(inferInstance : Neg <| Completion α),
(inferInstance : Sub <| Completion α) with
sub_eq_add_neg := fun a b ↦
Completion.induction_on₂ a b
(isClosed_eq (continuous_map₂ continuous_fst continuous_snd)
(continuous_map₂ continuous_fst (Completion.continuous_map.comp continuous_snd)))
fun a b ↦ mod_cast congr_arg ((↑) : α → Completion α) (sub_eq_add_neg a b)
zsmul := (· • ·)
zsmul_zero' := fun a ↦
Completion.induction_on a (isClosed_eq continuous_map continuous_const) fun a ↦
show (0 : ℤ) • (a : Completion α) = 0 by rw [← coe_smul, ← coe_zero, zero_smul]
zsmul_succ' := fun n a ↦
Completion.induction_on a
(isClosed_eq continuous_map <| continuous_map₂ continuous_map continuous_id) fun a ↦
show (n.succ : ℤ) • (a : Completion α) = _ by
rw [← coe_smul, show (n.succ : ℤ) • a = (n : ℤ) • a + a from
SubNegMonoid.zsmul_succ' n a, coe_add, coe_smul]
zsmul_neg' := fun n a ↦
Completion.induction_on a
(isClosed_eq continuous_map <| Completion.continuous_map.comp continuous_map) fun a ↦
show (Int.negSucc n) • (a : Completion α) = _ by
rw [← coe_smul, show (Int.negSucc n) • a = -((n.succ : ℤ) • a) from
SubNegMonoid.zsmul_neg' n a, coe_neg, coe_smul] }
instance addGroup : AddGroup (Completion α) :=
{ (inferInstance : SubNegMonoid <| Completion α) with
neg_add_cancel := fun a ↦
Completion.induction_on a
(isClosed_eq (continuous_map₂ Completion.continuous_map continuous_id) continuous_const)
fun a ↦
show -(a : Completion α) + a = 0 by
rw_mod_cast [neg_add_cancel]
rfl }
instance isUniformAddGroup : IsUniformAddGroup (Completion α) :=
⟨uniformContinuous_map₂ Sub.sub⟩
instance {M} [Monoid M] [DistribMulAction M α] [UniformContinuousConstSMul M α] :
DistribMulAction M (Completion α) :=
{ (inferInstance : MulAction M <| Completion α) with
smul_add := fun r x y ↦
induction_on₂ x y
(isClosed_eq ((continuous_fst.add continuous_snd).const_smul _)
((continuous_fst.const_smul _).add (continuous_snd.const_smul _)))
fun a b ↦ by simp only [← coe_add, ← coe_smul, smul_add]
smul_zero := fun r ↦ by rw [← coe_zero, ← coe_smul, smul_zero r] }
/-- The map from a group to its completion as a group hom. -/
@[simps]
def toCompl : α →+ Completion α where
toFun := (↑)
map_add' := coe_add
map_zero' := coe_zero
theorem continuous_toCompl : Continuous (toCompl : α → Completion α) :=
continuous_coe α
variable (α) in
theorem isDenseInducing_toCompl : IsDenseInducing (toCompl : α → Completion α) :=
isDenseInducing_coe
end IsUniformAddGroup
section UniformAddCommGroup
variable [UniformSpace α] [AddCommGroup α] [IsUniformAddGroup α]
instance instAddCommGroup : AddCommGroup (Completion α) :=
{ (inferInstance : AddGroup <| Completion α) with
add_comm := fun a b ↦
Completion.induction_on₂ a b
(isClosed_eq (continuous_map₂ continuous_fst continuous_snd)
(continuous_map₂ continuous_snd continuous_fst))
fun x y ↦ by
change (x : Completion α) + ↑y = ↑y + ↑x
rw [← coe_add, ← coe_add, add_comm] }
instance instModule [Semiring R] [Module R α] [UniformContinuousConstSMul R α] :
Module R (Completion α) :=
{ (inferInstance : DistribMulAction R <| Completion α),
(inferInstance : MulActionWithZero R <| Completion α) with
add_smul := fun a b ↦
ext' (continuous_const_smul _) ((continuous_const_smul _).add (continuous_const_smul _))
fun x ↦ by
rw [← coe_smul, add_smul, coe_add, coe_smul, coe_smul] }
end UniformAddCommGroup
end UniformSpace.Completion
section AddMonoidHom
variable [UniformSpace α] [AddGroup α] [IsUniformAddGroup α] [UniformSpace β] [AddGroup β]
[IsUniformAddGroup β]
open UniformSpace UniformSpace.Completion
/-- Extension to the completion of a continuous group hom. -/
def AddMonoidHom.extension [CompleteSpace β] [T0Space β] (f : α →+ β) (hf : Continuous f) :
Completion α →+ β :=
have hf : UniformContinuous f := uniformContinuous_addMonoidHom_of_continuous hf
{ toFun := Completion.extension f
map_zero' := by rw [← coe_zero, extension_coe hf, f.map_zero]
map_add' := fun a b ↦
Completion.induction_on₂ a b
(isClosed_eq (continuous_extension.comp continuous_add)
((continuous_extension.comp continuous_fst).add
(continuous_extension.comp continuous_snd)))
fun a b ↦
show Completion.extension f _ = Completion.extension f _ + Completion.extension f _ by
rw_mod_cast [extension_coe hf, extension_coe hf, extension_coe hf, f.map_add] }
theorem AddMonoidHom.extension_coe [CompleteSpace β] [T0Space β] (f : α →+ β)
(hf : Continuous f) (a : α) : f.extension hf a = f a :=
UniformSpace.Completion.extension_coe (uniformContinuous_addMonoidHom_of_continuous hf) a
@[continuity]
theorem AddMonoidHom.continuous_extension [CompleteSpace β] [T0Space β] (f : α →+ β)
(hf : Continuous f) : Continuous (f.extension hf) :=
UniformSpace.Completion.continuous_extension
/-- Completion of a continuous group hom, as a group hom. -/
def AddMonoidHom.completion (f : α →+ β) (hf : Continuous f) : Completion α →+ Completion β :=
(toCompl.comp f).extension (continuous_toCompl.comp hf)
@[continuity]
theorem AddMonoidHom.continuous_completion (f : α →+ β) (hf : Continuous f) :
Continuous (AddMonoidHom.completion f hf : Completion α → Completion β) :=
continuous_map
theorem AddMonoidHom.completion_coe (f : α →+ β) (hf : Continuous f) (a : α) :
AddMonoidHom.completion f hf a = f a :=
map_coe (uniformContinuous_addMonoidHom_of_continuous hf) a
theorem AddMonoidHom.completion_zero :
AddMonoidHom.completion (0 : α →+ β) continuous_const = 0 := by
ext x
refine Completion.induction_on x ?_ ?_
· apply isClosed_eq (AddMonoidHom.continuous_completion (0 : α →+ β) continuous_const)
exact continuous_const
· intro a
simp [(0 : α →+ β).completion_coe continuous_const, coe_zero]
theorem AddMonoidHom.completion_add {γ : Type*} [AddCommGroup γ] [UniformSpace γ]
[IsUniformAddGroup γ] (f g : α →+ γ) (hf : Continuous f) (hg : Continuous g) :
AddMonoidHom.completion (f + g) (hf.add hg) =
AddMonoidHom.completion f hf + AddMonoidHom.completion g hg := by
have hfg := hf.add hg
ext x
refine Completion.induction_on x ?_ ?_
· exact isClosed_eq ((f + g).continuous_completion hfg)
((f.continuous_completion hf).add (g.continuous_completion hg))
· intro a
simp [(f + g).completion_coe hfg, coe_add, f.completion_coe hf, g.completion_coe hg]
end AddMonoidHom
|
Slice.lean
|
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Category.Basic
import Mathlib.Tactic.Conv
/-!
# The `slice` tactic
Applies a tactic to an interval of terms from a term obtained by repeated application
of `Category.comp`.
-/
open CategoryTheory
open Lean Parser.Tactic Elab Command Elab.Tactic Meta
-- TODO someone might like to generalise this tactic to work with other associative structures.
/- Porting note: moved `repeat_with_results` to `repeat_count` to `Mathlib/Tactic/Core.lean` -/
open Parser.Tactic.Conv
/--
`slice` is a conv tactic; if the current focus is a composition of several morphisms,
`slice a b` reassociates as needed, and zooms in on the `a`-th through `b`-th morphisms.
Thus if the current focus is `(a ≫ b) ≫ ((c ≫ d) ≫ e)`, then `slice 2 3` zooms to `b ≫ c`.
-/
syntax (name := slice) "slice " num ppSpace num : conv
/--
`evalSlice`
- rewrites the target expression using `Category.assoc`.
- uses `congr` to split off the first `a-1` terms and rotates to `a`-th (last) term
- counts the number `k` of rewrites as it uses `←Category.assoc` to bring the target to
left associated form; from the first step this is the total number of remaining terms from `C`
- it now splits off `b-a` terms from target using `congr` leaving the desired subterm
- finally, it rewrites it once more using `Category.assoc` to bring it to right-associated
normal form
-/
def evalSlice (a b : Nat) : TacticM Unit := do
let _ ← iterateUntilFailureWithResults do
evalTactic (← `(conv| rw [Category.assoc]))
iterateRange (a - 1) (a - 1) do
evalTactic (← `(conv| congr))
evalTactic (← `(tactic| rotate_left))
let k ← iterateUntilFailureCount
<| evalTactic (← `(conv| rw [← Category.assoc]))
let c := k+1+a-b
iterateRange c c <| evalTactic (← `(conv| congr))
let _ ← iterateUntilFailureWithResults do
evalTactic (← `(conv| rw [Category.assoc]))
/-- `slice` is implemented by `evalSlice`. -/
elab "slice " a:num ppSpace b:num : conv => evalSlice a.getNat b.getNat
/--
`slice_lhs a b => tac` zooms to the left hand side, uses associativity for categorical
composition as needed, zooms in on the `a`-th through `b`-th morphisms, and invokes `tac`.
-/
syntax (name := sliceLHS) "slice_lhs " num ppSpace num " => " convSeq : tactic
macro_rules
| `(tactic| slice_lhs $a $b => $seq) =>
`(tactic| conv => lhs; slice $a $b; ($seq:convSeq))
/--
`slice_rhs a b => tac` zooms to the right hand side, uses associativity for categorical
composition as needed, zooms in on the `a`-th through `b`-th morphisms, and invokes `tac`.
-/
syntax (name := sliceRHS) "slice_rhs " num ppSpace num " => " convSeq : tactic
macro_rules
| `(tactic| slice_rhs $a $b => $seq) =>
`(tactic| conv => rhs; slice $a $b; ($seq:convSeq))
/- Porting note: update when `add_tactic_doc` is supported` -/
-- add_tactic_doc
-- { Name := "slice"
-- category := DocCategory.tactic
-- declNames := [`tactic.interactive.sliceLHS, `tactic.interactive.sliceRHS]
-- tags := ["category theory"] }
--
|
factors.lean
|
import Mathlib.Tactic.Simproc.Factors
example : Nat.primeFactorsList 0 = [] := by simp only [Nat.primeFactorsList_ofNat]
example : Nat.primeFactorsList 1 = [] := by simp only [Nat.primeFactorsList_ofNat]
example : Nat.primeFactorsList 2 = [2] := by simp only [Nat.primeFactorsList_ofNat]
example : Nat.primeFactorsList 3 = [3] := by simp only [Nat.primeFactorsList_ofNat]
example : Nat.primeFactorsList 4 = [2, 2] := by simp only [Nat.primeFactorsList_ofNat]
example : Nat.primeFactorsList 12 = [2, 2, 3] := by simp only [Nat.primeFactorsList_ofNat]
example : Nat.primeFactorsList 221 = [13, 17] := by simp only [Nat.primeFactorsList_ofNat]
|
Proper.lean
|
/-
Copyright (c) 2024 Yaël Dillies, Kalle Kytölä, Kin Yau James Wong. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Kalle Kytölä, Kin Yau James Wong
-/
import Mathlib.Probability.Kernel.Composition.CompNotation
/-!
# Proper kernels
This file defines properness of measure kernels.
For two σ-algebras `𝓑 ≤ 𝓧`, a `𝓑, 𝓧`-kernel `π : X → Measure X` is proper if
`∫ x, g x * f x ∂(π x₀) = g x₀ * ∫ x, f x ∂(π x₀)` for all `x₀ : X`, `𝓧`-measurable function `f`
and `𝓑`-measurable function `g`.
By the standard machine, this is equivalent to having that, for all `B ∈ 𝓑`, `π` restricted to `B`
is the same as `π` times the indicator of `B`.
This should be thought of as the condition under which one can meaningfully restrict a kernel to an
event.
## TODO
Prove the `integral` versions of the `lintegral` lemmas below
-/
open MeasureTheory ENNReal NNReal Set
open scoped ProbabilityTheory
namespace ProbabilityTheory.Kernel
variable {X : Type*} {𝓑 𝓧 : MeasurableSpace X} {π : Kernel[𝓑, 𝓧] X X} {A B : Set X}
{f g : X → ℝ≥0∞} {x₀ : X}
/-- For two σ-algebras `𝓑 ≤ 𝓧` on a space `X`, a `𝓑, 𝓧`-kernel `π : X → Measure X` is proper if
`∫ x, g x * f x ∂(π x₀) = g x₀ * ∫ x, f x ∂(π x₀)` for all `x₀ : X`, `𝓧`-measurable function `f`
and `𝓑`-measurable function `g`.
By the standard machine, this is equivalent to having that, for all `B ∈ 𝓑`, `π` restricted to `B`
is the same as `π` times the indicator of `B`.
To avoid assuming `𝓑 ≤ 𝓧` in the definition, we replace `𝓑` by `𝓑 ⊓ 𝓧` in the restriction. -/
structure IsProper (π : Kernel[𝓑, 𝓧] X X) : Prop where
restrict_eq_indicator_smul' :
∀ ⦃B : Set X⦄ (hB : MeasurableSet[𝓑 ⊓ 𝓧] B) (x : X),
π.restrict (inf_le_right (b := 𝓧) _ hB) x = B.indicator (fun _ ↦ (1 : ℝ≥0∞)) x • π x
lemma isProper_iff_restrict_eq_indicator_smul (h𝓑𝓧 : 𝓑 ≤ 𝓧) :
IsProper π ↔ ∀ ⦃B : Set X⦄ (hB : MeasurableSet[𝓑] B) (x : X),
π.restrict (h𝓑𝓧 _ hB) x = B.indicator (fun _ ↦ (1 : ℝ≥0∞)) x • π x := by
refine ⟨fun ⟨h⟩ ↦ ?_, fun h ↦ ⟨?_⟩⟩ <;> simpa only [inf_eq_left.2 h𝓑𝓧] using h
lemma isProper_iff_inter_eq_indicator_mul (h𝓑𝓧 : 𝓑 ≤ 𝓧) :
IsProper π ↔
∀ ⦃A : Set X⦄ (_hA : MeasurableSet[𝓧] A) ⦃B : Set X⦄ (_hB : MeasurableSet[𝓑] B) (x : X),
π x (A ∩ B) = B.indicator 1 x * π x A := by
calc
_ ↔ ∀ ⦃A : Set X⦄ (_hA : MeasurableSet[𝓧] A) ⦃B : Set X⦄ (hB : MeasurableSet[𝓑] B) (x : X),
π.restrict (h𝓑𝓧 _ hB) x A = B.indicator 1 x * π x A := by
simp [isProper_iff_restrict_eq_indicator_smul h𝓑𝓧, Measure.ext_iff]; aesop
_ ↔ _ := by congr! 5 with A hA B hB x; rw [restrict_apply, Measure.restrict_apply hA]
alias ⟨IsProper.restrict_eq_indicator_smul, IsProper.of_restrict_eq_indicator_smul⟩ :=
isProper_iff_restrict_eq_indicator_smul
alias ⟨IsProper.inter_eq_indicator_mul, IsProper.of_inter_eq_indicator_mul⟩ :=
isProper_iff_inter_eq_indicator_mul
lemma IsProper.setLIntegral_eq_comp (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧) {μ : Measure[𝓧] X}
(hA : MeasurableSet[𝓧] A) (hB : MeasurableSet[𝓑] B) :
∫⁻ a in B, π a A ∂μ = (π ∘ₘ μ) (A ∩ B) := by
rw [Measure.bind_apply (by measurability) (π.measurable.mono h𝓑𝓧 le_rfl).aemeasurable]
simp only [hπ.inter_eq_indicator_mul h𝓑𝓧 hA hB, ← indicator_mul_const, Pi.one_apply, one_mul]
rw [← lintegral_indicator (h𝓑𝓧 _ hB)]
rfl
/-- Auxiliary lemma for `IsProper.lintegral_mul` and
`IsProper.setLIntegral_eq_indicator_mul_lintegral`. -/
private lemma IsProper.lintegral_indicator_mul_indicator (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hA : MeasurableSet[𝓧] A) (hB : MeasurableSet[𝓑] B) :
∫⁻ x, B.indicator 1 x * A.indicator 1 x ∂(π x₀) =
B.indicator 1 x₀ * ∫⁻ x, A.indicator 1 x ∂(π x₀) := by
simp_rw [← inter_indicator_mul]
rw [lintegral_indicator ((h𝓑𝓧 _ hB).inter hA), lintegral_indicator hA]
simp only [MeasureTheory.lintegral_const, MeasurableSet.univ, Measure.restrict_apply, univ_inter,
Pi.one_apply, one_mul]
rw [← hπ.inter_eq_indicator_mul h𝓑𝓧 hA hB, inter_comm]
set_option linter.style.multiGoal false in -- false positive
/-- Auxiliary lemma for `IsProper.lintegral_mul` and
`IsProper.setLIntegral_eq_indicator_mul_lintegral`. -/
private lemma IsProper.lintegral_indicator_mul (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hf : Measurable[𝓧] f) (hB : MeasurableSet[𝓑] B) :
∫⁻ x, B.indicator 1 x * f x ∂(π x₀) = B.indicator 1 x₀ * ∫⁻ x, f x ∂(π x₀) := by
refine hf.ennreal_induction ?_ ?_ ?_
· rintro c A hA
simp_rw [← smul_indicator_one_apply, mul_smul_comm, smul_eq_mul]
rw [lintegral_const_mul, lintegral_const_mul, hπ.lintegral_indicator_mul_indicator h𝓑𝓧 hA hB,
mul_left_comm] <;> measurability
· rintro f₁ f₂ - _ _ hf₁ hf₂
simp only [Pi.add_apply, mul_add]
rw [lintegral_add_right, lintegral_add_right, hf₁, hf₂, mul_add] <;> measurability
· rintro f' hf'_meas hf'_mono hf'
simp_rw [ENNReal.mul_iSup]
rw [lintegral_iSup (by measurability), lintegral_iSup hf'_meas hf'_mono, ENNReal.mul_iSup]
simp_rw [hf']
· exact hf'_mono.const_mul (zero_le _)
lemma IsProper.setLIntegral_eq_indicator_mul_lintegral (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hf : Measurable[𝓧] f) (hB : MeasurableSet[𝓑] B) (x₀ : X) :
∫⁻ x in B, f x ∂(π x₀) = B.indicator 1 x₀ * ∫⁻ x, f x ∂(π x₀) := by
simp [← hπ.lintegral_indicator_mul h𝓑𝓧 hf hB, ← indicator_mul_left,
lintegral_indicator (h𝓑𝓧 _ hB)]
lemma IsProper.setLIntegral_inter_eq_indicator_mul_setLIntegral (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧)
(hf : Measurable[𝓧] f) (hA : MeasurableSet[𝓧] A) (hB : MeasurableSet[𝓑] B) (x₀ : X) :
∫⁻ x in A ∩ B, f x ∂(π x₀) = B.indicator 1 x₀ * ∫⁻ x in A, f x ∂(π x₀) := by
rw [← lintegral_indicator hA, ← hπ.setLIntegral_eq_indicator_mul_lintegral h𝓑𝓧 _ hB,
setLIntegral_indicator] <;> measurability
lemma IsProper.lintegral_mul (hπ : IsProper π) (h𝓑𝓧 : 𝓑 ≤ 𝓧) (hf : Measurable[𝓧] f)
(hg : Measurable[𝓑] g) (x₀ : X) :
∫⁻ x, g x * f x ∂(π x₀) = g x₀ * ∫⁻ x, f x ∂(π x₀) := by
refine hg.ennreal_induction ?_ ?_ ?_
· rintro c A hA
simp_rw [← smul_indicator_one_apply, smul_mul_assoc, smul_eq_mul]
rw [lintegral_const_mul, hπ.lintegral_indicator_mul h𝓑𝓧 hf hA]
· measurability
· rintro g₁ g₂ - _ hg₂_meas hg₁ hg₂
simp only [Pi.add_apply, add_mul]
rw [lintegral_add_right, hg₁, hg₂]
· exact (hg₂_meas.mono h𝓑𝓧 le_rfl).mul hf
· rintro g' hg'_meas hg'_mono hg'
simp_rw [ENNReal.iSup_mul]
rw [lintegral_iSup (fun n ↦ ((hg'_meas _).mono h𝓑𝓧 le_rfl).mul hf)
(hg'_mono.mul_const (zero_le _))]
simp_rw [hg']
end ProbabilityTheory.Kernel
|
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.
|
ssrint.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 fintype finfun bigop order ssralg countalg ssrnum.
From mathcomp Require Import poly.
(******************************************************************************)
(* This file develops a basic theory of signed integers, defining: *)
(* int == the type of signed integers, with two constructors Posz for *)
(* non-negative integers and Negz for negative integers. It *)
(* supports the realDomainType interface (and its parents). *)
(* n%:Z == explicit cast from nat to int (:= Posz n); displayed as n. *)
(* However (Posz m = Posz n) is displayed as (m = n :> int) *)
(* (and so are ==, != and <>) *)
(* Lemma NegzE : turns (Negz n) into - n.+1%:Z. *)
(* <number> == <number> as an int, with <number> an optional minus sign *)
(* followed by a sequence of digits. This notation is in *)
(* int_scope (delimited with %Z). *)
(* x *~ m == m times x, with m : int; *)
(* convertible to x *+ n if m is Posz n *)
(* convertible to x *- n.+1 if m is Negz n. *)
(* m%:~R == the image of m : int in a generic ring (:= 1 *~ m). *)
(* x ^ m == x to the m, with m : int; *)
(* convertible to x ^+ n if m is Posz n *)
(* convertible to x ^- n.+1 if m is Negz n. *)
(* sgz x == sign of x : R, *)
(* equals (0 : int) if and only x == 0, *)
(* equals (1 : int) if x is positive *)
(* and (-1 : int) otherwise. *)
(* `|m|%N == the n : nat such that `|m|%R = n%:Z, for m : int. *)
(* `|m - n|%N == the distance between m and n; the '-' is specialized to *)
(* the int type, so m and n can be either of type nat or int *)
(* thanks to the Posz coercion; m and n are however parsed in *)
(* the %N scope. The IntDist submodule provides this notation *)
(* and the corresponding theory independently of the rest of *)
(* of the int and ssralg libraries (and notations). *)
(* Warning: due to the declaration of Posz as a coercion, two terms might be *)
(* displayed the same while not being convertible, for instance: *)
(* (Posz (x - y)) and (Posz x) - (Posz y) for x, y : nat. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope int_scope.
Declare Scope distn_scope.
Declare Scope rat_scope.
Reserved Notation "*~%R" (format " *~%R").
Reserved Notation "x *~ n" (at level 40, left associativity, format "x *~ n").
Reserved Notation "n %:~R" (left associativity, format "n %:~R").
Reserved Notation "n %:Z" (left associativity, format "n %:Z").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "n = m :> 'int'" (format "n = m :> 'int'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "n == m :> 'int'" (format "n == m :> 'int'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "n != m :> 'int'" (format "n != m :> 'int'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "n <> m :> 'int'" (format "n <> m :> 'int'").
Import Order.TTheory GRing.Theory Num.Theory.
Delimit Scope int_scope with Z.
Local Open Scope int_scope.
(* Defining int *)
Variant int : Set := Posz of nat | Negz of nat.
(* This must be deferred to module DistInt to work around the design flaws of *)
(* the Coq module system. *)
(* Coercion Posz : nat >-> int. *)
Notation "n %:Z" := (Posz n) (only parsing) : int_scope.
Notation "n %:Z" := (Posz n) (only parsing) : ring_scope.
Notation "n = m :> 'int'" := (@eq int n%Z m%Z) (only parsing) : ring_scope.
Notation "n = m :> 'int'" := (Posz n = Posz m) (only printing) : ring_scope.
Notation "n == m :> 'int'" := ((n%Z : int) == (m%Z : int)) (only parsing)
: ring_scope.
Notation "n == m :> 'int'" := (Posz n == Posz m) (only printing) : ring_scope.
Notation "n != m :> 'int'" := ((n%Z : int) != (m%Z : int)) (only parsing)
: ring_scope.
Notation "n != m :> 'int'" := (Posz n != Posz m) (only printing) : ring_scope.
Notation "n <> m :> 'int'" := (not (@eq int n%Z m%Z)) (only parsing)
: ring_scope.
Notation "n <> m :> 'int'" := (Posz n <> Posz m) (only printing) : ring_scope.
Definition parse_int (x : Number.int) : int :=
match x with
| Number.IntDecimal (Decimal.Pos u) => Posz (Nat.of_uint u)
| Number.IntDecimal (Decimal.Neg u) => Negz (Nat.of_uint u).-1
| Number.IntHexadecimal (Hexadecimal.Pos u) => Posz (Nat.of_hex_uint u)
| Number.IntHexadecimal (Hexadecimal.Neg u) => Negz (Nat.of_hex_uint u).-1
end.
Definition print_int (x : int) : Number.int :=
match x with
| Posz n => Number.IntDecimal (Decimal.Pos (Nat.to_uint n))
| Negz n => Number.IntDecimal (Decimal.Neg (Nat.to_uint n.+1))
end.
Number Notation int parse_int print_int : int_scope.
Definition natsum_of_int (m : int) : nat + nat :=
match m with Posz p => inl _ p | Negz n => inr _ n end.
Definition int_of_natsum (m : nat + nat) :=
match m with inl p => Posz p | inr n => Negz n end.
Lemma natsum_of_intK : cancel natsum_of_int int_of_natsum.
Proof. by case. Qed.
HB.instance Definition _ := Countable.copy int (can_type natsum_of_intK).
Lemma eqz_nat (m n : nat) : (m%:Z == n%:Z) = (m == n). Proof. by []. Qed.
Module intZmod.
Section intZmod.
Definition addz (m n : int) :=
match m, n with
| Posz m', Posz n' => Posz (m' + n')
| Negz m', Negz n' => Negz (m' + n').+1
| Posz m', Negz n' => if n' < m' then Posz (m' - n'.+1) else Negz (n' - m')
| Negz n', Posz m' => if n' < m' then Posz (m' - n'.+1) else Negz (n' - m')
end.
Definition oppz m :=
match m with
| Posz n => if n is (n'.+1)%N then Negz n' else Posz 0
| Negz n => Posz (n.+1)%N
end.
Arguments oppz : simpl never.
Local Notation "-%Z" := (@oppz) : int_scope.
Local Notation "- x" := (oppz x) : int_scope.
Local Notation "+%Z" := (@addz) : int_scope.
Local Notation "x + y" := (addz x y) : int_scope.
Local Notation "x - y" := (x + - y) : int_scope.
Lemma PoszD : {morph Posz : m n / (m + n)%N >-> m + n}. Proof. by []. Qed.
Local Coercion Posz : nat >-> int.
Lemma NegzE (n : nat) : Negz n = - n.+1. Proof. by []. Qed.
Lemma int_rect (P : int -> Type) :
P 0 -> (forall n : nat, P n -> P (n.+1))
-> (forall n : nat, P (- n) -> P (- (n.+1)))
-> forall n : int, P n.
Proof.
by move=> P0 hPp hPn []; elim=> [|n ihn]//; do ?[apply: hPn | apply: hPp].
Qed.
Definition int_rec := int_rect.
Definition int_ind := int_rect.
Variant int_spec (x : int) : int -> Type :=
| ZintNull of x = 0 : int_spec x 0
| ZintPos n of x = n.+1 : int_spec x n.+1
| ZintNeg n of x = - (n.+1)%:Z : int_spec x (- n.+1).
Lemma intP x : int_spec x x. Proof. by move: x=> [] []; constructor. Qed.
Lemma addzC : commutative addz.
Proof. by move=> [] m [] n //=; rewrite addnC. Qed.
Lemma add0z : left_id 0 addz. Proof. by do 2?case. Qed.
Lemma oppzK : involutive oppz. Proof. by do 2?case. Qed.
Lemma oppzD : {morph oppz : m n / m + n}.
Proof.
by move=> [[|n]|n] [[|m]|m] /=; rewrite ?addn0 ?subn0 ?addnS //;
rewrite !NegzE !ltnS !subSS; case: ltngtP => [?|?|->];
rewrite ?subnn // ?oppzK ?subnS ?prednK // subn_gt0.
Qed.
Lemma add1Pz (n : int) : 1 + (n - 1) = n.
Proof. by case: (intP n)=> // n' /= _; rewrite ?(subn1, addn0). Qed.
Lemma subSz1 (n : int) : 1 + n - 1 = n.
Proof.
by apply: (inv_inj oppzK); rewrite addzC !oppzD oppzK [_ - n]addzC add1Pz.
Qed.
Lemma addSnz (m : nat) (n : int) : m.+1%N + n = 1 + (m + n).
Proof.
move: m n=> [|m] [] [|n] //=; rewrite ?add1n ?subn1 // !(ltnS, subSS).
case: ltngtP=> hnm /=; rewrite ?hnm ?subnn //.
by rewrite subnS add1n prednK ?subn_gt0.
by rewrite ltnS leqn0 subn_eq0 leqNgt hnm /= subnS subn1.
Qed.
Lemma addSz (m n : int) : (1 + m) + n = 1 + (m + n).
Proof.
case: m => [] m; first by rewrite -PoszD add1n addSnz.
rewrite !NegzE; apply: (inv_inj oppzK).
rewrite !oppzD !oppzK addSnz [-1%:Z + _]addzC addSnz add1Pz.
by rewrite [-1%:Z + _]addzC subSz1.
Qed.
Lemma addPz (m n : int) : (m - 1) + n = (m + n) - 1.
Proof.
by apply: (inv_inj oppzK); rewrite !oppzD oppzK [_ + 1]addzC addSz addzC.
Qed.
Lemma addzA : associative addz.
Proof.
elim=> [|m ihm|m ihm] n p; first by rewrite !add0z.
by rewrite -add1n PoszD !addSz ihm.
by rewrite -add1n addnC PoszD oppzD !addPz ihm.
Qed.
Lemma addNz : left_inverse (0:int) oppz addz. Proof. by do 3?elim. Qed.
Lemma predn_int (n : nat) : 0 < n -> n.-1%:Z = n - 1.
Proof. by case: n => //= n _; rewrite subn1. Qed.
Definition Mixin := GRing.isZmodule.Build int addzA addzC add0z addNz.
End intZmod.
Arguments oppz : simpl never.
End intZmod.
HB.instance Definition _ := intZmod.Mixin.
HB.instance Definition _ := GRing.isNmodMorphism.Build nat int Posz
(erefl, intZmod.PoszD).
Local Open Scope ring_scope.
Section intZmoduleTheory.
Local Coercion Posz : nat >-> int.
Lemma PoszD : {morph Posz : n m / (n + m)%N >-> n + m}. Proof. by []. Qed.
Lemma NegzE (n : nat) : Negz n = -(n.+1)%:Z. Proof. by []. Qed.
Lemma int_rect (P : int -> Type) :
P 0 -> (forall n : nat, P n -> P (n.+1)%N)
-> (forall n : nat, P (- (n%:Z)) -> P (- (n.+1%N%:Z)))
-> forall n : int, P n.
Proof.
by move=> P0 hPp hPn []; elim=> [|n ihn]//; do ?[apply: hPn | apply: hPp].
Qed.
Definition int_rec := int_rect.
Definition int_ind := int_rect.
Variant int_spec (x : int) : int -> Type :=
| ZintNull : int_spec x 0
| ZintPos n : int_spec x n.+1
| ZintNeg n : int_spec x (- (n.+1)%:Z).
Lemma intP x : int_spec x x.
Proof. by move: x=> [] [] *; rewrite ?NegzE; constructor. Qed.
Definition oppzD := @opprD int.
Lemma subzn (m n : nat) : (n <= m)%N -> m%:Z - n%:Z = (m - n)%N.
Proof.
elim: n=> //= [|n ihn] hmn; first by rewrite subr0 subn0.
rewrite subnS -addn1 !PoszD opprD addrA ihn 1?ltnW //.
by rewrite intZmod.predn_int // subn_gt0.
Qed.
Lemma subzSS (m n : nat) : m.+1%:Z - n.+1%:Z = m%:Z - n%:Z.
Proof. by elim: n m=> [|n ihn] m //; rewrite !subzn. Qed.
End intZmoduleTheory.
Module intRing.
Section intRing.
Local Coercion Posz : nat >-> int.
Definition mulz (m n : int) :=
match m, n with
| Posz m', Posz n' => (m' * n')%N%:Z
| Negz m', Negz n' => (m'.+1%N * n'.+1%N)%N%:Z
| Posz m', Negz n' => - (m' * (n'.+1%N))%N%:Z
| Negz n', Posz m' => - (m' * (n'.+1%N))%N%:Z
end.
Local Notation "*%Z" := (@mulz) : int_scope.
Local Notation "x * y" := (mulz x y) : int_scope.
Lemma mul0z : left_zero 0 *%Z.
Proof. by case=> [n|[|n]] //=; rewrite muln0. Qed.
Lemma mulzC : commutative mulz.
Proof. by move=> [] m [] n //=; rewrite mulnC. Qed.
Lemma mulz0 : right_zero 0 *%Z.
Proof. by move=> x; rewrite mulzC mul0z. Qed.
Lemma mulzN (m n : int) : (m * (- n))%Z = - (m * n)%Z.
Proof.
by case: (intP m)=> {m} [|m|m]; rewrite ?mul0z //;
case: (intP n)=> {n} [|n|n]; rewrite ?mulz0 //= mulnC.
Qed.
Lemma mulNz (m n : int) : ((- m) * n)%Z = - (m * n)%Z.
Proof. by rewrite mulzC mulzN mulzC. Qed.
Lemma mulzA : associative mulz.
Proof.
by move=> [] m [] n [] p; rewrite ?NegzE ?(mulnA,mulNz,mulzN,opprK) //= ?mulnA.
Qed.
Lemma mul1z : left_id 1%Z mulz.
Proof. by case=> [[|n]|n] //=; rewrite ?mul1n// plusE addn0. Qed.
Lemma mulzS (x : int) (n : nat) : (x * n.+1%:Z)%Z = x + (x * n)%Z.
Proof.
by case: (intP x)=> [|m'|m'] //=; [rewrite mulnS|rewrite mulSn -opprD].
Qed.
Lemma mulz_addl : left_distributive mulz (+%R).
Proof.
move=> x y z; elim: z=> [|n|n]; first by rewrite !(mul0z,mulzC).
by rewrite !mulzS=> ->; rewrite !addrA [X in X + _]addrAC.
rewrite !mulzN !mulzS -!opprD=> /oppr_inj->.
by rewrite !addrA [X in X + _]addrAC.
Qed.
Lemma nonzero1z : 1%Z != 0. Proof. by []. Qed.
Definition comMixin := GRing.Zmodule_isComNzRing.Build int
mulzA mulzC mul1z mulz_addl nonzero1z.
End intRing.
End intRing.
HB.instance Definition _ := intRing.comMixin.
Section intRingTheory.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
Lemma PoszM : {morph Posz : n m / (n * m)%N >-> n * m}. Proof. by []. Qed.
Lemma intS (n : nat) : n.+1%:Z = 1 + n%:Z. Proof. by rewrite -PoszD. Qed.
Lemma predn_int (n : nat) : (0 < n)%N -> n.-1%:Z = n%:Z - 1.
Proof. exact: intZmod.predn_int. Qed.
End intRingTheory.
HB.instance Definition _ := GRing.isMonoidMorphism.Build nat int Posz
(erefl, PoszM).
Module intUnitRing.
Section intUnitRing.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
Definition unitz := [qualify a n : int | (n == 1) || (n == -1)].
Definition invz n : int := n.
Lemma mulVz : {in unitz, left_inverse 1%R invz *%R}.
Proof. by move=> n /pred2P[] ->. Qed.
Lemma mulzn_eq1 m (n : nat) : (m * n == 1) = (m == 1) && (n == 1).
Proof. by case: m => m /=; [rewrite -PoszM [_==_]muln_eq1 | case: n]. Qed.
Lemma unitzPl m n : n * m = 1 -> m \is a unitz.
Proof.
rewrite qualifE => /eqP.
by case: m => m; rewrite ?NegzE ?mulrN -?mulNr mulzn_eq1 => /andP[_ /eqP->].
Qed.
Lemma invz_out : {in [predC unitz], invz =1 id}.
Proof. exact. Qed.
Lemma idomain_axiomz m n : m * n = 0 -> (m == 0) || (n == 0).
Proof. by case: m n => [[|m]|m] [[|n]|n]. Qed.
Definition comMixin := GRing.ComNzRing_hasMulInverse.Build int
mulVz unitzPl invz_out.
End intUnitRing.
End intUnitRing.
HB.instance Definition _ := intUnitRing.comMixin.
HB.instance Definition _ := GRing.ComUnitRing_isIntegral.Build int
intUnitRing.idomain_axiomz.
Definition absz m := match m with Posz p => p | Negz n => n.+1 end.
Notation "m - n" := (@GRing.add int m%N (@GRing.opp int n%N)) : distn_scope.
Arguments absz m%_distn_scope.
Local Notation "`| m |" := (absz m) : nat_scope.
Module intOrdered.
Section intOrdered.
Implicit Types m n p : int.
Local Coercion Posz : nat >-> int.
Local Notation normz m := (absz m)%:Z.
Definition lez m n :=
match m, n with
| Posz m', Posz n' => (m' <= n')%N
| Posz m', Negz n' => false
| Negz m', Posz n' => true
| Negz m', Negz n' => (n' <= m')%N
end.
Definition ltz m n :=
match m, n with
| Posz m', Posz n' => (m' < n')%N
| Posz m', Negz n' => false
| Negz m', Posz n' => true
| Negz m', Negz n' => (n' < m')%N
end.
Fact lez_add m n : lez 0 m -> lez 0 n -> lez 0 (m + n).
Proof. by case: m n => [] m [] n. Qed.
Fact lez_mul m n : lez 0 m -> lez 0 n -> lez 0 (m * n).
Proof. by case: m n => [] m [] n. Qed.
Fact lez_anti m : lez 0 m -> lez m 0 -> m = 0.
Proof. by case: m; first case. Qed.
Lemma subz_ge0 m n : lez 0 (n - m) = lez m n.
Proof.
case: (intP m); case: (intP n)=> // {}m {}n /=;
rewrite ?ltnS -?opprD ?opprB ?subzSS; case: leqP=> // hmn;
by [ rewrite subzn //
| rewrite -opprB subzn ?(ltnW hmn) //;
move: hmn; rewrite -subn_gt0; case: (_ - _)%N].
Qed.
Fact lez_total m n : lez m n || lez n m.
Proof. by move: m n => [] m [] n //=; apply: leq_total. Qed.
Fact normzN m : normz (- m) = normz m.
Proof. by case: m => // -[]. Qed.
Fact gez0_norm m : lez 0 m -> normz m = m.
Proof. by case: m. Qed.
Fact ltz_def m n : (ltz m n) = (n != m) && (lez m n).
Proof.
by move: m n => [] m [] n //=; rewrite (ltn_neqAle, leq_eqVlt) // eq_sym.
Qed.
Definition Mixin := Num.IntegralDomain_isLeReal.Build int
lez_add lez_mul lez_anti subz_ge0 (lez_total 0) normzN gez0_norm ltz_def.
End intOrdered.
End intOrdered.
HB.instance Definition _ := intOrdered.Mixin.
Section intOrderedTheory.
Local Coercion Posz : nat >-> int.
Implicit Types m n p : nat.
Implicit Types x y z : int.
Lemma lez_nat m n : (m <= n :> int) = (m <= n)%N. Proof. by []. Qed.
Lemma ltz_nat m n : (m < n :> int) = (m < n)%N.
Proof. by rewrite ltnNge ltNge lez_nat. Qed.
Definition ltez_nat := (lez_nat, ltz_nat).
Lemma leNz_nat m n : (- m%:Z <= n). Proof. by case: m. Qed.
Lemma ltNz_nat m n : (- m%:Z < n) = (m != 0) || (n != 0).
Proof. by move: m n=> [|?] []. Qed.
Definition lteNz_nat := (leNz_nat, ltNz_nat).
Lemma lezN_nat m n : (m%:Z <= - n%:Z) = (m == 0) && (n == 0).
Proof. by move: m n=> [|?] []. Qed.
Lemma ltzN_nat m n : (m%:Z < - n%:Z) = false.
Proof. by move: m n=> [|?] []. Qed.
Lemma le0z_nat n : 0 <= n :> int. Proof. by []. Qed.
Lemma lez0_nat n : n <= 0 :> int = (n == 0 :> nat). Proof. by elim: n. Qed.
Definition ltezN_nat := (lezN_nat, ltzN_nat).
Definition ltez_natE := (ltez_nat, lteNz_nat, ltezN_nat, le0z_nat, lez0_nat).
Lemma gtz0_ge1 x : (0 < x) = (1 <= x). Proof. by case: (intP x). Qed.
Lemma lez1D x y : (1 + x <= y) = (x < y).
Proof. by rewrite -subr_gt0 gtz0_ge1 lterBDr. Qed.
Lemma lezD1 x y : (x + 1 <= y) = (x < y).
Proof. by rewrite addrC lez1D. Qed.
Lemma ltz1D x y : (x < 1 + y) = (x <= y).
Proof. by rewrite -lez1D lerD2l. Qed.
Lemma ltzD1 x y : (x < y + 1) = (x <= y).
Proof. by rewrite -lezD1 lerD2r. Qed.
End intOrderedTheory.
Bind Scope ring_scope with int.
(* definition of intmul *)
Definition intmul (R : zmodType) (x : R) (n : int) :=
match n with
| Posz n => (x *+ n)%R
| Negz n => (x *- (n.+1))%R
end.
Arguments intmul : simpl never.
Notation "*~%R" := (@intmul _) : function_scope.
Notation "x *~ n" := (intmul x n) : ring_scope.
Notation intr := ( *~%R 1).
Notation "n %:~R" := (1 *~ n)%R : ring_scope.
Lemma pmulrn (R : zmodType) (x : R) (n : nat) : x *+ n = x *~ n%:Z.
Proof. by []. Qed.
Lemma nmulrn (R : zmodType) (x : R) (n : nat) : x *- n = x *~ - n%:Z.
Proof. by case: n; rewrite // oppr0. Qed.
Section ZintLmod.
Definition zmodule (M : Type) : Type := M.
Local Notation "M ^z" := (zmodule M) (format "M ^z") : type_scope.
Local Coercion Posz : nat >-> int.
Variable M : zmodType.
Implicit Types m n : int.
Implicit Types x y z : M.
Fact mulrzA_C m n x : (x *~ n) *~ m = x *~ (m * n).
Proof.
elim: m=> [|m _|m _]; elim: n=> [|n _|n _]; rewrite /intmul //=;
rewrite ?(muln0, mulr0n, mul0rn, oppr0, mulNrn, opprK) //;
do ?by rewrite mulnC mulrnA.
* by rewrite -mulrnA mulnC.
* by rewrite -mulrnA.
Qed.
Fact mulrzAC m n x : (x *~ n) *~ m = (x *~ m) *~ n.
Proof. by rewrite !mulrzA_C mulrC. Qed.
Fact mulr1z (x : M) : x *~ 1 = x. Proof. by []. Qed.
Fact mulrzDl m : {morph ( *~%R^~ m : M -> M) : x y / x + y}.
Proof. by case: m => m x y; rewrite /intmul mulrnDl // opprD. Qed.
Lemma mulrzBl_nat (m n : nat) x : x *~ (m%:Z - n%:Z) = x *~ m - x *~ n.
Proof.
wlog/subnK <-: m n / (n <= m)%N; last by rewrite -!pmulrn PoszD mulrnDr !addrK.
have [hmn|/ltnW hmn] := leqP n m; first exact.
by rewrite -[in LHS]opprB -[RHS]opprB subzn // -nmulrn pmulrn -subzn // => ->.
Qed.
Fact mulrzDr x : {morph *~%R x : m n / m + n}.
Proof.
by case=> []m []n; rewrite ?NegzE /intmul /= -/(intmul _ _) -?opprD;
rewrite -?[- _ + _]addrC ?mulrzBl_nat // -mulrnDr // addnS.
Qed.
HB.instance Definition _ := GRing.Zmodule.on M^z. (* FIXME, the error message below "nomsg" when we forget this line is not very helpful *)
HB.instance Definition _ := @GRing.Zmodule_isLmodule.Build _ M^z
(fun n x => x *~ n) mulrzA_C mulr1z mulrzDl mulrzDr.
Lemma scalezrE n x : n *: (x : M^z) = x *~ n. Proof. by []. Qed.
Lemma mulrzA x m n : x *~ (m * n) = x *~ m *~ n.
Proof. by rewrite -!scalezrE scalerA mulrC. Qed.
Lemma mulr0z x : x *~ 0 = 0. Proof. by []. Qed.
Lemma mul0rz n : 0 *~ n = 0 :> M.
Proof. by rewrite -scalezrE scaler0. Qed.
Lemma mulrNz x n : x *~ (- n) = - (x *~ n).
Proof. by rewrite -scalezrE scaleNr. Qed.
Lemma mulrN1z x : x *~ (- 1) = - x. Proof. by rewrite -scalezrE scaleN1r. Qed.
Lemma mulNrz x n : (- x) *~ n = - (x *~ n).
Proof. by rewrite -scalezrE scalerN. Qed.
Lemma mulrzBr x m n : x *~ (m - n) = x *~ m - x *~ n.
Proof. by rewrite -scalezrE scalerBl. Qed.
Lemma mulrzBl x y n : (x - y) *~ n = x *~ n - y *~ n.
Proof. by rewrite -scalezrE scalerBr. Qed.
Lemma mulrz_nat (n : nat) x : x *~ n%:R = x *+ n.
Proof. by rewrite -scalezrE scaler_nat. Qed.
Lemma mulrz_sumr : forall x I r (P : pred I) F,
x *~ (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) x *~ F i.
Proof. by rewrite -/M^z; apply: scaler_suml. Qed.
Lemma mulrz_suml : forall n I r (P : pred I) (F : I -> M),
(\sum_(i <- r | P i) F i) *~ n= \sum_(i <- r | P i) F i *~ n.
Proof. by rewrite -/M^z; apply: scaler_sumr. Qed.
HB.instance Definition _ (x : M) := GRing.isZmodMorphism.Build int M ( *~%R x)
(@mulrzBr x).
End ZintLmod.
#[deprecated(since="mathcomp 2.3.0", note="Use mulrzDl instead.")]
Notation mulrzDl_tmp := mulrzDl.
#[deprecated(since="mathcomp 2.3.0", note="Use mulrzDr instead.")]
Notation mulrzDr_tmp := mulrzDr.
Lemma ffunMzE (I : finType) (M : zmodType) (f : {ffun I -> M}) z x :
(f *~ z) x = f x *~ z.
Proof. by case: z => n; rewrite ?ffunE ffunMnE. Qed.
Lemma intz (n : int) : n%:~R = n.
Proof. by case: n => n; rewrite ?NegzE /intmul/= -(rmorphMn Posz)/= natn. Qed.
Lemma natz (n : nat) : n%:R = n%:Z :> int.
Proof. by rewrite pmulrn intz. Qed.
Section RintMod.
Local Coercion Posz : nat >-> int.
Variable R : pzRingType.
Implicit Types m n : int.
Implicit Types x y z : R.
Lemma mulrzAl n x y : (x *~ n) * y = (x * y) *~ n.
Proof. by case: n => n; rewrite ?mulNr mulrnAl. Qed.
Lemma mulrzAr n x y : x * (y *~ n) = (x * y) *~ n.
Proof. by case: n => n; rewrite ?mulrN mulrnAr. Qed.
Lemma mulrzl x n : n%:~R * x = x *~ n. Proof. by rewrite mulrzAl mul1r. Qed.
Lemma mulrzr x n : x * n%:~R = x *~ n. Proof. by rewrite mulrzAr mulr1. Qed.
Lemma mulNrNz n x : (- x) *~ (- n) = x *~ n.
Proof. by rewrite mulNrz mulrNz opprK. Qed.
Lemma mulrbz x (b : bool) : x *~ b = (if b then x else 0).
Proof. by case: b. Qed.
Lemma intrN n : (- n)%:~R = - n%:~R :> R. Proof. exact: mulrNz. Qed.
Lemma intrD m n : (m + n)%:~R = m%:~R + n%:~R :> R. Proof. exact: mulrzDr. Qed.
Lemma intrB m n : (m - n)%:~R = m%:~R - n%:~R :> R. Proof. exact: mulrzBr. Qed.
Lemma intrM m n : (m * n)%:~R = m%:~R * n%:~R :> R.
Proof. by rewrite mulrzA -mulrzr. Qed.
Lemma intmul1_is_monoid_morphism : monoid_morphism ( *~%R (1 : R)).
Proof. by split; move=> // x y /=; rewrite ?intrD ?mulrNz ?intrM. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `intmul1_is_monoid_morphism` instead")]
Definition intmul1_is_multiplicative :=
(fun g => (g.2,g.1)) intmul1_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build int R ( *~%R 1)
intmul1_is_monoid_morphism.
Lemma mulr2z n : n *~ 2 = n + n. Proof. exact: mulr2n. Qed.
End RintMod.
Lemma mulrzz m n : m *~ n = m * n. Proof. by rewrite -mulrzr intz. Qed.
Lemma mulz2 n : n * 2%:Z = n + n. Proof. by rewrite -mulrzz. Qed.
Lemma mul2z n : 2%:Z * n = n + n. Proof. by rewrite mulrC -mulrzz. Qed.
Section LMod.
Variable R : pzRingType.
Variable V : (lmodType R).
Local Coercion Posz : nat >-> int.
Implicit Types m n : int.
Implicit Types x y z : R.
Implicit Types u v w : V.
Lemma scaler_int n v : n%:~R *: v = v *~ n.
Proof. by case: n => n; rewrite /intmul ?scaleNr scaler_nat. Qed.
Lemma scalerMzl a v n : (a *: v) *~ n = (a *~ n) *: v.
Proof. by rewrite -mulrzl -scaler_int scalerA. Qed.
Lemma scalerMzr a v n : (a *: v) *~ n = a *: (v *~ n).
Proof. by rewrite -!scaler_int !scalerA mulrzr mulrzl. Qed.
End LMod.
Lemma mulrz_int (M : zmodType) (n : int) (x : M) : x *~ n%:~R = x *~ n.
Proof. by rewrite -scalezrE scaler_int. Qed.
Section MorphTheory.
Local Coercion Posz : nat >-> int.
Section Additive.
Variables (U V : zmodType) (f : {additive U -> V}).
Lemma raddfMz n : {morph f : x / x *~ n}.
Proof. by case: n=> n x; rewrite 1?raddfN raddfMn. Qed.
End Additive.
Section Multiplicative.
Variables (R S : pzRingType) (f : {rmorphism R -> S}).
Lemma rmorphMz : forall n, {morph f : x / x *~ n}. Proof. exact: raddfMz. Qed.
Lemma rmorph_int : forall n, f n%:~R = n%:~R.
Proof. by move=> n; rewrite rmorphMz rmorph1. Qed.
End Multiplicative.
Section Linear.
Variable R : pzRingType.
Variables (U V : lmodType R) (f : {linear U -> V}).
Lemma linearMn : forall n, {morph f : x / x *~ n}. Proof. exact: raddfMz. Qed.
End Linear.
Lemma raddf_int_scalable (aV rV : lmodType int) (f : {additive aV -> rV}) :
scalable f.
Proof. by move=> z u; rewrite -[z]intz !scaler_int raddfMz. Qed.
Section Zintmul1rMorph.
Variable R : pzRingType.
Lemma commrMz (x y : R) n : GRing.comm x y -> GRing.comm x (y *~ n).
Proof. by rewrite /GRing.comm=> com_xy; rewrite mulrzAr mulrzAl com_xy. Qed.
Lemma commr_int (x : R) n : GRing.comm x n%:~R.
Proof. exact/commrMz/commr1. Qed.
End Zintmul1rMorph.
Section ZintBigMorphism.
Variable R : pzRingType.
Lemma sumMz : forall I r (P : pred I) F,
(\sum_(i <- r | P i) F i)%N%:~R = \sum_(i <- r | P i) ((F i)%:~R) :> R.
Proof. exact: rmorph_sum. Qed.
Lemma prodMz : forall I r (P : pred I) F,
(\prod_(i <- r | P i) F i)%N%:~R = \prod_(i <- r | P i) ((F i)%:~R) :> R.
Proof. exact: rmorph_prod. Qed.
End ZintBigMorphism.
Section Frobenius.
Variable R : nzRingType.
Implicit Types x y : R.
Variable p : nat.
Hypothesis pcharFp : p \in [pchar R].
Local Notation "x ^f" := (pFrobenius_aut pcharFp x).
Lemma pFrobenius_autMz x n : (x *~ n)^f = x^f *~ n.
Proof.
case: n=> n /=; first exact: pFrobenius_autMn.
by rewrite !NegzE !mulrNz pFrobenius_autN pFrobenius_autMn.
Qed.
Lemma pFrobenius_aut_int n : (n%:~R)^f = n%:~R.
Proof. by rewrite pFrobenius_autMz pFrobenius_aut1. Qed.
End Frobenius.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMz instead.")]
Notation Frobenius_autMz := (pFrobenius_autMz) (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_int instead.")]
Notation Frobenius_aut_int := (pFrobenius_aut_int) (only parsing).
Section NumMorphism.
Section PO.
Variables (R : numDomainType).
Implicit Types n m : int.
Implicit Types x y : R.
Lemma rmorphzP (f : {rmorphism int -> R}) : f =1 ( *~%R 1).
Proof. by move=> n; rewrite -[n in LHS]intz rmorph_int. Qed.
(* intmul and ler/ltr *)
Lemma ler_pMz2r n (hn : 0 < n) : {mono *~%R^~ n :x y / x <= y :> R}.
Proof. by move=> x y; case: n hn=> [[]|] // n _; rewrite ler_pMn2r. Qed.
Lemma ltr_pMz2r n (hn : 0 < n) : {mono *~%R^~ n : x y / x < y :> R}.
Proof. exact: leW_mono (ler_pMz2r _). Qed.
Lemma ler_nMz2r n (hn : n < 0) : {mono *~%R^~ n : x y /~ x <= y :> R}.
Proof.
by move=> x y /=; rewrite -![_ *~ n]mulNrNz ler_pMz2r (oppr_cp0, lerN2).
Qed.
Lemma ltr_nMz2r n (hn : n < 0) : {mono *~%R^~ n : x y /~ x < y :> R}.
Proof. exact: leW_nmono (ler_nMz2r _). Qed.
Lemma ler_wpMz2r n (hn : 0 <= n) : {homo *~%R^~ n : x y / x <= y :> R}.
Proof. by move=> x y xy; case: n hn=> [] // n _; rewrite ler_wMn2r. Qed.
Lemma ler_wnMz2r n (hn : n <= 0) : {homo *~%R^~ n : x y /~ x <= y :> R}.
Proof. by move=> x y xy /=; rewrite -lerN2 -!mulrNz ler_wpMz2r // oppr_ge0. Qed.
Lemma mulrz_ge0 x n (x0 : 0 <= x) (n0 : 0 <= n) : 0 <= x *~ n.
Proof. by rewrite -(mul0rz _ n) ler_wpMz2r. Qed.
Lemma mulrz_le0 x n (x0 : x <= 0) (n0 : n <= 0) : 0 <= x *~ n.
Proof. by rewrite -(mul0rz _ n) ler_wnMz2r. Qed.
Lemma mulrz_ge0_le0 x n (x0 : 0 <= x) (n0 : n <= 0) : x *~ n <= 0.
Proof. by rewrite -(mul0rz _ n) ler_wnMz2r. Qed.
Lemma mulrz_le0_ge0 x n (x0 : x <= 0) (n0 : 0 <= n) : x *~ n <= 0.
Proof. by rewrite -(mul0rz _ n) ler_wpMz2r. Qed.
Lemma pmulrz_lgt0 x n (n0 : 0 < n) : 0 < x *~ n = (0 < x).
Proof. by rewrite -(mul0rz _ n) ltr_pMz2r // mul0rz. Qed.
Lemma nmulrz_lgt0 x n (n0 : n < 0) : 0 < x *~ n = (x < 0).
Proof. by rewrite -(mul0rz _ n) ltr_nMz2r // mul0rz. Qed.
Lemma pmulrz_llt0 x n (n0 : 0 < n) : x *~ n < 0 = (x < 0).
Proof. by rewrite -(mul0rz _ n) ltr_pMz2r // mul0rz. Qed.
Lemma nmulrz_llt0 x n (n0 : n < 0) : x *~ n < 0 = (0 < x).
Proof. by rewrite -(mul0rz _ n) ltr_nMz2r // mul0rz. Qed.
Lemma pmulrz_lge0 x n (n0 : 0 < n) : 0 <= x *~ n = (0 <= x).
Proof. by rewrite -(mul0rz _ n) ler_pMz2r // mul0rz. Qed.
Lemma nmulrz_lge0 x n (n0 : n < 0) : 0 <= x *~ n = (x <= 0).
Proof. by rewrite -(mul0rz _ n) ler_nMz2r // mul0rz. Qed.
Lemma pmulrz_lle0 x n (n0 : 0 < n) : x *~ n <= 0 = (x <= 0).
Proof. by rewrite -(mul0rz _ n) ler_pMz2r // mul0rz. Qed.
Lemma nmulrz_lle0 x n (n0 : n < 0) : x *~ n <= 0 = (0 <= x).
Proof. by rewrite -(mul0rz _ n) ler_nMz2r // mul0rz. Qed.
Lemma ler_wpMz2l x (hx : 0 <= x) : {homo *~%R x : x y / x <= y}.
Proof.
by move=> m n /= hmn; rewrite -subr_ge0 -mulrzBr mulrz_ge0 // subr_ge0.
Qed.
Lemma ler_wnMz2l x (hx : x <= 0) : {homo *~%R x : x y /~ x <= y}.
Proof.
by move=> m n /= hmn; rewrite -subr_ge0 -mulrzBr mulrz_le0 // subr_le0.
Qed.
Lemma ler_pMz2l x (hx : 0 < x) : {mono *~%R x : x y / x <= y}.
Proof.
move=> m n /=; rewrite real_mono ?num_real // => {m n}.
by move=> m n /= hmn; rewrite -subr_gt0 -mulrzBr pmulrz_lgt0 // subr_gt0.
Qed.
Lemma ler_nMz2l x (hx : x < 0) : {mono *~%R x : x y /~ x <= y}.
Proof.
move=> m n /=; rewrite real_nmono ?num_real // => {m n}.
by move=> m n /= hmn; rewrite -subr_gt0 -mulrzBr nmulrz_lgt0 // subr_lt0.
Qed.
Lemma ltr_pMz2l x (hx : 0 < x) : {mono *~%R x : x y / x < y}.
Proof. exact: leW_mono (ler_pMz2l _). Qed.
Lemma ltr_nMz2l x (hx : x < 0) : {mono *~%R x : x y /~ x < y}.
Proof. exact: leW_nmono (ler_nMz2l _). Qed.
Lemma pmulrz_rgt0 x n (x0 : 0 < x) : 0 < x *~ n = (0 < n).
Proof. by rewrite -(mulr0z x) ltr_pMz2l. Qed.
Lemma nmulrz_rgt0 x n (x0 : x < 0) : 0 < x *~ n = (n < 0).
Proof. by rewrite -(mulr0z x) ltr_nMz2l. Qed.
Lemma pmulrz_rlt0 x n (x0 : 0 < x) : x *~ n < 0 = (n < 0).
Proof. by rewrite -(mulr0z x) ltr_pMz2l. Qed.
Lemma nmulrz_rlt0 x n (x0 : x < 0) : x *~ n < 0 = (0 < n).
Proof. by rewrite -(mulr0z x) ltr_nMz2l. Qed.
Lemma pmulrz_rge0 x n (x0 : 0 < x) : 0 <= x *~ n = (0 <= n).
Proof. by rewrite -(mulr0z x) ler_pMz2l. Qed.
Lemma nmulrz_rge0 x n (x0 : x < 0) : 0 <= x *~ n = (n <= 0).
Proof. by rewrite -(mulr0z x) ler_nMz2l. Qed.
Lemma pmulrz_rle0 x n (x0 : 0 < x) : x *~ n <= 0 = (n <= 0).
Proof. by rewrite -(mulr0z x) ler_pMz2l. Qed.
Lemma nmulrz_rle0 x n (x0 : x < 0) : x *~ n <= 0 = (0 <= n).
Proof. by rewrite -(mulr0z x) ler_nMz2l. Qed.
Lemma mulrIz x (hx : x != 0) : injective ( *~%R x).
Proof.
move=> y z; rewrite -![x *~ _]mulrzr => /(mulfI hx).
by apply: inc_inj y z; exact: ler_pMz2l.
Qed.
Lemma ler_int m n : (m%:~R <= n%:~R :> R) = (m <= n).
Proof. by rewrite ler_pMz2l. Qed.
Lemma ltr_int m n : (m%:~R < n%:~R :> R) = (m < n).
Proof. by rewrite ltr_pMz2l. Qed.
Lemma eqr_int m n : (m%:~R == n%:~R :> R) = (m == n).
Proof. by rewrite (inj_eq (mulrIz _)) ?oner_eq0. Qed.
Lemma ler0z n : (0 <= n%:~R :> R) = (0 <= n).
Proof. by rewrite pmulrz_rge0. Qed.
Lemma ltr0z n : (0 < n%:~R :> R) = (0 < n).
Proof. by rewrite pmulrz_rgt0. Qed.
Lemma lerz0 n : (n%:~R <= 0 :> R) = (n <= 0).
Proof. by rewrite pmulrz_rle0. Qed.
Lemma ltrz0 n : (n%:~R < 0 :> R) = (n < 0).
Proof. by rewrite pmulrz_rlt0. Qed.
Lemma ler1z (n : int) : (1 <= n%:~R :> R) = (1 <= n).
Proof. by rewrite -[1]/(1%:~R) ler_int. Qed.
Lemma ltr1z (n : int) : (1 < n%:~R :> R) = (1 < n).
Proof. by rewrite -[1]/(1%:~R) ltr_int. Qed.
Lemma lerz1 n : (n%:~R <= 1 :> R) = (n <= 1).
Proof. by rewrite -[1]/(1%:~R) ler_int. Qed.
Lemma ltrz1 n : (n%:~R < 1 :> R) = (n < 1).
Proof. by rewrite -[1]/(1%:~R) ltr_int. Qed.
Lemma intr_eq0 n : (n%:~R == 0 :> R) = (n == 0).
Proof. by rewrite -(mulr0z 1) (inj_eq (mulrIz _)) // oner_eq0. Qed.
Lemma mulrz_eq0 x n : (x *~ n == 0) = ((n == 0) || (x == 0)).
Proof. by rewrite -mulrzl mulf_eq0 intr_eq0. Qed.
Lemma mulrz_neq0 x n : x *~ n != 0 = ((n != 0) && (x != 0)).
Proof. by rewrite mulrz_eq0 negb_or. Qed.
Lemma realz n : (n%:~R : R) \in Num.real.
Proof. by rewrite -topredE /Num.real /= ler0z lerz0 le_total. Qed.
Hint Resolve realz : core.
Definition intr_inj := @mulrIz 1 (oner_neq0 R).
End PO.
End NumMorphism.
End MorphTheory.
Arguments intr_inj {R} [x1 x2].
Definition exprz (R : unitRingType) (x : R) (n : int) :=
match n with
| Posz n => x ^+ n
| Negz n => x ^- (n.+1)
end.
Arguments exprz : simpl never.
Notation "x ^ n" := (exprz x n) : ring_scope.
Section ExprzUnitRing.
Variable R : unitRingType.
Implicit Types x y : R.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
Lemma exprnP x (n : nat) : x ^+ n = x ^ n. Proof. by []. Qed.
Lemma exprnN x (n : nat) : x ^- n = x ^ (-n%:Z).
Proof. by case: n=> //; rewrite oppr0 expr0 invr1. Qed.
Lemma expr0z x : x ^ 0 = 1. Proof. by []. Qed.
Lemma expr1z x : x ^ 1 = x. Proof. by []. Qed.
Lemma exprN1 x : x ^ (-1) = x^-1. Proof. by []. Qed.
Lemma invr_expz x n : (x ^ n)^-1 = x ^ (- n).
Proof. by case: (intP n)=> // [|m]; rewrite ?opprK ?expr0z ?invr1 // invrK. Qed.
Lemma exprz_inv x n : (x^-1) ^ n = x ^ (- n).
Proof. by case: (intP n)=> // m; rewrite -[_ ^ (- _)]exprVn ?opprK ?invrK. Qed.
Lemma exp1rz n : 1 ^ n = 1 :> R.
Proof. by case: (intP n)=> // m; rewrite -?exprz_inv ?invr1; apply: expr1n. Qed.
Lemma exprSz x (n : nat) : x ^ n.+1 = x * x ^ n. Proof. exact: exprS. Qed.
Lemma exprSzr x (n : nat) : x ^ n.+1 = x ^ n * x. Proof. exact: exprSr. Qed.
Fact exprzD_nat x (m n : nat) : x ^ (m%:Z + n) = x ^ m * x ^ n.
Proof. exact: exprD. Qed.
Fact exprzD_Nnat x (m n : nat) : x ^ (-m%:Z + -n%:Z) = x ^ (-m%:Z) * x ^ (-n%:Z).
Proof. by rewrite -opprD -!exprz_inv exprzD_nat. Qed.
Lemma exprzD_ss x m n : (0 <= m) && (0 <= n) || (m <= 0) && (n <= 0)
-> x ^ (m + n) = x ^ m * x ^ n.
Proof.
case: (intP m)=> {m} [|m|m]; case: (intP n)=> {n} [|n|n] //= _;
by rewrite ?expr0z ?mul1r ?exprzD_nat ?exprzD_Nnat ?sub0r ?addr0 ?mulr1.
Qed.
Lemma exp0rz n : 0 ^ n = (n == 0)%:~R :> R.
Proof. by case: (intP n)=> // m; rewrite -?exprz_inv ?invr0 exprSz mul0r. Qed.
Lemma commrXz x y n : GRing.comm x y -> GRing.comm x (y ^ n).
Proof.
rewrite /GRing.comm; elim: n x y=> [|n ihn|n ihn] x y com_xy //=.
* by rewrite expr0z mul1r mulr1.
* by rewrite -exprnP commrX //.
rewrite -exprz_inv -exprnP commrX //.
case: (boolP (y \is a GRing.unit))=> uy; last by rewrite invr_out.
by apply/eqP; rewrite (can2_eq (mulrVK _) (mulrK _)) // -mulrA com_xy mulKr.
Qed.
Lemma exprMz_comm x y n : x \is a GRing.unit -> y \is a GRing.unit ->
GRing.comm x y -> (x * y) ^ n = x ^ n * y ^ n.
Proof.
move=> ux uy com_xy; elim: n => [|n _|n _]; first by rewrite expr0z mulr1.
by rewrite -!exprnP exprMn_comm.
rewrite -!exprnN -!exprVn com_xy -exprMn_comm ?invrM//.
exact/commrV/commr_sym/commrV.
Qed.
Lemma commrXz_wmulls x y n :
0 <= n -> GRing.comm x y -> (x * y) ^ n = x ^ n * y ^ n.
Proof.
move=> n0 com_xy; elim: n n0 => [|n _|n _] //; first by rewrite expr0z mulr1.
by rewrite -!exprnP exprMn_comm.
Qed.
Lemma unitrXz x n (ux : x \is a GRing.unit) : x ^ n \is a GRing.unit.
Proof.
case: (intP n)=> {n} [|n|n]; rewrite ?expr0z ?unitr1 ?unitrX //.
by rewrite -invr_expz unitrV unitrX.
Qed.
Lemma exprzDr x (ux : x \is a GRing.unit) m n : x ^ (m + n) = x ^ m * x ^ n.
Proof.
move: n m; apply: wlog_le=> n m hnm.
by rewrite addrC hnm commrXz //; exact/commr_sym/commrXz.
case: (intP m) hnm=> {m} [|m|m]; rewrite ?mul1r ?add0r //;
case: (intP n)=> {n} [|n|n _]; rewrite ?mulr1 ?addr0 //;
do ?by rewrite exprzD_ss.
rewrite -invr_expz subzSS !exprSzr invrM ?unitrX // -mulrA mulVKr //.
case: (leqP n m)=> [|/ltnW] hmn; rewrite -{2}(subnK hmn) exprzD_nat -subzn //.
by rewrite mulrK ?unitrX.
by rewrite invrM ?unitrXz // mulVKr ?unitrXz // -opprB -invr_expz.
Qed.
Lemma exprz_exp x m n : (x ^ m) ^ n = (x ^ (m * n)).
Proof.
wlog: n / 0 <= n.
by case: n=> [n -> //|n]; rewrite ?NegzE mulrN -?invr_expz=> -> /=.
elim: n x m=> [|n ihn|n ihn] x m // _; first by rewrite mulr0 !expr0z.
rewrite exprSz ihn // intS mulrDr mulr1 exprzD_ss //.
by case: (intP m)=> // m'; rewrite ?oppr_le0 //.
Qed.
Lemma exprzAC x m n : (x ^ m) ^ n = (x ^ n) ^ m.
Proof. by rewrite !exprz_exp mulrC. Qed.
Lemma exprz_out x n (nux : x \isn't a GRing.unit) (hn : 0 <= n) :
x ^ (- n) = x ^ n.
Proof. by case: (intP n) hn=> //= m; rewrite -exprnN -exprVn invr_out. Qed.
End ExprzUnitRing.
Section Exprz_Zint_UnitRing.
Variable R : unitRingType.
Implicit Types x y : R.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
Lemma exprz_pMzl x m n : 0 <= n -> (x *~ m) ^ n = x ^ n *~ (m ^ n).
Proof.
by elim: n=> [|n ihn|n _] // _; rewrite !exprSz ihn // mulrzAr mulrzAl -mulrzA.
Qed.
Lemma exprz_pintl m n (hn : 0 <= n) : m%:~R ^ n = (m ^ n)%:~R :> R.
Proof. by rewrite exprz_pMzl // exp1rz. Qed.
Lemma exprzMzl x m n (ux : x \is a GRing.unit) (um : m%:~R \is a @GRing.unit R):
(x *~ m) ^ n = (m%:~R ^ n) * x ^ n :> R.
Proof. rewrite -[x *~ _]mulrzl exprMz_comm //; exact/commr_sym/commr_int. Qed.
Lemma expNrz x n : (- x) ^ n = (-1) ^ n * x ^ n :> R.
Proof.
case: n=> [] n; rewrite ?NegzE; first exact: exprNn.
by rewrite -!exprz_inv !invrN invr1; apply: exprNn.
Qed.
Lemma unitr_n0expz x n :
n != 0 -> (x ^ n \is a GRing.unit) = (x \is a GRing.unit).
Proof.
by case: n => *; rewrite ?NegzE -?exprz_inv ?unitrX_pos ?unitrV ?lt0n.
Qed.
Lemma intrV (n : int) :
n \in [:: 0; 1; -1] -> n%:~R ^-1 = n%:~R :> R.
Proof.
by case: (intP n)=> // [|[]|[]] //; rewrite ?rmorphN ?invrN (invr0, invr1).
Qed.
Lemma rmorphXz (R' : unitRingType) (f : {rmorphism R -> R'}) n :
{in GRing.unit, {morph f : x / x ^ n}}.
Proof. by case: n => n x Ux; rewrite ?rmorphV ?rpredX ?rmorphXn. Qed.
End Exprz_Zint_UnitRing.
Section ExprzIdomain.
Variable R : idomainType.
Implicit Types x y : R.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
Lemma expfz_eq0 x n : (x ^ n == 0) = (n != 0) && (x == 0).
Proof.
by case: n=> n; rewrite ?NegzE -?exprz_inv ?expf_eq0 ?lt0n ?invr_eq0.
Qed.
Lemma expfz_neq0 x n : x != 0 -> x ^ n != 0.
Proof. by move=> x_nz; rewrite expfz_eq0; apply/nandP; right. Qed.
Lemma exprzMl x y n (ux : x \is a GRing.unit) (uy : y \is a GRing.unit) :
(x * y) ^ n = x ^ n * y ^ n.
Proof. by rewrite exprMz_comm //; apply: mulrC. Qed.
Lemma expfV (x : R) (i : int) : (x ^ i) ^-1 = (x ^-1) ^ i.
Proof. by rewrite invr_expz exprz_inv. Qed.
End ExprzIdomain.
Section ExprzField.
Variable F : fieldType.
Implicit Types x y : F.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
Lemma expfzDr x m n : x != 0 -> x ^ (m + n) = x ^ m * x ^ n.
Proof. by move=> hx; rewrite exprzDr ?unitfE. Qed.
Lemma expfz_n0addr x m n : m + n != 0 -> x ^ (m + n) = x ^ m * x ^ n.
Proof.
have [-> hmn|nx0 _] := eqVneq x 0; last exact: expfzDr.
rewrite !exp0rz (negPf hmn).
case: (eqVneq m 0) hmn => [->|]; rewrite (mul0r, mul1r) //.
by rewrite add0r=> /negPf->.
Qed.
Lemma expfzMl x y n : (x * y) ^ n = x ^ n * y ^ n.
Proof.
have [->|/negPf n0] := eqVneq n 0; first by rewrite !expr0z mulr1.
case: (boolP ((x * y) == 0)); rewrite ?mulf_eq0.
by case/pred2P=> ->; rewrite ?(mul0r, mulr0, exp0rz, n0).
by case/norP=> x0 y0; rewrite exprzMl ?unitfE.
Qed.
Lemma fmorphXz (R : unitRingType) (f : {rmorphism F -> R}) n :
{morph f : x / x ^ n}.
Proof. by case: n => n x; rewrite ?fmorphV rmorphXn. Qed.
End ExprzField.
Section ExprzNumDomain.
Variable R : numDomainType.
Implicit Types x y : R.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
(* ler and exprz *)
Lemma exprz_ge0 n x (hx : 0 <= x) : (0 <= x ^ n).
Proof. by case: n => n; rewrite ?invr_ge0 ?exprn_ge0. Qed.
Lemma exprz_gt0 n x (hx : 0 < x) : (0 < x ^ n).
Proof. by case: n => n; rewrite ?invr_gt0 ?exprn_gt0. Qed.
Definition exprz_gte0 := (exprz_ge0, exprz_gt0).
Lemma ler_wpiXz2l x (x0 : 0 <= x) (x1 : x <= 1) :
{in >= 0 &, {homo exprz x : x y /~ x <= y}}.
Proof.
move=> [] m [] n; rewrite -!topredE /= ?oppr_cp0 ?ltz_nat // => _ _.
by rewrite lez_nat -?exprnP => /ler_wiXn2l; apply.
Qed.
Fact ler_wpeXz2l x (x1 : 1 <= x) : {in >= 0 &, {homo exprz x : x y / x <= y}}.
Proof.
move=> [] m [] n; rewrite -!topredE /= ?oppr_cp0 ?ltz_nat // => _ _.
by rewrite lez_nat -?exprnP=> /ler_weXn2l; apply.
Qed.
Lemma pexprz_eq1 x n (x0 : 0 <= x) : (x ^ n == 1) = ((n == 0) || (x == 1)).
Proof.
case: n=> n; rewrite ?NegzE -?exprz_inv ?oppr_eq0 pexprn_eq1 // ?invr_eq1 //.
by rewrite invr_ge0.
Qed.
Lemma ler_wpXz2r n (hn : 0 <= n) :
{in >= 0 & , {homo (@exprz R)^~ n : x y / x <= y}}.
Proof. by case: n hn=> // n _; exact: lerXn2r. Qed.
End ExprzNumDomain.
Section ExprzOrder.
Variable R : realFieldType.
Implicit Types x y : R.
Implicit Types m n : int.
Local Coercion Posz : nat >-> int.
(* ler and exprz *)
Lemma ler_wniXz2l x (x0 : 0 <= x) (x1 : x <= 1) :
{in < 0 &, {homo exprz x : x y /~ x <= y}}.
Proof.
move=> [] m [] n; rewrite ?NegzE -!topredE /= ?oppr_cp0 ?ltz_nat // => _ _.
rewrite lerN2 lez_nat -?invr_expz=> hmn; have := x0.
rewrite le0r=> /predU1P [->|lx0]; first by rewrite !exp0rz invr0.
by rewrite lef_pV2 -?topredE /= ?exprz_gt0 // ler_wiXn2l.
Qed.
Fact ler_wneXz2l x (x1 : 1 <= x) : {in <= 0 &, {homo exprz x : x y / x <= y}}.
Proof.
move=> m n hm hn /= hmn.
rewrite -lef_pV2 -?topredE /= ?exprz_gt0 ?(lt_le_trans ltr01) //.
by rewrite !invr_expz ler_wpeXz2l ?lerN2 -?topredE //= oppr_cp0.
Qed.
Lemma ler_weXz2l x (x1 : 1 <= x) : {homo exprz x : x y / x <= y}.
Proof.
move=> m n /= hmn; case: (lerP 0 m)=> [|/ltW] hm.
by rewrite ler_wpeXz2l // [_ \in _](le_trans hm).
case: (lerP n 0)=> [|/ltW] hn.
by rewrite ler_wneXz2l // [_ \in _](le_trans hmn).
apply: (@le_trans _ _ (x ^ 0)); first by rewrite ler_wneXz2l.
by rewrite ler_wpeXz2l.
Qed.
Lemma ieexprIz x (x0 : 0 < x) (nx1 : x != 1) : injective (exprz x).
Proof.
apply: wlog_lt=> // m n hmn; first by move=> hmn'; rewrite hmn.
move=> /(f_equal ( *%R^~ (x ^ (- n)))).
rewrite -!expfzDr ?gt_eqF // subrr expr0z=> /eqP.
by rewrite pexprz_eq1 ?(ltW x0) // (negPf nx1) subr_eq0 orbF=> /eqP.
Qed.
Lemma ler_piXz2l x (x0 : 0 < x) (x1 : x < 1) :
{in >= 0 &, {mono exprz x : x y /~ x <= y}}.
Proof.
apply: (le_nmono_in (inj_nhomo_lt_in _ _)).
by move=> n m hn hm /=; apply: ieexprIz; rewrite // lt_eqF.
by apply: ler_wpiXz2l; rewrite ?ltW.
Qed.
Lemma ltr_piXz2l x (x0 : 0 < x) (x1 : x < 1) :
{in >= 0 &, {mono exprz x : x y /~ x < y}}.
Proof. exact: (leW_nmono_in (ler_piXz2l _ _)). Qed.
Lemma ler_niXz2l x (x0 : 0 < x) (x1 : x < 1) :
{in < 0 &, {mono exprz x : x y /~ x <= y}}.
Proof.
apply: (le_nmono_in (inj_nhomo_lt_in _ _)).
by move=> n m hn hm /=; apply: ieexprIz; rewrite // lt_eqF.
by apply: ler_wniXz2l; rewrite ?ltW.
Qed.
Lemma ltr_niXz2l x (x0 : 0 < x) (x1 : x < 1) :
{in < 0 &, {mono (exprz x) : x y /~ x < y}}.
Proof. exact: (leW_nmono_in (ler_niXz2l _ _)). Qed.
Lemma ler_eXz2l x (x1 : 1 < x) : {mono exprz x : x y / x <= y}.
Proof.
apply: (le_mono (inj_homo_lt _ _)).
by apply: ieexprIz; rewrite ?(lt_trans ltr01) // gt_eqF.
by apply: ler_weXz2l; rewrite ?ltW.
Qed.
Lemma ltr_eXz2l x (x1 : 1 < x) : {mono exprz x : x y / x < y}.
Proof. exact: (leW_mono (ler_eXz2l _)). Qed.
Lemma ler_wnXz2r n (hn : n <= 0) :
{in > 0 & , {homo (@exprz R)^~ n : x y /~ x <= y}}.
Proof.
move=> x y /= hx hy hxy; rewrite -lef_pV2 ?[_ \in _]exprz_gt0 //.
by rewrite !invr_expz ler_wpXz2r ?[_ \in _]ltW // oppr_cp0.
Qed.
Lemma pexpIrz n (n0 : n != 0) : {in >= 0 &, injective ((@exprz R)^~ n)}.
Proof.
move=> x y; rewrite ![_ \in _]le0r=> /predU1P [-> _ /eqP|hx].
by rewrite exp0rz ?(negPf n0) eq_sym expfz_eq0=> /andP [_ /eqP->].
case/predU1P=> [-> /eqP|hy].
by rewrite exp0rz ?(negPf n0) expfz_eq0=> /andP [_ /eqP].
move=> /(f_equal ( *%R^~ (y ^ (- n)))) /eqP.
rewrite -expfzDr ?(gt_eqF hy) // subrr expr0z -exprz_inv -expfzMl.
rewrite pexprz_eq1 ?(negPf n0) /= ?mulr_ge0 ?invr_ge0 ?ltW //.
by rewrite (can2_eq (mulrVK _) (mulrK _)) ?unitfE ?(gt_eqF hy) // mul1r=> /eqP.
Qed.
Lemma nexpIrz n (n0 : n != 0) : {in <= 0 &, injective ((@exprz R)^~ n)}.
Proof.
move=> x y; rewrite ![_ \in _]le_eqVlt => /predU1P [-> _ /eqP|hx].
by rewrite exp0rz ?(negPf n0) eq_sym expfz_eq0=> /andP [_ /eqP->].
case/predU1P=> [-> /eqP|hy].
by rewrite exp0rz ?(negPf n0) expfz_eq0=> /andP [_ /eqP].
move=> /(f_equal ( *%R^~ (y ^ (- n)))) /eqP.
rewrite -expfzDr ?(lt_eqF hy) // subrr expr0z -exprz_inv -expfzMl.
rewrite pexprz_eq1 ?(negPf n0) /= ?mulr_le0 ?invr_le0 ?ltW //.
by rewrite (can2_eq (mulrVK _) (mulrK _)) ?unitfE ?(lt_eqF hy) // mul1r=> /eqP.
Qed.
Lemma ler_pXz2r n (hn : 0 < n) :
{in >= 0 & , {mono ((@exprz R)^~ n) : x y / x <= y}}.
Proof.
apply: le_mono_in (inj_homo_lt_in _ _).
by move=> x y hx hy /=; apply: pexpIrz; rewrite // gt_eqF.
by apply: ler_wpXz2r; rewrite ltW.
Qed.
Lemma ltr_pXz2r n (hn : 0 < n) :
{in >= 0 & , {mono ((@exprz R)^~ n) : x y / x < y}}.
Proof. exact: leW_mono_in (ler_pXz2r _). Qed.
Lemma ler_nXz2r n (hn : n < 0) :
{in > 0 & , {mono ((@exprz R)^~ n) : x y /~ x <= y}}.
Proof.
apply: le_nmono_in (inj_nhomo_lt_in _ _); last first.
by apply: ler_wnXz2r; rewrite ltW.
by move=> x y hx hy /=; apply: pexpIrz; rewrite ?[_ \in _]ltW ?lt_eqF.
Qed.
Lemma ltr_nXz2r n (hn : n < 0) :
{in > 0 & , {mono ((@exprz R)^~ n) : x y /~ x < y}}.
Proof. exact: leW_nmono_in (ler_nXz2r _). Qed.
Lemma eqrXz2 n x y : n != 0 -> 0 <= x -> 0 <= y -> (x ^ n == y ^ n) = (x == y).
Proof. by move=> *; rewrite (inj_in_eq (pexpIrz _)). Qed.
End ExprzOrder.
Local Notation sgr := Num.sg.
Section Sgz.
Variable R : numDomainType.
Implicit Types x y z : R.
Implicit Types m n p : int.
Local Coercion Posz : nat >-> int.
Definition sgz x : int := if x == 0 then 0 else if x < 0 then -1 else 1.
Lemma sgz_def x : sgz x = (-1) ^+ (x < 0)%R *+ (x != 0).
Proof. by rewrite /sgz; case: (_ == _); case: (_ < _). Qed.
Lemma sgrEz x : sgr x = (sgz x)%:~R. Proof. by rewrite !(fun_if intr). Qed.
Lemma gtr0_sgz x : 0 < x -> sgz x = 1.
Proof. by move=> x_gt0; rewrite /sgz lt_neqAle andbC eq_le lt_geF. Qed.
Lemma ltr0_sgz x : x < 0 -> sgz x = -1.
Proof. by move=> x_lt0; rewrite /sgz eq_sym eq_le x_lt0 lt_geF. Qed.
Lemma sgz0 : sgz (0 : R) = 0. Proof. by rewrite /sgz eqxx. Qed.
Lemma sgz1 : sgz (1 : R) = 1. Proof. by rewrite gtr0_sgz // ltr01. Qed.
Lemma sgzN1 : sgz (-1 : R) = -1. Proof. by rewrite ltr0_sgz // ltrN10. Qed.
Definition sgzE := (sgz0, sgz1, sgzN1).
Lemma sgz_sgr x : sgz (sgr x) = sgz x.
Proof. by rewrite !(fun_if sgz) !sgzE. Qed.
Lemma normr_sgz x : `|sgz x| = (x != 0).
Proof. by rewrite sgz_def -mulr_natr normrMsign normr_nat natz. Qed.
Lemma normr_sg x : `|sgr x| = (x != 0)%:~R.
Proof. by rewrite sgr_def -mulr_natr normrMsign normr_nat. Qed.
End Sgz.
Section MoreSgz.
Variable R : numDomainType.
Lemma sgz_int m : sgz (m%:~R : R) = sgz m.
Proof. by rewrite /sgz intr_eq0 ltrz0. Qed.
Lemma sgrz (n : int) : sgr n = sgz n. Proof. by rewrite sgrEz intz. Qed.
Lemma intr_sg m : (sgr m)%:~R = sgr (m%:~R) :> R.
Proof. by rewrite sgrz -sgz_int -sgrEz. Qed.
Lemma sgz_id (x : R) : sgz (sgz x) = sgz x.
Proof. by rewrite !(fun_if (@sgz _)). Qed.
End MoreSgz.
Section SgzReal.
Variable R : realDomainType.
Implicit Types x y z : R.
Implicit Types m n p : int.
Local Coercion Posz : nat >-> int.
Lemma sgz_cp0 x :
((sgz x == 1) = (0 < x)) *
((sgz x == -1) = (x < 0)) *
((sgz x == 0) = (x == 0)).
Proof. by rewrite /sgz; case: ltrgtP. Qed.
Variant sgz_val x : bool -> bool -> bool -> bool -> bool -> bool
-> bool -> bool -> bool -> bool -> bool -> bool
-> bool -> bool -> bool -> bool -> bool -> bool
-> R -> R -> int -> Set :=
| SgzNull of x = 0 : sgz_val x true true true true false false
true false false true false false true false false true false false 0 0 0
| SgzPos of x > 0 : sgz_val x false false true false false true
false false true false false true false false true false false true x 1 1
| SgzNeg of x < 0 : sgz_val x false true false false true false
false true false false true false false true false false true false (-x) (-1) (-1).
Lemma sgzP x :
sgz_val x (0 == x) (x <= 0) (0 <= x) (x == 0) (x < 0) (0 < x)
(0 == sgr x) (-1 == sgr x) (1 == sgr x)
(sgr x == 0) (sgr x == -1) (sgr x == 1)
(0 == sgz x) (-1 == sgz x) (1 == sgz x)
(sgz x == 0) (sgz x == -1) (sgz x == 1) `|x| (sgr x) (sgz x).
Proof.
rewrite ![_ == sgz _]eq_sym ![_ == sgr _]eq_sym !sgr_cp0 !sgz_cp0.
by rewrite /sgz; case: sgrP; constructor.
Qed.
Lemma sgzN x : sgz (- x) = - sgz x.
Proof. by rewrite /sgz oppr_eq0 oppr_lt0; case: ltrgtP. Qed.
Lemma mulz_sg x : sgz x * sgz x = (x != 0)%:~R.
Proof. by case: sgzP; rewrite ?(mulr0, mulr1, mulrNN). Qed.
Lemma mulz_sg_eq1 x y : (sgz x * sgz y == 1) = (x != 0) && (sgz x == sgz y).
Proof.
do 2?case: sgzP=> _; rewrite ?(mulr0, mulr1, mulrN1, opprK, oppr0, eqxx);
by rewrite ?[0 == 1]eq_sym ?oner_eq0 //= eqr_oppLR oppr0 oner_eq0.
Qed.
Lemma mulz_sg_eqN1 x y : (sgz x * sgz y == -1) = (x != 0) && (sgz x == - sgz y).
Proof. by rewrite -eqr_oppLR -mulrN -sgzN mulz_sg_eq1. Qed.
(* Lemma muls_eqA x y z : sgr x != 0 -> *)
(* (sgr y * sgr z == sgr x) = ((sgr y * sgr x == sgr z) && (sgr z != 0)). *)
(* Proof. by do 3!case: sgrP=> _. Qed. *)
Lemma sgzM x y : sgz (x * y) = sgz x * sgz y.
Proof.
rewrite -sgz_sgr -(sgz_sgr x) -(sgz_sgr y) sgrM.
by case: sgrP; case: sgrP; rewrite /sgz ?(mulNr, mul0r, mul1r);
rewrite ?(oppr_eq0, oppr_cp0, eqxx, ltxx, ltr01, ltr10, oner_eq0).
Qed.
Lemma sgzX (n : nat) x : sgz (x ^+ n) = (sgz x) ^+ n.
Proof. by elim: n => [|n IHn]; rewrite ?sgz1 // !exprS sgzM IHn. Qed.
Lemma sgz_eq0 x : (sgz x == 0) = (x == 0).
Proof. by rewrite sgz_cp0. Qed.
Lemma sgz_odd (n : nat) x : x != 0 -> (sgz x) ^+ n = (sgz x) ^+ (odd n).
Proof. by case: sgzP => //=; rewrite ?expr1n // signr_odd. Qed.
Lemma sgz_gt0 x : (sgz x > 0) = (x > 0).
Proof. by case: sgzP. Qed.
Lemma sgz_lt0 x : (sgz x < 0) = (x < 0).
Proof. by case: sgzP. Qed.
Lemma sgz_ge0 x : (sgz x >= 0) = (x >= 0).
Proof. by case: sgzP. Qed.
Lemma sgz_le0 x : (sgz x <= 0) = (x <= 0).
Proof. by case: sgzP. Qed.
Lemma sgz_smul x y : sgz (y *~ (sgz x)) = (sgz x) * (sgz y).
Proof. by rewrite -mulrzl sgzM -sgrEz sgz_sgr. Qed.
Lemma sgrMz m x : sgr (x *~ m) = sgr x *~ sgr m.
Proof. by rewrite -mulrzr sgrM -intr_sg mulrzr. Qed.
End SgzReal.
Lemma sgz_eq (R R' : realDomainType) (x : R) (y : R') :
(sgz x == sgz y) = ((x == 0) == (y == 0)) && ((0 < x) == (0 < y)).
Proof. by do 2!case: sgzP. Qed.
Lemma intr_sign (R : pzRingType) s : ((-1) ^+ s)%:~R = (-1) ^+ s :> R.
Proof. exact: rmorph_sign. Qed.
Section Absz.
Implicit Types m n p : int.
Open Scope nat_scope.
Local Coercion Posz : nat >-> int.
Lemma absz_nat (n : nat) : `|n| = n. Proof. by []. Qed.
Lemma abszE (m : int) : `|m| = `|m|%R :> int. Proof. by []. Qed.
Lemma absz0 : `|0%R| = 0. Proof. by []. Qed.
Lemma abszN m : `|- m| = `|m|. Proof. by case: (normrN m). Qed.
Lemma absz_eq0 m : (`|m| == 0) = (m == 0%R). Proof. by case: (intP m). Qed.
Lemma absz_gt0 m : (`|m| > 0) = (m != 0%R). Proof. by case: (intP m). Qed.
Lemma absz1 : `|1%R| = 1. Proof. by []. Qed.
Lemma abszN1 : `|-1%R| = 1. Proof. by []. Qed.
Lemma absz_id m : `|(`|m|)| = `|m|. Proof. by []. Qed.
Lemma abszM m1 m2 : `|(m1 * m2)%R| = `|m1| * `|m2|.
Proof. by case: m1 m2 => [[|m1]|m1] [[|m2]|m2] //=; rewrite ?mulnS mulnC. Qed.
Lemma abszX (n : nat) m : `|m ^+ n| = `|m| ^ n.
Proof. by elim: n => // n ihn; rewrite exprS expnS abszM ihn. Qed.
Lemma absz_sg m : `|sgr m| = (m != 0%R). Proof. by case: (intP m). Qed.
Lemma gez0_abs m : (0 <= m)%R -> `|m| = m :> int.
Proof. by case: (intP m). Qed.
Lemma gtz0_abs m : (0 < m)%R -> `|m| = m :> int.
Proof. by case: (intP m). Qed.
Lemma lez0_abs m : (m <= 0)%R -> `|m| = - m :> int.
Proof. by case: (intP m). Qed.
Lemma ltz0_abs m : (m < 0)%R -> `|m| = - m :> int.
Proof. by case: (intP m). Qed.
Lemma lez_abs m : m <= `|m|%N :> int.
Proof. by case: (intP m). Qed.
Lemma absz_sign s : `|(-1) ^+ s| = 1.
Proof. by rewrite abszX exp1n. Qed.
Lemma abszMsign s m : `|((-1) ^+ s * m)%R| = `|m|.
Proof. by rewrite abszM absz_sign mul1n. Qed.
Lemma mulz_sign_abs m : ((-1) ^+ (m < 0)%R * `|m|%:Z)%R = m.
Proof. by rewrite abszE mulr_sign_norm. Qed.
Lemma mulz_Nsign_abs m : ((-1) ^+ (0 < m)%R * `|m|%:Z)%R = - m.
Proof. by rewrite abszE mulr_Nsign_norm. Qed.
Lemma intEsign m : m = ((-1) ^+ (m < 0)%R * `|m|%:Z)%R.
Proof. exact: numEsign. Qed.
Lemma abszEsign m : `|m|%:Z = ((-1) ^+ (m < 0)%R * m)%R.
Proof. exact: normrEsign. Qed.
Lemma intEsg m : m = (sgz m * `|m|%:Z)%R.
Proof. by rewrite -sgrz -numEsg. Qed.
Lemma abszEsg m : (`|m|%:Z = sgz m * m)%R.
Proof. by rewrite -sgrz -normrEsg. Qed.
End Absz.
Section MoreAbsz.
Variable R : numDomainType.
Implicit Type i : int.
Lemma mulr_absz (x : R) i : x *+ `|i| = x *~ `|i|.
Proof. by rewrite -abszE. Qed.
Lemma natr_absz i : `|i|%:R = `|i|%:~R :> R.
Proof. by rewrite -abszE. Qed.
End MoreAbsz.
Module Export IntDist.
(* This notation is supposed to work even if the ssrint library is not Imported.
Since we can't rely on the CS database to contain the zmodule instance on
int we put the instance by hand in the notation. *)
Local Definition int_nmodType : nmodType := int.
Local Definition int_zmodType : zmodType := int.
Notation "m - n" :=
(@GRing.add int_nmodType (m%N : int)
(@GRing.opp int_zmodType (n%N : int))) : distn_scope.
Arguments absz m%_distn_scope.
Notation "`| m |" := (absz m) : nat_scope.
Coercion Posz : nat >-> int.
Section Distn.
Open Scope nat_scope.
Implicit Type m : int.
Implicit Types n d : nat.
Lemma distnC m1 m2 : `|m1 - m2| = `|m2 - m1|.
Proof. by rewrite -opprB abszN. Qed.
Lemma distnDl d n1 n2 : `|d + n1 - (d + n2)| = `|n1 - n2|.
Proof. by rewrite !PoszD opprD addrCA -addrA addKr. Qed.
Lemma distnDr d n1 n2 : `|n1 + d - (n2 + d)| = `|n1 - n2|.
Proof. by rewrite -!(addnC d) distnDl. Qed.
Lemma distnEr n1 n2 : n1 <= n2 -> `|n1 - n2| = n2 - n1.
Proof. by move/subnK=> {1}<-; rewrite distnC PoszD addrK absz_nat. Qed.
Lemma distnEl n1 n2 : n2 <= n1 -> `|n1 - n2| = n1 - n2.
Proof. by move/distnEr <-; rewrite distnC. Qed.
Lemma distn0 n : `|n - 0| = n.
Proof. by rewrite subr0 absz_nat. Qed.
Lemma dist0n n : `|0 - n| = n.
Proof. by rewrite distnC distn0. Qed.
Lemma distnn m : `|m - m| = 0.
Proof. by rewrite subrr. Qed.
Lemma distn_eq0 n1 n2 : (`|n1 - n2| == 0) = (n1 == n2).
Proof. by rewrite absz_eq0 subr_eq0. Qed.
Lemma distnS n : `|n - n.+1| = 1.
Proof. exact: distnDr n 0 1. Qed.
Lemma distSn n : `|n.+1 - n| = 1.
Proof. exact: distnDr n 1 0. Qed.
Lemma distn_eq1 n1 n2 :
(`|n1 - n2| == 1) = (if n1 < n2 then n1.+1 == n2 else n1 == n2.+1).
Proof.
case: ltnP => [lt_n12 | le_n21].
by rewrite eq_sym -(eqn_add2r n1) distnEr ?subnK // ltnW.
by rewrite -(eqn_add2r n2) distnEl ?subnK.
Qed.
Lemma leqD_dist m1 m2 m3 : `|m1 - m3| <= `|m1 - m2| + `|m2 - m3|.
Proof. by rewrite -lez_nat PoszD !abszE ler_distD. Qed.
(* Most of this proof generalizes to all real-ordered rings. *)
Lemma leqifD_distz m1 m2 m3 :
`|m1 - m3| <= `|m1 - m2| + `|m2 - m3|
?= iff (m1 <= m2 <= m3)%R || (m3 <= m2 <= m1)%R.
Proof.
apply/leqifP; rewrite -ltz_nat -eqz_nat PoszD !abszE; apply/leifP.
wlog le_m31 : m1 m3 / (m3 <= m1)%R.
move=> IH; case/orP: (le_total m1 m3) => /IH //.
by rewrite (addrC `|_|)%R orbC !(distrC m1) !(distrC m3).
rewrite ger0_norm ?subr_ge0 // orb_idl => [|/andP[le_m12 le_m23]]; last first.
by have /eqP->: m2 == m3; rewrite ?lexx // eq_le le_m23 (le_trans le_m31).
rewrite -{1}(subrK m2 m1) -(addrA _ m2) -subr_ge0 andbC -[X in X && _]subr_ge0.
by apply: leifD; apply/real_leif_norm/num_real.
Qed.
Lemma leqifD_dist n1 n2 n3 :
`|n1 - n3| <= `|n1 - n2| + `|n2 - n3|
?= iff (n1 <= n2 <= n3) || (n3 <= n2 <= n1).
Proof. exact: leqifD_distz. Qed.
Lemma sqrn_dist n1 n2 : `|n1 - n2| ^ 2 + 2 * (n1 * n2) = n1 ^ 2 + n2 ^ 2.
Proof.
wlog le_n21: n1 n2 / n2 <= n1.
move=> IH; case/orP: (leq_total n2 n1) => /IH //.
by rewrite (addnC (n2 ^ 2)) (mulnC n2) distnC.
by rewrite distnEl ?sqrnB ?subnK ?nat_Cauchy.
Qed.
End Distn.
End IntDist.
Section NormInt.
Variable R : numDomainType.
Lemma intr_norm m : `|m|%:~R = `|m%:~R : R|.
Proof. by rewrite {2}[m]intEsign rmorphMsign normrMsign abszE normr_nat. Qed.
Lemma normrMz m (x : R) : `|x *~ m| = `|x| *~ `|m|.
Proof. by rewrite -mulrzl normrM -intr_norm mulrzl. Qed.
Lemma expN1r (i : int) : (-1 : R) ^ i = (-1) ^+ `|i|.
Proof.
case: i => n; first by rewrite exprnP absz_nat.
by rewrite NegzE abszN absz_nat -invr_expz expfV invrN1.
Qed.
End NormInt.
Section PolyZintRing.
Variable R : nzRingType.
Implicit Types x y z: R.
Implicit Types m n : int.
Implicit Types i j k : nat.
Implicit Types p q r : {poly R}.
Lemma coefMrz p n i : (p *~ n)`_i = (p`_i *~ n).
Proof. by case: n => n; rewrite ?NegzE (coefMNn, coefMn). Qed.
Lemma polyCMz n : {morph (@polyC R) : c / c *~ n}.
Proof. by case: (intP n) => // n' c; rewrite ?mulrNz ?polyCN polyCMn. Qed.
Lemma hornerMz n p x : (p *~ n).[x] = p.[x] *~ n.
Proof. by case: n => n; rewrite ?NegzE ?mulNzr ?(hornerN, hornerMn). Qed.
Lemma horner_int n x : (n%:~R : {poly R}).[x] = n%:~R.
Proof. by rewrite hornerMz hornerC. Qed.
Lemma derivMz n p : (p *~ n)^`() = p^`() *~ n.
Proof. by case: n => n; rewrite ?NegzE -?pmulrn (derivMn, derivMNn). Qed.
Lemma mulpz p n : p *~ n = n%:~R *: p.
Proof. by rewrite -mul_polyC polyCMz polyC1 mulrzl. Qed.
End PolyZintRing.
Section rpred.
Lemma rpredMz (M : zmodType) (S : zmodClosed M) m :
{in S, forall u, u *~ m \in S}.
Proof. by case: m => n u Su; rewrite ?rpredN ?rpredMn. Qed.
Lemma rpred_int (R : pzRingType) (S : subringClosed R) m : m%:~R \in S.
Proof. by rewrite rpredMz ?rpred1. Qed.
Lemma rpredZint (R : pzRingType) (M : lmodType R) (S : zmodClosed M) m :
{in S, forall u, m%:~R *: u \in S}.
Proof. by move=> u Su; rewrite /= scaler_int rpredMz. Qed.
Lemma rpredXz (R : unitRingType) (S : divClosed R) m :
{in S, forall x, x ^ m \in S}.
Proof. by case: m => n x Sx; rewrite ?rpredV rpredX. Qed.
Lemma rpredXsign (R : unitRingType) (S : divClosed R) n x :
(x ^ ((-1) ^+ n) \in S) = (x \in S).
Proof. by rewrite -signr_odd; case: (odd n); rewrite ?rpredV. Qed.
End rpred.
|
ReduceOption.lean
|
/-
Copyright (c) 2020 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky, Anthony DeRossi
-/
import Mathlib.Data.List.Basic
/-!
# Properties of `List.reduceOption`
In this file we prove basic lemmas about `List.reduceOption`.
-/
namespace List
variable {α β : Type*}
@[simp]
theorem reduceOption_cons_of_some (x : α) (l : List (Option α)) :
reduceOption (some x :: l) = x :: l.reduceOption := by
simp only [reduceOption, filterMap, id]
@[simp]
theorem reduceOption_cons_of_none (l : List (Option α)) :
reduceOption (none :: l) = l.reduceOption := by simp only [reduceOption, filterMap, id]
@[simp]
theorem reduceOption_nil : @reduceOption α [] = [] :=
rfl
@[simp]
theorem reduceOption_map {l : List (Option α)} {f : α → β} :
reduceOption (map (Option.map f) l) = map f (reduceOption l) := by
induction' l with hd tl hl
· simp only [reduceOption_nil, map_nil]
· cases hd <;>
simpa [Option.map_some, map, eq_self_iff_true, reduceOption_cons_of_some] using hl
theorem reduceOption_append (l l' : List (Option α)) :
(l ++ l').reduceOption = l.reduceOption ++ l'.reduceOption :=
filterMap_append
@[simp]
theorem reduceOption_replicate_none {n : ℕ} : (replicate n (@none α)).reduceOption = [] := by
dsimp [reduceOption]
rw [filterMap_replicate_of_none (id_def _)]
theorem reduceOption_eq_nil_iff (l : List (Option α)) :
l.reduceOption = [] ↔ ∃ n, l = replicate n none := by
dsimp [reduceOption]
rw [filterMap_eq_nil_iff]
constructor
· intro h
exact ⟨l.length, eq_replicate_of_mem h⟩
· intro ⟨_, h⟩
simp_rw [h, mem_replicate]
tauto
theorem reduceOption_eq_singleton_iff (l : List (Option α)) (a : α) :
l.reduceOption = [a] ↔ ∃ m n, l = replicate m none ++ some a :: replicate n none := by
dsimp [reduceOption]
constructor
· intro h
rw [filterMap_eq_cons_iff] at h
obtain ⟨l₁, _, l₂, h, hl₁, ⟨⟩, hl₂⟩ := h
rw [filterMap_eq_nil_iff] at hl₂
apply eq_replicate_of_mem at hl₁
apply eq_replicate_of_mem at hl₂
rw [h, hl₁, hl₂]
use l₁.length, l₂.length
· intro ⟨_, _, h⟩
simp only [h, filterMap_append, filterMap_cons_some, filterMap_replicate_of_none, id_eq,
nil_append, Option.some.injEq]
theorem reduceOption_eq_append_iff (l : List (Option α)) (l'₁ l'₂ : List α) :
l.reduceOption = l'₁ ++ l'₂ ↔
∃ l₁ l₂, l = l₁ ++ l₂ ∧ l₁.reduceOption = l'₁ ∧ l₂.reduceOption = l'₂ := by
dsimp [reduceOption]
exact filterMap_eq_append_iff
theorem reduceOption_eq_concat_iff (l : List (Option α)) (l' : List α) (a : α) :
l.reduceOption = l'.concat a ↔
∃ l₁ l₂, l = l₁ ++ some a :: l₂ ∧ l₁.reduceOption = l' ∧ l₂.reduceOption = [] := by
rw [concat_eq_append]
constructor
· intro h
rw [reduceOption_eq_append_iff] at h
obtain ⟨l₁, _, h, hl₁, hl₂⟩ := h
rw [reduceOption_eq_singleton_iff] at hl₂
obtain ⟨m, n, hl₂⟩ := hl₂
use l₁ ++ replicate m none, replicate n none
simp_rw [h, reduceOption_append, reduceOption_replicate_none, append_assoc, append_nil, hl₁,
hl₂, and_self]
· intro ⟨_, _, h, hl₁, hl₂⟩
rw [h, reduceOption_append, reduceOption_cons_of_some, hl₁, hl₂]
theorem reduceOption_length_eq {l : List (Option α)} :
l.reduceOption.length = (l.filter Option.isSome).length := by
induction' l with hd tl hl
· simp_rw [reduceOption_nil, filter_nil, length]
· cases hd <;> simp [hl]
theorem length_eq_reduceOption_length_add_filter_none {l : List (Option α)} :
l.length = l.reduceOption.length + (l.filter Option.isNone).length := by
simp_rw [reduceOption_length_eq, l.length_eq_length_filter_add Option.isSome, Option.not_isSome]
theorem reduceOption_length_le (l : List (Option α)) : l.reduceOption.length ≤ l.length := by
rw [length_eq_reduceOption_length_add_filter_none]
apply Nat.le_add_right
theorem reduceOption_length_eq_iff {l : List (Option α)} :
l.reduceOption.length = l.length ↔ ∀ x ∈ l, Option.isSome x := by
rw [reduceOption_length_eq, List.length_filter_eq_length_iff]
theorem reduceOption_length_lt_iff {l : List (Option α)} :
l.reduceOption.length < l.length ↔ none ∈ l := by
rw [Nat.lt_iff_le_and_ne, and_iff_right (reduceOption_length_le l), Ne,
reduceOption_length_eq_iff]
induction l <;> simp
rw [@eq_comm _ none, ← Option.not_isSome_iff_eq_none, Decidable.imp_iff_not_or]
theorem reduceOption_singleton (x : Option α) : [x].reduceOption = x.toList := by cases x <;> rfl
theorem reduceOption_concat (l : List (Option α)) (x : Option α) :
(l.concat x).reduceOption = l.reduceOption ++ x.toList := by
induction' l with hd tl hl generalizing x
· cases x <;> simp [Option.toList]
· simp only [concat_eq_append, reduceOption_append] at hl
cases hd <;> simp [hl, reduceOption_append]
theorem reduceOption_concat_of_some (l : List (Option α)) (x : α) :
(l.concat (some x)).reduceOption = l.reduceOption.concat x := by
simp only [reduceOption_nil, concat_eq_append, reduceOption_append, reduceOption_cons_of_some]
theorem reduceOption_mem_iff {l : List (Option α)} {x : α} : x ∈ l.reduceOption ↔ some x ∈ l := by
simp only [reduceOption, id, mem_filterMap, exists_eq_right]
theorem reduceOption_getElem?_iff {l : List (Option α)} {x : α} :
(∃ i : ℕ, l[i]? = some (some x)) ↔ ∃ i : ℕ, l.reduceOption[i]? = some x := by
rw [← mem_iff_getElem?, ← mem_iff_getElem?, reduceOption_mem_iff]
@[deprecated (since := "2025-02-21")]
alias reduceOption_get?_iff := reduceOption_getElem?_iff
end List
|
Defs.lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker, Yaël Dillies
-/
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Logic.Basic
/-!
# Irreducible elements in a monoid
This file defines irreducible elements of a monoid (`Irreducible`), as non-units that can't be
written as the product of two non-units. This generalises irreducible elements of a ring.
We also define the additive variant (`AddIrreducible`).
In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Prime`
(see `irreducible_iff_prime`), however this is not true in general.
-/
assert_not_exists MonoidWithZero OrderedCommMonoid Multiset
variable {M : Type*}
/-- `AddIrreducible p` states that `p` is not an additive unit and cannot be written as a sum of
additive non-units. -/
structure AddIrreducible [AddMonoid M] (p : M) : Prop where
/-- An irreducible element is not an additive unit. -/
not_isAddUnit : ¬IsAddUnit p
/-- If an irreducible element can be written as a sum, then one term is an additive unit. -/
isAddUnit_or_isAddUnit ⦃a b⦄ : p = a + b → IsAddUnit a ∨ IsAddUnit b
section Monoid
variable [Monoid M] {p q a b : M}
/-- `Irreducible p` states that `p` is non-unit and only factors into units.
We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a
monoid allows us to reuse irreducible for associated elements. -/
@[to_additive]
structure Irreducible (p : M) : Prop where
/-- An irreducible element is not a unit. -/
not_isUnit : ¬IsUnit p
/-- If an irreducible element factors, then one factor is a unit. -/
isUnit_or_isUnit ⦃a b : M⦄ : p = a * b → IsUnit a ∨ IsUnit b
namespace Irreducible
@[deprecated (since := "2025-04-09")] alias not_unit := not_isUnit
@[deprecated (since := "2025-04-10")] alias isUnit_or_isUnit' := isUnit_or_isUnit
end Irreducible
@[to_additive] lemma irreducible_iff :
Irreducible p ↔ ¬IsUnit p ∧ ∀ ⦃a b⦄, p = a * b → IsUnit a ∨ IsUnit b where
mp hp := ⟨hp.not_isUnit, hp.isUnit_or_isUnit⟩
mpr hp := ⟨hp.1, hp.2⟩
@[to_additive (attr := simp)]
lemma not_irreducible_one : ¬Irreducible (1 : M) := by simp [irreducible_iff]
@[to_additive]
lemma Irreducible.ne_one (hp : Irreducible p) : p ≠ 1 := by rintro rfl; exact not_irreducible_one hp
@[to_additive]
lemma of_irreducible_mul : Irreducible (a * b) → IsUnit a ∨ IsUnit b | ⟨_, h⟩ => h rfl
@[to_additive]
lemma irreducible_or_factor (hp : ¬IsUnit p) :
Irreducible p ∨ ∃ a b, ¬IsUnit a ∧ ¬IsUnit b ∧ p = a * b := by
simpa [irreducible_iff, hp, and_rotate] using em (∀ a b, p = a * b → IsUnit a ∨ IsUnit b)
@[to_additive]
lemma Irreducible.eq_one_or_eq_one [Subsingleton Mˣ] (hab : Irreducible (a * b)) :
a = 1 ∨ b = 1 := by simpa using hab.isUnit_or_isUnit rfl
end Monoid
|
action.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun ssrnotations eqtype.
From mathcomp Require Import ssrnat div seq prime fintype bigop finset.
From mathcomp Require Import fingroup morphism perm automorphism quotient.
(******************************************************************************)
(* Group action: orbits, stabilisers, transitivity. *)
(* is_action D to == the function to : T -> aT -> T defines an action *)
(* of D : {set aT} on T. *)
(* action D T == structure for a function defining an action of D. *)
(* act_dom to == the domain D of to : action D rT. *)
(* {action: aT &-> T} == structure for a total action. *)
(* := action [set: aT] T *)
(* TotalAction to1 toM == the constructor for total actions; to1 and toM *)
(* are the proofs of the action identities for 1 and *)
(* a * b, respectively. *)
(* is_groupAction R to == to is a group action on range R: for all a in D, *)
(* the permutation induced by to a is in Aut R. Thus *)
(* the action of D must be trivial outside R. *)
(* groupAction D R == the structure for group actions of D on R. This *)
(* is a telescope on action D rT. *)
(* gact_range to == the range R of to : groupAction D R. *)
(* GroupAction toAut == constructs a groupAction for action to from *)
(* toAut : actm to @* D \subset Aut R (actm to is *)
(* the morphism to {perm rT} associated to 'to'). *)
(* orbit to A x == the orbit of x under the action of A via to. *)
(* orbit_transversal to A S == a transversal of the partition orbit to A @: S *)
(* of S, provided A acts on S via to. *)
(* amove to A x y == the set of a in A whose action sends x to y. *)
(* 'C_A[x | to] == the stabiliser of x : rT in A :&: D. *)
(* 'C_A(S | to) == the pointwise stabiliser of S : {set rT} in D :&: A. *)
(* 'N_A(S | to) == the global stabiliser of S : {set rT} in D :&: A. *)
(* 'Fix_(S | to)[a] == the set of fixpoints of a in S. *)
(* 'Fix_(S | to)(A) == the set of fixpoints of A in S. *)
(* In the first three _A can be omitted and defaults to the domain D of to; *)
(* in the last two S can be omitted and defaults to [set: T], so 'Fix_to[a] *)
(* is the set of all fixpoints of a. *)
(* The domain restriction ensures that stabilisers have a canonical group *)
(* structure, but note that 'Fix sets are generally not groups. Indeed, we *)
(* provide alternative definitions when to is a group action on R: *)
(* 'C_(G | to)(A) == the centraliser in R :&: G of the group action of *)
(* D :&: A via to *)
(* 'C_(G | to)[a] == the centraliser in R :&: G of a \in D, via to. *)
(* These sets are groups when G is; G can be omitted: 'C(|to)(A) is the *)
(* centraliser in R of the action of D :&: A via to. *)
(* [acts A, on S | to] == A \subset D acts on the set S via to. *)
(* {acts A, on S | to} == A acts on the set S (Prop statement). *)
(* {acts A, on group G | to} == [acts A, on S | to] /\ G \subset R, i.e., *)
(* A \subset D acts on G \subset R, via *)
(* to : groupAction D R. *)
(* [transitive A, on S | to] == A acts transitively on S. *)
(* [faithful A, on S | to] == A acts faithfully on S. *)
(* acts_irreducibly to A G == A acts irreducibly via the groupAction to *)
(* on the nontrivial group G, i.e., A does *)
(* not act on any nontrivial subgroup of G. *)
(* Important caveat: the definitions of orbit, amove, 'Fix_(S | to)(A), *)
(* transitive and faithful assume that A is a subset of the domain D. As most *)
(* of the permutation actions we consider are total this is usually harmless. *)
(* (Note that the theory of partial actions is only partially developed.) *)
(* In all of the above, to is expected to be the actual action structure, *)
(* not merely the function. There is a special scope %act for actions, and *)
(* constructions and notations for many classical actions: *)
(* 'P == natural action of a permutation group via aperm. *)
(* 'J == internal group action (conjugation) via conjg (_ ^ _). *)
(* 'R == regular group action (right translation) via mulg (_ * _). *)
(* (However, to limit ambiguity, _ * _ is NOT a canonical action.) *)
(* to^* == the action induced by to on {set rT} via to^* (== setact to). *)
(* 'Js == the internal action on subsets via _ :^ _, equivalent to 'J^*. *)
(* 'Rs == the regular action on subsets via rcoset, equivalent to 'R^*. *)
(* 'JG == the conjugation action on {group rT} via (_ :^ _)%G. *)
(* to / H == the action induced by to on coset_of H via qact to H, and *)
(* restricted to (qact_dom to H) == 'N(rcosets H 'N(H) | to^* ). *)
(* 'Q == the action induced to cosets by conjugation; the domain is *)
(* qact_dom 'J H, which is provably equal to 'N(H). *)
(* to %% A == the action of coset_of A via modact to A, with domain D / A *)
(* and support restricted to 'C(D :&: A | to). *)
(* to \ sAD == the action of A via ract to sAD == to, if sAD : A \subset D. *)
(* [Aut G] == the permutation action restricted to Aut G, via autact G. *)
(* <[nRA]> == the action of A on R via actby nRA == to in A and on R, and *)
(* the trivial action elsewhere; here nRA : [acts A, on R | to] *)
(* or nRA : {acts A, on group R | to}. *)
(* to^? == the action induced by to on sT : @subType rT P, via subact to *)
(* with domain subact_dom P to == 'N([set x | P x] | to). *)
(* <<phi>> == the action of phi : D >-> {perm rT}, via mact phi. *)
(* to \o f == the composite action (with domain f @*^-1 D) of the action to *)
(* with f : {morphism G >-> aT}, via comp_act to f. Here f must *)
(* be the actual morphism object (e.g., coset_morphism H), not *)
(* the underlying function (e.g., coset H). *)
(* The explicit application of an action to is usually written (to%act x a), *)
(* but %act can be omitted if to is an abstract action or a set action to^*. *)
(* Note that this form will simplify and expose the acting function. *)
(* There is a %gact scope for group actions; the notations above are *)
(* recognised in %gact when they denote canonical group actions. *)
(* Actions can be used to define morphisms: *)
(* actperm to == the morphism D >-> {perm rT} induced by to. *)
(* actm to a == if a \in D the function on D induced by the action to, else *)
(* the identity function. If to is a group action with range R *)
(* then actm to a is canonically a morphism on R. *)
(* We also define here the restriction operation on permutations (the domain *)
(* of this operations is a stabiliser), and local automorphism groups: *)
(* restr_perm S p == if p acts on S, the permutation with support in S that *)
(* coincides with p on S; else the identity. Note that *)
(* restr_perm is a permutation group morphism that maps *)
(* Aut G to Aut S when S is a subgroup of G. *)
(* Aut_in A G == the local permutation group 'N_A(G | 'P) / 'C_A(G | 'P) *)
(* Usually A is an automorphism group, and then Aut_in A G *)
(* is isomorphic to a subgroup of Aut G, specifically *)
(* restr_perm @* A. *)
(* Finally, gproduct.v will provide a semi-direct group construction that *)
(* maps an external group action to an internal one; the theory of morphisms *)
(* between such products makes use of the following definition: *)
(* morph_act to to' f fA <=> the action of to' on the images of f and fA is *)
(* the image of the action of to, i.e., for all x and a we *)
(* have f (to x a) = to' (f x) (fA a). Note that there is *)
(* no mention of the domains of to and to'; if needed, this *)
(* predicate should be restricted via the {in ...} notation *)
(* and domain conditions should be added. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope action_scope.
Declare Scope groupAction_scope.
Import GroupScope.
Section ActionDef.
Variables (aT : finGroupType) (D : {set aT}) (rT : Type).
Implicit Types a b : aT.
Implicit Type x : rT.
Definition act_morph to x := forall a b, to x (a * b) = to (to x a) b.
Definition is_action to :=
left_injective to /\ forall x, {in D &, act_morph to x}.
Record action := Action {act :> rT -> aT -> rT; _ : is_action act}.
Definition clone_action to :=
let: Action _ toP := to return {type of Action for to} -> action in
fun k => k toP.
End ActionDef.
(* Need to close the Section here to avoid re-declaring all Argument Scopes *)
Delimit Scope action_scope with act.
Bind Scope action_scope with action.
Arguments act_morph {aT rT%_type} to x%_g.
Arguments is_action {aT} D%_g {rT} to.
Arguments act {aT D%_g rT%_type} to%_act x%_g a%_g : rename.
Arguments clone_action [aT D%_g rT%_type to%_act] _.
Notation "{ 'action' aT &-> T }" := (action [set: aT] T)
(format "{ 'action' aT &-> T }") : type_scope.
Notation "[ 'action' 'of' to ]" := (clone_action (@Action _ _ _ to))
(format "[ 'action' 'of' to ]") : form_scope.
Definition act_dom aT D rT of @action aT D rT := D.
Section TotalAction.
Variables (aT : finGroupType) (rT : Type) (to : rT -> aT -> rT).
Hypotheses (to1 : to^~ 1 =1 id) (toM : forall x, act_morph to x).
Lemma is_total_action : is_action setT to.
Proof.
split=> [a | x a b _ _] /=; last by rewrite toM.
by apply: can_inj (to^~ a^-1) _ => x; rewrite -toM ?mulgV.
Qed.
Definition TotalAction := Action is_total_action.
End TotalAction.
Section ActionDefs.
Variables (aT aT' : finGroupType) (D : {set aT}) (D' : {set aT'}).
Definition morph_act rT rT' (to : action D rT) (to' : action D' rT') f fA :=
forall x a, f (to x a) = to' (f x) (fA a).
Variable rT : finType. (* Most definitions require a finType structure on rT *)
Implicit Type to : action D rT.
Implicit Type A : {set aT}.
Implicit Type S : {set rT}.
Definition actm to a := if a \in D then to^~ a else id.
Definition setact to S a := [set to x a | x in S].
Definition orbit to A x := to x @: A.
Definition amove to A x y := [set a in A | to x a == y].
Definition afix to A := [set x | A \subset [set a | to x a == x]].
Definition astab S to := D :&: [set a | S \subset [set x | to x a == x]].
Definition astabs S to := D :&: [set a | S \subset to^~ a @^-1: S].
Definition acts_on A S to := {in A, forall a x, (to x a \in S) = (x \in S)}.
Definition atrans A S to := S \in orbit to A @: S.
Definition faithful A S to := A :&: astab S to \subset [1].
End ActionDefs.
Arguments setact {aT D%_g rT} to%_act S%_g a%_g.
Arguments orbit {aT D%_g rT} to%_act A%_g x%_g.
Arguments amove {aT D%_g rT} to%_act A%_g x%_g y%_g.
Arguments afix {aT D%_g rT} to%_act A%_g.
Arguments astab {aT D%_g rT} S%_g to%_act.
Arguments astabs {aT D%_g rT} S%_g to%_act.
Arguments acts_on {aT D%_g rT} A%_g S%_g to%_act.
Arguments atrans {aT D%_g rT} A%_g S%_g to%_act.
Arguments faithful {aT D%_g rT} A%_g S%_g to%_act.
Notation "to ^*" := (setact to) : function_scope.
Prenex Implicits orbit amove.
Notation "''Fix_' to ( A )" := (afix to A)
(to at level 2, format "''Fix_' to ( A )") : group_scope.
(* camlp4 grammar factoring *)
Notation "''Fix_' ( to ) ( A )" := 'Fix_to(A) (only parsing) : group_scope.
Notation "''Fix_' ( S | to ) ( A )" := (S :&: 'Fix_to(A))
(format "''Fix_' ( S | to ) ( A )") : group_scope.
Notation "''Fix_' to [ a ]" := ('Fix_to([set a]))
(to at level 2, format "''Fix_' to [ a ]") : group_scope.
Notation "''Fix_' ( S | to ) [ a ]" := (S :&: 'Fix_to[a])
(format "''Fix_' ( S | to ) [ a ]") : group_scope.
Notation "''C' ( S | to )" := (astab S to) : group_scope.
Notation "''C_' A ( S | to )" := (A :&: 'C(S | to)) : group_scope.
Notation "''C_' ( A ) ( S | to )" := 'C_A(S | to) (only parsing) : group_scope.
Notation "''C' [ x | to ]" := ('C([set x] | to)) : group_scope.
Notation "''C_' A [ x | to ]" := (A :&: 'C[x | to]) : group_scope.
Notation "''C_' ( A ) [ x | to ]" := 'C_A[x | to] (only parsing) : group_scope.
Notation "''N' ( S | to )" := (astabs S to)
(format "''N' ( S | to )") : group_scope.
Notation "''N_' A ( S | to )" := (A :&: 'N(S | to))
(A at level 2, format "''N_' A ( S | to )") : group_scope.
Notation "[ 'acts' A , 'on' S | to ]" := (A \subset pred_of_set 'N(S | to))
(format "[ 'acts' A , 'on' S | to ]") : form_scope.
Notation "{ 'acts' A , 'on' S | to }" := (acts_on A S to)
(format "{ 'acts' A , 'on' S | to }") : type_scope.
Notation "[ 'transitive' A , 'on' S | to ]" := (atrans A S to)
(format "[ 'transitive' A , 'on' S | to ]") : form_scope.
Notation "[ 'faithful' A , 'on' S | to ]" := (faithful A S to)
(format "[ 'faithful' A , 'on' S | to ]") : form_scope.
Section RawAction.
(* Lemmas that do not require the group structure on the action domain. *)
(* Some lemmas like actMin would be actually be valid for arbitrary rT, *)
(* e.g., for actions on a function type, but would be difficult to use *)
(* as a view due to the confusion between parameters and assumptions. *)
Variables (aT : finGroupType) (D : {set aT}) (rT : finType) (to : action D rT).
Implicit Types (a : aT) (x y : rT) (A B : {set aT}) (S T : {set rT}).
Lemma act_inj : left_injective to. Proof. by case: to => ? []. Qed.
Arguments act_inj : clear implicits.
Lemma actMin x : {in D &, act_morph to x}.
Proof. by case: to => ? []. Qed.
Lemma actmEfun a : a \in D -> actm to a = to^~ a.
Proof. by rewrite /actm => ->. Qed.
Lemma actmE a : a \in D -> actm to a =1 to^~ a.
Proof. by move=> Da; rewrite actmEfun. Qed.
Lemma setactE S a : to^* S a = [set to x a | x in S].
Proof. by []. Qed.
Lemma mem_setact S a x : x \in S -> to x a \in to^* S a.
Proof. exact: imset_f. Qed.
Lemma card_setact S a : #|to^* S a| = #|S|.
Proof. by apply: card_imset; apply: act_inj. Qed.
Lemma setact_is_action : is_action D to^*.
Proof.
split=> [a R S eqRS | a b Da Db S]; last first.
by rewrite /setact /= -imset_comp; apply: eq_imset => x; apply: actMin.
apply/setP=> x; apply/idP/idP=> /(mem_setact a).
by rewrite eqRS => /imsetP[y Sy /act_inj->].
by rewrite -eqRS => /imsetP[y Sy /act_inj->].
Qed.
Canonical set_action := Action setact_is_action.
Lemma orbitE A x : orbit to A x = to x @: A. Proof. by []. Qed.
Lemma orbitP A x y :
reflect (exists2 a, a \in A & to x a = y) (y \in orbit to A x).
Proof. by apply: (iffP imsetP) => [] [a]; exists a. Qed.
Lemma mem_orbit A x a : a \in A -> to x a \in orbit to A x.
Proof. exact: imset_f. Qed.
Lemma afixP A x : reflect (forall a, a \in A -> to x a = x) (x \in 'Fix_to(A)).
Proof.
rewrite inE; apply: (iffP subsetP) => [xfix a /xfix | xfix a Aa].
by rewrite inE => /eqP.
by rewrite inE xfix.
Qed.
Lemma afixS A B : A \subset B -> 'Fix_to(B) \subset 'Fix_to(A).
Proof. by move=> sAB; apply/subsetP=> u /[!inE]; apply: subset_trans. Qed.
Lemma afixU A B : 'Fix_to(A :|: B) = 'Fix_to(A) :&: 'Fix_to(B).
Proof. by apply/setP=> x; rewrite !inE subUset. Qed.
Lemma afix1P a x : reflect (to x a = x) (x \in 'Fix_to[a]).
Proof. by rewrite inE sub1set inE; apply: eqP. Qed.
Lemma astabIdom S : 'C_D(S | to) = 'C(S | to).
Proof. by rewrite setIA setIid. Qed.
Lemma astab_dom S : {subset 'C(S | to) <= D}.
Proof. by move=> a /setIP[]. Qed.
Lemma astab_act S a x : a \in 'C(S | to) -> x \in S -> to x a = x.
Proof.
rewrite 2!inE => /andP[_ cSa] Sx; apply/eqP.
by have /[1!inE] := subsetP cSa x Sx.
Qed.
Lemma astabS S1 S2 : S1 \subset S2 -> 'C(S2 | to) \subset 'C(S1 | to).
Proof.
by move=> sS12; apply/subsetP=> x /[!inE] /andP[->]; apply: subset_trans.
Qed.
Lemma astabsIdom S : 'N_D(S | to) = 'N(S | to).
Proof. by rewrite setIA setIid. Qed.
Lemma astabs_dom S : {subset 'N(S | to) <= D}.
Proof. by move=> a /setIdP[]. Qed.
Lemma astabs_act S a x : a \in 'N(S | to) -> (to x a \in S) = (x \in S).
Proof.
rewrite 2!inE subEproper properEcard => /andP[_].
rewrite (card_preimset _ (act_inj _)) ltnn andbF orbF => /eqP{2}->.
by rewrite inE.
Qed.
Lemma astab_sub S : 'C(S | to) \subset 'N(S | to).
Proof.
apply/subsetP=> a cSa; rewrite !inE (astab_dom cSa).
by apply/subsetP=> x Sx; rewrite inE (astab_act cSa).
Qed.
Lemma astabsC S : 'N(~: S | to) = 'N(S | to).
Proof.
apply/setP=> a; apply/idP/idP=> nSa; rewrite !inE (astabs_dom nSa).
by rewrite -setCS -preimsetC; apply/subsetP=> x; rewrite inE astabs_act.
by rewrite preimsetC setCS; apply/subsetP=> x; rewrite inE astabs_act.
Qed.
Lemma astabsI S T : 'N(S | to) :&: 'N(T | to) \subset 'N(S :&: T | to).
Proof.
apply/subsetP=> a; rewrite !inE -!andbA preimsetI => /and4P[-> nSa _ nTa] /=.
by rewrite setISS.
Qed.
Lemma astabs_setact S a : a \in 'N(S | to) -> to^* S a = S.
Proof.
move=> nSa; apply/eqP; rewrite eqEcard card_setact leqnn andbT.
by apply/subsetP=> _ /imsetP[x Sx ->]; rewrite astabs_act.
Qed.
Lemma astab1_set S : 'C[S | set_action] = 'N(S | to).
Proof.
apply/setP=> a; apply/idP/idP=> nSa.
case/setIdP: nSa => Da; rewrite !inE Da sub1set inE => /eqP defS.
by apply/subsetP=> x Sx; rewrite inE -defS mem_setact.
by rewrite !inE (astabs_dom nSa) sub1set inE /= astabs_setact.
Qed.
Lemma astabs_set1 x : 'N([set x] | to) = 'C[x | to].
Proof.
apply/eqP; rewrite eqEsubset astab_sub andbC setIS //.
by apply/subsetP=> a; rewrite ?(inE,sub1set).
Qed.
Lemma acts_dom A S : [acts A, on S | to] -> A \subset D.
Proof. by move=> nSA; rewrite (subset_trans nSA) ?subsetIl. Qed.
Lemma acts_act A S : [acts A, on S | to] -> {acts A, on S | to}.
Proof. by move=> nAS a Aa x; rewrite astabs_act ?(subsetP nAS). Qed.
Lemma astabCin A S :
A \subset D -> (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)).
Proof.
move=> sAD; apply/subsetP/subsetP=> [sAC x xS | sSF a aA].
by apply/afixP=> a aA; apply: astab_act (sAC _ aA) xS.
rewrite !inE (subsetP sAD _ aA); apply/subsetP=> x xS.
by move/afixP/(_ _ aA): (sSF _ xS) => /[1!inE] ->.
Qed.
Section ActsSetop.
Variables (A : {set aT}) (S T : {set rT}).
Hypotheses (AactS : [acts A, on S | to]) (AactT : [acts A, on T | to]).
Lemma astabU : 'C(S :|: T | to) = 'C(S | to) :&: 'C(T | to).
Proof. by apply/setP=> a; rewrite !inE subUset; case: (a \in D). Qed.
Lemma astabsU : 'N(S | to) :&: 'N(T | to) \subset 'N(S :|: T | to).
Proof.
by rewrite -(astabsC S) -(astabsC T) -(astabsC (S :|: T)) setCU astabsI.
Qed.
Lemma astabsD : 'N(S | to) :&: 'N(T | to) \subset 'N(S :\: T| to).
Proof. by rewrite setDE -(astabsC T) astabsI. Qed.
Lemma actsI : [acts A, on S :&: T | to].
Proof. by apply: subset_trans (astabsI S T); rewrite subsetI AactS. Qed.
Lemma actsU : [acts A, on S :|: T | to].
Proof. by apply: subset_trans astabsU; rewrite subsetI AactS. Qed.
Lemma actsD : [acts A, on S :\: T | to].
Proof. by apply: subset_trans astabsD; rewrite subsetI AactS. Qed.
End ActsSetop.
Lemma acts_in_orbit A S x y :
[acts A, on S | to] -> y \in orbit to A x -> x \in S -> y \in S.
Proof.
by move=> nSA/imsetP[a Aa ->{y}] Sx; rewrite (astabs_act _ (subsetP nSA a Aa)).
Qed.
Lemma subset_faithful A B S :
B \subset A -> [faithful A, on S | to] -> [faithful B, on S | to].
Proof. by move=> sAB; apply: subset_trans; apply: setSI. Qed.
Section Reindex.
Variables (vT : Type) (idx : vT) (op : Monoid.com_law idx) (S : {set rT}).
Lemma reindex_astabs a F : a \in 'N(S | to) ->
\big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a).
Proof.
move=> nSa; rewrite (reindex_inj (act_inj a)); apply: eq_bigl => x.
exact: astabs_act.
Qed.
Lemma reindex_acts A a F : [acts A, on S | to] -> a \in A ->
\big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a).
Proof. by move=> nSA /(subsetP nSA); apply: reindex_astabs. Qed.
End Reindex.
End RawAction.
Arguments act_inj {aT D rT} to a [x1 x2] : rename.
Notation "to ^*" := (set_action to) : action_scope.
Arguments orbitP {aT D rT to A x y}.
Arguments afixP {aT D rT to A x}.
Arguments afix1P {aT D rT to a x}.
Arguments reindex_astabs [aT D rT] to [vT idx op S] a [F].
Arguments reindex_acts [aT D rT] to [vT idx op S A a F].
Section PartialAction.
(* Lemmas that require a (partial) group domain. *)
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable to : action D rT.
Implicit Types a : aT.
Implicit Types x y : rT.
Implicit Types A B : {set aT}.
Implicit Types G H : {group aT}.
Implicit Types S : {set rT}.
Lemma act1 x : to x 1 = x.
Proof. by apply: (act_inj to 1); rewrite -actMin ?mulg1. Qed.
Lemma actKin : {in D, right_loop invg to}.
Proof. by move=> a Da /= x; rewrite -actMin ?groupV // mulgV act1. Qed.
Lemma actKVin : {in D, rev_right_loop invg to}.
Proof. by move=> a Da /= x; rewrite -{2}(invgK a) actKin ?groupV. Qed.
Lemma setactVin S a : a \in D -> to^* S a^-1 = to^~ a @^-1: S.
Proof.
by move=> Da; apply: can2_imset_pre; [apply: actKVin | apply: actKin].
Qed.
Lemma actXin x a i : a \in D -> to x (a ^+ i) = iter i (to^~ a) x.
Proof.
move=> Da; elim: i => /= [|i <-]; first by rewrite act1.
by rewrite expgSr actMin ?groupX.
Qed.
Lemma afix1 : 'Fix_to(1) = setT.
Proof. by apply/setP=> x; rewrite !inE sub1set inE act1 eqxx. Qed.
Lemma afixD1 G : 'Fix_to(G^#) = 'Fix_to(G).
Proof. by rewrite -{2}(setD1K (group1 G)) afixU afix1 setTI. Qed.
Lemma orbit_refl G x : x \in orbit to G x.
Proof. by rewrite -{1}[x]act1 mem_orbit. Qed.
Local Notation orbit_rel A := (fun x y => x \in orbit to A y).
Lemma contra_orbit G x y : x \notin orbit to G y -> x != y.
Proof. by apply: contraNneq => ->; apply: orbit_refl. Qed.
Lemma orbit_in_sym G : G \subset D -> symmetric (orbit_rel G).
Proof.
move=> sGD; apply: symmetric_from_pre => x y /imsetP[a Ga].
by move/(canLR (actKin (subsetP sGD a Ga))) <-; rewrite mem_orbit ?groupV.
Qed.
Lemma orbit_in_trans G : G \subset D -> transitive (orbit_rel G).
Proof.
move=> sGD _ _ z /imsetP[a Ga ->] /imsetP[b Gb ->].
by rewrite -actMin ?mem_orbit ?groupM // (subsetP sGD).
Qed.
Lemma orbit_in_eqP G x y :
G \subset D -> reflect (orbit to G x = orbit to G y) (x \in orbit to G y).
Proof.
move=> sGD; apply: (iffP idP) => [yGx|<-]; last exact: orbit_refl.
by apply/setP=> z; apply/idP/idP=> /orbit_in_trans-> //; rewrite orbit_in_sym.
Qed.
Lemma orbit_in_transl G x y z :
G \subset D -> y \in orbit to G x ->
(y \in orbit to G z) = (x \in orbit to G z).
Proof.
by move=> sGD Gxy; rewrite !(orbit_in_sym sGD _ z) (orbit_in_eqP y x sGD Gxy).
Qed.
Lemma orbit_act_in x a G :
G \subset D -> a \in G -> orbit to G (to x a) = orbit to G x.
Proof. by move=> sGD /mem_orbit/orbit_in_eqP->. Qed.
Lemma orbit_actr_in x a G y :
G \subset D -> a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x).
Proof. by move=> sGD /mem_orbit/orbit_in_transl->. Qed.
Lemma orbit_inv_in A x y :
A \subset D -> (y \in orbit to A^-1 x) = (x \in orbit to A y).
Proof.
move/subsetP=> sAD; apply/imsetP/imsetP=> [] [a Aa ->].
by exists a^-1; rewrite -?mem_invg ?actKin // -groupV sAD -?mem_invg.
by exists a^-1; rewrite ?memV_invg ?actKin // sAD.
Qed.
Lemma orbit_lcoset_in A a x :
A \subset D -> a \in D ->
orbit to (a *: A) x = orbit to A (to x a).
Proof.
move/subsetP=> sAD Da; apply/setP=> y; apply/imsetP/imsetP=> [] [b Ab ->{y}].
by exists (a^-1 * b); rewrite -?actMin ?mulKVg // ?sAD -?mem_lcoset.
by exists (a * b); rewrite ?mem_mulg ?set11 ?actMin // sAD.
Qed.
Lemma orbit_rcoset_in A a x y :
A \subset D -> a \in D ->
(to y a \in orbit to (A :* a) x) = (y \in orbit to A x).
Proof.
move=> sAD Da; rewrite -orbit_inv_in ?mul_subG ?sub1set // invMg.
by rewrite invg_set1 orbit_lcoset_in ?inv_subG ?groupV ?actKin ?orbit_inv_in.
Qed.
Lemma orbit_conjsg_in A a x y :
A \subset D -> a \in D ->
(to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x).
Proof.
move=> sAD Da; rewrite conjsgE.
by rewrite orbit_lcoset_in ?groupV ?mul_subG ?sub1set ?actKin ?orbit_rcoset_in.
Qed.
Lemma orbit1P G x : reflect (orbit to G x = [set x]) (x \in 'Fix_to(G)).
Proof.
apply: (iffP afixP) => [xfix | xfix a Ga].
apply/eqP; rewrite eq_sym eqEsubset sub1set -{1}[x]act1 imset_f //=.
by apply/subsetP=> y; case/imsetP=> a Ga ->; rewrite inE xfix.
by apply/set1P; rewrite -xfix imset_f.
Qed.
Lemma card_orbit1 G x : #|orbit to G x| = 1%N -> orbit to G x = [set x].
Proof.
move=> orb1; apply/eqP; rewrite eq_sym eqEcard {}orb1 cards1.
by rewrite sub1set orbit_refl.
Qed.
Lemma orbit_partition G S :
[acts G, on S | to] -> partition (orbit to G @: S) S.
Proof.
move=> actsGS; have sGD := acts_dom actsGS.
have eqiG: {in S & &, equivalence_rel [rel x y | y \in orbit to G x]}.
by move=> x y z * /=; rewrite orbit_refl; split=> // /orbit_in_eqP->.
congr (partition _ _): (equivalence_partitionP eqiG).
apply: eq_in_imset => x Sx; apply/setP=> y.
by rewrite inE /= andb_idl // => /acts_in_orbit->.
Qed.
Definition orbit_transversal A S := transversal (orbit to A @: S) S.
Lemma orbit_transversalP G S (P := orbit to G @: S)
(X := orbit_transversal G S) :
[acts G, on S | to] ->
[/\ is_transversal X P S, X \subset S,
{in X &, forall x y, (y \in orbit to G x) = (x == y)}
& forall x, x \in S -> exists2 a, a \in G & to x a \in X].
Proof.
move/orbit_partition; rewrite -/P => partP.
have [/eqP defS tiP _] := and3P partP.
have trXP: is_transversal X P S := transversalP partP.
have sXS: X \subset S := transversal_sub trXP.
split=> // [x y Xx Xy /= | x Sx].
have Sx := subsetP sXS x Xx.
rewrite -(inj_in_eq (pblock_inj trXP)) // eq_pblock ?defS //.
by rewrite (def_pblock tiP (imset_f _ Sx)) ?orbit_refl.
have /imsetP[y Xy defxG]: orbit to G x \in pblock P @: X.
by rewrite (pblock_transversal trXP) ?imset_f.
suffices /orbitP[a Ga def_y]: y \in orbit to G x by exists a; rewrite ?def_y.
by rewrite defxG mem_pblock defS (subsetP sXS).
Qed.
Lemma group_set_astab S : group_set 'C(S | to).
Proof.
apply/group_setP; split=> [|a b cSa cSb].
by rewrite !inE group1; apply/subsetP=> x _; rewrite inE act1.
rewrite !inE groupM ?(@astab_dom _ _ _ to S) //; apply/subsetP=> x Sx.
by rewrite inE actMin ?(@astab_dom _ _ _ to S) ?(astab_act _ Sx).
Qed.
Canonical astab_group S := group (group_set_astab S).
Lemma afix_gen_in A : A \subset D -> 'Fix_to(<<A>>) = 'Fix_to(A).
Proof.
move=> sAD; apply/eqP; rewrite eqEsubset afixS ?sub_gen //=.
by rewrite -astabCin gen_subG ?astabCin.
Qed.
Lemma afix_cycle_in a : a \in D -> 'Fix_to(<[a]>) = 'Fix_to[a].
Proof. by move=> Da; rewrite afix_gen_in ?sub1set. Qed.
Lemma afixYin A B :
A \subset D -> B \subset D -> 'Fix_to(A <*> B) = 'Fix_to(A) :&: 'Fix_to(B).
Proof. by move=> sAD sBD; rewrite afix_gen_in ?afixU // subUset sAD. Qed.
Lemma afixMin G H :
G \subset D -> H \subset D -> 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H).
Proof.
by move=> sGD sHD; rewrite -afix_gen_in ?mul_subG // genM_join afixYin.
Qed.
Lemma sub_astab1_in A x :
A \subset D -> (A \subset 'C[x | to]) = (x \in 'Fix_to(A)).
Proof. by move=> sAD; rewrite astabCin ?sub1set. Qed.
Lemma group_set_astabs S : group_set 'N(S | to).
Proof.
apply/group_setP; split=> [|a b cSa cSb].
by rewrite !inE group1; apply/subsetP=> x Sx; rewrite inE act1.
rewrite !inE groupM ?(@astabs_dom _ _ _ to S) //; apply/subsetP=> x Sx.
by rewrite inE actMin ?(@astabs_dom _ _ _ to S) ?astabs_act.
Qed.
Canonical astabs_group S := group (group_set_astabs S).
Lemma astab_norm S : 'N(S | to) \subset 'N('C(S | to)).
Proof.
apply/subsetP=> a nSa; rewrite inE sub_conjg; apply/subsetP=> b cSb.
have [Da Db] := (astabs_dom nSa, astab_dom cSb).
rewrite mem_conjgV !inE groupJ //; apply/subsetP=> x Sx.
rewrite inE !actMin ?groupM ?groupV //.
by rewrite (astab_act cSb) ?actKVin ?astabs_act ?groupV.
Qed.
Lemma astab_normal S : 'C(S | to) <| 'N(S | to).
Proof. by rewrite /normal astab_sub astab_norm. Qed.
Lemma acts_sub_orbit G S x :
[acts G, on S | to] -> (orbit to G x \subset S) = (x \in S).
Proof.
move/acts_act=> GactS.
apply/subsetP/idP=> [| Sx y]; first by apply; apply: orbit_refl.
by case/orbitP=> a Ga <-{y}; rewrite GactS.
Qed.
Lemma acts_orbit G x : G \subset D -> [acts G, on orbit to G x | to].
Proof.
move/subsetP=> sGD; apply/subsetP=> a Ga; rewrite !inE sGD //.
apply/subsetP=> _ /imsetP[b Gb ->].
by rewrite inE -actMin ?sGD // imset_f ?groupM.
Qed.
Lemma acts_subnorm_fix A : [acts 'N_D(A), on 'Fix_to(D :&: A) | to].
Proof.
apply/subsetP=> a nAa; have [Da _] := setIP nAa; rewrite !inE Da.
apply/subsetP=> x Cx /[1!inE]; apply/afixP=> b DAb.
have [Db _]:= setIP DAb; rewrite -actMin // conjgCV actMin ?groupJ ?groupV //.
by rewrite /= (afixP Cx) // memJ_norm // groupV (subsetP (normsGI _ _) _ nAa).
Qed.
Lemma atrans_orbit G x : [transitive G, on orbit to G x | to].
Proof. by apply: imset_f; apply: orbit_refl. Qed.
Section OrbitStabilizer.
Variables (G : {group aT}) (x : rT).
Hypothesis sGD : G \subset D.
Let ssGD := subsetP sGD.
Lemma amove_act a : a \in G -> amove to G x (to x a) = 'C_G[x | to] :* a.
Proof.
move=> Ga; apply/setP=> b; have Da := ssGD Ga.
rewrite mem_rcoset !(inE, sub1set) !groupMr ?groupV //.
by case Gb: (b \in G); rewrite //= actMin ?groupV ?ssGD ?(canF_eq (actKVin Da)).
Qed.
Lemma amove_orbit : amove to G x @: orbit to G x = rcosets 'C_G[x | to] G.
Proof.
apply/setP => Ha; apply/imsetP/rcosetsP=> [[y] | [a Ga ->]].
by case/imsetP=> b Gb -> ->{Ha y}; exists b => //; rewrite amove_act.
by rewrite -amove_act //; exists (to x a); first apply: mem_orbit.
Qed.
Lemma amoveK :
{in orbit to G x, cancel (amove to G x) (fun Ca => to x (repr Ca))}.
Proof.
move=> _ /orbitP[a Ga <-]; rewrite amove_act //= -[G :&: _]/(gval _).
case: repr_rcosetP => b; rewrite !(inE, sub1set)=> /and3P[Gb _ xbx].
by rewrite actMin ?ssGD ?(eqP xbx).
Qed.
Lemma orbit_stabilizer :
orbit to G x = [set to x (repr Ca) | Ca in rcosets 'C_G[x | to] G].
Proof.
rewrite -amove_orbit -imset_comp /=; apply/setP=> z.
by apply/idP/imsetP=> [xGz | [y xGy ->]]; first exists z; rewrite /= ?amoveK.
Qed.
Lemma act_reprK :
{in rcosets 'C_G[x | to] G, cancel (to x \o repr) (amove to G x)}.
Proof.
move=> _ /rcosetsP[a Ga ->] /=; rewrite amove_act ?rcoset_repr //.
rewrite -[G :&: _]/(gval _); case: repr_rcosetP => b /setIP[Gb _].
exact: groupM.
Qed.
End OrbitStabilizer.
Lemma card_orbit_in G x : G \subset D -> #|orbit to G x| = #|G : 'C_G[x | to]|.
Proof.
move=> sGD; rewrite orbit_stabilizer 1?card_in_imset //.
exact: can_in_inj (act_reprK _).
Qed.
Lemma card_orbit_in_stab G x :
G \subset D -> (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|.
Proof. by move=> sGD; rewrite mulnC card_orbit_in ?Lagrange ?subsetIl. Qed.
Lemma acts_sum_card_orbit G S :
[acts G, on S | to] -> \sum_(T in orbit to G @: S) #|T| = #|S|.
Proof. by move/orbit_partition/card_partition. Qed.
Lemma astab_setact_in S a : a \in D -> 'C(to^* S a | to) = 'C(S | to) :^ a.
Proof.
move=> Da; apply/setP=> b; rewrite mem_conjg !inE -mem_conjg conjGid //.
apply: andb_id2l => Db; rewrite sub_imset_pre; apply: eq_subset_r => x.
by rewrite !inE !actMin ?groupM ?groupV // invgK (canF_eq (actKVin Da)).
Qed.
Lemma astab1_act_in x a : a \in D -> 'C[to x a | to] = 'C[x | to] :^ a.
Proof. by move=> Da; rewrite -astab_setact_in // /setact imset_set1. Qed.
Theorem Frobenius_Cauchy G S : [acts G, on S | to] ->
\sum_(a in G) #|'Fix_(S | to)[a]| = (#|orbit to G @: S| * #|G|)%N.
Proof.
move=> GactS; have sGD := acts_dom GactS.
transitivity (\sum_(a in G) \sum_(x in 'Fix_(S | to)[a]) 1%N).
by apply: eq_bigr => a _; rewrite -sum1_card.
rewrite (exchange_big_dep [in S]) /= => [|a x _]; last by case/setIP.
rewrite (set_partition_big _ (orbit_partition GactS)) -sum_nat_const /=.
apply: eq_bigr => _ /imsetP[x Sx ->].
rewrite -(card_orbit_in_stab x sGD) -sum_nat_const.
apply: eq_bigr => y; rewrite orbit_in_sym // => /imsetP[a Ga defx].
rewrite defx astab1_act_in ?(subsetP sGD) //.
rewrite -{2}(conjGid Ga) -conjIg cardJg -sum1_card setIA (setIidPl sGD).
by apply: eq_bigl => b; rewrite !(sub1set, inE) -(acts_act GactS Ga) -defx Sx.
Qed.
Lemma atrans_dvd_index_in G S :
G \subset D -> [transitive G, on S | to] -> #|S| %| #|G : 'C_G(S | to)|.
Proof.
move=> sGD /imsetP[x Sx {1}->]; rewrite card_orbit_in //.
by rewrite indexgS // setIS // astabS // sub1set.
Qed.
Lemma atrans_dvd_in G S :
G \subset D -> [transitive G, on S | to] -> #|S| %| #|G|.
Proof.
move=> sGD transG; apply: dvdn_trans (atrans_dvd_index_in sGD transG) _.
exact: dvdn_indexg.
Qed.
Lemma atransPin G S :
G \subset D -> [transitive G, on S | to] ->
forall x, x \in S -> orbit to G x = S.
Proof. by move=> sGD /imsetP[y _ ->] x; apply/orbit_in_eqP. Qed.
Lemma atransP2in G S :
G \subset D -> [transitive G, on S | to] ->
{in S &, forall x y, exists2 a, a \in G & y = to x a}.
Proof. by move=> sGD transG x y /(atransPin sGD transG) <- /imsetP. Qed.
Lemma atrans_acts_in G S :
G \subset D -> [transitive G, on S | to] -> [acts G, on S | to].
Proof.
move=> sGD transG; apply/subsetP=> a Ga; rewrite !inE (subsetP sGD) //.
by apply/subsetP=> x /(atransPin sGD transG) <-; rewrite inE imset_f.
Qed.
Lemma subgroup_transitivePin G H S x :
x \in S -> H \subset G -> G \subset D -> [transitive G, on S | to] ->
reflect ('C_G[x | to] * H = G) [transitive H, on S | to].
Proof.
move=> Sx sHG sGD trG; have sHD := subset_trans sHG sGD.
apply: (iffP idP) => [trH | defG].
rewrite group_modr //; apply/setIidPl/subsetP=> a Ga.
have Sxa: to x a \in S by rewrite (acts_act (atrans_acts_in sGD trG)).
have [b Hb xab]:= atransP2in sHD trH Sxa Sx.
have Da := subsetP sGD a Ga; have Db := subsetP sHD b Hb.
rewrite -(mulgK b a) mem_mulg ?groupV // !inE groupM //= sub1set inE.
by rewrite actMin -?xab.
apply/imsetP; exists x => //; apply/setP=> y; rewrite -(atransPin sGD trG Sx).
apply/imsetP/imsetP=> [] [a]; last by exists a; first apply: (subsetP sHG).
rewrite -defG => /imset2P[c b /setIP[_ cxc] Hb ->] ->.
exists b; rewrite ?actMin ?(astab_dom cxc) ?(subsetP sHD) //.
by rewrite (astab_act cxc) ?inE.
Qed.
End PartialAction.
Arguments orbit_transversal {aT D%_g rT} to%_act A%_g S%_g.
Arguments orbit_in_eqP {aT D rT to G x y}.
Arguments orbit1P {aT D rT to G x}.
Arguments contra_orbit [aT D rT] to G [x y].
Notation "''C' ( S | to )" := (astab_group to S) : Group_scope.
Notation "''C_' A ( S | to )" := (setI_group A 'C(S | to)) : Group_scope.
Notation "''C_' ( A ) ( S | to )" := (setI_group A 'C(S | to))
(only parsing) : Group_scope.
Notation "''C' [ x | to ]" := (astab_group to [set x%g]) : Group_scope.
Notation "''C_' A [ x | to ]" := (setI_group A 'C[x | to]) : Group_scope.
Notation "''C_' ( A ) [ x | to ]" := (setI_group A 'C[x | to])
(only parsing) : Group_scope.
Notation "''N' ( S | to )" := (astabs_group to S) : Group_scope.
Notation "''N_' A ( S | to )" := (setI_group A 'N(S | to)) : Group_scope.
Section TotalActions.
(* These lemmas are only established for total actions (domain = [set: rT]) *)
Variable (aT : finGroupType) (rT : finType).
Variable to : {action aT &-> rT}.
Implicit Types (a b : aT) (x y z : rT) (A B : {set aT}) (G H : {group aT}).
Implicit Type S : {set rT}.
Lemma actM x a b : to x (a * b) = to (to x a) b.
Proof. by rewrite actMin ?inE. Qed.
Lemma actK : right_loop invg to.
Proof. by move=> a; apply: actKin; rewrite inE. Qed.
Lemma actKV : rev_right_loop invg to.
Proof. by move=> a; apply: actKVin; rewrite inE. Qed.
Lemma actX x a n : to x (a ^+ n) = iter n (to^~ a) x.
Proof. by elim: n => [|n /= <-]; rewrite ?act1 // -actM expgSr. Qed.
Lemma actCJ a b x : to (to x a) b = to (to x b) (a ^ b).
Proof. by rewrite !actM actK. Qed.
Lemma actCJV a b x : to (to x a) b = to (to x (b ^ a^-1)) a.
Proof. by rewrite (actCJ _ a) conjgKV. Qed.
Lemma orbit_sym G x y : (x \in orbit to G y) = (y \in orbit to G x).
Proof. exact/orbit_in_sym/subsetT. Qed.
Lemma orbit_trans G x y z :
x \in orbit to G y -> y \in orbit to G z -> x \in orbit to G z.
Proof. exact/orbit_in_trans/subsetT. Qed.
Lemma orbit_eqP G x y :
reflect (orbit to G x = orbit to G y) (x \in orbit to G y).
Proof. exact/orbit_in_eqP/subsetT. Qed.
Lemma orbit_transl G x y z :
y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z).
Proof. exact/orbit_in_transl/subsetT. Qed.
Lemma orbit_act G a x: a \in G -> orbit to G (to x a) = orbit to G x.
Proof. exact/orbit_act_in/subsetT. Qed.
Lemma orbit_actr G a x y :
a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x).
Proof. by move/mem_orbit/orbit_transl; apply. Qed.
Lemma orbit_eq_mem G x y :
(orbit to G x == orbit to G y) = (x \in orbit to G y).
Proof. exact: sameP eqP (orbit_eqP G x y). Qed.
Lemma orbit_inv A x y : (y \in orbit to A^-1 x) = (x \in orbit to A y).
Proof. by rewrite orbit_inv_in ?subsetT. Qed.
Lemma orbit_lcoset A a x : orbit to (a *: A) x = orbit to A (to x a).
Proof. by rewrite orbit_lcoset_in ?subsetT ?inE. Qed.
Lemma orbit_rcoset A a x y :
(to y a \in orbit to (A :* a) x) = (y \in orbit to A x).
Proof. by rewrite orbit_rcoset_in ?subsetT ?inE. Qed.
Lemma orbit_conjsg A a x y :
(to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x).
Proof. by rewrite orbit_conjsg_in ?subsetT ?inE. Qed.
Lemma astabP S a : reflect (forall x, x \in S -> to x a = x) (a \in 'C(S | to)).
Proof.
apply: (iffP idP) => [cSa x|cSa]; first exact: astab_act.
by rewrite !inE; apply/subsetP=> x Sx; rewrite inE cSa.
Qed.
Lemma astab1P x a : reflect (to x a = x) (a \in 'C[x | to]).
Proof. by rewrite !inE sub1set inE; apply: eqP. Qed.
Lemma sub_astab1 A x : (A \subset 'C[x | to]) = (x \in 'Fix_to(A)).
Proof. by rewrite sub_astab1_in ?subsetT. Qed.
Lemma astabC A S : (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)).
Proof. by rewrite astabCin ?subsetT. Qed.
Lemma afix_cycle a : 'Fix_to(<[a]>) = 'Fix_to[a].
Proof. by rewrite afix_cycle_in ?inE. Qed.
Lemma afix_gen A : 'Fix_to(<<A>>) = 'Fix_to(A).
Proof. by rewrite afix_gen_in ?subsetT. Qed.
Lemma afixM G H : 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H).
Proof. by rewrite afixMin ?subsetT. Qed.
Lemma astabsP S a :
reflect (forall x, (to x a \in S) = (x \in S)) (a \in 'N(S | to)).
Proof.
apply: (iffP idP) => [nSa x|nSa]; first exact: astabs_act.
by rewrite !inE; apply/subsetP=> x; rewrite inE nSa.
Qed.
Lemma card_orbit G x : #|orbit to G x| = #|G : 'C_G[x | to]|.
Proof. by rewrite card_orbit_in ?subsetT. Qed.
Lemma dvdn_orbit G x : #|orbit to G x| %| #|G|.
Proof. by rewrite card_orbit dvdn_indexg. Qed.
Lemma card_orbit_stab G x : (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|.
Proof. by rewrite mulnC card_orbit Lagrange ?subsetIl. Qed.
Lemma actsP A S : reflect {acts A, on S | to} [acts A, on S | to].
Proof.
apply: (iffP idP) => [nSA x|nSA]; first exact: acts_act.
by apply/subsetP=> a Aa /[!inE]; apply/subsetP=> x; rewrite inE nSA.
Qed.
Arguments actsP {A S}.
Lemma setact_orbit A x b : to^* (orbit to A x) b = orbit to (A :^ b) (to x b).
Proof.
apply/setP=> y; apply/idP/idP=> /imsetP[_ /imsetP[a Aa ->] ->{y}].
by rewrite actCJ mem_orbit ?memJ_conjg.
by rewrite -actCJ mem_setact ?mem_orbit.
Qed.
Lemma astab_setact S a : 'C(to^* S a | to) = 'C(S | to) :^ a.
Proof.
apply/setP=> b; rewrite mem_conjg.
apply/astabP/astabP=> stab x => [Sx|].
by rewrite conjgE invgK !actM stab ?actK //; apply/imsetP; exists x.
by case/imsetP=> y Sy ->{x}; rewrite -actM conjgCV actM stab.
Qed.
Lemma astab1_act x a : 'C[to x a | to] = 'C[x | to] :^ a.
Proof. by rewrite -astab_setact /setact imset_set1. Qed.
Lemma atransP G S : [transitive G, on S | to] ->
forall x, x \in S -> orbit to G x = S.
Proof. by case/imsetP=> x _ -> y; apply/orbit_eqP. Qed.
Lemma atransP2 G S : [transitive G, on S | to] ->
{in S &, forall x y, exists2 a, a \in G & y = to x a}.
Proof. by move=> GtrS x y /(atransP GtrS) <- /imsetP. Qed.
Lemma atrans_acts G S : [transitive G, on S | to] -> [acts G, on S | to].
Proof.
move=> GtrS; apply/subsetP=> a Ga; rewrite !inE.
by apply/subsetP=> x /(atransP GtrS) <-; rewrite inE imset_f.
Qed.
Lemma atrans_supgroup G H S :
G \subset H -> [transitive G, on S | to] ->
[transitive H, on S | to] = [acts H, on S | to].
Proof.
move=> sGH trG; apply/idP/idP=> [|actH]; first exact: atrans_acts.
case/imsetP: trG => x Sx defS; apply/imsetP; exists x => //.
by apply/eqP; rewrite eqEsubset acts_sub_orbit ?Sx // defS imsetS.
Qed.
Lemma atrans_acts_card G S :
[transitive G, on S | to] =
[acts G, on S | to] && (#|orbit to G @: S| == 1%N).
Proof.
apply/idP/andP=> [GtrS | [nSG]].
split; first exact: atrans_acts.
rewrite ((_ @: S =P [set S]) _) ?cards1 // eqEsubset sub1set.
apply/andP; split=> //; apply/subsetP=> _ /imsetP[x Sx ->].
by rewrite inE (atransP GtrS).
rewrite eqn_leq andbC lt0n => /andP[/existsP[X /imsetP[x Sx X_Gx]]].
rewrite (cardD1 X) {X}X_Gx imset_f // ltnS leqn0 => /eqP GtrS.
apply/imsetP; exists x => //; apply/eqP.
rewrite eqEsubset acts_sub_orbit // Sx andbT.
apply/subsetP=> y Sy; have:= card0_eq GtrS (orbit to G y).
by rewrite !inE /= imset_f // andbT => /eqP <-; apply: orbit_refl.
Qed.
Lemma atrans_dvd G S : [transitive G, on S | to] -> #|S| %| #|G|.
Proof. by case/imsetP=> x _ ->; apply: dvdn_orbit. Qed.
(* This is Aschbacher (5.2) *)
Lemma acts_fix_norm A B : A \subset 'N(B) -> [acts A, on 'Fix_to(B) | to].
Proof.
move=> nAB; have:= acts_subnorm_fix to B; rewrite !setTI.
exact: subset_trans.
Qed.
Lemma faithfulP A S :
reflect (forall a, a \in A -> {in S, to^~ a =1 id} -> a = 1)
[faithful A, on S | to].
Proof.
apply: (iffP subsetP) => [Cto1 a Aa Ca | Cto1 a].
by apply/set1P; rewrite Cto1 // inE Aa; apply/astabP.
by case/setIP=> Aa /astabP Ca; apply/set1P; apply: Cto1.
Qed.
(* This is the first part of Aschbacher (5.7) *)
Lemma astab_trans_gcore G S u :
[transitive G, on S | to] -> u \in S -> 'C(S | to) = gcore 'C[u | to] G.
Proof.
move=> transG Su; apply/eqP; rewrite eqEsubset.
rewrite gcore_max ?astabS ?sub1set //=; last first.
exact: subset_trans (atrans_acts transG) (astab_norm _ _).
apply/subsetP=> x cSx; apply/astabP=> uy.
case/(atransP2 transG Su) => y Gy ->{uy}.
by apply/astab1P; rewrite astab1_act (bigcapP cSx).
Qed.
(* This is Aschbacher (5.20) *)
Theorem subgroup_transitiveP G H S x :
x \in S -> H \subset G -> [transitive G, on S | to] ->
reflect ('C_G[x | to] * H = G) [transitive H, on S | to].
Proof. by move=> Sx sHG; apply: subgroup_transitivePin (subsetT G). Qed.
(* This is Aschbacher (5.21) *)
Lemma trans_subnorm_fixP x G H S :
let C := 'C_G[x | to] in let T := 'Fix_(S | to)(H) in
[transitive G, on S | to] -> x \in S -> H \subset C ->
reflect ((H :^: G) ::&: C = H :^: C) [transitive 'N_G(H), on T | to].
Proof.
move=> C T trGS Sx sHC; have actGS := acts_act (atrans_acts trGS).
have:= sHC; rewrite subsetI sub_astab1 => /andP[sHG cHx].
have Tx: x \in T by rewrite inE Sx.
apply: (iffP idP) => [trN | trC].
apply/setP=> Ha; apply/setIdP/imsetP=> [[]|[a Ca ->{Ha}]]; last first.
by rewrite conj_subG //; case/setIP: Ca => Ga _; rewrite imset_f.
case/imsetP=> a Ga ->{Ha}; rewrite subsetI !sub_conjg => /andP[_ sHCa].
have Txa: to x a^-1 \in T.
by rewrite inE -sub_astab1 astab1_act actGS ?Sx ?groupV.
have [b] := atransP2 trN Tx Txa; case/setIP=> Gb nHb cxba.
exists (b * a); last by rewrite conjsgM (normP nHb).
by rewrite inE groupM //; apply/astab1P; rewrite actM -cxba actKV.
apply/imsetP; exists x => //; apply/setP=> y; apply/idP/idP=> [Ty|].
have [Sy cHy]:= setIP Ty; have [a Ga defy] := atransP2 trGS Sx Sy.
have: H :^ a^-1 \in H :^: C.
rewrite -trC inE subsetI imset_f 1?conj_subG ?groupV // sub_conjgV.
by rewrite -astab1_act -defy sub_astab1.
case/imsetP=> b /setIP[Gb /astab1P cxb] defHb.
rewrite defy -{1}cxb -actM mem_orbit // inE groupM //.
by apply/normP; rewrite conjsgM -defHb conjsgKV.
case/imsetP=> a /setIP[Ga nHa] ->{y}.
by rewrite inE actGS // Sx (acts_act (acts_fix_norm _) nHa).
Qed.
End TotalActions.
Arguments astabP {aT rT to S a}.
Arguments orbit_eqP {aT rT to G x y}.
Arguments astab1P {aT rT to x a}.
Arguments astabsP {aT rT to S a}.
Arguments atransP {aT rT to G S}.
Arguments actsP {aT rT to A S}.
Arguments faithfulP {aT rT to A S}.
Section Restrict.
Variables (aT : finGroupType) (D : {set aT}) (rT : Type).
Variables (to : action D rT) (A : {set aT}).
Definition ract of A \subset D := act to.
Variable sAD : A \subset D.
Lemma ract_is_action : is_action A (ract sAD).
Proof.
rewrite /ract; case: to => f [injf fM].
by split=> // x; apply: (sub_in2 (subsetP sAD)).
Qed.
Canonical raction := Action ract_is_action.
Lemma ractE : raction =1 to. Proof. by []. Qed.
(* Other properties of raction need rT : finType; we defer them *)
(* until after the definition of actperm. *)
End Restrict.
Notation "to \ sAD" := (raction to sAD) (at level 50) : action_scope.
Section ActBy.
Variables (aT : finGroupType) (D : {set aT}) (rT : finType).
Definition actby_cond (A : {set aT}) R (to : action D rT) : Prop :=
[acts A, on R | to].
Definition actby A R to of actby_cond A R to :=
fun x a => if (x \in R) && (a \in A) then to x a else x.
Variables (A : {group aT}) (R : {set rT}) (to : action D rT).
Hypothesis nRA : actby_cond A R to.
Lemma actby_is_action : is_action A (actby nRA).
Proof.
rewrite /actby; split=> [a x y | x a b Aa Ab /=]; last first.
rewrite Aa Ab groupM // !andbT actMin ?(subsetP (acts_dom nRA)) //.
by case Rx: (x \in R); rewrite ?(acts_act nRA) ?Rx.
case Aa: (a \in A); rewrite ?andbF ?andbT //.
case Rx: (x \in R); case Ry: (y \in R) => // eqxy; first exact: act_inj eqxy.
by rewrite -eqxy (acts_act nRA Aa) Rx in Ry.
by rewrite eqxy (acts_act nRA Aa) Ry in Rx.
Qed.
Canonical action_by := Action actby_is_action.
Local Notation "<[nRA]>" := action_by : action_scope.
Lemma actbyE x a : x \in R -> a \in A -> <[nRA]>%act x a = to x a.
Proof. by rewrite /= /actby => -> ->. Qed.
Lemma afix_actby B : 'Fix_<[nRA]>(B) = ~: R :|: 'Fix_to(A :&: B).
Proof.
apply/setP=> x; rewrite !inE /= /actby.
case: (x \in R); last by apply/subsetP=> a _ /[!inE].
apply/subsetP/subsetP=> [cBx a | cABx a Ba] /[!inE].
by case/andP=> Aa /cBx; rewrite inE Aa.
by case: ifP => //= Aa; have:= cABx a; rewrite !inE Aa => ->.
Qed.
Lemma astab_actby S : 'C(S | <[nRA]>) = 'C_A(R :&: S | to).
Proof.
apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE.
case Aa: (a \in A) => //=; apply/subsetP/subsetP=> cRSa x => [|Sx].
by case/setIP=> Rx /cRSa; rewrite !inE actbyE.
by have:= cRSa x; rewrite !inE /= /actby Aa Sx; case: (x \in R) => //; apply.
Qed.
Lemma astabs_actby S : 'N(S | <[nRA]>) = 'N_A(R :&: S | to).
Proof.
apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE.
case Aa: (a \in A) => //=; apply/subsetP/subsetP=> nRSa x => [|Sx].
by case/setIP=> Rx /nRSa; rewrite !inE actbyE ?(acts_act nRA) ?Rx.
have:= nRSa x; rewrite !inE /= /actby Aa Sx ?(acts_act nRA) //.
by case: (x \in R) => //; apply.
Qed.
Lemma acts_actby (B : {set aT}) S :
[acts B, on S | <[nRA]>] = (B \subset A) && [acts B, on R :&: S | to].
Proof. by rewrite astabs_actby subsetI. Qed.
End ActBy.
Notation "<[ nRA ] >" := (action_by nRA) : action_scope.
Section SubAction.
Variables (aT : finGroupType) (D : {group aT}).
Variables (rT : finType) (sP : pred rT) (sT : subFinType sP) (to : action D rT).
Implicit Type A : {set aT}.
Implicit Type u : sT.
Implicit Type S : {set sT}.
Definition subact_dom := 'N([set x | sP x] | to).
Canonical subact_dom_group := [group of subact_dom].
Implicit Type Na : {a | a \in subact_dom}.
Lemma sub_act_proof u Na : sP (to (val u) (val Na)).
Proof. by case: Na => a /= /(astabs_act (val u)); rewrite !inE valP. Qed.
Definition subact u a :=
if insub a is Some Na then Sub _ (sub_act_proof u Na) else u.
Lemma val_subact u a :
val (subact u a) = if a \in subact_dom then to (val u) a else val u.
Proof.
by rewrite /subact -if_neg; case: insubP => [Na|] -> //=; rewrite SubK => ->.
Qed.
Lemma subact_is_action : is_action subact_dom subact.
Proof.
split=> [a u v eq_uv | u a b Na Nb]; apply: val_inj.
move/(congr1 val): eq_uv; rewrite !val_subact.
by case: (a \in _); first move/act_inj.
have Da := astabs_dom Na; have Db := astabs_dom Nb.
by rewrite !val_subact Na Nb groupM ?actMin.
Qed.
Canonical subaction := Action subact_is_action.
Lemma astab_subact S : 'C(S | subaction) = subact_dom :&: 'C(val @: S | to).
Proof.
apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa.
have [Da _] := setIP sDa; rewrite !inE Da.
apply/subsetP/subsetP=> [cSa _ /imsetP[x Sx ->] | cSa x Sx] /[!inE].
by have:= cSa x Sx; rewrite inE -val_eqE val_subact sDa.
by have:= cSa _ (imset_f val Sx); rewrite inE -val_eqE val_subact sDa.
Qed.
Lemma astabs_subact S : 'N(S | subaction) = subact_dom :&: 'N(val @: S | to).
Proof.
apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa.
have [Da _] := setIP sDa; rewrite !inE Da.
apply/subsetP/subsetP=> [nSa _ /imsetP[x Sx ->] | nSa x Sx] /[!inE].
by have /[1!inE]/(imset_f val) := nSa x Sx; rewrite val_subact sDa.
have /[1!inE]/imsetP[y Sy def_y] := nSa _ (imset_f val Sx).
by rewrite ((_ a =P y) _) // -val_eqE val_subact sDa def_y.
Qed.
Lemma afix_subact A :
A \subset subact_dom -> 'Fix_subaction(A) = val @^-1: 'Fix_to(A).
Proof.
move/subsetP=> sAD; apply/setP=> u.
rewrite !inE !(sameP setIidPl eqP); congr (_ == A).
apply/setP=> a /[!inE]; apply: andb_id2l => Aa.
by rewrite -val_eqE val_subact sAD.
Qed.
End SubAction.
Notation "to ^?" := (subaction _ to) (format "to ^?") : action_scope.
Section QuotientAction.
Variables (aT : finGroupType) (D : {group aT}) (rT : finGroupType).
Variables (to : action D rT) (H : {group rT}).
Definition qact_dom := 'N(rcosets H 'N(H) | to^*).
Canonical qact_dom_group := [group of qact_dom].
Local Notation subdom := (subact_dom (coset_range H) to^*).
Fact qact_subdomE : subdom = qact_dom.
Proof. by congr 'N(_|_); apply/setP=> Hx; rewrite !inE genGid. Qed.
Lemma qact_proof : qact_dom \subset subdom.
Proof. by rewrite qact_subdomE. Qed.
Definition qact : coset_of H -> aT -> coset_of H := act (to^*^? \ qact_proof).
Canonical quotient_action := [action of qact].
Lemma acts_qact_dom : [acts qact_dom, on 'N(H) | to].
Proof.
apply/subsetP=> a nNa; rewrite !inE (astabs_dom nNa); apply/subsetP=> x Nx.
have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f.
rewrite inE -(astabs_act _ nNa) => /rcosetsP[y Ny defHy].
have: to x a \in H :* y by rewrite -defHy (imset_f (to^~a)) ?rcoset_refl.
by apply: subsetP; rewrite mul_subG ?sub1set ?normG.
Qed.
Lemma qactEcond x a :
x \in 'N(H) ->
quotient_action (coset H x) a
= coset H (if a \in qact_dom then to x a else x).
Proof.
move=> Nx; apply: val_inj; rewrite val_subact //= qact_subdomE.
have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f.
case nNa: (a \in _); rewrite // -(astabs_act _ nNa).
rewrite !val_coset ?(acts_act acts_qact_dom nNa) //=.
case/rcosetsP=> y Ny defHy; rewrite defHy; apply: rcoset_eqP.
by rewrite rcoset_sym -defHy (imset_f (_^~_)) ?rcoset_refl.
Qed.
Lemma qactE x a :
x \in 'N(H) -> a \in qact_dom ->
quotient_action (coset H x) a = coset H (to x a).
Proof. by move=> Nx nNa; rewrite qactEcond ?nNa. Qed.
Lemma acts_quotient (A : {set aT}) (B : {set rT}) :
A \subset 'N_qact_dom(B | to) -> [acts A, on B / H | quotient_action].
Proof.
move=> nBA; apply: subset_trans {A}nBA _; apply/subsetP=> a /setIP[dHa nBa].
rewrite inE dHa inE; apply/subsetP=> _ /morphimP[x nHx Bx ->].
rewrite inE /= qactE //.
by rewrite mem_morphim ?(acts_act acts_qact_dom) ?(astabs_act _ nBa).
Qed.
Lemma astabs_quotient (G : {group rT}) :
H <| G -> 'N(G / H | quotient_action) = 'N_qact_dom(G | to).
Proof.
move=> nsHG; have [_ nHG] := andP nsHG.
apply/eqP; rewrite eqEsubset acts_quotient // andbT.
apply/subsetP=> a nGa; have dHa := astabs_dom nGa; have [Da _]:= setIdP dHa.
rewrite inE dHa 2!inE Da; apply/subsetP=> x Gx; have nHx := subsetP nHG x Gx.
rewrite -(quotientGK nsHG) 2!inE (acts_act acts_qact_dom) ?nHx //= inE.
by rewrite -qactE // (astabs_act _ nGa) mem_morphim.
Qed.
End QuotientAction.
Notation "to / H" := (quotient_action to H) : action_scope.
Section ModAction.
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable to : action D rT.
Implicit Types (G : {group aT}) (S : {set rT}).
Section GenericMod.
Variable H : {group aT}.
Local Notation dom := 'N_D(H).
Local Notation range := 'Fix_to(D :&: H).
Let acts_dom : {acts dom, on range | to} := acts_act (acts_subnorm_fix to H).
Definition modact x (Ha : coset_of H) :=
if x \in range then to x (repr (D :&: Ha)) else x.
Lemma modactEcond x a :
a \in dom -> modact x (coset H a) = (if x \in range then to x a else x).
Proof.
case/setIP=> Da Na; case: ifP => Cx; rewrite /modact Cx //.
rewrite val_coset // -group_modr ?sub1set //.
case: (repr _) / (repr_rcosetP (D :&: H) a) => a' Ha'.
by rewrite actMin ?(afixP Cx _ Ha') //; case/setIP: Ha'.
Qed.
Lemma modactE x a :
a \in D -> a \in 'N(H) -> x \in range -> modact x (coset H a) = to x a.
Proof. by move=> Da Na Rx; rewrite modactEcond ?Rx // inE Da. Qed.
Lemma modact_is_action : is_action (D / H) modact.
Proof.
split=> [Ha x y | x Ha Hb]; last first.
case/morphimP=> a Na Da ->{Ha}; case/morphimP=> b Nb Db ->{Hb}.
rewrite -morphM //= !modactEcond // ?groupM ?(introT setIP _) //.
by case: ifP => Cx; rewrite ?(acts_dom, Cx, actMin, introT setIP _).
case: (set_0Vmem (D :&: Ha)) => [Da0 | [a /setIP[Da NHa]]].
by rewrite /modact Da0 repr_set0 !act1 !if_same.
have Na := subsetP (coset_norm _) _ NHa.
have NDa: a \in 'N_D(H) by rewrite inE Da.
rewrite -(coset_mem NHa) !modactEcond //.
do 2![case: ifP]=> Cy Cx // eqxy; first exact: act_inj eqxy.
by rewrite -eqxy acts_dom ?Cx in Cy.
by rewrite eqxy acts_dom ?Cy in Cx.
Qed.
Canonical mod_action := Action modact_is_action.
Section Stabilizers.
Variable S : {set rT}.
Hypothesis cSH : H \subset 'C(S | to).
Let fixSH : S \subset 'Fix_to(D :&: H).
Proof. by rewrite -astabCin ?subsetIl // subIset ?cSH ?orbT. Qed.
Lemma astabs_mod : 'N(S | mod_action) = 'N(S | to) / H.
Proof.
apply/setP=> Ha; apply/idP/morphimP=> [nSa | [a nHa nSa ->]].
case/morphimP: (astabs_dom nSa) => a nHa Da defHa.
exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE.
by have:= Sx; rewrite -(astabs_act x nSa) defHa /= modactE ?(subsetP fixSH).
have Da := astabs_dom nSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx.
by rewrite !inE /= modactE ?(astabs_act x nSa) ?(subsetP fixSH).
Qed.
Lemma astab_mod : 'C(S | mod_action) = 'C(S | to) / H.
Proof.
apply/setP=> Ha; apply/idP/morphimP=> [cSa | [a nHa cSa ->]].
case/morphimP: (astab_dom cSa) => a nHa Da defHa.
exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE.
by rewrite -{2}[x](astab_act cSa) // defHa /= modactE ?(subsetP fixSH).
have Da := astab_dom cSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx.
by rewrite !inE /= modactE ?(astab_act cSa) ?(subsetP fixSH).
Qed.
End Stabilizers.
Lemma afix_mod G S :
H \subset 'C(S | to) -> G \subset 'N_D(H) ->
'Fix_(S | mod_action)(G / H) = 'Fix_(S | to)(G).
Proof.
move=> cSH /subsetIP[sGD nHG].
apply/eqP; rewrite eqEsubset !subsetI !subsetIl /= -!astabCin ?quotientS //.
have cfixH F: H \subset 'C(S :&: F | to).
by rewrite (subset_trans cSH) // astabS ?subsetIl.
rewrite andbC astab_mod ?quotientS //=; last by rewrite astabCin ?subsetIr.
by rewrite -(quotientSGK nHG) //= -astab_mod // astabCin ?quotientS ?subsetIr.
Qed.
End GenericMod.
Lemma modact_faithful G S :
[faithful G / 'C_G(S | to), on S | mod_action 'C_G(S | to)].
Proof.
rewrite /faithful astab_mod ?subsetIr //=.
by rewrite -quotientIG ?subsetIr ?trivg_quotient.
Qed.
End ModAction.
Notation "to %% H" := (mod_action to H) : action_scope.
Section ActPerm.
(* Morphism to permutations induced by an action. *)
Variables (aT : finGroupType) (D : {set aT}) (rT : finType).
Variable to : action D rT.
Definition actperm a := perm (act_inj to a).
Lemma actpermM : {in D &, {morph actperm : a b / a * b}}.
Proof. by move=> a b Da Db; apply/permP=> x; rewrite permM !permE actMin. Qed.
Canonical actperm_morphism := Morphism actpermM.
Lemma actpermE a x : actperm a x = to x a.
Proof. by rewrite permE. Qed.
Lemma actpermK x a : aperm x (actperm a) = to x a.
Proof. exact: actpermE. Qed.
Lemma ker_actperm : 'ker actperm = 'C(setT | to).
Proof.
congr (_ :&: _); apply/setP=> a /[!inE]/=.
apply/eqP/subsetP=> [a1 x _ | a1]; first by rewrite inE -actpermE a1 perm1.
by apply/permP=> x; apply/eqP; have:= a1 x; rewrite !inE actpermE perm1 => ->.
Qed.
End ActPerm.
Section RestrictActionTheory.
Variables (aT : finGroupType) (D : {set aT}) (rT : finType).
Variables (to : action D rT).
Lemma faithful_isom (A : {group aT}) S (nSA : actby_cond A S to) :
[faithful A, on S | to] -> isom A (actperm <[nSA]> @* A) (actperm <[nSA]>).
Proof.
by move=> ffulAS; apply/isomP; rewrite ker_actperm astab_actby setIT.
Qed.
Variables (A : {set aT}) (sAD : A \subset D).
Lemma ractpermE : actperm (to \ sAD) =1 actperm to.
Proof. by move=> a; apply/permP=> x; rewrite !permE. Qed.
Lemma afix_ract B : 'Fix_(to \ sAD)(B) = 'Fix_to(B). Proof. by []. Qed.
Lemma astab_ract S : 'C(S | to \ sAD) = 'C_A(S | to).
Proof. by rewrite setIA (setIidPl sAD). Qed.
Lemma astabs_ract S : 'N(S | to \ sAD) = 'N_A(S | to).
Proof. by rewrite setIA (setIidPl sAD). Qed.
Lemma acts_ract (B : {set aT}) S :
[acts B, on S | to \ sAD] = (B \subset A) && [acts B, on S | to].
Proof. by rewrite astabs_ract subsetI. Qed.
End RestrictActionTheory.
Section MorphAct.
(* Action induced by a morphism to permutations. *)
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable phi : {morphism D >-> {perm rT}}.
Definition mact x a := phi a x.
Lemma mact_is_action : is_action D mact.
Proof.
split=> [a x y | x a b Da Db]; first exact: perm_inj.
by rewrite /mact morphM //= permM.
Qed.
Canonical morph_action := Action mact_is_action.
Lemma mactE x a : morph_action x a = phi a x. Proof. by []. Qed.
Lemma injm_faithful : 'injm phi -> [faithful D, on setT | morph_action].
Proof.
move/injmP=> phi_inj; apply/subsetP=> a /setIP[Da /astab_act a1].
apply/set1P/phi_inj => //; apply/permP=> x.
by rewrite morph1 perm1 -mactE a1 ?inE.
Qed.
Lemma perm_mact a : actperm morph_action a = phi a.
Proof. by apply/permP=> x; rewrite permE. Qed.
End MorphAct.
Notation "<< phi >>" := (morph_action phi) : action_scope.
Section CompAct.
Variables (gT aT : finGroupType) (rT : finType).
Variables (D : {set aT}) (to : action D rT).
Variables (B : {set gT}) (f : {morphism B >-> aT}).
Definition comp_act x e := to x (f e).
Lemma comp_is_action : is_action (f @*^-1 D) comp_act.
Proof.
split=> [e | x e1 e2]; first exact: act_inj.
move=> /morphpreP[Be1 Dfe1] /morphpreP[Be2 Dfe2].
by rewrite /comp_act morphM ?actMin.
Qed.
Canonical comp_action := Action comp_is_action.
Lemma comp_actE x e : comp_action x e = to x (f e). Proof. by []. Qed.
Lemma afix_comp (A : {set gT}) :
A \subset B -> 'Fix_comp_action(A) = 'Fix_to(f @* A).
Proof.
move=> sAB; apply/setP=> x; rewrite !inE /morphim (setIidPr sAB).
apply/subsetP/subsetP; first by move=> + _ /imsetP[a + ->] => /[apply]/[!inE].
by move=> + a Aa => /(_ (f a)); rewrite !inE imset_f// => ->.
Qed.
Lemma astab_comp S : 'C(S | comp_action) = f @*^-1 'C(S | to).
Proof. by apply/setP=> x; rewrite !inE -andbA. Qed.
Lemma astabs_comp S : 'N(S | comp_action) = f @*^-1 'N(S | to).
Proof. by apply/setP=> x; rewrite !inE -andbA. Qed.
End CompAct.
Notation "to \o f" := (comp_action to f) : action_scope.
Section PermAction.
(* Natural action of permutation groups. *)
Variable rT : finType.
Local Notation gT := {perm rT}.
Implicit Types a b c : gT.
Lemma aperm_is_action : is_action setT (@aperm rT).
Proof.
by apply: is_total_action => [x|x a b]; rewrite apermE (perm1, permM).
Qed.
Canonical perm_action := Action aperm_is_action.
Lemma porbitE a : porbit a = orbit perm_action <[a]>%g.
Proof. by rewrite unlock. Qed.
Lemma perm_act1P a : reflect (forall x, aperm x a = x) (a == 1).
Proof.
apply: (iffP eqP) => [-> x | a1]; first exact: act1.
by apply/permP=> x; rewrite -apermE a1 perm1.
Qed.
Lemma perm_faithful A : [faithful A, on setT | perm_action].
Proof.
apply/subsetP=> a /setIP[Da crTa].
by apply/set1P; apply/permP=> x; rewrite -apermE perm1 (astabP crTa) ?inE.
Qed.
Lemma actperm_id p : actperm perm_action p = p.
Proof. by apply/permP=> x; rewrite permE. Qed.
End PermAction.
Arguments perm_act1P {rT a}.
Notation "'P" := (perm_action _) : action_scope.
Section ActpermOrbits.
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable to : action D rT.
Lemma orbit_morphim_actperm (A : {set aT}) :
A \subset D -> orbit 'P (actperm to @* A) =1 orbit to A.
Proof.
move=> sAD x; rewrite morphimEsub // /orbit -imset_comp.
by apply: eq_imset => a //=; rewrite actpermK.
Qed.
Lemma porbit_actperm (a : aT) :
a \in D -> porbit (actperm to a) =1 orbit to <[a]>.
Proof.
move=> Da x.
by rewrite porbitE -orbit_morphim_actperm ?cycle_subG ?morphim_cycle.
Qed.
End ActpermOrbits.
Section RestrictPerm.
Variables (T : finType) (S : {set T}).
Definition restr_perm := actperm (<[subxx 'N(S | 'P)]>).
Canonical restr_perm_morphism := [morphism of restr_perm].
Lemma restr_perm_on p : perm_on S (restr_perm p).
Proof.
apply/subsetP=> x; apply: contraR => notSx.
by rewrite permE /= /actby (negPf notSx).
Qed.
Lemma triv_restr_perm p : p \notin 'N(S | 'P) -> restr_perm p = 1.
Proof.
move=> not_nSp; apply/permP=> x.
by rewrite !permE /= /actby (negPf not_nSp) andbF.
Qed.
Lemma restr_permE : {in 'N(S | 'P) & S, forall p, restr_perm p =1 p}.
Proof. by move=> y x nSp Sx; rewrite /= actpermE actbyE. Qed.
Lemma ker_restr_perm : 'ker restr_perm = 'C(S | 'P).
Proof. by rewrite ker_actperm astab_actby setIT (setIidPr (astab_sub _ _)). Qed.
Lemma im_restr_perm p : restr_perm p @: S = S.
Proof. exact: im_perm_on (restr_perm_on p). Qed.
Lemma restr_perm_commute s : commute (restr_perm s) s.
Proof.
have [sC|/triv_restr_perm->] := boolP (s \in 'N(S | 'P)); last first.
exact: (commute_sym (commute1 _)).
apply/permP => x; have /= xsS := astabsP sC x; rewrite !permM.
have [xS|xNS] := boolP (x \in S); first by rewrite ?(restr_permE) ?xsS.
by rewrite !(out_perm (restr_perm_on _)) ?xsS.
Qed.
End RestrictPerm.
Section Symmetry.
Variables (T : finType) (S : {set T}).
Lemma SymE : Sym S = 'C(~: S | 'P).
Proof.
apply/setP => s; rewrite inE; apply/idP/astabP => [sS x|/= S_id].
by rewrite inE /= apermE => /out_perm->.
by apply/subsetP => x; move=> /(contra_neqN (S_id _)); rewrite inE negbK.
Qed.
End Symmetry.
Section AutIn.
Variable gT : finGroupType.
Definition Aut_in A (B : {set gT}) := 'N_A(B | 'P) / 'C_A(B | 'P).
Variables G H : {group gT}.
Hypothesis sHG: H \subset G.
Lemma Aut_restr_perm a : a \in Aut G -> restr_perm H a \in Aut H.
Proof.
move=> AutGa.
case nHa: (a \in 'N(H | 'P)); last by rewrite triv_restr_perm ?nHa ?group1.
rewrite inE restr_perm_on; apply/morphicP=> x y Hx Hy /=.
by rewrite !restr_permE ?groupM // -(autmE AutGa) morphM ?(subsetP sHG).
Qed.
Lemma restr_perm_Aut : restr_perm H @* Aut G \subset Aut H.
Proof.
by apply/subsetP=> a'; case/morphimP=> a _ AutGa ->{a'}; apply: Aut_restr_perm.
Qed.
Lemma Aut_in_isog : Aut_in (Aut G) H \isog restr_perm H @* Aut G.
Proof.
rewrite /Aut_in -ker_restr_perm kerE -morphpreIdom -morphimIdom -kerE /=.
by rewrite setIA (setIC _ (Aut G)) first_isog_loc ?subsetIr.
Qed.
Lemma Aut_sub_fullP :
reflect (forall h : {morphism H >-> gT}, 'injm h -> h @* H = H ->
exists g : {morphism G >-> gT},
[/\ 'injm g, g @* G = G & {in H, g =1 h}])
(Aut_in (Aut G) H \isog Aut H).
Proof.
rewrite (isog_transl _ Aut_in_isog) /=; set rG := _ @* _.
apply: (iffP idP) => [iso_rG h injh hH| AutHinG].
have: aut injh hH \in rG; last case/morphimP=> g nHg AutGg def_g.
suffices ->: rG = Aut H by apply: Aut_aut.
by apply/eqP; rewrite eqEcard restr_perm_Aut /= (card_isog iso_rG).
exists (autm_morphism AutGg); rewrite injm_autm im_autm; split=> // x Hx.
by rewrite -(autE injh hH Hx) def_g actpermE actbyE.
suffices ->: rG = Aut H by apply: isog_refl.
apply/eqP; rewrite eqEsubset restr_perm_Aut /=.
apply/subsetP=> h AutHh; have hH := im_autm AutHh.
have [g [injg gG eq_gh]] := AutHinG _ (injm_autm AutHh) hH.
have [Ng AutGg]: aut injg gG \in 'N(H | 'P) /\ aut injg gG \in Aut G.
rewrite Aut_aut !inE; split=> //; apply/subsetP=> x Hx.
by rewrite inE /= /aperm autE ?(subsetP sHG) // -hH eq_gh ?mem_morphim.
apply/morphimP; exists (aut injg gG) => //; apply: (eq_Aut AutHh) => [|x Hx].
by rewrite (subsetP restr_perm_Aut) // mem_morphim.
by rewrite restr_permE //= /aperm autE ?eq_gh ?(subsetP sHG).
Qed.
End AutIn.
Arguments Aut_in {gT} A%_g B%_g.
Section InjmAutIn.
Variables (gT rT : finGroupType) (D G H : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D) (sHG : H \subset G).
Let sHD := subset_trans sHG sGD.
Local Notation fGisom := (Aut_isom injf sGD).
Local Notation fHisom := (Aut_isom injf sHD).
Local Notation inH := (restr_perm H).
Local Notation infH := (restr_perm (f @* H)).
Lemma astabs_Aut_isom a :
a \in Aut G -> (fGisom a \in 'N(f @* H | 'P)) = (a \in 'N(H | 'P)).
Proof.
move=> AutGa; rewrite !inE sub_morphim_pre // subsetI sHD /= /aperm.
rewrite !(sameP setIidPl eqP) !eqEsubset !subsetIl; apply: eq_subset_r => x.
rewrite !inE; apply: andb_id2l => Hx; have Gx: x \in G := subsetP sHG x Hx.
have Dax: a x \in D by rewrite (subsetP sGD) // Aut_closed.
by rewrite Aut_isomE // -!sub1set -morphim_set1 // injmSK ?sub1set.
Qed.
Lemma isom_restr_perm a : a \in Aut G -> fHisom (inH a) = infH (fGisom a).
Proof.
move=> AutGa; case nHa: (a \in 'N(H | 'P)); last first.
by rewrite !triv_restr_perm ?astabs_Aut_isom ?nHa ?morph1.
apply: (eq_Aut (Aut_Aut_isom injf sHD _)) => [|fx Hfx /=].
by rewrite (Aut_restr_perm (morphimS f sHG)) ?Aut_Aut_isom.
have [x Dx Hx def_fx] := morphimP Hfx; have Gx := subsetP sHG x Hx.
rewrite {1}def_fx Aut_isomE ?(Aut_restr_perm sHG) //.
by rewrite !restr_permE ?astabs_Aut_isom // def_fx Aut_isomE.
Qed.
Lemma restr_perm_isom : isom (inH @* Aut G) (infH @* Aut (f @* G)) fHisom.
Proof.
apply: sub_isom; rewrite ?restr_perm_Aut ?injm_Aut_isom //=.
rewrite -(im_Aut_isom injf sGD) -!morphim_comp.
apply: eq_in_morphim; last exact: isom_restr_perm.
(* TODO: investigate why rewrite does not match in the same order *)
apply/setP=> a; rewrite in_setI [in RHS]in_setI; apply: andb_id2r => AutGa.
(* the middle rewrite was rewrite 2!in_setI *)
rewrite /= inE andbC inE (Aut_restr_perm sHG) //=.
by symmetry; rewrite inE AutGa inE astabs_Aut_isom.
Qed.
Lemma injm_Aut_sub : Aut_in (Aut (f @* G)) (f @* H) \isog Aut_in (Aut G) H.
Proof.
do 2!rewrite isog_sym (isog_transl _ (Aut_in_isog _ _)).
by rewrite isog_sym (isom_isog _ _ restr_perm_isom) // restr_perm_Aut.
Qed.
Lemma injm_Aut_full :
(Aut_in (Aut (f @* G)) (f @* H) \isog Aut (f @* H))
= (Aut_in (Aut G) H \isog Aut H).
Proof.
by rewrite (isog_transl _ injm_Aut_sub) (isog_transr _ (injm_Aut injf sHD)).
Qed.
End InjmAutIn.
Section GroupAction.
Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}).
Local Notation actT := (action D rT).
Definition is_groupAction (to : actT) :=
{in D, forall a, actperm to a \in Aut R}.
Structure groupAction := GroupAction {gact :> actT; _ : is_groupAction gact}.
Definition clone_groupAction to :=
let: GroupAction _ toA := to return {type of GroupAction for to} -> _ in
fun k => k toA : groupAction.
End GroupAction.
Delimit Scope groupAction_scope with gact.
Bind Scope groupAction_scope with groupAction.
Arguments is_groupAction {aT rT D%_g} R%_g to%_act.
Arguments groupAction {aT rT} D%_g R%_g.
Arguments gact {aT rT D%_g R%_g} to%_gact : rename.
Notation "[ 'groupAction' 'of' to ]" :=
(clone_groupAction (@GroupAction _ _ _ _ to))
(format "[ 'groupAction' 'of' to ]") : form_scope.
Section GroupActionDefs.
Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}).
Implicit Type A : {set aT}.
Implicit Type S : {set rT}.
Implicit Type to : groupAction D R.
Definition gact_range of groupAction D R := R.
Definition gacent to A := 'Fix_(R | to)(D :&: A).
Definition acts_on_group A S to := [acts A, on S | to] /\ S \subset R.
Coercion actby_cond_group A S to : acts_on_group A S to -> actby_cond A S to :=
@proj1 _ _.
Definition acts_irreducibly A S to :=
[min S of G | G :!=: 1 & [acts A, on G | to]].
End GroupActionDefs.
Arguments gacent {aT rT D%_g R%_g} to%_gact A%_g.
Arguments acts_on_group {aT rT D%_g R%_g} A%_g S%_g to%_gact.
Arguments acts_irreducibly {aT rT D%_g R%_g} A%_g S%_g to%_gact.
Notation "''C_' ( | to ) ( A )" := (gacent to A) : group_scope.
Notation "''C_' ( G | to ) ( A )" := (G :&: 'C_(|to)(A)) : group_scope.
Notation "''C_' ( | to ) [ a ]" := 'C_(|to)([set a]) : group_scope.
Notation "''C_' ( G | to ) [ a ]" := 'C_(G | to)([set a]) : group_scope.
Notation "{ 'acts' A , 'on' 'group' G | to }" := (acts_on_group A G to)
(format "{ 'acts' A , 'on' 'group' G | to }") : type_scope.
Section RawGroupAction.
Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}).
Variable to : groupAction D R.
Lemma actperm_Aut : is_groupAction R to. Proof. by case: to. Qed.
Lemma im_actperm_Aut : actperm to @* D \subset Aut R.
Proof. by apply/subsetP=> _ /morphimP[a _ Da ->]; apply: actperm_Aut. Qed.
Lemma gact_out x a : a \in D -> x \notin R -> to x a = x.
Proof. by move=> Da Rx; rewrite -actpermE (out_Aut _ Rx) ?actperm_Aut. Qed.
Lemma gactM : {in D, forall a, {in R &, {morph to^~ a : x y / x * y}}}.
Proof.
move=> a Da /= x y; rewrite -!(actpermE to); apply: morphicP x y.
by rewrite Aut_morphic ?actperm_Aut.
Qed.
Lemma actmM a : {in R &, {morph actm to a : x y / x * y}}.
Proof. by rewrite /actm; case: ifP => //; apply: gactM. Qed.
Canonical act_morphism a := Morphism (actmM a).
Lemma morphim_actm :
{in D, forall a (S : {set rT}), S \subset R -> actm to a @* S = to^* S a}.
Proof. by move=> a Da /= S sSR; rewrite /morphim /= actmEfun ?(setIidPr _). Qed.
Variables (a : aT) (A B : {set aT}) (S : {set rT}).
Lemma gacentIdom : 'C_(|to)(D :&: A) = 'C_(|to)(A).
Proof. by rewrite /gacent setIA setIid. Qed.
Lemma gacentIim : 'C_(R | to)(A) = 'C_(|to)(A).
Proof. by rewrite setIA setIid. Qed.
Lemma gacentS : A \subset B -> 'C_(|to)(B) \subset 'C_(|to)(A).
Proof. by move=> sAB; rewrite !(setIS, afixS). Qed.
Lemma gacentU : 'C_(|to)(A :|: B) = 'C_(|to)(A) :&: 'C_(|to)(B).
Proof. by rewrite -setIIr -afixU -setIUr. Qed.
Hypotheses (Da : a \in D) (sAD : A \subset D) (sSR : S \subset R).
Lemma gacentE : 'C_(|to)(A) = 'Fix_(R | to)(A).
Proof. by rewrite -{2}(setIidPr sAD). Qed.
Lemma gacent1E : 'C_(|to)[a] = 'Fix_(R | to)[a].
Proof. by rewrite /gacent [D :&: _](setIidPr _) ?sub1set. Qed.
Lemma subgacentE : 'C_(S | to)(A) = 'Fix_(S | to)(A).
Proof. by rewrite gacentE setIA (setIidPl sSR). Qed.
Lemma subgacent1E : 'C_(S | to)[a] = 'Fix_(S | to)[a].
Proof. by rewrite gacent1E setIA (setIidPl sSR). Qed.
End RawGroupAction.
Section GroupActionTheory.
Variables aT rT : finGroupType.
Variables (D : {group aT}) (R : {group rT}) (to : groupAction D R).
Implicit Type A B : {set aT}.
Implicit Types G H : {group aT}.
Implicit Type S : {set rT}.
Implicit Types M N : {group rT}.
Lemma gact1 : {in D, forall a, to 1 a = 1}.
Proof. by move=> a Da; rewrite /= -actmE ?morph1. Qed.
Lemma gactV : {in D, forall a, {in R, {morph to^~ a : x / x^-1}}}.
Proof. by move=> a Da /= x Rx; move; rewrite -!actmE ?morphV. Qed.
Lemma gactX : {in D, forall a n, {in R, {morph to^~ a : x / x ^+ n}}}.
Proof. by move=> a Da /= n x Rx; rewrite -!actmE // morphX. Qed.
Lemma gactJ : {in D, forall a, {in R &, {morph to^~ a : x y / x ^ y}}}.
Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphJ. Qed.
Lemma gactR : {in D, forall a, {in R &, {morph to^~ a : x y / [~ x, y]}}}.
Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphR. Qed.
Lemma gact_stable : {acts D, on R | to}.
Proof.
apply: acts_act; apply/subsetP=> a Da; rewrite !inE Da.
apply/subsetP=> x; rewrite inE; apply: contraLR => R'xa.
by rewrite -(actKin to Da x) gact_out ?groupV.
Qed.
Lemma group_set_gacent A : group_set 'C_(|to)(A).
Proof.
apply/group_setP; split=> [|x y].
by rewrite !inE group1; apply/subsetP=> a /setIP[Da _]; rewrite inE gact1.
case/setIP=> Rx /afixP cAx /setIP[Ry /afixP cAy].
rewrite inE groupM //; apply/afixP=> a Aa.
by rewrite gactM ?cAx ?cAy //; case/setIP: Aa.
Qed.
Canonical gacent_group A := Group (group_set_gacent A).
Lemma gacent1 : 'C_(|to)(1) = R.
Proof. by rewrite /gacent (setIidPr (sub1G _)) afix1 setIT. Qed.
Lemma gacent_gen A : A \subset D -> 'C_(|to)(<<A>>) = 'C_(|to)(A).
Proof.
by move=> sAD; rewrite /gacent  ?gen_subG ?afix_gen_in.
Qed.
Lemma gacentD1 A : 'C_(|to)(A^#) = 'C_(|to)(A).
Proof.
rewrite -gacentIdom -gacent_gen ?subsetIl // setIDA genD1 ?group1 //.
by rewrite gacent_gen ?subsetIl // gacentIdom.
Qed.
Lemma gacent_cycle a : a \in D -> 'C_(|to)(<[a]>) = 'C_(|to)[a].
Proof. by move=> Da; rewrite gacent_gen ?sub1set. Qed.
Lemma gacentY A B :
A \subset D -> B \subset D -> 'C_(|to)(A <*> B) = 'C_(|to)(A) :&: 'C_(|to)(B).
Proof. by move=> sAD sBD; rewrite gacent_gen ?gacentU // subUset sAD. Qed.
Lemma gacentM G H :
G \subset D -> H \subset D -> 'C_(|to)(G * H) = 'C_(|to)(G) :&: 'C_(|to)(H).
Proof.
by move=> sGD sHB; rewrite -gacent_gen ?mul_subG // genM_join gacentY.
Qed.
Lemma astab1 : 'C(1 | to) = D.
Proof.
by apply/setP=> x; rewrite ?(inE, sub1set) andb_idr //; move/gact1=> ->.
Qed.
Lemma astab_range : 'C(R | to) = 'C(setT | to).
Proof.
apply/eqP; rewrite eqEsubset andbC astabS ?subsetT //=.
apply/subsetP=> a cRa; have Da := astab_dom cRa; rewrite !inE Da.
apply/subsetP=> x; rewrite -(setUCr R) !inE.
by case/orP=> ?; [rewrite (astab_act cRa) | rewrite gact_out].
Qed.
Lemma gacentC A S :
A \subset D -> S \subset R ->
(S \subset 'C_(|to)(A)) = (A \subset 'C(S | to)).
Proof. by move=> sAD sSR; rewrite subsetI sSR astabCin // (setIidPr sAD). Qed.
Lemma astab_gen S : S \subset R -> 'C(<<S>> | to) = 'C(S | to).
Proof.
move=> sSR; apply/setP=> a; case Da: (a \in D); last by rewrite !inE Da.
by rewrite -!sub1set -!gacentC ?sub1set ?gen_subG.
Qed.
Lemma astabM M N :
M \subset R -> N \subset R -> 'C(M * N | to) = 'C(M | to) :&: 'C(N | to).
Proof.
move=> sMR sNR; rewrite -astabU -astab_gen ?mul_subG // genM_join.
by rewrite astab_gen // subUset sMR.
Qed.
Lemma astabs1 : 'N(1 | to) = D.
Proof. by rewrite astabs_set1 astab1. Qed.
Lemma astabs_range : 'N(R | to) = D.
Proof.
apply/setIidPl; apply/subsetP=> a Da; rewrite inE.
by apply/subsetP=> x Rx; rewrite inE gact_stable.
Qed.
Lemma astabsD1 S : 'N(S^# | to) = 'N(S | to).
Proof.
case S1: (1 \in S); last first.
by rewrite (setDidPl _) // disjoint_sym disjoints_subset sub1set inE S1.
apply/eqP; rewrite eqEsubset andbC -{1}astabsIdom -{1}astabs1 setIC astabsD /=.
by rewrite -{2}(setD1K S1) -astabsIdom -{1}astabs1 astabsU.
Qed.
Lemma gacts_range A : A \subset D -> {acts A, on group R | to}.
Proof. by move=> sAD; split; rewrite ?astabs_range. Qed.
Lemma acts_subnorm_gacent A : A \subset D ->
[acts 'N_D(A), on 'C_(| to)(A) | to].
Proof.
move=> sAD; rewrite gacentE // actsI ?astabs_range ?subsetIl //.
by rewrite -{2}(setIidPr sAD) acts_subnorm_fix.
Qed.
Lemma acts_subnorm_subgacent A B S :
A \subset D -> [acts B, on S | to] -> [acts 'N_B(A), on 'C_(S | to)(A) | to].
Proof.
move=> sAD actsB; rewrite actsI //; first by rewrite subIset ?actsB.
by rewrite (subset_trans _ (acts_subnorm_gacent sAD)) ?setSI ?(acts_dom actsB).
Qed.
Lemma acts_gen A S :
S \subset R -> [acts A, on S | to] -> [acts A, on <<S>> | to].
Proof.
move=> sSR actsA; apply: {A}subset_trans actsA _.
apply/subsetP=> a nSa; have Da := astabs_dom nSa; rewrite !inE Da.
apply: subset_trans (_ : <<S>> \subset actm to a @*^-1 <<S>>) _.
rewrite gen_subG subsetI sSR; apply/subsetP=> x Sx.
by rewrite inE /= actmE ?mem_gen // astabs_act.
by apply/subsetP=> x /[!inE]; case/andP=> Rx; rewrite /= actmE.
Qed.
Lemma acts_joing A M N :
M \subset R -> N \subset R -> [acts A, on M | to] -> [acts A, on N | to] ->
[acts A, on M <*> N | to].
Proof. by move=> sMR sNR nMA nNA; rewrite acts_gen ?actsU // subUset sMR. Qed.
Lemma injm_actm a : 'injm (actm to a).
Proof.
apply/injmP=> x y Rx Ry; rewrite /= /actm; case: ifP => Da //.
exact: act_inj.
Qed.
Lemma im_actm a : actm to a @* R = R.
Proof.
apply/eqP; rewrite eqEcard (card_injm (injm_actm a)) // leqnn andbT.
apply/subsetP=> _ /morphimP[x Rx _ ->] /=.
by rewrite /actm; case: ifP => // Da; rewrite gact_stable.
Qed.
Lemma acts_char G M : G \subset D -> M \char R -> [acts G, on M | to].
Proof.
move=> sGD /charP[sMR charM].
apply/subsetP=> a Ga; have Da := subsetP sGD a Ga; rewrite !inE Da.
apply/subsetP=> x Mx; have Rx := subsetP sMR x Mx.
by rewrite inE -(charM _ (injm_actm a) (im_actm a)) -actmE // mem_morphim.
Qed.
Lemma gacts_char G M :
G \subset D -> M \char R -> {acts G, on group M | to}.
(* TODO: investigate why rewrite does not match in the same order *)
Proof. by move=> sGD charM; split; rewrite ?acts_char// char_sub. Qed.
(* was ending with rewrite (acts_char, char_sub)// *)
Section Restrict.
Variables (A : {group aT}) (sAD : A \subset D).
Lemma ract_is_groupAction : is_groupAction R (to \ sAD).
Proof. by move=> a Aa /=; rewrite ractpermE actperm_Aut ?(subsetP sAD). Qed.
Canonical ract_groupAction := GroupAction ract_is_groupAction.
Lemma gacent_ract B : 'C_(|ract_groupAction)(B) = 'C_(|to)(A :&: B).
Proof. by rewrite /gacent afix_ract setIA (setIidPr sAD). Qed.
End Restrict.
Section ActBy.
Variables (A : {group aT}) (G : {group rT}) (nGAg : {acts A, on group G | to}).
Lemma actby_is_groupAction : is_groupAction G <[nGAg]>.
Proof.
move=> a Aa; rewrite /= inE; apply/andP; split.
apply/subsetP=> x; apply: contraR => Gx.
by rewrite actpermE /= /actby (negbTE Gx).
apply/morphicP=> x y Gx Gy; rewrite !actpermE /= /actby Aa groupM ?Gx ?Gy //=.
by case nGAg; move/acts_dom; do 2!move/subsetP=> ?; rewrite gactM; auto.
Qed.
Canonical actby_groupAction := GroupAction actby_is_groupAction.
Lemma gacent_actby B :
'C_(|actby_groupAction)(B) = 'C_(G | to)(A :&: B).
Proof.
rewrite /gacent afix_actby !setIA setIid setIUr setICr set0U.
by have [nAG sGR] := nGAg; rewrite (setIidPr (acts_dom nAG)) (setIidPl sGR).
Qed.
End ActBy.
Section Quotient.
Variable H : {group rT}.
Lemma acts_qact_dom_norm : {acts qact_dom to H, on 'N(H) | to}.
Proof.
move=> a HDa /= x; rewrite {2}(('N(H) =P to^~ a @^-1: 'N(H)) _) ?inE {x}//.
rewrite eqEcard (card_preimset _ (act_inj _ _)) leqnn andbT.
apply/subsetP=> x Nx; rewrite inE; move/(astabs_act (H :* x)): HDa.
rewrite mem_rcosets mulSGid ?normG // Nx => /rcosetsP[y Ny defHy].
suffices: to x a \in H :* y by apply: subsetP; rewrite mul_subG ?sub1set ?normG.
by rewrite -defHy; apply: imset_f; apply: rcoset_refl.
Qed.
Lemma qact_is_groupAction : is_groupAction (R / H) (to / H).
Proof.
move=> a HDa /=; have Da := astabs_dom HDa.
rewrite inE; apply/andP; split.
apply/subsetP=> Hx /=; case: (cosetP Hx) => x Nx ->{Hx}.
apply: contraR => R'Hx; rewrite actpermE qactE // gact_out //.
by apply: contra R'Hx; apply: mem_morphim.
apply/morphicP=> Hx Hy; rewrite !actpermE.
case/morphimP=> x Nx Gx ->{Hx}; case/morphimP=> y Ny Gy ->{Hy}.
by rewrite -morphM ?qactE ?groupM ?gactM // morphM ?acts_qact_dom_norm.
Qed.
Canonical quotient_groupAction := GroupAction qact_is_groupAction.
Lemma qact_domE : H \subset R -> qact_dom to H = 'N(H | to).
Proof.
move=> sHR; apply/setP=> a; apply/idP/idP=> nHa; have Da := astabs_dom nHa.
rewrite !inE Da; apply/subsetP=> x Hx; rewrite inE -(rcoset1 H).
have /rcosetsP[y Ny defHy]: to^~ a @: H \in rcosets H 'N(H).
by rewrite (astabs_act _ nHa); apply/rcosetsP; exists 1; rewrite ?mulg1.
by rewrite (rcoset_eqP (_ : 1 \in H :* y)) -defHy -1?(gact1 Da) mem_setact.
rewrite !inE Da; apply/subsetP=> Hx /[1!inE] /rcosetsP[x Nx ->{Hx}].
apply/imsetP; exists (to x a).
case Rx: (x \in R); last by rewrite gact_out ?Rx.
rewrite inE; apply/subsetP=> _ /imsetP[y Hy ->].
rewrite -(actKVin to Da y) -gactJ // ?(subsetP sHR, astabs_act, groupV) //.
by rewrite memJ_norm // astabs_act ?groupV.
apply/eqP; rewrite rcosetE eqEcard.
rewrite (card_imset _ (act_inj _ _)) !card_rcoset leqnn andbT.
apply/subsetP=> _ /imsetP[y Hxy ->]; rewrite !mem_rcoset in Hxy *.
have Rxy := subsetP sHR _ Hxy; rewrite -(mulgKV x y).
case Rx: (x \in R); last by rewrite !gact_out ?mulgK // 1?groupMl ?Rx.
by rewrite -gactV // -gactM 1?groupMr ?groupV // mulgK astabs_act.
Qed.
End Quotient.
Section Mod.
Variable H : {group aT}.
Lemma modact_is_groupAction : is_groupAction 'C_(|to)(H) (to %% H).
Proof.
move=> Ha /morphimP[a Na Da ->]; have NDa: a \in 'N_D(H) by apply/setIP.
rewrite inE; apply/andP; split.
apply/subsetP=> x; rewrite 2!inE andbC actpermE /= modactEcond //.
by apply: contraR; case: ifP => // E Rx; rewrite gact_out.
apply/morphicP=> x y /setIP[Rx cHx] /setIP[Ry cHy].
rewrite /= !actpermE /= !modactE ?gactM //.
suffices: x * y \in 'C_(|to)(H) by case/setIP.
by rewrite groupM //; apply/setIP.
Qed.
Canonical mod_groupAction := GroupAction modact_is_groupAction.
Lemma modgactE x a :
H \subset 'C(R | to) -> a \in 'N_D(H) -> (to %% H)%act x (coset H a) = to x a.
Proof.
move=> cRH NDa /=; have [Da Na] := setIP NDa.
have [Rx | notRx] := boolP (x \in R).
by rewrite modactE //; apply/afixP=> b /setIP[_ /(subsetP cRH)/astab_act->].
rewrite gact_out //= /modact; case: ifP => // _; rewrite gact_out //.
suffices: a \in D :&: coset H a by case/mem_repr/setIP.
by rewrite inE Da val_coset // rcoset_refl.
Qed.
Lemma gacent_mod G M :
H \subset 'C(M | to) -> G \subset 'N(H) ->
'C_(M | mod_groupAction)(G / H) = 'C_(M | to)(G).
Proof.
move=> cMH nHG; rewrite -gacentIdom gacentE ?subsetIl // setICA.
have sHD: H \subset D by rewrite (subset_trans cMH) ?subsetIl.
rewrite -quotientGI // afix_mod ?setIS // setICA -gacentIim (setIC R) -setIA.
rewrite -gacentE ?subsetIl // gacentIdom setICA (setIidPr _) //.
by rewrite gacentC // ?(subset_trans cMH) ?astabS ?subsetIl // setICA subsetIl.
Qed.
Lemma acts_irr_mod G M :
H \subset 'C(M | to) -> G \subset 'N(H) -> acts_irreducibly G M to ->
acts_irreducibly (G / H) M mod_groupAction.
Proof.
move=> cMH nHG /mingroupP[/andP[ntM nMG] minM].
apply/mingroupP; rewrite ntM astabs_mod ?quotientS //; split=> // L modL ntL.
have cLH: H \subset 'C(L | to) by rewrite (subset_trans cMH) ?astabS //.
apply: minM => //; case/andP: modL => ->; rewrite astabs_mod ?quotientSGK //.
by rewrite (subset_trans cLH) ?astab_sub.
Qed.
End Mod.
Lemma modact_coset_astab x a :
a \in D -> (to %% 'C(R | to))%act x (coset _ a) = to x a.
Proof.
move=> Da; apply: modgactE => {x}//.
rewrite !inE Da; apply/subsetP=> _ /imsetP[c Cc ->].
have Dc := astab_dom Cc; rewrite !inE groupJ //.
apply/subsetP=> x Rx; rewrite inE conjgE !actMin ?groupM ?groupV //.
by rewrite (astab_act Cc) ?actKVin // gact_stable ?groupV.
Qed.
Lemma acts_irr_mod_astab G M :
acts_irreducibly G M to ->
acts_irreducibly (G / 'C_G(M | to)) M (mod_groupAction _).
Proof.
move=> irrG; have /andP[_ nMG] := mingroupp irrG.
apply: acts_irr_mod irrG; first exact: subsetIr.
by rewrite normsI ?normG // (subset_trans nMG) // astab_norm.
Qed.
Section CompAct.
Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> aT}).
Lemma comp_is_groupAction : is_groupAction R (comp_action to f).
Proof.
move=> a /morphpreP[Ba Dfa]; apply: etrans (actperm_Aut to Dfa).
by congr (_ \in Aut R); apply/permP=> x; rewrite !actpermE.
Qed.
Canonical comp_groupAction := GroupAction comp_is_groupAction.
Lemma gacent_comp U : 'C_(|comp_groupAction)(U) = 'C_(|to)(f @* U).
Proof.
rewrite /gacent afix_comp ?subIset ?subxx //.
by rewrite -(setIC U) (setIC D) morphim_setIpre.
Qed.
End CompAct.
End GroupActionTheory.
Notation "''C_' ( | to ) ( A )" := (gacent_group to A) : Group_scope.
Notation "''C_' ( G | to ) ( A )" :=
(setI_group G 'C_(|to)(A)) : Group_scope.
Notation "''C_' ( | to ) [ a ]" := (gacent_group to [set a%g]) : Group_scope.
Notation "''C_' ( G | to ) [ a ]" :=
(setI_group G 'C_(|to)[a]) : Group_scope.
Notation "to \ sAD" := (ract_groupAction to sAD) : groupAction_scope.
Notation "<[ nGA ] >" := (actby_groupAction nGA) : groupAction_scope.
Notation "to / H" := (quotient_groupAction to H) : groupAction_scope.
Notation "to %% H" := (mod_groupAction to H) : groupAction_scope.
Notation "to \o f" := (comp_groupAction to f) : groupAction_scope.
(* Operator group isomorphism. *)
Section MorphAction.
Variables (aT1 aT2 : finGroupType) (rT1 rT2 : finType).
Variables (D1 : {group aT1}) (D2 : {group aT2}).
Variables (to1 : action D1 rT1) (to2 : action D2 rT2).
Variables (A : {set aT1}) (R S : {set rT1}).
Variables (h : rT1 -> rT2) (f : {morphism D1 >-> aT2}).
Hypotheses (actsDR : {acts D1, on R | to1}) (injh : {in R &, injective h}).
Hypothesis defD2 : f @* D1 = D2.
Hypotheses (sSR : S \subset R) (sAD1 : A \subset D1).
Hypothesis hfJ : {in S & D1, morph_act to1 to2 h f}.
Lemma morph_astabs : f @* 'N(S | to1) = 'N(h @: S | to2).
Proof.
apply/setP=> fx; apply/morphimP/idP=> [[x D1x nSx ->] | nSx].
rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->].
by rewrite inE -hfJ ?imset_f // (astabs_act _ nSx).
have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1).
by rewrite defD2 (astabs_dom nSx).
exists x => //; rewrite !inE D1x; apply/subsetP=> u Su.
have /imsetP[u' Su' /injh def_u']: h (to1 u x) \in h @: S.
by rewrite hfJ // -def_fx (astabs_act _ nSx) imset_f.
by rewrite inE def_u' ?actsDR ?(subsetP sSR).
Qed.
Lemma morph_astab : f @* 'C(S | to1) = 'C(h @: S | to2).
Proof.
apply/setP=> fx; apply/morphimP/idP=> [[x D1x cSx ->] | cSx].
rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->].
by rewrite inE -hfJ // (astab_act cSx).
have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1).
by rewrite defD2 (astab_dom cSx).
exists x => //; rewrite !inE D1x; apply/subsetP=> u Su.
rewrite inE -(inj_in_eq injh) ?actsDR ?(subsetP sSR) ?hfJ //.
by rewrite -def_fx (astab_act cSx) ?imset_f.
Qed.
Lemma morph_afix : h @: 'Fix_(S | to1)(A) = 'Fix_(h @: S | to2)(f @* A).
Proof.
apply/setP=> hu; apply/imsetP/setIP=> [[u /setIP[Su cAu] ->]|].
split; first by rewrite imset_f.
by apply/afixP=> _ /morphimP[x D1x Ax ->]; rewrite -hfJ ?(afixP cAu).
case=> /imsetP[u Su ->] /afixP c_hu_fA; exists u; rewrite // inE Su.
apply/afixP=> x Ax; have Dx := subsetP sAD1 x Ax.
by apply: injh; rewrite ?actsDR ?(subsetP sSR) ?hfJ // c_hu_fA ?mem_morphim.
Qed.
End MorphAction.
Section MorphGroupAction.
Variables (aT1 aT2 rT1 rT2 : finGroupType).
Variables (D1 : {group aT1}) (D2 : {group aT2}).
Variables (R1 : {group rT1}) (R2 : {group rT2}).
Variables (to1 : groupAction D1 R1) (to2 : groupAction D2 R2).
Variables (h : {morphism R1 >-> rT2}) (f : {morphism D1 >-> aT2}).
Hypotheses (iso_h : isom R1 R2 h) (iso_f : isom D1 D2 f).
Hypothesis hfJ : {in R1 & D1, morph_act to1 to2 h f}.
Implicit Types (A : {set aT1}) (S : {set rT1}) (M : {group rT1}).
Lemma morph_gastabs S : S \subset R1 -> f @* 'N(S | to1) = 'N(h @* S | to2).
Proof.
have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h).
move=> sSR1; rewrite (morphimEsub _ sSR1).
apply: (morph_astabs (gact_stable to1) (injmP injh)) => // u x.
by move/(subsetP sSR1); apply: hfJ.
Qed.
Lemma morph_gastab S : S \subset R1 -> f @* 'C(S | to1) = 'C(h @* S | to2).
Proof.
have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h).
move=> sSR1; rewrite (morphimEsub _ sSR1).
apply: (morph_astab (gact_stable to1) (injmP injh)) => // u x.
by move/(subsetP sSR1); apply: hfJ.
Qed.
Lemma morph_gacent A : A \subset D1 -> h @* 'C_(|to1)(A) = 'C_(|to2)(f @* A).
Proof.
have [[_ defD2] [injh defR2]] := (isomP iso_f, isomP iso_h).
move=> sAD1; rewrite !gacentE //; last by rewrite -defD2 morphimS.
rewrite morphimEsub ?subsetIl // -{1}defR2 morphimEdom.
exact: (morph_afix (gact_stable to1) (injmP injh)).
Qed.
Lemma morph_gact_irr A M :
A \subset D1 -> M \subset R1 ->
acts_irreducibly (f @* A) (h @* M) to2 = acts_irreducibly A M to1.
Proof.
move=> sAD1 sMR1.
have [[injf defD2] [injh defR2]] := (isomP iso_f, isomP iso_h).
have h_eq1 := morphim_injm_eq1 injh.
apply/mingroupP/mingroupP=> [] [/andP[ntM actAM] minM].
split=> [|U]; first by rewrite -h_eq1 // ntM -(injmSK injf) ?morph_gastabs.
case/andP=> ntU acts_fAU sUM; have sUR1 := subset_trans sUM sMR1.
apply: (injm_morphim_inj injh) => //; apply: minM; last exact: morphimS.
by rewrite h_eq1 // ntU -morph_gastabs ?morphimS.
split=> [|U]; first by rewrite h_eq1 // ntM -morph_gastabs ?morphimS.
case/andP=> ntU acts_fAU sUhM.
have sUhR1 := subset_trans sUhM (morphimS h sMR1).
have sU'M: h @*^-1 U \subset M by rewrite sub_morphpre_injm.
rewrite /= -(minM _ _ sU'M) ?morphpreK // -h_eq1 ?subsetIl // -(injmSK injf) //.
by rewrite morph_gastabs ?(subset_trans sU'M) // morphpreK ?ntU.
Qed.
End MorphGroupAction.
(* Conjugation and right translation actions. *)
Section InternalActionDefs.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Implicit Type G : {group gT}.
(* This is not a Canonical action because it is seldom used, and it would *)
(* cause too many spurious matches (any group product would be viewed as an *)
(* action!). *)
Definition mulgr_action := TotalAction (@mulg1 gT) (@mulgA gT).
Canonical conjg_action := TotalAction (@conjg1 gT) (@conjgM gT).
Lemma conjg_is_groupAction : is_groupAction setT conjg_action.
Proof.
move=> a _; rewrite inE; apply/andP; split; first by apply/subsetP=> x /[1!inE].
by apply/morphicP=> x y _ _; rewrite !actpermE /= conjMg.
Qed.
Canonical conjg_groupAction := GroupAction conjg_is_groupAction.
Lemma rcoset_is_action : is_action setT (@rcoset gT).
Proof.
by apply: is_total_action => [A|A x y]; rewrite !rcosetE (mulg1, rcosetM).
Qed.
Canonical rcoset_action := Action rcoset_is_action.
Canonical conjsg_action := TotalAction (@conjsg1 gT) (@conjsgM gT).
Lemma conjG_is_action : is_action setT (@conjG_group gT).
Proof.
apply: is_total_action => [G | G x y]; apply: val_inj; rewrite /= ?act1 //.
exact: actM.
Qed.
Definition conjG_action := Action conjG_is_action.
End InternalActionDefs.
Notation "'R" := (@mulgr_action _) : action_scope.
Notation "'Rs" := (@rcoset_action _) : action_scope.
Notation "'J" := (@conjg_action _) : action_scope.
Notation "'J" := (@conjg_groupAction _) : groupAction_scope.
Notation "'Js" := (@conjsg_action _) : action_scope.
Notation "'JG" := (@conjG_action _) : action_scope.
Notation "'Q" := ('J / _)%act : action_scope.
Notation "'Q" := ('J / _)%gact : groupAction_scope.
Section InternalGroupAction.
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H : {group gT}.
Implicit Type x : gT.
(* Various identities for actions on groups. *)
Lemma orbitR G x : orbit 'R G x = x *: G.
Proof. by rewrite -lcosetE. Qed.
Lemma astab1R x : 'C[x | 'R] = 1.
Proof.
apply/trivgP/subsetP=> y cxy.
by rewrite -(mulKg x y) [x * y](astab1P cxy) mulVg set11.
Qed.
Lemma astabR G : 'C(G | 'R) = 1.
Proof.
apply/trivgP/subsetP=> x cGx.
by rewrite -(mul1g x) [1 * x](astabP cGx) group1.
Qed.
Lemma astabsR G : 'N(G | 'R) = G.
Proof.
apply/setP=> x; rewrite !inE -setactVin ?inE //=.
by rewrite -groupV -{1 3}(mulg1 G) rcoset_sym -sub1set -mulGS -!rcosetE.
Qed.
Lemma atransR G : [transitive G, on G | 'R].
Proof. by rewrite /atrans -{1}(mul1g G) -orbitR imset_f. Qed.
Lemma faithfulR G : [faithful G, on G | 'R].
Proof. by rewrite /faithful astabR subsetIr. Qed.
Definition Cayley_repr G := actperm <[atrans_acts (atransR G)]>.
Theorem Cayley_isom G : isom G (Cayley_repr G @* G) (Cayley_repr G).
Proof. exact: faithful_isom (faithfulR G). Qed.
Theorem Cayley_isog G : G \isog Cayley_repr G @* G.
Proof. exact: isom_isog (Cayley_isom G). Qed.
Lemma orbitJ G x : orbit 'J G x = x ^: G. Proof. by []. Qed.
Lemma afixJ A : 'Fix_('J)(A) = 'C(A).
Proof.
apply/setP=> x; apply/afixP/centP=> cAx y Ay /=.
by rewrite /commute conjgC cAx.
by rewrite conjgE cAx ?mulKg.
Qed.
Lemma astabJ A : 'C(A |'J) = 'C(A).
Proof.
apply/setP=> x; apply/astabP/centP=> cAx y Ay /=.
by apply: esym; rewrite conjgC cAx.
by rewrite conjgE -cAx ?mulKg.
Qed.
Lemma astab1J x : 'C[x |'J] = 'C[x].
Proof. by rewrite astabJ cent_set1. Qed.
Lemma astabsJ A : 'N(A | 'J) = 'N(A).
Proof. by apply/setP=> x; rewrite -2!groupV !inE -conjg_preim -sub_conjg. Qed.
Lemma setactJ A x : 'J^*%act A x = A :^ x. Proof. by []. Qed.
Lemma gacentJ A : 'C_(|'J)(A) = 'C(A).
Proof. by rewrite gacentE ?setTI ?subsetT ?afixJ. Qed.
Lemma orbitRs G A : orbit 'Rs G A = rcosets A G. Proof. by []. Qed.
Lemma sub_afixRs_norms G x A : (G :* x \in 'Fix_('Rs)(A)) = (A \subset G :^ x).
Proof.
rewrite inE /=; apply: eq_subset_r => a.
rewrite inE rcosetE -(can2_eq (rcosetKV x) (rcosetK x)) -!rcosetM.
rewrite eqEcard card_rcoset leqnn andbT mulgA (conjgCV x) mulgK.
by rewrite -{2 3}(mulGid G) mulGS sub1set -mem_conjg.
Qed.
Lemma sub_afixRs_norm G x : (G :* x \in 'Fix_('Rs)(G)) = (x \in 'N(G)).
Proof. by rewrite sub_afixRs_norms -groupV inE sub_conjgV. Qed.
Lemma afixRs_rcosets A G : 'Fix_(rcosets G A | 'Rs)(G) = rcosets G 'N_A(G).
Proof.
apply/setP=> Gx; apply/setIP/rcosetsP=> [[/rcosetsP[x Ax ->]]|[x]].
by rewrite sub_afixRs_norm => Nx; exists x; rewrite // inE Ax.
by case/setIP=> Ax Nx ->; rewrite -{1}rcosetE imset_f // sub_afixRs_norm.
Qed.
Lemma astab1Rs G : 'C[G : {set gT} | 'Rs] = G.
Proof.
apply/setP=> x.
by apply/astab1P/idP=> /= [<- | Gx]; rewrite rcosetE ?rcoset_refl ?rcoset_id.
Qed.
Lemma actsRs_rcosets H G : [acts G, on rcosets H G | 'Rs].
Proof. by rewrite -orbitRs acts_orbit ?subsetT. Qed.
Lemma transRs_rcosets H G : [transitive G, on rcosets H G | 'Rs].
Proof. by rewrite -orbitRs atrans_orbit. Qed.
(* This is the second part of Aschbacher (5.7) *)
Lemma astabRs_rcosets H G : 'C(rcosets H G | 'Rs) = gcore H G.
Proof.
have transGH := transRs_rcosets H G.
by rewrite (astab_trans_gcore transGH (orbit_refl _ G _)) astab1Rs.
Qed.
Lemma orbitJs G A : orbit 'Js G A = A :^: G. Proof. by []. Qed.
Lemma astab1Js A : 'C[A | 'Js] = 'N(A).
Proof. by apply/setP=> x; apply/astab1P/normP. Qed.
Lemma card_conjugates A G : #|A :^: G| = #|G : 'N_G(A)|.
Proof. by rewrite card_orbit astab1Js. Qed.
Lemma afixJG G A : (G \in 'Fix_('JG)(A)) = (A \subset 'N(G)).
Proof. by apply/afixP/normsP=> nG x Ax; apply/eqP; move/eqP: (nG x Ax). Qed.
Lemma astab1JG G : 'C[G | 'JG] = 'N(G).
Proof.
by apply/setP=> x; apply/astab1P/normP=> [/congr_group | /group_inj].
Qed.
Lemma dom_qactJ H : qact_dom 'J H = 'N(H).
Proof. by rewrite qact_domE ?subsetT ?astabsJ. Qed.
Lemma qactJ H (Hy : coset_of H) x :
'Q%act Hy x = if x \in 'N(H) then Hy ^ coset H x else Hy.
Proof.
case: (cosetP Hy) => y Ny ->{Hy}.
by rewrite qactEcond // dom_qactJ; case Nx: (x \in 'N(H)); rewrite ?morphJ.
Qed.
Lemma actsQ A B H :
A \subset 'N(H) -> A \subset 'N(B) -> [acts A, on B / H | 'Q].
Proof.
by move=> nHA nBA; rewrite acts_quotient // subsetI dom_qactJ nHA astabsJ.
Qed.
Lemma astabsQ G H : H <| G -> 'N(G / H | 'Q) = 'N(H) :&: 'N(G).
Proof. by move=> nsHG; rewrite astabs_quotient // dom_qactJ astabsJ. Qed.
Lemma astabQ H Abar : 'C(Abar |'Q) = coset H @*^-1 'C(Abar).
Proof.
apply/setP=> x; rewrite inE /= dom_qactJ morphpreE in_setI /=.
apply: andb_id2l => Nx; rewrite !inE -sub1set centsC cent_set1.
apply: eq_subset_r => {Abar} Hy; rewrite inE qactJ Nx (sameP eqP conjg_fixP).
by rewrite (sameP cent1P eqP) (sameP commgP eqP).
Qed.
Lemma sub_astabQ A H Bbar :
(A \subset 'C(Bbar | 'Q)) = (A \subset 'N(H)) && (A / H \subset 'C(Bbar)).
Proof.
rewrite astabQ -morphpreIdom subsetI; apply: andb_id2l => nHA.
by rewrite -sub_quotient_pre.
Qed.
Lemma sub_astabQR A B H :
A \subset 'N(H) -> B \subset 'N(H) ->
(A \subset 'C(B / H | 'Q)) = ([~: A, B] \subset H).
Proof.
move=> nHA nHB; rewrite sub_astabQ nHA /= (sameP commG1P eqP).
by rewrite eqEsubset sub1G andbT -quotientR // quotient_sub1 // comm_subG.
Qed.
Lemma astabQR A H : A \subset 'N(H) ->
'C(A / H | 'Q) = [set x in 'N(H) | [~: [set x], A] \subset H].
Proof.
move=> nHA; apply/setP=> x; rewrite astabQ -morphpreIdom 2!inE -astabQ.
by case nHx: (x \in _); rewrite //= -sub1set sub_astabQR ?sub1set.
Qed.
Lemma quotient_astabQ H Abar : 'C(Abar | 'Q) / H = 'C(Abar).
Proof. by rewrite astabQ cosetpreK. Qed.
Lemma conj_astabQ A H x :
x \in 'N(H) -> 'C(A / H | 'Q) :^ x = 'C(A :^ x / H | 'Q).
Proof.
move=> nHx; apply/setP=> y; rewrite !astabQ mem_conjg !in_setI -mem_conjg.
rewrite -normJ (normP nHx) quotientJ //; apply/andb_id2l => nHy.
by rewrite !inE centJ morphJ ?groupV ?morphV // -mem_conjg.
Qed.
Section CardClass.
Variable G : {group gT}.
Lemma index_cent1 x : #|G : 'C_G[x]| = #|x ^: G|.
Proof. by rewrite -astab1J -card_orbit. Qed.
Lemma classes_partition : partition (classes G) G.
Proof. by apply: orbit_partition; apply/actsP=> x Gx y; apply: groupJr. Qed.
Lemma sum_card_class : \sum_(C in classes G) #|C| = #|G|.
Proof. by apply: acts_sum_card_orbit; apply/actsP=> x Gx y; apply: groupJr. Qed.
Lemma class_formula : \sum_(C in classes G) #|G : 'C_G[repr C]| = #|G|.
Proof.
rewrite -sum_card_class; apply: eq_bigr => _ /imsetP[x Gx ->].
have: x \in x ^: G by rewrite -{1}(conjg1 x) imset_f.
by case/mem_repr/imsetP=> y Gy ->; rewrite index_cent1 classGidl.
Qed.
Lemma abelian_classP : reflect {in G, forall x, x ^: G = [set x]} (abelian G).
Proof.
rewrite /abelian -astabJ astabC.
by apply: (iffP subsetP) => cGG x Gx; apply/orbit1P; apply: cGG.
Qed.
Lemma card_classes_abelian : abelian G = (#|classes G| == #|G|).
Proof.
have cGgt0 C: C \in classes G -> 1 <= #|C| ?= iff (#|C| == 1)%N.
by case/imsetP=> x _ ->; rewrite eq_sym -index_cent1.
rewrite -sum_card_class -sum1_card (leqif_sum cGgt0).
apply/abelian_classP/forall_inP=> [cGG _ /imsetP[x Gx ->]| cGG x Gx].
by rewrite cGG ?cards1.
apply/esym/eqP; rewrite eqEcard sub1set cards1 class_refl leq_eqVlt cGG //.
exact: imset_f.
Qed.
End CardClass.
End InternalGroupAction.
Lemma gacentQ (gT : finGroupType) (H : {group gT}) (A : {set gT}) :
'C_(|'Q)(A) = 'C(A / H).
Proof.
apply/setP=> Hx; case: (cosetP Hx) => x Nx ->{Hx}.
rewrite -sub_cent1 -astab1J astabC sub1set -(quotientInorm H A).
have defD: qact_dom 'J H = 'N(H) by rewrite qact_domE ?subsetT ?astabsJ.
rewrite !(inE, mem_quotient) //= defD setIC.
apply/subsetP/subsetP=> [cAx _ /morphimP[a Na Aa ->] | cAx a Aa].
by move/cAx: Aa; rewrite !inE qactE ?defD ?morphJ.
have [_ Na] := setIP Aa; move/implyP: (cAx (coset H a)); rewrite mem_morphim //.
by rewrite !inE qactE ?defD ?morphJ.
Qed.
Section AutAct.
Variable (gT : finGroupType) (G : {set gT}).
Definition autact := act ('P \ subsetT (Aut G)).
Canonical aut_action := [action of autact].
Lemma autactK a : actperm aut_action a = a.
Proof. by apply/permP=> x; rewrite permE. Qed.
Lemma autact_is_groupAction : is_groupAction G aut_action.
Proof. by move=> a Aa /=; rewrite autactK. Qed.
Canonical aut_groupAction := GroupAction autact_is_groupAction.
Section perm_prime_orbit.
Variable (T : finType) (c : {perm T}).
Hypothesis Tp : prime #|T|.
Hypothesis cc : #[c]%g = #|T|.
Let cp : prime #[c]%g. Proof. by rewrite cc. Qed.
Lemma perm_prime_atrans : [transitive <[c]>, on setT | 'P].
Proof.
apply/imsetP; suff /existsP[x] : [exists x, ~~ (#|orbit 'P <[c]> x| < #[c])].
move=> oxT; suff /eqP orbit_x : orbit 'P <[c]> x == setT by exists x.
by rewrite eqEcard subsetT cardsT -cc leqNgt.
apply/forallP => olT; have o1 x : #|orbit 'P <[c]> x| == 1%N.
by case/primeP: cp => _ /(_ _ (dvdn_orbit 'P _ x))/orP[]//; rewrite ltn_eqF.
suff c1 : c = 1%g by rewrite c1 ?order1 in (cp).
apply/permP => x; rewrite perm1; apply/set1P.
by rewrite -(card_orbit1 (eqP (o1 _))) (mem_orbit 'P) ?cycle_id.
Qed.
Lemma perm_prime_orbit x : orbit 'P <[c]> x = [set: T].
Proof. by apply: atransP => //; apply: perm_prime_atrans. Qed.
Lemma perm_prime_astab x : 'C_<[c]>[x | 'P]%g = 1%g.
Proof.
by apply/card1_trivg/eqP; rewrite -(@eqn_pmul2l #|orbit 'P <[c]> x|)
?card_orbit_stab ?perm_prime_orbit ?cardsT ?muln1 ?prime_gt0// -cc.
Qed.
End perm_prime_orbit.
End AutAct.
Arguments autact {gT} G%_g.
Arguments aut_action {gT} G%_g.
Arguments aut_groupAction {gT} G%_g.
Notation "[ 'Aut' G ]" := (aut_action G) : action_scope.
Notation "[ 'Aut' G ]" := (aut_groupAction G) : groupAction_scope.
|
Removal.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.Combinatorics.SimpleGraph.DegreeSum
import Mathlib.Combinatorics.SimpleGraph.Regularity.Lemma
import Mathlib.Combinatorics.SimpleGraph.Triangle.Basic
import Mathlib.Combinatorics.SimpleGraph.Triangle.Counting
import Mathlib.Data.Finset.CastCard
/-!
# Triangle removal lemma
In this file, we prove the triangle removal lemma.
## References
[Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp]
-/
open Finset Fintype Nat SzemerediRegularity
variable {α : Type*} [DecidableEq α] [Fintype α] {G : SimpleGraph α} [DecidableRel G.Adj]
{s t : Finset α} {P : Finpartition (univ : Finset α)} {ε : ℝ}
namespace SimpleGraph
/-- An explicit form for the constant in the triangle removal lemma.
Note that this depends on `SzemerediRegularity.bound`, which is a tower-type exponential. This means
`triangleRemovalBound` is in practice absolutely tiny. -/
noncomputable def triangleRemovalBound (ε : ℝ) : ℝ :=
min (2 * ⌈4/ε⌉₊^3)⁻¹ ((1 - ε/4) * (ε/(16 * bound (ε/8) ⌈4/ε⌉₊))^3)
lemma triangleRemovalBound_pos (hε : 0 < ε) (hε₁ : ε ≤ 1) : 0 < triangleRemovalBound ε := by
have : 0 < 1 - ε / 4 := by linarith
unfold triangleRemovalBound
positivity
lemma triangleRemovalBound_nonpos (hε : ε ≤ 0) : triangleRemovalBound ε ≤ 0 := by
rw [triangleRemovalBound, ceil_eq_zero.2 (div_nonpos_of_nonneg_of_nonpos _ hε)] <;> simp
lemma triangleRemovalBound_mul_cube_lt (hε : 0 < ε) :
triangleRemovalBound ε * ⌈4 / ε⌉₊ ^ 3 < 1 := by
calc
_ ≤ (2 * ⌈4 / ε⌉₊ ^ 3 : ℝ)⁻¹ * ↑⌈4 / ε⌉₊ ^ 3 := by gcongr; exact min_le_left _ _
_ = 2⁻¹ := by rw [mul_inv, inv_mul_cancel_right₀]; positivity
_ < 1 := by norm_num
private lemma aux {n k : ℕ} (hk : 0 < k) (hn : k ≤ n) : n < 2 * k * (n / k) := by
rw [mul_assoc, two_mul, ← add_lt_add_iff_right (n % k), add_right_comm, add_assoc,
mod_add_div n k, add_comm, add_lt_add_iff_right]
apply (mod_lt n hk).trans_le
simpa using Nat.mul_le_mul_left k ((Nat.one_le_div_iff hk).2 hn)
private lemma card_bound (hP₁ : P.IsEquipartition) (hP₃ : #P.parts ≤ bound (ε / 8) ⌈4 / ε⌉₊)
(hX : s ∈ P.parts) : card α / (2 * bound (ε / 8) ⌈4 / ε⌉₊ : ℝ) ≤ #s := by
cases isEmpty_or_nonempty α
· simp [Fintype.card_eq_zero]
have := Finset.Nonempty.card_pos ⟨_, hX⟩
calc
_ ≤ card α / (2 * #P.parts : ℝ) := by gcongr
_ ≤ ↑(card α / #P.parts) :=
(div_le_iff₀' (by positivity)).2 <| mod_cast (aux ‹_› P.card_parts_le_card).le
_ ≤ (#s : ℝ) := mod_cast hP₁.average_le_card_part hX
private lemma triangle_removal_aux (hε : 0 < ε) (hP₁ : P.IsEquipartition)
(hP₃ : #P.parts ≤ bound (ε / 8) ⌈4 / ε⌉₊)
(ht : t ∈ (G.regularityReduced P (ε / 8) (ε / 4)).cliqueFinset 3) :
triangleRemovalBound ε * card α ^ 3 ≤ #(G.cliqueFinset 3) := by
rw [mem_cliqueFinset_iff, is3Clique_iff] at ht
obtain ⟨x, y, z, ⟨-, s, hX, Y, hY, xX, yY, nXY, uXY, dXY⟩,
⟨-, X', hX', Z, hZ, xX', zZ, nXZ, uXZ, dXZ⟩,
⟨-, Y', hY', Z', hZ', yY', zZ', nYZ, uYZ, dYZ⟩, rfl⟩ := ht
cases P.disjoint.elim hX hX' (not_disjoint_iff.2 ⟨x, xX, xX'⟩)
cases P.disjoint.elim hY hY' (not_disjoint_iff.2 ⟨y, yY, yY'⟩)
cases P.disjoint.elim hZ hZ' (not_disjoint_iff.2 ⟨z, zZ, zZ'⟩)
have dXY := P.disjoint hX hY nXY
have dXZ := P.disjoint hX hZ nXZ
have dYZ := P.disjoint hY hZ nYZ
have that : 2 * (ε/8) = ε/4 := by ring
have : 0 ≤ 1 - 2 * (ε / 8) := by
have : ε / 4 ≤ 1 := ‹ε / 4 ≤ _›.trans (by exact mod_cast G.edgeDensity_le_one _ _); linarith
calc
_ ≤ (1 - ε/4) * (ε/(16 * bound (ε/8) ⌈4/ε⌉₊))^3 * card α ^ 3 := by
gcongr; exact min_le_right _ _
_ = (1 - 2 * (ε / 8)) * (ε / 8) ^ 3 * (card α / (2 * bound (ε / 8) ⌈4 / ε⌉₊)) *
(card α / (2 * bound (ε / 8) ⌈4 / ε⌉₊)) * (card α / (2 * bound (ε / 8) ⌈4 / ε⌉₊)) := by
ring
_ ≤ (1 - 2 * (ε / 8)) * (ε / 8) ^ 3 * #s * #Y * #Z := by
gcongr <;> exact card_bound hP₁ hP₃ ‹_›
_ ≤ _ :=
triangle_counting G (by rwa [that]) uXY dXY (by rwa [that]) uXZ dXZ (by rwa [that]) uYZ dYZ
lemma regularityReduced_edges_card_aux [Nonempty α] (hε : 0 < ε) (hP : P.IsEquipartition)
(hPε : P.IsUniform G (ε / 8)) (hP' : 4 / ε ≤ #P.parts) :
2 * (#G.edgeFinset - #(G.regularityReduced P (ε/8) (ε/4)).edgeFinset : ℝ)
< 2 * ε * (card α ^ 2 : ℕ) := by
let A := (P.nonUniforms G (ε/8)).biUnion fun (U, V) ↦ U ×ˢ V
let B := P.parts.biUnion offDiag
let C := (P.sparsePairs G (ε/4)).biUnion fun (U, V) ↦ G.interedges U V
calc
_ = (#((univ ×ˢ univ).filter fun (x, y) ↦
G.Adj x y ∧ ¬(G.regularityReduced P (ε / 8) (ε /4)).Adj x y) : ℝ) := by
rw [univ_product_univ, mul_sub, filter_and_not, cast_card_sdiff]
· norm_cast
rw [two_mul_card_edgeFinset, two_mul_card_edgeFinset]
· exact monotone_filter_right _ fun xy hxy ↦ regularityReduced_le hxy
_ ≤ #(A ∪ B ∪ C) := by gcongr; exact unreduced_edges_subset
_ ≤ #(A ∪ B) + #C := mod_cast (card_union_le _ _)
_ ≤ #A + #B + #C := by gcongr; exact mod_cast card_union_le _ _
_ < 4 * (ε / 8) * card α ^ 2 + _ + _ := by
gcongr; exact hP.sum_nonUniforms_lt univ_nonempty (by positivity) hPε
_ ≤ _ + ε / 2 * card α ^ 2 + 4 * (ε / 4) * card α ^ 2 := by
gcongr
· exact hP.card_biUnion_offDiag_le hε hP'
· exact hP.card_interedges_sparsePairs_le (G := G) (ε := ε / 4) (by positivity)
_ = 2 * ε * (card α ^ 2 : ℕ) := by norm_cast; ring
/-- **Triangle Removal Lemma**. If not all triangles can be removed by removing few edges (on the
order of `(card α)^2`), then there were many triangles to start with (on the order of
`(card α)^3`). -/
lemma FarFromTriangleFree.le_card_cliqueFinset (hG : G.FarFromTriangleFree ε) :
triangleRemovalBound ε * card α ^ 3 ≤ #(G.cliqueFinset 3) := by
cases isEmpty_or_nonempty α
· simp [Fintype.card_eq_zero]
obtain hε | hε := le_or_gt ε 0
· apply (mul_nonpos_of_nonpos_of_nonneg (triangleRemovalBound_nonpos hε) _).trans <;> positivity
let l : ℕ := ⌈4 / ε⌉₊
have hl : 4/ε ≤ l := le_ceil (4/ε)
rcases le_total (card α) l with hl' | hl'
· calc
_ ≤ triangleRemovalBound ε * ↑l ^ 3 := by
gcongr; exact (triangleRemovalBound_pos hε hG.lt_one.le).le
_ ≤ (1 : ℝ) := (triangleRemovalBound_mul_cube_lt hε).le
_ ≤ _ := by simpa [one_le_iff_ne_zero] using (hG.cliqueFinset_nonempty hε).card_pos.ne'
obtain ⟨P, hP₁, hP₂, hP₃, hP₄⟩ := szemeredi_regularity G (by positivity : 0 < ε / 8) hl'
have : 4/ε ≤ #P.parts := hl.trans (cast_le.2 hP₂)
have k := regularityReduced_edges_card_aux hε hP₁ hP₄ this
rw [mul_assoc] at k
replace k := lt_of_mul_lt_mul_left k zero_le_two
obtain ⟨t, ht⟩ := hG.cliqueFinset_nonempty' regularityReduced_le k
exact triangle_removal_aux hε hP₁ hP₃ ht
/-- **Triangle Removal Lemma**. If there are not too many triangles (on the order of `(card α)^3`)
then they can all be removed by removing a few edges (on the order of `(card α)^2`). -/
lemma triangle_removal (hG : #(G.cliqueFinset 3) < triangleRemovalBound ε * card α ^ 3) :
∃ G' ≤ G, ∃ _ : DecidableRel G'.Adj,
(#G.edgeFinset - #G'.edgeFinset : ℝ) < ε * (card α^2 : ℕ) ∧ G'.CliqueFree 3 := by
by_contra! h
refine hG.not_ge (farFromTriangleFree_iff.2 ?_).le_card_cliqueFinset
intros G' _ hG hG'
exact le_of_not_gt fun i ↦ h G' hG _ i hG'
end SimpleGraph
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq SimpleGraph
/-- Extension for the `positivity` tactic: `SimpleGraph.triangleRemovalBound ε` is positive if
`0 < ε ≤ 1`.
Note this looks for `ε ≤ 1` in the context. -/
@[positivity triangleRemovalBound _]
def evalTriangleRemovalBound : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(triangleRemovalBound $ε) =>
let some hε₁ ← findLocalDeclWithTypeQ? q($ε ≤ 1) | failure
let .positive hε ← core q(inferInstance) q(inferInstance) ε | failure
assertInstancesCommute
pure (.positive q(triangleRemovalBound_pos $hε $hε₁))
| _, _, _ => throwError "failed to match on Int.ceil application"
example (ε : ℝ) (hε₀ : 0 < ε) (hε₁ : ε ≤ 1) : 0 < triangleRemovalBound ε := by positivity
end Mathlib.Meta.Positivity
|
AddContent.lean
|
/-
Copyright (c) 2024 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Peter Pfaffelhuber
-/
import Mathlib.MeasureTheory.SetSemiring
import Mathlib.MeasureTheory.OuterMeasure.Induced
/-!
# Additive Contents
An additive content `m` on a set of sets `C` is a set function with value 0 at the empty set which
is finitely additive on `C`. That means that for any finset `I` of pairwise disjoint sets in `C`
such that `⋃₀ I ∈ C`, `m (⋃₀ I) = ∑ s ∈ I, m s`.
Mathlib also has a definition of contents over compact sets: see `MeasureTheory.Content`.
A `Content` is in particular an `AddContent` on the set of compact sets.
## Main definitions
* `MeasureTheory.AddContent C`: additive contents over the set of sets `C`.
* `MeasureTheory.AddContent.IsSigmaSubadditive`: an `AddContent` is σ-subadditive if
`m (⋃ i, f i) ≤ ∑' i, m (f i)` for any sequence of sets `f` in `C` such that `⋃ i, f i ∈ C`.
## Main statements
Let `m` be an `AddContent C`. If `C` is a set semi-ring (`IsSetSemiring C`) we have the properties
* `MeasureTheory.sum_addContent_le_of_subset`: if `I` is a finset of pairwise disjoint sets in `C`
and `⋃₀ I ⊆ t` for `t ∈ C`, then `∑ s ∈ I, m s ≤ m t`.
* `MeasureTheory.addContent_mono`: if `s ⊆ t` for two sets in `C`, then `m s ≤ m t`.
* `MeasureTheory.addContent_sUnion_le_sum`: an `AddContent C` on a `SetSemiring C` is
sub-additive.
* `MeasureTheory.addContent_iUnion_eq_tsum_of_disjoint_of_addContent_iUnion_le`: if an
`AddContent` is σ-subadditive on a semi-ring of sets, then it is σ-additive.
* `MeasureTheory.addContent_union'`: if `s, t ∈ C` are disjoint and `s ∪ t ∈ C`,
then `m (s ∪ t) = m s + m t`.
If `C` is a set ring (`IsSetRing`), then `addContent_union` gives the same conclusion without the
hypothesis `s ∪ t ∈ C` (since it is a consequence of `IsSetRing C`).
If `C` is a set ring (`MeasureTheory.IsSetRing C`), we have
* `MeasureTheory.addContent_union_le`: for `s, t ∈ C`, `m (s ∪ t) ≤ m s + m t`
* `MeasureTheory.addContent_le_diff`: for `s, t ∈ C`, `m s - m t ≤ m (s \ t)`
* `IsSetRing.addContent_of_union`: a function on a ring of sets which is additive on pairs of
disjoint sets defines an additive content
* `addContent_iUnion_eq_sum_of_tendsto_zero`: if an additive content is continuous at `∅`, then
its value on a countable disjoint union is the sum of the values
* `MeasureTheory.isSigmaSubadditive_of_addContent_iUnion_eq_tsum`: if an `AddContent` is
σ-additive on a set ring, then it is σ-subadditive.
-/
open Set Finset Function Filter
open scoped ENNReal Topology Function
namespace MeasureTheory
variable {α : Type*} {C : Set (Set α)} {s t : Set α} {I : Finset (Set α)}
/-- An additive content is a set function with value 0 at the empty set which is finitely additive
on a given set of sets. -/
structure AddContent (C : Set (Set α)) where
/-- The value of the content on a set. -/
toFun : Set α → ℝ≥0∞
empty' : toFun ∅ = 0
sUnion' (I : Finset (Set α)) (_h_ss : ↑I ⊆ C)
(_h_dis : PairwiseDisjoint (I : Set (Set α)) id) (_h_mem : ⋃₀ ↑I ∈ C) :
toFun (⋃₀ I) = ∑ u ∈ I, toFun u
instance : Inhabited (AddContent C) :=
⟨{toFun := fun _ => 0
empty' := by simp
sUnion' := by simp }⟩
instance : FunLike (AddContent C) (Set α) ℝ≥0∞ where
coe m s := m.toFun s
coe_injective' m m' _ := by
cases m
cases m'
congr
variable {m m' : AddContent C}
@[ext] protected lemma AddContent.ext (h : ∀ s, m s = m' s) : m = m' :=
DFunLike.ext _ _ h
@[simp] lemma addContent_empty : m ∅ = 0 := m.empty'
lemma addContent_sUnion (h_ss : ↑I ⊆ C)
(h_dis : PairwiseDisjoint (I : Set (Set α)) id) (h_mem : ⋃₀ ↑I ∈ C) :
m (⋃₀ I) = ∑ u ∈ I, m u :=
m.sUnion' I h_ss h_dis h_mem
lemma addContent_union' (hs : s ∈ C) (ht : t ∈ C) (hst : s ∪ t ∈ C) (h_dis : Disjoint s t) :
m (s ∪ t) = m s + m t := by
by_cases hs_empty : s = ∅
· simp only [hs_empty, Set.empty_union, addContent_empty, zero_add]
classical
have h := addContent_sUnion (m := m) (I := {s, t}) ?_ ?_ ?_
rotate_left
· simp only [coe_pair, Set.insert_subset_iff, hs, ht, Set.singleton_subset_iff, and_self_iff]
· simp only [coe_pair, Set.pairwiseDisjoint_insert, pairwiseDisjoint_singleton,
mem_singleton_iff, Ne, id, forall_eq, true_and]
exact fun _ => h_dis
· simp only [coe_pair, sUnion_insert, sUnion_singleton]
exact hst
convert h
· simp only [coe_pair, sUnion_insert, sUnion_singleton]
· rw [sum_insert, sum_singleton]
simp only [Finset.mem_singleton]
refine fun hs_eq_t => hs_empty ?_
rw [← hs_eq_t] at h_dis
exact Disjoint.eq_bot_of_self h_dis
/-- An additive content is said to be sigma-sub-additive if for any sequence of sets `f` in `C` such
that `⋃ i, f i ∈ C`, we have `m (⋃ i, f i) ≤ ∑' i, m (f i)`. -/
def AddContent.IsSigmaSubadditive (m : AddContent C) : Prop :=
∀ ⦃f : ℕ → Set α⦄ (_hf : ∀ i, f i ∈ C) (_hf_Union : (⋃ i, f i) ∈ C), m (⋃ i, f i) ≤ ∑' i, m (f i)
section IsSetSemiring
lemma addContent_eq_add_disjointOfDiffUnion_of_subset (hC : IsSetSemiring C)
(hs : s ∈ C) (hI : ↑I ⊆ C) (hI_ss : ∀ t ∈ I, t ⊆ s)
(h_dis : PairwiseDisjoint (I : Set (Set α)) id) :
m s = ∑ i ∈ I, m i + ∑ i ∈ hC.disjointOfDiffUnion hs hI, m i := by
classical
conv_lhs => rw [← hC.sUnion_union_disjointOfDiffUnion_of_subset hs hI hI_ss]
rw [addContent_sUnion]
· rw [sum_union]
exact hC.disjoint_disjointOfDiffUnion hs hI
· rw [coe_union]
exact Set.union_subset hI (hC.disjointOfDiffUnion_subset hs hI)
· rw [coe_union]
exact hC.pairwiseDisjoint_union_disjointOfDiffUnion hs hI h_dis
· rwa [hC.sUnion_union_disjointOfDiffUnion_of_subset hs hI hI_ss]
/-- For an `m : addContent C` on a `SetSemiring C`, if `I` is a `Finset` of pairwise disjoint
sets in `C` and `⋃₀ I ⊆ t` for `t ∈ C`, then `∑ s ∈ I, m s ≤ m t`. -/
lemma sum_addContent_le_of_subset (hC : IsSetSemiring C)
(h_ss : ↑I ⊆ C) (h_dis : PairwiseDisjoint (I : Set (Set α)) id)
(ht : t ∈ C) (hJt : ∀ s ∈ I, s ⊆ t) :
∑ u ∈ I, m u ≤ m t := by
classical
rw [addContent_eq_add_disjointOfDiffUnion_of_subset hC ht h_ss hJt h_dis]
exact le_add_right le_rfl
/-- An `addContent C` on a `SetSemiring C` is monotone. -/
lemma addContent_mono (hC : IsSetSemiring C) (hs : s ∈ C) (ht : t ∈ C)
(hst : s ⊆ t) :
m s ≤ m t := by
have h := sum_addContent_le_of_subset (m := m) hC (I := {s}) ?_ ?_ ht ?_
· simpa only [sum_singleton] using h
· rwa [singleton_subset_set_iff]
· simp only [coe_singleton, pairwiseDisjoint_singleton]
· simp [hst]
/-- For an `m : addContent C` on a `SetSemiring C` and `s t : Set α` with `s ⊆ t`, we can write
`m t = m s + ∑ i in hC.disjointOfDiff ht hs, m i`. -/
theorem eq_add_disjointOfDiff_of_subset (hC : IsSetSemiring C)
(hs : s ∈ C) (ht : t ∈ C) (hst : s ⊆ t) :
m t = m s + ∑ i ∈ hC.disjointOfDiff ht hs, m i := by
classical
conv_lhs => rw [← hC.sUnion_insert_disjointOfDiff ht hs hst]
rw [← coe_insert, addContent_sUnion]
· rw [sum_insert]
exact hC.notMem_disjointOfDiff ht hs
· rw [coe_insert]
exact Set.insert_subset hs (hC.subset_disjointOfDiff ht hs)
· rw [coe_insert]
exact hC.pairwiseDisjoint_insert_disjointOfDiff ht hs
· rw [coe_insert]
rwa [hC.sUnion_insert_disjointOfDiff ht hs hst]
/-- An `addContent C` on a `SetSemiring C` is sub-additive. -/
lemma addContent_sUnion_le_sum {m : AddContent C} (hC : IsSetSemiring C)
(J : Finset (Set α)) (h_ss : ↑J ⊆ C) (h_mem : ⋃₀ ↑J ∈ C) :
m (⋃₀ ↑J) ≤ ∑ u ∈ J, m u := by
classical
have h1 : (disjiUnion J (hC.disjointOfUnion h_ss)
(hC.pairwiseDisjoint_disjointOfUnion h_ss) : Set (Set α)) ⊆ C := by
simp only [disjiUnion_eq_biUnion, coe_biUnion, mem_coe, iUnion_subset_iff]
exact fun _ x ↦ hC.disjointOfUnion_subset h_ss x
have h2 : PairwiseDisjoint (disjiUnion J (hC.disjointOfUnion h_ss)
((hC.pairwiseDisjoint_disjointOfUnion h_ss)) : Set (Set α)) id := by
simp only [disjiUnion_eq_biUnion, coe_biUnion, mem_coe]
exact hC.pairwiseDisjoint_biUnion_disjointOfUnion h_ss
have h3 : ⋃₀ J = ⋃₀ ((disjiUnion J (hC.disjointOfUnion h_ss)
(hC.pairwiseDisjoint_disjointOfUnion h_ss)) : Set (Set α)) := by
simp only [disjiUnion_eq_biUnion, coe_biUnion, mem_coe]
exact (Exists.choose_spec (hC.disjointOfUnion_props h_ss)).2.2.2.2.2
rw [h3, addContent_sUnion h1 h2, sum_disjiUnion]
· apply sum_le_sum
intro x hx
refine sum_addContent_le_of_subset hC (hC.disjointOfUnion_subset h_ss hx)
(hC.pairwiseDisjoint_disjointOfUnion_of_mem h_ss hx) (h_ss hx)
(fun _ s ↦ hC.subset_of_mem_disjointOfUnion h_ss hx s)
· simp only [disjiUnion_eq_biUnion, coe_biUnion, mem_coe] at *
exact h3.symm ▸ h_mem
lemma addContent_le_sum_of_subset_sUnion {m : AddContent C} (hC : IsSetSemiring C)
{J : Finset (Set α)} (h_ss : ↑J ⊆ C) (ht : t ∈ C) (htJ : t ⊆ ⋃₀ ↑J) :
m t ≤ ∑ u ∈ J, m u := by
-- we can't apply `addContent_mono` and `addContent_sUnion_le_sum` because `⋃₀ ↑J` might not
-- be in `C`
classical
let Jt := J.image (fun u ↦ t ∩ u)
have ht_eq : t = ⋃₀ Jt := by
rw [coe_image, sUnion_image, ← inter_iUnion₂, inter_eq_self_of_subset_left]
rwa [← sUnion_eq_biUnion]
rw [ht_eq]
refine (addContent_sUnion_le_sum hC Jt ?_ ?_).trans ?_
· intro s
simp only [Jt, coe_image, Set.mem_image, mem_coe, forall_exists_index, and_imp]
rintro u hu rfl
exact hC.inter_mem _ ht _ (h_ss hu)
· rwa [← ht_eq]
· refine (Finset.sum_image_le_of_nonneg fun _ _ ↦ zero_le _).trans (sum_le_sum fun u hu ↦ ?_)
exact addContent_mono hC (hC.inter_mem _ ht _ (h_ss hu)) (h_ss hu) inter_subset_right
/-- If an `AddContent` is σ-subadditive on a semi-ring of sets, then it is σ-additive. -/
theorem addContent_iUnion_eq_tsum_of_disjoint_of_addContent_iUnion_le {m : AddContent C}
(hC : IsSetSemiring C)
-- TODO: `m_subadd` is in fact equivalent to `m.IsSigmaSubadditive`.
(m_subadd : ∀ (f : ℕ → Set α) (_ : ∀ i, f i ∈ C) (_ : ⋃ i, f i ∈ C)
(_hf_disj : Pairwise (Disjoint on f)), m (⋃ i, f i) ≤ ∑' i, m (f i))
(f : ℕ → Set α) (hf : ∀ i, f i ∈ C) (hf_Union : (⋃ i, f i) ∈ C)
(hf_disj : Pairwise (Disjoint on f)) :
m (⋃ i, f i) = ∑' i, m (f i) := by
refine le_antisymm (m_subadd f hf hf_Union hf_disj) ?_
refine ENNReal.summable.tsum_le_of_sum_le fun I ↦ ?_
classical
rw [← Finset.sum_image_of_disjoint addContent_empty (hf_disj.pairwiseDisjoint _)]
refine sum_addContent_le_of_subset hC (I := I.image f) ?_ ?_ hf_Union ?_
· simp only [coe_image, Set.image_subset_iff]
refine (subset_preimage_image f I).trans (preimage_mono ?_)
rintro i ⟨j, _, rfl⟩
exact hf j
· simp only [coe_image]
intro s hs t ht hst
rw [Set.mem_image] at hs ht
obtain ⟨i, _, rfl⟩ := hs
obtain ⟨j, _, rfl⟩ := ht
have hij : i ≠ j := by intro h_eq; rw [h_eq] at hst; exact hst rfl
exact hf_disj hij
· simp only [Finset.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
exact fun i _ ↦ subset_iUnion _ i
/-- If an `AddContent` is σ-subadditive on a semi-ring of sets, then it is σ-additive. -/
theorem addContent_iUnion_eq_tsum_of_disjoint_of_IsSigmaSubadditive {m : AddContent C}
(hC : IsSetSemiring C) (m_subadd : m.IsSigmaSubadditive)
(f : ℕ → Set α) (hf : ∀ i, f i ∈ C) (hf_Union : (⋃ i, f i) ∈ C)
(hf_disj : Pairwise (Disjoint on f)) :
m (⋃ i, f i) = ∑' i, m (f i) :=
addContent_iUnion_eq_tsum_of_disjoint_of_addContent_iUnion_le hC
(fun _ hf hf_Union _ ↦ m_subadd hf hf_Union) f hf hf_Union hf_disj
end IsSetSemiring
section AddContentExtend
/-- An additive content obtained from another one on the same semiring of sets by setting the value
of each set not in the semiring at `∞`. -/
protected noncomputable
def AddContent.extend (hC : IsSetSemiring C) (m : AddContent C) : AddContent C where
toFun := extend (fun x (_ : x ∈ C) ↦ m x)
empty' := by rw [extend_eq, addContent_empty]; exact hC.empty_mem
sUnion' I h_ss h_dis h_mem := by
rw [extend_eq]
swap; · exact h_mem
rw [addContent_sUnion h_ss h_dis h_mem]
refine Finset.sum_congr rfl (fun s hs ↦ ?_)
rw [extend_eq]
exact h_ss hs
protected theorem AddContent.extend_eq_extend (hC : IsSetSemiring C) (m : AddContent C) :
m.extend hC = extend (fun x (_ : x ∈ C) ↦ m x) := rfl
protected theorem AddContent.extend_eq (hC : IsSetSemiring C) (m : AddContent C) (hs : s ∈ C) :
m.extend hC s = m s := by
rwa [m.extend_eq_extend, extend_eq]
protected theorem AddContent.extend_eq_top (hC : IsSetSemiring C) (m : AddContent C) (hs : s ∉ C) :
m.extend hC s = ∞ := by
rwa [m.extend_eq_extend, extend_eq_top]
end AddContentExtend
section IsSetRing
lemma addContent_union (hC : IsSetRing C) (hs : s ∈ C) (ht : t ∈ C)
(h_dis : Disjoint s t) :
m (s ∪ t) = m s + m t :=
addContent_union' hs ht (hC.union_mem hs ht) h_dis
lemma addContent_union_le (hC : IsSetRing C) (hs : s ∈ C) (ht : t ∈ C) :
m (s ∪ t) ≤ m s + m t := by
rw [← union_diff_self, addContent_union hC hs (hC.diff_mem ht hs)]
· exact add_le_add le_rfl
(addContent_mono hC.isSetSemiring (hC.diff_mem ht hs) ht diff_subset)
· rw [Set.disjoint_iff_inter_eq_empty, inter_diff_self]
lemma addContent_biUnion_le {ι : Type*} (hC : IsSetRing C) {s : ι → Set α}
{S : Finset ι} (hs : ∀ n ∈ S, s n ∈ C) :
m (⋃ i ∈ S, s i) ≤ ∑ i ∈ S, m (s i) := by
classical
induction S using Finset.induction with
| empty => simp
| insert i S hiS h =>
rw [Finset.sum_insert hiS]
simp_rw [← Finset.mem_coe, Finset.coe_insert, Set.biUnion_insert]
simp only [Finset.mem_insert, forall_eq_or_imp] at hs
refine (addContent_union_le hC hs.1 (hC.biUnion_mem S hs.2)).trans ?_
exact add_le_add le_rfl (h hs.2)
lemma addContent_biUnion_eq {ι : Type*} (hC : IsSetRing C) {s : ι → Set α}
{S : Finset ι} (hs : ∀ n ∈ S, s n ∈ C) (hS : (S : Set ι).PairwiseDisjoint s) :
m (⋃ i ∈ S, s i) = ∑ i ∈ S, m (s i) := by
classical
induction S using Finset.induction with
| empty => simp
| insert i S hiS h =>
rw [Finset.sum_insert hiS]
simp_rw [← Finset.mem_coe, Finset.coe_insert, Set.biUnion_insert]
simp only [Finset.mem_insert, forall_eq_or_imp] at hs
simp only [Finset.coe_insert, Set.pairwiseDisjoint_insert] at hS
rw [← h hs.2 hS.1]
refine addContent_union hC hs.1 (hC.biUnion_mem S hs.2) ?_
rw [disjoint_iUnion₂_right]
exact fun j hjS ↦ hS.2 j hjS (ne_of_mem_of_not_mem hjS hiS).symm
lemma le_addContent_diff (m : AddContent C) (hC : IsSetRing C) (hs : s ∈ C) (ht : t ∈ C) :
m s - m t ≤ m (s \ t) := by
conv_lhs => rw [← inter_union_diff s t]
rw [addContent_union hC (hC.inter_mem hs ht) (hC.diff_mem hs ht) disjoint_inf_sdiff, add_comm]
refine add_tsub_le_assoc.trans_eq ?_
rw [tsub_eq_zero_of_le
(addContent_mono hC.isSetSemiring (hC.inter_mem hs ht) ht inter_subset_right), add_zero]
lemma addContent_diff_of_ne_top (m : AddContent C) (hC : IsSetRing C)
(hm_ne_top : ∀ s ∈ C, m s ≠ ∞)
{s t : Set α} (hs : s ∈ C) (ht : t ∈ C) (hts : t ⊆ s) :
m (s \ t) = m s - m t := by
have h_union : m (t ∪ s \ t) = m t + m (s \ t) :=
addContent_union hC ht (hC.diff_mem hs ht) disjoint_sdiff_self_right
simp_rw [Set.union_diff_self, Set.union_eq_right.mpr hts] at h_union
rw [h_union, ENNReal.add_sub_cancel_left (hm_ne_top _ ht)]
lemma addContent_accumulate (m : AddContent C) (hC : IsSetRing C)
{s : ℕ → Set α} (hs_disj : Pairwise (Disjoint on s)) (hsC : ∀ i, s i ∈ C) (n : ℕ) :
m (Set.Accumulate s n) = ∑ i ∈ Finset.range (n + 1), m (s i) := by
induction n with
| zero => simp
| succ n hn =>
rw [Finset.sum_range_succ, ← hn, Set.accumulate_succ, addContent_union hC _ (hsC _)]
· exact Set.disjoint_accumulate hs_disj (Nat.lt_succ_self n)
· exact hC.accumulate_mem hsC n
/-- A function which is additive on disjoint elements in a ring of sets `C` defines an
additive content on `C`. -/
def IsSetRing.addContent_of_union (m : Set α → ℝ≥0∞) (hC : IsSetRing C) (m_empty : m ∅ = 0)
(m_add : ∀ {s t : Set α} (_hs : s ∈ C) (_ht : t ∈ C), Disjoint s t → m (s ∪ t) = m s + m t) :
AddContent C where
toFun := m
empty' := m_empty
sUnion' I h_ss h_dis h_mem := by
classical
induction I using Finset.induction with
| empty => simp only [Finset.coe_empty, Set.sUnion_empty, Finset.sum_empty, m_empty]
| insert s I hsI h =>
rw [Finset.coe_insert] at *
rw [Set.insert_subset_iff] at h_ss
rw [Set.pairwiseDisjoint_insert_of_notMem] at h_dis
swap; · exact hsI
have h_sUnion_mem : ⋃₀ ↑I ∈ C := by
rw [Set.sUnion_eq_biUnion]
apply hC.biUnion_mem
intro n hn
exact h_ss.2 hn
rw [Set.sUnion_insert, m_add h_ss.1 h_sUnion_mem (Set.disjoint_sUnion_right.mpr h_dis.2),
Finset.sum_insert hsI, h h_ss.2 h_dis.1]
rwa [Set.sUnion_insert] at h_mem
/-- In a ring of sets, continuity of an additive content at `∅` implies σ-additivity.
This is not true in general in semirings, or without the hypothesis that `m` is finite. See the
examples 7 and 8 in Halmos' book Measure Theory (1974), page 40. -/
theorem addContent_iUnion_eq_sum_of_tendsto_zero (hC : IsSetRing C) (m : AddContent C)
(hm_ne_top : ∀ s ∈ C, m s ≠ ∞)
(hm_tendsto : ∀ ⦃s : ℕ → Set α⦄ (_ : ∀ n, s n ∈ C),
Antitone s → (⋂ n, s n) = ∅ → Tendsto (fun n ↦ m (s n)) atTop (𝓝 0))
⦃f : ℕ → Set α⦄ (hf : ∀ i, f i ∈ C) (hUf : (⋃ i, f i) ∈ C)
(h_disj : Pairwise (Disjoint on f)) :
m (⋃ i, f i) = ∑' i, m (f i) := by
-- We use the continuity of `m` at `∅` on the sequence `n ↦ (⋃ i, f i) \ (set.accumulate f n)`
let s : ℕ → Set α := fun n ↦ (⋃ i, f i) \ Set.Accumulate f n
have hCs n : s n ∈ C := hC.diff_mem hUf (hC.accumulate_mem hf n)
have h_tendsto : Tendsto (fun n ↦ m (s n)) atTop (𝓝 0) := by
refine hm_tendsto hCs ?_ ?_
· intro i j hij x hxj
rw [Set.mem_diff] at hxj ⊢
exact ⟨hxj.1, fun hxi ↦ hxj.2 (Set.monotone_accumulate hij hxi)⟩
· simp_rw [s, Set.diff_eq]
rw [Set.iInter_inter_distrib, Set.iInter_const, ← Set.compl_iUnion, Set.iUnion_accumulate]
exact Set.inter_compl_self _
have hmsn n : m (s n) = m (⋃ i, f i) - ∑ i ∈ Finset.range (n + 1), m (f i) := by
rw [addContent_diff_of_ne_top m hC hm_ne_top hUf (hC.accumulate_mem hf n)
(Set.accumulate_subset_iUnion _), addContent_accumulate m hC h_disj hf n]
simp_rw [hmsn] at h_tendsto
refine tendsto_nhds_unique ?_ (ENNReal.tendsto_nat_tsum fun i ↦ m (f i))
refine (Filter.tendsto_add_atTop_iff_nat 1).mp ?_
rwa [ENNReal.tendsto_const_sub_nhds_zero_iff (hm_ne_top _ hUf) (fun n ↦ ?_)] at h_tendsto
rw [← addContent_accumulate m hC h_disj hf]
exact addContent_mono hC.isSetSemiring (hC.accumulate_mem hf n) hUf
(Set.accumulate_subset_iUnion _)
/-- If an additive content is σ-additive on a set ring, then the content of a monotone sequence of
sets tends to the content of the union. -/
theorem tendsto_atTop_addContent_iUnion_of_addContent_iUnion_eq_tsum (hC : IsSetRing C)
(m_iUnion : ∀ (f : ℕ → Set α) (_ : ∀ i, f i ∈ C) (_ : (⋃ i, f i) ∈ C)
(_hf_disj : Pairwise (Disjoint on f)), m (⋃ i, f i) = ∑' i, m (f i))
⦃f : ℕ → Set α⦄ (hf_mono : Monotone f) (hf : ∀ i, f i ∈ C) (hf_Union : ⋃ i, f i ∈ C) :
Tendsto (fun n ↦ m (f n)) atTop (𝓝 (m (⋃ i, f i))) := by
rw [← iUnion_disjointed, m_iUnion _ (hC.disjointed_mem hf) (by rwa [iUnion_disjointed])
(disjoint_disjointed f)]
have h n : m (f n) = ∑ i ∈ range (n + 1), m (disjointed f i) := by
nth_rw 1 [← addContent_accumulate _ hC (disjoint_disjointed f) (hC.disjointed_mem hf),
← hf_mono.partialSups_eq, ← partialSups_disjointed, partialSups_eq_biSup, Accumulate]
rfl
simp_rw [h]
refine (tendsto_add_atTop_iff_nat (f := (fun k ↦ ∑ i ∈ range k, m (disjointed f i))) 1).2 ?_
exact ENNReal.tendsto_nat_tsum _
/-- If an additive content is σ-additive on a set ring, then it is σ-subadditive. -/
theorem isSigmaSubadditive_of_addContent_iUnion_eq_tsum (hC : IsSetRing C)
(m_iUnion : ∀ (f : ℕ → Set α) (_ : ∀ i, f i ∈ C) (_ : (⋃ i, f i) ∈ C)
(_hf_disj : Pairwise (Disjoint on f)), m (⋃ i, f i) = ∑' i, m (f i)) :
m.IsSigmaSubadditive := by
intro f hf hf_Union
have h_tendsto : Tendsto (fun n ↦ m (partialSups f n)) atTop (𝓝 (m (⋃ i, f i))) := by
rw [← iSup_eq_iUnion, ← iSup_partialSups_eq]
refine tendsto_atTop_addContent_iUnion_of_addContent_iUnion_eq_tsum hC m_iUnion
(partialSups_monotone f) (hC.partialSups_mem hf) ?_
rwa [← iSup_eq_iUnion, iSup_partialSups_eq]
have h_tendsto' : Tendsto (fun n ↦ ∑ i ∈ range (n + 1), m (f i)) atTop (𝓝 (∑' i, m (f i))) := by
rw [tendsto_add_atTop_iff_nat (f := (fun k ↦ ∑ i ∈ range k, m (f i))) 1]
exact ENNReal.tendsto_nat_tsum _
refine le_of_tendsto_of_tendsto' h_tendsto h_tendsto' fun _ ↦ ?_
rw [partialSups_eq_biUnion_range]
exact addContent_biUnion_le hC (fun _ _ ↦ hf _)
end IsSetRing
end MeasureTheory
|
Circle.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.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Normed.Field.UnitBall
/-!
# The circle
This file defines `circle` to be the metric sphere (`Metric.sphere`) in `ℂ` centred at `0` of
radius `1`. We equip it with the following structure:
* a submonoid of `ℂ`
* a group
* a topological group
We furthermore define `Circle.exp` to be the natural map `fun t ↦ exp (t * I)` from `ℝ` to
`circle`, and show that this map is a group homomorphism.
We define two additive characters onto the circle:
* `Real.fourierChar`: The character `fun x ↦ exp ((2 * π * x) * I)` (for which we introduce the
notation `𝐞` in the locale `FourierTransform`). This uses the analyst convention that there is a
`2 * π` in the exponent.
* `Real.probChar`: The character `fun x ↦ exp (x * I)`, which uses the probabilist convention that
there is no `2 * π` in the exponent.
## Implementation notes
Because later (in `Geometry.Manifold.Instances.Sphere`) one wants to equip the circle with a smooth
manifold structure borrowed from `Metric.sphere`, the underlying set is
`{z : ℂ | abs (z - 0) = 1}`. This prevents certain algebraic facts from working definitionally --
for example, the circle is not defeq to `{z : ℂ | abs z = 1}`, which is the kernel of `Complex.abs`
considered as a homomorphism from `ℂ` to `ℝ`, nor is it defeq to `{z : ℂ | normSq z = 1}`, which
is the kernel of the homomorphism `Complex.normSq` from `ℂ` to `ℝ`.
-/
noncomputable section
open Complex Function Metric
open ComplexConjugate
/-- The unit circle in `ℂ`. -/
def Circle : Type := Submonoid.unitSphere ℂ
deriving TopologicalSpace
namespace Circle
variable {x y : Circle}
instance instCoeOut : CoeOut Circle ℂ := subtypeCoe
instance instCommGroup : CommGroup Circle := Metric.sphere.instCommGroup
instance instMetricSpace : MetricSpace Circle := Subtype.metricSpace
@[ext] lemma ext : (x : ℂ) = y → x = y := Subtype.ext
lemma coe_injective : Injective ((↑) : Circle → ℂ) := fun _ _ ↦ ext
-- Not simp because `SetLike.coe_eq_coe` already proves it
lemma coe_inj : (x : ℂ) = y ↔ x = y := coe_injective.eq_iff
lemma norm_coe (z : Circle) : ‖(z : ℂ)‖ = 1 := mem_sphere_zero_iff_norm.1 z.2
@[deprecated (since := "2025-02-16")] alias abs_coe := norm_coe
@[simp] lemma normSq_coe (z : Circle) : normSq z = 1 := by simp [normSq_eq_norm_sq]
@[simp] lemma coe_ne_zero (z : Circle) : (z : ℂ) ≠ 0 := ne_zero_of_mem_unit_sphere z
@[simp, norm_cast] lemma coe_one : ↑(1 : Circle) = (1 : ℂ) := rfl
-- Not simp because `OneMemClass.coe_eq_one` already proves it
@[norm_cast] lemma coe_eq_one : (x : ℂ) = 1 ↔ x = 1 := by rw [← coe_inj, coe_one]
@[simp, norm_cast] lemma coe_mul (z w : Circle) : ↑(z * w) = (z : ℂ) * w := rfl
@[simp, norm_cast] lemma coe_inv (z : Circle) : ↑z⁻¹ = (z : ℂ)⁻¹ := rfl
lemma coe_inv_eq_conj (z : Circle) : ↑z⁻¹ = conj (z : ℂ) := by
rw [coe_inv, inv_def, normSq_coe, inv_one, ofReal_one, mul_one]
@[simp, norm_cast] lemma coe_div (z w : Circle) : ↑(z / w) = (z : ℂ) / w := rfl
/-- The coercion `Circle → ℂ` as a monoid homomorphism. -/
@[simps]
def coeHom : Circle →* ℂ where
toFun := (↑)
map_one' := coe_one
map_mul' := coe_mul
/-- The elements of the circle embed into the units. -/
def toUnits : Circle →* Units ℂ := unitSphereToUnits ℂ
-- written manually because `@[simps]` generated the wrong lemma
@[simp] lemma toUnits_apply (z : Circle) : toUnits z = Units.mk0 ↑z z.coe_ne_zero := rfl
instance : CompactSpace Circle := Metric.sphere.compactSpace _ _
instance : IsTopologicalGroup Circle := Metric.sphere.instIsTopologicalGroup
instance instUniformSpace : UniformSpace Circle := instUniformSpaceSubtype
instance : IsUniformGroup Circle := by
convert topologicalGroup_is_uniform_of_compactSpace Circle
exact unique_uniformity_of_compact rfl rfl
/-- If `z` is a nonzero complex number, then `conj z / z` belongs to the unit circle. -/
@[simps]
def ofConjDivSelf (z : ℂ) (hz : z ≠ 0) : Circle where
val := conj z / z
property := mem_sphere_zero_iff_norm.2 <| by
rw [norm_div, RCLike.norm_conj, div_self]; exact norm_ne_zero_iff.mpr hz
/-- The map `fun t => exp (t * I)` from `ℝ` to the unit circle in `ℂ`. -/
def exp : C(ℝ, Circle) where
toFun t := ⟨(t * I).exp, by simp [Submonoid.unitSphere, exp_mul_I, norm_cos_add_sin_mul_I]⟩
continuous_toFun := Continuous.subtype_mk (by fun_prop)
(by simp [Submonoid.unitSphere, exp_mul_I, norm_cos_add_sin_mul_I])
@[simp, norm_cast]
theorem coe_exp (t : ℝ) : exp t = Complex.exp (t * Complex.I) := rfl
@[simp]
theorem exp_zero : exp 0 = 1 :=
Subtype.ext <| by rw [coe_exp, ofReal_zero, zero_mul, Complex.exp_zero, coe_one]
@[simp]
theorem exp_add (x y : ℝ) : exp (x + y) = exp x * exp y :=
Subtype.ext <| by
simp only [coe_exp, ofReal_add, add_mul, Complex.exp_add, coe_mul]
/-- The map `fun t => exp (t * I)` from `ℝ` to the unit circle in `ℂ`,
considered as a homomorphism of groups. -/
@[simps]
def expHom : ℝ →+ Additive Circle where
toFun := Additive.ofMul ∘ exp
map_zero' := exp_zero
map_add' := exp_add
@[simp] lemma exp_sub (x y : ℝ) : exp (x - y) = exp x / exp y := expHom.map_sub x y
@[simp] lemma exp_neg (x : ℝ) : exp (-x) = (exp x)⁻¹ := expHom.map_neg x
lemma exp_pi_ne_one : Circle.exp Real.pi ≠ 1 := by
intro h
have heq : (Circle.exp Real.pi : ℂ) = 1 := by simp [h]
rw [Circle.coe_exp, exp_pi_mul_I] at heq
norm_num at heq
variable {e : AddChar ℝ Circle}
@[simp]
lemma star_addChar (x : ℝ) : star ((e x) : ℂ) = e (-x) := by
have h := Circle.coe_inv_eq_conj ⟨e x, ?_⟩
· simp only [Circle.coe_inv] at h
simp [← h, e.map_neg_eq_inv]
· simp only [Submonoid.unitSphere, SetLike.coe_mem]
@[simp]
lemma starRingEnd_addChar (x : ℝ) : starRingEnd ℂ (e x) = e (-x) := star_addChar x
variable {α β M : Type*}
instance instSMul [SMul ℂ α] : SMul Circle α := Submonoid.smul _
instance instSMulCommClass_left [SMul ℂ β] [SMul α β] [SMulCommClass ℂ α β] :
SMulCommClass Circle α β := Submonoid.smulCommClass_left _
instance instSMulCommClass_right [SMul ℂ β] [SMul α β] [SMulCommClass α ℂ β] :
SMulCommClass α Circle β := Submonoid.smulCommClass_right _
instance instIsScalarTower [SMul ℂ α] [SMul ℂ β] [SMul α β] [IsScalarTower ℂ α β] :
IsScalarTower Circle α β := Submonoid.isScalarTower _
instance instMulAction [MulAction ℂ α] : MulAction Circle α := Submonoid.mulAction _
instance instDistribMulAction [AddMonoid M] [DistribMulAction ℂ M] :
DistribMulAction Circle M := Submonoid.distribMulAction _
lemma smul_def [SMul ℂ α] (z : Circle) (a : α) : z • a = (z : ℂ) • a := rfl
instance instContinuousSMul [TopologicalSpace α] [MulAction ℂ α] [ContinuousSMul ℂ α] :
ContinuousSMul Circle α := Submonoid.continuousSMul
@[simp]
protected lemma norm_smul {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℂ E]
(u : Circle) (v : E) :
‖u • v‖ = ‖v‖ := by
rw [Submonoid.smul_def, norm_smul, norm_eq_of_mem_sphere, one_mul]
end Circle
namespace Real
/-- The additive character from `ℝ` onto the circle, given by `fun x ↦ exp (2 * π * x * I)`.
Denoted as `𝐞` within the `Real.FourierTransform` namespace. This uses the analyst convention that
there is a `2 * π` in the exponent. -/
def fourierChar : AddChar ℝ Circle where
toFun z := .exp (2 * π * z)
map_zero_eq_one' := by rw [mul_zero, Circle.exp_zero]
map_add_eq_mul' x y := by rw [mul_add, Circle.exp_add]
@[inherit_doc] scoped[FourierTransform] notation "𝐞" => Real.fourierChar
open FourierTransform
theorem fourierChar_apply' (x : ℝ) : 𝐞 x = Circle.exp (2 * π * x) := rfl
theorem fourierChar_apply (x : ℝ) : 𝐞 x = Complex.exp (↑(2 * π * x) * Complex.I) := rfl
@[continuity]
theorem continuous_fourierChar : Continuous 𝐞 := Circle.exp.continuous.comp (continuous_mul_left _)
theorem fourierChar_ne_one : fourierChar ≠ 1 := by
rw [DFunLike.ne_iff]
use 2⁻¹
simp only [fourierChar_apply', AddChar.one_apply]
rw [mul_comm, ← mul_assoc, inv_mul_cancel₀ (by positivity), one_mul]
exact Circle.exp_pi_ne_one
/-- The additive character from `ℝ` onto the circle, given by `fun x ↦ exp (x * I)`. This uses the
probabilist convention that there is no `2 * π` in the exponent. -/
def probChar : AddChar ℝ Circle where
toFun := Circle.exp
map_zero_eq_one' := Circle.exp_zero
map_add_eq_mul' := Circle.exp_add
theorem probChar_apply' (x : ℝ) : probChar x = Circle.exp x := rfl
theorem probChar_apply (x : ℝ) : probChar x = Complex.exp (x * Complex.I) := rfl
@[continuity]
theorem continuous_probChar : Continuous probChar := Circle.exp.continuous
theorem probChar_ne_one : probChar ≠ 1 := by
rw [DFunLike.ne_iff]
use Real.pi
simpa only [probChar_apply'] using Circle.exp_pi_ne_one
end Real
|
eval_elab.lean
|
import Mathlib.Tactic.Eval
import Mathlib.Data.Finset.Powerset
import Mathlib.Data.Finset.Sort
import Mathlib.Util.Qq
#guard_expr eval% 2^10 =ₛ 1024
#guard_expr (eval% 2^10 : Int) =ₛ (1024 : Int)
#guard_expr
(eval% Multiset.powerset ({1, 2, 3} : Multiset ℕ)) =
{0, {1}, {2}, {1, 2}, {3}, {1, 3}, {2, 3}, {1, 2, 3}}
-- https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/How.20to.20simplify.20this.20proof.20without.20using.20a.20have.20statement.3F/near/422294189
section from_zulip
/--
error: failed to synthesize
Lean.ToExpr (Finset (Finset ℕ))
Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command.
-/
#guard_msgs in
#check eval% Finset.powerset ({1, 2, 3} : Finset ℕ)
open Lean Qq
/-- `HasInstance (Foo X)` means than an `inst : Foo X` exists. -/
class HasInstance (α : Type u) where
/-- The reflected version of `inst`. -/
expr : Expr
-- this obviously doesn't scale, which is why this is only in the test file
instance : HasInstance (DecidableEq ℕ) :=
⟨q(inferInstanceAs <| DecidableEq ℕ)⟩
instance : HasInstance (DecidableEq (Finset ℕ)) :=
⟨q(inferInstanceAs <| DecidableEq (Finset ℕ))⟩
instance : HasInstance (DecidableEq (Finset (Finset ℕ))) :=
⟨q(inferInstanceAs <| DecidableEq (Finset (Finset ℕ)))⟩
open Qq Lean
/-- `Finset α` can be converted to an expr only if there is some way to find `DecidableEq α`. -/
unsafe nonrec instance Finset.toExpr
{α : Type u} [ToLevel.{u}] [ToExpr α] [HasInstance (DecidableEq α)] : ToExpr (Finset α) :=
haveI u' : Level := Lean.toLevel.{u}
haveI α' : Q(Type u') := Lean.toTypeExpr α
letI : Q(DecidableEq $α') := HasInstance.expr (DecidableEq α)
{ toTypeExpr := q(Finset $α')
toExpr x := show Q(Finset $α') from mkSetLiteralQ q(Finset $α') (x.val.unquot.map toExpr) }
#guard_expr
(eval% Finset.powerset ({1, 2, 3} : Finset ℕ)) =
{∅, {1}, {2}, {1, 2}, {3}, {1, 3}, {2, 3}, {1, 2, 3}}
end from_zulip
|
hall.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div choice.
From mathcomp Require Import fintype finset prime fingroup morphism.
From mathcomp Require Import automorphism quotient action gproduct gfunctor.
From mathcomp Require Import commutator center pgroup finmodule nilpotent.
From mathcomp Require Import sylow abelian maximal.
(*****************************************************************************)
(* In this files we prove the Schur-Zassenhaus splitting and transitivity *)
(* theorems (under solvability assumptions), then derive P. Hall's *)
(* generalization of Sylow's theorem to solvable groups and its corollaries, *)
(* in particular the theory of coprime action. We develop both the theory of *)
(* coprime action of a solvable group on Sylow subgroups (as in Aschbacher *)
(* 18.7), and that of coprime action on Hall subgroups of a solvable group *)
(* as per B & G, Proposition 1.5; however we only support external group *)
(* action (as opposed to internal action by conjugation) for the latter case *)
(* because it is much harder to apply in practice. *)
(*****************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Hall.
Implicit Type gT : finGroupType.
Theorem SchurZassenhaus_split gT (G H : {group gT}) :
Hall G H -> H <| G -> [splits G, over H].
Proof.
have [n] := ubnP #|G|; elim: n => // n IHn in gT G H * => /ltnSE-Gn hallH nsHG.
have [sHG nHG] := andP nsHG.
have [-> | [p pr_p pH]] := trivgVpdiv H.
by apply/splitsP; exists G; rewrite inE -subG1 subsetIl mul1g eqxx.
have [P sylP] := Sylow_exists p H.
case nPG: (P <| G); last first.
pose N := ('N_G(P))%G; have sNG: N \subset G by rewrite subsetIl.
have eqHN_G: H * N = G by apply: Frattini_arg sylP.
pose H' := (H :&: N)%G.
have nsH'N: H' <| N.
by rewrite /normal subsetIr normsI ?normG ?(subset_trans sNG).
have eq_iH: #|G : H| = #|N| %/ #|H'|.
rewrite -divgS // -(divnMl (cardG_gt0 H')) mulnC -eqHN_G.
by rewrite -mul_cardG (mulnC #|H'|) divnMl // cardG_gt0.
have hallH': Hall N H'.
rewrite /Hall -divgS subsetIr //= -eq_iH.
by case/andP: hallH => _; apply: coprimeSg; apply: subsetIl.
have: [splits N, over H'].
apply: IHn hallH' nsH'N; apply: {n}leq_trans Gn.
rewrite proper_card // properEneq sNG andbT; apply/eqP=> eqNG.
by rewrite -eqNG normal_subnorm (subset_trans (pHall_sub sylP)) in nPG.
case/splitsP=> K /complP[tiKN eqH'K].
have sKN: K \subset N by rewrite -(mul1g K) -eqH'K mulSg ?sub1set.
apply/splitsP; exists K; rewrite inE -subG1; apply/andP; split.
by rewrite /= -(setIidPr sKN) setIA tiKN.
by rewrite eqEsubset -eqHN_G mulgS // -eqH'K mulGS mulSg ?subsetIl.
pose Z := 'Z(P); pose Gbar := G / Z; pose Hbar := H / Z.
have sZP: Z \subset P by apply: center_sub.
have sZH: Z \subset H by apply: subset_trans (pHall_sub sylP).
have sZG: Z \subset G by apply: subset_trans sHG.
have nZG: Z <| G by apply: gFnormal_trans nPG.
have nZH: Z <| H by apply: normalS nZG.
have nHGbar: Hbar <| Gbar by apply: morphim_normal.
have hallHbar: Hall Gbar Hbar by apply: morphim_Hall (normal_norm _) _.
have: [splits Gbar, over Hbar].
apply: IHn => //; apply: {n}leq_trans Gn; rewrite ltn_quotient //.
apply/eqP=> /(trivg_center_pgroup (pHall_pgroup sylP))/eqP.
rewrite trivg_card1 (card_Hall sylP) p_part -(expn0 p).
by rewrite eqn_exp2l ?prime_gt1 // lognE pH pr_p cardG_gt0.
case/splitsP=> Kbar /complP[tiHKbar eqHKbar].
have: Kbar \subset Gbar by rewrite -eqHKbar mulG_subr.
case/inv_quotientS=> //= ZK quoZK sZZK sZKG.
have nZZK: Z <| ZK by apply: normalS nZG.
have cardZK: #|ZK| = (#|Z| * #|G : H|)%N.
rewrite -(Lagrange sZZK); congr (_ * _)%N.
rewrite -card_quotient -?quoZK; last by case/andP: nZZK.
rewrite -(divgS sHG) -(Lagrange sZG) -(Lagrange sZH) divnMl //.
rewrite -!card_quotient ?normal_norm //= -/Gbar -/Hbar.
by rewrite -eqHKbar (TI_cardMg tiHKbar) mulKn.
have: [splits ZK, over Z].
rewrite (Gaschutz_split nZZK _ sZZK) ?center_abelian //; last first.
rewrite -divgS // cardZK mulKn ?cardG_gt0 //.
by case/andP: hallH => _; apply: coprimeSg.
by apply/splitsP; exists 1%G; rewrite inE -subG1 subsetIr mulg1 eqxx.
case/splitsP=> K /complP[tiZK eqZK].
have sKZK: K \subset ZK by rewrite -(mul1g K) -eqZK mulSg ?sub1G.
have tiHK: H :&: K = 1.
apply/trivgP; rewrite /= -(setIidPr sKZK) setIA -tiZK setSI //.
rewrite -quotient_sub1; last by rewrite subIset 1?normal_norm.
by rewrite /= quotientGI //= -quoZK tiHKbar.
apply/splitsP; exists K; rewrite inE tiHK ?eqEcard subxx leqnn /=.
rewrite mul_subG ?(subset_trans sKZK) //= TI_cardMg //.
rewrite -(@mulKn #|K| #|Z|) ?cardG_gt0 // -TI_cardMg // eqZK.
by rewrite cardZK mulKn ?cardG_gt0 // Lagrange.
Qed.
Theorem SchurZassenhaus_trans_sol gT (H K K1 : {group gT}) :
solvable H -> K \subset 'N(H) -> K1 \subset H * K ->
coprime #|H| #|K| -> #|K1| = #|K| ->
exists2 x, x \in H & K1 :=: K :^ x.
Proof.
have [n] := ubnP #|H|.
elim: n => // n IHn in gT H K K1 * => /ltnSE-leHn solH nHK.
have [-> | ] := eqsVneq H 1.
rewrite mul1g => sK1K _ eqK1K; exists 1; first exact: set11.
by apply/eqP; rewrite conjsg1 eqEcard sK1K eqK1K /=.
pose G := (H <*> K)%G.
have defG: G :=: H * K by rewrite -normC // -norm_joinEl // joingC.
have sHG: H \subset G by apply: joing_subl.
have sKG: K \subset G by apply: joing_subr.
have nsHG: H <| G by rewrite /(H <| G) sHG join_subG normG.
case/(solvable_norm_abelem solH nsHG)=> M [sMH nsMG ntM] /and3P[_ abelM _].
have [sMG nMG] := andP nsMG; rewrite -defG => sK1G coHK oK1K.
have nMsG (L : {set gT}): L \subset G -> L \subset 'N(M).
by move/subset_trans->.
have [coKM coHMK]: coprime #|M| #|K| /\ coprime #|H / M| #|K|.
by apply/andP; rewrite -coprimeMl card_quotient ?nMsG ?Lagrange.
have oKM (K' : {group gT}): K' \subset G -> #|K'| = #|K| -> #|K' / M| = #|K|.
move=> sK'G oK'.
rewrite -quotientMidr -?norm_joinEl ?card_quotient ?nMsG //; last first.
by rewrite gen_subG subUset sK'G.
rewrite -divgS /=; last by rewrite -gen_subG genS ?subsetUr.
by rewrite norm_joinEl ?nMsG // coprime_cardMg ?mulnK // oK' coprime_sym.
have [xb]: exists2 xb, xb \in H / M & K1 / M = (K / M) :^ xb.
apply: IHn; try by rewrite (quotient_sol, morphim_norms, oKM K) ?(oKM K1).
by apply: leq_trans leHn; rewrite ltn_quotient.
by rewrite -morphimMl ?nMsG // -defG morphimS.
case/morphimP=> x nMx Hx ->{xb} eqK1Kx; pose K2 := (K :^ x)%G.
have{eqK1Kx} eqK12: K1 / M = K2 / M by rewrite quotientJ.
suff [y My ->]: exists2 y, y \in M & K1 :=: K2 :^ y.
by exists (x * y); [rewrite groupMl // (subsetP sMH) | rewrite conjsgM].
have nMK1: K1 \subset 'N(M) by apply: nMsG.
have defMK: M * K1 = M <*> K1 by rewrite -normC // -norm_joinEl // joingC.
have sMKM: M \subset M <*> K1 by rewrite joing_subl.
have nMKM: M <| M <*> K1 by rewrite normalYl.
have trMK1: M :&: K1 = 1 by rewrite coprime_TIg ?oK1K.
have trMK2: M :&: K2 = 1 by rewrite coprime_TIg ?cardJg ?oK1K.
apply: (Gaschutz_transitive nMKM _ sMKM) => //=; last 2 first.
- by rewrite inE trMK1 defMK !eqxx.
- by rewrite -!(setIC M) trMK1.
- by rewrite -divgS //= -defMK coprime_cardMg oK1K // mulKn.
rewrite inE trMK2 eqxx eq_sym eqEcard /= -defMK andbC.
by rewrite !coprime_cardMg ?cardJg ?oK1K ?leqnn //= mulGS -quotientSK -?eqK12.
Qed.
Lemma SchurZassenhaus_trans_actsol gT (G A B : {group gT}) :
solvable A -> A \subset 'N(G) -> B \subset A <*> G ->
coprime #|G| #|A| -> #|A| = #|B| ->
exists2 x, x \in G & B :=: A :^ x.
Proof.
set AG := A <*> G; have [n] := ubnP #|AG|.
elim: n => // n IHn in gT A B G AG * => /ltnSE-leAn solA nGA sB_AG coGA oAB.
have [A1 | ntA] := eqsVneq A 1.
by exists 1; rewrite // conjsg1 A1 (@card1_trivg _ B) // -oAB A1 cards1.
have [M [sMA nsMA ntM]] := solvable_norm_abelem solA (normal_refl A) ntA.
case/is_abelemP=> q q_pr /abelem_pgroup qM; have nMA := normal_norm nsMA.
have defAG: AG = A * G := norm_joinEl nGA.
have sA_AG: A \subset AG := joing_subl _ _.
have sG_AG: G \subset AG := joing_subr _ _.
have sM_AG := subset_trans sMA sA_AG.
have oAG: #|AG| = (#|A| * #|G|)%N by rewrite defAG coprime_cardMg 1?coprime_sym.
have q'G: #|G|`_q = 1%N.
rewrite part_p'nat ?p'natE -?prime_coprime // coprime_sym.
have [_ _ [k oM]] := pgroup_pdiv qM ntM.
by rewrite -(@coprime_pexpr k.+1) // -oM (coprimegS sMA).
have coBG: coprime #|B| #|G| by rewrite -oAB coprime_sym.
have defBG: B * G = AG.
by apply/eqP; rewrite eqEcard mul_subG ?sG_AG //= oAG oAB coprime_cardMg.
case nMG: (G \subset 'N(M)).
have nsM_AG: M <| AG by rewrite /normal sM_AG join_subG nMA.
have nMB: B \subset 'N(M) := subset_trans sB_AG (normal_norm nsM_AG).
have sMB: M \subset B.
have [Q sylQ]:= Sylow_exists q B; have sQB := pHall_sub sylQ.
apply: subset_trans (normal_sub_max_pgroup (Hall_max _) qM nsM_AG) (sQB).
rewrite pHallE (subset_trans sQB) //= oAG partnM // q'G muln1 oAB.
by rewrite (card_Hall sylQ).
have defAGq: AG / M = (A / M) <*> (G / M).
by rewrite quotient_gen ?quotientU ?subUset ?nMA.
have: B / M \subset (A / M) <*> (G / M) by rewrite -defAGq quotientS.
case/IHn; rewrite ?morphim_sol ?quotient_norms ?coprime_morph //.
- by rewrite -defAGq (leq_trans _ leAn) ?ltn_quotient.
- by rewrite !card_quotient // -!divgS // oAB.
move=> Mx; case/morphimP=> x Nx Gx ->{Mx} //; rewrite -quotientJ //= => defBq.
exists x => //; apply: quotient_inj defBq; first by rewrite /normal sMB.
by rewrite -(normsP nMG x Gx) /normal normJ !conjSg.
pose K := M <*> G; pose R := K :&: B; pose N := 'N_G(M).
have defK: K = M * G by rewrite -norm_joinEl ?(subset_trans sMA).
have oK: #|K| = (#|M| * #|G|)%N.
by rewrite defK coprime_cardMg // coprime_sym (coprimegS sMA).
have sylM: q.-Sylow(K) M.
by rewrite pHallE joing_subl /= oK partnM // q'G muln1 part_pnat_id.
have sylR: q.-Sylow(K) R.
rewrite pHallE subsetIl /= -(card_Hall sylM) -(@eqn_pmul2r #|G|) // -oK.
rewrite -coprime_cardMg ?(coprimeSg _ coBG) ?subsetIr //=.
by rewrite group_modr ?joing_subr ?(setIidPl _) // defBG join_subG sM_AG.
have [mx] := Sylow_trans sylM sylR.
rewrite /= -/K defK; case/imset2P=> m x Mm Gx ->{mx}.
rewrite conjsgM (conjGid Mm) {m Mm} => defR.
have sNG: N \subset G := subsetIl _ _.
have pNG: N \proper G by rewrite /proper sNG subsetI subxx nMG.
have nNA: A \subset 'N(N) by rewrite normsI ?norms_norm.
have: B :^ x^-1 \subset A <*> N.
rewrite norm_joinEl ?group_modl // -defAG subsetI !sub_conjgV -normJ -defR.
rewrite conjGid ?(subsetP sG_AG) // normsI ?normsG // (subset_trans sB_AG) //.
by rewrite join_subG normsM // -defK normsG ?joing_subr.
do [case/IHn; rewrite ?cardJg ?(coprimeSg _ coGA) //= -/N] => [|y Ny defB].
rewrite joingC norm_joinEr // coprime_cardMg ?(coprimeSg sNG) //.
by rewrite (leq_trans _ leAn) // oAG mulnC ltn_pmul2l // proper_card.
exists (y * x); first by rewrite groupM // (subsetP sNG).
by rewrite conjsgM -defB conjsgKV.
Qed.
Lemma Hall_exists_subJ pi gT (G : {group gT}) :
solvable G -> exists2 H : {group gT}, pi.-Hall(G) H
& forall K : {group gT}, K \subset G -> pi.-group K ->
exists2 x, x \in G & K \subset H :^ x.
Proof.
have [n] := ubnP #|G|; elim: n gT G => // n IHn gT G /ltnSE-leGn solG.
have [-> | ntG] := eqsVneq G 1.
exists 1%G => [|_ /trivGP-> _]; last by exists 1; rewrite ?set11 ?sub1G.
by rewrite pHallE sub1G cards1 part_p'nat.
case: (solvable_norm_abelem solG (normal_refl _)) => // M [sMG nsMG ntM].
case/is_abelemP=> p pr_p /and3P[pM cMM _].
pose Gb := (G / M)%G; case: (IHn _ Gb) => [||Hb]; try exact: quotient_sol.
by rewrite (leq_trans (ltn_quotient _ _)).
case/and3P=> [sHbGb piHb pi'Hb'] transHb.
case: (inv_quotientS nsMG sHbGb) => H def_H sMH sHG.
have nMG := normal_norm nsMG; have nMH := subset_trans sHG nMG.
have{transHb} transH (K : {group gT}):
K \subset G -> pi.-group K -> exists2 x, x \in G & K \subset H :^ x.
- move=> sKG piK; have nMK := subset_trans sKG nMG.
case: (transHb (K / M)%G) => [||xb Gxb sKHxb]; first exact: morphimS.
exact: morphim_pgroup.
case/morphimP: Gxb => x Nx Gx /= def_x; exists x => //.
apply/subsetP=> y Ky.
have: y \in coset M y by rewrite val_coset (subsetP nMK, rcoset_refl).
have: coset M y \in (H :^ x) / M.
rewrite /quotient morphimJ //=.
by rewrite def_x def_H in sKHxb; apply/(subsetP sKHxb)/mem_quotient.
case/morphimP=> z Nz Hxz ->.
rewrite val_coset //; case/rcosetP=> t Mt ->; rewrite groupMl //.
by rewrite mem_conjg (subsetP sMH) // -mem_conjg (normP Nx).
have{pi'Hb'} pi'H': pi^'.-nat #|G : H|.
move: pi'Hb'; rewrite -!divgS // def_H !card_quotient //.
by rewrite -(divnMl (cardG_gt0 M)) !Lagrange.
have [pi_p | pi'p] := boolP (p \in pi).
exists H => //; apply/and3P; split=> //; rewrite /pgroup.
by rewrite -(Lagrange sMH) -card_quotient // pnatM -def_H (pi_pnat pM).
have [ltHG | leGH {n IHn leGn transH}] := ltnP #|H| #|G|.
case: (IHn _ H (leq_trans ltHG leGn)) => [|H1]; first exact: solvableS solG.
case/and3P=> sH1H piH1 pi'H1' transH1.
have sH1G: H1 \subset G by apply: subset_trans sHG.
exists H1 => [|K sKG piK].
apply/and3P; split => //.
rewrite -divgS // -(Lagrange sHG) -(Lagrange sH1H) -mulnA.
by rewrite mulKn // pnatM pi'H1'.
case: (transH K sKG piK) => x Gx def_K.
case: (transH1 (K :^ x^-1)%G) => [||y Hy def_K1].
- by rewrite sub_conjgV.
- by rewrite /pgroup cardJg.
exists (y * x); first by rewrite groupMr // (subsetP sHG).
by rewrite -(conjsgKV x K) conjsgM conjSg.
have{leGH Gb sHbGb sHG sMH pi'H'} eqHG: H = G.
by apply/eqP; rewrite -val_eqE eqEcard sHG.
have{H Hb def_H eqHG piHb nMH} hallM: pi^'.-Hall(G) M.
rewrite /pHall /pgroup sMG pnatNK -card_quotient //=.
by rewrite -eqHG -def_H (pi_pnat pM).
case/splitsP: (SchurZassenhaus_split (pHall_Hall hallM) nsMG) => H.
case/complP=> trMH defG.
have sHG: H \subset G by rewrite -defG mulG_subr.
exists H => [|K sKG piK].
apply: etrans hallM; rewrite /pHall sMG sHG /= -!divgS // -defG andbC.
by rewrite (TI_cardMg trMH) mulKn ?mulnK // pnatNK.
pose G1 := (K <*> M)%G; pose K1 := (H :&: G1)%G.
have nMK: K \subset 'N(M) by apply: subset_trans sKG nMG.
have defG1: M * K = G1 by rewrite -normC -?norm_joinEl.
have sK1G1: K1 \subset M * K by rewrite defG1 subsetIr.
have coMK: coprime #|M| #|K|.
by rewrite coprime_sym (pnat_coprime piK) //; apply: (pHall_pgroup hallM).
case: (SchurZassenhaus_trans_sol _ nMK sK1G1 coMK) => [||x Mx defK1].
- exact: solvableS solG.
- apply/eqP; rewrite -(eqn_pmul2l (cardG_gt0 M)) -TI_cardMg //; last first.
by apply/trivgP; rewrite -trMH /= setIA subsetIl.
rewrite -coprime_cardMg // defG1; apply/eqP; congr #|(_ : {set _})|.
rewrite group_modl; last by rewrite -defG1 mulG_subl.
by apply/setIidPr; rewrite defG gen_subG subUset sKG.
exists x^-1; first by rewrite groupV (subsetP sMG).
by rewrite -(_ : K1 :^ x^-1 = K) ?(conjSg, subsetIl) // defK1 conjsgK.
Qed.
End Hall.
Section HallCorollaries.
Variable gT : finGroupType.
Corollary Hall_exists pi (G : {group gT}) :
solvable G -> exists H : {group gT}, pi.-Hall(G) H.
Proof. by case/(Hall_exists_subJ pi) => H; exists H. Qed.
Corollary Hall_trans pi (G H1 H2 : {group gT}) :
solvable G -> pi.-Hall(G) H1 -> pi.-Hall(G) H2 ->
exists2 x, x \in G & H1 :=: H2 :^ x.
Proof.
move=> solG; have [H hallH transH] := Hall_exists_subJ pi solG.
have conjH (K : {group gT}):
pi.-Hall(G) K -> exists2 x, x \in G & K = (H :^ x)%G.
- move=> hallK; have [sKG piK _] := and3P hallK.
case: (transH K sKG piK) => x Gx sKH; exists x => //.
apply/eqP; rewrite -val_eqE eqEcard sKH cardJg.
by rewrite (card_Hall hallH) (card_Hall hallK) /=.
case/conjH=> x1 Gx1 ->{H1}; case/conjH=> x2 Gx2 ->{H2}.
exists (x2^-1 * x1); first by rewrite groupMl ?groupV.
by apply: val_inj; rewrite /= conjsgM conjsgK.
Qed.
Corollary Hall_superset pi (G K : {group gT}) :
solvable G -> K \subset G -> pi.-group K ->
exists2 H : {group gT}, pi.-Hall(G) H & K \subset H.
Proof.
move=> solG sKG; have [H hallH transH] := Hall_exists_subJ pi solG.
by case/transH=> // x Gx sKHx; exists (H :^ x)%G; rewrite ?pHallJ.
Qed.
Corollary Hall_subJ pi (G H K : {group gT}) :
solvable G -> pi.-Hall(G) H -> K \subset G -> pi.-group K ->
exists2 x, x \in G & K \subset H :^ x.
Proof.
move=> solG HallH sKG piK; have [M HallM sKM]:= Hall_superset solG sKG piK.
have [x Gx defM] := Hall_trans solG HallM HallH.
by exists x; rewrite // -defM.
Qed.
Corollary Hall_Jsub pi (G H K : {group gT}) :
solvable G -> pi.-Hall(G) H -> K \subset G -> pi.-group K ->
exists2 x, x \in G & K :^ x \subset H.
Proof.
move=> solG HallH sKG piK; have [x Gx sKHx] := Hall_subJ solG HallH sKG piK.
by exists x^-1; rewrite ?groupV // sub_conjgV.
Qed.
Lemma Hall_Frattini_arg pi (G K H : {group gT}) :
solvable K -> K <| G -> pi.-Hall(K) H -> K * 'N_G(H) = G.
Proof.
move=> solK /andP[sKG nKG] hallH.
have sHG: H \subset G by apply: subset_trans sKG; case/andP: hallH.
rewrite setIC group_modl //; apply/setIidPr/subsetP=> x Gx.
pose H1 := (H :^ x^-1)%G.
have hallH1: pi.-Hall(K) H1 by rewrite pHallJnorm // groupV (subsetP nKG).
case: (Hall_trans solK hallH hallH1) => y Ky defH.
rewrite -(mulKVg y x) mem_mulg //; apply/normP.
by rewrite conjsgM {1}defH conjsgK conjsgKV.
Qed.
End HallCorollaries.
Section InternalAction.
Variables (pi : nat_pred) (gT : finGroupType).
Implicit Types G H K A X : {group gT}.
(* Part of Aschbacher (18.7.4). *)
Lemma coprime_norm_cent A G :
A \subset 'N(G) -> coprime #|G| #|A| -> 'N_G(A) = 'C_G(A).
Proof.
move=> nGA coGA; apply/eqP; rewrite eqEsubset andbC setIS ?cent_sub //=.
rewrite subsetI subsetIl /= (sameP commG1P trivgP) -(coprime_TIg coGA).
rewrite subsetI commg_subr subsetIr andbT.
move: nGA; rewrite -commg_subl; apply: subset_trans.
by rewrite commSg ?subsetIl.
Qed.
(* This is B & G, Proposition 1.5(a) *)
Proposition coprime_Hall_exists A G :
A \subset 'N(G) -> coprime #|G| #|A| -> solvable G ->
exists2 H : {group gT}, pi.-Hall(G) H & A \subset 'N(H).
Proof.
move=> nGA coGA solG; have [H hallH] := Hall_exists pi solG.
have sG_AG: G \subset A <*> G by rewrite joing_subr.
have nG_AG: A <*> G \subset 'N(G) by rewrite join_subG nGA normG.
pose N := 'N_(A <*> G)(H)%G.
have nGN: N \subset 'N(G) by rewrite subIset ?nG_AG.
have nGN_N: G :&: N <| N by rewrite /(_ <| N) subsetIr normsI ?normG.
have NG_AG: G * N = A <*> G.
by apply: Hall_Frattini_arg hallH => //; apply/andP.
have iGN_A: #|N| %/ #|G :&: N| = #|A|.
rewrite setIC divgI -card_quotient // -quotientMidl NG_AG.
rewrite card_quotient -?divgS //= norm_joinEl //.
by rewrite coprime_cardMg 1?coprime_sym // mulnK.
have hallGN: Hall N (G :&: N).
by rewrite /Hall -divgS subsetIr //= iGN_A (coprimeSg _ coGA) ?subsetIl.
case/splitsP: {hallGN nGN_N}(SchurZassenhaus_split hallGN nGN_N) => B.
case/complP=> trBGN defN.
have{trBGN iGN_A} oBA: #|B| = #|A|.
by rewrite -iGN_A -{1}defN (TI_cardMg trBGN) mulKn.
have sBN: B \subset N by rewrite -defN mulG_subr.
case: (SchurZassenhaus_trans_sol solG nGA _ coGA oBA) => [|x Gx defB].
by rewrite -(normC nGA) -norm_joinEl // -NG_AG -(mul1g B) mulgSS ?sub1G.
exists (H :^ x^-1)%G; first by rewrite pHallJ ?groupV.
apply/subsetP=> y Ay; have: y ^ x \in B by rewrite defB memJ_conjg.
move/(subsetP sBN)=> /setIP[_ /normP nHyx].
by apply/normP; rewrite -conjsgM conjgCV invgK conjsgM nHyx.
Qed.
(* This is B & G, Proposition 1.5(c) *)
Proposition coprime_Hall_trans A G H1 H2 :
A \subset 'N(G) -> coprime #|G| #|A| -> solvable G ->
pi.-Hall(G) H1 -> A \subset 'N(H1) ->
pi.-Hall(G) H2 -> A \subset 'N(H2) ->
exists2 x, x \in 'C_G(A) & H1 :=: H2 :^ x.
Proof.
move: H1 => H nGA coGA solG hallH nHA hallH2.
have{H2 hallH2} [x Gx -> nH1xA] := Hall_trans solG hallH2 hallH.
have sG_AG: G \subset A <*> G by rewrite -{1}genGid genS ?subsetUr.
have nG_AG: A <*> G \subset 'N(G) by rewrite gen_subG subUset nGA normG.
pose N := 'N_(A <*> G)(H)%G.
have nGN: N \subset 'N(G) by rewrite subIset ?nG_AG.
have nGN_N: G :&: N <| N.
apply/normalP; rewrite subsetIr; split=> // y Ny.
by rewrite conjIg (normP _) // (subsetP nGN, conjGid).
have NG_AG : G * N = A <*> G.
by apply: Hall_Frattini_arg hallH => //; apply/andP.
have iGN_A: #|N : G :&: N| = #|A|.
rewrite -card_quotient //; last by case/andP: nGN_N.
rewrite (card_isog (second_isog nGN)) /= -quotientMidr (normC nGN) NG_AG.
rewrite card_quotient // -divgS //= joingC norm_joinEr //.
by rewrite coprime_cardMg // mulnC mulnK.
have solGN: solvable (G :&: N) by apply: solvableS solG; apply: subsetIl.
have oAxA: #|A :^ x^-1| = #|A| by apply: cardJg.
have sAN: A \subset N by rewrite subsetI -{1}genGid genS // subsetUl.
have nGNA: A \subset 'N(G :&: N).
by apply/normsP=> y ?; rewrite conjIg (normsP nGA) ?(conjGid, subsetP sAN).
have coGNA: coprime #|G :&: N| #|A| := coprimeSg (subsetIl _ _) coGA.
case: (SchurZassenhaus_trans_sol solGN nGNA _ coGNA oAxA) => [|y GNy defAx].
have ->: (G :&: N) * A = N.
apply/eqP; rewrite eqEcard -{2}(mulGid N) mulgSS ?subsetIr //=.
by rewrite coprime_cardMg // -iGN_A Lagrange ?subsetIr.
rewrite sub_conjgV conjIg -normJ subsetI conjGid ?joing_subl //.
by rewrite mem_gen // inE Gx orbT.
case/setIP: GNy => Gy; case/setIP=> _; move/normP=> nHy.
exists (y * x)^-1.
rewrite -coprime_norm_cent // groupV inE groupM //=; apply/normP.
by rewrite conjsgM -defAx conjsgKV.
by apply: val_inj; rewrite /= -{2}nHy -(conjsgM _ y) conjsgK.
Qed.
(* A complement to the above: 'C(A) acts on 'Nby(A) *)
Lemma norm_conj_cent A G x : x \in 'C(A) ->
(A \subset 'N(G :^ x)) = (A \subset 'N(G)).
Proof. by move=> cAx; rewrite norm_conj_norm ?(subsetP (cent_sub A)). Qed.
(* Strongest version of the centraliser lemma -- not found in textbooks! *)
(* Obviously, the solvability condition could be removed once we have the *)
(* Odd Order Theorem. *)
Lemma strongest_coprime_quotient_cent A G H :
let R := H :&: [~: G, A] in
A \subset 'N(H) -> R \subset G -> coprime #|R| #|A| ->
solvable R || solvable A ->
'C_G(A) / H = 'C_(G / H)(A / H).
Proof.
move=> R nHA sRG coRA solRA.
have nRA: A \subset 'N(R) by rewrite normsI ?commg_normr.
apply/eqP; rewrite eqEsubset subsetI morphimS ?subsetIl //=.
rewrite (subset_trans _ (morphim_cent _ _)) ?morphimS ?subsetIr //=.
apply/subsetP=> _ /setIP[/morphimP[x Nx Gx ->] cAHx].
have{cAHx} cAxR y: y \in A -> [~ x, y] \in R.
move=> Ay; have Ny: y \in 'N(H) by apply: subsetP Ay.
rewrite inE mem_commg // andbT coset_idr ?groupR // morphR //=.
by apply/eqP; apply/commgP; apply: (centP cAHx); rewrite mem_quotient.
have AxRA: A :^ x \subset R * A.
apply/subsetP=> _ /imsetP[y Ay ->].
rewrite -normC // -(mulKVg y (y ^ x)) -commgEl mem_mulg //.
by rewrite -groupV invg_comm cAxR.
have [y Ry def_Ax]: exists2 y, y \in R & A :^ x = A :^ y.
have oAx: #|A :^ x| = #|A| by rewrite cardJg.
have [solR | solA] := orP solRA; first exact: SchurZassenhaus_trans_sol.
by apply: SchurZassenhaus_trans_actsol; rewrite // joingC norm_joinEr.
rewrite -imset_coset; apply/imsetP; exists (x * y^-1); last first.
by rewrite conjgCV mkerl // ker_coset memJ_norm groupV; case/setIP: Ry.
rewrite /= inE groupMl // ?(groupV, subsetP sRG) //=.
apply/centP=> z Az; apply/commgP/eqP/set1P.
rewrite -[[set 1]](coprime_TIg coRA) inE {1}commgEl commgEr /= -/R.
rewrite invMg -mulgA invgK (@groupMl _ R) // conjMg mulgA -commgEl.
rewrite groupMl ?cAxR // memJ_norm ?(groupV, subsetP nRA) // Ry /=.
by rewrite groupMr // conjVg groupV conjgM -mem_conjg -def_Ax memJ_conjg.
Qed.
(* A weaker but more practical version, still stronger than the usual form *)
(* (viz. Aschbacher 18.7.4), similar to the one needed in Aschbacher's *)
(* proof of Thompson factorization. Note that the coprime and solvability *)
(* assumptions could be further weakened to H :&: G (and hence become *)
(* trivial if H and G are TI). However, the assumption that A act on G is *)
(* needed in this case. *)
Lemma coprime_norm_quotient_cent A G H :
A \subset 'N(G) -> A \subset 'N(H) -> coprime #|H| #|A| -> solvable H ->
'C_G(A) / H = 'C_(G / H)(A / H).
Proof.
move=> nGA nHA coHA solH; have sRH := subsetIl H [~: G, A].
rewrite strongest_coprime_quotient_cent ?(coprimeSg sRH) 1?(solvableS sRH) //.
by rewrite subIset // commg_subl nGA orbT.
Qed.
(* A useful consequence (similar to Ex. 6.1 in Aschbacher) of the stronger *)
(* theorem. *)
Lemma coprime_cent_mulG A G H :
A \subset 'N(G) -> A \subset 'N(H) -> G \subset 'N(H) ->
coprime #|H| #|A| -> solvable H ->
'C_(H * G)(A) = 'C_H(A) * 'C_G(A).
Proof.
move=> nHA nGA nHG coHA solH; rewrite -norm_joinEr //.
have nsHG: H <| H <*> G by rewrite /normal joing_subl join_subG normG.
rewrite -{2}(setIidPr (normal_sub nsHG)) setIAC.
rewrite group_modr ?setSI ?joing_subr //=; symmetry; apply/setIidPl.
rewrite -quotientSK ?subIset 1?normal_norm //.
by rewrite !coprime_norm_quotient_cent ?normsY //= norm_joinEr ?quotientMidl.
Qed.
(* Another special case of the strong coprime quotient lemma; not found in *)
(* textbooks, but nevertheless used implicitly throughout B & G, sometimes *)
(* justified by switching to external action. *)
Lemma quotient_TI_subcent K G H :
G \subset 'N(K) -> G \subset 'N(H) -> K :&: H = 1 ->
'C_K(G) / H = 'C_(K / H)(G / H).
Proof.
move=> nGK nGH tiKH.
have tiHR: H :&: [~: K, G] = 1.
by apply/trivgP; rewrite /= setIC -tiKH setSI ?commg_subl.
apply: strongest_coprime_quotient_cent; rewrite ?tiHR ?sub1G ?solvable1 //.
by rewrite cards1 coprime1n.
Qed.
(* This is B & G, Proposition 1.5(d): the more traditional form of the lemma *)
(* above, with the assumption H <| G weakened to H \subset G. The stronger *)
(* coprime and solvability assumptions are easier to satisfy in practice. *)
Proposition coprime_quotient_cent A G H :
H \subset G -> A \subset 'N(H) -> coprime #|G| #|A| -> solvable G ->
'C_G(A) / H = 'C_(G / H)(A / H).
Proof.
move=> sHG nHA coGA solG.
have sRG: H :&: [~: G, A] \subset G by rewrite subIset ?sHG.
by rewrite strongest_coprime_quotient_cent ?(coprimeSg sRG) 1?(solvableS sRG).
Qed.
(* This is B & G, Proposition 1.5(e). *)
Proposition coprime_comm_pcore A G K :
A \subset 'N(G) -> coprime #|G| #|A| -> solvable G ->
pi^'.-Hall(G) K -> K \subset 'C_G(A) ->
[~: G, A] \subset 'O_pi(G).
Proof.
move=> nGA coGA solG hallK cKA.
case: (coprime_Hall_exists nGA) => // H hallH nHA.
have sHG: H \subset G by case/andP: hallH.
have sKG: K \subset G by case/andP: hallK.
have coKH: coprime #|K| #|H|.
case/and3P: hallH=> _ piH _; case/and3P: hallK => _ pi'K _.
by rewrite coprime_sym (pnat_coprime piH pi'K).
have defG: G :=: K * H.
apply/eqP; rewrite eq_sym eqEcard coprime_cardMg //.
rewrite -{1}(mulGid G) mulgSS //= (card_Hall hallH) (card_Hall hallK).
by rewrite mulnC partnC.
have sGA_H: [~: G, A] \subset H.
rewrite gen_subG defG.
apply/subsetP=> _ /imset2P[_ a /imset2P[x y Kx Hy ->] Aa ->].
rewrite commMgJ (([~ x, a] =P 1) _) ?(conj1g, mul1g).
by rewrite groupMl ?groupV // memJ_norm ?(subsetP nHA).
by rewrite subsetI sKG in cKA; apply/commgP/(centsP cKA).
apply: pcore_max; last first.
by rewrite /(_ <| G) /= commg_norml commGC commg_subr nGA.
by case/and3P: hallH => _ piH _; apply: pgroupS piH.
Qed.
End InternalAction.
(* This is B & G, Proposition 1.5(b). *)
Proposition coprime_Hall_subset pi (gT : finGroupType) (A G X : {group gT}) :
A \subset 'N(G) -> coprime #|G| #|A| -> solvable G ->
X \subset G -> pi.-group X -> A \subset 'N(X) ->
exists H : {group gT}, [/\ pi.-Hall(G) H, A \subset 'N(H) & X \subset H].
Proof.
have [n] := ubnP #|G|.
elim: n => // n IHn in gT A G X * => /ltnSE-leGn nGA coGA solG sXG piX nXA.
have [G1 | ntG] := eqsVneq G 1.
case: (coprime_Hall_exists pi nGA) => // H hallH nHA.
by exists H; split; rewrite // (subset_trans sXG) // G1 sub1G.
have sG_AG: G \subset A <*> G by rewrite joing_subr.
have sA_AG: A \subset A <*> G by rewrite joing_subl.
have nG_AG: A <*> G \subset 'N(G) by rewrite join_subG nGA normG.
have nsG_AG: G <| A <*> G by apply/andP.
case: (solvable_norm_abelem solG nsG_AG) => // M [sMG nsMAG ntM].
have{nsMAG} [nMA nMG]: A \subset 'N(M) /\ G \subset 'N(M).
by apply/andP; rewrite -join_subG normal_norm.
have nMX: X \subset 'N(M) by apply: subset_trans nMG.
case/is_abelemP=> p pr_p; case/and3P=> pM cMM _.
have: #|G / M| < n by rewrite (leq_trans (ltn_quotient _ _)).
move/(IHn _ (A / M)%G _ (X / M)%G); rewrite !(quotient_norms, quotientS) //.
rewrite !(coprime_morph, quotient_sol, morphim_pgroup) //.
case=> //= Hq []; case/and3P=> sHGq piHq pi'Hq' nHAq sXHq.
case/inv_quotientS: (sHGq) => [|HM defHM sMHM sHMG]; first exact/andP.
have nMHM := subset_trans sHMG nMG.
have{sXHq} sXHM: X \subset HM by rewrite -(quotientSGK nMX) -?defHM.
have{pi'Hq' sHGq} pi'HM': pi^'.-nat #|G : HM|.
move: pi'Hq'; rewrite -!divgS // defHM !card_quotient //.
by rewrite -(divnMl (cardG_gt0 M)) !Lagrange.
have{nHAq} nHMA: A \subset 'N(HM).
by rewrite -(quotientSGK nMA) ?normsG ?quotient_normG -?defHM //; apply/andP.
case/orP: (orbN (p \in pi)) => pi_p.
exists HM; split=> //; apply/and3P; split; rewrite /pgroup //.
by rewrite -(Lagrange sMHM) pnatM -card_quotient // -defHM (pi_pnat pM).
case: (ltnP #|HM| #|G|) => [ltHG | leGHM {n IHn leGn}].
case: (IHn _ A HM X (leq_trans ltHG leGn)) => // [||H [hallH nHA sXH]].
- exact: coprimeSg coGA.
- exact: solvableS solG.
case/and3P: hallH => sHHM piH pi'H'.
have sHG: H \subset G by apply: subset_trans sHMG.
exists H; split=> //; apply/and3P; split=> //.
rewrite -divgS // -(Lagrange sHMG) -(Lagrange sHHM) -mulnA mulKn //.
by rewrite pnatM pi'H'.
have{leGHM nHMA sHMG sMHM sXHM pi'HM'} eqHMG: HM = G.
by apply/eqP; rewrite -val_eqE eqEcard sHMG.
have pi'M: pi^'.-group M by rewrite /pgroup (pi_pnat pM).
have{HM Hq nMHM defHM eqHMG piHq} hallM: pi^'.-Hall(G) M.
apply/and3P; split; rewrite // /pgroup pnatNK.
by rewrite -card_quotient // -eqHMG -defHM.
case: (coprime_Hall_exists pi nGA) => // H hallH nHA.
pose XM := (X <*> M)%G; pose Y := (H :&: XM)%G.
case/and3P: (hallH) => sHG piH _.
have sXXM: X \subset XM by rewrite joing_subl.
have co_pi_M (B : {group gT}): pi.-group B -> coprime #|B| #|M|.
by move=> piB; rewrite (pnat_coprime piB).
have hallX: pi.-Hall(XM) X.
rewrite /pHall piX sXXM -divgS //= norm_joinEl //.
by rewrite coprime_cardMg ?co_pi_M // mulKn.
have sXMG: XM \subset G by rewrite join_subG sXG.
have hallY: pi.-Hall(XM) Y.
have sYXM: Y \subset XM by rewrite subsetIr.
have piY: pi.-group Y by apply: pgroupS piH; apply: subsetIl.
rewrite /pHall sYXM piY -divgS // -(_ : Y * M = XM).
by rewrite coprime_cardMg ?co_pi_M // mulKn //.
rewrite /= setIC group_modr ?joing_subr //=; apply/setIidPl.
rewrite ((H * M =P G) _) // eqEcard mul_subG //= coprime_cardMg ?co_pi_M //.
by rewrite (card_Hall hallM) (card_Hall hallH) partnC.
have nXMA: A \subset 'N(XM) by rewrite normsY.
have:= coprime_Hall_trans nXMA _ _ hallX nXA hallY.
rewrite !(coprimeSg sXMG, solvableS sXMG, normsI) //.
case=> // x /setIP[XMx cAx] ->.
exists (H :^ x)%G; split; first by rewrite pHallJ ?(subsetP sXMG).
by rewrite norm_conj_cent.
by rewrite conjSg subsetIl.
Qed.
Section ExternalAction.
Variables (pi : nat_pred) (aT gT : finGroupType).
Variables (A : {group aT}) (G : {group gT}) (to : groupAction A G).
Section FullExtension.
Local Notation inA := (sdpair2 to).
Local Notation inG := (sdpair1 to).
Local Notation A' := (inA @* gval A).
Local Notation G' := (inG @* gval G).
Let injG : 'injm inG := injm_sdpair1 _.
Let injA : 'injm inA := injm_sdpair2 _.
Hypotheses (coGA : coprime #|G| #|A|) (solG : solvable G).
Lemma external_action_im_coprime : coprime #|G'| #|A'|.
Proof. by rewrite !card_injm. Qed.
Let coGA' := external_action_im_coprime.
Let solG' : solvable G' := morphim_sol _ solG.
Let nGA' := im_sdpair_norm to.
Lemma ext_coprime_Hall_exists :
exists2 H : {group gT}, pi.-Hall(G) H & [acts A, on H | to].
Proof.
have [H' hallH' nHA'] := coprime_Hall_exists pi nGA' coGA' solG'.
have sHG' := pHall_sub hallH'.
exists (inG @*^-1 H')%G => /=.
by rewrite -(morphim_invmE injG) -{1}(im_invm injG) morphim_pHall.
by rewrite actsEsd ?morphpreK // subsetIl.
Qed.
Lemma ext_coprime_Hall_trans (H1 H2 : {group gT}) :
pi.-Hall(G) H1 -> [acts A, on H1 | to] ->
pi.-Hall(G) H2 -> [acts A, on H2 | to] ->
exists2 x, x \in 'C_(G | to)(A) & H1 :=: H2 :^ x.
Proof.
move=> hallH1 nH1A hallH2 nH2A.
have sH1G := pHall_sub hallH1; have sH2G := pHall_sub hallH2.
rewrite !actsEsd // in nH1A nH2A.
have hallH1': pi.-Hall(G') (inG @* H1) by rewrite morphim_pHall.
have hallH2': pi.-Hall(G') (inG @* H2) by rewrite morphim_pHall.
have [x'] := coprime_Hall_trans nGA' coGA' solG' hallH1' nH1A hallH2' nH2A.
case/setIP=> /= Gx' cAx' /eqP defH1; pose x := invm injG x'.
have Gx: x \in G by rewrite -(im_invm injG) mem_morphim.
have def_x': x' = inG x by rewrite invmK.
exists x; first by rewrite inE Gx gacentEsd mem_morphpre /= -?def_x'.
apply/eqP; move: defH1; rewrite def_x' /= -morphimJ //=.
by rewrite !eqEsubset !injmSK // conj_subG.
Qed.
Lemma ext_norm_conj_cent (H : {group gT}) x :
H \subset G -> x \in 'C_(G | to)(A) ->
[acts A, on H :^ x | to] = [acts A, on H | to].
Proof.
move=> sHG /setIP[Gx].
rewrite gacentEsd !actsEsd ?conj_subG ?morphimJ // 2!inE Gx /=.
exact: norm_conj_cent.
Qed.
Lemma ext_coprime_Hall_subset (X : {group gT}) :
X \subset G -> pi.-group X -> [acts A, on X | to] ->
exists H : {group gT},
[/\ pi.-Hall(G) H, [acts A, on H | to] & X \subset H].
Proof.
move=> sXG piX; rewrite actsEsd // => nXA'.
case: (coprime_Hall_subset nGA' coGA' solG' _ (morphim_pgroup _ piX) nXA').
exact: morphimS.
move=> H' /= [piH' nHA' sXH']; have sHG' := pHall_sub piH'.
exists (inG @*^-1 H')%G; rewrite actsEsd ?subsetIl ?morphpreK // nHA'.
rewrite -sub_morphim_pre //= sXH'; split=> //.
by rewrite -(morphim_invmE injG) -{1}(im_invm injG) morphim_pHall.
Qed.
End FullExtension.
(* We only prove a weaker form of the coprime group action centraliser *)
(* lemma, because it is more convenient in practice to make G the range *)
(* of the action, whence G both contains H and is stable under A. *)
(* However we do restrict the coprime/solvable assumptions to H, and *)
(* we do not require that G normalize H. *)
Lemma ext_coprime_quotient_cent (H : {group gT}) :
H \subset G -> [acts A, on H | to] -> coprime #|H| #|A| -> solvable H ->
'C_(|to)(A) / H = 'C_(|to / H)(A).
Proof.
move=> sHG nHA coHA solH; pose N := 'N_G(H).
have nsHN: H <| N by rewrite normal_subnorm.
have [sHN nHn] := andP nsHN.
have sNG: N \subset G by apply: subsetIl.
have nNA: {acts A, on group N | to}.
split; rewrite // actsEsd // injm_subnorm ?injm_sdpair1 //=.
by rewrite normsI ?norms_norm ?im_sdpair_norm -?actsEsd.
rewrite -!(gacentIdom _ A) -quotientInorm -gacentIim setIAC.
rewrite -(gacent_actby nNA) gacentEsd -morphpreIim /= -/N.
have:= (injm_sdpair1 <[nNA]>, injm_sdpair2 <[nNA]>).
set inG := sdpair1 _; set inA := sdpair2 _ => [[injG injA]].
set G' := inG @* N; set A' := inA @* A; pose H' := inG @* H.
have defN: 'N(H | to) = A by apply/eqP; rewrite eqEsubset subsetIl.
have def_Dq: qact_dom to H = A by rewrite qact_domE.
have sAq: A \subset qact_dom to H by rewrite def_Dq.
rewrite {2}def_Dq -(gacent_ract _ sAq); set to_q := (_ \ _)%gact.
have:= And3 (sdprod_sdpair to_q) (injm_sdpair1 to_q) (injm_sdpair2 to_q).
rewrite gacentEsd; set inAq := sdpair2 _; set inGq := sdpair1 _ => /=.
set Gq := inGq @* _; set Aq := inAq @* _ => [[q_d iGq iAq]].
have nH': 'N(H') = setT.
apply/eqP; rewrite -subTset -im_sdpair mulG_subG morphim_norms //=.
by rewrite -actsEsd // acts_actby subxx /= (setIidPr sHN).
have: 'dom (coset H' \o inA \o invm iAq) = Aq.
by rewrite ['dom _]morphpre_invm /= nH' morphpreT.
case/domP=> /= qA [def_qA ker_qA _ im_qA].
have{coHA} coHA': coprime #|H'| #|A'| by rewrite !card_injm.
have{ker_qA} injAq: 'injm qA.
rewrite {}ker_qA !ker_comp ker_coset morphpre_invm -morphpreIim /= setIC.
by rewrite coprime_TIg // -kerE (trivgP injA) morphim1.
have{im_qA} im_Aq : qA @* Aq = A' / H'.
by rewrite {}im_qA !morphim_comp im_invm.
have: 'dom (quotm (sdpair1_morphism <[nNA]>) nsHN \o invm iGq) = Gq.
by rewrite ['dom _]morphpre_invm /= quotientInorm.
case/domP=> /= qG [def_qG ker_qG _ im_qG].
have{ker_qG} injGq: 'injm qG.
rewrite {}ker_qG ker_comp ker_quotm morphpre_invm (trivgP injG).
by rewrite quotient1 morphim1.
have im_Gq: qG @* Gq = G' / H'.
rewrite {}im_qG morphim_comp im_invm morphim_quotm //= -/inG -/H'.
by rewrite -morphimIdom setIAC setIid.
have{def_qA def_qG} q_J : {in Gq & Aq, morph_act 'J 'J qG qA}.
move=> x' a'; case/morphimP=> Hx; case/morphimP=> x nHx Gx -> GHx ->{Hx x'}.
case/morphimP=> a _ Aa ->{a'} /=; rewrite -/inAq -/inGq.
rewrite !{}def_qG {}def_qA /= !invmE // -sdpair_act //= -/inG -/inA.
have Nx: x \in N by rewrite inE Gx.
have Nxa: to x a \in N by case: (nNA); move/acts_act->.
have [Gxa nHxa] := setIP Nxa.
rewrite invmE qactE ?quotmE ?mem_morphim ?def_Dq //=.
by rewrite -morphJ /= ?nH' ?inE // -sdpair_act //= actbyE.
pose q := sdprodm q_d q_J.
have{injAq injGq} injq: 'injm q.
rewrite injm_sdprodm injAq injGq /= {}im_Aq {}im_Gq -/Aq .
by rewrite -quotientGI ?im_sdpair_TI ?morphimS //= quotient1.
rewrite -[inGq @*^-1 _]morphpreIim -/Gq.
have sC'G: inG @*^-1 'C_G'(A') \subset G by rewrite !subIset ?subxx.
rewrite -[_ / _](injmK iGq) ?quotientS //= -/inGq; congr (_ @*^-1 _).
apply: (injm_morphim_inj injq); rewrite 1?injm_subcent ?subsetT //= -/q.
rewrite 2?morphim_sdprodml ?morphimS //= im_Gq.
rewrite morphim_sdprodmr ?morphimS //= im_Aq.
rewrite {}im_qG morphim_comp morphim_invm ?morphimS //.
rewrite morphim_quotm morphpreK ?subsetIl //= -/H'.
rewrite coprime_norm_quotient_cent ?im_sdpair_norm ?nH' ?subsetT //=.
exact: morphim_sol.
Qed.
End ExternalAction.
Section SylowSolvableAct.
Variables (gT : finGroupType) (p : nat).
Implicit Types A B G X : {group gT}.
Lemma sol_coprime_Sylow_exists A G :
solvable A -> A \subset 'N(G) -> coprime #|G| #|A| ->
exists2 P : {group gT}, p.-Sylow(G) P & A \subset 'N(P).
Proof.
move=> solA nGA coGA; pose AG := A <*> G.
have nsG_AG: G <| AG by rewrite /normal joing_subr join_subG nGA normG.
have [sG_AG nG_AG]:= andP nsG_AG.
have [P sylP] := Sylow_exists p G; pose N := 'N_AG(P); pose NG := G :&: N.
have nGN: N \subset 'N(G) by rewrite subIset ?nG_AG.
have sNG_G: NG \subset G := subsetIl G N.
have nsNG_N: NG <| N by rewrite /normal subsetIr normsI ?normG.
have defAG: G * N = AG := Frattini_arg nsG_AG sylP.
have oA : #|A| = #|N| %/ #|NG|.
rewrite /NG setIC divgI -card_quotient // -quotientMidl defAG.
rewrite card_quotient -?divgS //= norm_joinEl //.
by rewrite coprime_cardMg 1?coprime_sym // mulnK.
have: [splits N, over NG].
rewrite SchurZassenhaus_split // /Hall -divgS subsetIr //.
by rewrite -oA (coprimeSg sNG_G).
case/splitsP=> B; case/complP=> tNG_B defN.
have [nPB]: B \subset 'N(P) /\ B \subset AG.
by apply/andP; rewrite andbC -subsetI -/N -defN mulG_subr.
case/SchurZassenhaus_trans_actsol => // [|x Gx defB].
by rewrite oA -defN TI_cardMg // mulKn.
exists (P :^ x^-1)%G; first by rewrite pHallJ ?groupV.
by rewrite normJ -sub_conjg -defB.
Qed.
Lemma sol_coprime_Sylow_trans A G :
solvable A -> A \subset 'N(G) -> coprime #|G| #|A| ->
[transitive 'C_G(A), on [set P in 'Syl_p(G) | A \subset 'N(P)] | 'JG].
Proof.
move=> solA nGA coGA; pose AG := A <*> G; set FpA := finset _.
have nG_AG: AG \subset 'N(G) by rewrite join_subG nGA normG.
have [P sylP nPA] := sol_coprime_Sylow_exists solA nGA coGA.
pose N := 'N_AG(P); have sAN: A \subset N by rewrite subsetI joing_subl.
have trNPA: A :^: AG ::&: N = A :^: N.
pose NG := 'N_G(P); have sNG_G : NG \subset G := subsetIl _ _.
have nNGA: A \subset 'N(NG) by rewrite normsI ?norms_norm.
apply/setP=> Ax; apply/setIdP/imsetP=> [[]|[x Nx ->{Ax}]]; last first.
by rewrite conj_subG //; case/setIP: Nx => AGx; rewrite imset_f.
have ->: N = A <*> NG by rewrite /N /AG !norm_joinEl // -group_modl.
have coNG_A := coprimeSg sNG_G coGA; case/imsetP=> x AGx ->{Ax}.
case/SchurZassenhaus_trans_actsol; rewrite ?cardJg // => y Ny /= ->.
by exists y; rewrite // mem_gen 1?inE ?Ny ?orbT.
have{trNPA}: [transitive 'N_AG(A), on FpA | 'JG].
have ->: FpA = 'Fix_('Syl_p(G) | 'JG)(A).
by apply/setP=> Q; rewrite 4!inE afixJG.
have SylP : P \in 'Syl_p(G) by rewrite inE.
apply/(trans_subnorm_fixP _ SylP); rewrite ?astab1JG //.
rewrite (atrans_supgroup _ (Syl_trans _ _)) ?joing_subr //= -/AG.
by apply/actsP=> x /= AGx Q /=; rewrite !inE -{1}(normsP nG_AG x) ?pHallJ2.
rewrite {1}/AG norm_joinEl // -group_modl ?normG ?coprime_norm_cent //=.
rewrite -cent_joinEr ?subsetIr // => trC_FpA.
have FpA_P: P \in FpA by rewrite !inE sylP.
apply/(subgroup_transitiveP FpA_P _ trC_FpA); rewrite ?joing_subr //=.
rewrite astab1JG cent_joinEr ?subsetIr // -group_modl // -mulgA.
by congr (_ * _); rewrite mulSGid ?subsetIl.
Qed.
Lemma sol_coprime_Sylow_subset A G X :
A \subset 'N(G) -> coprime #|G| #|A| -> solvable A ->
X \subset G -> p.-group X -> A \subset 'N(X) ->
exists P : {group gT}, [/\ p.-Sylow(G) P, A \subset 'N(P) & X \subset P].
Proof.
move=> nGA coGA solA sXG pX nXA.
pose nAp (Q : {group gT}) := [&& p.-group Q, Q \subset G & A \subset 'N(Q)].
have: nAp X by apply/and3P.
case/maxgroup_exists=> R; case/maxgroupP; case/and3P=> pR sRG nRA maxR sXR.
have [P sylP sRP]:= Sylow_superset sRG pR.
suffices defP: P :=: R by exists P; rewrite sylP defP.
case/and3P: sylP => sPG pP _; apply: (nilpotent_sub_norm (pgroup_nil pP)) => //.
pose N := 'N_G(R); have{sPG} sPN_N: 'N_P(R) \subset N by apply: setSI.
apply: norm_sub_max_pgroup (pgroupS (subsetIl _ _) pP) sPN_N (subsetIr _ _).
have nNA: A \subset 'N(N) by rewrite normsI ?norms_norm.
have coNA: coprime #|N| #|A| by apply: coprimeSg coGA; rewrite subsetIl.
have{solA coNA} [Q sylQ nQA] := sol_coprime_Sylow_exists solA nNA coNA.
suffices defQ: Q :=: R by rewrite max_pgroup_Sylow -{2}defQ.
apply: maxR; first by apply/and3P; case/and3P: sylQ; rewrite subsetI; case/andP.
by apply: normal_sub_max_pgroup (Hall_max sylQ) pR _; rewrite normal_subnorm.
Qed.
End SylowSolvableAct.
|
Algebra.lean
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.GroupWithZero.Indicator
import Mathlib.LinearAlgebra.Pi
import Mathlib.Topology.LocallyConstant.Basic
/-!
# Algebraic structure on locally constant functions
This file puts algebraic structure (`Group`, `AddGroup`, etc)
on the type of locally constant functions.
-/
namespace LocallyConstant
variable {X Y : Type*} [TopologicalSpace X]
@[to_additive]
instance [One Y] : One (LocallyConstant X Y) where one := const X 1
@[to_additive (attr := simp)]
theorem coe_one [One Y] : ⇑(1 : LocallyConstant X Y) = (1 : X → Y) :=
rfl
@[to_additive]
theorem one_apply [One Y] (x : X) : (1 : LocallyConstant X Y) x = 1 :=
rfl
@[to_additive]
instance [Inv Y] : Inv (LocallyConstant X Y) where inv f := ⟨f⁻¹, f.isLocallyConstant.inv⟩
@[to_additive (attr := simp)]
theorem coe_inv [Inv Y] (f : LocallyConstant X Y) : ⇑(f⁻¹ : LocallyConstant X Y) = (f : X → Y)⁻¹ :=
rfl
@[to_additive]
theorem inv_apply [Inv Y] (f : LocallyConstant X Y) (x : X) : f⁻¹ x = (f x)⁻¹ :=
rfl
@[to_additive]
instance [Mul Y] : Mul (LocallyConstant X Y) where
mul f g := ⟨f * g, f.isLocallyConstant.mul g.isLocallyConstant⟩
@[to_additive (attr := simp)]
theorem coe_mul [Mul Y] (f g : LocallyConstant X Y) : ⇑(f * g) = f * g :=
rfl
@[to_additive]
theorem mul_apply [Mul Y] (f g : LocallyConstant X Y) (x : X) : (f * g) x = f x * g x :=
rfl
@[to_additive]
instance [MulOneClass Y] : MulOneClass (LocallyConstant X Y) :=
Function.Injective.mulOneClass DFunLike.coe DFunLike.coe_injective' rfl fun _ _ => rfl
/-- `DFunLike.coe` as a `MonoidHom`. -/
@[to_additive (attr := simps) /-- `DFunLike.coe` as an `AddMonoidHom`. -/]
def coeFnMonoidHom [MulOneClass Y] : LocallyConstant X Y →* X → Y where
toFun := DFunLike.coe
map_one' := rfl
map_mul' _ _ := rfl
/-- The constant-function embedding, as a multiplicative monoid hom. -/
@[to_additive (attr := simps) /-- The constant-function embedding, as an additive monoid hom. -/]
def constMonoidHom [MulOneClass Y] : Y →* LocallyConstant X Y where
toFun := const X
map_one' := rfl
map_mul' _ _ := rfl
instance [MulZeroClass Y] : MulZeroClass (LocallyConstant X Y) :=
Function.Injective.mulZeroClass DFunLike.coe DFunLike.coe_injective' rfl fun _ _ => rfl
instance [MulZeroOneClass Y] : MulZeroOneClass (LocallyConstant X Y) :=
Function.Injective.mulZeroOneClass DFunLike.coe DFunLike.coe_injective' rfl rfl fun _ _ => rfl
section CharFn
variable (Y) [MulZeroOneClass Y] {U V : Set X}
/-- Characteristic functions are locally constant functions taking `x : X` to `1` if `x ∈ U`,
where `U` is a clopen set, and `0` otherwise. -/
noncomputable def charFn (hU : IsClopen U) : LocallyConstant X Y :=
indicator 1 hU
theorem coe_charFn (hU : IsClopen U) : (charFn Y hU : X → Y) = Set.indicator U 1 :=
rfl
theorem charFn_eq_one [Nontrivial Y] (x : X) (hU : IsClopen U) : charFn Y hU x = (1 : Y) ↔ x ∈ U :=
Set.indicator_eq_one_iff_mem _
theorem charFn_eq_zero [Nontrivial Y] (x : X) (hU : IsClopen U) : charFn Y hU x = (0 : Y) ↔ x ∉ U :=
Set.indicator_eq_zero_iff_notMem _
theorem charFn_inj [Nontrivial Y] (hU : IsClopen U) (hV : IsClopen V)
(h : charFn Y hU = charFn Y hV) : U = V :=
Set.indicator_one_inj Y <| coe_inj.mpr h
end CharFn
@[to_additive]
instance [Div Y] : Div (LocallyConstant X Y) where
div f g := ⟨f / g, f.isLocallyConstant.div g.isLocallyConstant⟩
@[to_additive]
theorem coe_div [Div Y] (f g : LocallyConstant X Y) : ⇑(f / g) = f / g :=
rfl
@[to_additive]
theorem div_apply [Div Y] (f g : LocallyConstant X Y) (x : X) : (f / g) x = f x / g x :=
rfl
@[to_additive]
instance [Semigroup Y] : Semigroup (LocallyConstant X Y) :=
Function.Injective.semigroup DFunLike.coe DFunLike.coe_injective' fun _ _ => rfl
instance [SemigroupWithZero Y] : SemigroupWithZero (LocallyConstant X Y) :=
Function.Injective.semigroupWithZero DFunLike.coe DFunLike.coe_injective' rfl fun _ _ => rfl
@[to_additive]
instance [CommSemigroup Y] : CommSemigroup (LocallyConstant X Y) :=
Function.Injective.commSemigroup DFunLike.coe DFunLike.coe_injective' fun _ _ => rfl
variable {α R : Type*}
@[to_additive]
instance smul [SMul α Y] : SMul α (LocallyConstant X Y) where
smul n f := f.map (n • ·)
@[to_additive (attr := simp)]
theorem coe_smul [SMul R Y] (r : R) (f : LocallyConstant X Y) : ⇑(r • f) = r • (f : X → Y) :=
rfl
@[to_additive]
theorem smul_apply [SMul R Y] (r : R) (f : LocallyConstant X Y) (x : X) : (r • f) x = r • f x :=
rfl
@[to_additive existing LocallyConstant.smul]
instance [Pow Y α] : Pow (LocallyConstant X Y) α where
pow f n := f.map (· ^ n)
@[to_additive]
instance [Monoid Y] : Monoid (LocallyConstant X Y) :=
Function.Injective.monoid DFunLike.coe DFunLike.coe_injective' rfl (fun _ _ => rfl) fun _ _ => rfl
instance [NatCast Y] : NatCast (LocallyConstant X Y) where
natCast n := const X n
instance [IntCast Y] : IntCast (LocallyConstant X Y) where
intCast n := const X n
instance [AddMonoidWithOne Y] : AddMonoidWithOne (LocallyConstant X Y) :=
Function.Injective.addMonoidWithOne DFunLike.coe DFunLike.coe_injective' rfl rfl (fun _ _ => rfl)
(fun _ _ => rfl) fun _ => rfl
@[to_additive]
instance [CommMonoid Y] : CommMonoid (LocallyConstant X Y) :=
Function.Injective.commMonoid DFunLike.coe DFunLike.coe_injective' rfl (fun _ _ => rfl)
fun _ _ => rfl
@[to_additive]
instance [Group Y] : Group (LocallyConstant X Y) :=
Function.Injective.group DFunLike.coe DFunLike.coe_injective' rfl (fun _ _ => rfl)
(fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
@[to_additive]
instance [CommGroup Y] : CommGroup (LocallyConstant X Y) :=
Function.Injective.commGroup DFunLike.coe DFunLike.coe_injective' rfl (fun _ _ => rfl)
(fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance [Distrib Y] : Distrib (LocallyConstant X Y) :=
Function.Injective.distrib DFunLike.coe DFunLike.coe_injective' (fun _ _ => rfl) fun _ _ => rfl
instance [NonUnitalNonAssocSemiring Y] : NonUnitalNonAssocSemiring (LocallyConstant X Y) :=
Function.Injective.nonUnitalNonAssocSemiring DFunLike.coe DFunLike.coe_injective' rfl
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance [NonUnitalSemiring Y] : NonUnitalSemiring (LocallyConstant X Y) :=
Function.Injective.nonUnitalSemiring DFunLike.coe DFunLike.coe_injective' rfl
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance [NonAssocSemiring Y] : NonAssocSemiring (LocallyConstant X Y) :=
Function.Injective.nonAssocSemiring DFunLike.coe DFunLike.coe_injective' rfl rfl
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl
/-- The constant-function embedding, as a ring hom. -/
@[simps]
def constRingHom [NonAssocSemiring Y] : Y →+* LocallyConstant X Y :=
{ constMonoidHom, constAddMonoidHom with toFun := const X }
instance [Semiring Y] : Semiring (LocallyConstant X Y) :=
Function.Injective.semiring DFunLike.coe DFunLike.coe_injective' rfl rfl
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl
instance [NonUnitalCommSemiring Y] : NonUnitalCommSemiring (LocallyConstant X Y) :=
Function.Injective.nonUnitalCommSemiring DFunLike.coe DFunLike.coe_injective' rfl
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance [CommSemiring Y] : CommSemiring (LocallyConstant X Y) :=
Function.Injective.commSemiring DFunLike.coe DFunLike.coe_injective' rfl rfl
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl
instance [NonUnitalNonAssocRing Y] : NonUnitalNonAssocRing (LocallyConstant X Y) :=
Function.Injective.nonUnitalNonAssocRing DFunLike.coe DFunLike.coe_injective' rfl (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance [NonUnitalRing Y] : NonUnitalRing (LocallyConstant X Y) :=
Function.Injective.nonUnitalRing DFunLike.coe DFunLike.coe_injective' rfl (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance [NonAssocRing Y] : NonAssocRing (LocallyConstant X Y) :=
Function.Injective.nonAssocRing DFunLike.coe DFunLike.coe_injective' rfl rfl (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ => rfl) (fun _ => rfl)
instance [Ring Y] : Ring (LocallyConstant X Y) :=
Function.Injective.ring DFunLike.coe DFunLike.coe_injective' rfl rfl (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) fun _ => rfl
instance [NonUnitalCommRing Y] : NonUnitalCommRing (LocallyConstant X Y) :=
Function.Injective.nonUnitalCommRing DFunLike.coe DFunLike.coe_injective' rfl (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
instance [CommRing Y] : CommRing (LocallyConstant X Y) :=
Function.Injective.commRing DFunLike.coe DFunLike.coe_injective' rfl rfl (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ => rfl) fun _ => rfl
variable {R : Type*}
instance [Monoid R] [MulAction R Y] : MulAction R (LocallyConstant X Y) :=
Function.Injective.mulAction _ coe_injective fun _ _ => rfl
instance [Monoid R] [AddMonoid Y] [DistribMulAction R Y] :
DistribMulAction R (LocallyConstant X Y) :=
Function.Injective.distribMulAction coeFnAddMonoidHom coe_injective fun _ _ => rfl
instance [Semiring R] [AddCommMonoid Y] [Module R Y] : Module R (LocallyConstant X Y) :=
Function.Injective.module R coeFnAddMonoidHom coe_injective fun _ _ => rfl
section Algebra
variable [CommSemiring R] [Semiring Y] [Algebra R Y]
instance : Algebra R (LocallyConstant X Y) where
algebraMap := constRingHom.comp <| algebraMap R Y
commutes' := by
intros
ext
exact Algebra.commutes' _ _
smul_def' := by
intros
ext
exact Algebra.smul_def' _ _
@[simp]
theorem coe_algebraMap (r : R) : ⇑(algebraMap R (LocallyConstant X Y) r) = algebraMap R (X → Y) r :=
rfl
end Algebra
section coeFn
/-- `DFunLike.coe` as a `RingHom`. -/
@[simps!] def coeFnRingHom [Semiring Y] : LocallyConstant X Y →+* X → Y where
toMonoidHom := coeFnMonoidHom
__ := coeFnAddMonoidHom
/-- `DFunLike.coe` as a linear map. -/
@[simps!] def coeFnₗ (R : Type*) [Semiring R] [AddCommMonoid Y]
[Module R Y] : LocallyConstant X Y →ₗ[R] X → Y where
toAddHom := coeFnAddMonoidHom.toAddHom
map_smul' _ _ := rfl
/-- `DFunLike.coe` as an `AlgHom`. -/
@[simps!] def coeFnAlgHom (R : Type*) [CommSemiring R] [Semiring Y] [Algebra R Y] :
LocallyConstant X Y →ₐ[R] X → Y where
toRingHom := coeFnRingHom
commutes' _ := rfl
end coeFn
section Eval
/-- Evaluation as a `MonoidHom` -/
@[to_additive (attr := simps!) /-- Evaluation as an `AddMonoidHom` -/]
def evalMonoidHom [MulOneClass Y] (x : X) : LocallyConstant X Y →* Y :=
(Pi.evalMonoidHom _ x).comp coeFnMonoidHom
/-- Evaluation as a linear map -/
@[simps!] def evalₗ (R : Type*) [Semiring R] [AddCommMonoid Y]
[Module R Y] (x : X) : LocallyConstant X Y →ₗ[R] Y :=
(LinearMap.proj x).comp (coeFnₗ R)
/-- Evaluation as a `RingHom` -/
@[simps!] def evalRingHom [Semiring Y] (x : X) : LocallyConstant X Y →+* Y :=
(Pi.evalRingHom _ x).comp coeFnRingHom
/-- Evaluation as an `AlgHom` -/
@[simps!]
def evalₐ (R : Type*) [CommSemiring R] [Semiring Y] [Algebra R Y] (x : X) :
LocallyConstant X Y →ₐ[R] Y :=
(Pi.evalAlgHom _ _ x).comp (coeFnAlgHom R)
end Eval
section Comap
variable [TopologicalSpace Y] {Z : Type*}
/-- `LocallyConstant.comap` as a `MonoidHom`. -/
@[to_additive (attr := simps) /-- `LocallyConstant.comap` as an `AddMonoidHom`. -/]
def comapMonoidHom [MulOneClass Z] (f : C(X, Y)) :
LocallyConstant Y Z →* LocallyConstant X Z where
toFun := comap f
map_one' := rfl
map_mul' _ _ := rfl
/-- `LocallyConstant.comap` as a linear map. -/
@[simps!]
def comapₗ (R : Type*) [Semiring R] [AddCommMonoid Z] [Module R Z] (f : C(X, Y)) :
LocallyConstant Y Z →ₗ[R] LocallyConstant X Z where
toFun := comap f
map_add' := map_add (comapAddMonoidHom f)
map_smul' _ _ := rfl
/-- `LocallyConstant.comap` as a `RingHom`. -/
@[simps!]
def comapRingHom [Semiring Z] (f : C(X, Y)) :
LocallyConstant Y Z →+* LocallyConstant X Z where
toMonoidHom := comapMonoidHom f
__ := (comapAddMonoidHom f)
/-- `LocallyConstant.comap` as an `AlgHom` -/
@[simps!]
def comapₐ (R : Type*) [CommSemiring R] [Semiring Z] [Algebra R Z]
(f : C(X, Y)) : LocallyConstant Y Z →ₐ[R] LocallyConstant X Z where
toRingHom := comapRingHom f
commutes' _ := rfl
lemma ker_comapₗ [Semiring R] [AddCommMonoid Z] [Module R Z] (f : C(X, Y))
(hfs : Function.Surjective f) :
LinearMap.ker (comapₗ R f : LocallyConstant Y Z →ₗ[R] LocallyConstant X Z) = ⊥ :=
LinearMap.ker_eq_bot_of_injective <| comap_injective _ hfs
/-- `LocallyConstant.congrLeft` as a linear equivalence. -/
@[simps!]
def congrLeftₗ (R : Type*) [Semiring R] [AddCommMonoid Z] [Module R Z] (e : X ≃ₜ Y) :
LocallyConstant X Z ≃ₗ[R] LocallyConstant Y Z where
toLinearMap := comapₗ R ⟨_, e.symm.continuous⟩
__ := congrLeft e
/-- `LocallyConstant.congrLeft` as a `RingEquiv`. -/
@[simps!]
def congrLeftRingEquiv [Semiring Z] (e : X ≃ₜ Y) :
LocallyConstant X Z ≃+* LocallyConstant Y Z where
toEquiv := congrLeft e
__ := comapMonoidHom ⟨_, e.symm.continuous⟩
__ := comapAddMonoidHom ⟨_, e.symm.continuous⟩
/-- `LocallyConstant.congrLeft` as an `AlgEquiv`. -/
@[simps!]
def congrLeftₐ (R : Type*) [CommSemiring R] [Semiring Z] [Algebra R Z] (e : X ≃ₜ Y) :
LocallyConstant X Z ≃ₐ[R] LocallyConstant Y Z where
toEquiv := congrLeft e
__ := comapₐ R ⟨_, e.symm.continuous⟩
end Comap
section Map
variable {Z : Type*}
/-- `LocallyConstant.map` as a `MonoidHom`. -/
@[to_additive (attr := simps) /-- `LocallyConstant.map` as an `AddMonoidHom`. -/]
def mapMonoidHom [MulOneClass Y] [MulOneClass Z] (f : Y →* Z) :
LocallyConstant X Y →* LocallyConstant X Z where
toFun := map f
map_one' := by aesop
map_mul' := by aesop
/-- `LocallyConstant.map` as a linear map. -/
@[simps!]
def mapₗ (R : Type*) [Semiring R] [AddCommMonoid Y] [Module R Y]
[AddCommMonoid Z] [Module R Z] (f : Y →ₗ[R] Z) :
LocallyConstant X Y →ₗ[R] LocallyConstant X Z where
toFun := map f
map_add' := by aesop
map_smul' := by aesop
/-- `LocallyConstant.map` as a `RingHom`. -/
@[simps!]
def mapRingHom [Semiring Y] [Semiring Z] (f : Y →+* Z) :
LocallyConstant X Y →+* LocallyConstant X Z where
toMonoidHom := mapMonoidHom f
__ := (mapAddMonoidHom f.toAddMonoidHom)
/-- `LocallyConstant.map` as an `AlgHom` -/
@[simps!]
def mapₐ (R : Type*) [CommSemiring R] [Semiring Y] [Algebra R Y] [Semiring Z] [Algebra R Z]
(f : Y →ₐ[R] Z) : LocallyConstant X Y →ₐ[R] LocallyConstant X Z where
toRingHom := mapRingHom f
commutes' _ := by aesop
/-- `LocallyConstant.congrRight` as a linear equivalence. -/
@[simps!]
def congrRightₗ (R : Type*) [Semiring R] [AddCommMonoid Y] [Module R Y]
[AddCommMonoid Z] [Module R Z] (e : Y ≃ₗ[R] Z) :
LocallyConstant X Y ≃ₗ[R] LocallyConstant X Z where
toLinearMap := mapₗ R e
__ := congrRight e.toEquiv
/-- `LocallyConstant.congrRight` as a `RingEquiv`. -/
@[simps!]
def congrRightRingEquiv [Semiring Y] [Semiring Z] (e : Y ≃+* Z) :
LocallyConstant X Y ≃+* LocallyConstant X Z where
toEquiv := congrRight e
__ := mapMonoidHom e.toMonoidHom
__ := mapAddMonoidHom e.toAddMonoidHom
/-- `LocallyConstant.congrRight` as an `AlgEquiv`. -/
@[simps!]
def congrRightₐ (R : Type*) [CommSemiring R] [Semiring Y] [Algebra R Y] [Semiring Z] [Algebra R Z]
(e : Y ≃ₐ[R] Z) : LocallyConstant X Y ≃ₐ[R] LocallyConstant X Z where
toEquiv := congrRight e
__ := mapₐ R e.toAlgHom
end Map
section Const
/-- `LocallyConstant.const` as a linear map. -/
@[simps!]
def constₗ (R : Type*) [Semiring R] [AddCommMonoid Y] [Module R Y] :
Y →ₗ[R] LocallyConstant X Y where
toFun := const X
map_add' _ _ := rfl
map_smul' _ _ := rfl
/-- `LocallyConstant.const` as an `AlgHom` -/
@[simps!]
def constₐ (R : Type*) [CommSemiring R] [Semiring Y] [Algebra R Y] :
Y →ₐ[R] LocallyConstant X Y where
toRingHom := constRingHom
commutes' _ := rfl
end Const
end LocallyConstant
|
FBinop.lean
|
import Mathlib.Tactic.FBinop
import Mathlib.Data.Set.Prod
import Mathlib.Data.Finset.Prod
import Mathlib.Data.SetLike.Basic
private axiom test_sorry : ∀ {α}, α
universe u v w
set_option autoImplicit true
namespace FBinopTests
/-- Notation type class for the set product `×ˢ`. -/
class SProd' (α : Type u) (β : Type v) (γ : outParam (Type w)) where
/-- The cartesian product `s ×ˢ t` is the set of `(a, b)` such that `a ∈ s` and `b ∈ t`. -/
sprod : α → β → γ
-- This notation binds more strongly than (pre)images, unions and intersections.
@[inherit_doc SProd'.sprod] infixr:82 " ×ˢ' " => SProd'.sprod
macro_rules | `($x ×ˢ' $y) => `(fbinop% SProd'.sprod $x $y)
@[default_instance]
instance : SProd' (Set α) (Set β) (Set (α × β)) := ⟨Set.prod⟩
instance : SProd' (Finset α) (Finset β) (Finset (α × β)) := ⟨Finset.product⟩
-- set_option trace.Elab.fbinop true
-- These work without `fbinop%`. They're tests that we haven't broken anything.
example (s : Set α) (t : Set β) : s ×ˢ' t = s ×ˢ' t := rfl
example {α : Type u} {β : Type v} (s : Finset α) (t : Finset β) : s ×ˢ' t = s ×ˢ' t := rfl
example (f : α × α → β) (s : Set (α × α)) : s.InjOn f := test_sorry
example (f : α × α → β) (s t : Set α) : (s ×ˢ' t).InjOn f := test_sorry
example (f : α × α → β) (s t : Finset α) : (s ×ˢ' t : Set (α × α)).InjOn f := test_sorry
example (f : α × α → β) (s t : Finset α) : (s ×ˢ' t : Set _).InjOn f := test_sorry
example (f : α × α → β) (s t : Finset α) : (s ×ˢ' t : Set _).InjOn f := test_sorry
example (f : α × α → β) (s t : Finset α) : ((s : Set _) ×ˢ' (t : Set _)).InjOn f := test_sorry
example (f : α × α → β) (s t : Finset α) : ((s : Set _) ×ˢ' (t : Set _)).InjOn f := test_sorry
example (f : α × α → β) (s t : Finset α) : Set.InjOn f (s ×ˢ' t) := test_sorry
axiom Nat.card : Sort u → Nat
example (s : Finset α) (t : Finset γ) : Nat.card (s ×ˢ' t) = 0 := test_sorry
example (s : Set α) (t : Set (α × ℕ)) : s ×ˢ' {n | 0 < n} = t := test_sorry
example (s : Set α) (t : Set (α × ℕ)) : s ×ˢ' {1, 2, 3} = t := test_sorry
example (s : Set α) (t : Set (ℕ × α)) : {1, 2, 3} ×ˢ' s = t := test_sorry
-- These need `fbinop%`. (Comment out `macro_rules` above to check.)
example {α : Type u} {β : Type v} (s : Finset α) (t : Set β) : s ×ˢ' t = s ×ˢ' t := rfl
example (s : Finset α) (t : Finset (α × ℕ)) : s ×ˢ' {1, 2, 3} = t := test_sorry
example (s : Finset α) (t : Finset (ℕ × α)) : {1, 2, 3} ×ˢ' s = t := test_sorry
example (s : Finset α) (_t : Finset (ℕ × α)) : ({1, 2, 3} ×ˢ' s).card = 22 := test_sorry
/--
info: {1, 2, 3} ×ˢ' {4, 5, 6} : Finset (ℕ × ℕ)
-/
#guard_msgs in
#check ({1,2,3} ×ˢ' {4,5,6} : Finset _)
example (s : Finset α) (t : Set β) (u : Finset γ) : Nat.card (s ×ˢ' t ×ˢ' u) = 0 := test_sorry
example (s : Finset α) (t : Finset β) :
(↑(s ×ˢ' t) : Set _) = (s : Set α) ×ˢ' t := Finset.coe_product s t
structure SubObj (X : Type _) where
carrier : Set X
instance : SetLike (SubObj X) X where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr
-- Note: this easily works because the last argument of `SubObj` is a type.
def SubObj.prod (s : SubObj X) (t : SubObj Y) : SubObj (X × Y) where
carrier := s ×ˢ' t
/-- Modeling subobjects of algebraic types, which have an instance argument after the type. -/
structure DecSubObj (X : Type _) [DecidableEq X] where
carrier : Set X
instance [DecidableEq X] : SetLike (DecSubObj X) X where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr
-- Note: this is testing instance arguments after the type.
def DecSubObj.prod [DecidableEq X] [DecidableEq Y] (s : DecSubObj X) (t : DecSubObj Y) :
DecSubObj (X × Y) where
carrier := s ×ˢ' t
end FBinopTests
|
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.
|
Cyclotomic105.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.RingTheory.Polynomial.Cyclotomic.Basic
import Mathlib.Tactic.NormNum.Prime
/-!
# Not all coefficients of cyclotomic polynomials are -1, 0, or 1
We show that not all coefficients of cyclotomic polynomials are equal to `0`, `-1` or `1`, in the
theorem `not_forall_coeff_cyclotomic_neg_one_zero_one`. We prove this with the counterexample
`coeff_cyclotomic_105 : coeff (cyclotomic 105 ℤ) 7 = -2`.
-/
open Nat (properDivisors)
open Finset
namespace Counterexample
section Computation
instance Nat.fact_prime_five : Fact (Nat.Prime 5) :=
⟨by norm_num⟩
instance Nat.fact_prime_seven : Fact (Nat.Prime 7) :=
⟨by norm_num⟩
theorem properDivisors_15 : Nat.properDivisors 15 = {1, 3, 5} :=
rfl
theorem properDivisors_21 : Nat.properDivisors 21 = {1, 3, 7} :=
rfl
theorem properDivisors_35 : Nat.properDivisors 35 = {1, 5, 7} :=
rfl
theorem properDivisors_105 : Nat.properDivisors 105 = {1, 3, 5, 7, 15, 21, 35} :=
rfl
end Computation
open Polynomial
theorem cyclotomic_3 : cyclotomic 3 ℤ = 1 + X + X ^ 2 := by
simp only [cyclotomic_prime, sum_range_succ, range_one, sum_singleton, pow_zero, pow_one]
theorem cyclotomic_5 : cyclotomic 5 ℤ = 1 + X + X ^ 2 + X ^ 3 + X ^ 4 := by
simp only [cyclotomic_prime, sum_range_succ, range_one, sum_singleton, pow_zero, pow_one]
theorem cyclotomic_7 : cyclotomic 7 ℤ = 1 + X + X ^ 2 + X ^ 3 + X ^ 4 + X ^ 5 + X ^ 6 := by
simp only [cyclotomic_prime, sum_range_succ, range_one, sum_singleton, pow_zero, pow_one]
theorem cyclotomic_15 : cyclotomic 15 ℤ = 1 - X + X ^ 3 - X ^ 4 + X ^ 5 - X ^ 7 + X ^ 8 := by
refine ((eq_cyclotomic_iff (by simp) _).2 ?_).symm
rw [properDivisors_15, Finset.prod_insert _, Finset.prod_insert _, Finset.prod_singleton,
cyclotomic_one, cyclotomic_3, cyclotomic_5]
· ring
repeat' norm_num
theorem cyclotomic_21 :
cyclotomic 21 ℤ = 1 - X + X ^ 3 - X ^ 4 + X ^ 6 - X ^ 8 + X ^ 9 - X ^ 11 + X ^ 12 := by
refine ((eq_cyclotomic_iff (by simp) _).2 ?_).symm
rw [properDivisors_21, Finset.prod_insert _, Finset.prod_insert _, Finset.prod_singleton,
cyclotomic_one, cyclotomic_3, cyclotomic_7]
· ring
repeat' norm_num
theorem cyclotomic_35 :
cyclotomic 35 ℤ =
1 - X + X ^ 5 - X ^ 6 + X ^ 7 - X ^ 8 + X ^ 10 - X ^ 11 + X ^ 12 - X ^ 13 + X ^ 14 - X ^ 16 +
X ^ 17 - X ^ 18 + X ^ 19 - X ^ 23 + X ^ 24 := by
refine ((eq_cyclotomic_iff (by simp) _).2 ?_).symm
rw [properDivisors_35, Finset.prod_insert _, Finset.prod_insert _, Finset.prod_singleton,
cyclotomic_one, cyclotomic_5, cyclotomic_7]
· ring
repeat' norm_num
theorem cyclotomic_105 :
cyclotomic 105 ℤ =
1 + X + X ^ 2 - X ^ 5 - X ^ 6 - 2 * X ^ 7 - X ^ 8 - X ^ 9 + X ^ 12 + X ^ 13 + X ^ 14 +
X ^ 15 + X ^ 16 + X ^ 17 - X ^ 20 - X ^ 22 - X ^ 24 - X ^ 26 - X ^ 28 + X ^ 31 + X ^ 32 +
X ^ 33 + X ^ 34 + X ^ 35 + X ^ 36 - X ^ 39 - X ^ 40 - 2 * X ^ 41 - X ^ 42 - X ^ 43 +
X ^ 46 + X ^ 47 + X ^ 48 := by
refine ((eq_cyclotomic_iff (by simp) _).2 ?_).symm
rw [properDivisors_105]
repeat rw [Finset.prod_insert]
· rw [Finset.prod_singleton, cyclotomic_one, cyclotomic_3, cyclotomic_5, cyclotomic_7,
cyclotomic_15, cyclotomic_21, cyclotomic_35]
ring
repeat' norm_num
theorem coeff_cyclotomic_105 : coeff (cyclotomic 105 ℤ) 7 = -2 := by
simp [cyclotomic_105, coeff_X_of_ne_one, coeff_one]
theorem not_forall_coeff_cyclotomic_neg_one_zero_one :
¬∀ n i, coeff (cyclotomic n ℤ) i ∈ ({-1, 0, 1} : Set ℤ) := by
intro h
specialize h 105 7
rw [coeff_cyclotomic_105] at h
norm_num at h
end Counterexample
|
Duality.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.GroupTheory.FiniteAbelian.Duality
import Mathlib.NumberTheory.MulChar.Basic
/-!
# Duality for multiplicative characters
Let `M` be a finite commutative monoid and `R` a ring that has enough `n`th roots of unity,
where `n` is the exponent of `M`. Then the main results of this file are as follows.
* `MulChar.exists_apply_ne_one_of_hasEnoughRootsOfUnity`: multiplicative characters
`M → R` separate elements of `Mˣ`.
* `MulChar.mulEquiv_units`: the group of multiplicative characters `M → R` is
(noncanonically) isomorphic to `Mˣ`.
-/
namespace MulChar
variable {M R : Type*} [CommMonoid M] [CommRing R]
instance finite [Finite Mˣ] [IsDomain R] : Finite (MulChar M R) := by
have : Finite (Mˣ →* Rˣ) := by
have : Fintype Mˣ := .ofFinite _
let S := rootsOfUnity (Fintype.card Mˣ) R
let F := Mˣ →* S
have fF : Finite F := .of_injective _ DFunLike.coe_injective
refine .of_surjective (fun f : F ↦ (Subgroup.subtype _).comp f) fun f ↦ ?_
have H a : f a ∈ S := by simp only [mem_rootsOfUnity, ← map_pow, pow_card_eq_one, map_one, S]
refine ⟨.codRestrict f S H, MonoidHom.ext fun _ ↦ ?_⟩
simp only [MonoidHom.coe_comp, Subgroup.coe_subtype, Function.comp_apply,
MonoidHom.codRestrict_apply]
exact .of_equiv _ MulChar.equivToUnitHom.symm
lemma exists_apply_ne_one_iff_exists_monoidHom (a : Mˣ) :
(∃ χ : MulChar M R, χ a ≠ 1) ↔ ∃ φ : Mˣ →* Rˣ, φ a ≠ 1 := by
refine ⟨fun ⟨χ, hχ⟩ ↦ ⟨χ.toUnitHom, ?_⟩, fun ⟨φ, hφ⟩ ↦ ⟨ofUnitHom φ, ?_⟩⟩
· contrapose! hχ
rwa [Units.ext_iff, coe_toUnitHom] at hχ
· contrapose! hφ
simpa only [ofUnitHom_eq, equivToUnitHom_symm_coe, Units.val_eq_one] using hφ
variable (M R)
variable [Finite M] [HasEnoughRootsOfUnity R (Monoid.exponent Mˣ)]
/-- If `M` is a finite commutative monoid and `R` is a ring that has enough roots of unity,
then for each `a ≠ 1` in `M`, there exists a multiplicative character `χ : M → R` such that
`χ a ≠ 1`. -/
theorem exists_apply_ne_one_of_hasEnoughRootsOfUnity [Nontrivial R] {a : M} (ha : a ≠ 1) :
∃ χ : MulChar M R, χ a ≠ 1 := by
by_cases hu : IsUnit a
· refine (exists_apply_ne_one_iff_exists_monoidHom hu.unit).mpr ?_
refine CommGroup.exists_apply_ne_one_of_hasEnoughRootsOfUnity Mˣ R ?_
contrapose! ha
rw [← hu.unit_spec, ha, Units.val_eq_one]
· exact ⟨1, by simpa only [map_nonunit _ hu] using zero_ne_one⟩
/-- The group of `R`-valued multiplicative characters on a finite commutative monoid `M` is
(noncanonically) isomorphic to its unit group `Mˣ` when `R` is a ring that has enough roots
of unity. -/
lemma mulEquiv_units : Nonempty (MulChar M R ≃* Mˣ) :=
⟨mulEquivToUnitHom.trans
(CommGroup.monoidHom_mulEquiv_of_hasEnoughRootsOfUnity Mˣ R).some⟩
/-- The cardinality of the group of `R`-valued multiplicative characters on a finite commutative
monoid `M` is the same as that of its unit group `Mˣ` when `R` is a ring that has enough roots
of unity. -/
lemma card_eq_card_units_of_hasEnoughRootsOfUnity : Nat.card (MulChar M R) = Nat.card Mˣ :=
Nat.card_congr (mulEquiv_units M R).some.toEquiv
end MulChar
|
all_ssreflect.v
|
Attributes deprecated(since="mathcomp 2.5.0",
note="Use 'all_boot' and/or 'all_order' instead.").
From mathcomp Require Export all_boot.
From mathcomp Require Export preorder.
From mathcomp Require Export order.
|
IntegrableExpMul.lean
|
/-
Copyright (c) 2024 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Function.L1Space.Integrable
import Mathlib.MeasureTheory.Order.Group.Lattice
/-!
# Domain of the moment generating function
For `X` a real random variable and `μ` a finite measure, the set
`{t | Integrable (fun ω ↦ exp (t * X ω)) μ}` is an interval containing zero. This is the set of
points for which the moment generating function `mgf X μ t` is well defined.
We denote that set by `integrableExpSet X μ`.
We prove the integrability of other functions for `t` in the interior of that interval.
## Main definitions
* `ProbabilityTheory.IntegrableExpSet`: the interval of reals for which `exp (t * X)` is integrable.
## Main results
* `ProbabilityTheory.integrable_exp_mul_of_le_of_le`: if `exp (u * X)` is integrable for `u = a` and
`u = b` then it is integrable on `[a, b]`.
* `ProbabilityTheory.convex_integrableExpSet`: `integrableExpSet X μ` is a convex set.
* `ProbabilityTheory.integrable_exp_mul_of_nonpos_of_ge`: if `exp (u * X)` is integrable for `u ≤ 0`
then it is integrable on `[u, 0]`.
* `ProbabilityTheory.integrable_rpow_abs_mul_exp_of_mem_interior`: for `v` in the interior of the
interval in which `exp (t * X)` is integrable, for all nonnegative `p : ℝ`,
`|X| ^ p * exp (v * X)` is integrable.
* `ProbabilityTheory.memLp_of_mem_interior_integrableExpSet`: if 0 belongs to the interior of
`integrableExpSet X μ`, then `X` is in `ℒp` for all finite `p`.
-/
open MeasureTheory Filter Finset Real
open scoped MeasureTheory ProbabilityTheory ENNReal NNReal Topology
namespace ProbabilityTheory
variable {Ω ι : Type*} {m : MeasurableSpace Ω} {X : Ω → ℝ} {μ : Measure Ω} {t u v : ℝ}
section Interval
lemma integrable_exp_mul_of_le_of_le {a b : ℝ}
(ha : Integrable (fun ω ↦ exp (a * X ω)) μ) (hb : Integrable (fun ω ↦ exp (b * X ω)) μ)
(hat : a ≤ t) (htb : t ≤ b) :
Integrable (fun ω ↦ exp (t * X ω)) μ := by
refine Integrable.mono (ha.add hb) ?_ (ae_of_all _ fun ω ↦ ?_)
· by_cases hab : a = b
· have ha_eq_t : a = t := le_antisymm hat (hab ▸ htb)
rw [← ha_eq_t]
exact ha.1
· refine AEMeasurable.aestronglyMeasurable ?_
refine measurable_exp.comp_aemeasurable (AEMeasurable.const_mul ?_ _)
by_cases ha_zero : a = 0
· refine aemeasurable_of_aemeasurable_exp_mul ?_ hb.1.aemeasurable
rw [ha_zero] at hab
exact Ne.symm hab
· exact aemeasurable_of_aemeasurable_exp_mul ha_zero ha.1.aemeasurable
· simp only [norm_eq_abs, abs_exp, Pi.add_apply]
conv_rhs => rw [abs_of_nonneg (by positivity)]
rcases le_total 0 (X ω) with h | h
· calc exp (t * X ω)
_ ≤ exp (b * X ω) := exp_le_exp.mpr (mul_le_mul_of_nonneg_right htb h)
_ ≤ exp (a * X ω) + exp (b * X ω) := le_add_of_nonneg_left (exp_nonneg _)
· calc exp (t * X ω)
_ ≤ exp (a * X ω) := exp_le_exp.mpr (mul_le_mul_of_nonpos_right hat h)
_ ≤ exp (a * X ω) + exp (b * X ω) := le_add_of_nonneg_right (exp_nonneg _)
/-- If `ω ↦ exp (u * X ω)` is integrable at `u` and `-u`, then it is integrable on `[-u, u]`. -/
lemma integrable_exp_mul_of_abs_le
(hu_int_pos : Integrable (fun ω ↦ exp (u * X ω)) μ)
(hu_int_neg : Integrable (fun ω ↦ exp (-u * X ω)) μ)
(htu : |t| ≤ |u|) :
Integrable (fun ω ↦ exp (t * X ω)) μ := by
refine integrable_exp_mul_of_le_of_le (a := -|u|) (b := |u|) ?_ ?_ ?_ ?_
· rcases le_total 0 u with hu | hu
· rwa [abs_of_nonneg hu]
· simpa [abs_of_nonpos hu]
· rcases le_total 0 u with hu | hu
· rwa [abs_of_nonneg hu]
· rwa [abs_of_nonpos hu]
· rw [neg_le]
exact (neg_le_abs t).trans htu
· exact (le_abs_self t).trans htu
/-- If `ω ↦ exp (u * X ω)` is integrable at `u ≥ 0`, then it is integrable on `[0, u]`. -/
lemma integrable_exp_mul_of_nonneg_of_le [IsFiniteMeasure μ]
(hu : Integrable (fun ω ↦ exp (u * X ω)) μ) (h_nonneg : 0 ≤ t) (htu : t ≤ u) :
Integrable (fun ω ↦ exp (t * X ω)) μ :=
integrable_exp_mul_of_le_of_le (by simp) hu h_nonneg htu
/-- If `ω ↦ exp (u * X ω)` is integrable at `u ≤ 0`, then it is integrable on `[u, 0]`. -/
lemma integrable_exp_mul_of_nonpos_of_ge [IsFiniteMeasure μ]
(hu : Integrable (fun ω ↦ exp (u * X ω)) μ) (h_nonpos : t ≤ 0) (htu : u ≤ t) :
Integrable (fun ω ↦ exp (t * X ω)) μ :=
integrable_exp_mul_of_le_of_le hu (by simp) htu h_nonpos
end Interval
section IntegrableExpSet
/-- The interval of reals `t` for which `exp (t * X)` is integrable. -/
def integrableExpSet (X : Ω → ℝ) (μ : Measure Ω) : Set ℝ :=
{t | Integrable (fun ω ↦ exp (t * X ω)) μ}
lemma integrable_of_mem_integrableExpSet (h : t ∈ integrableExpSet X μ) :
Integrable (fun ω ↦ exp (t * X ω)) μ := h
/-- `integrableExpSet X μ` is a convex subset of `ℝ` (it is an interval). -/
lemma convex_integrableExpSet : Convex ℝ (integrableExpSet X μ) := by
rintro t₁ ht₁ t₂ ht₂ a b ha hb hab
wlog h_le : t₁ ≤ t₂
· rw [add_comm] at hab ⊢
exact this ht₂ ht₁ hb ha hab (not_le.mp h_le).le
refine integrable_exp_mul_of_le_of_le ht₁ ht₂ ?_ ?_
· simp only [smul_eq_mul]
calc t₁
_ = a * t₁ + b * t₁ := by rw [← add_mul, hab, one_mul]
_ ≤ a * t₁ + b * t₂ := by gcongr
· simp only [smul_eq_mul]
calc a * t₁ + b * t₂
_ ≤ a * t₂ + b * t₂ := by gcongr
_ = t₂ := by rw [← add_mul, hab, one_mul]
end IntegrableExpSet
section FiniteMoments
lemma aemeasurable_of_integrable_exp_mul (huv : u ≠ v)
(hu_int : Integrable (fun ω ↦ exp (u * X ω)) μ)
(hv_int : Integrable (fun ω ↦ exp (v * X ω)) μ) :
AEMeasurable X μ := by
by_cases hu : u = 0
· have hv : v ≠ 0 := ne_of_ne_of_eq huv.symm hu
exact aemeasurable_of_aemeasurable_exp_mul hv hv_int.aemeasurable
· exact aemeasurable_of_aemeasurable_exp_mul hu hu_int.aemeasurable
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then
`ω ↦ exp (t * |X| + v * X)` is integrable. -/
lemma integrable_exp_mul_abs_add (ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) :
Integrable (fun ω ↦ exp (t * |X ω| + v * X ω)) μ := by
have h_int_add : Integrable (fun a ↦ exp ((v + t) * X a) + exp ((v - t) * X a)) μ :=
ht_int_pos.add <| by simpa using ht_int_neg
refine Integrable.mono h_int_add ?_ (ae_of_all _ fun ω ↦ ?_)
· by_cases ht : t = 0
· simp only [ht, zero_mul, zero_add, add_zero] at ht_int_pos ⊢
exact ht_int_pos.1
have hX : AEMeasurable X μ := aemeasurable_of_integrable_exp_mul ?_ ht_int_pos ht_int_neg
· fun_prop
· rw [← sub_ne_zero]
simp [ht]
· simp only [norm_eq_abs, abs_exp]
conv_rhs => rw [abs_of_nonneg (by positivity)]
-- ⊢ exp (t * |X ω| + v * X ω) ≤ exp ((v + t) * X ω) + exp ((v - t) * X ω)
rcases le_total 0 (X ω) with h_nonneg | h_nonpos
· rw [abs_of_nonneg h_nonneg, ← add_mul, add_comm, le_add_iff_nonneg_right]
positivity
· rw [abs_of_nonpos h_nonpos, mul_neg, mul_comm, ← mul_neg, mul_comm, ← add_mul, add_comm,
← sub_eq_add_neg, le_add_iff_nonneg_left]
positivity
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t`, then `ω ↦ exp (t * |X ω|)` is
integrable. -/
lemma integrable_exp_mul_abs (ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) :
Integrable (fun ω ↦ exp (t * |X ω|)) μ := by
have h := integrable_exp_mul_abs_add (t := t) (μ := μ) (X := X) (v := 0) ?_ ?_
· simpa using h
· simpa using ht_int_pos
· simpa using ht_int_neg
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then
`ω ↦ exp (|t| * |X| + v * X)` is integrable. -/
lemma integrable_exp_abs_mul_abs_add (ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) :
Integrable (fun ω ↦ exp (|t| * |X ω| + v * X ω)) μ := by
rcases le_total 0 t with ht_nonneg | ht_nonpos
· simp_rw [abs_of_nonneg ht_nonneg]
exact integrable_exp_mul_abs_add ht_int_pos ht_int_neg
· simp_rw [abs_of_nonpos ht_nonpos]
exact integrable_exp_mul_abs_add ht_int_neg (by simpa using ht_int_pos)
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t`, then `ω ↦ exp (|t| * |X ω|)` is
integrable. -/
lemma integrable_exp_abs_mul_abs (ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) :
Integrable (fun ω ↦ exp (|t| * |X ω|)) μ := by
rcases le_total 0 t with ht_nonneg | ht_nonpos
· simp_rw [abs_of_nonneg ht_nonneg]
exact integrable_exp_mul_abs ht_int_pos ht_int_neg
· simp_rw [abs_of_nonpos ht_nonpos]
exact integrable_exp_mul_abs ht_int_neg (by simpa using ht_int_pos)
/-- Auxiliary lemma for `rpow_abs_le_mul_max_exp`. -/
lemma rpow_abs_le_mul_max_exp_of_pos (x : ℝ) {t p : ℝ} (hp : 0 ≤ p) (ht : 0 < t) :
|x| ^ p ≤ (p / t) ^ p * max (exp (t * x)) (exp (- t * x)) := by
by_cases hp_zero : p = 0
· simp only [hp_zero, rpow_zero, zero_div, neg_mul, one_mul, le_sup_iff, one_le_exp_iff,
Left.nonneg_neg_iff]
exact le_total 0 (t * x)
have h_x_le c (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := le_inv_mul_exp x hc
have h_neg_x_le c (hc : 0 < c) : -x ≤ c⁻¹ * exp (- c * x) := by simpa using le_inv_mul_exp (-x) hc
have h_abs_le c (hc : 0 < c) : |x| ≤ c⁻¹ * max (exp (c * x)) (exp (- c * x)) := by
refine abs_le.mpr ⟨?_, ?_⟩
· rw [neg_le]
refine (h_neg_x_le c hc).trans ?_
gcongr
exact le_max_right _ _
· refine (h_x_le c hc).trans ?_
gcongr
exact le_max_left _ _
calc |x| ^ p
_ ≤ ((t / p)⁻¹ * max (exp (t / p * x)) (exp (- t / p * x))) ^ p := by
refine rpow_le_rpow (abs_nonneg _) ?_ hp
convert h_abs_le (t / p) (div_pos ht (hp.lt_of_ne' hp_zero)) using 5
rw [neg_div]
_ = (p / t) ^ p * max (exp (t * x)) (exp (- t * x)) := by
rw [mul_rpow (by positivity) (by positivity)]
congr
· simp
· rw [rpow_max (by positivity) (by positivity) hp, ← exp_mul, ← exp_mul]
ring_nf
congr <;> rw [mul_assoc, mul_inv_cancel₀ hp_zero, mul_one]
lemma rpow_abs_le_mul_max_exp (x : ℝ) {t p : ℝ} (hp : 0 ≤ p) (ht : t ≠ 0) :
|x| ^ p ≤ (p / |t|) ^ p * max (exp (t * x)) (exp (- t * x)) := by
rcases lt_or_gt_of_ne ht with ht_neg | ht_pos
· rw [abs_of_nonpos ht_neg.le, sup_comm]
convert rpow_abs_le_mul_max_exp_of_pos x hp (t := -t) (by simp [ht_neg])
simp
· rw [abs_of_nonneg ht_pos.le]
exact rpow_abs_le_mul_max_exp_of_pos x hp ht_pos
lemma rpow_abs_le_mul_exp_abs (x : ℝ) {t p : ℝ} (hp : 0 ≤ p) (ht : t ≠ 0) :
|x| ^ p ≤ (p / |t|) ^ p * exp (|t| * |x|) := by
refine (rpow_abs_le_mul_max_exp_of_pos x hp (t := |t|) ?_).trans_eq ?_
· simp [ht]
· congr
rcases le_total 0 x with hx | hx
· rw [abs_of_nonneg hx]
simp only [neg_mul, sup_eq_left, exp_le_exp, neg_le_self_iff]
positivity
· rw [abs_of_nonpos hx]
simp only [neg_mul, mul_neg, sup_eq_right, exp_le_exp, le_neg_self_iff]
exact mul_nonpos_of_nonneg_of_nonpos (abs_nonneg _) hx
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable
then for nonnegative `p : ℝ` and any `x ∈ [0, |t|)`,
`|X| ^ p * exp (v * X + x * |X|)` is integrable. -/
lemma integrable_rpow_abs_mul_exp_add_of_integrable_exp_mul {x : ℝ}
(h_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(h_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (h_nonneg : 0 ≤ x) (hx : x < |t|)
{p : ℝ} (hp : 0 ≤ p) :
Integrable (fun a ↦ |X a| ^ p * exp (v * X a + x * |X a|)) μ := by
have ht : t ≠ 0 := by
suffices |t| ≠ 0 by simpa
exact (h_nonneg.trans_lt hx).ne'
have hX : AEMeasurable X μ := aemeasurable_of_integrable_exp_mul ?_ h_int_pos h_int_neg
swap; · rw [← sub_ne_zero]; simp [ht]
rw [← integrable_norm_iff]
swap; · fun_prop
simp only [norm_mul, norm_eq_abs, abs_exp]
have h_le a : |X a| ^ p * exp (v * X a + x * |X a|)
≤ (p / (|t| - x)) ^ p * exp (v * X a + |t| * |X a|) := by
simp_rw [exp_add, mul_comm (exp (v * X a)), ← mul_assoc]
gcongr ?_ * _
have : |t| = |t| - x + x := by simp
nth_rw 2 [this]
rw [add_mul, exp_add, ← mul_assoc]
gcongr ?_ * _
convert rpow_abs_le_mul_exp_abs (X a) hp (t := |t| - x) _ using 4
· nth_rw 2 [abs_of_nonneg]
simp [hx.le]
· nth_rw 2 [abs_of_nonneg]
simp [hx.le]
· rw [sub_ne_zero]
exact hx.ne'
refine Integrable.mono (g := fun a ↦ (p / (|t| - x)) ^ p * exp (v * X a + |t| * |X a|))
?_ ?_ <| ae_of_all _ fun ω ↦ ?_
· refine Integrable.const_mul ?_ _
simp_rw [add_comm (v * X _)]
exact integrable_exp_abs_mul_abs_add h_int_pos h_int_neg
· fun_prop
· simp only [norm_mul, norm_eq_abs, abs_exp]
simp_rw [abs_rpow_of_nonneg (abs_nonneg _), abs_abs]
refine (h_le ω).trans_eq ?_
congr
symm
simp only [abs_eq_self]
exact rpow_nonneg (div_nonneg hp (sub_nonneg_of_le hx.le)) _
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable
then for any `n : ℕ` and any `x ∈ [0, |t|)`,
`|X| ^ n * exp (v * X + x * |X|)` is integrable. -/
lemma integrable_pow_abs_mul_exp_add_of_integrable_exp_mul {x : ℝ}
(h_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(h_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (h_nonneg : 0 ≤ x) (hx : x < |t|)
(n : ℕ) :
Integrable (fun a ↦ |X a| ^ n * exp (v * X a + x * |X a|)) μ := by
convert integrable_rpow_abs_mul_exp_add_of_integrable_exp_mul h_int_pos h_int_neg h_nonneg hx
n.cast_nonneg
simp
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable
then for nonnegative `p : ℝ`, `|X| ^ p * exp (v * X)` is integrable. -/
lemma integrable_rpow_abs_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p * exp (v * X ω)) μ := by
convert integrable_rpow_abs_mul_exp_add_of_integrable_exp_mul ht_int_pos ht_int_neg le_rfl _ hp
using 4
· simp
· simp [ht]
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then for all `n : ℕ`,
`|X| ^ n * exp (v * X)` is integrable. -/
lemma integrable_pow_abs_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_abs_mul_exp_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then for all nonnegative `p : ℝ`,
`X ^ p * exp (v * X)` is integrable. -/
lemma integrable_rpow_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p * exp (v * X ω)) μ := by
have hX : AEMeasurable X μ := aemeasurable_of_integrable_exp_mul ?_ ht_int_pos ht_int_neg
swap; · rw [← sub_ne_zero]; simp [ht]
rw [← integrable_norm_iff]
· simp_rw [norm_eq_abs, abs_mul, abs_exp]
have h := integrable_rpow_abs_mul_exp_of_integrable_exp_mul ht ht_int_pos ht_int_neg hp
refine h.mono' ?_ ?_
· fun_prop
· refine ae_of_all _ fun ω ↦ ?_
simp only [norm_mul, norm_eq_abs, abs_abs, abs_exp]
gcongr
exact abs_rpow_le_abs_rpow _ _
· fun_prop
/-- If `exp ((v + t) * X)` and `exp ((v - t) * X)` are integrable, then for all `n : ℕ`,
`X ^ n * exp (v * X)` is integrable. -/
lemma integrable_pow_mul_exp_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp ((v + t) * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp ((v - t) * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_mul_exp_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ |X ω| ^ p` is
integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_abs_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p) μ := by
have h := integrable_rpow_abs_mul_exp_of_integrable_exp_mul (μ := μ) (X := X) ht (v := 0) ?_ ?_ hp
· simpa using h
· simpa using ht_int_pos
· simpa using ht_int_neg
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ |X ω| ^ n` is
integrable for all `n : ℕ`. That is, all moments of `X` are finite. -/
lemma integrable_pow_abs_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n) μ := by
convert integrable_rpow_abs_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ X ω ^ p` is
integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p) μ := by
have h := integrable_rpow_mul_exp_of_integrable_exp_mul (μ := μ) (X := X) ht (v := 0) ?_ ?_ hp
· simpa using h
· simpa using ht_int_pos
· simpa using ht_int_neg
/-- If `ω ↦ exp (t * X ω)` is integrable at `t` and `-t` for `t ≠ 0`, then `ω ↦ X ω ^ n` is
integrable for all `n : ℕ`. -/
lemma integrable_pow_of_integrable_exp_mul (ht : t ≠ 0)
(ht_int_pos : Integrable (fun ω ↦ exp (t * X ω)) μ)
(ht_int_neg : Integrable (fun ω ↦ exp (-t * X ω)) μ) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n) μ := by
convert integrable_rpow_of_integrable_exp_mul ht ht_int_pos ht_int_neg
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
section IntegrableExpSet
lemma add_half_inf_sub_mem_Ioo {l u v : ℝ} (hv : v ∈ Set.Ioo l u) :
v + ((v - l) ⊓ (u - v)) / 2 ∈ Set.Ioo l u := by
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hv.1, hv.2]
constructor
· calc l < v := hv.1
_ ≤ v + ((v - l) ⊓ (u - v)) / 2 := le_add_of_nonneg_right (by positivity)
· calc v + ((v - l) ⊓ (u - v)) / 2
_ < v + ((v - l) ⊓ (u - v)) := by gcongr; exact half_lt_self (by positivity)
_ ≤ v + (u - v) := by gcongr; exact inf_le_right
_ = u := by abel
lemma sub_half_inf_sub_mem_Ioo {l u v : ℝ} (hv : v ∈ Set.Ioo l u) :
v - ((v - l) ⊓ (u - v)) / 2 ∈ Set.Ioo l u := by
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hv.1, hv.2]
constructor
· calc l = v - (v - l) := by abel
_ ≤ v - ((v - l) ⊓ (u - v)) := by gcongr; exact inf_le_left
_ < v - ((v - l) ⊓ (u - v)) / 2 := by gcongr; exact half_lt_self (by positivity)
· calc v - ((v - l) ⊓ (u - v)) / 2
_ ≤ v := by
rw [sub_le_iff_le_add]
exact le_add_of_nonneg_right (by positivity)
_ < u := hv.2
/-- If the interior of the interval `integrableExpSet X μ` is nonempty,
then `X` is a.e. measurable. -/
lemma aemeasurable_of_mem_interior_integrableExpSet (hv : v ∈ interior (integrableExpSet X μ)) :
AEMeasurable X μ := by
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hv
obtain ⟨l, u, hvlu, h_subset⟩ := hv
let t := ((v - l) ⊓ (u - v)) / 2
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hvlu.1, hvlu.2]
have ht : 0 < t := half_pos h_pos
by_cases hvt : v + t = 0
· have hvt' : v - t ≠ 0 := by
rw [sub_ne_zero]
refine fun h_eq ↦ ht.ne' ?_
simpa [h_eq] using hvt
exact aemeasurable_of_aemeasurable_exp_mul hvt'
(h_subset (sub_half_inf_sub_mem_Ioo hvlu)).aemeasurable
· exact aemeasurable_of_aemeasurable_exp_mul hvt
(h_subset (add_half_inf_sub_mem_Ioo hvlu)).aemeasurable
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ p * exp (v * X)` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p * exp (v * X ω)) μ := by
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hv
obtain ⟨l, u, hvlu, h_subset⟩ := hv
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hvlu.1, hvlu.2]
refine integrable_rpow_abs_mul_exp_of_integrable_exp_mul
(t := min (v - l) (u - v) / 2) ?_ ?_ ?_ hp
· positivity
· exact h_subset (add_half_inf_sub_mem_Ioo hvlu)
· exact h_subset (sub_half_inf_sub_mem_Ioo hvlu)
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ n * exp (v * X)` is integrable for all `n : ℕ`. -/
lemma integrable_pow_abs_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet hv
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ p * exp (v * X)` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p * exp (v * X ω)) μ := by
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hv
obtain ⟨l, u, hvlu, h_subset⟩ := hv
have h_pos : 0 < (v - l) ⊓ (u - v) := by simp [hvlu.1, hvlu.2]
refine integrable_rpow_mul_exp_of_integrable_exp_mul
(t := min (v - l) (u - v) / 2) ?_ ?_ ?_ hp
· positivity
· exact h_subset (add_half_inf_sub_mem_Ioo hvlu)
· exact h_subset (sub_half_inf_sub_mem_Ioo hvlu)
/-- If `v` belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ n * exp (v * X)` is integrable for all `n : ℕ`. -/
lemma integrable_pow_mul_exp_of_mem_interior_integrableExpSet
(hv : v ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n * exp (v * X ω)) μ := by
convert integrable_rpow_mul_exp_of_mem_interior_integrableExpSet hv
(by positivity : 0 ≤ (n : ℝ)) with ω
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ n` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_abs_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ |X ω| ^ p) μ := by
convert integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet h hp using 1
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `|X| ^ n` is integrable for all `n : ℕ`. -/
lemma integrable_pow_abs_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n) μ := by
convert integrable_pow_abs_mul_exp_of_mem_interior_integrableExpSet h n
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ n` is integrable for all nonnegative `p : ℝ`. -/
lemma integrable_rpow_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ X ω ^ p) μ := by
convert integrable_rpow_mul_exp_of_mem_interior_integrableExpSet h hp using 1
simp
/-- If 0 belongs to the interior of the interval `integrableExpSet X μ`,
then `X ^ n` is integrable for all `n : ℕ`. -/
lemma integrable_pow_of_mem_interior_integrableExpSet
(h : 0 ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n) μ := by
convert integrable_pow_mul_exp_of_mem_interior_integrableExpSet h n
simp
/-- If 0 belongs to the interior of `integrableExpSet X μ`, then `X` is in `ℒp` for all
finite `p`. -/
lemma memLp_of_mem_interior_integrableExpSet (h : 0 ∈ interior (integrableExpSet X μ)) (p : ℝ≥0) :
MemLp X p μ := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet h
by_cases hp_zero : p = 0
· simp only [hp_zero, ENNReal.coe_zero, memLp_zero_iff_aestronglyMeasurable]
exact hX.aestronglyMeasurable
rw [← integrable_norm_rpow_iff hX.aestronglyMeasurable (mod_cast hp_zero) (by simp)]
simp only [norm_eq_abs, ENNReal.coe_toReal]
exact integrable_rpow_abs_of_mem_interior_integrableExpSet h p.2
@[deprecated (since := "2025-02-21")]
alias memℒp_of_mem_interior_integrableExpSet := memLp_of_mem_interior_integrableExpSet
section Complex
open Complex
variable {z : ℂ}
lemma integrable_cexp_mul_of_re_mem_integrableExpSet (hX : AEMeasurable X μ)
(hz : z.re ∈ integrableExpSet X μ) :
Integrable (fun ω ↦ cexp (z * X ω)) μ := by
rw [← integrable_norm_iff]
· simpa [Complex.norm_exp] using hz
· fun_prop
lemma integrable_cexp_mul_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) :
Integrable (fun ω ↦ cexp (z * X ω)) μ :=
integrable_cexp_mul_of_re_mem_integrableExpSet
(aemeasurable_of_mem_interior_integrableExpSet hz) (interior_subset hz)
lemma integrable_rpow_abs_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ (|X ω| ^ p : ℝ) * cexp (z * X ω)) μ := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet hz
rw [← integrable_norm_iff]
swap; · fun_prop
simpa [abs_rpow_of_nonneg (abs_nonneg _), Complex.norm_exp]
using integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet hz hp
lemma integrable_pow_abs_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ |X ω| ^ n * cexp (z * X ω)) μ := by
convert integrable_rpow_abs_mul_cexp_of_re_mem_interior_integrableExpSet hz (Nat.cast_nonneg n)
simp
lemma integrable_rpow_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) {p : ℝ} (hp : 0 ≤ p) :
Integrable (fun ω ↦ (X ω ^ p : ℝ) * cexp (z * X ω)) μ := by
have hX : AEMeasurable X μ := aemeasurable_of_mem_interior_integrableExpSet hz
rw [← integrable_norm_iff]
swap; · fun_prop
simp only [norm_mul, norm_real, Complex.norm_exp, mul_re, ofReal_re,
ofReal_im, mul_zero, sub_zero]
refine (integrable_rpow_abs_mul_exp_of_mem_interior_integrableExpSet hz hp).mono ?_ ?_
· fun_prop
refine ae_of_all _ fun ω ↦ ?_
simp only [norm_mul, Real.norm_eq_abs, Real.abs_exp]
gcongr
exact abs_rpow_le_abs_rpow _ _
lemma integrable_pow_mul_cexp_of_re_mem_interior_integrableExpSet
(hz : z.re ∈ interior (integrableExpSet X μ)) (n : ℕ) :
Integrable (fun ω ↦ X ω ^ n * cexp (z * X ω)) μ := by
convert integrable_rpow_mul_cexp_of_re_mem_interior_integrableExpSet hz (Nat.cast_nonneg n)
simp
end Complex
end IntegrableExpSet
end FiniteMoments
end ProbabilityTheory
|
MulAntidiagonal.lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Floris van Doorn
-/
import Mathlib.Order.WellFoundedSet
/-! # Multiplication antidiagonal -/
namespace Set
variable {α : Type*}
section Mul
variable [Mul α] {s s₁ s₂ t t₁ t₂ : Set α} {a : α} {x : α × α}
/-- `Set.mulAntidiagonal s t a` is the set of all pairs of an element in `s` and an element in `t`
that multiply to `a`. -/
@[to_additive
/-- `Set.addAntidiagonal s t a` is the set of all pairs of an element in `s` and an
element in `t` that add to `a`. -/]
def mulAntidiagonal (s t : Set α) (a : α) : Set (α × α) :=
{ x | x.1 ∈ s ∧ x.2 ∈ t ∧ x.1 * x.2 = a }
@[to_additive (attr := simp)]
theorem mem_mulAntidiagonal : x ∈ mulAntidiagonal s t a ↔ x.1 ∈ s ∧ x.2 ∈ t ∧ x.1 * x.2 = a :=
Iff.rfl
@[to_additive]
theorem mulAntidiagonal_mono_left (h : s₁ ⊆ s₂) : mulAntidiagonal s₁ t a ⊆ mulAntidiagonal s₂ t a :=
fun _ hx => ⟨h hx.1, hx.2.1, hx.2.2⟩
@[to_additive]
theorem mulAntidiagonal_mono_right (h : t₁ ⊆ t₂) :
mulAntidiagonal s t₁ a ⊆ mulAntidiagonal s t₂ a := fun _ hx => ⟨hx.1, h hx.2.1, hx.2.2⟩
end Mul
-- The left hand side is not in simp normal form, see variant below.
@[to_additive]
theorem swap_mem_mulAntidiagonal [CommMagma α] {s t : Set α} {a : α} {x : α × α} :
x.swap ∈ Set.mulAntidiagonal s t a ↔ x ∈ Set.mulAntidiagonal t s a := by
simp [mul_comm, and_left_comm]
@[to_additive (attr := simp)]
theorem swap_mem_mulAntidiagonal_aux [CommMagma α] {s t : Set α} {a : α} {x : α × α} :
x.snd ∈ s ∧ x.fst ∈ t ∧ x.snd * x.fst = a
↔ x ∈ Set.mulAntidiagonal t s a := by
simp [mul_comm, and_left_comm]
namespace MulAntidiagonal
section CancelCommMonoid
variable [CommMonoid α] [IsCancelMul α] {s t : Set α} {a : α} {x y : mulAntidiagonal s t a}
-- We have to translate the names manually because the namespace name `MulAntidiagonal`
-- does not match the declaration `mulAntidiagonal` that has the `to_additive` attribute.
@[to_additive Set.AddAntidiagonal.fst_eq_fst_iff_snd_eq_snd]
theorem fst_eq_fst_iff_snd_eq_snd : (x : α × α).1 = (y : α × α).1 ↔ (x : α × α).2 = (y : α × α).2 :=
⟨fun h =>
mul_left_cancel
(y.2.2.2.trans <| by
rw [← h]
exact x.2.2.2.symm).symm,
fun h =>
mul_right_cancel
(y.2.2.2.trans <| by
rw [← h]
exact x.2.2.2.symm).symm⟩
@[to_additive Set.AddAntidiagonal.eq_of_fst_eq_fst]
theorem eq_of_fst_eq_fst (h : (x : α × α).fst = (y : α × α).fst) : x = y :=
Subtype.ext <| Prod.ext h <| fst_eq_fst_iff_snd_eq_snd.1 h
@[to_additive Set.AddAntidiagonal.eq_of_snd_eq_snd]
theorem eq_of_snd_eq_snd (h : (x : α × α).snd = (y : α × α).snd) : x = y :=
Subtype.ext <| Prod.ext (fst_eq_fst_iff_snd_eq_snd.2 h) h
end CancelCommMonoid
section OrderedCancelCommMonoid
variable [CommMonoid α] [PartialOrder α] [IsCancelMul α] [MulLeftMono α] [MulRightStrictMono α]
(s t : Set α) (a : α) {x y : mulAntidiagonal s t a}
@[to_additive Set.AddAntidiagonal.eq_of_fst_le_fst_of_snd_le_snd]
theorem eq_of_fst_le_fst_of_snd_le_snd (h₁ : (x : α × α).1 ≤ (y : α × α).1)
(h₂ : (x : α × α).2 ≤ (y : α × α).2) : x = y :=
eq_of_fst_eq_fst <|
h₁.eq_of_not_lt fun hlt =>
(mul_lt_mul_of_lt_of_le hlt h₂).ne <|
(mem_mulAntidiagonal.1 x.2).2.2.trans (mem_mulAntidiagonal.1 y.2).2.2.symm
variable {s t}
@[to_additive Set.AddAntidiagonal.finite_of_isPWO]
theorem finite_of_isPWO (hs : s.IsPWO) (ht : t.IsPWO) (a) : (mulAntidiagonal s t a).Finite := by
refine not_infinite.1 fun h => ?_
have h1 : (mulAntidiagonal s t a).PartiallyWellOrderedOn (Prod.fst ⁻¹'o (· ≤ ·)) :=
fun f ↦ hs fun n ↦ ⟨_, (mem_mulAntidiagonal.1 (f n).2).1⟩
have h2 : (mulAntidiagonal s t a).PartiallyWellOrderedOn (Prod.snd ⁻¹'o (· ≤ ·)) :=
fun f ↦ ht fun n ↦ ⟨_, (mem_mulAntidiagonal.1 (f n).2).2.1⟩
obtain ⟨g, hg⟩ :=
h1.exists_monotone_subseq fun n ↦ (h.natEmbedding _ n).2
obtain ⟨m, n, mn, h2'⟩ := h2 fun n ↦ h.natEmbedding _ _
refine mn.ne (g.injective <| (h.natEmbedding _).injective ?_)
exact eq_of_fst_le_fst_of_snd_le_snd _ _ _ (hg _ _ mn.le) h2'
end OrderedCancelCommMonoid
variable [CancelCommMonoid α] [LinearOrder α] [MulLeftMono α] [MulRightStrictMono α]
@[to_additive Set.AddAntidiagonal.finite_of_isWF]
theorem finite_of_isWF {s t : Set α} (hs : s.IsWF) (ht : t.IsWF)
(a) : (mulAntidiagonal s t a).Finite :=
finite_of_isPWO hs.isPWO ht.isPWO a
end MulAntidiagonal
end Set
|
BigOperators.lean
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise
import Mathlib.Algebra.Group.Pointwise.Set.Basic
import Mathlib.Data.Fintype.Card
/-!
# Results about pointwise operations on sets and big operators.
-/
namespace Set
open Pointwise Function
variable {ι α β F : Type*} [FunLike F α β]
section Monoid
variable [Monoid α] [Monoid β] [MonoidHomClass F α β]
@[to_additive]
theorem image_list_prod (f : F) :
∀ l : List (Set α), (f : α → β) '' l.prod = (l.map fun s => f '' s).prod
| [] => image_one.trans <| congr_arg singleton (map_one f)
| a :: as => by rw [List.map_cons, List.prod_cons, List.prod_cons, image_mul, image_list_prod _ _]
end Monoid
section CommMonoid
variable [CommMonoid α] [CommMonoid β] [MonoidHomClass F α β]
@[to_additive]
theorem image_multiset_prod (f : F) :
∀ m : Multiset (Set α), (f : α → β) '' m.prod = (m.map fun s => f '' s).prod :=
Quotient.ind <| by
simpa only [Multiset.quot_mk_to_coe, Multiset.prod_coe, Multiset.map_coe] using
image_list_prod f
@[to_additive]
theorem image_finset_prod (f : F) (m : Finset ι) (s : ι → Set α) :
((f : α → β) '' ∏ i ∈ m, s i) = ∏ i ∈ m, f '' s i :=
(image_multiset_prod f _).trans <| congr_arg Multiset.prod <| Multiset.map_map _ _ _
/-- The n-ary version of `Set.mem_mul`. -/
@[to_additive /-- The n-ary version of `Set.mem_add`. -/]
theorem mem_finset_prod (t : Finset ι) (f : ι → Set α) (a : α) :
(a ∈ ∏ i ∈ t, f i) ↔ ∃ (g : ι → α) (_ : ∀ {i}, i ∈ t → g i ∈ f i), ∏ i ∈ t, g i = a := by
classical
induction' t using Finset.induction_on with i is hi ih generalizing a
· simp_rw [Finset.prod_empty, Set.mem_one]
exact ⟨fun h ↦ ⟨fun _ ↦ a, fun hi ↦ False.elim (Finset.notMem_empty _ hi), h.symm⟩,
fun ⟨_, _, hf⟩ ↦ hf.symm⟩
rw [Finset.prod_insert hi, Set.mem_mul]
simp_rw [Finset.prod_insert hi]
simp_rw [ih]
constructor
· rintro ⟨x, y, hx, ⟨g, hg, rfl⟩, rfl⟩
refine ⟨Function.update g i x, ?_, ?_⟩
· intro j hj
obtain rfl | hj := Finset.mem_insert.mp hj
· rwa [Function.update_self]
· rw [update_of_ne (ne_of_mem_of_not_mem hj hi)]
exact hg hj
· rw [Finset.prod_update_of_notMem hi, Function.update_self]
· rintro ⟨g, hg, rfl⟩
exact ⟨g i, hg (is.mem_insert_self _), is.prod g,
⟨⟨g, fun hi ↦ hg (Finset.mem_insert_of_mem hi), rfl⟩, rfl⟩⟩
@[to_additive]
lemma mem_pow_iff_prod {n : ℕ} {s : Set α} {a : α} :
a ∈ s ^ n ↔ ∃ f : Fin n → α, (∀ i, f i ∈ s) ∧ ∏ i, f i = a := by
simpa using mem_finset_prod (t := .univ) (f := fun _ : Fin n ↦ s) _
/-- A version of `Set.mem_finset_prod` with a simpler RHS for products over a Fintype. -/
@[to_additive /-- A version of `Set.mem_finset_sum` with a simpler RHS for sums over a Fintype. -/]
theorem mem_fintype_prod [Fintype ι] (f : ι → Set α) (a : α) :
(a ∈ ∏ i, f i) ↔ ∃ (g : ι → α) (_ : ∀ i, g i ∈ f i), ∏ i, g i = a := by
rw [mem_finset_prod]
simp
/-- An n-ary version of `Set.mul_mem_mul`. -/
@[to_additive /-- An n-ary version of `Set.add_mem_add`. -/]
theorem list_prod_mem_list_prod (t : List ι) (f : ι → Set α) (g : ι → α) (hg : ∀ i ∈ t, g i ∈ f i) :
(t.map g).prod ∈ (t.map f).prod := by
induction' t with h tl ih
· simp_rw [List.map_nil, List.prod_nil, Set.mem_one]
· simp_rw [List.map_cons, List.prod_cons]
exact mul_mem_mul (hg h List.mem_cons_self)
(ih fun i hi ↦ hg i <| List.mem_cons_of_mem _ hi)
/-- An n-ary version of `Set.mul_subset_mul`. -/
@[to_additive /-- An n-ary version of `Set.add_subset_add`. -/]
theorem list_prod_subset_list_prod (t : List ι) (f₁ f₂ : ι → Set α) (hf : ∀ i ∈ t, f₁ i ⊆ f₂ i) :
(t.map f₁).prod ⊆ (t.map f₂).prod := by
induction' t with h tl ih
· rfl
· simp_rw [List.map_cons, List.prod_cons]
exact mul_subset_mul (hf h List.mem_cons_self)
(ih fun i hi ↦ hf i <| List.mem_cons_of_mem _ hi)
@[to_additive]
theorem list_prod_singleton {M : Type*} [Monoid M] (s : List M) :
(s.map fun i ↦ ({i} : Set M)).prod = {s.prod} :=
(map_list_prod (singletonMonoidHom : M →* Set M) _).symm
/-- An n-ary version of `Set.mul_mem_mul`. -/
@[to_additive /-- An n-ary version of `Set.add_mem_add`. -/]
theorem multiset_prod_mem_multiset_prod (t : Multiset ι) (f : ι → Set α) (g : ι → α)
(hg : ∀ i ∈ t, g i ∈ f i) : (t.map g).prod ∈ (t.map f).prod := by
induction t using Quotient.inductionOn
simp_rw [Multiset.quot_mk_to_coe, Multiset.map_coe, Multiset.prod_coe]
exact list_prod_mem_list_prod _ _ _ hg
/-- An n-ary version of `Set.mul_subset_mul`. -/
@[to_additive /-- An n-ary version of `Set.add_subset_add`. -/]
theorem multiset_prod_subset_multiset_prod (t : Multiset ι) (f₁ f₂ : ι → Set α)
(hf : ∀ i ∈ t, f₁ i ⊆ f₂ i) : (t.map f₁).prod ⊆ (t.map f₂).prod := by
induction t using Quotient.inductionOn
simp_rw [Multiset.quot_mk_to_coe, Multiset.map_coe, Multiset.prod_coe]
exact list_prod_subset_list_prod _ _ _ hf
@[to_additive]
theorem multiset_prod_singleton {M : Type*} [CommMonoid M] (s : Multiset M) :
(s.map fun i ↦ ({i} : Set M)).prod = {s.prod} :=
(map_multiset_prod (singletonMonoidHom : M →* Set M) _).symm
/-- An n-ary version of `Set.mul_mem_mul`. -/
@[to_additive /-- An n-ary version of `Set.add_mem_add`. -/]
theorem finset_prod_mem_finset_prod (t : Finset ι) (f : ι → Set α) (g : ι → α)
(hg : ∀ i ∈ t, g i ∈ f i) : (∏ i ∈ t, g i) ∈ ∏ i ∈ t, f i :=
multiset_prod_mem_multiset_prod _ _ _ hg
/-- An n-ary version of `Set.mul_subset_mul`. -/
@[to_additive /-- An n-ary version of `Set.add_subset_add`. -/]
theorem finset_prod_subset_finset_prod (t : Finset ι) (f₁ f₂ : ι → Set α)
(hf : ∀ i ∈ t, f₁ i ⊆ f₂ i) : ∏ i ∈ t, f₁ i ⊆ ∏ i ∈ t, f₂ i :=
multiset_prod_subset_multiset_prod _ _ _ hf
@[to_additive]
theorem finset_prod_singleton {M ι : Type*} [CommMonoid M] (s : Finset ι) (I : ι → M) :
∏ i ∈ s, ({I i} : Set M) = {∏ i ∈ s, I i} :=
(map_prod (singletonMonoidHom : M →* Set M) _ _).symm
/-- The n-ary version of `Set.image_mul_prod`. -/
@[to_additive /-- The n-ary version of `Set.add_image_prod`. -/]
theorem image_finset_prod_pi (l : Finset ι) (S : ι → Set α) :
(fun f : ι → α => ∏ i ∈ l, f i) '' (l : Set ι).pi S = ∏ i ∈ l, S i := by
ext
simp_rw [mem_finset_prod, mem_image, mem_pi, exists_prop, Finset.mem_coe]
/-- A special case of `Set.image_finset_prod_pi` for `Finset.univ`. -/
@[to_additive /-- A special case of `Set.image_finset_sum_pi` for `Finset.univ`. -/]
theorem image_fintype_prod_pi [Fintype ι] (S : ι → Set α) :
(fun f : ι → α => ∏ i, f i) '' univ.pi S = ∏ i, S i := by
simpa only [Finset.coe_univ] using image_finset_prod_pi Finset.univ S
end CommMonoid
/-! TODO: define `decidable_mem_finset_prod` and `decidable_mem_finset_sum`. -/
end Set
|
bigop.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 fintype tuple finfun.
(******************************************************************************)
(* Finitely iterated operators *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file provides a generic definition for iterating an operator over a *)
(* set of indices (bigop); this big operator is parameterized by the return *)
(* type (R), the type of indices (I), the operator (op), the default value on *)
(* empty lists (idx), the range of indices (r), the filter applied on this *)
(* range (P) and the expression we are iterating (F). The definition is not *)
(* to be used directly, but via the wide range of notations provided and *)
(* which support a natural use of big operators. *)
(* To improve performance of the Coq typechecker on large expressions, the *)
(* bigop constant is OPAQUE. It can however be unlocked to reveal the *)
(* transparent constant reducebig, to let Coq expand summation on an explicit *)
(* sequence with an explicit test. *)
(* The lemmas can be classified according to the operator being iterated: *)
(* 1. Results independent of the operator: extensionality with respect to *)
(* the range of indices, to the filtering predicate or to the expression *)
(* being iterated; reindexing, widening or narrowing of the range of *)
(* indices; we provide lemmas for the special cases where indices are *)
(* natural numbers or bounded natural numbers ("ordinals"). We supply *)
(* several "functional" induction principles that can be used with the *)
(* ssreflect 1.3 "elim" tactic to do induction over the index range for *)
(* up to 3 bigops simultaneously. *)
(* 2. Results depending on the properties of the operator: *)
(* We distinguish: *)
(* - semigroup laws (op is associative) *)
(* - commutative semigroup laws (semigroup laws, op is commutative) *)
(* - monoid laws (semigroup laws, idx is an identity element) *)
(* - abelian monoid laws (op is also commutative) *)
(* - laws with a distributive operation (semirings) *)
(* Examples of such results are splitting, permuting, and exchanging *)
(* bigops. *)
(* A special section is dedicated to big operators on natural numbers. *)
(******************************************************************************)
(* Notations: *)
(* The general form for iterated operators is *)
(* <bigop>_<range> <general_term> *)
(* - <bigop> is one of \big[op/idx], \sum, \prod, or \max (see below). *)
(* - <general_term> can be any expression. *)
(* - <range> binds an index variable in <general_term>; <range> is one of *)
(* (i <- s) i ranges over the sequence s. *)
(* (m <= i < n) i ranges over the nat interval m, m+1, ..., n-1. *)
(* (i < n) i ranges over the (finite) type 'I_n (i.e., ordinal n). *)
(* (i : T) i ranges over the finite type T. *)
(* i or (i) i ranges over its (inferred) finite type. *)
(* (i in A) i ranges over the elements that satisfy the collective *)
(* predicate A (the domain of A must be a finite type). *)
(* (i <- s | <condition>) limits the range to the i for which <condition> *)
(* holds. <condition> can be any expression that coerces to *)
(* bool, and may mention the bound index i. All six kinds of *)
(* ranges above can have a <condition> part. *)
(* - One can use the "\big[op/idx]" notations for any operator. *)
(* - BIG_F and BIG_P are pattern abbreviations for the <general_term> and *)
(* <condition> part of a \big ... expression; for (i in A) and (i in A | C) *)
(* ranges the term matched by BIG_P will include the i \in A condition. *)
(* - The (locked) head constant of a \big notation is bigop. *)
(* - The "\sum", "\prod" and "\max" notations in the %N scope are used for *)
(* natural numbers with addition, multiplication and maximum (and their *)
(* corresponding neutral elements), respectively. *)
(* - The "\sum" and "\prod" reserved notations are overloaded in ssralg in *)
(* the %R scope; in mxalgebra, vector & falgebra in the %MS and %VS scopes; *)
(* "\prod" is also overloaded in fingroup, in the %g and %G scopes. *)
(* - We reserve "\bigcup" and "\bigcap" notations for iterated union and *)
(* intersection (of sets, groups, vector spaces, etc.). *)
(******************************************************************************)
(* Tips for using lemmas in this file: *)
(* To apply a lemma for a specific operator: if no special property is *)
(* required for the operator, simply apply the lemma; if the lemma needs *)
(* certain properties for the operator, make sure the appropriate instances *)
(* are declared using, e.g., Check addn : Monoid.law _. to check that addn *)
(* is equipped with the monoid laws. *)
(******************************************************************************)
(* Interfaces for operator properties are packaged in the SemiGroup and *)
(* Monoid submodules: *)
(* SemiGroup.law == interface (keyed on the operator) for associative *)
(* operators *)
(* The HB class is SemiGroup. *)
(* SemiGroup.com_law == interface for associative and commutative operators *)
(* The HB class is SemiGroup.ComLaw. *)
(* Monoid.law idx == interface for associative operators with identity *)
(* element idx *)
(* The HB class is Monoid.Law. *)
(* Monoid.com_law idx == extension of Monoid.law for operators that are also *)
(* commutative *)
(* The HB class is Monoid.ComLaw. *)
(* Monoid.mul_law abz == interface for operators with absorbing (zero) *)
(* element abz *)
(* The HB class is Monoid.MulLaw. *)
(* Monoid.add_law idx mop == extension of Monoid.com_law for operators over *)
(* which operation mop distributes (mop will often also *)
(* have a Monoid.mul_law idx structure) *)
(* The HB class is Monoid.AddLaw. *)
(* SemiGroup.Theory == submodule containing basic generic algebra lemmas *)
(* for operators satisfying the SemiGroup interfaces *)
(* Monoid.Theory == submodule containing basic generic algebra lemmas *)
(* for operators satisfying the Monoid interfaces, *)
(* exports SemiGroup.Theory *)
(* Monoid.simpm == generic monoid simplification rewrite multirule *)
(* oAC op == convert an AC operator op : T -> T -> T *)
(* to a Monoid.com_law on option T *)
(* Monoid structures are predeclared for many basic operators: (_ && _)%B, *)
(* (_ || _)%B, (_ (+) _)%B (exclusive or), (_ + _)%N, (_ * _)%N, maxn, *)
(* gcdn, lcmn and (_ ++ _)%SEQ (list concatenation) *)
(******************************************************************************)
(* Reference: Y. Bertot, G. Gonthier, S. Ould Biha, I. Pasca, Canonical Big *)
(* Operators, TPHOLs 2008, LNCS vol. 5170, Springer, available at: *)
(* http://hal.inria.fr/docs/00/33/11/93/PDF/main.pdf *)
(******************************************************************************)
(* Examples of use in: poly.v, matrix.v *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope big_scope.
Reserved Notation "\big [ op / idx ]_ i F"
(at level 36, F at level 36, op, idx at level 10, i at level 0,
right associativity,
format "'[' \big [ op / idx ]_ i '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i <- r | P ) F"
(F at level 36, i, r at level 60,
format "'[' \big [ op / idx ]_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i <- r ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( m <= i < n | P ) F"
(F at level 36, i, n at level 60,
format "'[' \big [ op / idx ]_ ( m <= i < n | P ) F ']'").
Reserved Notation "\big [ op / idx ]_ ( m <= i < n ) F"
(at level 36, F at level 36,
format "'[' \big [ op / idx ]_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i | P ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i : t | P ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i : t | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i : t ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i : t ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i < n | P ) F"
(F at level 36, n at level 60,
format "'[' \big [ op / idx ]_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i < n ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i < n ) F ']'").
Reserved Notation "\big [ op / idx ]_ ( i 'in' A | P ) F"
(F at level 36, A at level 60,
format "'[' \big [ op / idx ]_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i 'in' A ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\sum_ i F"
(at level 34, F at level 41, i at level 0,
right associativity,
format "'[' \sum_ i '/ ' F ']'").
Reserved Notation "\sum_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \sum_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i <- r ) F"
(F at level 41,
format "'[' \sum_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\sum_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \sum_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( m <= i < n ) F"
(F at level 41,
format "'[' \sum_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\sum_ ( i | P ) F"
(F at level 41,
format "'[' \sum_ ( i | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i : t | P ) F" (F at level 41). (* only parsing *)
Reserved Notation "\sum_ ( i : t ) F" (F at level 41). (* only parsing *)
Reserved Notation "\sum_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \sum_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i < n ) F"
(F at level 41,
format "'[' \sum_ ( i < n ) '/ ' F ']'").
Reserved Notation "\sum_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \sum_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i 'in' A ) F"
(F at level 41,
format "'[' \sum_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max_ i '/ ' F ']'").
Reserved Notation "\max_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i <- r ) F"
(F at level 41,
format "'[' \max_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max_ ( i | P ) F"
(F at level 41,
format "'[' \max_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i : t | P ) F" (F at level 41). (* only parsing *)
Reserved Notation "\max_ ( i : t ) F" (F at level 41). (* only parsing *)
Reserved Notation "\max_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i < n ) F"
(F at level 41, n at level 60,
format "'[' \max_ ( i < n ) F ']'").
Reserved Notation "\max_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\prod_ i F"
(at level 34, F at level 36, i at level 0,
format "'[' \prod_ i '/ ' F ']'").
Reserved Notation "\prod_ ( i <- r | P ) F"
(F at level 36, i, r at level 60,
format "'[' \prod_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( i <- r ) F"
(F at level 36,
format "'[' \prod_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\prod_ ( m <= i < n | P ) F"
(F at level 36, i, n at level 60,
format "'[' \prod_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( m <= i < n ) F"
(F at level 36,
format "'[' \prod_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\prod_ ( i | P ) F"
(F at level 36,
format "'[' \prod_ ( i | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( i : t | P ) F" (F at level 36). (* only parsing *)
Reserved Notation "\prod_ ( i : t ) F" (F at level 36). (* only parsing *)
Reserved Notation "\prod_ ( i < n | P ) F"
(F at level 36, n at level 60,
format "'[' \prod_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( i < n ) F"
(F at level 36,
format "'[' \prod_ ( i < n ) '/ ' F ']'").
Reserved Notation "\prod_ ( i 'in' A | P ) F"
(F at level 36, A at level 60,
format "'[' \prod_ ( i 'in' A | P ) F ']'").
Reserved Notation "\prod_ ( i 'in' A ) F"
(F at level 36,
format "'[' \prod_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\bigcup_ i F"
(at level 41, F at level 41, i at level 0,
format "'[' \bigcup_ i '/ ' F ']'").
Reserved Notation "\bigcup_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \bigcup_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i <- r ) F"
(F at level 41,
format "'[' \bigcup_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \bigcup_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( m <= i < n ) F"
(F at level 41,
format "'[' \bigcup_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i | P ) F"
(F at level 41,
format "'[' \bigcup_ ( i | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i : t | P ) F"
(F at level 41,
format "'[' \bigcup_ ( i : t | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i : t ) F"
(F at level 41,
format "'[' \bigcup_ ( i : t ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \bigcup_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i < n ) F"
(F at level 41,
format "'[' \bigcup_ ( i < n ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \bigcup_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i 'in' A ) F"
(F at level 41,
format "'[' \bigcup_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\bigcap_ i F"
(at level 41, F at level 41, i at level 0,
format "'[' \bigcap_ i '/ ' F ']'").
Reserved Notation "\bigcap_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \bigcap_ ( i <- r | P ) F ']'").
Reserved Notation "\bigcap_ ( i <- r ) F"
(F at level 41,
format "'[' \bigcap_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \bigcap_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( m <= i < n ) F"
(F at level 41,
format "'[' \bigcap_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i | P ) F"
(F at level 41,
format "'[' \bigcap_ ( i | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i : t | P ) F"
(F at level 41,
format "'[' \bigcap_ ( i : t | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i : t ) F"
(F at level 41,
format "'[' \bigcap_ ( i : t ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \bigcap_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i < n ) F"
(F at level 41,
format "'[' \bigcap_ ( i < n ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \bigcap_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i 'in' A ) F"
(F at level 41,
format "'[' \bigcap_ ( i 'in' A ) '/ ' F ']'").
Module SemiGroup.
HB.mixin Record isLaw T (op : T -> T -> T) := {
opA : associative op;
}.
#[export]
HB.structure Definition Law T := {op of isLaw T op}.
Notation law := Law.type.
HB.mixin Record isCommutativeLaw T (op : T -> T -> T) := {
opC : commutative op;
}.
#[export]
HB.structure Definition ComLaw T := {op of Law T op & isCommutativeLaw T op}.
Notation com_law := ComLaw.type.
HB.factory Record isComLaw T (op : T -> T -> T) := {
opA : associative op;
opC : commutative op;
}.
HB.builders Context T op of isComLaw T op.
HB.instance Definition _ := isLaw.Build T op opA.
HB.instance Definition _ := isCommutativeLaw.Build T op opC.
HB.end.
Module Import Exports. HB.reexport. End Exports.
Module Theory.
Section Theory.
Variables (T : Type).
Section Plain.
Variable mul : law T.
Lemma mulmA : associative mul. Proof. exact: opA. Qed.
End Plain.
Section Commutative.
Variable mul : com_law T.
Lemma mulmC : commutative mul. Proof. exact: opC. Qed.
Lemma mulmCA : left_commutative mul.
Proof. by move=> x y z; rewrite !mulmA [_ x _]mulmC. Qed.
Lemma mulmAC : right_commutative mul.
Proof. by move=> x y z; rewrite -!mulmA [_ y _]mulmC. Qed.
Lemma mulmACA : interchange mul mul.
Proof. by move=> x y z t; rewrite -!mulmA [_ y _]mulmCA. Qed.
End Commutative.
End Theory.
End Theory.
Include Theory.
End SemiGroup.
Export SemiGroup.Exports.
Module Monoid.
Export SemiGroup.
HB.mixin Record isMonoidLaw T (idm : T) (op : T -> T -> T) := {
op1m : left_id idm op;
opm1 : right_id idm op;
}.
#[export]
HB.structure Definition Law T idm :=
{op of SemiGroup.Law T op & isMonoidLaw T idm op}.
Notation law := Law.type.
HB.factory Record isLaw T (idm : T) (op : T -> T -> T) := {
opA : associative op;
op1m : left_id idm op;
opm1 : right_id idm op;
}.
HB.builders Context T idm op of isLaw T idm op.
HB.instance Definition _ := SemiGroup.isLaw.Build T op opA.
HB.instance Definition _ := isMonoidLaw.Build T idm op op1m opm1.
HB.end.
#[export]
HB.structure Definition ComLaw T idm :=
{op of Law T idm op & isCommutativeLaw T op}.
Notation com_law := ComLaw.type.
HB.factory Record isComLaw T (idm : T) (op : T -> T -> T) := {
opA : associative op;
opC : commutative op;
op1m : left_id idm op;
}.
HB.builders Context T idm op of isComLaw T idm op.
Lemma opm1 : right_id idm op. Proof. by move=> x; rewrite opC op1m. Qed.
HB.instance Definition _ := isLaw.Build T idm op opA op1m opm1.
HB.instance Definition _ := isCommutativeLaw.Build T op opC.
HB.end.
HB.mixin Record isMulLaw T (zero : T) (mul : T -> T -> T) := {
mul_zerol : left_zero zero mul;
mul_zeror : right_zero zero mul;
}.
#[export]
HB.structure Definition MulLaw T zero := {mul of isMulLaw T zero mul}.
Notation mul_law := MulLaw.type.
HB.mixin Record isAddLaw T (mul : T -> T -> T) (op : T -> T -> T) := {
mul_op_Dl : left_distributive mul op;
mul_op_Dr : right_distributive mul op;
}.
#[export]
HB.structure Definition AddLaw T zero mul :=
{add of ComLaw T zero add & isAddLaw T mul add}.
Notation add_law := AddLaw.type.
Module Import Exports. HB.reexport. End Exports.
Section CommutativeAxioms.
Variable (T : Type) (zero one : T) (mul add : T -> T -> T).
Hypothesis mulC : commutative mul.
Lemma mulC_id : left_id one mul -> right_id one mul.
Proof. by move=> mul1x x; rewrite mulC. Qed.
Lemma mulC_zero : left_zero zero mul -> right_zero zero mul.
Proof. by move=> mul0x x; rewrite mulC. Qed.
Lemma mulC_dist : left_distributive mul add -> right_distributive mul add.
Proof. by move=> mul_addl x y z; rewrite !(mulC x). Qed.
End CommutativeAxioms.
Module Theory.
Export SemiGroup.Theory.
Section Theory.
Variables (T : Type) (idm : T).
Section Plain.
Variable mul : law idm.
Lemma mul1m : left_id idm mul. Proof. exact: op1m. Qed.
Lemma mulm1 : right_id idm mul. Proof. exact: opm1. Qed.
Lemma iteropE n x : iterop n mul x idm = iter n (mul x) idm.
Proof. by case: n => // n; rewrite iterSr mulm1 iteropS. Qed.
End Plain.
Section Mul.
Variable mul : mul_law idm.
Lemma mul0m : left_zero idm mul. Proof. exact: mul_zerol. Qed.
Lemma mulm0 : right_zero idm mul. Proof. exact: mul_zeror. Qed.
End Mul.
Section Add.
Variables (mul : T -> T -> T) (add : add_law idm mul).
Lemma addmA : associative add. Proof. exact: mulmA. Qed.
Lemma addmC : commutative add. Proof. exact: mulmC. Qed.
Lemma addmCA : left_commutative add. Proof. exact: mulmCA. Qed.
Lemma addmAC : right_commutative add. Proof. exact: mulmAC. Qed.
Lemma add0m : left_id idm add. Proof. exact: mul1m. Qed.
Lemma addm0 : right_id idm add. Proof. exact: mulm1. Qed.
Lemma mulmDl : left_distributive mul add. Proof. exact: mul_op_Dl. Qed.
Lemma mulmDr : right_distributive mul add. Proof. exact: mul_op_Dr. Qed.
End Add.
Definition simpm := (mulm1, mulm0, mul1m, mul0m, mulmA).
End Theory.
End Theory.
Include SemiGroup.Theory.
Include Theory.
End Monoid.
Export Monoid.Exports.
Section PervasiveMonoids.
Import Monoid.
HB.instance Definition _ := isComLaw.Build bool true andb andbA andbC andTb.
HB.instance Definition _ := isMulLaw.Build bool false andb andFb andbF.
HB.instance Definition _ := isComLaw.Build bool false orb orbA orbC orFb.
HB.instance Definition _ := isMulLaw.Build bool true orb orTb orbT.
HB.instance Definition _ := isComLaw.Build bool false addb addbA addbC addFb.
HB.instance Definition _ := isAddLaw.Build bool andb orb andb_orl andb_orr.
HB.instance Definition _ := isAddLaw.Build bool orb andb orb_andl orb_andr.
HB.instance Definition _ := isAddLaw.Build bool andb addb andb_addl andb_addr.
HB.instance Definition _ := isComLaw.Build nat 0 addn addnA addnC add0n.
HB.instance Definition _ := isComLaw.Build nat 1 muln mulnA mulnC mul1n.
HB.instance Definition _ := isMulLaw.Build nat 0 muln mul0n muln0.
HB.instance Definition _ := isAddLaw.Build nat muln addn mulnDl mulnDr.
HB.instance Definition _ := isComLaw.Build nat 0 maxn maxnA maxnC max0n.
HB.instance Definition _ := isAddLaw.Build nat muln maxn maxnMl maxnMr.
HB.instance Definition _ := isComLaw.Build nat 0 gcdn gcdnA gcdnC gcd0n.
HB.instance Definition _ := isAddLaw.Build nat muln gcdn muln_gcdl muln_gcdr.
HB.instance Definition _ := isComLaw.Build nat 1 lcmn lcmnA lcmnC lcm1n.
HB.instance Definition _ := isAddLaw.Build nat muln lcmn muln_lcml muln_lcmr.
HB.instance Definition _ T := isLaw.Build (seq T) nil cat
(@catA T) (@cat0s T) (@cats0 T).
End PervasiveMonoids.
(* Unit test for the [...law of ...] Notations
Definition myp := addn. Definition mym := muln.
Canonical myp_mon := [law of myp].
Canonical myp_cmon := [com_law of myp].
Canonical mym_mul := [mul_law of mym].
Canonical myp_add := [add_law _ of myp].
Print myp_add.
Print Canonical Projections.
*)
Delimit Scope big_scope with BIG.
Open Scope big_scope.
(* The bigbody wrapper is a workaround for a quirk of the Coq pretty-printer, *)
(* which would fail to redisplay the \big notation when the <general_term> or *)
(* <condition> do not depend on the bound index. The BigBody constructor *)
(* packages both in in a term in which i occurs; it also depends on the *)
(* iterated <op>, as this can give more information on the expected type of *)
(* the <general_term>, thus allowing for the insertion of coercions. *)
Variant bigbody R I := BigBody of I & (R -> R -> R) & bool & R.
Definition applybig {R I} (body : bigbody R I) x :=
let: BigBody _ op b v := body in if b then op v x else x.
Definition reducebig R I idx r (body : I -> bigbody R I) :=
foldr (applybig \o body) idx r.
HB.lock Definition bigop := reducebig.
Canonical bigop_unlock := Unlockable bigop.unlock.
Definition index_iota m n := iota m (n - m).
Lemma mem_index_iota m n i : i \in index_iota m n = (m <= i < n).
Proof.
rewrite mem_iota; case le_m_i: (m <= i) => //=.
by rewrite -leq_subLR subSn // -subn_gt0 -subnDA subnKC // subn_gt0.
Qed.
(* Legacy mathcomp scripts have been relying on the fact that enum A and *)
(* filter A (index_enum T) are convertible. This is likely to change in the *)
(* next mathcomp release when enum, pick, subset and card are generalised to *)
(* predicates with finite support in a choiceType - in fact the two will only *)
(* be equal up to permutation in this new theory. *)
(* It is therefore advisable to stop relying on this, and use the new *)
(* facilities provided in this library: lemmas big_enumP, big_enum, big_image *)
(* and such. Users wishing to test compliance should change the Defined in *)
(* index_enum_key to Qed, and comment out the filter_index_enum compatibility *)
(* definition below. *)
Fact index_enum_key : unit. Proof. split. Defined. (* Qed. *)
Definition index_enum (T : finType) :=
locked_with index_enum_key (Finite.enum T).
Lemma deprecated_filter_index_enum T P : filter P (index_enum T) = enum P.
Proof. by rewrite [index_enum T]unlock. Qed.
Lemma mem_index_enum T i : i \in index_enum T.
Proof. by rewrite [index_enum T]unlock -enumT mem_enum. Qed.
#[global] Hint Resolve mem_index_enum : core.
Lemma index_enum_uniq T : uniq (index_enum T).
Proof. by rewrite [index_enum T]unlock -enumT enum_uniq. Qed.
Notation "\big [ op / idx ]_ ( i <- r | P ) F" :=
(bigop idx r (fun i => BigBody i op P%B F)) : big_scope.
Notation "\big [ op / idx ]_ ( i <- r ) F" :=
(bigop idx r (fun i => BigBody i op true F)) : big_scope.
Notation "\big [ op / idx ]_ ( m <= i < n | P ) F" :=
(bigop idx (index_iota m n) (fun i : nat => BigBody i op P%B F))
: big_scope.
Notation "\big [ op / idx ]_ ( m <= i < n ) F" :=
(bigop idx (index_iota m n) (fun i : nat => BigBody i op true F))
: big_scope.
Notation "\big [ op / idx ]_ ( i | P ) F" :=
(bigop idx (index_enum _) (fun i => BigBody i op P%B F)) : big_scope.
Notation "\big [ op / idx ]_ i F" :=
(bigop idx (index_enum _) (fun i => BigBody i op true F)) : big_scope.
Notation "\big [ op / idx ]_ ( i : t | P ) F" :=
(bigop idx (index_enum _) (fun i : t => BigBody i op P%B F))
(only parsing) : big_scope.
Notation "\big [ op / idx ]_ ( i : t ) F" :=
(bigop idx (index_enum _) (fun i : t => BigBody i op true F))
(only parsing) : big_scope.
Notation "\big [ op / idx ]_ ( i < n | P ) F" :=
(\big[op/idx]_(i : ordinal n | P%B) F) : big_scope.
Notation "\big [ op / idx ]_ ( i < n ) F" :=
(\big[op/idx]_(i : ordinal n) F) : big_scope.
Notation "\big [ op / idx ]_ ( i 'in' A | P ) F" :=
(\big[op/idx]_(i | (i \in A) && P) F) : big_scope.
Notation "\big [ op / idx ]_ ( i 'in' A ) F" :=
(\big[op/idx]_(i | i \in A) F) : big_scope.
Notation BIG_F := (F in \big[_/_]_(i <- _ | _) F i)%pattern.
Notation BIG_P := (P in \big[_/_]_(i <- _ | P i) _)%pattern.
Local Notation "+%N" := addn (only parsing).
Notation "\sum_ ( i <- r | P ) F" :=
(\big[+%N/0%N]_(i <- r | P%B) F%N) : nat_scope.
Notation "\sum_ ( i <- r ) F" :=
(\big[+%N/0%N]_(i <- r) F%N) : nat_scope.
Notation "\sum_ ( m <= i < n | P ) F" :=
(\big[+%N/0%N]_(m <= i < n | P%B) F%N) : nat_scope.
Notation "\sum_ ( m <= i < n ) F" :=
(\big[+%N/0%N]_(m <= i < n) F%N) : nat_scope.
Notation "\sum_ ( i | P ) F" :=
(\big[+%N/0%N]_(i | P%B) F%N) : nat_scope.
Notation "\sum_ i F" :=
(\big[+%N/0%N]_i F%N) : nat_scope.
Notation "\sum_ ( i : t | P ) F" :=
(\big[+%N/0%N]_(i : t | P%B) F%N) (only parsing) : nat_scope.
Notation "\sum_ ( i : t ) F" :=
(\big[+%N/0%N]_(i : t) F%N) (only parsing) : nat_scope.
Notation "\sum_ ( i < n | P ) F" :=
(\big[+%N/0%N]_(i < n | P%B) F%N) : nat_scope.
Notation "\sum_ ( i < n ) F" :=
(\big[+%N/0%N]_(i < n) F%N) : nat_scope.
Notation "\sum_ ( i 'in' A | P ) F" :=
(\big[+%N/0%N]_(i in A | P%B) F%N) : nat_scope.
Notation "\sum_ ( i 'in' A ) F" :=
(\big[+%N/0%N]_(i in A) F%N) : nat_scope.
Local Notation "*%N" := muln (only parsing).
Notation "\prod_ ( i <- r | P ) F" :=
(\big[*%N/1%N]_(i <- r | P%B) F%N) : nat_scope.
Notation "\prod_ ( i <- r ) F" :=
(\big[*%N/1%N]_(i <- r) F%N) : nat_scope.
Notation "\prod_ ( m <= i < n | P ) F" :=
(\big[*%N/1%N]_(m <= i < n | P%B) F%N) : nat_scope.
Notation "\prod_ ( m <= i < n ) F" :=
(\big[*%N/1%N]_(m <= i < n) F%N) : nat_scope.
Notation "\prod_ ( i | P ) F" :=
(\big[*%N/1%N]_(i | P%B) F%N) : nat_scope.
Notation "\prod_ i F" :=
(\big[*%N/1%N]_i F%N) : nat_scope.
Notation "\prod_ ( i : t | P ) F" :=
(\big[*%N/1%N]_(i : t | P%B) F%N) (only parsing) : nat_scope.
Notation "\prod_ ( i : t ) F" :=
(\big[*%N/1%N]_(i : t) F%N) (only parsing) : nat_scope.
Notation "\prod_ ( i < n | P ) F" :=
(\big[*%N/1%N]_(i < n | P%B) F%N) : nat_scope.
Notation "\prod_ ( i < n ) F" :=
(\big[*%N/1%N]_(i < n) F%N) : nat_scope.
Notation "\prod_ ( i 'in' A | P ) F" :=
(\big[*%N/1%N]_(i in A | P%B) F%N) : nat_scope.
Notation "\prod_ ( i 'in' A ) F" :=
(\big[*%N/1%N]_(i in A) F%N) : nat_scope.
Notation "\max_ ( i <- r | P ) F" :=
(\big[maxn/0%N]_(i <- r | P%B) F%N) : nat_scope.
Notation "\max_ ( i <- r ) F" :=
(\big[maxn/0%N]_(i <- r) F%N) : nat_scope.
Notation "\max_ ( i | P ) F" :=
(\big[maxn/0%N]_(i | P%B) F%N) : nat_scope.
Notation "\max_ i F" :=
(\big[maxn/0%N]_i F%N) : nat_scope.
Notation "\max_ ( i : I | P ) F" :=
(\big[maxn/0%N]_(i : I | P%B) F%N) (only parsing) : nat_scope.
Notation "\max_ ( i : I ) F" :=
(\big[maxn/0%N]_(i : I) F%N) (only parsing) : nat_scope.
Notation "\max_ ( m <= i < n | P ) F" :=
(\big[maxn/0%N]_(m <= i < n | P%B) F%N) : nat_scope.
Notation "\max_ ( m <= i < n ) F" :=
(\big[maxn/0%N]_(m <= i < n) F%N) : nat_scope.
Notation "\max_ ( i < n | P ) F" :=
(\big[maxn/0%N]_(i < n | P%B) F%N) : nat_scope.
Notation "\max_ ( i < n ) F" :=
(\big[maxn/0%N]_(i < n) F%N) : nat_scope.
Notation "\max_ ( i 'in' A | P ) F" :=
(\big[maxn/0%N]_(i in A | P%B) F%N) : nat_scope.
Notation "\max_ ( i 'in' A ) F" :=
(\big[maxn/0%N]_(i in A) F%N) : nat_scope.
(* Induction loading *)
Lemma big_load R (K K' : R -> Type) idx op I r (P : pred I) F :
K (\big[op/idx]_(i <- r | P i) F i) * K' (\big[op/idx]_(i <- r | P i) F i)
-> K' (\big[op/idx]_(i <- r | P i) F i).
Proof. by case. Qed.
Arguments big_load [R] K [K'] idx op [I].
Section Elim3.
Variables (R1 R2 R3 : Type) (K : R1 -> R2 -> R3 -> Type).
Variables (id1 : R1) (op1 : R1 -> R1 -> R1).
Variables (id2 : R2) (op2 : R2 -> R2 -> R2).
Variables (id3 : R3) (op3 : R3 -> R3 -> R3).
Hypothesis Kid : K id1 id2 id3.
Lemma big_rec3 I r (P : pred I) F1 F2 F3
(K_F : forall i y1 y2 y3, P i -> K y1 y2 y3 ->
K (op1 (F1 i) y1) (op2 (F2 i) y2) (op3 (F3 i) y3)) :
K (\big[op1/id1]_(i <- r | P i) F1 i)
(\big[op2/id2]_(i <- r | P i) F2 i)
(\big[op3/id3]_(i <- r | P i) F3 i).
Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: K_F. Qed.
Hypothesis Kop : forall x1 x2 x3 y1 y2 y3,
K x1 x2 x3 -> K y1 y2 y3-> K (op1 x1 y1) (op2 x2 y2) (op3 x3 y3).
Lemma big_ind3 I r (P : pred I) F1 F2 F3
(K_F : forall i, P i -> K (F1 i) (F2 i) (F3 i)) :
K (\big[op1/id1]_(i <- r | P i) F1 i)
(\big[op2/id2]_(i <- r | P i) F2 i)
(\big[op3/id3]_(i <- r | P i) F3 i).
Proof. by apply: big_rec3 => i x1 x2 x3 /K_F; apply: Kop. Qed.
End Elim3.
Arguments big_rec3 [R1 R2 R3] K [id1 op1 id2 op2 id3 op3] _ [I r P F1 F2 F3].
Arguments big_ind3 [R1 R2 R3] K [id1 op1 id2 op2 id3 op3] _ _ [I r P F1 F2 F3].
Section Elim2.
Variables (R1 R2 : Type) (K : R1 -> R2 -> Type) (f : R2 -> R1).
Variables (id1 : R1) (op1 : R1 -> R1 -> R1).
Variables (id2 : R2) (op2 : R2 -> R2 -> R2).
Hypothesis Kid : K id1 id2.
Lemma big_rec2 I r (P : pred I) F1 F2
(K_F : forall i y1 y2, P i -> K y1 y2 ->
K (op1 (F1 i) y1) (op2 (F2 i) y2)) :
K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i).
Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: K_F. Qed.
Hypothesis Kop : forall x1 x2 y1 y2,
K x1 x2 -> K y1 y2 -> K (op1 x1 y1) (op2 x2 y2).
Lemma big_ind2 I r (P : pred I) F1 F2 (K_F : forall i, P i -> K (F1 i) (F2 i)) :
K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i).
Proof. by apply: big_rec2 => i x1 x2 /K_F; apply: Kop. Qed.
Hypotheses (f_op : {morph f : x y / op2 x y >-> op1 x y}) (f_id : f id2 = id1).
Lemma big_morph I r (P : pred I) F :
f (\big[op2/id2]_(i <- r | P i) F i) = \big[op1/id1]_(i <- r | P i) f (F i).
Proof. by rewrite unlock; elim: r => //= i r <-; rewrite -f_op -fun_if. Qed.
End Elim2.
Arguments big_rec2 [R1 R2] K [id1 op1 id2 op2] _ [I r P F1 F2].
Arguments big_ind2 [R1 R2] K [id1 op1 id2 op2] _ _ [I r P F1 F2].
Arguments big_morph [R1 R2] f [id1 op1 id2 op2] _ _ [I].
Section Elim1.
Variables (R : Type) (K : R -> Type) (f : R -> R).
Variables (idx : R) (op op' : R -> R -> R).
Hypothesis Kid : K idx.
Lemma big_rec I r (P : pred I) F
(Kop : forall i x, P i -> K x -> K (op (F i) x)) :
K (\big[op/idx]_(i <- r | P i) F i).
Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: Kop. Qed.
Hypothesis Kop : forall x y, K x -> K y -> K (op x y).
Lemma big_ind I r (P : pred I) F (K_F : forall i, P i -> K (F i)) :
K (\big[op/idx]_(i <- r | P i) F i).
Proof. by apply: big_rec => // i x /K_F /Kop; apply. Qed.
Hypothesis Kop' : forall x y, K x -> K y -> op x y = op' x y.
Lemma eq_big_op I r (P : pred I) F (K_F : forall i, P i -> K (F i)) :
\big[op/idx]_(i <- r | P i) F i = \big[op'/idx]_(i <- r | P i) F i.
Proof.
by elim/(big_load K): _; elim/big_rec2: _ => // i _ y Pi [Ky <-]; auto.
Qed.
Hypotheses (fM : {morph f : x y / op x y}) (f_id : f idx = idx).
Lemma big_endo I r (P : pred I) F :
f (\big[op/idx]_(i <- r | P i) F i) = \big[op/idx]_(i <- r | P i) f (F i).
Proof. exact: big_morph. Qed.
End Elim1.
Arguments big_rec [R] K [idx op] _ [I r P F].
Arguments big_ind [R] K [idx op] _ _ [I r P F].
Arguments eq_big_op [R] K [idx op] op' _ _ _ [I].
Arguments big_endo [R] f [idx op] _ _ [I].
Lemma big_morph_in (R1 R2 : Type) (Q : {pred R2}) (f : R2 -> R1)
(id1 : R1) (op1 : R1 -> R1 -> R1)
(id2 : R2) (op2 : R2 -> R2 -> R2) :
{in Q &, forall x y, op2 x y \in Q} ->
id2 \in Q ->
{in Q &, {morph f : x y / op2 x y >-> op1 x y}} ->
f id2 = id1 ->
forall [I : Type] (r : seq I) (P : pred I) (F : I -> R2),
(forall i, P i -> F i \in Q) ->
f (\big[op2/id2]_(i <- r | P i) F i) = \big[op1/id1]_(i <- r | P i) f (F i).
Proof.
move=> Qop Qid fop fid I r P F QF; elim/(big_load Q): _.
by elim/big_rec2: _ => // j x y Pj [Qx <-]; rewrite [Q _]Qop ?fop ?QF.
Qed.
Arguments big_morph_in [R1 R2] Q f [id1 op1 id2 op2].
Section oAC.
Variables (T : Type) (op : T -> T -> T).
Definition oAC of associative op & commutative op :=
fun x => oapp (fun y => Some (oapp (op^~ y) y x)) x.
Arguments oAC : simpl never.
Hypothesis (opA : associative op) (opC : commutative op).
Local Notation oop := (oAC opA opC).
Lemma oACE x y : oop (Some x) (Some y) = some (op x y). Proof. by []. Qed.
Lemma oopA_subdef : associative oop.
Proof. by move=> [x|] [y|] [z|]//; rewrite /oAC/= opA. Qed.
Lemma oopx1_subdef : left_id None oop. Proof. by case. Qed.
Lemma oop1x_subdef : right_id None oop. Proof. by []. Qed.
Lemma oopC_subdef : commutative oop.
Proof. by move=> [x|] [y|]//; rewrite /oAC/= opC. Qed.
HB.instance Definition _ := Monoid.isComLaw.Build (option T) None oop
oopA_subdef oopC_subdef oopx1_subdef.
Context [x : T].
Lemma some_big_AC_mk_monoid [I : Type] r P (F : I -> T) :
Some (\big[op/x]_(i <- r | P i) F i) =
oop (\big[oop/None]_(i <- r | P i) Some (F i)) (Some x).
Proof. by elim/big_rec2 : _ => //= i [y|] _ Pi [] -> //=; rewrite opA. Qed.
Lemma big_AC_mk_monoid [I : Type] r P (F : I -> T) :
\big[op/x]_(i <- r | P i) F i =
odflt x (oop (\big[oop/None]_(i <- r | P i) Some (F i)) (Some x)).
Proof. by apply: Some_inj; rewrite some_big_AC_mk_monoid. Qed.
End oAC.
Arguments oAC : simpl never.
Section Extensionality.
Variables (R : Type) (idx : R) (op : R -> R -> R).
Section SeqExtension.
Variable I : Type.
Lemma foldrE r : foldr op idx r = \big[op/idx]_(x <- r) x.
Proof. by rewrite unlock. Qed.
Lemma big_filter r (P : pred I) F :
\big[op/idx]_(i <- filter P r) F i = \big[op/idx]_(i <- r | P i) F i.
Proof. by rewrite unlock; elim: r => //= i r <-; case (P i). Qed.
Lemma big_filter_cond r (P1 P2 : pred I) F :
\big[op/idx]_(i <- filter P1 r | P2 i) F i
= \big[op/idx]_(i <- r | P1 i && P2 i) F i.
Proof.
rewrite -big_filter -(big_filter r); congr bigop.
by rewrite -filter_predI; apply: eq_filter => i; apply: andbC.
Qed.
Lemma eq_bigl r (P1 P2 : pred I) F :
P1 =1 P2 ->
\big[op/idx]_(i <- r | P1 i) F i = \big[op/idx]_(i <- r | P2 i) F i.
Proof. by move=> eqP12; rewrite -!(big_filter r) (eq_filter eqP12). Qed.
(* A lemma to permute aggregate conditions. *)
Lemma big_andbC r (P Q : pred I) F :
\big[op/idx]_(i <- r | P i && Q i) F i
= \big[op/idx]_(i <- r | Q i && P i) F i.
Proof. by apply: eq_bigl => i; apply: andbC. Qed.
Lemma eq_bigr r (P : pred I) F1 F2 : (forall i, P i -> F1 i = F2 i) ->
\big[op/idx]_(i <- r | P i) F1 i = \big[op/idx]_(i <- r | P i) F2 i.
Proof. by move=> eqF12; elim/big_rec2: _ => // i x _ /eqF12-> ->. Qed.
Lemma eq_big r (P1 P2 : pred I) F1 F2 :
P1 =1 P2 -> (forall i, P1 i -> F1 i = F2 i) ->
\big[op/idx]_(i <- r | P1 i) F1 i = \big[op/idx]_(i <- r | P2 i) F2 i.
Proof. by move/eq_bigl <-; move/eq_bigr->. Qed.
Lemma congr_big r1 r2 (P1 P2 : pred I) F1 F2 :
r1 = r2 -> P1 =1 P2 -> (forall i, P1 i -> F1 i = F2 i) ->
\big[op/idx]_(i <- r1 | P1 i) F1 i = \big[op/idx]_(i <- r2 | P2 i) F2 i.
Proof. by move=> <-{r2}; apply: eq_big. Qed.
Lemma big_nil (P : pred I) F : \big[op/idx]_(i <- [::] | P i) F i = idx.
Proof. by rewrite unlock. Qed.
Lemma big_cons i r (P : pred I) F :
let x := \big[op/idx]_(j <- r | P j) F j in
\big[op/idx]_(j <- i :: r | P j) F j = if P i then op (F i) x else x.
Proof. by rewrite unlock. Qed.
Lemma big_rcons_op i r (P : pred I) F :
let idx' := if P i then op (F i) idx else idx in
\big[op/idx]_(j <- rcons r i | P j) F j = \big[op/idx']_(j <- r | P j) F j.
Proof.
by elim: r => /= [|j r]; rewrite !(big_nil, big_cons, unlock)// => ->.
Qed.
Lemma big_map J (h : J -> I) r (P : pred I) F :
\big[op/idx]_(i <- map h r | P i) F i
= \big[op/idx]_(j <- r | P (h j)) F (h j).
Proof. by rewrite unlock; elim: r => //= j r ->. Qed.
Lemma big_nth x0 r (P : pred I) F :
\big[op/idx]_(i <- r | P i) F i
= \big[op/idx]_(0 <= i < size r | P (nth x0 r i)) (F (nth x0 r i)).
Proof. by rewrite -[r in LHS](mkseq_nth x0) big_map /index_iota subn0. Qed.
Lemma big_hasC r (P : pred I) F :
~~ has P r -> \big[op/idx]_(i <- r | P i) F i = idx.
Proof.
by rewrite -big_filter has_count -size_filter -eqn0Ngt unlock => /nilP->.
Qed.
Lemma big_pred0_eq (r : seq I) F : \big[op/idx]_(i <- r | false) F i = idx.
Proof. by rewrite big_hasC // has_pred0. Qed.
Lemma big_pred0 r (P : pred I) F :
P =1 xpred0 -> \big[op/idx]_(i <- r | P i) F i = idx.
Proof. by move/eq_bigl->; apply: big_pred0_eq. Qed.
Lemma big_cat_nested r1 r2 (P : pred I) F :
let x := \big[op/idx]_(i <- r2 | P i) F i in
\big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/x]_(i <- r1 | P i) F i.
Proof. by rewrite unlock /reducebig foldr_cat. Qed.
Lemma big_catl r1 r2 (P : pred I) F :
~~ has P r2 ->
\big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/idx]_(i <- r1 | P i) F i.
Proof. by rewrite big_cat_nested => /big_hasC->. Qed.
Lemma big_catr r1 r2 (P : pred I) F :
~~ has P r1 ->
\big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/idx]_(i <- r2 | P i) F i.
Proof.
rewrite -big_filter -(big_filter r2) filter_cat.
by rewrite has_count -size_filter; case: filter.
Qed.
End SeqExtension.
Lemma big_map_id J (h : J -> R) r (P : pred R) :
\big[op/idx]_(i <- map h r | P i) i
= \big[op/idx]_(j <- r | P (h j)) h j.
Proof. exact: big_map. Qed.
Lemma big_condT (J : finType) (A : {pred J}) F :
\big[op/idx]_(i in A | true) F i = \big[op/idx]_(i in A) F i.
Proof. by apply: eq_bigl => i; exact: andbT. Qed.
(* The following lemmas can be used to localise extensionality to a specific *)
(* index sequence. This is done by ssreflect rewriting, before applying *)
(* congruence or induction lemmas. *)
Lemma big_seq_cond (I : eqType) r (P : pred I) F :
\big[op/idx]_(i <- r | P i) F i
= \big[op/idx]_(i <- r | (i \in r) && P i) F i.
Proof.
by rewrite -!(big_filter r); congr bigop; apply: eq_in_filter => i ->.
Qed.
Lemma big_seq (I : eqType) (r : seq I) F :
\big[op/idx]_(i <- r) F i = \big[op/idx]_(i <- r | i \in r) F i.
Proof. by rewrite big_seq_cond big_andbC. Qed.
Lemma eq_big_seq (I : eqType) (r : seq I) F1 F2 :
{in r, F1 =1 F2} -> \big[op/idx]_(i <- r) F1 i = \big[op/idx]_(i <- r) F2 i.
Proof. by move=> eqF; rewrite !big_seq (eq_bigr _ eqF). Qed.
(* Similar lemmas for exposing integer indexing in the predicate. *)
Lemma big_nat_cond m n (P : pred nat) F :
\big[op/idx]_(m <= i < n | P i) F i
= \big[op/idx]_(m <= i < n | (m <= i < n) && P i) F i.
Proof.
by rewrite big_seq_cond; apply: eq_bigl => i; rewrite mem_index_iota.
Qed.
Lemma big_nat m n F :
\big[op/idx]_(m <= i < n) F i = \big[op/idx]_(m <= i < n | m <= i < n) F i.
Proof. by rewrite big_nat_cond big_andbC. Qed.
Lemma congr_big_nat m1 n1 m2 n2 P1 P2 F1 F2 :
m1 = m2 -> n1 = n2 ->
(forall i, m1 <= i < n2 -> P1 i = P2 i) ->
(forall i, P1 i && (m1 <= i < n2) -> F1 i = F2 i) ->
\big[op/idx]_(m1 <= i < n1 | P1 i) F1 i
= \big[op/idx]_(m2 <= i < n2 | P2 i) F2 i.
Proof.
move=> <- <- eqP12 eqF12; rewrite big_seq_cond (big_seq_cond _ P2).
apply: eq_big => i; rewrite ?inE /= !mem_index_iota.
by apply: andb_id2l; apply: eqP12.
by rewrite andbC; apply: eqF12.
Qed.
Lemma eq_big_nat m n F1 F2 :
(forall i, m <= i < n -> F1 i = F2 i) ->
\big[op/idx]_(m <= i < n) F1 i = \big[op/idx]_(m <= i < n) F2 i.
Proof. by move=> eqF; apply: congr_big_nat. Qed.
Lemma big_geq m n (P : pred nat) F :
m >= n -> \big[op/idx]_(m <= i < n | P i) F i = idx.
Proof. by move=> ge_m_n; rewrite /index_iota (eqnP ge_m_n) big_nil. Qed.
Lemma big_ltn_cond m n (P : pred nat) F :
m < n -> let x := \big[op/idx]_(m.+1 <= i < n | P i) F i in
\big[op/idx]_(m <= i < n | P i) F i = if P m then op (F m) x else x.
Proof. by case: n => [//|n] le_m_n; rewrite /index_iota subSn // big_cons. Qed.
Lemma big_ltn m n F :
m < n ->
\big[op/idx]_(m <= i < n) F i = op (F m) (\big[op/idx]_(m.+1 <= i < n) F i).
Proof. by move=> lt_mn; apply: big_ltn_cond. Qed.
Lemma big_addn m n a (P : pred nat) F :
\big[op/idx]_(m + a <= i < n | P i) F i =
\big[op/idx]_(m <= i < n - a | P (i + a)) F (i + a).
Proof.
rewrite /index_iota -subnDA addnC iotaDl big_map.
by apply: eq_big => ? *; rewrite addnC.
Qed.
Lemma big_add1 m n (P : pred nat) F :
\big[op/idx]_(m.+1 <= i < n | P i) F i =
\big[op/idx]_(m <= i < n.-1 | P (i.+1)) F (i.+1).
Proof.
by rewrite -addn1 big_addn subn1; apply: eq_big => ? *; rewrite addn1.
Qed.
Lemma big_nat_recl n m F : m <= n ->
\big[op/idx]_(m <= i < n.+1) F i =
op (F m) (\big[op/idx]_(m <= i < n) F i.+1).
Proof. by move=> lemn; rewrite big_ltn // big_add1. Qed.
Lemma big_mkord n (P : pred nat) F :
\big[op/idx]_(0 <= i < n | P i) F i = \big[op/idx]_(i < n | P i) F i.
Proof.
rewrite /index_iota subn0 -(big_map (@nat_of_ord n)).
by congr bigop; rewrite /index_enum 2!unlock val_ord_enum.
Qed.
Lemma big_mknat n (P : pred 'I_n.+1) F :
\big[op/idx]_(i < n.+1 | P i) F i
= \big[op/idx]_(0 <= i < n.+1 | P (inord i)) F (inord i).
Proof. by rewrite big_mkord; apply: eq_big => ?; rewrite inord_val. Qed.
Lemma big_nat_widen m n1 n2 (P : pred nat) F :
n1 <= n2 ->
\big[op/idx]_(m <= i < n1 | P i) F i
= \big[op/idx]_(m <= i < n2 | P i && (i < n1)) F i.
Proof.
move=> len12; symmetry; rewrite -big_filter filter_predI big_filter.
have [ltn_trans eq_by_mem] := (ltn_trans, irr_sorted_eq ltn_trans ltnn).
congr bigop; apply: eq_by_mem; rewrite ?sorted_filter ?iota_ltn_sorted // => i.
rewrite mem_filter !mem_index_iota andbCA andbA andb_idr => // /andP[_].
by move/leq_trans->.
Qed.
Lemma big_ord_widen_cond n1 n2 (P : pred nat) (F : nat -> R) :
n1 <= n2 ->
\big[op/idx]_(i < n1 | P i) F i
= \big[op/idx]_(i < n2 | P i && (i < n1)) F i.
Proof. by move/big_nat_widen=> len12; rewrite -big_mkord len12 big_mkord. Qed.
Lemma big_ord_widen n1 n2 (F : nat -> R) :
n1 <= n2 ->
\big[op/idx]_(i < n1) F i = \big[op/idx]_(i < n2 | i < n1) F i.
Proof. by move=> le_n12; apply: (big_ord_widen_cond (predT)). Qed.
Lemma big_ord_widen_leq n1 n2 (P : pred 'I_(n1.+1)) F :
n1 < n2 ->
\big[op/idx]_(i < n1.+1 | P i) F i
= \big[op/idx]_(i < n2 | P (inord i) && (i <= n1)) F (inord i).
Proof.
move=> len12; pose g G i := G (inord i : 'I_(n1.+1)).
rewrite -(big_ord_widen_cond (g _ P) (g _ F) len12) {}/g.
by apply: eq_big => i *; rewrite inord_val.
Qed.
Lemma big_ord0 P F : \big[op/idx]_(i < 0 | P i) F i = idx.
Proof. by rewrite big_pred0 => [|[]]. Qed.
Lemma big_mask_tuple I n m (t : n.-tuple I) (P : pred I) F :
\big[op/idx]_(i <- mask m t | P i) F i
= \big[op/idx]_(i < n | nth false m i && P (tnth t i)) F (tnth t i).
Proof.
rewrite [t in LHS]tuple_map_ord/= -map_mask big_map.
by rewrite mask_enum_ord big_filter_cond/= enumT.
Qed.
Lemma big_mask I r m (P : pred I) (F : I -> R) (r_ := tnth (in_tuple r)) :
\big[op/idx]_(i <- mask m r | P i) F i
= \big[op/idx]_(i < size r | nth false m i && P (r_ i)) F (r_ i).
Proof. exact: (big_mask_tuple _ (in_tuple r)). Qed.
Lemma big_tnth I r (P : pred I) F (r_ := tnth (in_tuple r)) :
\big[op/idx]_(i <- r | P i) F i
= \big[op/idx]_(i < size r | P (r_ i)) (F (r_ i)).
Proof.
rewrite /= -[r in LHS](mask_true (leqnn (size r))) big_mask//.
by apply: eq_bigl => i /=; rewrite nth_nseq ltn_ord.
Qed.
Lemma big_index_uniq (I : eqType) (r : seq I) (E : 'I_(size r) -> R) :
uniq r ->
\big[op/idx]_i E i = \big[op/idx]_(x <- r) oapp E idx (insub (index x r)).
Proof.
move=> Ur; apply/esym; rewrite big_tnth.
by under [LHS]eq_bigr do rewrite index_uniq// valK.
Qed.
Lemma big_tuple I n (t : n.-tuple I) (P : pred I) F :
\big[op/idx]_(i <- t | P i) F i
= \big[op/idx]_(i < n | P (tnth t i)) F (tnth t i).
Proof. by rewrite big_tnth tvalK; case: _ / (esym _). Qed.
Lemma big_ord_narrow_cond n1 n2 (P : pred 'I_n2) F (le_n12 : n1 <= n2) :
let w := widen_ord le_n12 in
\big[op/idx]_(i < n2 | P i && (i < n1)) F i
= \big[op/idx]_(i < n1 | P (w i)) F (w i).
Proof.
case: n1 => [|n1] /= in le_n12 *.
by rewrite big_ord0 big_pred0 // => i; rewrite andbF.
rewrite (big_ord_widen_leq _ _ le_n12); apply: eq_big => i.
by apply: andb_id2r => le_i_n1; congr P; apply: val_inj; rewrite /= inordK.
by case/andP=> _ le_i_n1; congr F; apply: val_inj; rewrite /= inordK.
Qed.
Lemma big_ord_narrow_cond_leq n1 n2 (P : pred _) F (le_n12 : n1 <= n2) :
let w := @widen_ord n1.+1 n2.+1 le_n12 in
\big[op/idx]_(i < n2.+1 | P i && (i <= n1)) F i
= \big[op/idx]_(i < n1.+1 | P (w i)) F (w i).
Proof. exact: (@big_ord_narrow_cond n1.+1 n2.+1). Qed.
Lemma big_ord_narrow n1 n2 F (le_n12 : n1 <= n2) :
let w := widen_ord le_n12 in
\big[op/idx]_(i < n2 | i < n1) F i = \big[op/idx]_(i < n1) F (w i).
Proof. exact: (big_ord_narrow_cond (predT)). Qed.
Lemma big_ord_narrow_leq n1 n2 F (le_n12 : n1 <= n2) :
let w := @widen_ord n1.+1 n2.+1 le_n12 in
\big[op/idx]_(i < n2.+1 | i <= n1) F i = \big[op/idx]_(i < n1.+1) F (w i).
Proof. exact: (big_ord_narrow_cond_leq (predT)). Qed.
Lemma big_ord_recl n F :
\big[op/idx]_(i < n.+1) F i =
op (F ord0) (\big[op/idx]_(i < n) F (@lift n.+1 ord0 i)).
Proof.
pose G i := F (inord i); have eqFG i: F i = G i by rewrite /G inord_val.
under eq_bigr do rewrite eqFG; under [in RHS]eq_bigr do rewrite eqFG.
by rewrite -(big_mkord _ (fun _ => _) G) eqFG big_ltn // big_add1 /= big_mkord.
Qed.
Lemma big_nseq_cond I n a (P : pred I) F :
\big[op/idx]_(i <- nseq n a | P i) F i
= if P a then iter n (op (F a)) idx else idx.
Proof. by rewrite unlock; elim: n => /= [|n ->]; case: (P a). Qed.
Lemma big_nseq I n a (F : I -> R):
\big[op/idx]_(i <- nseq n a) F i = iter n (op (F a)) idx.
Proof. exact: big_nseq_cond. Qed.
End Extensionality.
Variant big_enum_spec (I : finType) (P : pred I) : seq I -> Type :=
BigEnumSpec e of
forall R idx op (F : I -> R),
\big[op/idx]_(i <- e) F i = \big[op/idx]_(i | P i) F i
& uniq e /\ (forall i, i \in e = P i)
& (let cP := [pred i | P i] in perm_eq e (enum cP) /\ size e = #|cP|)
: big_enum_spec P e.
(* This lemma can be used to introduce an enumeration into a non-abelian *)
(* bigop, in one of three ways: *)
(* have [e big_e [Ue mem_e] [e_enum size_e]] := big_enumP P. *)
(* gives a permutation e of enum P alongside a equation big_e for converting *)
(* between bigops iterating on (i <- e) and ones on (i | P i). Usually not *)
(* all properties of e are needed, but see below the big_distr_big_dep proof *)
(* where most are. *)
(* rewrite -big_filter; have [e ...] := big_enumP. *)
(* uses big_filter to do this conversion first, and then abstracts the *)
(* resulting filter P (index_enum T) enumeration as an e with the same *)
(* properties (see big_enum_cond below for an example of this usage). *)
(* Finally *)
(* rewrite -big_filter; case def_e: _ / big_enumP => [e ...] *)
(* does the same while remembering the definition of e. *)
Lemma big_enumP I P : big_enum_spec P (filter P (index_enum I)).
Proof.
set e := filter P _; have Ue: uniq e by apply/filter_uniq/index_enum_uniq.
have mem_e i: i \in e = P i by rewrite mem_filter mem_index_enum andbT.
split=> // [R idx op F | cP]; first by rewrite big_filter.
suffices De: perm_eq e (enum cP) by rewrite (perm_size De) cardE.
by apply/uniq_perm=> // [|i]; rewrite ?enum_uniq ?mem_enum ?mem_e.
Qed.
Section BigConst.
Variables (R : Type) (idx : R) (op : R -> R -> R).
Lemma big_const_seq I r (P : pred I) x :
\big[op/idx]_(i <- r | P i) x = iter (count P r) (op x) idx.
Proof. by rewrite unlock; elim: r => //= i r ->; case: (P i). Qed.
Lemma big_const (I : finType) (A : {pred I}) x :
\big[op/idx]_(i in A) x = iter #|A| (op x) idx.
Proof.
by have [e <- _ [_ <-]] := big_enumP A; rewrite big_const_seq count_predT.
Qed.
Lemma big_const_nat m n x :
\big[op/idx]_(m <= i < n) x = iter (n - m) (op x) idx.
Proof. by rewrite big_const_seq count_predT size_iota. Qed.
Lemma big_const_ord n x :
\big[op/idx]_(i < n) x = iter n (op x) idx.
Proof. by rewrite big_const card_ord. Qed.
End BigConst.
Section Plain.
Variable R : Type.
Variable op : R -> R -> R.
Variable x : R.
Lemma big_seq1_id I (i : I) (F : I -> R) :
\big[op/x]_(j <- [:: i]) F j = op (F i) x.
Proof. by rewrite big_cons big_nil. Qed.
Lemma big_nat1_id n F : \big[op/x]_(n <= i < n.+1) F i = op (F n) x.
Proof. by rewrite big_ltn // big_geq // mulm1. Qed.
Lemma big_pred1_eq_id (I : finType) (i : I) F :
\big[op/x]_(j | j == i) F j = op (F i) x.
Proof.
have [e1 <- _ [e_enum _]] := big_enumP (pred1 i).
by rewrite (perm_small_eq _ e_enum) enum1 ?big_seq1_id.
Qed.
Lemma big_pred1_id (I : finType) i (P : pred I) F :
P =1 pred1 i -> \big[op/x]_(j | P j) F j = op (F i) x.
Proof. by move/(eq_bigl _ _)->; apply: big_pred1_eq_id. Qed.
End Plain.
Section SemiGroupProperties.
Variable R : Type.
#[local] Notation opA := SemiGroup.opA.
#[local] Notation opC := SemiGroup.opC.
Section Id.
Variable op : SemiGroup.law R.
Variable x : R.
Hypothesis opxx : op x x = x.
Lemma big_const_idem I (r : seq I) P : \big[op/x]_(i <- r | P i) x = x.
Proof. by elim/big_ind : _ => // _ _ -> ->. Qed.
Lemma big1_idem I r (P : pred I) F :
(forall i, P i -> F i = x) -> \big[op/x]_(i <- r | P i) F i = x.
Proof.
move=> Fix; under eq_bigr => ? ? do rewrite Fix//; exact: big_const_idem.
Qed.
Lemma big_id_idem I (r : seq I) P F :
op (\big[op/x]_(i <- r | P i) F i) x = \big[op/x]_(i <- r | P i) F i.
Proof. by elim/big_rec : _ => // ? ? ?; rewrite -opA => ->. Qed.
End Id.
Section Abelian.
Variable op : SemiGroup.com_law R.
Let opCA : left_commutative op.
Proof. by move=> x *; rewrite !opA /= (opC x). Qed.
Variable x : R.
Lemma big_rem_AC (I : eqType) (r : seq I) z (P : pred I) F : z \in r ->
\big[op/x]_(y <- r | P y) F y
= if P z then op (F z) (\big[op/x]_(y <- rem z r | P y) F y)
else \big[op/x]_(y <- rem z r | P y) F y.
Proof.
elim: r =>// i r ih; rewrite big_cons rem_cons inE =>/predU1P[-> /[!eqxx]//|zr].
by case: eqP => [-> //|]; rewrite ih// big_cons; case: ifPn; case: ifPn.
Qed.
Lemma big_undup (I : eqType) (r : seq I) (P : pred I) F :
idempotent_op op ->
\big[op/x]_(i <- undup r | P i) F i = \big[op/x]_(i <- r | P i) F i.
Proof.
move=> opxx; rewrite -!(big_filter _ _ _ P) filter_undup.
elim: {P r}(filter P r) => //= i r IHr.
case: ifP => [r_i | _]; rewrite !big_cons {}IHr //.
by rewrite (big_rem_AC _ _ r_i) opA /= opxx.
Qed.
Lemma perm_big (I : eqType) r1 r2 (P : pred I) F :
perm_eq r1 r2 ->
\big[op/x]_(i <- r1 | P i) F i = \big[op/x]_(i <- r2 | P i) F i.
Proof.
elim: r1 r2 => [|i r1 IHr1] r2 eq_r12.
by case: r2 eq_r12 => [//|i r2] /[1!perm_sym] /perm_nilP.
have r2i: i \in r2 by rewrite -has_pred1 has_count -(permP eq_r12) /= eqxx.
rewrite big_cons (IHr1 (rem i r2)) -?big_rem_AC// -(perm_cons i).
exact: perm_trans (perm_to_rem _).
Qed.
Lemma big_enum_cond (I : finType) (A : {pred I}) (P : pred I) F :
\big[op/x]_(i <- enum A | P i) F i = \big[op/x]_(i in A | P i) F i.
Proof.
by rewrite -big_filter_cond; have [e _ _ [/perm_big->]] := big_enumP.
Qed.
Lemma big_enum (I : finType) (A : {pred I}) F :
\big[op/x]_(i <- enum A) F i = \big[op/x]_(i in A) F i.
Proof. by rewrite big_enum_cond big_andbC. Qed.
Lemma big_uniq (I : finType) (r : seq I) F :
uniq r -> \big[op/x]_(i <- r) F i = \big[op/x]_(i in r) F i.
Proof.
move=> uniq_r; rewrite -big_enum; apply: perm_big.
by rewrite uniq_perm ?enum_uniq // => i; rewrite mem_enum.
Qed.
Lemma bigD1 (I : finType) j (P : pred I) F :
P j -> \big[op/x]_(i | P i) F i
= op (F j) (\big[op/x]_(i | P i && (i != j)) F i).
Proof.
rewrite (big_rem_AC _ _ (mem_index_enum j)) => ->.
by rewrite rem_filter ?index_enum_uniq// big_filter_cond big_andbC.
Qed.
Arguments bigD1 [I] j [P F].
Lemma bigD1_seq (I : eqType) (r : seq I) j F :
j \in r -> uniq r ->
\big[op/x]_(i <- r) F i = op (F j) (\big[op/x]_(i <- r | i != j) F i).
Proof. by move=> /big_rem_AC-> /rem_filter->; rewrite big_filter. Qed.
Lemma big_image_cond I (J : finType) (h : J -> I) (A : pred J) (P : pred I) F :
\big[op/x]_(i <- [seq h j | j in A] | P i) F i
= \big[op/x]_(j in A | P (h j)) F (h j).
Proof. by rewrite big_map big_enum_cond. Qed.
Lemma big_image I (J : finType) (h : J -> I) (A : pred J) F :
\big[op/x]_(i <- [seq h j | j in A]) F i = \big[op/x]_(j in A) F (h j).
Proof. by rewrite big_map big_enum. Qed.
Lemma cardD1x (I : finType) (A : pred I) j :
A j -> #|SimplPred A| = 1 + #|[pred i | A i & i != j]|.
Proof.
move=> Aj; rewrite (cardD1 j) [j \in A]Aj; congr (_ + _).
by apply: eq_card => i; rewrite inE /= andbC.
Qed.
Arguments cardD1x [I A].
Lemma reindex_omap (I J : finType) (h : J -> I) h' (P : pred I) F :
(forall i, P i -> omap h (h' i) = some i) ->
\big[op/x]_(i | P i) F i =
\big[op/x]_(j | P (h j) && (h' (h j) == some j)) F (h j).
Proof.
move=> h'K; have [n lePn] := ubnP #|P|; elim: n => // n IHn in P h'K lePn *.
case: (pickP P) => [i Pi | P0]; last first.
by rewrite !big_pred0 // => j; rewrite P0.
have := h'K i Pi; case h'i_eq : (h' i) => [/= j|//] [hj_eq].
rewrite (bigD1 i Pi) (bigD1 j) hj_eq ?Pi ?h'i_eq ?eqxx //=; congr (op : _ -> _).
rewrite {}IHn => [|k /andP[]|]; [|by auto | by rewrite (cardD1x i) in lePn].
apply: eq_bigl => k; rewrite andbC -andbA (andbCA (P _)); case: eqP => //= hK.
congr (_ && ~~ _); apply/eqP/eqP => [|->//].
by move=> /(congr1 h'); rewrite h'i_eq hK => -[].
Qed.
Arguments reindex_omap [I J] h h' [P F].
Lemma reindex_onto (I J : finType) (h : J -> I) h' (P : pred I) F :
(forall i, P i -> h (h' i) = i) ->
\big[op/x]_(i | P i) F i =
\big[op/x]_(j | P (h j) && (h' (h j) == j)) F (h j).
Proof.
by move=> h'K; rewrite (reindex_omap h (some \o h'))//= => i Pi; rewrite h'K.
Qed.
Arguments reindex_onto [I J] h h' [P F].
Lemma reindex (I J : finType) (h : J -> I) (P : pred I) F :
{on [pred i | P i], bijective h} ->
\big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j)) F (h j).
Proof.
case=> h' hK h'K; rewrite (reindex_onto h h' h'K).
by apply: eq_bigl => j /[!inE]; case Pi: (P _); rewrite //= hK ?eqxx.
Qed.
Arguments reindex [I J] h [P F].
Lemma reindex_inj (I : finType) (h : I -> I) (P : pred I) F :
injective h -> \big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j)) F (h j).
Proof. by move=> injh; apply: reindex (onW_bij _ (injF_bij injh)). Qed.
Arguments reindex_inj [I h P F].
Lemma bigD1_ord n j (P : pred 'I_n) F :
P j -> \big[op/x]_(i < n | P i) F i
= op (F j) (\big[op/x]_(i < n.-1 | P (lift j i)) F (lift j i)).
Proof.
move=> Pj; rewrite (bigD1 j Pj) (reindex_omap (lift j) (unlift j))/=.
by under eq_bigl do rewrite liftK eq_sym eqxx neq_lift ?andbT.
by move=> i; case: unliftP => [k ->|->]; rewrite ?eqxx ?andbF.
Qed.
Lemma big_enum_val_cond (I : finType) (A : pred I) (P : pred I) F :
\big[op/x]_(x in A | P x) F x =
\big[op/x]_(i < #|A| | P (enum_val i)) F (enum_val i).
Proof.
have [A_eq0|/card_gt0P[x0 x0A]] := posnP #|A|.
rewrite !big_pred0 // => i; last by rewrite card0_eq.
by have: false by move: i => []; rewrite A_eq0.
rewrite (reindex (enum_val : 'I_#|A| -> I)).
by apply: eq_big => [y|y Py]; rewrite ?enum_valP.
by apply: subon_bij (enum_val_bij_in x0A) => y /andP[].
Qed.
Arguments big_enum_val_cond [I A] P F.
Lemma big_enum_rank_cond (I : finType) (A : pred I) z (zA : z \in A) P F
(h := enum_rank_in zA) :
\big[op/x]_(i < #|A| | P i) F i = \big[op/x]_(s in A | P (h s)) F (h s).
Proof.
rewrite big_enum_val_cond {}/h.
by apply: eq_big => [i|i Pi]; rewrite ?enum_valK_in.
Qed.
Arguments big_enum_rank_cond [I A z] zA P F.
Lemma big_nat_rev m n P F :
\big[op/x]_(m <= i < n | P i) F i
= \big[op/x]_(m <= i < n | P (m + n - i.+1)) F (m + n - i.+1).
Proof.
case: (ltnP m n) => ltmn; last by rewrite !big_geq.
rewrite -{3 4}(subnK (ltnW ltmn)) addnA.
do 2!rewrite (big_addn _ _ 0) big_mkord; rewrite (reindex_inj rev_ord_inj)/=.
by apply: eq_big => [i | i _]; rewrite /= -addSn subnDr addnC addnBA.
Qed.
Lemma big_rev_mkord m n P F :
\big[op/x]_(m <= k < n | P k) F k
= \big[op/x]_(k < n - m | P (n - k.+1)) F (n - k.+1).
Proof.
rewrite big_nat_rev (big_addn _ _ 0) big_mkord.
by apply: eq_big => [i|i _]; rewrite -addSn addnC subnDr.
Qed.
Section Id.
Hypothesis opxx : op x x = x.
Lemma big_mkcond_idem I r (P : pred I) F :
\big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) (if P i then F i else x).
Proof.
elim: r => [|i r]; rewrite ?(big_nil, big_cons)//.
by case: ifPn => Pi ->//; rewrite -[in LHS]big_id_idem // opC.
Qed.
Lemma big_mkcondr_idem I r (P Q : pred I) F :
\big[op/x]_(i <- r | P i && Q i) F i =
\big[op/x]_(i <- r | P i) (if Q i then F i else x).
Proof. by rewrite -big_filter_cond big_mkcond_idem big_filter. Qed.
Lemma big_mkcondl_idem I r (P Q : pred I) F :
\big[op/x]_(i <- r | P i && Q i) F i =
\big[op/x]_(i <- r | Q i) (if P i then F i else x).
Proof. by rewrite big_andbC big_mkcondr_idem. Qed.
Lemma big_rmcond_idem I (r : seq I) (P : pred I) F :
(forall i, ~~ P i -> F i = x) ->
\big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_mkcond_idem; apply: eq_bigr => i.
by case: (P i) (F_eq1 i) => // ->.
Qed.
Lemma big_rmcond_in_idem (I : eqType) (r : seq I) (P : pred I) F :
(forall i, i \in r -> ~~ P i -> F i = x) ->
\big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_seq_cond [RHS]big_seq_cond !big_mkcondl_idem.
by rewrite big_rmcond_idem => // i /F_eq1; case: ifP => // _ ->.
Qed.
Lemma big_cat_idem I r1 r2 (P : pred I) F :
\big[op/x]_(i <- r1 ++ r2 | P i) F i =
op (\big[op/x]_(i <- r1 | P i) F i) (\big[op/x]_(i <- r2 | P i) F i).
Proof.
elim: r1 => [/=|i r1 IHr1]; first by rewrite big_nil opC big_id_idem.
by rewrite /= big_cons IHr1 big_cons; case: (P i); rewrite // opA.
Qed.
Lemma big_allpairs_dep_idem I1 (I2 : I1 -> Type) J (h : forall i1, I2 i1 -> J)
(r1 : seq I1) (r2 : forall i1, seq (I2 i1)) (F : J -> R) :
\big[op/x]_(i <- [seq h i1 i2 | i1 <- r1, i2 <- r2 i1]) F i =
\big[op/x]_(i1 <- r1) \big[op/x]_(i2 <- r2 i1) F (h i1 i2).
Proof.
elim: r1 => [|i1 r1 IHr1]; first by rewrite !big_nil.
by rewrite big_cat_idem IHr1 big_cons big_map.
Qed.
Lemma big_allpairs_idem I1 I2 (r1 : seq I1) (r2 : seq I2) F :
\big[op/x]_(i <- [seq (i1, i2) | i1 <- r1, i2 <- r2]) F i =
\big[op/x]_(i1 <- r1) \big[op/x]_(i2 <- r2) F (i1, i2).
Proof. exact: big_allpairs_dep_idem. Qed.
Lemma big_cat_nat_idem n m p (P : pred nat) F : m <= n -> n <= p ->
\big[op/x]_(m <= i < p | P i) F i =
op (\big[op/x]_(m <= i < n | P i) F i) (\big[op/x]_(n <= i < p | P i) F i).
Proof.
move=> le_mn le_np; rewrite -big_cat_idem -{2}(subnKC le_mn) -iotaD subnDA.
by rewrite subnKC // leq_sub.
Qed.
Lemma big_split_idem I r (P : pred I) F1 F2 :
\big[op/x]_(i <- r | P i) op (F1 i) (F2 i) =
op (\big[op/x]_(i <- r | P i) F1 i) (\big[op/x]_(i <- r | P i) F2 i).
Proof.
by elim/big_rec3: _ => [|i x' y _ _ ->]; rewrite ?opxx// opCA -!opA opCA.
Qed.
Lemma big_id_idem_AC I (r : seq I) P F :
\big[op/x]_(i <- r | P i) op (F i) x = \big[op/x]_(i <- r | P i) F i.
Proof. by rewrite big_split_idem big_const_idem ?big_id_idem. Qed.
Lemma bigID_idem I r (a P : pred I) F :
\big[op/x]_(i <- r | P i) F i =
op (\big[op/x]_(i <- r | P i && a i) F i)
(\big[op/x]_(i <- r | P i && ~~ a i) F i).
Proof.
rewrite -big_id_idem_AC big_mkcond_idem !(big_mkcond_idem _ _ F) -big_split_idem.
by apply: eq_bigr => i; case: ifPn => //=; case: ifPn; rewrite // opC.
Qed.
Arguments bigID_idem [I r].
Lemma bigU_idem (I : finType) (A B : pred I) F :
[disjoint A & B] ->
\big[op/x]_(i in [predU A & B]) F i =
op (\big[op/x]_(i in A) F i) (\big[op/x]_(i in B) F i).
Proof.
move=> dAB; rewrite (bigID_idem (mem A)).
congr (op : _ -> _); apply: eq_bigl => i; first by rewrite orbK.
by have:= pred0P dAB i; rewrite andbC /= !inE; case: (i \in A).
Qed.
Lemma partition_big_idem I (s : seq I)
(J : finType) (P : pred I) (p : I -> J) (Q : pred J) F :
(forall i, P i -> Q (p i)) ->
\big[op/x]_(i <- s | P i) F i =
\big[op/x]_(j : J | Q j) \big[op/x]_(i <- s | (P i) && (p i == j)) F i.
Proof.
move=> Qp; transitivity (\big[op/x]_(i <- s | P i && Q (p i)) F i).
by apply: eq_bigl => i; case Pi: (P i); rewrite // Qp.
have [n leQn] := ubnP #|Q|; elim: n => // n IHn in Q {Qp} leQn *.
case: (pickP Q) => [j Qj | Q0]; last first.
by rewrite !big_pred0 // => i; rewrite Q0 andbF.
rewrite (bigD1 j) // -IHn; last by rewrite ltnS (cardD1x j Qj) in leQn.
rewrite (bigID_idem (fun i => p i == j)).
congr (op : _ -> _); apply: eq_bigl => i; last by rewrite andbA.
by case: eqP => [->|_]; rewrite !(Qj, andbT, andbF).
Qed.
Arguments partition_big_idem [I s J P] p Q [F].
Lemma sig_big_dep_idem (I : finType) (J : I -> finType)
(P : pred I) (Q : forall {i}, pred (J i)) (F : forall {i}, J i -> R) :
\big[op/x]_(i | P i) \big[op/x]_(j : J i | Q j) F j =
\big[op/x]_(p : {i : I & J i} | P (tag p) && Q (tagged p)) F (tagged p).
Proof.
pose s := [seq Tagged J j | i <- index_enum I, j <- index_enum (J i)].
rewrite [LHS]big_mkcond_idem big_mkcondl_idem.
rewrite [RHS]big_mkcond_idem -[RHS](@perm_big _ s).
rewrite big_allpairs_dep_idem/=; apply: eq_bigr => i _.
by rewrite -big_mkcond_idem/=; case: P; rewrite // big1_idem.
rewrite uniq_perm ?index_enum_uniq//.
by rewrite allpairs_uniq_dep// => [|i|[i j] []]; rewrite ?index_enum_uniq.
by move=> [i j]; rewrite ?mem_index_enum; apply/allpairsPdep; exists i, j.
Qed.
Lemma pair_big_dep_idem (I J : finType) (P : pred I) (Q : I -> pred J) F :
\big[op/x]_(i | P i) \big[op/x]_(j | Q i j) F i j =
\big[op/x]_(p | P p.1 && Q p.1 p.2) F p.1 p.2.
Proof.
rewrite sig_big_dep_idem; apply: (reindex (fun x => Tagged (fun=> J) x.2)).
by exists (fun x => (projT1 x, projT2 x)) => -[].
Qed.
Lemma pair_big_idem (I J : finType) (P : pred I) (Q : pred J) F :
\big[op/x]_(i | P i) \big[op/x]_(j | Q j) F i j =
\big[op/x]_(p | P p.1 && Q p.2) F p.1 p.2.
Proof. exact: pair_big_dep_idem. Qed.
Lemma pair_bigA_idem (I J : finType) (F : I -> J -> R) :
\big[op/x]_i \big[op/x]_j F i j = \big[op/x]_p F p.1 p.2.
Proof. exact: pair_big_dep_idem. Qed.
Lemma exchange_big_dep_idem I J rI rJ (P : pred I) (Q : I -> pred J)
(xQ : pred J) F :
(forall i j, P i -> Q i j -> xQ j) ->
\big[op/x]_(i <- rI | P i) \big[op/x]_(j <- rJ | Q i j) F i j =
\big[op/x]_(j <- rJ | xQ j) \big[op/x]_(i <- rI | P i && Q i j) F i j.
Proof.
move=> PQxQ; pose p u := (u.2, u.1).
under [LHS]eq_bigr do rewrite big_tnth; rewrite [LHS]big_tnth.
under [RHS]eq_bigr do rewrite big_tnth; rewrite [RHS]big_tnth.
rewrite !pair_big_dep_idem (reindex_onto (p _ _) (p _ _)) => [|[]] //=.
apply: eq_big => [] [j i] //=; symmetry; rewrite eqxx andbT andb_idl //.
by case/andP; apply: PQxQ.
Qed.
Arguments exchange_big_dep_idem [I J rI rJ P Q] xQ [F].
Lemma exchange_big_idem I J rI rJ (P : pred I) (Q : pred J) F :
\big[op/x]_(i <- rI | P i) \big[op/x]_(j <- rJ | Q j) F i j =
\big[op/x]_(j <- rJ | Q j) \big[op/x]_(i <- rI | P i) F i j.
Proof.
rewrite (exchange_big_dep_idem Q) //.
by under eq_bigr => i Qi do under eq_bigl do rewrite Qi andbT.
Qed.
Lemma exchange_big_dep_nat_idem m1 n1 m2 n2 (P : pred nat) (Q : rel nat)
(xQ : pred nat) F :
(forall i j, m1 <= i < n1 -> m2 <= j < n2 -> P i -> Q i j -> xQ j) ->
\big[op/x]_(m1 <= i < n1 | P i) \big[op/x]_(m2 <= j < n2 | Q i j) F i j =
\big[op/x]_(m2 <= j < n2 | xQ j)
\big[op/x]_(m1 <= i < n1 | P i && Q i j) F i j.
Proof.
move=> PQxQ; under eq_bigr do rewrite big_seq_cond.
rewrite big_seq_cond /= (exchange_big_dep_idem xQ) => [|i j]; last first.
by rewrite !mem_index_iota => /andP[mn_i Pi] /andP[mn_j /PQxQ->].
rewrite 2!(big_seq_cond _ _ _ xQ); apply: eq_bigr => j /andP[-> _] /=.
by rewrite [rhs in _ = rhs]big_seq_cond; apply: eq_bigl => i; rewrite -andbA.
Qed.
Arguments exchange_big_dep_nat_idem [m1 n1 m2 n2 P Q] xQ [F].
Lemma exchange_big_nat_idem m1 n1 m2 n2 (P Q : pred nat) F :
\big[op/x]_(m1 <= i < n1 | P i) \big[op/x]_(m2 <= j < n2 | Q j) F i j =
\big[op/x]_(m2 <= j < n2 | Q j) \big[op/x]_(m1 <= i < n1 | P i) F i j.
Proof.
rewrite (exchange_big_dep_nat_idem Q) //.
by under eq_bigr => i Qi do under eq_bigl do rewrite Qi andbT.
Qed.
End Id.
End Abelian.
End SemiGroupProperties.
Arguments big_undup [R op x I].
Arguments perm_big [R op x I r1 r2].
Arguments bigD1 [R op x I] j [P F].
Arguments reindex_omap [R op x I J] h h' [P F].
Arguments reindex_onto [R op x I J] h h' [P F].
Arguments reindex [R op x I J] h [P F].
Arguments reindex_inj [R op x I h P F].
Arguments big_enum_val_cond [R op x I A] P F.
Arguments big_enum_rank_cond [R op x I A z] zA P F.
Section MonoidProperties.
Import Monoid.Theory.
Variable R : Type.
Variable idx : R.
Local Notation "1" := idx.
Section Plain.
Variable op : Monoid.law 1.
Local Notation "*%M" := op.
Local Notation "x * y" := (op x y).
Lemma foldlE x r : foldl *%M x r = \big[*%M/1]_(y <- x :: r) y.
Proof.
by rewrite -foldrE; elim: r => [|y r IHr]/= in x *; rewrite ?mulm1 ?mulmA ?IHr.
Qed.
Lemma foldl_idx r : foldl *%M 1 r = \big[*%M/1]_(x <- r) x.
Proof. by rewrite foldlE big_cons mul1m. Qed.
Lemma eq_big_idx_seq idx' I r (P : pred I) F :
right_id idx' *%M -> has P r ->
\big[*%M/idx']_(i <- r | P i) F i = \big[*%M/1]_(i <- r | P i) F i.
Proof.
move=> op_idx'; rewrite -!(big_filter _ _ r) has_count -size_filter.
case/lastP: (filter P r) => {r}// r i _.
by rewrite -cats1 !(big_cat_nested, big_cons, big_nil) op_idx' mulm1.
Qed.
Lemma eq_big_idx idx' (I : finType) i0 (P : pred I) F :
P i0 -> right_id idx' *%M ->
\big[*%M/idx']_(i | P i) F i = \big[*%M/1]_(i | P i) F i.
Proof.
by move=> Pi0 op_idx'; apply: eq_big_idx_seq => //; apply/hasP; exists i0.
Qed.
Lemma big_change_idx I x r (P : pred I) F :
\big[*%M/x]_(j <- r | P j) F j = (\big[*%M/1]_(j <- r | P j) F j) * x.
Proof.
elim: r => [|i r]; rewrite ?(big_nil, big_cons, mul1m)// => ->.
by case: ifP => // Pi; rewrite mulmA.
Qed.
Lemma big1_eq I r (P : pred I) : \big[*%M/1]_(i <- r | P i) 1 = 1.
Proof. by rewrite big1_idem //= mul1m. Qed.
Lemma big1 I r (P : pred I) F :
(forall i, P i -> F i = 1) -> \big[*%M/1]_(i <- r | P i) F i = 1.
Proof. by move/(eq_bigr _)->; apply: big1_eq. Qed.
Lemma big1_seq (I : eqType) r (P : pred I) F :
(forall i, P i && (i \in r) -> F i = 1) ->
\big[*%M/1]_(i <- r | P i) F i = 1.
Proof. by move=> eqF1; rewrite big_seq_cond big_andbC big1. Qed.
Lemma big_seq1 I (i : I) F : \big[*%M/1]_(j <- [:: i]) F j = F i.
Proof. by rewrite big_seq1_id mulm1. Qed.
Lemma big_rcons I i r (P : pred I) F :
\big[*%M/1]_(j <- rcons r i | P j) F j =
(\big[*%M/1]_(j <- r | P j) F j) * (if P i then F i else idx).
Proof. by rewrite big_rcons_op big_change_idx mulm1. Qed.
Lemma big_mkcond I r (P : pred I) F :
\big[*%M/1]_(i <- r | P i) F i =
\big[*%M/1]_(i <- r) (if P i then F i else 1).
Proof. by rewrite unlock; elim: r => //= i r ->; case P; rewrite ?mul1m. Qed.
Lemma big_mkcondr I r (P Q : pred I) F :
\big[*%M/1]_(i <- r | P i && Q i) F i =
\big[*%M/1]_(i <- r | P i) (if Q i then F i else 1).
Proof. by rewrite -big_filter_cond big_mkcond big_filter. Qed.
Lemma big_mkcondl I r (P Q : pred I) F :
\big[*%M/1]_(i <- r | P i && Q i) F i =
\big[*%M/1]_(i <- r | Q i) (if P i then F i else 1).
Proof. by rewrite big_andbC big_mkcondr. Qed.
Lemma big_rmcond I (r : seq I) (P : pred I) F :
(forall i, ~~ P i -> F i = 1) ->
\big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_mkcond; apply: eq_bigr => i.
by case: (P i) (F_eq1 i) => // ->.
Qed.
Lemma big_rmcond_in (I : eqType) (r : seq I) (P : pred I) F :
(forall i, i \in r -> ~~ P i -> F i = 1) ->
\big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_seq_cond [RHS]big_seq_cond !big_mkcondl big_rmcond//.
by move=> i /F_eq1; case: ifP => // _ ->.
Qed.
Lemma big_cat I r1 r2 (P : pred I) F :
\big[*%M/1]_(i <- r1 ++ r2 | P i) F i =
\big[*%M/1]_(i <- r1 | P i) F i * \big[*%M/1]_(i <- r2 | P i) F i.
Proof.
rewrite !(big_mkcond _ P) unlock.
by elim: r1 => /= [|i r1 ->]; rewrite (mul1m, mulmA).
Qed.
Lemma big_allpairs_dep I1 (I2 : I1 -> Type) J (h : forall i1, I2 i1 -> J)
(r1 : seq I1) (r2 : forall i1, seq (I2 i1)) (F : J -> R) :
\big[*%M/1]_(i <- [seq h i1 i2 | i1 <- r1, i2 <- r2 i1]) F i =
\big[*%M/1]_(i1 <- r1) \big[*%M/1]_(i2 <- r2 i1) F (h i1 i2).
Proof.
elim: r1 => [|i1 r1 IHr1]; first by rewrite !big_nil.
by rewrite big_cat IHr1 big_cons big_map.
Qed.
Lemma big_allpairs I1 I2 (r1 : seq I1) (r2 : seq I2) F :
\big[*%M/1]_(i <- [seq (i1, i2) | i1 <- r1, i2 <- r2]) F i =
\big[*%M/1]_(i1 <- r1) \big[op/idx]_(i2 <- r2) F (i1, i2).
Proof. exact: big_allpairs_dep. Qed.
Lemma rev_big_rev I (r : seq I) P F :
\big[*%M/1]_(i <- rev r | P i) F i =
\big[(fun x y => y * x)/1]_(i <- r | P i) F i.
Proof.
elim: r => [|i r IHr]; rewrite ?big_nil// big_cons rev_cons big_rcons IHr.
by case: (P i); rewrite ?mulm1.
Qed.
Lemma big_only1 (I : finType) (i : I) (P : pred I) (F : I -> R) : P i ->
(forall j, j != i -> P j -> F j = idx) ->
\big[op/idx]_(j | P j) F j = F i.
Proof.
move=> Pi Fisx; have := index_enum_uniq I.
have : i \in index_enum I by rewrite mem_index_enum.
elim: index_enum => //= j r IHr /[!inE]; case: eqVneq => [<-|nij]//=.
move=> _ /andP[iNr runiq]; rewrite big_cons/= Pi big1_seq ?Monoid.mulm1//.
by move=> {}j /andP[/Fisx + jr] => ->//; apply: contraNneq iNr => <-.
move=> ir /andP[jNr runiq]; rewrite big_cons IHr//.
by case: ifPn => // /Fisx->; rewrite 1?eq_sym// Monoid.mul1m.
Qed.
Lemma big_pred1_eq (I : finType) (i : I) F : \big[*%M/1]_(j | j == i) F j = F i.
Proof. by rewrite (@big_only1 _ i)// => j /negPf->. Qed.
Lemma big_pred1 (I : finType) i (P : pred I) F :
P =1 pred1 i -> \big[*%M/1]_(j | P j) F j = F i.
Proof. by move/(eq_bigl _ _)->; apply: big_pred1_eq. Qed.
Lemma big_ord1 F : \big[op/idx]_(i < 1) F i = F ord0.
Proof. by rewrite big_ord_recl big_ord0 Monoid.mulm1. Qed.
Lemma big_ord1_cond P F :
\big[op/idx]_(i < 1 | P i) F i = if P ord0 then F ord0 else idx.
Proof. by rewrite big_mkcond big_ord1. Qed.
Lemma big_ord1_eq (F : nat -> R) i n :
\big[op/idx]_(j < n | j == i :> nat) F j = if i < n then F i else idx.
Proof.
case: ltnP => [i_lt|i_ge]; first by rewrite (big_pred1_eq (Ordinal _)).
by rewrite big_pred0// => j; apply: contra_leqF i_ge => /eqP <-.
Qed.
Lemma big_ord1_cond_eq (F : nat -> R) (P : pred nat) i n :
\big[op/idx]_(j < n | P j && (j == i :> nat)) F j =
if (i < n) && P i then F i else idx.
Proof.
by rewrite big_mkcondl if_and (big_ord1_eq (fun j => if P j then F j else _)).
Qed.
Lemma big_cat_nat n m p (P : pred nat) F : m <= n -> n <= p ->
\big[*%M/1]_(m <= i < p | P i) F i =
(\big[*%M/1]_(m <= i < n | P i) F i) * (\big[*%M/1]_(n <= i < p | P i) F i).
Proof.
move=> le_mn le_np; rewrite -big_cat -{2}(subnKC le_mn) -iotaD subnDA.
by rewrite subnKC // leq_sub.
Qed.
Lemma big_nat_widenl (m1 m2 n : nat) (P : pred nat) F :
m2 <= m1 ->
\big[op/idx]_(m1 <= i < n | P i) F i =
\big[op/idx]_(m2 <= i < n | P i && (m1 <= i)) F i.
Proof.
move=> le_m21; have [le_nm1|lt_m1n] := leqP n m1.
rewrite big_geq// big_nat_cond big1//.
by move=> i /and3P[/andP[_ /leq_trans/(_ le_nm1)/ltn_geF->]].
rewrite big_mkcond big_mkcondl (big_cat_nat _ _ le_m21) 1?ltnW//.
rewrite [X in op X]big_nat_cond [X in op X]big_pred0; last first.
by move=> k; case: ltnP; rewrite andbF.
by rewrite Monoid.mul1m; apply: congr_big_nat => // k /andP[].
Qed.
Lemma big_geq_mkord (m n : nat) (P : pred nat) F :
\big[op/idx]_(m <= i < n | P i) F i =
\big[op/idx]_(i < n | P i && (m <= i)) F i.
Proof. by rewrite (@big_nat_widenl _ 0)// big_mkord. Qed.
Lemma big_nat1_eq (F : nat -> R) i m n :
\big[op/idx]_(m <= j < n | j == i) F j = if m <= i < n then F i else idx.
Proof. by rewrite big_geq_mkord big_andbC big_ord1_cond_eq andbC. Qed.
Lemma big_nat1_cond_eq (F : nat -> R) (P : pred nat) i m n :
\big[op/idx]_(m <= j < n | P j && (j == i)) F j =
if (m <= i < n) && P i then F i else idx.
Proof. by rewrite big_mkcondl big_nat1_eq -if_and. Qed.
Lemma big_nat1 n F : \big[*%M/1]_(n <= i < n.+1) F i = F n.
Proof. by rewrite big_ltn // big_geq // mulm1. Qed.
Lemma big_nat_recr n m F : m <= n ->
\big[*%M/1]_(m <= i < n.+1) F i = (\big[*%M/1]_(m <= i < n) F i) * F n.
Proof. by move=> lemn; rewrite (@big_cat_nat n) ?leqnSn // big_nat1. Qed.
Lemma big_nat_mul n k F :
\big[*%M/1]_(0 <= i < n * k) F i =
\big[*%M/1]_(0 <= i < n) \big[*%M/1]_(i * k <= j < i.+1 * k) F j.
Proof.
elim: n => [|n ih]; first by rewrite mul0n 2!big_nil.
rewrite [in RHS]big_nat_recr//= -ih mulSn addnC [in LHS]/index_iota subn0 iotaD.
rewrite big_cat /= [in X in _ = X * _]/index_iota subn0; congr (_ * _).
by rewrite add0n /index_iota (addnC _ k) addnK.
Qed.
Lemma big_ord_recr n F :
\big[*%M/1]_(i < n.+1) F i =
(\big[*%M/1]_(i < n) F (widen_ord (leqnSn n) i)) * F ord_max.
Proof.
transitivity (\big[*%M/1]_(0 <= i < n.+1) F (inord i)).
by rewrite big_mkord; apply: eq_bigr=> i _; rewrite inord_val.
rewrite big_nat_recr // big_mkord; congr (_ * F _); last first.
by apply: val_inj; rewrite /= inordK.
by apply: eq_bigr => [] i _; congr F; apply: ord_inj; rewrite inordK //= leqW.
Qed.
Lemma big_sumType (I1 I2 : finType) (P : pred (I1 + I2)) F :
\big[*%M/1]_(i | P i) F i =
(\big[*%M/1]_(i | P (inl _ i)) F (inl _ i))
* (\big[*%M/1]_(i | P (inr _ i)) F (inr _ i)).
Proof.
by rewrite ![index_enum _]unlock [@Finite.enum in LHS]unlock/= big_cat !big_map.
Qed.
Lemma big_split_ord m n (P : pred 'I_(m + n)) F :
\big[*%M/1]_(i | P i) F i =
(\big[*%M/1]_(i | P (lshift n i)) F (lshift n i))
* (\big[*%M/1]_(i | P (rshift m i)) F (rshift m i)).
Proof.
rewrite -(big_map _ _ (lshift n) _ P F) -(big_map _ _ (@rshift m _) _ P F).
rewrite -big_cat; congr bigop; apply: (inj_map val_inj).
rewrite map_cat -!map_comp (map_comp (addn m)) /=.
by rewrite ![index_enum _]unlock unlock !val_ord_enum -iotaDl addn0 iotaD.
Qed.
Lemma big_flatten I rr (P : pred I) F :
\big[*%M/1]_(i <- flatten rr | P i) F i
= \big[*%M/1]_(r <- rr) \big[*%M/1]_(i <- r | P i) F i.
Proof.
by elim: rr => [|r rr IHrr]; rewrite ?big_nil //= big_cat big_cons -IHrr.
Qed.
Lemma big_pmap J I (h : J -> option I) (r : seq J) F :
\big[op/idx]_(i <- pmap h r) F i = \big[op/idx]_(j <- r) oapp F idx (h j).
Proof.
elim: r => [| r0 r IHr]/=; first by rewrite !big_nil.
rewrite /= big_cons; case: (h r0) => [i|] /=; last by rewrite mul1m.
by rewrite big_cons IHr.
Qed.
Lemma telescope_big (f : nat -> nat -> R) (n m : nat) :
(forall k, n < k < m -> op (f n k) (f k k.+1) = f n k.+1) ->
\big[op/idx]_(n <= i < m) f i i.+1 = if n < m then f n m else idx.
Proof.
elim: m => [//| m IHm]; first by rewrite ltn0 big_geq.
move=> tm; rewrite ltnS; case: ltnP=> // mn; first by rewrite big_geq.
rewrite big_nat_recr// IHm//; last first.
by move=> k /andP[nk /ltnW nm]; rewrite tm// nk.
by case: ltngtP mn=> //= [nm|<-]; rewrite ?mul1m// tm// nm leqnn.
Qed.
End Plain.
Section Abelian.
Variable op : Monoid.com_law 1.
Local Notation "'*%M'" := op.
Local Notation "x * y" := (op x y).
Lemma big_rem (I : eqType) r x (P : pred I) F :
x \in r ->
\big[*%M/1]_(y <- r | P y) F y
= (if P x then F x else 1) * \big[*%M/1]_(y <- rem x r | P y) F y.
Proof.
by move/perm_to_rem/(perm_big _)->; rewrite !(big_mkcond _ _ P) big_cons.
Qed.
Lemma big_rev I (r : seq I) P F :
\big[*%M/1]_(i <- rev r | P i) F i = \big[*%M/1]_(i <- r | P i) F i.
Proof.
by rewrite rev_big_rev; apply: (eq_big_op (fun=> True)) => // *; apply: mulmC.
Qed.
Lemma eq_big_idem (I : eqType) (r1 r2 : seq I) (P : pred I) F :
idempotent_op *%M -> r1 =i r2 ->
\big[*%M/1]_(i <- r1 | P i) F i = \big[*%M/1]_(i <- r2 | P i) F i.
Proof.
move=> idM eq_r; rewrite -big_undup // -(big_undup r2) //; apply/perm_big.
by rewrite uniq_perm ?undup_uniq // => i; rewrite !mem_undup eq_r.
Qed.
Lemma big_undup_iterop_count (I : eqType) (r : seq I) (P : pred I) F :
\big[*%M/1]_(i <- undup r | P i) iterop (count_mem i r) *%M (F i) 1
= \big[*%M/1]_(i <- r | P i) F i.
Proof.
rewrite -[RHS](perm_big _ F (perm_count_undup _)) big_flatten big_map.
by rewrite [LHS]big_mkcond; apply: eq_bigr=> i _; rewrite big_nseq_cond iteropE.
Qed.
Lemma big_split I r (P : pred I) F1 F2 :
\big[*%M/1]_(i <- r | P i) (F1 i * F2 i) =
\big[*%M/1]_(i <- r | P i) F1 i * \big[*%M/1]_(i <- r | P i) F2 i.
Proof. exact/big_split_idem/mul1m. Qed.
Lemma bigID I r (a P : pred I) F :
\big[*%M/1]_(i <- r | P i) F i =
\big[*%M/1]_(i <- r | P i && a i) F i *
\big[*%M/1]_(i <- r | P i && ~~ a i) F i.
Proof. exact/bigID_idem/mul1m. Qed.
Arguments bigID [I r].
Lemma big_if I r (P Q : pred I) F G :
\big[*%M/1]_(i <- r | P i) (if Q i then F i else G i) =
\big[*%M/1]_(i <- r | P i && Q i) F i *
\big[*%M/1]_(i <- r | P i && ~~ Q i) G i.
Proof.
rewrite (bigID Q); congr (_ * _); apply: eq_bigr => i /andP[_].
by move=> ->.
by move=> /negPf ->.
Qed.
Lemma bigU (I : finType) (A B : pred I) F :
[disjoint A & B] ->
\big[*%M/1]_(i in [predU A & B]) F i =
(\big[*%M/1]_(i in A) F i) * (\big[*%M/1]_(i in B) F i).
Proof. exact/bigU_idem/mul1m. Qed.
Lemma partition_big I (s : seq I)
(J : finType) (P : pred I) (p : I -> J) (Q : pred J) F :
(forall i, P i -> Q (p i)) ->
\big[*%M/1]_(i <- s | P i) F i =
\big[*%M/1]_(j : J | Q j) \big[*%M/1]_(i <- s | (P i) && (p i == j)) F i.
Proof.
move=> Qp; transitivity (\big[*%M/1]_(i <- s | P i && Q (p i)) F i).
by apply: eq_bigl => i; case Pi: (P i); rewrite // Qp.
have [n leQn] := ubnP #|Q|; elim: n => // n IHn in Q {Qp} leQn *.
case: (pickP Q) => [j Qj | Q0]; last first.
by rewrite !big_pred0 // => i; rewrite Q0 andbF.
rewrite (bigD1 j) // -IHn; last by rewrite ltnS (cardD1x Qj) in leQn.
rewrite (bigID (fun i => p i == j)); congr (_ * _); apply: eq_bigl => i.
by case: eqP => [-> | _]; rewrite !(Qj, simpm).
by rewrite andbA.
Qed.
Arguments partition_big [I s J P] p Q [F].
Lemma big_enum_val (I : finType) (A : pred I) F :
\big[op/idx]_(x in A) F x = \big[op/idx]_(i < #|A|) F (enum_val i).
Proof. by rewrite -(big_enum_val_cond predT) big_mkcondr. Qed.
Arguments big_enum_val [I A] F.
Lemma big_enum_rank (I : finType) (A : pred I) x (xA : x \in A) F
(h := enum_rank_in xA) :
\big[op/idx]_(i < #|A|) F i = \big[op/idx]_(s in A) F (h s).
Proof. by rewrite (big_enum_rank_cond xA) big_mkcondr. Qed.
Arguments big_enum_rank [I A x] xA F.
Lemma big_sub_cond (I : finType) (A P : {pred I}) (F : I -> R) :
\big[*%M/1]_(i in A | P i) F i =
\big[*%M/1]_(x : {x in A} | P (val x)) F (val x).
Proof.
rewrite (reindex_omap (val : {x in A} -> I) insub); last first.
by move=> i /andP[iA Pi]; rewrite insubT.
by apply: eq_bigl=> -[i iA]/=; rewrite insubT ?iA /= eqxx andbT.
Qed.
Lemma big_sub (I : finType) (A : {pred I}) (F : I -> R) :
\big[*%M/1]_(i in A) F i = \big[*%M/1]_(x : {x in A}) F (val x).
Proof. by rewrite -(big_sub_cond A xpredT) big_mkcondr. Qed.
Lemma sig_big_dep (I : finType) (J : I -> finType)
(P : pred I) (Q : forall {i}, pred (J i)) (F : forall {i}, J i -> R) :
\big[op/idx]_(i | P i) \big[op/idx]_(j : J i | Q j) F j =
\big[op/idx]_(p : {i : I & J i} | P (tag p) && Q (tagged p)) F (tagged p).
Proof. exact/sig_big_dep_idem/mul1m. Qed.
Lemma pair_big_dep (I J : finType) (P : pred I) (Q : I -> pred J) F :
\big[*%M/1]_(i | P i) \big[*%M/1]_(j | Q i j) F i j =
\big[*%M/1]_(p | P p.1 && Q p.1 p.2) F p.1 p.2.
Proof. exact/pair_big_dep_idem/mul1m. Qed.
Lemma pair_big (I J : finType) (P : pred I) (Q : pred J) F :
\big[*%M/1]_(i | P i) \big[*%M/1]_(j | Q j) F i j =
\big[*%M/1]_(p | P p.1 && Q p.2) F p.1 p.2.
Proof. exact/pair_big_idem/mul1m. Qed.
Lemma pair_bigA (I J : finType) (F : I -> J -> R) :
\big[*%M/1]_i \big[*%M/1]_j F i j = \big[*%M/1]_p F p.1 p.2.
Proof. exact/pair_bigA_idem/mul1m. Qed.
Lemma exchange_big_dep I J rI rJ (P : pred I) (Q : I -> pred J)
(xQ : pred J) F :
(forall i j, P i -> Q i j -> xQ j) ->
\big[*%M/1]_(i <- rI | P i) \big[*%M/1]_(j <- rJ | Q i j) F i j =
\big[*%M/1]_(j <- rJ | xQ j) \big[*%M/1]_(i <- rI | P i && Q i j) F i j.
Proof. exact/exchange_big_dep_idem/mul1m. Qed.
Arguments exchange_big_dep [I J rI rJ P Q] xQ [F].
Lemma exchange_big I J rI rJ (P : pred I) (Q : pred J) F :
\big[*%M/1]_(i <- rI | P i) \big[*%M/1]_(j <- rJ | Q j) F i j =
\big[*%M/1]_(j <- rJ | Q j) \big[*%M/1]_(i <- rI | P i) F i j.
Proof. exact/exchange_big_idem/mul1m. Qed.
Lemma exchange_big_dep_nat m1 n1 m2 n2 (P : pred nat) (Q : rel nat)
(xQ : pred nat) F :
(forall i j, m1 <= i < n1 -> m2 <= j < n2 -> P i -> Q i j -> xQ j) ->
\big[*%M/1]_(m1 <= i < n1 | P i) \big[*%M/1]_(m2 <= j < n2 | Q i j) F i j =
\big[*%M/1]_(m2 <= j < n2 | xQ j)
\big[*%M/1]_(m1 <= i < n1 | P i && Q i j) F i j.
Proof. exact/exchange_big_dep_nat_idem/mul1m. Qed.
Arguments exchange_big_dep_nat [m1 n1 m2 n2 P Q] xQ [F].
Lemma exchange_big_nat m1 n1 m2 n2 (P Q : pred nat) F :
\big[*%M/1]_(m1 <= i < n1 | P i) \big[*%M/1]_(m2 <= j < n2 | Q j) F i j =
\big[*%M/1]_(m2 <= j < n2 | Q j) \big[*%M/1]_(m1 <= i < n1 | P i) F i j.
Proof. exact/exchange_big_nat_idem/mul1m. Qed.
End Abelian.
End MonoidProperties.
Arguments big_filter [R idx op I].
Arguments big_filter_cond [R idx op I].
Arguments congr_big [R idx op I r1] r2 [P1] P2 [F1] F2.
Arguments eq_big [R idx op I r P1] P2 [F1] F2.
Arguments eq_bigl [R idx op I r P1] P2.
Arguments eq_bigr [R idx op I r P F1] F2.
Arguments eq_big_idx [R idx op idx' I] i0 [P F].
Arguments big_seq_cond [R idx op I r].
Arguments eq_big_seq [R idx op I r F1] F2.
Arguments congr_big_nat [R idx op m1 n1] m2 n2 [P1] P2 [F1] F2.
Arguments big_map [R idx op I J] h [r].
Arguments big_nth [R idx op I] x0 [r].
Arguments big_catl [R idx op I r1 r2 P F].
Arguments big_catr [R idx op I r1 r2 P F].
Arguments big_geq [R idx op m n P F].
Arguments big_ltn_cond [R idx op m n P F].
Arguments big_ltn [R idx op m n F].
Arguments big_addn [R idx op].
Arguments big_mkord [R idx op n].
Arguments big_nat_widen [R idx op].
Arguments big_nat_widenl [R idx op].
Arguments big_geq_mkord [R idx op].
Arguments big_ord_widen_cond [R idx op n1].
Arguments big_ord_widen [R idx op n1].
Arguments big_ord_widen_leq [R idx op n1].
Arguments big_ord_narrow_cond [R idx op n1 n2 P F].
Arguments big_ord_narrow_cond_leq [R idx op n1 n2 P F].
Arguments big_ord_narrow [R idx op n1 n2 F].
Arguments big_ord_narrow_leq [R idx op n1 n2 F].
Arguments big_mkcond [R idx op I r].
Arguments big1_eq [R idx op I].
Arguments big1_seq [R idx op I].
Arguments big1 [R idx op I].
Arguments big_only1 {R idx op I} i [P F].
Arguments big_pred1 [R idx op I] i [P F].
Arguments perm_big [R op x I r1] r2 [P F].
Arguments big_uniq [R op x I] r [F].
Arguments big_rem [R idx op I r] x [P F].
Arguments bigID [R idx op I r].
Arguments bigU [R idx op I].
Arguments bigD1 [R op x I] j [P F].
Arguments bigD1_seq [R op x I r] j [F].
Arguments bigD1_ord [R op x n] j [P F].
Arguments partition_big [R idx op I s J P] p Q [F].
Arguments reindex_omap [R op x I J] h h' [P F].
Arguments reindex_onto [R op x I J] h h' [P F].
Arguments reindex [R op x I J] h [P F].
Arguments reindex_inj [R op x I h P F].
Arguments big_enum_val_cond [R op x I A] P F.
Arguments big_enum_rank_cond [R op x I A z] zA P F.
Arguments big_enum_val [R idx op I A] F.
Arguments big_enum_rank [R idx op I A x] xA F.
Arguments big_sub_cond [R idx op I].
Arguments big_sub [R idx op I].
Arguments sig_big_dep [R idx op I J].
Arguments pair_big_dep [R idx op I J].
Arguments pair_big [R idx op I J].
Arguments big_allpairs_dep {R idx op I1 I2 J h r1 r2 F}.
Arguments big_allpairs {R idx op I1 I2 r1 r2 F}.
Arguments exchange_big_dep [R idx op I J rI rJ P Q] xQ [F].
Arguments exchange_big_dep_nat [R idx op m1 n1 m2 n2 P Q] xQ [F].
Arguments big_ord_recl [R idx op].
Arguments big_ord_recr [R idx op].
Arguments big_nat_recl [R idx op].
Arguments big_nat_recr [R idx op].
Arguments big_cat_nat_idem [R op x] opxx [n m p P F].
Arguments big_cat_nat [R idx op n m p P F].
Arguments big_pmap [R idx op J I] h [r].
Arguments telescope_big [R idx op] f [n m].
Section IncreasingSemiGroup.
Variables (R : Type) (op : SemiGroup.com_law R).
Variable le : rel R.
Hypothesis le_refl : reflexive le.
Hypothesis op_incr : forall x y, le x (op x y).
Context [x : R].
Local Notation opA := SemiGroup.opA.
Local Notation opC := SemiGroup.opC.
Lemma sub_le_big I [s] (P P' : {pred I}) (F : I -> R) :
(forall i, P i -> P' i) ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s | P' i) F i).
Proof.
move=> PP'; rewrite [X in le _ X](big_AC_mk_monoid opA opC) (bigID P P') /=.
under [in X in le _ X]eq_bigl do rewrite (andb_idl (PP' _)).
rewrite [X in le X _](big_AC_mk_monoid opA opC).
case: (bigop _ _ _) (bigop _ _ _) => [y|] [z|]//=.
by rewrite -opA [_ y x]opC opA op_incr.
by rewrite opC op_incr.
Qed.
Lemma sub_le_big_seq (I : eqType) s s' P (F : I -> R) :
(forall i, count_mem i s <= count_mem i s')%N ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i).
Proof.
rewrite (big_AC_mk_monoid opA opC) => /count_subseqP[_ /subseqP[m sm ->]].
move/(perm_big _)->; rewrite big_mask [X in le _ X]big_tnth.
by rewrite -!(big_AC_mk_monoid opA opC) sub_le_big // => j /andP[].
Qed.
Lemma sub_le_big_seq_cond (I : eqType) s s' P P' (F : I -> R) :
(forall i, count_mem i (filter P s) <= count_mem i (filter P' s'))%N ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i).
Proof. by move=> /(sub_le_big_seq xpredT F); rewrite !big_filter. Qed.
Lemma uniq_sub_le_big (I : eqType) s s' P (F : I -> R) : uniq s -> uniq s' ->
{subset s <= s'} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i).
Proof.
move=> us us' ss'; rewrite sub_le_big_seq => // i; rewrite !count_uniq_mem//.
by have /implyP := ss' i; case: (_ \in s) (_ \in s') => [] [].
Qed.
Lemma uniq_sub_le_big_cond (I : eqType) s s' P P' (F : I -> R) :
uniq (filter P s) -> uniq (filter P' s') ->
{subset [seq i <- s | P i] <= [seq i <- s' | P' i]} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i).
Proof. by move=> u v /(uniq_sub_le_big xpredT F u v); rewrite !big_filter. Qed.
Section Id.
Hypothesis opK : idempotent_op op.
Lemma idem_sub_le_big (I : eqType) s s' P (F : I -> R) :
{subset s <= s'} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i).
Proof.
move=> ss'; rewrite -big_undup// -[X in le _ X]big_undup//.
by rewrite uniq_sub_le_big ?undup_uniq// => i; rewrite !mem_undup; apply: ss'.
Qed.
Lemma idem_sub_le_big_cond (I : eqType) s s' P P' (F : I -> R) :
{subset [seq i <- s | P i] <= [seq i <- s' | P' i]} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i).
Proof. by move=> /(idem_sub_le_big xpredT F); rewrite !big_filter. Qed.
End Id.
Lemma sub_in_le_big [I : eqType] (s : seq I) (P P' : {pred I}) (F : I -> R) :
{in s, forall i, P i -> P' i} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s | P' i) F i).
Proof.
move=> PP'; apply: sub_le_big_seq_cond => i; rewrite leq_count_subseq//.
rewrite subseq_filter filter_subseq andbT; apply/allP => j.
by rewrite !mem_filter => /andP[/PP'/[apply]->].
Qed.
Lemma le_big_ord n m [P : {pred nat}] [F : nat -> R] : (n <= m)%N ->
le (\big[op/x]_(i < n | P i) F i) (\big[op/x]_(i < m | P i) F i).
Proof.
by move=> nm; rewrite (big_ord_widen_cond m)// sub_le_big => //= ? /andP[].
Qed.
Lemma subset_le_big [I : finType] [A A' P : {pred I}] (F : I -> R) :
A \subset A' ->
le (\big[op/x]_(i in A | P i) F i) (\big[op/x]_(i in A' | P i) F i).
Proof.
move=> AA'; apply: sub_le_big => y /andP[yA yP]; apply/andP; split => //.
exact: subsetP yA.
Qed.
Lemma le_big_nat_cond n m n' m' (P P' : {pred nat}) (F : nat -> R) :
(n' <= n)%N -> (m <= m')%N -> (forall i, (n <= i < m)%N -> P i -> P' i) ->
le (\big[op/x]_(n <= i < m | P i) F i) (\big[op/x]_(n' <= i < m' | P' i) F i).
Proof.
move=> len'n lemm' PP'i; rewrite uniq_sub_le_big_cond ?filter_uniq ?iota_uniq//.
move=> i; rewrite !mem_filter !mem_index_iota => /and3P[Pi ni im].
by rewrite PP'i ?ni//= (leq_trans _ ni)// (leq_trans im).
Qed.
Lemma le_big_nat n m n' m' [P] [F : nat -> R] : (n' <= n)%N -> (m <= m')%N ->
le (\big[op/x]_(n <= i < m | P i) F i) (\big[op/x]_(n' <= i < m' | P i) F i).
Proof. by move=> len'n lemm'; rewrite le_big_nat_cond. Qed.
Lemma le_big_ord_cond n m (P P' : {pred nat}) (F : nat -> R) :
(n <= m)%N -> (forall i : 'I_n, P i -> P' i) ->
le (\big[op/x]_(i < n | P i) F i) (\big[op/x]_(i < m | P' i) F i).
Proof.
move=> nm PP'; rewrite -!big_mkord le_big_nat_cond//= => i ni.
by have := PP' (Ordinal ni).
Qed.
End IncreasingSemiGroup.
Section EqSupport.
Variables (R : eqType) (idx : R).
Section MonoidSupport.
Variables (op : Monoid.law idx) (I : Type).
Lemma eq_bigl_supp (r : seq I) (P1 : pred I) (P2 : pred I) (F : I -> R) :
{in [pred x | F x != idx], P1 =1 P2} ->
\big[op/idx]_(i <- r | P1 i) F i = \big[op/idx]_(i <- r | P2 i) F i.
Proof.
move=> P12; rewrite big_mkcond [RHS]big_mkcond; apply: eq_bigr => i _.
by case: (eqVneq (F i) idx) => [->|/P12->]; rewrite ?if_same.
Qed.
End MonoidSupport.
Section ComoidSupport.
Variables (op : Monoid.com_law idx) (I : eqType).
Lemma perm_big_supp_cond [r s : seq I] [P : pred I] (F : I -> R) :
perm_eq
[seq i <- r | P i && (F i != idx)]
[seq i <- s | P i && (F i != idx)] ->
\big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i <- s | P i) F i.
Proof.
move=> prs; rewrite !(bigID [pred i | F i == idx] P F)/=.
rewrite big1 ?Monoid.mul1m; last by move=> i /andP[_ /eqP->].
rewrite [in RHS]big1 ?Monoid.mul1m; last by move=> i /andP[_ /eqP->].
by rewrite -[in LHS]big_filter -[in RHS]big_filter; apply perm_big.
Qed.
Lemma perm_big_supp [r s : seq I] [P : pred I] (F : I -> R) :
perm_eq [seq i <- r | F i != idx] [seq i <- s | F i != idx] ->
\big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i <- s | P i) F i.
Proof.
by move=> ?; apply: perm_big_supp_cond; rewrite !filter_predI perm_filter.
Qed.
End ComoidSupport.
End EqSupport.
Arguments eq_bigl_supp [R idx op I r P1].
Arguments perm_big_supp_cond [R idx op I r s P].
Arguments perm_big_supp [R idx op I r s P].
Section Distributivity.
Import Monoid.Theory.
Variable R : Type.
Variables zero one : R.
Local Notation "0" := zero.
Local Notation "1" := one.
Variable times : Monoid.mul_law 0.
Local Notation "*%M" := times.
Local Notation "x * y" := (times x y).
Variable plus : Monoid.add_law 0 *%M.
Local Notation "+%M" := plus.
Local Notation "x + y" := (plus x y).
Lemma big_distrl I r a (P : pred I) F :
\big[+%M/0]_(i <- r | P i) F i * a = \big[+%M/0]_(i <- r | P i) (F i * a).
Proof. by rewrite (big_endo ( *%M^~ a)) ?mul0m // => x y; apply: mulmDl. Qed.
Lemma big_distrr I r a (P : pred I) F :
a * \big[+%M/0]_(i <- r | P i) F i = \big[+%M/0]_(i <- r | P i) (a * F i).
Proof. by rewrite big_endo ?mulm0 // => x y; apply: mulmDr. Qed.
Lemma big_distrlr I J rI rJ (pI : pred I) (pJ : pred J) F G :
(\big[+%M/0]_(i <- rI | pI i) F i) * (\big[+%M/0]_(j <- rJ | pJ j) G j)
= \big[+%M/0]_(i <- rI | pI i) \big[+%M/0]_(j <- rJ | pJ j) (F i * G j).
Proof. by rewrite big_distrl; under eq_bigr do rewrite big_distrr. Qed.
Lemma big_distr_big_dep (I J : finType) j0 (P : pred I) (Q : I -> pred J) F :
\big[*%M/1]_(i | P i) \big[+%M/0]_(j | Q i j) F i j =
\big[+%M/0]_(f in pfamily j0 P Q) \big[*%M/1]_(i | P i) F i (f i).
Proof.
pose fIJ := {ffun I -> J}; pose Pf := pfamily j0 (_ : seq I) Q.
have [r big_r [Ur mem_r] _] := big_enumP P.
symmetry; transitivity (\big[+%M/0]_(f in Pf r) \big[*%M/1]_(i <- r) F i (f i)).
by apply: eq_big => // f; apply: eq_forallb => i; rewrite /= mem_r.
rewrite -{P mem_r}big_r; elim: r Ur => /= [_ | i r IHr].
rewrite (big_pred1 [ffun=> j0]) ?big_nil //= => f.
apply/familyP/eqP=> /= [Df |->{f} i]; last by rewrite ffunE !inE.
by apply/ffunP=> i; rewrite ffunE; apply/eqP/Df.
case/andP=> /negbTE nri; rewrite big_cons big_distrl => {}/IHr<-.
rewrite (partition_big (fun f : fIJ => f i) (Q i)) => [|f]; last first.
by move/familyP/(_ i); rewrite /= inE /= eqxx.
pose seti j (f : fIJ) := [ffun k => if k == i then j else f k].
apply: eq_bigr => j Qij.
rewrite (reindex_onto (seti j) (seti j0)) => [|f /andP[_ /eqP fi]]; last first.
by apply/ffunP=> k; rewrite !ffunE; case: eqP => // ->.
rewrite big_distrr; apply: eq_big => [f | f eq_f]; last first.
rewrite big_cons ffunE eqxx !big_seq; congr (_ * _).
by apply: eq_bigr => k; rewrite ffunE; case: eqP nri => // -> ->.
rewrite !ffunE !eqxx andbT; apply/andP/familyP=> /= [[Pjf fij0] k | Pff].
have /[!(ffunE, inE)] := familyP Pjf k; case: eqP => // -> _.
by rewrite nri -(eqP fij0) !ffunE !inE !eqxx.
(split; [apply/familyP | apply/eqP/ffunP]) => k; have /[!(ffunE, inE)]:= Pff k.
by case: eqP => // ->.
by case: eqP => // ->; rewrite nri /= => /eqP.
Qed.
Lemma big_distr_big (I J : finType) j0 (P : pred I) (Q : pred J) F :
\big[*%M/1]_(i | P i) \big[+%M/0]_(j | Q j) F i j =
\big[+%M/0]_(f in pffun_on j0 P Q) \big[*%M/1]_(i | P i) F i (f i).
Proof.
rewrite (big_distr_big_dep j0); apply: eq_bigl => f.
by apply/familyP/familyP=> Pf i; case: ifP (Pf i).
Qed.
Lemma bigA_distr_big_dep (I J : finType) (Q : I -> pred J) F :
\big[*%M/1]_i \big[+%M/0]_(j | Q i j) F i j
= \big[+%M/0]_(f in family Q) \big[*%M/1]_i F i (f i).
Proof.
have [j _ | J0] := pickP J; first by rewrite (big_distr_big_dep j).
have Q0 i: Q i =i pred0 by move=> /J0/esym/notF[].
transitivity (iter #|I| ( *%M 0) 1).
by rewrite -big_const; apply/eq_bigr=> i; have /(big_pred0 _)-> := Q0 i.
have [i _ | I0] := pickP I.
rewrite (cardD1 i) //= mul0m big_pred0 // => f.
by apply/familyP=> /(_ i); rewrite Q0.
have f: I -> J by move=> /I0/esym/notF[].
rewrite eq_card0 // (big_pred1 (finfun f)) ?big_pred0 // => g.
by apply/familyP/eqP=> _; first apply/ffunP; move=> /I0/esym/notF[].
Qed.
Lemma bigA_distr_big (I J : finType) (Q : pred J) (F : I -> J -> R) :
\big[*%M/1]_i \big[+%M/0]_(j | Q j) F i j
= \big[+%M/0]_(f in ffun_on Q) \big[*%M/1]_i F i (f i).
Proof. exact: bigA_distr_big_dep. Qed.
Lemma bigA_distr_bigA (I J : finType) F :
\big[*%M/1]_(i : I) \big[+%M/0]_(j : J) F i j
= \big[+%M/0]_(f : {ffun I -> J}) \big[*%M/1]_i F i (f i).
Proof. by rewrite bigA_distr_big; apply: eq_bigl => ?; apply/familyP. Qed.
End Distributivity.
Arguments big_distrl [R zero times plus I r].
Arguments big_distrr [R zero times plus I r].
Arguments big_distr_big_dep [R zero one times plus I J].
Arguments big_distr_big [R zero one times plus I J].
Arguments bigA_distr_big_dep [R zero one times plus I J].
Arguments bigA_distr_big [R zero one times plus I J].
Arguments bigA_distr_bigA [R zero one times plus I J].
Section BigBool.
Section Seq.
Variables (I : Type) (r : seq I) (P B : pred I).
Lemma big_has : \big[orb/false]_(i <- r) B i = has B r.
Proof. by rewrite unlock. Qed.
Lemma big_all : \big[andb/true]_(i <- r) B i = all B r.
Proof. by rewrite unlock. Qed.
Lemma big_has_cond : \big[orb/false]_(i <- r | P i) B i = has (predI P B) r.
Proof. by rewrite big_mkcond unlock. Qed.
Lemma big_all_cond :
\big[andb/true]_(i <- r | P i) B i = all [pred i | P i ==> B i] r.
Proof. by rewrite big_mkcond unlock. Qed.
Lemma big_bool R (idx : R) (op : Monoid.com_law idx) (F : bool -> R):
\big[op/idx]_(i : bool) F i = op (F true) (F false).
Proof. by rewrite /index_enum !unlock /= Monoid.mulm1. Qed.
End Seq.
Section FinType.
Variables (I : finType) (P B : pred I).
Lemma big_orE : \big[orb/false]_(i | P i) B i = [exists (i | P i), B i].
Proof. by rewrite big_has_cond; apply/hasP/existsP=> [] [i]; exists i. Qed.
Lemma big_andE : \big[andb/true]_(i | P i) B i = [forall (i | P i), B i].
Proof.
rewrite big_all_cond; apply/allP/forallP=> /= allB i; rewrite allB //.
exact: mem_index_enum.
Qed.
End FinType.
End BigBool.
Section NatConst.
Variables (I : finType) (A : pred I).
Lemma sum_nat_const n : \sum_(i in A) n = #|A| * n.
Proof. by rewrite big_const iter_addn_0 mulnC. Qed.
Lemma sum1_card : \sum_(i in A) 1 = #|A|.
Proof. by rewrite sum_nat_const muln1. Qed.
Lemma sum1_count J (r : seq J) (a : pred J) : \sum_(j <- r | a j) 1 = count a r.
Proof. by rewrite big_const_seq iter_addn_0 mul1n. Qed.
Lemma sum1_size J (r : seq J) : \sum_(j <- r) 1 = size r.
Proof. by rewrite sum1_count count_predT. Qed.
Lemma prod_nat_const n : \prod_(i in A) n = n ^ #|A|.
Proof. by rewrite big_const -Monoid.iteropE. Qed.
Lemma sum_nat_const_nat n1 n2 n : \sum_(n1 <= i < n2) n = (n2 - n1) * n.
Proof. by rewrite big_const_nat iter_addn_0 mulnC. Qed.
Lemma prod_nat_const_nat n1 n2 n : \prod_(n1 <= i < n2) n = n ^ (n2 - n1).
Proof. by rewrite big_const_nat -Monoid.iteropE. Qed.
End NatConst.
Lemma telescope_sumn_in n m f : n <= m ->
(forall i, n <= i < m -> f i <= f i.+1) ->
\sum_(n <= k < m) (f k.+1 - f k) = f m - f n.
Proof.
move=> nm fle; rewrite (telescope_big (fun i j => f j - f i)).
by case: ltngtP nm => // ->; rewrite subnn.
move=> k /andP[nk km]; rewrite /= addnBAC ?subnKC ?fle ?(ltnW nk)//.
elim: k nk km => [//| k IHk /[!ltnS]/[1!leq_eqVlt]+ km].
move=> /predU1P[/[dup]nk -> | nk]; first by rewrite fle ?nk ?leqnn 1?ltnW.
by rewrite (leq_trans (IHk _ _) (fle _ _))// ltnW// ltnW.
Qed.
Lemma telescope_sumn n m f : {homo f : x y / x <= y} ->
\sum_(n <= k < m) (f k.+1 - f k) = f m - f n.
Proof.
move=> fle; case: (ltnP n m) => nm.
by apply: (telescope_sumn_in (ltnW nm)) => ? ?; apply: fle.
by apply/esym/eqP; rewrite big_geq// subn_eq0 fle.
Qed.
Lemma sumnE r : sumn r = \sum_(i <- r) i. Proof. exact: foldrE. Qed.
Lemma card_bseq n (T : finType) : #|{bseq n of T}| = \sum_(i < n.+1) #|T| ^ i.
Proof.
rewrite (bij_eq_card bseq_tagged_tuple_bij) card_tagged sumnE big_map big_enum.
by under eq_bigr do rewrite card_tuple.
Qed.
Lemma leqif_sum (I : finType) (P C : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i ?= iff C i) ->
\sum_(i | P i) E1 i <= \sum_(i | P i) E2 i ?= iff [forall (i | P i), C i].
Proof.
move=> leE12; rewrite -big_andE.
by elim/big_rec3: _ => // i Ci m1 m2 /leE12; apply: leqif_add.
Qed.
Lemma leq_sum I r (P : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i) ->
\sum_(i <- r | P i) E1 i <= \sum_(i <- r | P i) E2 i.
Proof. by move=> leE12; elim/big_ind2: _ => // m1 m2 n1 n2; apply: leq_add. Qed.
Lemma sumnB I r (P : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i) ->
\sum_(i <- r | P i) (E2 i - E1 i) =
\sum_(i <- r | P i) E2 i - \sum_(i <- r | P i) E1 i.
Proof. by move=> /(_ _ _)/subnK-/(eq_bigr _)<-; rewrite big_split addnK. Qed.
Lemma sum_nat_eq0 (I : finType) (P : pred I) (E : I -> nat) :
(\sum_(i | P i) E i == 0)%N = [forall (i | P i), E i == 0%N].
Proof. by rewrite eq_sym -(@leqif_sum I P _ (fun _ => 0%N) E) ?big1_eq. Qed.
Lemma sum_nat_seq_eq0 I r (P : pred I) F :
(\sum_(i <- r | P i) F i == 0)%N = all (fun i => P i ==> (F i == 0%N)) r.
Proof. by rewrite (big_morph _ (id1:=true) addn_eq0)// big_all_cond. Qed.
Lemma sum_nat_seq_neq0 I r (P : pred I) F :
(\sum_(i <- r | P i) F i != 0)%N = has (fun i => P i && (F i != 0)%N) r.
Proof.
by rewrite sum_nat_seq_eq0// -has_predC; apply: eq_has => x /=; case Px: (P x).
Qed.
Lemma sum_nat_eq1 (I : finType) (P : pred I) (F : I -> nat) :
reflect
(exists i : I, [/\ P i, F i = 1 & forall j, j != i -> P j -> F j = 0]%N)
(\sum_(i | P i) F i == 1)%N.
Proof.
apply/(iffP idP) => [sumF_eq1 | [i [Pi Fi1 zFj]]]; last first.
rewrite (bigD1 i)//= Fi1 addn_eq1//= orbF sum_nat_eq0.
by apply/forall_inP => j /andP[Pj ji]; apply/eqP/zFj.
have /forall_inPn [i Pi FiN0]: ~~ [forall i in P, F i == 0].
by apply: contraTN sumF_eq1 => /'forall_in_eqP F0; rewrite big1.
move: sumF_eq1; rewrite (bigD1 i)//= addn_eq1 (negPf FiN0)/= orbF.
move=> /andP[/eqP Fi1]; rewrite sum_nat_eq0 => /'forall_in_eqP FNi0.
by exists i; split; rewrite // => j /[swap] Nij /(conj Nij)/andP/FNi0.
Qed.
Lemma sum_nat_seq_eq1 (I : eqType) r (P : pred I) (F : I -> nat) :
(\sum_(i <- r | P i) F i = 1)%N ->
exists i, [/\ i \in r, P i, F i = 1
& forall j, j != i -> j \in r -> P j -> F j = 0]%N.
Proof.
rewrite big_tnth/= => /eqP/sum_nat_eq1[/= i [Pi Fi FNi]].
exists (tnth (in_tuple r) i); split; rewrite //= ?mem_tnth// => j.
move=> /[swap] /(tnthP (in_tuple r))[{} j -> Nij /FNi->//].
by apply: contra_neq Nij => ->.
Qed.
Lemma prod_nat_seq_eq0 I r (P : pred I) F :
(\prod_(i <- r | P i) F i == 0)%N = has (fun i => P i && (F i == 0%N)) r.
Proof. by rewrite (big_morph _ (id1 := false) muln_eq0)// big_has_cond. Qed.
Lemma prod_nat_seq_neq0 I r (P : pred I) F :
(\prod_(i <- r | P i) F i != 0)%N = all (fun i => P i ==> (F i != 0%N)) r.
Proof.
by rewrite prod_nat_seq_eq0 -all_predC; apply: eq_all => i /=; case: (P i).
Qed.
Lemma prod_nat_seq_eq1 I r (P : pred I) F :
(\prod_(i <- r | P i) F i == 1)%N = all (fun i => P i ==> (F i == 1%N)) r.
Proof. by rewrite (big_morph _ (id1:=true) muln_eq1)// big_all_cond. Qed.
Lemma prod_nat_seq_neq1 I r (P : pred I) F :
(\prod_(i <- r | P i) F i != 1)%N = has (fun i => P i && (F i != 1%N)) r.
Proof.
by rewrite prod_nat_seq_eq1 -has_predC; apply: eq_has => i /=; case: (P i).
Qed.
Lemma leq_prod I r (P : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i) ->
\prod_(i <- r | P i) E1 i <= \prod_(i <- r | P i) E2 i.
Proof. by move=> leE12; elim/big_ind2: _ => // m1 m2 n1 n2; apply: leq_mul. Qed.
Arguments leq_prod [I r P E1 E2].
Lemma prodn_cond_gt0 I r (P : pred I) F :
(forall i, P i -> 0 < F i) -> 0 < \prod_(i <- r | P i) F i.
Proof. by move=> Fpos; elim/big_ind: _ => // n1 n2; rewrite muln_gt0 => ->. Qed.
Arguments prodn_cond_gt0 [I r P F].
Lemma prodn_gt0 I r (P : pred I) F :
(forall i, 0 < F i) -> 0 < \prod_(i <- r | P i) F i.
Proof. by move=> Fpos; apply: prodn_cond_gt0. Qed.
Arguments prodn_gt0 [I r P F].
Lemma gt0_prodn_seq (I : eqType) r (P : pred I) F :
0 < \prod_(i <- r | P i) F i -> forall i, i \in r -> P i -> 0 < F i.
Proof.
move=> + i ri Pi; rewrite !lt0n; apply: contra_neq => Fi_eq0.
by case: (path.splitP ri) => *; rewrite big_cat big_rcons Pi Fi_eq0/= muln0.
Qed.
Arguments gt0_prodn_seq [I r P F].
Lemma gt0_prodn (I : finType) (P : pred I) F :
0 < \prod_(i | P i) F i -> forall i, P i -> 0 < F i.
Proof. by move=> /gt0_prodn_seq + i => /[apply]; apply. Qed.
Arguments gt0_prodn [I P F].
Lemma leq_bigmax_seq (I : eqType) r (P : pred I) F i0 :
i0 \in r -> P i0 -> F i0 <= \max_(i <- r | P i) F i.
Proof.
move=> + Pi0; elim: r => // h t ih; rewrite inE big_cons.
move=> /predU1P[<-|i0t]; first by rewrite Pi0 leq_maxl.
by case: ifPn => Ph; [rewrite leq_max ih// orbT|rewrite ih].
Qed.
Arguments leq_bigmax_seq [I r P F].
Lemma leq_bigmax_cond (I : finType) (P : pred I) F i0 :
P i0 -> F i0 <= \max_(i | P i) F i.
Proof. exact: leq_bigmax_seq. Qed.
Arguments leq_bigmax_cond [I P F].
Lemma leq_bigmax (I : finType) F (i0 : I) : F i0 <= \max_i F i.
Proof. exact: leq_bigmax_cond. Qed.
Arguments leq_bigmax [I F].
Lemma bigmax_leqP (I : finType) (P : pred I) m F :
reflect (forall i, P i -> F i <= m) (\max_(i | P i) F i <= m).
Proof.
apply: (iffP idP) => leFm => [i Pi|].
by apply: leq_trans leFm; apply: leq_bigmax_cond.
by elim/big_ind: _ => // m1 m2; rewrite geq_max => ->.
Qed.
Lemma bigmax_leqP_seq (I : eqType) r (P : pred I) m F :
reflect (forall i, i \in r -> P i -> F i <= m) (\max_(i <- r | P i) F i <= m).
Proof.
apply: (iffP idP) => leFm => [i ri Pi|].
exact/(leq_trans _ leFm)/leq_bigmax_seq.
rewrite big_seq_cond; elim/big_ind: _ => // [m1 m2|i /andP[ri]].
by rewrite geq_max => ->.
exact: leFm.
Qed.
Lemma bigmax_sup (I : finType) i0 (P : pred I) m F :
P i0 -> m <= F i0 -> m <= \max_(i | P i) F i.
Proof. by move=> Pi0 le_m_Fi0; apply: leq_trans (leq_bigmax_cond i0 Pi0). Qed.
Arguments bigmax_sup [I] i0 [P m F].
Lemma bigmax_sup_seq (I : eqType) r i0 (P : pred I) m F :
i0 \in r -> P i0 -> m <= F i0 -> m <= \max_(i <- r | P i) F i.
Proof. by move=> i0r Pi0 ?; apply: leq_trans (leq_bigmax_seq i0 _ _). Qed.
Arguments bigmax_sup_seq [I r] i0 [P m F].
Lemma bigmax_eq_arg (I : finType) i0 (P : pred I) F :
P i0 -> \max_(i | P i) F i = F [arg max_(i > i0 | P i) F i].
Proof.
move=> Pi0; case: arg_maxnP => //= i Pi maxFi.
by apply/eqP; rewrite eqn_leq leq_bigmax_cond // andbT; apply/bigmax_leqP.
Qed.
Arguments bigmax_eq_arg [I] i0 [P F].
Lemma eq_bigmax_cond (I : finType) (A : pred I) F :
#|A| > 0 -> {i0 | i0 \in A & \max_(i in A) F i = F i0}.
Proof.
case: (pickP A) => [i0 Ai0 _ | ]; last by move/eq_card0->.
by exists [arg max_(i > i0 in A) F i]; [case: arg_maxnP | apply: bigmax_eq_arg].
Qed.
Lemma eq_bigmax (I : finType) F : #|I| > 0 -> {i0 : I | \max_i F i = F i0}.
Proof. by case/(eq_bigmax_cond F) => x _ ->; exists x. Qed.
Lemma expn_sum m I r (P : pred I) F :
(m ^ (\sum_(i <- r | P i) F i) = \prod_(i <- r | P i) m ^ F i)%N.
Proof. exact: (big_morph _ (expnD m)). Qed.
Lemma dvdn_biglcmP (I : finType) (P : pred I) F m :
reflect (forall i, P i -> F i %| m) (\big[lcmn/1%N]_(i | P i) F i %| m).
Proof.
apply: (iffP idP) => [dvFm i Pi | dvFm].
by rewrite (bigD1 i) // dvdn_lcm in dvFm; case/andP: dvFm.
by elim/big_ind: _ => // p q p_m; rewrite dvdn_lcm p_m.
Qed.
Lemma biglcmn_sup (I : finType) i0 (P : pred I) F m :
P i0 -> m %| F i0 -> m %| \big[lcmn/1%N]_(i | P i) F i.
Proof.
by move=> Pi0 m_Fi0; rewrite (dvdn_trans m_Fi0) // (bigD1 i0) ?dvdn_lcml.
Qed.
Arguments biglcmn_sup [I] i0 [P F m].
Lemma dvdn_biggcdP (I : finType) (P : pred I) F m :
reflect (forall i, P i -> m %| F i) (m %| \big[gcdn/0]_(i | P i) F i).
Proof.
apply: (iffP idP) => [dvmF i Pi | dvmF].
by rewrite (bigD1 i) // dvdn_gcd in dvmF; case/andP: dvmF.
by elim/big_ind: _ => // p q m_p; rewrite dvdn_gcd m_p.
Qed.
Lemma biggcdn_inf (I : finType) i0 (P : pred I) F m :
P i0 -> F i0 %| m -> \big[gcdn/0]_(i | P i) F i %| m.
Proof. by move=> Pi0; apply: dvdn_trans; rewrite (bigD1 i0) ?dvdn_gcdl. Qed.
Arguments biggcdn_inf [I] i0 [P F m].
|
AList.lean
|
/-
Copyright (c) 2018 Sean Leather. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sean Leather, Mario Carneiro
-/
import Mathlib.Data.List.Sigma
/-!
# Association Lists
This file defines association lists. An association list is a list where every element consists of
a key and a value, and no two entries have the same key. The type of the value is allowed to be
dependent on the type of the key.
This type dependence is implemented using `Sigma`: The elements of the list are of type `Sigma β`,
for some type index `β`.
## Main definitions
Association lists are represented by the `AList` structure. This file defines this structure and
provides ways to access, modify, and combine `AList`s.
* `AList.keys` returns a list of keys of the alist.
* `AList.membership` returns membership in the set of keys.
* `AList.erase` removes a certain key.
* `AList.insert` adds a key-value mapping to the list.
* `AList.union` combines two association lists.
## References
* <https://en.wikipedia.org/wiki/Association_list>
-/
universe u v w
open List
variable {α : Type u} {β : α → Type v}
/-- `AList β` is a key-value map stored as a `List` (i.e. a linked list).
It is a wrapper around certain `List` functions with the added constraint
that the list have unique keys. -/
structure AList (β : α → Type v) : Type max u v where
/-- The underlying `List` of an `AList` -/
entries : List (Sigma β)
/-- There are no duplicate keys in `entries` -/
nodupKeys : entries.NodupKeys
/-- Given `l : List (Sigma β)`, create a term of type `AList β` by removing
entries with duplicate keys. -/
def List.toAList [DecidableEq α] {β : α → Type v} (l : List (Sigma β)) : AList β where
entries := _
nodupKeys := nodupKeys_dedupKeys l
namespace AList
@[ext]
theorem ext : ∀ {s t : AList β}, s.entries = t.entries → s = t
| ⟨l₁, h₁⟩, ⟨l₂, _⟩, H => by congr
instance [DecidableEq α] [∀ a, DecidableEq (β a)] : DecidableEq (AList β) := fun xs ys => by
rw [AList.ext_iff]; infer_instance
/-! ### keys -/
/-- The list of keys of an association list. -/
def keys (s : AList β) : List α :=
s.entries.keys
theorem keys_nodup (s : AList β) : s.keys.Nodup :=
s.nodupKeys
/-! ### mem -/
/-- The predicate `a ∈ s` means that `s` has a value associated to the key `a`. -/
instance : Membership α (AList β) :=
⟨fun s a => a ∈ s.keys⟩
theorem mem_keys {a : α} {s : AList β} : a ∈ s ↔ a ∈ s.keys :=
Iff.rfl
theorem mem_of_perm {a : α} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) : a ∈ s₁ ↔ a ∈ s₂ :=
(p.map Sigma.fst).mem_iff
/-! ### empty -/
/-- The empty association list. -/
instance : EmptyCollection (AList β) :=
⟨⟨[], nodupKeys_nil⟩⟩
instance : Inhabited (AList β) :=
⟨∅⟩
@[simp]
theorem notMem_empty (a : α) : a ∉ (∅ : AList β) :=
not_mem_nil
@[deprecated (since := "2025-05-23")] alias not_mem_empty := notMem_empty
@[simp]
theorem empty_entries : (∅ : AList β).entries = [] :=
rfl
@[simp]
theorem keys_empty : (∅ : AList β).keys = [] :=
rfl
/-! ### singleton -/
/-- The singleton association list. -/
def singleton (a : α) (b : β a) : AList β :=
⟨[⟨a, b⟩], nodupKeys_singleton _⟩
@[simp]
theorem singleton_entries (a : α) (b : β a) : (singleton a b).entries = [Sigma.mk a b] :=
rfl
@[simp]
theorem keys_singleton (a : α) (b : β a) : (singleton a b).keys = [a] :=
rfl
/-! ### lookup -/
section
variable [DecidableEq α]
/-- Look up the value associated to a key in an association list. -/
def lookup (a : α) (s : AList β) : Option (β a) :=
s.entries.dlookup a
@[simp]
theorem lookup_empty (a) : lookup a (∅ : AList β) = none :=
rfl
theorem lookup_isSome {a : α} {s : AList β} : (s.lookup a).isSome ↔ a ∈ s :=
dlookup_isSome
theorem lookup_eq_none {a : α} {s : AList β} : lookup a s = none ↔ a ∉ s :=
dlookup_eq_none
theorem mem_lookup_iff {a : α} {b : β a} {s : AList β} :
b ∈ lookup a s ↔ Sigma.mk a b ∈ s.entries :=
mem_dlookup_iff s.nodupKeys
theorem perm_lookup {a : α} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) :
s₁.lookup a = s₂.lookup a :=
perm_dlookup _ s₁.nodupKeys s₂.nodupKeys p
instance (a : α) (s : AList β) : Decidable (a ∈ s) :=
decidable_of_iff _ lookup_isSome
end
theorem keys_subset_keys_of_entries_subset_entries
{s₁ s₂ : AList β} (h : s₁.entries ⊆ s₂.entries) : s₁.keys ⊆ s₂.keys := by
intro k hk
letI : DecidableEq α := Classical.decEq α
have := h (mem_lookup_iff.1 (Option.get_mem (lookup_isSome.2 hk)))
rw [← mem_lookup_iff, Option.mem_def] at this
rw [← mem_keys, ← lookup_isSome, this]
exact Option.isSome_some
/-! ### replace -/
section
variable [DecidableEq α]
/-- Replace a key with a given value in an association list.
If the key is not present it does nothing. -/
def replace (a : α) (b : β a) (s : AList β) : AList β :=
⟨kreplace a b s.entries, (kreplace_nodupKeys a b).2 s.nodupKeys⟩
@[simp]
theorem keys_replace (a : α) (b : β a) (s : AList β) : (replace a b s).keys = s.keys :=
keys_kreplace _ _ _
@[simp]
theorem mem_replace {a a' : α} {b : β a} {s : AList β} : a' ∈ replace a b s ↔ a' ∈ s := by
rw [mem_keys, keys_replace, ← mem_keys]
theorem perm_replace {a : α} {b : β a} {s₁ s₂ : AList β} :
s₁.entries ~ s₂.entries → (replace a b s₁).entries ~ (replace a b s₂).entries :=
Perm.kreplace s₁.nodupKeys
end
/-- Fold a function over the key-value pairs in the map. -/
def foldl {δ : Type w} (f : δ → ∀ a, β a → δ) (d : δ) (m : AList β) : δ :=
m.entries.foldl (fun r a => f r a.1 a.2) d
/-! ### erase -/
section
variable [DecidableEq α]
/-- Erase a key from the map. If the key is not present, do nothing. -/
def erase (a : α) (s : AList β) : AList β :=
⟨s.entries.kerase a, s.nodupKeys.kerase a⟩
@[simp]
theorem keys_erase (a : α) (s : AList β) : (erase a s).keys = s.keys.erase a :=
keys_kerase
@[simp]
theorem mem_erase {a a' : α} {s : AList β} : a' ∈ erase a s ↔ a' ≠ a ∧ a' ∈ s := by
rw [mem_keys, keys_erase, s.keys_nodup.mem_erase_iff, ← mem_keys]
theorem perm_erase {a : α} {s₁ s₂ : AList β} :
s₁.entries ~ s₂.entries → (erase a s₁).entries ~ (erase a s₂).entries :=
Perm.kerase s₁.nodupKeys
@[simp]
theorem lookup_erase (a) (s : AList β) : lookup a (erase a s) = none :=
dlookup_kerase a s.nodupKeys
@[simp]
theorem lookup_erase_ne {a a'} {s : AList β} (h : a ≠ a') : lookup a (erase a' s) = lookup a s :=
dlookup_kerase_ne h
theorem erase_erase (a a' : α) (s : AList β) : (s.erase a).erase a' = (s.erase a').erase a :=
ext <| kerase_kerase
/-! ### insert -/
/-- Insert a key-value pair into an association list and erase any existing pair
with the same key. -/
def insert (a : α) (b : β a) (s : AList β) : AList β :=
⟨kinsert a b s.entries, kinsert_nodupKeys a b s.nodupKeys⟩
@[simp]
theorem entries_insert {a} {b : β a} {s : AList β} :
(insert a b s).entries = Sigma.mk a b :: kerase a s.entries :=
rfl
theorem entries_insert_of_notMem {a} {b : β a} {s : AList β} (h : a ∉ s) :
(insert a b s).entries = ⟨a, b⟩ :: s.entries := by rw [entries_insert, kerase_of_notMem_keys h]
@[deprecated (since := "2025-05-23")] alias entries_insert_of_not_mem := entries_insert_of_notMem
theorem insert_of_notMem {a} {b : β a} {s : AList β} (h : a ∉ s) :
insert a b s = ⟨⟨a, b⟩ :: s.entries, nodupKeys_cons.2 ⟨h, s.2⟩⟩ :=
ext <| entries_insert_of_notMem h
@[deprecated (since := "2025-05-23")] alias insert_of_not_mem := insert_of_notMem
@[simp]
theorem insert_empty (a) (b : β a) : insert a b ∅ = singleton a b :=
rfl
@[simp]
theorem mem_insert {a a'} {b' : β a'} (s : AList β) : a ∈ insert a' b' s ↔ a = a' ∨ a ∈ s :=
mem_keys_kinsert
@[simp]
theorem keys_insert {a} {b : β a} (s : AList β) : (insert a b s).keys = a :: s.keys.erase a := by
simp [insert, keys, keys_kerase]
theorem perm_insert {a} {b : β a} {s₁ s₂ : AList β} (p : s₁.entries ~ s₂.entries) :
(insert a b s₁).entries ~ (insert a b s₂).entries := by
simp only [entries_insert]; exact p.kinsert s₁.nodupKeys
@[simp]
theorem lookup_insert {a} {b : β a} (s : AList β) : lookup a (insert a b s) = some b := by
simp only [lookup, insert, dlookup_kinsert]
@[simp]
theorem lookup_insert_ne {a a'} {b' : β a'} {s : AList β} (h : a ≠ a') :
lookup a (insert a' b' s) = lookup a s :=
dlookup_kinsert_ne h
@[simp] theorem lookup_insert_eq_none {l : AList β} {k k' : α} {v : β k} :
(l.insert k v).lookup k' = none ↔ (k' ≠ k) ∧ l.lookup k' = none := by
by_cases h : k' = k
· subst h; simp
· simp_all [lookup_insert_ne h]
@[simp]
theorem lookup_to_alist {a} (s : List (Sigma β)) : lookup a s.toAList = s.dlookup a := by
rw [List.toAList, lookup, dlookup_dedupKeys]
@[simp]
theorem insert_insert {a} {b b' : β a} (s : AList β) :
(s.insert a b).insert a b' = s.insert a b' := by
ext : 1; simp only [AList.entries_insert, List.kerase_cons_eq]
theorem insert_insert_of_ne {a a'} {b : β a} {b' : β a'} (s : AList β) (h : a ≠ a') :
((s.insert a b).insert a' b').entries ~ ((s.insert a' b').insert a b).entries := by
simp only [entries_insert]; rw [kerase_cons_ne, kerase_cons_ne, kerase_comm] <;>
[apply Perm.swap; exact h; exact h.symm]
@[simp]
theorem insert_singleton_eq {a : α} {b b' : β a} : insert a b (singleton a b') = singleton a b :=
ext <| by
simp only [AList.entries_insert, List.kerase_cons_eq, AList.singleton_entries]
@[simp]
theorem entries_toAList (xs : List (Sigma β)) : (List.toAList xs).entries = dedupKeys xs :=
rfl
theorem toAList_cons (a : α) (b : β a) (xs : List (Sigma β)) :
List.toAList (⟨a, b⟩ :: xs) = insert a b xs.toAList :=
rfl
theorem mk_cons_eq_insert (c : Sigma β) (l : List (Sigma β)) (h : (c :: l).NodupKeys) :
(⟨c :: l, h⟩ : AList β) = insert c.1 c.2 ⟨l, nodupKeys_of_nodupKeys_cons h⟩ := by
simpa [insert] using (kerase_of_notMem_keys <| notMem_keys_of_nodupKeys_cons h).symm
/-- Recursion on an `AList`, using `insert`. Use as `induction l`. -/
@[elab_as_elim, induction_eliminator]
def insertRec {C : AList β → Sort*} (H0 : C ∅)
(IH : ∀ (a : α) (b : β a) (l : AList β), a ∉ l → C l → C (l.insert a b)) :
∀ l : AList β, C l
| ⟨[], _⟩ => H0
| ⟨c :: l, h⟩ => by
rw [mk_cons_eq_insert]
refine IH _ _ _ ?_ (insertRec H0 IH _)
exact notMem_keys_of_nodupKeys_cons h
-- Test that the `induction` tactic works on `insertRec`.
example (l : AList β) : True := by induction l <;> trivial
@[simp]
theorem insertRec_empty {C : AList β → Sort*} (H0 : C ∅)
(IH : ∀ (a : α) (b : β a) (l : AList β), a ∉ l → C l → C (l.insert a b)) :
@insertRec α β _ C H0 IH ∅ = H0 := by
change @insertRec α β _ C H0 IH ⟨[], _⟩ = H0
rw [insertRec]
theorem insertRec_insert {C : AList β → Sort*} (H0 : C ∅)
(IH : ∀ (a : α) (b : β a) (l : AList β), a ∉ l → C l → C (l.insert a b)) {c : Sigma β}
{l : AList β} (h : c.1 ∉ l) :
@insertRec α β _ C H0 IH (l.insert c.1 c.2) = IH c.1 c.2 l h (@insertRec α β _ C H0 IH l) := by
obtain ⟨l, hl⟩ := l
suffices @insertRec α β _ C H0 IH ⟨c :: l, nodupKeys_cons.2 ⟨h, hl⟩⟩ ≍
IH c.1 c.2 ⟨l, hl⟩ h (@insertRec α β _ C H0 IH ⟨l, hl⟩) by
cases c
apply eq_of_heq
convert this <;> rw [insert_of_notMem h]
rw [insertRec]
apply cast_heq
theorem insertRec_insert_mk {C : AList β → Sort*} (H0 : C ∅)
(IH : ∀ (a : α) (b : β a) (l : AList β), a ∉ l → C l → C (l.insert a b)) {a : α} (b : β a)
{l : AList β} (h : a ∉ l) :
@insertRec α β _ C H0 IH (l.insert a b) = IH a b l h (@insertRec α β _ C H0 IH l) :=
@insertRec_insert α β _ C H0 IH ⟨a, b⟩ l h
/-! ### extract -/
/-- Erase a key from the map, and return the corresponding value, if found. -/
def extract (a : α) (s : AList β) : Option (β a) × AList β :=
have : (kextract a s.entries).2.NodupKeys := by
rw [kextract_eq_dlookup_kerase]; exact s.nodupKeys.kerase _
match kextract a s.entries, this with
| (b, l), h => (b, ⟨l, h⟩)
@[simp]
theorem extract_eq_lookup_erase (a : α) (s : AList β) : extract a s = (lookup a s, erase a s) := by
simp [extract]; constructor <;> rfl
/-! ### union -/
/-- `s₁ ∪ s₂` is the key-based union of two association lists. It is
left-biased: if there exists an `a ∈ s₁`, `lookup a (s₁ ∪ s₂) = lookup a s₁`.
-/
def union (s₁ s₂ : AList β) : AList β :=
⟨s₁.entries.kunion s₂.entries, s₁.nodupKeys.kunion s₂.nodupKeys⟩
instance : Union (AList β) :=
⟨union⟩
@[simp]
theorem union_entries {s₁ s₂ : AList β} : (s₁ ∪ s₂).entries = kunion s₁.entries s₂.entries :=
rfl
@[simp]
theorem empty_union {s : AList β} : (∅ : AList β) ∪ s = s :=
ext rfl
@[simp]
theorem union_empty {s : AList β} : s ∪ (∅ : AList β) = s :=
ext <| by simp
@[simp]
theorem mem_union {a} {s₁ s₂ : AList β} : a ∈ s₁ ∪ s₂ ↔ a ∈ s₁ ∨ a ∈ s₂ :=
mem_keys_kunion
theorem perm_union {s₁ s₂ s₃ s₄ : AList β} (p₁₂ : s₁.entries ~ s₂.entries)
(p₃₄ : s₃.entries ~ s₄.entries) : (s₁ ∪ s₃).entries ~ (s₂ ∪ s₄).entries := by
simp [p₁₂.kunion s₃.nodupKeys p₃₄]
theorem union_erase (a : α) (s₁ s₂ : AList β) : erase a (s₁ ∪ s₂) = erase a s₁ ∪ erase a s₂ :=
ext kunion_kerase.symm
@[simp]
theorem lookup_union_left {a} {s₁ s₂ : AList β} : a ∈ s₁ → lookup a (s₁ ∪ s₂) = lookup a s₁ :=
dlookup_kunion_left
@[simp]
theorem lookup_union_right {a} {s₁ s₂ : AList β} : a ∉ s₁ → lookup a (s₁ ∪ s₂) = lookup a s₂ :=
dlookup_kunion_right
-- The corresponding lemma in `simp`-normal form is `lookup_union_eq_some`.
theorem mem_lookup_union {a} {b : β a} {s₁ s₂ : AList β} :
b ∈ lookup a (s₁ ∪ s₂) ↔ b ∈ lookup a s₁ ∨ a ∉ s₁ ∧ b ∈ lookup a s₂ :=
mem_dlookup_kunion
@[simp]
theorem lookup_union_eq_some {a} {b : β a} {s₁ s₂ : AList β} :
lookup a (s₁ ∪ s₂) = some b ↔ lookup a s₁ = some b ∨ a ∉ s₁ ∧ lookup a s₂ = some b :=
mem_dlookup_kunion
theorem mem_lookup_union_middle {a} {b : β a} {s₁ s₂ s₃ : AList β} :
b ∈ lookup a (s₁ ∪ s₃) → a ∉ s₂ → b ∈ lookup a (s₁ ∪ s₂ ∪ s₃) :=
mem_dlookup_kunion_middle
theorem insert_union {a} {b : β a} {s₁ s₂ : AList β} :
insert a b (s₁ ∪ s₂) = insert a b s₁ ∪ s₂ := by ext; simp
theorem union_assoc {s₁ s₂ s₃ : AList β} : (s₁ ∪ s₂ ∪ s₃).entries ~ (s₁ ∪ (s₂ ∪ s₃)).entries :=
lookup_ext (AList.nodupKeys _) (AList.nodupKeys _)
(by simp [not_or, or_assoc, and_or_left, and_assoc])
end
/-! ### disjoint -/
/-- Two associative lists are disjoint if they have no common keys. -/
def Disjoint (s₁ s₂ : AList β) : Prop :=
∀ k ∈ s₁.keys, k ∉ s₂.keys
variable [DecidableEq α]
theorem union_comm_of_disjoint {s₁ s₂ : AList β} (h : Disjoint s₁ s₂) :
(s₁ ∪ s₂).entries ~ (s₂ ∪ s₁).entries :=
lookup_ext (AList.nodupKeys _) (AList.nodupKeys _)
(by
intros; simp only [union_entries, Option.mem_def, dlookup_kunion_eq_some]
constructor <;> intro h'
· rcases h' with h' | h'
· right
refine ⟨?_, h'⟩
apply h
rw [keys, ← List.dlookup_isSome, h']
exact rfl
· left
rw [h'.2]
· rcases h' with h' | h'
· right
refine ⟨?_, h'⟩
intro h''
apply h _ h''
rw [keys, ← List.dlookup_isSome, h']
exact rfl
· left
rw [h'.2])
end AList
|
Determinant.lean
|
/-
Copyright (c) 2020 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence
import Mathlib.Algebra.ContinuedFractions.TerminatedStable
import Mathlib.Tactic.Ring
/-!
# Determinant Formula for Simple Continued Fraction
## Summary
We derive the so-called *determinant formula* for `SimpContFract`:
`Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`.
## TODO
Generalize this for `GenContFract` version:
`Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-a₀) * (-a₁) * .. * (-aₙ₊₁)`.
## References
- https://en.wikipedia.org/wiki/Generalized_continued_fraction#The_determinant_formula
-/
open GenContFract
namespace SimpContFract
variable {K : Type*} [Field K] {s : SimpContFract K} {n : ℕ}
theorem determinant_aux (hyp : n = 0 ∨ ¬(↑s : GenContFract K).TerminatedAt (n - 1)) :
((↑s : GenContFract K).contsAux n).a * ((↑s : GenContFract K).contsAux (n + 1)).b -
((↑s : GenContFract K).contsAux n).b * ((↑s : GenContFract K).contsAux (n + 1)).a =
(-1) ^ n := by
induction n with
| zero => simp [contsAux]
| succ n IH =>
-- set up some shorthand notation
let g := (↑s : GenContFract K)
let conts := contsAux g (n + 2)
set pred_conts := contsAux g (n + 1) with pred_conts_eq
set ppred_conts := contsAux g n with ppred_conts_eq
let pA := pred_conts.a
let pB := pred_conts.b
let ppA := ppred_conts.a
let ppB := ppred_conts.b
-- let's change the goal to something more readable
change pA * conts.b - pB * conts.a = (-1) ^ (n + 1)
have not_terminated_at_n : ¬TerminatedAt g n := Or.resolve_left hyp n.succ_ne_zero
obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
Option.ne_none_iff_exists'.1 not_terminated_at_n
-- unfold the recurrence relation for `conts` once and simplify to derive the following
suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1) by
simp only [conts, contsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq]
have gp_a_eq_one : gp.a = 1 := s.property _ _ (partNum_eq_s_a s_nth_eq)
rw [gp_a_eq_one, this.symm]
ring
suffices pA * ppB - pB * ppA = (-1) ^ (n + 1) by grind
suffices ppA * pB - ppB * pA = (-1) ^ n by grind
exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1) not_terminated_at_n
/-- The determinant formula `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`. -/
theorem determinant (not_terminatedAt_n : ¬(↑s : GenContFract K).TerminatedAt n) :
(↑s : GenContFract K).nums n * (↑s : GenContFract K).dens (n + 1) -
(↑s : GenContFract K).dens n * (↑s : GenContFract K).nums (n + 1) = (-1) ^ (n + 1) :=
determinant_aux <| Or.inr <| not_terminatedAt_n
end SimpContFract
|
matrix.lean
|
/-
manually ported from
https://github.com/leanprover-community/mathlib/blob/4f4a1c875d0baa92ab5d92f3fb1bb258ad9f3e5b/test/matrix.lean
-/
import Mathlib.Data.Matrix.Notation
import Mathlib.GroupTheory.Perm.Fin
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Qq
set_option linter.style.commandStart false
open Qq
variable {α β : Type} [Semiring α] [Ring β]
namespace Matrix
/-! Test that the dimensions are inferred correctly, even for empty matrices -/
section dimensions
-- set_option pp.universes true
-- set_option pp.all true
section elaborators
open Lean Meta Elab Command
/-- `dims% e` elaborates `e` as a Matrix and returns its dimensions as a `Nat × Nat`. -/
elab "dims% " e:term : term => do
let elem_t ← mkFreshTypeMVar
let m ← mkFreshExprMVar (mkConst ``Nat)
let n ← mkFreshExprMVar (mkConst ``Nat)
let matrix_t := mkAppN (← mkConstWithFreshMVarLevels ``Matrix)
#[mkApp (mkConst ``Fin) m, mkApp (mkConst ``Fin) n, elem_t]
let _ ← Term.elabTermEnsuringType e (some matrix_t)
let m ← instantiateMVars m
let n ← instantiateMVars n
mkAppM ``Prod.mk #[m, n]
end elaborators
-- we test equality of expressions here to ensure that we have `2` and not `1.succ` in the type
#guard_expr dims% !![] =ₛ (0, 0)
#guard_expr dims% !![;] =ₛ (1, 0)
#guard_expr dims% !![;;] =ₛ (2, 0)
#guard_expr dims% !![,] =ₛ (0, 1)
#guard_expr dims% !![,,] =ₛ (0, 2)
#guard_expr dims% !![1] =ₛ (1, 1)
#guard_expr dims% !![1,] =ₛ (1, 1)
#guard_expr dims% !![1;] =ₛ (1, 1)
#guard_expr dims% !![1,2;3,4] =ₛ (2, 2)
end dimensions
section safety
open Lean Meta Elab Command
def mkMatrix (rows : Array (Array Term)) : Term := Unhygienic.run `(!![$[$[$rows],*];*])
def mkColumnVector (elems : Array Term) : Term := Unhygienic.run `(!![$[$elems];*])
-- Check that the `!![$[$[$rows],*];*]` case can deal with empty arrays even though it uses sepBy1
run_elab do
let e ← Term.elabTerm (mkMatrix #[]) q(Matrix (Fin 0) (Fin 0) Nat)
Term.synthesizeSyntheticMVarsUsingDefault
let e ← instantiateMVars e
guard <| e == q(!![] : Matrix (Fin 0) (Fin 0) Nat)
run_elab do
let e ← Term.elabTerm (mkColumnVector #[]) q(Matrix (Fin 0) (Fin 0) Nat)
Term.synthesizeSyntheticMVarsUsingDefault
let e ← instantiateMVars e
guard <| e == q(!![] : Matrix (Fin 0) (Fin 0) Nat)
end safety
#guard !![1;2] = of ![![1], ![2]]
#guard !![1,3] = of ![![1,3]]
#guard !![1,2;3,4] = of ![![1,2], ![3,4]]
#guard !![1,2;3,4;] = of ![![1,2], ![3,4]]
#guard !![1,2,;3,4,] = of ![![1,2], ![3,4]]
section to_expr
open Lean Meta
/-- info: !![1 + 1, 1 + 2; 2 + 1, 2 + 2] : Matrix (Fin 2) (Fin 2) ℕ -/
#guard_msgs in
#check by_elab return Matrix.mkLiteralQ !![q(1 + 1), q(1 + 2); q(2 + 1), q(2 + 2)]
run_elab do
let x := !![1, 2; 3, 4]
guard (← withReducible <| isDefEq (toExpr x) q(!![1, 2; 3, 4]))
end to_expr
section delaborators
/-- info: !![0, 1, 2; 3, 4, 5] : Matrix (Fin 2) (Fin 3) ℕ -/
#guard_msgs in #check (!![0, 1, 2; 3, 4, 5] : Matrix (Fin 2) (Fin 3) ℕ)
/-- info: !![0, 1, 2; 3, 4, 5] 1 1 : ℕ -/
#guard_msgs in #check (!![0, 1, 2; 3, 4, 5] : Matrix (Fin 2) (Fin 3) ℕ) 1 1
/-- info: !![,,,] : Matrix (Fin 0) (Fin 3) ℕ -/
#guard_msgs in #check (!![,,,] : Matrix (Fin 0) (Fin 3) ℕ)
/-- info: !![;;;] : Matrix (Fin 3) (Fin 0) ℕ -/
#guard_msgs in #check (!![;;;] : Matrix (Fin 3) (Fin 0) ℕ)
/-- info: !![] : Matrix (Fin 0) (Fin 0) ℕ -/
#guard_msgs in #check (!![] : Matrix (Fin 0) (Fin 0) ℕ)
end delaborators
example {a a' b b' c c' d d' : α} :
!![a, b; c, d] + !![a', b'; c', d'] = !![a + a', b + b'; c + c', d + d'] := by
simp
example {a a' b b' c c' d d' : β} :
!![a, b; c, d] - !![a', b'; c', d'] = !![a - a', b - b'; c - c', d - d'] := by
simp
example {a a' b b' c c' d d' : α} :
!![a, b; c, d] * !![a', b'; c', d'] =
!![a * a' + b * c', a * b' + b * d'; c * a' + d * c', c * b' + d * d'] := by
simp
example {a b c d x y : α} :
!![a, b; c, d] *ᵥ ![x, y] = ![a * x + b * y, c * x + d * y] := by
simp
/-!
TODO: the below lemmas rely on simp lemmas assuming the indexing numerals are assembled from
`bit0` and `bit1`, so no longer work in Lean 4
-/
/-
example {a b c d : α} : submatrix !![a, b; c, d] ![1, 0] ![0] = !![c; a] := by
ext; simp
-/
example {α : Type _} [CommRing α] {a b c d : α} :
Matrix.det !![a, b; c, d] = a * d - b * c := by
simp? [Matrix.det_succ_row_zero, Fin.sum_univ_succ] says
simp only [det_succ_row_zero, Nat.succ_eq_add_one, Nat.reduceAdd, Fin.isValue, of_apply,
cons_val', cons_val_fin_one, cons_val_zero, det_unique, Fin.default_eq_zero, submatrix_apply,
Fin.succ_zero_eq_one, cons_val_one, Fin.sum_univ_succ, Fin.coe_ofNat_eq_mod, Nat.zero_mod,
pow_zero, one_mul, Fin.zero_succAbove, Finset.univ_unique, Fin.val_succ, Fin.val_eq_zero,
zero_add, pow_one, cons_val_succ, neg_mul, ne_eq, Fin.succ_ne_zero, not_false_eq_true,
Fin.succAbove_ne_zero_zero, Finset.sum_neg_distrib, Finset.sum_const, Finset.card_singleton,
one_smul]
ring
example {α : Type _} [CommRing α] {a b c d e f g h i : α} :
Matrix.det !![a, b, c; d, e, f; g, h, i] =
a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g := by
simp? [Matrix.det_succ_row_zero, Fin.sum_univ_succ] says
simp only [det_succ_row_zero, Nat.succ_eq_add_one, Nat.reduceAdd, Fin.isValue, of_apply,
cons_val', cons_val_fin_one, cons_val_zero, submatrix_apply, Fin.succ_zero_eq_one,
cons_val_one, submatrix_submatrix, det_unique, Fin.default_eq_zero, Function.comp_apply,
Fin.succ_one_eq_two, cons_val, Fin.sum_univ_succ, Fin.coe_ofNat_eq_mod, Nat.zero_mod,
pow_zero, one_mul, Fin.zero_succAbove, Finset.univ_unique, Fin.val_succ, Fin.val_eq_zero,
zero_add, pow_one, neg_mul, ne_eq, Fin.succ_ne_zero, not_false_eq_true,
Fin.succAbove_ne_zero_zero, Finset.sum_neg_distrib, Finset.sum_singleton, cons_val_succ,
Fin.succ_succAbove_one, even_two, Even.neg_pow, one_pow, Finset.sum_const,
Finset.card_singleton, one_smul]
ring
example {R : Type*} [Semiring R] {a b c d : R} :
!![a, b] * (transpose !![c, d]) = !![a * c + b * d] := by
ext i j
fin_cases i
fin_cases j
simp [Matrix.vecHead, Matrix.vecTail]
/- Check that matrix notation works with `row` and `col` -/
example : Matrix.replicateRow _ ![1, 1] = !![1, 1] := by
ext i j
simp
example : Matrix.replicateCol _ ![1, 1] = !![1; 1] := by
ext i j
fin_cases i <;> simp
example (ι : Type*) [Inhabited ι] : Matrix.replicateRow ι (fun (_ : Fin 3) => 0) = 0 := by
simp_all
rfl
example (ι : Type*) [Inhabited ι] : Matrix.replicateCol ι (fun (_ : Fin 3) => 0) = 0 := by
simp_all
rfl
end Matrix
|
QuadraticReciprocity.lean
|
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.NumberTheory.Zsqrtd.GaussianInt
import Mathlib.NumberTheory.LegendreSymbol.Basic
/-!
# Facts about the gaussian integers relying on quadratic reciprocity.
## Main statements
`prime_iff_mod_four_eq_three_of_nat_prime`
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
-/
open Zsqrtd Complex
open scoped ComplexConjugate
local notation "ℤ[i]" => GaussianInt
namespace GaussianInt
open PrincipalIdealRing
theorem mod_four_eq_three_of_nat_prime_of_prime (p : ℕ) [hp : Fact p.Prime]
(hpi : Prime (p : ℤ[i])) : p % 4 = 3 :=
hp.1.eq_two_or_odd.elim
(fun hp2 => by
have := hpi.irreducible.isUnit_or_isUnit (a := ⟨1, 1⟩) (b := ⟨1, -1⟩)
simp [hp2, Zsqrtd.ext_iff, ← norm_eq_one_iff, norm_def] at this)
fun hp1 =>
by_contradiction fun hp3 : p % 4 ≠ 3 => by
let ⟨k, hk⟩ := (ZMod.exists_sq_eq_neg_one_iff (p := p)).2 hp3
obtain ⟨k, k_lt_p, rfl⟩ : ∃ (k' : ℕ) (_ : k' < p), (k' : ZMod p) = k := by
exact ⟨k.val, k.val_lt, ZMod.natCast_zmod_val k⟩
have hpk : p ∣ k ^ 2 + 1 := by
rw [pow_two, ← CharP.cast_eq_zero_iff (ZMod p) p, Nat.cast_add, Nat.cast_mul, Nat.cast_one,
← hk, neg_add_cancel]
have hkmul : (k ^ 2 + 1 : ℤ[i]) = ⟨k, 1⟩ * ⟨k, -1⟩ := by ext <;> simp [sq]
have hkltp : 1 + k * k < p * p :=
calc
1 + k * k ≤ k + k * k := by
apply add_le_add_right
exact (Nat.pos_of_ne_zero fun (hk0 : k = 0) => by clear_aux_decl; simp_all)
_ = k * (k + 1) := by simp [add_comm, mul_add]
_ < p * p := mul_lt_mul k_lt_p k_lt_p (Nat.succ_pos _) (Nat.zero_le _)
have hpk₁ : ¬(p : ℤ[i]) ∣ ⟨k, -1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, -1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (-1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
have hpk₂ : ¬(p : ℤ[i]) ∣ ⟨k, 1⟩ := fun ⟨x, hx⟩ =>
lt_irrefl (p * x : ℤ[i]).norm.natAbs <|
calc
(norm (p * x : ℤ[i])).natAbs = (Zsqrtd.norm ⟨k, 1⟩).natAbs := by rw [hx]
_ < (norm (p : ℤ[i])).natAbs := by simpa [add_comm, Zsqrtd.norm] using hkltp
_ ≤ (norm (p * x : ℤ[i])).natAbs :=
norm_le_norm_mul_left _ fun hx0 =>
show (1 : ℤ) ≠ 0 by decide <| by simpa [hx0] using congr_arg Zsqrtd.im hx
obtain ⟨y, hy⟩ := hpk
have := hpi.2.2 ⟨k, 1⟩ ⟨k, -1⟩ ⟨y, by rw [← hkmul, ← Nat.cast_mul p, ← hy]; simp⟩
tauto
theorem prime_of_nat_prime_of_mod_four_eq_three (p : ℕ) [Fact p.Prime] (hp3 : p % 4 = 3) :
Prime (p : ℤ[i]) :=
irreducible_iff_prime.1 <|
by_contradiction fun hpi =>
let ⟨a, b, hab⟩ := sq_add_sq_of_nat_prime_of_not_irreducible p hpi
have : ∀ a b : ZMod 4, a ^ 2 + b ^ 2 ≠ (p : ZMod 4) := by
rw [← ZMod.natCast_mod p 4, hp3]; decide
this a b (hab ▸ by simp)
/-- A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` -/
theorem prime_iff_mod_four_eq_three_of_nat_prime (p : ℕ) [Fact p.Prime] :
Prime (p : ℤ[i]) ↔ p % 4 = 3 :=
⟨mod_four_eq_three_of_nat_prime_of_prime p, prime_of_nat_prime_of_mod_four_eq_three p⟩
end GaussianInt
|
Series.lean
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Yaël Dillies
-/
import Mathlib.Analysis.SpecialFunctions.Exponential
import Mathlib.Data.Complex.Trigonometric
/-!
# Trigonometric functions as sums of infinite series
In this file we express trigonometric functions in terms of their series expansion.
## Main results
* `Complex.hasSum_cos`, `Complex.cos_eq_tsum`: `Complex.cos` as the sum of an infinite series.
* `Real.hasSum_cos`, `Real.cos_eq_tsum`: `Real.cos` as the sum of an infinite series.
* `Complex.hasSum_sin`, `Complex.sin_eq_tsum`: `Complex.sin` as the sum of an infinite series.
* `Real.hasSum_sin`, `Real.sin_eq_tsum`: `Real.sin` as the sum of an infinite series.
-/
open NormedSpace
open scoped Nat
/-! ### `cos` and `sin` for `ℝ` and `ℂ` -/
section SinCos
theorem Complex.hasSum_cos' (z : ℂ) :
HasSum (fun n : ℕ => (z * Complex.I) ^ (2 * n) / ↑(2 * n)!) (Complex.cos z) := by
rw [Complex.cos, Complex.exp_eq_exp_ℂ]
have := ((expSeries_div_hasSum_exp ℂ (z * Complex.I)).add
(expSeries_div_hasSum_exp ℂ (-z * Complex.I))).div_const 2
replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this
dsimp [Function.comp_def] at this
simp_rw [← mul_comm 2 _] at this
refine this.prod_fiberwise fun k => ?_
dsimp only
convert hasSum_fintype (_ : Fin 2 → ℂ) using 1
rw [Fin.sum_univ_two]
simp_rw [Fin.val_zero, Fin.val_one, add_zero, pow_succ, pow_mul, mul_pow, neg_sq, ← two_mul,
neg_mul, mul_neg, neg_div, add_neg_cancel, zero_div, add_zero,
mul_div_cancel_left₀ _ (two_ne_zero : (2 : ℂ) ≠ 0)]
theorem Complex.hasSum_sin' (z : ℂ) :
HasSum (fun n : ℕ => (z * Complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / Complex.I)
(Complex.sin z) := by
rw [Complex.sin, Complex.exp_eq_exp_ℂ]
have := (((expSeries_div_hasSum_exp ℂ (-z * Complex.I)).sub
(expSeries_div_hasSum_exp ℂ (z * Complex.I))).mul_right Complex.I).div_const 2
replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this
dsimp [Function.comp_def] at this
simp_rw [← mul_comm 2 _] at this
refine this.prod_fiberwise fun k => ?_
dsimp only
convert hasSum_fintype (_ : Fin 2 → ℂ) using 1
rw [Fin.sum_univ_two]
simp_rw [Fin.val_zero, Fin.val_one, add_zero, pow_succ, pow_mul, mul_pow, neg_sq, sub_self,
zero_mul, zero_div, zero_add, neg_mul, mul_neg, neg_div, ← neg_add', ← two_mul,
neg_mul, neg_div, mul_assoc, mul_div_cancel_left₀ _ (two_ne_zero : (2 : ℂ) ≠ 0), Complex.div_I]
/-- The power series expansion of `Complex.cos`. -/
theorem Complex.hasSum_cos (z : ℂ) :
HasSum (fun n : ℕ => (-1) ^ n * z ^ (2 * n) / ↑(2 * n)!) (Complex.cos z) := by
convert Complex.hasSum_cos' z using 1
simp_rw [mul_pow, pow_mul, Complex.I_sq, mul_comm]
/-- The power series expansion of `Complex.sin`. -/
theorem Complex.hasSum_sin (z : ℂ) :
HasSum (fun n : ℕ => (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)!) (Complex.sin z) := by
convert Complex.hasSum_sin' z using 1
simp_rw [mul_pow, pow_succ, pow_mul, Complex.I_sq, ← mul_assoc, mul_div_assoc, div_right_comm,
div_self Complex.I_ne_zero, mul_comm _ ((-1 : ℂ) ^ _), mul_one_div, mul_div_assoc, mul_assoc]
theorem Complex.cos_eq_tsum' (z : ℂ) :
Complex.cos z = ∑' n : ℕ, (z * Complex.I) ^ (2 * n) / ↑(2 * n)! :=
(Complex.hasSum_cos' z).tsum_eq.symm
theorem Complex.sin_eq_tsum' (z : ℂ) :
Complex.sin z = ∑' n : ℕ, (z * Complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / Complex.I :=
(Complex.hasSum_sin' z).tsum_eq.symm
theorem Complex.cos_eq_tsum (z : ℂ) :
Complex.cos z = ∑' n : ℕ, (-1) ^ n * z ^ (2 * n) / ↑(2 * n)! :=
(Complex.hasSum_cos z).tsum_eq.symm
theorem Complex.sin_eq_tsum (z : ℂ) :
Complex.sin z = ∑' n : ℕ, (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)! :=
(Complex.hasSum_sin z).tsum_eq.symm
/-- The power series expansion of `Real.cos`. -/
theorem Real.hasSum_cos (r : ℝ) :
HasSum (fun n : ℕ => (-1) ^ n * r ^ (2 * n) / ↑(2 * n)!) (Real.cos r) :=
mod_cast Complex.hasSum_cos r
/-- The power series expansion of `Real.sin`. -/
theorem Real.hasSum_sin (r : ℝ) :
HasSum (fun n : ℕ => (-1) ^ n * r ^ (2 * n + 1) / ↑(2 * n + 1)!) (Real.sin r) :=
mod_cast Complex.hasSum_sin r
theorem Real.cos_eq_tsum (r : ℝ) : Real.cos r = ∑' n : ℕ, (-1) ^ n * r ^ (2 * n) / ↑(2 * n)! :=
(Real.hasSum_cos r).tsum_eq.symm
theorem Real.sin_eq_tsum (r : ℝ) :
Real.sin r = ∑' n : ℕ, (-1) ^ n * r ^ (2 * n + 1) / ↑(2 * n + 1)! :=
(Real.hasSum_sin r).tsum_eq.symm
end SinCos
/-! ### `cosh` and `sinh` for `ℝ` and `ℂ` -/
section SinhCosh
namespace Complex
/-- The power series expansion of `Complex.cosh`. -/
lemma hasSum_cosh (z : ℂ) : HasSum (fun n ↦ z ^ (2 * n) / ↑(2 * n)!) (cosh z) := by
simpa [mul_assoc, cos_mul_I] using hasSum_cos' (z * I)
/-- The power series expansion of `Complex.sinh`. -/
lemma hasSum_sinh (z : ℂ) : HasSum (fun n ↦ z ^ (2 * n + 1) / ↑(2 * n + 1)!) (sinh z) := by
simpa [mul_assoc, sin_mul_I, neg_pow z, pow_add, pow_mul, neg_mul, neg_div]
using (hasSum_sin' (z * I)).mul_right (-I)
lemma cosh_eq_tsum (z : ℂ) : cosh z = ∑' n, z ^ (2 * n) / ↑(2 * n)! := z.hasSum_cosh.tsum_eq.symm
lemma sinh_eq_tsum (z : ℂ) : sinh z = ∑' n, z ^ (2 * n + 1) / ↑(2 * n + 1)! :=
z.hasSum_sinh.tsum_eq.symm
end Complex
namespace Real
/-- The power series expansion of `Real.cosh`. -/
lemma hasSum_cosh (r : ℝ) : HasSum (fun n ↦ r ^ (2 * n) / ↑(2 * n)!) (cosh r) :=
mod_cast Complex.hasSum_cosh r
/-- The power series expansion of `Real.sinh`. -/
lemma hasSum_sinh (r : ℝ) : HasSum (fun n ↦ r ^ (2 * n + 1) / ↑(2 * n + 1)!) (sinh r) :=
mod_cast Complex.hasSum_sinh r
lemma cosh_eq_tsum (r : ℝ) : cosh r = ∑' n, r ^ (2 * n) / ↑(2 * n)! := r.hasSum_cosh.tsum_eq.symm
lemma sinh_eq_tsum (r : ℝ) : sinh r = ∑' n, r ^ (2 * n + 1) / ↑(2 * n + 1)! :=
r.hasSum_sinh.tsum_eq.symm
lemma cosh_le_exp_half_sq (x : ℝ) : cosh x ≤ exp (x ^ 2 / 2) := by
rw [cosh_eq_tsum, exp_eq_exp_ℝ, exp_eq_tsum]
refine x.hasSum_cosh.summable.tsum_le_tsum (fun i ↦ ?_) <| expSeries_summable' (x ^ 2 / 2)
simp only [div_pow, pow_mul, smul_eq_mul, inv_mul_eq_div, div_div]
gcongr
norm_cast
exact Nat.two_pow_mul_factorial_le_factorial_two_mul _
end Real
end SinhCosh
|
generic_quotient.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice.
From mathcomp Require Import seq fintype.
(*****************************************************************************)
(* Quotient Types *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* Provided a base type T, this files defines an interface for quotients Q *)
(* of the type T with explicit functions for canonical surjection (\pi *)
(* : T -> Q) and for choosing a representative (repr : Q -> T). It then *)
(* provides a helper to quotient T by a decidable equivalence relation (e *)
(* : rel T) if T is a choiceType (or encodable as a choiceType modulo e). *)
(* *)
(* Reference: Cyril Cohen, Pragmatic Quotient Types in Coq, ITP 2013 *)
(* *)
(* *** Generic Quotienting *** *)
(* quotType T == the type of quotient types based on T *)
(* The HB class is called Quotient. *)
(* *)
(* The quotType interface supports these operations (in quotient_scope): *)
(* \pi_Q x == the class in Q of the element x of T *)
(* \pi x == the class of x where Q is inferred from the context *)
(* repr c == canonical representative in T of the class c *)
(* x = y %[mod Q] := \pi_Q x = \pi_Q y *)
(* <-> x and y are equal modulo Q *)
(* x <> y %[mod Q] := \pi_Q x <> \pi_Q y *)
(* x == y %[mod Q] := \pi_Q x == \pi_Q y *)
(* x != y %[mod Q] := \pi_Q x != \pi_Q y *)
(* *)
(* The quotient_scope is delimited by %qT, *)
(* The most useful lemmas are piE and reprK. *)
(* *)
(* List of factories: *)
(* isQuotient.Build T Q (reprK : cancel repr pi) == builds the quotient *)
(* whose canonical surjection function is (pi : T -> Q) and *)
(* whose representative selection function is repr *)
(* *** Morphisms *** *)
(* One may declare existing functions and predicates as liftings of some *)
(* morphisms for a quotient. *)
(* PiMorph1 pi_f == where pi_f : {morph \pi : x / f x >-> fq x} *)
(* declares fq : Q -> Q as the lifting of f : T -> T *)
(* PiMorph2 pi_g == idem with pi_g : {morph \pi : x y / g x y >-> gq x y} *)
(* PiMono1 pi_p == idem with pi_p : {mono \pi : x / p x >-> pq x} *)
(* PiMono2 pi_r == idem with pi_r : {morph \pi : x y / r x y >-> rq x y} *)
(* PiMorph11 pi_f == idem with pi_f : {morph \pi : x / f x >-> fq x} *)
(* where fq : Q -> Q' and f : T -> T'. *)
(* PiMorph eq == Most general declaration of compatibility, *)
(* /!\ use with caution /!\ *)
(* One can use the following helpers to build the liftings which may or *)
(* may not satisfy the above properties (but if they do not, it is *)
(* probably not a good idea to define them): *)
(* lift_op1 Q f := lifts f : T -> T *)
(* lift_op2 Q g := lifts g : T -> T -> T *)
(* lift_fun1 Q p := lifts p : T -> R *)
(* lift_fun2 Q r := lifts r : T -> T -> R *)
(* lift_op11 Q Q' f := lifts f : T -> T' *)
(* There is also the special case of constants and embedding functions *)
(* that one may define and declare as compatible with Q using: *)
(* lift_cst Q x := lifts x : T to Q *)
(* PiConst c := declare the result c of the previous construction as *)
(* compatible with Q *)
(* lift_embed Q e := lifts e : R -> T to R -> Q *)
(* PiEmbed f := declare the result f of the previous construction as *)
(* compatible with Q *)
(* *)
(* *** Quotients that have an eqType structure *** *)
(* Having a canonical (eqQuotType e) structure enables piE to replace terms *)
(* of the form (x == y) by terms of the form (e x' y') if x and y are *)
(* canonical surjections of some x' and y'. *)
(* eqQuotType e == the type of quotients types on T which mirror *)
(* the equivalence relation (e : rel T) *)
(* the HB class is called EqQuotient. *)
(* *)
(* The most useful property is that an eqQuotType is an eqType. *)
(* List of factories: *)
(* isEqQuotient.Build T e Q m *)
(* == builds an (eqQuotType e) structure on Q from the *)
(* morphism property m *)
(* where m : {mono \pi : x y / e x y >-> x == y} *)
(* *)
(* *** Equivalence and quotient by an equivalence *** *)
(* EquivRel r er es et == builds an equiv_rel structure based on the *)
(* reflexivity, symmetry and transitivity property *)
(* of a boolean relation. *)
(* {eq_quot e} == builds the quotType of T by equiv *)
(* where e : rel T is an equiv_rel *)
(* and T is a choiceType or a (choiceTypeMod e) *)
(* it is canonically an eqType, a choiceType, *)
(* a quotType and an eqQuotType *)
(* x = y %[mod_eq e] := x = y %[mod {eq_quot e}] *)
(* <-> x and y are equal modulo e *)
(* ... *)
(*****************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope quotient_scope.
Reserved Notation "\pi_ Q" (at level 0, format "\pi_ Q").
Reserved Notation "\pi" (format "\pi").
Reserved Notation "{pi_ Q a }" (Q at next level, format "{pi_ Q a }").
Reserved Notation "{pi a }" (format "{pi a }").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x == y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' == y '/' %[mod_eq e ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x = y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' = y '/' %[mod_eq e ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x != y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' != y '/' %[mod_eq e ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x <> y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' <> y '/' %[mod_eq e ] ']'").
Reserved Notation "{eq_quot e }" (format "{eq_quot e }").
Delimit Scope quotient_scope with qT.
Local Open Scope quotient_scope.
(*****************************************)
(* Definition of the quotient interface. *)
(*****************************************)
HB.mixin Record isQuotient T (qT : Type) := {
repr_of : qT -> T;
quot_pi_subdef : T -> qT;
repr_ofK_subproof : cancel repr_of quot_pi_subdef
}.
#[short(type="quotType")]
HB.structure Definition Quotient T := { qT of isQuotient T qT }.
Arguments repr_of [T qT] : rename.
Section QuotientDef.
Variable T : Type.
Variable qT : quotType T.
Definition pi_subdef := @quot_pi_subdef _ qT.
Local Notation "\pi" := pi_subdef.
Lemma repr_ofK : cancel (@repr_of _ _) \pi.
Proof. exact: repr_ofK_subproof. Qed.
End QuotientDef.
Arguments repr_ofK {T qT}.
(****************************)
(* Protecting some symbols. *)
(****************************)
HB.lock Definition pi := pi_subdef.
HB.lock Definition mpi := pi_subdef.
HB.lock Definition repr := repr_of.
(*******************)
(* Fancy Notations *)
(*******************)
Arguments pi.body [T]%_type qT%_type.
Notation "\pi_ Q" := (@pi _ Q) : quotient_scope.
Notation "\pi" := (@pi _ _) (only parsing) : quotient_scope.
Notation "x == y %[mod Q ]" := (\pi_Q x == \pi_Q y) : quotient_scope.
Notation "x = y %[mod Q ]" := (\pi_Q x = \pi_Q y) : quotient_scope.
Notation "x != y %[mod Q ]" := (\pi_Q x != \pi_Q y) : quotient_scope.
Notation "x <> y %[mod Q ]" := (\pi_Q x <> \pi_Q y) : quotient_scope.
Local Notation "\mpi" := (@mpi _ _).
Canonical mpi_unlock := Unlockable mpi.unlock.
Canonical pi_unlock := Unlockable pi.unlock.
Canonical repr_unlock := Unlockable repr.unlock.
Arguments repr {T qT} x.
(************************)
(* Exporting the theory *)
(************************)
Section QuotTypeTheory.
Variable T : Type.
Variable qT : quotType T.
Lemma reprK : cancel repr \pi_qT.
Proof. by move=> x; rewrite !unlock repr_ofK. Qed.
Variant pi_spec (x : T) : T -> Type :=
PiSpec y of x = y %[mod qT] : pi_spec x y.
Lemma piP (x : T) : pi_spec x (repr (\pi_qT x)).
Proof. by constructor; rewrite reprK. Qed.
Lemma mpiE : \mpi =1 \pi_qT.
Proof. by move=> x; rewrite !unlock. Qed.
Lemma quotW P : (forall y : T, P (\pi_qT y)) -> forall x : qT, P x.
Proof. by move=> Py x; rewrite -[x]reprK; apply: Py. Qed.
Lemma quotP P : (forall y : T, repr (\pi_qT y) = y -> P (\pi_qT y))
-> forall x : qT, P x.
Proof. by move=> Py x; rewrite -[x]reprK; apply: Py; rewrite reprK. Qed.
End QuotTypeTheory.
Arguments reprK {T qT} x.
(*******************)
(* About morphisms *)
(*******************)
(* This was pi_morph T (x : T) := PiMorph { pi_op : T; _ : x = pi_op }. *)
Structure equal_to T (x : T) := EqualTo {
equal_val : T;
_ : x = equal_val
}.
Lemma equal_toE (T : Type) (x : T) (m : equal_to x) : equal_val m = x.
Proof. by case: m. Qed.
Notation piE := (@equal_toE _ _).
Canonical equal_to_pi T (qT : quotType T) (x : T) :=
@EqualTo _ (\pi_qT x) (\pi x) (erefl _).
Arguments EqualTo {T x equal_val}.
Section Morphism.
Variables T U : Type.
Variable (qT : quotType T).
Variable (qU : quotType U).
Variable (f : T -> T) (g : T -> T -> T) (p : T -> U) (r : T -> T -> U).
Variable (fq : qT -> qT) (gq : qT -> qT -> qT) (pq : qT -> U) (rq : qT -> qT -> U).
Variable (h : T -> U) (hq : qT -> qU).
Hypothesis pi_f : {morph \pi : x / f x >-> fq x}.
Hypothesis pi_g : {morph \pi : x y / g x y >-> gq x y}.
Hypothesis pi_p : {mono \pi : x / p x >-> pq x}.
Hypothesis pi_r : {mono \pi : x y / r x y >-> rq x y}.
Hypothesis pi_h : forall (x : T), \pi_qU (h x) = hq (\pi_qT x).
Variables (a b : T) (x : equal_to (\pi_qT a)) (y : equal_to (\pi_qT b)).
(* Internal Lemmas : do not use directly *)
Lemma pi_morph1 : \pi (f a) = fq (equal_val x). Proof. by rewrite !piE. Qed.
Lemma pi_morph2 : \pi (g a b) = gq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed.
Lemma pi_mono1 : p a = pq (equal_val x). Proof. by rewrite !piE. Qed.
Lemma pi_mono2 : r a b = rq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed.
Lemma pi_morph11 : \pi (h a) = hq (equal_val x). Proof. by rewrite !piE. Qed.
End Morphism.
Arguments pi_morph1 {T qT f fq}.
Arguments pi_morph2 {T qT g gq}.
Arguments pi_mono1 {T U qT p pq}.
Arguments pi_mono2 {T U qT r rq}.
Arguments pi_morph11 {T U qT qU h hq}.
Notation "{pi_ Q a }" := (equal_to (\pi_Q a)) : quotient_scope.
Notation "{pi a }" := (equal_to (\pi a)) : quotient_scope.
(* Declaration of morphisms *)
Notation PiMorph pi_x := (EqualTo pi_x).
Notation PiMorph1 pi_f :=
(fun a (x : {pi a}) => EqualTo (pi_morph1 pi_f a x)).
Notation PiMorph2 pi_g :=
(fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_morph2 pi_g a b x y)).
Notation PiMono1 pi_p :=
(fun a (x : {pi a}) => EqualTo (pi_mono1 pi_p a x)).
Notation PiMono2 pi_r :=
(fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_mono2 pi_r a b x y)).
Notation PiMorph11 pi_f :=
(fun a (x : {pi a}) => EqualTo (pi_morph11 pi_f a x)).
(* lifting helpers *)
Notation lift_op1 Q f := (locked (fun x : Q => \pi_Q (f (repr x)) : Q)).
Notation lift_op2 Q g :=
(locked (fun x y : Q => \pi_Q (g (repr x) (repr y)) : Q)).
Notation lift_fun1 Q f := (locked (fun x : Q => f (repr x))).
Notation lift_fun2 Q g := (locked (fun x y : Q => g (repr x) (repr y))).
Notation lift_op11 Q Q' f := (locked (fun x : Q => \pi_Q' (f (repr x)) : Q')).
(* constant declaration *)
Notation lift_cst Q x := (locked (\pi_Q x : Q)).
Notation PiConst a := (@EqualTo _ _ a (lock _)).
(* embedding declaration, please don't redefine \pi *)
Notation lift_embed qT e := (locked (fun x => \pi_qT (e x) : qT)).
Lemma eq_lock T T' e : e =1 (@locked (T -> T') (fun x : T => e x)).
Proof. by rewrite -lock. Qed.
Prenex Implicits eq_lock.
Notation PiEmbed e :=
(fun x => @EqualTo _ _ (e x) (eq_lock (fun _ => \pi _) _)).
(********************)
(* About eqQuotType *)
(********************)
HB.mixin Record isEqQuotient T (eq_quot_op : rel T) (Q : Type) of
isQuotient T Q & hasDecEq Q := {
pi_eq_quot : {mono \pi_Q : x y / eq_quot_op x y >-> x == y}
}.
#[short(type="eqQuotType")]
HB.structure Definition EqQuotient T eq_quot_op :=
{Q of isEqQuotient T eq_quot_op Q & Quotient T Q & hasDecEq Q}.
Canonical pi_eq_quot_mono T eq_quot_op eqT :=
PiMono2 (@pi_eq_quot T eq_quot_op eqT).
(**************************************************************************)
(* Even if a quotType is a natural subType, we do not make this subType *)
(* canonical, to allow the user to define the subtyping he wants. However *)
(* one can: *)
(* - get the hasDecEq and the hasChoice by subtyping *)
(* - get the subType structure and maybe declare it Canonical. *)
(**************************************************************************)
Definition quot_type_of T (qT : quotType T) : Type := qT.
Arguments quot_type_of T%_type qT%_type : clear implicits.
Notation quot_type Q := (quot_type_of _ Q).
HB.instance Definition _ T (qT : quotType T) := Quotient.on (quot_type qT).
Module QuotSubType.
Section QuotSubType.
Variable (T : eqType) (qT : quotType T).
Definition Sub x (px : repr (\pi_qT x) == x) := \pi_qT x.
Lemma qreprK x Px : repr (@Sub x Px) = x.
Proof. by rewrite /Sub (eqP Px). Qed.
Lemma sortPx (x : qT) : repr (\pi_qT (repr x)) == repr x.
Proof. by rewrite !reprK eqxx. Qed.
Lemma sort_Sub (x : qT) : x = Sub (sortPx x).
Proof. by rewrite /Sub reprK. Qed.
Lemma reprP K (PK : forall x Px, K (@Sub x Px)) u : K u.
Proof. by rewrite (sort_Sub u); apply: PK. Qed.
#[export]
HB.instance Definition _ := isSub.Build _ _ (quot_type qT) reprP qreprK.
#[export]
HB.instance Definition _ := [Equality of quot_type qT by <:].
End QuotSubType.
Module Exports. HB.reexport. End Exports.
End QuotSubType.
Export QuotSubType.Exports.
HB.instance Definition _ (T : choiceType) (qT : quotType T) :=
[Choice of quot_type qT by <:].
HB.instance Definition _ (T : countType) (qT : quotType T) :=
[Countable of quot_type qT by <:].
HB.instance Definition _ (T : finType) (qT : quotType T) :=
[Finite of quot_type qT by <:].
Notation "[ 'Sub' Q 'of' T 'by' %/ ]" :=
(SubType.copy Q%type (quot_type_of T Q%type))
(format "[ 'Sub' Q 'of' T 'by' %/ ]") : form_scope.
Notation "[ 'Sub' Q 'by' %/ ]" :=
(SubType.copy Q%type (quot_type Q))
(format "[ 'Sub' Q 'by' %/ ]") : form_scope.
Notation "[ 'Equality' 'of' Q 'by' <:%/ ]" :=
(Equality.copy Q%type (quot_type Q))
(format "[ 'Equality' 'of' Q 'by' <:%/ ]") : form_scope.
Notation "[ 'Choice' 'of' Q 'by' <:%/ ]" := (Choice.copy Q%type (quot_type Q))
(format "[ 'Choice' 'of' Q 'by' <:%/ ]") : form_scope.
Notation "[ 'Countable' 'of' Q 'by' <:%/ ]" := (Countable.copy Q%type (quot_type Q))
(format "[ 'Countable' 'of' Q 'by' <:%/ ]") : form_scope.
Notation "[ 'Finite' 'of' Q 'by' <:%/ ]" := (Finite.copy Q%type (quot_type Q))
(format "[ 'Finite' 'of' Q 'by' <:%/ ]") : form_scope.
(****************************************************)
(* Definition of a (decidable) equivalence relation *)
(****************************************************)
Section EquivRel.
Variable T : Type.
Lemma left_trans (e : rel T) :
symmetric e -> transitive e -> left_transitive e.
Proof. by move=> s t ? * ?; apply/idP/idP; apply: t; rewrite // s. Qed.
Lemma right_trans (e : rel T) :
symmetric e -> transitive e -> right_transitive e.
Proof. by move=> s t ? * x; rewrite ![e x _]s; apply: left_trans. Qed.
Variant equiv_class_of (equiv : rel T) :=
EquivClass of reflexive equiv & symmetric equiv & transitive equiv.
Record equiv_rel := EquivRelPack {
equiv :> rel T;
_ : equiv_class_of equiv
}.
Variable e : equiv_rel.
Definition equiv_class :=
let: EquivRelPack _ ce as e' := e return equiv_class_of e' in ce.
Definition equiv_pack (r : rel T) ce of phant_id ce equiv_class :=
@EquivRelPack r ce.
Lemma equiv_refl x : e x x. Proof. by case: e => [] ? []. Qed.
Lemma equiv_sym : symmetric e. Proof. by case: e => [] ? []. Qed.
Lemma equiv_trans : transitive e. Proof. by case: e => [] ? []. Qed.
Lemma eq_op_trans (T' : eqType) : transitive (@eq_op T').
Proof. by move=> x y z /eqP -> /eqP ->. Qed.
Lemma equiv_ltrans: left_transitive e.
Proof. by apply: left_trans; [apply: equiv_sym|apply: equiv_trans]. Qed.
Lemma equiv_rtrans: right_transitive e.
Proof. by apply: right_trans; [apply: equiv_sym|apply: equiv_trans]. Qed.
End EquivRel.
#[global] Hint Resolve equiv_refl : core.
Notation EquivRel r er es et := (@EquivRelPack _ r (EquivClass er es et)).
Notation "[ 'equiv_rel' 'of' e ]" := (@equiv_pack _ _ e _ id)
(format "[ 'equiv_rel' 'of' e ]") : form_scope.
(**************************************************)
(* Encoding to another type modulo an equivalence *)
(**************************************************)
Section EncodingModuloRel.
Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : rel D).
Variant encModRel_class_of (r : rel D) :=
EncModRelClassPack of (forall x, r x x -> r (ED (DE x)) x) & (r =2 e).
Record encModRel := EncModRelPack {
enc_mod_rel :> rel D;
_ : encModRel_class_of enc_mod_rel
}.
Variable r : encModRel.
Definition encModRelClass :=
let: EncModRelPack _ c as r' := r return encModRel_class_of r' in c.
Definition encModRelP (x : D) : r x x -> r (ED (DE x)) x.
Proof. by case: r => [] ? [] /= he _ /he. Qed.
Definition encModRelE : r =2 e. Proof. by case: r => [] ? []. Qed.
Definition encoded_equiv : rel E := [rel x y | r (ED x) (ED y)].
End EncodingModuloRel.
Notation EncModRelClass m :=
(EncModRelClassPack (fun x _ => m x) (fun _ _ => erefl _)).
Notation EncModRel r m := (@EncModRelPack _ _ _ _ _ r (EncModRelClass m)).
Section EncodingModuloEquiv.
Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : equiv_rel D).
Variable (r : encModRel ED DE e).
Lemma enc_mod_rel_is_equiv : equiv_class_of (enc_mod_rel r).
Proof.
split => [x|x y|y x z]; rewrite !encModRelE //; first by rewrite equiv_sym.
by move=> exy /(equiv_trans exy).
Qed.
Definition enc_mod_rel_equiv_rel := EquivRelPack enc_mod_rel_is_equiv.
Definition encModEquivP (x : D) : r (ED (DE x)) x.
Proof. by rewrite encModRelP ?encModRelE. Qed.
Local Notation e' := (encoded_equiv r).
Lemma encoded_equivE : e' =2 [rel x y | e (ED x) (ED y)].
Proof. by move=> x y; rewrite /encoded_equiv /= encModRelE. Qed.
Local Notation e'E := encoded_equivE.
Lemma encoded_equiv_is_equiv : equiv_class_of e'.
Proof.
split => [x|x y|y x z]; rewrite !e'E //=; first by rewrite equiv_sym.
by move=> exy /(equiv_trans exy).
Qed.
Canonical encoded_equiv_equiv_rel := EquivRelPack encoded_equiv_is_equiv.
Lemma encoded_equivP x : e' (DE (ED x)) x.
Proof. by rewrite /encoded_equiv /= encModEquivP. Qed.
End EncodingModuloEquiv.
(**************************************)
(* Quotient by a equivalence relation *)
(**************************************)
Module EquivQuot.
Section EquivQuot.
Variables (D : Type) (C : choiceType) (CD : C -> D) (DC : D -> C).
Variables (eD : equiv_rel D) (encD : encModRel CD DC eD).
Notation eC := (encoded_equiv encD).
Definition canon x := choose (eC x) (x).
Record equivQuotient := EquivQuotient {
erepr : C;
_ : (frel canon) erepr erepr
}.
Definition type_of of (phantom (rel _) encD) := equivQuotient.
Lemma canon_id : forall x, (invariant canon canon) x.
Proof.
move=> x /=; rewrite /canon (@eq_choose _ _ (eC x)).
by rewrite (@choose_id _ (eC x) _ x) ?chooseP ?equiv_refl.
by move=> y; apply: equiv_ltrans; rewrite equiv_sym /= chooseP.
Qed.
Definition pi := locked (fun x => EquivQuotient (canon_id x)).
Lemma ereprK : cancel erepr pi.
Proof.
pose T : subType _ := HB.pack equivQuotient [isSub for erepr].
by unlock pi; case=> x hx; apply/(@val_inj _ _ T)/eqP.
Qed.
Local Notation encDE := (encModRelE encD).
Local Notation encDP := (encModEquivP encD).
Canonical encD_equiv_rel := EquivRelPack (enc_mod_rel_is_equiv encD).
Lemma pi_CD (x y : C) : reflect (pi x = pi y) (eC x y).
Proof.
apply: (iffP idP) => hxy.
apply: (can_inj ereprK); unlock pi canon => /=.
rewrite -(@eq_choose _ (eC x) (eC y)); last first.
by move=> z; rewrite /eC /=; apply: equiv_ltrans.
by apply: choose_id; rewrite ?equiv_refl //.
rewrite (equiv_trans (chooseP (equiv_refl _ _))) //=.
move: hxy => /(f_equal erepr) /=; unlock pi canon => /= ->.
by rewrite equiv_sym /= chooseP.
Qed.
Lemma pi_DC (x y : D) :
reflect (pi (DC x) = pi (DC y)) (eD x y).
Proof.
apply: (iffP idP)=> hxy.
apply/pi_CD; rewrite /eC /=.
by rewrite (equiv_ltrans (encDP _)) (equiv_rtrans (encDP _)) /= encDE.
rewrite -encDE -(equiv_ltrans (encDP _)) -(equiv_rtrans (encDP _)) /=.
exact/pi_CD.
Qed.
Lemma equivQTP : cancel (CD \o erepr) (pi \o DC).
Proof. by move=> x; rewrite /= (pi_CD _ (erepr x) _) ?ereprK /eC /= ?encDP. Qed.
Local Notation qT := (type_of (Phantom (rel D) encD)).
#[export]
HB.instance Definition _ := isQuotient.Build D qT equivQTP.
Lemma eqmodP x y : reflect (x = y %[mod qT]) (eD x y).
Proof. by apply: (iffP (pi_DC _ _)); rewrite !unlock. Qed.
#[export]
HB.instance Definition _ := Choice.copy qT (can_type ereprK).
Lemma eqmodE x y : x == y %[mod qT] = eD x y.
Proof. exact: sameP eqP (@eqmodP _ _). Qed.
#[export]
HB.instance Definition _ := isEqQuotient.Build _ eD qT eqmodE.
End EquivQuot.
Module Exports. HB.reexport. End Exports.
End EquivQuot.
Export EquivQuot.Exports.
Arguments EquivQuot.ereprK {D C CD DC eD encD}.
Notation "{eq_quot e }" :=
(@EquivQuot.type_of _ _ _ _ _ _ (Phantom (rel _) e)) : quotient_scope.
Notation "x == y %[mod_eq r ]" := (x == y %[mod {eq_quot r}]) : quotient_scope.
Notation "x = y %[mod_eq r ]" := (x = y %[mod {eq_quot r}]) : quotient_scope.
Notation "x != y %[mod_eq r ]" := (x != y %[mod {eq_quot r}]) : quotient_scope.
Notation "x <> y %[mod_eq r ]" := (x <> y %[mod {eq_quot r}]) : quotient_scope.
(***********************************************************)
(* If the type is directly a choiceType, no need to encode *)
(***********************************************************)
Section DefaultEncodingModuloRel.
Variables (D : choiceType) (r : rel D).
Definition defaultEncModRelClass :=
@EncModRelClassPack D D id id r r (fun _ rxx => rxx) (fun _ _ => erefl _).
Canonical defaultEncModRel := EncModRelPack defaultEncModRelClass.
End DefaultEncodingModuloRel.
(***************************************************)
(* Recovering a potential countable type structure *)
(***************************************************)
Section CountEncodingModuloRel.
Variables (D : Type) (C : countType) (CD : C -> D) (DC : D -> C).
Variables (eD : equiv_rel D) (encD : encModRel CD DC eD).
Notation eC := (encoded_equiv encD).
HB.instance Definition _ :=
Countable.copy {eq_quot encD} (can_type EquivQuot.ereprK).
End CountEncodingModuloRel.
Section EquivQuotTheory.
Variables (T : choiceType) (e : equiv_rel T) (Q : eqQuotType e).
Lemma eqmodE x y : x == y %[mod_eq e] = e x y.
Proof. by rewrite pi_eq_quot. Qed.
Lemma eqmodP x y : reflect (x = y %[mod_eq e]) (e x y).
Proof. by rewrite -eqmodE; apply/eqP. Qed.
End EquivQuotTheory.
Prenex Implicits eqmodE eqmodP.
Section EqQuotTheory.
Variables (T : Type) (e : rel T) (Q : eqQuotType e).
Lemma eqquotE x y : x == y %[mod Q] = e x y.
Proof. by rewrite pi_eq_quot. Qed.
Lemma eqquotP x y : reflect (x = y %[mod Q]) (e x y).
Proof. by rewrite -eqquotE; apply/eqP. Qed.
End EqQuotTheory.
Prenex Implicits eqquotE eqquotP.
|
Order.lean
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Aaron Anderson
-/
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Module.Defs
import Mathlib.Algebra.Order.Pi
import Mathlib.Algebra.Order.Sub.Basic
import Mathlib.Data.Finsupp.Basic
import Mathlib.Data.Finsupp.SMulWithZero
import Mathlib.Order.Preorder.Finsupp
/-!
# Pointwise order on finitely supported functions
This file lifts order structures on `α` to `ι →₀ α`.
## Main declarations
* `Finsupp.orderEmbeddingToFun`: The order embedding from finitely supported functions to
functions.
-/
noncomputable section
open Finset
variable {ι κ α β : Type*}
namespace Finsupp
/-! ### Order structures -/
section Zero
variable [Zero α]
section OrderedAddCommMonoid
variable [AddCommMonoid β] [PartialOrder β] [IsOrderedAddMonoid β] {f : ι →₀ α} {h₁ h₂ : ι → α → β}
@[gcongr]
lemma sum_le_sum (h : ∀ i ∈ f.support, h₁ i (f i) ≤ h₂ i (f i)) : f.sum h₁ ≤ f.sum h₂ :=
Finset.sum_le_sum h
end OrderedAddCommMonoid
section Preorder
variable [Preorder α] {f g : ι →₀ α} {i : ι} {a b : α}
@[simp] lemma single_le_single : single i a ≤ single i b ↔ a ≤ b := by
classical exact Pi.single_le_single
lemma single_mono : Monotone (single i : α → ι →₀ α) := fun _ _ ↦ single_le_single.2
@[gcongr] protected alias ⟨_, GCongr.single_mono⟩ := single_le_single
@[simp] lemma single_nonneg : 0 ≤ single i a ↔ 0 ≤ a := by classical exact Pi.single_nonneg
@[simp] lemma single_nonpos : single i a ≤ 0 ↔ a ≤ 0 := by classical exact Pi.single_nonpos
variable [AddCommMonoid β] [PartialOrder β] [IsOrderedAddMonoid β]
lemma sum_le_sum_index [DecidableEq ι] {f₁ f₂ : ι →₀ α} {h : ι → α → β} (hf : f₁ ≤ f₂)
(hh : ∀ i ∈ f₁.support ∪ f₂.support, Monotone (h i))
(hh₀ : ∀ i ∈ f₁.support ∪ f₂.support, h i 0 = 0) : f₁.sum h ≤ f₂.sum h := by
classical
rw [sum_of_support_subset _ Finset.subset_union_left _ hh₀,
sum_of_support_subset _ Finset.subset_union_right _ hh₀]
exact Finset.sum_le_sum fun i hi ↦ hh _ hi <| hf _
end Preorder
end Zero
/-! ### Algebraic order structures -/
section OrderedAddCommMonoid
variable [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α]
{i : ι} {f : ι → κ} {g g₁ g₂ : ι →₀ α}
instance isOrderedAddMonoid : IsOrderedAddMonoid (ι →₀ α) :=
{ add_le_add_left := fun _a _b h c s => add_le_add_left (h s) (c s) }
lemma mapDomain_mono : Monotone (mapDomain f : (ι →₀ α) → (κ →₀ α)) := by
classical exact fun g₁ g₂ h ↦ sum_le_sum_index h (fun _ _ ↦ single_mono) (by simp)
@[gcongr] protected lemma GCongr.mapDomain_mono (hg : g₁ ≤ g₂) : g₁.mapDomain f ≤ g₂.mapDomain f :=
mapDomain_mono hg
lemma mapDomain_nonneg (hg : 0 ≤ g) : 0 ≤ g.mapDomain f := by simpa using mapDomain_mono hg
lemma mapDomain_nonpos (hg : g ≤ 0) : g.mapDomain f ≤ 0 := by simpa using mapDomain_mono hg
end OrderedAddCommMonoid
instance isOrderedCancelAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] :
IsOrderedCancelAddMonoid (ι →₀ α) :=
{ le_of_add_le_add_left := fun _f _g _i h s => le_of_add_le_add_left (h s) }
instance addLeftReflectLE [AddCommMonoid α] [PartialOrder α] [AddLeftReflectLE α] :
AddLeftReflectLE (ι →₀ α) :=
⟨fun _f _g _h H x => le_of_add_le_add_left <| H x⟩
section SMulZeroClass
variable [Zero α] [Preorder α] [Zero β] [Preorder β] [SMulZeroClass α β]
instance instPosSMulMono [PosSMulMono α β] : PosSMulMono α (ι →₀ β) :=
PosSMulMono.lift _ coe_le_coe coe_smul
instance instSMulPosMono [SMulPosMono α β] : SMulPosMono α (ι →₀ β) :=
SMulPosMono.lift _ coe_le_coe coe_smul coe_zero
instance instPosSMulReflectLE [PosSMulReflectLE α β] : PosSMulReflectLE α (ι →₀ β) :=
PosSMulReflectLE.lift _ coe_le_coe coe_smul
instance instSMulPosReflectLE [SMulPosReflectLE α β] : SMulPosReflectLE α (ι →₀ β) :=
SMulPosReflectLE.lift _ coe_le_coe coe_smul coe_zero
end SMulZeroClass
section SMulWithZero
variable [Zero α] [PartialOrder α] [Zero β] [PartialOrder β] [SMulWithZero α β]
instance instPosSMulStrictMono [PosSMulStrictMono α β] : PosSMulStrictMono α (ι →₀ β) :=
PosSMulStrictMono.lift _ coe_le_coe coe_smul
instance instSMulPosStrictMono [SMulPosStrictMono α β] : SMulPosStrictMono α (ι →₀ β) :=
SMulPosStrictMono.lift _ coe_le_coe coe_smul coe_zero
-- `PosSMulReflectLT α (ι →₀ β)` already follows from the other instances
instance instSMulPosReflectLT [SMulPosReflectLT α β] : SMulPosReflectLT α (ι →₀ β) :=
SMulPosReflectLT.lift _ coe_le_coe coe_smul coe_zero
end SMulWithZero
section PartialOrder
variable [AddCommMonoid α] [PartialOrder α] [CanonicallyOrderedAdd α] {f g : ι →₀ α}
instance orderBot : OrderBot (ι →₀ α) where
bot := 0
bot_le := by simp only [le_def, coe_zero, Pi.zero_apply, imp_true_iff, zero_le]
protected theorem bot_eq_zero : (⊥ : ι →₀ α) = 0 :=
rfl
@[simp]
theorem add_eq_zero_iff (f g : ι →₀ α) : f + g = 0 ↔ f = 0 ∧ g = 0 := by
simp [DFunLike.ext_iff, forall_and]
theorem le_iff' (f g : ι →₀ α) {s : Finset ι} (hf : f.support ⊆ s) : f ≤ g ↔ ∀ i ∈ s, f i ≤ g i :=
⟨fun h s _hs => h s, fun h s => by
classical exact
if H : s ∈ f.support then h s (hf H) else (notMem_support_iff.1 H).symm ▸ zero_le (g s)⟩
theorem le_iff (f g : ι →₀ α) : f ≤ g ↔ ∀ i ∈ f.support, f i ≤ g i :=
le_iff' f g <| Subset.refl _
lemma support_monotone : Monotone (support (α := ι) (M := α)) :=
fun f g h a ha ↦ by rw [mem_support_iff, ← pos_iff_ne_zero] at ha ⊢; exact ha.trans_le (h _)
lemma support_mono (hfg : f ≤ g) : f.support ⊆ g.support := support_monotone hfg
instance decidableLE [DecidableLE α] : DecidableLE (ι →₀ α) := fun f g =>
decidable_of_iff _ (le_iff f g).symm
instance decidableLT [DecidableLE α] : DecidableLT (ι →₀ α) :=
decidableLTOfDecidableLE
@[simp]
theorem single_le_iff {i : ι} {x : α} {f : ι →₀ α} : single i x ≤ f ↔ x ≤ f i :=
(le_iff' _ _ support_single_subset).trans <| by simp
variable [Sub α] [OrderedSub α] {f g : ι →₀ α} {i : ι} {a b : α}
/-- This is called `tsub` for truncated subtraction, to distinguish it with subtraction in an
additive group. -/
instance tsub : Sub (ι →₀ α) :=
⟨zipWith (fun m n => m - n) (tsub_self 0)⟩
instance orderedSub : OrderedSub (ι →₀ α) :=
⟨fun _n _m _k => forall_congr' fun _x => tsub_le_iff_right⟩
instance [AddLeftMono α] : CanonicallyOrderedAdd (ι →₀ α) where
exists_add_of_le := fun {f g} h => ⟨g - f, ext fun x => (add_tsub_cancel_of_le <| h x).symm⟩
le_self_add := fun _f _g _x => le_self_add
@[simp, norm_cast] lemma coe_tsub (f g : ι →₀ α) : ⇑(f - g) = f - g := rfl
theorem tsub_apply (f g : ι →₀ α) (a : ι) : (f - g) a = f a - g a :=
rfl
@[simp]
theorem single_tsub : single i (a - b) = single i a - single i b := by
ext j
obtain rfl | h := eq_or_ne i j
· rw [tsub_apply, single_eq_same, single_eq_same, single_eq_same]
· rw [tsub_apply, single_eq_of_ne h, single_eq_of_ne h, single_eq_of_ne h, tsub_self]
theorem support_tsub {f1 f2 : ι →₀ α} : (f1 - f2).support ⊆ f1.support := by
simp +contextual only [subset_iff, tsub_eq_zero_iff_le, mem_support_iff,
Ne, coe_tsub, Pi.sub_apply, not_imp_not, zero_le, imp_true_iff]
theorem subset_support_tsub [DecidableEq ι] {f1 f2 : ι →₀ α} :
f1.support \ f2.support ⊆ (f1 - f2).support := by
simp +contextual [subset_iff]
end PartialOrder
section LinearOrder
variable [AddCommMonoid α] [LinearOrder α] [CanonicallyOrderedAdd α]
@[simp]
theorem support_inf [DecidableEq ι] (f g : ι →₀ α) : (f ⊓ g).support = f.support ∩ g.support := by
ext
simp only [inf_apply, mem_support_iff, Ne,
Finset.mem_inter]
simp only [← nonpos_iff_eq_zero, min_le_iff, not_or]
@[simp]
theorem support_sup [DecidableEq ι] (f g : ι →₀ α) : (f ⊔ g).support = f.support ∪ g.support := by
ext
simp only [mem_support_iff, Ne, sup_apply, ← nonpos_iff_eq_zero, sup_le_iff, mem_union,
not_and_or]
nonrec theorem disjoint_iff {f g : ι →₀ α} : Disjoint f g ↔ Disjoint f.support g.support := by
classical
rw [disjoint_iff, disjoint_iff, Finsupp.bot_eq_zero, ← Finsupp.support_eq_empty,
Finsupp.support_inf]
rfl
end LinearOrder
/-! ### Some lemmas about `ℕ` -/
section Nat
theorem sub_single_one_add {a : ι} {u u' : ι →₀ ℕ} (h : u a ≠ 0) :
u - single a 1 + u' = u + u' - single a 1 :=
tsub_add_eq_add_tsub <| single_le_iff.mpr <| Nat.one_le_iff_ne_zero.mpr h
theorem add_sub_single_one {a : ι} {u u' : ι →₀ ℕ} (h : u' a ≠ 0) :
u + (u' - single a 1) = u + u' - single a 1 :=
(add_tsub_assoc_of_le (single_le_iff.mpr <| Nat.one_le_iff_ne_zero.mpr h) _).symm
lemma sub_add_single_one_cancel {u : ι →₀ ℕ} {i : ι} (h : u i ≠ 0) :
u - single i 1 + single i 1 = u := by
rw [sub_single_one_add h, add_tsub_cancel_right]
end Nat
end Finsupp
|
Inverse.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Topology.Order.ProjIcc
/-!
# Inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function.
(This is delayed as it is easier to set up after developing complex trigonometric functions.)
Basic inequalities on trigonometric functions.
-/
noncomputable section
open Topology Filter Set Filter Real
namespace Real
variable {x y : ℝ}
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.
It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/
@[pp_nodot]
noncomputable def arcsin : ℝ → ℝ :=
Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm
theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) :=
Subtype.coe_prop _
@[simp]
theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by
rw [arcsin, range_comp Subtype.val]
simp [Icc]
theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 :=
(arcsin_mem_Icc x).2
theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x :=
(arcsin_mem_Icc x).1
theorem arcsin_projIcc (x : ℝ) :
arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by
rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend,
Function.comp_apply]
theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by
simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using
Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩)
theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
sin_arcsin' ⟨hx₁, hx₂⟩
theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x :=
injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]
theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
arcsin_sin' ⟨hx₁, hx₂⟩
theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) :=
(Subtype.strictMono_coe _).comp_strictMonoOn <|
sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _
@[gcongr]
theorem arcsin_lt_arcsin {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) :
arcsin x < arcsin y :=
strictMonoOn_arcsin ⟨hx, hlt.le.trans hy⟩ ⟨hx.trans hlt.le, hy⟩ hlt
theorem monotone_arcsin : Monotone arcsin :=
(Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _
@[gcongr]
theorem arcsin_le_arcsin {x y : ℝ} (h : x ≤ y) : arcsin x ≤ arcsin y := monotone_arcsin h
theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) :=
strictMonoOn_arcsin.injOn
theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arcsin x = arcsin y ↔ x = y :=
injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[continuity, fun_prop]
theorem continuous_arcsin : Continuous arcsin :=
continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend'
@[fun_prop]
theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x :=
continuous_arcsin.continuousAt
theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :
arcsin y = x := by
subst y
exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))
@[simp]
theorem arcsin_zero : arcsin 0 = 0 :=
arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩
@[simp]
theorem arcsin_one : arcsin 1 = π / 2 :=
arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by
rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one]
theorem arcsin_neg_one : arcsin (-1) = -(π / 2) :=
arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <|
left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by
rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one]
@[simp]
theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by
rcases le_total x (-1) with hx₁ | hx₁
· rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)]
rcases le_total 1 x with hx₂ | hx₂
· rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)]
refine arcsin_eq_of_sin_eq ?_ ?_
· rw [sin_neg, sin_arcsin hx₁ hx₂]
· exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩
theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y := by
rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]
theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y := by
rcases le_total x (-1) with hx₁ | hx₁
· simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)]
rcases lt_or_ge 1 x with hx₂ | hx₂
· simp [arcsin_of_one_le hx₂.le, hy.2.not_ge, (sin_le_one y).trans_lt hx₂]
exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)
theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x ≤ arcsin y ↔ sin x ≤ y := by
rw [← neg_le_neg_iff, ← arcsin_neg,
arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg,
neg_le_neg_iff]
theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :
x ≤ arcsin y ↔ sin x ≤ y := by
rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le
theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le
theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le
theorem lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le
theorem arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :
arcsin x = y ↔ x = sin y := by
simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),
le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]
@[simp]
theorem arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=
(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans <| by
rw [sin_zero]
@[simp]
theorem arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=
neg_nonneg.symm.trans <| arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg
@[simp]
theorem arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff]
@[simp]
theorem zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=
eq_comm.trans arcsin_eq_zero_iff
@[simp]
theorem arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le arcsin_nonpos
@[simp]
theorem arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=
lt_iff_lt_of_le_iff_le arcsin_nonneg
@[simp]
theorem arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 :=
(arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by
rw [sin_pi_div_two]
@[simp]
theorem neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x :=
(lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by
rw [sin_neg, sin_pi_div_two]
@[simp]
theorem arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=
⟨fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩
@[simp]
theorem pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=
eq_comm.trans arcsin_eq_pi_div_two
@[simp]
theorem pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x :=
(arcsin_le_pi_div_two x).ge_iff_eq'.trans pi_div_two_eq_arcsin
@[simp]
theorem arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=
⟨fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩
@[simp]
theorem neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=
eq_comm.trans arcsin_eq_neg_pi_div_two
@[simp]
theorem arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=
(neg_pi_div_two_le_arcsin x).ge_iff_eq'.trans arcsin_eq_neg_pi_div_two
@[simp]
theorem pi_div_four_le_arcsin {x} : π / 4 ≤ arcsin x ↔ √2 / 2 ≤ x := by
rw [← sin_pi_div_four, le_arcsin_iff_sin_le']
have := pi_pos
constructor <;> linarith
theorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := fun x h => by
rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le]
/-- `Real.sin` as a `PartialHomeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/
@[simp]
def sinPartialHomeomorph : PartialHomeomorph ℝ ℝ where
toFun := sin
invFun := arcsin
source := Ioo (-(π / 2)) (π / 2)
target := Ioo (-1) 1
map_source' := mapsTo_sin_Ioo
map_target' _ hy := ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩
left_inv' _ hx := arcsin_sin hx.1.le hx.2.le
right_inv' _ hy := sin_arcsin hy.1.le hy.2.le
open_source := isOpen_Ioo
open_target := isOpen_Ioo
continuousOn_toFun := continuous_sin.continuousOn
continuousOn_invFun := continuous_arcsin.continuousOn
theorem cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.
theorem cos_arcsin (x : ℝ) : cos (arcsin x) = √(1 - x ^ 2) := by
by_cases hx₁ : -1 ≤ x; swap
· rw [not_le] at hx₁
rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos]
nlinarith
by_cases hx₂ : x ≤ 1; swap
· rw [not_le] at hx₂
rw [arcsin_of_one_le hx₂.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos]
nlinarith
have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x)
rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq,
sqrt_mul_self (cos_arcsin_nonneg _)] at this
rw [this, sin_arcsin hx₁ hx₂]
-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.
theorem tan_arcsin (x : ℝ) : tan (arcsin x) = x / √(1 - x ^ 2) := by
rw [tan_eq_sin_div_cos, cos_arcsin]
by_cases hx₁ : -1 ≤ x; swap
· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)
rw [h]
simp
by_cases hx₂ : x ≤ 1; swap
· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)
rw [h]
simp
rw [sin_arcsin hx₁ hx₂]
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
It defaults to `π` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/
@[pp_nodot]
noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
theorem arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x :=
rfl
theorem arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [arccos]
theorem arccos_le_pi (x : ℝ) : arccos x ≤ π := by
unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
theorem arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by
unfold arccos; linarith [arcsin_le_pi_div_two x]
@[simp]
theorem arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 := by simp [arccos]
theorem cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by
rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
theorem arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by
rw [arccos, ← sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith
lemma arccos_eq_of_eq_cos (hy₀ : 0 ≤ y) (hy₁ : y ≤ π) (hxy : x = cos y) : arccos x = y := by
rw [hxy, arccos_cos hy₀ hy₁]
theorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun _ hx _ hy h =>
sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _
@[gcongr]
lemma arccos_lt_arccos {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) :
arccos y < arccos x := by
unfold arccos; gcongr <;> assumption
@[gcongr]
lemma arccos_le_arccos {x y : ℝ} (hlt : x ≤ y) : arccos y ≤ arccos x := by unfold arccos; gcongr
theorem antitone_arccos : Antitone arccos := fun _ _ ↦ arccos_le_arccos
theorem arccos_injOn : InjOn arccos (Icc (-1) 1) :=
strictAntiOn_arccos.injOn
theorem arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arccos x = arccos y ↔ x = y :=
arccos_injOn.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[simp]
theorem arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp]
theorem arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp]
theorem arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
@[simp]
theorem arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x := by simp [arccos, sub_eq_zero]
@[simp]
theorem arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 := by simp [arccos]
@[simp]
theorem arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 := by
rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]
theorem arccos_neg (x : ℝ) : arccos (-x) = π - arccos x := by
rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]
theorem arccos_of_one_le {x : ℝ} (hx : 1 ≤ x) : arccos x = 0 := by
rw [arccos, arcsin_of_one_le hx, sub_self]
theorem arccos_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arccos x = π := by
rw [arccos, arcsin_of_le_neg_one hx, sub_neg_eq_add, add_halves]
-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.
theorem sin_arccos (x : ℝ) : sin (arccos x) = √(1 - x ^ 2) := by
by_cases hx₁ : -1 ≤ x; swap
· rw [not_le] at hx₁
rw [arccos_of_le_neg_one hx₁.le, sin_pi, sqrt_eq_zero_of_nonpos]
nlinarith
by_cases hx₂ : x ≤ 1; swap
· rw [not_le] at hx₂
rw [arccos_of_one_le hx₂.le, sin_zero, sqrt_eq_zero_of_nonpos]
nlinarith
rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin]
@[simp]
theorem arccos_le_pi_div_two {x} : arccos x ≤ π / 2 ↔ 0 ≤ x := by simp [arccos]
@[simp]
theorem arccos_lt_pi_div_two {x : ℝ} : arccos x < π / 2 ↔ 0 < x := by simp [arccos]
@[simp]
theorem arccos_le_pi_div_four {x} : arccos x ≤ π / 4 ↔ √2 / 2 ≤ x := by
rw [arccos, ← pi_div_four_le_arcsin]
constructor <;>
· intro
linarith
@[continuity, fun_prop]
theorem continuous_arccos : Continuous arccos :=
continuous_const.sub continuous_arcsin
-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.
theorem tan_arccos (x : ℝ) : tan (arccos x) = √(1 - x ^ 2) / x := by
rw [arccos, tan_pi_div_two_sub, tan_arcsin, inv_div]
-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.
theorem arccos_eq_arcsin {x : ℝ} (h : 0 ≤ x) : arccos x = arcsin (√(1 - x ^ 2)) :=
(arcsin_eq_of_sin_eq (sin_arccos _)
⟨(Left.neg_nonpos_iff.2 (div_nonneg pi_pos.le (by simp))).trans (arccos_nonneg _),
arccos_le_pi_div_two.2 h⟩).symm
-- The junk values for `arcsin` and `sqrt` make this true even for `1 < x`.
theorem arcsin_eq_arccos {x : ℝ} (h : 0 ≤ x) : arcsin x = arccos (√(1 - x ^ 2)) := by
rw [eq_comm, ← cos_arcsin]
exact
arccos_cos (arcsin_nonneg.2 h)
((arcsin_le_pi_div_two _).trans (div_le_self pi_pos.le one_le_two))
end Real
open Real
/-!
### Convenience dot notation lemmas
-/
namespace Filter.Tendsto
variable {α : Type*} {l : Filter α} {x : ℝ} {f : α → ℝ}
protected theorem arcsin (h : Tendsto f l (𝓝 x)) : Tendsto (arcsin <| f ·) l (𝓝 (arcsin x)) :=
(continuous_arcsin.tendsto _).comp h
theorem arcsin_nhdsLE (h : Tendsto f l (𝓝[≤] x)) :
Tendsto (arcsin <| f ·) l (𝓝[≤] (arcsin x)) := by
refine ((continuous_arcsin.tendsto _).inf <| MapsTo.tendsto fun y hy ↦ ?_).comp h
exact monotone_arcsin hy
theorem arcsin_nhdsGE (h : Tendsto f l (𝓝[≥] x)) : Tendsto (arcsin <| f ·) l (𝓝[≥] (arcsin x)) :=
((continuous_arcsin.tendsto _).inf <| MapsTo.tendsto fun _ ↦ arcsin_le_arcsin).comp h
protected theorem arccos (h : Tendsto f l (𝓝 x)) : Tendsto (arccos <| f ·) l (𝓝 (arccos x)) :=
(continuous_arccos.tendsto _).comp h
theorem arccos_nhdsLE (h : Tendsto f l (𝓝[≤] x)) : Tendsto (arccos <| f ·) l (𝓝[≥] (arccos x)) :=
((continuous_arccos.tendsto _).inf <| MapsTo.tendsto fun _ ↦ arccos_le_arccos).comp h
theorem arccos_nhdsGE (h : Tendsto f l (𝓝[≥] x)) :
Tendsto (arccos <| f ·) l (𝓝[≤] (arccos x)) := by
refine ((continuous_arccos.tendsto _).inf <| MapsTo.tendsto fun y hy ↦ ?_).comp h
simp only [mem_Ici, mem_Iic] at hy ⊢
exact antitone_arccos hy
end Filter.Tendsto
variable {X : Type*} [TopologicalSpace X] {f : X → ℝ} {s : Set X} {x : X}
protected nonrec theorem ContinuousWithinAt.arcsin (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (arcsin <| f ·) s x :=
h.arcsin
protected nonrec theorem ContinuousWithinAt.arccos (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (arccos <| f ·) s x :=
h.arccos
protected nonrec theorem ContinuousAt.arcsin (h : ContinuousAt f x) :
ContinuousAt (arcsin <| f ·) x :=
h.arcsin
protected nonrec theorem ContinuousAt.arccos (h : ContinuousAt f x) :
ContinuousAt (arccos <| f ·) x :=
h.arccos
protected theorem ContinuousOn.arcsin (h : ContinuousOn f s) : ContinuousOn (arcsin <| f ·) s :=
fun x hx ↦ (h x hx).arcsin
protected theorem ContinuousOn.arccos (h : ContinuousOn f s) : ContinuousOn (arccos <| f ·) s :=
fun x hx ↦ (h x hx).arccos
protected theorem Continuous.arcsin (h : Continuous f) : Continuous (arcsin <| f ·) :=
continuous_arcsin.comp h
protected theorem Continuous.arccos (h : Continuous f) : Continuous (arccos <| f ·) :=
continuous_arccos.comp h
|
BooleanRing.lean
|
/-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bryan Gin-ge Chen, Yaël Dillies
-/
import Mathlib.Algebra.Group.Idempotent
import Mathlib.Algebra.Ring.Equiv
import Mathlib.Algebra.Ring.PUnit
import Mathlib.Order.Hom.BoundedLattice
import Mathlib.Tactic.Abel
import Mathlib.Tactic.Ring
/-!
# Boolean rings
A Boolean ring is a ring where multiplication is idempotent. They are equivalent to Boolean
algebras.
## Main declarations
* `BooleanRing`: a typeclass for rings where multiplication is idempotent.
* `BooleanRing.toBooleanAlgebra`: Turn a Boolean ring into a Boolean algebra.
* `BooleanAlgebra.toBooleanRing`: Turn a Boolean algebra into a Boolean ring.
* `AsBoolAlg`: Type-synonym for the Boolean algebra associated to a Boolean ring.
* `AsBoolRing`: Type-synonym for the Boolean ring associated to a Boolean algebra.
## Implementation notes
We provide two ways of turning a Boolean algebra/ring into a Boolean ring/algebra:
* Instances on the same type accessible in locales `BooleanAlgebraOfBooleanRing` and
`BooleanRingOfBooleanAlgebra`.
* Type-synonyms `AsBoolAlg` and `AsBoolRing`.
At this point in time, it is not clear the first way is useful, but we keep it for educational
purposes and because it is easier than dealing with
`ofBoolAlg`/`toBoolAlg`/`ofBoolRing`/`toBoolRing` explicitly.
## Tags
boolean ring, boolean algebra
-/
open scoped symmDiff
variable {α β γ : Type*}
/-- A Boolean ring is a ring where multiplication is idempotent. -/
class BooleanRing (α) extends Ring α where
/-- Multiplication in a boolean ring is idempotent. -/
isIdempotentElem (a : α) : IsIdempotentElem a
namespace BooleanRing
variable [BooleanRing α] (a b : α)
@[scoped simp]
lemma mul_self : a * a = a := IsIdempotentElem.eq (isIdempotentElem a)
instance : Std.IdempotentOp (α := α) (· * ·) :=
⟨BooleanRing.mul_self⟩
@[scoped simp]
theorem add_self : a + a = 0 := by
have : a + a = a + a + (a + a) :=
calc
a + a = (a + a) * (a + a) := by rw [mul_self]
_ = a * a + a * a + (a * a + a * a) := by rw [add_mul, mul_add]
_ = a + a + (a + a) := by rw [mul_self]
rwa [right_eq_add] at this
@[scoped simp]
theorem neg_eq : -a = a :=
calc
-a = -a + 0 := by rw [add_zero]
_ = -a + -a + a := by rw [← neg_add_cancel, add_assoc]
_ = a := by rw [add_self, zero_add]
theorem add_eq_zero' : a + b = 0 ↔ a = b :=
calc
a + b = 0 ↔ a = -b := add_eq_zero_iff_eq_neg
_ ↔ a = b := by rw [neg_eq]
@[simp]
theorem mul_add_mul : a * b + b * a = 0 := by
have : a + b = a + b + (a * b + b * a) :=
calc
a + b = (a + b) * (a + b) := by rw [mul_self]
_ = a * a + a * b + (b * a + b * b) := by rw [add_mul, mul_add, mul_add]
_ = a + a * b + (b * a + b) := by simp only [mul_self]
_ = a + b + (a * b + b * a) := by abel
rwa [left_eq_add] at this
@[scoped simp]
theorem sub_eq_add : a - b = a + b := by rw [sub_eq_add_neg, add_right_inj, neg_eq]
@[simp]
theorem mul_one_add_self : a * (1 + a) = 0 := by rw [mul_add, mul_one, mul_self, add_self]
-- Note [lower instance priority]
instance (priority := 100) toCommRing : CommRing α :=
{ (inferInstance : BooleanRing α) with
mul_comm := fun a b => by rw [← add_eq_zero', mul_add_mul] }
end BooleanRing
instance : BooleanRing PUnit :=
⟨fun _ => Subsingleton.elim _ _⟩
/-! ### Turning a Boolean ring into a Boolean algebra -/
section RingToAlgebra
/-- Type synonym to view a Boolean ring as a Boolean algebra. -/
def AsBoolAlg (α : Type*) :=
α
/-- The "identity" equivalence between `AsBoolAlg α` and `α`. -/
def toBoolAlg : α ≃ AsBoolAlg α :=
Equiv.refl _
/-- The "identity" equivalence between `α` and `AsBoolAlg α`. -/
def ofBoolAlg : AsBoolAlg α ≃ α :=
Equiv.refl _
@[simp]
theorem toBoolAlg_symm_eq : (@toBoolAlg α).symm = ofBoolAlg :=
rfl
@[simp]
theorem ofBoolAlg_symm_eq : (@ofBoolAlg α).symm = toBoolAlg :=
rfl
@[simp]
theorem toBoolAlg_ofBoolAlg (a : AsBoolAlg α) : toBoolAlg (ofBoolAlg a) = a :=
rfl
@[simp]
theorem ofBoolAlg_toBoolAlg (a : α) : ofBoolAlg (toBoolAlg a) = a :=
rfl
theorem toBoolAlg_inj {a b : α} : toBoolAlg a = toBoolAlg b ↔ a = b :=
Iff.rfl
theorem ofBoolAlg_inj {a b : AsBoolAlg α} : ofBoolAlg a = ofBoolAlg b ↔ a = b :=
Iff.rfl
instance [Inhabited α] : Inhabited (AsBoolAlg α) :=
‹Inhabited α›
variable [BooleanRing α] [BooleanRing β] [BooleanRing γ]
namespace BooleanRing
/-- The join operation in a Boolean ring is `x + y + x * y`. -/
def sup : Max α :=
⟨fun x y => x + y + x * y⟩
/-- The meet operation in a Boolean ring is `x * y`. -/
def inf : Min α :=
⟨(· * ·)⟩
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: add priority 100. lower instance priority
scoped [BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.sup
scoped [BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.inf
open BooleanAlgebraOfBooleanRing
theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by
dsimp only [(· ⊔ ·)]
ring
theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := by
dsimp only [(· ⊓ ·)]
ring
theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := by
dsimp only [(· ⊔ ·)]
ring
theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := by
dsimp only [(· ⊓ ·)]
ring
theorem sup_inf_self (a b : α) : a ⊔ a ⊓ b = a := by
dsimp only [(· ⊔ ·), (· ⊓ ·)]
rw [← mul_assoc, mul_self, add_assoc, add_self, add_zero]
theorem inf_sup_self (a b : α) : a ⊓ (a ⊔ b) = a := by
dsimp only [(· ⊔ ·), (· ⊓ ·)]
rw [mul_add, mul_add, mul_self, ← mul_assoc, mul_self, add_assoc, add_self, add_zero]
theorem le_sup_inf_aux (a b c : α) : (a + b + a * b) * (a + c + a * c) = a + b * c + a * (b * c) :=
calc
(a + b + a * b) * (a + c + a * c) =
a * a + b * c + a * (b * c) + (a * b + a * a * b) + (a * c + a * a * c) +
(a * b * c + a * a * b * c) := by ring
_ = a + b * c + a * (b * c) := by simp only [mul_self, add_self, add_zero]
theorem le_sup_inf (a b c : α) : (a ⊔ b) ⊓ (a ⊔ c) ⊔ (a ⊔ b ⊓ c) = a ⊔ b ⊓ c := by
dsimp only [(· ⊔ ·), (· ⊓ ·)]
rw [le_sup_inf_aux, add_self, mul_self, zero_add]
/-- The Boolean algebra structure on a Boolean ring.
The data is defined so that:
* `a ⊔ b` unfolds to `a + b + a * b`
* `a ⊓ b` unfolds to `a * b`
* `a ≤ b` unfolds to `a + b + a * b = b`
* `⊥` unfolds to `0`
* `⊤` unfolds to `1`
* `aᶜ` unfolds to `1 + a`
* `a \ b` unfolds to `a * (1 + b)`
-/
def toBooleanAlgebra : BooleanAlgebra α :=
{ Lattice.mk' sup_comm sup_assoc inf_comm inf_assoc sup_inf_self inf_sup_self with
le_sup_inf := le_sup_inf
top := 1
le_top := fun a => show a + 1 + a * 1 = 1 by rw [mul_one, add_comm a 1,
add_assoc, add_self, add_zero]
bot := 0
bot_le := fun a => show 0 + a + 0 * a = a by rw [zero_mul, zero_add, add_zero]
compl := fun a => 1 + a
inf_compl_le_bot := fun a =>
show a * (1 + a) + 0 + a * (1 + a) * 0 = 0 by simp [mul_add, mul_self, add_self]
top_le_sup_compl := fun a => by
change
1 + (a + (1 + a) + a * (1 + a)) + 1 * (a + (1 + a) + a * (1 + a)) =
a + (1 + a) + a * (1 + a)
norm_num [mul_add, mul_self, add_self]
rw [← add_assoc, add_self] }
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: add priority 100. lower instance priority
scoped[BooleanAlgebraOfBooleanRing] attribute [instance] BooleanRing.toBooleanAlgebra
end BooleanRing
open BooleanRing
instance : BooleanAlgebra (AsBoolAlg α) :=
@BooleanRing.toBooleanAlgebra α _
@[simp]
theorem ofBoolAlg_top : ofBoolAlg (⊤ : AsBoolAlg α) = 1 :=
rfl
@[simp]
theorem ofBoolAlg_bot : ofBoolAlg (⊥ : AsBoolAlg α) = 0 :=
rfl
@[simp]
theorem ofBoolAlg_sup (a b : AsBoolAlg α) :
ofBoolAlg (a ⊔ b) = ofBoolAlg a + ofBoolAlg b + ofBoolAlg a * ofBoolAlg b :=
rfl
@[simp]
theorem ofBoolAlg_inf (a b : AsBoolAlg α) : ofBoolAlg (a ⊓ b) = ofBoolAlg a * ofBoolAlg b :=
rfl
@[simp]
theorem ofBoolAlg_compl (a : AsBoolAlg α) : ofBoolAlg aᶜ = 1 + ofBoolAlg a :=
rfl
@[simp]
theorem ofBoolAlg_sdiff (a b : AsBoolAlg α) : ofBoolAlg (a \ b) = ofBoolAlg a * (1 + ofBoolAlg b) :=
rfl
private theorem of_boolalg_symmDiff_aux (a b : α) : (a + b + a * b) * (1 + a * b) = a + b :=
calc (a + b + a * b) * (1 + a * b)
_ = a + b + (a * b + a * b * (a * b)) + (a * (b * b) + a * a * b) := by ring
_ = a + b := by simp only [mul_self, add_self, add_zero]
@[simp]
theorem ofBoolAlg_symmDiff (a b : AsBoolAlg α) : ofBoolAlg (a ∆ b) = ofBoolAlg a + ofBoolAlg b := by
rw [symmDiff_eq_sup_sdiff_inf]
exact of_boolalg_symmDiff_aux _ _
@[simp]
theorem ofBoolAlg_mul_ofBoolAlg_eq_left_iff {a b : AsBoolAlg α} :
ofBoolAlg a * ofBoolAlg b = ofBoolAlg a ↔ a ≤ b :=
@inf_eq_left (AsBoolAlg α) _ _ _
@[simp]
theorem toBoolAlg_zero : toBoolAlg (0 : α) = ⊥ :=
rfl
@[simp]
theorem toBoolAlg_one : toBoolAlg (1 : α) = ⊤ :=
rfl
@[simp]
theorem toBoolAlg_mul (a b : α) : toBoolAlg (a * b) = toBoolAlg a ⊓ toBoolAlg b :=
rfl
@[simp]
theorem toBoolAlg_add_add_mul (a b : α) : toBoolAlg (a + b + a * b) = toBoolAlg a ⊔ toBoolAlg b :=
rfl
@[simp]
theorem toBoolAlg_add (a b : α) : toBoolAlg (a + b) = toBoolAlg a ∆ toBoolAlg b :=
(ofBoolAlg_symmDiff a b).symm
/-- Turn a ring homomorphism from Boolean rings `α` to `β` into a bounded lattice homomorphism
from `α` to `β` considered as Boolean algebras. -/
@[simps]
protected def RingHom.asBoolAlg (f : α →+* β) : BoundedLatticeHom (AsBoolAlg α) (AsBoolAlg β) where
toFun := toBoolAlg ∘ f ∘ ofBoolAlg
map_sup' a b := by
dsimp
simp_rw [map_add f, map_mul f, toBoolAlg_add_add_mul]
map_inf' := f.map_mul'
map_top' := f.map_one'
map_bot' := f.map_zero'
@[simp]
theorem RingHom.asBoolAlg_id : (RingHom.id α).asBoolAlg = BoundedLatticeHom.id _ :=
rfl
@[simp]
theorem RingHom.asBoolAlg_comp (g : β →+* γ) (f : α →+* β) :
(g.comp f).asBoolAlg = g.asBoolAlg.comp f.asBoolAlg :=
rfl
end RingToAlgebra
/-! ### Turning a Boolean algebra into a Boolean ring -/
section AlgebraToRing
/-- Type synonym to view a Boolean ring as a Boolean algebra. -/
def AsBoolRing (α : Type*) :=
α
/-- The "identity" equivalence between `AsBoolRing α` and `α`. -/
def toBoolRing : α ≃ AsBoolRing α :=
Equiv.refl _
/-- The "identity" equivalence between `α` and `AsBoolRing α`. -/
def ofBoolRing : AsBoolRing α ≃ α :=
Equiv.refl _
@[simp]
theorem toBoolRing_symm_eq : (@toBoolRing α).symm = ofBoolRing :=
rfl
@[simp]
theorem ofBoolRing_symm_eq : (@ofBoolRing α).symm = toBoolRing :=
rfl
@[simp]
theorem toBoolRing_ofBoolRing (a : AsBoolRing α) : toBoolRing (ofBoolRing a) = a :=
rfl
@[simp]
theorem ofBoolRing_toBoolRing (a : α) : ofBoolRing (toBoolRing a) = a :=
rfl
theorem toBoolRing_inj {a b : α} : toBoolRing a = toBoolRing b ↔ a = b :=
Iff.rfl
theorem ofBoolRing_inj {a b : AsBoolRing α} : ofBoolRing a = ofBoolRing b ↔ a = b :=
Iff.rfl
instance [Inhabited α] : Inhabited (AsBoolRing α) :=
‹Inhabited α›
-- See note [reducible non-instances]
/-- Every generalized Boolean algebra has the structure of a non unital commutative ring with the
following data:
* `a + b` unfolds to `a ∆ b` (symmetric difference)
* `a * b` unfolds to `a ⊓ b`
* `-a` unfolds to `a`
* `0` unfolds to `⊥`
-/
abbrev GeneralizedBooleanAlgebra.toNonUnitalCommRing [GeneralizedBooleanAlgebra α] :
NonUnitalCommRing α where
add := (· ∆ ·)
add_assoc := symmDiff_assoc
zero := ⊥
zero_add := bot_symmDiff
add_zero := symmDiff_bot
zero_mul := bot_inf_eq
mul_zero := inf_bot_eq
neg := id
neg_add_cancel := symmDiff_self
add_comm := symmDiff_comm
mul := (· ⊓ ·)
mul_assoc := inf_assoc
mul_comm := inf_comm
left_distrib := inf_symmDiff_distrib_left
right_distrib := inf_symmDiff_distrib_right
nsmul := letI : Zero α := ⟨⊥⟩; letI : Add α := ⟨(· ∆ ·)⟩; nsmulRec
zsmul := letI : Zero α := ⟨⊥⟩; letI : Add α := ⟨(· ∆ ·)⟩; letI : Neg α := ⟨id⟩; zsmulRec
instance [GeneralizedBooleanAlgebra α] : NonUnitalCommRing (AsBoolRing α) :=
@GeneralizedBooleanAlgebra.toNonUnitalCommRing α _
variable [BooleanAlgebra α] [BooleanAlgebra β] [BooleanAlgebra γ]
-- See note [reducible non-instances]
/-- Every Boolean algebra has the structure of a Boolean ring with the following data:
* `a + b` unfolds to `a ∆ b` (symmetric difference)
* `a * b` unfolds to `a ⊓ b`
* `-a` unfolds to `a`
* `0` unfolds to `⊥`
* `1` unfolds to `⊤`
-/
abbrev BooleanAlgebra.toBooleanRing : BooleanRing α where
__ := GeneralizedBooleanAlgebra.toNonUnitalCommRing
one := ⊤
one_mul := top_inf_eq
mul_one := inf_top_eq
isIdempotentElem := inf_idem
scoped[BooleanRingOfBooleanAlgebra]
attribute [instance] GeneralizedBooleanAlgebra.toNonUnitalCommRing BooleanAlgebra.toBooleanRing
instance : BooleanRing (AsBoolRing α) :=
@BooleanAlgebra.toBooleanRing α _
@[simp]
theorem ofBoolRing_zero : ofBoolRing (0 : AsBoolRing α) = ⊥ :=
rfl
@[simp]
theorem ofBoolRing_one : ofBoolRing (1 : AsBoolRing α) = ⊤ :=
rfl
@[simp]
theorem ofBoolRing_neg (a : AsBoolRing α) : ofBoolRing (-a) = ofBoolRing a :=
rfl
@[simp]
theorem ofBoolRing_add (a b : AsBoolRing α) : ofBoolRing (a + b) = ofBoolRing a ∆ ofBoolRing b :=
rfl
@[simp]
theorem ofBoolRing_sub (a b : AsBoolRing α) : ofBoolRing (a - b) = ofBoolRing a ∆ ofBoolRing b :=
rfl
@[simp]
theorem ofBoolRing_mul (a b : AsBoolRing α) : ofBoolRing (a * b) = ofBoolRing a ⊓ ofBoolRing b :=
rfl
@[simp]
theorem ofBoolRing_le_ofBoolRing_iff {a b : AsBoolRing α} :
ofBoolRing a ≤ ofBoolRing b ↔ a * b = a :=
inf_eq_left.symm
@[simp]
theorem toBoolRing_bot : toBoolRing (⊥ : α) = 0 :=
rfl
@[simp]
theorem toBoolRing_top : toBoolRing (⊤ : α) = 1 :=
rfl
@[simp]
theorem toBoolRing_inf (a b : α) : toBoolRing (a ⊓ b) = toBoolRing a * toBoolRing b :=
rfl
@[simp]
theorem toBoolRing_symmDiff (a b : α) : toBoolRing (a ∆ b) = toBoolRing a + toBoolRing b :=
rfl
/-- Turn a bounded lattice homomorphism from Boolean algebras `α` to `β` into a ring homomorphism
from `α` to `β` considered as Boolean rings. -/
@[simps]
protected def BoundedLatticeHom.asBoolRing (f : BoundedLatticeHom α β) :
AsBoolRing α →+* AsBoolRing β where
toFun := toBoolRing ∘ f ∘ ofBoolRing
map_zero' := f.map_bot'
map_one' := f.map_top'
map_add' := map_symmDiff' f
map_mul' := f.map_inf'
@[simp]
theorem BoundedLatticeHom.asBoolRing_id : (BoundedLatticeHom.id α).asBoolRing = RingHom.id _ :=
rfl
@[simp]
theorem BoundedLatticeHom.asBoolRing_comp (g : BoundedLatticeHom β γ) (f : BoundedLatticeHom α β) :
(g.comp f).asBoolRing = g.asBoolRing.comp f.asBoolRing :=
rfl
end AlgebraToRing
/-! ### Equivalence between Boolean rings and Boolean algebras -/
/-- Order isomorphism between `α` considered as a Boolean ring considered as a Boolean algebra and
`α`. -/
@[simps!]
def OrderIso.asBoolAlgAsBoolRing (α : Type*) [BooleanAlgebra α] : AsBoolAlg (AsBoolRing α) ≃o α :=
⟨ofBoolAlg.trans ofBoolRing,
ofBoolRing_le_ofBoolRing_iff.trans ofBoolAlg_mul_ofBoolAlg_eq_left_iff⟩
/-- Ring isomorphism between `α` considered as a Boolean algebra considered as a Boolean ring and
`α`. -/
@[simps!]
def RingEquiv.asBoolRingAsBoolAlg (α : Type*) [BooleanRing α] : AsBoolRing (AsBoolAlg α) ≃+* α :=
{ ofBoolRing.trans ofBoolAlg with
map_mul' := fun _a _b => rfl
map_add' := ofBoolAlg_symmDiff }
open Bool
instance : Zero Bool where zero := false
instance : One Bool where one := true
instance : Add Bool where add := xor
instance : Neg Bool where neg := id
instance : Sub Bool where sub := xor
instance : Mul Bool where mul := and
instance : BooleanRing Bool where
add_assoc := xor_assoc
zero_add := Bool.false_xor
add_zero := Bool.xor_false
sub_eq_add_neg _ _ := rfl
neg_add_cancel := Bool.xor_self
add_comm := xor_comm
mul_assoc := and_assoc
one_mul := Bool.true_and
mul_one := Bool.and_true
left_distrib := and_xor_distrib_left
right_distrib := and_xor_distrib_right
isIdempotentElem := Bool.and_self
zero_mul _ := rfl
mul_zero a := by cases a <;> rfl
nsmul := nsmulRec
zsmul := zsmulRec
|
Goursat.lean
|
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.GroupTheory.Goursat
import Mathlib.LinearAlgebra.Prod
import Mathlib.LinearAlgebra.Quotient.Basic
/-!
# Goursat's lemma for submodules
Let `M, N` be modules over a ring `R`. If `L` is a submodule of `M × N` which projects fully on
to both factors, then there exist submodules `M' ≤ M` and `N' ≤ N` such that `M' × N' ≤ L` and the
image of `L` in `(M ⧸ M') × (N ⧸ N')` is the graph of an isomorphism `M ⧸ M' ≃ₗ[R] N ⧸ N'`.
Equivalently, `L` is equal to the preimage in `M × N` of the graph of this isomorphism
`M ⧸ M' ≃ₗ[R] N ⧸ N'`.
`M'` and `N'` can be explicitly constructed as `Submodule.goursatFst L` and `Submodule.goursatSnd L`
respectively.
-/
open Function Set LinearMap
namespace Submodule
variable {R M N : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
{L : Submodule R (M × N)}
(hL₁ : Surjective (Prod.fst ∘ L.subtype)) (hL₂ : Surjective (Prod.snd ∘ L.subtype))
variable (L) in
/-- For `L` a submodule of `M × N`, `L.goursatFst` is the kernel of the projection map `L → N`,
considered as a submodule of `M`.
This is the first submodule appearing in Goursat's lemma. See `Subgroup.goursat`. -/
def goursatFst : Submodule R M :=
(LinearMap.ker <| (LinearMap.snd R M N).comp L.subtype).map ((LinearMap.fst R M N).comp L.subtype)
variable (L) in
/-- For `L` a subgroup of `M × N`, `L.goursatSnd` is the kernel of the projection map `L → M`,
considered as a subgroup of `N`.
This is the second subgroup appearing in Goursat's lemma. See `Subgroup.goursat`. -/
def goursatSnd : Submodule R N :=
(LinearMap.ker <| (LinearMap.fst R M N).comp L.subtype).map ((LinearMap.snd R M N).comp L.subtype)
lemma goursatFst_toAddSubgroup :
(goursatFst L).toAddSubgroup = L.toAddSubgroup.goursatFst := by
ext x
simp [mem_toAddSubgroup, goursatFst, AddSubgroup.mem_goursatFst]
lemma goursatSnd_toAddSubgroup :
(goursatSnd L).toAddSubgroup = L.toAddSubgroup.goursatSnd := by
ext x
simp [mem_toAddSubgroup, goursatSnd, AddSubgroup.mem_goursatSnd]
variable (L) in
lemma goursatFst_prod_goursatSnd_le : L.goursatFst.prod L.goursatSnd ≤ L := by
simpa only [← toAddSubgroup_le, goursatFst_toAddSubgroup, goursatSnd_toAddSubgroup]
using L.toAddSubgroup.goursatFst_prod_goursatSnd_le
include hL₁ hL₂ in
/-- **Goursat's lemma** for a submodule of a product with surjective projections.
If `L` is a submodule of `M × N` which projects fully on both factors, then there exist submodules
`M' ≤ M` and `N' ≤ N` such that `M' × N' ≤ L` and the image of `L` in `(M ⧸ M') × (N ⧸ N')` is the
graph of an isomorphism of `R`-modules `(M ⧸ M') ≃ (N ⧸ N')`.
`M` and `N` can be explicitly constructed as `L.goursatFst` and `L.goursatSnd` respectively. -/
lemma goursat_surjective : ∃ e : (M ⧸ L.goursatFst) ≃ₗ[R] N ⧸ L.goursatSnd,
LinearMap.range ((L.goursatFst.mkQ.prodMap L.goursatSnd.mkQ).comp L.subtype) = e.graph := by
-- apply add-group result
obtain ⟨(e : M ⧸ L.goursatFst ≃+ N ⧸ L.goursatSnd), he⟩ :=
L.toAddSubgroup.goursat_surjective hL₁ hL₂
-- check R-linearity of the map
have (r : R) (x : M ⧸ L.goursatFst) : e (r • x) = r • e x := by
change (r • x, r • e x) ∈ e.toAddMonoidHom.graph
rw [← he, ← Prod.smul_mk]
have : (x, e x) ∈ e.toAddMonoidHom.graph := rfl
rw [← he, AddMonoidHom.mem_range] at this
rcases this with ⟨⟨l, hl⟩, hl'⟩
use ⟨r • l, L.smul_mem r hl⟩
rw [← hl']
rfl
-- define the map as an R-linear equiv
use { e with map_smul' := this }
rw [← toAddSubgroup_injective.eq_iff]
convert he using 1
ext v
rw [mem_toAddSubgroup, mem_graph_iff, Eq.comm]
rfl
/-- **Goursat's lemma** for an arbitrary submodule of a product.
If `L` is a submodule of `M × N`, then there exist submodules `M'' ≤ M' ≤ M` and `N'' ≤ N' ≤ N` such
that `L ≤ M' × N'`, and `L` is (the image in `M × N` of) the preimage of the graph of an `R`-linear
isomorphism `M' ⧸ M'' ≃ N' ⧸ N''`. -/
lemma goursat : ∃ (M' : Submodule R M) (N' : Submodule R N) (M'' : Submodule R M')
(N'' : Submodule R N') (e : (M' ⧸ M'') ≃ₗ[R] N' ⧸ N''),
L = (e.graph.comap <| M''.mkQ.prodMap N''.mkQ).map (M'.subtype.prodMap N'.subtype) := by
let M' := L.map (LinearMap.fst ..)
let N' := L.map (LinearMap.snd ..)
let P : L →ₗ[R] M' := (LinearMap.fst ..).submoduleMap L
let Q : L →ₗ[R] N' := (LinearMap.snd ..).submoduleMap L
let L' : Submodule R (M' × N') := LinearMap.range (P.prod Q)
have hL₁' : Surjective (Prod.fst ∘ L'.subtype) := by
simp only [← coe_fst (R := R), ← coe_comp, ← range_eq_top, LinearMap.range_comp, range_subtype]
simpa only [L', ← LinearMap.range_comp, fst_prod, range_eq_top] using
(LinearMap.fst ..).submoduleMap_surjective L
have hL₂' : Surjective (Prod.snd ∘ L'.subtype) := by
simp only [← coe_snd (R := R), ← coe_comp, ← range_eq_top, LinearMap.range_comp, range_subtype]
simpa only [L', ← LinearMap.range_comp, snd_prod, range_eq_top] using
(LinearMap.snd ..).submoduleMap_surjective L
obtain ⟨e, he⟩ := goursat_surjective hL₁' hL₂'
use M', N', L'.goursatFst, L'.goursatSnd, e
rw [← he]
simp only [LinearMap.range_comp, Submodule.range_subtype, L']
rw [comap_map_eq_self]
· ext ⟨m, n⟩
constructor
· intro hmn
simp only [mem_map, LinearMap.mem_range, prod_apply, Subtype.exists, Prod.exists, coe_prodMap,
coe_subtype, Prod.map_apply, Prod.mk.injEq, exists_and_right, exists_eq_right_right,
exists_eq_right, M', N', fst_apply, snd_apply]
exact ⟨⟨n, hmn⟩, ⟨m, hmn⟩, ⟨m, n, hmn, rfl⟩⟩
· simp only [mem_map, LinearMap.mem_range, prod_apply, Subtype.exists, Prod.exists,
coe_prodMap, coe_subtype, Prod.map_apply, Prod.mk.injEq, exists_and_right,
exists_eq_right_right, exists_eq_right, forall_exists_index, Pi.prod]
rintro hm hn m₁ n₁ hm₁n₁ ⟨hP, hQ⟩
simp only [Subtype.ext_iff] at hP hQ
rwa [← hP, ← hQ]
· convert goursatFst_prod_goursatSnd_le (range <| P.prod Q)
ext ⟨m, n⟩
simp_rw [mem_ker, coe_prodMap, Prod.map_apply, Submodule.mem_prod, Prod.zero_eq_mk,
Prod.ext_iff, ← mem_ker, ker_mkQ]
end Submodule
|
LogMeromorphic.lean
|
/-
Copyright (c) 2025 Stefan Kebekus. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stefan Kebekus
-/
import Mathlib.Analysis.Meromorphic.FactorizedRational
import Mathlib.Analysis.NormedSpace.Connected
import Mathlib.Analysis.SpecialFunctions.Integrability.Basic
import Mathlib.Analysis.SpecialFunctions.Log.PosLog
import Mathlib.Data.Complex.FiniteDimensional
import Mathlib.MeasureTheory.Integral.CircleIntegral
/-!
# Integrability for Logarithms of Meromorphic Functions
We establish integrability for functions of the form `log ‖meromorphic‖`. In the real setting, these
functions are interval integrable over every interval of the real line. This implies in particular
that logarithms of trigonometric functions are interval integrable. In the complex setting, the
functions are circle integrable over every circle in the complex plane.
-/
open Filter Interval MeasureTheory MeromorphicOn Metric Real
/-!
## Interval Integrability for Logarithms of Real Meromorphic Functions
-/
section IntervalIntegrable
variable
{E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
{f : ℝ → E} {a b : ℝ}
/--
If `f` is real-meromorphic on a compact interval, then `log ‖f ·‖` is interval integrable on this
interval.
-/
theorem intervalIntegrable_log_norm_meromorphicOn (hf : MeromorphicOn f [[a, b]]) :
IntervalIntegrable (log ‖f ·‖) volume a b := by
by_cases t₀ : ∀ u : [[a, b]], meromorphicOrderAt f u ≠ ⊤
· obtain ⟨g, h₁g, h₂g, h₃g⟩ := hf.extract_zeros_poles t₀
((MeromorphicOn.divisor f [[a, b]]).finiteSupport isCompact_uIcc)
have h₄g := MeromorphicOn.extract_zeros_poles_log h₂g h₃g
rw [intervalIntegrable_congr_codiscreteWithin
(h₄g.filter_mono (Filter.codiscreteWithin.mono Set.uIoc_subset_uIcc))]
apply IntervalIntegrable.add
· apply IntervalIntegrable.finsum
intro i
apply IntervalIntegrable.const_mul
rw [(by ring : a = ((a - i) + i)), (by ring : b = ((b - i) + i))]
apply IntervalIntegrable.comp_sub_right (f := (log ‖·‖)) _ i
simp [norm_eq_abs, log_abs]
· apply ContinuousOn.intervalIntegrable
apply h₁g.continuousOn.norm.log
simp_all
· rw [← hf.exists_meromorphicOrderAt_ne_top_iff_forall (isConnected_Icc inf_le_sup)] at t₀
push_neg at t₀
have : (log ‖f ·‖) =ᶠ[Filter.codiscreteWithin (Ι a b)] 0 := by
apply Filter.EventuallyEq.filter_mono _ (Filter.codiscreteWithin.mono Set.uIoc_subset_uIcc)
filter_upwards [hf.meromorphicNFAt_mem_codiscreteWithin,
Filter.self_mem_codiscreteWithin [[a, b]]] with x h₁x h₂x
simp only [Pi.zero_apply, log_eq_zero, norm_eq_zero]
left
by_contra hCon
simp_all [← h₁x.meromorphicOrderAt_eq_zero_iff, t₀ ⟨x, h₂x⟩]
rw [intervalIntegrable_congr_codiscreteWithin this]
apply Iff.mpr _root_.intervalIntegrable_const_iff
tauto
/--
If `f` is real-meromorphic on a compact interval, then `log ‖f ·‖` is interval integrable on this
interval.
-/
theorem intervalIntegrable_posLog_norm_meromorphicOn (hf : MeromorphicOn f [[a, b]]) :
IntervalIntegrable (log⁺ ‖f ·‖) volume a b := by
simp_rw [← half_mul_log_add_log_abs, mul_add]
apply IntervalIntegrable.add
· apply (intervalIntegrable_log_norm_meromorphicOn hf).const_mul
· apply (intervalIntegrable_log_norm_meromorphicOn hf).abs.const_mul
/--
If `f` is real-meromorphic on a compact interval, then `log ∘ f` is interval integrable on this
interval.
-/
theorem _root_.MeromorphicOn.intervalIntegrable_log {f : ℝ → ℝ} (hf : MeromorphicOn f [[a, b]]) :
IntervalIntegrable (log ∘ f) volume a b := by
rw [(by aesop : log ∘ f = (log ‖f ·‖))]
exact intervalIntegrable_log_norm_meromorphicOn hf
/--
Special case of `MeromorphicOn.intervalIntegrable_log`: The function `log ∘ sin` is interval
integrable over every interval.
-/
theorem intervalIntegrable_log_sin : IntervalIntegrable (log ∘ sin) volume a b :=
analyticOnNhd_sin.meromorphicOn.intervalIntegrable_log
/--
Special case of `MeromorphicOn.intervalIntegrable_log`: The function `log ∘ cos` is interval
integrable over every interval.
-/
theorem intervalIntegrable_log_cos : IntervalIntegrable (log ∘ cos) volume a b :=
analyticOnNhd_cos.meromorphicOn.intervalIntegrable_log
end IntervalIntegrable
/-!
## Circle Integrability for Logarithms of Complex Meromorphic Functions
-/
section CircleIntegrable
variable
{E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E]
{c : ℂ} {R : ℝ} {f : ℂ → E}
/--
If `f` is complex meromorphic on a circle in the complex plane, then `log ‖f ·‖` is circle
integrable over that circle.
-/
theorem circleIntegrable_log_norm_meromorphicOn (hf : MeromorphicOn f (sphere c |R|)) :
CircleIntegrable (log ‖f ·‖) c R := by
by_cases t₀ : ∀ u : (sphere c |R|), meromorphicOrderAt f u ≠ ⊤
· obtain ⟨g, h₁g, h₂g, h₃g⟩ := hf.extract_zeros_poles t₀
((divisor f (sphere c |R|)).finiteSupport (isCompact_sphere c |R|))
have h₄g := MeromorphicOn.extract_zeros_poles_log h₂g h₃g
apply CircleIntegrable.congr_codiscreteWithin h₄g.symm
apply CircleIntegrable.add
· apply CircleIntegrable.finsum
intro i
apply IntervalIntegrable.const_mul
apply intervalIntegrable_log_norm_meromorphicOn
apply AnalyticOnNhd.meromorphicOn
apply AnalyticOnNhd.sub _ analyticOnNhd_const
apply (analyticOnNhd_circleMap c R).mono (by tauto)
· apply ContinuousOn.intervalIntegrable
apply ContinuousOn.log
· apply ContinuousOn.norm
apply h₁g.continuousOn.comp (t := sphere c |R|) (continuous_circleMap c R).continuousOn
intro x hx
simp
· intro x hx
rw [ne_eq, norm_eq_zero]
apply h₂g ⟨circleMap c R x, circleMap_mem_sphere' c R x⟩
· rw [← hf.exists_meromorphicOrderAt_ne_top_iff_forall (isConnected_sphere (by simp) c
(abs_nonneg R))] at t₀
push_neg at t₀
have : (log ‖f ·‖) =ᶠ[codiscreteWithin (sphere c |R|)] 0 := by
filter_upwards [hf.meromorphicNFAt_mem_codiscreteWithin,
self_mem_codiscreteWithin (sphere c |R|)] with x h₁x h₂x
simp only [Pi.zero_apply, log_eq_zero, norm_eq_zero]
left
by_contra hCon
simp_all [← h₁x.meromorphicOrderAt_eq_zero_iff, t₀ ⟨x, h₂x⟩]
apply CircleIntegrable.congr_codiscreteWithin this.symm (circleIntegrable_const 0 c R)
/--
Variant of `circleIntegrable_log_norm_meromorphicOn` for non-negative radii.
-/
theorem circleIntegrable_log_norm_meromorphicOn_of_nonneg (hf : MeromorphicOn f (sphere c R))
(hR : 0 ≤ R) :
CircleIntegrable (log ‖f ·‖) c R := by
rw [← abs_of_nonneg hR] at hf
exact circleIntegrable_log_norm_meromorphicOn hf
/--
Variant of `circleIntegrable_log_norm_meromorphicOn` for factorized rational functions.
-/
theorem circleIntegrable_log_norm_factorizedRational {R : ℝ} {c : ℂ} (D : ℂ → ℤ) :
CircleIntegrable (∑ᶠ u, ((D u) * log ‖· - u‖)) c R :=
CircleIntegrable.finsum (fun _ ↦ (circleIntegrable_log_norm_meromorphicOn
(analyticOnNhd_id.sub analyticOnNhd_const).meromorphicOn).const_smul)
/--
If `f` is complex meromorphic on a circle in the complex plane, then `log⁺ ‖f ·‖` is circle
integrable over that circle.
-/
theorem circleIntegrable_posLog_norm_meromorphicOn (hf : MeromorphicOn f (sphere c |R|)) :
CircleIntegrable (log⁺ ‖f ·‖) c R := by
simp_rw [← half_mul_log_add_log_abs, mul_add]
apply CircleIntegrable.add
· apply (circleIntegrable_log_norm_meromorphicOn hf).const_mul
· apply (circleIntegrable_log_norm_meromorphicOn hf).abs.const_mul
/--
Variant of `circleIntegrable_posLog_norm_meromorphicOn` for non-negative radii.
-/
theorem circleIntegrable_posLog_norm_meromorphicOn_of_nonneg (hf : MeromorphicOn f (sphere c R))
(hR : 0 ≤ R) :
CircleIntegrable (log⁺ ‖f ·‖) c R := by
rw [← abs_of_nonneg hR] at hf
exact circleIntegrable_posLog_norm_meromorphicOn hf
end CircleIntegrable
|
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.
|
Yoneda.lean
|
import Mathlib.CategoryTheory.Monoidal.Mon_
deprecated_module (since := "2025-05-11")
|
Zero.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects
/-!
# The category of (commutative) (additive) groups has a zero object.
`AddCommGroup` also has zero morphisms. For definitional reasons, we infer this from preadditivity
rather than from the existence of a zero object.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u
namespace Grp
@[to_additive]
theorem isZero_of_subsingleton (G : Grp) [Subsingleton G] : IsZero G := by
refine ⟨fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩⟩
· ext x
have : x = 1 := Subsingleton.elim _ _
rw [this, map_one, map_one]
· ext
subsingleton
@[to_additive AddGrp.hasZeroObject]
instance : HasZeroObject Grp :=
⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩
end Grp
namespace CommGrp
@[to_additive]
theorem isZero_of_subsingleton (G : CommGrp) [Subsingleton G] : IsZero G := by
refine ⟨fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨1⟩, fun f => ?_⟩⟩⟩
· ext x
have : x = 1 := Subsingleton.elim _ _
rw [this, map_one, map_one]
· ext
subsingleton
@[to_additive AddCommGrp.hasZeroObject]
instance : HasZeroObject CommGrp :=
⟨⟨of PUnit, isZero_of_subsingleton _⟩⟩
end CommGrp
|
Bind.lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Group.Multiset.Basic
/-!
# Bind operation for multisets
This file defines a few basic operations on `Multiset`, notably the monadic bind.
## Main declarations
* `Multiset.join`: The join, aka union or sum, of multisets.
* `Multiset.bind`: The bind of a multiset-indexed family of multisets.
* `Multiset.product`: Cartesian product of two multisets.
* `Multiset.sigma`: Disjoint sum of multisets in a sigma type.
-/
assert_not_exists MonoidWithZero MulAction
universe v
variable {α : Type*} {β : Type v} {γ δ : Type*}
namespace Multiset
/-! ### Join -/
/-- `join S`, where `S` is a multiset of multisets, is the lift of the list join
operation, that is, the union of all the sets.
For example, `join {{1, 2}, {1, 2}, {0, 1}} = {0, 1, 1, 1, 2, 2}`. -/
def join : Multiset (Multiset α) → Multiset α :=
sum
theorem coe_join : ∀ L : List (List α), join (L.map ((↑) : List α → Multiset α) :
Multiset (Multiset α)) = L.flatten
| [] => rfl
| l :: L => by
exact congr_arg (fun s : Multiset α => ↑l + s) (coe_join L)
@[simp]
theorem join_zero : @join α 0 = 0 :=
rfl
@[simp]
theorem join_cons (s S) : @join α (s ::ₘ S) = s + join S :=
sum_cons _ _
@[simp]
theorem join_add (S T) : @join α (S + T) = join S + join T :=
sum_add _ _
@[simp]
theorem singleton_join (a) : join ({a} : Multiset (Multiset α)) = a :=
sum_singleton _
@[simp]
theorem mem_join {a S} : a ∈ @join α S ↔ ∃ s ∈ S, a ∈ s :=
Multiset.induction_on S (by simp) <| by
simp +contextual [or_and_right, exists_or]
@[simp]
theorem card_join (S) : card (@join α S) = sum (map card S) :=
Multiset.induction_on S (by simp) (by simp)
@[simp]
theorem map_join (f : α → β) (S : Multiset (Multiset α)) :
map f (join S) = join (map (map f) S) := by
induction S using Multiset.induction with
| empty => simp
| cons _ _ ih => simp [ih]
@[to_additive (attr := simp)]
theorem prod_join [CommMonoid α] {S : Multiset (Multiset α)} :
prod (join S) = prod (map prod S) := by
induction S using Multiset.induction with
| empty => simp
| cons _ _ ih => simp [ih]
theorem rel_join {r : α → β → Prop} {s t} (h : Rel (Rel r) s t) : Rel r s.join t.join := by
induction h with
| zero => simp
| cons hab hst ih => simpa using hab.add ih
/-! ### Bind -/
section Bind
variable (a : α) (s t : Multiset α) (f g : α → Multiset β)
/-- `s.bind f` is the monad bind operation, defined as `(s.map f).join`. It is the union of `f a` as
`a` ranges over `s`. -/
def bind (s : Multiset α) (f : α → Multiset β) : Multiset β :=
(s.map f).join
@[simp]
theorem coe_bind (l : List α) (f : α → List β) : (@bind α β l fun a => f a) = l.flatMap f := by
rw [List.flatMap, ← coe_join, List.map_map]
rfl
@[simp]
theorem zero_bind : bind 0 f = 0 :=
rfl
@[simp]
theorem cons_bind : (a ::ₘ s).bind f = f a + s.bind f := by simp [bind]
@[simp]
theorem singleton_bind : bind {a} f = f a := by simp [bind]
@[simp]
theorem add_bind : (s + t).bind f = s.bind f + t.bind f := by simp [bind]
@[simp]
theorem bind_zero : s.bind (fun _ => 0 : α → Multiset β) = 0 := by simp [bind, join, nsmul_zero]
@[simp]
theorem bind_add : (s.bind fun a => f a + g a) = s.bind f + s.bind g := by simp [bind, join]
@[simp]
theorem bind_cons (f : α → β) (g : α → Multiset β) :
(s.bind fun a => f a ::ₘ g a) = map f s + s.bind g :=
Multiset.induction_on s (by simp)
(by simp +contextual [add_comm, add_left_comm, add_assoc])
@[simp]
theorem bind_singleton (f : α → β) : (s.bind fun x => ({f x} : Multiset β)) = map f s :=
Multiset.induction_on s (by rw [zero_bind, map_zero]) (by simp [singleton_add])
@[simp]
theorem mem_bind {b s} {f : α → Multiset β} : b ∈ bind s f ↔ ∃ a ∈ s, b ∈ f a := by
simp [bind]
@[simp]
theorem card_bind : card (s.bind f) = (s.map (card ∘ f)).sum := by simp [bind]
theorem bind_congr {f g : α → Multiset β} {m : Multiset α} :
(∀ a ∈ m, f a = g a) → bind m f = bind m g := by simp +contextual [bind]
theorem bind_hcongr {β' : Type v} {m : Multiset α} {f : α → Multiset β} {f' : α → Multiset β'}
(h : β = β') (hf : ∀ a ∈ m, f a ≍ f' a) : bind m f ≍ bind m f' := by
subst h
simp only [heq_eq_eq] at hf
simp [bind_congr hf]
theorem map_bind (m : Multiset α) (n : α → Multiset β) (f : β → γ) :
map f (bind m n) = bind m fun a => map f (n a) := by simp [bind]
theorem bind_map (m : Multiset α) (n : β → Multiset γ) (f : α → β) :
bind (map f m) n = bind m fun a => n (f a) :=
Multiset.induction_on m (by simp) (by simp +contextual)
theorem bind_assoc {s : Multiset α} {f : α → Multiset β} {g : β → Multiset γ} :
(s.bind f).bind g = s.bind fun a => (f a).bind g :=
Multiset.induction_on s (by simp) (by simp +contextual)
theorem bind_bind (m : Multiset α) (n : Multiset β) {f : α → β → Multiset γ} :
((bind m) fun a => (bind n) fun b => f a b) = (bind n) fun b => (bind m) fun a => f a b :=
Multiset.induction_on m (by simp) (by simp +contextual)
theorem bind_map_comm (m : Multiset α) (n : Multiset β) {f : α → β → γ} :
((bind m) fun a => n.map fun b => f a b) = (bind n) fun b => m.map fun a => f a b :=
Multiset.induction_on m (by simp) (by simp +contextual)
@[to_additive (attr := simp)]
theorem prod_bind [CommMonoid β] (s : Multiset α) (t : α → Multiset β) :
(s.bind t).prod = (s.map fun a => (t a).prod).prod := by simp [bind]
open scoped Relator in
theorem rel_bind {r : α → β → Prop} {p : γ → δ → Prop} {s t} {f : α → Multiset γ}
{g : β → Multiset δ} (h : (r ⇒ Rel p) f g) (hst : Rel r s t) :
Rel p (s.bind f) (t.bind g) := by
apply rel_join
rw [rel_map]
exact hst.mono fun a _ b _ hr => h hr
theorem count_sum [DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α} :
count a (map f m).sum = sum (m.map fun b => count a <| f b) :=
Multiset.induction_on m (by simp) (by simp)
theorem count_bind [DecidableEq α] {m : Multiset β} {f : β → Multiset α} {a : α} :
count a (bind m f) = sum (m.map fun b => count a <| f b) :=
count_sum
theorem le_bind {α β : Type*} {f : α → Multiset β} (S : Multiset α) {x : α} (hx : x ∈ S) :
f x ≤ S.bind f := by
classical
refine le_iff_count.2 fun a ↦ ?_
obtain ⟨m', hm'⟩ := exists_cons_of_mem <| mem_map_of_mem (fun b ↦ count a (f b)) hx
rw [count_bind, hm', sum_cons]
exact Nat.le_add_right _ _
@[simp]
theorem attach_bind_coe (s : Multiset α) (f : α → Multiset β) :
(s.attach.bind fun i => f i) = s.bind f :=
congr_arg join <| attach_map_val' _ _
variable {f s t}
open scoped Function in -- required for scoped `on` notation
@[simp] lemma nodup_bind :
Nodup (bind s f) ↔ (∀ a ∈ s, Nodup (f a)) ∧ s.Pairwise (Disjoint on f) := by
have : ∀ a, ∃ l : List β, f a = l := fun a => Quot.induction_on (f a) fun l => ⟨l, rfl⟩
choose f' h' using this
have : f = fun a ↦ ofList (f' a) := funext h'
have hd : Symmetric fun a b ↦ List.Disjoint (f' a) (f' b) := fun a b h ↦ h.symm
exact Quot.induction_on s <| by
unfold Function.onFun
simp [this, List.nodup_flatMap, pairwise_coe_iff_pairwise hd]
@[simp]
lemma dedup_bind_dedup [DecidableEq α] [DecidableEq β] (s : Multiset α) (f : α → Multiset β) :
(s.dedup.bind f).dedup = (s.bind f).dedup := by
ext x
-- Porting note: was `simp_rw [count_dedup, mem_bind, mem_dedup]`
simp_rw [count_dedup]
congr 1
simp
variable (op : α → α → α) [hc : Std.Commutative op] [ha : Std.Associative op]
theorem fold_bind {ι : Type*} (s : Multiset ι) (t : ι → Multiset α) (b : ι → α) (b₀ : α) :
(s.bind t).fold op ((s.map b).fold op b₀) =
(s.map fun i => (t i).fold op (b i)).fold op b₀ := by
induction' s using Multiset.induction_on with a ha ih
· rw [zero_bind, map_zero, map_zero, fold_zero]
· rw [cons_bind, map_cons, map_cons, fold_cons_left, fold_cons_left, fold_add, ih]
end Bind
/-! ### Product of two multisets -/
section Product
variable (a : α) (b : β) (s : Multiset α) (t : Multiset β)
/-- The multiplicity of `(a, b)` in `s ×ˢ t` is
the product of the multiplicity of `a` in `s` and `b` in `t`. -/
def product (s : Multiset α) (t : Multiset β) : Multiset (α × β) :=
s.bind fun a => t.map <| Prod.mk a
instance instSProd : SProd (Multiset α) (Multiset β) (Multiset (α × β)) where
sprod := Multiset.product
@[simp]
theorem coe_product (l₁ : List α) (l₂ : List β) :
(l₁ : Multiset α) ×ˢ (l₂ : Multiset β) = (l₁ ×ˢ l₂) := by
dsimp only [SProd.sprod]
rw [product, List.product, ← coe_bind]
simp
@[simp]
theorem zero_product : (0 : Multiset α) ×ˢ t = 0 :=
rfl
@[simp]
theorem cons_product : (a ::ₘ s) ×ˢ t = map (Prod.mk a) t + s ×ˢ t := by simp [SProd.sprod, product]
@[simp]
theorem product_zero : s ×ˢ (0 : Multiset β) = 0 := by simp [SProd.sprod, product]
@[simp]
theorem product_cons : s ×ˢ (b ::ₘ t) = (s.map fun a => (a, b)) + s ×ˢ t := by
simp [SProd.sprod, product]
@[simp]
theorem product_singleton : ({a} : Multiset α) ×ˢ ({b} : Multiset β) = {(a, b)} := by
simp only [SProd.sprod, product, bind_singleton, map_singleton]
@[simp]
theorem add_product (s t : Multiset α) (u : Multiset β) : (s + t) ×ˢ u = s ×ˢ u + t ×ˢ u := by
simp [SProd.sprod, product]
@[simp]
theorem product_add (s : Multiset α) : ∀ t u : Multiset β, s ×ˢ (t + u) = s ×ˢ t + s ×ˢ u :=
Multiset.induction_on s (fun _ _ => rfl) fun a s IH t u => by
rw [cons_product, IH]
simp [add_left_comm, add_assoc]
@[simp]
theorem card_product : card (s ×ˢ t) = card s * card t := by simp [SProd.sprod, product]
variable {s t}
@[simp] lemma mem_product : ∀ {p : α × β}, p ∈ @product α β s t ↔ p.1 ∈ s ∧ p.2 ∈ t
| (a, b) => by simp [product, and_left_comm]
protected theorem Nodup.product : Nodup s → Nodup t → Nodup (s ×ˢ t) :=
Quotient.inductionOn₂ s t fun l₁ l₂ d₁ d₂ => by simp [List.Nodup.product d₁ d₂]
end Product
/-! ### Disjoint sum of multisets -/
section Sigma
variable {σ : α → Type*} (a : α) (s : Multiset α) (t : ∀ a, Multiset (σ a))
/-- `Multiset.sigma s t` is the dependent version of `Multiset.product`. It is the sum of
`(a, b)` as `a` ranges over `s` and `b` ranges over `t a`. -/
protected def sigma (s : Multiset α) (t : ∀ a, Multiset (σ a)) : Multiset (Σ a, σ a) :=
s.bind fun a => (t a).map <| Sigma.mk a
@[simp]
theorem coe_sigma (l₁ : List α) (l₂ : ∀ a, List (σ a)) :
(@Multiset.sigma α σ l₁ fun a => l₂ a) = l₁.sigma l₂ := by
rw [Multiset.sigma, List.sigma, ← coe_bind]
simp
@[simp]
theorem zero_sigma : @Multiset.sigma α σ 0 t = 0 :=
rfl
@[simp]
theorem cons_sigma : (a ::ₘ s).sigma t = (t a).map (Sigma.mk a) + s.sigma t := by
simp [Multiset.sigma]
@[simp]
theorem sigma_singleton (b : α → β) :
(({a} : Multiset α).sigma fun a => ({b a} : Multiset β)) = {⟨a, b a⟩} :=
rfl
@[simp]
theorem add_sigma (s t : Multiset α) (u : ∀ a, Multiset (σ a)) :
(s + t).sigma u = s.sigma u + t.sigma u := by simp [Multiset.sigma]
@[simp]
theorem sigma_add :
∀ t u : ∀ a, Multiset (σ a), (s.sigma fun a => t a + u a) = s.sigma t + s.sigma u :=
Multiset.induction_on s (fun _ _ => rfl) fun a s IH t u => by
rw [cons_sigma, IH]
simp [add_comm, add_left_comm, add_assoc]
@[simp]
theorem card_sigma : card (s.sigma t) = sum (map (fun a => card (t a)) s) := by
simp [Multiset.sigma, (· ∘ ·)]
variable {s t}
@[simp] lemma mem_sigma : ∀ {p : Σ a, σ a}, p ∈ @Multiset.sigma α σ s t ↔ p.1 ∈ s ∧ p.2 ∈ t p.1
| ⟨a, b⟩ => by simp [Multiset.sigma, and_left_comm]
protected theorem Nodup.sigma {σ : α → Type*} {t : ∀ a, Multiset (σ a)} :
Nodup s → (∀ a, Nodup (t a)) → Nodup (s.sigma t) :=
Quot.induction_on s fun l₁ => by
choose f hf using fun a => Quotient.exists_rep (t a)
simpa [← funext hf] using List.Nodup.sigma
end Sigma
end Multiset
|
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.
|
ArithMult.lean
|
/-
Copyright (c) 2023 Arend Mellendijk. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Arend Mellendijk
-/
import Mathlib.NumberTheory.ArithmeticFunction
open ArithmeticFunction
variable {R : Type*} [Field R]
set_option linter.unusedVariables false
example : IsMultiplicative μ := by arith_mult
example : IsMultiplicative (ζ * ζ) := by arith_mult
example {R : Type*} [Field R] (f : ArithmeticFunction R) (hf : IsMultiplicative f) :
IsMultiplicative ((ζ : ArithmeticFunction R).pdiv f) := by arith_mult
example (f g : ArithmeticFunction R) (hf : IsMultiplicative f) :
IsMultiplicative (prodPrimeFactors g |>.pmul f) := by arith_mult
example (n : ℕ) : IsMultiplicative <| (σ n * pow (n + 3)).ppow 2 := by arith_mult
|
Rename.lean
|
import Mathlib.Tactic.Rename
example (a : Nat) (b : Int) : Int × Nat := by
rename' a => c, b => d
exact (d, c)
example (a : Nat) (b : Int) : Int × Nat := by
rename' a => b, b => a
exact (a, b)
|
OrderClosedExtr.lean
|
/-
Copyright (c) 2024 Bjørn Kjos-Hanssen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bjørn Kjos-Hanssen, Patrick Massot
-/
import Mathlib.Topology.Order.OrderClosed
import Mathlib.Topology.Order.LocalExtr
/-!
# Local maxima from monotonicity and antitonicity
In this file we prove a lemma that is useful for the First Derivative Test in calculus,
and its dual.
## Main statements
* `isLocalMax_of_mono_anti` : if a function `f` is monotone to the left of `x`
and antitone to the right of `x` then `f` has a local maximum at `x`.
* `isLocalMin_of_anti_mono` : the dual statement for minima.
* `isLocalMax_of_mono_anti'` : a version of `isLocalMax_of_mono_anti` for filters.
* `isLocalMin_of_anti_mono'` : a version of `isLocalMax_of_mono_anti'` for minima.
-/
open Set Topology Filter
/-- If `f` is monotone on `(a,b]` and antitone on `[b,c)` then `f` has
a local maximum at `b`. -/
lemma isLocalMax_of_mono_anti
{α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α]
{β : Type*} [Preorder β]
{a b c : α} (g₀ : a < b) (g₁ : b < c) {f : α → β}
(h₀ : MonotoneOn f (Ioc a b))
(h₁ : AntitoneOn f (Ico b c)) : IsLocalMax f b :=
isLocalMax_of_mono_anti' (Ioc_mem_nhdsLE g₀) (Ico_mem_nhdsGE g₁) h₀ h₁
/-- If `f` is antitone on `(a,b]` and monotone on `[b,c)` then `f` has
a local minimum at `b`. -/
lemma isLocalMin_of_anti_mono
{α : Type*} [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α]
{β : Type*} [Preorder β] {a b c : α} (g₀ : a < b) (g₁ : b < c) {f : α → β}
(h₀ : AntitoneOn f (Ioc a b)) (h₁ : MonotoneOn f (Ico b c)) : IsLocalMin f b :=
mem_of_superset (Ioo_mem_nhds g₀ g₁) (fun x hx => by rcases le_total x b <;> aesop)
|
Prime.lean
|
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.Num.ZNum
import Mathlib.Tactic.Ring
/-!
# Primality for binary natural numbers
This file defines versions of `Nat.minFac` and `Nat.Prime` for `Num` and `PosNum`. As with other
`Num` definitions, they are not intended for general use (`Nat` should be used instead of `Num` in
most cases) but they can be used in contexts where kernel computation is required, such as proofs
by `rfl` and `decide`, as well as in `#reduce`.
The default decidable instance for `Nat.Prime` is optimized for VM evaluation, so it should be
preferred within `#eval` or in tactic execution, while for proofs the `norm_num` tactic can be used
to construct primality and non-primality proofs more efficiently than kernel computation.
Nevertheless, sometimes proof by computational reflection requires natural number computations, and
`Num` implements algorithms directly on binary natural numbers for this purpose.
-/
namespace PosNum
/-- Auxiliary function for computing the smallest prime factor of a `PosNum`. Unlike
`Nat.minFacAux`, we use a natural number `fuel` variable that is set to an upper bound on the
number of iterations. It is initialized to the number `n` we are determining primality for. Even
though this is exponential in the input (since it is a `Nat`, not a `Num`), it will get lazily
evaluated during kernel reduction, so we will only require about `sqrt n` unfoldings, for the
`sqrt n` iterations of the loop. -/
def minFacAux (n : PosNum) : ℕ → PosNum → PosNum
| 0, _ => n
| fuel + 1, k =>
if n < k.bit1 * k.bit1 then n else if k.bit1 ∣ n then k.bit1 else minFacAux n fuel k.succ
theorem minFacAux_to_nat {fuel : ℕ} {n k : PosNum} (h : Nat.sqrt n < fuel + k.bit1) :
(minFacAux n fuel k : ℕ) = Nat.minFacAux n k.bit1 := by
induction' fuel with fuel ih generalizing k <;> rw [minFacAux, Nat.minFacAux]
· rw [Nat.zero_add, Nat.sqrt_lt] at h
simp only [h, ite_true]
simp_rw [← mul_to_nat]
simp only [cast_lt, dvd_to_nat]
split_ifs <;> try rfl
rw [ih] <;> [congr; convert Nat.lt_succ_of_lt h using 1] <;>
simp only [cast_bit1, cast_succ, Nat.succ_eq_add_one, add_assoc,
add_left_comm, ← one_add_one_eq_two]
/-- Returns the smallest prime factor of `n ≠ 1`. -/
def minFac : PosNum → PosNum
| 1 => 1
| bit0 _ => 2
| bit1 n => minFacAux (bit1 n) n 1
@[simp]
theorem minFac_to_nat (n : PosNum) : (minFac n : ℕ) = Nat.minFac n := by
obtain - | n := n
· rfl
· rw [minFac, Nat.minFac_eq, if_neg]
swap
· simp [← two_mul]
rw [minFacAux_to_nat]
· rfl
simp only [cast_one, cast_bit1]
rw [Nat.sqrt_lt]
calc
(n : ℕ) + (n : ℕ) + 1 ≤ (n : ℕ) + (n : ℕ) + (n : ℕ) := by simp
_ = (n : ℕ) * (1 + 1 + 1) := by simp only [mul_add, mul_one]
_ < _ := by simp [mul_lt_mul]
· rw [minFac, Nat.minFac_eq, if_pos]
· rfl
simp [← two_mul]
/-- Primality predicate for a `PosNum`. -/
@[simp]
def Prime (n : PosNum) : Prop :=
Nat.Prime n
instance decidablePrime : DecidablePred PosNum.Prime
| 1 => Decidable.isFalse Nat.not_prime_one
| bit0 n =>
decidable_of_iff' (n = 1)
(by
refine Nat.prime_def_minFac.trans ((and_iff_right ?_).trans <| eq_comm.trans ?_)
· exact add_le_add (Nat.succ_le_of_lt (to_nat_pos _)) (Nat.succ_le_of_lt (to_nat_pos _))
rw [← minFac_to_nat, to_nat_inj]
exact ⟨bit0.inj, congr_arg _⟩)
| bit1 n =>
decidable_of_iff' (minFacAux (bit1 n) n 1 = bit1 n) <| by
refine Nat.prime_def_minFac.trans ((and_iff_right ?_).trans ?_)
· simp only [cast_bit1]
have := to_nat_pos n
omega
rw [← minFac_to_nat, to_nat_inj]; rfl
end PosNum
namespace Num
/-- Returns the smallest prime factor of `n ≠ 1`. -/
def minFac : Num → PosNum
| 0 => 2
| pos n => n.minFac
@[simp]
theorem minFac_to_nat : ∀ n : Num, (minFac n : ℕ) = Nat.minFac n
| 0 => rfl
| pos _ => PosNum.minFac_to_nat _
/-- Primality predicate for a `Num`. -/
@[simp]
def Prime (n : Num) : Prop :=
Nat.Prime n
instance decidablePrime : DecidablePred Num.Prime
| 0 => Decidable.isFalse Nat.not_prime_zero
| pos n => PosNum.decidablePrime n
end Num
|
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.
|
Shapiro.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.CategoryTheory.Preadditive.Projective.Resolution
import Mathlib.RepresentationTheory.Homological.GroupCohomology.Basic
import Mathlib.RepresentationTheory.Coinduced
import Mathlib.RepresentationTheory.Induced
/-!
# Shapiro's lemma for group cohomology
Given a commutative ring `k` and a subgroup `S ≤ G`, the file
`RepresentationTheory/Coinduced.lean` proves that the functor `Coind_S^G : Rep k S ⥤ Rep k G`
preserves epimorphisms. Since `Res(S) : Rep k G ⥤ Rep k S` is left adjoint to `Coind_S^G`, this
means `Res(S)` preserves projective objects. Since `Res(S)` is also exact, given a projective
resolution `P` of `k` as a trivial `k`-linear `G`-representation, `Res(S)(P)` is a projective
resolution of `k` as a trivial `k`-linear `S`-representation.
Since `Hom(Res(S)(P), A) ≅ Hom(P, Coind_S^G(A))` for any `S`-representation `A`, we conclude
Shapiro's lemma for group cohomology: `Hⁿ(G, Coind_S^G(A)) ≅ Hⁿ(S, A)` for all `n`.
## Main definitions
* `groupCohomology.coindIso A n`: Shapiro's lemma for group cohomology: an isomorphism
`Hⁿ(G, Coind_S^G(A)) ≅ Hⁿ(S, A)`, given a subgroup `S ≤ G` and an `S`-representation `A`.
!-/
universe u
namespace groupCohomology
open CategoryTheory Finsupp TensorProduct Rep
variable {k G : Type u} [CommRing k] [Group G] {S : Subgroup G} (A : Rep k S)
/-- Given a projective resolution `P` of `k` as a `k`-linear `G`-representation, a subgroup
`S ≤ G`, and a `k`-linear `S`-representation `A`, this is an isomorphism of complexes
`Hom(Res(S)(P), A) ≅ Hom(P, Coind_S^G(A)).` -/
noncomputable def linearYonedaObjResProjectiveResolutionIso
(P : ProjectiveResolution (trivial k G k)) (A : Rep k S) :
((Action.res _ S.subtype).mapProjectiveResolution P).complex.linearYonedaObj k A ≅
P.complex.linearYonedaObj k (coind S.subtype A) :=
HomologicalComplex.Hom.isoOfComponents
(fun _ => (resCoindHomEquiv _ _ _).toModuleIso) fun _ _ _ =>
ModuleCat.hom_ext (LinearMap.ext fun f => Action.Hom.ext <| by ext; simp [hom_comm_apply])
/-- Shapiro's lemma: given a subgroup `S ≤ G` and an `S`-representation `A`, we have
`Hⁿ(G, Coind_S^G(A)) ≅ Hⁿ(S, A).` -/
noncomputable def coindIso [DecidableEq G] (A : Rep k S) (n : ℕ) :
groupCohomology (coind S.subtype A) n ≅ groupCohomology A n :=
(HomologicalComplex.homologyFunctor _ _ _).mapIso
(inhomogeneousCochainsIso (coind S.subtype A) ≪≫
(linearYonedaObjResProjectiveResolutionIso (barResolution k G) A).symm) ≪≫
(groupCohomologyIso A n ((Action.res _ _).mapProjectiveResolution <| barResolution k G)).symm
end groupCohomology
|
Synonym.lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.GroupWithZero.Defs
import Mathlib.Algebra.Order.Group.Synonym
/-!
# Group with zero structure on the order type synonyms
Transfer algebraic instances from `α` to `αᵒᵈ` and `Lex α`.
-/
open Function
variable {α : Type*}
/-! ### Order dual -/
open OrderDual
instance [h : MulZeroClass α] : MulZeroClass αᵒᵈ := h
instance [h : MulZeroOneClass α] : MulZeroOneClass αᵒᵈ := h
instance [Mul α] [Zero α] [h : NoZeroDivisors α] : NoZeroDivisors αᵒᵈ := h
instance [h : SemigroupWithZero α] : SemigroupWithZero αᵒᵈ := h
instance [h : MonoidWithZero α] : MonoidWithZero αᵒᵈ := h
instance [h : CancelMonoidWithZero α] : CancelMonoidWithZero αᵒᵈ := h
instance [h : CommMonoidWithZero α] : CommMonoidWithZero αᵒᵈ := h
instance [h : CancelCommMonoidWithZero α] : CancelCommMonoidWithZero αᵒᵈ := h
instance [h : GroupWithZero α] : GroupWithZero αᵒᵈ := h
instance [h : CommGroupWithZero α] : CommGroupWithZero αᵒᵈ := h
/-! ### Lexicographic order -/
instance [h : MulZeroClass α] : MulZeroClass (Lex α) := h
instance [h : MulZeroOneClass α] : MulZeroOneClass (Lex α) := h
instance [Mul α] [Zero α] [h : NoZeroDivisors α] : NoZeroDivisors (Lex α) := h
instance [h : SemigroupWithZero α] : SemigroupWithZero (Lex α) := h
instance [h : MonoidWithZero α] : MonoidWithZero (Lex α) := h
instance [h : CancelMonoidWithZero α] : CancelMonoidWithZero (Lex α) := h
instance [h : CommMonoidWithZero α] : CommMonoidWithZero (Lex α) := h
instance [h : CancelCommMonoidWithZero α] : CancelCommMonoidWithZero (Lex α) := h
instance [h : GroupWithZero α] : GroupWithZero (Lex α) := h
instance [h : CommGroupWithZero α] : CommGroupWithZero (Lex α) := h
|
SchroederBernstein.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Set.Piecewise
import Mathlib.Order.FixedPoints
import Mathlib.Order.Zorn
/-!
# Schröder-Bernstein theorem, well-ordering of cardinals
This file proves the Schröder-Bernstein theorem (see `schroeder_bernstein`), the well-ordering of
cardinals (see `min_injective`) and the totality of their order (see `total`).
## Notes
Cardinals are naturally ordered by `α ≤ β ↔ ∃ f : a → β, Injective f`:
* `schroeder_bernstein` states that, given injections `α → β` and `β → α`, one can get a
bijection `α → β`. This corresponds to the antisymmetry of the order.
* The order is also well-founded: any nonempty set of cardinals has a minimal element.
`min_injective` states that by saying that there exists an element of the set that injects into
all others.
Cardinals are defined and further developed in the folder `SetTheory.Cardinal`.
-/
open Set Function
universe u v
namespace Function
namespace Embedding
section antisymm
variable {α : Type u} {β : Type v}
/-- **The Schröder-Bernstein Theorem**:
Given injections `α → β` and `β → α`, we can get a bijection `α → β`. -/
theorem schroeder_bernstein {f : α → β} {g : β → α} (hf : Function.Injective f)
(hg : Function.Injective g) : ∃ h : α → β, Bijective h := by
classical
rcases isEmpty_or_nonempty β with hβ | hβ
· have : IsEmpty α := Function.isEmpty f
exact ⟨_, ((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).bijective⟩
set F : Set α →o Set α :=
{ toFun := fun s => (g '' (f '' s)ᶜ)ᶜ
monotone' := fun s t hst => by dsimp at hst ⊢; gcongr }
set s : Set α := F.lfp
have hs : (g '' (f '' s)ᶜ)ᶜ = s := F.map_lfp
have hns : g '' (f '' s)ᶜ = sᶜ := compl_injective (by simp [hs])
set g' := invFun g
have g'g : LeftInverse g' g := leftInverse_invFun hg
have hg'ns : g' '' sᶜ = (f '' s)ᶜ := by rw [← hns, g'g.image_image]
set h : α → β := s.piecewise f g'
have : Surjective h := by rw [← range_eq_univ, range_piecewise, hg'ns, union_compl_self]
have : Injective h := by
refine (injective_piecewise_iff _).2 ⟨hf.injOn, ?_, ?_⟩
· intro x hx y hy hxy
obtain ⟨x', _, rfl⟩ : x ∈ g '' (f '' s)ᶜ := by rwa [hns]
obtain ⟨y', _, rfl⟩ : y ∈ g '' (f '' s)ᶜ := by rwa [hns]
rw [g'g _, g'g _] at hxy
rw [hxy]
· intro x hx y hy hxy
obtain ⟨y', hy', rfl⟩ : y ∈ g '' (f '' s)ᶜ := by rwa [hns]
rw [g'g _] at hxy
exact hy' ⟨x, hx, hxy⟩
exact ⟨h, ‹Injective h›, ‹Surjective h›⟩
/-- **The Schröder-Bernstein Theorem**: Given embeddings `α ↪ β` and `β ↪ α`, there exists an
equivalence `α ≃ β`. -/
theorem antisymm : (α ↪ β) → (β ↪ α) → Nonempty (α ≃ β)
| ⟨_, h₁⟩, ⟨_, h₂⟩ =>
let ⟨f, hf⟩ := schroeder_bernstein h₁ h₂
⟨Equiv.ofBijective f hf⟩
end antisymm
section Wo
variable {ι : Type u} (β : ι → Type v)
/-- `sets β` -/
private abbrev sets :=
{ s : Set (∀ i, β i) | ∀ i : ι, s.InjOn fun x => x i }
/-- The cardinals are well-ordered. We express it here by the fact that in any set of cardinals
there is an element that injects into the others.
See `Cardinal.conditionallyCompleteLinearOrderBot` for (one of) the lattice instances. -/
theorem min_injective [I : Nonempty ι] : ∃ i, Nonempty (∀ j, β i ↪ β j) :=
let ⟨s, hs⟩ := show ∃ s, Maximal (· ∈ sets β) s by
refine zorn_subset _ fun c hc hcc ↦
⟨⋃₀ c, fun i x ⟨p, hpc, hxp⟩ y ⟨q, hqc, hyq⟩ hi ↦ ?_, fun _ ↦ subset_sUnion_of_mem⟩
exact (hcc.total hpc hqc).elim (fun h ↦ hc hqc i (h hxp) hyq hi)
fun h ↦ hc hpc i hxp (h hyq) hi
let ⟨i, e⟩ :=
show ∃ i, Surjective fun x : s => x.val i from
Classical.by_contradiction fun h =>
have h : ∀ i, ∃ y, ∀ x ∈ s, (x : ∀ i, β i) i ≠ y := by
simpa [Surjective] using h
let ⟨f, hf⟩ := Classical.axiom_of_choice h
have : f ∈ s :=
have : insert f s ∈ sets β := fun i x hx y hy => by
rcases hx with hx | hx <;> rcases hy with hy | hy; · simp [hx, hy]
· subst x
exact fun e => (hf i y hy e.symm).elim
· subst y
exact fun e => (hf i x hx e).elim
· exact hs.prop i hx hy
hs.eq_of_subset this (subset_insert _ _) ▸ mem_insert ..
let ⟨i⟩ := I
hf i f this rfl
⟨i, ⟨fun j => ⟨s.restrict (fun x => x j) ∘ surjInv e,
((hs.1 j).injective).comp (injective_surjInv _)⟩⟩⟩
end Wo
/-- The cardinals are totally ordered. See
`Cardinal.conditionallyCompleteLinearOrderBot` for (one of) the lattice
instance. -/
-- Porting note: `ULift.{max u v, u} α` was `ULift α`
theorem total (α : Type u) (β : Type v) : Nonempty (α ↪ β) ∨ Nonempty (β ↪ α) :=
match @min_injective Bool (fun b => cond b (ULift.{max u v, u} α) (ULift.{max u v, v} β)) ⟨true⟩
with
| ⟨true, ⟨h⟩⟩ =>
let ⟨f, hf⟩ := h false
Or.inl ⟨Embedding.congr Equiv.ulift Equiv.ulift ⟨f, hf⟩⟩
| ⟨false, ⟨h⟩⟩ =>
let ⟨f, hf⟩ := h true
Or.inr ⟨Embedding.congr Equiv.ulift Equiv.ulift ⟨f, hf⟩⟩
end Embedding
end Function
|
WellFounded.lean
|
/-
Copyright (c) 2022 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Data.DFinsupp.Lex
import Mathlib.Order.Antisymmetrization
import Mathlib.Order.GameAdd
import Mathlib.SetTheory.Cardinal.Order
import Mathlib.Tactic.AdaptationNote
/-!
# Well-foundedness of the lexicographic and product orders on `DFinsupp` and `Pi`
The primary results are `DFinsupp.Lex.wellFounded` and the two variants that follow it,
which essentially say that if `(· > ·)` is a well order on `ι`, `(· < ·)` is well-founded on each
`α i`, and `0` is a bottom element in `α i`, then the lexicographic `(· < ·)` is well-founded
on `Π₀ i, α i`. The proof is modelled on the proof of `WellFounded.cutExpand`.
The results are used to prove `Pi.Lex.wellFounded` and two variants, which say that if
`ι` is finite and equipped with a linear order and `(· < ·)` is well-founded on each `α i`,
then the lexicographic `(· < ·)` is well-founded on `Π i, α i`, and the same is true for
`Π₀ i, α i` (`DFinsupp.Lex.wellFounded_of_finite`), because `DFinsupp` is order-isomorphic
to `pi` when `ι` is finite.
Finally, we deduce `DFinsupp.wellFoundedLT`, `Pi.wellFoundedLT`,
`DFinsupp.wellFoundedLT_of_finite` and variants, which concern the product order
rather than the lexicographic one. An order on `ι` is not required in these results,
but we deduce them from the well-foundedness of the lexicographic order by choosing
a well order on `ι` so that the product order `(· < ·)` becomes a subrelation
of the lexicographic `(· < ·)`.
All results are provided in two forms whenever possible: a general form where the relations
can be arbitrary (not the `(· < ·)` of a preorder, or not even transitive, etc.) and a specialized
form provided as `WellFoundedLT` instances where the `(d)Finsupp/pi` type (or their `Lex`
type synonyms) carries a natural `(· < ·)`.
Notice that the definition of `DFinsupp.Lex` says that `x < y` according to `DFinsupp.Lex r s`
iff there exists a coordinate `i : ι` such that `x i < y i` according to `s i`, and at all
`r`-smaller coordinates `j` (i.e. satisfying `r j i`), `x` remains unchanged relative to `y`;
in other words, coordinates `j` such that `¬ r j i` and `j ≠ i` are exactly where changes
can happen arbitrarily. This explains the appearance of `rᶜ ⊓ (≠)` in
`dfinsupp.acc_single` and `dfinsupp.well_founded`. When `r` is trichotomous (e.g. the `(· < ·)`
of a linear order), `¬ r j i ∧ j ≠ i` implies `r i j`, so it suffices to require `r.swap`
to be well-founded.
-/
variable {ι : Type*} {α : ι → Type*}
namespace DFinsupp
open Relation Prod
section Zero
variable [∀ i, Zero (α i)] (r : ι → ι → Prop) (s : ∀ i, α i → α i → Prop)
/-- This key lemma says that if a finitely supported dependent function `x₀` is obtained by merging
two such functions `x₁` and `x₂`, and if we evolve `x₀` down the `DFinsupp.Lex` relation one
step and get `x`, we can always evolve one of `x₁` and `x₂` down the `DFinsupp.Lex` relation
one step while keeping the other unchanged, and merge them back (possibly in a different way)
to get back `x`. In other words, the two parts evolve essentially independently under
`DFinsupp.Lex`. This is used to show that a function `x` is accessible if
`DFinsupp.single i (x i)` is accessible for each `i` in the (finite) support of `x`
(`DFinsupp.Lex.acc_of_single`). -/
theorem lex_fibration [∀ (i) (s : Set ι), Decidable (i ∈ s)] :
Fibration (InvImage (GameAdd (DFinsupp.Lex r s) (DFinsupp.Lex r s)) snd) (DFinsupp.Lex r s)
fun x => piecewise x.2.1 x.2.2 x.1 := by
rintro ⟨p, x₁, x₂⟩ x ⟨i, hr, hs⟩
simp_rw [piecewise_apply] at hs hr
split_ifs at hs with hp
· refine ⟨⟨{ j | r j i → j ∈ p }, piecewise x₁ x { j | r j i }, x₂⟩,
.fst ⟨i, fun j hj ↦ ?_, ?_⟩, ?_⟩ <;> simp only [piecewise_apply, Set.mem_setOf_eq]
· simp only [if_pos hj]
· split_ifs with hi
· rwa [hr i hi, if_pos hp] at hs
· assumption
· ext1 j
simp only [piecewise_apply, Set.mem_setOf_eq]
split_ifs with h₁ h₂ <;> try rfl
· rw [hr j h₂, if_pos (h₁ h₂)]
· rw [Classical.not_imp] at h₁
rw [hr j h₁.1, if_neg h₁.2]
· refine ⟨⟨{ j | r j i ∧ j ∈ p }, x₁, piecewise x₂ x { j | r j i }⟩,
.snd ⟨i, fun j hj ↦ ?_, ?_⟩, ?_⟩ <;> simp only [piecewise_apply, Set.mem_setOf_eq]
· exact if_pos hj
· split_ifs with hi
· rwa [hr i hi, if_neg hp] at hs
· assumption
· ext1 j
simp only [piecewise_apply, Set.mem_setOf_eq]
split_ifs with h₁ h₂ <;> try rfl
· rw [hr j h₁.1, if_pos h₁.2]
· rw [hr j h₂, if_neg]
simpa [h₂] using h₁
variable {r s}
theorem Lex.acc_of_single_erase [DecidableEq ι] {x : Π₀ i, α i} (i : ι)
(hs : Acc (DFinsupp.Lex r s) <| single i (x i)) (hu : Acc (DFinsupp.Lex r s) <| x.erase i) :
Acc (DFinsupp.Lex r s) x := by
classical
convert ← @Acc.of_fibration _ _ _ _ _ (lex_fibration r s) ⟨{i}, _⟩
(InvImage.accessible snd <| hs.prod_gameAdd hu)
convert piecewise_single_erase x i
theorem Lex.acc_zero (hbot : ∀ ⦃i a⦄, ¬s i a 0) : Acc (DFinsupp.Lex r s) 0 :=
Acc.intro 0 fun _ ⟨_, _, h⟩ => (hbot h).elim
theorem Lex.acc_of_single (hbot : ∀ ⦃i a⦄, ¬s i a 0) [DecidableEq ι]
[∀ (i) (x : α i), Decidable (x ≠ 0)] (x : Π₀ i, α i) :
(∀ i ∈ x.support, Acc (DFinsupp.Lex r s) <| single i (x i)) → Acc (DFinsupp.Lex r s) x := by
generalize ht : x.support = t; revert x
classical
induction' t using Finset.induction with b t hb ih
· intro x ht
rw [support_eq_empty.1 ht]
exact fun _ => Lex.acc_zero hbot
refine fun x ht h => Lex.acc_of_single_erase b (h b <| t.mem_insert_self b) ?_
refine ih _ (by rw [support_erase, ht, Finset.erase_insert hb]) fun a ha => ?_
rw [erase_ne (ha.ne_of_notMem hb)]
exact h a (Finset.mem_insert_of_mem ha)
theorem Lex.acc_single (hbot : ∀ ⦃i a⦄, ¬s i a 0) (hs : ∀ i, WellFounded (s i))
[DecidableEq ι] {i : ι} (hi : Acc (rᶜ ⊓ (· ≠ ·)) i) :
∀ a, Acc (DFinsupp.Lex r s) (single i a) := by
induction' hi with i _ ih
refine fun a => WellFounded.induction (hs i)
(C := fun x ↦ Acc (DFinsupp.Lex r s) (single i x)) a fun a ha ↦ ?_
refine Acc.intro _ fun x ↦ ?_
rintro ⟨k, hr, hs⟩
rw [single_apply] at hs
split_ifs at hs with hik
swap
· exact (hbot hs).elim
subst hik
classical
refine Lex.acc_of_single hbot x fun j hj ↦ ?_
obtain rfl | hij := eq_or_ne i j
· exact ha _ hs
by_cases h : r j i
· rw [hr j h, single_eq_of_ne hij, single_zero]
exact Lex.acc_zero hbot
· exact ih _ ⟨h, hij.symm⟩ _
theorem Lex.acc (hbot : ∀ ⦃i a⦄, ¬s i a 0) (hs : ∀ i, WellFounded (s i))
[DecidableEq ι] [∀ (i) (x : α i), Decidable (x ≠ 0)] (x : Π₀ i, α i)
(h : ∀ i ∈ x.support, Acc (rᶜ ⊓ (· ≠ ·)) i) : Acc (DFinsupp.Lex r s) x :=
Lex.acc_of_single hbot x fun i hi => Lex.acc_single hbot hs (h i hi) _
theorem Lex.wellFounded (hbot : ∀ ⦃i a⦄, ¬s i a 0) (hs : ∀ i, WellFounded (s i))
(hr : WellFounded <| rᶜ ⊓ (· ≠ ·)) : WellFounded (DFinsupp.Lex r s) :=
⟨fun x => by classical exact Lex.acc hbot hs x fun i _ => hr.apply i⟩
theorem Lex.wellFounded' (hbot : ∀ ⦃i a⦄, ¬s i a 0) (hs : ∀ i, WellFounded (s i))
[IsTrichotomous ι r] (hr : WellFounded (Function.swap r)) :
WellFounded (DFinsupp.Lex r s) :=
Lex.wellFounded hbot hs <| Subrelation.wf
(fun {i j} h => ((@IsTrichotomous.trichotomous ι r _ i j).resolve_left h.1).resolve_left h.2) hr
end Zero
instance Lex.wellFoundedLT [LT ι] [IsTrichotomous ι (· < ·)] [hι : WellFoundedGT ι]
[∀ i, AddMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, CanonicallyOrderedAdd (α i)]
[hα : ∀ i, WellFoundedLT (α i)] :
WellFoundedLT (Lex (Π₀ i, α i)) :=
⟨Lex.wellFounded' (fun _ a => (zero_le a).not_gt) (fun i => (hα i).wf) hι.wf⟩
end DFinsupp
open DFinsupp
variable (r : ι → ι → Prop) {s : ∀ i, α i → α i → Prop}
theorem Pi.Lex.wellFounded [IsStrictTotalOrder ι r] [Finite ι] (hs : ∀ i, WellFounded (s i)) :
WellFounded (Pi.Lex r (fun {i} ↦ s i)) := by
obtain h | ⟨⟨x⟩⟩ := isEmpty_or_nonempty (∀ i, α i)
· convert emptyWf.wf
letI : ∀ i, Zero (α i) := fun i => ⟨(hs i).min ⊤ ⟨x i, trivial⟩⟩
haveI := IsTrans.swap r; haveI := IsIrrefl.swap r; haveI := Fintype.ofFinite ι
refine InvImage.wf equivFunOnFintype.symm (Lex.wellFounded' (fun i a => ?_) hs ?_)
exacts [(hs i).not_lt_min ⊤ _ trivial, Finite.wellFounded_of_trans_of_irrefl (Function.swap r)]
instance Pi.Lex.wellFoundedLT [LinearOrder ι] [Finite ι] [∀ i, LT (α i)]
[hwf : ∀ i, WellFoundedLT (α i)] : WellFoundedLT (Lex (∀ i, α i)) :=
⟨Pi.Lex.wellFounded (· < ·) fun i => (hwf i).1⟩
instance Function.Lex.wellFoundedLT {α} [LinearOrder ι] [Finite ι] [LT α] [WellFoundedLT α] :
WellFoundedLT (Lex (ι → α)) :=
Pi.Lex.wellFoundedLT
theorem DFinsupp.Lex.wellFounded_of_finite [IsStrictTotalOrder ι r] [Finite ι] [∀ i, Zero (α i)]
(hs : ∀ i, WellFounded (s i)) : WellFounded (DFinsupp.Lex r s) :=
have := Fintype.ofFinite ι
InvImage.wf equivFunOnFintype (Pi.Lex.wellFounded r hs)
instance DFinsupp.Lex.wellFoundedLT_of_finite [LinearOrder ι] [Finite ι] [∀ i, Zero (α i)]
[∀ i, LT (α i)] [hwf : ∀ i, WellFoundedLT (α i)] : WellFoundedLT (Lex (Π₀ i, α i)) :=
⟨DFinsupp.Lex.wellFounded_of_finite (· < ·) fun i => (hwf i).1⟩
protected theorem DFinsupp.wellFoundedLT [∀ i, Zero (α i)] [∀ i, Preorder (α i)]
[∀ i, WellFoundedLT (α i)] (hbot : ∀ ⦃i⦄ ⦃a : α i⦄, ¬a < 0) : WellFoundedLT (Π₀ i, α i) :=
⟨by
set β := fun i ↦ Antisymmetrization (α i) (· ≤ ·)
set e : (i : ι) → α i → β i := fun i ↦ toAntisymmetrization (· ≤ ·)
let _ : ∀ i, Zero (β i) := fun i ↦ ⟨e i 0⟩
have : WellFounded (DFinsupp.Lex (Function.swap <| @WellOrderingRel ι)
(fun _ ↦ (· < ·) : (i : ι) → β i → β i → Prop)) := by
have := IsTrichotomous.swap (@WellOrderingRel ι)
refine Lex.wellFounded' ?_ (fun i ↦ IsWellFounded.wf) ?_
· rintro i ⟨a⟩
apply hbot
· simp +unfoldPartialApp only [Function.swap]
exact IsWellFounded.wf
refine Subrelation.wf (fun h => ?_) <| InvImage.wf (mapRange e fun _ ↦ rfl) this
have := IsStrictOrder.swap (@WellOrderingRel ι)
obtain ⟨i, he, hl⟩ := lex_lt_of_lt_of_preorder (Function.swap WellOrderingRel) h
exact ⟨i, fun j hj ↦ Quot.sound (he j hj), hl⟩⟩
instance DFinsupp.wellFoundedLT'
[∀ i, AddMonoid (α i)] [∀ i, PartialOrder (α i)] [∀ i, CanonicallyOrderedAdd (α i)]
[∀ i, WellFoundedLT (α i)] : WellFoundedLT (Π₀ i, α i) :=
DFinsupp.wellFoundedLT fun _i a => (zero_le a).not_gt
instance Pi.wellFoundedLT [Finite ι] [∀ i, Preorder (α i)] [hw : ∀ i, WellFoundedLT (α i)] :
WellFoundedLT (∀ i, α i) :=
⟨by
obtain h | ⟨⟨x⟩⟩ := isEmpty_or_nonempty (∀ i, α i)
· convert emptyWf.wf
letI : ∀ i, Zero (α i) := fun i => ⟨(hw i).wf.min ⊤ ⟨x i, trivial⟩⟩
haveI := Fintype.ofFinite ι
refine InvImage.wf equivFunOnFintype.symm (DFinsupp.wellFoundedLT fun i a => ?_).wf
exact (hw i).wf.not_lt_min ⊤ _ trivial⟩
instance Function.wellFoundedLT {α} [Finite ι] [Preorder α] [WellFoundedLT α] :
WellFoundedLT (ι → α) :=
Pi.wellFoundedLT
instance DFinsupp.wellFoundedLT_of_finite [Finite ι] [∀ i, Zero (α i)] [∀ i, Preorder (α i)]
[∀ i, WellFoundedLT (α i)] : WellFoundedLT (Π₀ i, α i) :=
have := Fintype.ofFinite ι
⟨InvImage.wf equivFunOnFintype Pi.wellFoundedLT.wf⟩
|
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.
|
Finset.lean
|
/-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Data.Finset.Max
import Mathlib.Data.Set.Finite.Lattice
import Mathlib.Order.ConditionallyCompleteLattice.Indexed
/-!
# Conditionally complete lattices and finite sets.
-/
open Set
variable {ι α β γ : Type*}
section ConditionallyCompleteLinearOrder
variable [ConditionallyCompleteLinearOrder α] {s t : Set α} {a b : α}
theorem Finset.Nonempty.csSup_eq_max' {s : Finset α} (h : s.Nonempty) : sSup ↑s = s.max' h :=
eq_of_forall_ge_iff fun _ => (csSup_le_iff s.bddAbove h.to_set).trans (s.max'_le_iff h).symm
theorem Finset.Nonempty.csInf_eq_min' {s : Finset α} (h : s.Nonempty) : sInf ↑s = s.min' h :=
@Finset.Nonempty.csSup_eq_max' αᵒᵈ _ s h
theorem Finset.Nonempty.csSup_mem {s : Finset α} (h : s.Nonempty) : sSup (s : Set α) ∈ s := by
rw [h.csSup_eq_max']
exact s.max'_mem _
theorem Finset.Nonempty.csInf_mem {s : Finset α} (h : s.Nonempty) : sInf (s : Set α) ∈ s :=
@Finset.Nonempty.csSup_mem αᵒᵈ _ _ h
theorem Set.Nonempty.csSup_mem (h : s.Nonempty) (hs : s.Finite) : sSup s ∈ s := by
lift s to Finset α using hs
exact Finset.Nonempty.csSup_mem h
theorem Set.Nonempty.csInf_mem (h : s.Nonempty) (hs : s.Finite) : sInf s ∈ s :=
@Set.Nonempty.csSup_mem αᵒᵈ _ _ h hs
theorem Set.Finite.csSup_lt_iff (hs : s.Finite) (h : s.Nonempty) : sSup s < a ↔ ∀ x ∈ s, x < a :=
⟨fun h _ hx => (le_csSup hs.bddAbove hx).trans_lt h, fun H => H _ <| h.csSup_mem hs⟩
theorem Set.Finite.lt_csInf_iff (hs : s.Finite) (h : s.Nonempty) : a < sInf s ↔ ∀ x ∈ s, a < x :=
@Set.Finite.csSup_lt_iff αᵒᵈ _ _ _ hs h
variable (f : ι → α)
theorem Finset.ciSup_eq_max'_image {s : Finset ι} (h : ∃ x ∈ s, sSup ∅ ≤ f x)
(h' : (s.image f).Nonempty := by classical exact image_nonempty.mpr (h.imp fun _ ↦ And.left)) :
⨆ i ∈ s, f i = (s.image f).max' h' := by
classical
rw [iSup, ← h'.csSup_eq_max', coe_image]
refine csSup_eq_csSup_of_forall_exists_le ?_ ?_
· simp only [ciSup_eq_ite, dite_eq_ite, Set.mem_range, Set.mem_image, mem_coe,
exists_exists_and_eq_and, forall_exists_index, forall_apply_eq_imp_iff]
intro i
split_ifs
· exact ⟨_, by assumption, le_rfl⟩
· assumption
· simp only [Set.mem_image, mem_coe, ciSup_eq_ite, dite_eq_ite, Set.mem_range,
exists_exists_eq_and, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
intro i hi
refine ⟨i, ?_⟩
simp [hi]
theorem Finset.ciInf_eq_min'_image {s : Finset ι} (h : ∃ x ∈ s, f x ≤ sInf ∅)
(h' : (s.image f).Nonempty := by classical exact image_nonempty.mpr (h.imp fun _ ↦ And.left)) :
⨅ i ∈ s, f i = (s.image f).min' h' := by
classical
rw [← OrderDual.toDual_inj, toDual_min', toDual_iInf]
simp only [toDual_iInf]
rw [ciSup_eq_max'_image _ h]
simp only [image_image]
congr
theorem Finset.ciSup_mem_image {s : Finset ι} (h : ∃ x ∈ s, sSup ∅ ≤ f x) :
⨆ i ∈ s, f i ∈ s.image f := by
rw [ciSup_eq_max'_image _ h]
exact max'_mem (image f s) _
theorem Finset.ciInf_mem_image {s : Finset ι} (h : ∃ x ∈ s, f x ≤ sInf ∅) :
⨅ i ∈ s, f i ∈ s.image f := by
rw [ciInf_eq_min'_image _ h]
exact min'_mem (image f s) _
theorem Set.Finite.ciSup_mem_image {s : Set ι} (hs : s.Finite) (h : ∃ x ∈ s, sSup ∅ ≤ f x) :
⨆ i ∈ s, f i ∈ f '' s := by
lift s to Finset ι using hs
simp only [Finset.mem_coe] at h
simpa using Finset.ciSup_mem_image f h
theorem Set.Finite.ciInf_mem_image {s : Set ι} (hs : s.Finite) (h : ∃ x ∈ s, f x ≤ sInf ∅) :
⨅ i ∈ s, f i ∈ f '' s := by
lift s to Finset ι using hs
simp only [Finset.mem_coe] at h
simpa using Finset.ciInf_mem_image f h
theorem Set.Finite.ciSup_lt_iff {s : Set ι} {f : ι → α} (hs : s.Finite)
(h : ∃ x ∈ s, sSup ∅ ≤ f x) :
⨆ i ∈ s, f i < a ↔ ∀ x ∈ s, f x < a := by
constructor
· intro h x hx
refine h.trans_le' (le_csSup ?_ ?_)
· classical
refine (((hs.image f).union (finite_singleton (sSup ∅))).subset ?_).bddAbove
intro
simp only [ciSup_eq_ite, dite_eq_ite, mem_range, union_singleton, mem_insert_iff, mem_image,
forall_exists_index]
grind
· simp only [mem_range]
refine ⟨x, ?_⟩
simp [hx]
· have := hs.ciSup_mem_image _ h
grind
theorem Set.Finite.lt_ciInf_iff {s : Set ι} {f : ι → α} (hs : s.Finite)
(h : ∃ x ∈ s, f x ≤ sInf ∅) :
a < ⨅ i ∈ s, f i ↔ ∀ x ∈ s, a < f x := by
constructor
· intro h x hx
refine h.trans_le (csInf_le ?_ ?_)
· classical
refine (((hs.image f).union (finite_singleton (sInf ∅))).subset ?_).bddBelow
intro
simp only [ciInf_eq_ite, dite_eq_ite, mem_range, union_singleton, mem_insert_iff, mem_image,
forall_exists_index]
grind
· simp only [mem_range]
refine ⟨x, ?_⟩
simp [hx]
· intro H
have := hs.ciInf_mem_image _ h
simp only [mem_image] at this
obtain ⟨_, hmem, hx⟩ := this
rw [← hx]
exact H _ hmem
section ListMultiset
lemma List.iSup_mem_map_of_exists_sSup_empty_le {l : List ι} (f : ι → α)
(h : ∃ x ∈ l, sSup ∅ ≤ f x) :
⨆ x ∈ l, f x ∈ l.map f := by
classical
simpa using l.toFinset.ciSup_mem_image f (by simpa using h)
lemma List.iInf_mem_map_of_exists_le_sInf_empty {l : List ι} (f : ι → α)
(h : ∃ x ∈ l, f x ≤ sInf ∅) :
⨅ x ∈ l, f x ∈ l.map f := by
classical
simpa using l.toFinset.ciInf_mem_image f (by simpa using h)
lemma Multiset.iSup_mem_map_of_exists_sSup_empty_le {s : Multiset ι} (f : ι → α)
(h : ∃ x ∈ s, sSup ∅ ≤ f x) :
⨆ x ∈ s, f x ∈ s.map f := by
classical
simpa using s.toFinset.ciSup_mem_image f (by simpa using h)
lemma Multiset.iInf_mem_map_of_exists_le_sInf_empty {s : Multiset ι} (f : ι → α)
(h : ∃ x ∈ s, f x ≤ sInf ∅) :
⨅ x ∈ s, f x ∈ s.map f := by
classical
simpa using s.toFinset.ciInf_mem_image f (by simpa using h)
theorem exists_eq_ciSup_of_finite [Nonempty ι] [Finite ι] {f : ι → α} : ∃ i, f i = ⨆ i, f i :=
Nonempty.csSup_mem (range_nonempty f) (finite_range f)
theorem exists_eq_ciInf_of_finite [Nonempty ι] [Finite ι] {f : ι → α} : ∃ i, f i = ⨅ i, f i :=
Nonempty.csInf_mem (range_nonempty f) (finite_range f)
end ListMultiset
end ConditionallyCompleteLinearOrder
namespace Finite
variable [Finite ι] [ConditionallyCompleteLattice α] (f : ι → α)
lemma le_ciSup (i : ι) : f i ≤ ⨆ j, f j := by
suffices BddAbove (range f) from _root_.le_ciSup this i
let : Fintype ι := Fintype.ofFinite ι
use Finset.sup' Finset.univ ⟨i, Finset.mem_univ i⟩ f
simp only [mem_upperBounds, mem_range, forall_exists_index, forall_apply_eq_imp_iff]
exact fun j ↦ Finset.le_sup' f <| Finset.mem_univ j
lemma ciInf_le (i : ι) : ⨅ j, f j ≤ f i :=
le_ciSup (α := αᵒᵈ) f i
end Finite
/-!
### Relation between `sSup` / `sInf` and `Finset.sup'` / `Finset.inf'`
Like the `Sup` of a `ConditionallyCompleteLattice`, `Finset.sup'` also requires the set to be
non-empty. As a result, we can translate between the two.
-/
namespace Finset
section ConditionallyCompleteLattice
variable [ConditionallyCompleteLattice α]
theorem sup'_eq_csSup_image (s : Finset ι) (H : s.Nonempty) (f : ι → α) :
s.sup' H f = sSup (f '' s) :=
eq_of_forall_ge_iff fun a => by
simp [csSup_le_iff (s.finite_toSet.image f).bddAbove (H.to_set.image f)]
theorem inf'_eq_csInf_image (s : Finset ι) (H : s.Nonempty) (f : ι → α) :
s.inf' H f = sInf (f '' s) :=
sup'_eq_csSup_image (α := αᵒᵈ) _ H _
theorem sup'_id_eq_csSup (s : Finset α) (hs) : s.sup' hs id = sSup s := by
rw [sup'_eq_csSup_image s hs, Set.image_id]
theorem inf'_id_eq_csInf (s : Finset α) (hs) : s.inf' hs id = sInf s :=
sup'_id_eq_csSup (α := αᵒᵈ) _ hs
variable [Fintype ι] [Nonempty ι]
lemma sup'_univ_eq_ciSup (f : ι → α) : univ.sup' univ_nonempty f = ⨆ i, f i := by
simp [sup'_eq_csSup_image, iSup]
lemma inf'_univ_eq_ciInf (f : ι → α) : univ.inf' univ_nonempty f = ⨅ i, f i := by
simp [inf'_eq_csInf_image, iInf]
end ConditionallyCompleteLattice
section ConditionallyCompleteLinearOrderBot
variable [ConditionallyCompleteLinearOrderBot α]
lemma sup_univ_eq_ciSup [Fintype ι] (f : ι → α) : univ.sup f = ⨆ i, f i :=
le_antisymm
(Finset.sup_le fun _ _ => le_ciSup (finite_range _).bddAbove _)
(ciSup_le' fun _ => Finset.le_sup (mem_univ _))
end ConditionallyCompleteLinearOrderBot
end Finset
section ConditionallyCompleteLinearOrderBot
variable [ConditionallyCompleteLinearOrderBot α] (f : ι → α)
theorem Finset.Nonempty.ciSup_eq_max'_image {s : Finset ι} (h : s.Nonempty)
(h' : (s.image f).Nonempty := h.image f) :
⨆ i ∈ s, f i = (s.image f).max' h' :=
s.ciSup_eq_max'_image _ (h.imp (by simp)) _
theorem Finset.Nonempty.ciSup_mem_image {s : Finset ι} (h : s.Nonempty) :
⨆ i ∈ s, f i ∈ s.image f :=
s.ciSup_mem_image _ (h.imp (by simp))
theorem Set.Nonempty.ciSup_mem_image {s : Set ι} (h : s.Nonempty) (hs : s.Finite) :
⨆ i ∈ s, f i ∈ f '' s :=
hs.ciSup_mem_image _ (h.imp (by simp))
theorem Set.Nonempty.ciSup_lt_iff {s : Set ι} {a : α} {f : ι → α} (h : s.Nonempty) (hs : s.Finite) :
⨆ i ∈ s, f i < a ↔ ∀ x ∈ s, f x < a :=
hs.ciSup_lt_iff (h.imp (by simp))
section ListMultiset
lemma List.iSup_mem_map_of_ne_nil {l : List ι} (f : ι → α) (h : l ≠ []) :
⨆ x ∈ l, f x ∈ l.map f :=
l.iSup_mem_map_of_exists_sSup_empty_le _ (by simpa using exists_mem_of_ne_nil _ h)
lemma Multiset.iSup_mem_map_of_ne_zero {s : Multiset ι} (f : ι → α) (h : s ≠ 0) :
⨆ x ∈ s, f x ∈ s.map f :=
s.iSup_mem_map_of_exists_sSup_empty_le _ (by simpa using exists_mem_of_ne_zero h)
end ListMultiset
end ConditionallyCompleteLinearOrderBot
|
Order.lean
|
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Sigma.Lex
import Mathlib.Util.Notation3
import Mathlib.Data.Sigma.Basic
import Mathlib.Order.Lattice
import Mathlib.Order.BoundedOrder.Basic
/-!
# Orders on a sigma type
This file defines two orders on a sigma type:
* The disjoint sum of orders. `a` is less `b` iff `a` and `b` are in the same summand and `a` is
less than `b` there.
* The lexicographical order. `a` is less than `b` if its summand is strictly less than the summand
of `b` or they are in the same summand and `a` is less than `b` there.
We make the disjoint sum of orders the default set of instances. The lexicographic order goes on a
type synonym.
## Notation
* `_root_.Lex (Sigma α)`: Sigma type equipped with the lexicographic order.
Type synonym of `Σ i, α i`.
## See also
Related files are:
* `Data.Finset.CoLex`: Colexicographic order on finite sets.
* `Data.List.Lex`: Lexicographic order on lists.
* `Data.Pi.Lex`: Lexicographic order on `Πₗ i, α i`.
* `Data.PSigma.Order`: Lexicographic order on `Σₗ' i, α i`. Basically a twin of this file.
* `Data.Prod.Lex`: Lexicographic order on `α × β`.
## TODO
Upgrade `Equiv.sigma_congr_left`, `Equiv.sigma_congr`, `Equiv.sigma_assoc`,
`Equiv.sigma_prod_of_equiv`, `Equiv.sigma_equiv_prod`, ... to order isomorphisms.
-/
namespace Sigma
variable {ι : Type*} {α : ι → Type*}
/-! ### Disjoint sum of orders on `Sigma` -/
/-- Disjoint sum of orders. `⟨i, a⟩ ≤ ⟨j, b⟩` iff `i = j` and `a ≤ b`. -/
protected inductive LE [∀ i, LE (α i)] : ∀ _a _b : Σ i, α i, Prop
| fiber (i : ι) (a b : α i) : a ≤ b → Sigma.LE ⟨i, a⟩ ⟨i, b⟩
/-- Disjoint sum of orders. `⟨i, a⟩ < ⟨j, b⟩` iff `i = j` and `a < b`. -/
protected inductive LT [∀ i, LT (α i)] : ∀ _a _b : Σ i, α i, Prop
| fiber (i : ι) (a b : α i) : a < b → Sigma.LT ⟨i, a⟩ ⟨i, b⟩
protected instance [∀ i, LE (α i)] : LE (Σ i, α i) where
le := Sigma.LE
protected instance [∀ i, LT (α i)] : LT (Σ i, α i) where
lt := Sigma.LT
@[simp]
theorem mk_le_mk_iff [∀ i, LE (α i)] {i : ι} {a b : α i} : (⟨i, a⟩ : Sigma α) ≤ ⟨i, b⟩ ↔ a ≤ b :=
⟨fun ⟨_, _, _, h⟩ => h, Sigma.LE.fiber _ _ _⟩
@[simp]
theorem mk_lt_mk_iff [∀ i, LT (α i)] {i : ι} {a b : α i} : (⟨i, a⟩ : Sigma α) < ⟨i, b⟩ ↔ a < b :=
⟨fun ⟨_, _, _, h⟩ => h, Sigma.LT.fiber _ _ _⟩
theorem le_def [∀ i, LE (α i)] {a b : Σ i, α i} : a ≤ b ↔ ∃ h : a.1 = b.1, h.rec a.2 ≤ b.2 := by
constructor
· rintro ⟨i, a, b, h⟩
exact ⟨rfl, h⟩
· obtain ⟨i, a⟩ := a
obtain ⟨j, b⟩ := b
rintro ⟨rfl : i = j, h⟩
exact LE.fiber _ _ _ h
theorem lt_def [∀ i, LT (α i)] {a b : Σ i, α i} : a < b ↔ ∃ h : a.1 = b.1, h.rec a.2 < b.2 := by
constructor
· rintro ⟨i, a, b, h⟩
exact ⟨rfl, h⟩
· obtain ⟨i, a⟩ := a
obtain ⟨j, b⟩ := b
rintro ⟨rfl : i = j, h⟩
exact LT.fiber _ _ _ h
protected instance preorder [∀ i, Preorder (α i)] : Preorder (Σ i, α i) :=
{ le_refl := fun ⟨i, a⟩ => Sigma.LE.fiber i a a le_rfl,
le_trans := by
rintro _ _ _ ⟨i, a, b, hab⟩ ⟨_, _, c, hbc⟩
exact LE.fiber i a c (hab.trans hbc),
lt_iff_le_not_ge := fun _ _ => by
constructor
· rintro ⟨i, a, b, hab⟩
rwa [mk_le_mk_iff, mk_le_mk_iff, ← lt_iff_le_not_ge]
· rintro ⟨⟨i, a, b, hab⟩, h⟩
rw [mk_le_mk_iff] at h
exact mk_lt_mk_iff.2 (hab.lt_of_not_ge h) }
instance [∀ i, PartialOrder (α i)] : PartialOrder (Σ i, α i) :=
{ Sigma.preorder with
le_antisymm := by
rintro _ _ ⟨i, a, b, hab⟩ ⟨_, _, _, hba⟩
exact congr_arg (Sigma.mk _ ·) <| hab.antisymm hba }
instance [∀ i, Preorder (α i)] [∀ i, DenselyOrdered (α i)] : DenselyOrdered (Σ i, α i) where
dense := by
rintro ⟨i, a⟩ ⟨_, _⟩ ⟨_, _, b, h⟩
obtain ⟨c, ha, hb⟩ := exists_between h
exact ⟨⟨i, c⟩, LT.fiber i a c ha, LT.fiber i c b hb⟩
/-! ### Lexicographical order on `Sigma` -/
namespace Lex
/-- The notation `Σₗ i, α i` refers to a sigma type equipped with the lexicographic order. -/
notation3 "Σₗ "(...)", "r:(scoped p => _root_.Lex (Sigma p)) => r
/-- The lexicographical `≤` on a sigma type. -/
protected instance LE [LT ι] [∀ i, LE (α i)] : LE (Σₗ i, α i) where
le := Lex (· < ·) fun _ => (· ≤ ·)
/-- The lexicographical `<` on a sigma type. -/
protected instance LT [LT ι] [∀ i, LT (α i)] : LT (Σₗ i, α i) where
lt := Lex (· < ·) fun _ => (· < ·)
theorem le_def [LT ι] [∀ i, LE (α i)] {a b : Σₗ i, α i} :
a ≤ b ↔ a.1 < b.1 ∨ ∃ h : a.1 = b.1, h.rec a.2 ≤ b.2 :=
Sigma.lex_iff
theorem lt_def [LT ι] [∀ i, LT (α i)] {a b : Σₗ i, α i} :
a < b ↔ a.1 < b.1 ∨ ∃ h : a.1 = b.1, h.rec a.2 < b.2 :=
Sigma.lex_iff
/-- The lexicographical preorder on a sigma type. -/
instance preorder [Preorder ι] [∀ i, Preorder (α i)] : Preorder (Σₗ i, α i) :=
{ Sigma.Lex.LE, Sigma.Lex.LT with
le_refl := fun ⟨_, a⟩ => Lex.right a a le_rfl,
le_trans := fun _ _ _ => trans_of ((Lex (· < ·)) fun _ => (· ≤ ·)),
lt_iff_le_not_ge := by
refine fun a b => ⟨fun hab => ⟨hab.mono_right fun i a b => le_of_lt, ?_⟩, ?_⟩
· rintro (⟨b, a, hji⟩ | ⟨b, a, hba⟩) <;> obtain ⟨_, _, hij⟩ | ⟨_, _, hab⟩ := hab
· exact hij.not_gt hji
· exact lt_irrefl _ hji
· exact lt_irrefl _ hij
· exact hab.not_ge hba
· rintro ⟨⟨a, b, hij⟩ | ⟨a, b, hab⟩, hba⟩
· exact Sigma.Lex.left _ _ hij
· exact Sigma.Lex.right _ _ (hab.lt_of_not_ge fun h => hba <| Sigma.Lex.right _ _ h) }
/-- The lexicographical partial order on a sigma type. -/
instance partialOrder [Preorder ι] [∀ i, PartialOrder (α i)] :
PartialOrder (Σₗ i, α i) :=
{ Lex.preorder with
le_antisymm := fun _ _ => antisymm_of ((Lex (· < ·)) fun _ => (· ≤ ·)) }
/-- The lexicographical linear order on a sigma type. -/
instance linearOrder [LinearOrder ι] [∀ i, LinearOrder (α i)] :
LinearOrder (Σₗ i, α i) :=
{ Lex.partialOrder with
le_total := total_of ((Lex (· < ·)) fun _ => (· ≤ ·)),
toDecidableEq := Sigma.instDecidableEqSigma
toDecidableLE := Lex.decidable _ _
toDecidableLT := Lex.decidable _ _ }
/-- The lexicographical linear order on a sigma type. -/
instance orderBot [PartialOrder ι] [OrderBot ι] [∀ i, Preorder (α i)] [OrderBot (α ⊥)] :
OrderBot (Σₗ i, α i) where
bot := ⟨⊥, ⊥⟩
bot_le := fun ⟨a, b⟩ => by
obtain rfl | ha := eq_bot_or_bot_lt a
· exact Lex.right _ _ bot_le
· exact Lex.left _ _ ha
/-- The lexicographical linear order on a sigma type. -/
instance orderTop [PartialOrder ι] [OrderTop ι] [∀ i, Preorder (α i)] [OrderTop (α ⊤)] :
OrderTop (Σₗ i, α i) where
top := ⟨⊤, ⊤⟩
le_top := fun ⟨a, b⟩ => by
obtain rfl | ha := eq_top_or_lt_top a
· exact Lex.right _ _ le_top
· exact Lex.left _ _ ha
/-- The lexicographical linear order on a sigma type. -/
instance boundedOrder [PartialOrder ι] [BoundedOrder ι] [∀ i, Preorder (α i)] [OrderBot (α ⊥)]
[OrderTop (α ⊤)] : BoundedOrder (Σₗ i, α i) :=
{ Lex.orderBot, Lex.orderTop with }
instance denselyOrdered [Preorder ι] [DenselyOrdered ι] [∀ i, Nonempty (α i)] [∀ i, Preorder (α i)]
[∀ i, DenselyOrdered (α i)] : DenselyOrdered (Σₗ i, α i) where
dense := by
rintro ⟨i, a⟩ ⟨j, b⟩ (⟨_, _, h⟩ | ⟨_, b, h⟩)
· obtain ⟨k, hi, hj⟩ := exists_between h
obtain ⟨c⟩ : Nonempty (α k) := inferInstance
exact ⟨⟨k, c⟩, left _ _ hi, left _ _ hj⟩
· obtain ⟨c, ha, hb⟩ := exists_between h
exact ⟨⟨i, c⟩, right _ _ ha, right _ _ hb⟩
instance denselyOrdered_of_noMaxOrder [Preorder ι] [∀ i, Preorder (α i)]
[∀ i, DenselyOrdered (α i)] [∀ i, NoMaxOrder (α i)] :
DenselyOrdered (Σₗ i, α i) where
dense := by
rintro ⟨i, a⟩ ⟨j, b⟩ (⟨_, _, h⟩ | ⟨_, b, h⟩)
· obtain ⟨c, ha⟩ := exists_gt a
exact ⟨⟨i, c⟩, right _ _ ha, left _ _ h⟩
· obtain ⟨c, ha, hb⟩ := exists_between h
exact ⟨⟨i, c⟩, right _ _ ha, right _ _ hb⟩
instance denselyOrdered_of_noMinOrder [Preorder ι] [∀ i, Preorder (α i)]
[∀ i, DenselyOrdered (α i)] [∀ i, NoMinOrder (α i)] :
DenselyOrdered (Σₗ i, α i) where
dense := by
rintro ⟨i, a⟩ ⟨j, b⟩ (⟨_, _, h⟩ | ⟨_, b, h⟩)
· obtain ⟨c, hb⟩ := exists_lt b
exact ⟨⟨j, c⟩, left _ _ h, right _ _ hb⟩
· obtain ⟨c, ha, hb⟩ := exists_between h
exact ⟨⟨i, c⟩, right _ _ ha, right _ _ hb⟩
instance noMaxOrder_of_nonempty [Preorder ι] [∀ i, Preorder (α i)] [NoMaxOrder ι]
[∀ i, Nonempty (α i)] : NoMaxOrder (Σₗ i, α i) where
exists_gt := by
rintro ⟨i, a⟩
obtain ⟨j, h⟩ := exists_gt i
obtain ⟨b⟩ : Nonempty (α j) := inferInstance
exact ⟨⟨j, b⟩, left _ _ h⟩
instance noMinOrder_of_nonempty [Preorder ι] [∀ i, Preorder (α i)] [NoMinOrder ι]
[∀ i, Nonempty (α i)] : NoMinOrder (Σₗ i, α i) where
exists_lt := by
rintro ⟨i, a⟩
obtain ⟨j, h⟩ := exists_lt i
obtain ⟨b⟩ : Nonempty (α j) := inferInstance
exact ⟨⟨j, b⟩, left _ _ h⟩
instance noMaxOrder [Preorder ι] [∀ i, Preorder (α i)] [∀ i, NoMaxOrder (α i)] :
NoMaxOrder (Σₗ i, α i) where
exists_gt := by
rintro ⟨i, a⟩
obtain ⟨b, h⟩ := exists_gt a
exact ⟨⟨i, b⟩, right _ _ h⟩
instance noMinOrder [Preorder ι] [∀ i, Preorder (α i)] [∀ i, NoMinOrder (α i)] :
NoMinOrder (Σₗ i, α i) where
exists_lt := by
rintro ⟨i, a⟩
obtain ⟨b, h⟩ := exists_lt a
exact ⟨⟨i, b⟩, right _ _ h⟩
end Lex
end Sigma
|
Comp.lean
|
/-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Yuyang Zhao
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Comp
import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars
/-!
# One-dimensional derivatives of compositions of functions
In this file we prove the chain rule for the following cases:
* `HasDerivAt.comp` etc: `f : 𝕜' → 𝕜'` composed with `g : 𝕜 → 𝕜'`;
* `HasDerivAt.scomp` etc: `f : 𝕜' → E` composed with `g : 𝕜 → 𝕜'`;
* `HasFDerivAt.comp_hasDerivAt` etc: `f : E → F` composed with `g : 𝕜 → E`;
Here `𝕜` is the base normed field, `E` and `F` are normed spaces over `𝕜` and `𝕜'` is an algebra
over `𝕜` (e.g., `𝕜'=𝕜` or `𝕜=ℝ`, `𝕜'=ℂ`).
We also give versions with the `of_eq` suffix, which require an equality proof instead
of definitional equality of the different points used in the composition. These versions are
often more flexible to use.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## Keywords
derivative, chain rule
-/
universe u v w
open scoped Topology Filter ENNReal
open Filter Asymptotics Set
open ContinuousLinearMap (smulRight smulRight_one_eq_iff)
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {f : 𝕜 → F}
variable {f' : F}
variable {x : 𝕜}
variable {s : Set 𝕜}
variable {L : Filter 𝕜}
section Composition
/-!
### Derivative of the composition of a vector function and a scalar function
We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp`
in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also
because the `comp` version with the shorter name will show up much more often in applications).
The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to
usual multiplication in `comp` lemmas.
-/
/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F]
[IsScalarTower 𝕜 𝕜' F] {s' t' : Set 𝕜'} {h : 𝕜 → 𝕜'} {h₂ : 𝕜' → 𝕜'} {h' h₂' : 𝕜'}
{g₁ : 𝕜' → F} {g₁' : F} {L' : Filter 𝕜'} {y : 𝕜'} (x)
theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
simpa using ((hg.restrictScalars 𝕜).comp x hh hL).hasDerivAtFilter
theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L')
(hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') :
HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by
rw [hy] at hg; exact hg.scomp x hh hL
theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x))
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh <| tendsto_inf.2 ⟨hh.continuousAt, tendsto_principal.2 <| Eventually.of_forall hs⟩
theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y)
(hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs
nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x))
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y)
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp x hh hst
/-- The chain rule. -/
nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x :=
hg.scomp x hh hh.continuousAt
/-- The chain rule. -/
theorem HasDerivAt.scomp_of_eq
(hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) :
HasDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
simpa using ((hg.restrictScalars 𝕜).comp x hh).hasStrictDerivAt
theorem HasStrictDerivAt.scomp_of_eq
(hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) :
HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by
rw [hy] at hg; exact hg.scomp x hh
theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x))
(hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x :=
HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _)
theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y)
(hh : HasDerivWithinAt h h' s x) (hy : y = h x) :
HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by
rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh
theorem derivWithin.scomp (hg : DifferentiableWithinAt 𝕜' g₁ t' (h x))
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt 𝕜' g₁ t' y)
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t')
(hy : y = h x) :
derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by
rw [hy] at hg; exact derivWithin.scomp x hg hh hs
theorem deriv.scomp (hg : DifferentiableAt 𝕜' g₁ (h x)) (hh : DifferentiableAt 𝕜 h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) :=
(HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv
theorem deriv.scomp_of_eq
(hg : DifferentiableAt 𝕜' g₁ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) :
deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := by
rw [hy] at hg; exact deriv.scomp x hg hh
/-! ### Derivative of the composition of a scalar and vector functions -/
theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' (f x) L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
convert (hh₂.restrictScalars 𝕜).comp x hf hL
ext x
simp [mul_comm]
theorem HasDerivAtFilter.comp_hasFDerivAtFilter_of_eq
{f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E}
(hh₂ : HasDerivAtFilter h₂ h₂' y L') (hf : HasFDerivAtFilter f f' x L'')
(hL : Tendsto f L'' L') (hy : y = f x) : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by
rw [hy] at hh₂; exact hh₂.comp_hasFDerivAtFilter x hf hL
theorem HasStrictDerivAt.comp_hasStrictFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' (f x)) (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [HasStrictDerivAt] at hh
convert (hh.restrictScalars 𝕜).comp x hf
ext x
simp [mul_comm]
theorem HasStrictDerivAt.comp_hasStrictFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasStrictDerivAt h₂ h₂' y) (hf : HasStrictFDerivAt f f' x) (hy : y = f x) :
HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasStrictFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousAt
theorem HasDerivAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivAt f f' x) (hy : y = f x) :
HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by
rw [hy] at hh; exact hh.comp_hasFDerivAt x hf
theorem HasDerivAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf hf.continuousWithinAt
theorem HasDerivAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x)
(hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivWithinAt f f' s x) (hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf
theorem HasDerivWithinAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x :=
hh.comp_hasFDerivAtFilter x hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst
theorem HasDerivWithinAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x)
(hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t)
(hy : y = f x) :
HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by
rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf hst
theorem HasDerivWithinAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {t} (x)
(hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivAt f f' x) (ht : ∀ᶠ x' in 𝓝 x, f x' ∈ t) :
HasFDerivAt (h₂ ∘ f) (h₂' • f') x :=
hh.comp_hasFDerivAtFilter x hf <| tendsto_nhdsWithin_iff.mpr ⟨hf.continuousAt, ht⟩
theorem HasDerivWithinAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {t} (x)
(hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivAt f f' x) (ht : ∀ᶠ x' in 𝓝 x, f x' ∈ t)
(hy : y = f x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by
subst y; exact hh.comp_hasFDerivAt x hf ht
/-! ### Derivative of the composition of two scalar functions -/
theorem HasDerivAtFilter.comp (hh₂ : HasDerivAtFilter h₂ h₂' (h x) L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [mul_comm]
exact hh₂.scomp x hh hL
theorem HasDerivAtFilter.comp_of_eq (hh₂ : HasDerivAtFilter h₂ h₂' y L')
(hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') (hy : y = h x) :
HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by
rw [hy] at hh₂; exact hh₂.comp x hh hL
theorem HasDerivWithinAt.comp (hh₂ : HasDerivWithinAt h₂ h₂' s' (h x))
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [mul_comm]
exact hh₂.scomp x hh hst
theorem HasDerivWithinAt.comp_of_eq (hh₂ : HasDerivWithinAt h₂ h₂' s' y)
(hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') (hy : y = h x) :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [hy] at hh₂; exact hh₂.comp x hh hst
/-- The chain rule.
Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule
with `h₂` taking values in a vector space, use `HasDerivAt.scomp`. -/
nonrec theorem HasDerivAt.comp (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivAt h h' x) :
HasDerivAt (h₂ ∘ h) (h₂' * h') x :=
hh₂.comp x hh hh.continuousAt
/-- The chain rule.
Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule
with `h₂` taking values in a vector space, use `HasDerivAt.scomp_of_eq`. -/
theorem HasDerivAt.comp_of_eq
(hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivAt h h' x) (hy : y = h x) :
HasDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [hy] at hh₂; exact hh₂.comp x hh
theorem HasStrictDerivAt.comp (hh₂ : HasStrictDerivAt h₂ h₂' (h x)) (hh : HasStrictDerivAt h h' x) :
HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [mul_comm]
exact hh₂.scomp x hh
theorem HasStrictDerivAt.comp_of_eq
(hh₂ : HasStrictDerivAt h₂ h₂' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) :
HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by
rw [hy] at hh₂; exact hh₂.comp x hh
theorem HasDerivAt.comp_hasDerivWithinAt (hh₂ : HasDerivAt h₂ h₂' (h x))
(hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x :=
hh₂.hasDerivWithinAt.comp x hh (mapsTo_univ _ _)
theorem HasDerivAt.comp_hasDerivWithinAt_of_eq (hh₂ : HasDerivAt h₂ h₂' y)
(hh : HasDerivWithinAt h h' s x) (hy : y = h x) :
HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by
rw [hy] at hh₂; exact hh₂.comp_hasDerivWithinAt x hh
theorem HasDerivWithinAt.comp_hasDerivAt {t} (hh₂ : HasDerivWithinAt h₂ h₂' t (h x))
(hh : HasDerivAt h h' x) (ht : ∀ᶠ x' in 𝓝 x, h x' ∈ t) : HasDerivAt (h₂ ∘ h) (h₂' * h') x :=
HasDerivAtFilter.comp x hh₂ hh <| tendsto_nhdsWithin_iff.mpr ⟨hh.continuousAt, ht⟩
theorem HasDerivWithinAt.comp_hasDerivAt_of_eq {t} (hh₂ : HasDerivWithinAt h₂ h₂' t y)
(hh : HasDerivAt h h' x) (ht : ∀ᶠ x' in 𝓝 x, h x' ∈ t) (hy : y = h x) :
HasDerivAt (h₂ ∘ h) (h₂' * h') x := by
subst y; exact hh₂.comp_hasDerivAt x hh ht
theorem derivWithin_comp (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' (h x))
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') :
derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (hh₂.hasDerivWithinAt.comp x hh.hasDerivWithinAt hs).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
theorem derivWithin_comp_of_eq (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' y)
(hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s')
(hy : h x = y) :
derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by
subst hy; exact derivWithin_comp x hh₂ hh hs
theorem deriv_comp (hh₂ : DifferentiableAt 𝕜' h₂ (h x)) (hh : DifferentiableAt 𝕜 h x) :
deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x :=
(hh₂.hasDerivAt.comp x hh.hasDerivAt).deriv
theorem deriv_comp_of_eq (hh₂ : DifferentiableAt 𝕜' h₂ y) (hh : DifferentiableAt 𝕜 h x)
(hy : h x = y) :
deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := by
subst hy; exact deriv_comp x hh₂ hh
protected nonrec theorem HasDerivAtFilter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : HasDerivAtFilter f f' x L) (hL : Tendsto f L L) (hx : f x = x) (n : ℕ) :
HasDerivAtFilter f^[n] (f' ^ n) x L := by
have := hf.iterate hL hx n
rwa [ContinuousLinearMap.smulRight_one_pow] at this
protected nonrec theorem HasDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAt f f' x)
(hx : f x = x) (n : ℕ) : HasDerivAt f^[n] (f' ^ n) x :=
hf.iterate _ (have := hf.tendsto_nhds le_rfl; by rwa [hx] at this) hx n
protected theorem HasDerivWithinAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivWithinAt f f' s x)
(hx : f x = x) (hs : MapsTo f s s) (n : ℕ) : HasDerivWithinAt f^[n] (f' ^ n) s x := by
have := HasFDerivWithinAt.iterate hf hx hs n
rwa [ContinuousLinearMap.smulRight_one_pow] at this
protected nonrec theorem HasStrictDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜}
(hf : HasStrictDerivAt f f' x) (hx : f x = x) (n : ℕ) :
HasStrictDerivAt f^[n] (f' ^ n) x := by
have := hf.iterate hx n
rwa [ContinuousLinearMap.smulRight_one_pow] at this
end Composition
section CompositionVector
/-! ### Derivative of the composition of a function between vector spaces and a function on `𝕜` -/
open ContinuousLinearMap
variable {l : F → E} {l' : F →L[𝕜] E} {y : F}
variable (x)
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set
equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem HasFDerivWithinAt.comp_hasDerivWithinAt {t : Set F} (hl : HasFDerivWithinAt l l' t (f x))
(hf : HasDerivWithinAt f f' s x) (hst : MapsTo f s t) :
HasDerivWithinAt (l ∘ f) (l' f') s x := by
simpa only [one_apply, one_smul, smulRight_apply, coe_comp', (· ∘ ·)] using
(hl.comp x hf.hasFDerivWithinAt hst).hasDerivWithinAt
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set
equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem HasFDerivWithinAt.comp_hasDerivWithinAt_of_eq {t : Set F}
(hl : HasFDerivWithinAt l l' t y)
(hf : HasDerivWithinAt f f' s x) (hst : MapsTo f s t) (hy : y = f x) :
HasDerivWithinAt (l ∘ f) (l' f') s x := by
rw [hy] at hl; exact hl.comp_hasDerivWithinAt x hf hst
theorem HasFDerivWithinAt.comp_hasDerivAt {t : Set F} (hl : HasFDerivWithinAt l l' t (f x))
(hf : HasDerivAt f f' x) (ht : ∀ᶠ x' in 𝓝 x, f x' ∈ t) : HasDerivAt (l ∘ f) (l' f') x := by
simpa only [one_apply, one_smul, smulRight_apply, coe_comp', (· ∘ ·)] using
(hl.comp_hasFDerivAt x hf.hasFDerivAt ht).hasDerivAt
theorem HasFDerivWithinAt.comp_hasDerivAt_of_eq {t : Set F} (hl : HasFDerivWithinAt l l' t y)
(hf : HasDerivAt f f' x) (ht : ∀ᶠ x' in 𝓝 x, f x' ∈ t) (hy : y = f x) :
HasDerivAt (l ∘ f) (l' f') x := by
subst y; exact hl.comp_hasDerivAt x hf ht
theorem HasFDerivAt.comp_hasDerivWithinAt (hl : HasFDerivAt l l' (f x))
(hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (l ∘ f) (l' f') s x :=
hl.hasFDerivWithinAt.comp_hasDerivWithinAt x hf (mapsTo_univ _ _)
theorem HasFDerivAt.comp_hasDerivWithinAt_of_eq (hl : HasFDerivAt l l' y)
(hf : HasDerivWithinAt f f' s x) (hy : y = f x) :
HasDerivWithinAt (l ∘ f) (l' f') s x := by
rw [hy] at hl; exact hl.comp_hasDerivWithinAt x hf
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the
Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem HasFDerivAt.comp_hasDerivAt (hl : HasFDerivAt l l' (f x)) (hf : HasDerivAt f f' x) :
HasDerivAt (l ∘ f) (l' f') x :=
hasDerivWithinAt_univ.mp <| hl.comp_hasDerivWithinAt x hf.hasDerivWithinAt
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the
Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem HasFDerivAt.comp_hasDerivAt_of_eq
(hl : HasFDerivAt l l' y) (hf : HasDerivAt f f' x) (hy : y = f x) :
HasDerivAt (l ∘ f) (l' f') x := by
rw [hy] at hl; exact hl.comp_hasDerivAt x hf
theorem HasStrictFDerivAt.comp_hasStrictDerivAt (hl : HasStrictFDerivAt l l' (f x))
(hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (l ∘ f) (l' f') x := by
simpa only [one_apply, one_smul, smulRight_apply, coe_comp', (· ∘ ·)] using
(hl.comp x hf.hasStrictFDerivAt).hasStrictDerivAt
theorem HasStrictFDerivAt.comp_hasStrictDerivAt_of_eq (hl : HasStrictFDerivAt l l' y)
(hf : HasStrictDerivAt f f' x) (hy : y = f x) :
HasStrictDerivAt (l ∘ f) (l' f') x := by
rw [hy] at hl; exact hl.comp_hasStrictDerivAt x hf
theorem fderivWithin_comp_derivWithin {t : Set F} (hl : DifferentiableWithinAt 𝕜 l t (f x))
(hf : DifferentiableWithinAt 𝕜 f s x) (hs : MapsTo f s t) :
derivWithin (l ∘ f) s x = (fderivWithin 𝕜 l t (f x) : F → E) (derivWithin f s x) := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (hl.hasFDerivWithinAt.comp_hasDerivWithinAt x hf.hasDerivWithinAt hs).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
theorem fderivWithin_comp_derivWithin_of_eq {t : Set F} (hl : DifferentiableWithinAt 𝕜 l t y)
(hf : DifferentiableWithinAt 𝕜 f s x) (hs : MapsTo f s t) (hy : y = f x) :
derivWithin (l ∘ f) s x = (fderivWithin 𝕜 l t (f x) : F → E) (derivWithin f s x) := by
rw [hy] at hl; exact fderivWithin_comp_derivWithin x hl hf hs
theorem fderiv_comp_deriv (hl : DifferentiableAt 𝕜 l (f x)) (hf : DifferentiableAt 𝕜 f x) :
deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) :=
(hl.hasFDerivAt.comp_hasDerivAt x hf.hasDerivAt).deriv
theorem fderiv_comp_deriv_of_eq (hl : DifferentiableAt 𝕜 l y) (hf : DifferentiableAt 𝕜 f x)
(hy : y = f x) :
deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) := by
rw [hy] at hl; exact fderiv_comp_deriv x hl hf
end CompositionVector
|
finfun.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 tuple.
(******************************************************************************)
(* This file implements a type for functions with a finite domain: *)
(* {ffun aT -> rT} where aT should have a finType structure, *)
(* {ffun forall x : aT, rT} for dependent functions over a finType aT, *)
(* and {ffun funT} where funT expands to a product over a finType. *)
(* Any eqType, choiceType, countType and finType structures on rT extend to *)
(* {ffun aT -> rT} as Leibnitz equality and extensional equalities coincide. *)
(* (T ^ n)%type is notation for {ffun 'I_n -> T}, which is isomorphic *)
(* to n.-tuple T, but is structurally positive and thus can be used to *)
(* define inductive types, e.g., Inductive tree := node n of tree ^ n (see *)
(* mid-file for an expanded example). *)
(* --> More generally, {ffun fT} is always structurally positive. *)
(* {ffun fT} inherits combinatorial structures of rT, i.e., eqType, *)
(* choiceType, countType, and finType. However, due to some limitations of *)
(* the Coq 8.9 unification code the structures are only inherited in the *)
(* NON dependent case, when rT does not depend on x. *)
(* For f : {ffun fT} with fT := forall x : aT, rT we define *)
(* f x == the image of x under f (f coerces to a CiC function) *)
(* --> The coercion is structurally decreasing, e.g., Coq will accept *)
(* Fixpoint size t := let: node n f := t in sumn (codom (size \o f)) + 1. *)
(* as structurally decreasing on t of the inductive tree type above. *)
(* {dffun fT} == alias for {ffun fT} that inherits combinatorial *)
(* structures on rT, when rT DOES depend on x. *)
(* total_fun g == the function induced by a dependent function g of type *)
(* forall x, rT on the total space {x : aT & rT}. *)
(* := fun x => Tagged (fun x => rT) (g x). *)
(* tfgraph f == the total function graph of f, i.e., the #|aT|.-tuple *)
(* of all the (dependent pair) values of total_fun f. *)
(* finfun g == the f extensionally equal to g, and the RECOMMENDED *)
(* interface for building elements of {ffun fT}. *)
(* [ffun x : aT => E] := finfun (fun x : aT => E). *)
(* There should be an explicit type constraint on E if *)
(* type does not depend on x, due to the Coq unification *)
(* limitations referred to above. *)
(* ffun0 aT0 == the trivial finfun, from a proof aT0 that #|aT| = 0. *)
(* f \in family F == f belongs to the family F (f x \in F x for all x) *)
(* There are additional operations for non-dependent finite functions, *)
(* i.e., f in {ffun aT -> rT}. *)
(* [ffun x => E] := finfun (fun x => E). *)
(* The type of E must not depend on x; this restriction *)
(* is a mitigation of the aforementioned Coq unification *)
(* limitations. *)
(* [ffun=> E] := [ffun _ => E] (E should not have a dependent type). *)
(* fgraph f == the function graph of f, i.e., the #|aT|.-tuple *)
(* listing the values of f x, for x ranging over enum aT. *)
(* Finfun G == the finfun f whose (simple) function graph is G. *)
(* f \in ffun_on R == the range of f is a subset of R. *)
(* y.-support f == the y-support of f, i.e., [pred x | f x != y]. *)
(* Thus, y.-support f \subset D means f has y-support D. *)
(* We will put Notation support := 0.-support in ssralg. *)
(* f \in pffun_on y D R == f is a y-partial function from D to R: *)
(* f has y-support D and f x \in R for all x \in D. *)
(* f \in pfamily y D F == f belongs to the y-partial family from D to F: *)
(* f has y-support D and f x \in F x for all x \in D. *)
(* fprod I T_ == alternative construct to {ffun forall i : I, T_ i} for *)
(* the finite product of finTypes, in a set-theoretic way *)
(* := Record fprod I T_ := FProd *)
(* { fprod_fun : {ffun I -> {i : I & T_ i}} ; *)
(* fprod_prop : [forall i : I, tag (fprod_fun i) == i] }. *)
(* fprod I T_ is endowed with a finType structure and allow these operations: *)
(* [fprod i : I => F] == the dependent fprod function built from fun i:I => F *)
(* := fprod_of_fun (fun i : I => F) *)
(* [fprod : I => F] == [fprod _ : I => F] *)
(* [fprod i => F] == [fprod i : _ => F] *)
(* [fprod => F] == [fprod _ : _ => F] *)
(* These fprod terms coerce into vanilla dependent functions via the coercion *)
(* fun_of_fprod I T_ : fprod I T_ -> (forall i : I, T_ i). *)
(* We also define the mutual bijections: *)
(* fprod_of_dffun : {dffun forall i : I, T_ i} -> fprod I T_ *)
(* dffun_of_fprod : fprod I T_ -> {dffun forall i : I, T_ i} *)
(* of_family_tagged_with : {x in family (tagged_with T_)} -> fprod I T_ *)
(* to_family_tagged_with : fprod I T_ -> {x in family (tagged_with T_)} *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Section Def.
Variables (aT : finType) (rT : aT -> Type).
Inductive finfun_on : seq aT -> Type :=
| finfun_nil : finfun_on [::]
| finfun_cons x s of rT x & finfun_on s : finfun_on (x :: s).
Local Fixpoint finfun_rec (g : forall x, rT x) s : finfun_on s :=
if s is x1 :: s1 then finfun_cons (g x1) (finfun_rec g s1) else finfun_nil.
Local Fixpoint fun_of_fin_rec x s (f_s : finfun_on s) : x \in s -> rT x :=
if f_s is finfun_cons x1 s1 y1 f_s1 then
if eqP is ReflectT Dx in reflect _ Dxb return Dxb || (x \in s1) -> rT x then
fun=> ecast x (rT x) (esym Dx) y1
else fun_of_fin_rec f_s1
else fun isF => False_rect (rT x) (notF isF).
Variant finfun_of (ph : phant (forall x, rT x)) : predArgType :=
FinfunOf of finfun_on (enum aT).
Definition dfinfun_of ph := finfun_of ph.
Definition fun_of_fin ph (f : finfun_of ph) x :=
let: FinfunOf f_aT := f in fun_of_fin_rec f_aT (mem_enum aT x).
End Def.
Coercion fun_of_fin : finfun_of >-> Funclass.
Identity Coercion unfold_dfinfun_of : dfinfun_of >-> finfun_of.
Arguments fun_of_fin {aT rT ph} f x.
Notation "{ 'ffun' fT }" := (finfun_of (Phant fT))
(format "{ 'ffun' '[hv' fT ']' }") : type_scope.
Notation "{ 'dffun' fT }" := (dfinfun_of (Phant fT))
(format "{ 'dffun' '[hv' fT ']' }") : type_scope.
Definition exp_finIndexType n : finType := 'I_n.
Notation "T ^ n" :=
(@finfun_of (exp_finIndexType n) (fun=> T) (Phant _)) : type_scope.
Local Notation finPi aT rT := (forall x : Finite.sort aT, rT x) (only parsing).
HB.lock Definition finfun aT rT g :=
FinfunOf (Phant (finPi aT rT)) (finfun_rec g (enum aT)).
Canonical finfun_unlock := Unlockable finfun.unlock.
Arguments finfun {aT rT} g.
Notation "[ 'ffun' x : aT => E ]" := (finfun (fun x : aT => E))
(x name) : function_scope.
Notation "[ 'ffun' x => E ]" := (@finfun _ (fun=> _) (fun x => E))
(x name, format "[ 'ffun' x => E ]") : function_scope.
Notation "[ 'ffun' => E ]" := [ffun _ => E]
(format "[ 'ffun' => E ]") : function_scope.
(* Example outcommented.
(* Examples of using finite functions as containers in recursive inductive *)
(* types, and making use of the fact that the type and accessor are *)
(* structurally positive and decreasing, respectively. *)
Unset Elimination Schemes.
Inductive tree := node n of tree ^ n.
Fixpoint size t := let: node n f := t in sumn (codom (size \o f)) + 1.
Example tree_step (K : tree -> Type) :=
forall n st (t := node st) & forall i : 'I_n, K (st i), K t.
Example tree_rect K (Kstep : tree_step K) : forall t, K t.
Proof. by fix IHt 1 => -[n st]; apply/Kstep=> i; apply: IHt. Defined.
(* An artificial example use of dependent functions. *)
Inductive tri_tree n := tri_row of {ffun forall i : 'I_n, tri_tree i}.
Fixpoint tri_size n (t : tri_tree n) :=
let: tri_row f := t in sumn [seq tri_size (f i) | i : 'I_n] + 1.
Example tri_tree_step (K : forall n, tri_tree n -> Type) :=
forall n st (t := tri_row st) & forall i : 'I_n, K i (st i), K n t.
Example tri_tree_rect K (Kstep : tri_tree_step K) : forall n t, K n t.
Proof. by fix IHt 2 => n [st]; apply/Kstep=> i; apply: IHt. Defined.
Set Elimination Schemes.
(* End example. *) *)
(* The correspondence between finfun_of and CiC dependent functions. *)
Section DepPlainTheory.
Variables (aT : finType) (rT : aT -> Type).
Notation fT := {ffun finPi aT rT}.
Implicit Type f : fT.
Fact ffun0 (aT0 : #|aT| = 0) : fT.
Proof. by apply/finfun=> x; have:= card0_eq aT0 x. Qed.
Lemma ffunE g x : (finfun g : fT) x = g x.
Proof.
rewrite unlock /=; set s := enum aT; set s_x : mem_seq s x := mem_enum _ _.
by elim: s s_x => //= x1 s IHs; case: eqP => [|_]; [case: x1 / | apply: IHs].
Qed.
Lemma ffunP (f1 f2 : fT) : (forall x, f1 x = f2 x) <-> f1 = f2.
Proof.
suffices ffunK f g: (forall x, f x = g x) -> f = finfun g.
by split=> [/ffunK|] -> //; apply/esym/ffunK.
case: f => f Dg; rewrite unlock; congr FinfunOf.
have{} Dg x (aTx : mem_seq (enum aT) x): g x = fun_of_fin_rec f aTx.
by rewrite -Dg /= (bool_irrelevance (mem_enum _ _) aTx).
elim: (enum aT) / f (enum_uniq aT) => //= x1 s y f IHf /andP[s'x1 Us] in Dg *.
rewrite Dg ?eqxx //=; case: eqP => // /eq_axiomK-> /= _.
rewrite {}IHf // => x s_x; rewrite Dg ?s_x ?orbT //.
by case: eqP (memPn s'x1 x s_x) => // _ _ /(bool_irrelevance s_x) <-.
Qed.
Lemma ffunK : @cancel (finPi aT rT) fT fun_of_fin finfun.
Proof. by move=> f; apply/ffunP=> x; rewrite ffunE. Qed.
Lemma eq_dffun (g1 g2 : forall x, rT x) :
(forall x, g1 x = g2 x) -> finfun g1 = finfun g2.
Proof. by move=> eq_g; apply/ffunP => x; rewrite !ffunE eq_g. Qed.
Definition total_fun g x := Tagged rT (g x : rT x).
Definition tfgraph f := codom_tuple (total_fun f).
Lemma codom_tffun f : codom (total_fun f) = tfgraph f. Proof. by []. Qed.
Local Definition tfgraph_inv (G : #|aT|.-tuple {x : aT & rT x}) : option fT :=
if eqfunP isn't ReflectT Dtg then None else
Some [ffun x => ecast x (rT x) (Dtg x) (tagged (tnth G (enum_rank x)))].
Local Lemma tfgraphK : pcancel tfgraph tfgraph_inv.
Proof.
move=> f; have Dg x: tnth (tfgraph f) (enum_rank x) = total_fun f x.
by rewrite tnth_map -[tnth _ _]enum_val_nth enum_rankK.
rewrite /tfgraph_inv; case: eqfunP => /= [Dtg | [] x]; last by rewrite Dg.
congr (Some _); apply/ffunP=> x; rewrite ffunE.
by rewrite Dg in (Dx := Dtg x) *; rewrite eq_axiomK.
Qed.
Lemma tfgraph_inj : injective tfgraph. Proof. exact: pcan_inj tfgraphK. Qed.
Definition family_mem mF := [pred f : fT | [forall x, in_mem (f x) (mF x)]].
Variables (pT : forall x, predType (rT x)) (F : forall x, pT x).
(* Helper for defining notation for function families. *)
Local Definition fmem F x := mem (F x : pT x).
Lemma familyP f : reflect (forall x, f x \in F x) (f \in family_mem (fmem F)).
Proof. exact: forallP. Qed.
End DepPlainTheory.
Arguments ffunK {aT rT} f : rename.
Arguments ffun0 {aT rT} aT0.
Arguments eq_dffun {aT rT} [g1] g2 eq_g12.
Arguments total_fun {aT rT} g x.
Arguments tfgraph {aT rT} f.
Arguments tfgraphK {aT rT} f : rename.
Arguments tfgraph_inj {aT rT} [f1 f2] : rename.
Arguments fmem {aT rT pT} F x /.
Arguments familyP {aT rT pT F f}.
Notation family F := (family_mem (fmem F)).
Section InheritedStructures.
Variable aT : finType.
Notation dffun_aT rT rS := {dffun forall x : aT, rT x : rS}.
#[hnf] HB.instance Definition _ rT := Equality.copy (dffun_aT rT eqType)
(pcan_type tfgraphK).
#[hnf] HB.instance Definition _ (rT : eqType) :=
Equality.copy {ffun aT -> rT} {dffun forall _, rT}.
#[hnf] HB.instance Definition _ rT := Choice.copy (dffun_aT rT choiceType)
(pcan_type tfgraphK).
#[hnf] HB.instance Definition _ (rT : choiceType) :=
Choice.copy {ffun aT -> rT} {dffun forall _, rT}.
#[hnf] HB.instance Definition _ rT := Countable.copy (dffun_aT rT countType)
(pcan_type tfgraphK).
#[hnf] HB.instance Definition _ (rT : countType) :=
Countable.copy {ffun aT -> rT} {dffun forall _, rT}.
#[hnf] HB.instance Definition _ rT := Finite.copy (dffun_aT rT finType)
(pcan_type tfgraphK).
#[hnf] HB.instance Definition _ (rT : finType) :=
Finite.copy {ffun aT -> rT} {dffun forall _, rT}.
End InheritedStructures.
Section FinFunTuple.
Context {T : Type} {n : nat}.
Definition tuple_of_finfun (f : T ^ n) : n.-tuple T := [tuple f i | i < n].
Definition finfun_of_tuple (t : n.-tuple T) : (T ^ n) := [ffun i => tnth t i].
Lemma finfun_of_tupleK : cancel finfun_of_tuple tuple_of_finfun.
Proof.
by move=> t; apply: eq_from_tnth => i; rewrite tnth_map ffunE tnth_ord_tuple.
Qed.
Lemma tuple_of_finfunK : cancel tuple_of_finfun finfun_of_tuple.
Proof.
by move=> f; apply/ffunP => i; rewrite ffunE tnth_map tnth_ord_tuple.
Qed.
End FinFunTuple.
Section FunPlainTheory.
Variables (aT : finType) (rT : Type).
Notation fT := {ffun aT -> rT}.
Implicit Types (f : fT) (R : pred rT).
Definition fgraph f := codom_tuple f.
Definition Finfun (G : #|aT|.-tuple rT) := [ffun x => tnth G (enum_rank x)].
Lemma tnth_fgraph f i : tnth (fgraph f) i = f (enum_val i).
Proof. by rewrite tnth_map /tnth -enum_val_nth. Qed.
Lemma FinfunK : cancel Finfun fgraph.
Proof.
by move=> G; apply/eq_from_tnth=> i; rewrite tnth_fgraph ffunE enum_valK.
Qed.
Lemma fgraphK : cancel fgraph Finfun.
Proof. by move=> f; apply/ffunP=> x; rewrite ffunE tnth_fgraph enum_rankK. Qed.
Lemma fgraph_ffun0 aT0 : fgraph (ffun0 aT0) = nil :> seq rT.
Proof. by apply/nilP/eqP; rewrite size_tuple. Qed.
Lemma codom_ffun f : codom f = fgraph f. Proof. by []. Qed.
Lemma tagged_tfgraph f : @map _ rT tagged (tfgraph f) = fgraph f.
Proof. by rewrite -map_comp. Qed.
Lemma eq_ffun (g1 g2 : aT -> rT) : g1 =1 g2 -> finfun g1 = finfun g2.
Proof. exact: eq_dffun. Qed.
Lemma fgraph_codom f : fgraph f = codom_tuple f.
Proof. exact/esym/val_inj/codom_ffun. Qed.
Definition ffun_on_mem (mR : mem_pred rT) := family_mem (fun _ : aT => mR).
Lemma ffun_onP R f : reflect (forall x, f x \in R) (f \in ffun_on_mem (mem R)).
Proof. exact: forallP. Qed.
End FunPlainTheory.
Arguments Finfun {aT rT} G.
Arguments fgraph {aT rT} f.
Arguments FinfunK {aT rT} G : rename.
Arguments fgraphK {aT rT} f : rename.
Arguments eq_ffun {aT rT} [g1] g2 eq_g12.
Arguments ffun_onP {aT rT R f}.
Notation ffun_on R := (ffun_on_mem _ (mem R)).
Notation "@ 'ffun_on' aT R" :=
(ffun_on R : simpl_pred (finfun_of (Phant (aT -> id _))))
(at level 10, aT, R at level 9).
Lemma nth_fgraph_ord T n (x0 : T) (i : 'I_n) f : nth x0 (fgraph f) i = f i.
Proof.
by rewrite -[i in RHS]enum_rankK -tnth_fgraph (tnth_nth x0) enum_rank_ord.
Qed.
(*****************************************************************************)
Section Support.
Variables (aT : Type) (rT : eqType).
Definition support_for y (f : aT -> rT) := [pred x | f x != y].
Lemma supportE x y f : (x \in support_for y f) = (f x != y). Proof. by []. Qed.
End Support.
Notation "y .-support" := (support_for y)
(at level 1, format "y .-support") : function_scope.
Section EqTheory.
Variables (aT : finType) (rT : eqType).
Notation fT := {ffun aT -> rT}.
Implicit Types (y : rT) (D : {pred aT}) (R : {pred rT}) (f : fT).
Lemma supportP y D g :
reflect (forall x, x \notin D -> g x = y) (y.-support g \subset D).
Proof.
by (apply: (iffP subsetP) => Dg x; [apply: contraNeq|apply: contraR]) => /Dg->.
Qed.
Definition pfamily_mem y mD (mF : aT -> mem_pred rT) :=
family (fun i : aT => if in_mem i mD then pred_of_simpl (mF i) else pred1 y).
Lemma pfamilyP (pT : predType rT) y D (F : aT -> pT) f :
reflect (y.-support f \subset D /\ {in D, forall x, f x \in F x})
(f \in pfamily_mem y (mem D) (fmem F)).
Proof.
apply: (iffP familyP) => [/= f_pfam | [/supportP f_supp f_fam] x].
split=> [|x Ax]; last by have:= f_pfam x; rewrite Ax.
by apply/subsetP=> x; case: ifP (f_pfam x) => //= _ fx0 /negP[].
by case: ifPn => Ax /=; rewrite inE /= (f_fam, f_supp).
Qed.
Definition pffun_on_mem y mD mR := pfamily_mem y mD (fun _ => mR).
Lemma pffun_onP y D R f :
reflect (y.-support f \subset D /\ {subset image f D <= R})
(f \in pffun_on_mem y (mem D) (mem R)).
Proof.
apply: (iffP (pfamilyP y D (fun _ => R) f)) => [] [-> f_fam]; split=> //.
by move=> _ /imageP[x Ax ->]; apply: f_fam.
by move=> x Ax; apply: f_fam; apply/imageP; exists x.
Qed.
End EqTheory.
Arguments supportP {aT rT y D g}.
Arguments pfamilyP {aT rT pT y D F f}.
Arguments pffun_onP {aT rT y D R f}.
Notation pfamily y D F := (pfamily_mem y (mem D) (fmem F)).
Notation pffun_on y D R := (pffun_on_mem y (mem D) (mem R)).
(*****************************************************************************)
Section FinDepTheory.
Variables (aT : finType) (rT : aT -> finType).
Notation fT := {dffun forall x : aT, rT x}.
Lemma card_family (F : forall x, pred (rT x)) :
#|(family F : simpl_pred fT)| = foldr muln 1 [seq #|F x| | x : aT].
Proof.
rewrite /image_mem; set E := enum aT in (uniqE := enum_uniq aT) *.
have trivF x: x \notin E -> #|F x| = 1 by rewrite mem_enum.
elim: E uniqE => /= [_ | x0 E IH_E /andP[E'x0 uniqE]] in F trivF *.
have /fin_all_exists[f0 Ff0] x: exists y0, F x =i pred1 y0.
have /pred0Pn[y Fy]: #|F x| != 0 by rewrite trivF.
by exists y; apply/fsym/subset_cardP; rewrite ?subset_pred1 // card1 trivF.
apply: eq_card1 (finfun f0 : fT) _ _ => f; apply/familyP/eqP=> [Ff | {f}-> x].
by apply/ffunP=> x; have /[!(Ff0, ffunE)]/eqP := Ff x.
by rewrite ffunE Ff0 inE /=.
have [y0 Fxy0 | Fx00] := pickP (F x0); last first.
by rewrite !eq_card0 // => f; apply: contraFF (Fx00 (f x0))=> /familyP; apply.
pose F1 x := if eqP is ReflectT Dx then xpred1 (ecast x (rT x) Dx y0) else F x.
transitivity (#|[predX F x0 & family F1 : pred fT]|); last first.
rewrite cardX {}IH_E {uniqE}// => [|x E'x]; last first.
rewrite /F1; case: eqP => [Dx | /nesym/eqP-x0'x]; first exact: card1.
by rewrite trivF // negb_or x0'x.
congr (_ * foldr _ _ _); apply/eq_in_map=> x Ex.
by rewrite /F1; case: eqP => // Dx0; rewrite Dx0 Ex in E'x0.
pose g yf : fT := let: (y, f) := yf : rT x0 * fT in
[ffun x => if eqP is ReflectT Dx then ecast x (rT x) Dx y else f x].
have gK: cancel (fun f : fT => (f x0, g (y0, f))) g.
by move=> f; apply/ffunP=> x; rewrite !ffunE; case: eqP => //; case: x /.
rewrite -(card_image (can_inj gK)); apply: eq_card => [] [y f] /=.
apply/imageP/andP=> [[f1 /familyP/=Ff1] [-> ->]| [/=Fx0y /familyP/=Ff]].
split=> //; apply/familyP=> x; rewrite ffunE /F1 /=.
by case: eqP => // Dx; apply: eqxx.
exists (g (y, f)).
by apply/familyP=> x; have:= Ff x; rewrite ffunE /F1; case: eqP; [case: x /|].
congr (_, _); first by rewrite /= ffunE; case: eqP => // Dx; rewrite eq_axiomK.
by apply/ffunP=> x; have:= Ff x; rewrite !ffunE /F1; case: eqP => // Dx /eqP.
Qed.
Lemma card_dep_ffun : #|fT| = foldr muln 1 [seq #|rT x| | x : aT].
Proof. by rewrite -card_family; apply/esym/eq_card=> f; apply/familyP. Qed.
End FinDepTheory.
Section FinFunTheory.
Variables aT rT : finType.
Notation fT := {ffun aT -> rT}.
Implicit Types (D : {pred aT}) (R : {pred rT}) (F : aT -> pred rT).
Lemma card_pfamily y0 D F :
#|pfamily y0 D F| = foldr muln 1 [seq #|F x| | x in D].
Proof.
rewrite card_family !/(image _ _) /(enum D) -enumT /=.
by elim: (enum aT) => //= x E ->; have [// | D'x] := ifP; rewrite card1 mul1n.
Qed.
Lemma card_pffun_on y0 D R : #|pffun_on y0 D R| = #|R| ^ #|D|.
Proof.
rewrite (cardE D) card_pfamily /image_mem.
by elim: (enum D) => //= _ e ->; rewrite expnS.
Qed.
Lemma card_ffun_on R : #|@ffun_on aT R| = #|R| ^ #|aT|.
Proof.
rewrite card_family /image_mem cardT.
by elim: (enum aT) => //= _ e ->; rewrite expnS.
Qed.
Lemma card_ffun : #|fT| = #|rT| ^ #|aT|.
Proof. by rewrite -card_ffun_on; apply/esym/eq_card=> f; apply/forallP. Qed.
End FinFunTheory.
Section DependentFiniteProduct.
Variables (I : finType) (T_ : I -> finType).
Notation fprod_type := (forall i : I, T_ i) (only parsing).
(* Definition of [fprod] := dependent product of finTypes *)
Record fprod : predArgType := FProd
{ fprod_fun : {ffun I -> {i : I & T_ i}} ;
fprod_prop : [forall i : I, tag (fprod_fun i) == i] }.
Lemma tag_fprod_fun (f : fprod) i : tag (fprod_fun f i) = i.
Proof. by have /'forall_eqP/(_ i) := fprod_prop f. Qed.
Definition fun_of_fprod (f : fprod) : fprod_type :=
fun i => etagged ('forall_eqP (fprod_prop f) i).
Coercion fun_of_fprod : fprod >-> Funclass.
#[hnf] HB.instance Definition _ := [isSub for fprod_fun].
#[hnf] HB.instance Definition _ := [Finite of fprod by <:].
Lemma fprod_of_prod_type_subproof (f : fprod_type) :
[forall i : I, tag ([ffun i => Tagged T_ (f i)] i) == i].
Proof. by apply/'forall_eqP => i /=; rewrite ffunE. Qed.
Definition fprod_of_fun (f : fprod_type) : fprod :=
FProd (fprod_of_prod_type_subproof f).
Lemma fprodK : cancel fun_of_fprod fprod_of_fun.
Proof.
rewrite /fun_of_fprod /fprod_of_fun; case=> f fP.
by apply/val_inj/ffunP => i /=; rewrite !ffunE etaggedK.
Qed.
Lemma fprodE g i : fprod_of_fun g i = g i.
Proof.
rewrite /fprod_of_fun /fun_of_fprod/=.
by move: ('forall_eqP _ _); rewrite ffunE/= => e; rewrite eq_axiomK.
Qed.
Lemma fprodP (f1 f2 : fprod) : (forall x, f1 x = f2 x) <-> f1 = f2.
Proof.
split=> [eq_f12|->//]; rewrite -[f1]fprodK -[f2]fprodK.
by apply/val_inj/ffunP => i; rewrite !ffunE eq_f12.
Qed.
Definition dffun_of_fprod (f : fprod) : {dffun forall i : I, T_ i} :=
[ffun x => f x].
Definition fprod_of_dffun (f : {dffun forall i : I, T_ i}) : fprod :=
fprod_of_fun f.
Lemma dffun_of_fprodK : cancel dffun_of_fprod fprod_of_dffun.
Proof. by move=> f; apply/fprodP=> i; rewrite fprodE ffunE. Qed.
#[local] Hint Resolve dffun_of_fprodK : core.
Lemma fprod_of_dffunK : cancel fprod_of_dffun dffun_of_fprod.
Proof. by move=> f; apply/ffunP => i; rewrite !ffunE fprodE. Qed.
#[local] Hint Resolve fprod_of_dffunK : core.
Lemma dffun_of_fprod_bij : bijective dffun_of_fprod.
Proof. by exists fprod_of_dffun. Qed.
Lemma fprod_of_dffun_bij : bijective fprod_of_dffun.
Proof. by exists dffun_of_fprod. Qed.
Definition to_family_tagged_with (f : fprod) : {x in family (tagged_with T_)} :=
exist _ (fprod_fun f) (fprod_prop f).
Definition of_family_tagged_with (f : {x in family (tagged_with T_)}) : fprod :=
FProd (valP f).
Lemma to_family_tagged_withK :
cancel to_family_tagged_with of_family_tagged_with.
Proof. by case=> f fP; apply/val_inj. Qed.
#[local] Hint Resolve to_family_tagged_withK : core.
Lemma of_family_tagged_withK :
cancel of_family_tagged_with to_family_tagged_with.
Proof. by case=> f fP; apply/val_inj. Qed.
#[local] Hint Resolve of_family_tagged_withK : core.
Lemma to_family_tagged_with_bij : bijective to_family_tagged_with.
Proof. by exists of_family_tagged_with. Qed.
Lemma of_family_tagged_with_bij : bijective of_family_tagged_with.
Proof. by exists to_family_tagged_with. Qed.
Lemma etaggedE (a : fprod) (i : I) (e : tag (fprod_fun a i) = i) :
etagged e = a i.
Proof. by case: a e => //= f fP e; congr etagged; apply: eq_irrelevance. Qed.
End DependentFiniteProduct.
Arguments to_family_tagged_with {I T_}.
Arguments of_family_tagged_with {I T_}.
Notation "[ 'fprod' i : I => F ]" := (fprod_of_fun (fun i : I => F))
(i name, only parsing) : function_scope.
Notation "[ 'fprod' : I => F ]" := (fprod_of_fun (fun _ : I => F))
(only parsing) : function_scope.
Notation "[ 'fprod' i => F ]" := [fprod i : _ => F]
(i name, format "[ 'fprod' i => F ]") : function_scope.
Notation "[ 'fprod' => F ]" := [fprod : _ => F]
(format "[ 'fprod' => F ]") : function_scope.
|
Groebner.lean
|
/-
Copyright (c) 2024 Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir
-/
import Mathlib.Data.Finsupp.Lex
import Mathlib.Data.Finsupp.MonomialOrder
import Mathlib.Data.Finsupp.WellFounded
import Mathlib.Data.List.TFAE
import Mathlib.RingTheory.MvPolynomial.Homogeneous
import Mathlib.RingTheory.MvPolynomial.MonomialOrder
/-! # Division algorithm with respect to monomial orders
We provide a division algorithm with respect to monomial orders in polynomial rings.
Let `R` be a commutative ring, `σ` a type of indeterminates and `m : MonomialOrder σ`
a monomial ordering on `σ →₀ ℕ`.
Consider a family of polynomials `b : ι → MvPolynomial σ R` with invertible leading coefficients
(with respect to `m`) : we assume `hb : ∀ i, IsUnit (m.leadingCoeff (b i))`).
* `MonomialOrder.div hb f` furnishes
- a finitely supported family `g : ι →₀ MvPolynomial σ R`
- and a “remainder” `r : MvPolynomial σ R`
such that the three properties hold:
(1) One has `f = ∑ (g i) * (b i) + r`
(2) For every `i`, `m.degree ((g i) * (b i)` is less than or equal to that of `f`
(3) For every `i`, every monomial in the support of `r` is strictly smaller
than the leading term of `b i`,
The proof is done by induction, using two standard constructions
* `MonomialOrder.subLTerm f` deletes the leading term of a polynomial `f`
* `MonomialOrder.reduce hb f` subtracts from `f` the appropriate multiple of `b : MvPolynomial σ R`,
provided `IsUnit (m.leadingCoeff b)`.
* `MonomialOrder.div_set` is the variant of `MonomialOrder.div` for a set of polynomials.
* `MonomialOrder.div_single` is the variant of `MonomialOrder.div` for a single polynomial.
## Reference : [Becker-Weispfenning1993]
-/
namespace MonomialOrder
open MvPolynomial
open scoped MonomialOrder
variable {σ : Type*} {m : MonomialOrder σ} {R : Type*} [CommRing R]
variable (m) in
/-- Delete the leading term in a multivariate polynomial (for some monomial order) -/
noncomputable def subLTerm (f : MvPolynomial σ R) : MvPolynomial σ R :=
f - monomial (m.degree f) (m.leadingCoeff f)
theorem degree_sub_LTerm_le (f : MvPolynomial σ R) :
m.degree (m.subLTerm f) ≼[m] m.degree f := by
apply le_trans degree_sub_le
simp only [sup_le_iff, le_refl, true_and]
apply degree_monomial_le
theorem degree_sub_LTerm_lt {f : MvPolynomial σ R} (hf : m.degree f ≠ 0) :
m.degree (m.subLTerm f) ≺[m] m.degree f := by
rw [lt_iff_le_and_ne]
refine ⟨degree_sub_LTerm_le f, ?_⟩
classical
intro hf'
simp only [EmbeddingLike.apply_eq_iff_eq] at hf'
have : m.subLTerm f ≠ 0 := by
intro h
simp only [h, degree_zero] at hf'
exact hf hf'.symm
rw [← coeff_degree_ne_zero_iff (m := m), hf'] at this
apply this
simp [subLTerm, coeff_monomial, leadingCoeff]
variable (m) in
/-- Reduce a polynomial modulo a polynomial with unit leading term (for some monomial order) -/
noncomputable
def reduce {b : MvPolynomial σ R} (hb : IsUnit (m.leadingCoeff b)) (f : MvPolynomial σ R) :
MvPolynomial σ R :=
f - monomial (m.degree f - m.degree b) (hb.unit⁻¹ * m.leadingCoeff f) * b
theorem degree_reduce_lt {f b : MvPolynomial σ R} (hb : IsUnit (m.leadingCoeff b))
(hbf : m.degree b ≤ m.degree f) (hf : m.degree f ≠ 0) :
m.degree (m.reduce hb f) ≺[m] m.degree f := by
have H : m.degree f =
m.degree ((monomial (m.degree f - m.degree b)) (hb.unit⁻¹ * m.leadingCoeff f)) +
m.degree b := by
classical
rw [degree_monomial, if_neg]
· ext d
rw [tsub_add_cancel_of_le hbf]
· simp only [Units.mul_right_eq_zero, leadingCoeff_eq_zero_iff]
intro hf0
apply hf
simp [hf0]
have H' : coeff (m.degree f) (m.reduce hb f) = 0 := by
simp only [reduce, coeff_sub, sub_eq_zero]
nth_rewrite 2 [H]
rw [coeff_mul_of_degree_add (m := m), leadingCoeff_monomial, mul_comm, ← mul_assoc,
IsUnit.mul_val_inv, one_mul, ← leadingCoeff]
rw [lt_iff_le_and_ne]
constructor
· classical
apply le_trans degree_sub_le
simp only [sup_le_iff, le_refl, true_and]
apply le_of_le_of_eq degree_mul_le
rw [m.toSyn.injective.eq_iff]
exact H.symm
· intro K
simp only [EmbeddingLike.apply_eq_iff_eq] at K
nth_rewrite 1 [← K] at H'
rw [← leadingCoeff, leadingCoeff_eq_zero_iff] at H'
rw [H', degree_zero] at K
exact hf K.symm
/-- Division by a family of multivariate polynomials
whose leading coefficients are invertible with respect to a monomial order -/
theorem div {ι : Type*} {b : ι → MvPolynomial σ R}
(hb : ∀ i, IsUnit (m.leadingCoeff (b i))) (f : MvPolynomial σ R) :
∃ (g : ι →₀ (MvPolynomial σ R)) (r : MvPolynomial σ R),
f = Finsupp.linearCombination _ b g + r ∧
(∀ i, m.degree (b i * (g i)) ≼[m] m.degree f) ∧
(∀ c ∈ r.support, ∀ i, ¬ (m.degree (b i) ≤ c)) := by
by_cases hb' : ∃ i, m.degree (b i) = 0
· obtain ⟨i, hb0⟩ := hb'
use Finsupp.single i ((hb i).unit⁻¹ • f), 0
constructor
· simp only [Finsupp.linearCombination_single, smul_eq_mul, add_zero]
simp only [smul_mul_assoc, ← smul_eq_iff_eq_inv_smul, Units.smul_isUnit]
nth_rewrite 2 [eq_C_of_degree_eq_zero hb0]
rw [mul_comm, smul_eq_C_mul]
constructor
· intro j
by_cases hj : j = i
· apply le_trans degree_mul_le
simp only [hj, hb0, Finsupp.single_eq_same, zero_add]
apply le_of_eq
simp only [EmbeddingLike.apply_eq_iff_eq]
apply degree_smul (Units.isRegular _)
· simp only [Finsupp.single_eq_of_ne (Ne.symm hj), mul_zero, degree_zero, map_zero]
apply bot_le
· simp
push_neg at hb'
by_cases hf0 : f = 0
· refine ⟨0, 0, by simp [hf0], ?_, by simp⟩
intro b
simp only [Finsupp.coe_zero, Pi.zero_apply, mul_zero, degree_zero, map_zero]
exact bot_le
by_cases hf : ∃ i, m.degree (b i) ≤ m.degree f
· obtain ⟨i, hf⟩ := hf
have deg_reduce : m.degree (m.reduce (hb i) f) ≺[m] m.degree f := by
apply degree_reduce_lt (hb i) hf
intro hf0'
apply hb' i
simpa [hf0'] using hf
obtain ⟨g', r', H'⟩ := div hb (m.reduce (hb i) f)
use g' +
Finsupp.single i (monomial (m.degree f - m.degree (b i)) ((hb i).unit⁻¹ * m.leadingCoeff f))
use r'
constructor
· rw [map_add, add_assoc, add_comm _ r', ← add_assoc, ← H'.1]
simp [reduce]
constructor
· rintro j
simp only [Finsupp.coe_add, Pi.add_apply]
rw [mul_add]
apply le_trans degree_add_le
simp only [sup_le_iff]
constructor
· exact le_trans (H'.2.1 _) (le_of_lt deg_reduce)
· classical
rw [Finsupp.single_apply]
split_ifs with hc
· apply le_trans degree_mul_le
simp only [map_add]
apply le_of_le_of_eq (add_le_add_left (degree_monomial_le _) _)
simp only [← hc]
rw [← map_add, m.toSyn.injective.eq_iff]
rw [add_tsub_cancel_of_le]
exact hf
· simp only [mul_zero, degree_zero, map_zero]
exact bot_le
· exact H'.2.2
· push_neg at hf
suffices ∃ (g' : ι →₀ MvPolynomial σ R), ∃ r',
(m.subLTerm f = Finsupp.linearCombination (MvPolynomial σ R) b g' + r') ∧
(∀ i, m.degree ((b i) * (g' i)) ≼[m] m.degree (m.subLTerm f)) ∧
(∀ c ∈ r'.support, ∀ i, ¬ m.degree (b i) ≤ c) by
obtain ⟨g', r', H'⟩ := this
use g', r' + monomial (m.degree f) (m.leadingCoeff f)
constructor
· simp [← add_assoc, ← H'.1, subLTerm]
constructor
· exact fun b ↦ le_trans (H'.2.1 b) (degree_sub_LTerm_le f)
· intro c hc i
by_cases hc' : c ∈ r'.support
· exact H'.2.2 c hc' i
· convert hf i
classical
have := MvPolynomial.support_add hc
rw [Finset.mem_union, Classical.or_iff_not_imp_left] at this
simpa only [Finset.mem_singleton] using support_monomial_subset (this hc')
by_cases hf'0 : m.subLTerm f = 0
· refine ⟨0, 0, by simp [hf'0], ?_, by simp⟩
intro b
simp only [Finsupp.coe_zero, Pi.zero_apply, mul_zero, degree_zero, map_zero]
exact bot_le
· exact (div hb) (m.subLTerm f)
termination_by WellFounded.wrap
((isWellFounded_iff m.syn fun x x_1 ↦ x < x_1).mp m.wf) (m.toSyn (m.degree f))
decreasing_by
· exact deg_reduce
· apply degree_sub_LTerm_lt
intro hf0
apply hf'0
simp only [subLTerm, sub_eq_zero]
nth_rewrite 1 [eq_C_of_degree_eq_zero hf0, hf0]
simp
/-- Division by a *set* of multivariate polynomials
whose leading coefficients are invertible with respect to a monomial order -/
theorem div_set {B : Set (MvPolynomial σ R)}
(hB : ∀ b ∈ B, IsUnit (m.leadingCoeff b)) (f : MvPolynomial σ R) :
∃ (g : B →₀ (MvPolynomial σ R)) (r : MvPolynomial σ R),
f = Finsupp.linearCombination _ (fun (b : B) ↦ (b : MvPolynomial σ R)) g + r ∧
(∀ (b : B), m.degree ((b : MvPolynomial σ R) * (g b)) ≼[m] m.degree f) ∧
(∀ c ∈ r.support, ∀ b ∈ B, ¬ (m.degree b ≤ c)) := by
obtain ⟨g, r, H⟩ := m.div (b := fun (p : B) ↦ p) (fun b ↦ hB b b.prop) f
exact ⟨g, r, H.1, H.2.1, fun c hc b hb ↦ H.2.2 c hc ⟨b, hb⟩⟩
/-- Division by a multivariate polynomial
whose leading coefficient is invertible with respect to a monomial order -/
theorem div_single {b : MvPolynomial σ R}
(hb : IsUnit (m.leadingCoeff b)) (f : MvPolynomial σ R) :
∃ (g : MvPolynomial σ R) (r : MvPolynomial σ R),
f = g * b + r ∧
(m.degree (b * g) ≼[m] m.degree f) ∧
(∀ c ∈ r.support, ¬ (m.degree b ≤ c)) := by
obtain ⟨g, r, hgr, h1, h2⟩ := div_set (B := {b}) (m := m) (by simp [hb]) f
specialize h1 ⟨b, by simp⟩
set q := g ⟨b, by simp⟩
simp only [Set.mem_singleton_iff, forall_eq] at h2
simp only at h1
refine ⟨q, r, ?_, h1, h2⟩
rw [hgr]
simp only [Finsupp.linearCombination, Finsupp.coe_lsum, LinearMap.coe_smulRight, LinearMap.id_coe,
id_eq, smul_eq_mul, add_left_inj]
rw [Finsupp.sum_eq_single ⟨b, by simp⟩ _ (by simp)]
simp +contextual
end MonomialOrder
|
NhdsKer.lean
|
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Yury Kudryashov
-/
import Mathlib.Topology.NhdsSet
import Mathlib.Topology.Inseparable
/-!
# Neighborhoods kernel of a set
In `Mathlib/Topology/Defs/Filter.lean`, `nhdsKer s` is defined to be the intersection of all
neighborhoods of `s`.
Note that this construction has no standard name in the literature.
In this file we prove basic properties of this operation.
-/
open Set Filter
open scoped Topology
variable {ι : Sort*} {X : Type*} [TopologicalSpace X] {s t : Set X} {x y : X}
lemma nhdsKer_singleton_eq_ker_nhds (x : X) : nhdsKer {x} = (𝓝 x).ker := by simp [nhdsKer]
@[deprecated (since := "2025-07-09")]
alias exterior_singleton_eq_ker_nhds := nhdsKer_singleton_eq_ker_nhds
@[simp]
theorem mem_nhdsKer_singleton : x ∈ nhdsKer {y} ↔ x ⤳ y := by
rw [nhdsKer_singleton_eq_ker_nhds, ker_nhds_eq_specializes, mem_setOf]
@[deprecated (since := "2025-07-09")] alias mem_exterior_singleton := mem_nhdsKer_singleton
lemma nhdsKer_def (s : Set X) : nhdsKer s = ⋂₀ {t : Set X | IsOpen t ∧ s ⊆ t} :=
(hasBasis_nhdsSet _).ker.trans sInter_eq_biInter.symm
@[deprecated (since := "2025-07-09")] alias exterior_def := nhdsKer_def
lemma mem_nhdsKer : x ∈ nhdsKer s ↔ ∀ U, IsOpen U → s ⊆ U → x ∈ U := by simp [nhdsKer_def]
@[deprecated (since := "2025-07-09")] alias mem_exterior := mem_nhdsKer
lemma subset_nhdsKer_iff : s ⊆ nhdsKer t ↔ ∀ U, IsOpen U → t ⊆ U → s ⊆ U := by
simp [nhdsKer_def]
@[deprecated (since := "2025-07-09")] alias subset_exterior_iff := subset_nhdsKer_iff
lemma subset_nhdsKer : s ⊆ nhdsKer s := subset_nhdsKer_iff.2 fun _ _ ↦ id
@[deprecated (since := "2025-07-09")] alias subset_exterior := subset_nhdsKer
lemma nhdsKer_minimal (h₁ : s ⊆ t) (h₂ : IsOpen t) : nhdsKer s ⊆ t := by
rw [nhdsKer_def]; exact sInter_subset_of_mem ⟨h₂, h₁⟩
@[deprecated (since := "2025-07-09")] alias exterior_minimal := nhdsKer_minimal
lemma IsOpen.nhdsKer_eq (h : IsOpen s) : nhdsKer s = s :=
(nhdsKer_minimal Subset.rfl h).antisymm subset_nhdsKer
@[deprecated (since := "2025-07-09")] alias IsOpen.exterior_eq := IsOpen.nhdsKer_eq
lemma IsOpen.nhdsKer_subset (ht : IsOpen t) : nhdsKer s ⊆ t ↔ s ⊆ t :=
⟨subset_nhdsKer.trans, fun h ↦ nhdsKer_minimal h ht⟩
@[deprecated (since := "2025-07-09")] alias IsOpen.exterior_subset := IsOpen.nhdsKer_subset
@[simp]
theorem nhdsKer_iUnion (s : ι → Set X) : nhdsKer (⋃ i, s i) = ⋃ i, nhdsKer (s i) := by
simp only [nhdsKer, nhdsSet_iUnion, ker_iSup]
@[deprecated (since := "2025-07-09")] alias exterior_iUnion := nhdsKer_iUnion
@[simp]
theorem nhdsKer_union (s t : Set X) : nhdsKer (s ∪ t) = nhdsKer s ∪ nhdsKer t := by
simp only [nhdsKer, nhdsSet_union, ker_sup]
@[deprecated (since := "2025-07-09")] alias exterior_union := nhdsKer_union
@[simp]
theorem nhdsKer_sUnion (S : Set (Set X)) : nhdsKer (⋃₀ S) = ⋃ s ∈ S, nhdsKer s := by
simp only [sUnion_eq_biUnion, nhdsKer_iUnion]
@[deprecated (since := "2025-07-09")] alias exterior_sUnion := nhdsKer_sUnion
theorem mem_nhdsKer_iff_specializes : x ∈ nhdsKer s ↔ ∃ y ∈ s, x ⤳ y := calc
x ∈ nhdsKer s ↔ x ∈ nhdsKer (⋃ y ∈ s, {y}) := by simp
_ ↔ ∃ y ∈ s, x ⤳ y := by
simp only [nhdsKer_iUnion, mem_nhdsKer_singleton, mem_iUnion₂, exists_prop]
@[deprecated (since := "2025-07-09")]
alias mem_exterior_iff_specializes := mem_nhdsKer_iff_specializes
@[mono] lemma nhdsKer_mono : Monotone (nhdsKer : Set X → Set X) :=
fun _s _t h ↦ ker_mono <| nhdsSet_mono h
@[deprecated (since := "2025-07-09")] alias exterior_mono := nhdsKer_mono
/-- This name was used to be used for the `Iff` version,
see `nhdsKer_subset_nhdsKer_iff_nhdsSet`.
-/
@[gcongr] lemma nhdsKer_subset_nhdsKer (h : s ⊆ t) : nhdsKer s ⊆ nhdsKer t := nhdsKer_mono h
@[deprecated (since := "2025-07-09")] alias exterior_subset_exterior := nhdsKer_subset_nhdsKer
@[simp] lemma nhdsKer_subset_nhdsKer_iff_nhdsSet : nhdsKer s ⊆ nhdsKer t ↔ 𝓝ˢ s ≤ 𝓝ˢ t := by
simp +contextual only [subset_nhdsKer_iff, (hasBasis_nhdsSet _).ge_iff,
and_imp, IsOpen.mem_nhdsSet, IsOpen.nhdsKer_subset]
@[deprecated (since := "2025-07-09")]
alias exterior_subset_exterior_iff_nhdsSet := nhdsKer_subset_nhdsKer_iff_nhdsSet
theorem nhdsKer_eq_nhdsKer_iff_nhdsSet : nhdsKer s = nhdsKer t ↔ 𝓝ˢ s = 𝓝ˢ t := by
simp [le_antisymm_iff]
@[deprecated (since := "2025-07-09")]
alias exterior_eq_exterior_iff_nhdsSet := nhdsKer_eq_nhdsKer_iff_nhdsSet
lemma specializes_iff_nhdsKer_subset : x ⤳ y ↔ nhdsKer {x} ⊆ nhdsKer {y} := by
simp [Specializes]
@[deprecated (since := "2025-07-09")]
alias specializes_iff_exterior_subset := specializes_iff_nhdsKer_subset
theorem nhdsKer_iInter_subset {s : ι → Set X} : nhdsKer (⋂ i, s i) ⊆ ⋂ i, nhdsKer (s i) :=
nhdsKer_mono.map_iInf_le
@[deprecated (since := "2025-07-09")] alias exterior_iInter_subset := nhdsKer_iInter_subset
theorem nhdsKer_inter_subset {s t : Set X} : nhdsKer (s ∩ t) ⊆ nhdsKer s ∩ nhdsKer t :=
nhdsKer_mono.map_inf_le _ _
@[deprecated (since := "2025-07-09")] alias exterior_inter_subset := nhdsKer_inter_subset
theorem nhdsKer_sInter_subset {s : Set (Set X)} : nhdsKer (⋂₀ s) ⊆ ⋂ x ∈ s, nhdsKer x :=
nhdsKer_mono.map_sInf_le
@[deprecated (since := "2025-07-09")] alias exterior_sInter_subset := nhdsKer_sInter_subset
@[simp] lemma nhdsKer_empty : nhdsKer (∅ : Set X) = ∅ := isOpen_empty.nhdsKer_eq
@[deprecated (since := "2025-07-09")] alias exterior_empty := nhdsKer_empty
@[simp] lemma nhdsKer_univ : nhdsKer (univ : Set X) = univ := isOpen_univ.nhdsKer_eq
@[deprecated (since := "2025-07-09")] alias exterior_univ := nhdsKer_univ
@[simp] lemma nhdsKer_eq_empty : nhdsKer s = ∅ ↔ s = ∅ :=
⟨eq_bot_mono subset_nhdsKer, by rintro rfl; exact nhdsKer_empty⟩
@[deprecated (since := "2025-07-09")] alias exterior_eq_empty := nhdsKer_eq_empty
@[simp] lemma nhdsSet_nhdsKer (s : Set X) : 𝓝ˢ (nhdsKer s) = 𝓝ˢ s := by
refine le_antisymm ((hasBasis_nhdsSet _).ge_iff.2 ?_) (nhdsSet_mono subset_nhdsKer)
exact fun U ⟨hUo, hsU⟩ ↦ hUo.mem_nhdsSet.2 <| hUo.nhdsKer_subset.2 hsU
@[deprecated (since := "2025-07-09")] alias nhdsSet_exterior := nhdsSet_nhdsKer
@[simp] lemma nhdsKer_nhdsKer (s : Set X) : nhdsKer (nhdsKer s) = nhdsKer s := by
simp only [nhdsKer_eq_nhdsKer_iff_nhdsSet, nhdsSet_nhdsKer]
@[deprecated (since := "2025-07-09")] alias exterior_exterior := nhdsKer_nhdsKer
|
CommMon_.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Monoidal.Braided.Basic
import Mathlib.CategoryTheory.Monoidal.Mon_
/-!
# The category of commutative monoids in a braided monoidal category.
-/
universe v₁ v₂ v₃ u₁ u₂ u₃ u
open CategoryTheory MonoidalCategory Mon_Class
variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] [BraidedCategory.{v₁} C]
variable (C) in
/-- A commutative monoid object internal to a monoidal category.
-/
structure CommMon_ where
/-- The underlying object in the ambient monoidal category -/
X : C
[mon : Mon_Class X]
[comm : IsCommMon X]
attribute [instance] CommMon_.mon CommMon_.comm
namespace CommMon_
/-- A commutative monoid object is a monoid object. -/
@[simps X]
def toMon_ (A : CommMon_ C) : Mon_ C := ⟨A.X⟩
variable (C) in
/-- The trivial commutative monoid object. We later show this is initial in `CommMon_ C`.
-/
@[simps!]
def trivial : CommMon_ C := { X := 𝟙_ C }
instance : Inhabited (CommMon_ C) :=
⟨trivial C⟩
variable {M : CommMon_ C}
instance : Category (CommMon_ C) :=
InducedCategory.category CommMon_.toMon_
@[simp]
theorem id_hom (A : CommMon_ C) : Mon_.Hom.hom (𝟙 A) = 𝟙 A.X :=
rfl
@[simp]
theorem comp_hom {R S T : CommMon_ C} (f : R ⟶ S) (g : S ⟶ T) :
Mon_.Hom.hom (f ≫ g) = f.hom ≫ g.hom :=
rfl
@[ext]
lemma hom_ext {A B : CommMon_ C} (f g : A ⟶ B) (h : f.hom = g.hom) : f = g :=
Mon_.Hom.ext h
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/10688): the following two lemmas `id'` and `comp'`
-- have been added to ease automation;
@[simp]
lemma id' (A : CommMon_ C) : (𝟙 A : A.toMon_ ⟶ A.toMon_) = 𝟙 (A.toMon_) := rfl
@[simp]
lemma comp' {A₁ A₂ A₃ : CommMon_ C} (f : A₁ ⟶ A₂) (g : A₂ ⟶ A₃) :
((f ≫ g : A₁ ⟶ A₃) : A₁.toMon_ ⟶ A₃.toMon_) = @CategoryStruct.comp (Mon_ C) _ _ _ _ f g := rfl
section
variable (C)
/-- The forgetful functor from commutative monoid objects to monoid objects. -/
@[simps! obj_X]
def forget₂Mon_ : CommMon_ C ⥤ Mon_ C :=
inducedFunctor CommMon_.toMon_
/-- The forgetful functor from commutative monoid objects to monoid objects
is fully faithful. -/
def fullyFaithfulForget₂Mon_ : (forget₂Mon_ C).FullyFaithful :=
fullyFaithfulInducedFunctor _
-- The `Full, Faithful` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance : (forget₂Mon_ C).Full := InducedCategory.full _
instance : (forget₂Mon_ C).Faithful := InducedCategory.faithful _
@[simp]
theorem forget₂Mon_obj_one (A : CommMon_ C) : η[((forget₂Mon_ C).obj A).X] = η[A.X] :=
rfl
@[simp]
theorem forget₂Mon_obj_mul (A : CommMon_ C) : μ[((forget₂Mon_ C).obj A).X] = μ[A.X] :=
rfl
@[simp]
theorem forget₂Mon_map_hom {A B : CommMon_ C} (f : A ⟶ B) : ((forget₂Mon_ C).map f).hom = f.hom :=
rfl
@[deprecated (since := "2025-02-07")] alias forget₂_Mon_obj_one := forget₂Mon_obj_one
@[deprecated (since := "2025-02-07")] alias forget₂_Mon_obj_mul := forget₂Mon_obj_mul
@[deprecated (since := "2025-02-07")] alias forget₂_Mon_map_hom := forget₂Mon_map_hom
/-- The forgetful functor from commutative monoid objects to the ambient category. -/
@[simps!]
def forget : CommMon_ C ⥤ C :=
forget₂Mon_ C ⋙ Mon_.forget C
instance : (forget C).Faithful where
@[simp]
theorem forget₂Mon_comp_forget : forget₂Mon_ C ⋙ Mon_.forget C = forget C := rfl
instance {M N : CommMon_ C} {f : M ⟶ N} [IsIso f] : IsIso f.hom :=
inferInstanceAs <| IsIso <| (forget C).map f
end
/-- Construct an isomorphism of commutative monoid objects by giving a monoid isomorphism between
the underlying objects. -/
@[simps!]
def mkIso' {M N : C} (e : M ≅ N) [Mon_Class M] [IsCommMon M] [Mon_Class N] [IsCommMon N]
[IsMon_Hom e.hom] : mk M ≅ mk N :=
(fullyFaithfulForget₂Mon_ C).preimageIso (Mon_.mkIso' e)
/-- Construct an isomorphism of commutative monoid objects by giving an isomorphism between the
underlying objects and checking compatibility with unit and multiplication only in the forward
direction. -/
@[simps!]
abbrev mkIso {M N : CommMon_ C} (e : M.X ≅ N.X) (one_f : η[M.X] ≫ e.hom = η[N.X] := by cat_disch)
(mul_f : μ[M.X] ≫ e.hom = (e.hom ⊗ₘ e.hom) ≫ μ[N.X] := by cat_disch) : M ≅ N :=
have : IsMon_Hom e.hom := ⟨one_f, mul_f⟩
mkIso' e
instance uniqueHomFromTrivial (A : CommMon_ C) : Unique (trivial C ⟶ A) :=
Mon_.uniqueHomFromTrivial A.toMon_
open CategoryTheory.Limits
instance : HasInitial (CommMon_ C) :=
hasInitial_of_unique (trivial C)
end CommMon_
namespace CategoryTheory
variable
{D : Type u₂} [Category.{v₂} D] [MonoidalCategory D] [BraidedCategory D]
{E : Type u₃} [Category.{v₃} E] [MonoidalCategory E] [BraidedCategory E]
{F F' : C ⥤ D} {G : D ⥤ E}
namespace Functor
section LaxBraided
variable [F.LaxBraided] [F'.LaxBraided] [G.LaxBraided]
open scoped Obj
instance isCommMon_obj {M : C} [Mon_Class M] [IsCommMon M] : IsCommMon (F.obj M) where
mul_comm := by
dsimp; rw [← Functor.LaxBraided.braided_assoc, ← Functor.map_comp, IsCommMon.mul_comm]
variable (F) in
/-- A lax braided functor takes commutative monoid objects to commutative monoid objects.
That is, a lax braided functor `F : C ⥤ D` induces a functor `CommMon_ C ⥤ CommMon_ D`.
-/
@[simps!]
def mapCommMon : CommMon_ C ⥤ CommMon_ D where
obj A :=
{ F.mapMon.obj A.toMon_ with
comm :=
{ mul_comm := by
dsimp
rw [← Functor.LaxBraided.braided_assoc, ← Functor.map_comp, IsCommMon.mul_comm] } }
map f := F.mapMon.map f
@[simp]
theorem mapCommMon_id_one (A : CommMon_ C) :
η[((𝟭 C).mapCommMon.obj A).X] = 𝟙 _ ≫ η[A.X] :=
rfl
@[simp]
theorem mapCommMon_id_mul (A : CommMon_ C) :
μ[((𝟭 C).mapCommMon.obj A).X] = 𝟙 _ ≫ μ[A.X] :=
rfl
@[simp]
theorem comp_mapCommMon_one (A : CommMon_ C) :
η[((F ⋙ G).mapCommMon.obj A).X] = LaxMonoidal.ε (F ⋙ G) ≫ (F ⋙ G).map η[A.X] :=
rfl
@[simp]
theorem comp_mapCommMon_mul (A : CommMon_ C) :
μ[((F ⋙ G).mapCommMon.obj A).X] = LaxMonoidal.μ (F ⋙ G) _ _ ≫ (F ⋙ G).map μ[A.X] :=
rfl
/-- The identity functor is also the identity on commutative monoid objects. -/
@[simps!]
def mapCommMonIdIso : mapCommMon (𝟭 C) ≅ 𝟭 (CommMon_ C) :=
NatIso.ofComponents fun X ↦ CommMon_.mkIso (.refl _)
/-- The composition functor is also the composition on commutative monoid objects. -/
@[simps!]
def mapCommMonCompIso : (F ⋙ G).mapCommMon ≅ F.mapCommMon ⋙ G.mapCommMon :=
NatIso.ofComponents fun X ↦ CommMon_.mkIso (.refl _)
variable (C D) in
/-- `mapCommMon` is functorial in the lax braided functor. -/
@[simps]
def mapCommMonFunctor : LaxBraidedFunctor C D ⥤ CommMon_ C ⥤ CommMon_ D where
obj F := F.mapCommMon
map α := { app A := .mk' (α.hom.app A.X) }
map_comp _ _ := rfl
protected instance Faithful.mapCommMon [F.Faithful] : F.mapCommMon.Faithful where
map_injective hfg := F.mapMon.map_injective hfg
/-- Natural transformations between functors lift to monoid objects. -/
@[simps!]
def mapCommMonNatTrans (f : F ⟶ F') [NatTrans.IsMonoidal f] : F.mapCommMon ⟶ F'.mapCommMon where
app X := .mk' (f.app _)
/-- Natural isomorphisms between functors lift to monoid objects. -/
@[simps!]
def mapCommMonNatIso (e : F ≅ F') [NatTrans.IsMonoidal e.hom] : F.mapCommMon ≅ F'.mapCommMon :=
NatIso.ofComponents fun X ↦ CommMon_.mkIso (e.app _)
end LaxBraided
section Braided
variable [F.Braided]
protected instance Full.mapCommMon [F.Full] [F.Faithful] : F.mapCommMon.Full where
map_surjective := F.mapMon.map_surjective
/-- If `F : C ⥤ D` is a fully faithful monoidal functor, then `Grp(F) : Grp C ⥤ Grp D` is fully
faithful too. -/
@[simps]
protected def FullyFaithful.mapCommMon (hF : F.FullyFaithful) : F.mapCommMon.FullyFaithful where
preimage f := .mk <| hF.preimage f.hom
end Braided
end Functor
open Functor
namespace Adjunction
variable {F : C ⥤ D} {G : D ⥤ C} (a : F ⊣ G) [F.Braided] [G.LaxBraided] [a.IsMonoidal]
/-- An adjunction of braided functors lifts to an adjunction of their lifts to commutative monoid
objects. -/
@[simps] def mapCommMon : F.mapCommMon ⊣ G.mapCommMon where
unit := mapCommMonIdIso.inv ≫ mapCommMonNatTrans a.unit ≫ mapCommMonCompIso.hom
counit := mapCommMonCompIso.inv ≫ mapCommMonNatTrans a.counit ≫ mapCommMonIdIso.hom
end Adjunction
namespace Equivalence
/-- An equivalence of categories lifts to an equivalence of their commutative monoid objects. -/
@[simps]
def mapCommMon (e : C ≌ D) [e.functor.Braided] [e.inverse.Braided] [e.IsMonoidal] :
CommMon_ C ≌ CommMon_ D where
functor := e.functor.mapCommMon
inverse := e.inverse.mapCommMon
unitIso := mapCommMonIdIso.symm ≪≫ mapCommMonNatIso e.unitIso ≪≫ mapCommMonCompIso
counitIso := mapCommMonCompIso.symm ≪≫ mapCommMonNatIso e.counitIso ≪≫ mapCommMonIdIso
end CategoryTheory.Equivalence
namespace CommMon_
open CategoryTheory.LaxBraidedFunctor
namespace EquivLaxBraidedFunctorPUnit
variable (C) in
/-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/
@[simps]
def laxBraidedToCommMon : LaxBraidedFunctor (Discrete PUnit.{u + 1}) C ⥤ CommMon_ C where
obj F := (F.mapCommMon : CommMon_ _ ⥤ CommMon_ C).obj (trivial (Discrete PUnit.{u+1}))
map α := ((Functor.mapCommMonFunctor (Discrete PUnit) C).map α).app _
/-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/
@[simps!]
def commMonToLaxBraidedObj (A : CommMon_ C) :
Discrete PUnit.{u + 1} ⥤ C := (Functor.const _).obj A.X
instance (A : CommMon_ C) : (commMonToLaxBraidedObj A).LaxMonoidal where
ε := η[A.X]
«μ» _ _ := μ[A.X]
open Functor.LaxMonoidal
@[simp]
lemma commMonToLaxBraidedObj_ε (A : CommMon_ C) :
ε (commMonToLaxBraidedObj A) = η[A.X] := rfl
@[simp]
lemma commMonToLaxBraidedObj_μ (A : CommMon_ C) (X Y) :
«μ» (commMonToLaxBraidedObj A) X Y = μ[A.X] := rfl
instance (A : CommMon_ C) : (commMonToLaxBraidedObj A).LaxBraided where
variable (C)
/-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/
@[simps]
def commMonToLaxBraided : CommMon_ C ⥤ LaxBraidedFunctor (Discrete PUnit.{u + 1}) C where
obj A := LaxBraidedFunctor.of (commMonToLaxBraidedObj A)
map f :=
{ hom := { app := fun _ => f.hom }
isMonoidal := { } }
/-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/
@[simps!]
def unitIso :
𝟭 (LaxBraidedFunctor (Discrete PUnit.{u + 1}) C) ≅
laxBraidedToCommMon C ⋙ commMonToLaxBraided C :=
NatIso.ofComponents
(fun F ↦ LaxBraidedFunctor.isoOfComponents (fun _ ↦ F.mapIso (eqToIso (by ext))))
(fun f ↦ by ext ⟨⟨⟩⟩; dsimp; simp)
@[simp]
theorem counitIso_aux_one (A : CommMon_ C) :
η[((commMonToLaxBraided C ⋙ laxBraidedToCommMon C).obj A).X] = η[A.X] ≫ 𝟙 _ :=
rfl
@[simp]
theorem counitIso_aux_mul (A : CommMon_ C) :
μ[((commMonToLaxBraided C ⋙ laxBraidedToCommMon C).obj A).X] = μ[A.X] ≫ 𝟙 _ :=
rfl
/-- Implementation of `CommMon_.equivLaxBraidedFunctorPUnit`. -/
@[simps!]
def counitIso : commMonToLaxBraided C ⋙ laxBraidedToCommMon C ≅ 𝟭 (CommMon_ C) :=
NatIso.ofComponents (fun F ↦ mkIso (Iso.refl _))
end EquivLaxBraidedFunctorPUnit
open EquivLaxBraidedFunctorPUnit
/-- Commutative monoid objects in `C` are "just" braided lax monoidal functors from the trivial
braided monoidal category to `C`.
-/
@[simps]
def equivLaxBraidedFunctorPUnit : LaxBraidedFunctor (Discrete PUnit.{u + 1}) C ≌ CommMon_ C where
functor := laxBraidedToCommMon C
inverse := commMonToLaxBraided C
unitIso := unitIso C
counitIso := counitIso C
end CommMon_
|
OrderClosed.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Topology.Order.LeftRight
import Mathlib.Topology.Separation.Hausdorff
/-!
# Order-closed topologies
In this file we introduce 3 typeclass mixins that relate topology and order structures:
- `ClosedIicTopology` says that all the intervals $(-∞, a]$ (formally, `Set.Iic a`)
are closed sets;
- `ClosedIciTopology` says that all the intervals $[a, +∞)$ (formally, `Set.Ici a`)
are closed sets;
- `OrderClosedTopology` says that the set of points `(x, y)` such that `x ≤ y`
is closed in the product topology.
The last predicate implies the first two.
We prove many basic properties of such topologies.
## Main statements
This file contains the proofs of the following facts.
For exact requirements
(`OrderClosedTopology` vs `ClosedIciTopology` vs `ClosedIicTopology,
`Preorder` vs `PartialOrder` vs `LinearOrder` etc)
see their statements.
### Open / closed sets
* `isOpen_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open;
* `isOpen_Iio`, `isOpen_Ioi`, `isOpen_Ioo` : open intervals are open;
* `isClosed_le` : if `f` and `g` are continuous functions, then `{x | f x ≤ g x}` is closed;
* `isClosed_Iic`, `isClosed_Ici`, `isClosed_Icc` : closed intervals are closed;
* `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x ≤ g x}`
and `{x | f x < g x}` are included by `{x | f x = g x}`;
### Convergence and inequalities
* `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually
`f x ≤ g x`, then `a ≤ b`
* `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x ≤ b`
(resp., `b ≤ f x`), then `a ≤ b` (resp., `b ≤ a`); we also provide primed versions
that assume the inequalities to hold for all `x`.
### Min, max, `sSup` and `sInf`
* `Continuous.min`, `Continuous.max`: pointwise `min`/`max` of two continuous functions is
continuous.
* `Tendsto.min`, `Tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise
`min`/`max` tend to `min a b` and `max a b`, respectively.
-/
open Set Filter
open OrderDual (toDual)
open scoped Topology
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
/-- If `α` is a topological space and a preorder, `ClosedIicTopology α` means that `Iic a` is
closed for all `a : α`. -/
class ClosedIicTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where
/-- For any `a`, the set `(-∞, a]` is closed. -/
isClosed_Iic (a : α) : IsClosed (Iic a)
/-- If `α` is a topological space and a preorder, `ClosedIciTopology α` means that `Ici a` is
closed for all `a : α`. -/
class ClosedIciTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where
/-- For any `a`, the set `[a, +∞)` is closed. -/
isClosed_Ici (a : α) : IsClosed (Ici a)
/-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the
set of points `(x, y)` with `x ≤ y` is closed in the product space. We introduce this as a mixin.
This property is satisfied for the order topology on a linear order, but it can be satisfied more
generally, and suffices to derive many interesting properties relating order and topology. -/
class OrderClosedTopology (α : Type*) [TopologicalSpace α] [Preorder α] : Prop where
/-- The set `{ (x, y) | x ≤ y }` is a closed set. -/
isClosed_le' : IsClosed { p : α × α | p.1 ≤ p.2 }
instance [TopologicalSpace α] [h : FirstCountableTopology α] : FirstCountableTopology αᵒᵈ := h
instance [TopologicalSpace α] [h : SecondCountableTopology α] : SecondCountableTopology αᵒᵈ := h
theorem Dense.orderDual [TopologicalSpace α] {s : Set α} (hs : Dense s) :
Dense (OrderDual.ofDual ⁻¹' s) :=
hs
section General
variable [TopologicalSpace α] [Preorder α] {s : Set α}
protected lemma BddAbove.of_closure : BddAbove (closure s) → BddAbove s :=
BddAbove.mono subset_closure
protected lemma BddBelow.of_closure : BddBelow (closure s) → BddBelow s :=
BddBelow.mono subset_closure
end General
section ClosedIicTopology
section Preorder
variable [TopologicalSpace α] [Preorder α] [ClosedIicTopology α] {f : β → α} {a b : α} {s : Set α}
theorem isClosed_Iic : IsClosed (Iic a) :=
ClosedIicTopology.isClosed_Iic a
instance : ClosedIciTopology αᵒᵈ where
isClosed_Ici _ := isClosed_Iic (α := α)
@[simp]
theorem closure_Iic (a : α) : closure (Iic a) = Iic a :=
isClosed_Iic.closure_eq
theorem le_of_tendsto_of_frequently {x : Filter β} (lim : Tendsto f x (𝓝 a))
(h : ∃ᶠ c in x, f c ≤ b) : a ≤ b :=
isClosed_Iic.mem_of_frequently_of_tendsto h lim
theorem le_of_tendsto {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a))
(h : ∀ᶠ c in x, f c ≤ b) : a ≤ b :=
isClosed_Iic.mem_of_tendsto lim h
theorem le_of_tendsto' {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a))
(h : ∀ c, f c ≤ b) : a ≤ b :=
le_of_tendsto lim (Eventually.of_forall h)
@[simp] lemma upperBounds_closure (s : Set α) : upperBounds (closure s : Set α) = upperBounds s :=
ext fun a ↦ by simp_rw [mem_upperBounds_iff_subset_Iic, isClosed_Iic.closure_subset_iff]
@[simp] lemma bddAbove_closure : BddAbove (closure s) ↔ BddAbove s := by
simp_rw [BddAbove, upperBounds_closure]
protected alias ⟨_, BddAbove.closure⟩ := bddAbove_closure
@[simp]
theorem disjoint_nhds_atBot_iff : Disjoint (𝓝 a) atBot ↔ ¬IsBot a := by
constructor
· intro hd hbot
rw [hbot.atBot_eq, disjoint_principal_right] at hd
exact mem_of_mem_nhds hd le_rfl
· simp only [IsBot, not_forall]
rintro ⟨b, hb⟩
refine disjoint_of_disjoint_of_mem disjoint_compl_left ?_ (Iic_mem_atBot b)
exact isClosed_Iic.isOpen_compl.mem_nhds hb
theorem IsLUB.range_of_tendsto {F : Filter β} [F.NeBot] (hle : ∀ i, f i ≤ a)
(hlim : Tendsto f F (𝓝 a)) : IsLUB (range f) a :=
⟨forall_mem_range.mpr hle, fun _c hc ↦ le_of_tendsto' hlim fun i ↦ hc <| mem_range_self i⟩
end Preorder
section NoBotOrder
variable [Preorder α] [NoBotOrder α] [TopologicalSpace α] [ClosedIicTopology α] {a : α}
{l : Filter β} [NeBot l] {f : β → α}
theorem disjoint_nhds_atBot (a : α) : Disjoint (𝓝 a) atBot := by simp
@[simp]
theorem inf_nhds_atBot (a : α) : 𝓝 a ⊓ atBot = ⊥ := (disjoint_nhds_atBot a).eq_bot
theorem not_tendsto_nhds_of_tendsto_atBot (hf : Tendsto f l atBot) (a : α) : ¬Tendsto f l (𝓝 a) :=
hf.not_tendsto (disjoint_nhds_atBot a).symm
theorem not_tendsto_atBot_of_tendsto_nhds (hf : Tendsto f l (𝓝 a)) : ¬Tendsto f l atBot :=
hf.not_tendsto (disjoint_nhds_atBot a)
end NoBotOrder
theorem iSup_eq_of_forall_le_of_tendsto {ι : Type*} {F : Filter ι} [Filter.NeBot F]
[ConditionallyCompleteLattice α] [TopologicalSpace α] [ClosedIicTopology α]
{a : α} {f : ι → α} (hle : ∀ i, f i ≤ a) (hlim : Filter.Tendsto f F (𝓝 a)) :
⨆ i, f i = a :=
have := F.nonempty_of_neBot
(IsLUB.range_of_tendsto hle hlim).ciSup_eq
theorem iUnion_Iic_eq_Iio_of_lt_of_tendsto {ι : Type*} {F : Filter ι} [F.NeBot]
[ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [ClosedIicTopology α]
{a : α} {f : ι → α} (hlt : ∀ i, f i < a) (hlim : Tendsto f F (𝓝 a)) :
⋃ i : ι, Iic (f i) = Iio a := by
have obs : a ∉ range f := by
rw [mem_range]
rintro ⟨i, rfl⟩
exact (hlt i).false
rw [← biUnion_range, (IsLUB.range_of_tendsto (le_of_lt <| hlt ·) hlim).biUnion_Iic_eq_Iio obs]
section LinearOrder
variable [TopologicalSpace α] [LinearOrder α] [ClosedIicTopology α] [TopologicalSpace β]
{a b c : α} {f : α → β}
theorem isOpen_Ioi : IsOpen (Ioi a) := by
rw [← compl_Iic]
exact isClosed_Iic.isOpen_compl
@[simp]
theorem interior_Ioi : interior (Ioi a) = Ioi a :=
isOpen_Ioi.interior_eq
theorem Ioi_mem_nhds (h : a < b) : Ioi a ∈ 𝓝 b := IsOpen.mem_nhds isOpen_Ioi h
theorem eventually_gt_nhds (hab : b < a) : ∀ᶠ x in 𝓝 a, b < x := Ioi_mem_nhds hab
theorem Ici_mem_nhds (h : a < b) : Ici a ∈ 𝓝 b :=
mem_of_superset (Ioi_mem_nhds h) Ioi_subset_Ici_self
theorem eventually_ge_nhds (hab : b < a) : ∀ᶠ x in 𝓝 a, b ≤ x := Ici_mem_nhds hab
theorem Filter.Tendsto.eventually_const_lt {l : Filter γ} {f : γ → α} {u v : α} (hv : u < v)
(h : Filter.Tendsto f l (𝓝 v)) : ∀ᶠ a in l, u < f a :=
h.eventually <| eventually_gt_nhds hv
theorem Filter.Tendsto.eventually_const_le {l : Filter γ} {f : γ → α} {u v : α} (hv : u < v)
(h : Tendsto f l (𝓝 v)) : ∀ᶠ a in l, u ≤ f a :=
h.eventually <| eventually_ge_nhds hv
protected theorem Dense.exists_gt [NoMaxOrder α] {s : Set α} (hs : Dense s) (x : α) :
∃ y ∈ s, x < y :=
hs.exists_mem_open isOpen_Ioi (exists_gt x)
protected theorem Dense.exists_ge [NoMaxOrder α] {s : Set α} (hs : Dense s) (x : α) :
∃ y ∈ s, x ≤ y :=
(hs.exists_gt x).imp fun _ h ↦ ⟨h.1, h.2.le⟩
theorem Dense.exists_ge' {s : Set α} (hs : Dense s) (htop : ∀ x, IsTop x → x ∈ s) (x : α) :
∃ y ∈ s, x ≤ y := by
by_cases hx : IsTop x
· exact ⟨x, htop x hx, le_rfl⟩
· simp only [IsTop, not_forall, not_le] at hx
rcases hs.exists_mem_open isOpen_Ioi hx with ⟨y, hys, hy : x < y⟩
exact ⟨y, hys, hy.le⟩
/-!
### Left neighborhoods on a `ClosedIicTopology`
Limits to the left of real functions are defined in terms of neighborhoods to the left,
either open or closed, i.e., members of `𝓝[<] a` and `𝓝[≤] a`.
Here we prove that all left-neighborhoods of a point are equal,
and we prove other useful characterizations which require the stronger hypothesis `OrderTopology α`
in another file.
-/
/-!
#### Point excluded
-/
theorem Ioo_mem_nhdsLT (H : a < b) : Ioo a b ∈ 𝓝[<] b := by
simpa only [← Iio_inter_Ioi] using inter_mem_nhdsWithin _ (Ioi_mem_nhds H)
theorem Ioo_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Ioo a c ∈ 𝓝[<] b :=
mem_of_superset (Ioo_mem_nhdsLT H.1) <| Ioo_subset_Ioo_right H.2
protected theorem CovBy.nhdsLT (h : a ⋖ b) : 𝓝[<] b = ⊥ :=
empty_mem_iff_bot.mp <| h.Ioo_eq ▸ Ioo_mem_nhdsLT h.1
protected theorem PredOrder.nhdsLT [PredOrder α] : 𝓝[<] a = ⊥ := by
if h : IsMin a then simp [h.Iio_eq]
else exact (Order.pred_covBy_of_not_isMin h).nhdsLT
theorem PredOrder.nhdsGT_eq_nhdsNE [PredOrder α] (a : α) : 𝓝[>] a = 𝓝[≠] a := by
rw [← nhdsLT_sup_nhdsGT, PredOrder.nhdsLT, bot_sup_eq]
theorem PredOrder.nhdsGE_eq_nhds [PredOrder α] (a : α) : 𝓝[≥] a = 𝓝 a := by
rw [← nhdsLT_sup_nhdsGE, PredOrder.nhdsLT, bot_sup_eq]
theorem Ico_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Ico a c ∈ 𝓝[<] b :=
mem_of_superset (Ioo_mem_nhdsLT_of_mem H) Ioo_subset_Ico_self
theorem Ico_mem_nhdsLT (H : a < b) : Ico a b ∈ 𝓝[<] b := Ico_mem_nhdsLT_of_mem ⟨H, le_rfl⟩
theorem Ioc_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[<] b :=
mem_of_superset (Ioo_mem_nhdsLT_of_mem H) Ioo_subset_Ioc_self
theorem Ioc_mem_nhdsLT (H : a < b) : Ioc a b ∈ 𝓝[<] b := Ioc_mem_nhdsLT_of_mem ⟨H, le_rfl⟩
theorem Icc_mem_nhdsLT_of_mem (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[<] b :=
mem_of_superset (Ioo_mem_nhdsLT_of_mem H) Ioo_subset_Icc_self
theorem Icc_mem_nhdsLT (H : a < b) : Icc a b ∈ 𝓝[<] b := Icc_mem_nhdsLT_of_mem ⟨H, le_rfl⟩
@[simp]
theorem nhdsWithin_Ico_eq_nhdsLT (h : a < b) : 𝓝[Ico a b] b = 𝓝[<] b :=
nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ici_mem_nhds h
@[simp]
theorem nhdsWithin_Ioo_eq_nhdsLT (h : a < b) : 𝓝[Ioo a b] b = 𝓝[<] b :=
nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ioi_mem_nhds h
@[simp]
theorem continuousWithinAt_Ico_iff_Iio (h : a < b) :
ContinuousWithinAt f (Ico a b) b ↔ ContinuousWithinAt f (Iio b) b := by
simp only [ContinuousWithinAt, nhdsWithin_Ico_eq_nhdsLT h]
@[simp]
theorem continuousWithinAt_Ioo_iff_Iio (h : a < b) :
ContinuousWithinAt f (Ioo a b) b ↔ ContinuousWithinAt f (Iio b) b := by
simp only [ContinuousWithinAt, nhdsWithin_Ioo_eq_nhdsLT h]
/-!
#### Point included
-/
protected theorem CovBy.nhdsLE (H : a ⋖ b) : 𝓝[≤] b = pure b := by
rw [← Iio_insert, nhdsWithin_insert, H.nhdsLT, sup_bot_eq]
protected theorem PredOrder.nhdsLE [PredOrder α] : 𝓝[≤] b = pure b := by
rw [← Iio_insert, nhdsWithin_insert, PredOrder.nhdsLT, sup_bot_eq]
theorem Ioc_mem_nhdsLE (H : a < b) : Ioc a b ∈ 𝓝[≤] b :=
inter_mem (nhdsWithin_le_nhds <| Ioi_mem_nhds H) self_mem_nhdsWithin
theorem Ioo_mem_nhdsLE_of_mem (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[≤] b :=
mem_of_superset (Ioc_mem_nhdsLE H.1) <| Ioc_subset_Ioo_right H.2
theorem Ico_mem_nhdsLE_of_mem (H : b ∈ Ioo a c) : Ico a c ∈ 𝓝[≤] b :=
mem_of_superset (Ioo_mem_nhdsLE_of_mem H) Ioo_subset_Ico_self
theorem Ioc_mem_nhdsLE_of_mem (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[≤] b :=
mem_of_superset (Ioc_mem_nhdsLE H.1) <| Ioc_subset_Ioc_right H.2
theorem Icc_mem_nhdsLE_of_mem (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[≤] b :=
mem_of_superset (Ioc_mem_nhdsLE_of_mem H) Ioc_subset_Icc_self
theorem Icc_mem_nhdsLE (H : a < b) : Icc a b ∈ 𝓝[≤] b := Icc_mem_nhdsLE_of_mem ⟨H, le_rfl⟩
@[simp]
theorem nhdsWithin_Icc_eq_nhdsLE (h : a < b) : 𝓝[Icc a b] b = 𝓝[≤] b :=
nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ici_mem_nhds h
@[simp]
theorem nhdsWithin_Ioc_eq_nhdsLE (h : a < b) : 𝓝[Ioc a b] b = 𝓝[≤] b :=
nhdsWithin_inter_of_mem <| nhdsWithin_le_nhds <| Ioi_mem_nhds h
@[simp]
theorem continuousWithinAt_Icc_iff_Iic (h : a < b) :
ContinuousWithinAt f (Icc a b) b ↔ ContinuousWithinAt f (Iic b) b := by
simp only [ContinuousWithinAt, nhdsWithin_Icc_eq_nhdsLE h]
@[simp]
theorem continuousWithinAt_Ioc_iff_Iic (h : a < b) :
ContinuousWithinAt f (Ioc a b) b ↔ ContinuousWithinAt f (Iic b) b := by
simp only [ContinuousWithinAt, nhdsWithin_Ioc_eq_nhdsLE h]
end LinearOrder
end ClosedIicTopology
section ClosedIciTopology
section Preorder
variable [TopologicalSpace α] [Preorder α] [ClosedIciTopology α] {f : β → α} {a b : α} {s : Set α}
theorem isClosed_Ici {a : α} : IsClosed (Ici a) :=
ClosedIciTopology.isClosed_Ici a
instance : ClosedIicTopology αᵒᵈ where
isClosed_Iic _ := isClosed_Ici (α := α)
@[simp]
theorem closure_Ici (a : α) : closure (Ici a) = Ici a :=
isClosed_Ici.closure_eq
lemma ge_of_tendsto_of_frequently {x : Filter β} (lim : Tendsto f x (𝓝 a))
(h : ∃ᶠ c in x, b ≤ f c) : b ≤ a :=
isClosed_Ici.mem_of_frequently_of_tendsto h lim
theorem ge_of_tendsto {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a))
(h : ∀ᶠ c in x, b ≤ f c) : b ≤ a :=
isClosed_Ici.mem_of_tendsto lim h
theorem ge_of_tendsto' {x : Filter β} [NeBot x] (lim : Tendsto f x (𝓝 a))
(h : ∀ c, b ≤ f c) : b ≤ a :=
ge_of_tendsto lim (Eventually.of_forall h)
@[simp] lemma lowerBounds_closure (s : Set α) : lowerBounds (closure s : Set α) = lowerBounds s :=
ext fun a ↦ by simp_rw [mem_lowerBounds_iff_subset_Ici, isClosed_Ici.closure_subset_iff]
@[simp] lemma bddBelow_closure : BddBelow (closure s) ↔ BddBelow s := by
simp_rw [BddBelow, lowerBounds_closure]
protected alias ⟨_, BddBelow.closure⟩ := bddBelow_closure
@[simp]
theorem disjoint_nhds_atTop_iff : Disjoint (𝓝 a) atTop ↔ ¬IsTop a :=
disjoint_nhds_atBot_iff (α := αᵒᵈ)
theorem IsGLB.range_of_tendsto {F : Filter β} [F.NeBot] (hle : ∀ i, a ≤ f i)
(hlim : Tendsto f F (𝓝 a)) : IsGLB (range f) a :=
IsLUB.range_of_tendsto (α := αᵒᵈ) hle hlim
end Preorder
section NoTopOrder
variable [Preorder α] [NoTopOrder α] [TopologicalSpace α] [ClosedIciTopology α] {a : α}
{l : Filter β} [NeBot l] {f : β → α}
theorem disjoint_nhds_atTop (a : α) : Disjoint (𝓝 a) atTop := disjoint_nhds_atBot (toDual a)
@[simp]
theorem inf_nhds_atTop (a : α) : 𝓝 a ⊓ atTop = ⊥ := (disjoint_nhds_atTop a).eq_bot
theorem not_tendsto_nhds_of_tendsto_atTop (hf : Tendsto f l atTop) (a : α) : ¬Tendsto f l (𝓝 a) :=
hf.not_tendsto (disjoint_nhds_atTop a).symm
theorem not_tendsto_atTop_of_tendsto_nhds (hf : Tendsto f l (𝓝 a)) : ¬Tendsto f l atTop :=
hf.not_tendsto (disjoint_nhds_atTop a)
end NoTopOrder
theorem iInf_eq_of_forall_le_of_tendsto {ι : Type*} {F : Filter ι} [F.NeBot]
[ConditionallyCompleteLattice α] [TopologicalSpace α] [ClosedIciTopology α]
{a : α} {f : ι → α} (hle : ∀ i, a ≤ f i) (hlim : Tendsto f F (𝓝 a)) :
⨅ i, f i = a :=
iSup_eq_of_forall_le_of_tendsto (α := αᵒᵈ) hle hlim
theorem iUnion_Ici_eq_Ioi_of_lt_of_tendsto {ι : Type*} {F : Filter ι} [F.NeBot]
[ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [ClosedIciTopology α]
{a : α} {f : ι → α} (hlt : ∀ i, a < f i) (hlim : Tendsto f F (𝓝 a)) :
⋃ i : ι, Ici (f i) = Ioi a :=
iUnion_Iic_eq_Iio_of_lt_of_tendsto (α := αᵒᵈ) hlt hlim
section LinearOrder
variable [TopologicalSpace α] [LinearOrder α] [ClosedIciTopology α] [TopologicalSpace β]
{a b c : α} {f : α → β}
theorem isOpen_Iio : IsOpen (Iio a) := isOpen_Ioi (α := αᵒᵈ)
@[simp] theorem interior_Iio : interior (Iio a) = Iio a := isOpen_Iio.interior_eq
theorem Iio_mem_nhds (h : a < b) : Iio b ∈ 𝓝 a := isOpen_Iio.mem_nhds h
theorem eventually_lt_nhds (hab : a < b) : ∀ᶠ x in 𝓝 a, x < b := Iio_mem_nhds hab
theorem Iic_mem_nhds (h : a < b) : Iic b ∈ 𝓝 a :=
mem_of_superset (Iio_mem_nhds h) Iio_subset_Iic_self
theorem eventually_le_nhds (hab : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := Iic_mem_nhds hab
theorem Filter.Tendsto.eventually_lt_const {l : Filter γ} {f : γ → α} {u v : α} (hv : v < u)
(h : Filter.Tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a < u :=
h.eventually <| eventually_lt_nhds hv
theorem Filter.Tendsto.eventually_le_const {l : Filter γ} {f : γ → α} {u v : α} (hv : v < u)
(h : Tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a ≤ u :=
h.eventually <| eventually_le_nhds hv
protected theorem Dense.exists_lt [NoMinOrder α] {s : Set α} (hs : Dense s) (x : α) :
∃ y ∈ s, y < x :=
hs.orderDual.exists_gt x
protected theorem Dense.exists_le [NoMinOrder α] {s : Set α} (hs : Dense s) (x : α) :
∃ y ∈ s, y ≤ x :=
hs.orderDual.exists_ge x
theorem Dense.exists_le' {s : Set α} (hs : Dense s) (hbot : ∀ x, IsBot x → x ∈ s) (x : α) :
∃ y ∈ s, y ≤ x :=
hs.orderDual.exists_ge' hbot x
/-!
### Right neighborhoods on a `ClosedIciTopology`
Limits to the right of real functions are defined in terms of neighborhoods to the right,
either open or closed, i.e., members of `𝓝[>] a` and `𝓝[≥] a`.
Here we prove that all right-neighborhoods of a point are equal,
and we prove other useful characterizations which require the stronger hypothesis `OrderTopology α`
in another file.
-/
/-!
#### Point excluded
-/
theorem Ioo_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Ioo a c ∈ 𝓝[>] b :=
mem_nhdsWithin.2
⟨Iio c, isOpen_Iio, H.2, by rw [inter_comm, Ioi_inter_Iio]; exact Ioo_subset_Ioo_left H.1⟩
theorem Ioo_mem_nhdsGT (H : a < b) : Ioo a b ∈ 𝓝[>] a := Ioo_mem_nhdsGT_of_mem ⟨le_rfl, H⟩
protected theorem CovBy.nhdsGT (h : a ⋖ b) : 𝓝[>] a = ⊥ := h.toDual.nhdsLT
protected theorem SuccOrder.nhdsGT [SuccOrder α] : 𝓝[>] a = ⊥ := PredOrder.nhdsLT (α := αᵒᵈ)
theorem SuccOrder.nhdsLT_eq_nhdsNE [SuccOrder α] (a : α) : 𝓝[<] a = 𝓝[≠] a :=
PredOrder.nhdsGT_eq_nhdsNE (α := αᵒᵈ) a
theorem SuccOrder.nhdsLE_eq_nhds [SuccOrder α] (a : α) : 𝓝[≤] a = 𝓝 a :=
PredOrder.nhdsGE_eq_nhds (α := αᵒᵈ) a
theorem Ioc_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Ioc a c ∈ 𝓝[>] b :=
mem_of_superset (Ioo_mem_nhdsGT_of_mem H) Ioo_subset_Ioc_self
theorem Ioc_mem_nhdsGT (H : a < b) : Ioc a b ∈ 𝓝[>] a := Ioc_mem_nhdsGT_of_mem ⟨le_rfl, H⟩
theorem Ico_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[>] b :=
mem_of_superset (Ioo_mem_nhdsGT_of_mem H) Ioo_subset_Ico_self
theorem Ico_mem_nhdsGT (H : a < b) : Ico a b ∈ 𝓝[>] a := Ico_mem_nhdsGT_of_mem ⟨le_rfl, H⟩
theorem Icc_mem_nhdsGT_of_mem (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[>] b :=
mem_of_superset (Ioo_mem_nhdsGT_of_mem H) Ioo_subset_Icc_self
theorem Icc_mem_nhdsGT (H : a < b) : Icc a b ∈ 𝓝[>] a := Icc_mem_nhdsGT_of_mem ⟨le_rfl, H⟩
@[simp]
theorem nhdsWithin_Ioc_eq_nhdsGT (h : a < b) : 𝓝[Ioc a b] a = 𝓝[>] a :=
nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iic_mem_nhds h
@[simp]
theorem nhdsWithin_Ioo_eq_nhdsGT (h : a < b) : 𝓝[Ioo a b] a = 𝓝[>] a :=
nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iio_mem_nhds h
@[simp]
theorem continuousWithinAt_Ioc_iff_Ioi (h : a < b) :
ContinuousWithinAt f (Ioc a b) a ↔ ContinuousWithinAt f (Ioi a) a := by
simp only [ContinuousWithinAt, nhdsWithin_Ioc_eq_nhdsGT h]
@[simp]
theorem continuousWithinAt_Ioo_iff_Ioi (h : a < b) :
ContinuousWithinAt f (Ioo a b) a ↔ ContinuousWithinAt f (Ioi a) a := by
simp only [ContinuousWithinAt, nhdsWithin_Ioo_eq_nhdsGT h]
/-!
### Point included
-/
protected theorem CovBy.nhdsGE (H : a ⋖ b) : 𝓝[≥] a = pure a := H.toDual.nhdsLE
protected theorem SuccOrder.nhdsGE [SuccOrder α] : 𝓝[≥] a = pure a :=
PredOrder.nhdsLE (α := αᵒᵈ)
theorem Ico_mem_nhdsGE (H : a < b) : Ico a b ∈ 𝓝[≥] a :=
inter_mem_nhdsWithin _ <| Iio_mem_nhds H
theorem Ico_mem_nhdsGE_of_mem (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[≥] b :=
mem_of_superset (Ico_mem_nhdsGE H.2) <| Ico_subset_Ico_left H.1
theorem Ioo_mem_nhdsGE_of_mem (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[≥] b :=
mem_of_superset (Ico_mem_nhdsGE H.2) <| Ico_subset_Ioo_left H.1
theorem Ioc_mem_nhdsGE_of_mem (H : b ∈ Ioo a c) : Ioc a c ∈ 𝓝[≥] b :=
mem_of_superset (Ioo_mem_nhdsGE_of_mem H) Ioo_subset_Ioc_self
theorem Icc_mem_nhdsGE_of_mem (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[≥] b :=
mem_of_superset (Ico_mem_nhdsGE_of_mem H) Ico_subset_Icc_self
theorem Icc_mem_nhdsGE (H : a < b) : Icc a b ∈ 𝓝[≥] a := Icc_mem_nhdsGE_of_mem ⟨le_rfl, H⟩
@[simp]
theorem nhdsWithin_Icc_eq_nhdsGE (h : a < b) : 𝓝[Icc a b] a = 𝓝[≥] a :=
nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iic_mem_nhds h
@[simp]
theorem nhdsWithin_Ico_eq_nhdsGE (h : a < b) : 𝓝[Ico a b] a = 𝓝[≥] a :=
nhdsWithin_inter_of_mem' <| nhdsWithin_le_nhds <| Iio_mem_nhds h
@[simp]
theorem continuousWithinAt_Icc_iff_Ici (h : a < b) :
ContinuousWithinAt f (Icc a b) a ↔ ContinuousWithinAt f (Ici a) a := by
simp only [ContinuousWithinAt, nhdsWithin_Icc_eq_nhdsGE h]
@[simp]
theorem continuousWithinAt_Ico_iff_Ici (h : a < b) :
ContinuousWithinAt f (Ico a b) a ↔ ContinuousWithinAt f (Ici a) a := by
simp only [ContinuousWithinAt, nhdsWithin_Ico_eq_nhdsGE h]
end LinearOrder
end ClosedIciTopology
section OrderClosedTopology
section Preorder
variable [TopologicalSpace α] [Preorder α] [t : OrderClosedTopology α]
namespace Subtype
-- todo: add `OrderEmbedding.orderClosedTopology`
instance {p : α → Prop} : OrderClosedTopology (Subtype p) :=
have this : Continuous fun p : Subtype p × Subtype p => ((p.fst : α), (p.snd : α)) :=
continuous_subtype_val.prodMap continuous_subtype_val
OrderClosedTopology.mk (t.isClosed_le'.preimage this)
end Subtype
theorem isClosed_le_prod : IsClosed { p : α × α | p.1 ≤ p.2 } :=
t.isClosed_le'
theorem isClosed_le [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) :
IsClosed { b | f b ≤ g b } :=
continuous_iff_isClosed.mp (hf.prodMk hg) _ isClosed_le_prod
instance : ClosedIicTopology α where
isClosed_Iic _ := isClosed_le continuous_id continuous_const
instance : ClosedIciTopology α where
isClosed_Ici _ := isClosed_le continuous_const continuous_id
instance : OrderClosedTopology αᵒᵈ :=
⟨(OrderClosedTopology.isClosed_le' (α := α)).preimage continuous_swap⟩
theorem isClosed_Icc {a b : α} : IsClosed (Icc a b) :=
IsClosed.inter isClosed_Ici isClosed_Iic
@[simp]
theorem closure_Icc (a b : α) : closure (Icc a b) = Icc a b :=
isClosed_Icc.closure_eq
theorem le_of_tendsto_of_tendsto_of_frequently {f g : β → α} {b : Filter β} {a₁ a₂ : α}
(hf : Tendsto f b (𝓝 a₁)) (hg : Tendsto g b (𝓝 a₂)) (h : ∃ᶠ x in b, f x ≤ g x) : a₁ ≤ a₂ :=
t.isClosed_le'.mem_of_frequently_of_tendsto h (hf.prodMk_nhds hg)
theorem le_of_tendsto_of_tendsto {f g : β → α} {b : Filter β} {a₁ a₂ : α} [NeBot b]
(hf : Tendsto f b (𝓝 a₁)) (hg : Tendsto g b (𝓝 a₂)) (h : f ≤ᶠ[b] g) : a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto_of_frequently hf hg <| Eventually.frequently h
alias tendsto_le_of_eventuallyLE := le_of_tendsto_of_tendsto
theorem le_of_tendsto_of_tendsto' {f g : β → α} {b : Filter β} {a₁ a₂ : α} [NeBot b]
(hf : Tendsto f b (𝓝 a₁)) (hg : Tendsto g b (𝓝 a₂)) (h : ∀ x, f x ≤ g x) : a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto hf hg (Eventually.of_forall h)
@[simp]
theorem closure_le_eq [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) :
closure { b | f b ≤ g b } = { b | f b ≤ g b } :=
(isClosed_le hf hg).closure_eq
theorem closure_lt_subset_le [TopologicalSpace β] {f g : β → α} (hf : Continuous f)
(hg : Continuous g) : closure { b | f b < g b } ⊆ { b | f b ≤ g b } :=
(closure_minimal fun _ => le_of_lt) <| isClosed_le hf hg
theorem ContinuousWithinAt.closure_le [TopologicalSpace β] {f g : β → α} {s : Set β} {x : β}
(hx : x ∈ closure s) (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x)
(h : ∀ y ∈ s, f y ≤ g y) : f x ≤ g x :=
show (f x, g x) ∈ { p : α × α | p.1 ≤ p.2 } from
OrderClosedTopology.isClosed_le'.closure_subset ((hf.prodMk hg).mem_closure hx h)
/-- If `s` is a closed set and two functions `f` and `g` are continuous on `s`,
then the set `{x ∈ s | f x ≤ g x}` is a closed set. -/
theorem IsClosed.isClosed_le [TopologicalSpace β] {f g : β → α} {s : Set β} (hs : IsClosed s)
(hf : ContinuousOn f s) (hg : ContinuousOn g s) : IsClosed ({ x ∈ s | f x ≤ g x }) :=
(hf.prodMk hg).preimage_isClosed_of_isClosed hs OrderClosedTopology.isClosed_le'
theorem le_on_closure [TopologicalSpace β] {f g : β → α} {s : Set β} (h : ∀ x ∈ s, f x ≤ g x)
(hf : ContinuousOn f (closure s)) (hg : ContinuousOn g (closure s)) ⦃x⦄ (hx : x ∈ closure s) :
f x ≤ g x :=
have : s ⊆ { y ∈ closure s | f y ≤ g y } := fun y hy => ⟨subset_closure hy, h y hy⟩
(closure_minimal this (isClosed_closure.isClosed_le hf hg) hx).2
theorem IsClosed.epigraph [TopologicalSpace β] {f : β → α} {s : Set β} (hs : IsClosed s)
(hf : ContinuousOn f s) : IsClosed { p : β × α | p.1 ∈ s ∧ f p.1 ≤ p.2 } :=
(hs.preimage continuous_fst).isClosed_le (hf.comp continuousOn_fst Subset.rfl) continuousOn_snd
theorem IsClosed.hypograph [TopologicalSpace β] {f : β → α} {s : Set β} (hs : IsClosed s)
(hf : ContinuousOn f s) : IsClosed { p : β × α | p.1 ∈ s ∧ p.2 ≤ f p.1 } :=
(hs.preimage continuous_fst).isClosed_le continuousOn_snd (hf.comp continuousOn_fst Subset.rfl)
/-- The set of monotone functions on a set is closed. -/
theorem isClosed_monotoneOn [Preorder β] {s : Set β} : IsClosed {f : β → α | MonotoneOn f s} := by
simp only [isClosed_iff_clusterPt, clusterPt_principal_iff_frequently]
intro g hg a ha b hb hab
have hmain (x) : Tendsto (fun f' ↦ f' x) (𝓝 g) (𝓝 (g x)) := continuousAt_apply x _
exact le_of_tendsto_of_tendsto_of_frequently (hmain a) (hmain b) (hg.mono fun g h ↦ h ha hb hab)
/-- The set of monotone functions is closed. -/
theorem isClosed_monotone [Preorder β] : IsClosed {f : β → α | Monotone f} := by
simp_rw [← monotoneOn_univ]
exact isClosed_monotoneOn
/-- The set of antitone functions on a set is closed. -/
theorem isClosed_antitoneOn [Preorder β] {s : Set β} : IsClosed {f : β → α | AntitoneOn f s} :=
isClosed_monotoneOn (α := αᵒᵈ) (β := β)
/-- The set of antitone functions is closed. -/
theorem isClosed_antitone [Preorder β] : IsClosed {f : β → α | Antitone f} :=
isClosed_monotone (α := αᵒᵈ) (β := β)
end Preorder
section PartialOrder
variable [TopologicalSpace α] [PartialOrder α] [t : OrderClosedTopology α]
-- see Note [lower instance priority]
instance (priority := 90) OrderClosedTopology.to_t2Space : T2Space α :=
t2_iff_isClosed_diagonal.2 <| by
simpa only [diagonal, le_antisymm_iff] using
t.isClosed_le'.inter (isClosed_le continuous_snd continuous_fst)
end PartialOrder
section LinearOrder
variable [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α]
theorem isOpen_lt [TopologicalSpace β] {f g : β → α} (hf : Continuous f) (hg : Continuous g) :
IsOpen { b | f b < g b } := by
simpa only [lt_iff_not_ge] using (isClosed_le hg hf).isOpen_compl
theorem isOpen_lt_prod : IsOpen { p : α × α | p.1 < p.2 } :=
isOpen_lt continuous_fst continuous_snd
variable {a b : α}
theorem isOpen_Ioo : IsOpen (Ioo a b) :=
IsOpen.inter isOpen_Ioi isOpen_Iio
@[simp]
theorem interior_Ioo : interior (Ioo a b) = Ioo a b :=
isOpen_Ioo.interior_eq
theorem Ioo_subset_closure_interior : Ioo a b ⊆ closure (interior (Ioo a b)) := by
simp only [interior_Ioo, subset_closure]
theorem Ioo_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioo a b ∈ 𝓝 x :=
IsOpen.mem_nhds isOpen_Ioo ⟨ha, hb⟩
theorem Ioc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioc a b ∈ 𝓝 x :=
mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ioc_self
theorem Ico_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ico a b ∈ 𝓝 x :=
mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ico_self
theorem Icc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Icc a b ∈ 𝓝 x :=
mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Icc_self
/-- The only order closed topology on a linear order which is a `PredOrder` and a `SuccOrder`
is the discrete topology.
This theorem is not an instance,
because it causes searches for `PredOrder` and `SuccOrder` with their `Preorder` arguments
and very rarely matches. -/
theorem DiscreteTopology.of_predOrder_succOrder [PredOrder α] [SuccOrder α] :
DiscreteTopology α := by
refine discreteTopology_iff_nhds.mpr fun a ↦ ?_
rw [← nhdsWithin_univ, ← Iic_union_Ioi, nhdsWithin_union, PredOrder.nhdsLE, SuccOrder.nhdsGT,
sup_bot_eq]
end LinearOrder
section LinearOrder
variable [TopologicalSpace α] [LinearOrder α] [OrderClosedTopology α] {f g : β → α}
section
variable [TopologicalSpace β]
theorem lt_subset_interior_le (hf : Continuous f) (hg : Continuous g) :
{ b | f b < g b } ⊆ interior { b | f b ≤ g b } :=
(interior_maximal fun _ => le_of_lt) <| isOpen_lt hf hg
theorem frontier_le_subset_eq (hf : Continuous f) (hg : Continuous g) :
frontier { b | f b ≤ g b } ⊆ { b | f b = g b } := by
rw [frontier_eq_closure_inter_closure, closure_le_eq hf hg]
rintro b ⟨hb₁, hb₂⟩
refine le_antisymm hb₁ (closure_lt_subset_le hg hf ?_)
convert hb₂ using 2; simp only [not_le.symm]; rfl
theorem frontier_Iic_subset (a : α) : frontier (Iic a) ⊆ {a} :=
frontier_le_subset_eq (@continuous_id α _) continuous_const
theorem frontier_Ici_subset (a : α) : frontier (Ici a) ⊆ {a} :=
frontier_Iic_subset (α := αᵒᵈ) _
theorem frontier_lt_subset_eq (hf : Continuous f) (hg : Continuous g) :
frontier { b | f b < g b } ⊆ { b | f b = g b } := by
simpa only [← not_lt, ← compl_setOf, frontier_compl, eq_comm] using frontier_le_subset_eq hg hf
theorem continuous_if_le [TopologicalSpace γ] [∀ x, Decidable (f x ≤ g x)] {f' g' : β → γ}
(hf : Continuous f) (hg : Continuous g) (hf' : ContinuousOn f' { x | f x ≤ g x })
(hg' : ContinuousOn g' { x | g x ≤ f x }) (hfg : ∀ x, f x = g x → f' x = g' x) :
Continuous fun x => if f x ≤ g x then f' x else g' x := by
refine continuous_if (fun a ha => hfg _ (frontier_le_subset_eq hf hg ha)) ?_ (hg'.mono ?_)
· rwa [(isClosed_le hf hg).closure_eq]
· simp only [not_le]
exact closure_lt_subset_le hg hf
theorem Continuous.if_le [TopologicalSpace γ] [∀ x, Decidable (f x ≤ g x)] {f' g' : β → γ}
(hf' : Continuous f') (hg' : Continuous g') (hf : Continuous f) (hg : Continuous g)
(hfg : ∀ x, f x = g x → f' x = g' x) : Continuous fun x => if f x ≤ g x then f' x else g' x :=
continuous_if_le hf hg hf'.continuousOn hg'.continuousOn hfg
theorem Filter.Tendsto.eventually_lt {l : Filter γ} {f g : γ → α} {y z : α} (hf : Tendsto f l (𝓝 y))
(hg : Tendsto g l (𝓝 z)) (hyz : y < z) : ∀ᶠ x in l, f x < g x :=
let ⟨_a, ha, _b, hb, h⟩ := hyz.exists_disjoint_Iio_Ioi
(hg.eventually (Ioi_mem_nhds hb)).mp <| (hf.eventually (Iio_mem_nhds ha)).mono fun _ h₁ h₂ =>
h _ h₁ _ h₂
nonrec theorem ContinuousAt.eventually_lt {x₀ : β} (hf : ContinuousAt f x₀) (hg : ContinuousAt g x₀)
(hfg : f x₀ < g x₀) : ∀ᶠ x in 𝓝 x₀, f x < g x :=
hf.eventually_lt hg hfg
@[continuity, fun_prop]
protected theorem Continuous.min (hf : Continuous f) (hg : Continuous g) :
Continuous fun b => min (f b) (g b) := by
simp only [min_def]
exact hf.if_le hg hf hg fun x => id
@[continuity, fun_prop]
protected theorem Continuous.max (hf : Continuous f) (hg : Continuous g) :
Continuous fun b => max (f b) (g b) :=
Continuous.min (α := αᵒᵈ) hf hg
end
theorem continuous_min : Continuous fun p : α × α => min p.1 p.2 :=
continuous_fst.min continuous_snd
theorem continuous_max : Continuous fun p : α × α => max p.1 p.2 :=
continuous_fst.max continuous_snd
protected theorem Filter.Tendsto.max {b : Filter β} {a₁ a₂ : α} (hf : Tendsto f b (𝓝 a₁))
(hg : Tendsto g b (𝓝 a₂)) : Tendsto (fun b => max (f b) (g b)) b (𝓝 (max a₁ a₂)) :=
(continuous_max.tendsto (a₁, a₂)).comp (hf.prodMk_nhds hg)
protected theorem Filter.Tendsto.min {b : Filter β} {a₁ a₂ : α} (hf : Tendsto f b (𝓝 a₁))
(hg : Tendsto g b (𝓝 a₂)) : Tendsto (fun b => min (f b) (g b)) b (𝓝 (min a₁ a₂)) :=
(continuous_min.tendsto (a₁, a₂)).comp (hf.prodMk_nhds hg)
protected theorem Filter.Tendsto.max_right {l : Filter β} {a : α} (h : Tendsto f l (𝓝 a)) :
Tendsto (fun i => max a (f i)) l (𝓝 a) := by
simpa only [sup_idem] using (tendsto_const_nhds (x := a)).max h
protected theorem Filter.Tendsto.max_left {l : Filter β} {a : α} (h : Tendsto f l (𝓝 a)) :
Tendsto (fun i => max (f i) a) l (𝓝 a) := by
simp_rw [max_comm _ a]
exact h.max_right
theorem Filter.tendsto_nhds_max_right {l : Filter β} {a : α} (h : Tendsto f l (𝓝[>] a)) :
Tendsto (fun i => max a (f i)) l (𝓝[>] a) := by
obtain ⟨h₁ : Tendsto f l (𝓝 a), h₂ : ∀ᶠ i in l, f i ∈ Ioi a⟩ := tendsto_nhdsWithin_iff.mp h
exact tendsto_nhdsWithin_iff.mpr ⟨h₁.max_right, h₂.mono fun i hi => lt_max_of_lt_right hi⟩
theorem Filter.tendsto_nhds_max_left {l : Filter β} {a : α} (h : Tendsto f l (𝓝[>] a)) :
Tendsto (fun i => max (f i) a) l (𝓝[>] a) := by
simp_rw [max_comm _ a]
exact Filter.tendsto_nhds_max_right h
theorem Filter.Tendsto.min_right {l : Filter β} {a : α} (h : Tendsto f l (𝓝 a)) :
Tendsto (fun i => min a (f i)) l (𝓝 a) :=
Filter.Tendsto.max_right (α := αᵒᵈ) h
theorem Filter.Tendsto.min_left {l : Filter β} {a : α} (h : Tendsto f l (𝓝 a)) :
Tendsto (fun i => min (f i) a) l (𝓝 a) :=
Filter.Tendsto.max_left (α := αᵒᵈ) h
theorem Filter.tendsto_nhds_min_right {l : Filter β} {a : α} (h : Tendsto f l (𝓝[<] a)) :
Tendsto (fun i => min a (f i)) l (𝓝[<] a) :=
Filter.tendsto_nhds_max_right (α := αᵒᵈ) h
theorem Filter.tendsto_nhds_min_left {l : Filter β} {a : α} (h : Tendsto f l (𝓝[<] a)) :
Tendsto (fun i => min (f i) a) l (𝓝[<] a) :=
Filter.tendsto_nhds_max_left (α := αᵒᵈ) h
theorem Dense.exists_between [DenselyOrdered α] {s : Set α} (hs : Dense s) {x y : α} (h : x < y) :
∃ z ∈ s, z ∈ Ioo x y :=
hs.exists_mem_open isOpen_Ioo (nonempty_Ioo.2 h)
theorem Dense.Ioi_eq_biUnion [DenselyOrdered α] {s : Set α} (hs : Dense s) (x : α) :
Ioi x = ⋃ y ∈ s ∩ Ioi x, Ioi y := by
refine Subset.antisymm (fun z hz ↦ ?_) (iUnion₂_subset fun y hy ↦ Ioi_subset_Ioi (le_of_lt hy.2))
rcases hs.exists_between hz with ⟨y, hys, hxy, hyz⟩
exact mem_iUnion₂.2 ⟨y, ⟨hys, hxy⟩, hyz⟩
theorem Dense.Iio_eq_biUnion [DenselyOrdered α] {s : Set α} (hs : Dense s) (x : α) :
Iio x = ⋃ y ∈ s ∩ Iio x, Iio y :=
Dense.Ioi_eq_biUnion (α := αᵒᵈ) hs x
end LinearOrder
end OrderClosedTopology
instance [Preorder α] [TopologicalSpace α] [OrderClosedTopology α] [Preorder β] [TopologicalSpace β]
[OrderClosedTopology β] : OrderClosedTopology (α × β) :=
⟨(isClosed_le continuous_fst.fst continuous_snd.fst).inter
(isClosed_le continuous_fst.snd continuous_snd.snd)⟩
instance {ι : Type*} {α : ι → Type*} [∀ i, Preorder (α i)] [∀ i, TopologicalSpace (α i)]
[∀ i, OrderClosedTopology (α i)] : OrderClosedTopology (∀ i, α i) := by
constructor
simp only [Pi.le_def, setOf_forall]
exact isClosed_iInter fun i => isClosed_le (continuous_apply i).fst' (continuous_apply i).snd'
instance Pi.orderClosedTopology' [Preorder β] [TopologicalSpace β] [OrderClosedTopology β] :
OrderClosedTopology (α → β) :=
inferInstance
|
order.v
|
(* (c) Copyright 2006-2019 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 path fintype tuple bigop finset div prime finfun.
From mathcomp Require Import finset.
From mathcomp Require Export preorder.
(******************************************************************************)
(* Types equipped with order relations *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This files defines types equipped with order relations. *)
(* *)
(* * How to use orders in MathComp? *)
(* Use one of the following modules implementing different theories (all *)
(* located in the module Order): *)
(* Order.LTheory: partially ordered types and lattices excluding complement *)
(* and totality related theorems *)
(* Order.CTheory: complemented lattices including Order.LTheory *)
(* Order.TTheory: totally ordered types including Order.LTheory *)
(* Order.Theory: ordered types including all of the above theory modules *)
(* To access the definitions, notations, and the theory from, say, *)
(* "Order.Xyz", insert "Import Order.Xyz." at the top of your scripts. You can*)
(* also "Import Order.Def." to enjoy shorter notations (e.g., min instead of *)
(* Order.min, nondecreasing instead of Order.nondecreasing, etc.). *)
(* *)
(* In order to reason about abstract orders, notations are accessible by *)
(* opening the scope "order_scope" bound to the delimiting key "O"; however, *)
(* when dealing with another notation scope providing order notations for *)
(* a concrete instance (e.g., "ring_scope"), it is not recommended to open *)
(* "order_scope" at the same time. *)
(* *)
(* * Control of inference (parsing) and printing *)
(* One characteristic of ordered types is that one carrier type may have *)
(* several orders. For example, natural numbers can be totally or partially *)
(* ordered by the less than or equal relation, the divisibility relation, and *)
(* their dual relations. Therefore, we need a way to control inference of *)
(* ordered type instances and printing of generic relations and operations on *)
(* ordered types. As a rule of thumb, we use the carrier type or its "alias" *)
(* (named copy) to control inference (using canonical structures), and use a *)
(* "display" to control the printing of notations. *)
(* *)
(* Each generic interface and operation for ordered types has, as its first *)
(* argument, a "display" of type Order.disp_t. For example, the less than or *)
(* equal relation has type: *)
(* Order.le : forall {d : Order.disp_t} {T : porderType d}, rel T, *)
(* where porderType d is the structure of partially ordered types with *)
(* display d. (@Order.le dvd_display _ m n) is printed as m %| n because *)
(* ordered type instances associated to the display dvd_display is intended *)
(* to represent natural numbers partially ordered by the divisibility *)
(* relation. *)
(* *)
(* We stress that order structure inference can be triggered only from the *)
(* carrier type (or its alias), but not the display. For example, writing *)
(* m %| n for m and n of type nat does not trigger an inference of the *)
(* divisibility relation on natural numbers, which is associated to an alias *)
(* natdvd for nat; such an inference should be triggered through the use of *)
(* the corresponding alias, i.e., (m : natdvd) %| n. In other words, displays *)
(* are merely used to inform the user and the notation mechanism of what the *)
(* inference did; they are not additional input for the inference. *)
(* *)
(* See below for various aliases and their associated displays. *)
(* *)
(* NB: algebra/ssrnum.v provides the display ring_display to change the *)
(* scope of the usual notations to ring_scope. *)
(* *)
(* Instantiating d with Disp tt tt or an unknown display will lead to a *)
(* default display for notations. *)
(* *)
(* Alternative notation displays can be defined by : *)
(* 1. declaring a new opaque definition of type unit. Using the idiom *)
(* `Fact my_display : Order.disp_t. Proof. exact: Disp tt tt. Qed.` *)
(* 2. using this symbol to tag canonical porderType structures using *)
(* `HB.instance Definition _ := isPOrder.Build my_display my_type ...`, *)
(* 3. declaring notations for the main operations of this library, by *)
(* setting the first argument of the definition to the display, e.g. *)
(* `Notation my_syndef_le x y := @Order.le my_display _ x y.` or *)
(* `Notation "x <=< y" := @Order.lt my_display _ x y (at level ...).` *)
(* Non overloaded notations will default to the default display. *)
(* We suggest the user to refer to the example of natdvd below as a guideline *)
(* example to add their own displays. *)
(* *)
(* * Interfaces *)
(* We provide the following interfaces for types equipped with an order: *)
(* *)
(* porderType d == the type of partially ordered types *)
(* The HB class is called POrder. *)
(* bPOrderType d == porderType with a bottom element (\bot) *)
(* The HB class is called BPOrder. *)
(* tPOrderType d == porderType with a top element (\top) *)
(* The HB class is called TPOrder. *)
(* tbPOrderType d == porderType with both a top and a bottom *)
(* The HB class is called TBPOrder. *)
(* meetSemilatticeType d == the type of meet semilattices *)
(* The HB class is called MeetSemilattice. *)
(* bMeetSemilatticeType d == meetSemilatticeType with a bottom element *)
(* The HB class is called BMeetSemilattice. *)
(* tMeetSemilatticeType d == meetSemilatticeType with a top element *)
(* The HB class is called TMeetSemilattice. *)
(* tbMeetSemilatticeType d == meetSemilatticeType with both a top and a *)
(* bottom *)
(* The HB class is called TBMeetSemilattice. *)
(* joinSemilatticeType d == the type of join semilattices *)
(* The HB class is called JoinSemilattice. *)
(* bJoinSemilatticeType d == joinSemilatticeType with a bottom element *)
(* The HB class is called BJoinSemilattice. *)
(* tJoinSemilatticeType d == joinSemilatticeType with a top element *)
(* The HB class is called TJoinSemilattice. *)
(* tbJoinSemilatticeType d == joinSemilatticeType with both a top and a *)
(* bottom *)
(* The HB class is called TBJoinSemilattice. *)
(* latticeType d == the type of lattices *)
(* The HB class is called Lattice. *)
(* bLatticeType d == latticeType with a bottom element *)
(* The HB class is called BLattice. *)
(* tLatticeType d == latticeType with a top element *)
(* The HB class is called TLattice. *)
(* tbLatticeType d == latticeType with both a top and a bottom *)
(* The HB class is called TBLattice. *)
(* distrLatticeType d == the type of distributive lattices *)
(* The HB class is called DistrLattice. *)
(* bDistrLatticeType d == distrLatticeType with a bottom element *)
(* The HB class is called BDistrLattice. *)
(* tDistrLatticeType d == distrLatticeType with a top element *)
(* The HB class is called TDistrLattice. *)
(* tbDistrLatticeType d == distrLatticeType with both a top and a bottom *)
(* The HB class is called TBDistrLattice. *)
(* orderType d == the type of totally ordered types *)
(* The HB class is called Total. *)
(* bOrderType d == orderType with a bottom element *)
(* The HB class is called BTotal. *)
(* tOrderType d == orderType with a top element *)
(* The HB class is called TTotal. *)
(* tbOrderType d == orderType with both a top and a bottom *)
(* The HB class is called TBTotal. *)
(* cDistrLatticeType d == the type of relatively complemented *)
(* distributive lattices, where each interval *)
(* [a, b] is equipped with a complement operation*)
(* The HB class is called CDistrLattice. *)
(* cbDistrLatticeType d == the type of sectionally complemented *)
(* distributive lattices, equipped with a bottom,*)
(* a relative complement operation, and a *)
(* difference operation, i.e., a complement *)
(* operation for each interval of the form *)
(* [\bot, b] *)
(* The HB class is called CBDistrLattice. *)
(* ctDistrLatticeType d == the type of dually sectionally complemented *)
(* distributive lattices, equipped with a top, *)
(* a relative complement operation, and a *)
(* dual difference operation, i.e. a complement *)
(* operation for each interval of the form *)
(* [a, \top] *)
(* The HB class is called CTDistrLattice. *)
(* ctbDistrLatticeType d == the type of complemented distributive *)
(* lattices, equipped with top, bottom, *)
(* difference, dual difference, and complement *)
(* The HB class is called CTBDistrLattice. *)
(* finPOrderType d == the type of partially ordered finite types *)
(* The HB class is called FinPOrder. *)
(* finBPOrderType d == finPOrderType with a bottom element *)
(* The HB class is called FinBPOrder. *)
(* finTPOrderType d == finPOrderType with a top element *)
(* The HB class is called FinTPOrder. *)
(* finTBPOrderType d == finPOrderType with both a top and a bottom *)
(* The HB class is called FinTBPOrder. *)
(* finMeetSemilatticeType d == the type of finite meet semilattice types *)
(* The HB class is called FinMeetSemilattice. *)
(* finBMeetSemilatticeType d == finMeetSemilatticeType with a bottom element *)
(* Note that finTMeetSemilatticeType is just *)
(* finTBLatticeType. *)
(* The HB class is called FinBMeetSemilattice. *)
(* finJoinSemilatticeType d == the type of finite join semilattice types *)
(* The HB class is called FinJoinSemilattice. *)
(* finTJoinSemilatticeType d == finJoinSemilatticeType with a top element *)
(* Note that finBJoinSemilatticeType is just *)
(* finTBLatticeType. *)
(* The HB class is called FinTJoinSemilattice. *)
(* finLatticeType d == the type of finite lattices *)
(* The HB class is called FinLattice. *)
(* finTBLatticeType d == the type of nonempty finite lattices *)
(* The HB class is called FinTBLattice. *)
(* finDistrLatticeType d == the type of finite distributive lattices *)
(* The HB class is called FinDistrLattice. *)
(* finTBDistrLatticeType d == the type of nonempty finite distributive *)
(* lattices *)
(* The HB class is called FinTBDistrLattice. *)
(* finOrderType d == the type of totally ordered finite types *)
(* The HB class is called FinTotal. *)
(* finTBOrderType d == the type of nonempty totally ordered finite *)
(* types *)
(* The HB class is called FinTBTotal. *)
(* finCDistrLatticeType d == the type of finite relatively complemented *)
(* distributive lattices *)
(* The HB class is called FinCDistrLattice. *)
(* finCTBDistrLatticeType d == the type of finite complemented distributive *)
(* lattices *)
(* The HB class is called FinCTBDistrLattice. *)
(* *)
(* and their joins with subType: *)
(* *)
(* subPOrder d T P d' == join of porderType d' and subType *)
(* (P : pred T) such that val is monotonic *)
(* The HB class is called SubPOrder. *)
(* meetSubLattice d T P d' == join of latticeType d' and subType *)
(* (P : pred T) such that val is monotonic and *)
(* a morphism for meet *)
(* The HB class is called MeetSubLattice. *)
(* joinSubLattice d T P d' == join of latticeType d' and subType *)
(* (P : pred T) such that val is monotonic and *)
(* a morphism for join *)
(* The HB class is called JoinSubLattice. *)
(* subLattice d T P d' == join of JoinSubLattice and MeetSubLattice *)
(* The HB class is called SubLattice. *)
(* bJoinSubLattice d T P d' == join of JoinSubLattice and BLattice *)
(* such that val is a morphism for \bot *)
(* The HB class is called BJoinSubLattice. *)
(* tMeetSubLattice d T P d' == join of MeetSubLattice and TLattice *)
(* such that val is a morphism for \top *)
(* The HB class is called TMeetSubLattice. *)
(* bSubLattice d T P d' == join of SubLattice and BLattice *)
(* such that val is a morphism for \bot *)
(* The HB class is called BSubLattice. *)
(* tSubLattice d T P d' == join of SubLattice and TLattice *)
(* such that val is a morphism for \top *)
(* The HB class is called BSubLattice. *)
(* subOrder d T P d' == join of orderType d' and *)
(* subLatticeType d T P d' *)
(* The HB class is called SubOrder. *)
(* subPOrderLattice d T P d' == join of SubPOrder and Lattice *)
(* The HB class is called SubPOrderLattice. *)
(* subPOrderBLattice d T P d' == join of SubPOrder and BLattice *)
(* The HB class is called SubPOrderBLattice. *)
(* subPOrderTLattice d T P d' == join of SubPOrder and TLattice *)
(* The HB class is called SubPOrderTLattice. *)
(* subPOrderTBLattice d T P d' == join of SubPOrder and TBLattice *)
(* The HB class is called SubPOrderTBLattice. *)
(* meetSubBLattice d T P d' == join of MeetSubLattice and BLattice *)
(* The HB class is called MeetSubBLattice. *)
(* meetSubTLattice d T P d' == join of MeetSubLattice and TLattice *)
(* The HB class is called MeetSubTLattice. *)
(* meetSubTBLattice d T P d' == join of MeetSubLattice and TBLattice *)
(* The HB class is called MeetSubTBLattice. *)
(* joinSubBLattice d T P d' == join of JoinSubLattice and BLattice *)
(* The HB class is called JoinSubBLattice. *)
(* joinSubTLattice d T P d' == join of JoinSubLattice and TLattice *)
(* The HB class is called JoinSubTLattice. *)
(* joinSubTBLattice d T P d' == join of JoinSubLattice and TBLattice *)
(* The HB class is called JoinSubTBLattice. *)
(* subBLattice d T P d' == join of SubLattice and BLattice *)
(* The HB class is called SubBLattice. *)
(* subTLattice d T P d' == join of SubLattice and TLattice *)
(* The HB class is called SubTLattice. *)
(* subTBLattice d T P d' == join of SubLattice and TBLattice *)
(* The HB class is called SubTBLattice. *)
(* bJoinSubTLattice d T P d' == join of BJoinSubLattice and TBLattice *)
(* The HB class is called BJoinSubTLattice. *)
(* tMeetSubBLattice d T P d' == join of TMeetSubLattice and TBLattice *)
(* The HB class is called TMeetSubBLattice. *)
(* bSubTLattice d T P d' == join of BSubLattice and TBLattice *)
(* The HB class is called BSubTLattice. *)
(* tSubBLattice d T P d' == join of TSubLattice and TBLattice *)
(* The HB class is called TSubBLattice. *)
(* tbSubBLattice d T P d' == join of BSubLattice and TSubLattice *)
(* The HB class is called TBSubLattice. *)
(* *)
(* Morphisms between the above structures: *)
(* *)
(* MeetLatticeMorphism.type d T d' T', *)
(* JoinLatticeMorphism.type d T d' T', *)
(* LatticeMorphism.type d T d' T' == nondecreasing function between two *)
(* lattices which are morphism for meet, join, and *)
(* meet/join respectively *)
(* BLatticeMorphism.type d T d' T' := {blmorphism T -> T'}, *)
(* TLatticeMorphism.type d T d' T' := {tlmorphism T -> T'}, *)
(* TBLatticeMorphism.type d T d' T' := {tblmorphism T -> T'} *)
(* == nondecreasing function between two lattices with *)
(* bottom/top which are morphism for bottom/top *)
(* *)
(* Closedness predicates for the algebraic structures: *)
(* *)
(* meetLatticeClosed d T == predicate closed under meet on T : latticeType d *)
(* The HB class is MeetLatticeClosed. *)
(* joinLatticeClosed d T == predicate closed under join on T : latticeType d *)
(* The HB class is JoinLatticeClosed. *)
(* latticeClosed d T == predicate closed under meet and join *)
(* The HB class is JoinLatticeClosed. *)
(* bLatticeClosed d T == predicate that contains bottom *)
(* The HB class is BLatticeClosed. *)
(* tLatticeClosed d T == predicate that contains top *)
(* The HB class is TLatticeClosed. *)
(* tbLatticeClosed d T == predicate that contains top and bottom *)
(* the HB class ie TBLatticeClosed. *)
(* bJoinLatticeClosed d T == predicate that contains bottom and is closed *)
(* under join *)
(* The HB class is BJoinLatticeClosed. *)
(* tMeetLatticeClosed d T == predicate that contains top and is closed under *)
(* meet *)
(* The HB class is TMeetLatticeClosed. *)
(* *)
(* * Useful lemmas: *)
(* On orderType, leP, ltP, and ltgtP are the three main lemmas for case *)
(* analysis. *)
(* On porderType, one may use comparableP, comparable_leP, comparable_ltP, *)
(* and comparable_ltgtP, which are the four main lemmas for case analysis. *)
(* *)
(* * Order relations and operations: *)
(* In general, an overloaded relation or operation on ordered types takes the *)
(* following arguments: *)
(* 1. a display d of type Order.disp_t, *)
(* 2. an instance T of the minimal structure it operates on, and *)
(* 3. operands. *)
(* Here is the exhaustive list of all such operations together with their *)
(* default notation (defined in order_scope unless specified otherwise). *)
(* *)
(* For T of type porderType d, x and y of type T, and C of type bool: *)
(* x <= y := @Order.le d T x y *)
(* <-> x is less than or equal to y. *)
(* x < y := @Order.lt d T x y *)
(* <-> x is less than y, i.e., (y != x) && (x <= y). *)
(* x >= y := y <= x *)
(* <-> x is greater than or equal to y. *)
(* x > y := y < x *)
(* <-> x is greater than y. *)
(* x >=< y := @Order.comparable d T x y (:= (x <= y) || (y <= x)) *)
(* <-> x and y are comparable. *)
(* x >< y := ~~ x >=< y *)
(* <-> x and y are incomparable. *)
(* x <= y ?= iff C := @Order.leif d T x y C (:= (x <= y) * ((x == y) = C)) *)
(* <-> x is less than y, or equal iff C is true. *)
(* x < y ?<= if C := @Order.lteif d T x y C (:= if C then x <= y else x < y)*)
(* <-> x is smaller than y, and strictly if C is false. *)
(* Order.min x y := if x < y then x else y *)
(* Order.max x y := if x < y then y else x *)
(* f \min g == the function x |-> Order.min (f x) (g x); *)
(* f \min g simplifies on application. *)
(* f \max g == the function x |-> Order.max (f x) (g x); *)
(* f \max g simplifies on application. *)
(* nondecreasing f <-> the function f : T -> T' is nondecreasing, *)
(* where T and T' are porderType *)
(* := {homo f : x y / x <= y} *)
(* Unary (partially applied) versions of order notations: *)
(* >= y := @Order.le d T y *)
(* == a predicate characterizing elements greater than or *)
(* equal to y *)
(* > y := @Order.lt d T y *)
(* <= y := @Order.ge d T y *)
(* < y := @Order.gt d T y *)
(* >=< y := [pred x | @Order.comparable d T x y] *)
(* >< y := [pred x | ~~ @Order.comparable d T x y] *)
(* 0-ary versions of order notations (in function_scope): *)
(* <=%O := @Order.le d T *)
(* <%O := @Order.lt d T *)
(* >=%O := @Order.ge d T *)
(* >%O := @Order.gt d T *)
(* >=<%O := @Order.comparable d T *)
(* <?=%O := @Order.leif d T *)
(* <?<=%O := @Order.lteif d T *)
(* -> These conventions are compatible with Haskell's, *)
(* where ((< y) x) = (x < y) = ((<) x y), *)
(* except that we write <%O instead of (<). *)
(* *)
(* For T of type bPOrderType d: *)
(* \bot := @Order.bottom d T *)
(* == the bottom element of type T *)
(* \max_<range> e := \big[Order.max / Order.bottom]_<range> e *)
(* == iterated max of a preorder with a bottom *)
(* the possible <range>s are documented in bigop.v *)
(* For T of type tPOrderType d: *)
(* \top := @Order.top d T *)
(* == the top element of type T *)
(* \min_<range> e := \big[Order.max / Order.top]_<range> e *)
(* == iterated min of a preorder with a top *)
(* the possible <range>s are documented in bigop.v *)
(* *)
(* For T of type meetSemilatticeType d, and x, y of type T: *)
(* x `&` y := @Order.meet d T x y *)
(* == the meet of x and y *)
(* For T of type joinSemilatticeType d, and x, y of type T: *)
(* x `|` y := @Order.join d T x y *)
(* == the join of x and y *)
(* *)
(* For T of type tMeetSemilatticeType d: *)
(* \meet_<range> e := \big[Order.meet / Order.top]_<range> e *)
(* == iterated meet of a meet-semilattice with a top *)
(* the possible <range>s are documented in bigop.v *)
(* For T of type bJoinSemilatticeType d: *)
(* \join_<range> e := \big[Order.join / Order.bottom]_<range> e *)
(* == iterated join of a join-semilattice with a bottom *)
(* the possible <range>s are documented in bigop.v *)
(* *)
(* For T of type cDistrLatticeType d, and x, y, z of type T: *)
(* rcompl x y z == the (relative) complement of z in [x, y] *)
(* *)
(* For T of type cbDistrLatticeType d, and x, y of type T: *)
(* x `\` y := @Order.diff d T x y *)
(* == the (sectional) complement of y in [\bot, x], *)
(* i.e., rcompl \bot x y *)
(* *)
(* For T of type ctDistrLatticeType d, and x, y of type T: *)
(* codiff x y == the (dual sectional) complement of y in [x, \top], *)
(* i.e., rcompl x \top y *)
(* *)
(* For T of type ctbDistrLatticeType d, and x of type T: *)
(* ~` x := @Order.compl d T x *)
(* == the complement of x in [\bot, \top], *)
(* i.e., rcompl \bot \top x *)
(* *)
(* For preorderType we provide the following operations: *)
(* [arg min_(i < i0 | P) M] == a value i : T minimizing M : R, subject to *)
(* the condition P (i may appear in P and M), and *)
(* provided P holds for i0. *)
(* [arg max_(i > i0 | P) M] == a value i maximizing M subject to P and *)
(* provided P holds for i0. *)
(* [arg min_(i < i0 in A) M] == an i \in A minimizing M if i0 \in A. *)
(* [arg max_(i > i0 in A) M] == an i \in A maximizing M if i0 \in A. *)
(* [arg min_(i < i0) M] == an i : T minimizing M, given i0 : T. *)
(* [arg max_(i > i0) M] == an i : T maximizing M, given i0 : T. *)
(* with head symbols Order.arg_min and Order.arg_max *)
(* The user may use extremumP or extremum_inP to eliminate them. *)
(* *)
(* -> patterns for contextual rewriting: *)
(* leLHS := (X in (X <= _)%O)%pattern *)
(* leRHS := (X in (_ <= X)%O)%pattern *)
(* ltLHS := (X in (X < _)%O)%pattern *)
(* ltRHS := (X in (_ < X)%O)%pattern *)
(* *)
(* We provide aliases for various types and their displays: *)
(* natdvd := nat (associated with display dvd_display) *)
(* == an alias for nat which is canonically ordered using *)
(* divisibility predicate dvdn *)
(* Notation %|, %<|, gcd, lcm are used instead of *)
(* <=, <, meet and join. *)
(* T^d := dual T, *)
(* where dual is a new definition for (fun T => T) *)
(* (associated with dual_display d where d is a display) *)
(* == an alias for T, such that if T is canonically *)
(* ordered, then T^d is canonically ordered with the *)
(* dual order, and displayed with an extra ^d in the *)
(* notation, i.e., <=^d, <^d, >=<^d, ><^d, `&`^d, `|`^d *)
(* are used and displayed instead of *)
(* <=, <, >=<, ><, `&`, `|` *)
(* T *prod[d] T' := T * T' *)
(* == an alias for the cartesian product such that, *)
(* if T and T' are canonically ordered, *)
(* then T *prod[d] T' is canonically ordered in product *)
(* order, i.e., *)
(* (x1, x2) <= (y1, y2) = (x1 <= y1) && (x2 <= y2), *)
(* and displayed in display d *)
(* T *p T' := T *prod[prod_display d d'] T' *)
(* where d and d' are the displays of T and T', *)
(* respectively, and prod_display adds an extra ^p to *)
(* all notations *)
(* T *lexi[d] T' := T * T' *)
(* == an alias for the cartesian product such that, *)
(* if T and T' are canonically ordered, *)
(* then T *lexi[d] T' is canonically ordered in *)
(* lexicographic order, *)
(* i.e., (x1, x2) <= (y1, y2) = *)
(* (x1 <= y1) && ((x1 >= y1) ==> (x2 <= y2)) *)
(* and (x1, x2) < (y1, y2) = *)
(* (x1 <= y1) && ((x1 >= y1) ==> (x2 < y2)) *)
(* and displayed in display d *)
(* T *l T' := T *lexi[lexi_display d d'] T' *)
(* where d and d' are the displays of T and T', *)
(* respectively, and lexi_display adds an extra ^l to *)
(* all notations *)
(* seqprod_with d T := seq T *)
(* == an alias for seq, such that if T is canonically *)
(* ordered, then seqprod_with d T is canonically ordered *)
(* in product order, i.e., *)
(* [:: x1, .., xn] <= [y1, .., yn] = *)
(* (x1 <= y1) && ... && (xn <= yn) *)
(* and displayed in display d *)
(* n.-tupleprod[d] T == same with n.tuple T *)
(* seqprod T := seqprod_with (seqprod_display d) T *)
(* where d is the display of T, and seqprod_display adds *)
(* an extra ^sp to all notations *)
(* n.-tupleprod T := n.-tuple[seqprod_display d] T *)
(* where d is the display of T *)
(* seqlexi_with d T := seq T *)
(* == an alias for seq, such that if T is canonically *)
(* ordered, then seqprod_with d T is canonically ordered *)
(* in lexicographic order, i.e., *)
(* [:: x1, .., xn] <= [y1, .., yn] = *)
(* (x1 <= x2) && ((x1 >= y1) ==> ((x2 <= y2) && ...)) *)
(* and displayed in display d *)
(* n.-tuplelexi[d] T == same with n.tuple T *)
(* seqlexi T := lexiprod_with (seqlexi_display d) T *)
(* where d is the display of T, and seqlexi_display adds *)
(* an extra ^sl to all notations *)
(* n.-tuplelexi T := n.-tuple[seqlexi_display d] T *)
(* where d is the display of T *)
(* {subset[d] T} := {set T} *)
(* == an alias for set which is canonically ordered by the *)
(* subset order and displayed in display d *)
(* {subset T} := {subset[subset_display] T} *)
(* *)
(* The following notations are provided to build substructures: *)
(* [SubChoice_isSubPOrder of U by <: with disp] == *)
(* [SubChoice_isSubPOrder of U by <:] == porderType mixin for a subType *)
(* whose base type is a porderType *)
(* [SubPOrder_isSubLattice of U by <: with disp] == *)
(* [SubPOrder_isSubLattice of U by <:] == *)
(* [SubChoice_isSubLattice of U by <: with disp] == *)
(* [SubChoice_isSubLattice of U by <:] == latticeType mixin for a subType *)
(* whose base type is a latticeType and whose *)
(* predicate is a latticeClosed *)
(* [SubPOrder_isBSubLattice of U by <: with disp] == *)
(* [SubPOrder_isBSubLattice of U by <:] == *)
(* [SubChoice_isBSubLattice of U by <: with disp] == *)
(* [SubChoice_isBSubLattice of U by <:] == blatticeType mixin for a subType *)
(* whose base type is a blatticeType and whose *)
(* predicate is both a latticeClosed *)
(* and a bLatticeClosed *)
(* [SubPOrder_isTSubLattice of U by <: with disp] == *)
(* [SubPOrder_isTSubLattice of U by <:] == *)
(* [SubChoice_isTSubLattice of U by <: with disp] == *)
(* [SubChoice_isTSubLattice of U by <:] == tlatticeType mixin for a subType *)
(* whose base type is a tlatticeType and whose *)
(* predicate is both a latticeClosed *)
(* and a tLatticeClosed *)
(* [SubPOrder_isTBSubLattice of U by <: with disp] == *)
(* [SubPOrder_isTBSubLattice of U by <:] == *)
(* [SubChoice_isTBSubLattice of U by <: with disp] == *)
(* [SubChoice_isTBSubLattice of U by <:] == tblatticeType mixin for a subType *)
(* whose base type is a tblatticeType and whose *)
(* predicate is both a latticeClosed *)
(* and a tbLatticeClosed *)
(* [SubLattice_isSubOrder of U by <: with disp] == *)
(* [SubLattice_isSubOrder of U by <:] == *)
(* [SubPOrder_isSubOrder of U by <: with disp] == *)
(* [SubPOrder_isSubOrder of U by <:] == *)
(* [SubChoice_isSubOrder of U by <: with disp] == *)
(* [SubChoice_isSubOrder of U by <:] == orderType mixin for a subType whose *)
(* base type is an orderType *)
(* [POrder of U by <:] == porderType mixin for a subType whose base type is *)
(* a porderType *)
(* [Order of U by <:] == orderType mixin for a subType whose base type is *)
(* an orderType *)
(* *)
(* We provide expected instances of ordered types for bool, nat (for leq and *)
(* and dvdn), 'I_n, 'I_n.+1 (with a top and bottom), nat for dvdn, *)
(* T *prod[disp] T', T *lexi[disp] T', {t : T & T' x} (with lexicographic *)
(* ordering), seqprod_with d T (using product order), seqlexi_with d T *)
(* (with lexicographic ordering), n.-tupleprod[disp] (using product order), *)
(* n.-tuplelexi[d] T (with lexicographic ordering), on {subset[disp] T} *)
(* (using subset order) and all possible finite type instances. *)
(* (Use `HB.about type` to discover the instances on type.) *)
(* *)
(* In order to get a canonical order on prod, seq, tuple or set, one may *)
(* import modules DefaultProdOrder or DefaultProdLexiOrder, *)
(* DefaultSeqProdOrder or DefaultSeqLexiOrder, *)
(* DefaultTupleProdOrder or DefaultTupleLexiOrder, *)
(* and DefaultSetSubsetOrder. *)
(* *)
(* We also provide specialized versions of some theorems from path.v. *)
(* *)
(* We provide Order.enum_val, Order.enum_rank, and Order.enum_rank_in, which *)
(* are monotonic variations of enum_val, enum_rank, and enum_rank_in *)
(* whenever the type is porderType, and their monotonicity is provided if *)
(* this order is total. The theory is in the module Order (Order.enum_valK, *)
(* Order.enum_rank_inK, etc) but Order.Enum can be imported to shorten these. *)
(* *)
(* We provide an opaque monotonous bijection tagnat.sig / tagnat.rank between *)
(* the finite types {i : 'I_n & 'I_(p_ i)} and 'I_(\sum_i p_ i): *)
(* tagnat.sig : 'I_(\sum_i p_ i) -> {i : 'I_n & 'I_(p_ i)} *)
(* tagnat.rank : {i : 'I_n & 'I_(p_ i)} -> 'I_(\sum_i p_ i) *)
(* tagnat.sig1 : 'I_(\sum_i p_ i) -> 'I_n *)
(* tagnat.sig2 : forall p : 'I_(\sum_i p_ i), 'I_(p_ (tagnat.sig1 p)) *)
(* tagnat.Rank : forall i, 'I_(p_ i) -> 'I_(\sum_i p_ i) *)
(* *)
(* Acknowledgments: This file is based on prior work by D. Dreyer, G. *)
(* Gonthier, A. Nanevski, P-Y Strub, B. Ziliani *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope order_scope.
Delimit Scope order_scope with O.
Local Open Scope order_scope.
(* Reserved notations for lattice operations *)
Reserved Notation "A `&` B" (at level 48, left associativity).
Reserved Notation "A `|` B" (at level 52, left associativity).
Reserved Notation "A `\` B" (at level 50, left associativity).
Reserved Notation "~` A" (at level 35, right associativity).
(* Reserved notations for dual order *)
Reserved Notation "A `&^d` B" (at level 48, left associativity).
Reserved Notation "A `|^d` B" (at level 52, left associativity).
Reserved Notation "A `\^d` B" (at level 50, left associativity).
Reserved Notation "~^d` A" (at level 35, right associativity).
(* Reserved notations for product ordering of prod *)
Reserved Notation "A `&^p` B" (at level 48, left associativity).
Reserved Notation "A `|^p` B" (at level 52, left associativity).
Reserved Notation "A `\^p` B" (at level 50, left associativity).
Reserved Notation "~^p` A" (at level 35, right associativity).
(* Reserved notations for product ordering of seq *)
Reserved Notation "A `&^sp` B" (at level 48, left associativity).
Reserved Notation "A `|^sp` B" (at level 52, left associativity).
Reserved Notation "A `\^sp` B" (at level 50, left associativity).
Reserved Notation "~^sp` A" (at level 35, right associativity).
(* Reserved notations for lexicographic ordering of prod *)
Reserved Notation "A `&^l` B" (at level 48, left associativity).
Reserved Notation "A `|^l` B" (at level 52, left associativity).
Reserved Notation "A `\^l` B" (at level 50, left associativity).
Reserved Notation "~^l` A" (at level 35, right associativity).
(* Reserved notations for lexicographic ordering of seq *)
Reserved Notation "A `&^sl` B" (at level 48, left associativity).
Reserved Notation "A `|^sl` B" (at level 52, left associativity).
Reserved Notation "A `\^sl` B" (at level 50, left associativity).
Reserved Notation "~^sl` A" (at level 35, right associativity).
(* Reserved notations for divisibility *)
Reserved Notation "\gcd_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \gcd_ i '/ ' F ']'").
Reserved Notation "\gcd_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \gcd_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i <- r ) F"
(F at level 41,
format "'[' \gcd_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\gcd_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \gcd_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( m <= i < n ) F"
(F at level 41,
format "'[' \gcd_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i | P ) F"
(F at level 41,
format "'[' \gcd_ ( i | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\gcd_ ( i : t ) F" (F at level 41).
Reserved Notation "\gcd_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \gcd_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i < n ) F"
(F at level 41,
format "'[' \gcd_ ( i < n ) F ']'").
Reserved Notation "\gcd_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \gcd_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i 'in' A ) F"
(F at level 41,
format "'[' \gcd_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\lcm_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \lcm_ i '/ ' F ']'").
Reserved Notation "\lcm_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \lcm_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i <- r ) F"
(F at level 41,
format "'[' \lcm_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\lcm_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \lcm_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( m <= i < n ) F"
(F at level 41,
format "'[' \lcm_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i | P ) F"
(F at level 41,
format "'[' \lcm_ ( i | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\lcm_ ( i : t ) F" (F at level 41).
Reserved Notation "\lcm_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \lcm_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i < n ) F"
(F at level 41,
format "'[' \lcm_ ( i < n ) F ']'").
Reserved Notation "\lcm_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \lcm_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i 'in' A ) F"
(F at level 41,
format "'[' \lcm_ ( i 'in' A ) '/ ' F ']'").
(* Reserved notations for iterative meet and join *)
Reserved Notation "\meet_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet_ i '/ ' F ']'").
Reserved Notation "\meet_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i <- r ) F"
(F at level 41,
format "'[' \meet_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet_ ( i | P ) F"
(F at level 41,
format "'[' \meet_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i < n ) F"
(F at level 41,
format "'[' \meet_ ( i < n ) F ']'").
Reserved Notation "\meet_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join_ i '/ ' F ']'").
Reserved Notation "\join_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i <- r ) F"
(F at level 41,
format "'[' \join_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join_ ( i | P ) F"
(F at level 41,
format "'[' \join_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join_ ( i : t ) F" (F at level 41).
Reserved Notation "\join_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i < n ) F"
(F at level 41,
format "'[' \join_ ( i < n ) F ']'").
Reserved Notation "\join_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^d_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^d_ i '/ ' F ']'").
Reserved Notation "\meet^d_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^d_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^d_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^d_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^d_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i | P ) F"
(F at level 41,
format "'[' \meet^d_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^d_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^d_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^d_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i < n ) F"
(F at level 41,
format "'[' \meet^d_ ( i < n ) F ']'").
Reserved Notation "\meet^d_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^d_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^d_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^d_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^d_ i '/ ' F ']'").
Reserved Notation "\join^d_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^d_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i <- r ) F"
(F at level 41,
format "'[' \join^d_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^d_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^d_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^d_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i | P ) F"
(F at level 41,
format "'[' \join^d_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^d_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^d_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^d_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i < n ) F"
(F at level 41,
format "'[' \join^d_ ( i < n ) F ']'").
Reserved Notation "\join^d_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^d_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^d_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^p_ i '/ ' F ']'").
Reserved Notation "\meet^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i | P ) F"
(F at level 41,
format "'[' \meet^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i < n ) F"
(F at level 41,
format "'[' \meet^p_ ( i < n ) F ']'").
Reserved Notation "\meet^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^p_ i '/ ' F ']'").
Reserved Notation "\join^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i <- r ) F"
(F at level 41,
format "'[' \join^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i | P ) F"
(F at level 41,
format "'[' \join^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i < n ) F"
(F at level 41,
format "'[' \join^p_ ( i < n ) F ']'").
Reserved Notation "\join^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\min^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \min^p_ i '/ ' F ']'").
Reserved Notation "\min^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i <- r ) F"
(F at level 41,
format "'[' \min^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i | P ) F"
(F at level 41,
format "'[' \min^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\min^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i < n ) F"
(F at level 41,
format "'[' \min^p_ ( i < n ) F ']'").
Reserved Notation "\min^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max^p_ i '/ ' F ']'").
Reserved Notation "\max^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i <- r ) F"
(F at level 41,
format "'[' \max^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i | P ) F"
(F at level 41,
format "'[' \max^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\max^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\max^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i < n ) F"
(F at level 41,
format "'[' \max^p_ ( i < n ) F ']'").
Reserved Notation "\max^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^sp_ i '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i | P ) F"
(F at level 41,
format "'[' \meet^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i < n ) F"
(F at level 41,
format "'[' \meet^sp_ ( i < n ) F ']'").
Reserved Notation "\meet^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^sp_ i '/ ' F ']'").
Reserved Notation "\join^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \join^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i | P ) F"
(F at level 41,
format "'[' \join^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i < n ) F"
(F at level 41,
format "'[' \join^sp_ ( i < n ) F ']'").
Reserved Notation "\join^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\min^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \min^sp_ i '/ ' F ']'").
Reserved Notation "\min^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \min^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i | P ) F"
(F at level 41,
format "'[' \min^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\min^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i < n ) F"
(F at level 41,
format "'[' \min^sp_ ( i < n ) F ']'").
Reserved Notation "\min^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max^sp_ i '/ ' F ']'").
Reserved Notation "\max^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \max^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i | P ) F"
(F at level 41,
format "'[' \max^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\max^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\max^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i < n ) F"
(F at level 41,
format "'[' \max^sp_ ( i < n ) F ']'").
Reserved Notation "\max^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^l_ i '/ ' F ']'").
Reserved Notation "\meet^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i | P ) F"
(F at level 41,
format "'[' \meet^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i < n ) F"
(F at level 41,
format "'[' \meet^l_ ( i < n ) F ']'").
Reserved Notation "\meet^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^l_ i '/ ' F ']'").
Reserved Notation "\join^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i <- r ) F"
(F at level 41,
format "'[' \join^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i | P ) F"
(F at level 41,
format "'[' \join^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i < n ) F"
(F at level 41,
format "'[' \join^l_ ( i < n ) F ']'").
Reserved Notation "\join^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\min^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \min^l_ i '/ ' F ']'").
Reserved Notation "\min^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i <- r ) F"
(F at level 41,
format "'[' \min^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i | P ) F"
(F at level 41,
format "'[' \min^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\min^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i < n ) F"
(F at level 41,
format "'[' \min^l_ ( i < n ) F ']'").
Reserved Notation "\min^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max^l_ i '/ ' F ']'").
Reserved Notation "\max^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i <- r ) F"
(F at level 41,
format "'[' \max^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i | P ) F"
(F at level 41,
format "'[' \max^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\max^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\max^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i < n ) F"
(F at level 41,
format "'[' \max^l_ ( i < n ) F ']'").
Reserved Notation "\max^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "'{' 'omorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'omorphism' U -> V }").
Reserved Notation "'{' 'mlmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'mlmorphism' U -> V }").
Reserved Notation "'{' 'jlmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'jlmorphism' U -> V }").
Reserved Notation "'{' 'lmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'lmorphism' U -> V }").
Reserved Notation "'{' 'blmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'blmorphism' U -> V }").
Reserved Notation "'{' 'tlmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'tlmorphism' U -> V }").
Reserved Notation "'{' 'tblmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'tblmorphism' U -> V }").
Module Order.
Export Order.
#[key="T", primitive]
HB.mixin Record Preorder_isDuallyPOrder (d : disp_t) T of Preorder d T := {
le_anti : antisymmetric (@le d T);
ge_anti : antisymmetric (fun x y => @le d T y x);
}.
#[short(type="porderType")]
HB.structure Definition POrder (d : disp_t) :=
{ T of Preorder d T & Preorder_isDuallyPOrder d T }.
#[short(type="bPOrderType")]
HB.structure Definition BPOrder d := { T of hasBottom d T & POrder d T }.
#[short(type="tPOrderType")]
HB.structure Definition TPOrder d := { T of hasTop d T & POrder d T }.
#[short(type="tbPOrderType")]
HB.structure Definition TBPOrder d := { T of hasTop d T & BPOrder d T }.
Module POrderExports.
Arguments le_trans {d s} [_ _ _].
End POrderExports.
HB.export POrderExports.
(* Bind Scope order_scope with POrder.sort. *)
#[key="T", primitive]
HB.mixin Record POrder_isMeetSemilattice d (T : Type) of POrder d T := {
meet : T -> T -> T;
lexI : forall x y z, (x <= meet y z) = (x <= y) && (x <= z);
}.
#[key="T", primitive]
HB.mixin Record POrder_isJoinSemilattice d T of POrder d T := {
join : T -> T -> T;
leUx : forall x y z, (join x y <= z) = (x <= z) && (y <= z);
}.
#[short(type="meetSemilatticeType")]
HB.structure Definition MeetSemilattice d :=
{ T of POrder d T & POrder_isMeetSemilattice d T }.
#[short(type="bMeetSemilatticeType")]
HB.structure Definition BMeetSemilattice d :=
{ T of MeetSemilattice d T & hasBottom d T }.
#[short(type="tMeetSemilatticeType")]
HB.structure Definition TMeetSemilattice d :=
{ T of MeetSemilattice d T & hasTop d T }.
#[short(type="tbMeetSemilatticeType")]
HB.structure Definition TBMeetSemilattice d :=
{ T of BMeetSemilattice d T & hasTop d T }.
#[short(type="joinSemilatticeType")]
HB.structure Definition JoinSemilattice d :=
{ T of POrder d T & POrder_isJoinSemilattice d T }.
#[short(type="bJoinSemilatticeType")]
HB.structure Definition BJoinSemilattice d :=
{ T of JoinSemilattice d T & hasBottom d T }.
#[short(type="tJoinSemilatticeType")]
HB.structure Definition TJoinSemilattice d :=
{ T of JoinSemilattice d T & hasTop d T }.
#[short(type="tbJoinSemilatticeType")]
HB.structure Definition TBJoinSemilattice d :=
{ T of BJoinSemilattice d T & hasTop d T }.
#[short(type="latticeType")]
HB.structure Definition Lattice d :=
{ T of JoinSemilattice d T & POrder_isMeetSemilattice d T }.
#[short(type="bLatticeType")]
HB.structure Definition BLattice d := { T of Lattice d T & hasBottom d T }.
#[short(type="tLatticeType")]
HB.structure Definition TLattice d := { T of Lattice d T & hasTop d T }.
#[short(type="tbLatticeType")]
HB.structure Definition TBLattice d := { T of BLattice d T & hasTop d T }.
Section LatticeDef.
Context {disp : disp_t} {T : latticeType disp}.
Variant lel_xor_gt (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> Set :=
| LelNotGt of x <= y : lel_xor_gt x y x x y y x x y y true false
| GtlNotLe of y < x : lel_xor_gt x y y y x x y y x x false true.
Variant ltl_xor_ge (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> Set :=
| LtlNotGe of x < y : ltl_xor_ge x y x x y y x x y y false true
| GelNotLt of y <= x : ltl_xor_ge x y y y x x y y x x true false.
Variant comparel (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| ComparelLt of x < y : comparel x y
x x y y x x y y false false false true false true
| ComparelGt of y < x : comparel x y
y y x x y y x x false false true false true false
| ComparelEq of x = y : comparel x y
x x x x x x x x true true true true false false.
Variant incomparel (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T ->
bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| InComparelLt of x < y : incomparel x y
x x y y x x y y false false false true false true true true
| InComparelGt of y < x : incomparel x y
y y x x y y x x false false true false true false true true
| InComparel of x >< y : incomparel x y
x y y x (meet y x) (meet x y) (join y x) (join x y)
false false false false false false false false
| InComparelEq of x = y : incomparel x y
x x x x x x x x true true true true false false true true.
End LatticeDef.
Module LatticeSyntax.
Notation "x `&` y" := (meet x y) : order_scope.
Notation "x `|` y" := (join x y) : order_scope.
End LatticeSyntax.
HB.export LatticeSyntax.
Module BLatticeSyntax.
Notation "\join_ ( i <- r | P ) F" :=
(\big[@join _ _ / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join_ ( i <- r ) F" :=
(\big[@join _ _ / \bot]_(i <- r) F%O) : order_scope.
Notation "\join_ ( i | P ) F" :=
(\big[@join _ _ / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join_ i F" :=
(\big[@join _ _ / \bot]_i F%O) : order_scope.
Notation "\join_ ( i : I | P ) F" :=
(\big[@join _ _ / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join_ ( i : I ) F" :=
(\big[@join _ _ / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join_ ( m <= i < n | P ) F" :=
(\big[@join _ _ / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join_ ( m <= i < n ) F" :=
(\big[@join _ _ / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join_ ( i < n | P ) F" :=
(\big[@join _ _ / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join_ ( i < n ) F" :=
(\big[@join _ _ / \bot]_(i < n) F%O) : order_scope.
Notation "\join_ ( i 'in' A | P ) F" :=
(\big[@join _ _ / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join_ ( i 'in' A ) F" :=
(\big[@join _ _ / \bot]_(i in A) F%O) : order_scope.
End BLatticeSyntax.
HB.export BLatticeSyntax.
Module TLatticeSyntax.
Notation "\meet_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
End TLatticeSyntax.
HB.export TLatticeSyntax.
#[key="T", primitive]
HB.mixin Record Lattice_isDistributive d (T : Type) of Lattice d T := {
meetUl : @left_distributive T T meet join;
joinIl : @left_distributive T T join meet; (* dual of meetUl *)
}.
#[short(type="distrLatticeType")]
HB.structure Definition DistrLattice d :=
{ T of Lattice_isDistributive d T & Lattice d T }.
#[short(type="bDistrLatticeType")]
HB.structure Definition BDistrLattice d :=
{ T of DistrLattice d T & hasBottom d T }.
#[short(type="tDistrLatticeType")]
HB.structure Definition TDistrLattice d :=
{ T of DistrLattice d T & hasTop d T }.
#[short(type="tbDistrLatticeType")]
HB.structure Definition TBDistrLattice d :=
{ T of BDistrLattice d T & hasTop d T }.
#[key="T", primitive]
HB.mixin Record DistrLattice_isTotal d T of DistrLattice d T :=
{ le_total : total (<=%O : rel T) }.
#[short(type="orderType")]
HB.structure Definition Total d :=
{ T of DistrLattice_isTotal d T & DistrLattice d T }.
#[short(type="bOrderType")]
HB.structure Definition BTotal d := { T of Total d T & hasBottom d T }.
#[short(type="tOrderType")]
HB.structure Definition TTotal d := { T of Total d T & hasTop d T }.
#[short(type="tbOrderType")]
HB.structure Definition TBTotal d := { T of BTotal d T & hasTop d T }.
#[key="T", primitive]
HB.mixin Record DistrLattice_hasRelativeComplement d T of DistrLattice d T := {
(* rcompl x y z is the complement of z in the interval [x, y]. *)
rcompl : T -> T -> T -> T;
rcomplPmeet : forall x y z, ((x `&` y) `|` z) `&` rcompl x y z = x `&` y;
rcomplPjoin : forall x y z, ((y `|` x) `&` z) `|` rcompl x y z = y `|` x;
}.
#[short(type="cDistrLatticeType")]
HB.structure Definition CDistrLattice d :=
{ T of DistrLattice d T & DistrLattice_hasRelativeComplement d T }.
#[key="T", primitive]
HB.mixin Record CDistrLattice_hasSectionalComplement d T
of CDistrLattice d T & hasBottom d T := {
diff : T -> T -> T;
(* FIXME: a bug in HB prevents us writing "rcompl \bot x y" *)
diffErcompl : forall x y, diff x y = rcompl (\bot : T) x y;
}.
#[short(type="cbDistrLatticeType")]
HB.structure Definition CBDistrLattice d :=
{ T of CDistrLattice d T & hasBottom d T &
CDistrLattice_hasSectionalComplement d T }.
#[key="T", primitive]
HB.mixin Record CDistrLattice_hasDualSectionalComplement d T
of CDistrLattice d T & hasTop d T := {
codiff : T -> T -> T;
codiffErcompl : forall x y, codiff x y = rcompl x \top y;
}.
#[short(type="ctDistrLatticeType")]
HB.structure Definition CTDistrLattice d :=
{ T of CDistrLattice d T & hasTop d T &
CDistrLattice_hasDualSectionalComplement d T }.
Module Import CBDistrLatticeSyntax.
Notation "x `\` y" := (diff x y) : order_scope.
End CBDistrLatticeSyntax.
#[key="T", primitive]
HB.mixin Record CDistrLattice_hasComplement d T of
CTDistrLattice d T & CBDistrLattice d T := {
compl : T -> T;
(* FIXME: a bug in HB prevents us writing "\top `\` x" and "codiff \bot x" *)
complEdiff : forall x : T, compl x = (\top : T) `\` x;
complEcodiff : forall x : T, compl x = codiff (\bot : T) x;
}.
#[short(type="ctbDistrLatticeType")]
HB.structure Definition CTBDistrLattice d :=
{ T of CBDistrLattice d T & CTDistrLattice d T &
CDistrLattice_hasComplement d T }.
Module Import CTBDistrLatticeSyntax.
Notation "~` A" := (compl A) : order_scope.
End CTBDistrLatticeSyntax.
(**********)
(* FINITE *)
(**********)
#[short(type="finPOrderType")]
HB.structure Definition FinPOrder d := { T of Finite T & POrder d T }.
#[short(type="finBPOrderType")]
HB.structure Definition FinBPOrder d := { T of FinPOrder d T & hasBottom d T }.
#[short(type="finTPOrderType")]
HB.structure Definition FinTPOrder d := { T of FinPOrder d T & hasTop d T }.
#[short(type="finTBPOrderType")]
HB.structure Definition FinTBPOrder d := { T of FinBPOrder d T & hasTop d T }.
#[short(type="finMeetSemilatticeType")]
HB.structure Definition FinMeetSemilattice d :=
{ T of Finite T & MeetSemilattice d T }.
#[short(type="finBMeetSemilatticeType")]
HB.structure Definition FinBMeetSemilattice d :=
{ T of Finite T & BMeetSemilattice d T }.
#[short(type="finJoinSemilatticeType")]
HB.structure Definition FinJoinSemilattice d :=
{ T of Finite T & JoinSemilattice d T }.
#[short(type="finTJoinSemilatticeType")]
HB.structure Definition FinTJoinSemilattice d :=
{ T of Finite T & TJoinSemilattice d T }.
#[short(type="finLatticeType")]
HB.structure Definition FinLattice d := { T of Finite T & Lattice d T }.
#[short(type="finTBLatticeType")]
HB.structure Definition FinTBLattice d := { T of Finite T & TBLattice d T }.
#[short(type="finDistrLatticeType")]
HB.structure Definition FinDistrLattice d :=
{ T of Finite T & DistrLattice d T }.
#[short(type="finTBDistrLatticeType")]
HB.structure Definition FinTBDistrLattice d :=
{ T of Finite T & TBDistrLattice d T }.
#[short(type="finOrderType")]
HB.structure Definition FinTotal d := { T of Finite T & Total d T }.
#[short(type="finTBOrderType")]
HB.structure Definition FinTBTotal d := { T of Finite T & TBTotal d T }.
#[short(type="finCDistrLatticeType")]
HB.structure Definition FinCDistrLattice d :=
{ T of Finite T & CDistrLattice d T }.
#[short(type="finCTBDistrLatticeType")]
HB.structure Definition FinCTBDistrLattice d :=
{ T of Finite T & CTBDistrLattice d T }.
(********)
(* DUAL *)
(********)
Notation dual_meet := (@meet (dual_display _) _).
Notation dual_join := (@join (dual_display _) _).
Module Import DualSyntax.
Notation "x `&^d` y" := (dual_meet x y) : order_scope.
Notation "x `|^d` y" := (dual_join x y) : order_scope.
(* The following Local Notations are here to define the \join^d_ and \meet^d_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := dual_bottom.
Local Notation "\top" := dual_top.
Local Notation join := dual_join.
Local Notation meet := dual_meet.
Local Notation min := dual_min.
Local Notation max := dual_max.
Notation "\join^d_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^d_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^d_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^d_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^d_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^d_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^d_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^d_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^d_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^d_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^d_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^d_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^d_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^d_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^d_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^d_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^d_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\meet^d_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^d_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^d_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^d_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^d_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^d_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^d_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^d_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^d_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^d_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^d_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^d_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^d_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^d_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^d_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^d_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^d_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^d_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^d_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^d_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^d_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^d_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^d_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^d_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^d_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^d_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^d_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^d_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^d_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End DualSyntax.
(*
FIXME: we have two issues in the dual instance declarations in the DualOrder
module below:
1. HB.saturate is slow, and
2. if we declare them by HB.instance, some declarations fail because it unfolds
[dual] and the generated instance does not typecheck
(math-comp/hierarchy-builder#257).
*)
Module DualOrder.
HB.instance Definition _ (d : disp_t) (T : porderType d) :=
Preorder_isDuallyPOrder.Build (dual_display d) T^d
ge_anti le_anti.
HB.instance Definition _ d (T : joinSemilatticeType d) :=
POrder_isMeetSemilattice.Build (dual_display d) T^d (fun x y z => leUx y z x).
Lemma meetEdual d (T : joinSemilatticeType d) (x y : T) :
((x : T^d) `&^d` y) = (x `|` y).
Proof. by []. Qed.
HB.instance Definition _ d (T : meetSemilatticeType d) :=
POrder_isJoinSemilattice.Build (dual_display d) T^d (fun x y z => lexI z x y).
Lemma joinEdual d (T : meetSemilatticeType d) (x y : T) :
((x : T^d) `|^d` y) = (x `&` y).
Proof. by []. Qed.
HB.saturate.
HB.instance Definition _ d (T : distrLatticeType d) :=
Lattice_isDistributive.Build (dual_display d) T^d joinIl meetUl.
HB.instance Definition _ d (T : orderType d) :=
DistrLattice_isTotal.Build (dual_display d) T^d (fun x y => le_total y x).
HB.saturate.
HB.instance Definition _ d (T : cDistrLatticeType d) :=
DistrLattice_hasRelativeComplement.Build (dual_display d) T^d
(fun x y => rcomplPjoin y x) (fun x y => rcomplPmeet y x).
HB.instance Definition _ d (T : ctDistrLatticeType d) :=
CDistrLattice_hasSectionalComplement.Build (dual_display d) T^d codiffErcompl.
HB.instance Definition _ d (T : cbDistrLatticeType d) :=
CDistrLattice_hasDualSectionalComplement.Build (dual_display d) T^d
diffErcompl.
HB.instance Definition _ d (T : ctbDistrLatticeType d) :=
CDistrLattice_hasComplement.Build (dual_display d) T^d
complEcodiff complEdiff.
HB.saturate.
End DualOrder.
HB.export DualOrder.
(**********)
(* THEORY *)
(**********)
Module Import POrderTheory.
Include PreorderTheory.
Section POrderTheory.
Context {disp : disp_t} {T : porderType disp}.
Implicit Types (x y : T) (s : seq T).
Lemma le_anti: antisymmetric (<=%O : rel T).
Proof. exact: le_anti. Qed.
Lemma ge_anti: antisymmetric (>=%O : rel T).
Proof. by move=> x y /le_anti. Qed.
Lemma eq_le x y: (x == y) = (x <= y <= x).
Proof. by apply/eqP/idP => [->|/le_anti]; rewrite ?lexx. Qed.
Lemma lt_def x y : (x < y) = (y != x) && (x <= y).
Proof.
rewrite andbC lt_le_def; case/boolP: (x <= y) => //= xy.
congr negb; apply/idP/eqP => [yx|->]; last exact/lexx.
by apply/le_anti; rewrite yx.
Qed.
Lemma lt_neqAle x y: (x < y) = (x != y) && (x <= y).
Proof. by rewrite lt_def eq_sym. Qed.
Lemma le_eqVlt x y: (x <= y) = (x == y) || (x < y).
Proof. by rewrite lt_neqAle; case: eqP => //= ->; rewrite lexx. Qed.
Definition lte_anti := (=^~ eq_le, @lt_asym disp T, @lt_le_asym disp T, @le_lt_asym disp T).
Lemma lt_sorted_uniq_le s : sorted <%O s = uniq s && sorted <=%O s.
Proof.
rewrite le_sorted_pairwise lt_sorted_pairwise uniq_pairwise -pairwise_relI.
by apply/eq_pairwise => ? ?; rewrite lt_neqAle.
Qed.
Lemma le_sorted_eq s1 s2 :
sorted <=%O s1 -> sorted <=%O s2 -> perm_eq s1 s2 -> s1 = s2.
Proof. exact/sorted_eq/le_anti/le_trans. Qed.
Lemma count_lt_le_mem x s : (count (< x) s < count (<= x) s)%N = (x \in s).
Proof.
have := count_predUI (pred1 x) (< x) s.
have -> : count (predI (pred1 x) (< x)) s = 0%N.
rewrite (@eq_count _ _ pred0) ?count_pred0 // => y /=.
by rewrite lt_neqAle; case: eqP => //= ->; rewrite eqxx.
have /eq_count-> : [predU1 x & < x] =1 (<= x) by move=> y /=; rewrite le_eqVlt.
by rewrite addn0 => ->; rewrite -add1n leq_add2r -has_count has_pred1.
Qed.
Lemma comparable_ltgtP x y : x >=< y ->
compare x y (min y x) (min x y) (max y x) (max x y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof.
rewrite /min /max />=<%O !le_eqVlt [y == x]eq_sym.
have := (eqVneq x y, (boolP (x < y), boolP (y < x))).
move=> [[->//|neq_xy /=] [[] xy [] //=]] ; do ?by rewrite ?ltxx; constructor.
by rewrite ltxx in xy.
by rewrite le_gtF // ltW.
Qed.
Lemma comparable_leP x y : x >=< y ->
le_xor_gt x y (min y x) (min x y) (max y x) (max x y) (x <= y) (y < x).
Proof. by move=> /comparable_ltgtP [?|?|->]; constructor; rewrite // ltW. Qed.
Lemma comparable_ltP x y : x >=< y ->
lt_xor_ge x y (min y x) (min x y) (max y x) (max x y) (y <= x) (x < y).
Proof. by move=> /comparable_ltgtP [?|?|->]; constructor; rewrite // ltW. Qed.
Lemma comparableP x y : incompare x y
(min y x) (min x y) (max y x) (max x y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y)
(y >=< x) (x >=< y).
Proof.
rewrite ![y >=< _]comparable_sym; have [c_xy|i_xy] := boolP (x >=< y).
by case: (comparable_ltgtP c_xy) => ?; constructor.
by rewrite /min /max ?incomparable_eqF ?incomparable_leF;
rewrite ?incomparable_ltF// 1?comparable_sym //; constructor.
Qed.
(* leif *)
Lemma leifP x y C : reflect (x <= y ?= iff C) (if C then x == y else x < y).
Proof.
rewrite /leif le_eqVlt; apply: (iffP idP)=> [|[]].
by case: C => [/eqP->|lxy]; rewrite ?eqxx // lxy lt_eqF.
by move=> /orP[/eqP->|lxy] <-; rewrite ?eqxx // lt_eqF.
Qed.
Lemma leif_trans x1 x2 x3 C12 C23 :
x1 <= x2 ?= iff C12 -> x2 <= x3 ?= iff C23 -> x1 <= x3 ?= iff C12 && C23.
Proof.
move=> ltx12 ltx23; apply/leifP; rewrite -ltx12.
case eqx12: (x1 == x2).
by rewrite (eqP eqx12) lt_neqAle !ltx23 andbT; case C23.
by rewrite (@lt_le_trans _ _ x2) ?ltx23 // lt_neqAle eqx12 ltx12.
Qed.
Lemma leif_le x y : x <= y -> x <= y ?= iff (x >= y).
Proof. by move=> lexy; split=> //; rewrite eq_le lexy. Qed.
Lemma leif_eq x y : x <= y -> x <= y ?= iff (x == y).
Proof. by []. Qed.
Lemma ge_leif x y C : x <= y ?= iff C -> (y <= x) = C.
Proof. by case=> le_xy; rewrite eq_le le_xy. Qed.
Lemma lt_leif x y C : x <= y ?= iff C -> (x < y) = ~~ C.
Proof. by move=> le_xy; rewrite lt_neqAle !le_xy andbT. Qed.
Lemma ltNleif x y C : x <= y ?= iff ~~ C -> (x < y) = C.
Proof. by move=> /lt_leif; rewrite negbK. Qed.
(* lteif *)
Lemma lteif_anti C1 C2 x y :
(x < y ?<= if C1) && (y < x ?<= if C2) = C1 && C2 && (x == y).
Proof. by case: C1 C2 => [][]; rewrite lte_anti. Qed.
Lemma lteifN C x y : x < y ?<= if ~~ C -> ~~ (y < x ?<= if C).
Proof. by case: C => /=; case: comparableP. Qed.
(* min and max *)
Lemma minEle x y : min x y = if x <= y then x else y.
Proof. by case: comparableP. Qed.
Lemma maxEle x y : max x y = if x <= y then y else x.
Proof. by case: comparableP. Qed.
Lemma comparable_minEgt x y : x >=< y -> min x y = if x > y then y else x.
Proof. by case: comparableP. Qed.
Lemma comparable_maxEgt x y : x >=< y -> max x y = if x > y then x else y.
Proof. by case: comparableP. Qed.
Lemma comparable_minEge x y : x >=< y -> min x y = if x >= y then y else x.
Proof. by case: comparableP. Qed.
Lemma comparable_maxEge x y : x >=< y -> max x y = if x >= y then x else y.
Proof. by case: comparableP. Qed.
Lemma min_l x y : x <= y -> min x y = x. Proof. by case: comparableP. Qed.
Lemma min_r x y : y <= x -> min x y = y. Proof. by case: comparableP. Qed.
Lemma max_l x y : y <= x -> max x y = x. Proof. by case: comparableP. Qed.
Lemma max_r x y : x <= y -> max x y = y. Proof. by case: comparableP. Qed.
Lemma eq_minl x y : (min x y == x) = (x <= y).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP. Qed.
Lemma eq_maxr x y : (max x y == y) = (x <= y).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP. Qed.
Lemma min_idPl x y : reflect (min x y = x) (x <= y).
Proof. by rewrite -eq_minl; apply/eqP. Qed.
Lemma max_idPr x y : reflect (max x y = y) (x <= y).
Proof. by rewrite -eq_maxr; apply/eqP. Qed.
Section Comparable2.
Context (z x y : T) (cmp_xy : x >=< y).
Lemma comparable_minC : min x y = min y x.
Proof. by case: comparableP cmp_xy. Qed.
Lemma comparable_maxC : max x y = max y x.
Proof. by case: comparableP cmp_xy. Qed.
Lemma comparable_eq_minr : (min x y == y) = (y <= x).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP cmp_xy. Qed.
Lemma comparable_eq_maxl : (max x y == x) = (y <= x).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP cmp_xy. Qed.
Lemma comparable_min_idPr : reflect (min x y = y) (y <= x).
Proof. by rewrite -comparable_eq_minr; apply/eqP. Qed.
Lemma comparable_max_idPl : reflect (max x y = x) (y <= x).
Proof. by rewrite -comparable_eq_maxl; apply/eqP. Qed.
Lemma comparable_lteifNE C : x >=< y -> x < y ?<= if ~~ C = ~~ (y < x ?<= if C).
Proof. by case: C => /=; case: comparableP. Qed.
End Comparable2.
Section Comparable3.
Context (x y z : T) (cmp_xy : x >=< y) (cmp_xz : x >=< z) (cmp_yz : y >=< z).
Let P := comparableP.
Lemma comparable_max_minl : max (min x y) z = min (max x z) (max y z).
Proof.
move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/=.
move: (P x y) (P x z) (P y z).
move=> [xy|xy|xy|<-] [xz|xz|xz|<-] [yz|yz|yz|//->]//= _; rewrite ?ltxx//.
- by have := lt_trans xy (lt_trans yz xz); rewrite ltxx.
- by have := lt_trans xy (lt_trans xz yz); rewrite ltxx.
Qed.
End Comparable3.
Section Comparable4.
Context (x y z w : T) (cmp_xy : x >=< y) (cmp_zw : z >=< w).
Lemma comparable_le_min2 : x <= z -> y <= w ->
Order.min x y <= Order.min z w.
Proof.
move: cmp_xy cmp_zw => /comparable_leP[] xy /comparable_leP[] zw // xz yw.
- exact: le_trans xy yw.
- exact: le_trans (ltW xy) xz.
Qed.
Lemma comparable_le_max2 : x <= z -> y <= w ->
Order.max x y <= Order.max z w.
Proof.
move: cmp_xy cmp_zw => /comparable_leP[] xy /comparable_leP[] zw // xz yw.
- exact: le_trans yw (ltW zw).
- exact: le_trans xz zw.
Qed.
End Comparable4.
Lemma comparable_minAC x y z : x >=< y -> x >=< z -> y >=< z ->
min (min x y) z = min (min x z) y.
Proof.
move=> xy xz yz; rewrite -comparable_minA// [min y z]comparable_minC//.
by rewrite comparable_minA// 1?comparable_sym.
Qed.
Lemma comparable_maxAC x y z : x >=< y -> x >=< z -> y >=< z ->
max (max x y) z = max (max x z) y.
Proof.
move=> xy xz yz; rewrite -comparable_maxA// [max y z]comparable_maxC//.
by rewrite comparable_maxA// 1?comparable_sym.
Qed.
Lemma comparable_minCA x y z : x >=< y -> x >=< z -> y >=< z ->
min x (min y z) = min y (min x z).
Proof.
move=> xy xz yz; rewrite comparable_minA// [min x y]comparable_minC//.
by rewrite -comparable_minA// 1?comparable_sym.
Qed.
Lemma comparable_maxCA x y z : x >=< y -> x >=< z -> y >=< z ->
max x (max y z) = max y (max x z).
Proof.
move=> xy xz yz; rewrite comparable_maxA// [max x y]comparable_maxC//.
by rewrite -comparable_maxA// 1?comparable_sym.
Qed.
Lemma comparable_minACA x y z t :
x >=< y -> x >=< z -> x >=< t -> y >=< z -> y >=< t -> z >=< t ->
min (min x y) (min z t) = min (min x z) (min y t).
Proof.
move=> xy xz xt yz yt zt; rewrite comparable_minA// ?comparable_minl//.
rewrite [min _ z]comparable_minAC// -comparable_minA// ?comparable_minl//.
by rewrite inE comparable_sym.
Qed.
Lemma comparable_maxACA x y z t :
x >=< y -> x >=< z -> x >=< t -> y >=< z -> y >=< t -> z >=< t ->
max (max x y) (max z t) = max (max x z) (max y t).
Proof.
move=> xy xz xt yz yt zt; rewrite comparable_maxA// ?comparable_maxl//.
rewrite [max _ z]comparable_maxAC// -comparable_maxA// ?comparable_maxl//.
by rewrite inE comparable_sym.
Qed.
Lemma comparable_min_maxr x y z : x >=< y -> x >=< z -> y >=< z ->
min x (max y z) = max (min x y) (min x z).
Proof.
move=> xy xz yz; rewrite ![min x _]comparable_minC// ?comparable_maxr//.
by rewrite comparable_min_maxl// 1?comparable_sym.
Qed.
(* monotonicity *)
Lemma mono_in_leif (A : {pred T}) (f : T -> T) C :
{in A &, {mono f : x y / x <= y}} ->
{in A &, forall x y, (f x <= f y ?= iff C) = (x <= y ?= iff C)}.
Proof. by move=> mf x y Ax Ay; rewrite /leif !eq_le !mf. Qed.
Lemma mono_leif (f : T -> T) C :
{mono f : x y / x <= y} ->
forall x y, (f x <= f y ?= iff C) = (x <= y ?= iff C).
Proof. by move=> mf x y; rewrite /leif !eq_le !mf. Qed.
Lemma nmono_in_leif (A : {pred T}) (f : T -> T) C :
{in A &, {mono f : x y /~ x <= y}} ->
{in A &, forall x y, (f x <= f y ?= iff C) = (y <= x ?= iff C)}.
Proof. by move=> mf x y Ax Ay; rewrite /leif !eq_le !mf. Qed.
Lemma nmono_leif (f : T -> T) C : {mono f : x y /~ x <= y} ->
forall x y, (f x <= f y ?= iff C) = (y <= x ?= iff C).
Proof. by move=> mf x y; rewrite /leif !eq_le !mf. Qed.
Section bigminmax.
Context (I : Type) (r : seq I) (f : I -> T) (x0 x : T) (P : pred I).
Lemma bigmax_le : x0 <= x -> (forall i, P i -> f i <= x) ->
\big[max/x0]_(i <- r | P i) f i <= x.
Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite maxEle; case: ifPn. Qed.
Lemma le_bigmin : x <= x0 -> (forall i, P i -> x <= f i) ->
x <= \big[min/x0]_(i <- r | P i) f i.
Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite minEle; case: ifPn. Qed.
End bigminmax.
End POrderTheory.
#[global] Hint Resolve comparable_minr comparable_minl : core.
#[global] Hint Resolve comparable_maxr comparable_maxl : core.
Section ContraTheory.
Context {disp1 disp2 : disp_t} {T1 : porderType disp1} {T2 : porderType disp2}.
Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop).
Lemma contra_leT b x y : (~~ b -> x < y) -> (y <= x -> b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_ltT b x y : (~~ b -> x <= y) -> (y < x -> b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_leN b x y : (b -> x < y) -> (y <= x -> ~~ b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_ltN b x y : (b -> x <= y) -> (y < x -> ~~ b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_le_not P x y : (P -> x < y) -> (y <= x -> ~ P).
Proof. by case: comparableP => // _ PF _ /PF. Qed.
Lemma contra_lt_not P x y : (P -> x <= y) -> (y < x -> ~ P).
Proof. by case: comparableP => // _ PF _ /PF. Qed.
Lemma contra_leF b x y : (b -> x < y) -> (y <= x -> b = false).
Proof. by case: comparableP; case: b => // _ /implyP. Qed.
Lemma contra_ltF b x y : (b -> x <= y) -> (y < x -> b = false).
Proof. by case: comparableP; case: b => // _ /implyP. Qed.
Lemma contra_le_leq x y m n : ((n < m)%N -> y < x) -> (x <= y -> (m <= n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
Lemma contra_le_ltn x y m n : ((n <= m)%N -> y < x) -> (x <= y -> (m < n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
Lemma contra_lt_leq x y m n : ((n < m)%N -> y <= x) -> (x < y -> (m <= n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
Lemma contra_lt_ltn x y m n : ((n <= m)%N -> y <= x) -> (x < y -> (m < n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
End ContraTheory.
Section POrderMonotonyTheory.
Context {disp disp' : disp_t} {T : porderType disp} {T' : porderType disp'}.
Context (D D' : {pred T}) (f : T -> T').
Let leT_anti := @le_anti _ T.
Hint Resolve lexx lt_neqAle : core.
Let ge_antiT : antisymmetric (>=%O : rel T).
Proof. by move=> ? ? /le_anti. Qed.
Lemma ltW_homo : {homo f : x y / x < y} -> {homo f : x y / x <= y}.
Proof. exact: homoW. Qed.
Lemma ltW_nhomo : {homo f : x y /~ x < y} -> {homo f : x y /~ x <= y}.
Proof. by apply: homoW=> // x y; rewrite eq_sym. Qed.
Lemma inj_homo_lt :
injective f -> {homo f : x y / x <= y} -> {homo f : x y / x < y}.
Proof. exact: inj_homo. Qed.
Lemma inj_nhomo_lt :
injective f -> {homo f : x y /~ x <= y} -> {homo f : x y /~ x < y}.
Proof. by apply: inj_homo=> // x y; rewrite eq_sym. Qed.
Lemma inc_inj : {mono f : x y / x <= y} -> injective f.
Proof. exact: mono_inj. Qed.
Lemma dec_inj : {mono f : x y /~ x <= y} -> injective f.
Proof. exact: mono_inj. Qed.
(* Monotony in D D' *)
Lemma ltW_homo_in :
{in D & D', {homo f : x y / x < y}} -> {in D & D', {homo f : x y / x <= y}}.
Proof. exact: homoW_in. Qed.
Lemma ltW_nhomo_in :
{in D & D', {homo f : x y /~ x < y}} -> {in D & D', {homo f : x y /~ x <= y}}.
Proof. by apply: homoW_in=> // x y; rewrite eq_sym. Qed.
Lemma inj_homo_lt_in :
{in D & D', injective f} -> {in D & D', {homo f : x y / x <= y}} ->
{in D & D', {homo f : x y / x < y}}.
Proof. exact: inj_homo_in. Qed.
Lemma inj_nhomo_lt_in :
{in D & D', injective f} -> {in D & D', {homo f : x y /~ x <= y}} ->
{in D & D', {homo f : x y /~ x < y}}.
Proof. by apply: inj_homo_in=> // x y; rewrite eq_sym. Qed.
Lemma inc_inj_in : {in D &, {mono f : x y / x <= y}} ->
{in D &, injective f}.
Proof. exact: mono_inj_in. Qed.
Lemma dec_inj_in :
{in D &, {mono f : x y /~ x <= y}} -> {in D &, injective f}.
Proof. exact: mono_inj_in. Qed.
End POrderMonotonyTheory.
End POrderTheory.
Arguments leifP {disp T x y C}.
Arguments mono_in_leif [disp T A f C].
Arguments nmono_in_leif [disp T A f C].
Arguments mono_leif [disp T f C].
Arguments nmono_leif [disp T f C].
Arguments min_idPl {disp T x y}.
Arguments max_idPr {disp T x y}.
Arguments comparable_min_idPr {disp T x y _}.
Arguments comparable_max_idPl {disp T x y _}.
Module Import BPOrderTheory.
Export BPreorderTheory.
Section BPOrderTheory.
Context {disp : disp_t} {T : bPOrderType disp}.
Implicit Types (x y : T).
Lemma lex0 x : (x <= \bot) = (x == \bot).
Proof. by rewrite le_eqVlt ltx0 orbF. Qed.
Lemma lt0x x : (\bot < x) = (x != \bot).
Proof. by rewrite lt_def le0x andbT. Qed.
Variant eq0_xor_gt0 x : bool -> bool -> Set :=
Eq0NotPOs : x = \bot -> eq0_xor_gt0 x true false
| POsNotEq0 : \bot < x -> eq0_xor_gt0 x false true.
Lemma posxP x : eq0_xor_gt0 x (x == \bot) (\bot < x).
Proof. by rewrite lt0x; have [] := eqVneq; constructor; rewrite ?lt0x. Qed.
End BPOrderTheory.
End BPOrderTheory.
Module Import TPOrderTheory.
Section TPOrderTheory.
Context {disp : disp_t} {T : tPOrderType disp}.
Implicit Types (x y : T).
Lemma le1x x : (\top <= x) = (x == \top). Proof. exact: (@lex0 _ T^d). Qed.
Lemma ltx1 x : (x < \top) = (x != \top). Proof. exact: (@lt0x _ T^d). Qed.
End TPOrderTheory.
End TPOrderTheory.
Module Import MeetTheory.
Section MeetTheory.
Context {disp : disp_t} {L : meetSemilatticeType disp}.
Implicit Types (x y : L).
(* interaction with order *)
Lemma lexI x y z : (x <= y `&` z) = (x <= y) && (x <= z).
Proof. exact: lexI. Qed.
Lemma leIr x y : y `&` x <= x.
Proof. by have:= le_refl (meet y x); rewrite lexI => /andP []. Qed.
Lemma leIl x y : x `&` y <= x.
Proof. by have:= le_refl (meet x y); rewrite lexI => /andP []. Qed.
Lemma leIxl x y z : y <= x -> y `&` z <= x.
Proof. exact/le_trans/leIl. Qed.
Lemma leIxr x y z : z <= x -> y `&` z <= x.
Proof. exact/le_trans/leIr. Qed.
Lemma leIx2 x y z : (y <= x) || (z <= x) -> y `&` z <= x.
Proof. by case/orP => [/leIxl|/leIxr]. Qed.
Lemma leEmeet x y : (x <= y) = (x `&` y == x).
Proof. by rewrite eq_le lexI leIl lexx. Qed.
Lemma eq_meetl x y : (x `&` y == x) = (x <= y).
Proof. by apply/esym/leEmeet. Qed.
Lemma eq_meetr x y : (x `&` y == y) = (y <= x).
Proof. by rewrite eq_le lexI leIr lexx andbT. Qed.
Lemma meet_idPl {x y} : reflect (x `&` y = x) (x <= y).
Proof. by rewrite -eq_meetl; apply/eqP. Qed.
Lemma meet_idPr {x y} : reflect (y `&` x = x) (x <= y).
Proof. by rewrite -eq_meetr; apply/eqP. Qed.
Lemma meet_l x y : x <= y -> x `&` y = x. Proof. exact/meet_idPl. Qed.
Lemma meet_r x y : y <= x -> x `&` y = y. Proof. exact/meet_idPr. Qed.
Lemma leIidl x y : (x <= x `&` y) = (x <= y).
Proof. by rewrite lexI lexx. Qed.
Lemma leIidr x y : (x <= y `&` x) = (x <= y).
Proof. by rewrite lexI lexx andbT. Qed.
Lemma leI2 x y z t : x <= z -> y <= t -> x `&` y <= z `&` t.
Proof. by move=> xz yt; rewrite lexI !leIx2 ?xz ?yt ?orbT //. Qed.
(* algebraic properties *)
Lemma meetC : commutative (@meet _ L).
Proof. by move=> x y; apply: le_anti; rewrite !lexI !leIr !leIl. Qed.
Lemma meetA : associative (@meet _ L).
Proof.
move=> x y z; apply: le_anti.
rewrite !lexI leIr leIl /= andbT -andbA.
rewrite ![_ `&` (_ `&` _) <= _]leIxr ?(leIr, leIl) //=.
by rewrite leIxl ?leIl // leIxl // leIr.
Qed.
HB.instance Definition _ := SemiGroup.isComLaw.Build L meet meetA meetC.
Lemma meetxx : idempotent_op (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Lemma meetAC : right_commutative (@meet _ L).
Proof. by move=> x y z; rewrite -!meetA [X in _ `&` X]meetC. Qed.
Lemma meetCA : left_commutative (@meet _ L).
Proof. by move=> x y z; rewrite !meetA [X in X `&` _]meetC. Qed.
Lemma meetACA : interchange (@meet _ L) (@meet _ L).
Proof. by move=> x y z t; rewrite !meetA [X in X `&` _]meetAC. Qed.
Lemma meetKI y x : x `&` (x `&` y) = x `&` y.
Proof. by rewrite meetA meetxx. Qed.
Lemma meetIK y x : (x `&` y) `&` y = x `&` y.
Proof. by rewrite -meetA meetxx. Qed.
Lemma meetKIC y x : x `&` (y `&` x) = x `&` y.
Proof. by rewrite meetC meetIK meetC. Qed.
Lemma meetIKC y x : y `&` x `&` y = x `&` y.
Proof. by rewrite meetAC meetC meetxx. Qed.
End MeetTheory.
End MeetTheory.
Arguments meet_idPl {disp L x y}.
Arguments meet_idPr {disp L x y}.
Module Import BMeetTheory.
Section BMeetTheory.
Context {disp : disp_t} {L : bMeetSemilatticeType disp}.
Lemma meet0x : left_zero \bot (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Lemma meetx0 : right_zero \bot (@meet _ L).
Proof. by move=> x; rewrite meetC meet0x. Qed.
HB.instance Definition _ := Monoid.isMulLaw.Build L \bot meet meet0x meetx0.
End BMeetTheory.
End BMeetTheory.
Module Import TMeetTheory.
Section TMeetTheory.
Context {disp : disp_t} {L : tMeetSemilatticeType disp}.
Implicit Types (I : finType) (T : eqType) (x y : L).
Lemma meetx1 : right_id \top (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Lemma meet1x : left_id \top (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite meetC meetx1. Qed.
Lemma meet_eq1 x y : (x `&` y == \top) = (x == \top) && (y == \top).
Proof.
apply/idP/idP; last by move=> /andP[/eqP-> /eqP->]; rewrite meetx1.
by move=> /eqP xIy1; rewrite -!le1x -xIy1 leIl leIr.
Qed.
HB.instance Definition _ := Monoid.isMonoidLaw.Build L \top meet meet1x meetx1.
Lemma meets_inf_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) :
x \in r -> P x -> \meet_(i <- r | P i) F i <= F x.
Proof. by move=> xr Px; rewrite (big_rem x) ?Px //= leIl. Qed.
Lemma meets_max_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) (u : L) :
x \in r -> P x -> F x <= u -> \meet_(x <- r | P x) F x <= u.
Proof. by move=> ? ?; apply/le_trans/meets_inf_seq. Qed.
Lemma meets_inf I (j : I) (P : {pred I}) (F : I -> L) :
P j -> \meet_(i | P i) F i <= F j.
Proof. exact: meets_inf_seq. Qed.
Lemma meets_max I (j : I) (u : L) (P : {pred I}) (F : I -> L) :
P j -> F j <= u -> \meet_(i | P i) F i <= u.
Proof. exact: meets_max_seq. Qed.
Lemma meets_ge J (r : seq J) (P : {pred J}) (F : J -> L) (u : L) :
(forall x : J, P x -> u <= F x) -> u <= \meet_(x <- r | P x) F x.
Proof. by move=> leFm; elim/big_rec: _ => // i x Px xu; rewrite lexI leFm. Qed.
Lemma meetsP_seq T (r : seq T) (P : {pred T}) (F : T -> L) (l : L) :
reflect (forall x : T, x \in r -> P x -> l <= F x)
(l <= \meet_(x <- r | P x) F x).
Proof.
apply: (iffP idP) => leFm => [x xr Px|].
exact/(le_trans leFm)/meets_inf_seq.
by rewrite big_seq_cond meets_ge// => x /andP[/leFm].
Qed.
Lemma meetsP I (l : L) (P : {pred I}) (F : I -> L) :
reflect (forall i : I, P i -> l <= F i) (l <= \meet_(i | P i) F i).
Proof. by apply: (iffP (meetsP_seq _ _ _ _)) => H ? ?; apply: H. Qed.
Lemma le_meets I (A B : {set I}) (F : I -> L) :
A \subset B -> \meet_(i in B) F i <= \meet_(i in A) F i.
Proof. by move=> /subsetP AB; apply/meetsP => i iA; apply/meets_inf/AB. Qed.
Lemma meets_setU I (A B : {set I}) (F : I -> L) :
\meet_(i in (A :|: B)) F i = \meet_(i in A) F i `&` \meet_(i in B) F i.
Proof.
rewrite -!big_enum; have /= <- := @big_cat _ _ meet.
apply/eq_big_idem; first exact: meetxx.
by move=> ?; rewrite mem_cat !fintype.mem_enum inE.
Qed.
Lemma meets_seq I (r : seq I) (F : I -> L) :
\meet_(i <- r) F i = \meet_(i in r) F i.
Proof.
by rewrite -big_enum; apply/eq_big_idem => ?; rewrite /= ?meetxx ?fintype.mem_enum.
Qed.
End TMeetTheory.
End TMeetTheory.
Module Import JoinTheory.
Section JoinTheory.
Context {disp : disp_t} {L : joinSemilatticeType disp}.
Implicit Types (x y : L).
(* interaction with order *)
Lemma leUx x y z : (x `|` y <= z) = (x <= z) && (y <= z).
Proof. exact: leUx. Qed.
Lemma leUr x y : x <= y `|` x. Proof. exact: (@leIr _ L^d). Qed.
Lemma leUl x y : x <= x `|` y. Proof. exact: (@leIl _ L^d). Qed.
Lemma lexUl x y z : x <= y -> x <= y `|` z.
Proof. exact: (@leIxl _ L^d). Qed.
Lemma lexUr x y z : x <= z -> x <= y `|` z.
Proof. exact: (@leIxr _ L^d). Qed.
Lemma lexU2 x y z : (x <= y) || (x <= z) -> x <= y `|` z.
Proof. exact: (@leIx2 _ L^d). Qed.
Lemma leEjoin x y : (x <= y) = (x `|` y == y).
Proof. by rewrite [LHS](@leEmeet _ L^d) meetC. Qed.
Lemma eq_joinl x y : (x `|` y == x) = (y <= x).
Proof. exact: (@eq_meetl _ L^d). Qed.
Lemma eq_joinr x y : (x `|` y == y) = (x <= y).
Proof. exact: (@eq_meetr _ L^d). Qed.
Lemma join_idPl {x y} : reflect (y `|` x = y) (x <= y).
Proof. exact: (@meet_idPl _ L^d). Qed.
Lemma join_idPr {x y} : reflect (x `|` y = y) (x <= y).
Proof. exact: (@meet_idPr _ L^d). Qed.
Lemma join_l x y : y <= x -> x `|` y = x. Proof. exact/join_idPl. Qed.
Lemma join_r x y : x <= y -> x `|` y = y. Proof. exact/join_idPr. Qed.
Lemma leUidl x y : (x `|` y <= y) = (x <= y).
Proof. exact: (@leIidr _ L^d). Qed.
Lemma leUidr x y : (y `|` x <= y) = (x <= y).
Proof. exact: (@leIidl _ L^d). Qed.
Lemma leU2 x y z t : x <= z -> y <= t -> x `|` y <= z `|` t.
Proof. exact: (@leI2 _ L^d). Qed.
(* algebraic properties *)
Lemma joinC : commutative (@join _ L). Proof. exact: (@meetC _ L^d). Qed.
Lemma joinA : associative (@join _ L). Proof. exact: (@meetA _ L^d). Qed.
HB.instance Definition _ := SemiGroup.isComLaw.Build L join joinA joinC.
Lemma joinxx : idempotent_op (@join _ L).
Proof. exact: (@meetxx _ L^d). Qed.
Lemma joinAC : right_commutative (@join _ L).
Proof. exact: (@meetAC _ L^d). Qed.
Lemma joinCA : left_commutative (@join _ L).
Proof. exact: (@meetCA _ L^d). Qed.
Lemma joinACA : interchange (@join _ L) (@join _ L).
Proof. exact: (@meetACA _ L^d). Qed.
Lemma joinKU y x : x `|` (x `|` y) = x `|` y.
Proof. exact: (@meetKI _ L^d). Qed.
Lemma joinUK y x : (x `|` y) `|` y = x `|` y.
Proof. exact: (@meetIK _ L^d). Qed.
Lemma joinKUC y x : x `|` (y `|` x) = x `|` y.
Proof. exact: (@meetKIC _ L^d). Qed.
Lemma joinUKC y x : y `|` x `|` y = x `|` y.
Proof. exact: (@meetIKC _ L^d). Qed.
End JoinTheory.
End JoinTheory.
Arguments join_idPl {disp L x y}.
Arguments join_idPr {disp L x y}.
Module Import BJoinTheory.
Section BJoinTheory.
Context {disp : disp_t} {L : bJoinSemilatticeType disp}.
Implicit Types (I : finType) (T : eqType) (x y : L).
Lemma joinx0 : right_id \bot (@join _ L).
Proof. exact: (@meetx1 _ L^d). Qed.
Lemma join0x : left_id \bot (@join _ L).
Proof. exact: (@meet1x _ L^d). Qed.
Lemma join_eq0 x y : (x `|` y == \bot) = (x == \bot) && (y == \bot).
Proof. exact: (@meet_eq1 _ L^d). Qed.
HB.instance Definition _ := Monoid.isMonoidLaw.Build L \bot join join0x joinx0.
Lemma joins_sup_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) :
x \in r -> P x -> F x <= \join_(i <- r | P i) F i.
Proof. exact: (@meets_inf_seq _ L^d). Qed.
Lemma joins_min_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) (l : L) :
x \in r -> P x -> l <= F x -> l <= \join_(x <- r | P x) F x.
Proof. exact: (@meets_max_seq _ L^d). Qed.
Lemma joins_sup I (j : I) (P : {pred I}) (F : I -> L) :
P j -> F j <= \join_(i | P i) F i.
Proof. exact: (@meets_inf _ L^d). Qed.
Lemma joins_min I (j : I) (l : L) (P : {pred I}) (F : I -> L) :
P j -> l <= F j -> l <= \join_(i | P i) F i.
Proof. exact: (@meets_max _ L^d). Qed.
Lemma joins_le J (r : seq J) (P : {pred J}) (F : J -> L) (u : L) :
(forall x : J, P x -> F x <= u) -> \join_(x <- r | P x) F x <= u.
Proof. exact: (@meets_ge _ L^d). Qed.
Lemma joinsP_seq T (r : seq T) (P : {pred T}) (F : T -> L) (u : L) :
reflect (forall x : T, x \in r -> P x -> F x <= u)
(\join_(x <- r | P x) F x <= u).
Proof. exact: (@meetsP_seq _ L^d). Qed.
Lemma joinsP I (u : L) (P : {pred I}) (F : I -> L) :
reflect (forall i : I, P i -> F i <= u) (\join_(i | P i) F i <= u).
Proof. exact: (@meetsP _ L^d). Qed.
Lemma le_joins I (A B : {set I}) (F : I -> L) :
A \subset B -> \join_(i in A) F i <= \join_(i in B) F i.
Proof. exact: (@le_meets _ L^d). Qed.
Lemma joins_setU I (A B : {set I}) (F : I -> L) :
\join_(i in (A :|: B)) F i = \join_(i in A) F i `|` \join_(i in B) F i.
Proof. exact: (@meets_setU _ L^d). Qed.
Lemma joins_seq I (r : seq I) (F : I -> L) :
\join_(i <- r) F i = \join_(i in r) F i.
Proof. exact: (@meets_seq _ L^d). Qed.
End BJoinTheory.
End BJoinTheory.
Module Import TJoinTheory.
Section TJoinTheory.
Context {disp : disp_t} {L : tJoinSemilatticeType disp}.
Lemma joinx1 : right_zero \top (@join _ L). Proof. exact: (@meetx0 _ L^d). Qed.
Lemma join1x : left_zero \top (@join _ L). Proof. exact: (@meet0x _ L^d). Qed.
HB.instance Definition _ := Monoid.isMulLaw.Build L \top join join1x joinx1.
End TJoinTheory.
End TJoinTheory.
Module Import LatticeTheory.
Section LatticeTheory.
Context {disp : disp_t} {L : latticeType disp}.
Implicit Types (x y : L).
Lemma meetUK x y : (x `&` y) `|` y = y. Proof. exact/join_idPr/leIr. Qed.
Lemma meetUKC x y : (y `&` x) `|` y = y. Proof. by rewrite meetC meetUK. Qed.
Lemma meetKUC y x : x `|` (y `&` x) = x. Proof. by rewrite joinC meetUK. Qed.
Lemma meetKU y x : x `|` (x `&` y) = x. Proof. by rewrite meetC meetKUC. Qed.
Lemma joinIK x y : (x `|` y) `&` y = y. Proof. exact/meet_idPr/leUr. Qed.
Lemma joinIKC x y : (y `|` x) `&` y = y. Proof. by rewrite joinC joinIK. Qed.
Lemma joinKIC y x : x `&` (y `|` x) = x. Proof. by rewrite meetC joinIK. Qed.
Lemma joinKI y x : x `&` (x `|` y) = x. Proof. by rewrite joinC joinKIC. Qed.
(* comparison predicates *)
Lemma lcomparableP x y : incomparel x y
(min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y) (y >=< x) (x >=< y).
Proof.
by case: (comparableP x) => [hxy|hxy|hxy|->]; do 1?have hxy' := ltW hxy;
rewrite ?(meetxx, joinxx);
rewrite ?(meet_l hxy', meet_r hxy', join_l hxy', join_r hxy');
constructor.
Qed.
Lemma lcomparable_ltgtP x y : x >=< y ->
comparel x y (min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof. by case: (lcomparableP x) => // *; constructor. Qed.
Lemma lcomparable_leP x y : x >=< y ->
lel_xor_gt x y (min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y) (x <= y) (y < x).
Proof. by move/lcomparable_ltgtP => [/ltW xy|xy|->]; constructor. Qed.
Lemma lcomparable_ltP x y : x >=< y ->
ltl_xor_ge x y (min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y) (y <= x) (x < y).
Proof. by move=> /lcomparable_ltgtP [xy|/ltW xy|->]; constructor. Qed.
End LatticeTheory.
End LatticeTheory.
Module Import DistrLatticeTheory.
Section DistrLatticeTheory.
Context {disp : disp_t} {L : distrLatticeType disp}.
Lemma meetUl : left_distributive (@meet _ L) (@join _ L).
Proof. exact: meetUl. Qed.
Lemma meetUr : right_distributive (@meet _ L) (@join _ L).
Proof. by move=> x y z; rewrite ![x `&` _]meetC meetUl. Qed.
Lemma joinIl : left_distributive (@join _ L) (@meet _ L).
Proof. exact: joinIl. Qed.
Lemma joinIr : right_distributive (@join _ L) (@meet _ L).
Proof. by move=> x y z; rewrite ![x `|` _]joinC joinIl. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := Monoid.isAddLaw.Build L meet join meetUl meetUr.
HB.instance Definition _ := Monoid.isAddLaw.Build L join meet joinIl joinIr.
End DistrLatticeTheory.
End DistrLatticeTheory.
Module Import BDistrLatticeTheory.
Section BDistrLatticeTheory.
Context {disp : disp_t} {L : bDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma leU2l_le y t x z : x `&` t = \bot -> x `|` y <= z `|` t -> x <= z.
Proof.
by move=> xIt0 /(leI2 (lexx x)); rewrite joinKI meetUr xIt0 joinx0 leIidl.
Qed.
Lemma leU2r_le y t x z : x `&` t = \bot -> y `|` x <= t `|` z -> x <= z.
Proof. by rewrite joinC [_ `|` z]joinC => /leU2l_le H /H. Qed.
Lemma disjoint_lexUl z x y : x `&` z = \bot -> (x <= y `|` z) = (x <= y).
Proof.
move=> xz0; apply/idP/idP=> xy; last by rewrite lexU2 ?xy.
by apply: (@leU2l_le x z); rewrite ?joinxx.
Qed.
Lemma disjoint_lexUr z x y : x `&` z = \bot -> (x <= z `|` y) = (x <= y).
Proof. by move=> xz0; rewrite joinC; rewrite disjoint_lexUl. Qed.
Lemma leU2E x y z t : x `&` t = \bot -> y `&` z = \bot ->
(x `|` y <= z `|` t) = (x <= z) && (y <= t).
Proof.
move=> dxt dyz; apply/idP/andP; last by case=> ? ?; exact: leU2.
by move=> lexyzt; rewrite (leU2l_le _ lexyzt) // (leU2r_le _ lexyzt).
Qed.
Lemma joins_disjoint (I : finType) (d : L) (P : {pred I}) (F : I -> L) :
(forall i : I, P i -> d `&` F i = \bot) -> d `&` \join_(i | P i) F i = \bot.
Proof.
move=> d_Fi_disj; have : \big[andb/true]_(i | P i) (d `&` F i == \bot).
rewrite big_all_cond; apply/allP => i _ /=.
by apply/implyP => /d_Fi_disj ->.
elim/big_rec2: _ => [|i y]; first by rewrite meetx0.
case; rewrite (andbF, andbT) // => Pi /(_ isT) dy /eqP dFi.
by rewrite meetUr dy dFi joinxx.
Qed.
End BDistrLatticeTheory.
End BDistrLatticeTheory.
Module Import TDistrLatticeTheory.
Section TDistrLatticeTheory.
Context {disp : disp_t} {L : tDistrLatticeType disp}.
Implicit Types (x y : L).
Lemma leI2l_le y t x z : y `|` z = \top -> x `&` y <= z `&` t -> x <= z.
Proof. by rewrite joinC; exact: (@leU2l_le _ L^d). Qed.
Lemma leI2r_le y t x z : y `|` z = \top -> y `&` x <= t `&` z -> x <= z.
Proof. by rewrite joinC; exact: (@leU2r_le _ L^d). Qed.
Lemma cover_leIxl z x y : z `|` y = \top -> (x `&` z <= y) = (x <= y).
Proof. by rewrite joinC; exact: (@disjoint_lexUl _ L^d). Qed.
Lemma cover_leIxr z x y : z `|` y = \top -> (z `&` x <= y) = (x <= y).
Proof. by rewrite joinC; exact: (@disjoint_lexUr _ L^d). Qed.
Lemma leI2E x y z t : x `|` t = \top -> y `|` z = \top ->
(x `&` y <= z `&` t) = (x <= z) && (y <= t).
Proof. by move=> ? ?; apply: (@leU2E _ L^d); rewrite meetC. Qed.
Lemma meets_total (I : finType) (d : L) (P : {pred I}) (F : I -> L) :
(forall i : I, P i -> d `|` F i = \top) -> d `|` \meet_(i | P i) F i = \top.
Proof. exact: (@joins_disjoint _ L^d). Qed.
End TDistrLatticeTheory.
End TDistrLatticeTheory.
Module Import TotalTheory.
Section TotalTheory.
Context {disp : disp_t} {T : orderType disp}.
Implicit Types (x y z t : T) (s : seq T).
Definition le_total : total (<=%O : rel T) := le_total.
Hint Resolve le_total : core.
Lemma ge_total : total (>=%O : rel T).
Proof. by move=> ? ?; apply: le_total. Qed.
Hint Resolve ge_total : core.
Lemma comparableT x y : x >=< y. Proof. exact: le_total. Qed.
Hint Extern 0 (is_true (_ >=< _)%O) => solve [apply: comparableT] : core.
Lemma sort_le_sorted s : sorted <=%O (sort <=%O s).
Proof. exact: sort_sorted. Qed.
Hint Resolve sort_le_sorted : core.
Lemma sort_lt_sorted s : sorted <%O (sort <=%O s) = uniq s.
Proof. by rewrite lt_sorted_uniq_le sort_uniq sort_le_sorted andbT. Qed.
Lemma perm_sort_leP s1 s2 : reflect (sort <=%O s1 = sort <=%O s2) (perm_eq s1 s2).
Proof. exact/perm_sortP/le_anti/le_trans/le_total. Qed.
Lemma filter_sort_le p s : filter p (sort <=%O s) = sort <=%O (filter p s).
Proof. exact/filter_sort/le_trans/le_total. Qed.
Lemma mask_sort_le s (m : bitseq) :
{m_s : bitseq | mask m_s (sort <=%O s) = sort <=%O (mask m s)}.
Proof. exact/mask_sort/le_trans/le_total. Qed.
Lemma sorted_mask_sort_le s (m : bitseq) :
sorted <=%O (mask m s) -> {m_s : bitseq | mask m_s (sort <=%O s) = mask m s}.
Proof. exact/sorted_mask_sort/le_trans/le_total. Qed.
Lemma subseq_sort_le : {homo sort <=%O : s1 s2 / @subseq T s1 s2}.
Proof. exact/subseq_sort/le_trans/le_total. Qed.
Lemma sorted_subseq_sort_le s1 s2 :
subseq s1 s2 -> sorted <=%O s1 -> subseq s1 (sort <=%O s2).
Proof. exact/sorted_subseq_sort/le_trans/le_total. Qed.
Lemma mem2_sort_le s x y : x <= y -> mem2 s x y -> mem2 (sort <=%O s) x y.
Proof. exact/mem2_sort/le_trans/le_total. Qed.
Lemma leNgt x y : (x <= y) = ~~ (y < x). Proof. exact: comparable_leNgt. Qed.
Lemma ltNge x y : (x < y) = ~~ (y <= x). Proof. exact: comparable_ltNge. Qed.
Definition ltgtP x y := LatticeTheory.lcomparable_ltgtP (comparableT x y).
Definition leP x y := LatticeTheory.lcomparable_leP (comparableT x y).
Definition ltP x y := LatticeTheory.lcomparable_ltP (comparableT x y).
Lemma wlog_le P :
(forall x y, P y x -> P x y) -> (forall x y, x <= y -> P x y) ->
forall x y, P x y.
Proof. by move=> sP hP x y; case: (leP x y) => [| /ltW] /hP // /sP. Qed.
Lemma wlog_lt P :
(forall x, P x x) ->
(forall x y, (P y x -> P x y)) -> (forall x y, x < y -> P x y) ->
forall x y, P x y.
Proof. by move=> rP sP hP x y; case: (ltgtP x y) => [||->] // /hP // /sP. Qed.
Lemma neq_lt x y : (x != y) = (x < y) || (y < x). Proof. by case: ltgtP. Qed.
Lemma lt_total x y : x != y -> (x < y) || (y < x). Proof. by case: ltgtP. Qed.
Lemma eq_leLR x y z t :
(x <= y -> z <= t) -> (y < x -> t < z) -> (x <= y) = (z <= t).
Proof. by rewrite !ltNge => ? /contraTT ?; apply/idP/idP. Qed.
Lemma eq_leRL x y z t :
(x <= y -> z <= t) -> (y < x -> t < z) -> (z <= t) = (x <= y).
Proof. by move=> *; apply/esym/eq_leLR. Qed.
Lemma eq_ltLR x y z t :
(x < y -> z < t) -> (y <= x -> t <= z) -> (x < y) = (z < t).
Proof. by rewrite !leNgt => ? /contraTT ?; apply/idP/idP. Qed.
Lemma eq_ltRL x y z t :
(x < y -> z < t) -> (y <= x -> t <= z) -> (z < t) = (x < y).
Proof. by move=> *; apply/esym/eq_ltLR. Qed.
(* max and min is join and meet *)
Lemma meetEtotal x y : x `&` y = min x y. Proof. by case: leP. Qed.
Lemma joinEtotal x y : x `|` y = max x y. Proof. by case: leP. Qed.
(* max and min theory *)
Lemma minEgt x y : min x y = if x > y then y else x. Proof. by case: ltP. Qed.
Lemma maxEgt x y : max x y = if x > y then x else y. Proof. by case: ltP. Qed.
Lemma minEge x y : min x y = if x >= y then y else x. Proof. by case: leP. Qed.
Lemma maxEge x y : max x y = if x >= y then x else y. Proof. by case: leP. Qed.
Lemma minC : commutative (min : T -> T -> T).
Proof. by move=> x y; apply: comparable_minC. Qed.
Lemma maxC : commutative (max : T -> T -> T).
Proof. by move=> x y; apply: comparable_maxC. Qed.
Lemma minA : associative (min : T -> T -> T).
Proof. by move=> x y z; apply: comparable_minA. Qed.
Lemma maxA : associative (max : T -> T -> T).
Proof. by move=> x y z; apply: comparable_maxA. Qed.
Lemma minAC : right_commutative (min : T -> T -> T).
Proof. by move=> x y z; apply: comparable_minAC. Qed.
Lemma maxAC : right_commutative (max : T -> T -> T).
Proof. by move=> x y z; apply: comparable_maxAC. Qed.
Lemma minCA : left_commutative (min : T -> T -> T).
Proof. by move=> x y z; apply: comparable_minCA. Qed.
Lemma maxCA : left_commutative (max : T -> T -> T).
Proof. by move=> x y z; apply: comparable_maxCA. Qed.
Lemma minACA : interchange (min : T -> T -> T) min.
Proof. by move=> x y z t; apply: comparable_minACA. Qed.
Lemma maxACA : interchange (max : T -> T -> T) max.
Proof. by move=> x y z t; apply: comparable_maxACA. Qed.
Lemma eq_minr x y : (min x y == y) = (y <= x).
Proof. exact: comparable_eq_minr. Qed.
Lemma eq_maxl x y : (max x y == x) = (y <= x).
Proof. exact: comparable_eq_maxl. Qed.
Lemma min_idPr x y : reflect (min x y = y) (y <= x).
Proof. exact: comparable_min_idPr. Qed.
Lemma max_idPl x y : reflect (max x y = x) (y <= x).
Proof. exact: comparable_max_idPl. Qed.
Lemma le_min z x y : (z <= min x y) = (z <= x) && (z <= y).
Proof. exact: comparable_le_min. Qed.
Lemma ge_min z x y : (min x y <= z) = (x <= z) || (y <= z).
Proof. exact: comparable_ge_min. Qed.
Lemma lt_min z x y : (z < min x y) = (z < x) && (z < y).
Proof. exact: comparable_lt_min. Qed.
Lemma gt_min z x y : (min x y < z) = (x < z) || (y < z).
Proof. exact: comparable_gt_min. Qed.
Lemma le_max z x y : (z <= max x y) = (z <= x) || (z <= y).
Proof. exact: comparable_le_max. Qed.
Lemma ge_max z x y : (max x y <= z) = (x <= z) && (y <= z).
Proof. exact: comparable_ge_max. Qed.
Lemma lt_max z x y : (z < max x y) = (z < x) || (z < y).
Proof. exact: comparable_lt_max. Qed.
Lemma gt_max z x y : (max x y < z) = (x < z) && (y < z).
Proof. exact: comparable_gt_max. Qed.
Lemma minxK x y : max (min x y) y = y. Proof. exact: comparable_minxK. Qed.
Lemma minKx x y : max x (min x y) = x. Proof. exact: comparable_minKx. Qed.
Lemma maxxK x y : min (max x y) y = y. Proof. exact: comparable_maxxK. Qed.
Lemma maxKx x y : min x (max x y) = x. Proof. exact: comparable_maxKx. Qed.
Lemma max_minl : left_distributive (max : T -> T -> T) min.
Proof. by move=> x y z; apply: comparable_max_minl. Qed.
Lemma min_maxl : left_distributive (min : T -> T -> T) max.
Proof. by move=> x y z; apply: comparable_min_maxl. Qed.
Lemma max_minr : right_distributive (max : T -> T -> T) min.
Proof. by move=> x y z; apply: comparable_max_minr. Qed.
Lemma min_maxr : right_distributive (min : T -> T -> T) max.
Proof. by move=> x y z; apply: comparable_min_maxr. Qed.
HB.instance Definition _ := SemiGroup.isComLaw.Build T max maxA maxC.
HB.instance Definition _ := SemiGroup.isComLaw.Build T min minA minC.
Lemma leIx x y z : (meet y z <= x) = (y <= x) || (z <= x).
Proof. by rewrite meetEtotal ge_min. Qed.
Lemma lexU x y z : (x <= join y z) = (x <= y) || (x <= z).
Proof. by rewrite joinEtotal le_max. Qed.
Lemma ltxI x y z : (x < meet y z) = (x < y) && (x < z).
Proof. by rewrite !ltNge leIx negb_or. Qed.
Lemma ltIx x y z : (meet y z < x) = (y < x) || (z < x).
Proof. by rewrite !ltNge lexI negb_and. Qed.
Lemma ltxU x y z : (x < join y z) = (x < y) || (x < z).
Proof. by rewrite !ltNge leUx negb_and. Qed.
Lemma ltUx x y z : (join y z < x) = (y < x) && (z < x).
Proof. by rewrite !ltNge lexU negb_or. Qed.
Definition ltexI := (@lexI _ T, ltxI).
Definition lteIx := (leIx, ltIx).
Definition ltexU := (lexU, ltxU).
Definition lteUx := (@leUx _ T, ltUx).
Lemma le_min2 x y z t : x <= z -> y <= t -> Order.min x y <= Order.min z t.
Proof. exact: comparable_le_min2. Qed.
Lemma le_max2 x y z t : x <= z -> y <= t -> Order.max x y <= Order.max z t.
Proof. exact: comparable_le_max2. Qed.
(* lteif *)
Lemma lteifNE x y C : x < y ?<= if ~~ C = ~~ (y < x ?<= if C).
Proof. by case: C => /=; case: leP. Qed.
Lemma lteif_minr z x y C :
(z < min x y ?<= if C) = (z < x ?<= if C) && (z < y ?<= if C).
Proof. by case: C; rewrite /= (le_min, lt_min). Qed.
Lemma lteif_minl z x y C :
(min x y < z ?<= if C) = (x < z ?<= if C) || (y < z ?<= if C).
Proof. by case: C; rewrite /= (ge_min, gt_min). Qed.
Lemma lteif_maxr z x y C :
(z < max x y ?<= if C) = (z < x ?<= if C) || (z < y ?<= if C).
Proof. by case: C; rewrite /= (le_max, lt_max). Qed.
Lemma lteif_maxl z x y C :
(max x y < z ?<= if C) = (x < z ?<= if C) && (y < z ?<= if C).
Proof. by case: C; rewrite /= (ge_max, gt_max). Qed.
Section ArgExtremum.
Context (I : finType) (i0 : I) (P : {pred I}) (F : I -> T) (Pi0 : P i0).
Lemma arg_minP: extremum_spec <=%O P F (arg_min i0 P F).
Proof. by apply: extremumP => //; apply: le_trans. Qed.
Lemma arg_maxP: extremum_spec >=%O P F (arg_max i0 P F).
Proof. by apply: extremumP => //; [apply: ge_refl | apply: ge_trans]. Qed.
End ArgExtremum.
Lemma count_le_gt x s : count (<= x) s = size s - count (> x) s.
Proof.
by rewrite -(count_predC (> x)) addKn; apply: eq_count => y; rewrite /= leNgt.
Qed.
Lemma count_lt_ge x s : count (< x) s = size s - count (>= x) s.
Proof.
by rewrite -(count_predC (>= x)) addKn; apply: eq_count => y; rewrite /= ltNge.
Qed.
Section bigminmax_Type.
Context (I : Type) (r : seq I) (x : T).
Implicit Types (P : pred I) (F : I -> T).
Lemma bigmin_mkcond P F : \big[min/x]_(i <- r | P i) F i =
\big[min/x]_(i <- r) (if P i then F i else x).
Proof. by rewrite big_mkcond_idem //= minxx. Qed.
Lemma bigmax_mkcond P F :
\big[max/x]_(i <- r | P i) F i = \big[max/x]_(i <- r) if P i then F i else x.
Proof. by rewrite big_mkcond_idem //= maxxx. Qed.
Lemma bigmin_mkcondl P Q F :
\big[min/x]_(i <- r | P i && Q i) F i
= \big[min/x]_(i <- r | Q i) if P i then F i else x.
Proof.
rewrite bigmin_mkcond [RHS]bigmin_mkcond.
by apply: eq_bigr => i _; case: P; case: Q.
Qed.
Lemma bigmin_mkcondr P Q F :
\big[min/x]_(i <- r | P i && Q i) F i
= \big[min/x]_(i <- r | P i) if Q i then F i else x.
Proof. by under eq_bigl do rewrite andbC; apply: bigmin_mkcondl. Qed.
Lemma bigmax_mkcondl P Q F :
\big[max/x]_(i <- r | P i && Q i) F i
= \big[max/x]_(i <- r | Q i) if P i then F i else x.
Proof.
rewrite bigmax_mkcond [RHS]bigmax_mkcond.
by apply: eq_bigr => i _; case: P; case: Q.
Qed.
Lemma bigmax_mkcondr P Q F :
\big[max/x]_(i <- r | P i && Q i) F i
= \big[max/x]_(i <- r | P i) if Q i then F i else x.
Proof. by under eq_bigl do rewrite andbC; apply: bigmax_mkcondl. Qed.
Lemma bigmin_split P F1 F2 :
\big[min/x]_(i <- r | P i) (min (F1 i) (F2 i)) =
min (\big[min/x]_(i <- r | P i) F1 i) (\big[min/x]_(i <- r | P i) F2 i).
Proof. by rewrite big_split_idem //= minxx. Qed.
Lemma bigmax_split P F1 F2 :
\big[max/x]_(i <- r | P i) (max (F1 i) (F2 i)) =
max (\big[max/x]_(i <- r | P i) F1 i) (\big[max/x]_(i <- r | P i) F2 i).
Proof. by rewrite big_split_idem //= maxxx. Qed.
Lemma bigmin_idl P F :
\big[min/x]_(i <- r | P i) F i = min x (\big[min/x]_(i <- r | P i) F i).
Proof. by rewrite minC big_id_idem //= minxx. Qed.
Lemma bigmax_idl P F :
\big[max/x]_(i <- r | P i) F i = max x (\big[max/x]_(i <- r | P i) F i).
Proof. by rewrite maxC big_id_idem //= maxxx. Qed.
Lemma bigmin_idr P F :
\big[min/x]_(i <- r | P i) F i = min (\big[min/x]_(i <- r | P i) F i) x.
Proof. by rewrite [LHS]bigmin_idl minC. Qed.
Lemma bigmax_idr P F :
\big[max/x]_(i <- r | P i) F i = max (\big[max/x]_(i <- r | P i) F i) x.
Proof. by rewrite [LHS]bigmax_idl maxC. Qed.
Lemma bigminID a P F : \big[min/x]_(i <- r | P i) F i =
min (\big[min/x]_(i <- r | P i && a i) F i)
(\big[min/x]_(i <- r | P i && ~~ a i) F i).
Proof. by rewrite (bigID_idem _ _ a) //= minxx. Qed.
Lemma bigmaxID a P F : \big[max/x]_(i <- r | P i) F i =
max (\big[max/x]_(i <- r | P i && a i) F i)
(\big[max/x]_(i <- r | P i && ~~ a i) F i).
Proof. by rewrite (bigID_idem _ _ a) //= maxxx. Qed.
End bigminmax_Type.
Let ge_min_id (x y : T) : x >= min x y. Proof. by rewrite ge_min lexx. Qed.
Let le_max_id (x y : T) : x <= max x y. Proof. by rewrite le_max lexx. Qed.
Lemma sub_bigmin [x0] I r (P P' : {pred I}) (F : I -> T) :
(forall i, P' i -> P i) ->
\big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r | P' i) F i.
Proof. exact: (sub_le_big ge_refl). Qed.
Lemma sub_bigmax [x0] I r (P P' : {pred I}) (F : I -> T) :
(forall i, P i -> P' i) ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r | P' i) F i.
Proof. exact: sub_le_big. Qed.
(* FIXME: Remove that. *)
Local Notation "'{subset' x '<=' y '}'" :=
(sub_mem (mem x) (mem y)) (at level 0, x, y at level 1).
Lemma sub_bigmin_seq [x0] (I : eqType) r r' P (F : I -> T) : {subset r' <= r} ->
\big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r' | P i) F i.
Proof. exact: (idem_sub_le_big ge_refl _ minxx). Qed.
Lemma sub_bigmax_seq [x0] (I : eqType) r r' P (F : I -> T) : {subset r <= r'} ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r' | P i) F i.
Proof. exact: (idem_sub_le_big _ _ maxxx). Qed.
Lemma sub_bigmin_cond [x0] (I : eqType) r r' P P' (F : I -> T) :
{subset ([seq i <- r | P i]) <= ([seq i <- r' | P' i])} ->
\big[min/x0]_(i <- r' | P' i) F i <= \big[min/x0]_(i <- r | P i) F i.
Proof. exact: (idem_sub_le_big_cond ge_refl _ minxx). Qed.
Lemma sub_bigmax_cond [x0] (I : eqType) r r' P P' (F : I -> T) :
{subset ([seq i <- r | P i]) <= ([seq i <- r' | P' i])} ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r' | P' i) F i.
Proof. exact: (idem_sub_le_big_cond _ _ maxxx). Qed.
Lemma sub_in_bigmin [x0] [I : eqType] (r : seq I) (P P' : {pred I}) F :
{in r, forall i, P' i -> P i} ->
\big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r | P' i) F i.
Proof. exact: (sub_in_le_big ge_refl). Qed.
Lemma sub_in_bigmax [x0] [I : eqType] (r : seq I) (P P' : {pred I}) F :
{in r, forall i, P i -> P' i} ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r | P' i) F i.
Proof. exact: sub_in_le_big. Qed.
Lemma le_bigmin_nat [x0] n m n' m' P (F : nat -> T) :
(n <= n')%N -> (m' <= m)%N ->
\big[min/x0]_(n <= i < m | P i) F i <= \big[min/x0]_(n' <= i < m' | P i) F i.
Proof. exact: (le_big_nat ge_refl). Qed.
Lemma le_bigmax_nat [x0] n m n' m' P (F : nat -> T) :
(n' <= n)%N -> (m <= m')%N ->
\big[max/x0]_(n <= i < m | P i) F i <= \big[max/x0]_(n' <= i < m' | P i) F i.
Proof. exact: le_big_nat. Qed.
Lemma le_bigmin_nat_cond [x0] n m n' m' (P P' : pred nat) (F : nat -> T) :
(n <= n')%N -> (m' <= m)%N -> (forall i, (n' <= i < m')%N -> P' i -> P i) ->
\big[min/x0]_(n <= i < m | P i) F i <= \big[min/x0]_(n' <= i < m' | P' i) F i.
Proof. exact: (le_big_nat_cond ge_refl). Qed.
Lemma le_bigmax_nat_cond [x0] n m n' m' (P P' : {pred nat}) (F : nat -> T) :
(n' <= n)%N -> (m <= m')%N -> (forall i, (n <= i < m)%N -> P i -> P' i) ->
\big[max/x0]_(n <= i < m | P i) F i <= \big[max/x0]_(n' <= i < m' | P' i) F i.
Proof. exact: le_big_nat_cond. Qed.
Lemma le_bigmin_ord [x0] n m (P : pred nat) (F : nat -> T) : (m <= n)%N ->
\big[min/x0]_(i < n | P i) F i <= \big[min/x0]_(i < m | P i) F i.
Proof. exact: (le_big_ord ge_refl). Qed.
Lemma le_bigmax_ord [x0] n m (P : {pred nat}) (F : nat -> T) : (n <= m)%N ->
\big[max/x0]_(i < n | P i) F i <= \big[max/x0]_(i < m | P i) F i.
Proof. exact: le_big_ord. Qed.
Lemma le_bigmin_ord_cond [x0] n m (P P' : pred nat) (F : nat -> T) :
(m <= n)%N -> (forall i : 'I_m, P' i -> P i) ->
\big[min/x0]_(i < n | P i) F i <= \big[min/x0]_(i < m | P' i) F i.
Proof. exact: (le_big_ord_cond ge_refl). Qed.
Lemma le_bigmax_ord_cond [x0] n m (P P' : {pred nat}) (F : nat -> T) :
(n <= m)%N -> (forall i : 'I_n, P i -> P' i) ->
\big[max/x0]_(i < n | P i) F i <= \big[max/x0]_(i < m | P' i) F i.
Proof. exact: le_big_ord_cond. Qed.
Lemma subset_bigmin [x0] [I : finType] [A A' P : {pred I}] (F : I -> T) :
A' \subset A ->
\big[min/x0]_(i in A | P i) F i <= \big[min/x0]_(i in A' | P i) F i.
Proof. exact: (subset_le_big ge_refl). Qed.
Lemma subset_bigmax [x0] [I : finType] (A A' P : {pred I}) (F : I -> T) :
A \subset A' ->
\big[max/x0]_(i in A | P i) F i <= \big[max/x0]_(i in A' | P i) F i.
Proof. exact: subset_le_big. Qed.
Lemma subset_bigmin_cond [x0] (I : finType) (A A' P P' : {pred I}) (F : I -> T) :
[set i in A' | P' i] \subset [set i in A | P i] ->
\big[min/x0]_(i in A | P i) F i <= \big[min/x0]_(i in A' | P' i) F i.
Proof. exact: (subset_le_big_cond ge_refl). Qed.
Lemma subset_bigmax_cond [x0] (I : finType) (A A' P P' : {pred I}) (F : I -> T) :
[set i in A | P i] \subset [set i in A' | P' i] ->
\big[max/x0]_(i in A | P i) F i <= \big[max/x0]_(i in A' | P' i) F i.
Proof. exact: subset_le_big_cond. Qed.
Section bigminmax_eqType.
Context (I : eqType) (r : seq I) (x : T).
Implicit Types (P : pred I) (F : I -> T).
Lemma bigmin_le_id P F : \big[min/x]_(i <- r | P i) F i <= x.
Proof. by rewrite bigmin_idl. Qed.
Lemma bigmax_ge_id P F : \big[max/x]_(i <- r | P i) F i >= x.
Proof. by rewrite bigmax_idl. Qed.
Lemma bigmin_eq_id P F :
(forall i, P i -> x <= F i) -> \big[min/x]_(i <- r | P i) F i = x.
Proof. by move=> x_le; apply: le_anti; rewrite bigmin_le_id le_bigmin. Qed.
Lemma bigmax_eq_id P F :
(forall i, P i -> x >= F i) -> \big[max/x]_(i <- r | P i) F i = x.
Proof. by move=> x_ge; apply: le_anti; rewrite bigmax_ge_id bigmax_le. Qed.
End bigminmax_eqType.
Section bigminmax_finType.
Context (I : finType) (x : T).
Implicit Types (P : pred I) (F : I -> T).
Lemma bigminD1 j P F : P j ->
\big[min/x]_(i | P i) F i = min (F j) (\big[min/x]_(i | P i && (i != j)) F i).
Proof. by move/(bigD1 _) ->. Qed.
Lemma bigmaxD1 j P F : P j ->
\big[max/x]_(i | P i) F i = max (F j) (\big[max/x]_(i | P i && (i != j)) F i).
Proof. by move/(bigD1 _) ->. Qed.
Lemma bigmin_le_cond j P F : P j -> \big[min/x]_(i | P i) F i <= F j.
Proof.
have := mem_index_enum j; rewrite unlock; elim: (index_enum I) => //= i l ih.
rewrite inE => /orP [/eqP-> ->|/ih leminlfi Pi]; first by rewrite ge_min lexx.
by case: ifPn => Pj; [rewrite ge_min leminlfi// orbC|exact: leminlfi].
Qed.
Lemma le_bigmax_cond j P F : P j -> F j <= \big[max/x]_(i | P i) F i.
Proof. by move=> Pj; rewrite (bigmaxD1 _ Pj) le_max lexx. Qed.
Lemma bigmin_le j F : \big[min/x]_i F i <= F j.
Proof. exact: bigmin_le_cond. Qed.
Lemma le_bigmax F j : F j <= \big[max/x]_i F i.
Proof. exact: le_bigmax_cond. Qed.
Lemma bigmin_inf j P m F : P j -> F j <= m -> \big[min/x]_(i | P i) F i <= m.
Proof. by move=> Pj ?; apply: le_trans (bigmin_le_cond _ Pj) _. Qed.
(* NB: as of [2022-08-02], bigop.bigmax_sup already exists for nat *)
Lemma bigmax_sup j P m F : P j -> m <= F j -> m <= \big[max/x]_(i | P i) F i.
Proof. by move=> Pj ?; apply: le_trans (le_bigmax_cond _ Pj). Qed.
Lemma bigmin_geP m P F :
reflect (m <= x /\ forall i, P i -> m <= F i)
(m <= \big[min/x]_(i | P i) F i).
Proof.
apply: (iffP idP) => [lemFi|[lemx lemPi]]; [split|exact: le_bigmin].
- by rewrite (le_trans lemFi)// bigmin_idl ge_min lexx.
- by move=> i Pi; rewrite (le_trans lemFi)// (bigminD1 _ Pi)// le_minl lexx.
Qed.
Lemma bigmax_leP m P F :
reflect (x <= m /\ forall i, P i -> F i <= m)
(\big[max/x]_(i | P i) F i <= m).
Proof.
apply: (iffP idP) => [|[? ?]]; last exact: bigmax_le.
rewrite bigmax_idl ge_max => /andP[-> leFm]; split=> // i Pi.
by apply: le_trans leFm; exact: le_bigmax_cond.
Qed.
Lemma bigmin_gtP m P F :
reflect (m < x /\ forall i, P i -> m < F i) (m < \big[min/x]_(i | P i) F i).
Proof.
apply: (iffP idP) => [lemFi|[lemx lemPi]]; [split|exact: lt_bigmin].
- by rewrite (lt_le_trans lemFi)// bigmin_idl ge_min lexx.
- by move=> i Pi; rewrite (lt_le_trans lemFi)// (bigminD1 _ Pi)// le_minl lexx.
Qed.
Lemma bigmax_ltP m P F :
reflect (x < m /\ forall i, P i -> F i < m) (\big[max/x]_(i | P i) F i < m).
Proof.
apply: (iffP idP) => [|[? ?]]; last exact: bigmax_lt.
rewrite bigmax_idl gt_max => /andP[-> ltFm]; split=> // i Pi.
by apply: le_lt_trans ltFm; exact: le_bigmax_cond.
Qed.
Lemma bigmin_eq_arg j P F : P j -> (forall i, P i -> F i <= x) ->
\big[min/x]_(i | P i) F i = F [arg min_(i < j | P i) F i].
Proof.
move=> Pi0; case: arg_minP => //= i Pi PF PFx.
apply/eqP; rewrite eq_le bigmin_le_cond //=.
by apply/bigmin_geP; split => //; exact: PFx.
Qed.
Lemma bigmax_eq_arg j P F : P j -> (forall i, P i -> x <= F i) ->
\big[max/x]_(i | P i) F i = F [arg max_(i > j | P i) F i].
Proof.
move=> Pi0; case: arg_maxP => //= i Pi PF PxF.
apply/eqP; rewrite eq_le le_bigmax_cond // andbT.
by apply/bigmax_leP; split => //; exact: PxF.
Qed.
Lemma eq_bigmin j P F : P j -> (forall i, P i -> F i <= x) ->
{i0 | i0 \in P & \big[min/x]_(i | P i) F i = F i0}.
Proof.
by move=> Pi0 Hx; rewrite (bigmin_eq_arg Pi0) //; eexists=> //; case: arg_minP.
Qed.
Lemma eq_bigmax j P F : P j -> (forall i, P i -> x <= F i) ->
{i0 | i0 \in P & \big[max/x]_(i | P i) F i = F i0}.
Proof.
by move=> Pi0 Hx; rewrite (bigmax_eq_arg Pi0) //; eexists=> //; case: arg_maxP.
Qed.
Lemma le_bigmin2 P F1 F2 : (forall i, P i -> F1 i <= F2 i) ->
\big[min/x]_(i | P i) F1 i <= \big[min/x]_(i | P i) F2 i.
Proof.
move=> FG; elim/big_ind2 : _ => // a b e f ba fe.
rewrite ge_min 2!le_min ba fe /= andbT.
move: (le_total a e) => /orP[/(le_trans ba)-> // | /(le_trans fe)->].
by rewrite orbT.
Qed.
Lemma le_bigmax2 P F1 F2 : (forall i, P i -> F1 i <= F2 i) ->
\big[max/x]_(i | P i) F1 i <= \big[max/x]_(i | P i) F2 i.
Proof.
move=> FG; elim/big_ind2 : _ => // a b e f ba fe.
rewrite le_max 2!ge_max ba fe /= andbT; have [//|/= af] := leP f a.
by rewrite (le_trans ba) // (le_trans _ fe) // ltW.
Qed.
Lemma bigmaxUl (A B : {set I}) F :
\big[max/x]_(i in A) F i <= \big[max/x]_(i in A :|: B) F i.
Proof. by apply: sub_bigmax => t; rewrite in_setU => ->. Qed.
Lemma bigmaxUr (A B : {set I}) F :
\big[max/x]_(i in B) F i <= \big[max/x]_(i in A :|: B) F i.
Proof. by under [leRHS]eq_bigl do rewrite setUC; apply: bigmaxUl. Qed.
Lemma bigminUl (A B : {set I}) F :
\big[min/x]_(i in A) F i >= \big[min/x]_(i in A :|: B) F i.
Proof. by apply: sub_bigmin => t; rewrite in_setU => ->. Qed.
Lemma bigminUr (A B : {set I}) F :
\big[min/x]_(i in B) F i >= \big[min/x]_(i in A :|: B) F i.
Proof. by under [leLHS]eq_bigl do rewrite setUC; apply: bigminUl. Qed.
Lemma bigmaxIl (A B : {set I}) F :
\big[max/x]_(i in A) F i >= \big[max/x]_(i in A :&: B) F i.
Proof. by apply: sub_bigmax => t; rewrite in_setI => /andP[-> _]. Qed.
Lemma bigmaxIr (A B : {set I}) F :
\big[max/x]_(i in B) F i >= \big[max/x]_(i in A :&: B) F i.
Proof. by under eq_bigl do rewrite setIC; apply: bigmaxIl. Qed.
Lemma bigminIl (A B : {set I}) F :
\big[min/x]_(i in A) F i <= \big[min/x]_(i in A :&: B) F i.
Proof. by apply: sub_bigmin => t; rewrite in_setI => /andP[->_]. Qed.
Lemma bigminIr (A B : {set I}) F :
\big[min/x]_(i in B) F i <= \big[min/x]_(i in A :&: B) F i.
Proof. by under [leRHS]eq_bigl do rewrite setIC; apply: bigminIl. Qed.
Lemma bigmaxD (A B : {set I}) F :
\big[max/x]_(i in B) F i >= \big[max/x]_(i in B :\: A) F i.
Proof. by apply: sub_bigmax => t; rewrite in_setD => /andP[_->]. Qed.
Lemma bigminD (A B : {set I}) F :
\big[min/x]_(i in B) F i <= \big[min/x]_(i in B :\: A) F i.
Proof. by apply: sub_bigmin => t; rewrite in_setD => /andP[_->]. Qed.
Lemma bigmaxU (A B : {set I}) F :
\big[max/x]_(i in A :|: B) F i
= max (\big[max/x]_(i in A) F i) (\big[max/x]_(i in B) F i).
Proof.
apply: le_anti; rewrite ge_max bigmaxUl bigmaxUr !andbT; apply/bigmax_leP.
split=> [|i /[!in_setU]/orP[iA|iB]]; first by rewrite le_max bigmax_ge_id.
- by rewrite le_max le_bigmax_cond.
- by rewrite le_max orbC le_bigmax_cond.
Qed.
Lemma bigminU (A B : {set I}) F :
\big[min/x]_(i in A :|: B) F i
= min (\big[min/x]_(i in A) F i) (\big[min/x]_(i in B) F i).
Proof.
apply: le_anti; rewrite le_min bigminUl bigminUr !andbT; apply/bigmin_geP.
split=> [|i /[!in_setU]/orP[iA|iB]]; first by rewrite ge_min bigmin_le_id.
- by rewrite ge_min bigmin_le_cond.
- by rewrite ge_min orbC bigmin_le_cond.
Qed.
Lemma bigmin_set1 j F : \big[min/x]_(i in [set j]) F i = min (F j) x.
Proof. exact: big_set1E. Qed.
Lemma bigmax_set1 j F : \big[max/x]_(i in [set j]) F i = max (F j) x.
Proof. exact: big_set1E. Qed.
End bigminmax_finType.
Lemma bigmin_imset [I J : finType] x [h : I -> J] [A : {set I}] (F : J -> T) :
\big[min/x]_(j in [set h x | x in A]) F j = \big[min/x]_(i in A) F (h i).
Proof. by apply: big_imset_idem; apply: minxx. Qed.
Lemma bigmax_imset [I J : finType] x [h : I -> J] [A : {set I}] (F : J -> T) :
\big[max/x]_(j in [set h x | x in A]) F j = \big[max/x]_(i in A) F (h i).
Proof. by apply: big_imset_idem; apply: maxxx. Qed.
End TotalTheory.
#[global] Hint Resolve le_total : core.
#[global] Hint Resolve ge_total : core.
#[global] Hint Extern 0 (is_true (_ >=< _)%O) => solve [apply: comparableT]
: core.
#[global] Hint Resolve sort_le_sorted : core.
Arguments min_idPr {disp T x y}.
Arguments max_idPl {disp T x y}.
Arguments bigmin_mkcond {disp T I r}.
Arguments bigmax_mkcond {disp T I r}.
Arguments bigminID {disp T I r}.
Arguments bigmaxID {disp T I r}.
Arguments bigminD1 {disp T I x} j.
Arguments bigmaxD1 {disp T I x} j.
Arguments bigmin_inf {disp T I x} j.
Arguments bigmax_sup {disp T I x} j.
Arguments bigmin_eq_arg {disp T I} x j.
Arguments bigmax_eq_arg {disp T I} x j.
Arguments eq_bigmin {disp T I x} j.
Arguments eq_bigmax {disp T I x} j.
(* FIXME: some lemmas in the following section should hold for any porderType *)
Module Import DualTotalTheory.
Section DualTotalTheory.
Context {disp : disp_t} {T : orderType disp}.
Implicit Type s : seq T.
Lemma sorted_filter_gt x s :
sorted <=%O s -> [seq y <- s | x < y] = drop (count (<= x) s) s.
Proof.
move=> s_sorted; rewrite count_le_gt -[LHS]revK -filter_rev.
rewrite (@sorted_filter_lt _ T^d); first by rewrite take_rev revK count_rev.
by rewrite rev_sorted.
Qed.
Lemma sorted_filter_ge x s :
sorted <=%O s -> [seq y <- s | x <= y] = drop (count (< x) s) s.
Proof.
move=> s_sorted; rewrite count_lt_ge -[LHS]revK -filter_rev.
rewrite (@sorted_filter_le _ T^d); first by rewrite take_rev revK count_rev.
by rewrite rev_sorted.
Qed.
Lemma nth_count_ge x x0 s i : sorted <=%O s ->
(count (< x) s <= i < size s)%N -> x <= nth x0 s i.
Proof.
move=> ss /andP[ige ilt]; rewrite -(subnKC ige) -nth_drop -sorted_filter_ge //.
apply/(all_nthP _ (filter_all _ _)).
by rewrite size_filter ltn_subLR // count_lt_ge subnK // count_size.
Qed.
Lemma nth_count_gt x x0 s i : sorted <=%O s ->
(count (<= x) s <= i < size s)%N -> x < nth x0 s i.
Proof.
move=> ss /andP[ige ilt]; rewrite -(subnKC ige) -nth_drop -sorted_filter_gt //.
apply/(all_nthP _ (filter_all _ _)).
by rewrite size_filter ltn_subLR // count_le_gt subnK // count_size.
Qed.
Lemma nth_count_eq x x0 s i : sorted <=%O s ->
(count (< x) s <= i < count (<= x) s)%N -> nth x0 s i = x.
Proof.
move=> ss /andP[ige ilt]; apply/le_anti.
by rewrite nth_count_le// nth_count_ge// ige (leq_trans ilt (count_size _ _)).
Qed.
End DualTotalTheory.
End DualTotalTheory.
(* contra lemmas *)
Section ContraTheory.
Context {disp1 disp2 : disp_t} {T1 : porderType disp1} {T2 : orderType disp2}.
Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop).
Lemma contraTle b z t : (t < z -> ~~ b) -> (b -> z <= t).
Proof. exact: comparable_contraTle. Qed.
Lemma contraTlt b z t : (t <= z -> ~~ b) -> (b -> z < t).
Proof. exact: comparable_contraTlt. Qed.
Lemma contraPle P z t : (t < z -> ~ P) -> (P -> z <= t).
Proof. exact: comparable_contraPle. Qed.
Lemma contraPlt P z t : (t <= z -> ~ P) -> (P -> z < t).
Proof. exact: comparable_contraPlt. Qed.
Lemma contraNle b z t : (t < z -> b) -> (~~ b -> z <= t).
Proof. exact: comparable_contraNle. Qed.
Lemma contraNlt b z t : (t <= z -> b) -> (~~ b -> z < t).
Proof. exact: comparable_contraNlt. Qed.
Lemma contra_not_le P z t : (t < z -> P) -> (~ P -> z <= t).
Proof. exact: comparable_contra_not_le. Qed.
Lemma contra_not_lt P z t : (t <= z -> P) -> (~ P -> z < t).
Proof. exact: comparable_contra_not_lt. Qed.
Lemma contraFle b z t : (t < z -> b) -> (b = false -> z <= t).
Proof. exact: comparable_contraFle. Qed.
Lemma contraFlt b z t : (t <= z -> b) -> (b = false -> z < t).
Proof. exact: comparable_contraFlt. Qed.
Lemma contra_leq_le m n z t : (t < z -> (n < m)%N) -> ((m <= n)%N -> z <= t).
Proof. exact: comparable_contra_leq_le. Qed.
Lemma contra_leq_lt m n z t : (t <= z -> (n < m)%N) -> ((m <= n)%N -> z < t).
Proof. exact: comparable_contra_leq_lt. Qed.
Lemma contra_ltn_le m n z t : (t < z -> (n <= m)%N) -> ((m < n)%N -> z <= t).
Proof. exact: comparable_contra_ltn_le. Qed.
Lemma contra_ltn_lt m n z t : (t <= z -> (n <= m)%N) -> ((m < n)%N -> z < t).
Proof. exact: comparable_contra_ltn_lt. Qed.
Lemma contra_le x y z t : (t < z -> y < x) -> (x <= y -> z <= t).
Proof. exact: comparable_contra_le. Qed.
Lemma contra_le_lt x y z t : (t <= z -> y < x) -> (x <= y -> z < t).
Proof. exact: comparable_contra_le_lt. Qed.
Lemma contra_lt_le x y z t : (t < z -> y <= x) -> (x < y -> z <= t).
Proof. exact: comparable_contra_lt_le. Qed.
Lemma contra_lt x y z t : (t <= z -> y <= x) -> (x < y -> z < t).
Proof. exact: comparable_contra_lt. Qed.
End ContraTheory.
Section TotalMonotonyTheory.
Context {disp disp' : disp_t} {T : orderType disp} {T' : porderType disp'}.
Context (D : {pred T}) (f : T -> T').
Implicit Types (x y z : T) (u v w : T').
Let leT_anti := @le_anti _ T.
Let leT'_anti := @le_anti _ T'.
Let ltT_neqAle := @lt_neqAle _ T.
Let ltT'_neqAle := @lt_neqAle _ T'.
Let ltT_def := @lt_def _ T.
Let leT_total := @le_total _ T.
Lemma le_mono : {homo f : x y / x < y} -> {mono f : x y / x <= y}.
Proof. exact: total_homo_mono. Qed.
Lemma le_nmono : {homo f : x y /~ x < y} -> {mono f : x y /~ x <= y}.
Proof. by apply: total_homo_mono => // x y; rewrite eq_sym. Qed.
Lemma le_mono_in :
{in D &, {homo f : x y / x < y}} -> {in D &, {mono f : x y / x <= y}}.
Proof. exact: total_homo_mono_in. Qed.
Lemma le_nmono_in :
{in D &, {homo f : x y /~ x < y}} -> {in D &, {mono f : x y /~ x <= y}}.
Proof. by apply: total_homo_mono_in => // x y; rewrite eq_sym. Qed.
End TotalMonotonyTheory.
End TotalTheory.
Module Import CDistrLatticeTheory.
Section CDistrLatticeTheory.
Context {disp : disp_t} {L : cDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. exact: rcomplPmeet. Qed.
Lemma rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. exact: rcomplPjoin. Qed.
Lemma rcomplKI x y z : x <= y -> (x `|` z) `&` rcompl x y z = x.
Proof. by move=> lexy; have := rcomplPmeet x y z; rewrite (meet_l lexy). Qed.
Lemma rcomplKU x y z : x <= y -> (y `&` z) `|` rcompl x y z = y.
Proof. by move=> lexy; have := rcomplPjoin x y z; rewrite (join_l lexy). Qed.
End CDistrLatticeTheory.
End CDistrLatticeTheory.
Module Import CBDistrLatticeTheory.
Section CBDistrLatticeTheory.
Context {disp : disp_t} {L : cbDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma diffErcompl x y : x `\` y = rcompl \bot x y.
Proof. exact: diffErcompl. Qed.
Lemma diffKI x y : y `&` (x `\` y) = \bot.
Proof. by have := rcomplKI y (le0x x); rewrite join0x diffErcompl. Qed.
Lemma diffIK x y : (x `\` y) `&` y = \bot.
Proof. by rewrite meetC diffKI. Qed.
Lemma meetIB z x y : (z `&` y) `&` (x `\` y) = \bot.
Proof. by rewrite -meetA diffKI meetx0. Qed.
Lemma meetBI z x y : (x `\` y) `&` (z `&` y) = \bot.
Proof. by rewrite meetC meetIB. Qed.
Lemma joinIB y x : (x `&` y) `|` (x `\` y) = x.
Proof. by rewrite diffErcompl rcomplKU. Qed.
Lemma joinBI y x : (x `\` y) `|` (x `&` y) = x.
Proof. by rewrite joinC joinIB. Qed.
Lemma joinIBC y x : (y `&` x) `|` (x `\` y) = x.
Proof. by rewrite meetC joinIB. Qed.
Lemma joinBIC y x : (x `\` y) `|` (y `&` x) = x.
Proof. by rewrite meetC joinBI. Qed.
Lemma leBx x y : x `\` y <= x.
Proof. by rewrite -[leRHS](joinIB y) leUr. Qed.
Hint Resolve leBx : core.
Lemma diffxx x : x `\` x = \bot.
Proof. by have := diffKI x x; rewrite meet_r. Qed.
Lemma leBl z x y : x <= y -> x `\` z <= y `\` z.
Proof.
rewrite -[leLHS](joinIB z) -[leRHS](joinIB z).
by rewrite leU2E ?meetIB ?meetBI // => /andP [].
Qed.
Lemma diffKU y x : y `|` (x `\` y) = y `|` x.
Proof.
apply/eqP; rewrite eq_le leU2 //= leUx leUl.
by apply/meet_idPl; have := joinIB y x; rewrite joinIl join_l.
Qed.
Lemma diffUK y x : (x `\` y) `|` y = x `|` y.
Proof. by rewrite joinC diffKU joinC. Qed.
Lemma leBKU y x : y <= x -> y `|` (x `\` y) = x.
Proof. by move=> /join_r {2}<-; rewrite diffKU. Qed.
Lemma leBUK y x : y <= x -> (x `\` y) `|` y = x.
Proof. by move=> leyx; rewrite joinC leBKU. Qed.
Lemma leBLR x y z : (x `\` y <= z) = (x <= y `|` z).
Proof.
apply/idP/idP; first by move=> /join_r <-; rewrite joinA diffKU joinAC leUr.
by rewrite -{1}[x](joinIB y) => /(leU2r_le (diffIK _ _)).
Qed.
Lemma diffUx x y z : (x `|` y) `\` z = (x `\` z) `|` (y `\` z).
Proof.
apply/eqP; rewrite eq_le leUx !leBl ?leUr ?leUl ?andbT //.
by rewrite leBLR joinA diffKU joinAC diffKU joinAC -joinA leUr.
Qed.
Lemma diff_eq0 x y : (x `\` y == \bot) = (x <= y).
Proof. by rewrite -lex0 leBLR joinx0. Qed.
Lemma joinxB x y z : x `|` (y `\` z) = ((x `|` y) `\` z) `|` (x `&` z).
Proof. by rewrite diffUx joinAC joinBI. Qed.
Lemma joinBx x y z : (y `\` z) `|` x = ((y `|` x) `\` z) `|` (z `&` x).
Proof. by rewrite ![_ `|` x]joinC ![_ `&` x]meetC joinxB. Qed.
Lemma leBr z x y : x <= y -> z `\` y <= z `\` x.
Proof. by move=> lexy; rewrite leBLR joinxB meet_r ?leBUK ?leUr ?lexUl. Qed.
Lemma leB2 x y z t : x <= z -> t <= y -> x `\` y <= z `\` t.
Proof. by move=> /(@leBl t) ? /(@leBr x) /le_trans ->. Qed.
Lemma meet_eq0E_diff z x y : x <= z -> (x `&` y == \bot) = (x <= z `\` y).
Proof.
move=> xz; apply/idP/idP; last by move=> /meet_r <-; rewrite -meetA meetBI.
by move=> /eqP xIy_eq0; rewrite -[x](joinIB y) xIy_eq0 join0x leBl.
Qed.
Lemma leBRL x y z : (x <= z `\` y) = (x <= z) && (x `&` y == \bot).
Proof.
apply/idP/idP => [xyz|]; first by rewrite (@meet_eq0E_diff z) // (le_trans xyz).
by move=> /andP [?]; rewrite -meet_eq0E_diff.
Qed.
Lemma eq_diff x y z : (x `\` y == z) = (z <= x <= y `|` z) && (z `&` y == \bot).
Proof. by rewrite eq_le leBLR leBRL andbCA andbA. Qed.
Lemma diffxU x y z : z `\` (x `|` y) = (z `\` x) `&` (z `\` y).
Proof.
apply/eqP; rewrite eq_le lexI !leBr ?leUl ?leUr //=.
rewrite leBRL leIx2 ?leBx //= meetUr meetAC diffIK -meetA diffIK.
by rewrite meet0x meetx0 joinx0.
Qed.
Lemma diffx0 x : x `\` \bot = x.
Proof. by apply/eqP; rewrite eq_diff join0x meetx0 lexx eqxx. Qed.
Lemma diff0x x : \bot `\` x = \bot.
Proof. by apply/eqP; rewrite eq_diff joinx0 meet0x lexx eqxx le0x. Qed.
Lemma diffIx x y z : (x `&` y) `\` z = (x `\` z) `&` (y `\` z).
Proof.
apply/eqP; rewrite eq_diff joinIr ?leI2 ?diffKU ?leUr ?leBx //=.
by rewrite -meetA diffIK meetx0.
Qed.
Lemma meetxB x y z : x `&` (y `\` z) = (x `&` y) `\` z.
Proof. by rewrite diffIx -{1}[x](joinBI z) meetUl meetIB joinx0. Qed.
Lemma meetBx x y z : (x `\` y) `&` z = (x `&` z) `\` y.
Proof. by rewrite ![_ `&` z]meetC meetxB. Qed.
Lemma diffxI x y z : x `\` (y `&` z) = (x `\` y) `|` (x `\` z).
Proof.
apply/eqP; rewrite eq_diff leUx !leBx //= joinIl joinA joinCA !diffKU.
rewrite joinCA -joinA [_ `|` x]joinC ![x `|` _]join_l //.
by rewrite -joinIl leUr /= meetUl {1}[_ `&` z]meetC ?meetBI joinx0.
Qed.
Lemma diffBx x y z : (x `\` y) `\` z = x `\` (y `|` z).
Proof.
apply/eqP; rewrite eq_diff leBr ?leUl //=.
by rewrite diffxU joinIr diffKU -joinIr meet_l ?leUr //= -meetA diffIK meetx0.
Qed.
Lemma diffxB x y z : x `\` (y `\` z) = (x `\` y) `|` (x `&` z).
Proof.
rewrite -[y in RHS](joinIB z) diffxU joinIl diffxI -joinA joinBI join_r //.
by rewrite joinBx meetKU meetA meetAC diffIK meet0x joinx0 meet_r.
Qed.
Lemma joinBK x y : (y `|` x) `\` x = (y `\` x).
Proof. by rewrite diffUx diffxx joinx0. Qed.
Lemma joinBKC x y : (x `|` y) `\` x = (y `\` x).
Proof. by rewrite diffUx diffxx join0x. Qed.
Lemma disj_le x y : x `&` y == \bot -> x <= y = (x == \bot).
Proof. by rewrite [x == \bot]eq_sym -eq_meetl => /eqP ->. Qed.
Lemma disj_leC x y : y `&` x == \bot -> x <= y = (x == \bot).
Proof. by rewrite meetC => /disj_le. Qed.
Lemma disj_diffl x y : x `&` y == \bot -> x `\` y = x.
Proof. by move=> dxy; apply/eqP; rewrite eq_diff dxy lexx leUr. Qed.
Lemma disj_diffr x y : x `&` y == \bot -> y `\` x = y.
Proof. by rewrite meetC => /disj_diffl. Qed.
Lemma lt0B x y : x < y -> \bot < y `\` x.
Proof. by move=> ?; rewrite lt_leAnge le0x leBLR joinx0 /= lt_geF. Qed.
End CBDistrLatticeTheory.
End CBDistrLatticeTheory.
Module Import CTDistrLatticeTheory.
Section CTDistrLatticeTheory.
Context {disp : disp_t} {L : ctDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma codiffErcompl x y : codiff x y = rcompl x \top y.
Proof. exact: codiffErcompl. Qed.
(* TODO: complete this theory module *)
End CTDistrLatticeTheory.
End CTDistrLatticeTheory.
Module Import CTBDistrLatticeTheory.
Section CTBDistrLatticeTheory.
Context {disp : disp_t} {L : ctbDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma complEdiff x : ~` x = \top `\` x. Proof. exact: complEdiff. Qed.
#[deprecated(since="mathcomp 2.3.0", note="Use complEdiff instead.")]
Notation complE := complEdiff.
Lemma complEcodiff x : ~` x = codiff \bot x. Proof. exact: complEcodiff. Qed.
Lemma complErcompl x : ~` x = rcompl \bot \top x.
Proof. by rewrite complEdiff diffErcompl. Qed.
Lemma diff1x x : \top `\` x = ~` x.
Proof. exact/esym/complEdiff. Qed.
Lemma diffE x y : x `\` y = x `&` ~` y.
Proof. by rewrite complEdiff meetxB meetx1. Qed.
Lemma complK : involutive (@compl _ L).
Proof. by move=> x; rewrite !complEdiff diffxB diffxx meet1x join0x. Qed.
Lemma compl_inj : injective (@compl _ L).
Proof. exact/inv_inj/complK. Qed.
Lemma disj_leC x y : (x `&` y == \bot) = (x <= ~` y).
Proof. by rewrite -diff_eq0 diffE complK. Qed.
Lemma leCx x y : (~` x <= y) = (~` y <= x).
Proof. by rewrite !complEdiff !leBLR joinC. Qed.
Lemma lexC x y : (x <= ~` y) = (y <= ~` x).
Proof. by rewrite -[x in LHS]complK leCx complK. Qed.
Lemma leC x y : (~` x <= ~` y) = (y <= x).
Proof. by rewrite leCx complK. Qed.
Lemma complU x y : ~` (x `|` y) = ~` x `&` ~` y.
Proof. by rewrite !complEdiff diffxU. Qed.
Lemma complI x y : ~` (x `&` y) = ~` x `|` ~` y.
Proof. by rewrite !complEdiff diffxI. Qed.
Lemma joinxC x : x `|` ~` x = \top.
Proof. by rewrite complEdiff diffKU joinx1. Qed.
Lemma joinCx x : ~` x `|` x = \top.
Proof. by rewrite joinC joinxC. Qed.
Lemma meetxC x : x `&` ~` x = \bot.
Proof. by rewrite complEdiff diffKI. Qed.
Lemma meetCx x : ~` x `&` x = \bot.
Proof. by rewrite meetC meetxC. Qed.
Lemma compl1 : ~` \top = \bot :> L.
Proof. by rewrite complEdiff diffxx. Qed.
Lemma compl0 : ~` \bot = \top :> L.
Proof. by rewrite -compl1 complK. Qed.
Lemma complB x y : ~` (x `\` y) = ~` x `|` y.
Proof. by rewrite diffE complI complK. Qed.
Lemma leBC x y : x `\` y <= ~` y.
Proof. by rewrite leBLR joinxC lex1. Qed.
Lemma compl_joins (J : Type) (r : seq J) (P : {pred J}) (F : J -> L) :
~` (\join_(j <- r | P j) F j) = \meet_(j <- r | P j) ~` F j.
Proof. by elim/big_rec2: _=> [|i x y ? <-]; rewrite ?compl0 ?complU. Qed.
Lemma compl_meets (J : Type) (r : seq J) (P : {pred J}) (F : J -> L) :
~` (\meet_(j <- r | P j) F j) = \join_(j <- r | P j) ~` F j.
Proof. by elim/big_rec2: _=> [|i x y ? <-]; rewrite ?compl1 ?complI. Qed.
End CTBDistrLatticeTheory.
End CTBDistrLatticeTheory.
(*************)
(* FACTORIES *)
(*************)
(* porderType *)
HB.factory Record Preorder_isPOrder (d : disp_t) T of Preorder d T := {
le_anti : antisymmetric (@le d T);
}.
HB.builders Context (d : disp_t) T of Preorder_isPOrder d T.
Let ge_anti : antisymmetric (fun x y => @le d T y x).
Proof. by move=> x y; rewrite andbC; apply: le_anti. Qed.
HB.instance Definition _ := Preorder_isDuallyPOrder.Build d T le_anti ge_anti.
HB.end.
HB.factory Record isPOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
lt_def : forall x y, lt x y = (y != x) && (le x y);
le_refl : reflexive le;
le_anti : antisymmetric le;
le_trans : transitive le;
}.
HB.builders Context (d : disp_t) T of isPOrder d T.
Let lt_le_def x y : lt x y = le x y && ~~ le y x.
Proof.
rewrite lt_def andbC; case /boolP: (le x y) => //= xy.
have [->|/negP xyE /=] := eqVneq y x; first by rewrite le_refl.
by apply/esym/negP => yx; apply/xyE/eqP/le_anti; rewrite yx.
Qed.
HB.instance Definition _ := isPreorder.Build d T lt_le_def le_refl le_trans.
HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti.
HB.end.
HB.factory Record Le_isPOrder (d : disp_t) T of Choice T := {
le : rel T;
le_refl : reflexive le;
le_anti : antisymmetric le;
le_trans : transitive le;
}.
HB.builders Context (d : disp_t) T of Le_isPOrder d T.
(* TODO: print nice error message when keyed type is not provided *)
HB.instance Definition _ := @Le_isPreorder.Build d T le le_refl le_trans.
HB.instance Definition _ := @Preorder_isPOrder.Build d T le_anti.
HB.end.
HB.factory Record LtLe_isPOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
le_def : forall x y, le x y = (x == y) || lt x y;
lt_irr : irreflexive lt;
lt_trans : transitive lt;
}.
HB.builders Context (d : disp_t) T of LtLe_isPOrder d T.
HB.instance Definition _ := @LtLe_isPreorder.Build d T le lt le_def lt_irr lt_trans.
Let le_anti : antisymmetric le.
Proof.
move=> x y; rewrite !le_def [y == _]eq_sym.
have [//|neq_xy/=] := eqVneq x y => /andP[xy yx].
by have := lt_trans xy yx; rewrite lt_irr.
Qed.
HB.instance Definition _ := @Preorder_isPOrder.Build d T le_anti.
HB.end.
HB.factory Record Lt_isPOrder (d : disp_t) T of Choice T := {
lt : rel T;
lt_irr : irreflexive lt;
lt_trans : transitive lt;
}.
HB.builders Context d T of Lt_isPOrder d T.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := @LtLe_isPOrder.Build d T
_ lt (fun _ _ => erefl) lt_irr lt_trans.
HB.end.
(* meetSemilatticeType and joinSemilatticeType *)
HB.factory Record POrder_Meet_isSemilattice d T of POrder d T := {
meet : T -> T -> T;
meetC : commutative meet;
meetA : associative meet;
leEmeet : forall x y, (x <= y) = (meet x y == x);
}.
HB.builders Context d T of POrder_Meet_isSemilattice d T.
Fact meetxx : idempotent_op meet.
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z).
Proof.
rewrite !leEmeet; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite meetA -meetA meetxx.
by rewrite -!meetA (meetC z) (meetA y) meetxx.
by rewrite -!meetA (meetC z) -meetA (meetA y) !meetxx.
Qed.
HB.instance Definition _ := @POrder_isMeetSemilattice.Build d T meet lexI.
HB.end.
HB.factory Record POrder_Join_isSemilattice d T of POrder d T := {
join : T -> T -> T;
joinC : commutative join;
joinA : associative join;
leEjoin : forall x y, (y <= x) = (join x y == x);
}.
HB.builders Context d T of POrder_Join_isSemilattice d T.
Fact joinxx : idempotent_op join.
Proof. by move=> x; apply/eqP; rewrite -leEjoin. Qed.
Fact leUx x y z : (join x y <= z) = (x <= z) && (y <= z).
rewrite !leEjoin; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite joinA -joinA joinxx.
by rewrite -joinA (joinC _ x) (joinA x) joinxx.
by rewrite -!joinA (joinC y) -joinA (joinA x) !joinxx.
Qed.
HB.instance Definition _ := @POrder_isJoinSemilattice.Build d T join leUx.
HB.end.
(* latticeType *)
HB.factory Record POrder_MeetJoin_isLattice d T of POrder d T := {
meet : T -> T -> T;
join : T -> T -> T;
meetP : forall x y z, (x <= meet y z) = (x <= y) && (x <= z);
joinP : forall x y z, (join x y <= z) = (x <= z) && (y <= z);
}.
HB.builders Context d T of POrder_MeetJoin_isLattice d T.
HB.instance Definition _ := @POrder_isMeetSemilattice.Build d T meet meetP.
HB.instance Definition _ := @POrder_isJoinSemilattice.Build d T join joinP.
HB.end.
HB.factory Record POrder_isLattice d T of POrder d T := {
meet : T -> T -> T;
join : T -> T -> T;
meetC : commutative meet;
joinC : commutative join;
meetA : associative meet;
joinA : associative join;
joinKI : forall y x, meet x (join x y) = x;
meetKU : forall y x, join x (meet x y) = x;
leEmeet : forall x y, (x <= y) = (meet x y == x);
}.
HB.builders Context d T of POrder_isLattice d T.
Fact leEjoin x y : (y <= x) = (join x y == x).
Proof.
rewrite leEmeet; apply/eqP/eqP => <-.
by rewrite meetC meetKU.
by rewrite joinC joinKI.
Qed.
Fact meetxx : idempotent_op meet.
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z).
Proof.
rewrite !leEmeet; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite meetA -meetA meetxx.
by rewrite -!meetA (meetC z) (meetA y) meetxx.
by rewrite -!meetA (meetC z) -meetA (meetA y) !meetxx.
Qed.
Fact joinxx : idempotent_op join.
Proof. by move=> x; apply/eqP; rewrite -leEjoin. Qed.
Fact leUx x y z : (join x y <= z) = (x <= z) && (y <= z).
rewrite !leEjoin; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite joinA -joinA joinxx.
by rewrite -joinA (joinC _ x) (joinA x) joinxx.
by rewrite -!joinA (joinC y) -joinA (joinA x) !joinxx.
Qed.
HB.instance Definition _ := @POrder_MeetJoin_isLattice.Build d T
meet join lexI leUx.
HB.end.
(* distrLatticeType *)
HB.factory Record Lattice_Meet_isDistrLattice d T of Lattice d T := {
meetUl : @left_distributive T T meet join;
}.
HB.builders Context d T of Lattice_Meet_isDistrLattice d T.
Let meetUr : right_distributive (@meet _ T) (@join _ T).
Proof. by move=> x y z; rewrite ![x `&` _]meetC meetUl. Qed.
Let joinIl : left_distributive (@join _ T) (@meet _ T).
Proof. by move=> x y z; rewrite meetUr joinIK meetUl -joinA meetUKC. Qed.
HB.instance Definition _ := Lattice_isDistributive.Build d T meetUl joinIl.
HB.end.
HB.factory Record POrder_Meet_isDistrLattice d T of POrder d T := {
meet : T -> T -> T;
join : T -> T -> T;
meetC : commutative meet;
joinC : commutative join;
meetA : associative meet;
joinA : associative join;
joinKI : forall y x, meet x (join x y) = x;
meetKU : forall y x, join x (meet x y) = x;
leEmeet : forall x y, (x <= y) = (meet x y == x);
meetUl : left_distributive meet join;
}.
HB.builders Context d T of POrder_Meet_isDistrLattice d T.
HB.instance Definition _ := @POrder_isLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU leEmeet.
HB.instance Definition _ :=
Lattice_Meet_isDistrLattice.Build d T meetUl.
HB.end.
HB.factory Record isMeetJoinDistrLattice (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
meet : T -> T -> T;
join : T -> T -> T;
le_def : forall x y : T, le x y = (meet x y == x);
lt_def : forall x y : T, lt x y = (y != x) && le x y;
meetC : commutative meet;
joinC : commutative join;
meetA : associative meet;
joinA : associative join;
joinKI : forall y x : T, meet x (join x y) = x;
meetKU : forall y x : T, join x (meet x y) = x;
meetUl : left_distributive meet join;
meetxx : idempotent_op meet;
}.
HB.builders Context d T of isMeetJoinDistrLattice d T.
Fact le_refl : reflexive le. Proof. by move=> x; rewrite le_def meetxx. Qed.
Fact le_anti : antisymmetric le.
Proof. by move=> x y; rewrite !le_def meetC => /andP [] /eqP {2}<- /eqP ->. Qed.
Fact le_trans : transitive le.
Proof.
move=> y x z; rewrite !le_def => /eqP lexy /eqP leyz; apply/eqP.
by rewrite -[in LHS]lexy -meetA leyz lexy.
Qed.
Fact lt_le_def x y : lt x y = (le x y) && ~~ (le y x).
Proof.
rewrite lt_def andbC; case/boolP: (le x y) => //= xy.
congr negb; apply/eqP/idP => [->|yx]; first exact/le_refl.
by apply/le_anti/andP; split.
Qed.
HB.instance Definition _ := isPreorder.Build d T
lt_le_def le_refl le_trans.
HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti.
HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU le_def meetUl.
HB.end.
(* complemented lattices *)
HB.factory Record BDistrLattice_hasSectionalComplement d T
of BDistrLattice d T := {
diff : T -> T -> T;
diffKI : forall x y, y `&` diff x y = \bot;
joinIB : forall x y, (x `&` y) `|` diff x y = x;
}.
Module hasRelativeComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use BDistrLattice_hasSectionalComplement.Build instead.")]
Notation Build d T :=
(BDistrLattice_hasSectionalComplement.Build d T) (only parsing).
End hasRelativeComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use BDistrLattice_hasSectionalComplement instead.")]
Notation hasRelativeComplement d T :=
(BDistrLattice_hasSectionalComplement d T) (only parsing).
HB.builders Context d T of BDistrLattice_hasSectionalComplement d T.
Definition rcompl x y z := (x `&` y) `|` diff (y `|` x) z.
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by rewrite meetUr joinIKC meetUl diffKI joinx0 meetKU. Qed.
Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. by rewrite joinCA joinIB joinA meetUK joinC. Qed.
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build d T rcompl rcomplPmeet rcomplPjoin.
Fact diffErcompl x y : diff x y = rcompl \bot x y.
Proof. by rewrite /rcompl meet0x join0x joinx0. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasSectionalComplement.Build d T diff diffErcompl.
HB.end.
HB.factory Record TDistrLattice_hasDualSectionalComplement d T
of TDistrLattice d T := {
codiff : T -> T -> T;
codiffKU : forall x y, y `|` codiff x y = \top;
meetUB : forall x y, (x `|` y) `&` codiff x y = x;
}.
HB.builders Context d T of TDistrLattice_hasDualSectionalComplement d T.
Definition rcompl x y z := (y `|` x) `&` codiff (x `&` y) z.
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by rewrite meetCA meetUB meetA joinIK. Qed.
Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. by rewrite joinIr meetUKC joinIl codiffKU meetx1 joinKI. Qed.
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build d T rcompl rcomplPmeet rcomplPjoin.
Fact codiffErcompl x y : codiff x y = rcompl x \top y.
Proof. by rewrite /rcompl join1x meet1x meetx1. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build d T codiff codiffErcompl.
HB.end.
HB.factory Record CBDistrLattice_hasComplement d T
of CBDistrLattice d T & hasTop d T := {
compl : T -> T;
complEdiff : forall x, compl x = (\top : T) `\` x; (* FIXME *)
}.
Module hasComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use CBDistrLattice_hasComplement.Build instead.")]
Notation Build d T := (CBDistrLattice_hasComplement.Build d T) (only parsing).
End hasComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use CBDistrLattice_hasComplement instead.")]
Notation hasComplement d T := (CBDistrLattice_hasComplement d T) (only parsing).
HB.builders Context d T of CBDistrLattice_hasComplement d T.
HB.instance Definition _ := @CDistrLattice_hasDualSectionalComplement.Build d T
(fun x y => rcompl x \top y) (fun _ _ => erefl).
Fact complEcodiff (x : T) : compl x = codiff (\bot : T) x.
Proof. by rewrite complEdiff diffErcompl. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff.
HB.end.
HB.factory Record CTDistrLattice_hasComplement d T
of CTDistrLattice d T & hasBottom d T := {
compl : T -> T;
complEcodiff : forall x, compl x = codiff (\bot : T) x;
}.
HB.builders Context d T of CTDistrLattice_hasComplement d T.
HB.instance Definition _ := @CDistrLattice_hasSectionalComplement.Build d T
(fun x y => rcompl (\bot : T) x y) (fun _ _ => erefl).
Fact complEdiff (x : T) : compl x = (\top : T) `\` x.
Proof. by rewrite complEcodiff codiffErcompl. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff.
HB.end.
HB.factory Record TBDistrLattice_hasComplement d T of TBDistrLattice d T := {
compl : T -> T;
joinxC : forall x, x `|` compl x = \top;
meetxC : forall x, x `&` compl x = \bot;
}.
HB.builders Context d T of TBDistrLattice_hasComplement d T.
Definition diff x y := x `&` compl y.
Definition codiff x y := x `|` compl y.
Definition rcompl x y z := (x `&` y) `|` diff (y `|` x) z.
Fact diffKI x y : y `&` diff x y = \bot.
Proof. by rewrite meetCA meetxC meetx0. Qed.
Fact joinIB x y : (x `&` y) `|` diff x y = x.
Proof. by rewrite -meetUr joinxC meetx1. Qed.
HB.instance Definition _ :=
@BDistrLattice_hasSectionalComplement.Build d T diff diffKI joinIB.
Fact codiffErcompl x y : codiff x y = rcompl x \top y.
Proof. by rewrite /rcompl /diff join1x meetx1 meet1x. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build d T codiff codiffErcompl.
Fact complEdiff x : compl x = diff \top x. Proof. exact/esym/meet1x. Qed.
Fact complEcodiff x : compl x = codiff \bot x. Proof. exact/esym/join0x. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff.
HB.end.
(* orderType *)
HB.factory Record Lattice_isTotal d T of Lattice d T := {
le_total : total (<=%O : rel T)
}.
HB.builders Context d T of Lattice_isTotal d T.
Fact meetUl : @left_distributive T T meet join.
Proof.
pose leP x y := lcomparable_leP (le_total x y); move=> x y z; apply/esym.
by case: (leP x y) (leP x z) (leP y z) => [|/ltW] xy [|/ltW] xz [|/ltW] yz;
(apply/join_idPl || apply/join_idPr) => //; apply: le_trans xy.
Qed.
HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build d T meetUl.
HB.instance Definition _ := DistrLattice_isTotal.Build d T le_total.
HB.end.
HB.factory Record POrder_isTotal d T of POrder d T := {
le_total : total (<=%O : rel T) }.
HB.builders Context d T of POrder_isTotal d T.
Implicit Types (x y z : T).
Let comparableT x y : x >=< y := le_total x y.
Fact ltgtP x y :
compare x y (min y x) (min x y) (max y x) (max x y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof. exact: comparable_ltgtP. Qed.
Fact leP x y : le_xor_gt x y
(min y x) (min x y) (max y x) (max x y) (x <= y) (y < x).
Proof. exact: comparable_leP. Qed.
Definition meet := @min _ T.
Definition join := @max _ T.
Fact meetC : commutative meet.
Proof. by move=> x y; rewrite /meet; have [] := ltgtP. Qed.
Fact joinC : commutative join.
Proof. by move=> x y; rewrite /join; have [] := ltgtP. Qed.
Fact meetA : associative meet.
Proof.
move=> x y z; rewrite /meet /min !(fun_if, if_arg).
case: (leP z y) (leP y x) (leP z x) => [] zy [] yx [] zx//=.
by have := le_lt_trans (le_trans zy yx) zx; rewrite ltxx.
by apply/eqP; rewrite eq_le zx ltW// (lt_trans yx).
Qed.
Fact joinA : associative join.
Proof.
move=> x y z; rewrite /meet /min !(fun_if, if_arg).
case: (leP z y) (leP y x) (leP z x) => [] zy [] yx [] zx//=.
by have := le_lt_trans (le_trans zy yx) zx; rewrite ltxx.
by apply/eqP; rewrite eq_le zx ltW// (lt_trans yx).
Qed.
Fact joinKI y x : meet x (join x y) = x.
Proof.
rewrite /meet /join /min /max !(fun_if, if_arg).
by have []// := ltgtP x y; rewrite ltxx.
Qed.
Fact meetKU y x : join x (meet x y) = x.
Proof.
rewrite /meet /join /min /max !(fun_if, if_arg).
by have []// := ltgtP x y; rewrite ltxx.
Qed.
Fact leEmeet x y : (x <= y) = (meet x y == x).
Proof. by rewrite /meet; case: leP => ?; rewrite ?eqxx ?lt_eqF. Qed.
HB.instance Definition _ := @POrder_isLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU leEmeet.
HB.instance Definition _ :=
Lattice_isTotal.Build d T comparableT.
HB.end.
HB.factory Record isOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
meet : T -> T -> T;
join : T -> T -> T;
lt_def : forall x y, lt x y = (y != x) && le x y;
meet_def : forall x y, meet x y = if lt x y then x else y;
join_def : forall x y, join x y = if lt x y then y else x;
le_anti : antisymmetric le;
le_trans : transitive le;
le_total : total le;
}.
HB.builders Context d T of isOrder d T.
Fact le_refl : reflexive le.
Proof. by move=> x; case: (le x x) (le_total x x). Qed.
Fact lt_le_def x y : lt x y = (le x y) && ~~ (le y x).
Proof.
rewrite lt_def andbC; case/boolP: (le x y) => //= xy.
congr negb; apply/eqP/idP => [->|yx]; first exact/le_refl.
by apply/le_anti/andP; split.
Qed.
HB.instance Definition _ := isPreorder.Build d T
lt_le_def le_refl le_trans.
HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti.
Section GeneratedOrder.
Local Definition T' := T.
HB.instance Definition _ := POrder.on T'.
HB.instance Definition _ := POrder_isTotal.Build d T' le_total.
Implicit Types (x y z : T').
Fact meetE x y : meet x y = x `&` y. Proof. by rewrite meet_def. Qed.
Fact joinE x y : join x y = x `|` y. Proof. by rewrite join_def. Qed.
Fact meetC : commutative meet.
Proof. by move=> *; rewrite !meetE meetC. Qed.
Fact joinC : commutative join.
Proof. by move=> *; rewrite !joinE joinC. Qed.
Fact meetA : associative meet.
Proof. by move=> *; rewrite !meetE meetA. Qed.
Fact joinA : associative join.
Proof. by move=> *; rewrite !joinE joinA. Qed.
Fact joinKI y x : meet x (join x y) = x.
Proof. by rewrite meetE joinE joinKI. Qed.
Fact meetKU y x : join x (meet x y) = x.
Proof. by rewrite meetE joinE meetKU. Qed.
Fact meetUl : left_distributive meet join.
Proof. by move=> *; rewrite !meetE !joinE meetUl. Qed.
Fact meetxx : idempotent_op meet.
Proof. by move=> *; rewrite meetE meetxx. Qed.
Fact le_def x y : x <= y = (meet x y == x).
Proof. by rewrite meetE (eq_meetl x y). Qed.
End GeneratedOrder.
HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU le_def meetUl.
HB.instance Definition _ := DistrLattice_isTotal.Build d T le_total.
HB.end.
HB.factory Record LtOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
meet : T -> T -> T;
join : T -> T -> T;
le_def : forall x y, le x y = (x == y) || lt x y;
meet_def : forall x y, meet x y = if lt x y then x else y;
join_def : forall x y, join x y = if lt x y then y else x;
lt_irr : irreflexive lt;
lt_trans : transitive lt;
lt_total : forall x y, x != y -> lt x y || lt y x;
}.
HB.builders Context d T of LtOrder d T.
Fact lt_def x y : lt x y = (y != x) && le x y.
Proof. by rewrite le_def; case: eqVneq => //= ->; rewrite lt_irr. Qed.
Fact meet_def_le x y : meet x y = if lt x y then x else y.
Proof. by rewrite meet_def lt_def; case: eqP. Qed.
Fact join_def_le x y : join x y = if lt x y then y else x.
Proof. by rewrite join_def lt_def; case: eqP. Qed.
Fact le_anti : antisymmetric le.
Proof.
move=> x y; rewrite !le_def; case: eqVneq => //= _ /andP [] hxy.
by move/(lt_trans hxy); rewrite lt_irr.
Qed.
Fact le_trans : transitive le.
Proof.
move=> y x z; rewrite !le_def; case: eqVneq => [->|_] //=.
by case: eqVneq => [-> ->|_ hxy /(lt_trans hxy) ->]; rewrite orbT.
Qed.
Fact le_total : total le.
Proof. by move=> x y; rewrite !le_def; case: eqVneq => //; exact: lt_total. Qed.
HB.instance Definition _ :=
isOrder.Build d T lt_def meet_def_le join_def_le le_anti le_trans le_total.
HB.end.
HB.factory Record MonoTotal disp T of POrder disp T := {
disp' : disp_t;
T' : orderType disp';
f : T -> T';
f_mono : {mono f : x y / x <= y}
}.
HB.builders Context disp T of MonoTotal disp T.
Fact totalT : total (<=%O : rel T).
Proof. by move=> x y; rewrite -!f_mono le_total. Qed.
HB.instance Definition _ := POrder_isTotal.Build disp T totalT.
HB.end.
Module CancelPartial.
Import PreCancelPartial.
Section CancelPartial.
Variables (disp : disp_t) (T : choiceType).
Variables (disp' : disp_t) (T' : porderType disp') (f : T -> T').
Section Pcan.
Variables (f' : T' -> option T) (f_can : pcancel f f').
Fact anti : antisymmetric (le f).
Proof. by move=> ? ? /le_anti; apply: pcan_inj. Qed.
Fact lt_def x y :
lt f x y = (y != x) && le f x y.
Proof. by rewrite /lt lt_def (inj_eq (pcan_inj f_can)). Qed.
Definition Pcan := isPOrder.Build disp (Choice.Pack (Choice.class T))
lt_def (@refl T disp' T' f) anti (@trans T disp' T' f).
End Pcan.
Definition Can f' (f_can : cancel f f') := Pcan (can_pcan f_can).
End CancelPartial.
End CancelPartial.
Notation PCanIsPartial := CancelPartial.Pcan.
Notation CanIsPartial := CancelPartial.Can.
#[export]
HB.instance Definition _ (disp : disp_t) (T : choiceType)
(disp' : disp_t) (T' : porderType disp') (f : T -> T')
(f' : T' -> option T) (f_can : pcancel f f') :=
Preorder_isPOrder.Build disp (pcan_type f_can) (CancelPartial.anti f_can).
#[export]
HB.instance Definition _ (disp : disp_t) (T : choiceType)
(disp' : disp_t) (T' : porderType disp') (f : T -> T') (f' : T' -> T)
(f_can : cancel f f') :=
Preorder_isPOrder.Build disp (can_type f_can)
(CancelPartial.anti (can_pcan f_can)).
Section CancelTotal.
Variables (disp : disp_t) (T : choiceType).
Variables (disp' : disp_t) (T' : orderType disp') (f : T -> T').
Section PCan.
Variables (f' : T' -> option T) (f_can : pcancel f f').
#[local]
HB.instance Definition _ :=
MonoTotal.Build disp (pcan_type f_can) (fun _ _ => erefl).
Definition PCanIsTotal : DistrLattice_isTotal _ (pcan_type f_can) :=
Total.on (pcan_type f_can).
End PCan.
Section Can.
Variables (f' : T' -> T) (f_can : cancel f f').
#[local]
HB.instance Definition _ :=
MonoTotal.Build disp (can_type f_can) (fun _ _ => erefl).
Definition CanIsTotal : DistrLattice_isTotal _ (can_type f_can) :=
Total.on (can_type f_can).
End Can.
End CancelTotal.
HB.factory Record IsoLattice disp T of POrder disp T := {
disp' : disp_t;
T' : latticeType disp';
f : T -> T';
f' : T' -> T;
f_can : cancel f f';
f'_can : cancel f' f;
f_mono : {mono f : x y / x <= y};
}.
HB.builders Context disp T of IsoLattice disp T.
Definition meet (x y : T) := f' (meet (f x) (f y)).
Definition join (x y : T) := f' (join (f x) (f y)).
Fact meetC : commutative meet. Proof. by move=> x y; rewrite /meet meetC. Qed.
Fact joinC : commutative join. Proof. by move=> x y; rewrite /join joinC. Qed.
Fact meetA : associative meet.
Proof. by move=> y x z; rewrite /meet !f'_can meetA. Qed.
Fact joinA : associative join.
Proof. by move=> y x z; rewrite /join !f'_can joinA. Qed.
Fact joinKI y x : meet x (join x y) = x.
Proof. by rewrite /meet /join f'_can joinKI f_can. Qed.
Fact meetKI y x : join x (meet x y) = x.
Proof. by rewrite /join /meet f'_can meetKU f_can. Qed.
Fact meet_eql x y : (x <= y) = (meet x y == x).
Proof. by rewrite /meet -(can_eq f_can) f'_can eq_meetl f_mono. Qed.
HB.instance Definition _ := POrder_isLattice.Build _ T
meetC joinC meetA joinA joinKI meetKI meet_eql.
HB.end.
HB.factory Record IsoDistrLattice disp T of POrder disp T := {
disp' : disp_t;
T' : distrLatticeType disp';
f : T -> T';
f' : T' -> T;
f_can : cancel f f';
f'_can : cancel f' f;
f_mono : {mono f : x y / x <= y};
}.
HB.builders Context disp T of IsoDistrLattice disp T.
HB.instance Definition _ := IsoLattice.Build _ T f_can f'_can f_mono.
Fact meetUl : left_distributive (meet : T -> T -> T) join.
Proof. by move=> x y z; rewrite /meet /join /= !f'_can meetUl. Qed.
HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build _ T meetUl.
HB.end.
(* Morphism hierarchy. *)
Export OrderMorphismTheory.
Lemma omorph_lt (d : disp_t) (T : porderType d) (d' : disp_t) (T' : porderType d')
(f : {omorphism T -> T'}) : injective f -> {homo f : x y / x < y}.
Proof. by move/inj_homo_lt; apply; apply: omorph_le. Qed.
Definition meet_morphism d (T : latticeType d) d' (T' : latticeType d')
(f : T -> T') : Prop := {morph f : x y / x `&` y}.
Definition join_morphism d (T : latticeType d) d' (T' : latticeType d')
(f : T -> T') : Prop := {morph f : x y / x `|` y}.
HB.mixin Record isMeetLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') (apply : T -> T') := {
omorphI_subproof : meet_morphism apply;
}.
HB.mixin Record isJoinLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') (apply : T -> T') := {
omorphU_subproof : join_morphism apply;
}.
HB.structure Definition MeetLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') :=
{f of isMeetLatticeMorphism d T d' T' f & @OrderMorphism d T d' T' f}.
HB.structure Definition JoinLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') :=
{f of isJoinLatticeMorphism d T d' T' f & @OrderMorphism d T d' T' f}.
HB.structure Definition LatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') :=
{f of @MeetLatticeMorphism d T d' T' f & @JoinLatticeMorphism d T d' T' f}.
HB.factory Record isLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') (f : T -> T') of @OrderMorphism d T d' T' f := {
omorphI_subproof : meet_morphism f;
omorphU_subproof : join_morphism f;
}.
HB.builders Context d T d' T' f of isLatticeMorphism d T d' T' f.
HB.instance Definition _ := isMeetLatticeMorphism.Build d T d' T' f
omorphI_subproof.
HB.instance Definition _ := isJoinLatticeMorphism.Build d T d' T' f
omorphU_subproof.
HB.end.
Module LatticeMorphismExports.
Notation "{ 'mlmorphism' T -> T' }" :=
(@MeetLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'jlmorphism' T -> T' }" :=
(@JoinLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'lmorphism' T -> T' }" :=
(@LatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "[ 'mlmorphism' 'of' f 'as' g ]" :=
(MeetLatticeMorphism.clone _ _ _ _ f%function g)
(format "[ 'mlmorphism' 'of' f 'as' g ]") : form_scope.
Notation "[ 'mlmorphism' 'of' f ]" :=
(MeetLatticeMorphism.clone _ _ _ _ f%function _)
(format "[ 'mlmorphism' 'of' f ]") : form_scope.
Notation "[ 'jlmorphism' 'of' f 'as' g ]" :=
(JoinLatticeMorphism.clone _ _ _ _ f%function g)
(format "[ 'jlmorphism' 'of' f 'as' g ]") : form_scope.
Notation "[ 'jlmorphism' 'of' f ]" :=
(JoinLatticeMorphism.clone _ _ _ _ f%function _)
(format "[ 'jlmorphism' 'of' f ]") : form_scope.
Notation "[ 'lmorphism' 'of' f 'as' g ]" :=
(LatticeMorphism.clone _ _ _ _ f%function g)
(format "[ 'lmorphism' 'of' f 'as' g ]") : form_scope.
Notation "[ 'lmorphism' 'of' f ]" :=
(LatticeMorphism.clone _ _ _ _ f%function _)
(format "[ 'lmorphism' 'of' f ]") : form_scope.
End LatticeMorphismExports.
HB.export LatticeMorphismExports.
Module Import LatticeMorphismTheory.
Section LatticeMorphismTheory.
Section Properties.
Variables (d : disp_t) (T : latticeType d) (d' : disp_t) (T' : latticeType d').
Lemma omorphI (f : {mlmorphism T -> T'}) : {morph f : x y / x `&` y}.
Proof. exact: omorphI_subproof. Qed.
Lemma omorphU (f : {jlmorphism T -> T'}) : {morph f : x y / x `|` y}.
Proof. exact: omorphU_subproof. Qed.
End Properties.
Section IdCompFun.
Variables (d : disp_t) (T : latticeType d) (d' : disp_t) (T' : latticeType d').
Variables (d'' : disp_t) (T'' : latticeType d'').
Section MeetCompFun.
Variables (f : {mlmorphism T' -> T''}) (g : {mlmorphism T -> T'}).
Fact idfun_is_meet_morphism : meet_morphism (@idfun T). Proof. by []. Qed.
#[export]
HB.instance Definition _ := isMeetLatticeMorphism.Build d T d T idfun
idfun_is_meet_morphism.
Fact comp_is_meet_morphism : meet_morphism (f \o g).
Proof. by move=> x y; rewrite /= !omorphI. Qed.
#[export]
HB.instance Definition _ := isMeetLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_meet_morphism.
End MeetCompFun.
Section JoinCompFun.
Variables (f : {jlmorphism T' -> T''}) (g : {jlmorphism T -> T'}).
Fact idfun_is_join_morphism : join_morphism (@idfun T). Proof. by []. Qed.
#[export]
HB.instance Definition _ := isJoinLatticeMorphism.Build d T d T idfun
idfun_is_join_morphism.
Fact comp_is_join_morphism : join_morphism (f \o g).
Proof. by move=> x y; rewrite /= !omorphU. Qed.
#[export]
HB.instance Definition _ := isJoinLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_join_morphism.
End JoinCompFun.
End IdCompFun.
End LatticeMorphismTheory.
End LatticeMorphismTheory.
HB.mixin Record isBLatticeMorphism d (T : bLatticeType d)
d' (T' : bLatticeType d') (apply : T -> T') := {
omorph0_subproof : apply \bot = \bot;
}.
HB.mixin Record isTLatticeMorphism d (T : tLatticeType d)
d' (T' : tLatticeType d') (apply : T -> T') := {
omorph1_subproof : apply \top = \top;
}.
HB.structure Definition BLatticeMorphism d (T : bLatticeType d)
d' (T' : bLatticeType d') := {f of isBLatticeMorphism d T d' T' f}.
HB.structure Definition TLatticeMorphism d (T : tLatticeType d)
d' (T' : tLatticeType d') := {f of isTLatticeMorphism d T d' T' f}.
HB.structure Definition TBLatticeMorphism d (T : tbLatticeType d)
d' (T' : tbLatticeType d') :=
{f of @BLatticeMorphism d T d' T' f & @TLatticeMorphism d T d' T' f}.
Module TBLatticeMorphismExports.
Notation "{ 'blmorphism' T -> T' }" :=
(@BLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'tlmorphism' T -> T' }" :=
(@TLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'tblmorphism' T -> T' }" :=
(@TBLatticeMorphism.type _ T%type _ T'%type) : type_scope.
End TBLatticeMorphismExports.
HB.export TBLatticeMorphismExports.
Module Import BLatticeMorphismTheory.
Section BLatticeMorphismTheory.
Section Properties.
Variables (d : disp_t) (T : bLatticeType d).
Variables (d' : disp_t) (T' : bLatticeType d').
Variables (f : {blmorphism T -> T'}).
Lemma omorph0 : f \bot = \bot.
Proof. exact: omorph0_subproof. Qed.
End Properties.
Section IdCompFun.
Variables (d : disp_t) (T : bLatticeType d).
Variables (d' : disp_t) (T' : bLatticeType d').
Variables (d'' : disp_t) (T'' : bLatticeType d'').
Variables (f : {blmorphism T' -> T''}) (g : {blmorphism T -> T'}).
Fact idfun_is_bottom_morphism : (@idfun T) \bot = \bot. Proof. by []. Qed.
#[export]
HB.instance Definition _ := isBLatticeMorphism.Build d T d T idfun
idfun_is_bottom_morphism.
Fact comp_is_bottom_morphism : (f \o g) \bot = \bot.
Proof. by rewrite /= !omorph0. Qed.
#[export]
HB.instance Definition _ := isBLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_bottom_morphism.
End IdCompFun.
End BLatticeMorphismTheory.
End BLatticeMorphismTheory.
Module Import TLatticeMorphismTheory.
Section TLatticeMorphismTheory.
Section Properties.
Variables (d : disp_t) (T : tLatticeType d).
Variables (d' : disp_t) (T' : tLatticeType d').
Variables (f : {tlmorphism T -> T'}).
Lemma omorph1 : f \top = \top.
Proof. exact: omorph1_subproof. Qed.
End Properties.
Section IdCompFun.
Variables (d : disp_t) (T : tLatticeType d).
Variables (d' : disp_t) (T' : tLatticeType d').
Variables (d'' : disp_t) (T'' : tLatticeType d'').
Variables (f : {tlmorphism T' -> T''}) (g : {tlmorphism T -> T'}).
Fact idfun_is_top_morphism : (@idfun T) \top = \top. Proof. by []. Qed.
#[export]
HB.instance Definition _ := isTLatticeMorphism.Build d T d T idfun
idfun_is_top_morphism.
Fact comp_is_top_morphism : (f \o g) \top = \top.
Proof. by rewrite /= !omorph1. Qed.
#[export]
HB.instance Definition _ := isTLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_top_morphism.
End IdCompFun.
End TLatticeMorphismTheory.
End TLatticeMorphismTheory.
Module Import ClosedPredicates.
Section ClosedPredicates.
Variable (d : disp_t) (T : latticeType d).
Variable S : {pred T}.
Definition meet_closed := {in S &, forall u v, u `&` v \in S}.
Definition join_closed := {in S &, forall u v, u `|` v \in S}.
End ClosedPredicates.
End ClosedPredicates.
(* Mixins for stability properties *)
HB.mixin Record isMeetLatticeClosed d (T : latticeType d) (S : {pred T}) := {
opredI : meet_closed S;
}.
HB.mixin Record isJoinLatticeClosed d (T : latticeType d) (S : {pred T}) := {
opredU : join_closed S;
}.
HB.mixin Record isBLatticeClosed d (T : bLatticeType d) (S : {pred T}) := {
opred0 : \bot \in S;
}.
HB.mixin Record isTLatticeClosed d (T : tLatticeType d) (S : {pred T}) := {
opred1 : \top \in S;
}.
(* Structures for stability properties *)
#[short(type="meetLatticeClosed")]
HB.structure Definition MeetLatticeClosed d T :=
{S of isMeetLatticeClosed d T S}.
#[short(type="joinLatticeClosed")]
HB.structure Definition JoinLatticeClosed d T :=
{S of isJoinLatticeClosed d T S}.
#[short(type="latticeClosed")]
HB.structure Definition LatticeClosed d T :=
{S of @MeetLatticeClosed d T S & @JoinLatticeClosed d T S}.
#[short(type="bLatticeClosed")]
HB.structure Definition BLatticeClosed d T := {S of isBLatticeClosed d T S}.
#[short(type="bJoinLatticeClosed")]
HB.structure Definition BJoinLatticeClosed d T :=
{S of isBLatticeClosed d T S & @JoinLatticeClosed d T S}.
#[short(type="tLatticeClosed")]
HB.structure Definition TLatticeClosed d T := {S of isTLatticeClosed d T S}.
#[short(type="tMeetLatticeClosed")]
HB.structure Definition TMeetLatticeClosed d T :=
{S of isTLatticeClosed d T S & @MeetLatticeClosed d T S}.
#[short(type="tbLatticeClosed")]
HB.structure Definition TBLatticeClosed d (T : tbLatticeType d) :=
{S of @BLatticeClosed d T S & @TLatticeClosed d T S}.
HB.factory Record isLatticeClosed d (T : latticeType d) (S : {pred T}) := {
opredI : meet_closed S;
opredU : join_closed S;
}.
HB.builders Context d T S of isLatticeClosed d T S.
HB.instance Definition _ := isMeetLatticeClosed.Build d T S opredI.
HB.instance Definition _ := isJoinLatticeClosed.Build d T S opredU.
HB.end.
HB.factory Record isTBLatticeClosed d (T : tbLatticeType d) (S : {pred T}) := {
opredI : meet_closed S;
opredU : join_closed S;
opred0 : \bot \in S;
opred1 : \top \in S;
}.
HB.builders Context d T S of isTBLatticeClosed d T S.
HB.instance Definition _ := isLatticeClosed.Build d T S opredI opredU.
HB.instance Definition _ := isBLatticeClosed.Build d T S opred0.
HB.instance Definition _ := isTLatticeClosed.Build d T S opred1.
HB.end.
Module Import LatticePred.
Section LatticePred.
Variables (d : disp_t) (T : latticeType d).
Lemma opredI (S : meetLatticeClosed T) : {in S &, forall u v, u `&` v \in S}.
Proof. exact: opredI. Qed.
Lemma opredU (S : joinLatticeClosed T) : {in S &, forall u v, u `|` v \in S}.
Proof. exact: opredU. Qed.
End LatticePred.
Section BLatticePred.
Variables (d : disp_t) (T : bLatticeType d).
Lemma opred0 (S : bLatticeClosed T) : \bot \in S.
Proof. exact: opred0. Qed.
Lemma opred_joins (S : bJoinLatticeClosed T) I r (P : pred I) F :
(forall i, P i -> F i \in S) -> \join_(i <- r | P i) F i \in S.
Proof. by move=> FS; elim/big_ind: _; [exact: opred0 | exact: opredU |]. Qed.
End BLatticePred.
Section TLatticePred.
Variables (d : disp_t) (T : tLatticeType d).
Lemma opred1 (S : tLatticeClosed T) : \top \in S.
Proof. exact: opred1. Qed.
Lemma opred_meets (S : tMeetLatticeClosed T) I r (P : pred I) F :
(forall i, P i -> F i \in S) -> \meet_(i <- r | P i) F i \in S.
Proof. by move=> FS; elim/big_ind: _; [exact: opred1 | exact: opredI |]. Qed.
End TLatticePred.
End LatticePred.
#[short(type="subPOrder")]
HB.structure Definition SubPOrder d (T : porderType d) S d' :=
{ U of SubEquality T S U & POrder d' U & isSubPreorder d T S d' U }.
HB.factory Record SubChoice_isSubPOrder d (T : porderType d) S (d' : disp_t) U
of SubChoice T S U := {}.
HB.builders Context d T S d' U of SubChoice_isSubPOrder d T S d' U.
HB.instance Definition _ := SubChoice_isSubPreorder.Build d T S d' U.
HB.instance Definition _ := Preorder_isPOrder.Build d' U
(@CancelPartial.anti U d T _ _ (@valK _ _ U)).
HB.end.
#[export]
HB.instance Definition _ d (T : porderType d) (S : pred T) (d' : disp_t)
(U : subType S) := SubChoice_isSubPOrder.Build d T S d' (sub_type U).
HB.mixin Record isMeetSubLattice d (T : latticeType d) (S : pred T) d' U
of SubType T S U & Lattice d' U := {
valI_subproof : {morph (val : U -> T) : x y / x `&` y};
}.
HB.mixin Record isJoinSubLattice d (T : latticeType d) (S : pred T) d' U
of SubType T S U & Lattice d' U := {
valU_subproof : {morph (val : U -> T) : x y / x `|` y};
}.
#[short(type="subPOrderLattice")]
HB.structure Definition SubPOrderLattice d (T : latticeType d) S d' :=
{ U of @SubPOrder d T S d' U & Lattice d' U }.
#[short(type="subPOrderBLattice")]
HB.structure Definition SubPOrderBLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & BLattice d' U }.
#[short(type="subPOrderTLattice")]
HB.structure Definition SubPOrderTLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & TLattice d' U }.
#[short(type="subPOrderTBLattice")]
HB.structure Definition SubPOrderTBLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & TBLattice d' U }.
#[short(type="meetSubLattice")]
HB.structure Definition MeetSubLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & isMeetSubLattice d T S d' U }.
#[short(type="meetSubBLattice")]
HB.structure Definition MeetSubBLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & BLattice d' U }.
#[short(type="meetSubTLattice")]
HB.structure Definition MeetSubTLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & TLattice d' U }.
#[short(type="meetSubTBLattice")]
HB.structure Definition MeetSubTBLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & TBLattice d' U }.
#[short(type="joinSubLattice")]
HB.structure Definition JoinSubLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & isJoinSubLattice d T S d' U }.
#[short(type="joinSubBLattice")]
HB.structure Definition JoinSubBLattice d (T : latticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & BLattice d' U }.
#[short(type="joinSubTLattice")]
HB.structure Definition JoinSubTLattice d (T : latticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & TLattice d' U }.
#[short(type="joinSubTBLattice")]
HB.structure Definition JoinSubTBLattice d (T : latticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & TBLattice d' U }.
#[short(type="subLattice")]
HB.structure Definition SubLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & @JoinSubLattice d T S d' U }.
#[short(type="subBLattice")]
HB.structure Definition SubBLattice d (T : latticeType d) S d' :=
{ U of @SubLattice d T S d' U & BLattice d' U }.
#[short(type="subTLattice")]
HB.structure Definition SubTLattice d (T : latticeType d) S d' :=
{ U of @SubLattice d T S d' U & TLattice d' U }.
#[short(type="subTBLattice")]
HB.structure Definition SubTBLattice d (T : latticeType d) S d' :=
{ U of @SubLattice d T S d' U & TBLattice d' U }.
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (d : disp_t) (T : latticeType d) (S : pred T)
d' (U : MeetSubLattice.type S d') :=
isMeetLatticeMorphism.Build d' U d T val valI_subproof.
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (d : disp_t) (T : latticeType d) (S : pred T)
d' (U : JoinSubLattice.type S d') :=
isJoinLatticeMorphism.Build d' U d T val valU_subproof.
HB.factory Record SubPOrder_isSubLattice d (T : latticeType d) S d' U
of @SubPOrder d T S d' U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
}.
HB.builders Context d T S d' U of SubPOrder_isSubLattice d T S d' U.
HB.instance Definition _ := isLatticeClosed.Build d T S
opredI_subproof opredU_subproof.
Let inU v Sv : U := Sub v Sv.
Let meetU (u1 u2 : U) : U := inU (opredI (valP u1) (valP u2)).
Let joinU (u1 u2 : U) : U := inU (opredU (valP u1) (valP u2)).
Let meetUC : commutative meetU.
Proof. by move=> x y; apply: val_inj; rewrite !SubK meetC. Qed.
Let joinUC : commutative joinU.
Proof. by move=> x y; apply: val_inj; rewrite !SubK joinC. Qed.
Let meetUA : associative meetU.
Proof. by move=> x y z; apply: val_inj; rewrite !SubK meetA. Qed.
Let joinUA : associative joinU.
Proof. by move=> x y z; apply: val_inj; rewrite !SubK joinA. Qed.
Lemma joinUKI y x : meetU x (joinU x y) = x.
Proof. by apply: val_inj; rewrite !SubK joinKI. Qed.
Let meetUKU y x : joinU x (meetU x y) = x.
Proof. by apply: val_inj; rewrite !SubK meetKU. Qed.
Let le_meetU x y : (x <= y) = (meetU x y == x).
Proof. by rewrite -le_val -(inj_eq val_inj) SubK leEmeet. Qed.
HB.instance Definition _ := POrder_isLattice.Build d' U
meetUC joinUC meetUA joinUA joinUKI meetUKU le_meetU.
Fact valI : meet_morphism (val : U -> T).
Proof. by move=> x y; rewrite !SubK. Qed.
Fact valU : join_morphism (val : U -> T).
Proof. by move=> x y; rewrite !SubK. Qed.
HB.instance Definition _ := isMeetSubLattice.Build d T S d' U valI.
HB.instance Definition _ := isJoinSubLattice.Build d T S d' U valU.
HB.end.
HB.factory Record SubChoice_isSubLattice d (T : latticeType d) S (d' : disp_t) U
of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
}.
HB.builders Context d T S d' U of SubChoice_isSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubPOrder.Build d T S d' U.
HB.instance Definition _ := SubPOrder_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.end.
HB.mixin Record isBSubLattice d (T : bLatticeType d) (S : pred T) d' U
of SubType T S U & BLattice d' U := {
val0_subproof : (val : U -> T) \bot = \bot;
}.
#[short(type="bJoinSubLattice")]
HB.structure Definition BJoinSubLattice d (T : bLatticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & BLattice d' U & isBSubLattice d T S d' U }.
#[short(type="bJoinSubTLattice")]
HB.structure Definition BJoinSubTLattice d (T : bLatticeType d) S d' :=
{ U of @BJoinSubLattice d T S d' U & TBLattice d' U }.
#[short(type="bSubLattice")]
HB.structure Definition BSubLattice d (T : bLatticeType d) S d' :=
{ U of @SubLattice d T S d' U & @BJoinSubLattice d T S d' U }.
#[short(type="bSubTLattice")]
HB.structure Definition BSubTLattice d (T : bLatticeType d) S d' :=
{ U of @BSubLattice d T S d' U & TBLattice d' U }.
#[export]
HB.instance Definition _ (d : disp_t) (T : bLatticeType d) (S : pred T)
d' (U : BJoinSubLattice.type S d') :=
isBLatticeMorphism.Build d' U d T val val0_subproof.
HB.factory Record SubPOrder_isBSubLattice d (T : bLatticeType d) S d' U
of @SubPOrder d T S d' U & Lattice d' U := {
opred0_subproof : \bot \in S;
}.
HB.builders Context d T S d' U of SubPOrder_isBSubLattice d T S d' U.
Let inU v Sv : U := Sub v Sv.
Let zeroU : U := inU opred0_subproof.
Fact le0x x : zeroU <= x. Proof. by rewrite -le_val /= SubK le0x. Qed.
HB.instance Definition _ := hasBottom.Build d' U le0x.
Fact val0 : (val : U -> T) \bot = \bot. Proof. by rewrite SubK. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := isBSubLattice.Build d T S d' U val0.
HB.end.
HB.factory Record SubChoice_isBSubLattice
d (T : bLatticeType d) S (d' : disp_t) U of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
opred0_subproof : \bot \in S;
}.
HB.builders Context d T S d' U of SubChoice_isBSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.instance Definition _ := SubPOrder_isBSubLattice.Build d T S d' U
opred0_subproof.
HB.end.
HB.mixin Record isTSubLattice d (T : tLatticeType d) (S : pred T) d' U
of SubType T S U & TLattice d' U := {
val1_subproof : (val : U -> T) \top = \top;
}.
#[short(type="tMeetSubLattice")]
HB.structure Definition TMeetSubLattice d (T : tLatticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & TLattice d' U & isTSubLattice d T S d' U }.
#[short(type="tMeetSubBLattice")]
HB.structure Definition TMeetSubBLattice d (T : tLatticeType d) S d' :=
{ U of @TMeetSubLattice d T S d' U & TBLattice d' U }.
#[short(type="tSubLattice")]
HB.structure Definition TSubLattice d (T : tLatticeType d) S d' :=
{ U of @SubLattice d T S d' U & @TMeetSubLattice d T S d' U }.
#[short(type="tSubBLattice")]
HB.structure Definition TSubBLattice d (T : tLatticeType d) S d' :=
{ U of @TSubLattice d T S d' U & TBLattice d' U }.
#[export]
HB.instance Definition _ (d : disp_t) (T : tLatticeType d) (S : pred T)
d' (U : TMeetSubLattice.type S d') :=
isTLatticeMorphism.Build d' U d T val val1_subproof.
HB.factory Record SubPOrder_isTSubLattice d (T : tLatticeType d) S d' U
of @SubPOrder d T S d' U & Lattice d' U := {
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubPOrder_isTSubLattice d T S d' U.
Let inU v Sv : U := Sub v Sv.
Let oneU : U := inU opred1_subproof.
Fact lex1 x : x <= oneU. Proof. by rewrite -le_val /= SubK lex1. Qed.
HB.instance Definition _ := hasTop.Build d' U lex1.
Fact val1 : (val : U -> T) \top = \top. Proof. by rewrite SubK. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := isTSubLattice.Build d T S d' U val1.
HB.end.
HB.factory Record SubChoice_isTSubLattice
d (T : tLatticeType d) S (d' : disp_t) U of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubChoice_isTSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.instance Definition _ := SubPOrder_isTSubLattice.Build d T S d' U
opred1_subproof.
HB.end.
#[short(type="tbSubLattice")]
HB.structure Definition TBSubLattice d (T : tbLatticeType d) S d' :=
{ U of @BSubLattice d T S d' U & @TSubLattice d T S d' U}.
#[export]
HB.instance Definition _ (d : disp_t) (T : tbLatticeType d) (S : pred T) d'
(U : TBSubLattice.type S d') := BLatticeMorphism.on (val : U -> T).
HB.factory Record SubPOrder_isTBSubLattice d (T : tbLatticeType d) S d' U
of @SubPOrder d T S d' U & Lattice d' U := {
opred0_subproof : \bot \in S;
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubPOrder_isTBSubLattice d T S d' U.
HB.instance Definition _ := SubPOrder_isBSubLattice.Build d T S d' U
opred0_subproof.
HB.instance Definition _ := SubPOrder_isTSubLattice.Build d T S d' U
opred1_subproof.
HB.end.
HB.factory Record SubChoice_isTBSubLattice d (T : tbLatticeType d) S
(d' : disp_t) U of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
opred0_subproof : \bot \in S;
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubChoice_isTBSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.instance Definition _ := SubPOrder_isTBSubLattice.Build d T S d' U
opred0_subproof opred1_subproof.
HB.end.
#[short(type="subOrder")]
HB.structure Definition SubOrder d (T : orderType d) S d' :=
{ U of @SubLattice d T S d' U & Total d' U }.
HB.factory Record SubLattice_isSubOrder d (T : orderType d) S d' U
of @SubLattice d T S d' U := {}.
HB.builders Context d T S d' U of SubLattice_isSubOrder d T S d' U.
Lemma totalU : total (<=%O : rel U).
Proof. by move=> x y; rewrite -!le_val le_total. Qed.
HB.instance Definition _ := Lattice_isTotal.Build d' U totalU.
HB.end.
HB.factory Record SubPOrder_isSubOrder d (T : orderType d) S d' U
of @SubPOrder d T S d' U := {}.
HB.builders Context d T S d' U of SubPOrder_isSubOrder d T S d' U.
Fact opredI : meet_closed S.
Proof. by move=> x y Sx Sy; rewrite meetEtotal; case: leP. Qed.
Fact opredU : join_closed S.
Proof. by move=> x y Sx Sy; rewrite joinEtotal; case: leP. Qed.
HB.instance Definition _ := SubPOrder_isSubLattice.Build d T S d' U opredI opredU.
HB.instance Definition _ := SubLattice_isSubOrder.Build d T S d' U.
HB.end.
HB.factory Record SubChoice_isSubOrder d (T : orderType d) S (d' : disp_t) U
of @SubChoice T S U := {}.
HB.builders Context d T S d' U of SubChoice_isSubOrder d T S d' U.
HB.instance Definition _ := SubChoice_isSubPOrder.Build d T S d' U.
HB.instance Definition _ := SubPOrder_isSubOrder.Build d T S d' U.
HB.end.
Module SubOrderExports.
Notation "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: ]" :=
(SubChoice_isSubPOrder.Build _ _ _ _ U)
(format "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isSubPOrder.Build _ _ _ disp U)
(format "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubChoice_isSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubChoice_isSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isBSubLattice.Build _ _ _ _ U (opred0 _))
(format "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isBSubLattice.Build _ _ _ disp U (opred0 _))
(format "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isBSubLattice.Build _ _ _ _ U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _))
(format "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isBSubLattice.Build _ _ _ disp U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _))
(format "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isTSubLattice.Build _ _ _ _ U (opred1 _))
(format "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isTSubLattice.Build _ _ _ disp U (opred1 _))
(format "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isTSubLattice.Build _ _ _ _ U
(@opredI _ _ _) (@opredU _ _ _) (opred1 _))
(format "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isTSubLattice.Build _ _ _ disp U
(@opredI _ _ _) (@opredU _ _ _) (opred1 _))
(format "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isTBSubLattice.Build _ _ _ _ U (opred0 _) (opred1 _))
(format "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isTBSubLattice.Build _ _ _ disp U (opred0 _) (opred1 _))
(format "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isTBSubLattice.Build _ _ _ _ U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _) (opred1 _))
(format "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isTBSubLattice.Build _ _ _ disp U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _) (opred1 _))
(format "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubLattice_isSubOrder' 'of' U 'by' <: ]" :=
(SubLattice_isSubOrder.Build _ _ _ _ U)
(format "[ 'SubLattice_isSubOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubLattice_isSubOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubLattice_isSubOrder.Build _ _ _ disp U)
(format "[ 'SubLattice_isSubOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: ]" :=
(SubPOrder_isSubOrder.Build _ _ _ _ U)
(format "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isSubOrder.Build _ _ _ disp U)
(format "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isSubOrder' 'of' U 'by' <: ]" :=
(SubChoice_isSubOrder.Build _ _ _ _ U)
(format "[ 'SubChoice_isSubOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isSubOrder.Build _ _ _ disp U)
(format "[ 'SubChoice_isSubOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
End SubOrderExports.
HB.export SubOrderExports.
Module DeprecatedSubOrder.
Section Total.
Context {disp : disp_t} {T : orderType disp} (P : {pred T}) (sT : subType P).
#[export]
HB.instance Definition _ :=
SubPOrder_isSubOrder.Build disp T P disp (sub_type sT).
End Total.
Module Exports.
HB.reexport DeprecatedSubOrder.
Notation "[ 'POrder' 'of' T 'by' <: ]" :=
(POrder.copy T%type (sub_type T%type))
(format "[ 'POrder' 'of' T 'by' <: ]") : form_scope.
Notation "[ 'Order' 'of' T 'by' <: ]" :=
(Total.copy T%type (sub_type T%type))
(only parsing) : form_scope.
End Exports.
End DeprecatedSubOrder.
HB.export DeprecatedSubOrder.Exports.
(*************)
(* INSTANCES *)
(*************)
(********************)
(* Instances on nat *)
(********************)
(******************************************************************************)
(* This is an example of creation of multiple instances on the same type, *)
(* with distinct displays, using natural numbers. *)
(* We declare two distinct canonical orders: *)
(* - leq which is total, and where meet and join are minn and maxn, on nat *)
(* - dvdn which is partial, and where meet and join are gcdn and lcmn, *)
(* on natdvd *)
(******************************************************************************)
(******************************************************************************)
(* The Module NatOrder defines leq as the canonical order on the type nat, *)
(* i.e., without creating an alias. We define and use nat_display and proceed *)
(* like a standard canonical structure declaration, except that we use this *)
(* display. We also use a single factory LeOrderMixin to instantiate three *)
(* different canonical declarations porderType, distrLatticeType, orderType. *)
(* We finish by providing theorems to convert the operations of ordered and *)
(* lattice types to their definition without structure abstraction. *)
(******************************************************************************)
Module NatOrder.
Section NatOrder.
Export NatOrder.
#[export]
HB.instance Definition _ :=
Preorder_isPOrder.Build nat_display nat anti_leq.
#[export]
HB.instance Definition _ :=
POrder_isTotal.Build nat_display nat leq_total.
End NatOrder.
Module Exports.
HB.reexport NatOrder.
End Exports.
End NatOrder.
HB.export NatOrder.Exports.
Module NatMonotonyTheory.
Section NatMonotonyTheory.
Export NatMonotonyTheory.
Context {disp : disp_t} {T : porderType disp}.
Variables (D : {pred nat}) (f : nat -> T).
Hypothesis Dconvex : {in D &, forall i j k, i < k < j -> k \in D}.
Lemma incn_inP : {in D, forall i, i.+1 \in D -> f i < f i.+1} ->
{in D &, {mono f : i j / i <= j}}.
Proof. by move=> f_inc; apply/le_mono_in/homo_ltn_lt_in. Qed.
Lemma decn_inP : {in D, forall i, i.+1 \in D -> f i > f i.+1} ->
{in D &, {mono f : i j /~ i <= j}}.
Proof. by move=> f_dec; apply/le_nmono_in/nhomo_ltn_lt_in. Qed.
Lemma incnP : (forall i, f i < f i.+1) -> {mono f : i j / i <= j}.
Proof. by move=> f_inc; apply/le_mono/homo_ltn_lt. Qed.
Lemma decnP : (forall i, f i > f i.+1) -> {mono f : i j /~ i <= j}.
Proof. by move=> f_dec; apply/le_nmono/nhomo_ltn_lt. Qed.
End NatMonotonyTheory.
Arguments incn_inP {disp T} [D f].
Arguments decn_inP {disp T} [D f].
Arguments incnP {disp T} [f].
Arguments decnP {disp T} [f].
End NatMonotonyTheory.
(****************************************************************************)
(* The Module DvdSyntax introduces a new set of notations using the newly *)
(* created display dvd_display. We first define the display as an opaque *)
(* definition of type disp_t, and we use it as the first argument of the *)
(* operator which display we want to change from the default one (here le, *)
(* lt, dvd sdvd, meet, join, top and bottom, as well as big op notations on *)
(* gcd and lcm). This notations will now be used for any ordered type which *)
(* first parameter is set to dvd_display. *)
(****************************************************************************)
Module DvdSyntax.
Export DvdSyntax.
Notation gcd := (@meet dvd_display _).
Notation "@ 'gcd' T" := (@meet dvd_display T)
(at level 10, T at level 8, only parsing) : function_scope.
Notation lcm := (@join dvd_display _).
Notation "@ 'lcm' T" := (@join dvd_display T)
(at level 10, T at level 8, only parsing) : function_scope.
Notation "\gcd_ ( i <- r | P ) F" :=
(\big[gcd/nat0]_(i <- r | P%B) F%O) : order_scope.
Notation "\gcd_ ( i <- r ) F" :=
(\big[gcd/nat0]_(i <- r) F%O) : order_scope.
Notation "\gcd_ ( i | P ) F" :=
(\big[gcd/nat0]_(i | P%B) F%O) : order_scope.
Notation "\gcd_ i F" :=
(\big[gcd/nat0]_i F%O) : order_scope.
Notation "\gcd_ ( i : I | P ) F" :=
(\big[gcd/nat0]_(i : I | P%B) F%O) (only parsing) :
order_scope.
Notation "\gcd_ ( i : I ) F" :=
(\big[gcd/nat0]_(i : I) F%O) (only parsing) : order_scope.
Notation "\gcd_ ( m <= i < n | P ) F" :=
(\big[gcd/nat0]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\gcd_ ( m <= i < n ) F" :=
(\big[gcd/nat0]_(m <= i < n) F%O) : order_scope.
Notation "\gcd_ ( i < n | P ) F" :=
(\big[gcd/nat0]_(i < n | P%B) F%O) : order_scope.
Notation "\gcd_ ( i < n ) F" :=
(\big[gcd/nat0]_(i < n) F%O) : order_scope.
Notation "\gcd_ ( i 'in' A | P ) F" :=
(\big[gcd/nat0]_(i in A | P%B) F%O) : order_scope.
Notation "\gcd_ ( i 'in' A ) F" :=
(\big[gcd/nat0]_(i in A) F%O) : order_scope.
Notation "\lcm_ ( i <- r | P ) F" :=
(\big[lcm/nat1]_(i <- r | P%B) F%O) : order_scope.
Notation "\lcm_ ( i <- r ) F" :=
(\big[lcm/nat1]_(i <- r) F%O) : order_scope.
Notation "\lcm_ ( i | P ) F" :=
(\big[lcm/nat1]_(i | P%B) F%O) : order_scope.
Notation "\lcm_ i F" :=
(\big[lcm/nat1]_i F%O) : order_scope.
Notation "\lcm_ ( i : I | P ) F" :=
(\big[lcm/nat1]_(i : I | P%B) F%O) (only parsing) :
order_scope.
Notation "\lcm_ ( i : I ) F" :=
(\big[lcm/nat1]_(i : I) F%O) (only parsing) : order_scope.
Notation "\lcm_ ( m <= i < n | P ) F" :=
(\big[lcm/nat1]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\lcm_ ( m <= i < n ) F" :=
(\big[lcm/nat1]_(m <= i < n) F%O) : order_scope.
Notation "\lcm_ ( i < n | P ) F" :=
(\big[lcm/nat1]_(i < n | P%B) F%O) : order_scope.
Notation "\lcm_ ( i < n ) F" :=
(\big[lcm/nat1]_(i < n) F%O) : order_scope.
Notation "\lcm_ ( i 'in' A | P ) F" :=
(\big[lcm/nat1]_(i in A | P%B) F%O) : order_scope.
Notation "\lcm_ ( i 'in' A ) F" :=
(\big[lcm/nat1]_(i in A) F%O) : order_scope.
End DvdSyntax.
(******************************************************************************)
(* The Module NatDvd defines dvdn as the canonical order on NatDvd.t, which *)
(* is abbreviated using the notation natdvd at the end of the module. *)
(* We use the newly defined dvd_display, described above. *)
(* We first recover structures that are common to both nat and natdvd *)
(* (eqType, choiceType, countType) through the copy mechanism, then we use *)
(* a single factory MeetJoinMixin to instantiate both porderType and *)
(* distrLatticeType canonical structures, and end with top and bottom. *)
(* We finish by providing theorems to convert the operations of ordered and *)
(* lattice types to their definition without structure abstraction. *)
(******************************************************************************)
Module NatDvd.
Export NatDvd.
Section NatDvd.
Implicit Types (m n p : natdvd).
Lemma lcmnn n : lcmn n n = n.
Proof. by case: n => // n; rewrite /lcmn gcdnn mulnK. Qed.
Lemma le_def m n : m %| n = (gcdn m n == m)%N.
Proof. by apply/gcdn_idPl/eqP. Qed.
Lemma joinKI n m : gcdn m (lcmn m n) = m.
Proof. by rewrite (gcdn_idPl _)// dvdn_lcml. Qed.
Lemma meetKU n m : lcmn m (gcdn m n) = m.
Proof. by rewrite (lcmn_idPl _)// dvdn_gcdl. Qed.
Lemma meetUl : left_distributive gcdn lcmn.
Proof.
move=> [|m'] [|n'] [|p'] //=; rewrite ?lcmnn ?lcm0n ?lcmn0 ?gcd0n ?gcdn0//.
- by rewrite gcdnC meetKU.
- by rewrite lcmnC gcdnC meetKU.
apply: eqn_from_log; rewrite ?(gcdn_gt0, lcmn_gt0)//= => p.
by rewrite !(logn_gcd, logn_lcm) ?(gcdn_gt0, lcmn_gt0)// minn_maxl.
Qed.
Fact dvdn_anti : antisymmetric dvdn.
Proof. by move=> a b => /andP[] /gcdn_idPl + /gcdn_idPr => ->. Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build dvd_display t dvdn_anti.
#[export]
HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build dvd_display t
gcdn lcmn gcdnC lcmnC gcdnA lcmnA joinKI meetKU le_def meetUl.
Import DvdSyntax.
Lemma sdvdE (m n : t) : m %<| n = (n != m) && (m %| n).
Proof. exact/lt_def. Qed.
Lemma gcdE : gcd = gcdn :> (t -> t -> t). Proof. by []. Qed.
Lemma lcmE : lcm = lcmn :> (t -> t -> t). Proof. by []. Qed.
End NatDvd.
Module Exports.
HB.reexport NatDvd.
Definition sdvdEnat := sdvdE.
Definition gcdEnat := gcdE.
Definition lcmEnat := lcmE.
End Exports.
End NatDvd.
HB.export NatDvd.Exports.
(************************)
(* Instances on ordinal *)
(************************)
Module OrdinalOrder.
Export OrdinalOrder.
#[export]
HB.instance Definition _ (n : nat) :=
[SubChoice_isSubOrder of 'I_n by <: with ord_display].
End OrdinalOrder.
HB.export OrdinalOrder.
(*********************)
(* Instances on bool *)
(*********************)
Module BoolOrder.
Export BoolOrder.
Section BoolOrder.
Implicit Types (x y : bool).
Fact andbE x y : x && y = if (x < y)%N then x else y.
Proof. by case: x y => [] []. Qed.
Fact orbE x y : x || y = if (x < y)%N then y else x.
Proof. by case: x y => [] []. Qed.
Fact anti : antisymmetric (leq : rel bool).
Proof. by move=> x y /anti_leq /(congr1 odd); rewrite !oddb. Qed.
#[export] HB.instance Definition _ := Preorder_isPOrder.Build bool_display bool
anti.
Fact orKb b a : a && (a || b) = a.
Proof. by rewrite orbC orKb. Qed.
Fact andKb y x : x || x && y = x.
Proof. by rewrite andbC andKb. Qed.
Fact leEmeet x y : (x <= y) = (x && y == x).
Proof. by case: x; case: y. Qed.
#[export] HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build
bool_display bool andb orb andbC orbC andbA orbA orKb andKb leEmeet andb_orl.
#[export] HB.instance Definition _ := DistrLattice_isTotal.Build bool_display
bool leq_total.
#[export] HB.instance Definition _ :=
@TBDistrLattice_hasComplement.Build _ bool negb orbN andbN.
Lemma andEbool : meet = andb. Proof. by []. Qed.
Lemma orEbool : meet = andb. Proof. by []. Qed.
Lemma subEbool x y : x `\` y = x && ~~ y. Proof. by []. Qed.
Lemma complEbool : compl = negb. Proof. by []. Qed.
End BoolOrder.
Module Exports.
HB.reexport BoolOrder.
Definition leEbool := leEbool.
Definition ltEbool := ltEbool.
Definition andEbool := andEbool.
Definition orEbool := orEbool.
Definition subEbool := subEbool.
Definition complEbool := complEbool.
End Exports.
End BoolOrder.
HB.export BoolOrder.Exports.
(******************************)
(* Definition of prod_display *)
(******************************)
Module Import ProdSyntax.
Export ProdSyntax.
(* The following Local Notations are here to define the \join^p_ and \meet^p_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (prod_display _ _) _).
Local Notation "\top" := (@top (prod_display _ _) _).
Local Notation meet := (@meet (prod_display _ _) _).
Local Notation join := (@join (prod_display _ _) _).
Local Notation min := (@min (prod_display _ _) _).
Local Notation max := (@max (prod_display _ _) _).
Notation "x `&^p` y" := (meet x y) : order_scope.
Notation "x `|^p` y" := (join x y) : order_scope.
Notation "\join^p_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^p_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^p_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^p_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^p_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^p_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^p_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^p_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^p_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^p_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^p_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^p_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^p_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^p_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^p_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^p_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^p_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^p_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^p_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^p_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^p_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^p_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^p_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^p_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^p_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^p_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^p_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^p_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^p_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^p_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^p_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^p_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^p_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^p_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^p_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^p_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^p_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^p_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^p_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^p_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^p_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^p_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^p_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^p_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^p_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^p_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^p_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^p_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End ProdSyntax.
Module Import SeqProdSyntax.
Export SeqProdSyntax.
(* The following Local Notations are here to define the \join^sp_ and *)
(* \meet^sp_ notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (seqprod_display _) _).
Local Notation "\top" := (@top (seqprod_display _) _).
Local Notation meet := (@meet (seqprod_display _) _).
Local Notation join := (@join (seqprod_display _) _).
Local Notation min := (@min (seqprod_display _) _).
Local Notation max := (@max (seqprod_display _) _).
Notation "x `&^sp` y" := (meet x y) : order_scope.
Notation "x `|^sp` y" := (join x y) : order_scope.
Notation "\join^sp_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^sp_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^sp_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^sp_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^sp_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^sp_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^sp_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^sp_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^sp_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^sp_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^sp_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^sp_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^sp_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^sp_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^sp_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^sp_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^sp_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^sp_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^sp_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^sp_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^sp_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^sp_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^sp_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^sp_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^sp_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^sp_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^sp_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^sp_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^sp_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^sp_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^sp_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^sp_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^sp_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^sp_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^sp_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^sp_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End SeqProdSyntax.
Module Import LexiSyntax.
Export LexiSyntax.
Notation meetlexi := (@meet (lexi_display _ _) _).
Notation joinlexi := (@join (lexi_display _ _) _).
Notation "x `&^l` y" := (meetlexi x y) : order_scope.
Notation "x `|^l` y" := (joinlexi x y) : order_scope.
(* The following Local Notations are here to define the \join^l_ and \meet^l_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (lexi_display _ _) _).
Local Notation "\top" := (@top (lexi_display _ _) _).
Local Notation meet := (@meet (lexi_display _ _) _).
Local Notation join := (@join (lexi_display _ _) _).
Local Notation min := (@min (lexi_display _ _) _).
Local Notation max := (@max (lexi_display _ _) _).
Notation "\join^l_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^l_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^l_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^l_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^l_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^l_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^l_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^l_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^l_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^l_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^l_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^l_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^l_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^l_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^l_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^l_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^l_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^l_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^l_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End LexiSyntax.
Module Import SeqLexiSyntax.
Export SeqLexiSyntax.
Notation meetlexi := (@meet (seqlexi_display _) _).
Notation joinlexi := (@join (seqlexi_display _) _).
Notation "x `&^l` y" := (meetlexi x y) : order_scope.
Notation "x `|^l` y" := (joinlexi x y) : order_scope.
(* The following Local Notations are here to define the \join^l_ and \meet^l_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (lexi_display _ _) _).
Local Notation "\top" := (@top (lexi_display _ _) _).
Local Notation meet := (@meet (lexi_display _ _) _).
Local Notation join := (@join (lexi_display _ _) _).
Local Notation min := (@min (lexi_display _ _) _).
Local Notation max := (@max (lexi_display _ _) _).
Notation "\join^l_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^l_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^l_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^l_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^l_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^l_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^l_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^l_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^l_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^l_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^l_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^l_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^l_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^l_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^l_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^l_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^l_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^l_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^l_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End SeqLexiSyntax.
(************************************************)
(* We declare an alias of the cartesian product *)
(* which has canonical product order. *)
(************************************************)
Module ProdOrder.
Export ProdOrder.
Local Open Scope type_scope. (* FIXME *)
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Fact anti : antisymmetric (@le disp1 disp2 disp2 T1 T2).
Proof.
case=> [? ?] [? ?].
by rewrite andbAC andbA andbAC -andbA => /= /andP [] /le_anti -> /le_anti ->.
Qed.
End POrder.
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := POrder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := POrder.on T2'.
#[export]
HB.instance Definition _ :=
Preorder_isDuallyPOrder.Build disp3 (T1 * T2)
(@anti _ _ T1' T2') (@anti _ _ T1^d T2^d).
Lemma ltEprod x y : (x < y) = [&& x != y, x.1 <= y.1 & x.2 <= y.2].
Proof. by rewrite lt_neqAle. Qed.
Lemma lt_pair (x1 y1 : T1) (x2 y2 : T2) : (x1, x2) < (y1, y2) :> T1 * T2 =
[&& (x1 != y1) || (x2 != y2), x1 <= y1 & x2 <= y2].
Proof. by rewrite ltEprod negb_and. Qed.
End POrder.
Section MeetSemilattice.
Context (disp1 disp2 : disp_t).
Context (T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let meet x y := (x.1 `&` y.1, x.2 `&` y.2).
Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z).
Proof. by rewrite leEprod !lexI andbACA. Qed.
End MeetSemilattice.
Section MeetSemilattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := MeetSemilattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := MeetSemilattice.on T2'.
Definition meet x y := (x.1 `&` y.1, x.2 `&` y.2).
#[export]
HB.instance Definition _ :=
@POrder_isMeetSemilattice.Build disp3 (T1 * T2) meet (@lexI _ _ T1' T2').
Lemma meetEprod x y : x `&` y = (x.1 `&` y.1, x.2 `&` y.2). Proof. by []. Qed.
End MeetSemilattice.
Section JoinSemilattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : joinSemilatticeType disp1) (T2 : joinSemilatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Definition join x y := (x.1 `|` y.1, x.2 `|` y.2).
#[export]
HB.instance Definition _ :=
@POrder_isJoinSemilattice.Build disp3 (T1 * T2) join
(fun x y z => @lexI _ _ T1^d T2^d z x y).
Lemma joinEprod x y : x `|` y = (x.1 `|` y.1, x.2 `|` y.2). Proof. by []. Qed.
End JoinSemilattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bPOrderType disp1) (T2 : bPOrderType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tPOrderType disp1) (T2 : tPOrderType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbPOrderType disp1) (T2 : tbPOrderType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bMeetSemilatticeType disp1) (T2 : bMeetSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tMeetSemilatticeType disp1) (T2 : tMeetSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbMeetSemilatticeType disp1) (T2 : tbMeetSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bJoinSemilatticeType disp1) (T2 : bJoinSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tJoinSemilatticeType disp1) (T2 : tJoinSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbJoinSemilatticeType disp1) (T2 : tbJoinSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : latticeType disp1) (T2 : latticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bLatticeType disp1) (T2 : bLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tLatticeType disp1) (T2 : tLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbLatticeType disp1) (T2 : tbLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
(* /FIXME *)
Section DistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Fact meetUl : @left_distributive (T1 * T2) _ Order.meet Order.join.
Proof. by move=> ? ? ?; rewrite meetEprod !meetUl. Qed.
End DistrLattice.
Section DistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Let T1' : Type := T1.
HB.instance Definition _ := DistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := DistrLattice.on T2'.
#[export]
HB.instance Definition _ := Lattice_isDistributive.Build disp3 (T1 * T2)
(@meetUl _ _ T1' T2') (@meetUl _ _ T1^d T2^d).
End DistrLattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bDistrLatticeType disp1) (T2 : bDistrLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tDistrLatticeType disp1) (T2 : tDistrLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbDistrLatticeType disp1) (T2 : tbDistrLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
(* /FIXME *)
Section CDistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x y z : T1 * T2).
Let rcompl x y z := (rcompl x.1 y.1 z.1, rcompl x.2 y.2 z.2).
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by rewrite !(meetEprod, joinEprod) !rcomplPmeet. Qed.
End CDistrLattice.
Section CDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y z : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := CDistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := CDistrLattice.on T2'.
Definition rcompl x y z := (rcompl x.1 y.1 z.1, rcompl x.2 y.2 z.2).
#[export]
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build disp3 (T1 * T2)
rcompl (@rcomplPmeet _ _ T1' T2')
(fun x y => @rcomplPmeet _ _ T1^d T2^d y x).
Lemma rcomplEprod x y z :
rcompl x y z = (Order.rcompl x.1 y.1 z.1, Order.rcompl x.2 y.2 z.2).
Proof. by []. Qed.
End CDistrLattice.
Section CBDistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let diff x y := (diff x.1 y.1, diff x.2 y.2).
Fact diffErcompl x y : diff x y = rcompl \bot x y.
Proof. by rewrite /diff !diffErcompl. Qed.
End CBDistrLattice.
Section CBDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := CBDistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := CBDistrLattice.on T2'.
Definition diff x y := (diff x.1 y.1, diff x.2 y.2).
#[export]
HB.instance Definition _ :=
@CDistrLattice_hasSectionalComplement.Build disp3 (T1 * T2)
diff (@diffErcompl _ _ T1' T2').
Lemma diffEprod x y : x `\` y = (x.1 `\` y.1, x.2 `\` y.2). Proof. by []. Qed.
End CBDistrLattice.
Section CTDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : ctDistrLatticeType disp1) (T2 : ctDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Definition codiff x y := (codiff x.1 y.1, codiff x.2 y.2).
#[export]
HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build disp3 (T1 * T2)
codiff (@diffErcompl _ _ T1^d T2^d).
Lemma codiffEprod x y :
codiff x y = (Order.codiff x.1 y.1, Order.codiff x.2 y.2).
Proof. by []. Qed.
End CTDistrLattice.
Section CTBDistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x : T1 * T2).
Let compl x := (~` x.1, ~` x.2).
Fact complEdiff x : compl x = (\top : T1 * T2) `\` x.
Proof. by rewrite /compl !complEdiff. Qed.
End CTBDistrLattice.
Section CTBDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := CTBDistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := CTBDistrLattice.on T2'.
Definition compl x := (~` x.1, ~` x.2).
#[export]
HB.instance Definition _ := @CDistrLattice_hasComplement.Build _ (T1 * T2) compl
(@complEdiff _ _ T1' T2') (@complEdiff _ _ T1^d T2^d).
Lemma complEprod x : ~` x = (~` x.1, ~` x.2). Proof. by []. Qed.
End CTBDistrLattice.
(* FIXME: use HB.saturate *)
Section FinOrder.
Context (disp1 disp2 disp3 : disp_t).
#[export]
HB.instance Definition _ (T1 : finPOrderType disp1)
(T2 : finPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBPOrderType disp1)
(T2 : finBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTPOrderType disp1)
(T2 : finTPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBPOrderType disp1)
(T2 : finTBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finMeetSemilatticeType disp1)
(T2 : finMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBMeetSemilatticeType disp1)
(T2 : finBMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finJoinSemilatticeType disp1)
(T2 : finJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTJoinSemilatticeType disp1)
(T2 : finTJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finLatticeType disp1)
(T2 : finLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBLatticeType disp1)
(T2 : finTBLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finDistrLatticeType disp1)
(T2 : finDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBDistrLatticeType disp1)
(T2 : finTBDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finCDistrLatticeType disp1)
(T2 : finCDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finCTBDistrLatticeType disp1)
(T2 : finCTBDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
End FinOrder.
(* /FIXME *)
Module Exports.
HB.reexport ProdOrder.
Definition ltEprod := @ltEprod.
Definition lt_pair := @lt_pair.
Definition meetEprod := @meetEprod.
Definition joinEprod := @joinEprod.
Definition rcomplEprod := @rcomplEprod.
Definition diffEprod := @diffEprod.
Definition codiffEprod := @codiffEprod.
Definition complEprod := @complEprod.
End Exports.
End ProdOrder.
HB.export ProdOrder.Exports.
Module DefaultProdOrder.
Export DefaultProdOrder.
Section DefaultProdOrder.
Context {disp1 disp2 : disp_t}.
Let prod T1 T2 := T1 *prod[prod_display disp1 disp2] T2.
(* FIXME: Scopes of arguments are broken in several places. *)
(* FIXME: Declaring a bunch of copies is still a bit painful. *)
HB.instance Definition _ (T1 : porderType disp1) (T2 : porderType disp2) :=
POrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : bPOrderType disp1) (T2 : bPOrderType disp2) :=
BPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tPOrderType disp1) (T2 : tPOrderType disp2) :=
TPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tbPOrderType disp1) (T2 : tbPOrderType disp2) :=
TBPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2) :=
MeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : bMeetSemilatticeType disp1) (T2 : bMeetSemilatticeType disp2) :=
BMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tMeetSemilatticeType disp1) (T2 : tMeetSemilatticeType disp2) :=
TMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbMeetSemilatticeType disp1) (T2 : tbMeetSemilatticeType disp2) :=
TBMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : joinSemilatticeType disp1) (T2 : joinSemilatticeType disp2) :=
JoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : bJoinSemilatticeType disp1) (T2 : bJoinSemilatticeType disp2) :=
BJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tJoinSemilatticeType disp1) (T2 : tJoinSemilatticeType disp2) :=
TJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbJoinSemilatticeType disp1) (T2 : tbJoinSemilatticeType disp2) :=
TBJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : latticeType disp1) (T2 : latticeType disp2) :=
Lattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : bLatticeType disp1) (T2 : bLatticeType disp2) :=
BLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tLatticeType disp1) (T2 : tLatticeType disp2) :=
TLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbLatticeType disp1) (T2 : tbLatticeType disp2) :=
TBLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2) :=
DistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : bDistrLatticeType disp1) (T2 : bDistrLatticeType disp2) :=
BDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tDistrLatticeType disp1) (T2 : tDistrLatticeType disp2) :=
TDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbDistrLatticeType disp1) (T2 : tbDistrLatticeType disp2) :=
TBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2) :=
CDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2) :=
CBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : ctDistrLatticeType disp1) (T2 : ctDistrLatticeType disp2) :=
CTDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2) :=
CTBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finPOrderType disp1) (T2 : finPOrderType disp2) :=
FinPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) :=
FinBPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) :=
FinTPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) :=
FinTBPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finMeetSemilatticeType disp1) (T2 : finMeetSemilatticeType disp2) :=
FinMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finBMeetSemilatticeType disp1) (T2 : finBMeetSemilatticeType disp2) :=
FinBMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finJoinSemilatticeType disp1) (T2 : finJoinSemilatticeType disp2) :=
FinJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTJoinSemilatticeType disp1) (T2 : finTJoinSemilatticeType disp2) :=
FinTJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finLatticeType disp1) (T2 : finLatticeType disp2) :=
FinLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTBLatticeType disp1) (T2 : finTBLatticeType disp2) :=
FinTBLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finDistrLatticeType disp1) (T2 : finDistrLatticeType disp2) :=
FinDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTBDistrLatticeType disp1) (T2 : finTBDistrLatticeType disp2) :=
FinTBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finCDistrLatticeType disp1) (T2 : finCDistrLatticeType disp2) :=
FinCDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finCTBDistrLatticeType disp1) (T2 : finCTBDistrLatticeType disp2) :=
FinCTBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
(* /FIXME *)
End DefaultProdOrder.
End DefaultProdOrder.
(*********************************************************)
(* We declare lexicographic ordering on dependent pairs. *)
(*********************************************************)
Module SigmaOrder.
Section SigmaOrder.
Context {disp1 disp2 : disp_t}.
Section POrder.
Context (T : porderType disp1) (T' : T -> porderType disp2).
Implicit Types (x y : {t : T & T' t}).
Definition le x y := (tag x <= tag y) &&
((tag x >= tag y) ==> (tagged x <= tagged_as x y)).
Definition lt x y := (tag x <= tag y) &&
((tag x >= tag y) ==> (tagged x < tagged_as x y)).
Fact refl : reflexive le.
Proof. by move=> [x x']; rewrite /le tagged_asE/= !lexx. Qed.
Fact anti : antisymmetric le.
Proof.
rewrite /le => -[x x'] [y y']/=; case: comparableP => //= eq_xy.
by case: _ / eq_xy in y' *; rewrite !tagged_asE => /le_anti ->.
Qed.
Fact trans : transitive le.
Proof.
move=> [y y'] [x x'] [z z'] /andP[/= lexy lexy'] /andP[/= leyz leyz'].
rewrite /= /le (le_trans lexy) //=; apply/implyP => lezx.
elim: _ / (@le_anti _ _ x y) in y' z' lexy' leyz' *; last first.
by rewrite lexy (le_trans leyz).
elim: _ / (@le_anti _ _ x z) in z' leyz' *; last by rewrite (le_trans lexy).
by rewrite lexx !tagged_asE/= in lexy' leyz' *; rewrite (le_trans lexy').
Qed.
Fact lt_le_def x y : lt x y = le x y && ~~ le y x.
Proof.
rewrite /lt /le; case: x y => [x x'] [y y']//=.
case: (comparableP x y) => //= xy.
by subst y; rewrite !tagged_asE lt_le_def.
Qed.
#[export]
HB.instance Definition _ :=
isPreorder.Build disp2 {t : T & T' t} lt_le_def refl trans.
#[export]
HB.instance Definition _ :=
Preorder_isPOrder.Build disp2 {t : T & T' t} anti.
Lemma leEsig x y : x <= y =
(tag x <= tag y) && ((tag x >= tag y) ==> (tagged x <= tagged_as x y)).
Proof. by []. Qed.
Lemma ltEsig x y : x < y =
(tag x <= tag y) && ((tag x >= tag y) ==> (tagged x < tagged_as x y)).
Proof. by []. Qed.
Lemma le_Taggedl x (u : T' (tag x)) : (Tagged T' u <= x) = (u <= tagged x).
Proof. by case: x => [t v]/= in u *; rewrite leEsig/= lexx/= tagged_asE. Qed.
Lemma le_Taggedr x (u : T' (tag x)) : (x <= Tagged T' u) = (tagged x <= u).
Proof. by case: x => [t v]/= in u *; rewrite leEsig/= lexx/= tagged_asE. Qed.
Lemma lt_Taggedl x (u : T' (tag x)) : (Tagged T' u < x) = (u < tagged x).
Proof. by case: x => [t v]/= in u *; rewrite ltEsig/= lexx/= tagged_asE. Qed.
Lemma lt_Taggedr x (u : T' (tag x)) : (x < Tagged T' u) = (tagged x < u).
Proof. by case: x => [t v]/= in u *; rewrite ltEsig/= lexx/= tagged_asE. Qed.
End POrder.
Section BPOrder.
Context (T : bPOrderType disp1) (T' : T -> bPOrderType disp2).
Fact le0x (x : {t : T & T' t}) : Tagged T' (\bot : T' \bot) <= x.
Proof. by rewrite leEsig /= !le0x implybT. Qed.
#[export]
HB.instance Definition _ := hasBottom.Build _ {t : T & T' t} le0x.
Lemma botEsig : \bot = Tagged T' (\bot : T' \bot). Proof. by []. Qed.
End BPOrder.
Section TPOrder.
Context (T : tPOrderType disp1) (T' : T -> tPOrderType disp2).
Fact lex1 (x : {t : T & T' t}) : x <= Tagged T' (\top : T' \top).
Proof.
rewrite leEsig /=; case: comparableP (lex1 (tag x)) => //=.
by case: x => //= x px x0; rewrite x0 in px *; rewrite tagged_asE lex1.
Qed.
#[export]
HB.instance Definition _ := hasTop.Build _ {t : T & T' t} lex1.
Lemma topEsig : \top = Tagged T' (\top : T' \top). Proof. by []. Qed.
End TPOrder.
Section Total.
Context (T : orderType disp1) (T' : T -> orderType disp2).
Implicit Types (x y : {t : T & T' t}).
Fact total : total (<=%O : rel {t : T & T' t}).
Proof.
move=> x y; rewrite !leEsig; case: (ltgtP (tag x) (tag y)) => //=.
case: x y => [x x'] [y y']/= eqxy; elim: _ /eqxy in y' *.
by rewrite !tagged_asE le_total.
Qed.
#[export]
HB.instance Definition _ := POrder_isTotal.Build _ {t : T & T' t} total.
End Total.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (T : bOrderType disp1)
(T' : T -> bOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : tOrderType disp1)
(T' : T -> tOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : tbOrderType disp1)
(T' : T -> tbOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finPOrderType disp1)
(T' : T -> finPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finBPOrderType disp1)
(T' : T -> finBPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finTPOrderType disp1)
(T' : T -> finTPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finTBPOrderType disp1)
(T' : T -> finTBPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finOrderType disp1)
(T' : T -> finOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finTBOrderType disp1)
(T' : T -> finTBOrderType disp2) := POrder.on {t : T & T' t}.
(* /FIXME *)
End SigmaOrder.
Module Exports.
HB.reexport SigmaOrder.
Definition leEsig := @leEsig.
Definition ltEsig := @ltEsig.
Definition le_Taggedl := @le_Taggedl.
Definition lt_Taggedl := @lt_Taggedl.
Definition le_Taggedr := @le_Taggedr.
Definition lt_Taggedr := @lt_Taggedr.
Definition topEsig := @topEsig.
Definition botEsig := @botEsig.
End Exports.
End SigmaOrder.
HB.export SigmaOrder.Exports.
(*************************************************)
(* We declare an alias of the cartesian product, *)
(* which has canonical lexicographic order. *)
(*************************************************)
Module ProdLexiOrder.
Export ProdLexiOrder.
Local Open Scope type_scope. (* FIXME *)
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Fact anti : antisymmetric (@le disp1 disp2 disp2 T1 T2).
Proof.
by rewrite /le => -[x x'] [y y'] /=; case: comparableP => //= -> /le_anti->.
Qed.
End POrder.
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := POrder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := POrder.on T2'.
#[export]
HB.instance Definition _ :=
Preorder_isDuallyPOrder.Build disp3 (T1 * T2)
(@anti _ _ T1' T2') (@anti _ _ T1^d T2^d).
End POrder.
Section Total.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : orderType disp1) (T2 : orderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Fact total : total (<=%O : rel (T1 * T2)).
Proof.
by move=> x y; rewrite !leEprodlexi; case: ltgtP => //= _; exact: le_total.
Qed.
(* FIXME: In order to dualize this instance, we have to dualize the *)
(* [POrder_isTotal] factory. However, [min] and max are not definitional dual *)
(* (while [min x y] and [max y x] are). *)
#[export]
HB.instance Definition _ := POrder_isTotal.Build _ (T1 * T2) total.
End Total.
(* FIXME: use HB.saturate *)
Section ProdLexiOrder.
Context (disp1 disp2 disp3 : disp_t).
#[export]
HB.instance Definition _ (T1 : finPOrderType disp1)
(T2 : finPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBPOrderType disp1)
(T2 : finBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTPOrderType disp1)
(T2 : finTPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBPOrderType disp1)
(T2 : finTBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finOrderType disp1)
(T2 : finOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBOrderType disp1)
(T2 : finTBOrderType disp2) := POrder.on (type disp3 T1 T2).
End ProdLexiOrder.
(* /FIXME *)
Module Exports.
HB.reexport ProdLexiOrder.
End Exports.
End ProdLexiOrder.
HB.export ProdLexiOrder.Exports.
Module DefaultProdLexiOrder.
Export DefaultProdLexiOrder.
Section DefaultProdLexiOrder.
Context {disp1 disp2 : disp_t}.
Let prodlexi T1 T2 := T1 *lexi[lexi_display disp1 disp2] T2.
(* FIXME: Scopes of arguments are broken in several places. *)
(* FIXME: Declaring a bunch of copies is still a bit painful. *)
HB.instance Definition _ (T1 : porderType disp1) (T2 : porderType disp2) :=
POrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _ (T1 : orderType disp1) (T2 : orderType disp2) :=
Total.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finPOrderType disp1) (T2 : finPOrderType disp2) :=
FinPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) :=
FinBPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) :=
FinTPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) :=
FinTBPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finOrderType disp1) (T2 : finOrderType disp2) :=
FinTotal.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTBOrderType disp1) (T2 : finTBOrderType disp2) :=
FinTBTotal.copy (T1 * T2)%type (prodlexi T1 T2).
(* /FIXME *)
End DefaultProdLexiOrder.
End DefaultProdLexiOrder.
(*****************************************)
(* We declare an alias of the sequences, *)
(* which has canonical product order. *)
(*****************************************)
Module SeqProdOrder.
Export SeqProdOrder.
Section SeqProdOrder.
Context {disp disp' : disp_t}.
Local Notation seq := (type disp').
Section POrder.
Variable T : porderType disp.
Implicit Types s : seq T.
Fact anti : antisymmetric (@le disp disp' T).
Proof.
by elim=> [|x s ihs] [|y s'] //=; rewrite andbACA => /andP[/le_anti-> /ihs->].
Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build disp' (seq T) anti.
End POrder.
Section MeetSemilattice.
Context (T : meetSemilatticeType disp).
Implicit Types (s : seq T).
Fixpoint meet s1 s2 :=
match s1, s2 with
| x1 :: s1', x2 :: s2' => (x1 `&` x2) :: meet s1' s2'
| _, _ => [::]
end.
Fact lexI s1 s2 s3 : (s1 <= meet s2 s3) = (s1 <= s2) && (s1 <= s3).
Proof.
elim: s1 s2 s3 => [|x s1 IHs1] [|y s2] [|z s3] //=; first by rewrite andbF.
by rewrite leEseq lexI IHs1 andbACA.
Qed.
#[export]
HB.instance Definition _ := @POrder_isMeetSemilattice.Build _ (seq T) meet lexI.
Lemma meetEseq s1 s2 : s1 `&` s2 = [seq x.1 `&` x.2 | x <- zip s1 s2].
Proof. by elim: s1 s2 => [|x s1 ihs1] [|y s2]//=; rewrite -ihs1. Qed.
Lemma meet_cons x1 s1 x2 s2 :
(x1 :: s1 : seq T) `&` (x2 :: s2) = (x1 `&` x2) :: s1 `&` s2.
Proof. by []. Qed.
End MeetSemilattice.
Section JoinSemilattice.
Context (T : joinSemilatticeType disp).
Implicit Types (s : seq T).
Fixpoint join s1 s2 :=
match s1, s2 with
| [::], _ => s2 | _, [::] => s1
| x1 :: s1', x2 :: s2' => (x1 `|` x2) :: join s1' s2'
end.
Fact leUx s1 s2 s3 : (join s1 s2 <= s3) = (s1 <= s3) && (s2 <= s3).
Proof.
elim : s1 s2 s3 => [|x s1 IHs1] [|y s2] [|z s3] //=; first by rewrite andbT.
by rewrite leEseq leUx IHs1 andbACA.
Qed.
#[export]
HB.instance Definition _ := @POrder_isJoinSemilattice.Build _ (seq T) join leUx.
Lemma joinEseq s1 s2 : s1 `|` s2 =
match s1, s2 with
| [::], _ => s2 | _, [::] => s1
| x1 :: s1', x2 :: s2' => (x1 `|` x2) :: ((s1' : seq _) `|` s2')
end.
Proof. by case: s1. Qed.
Lemma join_cons x1 s1 x2 s2 :
(x1 :: s1 : seq T) `|` (x2 :: s2) = (x1 `|` x2) :: s1 `|` s2.
Proof. by []. Qed.
End JoinSemilattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (T : latticeType disp) := POrder.on (seq T).
(* /FIXME *)
Section DistrLattice.
Context (T : distrLatticeType disp).
Fact meetUl : left_distributive (@meet T) (@join T).
Proof. by elim=> [|? ? ih] [|? ?] [|? ?] //=; rewrite meetUl ih. Qed.
#[export]
HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build _ (seq T) meetUl.
End DistrLattice.
End SeqProdOrder.
Module Exports.
HB.reexport SeqProdOrder.
Definition meetEseq := @meetEseq.
Definition meet_cons := @meet_cons.
Definition joinEseq := @joinEseq.
End Exports.
End SeqProdOrder.
HB.export SeqProdOrder.Exports.
Module DefaultSeqProdOrder.
Export DefaultSeqProdOrder.
Section DefaultSeqProdOrder.
Context {disp : disp_t}.
HB.instance Definition _ (T : porderType disp) :=
POrder.copy (seq T) (seqprod T).
HB.instance Definition _ (T : meetSemilatticeType disp) :=
BMeetSemilattice.copy (seq T) (seqprod T).
HB.instance Definition _ (T : joinSemilatticeType disp) :=
BJoinSemilattice.copy (seq T) (seqprod T).
HB.instance Definition _ (T : latticeType disp) :=
BLattice.copy (seq T) (seqprod T).
HB.instance Definition _ (T : distrLatticeType disp) :=
BDistrLattice.copy (seq T) (seqprod T).
End DefaultSeqProdOrder.
End DefaultSeqProdOrder.
(*********************************************)
(* We declare an alias of the sequences, *)
(* which has canonical lexicographic order. *)
(*********************************************)
Module SeqLexiOrder.
Export SeqLexiOrder.
Section SeqLexiOrder.
Context {disp disp' : disp_t}.
Local Notation seq := (type disp').
Section POrder.
Variable T : porderType disp.
Implicit Types s : seq T.
Fact anti: antisymmetric (@le disp disp' T).
Proof.
move=> x y /andP []; elim: x y => [|x sx ih] [|y sy] //=.
by case: comparableP => //= -> lesxsy /(ih _ lesxsy) ->.
Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build disp' (seq T) anti.
Lemma neqhead_lexiE (x y : T) s1 s2 : x != y ->
(x :: s1 <= y :: s2 :> seq _) = (x < y).
Proof. by rewrite lexi_cons; case: comparableP. Qed.
Lemma neqhead_ltxiE (x y : T) s1 s2 : x != y ->
(x :: s1 < y :: s2 :> seq _) = (x < y).
Proof. by rewrite ltxi_cons; case: (comparableP x y). Qed.
End POrder.
Section Total.
Context (T : orderType disp).
Fact total : total (<=%O : rel (seq T)).
Proof.
by elim=> [|x1 s1 ihs1] [|x2 s2]//=; rewrite !lexi_cons; case: ltgtP => /=.
Qed.
#[export]
HB.instance Definition _ := POrder_isTotal.Build _ (seq T) total.
End Total.
End SeqLexiOrder.
Module Exports.
HB.reexport SeqLexiOrder.
Definition neqhead_lexiE := @neqhead_lexiE.
Definition neqhead_ltxiE := @neqhead_ltxiE.
End Exports.
End SeqLexiOrder.
HB.export SeqLexiOrder.Exports.
Module DefaultSeqLexiOrder.
Export DefaultSeqLexiOrder.
Section DefaultSeqLexiOrder.
Context {disp : disp_t}.
HB.instance Definition _ (T : porderType disp) :=
POrder.copy (seq T) (seqlexi T).
HB.instance Definition _ (T : orderType disp) :=
BTotal.copy (seq T) (seqlexi T).
End DefaultSeqLexiOrder.
End DefaultSeqLexiOrder.
(***************************************)
(* We declare an alias of the tuples, *)
(* which has canonical product order. *)
(***************************************)
Module TupleProdOrder.
Export TupleProdOrder.
Import DefaultSeqProdOrder.
Section TupleProdOrder.
Context {disp disp' : disp_t}.
Local Notation "n .-tuple" := (type disp' n) : type_scope.
Section POrder.
Implicit Types (T : porderType disp).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ n T := SubChoice.on (n.-tuple T).
#[export]
HB.instance Definition _ n T :=
[SubChoice_isSubPOrder of n.-tuple T by <: with disp'].
End POrder.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bPOrderType disp) :=
POrder.on (n.-tuple T).
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : tPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbPOrderType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
Section MeetSemilattice.
Context (n : nat) (T : meetSemilatticeType disp).
Implicit Types (t : n.-tuple T).
Definition meet t1 t2 : n.-tuple T := [tuple tnth t1 i `&` tnth t2 i | i < n].
Fact lexI t1 t2 t3 : (t1 <= meet t2 t3) = (t1 <= t2) && (t1 <= t3).
Proof.
rewrite !leEtprod; apply/forallP/andP => [H|[Ht12 Ht13] i]; last first.
by rewrite tnth_mktuple lexI (forallP Ht12) (forallP Ht13).
by split; apply/forallP => i; move: (H i); rewrite tnth_mktuple lexI => /andP[].
Qed.
#[export]
HB.instance Definition _ :=
@POrder_isMeetSemilattice.Build _ (n.-tuple T) meet lexI.
Lemma tnth_meet t1 t2 i : tnth (t1 `&` t2) i = tnth t1 i `&` tnth t2 i.
Proof. exact: tnth_mktuple. Qed.
Lemma meetEtprod t1 t2 : t1 `&` t2 = [tuple tnth t1 i `&` tnth t2 i | i < n].
Proof. by []. Qed.
End MeetSemilattice.
Section JoinSemilattice.
Context (n : nat) (T : joinSemilatticeType disp).
Implicit Types (t : n.-tuple T).
Definition join t1 t2 : n.-tuple T := [tuple tnth t1 i `|` tnth t2 i | i < n].
Fact leUx t1 t2 t3 : (join t1 t2 <= t3) = (t1 <= t3) && (t2 <= t3).
Proof.
rewrite !leEtprod; apply/forallP/andP => [H|[Ht13 Ht23] i]; last first.
by rewrite tnth_mktuple leUx (forallP Ht13) (forallP Ht23).
by split; apply/forallP => i; move: (H i); rewrite tnth_mktuple leUx => /andP[].
Qed.
#[export]
HB.instance Definition _ :=
@POrder_isJoinSemilattice.Build _ (n.-tuple T) join leUx.
Lemma tnth_join t1 t2 i : tnth (t1 `|` t2) i = tnth t1 i `|` tnth t2 i.
Proof. exact: tnth_mktuple. Qed.
Lemma joinEtprod t1 t2 : t1 `|` t2 = [tuple tnth t1 i `|` tnth t2 i | i < n].
Proof. by []. Qed.
End JoinSemilattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : bJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : latticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : bLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbLatticeType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
Section DistrLattice.
Context (n : nat) (T : distrLatticeType disp).
Implicit Types (t : n.-tuple T).
Fact meetUl : left_distributive (@meet n T) (@join n T).
Proof.
by move=> t1 t2 t3; apply: eq_from_tnth => i; rewrite !tnth_mktuple meetUl.
Qed.
#[export]
HB.instance Definition _ :=
Lattice_Meet_isDistrLattice.Build _ (n.-tuple T) meetUl.
End DistrLattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bDistrLatticeType disp) :=
DistrLattice.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tDistrLatticeType disp) :=
DistrLattice.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbDistrLatticeType disp) :=
DistrLattice.on (n.-tuple T).
(* /FIXME *)
Section CDistrLattice.
Context (n : nat) (T : cDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition rcompl t1 t2 t3 :=
[tuple rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i) | i < n].
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple rcomplPmeet. Qed.
Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple rcomplPjoin. Qed.
#[export]
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build _ (n.-tuple T)
rcompl rcomplPmeet rcomplPjoin.
Lemma tnth_rcompl t1 t2 t3 i :
tnth (Order.rcompl t1 t2 t3) i =
Order.rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i).
Proof. exact: tnth_mktuple. Qed.
Lemma rcomplEtprod t1 t2 t3 :
Order.rcompl t1 t2 t3 =
[tuple Order.rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i) | i < n].
Proof. by []. Qed.
End CDistrLattice.
Section CBDistrLattice.
Context (n : nat) (T : cbDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition diff t1 t2 : n.-tuple T := [tuple tnth t1 i `\` tnth t2 i | i < n].
Fact diffErcompl t1 t2 : diff t1 t2 = rcompl \bot t1 t2.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple diffErcompl. Qed.
#[export] HB.instance Definition _ :=
@CDistrLattice_hasSectionalComplement.Build _ (n.-tuple T) diff diffErcompl.
Lemma tnth_diff t1 t2 i : tnth (diff t1 t2) i = tnth t1 i `\` tnth t2 i.
Proof. exact: tnth_mktuple. Qed.
Lemma diffEtprod t1 t2 : t1 `\` t2 = [tuple tnth t1 i `\` tnth t2 i | i < n].
Proof. by []. Qed.
End CBDistrLattice.
Section CTDistrLattice.
Context (n : nat) (T : ctDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition codiff t1 t2 : n.-tuple T :=
[tuple Order.codiff (tnth t1 i) (tnth t2 i) | i < n].
Fact codiffErcompl t1 t2 : codiff t1 t2 = rcompl t1 \top t2.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple codiffErcompl. Qed.
#[export] HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build _ (n.-tuple T)
codiff codiffErcompl.
Lemma tnth_codiff t1 t2 i :
tnth (Order.codiff t1 t2) i = Order.codiff (tnth t1 i) (tnth t2 i).
Proof. exact: tnth_mktuple. Qed.
Lemma codiffEtprod t1 t2 :
Order.codiff t1 t2 = [tuple Order.codiff (tnth t1 i) (tnth t2 i) | i < n].
Proof. by []. Qed.
End CTDistrLattice.
Section CTBDistrLattice.
Context (n : nat) (T : ctbDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition compl t : n.-tuple T := map_tuple compl t.
Fact complEdiff t : compl t = (\top : n.-tuple T) `\` t.
Proof.
by apply: eq_from_tnth => i; rewrite tnth_map !tnth_mktuple complEdiff.
Qed.
Fact complEcodiff t : compl t = codiff (\bot : n.-tuple T) t.
Proof.
by apply: eq_from_tnth => i; rewrite tnth_map !tnth_mktuple complEcodiff.
Qed.
#[export] HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build _ (n.-tuple T)
compl complEdiff complEcodiff.
Lemma tnth_compl t i : tnth (~` t) i = ~` tnth t i.
Proof. by rewrite tnth_map. Qed.
Lemma complEtprod t : ~` t = map_tuple Order.compl t.
Proof. by []. Qed.
End CTBDistrLattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : finPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finBMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finDistrLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBDistrLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finCDistrLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finCTBDistrLatticeType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
End TupleProdOrder.
Module Exports.
HB.reexport TupleProdOrder.
Definition tnth_meet := @tnth_meet.
Definition meetEtprod := @meetEtprod.
Definition tnth_join := @tnth_join.
Definition joinEtprod := @joinEtprod.
Definition tnth_rcompl := @tnth_rcompl.
Definition rcomplEtprod := @rcomplEtprod.
Definition tnth_diff := @tnth_diff.
Definition diffEtprod := @diffEtprod.
Definition tnth_codiff := @tnth_codiff.
Definition codiffEtprod := @codiffEtprod.
Definition tnth_compl := @tnth_compl.
Definition complEtprod := @complEtprod.
End Exports.
End TupleProdOrder.
HB.export TupleProdOrder.Exports.
Module DefaultTupleProdOrder.
Export DefaultTupleProdOrder.
Section DefaultTupleProdOrder.
Context {disp : disp_t}.
HB.instance Definition _ n (T : porderType disp) :=
POrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bPOrderType disp) :=
BPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tPOrderType disp) :=
TPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbPOrderType disp) :=
TBPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : meetSemilatticeType disp) :=
MeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bMeetSemilatticeType disp) :=
BMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tMeetSemilatticeType disp) :=
TMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbMeetSemilatticeType disp) :=
TBMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : joinSemilatticeType disp) :=
JoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bJoinSemilatticeType disp) :=
BJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tJoinSemilatticeType disp) :=
TJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbJoinSemilatticeType disp) :=
TBJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : latticeType disp) :=
Lattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bLatticeType disp) :=
BLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tLatticeType disp) :=
TLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbLatticeType disp) :=
TBLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : distrLatticeType disp) :=
DistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bDistrLatticeType disp) :=
BDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tDistrLatticeType disp) :=
TDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbDistrLatticeType disp) :=
TBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : cDistrLatticeType disp) :=
CDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : cbDistrLatticeType disp) :=
CBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : ctDistrLatticeType disp) :=
CTDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : ctbDistrLatticeType disp) :=
CTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finPOrderType disp) :=
FinPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finBPOrderType disp) :=
FinBPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTPOrderType disp) :=
FinTPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTBPOrderType disp) :=
FinTBPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finMeetSemilatticeType disp) :=
FinMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finBMeetSemilatticeType disp) :=
FinBMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finJoinSemilatticeType disp) :=
FinJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTJoinSemilatticeType disp) :=
FinTJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finLatticeType disp) :=
FinLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTBLatticeType disp) :=
FinTBLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finDistrLatticeType disp) :=
FinDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTBDistrLatticeType disp) :=
FinTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finCDistrLatticeType disp) :=
FinCDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finCTBDistrLatticeType disp) :=
FinCTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
End DefaultTupleProdOrder.
End DefaultTupleProdOrder.
(*********************************************)
(* We declare an alias of the tuples, *)
(* which has canonical lexicographic order. *)
(*********************************************)
Module TupleLexiOrder.
Export TupleLexiOrder.
Section TupleLexiOrder.
Import DefaultSeqLexiOrder.
Context {disp disp' : disp_t}.
Local Notation "n .-tuple" := (type disp' n) : type_scope.
Section POrder.
Implicit Types (n : nat) (T : porderType disp).
#[export] HB.instance Definition _ n T :=
[SubChoice_isSubPOrder of n.-tuple T by <: with disp'].
Lemma lexi_tupleP n T (t1 t2 : n.-tuple T) :
reflect (exists k : 'I_n.+1, forall i : 'I_n, (i <= k)%N ->
tnth t1 i <= tnth t2 i ?= iff (i != k :> nat)) (t1 <= t2).
Proof.
elim: n => [|n IHn] in t1 t2 *.
by rewrite tuple0 [t2]tuple0/= lexx; constructor; exists ord0 => -[].
case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2].
rewrite [_ <= _]lexi_cons; apply: (iffP idP) => [|[k leif_xt12]].
case: comparableP => //= [ltx12 _|-> /IHn[k kP]].
exists ord0 => i; rewrite leqn0 => /eqP/(@ord_inj n.+1 i ord0)->.
by apply/leifP; rewrite !tnth0.
exists (lift ord0 k) => i; case: (unliftP ord0 i) => [j ->|-> _].
by rewrite !ltnS => /kP; rewrite !tnthS.
by apply/leifP; rewrite !tnth0 eqxx.
have /= := leif_xt12 ord0 isT; rewrite !tnth0 => leif_x12.
rewrite leif_x12/=; move: leif_x12 leif_xt12 => /leifP.
case: (unliftP ord0 k) => {k} [k-> /eqP<-{x2}|-> /lt_geF->//] leif_xt12.
rewrite lexx implyTb; apply/IHn; exists k => i le_ik.
by have := leif_xt12 (lift ord0 i) le_ik; rewrite !tnthS.
Qed.
Lemma ltxi_tupleP n T (t1 t2 : n.-tuple T) :
reflect (exists k : 'I_n, forall i : 'I_n, (i <= k)%N ->
tnth t1 i <= tnth t2 i ?= iff (i != k :> nat)) (t1 < t2).
Proof.
elim: n => [|n IHn] in t1 t2 *.
by rewrite tuple0 [t2]tuple0/= ltxx; constructor => - [] [].
case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2].
rewrite [_ < _]ltxi_cons; apply: (iffP idP) => [|[k leif_xt12]].
case: (comparableP x1 x2) => //= [ltx12 _|-> /IHn[k kP]].
exists ord0 => i; rewrite leqn0 => /eqP/(@ord_inj n.+1 i ord0)->.
by apply/leifP; rewrite !tnth0.
exists (lift ord0 k) => i; case: (unliftP ord0 i) => {i} [i ->|-> _].
by rewrite !ltnS => /kP; rewrite !tnthS.
by apply/leifP; rewrite !tnth0 eqxx.
have /= := leif_xt12 ord0 isT; rewrite !tnth0 => leif_x12.
rewrite leif_x12/=; move: leif_x12 leif_xt12 => /leifP.
case: (unliftP ord0 k) => {k} [k-> /eqP<-{x2}|-> /lt_geF->//] leif_xt12.
rewrite lexx implyTb; apply/IHn; exists k => i le_ik.
by have := leif_xt12 (lift ord0 i) le_ik; rewrite !tnthS.
Qed.
Lemma ltxi_tuplePlt n T (t1 t2 : n.-tuple T) : reflect
(exists2 k : 'I_n, forall i : 'I_n, (i < k)%N -> tnth t1 i = tnth t2 i
& tnth t1 k < tnth t2 k)
(t1 < t2).
Proof.
apply: (iffP (ltxi_tupleP _ _)) => [[k kP]|[k kP ltk12]].
exists k => [i i_lt|]; last by rewrite (lt_leif (kP _ _)) ?eqxx ?leqnn.
by have /eqTleif->// := kP i (ltnW i_lt); rewrite ltn_eqF.
by exists k => i; case: ltngtP => //= [/kP-> _|/ord_inj-> _]; apply/leifP.
Qed.
End POrder.
#[export] HB.instance Definition _ n (T : orderType disp) :=
[SubChoice_isSubOrder of n.-tuple T by <: with disp'].
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : bOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBOrderType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
End TupleLexiOrder.
Module Exports.
HB.reexport TupleLexiOrder.
Definition lexi_tupleP := @lexi_tupleP.
Arguments lexi_tupleP {disp disp' n T t1 t2}.
Definition ltxi_tupleP := @ltxi_tupleP.
Arguments ltxi_tupleP {disp disp' n T t1 t2}.
Definition ltxi_tuplePlt := @ltxi_tuplePlt.
Arguments ltxi_tuplePlt {disp disp' n T t1 t2}.
End Exports.
End TupleLexiOrder.
HB.export TupleLexiOrder.Exports.
Module DefaultTupleLexiOrder.
Export DefaultTupleLexiOrder.
Section DefaultTupleLexiOrder.
Context {disp : disp_t}.
HB.instance Definition _ n (T : porderType disp) :=
POrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : bPOrderType disp) :=
BPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tPOrderType disp) :=
TPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tbPOrderType disp) :=
TBPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : orderType disp) :=
Lattice.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : orderType disp) :=
DistrLattice.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : orderType disp) :=
Total.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : bOrderType disp) :=
BTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tOrderType disp) :=
TTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tbOrderType disp) :=
TBTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finPOrderType disp) :=
FinPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finBPOrderType disp) :=
FinBPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finTPOrderType disp) :=
FinTPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finTBPOrderType disp) :=
FinTBPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finOrderType disp) :=
FinTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finTBOrderType disp) :=
FinTBTotal.copy (n.-tuple T) (n.-tuplelexi T).
End DefaultTupleLexiOrder.
End DefaultTupleLexiOrder.
(*********************************************)
(* We declare an alias of the sets, *)
(* which is canonically ordered by inclusion *)
(*********************************************)
Module SetSubsetOrder.
Export SetSubsetOrder.
Section SetSubsetOrder.
Context {disp : disp_t} {T : finType}.
Local Notation "{ 'subset' T }" := (type disp T).
Implicit Type (A B C : type disp T).
Lemma setKUC B A : A :&: (A :|: B) = A.
Proof. by rewrite setUC setKU. Qed.
Lemma setKIC B A : A :|: (A :&: B) = A.
Proof. by rewrite setIC setKI. Qed.
Fact le_anti : antisymmetric (fun A B => A \subset B).
Proof. by move=> A B ABA; apply/eqP; rewrite eqEsubset. Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build disp {subset T} le_anti.
#[export]
HB.instance Definition _ := POrder_Meet_isDistrLattice.Build disp {subset T}
(@setIC _) (@setUC _) (@setIA _) (@setUA _) setKUC setKIC le_def (@setIUl _).
Lemma setIDv A B : B :&: (A :\: B) = set0.
Proof.
apply/eqP; rewrite -subset0; apply/subsetP => x.
by rewrite !inE => /and3P[->].
Qed.
#[export]
HB.instance Definition _ :=
@BDistrLattice_hasSectionalComplement.Build disp {subset T}
(@setD _) setIDv (@setID _).
Lemma setTDsym A : ~: A = setT :\: A.
Proof. by rewrite setTD. Qed.
#[export]
HB.instance Definition _ :=
CBDistrLattice_hasComplement.Build disp {subset T} setTDsym.
Lemma meetEsubset A B : A `&` B = A :&: B.
Proof. by []. Qed.
Lemma joinEsubset A B : A `|` B = A :|: B.
Proof. by []. Qed.
Lemma botEsubset : \bot = set0 :> {subset T}.
Proof. by []. Qed.
Lemma topEsubset : \top = setT :> {subset T}.
Proof. by []. Qed.
Lemma subEsubset A B : A `\` B = A :\: B.
Proof. by []. Qed.
Lemma complEsubset A : ~` A = ~: A.
Proof. by []. Qed.
End SetSubsetOrder.
Module Exports.
HB.reexport.
Definition meetEsubset := @meetEsubset.
Definition joinEsubset := @joinEsubset.
Definition botEsubset := @botEsubset.
Definition topEsubset := @topEsubset.
Definition subEsubset := @subEsubset.
Definition complEsubset := @complEsubset.
End Exports.
End SetSubsetOrder.
Export SetSubsetOrder.Exports.
Module DefaultSetSubsetOrder.
Export DefaultSetSubsetOrder.
HB.instance Definition _ (T : finType) :=
CTBDistrLattice.copy {set T} {subset T}.
End DefaultSetSubsetOrder.
Lemma mono_unique d (T T' : finPOrderType d) (f g : T -> T') :
total (<=%O : rel T) -> (#|T'| <= #|T|)%N ->
{mono f : x y / x <= y} -> {mono g : x y / x <= y} ->
f =1 g.
Proof.
move=> le_total leT'T lef leg x0; move: {+}x0.
suff: finfun f = finfun g by move=> /ffunP + x => /(_ x); rewrite !ffunE.
apply: (can_inj fgraphK); apply/val_inj => /=; rewrite !codomE.
under eq_map do rewrite ffunE; under [RHS]eq_map do rewrite ffunE.
have [finj ginj] := (inc_inj lef, inc_inj leg).
have [f' fK f'K] := inj_card_bij finj leT'T.
have [g' gK g'K] := inj_card_bij ginj leT'T.
apply/eqP; have : [seq f i | i <- enum T] = [seq g i | i <- enum T].
apply: (@sorted_eq _ <=%O le_trans le_anti); rewrite ?mono_sorted_enum//.
apply: uniq_perm; rewrite ?map_inj_uniq ?sort_uniq ?fintype.enum_uniq//.
move=> x; apply/mapP/mapP => -[y _ ->].
by exists (g' (f y)); rewrite ?mem_enum.
by exists (f' (g y)); rewrite ?mem_enum.
move=> /eqP; rewrite !eq_map_all all_map [in X in _ -> X]all_map.
by have /permPl/perm_all-> := perm_sort <=%O (fintype.enum T).
Qed.
(* This module should be exported on demand, as in module tagnat below *)
Module Import EnumVal.
Export EnumVal.
Section EnumVal.
Import OrdinalOrder.Exports.
Variables (d : disp_t) (T : finPOrderType d).
Implicit Types (x : T) (A : {pred T}).
Section total.
(* We circumvent a shortcoming of finOrderType *)
(* which requires the type to be nonempty and we do not want to rule this out *)
Hypothesis (leT_total : total (<=%O : rel T)).
Lemma le_enum_val A : {mono @enum_val _ _ A : i j / i <= j}.
Proof.
apply: le_mono => i j le_ij.
rewrite /enum_val (set_nth_default (enum_default j)) -?cardE//.
apply: (sorted_ltn_nth lt_trans); rewrite -?topredE/= -?cardE//.
by rewrite lt_sorted_uniq_le enum_uniq/= sort_sorted.
Qed.
Lemma le_enum_rank_in x0 A (Ax0 : x0 \in A) :
{in A &, {mono enum_rank_in Ax0 : x y / x <= y}}.
Proof.
apply: can_mono_in (@in2W _ _ predT predT _ (@le_enum_val A)) => //.
exact/onW_can_in/enum_rankK_in.
Qed.
Lemma le_enum_rank : {mono @enum_rank d T : i j / i <= j}.
Proof. exact: (can_mono (@enum_rankK _ _) (@le_enum_val predT)). Qed.
End total.
End EnumVal.
End EnumVal.
Notation le_enum_val := le_enum_val.
Notation le_enum_rank_in := le_enum_rank_in.
Notation le_enum_rank := le_enum_rank.
Module Syntax.
Export PreOSyntax.
Export DualSyntax.
Export DvdSyntax.
Export LatticeSyntax.
Export BLatticeSyntax.
Export TLatticeSyntax.
Export CBDistrLatticeSyntax.
Export CTBDistrLatticeSyntax.
Export DualSyntax.
Export DvdSyntax.
End Syntax.
Module LTheory.
Export PreorderTheory.
Export BPreorderTheory.
Export TPreorderTheory.
Export DualPreorder. (* FIXME? *)
Export PreOCoercions.
Export PreorderTheory.
Export POrderTheory.
Export BPOrderTheory.
Export TPOrderTheory.
Export MeetTheory.
Export BMeetTheory.
Export TMeetTheory.
Export JoinTheory.
Export BJoinTheory.
Export TJoinTheory.
Export LatticeTheory.
Export DistrLatticeTheory.
Export BDistrLatticeTheory.
Export TDistrLatticeTheory.
Export DualTotalTheory. (* FIXME? *)
Export DualOrder. (* FIXME? *)
Export OrderMorphismTheory.
Export LatticeMorphismTheory.
Export BLatticeMorphismTheory.
Export TLatticeMorphismTheory.
Export ClosedPredicates.
Export LatticePred.
Export SubPreorderTheory.
End LTheory.
Module CTheory.
Export LTheory.
Export CDistrLatticeTheory.
Export CBDistrLatticeTheory.
Export CTDistrLatticeTheory.
Export CTBDistrLatticeTheory.
End CTheory.
Module TTheory.
Export LTheory TotalTheory.
End TTheory.
Module Theory.
Export CTheory TotalTheory.
End Theory.
Module Exports.
HB.reexport.
End Exports.
End Order.
Export Order.Exports.
Export Order.Syntax.
Export order.Order.Exports.
Export Order.POrder.Exports.
Export Order.BPOrder.Exports.
Export Order.TPOrder.Exports.
Export Order.TBPOrder.Exports.
Export Order.MeetSemilattice.Exports.
Export Order.BMeetSemilattice.Exports.
Export Order.TMeetSemilattice.Exports.
Export Order.TBMeetSemilattice.Exports.
Export Order.JoinSemilattice.Exports.
Export Order.BJoinSemilattice.Exports.
Export Order.TJoinSemilattice.Exports.
Export Order.TBJoinSemilattice.Exports.
Export Order.Lattice.Exports.
Export Order.BLattice.Exports.
Export Order.TLattice.Exports.
Export Order.TBLattice.Exports.
Export Order.DistrLattice.Exports.
Export Order.BDistrLattice.Exports.
Export Order.TDistrLattice.Exports.
Export Order.TBDistrLattice.Exports.
Export Order.Total.Exports.
Export Order.BTotal.Exports.
Export Order.TTotal.Exports.
Export Order.TBTotal.Exports.
Export Order.CDistrLattice.Exports.
Export Order.CBDistrLattice.Exports.
Export Order.CTDistrLattice.Exports.
Export Order.CTBDistrLattice.Exports.
Export Order.FinPOrder.Exports.
Export Order.FinBPOrder.Exports.
Export Order.FinTPOrder.Exports.
Export Order.FinTBPOrder.Exports.
Export Order.FinMeetSemilattice.Exports.
Export Order.FinBMeetSemilattice.Exports.
Export Order.FinJoinSemilattice.Exports.
Export Order.FinTJoinSemilattice.Exports.
Export Order.FinLattice.Exports.
Export Order.FinTBLattice.Exports.
Export Order.FinDistrLattice.Exports.
Export Order.FinTBDistrLattice.Exports.
Export Order.FinTotal.Exports.
Export Order.FinTBTotal.Exports.
Export Order.FinCDistrLattice.Exports.
Export Order.FinCTBDistrLattice.Exports.
(* FIXME: check if covered by Order.Exports *)
(* Export Order.NatOrder.Exports. *)
(* Export Order.NatMonotonyTheory. *)
(* Export Order.NatDvd.Exports. *)
(* Export Order.OrdinalOrder.Exports. *)
(* Export Order.BoolOrder.Exports. *)
(* Export Order.ProdOrder.Exports. *)
(* Export Order.SigmaOrder.Exports. *)
(* Export Order.ProdLexiOrder.Exports. *)
(* Export Order.SeqProdOrder.Exports. *)
(* Export Order.SeqLexiOrder.Exports. *)
(* Export Order.TupleProdOrder.Exports. *)
(* Export Order.TupleLexiOrder.Exports. *)
Module DefaultProdOrder := Order.DefaultProdOrder.
Module DefaultSeqProdOrder := Order.DefaultSeqProdOrder.
Module DefaultTupleProdOrder := Order.DefaultTupleProdOrder.
Module DefaultProdLexiOrder := Order.DefaultProdLexiOrder.
Module DefaultSeqLexiOrder := Order.DefaultSeqLexiOrder.
Module DefaultTupleLexiOrder := Order.DefaultTupleLexiOrder.
Import Order.Theory.
Module tagnat.
Section tagnat.
Import Order.EnumVal.
Context {n : nat} {p_ : 'I_n -> nat}.
Local Notation ordsum := 'I_(\sum_i p_ i)%N.
Local Notation T := {i & 'I_(p_ i)}.
Implicit Types (i : 'I_n) (s : ordsum) (p : T).
Lemma card : #|{: T}| = \sum_i p_ i.
Proof.
rewrite card_tagged sumnE/= big_map big_enum.
by apply: eq_bigr => i _; rewrite card_ord.
Qed.
Definition sig : ordsum -> T := enum_val \o cast_ord (esym card).
Definition rank : T -> ordsum := cast_ord card \o enum_rank.
Lemma sigK : cancel sig rank.
Proof.
by move=> s; rewrite /sig/rank/= enum_valK cast_ord_comp cast_ord_id.
Qed.
Lemma sig_inj : injective sig. Proof. exact: can_inj sigK. Qed.
Lemma rankK : cancel rank sig.
Proof.
by move=> p; rewrite /sig/rank/= cast_ord_comp cast_ord_id enum_rankK.
Qed.
Lemma rank_inj : injective rank. Proof. exact: can_inj rankK. Qed.
Definition sig1 s : 'I_n := tag (sig s).
Definition sig2 s : 'I_(p_ (sig1 s)) := tagged (sig s).
Definition Rank i (j : 'I_(p_ i)) := rank (Tagged _ j).
Lemma sigE12 s : sig s = @Tagged _ (sig1 s) _ (sig2 s).
Proof. by rewrite /sig1 /sig2; case: sig. Qed.
Lemma rankE p : rank p = @Rank (tag p) (tagged p). Proof. by case: p. Qed.
Lemma sig2K s : Rank (sig2 s) = s. Proof. by rewrite -rankE sigK. Qed.
Lemma Rank1K i0 (k : 'I_(p_ i0)) : sig1 (Rank k) = i0.
Proof. by rewrite /sig1 /Rank/= rankK/=. Qed.
Lemma Rank2K i0 (k : 'I_(p_ i0)) :
sig2 (Rank k) = cast_ord (congr1 p_ (esym (Rank1K k))) k.
Proof. by apply: val_inj; rewrite /sig2/sig1/Rank/= rankK. Qed.
#[local] Hint Resolve sigK rankK : core.
Lemma rank_bij : bijective rank. Proof. by exists sig. Qed.
Lemma sig_bij : bijective sig. Proof. by exists rank. Qed.
Lemma rank_bij_on : {on [pred _ | true], bijective rank}.
Proof. exact/onW_bij/rank_bij. Qed.
Lemma sig_bij_on : {on [pred _ | true], bijective sig}.
Proof. exact/onW_bij/sig_bij. Qed.
Lemma le_sig : {mono sig : i j / i <= j}.
Proof. by move=> i j; rewrite /sig/= le_enum_val//; apply: le_total. Qed.
Lemma le_sig1 : {homo sig1 : i j / i <= j}.
Proof. by move=> i j; rewrite /sig1/= -le_sig leEsig/=; case: leP. Qed.
Lemma le_rank : {mono rank : p q / p <= q}.
Proof. exact: can_mono le_sig. Qed.
Lemma le_Rank i : {mono @Rank i : j k / j <= k}.
Proof. by move=> j k; rewrite /Rank le_rank/= leEsig/= tagged_asE lexx. Qed.
Lemma lt_sig : {mono sig : i j / i < j}.
Proof. by move=> i j; rewrite !ltNge le_sig. Qed.
Lemma lt_rank : {mono rank : p q / p < q}.
Proof. by move=> p q; rewrite !ltNge le_rank. Qed.
Lemma lt_Rank i : {mono @Rank i : j k / j < k}.
Proof. by move=> j k; rewrite !ltNge le_Rank. Qed.
Lemma eq_Rank i i' (j : 'I_(p_ i)) (j': 'I_(p_ i')) :
(Rank j == Rank j' :> nat) = (i == i') && (j == j' :> nat).
Proof.
rewrite val_eqE /Rank -(can_eq sigK) !rankK.
case: (i =P i') => ii' /=; last by case: eqVneq => // -[].
by case: _ / ii' in j' *; rewrite eq_Tagged.
Qed.
Lemma rankEsum p : rank p = \sum_(i < n | (i < tag p)%N) p_ i + tagged p :> nat.
Proof.
pose sum p := \sum_(i < n | (i < tag p)%N) p_ i + tagged p.
rewrite -/(sum _); have sumlt : forall p, (sum p < \sum_i p_ i)%N.
rewrite /sum => -[/= i j].
rewrite [ltnRHS](bigID [pred i' : 'I__ | (i' < i)%N])/= ltn_add2l.
by rewrite (bigD1 i) ?ltnn//= ltn_addr.
suff: rank =1 (fun p => Ordinal (sumlt p)) by move=> /(_ p)/(congr1 val).
apply: (Order.mono_unique _ _ le_rank) => //=.
- exact: le_total.
- by rewrite card card_ord.
apply: le_mono => /= -[i j] -[i' j']; rewrite ltEsig/= !ltEord/= /sum leEord/=.
case: (ltngtP i i') => //= [ltii' _|/val_inj ii']; last first.
by rewrite -ii' in j' *; rewrite tagged_asE => ltjj'; rewrite ltn_add2l.
rewrite ltn_addr// (@leq_trans (\sum_(i0 < n | (i0 < i)%N) p_ i0 + p_ i))%N//.
by rewrite ltn_add2l.
rewrite [leqRHS](bigID [pred i' : 'I__ | (i' < i)%N])/=.
rewrite leq_add//; last first.
by rewrite (bigD1 i) ?ltnn ?ltii'//= leq_addr.
rewrite [leqRHS](eq_bigl [pred k : 'I_n | (k < i)%N])// => k/=.
by case: (ltnP k i); rewrite ?andbF// => /ltn_trans->.
Qed.
Lemma RankEsum i j : @Rank i j = \sum_(k < n | (k < i)%N) p_ k + j :> nat.
Proof. by rewrite /Rank rankEsum/=. Qed.
Lemma rect s : s = \sum_(i < n | (i < sig1 s)%N) p_ i + sig2 s :> nat.
Proof. by rewrite -[s]sigK rankEsum /= sigK. Qed.
Lemma eqRank (i0 j : nat) (li0 : (i0 < n)%N) (lj : (j < p_ (Ordinal li0))%N) :
(\sum_(i < n | (i < i0)%N) p_ i) + j = Rank (Ordinal lj) :> nat.
Proof. by rewrite RankEsum. Qed.
End tagnat.
End tagnat.
Arguments tagnat.Rank {n p_}.
|
AbelianImages.lean
|
/-
Copyright (c) 2025 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Abelian.Images
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels
/-!
# Preservation of coimage-image comparisons
If a functor preserves kernels and cokernels, then it preserves abelian images, abelian coimages
and coimage-image comparisons.
-/
noncomputable section
universe v₁ v₂ u₁ u₂
open CategoryTheory Limits
namespace CategoryTheory.Abelian
variable {C : Type u₁} [Category.{v₁} C] [HasZeroMorphisms C]
variable {D : Type u₂} [Category.{v₂} D] [HasZeroMorphisms D]
variable (F : C ⥤ D) [F.PreservesZeroMorphisms]
variable {X Y : C} (f : X ⟶ Y)
section Images
variable [HasCokernel f] [HasKernel (cokernel.π f)] [PreservesColimit (parallelPair f 0) F]
[PreservesLimit (parallelPair (cokernel.π f) 0) F] [HasCokernel (F.map f)]
[HasKernel (cokernel.π (F.map f))]
/-- If a functor preserves kernels and cokernels, it preserves abelian images. -/
def PreservesImage.iso : F.obj (Abelian.image f) ≅ Abelian.image (F.map f) :=
PreservesKernel.iso F _ ≪≫ kernel.mapIso _ _ (Iso.refl _) (PreservesCokernel.iso F _) (by simp)
@[reassoc (attr := simp)]
theorem PreservesImage.iso_hom_ι :
(PreservesImage.iso F f).hom ≫ Abelian.image.ι (F.map f) = F.map (Abelian.image.ι f) := by
simp [iso]
@[reassoc (attr := simp)]
theorem PreservesImage.factorThruImage_iso_hom :
F.map (Abelian.factorThruImage f) ≫ (PreservesImage.iso F f).hom =
Abelian.factorThruImage (F.map f) := by
ext; simp [iso]
@[reassoc (attr := simp)]
theorem PreservesImage.iso_inv_ι :
(PreservesImage.iso F f).inv ≫ F.map (Abelian.image.ι f) = Abelian.image.ι (F.map f) := by
simp [iso]
@[reassoc (attr := simp)]
theorem PreservesImage.factorThruImage_iso_inv :
Abelian.factorThruImage (F.map f) ≫ (PreservesImage.iso F f).inv =
F.map (Abelian.factorThruImage f) := by
simp [Iso.comp_inv_eq]
end Images
section Coimages
variable [HasKernel f] [HasCokernel (kernel.ι f)] [PreservesLimit (parallelPair f 0) F]
[PreservesColimit (parallelPair (kernel.ι f) 0) F] [HasKernel (F.map f)]
[HasCokernel (kernel.ι (F.map f))]
/-- If a functor preserves kernels and cokernels, it preserves abelian coimages. -/
def PreservesCoimage.iso : F.obj (Abelian.coimage f) ≅ Abelian.coimage (F.map f) :=
PreservesCokernel.iso F _ ≪≫ cokernel.mapIso _ _ (PreservesKernel.iso F _) (Iso.refl _) (by simp)
@[reassoc (attr := simp)]
theorem PreservesCoimage.iso_hom_π :
F.map (Abelian.coimage.π f) ≫ (PreservesCoimage.iso F f).hom = Abelian.coimage.π (F.map f) := by
simp [iso]
@[reassoc (attr := simp)]
theorem PreservesCoimage.factorThruCoimage_iso_inv :
(PreservesCoimage.iso F f).inv ≫ F.map (Abelian.factorThruCoimage f) =
Abelian.factorThruCoimage (F.map f) := by
ext; simp [iso]
@[reassoc (attr := simp)]
theorem PreservesCoimage.factorThruCoimage_iso_hom :
(PreservesCoimage.iso F f).hom ≫ Abelian.factorThruCoimage (F.map f) =
F.map (Abelian.factorThruCoimage f) := by
simp [← Iso.eq_inv_comp]
@[reassoc (attr := simp)]
theorem PreservesCoimage.iso_inv_π :
Abelian.coimage.π (F.map f) ≫ (PreservesCoimage.iso F f).inv = F.map (Abelian.coimage.π f) := by
simp [Iso.comp_inv_eq]
end Coimages
variable [HasKernel f] [HasCokernel f] [HasKernel (cokernel.π f)] [HasCokernel (kernel.ι f)]
[PreservesLimit (parallelPair f 0) F] [PreservesColimit (parallelPair f 0) F]
[PreservesLimit (parallelPair (cokernel.π f) 0) F]
[PreservesColimit (parallelPair (kernel.ι f) 0) F]
[HasKernel (cokernel.π (F.map f))] [HasCokernel (kernel.ι (F.map f))]
theorem PreservesCoimage.hom_coimageImageComparison :
(PreservesCoimage.iso F f).hom ≫ coimageImageComparison (F.map f) =
F.map (coimageImageComparison f) ≫ (PreservesImage.iso F f).hom := by
simp [← Functor.map_comp, ← Iso.eq_inv_comp, ← cancel_epi (Abelian.coimage.π (F.map f)),
← cancel_mono (Abelian.image.ι (F.map f))]
/-- If a functor preserves kernels and cokernels, it preserves coimage-image comparisons. -/
@[simps!]
def PreservesCoimageImageComparison.iso :
Arrow.mk (F.map (coimageImageComparison f)) ≅ Arrow.mk (coimageImageComparison (F.map f)) :=
Arrow.isoMk' _ _ (PreservesCoimage.iso F f) (PreservesImage.iso F f)
(PreservesCoimage.hom_coimageImageComparison F f)
end CategoryTheory.Abelian
|
Ring.lean
|
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Algebra.Order.Nonneg.Basic
import Mathlib.Algebra.Order.Nonneg.Lattice
import Mathlib.Algebra.Order.Ring.InjSurj
import Mathlib.Tactic.FastInstance
/-!
# Bundled ordered algebra instance on the type of nonnegative elements
This file defines instances and prove some properties about the nonnegative elements
`{x : α // 0 ≤ x}` of an arbitrary type `α`.
Currently we only state instances and states some `simp`/`norm_cast` lemmas.
When `α` is `ℝ`, this will give us some properties about `ℝ≥0`.
## Main declarations
* `{x : α // 0 ≤ x}` is a `CanonicallyLinearOrderedAddCommMonoid` if `α` is a `LinearOrderedRing`.
## Implementation Notes
Instead of `{x : α // 0 ≤ x}` we could also use `Set.Ici (0 : α)`, which is definitionally equal.
However, using the explicit subtype has a big advantage: when writing an element explicitly
with a proof of nonnegativity as `⟨x, hx⟩`, the `hx` is expected to have type `0 ≤ x`. If we would
use `Ici 0`, then the type is expected to be `x ∈ Ici 0`. Although these types are definitionally
equal, this often confuses the elaborator. Similar problems arise when doing cases on an element.
The disadvantage is that we have to duplicate some instances about `Set.Ici` to this subtype.
-/
open Set
variable {α : Type*}
namespace Nonneg
instance isOrderedAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedAddMonoid α] :
IsOrderedAddMonoid { x : α // 0 ≤ x } :=
Subtype.coe_injective.isOrderedAddMonoid _ Nonneg.coe_zero (fun _ _ => rfl) fun _ _ => rfl
instance isOrderedCancelAddMonoid [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] :
IsOrderedCancelAddMonoid { x : α // 0 ≤ x } :=
Subtype.coe_injective.isOrderedCancelAddMonoid _ Nonneg.coe_zero (fun _ _ => rfl) fun _ _ => rfl
instance isOrderedRing [Semiring α] [PartialOrder α] [IsOrderedRing α] :
IsOrderedRing { x : α // 0 ≤ x } :=
Subtype.coe_injective.isOrderedRing _ Nonneg.coe_zero Nonneg.coe_one
(fun _ _ => rfl) (fun _ _=> rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ => rfl
instance isStrictOrderedRing [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] :
IsStrictOrderedRing { x : α // 0 ≤ x } :=
Subtype.coe_injective.isStrictOrderedRing _ Nonneg.coe_zero Nonneg.coe_one
(fun _ _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) fun _ => rfl
instance existsAddOfLE [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] [ExistsAddOfLE α] :
ExistsAddOfLE { x : α // 0 ≤ x } :=
⟨fun {a b} h ↦ by
rw [← Subtype.coe_le_coe] at h
obtain ⟨c, hc⟩ := exists_add_of_le h
refine ⟨⟨c, ?_⟩, by simp [Subtype.ext_iff, hc]⟩
rw [← add_zero a.val, hc] at h
exact le_of_add_le_add_left h⟩
instance nontrivial [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] :
Nontrivial { x : α // 0 ≤ x } :=
⟨⟨0, 1, fun h => zero_ne_one (congr_arg Subtype.val h)⟩⟩
instance linearOrderedCommMonoidWithZero [CommSemiring α] [LinearOrder α] [IsStrictOrderedRing α] :
LinearOrderedCommMonoidWithZero { x : α // 0 ≤ x } :=
{ Nonneg.commSemiring, Nonneg.isOrderedRing with
mul_le_mul_left := fun _ _ h c ↦ mul_le_mul_of_nonneg_left h c.prop }
instance canonicallyOrderedAdd [Ring α] [PartialOrder α] [IsOrderedRing α] :
CanonicallyOrderedAdd { x : α // 0 ≤ x } :=
{ le_self_add := fun _ b => le_add_of_nonneg_right b.2
exists_add_of_le := fun {a b} h =>
⟨⟨b - a, sub_nonneg_of_le h⟩, Subtype.ext (add_sub_cancel _ _).symm⟩ }
instance noZeroDivisors [Semiring α] [PartialOrder α] [IsOrderedRing α] [NoZeroDivisors α] :
NoZeroDivisors { x : α // 0 ≤ x } :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
simp only [mk_mul_mk, mk_eq_zero, mul_eq_zero, imp_self]}
instance orderedSub [Ring α] [LinearOrder α] [IsStrictOrderedRing α] :
OrderedSub { x : α // 0 ≤ x } :=
⟨by
rintro ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩
simp only [sub_le_iff_le_add, Subtype.mk_le_mk, mk_sub_mk, mk_add_mk, toNonneg_le]⟩
end Nonneg
|
Basic.lean
|
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Analysis.Convex.Hull
import Mathlib.LinearAlgebra.AffineSpace.Independent
/-!
# Simplicial complexes
In this file, we define simplicial complexes in `𝕜`-modules. A simplicial complex is a collection
of simplices closed by inclusion (of vertices) and intersection (of underlying sets).
We model them by a downward-closed set of affine independent finite sets whose convex hulls "glue
nicely", each finite set and its convex hull corresponding respectively to the vertices and the
underlying set of a simplex.
## Main declarations
* `SimplicialComplex 𝕜 E`: A simplicial complex in the `𝕜`-module `E`.
* `SimplicialComplex.vertices`: The zero dimensional faces of a simplicial complex.
* `SimplicialComplex.facets`: The maximal faces of a simplicial complex.
## Notation
`s ∈ K` means that `s` is a face of `K`.
`K ≤ L` means that the faces of `K` are faces of `L`.
## Implementation notes
"glue nicely" usually means that the intersection of two faces (as sets in the ambient space) is a
face. Given that we store the vertices, not the faces, this would be a bit awkward to spell.
Instead, `SimplicialComplex.inter_subset_convexHull` is an equivalent condition which works on the
vertices.
## TODO
Simplicial complexes can be generalized to affine spaces once `ConvexHull` has been ported.
-/
open Finset Set
variable (𝕜 E : Type*) [Ring 𝕜] [PartialOrder 𝕜] [AddCommGroup E] [Module 𝕜 E]
namespace Geometry
-- TODO: update to new binder order? not sure what binder order is correct for `down_closed`.
/-- A simplicial complex in a `𝕜`-module is a collection of simplices which glue nicely together.
Note that the textbook meaning of "glue nicely" is given in
`Geometry.SimplicialComplex.disjoint_or_exists_inter_eq_convexHull`. It is mostly useless, as
`Geometry.SimplicialComplex.convexHull_inter_convexHull` is enough for all purposes. -/
@[ext]
structure SimplicialComplex where
/-- the faces of this simplicial complex: currently, given by their spanning vertices -/
faces : Set (Finset E)
/-- the empty set is not a face: hence, all faces are non-empty -/
empty_notMem : ∅ ∉ faces
/-- the vertices in each face are affine independent: this is an implementation detail -/
indep : ∀ {s}, s ∈ faces → AffineIndependent 𝕜 ((↑) : s → E)
/-- faces are downward closed: a non-empty subset of its spanning vertices spans another face -/
down_closed : ∀ {s t}, s ∈ faces → t ⊆ s → t ≠ ∅ → t ∈ faces
inter_subset_convexHull : ∀ {s t}, s ∈ faces → t ∈ faces →
convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t ⊆ convexHull 𝕜 (s ∩ t : Set E)
namespace SimplicialComplex
@[deprecated (since := "2025-05-23")]
alias not_empty_mem := empty_notMem
variable {𝕜 E}
variable {K : SimplicialComplex 𝕜 E} {s t : Finset E} {x : E}
/-- A `Finset` belongs to a `SimplicialComplex` if it's a face of it. -/
instance : Membership (Finset E) (SimplicialComplex 𝕜 E) :=
⟨fun K s => s ∈ K.faces⟩
lemma nonempty_of_mem_faces (hs : s ∈ K.faces) : s.Nonempty := by
rw [Finset.nonempty_iff_ne_empty]; rintro rfl; exact K.empty_notMem hs
/-- The underlying space of a simplicial complex is the union of its faces. -/
def space (K : SimplicialComplex 𝕜 E) : Set E :=
⋃ s ∈ K.faces, convexHull 𝕜 (s : Set E)
-- Porting note: Expanded `∃ s ∈ K.faces` to get the type to match more closely with Lean 3
theorem mem_space_iff : x ∈ K.space ↔ ∃ s ∈ K.faces, x ∈ convexHull 𝕜 (s : Set E) := by
simp [space]
-- Porting note: Original proof was `:= subset_biUnion_of_mem hs`
theorem convexHull_subset_space (hs : s ∈ K.faces) : convexHull 𝕜 ↑s ⊆ K.space := by
convert subset_biUnion_of_mem hs
rfl
protected theorem subset_space (hs : s ∈ K.faces) : (s : Set E) ⊆ K.space :=
(subset_convexHull 𝕜 _).trans <| convexHull_subset_space hs
theorem convexHull_inter_convexHull (hs : s ∈ K.faces) (ht : t ∈ K.faces) :
convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t = convexHull 𝕜 (s ∩ t : Set E) :=
(K.inter_subset_convexHull hs ht).antisymm <|
subset_inter (convexHull_mono Set.inter_subset_left) <|
convexHull_mono Set.inter_subset_right
/-- The conclusion is the usual meaning of "glue nicely" in textbooks. It turns out to be quite
unusable, as it's about faces as sets in space rather than simplices. Further, additional structure
on `𝕜` means the only choice of `u` is `s ∩ t` (but it's hard to prove). -/
theorem disjoint_or_exists_inter_eq_convexHull (hs : s ∈ K.faces) (ht : t ∈ K.faces) :
Disjoint (convexHull 𝕜 (s : Set E)) (convexHull 𝕜 ↑t) ∨
∃ u ∈ K.faces, convexHull 𝕜 (s : Set E) ∩ convexHull 𝕜 ↑t = convexHull 𝕜 ↑u := by
classical
by_contra! h
refine h.2 (s ∩ t) (K.down_closed hs inter_subset_left fun hst => h.1 <|
disjoint_iff_inf_le.mpr <| (K.inter_subset_convexHull hs ht).trans ?_) ?_
· rw [← coe_inter, hst, coe_empty, convexHull_empty]
rfl
· rw [coe_inter, convexHull_inter_convexHull hs ht]
/-- Construct a simplicial complex by removing the empty face for you. -/
@[simps]
def ofErase (faces : Set (Finset E)) (indep : ∀ s ∈ faces, AffineIndependent 𝕜 ((↑) : s → E))
(down_closed : ∀ s ∈ faces, ∀ t ⊆ s, t ∈ faces)
(inter_subset_convexHull : ∀ᵉ (s ∈ faces) (t ∈ faces),
convexHull 𝕜 ↑s ∩ convexHull 𝕜 ↑t ⊆ convexHull 𝕜 (s ∩ t : Set E)) :
SimplicialComplex 𝕜 E where
faces := faces \ {∅}
empty_notMem h := h.2 (mem_singleton _)
indep hs := indep _ hs.1
down_closed hs hts ht := ⟨down_closed _ hs.1 _ hts, ht⟩
inter_subset_convexHull hs ht := inter_subset_convexHull _ hs.1 _ ht.1
/-- Construct a simplicial complex as a subset of a given simplicial complex. -/
@[simps]
def ofSubcomplex (K : SimplicialComplex 𝕜 E) (faces : Set (Finset E)) (subset : faces ⊆ K.faces)
(down_closed : ∀ {s t}, s ∈ faces → t ⊆ s → t ∈ faces) : SimplicialComplex 𝕜 E :=
{ faces
empty_notMem := fun h => K.empty_notMem (subset h)
indep := fun hs => K.indep (subset hs)
down_closed := fun hs hts _ => down_closed hs hts
inter_subset_convexHull := fun hs ht => K.inter_subset_convexHull (subset hs) (subset ht) }
/-! ### Vertices -/
/-- The vertices of a simplicial complex are its zero dimensional faces. -/
def vertices (K : SimplicialComplex 𝕜 E) : Set E :=
{ x | {x} ∈ K.faces }
theorem mem_vertices : x ∈ K.vertices ↔ {x} ∈ K.faces := Iff.rfl
theorem vertices_eq : K.vertices = ⋃ k ∈ K.faces, (k : Set E) := by
ext x
refine ⟨fun h => mem_biUnion h <| mem_coe.2 <| mem_singleton_self x, fun h => ?_⟩
obtain ⟨s, hs, hx⟩ := mem_iUnion₂.1 h
exact K.down_closed hs (Finset.singleton_subset_iff.2 <| mem_coe.1 hx) (singleton_ne_empty _)
theorem vertices_subset_space : K.vertices ⊆ K.space :=
vertices_eq.subset.trans <| iUnion₂_mono fun x _ => subset_convexHull 𝕜 (x : Set E)
theorem vertex_mem_convexHull_iff (hx : x ∈ K.vertices) (hs : s ∈ K.faces) :
x ∈ convexHull 𝕜 (s : Set E) ↔ x ∈ s := by
refine ⟨fun h => ?_, fun h => subset_convexHull 𝕜 _ h⟩
classical
have h := K.inter_subset_convexHull hx hs ⟨by simp, h⟩
by_contra H
rwa [← coe_inter, Finset.disjoint_iff_inter_eq_empty.1 (Finset.disjoint_singleton_right.2 H).symm,
coe_empty, convexHull_empty] at h
/-- A face is a subset of another one iff its vertices are. -/
theorem face_subset_face_iff (hs : s ∈ K.faces) (ht : t ∈ K.faces) :
convexHull 𝕜 (s : Set E) ⊆ convexHull 𝕜 ↑t ↔ s ⊆ t :=
⟨fun h _ hxs =>
(vertex_mem_convexHull_iff
(K.down_closed hs (Finset.singleton_subset_iff.2 hxs) <| singleton_ne_empty _) ht).1
(h (subset_convexHull 𝕜 (E := E) s hxs)),
convexHull_mono⟩
/-! ### Facets -/
/-- A facet of a simplicial complex is a maximal face. -/
def facets (K : SimplicialComplex 𝕜 E) : Set (Finset E) :=
{ s ∈ K.faces | ∀ ⦃t⦄, t ∈ K.faces → s ⊆ t → s = t }
theorem mem_facets : s ∈ K.facets ↔ s ∈ K.faces ∧ ∀ t ∈ K.faces, s ⊆ t → s = t :=
mem_sep_iff
theorem facets_subset : K.facets ⊆ K.faces := fun _ hs => hs.1
theorem not_facet_iff_subface (hs : s ∈ K.faces) : s ∉ K.facets ↔ ∃ t, t ∈ K.faces ∧ s ⊂ t := by
refine ⟨fun hs' : ¬(_ ∧ _) => ?_, ?_⟩
· push_neg at hs'
obtain ⟨t, ht⟩ := hs' hs
exact ⟨t, ht.1, ⟨ht.2.1, fun hts => ht.2.2 (Subset.antisymm ht.2.1 hts)⟩⟩
· rintro ⟨t, ht⟩ ⟨hs, hs'⟩
have := hs' ht.1 ht.2.1
rw [this] at ht
exact ht.2.2 (Subset.refl t)
/-!
### The semilattice of simplicial complexes
`K ≤ L` means that `K.faces ⊆ L.faces`.
-/
-- `HasSSubset.SSubset.ne` would be handy here
variable (𝕜 E)
/-- The complex consisting of only the faces present in both of its arguments. -/
instance : Min (SimplicialComplex 𝕜 E) :=
⟨fun K L =>
{ faces := K.faces ∩ L.faces
empty_notMem := fun h => K.empty_notMem (Set.inter_subset_left h)
indep := fun hs => K.indep hs.1
down_closed := fun hs hst ht => ⟨K.down_closed hs.1 hst ht, L.down_closed hs.2 hst ht⟩
inter_subset_convexHull := fun hs ht => K.inter_subset_convexHull hs.1 ht.1 }⟩
instance : SemilatticeInf (SimplicialComplex 𝕜 E) :=
{ PartialOrder.lift faces (fun _ _ => SimplicialComplex.ext) with
inf := (· ⊓ ·)
inf_le_left := fun _ _ _ hs => hs.1
inf_le_right := fun _ _ _ hs => hs.2
le_inf := fun _ _ _ hKL hKM _ hs => ⟨hKL hs, hKM hs⟩ }
instance hasBot : Bot (SimplicialComplex 𝕜 E) :=
⟨{ faces := ∅
empty_notMem := Set.notMem_empty ∅
indep := fun hs => (Set.notMem_empty _ hs).elim
down_closed := fun hs => (Set.notMem_empty _ hs).elim
inter_subset_convexHull := fun hs => (Set.notMem_empty _ hs).elim }⟩
instance : OrderBot (SimplicialComplex 𝕜 E) :=
{ SimplicialComplex.hasBot 𝕜 E with bot_le := fun _ => Set.empty_subset _ }
instance : Inhabited (SimplicialComplex 𝕜 E) :=
⟨⊥⟩
variable {𝕜 E}
theorem faces_bot : (⊥ : SimplicialComplex 𝕜 E).faces = ∅ := rfl
theorem space_bot : (⊥ : SimplicialComplex 𝕜 E).space = ∅ :=
Set.biUnion_empty _
theorem facets_bot : (⊥ : SimplicialComplex 𝕜 E).facets = ∅ :=
eq_empty_of_subset_empty facets_subset
end SimplicialComplex
end Geometry
|
Real.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Topology.MetricSpace.Bounded
import Mathlib.Topology.Order.Bornology
/-!
# The reals are equipped with their order bornology
This file contains results related to the order bornology on (non-negative) real numbers.
We prove that `ℝ` and `ℝ≥0` are equipped with the order topology and bornology.
-/
assert_not_exists IsTopologicalRing UniformContinuousConstSMul UniformOnFun
open Metric Set
instance instIsOrderBornology : IsOrderBornology ℝ where
isBounded_iff_bddBelow_bddAbove s := by
refine ⟨fun bdd ↦ ?_, fun h ↦ isBounded_of_bddAbove_of_bddBelow h.2 h.1⟩
obtain ⟨r, hr⟩ : ∃ r : ℝ, s ⊆ Icc (-r) r := by
simpa [Real.closedBall_eq_Icc] using bdd.subset_closedBall 0
exact ⟨bddBelow_Icc.mono hr, bddAbove_Icc.mono hr⟩
namespace NNReal
/-!
Every instance is inherited from the corresponding structures on the reals.
-/
instance : OrderTopology ℝ≥0 :=
orderTopology_of_ordConnected (t := Ici 0)
-- TODO: generalize this to a broader class of subtypes
instance : IsOrderBornology ℝ≥0 where
isBounded_iff_bddBelow_bddAbove s := by
refine ⟨fun bdd ↦ ?_, fun h ↦ isBounded_of_bddAbove_of_bddBelow h.2 h.1⟩
obtain ⟨r, hr⟩ : ∃ r : ℝ≥0, s ⊆ Icc 0 r := by
obtain ⟨rreal, hrreal⟩ := bdd.subset_closedBall 0
use rreal.toNNReal
simp only [← NNReal.closedBall_zero_eq_Icc', Real.coe_toNNReal']
exact subset_trans hrreal (Metric.closedBall_subset_closedBall (le_max_left rreal 0))
exact ⟨bddBelow_Icc.mono hr, bddAbove_Icc.mono hr⟩
end NNReal
|
Rify.lean
|
/-
Copyright (c) 2023 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll, Mario Carneiro, Robert Y. Lewis, Patrick Massot
-/
import Mathlib.Data.Rat.Cast.Order
import Mathlib.Data.Real.Basic
import Mathlib.Tactic.Qify
/-!
# `rify` tactic
The `rify` tactic is used to shift propositions from `ℕ`, `ℤ` or `ℚ` to `ℝ`.
Although less useful than its cousins `zify` and `qify`, it can be useful when your
goal or context already involves real numbers.
In the example below, assumption `hn` is about natural numbers, `hk` is about integers
and involves casting a natural number to `ℤ`, and the conclusion is about real numbers.
The proof uses `rify` to lift both assumptions to `ℝ` before calling `linarith`.
```
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Rify
example {n : ℕ} {k : ℤ} (hn : 8 ≤ n) (hk : 2 * k ≤ n + 2) :
(0 : ℝ) < n - k - 1 := by
rify at hn hk
linarith
```
TODO: Investigate whether we should generalize this to other fields.
-/
namespace Mathlib.Tactic.Rify
open Lean
open Lean.Meta
open Lean.Parser.Tactic
open Lean.Elab.Tactic
/--
The `rify` tactic is used to shift propositions from `ℕ`, `ℤ` or `ℚ` to `ℝ`.
Although less useful than its cousins `zify` and `qify`, it can be useful when your
goal or context already involves real numbers.
In the example below, assumption `hn` is about natural numbers, `hk` is about integers
and involves casting a natural number to `ℤ`, and the conclusion is about real numbers.
The proof uses `rify` to lift both assumptions to `ℝ` before calling `linarith`.
```
example {n : ℕ} {k : ℤ} (hn : 8 ≤ n) (hk : 2 * k ≤ n + 2) :
(0 : ℝ) < n - k - 1 := by
rify at hn hk /- Now have hn : 8 ≤ (n : ℝ) hk : 2 * (k : ℝ) ≤ (n : ℝ) + 2 -/
linarith
```
`rify` makes use of the `@[zify_simps]`, `@[qify_simps]` and `@[rify_simps]` attributes to move
propositions, and the `push_cast` tactic to simplify the `ℝ`-valued expressions.
`rify` can be given extra lemmas to use in simplification. This is especially useful in the
presence of nat subtraction: passing `≤` arguments will allow `push_cast` to do more work.
```
example (a b c : ℕ) (h : a - b < c) (hab : b ≤ a) : a < b + c := by
rify [hab] at h ⊢
linarith
```
Note that `zify` or `qify` would work just as well in the above example (and `zify` is the natural
choice since it is enough to get rid of the pathological `ℕ` subtraction). -/
syntax (name := rify) "rify" (simpArgs)? (location)? : tactic
macro_rules
| `(tactic| rify $[[$simpArgs,*]]? $[at $location]?) =>
let args := simpArgs.map (·.getElems) |>.getD #[]
`(tactic|
simp -decide only [zify_simps, qify_simps, rify_simps, push_cast, $args,*]
$[at $location]?)
@[rify_simps] lemma ratCast_eq (a b : ℚ) : a = b ↔ (a : ℝ) = (b : ℝ) := by simp
@[rify_simps] lemma ratCast_le (a b : ℚ) : a ≤ b ↔ (a : ℝ) ≤ (b : ℝ) := by simp
@[rify_simps] lemma ratCast_lt (a b : ℚ) : a < b ↔ (a : ℝ) < (b : ℝ) := by simp
@[rify_simps] lemma ratCast_ne (a b : ℚ) : a ≠ b ↔ (a : ℝ) ≠ (b : ℝ) := by simp
@[rify_simps] lemma ofNat_rat_real (a : ℕ) [a.AtLeastTwo] :
((ofNat(a) : ℚ) : ℝ) = (ofNat(a) : ℝ) := rfl
end Mathlib.Tactic.Rify
|
Tauto.lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, David Renshaw
-/
import Mathlib.Tactic.Tauto
import Mathlib.Tactic.SplitIfs
import Mathlib.Data.Part
set_option autoImplicit true
section tauto₀
variable (p q r : Prop)
variable (h : p ∧ q ∨ p ∧ r)
example : p ∧ p := by tauto
end tauto₀
section tauto₁
variable (α : Type) (p q r : α → Prop)
variable (h : (∃ x, p x ∧ q x) ∨ (∃ x, p x ∧ r x))
example : ∃ x, p x := by tauto
end tauto₁
section tauto₂
variable (α : Type)
variable (x : α)
variable (p q r : α → Prop)
variable (h₀ : (∀ x, p x → q x → r x) ∨ r x)
variable (h₁ : p x)
variable (h₂ : q x)
example : ∃ x, r x := by tauto
end tauto₂
section tauto₃
example (p : Prop) : p ∧ True ↔ p := by tauto
example (p : Prop) : p ∨ False ↔ p := by tauto
example (p q : Prop) (h : p ≠ q) : ¬ p ↔ q := by tauto
example (p q : Prop) (h : ¬ p = q) : ¬ p ↔ q := by tauto
example (p q r : Prop) : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (r ∨ p ∨ r) := by tauto
example (p q r : Prop) : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (r ∨ p ∨ r) := by tauto
example (p q : Prop) (h : ¬ (p ↔ q)) (h' : ¬ p) : q := by tauto
example (p q : Prop) (h : ¬ (p ↔ q)) (h' : p) : ¬ q := by tauto
example (p q : Prop) (h : ¬ (p ↔ q)) (h' : q) : ¬ p := by tauto
example (p q : Prop) (h : ¬ (p ↔ q)) (h' : ¬ q) : p := by tauto
example (p q : Prop) (h : ¬ (p ↔ q)) (h' : ¬ q) (h'' : ¬ p) : False := by
tauto
example (p q r : Prop) (h : p ↔ q) (h' : r ↔ q) (h'' : ¬ r) : ¬ p := by
tauto
example (p q r : Prop) (h : p ↔ q) (h' : r ↔ q) : p ↔ r := by tauto
example (p q r : Prop) (h : ¬ p = q) (h' : r = q) : p ↔ ¬ r := by tauto
example (p : Prop) : p → ¬ (p → ¬ p) := by tauto
example (p : Prop) (em : p ∨ ¬ p) : ¬ (p ↔ ¬ p) := by tauto
-- reported at https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/weird.20tactic.20bug/near/370505747
open scoped Classical in
example (hp : p) (hq : q) : (if p ∧ q then 1 else 0) = 1 := by
-- split_ifs creates a hypothesis with a type that's a metavariable
split_ifs
· rfl
· tauto
example (hp : p) (hq : q) (h : ¬ (p ∧ q)) : False := by
-- causes `h'` to have a type that's a metavariable:
have h' := h
clear h
tauto
example (p : Prop) (h : False) : p := by
-- causes `h'` to have a type that's a metavariable:
have h' := h
clear h
tauto
example (hp : p) (hq : q) : p ∧ q := by
-- causes goal to have a type that's a metavariable:
suffices h : ?foo by exact h
tauto
-- Checking `tauto` can deal with annotations:
example (hp : ¬ p) (hq : ¬ (q ↔ p) := by sorry) : q := by
tauto
example (P : Nat → Prop) (n : Nat) : P n → n = 7 ∨ n = 0 ∨ ¬ (n = 7 ∨ n = 0) ∧ P n := by
tauto
section implementation_detail_ldecl
variable (a b c : Nat)
/--
Mathlib.Tactic.Tauto.distribNot must ignore any LocalDecl where isImplementationDetail
is true. Otherwise, this example yields an error saying "well-founded recursion cannot
be used".
-/
example : ¬(¬a ≤ b ∧ a ≤ c ∨ ¬a ≤ c ∧ a ≤ b) ↔ a ≤ b ∧ a ≤ c ∨ ¬a ≤ c ∧ ¬a ≤ b := by
tauto
end implementation_detail_ldecl
section modulo_symmetry
variable {p q r : Prop} {α : Type} {x y : α}
variable (h : x = y)
variable (h'' : (p ∧ q ↔ q ∨ r) ↔ (r ∧ p ↔ r ∨ q))
-- Currently this hits a "failed to show termination error"
-- because it erroneously used a recursive hypothesis.
-- See https://github.com/leanprover-community/mathlib4/issues/1061 and
-- https://github.com/leanprover/lean4/issues/1963
-- example (h' : ¬ y = x) : p ∧ q := by tauto
/-
example (h' : p ∧ ¬ y = x) : p ∧ q := by tauto
example : y = x := by tauto
example (h' : ¬ x = y) : p ∧ q := by tauto
example : x = y := by tauto
-/
end modulo_symmetry
section pair_eq_pair_iff
variable (α : Type)
variable (x y z w : α)
-- This example is taken from pair_eq_pair_iff in Data.Set.Basic.
-- It currently doesn't work because `tauto` does not apply `symm`.
--example : ((x = z ∨ x = w) ∧ (y = z ∨ y = w)) ∧
-- (z = x ∨ z = y) ∧ (w = x ∨ w = y) → x = z ∧ y = w ∨ x = w ∧ y = z := by
-- tauto
end pair_eq_pair_iff
end tauto₃
/-
section closer
example {α : Type*} {β : Type*} (a : α) {s_1 : Set α} :
(∃ (a_1 : α), a_1 = a ∨ a_1 ∈ s_1) := by
tauto {closer := `[simp]}
variable {p q r : Prop} {α : Type} {x y z w : α}
variable (h : x = y) (h₁ : y = z) (h₂ : z = w)
variable (h'' : (p ∧ q ↔ q ∨ r) ↔ (r ∧ p ↔ r ∨ q))
-- include h h₁ h₂ h''
example : (((r ∧ p ↔ r ∨ q) ∧ (q ∨ r)) → (p ∧ (x = w) ∧ (¬ x = w → p ∧ q ∧ r))) := by
tauto {closer := `[cc]}
end closer
-/
/- Zulip discussion:
https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/tauto!.20fails.20on.20ne
-/
example {x y : Nat} (h : ¬x ≠ y) : x = y := by
tauto
/-
Test the case where the goal depends on a hypothesis
https://github.com/leanprover-community/mathlib4/issues/10590
-/
section goal_depends_on_hyp
open Part
example (p : Prop) (o : Part α) (h : p → o.Dom) (a : α) :
a ∈ restrict p o h ↔ p ∧ a ∈ o := by
dsimp [restrict, mem_eq]
tauto
end goal_depends_on_hyp
|
poly.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice.
From mathcomp Require Import fintype bigop finset tuple div ssralg.
From mathcomp Require Import countalg binomial.
(******************************************************************************)
(* This file provides a library for univariate polynomials over ring *)
(* structures; it also provides an extended theory for polynomials whose *)
(* coefficients range over commutative rings and integral domains. *)
(* *)
(* {poly R} == the type of polynomials with coefficients of type R, *)
(* represented as lists with a non zero last element *)
(* (big endian representation); the coefficient type R *)
(* must have a canonical nzRingType structure cR. In *)
(* fact {poly R} denotes the concrete type polynomial *)
(* cR; R is just a phantom argument that lets type *)
(* inferencereconstruct the (hidden) nzRingType *)
(* structure cR. *)
(* p : seq R == the big-endian sequence of coefficients of p, via *)
(* the coercion polyseq : polynomial >-> seq. *)
(* Poly s == the polynomial with coefficient sequence s (ignoring *)
(* trailing zeroes). *)
(* \poly_(i < n) E(i) == the polynomial of degree at most n - 1 whose *)
(* coefficients are given by the general term E(i) *)
(* 0, 1, - p, p + q, == the usual ring operations: {poly R} has a canonical *)
(* p * q, p ^+ n, ... nzRingType structure, which is commutative / integral*)
(* when R is commutative / integral, respectively. *)
(* polyC c, c%:P == the constant polynomial c *)
(* 'X == the (unique) variable *)
(* 'X^n == a power of 'X; 'X^0 is 1, 'X^1 is convertible to 'X *)
(* p`_i == the coefficient of 'X^i in p; this is in fact just *)
(* the ring_scope notation generic seq-indexing using *)
(* nth 0%R, combined with the polyseq coercion. *)
(* *** The multi-rule coefE simplifies p`_i *)
(* coefp i == the linear function p |-> p`_i (self-exapanding). *)
(* size p == 1 + the degree of p, or 0 if p = 0 (this is the *)
(* generic seq function combined with polyseq). *)
(* lead_coef p == the coefficient of the highest monomial in p, or 0 *)
(* if p = 0 (hence lead_coef p = 0 iff p = 0) *)
(* p \is monic <=> lead_coef p == 1 (0 is not monic). *)
(* p \is a polyOver S <=> the coefficients of p satisfy S; S should have a *)
(* key that should be (at least) an addrPred. *)
(* p.[x] == the evaluation of a polynomial p at a point x using *)
(* the Horner scheme *)
(* *** The multi-rule hornerE (resp., hornerE_comm) unwinds *)
(* horner evaluation of a polynomial expression (resp., *)
(* in a non commutative ring, with side conditions). *)
(* p^`() == formal derivative of p *)
(* p^`(n) == formal n-derivative of p *)
(* p^`N(n) == formal n-derivative of p divided by n! *)
(* p \Po q == polynomial composition; because this is naturally a *)
(* a linear morphism in the first argument, this *)
(* notation is transposed (q comes before p for redex *)
(* selection, etc). *)
(* := \sum(i < size p) p`_i *: q ^+ i *)
(* odd_poly p == monomials of odd degree of p *)
(* even_poly p == monomials of even degree of p *)
(* take_poly n p == polynomial p without its monomials of degree >= n *)
(* drop_poly n p == polynomial p divided by X^n *)
(* comm_poly p x == x and p.[x] commute; this is a sufficient condition *)
(* for evaluating (q * p).[x] as q.[x] * p.[x] when R *)
(* is not commutative. *)
(* comm_coef p x == x commutes with all the coefficients of p (clearly, *)
(* this implies comm_poly p x). *)
(* root p x == x is a root of p, i.e., p.[x] = 0 *)
(* n.-unity_root x == x is an nth root of unity, i.e., a root of 'X^n - 1 *)
(* n.-primitive_root x == x is a primitive nth root of unity, i.e., n is the *)
(* least positive integer m > 0 such that x ^+ m = 1. *)
(* *** The submodule poly.UnityRootTheory can be used to *)
(* import selectively the part of the theory of roots *)
(* of unity that doesn't mention polynomials explicitly *)
(* map_poly f p == the image of the polynomial by the function f (which *)
(* (locally, p^f) is usually a ring morphism). *)
(* p^:P == p lifted to {poly {poly R}} (:= map_poly polyC p). *)
(* commr_rmorph f u == u commutes with the image of f (i.e., with all f x). *)
(* horner_morph cfu == given cfu : commr_rmorph f u, the function mapping p *)
(* to the value of map_poly f p at u; this is a ring *)
(* morphism from {poly R} to the codomain of f when f *)
(* is a ring morphism. *)
(* horner_eval u == the function mapping p to p.[u]; this function can *)
(* only be used for u in a commutative ring, so it is *)
(* always a linear ring morphism from {poly R} to R. *)
(* horner_alg a == given a in some R-algebra A, the function evaluating *)
(* a polynomial p at a; it is always a linear ring *)
(* morphism from {poly R} to A. *)
(* diff_roots x y == x and y are distinct roots; if R is a field, this *)
(* just means x != y, but this concept is generalized *)
(* to the case where R is only a ring with units (i.e., *)
(* a unitRingType); in which case it means that x and y *)
(* commute, and that the difference x - y is a unit *)
(* (i.e., has a multiplicative inverse) in R. *)
(* to just x != y). *)
(* uniq_roots s == s is a sequence or pairwise distinct roots, in the *)
(* sense of diff_roots p above. *)
(* *** We only show that these operations and properties are transferred by *)
(* morphisms whose domain is a field (thus ensuring injectivity). *)
(* We prove the factor_theorem, and the max_poly_roots inequality relating *)
(* the number of distinct roots of a polynomial and its size. *)
(* The some polynomial lemmas use following suffix interpretation : *)
(* C - constant polynomial (as in polyseqC : a%:P = nseq (a != 0) a). *)
(* X - the polynomial variable 'X (as in coefX : 'X`_i = (i == 1%N)). *)
(* Xn - power of 'X (as in monicXn : monic 'X^n). *)
(* *)
(* Pdeg2.Field (exported by the present library) : theory of the degree 2 *)
(* polynomials. *)
(* Pdeg2.FieldMonic : theory of Pdeg2.Field specialized to monic polynomials. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope unity_root_scope.
Import GRing.Theory.
Local Open Scope ring_scope.
Reserved Notation "{ 'poly' T }" (format "{ 'poly' T }").
Reserved Notation "c %:P" (format "c %:P").
Reserved Notation "p ^:P" (format "p ^:P").
Reserved Notation "'X".
Reserved Notation "''X^' n" (at level 1, format "''X^' n").
Reserved Notation "\poly_ ( i < n ) E"
(at level 34, E at level 36, i, n at level 50,
format "\poly_ ( i < n ) E").
Reserved Notation "p \Po q" (at level 50).
Reserved Notation "p ^`N ( n )" (format "p ^`N ( n )").
Reserved Notation "n .-unity_root" (format "n .-unity_root").
Reserved Notation "n .-primitive_root" (format "n .-primitive_root").
Local Notation simp := Monoid.simpm.
Section Polynomial.
Variable R : nzSemiRingType.
(* Defines a polynomial as a sequence with <> 0 last element *)
Record polynomial := Polynomial {polyseq :> seq R; _ : last 1 polyseq != 0}.
HB.instance Definition _ := [isSub for polyseq].
HB.instance Definition _ := [Choice of polynomial by <:].
Lemma poly_inj : injective polyseq. Proof. exact: val_inj. Qed.
Definition coefp i (p : polynomial) := p`_i.
End Polynomial.
(* We need to break off the section here to let the Bind Scope directives *)
(* take effect. *)
Bind Scope ring_scope with polynomial.
Arguments polynomial R%_type.
Arguments polyseq {R} p%_R.
Arguments poly_inj {R} [p1%_R p2%_R] : rename.
Arguments coefp {R} i%_N / p%_R.
Notation "{ 'poly' T }" := (polynomial T) : type_scope.
Section SemiPolynomialTheory.
Variable R : nzSemiRingType.
Implicit Types (a b c x y z : R) (p q r d : {poly R}).
Definition lead_coef p := p`_(size p).-1.
Lemma lead_coefE p : lead_coef p = p`_(size p).-1. Proof. by []. Qed.
Definition poly_nil := @Polynomial R [::] (oner_neq0 R).
Definition polyC c : {poly R} := insubd poly_nil [:: c].
Local Notation "c %:P" := (polyC c).
(* Remember the boolean (c != 0) is coerced to 1 if true and 0 if false *)
Lemma polyseqC c : c%:P = nseq (c != 0) c :> seq R.
Proof. by rewrite val_insubd /=; case: (c == 0). Qed.
Lemma size_polyC c : size c%:P = (c != 0).
Proof. by rewrite polyseqC size_nseq. Qed.
Lemma coefC c i : c%:P`_i = if i == 0 then c else 0.
Proof. by rewrite polyseqC; case: i => [|[]]; case: eqP. Qed.
Lemma polyCK : cancel polyC (coefp 0).
Proof. by move=> c; rewrite [coefp 0 _]coefC. Qed.
Lemma polyC_inj : injective polyC.
Proof. by move=> c1 c2 eqc12; have:= coefC c2 0; rewrite -eqc12 coefC. Qed.
Lemma lead_coefC c : lead_coef c%:P = c.
Proof. by rewrite /lead_coef polyseqC; case: eqP. Qed.
(* Extensional interpretation (poly <=> nat -> R) *)
Lemma polyP p q : nth 0 p =1 nth 0 q <-> p = q.
Proof.
split=> [eq_pq | -> //]; apply: poly_inj.
without loss lt_pq: p q eq_pq / size p < size q.
move=> IH; case: (ltngtP (size p) (size q)); try by move/IH->.
by move/(@eq_from_nth _ 0); apply.
case: q => q nz_q /= in lt_pq eq_pq *; case/eqP: nz_q.
by rewrite (last_nth 0) -(subnKC lt_pq) /= -eq_pq nth_default ?leq_addr.
Qed.
Lemma size1_polyC p : size p <= 1 -> p = (p`_0)%:P.
Proof.
move=> le_p_1; apply/polyP=> i; rewrite coefC.
by case: i => // i; rewrite nth_default // (leq_trans le_p_1).
Qed.
(* Builds a polynomial by extension. *)
Definition cons_poly c p : {poly R} :=
if p is Polynomial ((_ :: _) as s) ns then
@Polynomial R (c :: s) ns
else c%:P.
Lemma polyseq_cons c p :
cons_poly c p = (if ~~ nilp p then c :: p else c%:P) :> seq R.
Proof. by case: p => [[]]. Qed.
Lemma size_cons_poly c p :
size (cons_poly c p) = (if nilp p && (c == 0) then 0 else (size p).+1).
Proof. by case: p => [[|c' s] _] //=; rewrite size_polyC; case: eqP. Qed.
Lemma coef_cons c p i : (cons_poly c p)`_i = if i == 0 then c else p`_i.-1.
Proof.
by case: p i => [[|c' s] _] [] //=; rewrite polyseqC; case: eqP => //= _ [].
Qed.
(* Build a polynomial directly from a list of coefficients. *)
Definition Poly := foldr cons_poly 0%:P.
Lemma PolyK c s : last c s != 0 -> Poly s = s :> seq R.
Proof.
case: s => {c}/= [_ |c s]; first by rewrite polyseqC eqxx.
elim: s c => /= [|a s IHs] c nz_c; rewrite polyseq_cons ?{}IHs //.
by rewrite !polyseqC !eqxx nz_c.
Qed.
Lemma polyseqK p : Poly p = p.
Proof. by apply: poly_inj; apply: PolyK (valP p). Qed.
Lemma size_Poly s : size (Poly s) <= size s.
Proof.
elim: s => [|c s IHs] /=; first by rewrite polyseqC eqxx.
by rewrite polyseq_cons; case: ifP => // _; rewrite size_polyC; case: (~~ _).
Qed.
Lemma coef_Poly s i : (Poly s)`_i = s`_i.
Proof.
by elim: s i => [|c s IHs] /= [|i]; rewrite !(coefC, eqxx, coef_cons) /=.
Qed.
(* Build a polynomial from an infinite sequence of coefficients and a bound. *)
Definition poly_expanded_def n E := Poly (mkseq E n).
Fact poly_key : unit. Proof. by []. Qed.
Definition poly := locked_with poly_key poly_expanded_def.
Canonical poly_unlockable := [unlockable fun poly].
Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)).
Lemma polyseq_poly n E :
E n.-1 != 0 -> \poly_(i < n) E i = mkseq [eta E] n :> seq R.
Proof.
rewrite unlock; case: n => [|n] nzEn; first by rewrite polyseqC eqxx.
by rewrite (@PolyK 0) // -nth_last nth_mkseq size_mkseq.
Qed.
Lemma size_poly n E : size (\poly_(i < n) E i) <= n.
Proof. by rewrite unlock (leq_trans (size_Poly _)) ?size_mkseq. Qed.
Lemma size_poly_eq n E : E n.-1 != 0 -> size (\poly_(i < n) E i) = n.
Proof. by move/polyseq_poly->; apply: size_mkseq. Qed.
Lemma coef_poly n E k : (\poly_(i < n) E i)`_k = (if k < n then E k else 0).
Proof.
rewrite unlock coef_Poly.
have [lt_kn | le_nk] := ltnP k n; first by rewrite nth_mkseq.
by rewrite nth_default // size_mkseq.
Qed.
Lemma lead_coef_poly n E :
n > 0 -> E n.-1 != 0 -> lead_coef (\poly_(i < n) E i) = E n.-1.
Proof.
by case: n => // n _ nzE; rewrite /lead_coef size_poly_eq // coef_poly leqnn.
Qed.
Lemma coefK p : \poly_(i < size p) p`_i = p.
Proof.
by apply/polyP=> i; rewrite coef_poly; case: ltnP => // /(nth_default 0)->.
Qed.
(* Nmodule structure for polynomial *)
Definition add_poly_def p q := \poly_(i < maxn (size p) (size q)) (p`_i + q`_i).
Fact add_poly_key : unit. Proof. by []. Qed.
Definition add_poly := locked_with add_poly_key add_poly_def.
Canonical add_poly_unlockable := [unlockable fun add_poly].
Fact coef_add_poly p q i : (add_poly p q)`_i = p`_i + q`_i.
Proof.
rewrite unlock coef_poly; case: leqP => //.
by rewrite geq_max => /andP[le_p_i le_q_i]; rewrite !nth_default ?add0r.
Qed.
Fact add_polyA : associative add_poly.
Proof. by move=> p q r; apply/polyP=> i; rewrite !coef_add_poly addrA. Qed.
Fact add_polyC : commutative add_poly.
Proof. by move=> p q; apply/polyP=> i; rewrite !coef_add_poly addrC. Qed.
Fact add_poly0 : left_id 0%:P add_poly.
Proof.
by move=> p; apply/polyP=> i; rewrite coef_add_poly coefC if_same add0r.
Qed.
HB.instance Definition _ := GRing.isNmodule.Build (polynomial R)
add_polyA add_polyC add_poly0.
(* Properties of the zero polynomial *)
Lemma polyC0 : 0%:P = 0 :> {poly R}. Proof. by []. Qed.
Lemma polyseq0 : (0 : {poly R}) = [::] :> seq R.
Proof. by rewrite polyseqC eqxx. Qed.
Lemma size_poly0 : size (0 : {poly R}) = 0%N.
Proof. by rewrite polyseq0. Qed.
Lemma coef0 i : (0 : {poly R})`_i = 0.
Proof. by rewrite coefC if_same. Qed.
Lemma lead_coef0 : lead_coef 0 = 0 :> R. Proof. exact: lead_coefC. Qed.
Lemma size_poly_eq0 p : (size p == 0) = (p == 0).
Proof. by rewrite size_eq0 -polyseq0. Qed.
Lemma size_poly_leq0 p : (size p <= 0) = (p == 0).
Proof. by rewrite leqn0 size_poly_eq0. Qed.
Lemma size_poly_leq0P p : reflect (p = 0) (size p <= 0).
Proof. by apply: (iffP idP); rewrite size_poly_leq0; move/eqP. Qed.
Lemma size_poly_gt0 p : (0 < size p) = (p != 0).
Proof. by rewrite lt0n size_poly_eq0. Qed.
Lemma gt_size_poly_neq0 p n : (size p > n)%N -> p != 0.
Proof. by move=> /(leq_ltn_trans _) h; rewrite -size_poly_eq0 lt0n_neq0 ?h. Qed.
Lemma nil_poly p : nilp p = (p == 0).
Proof. exact: size_poly_eq0. Qed.
Lemma poly0Vpos p : {p = 0} + {size p > 0}.
Proof. by rewrite lt0n size_poly_eq0; case: eqVneq; [left | right]. Qed.
Lemma polySpred p : p != 0 -> size p = (size p).-1.+1.
Proof. by rewrite -size_poly_eq0 -lt0n => /prednK. Qed.
Lemma lead_coef_eq0 p : (lead_coef p == 0) = (p == 0).
Proof.
rewrite -nil_poly /lead_coef nth_last.
by case: p => [[|x s] /= /negbTE // _]; rewrite eqxx.
Qed.
Lemma polyC_eq0 (c : R) : (c%:P == 0) = (c == 0).
Proof. by rewrite -nil_poly polyseqC; case: (c == 0). Qed.
Lemma size_poly1P p : reflect (exists2 c, c != 0 & p = c%:P) (size p == 1).
Proof.
apply: (iffP eqP) => [pC | [c nz_c ->]]; last by rewrite size_polyC nz_c.
have def_p: p = (p`_0)%:P by rewrite -size1_polyC ?pC.
by exists p`_0; rewrite // -polyC_eq0 -def_p -size_poly_eq0 pC.
Qed.
Lemma size_polyC_leq1 (c : R) : (size c%:P <= 1)%N.
Proof. by rewrite size_polyC; case: (c == 0). Qed.
Lemma leq_sizeP p i : reflect (forall j, i <= j -> p`_j = 0) (size p <= i).
Proof.
apply: (iffP idP) => [hp j hij| hp].
by apply: nth_default; apply: leq_trans hij.
case: (eqVneq p) (lead_coef_eq0 p) => [->|p0]; first by rewrite size_poly0.
rewrite leqNgt; apply/contraFN => hs.
by apply/eqP/hp; rewrite -ltnS (ltn_predK hs).
Qed.
(* Size, leading coef, morphism properties of coef *)
Lemma coefD p q i : (p + q)`_i = p`_i + q`_i.
Proof. exact: coef_add_poly. Qed.
Lemma polyCD : {morph polyC : a b / a + b}.
Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefD !coefC ?addr0. Qed.
Lemma size_polyD p q : size (p + q) <= maxn (size p) (size q).
Proof. by rewrite -[+%R]/add_poly unlock; exact: size_poly. Qed.
Lemma size_polyDl p q : size p > size q -> size (p + q) = size p.
Proof.
move=> ltqp; rewrite -[+%R]/add_poly unlock size_poly_eq (maxn_idPl (ltnW _))//.
by rewrite addrC nth_default ?simp ?nth_last //; case: p ltqp => [[]].
Qed.
Lemma size_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) :
size (\sum_(i <- r | P i) F i) <= \max_(i <- r | P i) size (F i).
Proof.
elim/big_rec2: _ => [|i p q _ IHp]; first by rewrite size_poly0.
by rewrite -(maxn_idPr IHp) maxnA leq_max size_polyD.
Qed.
Lemma lead_coefDl p q : size p > size q -> lead_coef (p + q) = lead_coef p.
Proof.
move=> ltqp; rewrite /lead_coef coefD size_polyDl //.
by rewrite addrC nth_default ?simp // -ltnS (ltn_predK ltqp).
Qed.
Lemma lead_coefDr p q : size q > size p -> lead_coef (p + q) = lead_coef q.
Proof. by move/lead_coefDl<-; rewrite addrC. Qed.
(* Polynomial semiring structure. *)
Definition mul_poly_def p q :=
\poly_(i < (size p + size q).-1) (\sum_(j < i.+1) p`_j * q`_(i - j)).
Fact mul_poly_key : unit. Proof. by []. Qed.
Definition mul_poly := locked_with mul_poly_key mul_poly_def.
Canonical mul_poly_unlockable := [unlockable fun mul_poly].
Fact coef_mul_poly p q i :
(mul_poly p q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N.
Proof.
rewrite unlock coef_poly -subn1 ltn_subRL add1n; case: leqP => // le_pq_i1.
rewrite big1 // => j _; have [lq_q_ij | gt_q_ij] := leqP (size q) (i - j).
by rewrite [q`__]nth_default ?mulr0.
rewrite nth_default ?mul0r // -(leq_add2r (size q)) (leq_trans le_pq_i1) //.
by rewrite -leq_subLR -subnSK.
Qed.
Fact coef_mul_poly_rev p q i :
(mul_poly p q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j.
Proof.
rewrite coef_mul_poly (reindex_inj rev_ord_inj) /=.
by apply: eq_bigr => j _; rewrite (sub_ordK j).
Qed.
Fact mul_polyA : associative mul_poly.
Proof.
move=> p q r; apply/polyP=> i; rewrite coef_mul_poly coef_mul_poly_rev.
pose coef3 j k := p`_j * (q`_(i - j - k)%N * r`_k).
transitivity (\sum_(j < i.+1) \sum_(k < i.+1 | k <= i - j) coef3 j k).
apply: eq_bigr => /= j _; rewrite coef_mul_poly_rev big_distrr /=.
by rewrite (big_ord_narrow_leq (leq_subr _ _)).
rewrite (exchange_big_dep predT) //=; apply: eq_bigr => k _.
transitivity (\sum_(j < i.+1 | j <= i - k) coef3 j k).
apply: eq_bigl => j; rewrite -ltnS -(ltnS j) -!subSn ?leq_ord //.
by rewrite -subn_gt0 -(subn_gt0 j) -!subnDA addnC.
rewrite (big_ord_narrow_leq (leq_subr _ _)) coef_mul_poly big_distrl /=.
by apply: eq_bigr => j _; rewrite /coef3 -!subnDA addnC mulrA.
Qed.
Fact mul_1poly : left_id 1%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Fact mul_poly1 : right_id 1%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Fact mul_polyDl : left_distributive mul_poly +%R.
Proof.
move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split.
by apply: eq_bigr => j _; rewrite coefD mulrDl.
Qed.
Fact mul_polyDr : right_distributive mul_poly +%R.
Proof.
move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split.
by apply: eq_bigr => j _; rewrite coefD mulrDr.
Qed.
Fact mul_0poly : left_zero 0%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP.
Qed.
Fact mul_poly0 : right_zero 0%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP.
Qed.
Fact poly1_neq0 : 1%:P != 0 :> {poly R}.
Proof. by rewrite polyC_eq0 oner_neq0. Qed.
HB.instance Definition _ := GRing.Nmodule_isNzSemiRing.Build (polynomial R)
mul_polyA mul_1poly mul_poly1 mul_polyDl mul_polyDr mul_0poly mul_poly0
poly1_neq0.
Lemma polyC1 : 1%:P = 1 :> {poly R}. Proof. by []. Qed.
Lemma polyseq1 : (1 : {poly R}) = [:: 1] :> seq R.
Proof. by rewrite polyseqC oner_neq0. Qed.
Lemma size_poly1 : size (1 : {poly R}) = 1.
Proof. by rewrite polyseq1. Qed.
Lemma coef1 i : (1 : {poly R})`_i = (i == 0)%:R.
Proof. by case: i => [|i]; rewrite polyseq1 /= ?nth_nil. Qed.
Lemma lead_coef1 : lead_coef 1 = 1 :> R. Proof. exact: lead_coefC. Qed.
Lemma coefM p q i : (p * q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N.
Proof. exact: coef_mul_poly. Qed.
Lemma coefMr p q i : (p * q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j.
Proof. exact: coef_mul_poly_rev. Qed.
Lemma coef0M p q : (p * q)`_0 = p`_0 * q`_0.
Proof. by rewrite coefM big_ord1. Qed.
Lemma coef0_prod I rI (F : I -> {poly R}) P :
(\prod_(i <- rI| P i) F i)`_0 = \prod_(i <- rI | P i) (F i)`_0.
Proof. by apply: (big_morph _ coef0M); rewrite coef1 eqxx. Qed.
Lemma size_polyMleq p q : size (p * q) <= (size p + size q).-1.
Proof. by rewrite -[*%R]/mul_poly unlock size_poly. Qed.
Lemma mul_lead_coef p q :
lead_coef p * lead_coef q = (p * q)`_(size p + size q).-2.
Proof.
pose dp := (size p).-1; pose dq := (size q).-1.
have [-> | nz_p] := eqVneq p 0; first by rewrite lead_coef0 !mul0r coef0.
have [-> | nz_q] := eqVneq q 0; first by rewrite lead_coef0 !mulr0 coef0.
have ->: (size p + size q).-2 = (dp + dq)%N.
by do 2!rewrite polySpred // addSn addnC.
have lt_p_pq: dp < (dp + dq).+1 by rewrite ltnS leq_addr.
rewrite coefM (bigD1 (Ordinal lt_p_pq)) ?big1 ?simp ?addKn //= => i.
rewrite -val_eqE neq_ltn /= => /orP[lt_i_p | gt_i_p]; last first.
by rewrite nth_default ?mul0r //; rewrite -polySpred in gt_i_p.
rewrite [q`__]nth_default ?mulr0 //= -subSS -{1}addnS -polySpred //.
by rewrite addnC -addnBA ?leq_addr.
Qed.
Lemma size_proper_mul p q :
lead_coef p * lead_coef q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
apply: contraNeq; rewrite mul_lead_coef eqn_leq size_polyMleq -ltnNge => lt_pq.
by rewrite nth_default // -subn1 -(leq_add2l 1) -leq_subLR leq_sub2r.
Qed.
Lemma lead_coef_proper_mul p q :
let c := lead_coef p * lead_coef q in c != 0 -> lead_coef (p * q) = c.
Proof. by move=> /= nz_c; rewrite mul_lead_coef -size_proper_mul. Qed.
Lemma size_poly_prod_leq (I : finType) (P : pred I) (F : I -> {poly R}) :
size (\prod_(i | P i) F i) <= (\sum_(i | P i) size (F i)).+1 - #|P|.
Proof.
rewrite -sum1_card.
elim/big_rec3: _ => [|i n m p _ IHp]; first by rewrite size_poly1.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0.
rewrite (leq_trans (size_polyMleq _ _)) // subnS -!subn1 leq_sub2r //.
rewrite -addnS -addnBA ?leq_add2l // ltnW // -subn_gt0 (leq_trans _ IHp) //.
by rewrite polySpred.
Qed.
Lemma coefCM c p i : (c%:P * p)`_i = c * p`_i.
Proof.
rewrite coefM big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Lemma coefMC c p i : (p * c%:P)`_i = p`_i * c.
Proof.
rewrite coefMr big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Lemma polyCM : {morph polyC : a b / a * b}.
Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefCM !coefC ?simp. Qed.
Lemma size_poly_exp_leq p n : size (p ^+ n) <= ((size p).-1 * n).+1.
Proof.
elim: n => [|n IHn]; first by rewrite size_poly1.
have [-> | nzp] := poly0Vpos p; first by rewrite exprS mul0r size_poly0.
rewrite exprS (leq_trans (size_polyMleq _ _)) //.
by rewrite -{1}(prednK nzp) mulnS -addnS leq_add2l.
Qed.
End SemiPolynomialTheory.
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyD`")]
Notation size_add := size_polyD (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyDl`")]
Notation size_addl := size_polyDl (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyMleq`")]
Notation size_mul_leq := size_polyMleq (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_prod_leq`")]
Notation size_prod_leq := size_poly_prod_leq (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_exp_leq`")]
Notation size_exp_leq := size_poly_exp_leq (only parsing).
Section PolynomialTheory.
Variable R : nzRingType.
Implicit Types (a b c x y z : R) (p q r d : {poly R}).
Local Notation "c %:P" := (polyC c).
Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)).
(* Zmodule structure for polynomial *)
Definition opp_poly_def p := \poly_(i < size p) - p`_i.
Fact opp_poly_key : unit. Proof. by []. Qed.
Definition opp_poly := locked_with opp_poly_key opp_poly_def.
Canonical opp_poly_unlockable := [unlockable fun opp_poly].
Fact coef_opp_poly p i : (opp_poly p)`_i = - p`_i.
Proof.
rewrite unlock coef_poly /=.
by case: leqP => // le_p_i; rewrite nth_default ?oppr0.
Qed.
Fact add_polyN : left_inverse 0%:P opp_poly (@add_poly _).
Proof.
move=> p; apply/polyP=> i.
by rewrite coef_add_poly coef_opp_poly coefC if_same addNr.
Qed.
HB.instance Definition _ := GRing.Nmodule_isZmodule.Build (polynomial R)
add_polyN.
(* Size, leading coef, morphism properties of coef *)
Lemma coefN p i : (- p)`_i = - p`_i.
Proof. exact: coef_opp_poly. Qed.
Lemma coefB p q i : (p - q)`_i = p`_i - q`_i.
Proof. by rewrite coefD coefN. Qed.
HB.instance Definition _ i := GRing.isZmodMorphism.Build {poly R} R (coefp i)
(fun p => (coefB p)^~ i).
Lemma coefMn p n i : (p *+ n)`_i = p`_i *+ n.
Proof. exact: (raddfMn (coefp i)). Qed.
Lemma coefMNn p n i : (p *- n)`_i = p`_i *- n.
Proof. by rewrite coefN coefMn. Qed.
Lemma coef_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) k :
(\sum_(i <- r | P i) F i)`_k = \sum_(i <- r | P i) (F i)`_k.
Proof. exact: (raddf_sum (coefp k)). Qed.
Lemma polyCN : {morph (@polyC R) : c / - c}.
Proof. by move=> c; apply/polyP=> [[|i]]; rewrite coefN !coefC ?oppr0. Qed.
Lemma polyCB : {morph (@polyC R) : a b / a - b}.
Proof. by move=> a b; rewrite polyCD polyCN. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build R {poly R} (@polyC _) polyCB.
Lemma polyCMn n : {morph (@polyC R) : c / c *+ n}. Proof. exact: raddfMn. Qed.
Lemma size_polyN p : size (- p) = size p.
Proof.
by apply/eqP; rewrite eqn_leq -{3}(opprK p) -[-%R]/opp_poly unlock !size_poly.
Qed.
Lemma lead_coefN p : lead_coef (- p) = - lead_coef p.
Proof. by rewrite /lead_coef size_polyN coefN. Qed.
(* Polynomial ring structure. *)
Fact polyC_is_monoid_morphism : monoid_morphism (@polyC R).
Proof. by split; last apply: polyCM. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `polyC_is_monoid_morphism` instead")]
Definition polyC_multiplicative :=
(fun g => (g.2, g.1)) polyC_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build R {poly R} (@polyC R)
polyC_is_monoid_morphism.
Lemma polyC_exp n : {morph (@polyC R) : c / c ^+ n}. Proof. exact: rmorphXn. Qed.
Lemma polyC_natr n : n%:R%:P = n%:R :> {poly R}.
Proof. by rewrite rmorph_nat. Qed.
Lemma pchar_poly : [pchar {poly R}] =i [pchar R].
Proof.
move=> p; rewrite !inE; congr (_ && _).
apply/eqP/eqP=> [/(congr1 val) /=|]; last by rewrite -polyC_natr => ->.
by rewrite polyseq0 -polyC_natr polyseqC; case: eqP.
Qed.
Lemma size_Msign p n : size ((-1) ^+ n * p) = size p.
Proof.
by rewrite -signr_odd; case: (odd n); rewrite ?mul1r// mulN1r size_polyN.
Qed.
Fact coefp0_is_monoid_morphism : monoid_morphism (coefp 0 : {poly R} -> R).
Proof.
split=> [|p q]; first by rewrite polyCK.
by rewrite [coefp 0 _]coefM big_ord_recl big_ord0 addr0.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `coefp0_is_monoid_morphism` instead")]
Definition coefp0_multiplicative :=
(fun g => (g.2, g.1)) coefp0_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly R} R (coefp 0)
coefp0_is_monoid_morphism.
(* Algebra structure of polynomials. *)
Definition scale_poly_def a (p : {poly R}) := \poly_(i < size p) (a * p`_i).
Fact scale_poly_key : unit. Proof. by []. Qed.
Definition scale_poly := locked_with scale_poly_key scale_poly_def.
Canonical scale_poly_unlockable := [unlockable fun scale_poly].
Fact scale_polyE a p : scale_poly a p = a%:P * p.
Proof.
apply/polyP=> n; rewrite unlock coef_poly coefCM.
by case: leqP => // le_p_n; rewrite nth_default ?mulr0.
Qed.
Fact scale_polyA a b p : scale_poly a (scale_poly b p) = scale_poly (a * b) p.
Proof. by rewrite !scale_polyE mulrA polyCM. Qed.
Fact scale_1poly : left_id 1 scale_poly.
Proof. by move=> p; rewrite scale_polyE mul1r. Qed.
Fact scale_polyDr a : {morph scale_poly a : p q / p + q}.
Proof. by move=> p q; rewrite !scale_polyE mulrDr. Qed.
Fact scale_polyDl p : {morph scale_poly^~ p : a b / a + b}.
Proof. by move=> a b /=; rewrite !scale_polyE raddfD mulrDl. Qed.
Fact scale_polyAl a p q : scale_poly a (p * q) = scale_poly a p * q.
Proof. by rewrite !scale_polyE mulrA. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build R (polynomial R)
scale_polyA scale_1poly scale_polyDr scale_polyDl.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build R (polynomial R)
scale_polyAl.
Lemma mul_polyC a p : a%:P * p = a *: p.
Proof. by rewrite -scale_polyE. Qed.
Lemma scale_polyC a b : a *: b%:P = (a * b)%:P.
Proof. by rewrite -mul_polyC polyCM. Qed.
Lemma alg_polyC a : a%:A = a%:P :> {poly R}.
Proof. by rewrite -mul_polyC mulr1. Qed.
Lemma coefZ a p i : (a *: p)`_i = a * p`_i.
Proof.
rewrite -[*:%R]/scale_poly unlock coef_poly.
by case: leqP => // le_p_n; rewrite nth_default ?mulr0.
Qed.
Lemma size_scale_leq a p : size (a *: p) <= size p.
Proof. by rewrite -[*:%R]/scale_poly unlock size_poly. Qed.
HB.instance Definition _ i := GRing.isScalable.Build R {poly R} R *%R (coefp i)
(fun a => (coefZ a) ^~ i).
HB.instance Definition _ := GRing.Linear.on (coefp 0).
(* The indeterminate, at last! *)
Definition polyX_def := @Poly R [:: 0; 1].
Fact polyX_key : unit. Proof. by []. Qed.
Definition polyX : {poly R} := locked_with polyX_key polyX_def.
Canonical polyX_unlockable := [unlockable of polyX].
Local Notation "'X" := polyX.
Lemma polyseqX : 'X = [:: 0; 1] :> seq R.
Proof. by rewrite unlock !polyseq_cons nil_poly eqxx /= polyseq1. Qed.
Lemma size_polyX : size 'X = 2. Proof. by rewrite polyseqX. Qed.
Lemma polyX_eq0 : ('X == 0) = false.
Proof. by rewrite -size_poly_eq0 size_polyX. Qed.
Lemma coefX i : 'X`_i = (i == 1)%:R.
Proof. by case: i => [|[|i]]; rewrite polyseqX //= nth_nil. Qed.
Lemma lead_coefX : lead_coef 'X = 1.
Proof. by rewrite /lead_coef polyseqX. Qed.
Lemma commr_polyX p : GRing.comm p 'X.
Proof.
apply/polyP=> i; rewrite coefMr coefM.
by apply: eq_bigr => j _; rewrite coefX commr_nat.
Qed.
Lemma coefMX p i : (p * 'X)`_i = (if (i == 0)%N then 0 else p`_i.-1).
Proof.
rewrite coefMr big_ord_recl coefX ?simp.
case: i => [|i]; rewrite ?big_ord0 //= big_ord_recl polyseqX subn1 /=.
by rewrite big1 ?simp // => j _; rewrite nth_nil !simp.
Qed.
Lemma coefXM p i : ('X * p)`_i = (if (i == 0)%N then 0 else p`_i.-1).
Proof. by rewrite -commr_polyX coefMX. Qed.
Lemma cons_poly_def p a : cons_poly a p = p * 'X + a%:P.
Proof.
apply/polyP=> i; rewrite coef_cons coefD coefMX coefC.
by case: ifP; rewrite !simp.
Qed.
Lemma poly_ind (K : {poly R} -> Type) :
K 0 -> (forall p c, K p -> K (p * 'X + c%:P)) -> (forall p, K p).
Proof.
move=> K0 Kcons p; rewrite -[p]polyseqK.
by elim: {p}(p : seq R) => //= p c IHp; rewrite cons_poly_def; apply: Kcons.
Qed.
Lemma polyseqXaddC a : 'X + a%:P = [:: a; 1] :> seq R.
Proof. by rewrite -['X]mul1r -cons_poly_def polyseq_cons polyseq1. Qed.
Lemma polyseqXsubC a : 'X - a%:P = [:: - a; 1] :> seq R.
Proof. by rewrite -polyCN polyseqXaddC. Qed.
Lemma size_XsubC a : size ('X - a%:P) = 2.
Proof. by rewrite polyseqXsubC. Qed.
Lemma size_XaddC b : size ('X + b%:P) = 2.
Proof. by rewrite -[b]opprK rmorphN size_XsubC. Qed.
Lemma lead_coefXaddC a : lead_coef ('X + a%:P) = 1.
Proof. by rewrite lead_coefE polyseqXaddC. Qed.
Lemma lead_coefXsubC a : lead_coef ('X - a%:P) = 1.
Proof. by rewrite lead_coefE polyseqXsubC. Qed.
Lemma polyXsubC_eq0 a : ('X - a%:P == 0) = false.
Proof. by rewrite -nil_poly polyseqXsubC. Qed.
Lemma size_MXaddC p c :
size (p * 'X + c%:P) = (if (p == 0) && (c == 0) then 0 else (size p).+1).
Proof. by rewrite -cons_poly_def size_cons_poly nil_poly. Qed.
Lemma polyseqMX p : p != 0 -> p * 'X = 0 :: p :> seq R.
Proof.
by move=> nz_p; rewrite -[p * _]addr0 -cons_poly_def polyseq_cons nil_poly nz_p.
Qed.
Lemma size_mulX p : p != 0 -> size (p * 'X) = (size p).+1.
Proof. by move/polyseqMX->. Qed.
Lemma lead_coefMX p : lead_coef (p * 'X) = lead_coef p.
Proof.
have [-> | nzp] := eqVneq p 0; first by rewrite mul0r.
by rewrite /lead_coef !nth_last polyseqMX.
Qed.
Lemma size_XmulC a : a != 0 -> size ('X * a%:P) = 2.
Proof.
by move=> nz_a; rewrite -commr_polyX size_mulX ?polyC_eq0 ?size_polyC nz_a.
Qed.
Local Notation "''X^' n" := ('X ^+ n).
Lemma coefXn n i : 'X^n`_i = (i == n)%:R.
Proof.
by elim: n i => [|n IHn] [|i]; rewrite ?coef1 // exprS coefXM ?IHn.
Qed.
Lemma polyseqXn n : 'X^n = rcons (nseq n 0) 1 :> seq R.
Proof.
elim: n => [|n IHn]; rewrite ?polyseq1 // exprSr.
by rewrite polyseqMX -?size_poly_eq0 IHn ?size_rcons.
Qed.
Lemma size_polyXn n : size 'X^n = n.+1.
Proof. by rewrite polyseqXn size_rcons size_nseq. Qed.
Lemma commr_polyXn p n : GRing.comm p 'X^n.
Proof. exact/commrX/commr_polyX. Qed.
Lemma lead_coefXn n : lead_coef 'X^n = 1.
Proof. by rewrite /lead_coef nth_last polyseqXn last_rcons. Qed.
Lemma lead_coefXnaddC n c : 0 < n -> lead_coef ('X^n + c%:P) = 1.
Proof.
move=> n_gt0; rewrite lead_coefDl ?lead_coefXn//.
by rewrite size_polyC size_polyXn ltnS (leq_trans (leq_b1 _)).
Qed.
Lemma lead_coefXnsubC n c : 0 < n -> lead_coef ('X^n - c%:P) = 1.
Proof. by move=> n_gt0; rewrite -polyCN lead_coefXnaddC. Qed.
Lemma size_XnaddC n c : 0 < n -> size ('X^n + c%:P) = n.+1.
Proof.
by move=> *; rewrite size_polyDl ?size_polyXn// size_polyC; case: eqP.
Qed.
Lemma size_XnsubC n c : 0 < n -> size ('X^n - c%:P) = n.+1.
Proof. by move=> *; rewrite -polyCN size_XnaddC. Qed.
Lemma polyseqMXn n p : p != 0 -> p * 'X^n = ncons n 0 p :> seq R.
Proof.
case: n => [|n] nz_p; first by rewrite mulr1.
elim: n => [|n IHn]; first exact: polyseqMX.
by rewrite exprSr mulrA polyseqMX -?nil_poly IHn.
Qed.
Lemma coefMXn n p i : (p * 'X^n)`_i = if i < n then 0 else p`_(i - n).
Proof.
have [-> | /polyseqMXn->] := eqVneq p 0; last exact: nth_ncons.
by rewrite mul0r !coef0 if_same.
Qed.
Lemma size_mulXn n p : p != 0 -> size (p * 'X^n) = (n + size p)%N.
Proof.
elim: n p => [p p_neq0| n IH p p_neq0]; first by rewrite mulr1.
by rewrite exprS mulrA IH -?size_poly_eq0 size_mulX // addnS.
Qed.
Lemma coefXnM n p i : ('X^n * p)`_i = if i < n then 0 else p`_(i - n).
Proof. by rewrite -commr_polyXn coefMXn. Qed.
Lemma coef_sumMXn I (r : seq I) (P : pred I) (p : I -> R) (n : I -> nat) k :
(\sum_(i <- r | P i) p i *: 'X^(n i))`_k =
\sum_(i <- r | P i && (n i == k)) p i.
Proof.
rewrite coef_sum big_mkcondr; apply: eq_bigr => i Pi.
by rewrite coefZ coefXn mulr_natr mulrb eq_sym.
Qed.
(* Expansion of a polynomial as an indexed sum *)
Lemma poly_def n E : \poly_(i < n) E i = \sum_(i < n) E i *: 'X^i.
Proof. by apply/polyP => i; rewrite coef_sumMXn coef_poly big_ord1_eq. Qed.
(* Monic predicate *)
Definition monic_pred := fun p => lead_coef p == 1.
Arguments monic_pred _ /.
Definition monic := [qualify p | monic_pred p].
Lemma monicE p : (p \is monic) = (lead_coef p == 1). Proof. by []. Qed.
Lemma monicP p : reflect (lead_coef p = 1) (p \is monic).
Proof. exact: eqP. Qed.
Lemma monic1 : 1 \is monic. Proof. exact/eqP/lead_coef1. Qed.
Lemma monicX : 'X \is monic. Proof. exact/eqP/lead_coefX. Qed.
Lemma monicXn n : 'X^n \is monic. Proof. exact/eqP/lead_coefXn. Qed.
Lemma monic_neq0 p : p \is monic -> p != 0.
Proof. by rewrite -lead_coef_eq0 => /eqP->; apply: oner_neq0. Qed.
Lemma lead_coef_monicM p q : p \is monic -> lead_coef (p * q) = lead_coef q.
Proof.
have [-> | nz_q] := eqVneq q 0; first by rewrite mulr0.
by move/monicP=> mon_p; rewrite lead_coef_proper_mul mon_p mul1r ?lead_coef_eq0.
Qed.
Lemma lead_coef_Mmonic p q : q \is monic -> lead_coef (p * q) = lead_coef p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r.
by move/monicP=> mon_q; rewrite lead_coef_proper_mul mon_q mulr1 ?lead_coef_eq0.
Qed.
Lemma size_monicM p q :
p \is monic -> q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
move/monicP=> mon_p nz_q.
by rewrite size_proper_mul // mon_p mul1r lead_coef_eq0.
Qed.
Lemma size_Mmonic p q :
p != 0 -> q \is monic -> size (p * q) = (size p + size q).-1.
Proof.
move=> nz_p /monicP mon_q.
by rewrite size_proper_mul // mon_q mulr1 lead_coef_eq0.
Qed.
Lemma monicMl p q : p \is monic -> (p * q \is monic) = (q \is monic).
Proof. by move=> mon_p; rewrite !monicE lead_coef_monicM. Qed.
Lemma monicMr p q : q \is monic -> (p * q \is monic) = (p \is monic).
Proof. by move=> mon_q; rewrite !monicE lead_coef_Mmonic. Qed.
Fact monic_mulr_closed : mulr_closed monic.
Proof. by split=> [|p q mon_p]; rewrite (monic1, monicMl). Qed.
HB.instance Definition _ := GRing.isMulClosed.Build {poly R} monic_pred
monic_mulr_closed.
Lemma monic_exp p n : p \is monic -> p ^+ n \is monic.
Proof. exact: rpredX. Qed.
Lemma monic_prod I rI (P : pred I) (F : I -> {poly R}):
(forall i, P i -> F i \is monic) -> \prod_(i <- rI | P i) F i \is monic.
Proof. exact: rpred_prod. Qed.
Lemma monicXaddC c : 'X + c%:P \is monic.
Proof. exact/eqP/lead_coefXaddC. Qed.
Lemma monicXsubC c : 'X - c%:P \is monic.
Proof. exact/eqP/lead_coefXsubC. Qed.
Lemma monic_prod_XsubC I rI (P : pred I) (F : I -> R) :
\prod_(i <- rI | P i) ('X - (F i)%:P) \is monic.
Proof. by apply: monic_prod => i _; apply: monicXsubC. Qed.
Lemma lead_coef_prod_XsubC I rI (P : pred I) (F : I -> R) :
lead_coef (\prod_(i <- rI | P i) ('X - (F i)%:P)) = 1.
Proof. exact/eqP/monic_prod_XsubC. Qed.
Lemma size_prod_XsubC I rI (F : I -> R) :
size (\prod_(i <- rI) ('X - (F i)%:P)) = (size rI).+1.
Proof.
elim: rI => [|i r /= <-]; rewrite ?big_nil ?size_poly1 // big_cons.
rewrite size_monicM ?monicXsubC ?monic_neq0 ?monic_prod_XsubC //.
by rewrite size_XsubC.
Qed.
Lemma size_exp_XsubC n a : size (('X - a%:P) ^+ n) = n.+1.
Proof.
rewrite -[n]card_ord -prodr_const -big_filter size_prod_XsubC.
by have [e _ _ [_ ->]] := big_enumP.
Qed.
Lemma monicXnaddC n c : 0 < n -> 'X^n + c%:P \is monic.
Proof. by move=> n_gt0; rewrite monicE lead_coefXnaddC. Qed.
Lemma monicXnsubC n c : 0 < n -> 'X^n - c%:P \is monic.
Proof. by move=> n_gt0; rewrite monicE lead_coefXnsubC. Qed.
(* Some facts about regular elements. *)
Lemma lreg_lead p : GRing.lreg (lead_coef p) -> GRing.lreg p.
Proof.
move/mulrI_eq0=> reg_p; apply: mulrI0_lreg => q /eqP; apply: contraTeq => nz_q.
by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0.
Qed.
Lemma rreg_lead p : GRing.rreg (lead_coef p) -> GRing.rreg p.
Proof.
move/mulIr_eq0=> reg_p; apply: mulIr0_rreg => q /eqP; apply: contraTeq => nz_q.
by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0.
Qed.
Lemma lreg_lead0 p : GRing.lreg (lead_coef p) -> p != 0.
Proof. by move/lreg_neq0; rewrite lead_coef_eq0. Qed.
Lemma rreg_lead0 p : GRing.rreg (lead_coef p) -> p != 0.
Proof. by move/rreg_neq0; rewrite lead_coef_eq0. Qed.
Lemma lreg_size c p : GRing.lreg c -> size (c *: p) = size p.
Proof.
move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite scaler0.
rewrite -mul_polyC size_proper_mul; first by rewrite size_polyC lreg_neq0.
by rewrite lead_coefC mulrI_eq0 ?lead_coef_eq0.
Qed.
Lemma lreg_polyZ_eq0 c p : GRing.lreg c -> (c *: p == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /lreg_size->. Qed.
Lemma lead_coef_lreg c p :
GRing.lreg c -> lead_coef (c *: p) = c * lead_coef p.
Proof. by move=> reg_c; rewrite !lead_coefE coefZ lreg_size. Qed.
Lemma rreg_size c p : GRing.rreg c -> size (p * c%:P) = size p.
Proof.
move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r.
rewrite size_proper_mul; first by rewrite size_polyC rreg_neq0 ?addn1.
by rewrite lead_coefC mulIr_eq0 ?lead_coef_eq0.
Qed.
Lemma rreg_polyMC_eq0 c p : GRing.rreg c -> (p * c%:P == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /rreg_size->. Qed.
Lemma rreg_div0 q r d :
GRing.rreg (lead_coef d) -> size r < size d ->
(q * d + r == 0) = (q == 0) && (r == 0).
Proof.
move=> reg_d lt_r_d; rewrite addrC addr_eq0.
have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r oppr0.
apply: contraTF lt_r_d => /eqP->; rewrite -leqNgt size_polyN.
rewrite size_proper_mul ?mulIr_eq0 ?lead_coef_eq0 //.
by rewrite (polySpred nz_q) leq_addl.
Qed.
Lemma monic_comreg p :
p \is monic -> GRing.comm p (lead_coef p)%:P /\ GRing.rreg (lead_coef p).
Proof. by move/monicP->; split; [apply: commr1 | apply: rreg1]. Qed.
Lemma monic_lreg p : p \is monic -> GRing.lreg p.
Proof. by move=> /eqP lp1; apply/lreg_lead; rewrite lp1; apply/lreg1. Qed.
Lemma monic_rreg p : p \is monic -> GRing.rreg p.
Proof. by move=> /eqP lp1; apply/rreg_lead; rewrite lp1; apply/rreg1. Qed.
(* Horner evaluation of polynomials *)
Implicit Types s rs : seq R.
Fixpoint horner_rec s x := if s is a :: s' then horner_rec s' x * x + a else 0.
Definition horner p := horner_rec p.
Local Notation "p .[ x ]" := (horner p x) : ring_scope.
Lemma horner0 x : (0 : {poly R}).[x] = 0.
Proof. by rewrite /horner polyseq0. Qed.
Lemma hornerC c x : (c%:P).[x] = c.
Proof. by rewrite /horner polyseqC; case: eqP; rewrite /= ?simp. Qed.
Lemma hornerX x : 'X.[x] = x.
Proof. by rewrite /horner polyseqX /= !simp. Qed.
Lemma horner_cons p c x : (cons_poly c p).[x] = p.[x] * x + c.
Proof.
rewrite /horner polyseq_cons; case: nilP => //= ->.
by rewrite !simp -/(_.[x]) hornerC.
Qed.
Lemma horner_coef0 p : p.[0] = p`_0.
Proof. by rewrite /horner; case: (p : seq R) => //= c p'; rewrite !simp. Qed.
Lemma hornerMXaddC p c x : (p * 'X + c%:P).[x] = p.[x] * x + c.
Proof. by rewrite -cons_poly_def horner_cons. Qed.
Lemma hornerMX p x : (p * 'X).[x] = p.[x] * x.
Proof. by rewrite -[p * 'X]addr0 hornerMXaddC addr0. Qed.
Lemma horner_Poly s x : (Poly s).[x] = horner_rec s x.
Proof. by elim: s => [|a s /= <-]; rewrite (horner0, horner_cons). Qed.
Lemma horner_coef p x : p.[x] = \sum_(i < size p) p`_i * x ^+ i.
Proof.
rewrite /horner.
elim: {p}(p : seq R) => /= [|a s ->]; first by rewrite big_ord0.
rewrite big_ord_recl simp addrC big_distrl /=.
by congr (_ + _); apply: eq_bigr => i _; rewrite -mulrA exprSr.
Qed.
Lemma horner_coef_wide n p x :
size p <= n -> p.[x] = \sum_(i < n) p`_i * x ^+ i.
Proof.
move=> le_p_n.
rewrite horner_coef (big_ord_widen n (fun i => p`_i * x ^+ i)) // big_mkcond.
by apply: eq_bigr => i _; case: ltnP => // le_p_i; rewrite nth_default ?simp.
Qed.
Lemma horner_poly n E x : (\poly_(i < n) E i).[x] = \sum_(i < n) E i * x ^+ i.
Proof.
rewrite (@horner_coef_wide n) ?size_poly //.
by apply: eq_bigr => i _; rewrite coef_poly ltn_ord.
Qed.
Lemma hornerN p x : (- p).[x] = - p.[x].
Proof.
rewrite -[-%R]/opp_poly unlock horner_poly horner_coef -sumrN /=.
by apply: eq_bigr => i _; rewrite mulNr.
Qed.
Lemma hornerD p q x : (p + q).[x] = p.[x] + q.[x].
Proof.
rewrite -[+%R]/(@add_poly R) unlock horner_poly; set m := maxn _ _.
rewrite !(@horner_coef_wide m) ?leq_max ?leqnn ?orbT // -big_split /=.
by apply: eq_bigr => i _; rewrite -mulrDl.
Qed.
Lemma hornerXsubC a x : ('X - a%:P).[x] = x - a.
Proof. by rewrite hornerD hornerN hornerC hornerX. Qed.
Lemma horner_sum I (r : seq I) (P : pred I) F x :
(\sum_(i <- r | P i) F i).[x] = \sum_(i <- r | P i) (F i).[x].
Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (horner0, hornerD). Qed.
Lemma hornerCM a p x : (a%:P * p).[x] = a * p.[x].
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(mulr0, horner0).
by rewrite mulrDr mulrA -polyCM !hornerMXaddC IHp mulrDr mulrA.
Qed.
Lemma hornerZ c p x : (c *: p).[x] = c * p.[x].
Proof. by rewrite -mul_polyC hornerCM. Qed.
Lemma hornerMn n p x : (p *+ n).[x] = p.[x] *+ n.
Proof. by elim: n => [| n IHn]; rewrite ?horner0 // !mulrS hornerD IHn. Qed.
Definition comm_coef p x := forall i, p`_i * x = x * p`_i.
Definition comm_poly p x := x * p.[x] = p.[x] * x.
Lemma comm_coef_poly p x : comm_coef p x -> comm_poly p x.
Proof.
move=> cpx; rewrite /comm_poly !horner_coef big_distrl big_distrr /=.
by apply: eq_bigr => i _; rewrite /= mulrA -cpx -!mulrA commrX.
Qed.
Lemma comm_poly0 x : comm_poly 0 x.
Proof. by rewrite /comm_poly !horner0 !simp. Qed.
Lemma comm_poly1 x : comm_poly 1 x.
Proof. by rewrite /comm_poly !hornerC !simp. Qed.
Lemma comm_polyX x : comm_poly 'X x.
Proof. by rewrite /comm_poly !hornerX. Qed.
Lemma comm_polyD p q x: comm_poly p x -> comm_poly q x -> comm_poly (p + q) x.
Proof. by rewrite /comm_poly hornerD mulrDr mulrDl => -> ->. Qed.
Lemma commr_horner a b p : GRing.comm a b -> comm_coef p a -> GRing.comm a p.[b].
Proof.
move=> cab cpa; rewrite horner_coef; apply: commr_sum => i _.
by apply: commrM => //; apply: commrX.
Qed.
Lemma hornerM_comm p q x : comm_poly q x -> (p * q).[x] = p.[x] * q.[x].
Proof.
move=> comm_qx.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(simp, horner0).
rewrite mulrDl hornerD hornerCM -mulrA -commr_polyX mulrA hornerMX.
by rewrite {}IHp -mulrA -comm_qx mulrA -mulrDl hornerMXaddC.
Qed.
Lemma comm_polyM p q x: comm_poly p x -> comm_poly q x -> comm_poly (p * q) x.
Proof.
by move=> px qx; rewrite /comm_poly hornerM_comm// mulrA px -mulrA qx mulrA.
Qed.
Lemma horner_exp_comm p x n : comm_poly p x -> (p ^+ n).[x] = p.[x] ^+ n.
Proof.
move=> comm_px; elim: n => [|n IHn]; first by rewrite hornerC.
by rewrite !exprSr -IHn hornerM_comm.
Qed.
Lemma comm_poly_exp p n x: comm_poly p x -> comm_poly (p ^+ n) x.
Proof. by move=> px; rewrite /comm_poly !horner_exp_comm// commrX. Qed.
Lemma hornerXn x n : ('X^n).[x] = x ^+ n.
Proof. by rewrite horner_exp_comm /comm_poly hornerX. Qed.
Definition hornerE_comm :=
(hornerD, hornerN, hornerX, hornerC, horner_cons,
simp, hornerCM, hornerZ,
(fun p x => hornerM_comm p (comm_polyX x))).
Definition root p : pred R := fun x => p.[x] == 0.
Lemma mem_root p x : x \in root p = (p.[x] == 0).
Proof. by []. Qed.
Lemma rootE p x : (root p x = (p.[x] == 0)) * ((x \in root p) = (p.[x] == 0)).
Proof. by []. Qed.
Lemma rootP p x : reflect (p.[x] = 0) (root p x).
Proof. exact: eqP. Qed.
Lemma rootPt p x : reflect (p.[x] == 0) (root p x).
Proof. exact: idP. Qed.
Lemma rootPf p x : reflect ((p.[x] == 0) = false) (~~ root p x).
Proof. exact: negPf. Qed.
Lemma rootC a x : root a%:P x = (a == 0).
Proof. by rewrite rootE hornerC. Qed.
Lemma root0 x : root 0 x.
Proof. by rewrite rootC. Qed.
Lemma root1 x : ~~ root 1 x.
Proof. by rewrite rootC oner_eq0. Qed.
Lemma rootX x : root 'X x = (x == 0).
Proof. by rewrite rootE hornerX. Qed.
Lemma rootN p x : root (- p) x = root p x.
Proof. by rewrite rootE hornerN oppr_eq0. Qed.
Lemma root_size_gt1 a p : p != 0 -> root p a -> 1 < size p.
Proof.
rewrite ltnNge => nz_p; apply: contraL => /size1_polyC Dp.
by rewrite Dp rootC -polyC_eq0 -Dp.
Qed.
Lemma root_XsubC a x : root ('X - a%:P) x = (x == a).
Proof. by rewrite rootE hornerXsubC subr_eq0. Qed.
Lemma root_XaddC a x : root ('X + a%:P) x = (x == - a).
Proof. by rewrite -root_XsubC rmorphN opprK. Qed.
Theorem factor_theorem p a : reflect (exists q, p = q * ('X - a%:P)) (root p a).
Proof.
apply: (iffP eqP) => [pa0 | [q ->]]; last first.
by rewrite hornerM_comm /comm_poly hornerXsubC subrr ?simp.
exists (\poly_(i < size p) horner_rec (drop i.+1 p) a).
apply/polyP=> i; rewrite mulrBr coefB coefMX coefMC !coef_poly.
apply: canRL (addrK _) _; rewrite addrC; have [le_p_i | lt_i_p] := leqP.
rewrite nth_default // !simp drop_oversize ?if_same //.
exact: leq_trans (leqSpred _).
case: i => [|i] in lt_i_p *; last by rewrite ltnW // (drop_nth 0 lt_i_p).
by rewrite drop1 /= -{}pa0 /horner; case: (p : seq R) lt_i_p.
Qed.
Lemma multiplicity_XsubC p a :
{m | exists2 q, (p != 0) ==> ~~ root q a & p = q * ('X - a%:P) ^+ m}.
Proof.
have [n le_p_n] := ubnP (size p); elim: n => // n IHn in p le_p_n *.
have [-> | nz_p /=] := eqVneq p 0; first by exists 0, 0; rewrite ?mul0r.
have [/sig_eqW[p1 Dp] | nz_pa] := altP (factor_theorem p a); last first.
by exists 0%N, p; rewrite ?mulr1.
have nz_p1: p1 != 0 by apply: contraNneq nz_p => p1_0; rewrite Dp p1_0 mul0r.
have /IHn[m /sig2_eqW[q nz_qa Dp1]]: size p1 < n.
by rewrite Dp size_Mmonic ?monicXsubC // size_XsubC addn2 in le_p_n.
by exists m.+1, q; [rewrite nz_p1 in nz_qa | rewrite exprSr mulrA -Dp1].
Qed.
(* Roots of unity. *)
#[deprecated(since="mathcomp 2.3.0",note="Use size_XnsubC instead.")]
Lemma size_Xn_sub_1 n : n > 0 -> size ('X^n - 1 : {poly R}) = n.+1.
Proof. exact/size_XnsubC. Qed.
#[deprecated(since="mathcomp 2.3.0'",note="Use monicXnsubC instead.")]
Lemma monic_Xn_sub_1 n : n > 0 -> 'X^n - 1 \is monic.
Proof. exact/monicXnsubC. Qed.
Definition root_of_unity n : pred R := root ('X^n - 1).
Local Notation "n .-unity_root" := (root_of_unity n) : ring_scope.
Lemma unity_rootE n z : n.-unity_root z = (z ^+ n == 1).
Proof.
by rewrite /root_of_unity rootE hornerD hornerN hornerXn hornerC subr_eq0.
Qed.
Lemma unity_rootP n z : reflect (z ^+ n = 1) (n.-unity_root z).
Proof. by rewrite unity_rootE; apply: eqP. Qed.
Definition primitive_root_of_unity n z :=
(n > 0) && [forall i : 'I_n, i.+1.-unity_root z == (i.+1 == n)].
Local Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope.
Lemma prim_order_exists n z :
n > 0 -> z ^+ n = 1 -> {m | m.-primitive_root z & (m %| n)}.
Proof.
move=> n_gt0 zn1.
have: exists m, (m > 0) && (z ^+ m == 1) by exists n; rewrite n_gt0 /= zn1.
case/ex_minnP=> m /andP[m_gt0 /eqP zm1] m_min.
exists m.
apply/andP; split=> //; apply/eqfunP=> [[i]] /=.
rewrite leq_eqVlt unity_rootE.
case: eqP => [-> _ | _]; first by rewrite zm1 eqxx.
by apply: contraTF => zi1; rewrite -leqNgt m_min.
have: n %% m < m by rewrite ltn_mod.
apply: contraLR; rewrite -lt0n -leqNgt => nm_gt0; apply: m_min.
by rewrite nm_gt0 /= expr_mod ?zn1.
Qed.
Section OnePrimitive.
Variables (n : nat) (z : R).
Hypothesis prim_z : n.-primitive_root z.
Lemma prim_order_gt0 : n > 0. Proof. by case/andP: prim_z. Qed.
Let n_gt0 := prim_order_gt0.
Lemma prim_expr_order : z ^+ n = 1.
Proof.
case/andP: prim_z => _; rewrite -(prednK n_gt0) => /forallP/(_ ord_max).
by rewrite unity_rootE eqxx eqb_id => /eqP.
Qed.
Lemma prim_expr_mod i : z ^+ (i %% n) = z ^+ i.
Proof. exact: expr_mod prim_expr_order. Qed.
Lemma prim_order_dvd i : (n %| i) = (z ^+ i == 1).
Proof.
move: n_gt0; rewrite -prim_expr_mod /dvdn -(ltn_mod i).
case: {i}(i %% n)%N => [|i] lt_i; first by rewrite !eqxx.
case/andP: prim_z => _ /forallP/(_ (Ordinal (ltnW lt_i)))/eqP.
by rewrite unity_rootE eqn_leq andbC leqNgt lt_i.
Qed.
Lemma eq_prim_root_expr i j : (z ^+ i == z ^+ j) = (i == j %[mod n]).
Proof.
wlog le_ji: i j / j <= i.
move=> IH; case: (leqP j i) => [|/ltnW] /IH //.
by rewrite eq_sym (eq_sym (j %% n)%N).
rewrite -{1}(subnKC le_ji) exprD -prim_expr_mod eqn_mod_dvd //.
rewrite prim_order_dvd; apply/eqP/eqP=> [|->]; last by rewrite mulr1.
move/(congr1 ( *%R (z ^+ (n - j %% n)))); rewrite mulrA -exprD.
by rewrite subnK ?prim_expr_order ?mul1r // ltnW ?ltn_mod.
Qed.
Lemma exp_prim_root k : (n %/ gcdn k n).-primitive_root (z ^+ k).
Proof.
set d := gcdn k n; have d_gt0: (0 < d)%N by rewrite gcdn_gt0 orbC n_gt0.
have [d_dv_k d_dv_n]: (d %| k /\ d %| n)%N by rewrite dvdn_gcdl dvdn_gcdr.
set q := (n %/ d)%N; rewrite /q.-primitive_root ltn_divRL // n_gt0.
apply/forallP=> i; rewrite unity_rootE -exprM -prim_order_dvd.
rewrite -(divnK d_dv_n) -/q -(divnK d_dv_k) mulnAC dvdn_pmul2r //.
apply/eqP; apply/idP/idP=> [|/eqP->]; last by rewrite dvdn_mull.
rewrite Gauss_dvdr; first by rewrite eqn_leq ltn_ord; apply: dvdn_leq.
by rewrite /coprime gcdnC -(eqn_pmul2r d_gt0) mul1n muln_gcdl !divnK.
Qed.
Lemma dvdn_prim_root m : (m %| n)%N -> m.-primitive_root (z ^+ (n %/ m)).
Proof.
set k := (n %/ m)%N => m_dv_n; rewrite -{1}(mulKn m n_gt0) -divnA // -/k.
by rewrite -{1}(@gcdn_idPl k n _) ?exp_prim_root // -(divnK m_dv_n) dvdn_mulr.
Qed.
Lemma prim_root_eq0 : (z == 0) = (n == 0%N).
Proof.
rewrite gtn_eqF//; apply/eqP => z0; have /esym/eqP := prim_expr_order.
by rewrite z0 expr0n gtn_eqF//= oner_eq0.
Qed.
End OnePrimitive.
Lemma prim_root_exp_coprime n z k :
n.-primitive_root z -> n.-primitive_root (z ^+ k) = coprime k n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
apply/idP/idP=> [prim_zk | co_k_n].
set d := gcdn k n; have dv_d_n: (d %| n)%N := dvdn_gcdr _ _.
rewrite /coprime -/d -(eqn_pmul2r n_gt0) mul1n -{2}(gcdnMl n d).
rewrite -{2}(divnK dv_d_n) (mulnC _ d) -muln_gcdr (gcdn_idPr _) //.
rewrite (prim_order_dvd prim_zk) -exprM -(prim_order_dvd prim_z).
by rewrite muln_divCA_gcd dvdn_mulr.
have zkn_1: z ^+ k ^+ n = 1 by rewrite exprAC (prim_expr_order prim_z) expr1n.
have{zkn_1} [m prim_zk dv_m_n]:= prim_order_exists n_gt0 zkn_1.
suffices /eqP <-: m == n by [].
rewrite eqn_dvd dv_m_n -(@Gauss_dvdr n k m) 1?coprime_sym //=.
by rewrite (prim_order_dvd prim_z) exprM (prim_expr_order prim_zk).
Qed.
(* Lifting a ring predicate to polynomials. *)
Implicit Type S : {pred R}.
Definition polyOver_pred S := fun p : {poly R} => all (mem S) p.
Arguments polyOver_pred _ _ /.
Definition polyOver S := [qualify a p | polyOver_pred S p].
Lemma polyOverS (S1 S2 : {pred R}) :
{subset S1 <= S2} -> {subset polyOver S1 <= polyOver S2}.
Proof.
by move=> sS12 p /(all_nthP 0)S1p; apply/(all_nthP 0)=> i /S1p; apply: sS12.
Qed.
Lemma polyOver0 S : 0 \is a polyOver S.
Proof. by rewrite qualifE /= polyseq0. Qed.
Lemma polyOver_poly S n E :
(forall i, i < n -> E i \in S) -> \poly_(i < n) E i \is a polyOver S.
Proof.
move=> S_E; apply/(all_nthP 0)=> i lt_i_p /=; rewrite coef_poly.
by case: ifP => [/S_E// | /idP[]]; apply: leq_trans lt_i_p (size_poly n E).
Qed.
Section PolyOverAdd.
Variable S : addrClosed R.
Lemma polyOverP {p} : reflect (forall i, p`_i \in S) (p \in polyOver S).
Proof.
apply: (iffP (all_nthP 0)) => [Sp i | Sp i _]; last exact: Sp.
by have [/Sp // | /(nth_default 0)->] := ltnP i (size p); apply: rpred0.
Qed.
Lemma polyOverC c : (c%:P \in polyOver S) = (c \in S).
Proof.
by rewrite [LHS]qualifE /= polyseqC; case: eqP => [->|] /=; rewrite ?andbT ?rpred0.
Qed.
Fact polyOver_addr_closed : addr_closed (polyOver S).
Proof.
split=> [|p q Sp Sq]; first exact: polyOver0.
by apply/polyOverP=> i; rewrite coefD rpredD ?(polyOverP _).
Qed.
HB.instance Definition _ := GRing.isAddClosed.Build {poly R} (polyOver_pred S)
polyOver_addr_closed.
End PolyOverAdd.
Section PolyOverSemiRing2.
Variable S : semiring2Closed R.
Lemma polyOver_mulr_2closed : GRing.mulr_2closed (polyOver S).
Proof.
move=> p q /polyOverP Sp /polyOverP Sq; apply/polyOverP=> i.
by rewrite coefM rpred_sum // => j _; rewrite rpredM.
Qed.
HB.instance Definition _ := GRing.isMul2Closed.Build {poly R} (polyOver_pred S)
polyOver_mulr_2closed.
End PolyOverSemiRing2.
Fact polyOverNr (zmodS : zmodClosed R) : oppr_closed (polyOver zmodS).
Proof.
by move=> p /polyOverP Sp; apply/polyOverP=> i; rewrite coefN rpredN.
Qed.
HB.instance Definition _ (zmodS : zmodClosed R) :=
GRing.isOppClosed.Build {poly R} (polyOver_pred zmodS) (@polyOverNr _).
Section PolyOverSemiring.
Variable S : semiringClosed R.
Fact polyOver_mul1_closed : 1 \in (polyOver S).
Proof. by rewrite polyOverC rpred1. Qed.
HB.instance Definition _ := GRing.isMul1Closed.Build {poly R} (polyOver_pred S)
polyOver_mul1_closed.
Lemma polyOverZ : {in S & polyOver S, forall c p, c *: p \is a polyOver S}.
Proof.
by move=> c p Sc /polyOverP Sp; apply/polyOverP=> i; rewrite coefZ rpredM ?Sp.
Qed.
Lemma polyOverX : 'X \in polyOver S.
Proof. by rewrite qualifE /= polyseqX /= rpred0 rpred1. Qed.
Lemma polyOverXn n : 'X^n \in polyOver S.
Proof. by rewrite rpredX// polyOverX. Qed.
Lemma rpred_horner : {in polyOver S & S, forall p x, p.[x] \in S}.
Proof.
move=> p x /polyOverP Sp Sx; rewrite horner_coef rpred_sum // => i _.
by rewrite rpredM ?rpredX.
Qed.
End PolyOverSemiring.
Section PolyOverRing.
Variable S : subringClosed R.
HB.instance Definition _ := GRing.MulClosed.on (polyOver_pred S).
Lemma polyOverXaddC c : ('X + c%:P \in polyOver S) = (c \in S).
Proof. by rewrite rpredDl ?polyOverX ?polyOverC. Qed.
Lemma polyOverXnaddC n c : ('X^n + c%:P \is a polyOver S) = (c \in S).
Proof. by rewrite rpredDl ?polyOverXn// ?polyOverC. Qed.
Lemma polyOverXsubC c : ('X - c%:P \in polyOver S) = (c \in S).
Proof. by rewrite rpredBl ?polyOverX ?polyOverC. Qed.
Lemma polyOverXnsubC n c : ('X^n - c%:P \is a polyOver S) = (c \in S).
Proof. by rewrite rpredBl ?polyOverXn// ?polyOverC. Qed.
End PolyOverRing.
(* Single derivative. *)
Definition deriv p := \poly_(i < (size p).-1) (p`_i.+1 *+ i.+1).
Local Notation "a ^` ()" := (deriv a).
Lemma coef_deriv p i : p^`()`_i = p`_i.+1 *+ i.+1.
Proof.
rewrite coef_poly -subn1 ltn_subRL.
by case: leqP => // /(nth_default 0) ->; rewrite mul0rn.
Qed.
Lemma polyOver_deriv (ringS : semiringClosed R) :
{in polyOver ringS, forall p, p^`() \is a polyOver ringS}.
Proof.
by move=> p /polyOverP Kp; apply/polyOverP=> i; rewrite coef_deriv rpredMn ?Kp.
Qed.
Lemma derivC c : c%:P^`() = 0.
Proof. by apply/polyP=> i; rewrite coef_deriv coef0 coefC mul0rn. Qed.
Lemma derivX : ('X)^`() = 1.
Proof. by apply/polyP=> [[|i]]; rewrite coef_deriv coef1 coefX ?mul0rn. Qed.
Lemma derivXn n : ('X^n)^`() = 'X^(n.-1) *+ n.
Proof.
case: n => [|n]; first exact: derivC.
apply/polyP=> i; rewrite coef_deriv coefMn !coefXn eqSS.
by case: eqP => [-> // | _]; rewrite !mul0rn.
Qed.
Fact deriv_is_linear : linear deriv.
Proof.
move=> k p q; apply/polyP=> i.
by rewrite !(coef_deriv, coefD, coefZ) mulrnDl mulrnAr.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly R} _ deriv
(GRing.semilinear_linear deriv_is_linear).
Lemma deriv0 : 0^`() = 0.
Proof. exact: linear0. Qed.
Lemma derivD : {morph deriv : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma derivN : {morph deriv : p / - p}.
Proof. exact: linearN. Qed.
Lemma derivB : {morph deriv : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma derivXsubC (a : R) : ('X - a%:P)^`() = 1.
Proof. by rewrite derivB derivX derivC subr0. Qed.
Lemma derivMn n p : (p *+ n)^`() = p^`() *+ n.
Proof. exact: linearMn. Qed.
Lemma derivMNn n p : (p *- n)^`() = p^`() *- n.
Proof. exact: linearMNn. Qed.
Lemma derivZ c p : (c *: p)^`() = c *: p^`().
Proof. exact: linearZ. Qed.
Lemma deriv_mulC c p : (c%:P * p)^`() = c%:P * p^`().
Proof. by rewrite !mul_polyC derivZ. Qed.
Lemma derivMXaddC p c : (p * 'X + c%:P)^`() = p + p^`() * 'X.
Proof.
apply/polyP=> i; rewrite raddfD /= derivC addr0 coefD !(coefMX, coef_deriv).
by case: i; rewrite ?addr0.
Qed.
Lemma derivM p q : (p * q)^`() = p^`() * q + p * q^`().
Proof.
elim/poly_ind: p => [|p b IHp]; first by rewrite !(mul0r, add0r, derivC).
rewrite mulrDl -mulrA -commr_polyX mulrA -[_ * 'X]addr0 raddfD /= !derivMXaddC.
by rewrite deriv_mulC IHp !mulrDl -!mulrA !commr_polyX !addrA.
Qed.
Definition derivE := Eval lazy beta delta [morphism_2 morphism_1] in
(derivZ, deriv_mulC, derivC, derivX, derivMXaddC, derivXsubC, derivM, derivB,
derivD, derivN, derivXn, derivM, derivMn).
(* Iterated derivative. *)
Definition derivn n p := iter n deriv p.
Local Notation "a ^` ( n )" := (derivn n a) : ring_scope.
Lemma derivn0 p : p^`(0) = p.
Proof. by []. Qed.
Lemma derivn1 p : p^`(1) = p^`().
Proof. by []. Qed.
Lemma derivnS p n : p^`(n.+1) = p^`(n)^`().
Proof. by []. Qed.
Lemma derivSn p n : p^`(n.+1) = p^`()^`(n).
Proof. exact: iterSr. Qed.
Lemma coef_derivn n p i : p^`(n)`_i = p`_(n + i) *+ (n + i) ^_ n.
Proof.
elim: n i => [|n IHn] i; first by rewrite ffactn0 mulr1n.
by rewrite derivnS coef_deriv IHn -mulrnA ffactnSr addSnnS addKn.
Qed.
Lemma polyOver_derivn (ringS : semiringClosed R) :
{in polyOver ringS, forall p n, p^`(n) \is a polyOver ringS}.
Proof.
move=> p /polyOverP Kp /= n; apply/polyOverP=> i.
by rewrite coef_derivn rpredMn.
Qed.
Fact derivn_is_linear n : linear (derivn n).
Proof. by elim: n => // n IHn a p q; rewrite derivnS IHn linearP. Qed.
HB.instance Definition _ n :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (derivn n)
(GRing.semilinear_linear (derivn_is_linear n)).
Lemma derivnC c n : c%:P^`(n) = if n == 0 then c%:P else 0.
Proof. by case: n => // n; rewrite derivSn derivC linear0. Qed.
Lemma derivnD n : {morph derivn n : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma derivnB n : {morph derivn n : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma derivnMn n m p : (p *+ m)^`(n) = p^`(n) *+ m.
Proof. exact: linearMn. Qed.
Lemma derivnMNn n m p : (p *- m)^`(n) = p^`(n) *- m.
Proof. exact: linearMNn. Qed.
Lemma derivnN n : {morph derivn n : p / - p}.
Proof. exact: linearN. Qed.
Lemma derivnZ n : scalable (derivn n).
Proof. exact: linearZZ. Qed.
Lemma derivnXn m n : ('X^m)^`(n) = 'X^(m - n) *+ m ^_ n.
Proof.
apply/polyP=>i; rewrite coef_derivn coefMn !coefXn.
case: (ltnP m n) => [lt_m_n | le_m_n].
by rewrite eqn_leq leqNgt ltn_addr // mul0rn ffact_small.
by rewrite -{1 3}(subnKC le_m_n) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn.
Qed.
Lemma derivnMXaddC n p c :
(p * 'X + c%:P)^`(n.+1) = p^`(n) *+ n.+1 + p^`(n.+1) * 'X.
Proof.
elim: n => [|n IHn]; first by rewrite derivn1 derivMXaddC.
rewrite derivnS IHn derivD derivM derivX mulr1 derivMn -!derivnS.
by rewrite addrA addrAC -mulrSr.
Qed.
Lemma derivn_poly0 p n : size p <= n -> p^`(n) = 0.
Proof.
move=> le_p_n; apply/polyP=> i; rewrite coef_derivn.
rewrite nth_default; first by rewrite mul0rn coef0.
exact/(leq_trans le_p_n)/leq_addr.
Qed.
Lemma lt_size_deriv (p : {poly R}) : p != 0 -> size p^`() < size p.
Proof. by move=> /polySpred->; apply: size_poly. Qed.
(* A normalising version of derivation to get the division by n! in Taylor *)
Definition nderivn n p := \poly_(i < size p - n) (p`_(n + i) *+ 'C(n + i, n)).
Local Notation "a ^`N ( n )" := (nderivn n a) : ring_scope.
Lemma coef_nderivn n p i : p^`N(n)`_i = p`_(n + i) *+ 'C(n + i, n).
Proof.
rewrite coef_poly ltn_subRL; case: leqP => // le_p_ni.
by rewrite nth_default ?mul0rn.
Qed.
(* Here is the division by n! *)
Lemma nderivn_def n p : p^`(n) = p^`N(n) *+ n`!.
Proof.
by apply/polyP=> i; rewrite coefMn coef_nderivn coef_derivn -mulrnA bin_ffact.
Qed.
Lemma polyOver_nderivn (ringS : semiringClosed R) :
{in polyOver ringS, forall p n, p^`N(n) \in polyOver ringS}.
Proof.
move=> p /polyOverP Sp /= n; apply/polyOverP=> i.
by rewrite coef_nderivn rpredMn.
Qed.
Lemma nderivn0 p : p^`N(0) = p.
Proof. by rewrite -[p^`N(0)](nderivn_def 0). Qed.
Lemma nderivn1 p : p^`N(1) = p^`().
Proof. by rewrite -[p^`N(1)](nderivn_def 1). Qed.
Lemma nderivnC c n : (c%:P)^`N(n) = if n == 0 then c%:P else 0.
Proof.
apply/polyP=> i; rewrite coef_nderivn.
by case: n => [|n]; rewrite ?bin0 // coef0 coefC mul0rn.
Qed.
Lemma nderivnXn m n : ('X^m)^`N(n) = 'X^(m - n) *+ 'C(m, n).
Proof.
apply/polyP=> i; rewrite coef_nderivn coefMn !coefXn.
have [lt_m_n | le_n_m] := ltnP m n.
by rewrite eqn_leq leqNgt ltn_addr // mul0rn bin_small.
by rewrite -{1 3}(subnKC le_n_m) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn.
Qed.
Fact nderivn_is_linear n : linear (nderivn n).
Proof.
move=> k p q; apply/polyP=> i.
by rewrite !(coef_nderivn, coefD, coefZ) mulrnDl mulrnAr.
Qed.
HB.instance Definition _ n :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (nderivn n)
(GRing.semilinear_linear (nderivn_is_linear n)).
Lemma nderivnD n : {morph nderivn n : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma nderivnB n : {morph nderivn n : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma nderivnMn n m p : (p *+ m)^`N(n) = p^`N(n) *+ m.
Proof. exact: linearMn. Qed.
Lemma nderivnMNn n m p : (p *- m)^`N(n) = p^`N(n) *- m.
Proof. exact: linearMNn. Qed.
Lemma nderivnN n : {morph nderivn n : p / - p}.
Proof. exact: linearN. Qed.
Lemma nderivnZ n : scalable (nderivn n).
Proof. exact: linearZZ. Qed.
Lemma nderivnMXaddC n p c :
(p * 'X + c%:P)^`N(n.+1) = p^`N(n) + p^`N(n.+1) * 'X.
Proof.
apply/polyP=> i; rewrite coef_nderivn !coefD !coefMX coefC.
rewrite !addSn /= !coef_nderivn addr0 binS mulrnDr addrC; congr (_ + _).
by rewrite addSnnS; case: i; rewrite // addn0 bin_small.
Qed.
Lemma nderivn_poly0 p n : size p <= n -> p^`N(n) = 0.
Proof.
move=> le_p_n; apply/polyP=> i; rewrite coef_nderivn.
rewrite nth_default; first by rewrite mul0rn coef0.
exact/(leq_trans le_p_n)/leq_addr.
Qed.
Lemma nderiv_taylor p x h :
GRing.comm x h -> p.[x + h] = \sum_(i < size p) p^`N(i).[x] * h ^+ i.
Proof.
move/commrX=> cxh; elim/poly_ind: p => [|p c IHp].
by rewrite size_poly0 big_ord0 horner0.
rewrite hornerMXaddC size_MXaddC.
have [-> | nz_p] := eqVneq p 0.
rewrite horner0 !simp; have [-> | _] := c =P 0; first by rewrite big_ord0.
by rewrite size_poly0 big_ord_recl big_ord0 nderivn0 hornerC !simp.
rewrite big_ord_recl nderivn0 !simp hornerMXaddC addrAC; congr (_ + _).
rewrite mulrDr {}IHp !big_distrl polySpred //= big_ord_recl /= mulr1 -addrA.
rewrite nderivn0 /bump /(addn 1) /=; congr (_ + _).
rewrite !big_ord_recr /= nderivnMXaddC -mulrA -exprSr -polySpred // !addrA.
congr (_ + _); last by rewrite (nderivn_poly0 (leqnn _)) !simp.
rewrite addrC -big_split /=; apply: eq_bigr => i _.
by rewrite nderivnMXaddC !hornerE_comm /= mulrDl -!mulrA -exprSr cxh.
Qed.
Lemma nderiv_taylor_wide n p x h :
GRing.comm x h -> size p <= n ->
p.[x + h] = \sum_(i < n) p^`N(i).[x] * h ^+ i.
Proof.
move/nderiv_taylor=> -> le_p_n.
rewrite (big_ord_widen n (fun i => p^`N(i).[x] * h ^+ i)) // big_mkcond.
apply: eq_bigr => i _; case: leqP => // /nderivn_poly0->.
by rewrite horner0 simp.
Qed.
Lemma eq_poly n E1 E2 : (forall i, i < n -> E1 i = E2 i) ->
poly n E1 = poly n E2 :> {poly R}.
Proof. by move=> E; rewrite !poly_def; apply: eq_bigr => i _; rewrite E. Qed.
End PolynomialTheory.
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyN`")]
Notation size_opp := size_polyN (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_poly instead.")]
Notation char_poly := pchar_poly (only parsing).
Prenex Implicits polyC polyCK Poly polyseqK lead_coef root horner polyOver.
Arguments monic {R}.
Notation "\poly_ ( i < n ) E" := (poly n (fun i => E)) : ring_scope.
Notation "c %:P" := (polyC c) : ring_scope.
Notation "'X" := (polyX _) : ring_scope.
Notation "''X^' n" := ('X ^+ n) : ring_scope.
Notation "p .[ x ]" := (horner p x) : ring_scope.
Notation "n .-unity_root" := (root_of_unity n) : ring_scope.
Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope.
Notation "a ^` ()" := (deriv a) : ring_scope.
Notation "a ^` ( n )" := (derivn n a) : ring_scope.
Notation "a ^`N ( n )" := (nderivn n a) : ring_scope.
Arguments monic_pred _ _ /.
Arguments monicP {R p}.
Arguments rootP {R p x}.
Arguments rootPf {R p x}.
Arguments rootPt {R p x}.
Arguments unity_rootP {R n z}.
Arguments polyOver_pred _ _ _ /.
Arguments polyOverP {R S p}.
Arguments polyC_inj {R} [x1 x2] eq_x12P.
Arguments eq_poly {R n} [E1] E2 eq_E12.
Section IdomainPrimRoot.
Variables (R : idomainType) (n : nat) (z : R).
Hypothesis prim_z : n.-primitive_root z.
Import prime.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma prim_root_pcharF p : (p %| n)%N -> p \in [pchar R] = false.
Proof.
move=> pn; apply: contraTF isT => pchar_p; have p_prime := pcharf_prime pchar_p.
have /dvdnP[[|k] n_eq_kp] := pn; first by rewrite n_eq_kp in (n_gt0).
have /eqP := prim_expr_order prim_z; rewrite n_eq_kp exprM.
rewrite -pFrobenius_autE -(pFrobenius_aut1 pchar_p) -subr_eq0 -rmorphB/=.
rewrite pFrobenius_autE expf_eq0// prime_gt0//= subr_eq0 => /eqP.
move=> /eqP; rewrite -(prim_order_dvd prim_z) n_eq_kp.
rewrite -[X in _ %| X]muln1 dvdn_pmul2l ?dvdn1// => /eqP peq1.
by rewrite peq1 in p_prime.
Qed.
Lemma pchar_prim_root : [pchar R]^'.-nat n.
Proof. by apply/pnatP=> // p pp pn; rewrite inE/= prim_root_pcharF. Qed.
Lemma prim_root_pi_eq0 m : \pi(n).-nat m -> m%:R != 0 :> R.
Proof.
by rewrite natf_neq0_pchar; apply: sub_in_pnat => p _; apply: pnatPpi pchar_prim_root.
Qed.
Lemma prim_root_dvd_eq0 m : (m %| n)%N -> m%:R != 0 :> R.
Proof.
case: m => [|m mn]; first by rewrite dvd0n gtn_eqF.
by rewrite prim_root_pi_eq0 ?(sub_in_pnat (in1W (pi_of_dvd mn _))) ?pnat_pi.
Qed.
Lemma prim_root_natf_neq0 : n%:R != 0 :> R.
Proof. by rewrite prim_root_dvd_eq0. Qed.
End IdomainPrimRoot.
#[deprecated(since="mathcomp 2.4.0", note="Use prim_root_pcharF instead.")]
Notation prim_root_charF := prim_root_pcharF (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_prim_root instead.")]
Notation char_prim_root := pchar_prim_root (only parsing).
(* Container morphism. *)
Section MapPoly.
Section Definitions.
Variables (aR rR : nzRingType) (f : aR -> rR).
Definition map_poly (p : {poly aR}) := \poly_(i < size p) f p`_i.
(* Alternative definition; the one above is more convenient because it lets *)
(* us use the lemmas on \poly, e.g., size (map_poly p) <= size p is an *)
(* instance of size_poly. *)
Lemma map_polyE p : map_poly p = Poly (map f p).
Proof.
rewrite /map_poly unlock; congr Poly.
apply: (@eq_from_nth _ 0); rewrite size_mkseq ?size_map // => i lt_i_p.
by rewrite [RHS](nth_map 0) ?nth_mkseq.
Qed.
Definition commr_rmorph u := forall x, GRing.comm u (f x).
Definition horner_morph u of commr_rmorph u := fun p => (map_poly p).[u].
End Definitions.
Variables aR rR : nzRingType.
Section Combinatorial.
Variables (iR : nzRingType) (f : aR -> rR).
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Lemma map_poly0 : 0^f = 0.
Proof. by rewrite map_polyE polyseq0. Qed.
Lemma eq_map_poly (g : aR -> rR) : f =1 g -> map_poly f =1 map_poly g.
Proof. by move=> eq_fg p; rewrite !map_polyE (eq_map eq_fg). Qed.
Lemma map_poly_id g (p : {poly iR}) :
{in (p : seq iR), g =1 id} -> map_poly g p = p.
Proof. by move=> g_id; rewrite map_polyE map_id_in ?polyseqK. Qed.
Lemma coef_map_id0 p i : f 0 = 0 -> (p^f)`_i = f p`_i.
Proof.
by move=> f0; rewrite coef_poly; case: ltnP => // le_p_i; rewrite nth_default.
Qed.
Lemma map_Poly_id0 s : f 0 = 0 -> (Poly s)^f = Poly (map f s).
Proof.
move=> f0; apply/polyP=> j; rewrite coef_map_id0 ?coef_Poly //.
have [/(nth_map 0 0)->// | le_s_j] := ltnP j (size s).
by rewrite !nth_default ?size_map.
Qed.
Lemma map_poly_comp_id0 (g : iR -> aR) p :
f 0 = 0 -> map_poly (f \o g) p = (map_poly g p)^f.
Proof. by move=> f0; rewrite map_polyE map_comp -map_Poly_id0 -?map_polyE. Qed.
Lemma size_map_poly_id0 p : f (lead_coef p) != 0 -> size p^f = size p.
Proof. by move=> nz_fp; apply: size_poly_eq. Qed.
Lemma map_poly_eq0_id0 p : f (lead_coef p) != 0 -> (p^f == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /size_map_poly_id0->. Qed.
Lemma lead_coef_map_id0 p :
f 0 = 0 -> f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p).
Proof.
by move=> f0 nz_fp; rewrite lead_coefE coef_map_id0 ?size_map_poly_id0.
Qed.
Hypotheses (inj_f : injective f) (f_0 : f 0 = 0).
Lemma size_map_inj_poly p : size p^f = size p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite map_poly0 !size_poly0.
by rewrite size_map_poly_id0 // -f_0 (inj_eq inj_f) lead_coef_eq0.
Qed.
Lemma map_inj_poly : injective (map_poly f).
Proof.
move=> p q /polyP eq_pq; apply/polyP=> i; apply: inj_f.
by rewrite -!coef_map_id0 ?eq_pq.
Qed.
Lemma lead_coef_map_inj p : lead_coef p^f = f (lead_coef p).
Proof. by rewrite !lead_coefE size_map_inj_poly coef_map_id0. Qed.
End Combinatorial.
Lemma map_polyK (f : aR -> rR) g :
cancel g f -> f 0 = 0 -> cancel (map_poly g) (map_poly f).
Proof.
by move=> gK f_0 p; rewrite /= -map_poly_comp_id0 ?map_poly_id // => x _ //=.
Qed.
Lemma eq_in_map_poly_id0 (f g : aR -> rR) (S : addrClosed aR) :
f 0 = 0 -> g 0 = 0 -> {in S, f =1 g} ->
{in polyOver S, map_poly f =1 map_poly g}.
Proof.
move=> f0 g0 eq_fg p pP; apply/polyP => i.
by rewrite !coef_map_id0// eq_fg// (polyOverP _).
Qed.
Lemma eq_in_map_poly (f g : {additive aR -> rR}) (S : addrClosed aR) :
{in S, f =1 g} -> {in polyOver S, map_poly f =1 map_poly g}.
Proof. by move=> /eq_in_map_poly_id0; apply; rewrite //?raddf0. Qed.
Section Additive.
Variables (iR : nzRingType) (f : {additive aR -> rR}).
Local Notation "p ^f" := (map_poly (GRing.Additive.sort f) p) : ring_scope.
Lemma coef_map p i : p^f`_i = f p`_i.
Proof. exact: coef_map_id0 (raddf0 f). Qed.
Lemma map_Poly s : (Poly s)^f = Poly (map f s).
Proof. exact: map_Poly_id0 (raddf0 f). Qed.
Lemma map_poly_comp (g : iR -> aR) p :
map_poly (f \o g) p = map_poly f (map_poly g p).
Proof. exact: map_poly_comp_id0 (raddf0 f). Qed.
Fact map_poly_is_zmod_morphism : zmod_morphism (map_poly f).
Proof. by move=> p q; apply/polyP=> i; rewrite !(coef_map, coefB) raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `map_poly_is_zmod_morphism` instead")]
Definition map_poly_is_additive := map_poly_is_zmod_morphism.
HB.instance Definition _ :=
GRing.isZmodMorphism.Build {poly aR} {poly rR} (map_poly f)
map_poly_is_zmod_morphism.
Lemma map_polyC a : (a%:P)^f = (f a)%:P.
Proof. by apply/polyP=> i; rewrite !(coef_map, coefC) -!mulrb raddfMn. Qed.
Lemma lead_coef_map_eq p :
f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p).
Proof. exact: lead_coef_map_id0 (raddf0 f). Qed.
End Additive.
Variable f : {rmorphism aR -> rR}.
Implicit Types p : {poly aR}.
Local Notation "p ^f" := (map_poly (GRing.RMorphism.sort f) p) : ring_scope.
Fact map_poly_is_monoid_morphism : monoid_morphism (map_poly f).
Proof.
split=> [|p q]; apply/polyP=> i.
by rewrite !(coef_map, coef1) /= rmorph_nat.
rewrite coef_map /= !coefM /= !rmorph_sum; apply: eq_bigr => j _.
by rewrite !coef_map rmorphM.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `map_poly_is_monoid_morphism` instead")]
Definition map_poly_is_multiplicative :=
(fun g => (g.2, g.1)) map_poly_is_monoid_morphism.
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly aR} {poly rR} (map_poly f)
map_poly_is_monoid_morphism.
Lemma map_polyZ c p : (c *: p)^f = f c *: p^f.
Proof. by apply/polyP=> i; rewrite !(coef_map, coefZ) /= rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build aR {poly aR} {poly rR} (f \; *:%R) (map_poly f)
map_polyZ.
Lemma map_polyX : ('X)^f = 'X.
Proof. by apply/polyP=> i; rewrite coef_map !coefX /= rmorph_nat. Qed.
Lemma map_polyXn n : ('X^n)^f = 'X^n.
Proof. by rewrite rmorphXn /= map_polyX. Qed.
Lemma map_polyXaddC x : ('X + x%:P)^f = 'X + (f x)%:P.
Proof. by rewrite raddfD/= map_polyX map_polyC. Qed.
Lemma map_polyXsubC x : ('X - x%:P)^f = 'X - (f x)%:P.
Proof. by rewrite raddfB/= map_polyX map_polyC. Qed.
Lemma map_prod_XsubC I (rI : seq I) P F :
(\prod_(i <- rI | P i) ('X - (F i)%:P))^f =
\prod_(i <- rI | P i) ('X - (f (F i))%:P).
Proof.
by rewrite rmorph_prod//; apply/eq_bigr => x /=; rewrite map_polyXsubC.
Qed.
Lemma prod_map_poly (ar : seq aR) P :
\prod_(x <- map f ar | P x) ('X - x%:P) =
(\prod_(x <- ar | P (f x)) ('X - x%:P))^f.
Proof. by rewrite big_map map_prod_XsubC. Qed.
Lemma monic_map p : p \is monic -> p^f \is monic.
Proof.
move/monicP=> mon_p; rewrite monicE.
by rewrite lead_coef_map_eq mon_p /= rmorph1 ?oner_neq0.
Qed.
Lemma horner_map p x : p^f.[f x] = f p.[x].
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(rmorph0, horner0).
rewrite hornerMXaddC !rmorphD !rmorphM /=.
by rewrite map_polyX map_polyC hornerMXaddC IHp.
Qed.
Lemma map_comm_poly p x : comm_poly p x -> comm_poly p^f (f x).
Proof. by rewrite /comm_poly horner_map -!rmorphM // => ->. Qed.
Lemma map_comm_coef p x : comm_coef p x -> comm_coef p^f (f x).
Proof. by move=> cpx i; rewrite coef_map -!rmorphM ?cpx. Qed.
Lemma rmorph_root p x : root p x -> root p^f (f x).
Proof. by move/eqP=> px0; rewrite rootE horner_map px0 rmorph0. Qed.
Lemma rmorph_unity_root n z : n.-unity_root z -> n.-unity_root (f z).
Proof.
move/rmorph_root; rewrite rootE rmorphB hornerD hornerN.
by rewrite /= map_polyXn rmorph1 hornerC hornerXn subr_eq0 unity_rootE.
Qed.
Section HornerMorph.
Variable u : rR.
Hypothesis cfu : commr_rmorph f u.
Lemma horner_morphC a : horner_morph cfu a%:P = f a.
Proof. by rewrite /horner_morph map_polyC hornerC. Qed.
Lemma horner_morphX : horner_morph cfu 'X = u.
Proof. by rewrite /horner_morph map_polyX hornerX. Qed.
Fact horner_is_linear : linear_for (f \; *%R) (horner_morph cfu).
Proof. by move=> c p q; rewrite /horner_morph linearP /= hornerD hornerZ. Qed.
Fact horner_is_monoid_morphism : monoid_morphism (horner_morph cfu).
Proof.
split=> [|p q]; first by rewrite /horner_morph rmorph1 hornerC.
rewrite /horner_morph rmorphM /= hornerM_comm //.
by apply: comm_coef_poly => i; rewrite coef_map cfu.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `horner_is_monoid_morphism` instead")]
Definition horner_is_multiplicative :=
(fun g => (g.2, g.1)) horner_is_monoid_morphism.
HB.instance Definition _ :=
GRing.isSemilinear.Build aR {poly aR} rR _ (horner_morph cfu)
(GRing.semilinear_linear horner_is_linear).
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly aR} rR (horner_morph cfu)
horner_is_monoid_morphism.
End HornerMorph.
Lemma deriv_map p : p^f^`() = (p^`())^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_deriv) //= rmorphMn. Qed.
Lemma derivn_map p n : p^f^`(n) = (p^`(n))^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_derivn) //= rmorphMn. Qed.
Lemma nderivn_map p n : p^f^`N(n) = (p^`N(n))^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_nderivn) //= rmorphMn. Qed.
End MapPoly.
Lemma mapf_root (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R})
(p : {poly F}) (x : F) : root (map_poly f p) (f x) = root p x.
Proof. by rewrite !rootE horner_map fmorph_eq0. Qed.
(* Morphisms from the polynomial ring, and the initiality of polynomials *)
(* with respect to these. *)
Section MorphPoly.
Variable (aR rR : nzRingType) (pf : {rmorphism {poly aR} -> rR}).
Lemma poly_morphX_comm : commr_rmorph (pf \o polyC) (pf 'X).
Proof. by move=> a; rewrite /GRing.comm /= -!rmorphM // commr_polyX. Qed.
Lemma poly_initial : pf =1 horner_morph poly_morphX_comm.
Proof.
apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0.
by rewrite !rmorphD !rmorphM /= -{}IHp horner_morphC ?horner_morphX.
Qed.
End MorphPoly.
Notation "p ^:P" := (map_poly polyC p) : ring_scope.
Section PolyCompose.
Variable R : nzRingType.
Implicit Types p q : {poly R}.
Definition comp_poly q p := p^:P.[q].
Local Notation "p \Po q" := (comp_poly q p) : ring_scope.
Lemma size_map_polyC p : size p^:P = size p.
Proof. exact/(size_map_inj_poly polyC_inj). Qed.
Lemma map_polyC_eq0 p : (p^:P == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 size_map_polyC. Qed.
Lemma root_polyC p x : root p^:P x%:P = root p x.
Proof. by rewrite rootE horner_map polyC_eq0. Qed.
Lemma comp_polyE p q : p \Po q = \sum_(i < size p) p`_i *: q^+i.
Proof.
by rewrite [p \Po q]horner_poly; apply: eq_bigr => i _; rewrite mul_polyC.
Qed.
Lemma coef_comp_poly p q n :
(p \Po q)`_n = \sum_(i < size p) p`_i * (q ^+ i)`_n.
Proof. by rewrite comp_polyE coef_sum; apply: eq_bigr => i; rewrite coefZ. Qed.
Lemma polyOver_comp (ringS : semiringClosed R) :
{in polyOver ringS &, forall p q, p \Po q \in polyOver ringS}.
Proof.
move=> p q /polyOverP Sp Sq; rewrite comp_polyE rpred_sum // => i _.
by rewrite polyOverZ ?rpredX.
Qed.
Lemma comp_polyCr p c : p \Po c%:P = p.[c]%:P.
Proof. exact: horner_map. Qed.
Lemma comp_poly0r p : p \Po 0 = (p`_0)%:P.
Proof. by rewrite comp_polyCr horner_coef0. Qed.
Lemma comp_polyC c p : c%:P \Po p = c%:P.
Proof. by rewrite /(_ \Po p) map_polyC hornerC. Qed.
Fact comp_poly_is_linear p : linear (comp_poly p).
Proof.
move=> a q r.
by rewrite /comp_poly rmorphD /= map_polyZ !hornerE_comm mul_polyC.
Qed.
HB.instance Definition _ p :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (comp_poly p)
(GRing.semilinear_linear (comp_poly_is_linear p)).
Lemma comp_poly0 p : 0 \Po p = 0.
Proof. exact: raddf0. Qed.
Lemma comp_polyD p q r : (p + q) \Po r = (p \Po r) + (q \Po r).
Proof. exact: raddfD. Qed.
Lemma comp_polyB p q r : (p - q) \Po r = (p \Po r) - (q \Po r).
Proof. exact: raddfB. Qed.
Lemma comp_polyZ c p q : (c *: p) \Po q = c *: (p \Po q).
Proof. exact: linearZZ. Qed.
Lemma comp_polyXr p : p \Po 'X = p.
Proof. by rewrite -{2}/(idfun p) poly_initial. Qed.
Lemma comp_polyX p : 'X \Po p = p.
Proof. by rewrite /(_ \Po p) map_polyX hornerX. Qed.
Lemma comp_poly_MXaddC c p q : (p * 'X + c%:P) \Po q = (p \Po q) * q + c%:P.
Proof.
by rewrite /(_ \Po q) rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC.
Qed.
Lemma comp_polyXaddC_K p z : (p \Po ('X + z%:P)) \Po ('X - z%:P) = p.
Proof.
have addzK: ('X + z%:P) \Po ('X - z%:P) = 'X.
by rewrite raddfD /= comp_polyC comp_polyX subrK.
elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_poly0.
rewrite comp_poly_MXaddC linearD /= comp_polyC {1}/comp_poly rmorphM /=.
by rewrite hornerM_comm /comm_poly -!/(_ \Po _) ?IHp ?addzK ?commr_polyX.
Qed.
Lemma size_comp_poly_leq p q :
size (p \Po q) <= ((size p).-1 * (size q).-1).+1.
Proof.
rewrite comp_polyE (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _.
rewrite (leq_trans (size_scale_leq _ _))//.
rewrite (leq_trans (size_poly_exp_leq _ _))//.
by rewrite ltnS mulnC leq_mul // -{2}(subnKC (valP i)) leq_addr.
Qed.
Lemma comp_Xn_poly p n : 'X^n \Po p = p ^+ n.
Proof. by rewrite /(_ \Po p) map_polyXn hornerXn. Qed.
Lemma coef_comp_poly_Xn p n i : 0 < n ->
(p \Po 'X^n)`_i = if n %| i then p`_(i %/ n) else 0.
Proof.
move=> n_gt0; rewrite comp_polyE; under eq_bigr do rewrite -exprM mulnC.
rewrite coef_sumMXn/=; case: dvdnP => [[j ->]|nD]; last first.
by rewrite big1// => j /eqP ?; case: nD; exists j.
under eq_bigl do rewrite eqn_mul2r gtn_eqF//.
by rewrite big_ord1_eq if_nth ?leqVgt ?mulnK.
Qed.
Lemma comp_poly_Xn p n : 0 < n ->
p \Po 'X^n = \poly_(i < size p * n) if n %| i then p`_(i %/ n) else 0.
Proof.
move=> n_gt0; apply/polyP => i; rewrite coef_comp_poly_Xn // coef_poly.
case: dvdnP => [[k ->]|]; last by rewrite if_same.
by rewrite mulnK // ltn_mul2r n_gt0 if_nth ?leqVgt.
Qed.
End PolyCompose.
Notation "p \Po q" := (comp_poly q p) : ring_scope.
Lemma map_comp_poly (aR rR : nzRingType) (f : {rmorphism aR -> rR}) p q :
map_poly f (p \Po q) = map_poly f p \Po map_poly f q.
Proof.
elim/poly_ind: p => [|p a IHp]; first by rewrite !raddf0.
rewrite comp_poly_MXaddC !rmorphD !rmorphM /= !map_polyC map_polyX.
by rewrite comp_poly_MXaddC -IHp.
Qed.
Section Surgery.
Variable R : nzRingType.
Implicit Type p q : {poly R}.
(* Even part of a polynomial *)
Definition even_poly p : {poly R} := \poly_(i < uphalf (size p)) p`_i.*2.
Lemma size_even_poly p : size (even_poly p) <= uphalf (size p).
Proof. exact: size_poly. Qed.
Lemma coef_even_poly p i : (even_poly p)`_i = p`_i.*2.
Proof. by rewrite coef_poly gtn_uphalf_double if_nth ?leqVgt. Qed.
Lemma even_polyE s p : size p <= s.*2 -> even_poly p = \poly_(i < s) p`_i.*2.
Proof.
move=> pLs2; apply/polyP => i; rewrite coef_even_poly !coef_poly if_nth //.
by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?leq_double.
Qed.
Lemma size_even_poly_eq p : odd (size p) ->
size (even_poly p) = uphalf (size p).
Proof.
move=> p_even; rewrite size_poly_eq// double_pred odd_uphalfK//=.
by rewrite lead_coef_eq0 -size_poly_eq0; case: size p_even.
Qed.
Lemma even_polyD p q : even_poly (p + q) = even_poly p + even_poly q.
Proof. by apply/polyP => i; rewrite !(coef_even_poly, coefD). Qed.
Lemma even_polyZ k p : even_poly (k *: p) = k *: even_poly p.
Proof. by apply/polyP => i; rewrite !(coefZ, coef_even_poly). Qed.
Fact even_poly_is_linear : linear even_poly.
Proof. by move=> k p q; rewrite even_polyD even_polyZ. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly R} {poly R} _ even_poly
(GRing.semilinear_linear even_poly_is_linear).
Lemma even_polyC (c : R) : even_poly c%:P = c%:P.
Proof. by apply/polyP => i; rewrite coef_even_poly !coefC; case: i. Qed.
(* Odd part of a polynomial *)
Definition odd_poly p : {poly R} := \poly_(i < (size p)./2) p`_i.*2.+1.
Lemma size_odd_poly p : size (odd_poly p) <= (size p)./2.
Proof. exact: size_poly. Qed.
Lemma coef_odd_poly p i : (odd_poly p)`_i = p`_i.*2.+1.
Proof. by rewrite coef_poly gtn_half_double if_nth ?leqVgt. Qed.
Lemma odd_polyE s p :
size p <= s.*2.+1 -> odd_poly p = \poly_(i < s) p`_i.*2.+1.
Proof.
move=> pLs2; apply/polyP => i; rewrite coef_odd_poly !coef_poly if_nth //.
by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?ltnS ?leq_double.
Qed.
Lemma odd_polyC (c : R) : odd_poly c%:P = 0.
Proof. by apply/polyP => i; rewrite coef_odd_poly !coefC; case: i. Qed.
Lemma odd_polyD p q : odd_poly (p + q) = odd_poly p + odd_poly q.
Proof. by apply/polyP => i; rewrite !(coef_odd_poly, coefD). Qed.
Lemma odd_polyZ k p : odd_poly (k *: p) = k *: odd_poly p.
Proof. by apply/polyP => i; rewrite !(coefZ, coef_odd_poly). Qed.
Fact odd_poly_is_linear : linear odd_poly.
Proof. by move=> k p q; rewrite odd_polyD odd_polyZ. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly R} {poly R} _ odd_poly
(GRing.semilinear_linear odd_poly_is_linear).
Lemma size_odd_poly_eq p : ~~ odd (size p) -> size (odd_poly p) = (size p)./2.
Proof.
have [->|p_neq0] := eqVneq p 0; first by rewrite odd_polyC size_poly0.
move=> p_odd; rewrite size_poly_eq// -subn1 doubleB subn2 even_halfK//.
rewrite prednK ?lead_coef_eq0// ltn_predRL.
by move: p_neq0 p_odd; rewrite -size_poly_eq0; case: (size p) => [|[]].
Qed.
Lemma odd_polyMX p : odd_poly (p * 'X) = even_poly p.
Proof.
have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC.
by apply/polyP => i; rewrite !coef_poly size_mulX // coefMX.
Qed.
Lemma even_polyMX p : even_poly (p * 'X) = odd_poly p * 'X.
Proof.
have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC mul0r.
by apply/polyP => -[|i]; rewrite !(coefMX, coef_poly, if_same, size_mulX).
Qed.
Lemma sum_even_poly p :
\sum_(i < size p | ~~ odd i) p`_i *: 'X^i = even_poly p \Po 'X^2.
Proof.
apply/polyP => i; rewrite coef_comp_poly_Xn// coef_sumMXn coef_even_poly.
rewrite (big_ord1_cond_eq _ _ (negb \o _))/= -dvdn2 andbC -muln2.
by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt.
Qed.
Lemma sum_odd_poly p :
\sum_(i < size p | odd i) p`_i *: 'X^i = (odd_poly p \Po 'X^2) * 'X.
Proof.
apply/polyP => i; rewrite coefMX coef_comp_poly_Xn// coef_sumMXn coef_odd_poly/=.
case: i => [|i]//=; first by rewrite big_andbC big1// => -[[|j]//].
rewrite big_ord1_cond_eq/= -dvdn2 andbC -muln2.
by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt.
Qed.
(* Decomposition in odd and even part *)
Lemma poly_even_odd p : even_poly p \Po 'X^2 + (odd_poly p \Po 'X^2) * 'X = p.
Proof.
rewrite -sum_even_poly -sum_odd_poly addrC -(bigID _ xpredT).
by rewrite -[RHS]coefK poly_def.
Qed.
(* take and drop for polynomials *)
Definition take_poly m p := \poly_(i < m) p`_i.
Lemma size_take_poly m p : size (take_poly m p) <= m.
Proof. exact: size_poly. Qed.
Lemma coef_take_poly m p i : (take_poly m p)`_i = if i < m then p`_i else 0.
Proof. exact: coef_poly. Qed.
Lemma take_poly_id m p : size p <= m -> take_poly m p = p.
Proof.
move=> /leq_trans gep; apply/polyP => i; rewrite coef_poly if_nth//=.
by case: ltnP => // /gep->.
Qed.
Lemma take_polyD m p q : take_poly m (p + q) = take_poly m p + take_poly m q.
Proof.
by apply/polyP => i; rewrite !(coefD, coef_poly); case: leqP; rewrite ?add0r.
Qed.
Lemma take_polyZ k m p : take_poly m (k *: p) = k *: take_poly m p.
Proof.
apply/polyP => i; rewrite !(coefZ, coef_take_poly); case: leqP => //.
by rewrite mulr0.
Qed.
Fact take_poly_is_linear m : linear (take_poly m).
Proof. by move=> k p q; rewrite take_polyD take_polyZ. Qed.
HB.instance Definition _ m :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (take_poly m)
(GRing.semilinear_linear (take_poly_is_linear m)).
Lemma take_poly_sum m I r P (p : I -> {poly R}) :
take_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r| P i) take_poly m (p i).
Proof. exact: linear_sum. Qed.
Lemma take_poly0l p : take_poly 0 p = 0.
Proof. exact/size_poly_leq0P/size_take_poly. Qed.
Lemma take_poly0r m : take_poly m 0 = 0.
Proof. exact: linear0. Qed.
Lemma take_polyMXn m n p :
take_poly m (p * 'X^n) = take_poly (m - n) p * 'X^n.
Proof.
have [->|/eqP p_neq0] := p =P 0; first by rewrite !(mul0r, take_poly0r).
apply/polyP => i; rewrite !(coef_take_poly, coefMXn).
by have [iLn|nLi] := leqP n i; rewrite ?if_same// ltn_sub2rE.
Qed.
Lemma take_polyMXn_0 n p : take_poly n (p * 'X^n) = 0.
Proof. by rewrite take_polyMXn subnn take_poly0l mul0r. Qed.
Lemma take_polyDMXn n p q : size p <= n -> take_poly n (p + q * 'X^n) = p.
Proof. by move=> ?; rewrite take_polyD take_poly_id// take_polyMXn_0 addr0. Qed.
Definition drop_poly m p := \poly_(i < size p - m) p`_(i + m).
Lemma coef_drop_poly m p i : (drop_poly m p)`_i = p`_(i + m).
Proof. by rewrite coef_poly ltn_subRL addnC if_nth ?leqVgt. Qed.
Lemma drop_poly_eq0 m p : size p <= m -> drop_poly m p = 0.
Proof.
move=> sLm; apply/polyP => i; rewrite coef_poly coef0 ltn_subRL addnC.
by rewrite if_nth ?leqVgt// nth_default// (leq_trans _ (leq_addl _ _)).
Qed.
Lemma size_drop_poly n p : size (drop_poly n p) = (size p - n)%N.
Proof.
have [pLn|nLp] := leqP (size p) n.
by rewrite (eqP pLn) drop_poly_eq0 ?size_poly0.
have p_neq0 : p != 0 by rewrite -size_poly_gt0 (leq_trans _ nLp).
by rewrite size_poly_eq// predn_sub subnK ?lead_coef_eq0// -ltnS -polySpred.
Qed.
Lemma sum_drop_poly n p :
\sum_(n <= i < size p) p`_i *: 'X^i = drop_poly n p * 'X^n.
Proof.
rewrite (big_addn 0) big_mkord /drop_poly poly_def mulr_suml.
by apply: eq_bigr => i _; rewrite exprD scalerAl.
Qed.
Lemma drop_polyD m p q : drop_poly m (p + q) = drop_poly m p + drop_poly m q.
Proof. by apply/polyP => i; rewrite coefD !coef_drop_poly coefD. Qed.
Lemma drop_polyZ k m p : drop_poly m (k *: p) = k *: drop_poly m p.
Proof. by apply/polyP => i; rewrite coefZ !coef_drop_poly coefZ. Qed.
Fact drop_poly_is_linear m : linear (drop_poly m).
Proof. by move=> k p q; rewrite drop_polyD drop_polyZ. Qed.
HB.instance Definition _ m :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (drop_poly m)
(GRing.semilinear_linear (drop_poly_is_linear m)).
Lemma drop_poly_sum m I r P (p : I -> {poly R}) :
drop_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r | P i) drop_poly m (p i).
Proof. exact: linear_sum. Qed.
Lemma drop_poly0l p : drop_poly 0 p = p.
Proof. by apply/polyP => i; rewrite coef_poly subn0 addn0 if_nth ?leqVgt. Qed.
Lemma drop_poly0r m : drop_poly m 0 = 0. Proof. exact: linear0. Qed.
Lemma drop_polyMXn m n p :
drop_poly m (p * 'X^n) = drop_poly (m - n) p * 'X^(n - m).
Proof.
have [->|p_neq0] := eqVneq p 0; first by rewrite mul0r !drop_poly0r mul0r.
apply/polyP => i; rewrite !(coefMXn, coef_drop_poly) ltn_subRL [(m + i)%N]addnC.
have [i_small|i_big]// := ltnP; congr nth.
by have [mn|/ltnW mn] := leqP m n;
rewrite (eqP mn) (addn0, subn0) (subnBA, addnBA).
Qed.
Lemma drop_polyMXn_id n p : drop_poly n (p * 'X^ n) = p.
Proof. by rewrite drop_polyMXn subnn drop_poly0l expr0 mulr1. Qed.
Lemma drop_polyDMXn n p q : size p <= n -> drop_poly n (p + q * 'X^n) = q.
Proof. by move=> ?; rewrite drop_polyD drop_poly_eq0// drop_polyMXn_id add0r. Qed.
Lemma poly_take_drop n p : take_poly n p + drop_poly n p * 'X^n = p.
Proof.
apply/polyP => i; rewrite coefD coefMXn coef_take_poly coef_drop_poly.
by case: ltnP => ni; rewrite ?addr0 ?add0r//= subnK.
Qed.
Lemma eqp_take_drop n p q :
take_poly n p = take_poly n q -> drop_poly n p = drop_poly n q -> p = q.
Proof.
by move=> tpq dpq; rewrite -[p](poly_take_drop n) -[q](poly_take_drop n) tpq dpq.
Qed.
End Surgery.
Definition coefE :=
(coef0, coef1, coefC, coefX, coefXn, coef_sumMXn,
coefZ, coefMC, coefCM, coefXnM, coefMXn, coefXM, coefMX, coefMNn, coefMn,
coefN, coefB, coefD, coef_even_poly, coef_odd_poly,
coef_take_poly, coef_drop_poly, coef_cons, coef_Poly, coef_poly,
coef_deriv, coef_nderivn, coef_derivn, coef_map, coef_sum,
coef_comp_poly_Xn, coef_comp_poly).
Section PolynomialComNzRing.
Variable R : comNzRingType.
Implicit Types p q : {poly R}.
Fact poly_mul_comm p q : p * q = q * p.
Proof.
apply/polyP=> i; rewrite coefM coefMr.
by apply: eq_bigr => j _; rewrite mulrC.
Qed.
HB.instance Definition _ := GRing.PzRing_hasCommutativeMul.Build (polynomial R)
poly_mul_comm.
HB.instance Definition _ := GRing.Lalgebra_isComAlgebra.Build R (polynomial R).
Lemma coef_prod_XsubC (ps : seq R) (n : nat) :
(n <= size ps)%N ->
(\prod_(p <- ps) ('X - p%:P))`_n =
(-1) ^+ (size ps - n)%N *
\sum_(I in {set 'I_(size ps)} | #|I| == (size ps - n)%N)
\prod_(i in I) ps`_i.
Proof.
move=> nle.
under eq_bigr => i _ do rewrite addrC -raddfN/=.
rewrite -{1}(in_tupleE ps) -(map_tnth_enum (_ ps)) big_map.
rewrite enumT bigA_distr /= coef_sum.
transitivity (\sum_(I in {set 'I_(size ps)}) if #|I| == (size ps - n)%N then
\prod_(i < size ps | i \in I) - ps`_i else 0).
apply eq_bigr => I _.
rewrite big_if/= big_const iter_mulr_1 -rmorph_prod/= coefCM coefXn.
under eq_bigr => i _ do rewrite (tnth_nth 0)/=.
rewrite -[#|I| == _](eqn_add2r n) subnK//.
rewrite -[X in (_ + _)%N == X]card_ord -(cardC I) eqn_add2l.
by case: ifP; rewrite ?mulr1 ?mulr0.
by rewrite -big_mkcond mulr_sumr/=; apply: eq_bigr => I /eqP <-; rewrite prodrN.
Qed.
Lemma coefPn_prod_XsubC (ps : seq R) : size ps != 0 ->
(\prod_(p <- ps) ('X - p%:P))`_(size ps).-1 =
- \sum_(p <- ps) p.
Proof.
rewrite coef_prod_XsubC ?leq_pred// => ps0.
have -> : (size ps - (size ps).-1 = 1)%N.
by move: ps0; case: (size ps) => // n _; exact: subSnn.
rewrite expr1 mulN1r; congr GRing.opp.
set f : 'I_(size ps) -> {set 'I_(size ps)} := fun a => [set a].
transitivity (\sum_(I in imset f (mem setT)) \prod_(i in I) ps`_i).
apply: congr_big => // I /=.
by apply/cards1P/imsetP => [[a ->] | [a _ ->]]; exists a.
rewrite big_imset/=; last first.
by move=> i j _ _ ij; apply/set1P; rewrite -/(f j) -ij set11.
rewrite -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT.
apply: congr_big => // i; first exact: in_setT.
by rewrite big_set1 (tnth_nth 0).
Qed.
Lemma coef0_prod_XsubC (ps : seq R) :
(\prod_(p <- ps) ('X - p%:P))`_0 =
(-1) ^+ (size ps) * \prod_(p <- ps) p.
Proof.
rewrite coef_prod_XsubC// subn0; congr GRing.mul.
transitivity (\sum_(I in [set setT : {set 'I_(size ps)}]) \prod_(i in I) ps`_i).
apply: congr_big =>// i/=.
apply/idP/set1P => [/eqP cardE | ->]; last by rewrite cardsT card_ord.
by apply/eqP; rewrite eqEcard subsetT cardsT card_ord cardE leqnn.
rewrite big_set1 -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT.
apply: congr_big => // i; first exact: in_setT.
by rewrite (tnth_nth 0).
Qed.
Lemma hornerM p q x : (p * q).[x] = p.[x] * q.[x].
Proof. by rewrite hornerM_comm //; apply: mulrC. Qed.
Lemma horner_exp p x n : (p ^+ n).[x] = p.[x] ^+ n.
Proof. by rewrite horner_exp_comm //; apply: mulrC. Qed.
Lemma horner_prod I r (P : pred I) (F : I -> {poly R}) x :
(\prod_(i <- r | P i) F i).[x] = \prod_(i <- r | P i) (F i).[x].
Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (hornerM, hornerC). Qed.
Definition hornerE :=
(hornerD, hornerN, hornerX, hornerC, horner_exp,
simp, hornerCM, hornerZ, hornerM, horner_cons).
Definition horner_eval (x : R) := horner^~ x.
Lemma horner_evalE x p : horner_eval x p = p.[x]. Proof. by []. Qed.
Fact horner_eval_is_linear x : linear_for *%R (horner_eval x).
Proof.
have cxid: commr_rmorph idfun x by apply: mulrC.
have evalE : horner_eval x =1 horner_morph cxid.
by move=> p; congr _.[x]; rewrite map_poly_id.
by move=> c p q; rewrite !evalE linearP.
Qed.
Fact horner_eval_is_monoid_morphism x : monoid_morphism (horner_eval x).
Proof.
have cxid: commr_rmorph idfun x by apply: mulrC.
have evalE : horner_eval x =1 horner_morph cxid.
by move=> p; congr _.[x]; rewrite map_poly_id.
by split=> [|p q]; rewrite !evalE ?rmorph1// rmorphM.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `horner_eval_is_monoid_morphism` instead")]
Definition horner_eval_is_multiplicative x :=
(fun g => (g.2, g.1)) (horner_eval_is_monoid_morphism x).
HB.instance Definition _ x :=
GRing.isSemilinear.Build R {poly R} R _ (horner_eval x)
(GRing.semilinear_linear (horner_eval_is_linear x)).
HB.instance Definition _ x :=
GRing.isMonoidMorphism.Build {poly R} R (horner_eval x)
(horner_eval_is_monoid_morphism x).
Section HornerAlg.
Variable A : algType R. (* For univariate polys, commutativity is not needed *)
Section Defs.
Variable a : A.
Lemma in_alg_comm : commr_rmorph (in_alg A) a.
Proof. move=> r /=; by rewrite /GRing.comm comm_alg. Qed.
Definition horner_alg := horner_morph in_alg_comm.
Lemma horner_algC c : horner_alg c%:P = c%:A.
Proof. exact: horner_morphC. Qed.
Lemma horner_algX : horner_alg 'X = a.
Proof. exact: horner_morphX. Qed.
HB.instance Definition _ := GRing.LRMorphism.on horner_alg.
End Defs.
Variable (pf : {lrmorphism {poly R} -> A}).
Lemma poly_alg_initial : pf =1 horner_alg (pf 'X).
Proof.
apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0.
rewrite !rmorphD !rmorphM /= -{}IHp horner_algC ?horner_algX.
by rewrite -alg_polyC rmorph_alg.
Qed.
End HornerAlg.
Fact comp_poly_is_monoid_morphism q : monoid_morphism (comp_poly q).
Proof.
split=> [|p1 p2]; first by rewrite comp_polyC.
by rewrite /comp_poly rmorphM hornerM_comm //; apply: mulrC.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `comp_poly_is_monoid_morphism` instead")]
Definition comp_poly_multiplicative q :=
(fun g => (g.2, g.1)) (comp_poly_is_monoid_morphism q).
HB.instance Definition _ q := GRing.isMonoidMorphism.Build _ _ (comp_poly q)
(comp_poly_is_monoid_morphism q).
Lemma comp_polyM p q r : (p * q) \Po r = (p \Po r) * (q \Po r).
Proof. exact: rmorphM. Qed.
Lemma comp_polyA p q r : p \Po (q \Po r) = (p \Po q) \Po r.
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_polyC.
by rewrite !comp_polyD !comp_polyM !comp_polyX IHp !comp_polyC.
Qed.
Lemma horner_comp p q x : (p \Po q).[x] = p.[q.[x]].
Proof. by apply: polyC_inj; rewrite -!comp_polyCr comp_polyA. Qed.
Lemma root_comp p q x : root (p \Po q) x = root p (q.[x]).
Proof. by rewrite !rootE horner_comp. Qed.
Lemma deriv_comp p q : (p \Po q) ^`() = (p ^`() \Po q) * q^`().
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(deriv0, comp_poly0) mul0r.
rewrite comp_poly_MXaddC derivD derivC derivM IHp derivMXaddC comp_polyD.
by rewrite comp_polyM comp_polyX addr0 addrC mulrAC -mulrDl.
Qed.
Lemma deriv_exp p n : (p ^+ n)^`() = p^`() * p ^+ n.-1 *+ n.
Proof.
elim: n => [|n IHn]; first by rewrite expr0 mulr0n derivC.
by rewrite exprS derivM {}IHn (mulrC p) mulrnAl -mulrA -exprSr mulrS; case n.
Qed.
Definition derivCE := (derivE, deriv_exp).
End PolynomialComNzRing.
Section PolynomialIdomain.
(* Integral domain structure on poly *)
Variable R : idomainType.
Implicit Types (a b x y : R) (p q r m : {poly R}).
Lemma size_mul p q : p != 0 -> q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
by move=> nz_p nz_q; rewrite -size_proper_mul ?mulf_neq0 ?lead_coef_eq0.
Qed.
Fact poly_idomainAxiom p q : p * q = 0 -> (p == 0) || (q == 0).
Proof.
move=> pq0; apply/norP=> [[p_nz q_nz]]; move/eqP: (size_mul p_nz q_nz).
by rewrite eq_sym pq0 size_poly0 (polySpred p_nz) (polySpred q_nz) addnS.
Qed.
Definition poly_unit : pred {poly R} :=
fun p => (size p == 1) && (p`_0 \in GRing.unit).
Definition poly_inv p := if p \in poly_unit then (p`_0)^-1%:P else p.
Fact poly_mulVp : {in poly_unit, left_inverse 1 poly_inv *%R}.
Proof.
move=> p Up; rewrite /poly_inv Up.
by case/andP: Up => /size_poly1P[c _ ->]; rewrite coefC -polyCM => /mulVr->.
Qed.
Fact poly_intro_unit p q : q * p = 1 -> p \in poly_unit.
Proof.
move=> pq1; apply/andP; split; last first.
apply/unitrP; exists q`_0.
by rewrite 2!mulrC -!/(coefp 0 _) -rmorphM pq1 rmorph1.
have: size (q * p) == 1 by rewrite pq1 size_poly1.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0.
have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r size_poly0.
rewrite size_mul // (polySpred nz_p) (polySpred nz_q) addnS addSn !eqSS.
by rewrite addn_eq0 => /andP[].
Qed.
Fact poly_inv_out : {in [predC poly_unit], poly_inv =1 id}.
Proof. by rewrite /poly_inv => p /negbTE/= ->. Qed.
HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build (polynomial R)
poly_mulVp poly_intro_unit poly_inv_out.
HB.instance Definition _ := GRing.ComUnitRing_isIntegral.Build (polynomial R)
poly_idomainAxiom.
Lemma poly_unitE p :
(p \in GRing.unit) = (size p == 1) && (p`_0 \in GRing.unit).
Proof. by []. Qed.
Lemma poly_invE p : p ^-1 = if p \in GRing.unit then (p`_0)^-1%:P else p.
Proof. by []. Qed.
Lemma polyCV c : c%:P^-1 = (c^-1)%:P.
Proof.
have [/rmorphV-> // | nUc] := boolP (c \in GRing.unit).
by rewrite !invr_out // poly_unitE coefC (negbTE nUc) andbF.
Qed.
Lemma rootM p q x : root (p * q) x = root p x || root q x.
Proof. by rewrite !rootE hornerM mulf_eq0. Qed.
Lemma rootZ x a p : a != 0 -> root (a *: p) x = root p x.
Proof. by move=> nz_a; rewrite -mul_polyC rootM rootC (negPf nz_a). Qed.
Lemma root_exp p n a: comm_poly p a -> (0 < n)%N -> root (p ^+ n) a = root p a.
Proof. by move=> ? n0; rewrite !rootE horner_exp_comm// expf_eq0 n0. Qed.
Lemma size_scale a p : a != 0 -> size (a *: p) = size p.
Proof. by move/lregP/lreg_size->. Qed.
Lemma size_Cmul a p : a != 0 -> size (a%:P * p) = size p.
Proof. by rewrite mul_polyC => /size_scale->. Qed.
Lemma lead_coefM p q : lead_coef (p * q) = lead_coef p * lead_coef q.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(mul0r, lead_coef0).
have [-> | nz_q] := eqVneq q 0; first by rewrite !(mulr0, lead_coef0).
by rewrite lead_coef_proper_mul // mulf_neq0 ?lead_coef_eq0.
Qed.
Lemma lead_coef_prod I rI (P : {pred I}) (p : I -> {poly R}) :
lead_coef (\prod_(i <- rI | P i) p i) = \prod_(i <- rI | P i) lead_coef (p i).
Proof. by apply/big_morph/lead_coef1; apply: lead_coefM. Qed.
Lemma lead_coefZ a p : lead_coef (a *: p) = a * lead_coef p.
Proof. by rewrite -mul_polyC lead_coefM lead_coefC. Qed.
Lemma scale_poly_eq0 a p : (a *: p == 0) = (a == 0) || (p == 0).
Proof. by rewrite -mul_polyC mulf_eq0 polyC_eq0. Qed.
Lemma size_prod (I : finType) (P : pred I) (F : I -> {poly R}) :
(forall i, P i -> F i != 0) ->
size (\prod_(i | P i) F i) = ((\sum_(i | P i) size (F i)).+1 - #|P|)%N.
Proof.
move=> nzF; transitivity (\sum_(i | P i) (size (F i)).-1).+1; last first.
apply: canRL (addKn _) _; rewrite addnS -sum1_card -big_split /=.
by congr _.+1; apply: eq_bigr => i /nzF/polySpred.
elim/big_rec2: _ => [|i d p /nzF nzFi IHp]; first by rewrite size_poly1.
by rewrite size_mul // -?size_poly_eq0 IHp // addnS polySpred.
Qed.
Lemma size_prod_seq (I : eqType) (s : seq I) (F : I -> {poly R}) :
(forall i, i \in s -> F i != 0) ->
size (\prod_(i <- s) F i) = ((\sum_(i <- s) size (F i)).+1 - size s)%N.
Proof.
move=> nzF; rewrite big_tnth size_prod; last by move=> i; rewrite nzF ?mem_tnth.
by rewrite cardT /= size_enum_ord [in RHS]big_tnth.
Qed.
Lemma size_mul_eq1 p q : (size (p * q) == 1) = ((size p == 1) && (size q == 1)).
Proof.
have [->|pNZ] := eqVneq p 0; first by rewrite mul0r size_poly0.
have [->|qNZ] := eqVneq q 0; first by rewrite mulr0 size_poly0 andbF.
rewrite size_mul //.
by move: pNZ qNZ; rewrite -!size_poly_gt0; (do 2 case: size) => //= n [|[|]].
Qed.
Lemma size_prod_seq_eq1 (I : eqType) (s : seq I) (P : pred I) (F : I -> {poly R}) :
reflect (forall i, P i && (i \in s) -> size (F i) = 1)
(size (\prod_(i <- s | P i) F i) == 1%N).
Proof.
rewrite (big_morph _ (id1:=true) size_mul_eq1) ?size_polyC ?oner_neq0//.
rewrite big_all_cond; apply/(iffP allP).
by move=> h i /andP[Pi ins]; apply/eqP/(implyP (h i ins) Pi).
by move=> h i ins; apply/implyP => Pi; rewrite h ?Pi.
Qed.
Lemma size_prod_eq1 (I : finType) (P : pred I) (F : I -> {poly R}) :
reflect (forall i, P i -> size (F i) = 1)
(size (\prod_(i | P i) F i) == 1).
Proof.
apply: (iffP (size_prod_seq_eq1 _ _ _)) => Hi i.
by move=> Pi; apply: Hi; rewrite Pi /= mem_index_enum.
by rewrite mem_index_enum andbT; apply: Hi.
Qed.
Lemma size_exp p n : (size (p ^+ n)).-1 = ((size p).-1 * n)%N.
Proof.
elim: n => [|n IHn]; first by rewrite size_poly1 muln0.
have [-> | nz_p] := eqVneq p 0; first by rewrite exprS mul0r size_poly0.
rewrite exprS size_mul ?expf_neq0 // mulnS -{}IHn.
by rewrite polySpred // [size (p ^+ n)]polySpred ?expf_neq0 ?addnS.
Qed.
Lemma lead_coef_exp p n : lead_coef (p ^+ n) = lead_coef p ^+ n.
Proof.
elim: n => [|n IHn]; first by rewrite !expr0 lead_coef1.
by rewrite !exprS lead_coefM IHn.
Qed.
Lemma root_prod_XsubC rs x :
root (\prod_(a <- rs) ('X - a%:P)) x = (x \in rs).
Proof.
elim: rs => [|a rs IHrs]; first by rewrite rootE big_nil hornerC oner_eq0.
by rewrite big_cons rootM IHrs root_XsubC.
Qed.
Lemma root_exp_XsubC n a x : root (('X - a%:P) ^+ n.+1) x = (x == a).
Proof. by rewrite rootE horner_exp expf_eq0 [_ == 0]root_XsubC. Qed.
Lemma size_comp_poly p q :
(size (p \Po q)).-1 = ((size p).-1 * (size q).-1)%N.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite comp_poly0 size_poly0.
have [/size1_polyC-> | nc_q] := leqP (size q) 1.
by rewrite comp_polyCr !size_polyC -!sub1b -!subnS muln0.
have nz_q: q != 0 by rewrite -size_poly_eq0 -(subnKC nc_q).
rewrite mulnC comp_polyE (polySpred nz_p) /= big_ord_recr /= addrC.
rewrite size_polyDl size_scale ?lead_coef_eq0 ?size_exp //=.
rewrite [ltnRHS]polySpred ?expf_neq0 // ltnS size_exp.
rewrite (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _.
rewrite (leq_trans (size_scale_leq _ _)) // polySpred ?expf_neq0 //.
by rewrite size_exp -(subnKC nc_q) ltn_pmul2l.
Qed.
Lemma lead_coef_comp p q : size q > 1 ->
lead_coef (p \Po q) = (lead_coef p) * lead_coef q ^+ (size p).-1.
Proof.
move=> q_gt1; rewrite !lead_coefE coef_comp_poly size_comp_poly.
have [->|nz_p] := eqVneq p 0; first by rewrite size_poly0 big_ord0 coef0 mul0r.
rewrite polySpred //= big_ord_recr /= big1 ?add0r => [|i _].
by rewrite -!lead_coefE -lead_coef_exp !lead_coefE size_exp mulnC.
rewrite [X in _ * X]nth_default ?mulr0 ?(leq_trans (size_poly_exp_leq _ _)) //.
by rewrite mulnC ltn_mul2r -subn1 subn_gt0 q_gt1 /=.
Qed.
Lemma comp_poly_eq0 p q : size q > 1 -> (p \Po q == 0) = (p == 0).
Proof.
move=> sq_gt1; rewrite -!lead_coef_eq0 lead_coef_comp //.
rewrite mulf_eq0 expf_eq0 !lead_coef_eq0 -[q == 0]size_poly_leq0.
by rewrite [_ <= 0]leqNgt (leq_ltn_trans _ sq_gt1) ?andbF ?orbF.
Qed.
Lemma size_comp_poly2 p q : size q = 2 -> size (p \Po q) = size p.
Proof.
move=> sq2; have [->|pN0] := eqVneq p 0; first by rewrite comp_polyC.
by rewrite polySpred ?size_comp_poly ?comp_poly_eq0 ?sq2 // muln1 polySpred.
Qed.
Lemma comp_poly2_eq0 p q : size q = 2 -> (p \Po q == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /size_comp_poly2->. Qed.
Theorem max_poly_roots p rs :
p != 0 -> all (root p) rs -> uniq rs -> size rs < size p.
Proof.
elim: rs p => [p pn0 _ _ | r rs ihrs p pn0] /=; first by rewrite size_poly_gt0.
case/andP => rpr arrs /andP [rnrs urs]; case/factor_theorem: rpr => q epq.
have [q0 | ?] := eqVneq q 0; first by move: pn0; rewrite epq q0 mul0r eqxx.
have -> : size p = (size q).+1.
by rewrite epq size_Mmonic ?monicXsubC // size_XsubC addnC.
suff /eq_in_all h : {in rs, root q =1 root p} by apply: ihrs => //; rewrite h.
move=> x xrs; rewrite epq rootM root_XsubC orbC; case: (eqVneq x r) => // exr.
by move: rnrs; rewrite -exr xrs.
Qed.
Lemma roots_geq_poly_eq0 p (rs : seq R) : all (root p) rs -> uniq rs ->
(size rs >= size p)%N -> p = 0.
Proof. by move=> ??; apply: contraTeq => ?; rewrite leqNgt max_poly_roots. Qed.
End PolynomialIdomain.
(* FIXME: these are seamingly artificial ways to close the inheritance graph *)
(* We make parameters more and more precise to trigger completion by HB *)
HB.instance Definition _ (R : countNzRingType) :=
[Countable of polynomial R by <:].
HB.instance Definition _ (R : countComNzRingType) :=
[Countable of polynomial R by <:].
HB.instance Definition _ (R : countIdomainType) :=
[Countable of polynomial R by <:].
Section MapFieldPoly.
Variables (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R}).
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Lemma size_map_poly p : size p^f = size p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite rmorph0 !size_poly0.
by rewrite size_poly_eq // fmorph_eq0 // lead_coef_eq0.
Qed.
Lemma lead_coef_map p : lead_coef p^f = f (lead_coef p).
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(rmorph0, lead_coef0).
by rewrite lead_coef_map_eq // fmorph_eq0 // lead_coef_eq0.
Qed.
Lemma map_poly_eq0 p : (p^f == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 size_map_poly. Qed.
Lemma map_poly_inj : injective (map_poly f).
Proof.
move=> p q eqfpq; apply/eqP; rewrite -subr_eq0 -map_poly_eq0.
by rewrite rmorphB /= eqfpq subrr.
Qed.
Lemma map_monic p : (p^f \is monic) = (p \is monic).
Proof. by rewrite [in LHS]monicE lead_coef_map fmorph_eq1. Qed.
Lemma map_poly_com p x : comm_poly p^f (f x).
Proof. exact: map_comm_poly (mulrC x _). Qed.
Lemma fmorph_root p x : root p^f (f x) = root p x.
Proof. by rewrite rootE horner_map // fmorph_eq0. Qed.
Lemma fmorph_unity_root n z : n.-unity_root (f z) = n.-unity_root z.
Proof. by rewrite !unity_rootE -(inj_eq (fmorph_inj f)) rmorphXn ?rmorph1. Qed.
Lemma fmorph_primitive_root n z :
n.-primitive_root (f z) = n.-primitive_root z.
Proof.
by congr (_ && _); apply: eq_forallb => i; rewrite fmorph_unity_root.
Qed.
End MapFieldPoly.
Arguments map_poly_inj {F R} f [p1 p2] : rename.
Section MaxRoots.
Variable R : unitRingType.
Implicit Types (x y : R) (rs : seq R) (p : {poly R}).
Definition diff_roots (x y : R) := (x * y == y * x) && (y - x \in GRing.unit).
Fixpoint uniq_roots rs :=
if rs is x :: rs' then all (diff_roots x) rs' && uniq_roots rs' else true.
Lemma uniq_roots_prod_XsubC p rs :
all (root p) rs -> uniq_roots rs ->
exists q, p = q * \prod_(z <- rs) ('X - z%:P).
Proof.
elim: rs => [|z rs IHrs] /=; first by rewrite big_nil; exists p; rewrite mulr1.
case/andP=> rpz rprs /andP[drs urs]; case: IHrs => {urs rprs}// q def_p.
have [|q' def_q] := factor_theorem q z _; last first.
by exists q'; rewrite big_cons mulrA -def_q.
rewrite {p}def_p in rpz.
elim/last_ind: rs drs rpz => [|rs t IHrs] /=; first by rewrite big_nil mulr1.
rewrite all_rcons => /andP[/andP[/eqP czt Uzt] /IHrs{}IHrs].
rewrite -cats1 big_cat big_seq1 /= mulrA rootE hornerM_comm; last first.
by rewrite /comm_poly hornerXsubC mulrBl mulrBr czt.
rewrite hornerXsubC -opprB mulrN oppr_eq0 -(mul0r (t - z)).
by rewrite (inj_eq (mulIr Uzt)) => /IHrs.
Qed.
Theorem max_ring_poly_roots p rs :
p != 0 -> all (root p) rs -> uniq_roots rs -> size rs < size p.
Proof.
move=> nz_p _ /(@uniq_roots_prod_XsubC p)[// | q def_p]; rewrite def_p in nz_p *.
have nz_q: q != 0 by apply: contraNneq nz_p => ->; rewrite mul0r.
rewrite size_Mmonic ?monic_prod_XsubC // (polySpred nz_q) addSn /=.
by rewrite size_prod_XsubC leq_addl.
Qed.
Lemma all_roots_prod_XsubC p rs :
size p = (size rs).+1 -> all (root p) rs -> uniq_roots rs ->
p = lead_coef p *: \prod_(z <- rs) ('X - z%:P).
Proof.
move=> size_p /uniq_roots_prod_XsubC def_p Urs.
case/def_p: Urs => q -> {p def_p} in size_p *.
have [q0 | nz_q] := eqVneq q 0; first by rewrite q0 mul0r size_poly0 in size_p.
have{q nz_q size_p} /size_poly1P[c _ ->]: size q == 1.
rewrite -(eqn_add2r (size rs)) add1n -size_p.
by rewrite size_Mmonic ?monic_prod_XsubC // size_prod_XsubC addnS.
by rewrite lead_coef_Mmonic ?monic_prod_XsubC // lead_coefC mul_polyC.
Qed.
End MaxRoots.
Section FieldRoots.
Variable F : fieldType.
Implicit Types (p : {poly F}) (rs : seq F).
Lemma poly2_root p : size p = 2 -> {r | root p r}.
Proof.
case: p => [[|p0 [|p1 []]] //= nz_p1]; exists (- p0 / p1).
by rewrite /root addr_eq0 /= mul0r add0r mulrC divfK ?opprK.
Qed.
Lemma uniq_rootsE rs : uniq_roots rs = uniq rs.
Proof.
elim: rs => //= r rs ->; congr (_ && _); rewrite -has_pred1 -all_predC.
by apply: eq_all => t; rewrite /diff_roots mulrC eqxx unitfE subr_eq0.
Qed.
Lemma root_ZXsubC (a b r : F) : a != 0 ->
root (a *: 'X - b%:P) r = (r == b / a).
Proof.
move=> a0; rewrite rootE !hornerE.
by rewrite -[r in RHS]divr1 eqr_div ?oner_neq0// mulr1 mulrC subr_eq0.
Qed.
Section UnityRoots.
Variable n : nat.
Lemma max_unity_roots rs :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs <= n.
Proof.
move=> n_gt0 rs_n_1 Urs; have szPn := size_XnsubC (1 : F) n_gt0.
by rewrite -ltnS -szPn max_poly_roots -?size_poly_eq0 ?szPn.
Qed.
Lemma mem_unity_roots rs :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs = n ->
n.-unity_root =i rs.
Proof.
move=> n_gt0 rs_n_1 Urs sz_rs_n x; rewrite -topredE /=.
apply/idP/idP=> xn1; last exact: (allP rs_n_1).
apply: contraFT (ltnn n) => not_rs_x.
by rewrite -{1}sz_rs_n (@max_unity_roots (x :: rs)) //= ?xn1 ?not_rs_x.
Qed.
(* Showing the existence of a primitive root requires the theory in cyclic. *)
Variable z : F.
Hypothesis prim_z : n.-primitive_root z.
Let zn := [seq z ^+ i | i <- index_iota 0 n].
Lemma factor_Xn_sub_1 : \prod_(0 <= i < n) ('X - (z ^+ i)%:P) = 'X^n - 1.
Proof.
transitivity (\prod_(w <- zn) ('X - w%:P)); first by rewrite big_map.
have n_gt0: n > 0 := prim_order_gt0 prim_z.
rewrite (@all_roots_prod_XsubC _ ('X^n - 1) zn); first 1 last.
- by rewrite size_XnsubC // size_map size_iota subn0.
- apply/allP=> _ /mapP[i _ ->] /=; rewrite rootE !hornerE.
by rewrite exprAC (prim_expr_order prim_z) expr1n subrr.
- rewrite uniq_rootsE map_inj_in_uniq ?iota_uniq // => i j.
rewrite !mem_index_iota => ltin ltjn /eqP.
by rewrite (eq_prim_root_expr prim_z) !modn_small // => /eqP.
by rewrite (monicP (monicXnsubC 1 n_gt0)) scale1r.
Qed.
Lemma prim_rootP x : x ^+ n = 1 -> {i : 'I_n | x = z ^+ i}.
Proof.
move=> xn1; pose logx := [pred i : 'I_n | x == z ^+ i].
case: (pickP logx) => [i /eqP-> | no_i]; first by exists i.
case: notF; suffices{no_i}: x \in zn.
case/mapP=> i; rewrite mem_index_iota => lt_i_n def_x.
by rewrite -(no_i (Ordinal lt_i_n)) /= -def_x.
rewrite -root_prod_XsubC big_map factor_Xn_sub_1.
by rewrite [root _ x]unity_rootE xn1.
Qed.
End UnityRoots.
End FieldRoots.
Section MapPolyRoots.
Variables (F : fieldType) (R : unitRingType) (f : {rmorphism F -> R}).
Lemma map_diff_roots x y : diff_roots (f x) (f y) = (x != y).
Proof.
rewrite /diff_roots -rmorphB // fmorph_unit // subr_eq0 //.
by rewrite rmorph_comm // eqxx eq_sym.
Qed.
Lemma map_uniq_roots s : uniq_roots (map f s) = uniq s.
Proof.
elim: s => //= x s ->; congr (_ && _); elim: s => //= y s ->.
by rewrite map_diff_roots -negb_or.
Qed.
End MapPolyRoots.
Section AutPolyRoot.
(* The action of automorphisms on roots of unity. *)
Variable F : fieldType.
Implicit Types u v : {rmorphism F -> F}.
Lemma aut_prim_rootP u z n :
n.-primitive_root z -> {k | coprime k n & u z = z ^+ k}.
Proof.
move=> prim_z; have:= prim_z; rewrite -(fmorph_primitive_root u) => prim_uz.
have [[k _] /= def_uz] := prim_rootP prim_z (prim_expr_order prim_uz).
by exists k; rewrite // -(prim_root_exp_coprime _ prim_z) -def_uz.
Qed.
Lemma aut_unity_rootP u z n : n > 0 -> z ^+ n = 1 -> {k | u z = z ^+ k}.
Proof.
by move=> _ /prim_order_exists[// | m /(aut_prim_rootP u)[k]]; exists k.
Qed.
Lemma aut_unity_rootC u v z n : n > 0 -> z ^+ n = 1 -> u (v z) = v (u z).
Proof.
move=> n_gt0 /(aut_unity_rootP _ n_gt0) def_z.
have [[i def_uz] [j def_vz]] := (def_z u, def_z v).
by rewrite def_vz def_uz !rmorphXn /= def_vz def_uz exprAC.
Qed.
End AutPolyRoot.
Module UnityRootTheory.
Notation "n .-unity_root" := (root_of_unity n) : unity_root_scope.
Notation "n .-primitive_root" := (primitive_root_of_unity n) : unity_root_scope.
Open Scope unity_root_scope.
Definition unity_rootE := unity_rootE.
Definition unity_rootP := @unity_rootP.
Arguments unity_rootP {R n z}.
Definition prim_order_exists := prim_order_exists.
Notation prim_order_gt0 := prim_order_gt0.
Notation prim_expr_order := prim_expr_order.
Definition prim_expr_mod := prim_expr_mod.
Definition prim_order_dvd := prim_order_dvd.
Definition eq_prim_root_expr := eq_prim_root_expr.
Definition rmorph_unity_root := rmorph_unity_root.
Definition fmorph_unity_root := fmorph_unity_root.
Definition fmorph_primitive_root := fmorph_primitive_root.
Definition max_unity_roots := max_unity_roots.
Definition mem_unity_roots := mem_unity_roots.
Definition prim_rootP := prim_rootP.
End UnityRootTheory.
Module Export Pdeg2.
Module Export Field.
Section Pdeg2Field.
Variable F : fieldType.
Hypothesis nz2 : 2 != 0 :> F.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let pneq0 : p != 0. Proof. by rewrite -size_poly_gt0 degp. Qed.
Let aneq0 : a != 0.
Proof. by move: pneq0; rewrite -lead_coef_eq0 lead_coefE degp. Qed.
Let a2neq0 : 2 * a != 0. Proof. by rewrite mulf_neq0. Qed.
Let sqa2neq0 : (2 * a) ^+ 2 != 0. Proof. exact: expf_neq0. Qed.
Let aa4 : 4 * a * a = (2 * a)^+2.
Proof. by rewrite expr2 mulrACA mulrA -natrM. Qed.
Let splitr (x : F) : x = x / 2 + x / 2.
Proof.
by apply: (mulIf nz2); rewrite -mulrDl mulfVK// mulr_natr mulr2n.
Qed.
Let pE : p = a *: 'X^2 + b *: 'X + c%:P.
Proof.
apply/polyP => + /[!coefE] => -[|[|[|i]]] /=; rewrite !Monoid.simpm//.
by rewrite nth_default// degp.
Qed.
Let delta := b ^+ 2 - 4 * a * c.
Lemma deg2_poly_canonical :
p = a *: (('X + (b / (2 * a))%:P)^+2 - (delta / (4 * a ^+ 2))%:P).
Proof.
rewrite pE sqrrD -!addrA scalerDr; congr +%R; rewrite addrA scalerDr; congr +%R.
- rewrite -mulrDr -polyCD -!mul_polyC mulrA mulrAC -polyCM.
by rewrite [a * _]mulrC mulrDl invfM -!mulrA mulVf// mulr1 -splitr.
- rewrite [a ^+ 2]expr2 mulrA aa4 -polyC_exp -polyCB expr_div_n -mulrBl subKr.
by rewrite scale_polyC mulrCA mulrACA aa4 mulrCA mulfV// mulr1.
Qed.
Variable r : F.
Hypothesis r_sqrt_delta : r ^+ 2 = delta.
Let r1 := (- b - r) / (2 * a).
Let r2 := (- b + r) / (2 * a).
Lemma deg2_poly_factor : p = a *: ('X - r1%:P) * ('X - r2%:P).
Proof.
rewrite [p]deg2_poly_canonical//= -/a -/b -/c -/delta /r1 /r2.
rewrite ![(- b + _) * _]mulrDl 2!polyCD 2!opprD 2!addrA !mulNr !polyCN !opprK.
rewrite -scalerAl [in RHS]mulrC -subr_sqr -polyC_exp -[4]/(2 * 2)%:R natrM.
by rewrite -expr2 -exprMn [in RHS]exprMn exprVn r_sqrt_delta.
Qed.
Lemma deg2_poly_root1 : root p r1.
Proof.
apply/factor_theorem.
by exists (a *: ('X - r2%:P)); rewrite deg2_poly_factor -!scalerAl mulrC.
Qed.
Lemma deg2_poly_root2 : root p r2.
Proof.
apply/factor_theorem.
by exists (a *: ('X - r1%:P)); rewrite deg2_poly_factor -!scalerAl.
Qed.
End Pdeg2Field.
End Field.
Module FieldMonic.
Section Pdeg2FieldMonic.
Variable F : fieldType.
Hypothesis nz2 : 2 != 0 :> F.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Hypothesis monicp : p \is monic.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed.
Let delta := b ^+ 2 - 4 * c.
Lemma deg2_poly_canonical : p = (('X + (b / 2)%:P)^+2 - (delta / 4)%:P).
Proof. by rewrite [p]deg2_poly_canonical// -/a a1 scale1r expr1n !mulr1. Qed.
Variable r : F.
Hypothesis r_sqrt_delta : r ^+ 2 = delta.
Let r1 := (- b - r) / 2.
Let r2 := (- b + r) / 2.
Lemma deg2_poly_factor : p = ('X - r1%:P) * ('X - r2%:P).
Proof.
by rewrite [p](@deg2_poly_factor _ _ _ _ r)// -/a a1 !mulr1 ?scale1r.
Qed.
Lemma deg2_poly_root1 : root p r1.
Proof.
rewrite /r1 -[2]mulr1 -[X in 2 * X]a1.
by apply: deg2_poly_root1; rewrite // -/a a1 mulr1.
Qed.
Lemma deg2_poly_root2 : root p r2.
Proof.
rewrite /r2 -[2]mulr1 -[X in 2 * X]a1.
by apply: deg2_poly_root2; rewrite // -/a a1 mulr1.
Qed.
End Pdeg2FieldMonic.
End FieldMonic.
End Pdeg2.
Section DecField.
Variable F : decFieldType.
Lemma dec_factor_theorem (p : {poly F}) :
{s : seq F & {q : {poly F} | p = q * \prod_(x <- s) ('X - x%:P)
/\ (q != 0 -> forall x, ~~ root q x)}}.
Proof.
pose polyT (p : seq F) := (foldr (fun c f => f * 'X_0 + c%:T) (0%R)%:T p)%T.
have eval_polyT (q : {poly F}) x : GRing.eval [:: x] (polyT q) = q.[x].
by rewrite /horner; elim: (val q) => //= ? ? ->.
have [n] := ubnP (size p); elim: n => // n IHn in p *.
have /decPcases /= := @satP F [::] ('exists 'X_0, polyT p == 0%T).
case: ifP => [_ /sig_eqW[x]|_ noroot]; last first.
exists [::], p; rewrite big_nil mulr1; split => // p_neq0 x.
by apply/negP=> /rootP rpx; apply: noroot; exists x; rewrite eval_polyT.
rewrite eval_polyT => /rootP/factor_theorem/sig_eqW[p1 ->].
have [->|nz_p1] := eqVneq p1 0; first by exists [::], 0; rewrite !mul0r eqxx.
rewrite size_Mmonic ?monicXsubC // size_XsubC addn2 => /IHn[s [q [-> irr_q]]].
by exists (rcons s x), q; rewrite -cats1 big_cat big_seq1 mulrA.
Qed.
End DecField.
Module PreClosedField.
Section UseAxiom.
Variable F : fieldType.
Hypothesis closedF : GRing.closed_field_axiom F.
Implicit Type p : {poly F}.
Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1).
Proof.
have [-> | nz_p] := eqVneq p 0.
by rewrite size_poly0; left; exists 0; rewrite root0.
rewrite neq_ltn [in _ < 1]polySpred //=.
apply: (iffP idP) => [p_gt1 | [a]]; last exact: root_size_gt1.
pose n := (size p).-1; have n_gt0: n > 0 by rewrite -ltnS -polySpred.
have [a Dan] := closedF (fun i => - p`_i / lead_coef p) n_gt0.
exists a; apply/rootP; rewrite horner_coef polySpred // big_ord_recr /= -/n.
rewrite {}Dan mulr_sumr -big_split big1 //= => i _.
by rewrite -!mulrA mulrCA mulNr mulVKf ?subrr ?lead_coef_eq0.
Qed.
Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0).
Proof.
apply: (iffP idP) => [nz_p | [x]]; last first.
by apply: contraNneq => ->; apply: root0.
have [[x /rootP p1x0]|] := altP (closed_rootP (p - 1)).
by exists x; rewrite -[p](subrK 1) /root hornerD p1x0 add0r hornerC oner_eq0.
rewrite negbK => /size_poly1P[c _ /(canRL (subrK 1)) Dp].
by exists 0; rewrite Dp -raddfD polyC_eq0 rootC in nz_p *.
Qed.
End UseAxiom.
End PreClosedField.
Section ClosedField.
Variable F : closedFieldType.
Implicit Type p : {poly F}.
Let closedF := @solve_monicpoly F.
Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1).
Proof. exact: PreClosedField.closed_rootP. Qed.
Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0).
Proof. exact: PreClosedField.closed_nonrootP. Qed.
Lemma closed_field_poly_normal p :
{r : seq F | p = lead_coef p *: \prod_(z <- r) ('X - z%:P)}.
Proof.
apply: sig_eqW; have [r [q [->]]] /= := dec_factor_theorem p.
have [->|] := eqVneq; first by exists [::]; rewrite mul0r lead_coef0 scale0r.
have [[x rqx ? /(_ isT x) /negP /(_ rqx)] //|] := altP (closed_rootP q).
rewrite negbK => /size_poly1P [c c_neq0-> _ _]; exists r.
rewrite mul_polyC lead_coefZ (monicP _) ?mulr1 //.
by rewrite monic_prod => // i; rewrite monicXsubC.
Qed.
End ClosedField.
|
Yoneda.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.Finite
import Mathlib.CategoryTheory.Limits.Opposites
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products
import Mathlib.CategoryTheory.Limits.Types.Shapes
import Mathlib.Topology.Category.TopCat.Limits.Products
/-!
# Yoneda presheaves on topologically concrete categories
This file develops some API for "topologically concrete" categories, defining universe polymorphic
"Yoneda presheaves" on such categories.
-/
universe w w' v u
open CategoryTheory Opposite Limits
variable {C : Type u} [Category.{v} C] (F : C ⥤ TopCat.{w}) (Y : Type w') [TopologicalSpace Y]
namespace ContinuousMap
/--
A universe polymorphic "Yoneda presheaf" on `C` given by continuous maps into a topoological space
`Y`.
-/
@[simps]
def yonedaPresheaf : Cᵒᵖ ⥤ Type (max w w') where
obj X := C(F.obj (unop X), Y)
map f g := ContinuousMap.comp g (F.map f.unop).hom
/--
A universe polymorphic Yoneda presheaf on `TopCat` given by continuous maps into a topoological
space `Y`.
-/
@[simps]
def yonedaPresheaf' : TopCat.{w}ᵒᵖ ⥤ Type (max w w') where
obj X := C((unop X).1, Y)
map f g := ContinuousMap.comp g f.unop.hom
theorem comp_yonedaPresheaf' : yonedaPresheaf F Y = F.op ⋙ yonedaPresheaf' Y := rfl
theorem piComparison_fac {α : Type} (X : α → TopCat) :
piComparison (yonedaPresheaf'.{w, w'} Y) (fun x ↦ op (X x)) =
(yonedaPresheaf' Y).map ((opCoproductIsoProduct X).inv ≫ (TopCat.sigmaIsoSigma X).inv.op) ≫
(equivEquivIso (sigmaEquiv Y (fun x ↦ (X x).1))).inv ≫ (Types.productIso _).inv := by
rw [← Category.assoc, Iso.eq_comp_inv]
ext
simp only [yonedaPresheaf', unop_op, piComparison, types_comp_apply,
Types.productIso_hom_comp_eval_apply, Types.pi_lift_π_apply, comp_apply, TopCat.coe_of,
unop_comp, Quiver.Hom.unop_op, sigmaEquiv, equivEquivIso_hom, Equiv.toIso_inv,
Equiv.coe_fn_symm_mk, comp_assoc, sigmaMk_apply, ← opCoproductIsoProduct_inv_comp_ι]
rfl
/-- The universe polymorphic Yoneda presheaf on `TopCat` preserves finite products. -/
noncomputable instance : PreservesFiniteProducts (yonedaPresheaf'.{w, w'} Y) where
preserves _ :=
{ preservesLimit := fun {K} =>
have : ∀ {α : Type} (X : α → TopCat), PreservesLimit (Discrete.functor (fun x ↦ op (X x)))
(yonedaPresheaf'.{w, w'} Y) := fun X => @PreservesProduct.of_iso_comparison _ _ _ _
(yonedaPresheaf' Y) _ (fun x ↦ op (X x)) _ _ (by rw [piComparison_fac]; infer_instance)
let i : K ≅ Discrete.functor (fun i ↦ op (unop (K.obj ⟨i⟩))) := Discrete.natIsoFunctor
preservesLimit_of_iso_diagram _ i.symm }
end ContinuousMap
|
Pi.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.Algebra.Notation.Pi.Basic
import Mathlib.Data.Set.BooleanAlgebra
import Mathlib.Data.Set.Piecewise
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Order.Interval.Set.UnorderedInterval
/-!
# Intervals in `pi`-space
In this we prove various simple lemmas about intervals in `Π i, α i`. Closed intervals (`Ici x`,
`Iic x`, `Icc x y`) are equal to products of their projections to `α i`, while (semi-)open intervals
usually include the corresponding products as proper subsets.
-/
-- Porting note: Added, since dot notation no longer works on `Function.update`
open Function
variable {ι : Type*} {α : ι → Type*}
namespace Set
section PiPreorder
variable [∀ i, Preorder (α i)] (x y : ∀ i, α i)
@[simp]
theorem pi_univ_Ici : (pi univ fun i ↦ Ici (x i)) = Ici x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Iic : (pi univ fun i ↦ Iic (x i)) = Iic x :=
ext fun y ↦ by simp [Pi.le_def]
@[simp]
theorem pi_univ_Icc : (pi univ fun i ↦ Icc (x i) (y i)) = Icc x y :=
ext fun y ↦ by simp [Pi.le_def, forall_and]
theorem piecewise_mem_Icc {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : ∀ i ∈ s, f₁ i ∈ Icc (g₁ i) (g₂ i)) (h₂ : ∀ i ∉ s, f₂ i ∈ Icc (g₁ i) (g₂ i)) :
s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
⟨le_piecewise (fun i hi ↦ (h₁ i hi).1) fun i hi ↦ (h₂ i hi).1,
piecewise_le (fun i hi ↦ (h₁ i hi).2) fun i hi ↦ (h₂ i hi).2⟩
theorem piecewise_mem_Icc' {s : Set ι} [∀ j, Decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : ∀ i, α i}
(h₁ : f₁ ∈ Icc g₁ g₂) (h₂ : f₂ ∈ Icc g₁ g₂) : s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
piecewise_mem_Icc (fun _ _ ↦ ⟨h₁.1 _, h₁.2 _⟩) fun _ _ ↦ ⟨h₂.1 _, h₂.2 _⟩
section Nonempty
theorem pi_univ_Ioi_subset [Nonempty ι] : (pi univ fun i ↦ Ioi (x i)) ⊆ Ioi x := fun _ hz ↦
⟨fun i ↦ le_of_lt <| hz i trivial, fun h ↦
(‹Nonempty ι›.elim) fun i ↦ not_lt_of_ge (h i) (hz i trivial)⟩
theorem pi_univ_Iio_subset [Nonempty ι] : (pi univ fun i ↦ Iio (x i)) ⊆ Iio x :=
pi_univ_Ioi_subset (α := fun i ↦ (α i)ᵒᵈ) x
theorem pi_univ_Ioo_subset [Nonempty ι] : (pi univ fun i ↦ Ioo (x i) (y i)) ⊆ Ioo x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
theorem pi_univ_Ioc_subset [Nonempty ι] : (pi univ fun i ↦ Ioc (x i) (y i)) ⊆ Ioc x y := fun _ hx ↦
⟨(pi_univ_Ioi_subset _) fun i hi ↦ (hx i hi).1, fun i ↦ (hx i trivial).2⟩
theorem pi_univ_Ico_subset [Nonempty ι] : (pi univ fun i ↦ Ico (x i) (y i)) ⊆ Ico x y := fun _ hx ↦
⟨fun i ↦ (hx i trivial).1, (pi_univ_Iio_subset _) fun i hi ↦ (hx i hi).2⟩
end Nonempty
variable [DecidableEq ι]
open Function (update)
theorem pi_univ_Ioc_update_left {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : x i₀ ≤ m) :
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) =
{ z | m < z i₀ } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc m (y i₀) = Ioi m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, ← inter_assoc,
inter_eq_self_of_subset_left (Ioi_subset_Ioi hm)]
simp_rw [univ_pi_update i₀ _ _ fun i z ↦ Ioc z (y i), ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem pi_univ_Ioc_update_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} (hm : m ≤ y i₀) :
(pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) =
{ z | z i₀ ≤ m } ∩ pi univ fun i ↦ Ioc (x i) (y i) := by
have : Ioc (x i₀) m = Iic m ∩ Ioc (x i₀) (y i₀) := by
rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_left_comm,
inter_eq_self_of_subset_left (Iic_subset_Iic.2 hm)]
simp_rw [univ_pi_update i₀ y m fun i z ↦ Ioc (x i) z, ← pi_inter_compl ({i₀} : Set ι),
singleton_pi', ← inter_assoc, this]
rfl
theorem disjoint_pi_univ_Ioc_update_left_right {x y : ∀ i, α i} {i₀ : ι} {m : α i₀} :
Disjoint (pi univ fun i ↦ Ioc (x i) (update y i₀ m i))
(pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) := by
rw [disjoint_left]
rintro z h₁ h₂
refine (h₁ i₀ (mem_univ _)).2.not_gt ?_
simpa only [Function.update_self] using (h₂ i₀ (mem_univ _)).1
end PiPreorder
section PiPartialOrder
variable [DecidableEq ι] [∀ i, PartialOrder (α i)]
-- Porting note: Dot notation on `Function.update` broke
theorem image_update_Icc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Icc a b = Icc (update f i a) (update f i b) := by
ext x
rw [← Set.pi_univ_Icc]
refine ⟨?_, fun h => ⟨x i, ?_, ?_⟩⟩
· rintro ⟨c, hc, rfl⟩
simpa [update_le_update_iff]
· simpa only [Function.update_self] using h i (mem_univ i)
· ext j
obtain rfl | hij := eq_or_ne i j
· exact Function.update_self ..
· simpa only [Function.update_of_ne hij.symm, le_antisymm_iff] using h j (mem_univ j)
theorem image_update_Ico (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ico a b = Ico (update f i a) (update f i b) := by
rw [← Icc_diff_right, ← Icc_diff_right, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioc a b = Ioc (update f i a) (update f i b) := by
rw [← Icc_diff_left, ← Icc_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Icc]
theorem image_update_Ioo (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' Ioo a b = Ioo (update f i a) (update f i b) := by
rw [← Ico_diff_left, ← Ico_diff_left, image_diff (update_injective _ _), image_singleton,
image_update_Ico]
theorem image_update_Icc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Icc a (f i) = Icc (update f i a) f := by simpa using image_update_Icc f i a (f i)
theorem image_update_Ico_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ico a (f i) = Ico (update f i a) f := by simpa using image_update_Ico f i a (f i)
theorem image_update_Ioc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioc a (f i) = Ioc (update f i a) f := by simpa using image_update_Ioc f i a (f i)
theorem image_update_Ioo_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' Ioo a (f i) = Ioo (update f i a) f := by simpa using image_update_Ioo f i a (f i)
theorem image_update_Icc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Icc (f i) b = Icc f (update f i b) := by simpa using image_update_Icc f i (f i) b
theorem image_update_Ico_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ico (f i) b = Ico f (update f i b) := by simpa using image_update_Ico f i (f i) b
theorem image_update_Ioc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ioc (f i) b = Ioc f (update f i b) := by simpa using image_update_Ioc f i (f i) b
theorem image_update_Ioo_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' Ioo (f i) b = Ioo f (update f i b) := by simpa using image_update_Ioo f i (f i) b
variable [∀ i, One (α i)]
@[to_additive]
theorem image_mulSingle_Icc (i : ι) (a b : α i) :
Pi.mulSingle i '' Icc a b = Icc (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Icc _ _ _ _
@[to_additive]
theorem image_mulSingle_Ico (i : ι) (a b : α i) :
Pi.mulSingle i '' Ico a b = Ico (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Ico _ _ _ _
@[to_additive]
theorem image_mulSingle_Ioc (i : ι) (a b : α i) :
Pi.mulSingle i '' Ioc a b = Ioc (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Ioc _ _ _ _
@[to_additive]
theorem image_mulSingle_Ioo (i : ι) (a b : α i) :
Pi.mulSingle i '' Ioo a b = Ioo (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_Ioo _ _ _ _
@[to_additive]
theorem image_mulSingle_Icc_left (i : ι) (a : α i) :
Pi.mulSingle i '' Icc a 1 = Icc (Pi.mulSingle i a) 1 :=
image_update_Icc_left _ _ _
@[to_additive]
theorem image_mulSingle_Ico_left (i : ι) (a : α i) :
Pi.mulSingle i '' Ico a 1 = Ico (Pi.mulSingle i a) 1 :=
image_update_Ico_left _ _ _
@[to_additive]
theorem image_mulSingle_Ioc_left (i : ι) (a : α i) :
Pi.mulSingle i '' Ioc a 1 = Ioc (Pi.mulSingle i a) 1 :=
image_update_Ioc_left _ _ _
@[to_additive]
theorem image_mulSingle_Ioo_left (i : ι) (a : α i) :
Pi.mulSingle i '' Ioo a 1 = Ioo (Pi.mulSingle i a) 1 :=
image_update_Ioo_left _ _ _
@[to_additive]
theorem image_mulSingle_Icc_right (i : ι) (b : α i) :
Pi.mulSingle i '' Icc 1 b = Icc 1 (Pi.mulSingle i b) :=
image_update_Icc_right _ _ _
@[to_additive]
theorem image_mulSingle_Ico_right (i : ι) (b : α i) :
Pi.mulSingle i '' Ico 1 b = Ico 1 (Pi.mulSingle i b) :=
image_update_Ico_right _ _ _
@[to_additive]
theorem image_mulSingle_Ioc_right (i : ι) (b : α i) :
Pi.mulSingle i '' Ioc 1 b = Ioc 1 (Pi.mulSingle i b) :=
image_update_Ioc_right _ _ _
@[to_additive]
theorem image_mulSingle_Ioo_right (i : ι) (b : α i) :
Pi.mulSingle i '' Ioo 1 b = Ioo 1 (Pi.mulSingle i b) :=
image_update_Ioo_right _ _ _
end PiPartialOrder
section PiLattice
variable [∀ i, Lattice (α i)]
@[simp]
theorem pi_univ_uIcc (a b : ∀ i, α i) : (pi univ fun i => uIcc (a i) (b i)) = uIcc a b :=
pi_univ_Icc _ _
variable [DecidableEq ι]
theorem image_update_uIcc (f : ∀ i, α i) (i : ι) (a b : α i) :
update f i '' uIcc a b = uIcc (update f i a) (update f i b) :=
(image_update_Icc _ _ _ _).trans <| by simp_rw [uIcc, update_sup, update_inf]
theorem image_update_uIcc_left (f : ∀ i, α i) (i : ι) (a : α i) :
update f i '' uIcc a (f i) = uIcc (update f i a) f := by
simpa using image_update_uIcc f i a (f i)
theorem image_update_uIcc_right (f : ∀ i, α i) (i : ι) (b : α i) :
update f i '' uIcc (f i) b = uIcc f (update f i b) := by
simpa using image_update_uIcc f i (f i) b
variable [∀ i, One (α i)]
@[to_additive]
theorem image_mulSingle_uIcc (i : ι) (a b : α i) :
Pi.mulSingle i '' uIcc a b = uIcc (Pi.mulSingle i a) (Pi.mulSingle i b) :=
image_update_uIcc _ _ _ _
@[to_additive]
theorem image_mulSingle_uIcc_left (i : ι) (a : α i) :
Pi.mulSingle i '' uIcc a 1 = uIcc (Pi.mulSingle i a) 1 :=
image_update_uIcc_left _ _ _
@[to_additive]
theorem image_mulSingle_uIcc_right (i : ι) (b : α i) :
Pi.mulSingle i '' uIcc 1 b = uIcc 1 (Pi.mulSingle i b) :=
image_update_uIcc_right _ _ _
end PiLattice
variable [DecidableEq ι] [∀ i, LinearOrder (α i)]
open Function (update)
theorem pi_univ_Ioc_update_union (x y : ∀ i, α i) (i₀ : ι) (m : α i₀) (hm : m ∈ Icc (x i₀) (y i₀)) :
((pi univ fun i ↦ Ioc (x i) (update y i₀ m i)) ∪
pi univ fun i ↦ Ioc (update x i₀ m i) (y i)) =
pi univ fun i ↦ Ioc (x i) (y i) := by
simp_rw [pi_univ_Ioc_update_left hm.1, pi_univ_Ioc_update_right hm.2, ← union_inter_distrib_right,
← setOf_or, le_or_gt, setOf_true, univ_inter]
/-- If `x`, `y`, `x'`, and `y'` are functions `Π i : ι, α i`, then
the set difference between the box `[x, y]` and the product of the open intervals `(x' i, y' i)`
is covered by the union of the following boxes: for each `i : ι`, we take
`[x, update y i (x' i)]` and `[update x i (y' i), y]`.
E.g., if `x' = x` and `y' = y`, then this lemma states that the difference between a closed box
`[x, y]` and the corresponding open box `{z | ∀ i, x i < z i < y i}` is covered by the union
of the faces of `[x, y]`. -/
theorem Icc_diff_pi_univ_Ioo_subset (x y x' y' : ∀ i, α i) :
(Icc x y \ pi univ fun i ↦ Ioo (x' i) (y' i)) ⊆
(⋃ i : ι, Icc x (update y i (x' i))) ∪ ⋃ i : ι, Icc (update x i (y' i)) y := by
rintro a ⟨⟨hxa, hay⟩, ha'⟩
simp only [mem_pi, mem_univ, mem_Ioo, true_implies, not_forall] at ha'
simp only [le_update_iff, update_le_iff, mem_union, mem_iUnion, mem_Icc,
hxa, hay _, hxa _, hay, ← exists_or]
rcases ha' with ⟨w, hw⟩
apply Exists.intro w
cases lt_or_ge (x' w) (a w) <;> simp_all
/-- If `x`, `y`, `z` are functions `Π i : ι, α i`, then
the set difference between the box `[x, z]` and the product of the intervals `(y i, z i]`
is covered by the union of the boxes `[x, update z i (y i)]`.
E.g., if `x = y`, then this lemma states that the difference between a closed box
`[x, y]` and the product of half-open intervals `{z | ∀ i, x i < z i ≤ y i}` is covered by the union
of the faces of `[x, y]` adjacent to `x`. -/
theorem Icc_diff_pi_univ_Ioc_subset (x y z : ∀ i, α i) :
(Icc x z \ pi univ fun i ↦ Ioc (y i) (z i)) ⊆ ⋃ i : ι, Icc x (update z i (y i)) := by
rintro a ⟨⟨hax, haz⟩, hay⟩
simpa [not_and_or, hax, le_update_iff, haz _] using hay
end Set
|
Result.lean
|
/-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Invertible
import Mathlib.Data.Sigma.Basic
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.Int.Cast.Basic
import Qq.MetaM
/-!
## The `Result` type for `norm_num`
We set up predicates `IsNat`, `IsInt`, and `IsRat`,
stating that an element of a ring is equal to the "normal form" of a natural number, integer,
or rational number coerced into that ring.
We then define `Result e`, which contains a proof that a typed expression `e : Q($α)`
is equal to the coercion of an explicit natural number, integer, or rational number,
or is either `true` or `false`.
-/
universe u
variable {α : Type u}
open Lean
open Lean.Meta Qq Lean.Elab Term
namespace Mathlib
namespace Meta.NormNum
variable {u : Level}
/-- A shortcut (non)instance for `AddMonoidWithOne ℕ` to shrink generated proofs. -/
def instAddMonoidWithOneNat : AddMonoidWithOne ℕ := inferInstance
/-- A shortcut (non)instance for `AddMonoidWithOne α`
from `Semiring α` to shrink generated proofs. -/
def instAddMonoidWithOne' {α : Type u} [Semiring α] : AddMonoidWithOne α := inferInstance
/-- A shortcut (non)instance for `AddMonoidWithOne α` from `Ring α` to shrink generated proofs. -/
def instAddMonoidWithOne {α : Type u} [Ring α] : AddMonoidWithOne α := inferInstance
/-- Helper function to synthesize a typed `AddMonoidWithOne α` expression. -/
def inferAddMonoidWithOne (α : Q(Type u)) : MetaM Q(AddMonoidWithOne $α) :=
return ← synthInstanceQ q(AddMonoidWithOne $α) <|>
throwError "not an AddMonoidWithOne"
/-- Helper function to synthesize a typed `Semiring α` expression. -/
def inferSemiring (α : Q(Type u)) : MetaM Q(Semiring $α) :=
return ← synthInstanceQ q(Semiring $α) <|> throwError "not a semiring"
/-- Helper function to synthesize a typed `Ring α` expression. -/
def inferRing (α : Q(Type u)) : MetaM Q(Ring $α) :=
return ← synthInstanceQ q(Ring $α) <|> throwError "not a ring"
/--
Represent an integer as a "raw" typed expression.
This uses `.lit (.natVal n)` internally to represent a natural number,
rather than the preferred `OfNat.ofNat` form.
We use this internally to avoid unnecessary typeclass searches.
This function is the inverse of `Expr.intLit!`.
-/
def mkRawIntLit (n : ℤ) : Q(ℤ) :=
let lit : Q(ℕ) := mkRawNatLit n.natAbs
if 0 ≤ n then q(.ofNat $lit) else q(.negOfNat $lit)
/--
Represent an integer as a "raw" typed expression.
This `.lit (.natVal n)` internally to represent a natural number,
rather than the preferred `OfNat.ofNat` form.
We use this internally to avoid unnecessary typeclass searches.
-/
def mkRawRatLit (q : ℚ) : Q(ℚ) :=
let nlit : Q(ℤ) := mkRawIntLit q.num
let dlit : Q(ℕ) := mkRawNatLit q.den
q(mkRat $nlit $dlit)
/-- Extract the raw natlit representing the absolute value of a raw integer literal
(of the type produced by `Mathlib.Meta.NormNum.mkRawIntLit`) along with an equality proof. -/
def rawIntLitNatAbs (n : Q(ℤ)) : (m : Q(ℕ)) × Q(Int.natAbs $n = $m) :=
if n.isAppOfArity ``Int.ofNat 1 then
have m : Q(ℕ) := n.appArg!
⟨m, show Q(Int.natAbs (Int.ofNat $m) = $m) from q(Int.natAbs_natCast $m)⟩
else if n.isAppOfArity ``Int.negOfNat 1 then
have m : Q(ℕ) := n.appArg!
⟨m, show Q(Int.natAbs (Int.negOfNat $m) = $m) from q(Int.natAbs_neg $m)⟩
else
panic! "not a raw integer literal"
/--
Constructs an `ofNat` application `a'` with the canonical instance, together with a proof that
the instance is equal to the result of `Nat.cast` on the given `AddMonoidWithOne` instance.
This function is performance-critical, as many higher level tactics have to construct numerals.
So rather than using typeclass search we hardcode the (relatively small) set of solutions
to the typeclass problem.
-/
def mkOfNat (α : Q(Type u)) (_sα : Q(AddMonoidWithOne $α)) (lit : Q(ℕ)) :
MetaM ((a' : Q($α)) × Q($lit = $a')) := do
if α.isConstOf ``Nat then
let a' : Q(ℕ) := q(OfNat.ofNat $lit : ℕ)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
else if α.isConstOf ``Int then
let a' : Q(ℤ) := q(OfNat.ofNat $lit : ℤ)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
else if α.isConstOf ``Rat then
let a' : Q(ℚ) := q(OfNat.ofNat $lit : ℚ)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
else
let some n := lit.rawNatLit? | failure
match n with
| 0 => pure ⟨q(0 : $α), (q(Nat.cast_zero (R := $α)) : Expr)⟩
| 1 => pure ⟨q(1 : $α), (q(Nat.cast_one (R := $α)) : Expr)⟩
| k+2 =>
let k : Q(ℕ) := mkRawNatLit k
let _x : Q(Nat.AtLeastTwo $lit) :=
(q(instNatAtLeastTwo (n := $k)) : Expr)
let a' : Q($α) := q(OfNat.ofNat $lit)
pure ⟨a', (q(Eq.refl $a') : Expr)⟩
/-- Assert that an element of a semiring is equal to the coercion of some natural number. -/
structure IsNat {α : Type u} [AddMonoidWithOne α] (a : α) (n : ℕ) : Prop where
/-- The element is equal to the coercion of the natural number. -/
out : a = n
theorem IsNat.raw_refl (n : ℕ) : IsNat n n := ⟨rfl⟩
/--
A "raw nat cast" is an expression of the form `(Nat.rawCast lit : α)` where `lit` is a raw
natural number literal. These expressions are used by tactics like `ring` to decrease the number
of typeclass arguments required in each use of a number literal at type `α`.
-/
@[simp] def _root_.Nat.rawCast {α : Type u} [AddMonoidWithOne α] (n : ℕ) : α := n
theorem IsNat.to_eq {α : Type u} [AddMonoidWithOne α] {n} : {a a' : α} → IsNat a n → n = a' → a = a'
| _, _, ⟨rfl⟩, rfl => rfl
theorem IsNat.to_raw_eq {a : α} {n : ℕ} [AddMonoidWithOne α] : IsNat (a : α) n → a = n.rawCast
| ⟨e⟩ => e
theorem IsNat.of_raw (α) [AddMonoidWithOne α] (n : ℕ) : IsNat (n.rawCast : α) n := ⟨rfl⟩
@[elab_as_elim]
theorem isNat.natElim {p : ℕ → Prop} : {n : ℕ} → {n' : ℕ} → IsNat n n' → p n' → p n
| _, _, ⟨rfl⟩, h => h
/-- Assert that an element of a ring is equal to the coercion of some integer. -/
structure IsInt [Ring α] (a : α) (n : ℤ) : Prop where
/-- The element is equal to the coercion of the integer. -/
out : a = n
/--
A "raw int cast" is an expression of the form:
* `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal
* `(Int.rawCast (Int.negOfNat lit) : α)` where `lit` is a nonzero raw natural number literal
(That is, we only actually use this function for negative integers.) This representation is used by
tactics like `ring` to decrease the number of typeclass arguments required in each use of a number
literal at type `α`.
-/
@[simp] def _root_.Int.rawCast [Ring α] (n : ℤ) : α := n
theorem IsInt.to_isNat {α} [Ring α] : ∀ {a : α} {n}, IsInt a (.ofNat n) → IsNat a n
| _, _, ⟨rfl⟩ => ⟨by simp⟩
theorem IsNat.to_isInt {α} [Ring α] : ∀ {a : α} {n}, IsNat a n → IsInt a (.ofNat n)
| _, _, ⟨rfl⟩ => ⟨by simp⟩
theorem IsInt.to_raw_eq {a : α} {n : ℤ} [Ring α] : IsInt (a : α) n → a = n.rawCast
| ⟨e⟩ => e
theorem IsInt.of_raw (α) [Ring α] (n : ℤ) : IsInt (n.rawCast : α) n := ⟨rfl⟩
theorem IsInt.neg_to_eq {α} [Ring α] {n} :
{a a' : α} → IsInt a (.negOfNat n) → n = a' → a = -a'
| _, _, ⟨rfl⟩, rfl => by simp [Int.negOfNat_eq, Int.cast_neg]
theorem IsInt.nonneg_to_eq {α} [Ring α] {n}
{a a' : α} (h : IsInt a (.ofNat n)) (e : n = a') : a = a' := h.to_isNat.to_eq e
/--
Assert that an element of a ring is equal to `num / denom`
(and `denom` is invertible so that this makes sense).
We will usually also have `num` and `denom` coprime,
although this is not part of the definition.
-/
inductive IsRat [Ring α] (a : α) (num : ℤ) (denom : ℕ) : Prop
| mk (inv : Invertible (denom : α)) (eq : a = num * ⅟(denom : α))
/--
Assert that an element of a semiring is equal to `num / denom`
(and `denom` is invertible so that this makes sense).
We will usually also have `num` and `denom` coprime,
although this is not part of the definition.
-/
inductive IsNNRat [Semiring α] (a : α) (num : ℕ) (denom : ℕ) : Prop
| mk (inv : Invertible (denom : α)) (eq : a = num * ⅟(denom : α))
/--
A "raw nnrat cast" is an expression of the form:
* `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal
* `(NNRat.rawCast n d : α)` where `n` is a raw nat literal, `d` is a raw nat literal, and `d` is not
`1` or `0`.
This representation is used by tactics like `ring` to decrease the number of typeclass arguments
required in each use of a number literal at type `α`.
-/
@[simp]
def _root_.NNRat.rawCast [DivisionSemiring α] (n : ℕ) (d : ℕ) : α := n / d
/--
A "raw rat cast" is an expression of the form:
* `(Nat.rawCast lit : α)` where `lit` is a raw natural number literal
* `(Int.rawCast (Int.negOfNat lit) : α)` where `lit` is a nonzero raw natural number literal
* `(NNRat.rawCast n d : α)` where `n` is a raw nat literal, `d` is a raw nat literal, and `d` is not
`1` or `0`.
* `(Rat.rawCast (Int.negOfNat n) d : α)` where `n` is a raw nat literal,
`d` is a raw nat literal, `n` is not `0`, and `d` is not `1` or `0`.
This representation is used by tactics like `ring` to decrease the number of typeclass arguments
required in each use of a number literal at type `α`.
-/
@[simp]
def _root_.Rat.rawCast [DivisionRing α] (n : ℤ) (d : ℕ) : α := n / d
theorem IsNNRat.to_isNat {α} [Semiring α] : ∀ {a : α} {n}, IsNNRat a (n) (nat_lit 1) → IsNat a n
| _, num, ⟨inv, rfl⟩ => have := @invertibleOne α _; ⟨by simp⟩
theorem IsRat.to_isNNRat {α} [Ring α] : ∀ {a : α} {n d}, IsRat a (.ofNat n) (d) → IsNNRat a n d
| _, _, _, ⟨inv, rfl⟩ => ⟨inv, by simp⟩
theorem IsNat.to_isNNRat {α} [Semiring α] : ∀ {a : α} {n}, IsNat a n → IsNNRat a (n) (nat_lit 1)
| _, _, ⟨rfl⟩ => ⟨⟨1, by simp, by simp⟩, by simp⟩
theorem IsNNRat.to_isRat {α} [Ring α] : ∀ {a : α} {n d}, IsNNRat a n d → IsRat a (.ofNat n) d
| _, _, _, ⟨inv, rfl⟩ => ⟨inv, by simp⟩
theorem IsRat.to_isInt {α} [Ring α] : ∀ {a : α} {n}, IsRat a n (nat_lit 1) → IsInt a n
| _, _, ⟨inv, rfl⟩ => have := @invertibleOne α _; ⟨by simp⟩
theorem IsInt.to_isRat {α} [Ring α] : ∀ {a : α} {n}, IsInt a n → IsRat a n (nat_lit 1)
| _, _, ⟨rfl⟩ => ⟨⟨1, by simp, by simp⟩, by simp⟩
theorem IsNNRat.to_raw_eq {n d : ℕ} [DivisionSemiring α] :
∀ {a}, IsNNRat (a : α) n d → a = NNRat.rawCast n d
| _, ⟨inv, rfl⟩ => by simp [div_eq_mul_inv]
theorem IsRat.to_raw_eq {n : ℤ} {d : ℕ} [DivisionRing α] :
∀ {a}, IsRat (a : α) n d → a = Rat.rawCast n d
| _, ⟨inv, rfl⟩ => by simp [div_eq_mul_inv]
theorem IsRat.neg_to_eq {α} [DivisionRing α] {n d} :
{a n' d' : α} → IsRat a (.negOfNat n) d → n = n' → d = d' → a = -(n' / d')
| _, _, _, ⟨_, rfl⟩, rfl, rfl => by simp [div_eq_mul_inv]
theorem IsNNRat.to_eq {α} [DivisionSemiring α] {n d} :
{a n' d' : α} → IsNNRat a n d → n = n' → d = d' → a = n' / d'
| _, _, _, ⟨_, rfl⟩, rfl, rfl => by simp [div_eq_mul_inv]
theorem IsNNRat.of_raw (α) [DivisionSemiring α] (n : ℕ) (d : ℕ)
(h : (d : α) ≠ 0) : IsNNRat (NNRat.rawCast n d : α) n d :=
have := invertibleOfNonzero h
⟨this, by simp [div_eq_mul_inv]⟩
theorem IsRat.of_raw (α) [DivisionRing α] (n : ℤ) (d : ℕ)
(h : (d : α) ≠ 0) : IsRat (Rat.rawCast n d : α) n d :=
have := invertibleOfNonzero h
⟨this, by simp [div_eq_mul_inv]⟩
theorem IsNNRat.den_nz {α} [DivisionSemiring α] {a n d} : IsNNRat (a : α) n d → (d : α) ≠ 0
| ⟨_, _⟩ => Invertible.ne_zero (d : α)
theorem IsRat.den_nz {α} [DivisionRing α] {a n d} : IsRat (a : α) n d → (d : α) ≠ 0
| ⟨_, _⟩ => Invertible.ne_zero (d : α)
/-- The result of `norm_num` running on an expression `x` of type `α`.
Untyped version of `Result`. -/
inductive Result' where
/-- Untyped version of `Result.isBool`. -/
| isBool (val : Bool) (proof : Expr)
/-- Untyped version of `Result.isNat`. -/
| isNat (inst lit proof : Expr)
/-- Untyped version of `Result.isNegNat`. -/
| isNegNat (inst lit proof : Expr)
/-- Untyped version of `Result.isNNRat`. -/
| isNNRat (inst : Expr) (q : Rat) (n d proof : Expr)
/-- Untyped version of `Result.isNegNNRat`. -/
| isNegNNRat (inst : Expr) (q : Rat) (n d proof : Expr)
deriving Inhabited
section
set_option linter.unusedVariables false
/-- The result of `norm_num` running on an expression `x` of type `α`. -/
@[nolint unusedArguments] def Result {α : Q(Type u)} (x : Q($α)) := Result'
instance {α : Q(Type u)} {x : Q($α)} : Inhabited (Result x) := inferInstanceAs (Inhabited Result')
/-- The result is `proof : x`, where `x` is a (true) proposition. -/
@[match_pattern, inline] def Result.isTrue {x : Q(Prop)} :
∀ (proof : Q($x)), Result q($x) := Result'.isBool true
/-- The result is `proof : ¬x`, where `x` is a (false) proposition. -/
@[match_pattern, inline] def Result.isFalse {x : Q(Prop)} :
∀ (proof : Q(¬$x)), Result q($x) := Result'.isBool false
/-- The result is `lit : ℕ` (a raw nat literal) and `proof : isNat x lit`. -/
@[match_pattern, inline] def Result.isNat {α : Q(Type u)} {x : Q($α)} :
∀ (inst : Q(AddMonoidWithOne $α) := by assumption) (lit : Q(ℕ)) (proof : Q(IsNat $x $lit)),
Result x := Result'.isNat
/-- The result is `-lit` where `lit` is a raw nat literal
and `proof : isInt x (.negOfNat lit)`. -/
@[match_pattern, inline] def Result.isNegNat {α : Q(Type u)} {x : Q($α)} :
∀ (inst : Q(Ring $α) := by assumption) (lit : Q(ℕ)) (proof : Q(IsInt $x (.negOfNat $lit))),
Result x := Result'.isNegNat
/-- The result is `proof : IsNNRat x n d`,
where `n` a raw nat literal, `d` is a raw nat literal (not 0 or 1),
`n` and `d` are coprime, and `q` is the value of `n / d`. -/
@[match_pattern, inline] def Result.isNNRat {α : Q(Type u)} {x : Q($α)} :
∀ (inst : Q(DivisionSemiring $α) := by assumption) (q : Rat) (n : Q(ℕ)) (d : Q(ℕ))
(proof : Q(IsNNRat $x $n $d)), Result x := Result'.isNNRat
/-- The result is `proof : IsRat x n d`,
where `n` is `.negOfNat lit` with `lit` a raw nat literal,
`d` is a raw nat literal (not 0 or 1),
`n` and `d` are coprime, and `q` is the value of `n / d`. -/
@[match_pattern, inline] def Result.isNegNNRat {α : Q(Type u)} {x : Q($α)} :
∀ (inst : Q(DivisionRing $α) := by assumption) (q : Rat) (n : Q(ℕ)) (d : Q(ℕ))
(proof : Q(IsRat $x (.negOfNat $n) $d)), Result x := Result'.isNegNNRat
end
/-- The result is `z : ℤ` and `proof : isNat x z`. -/
-- Note the independent arguments `z : Q(ℤ)` and `n : ℤ`.
-- We ensure these are "the same" when calling.
def Result.isInt {α : Q(Type u)} {x : Q($α)} (inst : Q(Ring $α) := by assumption)
(z : Q(ℤ)) (n : ℤ) (proof : Q(IsInt $x $z)) : Result x :=
have lit : Q(ℕ) := z.appArg!
if 0 ≤ n then
let proof : Q(IsInt $x (.ofNat $lit)) := proof
.isNat q(instAddMonoidWithOne) lit q(IsInt.to_isNat $proof)
else
.isNegNat inst lit proof
/-- The result is `q : NNRat` and `proof : isNNRat x q`. -/
-- Note the independent arguments `q : Q(ℚ)` and `n : ℚ`.
-- We ensure these are "the same" when calling.
def Result.isNNRat' {α : Q(Type u)} {x : Q($α)} (inst : Q(DivisionSemiring $α) := by assumption)
(q : Rat) (n : Q(ℕ)) (d : Q(ℕ)) (proof : Q(IsNNRat $x $n $d)) : Result x :=
if q.den = 1 then
haveI : nat_lit 1 =Q $d := ⟨⟩
.isNat q(instAddMonoidWithOne') n q(IsNNRat.to_isNat $proof)
else
.isNNRat inst q n d proof
/-- The result is `q : ℚ` and `proof : isRat x q`. -/
-- Note the independent arguments `q : Q(ℚ)` and `n : ℚ`.
-- We ensure these are "the same" when calling.
def Result.isRat {α : Q(Type u)} {x : Q($α)} (inst : Q(DivisionRing $α) := by assumption)
(q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (proof : Q(IsRat $x $n $d)) : Result x :=
have lit : Q(ℕ) := n.appArg!
if q.den = 1 then
have proof : Q(IsRat $x $n (nat_lit 1)) := proof
.isInt q(DivisionRing.toRing) n q.num q(IsRat.to_isInt $proof)
else if 0 ≤ q then
let proof : Q(IsRat $x (.ofNat $lit) $d) := proof
.isNNRat q(DivisionRing.toDivisionSemiring) q lit d q(IsRat.to_isNNRat $proof)
else
.isNegNNRat inst q lit d proof
instance {α : Q(Type u)} {x : Q($α)} : ToMessageData (Result x) where
toMessageData
| .isBool true proof => m!"isTrue ({proof})"
| .isBool false proof => m!"isFalse ({proof})"
| .isNat _ lit proof => m!"isNat {lit} ({proof})"
| .isNegNat _ lit proof => m!"isNegNat {lit} ({proof})"
| .isNNRat _ q _ _ proof => m!"isNNRat {q} ({proof})"
| .isNegNNRat _ q _ _ proof => m!"isNegNNRat {q} ({proof})"
/-- Returns the rational number that is the result of `norm_num` evaluation. -/
def Result.toRat {α : Q(Type u)} {e : Q($α)} : Result e → Option Rat
| .isBool .. => none
| .isNat _ lit _ => some lit.natLit!
| .isNegNat _ lit _ => some (-lit.natLit!)
| .isNNRat _ q .. => some q
| .isNegNNRat _ q .. => some q
/-- Returns the rational number that is the result of `norm_num` evaluation, along with a proof
that the denominator is nonzero in the `isRat` case. -/
def Result.toRatNZ {α : Q(Type u)} {e : Q($α)} : Result e → Option (Rat × Option Expr)
| .isBool .. => none
| .isNat _ lit _ => some (lit.natLit!, none)
| .isNegNat _ lit _ => some (-lit.natLit!, none)
| .isNNRat _ q _ _ p => some (q, q(IsNNRat.den_nz $p))
| .isNegNNRat _ q _ _ p => some (q, q(IsRat.den_nz $p))
/--
Extract from a `Result` the integer value (as both a term and an expression),
and the proof that the original expression is equal to this integer.
-/
def Result.toInt {α : Q(Type u)} {e : Q($α)} (_i : Q(Ring $α) := by with_reducible assumption) :
Result e → Option (ℤ × (lit : Q(ℤ)) × Q(IsInt $e $lit))
| .isNat _ lit proof => do
have proof : Q(@IsNat _ instAddMonoidWithOne $e $lit) := proof
pure ⟨lit.natLit!, q(.ofNat $lit), q(($proof).to_isInt)⟩
| .isNegNat _ lit proof => pure ⟨-lit.natLit!, q(.negOfNat $lit), proof⟩
| _ => failure
/--
Extract from a `Result` the rational value (as both a term and an expression),
and the proof that the original expression is equal to this rational number.
-/
def Result.toNNRat' {α : Q(Type u)} {e : Q($α)}
(_i : Q(DivisionSemiring $α) := by with_reducible assumption) :
Result e → Option (Rat × (n : Q(ℕ)) × (d : Q(ℕ)) × Q(IsNNRat $e $n $d))
| .isNat _ lit proof =>
have proof : Q(@IsNat _ instAddMonoidWithOne' $e $lit) := proof
some ⟨lit.natLit!, q($lit), q(nat_lit 1), q(($proof).to_isNNRat)⟩
| .isNNRat _ q n d proof => some ⟨q, n, d, proof⟩
| _ => none
/--
Extract from a `Result` the rational value (as both a term and an expression),
and the proof that the original expression is equal to this rational number.
-/
def Result.toRat' {α : Q(Type u)} {e : Q($α)}
(_i : Q(DivisionRing $α) := by with_reducible assumption) :
Result e → Option (ℚ × (n : Q(ℤ)) × (d : Q(ℕ)) × Q(IsRat $e $n $d))
| .isBool .. => none
| .isNat _ lit proof =>
have proof : Q(@IsNat _ instAddMonoidWithOne $e $lit) := proof
some ⟨lit.natLit!, q(.ofNat $lit), q(nat_lit 1), q(($proof).to_isNNRat.to_isRat)⟩
| .isNegNat _ lit proof =>
have proof : Q(@IsInt _ DivisionRing.toRing $e (.negOfNat $lit)) := proof
some ⟨-lit.natLit!, q(.negOfNat $lit), q(nat_lit 1),
q(@IsInt.to_isRat _ DivisionRing.toRing _ _ $proof)⟩
| .isNNRat inst q n d proof =>
letI : $inst =Q DivisionRing.toDivisionSemiring := ⟨⟩
some ⟨q, q(.ofNat $n), d, q(IsNNRat.to_isRat $proof)⟩
| .isNegNNRat _ q n d proof => some ⟨q, q(.negOfNat $n), d, proof⟩
/--
Given a `NormNum.Result e` (which uses `IsNat`, `IsInt`, `IsRat` to express equality to a rational
numeral), converts it to an equality `e = Nat.rawCast n`, `e = Int.rawCast n`, or
`e = Rat.rawCast n d` to a raw cast expression, so it can be used for rewriting.
-/
def Result.toRawEq {α : Q(Type u)} {e : Q($α)} : Result e → (e' : Q($α)) × Q($e = $e')
| .isBool false p =>
have e : Q(Prop) := e; have p : Q(¬$e) := p
⟨(q(False) : Expr), (q(eq_false $p) : Expr)⟩
| .isBool true p =>
have e : Q(Prop) := e; have p : Q($e) := p
⟨(q(True) : Expr), (q(eq_true $p) : Expr)⟩
| .isNat _ lit p => ⟨q(Nat.rawCast $lit), q(IsNat.to_raw_eq $p)⟩
| .isNegNat _ lit p => ⟨q(Int.rawCast (.negOfNat $lit)), q(IsInt.to_raw_eq $p)⟩
| .isNNRat _ _ n d p => ⟨q(NNRat.rawCast $n $d), q(IsNNRat.to_raw_eq $p)⟩
| .isNegNNRat _ _ n d p => ⟨q(Rat.rawCast (.negOfNat $n) $d), q(IsRat.to_raw_eq $p)⟩
/--
`Result.toRawEq` but providing an integer. Given a `NormNum.Result e` for something known to be an
integer (which uses `IsNat` or `IsInt` to express equality to an integer numeral), converts it to
an equality `e = Nat.rawCast n` or `e = Int.rawCast n` to a raw cast expression, so it can be used
for rewriting. Gives `none` if not an integer.
-/
def Result.toRawIntEq {α : Q(Type u)} {e : Q($α)} : Result e →
Option (ℤ × (e' : Q($α)) × Q($e = $e'))
| .isNat _ lit p => some ⟨lit.natLit!, q(Nat.rawCast $lit), q(IsNat.to_raw_eq $p)⟩
| .isNegNat _ lit p => some ⟨-lit.natLit!, q(Int.rawCast (.negOfNat $lit)), q(IsInt.to_raw_eq $p)⟩
| .isNNRat _ .. | .isNegNNRat _ .. | .isBool .. => none
/-- Constructs a `Result` out of a raw nat cast. Assumes `e` is a raw nat cast expression. -/
def Result.ofRawNat {α : Q(Type u)} (e : Q($α)) : Result e := Id.run do
let .app (.app _ (sα : Q(AddMonoidWithOne $α))) (lit : Q(ℕ)) := e | panic! "not a raw nat cast"
.isNat sα lit (q(IsNat.of_raw $α $lit) : Expr)
/-- Constructs a `Result` out of a raw int cast.
Assumes `e` is a raw int cast expression denoting `n`. -/
def Result.ofRawInt {α : Q(Type u)} (n : ℤ) (e : Q($α)) : Result e :=
if 0 ≤ n then
Result.ofRawNat e
else Id.run do
let .app (.app _ (rα : Q(Ring $α))) (.app _ (lit : Q(ℕ))) := e | panic! "not a raw int cast"
.isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr)
/-- Constructs a `Result` out of a raw rat cast.
Assumes `e` is a raw rat cast expression denoting `n`. -/
def Result.ofRawNNRat
{α : Q(Type u)} (q : ℚ) (e : Q($α)) (hyp : Option Expr := none) : Result e :=
if q.den = 1 then
Result.ofRawNat e
else Id.run do
let .app (.app (.app _ (dα : Q(DivisionSemiring $α))) (n : Q(ℕ))) (d : Q(ℕ)) := e
| panic! "not a raw nnrat cast"
let hyp : Q(($d : $α) ≠ 0) := hyp.get!
.isNNRat dα q n d (q(IsNNRat.of_raw $α $n $d $hyp) : Expr)
/-- Constructs a `Result` out of a raw rat cast.
Assumes `e` is a raw rat cast expression denoting `n`. -/
def Result.ofRawRat {α : Q(Type u)} (q : ℚ) (e : Q($α)) (hyp : Option Expr := none) : Result e :=
if q.den = 1 then
Result.ofRawInt q.num e
else if 0 ≤ q then
Result.ofRawNNRat q e hyp
else Id.run do
let .app (.app (.app _ (dα : Q(DivisionRing $α))) (.app _ (n : Q(ℕ)))) (d : Q(ℕ)) := e
| panic! "not a raw rat cast"
let hyp : Q(($d : $α) ≠ 0) := hyp.get!
.isNegNNRat dα q n d (q(IsRat.of_raw $α (.negOfNat $n) $d $hyp) : Expr)
/-- Convert a `Result` to a `Simp.Result`. -/
def Result.toSimpResult {α : Q(Type u)} {e : Q($α)} : Result e → MetaM Simp.Result
| r@(.isBool ..) => let ⟨expr, proof?⟩ := r.toRawEq; pure { expr, proof? }
| .isNat sα lit p => do
let ⟨a', pa'⟩ ← mkOfNat α sα lit
return { expr := a', proof? := q(IsNat.to_eq $p $pa') }
| .isNegNat _rα lit p => do
let ⟨a', pa'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) lit
return { expr := q(-$a'), proof? := q(IsInt.neg_to_eq $p $pa') }
| .isNNRat _ _ n d p => do
let ⟨n', pn'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) n
let ⟨d', pd'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) d
return { expr := q($n' / $d'), proof? := q(IsNNRat.to_eq $p $pn' $pd') }
| .isNegNNRat _ _ n d p => do
let ⟨n', pn'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) n
let ⟨d', pd'⟩ ← mkOfNat α q(AddCommMonoidWithOne.toAddMonoidWithOne) d
return { expr := q(-($n' / $d')), proof? := q(IsRat.neg_to_eq $p $pn' $pd') }
/-- Given `Mathlib.Meta.NormNum.Result.isBool p b`, this is the type of `p`.
Note that `BoolResult p b` is definitionally equal to `Expr`, and if you write `match b with ...`,
then in the `true` branch `BoolResult p true` is reducibly equal to `Q($p)` and
in the `false` branch it is reducibly equal to `Q(¬ $p)`. -/
abbrev BoolResult (p : Q(Prop)) (b : Bool) : Type :=
Q(Bool.rec (¬ $p) ($p) $b)
/-- Obtain a `Result` from a `BoolResult`. -/
def Result.ofBoolResult {p : Q(Prop)} {b : Bool} (prf : BoolResult p b) : Result q(Prop) :=
Result'.isBool b prf
/-- If `a = b` and we can evaluate `b`, then we can evaluate `a`. -/
def Result.eqTrans {α : Q(Type u)} {a b : Q($α)} (eq : Q($a = $b)) : Result b → Result a
| .isBool true proof =>
have a : Q(Prop) := a
have b : Q(Prop) := b
have eq : Q($a = $b) := eq
have proof : Q($b) := proof
Result.isTrue (x := a) q($eq ▸ $proof)
| .isBool false proof =>
have a : Q(Prop) := a
have b : Q(Prop) := b
have eq : Q($a = $b) := eq
have proof : Q(¬ $b) := proof
Result.isFalse (x := a) q($eq ▸ $proof)
| .isNat inst lit proof => Result.isNat inst lit q($eq ▸ $proof)
| .isNegNat inst lit proof => Result.isNegNat inst lit q($eq ▸ $proof)
| .isNNRat inst q n d proof => Result.isNNRat inst q n d q($eq ▸ $proof)
| .isNegNNRat inst q n d proof => Result.isNegNNRat inst q n d q($eq ▸ $proof)
end Meta.NormNum
end Mathlib
|
Finite.lean
|
/-
Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Patrick Massot
-/
-- This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl.
import Mathlib.Algebra.Group.Subgroup.Finite
import Mathlib.Data.Finite.Prod
import Mathlib.GroupTheory.QuotientGroup.Basic
/-!
# Deducing finiteness of a group.
-/
open Function
open scoped Pointwise
universe u v w x
namespace Group
open QuotientGroup Subgroup
variable {F G H : Type u} [Group F] [Group G] [Group H] [Fintype F] [Fintype H]
variable (f : F →* G) (g : G →* H)
open scoped Classical in
/-- If `F` and `H` are finite such that `ker(G →* H) ≤ im(F →* G)`, then `G` is finite. -/
@[to_additive
/-- If `F` and `H` are finite such that `ker(G →+ H) ≤ im(F →+ G)`, then `G` is finite. -/]
noncomputable def fintypeOfKerLeRange (h : g.ker ≤ f.range) : Fintype G :=
@Fintype.ofEquiv _ _
(@instFintypeProd _ _ (Fintype.ofInjective _ <| kerLift_injective g) <|
Fintype.ofInjective _ <| inclusion_injective h)
groupEquivQuotientProdSubgroup.symm
/-- If `F` and `H` are finite such that `ker(G →* H) = im(F →* G)`, then `G` is finite. -/
@[to_additive
/-- If `F` and `H` are finite such that `ker(G →+ H) = im(F →+ G)`, then `G` is finite. -/]
noncomputable def fintypeOfKerEqRange (h : g.ker = f.range) : Fintype G :=
fintypeOfKerLeRange _ _ h.le
/-- If `ker(G →* H)` and `H` are finite, then `G` is finite. -/
@[to_additive /-- If `ker(G →+ H)` and `H` are finite, then `G` is finite. -/]
noncomputable def fintypeOfKerOfCodom [Fintype g.ker] : Fintype G :=
fintypeOfKerLeRange ((topEquiv : _ ≃* G).toMonoidHom.comp <| inclusion le_top) g fun x hx =>
⟨⟨x, hx⟩, rfl⟩
/-- If `F` and `coker(F →* G)` are finite, then `G` is finite. -/
@[to_additive /-- If `F` and `coker(F →+ G)` are finite, then `G` is finite. -/]
noncomputable def fintypeOfDomOfCoker [Normal f.range] [Fintype <| G ⧸ f.range] : Fintype G :=
fintypeOfKerLeRange _ (mk' f.range) fun x => (eq_one_iff x).mp
@[to_additive]
lemma _root_.Finite.of_finite_quot_finite_subgroup {H : Subgroup G} [Finite H] [Finite (G ⧸ H)] :
Finite G :=
Finite.of_equiv _ (groupEquivQuotientProdSubgroup (s := H)).symm
end Group
|
DenseEmbedding.lean
|
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import Mathlib.Topology.Bases
import Mathlib.Topology.Separation.Regular
/-!
# Dense embeddings
This file defines three properties of functions:
* `DenseRange f` means `f` has dense image;
* `IsDenseInducing i` means `i` is also inducing, namely it induces the topology on its codomain;
* `IsDenseEmbedding e` means `e` is further an embedding, namely it is injective and `Inducing`.
The main theorem `continuous_extend` gives a criterion for a function
`f : X → Z` to a T₃ space Z to extend along a dense embedding
`i : X → Y` to a continuous function `g : Y → Z`. Actually `i` only
has to be `IsDenseInducing` (not necessarily injective).
-/
noncomputable section
open Filter Set Topology
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
/-- `i : α → β` is "dense inducing" if it has dense range and the topology on `α`
is the one induced by `i` from the topology on `β`. -/
structure IsDenseInducing [TopologicalSpace α] [TopologicalSpace β] (i : α → β) : Prop
extends IsInducing i where
/-- The range of a dense inducing map is a dense set. -/
protected dense : DenseRange i
namespace IsDenseInducing
variable [TopologicalSpace α] [TopologicalSpace β]
theorem _root_.Dense.isDenseInducing_val {s : Set α} (hs : Dense s) :
IsDenseInducing (@Subtype.val α s) := ⟨IsInducing.subtypeVal, hs.denseRange_val⟩
variable {i : α → β}
lemma isInducing (di : IsDenseInducing i) : IsInducing i := di.toIsInducing
theorem nhds_eq_comap (di : IsDenseInducing i) : ∀ a : α, 𝓝 a = comap i (𝓝 <| i a) :=
di.isInducing.nhds_eq_comap
protected theorem continuous (di : IsDenseInducing i) : Continuous i :=
di.isInducing.continuous
theorem closure_range (di : IsDenseInducing i) : closure (range i) = univ :=
di.dense.closure_range
protected theorem preconnectedSpace [PreconnectedSpace α] (di : IsDenseInducing i) :
PreconnectedSpace β :=
di.dense.preconnectedSpace di.continuous
theorem closure_image_mem_nhds {s : Set α} {a : α} (di : IsDenseInducing i) (hs : s ∈ 𝓝 a) :
closure (i '' s) ∈ 𝓝 (i a) := by
rw [di.nhds_eq_comap a, ((nhds_basis_opens _).comap _).mem_iff] at hs
rcases hs with ⟨U, ⟨haU, hUo⟩, sub : i ⁻¹' U ⊆ s⟩
refine mem_of_superset (hUo.mem_nhds haU) ?_
calc
U ⊆ closure (i '' (i ⁻¹' U)) := di.dense.subset_closure_image_preimage_of_isOpen hUo
_ ⊆ closure (i '' s) := closure_mono (image_mono sub)
theorem dense_image (di : IsDenseInducing i) {s : Set α} : Dense (i '' s) ↔ Dense s := by
refine ⟨fun H x => ?_, di.dense.dense_image di.continuous⟩
rw [di.isInducing.closure_eq_preimage_closure_image, H.closure_eq, preimage_univ]
trivial
/-- If `i : α → β` is a dense embedding with dense complement of the range, then any compact set in
`α` has empty interior. -/
theorem interior_compact_eq_empty [T2Space β] (di : IsDenseInducing i) (hd : Dense (range i)ᶜ)
{s : Set α} (hs : IsCompact s) : interior s = ∅ := by
refine eq_empty_iff_forall_notMem.2 fun x hx => ?_
rw [mem_interior_iff_mem_nhds] at hx
have := di.closure_image_mem_nhds hx
rw [(hs.image di.continuous).isClosed.closure_eq] at this
rcases hd.inter_nhds_nonempty this with ⟨y, hyi, hys⟩
exact hyi (image_subset_range _ _ hys)
/-- The product of two dense inducings is a dense inducing -/
protected theorem prodMap [TopologicalSpace γ] [TopologicalSpace δ] {e₁ : α → β} {e₂ : γ → δ}
(de₁ : IsDenseInducing e₁) (de₂ : IsDenseInducing e₂) :
IsDenseInducing (Prod.map e₁ e₂) where
toIsInducing := de₁.isInducing.prodMap de₂.isInducing
dense := de₁.dense.prodMap de₂.dense
open TopologicalSpace
/-- If the domain of a `IsDenseInducing` map is a separable space, then so is the codomain. -/
protected theorem separableSpace [SeparableSpace α] (di : IsDenseInducing i) : SeparableSpace β :=
di.dense.separableSpace di.continuous
variable [TopologicalSpace δ] {f : γ → α} {g : γ → δ} {h : δ → β}
/--
```
γ -f→ α
g↓ ↓e
δ -h→ β
```
-/
theorem tendsto_comap_nhds_nhds {d : δ} {a : α} (di : IsDenseInducing i)
(H : Tendsto h (𝓝 d) (𝓝 (i a))) (comm : h ∘ g = i ∘ f) : Tendsto f (comap g (𝓝 d)) (𝓝 a) := by
have lim1 : map g (comap g (𝓝 d)) ≤ 𝓝 d := map_comap_le
replace lim1 : map h (map g (comap g (𝓝 d))) ≤ map h (𝓝 d) := map_mono lim1
rw [Filter.map_map, comm, ← Filter.map_map, map_le_iff_le_comap] at lim1
have lim2 : comap i (map h (𝓝 d)) ≤ comap i (𝓝 (i a)) := comap_mono H
rw [← di.nhds_eq_comap] at lim2
exact le_trans lim1 lim2
protected theorem nhdsWithin_neBot (di : IsDenseInducing i) (b : β) : NeBot (𝓝[range i] b) :=
di.dense.nhdsWithin_neBot b
theorem comap_nhds_neBot (di : IsDenseInducing i) (b : β) : NeBot (comap i (𝓝 b)) :=
comap_neBot fun s hs => by
rcases mem_closure_iff_nhds.1 (di.dense b) s hs with ⟨_, ⟨ha, a, rfl⟩⟩
exact ⟨a, ha⟩
variable [TopologicalSpace γ]
/-- If `i : α → β` is a dense inducing, then any function `f : α → γ` "extends" to a function `g =
IsDenseInducing.extend di f : β → γ`. If `γ` is Hausdorff and `f` has a continuous extension, then
`g` is the unique such extension. In general, `g` might not be continuous or even extend `f`. -/
def extend (di : IsDenseInducing i) (f : α → γ) (b : β) : γ :=
@limUnder _ _ _ ⟨f (di.dense.some b)⟩ (comap i (𝓝 b)) f
theorem extend_eq_of_tendsto [T2Space γ] (di : IsDenseInducing i) {b : β} {c : γ} {f : α → γ}
(hf : Tendsto f (comap i (𝓝 b)) (𝓝 c)) : di.extend f b = c :=
haveI := di.comap_nhds_neBot
hf.limUnder_eq
theorem extend_eq_at [T2Space γ] (di : IsDenseInducing i) {f : α → γ} {a : α}
(hf : ContinuousAt f a) : di.extend f (i a) = f a :=
extend_eq_of_tendsto _ <| di.nhds_eq_comap a ▸ hf
theorem extend_eq_at' [T2Space γ] (di : IsDenseInducing i) {f : α → γ} {a : α} (c : γ)
(hf : Tendsto f (𝓝 a) (𝓝 c)) : di.extend f (i a) = f a :=
di.extend_eq_at (continuousAt_of_tendsto_nhds hf)
theorem extend_eq [T2Space γ] (di : IsDenseInducing i) {f : α → γ} (hf : Continuous f) (a : α) :
di.extend f (i a) = f a :=
di.extend_eq_at hf.continuousAt
/-- Variation of `extend_eq` where we ask that `f` has a limit along `comap i (𝓝 b)` for each
`b : β`. This is a strictly stronger assumption than continuity of `f`, but in a lot of cases
you'd have to prove it anyway to use `continuous_extend`, so this avoids doing the work twice. -/
theorem extend_eq' [T2Space γ] {f : α → γ} (di : IsDenseInducing i)
(hf : ∀ b, ∃ c, Tendsto f (comap i (𝓝 b)) (𝓝 c)) (a : α) : di.extend f (i a) = f a := by
rcases hf (i a) with ⟨b, hb⟩
refine di.extend_eq_at' b ?_
rwa [← di.isInducing.nhds_eq_comap] at hb
theorem extend_unique_at [T2Space γ] {b : β} {f : α → γ} {g : β → γ} (di : IsDenseInducing i)
(hf : ∀ᶠ x in comap i (𝓝 b), g (i x) = f x) (hg : ContinuousAt g b) : di.extend f b = g b := by
refine di.extend_eq_of_tendsto fun s hs => mem_map.2 ?_
suffices ∀ᶠ x : α in comap i (𝓝 b), g (i x) ∈ s from
hf.mp (this.mono fun x hgx hfx => hfx ▸ hgx)
clear hf f
refine eventually_comap.2 ((hg.eventually hs).mono ?_)
rintro _ hxs x rfl
exact hxs
theorem extend_unique [T2Space γ] {f : α → γ} {g : β → γ} (di : IsDenseInducing i)
(hf : ∀ x, g (i x) = f x) (hg : Continuous g) : di.extend f = g :=
funext fun _ => extend_unique_at di (Eventually.of_forall hf) hg.continuousAt
theorem continuousAt_extend [T3Space γ] {b : β} {f : α → γ} (di : IsDenseInducing i)
(hf : ∀ᶠ x in 𝓝 b, ∃ c, Tendsto f (comap i <| 𝓝 x) (𝓝 c)) : ContinuousAt (di.extend f) b := by
set φ := di.extend f
haveI := di.comap_nhds_neBot
suffices ∀ V' ∈ 𝓝 (φ b), IsClosed V' → φ ⁻¹' V' ∈ 𝓝 b by
simpa [ContinuousAt, (closed_nhds_basis (φ b)).tendsto_right_iff]
intro V' V'_in V'_closed
set V₁ := { x | Tendsto f (comap i <| 𝓝 x) (𝓝 <| φ x) }
have V₁_in : V₁ ∈ 𝓝 b := by
filter_upwards [hf]
rintro x ⟨c, hc⟩
rwa [← di.extend_eq_of_tendsto hc] at hc
obtain ⟨V₂, V₂_in, V₂_op, hV₂⟩ : ∃ V₂ ∈ 𝓝 b, IsOpen V₂ ∧ ∀ x ∈ i ⁻¹' V₂, f x ∈ V' := by
simpa [and_assoc] using
((nhds_basis_opens' b).comap i).tendsto_left_iff.mp (mem_of_mem_nhds V₁_in : b ∈ V₁) V' V'_in
suffices ∀ x ∈ V₁ ∩ V₂, φ x ∈ V' by filter_upwards [inter_mem V₁_in V₂_in] using this
rintro x ⟨x_in₁, x_in₂⟩
have hV₂x : V₂ ∈ 𝓝 x := IsOpen.mem_nhds V₂_op x_in₂
apply V'_closed.mem_of_tendsto x_in₁
use V₂
tauto
theorem continuous_extend [T3Space γ] {f : α → γ} (di : IsDenseInducing i)
(hf : ∀ b, ∃ c, Tendsto f (comap i (𝓝 b)) (𝓝 c)) : Continuous (di.extend f) :=
continuous_iff_continuousAt.mpr fun _ => di.continuousAt_extend <| univ_mem' hf
theorem mk' (i : α → β) (c : Continuous i) (dense : ∀ x, x ∈ closure (range i))
(H : ∀ (a : α), ∀ s ∈ 𝓝 a, ∃ t ∈ 𝓝 (i a), ∀ b, i b ∈ t → b ∈ s) : IsDenseInducing i where
toIsInducing := isInducing_iff_nhds.2 fun a =>
le_antisymm (c.tendsto _).le_comap (by simpa [Filter.le_def] using H a)
dense := dense
end IsDenseInducing
namespace Dense
variable [TopologicalSpace α] [TopologicalSpace β] {s : Set α}
/-- This is a shortcut for `hs.isDenseInducing_val.extend f`. It is useful because if `s : Set α`
is dense then the coercion `(↑) : s → α` automatically satisfies `IsUniformInducing` and
`IsDenseInducing` so this gives access to the theorems satisfied by a uniform extension by simply
mentioning the density hypothesis. -/
noncomputable def extend (hs : Dense s) (f : s → β) : α → β :=
hs.isDenseInducing_val.extend f
variable {f : s → β}
theorem extend_eq_of_tendsto [T2Space β] (hs : Dense s) {a : α} {b : β}
(hf : Tendsto f (comap (↑) (𝓝 a)) (𝓝 b)) : hs.extend f a = b :=
hs.isDenseInducing_val.extend_eq_of_tendsto hf
theorem extend_eq_at [T2Space β] (hs : Dense s) {f : s → β} {x : s}
(hf : ContinuousAt f x) : hs.extend f x = f x :=
hs.isDenseInducing_val.extend_eq_at hf
theorem extend_eq [T2Space β] (hs : Dense s) (hf : Continuous f) (x : s) :
hs.extend f x = f x :=
hs.extend_eq_at hf.continuousAt
theorem extend_unique_at [T2Space β] {a : α} {g : α → β} (hs : Dense s)
(hf : ∀ᶠ x : s in comap (↑) (𝓝 a), g x = f x) (hg : ContinuousAt g a) :
hs.extend f a = g a :=
hs.isDenseInducing_val.extend_unique_at hf hg
theorem extend_unique [T2Space β] {g : α → β} (hs : Dense s)
(hf : ∀ x : s, g x = f x) (hg : Continuous g) : hs.extend f = g :=
hs.isDenseInducing_val.extend_unique hf hg
theorem continuousAt_extend [T3Space β] {a : α} (hs : Dense s)
(hf : ∀ᶠ x in 𝓝 a, ∃ b, Tendsto f (comap (↑) <| 𝓝 x) (𝓝 b)) :
ContinuousAt (hs.extend f) a :=
hs.isDenseInducing_val.continuousAt_extend hf
theorem continuous_extend [T3Space β] (hs : Dense s)
(hf : ∀ a : α, ∃ b, Tendsto f (comap (↑) (𝓝 a)) (𝓝 b)) : Continuous (hs.extend f) :=
hs.isDenseInducing_val.continuous_extend hf
end Dense
/-- A dense embedding is an embedding with dense image. -/
structure IsDenseEmbedding [TopologicalSpace α] [TopologicalSpace β] (e : α → β) : Prop
extends IsDenseInducing e where
/-- A dense embedding is injective. -/
injective : Function.Injective e
lemma IsDenseEmbedding.mk' [TopologicalSpace α] [TopologicalSpace β] (e : α → β) (c : Continuous e)
(dense : DenseRange e) (injective : Function.Injective e)
(H : ∀ (a : α), ∀ s ∈ 𝓝 a, ∃ t ∈ 𝓝 (e a), ∀ b, e b ∈ t → b ∈ s) : IsDenseEmbedding e :=
{ IsDenseInducing.mk' e c dense H with injective }
namespace IsDenseEmbedding
open TopologicalSpace
variable [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ]
variable {e : α → β}
lemma isDenseInducing (de : IsDenseEmbedding e) : IsDenseInducing e := de.toIsDenseInducing
theorem inj_iff (de : IsDenseEmbedding e) {x y} : e x = e y ↔ x = y :=
de.injective.eq_iff
theorem isEmbedding (de : IsDenseEmbedding e) : IsEmbedding e where __ := de
/-- If the domain of a `IsDenseEmbedding` is a separable space, then so is its codomain. -/
protected theorem separableSpace [SeparableSpace α] (de : IsDenseEmbedding e) : SeparableSpace β :=
de.isDenseInducing.separableSpace
/-- The product of two dense embeddings is a dense embedding. -/
protected theorem prodMap {e₁ : α → β} {e₂ : γ → δ} (de₁ : IsDenseEmbedding e₁)
(de₂ : IsDenseEmbedding e₂) : IsDenseEmbedding fun p : α × γ => (e₁ p.1, e₂ p.2) where
toIsDenseInducing := de₁.isDenseInducing.prodMap de₂.isDenseInducing
injective := de₁.injective.prodMap de₂.injective
/-- The dense embedding of a subtype inside its closure. -/
@[simps]
def subtypeEmb {α : Type*} (p : α → Prop) (e : α → β) (x : { x // p x }) :
{ x // x ∈ closure (e '' { x | p x }) } :=
⟨e x, subset_closure <| mem_image_of_mem e x.prop⟩
protected theorem subtype (de : IsDenseEmbedding e) (p : α → Prop) :
IsDenseEmbedding (subtypeEmb p e) where
dense :=
dense_iff_closure_eq.2 <| by
ext ⟨x, hx⟩
rw [image_eq_range] at hx
simpa [closure_subtype, ← range_comp, (· ∘ ·)]
injective := (de.injective.comp Subtype.coe_injective).codRestrict _
eq_induced :=
(induced_iff_nhds_eq _).2 fun ⟨x, hx⟩ => by
simp [subtypeEmb, nhds_subtype_eq_comap, de.isInducing.nhds_eq_comap, comap_comap,
Function.comp_def]
theorem dense_image (de : IsDenseEmbedding e) {s : Set α} : Dense (e '' s) ↔ Dense s :=
de.isDenseInducing.dense_image
protected lemma id {α : Type*} [TopologicalSpace α] : IsDenseEmbedding (id : α → α) :=
{ IsEmbedding.id with dense := denseRange_id }
end IsDenseEmbedding
theorem Dense.isDenseEmbedding_val [TopologicalSpace α] {s : Set α} (hs : Dense s) :
IsDenseEmbedding ((↑) : s → α) :=
{ IsEmbedding.subtypeVal with dense := hs.denseRange_val }
theorem isClosed_property [TopologicalSpace β] {e : α → β} {p : β → Prop} (he : DenseRange e)
(hp : IsClosed { x | p x }) (h : ∀ a, p (e a)) : ∀ b, p b := by
have : univ ⊆ { b | p b } :=
calc
univ = closure (range e) := he.closure_range.symm
_ ⊆ closure { b | p b } := closure_mono <| range_subset_iff.mpr h
_ = _ := hp.closure_eq
simpa only [univ_subset_iff, eq_univ_iff_forall, mem_setOf]
theorem isClosed_property2 [TopologicalSpace β] {e : α → β} {p : β → β → Prop} (he : DenseRange e)
(hp : IsClosed { q : β × β | p q.1 q.2 }) (h : ∀ a₁ a₂, p (e a₁) (e a₂)) : ∀ b₁ b₂, p b₁ b₂ :=
have : ∀ q : β × β, p q.1 q.2 := isClosed_property (he.prodMap he) hp fun _ => h _ _
fun b₁ b₂ => this ⟨b₁, b₂⟩
theorem isClosed_property3 [TopologicalSpace β] {e : α → β} {p : β → β → β → Prop}
(he : DenseRange e) (hp : IsClosed { q : β × β × β | p q.1 q.2.1 q.2.2 })
(h : ∀ a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) : ∀ b₁ b₂ b₃, p b₁ b₂ b₃ :=
have : ∀ q : β × β × β, p q.1 q.2.1 q.2.2 :=
isClosed_property (he.prodMap <| he.prodMap he) hp fun _ => h _ _ _
fun b₁ b₂ b₃ => this ⟨b₁, b₂, b₃⟩
@[elab_as_elim]
theorem DenseRange.induction_on [TopologicalSpace β] {e : α → β} (he : DenseRange e) {p : β → Prop}
(b₀ : β) (hp : IsClosed { b | p b }) (ih : ∀ a : α, p <| e a) : p b₀ :=
isClosed_property he hp ih b₀
@[elab_as_elim]
theorem DenseRange.induction_on₂ [TopologicalSpace β] {e : α → β} {p : β → β → Prop}
(he : DenseRange e) (hp : IsClosed { q : β × β | p q.1 q.2 }) (h : ∀ a₁ a₂, p (e a₁) (e a₂))
(b₁ b₂ : β) : p b₁ b₂ :=
isClosed_property2 he hp h _ _
@[elab_as_elim]
theorem DenseRange.induction_on₃ [TopologicalSpace β] {e : α → β} {p : β → β → β → Prop}
(he : DenseRange e) (hp : IsClosed { q : β × β × β | p q.1 q.2.1 q.2.2 })
(h : ∀ a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) (b₁ b₂ b₃ : β) : p b₁ b₂ b₃ :=
isClosed_property3 he hp h _ _ _
section
variable [TopologicalSpace β] [TopologicalSpace γ] [T2Space γ]
variable {f : α → β}
/-- Two continuous functions to a t2-space that agree on the dense range of a function are equal. -/
theorem DenseRange.equalizer (hfd : DenseRange f) {g h : β → γ} (hg : Continuous g)
(hh : Continuous h) (H : g ∘ f = h ∘ f) : g = h :=
funext fun y => hfd.induction_on y (isClosed_eq hg hh) <| congr_fun H
end
-- Bourbaki GT III §3 no.4 Proposition 7 (generalised to any dense-inducing map to a regular space)
theorem Filter.HasBasis.hasBasis_of_isDenseInducing [TopologicalSpace α] [TopologicalSpace β]
[RegularSpace β] {ι : Type*} {s : ι → Set α} {p : ι → Prop} {x : α} (h : (𝓝 x).HasBasis p s)
{f : α → β} (hf : IsDenseInducing f) : (𝓝 (f x)).HasBasis p fun i => closure <| f '' s i := by
rw [Filter.hasBasis_iff] at h ⊢
intro T
refine ⟨fun hT => ?_, fun hT => ?_⟩
· obtain ⟨T', hT₁, hT₂, hT₃⟩ := exists_mem_nhds_isClosed_subset hT
have hT₄ : f ⁻¹' T' ∈ 𝓝 x := by
rw [hf.isInducing.nhds_eq_comap x]
exact ⟨T', hT₁, Subset.rfl⟩
obtain ⟨i, hi, hi'⟩ := (h _).mp hT₄
exact
⟨i, hi,
(closure_mono (image_mono hi')).trans
(Subset.trans (closure_minimal (image_preimage_subset _ _) hT₂) hT₃)⟩
· obtain ⟨i, hi, hi'⟩ := hT
suffices closure (f '' s i) ∈ 𝓝 (f x) by filter_upwards [this] using hi'
replace h := (h (s i)).mpr ⟨i, hi, Subset.rfl⟩
exact hf.closure_image_mem_nhds h
|
Connected.lean
|
/-
Copyright (c) 2024 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Filtered.Basic
import Mathlib.CategoryTheory.IsConnected
/-!
# Filtered categories are connected
-/
universe v u
namespace CategoryTheory
variable (C : Type u) [Category.{v} C]
theorem IsFilteredOrEmpty.isPreconnected [IsFilteredOrEmpty C] : IsPreconnected C :=
zigzag_isPreconnected fun j j' => .trans
(.single <| .inl <| .intro <| IsFiltered.leftToMax j j')
(.single <| .inr <| .intro <| IsFiltered.rightToMax j j')
theorem IsCofilteredOrEmpty.isPreconnected [IsCofilteredOrEmpty C] : IsPreconnected C :=
zigzag_isPreconnected fun j j' => .trans
(.single <| .inr <| .intro <| IsCofiltered.minToLeft j j')
(.single <| .inl <| .intro <| IsCofiltered.minToRight j j')
attribute [local instance] IsFiltered.nonempty in
theorem IsFiltered.isConnected [IsFiltered C] : IsConnected C :=
{ IsFilteredOrEmpty.isPreconnected C with }
attribute [local instance] IsCofiltered.nonempty in
theorem IsCofiltered.isConnected [IsCofiltered C] : IsConnected C :=
{ IsCofilteredOrEmpty.isPreconnected C with }
end CategoryTheory
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.