(* (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 div path tuple bigop prime finset.
From mathcomp Require Export monoid.

(******************************************************************************)
(*                               Finite groups                                *)
(*                                                                            *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands.   *)
(*                                                                            *)
(* This file defines the main interface for finite groups:                    *)
(*          finGroupType == the structure for finite types with a group law   *)
(*                          The HB class is called FinGroup.                  *)
(*           {group gT}  == type of groups with elements of type gT           *)
(*     finStarMonoidType == the structure for finite star-monoids             *)
(*                          The HB class is called FinStarMonoid.             *)
(*    FinGroupType mulVg == the finGroupType structure for an existing        *)
(*                          finStarMonoidType structure, built from a proof of*)
(*                          the left inverse group axiom for that structure's *)
(*                          operations                                        *)
(*          [group of G] == a clone for an existing {group gT} structure on   *)
(*                          G : {set gT} (the existing structure might be for *)
(*                          some delta-expansion of G)                        *)
(* If gT implements finGroupType, then we can form {set gT}, the type of      *)
(* finite sets with elements of type gT (as finGroupType extends finType).    *)
(* The group law extends pointwise to {set gT}, which thus implements a sub-  *)
(* interface finStarMonoidType of finGroupType. To be consistent with the     *)
(* predType interface, this is done by coercion to FinGroup.arg_sort, an      *)
(* alias for FinGroup.sort. Accordingly, all pointwise group operations below *)
(* have arguments of type (FinGroup.arg_sort) gT and return results of type   *)
(* FinGroup.sort gT.                                                          *)
(*   The notations below are declared in two scopes:                          *)
(*      group_scope (delimiter %g) for point operations and set constructs.   *)
(*      Group_scope (delimiter %G) for explicit {group gT} structures.        *)
(* These scopes should not be opened globally, although group_scope is often  *)
(* opened locally in group-theory files.                                      *)
(*   As {group gT} is both a subtype and an interface structure for {set gT}, *)
(* the fact that a given G : {set gT} is a group can (and usually should) be  *)
(* inferred by type inference with canonical structures. This means that all  *)
(* `group' constructions (e.g., the normaliser 'N_G(H)) actually define sets  *)
(* with a canonical {group gT} structure; the %G delimiter can be used to     *)
(* specify the actual {group gT} structure (e.g., 'N_G(H)%G).                 *)
(*  Operations on elements of a group:                                        *)
(*                x * y == the group product of x and y                       *)
(*               x ^+ n == the nth power of x, i.e., x * ... * x (n times)    *)
(*                 x^-1 == the group inverse of x                             *)
(*               x ^- n == the inverse of x ^+ n (notation for (x ^+ n)^-1)   *)
(*                    1 == the unit element                                   *)
(*                x ^ y == the conjugate of x by y (i.e., y^-1 * (x * y))     *)
(*            [~ x, y]  == the commutator of x and y (i.e., x^-1 * x ^ y)     *)
(*     [~ x1, ..., xn]  == the commutator of x1, ..., xn (associating left)   *)
(*    \prod_(i ...) x i == the product of the x i (order-sensitive)           *)
(*         commute x y  <-> x and y commute                                   *)
(*      centralises x A <-> x centralises A                                   *)
(*                'C[x] == the set of elements that commute with x            *)
(*              'C_G[x] == the set of elements of G that commute with x       *)
(*                <[x]> == the cyclic subgroup generated by the element x     *)
(*                 #[x] == the order of the element x, i.e., #|<[x]>|         *)
(*  Operations on subsets/subgroups of a finite group:                        *)
(*                H * G == {xy | x \in H, y \in G}                            *)
(*   1 or [1] or [1 gT] == the unit group                                     *)
(*          [set: gT]%G == the group of all x : gT (in Group_scope)           *)
(*          group_set G == G contains 1 and is closed under binary product;   *)
(*                         this is the characteristic property of the         *)
(*                         {group gT} subtype of {set gT}                     *)
(*             [subg G] == the subtype, set, or group of all x \in G: this    *)
(*                         notation is defined simultaneously in %type, %g    *)
(*                         and %G scopes, and G must denote a {group gT}      *)
(*                         structure (G is in the %G scope)                   *)
(*          subg, sgval == the projection into and injection from [subg G]    *)
(*                  H^# == the set H minus the unit element                   *)
(*               repr H == some element of H if 1 \notin H != set0, else 1    *)
(*                         (repr is defined over sets of a finStarMonoidType, *)
(*                         so it can be used, e.g., to pick right cosets.)    *)
(*               x *: H == left coset of H by x                               *)
(*          lcosets H G == the set of the left cosets of H by elements of G   *)
(*               H :* x == right coset of H by x                              *)
(*          rcosets H G == the set of the right cosets of H by elements of G  *)
(*             #|G : H| == the index of H in G, i.e., #|rcosets G H|          *)
(*               H :^ x == the conjugate of H by x                            *)
(*               x ^: H == the conjugate class of x in H                      *)
(*            classes G == the set of all conjugate classes of G              *)
(*              G :^: H == {G :^ x | x \in H}                                 *)
(*    class_support G H == {x ^ y | x \in G, y \in H}                         *)
(*        commg_set G H == {[~ x, y] | x \in G, y \in H}; NOT the commutator! *)
(*                <<H>> == the subgroup generated by the set H                *)
(*            [~: G, H] == the commmutator subgroup of G and H, i.e.,         *)
(*                         <<commg_set G H>>>                                 *)
(*     [~: H1, ..., Hn] == commutator subgroup of H1, ..., Hn (left assoc.)   *)
(*              H <*> G == the subgroup generated by sets H and G (H join G)  *)
(*            (H * G)%G == the join of G H : {group gT} (convertible, but not *)
(*                         identical to (G <*> H)%G)                          *)
(* (\prod_(i ...) H i)%G == the group generated by the H i                    *)
(* {in G, centralised H} <-> G centralises H                                  *)
(* {in G, normalised H} <-> G normalises H                                    *)
(*                      <-> forall x, x \in G -> H :^ x = H                   *)
(*                'N(H) == the normaliser of H                                *)
(*              'N_G(H) == the normaliser of H in G                           *)
(*               H <| G <=> H is a normal subgroup of G                       *)
(*                'C(H) == the centraliser of H                               *)
(*              'C_G(H) == the centraliser of H in G                          *)
(*            gcore H G == the largest subgroup of H normalised by G          *)
(*                         If H is a subgroup of G, this is the largest       *)
(*                         normal subgroup of G contained in H).              *)
(*            abelian H <=> H is abelian                                      *)
(*          subgroups G == the set of subgroups of G, i.e., the set of all    *)
(*                         H : {group gT} such that H \subset G               *)
(* In the notation below G is a variable that is bound in P.                  *)
(*          [max G | P] <=> G is the largest group such that P holds          *)
(*     [max H of G | P] <=> H is the largest group G such that P holds        *)
(*      [max G | P & Q] := [max G | P && Q], likewise [max H of G | P & Q]    *)
(*          [min G | P] <=> G is the smallest group such that P holds         *)
(*      [min G | P & Q] := [min G | P && Q], likewise [min H of G | P & Q]    *)
(*     [min H of G | P] <=> H is the smallest group G such that P holds       *)
(* In addition to the generic suffixes described in ssrbool.v and finset.v,   *)
(* we associate the following suffixes to group operations:                   *)
(*   1 - identity element, as in group1 : 1 \in G                             *)
(*   M - multiplication, as is invMg : (x * y)^-1 = y^-1 * x^-1               *)
(*       Also nat multiplication, for expgM : x ^+ (m * n) = x ^+ m ^+ n      *)
(*   D - (nat) addition, for expgD : x ^+ (m + n) = x ^+ m * x ^+ n           *)
(*   V - inverse, as in mulgV : x * x^-1 = 1                                  *)
(*   X - exponentiation, as in conjXg : (x ^+ n) ^ y = (x ^ y) ^+ n           *)
(*   J - conjugation, as in orderJ : #[x ^ y] = #[x]                          *)
(*   R - commutator, as in conjRg : [~ x, y] ^ z = [~ x ^ z, y ^ z]           *)
(*   Y - join, as in centY : 'C(G <*> H) = 'C(G) :&: 'C(H)                    *)
(* We sometimes prefix these with an `s' to indicate a set-lifted operation,  *)
(* e.g., conjsMg : (A * B) :^ x = A :^ x * B :^ x.                            *)
(******************************************************************************)

Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.

Declare Scope Group_scope.

Delimit Scope Group_scope with G.

Module GroupScope.
Open Scope group_scope.
End GroupScope.
Local Open Scope group_scope.

(* These are the operation notations introduced by this file. *)
Reserved Notation "[ ~ x1 , x2 , .. , xn ]"
  (format  "'[ ' [ ~  x1 , '/'  x2 , '/'  .. , '/'  xn ] ']'").
Reserved Notation "[ 1 gT ]" (format "[ 1  gT ]").
Reserved Notation "[ 1 ]" (format "[ 1 ]").
Reserved Notation "[ 'subg' G ]" (format "[ 'subg'  G ]").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "A ^#" (at level 3, format "A ^#").

Reserved Notation "A :^ x" (at level 35, right associativity).
Reserved Notation "x ^: B" (at level 35, right associativity).
Reserved Notation "A :^: B" (at level 35, right associativity).
Reserved Notation "#| B : A |" (A at level 99, format "#| B  :  A |").
Reserved Notation "''N' ( A )" (format "''N' ( A )").
Reserved Notation "''N_' G ( A )" (G at level 2, format "''N_' G ( A )").
Reserved Notation "A <| B" (at level 70, no associativity).
Reserved Notation "A <*> B" (at level 40, left associativity).
Reserved Notation "[ ~: A1 , A2 , .. , An ]"
  (format "[ ~: '['  A1 , '/'  A2 , '/'  .. , '/'  An ']' ]").
Reserved Notation "[ 'max' A 'of' G | gP ]"
  (format "[ '[hv' 'max'  A  'of'  G '/ '  |  gP ']' ]").
Reserved Notation "[ 'max' G | gP ]"
  (format "[ '[hv' 'max'  G '/ '  |  gP ']' ]").
Reserved Notation "[ 'max' A 'of' G | gP & gQ ]"
  (format "[ '[hv' 'max'  A  'of'  G '/ '  |  gP '/ '  &  gQ ']' ]").
Reserved Notation "[ 'max' G | gP & gQ ]"
  (format "[ '[hv' 'max'  G '/ '  |  gP '/ '  &  gQ ']' ]").
Reserved Notation "[ 'min' A 'of' G | gP ]"
  (format "[ '[hv' 'min'  A  'of'  G '/ '  |  gP ']' ]").
Reserved Notation "[ 'min' G | gP ]"
  (format "[ '[hv' 'min'  G '/ '  |  gP ']' ]").
Reserved Notation "[ 'min' A 'of' G | gP & gQ ]"
  (format "[ '[hv' 'min'  A  'of'  G '/ '  |  gP '/ '  &  gQ ']' ]").
Reserved Notation "[ 'min' G | gP & gQ ]"
  (format "[ '[hv' 'min'  G '/ '  |  gP '/ '  &  gQ ']' ]").

Module isMulBaseGroup.
#[deprecated(since="mathcomp 2.5.0", use=isStarMonoid.Build)]
Notation Build G := (isStarMonoid.Build G) (only parsing).
End isMulBaseGroup.

#[deprecated(since="mathcomp 2.5.0", use=isStarMonoid)]
Notation isMulBaseGroup G := (isStarMonoid G) (only parsing).

Module BaseFinGroup_isGroup.
#[deprecated(since="mathcomp 2.5.0", use=StarMonoid_isGroup.Build)]
Notation Build G := (StarMonoid_isGroup.Build G) (only parsing).
End BaseFinGroup_isGroup.

#[deprecated(since="mathcomp 2.5.0", use=StarMonoid_isGroup)]
Notation BaseFinGroup_isGroup G := (StarMonoid_isGroup G) (only parsing).

#[arg_sort, short(type="finStarMonoidType")]
HB.structure Definition FinStarMonoid := { G of StarMonoid G & Finite G }.

#[deprecated(since="mathcomp 2.5.0", use=finStarMonoidType)]
Notation baseFinGroupType := finStarMonoidType (only parsing).

Module BaseFinGroup.
#[deprecated(since="mathcomp 2.5.0", use=FinStarMonoid.sort)]
Notation sort := (FinStarMonoid.sort) (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=FinStarMonoid.arg_sort)]
Notation arg_sort := (FinStarMonoid.arg_sort) (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=FinStarMonoid.on)]
Notation on M := (FinStarMonoid.on M) (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=FinStarMonoid.copy)]
Notation copy M N := (FinStarMonoid.copy M N) (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=FinStarMonoid.clone)]
Notation clone M N := (FinStarMonoid.clone M N) (only parsing).
End BaseFinGroup.

#[deprecated(since="mathcomp 2.4.0", use=FinStarMonoid)]
Notation BaseFinGroup R := (FinStarMonoid R) (only parsing).

Module FinStarMonoidExports.
Bind Scope group_scope with FinStarMonoid.arg_sort.
Bind Scope group_scope with FinStarMonoid.sort.
End FinStarMonoidExports.
HB.export FinStarMonoidExports.

#[deprecated(since="mathcomp 2.5.0", use=one)]
Notation oneg := one (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=mul)]
Notation mulg := mul (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=inv)]
Notation invg := inv (only parsing).
#[deprecated(since="mathcomp 2.5.0", use=natexp)]
Notation expgn := natexp (only parsing).

#[short(type="finGroupType")]
HB.structure Definition FinGroup :=
  { G of Group G & Finite G }.

Module FinGroupExports.
Bind Scope group_scope with FinGroup.sort.
End FinGroupExports.
HB.export FinGroupExports.

HB.factory Record Finite_isGroup G & Finite G := {
  mul : G -> G -> G;
  one : G;
  inv : G -> G;
  mulgA : associative mul;
  mul1g : left_id one mul;
  mulVg : left_inverse one inv mul;
}.

Module isMulGroup.
#[deprecated(since="mathcomp 2.5.0", use=Finite_isGroup.Build)]
Notation Build G := (Finite_isGroup.Build G) (only parsing).
End isMulGroup.
#[deprecated(since="mathcomp 2.5.0", use=Finite_isGroup)]
Notation isMulGroup G := (Finite_isGroup G) (only parsing).

HB.builders Context G & Finite_isGroup G.

Notation "1" := one.
Infix "*" := mul.
Notation "x ^-1" := (inv x).

Lemma invgK : involutive inv.
Proof.
Admitted.

Lemma invMg : {morph inv : x y / x * y >-> y * x}.
Proof.
Admitted.

HB.instance Definition _ :=
  isStarMonoid.Build G mulgA mul1g invgK invMg.
HB.instance Definition _ := StarMonoid_isGroup.Build G mulVg.

HB.end.

#[compress_coercions]
HB.instance Definition _ (T : finStarMonoidType) :
    Finite (FinStarMonoid.arg_sort T) := Finite.class T.

Notation conjg := conjg (only parsing).
Notation commg := commg (only parsing).
Notation mulgA := mulgA (only parsing).
Notation mul1g := mul1g (only parsing).
Notation invgK := invgK (only parsing).
Notation invMg := invgM (only parsing).
Notation invg_inj := invg_inj (only parsing).
Notation eq_invg_sym := eqg_invLR (only parsing).
Notation invg1 := invg1 (only parsing).
Notation eq_invg1 := invg_eq1 (only parsing).
Notation mulg1 := mulg1 (only parsing).
Notation expgnE := expgnE (only parsing).
Notation expg0 := expg0 (only parsing).
Notation expg1 := expg1 (only parsing).
Notation expg1n := expg1n (only parsing).
Notation expgD := expgnDr (only parsing).
Notation expgSr := expgSr (only parsing).
Notation expgM := expgnA (only parsing).
Notation expgAC := expgnAC (only parsing).
Notation commute := commute (only parsing).
Notation commute_refl := commute_refl (only parsing).
Notation commute_sym := commute_sym (only parsing).
Notation commute1 := commute1 (only parsing).
Notation commuteM := commuteM (only parsing).
Notation commuteX := commuteX (only parsing).
Notation commuteX2 := commuteX2 (only parsing).
Notation expgVn := expVgn (only parsing).
Notation expgMn := expgMn (only parsing).
Notation mulVg := mulVg (only parsing).
Notation mulgV := mulgV (only parsing).
Notation mulKg := mulKg (only parsing).
Notation mulKVg := mulVKg (only parsing).
Notation mulgI := mulgI (only parsing).
Notation mulgK := mulgK (only parsing).
Notation mulgKV := mulgVK (only parsing).
Lemma eq_invg_mul (T : finGroupType) x y : (x^-1 == y :> T) = (x * y == 1).
Proof.
Admitted.
Lemma eq_mulgV1 (T : finGroupType) x y : (x == y) = (x * y^-1 == 1 :> T).
Proof.
Admitted.
Lemma eq_mulVg1 (T : finGroupType) x y : (x == y) = (x^-1 * y == 1 :> T).
Proof.
Admitted.
Notation commuteV := commuteV (only parsing).
Notation conjgE := conjgE (only parsing).
Notation conjgC := conjgC (only parsing).
Notation conjgCV := conjgCV (only parsing).
Notation conjg1 := conjg1 (only parsing).
Notation conj1g := conj1g (only parsing).
Notation conjMg := conjMg (only parsing).
Notation conjgM := conjgM (only parsing).
Notation conjVg := conjVg (only parsing).
Notation conjJg := conjJg (only parsing).
Notation conjXg := conjXg (only parsing).
Notation conjgK := conjgK (only parsing).
Notation conjgKV := conjgKV (only parsing).
Notation conjg_inj := conjg_inj (only parsing).
Notation conjg_eq1 := conjg_eq1 (only parsing).
Notation conjg_prod := conjg_prod (only parsing).
Notation commgEl := commgEl (only parsing).
Notation commgEr := commgEr (only parsing).
Notation commgC := commgC (only parsing).
Notation commgCV := commgCV (only parsing).
Notation conjRg := conjRg (only parsing).
Notation invg_comm := invgR (only parsing).
Notation commgP := commgP (only parsing).
Notation conjg_fixP := conjg_fixP (only parsing).
Notation commg1_sym := commg1_sym (only parsing).
Notation commg1 := commg1 (only parsing).
Notation comm1g := comm1g (only parsing).
Notation commgg := commgg (only parsing).
Notation commgXg := commgXg (only parsing).
Notation commgVg := commgVg (only parsing).
Notation commgXVg := commgXVg (only parsing).

Section Repr.
(* Plucking a set representative. *)

Variable gT : finStarMonoidType.
Implicit Type A : {set gT}.

Definition repr A := if 1 \in A then 1 else odflt 1 [pick x in A].

Lemma mem_repr A x : x \in A -> repr A \in A.
Proof.
Admitted.

Lemma card_mem_repr A : #|A| > 0 -> repr A \in A.
Proof.
Admitted.

Lemma repr_set1 x : repr [set x] = x.
Proof.
Admitted.

Lemma repr_set0 : repr set0 = 1.
Proof.
Admitted.

End Repr.

Arguments mem_repr [gT A].

Section BaseSetMulDef.
(* We only assume a finStarMonoidType to allow this construct to be iterated. *)
Variable gT : finStarMonoidType.
Implicit Types A B : {set gT}.

(* Set-lifted group operations. *)

Definition set_mulg A B := mul @2: (A, B).
Definition set_invg A := inv @^-1: A.

(* The pre-group structure of group subsets. *)

Lemma set_mul1g : left_id [set 1] set_mulg.
Proof.
Admitted.

Lemma set_mulgA : associative set_mulg.
Proof.
Admitted.

Lemma set_invgK : involutive set_invg.
Proof.
Admitted.

Lemma set_invgM : {morph set_invg : A B / set_mulg A B >-> set_mulg B A}.
Proof.
Admitted.

HB.instance Definition set_base_group := isStarMonoid.Build (set_type gT)
  set_mulgA set_mul1g set_invgK set_invgM.
HB.instance Definition _ : isStarMonoid {set gT} := set_base_group.

End BaseSetMulDef.

(* Time to open the bag of dirty tricks. When we define groups down below *)
(* as a subtype of {set gT}, we need them to be able to coerce to sets in *)
(* both set-style contexts (x \in G) and monoid-style contexts (G * H),   *)
(* and we need the coercion function to be EXACTLY the structure          *)
(* projection in BOTH cases -- otherwise the canonical unification breaks.*)
(*   Alas, Coq doesn't let us use the same coercion function twice, even  *)
(* when the targets are convertible. Our workaround (ab)uses the module   *)
(* system to declare two different identity coercions on an alias class.  *)

Module GroupSet.
Definition sort (gT : finStarMonoidType) := {set gT}.
End GroupSet.
Identity Coercion GroupSet_of_sort : GroupSet.sort >-> set_of.

Module Type GroupSetFinStarMonoidSig.
Definition sort (gT : finStarMonoidType) := FinStarMonoid.arg_sort {set gT}.
End GroupSetFinStarMonoidSig.

Module MakeGroupSetFinStarMonoid (Gset_base : GroupSetFinStarMonoidSig).
Identity Coercion of_sort : Gset_base.sort >-> FinStarMonoid.arg_sort.
End MakeGroupSetFinStarMonoid.

Module Export GroupSetFinStarMonoid := MakeGroupSetFinStarMonoid GroupSet.

Module Type GroupSetMagmaSig.
Definition sort (gT : finStarMonoidType) := Magma.sort {set gT}.
End GroupSetMagmaSig.

Module MakeGroupSetMagma (Gset_base : GroupSetMagmaSig).
Identity Coercion of_sort : Gset_base.sort >-> Magma.sort.
End MakeGroupSetMagma.

Module Export GroupSetMagma := MakeGroupSetMagma GroupSet.

Module Type GroupSetBaseGroupSig.
Definition sort (gT : finStarMonoidType) := BaseGroup.sort {set gT}.
End GroupSetBaseGroupSig.

Module MakeGroupSetBaseGroup (Gset_base : GroupSetBaseGroupSig).
Identity Coercion of_sort : Gset_base.sort >-> BaseGroup.sort.
End MakeGroupSetBaseGroup.

Module Export GroupSetBaseGroup := MakeGroupSetBaseGroup GroupSet.

HB.instance Definition _ gT : Finite (GroupSet.sort gT) :=
   Finite.class {set gT}.

Section GroupSetMulDef.
(* Some of these constructs could be defined on a finStarMonoidType. *)
(* We restrict them to proper finGroupType because we only develop   *)
(* the theory for that case.                                         *)
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Type x y : gT.

Definition lcoset A x := mul x @: A.
Definition rcoset A x := mul^~ x @: A.
Definition lcosets A B := lcoset A @: B.
Definition rcosets A B := rcoset A @: B.
Definition indexg B A := #|rcosets A B|.

Definition conjugate A x := conjg^~ x @: A.
Definition conjugates A B := conjugate A @: B.
Definition class x B := conjg x @: B.
Definition classes A := class^~ A @: A.
Definition class_support A B := conjg @2: (A, B).

Definition commg_set A B := commg @2: (A, B).

(* These will only be used later, but are defined here so that we can *)
(* keep all the Notation together.                                    *)
Definition normaliser A := [set x | conjugate A x \subset A].
Definition centraliser A := \bigcap_(x in A) normaliser [set x].
Definition abelian A := A \subset centraliser A.
Definition normal A B := (A \subset B) && (B \subset normaliser A).

(* "normalised" and "centralise[s|d]" are intended to be used with   *)
(* the {in ...} form, as in abelian below.                           *)
Definition normalised A := forall x, conjugate A x = A.
Definition centralises x A := forall y, y \in A -> commute x y.
Definition centralised A := forall x, centralises x A.

End GroupSetMulDef.

Arguments lcoset _ _%_g _%_g.
Arguments rcoset _ _%_g _%_g.
Arguments rcosets _ _%_g _%_g.
Arguments lcosets _ _%_g _%_g.
Arguments indexg _ _%_g _%_g.
Arguments conjugate _ _%_g _%_g.
Arguments conjugates _ _%_g _%_g.
Arguments class _ _%_g _%_g.
Arguments classes _ _%_g.
Arguments class_support _ _%_g _%_g.
Arguments commg_set _ _%_g _%_g.
Arguments normaliser _ _%_g.
Arguments centraliser _ _%_g.
Arguments abelian _ _%_g.
Arguments normal _ _%_g _%_g.
Arguments normalised _ _%_g.
Arguments centralises _ _%_g _%_g.
Arguments centralised _ _%_g.

Notation "[ 1 gT ]" := (1 : {set gT}) : group_scope.
Notation "[ 1 ]" := [1 FinGroup.sort _] : group_scope.

Notation "A ^#" := (A :\ 1) : group_scope.

Notation "x *: A" := ([set x%g] * A) : group_scope.
Notation "A :* x" := (A * [set x%g]) : group_scope.
Notation "A :^ x" := (conjugate A x) : group_scope.
Notation "x ^: B" := (class x B) : group_scope.
Notation "A :^: B" := (conjugates A B) : group_scope.

Notation "#| B : A |" := (indexg B A) : group_scope.

(* No notation for lcoset and rcoset, which are to be used mostly  *)
(* in curried form; x *: B and A :* 1 denote singleton products,   *)
(* so we can use mulgA, mulg1, etc, on, say, A :* 1 * B :* x.      *)
(* No notation for the set commutator generator set commg_set.     *)

Notation "''N' ( A )" := (normaliser A) : group_scope.
Notation "''N_' G ( A )" := (G%g :&: 'N(A)) : group_scope.
Notation "A <| B" := (normal A B) : group_scope.
Notation "''C' ( A )" := (centraliser A) : group_scope.
Notation "''C_' G ( A )" := (G%g :&: 'C(A)) : group_scope.
Notation "''C_' ( G ) ( A )" := 'C_G(A) (only parsing) : group_scope.
Notation "''C' [ x ]" := 'N([set x%g]) : group_scope.
Notation "''C_' G [ x ]" := 'N_G([set x%g]) : group_scope.
Notation "''C_' ( G ) [ x ]" := 'C_G[x] (only parsing) : group_scope.

Prenex Implicits repr lcoset rcoset lcosets rcosets normal.
Prenex Implicits conjugate conjugates class classes class_support.
Prenex Implicits commg_set normalised centralised abelian.

Section BaseSetMulProp.
(* Properties of the purely multiplicative structure. *)
Variable gT : finStarMonoidType.
Implicit Types A B C D : {set gT}.
Implicit Type x y z : gT.

(* Set product. We already have all the pregroup identities, so we *)
(* only need to add the monotonicity rules.                        *)

Lemma mulsgP A B x :
  reflect (imset2_spec mul (mem A) (fun _ => mem B) x) (x \in A * B).
Proof.
Admitted.

Lemma mem_mulg A B x y : x \in A -> y \in B -> x * y \in A * B.
Proof.
Admitted.

Lemma prodsgP (I : finType) (P : pred I) (A : I -> {set gT}) x :
  reflect (exists2 c, forall i, P i -> c i \in A i & x = \prod_(i | P i) c i)
          (x \in \prod_(i | P i) A i).
Proof.
Admitted.

Lemma mem_prodg (I : finType) (P : pred I) (A : I -> {set gT}) c :
  (forall i, P i -> c i \in A i) -> \prod_(i | P i) c i \in \prod_(i | P i) A i.
Proof.
Admitted.

Lemma mulSg A B C : A \subset B -> A * C \subset B * C.
Proof.
Admitted.

Lemma mulgS A B C : B \subset C -> A * B \subset A * C.
Proof.
Admitted.

Lemma mulgSS A B C D : A \subset B -> C \subset D -> A * C \subset B * D.
Proof.
Admitted.

Lemma mulg_subl A B : 1 \in B -> A \subset A * B.
Proof.
Admitted.

Lemma mulg_subr A B : 1 \in A -> B \subset A * B.
Proof.
Admitted.

Lemma mulUg A B C : (A :|: B) * C = (A * C) :|: (B * C).
Proof.
Admitted.

Lemma mulgU A B C : A * (B :|: C) = (A * B) :|: (A * C).
Proof.
Admitted.

(* Set (pointwise) inverse. *)

Lemma invUg A B : (A :|: B)^-1 = A^-1 :|: B^-1.
Proof.
Admitted.

Lemma invIg A B : (A :&: B)^-1 = A^-1 :&: B^-1.
Proof.
Admitted.

Lemma invDg A B : (A :\: B)^-1 = A^-1 :\: B^-1.
Proof.
Admitted.

Lemma invCg A : (~: A)^-1 = ~: A^-1.
Proof.
Admitted.

Lemma invSg A B : (A^-1 \subset B^-1) = (A \subset B).
Proof.
Admitted.

Lemma mem_invg x A : (x \in A^-1) = (x^-1 \in A).
Proof.
Admitted.

Lemma memV_invg x A : (x^-1 \in A^-1) = (x \in A).
Proof.
Admitted.

Lemma card_invg A : #|A^-1| = #|A|.
Proof.
Admitted.

(* Product with singletons. *)

Lemma set1gE : 1 = [set 1] :> {set gT}.
Proof.
Admitted.
Lemma set1gP x : reflect (x = 1) (x \in [1 gT]).
Proof.
Admitted.

Lemma mulg_set1 x y : [set x] :* y = [set x * y].
Proof.
Admitted.

Lemma invg_set1 x : [set x]^-1 = [set x^-1].
Proof.
Admitted.

End BaseSetMulProp.

Arguments set1gP {gT x}.
Arguments mulsgP {gT A B x}.
Arguments prodsgP {gT I P A x}.

Section GroupSetMulProp.
(* Constructs that need a finGroupType *)
Variable gT : finGroupType.
Implicit Types A B C D : {set gT}.
Implicit Type x y z : gT.

(* Left cosets. *)

Lemma lcosetE A x : lcoset A x = x *: A.
Proof.
Admitted.

Lemma card_lcoset A x : #|x *: A| = #|A|.
Proof.
Admitted.

Lemma mem_lcoset A x y : (y \in x *: A) = (x^-1 * y \in A).
Proof.
Admitted.

Lemma lcosetP A x y : reflect (exists2 a, a \in A & y = x * a) (y \in x *: A).
Proof.
Admitted.

Lemma lcosetsP A B C :
  reflect (exists2 x, x \in B & C = x *: A) (C \in lcosets A B).
Proof.
Admitted.

Lemma lcosetM A x y : (x * y) *: A = x *: (y *: A).
Proof.
Admitted.

Lemma lcoset1 A : 1 *: A = A.
Proof.
Admitted.

Lemma lcosetK : left_loop inv (fun x A => x *: A).
Proof.
Admitted.

Lemma lcosetKV : rev_left_loop inv (fun x A => x *: A).
Proof.
Admitted.

Lemma lcoset_inj : right_injective (fun x A => x *: A).
Proof.
Admitted.

Lemma lcosetS x A B : (x *: A \subset x *: B) = (A \subset B).
Proof.
Admitted.

Lemma sub_lcoset x A B : (A \subset x *: B) = (x^-1 *: A \subset B).
Proof.
Admitted.

Lemma sub_lcosetV x A B : (A \subset x^-1 *: B) = (x *: A \subset B).
Proof.
Admitted.

(* Right cosets. *)

Lemma rcosetE A x : rcoset A x = A :* x.
Proof.
Admitted.

Lemma card_rcoset A x : #|A :* x| = #|A|.
Proof.
Admitted.

Lemma mem_rcoset A x y : (y \in A :* x) = (y * x^-1 \in A).
Proof.
Admitted.

Lemma rcosetP A x y : reflect (exists2 a, a \in A & y = a * x) (y \in A :* x).
Proof.
Admitted.

Lemma rcosetsP A B C :
  reflect (exists2 x, x \in B & C = A :* x) (C \in rcosets A B).
Proof.
Admitted.

Lemma rcosetM A x y : A :* (x * y) = A :* x :* y.
Proof.
Admitted.

Lemma rcoset1 A : A :* 1 = A.
Proof.
Admitted.

Lemma rcosetK : right_loop inv (fun A x => A :* x).
Proof.
Admitted.

Lemma rcosetKV : rev_right_loop inv (fun A x => A :* x).
Proof.
Admitted.

Lemma rcoset_inj : left_injective (fun A x => A :* x).
Proof.
Admitted.

Lemma rcosetS x A B : (A :* x \subset B :* x) = (A \subset B).
Proof.
Admitted.

Lemma sub_rcoset x A B : (A \subset B :* x) = (A :* x ^-1 \subset B).
Proof.
Admitted.

Lemma sub_rcosetV x A B : (A \subset B :* x^-1) = (A :* x \subset B).
Proof.
Admitted.

(* Inverse maps lcosets to rcosets *)
Lemma invg_lcosets A B : (lcosets A B)^-1 = rcosets A^-1 B^-1.
Proof.
Admitted.

(* Conjugates. *)

Lemma conjg_preim A x : A :^ x = (conjg^~ x^-1) @^-1: A.
Proof.
Admitted.

Lemma mem_conjg A x y : (y \in A :^ x) = (y ^ x^-1 \in A).
Proof.
Admitted.

Lemma mem_conjgV A x y : (y \in A :^ x^-1) = (y ^ x \in A).
Proof.
Admitted.

Lemma memJ_conjg A x y : (y ^ x \in A :^ x) = (y \in A).
Proof.
Admitted.

Lemma conjsgE A x : A :^ x = x^-1 *: (A :* x).
Proof.
Admitted.

Lemma conjsg1 A : A :^ 1 = A.
Proof.
Admitted.

Lemma conjsgM A x y : A :^ (x * y) = (A :^ x) :^ y.
Proof.
Admitted.

Lemma conjsgK : @right_loop _ gT inv conjugate.
Proof.
Admitted.

Lemma conjsgKV : @rev_right_loop _ gT inv conjugate.
Proof.
Admitted.

Lemma conjsg_inj : @left_injective _ gT _ conjugate.
Proof.
Admitted.

Lemma cardJg A x : #|A :^ x| = #|A|.
Proof.
Admitted.

Lemma conjSg A B x : (A :^ x \subset B :^ x) = (A \subset B).
Proof.
Admitted.

Lemma properJ A B x : (A :^ x \proper B :^ x) = (A \proper B).
Proof.
Admitted.

Lemma sub_conjg A B x : (A :^ x \subset B) = (A \subset B :^ x^-1).
Proof.
Admitted.

Lemma sub_conjgV A B x : (A :^ x^-1 \subset B) = (A \subset B :^ x).
Proof.
Admitted.

Lemma conjg_set1 x y : [set x] :^ y = [set x ^ y].
Proof.
Admitted.

Lemma conjs1g x : 1 :^ x = 1.
Proof.
Admitted.

Lemma conjsg_eq1 A x : (A :^ x == 1%g) = (A == 1%g).
Proof.
Admitted.

Lemma conjsMg A B x : (A * B) :^ x = A :^ x * B :^ x.
Proof.
Admitted.

Lemma conjIg A B x : (A :&: B) :^ x = A :^ x :&: B :^ x.
Proof.
Admitted.

Lemma conj0g x : set0 :^ x = set0.
Proof.
Admitted.

Lemma conjTg x : [set: gT] :^ x = [set: gT].
Proof.
Admitted.

Lemma bigcapJ I r (P : pred I) (B : I -> {set gT}) x :
  \bigcap_(i <- r | P i) (B i :^ x) = (\bigcap_(i <- r | P i) B i) :^ x.
Proof.
Admitted.

Lemma conjUg A B x : (A :|: B) :^ x = A :^ x :|: B :^ x.
Proof.
Admitted.

Lemma bigcupJ I r (P : pred I) (B : I -> {set gT}) x :
  \bigcup_(i <- r | P i) (B i :^ x) = (\bigcup_(i <- r | P i) B i) :^ x.
Proof.
Admitted.

Lemma conjCg A x : (~: A) :^ x = ~: A :^ x.
Proof.
Admitted.

Lemma conjDg A B x : (A :\: B) :^ x = A :^ x :\: B :^ x.
Proof.
Admitted.

Lemma conjD1g A x : A^# :^ x = (A :^ x)^#.
Proof.
Admitted.

(* Classes; not much for now. *)

Lemma memJ_class x y A : y \in A -> x ^ y \in x ^: A.
Proof.
Admitted.

Lemma classS x A B : A \subset B -> x ^: A \subset x ^: B.
Proof.
Admitted.

Lemma class_set1 x y :  x ^: [set y] = [set x ^ y].
Proof.
Admitted.

Lemma class1g x A : x \in A -> 1 ^: A = 1.
Proof.
Admitted.

Lemma classVg x A : x^-1 ^: A = (x ^: A)^-1.
Proof.
Admitted.

Lemma mem_classes x A : x \in A -> x ^: A \in classes A.
Proof.
Admitted.

Lemma memJ_class_support A B x y :
   x \in A -> y \in B -> x ^ y \in class_support A B.
Proof.
Admitted.

Lemma class_supportM A B C :
  class_support A (B * C) = class_support (class_support A B) C.
Proof.
Admitted.

Lemma class_support_set1l A x : class_support [set x] A = x ^: A.
Proof.
Admitted.

Lemma class_support_set1r A x : class_support A [set x] = A :^ x.
Proof.
Admitted.

Lemma classM x A B : x ^: (A * B) = class_support (x ^: A) B.
Proof.
Admitted.

Lemma class_lcoset x y A : x ^: (y *: A) = (x ^ y) ^: A.
Proof.
Admitted.

Lemma class_rcoset x A y : x ^: (A :* y) = (x ^: A) :^ y.
Proof.
Admitted.

(* Conjugate set. *)

Lemma conjugatesS A B C : B \subset C -> A :^: B \subset A :^: C.
Proof.
Admitted.

Lemma conjugates_set1 A x : A :^: [set x] = [set A :^ x].
Proof.
Admitted.

Lemma conjugates_conj A x B : (A :^ x) :^: B = A :^: (x *: B).
Proof.
Admitted.

(* Class support. *)

Lemma class_supportEl A B : class_support A B = \bigcup_(x in A) x ^: B.
Proof.
Admitted.

Lemma class_supportEr A B : class_support A B = \bigcup_(x in B) A :^ x.
Proof.
Admitted.

(* Groups (at last!) *)

Definition group_set A := (1 \in A) && (A * A \subset A).

Lemma group_setP A :
  reflect (1 \in A /\ {in A & A, forall x y, x * y \in A}) (group_set A).
Proof.
Admitted.

Structure group_type : Type := Group {
  gval :> GroupSet.sort gT;
  _ : group_set gval
}.

Definition group_of : predArgType := group_type.
Local Notation groupT := group_of.
Identity Coercion type_of_group : group_of >-> group_type.

HB.instance Definition _ := [isSub for gval].
#[hnf] HB.instance Definition _ := [Finite of group_type by <:].

(* No predType or finStarMonoidType structures, as these would hide the *)
(* group-to-set coercion and thus spoil unification.                    *)
HB.instance Definition _ := SubFinite.copy groupT group_type.

Definition group (A : {set gT}) gA : groupT := @Group A gA.

Definition clone_group G :=
  let: Group _ gP := G return {type of Group for G} -> groupT in fun k => k gP.

Lemma group_inj : injective gval.
Proof.
Admitted.
Lemma groupP (G : groupT) : group_set G.
Proof.
Admitted.

Lemma congr_group (H K : groupT) : H = K -> H :=: K.
Proof.
Admitted.

Lemma isgroupP A : reflect (exists G : groupT, A = G) (group_set A).
Proof.
Admitted.

Lemma group_set_one : group_set 1.
Proof.
Admitted.

Canonical one_group := group group_set_one.
Canonical set1_group := @group [set 1] group_set_one.

Lemma group_setT : group_set (setTfor gT).
Proof.
Admitted.

Canonical setT_group := group group_setT.

End GroupSetMulProp.

Arguments group_of gT%_type.
Arguments lcosetP {gT A x y}.
Arguments lcosetsP {gT A B C}.
Arguments rcosetP {gT A x y}.
Arguments rcosetsP {gT A B C}.
Arguments group_setP {gT A}.
Arguments setT_group gT%_type.
Prenex Implicits group_set mulsgP set1gP.

Notation "{ 'group' gT }" := (group_of gT)
  (format "{ 'group'  gT }") : type_scope.

Notation "[ 'group' 'of' G ]" := (clone_group (@group _ G))
  (format "[ 'group'  'of'  G ]") : form_scope.

Bind Scope Group_scope with group_type.
Bind Scope Group_scope with group_of.
Notation "1" := (one_group _) : Group_scope.
Notation "[ 1 gT ]" := (1%G : {group gT}) : Group_scope.
Notation "[ 'set' : gT ]" := (setT_group gT) : Group_scope.

(* These definitions come early so we can establish the Notation. *)
HB.lock
Definition generated (gT : finGroupType) (A : {set gT}) :=
  \bigcap_(G : {group gT} | A \subset G) G.
Canonical generated_unlockable := Unlockable generated.unlock.

Definition gcore (gT : finGroupType) (A B : {set gT}) := \bigcap_(x in B) A :^ x.
Definition joing (gT : finGroupType) (A B : {set gT}) := generated (A :|: B).
Definition commutator (gT : finGroupType) (A B : {set gT}) := generated (commg_set A B).
Definition cycle (gT : finGroupType) (x : gT) := generated [set x].
Definition order (gT : finGroupType) (x : gT) := #|cycle x|.

Arguments commutator _ _%_g _%_g.
Arguments joing _ _%_g _%_g.
Arguments generated _ _%_g.

(* Helper notation for defining new groups that need a bespoke finGroupType. *)
(* The actual group for such a type (say, my_gT) will be the full group,     *)
(* i.e., [set: my_gT] or [set: my_gT]%G, but Coq will not recognize          *)
(* specific notation for these because of the coercions inserted during type *)
(* inference, unless they are defined as [set: gsort my_gT] using the        *)
(* Notation below.                                                           *)
Notation gsort gT := (FinStarMonoid.arg_sort gT%type) (only parsing).
Notation "<< A >>"  := (generated A) : group_scope.
Notation "<[ x ] >"  := (cycle x) : group_scope.
Notation "#[ x ]"  := (order x) : group_scope.
Notation "A <*> B" := (joing A B) : group_scope.
Notation "[ ~: A1 , A2 , .. , An ]" :=
  (commutator .. (commutator A1 A2) .. An) : group_scope.

Prenex Implicits order cycle gcore.

Section GroupProp.

Variable gT : finGroupType.
Notation sT := {set gT}.
Implicit Types A B C D : sT.
Implicit Types x y z : gT.
Implicit Types G H K : {group gT}.

Section OneGroup.

Variable G : {group gT}.

Lemma valG : val G = G.
Proof.
Admitted.

(* Non-triviality. *)

Lemma group1 : 1 \in G.
Proof.
Admitted.
#[local] Hint Resolve group1 : core.

Lemma group1_contra x : x \notin G -> x != 1.
Proof.
Admitted.

Lemma sub1G : [1 gT] \subset G.
Proof.
Admitted.
Lemma subG1 : (G \subset [1]) = (G :==: 1).
Proof.
Admitted.

Lemma setI1g : 1 :&: G = 1.
Proof.
Admitted.
Lemma setIg1 : G :&: 1 = 1.
Proof.
Admitted.

Lemma subG1_contra H : G \subset H -> G :!=: 1 -> H :!=: 1.
Proof.
Admitted.

Lemma repr_group : repr G = 1.
Proof.
Admitted.

Lemma cardG_gt0 : 0 < #|G|.
Proof.
Admitted.

Lemma indexg_gt0 A : 0 < #|G : A|.
Proof.
Admitted.

Lemma trivgP : reflect (G :=: 1) (G \subset [1]).
Proof.
Admitted.

Lemma trivGP : reflect (G = 1%G) (G \subset [1]).
Proof.
Admitted.

Lemma proper1G : ([1] \proper G) = (G :!=: 1).
Proof.
Admitted.

Lemma in_one_group x : (x \in 1%G) = (x == 1).
Proof.
Admitted.

Definition inE := (in_one_group, inE).

Lemma trivgPn : reflect (exists2 x, x \in G & x != 1) (G :!=: 1).
Proof.
Admitted.

Lemma trivg_card_le1 : (G :==: 1) = (#|G| <= 1).
Proof.
Admitted.

Lemma trivg_card1 : (G :==: 1) = (#|G| == 1%N).
Proof.
Admitted.

Lemma cardG_gt1 : (#|G| > 1) = (G :!=: 1).
Proof.
Admitted.

Lemma card_le1_trivg : #|G| <= 1 -> G :=: 1.
Proof.
Admitted.

Lemma card1_trivg : #|G| = 1%N -> G :=: 1.
Proof.
Admitted.

(* Inclusion and product. *)

Lemma mulG_subl A : A \subset A * G.
Proof.
Admitted.

Lemma mulG_subr A : A \subset (G * A).
Proof.
Admitted.

Lemma mulGid : G * G = G.
Proof.
Admitted.

Lemma mulGS A B : (G * A \subset G * B) = (A \subset G * B).
Proof.
Admitted.

Lemma mulSG A B : (A * G \subset B * G) = (A \subset B * G).
Proof.
Admitted.

Lemma mul_subG A B : A \subset G -> B \subset G -> A * B \subset G.
Proof.
Admitted.

Lemma prod_subG (I : Type) (r : seq I) (P : {pred I}) (F : I -> {set gT}) :
  (forall i, P i -> F i \subset G) -> \prod_(i <- r | P i) F i \subset G.
Proof.
Admitted.

(* Membership lemmas *)

Lemma groupM x y : x \in G -> y \in G -> x * y \in G.
Proof.
Admitted.

Lemma groupX x n : x \in G -> x ^+ n \in G.
Proof.
Admitted.

Lemma groupVr x : x \in G -> x^-1 \in G.
Proof.
Admitted.

Lemma groupVl x : x^-1 \in G -> x \in G.
Proof.
Admitted.

Lemma groupV x : (x^-1 \in G) = (x \in G).
Proof.
Admitted.

Lemma groupMl x y : x \in G -> (x * y \in G) = (y \in G).
Proof.
Admitted.

Lemma groupMr x y : x \in G -> (y * x \in G) = (y \in G).
Proof.
Admitted.

Definition in_group := (group1, groupV, (groupMl, groupX)).

Lemma groupJ x y : x \in G -> y \in G -> x ^ y \in G.
Proof.
Admitted.

Lemma groupJr x y : y \in G -> (x ^ y \in G) = (x \in G).
Proof.
Admitted.

Lemma groupR x y : x \in G -> y \in G -> [~ x, y] \in G.
Proof.
Admitted.

Lemma group_prod I r (P : pred I) F :
  (forall i, P i -> F i \in G) -> \prod_(i <- r | P i) F i \in G.
Proof.
Admitted.

(* Inverse is an anti-morphism. *)

Lemma invGid : G^-1 = G.
Proof.
Admitted.

Lemma inv_subG A : (A^-1 \subset G) = (A \subset G).
Proof.
Admitted.

Lemma invg_lcoset x : (x *: G)^-1 = G :* x^-1.
Proof.
Admitted.

Lemma invg_rcoset x : (G :* x)^-1 = x^-1 *: G.
Proof.
Admitted.

Lemma memV_lcosetV x y : (y^-1 \in x^-1 *: G) = (y \in G :* x).
Proof.
Admitted.

Lemma memV_rcosetV x y : (y^-1 \in G :* x^-1) = (y \in x *: G).
Proof.
Admitted.

(* Product idempotence *)

Lemma mulSgGid A x : x \in A -> A \subset G -> A * G = G.
Proof.
Admitted.

Lemma mulGSgid A x : x \in A -> A \subset G -> G * A = G.
Proof.
Admitted.

(* Left cosets *)

Lemma lcoset_refl x : x \in x *: G.
Proof.
Admitted.

Lemma lcoset_sym x y : (x \in y *: G) = (y \in x *: G).
Proof.
Admitted.

Lemma lcoset_eqP {x y} : reflect (x *: G = y *: G) (x \in y *: G).
Proof.
Admitted.

Lemma lcoset_transl x y z : x \in y *: G -> (x \in z *: G) = (y \in z *: G).
Proof.
Admitted.

Lemma lcoset_trans x y z : x \in y *: G -> y \in z *: G -> x \in z *: G.
Proof.
Admitted.

Lemma lcoset_id x : x \in G -> x *: G = G.
Proof.
Admitted.

(* Right cosets, with an elimination form for repr. *)

Lemma rcoset_refl x : x \in G :* x.
Proof.
Admitted.

Lemma rcoset_sym x y : (x \in G :* y) = (y \in G :* x).
Proof.
Admitted.

Lemma rcoset_eqP {x y} : reflect (G :* x = G :* y) (x \in G :* y).
Proof.
Admitted.

Lemma rcoset_transl x y z : x \in G :* y -> (x \in G :* z) = (y \in G :* z).
Proof.
Admitted.

Lemma rcoset_trans x y z : x \in G :* y -> y \in G :* z -> x \in G :* z.
Proof.
Admitted.

Lemma rcoset_id x : x \in G -> G :* x = G.
Proof.
Admitted.

(* Elimination form. *)

Variant rcoset_repr_spec x : gT -> Type :=
  RcosetReprSpec g : g \in G -> rcoset_repr_spec x (g * x).

Lemma mem_repr_rcoset x : repr (G :* x) \in G :* x.
Proof.
Admitted.

(* This form sometimes fails because ssreflect 1.1 delegates matching to the *)
(* (weaker) primitive Coq algorithm for general (co)inductive type families. *)
Lemma repr_rcosetP x : rcoset_repr_spec x (repr (G :* x)).
Proof.
Admitted.

Lemma rcoset_repr x : G :* (repr (G :* x)) = G :* x.
Proof.
Admitted.

(* Coset spaces. *)

Lemma mem_rcosets A x : (G :* x \in rcosets G A) = (x \in G * A).
Proof.
Admitted.

Lemma mem_lcosets A x : (x *: G \in lcosets G A) = (x \in A * G).
Proof.
Admitted.

(* Conjugates. *)

Lemma group_setJ A x : group_set (A :^ x) = group_set A.
Proof.
Admitted.

Lemma group_set_conjG x : group_set (G :^ x).
Proof.
Admitted.

Canonical conjG_group x := group (group_set_conjG x).

Lemma conjGid : {in G, normalised G}.
Proof.
Admitted.

Lemma conj_subG x A : x \in G -> A \subset G -> A :^ x \subset G.
Proof.
Admitted.

(* Classes *)

Lemma class1G : 1 ^: G = 1.
Proof.
Admitted.

Lemma classes1 : [1] \in classes G.
Proof.
Admitted.

Lemma classGidl x y : y \in G -> (x ^ y) ^: G = x ^: G.
Proof.
Admitted.

Lemma classGidr x : {in G, normalised (x ^: G)}.
Proof.
Admitted.

Lemma class_refl x : x \in x ^: G.
Proof.
Admitted.
#[local] Hint Resolve class_refl : core.

Lemma class_eqP x y : reflect (x ^: G = y ^: G) (x \in y ^: G).
Proof.
Admitted.

Lemma class_sym x y : (x \in y ^: G) = (y \in x ^: G).
Proof.
Admitted.

Lemma class_transl x y z : x \in y ^: G -> (x \in z ^: G) = (y \in z ^: G).
Proof.
Admitted.

Lemma class_trans x y z : x \in y ^: G -> y \in z ^: G -> x \in z ^: G.
Proof.
Admitted.

Lemma repr_class x : {y | y \in G & repr (x ^: G) = x ^ y}.
Proof.
Admitted.

Lemma classG_eq1 x : (x ^: G == 1) = (x == 1).
Proof.
Admitted.

Lemma class_subG x A : x \in G -> A \subset G -> x ^: A \subset G.
Proof.
Admitted.

Lemma repr_classesP xG :
  reflect (repr xG \in G /\ xG = repr xG ^: G) (xG \in classes G).
Proof.
Admitted.

Lemma mem_repr_classes xG : xG \in classes G -> repr xG \in xG.
Proof.
Admitted.

Lemma classes_gt0 : 0 < #|classes G|.
Proof.
Admitted.

Lemma classes_gt1 : (#|classes G| > 1) = (G :!=: 1).
Proof.
Admitted.

Lemma mem_class_support A x : x \in A -> x \in class_support A G.
Proof.
Admitted.

Lemma class_supportGidl A x :
  x \in G -> class_support (A :^ x) G = class_support A G.
Proof.
Admitted.

Lemma class_supportGidr A : {in G, normalised (class_support A G)}.
Proof.
Admitted.

Lemma class_support_subG A : A \subset G -> class_support A G \subset G.
Proof.
Admitted.

Lemma sub_class_support A : A \subset class_support A G.
Proof.
Admitted.

Lemma class_support_id : class_support G G = G.
Proof.
Admitted.

Lemma class_supportD1 A : (class_support A G)^# =  cover (A^# :^: G).
Proof.
Admitted.

(* Subgroup Type construction. *)
(* We only expect to use this for abstract groups, so we don't project *)
(* the argument to a set.                                              *)

Inductive subg_of : predArgType := Subg x & x \in G.
Definition sgval u := let: Subg x _ := u in x.
Definition subg_of_Sub := Eval hnf in [isSub for sgval].
HB.instance Definition _ := subg_of_Sub.
#[hnf] HB.instance Definition _ := [Finite of subg_of by <:].

Lemma subgP u : sgval u \in G.
Proof.
Admitted.
Lemma subg_inj : injective sgval.
Proof.
Admitted.
Lemma congr_subg u v : u = v -> sgval u = sgval v.
Proof.
Admitted.

Definition subg_one := Subg group1.
Definition subg_inv u := Subg (groupVr (subgP u)).
Definition subg_mul u v := Subg (groupM (subgP u) (subgP v)).
Lemma subg_oneP : left_id subg_one subg_mul.
Proof.
Admitted.

Lemma subg_invP : left_inverse subg_one subg_inv subg_mul.
Proof.
Admitted.
Lemma subg_mulP : associative subg_mul.
Proof.
Admitted.

HB.instance Definition _ := Finite_isGroup.Build subg_of
  subg_mulP subg_oneP subg_invP.

Lemma sgvalM : {in setT &, {morph sgval : x y / x * y}}.
Proof.
Admitted.
Lemma valgM : {in setT &, {morph val : x y / (x : subg_of) * y >-> x * y}}.
Proof.
Admitted.

Definition subg : gT -> subg_of := insubd (1 : subg_of).
Lemma subgK x : x \in G -> val (subg x) = x.
Proof.
Admitted.
Lemma sgvalK : cancel sgval subg.
Proof.
Admitted.
Lemma subg_default x : (x \in G) = false -> val (subg x) = 1.
Proof.
Admitted.
Lemma subgM : {in G &, {morph subg : x y / x * y}}.
Proof.
Admitted.

End OneGroup.

#[local] Hint Resolve group1 : core.

Lemma groupD1_inj G H : G^# = H^# -> G :=: H.
Proof.
Admitted.

Lemma invMG G H : (G * H)^-1 = H * G.
Proof.
Admitted.

Lemma mulSGid G H : H \subset G -> H * G = G.
Proof.
Admitted.

Lemma mulGSid G H : H \subset G -> G * H = G.
Proof.
Admitted.

Lemma mulGidPl G H : reflect (G * H = G) (H \subset G).
Proof.
Admitted.

Lemma mulGidPr G H : reflect (G * H = H) (G \subset H).
Proof.
Admitted.

Lemma comm_group_setP G H : reflect (commute G H) (group_set (G * H)).
Proof.
Admitted.

Lemma card_lcosets G H : #|lcosets H G| = #|G : H|.
Proof.
Admitted.

(* Group Modularity equations *)

Lemma group_modl A B G : A \subset G -> A * (B :&: G) = A * B :&: G.
Proof.
Admitted.

Lemma group_modr A B G : B \subset G -> (G :&: A) * B = G :&: A * B.
Proof.
Admitted.

End GroupProp.

#[global] Hint Extern 0 (is_true (1%g \in _)) => apply: group1 : core.
#[global] Hint Extern 0 (is_true (0 < #|_|)) => apply: cardG_gt0 : core.
#[global] Hint Extern 0 (is_true (0 < #|_ : _|)) => apply: indexg_gt0 : core.

Notation "G :^ x" := (conjG_group G x) : Group_scope.

Notation "[ 'subg' G ]" := (subg_of G) : type_scope.
Notation "[ 'subg' G ]" := [set: subg_of G] : group_scope.
Notation "[ 'subg' G ]" := [set: subg_of G]%G : Group_scope.

Prenex Implicits subg sgval subg_of.
Bind Scope group_scope with subg_of.
Arguments subgK {gT G}.
Arguments sgvalK {gT G}.
Arguments subg_inj {gT G} [u1 u2] eq_u12 : rename.

Arguments trivgP {gT G}.
Arguments trivGP {gT G}.
Arguments lcoset_eqP {gT G x y}.
Arguments rcoset_eqP {gT G x y}.
Arguments mulGidPl {gT G H}.
Arguments mulGidPr {gT G H}.
Arguments comm_group_setP {gT G H}.
Arguments class_eqP {gT G x y}.
Arguments repr_classesP {gT G xG}.

Section GroupInter.

Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H : {group gT}.

Lemma group_setI G H : group_set (G :&: H).
Proof.
Admitted.

Canonical setI_group G H := group (group_setI G H).

Section Nary.

Variables (I : finType) (P : pred I) (F : I -> {group gT}).

Lemma group_set_bigcap : group_set (\bigcap_(i | P i) F i).
Proof.
Admitted.

Canonical bigcap_group := group group_set_bigcap.

End Nary.

Lemma group_set_generated (A : {set gT}) : group_set <<A>>.
Proof.
Admitted.

Canonical generated_group A := group (group_set_generated A).
Canonical gcore_group G A : {group _} := Eval hnf in [group of gcore G A].
Canonical commutator_group A B : {group _} := Eval hnf in [group of [~: A, B]].
Canonical joing_group A B : {group _} := Eval hnf in [group of A <*> B].
Canonical cycle_group x : {group _} := Eval hnf in [group of <[x]>].

Definition joinG G H := joing_group G H.

Definition subgroups A := [set G : {group gT} | G \subset A].

Lemma order_gt0 (x : gT) : 0 < #[x].
Proof.
Admitted.

End GroupInter.

#[global] Hint Resolve order_gt0 : core.

Arguments generated_group _ _%_g.
Arguments joing_group _ _%_g _%_g.
Arguments subgroups _ _%_g.

Notation "G :&: H" := (setI_group G H) : Group_scope.
Notation "<< A >>"  := (generated_group A) : Group_scope.
Notation "<[ x ] >"  := (cycle_group x) : Group_scope.
Notation "[ ~: A1 , A2 , .. , An ]" :=
  (commutator_group .. (commutator_group A1 A2) .. An) : Group_scope.
Notation "A <*> B" := (joing_group A B) : Group_scope.
Notation "G * H" := (joinG G H) : Group_scope.
Prenex Implicits joinG subgroups.

Notation "\prod_ ( i <- r | P ) F" :=
  (\big[joinG/1%G]_(i <- r | P%B) F%G) : Group_scope.
Notation "\prod_ ( i <- r ) F" :=
  (\big[joinG/1%G]_(i <- r) F%G) : Group_scope.
Notation "\prod_ ( m <= i < n | P ) F" :=
  (\big[joinG/1%G]_(m <= i < n | P%B) F%G) : Group_scope.
Notation "\prod_ ( m <= i < n ) F" :=
  (\big[joinG/1%G]_(m <= i < n) F%G) : Group_scope.
Notation "\prod_ ( i | P ) F" :=
  (\big[joinG/1%G]_(i | P%B) F%G) : Group_scope.
Notation "\prod_ i F" :=
  (\big[joinG/1%G]_i F%G) : Group_scope.
Notation "\prod_ ( i : t | P ) F" :=
  (\big[joinG/1%G]_(i : t | P%B) F%G) (only parsing) : Group_scope.
Notation "\prod_ ( i : t ) F" :=
  (\big[joinG/1%G]_(i : t) F%G) (only parsing) : Group_scope.
Notation "\prod_ ( i < n | P ) F" :=
  (\big[joinG/1%G]_(i < n | P%B) F%G) : Group_scope.
Notation "\prod_ ( i < n ) F" :=
  (\big[joinG/1%G]_(i < n) F%G) : Group_scope.
Notation "\prod_ ( i 'in' A | P ) F" :=
  (\big[joinG/1%G]_(i in A | P%B) F%G) : Group_scope.
Notation "\prod_ ( i 'in' A ) F" :=
  (\big[joinG/1%G]_(i in A) F%G) : Group_scope.

Section Lagrange.

Variable gT : finGroupType.
Implicit Types G H K : {group gT}.

Lemma LagrangeI G H : (#|G :&: H| * #|G : H|)%N = #|G|.
Proof.
Admitted.

Lemma divgI G H : #|G| %/ #|G :&: H| = #|G : H|.
Proof.
Admitted.

Lemma divg_index G H : #|G| %/ #|G : H| = #|G :&: H|.
Proof.
Admitted.

Lemma dvdn_indexg G H : #|G : H| %| #|G|.
Proof.
Admitted.

Theorem Lagrange G H : H \subset G -> (#|H| * #|G : H|)%N = #|G|.
Proof.
Admitted.

Lemma cardSg G H : H \subset G -> #|H| %| #|G|.
Proof.
Admitted.

Lemma lognSg p G H : G \subset H -> logn p #|G| <= logn p #|H|.
Proof.
Admitted.

Lemma piSg G H : G \subset H -> {subset \pi(gval G) <= \pi(gval H)}.
Proof.
Admitted.

Lemma divgS G H : H \subset G -> #|G| %/ #|H| = #|G : H|.
Proof.
Admitted.

Lemma divg_indexS G H : H \subset G -> #|G| %/ #|G : H| = #|H|.
Proof.
Admitted.

Lemma coprimeSg G H p : H \subset G -> coprime #|G| p -> coprime #|H| p.
Proof.
Admitted.

Lemma coprimegS G H p : H \subset G -> coprime p #|G| -> coprime p #|H|.
Proof.
Admitted.

Lemma indexJg G H x : #|G :^ x : H :^ x| = #|G : H|.
Proof.
Admitted.

Lemma indexgg G : #|G : G| = 1%N.
Proof.
Admitted.

Lemma rcosets_id G : rcosets G G = [set G : {set gT}].
Proof.
Admitted.

Lemma Lagrange_index G H K :
  H \subset G -> K \subset H -> (#|G : H| * #|H : K|)%N = #|G : K|.
Proof.
Admitted.

Lemma indexgI G H : #|G : G :&: H| = #|G : H|.
Proof.
Admitted.

Lemma indexgS G H K : H \subset K -> #|G : K| %| #|G : H|.
Proof.
Admitted.

Lemma indexSg G H K : H \subset K -> K \subset G -> #|K : H| %| #|G : H|.
Proof.
Admitted.

Lemma indexg_eq1 G H : (#|G : H| == 1%N) = (G \subset H).
Proof.
Admitted.

Lemma indexg_gt1 G H : (#|G : H| > 1) = ~~ (G \subset H).
Proof.
Admitted.

Lemma index1g G H : H \subset G -> #|G : H| = 1%N -> H :=: G.
Proof.
Admitted.

Lemma indexg1 G : #|G : 1| = #|G|.
Proof.
Admitted.

Lemma indexMg G A : #|G * A : G| = #|A : G|.
Proof.
Admitted.

Lemma rcosets_partition_mul G H : partition (rcosets H G) (H * G).
Proof.
Admitted.

Lemma rcosets_partition G H : H \subset G -> partition (rcosets H G) G.
Proof.
Admitted.

Lemma LagrangeMl G H : (#|G| * #|H : G|)%N = #|G * H|.
Proof.
Admitted.

Lemma LagrangeMr G H : (#|G : H| * #|H|)%N = #|G * H|.
Proof.
Admitted.

Lemma mul_cardG G H : (#|G| * #|H| = #|G * H|%g * #|G :&: H|)%N.
Proof.
Admitted.

Lemma dvdn_cardMg G H : #|G * H| %| #|G| * #|H|.
Proof.
Admitted.

Lemma cardMg_divn G H : #|G * H| = (#|G| * #|H|) %/ #|G :&: H|.
Proof.
Admitted.

Lemma cardIg_divn G H : #|G :&: H| = (#|G| * #|H|) %/ #|G * H|.
Proof.
Admitted.

Lemma TI_cardMg G H : G :&: H = 1 -> #|G * H| = (#|G| * #|H|)%N.
Proof.
Admitted.

Lemma cardMg_TI G H : #|G| * #|H| <= #|G * H| -> G :&: H = 1.
Proof.
Admitted.

Lemma coprime_TIg G H : coprime #|G| #|H| -> G :&: H = 1.
Proof.
Admitted.

Lemma prime_TIg G H : prime #|G| -> ~~ (G \subset H) -> G :&: H = 1.
Proof.
Admitted.

Lemma prime_meetG G H : prime #|G| -> G :&: H != 1 -> G \subset H.
Proof.
Admitted.

Lemma coprime_cardMg G H : coprime #|G| #|H| -> #|G * H| = (#|G| * #|H|)%N.
Proof.
Admitted.

Lemma coprime_index_mulG G H K :
  H \subset G -> K \subset G -> coprime #|G : H| #|G : K| -> H * K = G.
Proof.
Admitted.

End Lagrange.

Section GeneratedGroup.

Variable gT : finGroupType.
Implicit Types x y z : gT.
Implicit Types A B C D : {set gT}.
Implicit Types G H K : {group gT}.

Lemma subset_gen A : A \subset <<A>>.
Proof.
Admitted.

Lemma sub_gen A B : A \subset B -> A \subset <<B>>.
Proof.
Admitted.

Lemma mem_gen x A : x \in A -> x \in <<A>>.
Proof.
Admitted.

Lemma generatedP x A : reflect (forall G, A \subset G -> x \in G) (x \in <<A>>).
Proof.
Admitted.

Lemma gen_subG A G : (<<A>> \subset G) = (A \subset G).
Proof.
Admitted.

Lemma genGid G : <<G>> = G.
Proof.
Admitted.

Lemma genGidG G : <<G>>%G = G.
Proof.
Admitted.

Lemma gen_set_id A : group_set A -> <<A>> = A.
Proof.
Admitted.

Lemma genS A B : A \subset B -> <<A>> \subset <<B>>.
Proof.
Admitted.

Lemma gen0 : <<set0>> = 1 :> {set gT}.
Proof.
Admitted.

Lemma gen_expgs A : {n | <<A>> = (1 |: A) ^+ n}.
Proof.
Admitted.

Lemma gen_prodgP A x :
  reflect (exists n, exists2 c, forall i : 'I_n, c i \in A & x = \prod_i c i)
          (x \in <<A>>).
Proof.
Admitted.

Lemma genD A B : A \subset <<A :\: B>> -> <<A :\: B>> = <<A>>.
Proof.
Admitted.

Lemma genV A : <<A^-1>> = <<A>>.
Proof.
Admitted.

Lemma genJ A z : <<A :^z>> = <<A>> :^ z.
Proof.
Admitted.

Lemma conjYg A B z : (A <*> B) :^z = A :^ z <*> B :^ z.
Proof.
Admitted.

Lemma genD1 A x : x \in <<A :\ x>> -> <<A :\ x>> = <<A>>.
Proof.
Admitted.

Lemma genD1id A : <<A^#>> = <<A>>.
Proof.
Admitted.

Notation joingT := (@joing gT) (only parsing).
Notation joinGT := (@joinG gT) (only parsing).

Lemma joingE A B : A <*> B = <<A :|: B>>.
Proof.
Admitted.

Lemma joinGE G H : (G * H)%G = (G <*> H)%G.
Proof.
Admitted.

Lemma joingC : commutative joingT.
Proof.
Admitted.

Lemma joing_idr A B : A <*> <<B>> = A <*> B.
Proof.
Admitted.

Lemma joing_idl A B : <<A>> <*> B = A <*> B.
Proof.
Admitted.

Lemma joing_subl A B : A \subset A <*> B.
Proof.
Admitted.

Lemma joing_subr A B : B \subset A <*> B.
Proof.
Admitted.

Lemma join_subG A B G : (A <*> B \subset G) = (A \subset G) && (B \subset G).
Proof.
Admitted.

Lemma joing_idPl G A : reflect (G <*> A = G) (A \subset G).
Proof.
Admitted.

Lemma joing_idPr A G : reflect (A <*> G = G) (A \subset G).
Proof.
Admitted.

Lemma joing_subP A B G :
  reflect (A \subset G /\ B \subset G) (A <*> B \subset G).
Proof.
Admitted.

Lemma joing_sub A B C : A <*> B = C -> A \subset C /\ B \subset C.
Proof.
Admitted.

Lemma genDU A B C : A \subset C -> <<C :\: A>> = <<B>> -> <<A :|: B>> = <<C>>.
Proof.
Admitted.

Lemma joingA : associative joingT.
Proof.
Admitted.

Lemma joing1G G : 1 <*> G = G.
Proof.
Admitted.

Lemma joingG1 G : G <*> 1 = G.
Proof.
Admitted.

Lemma genM_join G H : <<G * H>> = G <*> H.
Proof.
Admitted.

Lemma mulG_subG G H K : (G * H \subset K) = (G \subset K) && (H \subset K).
Proof.
Admitted.

Lemma mulGsubP K H G : reflect (K \subset G /\ H \subset G) (K * H \subset G).
Proof.
Admitted.

Lemma mulG_sub K H A : K * H = A -> K \subset A /\ H \subset A.
Proof.
Admitted.

Lemma trivMg G H : (G * H == 1) = (G :==: 1) && (H :==: 1).
Proof.
Admitted.

Lemma comm_joingE G H : commute G H -> G <*> H = G * H.
Proof.
Admitted.

Lemma joinGC : commutative joinGT.
Proof.
Admitted.

Lemma joinGA : associative joinGT.
Proof.
Admitted.

Lemma join1G : left_id 1%G joinGT.
Proof.
Admitted.

Lemma joinG1 : right_id 1%G joinGT.
Proof.
Admitted.

HB.instance Definition _ := Monoid.isComLaw.Build {group gT} 1%G joinGT
  joinGA joinGC join1G.

Lemma bigprodGEgen I r (P : pred I) (F : I -> {set gT}) :
  (\prod_(i <- r | P i) <<F i>>)%G :=: << \bigcup_(i <- r | P i) F i >>.
Proof.
Admitted.

Lemma bigprodGE I r (P : pred I) (F : I -> {group gT}) :
  (\prod_(i <- r | P i) F i)%G :=: << \bigcup_(i <- r | P i) F i >>.
Proof.
Admitted.

Lemma mem_commg A B x y : x \in A -> y \in B -> [~ x, y] \in [~: A, B].
Proof.
Admitted.

Lemma commSg A B C : A \subset B -> [~: A, C] \subset [~: B, C].
Proof.
Admitted.

Lemma commgS A B C : B \subset C -> [~: A, B] \subset [~: A, C].
Proof.
Admitted.

Lemma commgSS A B C D :
  A \subset B -> C \subset D -> [~: A, C] \subset [~: B, D].
Proof.
Admitted.

Lemma der1_subG G : [~: G, G] \subset G.
Proof.
Admitted.

Lemma comm_subG A B G : A \subset G -> B \subset G -> [~: A, B] \subset G.
Proof.
Admitted.

Lemma commGC A B : [~: A, B] = [~: B, A].
Proof.
Admitted.

Lemma conjsRg A B x : [~: A, B] :^ x = [~: A :^ x, B :^ x].
Proof.
Admitted.

End GeneratedGroup.

Arguments gen_prodgP {gT A x}.
Arguments joing_idPl {gT G A}.
Arguments joing_idPr {gT A G}.
Arguments mulGsubP {gT K H G}.
Arguments joing_subP {gT A B G}.

Section Cycles.

(* Elementary properties of cycles and order, needed in perm.v.  *)
(* More advanced results on the structure of cyclic groups will  *)
(* be given in cyclic.v.                                         *)

Variable gT : finGroupType.
Implicit Types x y : gT.
Implicit Types G : {group gT}.

Import Monoid.Theory.

Lemma cycle1 : <[1]> = [1 gT].
Proof.
Admitted.

Lemma order1 : #[1 : gT] = 1%N.
Proof.
Admitted.

Lemma cycle_id x : x \in <[x]>.
Proof.
Admitted.

Lemma mem_cycle x i : x ^+ i \in <[x]>.
Proof.
Admitted.

Lemma cycle_subG x G : (<[x]> \subset G) = (x \in G).
Proof.
Admitted.

Lemma cycle_eq1 x : (<[x]> == 1) = (x == 1).
Proof.
Admitted.

Lemma orderE x : #[x] = #|<[x]>|.
Proof.
Admitted.

Lemma order_eq1 x : (#[x] == 1%N) = (x == 1).
Proof.
Admitted.

Lemma order_gt1 x : (#[x] > 1) = (x != 1).
Proof.
Admitted.

Lemma cycle_traject x : <[x]> =i traject (mul x) 1 #[x].
Proof.
Admitted.

Lemma cycle2g x : #[x] = 2 -> <[x]> = [set 1; x].
Proof.
Admitted.

Lemma cyclePmin x y : y \in <[x]> -> {i | i < #[x] & y = x ^+ i}.
Proof.
Admitted.

Lemma cycleP x y : reflect (exists i, y = x ^+ i) (y \in <[x]>).
Proof.
Admitted.

Lemma expg_order x : x ^+ #[x] = 1.
Proof.
Admitted.

Lemma expg_mod p k x : x ^+ p = 1 -> x ^+ (k %% p) = x ^+ k.
Proof.
Admitted.

Lemma expg_mod_order x i : x ^+ (i %% #[x]) = x ^+ i.
Proof.
Admitted.

Lemma invg_expg x : x^-1 = x ^+ #[x].
Proof.
Admitted.

Lemma invg2id x : #[x] = 2 -> x^-1 = x.
Proof.
Admitted.

Lemma cycleX x i : <[x ^+ i]> \subset <[x]>.
Proof.
Admitted.

Lemma cycleV x : <[x^-1]> = <[x]>.
Proof.
Admitted.

Lemma orderV x : #[x^-1] = #[x].
Proof.
Admitted.

Lemma cycleJ x y : <[x ^ y]> = <[x]> :^ y.
Proof.
Admitted.

Lemma orderJ x y : #[x ^ y] = #[x].
Proof.
Admitted.

End Cycles.

Section Normaliser.

Variable gT : finGroupType.
Implicit Types x y z : gT.
Implicit Types A B C D : {set gT}.
Implicit Type G H K : {group gT}.

Lemma normP x A : reflect (A :^ x = A) (x \in 'N(A)).
Proof.
Admitted.
Arguments normP {x A}.

Lemma group_set_normaliser A : group_set 'N(A).
Proof.
Admitted.

Canonical normaliser_group A := group (group_set_normaliser A).

Lemma normsP A B : reflect {in A, normalised B} (A \subset 'N(B)).
Proof.
Admitted.
Arguments normsP {A B}.

Lemma memJ_norm x y A : x \in 'N(A) -> (y ^ x \in A) = (y \in A).
Proof.
Admitted.

Lemma norms_cycle x y : (<[y]> \subset 'N(<[x]>)) = (x ^ y \in <[x]>).
Proof.
Admitted.

Lemma norm1 : 'N(1) =  setT :> {set gT}.
Proof.
Admitted.

Lemma norms1 A : A \subset 'N(1).
Proof.
Admitted.

Lemma normCs A : 'N(~: A) = 'N(A).
Proof.
Admitted.

Lemma normG G : G \subset 'N(G).
Proof.
Admitted.

Lemma normT : 'N([set: gT]) = [set: gT].
Proof.
Admitted.

Lemma normsG A G : A \subset G -> A \subset 'N(G).
Proof.
Admitted.

Lemma normC A B : A \subset 'N(B) -> commute A B.
Proof.
Admitted.

Lemma norm_joinEl G H : G \subset 'N(H) -> G <*> H = G * H.
Proof.
Admitted.

Lemma norm_joinEr G H : H \subset 'N(G) -> G <*> H = G * H.
Proof.
Admitted.

Lemma norm_rlcoset G x : x \in 'N(G) -> G :* x = x *: G.
Proof.
Admitted.

Lemma rcoset_mul G x y : x \in 'N(G) -> (G :* x) * (G :* y) = G :* (x * y).
Proof.
Admitted.

Lemma normJ A x : 'N(A :^ x) = 'N(A) :^ x.
Proof.
Admitted.

Lemma norm_conj_norm x A B :
  x \in 'N(A) -> (A \subset 'N(B :^ x)) = (A \subset 'N(B)).
Proof.
Admitted.

Lemma norm_gen A : 'N(A) \subset 'N(<<A>>).
Proof.
Admitted.

Lemma class_norm x G : G \subset 'N(x ^: G).
Proof.
Admitted.

Lemma class_normal x G : x \in G -> x ^: G <| G.
Proof.
Admitted.

Lemma class_sub_norm G A x : G \subset 'N(A) -> (x ^: G \subset A) = (x \in A).
Proof.
Admitted.

Lemma class_support_norm A G : G \subset 'N(class_support A G).
Proof.
Admitted.

Lemma class_support_sub_norm A B G :
  A \subset G -> B \subset 'N(G) -> class_support A B \subset G.
Proof.
Admitted.

Section norm_trans.

Variables (A B C D : {set gT}).
Hypotheses (nBA : A \subset 'N(B)) (nCA : A \subset 'N(C)).

Lemma norms_gen : A \subset 'N(<<B>>).
Proof.
Admitted.

Lemma norms_norm : A \subset 'N('N(B)).
Proof.
Admitted.

Lemma normsI : A \subset 'N(B :&: C).
Proof.
Admitted.

Lemma normsU : A \subset 'N(B :|: C).
Proof.
Admitted.

Lemma normsIs : B \subset 'N(D) -> A :&: B \subset 'N(C :&: D).
Proof.
Admitted.

Lemma normsD : A \subset 'N(B :\: C).
Proof.
Admitted.

Lemma normsM : A \subset 'N(B * C).
Proof.
Admitted.

Lemma normsY : A \subset 'N(B <*> C).
Proof.
Admitted.

Lemma normsR : A \subset 'N([~: B, C]).
Proof.
Admitted.

Lemma norms_class_support : A \subset 'N(class_support B C).
Proof.
Admitted.

End norm_trans.

Lemma normsIG A B G : A \subset 'N(B) -> A :&: G \subset 'N(B :&: G).
Proof.
Admitted.

Lemma normsGI A B G : A \subset 'N(B) -> G :&: A \subset 'N(G :&: B).
Proof.
Admitted.

Lemma norms_bigcap I r (P : pred I) A (B_ : I -> {set gT}) :
    A \subset \bigcap_(i <- r | P i) 'N(B_ i) ->
  A \subset 'N(\bigcap_(i <- r | P i) B_ i).
Proof.
Admitted.

Lemma norms_bigcup I r (P : pred I) A (B_ : I -> {set gT}) :
    A \subset \bigcap_(i <- r | P i) 'N(B_ i) ->
  A \subset 'N(\bigcup_(i <- r | P i) B_ i).
Proof.
Admitted.

Lemma normsD1 A B : A \subset 'N(B) -> A \subset 'N(B^#).
Proof.
Admitted.

Lemma normD1 A : 'N(A^#) = 'N(A).
Proof.
Admitted.

Lemma normalP A B : reflect (A \subset B /\ {in B, normalised A}) (A <| B).
Proof.
Admitted.

Lemma normal_sub A B : A <| B -> A \subset B.
Proof.
Admitted.

Lemma normal_norm A B : A <| B -> B \subset 'N(A).
Proof.
Admitted.

Lemma normalS G H K : K \subset H -> H \subset G -> K <| G -> K <| H.
Proof.
Admitted.

Lemma normal1 G : 1 <| G.
Proof.
Admitted.

Lemma normal_refl G : G <| G.
Proof.
Admitted.

Lemma normalG G : G <| 'N(G).
Proof.
Admitted.

Lemma normalSG G H : H \subset G -> H <| 'N_G(H).
Proof.
Admitted.

Lemma normalJ A B x : (A :^ x <| B :^ x) = (A <| B).
Proof.
Admitted.

Lemma normalM G A B : A <| G -> B <| G -> A * B <| G.
Proof.
Admitted.

Lemma normalY G A B : A <| G -> B <| G -> A <*> B <| G.
Proof.
Admitted.

Lemma normalYl G H : (H <| H <*> G) = (G \subset 'N(H)).
Proof.
Admitted.

Lemma normalYr G H : (H <| G <*> H) = (G \subset 'N(H)).
Proof.
Admitted.

Lemma normalI G A B : A <| G -> B <| G -> A :&: B <| G.
Proof.
Admitted.

Lemma norm_normalI G A : G \subset 'N(A) -> G :&: A <| G.
Proof.
Admitted.

Lemma normalGI G H A : H \subset G -> A <| G -> H :&: A <| H.
Proof.
Admitted.

Lemma normal_subnorm G H : (H <| 'N_G(H)) = (H \subset G).
Proof.
Admitted.

Lemma normalD1 A G : (A^# <| G) = (A <| G).
Proof.
Admitted.

Lemma gcore_sub A G : gcore A G \subset A.
Proof.
Admitted.

Lemma gcore_norm A G : G \subset 'N(gcore A G).
Proof.
Admitted.

Lemma gcore_normal A G : A \subset G -> gcore A G <| G.
Proof.
Admitted.

Lemma gcore_max A B G : B \subset A -> G \subset 'N(B) -> B \subset gcore A G.
Proof.
Admitted.

Lemma sub_gcore A B G :
  G \subset 'N(B) -> (B \subset gcore A G) = (B \subset A).
Proof.
Admitted.

(* An elementary proof that subgroups of index 2 are normal; it is almost as  *)
(* short as the "advanced" proof using group actions; besides, the fact that  *)
(* the coset is equal to the complement is used in extremal.v.                *)
Lemma rcoset_index2 G H x :
  H \subset G -> #|G : H| = 2 -> x \in G :\: H -> H :* x = G :\: H.
Proof.
Admitted.

Lemma index2_normal G H : H \subset G -> #|G : H| = 2 -> H <| G.
Proof.
Admitted.

Lemma cent1P x y : reflect (commute x y) (x \in 'C[y]).
Proof.
Admitted.

Lemma cent1id x : x \in 'C[x].
Proof.
Admitted.

Lemma cent1E x y : (x \in 'C[y]) = (x * y == y * x).
Proof.
Admitted.

Lemma cent1C x y : (x \in 'C[y]) = (y \in 'C[x]).
Proof.
Admitted.

Canonical centraliser_group A : {group _} := Eval hnf in [group of 'C(A)].

Lemma cent_set1 x : 'C([set x]) = 'C[x].
Proof.
Admitted.

Lemma cent1J x y : 'C[x ^ y] = 'C[x] :^ y.
Proof.
Admitted.

Lemma centP A x : reflect (centralises x A) (x \in 'C(A)).
Proof.
Admitted.

Lemma centsP A B : reflect {in A, centralised B} (A \subset 'C(B)).
Proof.
Admitted.

Lemma centsC A B : (A \subset 'C(B)) = (B \subset 'C(A)).
Proof.
Admitted.

Lemma cents1 A : A \subset 'C(1).
Proof.
Admitted.

Lemma cent1T : 'C(1) = setT :> {set gT}.
Proof.
Admitted.

Lemma cent11T : 'C[1] = setT :> {set gT}.
Proof.
Admitted.

Lemma cent_sub A : 'C(A) \subset 'N(A).
Proof.
Admitted.

Lemma cents_norm A B : A \subset 'C(B) -> A \subset 'N(B).
Proof.
Admitted.

Lemma centC A B : A \subset 'C(B) -> commute A B.
Proof.
Admitted.

Lemma cent_joinEl G H : G \subset 'C(H) -> G <*> H = G * H.
Proof.
Admitted.

Lemma cent_joinEr G H : H \subset 'C(G) -> G <*> H = G * H.
Proof.
Admitted.

Lemma centJ A x : 'C(A :^ x) = 'C(A) :^ x.
Proof.
Admitted.

Lemma cent_norm A : 'N(A) \subset 'N('C(A)).
Proof.
Admitted.

Lemma norms_cent A B : A \subset 'N(B) -> A \subset 'N('C(B)).
Proof.
Admitted.

Lemma cent_normal A : 'C(A) <| 'N(A).
Proof.
Admitted.

Lemma centS A B : B \subset A -> 'C(A) \subset 'C(B).
Proof.
Admitted.

Lemma centsS A B C : A \subset B -> C \subset 'C(B) -> C \subset 'C(A).
Proof.
Admitted.

Lemma centSS A B C D :
  A \subset C -> B \subset D -> C \subset 'C(D) -> A \subset 'C(B).
Proof.
Admitted.

Lemma centI A B : 'C(A) <*> 'C(B) \subset 'C(A :&: B).
Proof.
Admitted.

Lemma centU A B : 'C(A :|: B) = 'C(A) :&: 'C(B).
Proof.
Admitted.

Lemma cent_gen A : 'C(<<A>>) = 'C(A).
Proof.
Admitted.

Lemma cent_cycle x : 'C(<[x]>) = 'C[x].
Proof.
Admitted.

Lemma sub_cent1 A x : (A \subset 'C[x]) = (x \in 'C(A)).
Proof.
Admitted.

Lemma cents_cycle x y : commute x y -> <[x]> \subset 'C(<[y]>).
Proof.
Admitted.

Lemma cycle_abelian x : abelian <[x]>.
Proof.
Admitted.

Lemma centY A B : 'C(A <*> B) = 'C(A) :&: 'C(B).
Proof.
Admitted.

Lemma centM G H : 'C(G * H) = 'C(G) :&: 'C(H).
Proof.
Admitted.

Lemma cent_classP x G : reflect (x ^: G = [set x]) (x \in 'C(G)).
Proof.
Admitted.

Lemma commG1P A B : reflect ([~: A, B] = 1) (A \subset 'C(B)).
Proof.
Admitted.

Lemma abelianE A : abelian A = (A \subset 'C(A)).
Proof.
Admitted.

Lemma abelian1 : abelian [1 gT].
Proof.
Admitted.

Lemma abelianS A B : A \subset B -> abelian B -> abelian A.
Proof.
Admitted.

Lemma abelianJ A x : abelian (A :^ x) = abelian A.
Proof.
Admitted.

Lemma abelian_gen A : abelian <<A>> = abelian A.
Proof.
Admitted.

Lemma abelianY A B :
  abelian (A <*> B) = [&& abelian A, abelian B & B \subset 'C(A)].
Proof.
Admitted.

Lemma abelianM G H :
  abelian (G * H) = [&& abelian G, abelian H & H \subset 'C(G)].
Proof.
Admitted.

Section SubAbelian.

Variable A B C : {set gT}.
Hypothesis cAA : abelian A.

Lemma sub_abelian_cent : C \subset A -> A \subset 'C(C).
Proof.
Admitted.

Lemma sub_abelian_cent2 : B \subset A -> C \subset A -> B \subset 'C(C).
Proof.
Admitted.

Lemma sub_abelian_norm : C \subset A -> A \subset 'N(C).
Proof.
Admitted.

Lemma sub_abelian_normal : (C \subset A) = (C <| A).
Proof.
Admitted.

End SubAbelian.

End Normaliser.

Arguments normP {gT x A}.
Arguments centP {gT A x}.
Arguments normsP {gT A B}.
Arguments cent1P {gT x y}.
Arguments normalP {gT A B}.
Arguments centsP {gT A B}.
Arguments commG1P {gT A B}.

Arguments normaliser_group _ _%_g.
Arguments centraliser_group _ _%_g.

Notation "''N' ( A )" := (normaliser_group A) : Group_scope.
Notation "''C' ( A )" := (centraliser_group A) : Group_scope.
Notation "''C' [ x ]" := (normaliser_group [set x%g]) : Group_scope.
Notation "''N_' G ( A )" := (setI_group G 'N(A)) : Group_scope.
Notation "''C_' G ( A )" := (setI_group G 'C(A)) : Group_scope.
Notation "''C_' ( G ) ( A )" := (setI_group G 'C(A))
  (only parsing) : Group_scope.
Notation "''C_' G [ x ]" := (setI_group G 'C[x]) : Group_scope.
Notation "''C_' ( G ) [ x ]" := (setI_group G 'C[x])
  (only parsing) : Group_scope.

#[global] Hint Extern 0 (is_true (_ \subset _)) => apply: normG : core.
#[global] Hint Extern 0 (is_true (_ <| _)) => apply: normal_refl : core.

Section MinMaxGroup.

Variable gT : finGroupType.
Implicit Types gP : pred {group gT}.

Definition maxgroup A gP := maxset (fun A => group_set A && gP <<A>>%G) A.
Definition mingroup A gP := minset (fun A => group_set A && gP <<A>>%G) A.

Variable gP : pred {group gT}.
Arguments gP _%_G.

Lemma ex_maxgroup : (exists G, gP G) -> {G : {group gT} | maxgroup G gP}.
Proof.
Admitted.

Lemma ex_mingroup : (exists G, gP G) -> {G : {group gT} | mingroup G gP}.
Proof.
Admitted.

Variable G : {group gT}.

Lemma mingroupP :
  reflect (gP G /\ forall H, gP H -> H \subset G -> H :=: G) (mingroup G gP).
Proof.
Admitted.

Lemma maxgroupP :
  reflect (gP G /\ forall H, gP H -> G \subset H -> H :=: G) (maxgroup G gP).
Proof.
Admitted.

Lemma maxgroupp : maxgroup G gP -> gP G.
Proof.
Admitted.

Lemma mingroupp : mingroup G gP -> gP G.
Proof.
Admitted.

Hypothesis gPG : gP G.

Lemma maxgroup_exists : {H : {group gT} | maxgroup H gP & G \subset H}.
Proof.
Admitted.

Lemma mingroup_exists : {H : {group gT} | mingroup H gP & H \subset G}.
Proof.
Admitted.

End MinMaxGroup.

Arguments mingroup {gT} A%_g gP.
Arguments maxgroup {gT} A%_g gP.
Arguments mingroupP {gT gP G}.
Arguments maxgroupP {gT gP G}.

Notation "[ 'max' A 'of' G | gP ]" :=
  (maxgroup A (fun G : {group _} => gP)) : group_scope.
Notation "[ 'max' G | gP ]" := [max gval G of G | gP] : group_scope.
Notation "[ 'max' A 'of' G | gP & gQ ]" :=
  [max A of G | gP && gQ] : group_scope.
Notation "[ 'max' G | gP & gQ ]" := [max G | gP && gQ] : group_scope.
Notation "[ 'min' A 'of' G | gP ]" :=
  (mingroup A (fun G : {group _} => gP)) : group_scope.
Notation "[ 'min' G | gP ]" := [min gval G of G | gP] : group_scope.
Notation "[ 'min' A 'of' G | gP & gQ ]" :=
  [min A of G | gP && gQ] : group_scope.
Notation "[ 'min' G | gP & gQ ]" := [min G | gP && gQ] : group_scope.

HB.reexport.