filename
stringlengths 5
30
| content
stringlengths 22
296k
|
|---|---|
HasConicalLimits.lean
|
/-
Copyright (c) 2025 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster, Dagur Asgeirsson, Emily Riehl
-/
import Mathlib.CategoryTheory.Enriched.Ordinary.Basic
import Mathlib.CategoryTheory.Limits.Final
/-!
# Existence of conical limits
This file contains different statements about the (non-constructive) existence of conical limits.
The main constructions are the following.
- `HasConicalLimit`: there exists a conical limit for `F : J ⥤ C`.
- `HasConicalLimitsOfShape J`: All functors `F : J ⥤ C` have conical limits.
- `HasConicalLimitsOfSize.{v₁, u₁}`: For all small `J` all functors `F : J ⥤ C` have conical limits.
- `HasConicalLimits `: `C` has all (small) conical limits.
## References
* [Kelly G.M., *Basic concepts of enriched category theory*][kelly2005]:
See section 3.8 for a similar treatment, although the content of this file is not directly
adapted from there.
## Implementation notes
`V` has been made an `(V : outParam <| Type u')` in the classes below as it seems instance
inference prefers this. Otherwise it failed with
`cannot find synthesization order` on the instances below.
However, it is not fully clear yet whether this could lead to potential issues, for example
if there are multiple `MonoidalCategory _` instances in scope.
-/
universe v₁ u₁ v₂ u₂ w v' v u u'
namespace CategoryTheory.Enriched
open Limits
section Definitions
variable {J : Type u₁} [Category.{v₁} J]
variable (V : outParam <| Type u') [Category.{v'} V] [MonoidalCategory V]
variable (C : Type u) [Category.{v} C] [EnrichedOrdinaryCategory V C]
variable {C} in
/--
`HasConicalLimit F` represents the mere existence of a conical limit for `F`.
-/
class HasConicalLimit (F : J ⥤ C) : Prop extends HasLimit F where
preservesLimit_eCoyoneda (X : C) : PreservesLimit F (eCoyoneda V X) := by infer_instance
attribute [instance] HasConicalLimit.preservesLimit_eCoyoneda
variable (J) in
/--
`C` has conical limits of shape `J` if there exists a conical limit for every functor `F : J ⥤ C`.
-/
class HasConicalLimitsOfShape : Prop where
/-- All functors `F : J ⥤ C` from `J` have limits. -/
hasConicalLimit : ∀ F : J ⥤ C, HasConicalLimit V F := by infer_instance
attribute [instance] HasConicalLimitsOfShape.hasConicalLimit
/--
`C` has all conical limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`)
if it has conical limits of every shape `J : Type u₁` with `[Category.{v₁} J]`.
-/
@[pp_with_univ]
class HasConicalLimitsOfSize : Prop where
/-- All functors `F : J ⥤ C` from all small `J` have conical limits -/
hasConicalLimitsOfShape : ∀ (J : Type u₁) [Category.{v₁} J], HasConicalLimitsOfShape J V C := by
infer_instance
attribute [instance] HasConicalLimitsOfSize.hasConicalLimitsOfShape
/-- `C` has all (small) conical limits if it has limits of every shape that is as big as its
hom-sets. -/
abbrev HasConicalLimits : Prop := HasConicalLimitsOfSize.{v, v} V C
end Definitions
section Results
variable {J : Type u₁} [Category.{v₁} J] {J' : Type u₂} [Category.{v₂} J']
variable (V : Type u') [Category.{v'} V] [MonoidalCategory V]
variable {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory V C]
/-- ensure existence of a conical limit implies existence of a limit -/
example (F : J ⥤ C) [HasConicalLimit V F] : HasLimit F := inferInstance
/-- If a functor `F` has a conical limit, so does any naturally isomorphic functor. -/
lemma HasConicalLimit.of_iso {F G : J ⥤ C} [HasConicalLimit V F] (e : F ≅ G) :
HasConicalLimit V G where
toHasLimit := hasLimit_of_iso e
preservesLimit_eCoyoneda X := preservesLimit_of_iso_diagram (eCoyoneda V X) e
instance HasConicalLimit.of_equiv (F : J ⥤ C) [HasConicalLimit V F]
(G : J' ⥤ J) [G.IsEquivalence] : HasConicalLimit V (G ⋙ F) where
/-- If a `G ⋙ F` has a limit, and `G` is an equivalence, we can construct a limit of `F`. -/
lemma HasConicalLimit.of_equiv_comp (F : J ⥤ C) (G : J' ⥤ J) [G.IsEquivalence]
[HasConicalLimit V (G ⋙ F)] : HasConicalLimit V F :=
have e : G.inv ⋙ G ⋙ F ≅ F := G.asEquivalence.invFunIdAssoc F
HasConicalLimit.of_iso V e
variable (C)
variable (J) in
/-- existence of conical limits (of shape) implies existence of limits (of shape) -/
instance HasConicalLimitsOfShape.hasLimitsOfShape [HasConicalLimitsOfShape J V C] :
HasLimitsOfShape J C where
/-- We can transport conical limits of shape `J'` along an equivalence `J' ≌ J`. -/
lemma HasConicalLimitsOfShape.of_equiv [HasConicalLimitsOfShape J' V C]
(G : J' ⥤ J) [G.IsEquivalence] : HasConicalLimitsOfShape J V C where
hasConicalLimit F := HasConicalLimit.of_equiv_comp V F G
/-- existence of conical limits (of size) implies existence of limits (of size) -/
instance HasConicalLimitsOfSize.hasLimitsOfSize [HasConicalLimitsOfSize.{v₁, u₁} V C] :
HasLimitsOfSize.{v₁, u₁} C where
/-- ensure existence of (small) conical limits implies existence of (small) limits -/
example [HasConicalLimits V C] : HasLimits C := inferInstance
end Results
end CategoryTheory.Enriched
|
CubingACube.lean
|
/-
Copyright (c) 2019 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.Interval.Set.Group
import Mathlib.Data.Real.Basic
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.Order.Interval.Set.Disjoint
/-!
Proof that a cube (in dimension n ≥ 3) cannot be cubed:
There does not exist a partition of a cube into finitely many smaller cubes (at least two)
of different sizes.
We follow the proof described here:
http://www.alaricstephen.com/main-featured/2017/9/28/cubing-a-cube-proof
-/
open Real Set Function Fin
namespace Theorems100
noncomputable section
namespace «82»
variable {n : ℕ}
/-- Given three intervals `I, J, K` such that `J ⊂ I`,
neither endpoint of `J` coincides with an endpoint of `I`, `¬ (K ⊆ J)` and
`K` does not lie completely to the left nor completely to the right of `J`.
Then `I ∩ K \ J` is nonempty. -/
theorem Ico_lemma {α} [LinearOrder α] {x₁ x₂ y₁ y₂ z₁ z₂ w : α} (h₁ : x₁ < y₁) (hy : y₁ < y₂)
(h₂ : y₂ < x₂) (hz₁ : z₁ ≤ y₂) (hz₂ : y₁ ≤ z₂) (hw : w ∉ Ico y₁ y₂ ∧ w ∈ Ico z₁ z₂) :
∃ w, w ∈ Ico x₁ x₂ ∧ w ∉ Ico y₁ y₂ ∧ w ∈ Ico z₁ z₂ := by
simp only [not_and, not_lt, mem_Ico] at hw
refine ⟨max x₁ (min w y₂), ?_, ?_, ?_⟩
· simp [lt_trans h₁ (lt_trans hy h₂), h₂]
· simp +contextual [hw, not_le_of_gt h₁]
· simp [hw.2.1, hw.2.2, hz₁, lt_of_lt_of_le h₁ hz₂]
/-- A (hyper)-cube (in standard orientation) is a vector `b` consisting of the bottom-left point
of the cube, a width `w` and a proof that `w > 0`. We use functions from `Fin n` to denote vectors.
-/
structure Cube (n : ℕ) : Type where
b : Fin n → ℝ -- bottom-left coordinate
w : ℝ -- width
hw : 0 < w
namespace Cube
theorem hw' (c : Cube n) : 0 ≤ c.w :=
le_of_lt c.hw
/-- The j-th side of a cube is the half-open interval `[b j, b j + w)` -/
def side (c : Cube n) (j : Fin n) : Set ℝ :=
Ico (c.b j) (c.b j + c.w)
@[simp]
theorem b_mem_side (c : Cube n) (j : Fin n) : c.b j ∈ c.side j := by simp [side, Cube.hw, le_refl]
def toSet (c : Cube n) : Set (Fin n → ℝ) :=
{x | ∀ j, x j ∈ side c j}
theorem side_nonempty (c : Cube n) (i : Fin n) : (side c i).Nonempty := by simp [side, c.hw]
theorem univ_pi_side (c : Cube n) : pi univ (side c) = c.toSet :=
ext fun _ => mem_univ_pi
theorem toSet_subset {c c' : Cube n} : c.toSet ⊆ c'.toSet ↔ ∀ j, c.side j ⊆ c'.side j := by
simp only [← univ_pi_side, univ_pi_subset_univ_pi_iff, (c.side_nonempty _).ne_empty, exists_false,
or_false]
theorem toSet_disjoint {c c' : Cube n} :
Disjoint c.toSet c'.toSet ↔ ∃ j, Disjoint (c.side j) (c'.side j) := by
simp only [← univ_pi_side, disjoint_univ_pi]
theorem b_mem_toSet (c : Cube n) : c.b ∈ c.toSet := by simp [toSet]
protected def tail (c : Cube (n + 1)) : Cube n :=
⟨tail c.b, c.w, c.hw⟩
theorem side_tail (c : Cube (n + 1)) (j : Fin n) : c.tail.side j = c.side j.succ :=
rfl
def bottom (c : Cube (n + 1)) : Set (Fin (n + 1) → ℝ) :=
{x | x 0 = c.b 0 ∧ tail x ∈ c.tail.toSet}
theorem b_mem_bottom (c : Cube (n + 1)) : c.b ∈ c.bottom := by
simp [bottom, toSet, side, Cube.hw, le_refl, Cube.tail]
def xm (c : Cube (n + 1)) : ℝ :=
c.b 0 + c.w
theorem b_lt_xm (c : Cube (n + 1)) : c.b 0 < c.xm := by simp [xm, hw]
theorem b_ne_xm (c : Cube (n + 1)) : c.b 0 ≠ c.xm :=
ne_of_lt c.b_lt_xm
def shiftUp (c : Cube (n + 1)) : Cube (n + 1) :=
⟨cons c.xm <| tail c.b, c.w, c.hw⟩
@[simp]
theorem tail_shiftUp (c : Cube (n + 1)) : c.shiftUp.tail = c.tail := by simp [shiftUp, Cube.tail]
@[simp]
theorem head_shiftUp (c : Cube (n + 1)) : c.shiftUp.b 0 = c.xm :=
rfl
def unitCube : Cube n :=
⟨fun _ => 0, 1, by simp⟩
@[simp]
theorem side_unitCube {j : Fin n} : unitCube.side j = Ico 0 1 := by
norm_num [unitCube, side]
end Cube
open Cube
variable {ι : Type} {cs : ι → Cube (n + 1)} {i i' : ι}
/-- A finite family of (at least 2) cubes partitioning the unit cube with different sizes -/
structure Correct (cs : ι → Cube n) : Prop where
PairwiseDisjoint : Pairwise (Disjoint on Cube.toSet ∘ cs)
iUnion_eq : ⋃ i : ι, (cs i).toSet = unitCube.toSet
Injective : Injective (Cube.w ∘ cs)
three_le : 3 ≤ n
namespace Correct
variable (h : Correct cs)
include h
theorem toSet_subset_unitCube {i} : (cs i).toSet ⊆ unitCube.toSet := by
convert h.iUnion_eq ▸ subset_iUnion _ i
theorem side_subset {i j} : (cs i).side j ⊆ Ico 0 1 := by
simpa only [side_unitCube] using toSet_subset.1 h.toSet_subset_unitCube j
theorem zero_le_of_mem_side {i j x} (hx : x ∈ (cs i).side j) : 0 ≤ x :=
(side_subset h hx).1
theorem zero_le_of_mem {i p} (hp : p ∈ (cs i).toSet) (j) : 0 ≤ p j :=
zero_le_of_mem_side h (hp j)
theorem zero_le_b {i j} : 0 ≤ (cs i).b j :=
zero_le_of_mem h (cs i).b_mem_toSet j
theorem b_add_w_le_one {j} : (cs i).b j + (cs i).w ≤ 1 := by
have : side (cs i) j ⊆ Ico 0 1 := side_subset h
rw [side, Ico_subset_Ico_iff] at this
· convert this.2
· simp [hw]
theorem nontrivial_fin : Nontrivial (Fin n) :=
Fin.nontrivial_iff_two_le.2 (Nat.le_of_succ_le_succ h.three_le)
/-- The width of any cube in the partition cannot be 1. -/
theorem w_ne_one [Nontrivial ι] (i : ι) : (cs i).w ≠ 1 := by
intro hi
obtain ⟨i', hi'⟩ := exists_ne i
let p := (cs i').b
have hp : p ∈ (cs i').toSet := (cs i').b_mem_toSet
have h2p : p ∈ (cs i).toSet := by
intro j; constructor
trans (0 : ℝ)
· rw [← add_le_add_iff_right (1 : ℝ)]; convert b_add_w_le_one h
· rw [hi]
· rw [zero_add]
· apply zero_le_b h
· apply lt_of_lt_of_le (side_subset h <| (cs i').b_mem_side j).2
simp [hi, zero_le_b h]
exact (h.PairwiseDisjoint hi').le_bot ⟨hp, h2p⟩
/-- The top of a cube (which is the bottom of the cube shifted up by its width) must be covered by
bottoms of (other) cubes in the family. -/
theorem shiftUp_bottom_subset_bottoms (hc : (cs i).xm ≠ 1) :
(cs i).shiftUp.bottom ⊆ ⋃ i : ι, (cs i).bottom := by
intro p hp; obtain ⟨hp0, hps⟩ := hp; rw [tail_shiftUp] at hps
have : p ∈ (unitCube : Cube (n + 1)).toSet := by
simp only [toSet, forall_iff_succ, hp0, side_unitCube, mem_setOf_eq, mem_Ico, head_shiftUp]
refine ⟨⟨?_, ?_⟩, ?_⟩
· rw [← zero_add (0 : ℝ)]; apply add_le_add
· apply zero_le_b h
· apply (cs i).hw'
· exact lt_of_le_of_ne (b_add_w_le_one h) hc
intro j; exact side_subset h (hps j)
rw [← h.2, mem_iUnion] at this; rcases this with ⟨i', hi'⟩
rw [mem_iUnion]; use i'; refine ⟨?_, fun j => hi' j.succ⟩
have : i ≠ i' := by rintro rfl; apply not_le_of_gt (hi' 0).2; rw [hp0]; rfl
have := h.1 this
rw [onFun, comp_apply, comp_apply, toSet_disjoint, exists_fin_succ] at this
rcases this with (h0 | ⟨j, hj⟩)
· rw [hp0]; symm; apply eq_of_Ico_disjoint h0 (by simp [hw]) _
convert hi' 0; rw [hp0]; rfl
· exfalso; apply not_disjoint_iff.mpr ⟨tail p j, hps j, hi' j.succ⟩ hj
end Correct
/-- A valley is a square on which cubes in the family of cubes are placed, so that the cubes
completely cover the valley and none of those cubes is partially outside the square.
We also require that no cube on it has the same size as the valley (so that there are at least
two cubes on the valley).
This is the main concept in the formalization.
We prove that the smallest cube on a valley has another valley on the top of it, which
gives an infinite sequence of cubes in the partition, which contradicts the finiteness.
A valley is characterized by a cube `c` (which is not a cube in the family `cs`) by considering
the bottom face of `c`. -/
def Valley (cs : ι → Cube (n + 1)) (c : Cube (n + 1)) : Prop :=
(c.bottom ⊆ ⋃ i : ι, (cs i).bottom) ∧
(∀ i, (cs i).b 0 = c.b 0 →
(∃ x, x ∈ (cs i).tail.toSet ∩ c.tail.toSet) → (cs i).tail.toSet ⊆ c.tail.toSet) ∧
∀ i : ι, (cs i).b 0 = c.b 0 → (cs i).w ≠ c.w
variable {c : Cube (n + 1)} (h : Correct cs) (v : Valley cs c)
/-- The bottom of the unit cube is a valley -/
theorem valley_unitCube [Nontrivial ι] (h : Correct cs) : Valley cs unitCube := by
refine ⟨?_, ?_, ?_⟩
· intro v
simp only [bottom, and_imp, mem_iUnion, mem_setOf_eq]
intro h0 hv
have : v ∈ (unitCube : Cube (n + 1)).toSet := by
dsimp only [toSet, unitCube, mem_setOf_eq]
rw [forall_iff_succ, h0]; constructor
· norm_num [side, unitCube]
· exact hv
rw [← h.2, mem_iUnion] at this; rcases this with ⟨i, hi⟩
use i
constructor
· apply le_antisymm
· rw [h0]; exact h.zero_le_b
· exact (hi 0).1
intro j; exact hi _
· intro i _ _; rw [toSet_subset]; intro j; convert h.side_subset using 1; simp [side_tail]
· intro i _; exact h.w_ne_one i
/-- the cubes which lie in the valley `c` -/
def bcubes (cs : ι → Cube (n + 1)) (c : Cube (n + 1)) : Set ι :=
{i : ι | (cs i).b 0 = c.b 0 ∧ (cs i).tail.toSet ⊆ c.tail.toSet}
/-- A cube which lies on the boundary of a valley in dimension `j` -/
def OnBoundary (_ : i ∈ bcubes cs c) (j : Fin n) : Prop :=
c.b j.succ = (cs i).b j.succ ∨ (cs i).b j.succ + (cs i).w = c.b j.succ + c.w
theorem tail_sub (hi : i ∈ bcubes cs c) : ∀ j, (cs i).tail.side j ⊆ c.tail.side j := by
rw [← toSet_subset]; exact hi.2
theorem bottom_mem_side (hi : i ∈ bcubes cs c) : c.b 0 ∈ (cs i).side 0 := by
convert b_mem_side (cs i) _ using 1; rw [hi.1]
theorem b_le_b (hi : i ∈ bcubes cs c) (j : Fin n) : c.b j.succ ≤ (cs i).b j.succ :=
(tail_sub hi j <| b_mem_side _ _).1
theorem t_le_t (hi : i ∈ bcubes cs c) (j : Fin n) :
(cs i).b j.succ + (cs i).w ≤ c.b j.succ + c.w := by
have h' := tail_sub hi j; dsimp only [side] at h'; rw [Ico_subset_Ico_iff] at h'
· exact h'.2
· simp [hw]
section
include h v
/-- Every cube in the valley must be smaller than it -/
theorem w_lt_w (hi : i ∈ bcubes cs c) : (cs i).w < c.w := by
apply lt_of_le_of_ne _ (v.2.2 i hi.1)
have j : Fin n := ⟨1, Nat.le_of_succ_le_succ h.three_le⟩
rw [← add_le_add_iff_left ((cs i).b j.succ)]
apply le_trans (t_le_t hi j); gcongr; apply b_le_b hi
/-- There are at least two cubes in a valley -/
theorem nontrivial_bcubes : (bcubes cs c).Nontrivial := by
rcases v.1 c.b_mem_bottom with ⟨_, ⟨i, rfl⟩, hi⟩
have h2i : i ∈ bcubes cs c :=
⟨hi.1.symm, v.2.1 i hi.1.symm ⟨tail c.b, hi.2, fun j => c.b_mem_side j.succ⟩⟩
let j : Fin (n + 1) := ⟨2, h.three_le⟩
have hj : 0 ≠ j := by simp only [j, Fin.ext_iff, Ne]; norm_num
let p : Fin (n + 1) → ℝ := fun j' => if j' = j then c.b j + (cs i).w else c.b j'
have hp : p ∈ c.bottom := by
constructor
· simp only [p, if_neg hj]
intro j'; simp only [tail, side_tail]
by_cases hj' : j'.succ = j
· simp [p, if_pos, side, hj', hw', w_lt_w h v h2i]
· simp [p, if_neg hj']
rcases v.1 hp with ⟨_, ⟨i', rfl⟩, hi'⟩
have h2i' : i' ∈ bcubes cs c := ⟨hi'.1.symm, v.2.1 i' hi'.1.symm ⟨tail p, hi'.2, hp.2⟩⟩
refine ⟨i, h2i, i', h2i', ?_⟩
rintro rfl
apply not_le_of_gt (hi'.2 ⟨1, Nat.le_of_succ_le_succ h.three_le⟩).2
simp only [tail, Cube.tail, p]
rw [if_pos]
· gcongr
exact (hi.2 _).1
rfl
/-- There is a cube in the valley -/
theorem nonempty_bcubes : (bcubes cs c).Nonempty :=
(nontrivial_bcubes h v).nonempty
variable [Finite ι]
/-- There is a smallest cube in the valley -/
theorem exists_mi : ∃ i ∈ bcubes cs c, ∀ i' ∈ bcubes cs c, (cs i).w ≤ (cs i').w :=
(bcubes cs c).exists_min_image (fun i => (cs i).w) (Set.toFinite _) (nonempty_bcubes h v)
/-- We let `mi` be the (index for the) smallest cube in the valley `c` -/
def mi : ι :=
Classical.choose <| exists_mi h v
variable {h v}
theorem mi_mem_bcubes : mi h v ∈ bcubes cs c :=
(Classical.choose_spec <| exists_mi h v).1
theorem mi_minimal (hi : i ∈ bcubes cs c) : (cs <| mi h v).w ≤ (cs i).w :=
(Classical.choose_spec <| exists_mi h v).2 i hi
theorem mi_strict_minimal (hii' : mi h v ≠ i) (hi : i ∈ bcubes cs c) :
(cs <| mi h v).w < (cs i).w :=
(mi_minimal hi).lt_of_ne <| h.Injective.ne hii'
/-- The top of `mi` cannot be 1, since there is a larger cube in the valley -/
theorem mi_xm_ne_one : (cs <| mi h v).xm ≠ 1 := by
apply ne_of_lt; rcases (nontrivial_bcubes h v).exists_ne (mi h v) with ⟨i, hi, h2i⟩
· apply lt_of_lt_of_le _ h.b_add_w_le_one
· exact i
· exact 0
rw [xm, mi_mem_bcubes.1, hi.1, _root_.add_lt_add_iff_left]
exact mi_strict_minimal h2i.symm hi
/-- If `mi` lies on the boundary of the valley in dimension j, then this lemma expresses that all
other cubes on the same boundary extend further from the boundary.
More precisely, there is a j-th coordinate `x : ℝ` in the valley, but not in `mi`,
such that every cube that shares a (particular) j-th coordinate with `mi` also contains j-th
coordinate `x` -/
theorem smallest_onBoundary {j} (bi : OnBoundary (mi_mem_bcubes : mi h v ∈ _) j) :
∃ x : ℝ, x ∈ c.side j.succ \ (cs <| mi h v).side j.succ ∧
∀ ⦃i'⦄ (_ : i' ∈ bcubes cs c),
i' ≠ mi h v → (cs <| mi h v).b j.succ ∈ (cs i').side j.succ → x ∈ (cs i').side j.succ := by
let i := mi h v; have hi : i ∈ bcubes cs c := mi_mem_bcubes
obtain bi | bi := bi
· refine ⟨(cs i).b j.succ + (cs i).w, ⟨?_, ?_⟩, ?_⟩
· simp [i, side, bi, hw', w_lt_w h v hi]
· intro h'; simpa [i, lt_irrefl] using h'.2
intro i' hi' i'_i h2i'; constructor
· apply le_trans h2i'.1
simp [i, hw']
apply lt_of_lt_of_le (add_lt_add_left (mi_strict_minimal i'_i.symm hi') _)
simp [i, bi.symm, b_le_b hi']
let s := bcubes cs c \ {i}
have hs : s.Nonempty := by
rcases (nontrivial_bcubes h v).exists_ne i with ⟨i', hi', h2i'⟩
exact ⟨i', hi', h2i'⟩
rcases Set.exists_min_image s (w ∘ cs) (Set.toFinite _) hs with ⟨i', ⟨hi', h2i'⟩, h3i'⟩
rw [mem_singleton_iff] at h2i'
let x := c.b j.succ + c.w - (cs i').w
have hx : x < (cs i).b j.succ := by
dsimp only [x]; rw [← bi, add_sub_assoc, add_lt_iff_neg_left, sub_lt_zero]
apply mi_strict_minimal (Ne.symm h2i') hi'
refine ⟨x, ⟨?_, ?_⟩, ?_⟩
· simp only [side, neg_lt_zero, hw, add_lt_iff_neg_left, and_true, mem_Ico, sub_eq_add_neg, x]
rw [add_assoc, le_add_iff_nonneg_right, ← sub_eq_add_neg, sub_nonneg]
apply le_of_lt (w_lt_w h v hi')
· simp only [side, not_and_or, not_lt, not_le, mem_Ico]; left; exact hx
intro i'' hi'' h2i'' h3i''; constructor; swap; · apply lt_trans hx h3i''.2
rw [le_sub_iff_add_le]
refine le_trans ?_ (t_le_t hi'' j); gcongr; apply h3i' i'' ⟨hi'', _⟩
simp [i, h2i'']
variable (h v)
/-- `mi` cannot lie on the boundary of the valley. Otherwise, the cube adjacent to it in the `j`-th
direction will intersect one of the neighbouring cubes on the same boundary as `mi`. -/
theorem mi_not_onBoundary (j : Fin n) : ¬OnBoundary (mi_mem_bcubes : mi h v ∈ _) j := by
let i := mi h v; have hi : i ∈ bcubes cs c := mi_mem_bcubes
haveI := h.nontrivial_fin
rcases exists_ne j with ⟨j', hj'⟩
intro hj
rcases smallest_onBoundary hj with ⟨x, ⟨hx, h2x⟩, h3x⟩
let p : Fin (n + 1) → ℝ := cons (c.b 0) fun j₂ => if j₂ = j then x else (cs i).b j₂.succ
have hp : p ∈ c.bottom := by
suffices ∀ j' : Fin n, ite (j' = j) x ((cs i).b j'.succ) ∈ c.side j'.succ by
simpa [p, bottom, toSet, tail, side_tail]
intro j₂
by_cases hj₂ : j₂ = j
· simp [hj₂, hx]
simp only [hj₂, if_false]; apply tail_sub hi; apply b_mem_side
rcases v.1 hp with ⟨_, ⟨i', rfl⟩, hi'⟩
have h2i' : i' ∈ bcubes cs c := ⟨hi'.1.symm, v.2.1 i' hi'.1.symm ⟨tail p, hi'.2, hp.2⟩⟩
have i_i' : i ≠ i' := by rintro rfl; simpa [i, p, side_tail, h2x] using hi'.2 j
have : Nonempty (↥((cs i').tail.side j' \ (cs i).tail.side j')) := by
apply nonempty_Ico_sdiff
· apply mi_strict_minimal i_i' h2i'
· apply hw
rcases this with ⟨⟨x', hx'⟩⟩
let p' : Fin (n + 1) → ℝ := cons (c.b 0) fun j₂ => if j₂ = j' then x' else (cs i).b j₂.succ
have hp' : p' ∈ c.bottom := by
suffices ∀ j : Fin n, ite (j = j') x' ((cs i).b j.succ) ∈ c.side j.succ by
simpa [p', bottom, toSet, tail, side_tail]
intro j₂
by_cases hj₂ : j₂ = j'; · simp [hj₂]; apply tail_sub h2i'; apply hx'.1
simp only [if_false, hj₂]; apply tail_sub hi; apply b_mem_side
rcases v.1 hp' with ⟨_, ⟨i'', rfl⟩, hi''⟩
have h2i'' : i'' ∈ bcubes cs c := ⟨hi''.1.symm, v.2.1 i'' hi''.1.symm ⟨tail p', hi''.2, hp'.2⟩⟩
have i'_i'' : i' ≠ i'' := by
rintro ⟨⟩
have : (cs i).b ∈ (cs i').toSet := by
simp only [toSet, forall_iff_succ, hi.1, bottom_mem_side h2i', true_and, mem_setOf_eq]
intro j₂; by_cases hj₂ : j₂ = j
· simpa [p', side_tail, hj'.symm, hj₂] using hi''.2 j
· simpa [p, hj₂] using hi'.2 j₂
apply not_disjoint_iff.mpr ⟨(cs i).b, (cs i).b_mem_toSet, this⟩ (h.1 i_i')
have i_i'' : i ≠ i'' := by intro h; induction h; simpa [p', hx'.2] using hi''.2 j'
apply Not.elim _ (h.1 i'_i'')
simp_rw [onFun, comp, toSet_disjoint, not_exists, not_disjoint_iff, forall_iff_succ]
refine ⟨⟨c.b 0, bottom_mem_side h2i', bottom_mem_side h2i''⟩, ?_⟩
intro j₂
by_cases hj₂ : j₂ = j
· cases hj₂; refine ⟨x, ?_, ?_⟩
· convert hi'.2 j using 1; simp [i, p]
apply h3x h2i'' i_i''.symm; convert hi''.2 j using 1; simp [i, p', hj'.symm]
by_cases h2j₂ : j₂ = j'
· cases h2j₂; refine ⟨x', hx'.1, ?_⟩; convert hi''.2 j' using 1; simp [p']
refine ⟨(cs i).b j₂.succ, ?_, ?_⟩
· convert hi'.2 j₂ using 1; simp [p, hj₂]
· convert hi''.2 j₂ using 1; simp [p', h2j₂]
variable {h v}
/-- The same result that `mi` cannot lie on the boundary of the valley written as inequalities. -/
theorem mi_not_onBoundary' (j : Fin n) :
c.tail.b j < (cs (mi h v)).tail.b j ∧
(cs (mi h v)).tail.b j + (cs (mi h v)).w < c.tail.b j + c.w := by
have := mi_not_onBoundary h v j
simp only [OnBoundary, not_or] at this; obtain ⟨h1, h2⟩ := this
constructor
· apply lt_of_le_of_ne (b_le_b mi_mem_bcubes _) h1
apply lt_of_le_of_ne _ h2
apply ((Ico_subset_Ico_iff _).mp (tail_sub mi_mem_bcubes j)).2
simp [hw]
/-- The top of `mi` gives rise to a new valley, since the neighbouring cubes extend further upward
than `mi`. -/
theorem valley_mi : Valley cs (cs (mi h v)).shiftUp := by
let i := mi h v; have hi : i ∈ bcubes cs c := mi_mem_bcubes
refine ⟨?_, ?_, ?_⟩
· intro p; apply h.shiftUp_bottom_subset_bottoms mi_xm_ne_one
· rintro i' hi' ⟨p2, hp2, h2p2⟩; simp only [head_shiftUp] at hi'
classical
by_contra h2i'
rw [tail_shiftUp] at h2p2
simp only [not_subset, tail_shiftUp] at h2i'
rcases h2i' with ⟨p1, hp1, h2p1⟩
have : ∃ p3, p3 ∈ (cs i').tail.toSet ∧ p3 ∉ (cs i).tail.toSet ∧ p3 ∈ c.tail.toSet := by
simp only [toSet, not_forall, mem_setOf_eq] at h2p1; obtain ⟨j, hj⟩ := h2p1
rcases Ico_lemma (mi_not_onBoundary' j).1 (by simp [hw]) (mi_not_onBoundary' j).2
(le_trans (hp2 j).1 <| le_of_lt (h2p2 j).2) (le_trans (h2p2 j).1 <| le_of_lt (hp2 j).2)
⟨hj, hp1 j⟩ with
⟨w, hw, h2w, h3w⟩
refine ⟨fun j' => if j' = j then w else p2 j', ?_, ?_, ?_⟩
· intro j'; by_cases h : j' = j
· simp only [if_pos h]; exact h ▸ h3w
· simp only [if_neg h]; exact hp2 j'
· simp only [toSet, not_forall, mem_setOf_eq]; use j; rw [if_pos rfl]; convert h2w
· intro j'; by_cases h : j' = j
· simp only [if_pos h, side_tail]; exact h ▸ hw
· simp only [if_neg h]; apply hi.2; apply h2p2
rcases this with ⟨p3, h1p3, h2p3, h3p3⟩
let p := @cons n (fun _ => ℝ) (c.b 0) p3
have hp : p ∈ c.bottom := by refine ⟨rfl, ?_⟩; rwa [tail_cons]
rcases v.1 hp with ⟨_, ⟨i'', rfl⟩, hi''⟩
have h2i'' : i'' ∈ bcubes cs c := by
use hi''.1.symm; apply v.2.1 i'' hi''.1.symm
use tail p; constructor
· exact hi''.2
· rw [tail_cons]; exact h3p3
have h3i'' : (cs i).w < (cs i'').w := by
apply mi_strict_minimal _ h2i''; rintro rfl; apply h2p3; convert hi''.2
let p' := @cons n (fun _ => ℝ) (cs i).xm p3
have hp' : p' ∈ (cs i').toSet := by simpa [i, p', toSet, forall_iff_succ, hi'.symm] using h1p3
have h2p' : p' ∈ (cs i'').toSet := by
simp only [p', toSet, forall_iff_succ, cons_succ, cons_zero, mem_setOf_eq]
refine ⟨?_, by simpa [toSet] using hi''.2⟩
have : (cs i).b 0 = (cs i'').b 0 := by rw [hi.1, h2i''.1]
simp [side, hw', xm, this, h3i'']
apply not_disjoint_iff.mpr ⟨p', hp', h2p'⟩
apply h.1
rintro rfl
apply (cs i).b_ne_xm
rw [← hi', ← hi''.1, hi.1]
rfl
· intro i' hi' h2i'
dsimp only [shiftUp] at h2i'
replace h2i' := h.Injective h2i'.symm
induction h2i'
exact b_ne_xm (cs i) hi'
variable (h) [Nontrivial ι]
/-- We get a sequence of cubes whose size is decreasing -/
noncomputable def sequenceOfCubes : ℕ → { i : ι // Valley cs (cs i).shiftUp }
| 0 =>
let v := valley_unitCube h
⟨mi h v, valley_mi⟩
| k + 1 =>
let v := (sequenceOfCubes k).2
⟨mi h v, valley_mi⟩
def decreasingSequence (k : ℕ) : ℝ :=
(cs (sequenceOfCubes h k).1).w
end
variable [Finite ι] [Nontrivial ι]
include h in
theorem strictAnti_sequenceOfCubes : StrictAnti <| decreasingSequence h :=
strictAnti_nat_of_succ_lt fun k => by
let v := (sequenceOfCubes h k).2; dsimp only [decreasingSequence, sequenceOfCubes]
apply w_lt_w h v (mi_mem_bcubes : mi h v ∈ _)
theorem injective_sequenceOfCubes : Injective (sequenceOfCubes h) :=
@Injective.of_comp _ _ _ (fun x : { _i : ι // _ } => (cs x.1).w) _
(strictAnti_sequenceOfCubes h).injective
/-- The infinite sequence of cubes contradicts the finiteness of the family. -/
theorem not_correct : ¬Correct cs := fun h =>
(Finite.of_injective _ <| injective_sequenceOfCubes h).false
/-- **Dissection of Cubes**: A cube cannot be cubed. -/
theorem cannot_cube_a_cube :
∀ {n : ℕ}, n ≥ 3 → -- In ℝ^n for n ≥ 3
∀ {s : Set (Cube n)}, s.Finite → -- given a finite collection of (hyper)cubes
s.Nontrivial → -- containing at least two elements
s.PairwiseDisjoint Cube.toSet → -- which is pairwise disjoint
⋃ c ∈ s, Cube.toSet c = unitCube.toSet → -- whose union is the unit cube
InjOn Cube.w s → -- such that the widths of all cubes are different
False := by -- then we can derive a contradiction
intro n hn s hfin h2 hd hU hinj
rcases n with - | n
· cases hn
exact @not_correct n s (↑) hfin.to_subtype h2.coe_sort
⟨hd.subtype _ _, (iUnion_subtype _ _).trans hU, hinj.injective, hn⟩
end «82»
end
end Theorems100
|
cyclic.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice.
From mathcomp Require Import div fintype bigop prime finset fingroup morphism.
From mathcomp Require Import perm automorphism quotient gproduct ssralg.
From mathcomp Require Import finalg zmodp poly.
(******************************************************************************)
(* Properties of cyclic groups. *)
(* Definitions: *)
(* Defined in fingroup.v: *)
(* <[x]> == the cycle (cyclic group) generated by x. *)
(* #[x] == the order of x, i.e., the cardinal of <[x]>. *)
(* Defined in prime.v: *)
(* totient n == Euler's totient function *)
(* Definitions in this file: *)
(* cyclic G <=> G is a cyclic group. *)
(* metacyclic G <=> G is a metacyclic group (i.e., a cyclic extension of a *)
(* cyclic group). *)
(* generator G x <=> x is a generator of the (cyclic) group G. *)
(* Zpm x == the isomorphism mapping the additive group of integers *)
(* mod #[x] to the cyclic group <[x]>. *)
(* cyclem x n == the endomorphism y |-> y ^+ n of <[x]>. *)
(* Zp_unitm x == the isomorphism mapping the multiplicative group of the *)
(* units of the ring of integers mod #[x] to the group of *)
(* automorphisms of <[x]> (i.e., Aut <[x]>). *)
(* Zp_unitm x maps u to cyclem x u. *)
(* eltm dvd_y_x == the smallest morphism (with domain <[x]>) mapping x to *)
(* y, given a proof dvd_y_x : #[y] %| #[x]. *)
(* expg_invn G k == if coprime #|G| k, the inverse of exponent k in G. *)
(* Basic results for these notions, plus the classical result that any finite *)
(* group isomorphic to a subgroup of a field is cyclic, hence that Aut G is *)
(* cyclic when G is of prime order. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope GRing.Theory.
(***********************************************************************)
(* Cyclic groups. *)
(***********************************************************************)
Section Cyclic.
Variable gT : finGroupType.
Implicit Types (a x y : gT) (A B : {set gT}) (G K H : {group gT}).
Definition cyclic A := [exists x, A == <[x]>].
Lemma cyclicP A : reflect (exists x, A = <[x]>) (cyclic A).
Proof. exact: exists_eqP. Qed.
Lemma cycle_cyclic x : cyclic <[x]>.
Proof. by apply/cyclicP; exists x. Qed.
Lemma cyclic1 : cyclic [1 gT].
Proof. by rewrite -cycle1 cycle_cyclic. Qed.
(***********************************************************************)
(* Isomorphism with the additive group *)
(***********************************************************************)
Section Zpm.
Variable a : gT.
Definition Zpm (i : 'Z_#[a]) := a ^+ i.
Lemma ZpmM : {in Zp #[a] &, {morph Zpm : x y / x * y}}.
Proof.
rewrite /Zpm; case: (eqVneq a 1) => [-> | nta] i j _ _.
by rewrite !expg1n ?mulg1.
by rewrite /= {3}Zp_cast ?order_gt1 // expg_mod_order expgD.
Qed.
Canonical Zpm_morphism := Morphism ZpmM.
Lemma im_Zpm : Zpm @* Zp #[a] = <[a]>.
Proof.
apply/eqP; rewrite eq_sym eqEcard cycle_subG /= andbC morphimEdom.
rewrite (leq_trans (leq_imset_card _ _)) ?card_Zp //= /Zp order_gt1.
case: eqP => /= [a1 | _]; first by rewrite imset_set1 morph1 a1 set11.
by apply/imsetP; exists 1%R; rewrite ?expg1 ?inE.
Qed.
Lemma injm_Zpm : 'injm Zpm.
Proof.
apply/injmP/dinjectiveP/card_uniqP.
rewrite size_map -cardE card_Zp //= {7}/order -im_Zpm morphimEdom /=.
by apply: eq_card => x; apply/imageP/imsetP=> [] [i Zp_i ->]; exists i.
Qed.
Lemma eq_expg_mod_order m n : (a ^+ m == a ^+ n) = (m == n %[mod #[a]]).
Proof.
have [->|] := eqVneq a 1; first by rewrite order1 !modn1 !expg1n eqxx.
rewrite -order_gt1 => lt1a; have ZpT: Zp #[a] = setT by rewrite /Zp lt1a.
have: injective Zpm by move=> i j; apply (injmP injm_Zpm); rewrite /= ZpT inE.
move/inj_eq=> eqZ; symmetry; rewrite -(Zp_cast lt1a).
by rewrite -[_ == _](eqZ (inZp m) (inZp n)) /Zpm /= Zp_cast ?expg_mod_order.
Qed.
Lemma eq_expg_ord d (m n : 'I_d) :
d <= #[a]%g -> (a ^+ m == a ^+ n) = (m == n).
Proof.
by move=> d_leq; rewrite eq_expg_mod_order !modn_small// (leq_trans _ d_leq).
Qed.
Lemma expgD_Zp d (n m : 'Z_d) : (d > 0)%N ->
#[a]%g %| d -> a ^+ (n + m)%R = a ^+ n * a ^+ m.
Proof.
move=> d_gt0 xdvd; apply/eqP; rewrite -expgD eq_expg_mod_order/= modn_dvdm//.
by case: d d_gt0 {m n} xdvd => [|[|[]]]//= _; rewrite dvdn1 => /eqP->.
Qed.
Lemma Zp_isom : isom (Zp #[a]) <[a]> Zpm.
Proof. by apply/isomP; rewrite injm_Zpm im_Zpm. Qed.
Lemma Zp_isog : isog (Zp #[a]) <[a]>.
Proof. exact: isom_isog Zp_isom. Qed.
End Zpm.
(***********************************************************************)
(* Central and direct product of cycles *)
(***********************************************************************)
Lemma cyclic_abelian A : cyclic A -> abelian A.
Proof. by case/cyclicP=> a ->; apply: cycle_abelian. Qed.
Lemma cycleMsub a b :
commute a b -> coprime #[a] #[b] -> <[a]> \subset <[a * b]>.
Proof.
move=> cab co_ab; apply/subsetP=> _ /cycleP[k ->].
apply/cycleP; exists (chinese #[a] #[b] k 0); symmetry.
rewrite expgMn // -expg_mod_order chinese_modl // expg_mod_order.
by rewrite /chinese addn0 -mulnA mulnCA expgM expg_order expg1n mulg1.
Qed.
Lemma cycleM a b :
commute a b -> coprime #[a] #[b] -> <[a * b]> = <[a]> * <[b]>.
Proof.
move=> cab co_ab; apply/eqP; rewrite eqEsubset -(cent_joinEl (cents_cycle cab)).
rewrite join_subG {3}cab !cycleMsub // 1?coprime_sym //.
by rewrite -genM_join cycle_subG mem_gen // imset2_f ?cycle_id.
Qed.
Lemma cyclicM A B :
cyclic A -> cyclic B -> B \subset 'C(A) -> coprime #|A| #|B| ->
cyclic (A * B).
Proof.
move=> /cyclicP[a ->] /cyclicP[b ->]; rewrite cent_cycle cycle_subG => cab coab.
by rewrite -cycleM ?cycle_cyclic //; apply/esym/cent1P.
Qed.
Lemma cyclicY K H :
cyclic K -> cyclic H -> H \subset 'C(K) -> coprime #|K| #|H| ->
cyclic (K <*> H).
Proof. by move=> cycK cycH cKH coKH; rewrite cent_joinEr // cyclicM. Qed.
(***********************************************************************)
(* Order properties *)
(***********************************************************************)
Lemma order_dvdn a n : #[a] %| n = (a ^+ n == 1).
Proof. by rewrite (eq_expg_mod_order a n 0) mod0n. Qed.
Lemma order_inf a n : a ^+ n.+1 == 1 -> #[a] <= n.+1.
Proof. by rewrite -order_dvdn; apply: dvdn_leq. Qed.
Lemma order_dvdG G a : a \in G -> #[a] %| #|G|.
Proof. by move=> Ga; apply: cardSg; rewrite cycle_subG. Qed.
Lemma expg_cardG G a : a \in G -> a ^+ #|G| = 1.
Proof. by move=> Ga; apply/eqP; rewrite -order_dvdn order_dvdG. Qed.
Lemma expg_znat G x k : x \in G -> x ^+ (k%:R : 'Z_(#|G|))%R = x ^+ k.
Proof.
case: (eqsVneq G 1) => [-> /set1P-> | ntG Gx]; first by rewrite !expg1n.
apply/eqP; rewrite val_Zp_nat ?cardG_gt1 // eq_expg_mod_order.
by rewrite modn_dvdm ?order_dvdG.
Qed.
Lemma expg_zneg G x (k : 'Z_(#|G|)) : x \in G -> x ^+ (- k)%R = x ^- k.
Proof.
move=> Gx; apply/eqP; rewrite eq_sym eq_invg_mul -expgD.
by rewrite -(expg_znat _ Gx) natrD natr_Zp natr_negZp subrr.
Qed.
Lemma nt_gen_prime G x : prime #|G| -> x \in G^# -> G :=: <[x]>.
Proof.
move=> Gpr /setD1P[]; rewrite -cycle_subG -cycle_eq1 => ntX sXG.
apply/eqP; rewrite eqEsubset sXG andbT.
by apply: contraR ntX => /(prime_TIg Gpr); rewrite (setIidPr sXG) => ->.
Qed.
Lemma nt_prime_order p x : prime p -> x ^+ p = 1 -> x != 1 -> #[x] = p.
Proof.
move=> p_pr xp ntx; apply/prime_nt_dvdP; rewrite ?order_eq1 //.
by rewrite order_dvdn xp.
Qed.
Lemma orderXdvd a n : #[a ^+ n] %| #[a].
Proof. by apply: order_dvdG; apply: mem_cycle. Qed.
Lemma orderXgcd a n : #[a ^+ n] = #[a] %/ gcdn #[a] n.
Proof.
apply/eqP; rewrite eqn_dvd; apply/andP; split.
rewrite order_dvdn -expgM -muln_divCA_gcd //.
by rewrite expgM expg_order expg1n.
have [-> | n_gt0] := posnP n; first by rewrite gcdn0 divnn order_gt0 dvd1n.
rewrite -(dvdn_pmul2r n_gt0) divn_mulAC ?dvdn_gcdl // dvdn_lcm.
by rewrite order_dvdn mulnC expgM expg_order eqxx dvdn_mulr.
Qed.
Lemma orderXdiv a n : n %| #[a] -> #[a ^+ n] = #[a] %/ n.
Proof. by case/dvdnP=> q defq; rewrite orderXgcd {2}defq gcdnC gcdnMl. Qed.
Lemma orderXexp p m n x : #[x] = (p ^ n)%N -> #[x ^+ (p ^ m)] = (p ^ (n - m))%N.
Proof.
move=> ox; have [n_le_m | m_lt_n] := leqP n m.
rewrite -(subnKC n_le_m) subnDA subnn expnD expgM -ox.
by rewrite expg_order expg1n order1.
rewrite orderXdiv ox ?dvdn_exp2l ?expnB ?(ltnW m_lt_n) //.
by have:= order_gt0 x; rewrite ox expn_gt0 orbC -(ltn_predK m_lt_n).
Qed.
Lemma orderXpfactor p k n x :
#[x ^+ (p ^ k)] = n -> prime p -> p %| n -> #[x] = (p ^ k * n)%N.
Proof.
move=> oxp p_pr dv_p_n.
suffices pk_x: p ^ k %| #[x] by rewrite -oxp orderXdiv // mulnC divnK.
rewrite pfactor_dvdn // leqNgt; apply: contraL dv_p_n => lt_x_k.
rewrite -oxp -p'natE // -(subnKC (ltnW lt_x_k)) expnD expgM.
rewrite (pnat_dvd (orderXdvd _ _)) // -p_part // orderXdiv ?dvdn_part //.
by rewrite -{1}[#[x]](partnC p) // mulKn // part_pnat.
Qed.
Lemma orderXprime p n x :
#[x ^+ p] = n -> prime p -> p %| n -> #[x] = (p * n)%N.
Proof. exact: (@orderXpfactor p 1). Qed.
Lemma orderXpnat m n x : #[x ^+ m] = n -> \pi(n).-nat m -> #[x] = (m * n)%N.
Proof.
move=> oxm n_m; have [m_gt0 _] := andP n_m.
suffices m_x: m %| #[x] by rewrite -oxm orderXdiv // mulnC divnK.
apply/dvdn_partP=> // p; rewrite mem_primes => /and3P[p_pr _ p_m].
have n_p: p \in \pi(n) by apply: (pnatP _ _ n_m).
have p_oxm: p %| #[x ^+ (p ^ logn p m)].
apply: dvdn_trans (orderXdvd _ m`_p^'); rewrite -expgM -p_part ?partnC //.
by rewrite oxm; rewrite mem_primes in n_p; case/and3P: n_p.
by rewrite (orderXpfactor (erefl _) p_pr p_oxm) p_part // dvdn_mulr.
Qed.
Lemma orderM a b :
commute a b -> coprime #[a] #[b] -> #[a * b] = (#[a] * #[b])%N.
Proof. by move=> cab co_ab; rewrite -coprime_cardMg -?cycleM. Qed.
Definition expg_invn A k := (egcdn k #|A|).1.
Lemma expgK G k :
coprime #|G| k -> {in G, cancel (expgn^~ k) (expgn^~ (expg_invn G k))}.
Proof.
move=> coGk x /order_dvdG Gx; apply/eqP.
rewrite -expgM (eq_expg_mod_order _ _ 1) -(modn_dvdm 1 Gx).
by rewrite -(chinese_modl coGk 1 0) /chinese mul1n addn0 modn_dvdm.
Qed.
Lemma cyclic_dprod K H G :
K \x H = G -> cyclic K -> cyclic H -> cyclic G = coprime #|K| #|H| .
Proof.
case/dprodP=> _ defKH cKH tiKH cycK cycH; pose m := lcmn #|K| #|H|.
apply/idP/idP=> [/cyclicP[x defG] | coKH]; last by rewrite -defKH cyclicM.
rewrite /coprime -dvdn1 -(@dvdn_pmul2l m) ?lcmn_gt0 ?cardG_gt0 //.
rewrite muln_lcm_gcd muln1 -TI_cardMg // defKH defG order_dvdn.
have /mulsgP[y z Ky Hz ->]: x \in K * H by rewrite defKH defG cycle_id.
rewrite -[1]mulg1 expgMn; last exact/commute_sym/(centsP cKH).
apply/eqP; congr (_ * _); apply/eqP; rewrite -order_dvdn.
exact: dvdn_trans (order_dvdG Ky) (dvdn_lcml _ _).
exact: dvdn_trans (order_dvdG Hz) (dvdn_lcmr _ _).
Qed.
(***********************************************************************)
(* Generator *)
(***********************************************************************)
Definition generator (A : {set gT}) a := A == <[a]>.
Lemma generator_cycle a : generator <[a]> a.
Proof. exact: eqxx. Qed.
Lemma cycle_generator a x : generator <[a]> x -> x \in <[a]>.
Proof. by move/(<[a]> =P _)->; apply: cycle_id. Qed.
Lemma generator_order a b : generator <[a]> b -> #[a] = #[b].
Proof. by rewrite /order => /(<[a]> =P _)->. Qed.
End Cyclic.
Arguments cyclic {gT} A%_g.
Arguments generator {gT} A%_g a%_g.
Arguments expg_invn {gT} A%_g k%_N.
Arguments cyclicP {gT A}.
Prenex Implicits cyclic Zpm.
(* Euler's theorem *)
Theorem Euler_exp_totient a n : coprime a n -> a ^ totient n = 1 %[mod n].
Proof.
(case: n => [|[|n']] //; [by rewrite !modn1 | set n := n'.+2]) => co_a_n.
have{co_a_n} Ua: coprime n (inZp a : 'I_n) by rewrite coprime_sym coprime_modl.
have: FinRing.unit 'Z_n Ua ^+ totient n == 1.
by rewrite -card_units_Zp // -order_dvdn order_dvdG ?inE.
by rewrite -2!val_eqE unit_Zp_expg /= -/n modnXm => /eqP.
Qed.
Section Eltm.
Variables (aT rT : finGroupType) (x : aT) (y : rT).
Definition eltm of #[y] %| #[x] := fun x_i => y ^+ invm (injm_Zpm x) x_i.
Hypothesis dvd_y_x : #[y] %| #[x].
Lemma eltmE i : eltm dvd_y_x (x ^+ i) = y ^+ i.
Proof.
apply/eqP; rewrite eq_expg_mod_order.
have [x_le1 | x_gt1] := leqP #[x] 1.
suffices: #[y] %| 1 by rewrite dvdn1 => /eqP->; rewrite !modn1.
by rewrite (dvdn_trans dvd_y_x) // dvdn1 order_eq1 -cycle_eq1 trivg_card_le1.
rewrite -(expg_znat i (cycle_id x)) invmE /=; last by rewrite /Zp x_gt1 inE.
by rewrite val_Zp_nat // modn_dvdm.
Qed.
Lemma eltm_id : eltm dvd_y_x x = y. Proof. exact: (eltmE 1). Qed.
Lemma eltmM : {in <[x]> &, {morph eltm dvd_y_x : x_i x_j / x_i * x_j}}.
Proof.
move=> _ _ /cycleP[i ->] /cycleP[j ->].
by apply/eqP; rewrite -expgD !eltmE expgD.
Qed.
Canonical eltm_morphism := Morphism eltmM.
Lemma im_eltm : eltm dvd_y_x @* <[x]> = <[y]>.
Proof. by rewrite morphim_cycle ?cycle_id //= eltm_id. Qed.
Lemma ker_eltm : 'ker (eltm dvd_y_x) = <[x ^+ #[y]]>.
Proof.
apply/eqP; rewrite eq_sym eqEcard cycle_subG 3!inE mem_cycle /= eltmE.
rewrite expg_order eqxx (orderE y) -im_eltm card_morphim setIid -orderE.
by rewrite orderXdiv ?dvdn_indexg //= leq_divRL ?indexg_gt0 ?Lagrange ?subsetIl.
Qed.
Lemma injm_eltm : 'injm (eltm dvd_y_x) = (#[x] %| #[y]).
Proof. by rewrite ker_eltm subG1 cycle_eq1 -order_dvdn. Qed.
End Eltm.
Section CycleSubGroup.
Variable gT : finGroupType.
(* Gorenstein, 1.3.1 (i) *)
Lemma cycle_sub_group (a : gT) m :
m %| #[a] ->
[set H : {group gT} | H \subset <[a]> & #|H| == m]
= [set <[a ^+ (#[a] %/ m)]>%G].
Proof.
move=> m_dv_a; have m_gt0: 0 < m by apply: dvdn_gt0 m_dv_a.
have oam: #|<[a ^+ (#[a] %/ m)]>| = m.
apply/eqP; rewrite [#|_|]orderXgcd -(divnMr m_gt0) muln_gcdl divnK //.
by rewrite gcdnC gcdnMr mulKn.
apply/eqP; rewrite eqEsubset sub1set inE /= cycleX oam eqxx !andbT.
apply/subsetP=> X; rewrite in_set1 inE -val_eqE /= eqEcard oam.
case/andP=> sXa /eqP oX; rewrite oX leqnn andbT.
apply/subsetP=> x Xx; case/cycleP: (subsetP sXa _ Xx) => k def_x.
have: (x ^+ m == 1)%g by rewrite -oX -order_dvdn cardSg // gen_subG sub1set.
rewrite {x Xx}def_x -expgM -order_dvdn -[#[a]](Lagrange sXa) -oX mulnC.
rewrite dvdn_pmul2r // mulnK // => /dvdnP[i ->].
by rewrite mulnC expgM groupX // cycle_id.
Qed.
Lemma cycle_subgroup_char a (H : {group gT}) : H \subset <[a]> -> H \char <[a]>.
Proof.
move=> sHa; apply: lone_subgroup_char => // J sJa isoJH.
have dvHa: #|H| %| #[a] by apply: cardSg.
have{dvHa} /setP Huniq := esym (cycle_sub_group dvHa).
move: (Huniq H) (Huniq J); rewrite !inE /=.
by rewrite sHa sJa (card_isog isoJH) eqxx => /eqP<- /eqP<-.
Qed.
End CycleSubGroup.
(***********************************************************************)
(* Reflected boolean property and morphic image, injection, bijection *)
(***********************************************************************)
Section MorphicImage.
Variables aT rT : finGroupType.
Variables (D : {group aT}) (f : {morphism D >-> rT}) (x : aT).
Hypothesis Dx : x \in D.
Lemma morph_order : #[f x] %| #[x].
Proof. by rewrite order_dvdn -morphX // expg_order morph1. Qed.
Lemma morph_generator A : generator A x -> generator (f @* A) (f x).
Proof. by move/(A =P _)->; rewrite /generator morphim_cycle. Qed.
End MorphicImage.
Section CyclicProps.
Variables gT : finGroupType.
Implicit Types (aT rT : finGroupType) (G H K : {group gT}).
Lemma cyclicS G H : H \subset G -> cyclic G -> cyclic H.
Proof.
move=> sHG /cyclicP[x defG]; apply/cyclicP.
exists (x ^+ (#[x] %/ #|H|)); apply/congr_group/set1P.
by rewrite -cycle_sub_group /order -defG ?cardSg // inE sHG eqxx.
Qed.
Lemma cyclicJ G x : cyclic (G :^ x) = cyclic G.
Proof.
apply/cyclicP/cyclicP=> [[y /(canRL (conjsgK x))] | [y ->]].
by rewrite -cycleJ; exists (y ^ x^-1).
by exists (y ^ x); rewrite cycleJ.
Qed.
Lemma eq_subG_cyclic G H K :
cyclic G -> H \subset G -> K \subset G -> (H :==: K) = (#|H| == #|K|).
Proof.
case/cyclicP=> x -> sHx sKx; apply/eqP/eqP=> [-> //| eqHK].
have def_GHx := cycle_sub_group (cardSg sHx); set GHx := [set _] in def_GHx.
have []: H \in GHx /\ K \in GHx by rewrite -def_GHx !inE sHx sKx eqHK /=.
by do 2!move/set1P->.
Qed.
Lemma cardSg_cyclic G H K :
cyclic G -> H \subset G -> K \subset G -> (#|H| %| #|K|) = (H \subset K).
Proof.
move=> cycG sHG sKG; apply/idP/idP; last exact: cardSg.
case/cyclicP: (cyclicS sKG cycG) => x defK; rewrite {K}defK in sKG *.
case/dvdnP=> k ox; suffices ->: H :=: <[x ^+ k]> by apply: cycleX.
apply/eqP; rewrite (eq_subG_cyclic cycG) ?(subset_trans (cycleX _ _)) //.
rewrite -orderE orderXdiv orderE ox ?dvdn_mulr ?mulKn //.
by have:= order_gt0 x; rewrite orderE ox; case k.
Qed.
Lemma sub_cyclic_char G H : cyclic G -> (H \char G) = (H \subset G).
Proof.
case/cyclicP=> x ->; apply/idP/idP => [/andP[] //|].
exact: cycle_subgroup_char.
Qed.
Lemma morphim_cyclic rT G H (f : {morphism G >-> rT}) :
cyclic H -> cyclic (f @* H).
Proof.
move=> cycH; wlog sHG: H cycH / H \subset G.
by rewrite -morphimIdom; apply; rewrite (cyclicS _ cycH, subsetIl) ?subsetIr.
case/cyclicP: cycH sHG => x ->; rewrite gen_subG sub1set => Gx.
by apply/cyclicP; exists (f x); rewrite morphim_cycle.
Qed.
Lemma quotient_cycle x H : x \in 'N(H) -> <[x]> / H = <[coset H x]>.
Proof. exact: morphim_cycle. Qed.
Lemma quotient_cyclic G H : cyclic G -> cyclic (G / H).
Proof. exact: morphim_cyclic. Qed.
Lemma quotient_generator x G H :
x \in 'N(H) -> generator G x -> generator (G / H) (coset H x).
Proof. by move=> Nx; apply: morph_generator. Qed.
Lemma prime_cyclic G : prime #|G| -> cyclic G.
Proof.
case/primeP; rewrite ltnNge -trivg_card_le1.
case/trivgPn=> x Gx ntx /(_ _ (order_dvdG Gx)).
rewrite order_eq1 (negbTE ntx) => /eqnP oxG; apply/cyclicP.
by exists x; apply/eqP; rewrite eq_sym eqEcard -oxG cycle_subG Gx leqnn.
Qed.
Lemma dvdn_prime_cyclic G p : prime p -> #|G| %| p -> cyclic G.
Proof.
move=> p_pr pG; case: (eqsVneq G 1) => [-> | ntG]; first exact: cyclic1.
by rewrite prime_cyclic // (prime_nt_dvdP p_pr _ pG) -?trivg_card1.
Qed.
Lemma cyclic_small G : #|G| <= 3 -> cyclic G.
Proof.
rewrite 4!(ltnS, leq_eqVlt) -trivg_card_le1 orbA orbC.
case/predU1P=> [-> | oG]; first exact: cyclic1.
by apply: prime_cyclic; case/pred2P: oG => ->.
Qed.
End CyclicProps.
Section IsoCyclic.
Variables gT rT : finGroupType.
Implicit Types (G H : {group gT}) (M : {group rT}).
Lemma injm_cyclic G H (f : {morphism G >-> rT}) :
'injm f -> H \subset G -> cyclic (f @* H) = cyclic H.
Proof.
move=> injf sHG; apply/idP/idP; last exact: morphim_cyclic.
by rewrite -{2}(morphim_invm injf sHG); apply: morphim_cyclic.
Qed.
Lemma isog_cyclic G M : G \isog M -> cyclic G = cyclic M.
Proof. by case/isogP=> f injf <-; rewrite injm_cyclic. Qed.
Lemma isog_cyclic_card G M : cyclic G -> isog G M = cyclic M && (#|M| == #|G|).
Proof.
move=> cycG; apply/idP/idP=> [isoGM | ].
by rewrite (card_isog isoGM) -(isog_cyclic isoGM) cycG /=.
case/cyclicP: cycG => x ->{G} /andP[/cyclicP[y ->] /eqP oy].
by apply: isog_trans (isog_symr _) (Zp_isog y); rewrite /order oy Zp_isog.
Qed.
Lemma injm_generator G H (f : {morphism G >-> rT}) x :
'injm f -> x \in G -> H \subset G ->
generator (f @* H) (f x) = generator H x.
Proof.
move=> injf Gx sHG; apply/idP/idP; last exact: morph_generator.
rewrite -{2}(morphim_invm injf sHG) -{2}(invmE injf Gx).
by apply: morph_generator; apply: mem_morphim.
Qed.
End IsoCyclic.
(* Metacyclic groups. *)
Section Metacyclic.
Variable gT : finGroupType.
Implicit Types (A : {set gT}) (G H : {group gT}).
Definition metacyclic A :=
[exists H : {group gT}, [&& cyclic H, H <| A & cyclic (A / H)]].
Lemma metacyclicP A :
reflect (exists H : {group gT}, [/\ cyclic H, H <| A & cyclic (A / H)])
(metacyclic A).
Proof. exact: 'exists_and3P. Qed.
Lemma metacyclic1 : metacyclic 1.
Proof.
by apply/existsP; exists 1%G; rewrite normal1 trivg_quotient !cyclic1.
Qed.
Lemma cyclic_metacyclic A : cyclic A -> metacyclic A.
Proof.
case/cyclicP=> x ->; apply/existsP; exists (<[x]>)%G.
by rewrite normal_refl cycle_cyclic trivg_quotient cyclic1.
Qed.
Lemma metacyclicS G H : H \subset G -> metacyclic G -> metacyclic H.
Proof.
move=> sHG /metacyclicP[K [cycK nsKG cycGq]]; apply/metacyclicP.
exists (H :&: K)%G; rewrite (cyclicS (subsetIr H K)) ?(normalGI sHG) //=.
rewrite setIC (isog_cyclic (second_isog _)) ?(cyclicS _ cycGq) ?quotientS //.
by rewrite (subset_trans sHG) ?normal_norm.
Qed.
End Metacyclic.
Arguments metacyclic {gT} A%_g.
Arguments metacyclicP {gT A}.
(* Automorphisms of cyclic groups. *)
Section CyclicAutomorphism.
Variable gT : finGroupType.
Section CycleAutomorphism.
Variable a : gT.
Section CycleMorphism.
Variable n : nat.
Definition cyclem of gT := fun x : gT => x ^+ n.
Lemma cyclemM : {in <[a]> & , {morph cyclem a : x y / x * y}}.
Proof.
by move=> x y ax ay; apply: expgMn; apply: (centsP (cycle_abelian a)).
Qed.
Canonical cyclem_morphism := Morphism cyclemM.
End CycleMorphism.
Section ZpUnitMorphism.
Variable u : {unit 'Z_#[a]}.
Lemma injm_cyclem : 'injm (cyclem (val u) a).
Proof.
apply/subsetP=> x /setIdP[ax]; rewrite !inE -order_dvdn.
have [a1 | nta] := eqVneq a 1; first by rewrite a1 cycle1 inE in ax.
rewrite -order_eq1 -dvdn1; move/eqnP: (valP u) => /= <-.
by rewrite dvdn_gcd [in X in X && _]Zp_cast ?order_gt1 // order_dvdG.
Qed.
Lemma im_cyclem : cyclem (val u) a @* <[a]> = <[a]>.
Proof.
apply/morphim_fixP=> //; first exact: injm_cyclem.
by rewrite morphim_cycle ?cycle_id ?cycleX.
Qed.
Definition Zp_unitm := aut injm_cyclem im_cyclem.
End ZpUnitMorphism.
Lemma Zp_unitmM : {in units_Zp #[a] &, {morph Zp_unitm : u v / u * v}}.
Proof.
move=> u v _ _; apply: (eq_Aut (Aut_aut _ _)) => [|x a_x].
by rewrite groupM ?Aut_aut.
rewrite permM !autE ?groupX //= /cyclem -expgM.
rewrite -expg_mod_order modn_dvdm ?expg_mod_order //.
case: (leqP #[a] 1) => [lea1 | lt1a]; last by rewrite Zp_cast ?order_dvdG.
by rewrite card_le1_trivg // in a_x; rewrite (set1P a_x) order1 dvd1n.
Qed.
Canonical Zp_unit_morphism := Morphism Zp_unitmM.
Lemma injm_Zp_unitm : 'injm Zp_unitm.
Proof.
have [a1 | nta] := eqVneq a 1.
by rewrite subIset //= card_le1_trivg ?subxx // card_units_Zp a1 order1.
apply/subsetP=> /= u /morphpreP[_ /set1P/= um1].
have{um1}: Zp_unitm u a == Zp_unitm 1 a by rewrite um1 morph1.
rewrite !autE ?cycle_id // eq_expg_mod_order.
by rewrite -[n in _ == _ %[mod n]]Zp_cast ?order_gt1 // !modZp inE.
Qed.
Lemma generator_coprime m : generator <[a]> (a ^+ m) = coprime #[a] m.
Proof.
rewrite /generator eq_sym eqEcard cycleX -/#[a] [#|_|]orderXgcd /=.
apply/idP/idP=> [le_a_am|co_am]; last by rewrite (eqnP co_am) divn1.
have am_gt0: 0 < gcdn #[a] m by rewrite gcdn_gt0 order_gt0.
by rewrite /coprime eqn_leq am_gt0 andbT -(@leq_pmul2l #[a]) ?muln1 -?leq_divRL.
Qed.
Lemma im_Zp_unitm : Zp_unitm @* units_Zp #[a] = Aut <[a]>.
Proof.
rewrite morphimEdom; apply/setP=> f; pose n := invm (injm_Zpm a) (f a).
apply/imsetP/idP=> [[u _ ->] | Af]; first exact: Aut_aut.
have [a1 | nta] := eqVneq a 1.
by rewrite a1 cycle1 Aut1 in Af; exists 1; rewrite // morph1 (set1P Af).
have a_fa: <[a]> = <[f a]>.
by rewrite -(autmE Af) -morphim_cycle ?im_autm ?cycle_id.
have def_n: a ^+ n = f a.
by rewrite -/(Zpm n) invmK // im_Zpm a_fa cycle_id.
have co_a_n: coprime #[a].-2.+2 n.
by rewrite {1}Zp_cast ?order_gt1 // -generator_coprime def_n; apply/eqP.
exists (FinRing.unit 'Z_#[a] co_a_n); rewrite ?inE //.
apply: eq_Aut (Af) (Aut_aut _ _) _ => x ax.
rewrite autE //= /cyclem; case/cycleP: ax => k ->{x}.
by rewrite -(autmE Af) morphX ?cycle_id //= autmE -def_n -!expgM mulnC.
Qed.
Lemma Zp_unit_isom : isom (units_Zp #[a]) (Aut <[a]>) Zp_unitm.
Proof. by apply/isomP; rewrite ?injm_Zp_unitm ?im_Zp_unitm. Qed.
Lemma Zp_unit_isog : isog (units_Zp #[a]) (Aut <[a]>).
Proof. exact: isom_isog Zp_unit_isom. Qed.
Lemma card_Aut_cycle : #|Aut <[a]>| = totient #[a].
Proof. by rewrite -(card_isog Zp_unit_isog) card_units_Zp. Qed.
Lemma totient_gen : totient #[a] = #|[set x | generator <[a]> x]|.
Proof.
have [lea1 | lt1a] := leqP #[a] 1.
rewrite /order card_le1_trivg // cards1 (@eq_card1 _ 1) // => x.
by rewrite !inE -cycle_eq1 eq_sym.
rewrite -(card_injm (injm_invm (injm_Zpm a))) /= ?im_Zpm; last first.
by apply/subsetP=> x /[1!inE]; apply: cycle_generator.
rewrite -card_units_Zp // cardsE card_sub morphim_invmE; apply: eq_card => /= d.
by rewrite !inE /= qualifE /= /Zp lt1a inE /= generator_coprime {1}Zp_cast.
Qed.
Lemma Aut_cycle_abelian : abelian (Aut <[a]>).
Proof. by rewrite -im_Zp_unitm morphim_abelian ?units_Zp_abelian. Qed.
End CycleAutomorphism.
Variable G : {group gT}.
Lemma Aut_cyclic_abelian : cyclic G -> abelian (Aut G).
Proof. by case/cyclicP=> x ->; apply: Aut_cycle_abelian. Qed.
Lemma card_Aut_cyclic : cyclic G -> #|Aut G| = totient #|G|.
Proof. by case/cyclicP=> x ->; apply: card_Aut_cycle. Qed.
Lemma sum_ncycle_totient :
\sum_(d < #|G|.+1) #|[set <[x]> | x in G & #[x] == d]| * totient d = #|G|.
Proof.
pose h (x : gT) : 'I_#|G|.+1 := inord #[x].
symmetry; rewrite -{1}sum1_card (partition_big h xpredT) //=.
apply: eq_bigr => d _; set Gd := finset _.
rewrite -sum_nat_const sum1dep_card -sum1_card (_ : finset _ = Gd); last first.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
by rewrite /eq_op /= inordK // ltnS subset_leq_card ?cycle_subG.
rewrite (partition_big_imset cycle) {}/Gd; apply: eq_bigr => C /=.
case/imsetP=> x /setIdP[Gx /eqP <-] -> {C d}.
rewrite sum1dep_card totient_gen; apply: eq_card => y; rewrite !inE /generator.
move: Gx; rewrite andbC eq_sym -!cycle_subG /order.
by case: eqP => // -> ->; rewrite eqxx.
Qed.
End CyclicAutomorphism.
Lemma sum_totient_dvd n : \sum_(d < n.+1 | d %| n) totient d = n.
Proof.
case: n => [|[|n']]; try by rewrite big_mkcond !big_ord_recl big_ord0.
set n := n'.+2; pose x1 : 'Z_n := 1%R.
have ox1: #[x1] = n by rewrite /order -Zp_cycle card_Zp.
rewrite -[rhs in _ = rhs]ox1 -[#[_]]sum_ncycle_totient [#|_|]ox1 big_mkcond /=.
apply: eq_bigr => d _; rewrite -{2}ox1; case: ifP => [|ndv_dG]; last first.
rewrite eq_card0 // => C; apply/imsetP=> [[x /setIdP[Gx oxd] _{C}]].
by rewrite -(eqP oxd) order_dvdG in ndv_dG.
move/cycle_sub_group; set Gd := [set _] => def_Gd.
rewrite (_ : _ @: _ = @gval _ @: Gd); first by rewrite imset_set1 cards1 mul1n.
apply/setP=> C; apply/idP/imsetP=> [| [gC GdC ->{C}]].
case/imsetP=> x /setIdP[_ oxd] ->; exists <[x]>%G => //.
by rewrite -def_Gd inE -Zp_cycle subsetT.
have:= GdC; rewrite -def_Gd => /setIdP[_ /eqP <-].
by rewrite (set1P GdC) /= imset_f // inE eqxx (mem_cycle x1).
Qed.
Section FieldMulCyclic.
(***********************************************************************)
(* A classic application to finite multiplicative subgroups of fields. *)
(***********************************************************************)
Import GRing.Theory.
Variables (gT : finGroupType) (G : {group gT}).
Lemma order_inj_cyclic :
{in G &, forall x y, #[x] = #[y] -> <[x]> = <[y]>} -> cyclic G.
Proof.
move=> ucG; apply: negbNE (contra _ (negbT (ltnn #|G|))) => ncG.
rewrite -{2}[#|G|]sum_totient_dvd big_mkcond (bigD1 ord_max) ?dvdnn //=.
rewrite -{1}[#|G|]sum_ncycle_totient (bigD1 ord_max) //= -addSn leq_add //.
rewrite eq_card0 ?totient_gt0 ?cardG_gt0 // => C.
apply/imsetP=> [[x /setIdP[Gx /eqP oxG]]]; case/cyclicP: ncG.
by exists x; apply/eqP; rewrite eq_sym eqEcard cycle_subG Gx -oxG /=.
elim/big_ind2: _ => // [m1 n1 m2 n2 | d _]; first exact: leq_add.
set Gd := _ @: _; case: (set_0Vmem Gd) => [-> | [C]]; first by rewrite cards0.
rewrite {}/Gd => /imsetP[x /setIdP[Gx /eqP <-] _ {C d}].
rewrite order_dvdG // (@eq_card1 _ <[x]>) ?mul1n // => C.
apply/idP/eqP=> [|-> {C}]; last by rewrite imset_f // inE Gx eqxx.
by case/imsetP=> y /setIdP[Gy /eqP/ucG->].
Qed.
Lemma div_ring_mul_group_cyclic (R : unitRingType) (f : gT -> R) :
f 1 = 1%R -> {in G &, {morph f : u v / u * v >-> (u * v)%R}} ->
{in G^#, forall x, f x - 1 \in GRing.unit}%R ->
abelian G -> cyclic G.
Proof.
move=> f1 fM f1P abelG.
have fX n: {in G, {morph f : u / u ^+ n >-> (u ^+ n)%R}}.
by case: n => // n x Gx; elim: n => //= n IHn; rewrite expgS fM ?groupX ?IHn.
have fU x: x \in G -> f x \in GRing.unit.
by move=> Gx; apply/unitrP; exists (f x^-1); rewrite -!fM ?groupV ?gsimp.
apply: order_inj_cyclic => x y Gx Gy; set n := #[x] => yn.
apply/eqP; rewrite eq_sym eqEcard -[#|_|]/n yn leqnn andbT cycle_subG /=.
suff{y Gy yn} ->: <[x]> = G :&: [set z | #[z] %| n] by rewrite !inE Gy yn /=.
apply/eqP; rewrite eqEcard subsetI cycle_subG {}Gx /= cardE; set rs := enum _.
apply/andP; split; first by apply/subsetP=> y xy; rewrite inE order_dvdG.
pose P : {poly R} := ('X^n - 1)%R; have n_gt0: n > 0 by apply: order_gt0.
have szP : size P = n.+1.
by rewrite size_polyDl size_polyXn ?size_polyN ?size_poly1.
rewrite -ltnS -szP -(size_map f) max_ring_poly_roots -?size_poly_eq0 ?{}szP //.
apply/allP=> fy /mapP[y]; rewrite mem_enum !inE order_dvdn => /andP[Gy].
move/eqP=> yn1 ->{fy}; apply/eqP.
by rewrite !(hornerE, hornerXn) -fX // yn1 f1 subrr.
have: uniq rs by apply: enum_uniq.
have: all [in G] rs by apply/allP=> y; rewrite mem_enum; case/setIP.
elim: rs => //= y rs IHrs /andP[Gy Grs] /andP[y_rs]; rewrite andbC.
move/IHrs=> -> {IHrs}//; apply/allP=> _ /mapP[z rs_z ->].
have{Grs} Gz := allP Grs z rs_z; rewrite /diff_roots -!fM // (centsP abelG) //.
rewrite eqxx -[f y]mul1r -(mulgKV y z) fM ?groupM ?groupV //=.
rewrite -mulNr -mulrDl unitrMl ?fU ?f1P // !inE.
by rewrite groupM ?groupV // andbT -eq_mulgV1; apply: contra y_rs; move/eqP <-.
Qed.
Lemma field_mul_group_cyclic (F : fieldType) (f : gT -> F) :
{in G &, {morph f : u v / u * v >-> (u * v)%R}} ->
{in G, forall x, f x = 1%R <-> x = 1} ->
cyclic G.
Proof.
move=> fM f1P; have f1 : f 1 = 1%R by apply/f1P.
apply: (div_ring_mul_group_cyclic f1 fM) => [x|].
case/setD1P=> x1 Gx; rewrite unitfE; apply: contra x1.
by rewrite subr_eq0 => /eqP/f1P->.
apply/centsP=> x Gx y Gy; apply/commgP/eqP.
apply/f1P; rewrite ?fM ?groupM ?groupV //.
by rewrite mulrCA -!fM ?groupM ?groupV // mulKg mulVg.
Qed.
End FieldMulCyclic.
Lemma field_unit_group_cyclic (F : finFieldType) (G : {group {unit F}}) :
cyclic G.
Proof.
apply: field_mul_group_cyclic FinRing.uval _ _ => // u _.
by split=> /eqP ?; apply/eqP.
Qed.
Lemma units_Zp_cyclic p : prime p -> cyclic (units_Zp p).
Proof. by move/pdiv_id <-; exact: field_unit_group_cyclic. Qed.
Section PrimitiveRoots.
Open Scope ring_scope.
Import GRing.Theory.
(* This subproof has been extracted out of [has_prim_root] for performance reasons.
See github PR #1059 for further documentation and investigation on this problem. *)
Lemma has_prim_root_subproof (F : fieldType) (n : nat) (rs : seq F)
(n_gt0 : n > 0)
(rsn1 : all n.-unity_root rs)
(Urs : uniq rs)
(sz_rs : size rs = n)
(r := fun s => val (s : seq_sub rs))
(rn1 : forall x : seq_sub rs, r x ^+ n = 1)
(prim_r : forall z : F, z ^+ n = 1 -> z \in rs)
(r' := (fun s (e : s ^+ n = 1) => {| ssval := s; ssvalP := prim_r s e |})
: forall s : F, s ^+ n = 1 -> seq_sub rs)
(sG_1 := r' 1 (expr1n F n) : seq_sub rs)
(sG_VP : forall s : seq_sub rs, r s ^+ n.-1 ^+ n = 1)
(sG_MP : forall s s0 : seq_sub rs, (r s * r s0) ^+ n = 1)
(sG_V := (fun s : seq_sub rs => r' (r s ^+ n.-1) (sG_VP s))
: seq_sub rs -> seq_sub rs)
(sG_M := (fun s s0 : seq_sub rs => r' (r s * r s0) (sG_MP s s0))
: seq_sub rs -> seq_sub rs -> seq_sub rs)
(sG_Ag : associative sG_M)
(sG_1g : left_id sG_1 sG_M)
(sG_Vg : left_inverse sG_1 sG_V sG_M) :
has n.-primitive_root rs.
Proof.
pose ssMG : isMulGroup (seq_sub rs) := isMulGroup.Build (seq_sub rs) sG_Ag sG_1g sG_Vg.
pose gT : finGroupType := HB.pack (seq_sub rs) ssMG.
have /cyclicP[x gen_x]: @cyclic gT setT.
apply: (@field_mul_group_cyclic gT [set: _] F r) => // x _.
by split=> [ri1 | ->]; first apply: val_inj.
apply/hasP; exists (r x); first exact: (valP x).
have [m prim_x dvdmn] := prim_order_exists n_gt0 (rn1 x).
rewrite -((m =P n) _) // eqn_dvd {}dvdmn -sz_rs -(card_seq_sub Urs) -cardsT.
rewrite gen_x (@order_dvdn gT) /(_ == _) /= -{prim_x}(prim_expr_order prim_x).
by apply/eqP; elim: m => //= m IHm; rewrite exprS expgS /= -IHm.
Qed.
Lemma has_prim_root (F : fieldType) (n : nat) (rs : seq F) :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs >= n ->
has n.-primitive_root rs.
Proof.
move=> n_gt0 rsn1 Urs; rewrite leq_eqVlt ltnNge max_unity_roots // orbF eq_sym.
move/eqP=> sz_rs; pose r := val (_ : seq_sub rs).
have rn1 x: r x ^+ n = 1.
by apply/eqP; rewrite -unity_rootE (allP rsn1) ?(valP x).
have prim_r z: z ^+ n = 1 -> z \in rs.
by move/eqP; rewrite -unity_rootE -(mem_unity_roots n_gt0).
pose r' := SeqSub (prim_r _ _); pose sG_1 := r' _ (expr1n _ _).
have sG_VP: r _ ^+ n.-1 ^+ n = 1.
by move=> x; rewrite -exprM mulnC exprM rn1 expr1n.
have sG_MP: (r _ * r _) ^+ n = 1 by move=> x y; rewrite exprMn !rn1 mul1r.
pose sG_V := r' _ (sG_VP _); pose sG_M := r' _ (sG_MP _ _).
have sG_Ag: associative sG_M by move=> x y z; apply: val_inj; rewrite /= mulrA.
have sG_1g: left_id sG_1 sG_M by move=> x; apply: val_inj; rewrite /= mul1r.
have sG_Vg: left_inverse sG_1 sG_V sG_M.
by move=> x; apply: val_inj; rewrite /= -exprSr prednK ?rn1.
exact: has_prim_root_subproof.
Qed.
End PrimitiveRoots.
(***********************************************************************)
(* Cycles of prime order *)
(***********************************************************************)
Section AutPrime.
Variable gT : finGroupType.
Lemma Aut_prime_cycle_cyclic (a : gT) : prime #[a] -> cyclic (Aut <[a]>).
Proof.
move=> pr_a; have inj_um := injm_Zp_unitm a.
have /eq_S/eq_S eq_a := Fp_Zcast pr_a.
pose fm := cast_ord (esym eq_a) \o val \o invm inj_um.
apply: (@field_mul_group_cyclic _ _ _ fm) => [f g Af Ag | f Af] /=.
by apply: val_inj; rewrite /= morphM ?im_Zp_unitm //= eq_a.
split=> [/= fm1 |->]; last by apply: val_inj; rewrite /= morph1.
apply: (injm1 (injm_invm inj_um)); first by rewrite /= im_Zp_unitm.
by do 2!apply: val_inj; move/(congr1 val): fm1.
Qed.
Lemma Aut_prime_cyclic (G : {group gT}) : prime #|G| -> cyclic (Aut G).
Proof.
move=> pr_G; case/cyclicP: (prime_cyclic pr_G) (pr_G) => x ->.
exact: Aut_prime_cycle_cyclic.
Qed.
End AutPrime.
|
DegLex.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.RingTheory.MvPolynomial.MonomialOrder
import Mathlib.Data.Finsupp.MonomialOrder.DegLex
/-! # Some lemmas about the deglex monomial order on multivariate polynomials -/
namespace MvPolynomial
open MonomialOrder Finsupp
open scoped MonomialOrder
variable {σ : Type*} {R : Type*} [CommSemiring R] {f g : MvPolynomial σ R}
section LinearOrder
variable [LinearOrder σ] [WellFoundedGT σ]
theorem degree_degLexDegree : (degLex.degree f).degree = f.totalDegree := by
by_cases hf : f = 0
· simp [hf]
apply le_antisymm
· exact le_totalDegree (degLex.degree_mem_support hf)
· unfold MvPolynomial.totalDegree
apply Finset.sup_le
intro b hb
exact DegLex.monotone_degree (degLex.le_degree hb)
theorem degLex_totalDegree_monotone (h : degLex.degree f ≼[degLex] degLex.degree g) :
f.totalDegree ≤ g.totalDegree := by
simp only [← MvPolynomial.degree_degLexDegree]
exact DegLex.monotone_degree h
end LinearOrder
theorem totalDegree_mul_of_isDomain [IsCancelMulZero R] (hf : f ≠ 0) (hg : g ≠ 0) :
totalDegree (f * g) = totalDegree f + totalDegree g := by
cases exists_wellOrder σ
rw [← degree_degLexDegree (σ := σᵒᵈ), ← degree_degLexDegree (σ := σᵒᵈ),
← degree_degLexDegree (σ := σᵒᵈ), MonomialOrder.degree_mul hf hg]
simp
end MvPolynomial
|
DenselyOrdered.lean
|
/-
Copyright (c) 2025 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Order.Interval.Finset.Basic
/-!
# Linear locally finite orders are densely ordered iff they are trivial
## Main results
* `LocallyFiniteOrder.denselyOrdered_iff_subsingleton`:
A linear locally finite order is densely ordered if and only if it is a subsingleton.
-/
variable {X : Type*} [LinearOrder X] [LocallyFiniteOrder X]
lemma LocallyFiniteOrder.denselyOrdered_iff_subsingleton :
DenselyOrdered X ↔ Subsingleton X := by
refine ⟨fun H ↦ ?_, fun h ↦ h.instDenselyOrdered⟩
rw [← not_nontrivial_iff_subsingleton, nontrivial_iff_lt]
rintro ⟨a, b, hab⟩
exact not_lt_of_denselyOrdered_of_locallyFinite a b hab
lemma denselyOrdered_set_iff_subsingleton {s : Set X} :
DenselyOrdered s ↔ s.Subsingleton := by
classical
simp [LocallyFiniteOrder.denselyOrdered_iff_subsingleton]
lemma WithBot.denselyOrdered_set_iff_subsingleton {s : Set (WithBot X)} :
DenselyOrdered s ↔ s.Subsingleton := by
refine ⟨fun H ↦ ?_, fun h ↦ h.denselyOrdered⟩
rw [← Set.subsingleton_coe, ← not_nontrivial_iff_subsingleton, nontrivial_iff_lt]
suffices DenselyOrdered (WithBot.some ⁻¹' s) by
rintro ⟨x, y, H⟩
rw [_root_.denselyOrdered_set_iff_subsingleton] at this
obtain ⟨z, hz, hz'⟩ := exists_between H
have hz0 : (⊥ : WithBot X) < z := by simp [(Subtype.coe_lt_coe.mpr hz).trans_le']
replace hz' : WithBot.unbot z.val hz0.ne' < WithBot.unbot y (hz0.trans hz').ne' := by
rwa [← WithBot.coe_lt_coe, WithBot.coe_unbot, WithBot.coe_unbot]
refine absurd (this ?_ ?_) hz'.ne <;>
simp
constructor
simp only [Subtype.exists, Set.mem_preimage, Subtype.forall, Subtype.mk_lt_mk, exists_and_right,
exists_prop]
intro x hx y hy hxy
have : (⟨_, hx⟩ : s) < ⟨_, hy⟩ := by simp [hxy]
obtain ⟨z, hz, hz'⟩ := exists_between this
simp only [← Subtype.coe_lt_coe] at hz hz'
refine ⟨WithBot.unbot z (hz.trans_le' (by simp)).ne', ⟨?_, ?_⟩, ?_⟩
· simp
· rw [← WithBot.coe_lt_coe]
simp [hz.trans_le]
· rw [← WithBot.coe_lt_coe]
simp [hz'.trans_le']
lemma WithTop.denselyOrdered_set_iff_subsingleton {s : Set (WithTop X)} :
DenselyOrdered s ↔ s.Subsingleton := by
have he : StrictAnti (WithTop.toDual.image s) :=
WithTop.toDual.image_strictAnti _ (fun ⦃a b⦄ a ↦ a)
rw [denselyOrdered_iff_of_strictAnti _ he, WithBot.denselyOrdered_set_iff_subsingleton,
WithTop.toDual.injective.subsingleton_image_iff]
|
Curry.lean
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Data.Fintype.Sort
import Mathlib.LinearAlgebra.Multilinear.Basic
/-!
# Currying of multilinear maps
We register isomorphisms corresponding to currying or uncurrying variables, transforming a
multilinear function `f` on `n+1` variables into a linear function taking values in multilinear
functions in `n` variables, and into a multilinear function in `n` variables taking values in linear
functions. These operations are called `f.curryLeft` and `f.curryRight` respectively
(with inverses `f.uncurryLeft` and `f.uncurryRight`). These operations induce linear equivalences
between spaces of multilinear functions in `n+1` variables and spaces of linear functions into
multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values
in linear functions), called respectively `multilinearCurryLeftEquiv` and
`multilinearCurryRightEquiv`.
-/
open Fin Function Finset Set
universe uR uS uι uι' v v' v₁ v₂ v₃
variable {R : Type uR} {S : Type uS} {ι : Type uι} {ι' : Type uι'} {n : ℕ}
{M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'}
/-!
### Currying
We associate to a multilinear map in `n+1` variables (i.e., based on `Fin n.succ`) two
curried functions, named `f.curryLeft` (which is a linear map on `E 0` taking values
in multilinear maps in `n` variables) and `f.curryRight` (which is a multilinear map in `n`
variables taking values in linear maps on `E 0`). In both constructions, the variable that is
singled out is `0`, to take advantage of the operations `cons` and `tail` on `Fin n`.
The inverse operations are called `uncurryLeft` and `uncurryRight`.
We also register linear equiv versions of these correspondences, in
`multilinearCurryLeftEquiv` and `multilinearCurryRightEquiv`.
-/
open MultilinearMap
variable [CommSemiring R] [∀ i, AddCommMonoid (M i)] [AddCommMonoid M'] [AddCommMonoid M₂]
[∀ i, Module R (M i)] [Module R M'] [Module R M₂]
/-! #### Left currying -/
/-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables,
construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)` -/
def LinearMap.uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) :
MultilinearMap R M M₂ :=
MultilinearMap.mk' (fun m ↦ f (m 0) (tail m))
(fun m i x y ↦ by cases i using Fin.cases <;> simp [Ne.symm])
(fun m i c x ↦ by cases i using Fin.cases <;> simp [Ne.symm])
@[simp]
theorem LinearMap.uncurryLeft_apply (f : M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂)
(m : ∀ i, M i) : f.uncurryLeft m = f (m 0) (tail m) :=
rfl
/-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain
a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/
def MultilinearMap.curryLeft (f : MultilinearMap R M M₂) :
M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂ where
toFun x := MultilinearMap.mk' fun m => f (cons x m)
map_add' x y := by
ext m
exact cons_add f m x y
map_smul' c x := by
ext m
exact cons_smul f m c x
@[simp]
theorem MultilinearMap.curryLeft_apply (f : MultilinearMap R M M₂) (x : M 0)
(m : ∀ i : Fin n, M i.succ) : f.curryLeft x m = f (cons x m) :=
rfl
@[simp]
theorem LinearMap.curry_uncurryLeft (f : M 0 →ₗ[R] MultilinearMap R (fun i :
Fin n => M i.succ) M₂) : f.uncurryLeft.curryLeft = f := by
tauto
@[simp]
theorem MultilinearMap.uncurry_curryLeft (f : MultilinearMap R M M₂) :
f.curryLeft.uncurryLeft = f := by
ext m
simp
variable (R M M₂)
/-- The space of multilinear maps on `Π (i : Fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from `M 0` to the space of multilinear maps on
`Π (i : Fin n), M i.succ`, by separating the first variable. We register this isomorphism as a
linear isomorphism in `multilinearCurryLeftEquiv R M M₂`.
The direct and inverse maps are given by `f.curryLeft` and `f.uncurryLeft`. Use these
unless you need the full framework of linear equivs. -/
@[simps]
def multilinearCurryLeftEquiv :
MultilinearMap R M M₂ ≃ₗ[R] (M 0 →ₗ[R] MultilinearMap R (fun i : Fin n => M i.succ) M₂) where
toFun := MultilinearMap.curryLeft
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun := LinearMap.uncurryLeft
left_inv := MultilinearMap.uncurry_curryLeft
right_inv := LinearMap.curry_uncurryLeft
variable {R M M₂}
/-! #### Right currying -/
/-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to
`M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (init m) (m (last n))` -/
def MultilinearMap.uncurryRight
(f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) :
MultilinearMap R M M₂ :=
MultilinearMap.mk' (fun m ↦ f (init m) (m (last n)))
(fun m i x y ↦ by cases i using Fin.lastCases <;> simp [Ne.symm])
(fun m i c x ↦ by cases i using Fin.lastCases <;> simp [Ne.symm])
@[simp]
theorem MultilinearMap.uncurryRight_apply
(f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂))
(m : ∀ i, M i) : f.uncurryRight m = f (init m) (m (last n)) :=
rfl
/-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain
a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by
`m ↦ (x ↦ f (snoc m x))`. -/
def MultilinearMap.curryRight (f : MultilinearMap R M M₂) :
MultilinearMap R (fun i : Fin n => M (Fin.castSucc i)) (M (last n) →ₗ[R] M₂) :=
MultilinearMap.mk' fun m ↦
{ toFun := fun x => f (snoc m x)
map_add' := fun x y => by simp_rw [f.snoc_add]
map_smul' := fun c x => by simp only [f.snoc_smul, RingHom.id_apply] }
@[simp]
theorem MultilinearMap.curryRight_apply (f : MultilinearMap R M M₂)
(m : ∀ i : Fin n, M (castSucc i)) (x : M (last n)) : f.curryRight m x = f (snoc m x) :=
rfl
@[simp]
theorem MultilinearMap.curry_uncurryRight
(f : MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂)) :
f.uncurryRight.curryRight = f := by
ext m x
simp only [snoc_last, MultilinearMap.curryRight_apply, MultilinearMap.uncurryRight_apply]
rw [init_snoc]
@[simp]
theorem MultilinearMap.uncurry_curryRight (f : MultilinearMap R M M₂) :
f.curryRight.uncurryRight = f := by
ext m
simp
variable (R M M₂)
/-- The space of multilinear maps on `Π (i : Fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from the space of multilinear maps on `Π (i : Fin n), M (castSucc i)` to
the space of linear maps on `M (last n)`, by separating the last variable. We register this
isomorphism as a linear isomorphism in `multilinearCurryRightEquiv R M M₂`.
The direct and inverse maps are given by `f.curryRight` and `f.uncurryRight`. Use these
unless you need the full framework of linear equivs. -/
def multilinearCurryRightEquiv :
MultilinearMap R M M₂ ≃ₗ[R]
MultilinearMap R (fun i : Fin n => M (castSucc i)) (M (last n) →ₗ[R] M₂) where
toFun := MultilinearMap.curryRight
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun := MultilinearMap.uncurryRight
left_inv := MultilinearMap.uncurry_curryRight
right_inv := MultilinearMap.curry_uncurryRight
variable {R M M₂}
/-- Given a linear map from `M p` to the space of multilinear maps
in `n` variables `M 0`, ..., `M n` with `M p` removed,
returns a multilinear map in all `n + 1` variables. -/
@[simps!]
def LinearMap.uncurryMid (p : Fin (n + 1))
(f : M p →ₗ[R] MultilinearMap R (fun i ↦ M (p.succAbove i)) M₂) : MultilinearMap R M M₂ :=
.mk' (fun m ↦ f (m p) (p.removeNth m))
(fun m i x y ↦ by cases i using Fin.succAboveCases p <;> simp)
(fun m i x y ↦ by cases i using Fin.succAboveCases p <;> simp)
/-- Interpret a multilinear map in `n + 1` variables
as a linear map in `p`th variable with values in the multilinear maps in the other variables. -/
@[simps!]
def MultilinearMap.curryMid (p : Fin (n + 1)) (f : MultilinearMap R M M₂) :
M p →ₗ[R] MultilinearMap R (fun i ↦ M (p.succAbove i)) M₂ where
toFun x := .mk' fun m ↦ f (p.insertNth x m)
map_add' x y := by ext; simp [map_insertNth_add]
map_smul' c x := by ext; simp [map_insertNth_smul]
@[simp]
theorem LinearMap.curryMid_uncurryMid (i : Fin (n + 1))
(f : M i →ₗ[R] MultilinearMap R (fun j ↦ M (i.succAbove j)) M₂) :
(f.uncurryMid i).curryMid i = f := by ext; simp
@[simp]
theorem MultilinearMap.uncurryMid_curryMid (i : Fin (n + 1)) (f : MultilinearMap R M M₂) :
(f.curryMid i).uncurryMid i = f := by ext; simp
variable (R M M₂)
/-- `MultilinearMap.curryMid` as a linear equivalence. -/
@[simps]
def MultilinearMap.curryMidLinearEquiv (p : Fin (n + 1)) :
MultilinearMap R M M₂ ≃ₗ[R] M p →ₗ[R] MultilinearMap R (fun i ↦ M (p.succAbove i)) M₂ where
toFun := MultilinearMap.curryMid p
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun := LinearMap.uncurryMid p
left_inv := MultilinearMap.uncurryMid_curryMid p
right_inv := LinearMap.curryMid_uncurryMid p
namespace MultilinearMap
variable {R M₂} {N : (ι ⊕ ι') → Type*}
[∀ i, AddCommMonoid (N i)] [∀ i, Module R (N i)]
/-- Given a family of modules `N : (ι ⊕ ι') → Type*`, a multilinear map
on `(fun _ : ι ⊕ ι' => M')` induces a multilinear map on
`(fun (i : ι) ↦ N (.inl i))` taking values in the space of
linear maps on `(fun (i : ι') ↦ N (.inr i))`. -/
def currySum (f : MultilinearMap R N M₂) :
MultilinearMap R (fun i : ι ↦ N (.inl i)) (MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂) where
toFun u :=
{ toFun v := f (Sum.rec u v)
map_update_add' := by letI := Classical.decEq ι; aesop
map_update_smul' := by letI := Classical.decEq ι; aesop }
map_update_add' u i x y :=
ext fun _ ↦ by letI := Classical.decEq ι'; simp
map_update_smul' u i c x :=
ext fun _ ↦ by letI := Classical.decEq ι'; simp
@[simp low]
theorem currySum_apply (f : MultilinearMap R N M₂)
(u : (i : ι) → N (Sum.inl i)) (v : (i : ι') → N (Sum.inr i)) :
currySum f u v = f (Sum.rec u v) := rfl
@[simp]
theorem currySum_apply' {N : Type*} [AddCommMonoid N] [Module R N]
(f : MultilinearMap R (fun _ : ι ⊕ ι' ↦ N) M₂)
(u : ι → N) (v : ι' → N) :
currySum f u v = f (Sum.elim u v) := rfl
@[simp]
lemma currySum_add (f₁ f₂ : MultilinearMap R N M₂) :
currySum (f₁ + f₂) = currySum f₁ + currySum f₂ := rfl
@[simp]
lemma currySum_smul (r : R) (f : MultilinearMap R N M₂) :
currySum (r • f) = r • currySum f := rfl
/-- Given a family of modules `N : (ι ⊕ ι') → Type*`, a multilinear map on
`(fun (i : ι) ↦ N (.inl i))` taking values in the space of
linear maps on `(fun (i : ι') ↦ N (.inr i))` induces a multilinear map
on `(fun _ : ι ⊕ ι' => M')` induces. -/
def uncurrySum
(g : MultilinearMap R (fun i : ι ↦ N (.inl i))
(MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) :
MultilinearMap R N M₂ where
toFun u := g (fun i ↦ u (.inl i)) (fun i' ↦ u (.inr i'))
map_update_add' := by
letI := Classical.decEq ι
letI := Classical.decEq ι'
rintro _ _ (_ | _) _ _ <;> simp
map_update_smul' := by
letI := Classical.decEq ι
letI := Classical.decEq ι'
rintro _ _ (_ | _) _ _ <;> simp
@[simp]
theorem uncurrySum_apply
(g : MultilinearMap R (fun i : ι ↦ N (.inl i))
(MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) (u) :
g.uncurrySum u =
g (fun i ↦ u (.inl i)) (fun i' ↦ u (.inr i')) := rfl
@[simp]
lemma uncurrySum_add
(g₁ g₂ : MultilinearMap R (fun i : ι ↦ N (.inl i))
(MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) :
uncurrySum (g₁ + g₂) = uncurrySum g₁ + uncurrySum g₂ :=
rfl
lemma uncurrySum_smul
(r : R) (g : MultilinearMap R (fun i : ι ↦ N (.inl i))
(MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) :
uncurrySum (r • g) = r • uncurrySum g :=
rfl
@[deprecated (since := "2025-04-23")] alias uncurrySum_aux_apply := uncurrySum_apply
@[simp]
lemma uncurrySum_currySum (f : MultilinearMap R N M₂) :
uncurrySum (currySum f) = f := by
ext
simp only [uncurrySum_apply, currySum_apply]
congr
ext (_ | _) <;> simp
@[simp]
lemma currySum_uncurrySum
(g : MultilinearMap R (fun i : ι ↦ N (.inl i))
(MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂)) :
currySum (uncurrySum g) = g :=
rfl
/-- Multilinear maps on `N : (ι ⊕ ι') → Type*` identify to multilinear maps
from `(fun (i : ι) ↦ N (.inl i))` taking values in the space of
linear maps on `(fun (i : ι') ↦ N (.inr i))`. -/
@[simps]
def currySumEquiv : MultilinearMap R N M₂ ≃ₗ[R]
MultilinearMap R (fun i : ι ↦ N (.inl i))
(MultilinearMap R (fun i : ι' ↦ N (.inr i)) M₂) where
toFun := currySum
invFun := uncurrySum
left_inv _ := by simp
map_add' := by aesop
map_smul' := by aesop
@[simp]
theorem coe_currySumEquiv : ⇑(currySumEquiv (R := R) (N := N) (M₂ := M₂)) = currySum :=
rfl
@[simp]
theorem coe_currySumEquiv_symm : ⇑(currySumEquiv (R := R) (N := N) (M₂ := M₂)).symm = uncurrySum :=
rfl
variable (R M₂ M')
/-- If `s : Finset (Fin n)` is a finite set of cardinality `k` and its complement has cardinality
`l`, then the space of multilinear maps on `fun i : Fin n => M'` is isomorphic to the space of
multilinear maps on `fun i : Fin k => M'` taking values in the space of multilinear maps
on `fun i : Fin l => M'`. -/
def curryFinFinset {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l) :
MultilinearMap R (fun _ : Fin n => M') M₂ ≃ₗ[R]
MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂) :=
(domDomCongrLinearEquiv R R M' M₂ (finSumEquivOfFinset hk hl).symm).trans
currySumEquiv
variable {R M₂ M'}
@[simp]
theorem curryFinFinset_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k) (hl : #sᶜ = l)
(f : MultilinearMap R (fun _ : Fin n => M') M₂) (mk : Fin k → M') (ml : Fin l → M') :
curryFinFinset R M₂ M' hk hl f mk ml =
f fun i => Sum.elim mk ml ((finSumEquivOfFinset hk hl).symm i) :=
rfl
@[simp]
theorem curryFinFinset_symm_apply {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k)
(hl : #sᶜ = l)
(f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂))
(m : Fin n → M') :
(curryFinFinset R M₂ M' hk hl).symm f m =
f (fun i => m <| finSumEquivOfFinset hk hl (Sum.inl i)) fun i =>
m <| finSumEquivOfFinset hk hl (Sum.inr i) :=
rfl
theorem curryFinFinset_symm_apply_piecewise_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k)
(hl : #sᶜ = l)
(f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂))
(x y : M') :
(curryFinFinset R M₂ M' hk hl).symm f (s.piecewise (fun _ => x) fun _ => y) =
f (fun _ => x) fun _ => y := by
rw [curryFinFinset_symm_apply]; congr
· ext
rw [finSumEquivOfFinset_inl, Finset.piecewise_eq_of_mem]
apply Finset.orderEmbOfFin_mem
· ext
rw [finSumEquivOfFinset_inr, Finset.piecewise_eq_of_notMem]
exact Finset.mem_compl.1 (Finset.orderEmbOfFin_mem _ _ _)
@[simp]
theorem curryFinFinset_symm_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k)
(hl : #sᶜ = l)
(f : MultilinearMap R (fun _ : Fin k => M') (MultilinearMap R (fun _ : Fin l => M') M₂))
(x : M') : ((curryFinFinset R M₂ M' hk hl).symm f fun _ => x) = f (fun _ => x) fun _ => x :=
rfl
theorem curryFinFinset_apply_const {k l n : ℕ} {s : Finset (Fin n)} (hk : #s = k)
(hl : #sᶜ = l) (f : MultilinearMap R (fun _ : Fin n => M') M₂) (x y : M') :
(curryFinFinset R M₂ M' hk hl f (fun _ => x) fun _ => y) =
f (s.piecewise (fun _ => x) fun _ => y) := by
rw [← curryFinFinset_symm_apply_piecewise_const hk hl, LinearEquiv.symm_apply_apply]
end MultilinearMap
|
VectorField.lean
|
/-
Copyright (c) 2024 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.FDeriv.Symmetric
/-!
# Vector fields in vector spaces
We study functions of the form `V : E → E` on a vector space, thinking of these as vector fields.
We define several notions in this context, with the aim to generalize them to vector fields on
manifolds.
Notably, we define the pullback of a vector field under a map, as
`VectorField.pullback 𝕜 f V x := (fderiv 𝕜 f x).inverse (V (f x))` (together with the same notion
within a set).
We also define the Lie bracket of two vector fields as
`VectorField.lieBracket 𝕜 V W x := fderiv 𝕜 W x (V x) - fderiv 𝕜 V x (W x)`
(together with the same notion within a set).
In addition to comprehensive API on these two notions, the main results are the following:
* `VectorField.pullback_lieBracket` states that the pullback of the Lie bracket
is the Lie bracket of the pullbacks, when the second derivative is symmetric.
* `VectorField.leibniz_identity_lieBracket` is the Leibniz
identity `[U, [V, W]] = [[U, V], W] + [V, [U, W]]`.
-/
open Set
open scoped Topology
noncomputable section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {n : WithTop ℕ∞}
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
{G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
{V W V₁ W₁ : E → E} {s t : Set E} {x : E}
/-!
### The Lie bracket of vector fields in a vector space
We define the Lie bracket of two vector fields, and call it `lieBracket 𝕜 V W x`. We also define
a version localized to sets, `lieBracketWithin 𝕜 V W s x`. We copy the relevant API
of `fderivWithin` and `fderiv` for these notions to get a comprehensive API.
-/
namespace VectorField
variable (𝕜) in
/-- The Lie bracket `[V, W] (x)` of two vector fields at a point, defined as
`DW(x) (V x) - DV(x) (W x)`. -/
def lieBracket (V W : E → E) (x : E) : E :=
fderiv 𝕜 W x (V x) - fderiv 𝕜 V x (W x)
variable (𝕜) in
/-- The Lie bracket `[V, W] (x)` of two vector fields within a set at a point, defined as
`DW(x) (V x) - DV(x) (W x)` where the derivatives are taken inside `s`. -/
def lieBracketWithin (V W : E → E) (s : Set E) (x : E) : E :=
fderivWithin 𝕜 W s x (V x) - fderivWithin 𝕜 V s x (W x)
lemma lieBracket_eq :
lieBracket 𝕜 V W = fun x ↦ fderiv 𝕜 W x (V x) - fderiv 𝕜 V x (W x) := rfl
lemma lieBracketWithin_eq :
lieBracketWithin 𝕜 V W s =
fun x ↦ fderivWithin 𝕜 W s x (V x) - fderivWithin 𝕜 V s x (W x) := rfl
@[simp]
theorem lieBracketWithin_univ : lieBracketWithin 𝕜 V W univ = lieBracket 𝕜 V W := by
ext1 x
simp [lieBracketWithin, lieBracket]
lemma lieBracketWithin_eq_zero_of_eq_zero (hV : V x = 0) (hW : W x = 0) :
lieBracketWithin 𝕜 V W s x = 0 := by
simp [lieBracketWithin, hV, hW]
lemma lieBracket_eq_zero_of_eq_zero (hV : V x = 0) (hW : W x = 0) :
lieBracket 𝕜 V W x = 0 := by
simp [lieBracket, hV, hW]
lemma lieBracketWithin_swap : lieBracketWithin 𝕜 V W s = - lieBracketWithin 𝕜 W V s := by
ext x; simp [lieBracketWithin]
lemma lieBracket_swap : lieBracket 𝕜 V W x = - lieBracket 𝕜 W V x := by
simp [lieBracket]
@[simp] lemma lieBracketWithin_self : lieBracketWithin 𝕜 V V s = 0 := by
ext x; simp [lieBracketWithin]
@[simp] lemma lieBracket_self : lieBracket 𝕜 V V = 0 := by
ext x; simp [lieBracket]
lemma lieBracketWithin_const_smul_left {c : 𝕜} (hV : DifferentiableWithinAt 𝕜 V s x)
(hs : UniqueDiffWithinAt 𝕜 s x) :
lieBracketWithin 𝕜 (c • V) W s x =
c • lieBracketWithin 𝕜 V W s x := by
simp [lieBracketWithin, smul_sub, fderivWithin_const_smul hs hV]
lemma lieBracket_const_smul_left {c : 𝕜} (hV : DifferentiableAt 𝕜 V x) :
lieBracket 𝕜 (c • V) W x = c • lieBracket 𝕜 V W x := by
simp only [← differentiableWithinAt_univ, ← lieBracketWithin_univ] at hV ⊢
exact lieBracketWithin_const_smul_left hV uniqueDiffWithinAt_univ
lemma lieBracketWithin_const_smul_right {c : 𝕜} (hW : DifferentiableWithinAt 𝕜 W s x)
(hs : UniqueDiffWithinAt 𝕜 s x) :
lieBracketWithin 𝕜 V (c • W) s x =
c • lieBracketWithin 𝕜 V W s x := by
simp [lieBracketWithin, smul_sub, fderivWithin_const_smul hs hW]
lemma lieBracket_const_smul_right {c : 𝕜} (hW : DifferentiableAt 𝕜 W x) :
lieBracket 𝕜 V (c • W) x = c • lieBracket 𝕜 V W x := by
simp only [← differentiableWithinAt_univ, ← lieBracketWithin_univ] at hW ⊢
exact lieBracketWithin_const_smul_right hW uniqueDiffWithinAt_univ
/--
Product rule for Lie Brackets: given two vector fields `V W : E → E` and a function `f : E → 𝕜`,
we have `[V, f • W] = (df V) • W + f • [V, W]`
-/
lemma lieBracketWithin_smul_right {f : E → 𝕜} (hf : DifferentiableWithinAt 𝕜 f s x)
(hW : DifferentiableWithinAt 𝕜 W s x) (hs : UniqueDiffWithinAt 𝕜 s x) :
lieBracketWithin 𝕜 V (fun y ↦ f y • W y) s x =
(fderivWithin 𝕜 f s x) (V x) • (W x) + (f x) • lieBracketWithin 𝕜 V W s x := by
simp [lieBracketWithin, fderivWithin_fun_smul hs hf hW, map_smul, add_comm, smul_sub,
add_sub_assoc]
/--
Product rule for Lie Brackets: given two vector fields `V W : E → E` and a function `f : E → 𝕜`,
we have `[V, f • W] = (df V) • W + f • [V, W]`
-/
lemma lieBracket_smul_right {f : E → 𝕜} (hf : DifferentiableAt 𝕜 f x)
(hW : DifferentiableAt 𝕜 W x) :
lieBracket 𝕜 V (fun y ↦ f y • W y) x =
(fderiv 𝕜 f x) (V x) • (W x) + (f x) • lieBracket 𝕜 V W x := by
simp_rw [← differentiableWithinAt_univ, ← lieBracketWithin_univ, fderiv] at hW hf ⊢
exact lieBracketWithin_smul_right hf hW uniqueDiffWithinAt_univ
/--
Product rule for Lie Brackets: given two vector fields `V W : E → E` and a function `f : E → 𝕜`,
we have `[f • V, W] = - (df W) • V + f • [V, W]`
-/
lemma lieBracketWithin_smul_left {f : E → 𝕜} (hf : DifferentiableWithinAt 𝕜 f s x)
(hV : DifferentiableWithinAt 𝕜 V s x) (hs : UniqueDiffWithinAt 𝕜 s x) :
lieBracketWithin 𝕜 (fun y ↦ f y • V y) W s x =
- (fderivWithin 𝕜 f s x) (W x) • (V x) + (f x) • lieBracketWithin 𝕜 V W s x := by
rw [lieBracketWithin_swap, Pi.neg_apply, lieBracketWithin_smul_right hf hV hs,
lieBracketWithin_swap, add_comm]
simp
/--
Product rule for Lie Brackets: given two vector fields `V W : E → E` and a function `f : E → 𝕜`,
we have `[f • V, W] = - (df W) • V + f • [V, W]`
-/
lemma lieBracket_fmul_left {f : E → 𝕜} (hf : DifferentiableAt 𝕜 f x)
(hV : DifferentiableAt 𝕜 V x) :
lieBracket 𝕜 (fun y ↦ f y • V y) W x =
- (fderiv 𝕜 f x) (W x) • (V x) + (f x) • lieBracket 𝕜 V W x := by
rw [lieBracket_swap, lieBracket_smul_right hf hV, lieBracket_swap, add_comm]
simp
lemma lieBracketWithin_add_left (hV : DifferentiableWithinAt 𝕜 V s x)
(hV₁ : DifferentiableWithinAt 𝕜 V₁ s x) (hs : UniqueDiffWithinAt 𝕜 s x) :
lieBracketWithin 𝕜 (V + V₁) W s x =
lieBracketWithin 𝕜 V W s x + lieBracketWithin 𝕜 V₁ W s x := by
simp only [lieBracketWithin, Pi.add_apply, map_add]
rw [fderivWithin_add hs hV hV₁, ContinuousLinearMap.add_apply]
abel
lemma lieBracket_add_left (hV : DifferentiableAt 𝕜 V x) (hV₁ : DifferentiableAt 𝕜 V₁ x) :
lieBracket 𝕜 (V + V₁) W x =
lieBracket 𝕜 V W x + lieBracket 𝕜 V₁ W x := by
simp only [lieBracket, Pi.add_apply, map_add]
rw [fderiv_add hV hV₁, ContinuousLinearMap.add_apply]
abel
/-- We have `[0, W] = 0` for all vector fields `W`: this depends on the junk value 0
if `W` is not differentiable. Version within a set. -/
@[simp]
lemma lieBracketWithin_zero_left : lieBracketWithin 𝕜 0 W s = 0 := by ext; simp [lieBracketWithin]
/-- We have `[W, 0] = 0` for all vector fields `W`: this depends on the junk value 0
if `W` is not differentiable. Version within a set. -/
@[simp]
lemma lieBracketWithin_zero_right : lieBracketWithin 𝕜 W 0 s = 0 := by ext; simp [lieBracketWithin]
/-- We have `[0, W] = 0` for all vector fields `W`: this depends on the junk value 0
if `W` is not differentiable. -/
@[simp]
lemma lieBracket_zero_left : lieBracket 𝕜 0 W = 0 := by simp [← lieBracketWithin_univ]
/-- We have `[W, 0] = 0` for all vector fields `W`: this depends on the junk value 0
if `W` is not differentiable. -/
@[simp]
lemma lieBracket_zero_right : lieBracket 𝕜 W 0 = 0 := by simp [← lieBracketWithin_univ]
lemma lieBracketWithin_add_right (hW : DifferentiableWithinAt 𝕜 W s x)
(hW₁ : DifferentiableWithinAt 𝕜 W₁ s x) (hs : UniqueDiffWithinAt 𝕜 s x) :
lieBracketWithin 𝕜 V (W + W₁) s x =
lieBracketWithin 𝕜 V W s x + lieBracketWithin 𝕜 V W₁ s x := by
simp only [lieBracketWithin, Pi.add_apply, map_add]
rw [fderivWithin_add hs hW hW₁, ContinuousLinearMap.add_apply]
abel
lemma lieBracket_add_right (hW : DifferentiableAt 𝕜 W x) (hW₁ : DifferentiableAt 𝕜 W₁ x) :
lieBracket 𝕜 V (W + W₁) x =
lieBracket 𝕜 V W x + lieBracket 𝕜 V W₁ x := by
simp only [lieBracket, Pi.add_apply, map_add]
rw [fderiv_add hW hW₁, ContinuousLinearMap.add_apply]
abel
lemma _root_.ContDiffWithinAt.lieBracketWithin_vectorField
{m n : WithTop ℕ∞} (hV : ContDiffWithinAt 𝕜 n V s x)
(hW : ContDiffWithinAt 𝕜 n W s x) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) (hx : x ∈ s) :
ContDiffWithinAt 𝕜 m (lieBracketWithin 𝕜 V W s) s x := by
apply ContDiffWithinAt.sub
· exact ContDiffWithinAt.clm_apply (hW.fderivWithin_right hs hmn hx)
(hV.of_le (le_trans le_self_add hmn))
· exact ContDiffWithinAt.clm_apply (hV.fderivWithin_right hs hmn hx)
(hW.of_le (le_trans le_self_add hmn))
lemma _root_.ContDiffAt.lieBracket_vectorField {m n : WithTop ℕ∞} (hV : ContDiffAt 𝕜 n V x)
(hW : ContDiffAt 𝕜 n W x) (hmn : m + 1 ≤ n) :
ContDiffAt 𝕜 m (lieBracket 𝕜 V W) x := by
rw [← contDiffWithinAt_univ] at hV hW ⊢
simp_rw [← lieBracketWithin_univ]
exact hV.lieBracketWithin_vectorField hW uniqueDiffOn_univ hmn (mem_univ _)
lemma _root_.ContDiffOn.lieBracketWithin_vectorField {m n : WithTop ℕ∞} (hV : ContDiffOn 𝕜 n V s)
(hW : ContDiffOn 𝕜 n W s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) :
ContDiffOn 𝕜 m (lieBracketWithin 𝕜 V W s) s :=
fun x hx ↦ (hV x hx).lieBracketWithin_vectorField (hW x hx) hs hmn hx
lemma _root_.ContDiff.lieBracket_vectorField {m n : WithTop ℕ∞} (hV : ContDiff 𝕜 n V)
(hW : ContDiff 𝕜 n W) (hmn : m + 1 ≤ n) :
ContDiff 𝕜 m (lieBracket 𝕜 V W) :=
contDiff_iff_contDiffAt.2 (fun _ ↦ hV.contDiffAt.lieBracket_vectorField hW.contDiffAt hmn)
theorem lieBracketWithin_of_mem_nhdsWithin (st : t ∈ 𝓝[s] x) (hs : UniqueDiffWithinAt 𝕜 s x)
(hV : DifferentiableWithinAt 𝕜 V t x) (hW : DifferentiableWithinAt 𝕜 W t x) :
lieBracketWithin 𝕜 V W s x = lieBracketWithin 𝕜 V W t x := by
simp [lieBracketWithin, fderivWithin_of_mem_nhdsWithin st hs hV,
fderivWithin_of_mem_nhdsWithin st hs hW]
theorem lieBracketWithin_subset (st : s ⊆ t) (ht : UniqueDiffWithinAt 𝕜 s x)
(hV : DifferentiableWithinAt 𝕜 V t x) (hW : DifferentiableWithinAt 𝕜 W t x) :
lieBracketWithin 𝕜 V W s x = lieBracketWithin 𝕜 V W t x :=
lieBracketWithin_of_mem_nhdsWithin (nhdsWithin_mono _ st self_mem_nhdsWithin) ht hV hW
theorem lieBracketWithin_inter (ht : t ∈ 𝓝 x) :
lieBracketWithin 𝕜 V W (s ∩ t) x = lieBracketWithin 𝕜 V W s x := by
simp [lieBracketWithin, fderivWithin_inter, ht]
theorem lieBracketWithin_of_mem_nhds (h : s ∈ 𝓝 x) :
lieBracketWithin 𝕜 V W s x = lieBracket 𝕜 V W x := by
rw [← lieBracketWithin_univ, ← univ_inter s, lieBracketWithin_inter h]
theorem lieBracketWithin_of_isOpen (hs : IsOpen s) (hx : x ∈ s) :
lieBracketWithin 𝕜 V W s x = lieBracket 𝕜 V W x :=
lieBracketWithin_of_mem_nhds (hs.mem_nhds hx)
theorem lieBracketWithin_eq_lieBracket (hs : UniqueDiffWithinAt 𝕜 s x)
(hV : DifferentiableAt 𝕜 V x) (hW : DifferentiableAt 𝕜 W x) :
lieBracketWithin 𝕜 V W s x = lieBracket 𝕜 V W x := by
simp [lieBracketWithin, lieBracket, fderivWithin_eq_fderiv, hs, hV, hW]
/-- Variant of `lieBracketWithin_congr_set` where one requires the sets to coincide only in
the complement of a point. -/
theorem lieBracketWithin_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
lieBracketWithin 𝕜 V W s x = lieBracketWithin 𝕜 V W t x := by
simp [lieBracketWithin, fderivWithin_congr_set' _ h]
theorem lieBracketWithin_congr_set (h : s =ᶠ[𝓝 x] t) :
lieBracketWithin 𝕜 V W s x = lieBracketWithin 𝕜 V W t x :=
lieBracketWithin_congr_set' x <| h.filter_mono inf_le_left
/-- Variant of `lieBracketWithin_eventually_congr_set` where one requires the sets to coincide only
in the complement of a point. -/
theorem lieBracketWithin_eventually_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
lieBracketWithin 𝕜 V W s =ᶠ[𝓝 x] lieBracketWithin 𝕜 V W t :=
(eventually_nhds_nhdsWithin.2 h).mono fun _ => lieBracketWithin_congr_set' y
theorem lieBracketWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) :
lieBracketWithin 𝕜 V W s =ᶠ[𝓝 x] lieBracketWithin 𝕜 V W t :=
lieBracketWithin_eventually_congr_set' x <| h.filter_mono inf_le_left
theorem _root_.DifferentiableWithinAt.lieBracketWithin_congr_mono
(hV : DifferentiableWithinAt 𝕜 V s x) (hVs : EqOn V₁ V t) (hVx : V₁ x = V x)
(hW : DifferentiableWithinAt 𝕜 W s x) (hWs : EqOn W₁ W t) (hWx : W₁ x = W x)
(hxt : UniqueDiffWithinAt 𝕜 t x) (h₁ : t ⊆ s) :
lieBracketWithin 𝕜 V₁ W₁ t x = lieBracketWithin 𝕜 V W s x := by
simp [lieBracketWithin, hV.fderivWithin_congr_mono, hW.fderivWithin_congr_mono, hVs, hVx,
hWs, hWx, hxt, h₁]
theorem _root_.Filter.EventuallyEq.lieBracketWithin_vectorField_eq
(hV : V₁ =ᶠ[𝓝[s] x] V) (hxV : V₁ x = V x) (hW : W₁ =ᶠ[𝓝[s] x] W) (hxW : W₁ x = W x) :
lieBracketWithin 𝕜 V₁ W₁ s x = lieBracketWithin 𝕜 V W s x := by
simp only [lieBracketWithin, hV.fderivWithin_eq hxV, hW.fderivWithin_eq hxW, hxV, hxW]
theorem _root_.Filter.EventuallyEq.lieBracketWithin_vectorField_eq_of_mem
(hV : V₁ =ᶠ[𝓝[s] x] V) (hW : W₁ =ᶠ[𝓝[s] x] W) (hx : x ∈ s) :
lieBracketWithin 𝕜 V₁ W₁ s x = lieBracketWithin 𝕜 V W s x :=
hV.lieBracketWithin_vectorField_eq (mem_of_mem_nhdsWithin hx hV :)
hW (mem_of_mem_nhdsWithin hx hW :)
/-- If vector fields coincide on a neighborhood of a point within a set, then the Lie brackets
also coincide on a neighborhood of this point within this set. Version where one considers the Lie
bracket within a subset. -/
theorem _root_.Filter.EventuallyEq.lieBracketWithin_vectorField'
(hV : V₁ =ᶠ[𝓝[s] x] V) (hW : W₁ =ᶠ[𝓝[s] x] W) (ht : t ⊆ s) :
lieBracketWithin 𝕜 V₁ W₁ t =ᶠ[𝓝[s] x] lieBracketWithin 𝕜 V W t := by
filter_upwards [hV.fderivWithin' ht (𝕜 := 𝕜), hW.fderivWithin' ht (𝕜 := 𝕜), hV, hW]
with x hV' hW' hV hW
simp [lieBracketWithin, hV', hW', hV, hW]
protected theorem _root_.Filter.EventuallyEq.lieBracketWithin_vectorField
(hV : V₁ =ᶠ[𝓝[s] x] V) (hW : W₁ =ᶠ[𝓝[s] x] W) :
lieBracketWithin 𝕜 V₁ W₁ s =ᶠ[𝓝[s] x] lieBracketWithin 𝕜 V W s :=
hV.lieBracketWithin_vectorField' hW Subset.rfl
protected theorem _root_.Filter.EventuallyEq.lieBracketWithin_vectorField_eq_of_insert
(hV : V₁ =ᶠ[𝓝[insert x s] x] V) (hW : W₁ =ᶠ[𝓝[insert x s] x] W) :
lieBracketWithin 𝕜 V₁ W₁ s x = lieBracketWithin 𝕜 V W s x := by
apply mem_of_mem_nhdsWithin (mem_insert x s) (hV.lieBracketWithin_vectorField' hW
(subset_insert x s))
theorem _root_.Filter.EventuallyEq.lieBracketWithin_vectorField_eq_nhds
(hV : V₁ =ᶠ[𝓝 x] V) (hW : W₁ =ᶠ[𝓝 x] W) :
lieBracketWithin 𝕜 V₁ W₁ s x = lieBracketWithin 𝕜 V W s x :=
(hV.filter_mono nhdsWithin_le_nhds).lieBracketWithin_vectorField_eq hV.self_of_nhds
(hW.filter_mono nhdsWithin_le_nhds) hW.self_of_nhds
theorem lieBracketWithin_congr
(hV : EqOn V₁ V s) (hVx : V₁ x = V x) (hW : EqOn W₁ W s) (hWx : W₁ x = W x) :
lieBracketWithin 𝕜 V₁ W₁ s x = lieBracketWithin 𝕜 V W s x :=
(hV.eventuallyEq.filter_mono inf_le_right).lieBracketWithin_vectorField_eq hVx
(hW.eventuallyEq.filter_mono inf_le_right) hWx
/-- Version of `lieBracketWithin_congr` in which one assumes that the point belongs to the
given set. -/
theorem lieBracketWithin_congr' (hV : EqOn V₁ V s) (hW : EqOn W₁ W s) (hx : x ∈ s) :
lieBracketWithin 𝕜 V₁ W₁ s x = lieBracketWithin 𝕜 V W s x :=
lieBracketWithin_congr hV (hV hx) hW (hW hx)
theorem _root_.Filter.EventuallyEq.lieBracket_vectorField_eq
(hV : V₁ =ᶠ[𝓝 x] V) (hW : W₁ =ᶠ[𝓝 x] W) :
lieBracket 𝕜 V₁ W₁ x = lieBracket 𝕜 V W x := by
rw [← lieBracketWithin_univ, ← lieBracketWithin_univ, hV.lieBracketWithin_vectorField_eq_nhds hW]
protected theorem _root_.Filter.EventuallyEq.lieBracket_vectorField
(hV : V₁ =ᶠ[𝓝 x] V) (hW : W₁ =ᶠ[𝓝 x] W) : lieBracket 𝕜 V₁ W₁ =ᶠ[𝓝 x] lieBracket 𝕜 V W := by
filter_upwards [hV.eventuallyEq_nhds, hW.eventuallyEq_nhds] with y hVy hWy
exact hVy.lieBracket_vectorField_eq hWy
/-- The Lie bracket of vector fields in vector spaces satisfies the Leibniz identity
`[U, [V, W]] = [[U, V], W] + [V, [U, W]]`. -/
lemma leibniz_identity_lieBracketWithin_of_isSymmSndFDerivWithinAt
{U V W : E → E} {s : Set E} {x : E} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s)
(hU : ContDiffWithinAt 𝕜 2 U s x) (hV : ContDiffWithinAt 𝕜 2 V s x)
(hW : ContDiffWithinAt 𝕜 2 W s x)
(h'U : IsSymmSndFDerivWithinAt 𝕜 U s x) (h'V : IsSymmSndFDerivWithinAt 𝕜 V s x)
(h'W : IsSymmSndFDerivWithinAt 𝕜 W s x) :
lieBracketWithin 𝕜 U (lieBracketWithin 𝕜 V W s) s x =
lieBracketWithin 𝕜 (lieBracketWithin 𝕜 U V s) W s x
+ lieBracketWithin 𝕜 V (lieBracketWithin 𝕜 U W s) s x := by
simp only [lieBracketWithin_eq, map_sub]
have aux₁ {U V : E → E} (hU : ContDiffWithinAt 𝕜 2 U s x) (hV : ContDiffWithinAt 𝕜 2 V s x) :
DifferentiableWithinAt 𝕜 (fun x ↦ (fderivWithin 𝕜 V s x) (U x)) s x :=
have := hV.fderivWithin_right_apply (hU.of_le one_le_two) hs le_rfl hx
this.differentiableWithinAt le_rfl
have aux₂ {U V : E → E} (hU : ContDiffWithinAt 𝕜 2 U s x) (hV : ContDiffWithinAt 𝕜 2 V s x) :
fderivWithin 𝕜 (fun y ↦ (fderivWithin 𝕜 U s y) (V y)) s x =
(fderivWithin 𝕜 U s x).comp (fderivWithin 𝕜 V s x) +
(fderivWithin 𝕜 (fderivWithin 𝕜 U s) s x).flip (V x) := by
refine fderivWithin_clm_apply (hs x hx) ?_ (hV.differentiableWithinAt one_le_two)
exact (hU.fderivWithin_right hs le_rfl hx).differentiableWithinAt le_rfl
rw [fderivWithin_fun_sub (hs x hx) (aux₁ hV hW) (aux₁ hW hV)]
rw [fderivWithin_fun_sub (hs x hx) (aux₁ hU hV) (aux₁ hV hU)]
rw [fderivWithin_fun_sub (hs x hx) (aux₁ hU hW) (aux₁ hW hU)]
rw [aux₂ hW hV, aux₂ hV hW, aux₂ hV hU, aux₂ hU hV, aux₂ hW hU, aux₂ hU hW]
simp only [ContinuousLinearMap.coe_sub', Pi.sub_apply, ContinuousLinearMap.add_apply,
ContinuousLinearMap.coe_comp', Function.comp_apply, ContinuousLinearMap.flip_apply, h'V.eq,
h'U.eq, h'W.eq]
abel
/-- The Lie bracket of vector fields in vector spaces satisfies the Leibniz identity
`[U, [V, W]] = [[U, V], W] + [V, [U, W]]`. -/
lemma leibniz_identity_lieBracketWithin (hn : minSmoothness 𝕜 2 ≤ n)
{U V W : E → E} {s : Set E} {x : E}
(hs : UniqueDiffOn 𝕜 s) (h'x : x ∈ closure (interior s)) (hx : x ∈ s)
(hU : ContDiffWithinAt 𝕜 n U s x) (hV : ContDiffWithinAt 𝕜 n V s x)
(hW : ContDiffWithinAt 𝕜 n W s x) :
lieBracketWithin 𝕜 U (lieBracketWithin 𝕜 V W s) s x =
lieBracketWithin 𝕜 (lieBracketWithin 𝕜 U V s) W s x
+ lieBracketWithin 𝕜 V (lieBracketWithin 𝕜 U W s) s x := by
apply leibniz_identity_lieBracketWithin_of_isSymmSndFDerivWithinAt hs hx
(hU.of_le (le_minSmoothness.trans hn)) (hV.of_le (le_minSmoothness.trans hn))
(hW.of_le (le_minSmoothness.trans hn))
· exact hU.isSymmSndFDerivWithinAt hn hs h'x hx
· exact hV.isSymmSndFDerivWithinAt hn hs h'x hx
· exact hW.isSymmSndFDerivWithinAt hn hs h'x hx
/-- The Lie bracket of vector fields in vector spaces satisfies the Leibniz identity
`[U, [V, W]] = [[U, V], W] + [V, [U, W]]`. -/
lemma leibniz_identity_lieBracket (hn : minSmoothness 𝕜 2 ≤ n) {U V W : E → E} {x : E}
(hU : ContDiffAt 𝕜 n U x) (hV : ContDiffAt 𝕜 n V x) (hW : ContDiffAt 𝕜 n W x) :
lieBracket 𝕜 U (lieBracket 𝕜 V W) x =
lieBracket 𝕜 (lieBracket 𝕜 U V) W x + lieBracket 𝕜 V (lieBracket 𝕜 U W) x := by
simp only [← lieBracketWithin_univ, ← contDiffWithinAt_univ] at hU hV hW ⊢
exact leibniz_identity_lieBracketWithin hn uniqueDiffOn_univ (by simp) (mem_univ _) hU hV hW
/-!
### The pullback of vector fields in a vector space
-/
variable (𝕜) in
/-- The pullback of a vector field under a function, defined
as `(f^* V) (x) = Df(x)^{-1} (V (f x))`. If `Df(x)` is not invertible, we use the junk value `0`.
-/
def pullback (f : E → F) (V : F → F) (x : E) : E := (fderiv 𝕜 f x).inverse (V (f x))
variable (𝕜) in
/-- The pullback within a set of a vector field under a function, defined
as `(f^* V) (x) = Df(x)^{-1} (V (f x))` where `Df(x)` is the derivative of `f` within `s`.
If `Df(x)` is not invertible, we use the junk value `0`.
-/
def pullbackWithin (f : E → F) (V : F → F) (s : Set E) (x : E) : E :=
(fderivWithin 𝕜 f s x).inverse (V (f x))
lemma pullbackWithin_eq {f : E → F} {V : F → F} {s : Set E} :
pullbackWithin 𝕜 f V s = fun x ↦ (fderivWithin 𝕜 f s x).inverse (V (f x)) := rfl
lemma pullback_eq_of_fderiv_eq
{f : E → F} {M : E ≃L[𝕜] F} {x : E} (hf : M = fderiv 𝕜 f x) (V : F → F) :
pullback 𝕜 f V x = M.symm (V (f x)) := by
simp [pullback, ← hf]
lemma pullback_eq_of_not_isInvertible {f : E → F} {x : E}
(h : ¬(fderiv 𝕜 f x).IsInvertible) (V : F → F) :
pullback 𝕜 f V x = 0 := by
simp [pullback, h]
lemma pullbackWithin_eq_of_not_isInvertible {f : E → F} {x : E}
(h : ¬(fderivWithin 𝕜 f s x).IsInvertible) (V : F → F) :
pullbackWithin 𝕜 f V s x = 0 := by
simp [pullbackWithin, h]
lemma pullbackWithin_eq_of_fderivWithin_eq
{f : E → F} {M : E ≃L[𝕜] F} {x : E} (hf : M = fderivWithin 𝕜 f s x) (V : F → F) :
pullbackWithin 𝕜 f V s x = M.symm (V (f x)) := by
simp [pullbackWithin, ← hf]
@[simp] lemma pullbackWithin_univ {f : E → F} {V : F → F} :
pullbackWithin 𝕜 f V univ = pullback 𝕜 f V := by
ext x
simp [pullbackWithin, pullback]
open scoped Topology Filter
lemma fderiv_pullback (f : E → F) (V : F → F) (x : E) (h'f : (fderiv 𝕜 f x).IsInvertible) :
fderiv 𝕜 f x (pullback 𝕜 f V x) = V (f x) := by
rcases h'f with ⟨M, hM⟩
simp [pullback_eq_of_fderiv_eq hM, ← hM]
lemma fderivWithin_pullbackWithin {f : E → F} {V : F → F} {x : E}
(h'f : (fderivWithin 𝕜 f s x).IsInvertible) :
fderivWithin 𝕜 f s x (pullbackWithin 𝕜 f V s x) = V (f x) := by
rcases h'f with ⟨M, hM⟩
simp [pullbackWithin_eq_of_fderivWithin_eq hM, ← hM]
open Set
variable [CompleteSpace E]
/-- If a `C^2` map has an invertible derivative within a set at a point, then nearby derivatives
can be written as continuous linear equivs, which depend in a `C^1` way on the point, as well as
their inverse, and moreover one can compute the derivative of the inverse. -/
lemma _root_.exists_continuousLinearEquiv_fderivWithin_symm_eq
{f : E → F} {s : Set E} {x : E} (h'f : ContDiffWithinAt 𝕜 2 f s x)
(hf : (fderivWithin 𝕜 f s x).IsInvertible) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) :
∃ N : E → (E ≃L[𝕜] F), ContDiffWithinAt 𝕜 1 (fun y ↦ (N y : E →L[𝕜] F)) s x
∧ ContDiffWithinAt 𝕜 1 (fun y ↦ ((N y).symm : F →L[𝕜] E)) s x
∧ (∀ᶠ y in 𝓝[s] x, N y = fderivWithin 𝕜 f s y)
∧ ∀ v, fderivWithin 𝕜 (fun y ↦ ((N y).symm : F →L[𝕜] E)) s x v
= - (N x).symm ∘L ((fderivWithin 𝕜 (fderivWithin 𝕜 f s) s x v)) ∘L (N x).symm := by
classical
rcases hf with ⟨M, hM⟩
let U := {y | ∃ (N : E ≃L[𝕜] F), N = fderivWithin 𝕜 f s y}
have hU : U ∈ 𝓝[s] x := by
have I : range ((↑) : (E ≃L[𝕜] F) → E →L[𝕜] F) ∈ 𝓝 (fderivWithin 𝕜 f s x) := by
rw [← hM]
exact M.nhds
have : ContinuousWithinAt (fderivWithin 𝕜 f s) s x :=
(h'f.fderivWithin_right (m := 1) hs le_rfl hx).continuousWithinAt
exact this I
let N : E → (E ≃L[𝕜] F) := fun x ↦ if h : x ∈ U then h.choose else M
have eN : (fun y ↦ (N y : E →L[𝕜] F)) =ᶠ[𝓝[s] x] fun y ↦ fderivWithin 𝕜 f s y := by
filter_upwards [hU] with y hy
simpa only [hy, ↓reduceDIte, N] using Exists.choose_spec hy
have e'N : N x = fderivWithin 𝕜 f s x := by apply mem_of_mem_nhdsWithin hx eN
have hN : ContDiffWithinAt 𝕜 1 (fun y ↦ (N y : E →L[𝕜] F)) s x := by
have : ContDiffWithinAt 𝕜 1 (fun y ↦ fderivWithin 𝕜 f s y) s x :=
h'f.fderivWithin_right (m := 1) hs le_rfl hx
apply this.congr_of_eventuallyEq eN e'N
have hN' : ContDiffWithinAt 𝕜 1 (fun y ↦ ((N y).symm : F →L[𝕜] E)) s x := by
have : ContDiffWithinAt 𝕜 1 (ContinuousLinearMap.inverse ∘ (fun y ↦ (N y : E →L[𝕜] F))) s x :=
(contDiffAt_map_inverse (N x)).comp_contDiffWithinAt x hN
convert this with y
simp only [Function.comp_apply, ContinuousLinearMap.inverse_equiv]
refine ⟨N, hN, hN', eN, fun v ↦ ?_⟩
have A' y : ContinuousLinearMap.compL 𝕜 F E F (N y : E →L[𝕜] F) ((N y).symm : F →L[𝕜] E)
= ContinuousLinearMap.id 𝕜 F := by ext; simp
have : fderivWithin 𝕜 (fun y ↦ ContinuousLinearMap.compL 𝕜 F E F (N y : E →L[𝕜] F)
((N y).symm : F →L[𝕜] E)) s x v = 0 := by
simp [A', fderivWithin_const_apply]
have I : (N x : E →L[𝕜] F) ∘L (fderivWithin 𝕜 (fun y ↦ ((N y).symm : F →L[𝕜] E)) s x v) =
- (fderivWithin 𝕜 (fun y ↦ (N y : E →L[𝕜] F)) s x v) ∘L ((N x).symm : F →L[𝕜] E) := by
rw [ContinuousLinearMap.fderivWithin_of_bilinear _ (hN.differentiableWithinAt le_rfl)
(hN'.differentiableWithinAt le_rfl) (hs x hx)] at this
simpa [eq_neg_iff_add_eq_zero] using this
have B (M : F →L[𝕜] E) : M = ((N x).symm : F →L[𝕜] E) ∘L ((N x) ∘L M) := by
ext; simp
rw [B (fderivWithin 𝕜 (fun y ↦ ((N y).symm : F →L[𝕜] E)) s x v), I]
simp only [ContinuousLinearMap.comp_neg, eN.fderivWithin_eq e'N]
lemma DifferentiableWithinAt.pullbackWithin {f : E → F} {V : F → F} {s : Set E} {t : Set F} {x : E}
(hV : DifferentiableWithinAt 𝕜 V t (f x))
(hf : ContDiffWithinAt 𝕜 2 f s x) (hf' : (fderivWithin 𝕜 f s x).IsInvertible)
(hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (hst : MapsTo f s t) :
DifferentiableWithinAt 𝕜 (pullbackWithin 𝕜 f V s) s x := by
rcases exists_continuousLinearEquiv_fderivWithin_symm_eq hf hf' hs hx
with ⟨M, -, M_symm_smooth, hM, -⟩
simp only [pullbackWithin_eq]
have : DifferentiableWithinAt 𝕜 (fun y ↦ ((M y).symm : F →L[𝕜] E) (V (f y))) s x := by
apply DifferentiableWithinAt.clm_apply
· exact M_symm_smooth.differentiableWithinAt le_rfl
· exact hV.comp _ (hf.differentiableWithinAt one_le_two) hst
apply this.congr_of_eventuallyEq
· filter_upwards [hM] with y hy using by simp [← hy]
· have hMx : M x = fderivWithin 𝕜 f s x := by apply mem_of_mem_nhdsWithin hx hM
simp [← hMx]
/-- If a `C^2` map has an invertible derivative at a point, then nearby derivatives can be written
as continuous linear equivs, which depend in a `C^1` way on the point, as well as their inverse, and
moreover one can compute the derivative of the inverse. -/
lemma _root_.exists_continuousLinearEquiv_fderiv_symm_eq
{f : E → F} {x : E} (h'f : ContDiffAt 𝕜 2 f x) (hf : (fderiv 𝕜 f x).IsInvertible) :
∃ N : E → (E ≃L[𝕜] F), ContDiffAt 𝕜 1 (fun y ↦ (N y : E →L[𝕜] F)) x
∧ ContDiffAt 𝕜 1 (fun y ↦ ((N y).symm : F →L[𝕜] E)) x
∧ (∀ᶠ y in 𝓝 x, N y = fderiv 𝕜 f y)
∧ ∀ v, fderiv 𝕜 (fun y ↦ ((N y).symm : F →L[𝕜] E)) x v
= - (N x).symm ∘L ((fderiv 𝕜 (fderiv 𝕜 f) x v)) ∘L (N x).symm := by
simp only [← fderivWithin_univ, ← contDiffWithinAt_univ, ← nhdsWithin_univ] at hf h'f ⊢
exact exists_continuousLinearEquiv_fderivWithin_symm_eq h'f hf uniqueDiffOn_univ (mem_univ _)
/-- The Lie bracket commutes with taking pullbacks. This requires the function to have symmetric
second derivative. Version in a complete space. One could also give a version avoiding
completeness but requiring that `f` is a local diffeo. -/
lemma pullbackWithin_lieBracketWithin_of_isSymmSndFDerivWithinAt
{f : E → F} {V W : F → F} {x : E} {t : Set F}
(hf : IsSymmSndFDerivWithinAt 𝕜 f s x) (h'f : ContDiffWithinAt 𝕜 2 f s x)
(hV : DifferentiableWithinAt 𝕜 V t (f x)) (hW : DifferentiableWithinAt 𝕜 W t (f x))
(hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (hst : MapsTo f s t) :
pullbackWithin 𝕜 f (lieBracketWithin 𝕜 V W t) s x
= lieBracketWithin 𝕜 (pullbackWithin 𝕜 f V s) (pullbackWithin 𝕜 f W s) s x := by
by_cases h : (fderivWithin 𝕜 f s x).IsInvertible; swap
· simp [pullbackWithin_eq_of_not_isInvertible h, lieBracketWithin_eq]
rcases exists_continuousLinearEquiv_fderivWithin_symm_eq h'f h hu hx
with ⟨M, -, M_symm_smooth, hM, M_diff⟩
have hMx : M x = fderivWithin 𝕜 f s x := (mem_of_mem_nhdsWithin hx hM :)
have AV : fderivWithin 𝕜 (pullbackWithin 𝕜 f V s) s x =
fderivWithin 𝕜 (fun y ↦ ((M y).symm : F →L[𝕜] E) (V (f y))) s x := by
apply Filter.EventuallyEq.fderivWithin_eq_of_mem _ hx
filter_upwards [hM] with y hy using pullbackWithin_eq_of_fderivWithin_eq hy _
have AW : fderivWithin 𝕜 (pullbackWithin 𝕜 f W s) s x =
fderivWithin 𝕜 (fun y ↦ ((M y).symm : F →L[𝕜] E) (W (f y))) s x := by
apply Filter.EventuallyEq.fderivWithin_eq_of_mem _ hx
filter_upwards [hM] with y hy using pullbackWithin_eq_of_fderivWithin_eq hy _
have Af : DifferentiableWithinAt 𝕜 f s x := h'f.differentiableWithinAt one_le_two
simp only [lieBracketWithin_eq, pullbackWithin_eq_of_fderivWithin_eq hMx, map_sub, AV, AW]
rw [fderivWithin_clm_apply, fderivWithin_clm_apply]
· simp [fderivWithin_comp' x hW Af hst (hu x hx), ← hMx,
fderivWithin_comp' x hV Af hst (hu x hx), M_diff, hf.eq]
· exact hu x hx
· exact M_symm_smooth.differentiableWithinAt le_rfl
· exact hV.comp x Af hst
· exact hu x hx
· exact M_symm_smooth.differentiableWithinAt le_rfl
· exact hW.comp x Af hst
/-- The Lie bracket commutes with taking pullbacks. This requires the function to have symmetric
second derivative. Version in a complete space. One could also give a version avoiding
completeness but requiring that `f` is a local diffeo. Variant where unique differentiability and
the invariance property are only required in a smaller set `u`. -/
lemma pullbackWithin_lieBracketWithin_of_isSymmSndFDerivWithinAt_of_eventuallyEq
{f : E → F} {V W : F → F} {x : E} {t : Set F} {u : Set E}
(hf : IsSymmSndFDerivWithinAt 𝕜 f s x) (h'f : ContDiffWithinAt 𝕜 2 f s x)
(hV : DifferentiableWithinAt 𝕜 V t (f x)) (hW : DifferentiableWithinAt 𝕜 W t (f x))
(hu : UniqueDiffOn 𝕜 u) (hx : x ∈ u) (hst : MapsTo f u t) (hus : u =ᶠ[𝓝 x] s) :
pullbackWithin 𝕜 f (lieBracketWithin 𝕜 V W t) s x
= lieBracketWithin 𝕜 (pullbackWithin 𝕜 f V s) (pullbackWithin 𝕜 f W s) s x := calc
pullbackWithin 𝕜 f (lieBracketWithin 𝕜 V W t) s x
_ = pullbackWithin 𝕜 f (lieBracketWithin 𝕜 V W t) u x := by
simp only [pullbackWithin]
congr 2
exact fderivWithin_congr_set hus.symm
_ = lieBracketWithin 𝕜 (pullbackWithin 𝕜 f V u) (pullbackWithin 𝕜 f W u) u x :=
pullbackWithin_lieBracketWithin_of_isSymmSndFDerivWithinAt
(hf.congr_set hus.symm) (h'f.congr_set hus.symm) hV hW hu hx hst
_ = lieBracketWithin 𝕜 (pullbackWithin 𝕜 f V s) (pullbackWithin 𝕜 f W s) u x := by
apply Filter.EventuallyEq.lieBracketWithin_vectorField_eq_of_mem _ _ hx
· apply nhdsWithin_le_nhds
filter_upwards [fderivWithin_eventually_congr_set (𝕜 := 𝕜) (f := f) hus] with y hy
simp [pullbackWithin, hy]
· apply nhdsWithin_le_nhds
filter_upwards [fderivWithin_eventually_congr_set (𝕜 := 𝕜) (f := f) hus] with y hy
simp [pullbackWithin, hy]
_ = lieBracketWithin 𝕜 (pullbackWithin 𝕜 f V s) (pullbackWithin 𝕜 f W s) s x :=
lieBracketWithin_congr_set hus
/-- The Lie bracket commutes with taking pullbacks. This requires the function to have symmetric
second derivative. Version in a complete space. One could also give a version avoiding
completeness but requiring that `f` is a local diffeo. -/
lemma pullback_lieBracket_of_isSymmSndFDerivAt {f : E → F} {V W : F → F} {x : E}
(hf : IsSymmSndFDerivAt 𝕜 f x) (h'f : ContDiffAt 𝕜 2 f x)
(hV : DifferentiableAt 𝕜 V (f x)) (hW : DifferentiableAt 𝕜 W (f x)) :
pullback 𝕜 f (lieBracket 𝕜 V W) x = lieBracket 𝕜 (pullback 𝕜 f V) (pullback 𝕜 f W) x := by
simp only [← lieBracketWithin_univ, ← pullbackWithin_univ, ← isSymmSndFDerivWithinAt_univ,
← differentiableWithinAt_univ] at hf h'f hV hW ⊢
exact pullbackWithin_lieBracketWithin_of_isSymmSndFDerivWithinAt hf h'f hV hW uniqueDiffOn_univ
(mem_univ _) (mapsTo_univ _ _)
/-- The Lie bracket commutes with taking pullbacks. This requires the function to have symmetric
second derivative. Version in a complete space. One could also give a version avoiding
completeness but requiring that `f` is a local diffeo. -/
lemma pullbackWithin_lieBracketWithin
{f : E → F} {V W : F → F} {x : E} {t : Set F} (hn : minSmoothness 𝕜 2 ≤ n)
(h'f : ContDiffWithinAt 𝕜 n f s x)
(hV : DifferentiableWithinAt 𝕜 V t (f x)) (hW : DifferentiableWithinAt 𝕜 W t (f x))
(hu : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (h'x : x ∈ closure (interior s)) (hst : MapsTo f s t) :
pullbackWithin 𝕜 f (lieBracketWithin 𝕜 V W t) s x
= lieBracketWithin 𝕜 (pullbackWithin 𝕜 f V s) (pullbackWithin 𝕜 f W s) s x :=
pullbackWithin_lieBracketWithin_of_isSymmSndFDerivWithinAt
(h'f.isSymmSndFDerivWithinAt hn hu h'x hx) (h'f.of_le (le_minSmoothness.trans hn)) hV hW hu hx hst
/-- The Lie bracket commutes with taking pullbacks. One could also give a version avoiding
completeness but requiring that `f` is a local diffeo. -/
lemma pullback_lieBracket (hn : minSmoothness 𝕜 2 ≤ n)
{f : E → F} {V W : F → F} {x : E} (h'f : ContDiffAt 𝕜 n f x)
(hV : DifferentiableAt 𝕜 V (f x)) (hW : DifferentiableAt 𝕜 W (f x)) :
pullback 𝕜 f (lieBracket 𝕜 V W) x = lieBracket 𝕜 (pullback 𝕜 f V) (pullback 𝕜 f W) x :=
pullback_lieBracket_of_isSymmSndFDerivAt (h'f.isSymmSndFDerivAt hn)
(h'f.of_le (le_minSmoothness.trans hn)) hV hW
end VectorField
|
Fold.lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Sean Leather
-/
import Mathlib.Algebra.Group.Opposite
import Mathlib.Algebra.FreeMonoid.Basic
import Mathlib.Control.Traversable.Instances
import Mathlib.Control.Traversable.Lemmas
import Mathlib.CategoryTheory.Endomorphism
import Mathlib.CategoryTheory.Types
import Mathlib.CategoryTheory.Category.KleisliCat
import Mathlib.Tactic.AdaptationNote
/-!
# List folds generalized to `Traversable`
Informally, we can think of `foldl` as a special case of `traverse` where we do not care about the
reconstructed data structure and, in a state monad, we care about the final state.
The obvious way to define `foldl` would be to use the state monad but it
is nicer to reason about a more abstract interface with `foldMap` as a
primitive and `foldMap_hom` as a defining property.
```
def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω := ...
lemma foldMap_hom (α β) [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) :
f (foldMap g x) = foldMap (f ∘ g) x :=
...
```
`foldMap` uses a monoid ω to accumulate a value for every element of
a data structure and `foldMap_hom` uses a monoid homomorphism to
substitute the monoid used by `foldMap`. The two are sufficient to
define `foldl`, `foldr` and `toList`. `toList` permits the
formulation of specifications in terms of operations on lists.
Each fold function can be defined using a specialized
monoid. `toList` uses a free monoid represented as a list with
concatenation while `foldl` uses endofunctions together with function
composition.
The definition through monoids uses `traverse` together with the
applicative functor `const m` (where `m` is the monoid). As an
implementation, `const` guarantees that no resource is spent on
reconstructing the structure during traversal.
A special class could be defined for `foldable`, similarly to Haskell,
but the author cannot think of instances of `foldable` that are not also
`Traversable`.
-/
universe u v
open ULift CategoryTheory MulOpposite
namespace Monoid
variable {m : Type u → Type u} [Monad m]
variable {α β : Type u}
/-- For a list, foldl f x [y₀,y₁] reduces as follows:
```
calc foldl f x [y₀,y₁]
= foldl f (f x y₀) [y₁] : rfl
... = foldl f (f (f x y₀) y₁) [] : rfl
... = f (f x y₀) y₁ : rfl
```
with
```
f : α → β → α
x : α
[y₀,y₁] : List β
```
We can view the above as a composition of functions:
```
... = f (f x y₀) y₁ : rfl
... = flip f y₁ (flip f y₀ x) : rfl
... = (flip f y₁ ∘ flip f y₀) x : rfl
```
We can use traverse and const to construct this composition:
```
calc const.run (traverse (fun y ↦ const.mk' (flip f y)) [y₀,y₁]) x
= const.run ((::) <$> const.mk' (flip f y₀) <*>
traverse (fun y ↦ const.mk' (flip f y)) [y₁]) x
... = const.run ((::) <$> const.mk' (flip f y₀) <*>
( (::) <$> const.mk' (flip f y₁) <*> traverse (fun y ↦ const.mk' (flip f y)) [] )) x
... = const.run ((::) <$> const.mk' (flip f y₀) <*>
( (::) <$> const.mk' (flip f y₁) <*> pure [] )) x
... = const.run ( ((::) <$> const.mk' (flip f y₁) <*> pure []) ∘
((::) <$> const.mk' (flip f y₀)) ) x
... = const.run ( const.mk' (flip f y₁) ∘ const.mk' (flip f y₀) ) x
... = const.run ( flip f y₁ ∘ flip f y₀ ) x
... = f (f x y₀) y₁
```
And this is how `const` turns a monoid into an applicative functor and
how the monoid of endofunctions define `Foldl`.
-/
abbrev Foldl (α : Type u) : Type u :=
(End α)ᵐᵒᵖ
def Foldl.mk (f : α → α) : Foldl α :=
op f
def Foldl.get (x : Foldl α) : α → α :=
unop x
@[simps]
def Foldl.ofFreeMonoid (f : β → α → β) : FreeMonoid α →* Monoid.Foldl β where
toFun xs := op <| flip (List.foldl f) (FreeMonoid.toList xs)
map_one' := rfl
map_mul' := by
intros
simp only [FreeMonoid.toList_mul, List.foldl_append, Function.flip_def]
rfl
abbrev Foldr (α : Type u) : Type u :=
End α
def Foldr.mk (f : α → α) : Foldr α :=
f
def Foldr.get (x : Foldr α) : α → α :=
x
@[simps]
def Foldr.ofFreeMonoid (f : α → β → β) : FreeMonoid α →* Monoid.Foldr β where
toFun xs := flip (List.foldr f) (FreeMonoid.toList xs)
map_one' := rfl
map_mul' _ _ := funext fun _ => List.foldr_append
abbrev foldlM (m : Type u → Type u) [Monad m] (α : Type u) : Type u :=
MulOpposite <| End <| KleisliCat.mk m α
def foldlM.mk (f : α → m α) : foldlM m α :=
op f
def foldlM.get (x : foldlM m α) : α → m α :=
unop x
@[simps]
def foldlM.ofFreeMonoid [LawfulMonad m] (f : β → α → m β) : FreeMonoid α →* Monoid.foldlM m β where
toFun xs := op <| flip (List.foldlM f) (FreeMonoid.toList xs)
map_one' := rfl
map_mul' := by intros; apply unop_injective; funext; apply List.foldlM_append
abbrev foldrM (m : Type u → Type u) [Monad m] (α : Type u) : Type u :=
End <| KleisliCat.mk m α
def foldrM.mk (f : α → m α) : foldrM m α :=
f
def foldrM.get (x : foldrM m α) : α → m α :=
x
@[simps]
def foldrM.ofFreeMonoid [LawfulMonad m] (f : α → β → m β) : FreeMonoid α →* Monoid.foldrM m β where
toFun xs := flip (List.foldrM f) (FreeMonoid.toList xs)
map_one' := rfl
map_mul' := by intros; funext; apply List.foldrM_append
end Monoid
namespace Traversable
open Monoid Functor
section Defs
variable {α β : Type u} {t : Type u → Type u} [Traversable t]
def foldMap {α ω} [One ω] [Mul ω] (f : α → ω) : t α → ω :=
traverse (Const.mk' ∘ f)
def foldl (f : α → β → α) (x : α) (xs : t β) : α :=
(foldMap (Foldl.mk ∘ flip f) xs).get x
def foldr (f : α → β → β) (x : β) (xs : t α) : β :=
(foldMap (Foldr.mk ∘ f) xs).get x
/-- Conceptually, `toList` collects all the elements of a collection
in a list. This idea is formalized by
`lemma toList_spec (x : t α) : toList x = foldMap FreeMonoid.mk x`.
The definition of `toList` is based on `foldl` and `List.cons` for
speed. It is faster than using `foldMap FreeMonoid.mk` because, by
using `foldl` and `List.cons`, each insertion is done in constant
time. As a consequence, `toList` performs in linear.
On the other hand, `foldMap FreeMonoid.mk` creates a singleton list
around each element and concatenates all the resulting lists. In
`xs ++ ys`, concatenation takes a time proportional to `length xs`. Since
the order in which concatenation is evaluated is unspecified, nothing
prevents each element of the traversable to be appended at the end
`xs ++ [x]` which would yield a `O(n²)` run time. -/
def toList : t α → List α :=
List.reverse ∘ foldl (flip List.cons) []
def length (xs : t α) : ℕ :=
down <| foldl (fun l _ => up <| l.down + 1) (up 0) xs
variable {m : Type u → Type u} [Monad m]
def foldlm (f : α → β → m α) (x : α) (xs : t β) : m α :=
(foldMap (foldlM.mk ∘ flip f) xs).get x
def foldrm (f : α → β → m β) (x : β) (xs : t α) : m β :=
(foldMap (foldrM.mk ∘ f) xs).get x
end Defs
section ApplicativeTransformation
variable {α β γ : Type u}
open Function hiding const
def mapFold [Monoid α] [Monoid β] (f : α →* β) : ApplicativeTransformation (Const α) (Const β) where
app _ := f
preserves_seq' := by intros; simp only [Seq.seq, map_mul]
preserves_pure' := by intros; simp only [map_one, pure]
theorem Free.map_eq_map (f : α → β) (xs : List α) :
f <$> xs = (FreeMonoid.toList (FreeMonoid.map f (FreeMonoid.ofList xs))) :=
rfl
theorem foldl.unop_ofFreeMonoid (f : β → α → β) (xs : FreeMonoid α) (a : β) :
unop (Foldl.ofFreeMonoid f xs) a = List.foldl f a (FreeMonoid.toList xs) :=
rfl
variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t]
open LawfulTraversable
theorem foldMap_hom [Monoid α] [Monoid β] (f : α →* β) (g : γ → α) (x : t γ) :
f (foldMap g x) = foldMap (f ∘ g) x :=
calc
f (foldMap g x) = f (traverse (Const.mk' ∘ g) x) := rfl
_ = (mapFold f).app _ (traverse (Const.mk' ∘ g) x) := rfl
_ = traverse ((mapFold f).app _ ∘ Const.mk' ∘ g) x := naturality (mapFold f) _ _
_ = foldMap (f ∘ g) x := rfl
theorem foldMap_hom_free [Monoid β] (f : FreeMonoid α →* β) (x : t α) :
f (foldMap FreeMonoid.of x) = foldMap (f ∘ FreeMonoid.of) x :=
foldMap_hom f _ x
end ApplicativeTransformation
section Equalities
open LawfulTraversable
open List (cons)
variable {α β γ : Type u}
variable {t : Type u → Type u} [Traversable t] [LawfulTraversable t]
@[simp]
theorem foldl.ofFreeMonoid_comp_of (f : α → β → α) :
Foldl.ofFreeMonoid f ∘ FreeMonoid.of = Foldl.mk ∘ flip f :=
rfl
@[simp]
theorem foldr.ofFreeMonoid_comp_of (f : β → α → α) :
Foldr.ofFreeMonoid f ∘ FreeMonoid.of = Foldr.mk ∘ f :=
rfl
@[simp]
theorem foldlm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : α → β → m α) :
foldlM.ofFreeMonoid f ∘ FreeMonoid.of = foldlM.mk ∘ flip f := by
ext1 x
simp only [foldlM.ofFreeMonoid, Function.flip_def, MonoidHom.coe_mk, OneHom.coe_mk,
Function.comp_apply, FreeMonoid.toList_of, List.foldlM_cons, List.foldlM_nil, bind_pure,
foldlM.mk, op_inj]
rfl
@[simp]
theorem foldrm.ofFreeMonoid_comp_of {m} [Monad m] [LawfulMonad m] (f : β → α → m α) :
foldrM.ofFreeMonoid f ∘ FreeMonoid.of = foldrM.mk ∘ f := by
ext
simp [(· ∘ ·), foldrM.ofFreeMonoid, foldrM.mk, Function.flip_def]
theorem toList_spec (xs : t α) : toList xs = FreeMonoid.toList (foldMap FreeMonoid.of xs) :=
Eq.symm <|
calc
FreeMonoid.toList (foldMap FreeMonoid.of xs) =
FreeMonoid.toList (foldMap FreeMonoid.of xs).reverse.reverse := by
simp only [FreeMonoid.reverse_reverse]
_ = (List.foldr cons [] (foldMap FreeMonoid.of xs).toList.reverse).reverse := by simp
_ = (unop (Foldl.ofFreeMonoid (flip cons) (foldMap FreeMonoid.of xs)) []).reverse := by
simp [Function.flip_def, List.foldr_reverse, Foldl.ofFreeMonoid, unop_op]
_ = toList xs := by
rw [foldMap_hom_free (Foldl.ofFreeMonoid (flip <| @cons α))]
simp only [toList, foldl, Foldl.get, foldl.ofFreeMonoid_comp_of,
Function.comp_apply]
theorem foldMap_map [Monoid γ] (f : α → β) (g : β → γ) (xs : t α) :
foldMap g (f <$> xs) = foldMap (g ∘ f) xs := by
simp only [foldMap, traverse_map, Function.comp_def]
theorem foldl_toList (f : α → β → α) (xs : t β) (x : α) :
foldl f x xs = List.foldl f x (toList xs) := by
rw [← FreeMonoid.toList_ofList (toList xs), ← foldl.unop_ofFreeMonoid]
simp only [foldl, toList_spec, foldMap_hom_free, foldl.ofFreeMonoid_comp_of, Foldl.get,
FreeMonoid.ofList_toList]
theorem foldr_toList (f : α → β → β) (xs : t α) (x : β) :
foldr f x xs = List.foldr f x (toList xs) := by
change _ = Foldr.ofFreeMonoid _ (FreeMonoid.ofList <| toList xs) _
rw [toList_spec, foldr, Foldr.get, FreeMonoid.ofList_toList, foldMap_hom_free,
foldr.ofFreeMonoid_comp_of]
theorem toList_map (f : α → β) (xs : t α) : toList (f <$> xs) = f <$> toList xs := by
simp only [toList_spec, Free.map_eq_map, foldMap_hom, foldMap_map, FreeMonoid.ofList_toList,
FreeMonoid.map_of, Function.comp_def]
@[simp]
theorem foldl_map (g : β → γ) (f : α → γ → α) (a : α) (l : t β) :
foldl f a (g <$> l) = foldl (fun x y => f x (g y)) a l := by
simp only [foldl, foldMap_map, Function.comp_def, Function.flip_def]
@[simp]
theorem foldr_map (g : β → γ) (f : γ → α → α) (a : α) (l : t β) :
foldr f a (g <$> l) = foldr (f ∘ g) a l := by
simp only [foldr, foldMap_map, Function.comp_def]
@[simp]
theorem toList_eq_self {xs : List α} : toList xs = xs := by
simp only [toList_spec, foldMap, traverse]
induction xs with
| nil => rfl
| cons _ _ ih => (conv_rhs => rw [← ih]); rfl
theorem length_toList {xs : t α} : length xs = List.length (toList xs) := by
unfold length
rw [foldl_toList]
generalize toList xs = ys
rw [← Nat.add_zero ys.length]
generalize 0 = n
induction ys generalizing n with
| nil => simp
| cons _ _ ih => simp +arith [ih]
variable {m : Type u → Type u} [Monad m] [LawfulMonad m]
theorem foldlm_toList {f : α → β → m α} {x : α} {xs : t β} :
foldlm f x xs = List.foldlM f x (toList xs) :=
calc foldlm f x xs
_ = unop (foldlM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs)) x := by
simp only [foldlm, toList_spec, foldMap_hom_free (foldlM.ofFreeMonoid f),
foldlm.ofFreeMonoid_comp_of, foldlM.get, FreeMonoid.ofList_toList]
_ = List.foldlM f x (toList xs) := by simp [foldlM.ofFreeMonoid, unop_op, flip]
theorem foldrm_toList (f : α → β → m β) (x : β) (xs : t α) :
foldrm f x xs = List.foldrM f x (toList xs) := by
change _ = foldrM.ofFreeMonoid f (FreeMonoid.ofList <| toList xs) x
simp only [foldrm, toList_spec, foldMap_hom_free (foldrM.ofFreeMonoid f),
foldrm.ofFreeMonoid_comp_of, foldrM.get, FreeMonoid.ofList_toList]
@[simp]
theorem foldlm_map (g : β → γ) (f : α → γ → m α) (a : α) (l : t β) :
foldlm f a (g <$> l) = foldlm (fun x y => f x (g y)) a l := by
simp only [foldlm, foldMap_map, Function.comp_def, Function.flip_def]
@[simp]
theorem foldrm_map (g : β → γ) (f : γ → α → m α) (a : α) (l : t β) :
foldrm f a (g <$> l) = foldrm (f ∘ g) a l := by
simp only [foldrm, foldMap_map, Function.comp_def]
end Equalities
end Traversable
|
ExtendFrom.lean
|
/-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Anatole Dedecker
-/
import Mathlib.Topology.Separation.Regular
/-!
# Extending a function from a subset
The main definition of this file is `extendFrom A f` where `f : X → Y`
and `A : Set X`. This defines a new function `g : X → Y` which maps any
`x₀ : X` to the limit of `f` as `x` tends to `x₀`, if such a limit exists.
This is analogous to the way `IsDenseInducing.extend` "extends" a function
`f : X → Z` to a function `g : Y → Z` along a dense inducing `i : X → Y`.
The main theorem we prove about this definition is `continuousOn_extendFrom`
which states that, for `extendFrom A f` to be continuous on a set `B ⊆ closure A`,
it suffices that `f` converges within `A` at any point of `B`, provided that
`f` is a function to a T₃ space.
-/
noncomputable section
open Topology
open Filter Set
variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y]
/-- Extend a function from a set `A`. The resulting function `g` is such that
at any `x₀`, if `f` converges to some `y` as `x` tends to `x₀` within `A`,
then `g x₀` is defined to be one of these `y`. Else, `g x₀` could be anything. -/
def extendFrom (A : Set X) (f : X → Y) : X → Y :=
fun x ↦ @limUnder _ _ _ ⟨f x⟩ (𝓝[A] x) f
/-- If `f` converges to some `y` as `x` tends to `x₀` within `A`,
then `f` tends to `extendFrom A f x` as `x` tends to `x₀`. -/
theorem tendsto_extendFrom {A : Set X} {f : X → Y} {x : X} (h : ∃ y, Tendsto f (𝓝[A] x) (𝓝 y)) :
Tendsto f (𝓝[A] x) (𝓝 <| extendFrom A f x) :=
tendsto_nhds_limUnder h
theorem extendFrom_eq [T2Space Y] {A : Set X} {f : X → Y} {x : X} {y : Y} (hx : x ∈ closure A)
(hf : Tendsto f (𝓝[A] x) (𝓝 y)) : extendFrom A f x = y :=
haveI := mem_closure_iff_nhdsWithin_neBot.mp hx
tendsto_nhds_unique (tendsto_nhds_limUnder ⟨y, hf⟩) hf
theorem extendFrom_extends [T2Space Y] {f : X → Y} {A : Set X} (hf : ContinuousOn f A) :
∀ x ∈ A, extendFrom A f x = f x :=
fun x x_in ↦ extendFrom_eq (subset_closure x_in) (hf x x_in)
/-- If `f` is a function to a T₃ space `Y` which has a limit within `A` at any
point of a set `B ⊆ closure A`, then `extendFrom A f` is continuous on `B`. -/
theorem continuousOn_extendFrom [RegularSpace Y] {f : X → Y} {A B : Set X} (hB : B ⊆ closure A)
(hf : ∀ x ∈ B, ∃ y, Tendsto f (𝓝[A] x) (𝓝 y)) : ContinuousOn (extendFrom A f) B := by
set φ := extendFrom A f
intro x x_in
suffices ∀ V' ∈ 𝓝 (φ x), IsClosed V' → φ ⁻¹' V' ∈ 𝓝[B] x by
simpa [ContinuousWithinAt, (closed_nhds_basis (φ x)).tendsto_right_iff]
intro V' V'_in V'_closed
obtain ⟨V, V_in, V_op, hV⟩ : ∃ V ∈ 𝓝 x, IsOpen V ∧ V ∩ A ⊆ f ⁻¹' V' := by
have := tendsto_extendFrom (hf x x_in)
rcases (nhdsWithin_basis_open x A).tendsto_left_iff.mp this V' V'_in with ⟨V, ⟨hxV, V_op⟩, hV⟩
exact ⟨V, IsOpen.mem_nhds V_op hxV, V_op, hV⟩
suffices ∀ y ∈ V ∩ B, φ y ∈ V' from
mem_of_superset (inter_mem_inf V_in <| mem_principal_self B) this
rintro y ⟨hyV, hyB⟩
haveI := mem_closure_iff_nhdsWithin_neBot.mp (hB hyB)
have limy : Tendsto f (𝓝[A] y) (𝓝 <| φ y) := tendsto_extendFrom (hf y hyB)
have hVy : V ∈ 𝓝 y := IsOpen.mem_nhds V_op hyV
have : V ∩ A ∈ 𝓝[A] y := by simpa only [inter_comm] using inter_mem_nhdsWithin A hVy
exact V'_closed.mem_of_tendsto limy (mem_of_superset this hV)
/-- If a function `f` to a T₃ space `Y` has a limit within a
dense set `A` for any `x`, then `extendFrom A f` is continuous. -/
theorem continuous_extendFrom [RegularSpace Y] {f : X → Y} {A : Set X} (hA : Dense A)
(hf : ∀ x, ∃ y, Tendsto f (𝓝[A] x) (𝓝 y)) : Continuous (extendFrom A f) := by
rw [← continuousOn_univ]
exact continuousOn_extendFrom (fun x _ ↦ hA x) (by simpa using hf)
|
ValuedCSP.lean
|
import Mathlib.Algebra.Order.AbsoluteValue.Basic
import Mathlib.Algebra.Order.Ring.Rat
import Mathlib.Combinatorics.Optimization.ValuedCSP
import Mathlib.Data.Fin.Tuple.Curry
import Mathlib.Data.Fin.VecNotation
import Mathlib.Tactic.Positivity
/-!
# VCSP examples
This file shows two simple examples of General-Valued Constraint Satisfaction Problems (see
[ValuedCSP definition](Mathlib/Combinatorics/Optimization/ValuedCSP.lean)).
The first example is an optimization problem. The second example is a decision problem.
-/
def ValuedCSP.unaryTerm {D C : Type} [AddCommMonoid C] [PartialOrder C] [IsOrderedAddMonoid C]
{Γ : ValuedCSP D C} {ι : Type*} {f : D → C}
(ok : ⟨1, Function.OfArity.uncurry f⟩ ∈ Γ) (i : ι) : Γ.Term ι :=
⟨1, Function.OfArity.uncurry f, ok, ![i]⟩
def ValuedCSP.binaryTerm {D C : Type} [AddCommMonoid C] [PartialOrder C] [IsOrderedAddMonoid C]
{Γ : ValuedCSP D C} {ι : Type*} {f : D → D → C}
(ok : ⟨2, Function.OfArity.uncurry f⟩ ∈ Γ) (i j : ι) : Γ.Term ι :=
⟨2, Function.OfArity.uncurry f, ok, ![i, j]⟩
-- ## Example: minimize `|x| + |y|` where `x` and `y` are rational numbers
private def absRat : (Fin 1 → ℚ) → ℚ :=
Function.OfArity.uncurry (@abs ℚ Rat.instLattice Rat.addGroup)
private def exampleAbs : Σ (n : ℕ), (Fin n → ℚ) → ℚ := ⟨1, absRat⟩
private def exampleFiniteValuedCSP : ValuedCSP ℚ ℚ := {exampleAbs}
private lemma abs_in : ⟨1, absRat⟩ ∈ exampleFiniteValuedCSP := rfl
private def exampleFiniteValuedInstance : exampleFiniteValuedCSP.Instance (Fin 2) :=
{ValuedCSP.unaryTerm abs_in 0, ValuedCSP.unaryTerm abs_in 1}
example : exampleFiniteValuedInstance.IsOptimumSolution ![(0 : ℚ), (0 : ℚ)] := by
intro s
convert_to 0 ≤ exampleFiniteValuedInstance.evalSolution s
· simp [exampleFiniteValuedInstance, ValuedCSP.Instance.evalSolution]
exact Rat.zero_add 0
rw [ValuedCSP.Instance.evalSolution, exampleFiniteValuedInstance]
convert_to 0 ≤ |s 0| + |s 1|
· simp [ValuedCSP.unaryTerm, ValuedCSP.Term.evalSolution, Function.OfArity.uncurry]
rfl
positivity
-- ## Example: B ≠ A ≠ C ≠ D ≠ B ≠ C with three available labels (i.e., 3-coloring of K₄⁻)
private def Bool_add_le_add_left (a b : Bool) :
(a ≤ b) → ∀ (c : Bool), ((c || a) ≤ (c || b)) := by
intro hab c
cases a <;> cases b <;> cases c <;> trivial
-- For simpler implementation, we treat `false` as "satisfied" and `true` as "wrong" here.
private instance crispCodomainZero : Zero Bool where zero := false
private instance crispCodomainAdd : Add Bool where add a b := a || b
private instance crispCodomainAddCommMonoid : AddCommMonoid Bool where
add_assoc := Bool.or_assoc
zero_add (_ : Bool) := rfl
add_zero := Bool.or_false
add_comm := Bool.or_comm
nsmul := nsmulRec
private instance crispCodomain : IsOrderedAddMonoid Bool where
add_le_add_left := Bool_add_le_add_left
private def beqBool : (Fin 2 → Fin 3) → Bool :=
Function.OfArity.uncurry (fun (a b : Fin 3) => a == b)
private def exampleEquality : Σ (n : ℕ), (Fin n → Fin 3) → Bool := ⟨2, beqBool⟩
private def exampleCrispCSP : ValuedCSP (Fin 3) Bool := {exampleEquality}
private lemma beqBool_mem : ⟨2, beqBool⟩ ∈ exampleCrispCSP := rfl
private def exampleTermAB : exampleCrispCSP.Term (Fin 4) :=
ValuedCSP.binaryTerm beqBool_mem 0 1
private def exampleTermBC : exampleCrispCSP.Term (Fin 4) :=
ValuedCSP.binaryTerm beqBool_mem 1 2
private def exampleTermCA : exampleCrispCSP.Term (Fin 4) :=
ValuedCSP.binaryTerm beqBool_mem 2 0
private def exampleTermBD : exampleCrispCSP.Term (Fin 4) :=
ValuedCSP.binaryTerm beqBool_mem 1 3
private def exampleTermCD : exampleCrispCSP.Term (Fin 4) :=
ValuedCSP.binaryTerm beqBool_mem 2 3
private def exampleCrispCspInstance : exampleCrispCSP.Instance (Fin 4) :=
Multiset.ofList [exampleTermAB, exampleTermBC, exampleTermCA, exampleTermBD, exampleTermCD]
/-
0
/ \
1---2
\ /
0
-/
private def exampleSolutionCorrect0 : Fin 4 → Fin 3 := ![0, 1, 2, 0]
example : exampleCrispCspInstance.IsOptimumSolution exampleSolutionCorrect0 :=
fun _ => Bool.false_le _
/-
1
/ \
2---0
\ /
1
-/
private def exampleSolutionCorrect1 : Fin 4 → Fin 3 := ![1, 2, 0, 1]
example : exampleCrispCspInstance.IsOptimumSolution exampleSolutionCorrect1 :=
fun _ => Bool.false_le _
/-
2
/ \
0---1
\ /
2
-/
private def exampleSolutionCorrect2 : Fin 4 → Fin 3 := ![2, 0, 1, 2]
example : exampleCrispCspInstance.IsOptimumSolution exampleSolutionCorrect2 :=
fun _ => Bool.false_le _
/-
0
/ \
2---1
\ /
0
-/
private def exampleSolutionCorrect3 : Fin 4 → Fin 3 := ![0, 2, 1, 0]
example : exampleCrispCspInstance.IsOptimumSolution exampleSolutionCorrect3 :=
fun _ => Bool.false_le _
/-
1
/ \
0---2
\ /
1
-/
private def exampleSolutionCorrect4 : Fin 4 → Fin 3 := ![1, 0, 2, 1]
example : exampleCrispCspInstance.IsOptimumSolution exampleSolutionCorrect4 :=
fun _ => Bool.false_le _
/-
2
/ \
1---0
\ /
2
-/
private def exampleSolutionCorrect5 : Fin 4 → Fin 3 := ![2, 1, 0, 2]
example : exampleCrispCspInstance.IsOptimumSolution exampleSolutionCorrect5 :=
fun _ => Bool.false_le _
/-
0
/ \
0---0
\ /
0
-/
private def exampleSolutionIncorrect0 : Fin 4 → Fin 3 := ![0, 0, 0, 0]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect0 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
/-
1
/ \
0---0
\ /
0
-/
private def exampleSolutionIncorrect1 : Fin 4 → Fin 3 := ![1, 0, 0, 0]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect1 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
/-
0
/ \
2---0
\ /
0
-/
private def exampleSolutionIncorrect2 : Fin 4 → Fin 3 := ![0, 2, 0, 0]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect2 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
/-
0
/ \
1---0
\ /
2
-/
private def exampleSolutionIncorrect3 : Fin 4 → Fin 3 := ![0, 1, 0, 2]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect3 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
/-
2
/ \
2---0
\ /
1
-/
private def exampleSolutionIncorrect4 : Fin 4 → Fin 3 := ![2, 2, 0, 1]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect4 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
/-
0
/ \
1---2
\ /
1
-/
private def exampleSolutionIncorrect5 : Fin 4 → Fin 3 := ![0, 1, 2, 1]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect5 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
/-
1
/ \
0---0
\ /
1
-/
private def exampleSolutionIncorrect6 : Fin 4 → Fin 3 := ![1, 0, 0, 1]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect6 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
/-
2
/ \
2---0
\ /
2
-/
private def exampleSolutionIncorrect7 : Fin 4 → Fin 3 := ![2, 2, 0, 2]
example : ¬exampleCrispCspInstance.IsOptimumSolution exampleSolutionIncorrect7 := by
unfold ValuedCSP.Instance.IsOptimumSolution
push_neg
use exampleSolutionCorrect0
rfl
|
Subobject.lean
|
/-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Subobject.Limits
import Mathlib.CategoryTheory.Abelian.Basic
/-!
# Equivalence between subobjects and quotients in an abelian category
-/
open CategoryTheory CategoryTheory.Limits Opposite
universe w v u
noncomputable section
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C]
/-- In an abelian category, the subobjects and quotient objects of an object `X` are
order-isomorphic via taking kernels and cokernels.
Implemented here using subobjects in the opposite category,
since mathlib does not have a notion of quotient objects at the time of writing. -/
@[simps!]
def subobjectIsoSubobjectOp [Abelian C] (X : C) : Subobject X ≃o (Subobject (op X))ᵒᵈ := by
refine OrderIso.ofHomInv (cokernelOrderHom X) (kernelOrderHom X) ?_ ?_
· change (cokernelOrderHom X).comp (kernelOrderHom X) = _
refine OrderHom.ext _ _ (funext (Subobject.ind _ ?_))
intro A f hf
dsimp only [OrderHom.comp_coe, Function.comp_apply, kernelOrderHom_coe, Subobject.lift_mk,
cokernelOrderHom_coe, OrderHom.id_coe, id]
refine Subobject.mk_eq_mk_of_comm _ _
⟨?_, ?_, Quiver.Hom.unop_inj ?_, Quiver.Hom.unop_inj ?_⟩ ?_
· exact (Abelian.epiDesc f.unop _ (cokernel.condition (kernel.ι f.unop))).op
· exact (cokernel.desc _ _ (kernel.condition f.unop)).op
· rw [← cancel_epi (cokernel.π (kernel.ι f.unop))]
simp only [unop_comp, Quiver.Hom.unop_op, unop_id_op, cokernel.π_desc_assoc,
comp_epiDesc, Category.comp_id]
· simp only [← cancel_epi f.unop, unop_comp, Quiver.Hom.unop_op, unop_id, comp_epiDesc_assoc,
cokernel.π_desc, Category.comp_id]
· exact Quiver.Hom.unop_inj (by simp only [unop_comp, Quiver.Hom.unop_op, comp_epiDesc])
· change (kernelOrderHom X).comp (cokernelOrderHom X) = _
refine OrderHom.ext _ _ (funext (Subobject.ind _ ?_))
intro A f hf
dsimp only [OrderHom.comp_coe, Function.comp_apply, cokernelOrderHom_coe, Subobject.lift_mk,
kernelOrderHom_coe, OrderHom.id_coe, id, unop_op, Quiver.Hom.unop_op]
refine Subobject.mk_eq_mk_of_comm _ _ ⟨?_, ?_, ?_, ?_⟩ ?_
· exact Abelian.monoLift f _ (kernel.condition (cokernel.π f))
· exact kernel.lift _ _ (cokernel.condition f)
· simp only [← cancel_mono (kernel.ι (cokernel.π f)), Category.assoc, image.fac, monoLift_comp,
Category.id_comp]
· simp only [← cancel_mono f, Category.assoc, monoLift_comp, image.fac, Category.id_comp]
· simp only [monoLift_comp]
/-- A well-powered abelian category is also well-copowered. -/
instance wellPowered_opposite [Abelian C] [LocallySmall.{w} C] [WellPowered.{w} C] :
WellPowered.{w} Cᵒᵖ where
subobject_small X :=
(small_congr (subobjectIsoSubobjectOp (unop X)).toEquiv).1 inferInstance
end CategoryTheory.Abelian
|
Pointwise.lean
|
/-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Star.Basic
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Data.Set.Lattice.Image
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Pointwise star operation on sets
This file defines the star operation pointwise on sets and provides the basic API.
Besides basic facts about how the star operation acts on sets (e.g., `(s ∩ t)⋆ = s⋆ ∩ t⋆`),
if `s t : Set α`, then under suitable assumption on `α`, it is shown
* `(s + t)⋆ = s⋆ + t⋆`
* `(s * t)⋆ = t⋆ + s⋆`
* `(s⁻¹)⋆ = (s⋆)⁻¹`
-/
namespace Set
open Pointwise
local postfix:max "⋆" => star
variable {α : Type*} {s t : Set α} {a : α}
/-- The set `(star s : Set α)` is defined as `{x | star x ∈ s}` in the locale `Pointwise`.
In the usual case where `star` is involutive, it is equal to `{star s | x ∈ s}`, see
`Set.image_star`. -/
protected def star [Star α] : Star (Set α) := ⟨preimage Star.star⟩
scoped[Pointwise] attribute [instance] Set.star
@[simp]
theorem star_empty [Star α] : (∅ : Set α)⋆ = ∅ := rfl
@[simp]
theorem star_univ [Star α] : (univ : Set α)⋆ = univ := rfl
@[simp]
theorem nonempty_star [InvolutiveStar α] {s : Set α} : s⋆.Nonempty ↔ s.Nonempty :=
star_involutive.surjective.nonempty_preimage
theorem Nonempty.star [InvolutiveStar α] {s : Set α} (h : s.Nonempty) : s⋆.Nonempty :=
nonempty_star.2 h
@[simp]
theorem mem_star [Star α] : a ∈ s⋆ ↔ a⋆ ∈ s := Iff.rfl
theorem star_mem_star [InvolutiveStar α] : a⋆ ∈ s⋆ ↔ a ∈ s := by simp only [mem_star, star_star]
@[simp]
theorem star_preimage [Star α] : Star.star ⁻¹' s = s⋆ := rfl
@[simp]
theorem image_star [InvolutiveStar α] : Star.star '' s = s⋆ := by
simp only [← star_preimage]
rw [image_eq_preimage_of_inverse] <;> intro <;> simp only [star_star]
@[simp]
theorem inter_star [Star α] : (s ∩ t)⋆ = s⋆ ∩ t⋆ := preimage_inter
@[simp]
theorem union_star [Star α] : (s ∪ t)⋆ = s⋆ ∪ t⋆ := preimage_union
@[simp]
theorem iInter_star {ι : Sort*} [Star α] (s : ι → Set α) : (⋂ i, s i)⋆ = ⋂ i, (s i)⋆ :=
preimage_iInter
@[simp]
theorem iUnion_star {ι : Sort*} [Star α] (s : ι → Set α) : (⋃ i, s i)⋆ = ⋃ i, (s i)⋆ :=
preimage_iUnion
@[simp]
theorem compl_star [Star α] : sᶜ⋆ = s⋆ᶜ := preimage_compl
@[simp]
instance [InvolutiveStar α] : InvolutiveStar (Set α) where
star := Star.star
star_involutive s := by simp only [← star_preimage, preimage_preimage, star_star, preimage_id']
@[simp]
theorem star_subset_star [InvolutiveStar α] {s t : Set α} : s⋆ ⊆ t⋆ ↔ s ⊆ t :=
Equiv.star.surjective.preimage_subset_preimage_iff
theorem star_subset [InvolutiveStar α] {s t : Set α} : s⋆ ⊆ t ↔ s ⊆ t⋆ := by
rw [← star_subset_star, star_star]
theorem Finite.star [InvolutiveStar α] {s : Set α} (hs : s.Finite) : s⋆.Finite :=
hs.preimage star_injective.injOn
theorem star_singleton {β : Type*} [InvolutiveStar β] (x : β) : ({x} : Set β)⋆ = {x⋆} := by
ext1 y
rw [mem_star, mem_singleton_iff, mem_singleton_iff, star_eq_iff_star_eq, eq_comm]
protected theorem star_mul [Mul α] [StarMul α] (s t : Set α) : (s * t)⋆ = t⋆ * s⋆ := by
simp_rw [← image_star, ← image2_mul, image_image2, image2_image_left, image2_image_right,
star_mul, image2_swap _ s t]
protected theorem star_add [AddMonoid α] [StarAddMonoid α] (s t : Set α) : (s + t)⋆ = s⋆ + t⋆ := by
simp_rw [← image_star, ← image2_add, image_image2, image2_image_left, image2_image_right,
star_add]
@[simp]
instance [Star α] [TrivialStar α] : TrivialStar (Set α) where
star_trivial s := by
rw [← star_preimage]
ext1
simp [star_trivial]
protected theorem star_inv [Group α] [StarMul α] (s : Set α) : s⁻¹⋆ = s⋆⁻¹ := by
ext
simp only [mem_star, mem_inv, star_inv]
protected theorem star_inv' [GroupWithZero α] [StarMul α] (s : Set α) : s⁻¹⋆ = s⋆⁻¹ := by
ext
simp only [mem_star, mem_inv, star_inv₀]
end Set
@[simp]
lemma StarMemClass.star_coe_eq {S α : Type*} [InvolutiveStar α] [SetLike S α]
[StarMemClass S α] (s : S) : star (s : Set α) = s := by
ext x
simp only [Set.mem_star, SetLike.mem_coe]
exact ⟨by simpa only [star_star] using star_mem (s := s) (r := star x), star_mem⟩
|
ssrmatching.v
|
From Corelib Require Export ssrmatching.
|
CircleMap.lean
|
/-
Copyright (c) 2025 Fabrizio Barroero. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Fabrizio Barroero, Christopher Hoskin
-/
import Mathlib.Analysis.SpecialFunctions.Complex.Log
import Mathlib.Order.Interval.Set.Defs
/-!
# circleMap
This file defines the circle map $θ ↦ c + R e^{θi}$, a parametrization of a circle.
## Main definitions
* `circleMap c R`: the exponential map $θ ↦ c + R e^{θi}$.
## Tags
-/
noncomputable section circleMap
open Complex Function Metric Real
/-- The exponential map $θ ↦ c + R e^{θi}$. The range of this map is the circle in `ℂ` with center
`c` and radius `|R|`. -/
def circleMap (c : ℂ) (R : ℝ) : ℝ → ℂ := fun θ => c + R * exp (θ * I)
@[simp]
theorem circleMap_sub_center (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ - c = circleMap 0 R θ := by
simp [circleMap]
theorem circleMap_zero (R θ : ℝ) : circleMap 0 R θ = R * exp (θ * I) := zero_add _
@[simp]
theorem norm_circleMap_zero (R : ℝ) (θ : ℝ) : ‖circleMap 0 R θ‖ = |R| := by simp [circleMap]
@[deprecated (since := "2025-02-17")] alias abs_circleMap_zero := norm_circleMap_zero
theorem circleMap_notMem_ball (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ ∉ ball c R := by
simp [Complex.dist_eq, le_abs_self]
@[deprecated (since := "2025-05-23")] alias circleMap_not_mem_ball := circleMap_notMem_ball
theorem circleMap_ne_mem_ball {c : ℂ} {R : ℝ} {w : ℂ} (hw : w ∈ ball c R) (θ : ℝ) :
circleMap c R θ ≠ w :=
(ne_of_mem_of_not_mem hw (circleMap_notMem_ball _ _ _)).symm
theorem circleMap_mem_sphere' (c : ℂ) (R : ℝ) (θ : ℝ) : circleMap c R θ ∈ sphere c |R| := by simp
theorem circleMap_mem_sphere (c : ℂ) {R : ℝ} (hR : 0 ≤ R) (θ : ℝ) :
circleMap c R θ ∈ sphere c R := by
simpa only [abs_of_nonneg hR] using circleMap_mem_sphere' c R θ
theorem circleMap_mem_closedBall (c : ℂ) {R : ℝ} (hR : 0 ≤ R) (θ : ℝ) :
circleMap c R θ ∈ closedBall c R :=
sphere_subset_closedBall (circleMap_mem_sphere c hR θ)
@[simp]
theorem circleMap_eq_center_iff {c : ℂ} {R : ℝ} {θ : ℝ} : circleMap c R θ = c ↔ R = 0 := by
simp [circleMap, Complex.exp_ne_zero]
@[simp]
theorem circleMap_zero_radius (c : ℂ) : circleMap c 0 = const ℝ c :=
funext fun _ => circleMap_eq_center_iff.2 rfl
theorem circleMap_ne_center {c : ℂ} {R : ℝ} (hR : R ≠ 0) {θ : ℝ} : circleMap c R θ ≠ c :=
mt circleMap_eq_center_iff.1 hR
lemma circleMap_zero_mul (R₁ R₂ θ₁ θ₂ : ℝ) :
(circleMap 0 R₁ θ₁) * (circleMap 0 R₂ θ₂) = circleMap 0 (R₁ * R₂) (θ₁ + θ₂) := by
simp only [circleMap_zero, ofReal_mul, ofReal_add, add_mul, Complex.exp_add]
ring
lemma circleMap_zero_div (R₁ R₂ θ₁ θ₂ : ℝ) :
(circleMap 0 R₁ θ₁) / (circleMap 0 R₂ θ₂) = circleMap 0 (R₁ / R₂) (θ₁ - θ₂) := by
simp only [circleMap_zero, ofReal_div, ofReal_sub, sub_mul, Complex.exp_sub]
ring
lemma circleMap_zero_inv (R θ : ℝ) : (circleMap 0 R θ)⁻¹ = circleMap 0 R⁻¹ (-θ) := by
simp [circleMap_zero, Complex.exp_neg, mul_comm]
lemma circleMap_zero_pow (n : ℕ) (R θ : ℝ) :
(circleMap 0 R θ) ^ n = circleMap 0 (R ^ n) (n * θ) := by
simp [circleMap_zero, mul_pow, ← Complex.exp_nat_mul, ← mul_assoc]
lemma circleMap_zero_zpow (n : ℤ) (R θ : ℝ) :
(circleMap 0 R θ) ^ n = circleMap 0 (R ^ n) (n * θ) := by
simp [circleMap_zero, mul_zpow, ← exp_int_mul, ← mul_assoc]
@[deprecated (since := "2025-04-02")] alias circleMap_zero_int_mul := circleMap_zero_zpow
lemma circleMap_pi_div_two (c : ℂ) (R : ℝ) : circleMap c R (π / 2) = c + R * I := by
simp only [circleMap, ofReal_div, ofReal_ofNat, exp_pi_div_two_mul_I]
lemma circleMap_neg_pi_div_two (c : ℂ) (R : ℝ) : circleMap c R (-π / 2) = c - R * I := by
simp only [circleMap, ofReal_div, ofReal_neg, ofReal_ofNat, exp_neg_pi_div_two_mul_I, mul_neg,
sub_eq_add_neg]
/-- `circleMap` is `2π`-periodic. -/
theorem periodic_circleMap (c : ℂ) (R : ℝ) : Periodic (circleMap c R) (2 * π) := fun θ => by
simp [circleMap, add_mul, exp_periodic _]
theorem Set.Countable.preimage_circleMap {s : Set ℂ} (hs : s.Countable) (c : ℂ) {R : ℝ}
(hR : R ≠ 0) : (circleMap c R ⁻¹' s).Countable :=
show (((↑) : ℝ → ℂ) ⁻¹' ((· * I) ⁻¹'
(exp ⁻¹' ((R * ·) ⁻¹' ((c + ·) ⁻¹' s))))).Countable from
(((hs.preimage (add_right_injective _)).preimage <|
mul_right_injective₀ <| ofReal_ne_zero.2 hR).preimage_cexp.preimage <|
mul_left_injective₀ I_ne_zero).preimage ofReal_injective
lemma circleMap_eq_circleMap_iff {a b R : ℝ} (c : ℂ) (h_R : R ≠ 0) :
circleMap c R a = circleMap c R b ↔ ∃ (n : ℤ), a * I = b * I + n * (2 * π * I) := by
have : circleMap c R a = circleMap c R b ↔ (exp (a * I)).arg = (exp (b * I)).arg := by
simp [circleMap, ext_norm_arg_iff, h_R]
simp [this, arg_eq_arg_iff, exp_eq_exp_iff_exists_int]
lemma eq_of_circleMap_eq {a b R : ℝ} {c : ℂ} (h_R : R ≠ 0) (h_dist : |a - b| < 2 * π)
(h : circleMap c R a = circleMap c R b) : a = b := by
rw [circleMap_eq_circleMap_iff c h_R] at h
obtain ⟨n, hn⟩ := h
simp only [show n * (2 * π * I) = (n * 2 * π) * I by ring, ← add_mul, mul_eq_mul_right_iff,
I_ne_zero, or_false] at hn
norm_cast at hn
simp only [hn, Int.cast_mul, Int.cast_ofNat, mul_assoc, add_sub_cancel_left, abs_mul,
Nat.abs_ofNat, abs_of_pos Real.pi_pos] at h_dist
simp (disch := positivity) at h_dist
norm_cast at h_dist
simp [hn, Int.abs_lt_one_iff.mp h_dist]
open scoped Interval in
/-- `circleMap` is injective on `Ι a b` if the distance between `a` and `b` is at most `2π`. -/
theorem injOn_circleMap_of_abs_sub_le {a b R : ℝ} {c : ℂ} (h_R : R ≠ 0) (_ : |a - b| ≤ 2 * π) :
(Ι a b).InjOn (circleMap c R) := by
rintro _ ⟨_, _⟩ _ ⟨_, _⟩ h
apply eq_of_circleMap_eq h_R _ h
rw [abs_lt]
constructor <;> linarith [max_sub_min_eq_abs' a b]
/-- `circleMap` is injective on `Ico a b` if the distance between `a` and `b` is at most `2π`. -/
theorem injOn_circleMap_of_abs_sub_le' {a b R : ℝ} {c : ℂ} (h_R : R ≠ 0) (_ : b - a ≤ 2 * π) :
(Set.Ico a b).InjOn (circleMap c R) := by
rintro _ ⟨_, _⟩ _ ⟨_, _⟩ h
apply eq_of_circleMap_eq h_R _ h
rw [abs_lt]
constructor <;> linarith
end circleMap
|
Log.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.Complex.Arg
import Mathlib.Analysis.SpecialFunctions.Log.Basic
/-!
# The complex `log` function
Basic properties, relationship with `exp`.
-/
noncomputable section
namespace Complex
open Set Filter Bornology
open scoped Real Topology ComplexConjugate
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - π` and `(log x).im ≤ π`.
`log 0 = 0` -/
@[pp_nodot]
noncomputable def log (x : ℂ) : ℂ :=
Real.log ‖x‖ + arg x * I
theorem log_re (x : ℂ) : x.log.re = Real.log ‖x‖ := by simp [log]
theorem log_im (x : ℂ) : x.log.im = x.arg := by simp [log]
theorem neg_pi_lt_log_im (x : ℂ) : -π < (log x).im := by simp only [log_im, neg_pi_lt_arg]
theorem log_im_le_pi (x : ℂ) : (log x).im ≤ π := by simp only [log_im, arg_le_pi]
theorem exp_log {x : ℂ} (hx : x ≠ 0) : exp (log x) = x := by
rw [log, exp_add_mul_I, ← ofReal_sin, sin_arg, ← ofReal_cos, cos_arg hx, ← ofReal_exp,
Real.exp_log (norm_pos_iff.mpr hx), mul_add, ofReal_div, ofReal_div,
mul_div_cancel₀ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), ← mul_assoc,
mul_div_cancel₀ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), re_add_im]
@[simp]
theorem range_exp : Set.range exp = {0}ᶜ :=
Set.ext fun x =>
⟨by
rintro ⟨x, rfl⟩
exact exp_ne_zero x, fun hx => ⟨log x, exp_log hx⟩⟩
theorem log_exp {x : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π) : log (exp x) = x := by
rw [log, norm_exp, Real.log_exp, exp_eq_exp_re_mul_sin_add_cos, ← ofReal_exp,
arg_mul_cos_add_sin_mul_I (Real.exp_pos _) ⟨hx₁, hx₂⟩, re_add_im]
theorem exp_inj_of_neg_pi_lt_of_le_pi {x y : ℂ} (hx₁ : -π < x.im) (hx₂ : x.im ≤ π) (hy₁ : -π < y.im)
(hy₂ : y.im ≤ π) (hxy : exp x = exp y) : x = y := by
rw [← log_exp hx₁ hx₂, ← log_exp hy₁ hy₂, hxy]
theorem ofReal_log {x : ℝ} (hx : 0 ≤ x) : (x.log : ℂ) = log x :=
Complex.ext (by rw [log_re, ofReal_re, Complex.norm_of_nonneg hx])
(by rw [ofReal_im, log_im, arg_ofReal_of_nonneg hx])
@[simp, norm_cast]
lemma natCast_log {n : ℕ} : Real.log n = log n := ofReal_natCast n ▸ ofReal_log n.cast_nonneg
@[simp]
lemma ofNat_log {n : ℕ} [n.AtLeastTwo] :
Real.log ofNat(n) = log (OfNat.ofNat n) :=
natCast_log
theorem log_ofReal_re (x : ℝ) : (log (x : ℂ)).re = Real.log x := by simp [log_re]
theorem log_ofReal_mul {r : ℝ} (hr : 0 < r) {x : ℂ} (hx : x ≠ 0) :
log (r * x) = Real.log r + log x := by
replace hx := norm_ne_zero_iff.mpr hx
simp_rw [log, norm_mul, norm_real, arg_real_mul _ hr, Real.norm_of_nonneg hr.le,
Real.log_mul hr.ne' hx, ofReal_add, add_assoc]
theorem log_mul_ofReal (r : ℝ) (hr : 0 < r) (x : ℂ) (hx : x ≠ 0) :
log (x * r) = Real.log r + log x := by rw [mul_comm, log_ofReal_mul hr hx]
lemma log_mul_eq_add_log_iff {x y : ℂ} (hx₀ : x ≠ 0) (hy₀ : y ≠ 0) :
log (x * y) = log x + log y ↔ arg x + arg y ∈ Set.Ioc (-π) π := by
refine Complex.ext_iff.trans <| Iff.trans ?_ <| arg_mul_eq_add_arg_iff hx₀ hy₀
simp_rw [add_re, add_im, log_re, log_im, norm_mul,
Real.log_mul (norm_ne_zero_iff.mpr hx₀) (norm_ne_zero_iff.mpr hy₀), true_and]
alias ⟨_, log_mul⟩ := log_mul_eq_add_log_iff
@[simp]
theorem log_zero : log 0 = 0 := by simp [log]
@[simp]
theorem log_one : log 1 = 0 := by simp [log]
/-- This holds true for all `x : ℂ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/
@[simp] lemma log_div_self (x : ℂ) : log (x / x) = 0 := by simp [log]
theorem log_neg_one : log (-1) = π * I := by simp [log]
theorem log_I : log I = π / 2 * I := by simp [log]
theorem log_neg_I : log (-I) = -(π / 2) * I := by simp [log]
theorem log_conj_eq_ite (x : ℂ) : log (conj x) = if x.arg = π then log x else conj (log x) := by
simp_rw [log, norm_conj, arg_conj, map_add, map_mul, conj_ofReal]
split_ifs with hx
· rw [hx]
simp_rw [ofReal_neg, conj_I, mul_neg, neg_mul]
theorem log_conj (x : ℂ) (h : x.arg ≠ π) : log (conj x) = conj (log x) := by
rw [log_conj_eq_ite, if_neg h]
theorem log_inv_eq_ite (x : ℂ) : log x⁻¹ = if x.arg = π then -conj (log x) else -log x := by
by_cases hx : x = 0
· simp [hx]
rw [inv_def, log_mul_ofReal, Real.log_inv, ofReal_neg, ← sub_eq_neg_add, log_conj_eq_ite]
· simp_rw [log, map_add, map_mul, conj_ofReal, conj_I, normSq_eq_norm_sq, Real.log_pow,
Nat.cast_two, ofReal_mul, neg_add, mul_neg, neg_neg]
norm_num
grind
· rwa [inv_pos, Complex.normSq_pos]
· rwa [map_ne_zero]
theorem log_inv (x : ℂ) (hx : x.arg ≠ π) : log x⁻¹ = -log x := by rw [log_inv_eq_ite, if_neg hx]
theorem two_pi_I_ne_zero : (2 * π * I : ℂ) ≠ 0 := by simp [Real.pi_ne_zero, I_ne_zero]
theorem exp_eq_one_iff {x : ℂ} : exp x = 1 ↔ ∃ n : ℤ, x = n * (2 * π * I) := by
constructor
· intro h
rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos x.im (-π) with ⟨n, hn, -⟩
use -n
rw [Int.cast_neg, neg_mul, eq_neg_iff_add_eq_zero]
have : (x + n * (2 * π * I)).im ∈ Set.Ioc (-π) π := by simpa [two_mul, mul_add] using hn
rw [← log_exp this.1 this.2, exp_periodic.int_mul n, h, log_one]
· rintro ⟨n, rfl⟩
exact (exp_periodic.int_mul n).eq.trans exp_zero
theorem exp_eq_exp_iff_exp_sub_eq_one {x y : ℂ} : exp x = exp y ↔ exp (x - y) = 1 := by
rw [exp_sub, div_eq_one_iff_eq (exp_ne_zero _)]
theorem exp_eq_exp_iff_exists_int {x y : ℂ} : exp x = exp y ↔ ∃ n : ℤ, x = y + n * (2 * π * I) := by
simp only [exp_eq_exp_iff_exp_sub_eq_one, exp_eq_one_iff, sub_eq_iff_eq_add']
theorem log_exp_exists (z : ℂ) :
∃ n : ℤ, log (exp z) = z + n * (2 * π * I) := by
rw [← exp_eq_exp_iff_exists_int, exp_log]
exact exp_ne_zero z
@[simp]
theorem countable_preimage_exp {s : Set ℂ} : (exp ⁻¹' s).Countable ↔ s.Countable := by
refine ⟨fun hs => ?_, fun hs => ?_⟩
· refine ((hs.image exp).insert 0).mono ?_
rw [Set.image_preimage_eq_inter_range, range_exp, ← Set.diff_eq, ← Set.union_singleton,
Set.diff_union_self]
exact Set.subset_union_left
· rw [← Set.biUnion_preimage_singleton]
refine hs.biUnion fun z hz => ?_
rcases em (∃ w, exp w = z) with (⟨w, rfl⟩ | hne)
· simp only [Set.preimage, Set.mem_singleton_iff, exp_eq_exp_iff_exists_int, Set.setOf_exists]
exact Set.countable_iUnion fun m => Set.countable_singleton _
· push_neg at hne
simp [Set.preimage, hne]
alias ⟨_, _root_.Set.Countable.preimage_cexp⟩ := countable_preimage_exp
theorem tendsto_log_nhdsWithin_im_neg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0)
(him : z.im = 0) : Tendsto log (𝓝[{ z : ℂ | z.im < 0 }] z) (𝓝 <| Real.log ‖z‖ - π * I) := by
convert
(continuous_ofReal.continuousAt.comp_continuousWithinAt
(continuous_norm.continuousWithinAt.log _)).tendsto.add
(((continuous_ofReal.tendsto _).comp <|
tendsto_arg_nhdsWithin_im_neg_of_re_neg_of_im_zero hre him).mul
tendsto_const_nhds) using 1
· simp [sub_eq_add_neg]
· lift z to ℝ using him
simpa using hre.ne
theorem continuousWithinAt_log_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0) (him : z.im = 0) :
ContinuousWithinAt log { z : ℂ | 0 ≤ z.im } z := by
convert
(continuous_ofReal.continuousAt.comp_continuousWithinAt
(continuous_norm.continuousWithinAt.log _)).tendsto.add
((continuous_ofReal.continuousAt.comp_continuousWithinAt <|
continuousWithinAt_arg_of_re_neg_of_im_zero hre him).mul
tendsto_const_nhds) using 1
lift z to ℝ using him
simpa using hre.ne
theorem tendsto_log_nhdsWithin_im_nonneg_of_re_neg_of_im_zero {z : ℂ} (hre : z.re < 0)
(him : z.im = 0) : Tendsto log (𝓝[{ z : ℂ | 0 ≤ z.im }] z) (𝓝 <| Real.log ‖z‖ + π * I) := by
simpa only [log, arg_eq_pi_iff.2 ⟨hre, him⟩] using
(continuousWithinAt_log_of_re_neg_of_im_zero hre him).tendsto
@[simp]
theorem map_exp_comap_re_atBot : map exp (comap re atBot) = 𝓝[≠] 0 := by
rw [← comap_exp_nhds_zero, map_comap, range_exp, nhdsWithin]
@[simp]
theorem map_exp_comap_re_atTop : map exp (comap re atTop) = cobounded ℂ := by
rw [← comap_exp_cobounded, map_comap, range_exp, inf_eq_left, le_principal_iff]
exact eventually_ne_cobounded _
end Complex
section LogDeriv
open Complex Filter
open Topology
variable {α : Type*}
theorem continuousAt_clog {x : ℂ} (h : x ∈ slitPlane) : ContinuousAt log x := by
refine ContinuousAt.add ?_ ?_
· refine continuous_ofReal.continuousAt.comp ?_
refine (Real.continuousAt_log ?_).comp continuous_norm.continuousAt
exact norm_ne_zero_iff.mpr <| slitPlane_ne_zero h
· have h_cont_mul : Continuous fun x : ℂ => x * I := continuous_id'.mul continuous_const
refine h_cont_mul.continuousAt.comp (continuous_ofReal.continuousAt.comp ?_)
exact continuousAt_arg h
theorem _root_.Filter.Tendsto.clog {l : Filter α} {f : α → ℂ} {x : ℂ} (h : Tendsto f l (𝓝 x))
(hx : x ∈ slitPlane) : Tendsto (fun t => log (f t)) l (𝓝 <| log x) :=
(continuousAt_clog hx).tendsto.comp h
variable [TopologicalSpace α]
nonrec
theorem _root_.ContinuousAt.clog {f : α → ℂ} {x : α} (h₁ : ContinuousAt f x)
(h₂ : f x ∈ slitPlane) : ContinuousAt (fun t => log (f t)) x :=
h₁.clog h₂
nonrec
theorem _root_.ContinuousWithinAt.clog {f : α → ℂ} {s : Set α} {x : α}
(h₁ : ContinuousWithinAt f s x) (h₂ : f x ∈ slitPlane) :
ContinuousWithinAt (fun t => log (f t)) s x :=
h₁.clog h₂
nonrec
theorem _root_.ContinuousOn.clog {f : α → ℂ} {s : Set α} (h₁ : ContinuousOn f s)
(h₂ : ∀ x ∈ s, f x ∈ slitPlane) : ContinuousOn (fun t => log (f t)) s := fun x hx =>
(h₁ x hx).clog (h₂ x hx)
nonrec
theorem _root_.Continuous.clog {f : α → ℂ} (h₁ : Continuous f)
(h₂ : ∀ x, f x ∈ slitPlane) : Continuous fun t => log (f t) :=
continuous_iff_continuousAt.2 fun x => h₁.continuousAt.clog (h₂ x)
end LogDeriv
|
zmodp.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 choice eqtype ssrnat seq.
From mathcomp Require Import div fintype bigop finset prime fingroup perm.
From mathcomp Require Import ssralg finalg countalg.
(******************************************************************************)
(* Definition of the additive group and ring Zp, represented as 'I_p *)
(******************************************************************************)
(* Definitions: *)
(* From fintype.v: *)
(* 'I_p == the subtype of integers less than p, taken here as the type of *)
(* the integers mod p. *)
(* This file: *)
(* inZp == the natural projection from nat into the integers mod p, *)
(* represented as 'I_p. Here p is implicit, but MUST be of the *)
(* form n.+1. *)
(* The operations: *)
(* Zp0 == the identity element for addition *)
(* Zp1 == the identity element for multiplication, and a generator of *)
(* additive group *)
(* Zp_opp == inverse function for addition *)
(* Zp_add == addition *)
(* Zp_mul == multiplication *)
(* Zp_inv == inverse function for multiplication *)
(* Note that while 'I_n.+1 has canonical finZmodType and finGroupType *)
(* structures, only 'I_n.+2 has a canonical ring structure (it has, in fact, *)
(* a canonical finComUnitRing structure), and hence an associated *)
(* multiplicative unit finGroupType. To mitigate the issues caused by the *)
(* trivial "ring" (which is, indeed is NOT a ring in the ssralg/finalg *)
(* formalization), we define additional notation: *)
(* 'Z_p == the type of integers mod (max p 2); this is always a proper *)
(* ring, by constructions. Note that 'Z_p is provably equal to *)
(* 'I_p if p > 1, and convertible to 'I_p if p is of the form *)
(* n.+2. *)
(* Zp p == the subgroup of integers mod (max p 1) in 'Z_p; this is thus *)
(* all of 'Z_p if p > 1, and else the trivial group. *)
(* units_Zp p == the group of all units of 'Z_p -- i.e., the group of *)
(* (multiplicative) automorphisms of Zp p. *)
(* We show that Zp and units_Zp are abelian, and compute their orders. *)
(* We use a similar technique to represent the prime fields: *)
(* 'F_p == the finite field of integers mod the first prime divisor of *)
(* maxn p 2. This is provably equal to 'Z_p and 'I_p if p is *)
(* provably prime, and indeed convertible to the above if p is *)
(* a concrete prime such as 2, 5 or 23. *)
(* Note finally that due to the canonical structures it is possible to use *)
(* 0%R instead of Zp0, and 1%R instead of Zp1 (for the latter, p must be of *)
(* the form n.+2, and 1%R : nat will simplify to 1%N). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Section ZpDef.
(***********************************************************************)
(* *)
(* Mod p arithmetic on the finite set {0, 1, 2, ..., p - 1} *)
(* *)
(***********************************************************************)
(* Operations on 'I_p without constraint on p. *)
Section Generic.
Variable p : nat.
Implicit Types i j : 'I_p.
Lemma Zp_opp_subproof i : (p - i) %% p < p.
Proof. by case: p i => [[]//|k] i; apply/ltn_pmod. Qed.
Definition Zp_opp i := Ordinal (Zp_opp_subproof i).
Lemma Zp_add_subproof i j : (i + j) %% p < p.
Proof. by case: p i j => [[]//|k] i j; apply/ltn_pmod. Qed.
Definition Zp_add i j := Ordinal (Zp_add_subproof i j).
Lemma Zp_mul_subproof i j : (i * j) %% p < p.
Proof. by case: p i j => [[]//|k] i j; apply/ltn_pmod. Qed.
Definition Zp_mul i j := Ordinal (Zp_mul_subproof i j).
Lemma Zp_inv_subproof i : (egcdn i p).1 %% p < p.
Proof. by case: p i => [[]//|k] i; apply/ltn_pmod. Qed.
Definition Zp_inv i := if coprime p i then Ordinal (Zp_inv_subproof i) else i.
Lemma Zp_addA : associative Zp_add.
Proof.
by move=> x y z; apply: val_inj; rewrite /= modnDml modnDmr addnA.
Qed.
Lemma Zp_addC : commutative Zp_add.
Proof. by move=> x y; apply: val_inj; rewrite /= addnC. Qed.
Lemma Zp_mulC : commutative Zp_mul.
Proof. by move=> x y; apply: val_inj; rewrite /= mulnC. Qed.
Lemma Zp_mulA : associative Zp_mul.
Proof.
by move=> x y z; apply: val_inj; rewrite /= modnMml modnMmr mulnA.
Qed.
Lemma Zp_mul_addr : right_distributive Zp_mul Zp_add.
Proof.
by move=> x y z; apply: val_inj; rewrite /= modnMmr modnDm mulnDr.
Qed.
Lemma Zp_mul_addl : left_distributive Zp_mul Zp_add.
Proof. by move=> x y z; rewrite -!(Zp_mulC z) Zp_mul_addr. Qed.
Lemma Zp_inv_out i : ~~ coprime p i -> Zp_inv i = i.
Proof. by rewrite /Zp_inv => /negPf->. Qed.
End Generic.
Arguments Zp_opp {p}.
Arguments Zp_add {p}.
Arguments Zp_mul {p}.
Arguments Zp_inv {p}.
Variable p' : nat.
Local Notation p := p'.+1.
Implicit Types x y z : 'I_p.
(* Standard injection; val (inZp i) = i %% p *)
Definition inZp i := Ordinal (ltn_pmod i (ltn0Sn p')).
Lemma modZp x : x %% p = x.
Proof. by rewrite modn_small ?ltn_ord. Qed.
Lemma valZpK x : inZp x = x.
Proof. by apply: val_inj; rewrite /= modZp. Qed.
(* Operations *)
Definition Zp0 : 'I_p := ord0.
Definition Zp1 := inZp 1.
(* Additive group structure. *)
Lemma Zp_add0z : left_id Zp0 Zp_add.
Proof. by move=> x; apply: val_inj; rewrite /= modZp. Qed.
Lemma Zp_addNz : left_inverse Zp0 Zp_opp Zp_add.
Proof.
by move=> x; apply: val_inj; rewrite /= modnDml subnK ?modnn // ltnW.
Qed.
HB.instance Definition _ :=
GRing.isZmodule.Build 'I_p (@Zp_addA _) (@Zp_addC _) Zp_add0z Zp_addNz.
HB.instance Definition _ := [finGroupMixin of 'I_p for +%R].
(* Ring operations *)
Lemma Zp_mul1z : left_id Zp1 Zp_mul.
Proof. by move=> x; apply: val_inj; rewrite /= modnMml mul1n modZp. Qed.
Lemma Zp_mulz1 : right_id Zp1 Zp_mul.
Proof. by move=> x; rewrite Zp_mulC Zp_mul1z. Qed.
Lemma Zp_mulVz x : coprime p x -> Zp_mul (Zp_inv x) x = Zp1.
Proof.
move=> co_p_x; apply: val_inj; rewrite /Zp_inv co_p_x /= modnMml.
by rewrite -(chinese_modl co_p_x 1 0) /chinese addn0 mul1n mulnC.
Qed.
Lemma Zp_mulzV x : coprime p x -> Zp_mul x (Zp_inv x) = Zp1.
Proof. by move=> Ux; rewrite /= Zp_mulC Zp_mulVz. Qed.
Lemma Zp_intro_unit x y : Zp_mul y x = Zp1 -> coprime p x.
Proof.
case=> yx1; have:= coprimen1 p.
by rewrite -coprime_modr -yx1 coprime_modr coprimeMr; case/andP.
Qed.
Lemma Zp_mulrn x n : x *+ n = inZp (x * n).
Proof.
apply: val_inj => /=; elim: n => [|n IHn]; first by rewrite muln0 modn_small.
by rewrite !GRing.mulrS /= IHn modnDmr mulnS.
Qed.
Import GroupScope.
Lemma Zp_mulgC : @commutative 'I_p _ mulg.
Proof. exact: Zp_addC. Qed.
Lemma Zp_abelian : abelian [set: 'I_p].
Proof. exact: FinRing.zmod_abelian. Qed.
Lemma Zp_expg x n : x ^+ n = inZp (x * n).
Proof. exact: Zp_mulrn. Qed.
Lemma Zp1_expgz x : Zp1 ^+ x = x.
Proof.
rewrite Zp_expg; apply/val_inj.
by move: (Zp_mul1z x) => /(congr1 val).
Qed.
Lemma Zp_cycle : setT = <[Zp1]>.
Proof. by apply/setP=> x; rewrite -[x]Zp1_expgz inE groupX ?mem_gen ?set11. Qed.
Lemma order_Zp1 : #[Zp1] = p.
Proof. by rewrite orderE -Zp_cycle cardsT card_ord. Qed.
End ZpDef.
Arguments Zp0 {p'}.
Arguments Zp1 {p'}.
Arguments inZp {p'} i.
Arguments valZpK {p'} x.
(* We redefine fintype.ord1 to specialize it with 0 instead of ord0 *)
(* since 'I_n is now canonically a zmodType *)
Lemma ord1 : all_equal_to (0 : 'I_1).
Proof. exact: ord1. Qed.
Lemma lshift0 m n : lshift m (0 : 'I_n.+1) = (0 : 'I_(n + m).+1).
Proof. exact: val_inj. Qed.
Lemma rshift1 n : @rshift 1 n =1 lift (0 : 'I_n.+1).
Proof. by move=> i; apply: val_inj. Qed.
Lemma split1 n i :
split (i : 'I_(1 + n)) = oapp (@inr _ _) (inl _ 0) (unlift 0 i).
Proof.
case: unliftP => [i'|] -> /=.
by rewrite -rshift1 (unsplitK (inr _ _)).
by rewrite -(lshift0 n 0) (unsplitK (inl _ _)).
Qed.
(* TODO: bigop is imported after zmodp in matrix.v and intdiv.v to prevent
these warnings from triggering. We should restore the order of imports when
these are removed. *)
#[deprecated(since="mathcomp 2.3.0", note="Use bigop.big_ord1 instead.")]
Notation big_ord1 := big_ord1 (only parsing).
#[deprecated(since="mathcomp 2.3.0", note="Use bigop.big_ord1_cond instead.")]
Notation big_ord1_cond := big_ord1_cond (only parsing).
Section ZpNzRing.
Variable p' : nat.
Local Notation p := p'.+2.
Lemma Zp_nontrivial : Zp1 != 0 :> 'I_p. Proof. by []. Qed.
HB.instance Definition _ :=
GRing.Zmodule_isComNzRing.Build 'I_p
(@Zp_mulA _) (@Zp_mulC _) (@Zp_mul1z _) (@Zp_mul_addl _) Zp_nontrivial.
HB.instance Definition _ :=
GRing.ComNzRing_hasMulInverse.Build 'I_p
(@Zp_mulVz _) (@Zp_intro_unit _) (@Zp_inv_out _).
Lemma Zp_nat n : n%:R = inZp n :> 'I_p.
Proof. by apply: val_inj; rewrite [n%:R]Zp_mulrn /= modnMml mul1n. Qed.
Lemma natr_Zp (x : 'I_p) : x%:R = x.
Proof. by rewrite Zp_nat valZpK. Qed.
Lemma natr_negZp (x : 'I_p) : (- x)%:R = - x.
Proof. by apply: val_inj; rewrite /= Zp_nat /= modn_mod. Qed.
Import GroupScope.
Lemma unit_Zp_mulgC : @commutative {unit 'I_p} _ mulg.
Proof. by move=> u v; apply: val_inj; rewrite /= GRing.mulrC. Qed.
Lemma unit_Zp_expg (u : {unit 'I_p}) n :
val (u ^+ n) = inZp (val u ^ n) :> 'I_p.
Proof.
apply: val_inj => /=; elim: n => [|n IHn] //.
by rewrite expgS /= IHn expnS modnMmr.
Qed.
End ZpNzRing.
Definition Zp_trunc p := p.-2.
Notation "''Z_' p" := 'I_(Zp_trunc p).+2
(at level 0, p at level 2, format "''Z_' p") : type_scope.
Notation "''F_' p" := 'Z_(pdiv p)
(at level 0, p at level 2, format "''F_' p") : type_scope.
Arguments natr_Zp {p'} x.
Section ZpNzRing.
Import GRing.Theory.
Lemma add_1_Zp p (x : 'Z_p) : 1 + x = ordS x.
Proof. by case: p => [|[|p]] in x *; apply/val_inj. Qed.
Lemma add_Zp_1 p (x : 'Z_p) : x + 1 = ordS x.
Proof. by rewrite addrC add_1_Zp. Qed.
Lemma sub_Zp_1 p (x : 'Z_p) : x - 1 = ord_pred x.
Proof. by apply: (addIr 1); rewrite addrNK add_Zp_1 ord_predK. Qed.
Lemma add_N1_Zp p (x : 'Z_p) : -1 + x = ord_pred x.
Proof. by rewrite addrC sub_Zp_1. Qed.
End ZpNzRing.
Section Groups.
Variable p : nat.
Definition Zp := if p > 1 then [set: 'Z_p] else 1%g.
Definition units_Zp := [set: {unit 'Z_p}].
Lemma Zp_cast : p > 1 -> (Zp_trunc p).+2 = p.
Proof. by case: p => [|[]]. Qed.
Lemma val_Zp_nat (p_gt1 : p > 1) n : (n%:R : 'Z_p) = (n %% p)%N :> nat.
Proof. by rewrite Zp_nat /= Zp_cast. Qed.
Lemma Zp_nat_mod (p_gt1 : p > 1)m : (m %% p)%:R = m%:R :> 'Z_p.
Proof. by apply: ord_inj; rewrite !val_Zp_nat // modn_mod. Qed.
Lemma pchar_Zp : p > 1 -> p%:R = 0 :> 'Z_p.
Proof. by move=> p_gt1; rewrite -Zp_nat_mod ?modnn. Qed.
Lemma unitZpE x : p > 1 -> ((x%:R : 'Z_p) \is a GRing.unit) = coprime p x.
Proof.
move=> p_gt1; rewrite qualifE /=.
by rewrite val_Zp_nat ?Zp_cast ?coprime_modr.
Qed.
Lemma Zp_group_set : group_set Zp.
Proof. by rewrite /Zp; case: (p > 1); apply: groupP. Qed.
(* FIX ME : is this ok something similar is done in fingroup *)
Canonical Zp_group := Group Zp_group_set.
Lemma card_Zp : p > 0 -> #|Zp| = p.
Proof.
rewrite /Zp; case: p => [|[|p']] //= _; first by rewrite cards1.
by rewrite cardsT card_ord.
Qed.
Lemma mem_Zp x : p > 1 -> x \in Zp. Proof. by rewrite /Zp => ->. Qed.
Canonical units_Zp_group := [group of units_Zp].
Lemma card_units_Zp : p > 0 -> #|units_Zp| = totient p.
Proof.
move=> p_gt0; transitivity (totient p.-2.+2); last by case: p p_gt0 => [|[|p']].
rewrite cardsT card_sub -sum1_card big_mkcond /=.
by rewrite totient_count_coprime big_mkord.
Qed.
Lemma units_Zp_abelian : abelian units_Zp.
Proof. by apply/centsP=> u _ v _; apply: unit_Zp_mulgC. Qed.
End Groups.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_Zp instead.")]
Notation char_Zp := (pchar_Zp) (only parsing).
(* Field structure for primes. *)
Section PrimeField.
Open Scope ring_scope.
Variable p : nat.
Section F_prime.
Hypothesis p_pr : prime p.
Lemma Fp_Zcast : Zp_trunc (pdiv p) = Zp_trunc p.
Proof. by rewrite /pdiv primes_prime. Qed.
Lemma Fp_cast : (Zp_trunc (pdiv p)).+2 = p.
Proof. by rewrite Fp_Zcast ?Zp_cast ?prime_gt1. Qed.
Lemma card_Fp : #|'F_p| = p.
Proof. by rewrite card_ord Fp_cast. Qed.
Lemma val_Fp_nat n : (n%:R : 'F_p) = (n %% p)%N :> nat.
Proof. by rewrite Zp_nat /= Fp_cast. Qed.
Lemma Fp_nat_mod m : (m %% p)%:R = m%:R :> 'F_p.
Proof. by apply: ord_inj; rewrite !val_Fp_nat // modn_mod. Qed.
Lemma pchar_Fp : p \in [pchar 'F_p].
Proof. by rewrite !inE -Fp_nat_mod p_pr ?modnn. Qed.
Lemma pchar_Fp_0 : p%:R = 0 :> 'F_p.
Proof. exact: GRing.pcharf0 pchar_Fp. Qed.
Lemma unitFpE x : ((x%:R : 'F_p) \is a GRing.unit) = coprime p x.
Proof. by rewrite pdiv_id // unitZpE // prime_gt1. Qed.
End F_prime.
Lemma Fp_fieldMixin : GRing.ComUnitRing_isField 'F_p.
Proof.
constructor => x nzx.
rewrite qualifE /= prime_coprime ?gtnNdvd ?lt0n //.
case: (ltnP 1 p) => [lt1p | ]; last by case: p => [|[|p']].
by rewrite Zp_cast ?prime_gt1 ?pdiv_prime.
Qed.
HB.instance Definition _ := Fp_fieldMixin.
HB.instance Definition _ := FinRing.isField.Build 'F_p.
End PrimeField.
Section Sym.
Import GRing.
Lemma gen_tperm_step n (k : 'I_n.+1) : coprime n.+1 k ->
<<[set tperm i (i + k) | i : 'I_n.+1]>>%g = [set: 'S_n.+1].
Proof.
case: n k => [|n] k.
move=> _; apply/eqP; rewrite eqEsubset subsetT/= -(gen_tperm 0)/= gen_subG.
apply/subsetP => s /imsetP[/= [][|//] lt01 _ ->].
have ->: (Ordinal lt01) = 0 by apply/val_inj.
by rewrite tperm1 group1.
rewrite -unitZpE// natr_Zp => k_unit.
apply/eqP; rewrite eqEsubset subsetT/= -(gen_tperm 0)/= gen_subG.
apply/subsetP => s /imsetP[/= i _ ->].
rewrite -[i](mulVKr k_unit) -[_ * i]natr_Zp mulr_natr.
elim: (val _) => //= {i} [|[|i] IHi]; first by rewrite tperm1 group1.
by rewrite mulrSr mem_gen//; apply/imsetP; exists 0.
have [->|kS2N0] := eqVneq (k *+ i.+2) 0; first by rewrite tperm1 group1.
have kSSneqkS : k *+ i.+2 != k *+ i.+1.
rewrite -subr_eq0 -mulrnBr// subSnn mulr1n.
by apply: contraTneq k_unit => ->; rewrite unitr0.
rewrite -(@tpermJ_tperm _ (k *+ i.+1)) 1?eq_sym//.
rewrite groupJ// 1?tpermC// mulrSr 1?tpermC.
by rewrite mem_gen//; apply/imsetP; exists (k *+ i.+1).
Qed.
Lemma perm_addr1X n m (j k : 'I_n.+1) : (perm (addrI m%R) ^+ j)%g k = m *+ j + k.
Proof. by rewrite permX (eq_iter (permE _)) iter_addr. Qed.
Lemma gen_tpermn_circular_shift n (i j : 'I_n.+2)
(c := perm (addrI 1)) : coprime n.+2 (j - i)%R ->
<<[set tperm i j ; c]>>%g = [set: 'S_n.+2].
Proof.
move=> jBi_coprime; apply/eqP; rewrite eqEsubset subsetT/=.
rewrite -(gen_tperm_step jBi_coprime) gen_subG.
apply/subsetP => s /imsetP[/= k _ ->].
suff -> : tperm k (k + (j - i)) = (tperm i j ^ c ^+ (k - i)%R)%g.
by rewrite groupJ ?groupX ?mem_gen ?inE ?eqxx ?orbT.
by rewrite tpermJ !perm_addr1X natr_Zp addrNK addrAC addrA.
Qed.
End Sym.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_Fp instead.")]
Notation char_Fp := (pchar_Fp) (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_Fp_0 instead.")]
Notation char_Fp_0 := (pchar_Fp_0) (only parsing).
|
Substructures.lean
|
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Gabin Kolly
-/
import Mathlib.Data.Fintype.Order
import Mathlib.Order.Closure
import Mathlib.ModelTheory.Semantics
import Mathlib.ModelTheory.Encoding
/-!
# First-Order Substructures
This file defines substructures of first-order structures in a similar manner to the various
substructures appearing in the algebra library.
## Main Definitions
- A `FirstOrder.Language.Substructure` is defined so that `L.Substructure M` is the type of all
substructures of the `L`-structure `M`.
- `FirstOrder.Language.Substructure.closure` is defined so that if `s : Set M`, `closure L s` is
the least substructure of `M` containing `s`.
- `FirstOrder.Language.Substructure.comap` is defined so that `s.comap f` is the preimage of the
substructure `s` under the homomorphism `f`, as a substructure.
- `FirstOrder.Language.Substructure.map` is defined so that `s.map f` is the image of the
substructure `s` under the homomorphism `f`, as a substructure.
- `FirstOrder.Language.Hom.range` is defined so that `f.range` is the range of the
homomorphism `f`, as a substructure.
- `FirstOrder.Language.Hom.domRestrict` and `FirstOrder.Language.Hom.codRestrict` restrict
the domain and codomain respectively of first-order homomorphisms to substructures.
- `FirstOrder.Language.Embedding.domRestrict` and `FirstOrder.Language.Embedding.codRestrict`
restrict the domain and codomain respectively of first-order embeddings to substructures.
- `FirstOrder.Language.Substructure.inclusion` is the inclusion embedding between substructures.
- `FirstOrder.Language.Substructure.PartialEquiv` is defined so that `PartialEquiv L M N` is
the type of equivalences between substructures of `M` and `N`.
## Main Results
- `L.Substructure M` forms a `CompleteLattice`.
-/
universe u v w
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {M : Type w} {N P : Type*}
variable [L.Structure M] [L.Structure N] [L.Structure P]
open FirstOrder Cardinal
open Structure
section ClosedUnder
open Set
variable {n : ℕ} (f : L.Functions n) (s : Set M)
/-- Indicates that a set in a given structure is a closed under a function symbol. -/
def ClosedUnder : Prop :=
∀ x : Fin n → M, (∀ i : Fin n, x i ∈ s) → funMap f x ∈ s
variable (L)
@[simp]
theorem closedUnder_univ : ClosedUnder f (univ : Set M) := fun _ _ => mem_univ _
variable {L f s} {t : Set M}
namespace ClosedUnder
theorem inter (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ∩ t) := fun x h =>
mem_inter (hs x fun i => mem_of_mem_inter_left (h i)) (ht x fun i => mem_of_mem_inter_right (h i))
theorem inf (hs : ClosedUnder f s) (ht : ClosedUnder f t) : ClosedUnder f (s ⊓ t) :=
hs.inter ht
variable {S : Set (Set M)}
theorem sInf (hS : ∀ s, s ∈ S → ClosedUnder f s) : ClosedUnder f (sInf S) := fun x h s hs =>
hS s hs x fun i => h i s hs
end ClosedUnder
end ClosedUnder
variable (L) (M)
/-- A substructure of a structure `M` is a set closed under application of function symbols. -/
structure Substructure where
/-- The underlying set of this substructure -/
carrier : Set M
fun_mem : ∀ {n}, ∀ f : L.Functions n, ClosedUnder f carrier
variable {L} {M}
namespace Substructure
attribute [coe] Substructure.carrier
instance instSetLike : SetLike (L.Substructure M) M :=
⟨Substructure.carrier, fun p q h => by cases p; cases q; congr⟩
/-- See Note [custom simps projection] -/
def Simps.coe (S : L.Substructure M) : Set M :=
S
initialize_simps_projections Substructure (carrier → coe, as_prefix coe)
@[simp]
theorem mem_carrier {s : L.Substructure M} {x : M} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
/-- Two substructures are equal if they have the same elements. -/
@[ext]
theorem ext {S T : L.Substructure M} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
/-- Copy a substructure replacing `carrier` with a set that is equal to it. -/
protected def copy (S : L.Substructure M) (s : Set M) (hs : s = S) : L.Substructure M where
carrier := s
fun_mem _ f := hs.symm ▸ S.fun_mem _ f
end Substructure
variable {S : L.Substructure M}
theorem Term.realize_mem {α : Type*} (t : L.Term α) (xs : α → M) (h : ∀ a, xs a ∈ S) :
t.realize xs ∈ S := by
induction t with
| var a => exact h a
| func f ts ih => exact Substructure.fun_mem _ _ _ ih
namespace Substructure
@[simp]
theorem coe_copy {s : Set M} (hs : s = S) : (S.copy s hs : Set M) = s :=
rfl
theorem copy_eq {s : Set M} (hs : s = S) : S.copy s hs = S :=
SetLike.coe_injective hs
theorem constants_mem (c : L.Constants) : (c : M) ∈ S :=
mem_carrier.2 (S.fun_mem c _ finZeroElim)
/-- The substructure `M` of the structure `M`. -/
instance instTop : Top (L.Substructure M) :=
⟨{ carrier := Set.univ
fun_mem := fun {_} _ _ _ => Set.mem_univ _ }⟩
instance instInhabited : Inhabited (L.Substructure M) :=
⟨⊤⟩
@[simp]
theorem mem_top (x : M) : x ∈ (⊤ : L.Substructure M) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((⊤ : L.Substructure M) : Set M) = Set.univ :=
rfl
/-- The inf of two substructures is their intersection. -/
instance instInf : Min (L.Substructure M) :=
⟨fun S₁ S₂ =>
{ carrier := (S₁ : Set M) ∩ (S₂ : Set M)
fun_mem := fun {_} f => (S₁.fun_mem f).inf (S₂.fun_mem f) }⟩
@[simp]
theorem coe_inf (p p' : L.Substructure M) :
((p ⊓ p' : L.Substructure M) : Set M) = (p : Set M) ∩ (p' : Set M) :=
rfl
@[simp]
theorem mem_inf {p p' : L.Substructure M} {x : M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' :=
Iff.rfl
instance instInfSet : InfSet (L.Substructure M) :=
⟨fun s =>
{ carrier := ⋂ t ∈ s, (t : Set M)
fun_mem := fun {n} f =>
ClosedUnder.sInf
(by
rintro _ ⟨t, rfl⟩
by_cases h : t ∈ s
· simpa [h] using t.fun_mem f
· simp [h]) }⟩
@[simp, norm_cast]
theorem coe_sInf (S : Set (L.Substructure M)) :
((sInf S : L.Substructure M) : Set M) = ⋂ s ∈ S, (s : Set M) :=
rfl
theorem mem_sInf {S : Set (L.Substructure M)} {x : M} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p :=
Set.mem_iInter₂
theorem mem_iInf {ι : Sort*} {S : ι → L.Substructure M} {x : M} :
(x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range]
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} {S : ι → L.Substructure M} :
((⨅ i, S i : L.Substructure M) : Set M) = ⋂ i, (S i : Set M) := by
simp only [iInf, coe_sInf, Set.biInter_range]
/-- Substructures of a structure form a complete lattice. -/
instance instCompleteLattice : CompleteLattice (L.Substructure M) :=
{ completeLatticeOfInf (L.Substructure M) fun _ =>
IsGLB.of_image
(fun {S T : L.Substructure M} => show (S : Set M) ≤ T ↔ S ≤ T from SetLike.coe_subset_coe)
isGLB_biInf with
le := (· ≤ ·)
lt := (· < ·)
top := ⊤
le_top := fun _ x _ => mem_top x
inf := (· ⊓ ·)
sInf := InfSet.sInf
le_inf := fun _a _b _c ha hb _x hx => ⟨ha hx, hb hx⟩
inf_le_left := fun _ _ _ => And.left
inf_le_right := fun _ _ _ => And.right }
variable (L)
/-- The `L.Substructure` generated by a set. -/
def closure : LowerAdjoint ((↑) : L.Substructure M → Set M) :=
⟨fun s => sInf { S | s ⊆ S }, fun _ _ =>
⟨Set.Subset.trans fun _x hx => mem_sInf.2 fun _S hS => hS hx, fun h => sInf_le h⟩⟩
variable {L} {s : Set M}
theorem mem_closure {x : M} : x ∈ closure L s ↔ ∀ S : L.Substructure M, s ⊆ S → x ∈ S :=
mem_sInf
/-- The substructure generated by a set includes the set. -/
@[simp]
theorem subset_closure : s ⊆ closure L s :=
(closure L).le_closure s
theorem notMem_of_notMem_closure {P : M} (hP : P ∉ closure L s) : P ∉ s := fun h =>
hP (subset_closure h)
@[deprecated (since := "2025-05-23")] alias not_mem_of_not_mem_closure := notMem_of_notMem_closure
@[simp]
theorem closed (S : L.Substructure M) : (closure L).closed (S : Set M) :=
congr rfl ((closure L).eq_of_le Set.Subset.rfl fun _x xS => mem_closure.2 fun _T hT => hT xS)
open Set
/-- A substructure `S` includes `closure L s` if and only if it includes `s`. -/
@[simp]
theorem closure_le : closure L s ≤ S ↔ s ⊆ S :=
(closure L).closure_le_closed_iff_le s S.closed
/-- Substructure closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure L s ≤ closure L t`. -/
@[gcongr]
theorem closure_mono ⦃s t : Set M⦄ (h : s ⊆ t) : closure L s ≤ closure L t :=
(closure L).monotone h
theorem closure_eq_of_le (h₁ : s ⊆ S) (h₂ : S ≤ closure L s) : closure L s = S :=
(closure L).eq_of_le h₁ h₂
theorem coe_closure_eq_range_term_realize :
(closure L s : Set M) = range (@Term.realize L _ _ _ ((↑) : s → M)) := by
let S : L.Substructure M := ⟨range (Term.realize (L := L) ((↑) : s → M)), fun {n} f x hx => by
simp only [mem_range] at *
refine ⟨func f fun i => Classical.choose (hx i), ?_⟩
simp only [Term.realize, fun i => Classical.choose_spec (hx i)]⟩
change _ = (S : Set M)
rw [← SetLike.ext'_iff]
refine closure_eq_of_le (fun x hx => ⟨var ⟨x, hx⟩, rfl⟩) (le_sInf fun S' hS' => ?_)
rintro _ ⟨t, rfl⟩
exact t.realize_mem _ fun i => hS' i.2
instance small_closure [Small.{u} s] : Small.{u} (closure L s) := by
rw [← SetLike.coe_sort_coe, Substructure.coe_closure_eq_range_term_realize]
exact small_range _
theorem mem_closure_iff_exists_term {x : M} :
x ∈ closure L s ↔ ∃ t : L.Term s, t.realize ((↑) : s → M) = x := by
rw [← SetLike.mem_coe, coe_closure_eq_range_term_realize, mem_range]
theorem lift_card_closure_le_card_term : Cardinal.lift.{max u w} #(closure L s) ≤ #(L.Term s) := by
rw [← SetLike.coe_sort_coe, coe_closure_eq_range_term_realize]
rw [← Cardinal.lift_id'.{w, max u w} #(L.Term s)]
exact Cardinal.mk_range_le_lift
theorem lift_card_closure_le :
Cardinal.lift.{u, w} #(closure L s) ≤
max ℵ₀ (Cardinal.lift.{u, w} #s + Cardinal.lift.{w, u} #(Σ i, L.Functions i)) := by
rw [← lift_umax]
refine lift_card_closure_le_card_term.trans (Term.card_le.trans ?_)
rw [mk_sum, lift_umax.{w, u}]
lemma mem_closed_iff (s : Set M) :
s ∈ (closure L).closed ↔ ∀ {n}, ∀ f : L.Functions n, ClosedUnder f s := by
refine ⟨fun h n f => ?_, fun h => ?_⟩
· rw [← h]
exact Substructure.fun_mem _ _
· have h' : closure L s = ⟨s, h⟩ := closure_eq_of_le (refl _) subset_closure
exact congr_arg _ h'
variable (L)
lemma mem_closed_of_isRelational [L.IsRelational] (s : Set M) : s ∈ (closure L).closed :=
(mem_closed_iff s).2 isEmptyElim
@[simp]
lemma closure_eq_of_isRelational [L.IsRelational] (s : Set M) : closure L s = s :=
LowerAdjoint.closure_eq_self_of_mem_closed _ (mem_closed_of_isRelational L s)
@[simp]
lemma mem_closure_iff_of_isRelational [L.IsRelational] (s : Set M) (m : M) :
m ∈ closure L s ↔ m ∈ s := by
rw [← SetLike.mem_coe, closure_eq_of_isRelational]
theorem _root_.Set.Countable.substructure_closure
[Countable (Σ l, L.Functions l)] (h : s.Countable) : Countable.{w + 1} (closure L s) := by
haveI : Countable s := h.to_subtype
rw [← mk_le_aleph0_iff, ← lift_le_aleph0]
exact lift_card_closure_le_card_term.trans mk_le_aleph0
variable {L} (S)
/-- An induction principle for closure membership. If `p` holds for all elements of `s`, and
is preserved under function symbols, then `p` holds for all elements of the closure of `s`. -/
@[elab_as_elim]
theorem closure_induction {p : M → Prop} {x} (h : x ∈ closure L s) (Hs : ∀ x ∈ s, p x)
(Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x :=
(@closure_le L M _ ⟨setOf p, fun {_} => Hfun⟩ _).2 Hs h
/-- If `s` is a dense set in a structure `M`, `Substructure.closure L s = ⊤`, then in order to prove
that some predicate `p` holds for all `x : M` it suffices to verify `p x` for `x ∈ s`, and verify
that `p` is preserved under function symbols. -/
@[elab_as_elim]
theorem dense_induction {p : M → Prop} (x : M) {s : Set M} (hs : closure L s = ⊤)
(Hs : ∀ x ∈ s, p x) (Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f (setOf p)) : p x := by
have : ∀ x ∈ closure L s, p x := fun x hx => closure_induction hx Hs fun {n} => Hfun
simpa [hs] using this x
variable (L) (M)
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : GaloisInsertion (@closure L M _) (↑) where
choice s _ := closure L s
gc := (closure L).gc
le_l_u _ := subset_closure
choice_eq _ _ := rfl
variable {L} {M}
/-- Closure of a substructure `S` equals `S`. -/
@[simp]
theorem closure_eq : closure L (S : Set M) = S :=
(Substructure.gi L M).l_u_eq S
@[simp]
theorem closure_empty : closure L (∅ : Set M) = ⊥ :=
(Substructure.gi L M).gc.l_bot
@[simp]
theorem closure_univ : closure L (univ : Set M) = ⊤ :=
@coe_top L M _ ▸ closure_eq ⊤
theorem closure_union (s t : Set M) : closure L (s ∪ t) = closure L s ⊔ closure L t :=
(Substructure.gi L M).gc.l_sup
theorem closure_iUnion {ι} (s : ι → Set M) : closure L (⋃ i, s i) = ⨆ i, closure L (s i) :=
(Substructure.gi L M).gc.l_iSup
theorem closure_insert (s : Set M) (m : M) : closure L (insert m s) = closure L {m} ⊔ closure L s :=
closure_union {m} s
instance small_bot : Small.{u} (⊥ : L.Substructure M) := by
rw [← closure_empty]
haveI : Small.{u} (∅ : Set M) := small_subsingleton _
exact Substructure.small_closure
theorem iSup_eq_closure {ι : Sort*} (S : ι → L.Substructure M) :
⨆ i, S i = closure L (⋃ i, (S i : Set M)) := by simp_rw [closure_iUnion, closure_eq]
-- This proof uses the fact that `Substructure.closure` is finitary.
theorem mem_iSup_of_directed {ι : Type*} [hι : Nonempty ι] {S : ι → L.Substructure M}
(hS : Directed (· ≤ ·) S) {x : M} :
x ∈ ⨆ i, S i ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩
suffices x ∈ closure L (⋃ i, (S i : Set M)) → ∃ i, x ∈ S i by
simpa only [closure_iUnion, closure_eq (S _)] using this
refine fun hx ↦ closure_induction hx (fun _ ↦ mem_iUnion.1) (fun f v hC ↦ ?_)
simp_rw [Set.mem_setOf] at *
have ⟨i, hi⟩ := hS.finite_le (fun i ↦ Classical.choose (hC i))
refine ⟨i, (S i).fun_mem f v (fun j ↦ hi j (Classical.choose_spec (hC j)))⟩
-- This proof uses the fact that `Substructure.closure` is finitary.
theorem mem_sSup_of_directedOn {S : Set (L.Substructure M)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) {x : M} :
x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by
haveI : Nonempty S := Sne.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, Subtype.exists, exists_prop]
variable (L) (M)
instance [IsEmpty L.Constants] : IsEmpty (⊥ : L.Substructure M) := by
refine (isEmpty_subtype _).2 (fun x => ?_)
have h : (∅ : Set M) ∈ (closure L).closed := by
rw [mem_closed_iff]
intro n f
cases n
· exact isEmptyElim f
· intro x hx
simp only [mem_empty_iff_false, forall_const] at hx
rw [← closure_empty, ← SetLike.mem_coe, h]
exact Set.notMem_empty _
variable {L} {M}
/-!
### `comap` and `map`
-/
/-- The preimage of a substructure along a homomorphism is a substructure. -/
@[simps]
def comap (φ : M →[L] N) (S : L.Substructure N) : L.Substructure M where
carrier := φ ⁻¹' S
fun_mem {n} f x hx := by
rw [mem_preimage, φ.map_fun]
exact S.fun_mem f (φ ∘ x) hx
@[simp]
theorem mem_comap {S : L.Substructure N} {f : M →[L] N} {x : M} : x ∈ S.comap f ↔ f x ∈ S :=
Iff.rfl
theorem comap_comap (S : L.Substructure P) (g : N →[L] P) (f : M →[L] N) :
(S.comap g).comap f = S.comap (g.comp f) :=
rfl
@[simp]
theorem comap_id (S : L.Substructure P) : S.comap (Hom.id _ _) = S :=
ext (by simp)
/-- The image of a substructure along a homomorphism is a substructure. -/
@[simps]
def map (φ : M →[L] N) (S : L.Substructure M) : L.Substructure N where
carrier := φ '' S
fun_mem {n} f x hx :=
(mem_image _ _ _).1
⟨funMap f fun i => Classical.choose (hx i),
S.fun_mem f _ fun i => (Classical.choose_spec (hx i)).1, by
simp only [Hom.map_fun, SetLike.mem_coe]
exact congr rfl (funext fun i => (Classical.choose_spec (hx i)).2)⟩
@[simp]
theorem mem_map {f : M →[L] N} {S : L.Substructure M} {y : N} :
y ∈ S.map f ↔ ∃ x ∈ S, f x = y :=
Iff.rfl
theorem mem_map_of_mem (f : M →[L] N) {S : L.Substructure M} {x : M} (hx : x ∈ S) : f x ∈ S.map f :=
mem_image_of_mem f hx
theorem apply_coe_mem_map (f : M →[L] N) (S : L.Substructure M) (x : S) : f x ∈ S.map f :=
mem_map_of_mem f x.prop
theorem map_map (g : N →[L] P) (f : M →[L] N) : (S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| image_image _ _ _
theorem map_le_iff_le_comap {f : M →[L] N} {S : L.Substructure M} {T : L.Substructure N} :
S.map f ≤ T ↔ S ≤ T.comap f :=
image_subset_iff
theorem gc_map_comap (f : M →[L] N) : GaloisConnection (map f) (comap f) := fun _ _ =>
map_le_iff_le_comap
theorem map_le_of_le_comap {T : L.Substructure N} {f : M →[L] N} : S ≤ T.comap f → S.map f ≤ T :=
(gc_map_comap f).l_le
theorem le_comap_of_map_le {T : L.Substructure N} {f : M →[L] N} : S.map f ≤ T → S ≤ T.comap f :=
(gc_map_comap f).le_u
theorem le_comap_map {f : M →[L] N} : S ≤ (S.map f).comap f :=
(gc_map_comap f).le_u_l _
theorem map_comap_le {S : L.Substructure N} {f : M →[L] N} : (S.comap f).map f ≤ S :=
(gc_map_comap f).l_u_le _
theorem monotone_map {f : M →[L] N} : Monotone (map f) :=
(gc_map_comap f).monotone_l
theorem monotone_comap {f : M →[L] N} : Monotone (comap f) :=
(gc_map_comap f).monotone_u
@[simp]
theorem map_comap_map {f : M →[L] N} : ((S.map f).comap f).map f = S.map f :=
(gc_map_comap f).l_u_l_eq_l _
@[simp]
theorem comap_map_comap {S : L.Substructure N} {f : M →[L] N} :
((S.comap f).map f).comap f = S.comap f :=
(gc_map_comap f).u_l_u_eq_u _
theorem map_sup (S T : L.Substructure M) (f : M →[L] N) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure M) :
(⨆ i, s i).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem comap_inf (S T : L.Substructure N) (f : M →[L] N) :
(S ⊓ T).comap f = S.comap f ⊓ T.comap f :=
(gc_map_comap f).u_inf
theorem comap_iInf {ι : Sort*} (f : M →[L] N) (s : ι → L.Substructure N) :
(⨅ i, s i).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[simp]
theorem map_bot (f : M →[L] N) : (⊥ : L.Substructure M).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp]
theorem comap_top (f : M →[L] N) : (⊤ : L.Substructure N).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp]
theorem map_id (S : L.Substructure M) : S.map (Hom.id L M) = S :=
SetLike.coe_injective <| Set.image_id _
theorem map_closure (f : M →[L] N) (s : Set M) : (closure L s).map f = closure L (f '' s) :=
Eq.symm <|
closure_eq_of_le (Set.image_mono subset_closure) <|
map_le_iff_le_comap.2 <| closure_le.2 fun x hx => subset_closure ⟨x, hx, rfl⟩
@[simp]
theorem closure_image (f : M →[L] N) : closure L (f '' s) = map f (closure L s) :=
(map_closure f s).symm
section GaloisCoinsertion
variable {ι : Type*} {f : M →[L] N}
/-- `map f` and `comap f` form a `GaloisCoinsertion` when `f` is injective. -/
def gciMapComap (hf : Function.Injective f) : GaloisCoinsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisCoinsertion fun S x => by simp [mem_comap, mem_map, hf.eq_iff]
variable (hf : Function.Injective f)
include hf
theorem comap_map_eq_of_injective (S : L.Substructure M) : (S.map f).comap f = S :=
(gciMapComap hf).u_l_eq _
theorem comap_surjective_of_injective : Function.Surjective (comap f) :=
(gciMapComap hf).u_surjective
theorem map_injective_of_injective : Function.Injective (map f) :=
(gciMapComap hf).l_injective
theorem comap_inf_map_of_injective (S T : L.Substructure M) : (S.map f ⊓ T.map f).comap f = S ⊓ T :=
(gciMapComap hf).u_inf_l _ _
theorem comap_iInf_map_of_injective (S : ι → L.Substructure M) :
(⨅ i, (S i).map f).comap f = ⨅ i, S i :=
(gciMapComap hf).u_iInf_l _
theorem comap_sup_map_of_injective (S T : L.Substructure M) : (S.map f ⊔ T.map f).comap f = S ⊔ T :=
(gciMapComap hf).u_sup_l _ _
theorem comap_iSup_map_of_injective (S : ι → L.Substructure M) :
(⨆ i, (S i).map f).comap f = ⨆ i, S i :=
(gciMapComap hf).u_iSup_l _
theorem map_le_map_iff_of_injective {S T : L.Substructure M} : S.map f ≤ T.map f ↔ S ≤ T :=
(gciMapComap hf).l_le_l_iff
theorem map_strictMono_of_injective : StrictMono (map f) :=
(gciMapComap hf).strictMono_l
end GaloisCoinsertion
section GaloisInsertion
variable {ι : Type*} {f : M →[L] N} (hf : Function.Surjective f)
include hf
/-- `map f` and `comap f` form a `GaloisInsertion` when `f` is surjective. -/
def giMapComap : GaloisInsertion (map f) (comap f) :=
(gc_map_comap f).toGaloisInsertion fun S x h =>
let ⟨y, hy⟩ := hf x
mem_map.2 ⟨y, by simp [hy, h]⟩
theorem map_comap_eq_of_surjective (S : L.Substructure N) : (S.comap f).map f = S :=
(giMapComap hf).l_u_eq _
theorem map_surjective_of_surjective : Function.Surjective (map f) :=
(giMapComap hf).l_surjective
theorem comap_injective_of_surjective : Function.Injective (comap f) :=
(giMapComap hf).u_injective
theorem map_inf_comap_of_surjective (S T : L.Substructure N) :
(S.comap f ⊓ T.comap f).map f = S ⊓ T :=
(giMapComap hf).l_inf_u _ _
theorem map_iInf_comap_of_surjective (S : ι → L.Substructure N) :
(⨅ i, (S i).comap f).map f = ⨅ i, S i :=
(giMapComap hf).l_iInf_u _
theorem map_sup_comap_of_surjective (S T : L.Substructure N) :
(S.comap f ⊔ T.comap f).map f = S ⊔ T :=
(giMapComap hf).l_sup_u _ _
theorem map_iSup_comap_of_surjective (S : ι → L.Substructure N) :
(⨆ i, (S i).comap f).map f = ⨆ i, S i :=
(giMapComap hf).l_iSup_u _
theorem comap_le_comap_iff_of_surjective {S T : L.Substructure N} : S.comap f ≤ T.comap f ↔ S ≤ T :=
(giMapComap hf).u_le_u_iff
theorem comap_strictMono_of_surjective : StrictMono (comap f) :=
(giMapComap hf).strictMono_u
end GaloisInsertion
instance inducedStructure {S : L.Substructure M} : L.Structure S where
funMap {_} f x := ⟨funMap f fun i => x i, S.fun_mem f (fun i => x i) fun i => (x i).2⟩
RelMap {_} r x := RelMap r fun i => (x i : M)
/-- The natural embedding of an `L.Substructure` of `M` into `M`. -/
def subtype (S : L.Substructure M) : S ↪[L] M where
toFun := (↑)
inj' := Subtype.coe_injective
@[simp]
theorem subtype_apply {S : L.Substructure M} {x : S} : subtype S x = x :=
rfl
theorem subtype_injective (S : L.Substructure M) : Function.Injective (subtype S) :=
Subtype.coe_injective
@[simp]
theorem coe_subtype : ⇑S.subtype = ((↑) : S → M) :=
rfl
@[deprecated (since := "2025-02-18")]
alias coeSubtype := coe_subtype
/-- The equivalence between the maximal substructure of a structure and the structure itself. -/
def topEquiv : (⊤ : L.Substructure M) ≃[L] M where
toFun := subtype ⊤
invFun m := ⟨m, mem_top m⟩
left_inv m := by simp
@[simp]
theorem coe_topEquiv :
⇑(topEquiv : (⊤ : L.Substructure M) ≃[L] M) = ((↑) : (⊤ : L.Substructure M) → M) :=
rfl
@[simp]
theorem realize_boundedFormula_top {α : Type*} {n : ℕ} {φ : L.BoundedFormula α n}
{v : α → (⊤ : L.Substructure M)} {xs : Fin n → (⊤ : L.Substructure M)} :
φ.Realize v xs ↔ φ.Realize (((↑) : _ → M) ∘ v) ((↑) ∘ xs) := by
rw [← StrongHomClass.realize_boundedFormula Substructure.topEquiv φ]
simp
@[simp]
theorem realize_formula_top {α : Type*} {φ : L.Formula α} {v : α → (⊤ : L.Substructure M)} :
φ.Realize v ↔ φ.Realize (((↑) : (⊤ : L.Substructure M) → M) ∘ v) := by
rw [← StrongHomClass.realize_formula Substructure.topEquiv φ]
simp
/-- A dependent version of `Substructure.closure_induction`. -/
@[elab_as_elim]
theorem closure_induction' (s : Set M) {p : ∀ x, x ∈ closure L s → Prop}
(Hs : ∀ (x) (h : x ∈ s), p x (subset_closure h))
(Hfun : ∀ {n : ℕ} (f : L.Functions n), ClosedUnder f { x | ∃ hx, p x hx }) {x}
(hx : x ∈ closure L s) : p x hx := by
refine Exists.elim ?_ fun (hx : x ∈ closure L s) (hc : p x hx) => hc
exact closure_induction hx (fun x hx => ⟨subset_closure hx, Hs x hx⟩) @Hfun
end Substructure
open Substructure
namespace LHom
variable {L' : Language} [L'.Structure M]
/-- Reduces the language of a substructure along a language hom. -/
def substructureReduct (φ : L →ᴸ L') [φ.IsExpansionOn M] :
L'.Substructure M ↪o L.Substructure M where
toFun S :=
{ carrier := S
fun_mem := fun {n} f x hx => by
have h := S.fun_mem (φ.onFunction f) x hx
simp only [LHom.map_onFunction, Substructure.mem_carrier] at h
exact h }
inj' S T h := by
simp only [SetLike.coe_set_eq, Substructure.mk.injEq] at h
exact h
map_rel_iff' {_ _} := Iff.rfl
variable (φ : L →ᴸ L') [φ.IsExpansionOn M]
@[simp]
theorem mem_substructureReduct {x : M} {S : L'.Substructure M} :
x ∈ φ.substructureReduct S ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_substructureReduct {S : L'.Substructure M} : (φ.substructureReduct S : Set M) = ↑S :=
rfl
end LHom
namespace Substructure
/-- Turns any substructure containing a constant set `A` into a `L[[A]]`-substructure. -/
def withConstants (S : L.Substructure M) {A : Set M} (h : A ⊆ S) : L[[A]].Substructure M where
carrier := S
fun_mem {n} f := by
obtain f | f := f
· exact S.fun_mem f
· cases n
· exact fun _ _ => h f.2
· exact isEmptyElim f
variable {A : Set M} {s : Set M} (h : A ⊆ S)
@[simp]
theorem mem_withConstants {x : M} : x ∈ S.withConstants h ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_withConstants : (S.withConstants h : Set M) = ↑S :=
rfl
@[simp]
theorem reduct_withConstants :
(L.lhomWithConstants A).substructureReduct (S.withConstants h) = S := by
ext
simp
theorem subset_closure_withConstants : A ⊆ closure (L[[A]]) s := by
intro a ha
simp only [SetLike.mem_coe]
let a' : L[[A]].Constants := Sum.inr ⟨a, ha⟩
exact constants_mem a'
theorem closure_withConstants_eq :
closure (L[[A]]) s =
(closure L (A ∪ s)).withConstants ((A.subset_union_left).trans subset_closure) := by
refine closure_eq_of_le ((A.subset_union_right).trans subset_closure) ?_
rw [← (L.lhomWithConstants A).substructureReduct.le_iff_le]
simp only [subset_closure, reduct_withConstants, closure_le, LHom.coe_substructureReduct,
Set.union_subset_iff, and_true]
exact subset_closure_withConstants
end Substructure
namespace Hom
/-- The restriction of a first-order hom to a substructure `s ⊆ M` gives a hom `s → N`. -/
@[simps!]
def domRestrict (f : M →[L] N) (p : L.Substructure M) : p →[L] N :=
f.comp p.subtype.toHom
/-- A first-order hom `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted to a
hom `M → p`. -/
@[simps]
def codRestrict (p : L.Substructure N) (f : M →[L] N) (h : ∀ c, f c ∈ p) : M →[L] p where
toFun c := ⟨f c, h c⟩
map_fun' {n} f x := by aesop
map_rel' {_} R x h := f.map_rel R x h
@[simp]
theorem comp_codRestrict (f : M →[L] N) (g : N →[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) :
((codRestrict p g h).comp f : M →[L] p) = codRestrict p (g.comp f) fun _ => h _ :=
ext fun _ => rfl
@[simp]
theorem subtype_comp_codRestrict (f : M →[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) :
p.subtype.toHom.comp (codRestrict p f h) = f :=
ext fun _ => rfl
/-- The range of a first-order hom `f : M → N` is a submodule of `N`.
See Note [range copy pattern]. -/
def range (f : M →[L] N) : L.Substructure N :=
(map f ⊤).copy (Set.range f) Set.image_univ.symm
theorem range_coe (f : M →[L] N) : (range f : Set N) = Set.range f :=
rfl
@[simp]
theorem mem_range {f : M →[L] N} {x} : x ∈ range f ↔ ∃ y, f y = x :=
Iff.rfl
theorem range_eq_map (f : M →[L] N) : f.range = map f ⊤ := by
ext
simp
theorem mem_range_self (f : M →[L] N) (x : M) : f x ∈ f.range :=
⟨x, rfl⟩
@[simp]
theorem range_id : range (id L M) = ⊤ :=
SetLike.coe_injective Set.range_id
theorem range_comp (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) = map g (range f) :=
SetLike.coe_injective (Set.range_comp g f)
theorem range_comp_le_range (f : M →[L] N) (g : N →[L] P) : range (g.comp f : M →[L] P) ≤ range g :=
SetLike.coe_mono (Set.range_comp_subset_range f g)
theorem range_eq_top {f : M →[L] N} : range f = ⊤ ↔ Function.Surjective f := by
rw [SetLike.ext'_iff, range_coe, coe_top, Set.range_eq_univ]
theorem range_le_iff_comap {f : M →[L] N} {p : L.Substructure N} : range f ≤ p ↔ comap f p = ⊤ := by
rw [range_eq_map, map_le_iff_le_comap, eq_top_iff]
theorem map_le_range {f : M →[L] N} {p : L.Substructure M} : map f p ≤ range f :=
SetLike.coe_mono (Set.image_subset_range f p)
/-- The substructure of elements `x : M` such that `f x = g x` -/
def eqLocus (f g : M →[L] N) : Substructure L M where
carrier := { x : M | f x = g x }
fun_mem {n} fn x hx := by
have h : f ∘ x = g ∘ x := by
ext
repeat' rw [Function.comp_apply]
apply hx
simp [h]
/-- If two `L.Hom`s are equal on a set, then they are equal on its substructure closure. -/
theorem eqOn_closure {f g : M →[L] N} {s : Set M} (h : Set.EqOn f g s) :
Set.EqOn f g (closure L s) :=
show closure L s ≤ f.eqLocus g from closure_le.2 h
theorem eq_of_eqOn_top {f g : M →[L] N} (h : Set.EqOn f g (⊤ : Substructure L M)) : f = g :=
ext fun _ => h trivial
variable {s : Set M}
theorem eq_of_eqOn_dense (hs : closure L s = ⊤) {f g : M →[L] N} (h : s.EqOn f g) : f = g :=
eq_of_eqOn_top <| hs ▸ eqOn_closure h
end Hom
namespace Embedding
/-- The restriction of a first-order embedding to a substructure `s ⊆ M` gives an embedding `s → N`.
-/
def domRestrict (f : M ↪[L] N) (p : L.Substructure M) : p ↪[L] N :=
f.comp p.subtype
@[simp]
theorem domRestrict_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) : f.domRestrict p x = f x :=
rfl
/-- A first-order embedding `f : M → N` whose values lie in a substructure `p ⊆ N` can be restricted
to an embedding `M → p`. -/
def codRestrict (p : L.Substructure N) (f : M ↪[L] N) (h : ∀ c, f c ∈ p) : M ↪[L] p where
toFun := f.toHom.codRestrict p h
inj' _ _ ab := f.injective (Subtype.mk_eq_mk.1 ab)
map_fun' {_} F x := (f.toHom.codRestrict p h).map_fun' F x
map_rel' {n} r x := by
rw [← p.subtype.map_rel]
change RelMap r (Hom.comp p.subtype.toHom (f.toHom.codRestrict p h) ∘ x) ↔ _
rw [Hom.subtype_comp_codRestrict, ← f.map_rel]
rfl
@[simp]
theorem codRestrict_apply (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) :
(codRestrict p f h x : N) = f x :=
rfl
@[simp]
theorem codRestrict_apply' (p : L.Substructure N) (f : M ↪[L] N) {h} (x : M) :
codRestrict p f h x = ⟨f x, h x⟩ :=
rfl
@[simp]
theorem comp_codRestrict (f : M ↪[L] N) (g : N ↪[L] P) (p : L.Substructure P) (h : ∀ b, g b ∈ p) :
((codRestrict p g h).comp f : M ↪[L] p) = codRestrict p (g.comp f) fun _ => h _ :=
ext fun _ => rfl
@[simp]
theorem subtype_comp_codRestrict (f : M ↪[L] N) (p : L.Substructure N) (h : ∀ b, f b ∈ p) :
p.subtype.comp (codRestrict p f h) = f :=
ext fun _ => rfl
/-- The equivalence between a substructure `s` and its image `s.map f.toHom`, where `f` is an
embedding. -/
noncomputable def substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) :
s ≃[L] s.map f.toHom where
toFun := codRestrict (s.map f.toHom) (f.domRestrict s) fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩
invFun n := ⟨Classical.choose n.2, (Classical.choose_spec n.2).1⟩
left_inv := fun ⟨m, hm⟩ =>
Subtype.mk_eq_mk.2
(f.injective
(Classical.choose_spec
(codRestrict (s.map f.toHom) (f.domRestrict s) (fun ⟨m, hm⟩ => ⟨m, hm, rfl⟩)
⟨m, hm⟩).2).2)
right_inv := fun ⟨_, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn).2
map_fun' {n} f x := by simp
map_rel' {n} R x := by simp
@[simp]
theorem substructureEquivMap_apply (f : M ↪[L] N) (p : L.Substructure M) (x : p) :
(f.substructureEquivMap p x : N) = f x :=
rfl
@[simp]
theorem subtype_substructureEquivMap (f : M ↪[L] N) (s : L.Substructure M) :
(subtype _).comp (f.substructureEquivMap s).toEmbedding = f.comp (subtype _) := by
ext; rfl
/-- The equivalence between the domain and the range of an embedding `f`. -/
@[simps toEquiv_apply] noncomputable def equivRange (f : M ↪[L] N) : M ≃[L] f.toHom.range where
toFun := codRestrict f.toHom.range f f.toHom.mem_range_self
invFun n := Classical.choose n.2
left_inv m :=
f.injective (Classical.choose_spec (codRestrict f.toHom.range f f.toHom.mem_range_self m).2)
right_inv := fun ⟨_, hn⟩ => Subtype.mk_eq_mk.2 (Classical.choose_spec hn)
map_fun' {n} f x := by simp
map_rel' {n} R x := by simp
@[simp]
theorem equivRange_apply (f : M ↪[L] N) (x : M) : (f.equivRange x : N) = f x :=
rfl
@[simp]
theorem subtype_equivRange (f : M ↪[L] N) : (subtype _).comp f.equivRange.toEmbedding = f := by
ext; rfl
end Embedding
namespace Equiv
theorem toHom_range (f : M ≃[L] N) : f.toHom.range = ⊤ := by
ext n
simp only [Hom.mem_range, coe_toHom, Substructure.mem_top, iff_true]
exact ⟨f.symm n, apply_symm_apply _ _⟩
end Equiv
namespace Substructure
/-- The embedding associated to an inclusion of substructures. -/
def inclusion {S T : L.Substructure M} (h : S ≤ T) : S ↪[L] T :=
S.subtype.codRestrict _ fun x => h x.2
@[simp]
theorem inclusion_self (S : L.Substructure M) : inclusion (le_refl S) = Embedding.refl L S := rfl
@[simp]
theorem coe_inclusion {S T : L.Substructure M} (h : S ≤ T) :
(inclusion h : S → T) = Set.inclusion h :=
rfl
theorem range_subtype (S : L.Substructure M) : S.subtype.toHom.range = S := by
ext x
simp only [Hom.mem_range, Embedding.coe_toHom, coe_subtype]
refine ⟨?_, fun h => ⟨⟨x, h⟩, rfl⟩⟩
rintro ⟨⟨y, hy⟩, rfl⟩
exact hy
@[simp]
lemma subtype_comp_inclusion {S T : L.Substructure M} (h : S ≤ T) :
T.subtype.comp (inclusion h) = S.subtype := rfl
end Substructure
end Language
end FirstOrder
|
Sum.lean
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Group.Action.Faithful
/-!
# Sum instances for additive and multiplicative actions
This file defines instances for additive and multiplicative actions on the binary `Sum` type.
## See also
* `Mathlib/Algebra/Group/Action/Option.lean`
* `Mathlib/Algebra/Group/Action/Pi.lean`
* `Mathlib/Algebra/Group/Action/Prod.lean`
* `Mathlib/Algebra/Group/Action/Sigma.lean`
-/
assert_not_exists MonoidWithZero
variable {M N α β : Type*}
namespace Sum
section SMul
variable [SMul M α] [SMul M β] [SMul N α] [SMul N β] (a : M) (b : α) (c : β)
(x : α ⊕ β)
@[to_additive Sum.hasVAdd]
instance : SMul M (α ⊕ β) :=
⟨fun a => Sum.map (a • ·) (a • ·)⟩
@[to_additive]
theorem smul_def : a • x = x.map (a • ·) (a • ·) :=
rfl
@[to_additive (attr := simp)]
theorem smul_inl : a • (inl b : α ⊕ β) = inl (a • b) :=
rfl
@[to_additive (attr := simp)]
theorem smul_inr : a • (inr c : α ⊕ β) = inr (a • c) :=
rfl
@[to_additive (attr := simp)]
theorem smul_swap : (a • x).swap = a • x.swap := by cases x <;> rfl
instance [SMul M N] [IsScalarTower M N α] [IsScalarTower M N β] : IsScalarTower M N (α ⊕ β) :=
⟨fun a b x => by
cases x
exacts [congr_arg inl (smul_assoc _ _ _), congr_arg inr (smul_assoc _ _ _)]⟩
@[to_additive]
instance [SMulCommClass M N α] [SMulCommClass M N β] : SMulCommClass M N (α ⊕ β) :=
⟨fun a b x => by
cases x
exacts [congr_arg inl (smul_comm _ _ _), congr_arg inr (smul_comm _ _ _)]⟩
@[to_additive]
instance [SMul Mᵐᵒᵖ α] [SMul Mᵐᵒᵖ β] [IsCentralScalar M α] [IsCentralScalar M β] :
IsCentralScalar M (α ⊕ β) :=
⟨fun a x => by
cases x
exacts [congr_arg inl (op_smul_eq_smul _ _), congr_arg inr (op_smul_eq_smul _ _)]⟩
@[to_additive]
instance FaithfulSMulLeft [FaithfulSMul M α] : FaithfulSMul M (α ⊕ β) :=
⟨fun h => eq_of_smul_eq_smul fun a : α => by injection h (inl a)⟩
@[to_additive]
instance FaithfulSMulRight [FaithfulSMul M β] : FaithfulSMul M (α ⊕ β) :=
⟨fun h => eq_of_smul_eq_smul fun b : β => by injection h (inr b)⟩
end SMul
@[to_additive]
instance {m : Monoid M} [MulAction M α] [MulAction M β] :
MulAction M (α ⊕ β) where
mul_smul a b x := by
cases x
exacts [congr_arg inl (mul_smul _ _ _), congr_arg inr (mul_smul _ _ _)]
one_smul x := by
cases x
exacts [congr_arg inl (one_smul _ _), congr_arg inr (one_smul _ _)]
end Sum
|
Ext.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, Kim Morrison
-/
import Mathlib.Algebra.Group.Finsupp
import Mathlib.Algebra.Group.Submonoid.Basic
import Mathlib.Algebra.Group.TypeTags.Hom
/-!
# Extensionality for maps on `Finsupp`
This file contains some extensionality principles for maps on `Finsupp`.
These have been moved to their own file to avoid depending on submonoids when defining `Finsupp`.
## Main results
* `Finsupp.add_closure_setOf_eq_single`: `Finsupp` is generated by all the `single`s
* `Finsupp.addHom_ext`: additive homomorphisms that are equal on each `single` are equal everywhere
-/
variable {α M N : Type*}
namespace Finsupp
variable [AddZeroClass M]
@[simp]
theorem add_closure_setOf_eq_single :
AddSubmonoid.closure { f : α →₀ M | ∃ a b, f = single a b } = ⊤ :=
top_unique fun x _hx =>
Finsupp.induction x (AddSubmonoid.zero_mem _) fun a b _f _ha _hb hf =>
AddSubmonoid.add_mem _ (AddSubmonoid.subset_closure <| ⟨a, b, rfl⟩) hf
/-- If two additive homomorphisms from `α →₀ M` are equal on each `single a b`,
then they are equal. -/
theorem addHom_ext [AddZeroClass N] ⦃f g : (α →₀ M) →+ N⦄
(H : ∀ x y, f (single x y) = g (single x y)) : f = g := by
refine AddMonoidHom.eq_of_eqOn_denseM add_closure_setOf_eq_single ?_
rintro _ ⟨x, y, rfl⟩
apply H
/-- If two additive homomorphisms from `α →₀ M` are equal on each `single a b`,
then they are equal.
We formulate this using equality of `AddMonoidHom`s so that `ext` tactic can apply a type-specific
extensionality lemma after this one. E.g., if the fiber `M` is `ℕ` or `ℤ`, then it suffices to
verify `f (single a 1) = g (single a 1)`. -/
@[ext high]
theorem addHom_ext' [AddZeroClass N] ⦃f g : (α →₀ M) →+ N⦄
(H : ∀ x, f.comp (singleAddHom x) = g.comp (singleAddHom x)) : f = g :=
addHom_ext fun x => DFunLike.congr_fun (H x)
theorem mulHom_ext [MulOneClass N] ⦃f g : Multiplicative (α →₀ M) →* N⦄
(H : ∀ x y, f (Multiplicative.ofAdd <| single x y) = g (Multiplicative.ofAdd <| single x y)) :
f = g :=
MonoidHom.ext <|
DFunLike.congr_fun <| by
have := addHom_ext (f := MonoidHom.toAdditive'' f) (g := MonoidHom.toAdditive'' g) H
ext
rw [DFunLike.ext_iff] at this
apply this
@[ext]
theorem mulHom_ext' [MulOneClass N] {f g : Multiplicative (α →₀ M) →* N}
(H : ∀ x, f.comp (AddMonoidHom.toMultiplicative (singleAddHom x)) =
g.comp (AddMonoidHom.toMultiplicative (singleAddHom x))) :
f = g :=
mulHom_ext fun x => DFunLike.congr_fun (H x)
end Finsupp
|
Square.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Square
import Mathlib.CategoryTheory.Limits.Yoneda
import Mathlib.CategoryTheory.Limits.Preserves.Ulift
/-!
# Preservations of pullback/pushout squares
If a functor `F : C ⥤ D` preserves suitable cospans (resp. spans),
and `sq : Square C` is a pullback square (resp. a pushout square)
then so is the square`sq.map F`.
The lemma `Square.isPullback_iff_map_coyoneda_isPullback` also
shows that a square is a pullback square iff it is so after the
application of the functor `coyoneda.obj X` for all `X : Cᵒᵖ`.
Similarly, a square is a pushout square iff the opposite
square becomes a pullback square after the application of the
functor `yoneda.obj X` for all `X : C`.
-/
universe v v' u u'
namespace CategoryTheory
open Opposite Limits
variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
namespace Square
variable {sq : Square C}
lemma IsPullback.map (h : sq.IsPullback) (F : C ⥤ D) [PreservesLimit (cospan sq.f₂₄ sq.f₃₄) F] :
(sq.map F).IsPullback :=
Square.IsPullback.mk _ (isLimitPullbackConeMapOfIsLimit F sq.fac h.isLimit)
lemma IsPullback.of_map (F : C ⥤ D) [ReflectsLimit (cospan sq.f₂₄ sq.f₃₄) F]
(h : (sq.map F).IsPullback) : sq.IsPullback :=
CategoryTheory.IsPullback.of_map F sq.fac h
variable (sq) in
lemma IsPullback.map_iff (F : C ⥤ D) [PreservesLimit (cospan sq.f₂₄ sq.f₃₄) F]
[ReflectsLimit (cospan sq.f₂₄ sq.f₃₄) F] :
(sq.map F).IsPullback ↔ sq.IsPullback :=
⟨fun h ↦ of_map F h, fun h ↦ h.map F⟩
lemma IsPushout.map (h : sq.IsPushout) (F : C ⥤ D) [PreservesColimit (span sq.f₁₂ sq.f₁₃) F] :
(sq.map F).IsPushout :=
Square.IsPushout.mk _ (isColimitPushoutCoconeMapOfIsColimit F sq.fac h.isColimit)
lemma IsPushout.of_map (F : C ⥤ D) [ReflectsColimit (span sq.f₁₂ sq.f₁₃) F]
(h : (sq.map F).IsPushout) : sq.IsPushout :=
CategoryTheory.IsPushout.of_map F sq.fac h
variable (sq) in
lemma IsPushout.map_iff (F : C ⥤ D) [PreservesColimit (span sq.f₁₂ sq.f₁₃) F]
[ReflectsColimit (span sq.f₁₂ sq.f₁₃) F] :
(sq.map F).IsPushout ↔ sq.IsPushout :=
⟨fun h ↦ of_map F h, fun h ↦ h.map F⟩
variable (sq)
lemma isPullback_iff_map_coyoneda_isPullback :
sq.IsPullback ↔ ∀ (X : Cᵒᵖ), (sq.map (coyoneda.obj X)).IsPullback :=
⟨fun h _ ↦ h.map _, fun h ↦ IsPullback.mk _
((sq.pullbackCone.isLimitCoyonedaEquiv).symm (fun X ↦ (h X).isLimit))⟩
lemma isPushout_iff_op_map_yoneda_isPullback :
sq.IsPushout ↔ ∀ (X : C), (sq.op.map (yoneda.obj X)).IsPullback :=
⟨fun h _ ↦ h.op.map _, fun h ↦ IsPushout.mk _
((sq.pushoutCocone.isColimitYonedaEquiv).symm
(fun X ↦ IsLimit.ofIsoLimit (h X).isLimit (PullbackCone.ext (Iso.refl _))))⟩
section
variable {sq₁ : Square (Type v)} {sq₂ : Square (Type u)}
(e₁ : sq₁.X₁ ≃ sq₂.X₁) (e₂ : sq₁.X₂ ≃ sq₂.X₂)
(e₃ : sq₁.X₃ ≃ sq₂.X₃) (e₄ : sq₁.X₄ ≃ sq₂.X₄)
(comm₁₂ : e₂ ∘ sq₁.f₁₂ = sq₂.f₁₂ ∘ e₁)
(comm₁₃ : e₃ ∘ sq₁.f₁₃ = sq₂.f₁₃ ∘ e₁)
(comm₂₄ : e₄ ∘ sq₁.f₂₄ = sq₂.f₂₄ ∘ e₂)
(comm₃₄ : e₄ ∘ sq₁.f₃₄ = sq₂.f₃₄ ∘ e₃)
include comm₁₂ comm₁₃ comm₂₄ comm₃₄
variable (sq₁ sq₂) in
lemma IsPullback.iff_of_equiv : sq₁.IsPullback ↔ sq₂.IsPullback := by
rw [← IsPullback.map_iff sq₁ uliftFunctor.{max u v},
← IsPullback.map_iff sq₂ uliftFunctor.{max u v}]
refine iff_of_iso (Square.isoMk
(((Equiv.trans Equiv.ulift e₁).trans Equiv.ulift.symm).toIso)
(((Equiv.trans Equiv.ulift e₂).trans Equiv.ulift.symm).toIso)
(((Equiv.trans Equiv.ulift e₃).trans Equiv.ulift.symm).toIso)
(((Equiv.trans Equiv.ulift e₄).trans Equiv.ulift.symm).toIso)
?_ ?_ ?_ ?_)
all_goals ext; apply ULift.down_injective
· simpa [types_comp, uliftFunctor_map] using congrFun comm₁₂ _
· simpa [types_comp, uliftFunctor_map] using congrFun comm₁₃ _
· simpa [types_comp, uliftFunctor_map] using congrFun comm₂₄ _
· simpa [types_comp, uliftFunctor_map] using congrFun comm₃₄ _
lemma IsPullback.of_equiv (h₁ : sq₁.IsPullback) : sq₂.IsPullback :=
(iff_of_equiv sq₁ sq₂ e₁ e₂ e₃ e₄ comm₁₂ comm₁₃ comm₂₄ comm₃₄).1 h₁
end
end Square
end CategoryTheory
|
GCD.lean
|
/-
Copyright (c) 2018 Guy Leroy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sangwoo Jo (aka Jason), Guy Leroy, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Semiconj
import Mathlib.Algebra.Group.Commute.Units
import Mathlib.Data.Set.Operations
import Mathlib.Order.Basic
import Mathlib.Order.Bounds.Defs
import Mathlib.Algebra.Group.Int.Defs
import Mathlib.Data.Int.Basic
import Batteries.Data.Nat.Gcd
import Mathlib.Algebra.Divisibility.Basic
import Mathlib.Algebra.Group.Nat.Defs
/-!
# Extended GCD and divisibility over ℤ
## Main definitions
* Given `x y : ℕ`, `xgcd x y` computes the pair of integers `(a, b)` such that
`gcd x y = x * a + y * b`. `gcdA x y` and `gcdB x y` are defined to be `a` and `b`,
respectively.
## Main statements
* `gcd_eq_gcd_ab`: Bézout's lemma, given `x y : ℕ`, `gcd x y = x * gcdA x y + y * gcdB x y`.
## Tags
Bézout's lemma, Bezout's lemma
-/
/-! ### Extended Euclidean algorithm -/
namespace Nat
/-- Helper function for the extended GCD algorithm (`Nat.xgcd`). -/
def xgcdAux : ℕ → ℤ → ℤ → ℕ → ℤ → ℤ → ℕ × ℤ × ℤ
| 0, _, _, r', s', t' => (r', s', t')
| succ k, s, t, r', s', t' =>
let q := r' / succ k
xgcdAux (r' % succ k) (s' - q * s) (t' - q * t) (succ k) s t
termination_by k => k
decreasing_by exact mod_lt _ <| (succ_pos _).gt
@[simp]
theorem xgcd_zero_left {s t r' s' t'} : xgcdAux 0 s t r' s' t' = (r', s', t') := by simp [xgcdAux]
theorem xgcdAux_rec {r s t r' s' t'} (h : 0 < r) :
xgcdAux r s t r' s' t' = xgcdAux (r' % r) (s' - r' / r * s) (t' - r' / r * t) r s t := by
obtain ⟨r, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h.ne'
simp [xgcdAux]
/-- Use the extended GCD algorithm to generate the `a` and `b` values
satisfying `gcd x y = x * a + y * b`. -/
def xgcd (x y : ℕ) : ℤ × ℤ :=
(xgcdAux x 1 0 y 0 1).2
/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/
def gcdA (x y : ℕ) : ℤ :=
(xgcd x y).1
/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/
def gcdB (x y : ℕ) : ℤ :=
(xgcd x y).2
@[simp]
theorem gcdA_zero_left {s : ℕ} : gcdA 0 s = 0 := by
unfold gcdA
rw [xgcd, xgcd_zero_left]
@[simp]
theorem gcdB_zero_left {s : ℕ} : gcdB 0 s = 1 := by
unfold gcdB
rw [xgcd, xgcd_zero_left]
@[simp]
theorem gcdA_zero_right {s : ℕ} (h : s ≠ 0) : gcdA s 0 = 1 := by
unfold gcdA xgcd
obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
rw [xgcdAux]
simp
@[simp]
theorem gcdB_zero_right {s : ℕ} (h : s ≠ 0) : gcdB s 0 = 0 := by
unfold gcdB xgcd
obtain ⟨s, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h
rw [xgcdAux]
simp
@[simp]
theorem xgcdAux_fst (x y) : ∀ s t s' t', (xgcdAux x s t y s' t').1 = gcd x y :=
gcd.induction x y (by simp) fun x y h IH s t s' t' => by
simp only [h, xgcdAux_rec, IH]
rw [← gcd_rec]
theorem xgcdAux_val (x y) : xgcdAux x 1 0 y 0 1 = (gcd x y, xgcd x y) := by
rw [xgcd, ← xgcdAux_fst x y 1 0 0 1]
theorem xgcd_val (x y) : xgcd x y = (gcdA x y, gcdB x y) := by
unfold gcdA gcdB; constructor
section
variable (x y : ℕ)
private def P : ℕ × ℤ × ℤ → Prop
| (r, s, t) => (r : ℤ) = x * s + y * t
theorem xgcdAux_P {r r'} :
∀ {s t s' t'}, P x y (r, s, t) → P x y (r', s', t') → P x y (xgcdAux r s t r' s' t') := by
induction r, r' using gcd.induction with
| H0 => simp
| H1 a b h IH =>
intro s t s' t' p p'
rw [xgcdAux_rec h]; refine IH ?_ p; dsimp [P] at *
rw [Int.emod_def]; generalize (b / a : ℤ) = k
rw [p, p', Int.mul_sub, sub_add_eq_add_sub, Int.mul_sub, Int.add_mul, mul_comm k t,
mul_comm k s, ← mul_assoc, ← mul_assoc, add_comm (x * s * k), ← add_sub_assoc, sub_sub]
/-- **Bézout's lemma**: given `x y : ℕ`, `gcd x y = x * a + y * b`, where `a = gcd_a x y` and
`b = gcd_b x y` are computed by the extended Euclidean algorithm.
-/
theorem gcd_eq_gcd_ab : (gcd x y : ℤ) = x * gcdA x y + y * gcdB x y := by
have := @xgcdAux_P x y x y 1 0 0 1 (by simp [P]) (by simp [P])
rwa [xgcdAux_val, xgcd_val] at this
end
theorem exists_mul_emod_eq_gcd {k n : ℕ} (hk : gcd n k < k) : ∃ m, n * m % k = gcd n k := by
have hk' := Int.ofNat_ne_zero.2 (ne_of_gt (lt_of_le_of_lt (zero_le (gcd n k)) hk))
have key := congr_arg (fun (m : ℤ) => (m % k).toNat) (gcd_eq_gcd_ab n k)
simp only at key
rw [Int.add_mul_emod_self_left, ← Int.natCast_mod, Int.toNat_natCast, mod_eq_of_lt hk] at key
refine ⟨(n.gcdA k % k).toNat, Eq.trans (Int.ofNat.inj ?_) key.symm⟩
rw [Int.ofNat_eq_coe, Int.natCast_mod, Int.natCast_mul,
Int.toNat_of_nonneg (Int.emod_nonneg _ hk'), Int.ofNat_eq_coe,
Int.toNat_of_nonneg (Int.emod_nonneg _ hk'), Int.mul_emod, Int.emod_emod, ← Int.mul_emod]
theorem exists_mul_emod_eq_one_of_coprime {k n : ℕ} (hkn : Coprime n k) (hk : 1 < k) :
∃ m, n * m % k = 1 :=
Exists.recOn (exists_mul_emod_eq_gcd (lt_of_le_of_lt (le_of_eq hkn) hk)) fun m hm ↦
⟨m, hm.trans hkn⟩
end Nat
/-! ### Divisibility over ℤ -/
namespace Int
theorem gcd_def (i j : ℤ) : gcd i j = Nat.gcd i.natAbs j.natAbs := rfl
/-- The extended GCD `a` value in the equation `gcd x y = x * a + y * b`. -/
def gcdA : ℤ → ℤ → ℤ
| ofNat m, n => m.gcdA n.natAbs
| -[m+1], n => -m.succ.gcdA n.natAbs
/-- The extended GCD `b` value in the equation `gcd x y = x * a + y * b`. -/
def gcdB : ℤ → ℤ → ℤ
| m, ofNat n => m.natAbs.gcdB n
| m, -[n+1] => -m.natAbs.gcdB n.succ
/-- **Bézout's lemma** -/
theorem gcd_eq_gcd_ab : ∀ x y : ℤ, (gcd x y : ℤ) = x * gcdA x y + y * gcdB x y
| (m : ℕ), (n : ℕ) => Nat.gcd_eq_gcd_ab _ _
| (m : ℕ), -[n+1] =>
show (_ : ℤ) = _ + -(n + 1) * -_ by rw [Int.neg_mul_neg]; apply Nat.gcd_eq_gcd_ab
| -[m+1], (n : ℕ) =>
show (_ : ℤ) = -(m + 1) * -_ + _ by rw [Int.neg_mul_neg]; apply Nat.gcd_eq_gcd_ab
| -[m+1], -[n+1] =>
show (_ : ℤ) = -(m + 1) * -_ + -(n + 1) * -_ by
rw [Int.neg_mul_neg, Int.neg_mul_neg]
apply Nat.gcd_eq_gcd_ab
theorem lcm_def (i j : ℤ) : lcm i j = Nat.lcm (natAbs i) (natAbs j) :=
rfl
@[deprecated (since := "2025-04-04")] alias coe_nat_lcm := Int.lcm_natCast_natCast
alias gcd_div := gcd_ediv
alias gcd_div_gcd_div_gcd := gcd_ediv_gcd_ediv_gcd
@[deprecated (since := "2025-04-04")] alias gcd_dvd_gcd_mul_left := gcd_dvd_gcd_mul_left_left
@[deprecated (since := "2025-04-04")] alias gcd_dvd_gcd_mul_right := gcd_dvd_gcd_mul_right_left
/-- If `gcd a (m * n) = 1`, then `gcd a m = 1`. -/
theorem gcd_eq_one_of_gcd_mul_right_eq_one_left {a : ℤ} {m n : ℕ} (h : a.gcd (m * n) = 1) :
a.gcd m = 1 :=
Nat.dvd_one.mp <| h ▸ gcd_dvd_gcd_mul_right_right a m n
/-- If `gcd a (m * n) = 1`, then `gcd a n = 1`. -/
theorem gcd_eq_one_of_gcd_mul_right_eq_one_right {a : ℤ} {m n : ℕ} (h : a.gcd (m * n) = 1) :
a.gcd n = 1 :=
Nat.dvd_one.mp <| h ▸ gcd_dvd_gcd_mul_left_right a n m
theorem ne_zero_of_gcd {x y : ℤ} (hc : gcd x y ≠ 0) : x ≠ 0 ∨ y ≠ 0 := by
contrapose! hc
rw [hc.left, hc.right, gcd_zero_right, natAbs_zero]
theorem exists_gcd_one {m n : ℤ} (H : 0 < gcd m n) :
∃ m' n' : ℤ, gcd m' n' = 1 ∧ m = m' * gcd m n ∧ n = n' * gcd m n :=
⟨_, _, gcd_div_gcd_div_gcd H, (Int.ediv_mul_cancel (gcd_dvd_left ..)).symm,
(Int.ediv_mul_cancel (gcd_dvd_right ..)).symm⟩
theorem exists_gcd_one' {m n : ℤ} (H : 0 < gcd m n) :
∃ (g : ℕ) (m' n' : ℤ), 0 < g ∧ gcd m' n' = 1 ∧ m = m' * g ∧ n = n' * g :=
let ⟨m', n', h⟩ := exists_gcd_one H
⟨_, m', n', H, h⟩
theorem gcd_dvd_iff {a b : ℤ} {n : ℕ} : gcd a b ∣ n ↔ ∃ x y : ℤ, ↑n = a * x + b * y := by
constructor
· intro h
rw [← Nat.mul_div_cancel' h, Int.natCast_mul, gcd_eq_gcd_ab, Int.add_mul, mul_assoc, mul_assoc]
exact ⟨_, _, rfl⟩
· rintro ⟨x, y, h⟩
rw [← Int.natCast_dvd_natCast, h]
exact Int.dvd_add (dvd_mul_of_dvd_left (gcd_dvd_left ..) _)
(dvd_mul_of_dvd_left (gcd_dvd_right ..) y)
theorem gcd_greatest {a b d : ℤ} (hd_pos : 0 ≤ d) (hda : d ∣ a) (hdb : d ∣ b)
(hd : ∀ e : ℤ, e ∣ a → e ∣ b → e ∣ d) : d = gcd a b :=
dvd_antisymm hd_pos (ofNat_zero_le (gcd a b)) (dvd_coe_gcd hda hdb)
(hd _ (gcd_dvd_left ..) (gcd_dvd_right ..))
/-- Euclid's lemma: if `a ∣ b * c` and `gcd a c = 1` then `a ∣ b`.
Compare with `IsCoprime.dvd_of_dvd_mul_left` and
`UniqueFactorizationMonoid.dvd_of_dvd_mul_left_of_no_prime_factors` -/
theorem dvd_of_dvd_mul_left_of_gcd_one {a b c : ℤ} (habc : a ∣ b * c) (hab : gcd a c = 1) :
a ∣ b := by
have := gcd_eq_gcd_ab a c
simp only [hab, Int.ofNat_zero, Int.natCast_succ, zero_add] at this
have : b * a * gcdA a c + b * c * gcdB a c = b := by simp [mul_assoc, ← Int.mul_add, ← this]
rw [← this]
exact Int.dvd_add (dvd_mul_of_dvd_left (dvd_mul_left a b) _) (dvd_mul_of_dvd_left habc _)
/-- Euclid's lemma: if `a ∣ b * c` and `gcd a b = 1` then `a ∣ c`.
Compare with `IsCoprime.dvd_of_dvd_mul_right` and
`UniqueFactorizationMonoid.dvd_of_dvd_mul_right_of_no_prime_factors` -/
theorem dvd_of_dvd_mul_right_of_gcd_one {a b c : ℤ} (habc : a ∣ b * c) (hab : gcd a b = 1) :
a ∣ c := by
rw [mul_comm] at habc
exact dvd_of_dvd_mul_left_of_gcd_one habc hab
/-- For nonzero integers `a` and `b`, `gcd a b` is the smallest positive natural number that can be
written in the form `a * x + b * y` for some pair of integers `x` and `y` -/
theorem gcd_least_linear {a b : ℤ} (ha : a ≠ 0) :
IsLeast { n : ℕ | 0 < n ∧ ∃ x y : ℤ, ↑n = a * x + b * y } (a.gcd b) := by
simp_rw [← gcd_dvd_iff]
constructor
· simpa [and_true, dvd_refl, Set.mem_setOf_eq] using gcd_pos_of_ne_zero_left b ha
· simp only [lowerBounds, and_imp, Set.mem_setOf_eq]
exact fun n hn_pos hn => Nat.le_of_dvd hn_pos hn
end Int
@[to_additive gcd_nsmul_eq_zero]
theorem pow_gcd_eq_one {M : Type*} [Monoid M] (x : M) {m n : ℕ} (hm : x ^ m = 1) (hn : x ^ n = 1) :
x ^ m.gcd n = 1 := by
rcases m with (rfl | m); · simp [hn]
obtain ⟨y, rfl⟩ := IsUnit.of_pow_eq_one hm m.succ_ne_zero
rw [← Units.val_pow_eq_pow_val, ← Units.val_one (α := M), ← zpow_natCast, ← Units.ext_iff] at *
rw [Nat.gcd_eq_gcd_ab, zpow_add, zpow_mul, zpow_mul, hn, hm, one_zpow, one_zpow, one_mul]
variable {α : Type*}
section GroupWithZero
variable [GroupWithZero α] {a b : α} {m n : ℕ}
protected lemma Commute.pow_eq_pow_iff_of_coprime (hab : Commute a b) (hmn : m.Coprime n) :
a ^ m = b ^ n ↔ ∃ c, a = c ^ n ∧ b = c ^ m := by
refine ⟨fun h ↦ ?_, by rintro ⟨c, rfl, rfl⟩; rw [← pow_mul, ← pow_mul']⟩
by_cases m = 0; · aesop
by_cases n = 0; · aesop
by_cases hb : b = 0; · exact ⟨0, by aesop⟩
by_cases ha : a = 0; · exact ⟨0, by have := h.symm; aesop⟩
refine ⟨a ^ Nat.gcdB m n * b ^ Nat.gcdA m n, ?_, ?_⟩ <;>
· refine (pow_one _).symm.trans ?_
conv_lhs => rw [← zpow_natCast, ← hmn, Nat.gcd_eq_gcd_ab]
simp only [zpow_add₀ ha, zpow_add₀ hb, ← zpow_natCast, (hab.zpow_zpow₀ _ _).mul_zpow,
← zpow_mul, mul_comm (Nat.gcdB m n), mul_comm (Nat.gcdA m n)]
simp only [zpow_mul, zpow_natCast, h]
exact ((Commute.pow_pow (by aesop) _ _).zpow_zpow₀ _ _).symm
end GroupWithZero
section CommGroupWithZero
variable [CommGroupWithZero α] {a b : α} {m n : ℕ}
lemma pow_eq_pow_iff_of_coprime (hmn : m.Coprime n) : a ^ m = b ^ n ↔ ∃ c, a = c ^ n ∧ b = c ^ m :=
(Commute.all _ _).pow_eq_pow_iff_of_coprime hmn
lemma pow_mem_range_pow_of_coprime (hmn : m.Coprime n) (a : α) :
a ^ m ∈ Set.range (· ^ n : α → α) ↔ a ∈ Set.range (· ^ n : α → α) := by
simp [pow_eq_pow_iff_of_coprime hmn.symm]; aesop
end CommGroupWithZero
|
Real.lean
|
/-
! This file was ported from Lean 3 source file `test/real.lean`
! leanprover-community/mathlib commit d7943885503965d07ccaeb390d65fbc3f45962e6
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Real.Basic
private axiom test_sorry : ∀ {α}, α
unsafe def testRepr (r : ℝ) (s : String) : Lean.Elab.Command.CommandElabM Unit :=
unless toString (repr r) = s do throwError "got {repr r}"
run_cmd unsafe testRepr 0 "Real.ofCauchy (sorry /- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ... -/)"
run_cmd unsafe testRepr 1 "Real.ofCauchy (sorry /- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... -/)"
run_cmd
unsafe testRepr (37 : ℕ) "Real.ofCauchy (sorry /- 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, ... -/)"
run_cmd unsafe testRepr (2 + 3) "Real.ofCauchy (sorry /- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, ... -/)"
run_cmd unsafe testRepr ⟨CauSeq.Completion.mk <| ⟨fun n ↦ 2^(-n:ℤ), test_sorry⟩⟩
"Real.ofCauchy (sorry /- 1, (1 : Rat)/2, (1 : Rat)/4, (1 : Rat)/8, \
(1 : Rat)/16, (1 : Rat)/32, (1 : Rat)/64, (1 : Rat)/128, (1 : Rat)/256, \
(1 : Rat)/512, ... -/)"
|
ScottContinuity.lean
|
/-
Copyright (c) 2022 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin
-/
import Mathlib.Order.Bounds.Basic
/-!
# Scott continuity
A function `f : α → β` between preorders is Scott continuous (referring to Dana Scott) if it
distributes over `IsLUB`. Scott continuity corresponds to continuity in Scott topological spaces
(defined in `Mathlib/Topology/Order/ScottTopology.lean`). It is distinct from the (more commonly
used) continuity from topology (see `Mathlib/Topology/Basic.lean`).
## Implementation notes
Given a set `D` of directed sets, we define say `f` is `ScottContinuousOn D` if it distributes over
`IsLUB` for all elements of `D`. This allows us to consider Scott Continuity on all directed sets
in this file, and ωScott Continuity on chains later in
`Mathlib/Order/OmegaCompletePartialOrder.lean`.
## References
* [Abramsky and Jung, *Domain Theory*][abramsky_gabbay_maibaum_1994]
* [Gierz et al, *A Compendium of Continuous Lattices*][GierzEtAl1980]
-/
open Set
variable {α β : Type*}
section ScottContinuous
variable [Preorder α] [Preorder β] {D D₁ D₂ : Set (Set α)}
{f : α → β}
/-- A function between preorders is said to be Scott continuous on a set `D` of directed sets if it
preserves `IsLUB` on elements of `D`.
The dual notion
```lean
∀ ⦃d : Set α⦄, d ∈ D → d.Nonempty → DirectedOn (· ≥ ·) d → ∀ ⦃a⦄, IsGLB d a → IsGLB (f '' d) (f a)
```
does not appear to play a significant role in the literature, so is omitted here.
-/
def ScottContinuousOn (D : Set (Set α)) (f : α → β) : Prop :=
∀ ⦃d : Set α⦄, d ∈ D → d.Nonempty → DirectedOn (· ≤ ·) d → ∀ ⦃a⦄, IsLUB d a → IsLUB (f '' d) (f a)
lemma ScottContinuousOn.mono (hD : D₁ ⊆ D₂) (hf : ScottContinuousOn D₂ f) :
ScottContinuousOn D₁ f := fun _ hdD₁ hd₁ hd₂ _ hda => hf (hD hdD₁) hd₁ hd₂ hda
protected theorem ScottContinuousOn.monotone (D : Set (Set α)) (hD : ∀ a b : α, a ≤ b → {a, b} ∈ D)
(h : ScottContinuousOn D f) : Monotone f := by
refine fun a b hab =>
(h (hD a b hab) (insert_nonempty _ _) (directedOn_pair le_refl hab) ?_).1
(mem_image_of_mem _ <| mem_insert _ _)
rw [IsLUB, upperBounds_insert, upperBounds_singleton,
inter_eq_self_of_subset_right (Ici_subset_Ici.2 hab)]
exact isLeast_Ici
@[simp] lemma ScottContinuousOn.id : ScottContinuousOn D (id : α → α) := by simp [ScottContinuousOn]
variable {g : α → β}
lemma ScottContinuousOn.prodMk (hD : ∀ a b : α, a ≤ b → {a, b} ∈ D)
(hf : ScottContinuousOn D f) (hg : ScottContinuousOn D g) :
ScottContinuousOn D fun x => (f x, g x) := fun d hd₁ hd₂ hd₃ a hda => by
rw [IsLUB, IsLeast, upperBounds]
constructor
· simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, mem_setOf_eq,
Prod.mk_le_mk]
intro b hb
exact ⟨hf.monotone D hD (hda.1 hb), hg.monotone D hD (hda.1 hb)⟩
· intro ⟨p₁, p₂⟩ hp
simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, mem_setOf_eq,
Prod.mk_le_mk] at hp
constructor
· rw [isLUB_le_iff (hf hd₁ hd₂ hd₃ hda), upperBounds]
simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, mem_setOf_eq]
intro _ hb
exact (hp _ hb).1
· rw [isLUB_le_iff (hg hd₁ hd₂ hd₃ hda), upperBounds]
simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, mem_setOf_eq]
intro _ hb
exact (hp _ hb).2
/-- A function between preorders is said to be Scott continuous if it preserves `IsLUB` on directed
sets. It can be shown that a function is Scott continuous if and only if it is continuous wrt the
Scott topology.
-/
def ScottContinuous (f : α → β) : Prop :=
∀ ⦃d : Set α⦄, d.Nonempty → DirectedOn (· ≤ ·) d → ∀ ⦃a⦄, IsLUB d a → IsLUB (f '' d) (f a)
@[simp] lemma scottContinuousOn_univ : ScottContinuousOn univ f ↔ ScottContinuous f := by
simp [ScottContinuousOn, ScottContinuous]
lemma ScottContinuous.scottContinuousOn {D : Set (Set α)} :
ScottContinuous f → ScottContinuousOn D f := fun h _ _ d₂ d₃ _ hda => h d₂ d₃ hda
protected theorem ScottContinuous.monotone (h : ScottContinuous f) : Monotone f :=
h.scottContinuousOn.monotone univ (fun _ _ _ ↦ mem_univ _)
@[simp] lemma ScottContinuous.id : ScottContinuous (id : α → α) := by simp [ScottContinuous]
end ScottContinuous
section SemilatticeSup
variable [SemilatticeSup β]
lemma ScottContinuous.sup₂ :
ScottContinuous fun b : β × β => (b.1 ⊔ b.2 : β) := fun d _ _ ⟨p₁, p₂⟩ hdp => by
simp only [IsLUB, IsLeast, upperBounds, Prod.forall, mem_setOf_eq, Prod.mk_le_mk] at hdp
simp only [IsLUB, IsLeast, upperBounds, mem_image, Prod.exists, forall_exists_index, and_imp]
have e1 : (p₁, p₂) ∈ lowerBounds {x | ∀ (b₁ b₂ : β), (b₁, b₂) ∈ d → (b₁, b₂) ≤ x} := hdp.2
simp only [lowerBounds, mem_setOf_eq, Prod.forall, Prod.mk_le_mk] at e1
refine ⟨fun a b₁ b₂ hbd hba => ?_,fun b hb => ?_⟩
· rw [← hba]
exact sup_le_sup (hdp.1 _ _ hbd).1 (hdp.1 _ _ hbd).2
· rw [sup_le_iff]
exact e1 _ _ fun b₁ b₂ hb' => sup_le_iff.mp (hb b₁ b₂ hb' rfl)
lemma ScottContinuousOn.sup₂ {D : Set (Set (β × β))} :
ScottContinuousOn D fun (a, b) => (a ⊔ b : β) :=
ScottContinuous.sup₂.scottContinuousOn
end SemilatticeSup
|
Regular.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.Tactic.StacksAttribute
import Mathlib.Topology.Compactness.Lindelof
import Mathlib.Topology.Separation.Hausdorff
import Mathlib.Topology.Connected.Clopen
/-!
# Regular, normal, T₃, T₄ and T₅ spaces
This file continues the study of separation properties of topological spaces, focusing
on conditions strictly stronger than T₂.
## Main definitions
* `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`,
there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily
Hausdorff.
* `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅.
* `NormalSpace`: A normal space, is one where given two disjoint closed sets,
we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if
it is T₀.
* `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃.
* `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t`
such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`,
then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows
us to conclude that this is equivalent to all subspaces being normal. Such a space is not
necessarily Hausdorff or regular, even if it is T₀.
* `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄.
See `Mathlib/Topology/Separation/GDelta.lean` for the definitions of `PerfectlyNormalSpace` and
`T6Space`.
Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but
occasionally the literature swaps definitions for e.g. T₃ and regular.
## Main results
### Regular spaces
If the space is also Lindelöf:
* `NormalSpace.of_regularSpace_lindelofSpace`: every regular Lindelöf space is normal.
### T₃ spaces
* `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and
`y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint.
## References
* <https://en.wikipedia.org/wiki/Separation_axiom>
* <https://en.wikipedia.org/wiki/Normal_space>
* [Willard's *General Topology*][zbMATH02107988]
-/
assert_not_exists UniformSpace
open Function Set Filter Topology TopologicalSpace
universe u v
variable {X : Type*} {Y : Type*} [TopologicalSpace X]
section RegularSpace
/-- A topological space is called a *regular space* if for any closed set `s` and `a ∉ s`, there
exist disjoint open sets `U ⊇ s` and `V ∋ a`. We formulate this condition in terms of `Disjoint`ness
of filters `𝓝ˢ s` and `𝓝 a`. -/
@[mk_iff]
class RegularSpace (X : Type u) [TopologicalSpace X] : Prop where
/-- If `a` is a point that does not belong to a closed set `s`, then `a` and `s` admit disjoint
neighborhoods. -/
regular : ∀ {s : Set X} {a}, IsClosed s → a ∉ s → Disjoint (𝓝ˢ s) (𝓝 a)
theorem regularSpace_TFAE (X : Type u) [TopologicalSpace X] :
List.TFAE [RegularSpace X,
∀ (s : Set X) x, x ∉ closure s → Disjoint (𝓝ˢ s) (𝓝 x),
∀ (x : X) (s : Set X), Disjoint (𝓝ˢ s) (𝓝 x) ↔ x ∉ closure s,
∀ (x : X) (s : Set X), s ∈ 𝓝 x → ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s,
∀ x : X, (𝓝 x).lift' closure ≤ 𝓝 x,
∀ x : X , (𝓝 x).lift' closure = 𝓝 x] := by
tfae_have 1 ↔ 5 := by
rw [regularSpace_iff, (@compl_surjective (Set X) _).forall, forall_swap]
simp only [isClosed_compl_iff, mem_compl_iff, Classical.not_not, @and_comm (_ ∈ _),
(nhds_basis_opens _).lift'_closure.le_basis_iff (nhds_basis_opens _), and_imp,
(nhds_basis_opens _).disjoint_iff_right, ← subset_interior_iff_mem_nhdsSet,
interior_compl, compl_subset_compl]
tfae_have 5 → 6 := fun h a => (h a).antisymm (𝓝 _).le_lift'_closure
tfae_have 6 → 4
| H, a, s, hs => by
rw [← H] at hs
rcases (𝓝 a).basis_sets.lift'_closure.mem_iff.mp hs with ⟨U, hU, hUs⟩
exact ⟨closure U, mem_of_superset hU subset_closure, isClosed_closure, hUs⟩
tfae_have 4 → 2
| H, s, a, ha => by
have ha' : sᶜ ∈ 𝓝 a := by rwa [← mem_interior_iff_mem_nhds, interior_compl]
rcases H _ _ ha' with ⟨U, hU, hUc, hUs⟩
refine disjoint_of_disjoint_of_mem disjoint_compl_left ?_ hU
rwa [← subset_interior_iff_mem_nhdsSet, hUc.isOpen_compl.interior_eq, subset_compl_comm]
tfae_have 2 → 3 := by
refine fun H a s => ⟨fun hd has => mem_closure_iff_nhds_ne_bot.mp has ?_, H s a⟩
exact (hd.symm.mono_right <| @principal_le_nhdsSet _ _ s).eq_bot
tfae_have 3 → 1 := fun H => ⟨fun hs ha => (H _ _).mpr <| hs.closure_eq.symm ▸ ha⟩
tfae_finish
theorem RegularSpace.of_lift'_closure_le (h : ∀ x : X, (𝓝 x).lift' closure ≤ 𝓝 x) :
RegularSpace X :=
Iff.mpr ((regularSpace_TFAE X).out 0 4) h
theorem RegularSpace.of_lift'_closure (h : ∀ x : X, (𝓝 x).lift' closure = 𝓝 x) : RegularSpace X :=
Iff.mpr ((regularSpace_TFAE X).out 0 5) h
theorem RegularSpace.of_hasBasis {ι : X → Sort*} {p : ∀ a, ι a → Prop} {s : ∀ a, ι a → Set X}
(h₁ : ∀ a, (𝓝 a).HasBasis (p a) (s a)) (h₂ : ∀ a i, p a i → IsClosed (s a i)) :
RegularSpace X :=
.of_lift'_closure fun a => (h₁ a).lift'_closure_eq_self (h₂ a)
theorem RegularSpace.of_exists_mem_nhds_isClosed_subset
(h : ∀ (x : X), ∀ s ∈ 𝓝 x, ∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s) : RegularSpace X :=
Iff.mpr ((regularSpace_TFAE X).out 0 3) h
/-- A weakly locally compact R₁ space is regular. -/
instance (priority := 100) [WeaklyLocallyCompactSpace X] [R1Space X] : RegularSpace X :=
.of_hasBasis isCompact_isClosed_basis_nhds fun _ _ ⟨_, _, h⟩ ↦ h
section
variable [RegularSpace X] {x : X} {s : Set X}
theorem disjoint_nhdsSet_nhds : Disjoint (𝓝ˢ s) (𝓝 x) ↔ x ∉ closure s := by
have h := (regularSpace_TFAE X).out 0 2
exact h.mp ‹_› _ _
theorem disjoint_nhds_nhdsSet : Disjoint (𝓝 x) (𝓝ˢ s) ↔ x ∉ closure s :=
disjoint_comm.trans disjoint_nhdsSet_nhds
/-- A regular space is R₁. -/
instance (priority := 100) : R1Space X where
specializes_or_disjoint_nhds _ _ := or_iff_not_imp_left.2 fun h ↦ by
rwa [← nhdsSet_singleton, disjoint_nhdsSet_nhds, ← specializes_iff_mem_closure]
theorem exists_mem_nhds_isClosed_subset {x : X} {s : Set X} (h : s ∈ 𝓝 x) :
∃ t ∈ 𝓝 x, IsClosed t ∧ t ⊆ s := by
have h' := (regularSpace_TFAE X).out 0 3
exact h'.mp ‹_› _ _ h
theorem closed_nhds_basis (x : X) : (𝓝 x).HasBasis (fun s : Set X => s ∈ 𝓝 x ∧ IsClosed s) id :=
hasBasis_self.2 fun _ => exists_mem_nhds_isClosed_subset
theorem lift'_nhds_closure (x : X) : (𝓝 x).lift' closure = 𝓝 x :=
(closed_nhds_basis x).lift'_closure_eq_self fun _ => And.right
theorem Filter.HasBasis.nhds_closure {ι : Sort*} {x : X} {p : ι → Prop} {s : ι → Set X}
(h : (𝓝 x).HasBasis p s) : (𝓝 x).HasBasis p fun i => closure (s i) :=
lift'_nhds_closure x ▸ h.lift'_closure
theorem hasBasis_nhds_closure (x : X) : (𝓝 x).HasBasis (fun s => s ∈ 𝓝 x) closure :=
(𝓝 x).basis_sets.nhds_closure
theorem hasBasis_opens_closure (x : X) : (𝓝 x).HasBasis (fun s => x ∈ s ∧ IsOpen s) closure :=
(nhds_basis_opens x).nhds_closure
theorem IsCompact.exists_isOpen_closure_subset {K U : Set X} (hK : IsCompact K) (hU : U ∈ 𝓝ˢ K) :
∃ V, IsOpen V ∧ K ⊆ V ∧ closure V ⊆ U := by
have hd : Disjoint (𝓝ˢ K) (𝓝ˢ Uᶜ) := by
simpa [hK.disjoint_nhdsSet_left, disjoint_nhds_nhdsSet,
← subset_interior_iff_mem_nhdsSet] using hU
rcases ((hasBasis_nhdsSet _).disjoint_iff (hasBasis_nhdsSet _)).1 hd
with ⟨V, ⟨hVo, hKV⟩, W, ⟨hW, hUW⟩, hVW⟩
refine ⟨V, hVo, hKV, Subset.trans ?_ (compl_subset_comm.1 hUW)⟩
exact closure_minimal hVW.subset_compl_right hW.isClosed_compl
theorem IsCompact.lift'_closure_nhdsSet {K : Set X} (hK : IsCompact K) :
(𝓝ˢ K).lift' closure = 𝓝ˢ K := by
refine le_antisymm (fun U hU ↦ ?_) (le_lift'_closure _)
rcases hK.exists_isOpen_closure_subset hU with ⟨V, hVo, hKV, hVU⟩
exact mem_of_superset (mem_lift' <| hVo.mem_nhdsSet.2 hKV) hVU
theorem TopologicalSpace.IsTopologicalBasis.nhds_basis_closure {B : Set (Set X)}
(hB : IsTopologicalBasis B) (x : X) :
(𝓝 x).HasBasis (fun s : Set X => x ∈ s ∧ s ∈ B) closure := by
simpa only [and_comm] using hB.nhds_hasBasis.nhds_closure
theorem TopologicalSpace.IsTopologicalBasis.exists_closure_subset {B : Set (Set X)}
(hB : IsTopologicalBasis B) {x : X} {s : Set X} (h : s ∈ 𝓝 x) :
∃ t ∈ B, x ∈ t ∧ closure t ⊆ s := by
simpa only [exists_prop, and_assoc] using hB.nhds_hasBasis.nhds_closure.mem_iff.mp h
protected theorem Topology.IsInducing.regularSpace [TopologicalSpace Y] {f : Y → X}
(hf : IsInducing f) : RegularSpace Y :=
.of_hasBasis
(fun b => by rw [hf.nhds_eq_comap b]; exact (closed_nhds_basis _).comap _)
fun b s hs => by exact hs.2.preimage hf.continuous
theorem regularSpace_induced (f : Y → X) : @RegularSpace Y (induced f ‹_›) :=
letI := induced f ‹_›
(IsInducing.induced f).regularSpace
theorem regularSpace_sInf {X} {T : Set (TopologicalSpace X)} (h : ∀ t ∈ T, @RegularSpace X t) :
@RegularSpace X (sInf T) := by
let _ := sInf T
have : ∀ a, (𝓝 a).HasBasis
(fun If : Σ I : Set T, I → Set X =>
If.1.Finite ∧ ∀ i : If.1, If.2 i ∈ @nhds X i a ∧ @IsClosed X i (If.2 i))
fun If => ⋂ i : If.1, If.snd i := fun a ↦ by
rw [nhds_sInf, ← iInf_subtype'']
exact .iInf fun t : T => @closed_nhds_basis X t (h t t.2) a
refine .of_hasBasis this fun a If hIf => isClosed_iInter fun i => ?_
exact (hIf.2 i).2.mono (sInf_le (i : T).2)
theorem regularSpace_iInf {ι X} {t : ι → TopologicalSpace X} (h : ∀ i, @RegularSpace X (t i)) :
@RegularSpace X (iInf t) :=
regularSpace_sInf <| forall_mem_range.mpr h
theorem RegularSpace.inf {X} {t₁ t₂ : TopologicalSpace X} (h₁ : @RegularSpace X t₁)
(h₂ : @RegularSpace X t₂) : @RegularSpace X (t₁ ⊓ t₂) := by
rw [inf_eq_iInf]
exact regularSpace_iInf (Bool.forall_bool.2 ⟨h₂, h₁⟩)
instance {p : X → Prop} : RegularSpace (Subtype p) :=
IsEmbedding.subtypeVal.isInducing.regularSpace
instance [TopologicalSpace Y] [RegularSpace Y] : RegularSpace (X × Y) :=
(regularSpace_induced (@Prod.fst X Y)).inf (regularSpace_induced (@Prod.snd X Y))
instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, RegularSpace (X i)] :
RegularSpace (∀ i, X i) :=
regularSpace_iInf fun _ => regularSpace_induced _
/-- In a regular space, if a compact set and a closed set are disjoint, then they have disjoint
neighborhoods. -/
lemma SeparatedNhds.of_isCompact_isClosed {s t : Set X}
(hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : SeparatedNhds s t := by
simpa only [separatedNhds_iff_disjoint, hs.disjoint_nhdsSet_left, disjoint_nhds_nhdsSet,
ht.closure_eq, disjoint_left] using hst
end
/-- This technique to witness `HasSeparatingCover` in regular Lindelöf topological spaces
will be used to prove regular Lindelöf spaces are normal. -/
lemma IsClosed.HasSeparatingCover {s t : Set X} [LindelofSpace X] [RegularSpace X]
(s_cl : IsClosed s) (t_cl : IsClosed t) (st_dis : Disjoint s t) : HasSeparatingCover s t := by
-- `IsLindelof.indexed_countable_subcover` requires the space be Nonempty
rcases isEmpty_or_nonempty X with empty_X | nonempty_X
· rw [subset_eq_empty (t := s) (fun ⦃_⦄ _ ↦ trivial) (univ_eq_empty_iff.mpr empty_X)]
exact hasSeparatingCovers_iff_separatedNhds.mpr (SeparatedNhds.empty_left t) |>.1
-- This is almost `HasSeparatingCover`, but is not countable. We define for all `a : X` for use
-- with `IsLindelof.indexed_countable_subcover` momentarily.
have (a : X) : ∃ n : Set X, IsOpen n ∧ Disjoint (closure n) t ∧ (a ∈ s → a ∈ n) := by
wlog ains : a ∈ s
· exact ⟨∅, isOpen_empty, SeparatedNhds.empty_left t |>.disjoint_closure_left, fun a ↦ ains a⟩
obtain ⟨n, nna, ncl, nsubkc⟩ := ((regularSpace_TFAE X).out 0 3 :).mp ‹RegularSpace X› a tᶜ <|
t_cl.compl_mem_nhds (disjoint_left.mp st_dis ains)
exact
⟨interior n,
isOpen_interior,
disjoint_left.mpr fun ⦃_⦄ ain ↦
nsubkc <| (IsClosed.closure_subset_iff ncl).mpr interior_subset ain,
fun _ ↦ mem_interior_iff_mem_nhds.mpr nna⟩
-- By Lindelöf, we may obtain a countable subcover witnessing `HasSeparatingCover`
choose u u_open u_dis u_nhds using this
obtain ⟨f, f_cov⟩ := s_cl.isLindelof.indexed_countable_subcover
u u_open (fun a ainh ↦ mem_iUnion.mpr ⟨a, u_nhds a ainh⟩)
exact ⟨u ∘ f, f_cov, fun n ↦ ⟨u_open (f n), u_dis (f n)⟩⟩
end RegularSpace
section LocallyCompactRegularSpace
/-- In a (possibly non-Hausdorff) locally compact regular space, for every containment `K ⊆ U` of
a compact set `K` in an open set `U`, there is a compact closed neighborhood `L`
such that `K ⊆ L ⊆ U`: equivalently, there is a compact closed set `L` such
that `K ⊆ interior L` and `L ⊆ U`. -/
theorem exists_compact_closed_between [LocallyCompactSpace X] [RegularSpace X]
{K U : Set X} (hK : IsCompact K) (hU : IsOpen U) (h_KU : K ⊆ U) :
∃ L, IsCompact L ∧ IsClosed L ∧ K ⊆ interior L ∧ L ⊆ U :=
let ⟨L, L_comp, KL, LU⟩ := exists_compact_between hK hU h_KU
⟨closure L, L_comp.closure, isClosed_closure, KL.trans <| interior_mono subset_closure,
L_comp.closure_subset_of_isOpen hU LU⟩
/-- In a locally compact regular space, given a compact set `K` inside an open set `U`, we can find
an open set `V` between these sets with compact closure: `K ⊆ V` and the closure of `V` is
inside `U`. -/
theorem exists_open_between_and_isCompact_closure [LocallyCompactSpace X] [RegularSpace X]
{K U : Set X} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) :
∃ V, IsOpen V ∧ K ⊆ V ∧ closure V ⊆ U ∧ IsCompact (closure V) := by
rcases exists_compact_closed_between hK hU hKU with ⟨L, L_compact, L_closed, KL, LU⟩
have A : closure (interior L) ⊆ L := by
apply (closure_mono interior_subset).trans (le_of_eq L_closed.closure_eq)
refine ⟨interior L, isOpen_interior, KL, A.trans LU, ?_⟩
exact L_compact.closure_of_subset interior_subset
end LocallyCompactRegularSpace
section T25
/-- A T₂.₅ space, also known as a Urysohn space, is a topological space
where for every pair `x ≠ y`, there are two open sets, with the intersection of closures
empty, one containing `x` and the other `y` . -/
class T25Space (X : Type u) [TopologicalSpace X] : Prop where
/-- Given two distinct points in a T₂.₅ space, their filters of closed neighborhoods are
disjoint. -/
t2_5 : ∀ ⦃x y : X⦄, x ≠ y → Disjoint ((𝓝 x).lift' closure) ((𝓝 y).lift' closure)
@[simp]
theorem disjoint_lift'_closure_nhds [T25Space X] {x y : X} :
Disjoint ((𝓝 x).lift' closure) ((𝓝 y).lift' closure) ↔ x ≠ y :=
⟨fun h hxy => by simp [hxy, nhds_neBot.ne] at h, fun h => T25Space.t2_5 h⟩
-- see Note [lower instance priority]
instance (priority := 100) T25Space.t2Space [T25Space X] : T2Space X :=
t2Space_iff_disjoint_nhds.2 fun _ _ hne =>
(disjoint_lift'_closure_nhds.2 hne).mono (le_lift'_closure _) (le_lift'_closure _)
theorem exists_nhds_disjoint_closure [T25Space X] {x y : X} (h : x ≠ y) :
∃ s ∈ 𝓝 x, ∃ t ∈ 𝓝 y, Disjoint (closure s) (closure t) :=
((𝓝 x).basis_sets.lift'_closure.disjoint_iff (𝓝 y).basis_sets.lift'_closure).1 <|
disjoint_lift'_closure_nhds.2 h
theorem exists_open_nhds_disjoint_closure [T25Space X] {x y : X} (h : x ≠ y) :
∃ u : Set X,
x ∈ u ∧ IsOpen u ∧ ∃ v : Set X, y ∈ v ∧ IsOpen v ∧ Disjoint (closure u) (closure v) := by
simpa only [exists_prop, and_assoc] using
((nhds_basis_opens x).lift'_closure.disjoint_iff (nhds_basis_opens y).lift'_closure).1
(disjoint_lift'_closure_nhds.2 h)
theorem T25Space.of_injective_continuous [TopologicalSpace Y] [T25Space Y] {f : X → Y}
(hinj : Injective f) (hcont : Continuous f) : T25Space X where
t2_5 x y hne := (tendsto_lift'_closure_nhds hcont x).disjoint (t2_5 <| hinj.ne hne)
(tendsto_lift'_closure_nhds hcont y)
theorem Topology.IsEmbedding.t25Space [TopologicalSpace Y] [T25Space Y] {f : X → Y}
(hf : IsEmbedding f) : T25Space X :=
.of_injective_continuous hf.injective hf.continuous
protected theorem Homeomorph.t25Space [TopologicalSpace Y] [T25Space X] (h : X ≃ₜ Y) : T25Space Y :=
h.symm.isEmbedding.t25Space
instance Subtype.instT25Space [T25Space X] {p : X → Prop} : T25Space {x // p x} :=
IsEmbedding.subtypeVal.t25Space
end T25
section T3
/-- A T₃ space is a T₀ space which is a regular space. Any T₃ space is a T₁ space, a T₂ space, and
a T₂.₅ space. -/
class T3Space (X : Type u) [TopologicalSpace X] : Prop extends T0Space X, RegularSpace X
instance (priority := 90) instT3Space [T0Space X] [RegularSpace X] : T3Space X := ⟨⟩
theorem RegularSpace.t3Space_iff_t0Space [RegularSpace X] : T3Space X ↔ T0Space X := by
constructor <;> intro <;> infer_instance
-- see Note [lower instance priority]
instance (priority := 100) T3Space.t25Space [T3Space X] : T25Space X := by
refine ⟨fun x y hne => ?_⟩
rw [lift'_nhds_closure, lift'_nhds_closure]
have : x ∉ closure {y} ∨ y ∉ closure {x} :=
(t0Space_iff_or_notMem_closure X).mp inferInstance hne
simp only [← disjoint_nhds_nhdsSet, nhdsSet_singleton] at this
exact this.elim id fun h => h.symm
protected theorem Topology.IsEmbedding.t3Space [TopologicalSpace Y] [T3Space Y] {f : X → Y}
(hf : IsEmbedding f) : T3Space X :=
{ toT0Space := hf.t0Space
toRegularSpace := hf.isInducing.regularSpace }
protected theorem Homeomorph.t3Space [TopologicalSpace Y] [T3Space X] (h : X ≃ₜ Y) : T3Space Y :=
h.symm.isEmbedding.t3Space
instance Subtype.t3Space [T3Space X] {p : X → Prop} : T3Space (Subtype p) :=
IsEmbedding.subtypeVal.t3Space
instance ULift.instT3Space [T3Space X] : T3Space (ULift X) :=
IsEmbedding.uliftDown.t3Space
instance [TopologicalSpace Y] [T3Space X] [T3Space Y] : T3Space (X × Y) := ⟨⟩
instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T3Space (X i)] :
T3Space (∀ i, X i) := ⟨⟩
/-- Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`,
with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. -/
theorem disjoint_nested_nhds [T3Space X] {x y : X} (h : x ≠ y) :
∃ U₁ ∈ 𝓝 x, ∃ V₁ ∈ 𝓝 x, ∃ U₂ ∈ 𝓝 y, ∃ V₂ ∈ 𝓝 y,
IsClosed V₁ ∧ IsClosed V₂ ∧ IsOpen U₁ ∧ IsOpen U₂ ∧ V₁ ⊆ U₁ ∧ V₂ ⊆ U₂ ∧ Disjoint U₁ U₂ := by
rcases t2_separation h with ⟨U₁, U₂, U₁_op, U₂_op, x_in, y_in, H⟩
rcases exists_mem_nhds_isClosed_subset (U₁_op.mem_nhds x_in) with ⟨V₁, V₁_in, V₁_closed, h₁⟩
rcases exists_mem_nhds_isClosed_subset (U₂_op.mem_nhds y_in) with ⟨V₂, V₂_in, V₂_closed, h₂⟩
exact ⟨U₁, mem_of_superset V₁_in h₁, V₁, V₁_in, U₂, mem_of_superset V₂_in h₂, V₂, V₂_in,
V₁_closed, V₂_closed, U₁_op, U₂_op, h₁, h₂, H⟩
open SeparationQuotient
/-- The `SeparationQuotient` of a regular space is a T₃ space. -/
instance [RegularSpace X] : T3Space (SeparationQuotient X) where
regular {s a} hs ha := by
rcases surjective_mk a with ⟨a, rfl⟩
rw [← disjoint_comap_iff surjective_mk, comap_mk_nhds_mk, comap_mk_nhdsSet]
exact RegularSpace.regular (hs.preimage continuous_mk) ha
end T3
section NormalSpace
/-- A topological space is said to be a *normal space* if any two disjoint closed sets
have disjoint open neighborhoods. -/
class NormalSpace (X : Type u) [TopologicalSpace X] : Prop where
/-- Two disjoint sets in a normal space admit disjoint neighbourhoods. -/
normal : ∀ s t : Set X, IsClosed s → IsClosed t → Disjoint s t → SeparatedNhds s t
theorem normal_separation [NormalSpace X] {s t : Set X} (H1 : IsClosed s) (H2 : IsClosed t)
(H3 : Disjoint s t) : SeparatedNhds s t :=
NormalSpace.normal s t H1 H2 H3
theorem disjoint_nhdsSet_nhdsSet [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsClosed t)
(hd : Disjoint s t) : Disjoint (𝓝ˢ s) (𝓝ˢ t) :=
(normal_separation hs ht hd).disjoint_nhdsSet
theorem normal_exists_closure_subset [NormalSpace X] {s t : Set X} (hs : IsClosed s) (ht : IsOpen t)
(hst : s ⊆ t) : ∃ u, IsOpen u ∧ s ⊆ u ∧ closure u ⊆ t := by
have : Disjoint s tᶜ := Set.disjoint_left.mpr fun x hxs hxt => hxt (hst hxs)
rcases normal_separation hs (isClosed_compl_iff.2 ht) this with
⟨s', t', hs', ht', hss', htt', hs't'⟩
refine ⟨s', hs', hss', Subset.trans (closure_minimal ?_ (isClosed_compl_iff.2 ht'))
(compl_subset_comm.1 htt')⟩
exact fun x hxs hxt => hs't'.le_bot ⟨hxs, hxt⟩
/-- If the codomain of a closed embedding is a normal space, then so is the domain. -/
protected theorem Topology.IsClosedEmbedding.normalSpace [TopologicalSpace Y] [NormalSpace Y]
{f : X → Y} (hf : IsClosedEmbedding f) : NormalSpace X where
normal s t hs ht hst := by
have H : SeparatedNhds (f '' s) (f '' t) :=
NormalSpace.normal (f '' s) (f '' t) (hf.isClosedMap s hs) (hf.isClosedMap t ht)
(disjoint_image_of_injective hf.injective hst)
exact (H.preimage hf.continuous).mono (subset_preimage_image _ _) (subset_preimage_image _ _)
protected theorem Homeomorph.normalSpace [TopologicalSpace Y] [NormalSpace X] (h : X ≃ₜ Y) :
NormalSpace Y :=
h.symm.isClosedEmbedding.normalSpace
instance (priority := 100) NormalSpace.of_compactSpace_r1Space [CompactSpace X] [R1Space X] :
NormalSpace X where
normal _s _t hs ht := .of_isCompact_isCompact_isClosed hs.isCompact ht.isCompact ht
/-- A regular topological space with a Lindelöf topology is a normal space. A consequence of e.g.
Corollaries 20.8 and 20.10 of [Willard's *General Topology*][zbMATH02107988] (without the
assumption of Hausdorff). -/
instance (priority := 100) NormalSpace.of_regularSpace_lindelofSpace
[RegularSpace X] [LindelofSpace X] : NormalSpace X where
normal _ _ hcl kcl hkdis :=
hasSeparatingCovers_iff_separatedNhds.mp
⟨hcl.HasSeparatingCover kcl hkdis, kcl.HasSeparatingCover hcl (Disjoint.symm hkdis)⟩
instance (priority := 100) NormalSpace.of_regularSpace_secondCountableTopology
[RegularSpace X] [SecondCountableTopology X] : NormalSpace X :=
of_regularSpace_lindelofSpace
end NormalSpace
section Normality
/-- A T₄ space is a normal T₁ space. -/
class T4Space (X : Type u) [TopologicalSpace X] : Prop extends T1Space X, NormalSpace X
instance (priority := 100) [T1Space X] [NormalSpace X] : T4Space X := ⟨⟩
-- see Note [lower instance priority]
instance (priority := 100) T4Space.t3Space [T4Space X] : T3Space X where
regular hs hxs := by simpa only [nhdsSet_singleton] using (normal_separation hs isClosed_singleton
(disjoint_singleton_right.mpr hxs)).disjoint_nhdsSet
/-- If the codomain of a closed embedding is a T₄ space, then so is the domain. -/
protected theorem Topology.IsClosedEmbedding.t4Space [TopologicalSpace Y] [T4Space Y] {f : X → Y}
(hf : IsClosedEmbedding f) : T4Space X where
toT1Space := hf.isEmbedding.t1Space
toNormalSpace := hf.normalSpace
protected theorem Homeomorph.t4Space [TopologicalSpace Y] [T4Space X] (h : X ≃ₜ Y) : T4Space Y :=
h.symm.isClosedEmbedding.t4Space
instance ULift.instT4Space [T4Space X] : T4Space (ULift X) := IsClosedEmbedding.uliftDown.t4Space
namespace SeparationQuotient
/-- The `SeparationQuotient` of a normal space is a normal space. -/
instance [NormalSpace X] : NormalSpace (SeparationQuotient X) where
normal s t hs ht hd := separatedNhds_iff_disjoint.2 <| by
rw [← disjoint_comap_iff surjective_mk, comap_mk_nhdsSet, comap_mk_nhdsSet]
exact disjoint_nhdsSet_nhdsSet (hs.preimage continuous_mk) (ht.preimage continuous_mk)
(hd.preimage mk)
end SeparationQuotient
variable (X)
end Normality
section CompletelyNormal
/-- A topological space `X` is a *completely normal space* provided that for any two sets `s`, `t`
such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`,
then there exist disjoint neighbourhoods of `s` and `t`. -/
class CompletelyNormalSpace (X : Type u) [TopologicalSpace X] : Prop where
/-- If `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then `s` and `t`
admit disjoint neighbourhoods. -/
completely_normal :
∀ ⦃s t : Set X⦄, Disjoint (closure s) t → Disjoint s (closure t) → Disjoint (𝓝ˢ s) (𝓝ˢ t)
export CompletelyNormalSpace (completely_normal)
-- see Note [lower instance priority]
/-- A completely normal space is a normal space. -/
instance (priority := 100) CompletelyNormalSpace.toNormalSpace
[CompletelyNormalSpace X] : NormalSpace X where
normal s t hs ht hd := separatedNhds_iff_disjoint.2 <|
completely_normal (by rwa [hs.closure_eq]) (by rwa [ht.closure_eq])
theorem Topology.IsEmbedding.completelyNormalSpace [TopologicalSpace Y] [CompletelyNormalSpace Y]
{e : X → Y} (he : IsEmbedding e) : CompletelyNormalSpace X := by
refine ⟨fun s t hd₁ hd₂ => ?_⟩
simp only [he.isInducing.nhdsSet_eq_comap]
refine disjoint_comap (completely_normal ?_ ?_)
· rwa [← subset_compl_iff_disjoint_left, image_subset_iff, preimage_compl,
← he.closure_eq_preimage_closure_image, subset_compl_iff_disjoint_left]
· rwa [← subset_compl_iff_disjoint_right, image_subset_iff, preimage_compl,
← he.closure_eq_preimage_closure_image, subset_compl_iff_disjoint_right]
/-- A subspace of a completely normal space is a completely normal space. -/
instance [CompletelyNormalSpace X] {p : X → Prop} : CompletelyNormalSpace { x // p x } :=
IsEmbedding.subtypeVal.completelyNormalSpace
instance ULift.instCompletelyNormalSpace [CompletelyNormalSpace X] :
CompletelyNormalSpace (ULift X) :=
IsEmbedding.uliftDown.completelyNormalSpace
/-- A T₅ space is a completely normal T₁ space. -/
class T5Space (X : Type u) [TopologicalSpace X] : Prop extends T1Space X, CompletelyNormalSpace X
theorem Topology.IsEmbedding.t5Space [TopologicalSpace Y] [T5Space Y] {e : X → Y}
(he : IsEmbedding e) : T5Space X where
__ := he.t1Space
completely_normal := by
have := he.completelyNormalSpace
exact completely_normal
protected theorem Homeomorph.t5Space [TopologicalSpace Y] [T5Space X] (h : X ≃ₜ Y) : T5Space Y :=
h.symm.isClosedEmbedding.t5Space
-- see Note [lower instance priority]
/-- A `T₅` space is a `T₄` space. -/
instance (priority := 100) T5Space.toT4Space [T5Space X] : T4Space X where
-- follows from type-class inference
/-- A subspace of a T₅ space is a T₅ space. -/
instance [T5Space X] {p : X → Prop} : T5Space { x // p x } :=
IsEmbedding.subtypeVal.t5Space
instance ULift.instT5Space [T5Space X] : T5Space (ULift X) :=
IsEmbedding.uliftDown.t5Space
open SeparationQuotient
/-- The `SeparationQuotient` of a completely normal R₀ space is a T₅ space. -/
instance [CompletelyNormalSpace X] [R0Space X] : T5Space (SeparationQuotient X) where
t1 := by
rwa [((t1Space_TFAE (SeparationQuotient X)).out 1 0 :), SeparationQuotient.t1Space_iff]
completely_normal s t hd₁ hd₂ := by
rw [← disjoint_comap_iff surjective_mk, comap_mk_nhdsSet, comap_mk_nhdsSet]
apply completely_normal <;> rw [← preimage_mk_closure]
exacts [hd₁.preimage mk, hd₂.preimage mk]
end CompletelyNormal
/-- In a compact T₂ space, the connected component of a point equals the intersection of all
its clopen neighbourhoods. -/
theorem connectedComponent_eq_iInter_isClopen [T2Space X] [CompactSpace X] (x : X) :
connectedComponent x = ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, s := by
apply Subset.antisymm connectedComponent_subset_iInter_isClopen
-- Reduce to showing that the clopen intersection is connected.
refine IsPreconnected.subset_connectedComponent ?_ (mem_iInter.2 fun s => s.2.2)
-- We do this by showing that any disjoint cover by two closed sets implies
-- that one of these closed sets must contain our whole thing.
-- To reduce to the case where the cover is disjoint on all of `X` we need that `s` is closed
have hs : @IsClosed X _ (⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, s) :=
isClosed_iInter fun s => s.2.1.1
rw [isPreconnected_iff_subset_of_fully_disjoint_closed hs]
intro a b ha hb hab ab_disj
-- Since our space is normal, we get two larger disjoint open sets containing the disjoint
-- closed sets. If we can show that our intersection is a subset of any of these we can then
-- "descend" this to show that it is a subset of either a or b.
rcases normal_separation ha hb ab_disj with ⟨u, v, hu, hv, hau, hbv, huv⟩
obtain ⟨s, H⟩ : ∃ s : Set X, IsClopen s ∧ x ∈ s ∧ s ⊆ u ∪ v := by
/- Now we find a clopen set `s` around `x`, contained in `u ∪ v`. We utilize the fact that
`X \ u ∪ v` will be compact, so there must be some finite intersection of clopen neighbourhoods
of `X` disjoint to it, but a finite intersection of clopen sets is clopen,
so we let this be our `s`. -/
have H1 := (hu.union hv).isClosed_compl.isCompact.inter_iInter_nonempty
(fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s) fun s => s.2.1.1
rw [← not_disjoint_iff_nonempty_inter, imp_not_comm, not_forall] at H1
obtain ⟨si, H2⟩ :=
H1 (disjoint_compl_left_iff_subset.2 <| hab.trans <| union_subset_union hau hbv)
refine ⟨⋂ U ∈ si, Subtype.val U, ?_, ?_, ?_⟩
· exact isClopen_biInter_finset fun s _ => s.2.1
· exact mem_iInter₂.2 fun s _ => s.2.2
· rwa [← disjoint_compl_left_iff_subset, disjoint_iff_inter_eq_empty,
← not_nonempty_iff_eq_empty]
-- So, we get a disjoint decomposition `s = s ∩ u ∪ s ∩ v` of clopen sets. The intersection of all
-- clopen neighbourhoods will then lie in whichever of u or v x lies in and hence will be a subset
-- of either a or b.
· have H1 := isClopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hu hv huv
rw [union_comm] at H
have H2 := isClopen_inter_of_disjoint_cover_clopen H.1 H.2.2 hv hu huv.symm
by_cases hxu : x ∈ u <;> [left; right]
-- The x ∈ u case.
· suffices ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, ↑s ⊆ u
from Disjoint.left_le_of_le_sup_right hab (huv.mono this hbv)
· apply Subset.trans _ s.inter_subset_right
exact iInter_subset (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s.1)
⟨s ∩ u, H1, mem_inter H.2.1 hxu⟩
-- If x ∉ u, we get x ∈ v since x ∈ u ∪ v. The rest is then like the x ∈ u case.
· have h1 : x ∈ v :=
(hab.trans (union_subset_union hau hbv) (mem_iInter.2 fun i => i.2.2)).resolve_left hxu
suffices ⋂ s : { s : Set X // IsClopen s ∧ x ∈ s }, ↑s ⊆ v
from (huv.symm.mono this hau).left_le_of_le_sup_left hab
· refine Subset.trans ?_ s.inter_subset_right
exact iInter_subset (fun s : { s : Set X // IsClopen s ∧ x ∈ s } => s.1)
⟨s ∩ v, H2, mem_inter H.2.1 h1⟩
/-- `ConnectedComponents X` is Hausdorff when `X` is Hausdorff and compact -/
@[stacks 0900 "The Stacks entry proves profiniteness."]
instance ConnectedComponents.t2 [T2Space X] [CompactSpace X] : T2Space (ConnectedComponents X) := by
-- Fix 2 distinct connected components, with points a and b
refine ⟨ConnectedComponents.surjective_coe.forall₂.2 fun a b ne => ?_⟩
rw [ConnectedComponents.coe_ne_coe] at ne
have h := connectedComponent_disjoint ne
-- write ↑b as the intersection of all clopen subsets containing it
rw [connectedComponent_eq_iInter_isClopen b, disjoint_iff_inter_eq_empty] at h
-- Now we show that this can be reduced to some clopen containing `↑b` being disjoint to `↑a`
obtain ⟨U, V, hU, ha, hb, rfl⟩ : ∃ (U : Set X) (V : Set (ConnectedComponents X)),
IsClopen U ∧ connectedComponent a ∩ U = ∅ ∧ connectedComponent b ⊆ U ∧ (↑) ⁻¹' V = U := by
have h :=
(isClosed_connectedComponent (α := X)).isCompact.elim_finite_subfamily_closed
_ (fun s : { s : Set X // IsClopen s ∧ b ∈ s } => s.2.1.1) h
obtain ⟨fin_a, ha⟩ := h
-- This clopen and its complement will separate the connected components of `a` and `b`
set U : Set X := ⋂ (i : { s // IsClopen s ∧ b ∈ s }) (_ : i ∈ fin_a), i
have hU : IsClopen U := isClopen_biInter_finset fun i _ => i.2.1
exact ⟨U, (↑) '' U, hU, ha, subset_iInter₂ fun s _ => s.2.1.connectedComponent_subset s.2.2,
(connectedComponents_preimage_image U).symm ▸ hU.biUnion_connectedComponent_eq⟩
rw [ConnectedComponents.isQuotientMap_coe.isClopen_preimage] at hU
refine ⟨Vᶜ, V, hU.compl.isOpen, hU.isOpen, ?_, hb mem_connectedComponent, disjoint_compl_left⟩
exact fun h => flip Set.Nonempty.ne_empty ha ⟨a, mem_connectedComponent, h⟩
|
PWO.lean
|
/-
Copyright (c) 2022 Alex J. Best. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best
-/
import Mathlib.Order.Preorder.Finsupp
import Mathlib.Order.WellFoundedSet
/-!
# Partial well ordering on finsupps
This file contains the fact that finitely supported functions from a fintype are
partially well ordered when the codomain is a linear order that is well ordered.
It is in a separate file for now so as to not add imports to the file `Order.WellFoundedSet`.
## Main statements
* `Finsupp.isPWO` - finitely supported functions from a fintype are partially well ordered when
the codomain is a linear order that is well ordered
## Tags
Dickson, order, partial well order
-/
/-- A version of **Dickson's lemma** any subset of functions `σ →₀ α` is partially well
ordered, when `σ` is `Finite` and `α` is a linear well order.
This version uses finsupps on a finite type as it is intended for use with `MVPowerSeries`.
-/
theorem Finsupp.isPWO {α σ : Type*} [Zero α] [LinearOrder α] [WellFoundedLT α] [Finite σ]
(S : Set (σ →₀ α)) : S.IsPWO :=
Finsupp.equivFunOnFinite.symm_image_image S ▸
Set.PartiallyWellOrderedOn.image_of_monotone_on (Pi.isPWO _) fun _a _b _ha _hb => id
|
eqtype.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.
(******************************************************************************)
(* Types with a decidable equality *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines two "base" combinatorial structures: *)
(* eqType == types with a decidable equality *)
(* The HB class is called Equality. *)
(* The equality operation on an eqType is proof-irrelevant *)
(* (lemma eq_irrelevance). *)
(* The main notation is the boolean equality "==", see below. *)
(* subType P == types isomorphic to {x : T | P x} *)
(* with P : pred T for some type T *)
(* The HB class is called SubType. *)
(* subEqType P == join of eqType and subType P *)
(* The HB class is called SubEquality. *)
(* *)
(* The eqType interface supports the following operations (in bool_scope): *)
(* x == y <=> x compares equal to y (this is a boolean test) *)
(* x == y :> T <=> x == y at type T *)
(* x != y <=> x and y compare unequal *)
(* x != y :> T <=> x and y compare unequal at type T *)
(* x =P y :: a proof of reflect (x = y) (x == y); x =P y coerces *)
(* to x == y -> x = y *)
(* eqbLHS := (X in (X == _))%pattern (for rewriting) *)
(* eqbRHS := (X in (_ == X))%pattern (for rewriting) *)
(* eq_op == the boolean relation behind the == notation *)
(* (see lemma eqE below for generic folding *)
(* of equality predicates) *)
(* eqP == proof of Equality.axiom eq_op behind the =P notation*)
(* Equality.axiom e <-> e : rel T is a valid comparison decision procedure *)
(* for type T: reflect (x = y) (e x y) for all x y : T *)
(* pred1 a == the singleton predicate [pred x | x == a] *)
(* pred2, pred3, pred4 == pair, triple, quad predicates *)
(* predC1 a == [pred x | x != a] *)
(* [predU1 a & A] == [pred x | (x == a) || (x \in A)] *)
(* [predD1 A & a] == [pred x | x != a & x \in A] *)
(* predU1 a P, predD1 P a == applicative versions of the above *)
(* frel f == the relation associated with f : T -> T *)
(* := [rel x y | f x == y] *)
(* invariant f k == elements of T whose k-class is f-invariant *)
(* := [pred x | k (f x) == k x] with f : T -> T *)
(* [fun x : T => e0 with a1 |-> e1, .., a_n |-> e_n] *)
(* [eta f with a1 |-> e1, .., a_n |-> e_n] == *)
(* the auto-expanding function that maps x = a_i to e_i, and other values *)
(* of x to e0 (resp. f x). In the first form the `: T' is optional and x *)
(* can occur in a_i or e_i *)
(* dfwith f x == fun j => x if j = i, and f j otherwise, given *)
(* f : forall k, T k and x : T i *)
(* We also define: *)
(* tagged_as u v == v cast as T_(tag u) if tag v == tag u, else u *)
(* so that u == v <=> (tag u == tag v) && (tagged u == tagged_as u v *)
(* etagged i u (p : tag u = i) == (tagged u) cast as T_ i *)
(* untag idx i (F : T_ i -> _) u == F (etagged i u _) if tag u = i, else idx *)
(* tagged_with i == [pred j | tag j == i], this pred {x : I & T_ x} is useful *)
(* to define the sigma type {x in tagged_with i} and the mutual bijections: *)
(* tag_with i : T_ i -> {x in tagged_with i} *)
(* untag_with i : {x in tagged_with i} -> T_ i *)
(* *)
(* The subType interface supports the following operations: *)
(* \val == the generic injection from a subType S of T into T *)
(* For example, if u : {x : T | P}, then val u : T *)
(* val is injective because P is proof-irrelevant (P is in bool, *)
(* and the is_true coercion expands to P = true). *)
(* valP == the generic proof of P (val u) for u : subType P *)
(* Sub x Px == The generic constructor for a subType P; Px is a proof of P x *)
(* and P should be inferred from the expected return type. *)
(* insub x == the generic partial projection of T into a subType S of T *)
(* This returns an option S; if S : subType P then *)
(* insub x = Some u with val u = x if P x, *)
(* None if ~~ P x *)
(* The insubP lemma encapsulates this dichotomy. *)
(* P should be inferred from the expected return type. *)
(* innew x == total (non-option) variant of insub when P = predT *)
(* {? x | P} == option {x | P} (syntax for casting insub x) *)
(* insubd u0 x == the generic projection with default value u0 *)
(* := odflt u0 (insub x) *)
(* insigd A0 x == special case of insubd for S == {x | x \in A}, where A0 is *)
(* a proof of x0 \in A *)
(* insub_eq x == transparent version of insub x that expands to Some/None *)
(* when P x can evaluate *)
(* *)
(* * Sub *)
(* ** Specific notations *)
(* [isSub of S for S_val] == subtype for S where S_val : S -> T is the *)
(* first projection of a type S isomorphic to {x : T | P}; if S_val is *)
(* specified, then it replaces the inferred projector. *)
(* [isSub for S_val] := [isSub of _ for S_val] *)
(* It clones the canonical subType structure for S. *)
(* [isNew of S for S_val] == subtype for S where S_val : S -> T is the *)
(* projection of a type S isomorphic to T; in this case P must be predT *)
(* [isNew for S_val] := [isNew of _ for S_val] *)
(* [isSub for S_val by Srect], [isNew for S_val by Srect] == *)
(* variants of the above where the eliminator is explicitly provided. *)
(* Here S no longer needs to be syntactically identical to {x | P x} or *)
(* wrapped T, but it must have a derived constructor S_Sub satisfying an *)
(* eliminator Srect identical to the one the Coq Inductive command would *)
(* have generated, and S_val (S_Sub x Px) (resp. S_val (S_sub x) for the *)
(* newType form) must be convertible to x. *)
(* variant of the above when S is a wrapper type for T (so P = predT). *)
(* Subtypes inherit the eqType structure of their base types; the generic *)
(* structure should be explicitly instantiated using the *)
(* [Equality of S by <:] *)
(* construct; this pattern is repeated for all the combinatorial interfaces *)
(* (Choice, Countable, Finite). *)
(* *)
(* List of factories with a dedicated alias (not generated automatically): *)
(* inj_type injf == alias of T to copy an interface from another T' already *)
(* equipped with it and injf : injective f with f : T -> T'*)
(* pcan_type fK == alias of T to similarly derive an interface from f and *)
(* a left inverse partial function g and fK : pcancel f g *)
(* can_type fK == alias of T to similarly derive an interface from f and *)
(* a left inverse function g and fK : cancel f g *)
(* sub_type sT == alias of sT : subType _ *)
(* *)
(* comparable T <-> equality on T is decidable. *)
(* := forall x y : T, decidable (x = y) *)
(* comparableMixin compT == equality mixin for compT : comparable T *)
(* *)
(* The eqType interface is implemented for most standard datatypes: *)
(* bool, unit, void, option, prod (denoted A * B), sum (denoted A + B), *)
(* sig (denoted {x | P}), sigT (denoted {i : I & T}). *)
(* *)
(* We add the following to the standard suffixes documented in ssrbool.v: *)
(* 1, 2, 3, 4 -- explicit enumeration predicate for 1 (singleton), 2, 3, or *)
(* 4 values *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope eq_scope.
Declare Scope fun_delta_scope.
Definition eq_axiom T (e : rel T) := forall x y, reflect (x = y) (e x y).
HB.mixin Record hasDecEq T := { eq_op : rel T; eqP : eq_axiom eq_op }.
#[mathcomp(axiom="eq_axiom"), short(type="eqType")]
HB.structure Definition Equality := { T of hasDecEq T }.
(* eqE is a generic lemma that can be used to fold back recursive comparisons *)
(* after using partial evaluation to simplify comparisons on concrete *)
(* instances. The eqE lemma can be used e.g. like so: rewrite !eqE /= -!eqE. *)
(* For instance, with the above rewrite, n.+1 == n.+1 gets simplified to *)
(* n == n. For this to work, we need to declare equality _mixins_ *)
(* as canonical. Canonical declarations remove the need for specific *)
(* inverses to eqE (like eqbE, eqnE, eqseqE, etc.) for new recursive *)
(* comparisons, but can only be used for manifest mixing with a bespoke *)
(* comparison function, and so is incompatible with PcanEqMixin and the like *)
(* - this is why the tree_hasDecEq for GenTree.tree in library choice is not *)
(* declared Canonical. *)
Lemma eqE (T : eqType) x : eq_op x = hasDecEq.eq_op (Equality.class T) x.
Proof. by []. Qed.
Arguments eqP {T x y} : rename.
Delimit Scope eq_scope with EQ.
Open Scope eq_scope.
Notation "x == y" := (eq_op x y) (no associativity) : bool_scope.
Notation "x == y :> T" := ((x : T) == (y : T)) : bool_scope.
Notation "x != y" := (~~ (x == y)) (no associativity) : bool_scope.
Notation "x != y :> T" := (~~ (x == y :> T)) : bool_scope.
Notation "x =P y" := (eqP : reflect (x = y) (x == y))
(at level 70, no associativity) : eq_scope.
Notation "x =P y :> T" := (eqP : reflect (x = y :> T) (x == y :> T))
(no associativity) : eq_scope.
Notation eqbLHS := (X in (X == _))%pattern.
Notation eqbRHS := (X in (_ == X))%pattern.
Lemma eq_refl (T : eqType) (x : T) : x == x. Proof. exact/eqP. Qed.
Notation eqxx := eq_refl.
Lemma eq_sym (T : eqType) (x y : T) : (x == y) = (y == x).
Proof. exact/eqP/eqP. Qed.
#[global] Hint Resolve eq_refl eq_sym : core.
Variant eq_xor_neq (T : eqType) (x y : T) : bool -> bool -> Set :=
| EqNotNeq of x = y : eq_xor_neq x y true true
| NeqNotEq of x != y : eq_xor_neq x y false false.
Lemma eqVneq (T : eqType) (x y : T) : eq_xor_neq x y (y == x) (x == y).
Proof. by rewrite eq_sym; case: (altP eqP); constructor. Qed.
Arguments eqVneq {T} x y, {T x y}.
Section Contrapositives.
Variables (T1 T2 : eqType).
Implicit Types (A : pred T1) (b : bool) (P : Prop) (x : T1) (z : T2).
Lemma contraTeq b x y : (x != y -> ~~ b) -> b -> x = y.
Proof. by move=> imp hyp; apply/eqP; apply: contraTT hyp. Qed.
Lemma contraNeq b x y : (x != y -> b) -> ~~ b -> x = y.
Proof. by move=> imp hyp; apply/eqP; apply: contraNT hyp. Qed.
Lemma contraFeq b x y : (x != y -> b) -> b = false -> x = y.
Proof. by move=> imp /negbT; apply: contraNeq. Qed.
Lemma contraPeq P x y : (x != y -> ~ P) -> P -> x = y.
Proof. by move=> imp HP; apply: contraTeq isT => /imp /(_ HP). Qed.
Lemma contra_not_eq P x y : (x != y -> P) -> ~ P -> x = y.
Proof. by move=> imp; apply: contraPeq => /imp HP /(_ HP). Qed.
Lemma contra_not_neq P x y : (x = y -> P) -> ~ P -> x != y.
Proof. by move=> imp; apply: contra_notN => /eqP. Qed.
Lemma contraTneq b x y : (x = y -> ~~ b) -> b -> x != y.
Proof. by move=> imp; apply: contraTN => /eqP. Qed.
Lemma contraNneq b x y : (x = y -> b) -> ~~ b -> x != y.
Proof. by move=> imp; apply: contraNN => /eqP. Qed.
Lemma contraFneq b x y : (x = y -> b) -> b = false -> x != y.
Proof. by move=> imp /negbT; apply: contraNneq. Qed.
Lemma contraPneq P x y : (x = y -> ~ P) -> P -> x != y.
Proof. by move=> imp; apply: contraPN => /eqP. Qed.
Lemma contra_eqN b x y : (b -> x != y) -> x = y -> ~~ b.
Proof. by move=> imp /eqP; apply: contraL. Qed.
Lemma contra_eqF b x y : (b -> x != y) -> x = y -> b = false.
Proof. by move=> imp /eqP; apply: contraTF. Qed.
Lemma contra_eqT b x y : (~~ b -> x != y) -> x = y -> b.
Proof. by move=> imp /eqP; apply: contraLR. Qed.
Lemma contra_neqN b x y : (b -> x = y) -> x != y -> ~~ b.
Proof. by move=> imp; apply: contraNN => /imp->. Qed.
Lemma contra_neqF b x y : (b -> x = y) -> x != y -> b = false.
Proof. by move=> imp; apply: contraNF => /imp->. Qed.
Lemma contra_neqT b x y : (~~ b -> x = y) -> x != y -> b.
Proof. by move=> imp; apply: contraNT => /imp->. Qed.
Lemma contra_eq_not P x y : (P -> x != y) -> x = y -> ~ P.
Proof. by move=> imp /eqP; apply: contraTnot. Qed.
Lemma contra_neq_not P x y : (P -> x = y) -> x != y -> ~ P.
Proof. by move=> imp;apply: contraNnot => /imp->. Qed.
Lemma contra_eq z1 z2 x1 x2 : (x1 != x2 -> z1 != z2) -> z1 = z2 -> x1 = x2.
Proof. by move=> imp /eqP; apply: contraTeq. Qed.
Lemma contra_neq z1 z2 x1 x2 : (x1 = x2 -> z1 = z2) -> z1 != z2 -> x1 != x2.
Proof. by move=> imp; apply: contraNneq => /imp->. Qed.
Lemma contra_neq_eq z1 z2 x1 x2 : (x1 != x2 -> z1 = z2) -> z1 != z2 -> x1 = x2.
Proof. by move=> imp; apply: contraNeq => /imp->. Qed.
Lemma contra_eq_neq z1 z2 x1 x2 : (z1 = z2 -> x1 != x2) -> x1 = x2 -> z1 != z2.
Proof. by move=> imp; apply: contra_eqN => /eqP /imp. Qed.
Lemma memPn A x : reflect {in A, forall y, y != x} (x \notin A).
Proof.
apply: (iffP idP) => [notDx y | notDx]; first by apply: contraTneq => ->.
exact: contraL (notDx x) _.
Qed.
Lemma memPnC A x : reflect {in A, forall y, x != y} (x \notin A).
Proof. by apply: (iffP (memPn A x)) => A'x y /A'x; rewrite eq_sym. Qed.
Lemma ifN_eq R x y vT vF : x != y -> (if x == y then vT else vF) = vF :> R.
Proof. exact: ifN. Qed.
Lemma ifN_eqC R x y vT vF : x != y -> (if y == x then vT else vF) = vF :> R.
Proof. by rewrite eq_sym; apply: ifN. Qed.
End Contrapositives.
Arguments memPn {T1 A x}.
Arguments memPnC {T1 A x}.
Theorem eq_irrelevance (T : eqType) x y : forall e1 e2 : x = y :> T, e1 = e2.
Proof.
pose proj z e := if x =P z is ReflectT e0 then e0 else e.
suff: injective (proj y) by rewrite /proj => injp e e'; apply: injp; case: eqP.
pose join (e : x = _) := etrans (esym e).
apply: can_inj (join x y (proj x (erefl x))) _.
by case: y /; case: _ / (proj x _).
Qed.
Corollary eq_axiomK (T : eqType) (x : T) : all_equal_to (erefl x).
Proof. by move=> eq_x_x; apply: eq_irrelevance. Qed.
(* We use the module system to circumvent a silly limitation that *)
(* forbids using the same constant to coerce to different targets. *)
Module Type EqTypePredSig.
Parameter sort : eqType -> predArgType.
End EqTypePredSig.
Module MakeEqTypePred (eqmod : EqTypePredSig).
Coercion eqmod.sort : eqType >-> predArgType.
End MakeEqTypePred.
Module Export EqTypePred := MakeEqTypePred eqtype.Equality.
Lemma unit_eqP : Equality.axiom (fun _ _ : unit => true).
Proof. by do 2!case; left. Qed.
HB.instance Definition _ := hasDecEq.Build unit unit_eqP.
(* Comparison for booleans. *)
(* This is extensionally equal, but not convertible to Bool.eqb. *)
Definition eqb b := addb (~~ b).
Lemma eqbP : Equality.axiom eqb.
Proof. by do 2!case; constructor. Qed.
HB.instance Definition _ := hasDecEq.Build bool eqbP.
Lemma eqbE : eqb = eq_op. Proof. by []. Qed.
Lemma bool_irrelevance (b : bool) (p1 p2 : b) : p1 = p2.
Proof. exact: eq_irrelevance. Qed.
Lemma negb_add b1 b2 : ~~ (b1 (+) b2) = (b1 == b2).
Proof. by rewrite -addNb. Qed.
Lemma negb_eqb b1 b2 : (b1 != b2) = b1 (+) b2.
Proof. by rewrite -addNb negbK. Qed.
Lemma eqb_id b : (b == true) = b.
Proof. by case: b. Qed.
Lemma eqbF_neg b : (b == false) = ~~ b.
Proof. by case: b. Qed.
Lemma eqb_negLR b1 b2 : (~~ b1 == b2) = (b1 == ~~ b2).
Proof. by case: b1; case: b2. Qed.
(* Equality-based predicates. *)
Notation xpred1 := (fun a1 x => x == a1).
Notation xpred2 := (fun a1 a2 x => (x == a1) || (x == a2)).
Notation xpred3 := (fun a1 a2 a3 x => [|| x == a1, x == a2 | x == a3]).
Notation xpred4 :=
(fun a1 a2 a3 a4 x => [|| x == a1, x == a2, x == a3 | x == a4]).
Notation xpredU1 := (fun a1 (p : pred _) x => (x == a1) || p x).
Notation xpredC1 := (fun a1 x => x != a1).
Notation xpredD1 := (fun (p : pred _) a1 x => (x != a1) && p x).
Section EqPred.
Variable T : eqType.
Definition pred1 (a1 : T) := SimplPred (xpred1 a1).
Definition pred2 (a1 a2 : T) := SimplPred (xpred2 a1 a2).
Definition pred3 (a1 a2 a3 : T) := SimplPred (xpred3 a1 a2 a3).
Definition pred4 (a1 a2 a3 a4 : T) := SimplPred (xpred4 a1 a2 a3 a4).
Definition predU1 (a1 : T) p := SimplPred (xpredU1 a1 p).
Definition predC1 (a1 : T) := SimplPred (xpredC1 a1).
Definition predD1 p (a1 : T) := SimplPred (xpredD1 p a1).
Lemma pred1E : pred1 =2 eq_op. Proof. by move=> x y; apply: eq_sym. Qed.
Variables (T2 : eqType) (x y : T) (z u : T2) (b : bool).
Lemma predU1P : reflect (x = y \/ b) ((x == y) || b).
Proof. by apply: (iffP orP); do [case=> [/eqP|]; [left | right]]. Qed.
Lemma pred2P : reflect (x = y \/ z = u) ((x == y) || (z == u)).
Proof. by apply: (iffP orP); do [case=> /eqP; [left | right]]. Qed.
Lemma predD1P : reflect (x <> y /\ b) ((x != y) && b).
Proof. by apply: (iffP andP)=> [] [] // /eqP. Qed.
Lemma predU1l : x = y -> (x == y) || b.
Proof. by move->; rewrite eqxx. Qed.
Lemma predU1r : b -> (x == y) || b.
Proof. by move->; rewrite orbT. Qed.
End EqPred.
Arguments predU1P {T x y b}.
Arguments pred2P {T T2 x y z u}.
Arguments predD1P {T x y b}.
Prenex Implicits pred1 pred2 pred3 pred4 predU1 predC1 predD1.
Notation "[ 'predU1' x & A ]" := (predU1 x [in A])
(format "[ 'predU1' x & A ]") : function_scope.
Notation "[ 'predD1' A & x ]" := (predD1 [in A] x)
(format "[ 'predD1' A & x ]") : function_scope.
(* Lemmas for reflected equality and functions. *)
Section EqFun.
Section Exo.
Variables (aT rT : eqType) (D : pred aT) (f : aT -> rT) (g : rT -> aT).
Lemma inj_eq : injective f -> forall x y, (f x == f y) = (x == y).
Proof. by move=> inj_f x y; apply/eqP/eqP=> [|-> //]; apply: inj_f. Qed.
Lemma can_eq : cancel f g -> forall x y, (f x == f y) = (x == y).
Proof. by move/can_inj; apply: inj_eq. Qed.
Lemma bij_eq : bijective f -> forall x y, (f x == f y) = (x == y).
Proof. by move/bij_inj; apply: inj_eq. Qed.
Lemma can2_eq : cancel f g -> cancel g f -> forall x y, (f x == y) = (x == g y).
Proof. by move=> fK gK x y; rewrite -[y in LHS]gK; apply: can_eq. Qed.
Lemma inj_in_eq :
{in D &, injective f} -> {in D &, forall x y, (f x == f y) = (x == y)}.
Proof. by move=> inj_f x y Dx Dy; apply/eqP/eqP=> [|-> //]; apply: inj_f. Qed.
Lemma can_in_eq :
{in D, cancel f g} -> {in D &, forall x y, (f x == f y) = (x == y)}.
Proof. by move/can_in_inj; apply: inj_in_eq. Qed.
End Exo.
Section Endo.
Variable T : eqType.
Definition frel f := [rel x y : T | f x == y].
Lemma inv_eq f : involutive f -> forall x y : T, (f x == y) = (x == f y).
Proof. by move=> fK; apply: can2_eq. Qed.
Lemma eq_frel f f' : f =1 f' -> frel f =2 frel f'.
Proof. by move=> eq_f x y; rewrite /= eq_f. Qed.
End Endo.
Variable aT : Type.
(* The invariant of a function f wrt a projection k is the pred of points *)
(* that have the same projection as their image. *)
Definition invariant (rT : eqType) f (k : aT -> rT) :=
[pred x | k (f x) == k x].
Variables (rT1 rT2 : eqType) (f : aT -> aT) (h : rT1 -> rT2) (k : aT -> rT1).
Lemma invariant_comp : subpred (invariant f k) (invariant f (h \o k)).
Proof. by move=> x eq_kfx; rewrite /= (eqP eq_kfx). Qed.
Lemma invariant_inj : injective h -> invariant f (h \o k) =1 invariant f k.
Proof. by move=> inj_h x; apply: (inj_eq inj_h). Qed.
End EqFun.
Prenex Implicits frel.
(* The coercion to rel must be explicit for derived Notations to unparse. *)
Notation coerced_frel f := (rel_of_simpl (frel f)) (only parsing).
Section FunWith.
Variables (aT : eqType) (rT : Type).
Variant fun_delta : Type := FunDelta of aT & rT.
Definition fwith x y (f : aT -> rT) := [fun z => if z == x then y else f z].
Definition app_fdelta df f z :=
let: FunDelta x y := df in if z == x then y else f z.
End FunWith.
Prenex Implicits fwith.
Notation "x |-> y" := (FunDelta x y)
(at level 190, no associativity,
format "'[hv' x '/ ' |-> y ']'") : fun_delta_scope.
Delimit Scope fun_delta_scope with FUN_DELTA.
Arguments app_fdelta {aT rT%_type} df%_FUN_DELTA f z.
Notation "[ 'fun' z : T => F 'with' d1 , .. , dn ]" :=
(SimplFunDelta (fun z : T =>
app_fdelta d1%FUN_DELTA .. (app_fdelta dn%FUN_DELTA (fun _ => F)) ..))
(z name, only parsing) : function_scope.
Notation "[ 'fun' z => F 'with' d1 , .. , dn ]" :=
(SimplFunDelta (fun z =>
app_fdelta d1%FUN_DELTA .. (app_fdelta dn%FUN_DELTA (fun _ => F)) ..))
(z name, format
"'[hv' [ '[' 'fun' z => '/ ' F ']' '/' 'with' '[' d1 , '/' .. , '/' dn ']' ] ']'"
) : function_scope.
Notation "[ 'eta' f 'with' d1 , .. , dn ]" :=
(SimplFunDelta (fun _ =>
app_fdelta d1%FUN_DELTA .. (app_fdelta dn%FUN_DELTA f) ..))
(format
"'[hv' [ '[' 'eta' '/ ' f ']' '/' 'with' '[' d1 , '/' .. , '/' dn ']' ] ']'"
) : function_scope.
Section DFunWith.
Variables (I : eqType) (T : I -> Type) (f : forall i, T i).
Definition dfwith i (x : T i) (j : I) : T j :=
if (i =P j) is ReflectT ij then ecast j (T j) ij x else f j.
Lemma dfwith_in i x : dfwith x i = x.
Proof. by rewrite /dfwith; case: eqP => // ii; rewrite eq_axiomK. Qed.
Lemma dfwith_out i (x : T i) j : i != j -> dfwith x j = f j.
Proof. by rewrite /dfwith; case: eqP. Qed.
Variant dfwith_spec i (x : T i) : forall j, T j -> Type:=
| DFunWithIn : dfwith_spec x x
| DFunWithOut j : i != j -> dfwith_spec x (f j).
Lemma dfwithP i (x : T i) (j : I) : dfwith_spec x (dfwith x j).
Proof.
by case: (eqVneq i j) => [<-|nij];
[rewrite dfwith_in|rewrite dfwith_out//]; constructor.
Qed.
End DFunWith.
Arguments dfwith {I T} f [i] x.
(* Various EqType constructions. *)
Section ComparableType.
Variable T : Type.
Definition comparable := forall x y : T, decidable (x = y).
Hypothesis compare_T : comparable.
Definition compareb x y : bool := compare_T x y.
Lemma compareP : Equality.axiom compareb.
Proof. by move=> x y; apply: sumboolP. Qed.
Definition comparableMixin := hasDecEq.Build T compareP.
End ComparableType.
Definition eq_comparable (T : eqType) : comparable T :=
fun x y => decP (x =P y).
#[key="sub_sort"]
HB.mixin Record isSub (T : Type) (P : pred T) (sub_sort : Type) := {
val_subdef : sub_sort -> T;
Sub : forall x, P x -> sub_sort;
Sub_rect : forall K (_ : forall x Px, K (@Sub x Px)) u, K u;
SubK_subproof : forall x Px, val_subdef (@Sub x Px) = x
}.
#[short(type="subType")]
HB.structure Definition SubType (T : Type) (P : pred T) := { S of isSub T P S }.
Notation val := (isSub.val_subdef (SubType.on _)).
Notation "\val" := (isSub.val_subdef (SubType.on _)) (only parsing).
Notation "\val" := (isSub.val_subdef _) (only printing).
#[short(type="subEqType")]
HB.structure Definition SubEquality T (P : pred T) :=
{ sT of Equality sT & isSub T P sT}.
Section SubType.
Variables (T : Type) (P : pred T).
(* Generic proof that the second property holds by conversion. *)
(* The vrefl_rect alias is used to flag generic proofs of the first property. *)
Lemma vrefl : forall x, P x -> x = x. Proof. by []. Qed.
Definition vrefl_rect := vrefl.
Section Theory.
Variable sT : subType P.
Local Notation val := (isSub.val_subdef (SubType.on sT)).
Local Notation Sub := (@Sub _ _ sT).
Lemma SubK x Px : val (@Sub x Px) = x. Proof. exact: SubK_subproof. Qed.
Variant Sub_spec : sT -> Type := subSpec x Px : Sub_spec (Sub x Px).
Lemma SubP u : Sub_spec u.
Proof. by elim/(@Sub_rect _ _ sT) : u. Qed.
(* BUG in elim? sT could be inferred from u *)
Definition insub x := if idP is ReflectT Px then Some (Sub x Px) else None.
Definition insubd u0 x := odflt u0 (insub x).
Variant insub_spec x : option sT -> Type :=
| InsubSome u of P x & val u = x : insub_spec x (Some u)
| InsubNone of ~~ P x : insub_spec x None.
Lemma insubP x : insub_spec x (insub x).
Proof.
by rewrite /insub; case: {-}_ / idP; [left; rewrite ?SubK | right; apply/negP].
Qed.
Lemma insubT x Px : insub x = Some (Sub x Px).
Proof.
do [case: insubP => [/SubP[y Py] _ <- | /negP// ]; rewrite SubK] in Px *.
by rewrite (bool_irrelevance Px Py).
Qed.
Lemma insubF x : P x = false -> insub x = None.
Proof. by move/idP; case: insubP. Qed.
Lemma insubN x : ~~ P x -> insub x = None.
Proof. by move/negPf/insubF. Qed.
Lemma isSome_insub : ([eta insub] : pred T) =1 P.
Proof. by apply: fsym => x; case: insubP => // /negPf. Qed.
Lemma insubK : ocancel insub val.
Proof. by move=> x; case: insubP. Qed.
Lemma valP u : P (val u).
Proof. by case/SubP: u => x Px; rewrite SubK. Qed.
Lemma valK : pcancel val insub.
Proof. by case/SubP=> x Px; rewrite SubK; apply: insubT. Qed.
Lemma val_inj : injective val.
Proof. exact: pcan_inj valK. Qed.
Lemma valKd u0 : cancel val (insubd u0).
Proof. by move=> u; rewrite /insubd valK. Qed.
Lemma val_insubd u0 x : val (insubd u0 x) = if P x then x else val u0.
Proof. by rewrite /insubd; case: insubP => [u -> | /negPf->]. Qed.
Lemma insubdK u0 : {in P, cancel (insubd u0) val}.
Proof. by move=> x Px; rewrite val_insubd [P x]Px. Qed.
Let insub_eq_aux x isPx : P x = isPx -> option sT :=
if isPx as b return _ = b -> _ then fun Px => Some (Sub x Px) else fun=> None.
Definition insub_eq x := insub_eq_aux (erefl (P x)).
Lemma insub_eqE : insub_eq =1 insub.
Proof.
rewrite /insub_eq => x; set b := P x; rewrite [in LHS]/b in (Db := erefl b) *.
by case: b in Db *; [rewrite insubT | rewrite insubF].
Qed.
End Theory.
End SubType.
(* Arguments val {T P sT} u : rename. *)
Arguments Sub {T P sT} x Px : rename.
Arguments vrefl {T P} x Px.
Arguments vrefl_rect {T P} x Px.
Arguments insub {T P sT} x.
Arguments insubd {T P sT} u0 x.
Arguments insubT [T] P [sT x].
Arguments val_inj {T P sT} [u1 u2] eq_u12 : rename.
Arguments valK {T P sT} u : rename.
Arguments valKd {T P sT} u0 u : rename.
Arguments insubK {T P} sT x.
Arguments insubdK {T P sT} u0 [x] Px.
Local Notation inlined_sub_rect :=
(fun K K_S u => let (x, Px) as u return K u := u in K_S x Px).
Local Notation inlined_new_rect :=
(fun K K_S u => let (x) as u return K u := u in K_S x).
Reserved Notation "[ 'isSub' 'for' v ]" (format "[ 'isSub' 'for' v ]").
Notation "[ 'isSub' 'for' v ]" :=
(@isSub.phant_Build _ _ _ v _ inlined_sub_rect vrefl_rect)
(only parsing) : form_scope.
Notation "[ 'isSub' 'of' T 'for' v ]" :=
(@isSub.phant_Build _ _ T v _ inlined_sub_rect vrefl_rect)
(only parsing) : form_scope.
Notation "[ 'isSub' 'for' v 'by' rec ]" :=
(@isSub.phant_Build _ _ _ v _ rec vrefl)
(format "[ 'isSub' 'for' v 'by' rec ]") : form_scope.
Notation "[ 'isSub' 'for' v ]" := (@isSub.phant_Build _ _ _ v _ _ _)
(only printing, format "[ 'isSub' 'for' v ]") : form_scope.
Reserved Notation "[ 'isNew' 'for' v ]" (format "[ 'isNew' 'for' v ]").
Definition NewMixin T U v c Urec sk :=
let Urec' P IH := Urec P (fun x : T => IH x isT : P _) in
@isSub.phant_Build _ _ U v (fun x _ => c x) Urec' sk.
Notation "[ 'isNew' 'for' v ]" :=
(@NewMixin _ _ v _ inlined_new_rect vrefl_rect) (only parsing) : form_scope.
Notation "[ 'isNew' 'for' v ]" := (@NewMixin _ _ v _ _ _)
(only printing, format "[ 'isNew' 'for' v ]") : form_scope.
Notation "[ 'isNew' 'of' T 'for' v ]" :=
(@NewMixin _ T v _ inlined_new_rect vrefl_rect) (only parsing) : form_scope.
Definition innew T nT x := @Sub T predT nT x (erefl true).
Arguments innew {T nT}.
Lemma innew_val T nT : cancel val (@innew T nT).
Proof. by move=> u; apply: val_inj; apply: SubK. Qed.
HB.instance Definition _ T (P : pred T) := [isSub of sig P for sval].
(* Shorthand for sigma types over collective predicates. *)
Notation "{ x 'in' A }" := {x | x \in A}
(x at level 99, format "{ x 'in' A }") : type_scope.
Notation "{ x 'in' A | P }" := {x | (x \in A) && P}
(x at level 99, format "{ x 'in' A | P }") : type_scope.
(* Shorthand for the return type of insub. *)
Notation "{ ? x : T | P }" := (option {x : T | is_true P})
(x at level 99, only parsing) : type_scope.
Notation "{ ? x | P }" := {? x : _ | P}
(x at level 99, format "{ ? x | P }") : type_scope.
Notation "{ ? x 'in' A }" := {? x | x \in A}
(x at level 99, format "{ ? x 'in' A }") : type_scope.
Notation "{ ? x 'in' A | P }" := {? x | (x \in A) && P}
(x at level 99, format "{ ? x 'in' A | P }") : type_scope.
(* A variant of injection with default that infers a collective predicate *)
(* from the membership proof for the default value. *)
Definition insigd T (A : mem_pred T) x (Ax : in_mem x A) :=
insubd (exist [eta A] x Ax).
(* There should be a rel definition for the subType equality op, but this *)
(* seems to cause the simpl tactic to diverge on expressions involving == *)
(* on 4+ nested subTypes in a "strict" position (e.g., after ~~). *)
(* Definition feq f := [rel x y | f x == f y]. *)
Section TransferType.
Variables (T T' : Type) (f : T -> T').
Definition inj_type of injective f : Type := T.
Definition pcan_type g of pcancel f g : Type := T.
Definition can_type g of cancel f g : Type := T.
End TransferType.
Section TransferEqType.
Variables (T : Type) (eT : eqType) (f : T -> eT).
Lemma inj_eqAxiom : injective f -> Equality.axiom (fun x y => f x == f y).
Proof. by move=> f_inj x y; apply: (iffP eqP) => [|-> //]; apply: f_inj. Qed.
HB.instance Definition _ f_inj := hasDecEq.Build (inj_type f_inj)
(inj_eqAxiom f_inj).
HB.instance Definition _ g (fK : pcancel f g) := Equality.copy (pcan_type fK)
(inj_type (pcan_inj fK)).
HB.instance Definition _ g (fK : cancel f g) := Equality.copy (can_type fK)
(inj_type (can_inj fK)).
Definition deprecated_InjEqMixin f_inj := hasDecEq.Build T (inj_eqAxiom f_inj).
Definition deprecated_PcanEqMixin g (fK : pcancel f g) :=
deprecated_InjEqMixin (pcan_inj fK).
Definition deprecated_CanEqMixin g (fK : cancel f g) :=
deprecated_InjEqMixin (can_inj fK).
End TransferEqType.
Definition sub_type T (P : pred T) (sT : subType P) : Type := sT.
HB.instance Definition _ T (P : pred T) (sT : subType P) :=
SubType.on (sub_type sT).
Section SubEqType.
Variables (T : eqType) (P : pred T) (sT : subType P).
Local Notation ev_ax := (fun T v => @Equality.axiom T (fun x y => v x == v y)).
Lemma val_eqP : ev_ax sT val. Proof. exact: inj_eqAxiom val_inj. Qed.
#[hnf] HB.instance Definition _ := Equality.copy (sub_type sT) (pcan_type valK).
End SubEqType.
Lemma val_eqE (T : eqType) (P : pred T) (sT : subEqType P)
(u v : sT) : (val u == val v) = (u == v).
Proof. exact/val_eqP/eqP. Qed.
Arguments val_eqP {T P sT x y}.
Notation "[ 'Equality' 'of' T 'by' <: ]" := (Equality.copy T%type (sub_type T%type))
(format "[ 'Equality' 'of' T 'by' <: ]") : form_scope.
HB.instance Definition _ := Equality.copy void (pcan_type (of_voidK unit)).
HB.instance Definition _ (T : eqType) (P : pred T) :=
[Equality of {x | P x} by <:].
Section ProdEqType.
Variable T1 T2 : eqType.
Definition pair_eq : rel (T1 * T2) := fun u v => (u.1 == v.1) && (u.2 == v.2).
Lemma pair_eqP : Equality.axiom pair_eq.
Proof.
move=> [x1 x2] [y1 y2] /=; apply: (iffP andP) => [[]|[<- <-]] //=.
by do 2!move/eqP->.
Qed.
HB.instance Definition _ := hasDecEq.Build (T1 * T2)%type pair_eqP.
Lemma pair_eqE : pair_eq = eq_op :> rel _. Proof. by []. Qed.
Lemma xpair_eqE (x1 y1 : T1) (x2 y2 : T2) :
((x1, x2) == (y1, y2)) = ((x1 == y1) && (x2 == y2)).
Proof. by []. Qed.
Lemma pair_eq1 (u v : T1 * T2) : u == v -> u.1 == v.1.
Proof. by case/andP. Qed.
Lemma pair_eq2 (u v : T1 * T2) : u == v -> u.2 == v.2.
Proof. by case/andP. Qed.
End ProdEqType.
Arguments pair_eq {T1 T2} u v /.
Arguments pair_eqP {T1 T2}.
Definition predX T1 T2 (p1 : pred T1) (p2 : pred T2) :=
[pred z | p1 z.1 & p2 z.2].
Notation "[ 'predX' A1 & A2 ]" := (predX [in A1] [in A2])
(format "[ 'predX' A1 & A2 ]") : function_scope.
Section OptionEqType.
Variable T : eqType.
Definition opt_eq (u v : option T) : bool :=
oapp (fun x => oapp (eq_op x) false v) (~~ v) u.
Lemma opt_eqP : Equality.axiom opt_eq.
Proof.
case=> [x|] [y|] /=; by [constructor | apply: (iffP eqP) => [|[]] ->].
Qed.
HB.instance Definition _ := hasDecEq.Build (option T) opt_eqP.
End OptionEqType.
Arguments opt_eq {T} !u !v.
Section TaggedAs.
Variables (I : eqType) (T_ : I -> Type).
Implicit Types u v : {i : I & T_ i}.
Definition tagged_as u v :=
if tag u =P tag v is ReflectT eq_uv then
eq_rect_r T_ (tagged v) eq_uv
else tagged u.
Lemma tagged_asE u x : tagged_as u (Tagged T_ x) = x.
Proof.
by rewrite /tagged_as /=; case: eqP => // eq_uu; rewrite [eq_uu]eq_axiomK.
Qed.
End TaggedAs.
Section EqTagged.
Variables (I : eqType) (T_ : I -> Type).
Local Notation T := {i : I & T_ i}.
Definition etagged i u (p : tag u = i) := ecast i (T_ i) p (tagged u).
Implicit Types (i j : I) (u v : T).
Lemma eq_from_Tagged i (t s : T_ i) : Tagged T_ t = Tagged T_ s -> t = s.
Proof. by move=> /(congr1 (tagged_as (Tagged T_ t))); rewrite !tagged_asE. Qed.
Lemma etaggedK i u (p : tag u = i) : Tagged T_ (etagged p) = u.
Proof. by case: _ / p; apply: taggedK. Qed.
Definition tagged_with i : pred {i : I & T_ i} := [pred j | tag j == i].
Definition untag_with i (x : {x in tagged_with i}) : T_ i :=
etagged (eqP (valP x)).
Definition tag_with i (t : T_ i) : {x in tagged_with i} :=
exist _ (Tagged T_ t) (eq_refl i).
Lemma untag_withK i : cancel (@untag_with i) (@tag_with i).
Proof. by case=> -[j /= x eq_ji]; apply/val_inj=> /=; rewrite etaggedK. Qed.
#[local] Hint Resolve untag_withK : core.
Lemma tag_withK i : cancel (@tag_with i) (@untag_with i).
Proof. by move=> x; rewrite /untag_with/= eq_axiomK. Qed.
#[local] Hint Resolve tag_withK : core.
Lemma tag_with_bij i : bijective (@tag_with i).
Proof. by exists (@untag_with i). Qed.
Lemma untag_with_bij i : bijective (@untag_with i).
Proof. by exists (@tag_with i). Qed.
Definition untag (R : Type) (idx : R) (i : I) (F : T_ i -> R) u :=
if tag u =P i is ReflectT e then F (etagged e) else idx.
Lemma untagE (R : Type) (idx : R) (i : I) (F : T_ i -> R) u (e : tag u = i):
untag idx F u = F (etagged e).
Proof. by rewrite /untag; case: eqP => // p; rewrite (eq_irrelevance p e). Qed.
Lemma untag_dflt (R : Type) (idx : R) (i : I) (F : T_ i -> R) u : tag u != i ->
untag idx F u = idx.
Proof. by rewrite /untag; case: eqP. Qed.
Lemma untag_cst (R : Type) (idx : R) (i : I) u :
untag idx (fun _ : T_ i => idx) u = idx.
Proof. by rewrite /untag; case: eqP. Qed.
End EqTagged.
Arguments etagged {I T_ i u}.
Arguments untag {I T_ R} idx [i].
Arguments tagged_with {I}.
Arguments tag_with {I T_}.
Arguments untag_with {I T_}.
Section TagEqType.
Variables (I : eqType) (T_ : I -> eqType).
Implicit Types u v : {i : I & T_ i}.
Definition tag_eq u v := (tag u == tag v) && (tagged u == tagged_as u v).
Lemma tag_eqP : Equality.axiom tag_eq.
Proof.
rewrite /tag_eq => [] [i x] [j] /=.
case: eqP => [<-|Hij] y; last by right; case.
by apply: (iffP eqP) => [->|<-]; rewrite tagged_asE.
Qed.
HB.instance Definition _ := hasDecEq.Build {i : I & T_ i} tag_eqP.
Lemma tag_eqE : tag_eq = eq_op. Proof. by []. Qed.
Lemma eq_tag u v : u == v -> tag u = tag v.
Proof. by move/eqP->. Qed.
Lemma eq_Tagged u x :(u == Tagged _ x) = (tagged u == x).
Proof. by rewrite -tag_eqE /tag_eq eqxx tagged_asE. Qed.
End TagEqType.
Arguments tag_eq {I T_} !u !v.
Arguments tag_eqP {I T_ x y}.
Section SumEqType.
Variables T1 T2 : eqType.
Implicit Types u v : T1 + T2.
Definition sum_eq u v :=
match u, v with
| inl x, inl y | inr x, inr y => x == y
| _, _ => false
end.
Lemma sum_eqP : Equality.axiom sum_eq.
Proof. case=> x [] y /=; by [right | apply: (iffP eqP) => [->|[->]]]. Qed.
HB.instance Definition _ := hasDecEq.Build (T1 + T2)%type sum_eqP.
Lemma sum_eqE : sum_eq = eq_op. Proof. by []. Qed.
End SumEqType.
Arguments sum_eq {T1 T2} !u !v.
Arguments sum_eqP {T1 T2 x y}.
Section MonoHomoTheory.
Variables (aT rT : eqType) (f : aT -> rT).
Variables (aR aR' : rel aT) (rR rR' : rel rT).
Hypothesis aR_refl : reflexive aR.
Hypothesis rR_refl : reflexive rR.
Hypothesis aR'E : forall x y, aR' x y = (x != y) && (aR x y).
Hypothesis rR'E : forall x y, rR' x y = (x != y) && (rR x y).
Let aRE x y : aR x y = (x == y) || (aR' x y).
Proof. by rewrite aR'E; case: eqVneq => //= ->; apply: aR_refl. Qed.
Let rRE x y : rR x y = (x == y) || (rR' x y).
Proof. by rewrite rR'E; case: eqVneq => //= ->; apply: rR_refl. Qed.
Section InDom.
Variable D : pred aT.
Section DifferentDom.
Variable D' : pred aT.
Lemma homoW_in : {in D & D', {homo f : x y / aR' x y >-> rR' x y}} ->
{in D & D', {homo f : x y / aR x y >-> rR x y}}.
Proof.
by move=> mf x y xD yD /[!aRE]/orP[/eqP->|/mf]; rewrite rRE ?eqxx// orbC => ->.
Qed.
Lemma inj_homo_in : {in D & D', injective f} ->
{in D & D', {homo f : x y / aR x y >-> rR x y}} ->
{in D & D', {homo f : x y / aR' x y >-> rR' x y}}.
Proof.
move=> fI mf x y xD yD /[!(aR'E, rR'E)] /andP[neq_xy xy].
by rewrite mf ?andbT//; apply: contra_neq neq_xy; apply: fI.
Qed.
End DifferentDom.
Hypothesis aR_anti : antisymmetric aR.
Hypothesis rR_anti : antisymmetric rR.
Lemma mono_inj_in : {in D &, {mono f : x y / aR x y >-> rR x y}} ->
{in D &, injective f}.
Proof. by move=> mf x y ?? eqf; apply/aR_anti; rewrite -!mf// eqf rR_refl. Qed.
Lemma anti_mono_in : {in D &, {mono f : x y / aR x y >-> rR x y}} ->
{in D &, {mono f : x y / aR' x y >-> rR' x y}}.
Proof.
move=> mf x y ??; rewrite rR'E aR'E mf// (@inj_in_eq _ _ D)//.
exact: mono_inj_in.
Qed.
Lemma total_homo_mono_in : total aR ->
{in D &, {homo f : x y / aR' x y >-> rR' x y}} ->
{in D &, {mono f : x y / aR x y >-> rR x y}}.
Proof.
move=> aR_tot mf x y xD yD.
have [->|neq_xy] := eqVneq x y; first by rewrite ?eqxx ?aR_refl ?rR_refl.
have [xy|] := (boolP (aR x y)); first by rewrite rRE mf ?orbT// aR'E neq_xy.
have /orP [->//|] := aR_tot x y.
rewrite aRE eq_sym (negPf neq_xy) /= => /mf -/(_ yD xD).
rewrite rR'E => /andP[Nfxfy fyfx] _; apply: contra_neqF Nfxfy => fxfy.
by apply/rR_anti; rewrite fyfx fxfy.
Qed.
End InDom.
Let D := @predT aT.
Lemma homoW : {homo f : x y / aR' x y >-> rR' x y} ->
{homo f : x y / aR x y >-> rR x y}.
Proof. by move=> mf ???; apply: (@homoW_in D D) => // ????; apply: mf. Qed.
Lemma inj_homo : injective f ->
{homo f : x y / aR x y >-> rR x y} ->
{homo f : x y / aR' x y >-> rR' x y}.
Proof.
by move=> fI mf ???; apply: (@inj_homo_in D D) => //????; [apply: fI|apply: mf].
Qed.
Hypothesis aR_anti : antisymmetric aR.
Hypothesis rR_anti : antisymmetric rR.
Lemma mono_inj : {mono f : x y / aR x y >-> rR x y} -> injective f.
Proof. by move=> mf x y eqf; apply/aR_anti; rewrite -!mf eqf rR_refl. Qed.
Lemma anti_mono : {mono f : x y / aR x y >-> rR x y} ->
{mono f : x y / aR' x y >-> rR' x y}.
Proof. by move=> mf x y; rewrite rR'E aR'E mf inj_eq //; apply: mono_inj. Qed.
Lemma total_homo_mono : total aR ->
{homo f : x y / aR' x y >-> rR' x y} ->
{mono f : x y / aR x y >-> rR x y}.
Proof.
move=> /(@total_homo_mono_in D rR_anti) hmf hf => x y.
by apply: hmf => // ?? _ _; apply: hf.
Qed.
End MonoHomoTheory.
|
TensorProduct.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.BilinearForm.Hom
import Mathlib.LinearAlgebra.Dual.Lemmas
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.RingTheory.TensorProduct.Finite
/-!
# The bilinear form on a tensor product
## Main definitions
* `LinearMap.BilinMap.tensorDistrib (B₁ ⊗ₜ B₂)`: the bilinear form on `M₁ ⊗ M₂` constructed by
applying `B₁` on `M₁` and `B₂` on `M₂`.
* `LinearMap.BilinMap.tensorDistribEquiv`: `BilinForm.tensorDistrib` as an equivalence on finite
free modules.
-/
universe u v w uR uA uM₁ uM₂ uN₁ uN₂
variable {R : Type uR} {A : Type uA} {M₁ : Type uM₁} {M₂ : Type uM₂} {N₁ : Type uN₁} {N₂ : Type uN₂}
open TensorProduct
namespace LinearMap
open LinearMap (BilinMap BilinForm)
section CommSemiring
variable [CommSemiring R] [CommSemiring A]
variable [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid N₁] [AddCommMonoid N₂]
variable [Algebra R A] [Module R M₁] [Module A M₁] [Module R N₁] [Module A N₁]
variable [SMulCommClass R A M₁] [IsScalarTower R A M₁]
variable [SMulCommClass R A N₁] [IsScalarTower R A N₁]
variable [Module R M₂] [Module R N₂]
namespace BilinMap
variable (R A) in
/-- The tensor product of two bilinear maps injects into bilinear maps on tensor products.
Note this is heterobasic; the bilinear map on the left can take values in a module over a
(commutative) algebra over the ring of the module in which the right bilinear map is valued. -/
def tensorDistrib :
(BilinMap A M₁ N₁ ⊗[R] BilinMap R M₂ N₂) →ₗ[A] BilinMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) :=
(TensorProduct.lift.equiv A (M₁ ⊗[R] M₂) (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂)).symm.toLinearMap ∘ₗ
((LinearMap.llcomp A _ _ _).flip
(TensorProduct.AlgebraTensorModule.tensorTensorTensorComm R R A A M₁ M₂ M₁ M₂).toLinearMap)
∘ₗ TensorProduct.AlgebraTensorModule.homTensorHomMap R _ _ _ _ _ _
∘ₗ (TensorProduct.AlgebraTensorModule.congr
(TensorProduct.lift.equiv A M₁ M₁ N₁)
(TensorProduct.lift.equiv R _ _ _)).toLinearMap
@[simp]
theorem tensorDistrib_tmul (B₁ : BilinMap A M₁ N₁) (B₂ : BilinMap R M₂ N₂) (m₁ : M₁) (m₂ : M₂)
(m₁' : M₁) (m₂' : M₂) :
tensorDistrib R A (B₁ ⊗ₜ B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂')
= B₁ m₁ m₁' ⊗ₜ B₂ m₂ m₂' :=
rfl
/-- The tensor product of two bilinear forms, a shorthand for dot notation. -/
protected abbrev tmul (B₁ : BilinMap A M₁ N₁) (B₂ : BilinMap R M₂ N₂) :
BilinMap A (M₁ ⊗[R] M₂) (N₁ ⊗[R] N₂) :=
tensorDistrib R A (B₁ ⊗ₜ[R] B₂)
attribute [local ext] TensorProduct.ext in
/-- A tensor product of symmetric bilinear maps is symmetric. -/
lemma tmul_isSymm {B₁ : BilinMap A M₁ N₁} {B₂ : BilinMap R M₂ N₂}
(hB₁ : ∀ x y, B₁ x y = B₁ y x) (hB₂ : ∀ x y, B₂ x y = B₂ y x)
(x y : M₁ ⊗[R] M₂) :
B₁.tmul B₂ x y = B₁.tmul B₂ y x := by
revert x y
rw [isSymm_iff_eq_flip]
aesop
variable (A) in
/-- The base change of a bilinear map (also known as "extension of scalars"). -/
protected def baseChange (B : BilinMap R M₂ N₂) : BilinMap A (A ⊗[R] M₂) (A ⊗[R] N₂) :=
BilinMap.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (LinearMap.mul A A) B
@[simp]
theorem baseChange_tmul (B₂ : BilinMap R M₂ N₂) (a : A) (m₂ : M₂)
(a' : A) (m₂' : M₂) :
B₂.baseChange A (a ⊗ₜ m₂) (a' ⊗ₜ m₂') = (a * a') ⊗ₜ (B₂ m₂ m₂') :=
rfl
lemma baseChange_isSymm {B₂ : BilinMap R M₂ N₂} (hB₂ : ∀ x y, B₂ x y = B₂ y x) (x y : A ⊗[R] M₂) :
B₂.baseChange A x y = B₂.baseChange A y x :=
tmul_isSymm mul_comm hB₂ x y
end BilinMap
namespace BilinForm
variable (R A) in
/-- The tensor product of two bilinear forms injects into bilinear forms on tensor products.
Note this is heterobasic; the bilinear form on the left can take values in an (commutative) algebra
over the ring in which the right bilinear form is valued. -/
def tensorDistrib : BilinForm A M₁ ⊗[R] BilinForm R M₂ →ₗ[A] BilinForm A (M₁ ⊗[R] M₂) :=
(AlgebraTensorModule.rid R A A).congrRight₂.toLinearMap ∘ₗ (BilinMap.tensorDistrib R A)
variable (R A) in
-- TODO: make the RHS `MulOpposite.op (B₂ m₂ m₂') • B₁ m₁ m₁'` so that this has a nicer defeq for
-- `R = A` of `B₁ m₁ m₁' * B₂ m₂ m₂'`, as it did before the generalization in https://github.com/leanprover-community/mathlib4/pull/6306.
@[simp]
theorem tensorDistrib_tmul (B₁ : BilinForm A M₁) (B₂ : BilinForm R M₂) (m₁ : M₁) (m₂ : M₂)
(m₁' : M₁) (m₂' : M₂) :
tensorDistrib R A (B₁ ⊗ₜ B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂')
= B₂ m₂ m₂' • B₁ m₁ m₁' :=
rfl
/-- The tensor product of two bilinear forms, a shorthand for dot notation. -/
protected abbrev tmul (B₁ : BilinForm A M₁) (B₂ : BilinMap R M₂ R) : BilinMap A (M₁ ⊗[R] M₂) A :=
tensorDistrib R A (B₁ ⊗ₜ[R] B₂)
attribute [local ext] TensorProduct.ext in
/-- A tensor product of symmetric bilinear forms is symmetric. -/
lemma _root_.LinearMap.IsSymm.tmul {B₁ : BilinForm A M₁} {B₂ : BilinForm R M₂}
(hB₁ : B₁.IsSymm) (hB₂ : B₂.IsSymm) : (B₁.tmul B₂).IsSymm := by
rw [LinearMap.isSymm_iff_eq_flip]
ext x₁ x₂ y₁ y₂
exact congr_arg₂ (HSMul.hSMul) (hB₂.eq x₂ y₂) (hB₁.eq x₁ y₁)
variable (A) in
/-- The base change of a bilinear form. -/
protected def baseChange (B : BilinForm R M₂) : BilinForm A (A ⊗[R] M₂) :=
BilinForm.tmul (R := R) (A := A) (M₁ := A) (M₂ := M₂) (LinearMap.mul A A) B
@[simp]
theorem baseChange_tmul (B₂ : BilinForm R M₂) (a : A) (m₂ : M₂)
(a' : A) (m₂' : M₂) :
B₂.baseChange A (a ⊗ₜ m₂) (a' ⊗ₜ m₂') = (B₂ m₂ m₂') • (a * a') :=
rfl
variable (A) in
/-- The base change of a symmetric bilinear form is symmetric. -/
lemma IsSymm.baseChange {B₂ : BilinForm R M₂} (hB₂ : B₂.IsSymm) : (B₂.baseChange A).IsSymm :=
IsSymm.tmul ⟨mul_comm⟩ hB₂
end BilinForm
end CommSemiring
section CommRing
variable [CommRing R]
variable [AddCommGroup M₁] [AddCommGroup M₂]
variable [Module R M₁] [Module R M₂]
variable [Module.Free R M₁] [Module.Finite R M₁]
variable [Module.Free R M₂] [Module.Finite R M₂]
namespace BilinForm
variable (R) in
/-- `tensorDistrib` as an equivalence. -/
noncomputable def tensorDistribEquiv :
BilinForm R M₁ ⊗[R] BilinForm R M₂ ≃ₗ[R] BilinForm R (M₁ ⊗[R] M₂) :=
-- the same `LinearEquiv`s as from `tensorDistrib`,
-- but with the inner linear map also as an equiv
TensorProduct.congr (TensorProduct.lift.equiv R _ _ _) (TensorProduct.lift.equiv R _ _ _) ≪≫ₗ
TensorProduct.dualDistribEquiv R (M₁ ⊗ M₁) (M₂ ⊗ M₂) ≪≫ₗ
(TensorProduct.tensorTensorTensorComm R _ _ _ _).dualMap ≪≫ₗ
(TensorProduct.lift.equiv R _ _ _).symm
@[simp]
theorem tensorDistribEquiv_tmul (B₁ : BilinForm R M₁) (B₂ : BilinForm R M₂) (m₁ : M₁) (m₂ : M₂)
(m₁' : M₁) (m₂' : M₂) :
tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂) (B₁ ⊗ₜ[R] B₂) (m₁ ⊗ₜ m₂) (m₁' ⊗ₜ m₂')
= B₁ m₁ m₁' * B₂ m₂ m₂' :=
rfl
variable (R M₁ M₂) in
-- TODO: make this `rfl`
@[simp]
theorem tensorDistribEquiv_toLinearMap :
(tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂)).toLinearMap = tensorDistrib R R := by
ext B₁ B₂ : 3
ext
exact mul_comm _ _
@[simp]
theorem tensorDistribEquiv_apply (B : BilinForm R M₁ ⊗ BilinForm R M₂) :
tensorDistribEquiv R (M₁ := M₁) (M₂ := M₂) B = tensorDistrib R R B :=
DFunLike.congr_fun (tensorDistribEquiv_toLinearMap R M₁ M₂) B
end BilinForm
end CommRing
end LinearMap
|
PerfectNumbers.lean
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.NumberTheory.ArithmeticFunction
import Mathlib.NumberTheory.LucasLehmer
import Mathlib.Tactic.NormNum.Prime
/-!
# Perfect Numbers
This file proves Theorem 70 from the [100 Theorems List](https://www.cs.ru.nl/~freek/100/).
The theorem characterizes even perfect numbers.
Euclid proved that if `2 ^ (k + 1) - 1` is prime (these primes are known as Mersenne primes),
then `2 ^ k * (2 ^ (k + 1) - 1)` is perfect.
Euler proved the converse, that if `n` is even and perfect, then there exists `k` such that
`n = 2 ^ k * (2 ^ (k + 1) - 1)` and `2 ^ (k + 1) - 1` is prime.
## References
https://en.wikipedia.org/wiki/Euclid%E2%80%93Euler_theorem
-/
namespace Theorems100
namespace Nat
open ArithmeticFunction Finset
theorem sigma_two_pow_eq_mersenne_succ (k : ℕ) : σ 1 (2 ^ k) = mersenne (k + 1) := by
simp_rw [sigma_one_apply, mersenne, ← one_add_one_eq_two, ← geom_sum_mul_add 1 (k + 1)]
norm_num
/-- Euclid's theorem that Mersenne primes induce perfect numbers -/
theorem perfect_two_pow_mul_mersenne_of_prime (k : ℕ) (pr : (mersenne (k + 1)).Prime) :
Nat.Perfect (2 ^ k * mersenne (k + 1)) := by
rw [Nat.perfect_iff_sum_divisors_eq_two_mul, ← mul_assoc, ← pow_succ', ← sigma_one_apply,
mul_comm,
isMultiplicative_sigma.map_mul_of_coprime ((Odd.coprime_two_right (by simp)).pow_right _),
sigma_two_pow_eq_mersenne_succ]
· simp [pr, sigma_one_apply]
· positivity
theorem ne_zero_of_prime_mersenne (k : ℕ) (pr : (mersenne (k + 1)).Prime) : k ≠ 0 := by
intro H
simp [H, mersenne, Nat.not_prime_one] at pr
theorem even_two_pow_mul_mersenne_of_prime (k : ℕ) (pr : (mersenne (k + 1)).Prime) :
Even (2 ^ k * mersenne (k + 1)) := by simp [ne_zero_of_prime_mersenne k pr, parity_simps]
theorem eq_two_pow_mul_odd {n : ℕ} (hpos : 0 < n) : ∃ k m : ℕ, n = 2 ^ k * m ∧ ¬Even m := by
have h := Nat.finiteMultiplicity_iff.2 ⟨Nat.prime_two.ne_one, hpos⟩
obtain ⟨m, hm⟩ := pow_multiplicity_dvd 2 n
use multiplicity 2 n, m
refine ⟨hm, ?_⟩
rw [even_iff_two_dvd]
have hg := h.not_pow_dvd_of_multiplicity_lt (Nat.lt_succ_self _)
contrapose! hg
rcases hg with ⟨k, rfl⟩
apply Dvd.intro k
rw [pow_succ, mul_assoc, ← hm]
/-- **Perfect Number Theorem**: Euler's theorem that even perfect numbers can be factored as a
power of two times a Mersenne prime. -/
theorem eq_two_pow_mul_prime_mersenne_of_even_perfect {n : ℕ} (ev : Even n) (perf : Nat.Perfect n) :
∃ k : ℕ, Nat.Prime (mersenne (k + 1)) ∧ n = 2 ^ k * mersenne (k + 1) := by
have hpos := perf.2
rcases eq_two_pow_mul_odd hpos with ⟨k, m, rfl, hm⟩
use k
rw [even_iff_two_dvd] at hm
rw [Nat.perfect_iff_sum_divisors_eq_two_mul hpos, ← sigma_one_apply,
isMultiplicative_sigma.map_mul_of_coprime (Nat.prime_two.coprime_pow_of_not_dvd hm).symm,
sigma_two_pow_eq_mersenne_succ, ← mul_assoc, ← pow_succ'] at perf
obtain ⟨j, rfl⟩ := ((Odd.coprime_two_right (by simp)).pow_right _).dvd_of_dvd_mul_left
(Dvd.intro _ perf)
rw [← mul_assoc, mul_comm _ (mersenne _), mul_assoc] at perf
have h := mul_left_cancel₀ (by positivity) perf
rw [sigma_one_apply, Nat.sum_divisors_eq_sum_properDivisors_add_self, ← succ_mersenne, add_mul,
one_mul, add_comm] at h
have hj := add_left_cancel h
cases Nat.sum_properDivisors_dvd (by rw [hj]; apply Dvd.intro_left (mersenne (k + 1)) rfl) with
| inl h_1 =>
have j1 : j = 1 := Eq.trans hj.symm h_1
rw [j1, mul_one, Nat.sum_properDivisors_eq_one_iff_prime] at h_1
simp [h_1, j1]
| inr h_1 =>
have jcon := Eq.trans hj.symm h_1
rw [← one_mul j, ← mul_assoc, mul_one] at jcon
have jcon2 := mul_right_cancel₀ ?_ jcon
· exfalso
match k with
| 0 =>
apply hm
rw [← jcon2, pow_zero, one_mul, one_mul] at ev
rw [← jcon2, one_mul]
exact even_iff_two_dvd.mp ev
| .succ k =>
apply ne_of_lt _ jcon2
rw [mersenne, ← Nat.pred_eq_sub_one, Nat.lt_pred_iff, ← pow_one (Nat.succ 1)]
apply pow_lt_pow_right₀ (Nat.lt_succ_self 1) (Nat.succ_lt_succ k.succ_pos)
contrapose! hm
simp [hm]
/-- The Euclid-Euler theorem characterizing even perfect numbers -/
theorem even_and_perfect_iff {n : ℕ} :
Even n ∧ Nat.Perfect n ↔ ∃ k : ℕ, Nat.Prime (mersenne (k + 1)) ∧
n = 2 ^ k * mersenne (k + 1) := by
constructor
· rintro ⟨ev, perf⟩
exact Nat.eq_two_pow_mul_prime_mersenne_of_even_perfect ev perf
· rintro ⟨k, pr, rfl⟩
exact ⟨even_two_pow_mul_mersenne_of_prime k pr, perfect_two_pow_mul_mersenne_of_prime k pr⟩
end Nat
end Theorems100
|
Bernoulli.lean
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kevin Buzzard
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.RingTheory.PowerSeries.Inverse
import Mathlib.RingTheory.PowerSeries.WellKnown
/-!
# Bernoulli numbers
The Bernoulli numbers are a sequence of rational numbers that frequently show up in
number theory.
## Mathematical overview
The Bernoulli numbers $(B_0, B_1, B_2, \ldots)=(1, -1/2, 1/6, 0, -1/30, \ldots)$ are
a sequence of rational numbers. They show up in the formula for the sums of $k$th
powers. They are related to the Taylor series expansions of $x/\tan(x)$ and
of $\coth(x)$, and also show up in the values that the Riemann Zeta function
takes both at both negative and positive integers (and hence in the
theory of modular forms). For example, if $1 \leq n$ then
$$\zeta(2n)=\sum_{t\geq1}t^{-2n}=(-1)^{n+1}\frac{(2\pi)^{2n}B_{2n}}{2(2n)!}.$$
This result is formalised in Lean: `riemannZeta_two_mul_nat`.
The Bernoulli numbers can be formally defined using the power series
$$\sum B_n\frac{t^n}{n!}=\frac{t}{1-e^{-t}}$$
although that happens to not be the definition in mathlib (this is an *implementation
detail* and need not concern the mathematician).
Note that $B_1=-1/2$, meaning that we are using the $B_n^-$ of
[from Wikipedia](https://en.wikipedia.org/wiki/Bernoulli_number).
## Implementation detail
The Bernoulli numbers are defined using well-founded induction, by the formula
$$B_n=1-\sum_{k\lt n}\frac{\binom{n}{k}}{n-k+1}B_k.$$
This formula is true for all $n$ and in particular $B_0=1$. Note that this is the definition
for positive Bernoulli numbers, which we call `bernoulli'`. The negative Bernoulli numbers are
then defined as `bernoulli := (-1)^n * bernoulli'`.
## Main theorems
`sum_bernoulli : ∑ k ∈ Finset.range n, (n.choose k : ℚ) * bernoulli k = if n = 1 then 1 else 0`
-/
open Nat Finset Finset.Nat PowerSeries
variable (A : Type*) [CommRing A] [Algebra ℚ A]
/-! ### Definitions -/
/-- The Bernoulli numbers:
the $n$-th Bernoulli number $B_n$ is defined recursively via
$$B_n = 1 - \sum_{k < n} \binom{n}{k}\frac{B_k}{n+1-k}$$ -/
def bernoulli' (n : ℕ) : ℚ :=
1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k
theorem bernoulli'_def' (n : ℕ) :
bernoulli' n = 1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k := by
rw [bernoulli']
theorem bernoulli'_def (n : ℕ) :
bernoulli' n = 1 - ∑ k ∈ range n, n.choose k / (n - k + 1) * bernoulli' k := by
rw [bernoulli'_def', ← Fin.sum_univ_eq_sum_range]
theorem bernoulli'_spec (n : ℕ) :
(∑ k ∈ range n.succ, (n.choose (n - k) : ℚ) / (n - k + 1) * bernoulli' k) = 1 := by
rw [sum_range_succ_comm, bernoulli'_def n, tsub_self, choose_zero_right, sub_self, zero_add,
div_one, cast_one, one_mul, sub_add, ← sum_sub_distrib, ← sub_eq_zero, sub_sub_cancel_left,
neg_eq_zero]
exact Finset.sum_eq_zero (fun x hx => by rw [choose_symm (le_of_lt (mem_range.1 hx)), sub_self])
theorem bernoulli'_spec' (n : ℕ) :
(∑ k ∈ antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli' k.1) = 1 := by
refine ((sum_antidiagonal_eq_sum_range_succ_mk _ n).trans ?_).trans (bernoulli'_spec n)
refine sum_congr rfl fun x hx => ?_
simp only [add_tsub_cancel_of_le, mem_range_succ_iff.mp hx, cast_sub]
/-! ### Examples -/
section Examples
@[simp]
theorem bernoulli'_zero : bernoulli' 0 = 1 := by
rw [bernoulli'_def]
norm_num
@[simp]
theorem bernoulli'_one : bernoulli' 1 = 1 / 2 := by
rw [bernoulli'_def]
norm_num
@[simp]
theorem bernoulli'_two : bernoulli' 2 = 1 / 6 := by
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero]
@[simp]
theorem bernoulli'_three : bernoulli' 3 = 0 := by
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero]
@[simp]
theorem bernoulli'_four : bernoulli' 4 = -1 / 30 := by
have : Nat.choose 4 2 = 6 := by decide -- shrug
rw [bernoulli'_def]
norm_num [sum_range_succ, sum_range_succ, sum_range_zero, this]
end Examples
@[simp]
theorem sum_bernoulli' (n : ℕ) : (∑ k ∈ range n, (n.choose k : ℚ) * bernoulli' k) = n := by
cases n with | zero => simp | succ n =>
suffices
((n + 1 : ℚ) * ∑ k ∈ range n, ↑(n.choose k) / (n - k + 1) * bernoulli' k) =
∑ x ∈ range n, ↑(n.succ.choose x) * bernoulli' x by
rw_mod_cast [sum_range_succ, bernoulli'_def, ← this, choose_succ_self_right]
ring
simp_rw [mul_sum, ← mul_assoc]
refine sum_congr rfl fun k hk => ?_
congr
have : ((n - k : ℕ) : ℚ) + 1 ≠ 0 := by norm_cast
field_simp [← cast_sub (mem_range.1 hk).le, mul_comm]
rw_mod_cast [tsub_add_eq_add_tsub (mem_range.1 hk).le, choose_mul_succ_eq]
/-- The exponential generating function for the Bernoulli numbers `bernoulli' n`. -/
def bernoulli'PowerSeries :=
mk fun n => algebraMap ℚ A (bernoulli' n / n !)
theorem bernoulli'PowerSeries_mul_exp_sub_one :
bernoulli'PowerSeries A * (exp A - 1) = X * exp A := by
ext n
-- constant coefficient is a special case
cases n with | zero => simp | succ n =>
rw [bernoulli'PowerSeries, coeff_mul, mul_comm X, sum_antidiagonal_succ']
suffices (∑ p ∈ antidiagonal n,
bernoulli' p.1 / p.1! * ((p.2 + 1) * p.2! : ℚ)⁻¹) = (n ! : ℚ)⁻¹ by
simpa [map_sum, Nat.factorial] using congr_arg (algebraMap ℚ A) this
apply eq_inv_of_mul_eq_one_left
rw [sum_mul]
convert bernoulli'_spec' n using 1
apply sum_congr rfl
simp_rw [mem_antidiagonal]
rintro ⟨i, j⟩ rfl
have := factorial_mul_factorial_dvd_factorial_add i j
field_simp [mul_comm _ (bernoulli' i), mul_assoc, add_choose]
norm_cast
simp [mul_comm (j + 1)]
/-- Odd Bernoulli numbers (greater than 1) are zero. -/
theorem bernoulli'_odd_eq_zero {n : ℕ} (h_odd : Odd n) (hlt : 1 < n) : bernoulli' n = 0 := by
let B := mk fun n => bernoulli' n / (n ! : ℚ)
suffices (B - evalNegHom B) * (exp ℚ - 1) = X * (exp ℚ - 1) by
rcases mul_eq_mul_right_iff.mp this with h | h <;>
simp only [PowerSeries.ext_iff, evalNegHom, coeff_X] at h
· apply eq_zero_of_neg_eq
specialize h n
split_ifs at h <;> simp_all [B, h_odd.neg_one_pow, factorial_ne_zero]
· simpa +decide [Nat.factorial] using h 1
have h : B * (exp ℚ - 1) = X * exp ℚ := by
simpa [bernoulli'PowerSeries] using bernoulli'PowerSeries_mul_exp_sub_one ℚ
rw [sub_mul, h, mul_sub X, sub_right_inj, ← neg_sub, mul_neg, neg_eq_iff_eq_neg]
suffices evalNegHom (B * (exp ℚ - 1)) * exp ℚ = evalNegHom (X * exp ℚ) * exp ℚ by
simpa [mul_assoc, sub_mul, mul_comm (evalNegHom (exp ℚ)), exp_mul_exp_neg_eq_one]
congr
/-- The Bernoulli numbers are defined to be `bernoulli'` with a parity sign. -/
def bernoulli (n : ℕ) : ℚ :=
(-1) ^ n * bernoulli' n
theorem bernoulli'_eq_bernoulli (n : ℕ) : bernoulli' n = (-1) ^ n * bernoulli n := by
simp [bernoulli, ← mul_assoc, ← sq, ← pow_mul, mul_comm n 2]
@[simp]
theorem bernoulli_zero : bernoulli 0 = 1 := by simp [bernoulli]
@[simp]
theorem bernoulli_one : bernoulli 1 = -1 / 2 := by norm_num [bernoulli]
theorem bernoulli_eq_bernoulli'_of_ne_one {n : ℕ} (hn : n ≠ 1) : bernoulli n = bernoulli' n := by
by_cases h0 : n = 0; · simp [h0]
rw [bernoulli, neg_one_pow_eq_pow_mod_two]
rcases mod_two_eq_zero_or_one n with h | h
· simp [h]
· simp [bernoulli'_odd_eq_zero (odd_iff.mpr h) (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, hn⟩)]
@[simp]
theorem sum_bernoulli (n : ℕ) :
(∑ k ∈ range n, (n.choose k : ℚ) * bernoulli k) = if n = 1 then 1 else 0 := by
cases n with | zero => simp | succ n =>
cases n with | zero => rw [sum_range_one]; simp | succ n =>
suffices (∑ i ∈ range n, ↑((n + 2).choose (i + 2)) * bernoulli (i + 2)) = n / 2 by
simp only [this, sum_range_succ', cast_succ, bernoulli_one, bernoulli_zero, choose_one_right,
mul_one, choose_zero_right, cast_zero, if_false, zero_add, succ_succ_ne_one]
ring
have f := sum_bernoulli' n.succ.succ
simp_rw [sum_range_succ', cast_succ, ← eq_sub_iff_add_eq] at f
refine Eq.trans ?_ (Eq.trans f ?_)
· congr
funext x
rw [bernoulli_eq_bernoulli'_of_ne_one (succ_ne_zero x ∘ succ.inj)]
· simp only [one_div, mul_one, bernoulli'_zero, choose_zero_right,
zero_add, choose_one_right, cast_succ, bernoulli'_one, one_div]
ring
theorem bernoulli_spec' (n : ℕ) :
(∑ k ∈ antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli k.1) =
if n = 0 then 1 else 0 := by
cases n with | zero => simp | succ n =>
rw [if_neg (succ_ne_zero _)]
-- algebra facts
have h₁ : (1, n) ∈ antidiagonal n.succ := by simp [mem_antidiagonal, add_comm]
have h₂ : (n : ℚ) + 1 ≠ 0 := by norm_cast
have h₃ : (1 + n).choose n = n + 1 := by simp [add_comm]
-- key equation: the corresponding fact for `bernoulli'`
have H := bernoulli'_spec' n.succ
-- massage it to match the structure of the goal, then convert piece by piece
rw [sum_eq_add_sum_diff_singleton h₁] at H ⊢
apply add_eq_of_eq_sub'
convert eq_sub_of_add_eq' H using 1
· refine sum_congr rfl fun p h => ?_
obtain ⟨h', h''⟩ : p ∈ _ ∧ p ≠ _ := by rwa [mem_sdiff, mem_singleton] at h
simp [bernoulli_eq_bernoulli'_of_ne_one ((not_congr (antidiagonal_congr h' h₁)).mp h'')]
· field_simp [h₃]
norm_num
/-- The exponential generating function for the Bernoulli numbers `bernoulli n`. -/
def bernoulliPowerSeries :=
mk fun n => algebraMap ℚ A (bernoulli n / n !)
theorem bernoulliPowerSeries_mul_exp_sub_one : bernoulliPowerSeries A * (exp A - 1) = X := by
ext n
-- constant coefficient is a special case
cases n with | zero => simp | succ n =>
simp only [bernoulliPowerSeries, coeff_mul, coeff_X, sum_antidiagonal_succ', one_div, coeff_mk,
coeff_one, coeff_exp, LinearMap.map_sub, factorial, if_pos, cast_succ, cast_mul,
sub_zero, add_eq_zero, if_false, one_ne_zero,
and_false, ← RingHom.map_mul, ← map_sum]
cases n with | zero => simp | succ n =>
rw [if_neg n.succ_succ_ne_one]
have hfact : ∀ m, (m ! : ℚ) ≠ 0 := fun m => mod_cast factorial_ne_zero m
have hite2 : ite (n.succ = 0) 1 0 = (0 : ℚ) := if_neg n.succ_ne_zero
simp only [CharP.cast_eq_zero, zero_add, inv_one, map_one, sub_self, mul_zero]
rw [← map_zero (algebraMap ℚ A), ← zero_div (n.succ ! : ℚ), ← hite2, ← bernoulli_spec', sum_div]
refine congr_arg (algebraMap ℚ A) (sum_congr rfl fun x h => eq_div_of_mul_eq (hfact n.succ) ?_)
rw [mem_antidiagonal] at h
rw [← h, add_choose, cast_div_charZero (factorial_mul_factorial_dvd_factorial_add _ _)]
field_simp [hfact x.1, mul_comm _ (bernoulli x.1), mul_assoc]
left; left; ring
section Faulhaber
/-- **Faulhaber's theorem** relating the **sum of p-th powers** to the Bernoulli numbers:
$$\sum_{k=0}^{n-1} k^p = \sum_{i=0}^p B_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$
See https://proofwiki.org/wiki/Faulhaber%27s_Formula and [orosi2018faulhaber] for
the proof provided here. -/
theorem sum_range_pow (n p : ℕ) :
(∑ k ∈ range n, (k : ℚ) ^ p) =
∑ i ∈ range (p + 1), bernoulli i * ((p + 1).choose i) * (n : ℚ) ^ (p + 1 - i) / (p + 1) := by
have hne : ∀ m : ℕ, (m ! : ℚ) ≠ 0 := fun m => mod_cast factorial_ne_zero m
-- compute the Cauchy product of two power series
have h_cauchy :
((mk fun p => bernoulli p / p !) * mk fun q => coeff ℚ (q + 1) (exp ℚ ^ n)) =
mk fun p => ∑ i ∈ range (p + 1),
bernoulli i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1)! := by
ext q : 1
let f a b := bernoulli a / a ! * coeff ℚ (b + 1) (exp ℚ ^ n)
-- key step: use `PowerSeries.coeff_mul` and then rewrite sums
simp only [f, coeff_mul, coeff_mk, sum_antidiagonal_eq_sum_range_succ f]
apply sum_congr rfl
intros m h
simp only [exp_pow_eq_rescale_exp, rescale, RingHom.coe_mk]
-- manipulate factorials and binomial coefficients
simp? at h says simp only [succ_eq_add_one, mem_range] at h
rw [choose_eq_factorial_div_factorial h.le, eq_comm, div_eq_iff (hne q.succ), succ_eq_add_one,
mul_assoc _ _ (q.succ ! : ℚ), mul_comm _ (q.succ ! : ℚ), ← mul_assoc, div_mul_eq_mul_div]
simp only [MonoidHom.coe_mk, OneHom.coe_mk, coeff_exp, Algebra.algebraMap_self, one_div,
map_inv₀, map_natCast, coeff_mk]
rw [mul_comm ((n : ℚ) ^ (q - m + 1)), ← mul_assoc _ _ ((n : ℚ) ^ (q - m + 1)), ← one_div,
mul_one_div, div_div, tsub_add_eq_add_tsub (le_of_lt_succ h), cast_div, cast_mul]
· ring
· exact factorial_mul_factorial_dvd_factorial h.le
· simp [factorial_ne_zero]
-- same as our goal except we pull out `p!` for convenience
have hps :
(∑ k ∈ range n, (k : ℚ) ^ p) =
(∑ i ∈ range (p + 1),
bernoulli i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1)!) * p ! := by
suffices
(mk fun p => ∑ k ∈ range n, (k : ℚ) ^ p * algebraMap ℚ ℚ p !⁻¹) =
mk fun p =>
∑ i ∈ range (p + 1), bernoulli i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1)! by
rw [← div_eq_iff (hne p), div_eq_mul_inv, sum_mul]
rw [PowerSeries.ext_iff] at this
simpa using this p
-- the power series `exp ℚ - 1` is non-zero, a fact we need in order to use `mul_right_inj'`
have hexp : exp ℚ - 1 ≠ 0 := by
simp only [exp, PowerSeries.ext_iff, Ne, not_forall]
use 1
simp
have h_r : exp ℚ ^ n - 1 = X * mk fun p => coeff ℚ (p + 1) (exp ℚ ^ n) := by
have h_const : C ℚ (constantCoeff ℚ (exp ℚ ^ n)) = 1 := by simp
rw [← h_const, sub_const_eq_X_mul_shift]
-- key step: a chain of equalities of power series
rw [← mul_right_inj' hexp, mul_comm]
rw [← exp_pow_sum, geom_sum_mul, h_r, ← bernoulliPowerSeries_mul_exp_sub_one,
bernoulliPowerSeries, mul_right_comm]
simp only [mul_comm, mul_eq_mul_left_iff, hexp, or_false]
refine Eq.trans (mul_eq_mul_right_iff.mpr ?_) (Eq.trans h_cauchy ?_)
· left
congr
· simp only [mul_comm, factorial]
-- massage `hps` into our goal
rw [hps, sum_mul]
refine sum_congr rfl fun x _ => ?_
field_simp [mul_right_comm _ ↑p !, ← mul_assoc _ _ ↑p !, factorial]
ring
/-- Alternate form of **Faulhaber's theorem**, relating the sum of p-th powers to the Bernoulli
numbers: $$\sum_{k=1}^{n} k^p = \sum_{i=0}^p (-1)^iB_i\binom{p+1}{i}\frac{n^{p+1-i}}{p+1}.$$
Deduced from `sum_range_pow`. -/
theorem sum_Ico_pow (n p : ℕ) :
(∑ k ∈ Ico 1 (n + 1), (k : ℚ) ^ p) =
∑ i ∈ range (p + 1), bernoulli' i * (p + 1).choose i * (n : ℚ) ^ (p + 1 - i) / (p + 1) := by
rw [← Nat.cast_succ]
-- dispose of the trivial case
cases p with | zero => simp | succ p =>
let f i := bernoulli i * p.succ.succ.choose i * (n : ℚ) ^ (p.succ.succ - i) / p.succ.succ
let f' i := bernoulli' i * p.succ.succ.choose i * (n : ℚ) ^ (p.succ.succ - i) / p.succ.succ
suffices (∑ k ∈ Ico 1 n.succ, (k : ℚ) ^ p.succ) = ∑ i ∈ range p.succ.succ, f' i by convert this
-- prove some algebraic facts that will make things easier for us later on
have hle := Nat.le_add_left 1 n
have hne : (p + 1 + 1 : ℚ) ≠ 0 := by norm_cast
have h1 : ∀ r : ℚ, r * (p + 1 + 1) * (n : ℚ) ^ p.succ / (p + 1 + 1 : ℚ) = r * (n : ℚ) ^ p.succ :=
fun r => by rw [mul_div_right_comm, mul_div_cancel_right₀ _ hne]
have h2 : f 1 + (n : ℚ) ^ p.succ = 1 / 2 * (n : ℚ) ^ p.succ := by
simp_rw [f, bernoulli_one, choose_one_right, succ_sub_succ_eq_sub, cast_succ, tsub_zero, h1]
ring
have :
(∑ i ∈ range p, bernoulli (i + 2) * (p + 2).choose (i + 2) * (n : ℚ) ^ (p - i) / ↑(p + 2)) =
∑ i ∈ range p, bernoulli' (i + 2) * (p + 2).choose (i + 2) * (n : ℚ) ^ (p - i) / ↑(p + 2) :=
sum_congr rfl fun i _ => by rw [bernoulli_eq_bernoulli'_of_ne_one (succ_succ_ne_one i)]
calc
(-- replace sum over `Ico` with sum over `range` and simplify
∑ k ∈ Ico 1 n.succ, (k : ℚ) ^ p.succ)
_ = ∑ k ∈ range n.succ, (k : ℚ) ^ p.succ := by simp [sum_Ico_eq_sub _ hle]
-- extract the last term of the sum
_ = (∑ k ∈ range n, (k : ℚ) ^ p.succ) + (n : ℚ) ^ p.succ := by rw [sum_range_succ]
-- apply the key lemma, `sum_range_pow`
_ = (∑ i ∈ range p.succ.succ, f i) + (n : ℚ) ^ p.succ := by simp [f, sum_range_pow]
-- extract the first two terms of the sum
_ = (∑ i ∈ range p, f i.succ.succ) + f 1 + f 0 + (n : ℚ) ^ p.succ := by
simp_rw [sum_range_succ']
_ = (∑ i ∈ range p, f i.succ.succ) + (f 1 + (n : ℚ) ^ p.succ) + f 0 := by ring
_ = (∑ i ∈ range p, f i.succ.succ) + 1 / 2 * (n : ℚ) ^ p.succ + f 0 := by rw [h2]
-- convert from `bernoulli` to `bernoulli'`
_ = (∑ i ∈ range p, f' i.succ.succ) + f' 1 + f' 0 := by
simpa [f, f', h1, fun i => show i + 2 = i + 1 + 1 from rfl]
-- rejoin the first two terms of the sum
_ = ∑ i ∈ range p.succ.succ, f' i := by simp_rw [sum_range_succ']
end Faulhaber
|
presentation.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.
From mathcomp Require Import fintype finset fingroup morphism.
(******************************************************************************)
(* Support for generator-and-relation presentations of groups. We provide the *)
(* syntax: *)
(* G \homg Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) *)
(* <=> G is generated by elements x_1, ..., x_m satisfying the relations *)
(* s_1 = t_1, ..., s_m = t_m, i.e., G is a homomorphic image of the *)
(* group generated by the x_i, subject to the relations s_j = t_j. *)
(* G \isog Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) *)
(* <=> G is isomorphic to the largest finite factor of the group generated *)
(* by the x_i, subject to the relations s_j = t_j. In particular, *)
(* if the abstract group defined by the presentation is finite, *)
(* it means that G is actually isomorphic to it. This is an *)
(* intensional predicate (in Prop), as even the non-triviality of a *)
(* generated group is undecidable. *)
(* Syntax details: *)
(* - Grp is a literal constant. *)
(* - There must be at least one generator and one relation. *)
(* - A relation s_j = 1 can be abbreviated as simply s_j (a.k.a. a relator). *)
(* - Two consecutive relations s_j = t, s_j+1 = t can be abbreviated *)
(* s_j = s_j+1 = t. *)
(* - The s_j and t_j are terms built from the x_i and the standard group *)
(* operators *, 1, ^-1, ^+, ^-, ^, [~ u_1, ..., u_k]; no other operator or *)
(* abbreviation may be used, as the notation is implemented using static *)
(* overloading. *)
(* - This is the closest we could get to the notation used in Aschbacher, *)
(* Grp (x_1, ... x_n : t_1,1 = ... = t_1,k1, ..., t_m,1 = ... = t_m,km) *)
(* under the current limitations of the Coq Notation facility. *)
(* Semantics details: *)
(* - G \isog Grp (...) : Prop expands to the statement *)
(* forall rT (H : {group rT}), (H \homg G) = (H \homg Grp (...)) *)
(* (with rT : finGroupType). *)
(* - G \homg Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) : bool, with *)
(* G : {set gT}, is convertible to the boolean expression *)
(* [exists t : gT * ... gT, let: (x_1, ..., x_n) := t in *)
(* (<[x_1]> <*> ... <*> <[x_n]>, (s_1, ... (s_m-1, s_m) ...)) *)
(* == (G, (t_1, ... (t_m-1, t_m) ...))] *)
(* where the tuple comparison above is convertible to the conjunction *)
(* [&& <[x_1]> <*> ... <*> <[x_n]> == G, s_1 == t_1, ... & s_m == t_m] *)
(* Thus G \homg Grp (...) can be easily exploited by destructing the tuple *)
(* created case/existsP, then destructing the tuple equality with case/eqP. *)
(* Conversely it can be proved by using apply/existsP, providing the tuple *)
(* with a single exists (u_1, ..., u_n), then using rewrite !xpair_eqE /= *)
(* to expose the conjunction, and optionally using an apply/and{m+1}P view *)
(* to split it into subgoals (in that case, the rewrite is in principle *)
(* redundant, but necessary in practice because of the poor performance of *)
(* conversion in the Coq unifier). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Module Presentation.
Section Presentation.
Implicit Types gT rT : finGroupType.
Implicit Type vT : finType. (* tuple value type *)
Inductive term :=
| Cst of nat
| Idx
| Inv of term
| Exp of term & nat
| Mul of term & term
| Conj of term & term
| Comm of term & term.
Fixpoint eval {gT} e t : gT :=
match t with
| Cst i => nth 1 e i
| Idx => 1
| Inv t1 => (eval e t1)^-1
| Exp t1 n => eval e t1 ^+ n
| Mul t1 t2 => eval e t1 * eval e t2
| Conj t1 t2 => eval e t1 ^ eval e t2
| Comm t1 t2 => [~ eval e t1, eval e t2]
end.
Inductive formula := Eq2 of term & term | And of formula & formula.
Definition Eq1 s := Eq2 s Idx.
Definition Eq3 s1 s2 t := And (Eq2 s1 t) (Eq2 s2 t).
Inductive rel_type := NoRel | Rel vT of vT & vT.
Definition bool_of_rel r := if r is Rel vT v1 v2 then v1 == v2 else true.
Local Coercion bool_of_rel : rel_type >-> bool.
Definition and_rel vT (v1 v2 : vT) r :=
if r is Rel wT w1 w2 then Rel (v1, w1) (v2, w2) else Rel v1 v2.
Fixpoint rel {gT} (e : seq gT) f r :=
match f with
| Eq2 s t => and_rel (eval e s) (eval e t) r
| And f1 f2 => rel e f1 (rel e f2 r)
end.
Inductive type := Generator of term -> type | Formula of formula.
Definition Cast p : type := p. (* syntactic scope cast *)
Local Coercion Formula : formula >-> type.
Inductive env gT := Env of {set gT} & seq gT.
Definition env1 {gT} (x : gT : finType) := Env <[x]> [:: x].
Fixpoint sat gT vT B n (s : vT -> env gT) p :=
match p with
| Formula f =>
[exists v, let: Env A e := s v in and_rel A B (rel (rev e) f NoRel)]
| Generator p' =>
let s' v := let: Env A e := s v.1 in Env (A <*> <[v.2]>) (v.2 :: e) in
sat B n.+1 s' (p' (Cst n))
end.
Definition hom gT (B : {set gT}) p := sat B 1 env1 (p (Cst 0)).
Definition iso gT (B : {set gT}) p :=
forall rT (H : {group rT}), (H \homg B) = hom H p.
End Presentation.
End Presentation.
Import Presentation.
Coercion bool_of_rel : rel_type >-> bool.
Coercion Eq1 : term >-> formula.
Coercion Formula : formula >-> type.
Declare Custom Entry group_presentation.
Notation "x * y" := (Mul x y)
(in custom group_presentation at level 40, left associativity).
Notation "x ^+ n" := (Exp x n)
(in custom group_presentation at level 29, n constr at level 28).
Notation "x ^ y" := (Conj x y)
(in custom group_presentation at level 30, right associativity).
Notation "x ^-1" := (Inv x) (in custom group_presentation at level 3).
Notation "x ^- n" := (Inv (Exp x n))
(in custom group_presentation at level 29, n constr at level 28).
Notation "[ ~ x1 , x2 , .. , xn ]" := (Comm .. (Comm x1 x2) .. xn)
(in custom group_presentation, x1, x2, xn at level 100).
Notation "x = y" := (Eq2 x y) (in custom group_presentation at level 70).
Notation "x = y = z" := (Eq3 x y z) (in custom group_presentation at level 70,
y at next level).
Notation "r1 , r2 , .. , rn" := (And .. (And r1 r2) .. rn)
(in custom group_presentation at level 200).
Notation "( p )" := p (in custom group_presentation, p at level 200).
Notation "1" := Idx (in custom group_presentation).
Notation "x" := x (in custom group_presentation at level 0, x ident).
Notation "x : p" := (Generator (fun x => Cast p))
(in custom group_presentation, x ident, p custom group_presentation at level 200).
Arguments hom _ _%_group_scope.
Arguments iso _ _%_group_scope.
Notation "H \homg 'Grp' p" := (hom H p)
(p at level 0, format "H \homg 'Grp' p") : group_scope.
Notation "H \isog 'Grp' p" := (iso H p)
(p at level 0, format "H \isog 'Grp' p") : group_scope.
Notation "H \homg 'Grp' ( x : p )" := (hom H (fun x => Cast p))
(x ident, p custom group_presentation at level 200,
format "'[hv' H '/ ' \homg 'Grp' ( x : p ) ']'") : group_scope.
Notation "H \isog 'Grp' ( x : p )" := (iso H (fun x => Cast p))
(x ident, p custom group_presentation at level 200,
format "'[hv' H '/ ' \isog 'Grp' ( x : p ) ']'") : group_scope.
Section PresentationTheory.
Implicit Types gT rT : finGroupType.
Import Presentation.
Lemma isoGrp_hom gT (G : {group gT}) p : G \isog Grp p -> G \homg Grp p.
Proof. by move <-; apply: homg_refl. Qed.
Lemma isoGrpP gT (G : {group gT}) p rT (H : {group rT}) :
G \isog Grp p -> reflect (#|H| = #|G| /\ H \homg Grp p) (H \isog G).
Proof.
move=> isoGp; apply: (iffP idP) => [isoGH | [oH homHp]].
by rewrite (card_isog isoGH) -isoGp isog_hom.
by rewrite isogEcard isoGp homHp /= oH.
Qed.
Lemma homGrp_trans rT gT (H : {set rT}) (G : {group gT}) p :
H \homg G -> G \homg Grp p -> H \homg Grp p.
Proof.
case/homgP=> h <-{H}; rewrite /hom; move: {p}(p _) => p.
have evalG e t: all [in G] e -> eval (map h e) t = h (eval e t).
move=> Ge; apply: (@proj2 (eval e t \in G)); elim: t => /=.
- move=> i; case: (leqP (size e) i) => [le_e_i | lt_i_e].
by rewrite !nth_default ?size_map ?morph1.
by rewrite (nth_map 1) // [_ \in G](allP Ge) ?mem_nth.
- by rewrite morph1.
- by move=> t [Gt ->]; rewrite groupV morphV.
- by move=> t [Gt ->] n; rewrite groupX ?morphX.
- by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupM ?morphM.
- by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupJ ?morphJ.
by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupR ?morphR.
have and_relE xT x1 x2 r: @and_rel xT x1 x2 r = (x1 == x2) && r :> bool.
by case: r => //=; rewrite andbT.
have rsatG e f: all [in G] e -> rel e f NoRel -> rel (map h e) f NoRel.
move=> Ge; have: NoRel -> NoRel by []; move: NoRel {2 4}NoRel.
elim: f => [x1 x2 | f1 IH1 f2 IH2] r hr IHr; last by apply: IH1; apply: IH2.
by rewrite !and_relE !evalG //; case/andP; move/eqP->; rewrite eqxx.
set s := env1; set vT := gT : finType in s *.
set s' := env1; set vT' := rT : finType in s' *.
have (v): let: Env A e := s v in
A \subset G -> all [in G] e /\ exists v', s' v' = Env (h @* A) (map h e).
- rewrite /= cycle_subG andbT => Gv; rewrite morphim_cycle //.
by split; last exists (h v).
elim: p 1%N vT vT' s s' => /= [p IHp | f] n vT vT' s s' Gs.
apply: IHp => [[v x]] /=; case: (s v) {Gs}(Gs v) => A e /= Gs.
rewrite join_subG cycle_subG; case/andP=> sAG Gx; rewrite Gx.
have [//|-> [v' def_v']] := Gs; split=> //; exists (v', h x); rewrite def_v'.
by congr (Env _ _); rewrite morphimY ?cycle_subG // morphim_cycle.
case/existsP=> v; case: (s v) {Gs}(Gs v) => /= A e Gs.
rewrite and_relE => /andP[/eqP defA rel_f].
have{Gs} [|Ge [v' def_v']] := Gs; first by rewrite defA.
apply/existsP; exists v'; rewrite def_v' and_relE defA eqxx /=.
by rewrite -map_rev rsatG ?(eq_all_r (mem_rev e)).
Qed.
Lemma eq_homGrp gT rT (G : {group gT}) (H : {group rT}) p :
G \isog H -> (G \homg Grp p) = (H \homg Grp p).
Proof.
by rewrite isogEhom => /andP[homGH homHG]; apply/idP/idP; apply: homGrp_trans.
Qed.
Lemma isoGrp_trans gT rT (G : {group gT}) (H : {group rT}) p :
G \isog H -> H \isog Grp p -> G \isog Grp p.
Proof. by move=> isoGH isoHp kT K; rewrite -isoHp; apply: eq_homgr. Qed.
Lemma intro_isoGrp gT (G : {group gT}) p :
G \homg Grp p -> (forall rT (H : {group rT}), H \homg Grp p -> H \homg G) ->
G \isog Grp p.
Proof.
move=> homGp freeG rT H.
by apply/idP/idP=> [homHp|]; [apply: homGrp_trans homGp | apply: freeG].
Qed.
End PresentationTheory.
|
Prod.lean
|
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.MeasureTheory.MeasurableSpace.Embedding
import Mathlib.MeasureTheory.PiSystem
/-!
# The product sigma algebra
This file talks about the measurability of operations on binary functions.
-/
assert_not_exists MeasureTheory.Measure
noncomputable section
open Set MeasurableSpace
variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β]
/-- The product of generated σ-algebras is the one generated by rectangles, if both generating sets
are countably spanning. -/
theorem generateFrom_prod_eq {α β} {C : Set (Set α)} {D : Set (Set β)} (hC : IsCountablySpanning C)
(hD : IsCountablySpanning D) :
@Prod.instMeasurableSpace _ _ (generateFrom C) (generateFrom D) =
generateFrom (image2 (· ×ˢ ·) C D) := by
apply le_antisymm
· refine sup_le ?_ ?_ <;> rw [comap_generateFrom] <;> apply generateFrom_le <;>
rintro _ ⟨s, hs, rfl⟩
· rcases hD with ⟨t, h1t, h2t⟩
rw [← prod_univ, ← h2t, prod_iUnion]
apply MeasurableSet.iUnion
intro n
apply measurableSet_generateFrom
exact ⟨s, hs, t n, h1t n, rfl⟩
· rcases hC with ⟨t, h1t, h2t⟩
rw [← univ_prod, ← h2t, iUnion_prod_const]
apply MeasurableSet.iUnion
rintro n
apply measurableSet_generateFrom
exact mem_image2_of_mem (h1t n) hs
· apply generateFrom_le
rintro _ ⟨s, hs, t, ht, rfl⟩
dsimp only
rw [prod_eq]
apply (measurable_fst _).inter (measurable_snd _)
· exact measurableSet_generateFrom hs
· exact measurableSet_generateFrom ht
/-- If `C` and `D` generate the σ-algebras on `α` resp. `β`, then rectangles formed by `C` and `D`
generate the σ-algebra on `α × β`. -/
theorem generateFrom_eq_prod {C : Set (Set α)} {D : Set (Set β)} (hC : generateFrom C = ‹_›)
(hD : generateFrom D = ‹_›) (h2C : IsCountablySpanning C) (h2D : IsCountablySpanning D) :
generateFrom (image2 (· ×ˢ ·) C D) = Prod.instMeasurableSpace := by
rw [← hC, ← hD, generateFrom_prod_eq h2C h2D]
/-- The product σ-algebra is generated from boxes, i.e. `s ×ˢ t` for sets `s : Set α` and
`t : Set β`. -/
lemma generateFrom_prod :
generateFrom (image2 (· ×ˢ ·) { s : Set α | MeasurableSet s } { t : Set β | MeasurableSet t }) =
Prod.instMeasurableSpace :=
generateFrom_eq_prod generateFrom_measurableSet generateFrom_measurableSet
isCountablySpanning_measurableSet isCountablySpanning_measurableSet
/-- Rectangles form a π-system. -/
lemma isPiSystem_prod :
IsPiSystem (image2 (· ×ˢ ·) { s : Set α | MeasurableSet s } { t : Set β | MeasurableSet t }) :=
isPiSystem_measurableSet.prod isPiSystem_measurableSet
lemma MeasurableEmbedding.prodMap {α β γ δ : Type*} {mα : MeasurableSpace α}
{mβ : MeasurableSpace β} {mγ : MeasurableSpace γ} {mδ : MeasurableSpace δ} {f : α → β}
{g : γ → δ} (hg : MeasurableEmbedding g) (hf : MeasurableEmbedding f) :
MeasurableEmbedding (Prod.map g f) := by
refine ⟨hg.injective.prodMap hf.injective, ?_, ?_⟩
· exact (hg.measurable.comp measurable_fst).prodMk (hf.measurable.comp measurable_snd)
· intro s hs
-- Induction using the π-system of rectangles
induction s, hs using induction_on_inter generateFrom_prod.symm isPiSystem_prod with
| empty =>
simp only [Set.image_empty, MeasurableSet.empty]
| basic s hs =>
obtain ⟨t₁, ht₁, t₂, ht₂, rfl⟩ := hs
simp_rw [Prod.map, ← prod_image_image_eq]
exact (hg.measurableSet_image.mpr ht₁).prod (hf.measurableSet_image.mpr ht₂)
| compl s _ ihs =>
rw [← range_diff_image (hg.injective.prodMap hf.injective), range_prodMap]
exact .diff (.prod hg.measurableSet_range hf.measurableSet_range) ihs
| iUnion f _ _ ihf =>
simpa only [image_iUnion] using .iUnion ihf
lemma MeasurableEmbedding.prodMk_left {β γ : Type*} [MeasurableSingletonClass α]
{mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
(x : α) {f : γ → β} (hf : MeasurableEmbedding f) :
MeasurableEmbedding (fun y ↦ (x, f y)) where
injective := by
intro y y'
simp only [Prod.mk.injEq, true_and]
exact fun h ↦ hf.injective h
measurable := Measurable.prodMk measurable_const hf.measurable
measurableSet_image' := by
intro s hs
convert (MeasurableSet.singleton x).prod (hf.measurableSet_image.mpr hs)
ext x
simp [Prod.ext_iff, eq_comm, ← exists_and_left, and_left_comm]
@[deprecated (since := "2025-03-05")]
alias MeasurableEmbedding.prod_mk_left := MeasurableEmbedding.prodMk_left
lemma measurableEmbedding_prodMk_left [MeasurableSingletonClass α] (x : α) :
MeasurableEmbedding (Prod.mk x : β → α × β) :=
MeasurableEmbedding.prodMk_left x MeasurableEmbedding.id
@[deprecated (since := "2025-03-05")]
alias measurableEmbedding_prod_mk_left := measurableEmbedding_prodMk_left
lemma MeasurableEmbedding.prodMk_right {β γ : Type*} [MeasurableSingletonClass α]
{mβ : MeasurableSpace β} {mγ : MeasurableSpace γ}
{f : γ → β} (hf : MeasurableEmbedding f) (x : α) :
MeasurableEmbedding (fun y ↦ (f y, x)) :=
MeasurableEquiv.prodComm.measurableEmbedding.comp (hf.prodMk_left _)
@[deprecated (since := "2025-03-05")]
alias MeasurableEmbedding.prod_mk_right := MeasurableEmbedding.prodMk_right
lemma measurableEmbedding_prod_mk_right [MeasurableSingletonClass α] (x : α) :
MeasurableEmbedding (fun y ↦ (y, x) : β → β × α) :=
MeasurableEmbedding.prodMk_right MeasurableEmbedding.id x
|
Units.lean
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.Group.Action.Units
import Mathlib.Algebra.GroupWithZero.Action.Defs
import Mathlib.Algebra.GroupWithZero.Units.Basic
/-!
# Multiplicative actions with zero on and by `Mˣ`
This file provides the multiplicative actions with zero of a unit on a type `α`, `SMul Mˣ α`, in the
presence of `SMulWithZero M α`, with the obvious definition stated in `Units.smul_def`.
Additionally, a `MulDistribMulAction G M` for some group `G` satisfying some additional properties
admits a `MulDistribMulAction G Mˣ` structure, again with the obvious definition stated in
`Units.coe_smul`. This instance uses a primed name.
## See also
* `Algebra.GroupWithZero.Action.Opposite`
* `Algebra.GroupWithZero.Action.Pi`
* `Algebra.GroupWithZero.Action.Prod`
-/
assert_not_exists Ring
variable {G₀ G M α β : Type*}
namespace Units
variable [GroupWithZero G₀]
@[simp]
lemma smul_mk0 {α : Type*} [SMul G₀ α] {g : G₀} (hg : g ≠ 0) (a : α) : mk0 g hg • a = g • a := rfl
end Units
section GroupWithZero
variable [GroupWithZero α] [MulAction α β] {a : α}
@[simp] lemma inv_smul_smul₀ (ha : a ≠ 0) (x : β) : a⁻¹ • a • x = x :=
inv_smul_smul (Units.mk0 a ha) x
@[simp]
lemma smul_inv_smul₀ (ha : a ≠ 0) (x : β) : a • a⁻¹ • x = x := smul_inv_smul (Units.mk0 a ha) x
lemma inv_smul_eq_iff₀ (ha : a ≠ 0) {x y : β} : a⁻¹ • x = y ↔ x = a • y :=
inv_smul_eq_iff (g := Units.mk0 a ha)
lemma eq_inv_smul_iff₀ (ha : a ≠ 0) {x y : β} : x = a⁻¹ • y ↔ a • x = y :=
eq_inv_smul_iff (g := Units.mk0 a ha)
@[simp]
lemma Commute.smul_right_iff₀ [Mul β] [SMulCommClass α β β] [IsScalarTower α β β] {x y : β}
(ha : a ≠ 0) : Commute x (a • y) ↔ Commute x y := Commute.smul_right_iff (g := Units.mk0 a ha)
@[simp]
lemma Commute.smul_left_iff₀ [Mul β] [SMulCommClass α β β] [IsScalarTower α β β] {x y : β}
(ha : a ≠ 0) : Commute (a • x) y ↔ Commute x y := Commute.smul_left_iff (g := Units.mk0 a ha)
/-- Right scalar multiplication as an order isomorphism. -/
@[simps] def Equiv.smulRight (ha : a ≠ 0) : β ≃ β where
toFun b := a • b
invFun b := a⁻¹ • b
left_inv := inv_smul_smul₀ ha
right_inv := smul_inv_smul₀ ha
end GroupWithZero
namespace Units
/-! ### Action of the units of `M` on a type `α` -/
instance instSMulZeroClass [Monoid M] [Zero α] [SMulZeroClass M α] : SMulZeroClass Mˣ α where
smul := (· • ·)
smul_zero m := smul_zero (m : M)
instance instDistribSMulUnits [Monoid M] [AddZeroClass α] [DistribSMul M α] :
DistribSMul Mˣ α where smul_add m := smul_add (m : M)
instance instDistribMulAction [Monoid M] [AddMonoid α] [DistribMulAction M α] :
DistribMulAction Mˣ α where
__ := instDistribSMulUnits
one_smul := fun b => one_smul M b
mul_smul := fun x y b => mul_smul (x : M) y b
instance instMulDistribMulAction [Monoid M] [Monoid α] [MulDistribMulAction M α] :
MulDistribMulAction Mˣ α where
smul_mul m := smul_mul' (m : M)
smul_one m := smul_one (m : M)
/-! ### Action of a group `G` on units of `M` -/
/-- A stronger form of `Units.mul_action'`. -/
instance mulDistribMulAction' [Group G] [Monoid M] [MulDistribMulAction G M] [SMulCommClass G M M]
[IsScalarTower G M M] : MulDistribMulAction G Mˣ :=
{ Units.mulAction' with
smul := (· • ·),
smul_one := fun _ => Units.ext <| smul_one _,
smul_mul := fun _ _ _ => Units.ext <| smul_mul' _ _ _ }
end Units
section Monoid
variable [Monoid G] [AddMonoid M] [DistribMulAction G M] {u : G} {x : M}
@[simp] lemma IsUnit.smul_eq_zero (hu : IsUnit u) : u • x = 0 ↔ x = 0 := smul_eq_zero_iff_eq hu.unit
end Monoid
|
Elements.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.Elements
import Mathlib.CategoryTheory.Limits.Types.Limits
import Mathlib.CategoryTheory.Limits.Creates
import Mathlib.CategoryTheory.Limits.Preserves.Limits
/-!
# Limits in the category of elements
We show that if `C` has limits of shape `I` and `A : C ⥤ Type w` preserves limits of shape `I`, then
the category of elements of `A` has limits of shape `I` and the forgetful functor
`π : A.Elements ⥤ C` creates them.
-/
universe w v₁ v u₁ u
namespace CategoryTheory
open Limits Opposite
variable {C : Type u} [Category.{v} C]
namespace CategoryOfElements
variable {A : C ⥤ Type w} {I : Type u₁} [Category.{v₁} I] [Small.{w} I]
namespace CreatesLimitsAux
variable (F : I ⥤ A.Elements)
/-- (implementation) A system `(Fi, fi)_i` of elements induces an element in `lim_i A(Fi)`. -/
noncomputable def liftedConeElement' : limit ((F ⋙ π A) ⋙ A) :=
Types.Limit.mk _ (fun i => (F.obj i).2) (by simp)
@[simp]
lemma π_liftedConeElement' (i : I) :
limit.π ((F ⋙ π A) ⋙ A) i (liftedConeElement' F) = (F.obj i).2 :=
Types.Limit.π_mk _ _ _ _
variable [HasLimitsOfShape I C] [PreservesLimitsOfShape I A]
/-- (implementation) A system `(Fi, fi)_i` of elements induces an element in `A(lim_i Fi)`. -/
noncomputable def liftedConeElement : A.obj (limit (F ⋙ π A)) :=
(preservesLimitIso A (F ⋙ π A)).inv (liftedConeElement' F)
@[simp]
lemma map_lift_mapCone (c : Cone F) :
A.map (limit.lift (F ⋙ π A) ((π A).mapCone c)) c.pt.snd = liftedConeElement F := by
apply (preservesLimitIso A (F ⋙ π A)).toEquiv.injective
ext i
have h₁ := congrFun (preservesLimitIso_hom_π A (F ⋙ π A) i)
(A.map (limit.lift (F ⋙ π A) ((π A).mapCone c)) c.pt.snd)
have h₂ := (c.π.app i).property
simp_all [← FunctorToTypes.map_comp_apply, liftedConeElement]
@[simp]
lemma map_π_liftedConeElement (i : I) :
A.map (limit.π (F ⋙ π A) i) (liftedConeElement F) = (F.obj i).snd := by
have := congrFun
(preservesLimitIso_inv_π A (F ⋙ π A) i) (liftedConeElement' F)
simp_all [liftedConeElement]
/-- (implementation) The constructed limit cone. -/
@[simps]
noncomputable def liftedCone : Cone F where
pt := ⟨_, liftedConeElement F⟩
π :=
{ app := fun i => ⟨limit.π (F ⋙ π A) i, by simp⟩
naturality := fun i i' f => by ext; simpa using (limit.w _ _).symm }
/-- (implementation) The constructed limit cone is a lift of the limit cone in `C`. -/
noncomputable def isValidLift : (π A).mapCone (liftedCone F) ≅ limit.cone (F ⋙ π A) :=
Iso.refl _
/-- (implementation) The constructed limit cone is a limit cone. -/
noncomputable def isLimit : IsLimit (liftedCone F) where
lift s := ⟨limit.lift (F ⋙ π A) ((π A).mapCone s), by simp⟩
uniq s m h := ext _ _ _ <| limit.hom_ext
fun i => by simpa using congrArg Subtype.val (h i)
end CreatesLimitsAux
variable [HasLimitsOfShape I C] [PreservesLimitsOfShape I A]
section
open CreatesLimitsAux
noncomputable instance (F : I ⥤ A.Elements) : CreatesLimit F (π A) :=
createsLimitOfReflectsIso' (limit.isLimit _) ⟨⟨liftedCone F, isValidLift F⟩, isLimit F⟩
end
noncomputable instance : CreatesLimitsOfShape I (π A) where
instance : HasLimitsOfShape I A.Elements :=
hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (π A)
end CategoryOfElements
end CategoryTheory
|
TopComparison.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.Condensed.Light.Basic
import Mathlib.Condensed.TopComparison
/-!
# The functor from topological spaces to light condensed sets
We define the functor `topCatToLightCondSet : TopCat.{u} ⥤ LightCondSet.{u}`.
-/
universe u
open CategoryTheory
/--
Associate to a `u`-small topological space the corresponding light condensed set, given by
`yonedaPresheaf`.
-/
noncomputable abbrev TopCat.toLightCondSet (X : TopCat.{u}) : LightCondSet.{u} :=
toSheafCompHausLike.{u} _ X (fun _ _ _ ↦ (LightProfinite.effectiveEpi_iff_surjective _).mp)
/--
`TopCat.toLightCondSet` yields a functor from `TopCat.{u}` to `LightCondSet.{u}`.
-/
noncomputable abbrev topCatToLightCondSet : TopCat.{u} ⥤ LightCondSet.{u} :=
topCatToSheafCompHausLike.{u} _ (fun _ _ _ ↦ (LightProfinite.effectiveEpi_iff_surjective _).mp)
|
IsConnected.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Jakob von Raumer
-/
import Mathlib.Data.List.Chain
import Mathlib.CategoryTheory.PUnit
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Category.ULift
/-!
# Connected category
Define a connected category as a _nonempty_ category for which every functor
to a discrete category is isomorphic to the constant functor.
NB. Some authors include the empty category as connected, we do not.
We instead are interested in categories with exactly one 'connected
component'.
We give some equivalent definitions:
- A nonempty category for which every functor to a discrete category is
constant on objects.
See `any_functor_const_on_obj` and `Connected.of_any_functor_const_on_obj`.
- A nonempty category for which every function `F` for which the presence of a
morphism `f : j₁ ⟶ j₂` implies `F j₁ = F j₂` must be constant everywhere.
See `constant_of_preserves_morphisms` and `Connected.of_constant_of_preserves_morphisms`.
- A nonempty category for which any subset of its elements containing the
default and closed under morphisms is everything.
See `induct_on_objects` and `Connected.of_induct`.
- A nonempty category for which every object is related under the reflexive
transitive closure of the relation "there is a morphism in some direction
from `j₁` to `j₂`".
See `connected_zigzag` and `zigzag_connected`.
- A nonempty category for which for any two objects there is a sequence of
morphisms (some reversed) from one to the other.
See `exists_zigzag'` and `connected_of_zigzag`.
We also prove the result that the functor given by `(X × -)` preserves any
connected limit. That is, any limit of shape `J` where `J` is a connected
category is preserved by the functor `(X × -)`. This appears in `CategoryTheory.Limits.Connected`.
-/
universe w₁ w₂ v₁ v₂ u₁ u₂
noncomputable section
open CategoryTheory.Category CategoryTheory.Functor
open Opposite
namespace CategoryTheory
/-- A possibly empty category for which every functor to a discrete category is constant.
-/
class IsPreconnected (J : Type u₁) [Category.{v₁} J] : Prop where
iso_constant :
∀ {α : Type u₁} (F : J ⥤ Discrete α) (j : J), Nonempty (F ≅ (Functor.const J).obj (F.obj j))
attribute [inherit_doc IsPreconnected] IsPreconnected.iso_constant
/-- We define a connected category as a _nonempty_ category for which every
functor to a discrete category is constant.
NB. Some authors include the empty category as connected, we do not.
We instead are interested in categories with exactly one 'connected
component'.
This allows us to show that the functor X ⨯ - preserves connected limits. -/
@[stacks 002S]
class IsConnected (J : Type u₁) [Category.{v₁} J] : Prop extends IsPreconnected J where
[is_nonempty : Nonempty J]
attribute [instance 100] IsConnected.is_nonempty
variable {J : Type u₁} [Category.{v₁} J]
variable {K : Type u₂} [Category.{v₂} K]
namespace IsPreconnected.IsoConstantAux
/-- Implementation detail of `isoConstant`. -/
private def liftToDiscrete {α : Type u₂} (F : J ⥤ Discrete α) : J ⥤ Discrete J where
obj j := have := Nonempty.intro j
Discrete.mk (Function.invFun F.obj (F.obj j))
map {j _} f := have := Nonempty.intro j
⟨⟨congr_arg (Function.invFun F.obj) (Discrete.ext (Discrete.eq_of_hom (F.map f)))⟩⟩
/-- Implementation detail of `isoConstant`. -/
private def factorThroughDiscrete {α : Type u₂} (F : J ⥤ Discrete α) :
liftToDiscrete F ⋙ Discrete.functor F.obj ≅ F :=
NatIso.ofComponents (fun _ => eqToIso Function.apply_invFun_apply) (by cat_disch)
end IsPreconnected.IsoConstantAux
/-- If `J` is connected, any functor `F : J ⥤ Discrete α` is isomorphic to
the constant functor with value `F.obj j` (for any choice of `j`).
-/
def isoConstant [IsPreconnected J] {α : Type u₂} (F : J ⥤ Discrete α) (j : J) :
F ≅ (Functor.const J).obj (F.obj j) :=
(IsPreconnected.IsoConstantAux.factorThroughDiscrete F).symm
≪≫ isoWhiskerRight (IsPreconnected.iso_constant _ j).some _
≪≫ NatIso.ofComponents (fun _ => eqToIso Function.apply_invFun_apply) (by simp)
/-- If `J` is connected, any functor to a discrete category is constant on objects.
The converse is given in `IsConnected.of_any_functor_const_on_obj`.
-/
theorem any_functor_const_on_obj [IsPreconnected J] {α : Type u₂} (F : J ⥤ Discrete α) (j j' : J) :
F.obj j = F.obj j' := by
ext; exact ((isoConstant F j').hom.app j).down.1
/-- If any functor to a discrete category is constant on objects, J is connected.
The converse of `any_functor_const_on_obj`.
-/
theorem IsPreconnected.of_any_functor_const_on_obj
(h : ∀ {α : Type u₁} (F : J ⥤ Discrete α), ∀ j j' : J, F.obj j = F.obj j') :
IsPreconnected J where
iso_constant := fun F j' => ⟨NatIso.ofComponents fun j => eqToIso (h F j j')⟩
instance IsPreconnected.prod [IsPreconnected J] [IsPreconnected K] : IsPreconnected (J × K) := by
refine .of_any_functor_const_on_obj (fun {a} F ⟨j, k⟩ ⟨j', k'⟩ => ?_)
exact (any_functor_const_on_obj (Prod.sectL J k ⋙ F) j j').trans
(any_functor_const_on_obj (Prod.sectR j' K ⋙ F) k k')
instance IsConnected.prod [IsConnected J] [IsConnected K] : IsConnected (J × K) where
/-- If any functor to a discrete category is constant on objects, J is connected.
The converse of `any_functor_const_on_obj`.
-/
theorem IsConnected.of_any_functor_const_on_obj [Nonempty J]
(h : ∀ {α : Type u₁} (F : J ⥤ Discrete α), ∀ j j' : J, F.obj j = F.obj j') : IsConnected J :=
{ IsPreconnected.of_any_functor_const_on_obj h with }
/-- If `J` is connected, then given any function `F` such that the presence of a
morphism `j₁ ⟶ j₂` implies `F j₁ = F j₂`, we have that `F` is constant.
This can be thought of as a local-to-global property.
The converse is shown in `IsConnected.of_constant_of_preserves_morphisms`
-/
theorem constant_of_preserves_morphisms [IsPreconnected J] {α : Type u₂} (F : J → α)
(h : ∀ (j₁ j₂ : J) (_ : j₁ ⟶ j₂), F j₁ = F j₂) (j j' : J) : F j = F j' := by
simpa using
any_functor_const_on_obj
{ obj := Discrete.mk ∘ F
map := fun f => eqToHom (by ext; exact h _ _ f) }
j j'
/-- `J` is connected if: given any function `F : J → α` which is constant for any
`j₁, j₂` for which there is a morphism `j₁ ⟶ j₂`, then `F` is constant.
This can be thought of as a local-to-global property.
The converse of `constant_of_preserves_morphisms`.
-/
theorem IsPreconnected.of_constant_of_preserves_morphisms
(h : ∀ {α : Type u₁} (F : J → α),
(∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), F j₁ = F j₂) → ∀ j j' : J, F j = F j') :
IsPreconnected J :=
IsPreconnected.of_any_functor_const_on_obj fun F =>
h F.obj fun f => by ext; exact Discrete.eq_of_hom (F.map f)
/-- `J` is connected if: given any function `F : J → α` which is constant for any
`j₁, j₂` for which there is a morphism `j₁ ⟶ j₂`, then `F` is constant.
This can be thought of as a local-to-global property.
The converse of `constant_of_preserves_morphisms`.
-/
theorem IsConnected.of_constant_of_preserves_morphisms [Nonempty J]
(h : ∀ {α : Type u₁} (F : J → α),
(∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), F j₁ = F j₂) → ∀ j j' : J, F j = F j') :
IsConnected J :=
{ IsPreconnected.of_constant_of_preserves_morphisms h with }
/-- An inductive-like property for the objects of a connected category.
If the set `p` is nonempty, and `p` is closed under morphisms of `J`,
then `p` contains all of `J`.
The converse is given in `IsConnected.of_induct`.
-/
theorem induct_on_objects [IsPreconnected J] (p : Set J) {j₀ : J} (h0 : j₀ ∈ p)
(h1 : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), j₁ ∈ p ↔ j₂ ∈ p) (j : J) : j ∈ p := by
let aux (j₁ j₂ : J) (f : j₁ ⟶ j₂) := congrArg ULift.up <| (h1 f).eq
injection constant_of_preserves_morphisms (fun k => ULift.up.{u₁} (k ∈ p)) aux j j₀ with i
rwa [i]
/--
If any maximal connected component containing some element j₀ of J is all of J, then J is connected.
The converse of `induct_on_objects`.
-/
theorem IsConnected.of_induct {j₀ : J}
(h : ∀ p : Set J, j₀ ∈ p → (∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), j₁ ∈ p ↔ j₂ ∈ p) → ∀ j : J, j ∈ p) :
IsConnected J :=
have := Nonempty.intro j₀
IsConnected.of_constant_of_preserves_morphisms fun {α} F a => by
have w := h { j | F j = F j₀ } rfl (fun {j₁} {j₂} f => by
change F j₁ = F j₀ ↔ F j₂ = F j₀
simp [a f])
intro j j'
rw [w j, w j']
attribute [local instance] uliftCategory in
/-- Lifting the universe level of morphisms and objects preserves connectedness. -/
instance [hc : IsConnected J] : IsConnected (ULiftHom.{v₂} (ULift.{u₂} J)) := by
apply IsConnected.of_induct
· rintro p hj₀ h ⟨j⟩
let p' : Set J := {j : J | p ⟨j⟩}
have hj₀' : Classical.choice hc.is_nonempty ∈ p' := by
simp only [p']
exact hj₀
apply induct_on_objects p' hj₀' fun f => h ((ULiftHomULiftCategory.equiv J).functor.map f)
/-- Another induction principle for `IsPreconnected J`:
given a type family `Z : J → Sort*` and
a rule for transporting in *both* directions along a morphism in `J`,
we can transport an `x : Z j₀` to a point in `Z j` for any `j`.
-/
theorem isPreconnected_induction [IsPreconnected J] (Z : J → Sort*)
(h₁ : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), Z j₁ → Z j₂) (h₂ : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), Z j₂ → Z j₁)
{j₀ : J} (x : Z j₀) (j : J) : Nonempty (Z j) :=
(induct_on_objects { j | Nonempty (Z j) } ⟨x⟩
(fun f => ⟨by rintro ⟨y⟩; exact ⟨h₁ f y⟩, by rintro ⟨y⟩; exact ⟨h₂ f y⟩⟩)
j :)
/-- If `J` and `K` are equivalent, then if `J` is preconnected then `K` is as well. -/
theorem isPreconnected_of_equivalent {K : Type u₂} [Category.{v₂} K] [IsPreconnected J]
(e : J ≌ K) : IsPreconnected K where
iso_constant F k :=
⟨calc
F ≅ e.inverse ⋙ e.functor ⋙ F := (e.invFunIdAssoc F).symm
_ ≅ e.inverse ⋙ (Functor.const J).obj ((e.functor ⋙ F).obj (e.inverse.obj k)) :=
isoWhiskerLeft e.inverse (isoConstant (e.functor ⋙ F) (e.inverse.obj k))
_ ≅ e.inverse ⋙ (Functor.const J).obj (F.obj k) :=
isoWhiskerLeft _ ((F ⋙ Functor.const J).mapIso (e.counitIso.app k))
_ ≅ (Functor.const K).obj (F.obj k) := NatIso.ofComponents fun _ => Iso.refl _⟩
lemma isPreconnected_iff_of_equivalence {K : Type u₂} [Category.{v₂} K] (e : J ≌ K) :
IsPreconnected J ↔ IsPreconnected K :=
⟨fun _ => isPreconnected_of_equivalent e, fun _ => isPreconnected_of_equivalent e.symm⟩
/-- If `J` and `K` are equivalent, then if `J` is connected then `K` is as well. -/
theorem isConnected_of_equivalent {K : Type u₂} [Category.{v₂} K] (e : J ≌ K) [IsConnected J] :
IsConnected K :=
{ is_nonempty := Nonempty.map e.functor.obj (by infer_instance)
toIsPreconnected := isPreconnected_of_equivalent e }
lemma isConnected_iff_of_equivalence {K : Type u₂} [Category.{v₂} K] (e : J ≌ K) :
IsConnected J ↔ IsConnected K :=
⟨fun _ => isConnected_of_equivalent e, fun _ => isConnected_of_equivalent e.symm⟩
/-- If `J` is preconnected, then `Jᵒᵖ` is preconnected as well. -/
instance isPreconnected_op [IsPreconnected J] : IsPreconnected Jᵒᵖ where
iso_constant := fun {α} F X =>
⟨NatIso.ofComponents fun Y =>
eqToIso (Discrete.ext (Discrete.eq_of_hom ((Nonempty.some
(IsPreconnected.iso_constant (F.rightOp ⋙ (Discrete.opposite α).functor) (unop X))).app
(unop Y)).hom))⟩
/-- If `J` is connected, then `Jᵒᵖ` is connected as well. -/
instance isConnected_op [IsConnected J] : IsConnected Jᵒᵖ where
is_nonempty := Nonempty.intro (op (Classical.arbitrary J))
theorem isPreconnected_of_isPreconnected_op [IsPreconnected Jᵒᵖ] : IsPreconnected J :=
isPreconnected_of_equivalent (opOpEquivalence J)
theorem isConnected_of_isConnected_op [IsConnected Jᵒᵖ] : IsConnected J :=
isConnected_of_equivalent (opOpEquivalence J)
variable (J) in
@[simp]
theorem isConnected_op_iff_isConnected : IsConnected Jᵒᵖ ↔ IsConnected J :=
⟨fun _ => isConnected_of_isConnected_op, fun _ => isConnected_op⟩
/-- j₁ and j₂ are related by `Zag` if there is a morphism between them. -/
def Zag (j₁ j₂ : J) : Prop :=
Nonempty (j₁ ⟶ j₂) ∨ Nonempty (j₂ ⟶ j₁)
@[refl] theorem Zag.refl (X : J) : Zag X X := Or.inl ⟨𝟙 _⟩
theorem zag_symmetric : Symmetric (@Zag J _) := fun _ _ h => h.symm
@[symm] theorem Zag.symm {j₁ j₂ : J} (h : Zag j₁ j₂) : Zag j₂ j₁ := zag_symmetric h
theorem Zag.of_hom {j₁ j₂ : J} (f : j₁ ⟶ j₂) : Zag j₁ j₂ := Or.inl ⟨f⟩
theorem Zag.of_inv {j₁ j₂ : J} (f : j₂ ⟶ j₁) : Zag j₁ j₂ := Or.inr ⟨f⟩
/-- `j₁` and `j₂` are related by `Zigzag` if there is a chain of
morphisms from `j₁` to `j₂`, with backward morphisms allowed.
-/
def Zigzag : J → J → Prop :=
Relation.ReflTransGen Zag
theorem zigzag_symmetric : Symmetric (@Zigzag J _) :=
Relation.ReflTransGen.symmetric zag_symmetric
theorem zigzag_equivalence : _root_.Equivalence (@Zigzag J _) :=
_root_.Equivalence.mk Relation.reflexive_reflTransGen (fun h => zigzag_symmetric h)
(fun h g => Relation.transitive_reflTransGen h g)
@[refl] theorem Zigzag.refl (X : J) : Zigzag X X := zigzag_equivalence.refl _
@[symm] theorem Zigzag.symm {j₁ j₂ : J} (h : Zigzag j₁ j₂) : Zigzag j₂ j₁ := zigzag_symmetric h
@[trans] theorem Zigzag.trans {j₁ j₂ j₃ : J} (h₁ : Zigzag j₁ j₂) (h₂ : Zigzag j₂ j₃) :
Zigzag j₁ j₃ :=
zigzag_equivalence.trans h₁ h₂
instance : Trans (α := J) (Zigzag · ·) (Zigzag · ·) (Zigzag · ·) where
trans := Zigzag.trans
theorem Zigzag.of_zag {j₁ j₂ : J} (h : Zag j₁ j₂) : Zigzag j₁ j₂ :=
Relation.ReflTransGen.single h
theorem Zigzag.of_hom {j₁ j₂ : J} (f : j₁ ⟶ j₂) : Zigzag j₁ j₂ :=
of_zag (Zag.of_hom f)
theorem Zigzag.of_inv {j₁ j₂ : J} (f : j₂ ⟶ j₁) : Zigzag j₁ j₂ :=
of_zag (Zag.of_inv f)
theorem Zigzag.of_zag_trans {j₁ j₂ j₃ : J} (h₁ : Zag j₁ j₂) (h₂ : Zag j₂ j₃) : Zigzag j₁ j₃ :=
trans (of_zag h₁) (of_zag h₂)
instance : Trans (α := J) (Zag · ·) (Zigzag · ·) (Zigzag · ·) where
trans h h' := Zigzag.trans (.of_zag h) h'
instance : Trans (α := J) (Zigzag · ·) (Zag · ·) (Zigzag · ·) where
trans h h' := Zigzag.trans h (.of_zag h')
instance : Trans (α := J) (Zag · ·) (Zag · ·) (Zigzag · ·) where
trans := Zigzag.of_zag_trans
theorem Zigzag.of_hom_hom {j₁ j₂ j₃ : J} (f₁₂ : j₁ ⟶ j₂) (f₂₃ : j₂ ⟶ j₃) : Zigzag j₁ j₃ :=
(of_hom f₁₂).trans (of_hom f₂₃)
theorem Zigzag.of_hom_inv {j₁ j₂ j₃ : J} (f₁₂ : j₁ ⟶ j₂) (f₃₂ : j₃ ⟶ j₂) : Zigzag j₁ j₃ :=
(of_hom f₁₂).trans (of_inv f₃₂)
theorem Zigzag.of_inv_hom {j₁ j₂ j₃ : J} (f₂₁ : j₂ ⟶ j₁) (f₂₃ : j₂ ⟶ j₃) : Zigzag j₁ j₃ :=
(of_inv f₂₁).trans (of_hom f₂₃)
theorem Zigzag.of_inv_inv {j₁ j₂ j₃ : J} (f₂₁ : j₂ ⟶ j₁) (f₃₂ : j₃ ⟶ j₂) : Zigzag j₁ j₃ :=
(of_inv f₂₁).trans (of_inv f₃₂)
/-- The setoid given by the equivalence relation `Zigzag`. A quotient for this
setoid is a connected component of the category.
-/
def Zigzag.setoid (J : Type u₂) [Category.{v₁} J] : Setoid J where
r := Zigzag
iseqv := zigzag_equivalence
/-- If there is a zigzag from `j₁` to `j₂`, then there is a zigzag from `F j₁` to
`F j₂` as long as `F` is a prefunctor.
-/
theorem zigzag_prefunctor_obj_of_zigzag (F : J ⥤q K) {j₁ j₂ : J} (h : Zigzag j₁ j₂) :
Zigzag (F.obj j₁) (F.obj j₂) :=
h.lift _ fun _ _ => Or.imp (Nonempty.map fun f => F.map f) (Nonempty.map fun f => F.map f)
/-- If there is a zigzag from `j₁` to `j₂`, then there is a zigzag from `F j₁` to
`F j₂` as long as `F` is a functor.
-/
theorem zigzag_obj_of_zigzag (F : J ⥤ K) {j₁ j₂ : J} (h : Zigzag j₁ j₂) :
Zigzag (F.obj j₁) (F.obj j₂) :=
zigzag_prefunctor_obj_of_zigzag F.toPrefunctor h
/-- A Zag in a discrete category entails an equality of its extremities -/
lemma eq_of_zag (X) {a b : Discrete X} (h : Zag a b) : a.as = b.as :=
h.elim (fun ⟨f⟩ ↦ Discrete.eq_of_hom f) (fun ⟨f⟩ ↦ (Discrete.eq_of_hom f).symm)
/-- A zigzag in a discrete category entails an equality of its extremities -/
lemma eq_of_zigzag (X) {a b : Discrete X} (h : Zigzag a b) : a.as = b.as := by
induction h with
| refl => rfl
| tail _ h eq => exact eq.trans (eq_of_zag _ h)
-- TODO: figure out the right way to generalise this to `Zigzag`.
theorem zag_of_zag_obj (F : J ⥤ K) [F.Full] {j₁ j₂ : J} (h : Zag (F.obj j₁) (F.obj j₂)) :
Zag j₁ j₂ :=
Or.imp (Nonempty.map F.preimage) (Nonempty.map F.preimage) h
/-- Any equivalence relation containing (⟶) holds for all pairs of a connected category. -/
theorem equiv_relation [IsPreconnected J] (r : J → J → Prop) (hr : _root_.Equivalence r)
(h : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), r j₁ j₂) : ∀ j₁ j₂ : J, r j₁ j₂ := by
intros j₁ j₂
have z : ∀ j : J, r j₁ j :=
induct_on_objects {k | r j₁ k} (hr.1 j₁)
fun f => ⟨fun t => hr.3 t (h f), fun t => hr.3 t (hr.2 (h f))⟩
exact z j₂
/-- In a connected category, any two objects are related by `Zigzag`. -/
theorem isPreconnected_zigzag [IsPreconnected J] (j₁ j₂ : J) : Zigzag j₁ j₂ :=
equiv_relation _ zigzag_equivalence
(fun f => Relation.ReflTransGen.single (Or.inl (Nonempty.intro f))) _ _
theorem zigzag_isPreconnected (h : ∀ j₁ j₂ : J, Zigzag j₁ j₂) : IsPreconnected J := by
apply IsPreconnected.of_constant_of_preserves_morphisms
intro α F hF j j'
specialize h j j'
induction h with
| refl => rfl
| tail _ hj ih =>
rw [ih]
rcases hj with (⟨⟨hj⟩⟩|⟨⟨hj⟩⟩)
exacts [hF hj, (hF hj).symm]
/-- If any two objects in a nonempty category are related by `Zigzag`, the category is connected.
-/
theorem zigzag_isConnected [Nonempty J] (h : ∀ j₁ j₂ : J, Zigzag j₁ j₂) : IsConnected J :=
{ zigzag_isPreconnected h with }
theorem exists_zigzag' [IsConnected J] (j₁ j₂ : J) :
∃ l, List.Chain Zag j₁ l ∧ List.getLast (j₁ :: l) (List.cons_ne_nil _ _) = j₂ :=
List.exists_chain_of_relationReflTransGen (isPreconnected_zigzag _ _)
/-- If any two objects in a nonempty category are linked by a sequence of (potentially reversed)
morphisms, then J is connected.
The converse of `exists_zigzag'`.
-/
theorem isPreconnected_of_zigzag (h : ∀ j₁ j₂ : J, ∃ l,
List.Chain Zag j₁ l ∧ List.getLast (j₁ :: l) (List.cons_ne_nil _ _) = j₂) :
IsPreconnected J := by
apply zigzag_isPreconnected
intro j₁ j₂
rcases h j₁ j₂ with ⟨l, hl₁, hl₂⟩
apply List.relationReflTransGen_of_exists_chain l hl₁ hl₂
/-- If any two objects in a nonempty category are linked by a sequence of (potentially reversed)
morphisms, then J is connected.
The converse of `exists_zigzag'`.
-/
theorem isConnected_of_zigzag [Nonempty J] (h : ∀ j₁ j₂ : J, ∃ l,
List.Chain Zag j₁ l ∧ List.getLast (j₁ :: l) (List.cons_ne_nil _ _) = j₂) :
IsConnected J :=
{ isPreconnected_of_zigzag h with }
/-- If `Discrete α` is connected, then `α` is (type-)equivalent to `PUnit`. -/
def discreteIsConnectedEquivPUnit {α : Type u₁} [IsConnected (Discrete α)] : α ≃ PUnit :=
Discrete.equivOfEquivalence.{u₁, u₁}
{ functor := Functor.star (Discrete α)
inverse := Discrete.functor fun _ => Classical.arbitrary _
unitIso := isoConstant _ (Classical.arbitrary _)
counitIso := Functor.punitExt _ _ }
variable {C : Type w₂} [Category.{w₁} C]
/-- For objects `X Y : C`, any natural transformation `α : const X ⟶ const Y` from a connected
category must be constant.
This is the key property of connected categories which we use to establish properties about limits.
-/
theorem nat_trans_from_is_connected [IsPreconnected J] {X Y : C}
(α : (Functor.const J).obj X ⟶ (Functor.const J).obj Y) :
∀ j j' : J, α.app j = (α.app j' : X ⟶ Y) :=
@constant_of_preserves_morphisms _ _ _ (X ⟶ Y) (fun j => α.app j) fun _ _ f => by
simpa using (α.naturality f).symm
instance [IsConnected J] : (Functor.const J : C ⥤ J ⥤ C).Full where
map_surjective f := ⟨f.app (Classical.arbitrary J), by
ext j
apply nat_trans_from_is_connected f (Classical.arbitrary J) j⟩
theorem nonempty_hom_of_preconnected_groupoid {G} [Groupoid G] [IsPreconnected G] :
∀ x y : G, Nonempty (x ⟶ y) := by
refine equiv_relation _ ?_ fun {j₁ j₂} => Nonempty.intro
exact
⟨fun j => ⟨𝟙 _⟩,
fun {j₁ j₂} => Nonempty.map fun f => inv f,
fun {_ _ _} => Nonempty.map2 (· ≫ ·)⟩
attribute [instance] nonempty_hom_of_preconnected_groupoid
instance isPreconnected_of_subsingleton [Subsingleton J] : IsPreconnected J where
iso_constant {α} F j := ⟨NatIso.ofComponents (fun x ↦ eqToIso (by simp [Subsingleton.allEq x j]))⟩
instance isConnected_of_nonempty_and_subsingleton [Nonempty J] [Subsingleton J] :
IsConnected J where
end CategoryTheory
|
Prod.lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot, Eric Wieser
-/
import Mathlib.Algebra.GroupWithZero.Action.Prod
import Mathlib.Algebra.Module.Defs
/-!
# Prod instances for module and multiplicative actions
This file defines instances for binary product of modules
-/
variable {R : Type*} {M : Type*} {N : Type*}
namespace Prod
instance instModule [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] :
Module R (M × N) where
add_smul _ _ _ := by ext <;> exact add_smul ..
zero_smul _ := by ext <;> exact zero_smul ..
end Prod
|
HurwitzZetaValues.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.NumberTheory.ZetaValues
import Mathlib.NumberTheory.LSeries.RiemannZeta
/-!
# Special values of Hurwitz and Riemann zeta functions
This file gives the formula for `ζ (2 * k)`, for `k` a non-zero integer, in terms of Bernoulli
numbers. More generally, we give formulae for any Hurwitz zeta functions at any (strictly) negative
integer in terms of Bernoulli polynomials.
(Note that most of the actual work for these formulae is done elsewhere, in
`Mathlib/NumberTheory/ZetaValues.lean`. This file has only those results which really need the
definition of Hurwitz zeta and related functions, rather than working directly with the defining
sums in the convergence range.)
## Main results
- `hurwitzZeta_neg_nat`: for `k : ℕ` with `k ≠ 0`, and any `x ∈ ℝ / ℤ`, the special value
`hurwitzZeta x (-k)` is equal to `-(Polynomial.bernoulli (k + 1) x) / (k + 1)`.
- `riemannZeta_neg_nat_eq_bernoulli` : for any `k ∈ ℕ` we have the formula
`riemannZeta (-k) = (-1) ^ k * bernoulli (k + 1) / (k + 1)`
- `riemannZeta_two_mul_nat`: formula for `ζ(2 * k)` for `k ∈ ℕ, k ≠ 0` in terms of Bernoulli
numbers
## TODO
* Extend to cover Dirichlet L-functions.
* The formulae are correct for `s = 0` as well, but we do not prove this case, since this requires
Fourier series which are only conditionally convergent, which is difficult to approach using the
methods in the library at the present time (May 2024).
-/
open Complex Real Set
open scoped Nat
namespace HurwitzZeta
variable {k : ℕ} {x : ℝ}
/-- Express the value of `cosZeta` at a positive even integer as a value
of the Bernoulli polynomial. -/
theorem cosZeta_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc 0 1) :
cosZeta x (2 * k) = (-1) ^ (k + 1) * (2 * π) ^ (2 * k) / 2 / (2 * k)! *
((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [← (hasSum_nat_cosZeta x (?_ : 1 < re (2 * k))).tsum_eq]
· refine Eq.trans ?_ <|
(congr_arg ofReal (hasSum_one_div_nat_pow_mul_cos hk hx).tsum_eq).trans ?_
· rw [ofReal_tsum]
refine tsum_congr fun n ↦ ?_
norm_cast
ring_nf
· push_cast
congr 1
have : (Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ) = _ :=
(Polynomial.map_map (algebraMap ℚ ℝ) ofRealHom _).symm
rw [this, ← ofRealHom_eq_coe, ← ofRealHom_eq_coe]
apply Polynomial.map_aeval_eq_aeval_map (by simp)
· norm_cast
omega
/--
Express the value of `sinZeta` at an odd integer `> 1` as a value of the Bernoulli polynomial.
Note that this formula is also correct for `k = 0` (i.e. for the value at `s = 1`), but we do not
prove it in this case, owing to the additional difficulty of working with series that are only
conditionally convergent.
-/
theorem sinZeta_two_mul_nat_add_one (hk : k ≠ 0) (hx : x ∈ Icc 0 1) :
sinZeta x (2 * k + 1) = (-1) ^ (k + 1) * (2 * π) ^ (2 * k + 1) / 2 / (2 * k + 1)! *
((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [← (hasSum_nat_sinZeta x (?_ : 1 < re (2 * k + 1))).tsum_eq]
· refine Eq.trans ?_ <|
(congr_arg ofReal (hasSum_one_div_nat_pow_mul_sin hk hx).tsum_eq).trans ?_
· rw [ofReal_tsum]
refine tsum_congr fun n ↦ ?_
norm_cast
ring_nf
· push_cast
congr 1
have : (Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ) = _ :=
(Polynomial.map_map (algebraMap ℚ ℝ) ofRealHom _).symm
rw [this, ← ofRealHom_eq_coe, ← ofRealHom_eq_coe]
apply Polynomial.map_aeval_eq_aeval_map (by simp)
· norm_cast
omega
/-- Reformulation of `cosZeta_two_mul_nat` using `Gammaℂ`. -/
theorem cosZeta_two_mul_nat' (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
cosZeta x (2 * k) = (-1) ^ (k + 1) / (2 * k) / Gammaℂ (2 * k) *
((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [cosZeta_two_mul_nat hk hx]
congr 1
have : (2 * k)! = (2 * k) * Complex.Gamma (2 * k) := by
rw [(by { norm_cast; omega } : 2 * (k : ℂ) = ↑(2 * k - 1) + 1), Complex.Gamma_nat_eq_factorial,
← Nat.cast_add_one, ← Nat.cast_mul, ← Nat.factorial_succ, Nat.sub_add_cancel (by omega)]
simp_rw [this, Gammaℂ, cpow_neg, ← div_div, div_inv_eq_mul, div_mul_eq_mul_div, div_div,
mul_right_comm (2 : ℂ) (k : ℂ)]
norm_cast
/-- Reformulation of `sinZeta_two_mul_nat_add_one` using `Gammaℂ`. -/
theorem sinZeta_two_mul_nat_add_one' (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
sinZeta x (2 * k + 1) = (-1) ^ (k + 1) / (2 * k + 1) / Gammaℂ (2 * k + 1) *
((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rw [sinZeta_two_mul_nat_add_one hk hx]
congr 1
have : (2 * k + 1)! = (2 * k + 1) * Complex.Gamma (2 * k + 1) := by
rw [(by simp : Complex.Gamma (2 * k + 1) = Complex.Gamma (↑(2 * k) + 1)),
Complex.Gamma_nat_eq_factorial, ← Nat.cast_ofNat (R := ℂ), ← Nat.cast_mul,
← Nat.cast_add_one, ← Nat.cast_mul, ← Nat.factorial_succ]
simp_rw [this, Gammaℂ, cpow_neg, ← div_div, div_inv_eq_mul, div_mul_eq_mul_div, div_div]
rw [(by simp : 2 * (k : ℂ) + 1 = ↑(2 * k + 1)), cpow_natCast]
ring
theorem hurwitzZetaEven_one_sub_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZetaEven x (1 - 2 * k) =
-1 / (2 * k) * ((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
have h1 (n : ℕ) : (2 * k : ℂ) ≠ -n := by
rw [← Int.cast_ofNat, ← Int.cast_natCast, ← Int.cast_mul, ← Int.cast_natCast n, ← Int.cast_neg,
Ne, Int.cast_inj, ← Ne]
refine ne_of_gt ((neg_nonpos_of_nonneg n.cast_nonneg).trans_lt (mul_pos two_pos ?_))
exact Nat.cast_pos.mpr (Nat.pos_of_ne_zero hk)
have h2 : (2 * k : ℂ) ≠ 1 := by norm_cast; simp
have h3 : Gammaℂ (2 * k) ≠ 0 := by
refine mul_ne_zero (mul_ne_zero two_ne_zero ?_) (Gamma_ne_zero h1)
simp [pi_ne_zero]
rw [hurwitzZetaEven_one_sub _ h1 (Or.inr h2), ← Gammaℂ, cosZeta_two_mul_nat' hk hx, ← mul_assoc,
← mul_div_assoc, mul_assoc, mul_div_cancel_left₀ _ h3, ← mul_div_assoc]
congr 2
rw [mul_div_assoc, mul_div_cancel_left₀ _ two_ne_zero, ← ofReal_natCast, ← ofReal_mul,
← ofReal_cos, mul_comm π, ← sub_zero (k * π), cos_nat_mul_pi_sub, Real.cos_zero, mul_one,
ofReal_pow, ofReal_neg, ofReal_one, pow_succ, mul_neg_one, mul_neg, ← mul_pow, neg_one_mul,
neg_neg, one_pow]
theorem hurwitzZetaOdd_neg_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZetaOdd x (-(2 * k)) =
-1 / (2 * k + 1) * ((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
have h1 (n : ℕ) : (2 * k + 1 : ℂ) ≠ -n := by
rw [← Int.cast_ofNat, ← Int.cast_natCast, ← Int.cast_mul, ← Int.cast_natCast n, ← Int.cast_neg,
← Int.cast_one, ← Int.cast_add, Ne, Int.cast_inj, ← Ne]
refine ne_of_gt ((neg_nonpos_of_nonneg n.cast_nonneg).trans_lt ?_)
positivity
have h3 : Gammaℂ (2 * k + 1) ≠ 0 := by
refine mul_ne_zero (mul_ne_zero two_ne_zero ?_) (Gamma_ne_zero h1)
simp [pi_ne_zero]
rw [(by simp : -(2 * k : ℂ) = 1 - (2 * k + 1)),
hurwitzZetaOdd_one_sub _ h1, ← Gammaℂ, sinZeta_two_mul_nat_add_one' hk hx, ← mul_assoc,
← mul_div_assoc, mul_assoc, mul_div_cancel_left₀ _ h3, ← mul_div_assoc]
congr 2
rw [mul_div_assoc, add_div, mul_div_cancel_left₀ _ two_ne_zero, ← ofReal_natCast,
← ofReal_one, ← ofReal_ofNat, ← ofReal_div, ← ofReal_add, ← ofReal_mul,
← ofReal_sin, mul_comm π, add_mul, mul_comm (1 / 2), mul_one_div, Real.sin_add_pi_div_two,
← sub_zero (k * π), cos_nat_mul_pi_sub, Real.cos_zero, mul_one,
ofReal_pow, ofReal_neg, ofReal_one, pow_succ, mul_neg_one, mul_neg, ← mul_pow, neg_one_mul,
neg_neg, one_pow]
-- private because it is superseded by `hurwitzZeta_neg_nat` below
private lemma hurwitzZeta_one_sub_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZeta x (1 - 2 * k) =
-1 / (2 * k) * ((Polynomial.bernoulli (2 * k)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
suffices hurwitzZetaOdd x (1 - 2 * k) = 0 by
rw [hurwitzZeta, this, add_zero, hurwitzZetaEven_one_sub_two_mul_nat hk hx]
obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hk
rw [Nat.cast_succ, show (1 : ℂ) - 2 * (k + 1) = -2 * k - 1 by ring,
hurwitzZetaOdd_neg_two_mul_nat_sub_one]
-- private because it is superseded by `hurwitzZeta_neg_nat` below
private lemma hurwitzZeta_neg_two_mul_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZeta x (-(2 * k)) = -1 / (2 * k + 1) *
((Polynomial.bernoulli (2 * k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
suffices hurwitzZetaEven x (-(2 * k)) = 0 by
rw [hurwitzZeta, this, zero_add, hurwitzZetaOdd_neg_two_mul_nat hk hx]
obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hk
simpa using hurwitzZetaEven_neg_two_mul_nat_add_one x k
/-- Values of Hurwitz zeta functions at (strictly) negative integers.
TODO: This formula is also correct for `k = 0`; but our current proof does not work in this
case. -/
theorem hurwitzZeta_neg_nat (hk : k ≠ 0) (hx : x ∈ Icc (0 : ℝ) 1) :
hurwitzZeta x (-k) =
-1 / (k + 1) * ((Polynomial.bernoulli (k + 1)).map (algebraMap ℚ ℂ)).eval (x : ℂ) := by
rcases Nat.even_or_odd' k with ⟨n, (rfl | rfl)⟩
· exact_mod_cast hurwitzZeta_neg_two_mul_nat (by omega : n ≠ 0) hx
· exact_mod_cast hurwitzZeta_one_sub_two_mul_nat (by omega : n + 1 ≠ 0) hx
end HurwitzZeta
open HurwitzZeta
/-- Explicit formula for `ζ (2 * k)`, for `k ∈ ℕ` with `k ≠ 0`, in terms of the Bernoulli number
`bernoulli (2 * k)`.
Compare `hasSum_zeta_nat` for a version formulated in terms of a sum over `1 / n ^ (2 * k)`, and
`riemannZeta_neg_nat_eq_bernoulli` for values at negative integers (equivalent to the above via
the functional equation). -/
theorem riemannZeta_two_mul_nat {k : ℕ} (hk : k ≠ 0) :
riemannZeta (2 * k) = (-1) ^ (k + 1) * (2 : ℂ) ^ (2 * k - 1)
* (π : ℂ) ^ (2 * k) * bernoulli (2 * k) / (2 * k)! := by
convert congr_arg ((↑) : ℝ → ℂ) (hasSum_zeta_nat hk).tsum_eq
· rw [← Nat.cast_two, ← Nat.cast_mul, zeta_nat_eq_tsum_of_gt_one (by omega)]
simp [push_cast]
· norm_cast
theorem riemannZeta_two : riemannZeta 2 = (π : ℂ) ^ 2 / 6 := by
convert congr_arg ((↑) : ℝ → ℂ) hasSum_zeta_two.tsum_eq
· rw [← Nat.cast_two, zeta_nat_eq_tsum_of_gt_one one_lt_two]
simp [push_cast]
· norm_cast
theorem riemannZeta_four : riemannZeta 4 = π ^ 4 / 90 := by
convert congr_arg ((↑) : ℝ → ℂ) hasSum_zeta_four.tsum_eq
· rw [← Nat.cast_one, show (4 : ℂ) = (4 : ℕ) by simp,
zeta_nat_eq_tsum_of_gt_one (by simp : 1 < 4)]
simp only [push_cast]
· norm_cast
/-- Value of Riemann zeta at `-ℕ` in terms of `bernoulli'`. -/
theorem riemannZeta_neg_nat_eq_bernoulli' (k : ℕ) :
riemannZeta (-k) = -bernoulli' (k + 1) / (k + 1) := by
rcases eq_or_ne k 0 with rfl | hk
· rw [Nat.cast_zero, neg_zero, riemannZeta_zero, zero_add, zero_add, div_one,
bernoulli'_one, Rat.cast_div, Rat.cast_one, Rat.cast_ofNat, neg_div]
· rw [← hurwitzZeta_zero, ← QuotientAddGroup.mk_zero, hurwitzZeta_neg_nat hk
(left_mem_Icc.mpr zero_le_one), ofReal_zero, Polynomial.eval_zero_map,
Polynomial.bernoulli_eval_zero, Algebra.algebraMap_eq_smul_one, Rat.smul_one_eq_cast,
div_mul_eq_mul_div, neg_one_mul, bernoulli_eq_bernoulli'_of_ne_one (by simp [hk])]
/-- Value of Riemann zeta at `-ℕ` in terms of `bernoulli`. -/
theorem riemannZeta_neg_nat_eq_bernoulli (k : ℕ) :
riemannZeta (-k) = (-1 : ℂ) ^ k * bernoulli (k + 1) / (k + 1) := by
rw [riemannZeta_neg_nat_eq_bernoulli', bernoulli, Rat.cast_mul, Rat.cast_pow, Rat.cast_neg,
Rat.cast_one, ← neg_one_mul, ← mul_assoc, pow_succ, ← mul_assoc, ← mul_pow, neg_one_mul (-1),
neg_neg, one_pow, one_mul]
|
Curry.lean
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.Alternating.Basic
import Mathlib.LinearAlgebra.Multilinear.Curry
/-!
# Currying alternating forms
In this file we define `AlternatingMap.curryLeft`
which interprets an alternating map in `n + 1` variables
as a linear map in the 0th variable taking values in the alternating maps in `n` variables.
-/
variable {R : Type*} {M M₂ N N₂ : Type*} [CommSemiring R] [AddCommMonoid M]
[AddCommMonoid M₂] [AddCommMonoid N] [AddCommMonoid N₂] [Module R M] [Module R M₂]
[Module R N] [Module R N₂] {n : ℕ}
namespace AlternatingMap
/-- Given an alternating map `f` in `n+1` variables, split the first variable to obtain
a linear map into alternating maps in `n` variables, given by `x ↦ (m ↦ f (Matrix.vecCons x m))`.
It can be thought of as a map $Hom(\bigwedge^{n+1} M, N) \to Hom(M, Hom(\bigwedge^n M, N))$.
This is `MultilinearMap.curryLeft` for `AlternatingMap`. See also
`AlternatingMap.curryLeftLinearMap`. -/
@[simps apply_toMultilinearMap]
def curryLeft (f : M [⋀^Fin n.succ]→ₗ[R] N) : M →ₗ[R] M [⋀^Fin n]→ₗ[R] N where
toFun m :=
{ f.toMultilinearMap.curryLeft m with
map_eq_zero_of_eq' v i j hv hij :=
f.map_eq_zero_of_eq _ (by simpa) ((Fin.succ_injective _).ne hij) }
map_add' _ _ := ext fun _ => f.map_vecCons_add _ _ _
map_smul' _ _ := ext fun _ => f.map_vecCons_smul _ _ _
@[simp]
theorem curryLeft_apply_apply (f : M [⋀^Fin n.succ]→ₗ[R] N) (x : M) (v : Fin n → M) :
curryLeft f x v = f (Matrix.vecCons x v) :=
rfl
@[simp]
theorem curryLeft_zero : curryLeft (0 : M [⋀^Fin n.succ]→ₗ[R] N) = 0 :=
rfl
@[simp]
theorem curryLeft_add (f g : M [⋀^Fin n.succ]→ₗ[R] N) :
curryLeft (f + g) = curryLeft f + curryLeft g :=
rfl
@[simp]
theorem curryLeft_smul (r : R) (f : M [⋀^Fin n.succ]→ₗ[R] N) :
curryLeft (r • f) = r • curryLeft f :=
rfl
/-- `AlternatingMap.curryLeft` as a `LinearMap`. This is a separate definition as dot notation
does not work for this version. -/
@[simps]
def curryLeftLinearMap :
(M [⋀^Fin n.succ]→ₗ[R] N) →ₗ[R] M →ₗ[R] M [⋀^Fin n]→ₗ[R] N where
toFun f := f.curryLeft
map_add' := curryLeft_add
map_smul' := curryLeft_smul
/-- Currying with the same element twice gives the zero map. -/
@[simp]
theorem curryLeft_same (f : M [⋀^Fin n.succ.succ]→ₗ[R] N) (m : M) :
(f.curryLeft m).curryLeft m = 0 :=
ext fun _ => f.map_eq_zero_of_eq _ (by simp) Fin.zero_ne_one
@[simp]
theorem curryLeft_compAlternatingMap (g : N →ₗ[R] N₂)
(f : M [⋀^Fin n.succ]→ₗ[R] N) (m : M) :
(g.compAlternatingMap f).curryLeft m = g.compAlternatingMap (f.curryLeft m) :=
rfl
@[simp]
theorem curryLeft_compLinearMap (g : M₂ →ₗ[R] M) (f : M [⋀^Fin n.succ]→ₗ[R] N) (m : M₂) :
(f.compLinearMap g).curryLeft m = (f.curryLeft (g m)).compLinearMap g :=
ext fun v ↦ congr_arg f <| funext fun i ↦ by cases i using Fin.cases <;> simp
end AlternatingMap
|
ZModChar.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.Data.Int.Range
import Mathlib.Data.ZMod.Basic
import Mathlib.NumberTheory.MulChar.Basic
/-!
# Quadratic characters on ℤ/nℤ
This file defines some quadratic characters on the rings ℤ/4ℤ and ℤ/8ℤ.
We set them up to be of type `MulChar (ZMod n) ℤ`, where `n` is `4` or `8`.
## Tags
quadratic character, zmod
-/
/-!
### Quadratic characters mod 4 and 8
We define the primitive quadratic characters `χ₄`on `ZMod 4`
and `χ₈`, `χ₈'` on `ZMod 8`.
-/
namespace ZMod
section QuadCharModP
/-- Define the nontrivial quadratic character on `ZMod 4`, `χ₄`.
It corresponds to the extension `ℚ(√-1)/ℚ`. -/
@[simps]
def χ₄ : MulChar (ZMod 4) ℤ where
toFun a :=
match a with
| 0 | 2 => 0
| 1 => 1
| 3 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₄` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₄ : χ₄.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- The value of `χ₄ n`, for `n : ℕ`, depends only on `n % 4`. -/
theorem χ₄_nat_mod_four (n : ℕ) : χ₄ n = χ₄ (n % 4 : ℕ) := by
rw [← ZMod.natCast_mod n 4]
/-- The value of `χ₄ n`, for `n : ℤ`, depends only on `n % 4`. -/
theorem χ₄_int_mod_four (n : ℤ) : χ₄ n = χ₄ (n % 4 : ℤ) := by
rw [← ZMod.intCast_mod n 4, Nat.cast_ofNat]
/-- An explicit description of `χ₄` on integers / naturals -/
theorem χ₄_int_eq_if_mod_four (n : ℤ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 := by
have help : ∀ m : ℤ, 0 ≤ m → m < 4 → χ₄ m = if m % 2 = 0 then 0 else if m = 1 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by omega : (2 : ℤ) ∣ 4), ← ZMod.intCast_mod n 4]
exact help (n % 4) (Int.emod_nonneg n (by omega)) (Int.emod_lt_abs n (by omega))
theorem χ₄_nat_eq_if_mod_four (n : ℕ) :
χ₄ n = if n % 2 = 0 then 0 else if n % 4 = 1 then 1 else -1 :=
mod_cast χ₄_int_eq_if_mod_four n
/-- Alternative description of `χ₄ n` for odd `n : ℕ` in terms of powers of `-1` -/
theorem χ₄_eq_neg_one_pow {n : ℕ} (hn : n % 2 = 1) : χ₄ n = (-1) ^ (n / 2) := by
rw [χ₄_nat_eq_if_mod_four]
simp only [hn, Nat.one_ne_zero, if_false]
nth_rewrite 3 [← Nat.div_add_mod n 4]
nth_rewrite 3 [show 4 = 2 * 2 by omega]
rw [mul_assoc, add_comm, Nat.add_mul_div_left _ _ zero_lt_two, pow_add, pow_mul,
neg_one_sq, one_pow, mul_one]
have help : ∀ m : ℕ, m < 4 → m % 2 = 1 → ite (m = 1) (1 : ℤ) (-1) = (-1) ^ (m / 2) := by decide
exact help _ (Nat.mod_lt n (by omega)) <| (Nat.mod_mod_of_dvd n (by omega : 2 ∣ 4)).trans hn
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_nat_one_mod_four {n : ℕ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
theorem χ₄_nat_three_mod_four {n : ℕ} (hn : n % 4 = 3) : χ₄ n = -1 := by
rw [χ₄_nat_mod_four, hn]
rfl
/-- If `n % 4 = 1`, then `χ₄ n = 1`. -/
theorem χ₄_int_one_mod_four {n : ℤ} (hn : n % 4 = 1) : χ₄ n = 1 := by
rw [χ₄_int_mod_four, hn]
rfl
/-- If `n % 4 = 3`, then `χ₄ n = -1`. -/
theorem χ₄_int_three_mod_four {n : ℤ} (hn : n % 4 = 3) : χ₄ n = -1 := by
rw [χ₄_int_mod_four, hn]
rfl
/-- If `n % 4 = 1`, then `(-1)^(n/2) = 1`. -/
theorem neg_one_pow_div_two_of_one_mod_four {n : ℕ} (hn : n % 4 = 1) : (-1 : ℤ) ^ (n / 2) = 1 :=
χ₄_eq_neg_one_pow (Nat.odd_of_mod_four_eq_one hn) ▸ χ₄_nat_one_mod_four hn
/-- If `n % 4 = 3`, then `(-1)^(n/2) = -1`. -/
theorem neg_one_pow_div_two_of_three_mod_four {n : ℕ} (hn : n % 4 = 3) : (-1 : ℤ) ^ (n / 2) = -1 :=
χ₄_eq_neg_one_pow (Nat.odd_of_mod_four_eq_three hn) ▸ χ₄_nat_three_mod_four hn
/-- Define the first primitive quadratic character on `ZMod 8`, `χ₈`.
It corresponds to the extension `ℚ(√2)/ℚ`. -/
@[simps]
def χ₈ : MulChar (ZMod 8) ℤ where
toFun a :=
match a with
| 0 | 2 | 4 | 6 => 0
| 1 | 7 => 1
| 3 | 5 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₈` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₈ : χ₈.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- The value of `χ₈ n`, for `n : ℕ`, depends only on `n % 8`. -/
theorem χ₈_nat_mod_eight (n : ℕ) : χ₈ n = χ₈ (n % 8 : ℕ) := by
rw [← ZMod.natCast_mod n 8]
/-- The value of `χ₈ n`, for `n : ℤ`, depends only on `n % 8`. -/
theorem χ₈_int_mod_eight (n : ℤ) : χ₈ n = χ₈ (n % 8 : ℤ) := by
rw [← ZMod.intCast_mod n 8, Nat.cast_ofNat]
/-- An explicit description of `χ₈` on integers / naturals -/
theorem χ₈_int_eq_if_mod_eight (n : ℤ) :
χ₈ n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 7 then 1 else -1 := by
have help :
∀ m : ℤ, 0 ≤ m → m < 8 → χ₈ m = if m % 2 = 0 then 0 else if m = 1 ∨ m = 7 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by omega : (2 : ℤ) ∣ 8), ← ZMod.intCast_mod n 8]
exact help (n % 8) (Int.emod_nonneg n (by omega)) (Int.emod_lt_abs n (by omega))
theorem χ₈_nat_eq_if_mod_eight (n : ℕ) :
χ₈ n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 7 then 1 else -1 :=
mod_cast χ₈_int_eq_if_mod_eight n
/-- Define the second primitive quadratic character on `ZMod 8`, `χ₈'`.
It corresponds to the extension `ℚ(√-2)/ℚ`. -/
@[simps]
def χ₈' : MulChar (ZMod 8) ℤ where
toFun a :=
match a with
| 0 | 2 | 4 | 6 => 0
| 1 | 3 => 1
| 5 | 7 => -1
map_one' := rfl
map_mul' := by decide
map_nonunit' := by decide
/-- `χ₈'` takes values in `{0, 1, -1}` -/
theorem isQuadratic_χ₈' : χ₈'.IsQuadratic := by
unfold MulChar.IsQuadratic
decide
/-- An explicit description of `χ₈'` on integers / naturals -/
theorem χ₈'_int_eq_if_mod_eight (n : ℤ) :
χ₈' n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 3 then 1 else -1 := by
have help :
∀ m : ℤ, 0 ≤ m → m < 8 → χ₈' m = if m % 2 = 0 then 0 else if m = 1 ∨ m = 3 then 1 else -1 := by
decide
rw [← Int.emod_emod_of_dvd n (by omega : (2 : ℤ) ∣ 8), ← ZMod.intCast_mod n 8]
exact help (n % 8) (Int.emod_nonneg n (by omega)) (Int.emod_lt_abs n (by omega))
theorem χ₈'_nat_eq_if_mod_eight (n : ℕ) :
χ₈' n = if n % 2 = 0 then 0 else if n % 8 = 1 ∨ n % 8 = 3 then 1 else -1 :=
mod_cast χ₈'_int_eq_if_mod_eight n
/-- The relation between `χ₄`, `χ₈` and `χ₈'` -/
theorem χ₈'_eq_χ₄_mul_χ₈ : ∀ a : ZMod 8, χ₈' a = χ₄ (cast a) * χ₈ a := by
decide
theorem χ₈'_int_eq_χ₄_mul_χ₈ (a : ℤ) : χ₈' a = χ₄ a * χ₈ a := by
rw [← @cast_intCast 8 (ZMod 4) _ 4 _ (by omega) a]
exact χ₈'_eq_χ₄_mul_χ₈ a
end QuadCharModP
end ZMod
|
SimpIntro.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 Lean.Elab.Tactic.Simp
import Mathlib.Init
/-! # `simp_intro` tactic -/
namespace Mathlib.Tactic
open Lean Meta Elab Tactic
/--
Main loop of the `simp_intro` tactic.
* `g`: the original goal
* `ctx`: the simp context, which is extended with local variables as we enter the binders
* `discharge?`: the discharger
* `more`: if true, we will keep introducing binders as long as we can
* `ids`: the list of binder identifiers
-/
partial def simpIntroCore (g : MVarId) (ctx : Simp.Context) (simprocs : Simp.SimprocsArray := #[])
(discharge? : Option Simp.Discharge) (more : Bool) (ids : List (TSyntax ``binderIdent)) :
TermElabM (Option MVarId) := do
let done := return (← simpTargetCore g ctx simprocs discharge?).1
let (transp, var, ids') ← match ids with
| [] => if more then pure (.reducible, mkHole (← getRef), []) else return ← done
| v::ids => pure (.default, v.raw[0], ids)
let t ← withTransparency transp g.getType'
let n := if var.isIdent then var.getId else `_
let withFVar := fun (fvar, g) ↦ g.withContext do
Term.addLocalVarInfo var (mkFVar fvar)
let ctx : Simp.Context ←
if (← Meta.isProp <| ← fvar.getType) then
let simpTheorems ← ctx.simpTheorems.addTheorem (.fvar fvar) (.fvar fvar)
pure <| ctx.setSimpTheorems simpTheorems
else
pure ctx
simpIntroCore g ctx simprocs discharge? more ids'
match t with
| .letE .. => withFVar (← g.intro n)
| .forallE (body := body) .. =>
let (fvar, g) ← g.intro n
if body.hasLooseBVars then withFVar (fvar, g) else
match (← simpLocalDecl g fvar ctx simprocs discharge?).1 with
| none =>
g.withContext <| Term.addLocalVarInfo var (mkFVar fvar)
return none
| some g' => withFVar g'
| _ =>
if more && ids.isEmpty then done else
throwErrorAt var "simp_intro failed to introduce {var}\n{g}"
open Parser.Tactic
/--
The `simp_intro` tactic is a combination of `simp` and `intro`: it will simplify the types of
variables as it introduces them and uses the new variables to simplify later arguments
and the goal.
* `simp_intro x y z` introduces variables named `x y z`
* `simp_intro x y z ..` introduces variables named `x y z` and then keeps introducing `_` binders
* `simp_intro (config := cfg) (discharger := tac) x y .. only [h₁, h₂]`:
`simp_intro` takes the same options as `simp` (see `simp`)
```
example : x + 0 = y → x = z := by
simp_intro h
-- h: x = y ⊢ y = z
sorry
```
-/
elab "simp_intro" cfg:optConfig disch:(discharger)?
ids:(ppSpace colGt binderIdent)* more:" .."? only:(&" only")? args:(simpArgs)? : tactic => do
let args := args.map fun args ↦ ⟨args.raw[1].getArgs⟩
let stx ← `(tactic| simp $cfg:optConfig $(disch)? $[only%$only]? $[[$args,*]]?)
let { ctx, simprocs, dischargeWrapper, .. } ←
withMainContext <| mkSimpContext stx (eraseLocal := false)
dischargeWrapper.with fun discharge? ↦ do
let g ← getMainGoal
g.checkNotAssigned `simp_intro
g.withContext do
let g? ← simpIntroCore g ctx (simprocs := simprocs) discharge? more.isSome ids.toList
replaceMainGoal <| if let some g := g? then [g] else []
end Mathlib.Tactic
|
test_order_conv.v
|
From mathcomp Require Import all_boot all_order.
Import Order.Theory.
Section dual_of_dual.
Context (disp : Order.disp_t).
Let eq_dual_dual_preorderType (T : preorderType disp) :
Order.Preorder.on T = Order.Preorder.on T^d^d := erefl.
Let eq_dual_dual_porderType (T : porderType disp) :
Order.POrder.on T = Order.POrder.on T^d^d := erefl.
Let eq_dual_dual_bPOrderType (T : bPOrderType disp) :
Order.BPOrder.on T = Order.BPOrder.on T^d^d := erefl.
Let eq_dual_dual_tPOrderType (T : tPOrderType disp) :
Order.TPOrder.on T = Order.TPOrder.on T^d^d := erefl.
Let eq_dual_dual_tbPOrderType (T : tbPOrderType disp) :
Order.TBPOrder.on T = Order.TBPOrder.on T^d^d := erefl.
Let eq_dual_dual_meetSemilatticeType (T : meetSemilatticeType disp) :
Order.MeetSemilattice.on T = Order.MeetSemilattice.on T^d^d := erefl.
Let eq_dual_dual_bMeetSemilatticeType (T : bMeetSemilatticeType disp) :
Order.BMeetSemilattice.on T = Order.BMeetSemilattice.on T^d^d := erefl.
Let eq_dual_dual_tMeetSemilatticeType (T : tMeetSemilatticeType disp) :
Order.TMeetSemilattice.on T = Order.TMeetSemilattice.on T^d^d := erefl.
Let eq_dual_dual_tbMeetSemilatticeType (T : tbMeetSemilatticeType disp) :
Order.TBMeetSemilattice.on T = Order.TBMeetSemilattice.on T^d^d := erefl.
Let eq_dual_dual_joinSemilatticeType (T : joinSemilatticeType disp) :
Order.JoinSemilattice.on T = Order.JoinSemilattice.on T^d^d := erefl.
Let eq_dual_dual_bJoinSemilatticeType (T : bJoinSemilatticeType disp) :
Order.BJoinSemilattice.on T = Order.BJoinSemilattice.on T^d^d := erefl.
Let eq_dual_dual_tJoinSemilatticeType (T : tJoinSemilatticeType disp) :
Order.TJoinSemilattice.on T = Order.TJoinSemilattice.on T^d^d := erefl.
Let eq_dual_dual_tbJoinSemilatticeType (T : tbJoinSemilatticeType disp) :
Order.TBJoinSemilattice.on T = Order.TBJoinSemilattice.on T^d^d := erefl.
Let eq_dual_dual_latticeType (T : latticeType disp) :
Order.Lattice.on T = Order.Lattice.on T^d^d := erefl.
Let eq_dual_dual_bLatticeType (T : bLatticeType disp) :
Order.BLattice.on T = Order.BLattice.on T^d^d := erefl.
Let eq_dual_dual_tLatticeType (T : tLatticeType disp) :
Order.TLattice.on T = Order.TLattice.on T^d^d := erefl.
Let eq_dual_dual_tbLatticeType (T : tbLatticeType disp) :
Order.TBLattice.on T = Order.TBLattice.on T^d^d := erefl.
Let eq_dual_dual_distrLatticeType (T : distrLatticeType disp) :
Order.DistrLattice.on T = Order.DistrLattice.on T^d^d := erefl.
Let eq_dual_dual_bDistrLatticeType (T : bDistrLatticeType disp) :
Order.BDistrLattice.on T = Order.BDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_tDistrLatticeType (T : tDistrLatticeType disp) :
Order.TDistrLattice.on T = Order.TDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_tbDistrLatticeType (T : tbDistrLatticeType disp) :
Order.TBDistrLattice.on T = Order.TBDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_cDistrLatticeType (T : cDistrLatticeType disp) :
Order.CDistrLattice.on T = Order.CDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_cbDistrLatticeType (T : cbDistrLatticeType disp) :
Order.CBDistrLattice.on T = Order.CBDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_ctDistrLatticeType (T : ctDistrLatticeType disp) :
Order.CTDistrLattice.on T = Order.CTDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_ctbDistrLatticeType (T : ctbDistrLatticeType disp) :
Order.CTBDistrLattice.on T = Order.CTBDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_orderType (T : orderType disp) :
Order.Total.on T = Order.Total.on T^d^d := erefl.
Let eq_dual_dual_bOrderType (T : bOrderType disp) :
Order.BTotal.on T = Order.BTotal.on T^d^d := erefl.
Let eq_dual_dual_tOrderType (T : tOrderType disp) :
Order.TTotal.on T = Order.TTotal.on T^d^d := erefl.
Let eq_dual_dual_tbOrderType (T : tbOrderType disp) :
Order.TBTotal.on T = Order.TBTotal.on T^d^d := erefl.
Let eq_dual_dual_finPOrderType (T : finPOrderType disp) :
Order.FinPOrder.on T = Order.FinPOrder.on T^d^d := erefl.
Let eq_dual_dual_finBPOrderType (T : finBPOrderType disp) :
Order.FinBPOrder.on T = Order.FinBPOrder.on T^d^d := erefl.
Let eq_dual_dual_finTPOrderType (T : finTPOrderType disp) :
Order.FinTPOrder.on T = Order.FinTPOrder.on T^d^d := erefl.
Let eq_dual_dual_finTBPOrderType (T : finTBPOrderType disp) :
Order.FinTBPOrder.on T = Order.FinTBPOrder.on T^d^d := erefl.
Let eq_dual_dual_finMeetSemilatticeType (T : finMeetSemilatticeType disp) :
Order.FinMeetSemilattice.on T = Order.FinMeetSemilattice.on T^d^d := erefl.
Let eq_dual_dual_finBMeetSemilatticeType (T : finBMeetSemilatticeType disp) :
Order.FinBMeetSemilattice.on T = Order.FinBMeetSemilattice.on T^d^d := erefl.
Let eq_dual_dual_finJoinSemilatticeType (T : finJoinSemilatticeType disp) :
Order.FinJoinSemilattice.on T = Order.FinJoinSemilattice.on T^d^d := erefl.
Let eq_dual_dual_finTJoinSemilatticeType (T : finTJoinSemilatticeType disp) :
Order.FinTJoinSemilattice.on T = Order.FinTJoinSemilattice.on T^d^d := erefl.
Let eq_dual_dual_FinLatticeType (T : finLatticeType disp) :
Order.FinLattice.on T = Order.FinLattice.on T^d^d := erefl.
Let eq_dual_dual_FinTBLatticeType (T : finTBLatticeType disp) :
Order.FinTBLattice.on T = Order.FinTBLattice.on T^d^d := erefl.
Let eq_dual_dual_FinDistrLatticeType (T : finDistrLatticeType disp) :
Order.FinDistrLattice.on T = Order.FinDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_FinTBDistrLatticeType (T : finTBDistrLatticeType disp) :
Order.FinTBDistrLattice.on T = Order.FinTBDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_finCDistrLatticeType (T : finCDistrLatticeType disp) :
Order.FinCDistrLattice.on T = Order.FinCDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_finCTBDistrLatticeType (T : finCTBDistrLatticeType disp) :
Order.FinCTBDistrLattice.on T = Order.FinCTBDistrLattice.on T^d^d := erefl.
Let eq_dual_dual_finOrderType (T : finOrderType disp) :
Order.FinTotal.on T = Order.FinTotal.on T^d^d := erefl.
Let eq_dual_dual_finTBOrderType (T : finTBOrderType disp) :
Order.FinTBTotal.on T = Order.FinTBTotal.on T^d^d := erefl.
End dual_of_dual.
Section dual_of_prod.
Context (disp1 disp2 : Order.disp_t).
Import DefaultProdOrder.
Let eq_dual_prod_porderType (T1 : porderType disp1) (T2 : porderType disp2) :
Order.POrder.on (T1 * T2)^d = Order.POrder.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_bPreorderType (T1 : bPreorderType disp1) (T2 : bPreorderType disp2) :
Order.BPreorder.on (T1 * T2)^d = Order.BPreorder.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tPreorderType (T1 : tPreorderType disp1) (T2 : tPreorderType disp2) :
Order.TPreorder.on (T1 * T2)^d = Order.TPreorder.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tbPreorderType
(T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) :
Order.TBPreorder.on (T1 * T2)^d = Order.TBPreorder.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_bPOrderType (T1 : bPOrderType disp1) (T2 : bPOrderType disp2) :
Order.BPOrder.on (T1 * T2)^d = Order.BPOrder.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tPOrderType (T1 : tPOrderType disp1) (T2 : tPOrderType disp2) :
Order.TPOrder.on (T1 * T2)^d = Order.TPOrder.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tbPOrderType
(T1 : tbPOrderType disp1) (T2 : tbPOrderType disp2) :
Order.TBPOrder.on (T1 * T2)^d = Order.TBPOrder.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_meetSemilatticeType
(T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2) :
Order.MeetSemilattice.on (T1 * T2)^d
= Order.MeetSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_bMeetSemilatticeType
(T1 : bMeetSemilatticeType disp1) (T2 : bMeetSemilatticeType disp2) :
Order.BMeetSemilattice.on (T1 * T2)^d
= Order.BMeetSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tMeetSemilatticeType
(T1 : tMeetSemilatticeType disp1) (T2 : tMeetSemilatticeType disp2) :
Order.TMeetSemilattice.on (T1 * T2)^d
= Order.TMeetSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tbMeetSemilatticeType
(T1 : tbMeetSemilatticeType disp1) (T2 : tbMeetSemilatticeType disp2) :
Order.TBMeetSemilattice.on (T1 * T2)^d
= Order.TBMeetSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_joinSemilatticeType
(T1 : joinSemilatticeType disp1) (T2 : joinSemilatticeType disp2) :
Order.JoinSemilattice.on (T1 * T2)^d
= Order.JoinSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_bJoinSemilatticeType
(T1 : bJoinSemilatticeType disp1) (T2 : bJoinSemilatticeType disp2) :
Order.BJoinSemilattice.on (T1 * T2)^d
= Order.BJoinSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tJoinSemilatticeType
(T1 : tJoinSemilatticeType disp1) (T2 : tJoinSemilatticeType disp2) :
Order.TJoinSemilattice.on (T1 * T2)^d
= Order.TJoinSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tbJoinSemilatticeType
(T1 : tbJoinSemilatticeType disp1) (T2 : tbJoinSemilatticeType disp2) :
Order.TBJoinSemilattice.on (T1 * T2)^d
= Order.TBJoinSemilattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_latticeType (T1 : latticeType disp1) (T2 : latticeType disp2) :
Order.Lattice.on (T1 * T2)^d = Order.Lattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_bLatticeType
(T1 : bLatticeType disp1) (T2 : bLatticeType disp2) :
Order.BLattice.on (T1 * T2)^d = Order.BLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tLatticeType
(T1 : tLatticeType disp1) (T2 : tLatticeType disp2) :
Order.TLattice.on (T1 * T2)^d = Order.TLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tbLatticeType
(T1 : tbLatticeType disp1) (T2 : tbLatticeType disp2) :
Order.TBLattice.on (T1 * T2)^d
= Order.TBLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_distrLatticeType
(T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2) :
Order.DistrLattice.on (T1 * T2)^d
= Order.DistrLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_bDistrLatticeType
(T1 : bDistrLatticeType disp1) (T2 : bDistrLatticeType disp2) :
Order.BDistrLattice.on (T1 * T2)^d
= Order.BDistrLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tDistrLatticeType
(T1 : tDistrLatticeType disp1) (T2 : tDistrLatticeType disp2) :
Order.TDistrLattice.on (T1 * T2)^d
= Order.TDistrLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_tbDistrLatticeType
(T1 : tbDistrLatticeType disp1) (T2 : tbDistrLatticeType disp2) :
Order.TBDistrLattice.on (T1 * T2)^d
= Order.TBDistrLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_cDistrLatticeType
(T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2) :
Order.CDistrLattice.on (T1 * T2)^d
= Order.CDistrLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_cbDistrLatticeType
(T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2) :
Order.CBDistrLattice.on (T1 * T2)^d
= Order.CBDistrLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_ctDistrLatticeType
(T1 : ctDistrLatticeType disp1) (T2 : ctDistrLatticeType disp2) :
Order.CTDistrLattice.on (T1 * T2)^d
= Order.CTDistrLattice.on (T1^d * T2^d)%type := erefl.
Let eq_dual_prod_ctbDistrLatticeType
(T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2) :
Order.CTBDistrLattice.on (T1 * T2)^d
= Order.CTBDistrLattice.on (T1^d * T2^d)%type := erefl.
End dual_of_prod.
|
Language.lean
|
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson, Martin Dvorak
-/
import Mathlib.Algebra.Order.Kleene
import Mathlib.Algebra.Ring.Hom.Defs
import Mathlib.Data.Set.Lattice
import Mathlib.Tactic.DeriveFintype
/-!
# Languages
This file contains the definition and operations on formal languages over an alphabet.
Note that "strings" are implemented as lists over the alphabet.
Union and concatenation define a [Kleene algebra](https://en.wikipedia.org/wiki/Kleene_algebra)
over the languages.
In addition to that, we define a reversal of a language and prove that it behaves well
with respect to other language operations.
## Notation
* `l + m`: union of languages `l` and `m`
* `l * m`: language of strings `x ++ y` such that `x ∈ l` and `y ∈ m`
* `l ^ n`: language of strings consisting of `n` members of `l` concatenated together
* `1`: language consisting of only the empty string.
This is because it is the unit of the `*` operator.
* `l∗`: Kleene's star – language of strings consisting of arbitrarily many
members of `l` concatenated together
(Note that this is the Unicode asterisk `∗`, and not the more common star `*`)
## Main definitions
* `Language α`: a set of strings over the alphabet `α`
* `l.map f`: transform a language `l` over `α` into a language over `β`
by translating through `f : α → β`
## Main theorems
* `Language.self_eq_mul_add_iff`: Arden's lemma – if a language `l` satisfies the equation
`l = m * l + n`, and `m` doesn't contain the empty string,
then `l` is the language `m∗ * n`
-/
open List Set Computability
universe v
variable {α β γ : Type*}
/-- A language is a set of strings over an alphabet. -/
def Language (α) :=
Set (List α)
namespace Language
instance : Membership (List α) (Language α) := ⟨Set.Mem⟩
instance : Singleton (List α) (Language α) := ⟨Set.singleton⟩
instance : Insert (List α) (Language α) := ⟨Set.insert⟩
instance instCompleteAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Language α) :=
Set.instCompleteAtomicBooleanAlgebra
variable {l m : Language α} {a b x : List α}
/-- Zero language has no elements. -/
instance : Zero (Language α) :=
⟨(∅ : Set _)⟩
/-- `1 : Language α` contains only one element `[]`. -/
instance : One (Language α) :=
⟨{[]}⟩
instance : Inhabited (Language α) := ⟨(∅ : Set _)⟩
/-- The sum of two languages is their union. -/
instance : Add (Language α) :=
⟨((· ∪ ·) : Set (List α) → Set (List α) → Set (List α))⟩
/-- The product of two languages `l` and `m` is the language made of the strings `x ++ y` where
`x ∈ l` and `y ∈ m`. -/
instance : Mul (Language α) :=
⟨image2 (· ++ ·)⟩
theorem zero_def : (0 : Language α) = (∅ : Set _) :=
rfl
theorem one_def : (1 : Language α) = ({[]} : Set (List α)) :=
rfl
theorem add_def (l m : Language α) : l + m = (l ∪ m : Set (List α)) :=
rfl
theorem mul_def (l m : Language α) : l * m = image2 (· ++ ·) l m :=
rfl
/-- The Kleene star of a language `L` is the set of all strings which can be written by
concatenating strings from `L`. -/
instance : KStar (Language α) := ⟨fun l ↦ {x | ∃ L : List (List α), x = L.flatten ∧ ∀ y ∈ L, y ∈ l}⟩
lemma kstar_def (l : Language α) : l∗ = {x | ∃ L : List (List α), x = L.flatten ∧ ∀ y ∈ L, y ∈ l} :=
rfl
@[ext]
theorem ext {l m : Language α} (h : ∀ (x : List α), x ∈ l ↔ x ∈ m) : l = m :=
Set.ext h
@[simp]
theorem notMem_zero (x : List α) : x ∉ (0 : Language α) :=
id
@[deprecated (since := "2025-05-23")] alias not_mem_zero := notMem_zero
@[simp]
theorem mem_one (x : List α) : x ∈ (1 : Language α) ↔ x = [] := by rfl
theorem nil_mem_one : [] ∈ (1 : Language α) :=
Set.mem_singleton _
theorem mem_add (l m : Language α) (x : List α) : x ∈ l + m ↔ x ∈ l ∨ x ∈ m :=
Iff.rfl
theorem mem_mul : x ∈ l * m ↔ ∃ a ∈ l, ∃ b ∈ m, a ++ b = x :=
mem_image2
theorem append_mem_mul : a ∈ l → b ∈ m → a ++ b ∈ l * m :=
mem_image2_of_mem
theorem mem_kstar : x ∈ l∗ ↔ ∃ L : List (List α), x = L.flatten ∧ ∀ y ∈ L, y ∈ l :=
Iff.rfl
theorem join_mem_kstar {L : List (List α)} (h : ∀ y ∈ L, y ∈ l) : L.flatten ∈ l∗ :=
⟨L, rfl, h⟩
theorem nil_mem_kstar (l : Language α) : [] ∈ l∗ :=
⟨[], rfl, fun _ h ↦ by contradiction⟩
instance instSemiring : Semiring (Language α) where
add := (· + ·)
add_assoc := union_assoc
zero := 0
zero_add := empty_union
add_zero := union_empty
add_comm := union_comm
mul := (· * ·)
mul_assoc _ _ _ := image2_assoc append_assoc
zero_mul _ := image2_empty_left
mul_zero _ := image2_empty_right
one := 1
one_mul l := by simp [mul_def, one_def]
mul_one l := by simp [mul_def, one_def]
natCast n := if n = 0 then 0 else 1
natCast_zero := rfl
natCast_succ n := by cases n <;> simp [add_def, zero_def]
left_distrib _ _ _ := image2_union_right
right_distrib _ _ _ := image2_union_left
nsmul := nsmulRec
@[simp]
theorem add_self (l : Language α) : l + l = l :=
sup_idem _
/-- Maps the alphabet of a language. -/
def map (f : α → β) : Language α →+* Language β where
toFun := image (List.map f)
map_zero' := image_empty _
map_one' := image_singleton
map_add' := image_union _
map_mul' _ _ := image_image2_distrib <| fun _ _ => map_append
@[simp]
theorem map_id (l : Language α) : map id l = l := by simp [map]
@[simp]
theorem map_map (g : β → γ) (f : α → β) (l : Language α) : map g (map f l) = map (g ∘ f) l := by
simp [map, image_image]
lemma mem_kstar_iff_exists_nonempty {x : List α} :
x ∈ l∗ ↔ ∃ S : List (List α), x = S.flatten ∧ ∀ y ∈ S, y ∈ l ∧ y ≠ [] := by
constructor
· rintro ⟨S, rfl, h⟩
refine ⟨S.filter fun l ↦ !List.isEmpty l,
by simp [List.flatten_filter_not_isEmpty], fun y hy ↦ ?_⟩
simp only [mem_filter, Bool.not_eq_eq_eq_not, Bool.not_true, isEmpty_eq_false_iff, ne_eq] at hy
exact ⟨h y hy.1, hy.2⟩
· rintro ⟨S, hx, h⟩
exact ⟨S, hx, fun y hy ↦ (h y hy).1⟩
theorem kstar_def_nonempty (l : Language α) :
l∗ = { x | ∃ S : List (List α), x = S.flatten ∧ ∀ y ∈ S, y ∈ l ∧ y ≠ [] } := by
ext x; apply mem_kstar_iff_exists_nonempty
theorem le_iff (l m : Language α) : l ≤ m ↔ l + m = m :=
sup_eq_right.symm
theorem le_mul_congr {l₁ l₂ m₁ m₂ : Language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ * l₂ ≤ m₁ * m₂ := by
intro h₁ h₂ x hx
simp only [mul_def, mem_image2] at hx ⊢
tauto
theorem le_add_congr {l₁ l₂ m₁ m₂ : Language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ + l₂ ≤ m₁ + m₂ :=
sup_le_sup
theorem mem_iSup {ι : Sort v} {l : ι → Language α} {x : List α} : (x ∈ ⨆ i, l i) ↔ ∃ i, x ∈ l i :=
mem_iUnion
theorem iSup_mul {ι : Sort v} (l : ι → Language α) (m : Language α) :
(⨆ i, l i) * m = ⨆ i, l i * m :=
image2_iUnion_left _ _ _
theorem mul_iSup {ι : Sort v} (l : ι → Language α) (m : Language α) :
(m * ⨆ i, l i) = ⨆ i, m * l i :=
image2_iUnion_right _ _ _
theorem iSup_add {ι : Sort v} [Nonempty ι] (l : ι → Language α) (m : Language α) :
(⨆ i, l i) + m = ⨆ i, l i + m :=
iSup_sup
theorem add_iSup {ι : Sort v} [Nonempty ι] (l : ι → Language α) (m : Language α) :
(m + ⨆ i, l i) = ⨆ i, m + l i :=
sup_iSup
theorem mem_pow {l : Language α} {x : List α} {n : ℕ} :
x ∈ l ^ n ↔ ∃ S : List (List α), x = S.flatten ∧ S.length = n ∧ ∀ y ∈ S, y ∈ l := by
induction n generalizing x with
| zero => simp
| succ n ihn =>
simp only [pow_succ', mem_mul, ihn]
constructor
· rintro ⟨a, ha, b, ⟨S, rfl, rfl, hS⟩, rfl⟩
exact ⟨a :: S, rfl, rfl, forall_mem_cons.2 ⟨ha, hS⟩⟩
· rintro ⟨_ | ⟨a, S⟩, rfl, hn, hS⟩ <;> cases hn
rw [forall_mem_cons] at hS
exact ⟨a, hS.1, _, ⟨S, rfl, rfl, hS.2⟩, rfl⟩
theorem kstar_eq_iSup_pow (l : Language α) : l∗ = ⨆ i : ℕ, l ^ i := by
ext x
simp only [mem_kstar, mem_iSup, mem_pow]
grind
@[simp]
theorem map_kstar (f : α → β) (l : Language α) : map f l∗ = (map f l)∗ := by
rw [kstar_eq_iSup_pow, kstar_eq_iSup_pow]
simp_rw [← map_pow]
exact image_iUnion
theorem mul_self_kstar_comm (l : Language α) : l∗ * l = l * l∗ := by
simp only [kstar_eq_iSup_pow, mul_iSup, iSup_mul, ← pow_succ, ← pow_succ']
@[simp]
theorem one_add_self_mul_kstar_eq_kstar (l : Language α) : 1 + l * l∗ = l∗ := by
simp only [kstar_eq_iSup_pow, mul_iSup, ← pow_succ', ← pow_zero l]
exact sup_iSup_nat_succ _
@[simp]
theorem one_add_kstar_mul_self_eq_kstar (l : Language α) : 1 + l∗ * l = l∗ := by
rw [mul_self_kstar_comm, one_add_self_mul_kstar_eq_kstar]
instance : KleeneAlgebra (Language α) :=
{ instSemiring, instCompleteAtomicBooleanAlgebra with
kstar := fun L ↦ L∗,
one_le_kstar := fun a _ hl ↦ ⟨[], hl, by simp⟩,
mul_kstar_le_kstar := fun a ↦ (one_add_self_mul_kstar_eq_kstar a).le.trans' le_sup_right,
kstar_mul_le_kstar := fun a ↦ (one_add_kstar_mul_self_eq_kstar a).le.trans' le_sup_right,
kstar_mul_le_self := fun l m h ↦ by
rw [kstar_eq_iSup_pow, iSup_mul]
refine iSup_le (fun n ↦ ?_)
induction n with
| zero => simp
| succ n ih =>
rw [pow_succ, mul_assoc (l^n) l m]
exact le_trans (le_mul_congr le_rfl h) ih,
mul_kstar_le_self := fun l m h ↦ by
rw [kstar_eq_iSup_pow, mul_iSup]
refine iSup_le (fun n ↦ ?_)
induction n with
| zero => simp
| succ n ih =>
rw [pow_succ, ← mul_assoc m (l^n) l]
exact le_trans (le_mul_congr ih le_rfl) h }
/-- **Arden's lemma** -/
theorem self_eq_mul_add_iff {l m n : Language α} (hm : [] ∉ m) : l = m * l + n ↔ l = m∗ * n where
mp h := by
apply le_antisymm
· intro x hx
induction hlen : x.length using Nat.strong_induction_on generalizing x with | _ _ ih
subst hlen
rw [h] at hx
obtain hx | hx := hx
· obtain ⟨a, ha, b, hb, rfl⟩ := mem_mul.mp hx
rw [length_append] at ih
have hal : 0 < a.length := length_pos_iff.mpr <| ne_of_mem_of_not_mem ha hm
specialize ih b.length (Nat.lt_add_left_iff_pos.mpr hal) hb rfl
rw [← one_add_self_mul_kstar_eq_kstar, one_add_mul, mul_assoc]
right
exact ⟨_, ha, _, ih, rfl⟩
· exact ⟨[], nil_mem_kstar _, _, ⟨hx, nil_append _⟩⟩
· rw [kstar_eq_iSup_pow, iSup_mul, iSup_le_iff]
intro i
induction i with rw [h]
| zero =>
rw [pow_zero, one_mul, add_comm]
exact le_self_add
| succ _ ih =>
rw [add_comm, pow_add, pow_one, mul_assoc]
exact le_add_right (mul_le_mul_left' ih _)
mpr h := by rw [h, add_comm, ← mul_assoc, ← one_add_mul, one_add_self_mul_kstar_eq_kstar]
/-- Language `l.reverse` is defined as the set of words from `l` backwards. -/
def reverse (l : Language α) : Language α := { w : List α | w.reverse ∈ l }
@[simp]
lemma mem_reverse : a ∈ l.reverse ↔ a.reverse ∈ l := Iff.rfl
lemma reverse_mem_reverse : a.reverse ∈ l.reverse ↔ a ∈ l := by
rw [mem_reverse, List.reverse_reverse]
lemma reverse_eq_image (l : Language α) : l.reverse = List.reverse '' l :=
((List.reverse_involutive.toPerm _).image_eq_preimage _).symm
@[simp]
lemma reverse_zero : (0 : Language α).reverse = 0 := rfl
@[simp]
lemma reverse_one : (1 : Language α).reverse = 1 := by
simp [reverse, ← one_def]
lemma reverse_involutive : Function.Involutive (reverse : Language α → _) :=
List.reverse_involutive.preimage
lemma reverse_bijective : Function.Bijective (reverse : Language α → _) :=
reverse_involutive.bijective
lemma reverse_injective : Function.Injective (reverse : Language α → _) :=
reverse_involutive.injective
lemma reverse_surjective : Function.Surjective (reverse : Language α → _) :=
reverse_involutive.surjective
@[simp]
lemma reverse_reverse (l : Language α) : l.reverse.reverse = l := reverse_involutive l
@[simp]
lemma reverse_add (l m : Language α) : (l + m).reverse = l.reverse + m.reverse := rfl
@[simp]
lemma reverse_mul (l m : Language α) : (l * m).reverse = m.reverse * l.reverse := by
simp only [mul_def, reverse_eq_image, image2_image_left, image2_image_right, image_image2,
List.reverse_append]
apply image2_swap
@[simp]
lemma reverse_iSup {ι : Sort*} (l : ι → Language α) : (⨆ i, l i).reverse = ⨆ i, (l i).reverse :=
preimage_iUnion
@[simp]
lemma reverse_iInf {ι : Sort*} (l : ι → Language α) : (⨅ i, l i).reverse = ⨅ i, (l i).reverse :=
preimage_iInter
variable (α) in
/-- `Language.reverse` as a ring isomorphism to the opposite ring. -/
@[simps]
def reverseIso : Language α ≃+* (Language α)ᵐᵒᵖ where
toFun l := .op l.reverse
invFun l' := l'.unop.reverse
left_inv := reverse_reverse
right_inv l' := MulOpposite.unop_injective <| reverse_reverse l'.unop
map_mul' l₁ l₂ := MulOpposite.unop_injective <| reverse_mul l₁ l₂
map_add' l₁ l₂ := MulOpposite.unop_injective <| reverse_add l₁ l₂
@[simp]
lemma reverse_pow (l : Language α) (n : ℕ) : (l ^ n).reverse = l.reverse ^ n :=
MulOpposite.op_injective (map_pow (reverseIso α) l n)
@[simp]
lemma reverse_kstar (l : Language α) : l∗.reverse = l.reverse∗ := by
simp only [kstar_eq_iSup_pow, reverse_iSup, reverse_pow]
end Language
/-- Symbols for use by all kinds of grammars. -/
inductive Symbol (T N : Type*)
/-- Terminal symbols (of the same type as the language) -/
| terminal (t : T) : Symbol T N
/-- Nonterminal symbols (must not be present when the word being generated is finalized) -/
| nonterminal (n : N) : Symbol T N
deriving
DecidableEq, Repr, Fintype
attribute [nolint docBlame] Symbol.proxyType Symbol.proxyTypeEquiv
|
Basic.lean
|
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland, Yury Kudryashov
-/
import Mathlib.Algebra.Group.Commute.Defs
import Mathlib.Algebra.Group.Semiconj.Basic
/-!
# Additional lemmas about commuting pairs of elements in monoids
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {G : Type*}
section Semigroup
variable [Semigroup G] {a b c : G}
open Function
@[to_additive]
lemma SemiconjBy.function_semiconj_mul_left (h : SemiconjBy a b c) :
Semiconj (a * ·) (b * ·) (c * ·) := fun j ↦ by simp only [← mul_assoc, h.eq]
@[to_additive]
lemma Commute.function_commute_mul_left (h : Commute a b) : Function.Commute (a * ·) (b * ·) :=
SemiconjBy.function_semiconj_mul_left h
@[to_additive]
lemma SemiconjBy.function_semiconj_mul_right_swap (h : SemiconjBy a b c) :
Function.Semiconj (· * a) (· * c) (· * b) := fun j ↦ by simp only [mul_assoc, ← h.eq]
@[to_additive]
lemma Commute.function_commute_mul_right (h : Commute a b) : Function.Commute (· * a) (· * b) :=
SemiconjBy.function_semiconj_mul_right_swap h
end Semigroup
namespace Commute
section DivisionMonoid
variable [DivisionMonoid G] {a b c d : G}
@[to_additive]
protected theorem inv_inv : Commute a b → Commute a⁻¹ b⁻¹ :=
SemiconjBy.inv_inv_symm
@[to_additive (attr := simp)]
theorem inv_inv_iff : Commute a⁻¹ b⁻¹ ↔ Commute a b :=
SemiconjBy.inv_inv_symm_iff
@[to_additive]
protected theorem div_mul_div_comm (hbd : Commute b d) (hbc : Commute b⁻¹ c) :
a / b * (c / d) = a * c / (b * d) := by
simp_rw [div_eq_mul_inv, mul_inv_rev, hbd.inv_inv.symm.eq, hbc.mul_mul_mul_comm]
@[to_additive]
protected theorem mul_div_mul_comm (hcd : Commute c d) (hbc : Commute b c⁻¹) :
a * b / (c * d) = a / c * (b / d) :=
(hcd.div_mul_div_comm hbc.symm).symm
@[to_additive]
protected theorem div_div_div_comm (hbc : Commute b c) (hbd : Commute b⁻¹ d) (hcd : Commute c⁻¹ d) :
a / b / (c / d) = a / c / (b / d) := by
simp_rw [div_eq_mul_inv, mul_inv_rev, inv_inv, hbd.symm.eq, hcd.symm.eq,
hbc.inv_inv.mul_mul_mul_comm]
end DivisionMonoid
section Group
variable [Group G] {a b : G}
@[to_additive (attr := simp)]
lemma inv_left_iff : Commute a⁻¹ b ↔ Commute a b := SemiconjBy.inv_symm_left_iff
@[to_additive] alias ⟨_, inv_left⟩ := inv_left_iff
@[to_additive (attr := simp)]
lemma inv_right_iff : Commute a b⁻¹ ↔ Commute a b := SemiconjBy.inv_right_iff
@[to_additive] alias ⟨_, inv_right⟩ := inv_right_iff
@[to_additive]
protected lemma inv_mul_cancel (h : Commute a b) : a⁻¹ * b * a = b := by
rw [h.inv_left.eq, inv_mul_cancel_right]
@[to_additive]
lemma inv_mul_cancel_assoc (h : Commute a b) : a⁻¹ * (b * a) = b := by
rw [← mul_assoc, h.inv_mul_cancel]
@[to_additive (attr := simp)]
protected theorem conj_iff (h : G) : Commute (h * a * h⁻¹) (h * b * h⁻¹) ↔ Commute a b :=
SemiconjBy.conj_iff
@[to_additive]
protected theorem conj (comm : Commute a b) (h : G) : Commute (h * a * h⁻¹) (h * b * h⁻¹) :=
(Commute.conj_iff h).mpr comm
@[to_additive (attr := simp)]
lemma zpow_right (h : Commute a b) (m : ℤ) : Commute a (b ^ m) := SemiconjBy.zpow_right h m
@[to_additive (attr := simp)]
lemma zpow_left (h : Commute a b) (m : ℤ) : Commute (a ^ m) b := (h.symm.zpow_right m).symm
@[to_additive] lemma zpow_zpow (h : Commute a b) (m n : ℤ) : Commute (a ^ m) (b ^ n) :=
(h.zpow_left m).zpow_right n
variable (a) (m n : ℤ)
@[to_additive] lemma self_zpow : Commute a (a ^ n) := (Commute.refl a).zpow_right n
@[to_additive] lemma zpow_self : Commute (a ^ n) a := (Commute.refl a).zpow_left n
@[to_additive] lemma zpow_zpow_self : Commute (a ^ m) (a ^ n) := (Commute.refl a).zpow_zpow m n
end Group
end Commute
section Group
variable [Group G]
@[to_additive] lemma pow_inv_comm (a : G) (m n : ℕ) : a⁻¹ ^ m * a ^ n = a ^ n * a⁻¹ ^ m :=
(Commute.refl a).inv_left.pow_pow _ _
end Group
|
intdiv.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple prime order.
From mathcomp Require Import ssralg poly ssrnum ssrint matrix.
From mathcomp Require Import polydiv perm zmodp bigop.
(******************************************************************************)
(* This file provides various results on divisibility of integers. *)
(* It defines, for m, n, d : int, *)
(* (m %% d)%Z == the remainder of the Euclidean division of m by d; this is *)
(* the least non-negative element of the coset m + dZ when *)
(* d != 0, and m if d = 0. *)
(* (m %/ d)%Z == the quotient of the Euclidean division of m by d, such *)
(* that m = (m %/ d)%Z * d + (m %% d)%Z. Since for d != 0 the *)
(* remainder is non-negative, (m %/ d)%Z is non-zero for *)
(* negative m. *)
(* (d %| m)%Z <=> m is divisible by d; dvdz d is the (collective) predicate *)
(* for integers divisible by d, and (d %| m)%Z is actually *)
(* (transposing) notation for m \in dvdz d. *)
(* (m = n %[mod d])%Z, (m == n %[mod d])%Z, (m != n %[mod d])%Z *)
(* m and n are (resp. compare, don't compare) equal mod d. *)
(* gcdz m n == the (non-negative) greatest common divisor of m and n, *)
(* with gcdz 0 0 = 0. *)
(* lcmz m n == the (non-negative) least common multiple of m and n. *)
(* coprimez m n <=> m and n are coprime. *)
(* egcdz m n == the Bezout coefficients of the gcd of m and n: a pair *)
(* (u, v) of coprime integers such that u*m + v*n = gcdz m n. *)
(* Alternatively, a Bezoutz lemma states such u and v exist. *)
(* zchinese m1 m2 n1 n2 == for coprime m1 and m2, a solution to the Chinese *)
(* remainder problem for n1 and n2, i.e., and integer n such *)
(* that n = n1 %[mod m1] and n = n2 %[mod m2]. *)
(* zcontents p == the contents of p : {poly int}, that is, the gcd of the *)
(* coefficients of p, with the same sign as the lead *)
(* coefficient of p. *)
(* zprimitive p == the primitive part of p : {poly int}, i.e., p divided by *)
(* its contents. *)
(* int_Smith_normal_form :: a theorem asserting the existence of the Smith *)
(* normal form for integer matrices. *)
(* Note that many of the concepts and results in this file could and perhaps *)
(* should be generalized to the more general setting of integral, unique *)
(* factorization, principal ideal, or Euclidean domains. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Definition divz (m d : int) : int :=
let: (K, n) := match m with Posz n => (Posz, n) | Negz n => (Negz, n) end in
sgz d * K (n %/ `|d|)%N.
Definition modz (m d : int) : int := m - divz m d * d.
Definition dvdz d m := (`|d| %| `|m|)%N.
Definition gcdz m n := (gcdn `|m| `|n|)%:Z.
Definition lcmz m n := (lcmn `|m| `|n|)%:Z.
Definition egcdz m n : int * int :=
if m == 0 then (0, (-1) ^+ (n < 0)%R) else
let: (u, v) := egcdn `|m| `|n| in (sgz m * u, - (-1) ^+ (n < 0)%R * v%:Z).
Definition coprimez m n := (gcdz m n == 1).
Infix "%/" := divz : int_scope.
Infix "%%" := modz : int_scope.
Notation "d %| m" := (m \in dvdz d) : int_scope.
Notation "m = n %[mod d ]" := (modz m d = modz n d) : int_scope.
Notation "m == n %[mod d ]" := (modz m d == modz n d) : int_scope.
Notation "m <> n %[mod d ]" := (modz m d <> modz n d) : int_scope.
Notation "m != n %[mod d ]" := (modz m d != modz n d) : int_scope.
Lemma divz_nat (n d : nat) : (n %/ d)%Z = (n %/ d)%N.
Proof. by case: d => // d; rewrite /divz /= mul1r. Qed.
Lemma divzN m d : (m %/ - d)%Z = - (m %/ d)%Z.
Proof. by case: m => n; rewrite /divz /= sgzN abszN mulNr. Qed.
Lemma divz_abs (m d : int) : (m %/ `|d|)%Z = (-1) ^+ (d < 0)%R * (m %/ d)%Z.
Proof.
by rewrite {3}[d]intEsign !mulr_sign; case: ifP => -> //; rewrite divzN opprK.
Qed.
Lemma div0z d : (0 %/ d)%Z = 0.
Proof.
by rewrite -(canLR (signrMK _) (divz_abs _ _)) (divz_nat 0) div0n mulr0.
Qed.
Lemma divNz_nat m d : (d > 0)%N -> (Negz m %/ d)%Z = - (m %/ d).+1%:Z.
Proof. by case: d => // d _; apply: mul1r. Qed.
Lemma divz_eq m d : m = (m %/ d)%Z * d + (m %% d)%Z.
Proof. by rewrite addrC subrK. Qed.
Lemma modzN m d : (m %% - d)%Z = (m %% d)%Z.
Proof. by rewrite /modz divzN mulrNN. Qed.
Lemma modz_abs m d : (m %% `|d|%N)%Z = (m %% d)%Z.
Proof. by rewrite {2}[d]intEsign mulr_sign; case: ifP; rewrite ?modzN. Qed.
Lemma modz_nat (m d : nat) : (m %% d)%Z = (m %% d)%N.
Proof.
by apply: (canLR (addrK _)); rewrite addrC divz_nat {1}(divn_eq m d).
Qed.
Lemma modNz_nat m d : (d > 0)%N -> (Negz m %% d)%Z = d%:Z - 1 - (m %% d)%:Z.
Proof.
rewrite /modz => /divNz_nat->; apply: (canLR (addrK _)).
rewrite -!addrA -!opprD -!PoszD -opprB mulnSr !addnA PoszD addrK.
by rewrite addnAC -addnA mulnC -divn_eq.
Qed.
Lemma modz_ge0 m d : d != 0 -> 0 <= (m %% d)%Z.
Proof.
rewrite -absz_gt0 -modz_abs => d_gt0.
case: m => n; rewrite ?modNz_nat ?modz_nat // -addrA -opprD subr_ge0.
by rewrite lez_nat ltn_mod.
Qed.
Lemma divz0 m : (m %/ 0)%Z = 0. Proof. by case: m. Qed.
Lemma mod0z d : (0 %% d)%Z = 0. Proof. by rewrite /modz div0z mul0r subrr. Qed.
Lemma modz0 m : (m %% 0)%Z = m. Proof. by rewrite /modz mulr0 subr0. Qed.
Lemma divz_small m d : 0 <= m < `|d|%:Z -> (m %/ d)%Z = 0.
Proof.
rewrite -(canLR (signrMK _) (divz_abs _ _)); case: m => // n /divn_small.
by rewrite divz_nat => ->; rewrite mulr0.
Qed.
Lemma divzMDl q m d : d != 0 -> ((q * d + m) %/ d)%Z = q + (m %/ d)%Z.
Proof.
rewrite neq_lt -oppr_gt0 => nz_d.
wlog{nz_d} d_gt0: q d / d > 0; last case: d => // d in d_gt0 *.
move=> IH; case/orP: nz_d => /IH// /(_ (- q)).
by rewrite mulrNN !divzN -opprD => /oppr_inj.
wlog q_gt0: q m / q >= 0; last case: q q_gt0 => // q _.
move=> IH; case: q => n; first exact: IH; rewrite NegzE mulNr.
by apply: canRL (addKr _) _; rewrite -IH ?addNKr.
case: m => n; first by rewrite !divz_nat divnMDl.
have [le_qd_n | lt_qd_n] := leqP (q * d) n.
rewrite divNz_nat // NegzE -(subnKC le_qd_n) divnMDl //.
by rewrite -!addnS !PoszD !opprD !addNKr divNz_nat.
rewrite divNz_nat // NegzE -PoszM subzn // divz_nat.
apply: canRL (addrK _) _; congr _%:Z; rewrite addnC -divnMDl // mulSnr.
rewrite -{3}(subnKC (ltn_pmod n d_gt0)) addnA addnS -divn_eq addnAC.
by rewrite subnKC // divnMDl // divn_small ?addn0 // subnSK ?ltn_mod ?leq_subr.
Qed.
Lemma mulzK m d : d != 0 -> (m * d %/ d)%Z = m.
Proof. by move=> d_nz; rewrite -[m * d]addr0 divzMDl // div0z addr0. Qed.
Lemma mulKz m d : d != 0 -> (d * m %/ d)%Z = m.
Proof. by move=> d_nz; rewrite mulrC mulzK. Qed.
Lemma expzB p m n : p != 0 -> (m >= n)%N -> p ^+ (m - n) = (p ^+ m %/ p ^+ n)%Z.
Proof. by move=> p_nz /subnK{2}<-; rewrite exprD mulzK // expf_neq0. Qed.
Lemma modz1 m : (m %% 1)%Z = 0.
Proof. by case: m => n; rewrite (modNz_nat, modz_nat) ?modn1. Qed.
Lemma divz1 m : (m %/ 1)%Z = m. Proof. by rewrite -{1}[m]mulr1 mulzK. Qed.
Lemma divzz d : (d %/ d)%Z = (d != 0).
Proof. by have [-> // | d_nz] := eqVneq; rewrite -{1}[d]mul1r mulzK. Qed.
Lemma ltz_pmod m d : d > 0 -> (m %% d)%Z < d.
Proof.
case: m d => n [] // d d_gt0; first by rewrite modz_nat ltz_nat ltn_pmod.
by rewrite modNz_nat // -lezD1 addrAC subrK gerDl oppr_le0.
Qed.
Lemma ltz_mod m d : d != 0 -> (m %% d)%Z < `|d|.
Proof. by rewrite -absz_gt0 -modz_abs => d_gt0; apply: ltz_pmod. Qed.
Lemma divzMpl p m d : p > 0 -> (p * m %/ (p * d) = m %/ d)%Z.
Proof.
case: p => // p p_gt0; wlog d_gt0: d / d > 0; last case: d => // d in d_gt0 *.
by move=> IH; case/intP: d => [|d|d]; rewrite ?mulr0 ?divz0 ?mulrN ?divzN ?IH.
rewrite {1}(divz_eq m d) mulrDr mulrCA divzMDl ?mulf_neq0 ?gt_eqF // addrC.
rewrite divz_small ?add0r // PoszM pmulr_rge0 ?modz_ge0 ?gt_eqF //=.
by rewrite ltr_pM2l ?ltz_pmod.
Qed.
Arguments divzMpl [p m d].
Lemma divzMpr p m d : p > 0 -> (m * p %/ (d * p) = m %/ d)%Z.
Proof. by move=> p_gt0; rewrite -!(mulrC p) divzMpl. Qed.
Arguments divzMpr [p m d].
Lemma lez_floor m d : d != 0 -> (m %/ d)%Z * d <= m.
Proof. by rewrite -subr_ge0; apply: modz_ge0. Qed.
(* leq_mod does not extend to negative m. *)
Lemma lez_div m d : (`|(m %/ d)%Z| <= `|m|)%N.
Proof.
wlog d_gt0: d / d > 0; last case: d d_gt0 => // d d_gt0.
by move=> IH; case/intP: d => [|n|n]; rewrite ?divz0 ?divzN ?abszN // IH.
case: m => n; first by rewrite divz_nat leq_div.
by rewrite divNz_nat // NegzE !abszN ltnS leq_div.
Qed.
Lemma ltz_ceil m d : d > 0 -> m < ((m %/ d)%Z + 1) * d.
Proof.
by case: d => // d d_gt0; rewrite mulrDl mul1r -ltrBlDl ltz_mod ?gt_eqF.
Qed.
Lemma ltz_divLR m n d : d > 0 -> ((m %/ d)%Z < n) = (m < n * d).
Proof.
move=> d_gt0; apply/idP/idP.
by rewrite -[_ < n]lezD1 -(ler_pM2r d_gt0); exact/lt_le_trans/ltz_ceil.
by rewrite -(ltr_pM2r d_gt0 _ n); apply/le_lt_trans/lez_floor; rewrite gt_eqF.
Qed.
Lemma lez_divRL m n d : d > 0 -> (m <= (n %/ d)%Z) = (m * d <= n).
Proof. by move=> d_gt0; rewrite !leNgt ltz_divLR. Qed.
Lemma lez_pdiv2r d : 0 <= d -> {homo divz^~ d : m n / m <= n}.
Proof.
by case: d => [[|d]|]// _ [] m [] n //; rewrite /divz !mul1r; apply: leq_div2r.
Qed.
Lemma divz_ge0 m d : d > 0 -> ((m %/ d)%Z >= 0) = (m >= 0).
Proof. by case: d m => // d [] n d_gt0; rewrite (divz_nat, divNz_nat). Qed.
Lemma divzMA_ge0 m n p : n >= 0 -> (m %/ (n * p) = (m %/ n)%Z %/ p)%Z.
Proof.
case: n => // [[|n]] _; first by rewrite mul0r !divz0 div0z.
wlog p_gt0: p / p > 0; last case: p => // p in p_gt0 *.
by case/intP: p => [|p|p] IH; rewrite ?mulr0 ?divz0 ?mulrN ?divzN // IH.
rewrite {2}(divz_eq m (n.+1%:Z * p)) mulrA mulrAC !divzMDl // ?gt_eqF //.
rewrite [rhs in _ + rhs]divz_small ?addr0 // ltz_divLR // divz_ge0 //.
by rewrite mulrC ltz_pmod ?modz_ge0 ?gt_eqF ?pmulr_lgt0.
Qed.
Lemma modz_small m d : 0 <= m < d -> (m %% d)%Z = m.
Proof. by case: m d => //= m [] // d; rewrite modz_nat => /modn_small->. Qed.
Lemma modz_mod m d : ((m %% d)%Z = m %[mod d])%Z.
Proof.
rewrite -!(modz_abs _ d); case: {d}`|d|%N => [|d]; first by rewrite !modz0.
by rewrite modz_small ?modz_ge0 ?ltz_mod.
Qed.
Lemma modzMDl p m d : (p * d + m = m %[mod d])%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite mulr0 add0r.
by rewrite /modz divzMDl // mulrDl opprD addrACA subrr add0r.
Qed.
Lemma mulz_modr {p m d} : 0 < p -> p * (m %% d)%Z = ((p * m) %% (p * d))%Z.
Proof.
case: p => // p p_gt0; rewrite mulrBr; apply: canLR (addrK _) _.
by rewrite mulrCA -(divzMpl p_gt0) subrK.
Qed.
Lemma mulz_modl {p m d} : 0 < p -> (m %% d)%Z * p = ((m * p) %% (d * p))%Z.
Proof. by rewrite -!(mulrC p); apply: mulz_modr. Qed.
Lemma modzDl m d : (d + m = m %[mod d])%Z.
Proof. by rewrite -{1}[d]mul1r modzMDl. Qed.
Lemma modzDr m d : (m + d = m %[mod d])%Z.
Proof. by rewrite addrC modzDl. Qed.
Lemma modzz d : (d %% d)%Z = 0.
Proof. by rewrite -{1}[d]addr0 modzDl mod0z. Qed.
Lemma modzMl p d : (p * d %% d)%Z = 0.
Proof. by rewrite -[p * d]addr0 modzMDl mod0z. Qed.
Lemma modzMr p d : (d * p %% d)%Z = 0.
Proof. by rewrite mulrC modzMl. Qed.
Lemma modzDml m n d : ((m %% d)%Z + n = m + n %[mod d])%Z.
Proof. by rewrite {2}(divz_eq m d) -[_ * d + _ + n]addrA modzMDl. Qed.
Lemma modzDmr m n d : (m + (n %% d)%Z = m + n %[mod d])%Z.
Proof. by rewrite !(addrC m) modzDml. Qed.
Lemma modzDm m n d : ((m %% d)%Z + (n %% d)%Z = m + n %[mod d])%Z.
Proof. by rewrite modzDml modzDmr. Qed.
Lemma eqz_modDl p m n d : (p + m == p + n %[mod d])%Z = (m == n %[mod d])%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite !modz0 (inj_eq (addrI p)).
apply/eqP/eqP=> eq_mn; last by rewrite -modzDmr eq_mn modzDmr.
by rewrite -(addKr p m) -modzDmr eq_mn modzDmr addKr.
Qed.
Lemma eqz_modDr p m n d : (m + p == n + p %[mod d])%Z = (m == n %[mod d])%Z.
Proof. by rewrite -!(addrC p) eqz_modDl. Qed.
Lemma modzMml m n d : ((m %% d)%Z * n = m * n %[mod d])%Z.
Proof. by rewrite {2}(divz_eq m d) [in RHS]mulrDl mulrAC modzMDl. Qed. (* FIXME: rewrite pattern *)
Lemma modzMmr m n d : (m * (n %% d)%Z = m * n %[mod d])%Z.
Proof. by rewrite !(mulrC m) modzMml. Qed.
Lemma modzMm m n d : ((m %% d)%Z * (n %% d)%Z = m * n %[mod d])%Z.
Proof. by rewrite modzMml modzMmr. Qed.
Lemma modzXm k m d : ((m %% d)%Z ^+ k = m ^+ k %[mod d])%Z.
Proof. by elim: k => // k IHk; rewrite !exprS -modzMmr IHk modzMm. Qed.
Lemma modzNm m d : (- (m %% d)%Z = - m %[mod d])%Z.
Proof. by rewrite -mulN1r modzMmr mulN1r. Qed.
Lemma modz_absm m d : ((-1) ^+ (m < 0)%R * (m %% d)%Z = `|m|%:Z %[mod d])%Z.
Proof. by rewrite modzMmr -abszEsign. Qed.
(** Divisibility **)
Lemma dvdzE d m : (d %| m)%Z = (`|d| %| `|m|)%N. Proof. by []. Qed.
Lemma dvdz0 d : (d %| 0)%Z. Proof. exact: dvdn0. Qed.
Lemma dvd0z n : (0 %| n)%Z = (n == 0). Proof. by rewrite -absz_eq0 -dvd0n. Qed.
Lemma dvdz1 d : (d %| 1)%Z = (`|d|%N == 1). Proof. exact: dvdn1. Qed.
Lemma dvd1z m : (1 %| m)%Z. Proof. exact: dvd1n. Qed.
Lemma dvdzz m : (m %| m)%Z. Proof. exact: dvdnn. Qed.
Lemma dvdz_mull d m n : (d %| n)%Z -> (d %| m * n)%Z.
Proof. by rewrite !dvdzE abszM; apply: dvdn_mull. Qed.
Lemma dvdz_mulr d m n : (d %| m)%Z -> (d %| m * n)%Z.
Proof. by move=> d_m; rewrite mulrC dvdz_mull. Qed.
#[global] Hint Resolve dvdz0 dvd1z dvdzz dvdz_mull dvdz_mulr : core.
Lemma dvdz_mul d1 d2 m1 m2 : (d1 %| m1 -> d2 %| m2 -> d1 * d2 %| m1 * m2)%Z.
Proof. by rewrite !dvdzE !abszM; apply: dvdn_mul. Qed.
Lemma dvdz_trans n d m : (d %| n -> n %| m -> d %| m)%Z.
Proof. by rewrite !dvdzE; apply: dvdn_trans. Qed.
Lemma dvdzP d m : reflect (exists q, m = q * d) (d %| m)%Z.
Proof.
apply: (iffP dvdnP) => [] [q Dm]; last by exists `|q|%N; rewrite Dm abszM.
exists ((-1) ^+ (m < 0)%R * q%:Z * (-1) ^+ (d < 0)%R).
by rewrite -!mulrA -abszEsign -PoszM -Dm -intEsign.
Qed.
Arguments dvdzP {d m}.
Lemma dvdz_mod0P d m : reflect (m %% d = 0)%Z (d %| m)%Z.
Proof.
apply: (iffP dvdzP) => [[q ->] | md0]; first by rewrite modzMl.
by rewrite (divz_eq m d) md0 addr0; exists (m %/ d)%Z.
Qed.
Arguments dvdz_mod0P {d m}.
Lemma dvdz_eq d m : (d %| m)%Z = ((m %/ d)%Z * d == m).
Proof. by rewrite (sameP dvdz_mod0P eqP) subr_eq0 eq_sym. Qed.
Lemma divzK d m : (d %| m)%Z -> (m %/ d)%Z * d = m.
Proof. by rewrite dvdz_eq => /eqP. Qed.
Lemma lez_divLR d m n : 0 < d -> (d %| m)%Z -> ((m %/ d)%Z <= n) = (m <= n * d).
Proof. by move=> /ler_pM2r <- /divzK->. Qed.
Lemma ltz_divRL d m n : 0 < d -> (d %| m)%Z -> (n < m %/ d)%Z = (n * d < m).
Proof. by move=> /ltr_pM2r/(_ n)<- /divzK->. Qed.
Lemma eqz_div d m n : d != 0 -> (d %| m)%Z -> (n == m %/ d)%Z = (n * d == m).
Proof. by move=> /mulIf/inj_eq <- /divzK->. Qed.
Lemma eqz_mul d m n : d != 0 -> (d %| m)%Z -> (m == n * d) = (m %/ d == n)%Z.
Proof. by move=> d_gt0 dv_d_m; rewrite eq_sym -eqz_div // eq_sym. Qed.
Lemma divz_mulAC d m n : (d %| m)%Z -> (m %/ d)%Z * n = (m * n %/ d)%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite !divz0 mul0r.
by move/divzK=> {2} <-; rewrite mulrAC mulzK.
Qed.
Lemma mulz_divA d m n : (d %| n)%Z -> m * (n %/ d)%Z = (m * n %/ d)%Z.
Proof. by move=> dv_d_m; rewrite !(mulrC m) divz_mulAC. Qed.
Lemma mulz_divCA d m n :
(d %| m)%Z -> (d %| n)%Z -> m * (n %/ d)%Z = n * (m %/ d)%Z.
Proof. by move=> dv_d_m dv_d_n; rewrite mulrC divz_mulAC ?mulz_divA. Qed.
Lemma divzA m n p : (p %| n -> n %| m * p -> m %/ (n %/ p)%Z = m * p %/ n)%Z.
Proof.
move/divzK=> p_dv_n; have [->|] := eqVneq n 0; first by rewrite div0z !divz0.
rewrite -{1 2}p_dv_n mulf_eq0 => /norP[pn_nz p_nz] /divzK; rewrite mulrA p_dv_n.
by move/mulIf=> {1} <- //; rewrite mulzK.
Qed.
Lemma divzMA m n p : (n * p %| m -> m %/ (n * p) = (m %/ n)%Z %/ p)%Z.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 !divz0.
have [-> | nz_n] := eqVneq n 0; first by rewrite mul0r !divz0 div0z.
by move/divzK=> {2} <-; rewrite mulrA mulrAC !mulzK.
Qed.
Lemma divzAC m n p : (n * p %| m -> (m %/ n)%Z %/ p = (m %/ p)%Z %/ n)%Z.
Proof. by move=> np_dv_mn; rewrite -!divzMA // mulrC. Qed.
Lemma divzMl p m d : p != 0 -> (d %| m -> p * m %/ (p * d) = m %/ d)%Z.
Proof.
have [-> | nz_d nz_p] := eqVneq d 0; first by rewrite mulr0 !divz0.
by move/divzK=> {1}<-; rewrite mulrCA mulzK ?mulf_neq0.
Qed.
Lemma divzMr p m d : p != 0 -> (d %| m -> m * p %/ (d * p) = m %/ d)%Z.
Proof. by rewrite -!(mulrC p); apply: divzMl. Qed.
Lemma dvdz_mul2l p d m : p != 0 -> (p * d %| p * m)%Z = (d %| m)%Z.
Proof. by rewrite !dvdzE -absz_gt0 !abszM; apply: dvdn_pmul2l. Qed.
Arguments dvdz_mul2l [p d m].
Lemma dvdz_mul2r p d m : p != 0 -> (d * p %| m * p)%Z = (d %| m)%Z.
Proof. by rewrite !dvdzE -absz_gt0 !abszM; apply: dvdn_pmul2r. Qed.
Arguments dvdz_mul2r [p d m].
Lemma dvdz_exp2l p m n : (m <= n)%N -> (p ^+ m %| p ^+ n)%Z.
Proof. by rewrite dvdzE !abszX; apply: dvdn_exp2l. Qed.
Lemma dvdz_Pexp2l p m n : `|p| > 1 -> (p ^+ m %| p ^+ n)%Z = (m <= n)%N.
Proof. by rewrite dvdzE !abszX ltz_nat; apply: dvdn_Pexp2l. Qed.
Lemma dvdz_exp2r m n k : (m %| n -> m ^+ k %| n ^+ k)%Z.
Proof. by rewrite !dvdzE !abszX; apply: dvdn_exp2r. Qed.
Fact dvdz_zmod_closed d : zmod_closed (dvdz d).
Proof.
split=> [|_ _ /dvdzP[p ->] /dvdzP[q ->]]; first exact: dvdz0.
by rewrite -mulrBl dvdz_mull.
Qed.
HB.instance Definition _ d := GRing.isZmodClosed.Build int (dvdz d)
(dvdz_zmod_closed d).
Lemma dvdz_exp k d m : (0 < k)%N -> (d %| m -> d %| m ^+ k)%Z.
Proof. by case: k => // k _ d_dv_m; rewrite exprS dvdz_mulr. Qed.
Lemma eqz_mod_dvd d m n : (m == n %[mod d])%Z = (d %| m - n)%Z.
Proof.
apply/eqP/dvdz_mod0P=> eq_mn.
by rewrite -modzDml eq_mn modzDml subrr mod0z.
by rewrite -(subrK n m) -modzDml eq_mn add0r.
Qed.
Lemma divzDl m n d :
(d %| m)%Z -> ((m + n) %/ d)%Z = (m %/ d)%Z + (n %/ d)%Z.
Proof.
have [-> | d_nz] := eqVneq d 0; first by rewrite !divz0.
by move/divzK=> {1}<-; rewrite divzMDl.
Qed.
Lemma divzDr m n d :
(d %| n)%Z -> ((m + n) %/ d)%Z = (m %/ d)%Z + (n %/ d)%Z.
Proof. by move=> dv_n; rewrite addrC divzDl // addrC. Qed.
Lemma dvdz_pcharf (R : nzRingType) p : p \in [pchar R] ->
forall n : int, (p %| n)%Z = (n%:~R == 0 :> R).
Proof.
move=> pcharRp [] n; rewrite [LHS](dvdn_pcharf pcharRp)//.
by rewrite NegzE abszN rmorphN// oppr_eq0.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use dvdz_pcharf instead.")]
Notation dvdz_charf chRp := (dvdz_pcharf chRp).
(* Greatest common divisor *)
Lemma gcdzz m : gcdz m m = `|m|%:Z. Proof. by rewrite /gcdz gcdnn. Qed.
Lemma gcdzC : commutative gcdz. Proof. by move=> m n; rewrite /gcdz gcdnC. Qed.
Lemma gcd0z m : gcdz 0 m = `|m|%:Z. Proof. by rewrite /gcdz gcd0n. Qed.
Lemma gcdz0 m : gcdz m 0 = `|m|%:Z. Proof. by rewrite /gcdz gcdn0. Qed.
Lemma gcd1z : left_zero 1 gcdz. Proof. by move=> m; rewrite /gcdz gcd1n. Qed.
Lemma gcdz1 : right_zero 1 gcdz. Proof. by move=> m; rewrite /gcdz gcdn1. Qed.
Lemma dvdz_gcdr m n : (gcdz m n %| n)%Z. Proof. exact: dvdn_gcdr. Qed.
Lemma dvdz_gcdl m n : (gcdz m n %| m)%Z. Proof. exact: dvdn_gcdl. Qed.
Lemma gcdz_eq0 m n : (gcdz m n == 0) = (m == 0) && (n == 0).
Proof. by rewrite -absz_eq0 eqn0Ngt gcdn_gt0 !negb_or -!eqn0Ngt !absz_eq0. Qed.
Lemma gcdNz m n : gcdz (- m) n = gcdz m n. Proof. by rewrite /gcdz abszN. Qed.
Lemma gcdzN m n : gcdz m (- n) = gcdz m n. Proof. by rewrite /gcdz abszN. Qed.
Lemma gcdz_modr m n : gcdz m (n %% m)%Z = gcdz m n.
Proof.
rewrite -modz_abs /gcdz; move/absz: m => m.
have [-> | m_gt0] := posnP m; first by rewrite modz0.
case: n => n; first by rewrite modz_nat gcdn_modr.
rewrite modNz_nat // NegzE abszN {2}(divn_eq n m) -addnS gcdnMDl.
rewrite -addrA -opprD -intS /=; set m1 := _.+1.
have le_m1m: (m1 <= m)%N by apply: ltn_pmod.
by rewrite subzn // !(gcdnC m) -{2 3}(subnK le_m1m) gcdnDl gcdnDr gcdnC.
Qed.
Lemma gcdz_modl m n : gcdz (m %% n)%Z n = gcdz m n.
Proof. by rewrite -!(gcdzC n) gcdz_modr. Qed.
Lemma gcdzMDl q m n : gcdz m (q * m + n) = gcdz m n.
Proof. by rewrite -gcdz_modr modzMDl gcdz_modr. Qed.
Lemma gcdzDl m n : gcdz m (m + n) = gcdz m n.
Proof. by rewrite -{2}(mul1r m) gcdzMDl. Qed.
Lemma gcdzDr m n : gcdz m (n + m) = gcdz m n.
Proof. by rewrite addrC gcdzDl. Qed.
Lemma gcdzMl n m : gcdz n (m * n) = `|n|%:Z.
Proof. by rewrite -[m * n]addr0 gcdzMDl gcdz0. Qed.
Lemma gcdzMr n m : gcdz n (n * m) = `|n|%:Z.
Proof. by rewrite mulrC gcdzMl. Qed.
Lemma gcdz_idPl {m n} : reflect (gcdz m n = `|m|%:Z) (m %| n)%Z.
Proof. by apply: (iffP gcdn_idPl) => [<- | []]. Qed.
Lemma gcdz_idPr {m n} : reflect (gcdz m n = `|n|%:Z) (n %| m)%Z.
Proof. by rewrite gcdzC; apply: gcdz_idPl. Qed.
Lemma expz_min e m n : e >= 0 -> e ^+ minn m n = gcdz (e ^+ m) (e ^+ n).
Proof.
by case: e => // e _; rewrite /gcdz !abszX -expn_min -natz -natrX !natz.
Qed.
Lemma dvdz_gcd p m n : (p %| gcdz m n)%Z = (p %| m)%Z && (p %| n)%Z.
Proof. exact: dvdn_gcd. Qed.
Lemma gcdzAC : right_commutative gcdz.
Proof. by move=> m n p; rewrite /gcdz gcdnAC. Qed.
Lemma gcdzA : associative gcdz.
Proof. by move=> m n p; rewrite /gcdz gcdnA. Qed.
Lemma gcdzCA : left_commutative gcdz.
Proof. by move=> m n p; rewrite /gcdz gcdnCA. Qed.
Lemma gcdzACA : interchange gcdz gcdz.
Proof. by move=> m n p q; rewrite /gcdz gcdnACA. Qed.
Lemma mulz_gcdr m n p : `|m|%:Z * gcdz n p = gcdz (m * n) (m * p).
Proof. by rewrite -PoszM muln_gcdr -!abszM. Qed.
Lemma mulz_gcdl m n p : gcdz m n * `|p|%:Z = gcdz (m * p) (n * p).
Proof. by rewrite -PoszM muln_gcdl -!abszM. Qed.
Lemma mulz_divCA_gcd n m : n * (m %/ gcdz n m)%Z = m * (n %/ gcdz n m)%Z.
Proof. by rewrite mulz_divCA ?dvdz_gcdl ?dvdz_gcdr. Qed.
(* Least common multiple *)
Lemma dvdz_lcmr m n : (n %| lcmz m n)%Z.
Proof. exact: dvdn_lcmr. Qed.
Lemma dvdz_lcml m n : (m %| lcmz m n)%Z.
Proof. exact: dvdn_lcml. Qed.
Lemma dvdz_lcm d1 d2 m : ((lcmn d1 d2 %| m) = (d1 %| m) && (d2 %| m))%Z.
Proof. exact: dvdn_lcm. Qed.
Lemma lcmzC : commutative lcmz.
Proof. by move=> m n; rewrite /lcmz lcmnC. Qed.
Lemma lcm0z : left_zero 0 lcmz.
Proof. by move=> x; rewrite /lcmz absz0 lcm0n. Qed.
Lemma lcmz0 : right_zero 0 lcmz.
Proof. by move=> x; rewrite /lcmz absz0 lcmn0. Qed.
Lemma lcmz_ge0 m n : 0 <= lcmz m n.
Proof. by []. Qed.
Lemma lcmz_neq0 m n : (lcmz m n != 0) = (m != 0) && (n != 0).
Proof.
have [->|m_neq0] := eqVneq m 0; first by rewrite lcm0z.
have [->|n_neq0] := eqVneq n 0; first by rewrite lcmz0.
by rewrite gt_eqF// [0 < _]lcmn_gt0 !absz_gt0 m_neq0 n_neq0.
Qed.
(* Coprime factors *)
Lemma coprimezE m n : coprimez m n = coprime `|m| `|n|. Proof. by []. Qed.
Lemma coprimez_sym : symmetric coprimez.
Proof. by move=> m n; apply: coprime_sym. Qed.
Lemma coprimeNz m n : coprimez (- m) n = coprimez m n.
Proof. by rewrite coprimezE abszN. Qed.
Lemma coprimezN m n : coprimez m (- n) = coprimez m n.
Proof. by rewrite coprimezE abszN. Qed.
Variant egcdz_spec m n : int * int -> Type :=
EgcdzSpec u v of u * m + v * n = gcdz m n & coprimez u v
: egcdz_spec m n (u, v).
Lemma egcdzP m n : egcdz_spec m n (egcdz m n).
Proof.
rewrite /egcdz; have [-> | m_nz] := eqVneq.
by split; [rewrite -abszEsign gcd0z | rewrite coprimezE absz_sign].
have m_gt0 : (`|m| > 0)%N by rewrite absz_gt0.
case: egcdnP (coprime_egcdn `|n| m_gt0) => //= u v Duv _ co_uv; split.
rewrite !mulNr -!mulrA mulrCA -abszEsg mulrCA -abszEsign.
by rewrite -!PoszM Duv addnC PoszD addrK.
by rewrite coprimezE abszM absz_sg m_nz mul1n mulNr abszN abszMsign.
Qed.
Lemma Bezoutz m n : {u : int & {v : int | u * m + v * n = gcdz m n}}.
Proof. by exists (egcdz m n).1, (egcdz m n).2; case: egcdzP. Qed.
Lemma coprimezP m n :
reflect (exists uv, uv.1 * m + uv.2 * n = 1) (coprimez m n).
Proof.
apply: (iffP eqP) => [<-| [[u v] /= Duv]].
by exists (egcdz m n); case: egcdzP.
congr _%:Z; apply: gcdn_def; rewrite ?dvd1n // => d dv_d_n dv_d_m.
by rewrite -(dvdzE d 1) -Duv [m]intEsg [n]intEsg rpredD ?dvdz_mull.
Qed.
Lemma Gauss_dvdz m n p :
coprimez m n -> (m * n %| p)%Z = (m %| p)%Z && (n %| p)%Z.
Proof. by move/Gauss_dvd <-; rewrite -abszM. Qed.
Lemma Gauss_dvdzr m n p : coprimez m n -> (m %| n * p)%Z = (m %| p)%Z.
Proof. by rewrite dvdzE abszM => /Gauss_dvdr->. Qed.
Lemma Gauss_dvdzl m n p : coprimez m p -> (m %| n * p)%Z = (m %| n)%Z.
Proof. by rewrite mulrC; apply: Gauss_dvdzr. Qed.
Lemma Gauss_gcdzr p m n : coprimez p m -> gcdz p (m * n) = gcdz p n.
Proof. by rewrite /gcdz abszM => /Gauss_gcdr->. Qed.
Lemma Gauss_gcdzl p m n : coprimez p n -> gcdz p (m * n) = gcdz p m.
Proof. by move=> co_pn; rewrite mulrC Gauss_gcdzr. Qed.
Lemma coprimezMr p m n : coprimez p (m * n) = coprimez p m && coprimez p n.
Proof. by rewrite -coprimeMr -abszM. Qed.
Lemma coprimezMl p m n : coprimez (m * n) p = coprimez m p && coprimez n p.
Proof. by rewrite -coprimeMl -abszM. Qed.
Lemma coprimez_pexpl k m n : (0 < k)%N -> coprimez (m ^+ k) n = coprimez m n.
Proof. by rewrite /coprimez /gcdz abszX; apply: coprime_pexpl. Qed.
Lemma coprimez_pexpr k m n : (0 < k)%N -> coprimez m (n ^+ k) = coprimez m n.
Proof. by move=> k_gt0; rewrite !(coprimez_sym m) coprimez_pexpl. Qed.
Lemma coprimezXl k m n : coprimez m n -> coprimez (m ^+ k) n.
Proof. by rewrite /coprimez /gcdz abszX; apply: coprimeXl. Qed.
Lemma coprimezXr k m n : coprimez m n -> coprimez m (n ^+ k).
Proof. by rewrite !(coprimez_sym m); apply: coprimezXl. Qed.
Lemma coprimez_dvdl m n p : (m %| n)%N -> coprimez n p -> coprimez m p.
Proof. exact: coprime_dvdl. Qed.
Lemma coprimez_dvdr m n p : (m %| n)%N -> coprimez p n -> coprimez p m.
Proof. exact: coprime_dvdr. Qed.
Lemma dvdz_pexp2r m n k : (k > 0)%N -> (m ^+ k %| n ^+ k)%Z = (m %| n)%Z.
Proof. by rewrite dvdzE !abszX; apply: dvdn_pexp2r. Qed.
Section Chinese.
(***********************************************************************)
(* The chinese remainder theorem *)
(***********************************************************************)
Variables m1 m2 : int.
Hypothesis co_m12 : coprimez m1 m2.
Lemma zchinese_remainder x y :
(x == y %[mod m1 * m2])%Z = (x == y %[mod m1])%Z && (x == y %[mod m2])%Z.
Proof. by rewrite !eqz_mod_dvd Gauss_dvdz. Qed.
(***********************************************************************)
(* A function that solves the chinese remainder problem *)
(***********************************************************************)
Definition zchinese r1 r2 :=
r1 * m2 * (egcdz m1 m2).2 + r2 * m1 * (egcdz m1 m2).1.
Lemma zchinese_modl r1 r2 : (zchinese r1 r2 = r1 %[mod m1])%Z.
Proof.
rewrite /zchinese; have [u v /= Duv _] := egcdzP m1 m2.
rewrite -{2}[r1]mulr1 -((gcdz _ _ =P 1) co_m12) -Duv.
by rewrite mulrDr mulrAC addrC (mulrAC r2) !mulrA !modzMDl.
Qed.
Lemma zchinese_modr r1 r2 : (zchinese r1 r2 = r2 %[mod m2])%Z.
Proof.
rewrite /zchinese; have [u v /= Duv _] := egcdzP m1 m2.
rewrite -{2}[r2]mulr1 -((gcdz _ _ =P 1) co_m12) -Duv.
by rewrite mulrAC modzMDl mulrAC addrC mulrDr !mulrA modzMDl.
Qed.
Lemma zchinese_mod x : (x = zchinese (x %% m1)%Z (x %% m2)%Z %[mod m1 * m2])%Z.
Proof.
apply/eqP; rewrite zchinese_remainder //.
by rewrite zchinese_modl zchinese_modr !modz_mod !eqxx.
Qed.
End Chinese.
Section ZpolyScale.
Definition zcontents (p : {poly int}) : int :=
sgz (lead_coef p) * \big[gcdn/0]_(i < size p) `|(p`_i)%R|%N.
Lemma sgz_contents p : sgz (zcontents p) = sgz (lead_coef p).
Proof.
rewrite /zcontents mulrC sgzM sgz_id; set d := _%:Z.
have [-> | nz_p] := eqVneq p 0; first by rewrite lead_coef0 mulr0.
rewrite gtr0_sgz ?mul1r // ltz_nat polySpred ?big_ord_recr //= -lead_coefE.
by rewrite gcdn_gt0 orbC absz_gt0 lead_coef_eq0 nz_p.
Qed.
Lemma zcontents_eq0 p : (zcontents p == 0) = (p == 0).
Proof. by rewrite -sgz_eq0 sgz_contents sgz_eq0 lead_coef_eq0. Qed.
Lemma zcontents0 : zcontents 0 = 0.
Proof. by apply/eqP; rewrite zcontents_eq0. Qed.
Lemma zcontentsZ a p : zcontents (a *: p) = a * zcontents p.
Proof.
have [-> | nz_a] := eqVneq a 0; first by rewrite scale0r mul0r zcontents0.
rewrite {2}[a]intEsg mulrCA -mulrA -PoszM big_distrr /= mulrCA mulrA -sgzM.
rewrite -lead_coefZ; congr (_ * _%:Z); rewrite size_scale //.
by apply: eq_bigr => i _; rewrite coefZ abszM.
Qed.
Lemma zcontents_monic p : p \is monic -> zcontents p = 1.
Proof.
move=> mon_p; rewrite /zcontents polySpred ?monic_neq0 //.
by rewrite big_ord_recr /= -lead_coefE (monicP mon_p) gcdn1.
Qed.
Lemma dvdz_contents a p : (a %| zcontents p)%Z = (p \is a polyOver (dvdz a)).
Proof.
rewrite dvdzE abszM absz_sg lead_coef_eq0.
have [-> | nz_p] := eqVneq; first by rewrite mul0n dvdn0 rpred0.
rewrite mul1n; apply/dvdn_biggcdP/(all_nthP 0)=> a_dv_p i ltip /=.
exact: (a_dv_p (Ordinal ltip)).
exact: a_dv_p.
Qed.
Lemma map_poly_divzK {a} p :
p \is a polyOver (dvdz a) -> a *: map_poly (divz^~ a) p = p.
Proof.
move/polyOverP=> a_dv_p; apply/polyP=> i.
by rewrite coefZ coef_map_id0 ?div0z // mulrC divzK.
Qed.
Lemma polyOver_dvdzP a p :
reflect (exists q, p = a *: q) (p \is a polyOver (dvdz a)).
Proof.
apply: (iffP idP) => [/map_poly_divzK | [q ->]].
by exists (map_poly (divz^~ a) p).
by apply/polyOverP=> i; rewrite coefZ dvdz_mulr.
Qed.
Definition zprimitive p := map_poly (divz^~ (zcontents p)) p.
Lemma zpolyEprim p : p = zcontents p *: zprimitive p.
Proof. by rewrite map_poly_divzK // -dvdz_contents. Qed.
Lemma zprimitive0 : zprimitive 0 = 0.
Proof.
by apply/polyP=> i; rewrite coef0 coef_map_id0 ?div0z // zcontents0 divz0.
Qed.
Lemma zprimitive_eq0 p : (zprimitive p == 0) = (p == 0).
Proof.
apply/idP/idP=> /eqP p0; first by rewrite [p]zpolyEprim p0 scaler0.
by rewrite p0 zprimitive0.
Qed.
Lemma size_zprimitive p : size (zprimitive p) = size p.
Proof.
have [-> | ] := eqVneq p 0; first by rewrite zprimitive0.
by rewrite {1 3}[p]zpolyEprim scale_poly_eq0 => /norP[/size_scale-> _].
Qed.
Lemma sgz_lead_primitive p : sgz (lead_coef (zprimitive p)) = (p != 0).
Proof.
have [-> | nz_p] := eqVneq; first by rewrite zprimitive0 lead_coef0.
apply: (@mulfI _ (sgz (zcontents p))); first by rewrite sgz_eq0 zcontents_eq0.
by rewrite -sgzM mulr1 -lead_coefZ -zpolyEprim sgz_contents.
Qed.
Lemma zcontents_primitive p : zcontents (zprimitive p) = (p != 0).
Proof.
have [-> | nz_p] := eqVneq; first by rewrite zprimitive0 zcontents0.
apply: (@mulfI _ (zcontents p)); first by rewrite zcontents_eq0.
by rewrite mulr1 -zcontentsZ -zpolyEprim.
Qed.
Lemma zprimitive_id p : zprimitive (zprimitive p) = zprimitive p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !zprimitive0.
by rewrite {2}[zprimitive p]zpolyEprim zcontents_primitive nz_p scale1r.
Qed.
Lemma zprimitive_monic p : p \in monic -> zprimitive p = p.
Proof. by move=> mon_p; rewrite {2}[p]zpolyEprim zcontents_monic ?scale1r. Qed.
Lemma zprimitiveZ a p : a != 0 -> zprimitive (a *: p) = zprimitive p.
Proof.
have [-> | nz_p nz_a] := eqVneq p 0; first by rewrite scaler0.
apply: (@mulfI _ (a * zcontents p)%:P).
by rewrite polyC_eq0 mulf_neq0 ?zcontents_eq0.
by rewrite -{1}zcontentsZ !mul_polyC -zpolyEprim -scalerA -zpolyEprim.
Qed.
Lemma zprimitive_min p a q :
p != 0 -> p = a *: q ->
{b | sgz b = sgz (lead_coef q) & q = b *: zprimitive p}.
Proof.
move=> nz_p Dp; have /dvdzP/sig_eqW[b Db]: (a %| zcontents p)%Z.
by rewrite dvdz_contents; apply/polyOver_dvdzP; exists q.
suffices ->: q = b *: zprimitive p.
by rewrite lead_coefZ sgzM sgz_lead_primitive nz_p mulr1; exists b.
apply: (@mulfI _ a%:P).
by apply: contraNneq nz_p; rewrite Dp -mul_polyC => ->; rewrite mul0r.
by rewrite !mul_polyC -Dp scalerA mulrC -Db -zpolyEprim.
Qed.
Lemma zprimitive_irr p a q :
p != 0 -> zprimitive p = a *: q -> a = sgz (lead_coef q).
Proof.
move=> nz_p Dp; have: p = (a * zcontents p) *: q.
by rewrite mulrC -scalerA -Dp -zpolyEprim.
case/zprimitive_min=> // b <- /eqP.
rewrite Dp -{1}[q]scale1r scalerA -subr_eq0 -scalerBl scale_poly_eq0 subr_eq0.
have{Dp} /negPf->: q != 0.
by apply: contraNneq nz_p; rewrite -zprimitive_eq0 Dp => ->; rewrite scaler0.
by case: b a => [[|[|b]] | [|b]] [[|[|a]] | [|a]] //; rewrite mulr0.
Qed.
Lemma zcontentsM p q : zcontents (p * q) = zcontents p * zcontents q.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(mul0r, zcontents0).
have [-> | nz_q] := eqVneq q 0; first by rewrite !(mulr0, zcontents0).
rewrite -[zcontents q]mulr1 {1}[p]zpolyEprim {1}[q]zpolyEprim.
rewrite -scalerAl -scalerAr !zcontentsZ; congr (_ * (_ * _)).
rewrite [zcontents _]intEsg sgz_contents lead_coefM sgzM !sgz_lead_primitive.
apply/eqP; rewrite nz_p nz_q !mul1r [_ == _]eqn_leq absz_gt0 zcontents_eq0.
rewrite mulf_neq0 ?zprimitive_eq0 // andbT leqNgt.
apply/negP=> /pdivP[r r_pr r_dv_d]; pose to_r : int -> 'F_r := intr.
have nz_prim_r q1: q1 != 0 -> map_poly to_r (zprimitive q1) != 0.
move=> nz_q1; apply: contraTneq (prime_gt1 r_pr) => r_dv_q1.
rewrite -leqNgt dvdn_leq // -(dvdzE r true) -nz_q1 -zcontents_primitive.
rewrite dvdz_contents; apply/polyOverP=> i /=; rewrite dvdzE /=.
have /polyP/(_ i)/eqP := r_dv_q1; rewrite coef_map coef0 /=.
rewrite {1}[_`_i]intEsign rmorphM /= rmorph_sign /= mulf_eq0 signr_eq0 /=.
by rewrite -val_eqE /= val_Fp_nat.
suffices{nz_prim_r} /idPn[]: map_poly to_r (zprimitive p * zprimitive q) == 0.
by rewrite rmorphM mulf_neq0 ?nz_prim_r.
rewrite [_ * _]zpolyEprim [zcontents _]intEsign mulrC -scalerA map_polyZ /=.
by rewrite scale_poly_eq0 -val_eqE /= val_Fp_nat ?(eqnP r_dv_d).
Qed.
Lemma zprimitiveM p q : zprimitive (p * q) = zprimitive p * zprimitive q.
Proof.
have [pq_0|] := eqVneq (p * q) 0.
rewrite pq_0; move/eqP: pq_0; rewrite mulf_eq0.
by case/pred2P=> ->; rewrite !zprimitive0 (mul0r, mulr0).
rewrite -zcontents_eq0 -polyC_eq0 => /mulfI; apply; rewrite !mul_polyC.
by rewrite -zpolyEprim zcontentsM -scalerA scalerAr scalerAl -!zpolyEprim.
Qed.
Lemma dvdpP_int p q : p %| q -> {r | q = zprimitive p * r}.
Proof.
case/Pdiv.Idomain.dvdpP/sig2_eqW=> [[c r] /= nz_c Dpr].
exists (zcontents q *: zprimitive r); rewrite -scalerAr.
by rewrite -zprimitiveM mulrC -Dpr zprimitiveZ // -zpolyEprim.
Qed.
End ZpolyScale.
(* Integral spans. *)
Lemma int_Smith_normal_form m n (M : 'M[int]_(m, n)) :
{L : 'M[int]_m & L \in unitmx &
{R : 'M[int]_n & R \in unitmx &
{d : seq int | sorted dvdz d &
M = L *m (\matrix_(i, j) (d`_i *+ (i == j :> nat))) *m R}}}.
Proof.
move: {2}_.+1 (ltnSn (m + n)) => mn.
elim: mn => // mn IHmn in m n M *; rewrite ltnS => le_mn.
have [[i j] nzMij | no_ij] := pickP (fun k => M k.1 k.2 != 0); last first.
do 2![exists 1%:M; first exact: unitmx1]; exists nil => //=.
apply/matrixP=> i j; apply/eqP; rewrite mulmx1 mul1mx mxE nth_nil mul0rn.
exact: negbFE (no_ij (i, j)).
do [case: m i => [[]//|m] i; case: n j => [[]//|n] j /=] in M nzMij le_mn *.
wlog Dj: j M nzMij / j = 0; last rewrite {j}Dj in nzMij.
case/(_ 0 (xcol j 0 M)); rewrite ?mxE ?tpermR // => L uL [R uR [d dvD dM]].
exists L => //; exists (xcol j 0 R); last exists d => //=.
by rewrite xcolE unitmx_mul uR unitmx_perm.
by rewrite xcolE !mulmxA -dM xcolE -mulmxA -perm_mxM tperm2 perm_mx1 mulmx1.
move Da: (M i 0) nzMij => a nz_a.
have [A leA] := ubnP `|a|; elim: A => // A IHa in a leA m n M i Da nz_a le_mn *.
wlog [j a'Mij]: m n M i Da le_mn / {j | ~~ (a %| M i j)%Z}; last first.
have nz_j: j != 0 by apply: contraNneq a'Mij => ->; rewrite Da.
case: n => [[[]//]|n] in j le_mn nz_j M a'Mij Da *.
wlog{nz_j} Dj: j M a'Mij Da / j = 1; last rewrite {j}Dj in a'Mij.
case/(_ 1 (xcol j 1 M)); rewrite ?mxE ?tpermR ?tpermD //.
move=> L uL [R uR [d dvD dM]]; exists L => //.
exists (xcol j 1 R); first by rewrite xcolE unitmx_mul uR unitmx_perm.
exists d; rewrite //= xcolE !mulmxA -dM xcolE -mulmxA -perm_mxM tperm2.
by rewrite perm_mx1 mulmx1.
have [u [v]] := Bezoutz a (M i 1); set b := gcdz _ _ => Db.
have{leA} ltA: (`|b| < A)%N.
rewrite -ltnS (leq_trans _ leA) // ltnS ltn_neqAle andbC.
rewrite dvdn_leq ?absz_gt0 ? dvdn_gcdl //=.
by rewrite (contraNneq _ a'Mij) ?dvdzE // => <-; apply: dvdn_gcdr.
pose t2 := [fun j : 'I_2 => [tuple _; _]`_j : int]; pose a1 := M i 1.
pose Uul := \matrix_(k, j) t2 (t2 u (- (a1 %/ b)%Z) j) (t2 v (a %/ b)%Z j) k.
pose U : 'M_(2 + n) := block_mx Uul 0 0 1%:M; pose M1 := M *m U.
have{nz_a} nz_b: b != 0 by rewrite gcdz_eq0 (negPf nz_a).
have uU: U \in unitmx.
rewrite unitmxE det_ublock det1 (expand_det_col _ 0) big_ord_recl big_ord1.
do 2!rewrite /cofactor [row' _ _]mx11_scalar !mxE det_scalar1 /=.
rewrite mulr1 mul1r mulN1r opprK -[_ + _](mulzK _ nz_b) mulrDl.
by rewrite -!mulrA !divzK ?dvdz_gcdl ?dvdz_gcdr // Db divzz nz_b unitr1.
have{} Db: M1 i 0 = b.
rewrite /M1 -(lshift0 n 1) [U]block_mxEh mul_mx_row row_mxEl.
rewrite -[M](@hsubmxK _ _ 2) (@mul_row_col _ _ 2) mulmx0 addr0 !mxE /=.
rewrite big_ord_recl big_ord1 !mxE /= [lshift _ _]((_ =P 0) _) // Da.
by rewrite [lshift _ _]((_ =P 1) _) // mulrC -(mulrC v).
have [L uL [R uR [d dvD dM1]]] := IHa b ltA _ _ M1 i Db nz_b le_mn.
exists L => //; exists (R *m invmx U); last exists d => //.
by rewrite unitmx_mul uR unitmx_inv.
by rewrite mulmxA -dM1 mulmxK.
move=> {A leA}IHa; wlog Di: i M Da / i = 0; last rewrite {i}Di in Da.
case/(_ 0 (xrow i 0 M)); rewrite ?mxE ?tpermR // => L uL [R uR [d dvD dM]].
exists (xrow i 0 L); first by rewrite xrowE unitmx_mul unitmx_perm.
exists R => //; exists d; rewrite //= xrowE -!mulmxA (mulmxA L) -dM xrowE.
by rewrite mulmxA -perm_mxM tperm2 perm_mx1 mul1mx.
without loss /forallP a_dvM0: / [forall j, a %| M 0%R j]%Z.
case: (altP forallP) => [_ IH|/forallPn/sigW/IHa IH _]; exact: IH.
without loss{Da a_dvM0} Da: M / forall j, M 0 j = a.
pose Uur := col' 0 (\row_j (1 - (M 0%R j %/ a)%Z)).
pose U : 'M_(1 + n) := block_mx 1 Uur 0 1%:M; pose M1 := M *m U.
have uU: U \in unitmx by rewrite unitmxE det_ublock !det1 mulr1.
case/(_ (M *m U)) => [j | L uL [R uR [d dvD dM]]].
rewrite -(lshift0 m 0) -[M](@submxK _ 1 _ 1) (@mulmx_block _ 1 m 1).
rewrite (@col_mxEu _ 1) !mulmx1 mulmx0 addr0 [ulsubmx _]mx11_scalar.
rewrite mul_scalar_mx !mxE !lshift0 Da.
case: splitP => [j0 _ | j1 Dj]; rewrite ?ord1 !mxE // lshift0 rshift1.
by rewrite mulrBr mulr1 mulrC divzK ?subrK.
exists L => //; exists (R * U^-1); first by rewrite unitmx_mul uR unitmx_inv.
by exists d; rewrite //= mulmxA -dM mulmxK.
without loss{IHa} /forallP/(_ (_, _))/= a_dvM: / [forall k, a %| M k.1 k.2]%Z.
case: (altP forallP) => [_|/forallPn/sigW [[i j] /= a'Mij] _]; first exact.
have [|||L uL [R uR [d dvD dM]]] := IHa _ _ M^T j; rewrite ?mxE 1?addnC //.
by exists i; rewrite mxE.
exists R^T; last exists L^T; rewrite ?unitmx_tr //; exists d => //.
rewrite -[M]trmxK dM !trmx_mul mulmxA; congr (_ *m _ *m _).
by apply/matrixP=> i1 j1 /[!mxE]; case: eqVneq => // ->.
without loss{nz_a a_dvM} a1: M a Da / a = 1.
pose M1 := map_mx (divz^~ a) M; case/(_ M1 1)=> // [k|L uL [R uR [d dvD dM]]].
by rewrite !mxE Da divzz nz_a.
exists L => //; exists R => //; exists [seq a * x | x <- d].
case: d dvD {dM} => //= x d; elim: d x => //= y d IHd x /andP[dv_xy /IHd].
by rewrite [dvdz _ _]dvdz_mul2l ?[_ \in _]dv_xy.
have ->: M = a *: M1 by apply/matrixP=> i j; rewrite !mxE mulrC divzK ?a_dvM.
rewrite dM scalemxAl scalemxAr; congr (_ *m _ *m _).
apply/matrixP=> i j; rewrite !mxE mulrnAr; congr (_ *+ _).
have [lt_i_d | le_d_i] := ltnP i (size d); first by rewrite (nth_map 0).
by rewrite !nth_default ?size_map ?mulr0.
rewrite {a}a1 -[m.+1]/(1 + m)%N -[n.+1]/(1 + n)%N in M Da *.
pose Mu := ursubmx M; pose Ml := dlsubmx M.
have{} Da: ulsubmx M = 1 by rewrite [_ M]mx11_scalar !mxE !lshift0 Da.
pose M1 := - (Ml *m Mu) + drsubmx M.
have [|L uL [R uR [d dvD dM1]]] := IHmn m n M1; first by rewrite -addnS ltnW.
exists (block_mx 1 0 Ml L).
by rewrite unitmxE det_lblock det_scalar1 mul1r.
exists (block_mx 1 Mu 0 R).
by rewrite unitmxE det_ublock det_scalar1 mul1r.
exists (1 :: d); set D1 := \matrix_(i, j) _ in dM1.
by rewrite /= path_min_sorted //; apply/allP => g _; apply: dvd1n.
rewrite [D in _ *m D *m _](_ : _ = block_mx 1 0 0 D1); last first.
by apply/matrixP=> i j; do 3?[rewrite ?mxE ?ord1 //=; case: splitP => ? ->].
rewrite !mulmx_block !(mul0mx, mulmx0, addr0) !mulmx1 add0r mul1mx -Da -dM1.
by rewrite addNKr submxK.
Qed.
|
RCLike.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.Analysis.RCLike.Lemmas
import Mathlib.MeasureTheory.Constructions.BorelSpace.Complex
/-!
# Measurability of the basic `RCLike` functions
-/
noncomputable section
open NNReal ENNReal
namespace RCLike
variable {𝕜 : Type*} [RCLike 𝕜]
@[measurability]
theorem measurable_re : Measurable (re : 𝕜 → ℝ) :=
continuous_re.measurable
@[measurability]
theorem measurable_im : Measurable (im : 𝕜 → ℝ) :=
continuous_im.measurable
end RCLike
section RCLikeComposition
variable {α 𝕜 : Type*} [RCLike 𝕜] {m : MeasurableSpace α} {f : α → 𝕜}
{μ : MeasureTheory.Measure α}
@[measurability, fun_prop]
theorem Measurable.re (hf : Measurable f) : Measurable fun x => RCLike.re (f x) :=
RCLike.measurable_re.comp hf
@[measurability, fun_prop]
theorem AEMeasurable.re (hf : AEMeasurable f μ) : AEMeasurable (fun x => RCLike.re (f x)) μ :=
RCLike.measurable_re.comp_aemeasurable hf
@[measurability, fun_prop]
theorem Measurable.im (hf : Measurable f) : Measurable fun x => RCLike.im (f x) :=
RCLike.measurable_im.comp hf
@[measurability, fun_prop]
theorem AEMeasurable.im (hf : AEMeasurable f μ) : AEMeasurable (fun x => RCLike.im (f x)) μ :=
RCLike.measurable_im.comp_aemeasurable hf
end RCLikeComposition
section
variable {α 𝕜 : Type*} [RCLike 𝕜] [MeasurableSpace α] {f : α → 𝕜} {μ : MeasureTheory.Measure α}
@[measurability]
theorem RCLike.measurable_ofReal : Measurable ((↑) : ℝ → 𝕜) :=
RCLike.continuous_ofReal.measurable
theorem measurable_of_re_im (hre : Measurable fun x => RCLike.re (f x))
(him : Measurable fun x => RCLike.im (f x)) : Measurable f := by
convert Measurable.add (M := 𝕜) (RCLike.measurable_ofReal.comp hre)
((RCLike.measurable_ofReal.comp him).mul_const RCLike.I)
exact (RCLike.re_add_im _).symm
theorem aemeasurable_of_re_im (hre : AEMeasurable (fun x => RCLike.re (f x)) μ)
(him : AEMeasurable (fun x => RCLike.im (f x)) μ) : AEMeasurable f μ := by
convert AEMeasurable.add (M := 𝕜) (RCLike.measurable_ofReal.comp_aemeasurable hre)
((RCLike.measurable_ofReal.comp_aemeasurable him).mul_const RCLike.I)
exact (RCLike.re_add_im _).symm
end
|
ContinuousFunctions.lean
|
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne, Sébastien Gouëzel
-/
import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace
import Mathlib.MeasureTheory.Function.LpSpace.Basic
import Mathlib.MeasureTheory.Measure.OpenPos
import Mathlib.Topology.ContinuousMap.Compact
/-!
# Continuous functions in Lp space
When `α` is a topological space equipped with a finite Borel measure, there is a bounded linear map
from the normed space of bounded continuous functions (`α →ᵇ E`) to `Lp E p μ`. We construct this
as `BoundedContinuousFunction.toLp`.
-/
open BoundedContinuousFunction MeasureTheory Filter
open scoped ENNReal
variable {α E : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {μ : Measure α}
[TopologicalSpace α] [BorelSpace α] [NormedAddCommGroup E] [SecondCountableTopologyEither α E]
variable (E p μ) in
/-- An additive subgroup of `Lp E p μ`, consisting of the equivalence classes which contain a
bounded continuous representative. -/
def MeasureTheory.Lp.boundedContinuousFunction : AddSubgroup (Lp E p μ) :=
AddSubgroup.addSubgroupOf
((ContinuousMap.toAEEqFunAddHom μ).comp (toContinuousMapAddHom α E)).range (Lp E p μ)
/-- By definition, the elements of `Lp.boundedContinuousFunction E p μ` are the elements of
`Lp E p μ` which contain a bounded continuous representative. -/
theorem MeasureTheory.Lp.mem_boundedContinuousFunction_iff {f : Lp E p μ} :
f ∈ MeasureTheory.Lp.boundedContinuousFunction E p μ ↔
∃ f₀ : α →ᵇ E, f₀.toContinuousMap.toAEEqFun μ = (f : α →ₘ[μ] E) :=
AddSubgroup.mem_addSubgroupOf
namespace BoundedContinuousFunction
variable [IsFiniteMeasure μ]
/-- A bounded continuous function on a finite-measure space is in `Lp`. -/
theorem mem_Lp (f : α →ᵇ E) : f.toContinuousMap.toAEEqFun μ ∈ Lp E p μ := by
refine Lp.mem_Lp_of_ae_bound ‖f‖ ?_
filter_upwards [f.toContinuousMap.coeFn_toAEEqFun μ] with x _
convert f.norm_coe_le_norm x using 2
/-- The `Lp`-norm of a bounded continuous function is at most a constant (depending on the measure
of the whole space) times its sup-norm. -/
theorem Lp_nnnorm_le (f : α →ᵇ E) :
‖(⟨f.toContinuousMap.toAEEqFun μ, mem_Lp f⟩ : Lp E p μ)‖₊ ≤
measureUnivNNReal μ ^ p.toReal⁻¹ * ‖f‖₊ := by
apply Lp.nnnorm_le_of_ae_bound
refine (f.toContinuousMap.coeFn_toAEEqFun μ).mono ?_
intro x hx
rw [← NNReal.coe_le_coe, coe_nnnorm, coe_nnnorm]
convert f.norm_coe_le_norm x using 2
/-- The `Lp`-norm of a bounded continuous function is at most a constant (depending on the measure
of the whole space) times its sup-norm. -/
theorem Lp_norm_le (f : α →ᵇ E) :
‖(⟨f.toContinuousMap.toAEEqFun μ, mem_Lp f⟩ : Lp E p μ)‖ ≤
measureUnivNNReal μ ^ p.toReal⁻¹ * ‖f‖ :=
Lp_nnnorm_le f
variable (p μ)
/-- The normed group homomorphism of considering a bounded continuous function on a finite-measure
space as an element of `Lp`. -/
def toLpHom [Fact (1 ≤ p)] : NormedAddGroupHom (α →ᵇ E) (Lp E p μ) :=
{ AddMonoidHom.codRestrict ((ContinuousMap.toAEEqFunAddHom μ).comp (toContinuousMapAddHom α E))
(Lp E p μ) mem_Lp with
bound' := ⟨_, Lp_norm_le⟩ }
theorem range_toLpHom [Fact (1 ≤ p)] :
((toLpHom p μ).range : AddSubgroup (Lp E p μ)) =
MeasureTheory.Lp.boundedContinuousFunction E p μ := by
symm
exact AddMonoidHom.addSubgroupOf_range_eq_of_le
((ContinuousMap.toAEEqFunAddHom μ).comp (toContinuousMapAddHom α E))
(by rintro - ⟨f, rfl⟩; exact mem_Lp f : _ ≤ Lp E p μ)
variable (𝕜 : Type*) [Fact (1 ≤ p)] [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
/-- The bounded linear map of considering a bounded continuous function on a finite-measure space
as an element of `Lp`. -/
noncomputable def toLp : (α →ᵇ E) →L[𝕜] Lp E p μ :=
LinearMap.mkContinuous
(LinearMap.codRestrict (Lp.LpSubmodule 𝕜 E p μ)
((ContinuousMap.toAEEqFunLinearMap μ).comp (toContinuousMapLinearMap α E 𝕜)) mem_Lp)
_ Lp_norm_le
theorem coeFn_toLp (f : α →ᵇ E) :
toLp (E := E) p μ 𝕜 f =ᵐ[μ] f :=
AEEqFun.coeFn_mk f _
variable {𝕜}
theorem range_toLp :
(LinearMap.range (toLp p μ 𝕜 : (α →ᵇ E) →L[𝕜] Lp E p μ)).toAddSubgroup =
MeasureTheory.Lp.boundedContinuousFunction E p μ :=
range_toLpHom p μ
variable {p}
theorem toLp_norm_le {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] :
‖(toLp p μ 𝕜 : (α →ᵇ E) →L[𝕜] Lp E p μ)‖ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ :=
LinearMap.mkContinuous_norm_le _ (measureUnivNNReal μ ^ p.toReal⁻¹).coe_nonneg _
theorem toLp_inj {f g : α →ᵇ E} [μ.IsOpenPosMeasure] :
toLp (E := E) p μ 𝕜 f = toLp (E := E) p μ 𝕜 g ↔ f = g := by
refine ⟨fun h => ?_, by tauto⟩
rw [← DFunLike.coe_fn_eq, ← (map_continuous f).ae_eq_iff_eq μ (map_continuous g)]
refine (coeFn_toLp p μ 𝕜 f).symm.trans (EventuallyEq.trans ?_ <| coeFn_toLp p μ 𝕜 g)
rw [h]
theorem toLp_injective [μ.IsOpenPosMeasure] :
Function.Injective (⇑(toLp p μ 𝕜 : (α →ᵇ E) →L[𝕜] Lp E p μ)) :=
fun _f _g hfg => (toLp_inj μ).mp hfg
end BoundedContinuousFunction
namespace ContinuousMap
variable [CompactSpace α] [IsFiniteMeasure μ]
variable (𝕜 : Type*) (p μ) [Fact (1 ≤ p)]
[NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
/-- The bounded linear map of considering a continuous function on a compact finite-measure
space `α` as an element of `Lp`. By definition, the norm on `C(α, E)` is the sup-norm, transferred
from the space `α →ᵇ E` of bounded continuous functions, so this construction is just a matter of
transferring the structure from `BoundedContinuousFunction.toLp` along the isometry. -/
noncomputable def toLp : C(α, E) →L[𝕜] Lp E p μ :=
(BoundedContinuousFunction.toLp p μ 𝕜).comp
(linearIsometryBoundedOfCompact α E 𝕜).toLinearIsometry.toContinuousLinearMap
variable {𝕜}
theorem range_toLp :
(LinearMap.range (toLp p μ 𝕜 : C(α, E) →L[𝕜] Lp E p μ)).toAddSubgroup =
MeasureTheory.Lp.boundedContinuousFunction E p μ := by
refine SetLike.ext' ?_
have := (linearIsometryBoundedOfCompact α E 𝕜).surjective
convert Function.Surjective.range_comp this (BoundedContinuousFunction.toLp (E := E) p μ 𝕜)
rw [← BoundedContinuousFunction.range_toLp p μ (𝕜 := 𝕜), Submodule.coe_toAddSubgroup,
LinearMap.range_coe]
variable {p}
theorem coeFn_toLp (f : C(α, E)) :
toLp (E := E) p μ 𝕜 f =ᵐ[μ] f :=
AEEqFun.coeFn_mk f _
theorem toLp_def (f : C(α, E)) :
toLp (E := E) p μ 𝕜 f =
BoundedContinuousFunction.toLp (E := E) p μ 𝕜 (linearIsometryBoundedOfCompact α E 𝕜 f) :=
rfl
@[simp]
theorem toLp_comp_toContinuousMap (f : α →ᵇ E) :
toLp (E := E) p μ 𝕜 f.toContinuousMap = BoundedContinuousFunction.toLp (E := E) p μ 𝕜 f :=
rfl
@[simp]
theorem coe_toLp (f : C(α, E)) :
(toLp (E := E) p μ 𝕜 f : α →ₘ[μ] E) = f.toAEEqFun μ :=
rfl
theorem toLp_injective [μ.IsOpenPosMeasure] :
Function.Injective (⇑(toLp p μ 𝕜 : C(α, E) →L[𝕜] Lp E p μ)) :=
(BoundedContinuousFunction.toLp_injective _).comp (linearIsometryBoundedOfCompact α E 𝕜).injective
theorem toLp_inj {f g : C(α, E)} [μ.IsOpenPosMeasure] :
toLp (E := E) p μ 𝕜 f = toLp (E := E) p μ 𝕜 g ↔ f = g :=
(toLp_injective μ).eq_iff
variable {μ}
/-- If a sum of continuous functions `g n` is convergent, and the same sum converges in `Lᵖ` to `h`,
then in fact `g n` converges uniformly to `h`. -/
theorem hasSum_of_hasSum_Lp {β : Type*} [μ.IsOpenPosMeasure]
{g : β → C(α, E)} {f : C(α, E)} (hg : Summable g)
(hg2 : HasSum (toLp (E := E) p μ 𝕜 ∘ g) (toLp (E := E) p μ 𝕜 f)) : HasSum g f := by
convert Summable.hasSum hg
exact toLp_injective μ (hg2.unique ((toLp p μ 𝕜).hasSum <| Summable.hasSum hg))
variable (μ) {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E]
theorem toLp_norm_eq_toLp_norm_coe :
‖(toLp p μ 𝕜 : C(α, E) →L[𝕜] Lp E p μ)‖ =
‖(BoundedContinuousFunction.toLp p μ 𝕜 : (α →ᵇ E) →L[𝕜] Lp E p μ)‖ :=
ContinuousLinearMap.opNorm_comp_linearIsometryEquiv _ _
/-- Bound for the operator norm of `ContinuousMap.toLp`. -/
theorem toLp_norm_le :
‖(toLp p μ 𝕜 : C(α, E) →L[𝕜] Lp E p μ)‖ ≤ measureUnivNNReal μ ^ p.toReal⁻¹ := by
rw [toLp_norm_eq_toLp_norm_coe]
exact BoundedContinuousFunction.toLp_norm_le μ
end ContinuousMap
|
Instances.lean
|
/-
Copyright (c) 2024. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: euprunin
-/
import Mathlib.Algebra.Ring.Defs
import Mathlib.RingTheory.NonUnitalSubring.Defs
import Mathlib.RingTheory.TwoSidedIdeal.Basic
/-!
# Additional instances for two sided ideals.
-/
instance {R} [NonUnitalNonAssocRing R] : NonUnitalSubringClass (TwoSidedIdeal R) R where
mul_mem _ hb := TwoSidedIdeal.mul_mem_left _ _ _ hb
|
Quandle.lean
|
/-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Algebra.Group.End
import Mathlib.Data.ZMod.Defs
import Mathlib.Tactic.Ring
/-!
# Racks and Quandles
This file defines racks and quandles, algebraic structures for sets
that bijectively act on themselves with a self-distributivity
property. If `R` is a rack and `act : R → (R ≃ R)` is the self-action,
then the self-distributivity is, equivalently, that
```
act (act x y) = act x * act y * (act x)⁻¹
```
where multiplication is composition in `R ≃ R` as a group.
Quandles are racks such that `act x x = x` for all `x`.
One example of a quandle (not yet in mathlib) is the action of a Lie
algebra on itself, defined by `act x y = Ad (exp x) y`.
Quandles and racks were independently developed by multiple
mathematicians. David Joyce introduced quandles in his thesis
[Joyce1982] to define an algebraic invariant of knot and link
complements that is analogous to the fundamental group of the
exterior, and he showed that the quandle associated to an oriented
knot is invariant up to orientation-reversed mirror image. Racks were
used by Fenn and Rourke for framed codimension-2 knots and
links in [FennRourke1992]. Unital shelves are discussed in [crans2017].
The name "rack" came from wordplay by Conway and Wraith for the "wrack
and ruin" of forgetting everything but the conjugation operation for a
group.
## Main definitions
* `Shelf` is a type with a self-distributive action
* `UnitalShelf` is a shelf with a left and right unit
* `Rack` is a shelf whose action for each element is invertible
* `Quandle` is a rack whose action for an element fixes that element
* `Quandle.conj` defines a quandle of a group acting on itself by conjugation.
* `ShelfHom` is homomorphisms of shelves, racks, and quandles.
* `Rack.EnvelGroup` gives the universal group the rack maps to as a conjugation quandle.
* `Rack.oppositeRack` gives the rack with the action replaced by its inverse.
## Main statements
* `Rack.EnvelGroup` is left adjoint to `Quandle.Conj` (`toEnvelGroup.map`).
The universality statements are `toEnvelGroup.univ` and `toEnvelGroup.univ_uniq`.
## Implementation notes
"Unital racks" are uninteresting (see `Rack.assoc_iff_id`, `UnitalShelf.assoc`), so we do not
define them.
## Notation
The following notation is localized in `quandles`:
* `x ◃ y` is `Shelf.act x y`
* `x ◃⁻¹ y` is `Rack.inv_act x y`
* `S →◃ S'` is `ShelfHom S S'`
Use `open quandles` to use these.
## TODO
* If `g` is the Lie algebra of a Lie group `G`, then `(x ◃ y) = Ad (exp x) x` forms a quandle.
* If `X` is a symmetric space, then each point has a corresponding involution that acts on `X`,
forming a quandle.
* Alexander quandle with `a ◃ b = t * b + (1 - t) * b`, with `a` and `b` elements
of a module over `Z[t,t⁻¹]`.
* If `G` is a group, `H` a subgroup, and `z` in `H`, then there is a quandle `(G/H;z)` defined by
`yH ◃ xH = yzy⁻¹xH`. Every homogeneous quandle (i.e., a quandle `Q` whose automorphism group acts
transitively on `Q` as a set) is isomorphic to such a quandle.
There is a generalization to this arbitrary quandles in [Joyce's paper (Theorem 7.2)][Joyce1982].
## Tags
rack, quandle
-/
open MulOpposite
universe u v
/-- A *Shelf* is a structure with a self-distributive binary operation.
The binary operation is regarded as a left action of the type on itself.
-/
class Shelf (α : Type u) where
/-- The action of the `Shelf` over `α` -/
act : α → α → α
/-- A verification that `act` is self-distributive -/
self_distrib : ∀ {x y z : α}, act x (act y z) = act (act x y) (act x z)
/--
A *unital shelf* is a shelf equipped with an element `1` such that, for all elements `x`,
we have both `x ◃ 1` and `1 ◃ x` equal `x`.
-/
class UnitalShelf (α : Type u) extends Shelf α, One α where
one_act : ∀ a : α, act 1 a = a
act_one : ∀ a : α, act a 1 = a
/-- The type of homomorphisms between shelves.
This is also the notion of rack and quandle homomorphisms.
-/
@[ext]
structure ShelfHom (S₁ : Type*) (S₂ : Type*) [Shelf S₁] [Shelf S₂] where
/-- The function under the Shelf Homomorphism -/
toFun : S₁ → S₂
/-- The homomorphism property of a Shelf Homomorphism -/
map_act' : ∀ {x y : S₁}, toFun (Shelf.act x y) = Shelf.act (toFun x) (toFun y)
/-- A *rack* is an automorphic set (a set with an action on itself by
bijections) that is self-distributive. It is a shelf such that each
element's action is invertible.
The notations `x ◃ y` and `x ◃⁻¹ y` denote the action and the
inverse action, respectively, and they are right associative.
-/
class Rack (α : Type u) extends Shelf α where
/-- The inverse actions of the elements -/
invAct : α → α → α
/-- Proof of left inverse -/
left_inv : ∀ x, Function.LeftInverse (invAct x) (act x)
/-- Proof of right inverse -/
right_inv : ∀ x, Function.RightInverse (invAct x) (act x)
/-- Action of a Shelf -/
scoped[Quandles] infixr:65 " ◃ " => Shelf.act
/-- Inverse Action of a Rack -/
scoped[Quandles] infixr:65 " ◃⁻¹ " => Rack.invAct
/-- Shelf Homomorphism -/
scoped[Quandles] infixr:25 " →◃ " => ShelfHom
open Quandles
namespace UnitalShelf
open Shelf
variable {S : Type*} [UnitalShelf S]
/--
A monoid is *graphic* if, for all `x` and `y`, the *graphic identity*
`(x * y) * x = x * y` holds. For a unital shelf, this graphic
identity holds.
-/
lemma act_act_self_eq (x y : S) : (x ◃ y) ◃ x = x ◃ y := by
have h : (x ◃ y) ◃ x = (x ◃ y) ◃ (x ◃ 1) := by rw [act_one]
rw [h, ← Shelf.self_distrib, act_one]
lemma act_idem (x : S) : (x ◃ x) = x := by rw [← act_one x, ← Shelf.self_distrib, act_one]
lemma act_self_act_eq (x y : S) : x ◃ (x ◃ y) = x ◃ y := by
have h : x ◃ (x ◃ y) = (x ◃ 1) ◃ (x ◃ y) := by rw [act_one]
rw [h, ← Shelf.self_distrib, one_act]
/--
The associativity of a unital shelf comes for free.
-/
lemma assoc (x y z : S) : (x ◃ y) ◃ z = x ◃ y ◃ z := by
rw [self_distrib, self_distrib, act_act_self_eq, act_self_act_eq]
end UnitalShelf
namespace Rack
variable {R : Type*} [Rack R]
export Shelf (self_distrib)
/-- A rack acts on itself by equivalences. -/
def act' (x : R) : R ≃ R where
toFun := Shelf.act x
invFun := invAct x
left_inv := left_inv x
right_inv := right_inv x
@[simp]
theorem act'_apply (x y : R) : act' x y = x ◃ y :=
rfl
@[simp]
theorem act'_symm_apply (x y : R) : (act' x).symm y = x ◃⁻¹ y :=
rfl
@[simp]
theorem invAct_apply (x y : R) : (act' x)⁻¹ y = x ◃⁻¹ y :=
rfl
@[simp]
theorem invAct_act_eq (x y : R) : x ◃⁻¹ x ◃ y = y :=
left_inv x y
@[simp]
theorem act_invAct_eq (x y : R) : x ◃ x ◃⁻¹ y = y :=
right_inv x y
theorem left_cancel (x : R) {y y' : R} : x ◃ y = x ◃ y' ↔ y = y' := by
constructor
· apply (act' x).injective
rintro rfl
rfl
theorem left_cancel_inv (x : R) {y y' : R} : x ◃⁻¹ y = x ◃⁻¹ y' ↔ y = y' := by
constructor
· apply (act' x).symm.injective
rintro rfl
rfl
theorem self_distrib_inv {x y z : R} : x ◃⁻¹ y ◃⁻¹ z = (x ◃⁻¹ y) ◃⁻¹ x ◃⁻¹ z := by
rw [← left_cancel (x ◃⁻¹ y), right_inv, ← left_cancel x, right_inv, self_distrib]
repeat' rw [right_inv]
/-- The *adjoint action* of a rack on itself is `op'`, and the adjoint
action of `x ◃ y` is the conjugate of the action of `y` by the action
of `x`. It is another way to understand the self-distributivity axiom.
This is used in the natural rack homomorphism `toConj` from `R` to
`Conj (R ≃ R)` defined by `op'`.
-/
theorem ad_conj {R : Type*} [Rack R] (x y : R) : act' (x ◃ y) = act' x * act' y * (act' x)⁻¹ := by
rw [eq_mul_inv_iff_mul_eq]; ext z
apply self_distrib.symm
/-- The opposite rack, swapping the roles of `◃` and `◃⁻¹`.
-/
instance oppositeRack : Rack Rᵐᵒᵖ where
act x y := op (invAct (unop x) (unop y))
self_distrib := by
intro x y z
induction x
induction y
induction z
simp only [op_inj, unop_op]
rw [self_distrib_inv]
invAct x y := op (Shelf.act (unop x) (unop y))
left_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp
right_inv := MulOpposite.rec' fun x => MulOpposite.rec' fun y => by simp
@[simp]
theorem op_act_op_eq {x y : R} : op x ◃ op y = op (x ◃⁻¹ y) :=
rfl
@[simp]
theorem op_invAct_op_eq {x y : R} : op x ◃⁻¹ op y = op (x ◃ y) :=
rfl
@[simp]
theorem self_act_act_eq {x y : R} : (x ◃ x) ◃ y = x ◃ y := by rw [← right_inv x y, ← self_distrib]
@[simp]
theorem self_invAct_invAct_eq {x y : R} : (x ◃⁻¹ x) ◃⁻¹ y = x ◃⁻¹ y := by
have h := @self_act_act_eq _ _ (op x) (op y)
simpa using h
@[simp]
theorem self_act_invAct_eq {x y : R} : (x ◃ x) ◃⁻¹ y = x ◃⁻¹ y := by
rw [← left_cancel (x ◃ x)]
rw [right_inv]
rw [self_act_act_eq]
rw [right_inv]
@[simp]
theorem self_invAct_act_eq {x y : R} : (x ◃⁻¹ x) ◃ y = x ◃ y := by
have h := @self_act_invAct_eq _ _ (op x) (op y)
simpa using h
theorem self_act_eq_iff_eq {x y : R} : x ◃ x = y ◃ y ↔ x = y := by
constructor; swap
· rintro rfl; rfl
intro h
trans (x ◃ x) ◃⁻¹ x ◃ x
· rw [← left_cancel (x ◃ x), right_inv, self_act_act_eq]
· rw [h, ← left_cancel (y ◃ y), right_inv, self_act_act_eq]
theorem self_invAct_eq_iff_eq {x y : R} : x ◃⁻¹ x = y ◃⁻¹ y ↔ x = y := by
have h := @self_act_eq_iff_eq _ _ (op x) (op y)
simpa using h
/-- The map `x ↦ x ◃ x` is a bijection. (This has applications for the
regular isotopy version of the Reidemeister I move for knot diagrams.)
-/
def selfApplyEquiv (R : Type*) [Rack R] : R ≃ R where
toFun x := x ◃ x
invFun x := x ◃⁻¹ x
left_inv x := by simp
right_inv x := by simp
/-- An involutory rack is one for which `Rack.oppositeRack R x` is an involution for every x.
-/
def IsInvolutory (R : Type*) [Rack R] : Prop :=
∀ x : R, Function.Involutive (Shelf.act x)
theorem involutory_invAct_eq_act {R : Type*} [Rack R] (h : IsInvolutory R) (x y : R) :
x ◃⁻¹ y = x ◃ y := by
rw [← left_cancel x, right_inv, h x]
/-- An abelian rack is one for which the mediality axiom holds.
-/
def IsAbelian (R : Type*) [Rack R] : Prop :=
∀ x y z w : R, (x ◃ y) ◃ z ◃ w = (x ◃ z) ◃ y ◃ w
/-- Associative racks are uninteresting.
-/
theorem assoc_iff_id {R : Type*} [Rack R] {x y z : R} : x ◃ y ◃ z = (x ◃ y) ◃ z ↔ x ◃ z = z := by
rw [self_distrib]
rw [left_cancel]
end Rack
namespace ShelfHom
variable {S₁ : Type*} {S₂ : Type*} {S₃ : Type*} [Shelf S₁] [Shelf S₂] [Shelf S₃]
instance : FunLike (S₁ →◃ S₂) S₁ S₂ where
coe := toFun
coe_injective' | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
@[simp] theorem toFun_eq_coe (f : S₁ →◃ S₂) : f.toFun = f := rfl
@[simp]
theorem map_act (f : S₁ →◃ S₂) {x y : S₁} : f (x ◃ y) = f x ◃ f y :=
map_act' f
/-- The identity homomorphism -/
def id (S : Type*) [Shelf S] : S →◃ S where
toFun := fun x => x
map_act' := by simp
instance inhabited (S : Type*) [Shelf S] : Inhabited (S →◃ S) :=
⟨id S⟩
/-- The composition of shelf homomorphisms -/
def comp (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) : S₁ →◃ S₃ where
toFun := g.toFun ∘ f.toFun
map_act' := by simp
@[simp]
theorem comp_apply (g : S₂ →◃ S₃) (f : S₁ →◃ S₂) (x : S₁) : (g.comp f) x = g (f x) :=
rfl
end ShelfHom
/-- A quandle is a rack such that each automorphism fixes its corresponding element.
-/
class Quandle (α : Type*) extends Rack α where
/-- The fixing property of a Quandle -/
fix : ∀ {x : α}, act x x = x
namespace Quandle
open Rack
variable {Q : Type*} [Quandle Q]
attribute [simp] fix
@[simp]
theorem fix_inv {x : Q} : x ◃⁻¹ x = x := by
rw [← left_cancel x]
simp
instance oppositeQuandle : Quandle Qᵐᵒᵖ where
fix := by
intro x
induction x
simp
/-- The conjugation quandle of a group. Each element of the group acts by
the corresponding inner automorphism. -/
abbrev Conj (G : Type*) := G
instance Conj.quandle (G : Type*) [Group G] : Quandle (Conj G) where
act x := @MulAut.conj G _ x
self_distrib := by
intro x y z
dsimp only [MulAut.conj_apply]
simp [mul_assoc]
invAct x := (@MulAut.conj G _ x).symm
left_inv x y := by
simp [mul_assoc]
right_inv x y := by
simp [mul_assoc]
fix := by simp
@[simp]
theorem conj_act_eq_conj {G : Type*} [Group G] (x y : Conj G) :
x ◃ y = ((x : G) * (y : G) * (x : G)⁻¹ : G) :=
rfl
theorem conj_swap {G : Type*} [Group G] (x y : Conj G) : x ◃ y = y ↔ y ◃ x = x := by
dsimp [Conj] at *; constructor
repeat' intro h; conv_rhs => rw [eq_mul_inv_of_mul_eq (eq_mul_inv_of_mul_eq h)]; simp
/-- `Conj` is functorial
-/
def Conj.map {G : Type*} {H : Type*} [Group G] [Group H] (f : G →* H) : Conj G →◃ Conj H where
toFun := f
map_act' := by simp
/-- The dihedral quandle. This is the conjugation quandle of the dihedral group restricted to flips.
Used for Fox n-colorings of knots. -/
def Dihedral (n : ℕ) :=
ZMod n
/-- The operation for the dihedral quandle. It does not need to be an equivalence
because it is an involution (see `dihedralAct.inv`). -/
def dihedralAct (n : ℕ) (a : ZMod n) : ZMod n → ZMod n := fun b => 2 * a - b
theorem dihedralAct.inv (n : ℕ) (a : ZMod n) : Function.Involutive (dihedralAct n a) := by
intro b
dsimp only [dihedralAct]
simp
instance (n : ℕ) : Quandle (Dihedral n) where
act := dihedralAct n
self_distrib := by
intro x y z
simp only [dihedralAct]
ring_nf
invAct := dihedralAct n
left_inv x := (dihedralAct.inv n x).leftInverse
right_inv x := (dihedralAct.inv n x).rightInverse
fix := by
intro x
simp only [dihedralAct]
ring_nf
end Quandle
namespace Rack
/-- This is the natural rack homomorphism to the conjugation quandle of the group `R ≃ R`
that acts on the rack. -/
def toConj (R : Type*) [Rack R] : R →◃ Quandle.Conj (R ≃ R) where
toFun := act'
map_act' := by
intro x y
exact ad_conj x y
section EnvelGroup
/-!
### Universal enveloping group of a rack
The universal enveloping group `EnvelGroup R` of a rack `R` is the
universal group such that every rack homomorphism `R →◃ conj G` is
induced by a unique group homomorphism `EnvelGroup R →* G`.
For quandles, Joyce called this group `AdConj R`.
The `EnvelGroup` functor is left adjoint to the `Conj` forgetful
functor, and the way we construct the enveloping group is via a
technique that should work for left adjoints of forgetful functors in
general. It involves thinking a little about 2-categories, but the
payoff is that the map `EnvelGroup R →* G` has a nice description.
Let's think of a group as being a one-object category. The first step
is to define `PreEnvelGroup`, which gives formal expressions for all
the 1-morphisms and includes the unit element, elements of `R`,
multiplication, and inverses. To introduce relations, the second step
is to define `PreEnvelGroupRel'`, which gives formal expressions
for all 2-morphisms between the 1-morphisms. The 2-morphisms include
associativity, multiplication by the unit, multiplication by inverses,
compatibility with multiplication and inverses (`congr_mul` and
`congr_inv`), the axioms for an equivalence relation, and,
importantly, the relationship between conjugation and the rack action
(see `Rack.ad_conj`).
None of this forms a 2-category yet, for example due to lack of
associativity of `trans`. The `PreEnvelGroupRel` relation is a
`Prop`-valued version of `PreEnvelGroupRel'`, and making it
`Prop`-valued essentially introduces enough 3-isomorphisms so that
every pair of compatible 2-morphisms is isomorphic. Now, while
composition in `PreEnvelGroup` does not strictly satisfy the category
axioms, `PreEnvelGroup` and `PreEnvelGroupRel'` do form a weak
2-category.
Since we just want a 1-category, the last step is to quotient
`PreEnvelGroup` by `PreEnvelGroupRel'`, and the result is the
group `EnvelGroup`.
For a homomorphism `f : R →◃ Conj G`, how does
`EnvelGroup.map f : EnvelGroup R →* G` work? Let's think of `G` as
being a 2-category with one object, a 1-morphism per element of `G`,
and a single 2-morphism called `Eq.refl` for each 1-morphism. We
define the map using a "higher `Quotient.lift`" -- not only do we
evaluate elements of `PreEnvelGroup` as expressions in `G` (this is
`toEnvelGroup.mapAux`), but we evaluate elements of
`PreEnvelGroup'` as expressions of 2-morphisms of `G` (this is
`toEnvelGroup.mapAux.well_def`). That is to say,
`toEnvelGroup.mapAux.well_def` recursively evaluates formal
expressions of 2-morphisms as equality proofs in `G`. Now that all
morphisms are accounted for, the map descends to a homomorphism
`EnvelGroup R →* G`.
Note: `Type`-valued relations are not common. The fact it is
`Type`-valued is what makes `toEnvelGroup.mapAux.well_def` have
well-founded recursion.
-/
/-- Free generators of the enveloping group.
-/
inductive PreEnvelGroup (R : Type u) : Type u
| unit : PreEnvelGroup R
| incl (x : R) : PreEnvelGroup R
| mul (a b : PreEnvelGroup R) : PreEnvelGroup R
| inv (a : PreEnvelGroup R) : PreEnvelGroup R
instance PreEnvelGroup.inhabited (R : Type u) : Inhabited (PreEnvelGroup R) :=
⟨PreEnvelGroup.unit⟩
open PreEnvelGroup
/-- Relations for the enveloping group. This is a type-valued relation because
`toEnvelGroup.mapAux.well_def` inducts on it to show `toEnvelGroup.map`
is well-defined. The relation `PreEnvelGroupRel` is the `Prop`-valued version,
which is used to define `EnvelGroup` itself.
-/
inductive PreEnvelGroupRel' (R : Type u) [Rack R] : PreEnvelGroup R → PreEnvelGroup R → Type u
| refl {a : PreEnvelGroup R} : PreEnvelGroupRel' R a a
| symm {a b : PreEnvelGroup R} (hab : PreEnvelGroupRel' R a b) : PreEnvelGroupRel' R b a
| trans {a b c : PreEnvelGroup R} (hab : PreEnvelGroupRel' R a b)
(hbc : PreEnvelGroupRel' R b c) : PreEnvelGroupRel' R a c
| congr_mul {a b a' b' : PreEnvelGroup R} (ha : PreEnvelGroupRel' R a a')
(hb : PreEnvelGroupRel' R b b') : PreEnvelGroupRel' R (mul a b) (mul a' b')
| congr_inv {a a' : PreEnvelGroup R} (ha : PreEnvelGroupRel' R a a') :
PreEnvelGroupRel' R (inv a) (inv a')
| assoc (a b c : PreEnvelGroup R) : PreEnvelGroupRel' R (mul (mul a b) c) (mul a (mul b c))
| one_mul (a : PreEnvelGroup R) : PreEnvelGroupRel' R (mul unit a) a
| mul_one (a : PreEnvelGroup R) : PreEnvelGroupRel' R (mul a unit) a
| inv_mul_cancel (a : PreEnvelGroup R) : PreEnvelGroupRel' R (mul (inv a) a) unit
| act_incl (x y : R) :
PreEnvelGroupRel' R (mul (mul (incl x) (incl y)) (inv (incl x))) (incl (x ◃ y))
instance PreEnvelGroupRel'.inhabited (R : Type u) [Rack R] :
Inhabited (PreEnvelGroupRel' R unit unit) :=
⟨PreEnvelGroupRel'.refl⟩
/--
The `PreEnvelGroupRel` relation as a `Prop`. Used as the relation for `PreEnvelGroup.setoid`.
-/
inductive PreEnvelGroupRel (R : Type u) [Rack R] : PreEnvelGroup R → PreEnvelGroup R → Prop
| rel {a b : PreEnvelGroup R} (r : PreEnvelGroupRel' R a b) : PreEnvelGroupRel R a b
/-- A quick way to convert a `PreEnvelGroupRel'` to a `PreEnvelGroupRel`.
-/
theorem PreEnvelGroupRel'.rel {R : Type u} [Rack R] {a b : PreEnvelGroup R} :
PreEnvelGroupRel' R a b → PreEnvelGroupRel R a b := PreEnvelGroupRel.rel
@[refl]
theorem PreEnvelGroupRel.refl {R : Type u} [Rack R] {a : PreEnvelGroup R} :
PreEnvelGroupRel R a a :=
PreEnvelGroupRel.rel PreEnvelGroupRel'.refl
@[symm]
theorem PreEnvelGroupRel.symm {R : Type u} [Rack R] {a b : PreEnvelGroup R} :
PreEnvelGroupRel R a b → PreEnvelGroupRel R b a
| ⟨r⟩ => r.symm.rel
@[trans]
theorem PreEnvelGroupRel.trans {R : Type u} [Rack R] {a b c : PreEnvelGroup R} :
PreEnvelGroupRel R a b → PreEnvelGroupRel R b c → PreEnvelGroupRel R a c
| ⟨rab⟩, ⟨rbc⟩ => (rab.trans rbc).rel
instance PreEnvelGroup.setoid (R : Type*) [Rack R] : Setoid (PreEnvelGroup R) where
r := PreEnvelGroupRel R
iseqv := by
constructor
· apply PreEnvelGroupRel.refl
· apply PreEnvelGroupRel.symm
· apply PreEnvelGroupRel.trans
/-- The universal enveloping group for the rack R.
-/
def EnvelGroup (R : Type*) [Rack R] :=
Quotient (PreEnvelGroup.setoid R)
-- Define the `Group` instances in two steps so `inv` can be inferred correctly.
-- TODO: is there a non-invasive way of defining the instance directly?
instance (R : Type*) [Rack R] : DivInvMonoid (EnvelGroup R) where
mul a b :=
Quotient.liftOn₂ a b (fun a b => ⟦PreEnvelGroup.mul a b⟧) fun _ _ _ _ ⟨ha⟩ ⟨hb⟩ =>
Quotient.sound (PreEnvelGroupRel'.congr_mul ha hb).rel
one := ⟦unit⟧
inv a :=
Quotient.liftOn a (fun a => ⟦PreEnvelGroup.inv a⟧) fun _ _ ⟨ha⟩ =>
Quotient.sound (PreEnvelGroupRel'.congr_inv ha).rel
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun a b c => Quotient.sound (PreEnvelGroupRel'.assoc a b c).rel
one_mul a := Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.one_mul a).rel
mul_one a := Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.mul_one a).rel
instance (R : Type*) [Rack R] : Group (EnvelGroup R) :=
{ inv_mul_cancel := fun a =>
Quotient.inductionOn a fun a => Quotient.sound (PreEnvelGroupRel'.inv_mul_cancel a).rel }
instance EnvelGroup.inhabited (R : Type*) [Rack R] : Inhabited (EnvelGroup R) :=
⟨1⟩
/-- The canonical homomorphism from a rack to its enveloping group.
Satisfies universal properties given by `toEnvelGroup.map` and `toEnvelGroup.univ`.
-/
def toEnvelGroup (R : Type*) [Rack R] : R →◃ Quandle.Conj (EnvelGroup R) where
toFun x := ⟦incl x⟧
map_act' := @fun x y => Quotient.sound (PreEnvelGroupRel'.act_incl x y).symm.rel
/-- The preliminary definition of the induced map from the enveloping group.
See `toEnvelGroup.map`.
-/
def toEnvelGroup.mapAux {R : Type*} [Rack R] {G : Type*} [Group G] (f : R →◃ Quandle.Conj G) :
PreEnvelGroup R → G
| .unit => 1
| .incl x => f x
| .mul a b => toEnvelGroup.mapAux f a * toEnvelGroup.mapAux f b
| .inv a => (toEnvelGroup.mapAux f a)⁻¹
namespace toEnvelGroup.mapAux
open PreEnvelGroupRel'
/-- Show that `toEnvelGroup.mapAux` sends equivalent expressions to equal terms.
-/
theorem well_def {R : Type*} [Rack R] {G : Type*} [Group G] (f : R →◃ Quandle.Conj G) :
∀ {a b : PreEnvelGroup R},
PreEnvelGroupRel' R a b → toEnvelGroup.mapAux f a = toEnvelGroup.mapAux f b
| _, _, PreEnvelGroupRel'.refl => rfl
| _, _, PreEnvelGroupRel'.symm h => (well_def f h).symm
| _, _, PreEnvelGroupRel'.trans hac hcb => Eq.trans (well_def f hac) (well_def f hcb)
| _, _, PreEnvelGroupRel'.congr_mul ha hb => by
simp [toEnvelGroup.mapAux, well_def f ha, well_def f hb]
| _, _, congr_inv ha => by simp [toEnvelGroup.mapAux, well_def f ha]
| _, _, assoc a b c => by apply mul_assoc
| _, _, PreEnvelGroupRel'.one_mul a => by simp [toEnvelGroup.mapAux]
| _, _, PreEnvelGroupRel'.mul_one a => by simp [toEnvelGroup.mapAux]
| _, _, PreEnvelGroupRel'.inv_mul_cancel a => by simp [toEnvelGroup.mapAux]
| _, _, act_incl x y => by simp [toEnvelGroup.mapAux]
end toEnvelGroup.mapAux
/-- Given a map from a rack to a group, lift it to being a map from the enveloping group.
More precisely, the `EnvelGroup` functor is left adjoint to `Quandle.Conj`.
-/
def toEnvelGroup.map {R : Type*} [Rack R] {G : Type*} [Group G] :
(R →◃ Quandle.Conj G) ≃ (EnvelGroup R →* G) where
toFun f :=
{ toFun := fun x =>
Quotient.liftOn x (toEnvelGroup.mapAux f) fun _ _ ⟨hab⟩ =>
toEnvelGroup.mapAux.well_def f hab
map_one' := by
change Quotient.liftOn ⟦Rack.PreEnvelGroup.unit⟧ (toEnvelGroup.mapAux f) _ = 1
simp only [Quotient.lift_mk, mapAux]
map_mul' := fun x y =>
Quotient.inductionOn₂ x y fun x y => by
change Quotient.liftOn ⟦mul x y⟧ (toEnvelGroup.mapAux f) _ = _
simp [toEnvelGroup.mapAux] }
invFun F := (Quandle.Conj.map F).comp (toEnvelGroup R)
right_inv F :=
MonoidHom.ext fun x =>
Quotient.inductionOn x fun x => by
induction x with
| unit => exact F.map_one.symm
| incl => rfl
| mul x y ih_x ih_y =>
have hm : ⟦x.mul y⟧ = @Mul.mul (EnvelGroup R) _ ⟦x⟧ ⟦y⟧ := rfl
simp only [MonoidHom.coe_mk, OneHom.coe_mk, Quotient.lift_mk]
suffices ∀ x y, F (Mul.mul x y) = F (x) * F (y) by
simp_all only [MonoidHom.coe_mk, OneHom.coe_mk, Quotient.lift_mk]
rw [← ih_x, ← ih_y, mapAux]
exact F.map_mul
| inv x ih_x =>
have hm : ⟦x.inv⟧ = @Inv.inv (EnvelGroup R) _ ⟦x⟧ := rfl
rw [hm, F.map_inv, MonoidHom.map_inv, ih_x]
/-- Given a homomorphism from a rack to a group, it factors through the enveloping group.
-/
theorem toEnvelGroup.univ (R : Type*) [Rack R] (G : Type*) [Group G] (f : R →◃ Quandle.Conj G) :
(Quandle.Conj.map (toEnvelGroup.map f)).comp (toEnvelGroup R) = f :=
toEnvelGroup.map.symm_apply_apply f
/-- The homomorphism `toEnvelGroup.map f` is the unique map that fits into the commutative
triangle in `toEnvelGroup.univ`.
-/
theorem toEnvelGroup.univ_uniq (R : Type*) [Rack R] (G : Type*) [Group G]
(f : R →◃ Quandle.Conj G) (g : EnvelGroup R →* G)
(h : f = (Quandle.Conj.map g).comp (toEnvelGroup R)) : g = toEnvelGroup.map f :=
h.symm ▸ (toEnvelGroup.map.apply_symm_apply g).symm
/-- The induced group homomorphism from the enveloping group into bijections of the rack,
using `Rack.toConj`. Satisfies the property `envelAction_prop`.
This gives the rack `R` the structure of an augmented rack over `EnvelGroup R`.
-/
def envelAction {R : Type*} [Rack R] : EnvelGroup R →* R ≃ R :=
toEnvelGroup.map (toConj R)
@[simp]
theorem envelAction_prop {R : Type*} [Rack R] (x y : R) :
envelAction (toEnvelGroup R x) y = x ◃ y :=
rfl
end EnvelGroup
end Rack
|
Bounds.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.NumberTheory.ModularForms.JacobiTheta.TwoVariable
/-!
# Asymptotic bounds for Jacobi theta functions
The goal of this file is to establish some technical lemmas about the asymptotics of the sums
`F_nat k a t = ∑' (n : ℕ), (n + a) ^ k * exp (-π * (n + a) ^ 2 * t)`
and
`F_int k a t = ∑' (n : ℤ), |n + a| ^ k * exp (-π * (n + a) ^ 2 * t).`
Here `k : ℕ` and `a : ℝ` (resp `a : UnitAddCircle`) are fixed, and we are interested in
asymptotics as `t → ∞`. These results are needed for the theory of Hurwitz zeta functions (and
hence Dirichlet L-functions, etc).
## Main results
* `HurwitzKernelBounds.isBigO_atTop_F_nat_zero_sub` : for `0 ≤ a`, the function
`F_nat 0 a - (if a = 0 then 1 else 0)` decays exponentially at `∞` (i.e. it satisfies
`=O[atTop] fun t ↦ exp (-p * t)` for some real `0 < p`).
* `HurwitzKernelBounds.isBigO_atTop_F_nat_one` : for `0 ≤ a`, the function `F_nat 1 a` decays
exponentially at `∞`.
* `HurwitzKernelBounds.isBigO_atTop_F_int_zero_sub` : for any `a : UnitAddCircle`, the function
`F_int 0 a - (if a = 0 then 1 else 0)` decays exponentially at `∞`.
* `HurwitzKernelBounds.isBigO_atTop_F_int_one`: the function `F_int 1 a` decays exponentially at
`∞`.
-/
open Set Filter Topology Asymptotics Real
noncomputable section
namespace HurwitzKernelBounds
section lemmas
lemma isBigO_exp_neg_mul_of_le {c d : ℝ} (hcd : c ≤ d) :
(fun t ↦ exp (-d * t)) =O[atTop] fun t ↦ exp (-c * t) := by
apply Eventually.isBigO
filter_upwards [eventually_gt_atTop 0] with t ht
rw [norm_of_nonneg (exp_pos _).le]
gcongr
private lemma exp_lt_aux {t : ℝ} (ht : 0 < t) : rexp (-π * t) < 1 := by
simpa only [exp_lt_one_iff, neg_mul, neg_lt_zero] using mul_pos pi_pos ht
private lemma isBigO_one_aux :
IsBigO atTop (fun t : ℝ ↦ (1 - rexp (-π * t))⁻¹) (fun _ ↦ (1 : ℝ)) := by
refine ((Tendsto.const_sub _ ?_).inv₀ (by simp)).isBigO_one ℝ (c := ((1 - 0)⁻¹ : ℝ))
simpa only [neg_mul, tendsto_exp_comp_nhds_zero, tendsto_neg_atBot_iff]
using tendsto_id.const_mul_atTop pi_pos
end lemmas
section nat
/-- Summand in the sum to be bounded (`ℕ` version). -/
def f_nat (k : ℕ) (a t : ℝ) (n : ℕ) : ℝ := (n + a) ^ k * exp (-π * (n + a) ^ 2 * t)
/-- An upper bound for the summand when `0 ≤ a`. -/
def g_nat (k : ℕ) (a t : ℝ) (n : ℕ) : ℝ := (n + a) ^ k * exp (-π * (n + a ^ 2) * t)
lemma f_le_g_nat (k : ℕ) {a t : ℝ} (ha : 0 ≤ a) (ht : 0 < t) (n : ℕ) :
‖f_nat k a t n‖ ≤ g_nat k a t n := by
rw [f_nat, norm_of_nonneg (by positivity), g_nat]
simp only [neg_mul, add_sq]
gcongr
have H₁ : (n : ℝ) ≤ n ^ 2 := mod_cast Nat.le_self_pow two_ne_zero n
have H₂ : 0 ≤ 2 * n * a := by positivity
linear_combination H₁ + H₂
/-- The sum to be bounded (`ℕ` version). -/
def F_nat (k : ℕ) (a t : ℝ) : ℝ := ∑' n, f_nat k a t n
lemma summable_f_nat (k : ℕ) (a : ℝ) {t : ℝ} (ht : 0 < t) : Summable (f_nat k a t) := by
have : Summable fun n : ℕ ↦ n ^ k * exp (-π * (n + a) ^ 2 * t) := by
refine (((summable_pow_mul_jacobiTheta₂_term_bound (|a| * t) ht k).mul_right
(rexp (-π * a ^ 2 * t))).comp_injective Nat.cast_injective).of_norm_bounded (fun n ↦ ?_)
simp_rw [mul_assoc, Function.comp_apply, ← Real.exp_add, norm_mul, norm_pow, Int.cast_abs,
Int.cast_natCast, norm_eq_abs, Nat.abs_cast, abs_exp]
gcongr
rw [← sub_nonneg]
rw [show -π * (t * n ^ 2 - 2 * (|a| * (t * n))) + -π * (a ^ 2 * t) - -π * ((n + a) ^ 2 * t)
= π * t * n * (|a| + a) * 2 by ring]
refine mul_nonneg (mul_nonneg (by positivity) ?_) two_pos.le
rw [← neg_le_iff_add_nonneg]
apply neg_le_abs
apply (this.mul_left (2 ^ k)).of_norm_bounded_eventually_nat
simp_rw [← mul_assoc, f_nat, norm_mul, norm_eq_abs, abs_exp,
mul_le_mul_iff_of_pos_right (exp_pos _), ← mul_pow, abs_pow, two_mul]
filter_upwards [eventually_ge_atTop (Nat.ceil |a|)] with n hn
gcongr
exact (abs_add_le ..).trans (add_le_add (Nat.abs_cast _).le (Nat.ceil_le.mp hn))
section k_eq_zero
/-!
## Sum over `ℕ` with `k = 0`
Here we use direct comparison with a geometric series.
-/
lemma F_nat_zero_le {a : ℝ} (ha : 0 ≤ a) {t : ℝ} (ht : 0 < t) :
‖F_nat 0 a t‖ ≤ rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t)) := by
refine tsum_of_norm_bounded ?_ (f_le_g_nat 0 ha ht)
convert (hasSum_geometric_of_lt_one (exp_pos _).le <| exp_lt_aux ht).mul_left _ using 1
ext1 n
simp only [g_nat]
rw [← Real.exp_nat_mul, ← Real.exp_add]
ring_nf
lemma F_nat_zero_zero_sub_le {t : ℝ} (ht : 0 < t) :
‖F_nat 0 0 t - 1‖ ≤ rexp (-π * t) / (1 - rexp (-π * t)) := by
convert F_nat_zero_le zero_le_one ht using 2
· rw [F_nat, (summable_f_nat 0 0 ht).tsum_eq_zero_add, f_nat, Nat.cast_zero, add_zero, pow_zero,
one_mul, pow_two, mul_zero, mul_zero, zero_mul, exp_zero, add_comm, add_sub_cancel_right]
simp_rw [F_nat, f_nat, Nat.cast_add, Nat.cast_one, add_zero]
· rw [one_pow, mul_one]
lemma isBigO_atTop_F_nat_zero_sub {a : ℝ} (ha : 0 ≤ a) : ∃ p, 0 < p ∧
(fun t ↦ F_nat 0 a t - (if a = 0 then 1 else 0)) =O[atTop] fun t ↦ exp (-p * t) := by
split_ifs with h
· rw [h]
have : (fun t ↦ F_nat 0 0 t - 1) =O[atTop] fun t ↦ rexp (-π * t) / (1 - rexp (-π * t)) := by
apply Eventually.isBigO
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_nat_zero_zero_sub_le ht
refine ⟨_, pi_pos, this.trans ?_⟩
simpa using (isBigO_refl (fun t ↦ rexp (-π * t)) _).mul isBigO_one_aux
· simp_rw [sub_zero]
have : (fun t ↦ F_nat 0 a t) =O[atTop] fun t ↦ rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t)) := by
apply Eventually.isBigO
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_nat_zero_le ha ht
refine ⟨π * a ^ 2, mul_pos pi_pos (sq_pos_of_ne_zero h), this.trans ?_⟩
simpa only [neg_mul π (a ^ 2), mul_one] using (isBigO_refl _ _).mul isBigO_one_aux
end k_eq_zero
section k_eq_one
/-!
## Sum over `ℕ` with `k = 1`
Here we use comparison with the series `∑ n * r ^ n`, where `r = exp (-π * t)`.
-/
lemma F_nat_one_le {a : ℝ} (ha : 0 ≤ a) {t : ℝ} (ht : 0 < t) :
‖F_nat 1 a t‖ ≤ rexp (-π * (a ^ 2 + 1) * t) / (1 - rexp (-π * t)) ^ 2
+ a * rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t)) := by
refine tsum_of_norm_bounded ?_ (f_le_g_nat 1 ha ht)
unfold g_nat
simp_rw [pow_one, add_mul]
apply HasSum.add
· have h0' : ‖rexp (-π * t)‖ < 1 := by
simpa only [norm_eq_abs, abs_exp] using exp_lt_aux ht
convert (hasSum_coe_mul_geometric_of_norm_lt_one h0').mul_left (exp (-π * a ^ 2 * t)) using 1
· ext1 n
rw [mul_comm (exp _), ← Real.exp_nat_mul, mul_assoc (n : ℝ), ← Real.exp_add]
ring_nf
· rw [mul_add, add_mul, mul_one, exp_add, mul_div_assoc]
· convert (hasSum_geometric_of_lt_one (exp_pos _).le <| exp_lt_aux ht).mul_left _ using 1
ext1 n
rw [← Real.exp_nat_mul, mul_assoc _ (exp _), ← Real.exp_add]
ring_nf
lemma isBigO_atTop_F_nat_one {a : ℝ} (ha : 0 ≤ a) : ∃ p, 0 < p ∧
F_nat 1 a =O[atTop] fun t ↦ exp (-p * t) := by
suffices ∃ p, 0 < p ∧ (fun t ↦ rexp (-π * (a ^ 2 + 1) * t) / (1 - rexp (-π * t)) ^ 2
+ a * rexp (-π * a ^ 2 * t) / (1 - rexp (-π * t))) =O[atTop] fun t ↦ exp (-p * t) by
let ⟨p, hp, hp'⟩ := this
refine ⟨p, hp, (Eventually.isBigO ?_).trans hp'⟩
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_nat_one_le ha ht
have aux' : IsBigO atTop (fun t : ℝ ↦ ((1 - rexp (-π * t)) ^ 2)⁻¹) (fun _ ↦ (1 : ℝ)) := by
simpa only [inv_pow, one_pow] using isBigO_one_aux.pow 2
rcases eq_or_lt_of_le ha with rfl | ha'
· exact ⟨_, pi_pos, by simpa only [zero_pow two_ne_zero, zero_add, mul_one, zero_mul, zero_div,
add_zero] using (isBigO_refl _ _).mul aux'⟩
· refine ⟨π * a ^ 2, mul_pos pi_pos <| pow_pos ha' _, IsBigO.add ?_ ?_⟩
· conv_rhs => enter [t]; rw [← mul_one (rexp _)]
refine (Eventually.isBigO ?_).mul aux'
filter_upwards [eventually_gt_atTop 0] with t ht
rw [norm_of_nonneg (exp_pos _).le, exp_le_exp]
nlinarith [pi_pos]
· simp_rw [mul_div_assoc, ← neg_mul]
apply IsBigO.const_mul_left
simpa only [mul_one] using (isBigO_refl _ _).mul isBigO_one_aux
end k_eq_one
end nat
section int
/-- Summand in the sum to be bounded (`ℤ` version). -/
def f_int (k : ℕ) (a t : ℝ) (n : ℤ) : ℝ := |n + a| ^ k * exp (-π * (n + a) ^ 2 * t)
lemma f_int_ofNat (k : ℕ) {a : ℝ} (ha : 0 ≤ a) (t : ℝ) (n : ℕ) :
f_int k a t (Int.ofNat n) = f_nat k a t n := by
rw [f_int, f_nat, Int.ofNat_eq_coe, Int.cast_natCast, abs_of_nonneg (by positivity)]
lemma f_int_negSucc (k : ℕ) {a : ℝ} (ha : a ≤ 1) (t : ℝ) (n : ℕ) :
f_int k a t (Int.negSucc n) = f_nat k (1 - a) t n := by
have : (Int.negSucc n) + a = -(n + (1 - a)) := by { push_cast; ring }
rw [f_int, f_nat, this, abs_neg, neg_sq, abs_of_nonneg (by linarith)]
lemma summable_f_int (k : ℕ) (a : ℝ) {t : ℝ} (ht : 0 < t) : Summable (f_int k a t) := by
apply Summable.of_norm
suffices ∀ n, ‖f_int k a t n‖ = ‖(Int.rec (f_nat k a t) (f_nat k (1 - a) t) : ℤ → ℝ) n‖ from
funext this ▸ (HasSum.int_rec (summable_f_nat k a ht).hasSum
(summable_f_nat k (1 - a) ht).hasSum).summable.norm
intro n
rcases n with - | m
· simp only [f_int, f_nat, Int.ofNat_eq_coe, Int.cast_natCast, norm_mul, norm_eq_abs, abs_pow,
abs_abs]
· simp only [f_int, f_nat, Int.cast_negSucc, norm_mul, norm_eq_abs, abs_pow, abs_abs,
(by { push_cast; ring } : -↑(m + 1) + a = -(m + (1 - a))), abs_neg, neg_sq]
/-- The sum to be bounded (`ℤ` version). -/
def F_int (k : ℕ) (a : UnitAddCircle) (t : ℝ) : ℝ :=
(show Function.Periodic (fun b ↦ ∑' (n : ℤ), f_int k b t n) 1 by
intro b
simp_rw [← (Equiv.addRight (1 : ℤ)).tsum_eq (f := fun n ↦ f_int k b t n)]
simp only [f_int, ← add_assoc, add_comm, Equiv.coe_addRight, Int.cast_add, Int.cast_one]
).lift a
lemma F_int_eq_of_mem_Icc (k : ℕ) {a : ℝ} (ha : a ∈ Icc 0 1) {t : ℝ} (ht : 0 < t) :
F_int k a t = (F_nat k a t) + (F_nat k (1 - a) t) := by
simp only [F_int, F_nat, Function.Periodic.lift_coe]
convert ((summable_f_nat k a ht).hasSum.int_rec (summable_f_nat k (1 - a) ht).hasSum).tsum_eq
using 3 with n
cases n
· rw [f_int_ofNat _ ha.1]
· rw [f_int_negSucc _ ha.2]
lemma isBigO_atTop_F_int_zero_sub (a : UnitAddCircle) : ∃ p, 0 < p ∧
(fun t ↦ F_int 0 a t - (if a = 0 then 1 else 0)) =O[atTop] fun t ↦ exp (-p * t) := by
obtain ⟨a, ha, rfl⟩ := a.eq_coe_Ico
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_F_nat_zero_sub ha.1
obtain ⟨q, hq, hq'⟩ := isBigO_atTop_F_nat_zero_sub (sub_nonneg.mpr ha.2.le)
simp_rw [AddCircle.coe_eq_zero_iff_of_mem_Ico ha]
simp_rw [eq_false_intro (by linarith [ha.2] : 1 - a ≠ 0), if_false, sub_zero] at hq'
refine ⟨_, lt_min hp hq, ?_⟩
have : (fun t ↦ F_int 0 a t - (if a = 0 then 1 else 0)) =ᶠ[atTop]
fun t ↦ (F_nat 0 a t - (if a = 0 then 1 else 0)) + F_nat 0 (1 - a) t := by
filter_upwards [eventually_gt_atTop 0] with t ht
rw [F_int_eq_of_mem_Icc 0 (Ico_subset_Icc_self ha) ht]
ring
refine this.isBigO.trans ((hp'.trans ?_).add (hq'.trans ?_)) <;>
apply isBigO_exp_neg_mul_of_le
exacts [min_le_left .., min_le_right ..]
lemma isBigO_atTop_F_int_one (a : UnitAddCircle) : ∃ p, 0 < p ∧
F_int 1 a =O[atTop] fun t ↦ exp (-p * t) := by
obtain ⟨a, ha, rfl⟩ := a.eq_coe_Ico
obtain ⟨p, hp, hp'⟩ := isBigO_atTop_F_nat_one ha.1
obtain ⟨q, hq, hq'⟩ := isBigO_atTop_F_nat_one (sub_nonneg.mpr ha.2.le)
refine ⟨_, lt_min hp hq, ?_⟩
have : F_int 1 a =ᶠ[atTop] fun t ↦ F_nat 1 a t + F_nat 1 (1 - a) t := by
filter_upwards [eventually_gt_atTop 0] with t ht
exact F_int_eq_of_mem_Icc 1 (Ico_subset_Icc_self ha) ht
refine this.isBigO.trans ((hp'.trans ?_).add (hq'.trans ?_)) <;>
apply isBigO_exp_neg_mul_of_le
exacts [min_le_left .., min_le_right ..]
end int
end HurwitzKernelBounds
|
HSpaces.lean
|
/-
Copyright (c) 2022 Filippo A. E. Nuccio Mortarino Majno di Capriglio. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Filippo A. E. Nuccio, Junyan Xu
-/
import Mathlib.Topology.CompactOpen
import Mathlib.Topology.Homotopy.Basic
import Mathlib.Topology.Path
/-!
# H-spaces
This file defines H-spaces mainly following the approach proposed by Serre in his paper
*Homologie singulière des espaces fibrés*. The idea beneath `H-spaces` is that they are topological
spaces with a binary operation `⋀ : X → X → X` that is a homotopic-theoretic weakening of an
operation what would make `X` into a topological monoid.
In particular, there exists a "neutral element" `e : X` such that `fun x ↦e ⋀ x` and
`fun x ↦ x ⋀ e` are homotopic to the identity on `X`, see
[the Wikipedia page of H-spaces](https://en.wikipedia.org/wiki/H-space).
Some notable properties of `H-spaces` are
* Their fundamental group is always abelian (by the same argument for topological groups);
* Their cohomology ring comes equipped with a structure of a Hopf-algebra;
* The loop space based at every `x : X` carries a structure of an `H-spaces`.
## Main Results
* Every topological group `G` is an `H-space` using its operation `* : G → G → G` (this is already
true if `G` has an instance of a `MulOneClass` and `ContinuousMul`);
* Given two `H-spaces` `X` and `Y`, their product is again an `H`-space. We show in an example that
starting with two topological groups `G, G'`, the `H`-space structure on `G × G'` is
definitionally equal to the product of `H-space` structures on `G` and `G'`.
* The loop space based at every `x : X` carries a structure of an `H-spaces`.
## To Do
* Prove that for every `NormedAddTorsor Z` and every `z : Z`, the operation
`fun x y ↦ midpoint x y` defines an `H-space` structure with `z` as a "neutral element".
* Prove that `S^0`, `S^1`, `S^3` and `S^7` are the unique spheres that are `H-spaces`, where the
first three inherit the structure because they are topological groups (they are Lie groups,
actually), isomorphic to the invertible elements in `ℤ`, in `ℂ` and in the quaternion; and the
fourth from the fact that `S^7` coincides with the octonions of norm 1 (it is not a group, in
particular, only has an instance of `MulOneClass`).
## References
* [J.-P. Serre, *Homologie singulière des espaces fibrés. Applications*,
Ann. of Math (2) 1951, 54, 425–505][serre1951]
-/
universe u v
noncomputable section
open scoped unitInterval
open Path ContinuousMap Set.Icc TopologicalSpace
/-- A topological space `X` is an H-space if it behaves like a (potentially non-associative)
topological group, but where the axioms for a group only hold up to homotopy.
-/
class HSpace (X : Type u) [TopologicalSpace X] where
hmul : C(X × X, X)
e : X
hmul_e_e : hmul (e, e) = e
eHmul :
(hmul.comp <| (const X e).prodMk <| ContinuousMap.id X).HomotopyRel (ContinuousMap.id X) {e}
hmulE :
(hmul.comp <| (ContinuousMap.id X).prodMk <| const X e).HomotopyRel (ContinuousMap.id X) {e}
/-- The binary operation `hmul` on an `H`-space -/
scoped[HSpaces] notation x "⋀" y => HSpace.hmul (x, y)
open HSpaces
instance HSpace.prod (X : Type u) (Y : Type v) [TopologicalSpace X] [TopologicalSpace Y] [HSpace X]
[HSpace Y] : HSpace (X × Y) where
hmul := ⟨fun p => (p.1.1 ⋀ p.2.1, p.1.2 ⋀ p.2.2), by fun_prop⟩
e := (HSpace.e, HSpace.e)
hmul_e_e := by
simp only [ContinuousMap.coe_mk, Prod.mk_inj]
exact ⟨HSpace.hmul_e_e, HSpace.hmul_e_e⟩
eHmul := by
let G : I × X × Y → X × Y := fun p => (HSpace.eHmul (p.1, p.2.1), HSpace.eHmul (p.1, p.2.2))
have hG : Continuous G := by fun_prop
use! ⟨G, hG⟩
· rintro ⟨x, y⟩
exact Prod.ext (HSpace.eHmul.1.2 x) (HSpace.eHmul.1.2 y)
· rintro ⟨x, y⟩
exact Prod.ext (HSpace.eHmul.1.3 x) (HSpace.eHmul.1.3 y)
· rintro t ⟨x, y⟩ h
replace h := Prod.mk_inj.mp h
exact Prod.ext (HSpace.eHmul.2 t x h.1) (HSpace.eHmul.2 t y h.2)
hmulE := by
let G : I × X × Y → X × Y := fun p => (HSpace.hmulE (p.1, p.2.1), HSpace.hmulE (p.1, p.2.2))
have hG : Continuous G := by fun_prop
use! ⟨G, hG⟩
· rintro ⟨x, y⟩
exact Prod.ext (HSpace.hmulE.1.2 x) (HSpace.hmulE.1.2 y)
· rintro ⟨x, y⟩
exact Prod.ext (HSpace.hmulE.1.3 x) (HSpace.hmulE.1.3 y)
· rintro t ⟨x, y⟩ h
replace h := Prod.mk_inj.mp h
exact Prod.ext (HSpace.hmulE.2 t x h.1) (HSpace.hmulE.2 t y h.2)
namespace IsTopologicalGroup
/-- The definition `toHSpace` is not an instance because its additive version would
lead to a diamond since a topological field would inherit two `HSpace` structures, one from the
`MulOneClass` and one from the `AddZeroClass`. In the case of a group, we make
`IsTopologicalGroup.hSpace` an instance." -/
@[to_additive
/-- The definition `toHSpace` is not an instance because it comes together with a
multiplicative version which would lead to a diamond since a topological field would inherit
two `HSpace` structures, one from the `MulOneClass` and one from the `AddZeroClass`.
In the case of an additive group, we make `IsTopologicalAddGroup.hSpace` an instance. -/]
def toHSpace (M : Type u) [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] : HSpace M where
hmul := ⟨Function.uncurry Mul.mul, continuous_mul⟩
e := 1
hmul_e_e := one_mul 1
eHmul := (HomotopyRel.refl _ _).cast rfl (by ext1; apply one_mul)
hmulE := (HomotopyRel.refl _ _).cast rfl (by ext1; apply mul_one)
@[to_additive]
instance (priority := 600) hSpace (G : Type u) [TopologicalSpace G] [Group G]
[IsTopologicalGroup G] : HSpace G :=
toHSpace G
theorem one_eq_hSpace_e {G : Type u} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] :
(1 : G) = HSpace.e :=
rfl
/- In the following example we see that the H-space structure on the product of two topological
groups is definitionally equally to the product H-space-structure of the two groups. -/
example {G G' : Type u} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] [TopologicalSpace G']
[Group G'] [IsTopologicalGroup G'] : IsTopologicalGroup.hSpace (G × G') = HSpace.prod G G' := by
simp only [HSpace.prod]
rfl
end IsTopologicalGroup
namespace unitInterval
/-- `qRight` is analogous to the function `Q` defined on p. 475 of [serre1951] that helps proving
continuity of `delayReflRight`. -/
def qRight (p : I × I) : I :=
Set.projIcc 0 1 zero_le_one (2 * p.1 / (1 + p.2))
@[fun_prop]
theorem continuous_qRight : Continuous qRight :=
continuous_projIcc.comp <|
Continuous.div (by fun_prop) (by fun_prop) fun _ ↦ (add_pos zero_lt_one).ne'
theorem qRight_zero_left (θ : I) : qRight (0, θ) = 0 :=
Set.projIcc_of_le_left _ <| by simp only [coe_zero, mul_zero, zero_div, le_refl]
theorem qRight_one_left (θ : I) : qRight (1, θ) = 1 :=
Set.projIcc_of_right_le _ <|
(le_div_iff₀ <| add_pos zero_lt_one).2 <| by
dsimp only
rw [coe_one, one_mul, mul_one, add_comm, ← one_add_one_eq_two]
simp only [add_le_add_iff_right]
exact le_one _
theorem qRight_zero_right (t : I) :
(qRight (t, 0) : ℝ) = if (t : ℝ) ≤ 1 / 2 then (2 : ℝ) * t else 1 := by
simp only [qRight, coe_zero, add_zero, div_one]
split_ifs
· rw [Set.projIcc_of_mem _ ((mul_pos_mem_iff zero_lt_two).2 _)]
refine ⟨t.2.1, ?_⟩
tauto
· rw [(Set.projIcc_eq_right _).2]
· linarith
· exact zero_lt_one
theorem qRight_one_right (t : I) : qRight (t, 1) = t :=
Eq.trans (by rw [qRight]; norm_num) <| Set.projIcc_val zero_le_one _
end unitInterval
namespace Path
open unitInterval
variable {X : Type u} [TopologicalSpace X] {x y : X}
/-- This is the function analogous to the one on p. 475 of [serre1951], defining a homotopy from
the product path `γ ∧ e` to `γ`. -/
def delayReflRight (θ : I) (γ : Path x y) : Path x y where
toFun t := γ (qRight (t, θ))
continuous_toFun := by fun_prop
source' := by
rw [qRight_zero_left, γ.source]
target' := by
rw [qRight_one_left, γ.target]
theorem continuous_delayReflRight : Continuous fun p : I × Path x y => delayReflRight p.1 p.2 :=
continuous_uncurry_iff.mp <|
(continuous_snd.comp continuous_fst).eval <|
continuous_qRight.comp <| continuous_snd.prodMk <| continuous_fst.comp continuous_fst
theorem delayReflRight_zero (γ : Path x y) : delayReflRight 0 γ = γ.trans (Path.refl y) := by
ext t
simp only [delayReflRight, trans_apply, Path.coe_mk_mk,
refl_apply]
split_ifs with h; swap
on_goal 1 => conv_rhs => rw [← γ.target]
all_goals apply congr_arg γ; ext1; rw [qRight_zero_right]
exacts [if_neg h, if_pos h]
theorem delayReflRight_one (γ : Path x y) : delayReflRight 1 γ = γ := by
ext t
exact congr_arg γ (qRight_one_right t)
/-- This is the function on p. 475 of [serre1951], defining a homotopy from a path `γ` to the
product path `e ∧ γ`. -/
def delayReflLeft (θ : I) (γ : Path x y) : Path x y :=
(delayReflRight θ γ.symm).symm
theorem continuous_delayReflLeft : Continuous fun p : I × Path x y => delayReflLeft p.1 p.2 :=
Path.continuous_symm.comp <|
continuous_delayReflRight.comp <|
continuous_fst.prodMk <| Path.continuous_symm.comp continuous_snd
theorem delayReflLeft_zero (γ : Path x y) : delayReflLeft 0 γ = (Path.refl x).trans γ := by
simp only [delayReflLeft, delayReflRight_zero, trans_symm, refl_symm, Path.symm_symm]
theorem delayReflLeft_one (γ : Path x y) : delayReflLeft 1 γ = γ := by
simp only [delayReflLeft, delayReflRight_one, Path.symm_symm]
/-- The loop space at x carries a structure of an H-space. Note that the field `eHmul`
(resp. `hmulE`) neither implies nor is implied by `Path.Homotopy.reflTrans`
(resp. `Path.Homotopy.transRefl`).
-/
instance (x : X) : HSpace (Path x x) where
hmul := ⟨fun ρ => ρ.1.trans ρ.2, continuous_trans⟩
e := refl x
hmul_e_e := refl_trans_refl
eHmul :=
{ toHomotopy :=
⟨⟨fun p : I × Path x x ↦ delayReflLeft p.1 p.2, continuous_delayReflLeft⟩,
delayReflLeft_zero, delayReflLeft_one⟩
prop' := by rintro t _ rfl; exact refl_trans_refl.symm }
hmulE :=
{ toHomotopy :=
⟨⟨fun p : I × Path x x ↦ delayReflRight p.1 p.2, continuous_delayReflRight⟩,
delayReflRight_zero, delayReflRight_one⟩
prop' := by rintro t _ rfl; exact refl_trans_refl.symm }
end Path
|
fingroup.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 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 *)
(* baseFinGroupType == the structure for finite types with a monoid law *)
(* and an involutive antimorphism; finGroupType is *)
(* derived from baseFinGroupType *)
(* The HB class is called BaseFinGroup. *)
(* FinGroupType mulVg == the finGroupType structure for an existing *)
(* baseFinGroupType 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 baseFinGroupType 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 (via Import GroupScope). *)
(* 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 baseFinGroupType, *)
(* 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.
(* This module can be imported to open the scope for group element *)
(* operations locally to a file, without exporting the Open to *)
(* clients of that file (as Open would do). *)
Module GroupScope.
Open Scope group_scope.
End GroupScope.
Import GroupScope.
(* 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 ']' ]").
(* We split the group axiomatisation in two. We define a *)
(* class of "base groups", which are basically monoids *)
(* with an involutive antimorphism, from which we derive *)
(* the class of groups proper. This allows us to reuse *)
(* much of the group notation and algebraic axioms for *)
(* group subsets, by defining a base group class on them. *)
(* We use class/mixins here rather than telescopes to *)
(* be able to interoperate with the type coercions. *)
(* Another potential benefit (not exploited here) would *)
(* be to define a class for infinite groups, which could *)
(* share all of the algebraic laws. *)
HB.mixin Record isMulBaseGroup G := {
mulg_subdef : G -> G -> G;
oneg_subdef : G;
invg_subdef : G -> G;
mulgA_subproof : associative mulg_subdef ;
mul1g_subproof : left_id oneg_subdef mulg_subdef ;
invgK_subproof : involutive invg_subdef ;
invMg_subproof : {morph invg_subdef : x y / mulg_subdef x y >-> mulg_subdef y x}
}.
(* We want to use sort as a coercion class, both to infer *)
(* argument scopes properly, and to allow groups and cosets to *)
(* coerce to the base group of group subsets. *)
(* However, the return type of group operations should NOT be a *)
(* coercion class, since this would trump the real (head-normal) *)
(* coercion class for concrete group types, thus spoiling the *)
(* coercion of A * B to pred_sort in x \in A * B, or rho * tau to *)
(* ffun and Funclass in (rho * tau) x, when rho tau : perm T. *)
(* Therefore we define an alias of sort for argument types, and *)
(* make it the default coercion FinGroup.base_type >-> Sortclass *)
(* so that arguments of a functions whose parameters are of type, *)
(* say, gT : finGroupType, can be coerced to the coercion class *)
(* of arg_sort. Care should be taken, however, to declare the *)
(* return type of functions and operators as FinGroup.sort gT *)
(* rather than gT, e.g., mulg : gT -> gT -> FinGroup.sort gT. *)
(* Note that since we do this here and in quotient.v for all the *)
(* basic functions, the inferred return type should generally be *)
(* correct. *)
#[arg_sort, short(type="baseFinGroupType")]
HB.structure Definition BaseFinGroup := { G of isMulBaseGroup G & Finite G }.
Module BaseFinGroupExports.
Bind Scope group_scope with BaseFinGroup.arg_sort.
Bind Scope group_scope with BaseFinGroup.sort.
End BaseFinGroupExports.
HB.export BaseFinGroupExports.
Module Notations.
Section ElementOps.
Variable T : baseFinGroupType.
Notation rT := (BaseFinGroup.sort T).
Definition oneg : rT := Eval unfold oneg_subdef in @oneg_subdef T.
Definition mulg : T -> T -> rT := Eval unfold mulg_subdef in @mulg_subdef T.
Definition invg : T -> rT := Eval unfold invg_subdef in @invg_subdef T.
Definition expgn (x : T) n : rT := iterop n mulg x oneg.
End ElementOps.
Arguments expgn : simpl never.
Notation "1" := (@oneg _) : group_scope.
Notation "x1 * x2" := (mulg x1 x2) : group_scope.
Notation "x ^-1" := (invg x) : group_scope.
Notation "x ^+ n" := (expgn x n) : group_scope.
Notation "x ^- n" := (x ^+ n)^-1 : group_scope.
End Notations.
HB.export Notations.
HB.mixin Record BaseFinGroup_isGroup G of BaseFinGroup G := {
mulVg_subproof : left_inverse (@oneg G) (@invg _) (@mulg _)
}.
#[short(type="finGroupType")]
HB.structure Definition FinGroup :=
{ G of BaseFinGroup_isGroup G & BaseFinGroup G }.
Module FinGroupExports.
Bind Scope group_scope with FinGroup.sort.
End FinGroupExports.
HB.export FinGroupExports.
HB.factory Record isMulGroup G of Finite G := {
mulg : G -> G -> G;
oneg : G;
invg : G -> G;
mulgA : associative mulg;
mul1g : left_id oneg mulg;
mulVg : left_inverse oneg invg mulg;
}.
HB.builders Context G of isMulGroup G.
Notation "1" := oneg.
Infix "*" := mulg.
Notation "x ^-1" := (invg x).
Lemma mk_invgK : involutive invg.
Proof.
have mulV21 x: x^-1^-1 * 1 = x by rewrite -(mulVg x) mulgA mulVg mul1g.
by move=> x; rewrite -[_ ^-1]mulV21 -(mul1g 1) mulgA !mulV21.
Qed.
Lemma mk_invMg : {morph invg : x y / x * y >-> y * x}.
Proof.
have mulgV x: x * x^-1 = 1 by rewrite -{1}[x]mk_invgK mulVg.
move=> x y /=; rewrite -[y^-1 * _]mul1g -(mulVg (x * y)) -2!mulgA (mulgA y).
by rewrite mulgV mul1g mulgV -(mulgV (x * y)) mulgA mulVg mul1g.
Qed.
HB.instance Definition _ :=
isMulBaseGroup.Build G mulgA mul1g mk_invgK mk_invMg.
HB.instance Definition _ := BaseFinGroup_isGroup.Build G mulVg.
HB.end.
#[compress_coercions]
HB.instance Definition _ (T : baseFinGroupType) :
Finite (BaseFinGroup.arg_sort T) := Finite.class T.
(* Arguments of conjg are restricted to true groups to avoid an *)
(* improper interpretation of A ^ B with A and B sets, namely: *)
(* {x^-1 * (y * z) | y \in A, x, z \in B} *)
Definition conjg (T : finGroupType) (x y : T) := y^-1 * (x * y).
Notation "x1 ^ x2" := (conjg x1 x2) : group_scope.
Definition commg (T : finGroupType) (x y : T) := x^-1 * x ^ y.
Notation "[ ~ x1 , x2 , .. , xn ]" := (commg .. (commg x1 x2) .. xn)
: group_scope.
Prenex Implicits mulg invg expgn conjg commg.
Notation "\prod_ ( i <- r | P ) F" :=
(\big[mulg/1]_(i <- r | P%B) F%g) : group_scope.
Notation "\prod_ ( i <- r ) F" :=
(\big[mulg/1]_(i <- r) F%g) : group_scope.
Notation "\prod_ ( m <= i < n | P ) F" :=
(\big[mulg/1]_(m <= i < n | P%B) F%g) : group_scope.
Notation "\prod_ ( m <= i < n ) F" :=
(\big[mulg/1]_(m <= i < n) F%g) : group_scope.
Notation "\prod_ ( i | P ) F" :=
(\big[mulg/1]_(i | P%B) F%g) : group_scope.
Notation "\prod_ i F" :=
(\big[mulg/1]_i F%g) : group_scope.
Notation "\prod_ ( i : t | P ) F" :=
(\big[mulg/1]_(i : t | P%B) F%g) (only parsing) : group_scope.
Notation "\prod_ ( i : t ) F" :=
(\big[mulg/1]_(i : t) F%g) (only parsing) : group_scope.
Notation "\prod_ ( i < n | P ) F" :=
(\big[mulg/1]_(i < n | P%B) F%g) : group_scope.
Notation "\prod_ ( i < n ) F" :=
(\big[mulg/1]_(i < n) F%g) : group_scope.
Notation "\prod_ ( i 'in' A | P ) F" :=
(\big[mulg/1]_(i in A | P%B) F%g) : group_scope.
Notation "\prod_ ( i 'in' A ) F" :=
(\big[mulg/1]_(i in A) F%g) : group_scope.
Section PreGroupIdentities.
Variable T : baseFinGroupType.
Implicit Types x y z : T.
Local Notation mulgT := (@mulg T).
Lemma mulgA : associative mulgT. Proof. exact: mulgA_subproof. Qed.
Lemma mul1g : left_id 1 mulgT. Proof. exact: mul1g_subproof. Qed.
Lemma invgK : @involutive T invg. Proof. exact: invgK_subproof. Qed.
Lemma invMg x y : (x * y)^-1 = y^-1 * x^-1. Proof. exact: invMg_subproof. Qed.
Lemma invg_inj : @injective T T invg. Proof. exact: can_inj invgK. Qed.
Lemma eq_invg_sym x y : (x^-1 == y) = (x == y^-1).
Proof. by apply: (inv_eq invgK). Qed.
Lemma invg1 : 1^-1 = 1 :> T.
Proof. by apply: invg_inj; rewrite -{1}[1^-1]mul1g invMg invgK mul1g. Qed.
Lemma eq_invg1 x : (x^-1 == 1) = (x == 1).
Proof. by rewrite eq_invg_sym invg1. Qed.
Lemma mulg1 : right_id 1 mulgT.
Proof. by move=> x; apply: invg_inj; rewrite invMg invg1 mul1g. Qed.
HB.instance Definition _ := Monoid.isLaw.Build T 1 mulgT mulgA mul1g mulg1.
Lemma expgnE x n : x ^+ n = iterop n mulg x 1. Proof. by []. Qed.
Lemma expg0 x : x ^+ 0 = 1. Proof. by []. Qed.
Lemma expg1 x : x ^+ 1 = x. Proof. by []. Qed.
Lemma expgS x n : x ^+ n.+1 = x * x ^+ n.
Proof. by case: n => //; rewrite mulg1. Qed.
Lemma expg1n n : 1 ^+ n = 1 :> T.
Proof. by elim: n => // n IHn; rewrite expgS mul1g. Qed.
Lemma expgD x n m : x ^+ (n + m) = x ^+ n * x ^+ m.
Proof. by elim: n => [|n IHn]; rewrite ?mul1g // !expgS IHn mulgA. Qed.
Lemma expgSr x n : x ^+ n.+1 = x ^+ n * x.
Proof. by rewrite -addn1 expgD expg1. Qed.
Lemma expgM x n m : x ^+ (n * m) = x ^+ n ^+ m.
Proof.
elim: m => [|m IHm]; first by rewrite muln0 expg0.
by rewrite mulnS expgD IHm expgS.
Qed.
Lemma expgAC x m n : x ^+ m ^+ n = x ^+ n ^+ m.
Proof. by rewrite -!expgM mulnC. Qed.
Definition commute x y := x * y = y * x.
Lemma commute_refl x : commute x x.
Proof. by []. Qed.
Lemma commute_sym x y : commute x y -> commute y x.
Proof. by []. Qed.
Lemma commute1 x : commute x 1.
Proof. by rewrite /commute mulg1 mul1g. Qed.
Lemma commuteM x y z : commute x y -> commute x z -> commute x (y * z).
Proof. by move=> cxy cxz; rewrite /commute -mulgA -cxz !mulgA cxy. Qed.
Lemma commuteX x y n : commute x y -> commute x (y ^+ n).
Proof.
by move=> cxy; case: n; [apply: commute1 | elim=> // n; apply: commuteM].
Qed.
Lemma commuteX2 x y m n : commute x y -> commute (x ^+ m) (y ^+ n).
Proof. by move=> cxy; apply/commuteX/commute_sym/commuteX. Qed.
Lemma expgVn x n : x^-1 ^+ n = x ^- n.
Proof. by elim: n => [|n IHn]; rewrite ?invg1 // expgSr expgS invMg IHn. Qed.
Lemma expgMn x y n : commute x y -> (x * y) ^+ n = x ^+ n * y ^+ n.
Proof.
move=> cxy; elim: n => [|n IHn]; first by rewrite mulg1.
by rewrite !expgS IHn -mulgA (mulgA y) (commuteX _ (commute_sym cxy)) !mulgA.
Qed.
End PreGroupIdentities.
#[global] Hint Resolve commute1 : core.
Arguments invg_inj {T} [x1 x2].
Prenex Implicits commute invgK.
Section GroupIdentities.
Variable T : finGroupType.
Implicit Types x y z : T.
Local Notation mulgT := (@mulg T).
Lemma mulVg : left_inverse 1 invg mulgT. Proof. exact: mulVg_subproof. Qed.
Lemma mulgV : right_inverse 1 invg mulgT.
Proof. by move=> x; rewrite -{1}(invgK x) mulVg. Qed.
Lemma mulKg : left_loop invg mulgT.
Proof. by move=> x y; rewrite mulgA mulVg mul1g. Qed.
Lemma mulKVg : rev_left_loop invg mulgT.
Proof. by move=> x y; rewrite mulgA mulgV mul1g. Qed.
Lemma mulgI : right_injective mulgT.
Proof. by move=> x; apply: can_inj (mulKg x). Qed.
Lemma mulgK : right_loop invg mulgT.
Proof. by move=> x y; rewrite -mulgA mulgV mulg1. Qed.
Lemma mulgKV : rev_right_loop invg mulgT.
Proof. by move=> x y; rewrite -mulgA mulVg mulg1. Qed.
Lemma mulIg : left_injective mulgT.
Proof. by move=> x; apply: can_inj (mulgK x). Qed.
Lemma eq_invg_mul x y : (x^-1 == y :> T) = (x * y == 1 :> T).
Proof. by rewrite -(inj_eq (@mulgI x)) mulgV eq_sym. Qed.
Lemma eq_mulgV1 x y : (x == y) = (x * y^-1 == 1 :> T).
Proof. by rewrite -(inj_eq invg_inj) eq_invg_mul. Qed.
Lemma eq_mulVg1 x y : (x == y) = (x^-1 * y == 1 :> T).
Proof. by rewrite -eq_invg_mul invgK. Qed.
Lemma commuteV x y : commute x y -> commute x y^-1.
Proof. by move=> cxy; apply: (@mulIg y); rewrite mulgKV -mulgA cxy mulKg. Qed.
Lemma conjgE x y : x ^ y = y^-1 * (x * y). Proof. by []. Qed.
Lemma conjgC x y : x * y = y * x ^ y.
Proof. by rewrite mulKVg. Qed.
Lemma conjgCV x y : x * y = y ^ x^-1 * x.
Proof. by rewrite -mulgA mulgKV invgK. Qed.
Lemma conjg1 x : x ^ 1 = x.
Proof. by rewrite conjgE commute1 mulKg. Qed.
Lemma conj1g x : 1 ^ x = 1.
Proof. by rewrite conjgE mul1g mulVg. Qed.
Lemma conjMg x y z : (x * y) ^ z = x ^ z * y ^ z.
Proof. by rewrite !conjgE !mulgA mulgK. Qed.
Lemma conjgM x y z : x ^ (y * z) = (x ^ y) ^ z.
Proof. by rewrite !conjgE invMg !mulgA. Qed.
Lemma conjVg x y : x^-1 ^ y = (x ^ y)^-1.
Proof. by rewrite !conjgE !invMg invgK mulgA. Qed.
Lemma conjJg x y z : (x ^ y) ^ z = (x ^ z) ^ y ^ z.
Proof. by rewrite 2!conjMg conjVg. Qed.
Lemma conjXg x y n : (x ^+ n) ^ y = (x ^ y) ^+ n.
Proof. by elim: n => [|n IHn]; rewrite ?conj1g // !expgS conjMg IHn. Qed.
Lemma conjgK : @right_loop T T invg conjg.
Proof. by move=> y x; rewrite -conjgM mulgV conjg1. Qed.
Lemma conjgKV : @rev_right_loop T T invg conjg.
Proof. by move=> y x; rewrite -conjgM mulVg conjg1. Qed.
Lemma conjg_inj : @left_injective T T T conjg.
Proof. by move=> y; apply: can_inj (conjgK y). Qed.
Lemma conjg_eq1 x y : (x ^ y == 1) = (x == 1).
Proof. by rewrite (canF_eq (conjgK _)) conj1g. Qed.
Lemma conjg_prod I r (P : pred I) F z :
(\prod_(i <- r | P i) F i) ^ z = \prod_(i <- r | P i) (F i ^ z).
Proof.
by apply: (big_morph (conjg^~ z)) => [x y|]; rewrite ?conj1g ?conjMg.
Qed.
Lemma commgEl x y : [~ x, y] = x^-1 * x ^ y. Proof. by []. Qed.
Lemma commgEr x y : [~ x, y] = y^-1 ^ x * y.
Proof. by rewrite -!mulgA. Qed.
Lemma commgC x y : x * y = y * x * [~ x, y].
Proof. by rewrite -mulgA !mulKVg. Qed.
Lemma commgCV x y : x * y = [~ x^-1, y^-1] * (y * x).
Proof. by rewrite commgEl !mulgA !invgK !mulgKV. Qed.
Lemma conjRg x y z : [~ x, y] ^ z = [~ x ^ z, y ^ z].
Proof. by rewrite !conjMg !conjVg. Qed.
Lemma invg_comm x y : [~ x, y]^-1 = [~ y, x].
Proof. by rewrite commgEr conjVg invMg invgK. Qed.
Lemma commgP x y : reflect (commute x y) ([~ x, y] == 1 :> T).
Proof. by rewrite [[~ x, y]]mulgA -invMg -eq_mulVg1 eq_sym; apply: eqP. Qed.
Lemma conjg_fixP x y : reflect (x ^ y = x) ([~ x, y] == 1 :> T).
Proof. by rewrite -eq_mulVg1 eq_sym; apply: eqP. Qed.
Lemma commg1_sym x y : ([~ x, y] == 1 :> T) = ([~ y, x] == 1 :> T).
Proof. by rewrite -invg_comm (inv_eq invgK) invg1. Qed.
Lemma commg1 x : [~ x, 1] = 1.
Proof. exact/eqP/commgP. Qed.
Lemma comm1g x : [~ 1, x] = 1.
Proof. by rewrite -invg_comm commg1 invg1. Qed.
Lemma commgg x : [~ x, x] = 1.
Proof. exact/eqP/commgP. Qed.
Lemma commgXg x n : [~ x, x ^+ n] = 1.
Proof. exact/eqP/commgP/commuteX. Qed.
Lemma commgVg x : [~ x, x^-1] = 1.
Proof. exact/eqP/commgP/commuteV. Qed.
Lemma commgXVg x n : [~ x, x ^- n] = 1.
Proof. exact/eqP/commgP/commuteV/commuteX. Qed.
(* Other commg identities should slot in here. *)
End GroupIdentities.
#[global] Hint Rewrite mulg1 @mul1g invg1 @mulVg mulgV (@invgK) mulgK mulgKV
@invMg @mulgA : gsimpl.
Ltac gsimpl := autorewrite with gsimpl; try done.
Definition gsimp := (@mulg1, @mul1g, (@invg1, @invgK), (@mulgV, @mulVg)).
Definition gnorm := (gsimp, (@mulgK, @mulgKV, (@mulgA, @invMg))).
Arguments mulgI [T].
Arguments mulIg [T].
Arguments conjg_inj {T} x [x1 x2].
Arguments commgP {T x y}.
Arguments conjg_fixP {T x y}.
Section Repr.
(* Plucking a set representative. *)
Variable gT : baseFinGroupType.
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.
by rewrite /repr; case: ifP => // _; case: pickP => // A0; rewrite [x \in A]A0.
Qed.
Lemma card_mem_repr A : #|A| > 0 -> repr A \in A.
Proof. by rewrite lt0n => /existsP[x]; apply: mem_repr. Qed.
Lemma repr_set1 x : repr [set x] = x.
Proof. by apply/set1P/card_mem_repr; rewrite cards1. Qed.
Lemma repr_set0 : repr set0 = 1.
Proof. by rewrite /repr; case: pickP => [x|_] /[!inE]. Qed.
End Repr.
Arguments mem_repr [gT A].
Section BaseSetMulDef.
(* We only assume a baseFinGroupType to allow this construct to be iterated. *)
Variable gT : baseFinGroupType.
Implicit Types A B : {set gT}.
(* Set-lifted group operations. *)
Definition set_mulg A B := mulg @2: (A, B).
Definition set_invg A := invg @^-1: A.
(* The pre-group structure of group subsets. *)
Lemma set_mul1g : left_id [set 1] set_mulg.
Proof.
move=> A; apply/setP=> y; apply/imset2P/idP=> [[_ x /set1P-> Ax ->] | Ay].
by rewrite mul1g.
by exists (1 : gT) y; rewrite ?(set11, mul1g).
Qed.
Lemma set_mulgA : associative set_mulg.
Proof.
move=> A B C; apply/setP=> y.
apply/imset2P/imset2P=> [[x1 z Ax1 /imset2P[x2 x3 Bx2 Cx3 ->] ->]| [z x3]].
by exists (x1 * x2) x3; rewrite ?mulgA //; apply/imset2P; exists x1 x2.
case/imset2P=> x1 x2 Ax1 Bx2 -> Cx3 ->.
by exists x1 (x2 * x3); rewrite ?mulgA //; apply/imset2P; exists x2 x3.
Qed.
Lemma set_invgK : involutive set_invg.
Proof. by move=> A; apply/setP=> x; rewrite !inE invgK. Qed.
Lemma set_invgM : {morph set_invg : A B / set_mulg A B >-> set_mulg B A}.
Proof.
move=> A B; apply/setP=> z; rewrite inE.
apply/imset2P/imset2P=> [[x y Ax By /(canRL invgK)->] | [y x]].
by exists y^-1 x^-1; rewrite ?invMg // inE invgK.
by rewrite !inE => By1 Ax1 ->; exists x^-1 y^-1; rewrite ?invMg.
Qed.
HB.instance Definition set_base_group := isMulBaseGroup.Build (set_type gT)
set_mulgA set_mul1g set_invgK set_invgM.
HB.instance Definition _ : isMulBaseGroup {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 : baseFinGroupType) := {set gT}.
End GroupSet.
Identity Coercion GroupSet_of_sort : GroupSet.sort >-> set_of.
Module Type GroupSetBaseGroupSig.
Definition sort (gT : baseFinGroupType) := BaseFinGroup.arg_sort {set gT}.
End GroupSetBaseGroupSig.
Module MakeGroupSetBaseGroup (Gset_base : GroupSetBaseGroupSig).
Identity Coercion of_sort : Gset_base.sort >-> BaseFinGroup.arg_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 baseFinGroupType. *)
(* 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 := mulg x @: A.
Definition rcoset A x := mulg^~ 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 : baseFinGroupType.
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 mulg (mem A) (fun _ => mem B) x) (x \in A * B).
Proof. exact: imset2P. Qed.
Lemma mem_mulg A B x y : x \in A -> y \in B -> x * y \in A * B.
Proof. by move=> Ax By; apply/mulsgP; exists x y. Qed.
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.
have [r big_r [Ur mem_r] _] := big_enumP P.
pose inA c := all (fun i => c i \in A i); rewrite -big_r; set piAx := x \in _.
suffices{big_r} IHr: reflect (exists2 c, inA c r & x = \prod_(i <- r) c i) piAx.
apply: (iffP IHr) => -[c inAc ->]; do [exists c; last by rewrite big_r].
by move=> i Pi; rewrite (allP inAc) ?mem_r.
by apply/allP=> i; rewrite mem_r => /inAc.
elim: {P mem_r}r x @piAx Ur => /= [x _ | i r IHr x /andP[r'i /IHr{}IHr]].
by rewrite unlock; apply: (iffP set1P) => [-> | [] //]; exists (fun=> x).
rewrite big_cons; apply: (iffP idP) => [|[c /andP[Aci Ac] ->]]; last first.
by rewrite big_cons mem_mulg //; apply/IHr=> //; exists c.
case/mulsgP=> c_i _ Ac_i /IHr[c /allP-inAcr ->] ->{x}.
exists [eta c with i |-> c_i]; rewrite /= ?big_cons eqxx ?Ac_i.
by apply/allP=> j rj; rewrite /= ifN ?(memPn r'i) ?inAcr.
by congr (_ * _); apply: eq_big_seq => j rj; rewrite ifN ?(memPn r'i).
Qed.
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. by move=> Ac; apply/prodsgP; exists c. Qed.
Lemma mulSg A B C : A \subset B -> A * C \subset B * C.
Proof. exact: imset2Sl. Qed.
Lemma mulgS A B C : B \subset C -> A * B \subset A * C.
Proof. exact: imset2Sr. Qed.
Lemma mulgSS A B C D : A \subset B -> C \subset D -> A * C \subset B * D.
Proof. exact: imset2S. Qed.
Lemma mulg_subl A B : 1 \in B -> A \subset A * B.
Proof. by move=> B1; rewrite -{1}(mulg1 A) mulgS ?sub1set. Qed.
Lemma mulg_subr A B : 1 \in A -> B \subset A * B.
Proof. by move=> A1; rewrite -{1}(mul1g B) mulSg ?sub1set. Qed.
Lemma mulUg A B C : (A :|: B) * C = (A * C) :|: (B * C).
Proof. exact: imset2Ul. Qed.
Lemma mulgU A B C : A * (B :|: C) = (A * B) :|: (A * C).
Proof. exact: imset2Ur. Qed.
(* Set (pointwise) inverse. *)
Lemma invUg A B : (A :|: B)^-1 = A^-1 :|: B^-1.
Proof. exact: preimsetU. Qed.
Lemma invIg A B : (A :&: B)^-1 = A^-1 :&: B^-1.
Proof. exact: preimsetI. Qed.
Lemma invDg A B : (A :\: B)^-1 = A^-1 :\: B^-1.
Proof. exact: preimsetD. Qed.
Lemma invCg A : (~: A)^-1 = ~: A^-1.
Proof. exact: preimsetC. Qed.
Lemma invSg A B : (A^-1 \subset B^-1) = (A \subset B).
Proof. by rewrite !(sameP setIidPl eqP) -invIg (inj_eq invg_inj). Qed.
Lemma mem_invg x A : (x \in A^-1) = (x^-1 \in A).
Proof. by rewrite inE. Qed.
Lemma memV_invg x A : (x^-1 \in A^-1) = (x \in A).
Proof. by rewrite inE invgK. Qed.
Lemma card_invg A : #|A^-1| = #|A|.
Proof. exact/card_preimset/invg_inj. Qed.
(* Product with singletons. *)
Lemma set1gE : 1 = [set 1] :> {set gT}. Proof. by []. Qed.
Lemma set1gP x : reflect (x = 1) (x \in [1 gT]).
Proof. exact: set1P. Qed.
Lemma mulg_set1 x y : [set x] :* y = [set x * y].
Proof. by rewrite [_ * _]imset2_set1l imset_set1. Qed.
Lemma invg_set1 x : [set x]^-1 = [set x^-1].
Proof. by apply/setP=> y; rewrite !inE inv_eq //; apply: invgK. Qed.
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. by rewrite [_ * _]imset2_set1l. Qed.
Lemma card_lcoset A x : #|x *: A| = #|A|.
Proof. by rewrite -lcosetE (card_imset _ (mulgI _)). Qed.
Lemma mem_lcoset A x y : (y \in x *: A) = (x^-1 * y \in A).
Proof. by rewrite -lcosetE [_ x](can_imset_pre _ (mulKg _)) inE. Qed.
Lemma lcosetP A x y : reflect (exists2 a, a \in A & y = x * a) (y \in x *: A).
Proof. by rewrite -lcosetE; apply: imsetP. Qed.
Lemma lcosetsP A B C :
reflect (exists2 x, x \in B & C = x *: A) (C \in lcosets A B).
Proof. by apply: (iffP imsetP) => [] [x Bx ->]; exists x; rewrite ?lcosetE. Qed.
Lemma lcosetM A x y : (x * y) *: A = x *: (y *: A).
Proof. by rewrite -mulg_set1 mulgA. Qed.
Lemma lcoset1 A : 1 *: A = A.
Proof. exact: mul1g. Qed.
Lemma lcosetK : left_loop invg (fun x A => x *: A).
Proof. by move=> x A; rewrite -lcosetM mulVg mul1g. Qed.
Lemma lcosetKV : rev_left_loop invg (fun x A => x *: A).
Proof. by move=> x A; rewrite -lcosetM mulgV mul1g. Qed.
Lemma lcoset_inj : right_injective (fun x A => x *: A).
Proof. by move=> x; apply: can_inj (lcosetK x). Qed.
Lemma lcosetS x A B : (x *: A \subset x *: B) = (A \subset B).
Proof.
apply/idP/idP=> sAB; last exact: mulgS.
by rewrite -(lcosetK x A) -(lcosetK x B) mulgS.
Qed.
Lemma sub_lcoset x A B : (A \subset x *: B) = (x^-1 *: A \subset B).
Proof. by rewrite -(lcosetS x^-1) lcosetK. Qed.
Lemma sub_lcosetV x A B : (A \subset x^-1 *: B) = (x *: A \subset B).
Proof. by rewrite sub_lcoset invgK. Qed.
(* Right cosets. *)
Lemma rcosetE A x : rcoset A x = A :* x.
Proof. by rewrite [_ * _]imset2_set1r. Qed.
Lemma card_rcoset A x : #|A :* x| = #|A|.
Proof. by rewrite -rcosetE (card_imset _ (mulIg _)). Qed.
Lemma mem_rcoset A x y : (y \in A :* x) = (y * x^-1 \in A).
Proof. by rewrite -rcosetE [_ x](can_imset_pre A (mulgK _)) inE. Qed.
Lemma rcosetP A x y : reflect (exists2 a, a \in A & y = a * x) (y \in A :* x).
Proof. by rewrite -rcosetE; apply: imsetP. Qed.
Lemma rcosetsP A B C :
reflect (exists2 x, x \in B & C = A :* x) (C \in rcosets A B).
Proof. by apply: (iffP imsetP) => [] [x Bx ->]; exists x; rewrite ?rcosetE. Qed.
Lemma rcosetM A x y : A :* (x * y) = A :* x :* y.
Proof. by rewrite -mulg_set1 mulgA. Qed.
Lemma rcoset1 A : A :* 1 = A.
Proof. exact: mulg1. Qed.
Lemma rcosetK : right_loop invg (fun A x => A :* x).
Proof. by move=> x A; rewrite -rcosetM mulgV mulg1. Qed.
Lemma rcosetKV : rev_right_loop invg (fun A x => A :* x).
Proof. by move=> x A; rewrite -rcosetM mulVg mulg1. Qed.
Lemma rcoset_inj : left_injective (fun A x => A :* x).
Proof. by move=> x; apply: can_inj (rcosetK x). Qed.
Lemma rcosetS x A B : (A :* x \subset B :* x) = (A \subset B).
Proof.
apply/idP/idP=> sAB; last exact: mulSg.
by rewrite -(rcosetK x A) -(rcosetK x B) mulSg.
Qed.
Lemma sub_rcoset x A B : (A \subset B :* x) = (A :* x ^-1 \subset B).
Proof. by rewrite -(rcosetS x^-1) rcosetK. Qed.
Lemma sub_rcosetV x A B : (A \subset B :* x^-1) = (A :* x \subset B).
Proof. by rewrite sub_rcoset invgK. Qed.
(* Inverse maps lcosets to rcosets *)
Lemma invg_lcosets A B : (lcosets A B)^-1 = rcosets A^-1 B^-1.
Proof.
rewrite /A^-1/= - -[RHS]imset_comp -imset_comp.
by apply: eq_imset => x /=; rewrite lcosetE rcosetE invMg invg_set1.
Qed.
(* Conjugates. *)
Lemma conjg_preim A x : A :^ x = (conjg^~ x^-1) @^-1: A.
Proof. exact: can_imset_pre (conjgK _). Qed.
Lemma mem_conjg A x y : (y \in A :^ x) = (y ^ x^-1 \in A).
Proof. by rewrite conjg_preim inE. Qed.
Lemma mem_conjgV A x y : (y \in A :^ x^-1) = (y ^ x \in A).
Proof. by rewrite mem_conjg invgK. Qed.
Lemma memJ_conjg A x y : (y ^ x \in A :^ x) = (y \in A).
Proof. by rewrite mem_conjg conjgK. Qed.
Lemma conjsgE A x : A :^ x = x^-1 *: (A :* x).
Proof. by apply/setP=> y; rewrite mem_lcoset mem_rcoset -mulgA mem_conjg. Qed.
Lemma conjsg1 A : A :^ 1 = A.
Proof. by rewrite conjsgE invg1 mul1g mulg1. Qed.
Lemma conjsgM A x y : A :^ (x * y) = (A :^ x) :^ y.
Proof. by rewrite !conjsgE invMg -!mulg_set1 !mulgA. Qed.
Lemma conjsgK : @right_loop _ gT invg conjugate.
Proof. by move=> x A; rewrite -conjsgM mulgV conjsg1. Qed.
Lemma conjsgKV : @rev_right_loop _ gT invg conjugate.
Proof. by move=> x A; rewrite -conjsgM mulVg conjsg1. Qed.
Lemma conjsg_inj : @left_injective _ gT _ conjugate.
Proof. by move=> x; apply: can_inj (conjsgK x). Qed.
Lemma cardJg A x : #|A :^ x| = #|A|.
Proof. by rewrite (card_imset _ (conjg_inj x)). Qed.
Lemma conjSg A B x : (A :^ x \subset B :^ x) = (A \subset B).
Proof. by rewrite !conjsgE lcosetS rcosetS. Qed.
Lemma properJ A B x : (A :^ x \proper B :^ x) = (A \proper B).
Proof. by rewrite /proper !conjSg. Qed.
Lemma sub_conjg A B x : (A :^ x \subset B) = (A \subset B :^ x^-1).
Proof. by rewrite -(conjSg A _ x) conjsgKV. Qed.
Lemma sub_conjgV A B x : (A :^ x^-1 \subset B) = (A \subset B :^ x).
Proof. by rewrite -(conjSg _ B x) conjsgKV. Qed.
Lemma conjg_set1 x y : [set x] :^ y = [set x ^ y].
Proof. by rewrite [_ :^ _]imset_set1. Qed.
Lemma conjs1g x : 1 :^ x = 1.
Proof. by rewrite conjg_set1 conj1g. Qed.
Lemma conjsg_eq1 A x : (A :^ x == 1%g) = (A == 1%g).
Proof. by rewrite (canF_eq (conjsgK x)) conjs1g. Qed.
Lemma conjsMg A B x : (A * B) :^ x = A :^ x * B :^ x.
Proof. by rewrite !conjsgE !mulgA rcosetK. Qed.
Lemma conjIg A B x : (A :&: B) :^ x = A :^ x :&: B :^ x.
Proof. by rewrite !conjg_preim preimsetI. Qed.
Lemma conj0g x : set0 :^ x = set0.
Proof. exact: imset0. Qed.
Lemma conjTg x : [set: gT] :^ x = [set: gT].
Proof. by rewrite conjg_preim preimsetT. Qed.
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.
by rewrite (big_endo (conjugate^~ x)) => // [B1 B2|]; rewrite (conjTg, conjIg).
Qed.
Lemma conjUg A B x : (A :|: B) :^ x = A :^ x :|: B :^ x.
Proof. by rewrite !conjg_preim preimsetU. Qed.
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.
rewrite (big_endo (conjugate^~ x)) => // [B1 B2|]; first by rewrite conjUg.
exact: imset0.
Qed.
Lemma conjCg A x : (~: A) :^ x = ~: A :^ x.
Proof. by rewrite !conjg_preim preimsetC. Qed.
Lemma conjDg A B x : (A :\: B) :^ x = A :^ x :\: B :^ x.
Proof. by rewrite !setDE !(conjCg, conjIg). Qed.
Lemma conjD1g A x : A^# :^ x = (A :^ x)^#.
Proof. by rewrite conjDg conjs1g. Qed.
(* Classes; not much for now. *)
Lemma memJ_class x y A : y \in A -> x ^ y \in x ^: A.
Proof. exact: imset_f. Qed.
Lemma classS x A B : A \subset B -> x ^: A \subset x ^: B.
Proof. exact: imsetS. Qed.
Lemma class_set1 x y : x ^: [set y] = [set x ^ y].
Proof. exact: imset_set1. Qed.
Lemma class1g x A : x \in A -> 1 ^: A = 1.
Proof.
move=> Ax; apply/setP=> y.
by apply/imsetP/set1P=> [[a Aa]|] ->; last exists x; rewrite ?conj1g.
Qed.
Lemma classVg x A : x^-1 ^: A = (x ^: A)^-1.
Proof.
apply/setP=> xy; rewrite inE; apply/imsetP/imsetP=> [] [y Ay def_xy].
by rewrite def_xy conjVg invgK; exists y.
by rewrite -[xy]invgK def_xy -conjVg; exists y.
Qed.
Lemma mem_classes x A : x \in A -> x ^: A \in classes A.
Proof. exact: imset_f. Qed.
Lemma memJ_class_support A B x y :
x \in A -> y \in B -> x ^ y \in class_support A B.
Proof. by move=> Ax By; apply: imset2_f. Qed.
Lemma class_supportM A B C :
class_support A (B * C) = class_support (class_support A B) C.
Proof.
apply/setP=> x; apply/imset2P/imset2P=> [[a y Aa] | [y c]].
case/mulsgP=> b c Bb Cc -> ->{x y}.
by exists (a ^ b) c; rewrite ?(imset2_f, conjgM).
case/imset2P=> a b Aa Bb -> Cc ->{x y}.
by exists a (b * c); rewrite ?(mem_mulg, conjgM).
Qed.
Lemma class_support_set1l A x : class_support [set x] A = x ^: A.
Proof. exact: imset2_set1l. Qed.
Lemma class_support_set1r A x : class_support A [set x] = A :^ x.
Proof. exact: imset2_set1r. Qed.
Lemma classM x A B : x ^: (A * B) = class_support (x ^: A) B.
Proof. by rewrite -!class_support_set1l class_supportM. Qed.
Lemma class_lcoset x y A : x ^: (y *: A) = (x ^ y) ^: A.
Proof. by rewrite classM class_set1 class_support_set1l. Qed.
Lemma class_rcoset x A y : x ^: (A :* y) = (x ^: A) :^ y.
Proof. by rewrite -class_support_set1r classM. Qed.
(* Conjugate set. *)
Lemma conjugatesS A B C : B \subset C -> A :^: B \subset A :^: C.
Proof. exact: imsetS. Qed.
Lemma conjugates_set1 A x : A :^: [set x] = [set A :^ x].
Proof. exact: imset_set1. Qed.
Lemma conjugates_conj A x B : (A :^ x) :^: B = A :^: (x *: B).
Proof.
rewrite /conjugates [x *: B]imset2_set1l -imset_comp.
by apply: eq_imset => y /=; rewrite conjsgM.
Qed.
(* Class support. *)
Lemma class_supportEl A B : class_support A B = \bigcup_(x in A) x ^: B.
Proof. exact: curry_imset2l. Qed.
Lemma class_supportEr A B : class_support A B = \bigcup_(x in B) A :^ x.
Proof. exact: curry_imset2r. Qed.
(* 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.
apply: (iffP andP) => [] [A1 AM]; split=> {A1}//.
by move=> x y Ax Ay; apply: (subsetP AM); rewrite mem_mulg.
by apply/subsetP=> _ /mulsgP[x y Ax Ay ->]; apply: AM.
Qed.
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 baseFinGroupType 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. exact: val_inj. Qed.
Lemma groupP (G : groupT) : group_set G. Proof. by case: G. Qed.
Lemma congr_group (H K : groupT) : H = K -> H :=: K.
Proof. exact: congr1. Qed.
Lemma isgroupP A : reflect (exists G : groupT, A = G) (group_set A).
Proof. by apply: (iffP idP) => [gA | [[B gB] -> //]]; exists (Group gA). Qed.
Lemma group_set_one : group_set 1.
Proof. by rewrite /group_set set11 mulg1 subxx. Qed.
Canonical one_group := group group_set_one.
Canonical set1_group := @group [set 1] group_set_one.
Lemma group_setT : group_set (setTfor gT).
Proof. by apply/group_setP; split=> [|x y _ _]; rewrite inE. Qed.
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 := (BaseFinGroup.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. by []. Qed.
(* Non-triviality. *)
Lemma group1 : 1 \in G. Proof. by case/group_setP: (valP G). Qed.
#[local] Hint Resolve group1 : core.
Lemma group1_contra x : x \notin G -> x != 1.
Proof. by apply: contraNneq => ->. Qed.
Lemma sub1G : [1 gT] \subset G. Proof. by rewrite sub1set. Qed.
Lemma subG1 : (G \subset [1]) = (G :==: 1).
Proof. by rewrite eqEsubset sub1G andbT. Qed.
Lemma setI1g : 1 :&: G = 1. Proof. exact: (setIidPl sub1G). Qed.
Lemma setIg1 : G :&: 1 = 1. Proof. exact: (setIidPr sub1G). Qed.
Lemma subG1_contra H : G \subset H -> G :!=: 1 -> H :!=: 1.
Proof. by move=> sGH; rewrite -subG1; apply: contraNneq => <-. Qed.
Lemma repr_group : repr G = 1. Proof. by rewrite /repr group1. Qed.
Lemma cardG_gt0 : 0 < #|G|.
Proof. by rewrite lt0n; apply/existsP; exists (1 : gT). Qed.
Lemma indexg_gt0 A : 0 < #|G : A|.
Proof.
rewrite lt0n; apply/existsP; exists A.
by rewrite -{2}[A]mulg1 -rcosetE; apply: imset_f.
Qed.
Lemma trivgP : reflect (G :=: 1) (G \subset [1]).
Proof. by rewrite subG1; apply: eqP. Qed.
Lemma trivGP : reflect (G = 1%G) (G \subset [1]).
Proof. by rewrite subG1; apply: eqP. Qed.
Lemma proper1G : ([1] \proper G) = (G :!=: 1).
Proof. by rewrite properEneq sub1G andbT eq_sym. Qed.
Lemma in_one_group x : (x \in 1%G) = (x == 1).
Proof. by rewrite -[x \in _]/(x \in [set 1]) !inE. Qed.
Definition inE := (in_one_group, inE).
Lemma trivgPn : reflect (exists2 x, x \in G & x != 1) (G :!=: 1).
Proof.
rewrite -subG1.
by apply: (iffP subsetPn) => [] [x Gx x1]; exists x; rewrite ?inE in x1 *.
Qed.
Lemma trivg_card_le1 : (G :==: 1) = (#|G| <= 1).
Proof. by rewrite eq_sym eqEcard cards1 sub1G. Qed.
Lemma trivg_card1 : (G :==: 1) = (#|G| == 1%N).
Proof. by rewrite trivg_card_le1 eqn_leq cardG_gt0 andbT. Qed.
Lemma cardG_gt1 : (#|G| > 1) = (G :!=: 1).
Proof. by rewrite trivg_card_le1 ltnNge. Qed.
Lemma card_le1_trivg : #|G| <= 1 -> G :=: 1.
Proof. by rewrite -trivg_card_le1; move/eqP. Qed.
Lemma card1_trivg : #|G| = 1%N -> G :=: 1.
Proof. by move=> G1; rewrite card_le1_trivg ?G1. Qed.
(* Inclusion and product. *)
Lemma mulG_subl A : A \subset A * G.
Proof. exact: mulg_subl group1. Qed.
Lemma mulG_subr A : A \subset ((G : {set gT}) * A ).
Proof. exact: mulg_subr group1. Qed.
Lemma mulGid : (G : {set gT}) * G = G.
Proof.
by apply/eqP; rewrite eqEsubset mulG_subr andbT; case/andP: (valP G).
Qed.
Lemma mulGS A B : (G * A \subset G * B) = (A \subset G * B).
Proof.
apply/idP/idP; first exact: subset_trans (mulG_subr A).
by move/(mulgS G); rewrite mulgA mulGid.
Qed.
Lemma mulSG A B : (A * G \subset B * G) = (A \subset B * G).
Proof.
apply/idP/idP; first exact: subset_trans (mulG_subl A).
by move/(mulSg G); rewrite -mulgA mulGid.
Qed.
Lemma mul_subG A B : A \subset G -> B \subset G -> A * B \subset G.
Proof. by move=> sAG sBG; rewrite -mulGid mulgSS. Qed.
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.
move=> subFG; elim/big_rec: _ => [|/= i A /subFG]; first by rewrite sub1set.
exact: mul_subG.
Qed.
(* Membership lemmas *)
Lemma groupM x y : x \in G -> y \in G -> x * y \in G.
Proof. by case/group_setP: (valP G) x y. Qed.
Lemma groupX x n : x \in G -> x ^+ n \in G.
Proof. by move=> Gx; elim: n => [|n IHn]; rewrite ?group1 // expgS groupM. Qed.
Lemma groupVr x : x \in G -> x^-1 \in G.
Proof.
move=> Gx; rewrite -(mul1g x^-1) -mem_rcoset ((G :* x =P G) _) //.
by rewrite eqEcard card_rcoset leqnn mul_subG ?sub1set.
Qed.
Lemma groupVl x : x^-1 \in G -> x \in G.
Proof. by move/groupVr; rewrite invgK. Qed.
Lemma groupV x : (x^-1 \in G) = (x \in G).
Proof. by apply/idP/idP; [apply: groupVl | apply: groupVr]. Qed.
Lemma groupMl x y : x \in G -> (x * y \in G) = (y \in G).
Proof.
move=> Gx; apply/idP/idP=> [Gxy|]; last exact: groupM.
by rewrite -(mulKg x y) groupM ?groupVr.
Qed.
Lemma groupMr x y : x \in G -> (y * x \in G) = (y \in G).
Proof. by move=> Gx; rewrite -[_ \in G]groupV invMg groupMl groupV. Qed.
Definition in_group := (group1, groupV, (groupMl, groupX)).
Lemma groupJ x y : x \in G -> y \in G -> x ^ y \in G.
Proof. by move=> Gx Gy; rewrite !in_group. Qed.
Lemma groupJr x y : y \in G -> (x ^ y \in G) = (x \in G).
Proof. by move=> Gy; rewrite groupMl (groupMr, groupV). Qed.
Lemma groupR x y : x \in G -> y \in G -> [~ x, y] \in G.
Proof. by move=> Gx Gy; rewrite !in_group. Qed.
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. by move=> G_P; elim/big_ind: _ => //; apply: groupM. Qed.
(* Inverse is an anti-morphism. *)
Lemma invGid : G^-1 = G. Proof. by apply/setP=> x; rewrite inE groupV. Qed.
Lemma inv_subG A : (A^-1 \subset G) = (A \subset G).
Proof. by rewrite -{1}invGid invSg. Qed.
Lemma invg_lcoset x : (x *: G)^-1 = G :* x^-1.
Proof. by rewrite invMg invGid invg_set1. Qed.
Lemma invg_rcoset x : (G :* x)^-1 = x^-1 *: G.
Proof. by rewrite invMg invGid invg_set1. Qed.
Lemma memV_lcosetV x y : (y^-1 \in x^-1 *: G) = (y \in G :* x).
Proof. by rewrite -invg_rcoset memV_invg. Qed.
Lemma memV_rcosetV x y : (y^-1 \in G :* x^-1) = (y \in x *: G).
Proof. by rewrite -invg_lcoset memV_invg. Qed.
(* Product idempotence *)
Lemma mulSgGid A x : x \in A -> A \subset G -> A * G = G.
Proof.
move=> Ax sAG; apply/eqP; rewrite eqEsubset -{2}mulGid mulSg //=.
apply/subsetP=> y Gy; rewrite -(mulKVg x y) mem_mulg // groupMr // groupV.
exact: (subsetP sAG).
Qed.
Lemma mulGSgid A x : x \in A -> A \subset G -> G * A = G.
Proof.
rewrite -memV_invg -invSg invGid => Ax sAG.
by apply: invg_inj; rewrite invMg invGid (mulSgGid Ax).
Qed.
(* Left cosets *)
Lemma lcoset_refl x : x \in x *: G.
Proof. by rewrite mem_lcoset mulVg group1. Qed.
Lemma lcoset_sym x y : (x \in y *: G) = (y \in x *: G).
Proof. by rewrite !mem_lcoset -groupV invMg invgK. Qed.
Lemma lcoset_eqP {x y} : reflect (x *: G = y *: G) (x \in y *: G).
Proof.
suffices <-: (x *: G == y *: G) = (x \in y *: G) by apply: eqP.
by rewrite eqEsubset !mulSG !sub1set lcoset_sym andbb.
Qed.
Lemma lcoset_transl x y z : x \in y *: G -> (x \in z *: G) = (y \in z *: G).
Proof. by move=> Gyx; rewrite -2!(lcoset_sym z) (lcoset_eqP Gyx). Qed.
Lemma lcoset_trans x y z : x \in y *: G -> y \in z *: G -> x \in z *: G.
Proof. by move/lcoset_transl->. Qed.
Lemma lcoset_id x : x \in G -> x *: G = G.
Proof. by move=> Gx; rewrite (lcoset_eqP (_ : x \in 1 *: G)) mul1g. Qed.
(* Right cosets, with an elimination form for repr. *)
Lemma rcoset_refl x : x \in G :* x.
Proof. by rewrite mem_rcoset mulgV group1. Qed.
Lemma rcoset_sym x y : (x \in G :* y) = (y \in G :* x).
Proof. by rewrite -!memV_lcosetV lcoset_sym. Qed.
Lemma rcoset_eqP {x y} : reflect (G :* x = G :* y) (x \in G :* y).
Proof.
suffices <-: (G :* x == G :* y) = (x \in G :* y) by apply: eqP.
by rewrite eqEsubset !mulGS !sub1set rcoset_sym andbb.
Qed.
Lemma rcoset_transl x y z : x \in G :* y -> (x \in G :* z) = (y \in G :* z).
Proof. by move=> Gyx; rewrite -2!(rcoset_sym z) (rcoset_eqP Gyx). Qed.
Lemma rcoset_trans x y z : x \in G :* y -> y \in G :* z -> x \in G :* z.
Proof. by move/rcoset_transl->. Qed.
Lemma rcoset_id x : x \in G -> G :* x = G.
Proof. by move=> Gx; rewrite (rcoset_eqP (_ : x \in G :* 1)) mulg1. Qed.
(* 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. exact: mem_repr (rcoset_refl x). Qed.
(* 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.
by rewrite -[repr _](mulgKV x); split; rewrite -mem_rcoset mem_repr_rcoset.
Qed.
Lemma rcoset_repr x : G :* (repr (G :* x)) = G :* x.
Proof. exact/rcoset_eqP/mem_repr_rcoset. Qed.
(* Coset spaces. *)
Lemma mem_rcosets A x : (G :* x \in rcosets G A) = (x \in G * A).
Proof.
apply/rcosetsP/mulsgP=> [[a Aa /rcoset_eqP/rcosetP[g]] | ]; first by exists g a.
by case=> g a Gg Aa ->{x}; exists a; rewrite // rcosetM rcoset_id.
Qed.
Lemma mem_lcosets A x : (x *: G \in lcosets G A) = (x \in A * G).
Proof.
rewrite -[LHS]memV_invg invg_lcoset invg_lcosets.
by rewrite -[RHS]memV_invg invMg invGid mem_rcosets.
Qed.
(* Conjugates. *)
Lemma group_setJ A x : group_set (A :^ x) = group_set A.
Proof. by rewrite /group_set mem_conjg conj1g -conjsMg conjSg. Qed.
Lemma group_set_conjG x : group_set (G :^ x).
Proof. by rewrite group_setJ groupP. Qed.
Canonical conjG_group x := group (group_set_conjG x).
Lemma conjGid : {in G, normalised G}.
Proof. by move=> x Gx; apply/setP=> y; rewrite mem_conjg groupJr ?groupV. Qed.
Lemma conj_subG x A : x \in G -> A \subset G -> A :^ x \subset G.
Proof. by move=> Gx sAG; rewrite -(conjGid Gx) conjSg. Qed.
(* Classes *)
Lemma class1G : 1 ^: G = 1. Proof. exact: class1g group1. Qed.
Lemma classes1 : [1] \in classes G. Proof. by rewrite -class1G mem_classes. Qed.
Lemma classGidl x y : y \in G -> (x ^ y) ^: G = x ^: G.
Proof. by move=> Gy; rewrite -class_lcoset lcoset_id. Qed.
Lemma classGidr x : {in G, normalised (x ^: G)}.
Proof. by move=> y Gy /=; rewrite -class_rcoset rcoset_id. Qed.
Lemma class_refl x : x \in x ^: G.
Proof. by apply/imsetP; exists 1; rewrite ?conjg1. Qed.
#[local] Hint Resolve class_refl : core.
Lemma class_eqP x y : reflect (x ^: G = y ^: G) (x \in y ^: G).
Proof.
by apply: (iffP idP) => [/imsetP[z Gz ->] | <-]; rewrite ?class_refl ?classGidl.
Qed.
Lemma class_sym x y : (x \in y ^: G) = (y \in x ^: G).
Proof. by apply/idP/idP=> /class_eqP->. Qed.
Lemma class_transl x y z : x \in y ^: G -> (x \in z ^: G) = (y \in z ^: G).
Proof. by rewrite -!(class_sym z) => /class_eqP->. Qed.
Lemma class_trans x y z : x \in y ^: G -> y \in z ^: G -> x \in z ^: G.
Proof. by move/class_transl->. Qed.
Lemma repr_class x : {y | y \in G & repr (x ^: G) = x ^ y}.
Proof.
set z := repr _; have: #|[set y in G | z == x ^ y]| > 0.
have: z \in x ^: G by apply: (mem_repr x).
by case/imsetP=> y Gy ->; rewrite (cardD1 y) inE Gy eqxx.
by move/card_mem_repr; move: (repr _) => y /setIdP[Gy /eqP]; exists y.
Qed.
Lemma classG_eq1 x : (x ^: G == 1) = (x == 1).
Proof.
apply/eqP/eqP=> [xG1 | ->]; last exact: class1G.
by have:= class_refl x; rewrite xG1 => /set1P.
Qed.
Lemma class_subG x A : x \in G -> A \subset G -> x ^: A \subset G.
Proof.
move=> Gx sAG; apply/subsetP=> _ /imsetP[y Ay ->].
by rewrite groupJ // (subsetP sAG).
Qed.
Lemma repr_classesP xG :
reflect (repr xG \in G /\ xG = repr xG ^: G) (xG \in classes G).
Proof.
apply: (iffP imsetP) => [[x Gx ->] | []]; last by exists (repr xG).
by have [y Gy ->] := repr_class x; rewrite classGidl ?groupJ.
Qed.
Lemma mem_repr_classes xG : xG \in classes G -> repr xG \in xG.
Proof. by case/repr_classesP=> _ {2}->; apply: class_refl. Qed.
Lemma classes_gt0 : 0 < #|classes G|.
Proof. by rewrite (cardsD1 1) classes1. Qed.
Lemma classes_gt1 : (#|classes G| > 1) = (G :!=: 1).
Proof.
rewrite (cardsD1 1) classes1 ltnS lt0n cards_eq0.
apply/set0Pn/trivgPn=> [[xG /setD1P[nt_xG]] | [x Gx ntx]].
by case/imsetP=> x Gx def_xG; rewrite def_xG classG_eq1 in nt_xG; exists x.
by exists (x ^: G); rewrite !inE classG_eq1 ntx; apply: imset_f.
Qed.
Lemma mem_class_support A x : x \in A -> x \in class_support A G.
Proof. by move=> Ax; rewrite -[x]conjg1 memJ_class_support. Qed.
Lemma class_supportGidl A x :
x \in G -> class_support (A :^ x) G = class_support A G.
Proof.
by move=> Gx; rewrite -class_support_set1r -class_supportM lcoset_id.
Qed.
Lemma class_supportGidr A : {in G, normalised (class_support A G)}.
Proof.
by move=> x Gx /=; rewrite -class_support_set1r -class_supportM rcoset_id.
Qed.
Lemma class_support_subG A : A \subset G -> class_support A G \subset G.
Proof.
by move=> sAG; rewrite class_supportEr; apply/bigcupsP=> x Gx; apply: conj_subG.
Qed.
Lemma sub_class_support A : A \subset class_support A G.
Proof. by rewrite class_supportEr (bigcup_max 1) ?conjsg1. Qed.
Lemma class_support_id : class_support G G = G.
Proof.
by apply/eqP; rewrite eqEsubset sub_class_support class_support_subG.
Qed.
Lemma class_supportD1 A : (class_support A G)^# = cover (A^# :^: G).
Proof.
rewrite cover_imset class_supportEr setDE big_distrl /=.
by apply: eq_bigr => x _; rewrite -setDE conjD1g.
Qed.
(* 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. exact: valP. Qed.
Lemma subg_inj : injective sgval.
Proof. exact: val_inj. Qed.
Lemma congr_subg u v : u = v -> sgval u = sgval v.
Proof. exact: congr1. Qed.
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. by move=> u; apply: val_inj; apply: mul1g. Qed.
Lemma subg_invP : left_inverse subg_one subg_inv subg_mul.
Proof. by move=> u; apply: val_inj; apply: mulVg. Qed.
Lemma subg_mulP : associative subg_mul.
Proof. by move=> u v w; apply: val_inj; apply: mulgA. Qed.
HB.instance Definition _ := isMulGroup.Build subg_of
subg_mulP subg_oneP subg_invP.
Lemma sgvalM : {in setT &, {morph sgval : x y / x * y}}. Proof. by []. Qed.
Lemma valgM : {in setT &, {morph val : x y / (x : subg_of) * y >-> x * y}}.
Proof. by []. Qed.
Definition subg : gT -> subg_of := insubd (1 : subg_of).
Lemma subgK x : x \in G -> val (subg x) = x.
Proof. by move=> Gx; rewrite insubdK. Qed.
Lemma sgvalK : cancel sgval subg.
Proof. by case=> x Gx; apply: val_inj; apply: subgK. Qed.
Lemma subg_default x : (x \in G) = false -> val (subg x) = 1.
Proof. by move=> Gx; rewrite val_insubd Gx. Qed.
Lemma subgM : {in G &, {morph subg : x y / x * y}}.
Proof. by move=> x y Gx Gy; apply: val_inj; rewrite /= !subgK ?groupM. Qed.
End OneGroup.
#[local] Hint Resolve group1 : core.
Lemma groupD1_inj G H : G^# = H^# -> G :=: H.
Proof. by move/(congr1 (setU 1)); rewrite !setD1K. Qed.
Lemma invMG G H : (G * H)^-1 = H * G.
Proof. by rewrite invMg !invGid. Qed.
Lemma mulSGid G H : H \subset G -> H * G = G.
Proof. exact: mulSgGid (group1 H). Qed.
Lemma mulGSid G H : H \subset G -> G * H = G.
Proof. exact: mulGSgid (group1 H). Qed.
Lemma mulGidPl G H : reflect (G * H = G) (H \subset G).
Proof. by apply: (iffP idP) => [|<-]; [apply: mulGSid | apply: mulG_subr]. Qed.
Lemma mulGidPr G H : reflect (G * H = H) (G \subset H).
Proof. by apply: (iffP idP) => [|<-]; [apply: mulSGid | apply: mulG_subl]. Qed.
Lemma comm_group_setP G H : reflect (commute G H) (group_set (G * H)).
Proof.
rewrite /group_set (subsetP (mulG_subl _ _)) ?group1 // andbC.
have <-: #|G * H| <= #|H * G| by rewrite -invMG card_invg.
by rewrite -mulgA mulGS mulgA mulSG -eqEcard eq_sym; apply: eqP.
Qed.
Lemma card_lcosets G H : #|lcosets H G| = #|G : H|.
Proof. by rewrite -card_invg invg_lcosets !invGid. Qed.
(* Group Modularity equations *)
Lemma group_modl A B G : A \subset G -> A * (B :&: G) = A * B :&: G.
Proof.
move=> sAG; apply/eqP; rewrite eqEsubset subsetI mulgS ?subsetIl //.
rewrite -{2}mulGid mulgSS ?subsetIr //.
apply/subsetP => _ /setIP[/mulsgP[a b Aa Bb ->] Gab].
by rewrite mem_mulg // inE Bb -(groupMl _ (subsetP sAG _ Aa)).
Qed.
Lemma group_modr A B G : B \subset G -> (G :&: A) * B = G :&: A * B.
Proof.
move=> sBG; apply: invg_inj; rewrite !(invMg, invIg) invGid !(setIC G).
by rewrite group_modl // -invGid invSg.
Qed.
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.
apply/group_setP; split=> [|x y]; rewrite !inE ?group1 //.
by case/andP=> Gx Hx; rewrite !groupMl.
Qed.
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.
by elim/big_rec: _ => [|i G _ gG]; rewrite -1?(insubdK 1%G gG) groupP.
Qed.
Canonical bigcap_group := group group_set_bigcap.
End Nary.
Lemma group_set_generated (A : {set gT}) : group_set <<A>>.
Proof. by rewrite unlock group_set_bigcap. Qed.
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. exact: cardG_gt0. Qed.
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.
rewrite -[#|G|]sum1_card (partition_big_imset (rcoset H)) /=.
rewrite mulnC -sum_nat_const; apply: eq_bigr => _ /rcosetsP[x Gx ->].
rewrite -(card_rcoset _ x) -sum1_card; apply: eq_bigl => y.
by rewrite rcosetE (sameP eqP rcoset_eqP) group_modr ?sub1set // !inE.
Qed.
Lemma divgI G H : #|G| %/ #|G :&: H| = #|G : H|.
Proof. by rewrite -(LagrangeI G H) mulKn ?cardG_gt0. Qed.
Lemma divg_index G H : #|G| %/ #|G : H| = #|G :&: H|.
Proof. by rewrite -(LagrangeI G H) mulnK. Qed.
Lemma dvdn_indexg G H : #|G : H| %| #|G|.
Proof. by rewrite -(LagrangeI G H) dvdn_mull. Qed.
Theorem Lagrange G H : H \subset G -> (#|H| * #|G : H|)%N = #|G|.
Proof. by move/setIidPr=> sHG; rewrite -{1}sHG LagrangeI. Qed.
Lemma cardSg G H : H \subset G -> #|H| %| #|G|.
Proof. by move/Lagrange <-; rewrite dvdn_mulr. Qed.
Lemma lognSg p G H : G \subset H -> logn p #|G| <= logn p #|H|.
Proof. by move=> sGH; rewrite dvdn_leq_log ?cardSg. Qed.
Lemma piSg G H : G \subset H -> {subset \pi(gval G) <= \pi(gval H)}.
Proof.
move=> sGH p; rewrite !mem_primes !cardG_gt0 => /and3P[-> _ pG].
exact: dvdn_trans (cardSg sGH).
Qed.
Lemma divgS G H : H \subset G -> #|G| %/ #|H| = #|G : H|.
Proof. by move/Lagrange <-; rewrite mulKn. Qed.
Lemma divg_indexS G H : H \subset G -> #|G| %/ #|G : H| = #|H|.
Proof. by move/Lagrange <-; rewrite mulnK. Qed.
Lemma coprimeSg G H p : H \subset G -> coprime #|G| p -> coprime #|H| p.
Proof. by move=> sHG; apply: coprime_dvdl (cardSg sHG). Qed.
Lemma coprimegS G H p : H \subset G -> coprime p #|G| -> coprime p #|H|.
Proof. by move=> sHG; apply: coprime_dvdr (cardSg sHG). Qed.
Lemma indexJg G H x : #|G :^ x : H :^ x| = #|G : H|.
Proof. by rewrite -!divgI -conjIg !cardJg. Qed.
Lemma indexgg G : #|G : G| = 1%N.
Proof. by rewrite -divgS // divnn cardG_gt0. Qed.
Lemma rcosets_id G : rcosets G G = [set G : {set gT}].
Proof.
apply/esym/eqP; rewrite eqEcard sub1set [#|_|]indexgg cards1 andbT.
by apply/rcosetsP; exists 1; rewrite ?mulg1.
Qed.
Lemma Lagrange_index G H K :
H \subset G -> K \subset H -> (#|G : H| * #|H : K|)%N = #|G : K|.
Proof.
move=> sHG sKH; apply/eqP; rewrite mulnC -(eqn_pmul2l (cardG_gt0 K)).
by rewrite mulnA !Lagrange // (subset_trans sKH).
Qed.
Lemma indexgI G H : #|G : G :&: H| = #|G : H|.
Proof. by rewrite -[RHS]divgI divgS ?subsetIl. Qed.
Lemma indexgS G H K : H \subset K -> #|G : K| %| #|G : H|.
Proof.
move=> sHK; rewrite -(@dvdn_pmul2l #|G :&: K|) ?cardG_gt0 // LagrangeI.
by rewrite -(Lagrange (setIS G sHK)) mulnAC LagrangeI dvdn_mulr.
Qed.
Lemma indexSg G H K : H \subset K -> K \subset G -> #|K : H| %| #|G : H|.
Proof.
move=> sHK sKG; rewrite -(@dvdn_pmul2l #|H|) ?cardG_gt0 //.
by rewrite !Lagrange ?(cardSg, subset_trans sHK).
Qed.
Lemma indexg_eq1 G H : (#|G : H| == 1%N) = (G \subset H).
Proof.
rewrite eqn_leq -(leq_pmul2l (cardG_gt0 (G :&: H))) LagrangeI muln1.
by rewrite indexg_gt0 andbT (sameP setIidPl eqP) eqEcard subsetIl.
Qed.
Lemma indexg_gt1 G H : (#|G : H| > 1) = ~~ (G \subset H).
Proof. by rewrite -indexg_eq1 eqn_leq indexg_gt0 andbT -ltnNge. Qed.
Lemma index1g G H : H \subset G -> #|G : H| = 1%N -> H :=: G.
Proof. by move=> sHG iHG; apply/eqP; rewrite eqEsubset sHG -indexg_eq1 iHG. Qed.
Lemma indexg1 G : #|G : 1| = #|G|.
Proof. by rewrite -divgS ?sub1G // cards1 divn1. Qed.
Lemma indexMg G A : #|G * A : G| = #|A : G|.
Proof.
apply/eq_card/setP/eqP; rewrite eqEsubset andbC imsetS ?mulG_subr //.
by apply/subsetP=> _ /rcosetsP[x GAx ->]; rewrite mem_rcosets.
Qed.
Lemma rcosets_partition_mul G H : partition (rcosets H G) (H * G).
Proof.
set HG := H * G; have sGHG: {subset G <= HG} by apply/subsetP/mulG_subr.
have defHx x: x \in HG -> [set y in HG | rcoset H x == rcoset H y] = H :* x.
move=> HGx; apply/setP=> y; rewrite inE !rcosetE (sameP eqP rcoset_eqP).
by rewrite rcoset_sym; apply/andb_idl/subsetP; rewrite mulGS sub1set.
have:= preim_partitionP (rcoset H) HG; congr (partition _ _); apply/setP=> Hx.
apply/imsetP/idP=> [[x HGx ->] | ]; first by rewrite defHx // mem_rcosets.
by case/rcosetsP=> x /sGHG-HGx ->; exists x; rewrite ?defHx.
Qed.
Lemma rcosets_partition G H : H \subset G -> partition (rcosets H G) G.
Proof. by move=> sHG; have:= rcosets_partition_mul G H; rewrite mulSGid. Qed.
Lemma LagrangeMl G H : (#|G| * #|H : G|)%N = #|G * H|.
Proof.
rewrite mulnC -(card_uniform_partition _ (rcosets_partition_mul H G)) //.
by move=> _ /rcosetsP[x Hx ->]; rewrite card_rcoset.
Qed.
Lemma LagrangeMr G H : (#|G : H| * #|H|)%N = #|G * H|.
Proof. by rewrite mulnC LagrangeMl -card_invg invMg !invGid. Qed.
Lemma mul_cardG G H : (#|G| * #|H| = #|G * H|%g * #|G :&: H|)%N.
Proof. by rewrite -LagrangeMr -(LagrangeI G H) -mulnA mulnC. Qed.
Lemma dvdn_cardMg G H : #|G * H| %| #|G| * #|H|.
Proof. by rewrite mul_cardG dvdn_mulr. Qed.
Lemma cardMg_divn G H : #|G * H| = (#|G| * #|H|) %/ #|G :&: H|.
Proof. by rewrite mul_cardG mulnK ?cardG_gt0. Qed.
Lemma cardIg_divn G H : #|G :&: H| = (#|G| * #|H|) %/ #|G * H|.
Proof. by rewrite mul_cardG mulKn // (cardD1 (1 * 1)) mem_mulg. Qed.
Lemma TI_cardMg G H : G :&: H = 1 -> #|G * H| = (#|G| * #|H|)%N.
Proof. by move=> tiGH; rewrite mul_cardG tiGH cards1 muln1. Qed.
Lemma cardMg_TI G H : #|G| * #|H| <= #|G * H| -> G :&: H = 1.
Proof.
move=> leGH; apply: card_le1_trivg.
rewrite -(@leq_pmul2l #|G * H|); first by rewrite -mul_cardG muln1.
by apply: leq_trans leGH; rewrite muln_gt0 !cardG_gt0.
Qed.
Lemma coprime_TIg G H : coprime #|G| #|H| -> G :&: H = 1.
Proof.
move=> coGH; apply/eqP; rewrite trivg_card1 -dvdn1 -{}(eqnP coGH).
by rewrite dvdn_gcd /= {2}setIC !cardSg ?subsetIl.
Qed.
Lemma prime_TIg G H : prime #|G| -> ~~ (G \subset H) -> G :&: H = 1.
Proof.
case/primeP=> _ /(_ _ (cardSg (subsetIl G H))).
rewrite (sameP setIidPl eqP) eqEcard subsetIl => /pred2P[/card1_trivg|] //= ->.
by case/negP.
Qed.
Lemma prime_meetG G H : prime #|G| -> G :&: H != 1 -> G \subset H.
Proof. by move=> prG; apply: contraR; move/prime_TIg->. Qed.
Lemma coprime_cardMg G H : coprime #|G| #|H| -> #|G * H| = (#|G| * #|H|)%N.
Proof. by move=> coGH; rewrite TI_cardMg ?coprime_TIg. Qed.
Lemma coprime_index_mulG G H K :
H \subset G -> K \subset G -> coprime #|G : H| #|G : K| -> H * K = G.
Proof.
move=> sHG sKG co_iG_HK; apply/eqP; rewrite eqEcard mul_subG //=.
rewrite -(@leq_pmul2r #|H :&: K|) ?cardG_gt0 // -mul_cardG.
rewrite -(Lagrange sHG) -(LagrangeI K H) mulnAC setIC -mulnA.
rewrite !leq_pmul2l ?cardG_gt0 // dvdn_leq // -(Gauss_dvdr _ co_iG_HK).
by rewrite -(indexgI K) Lagrange_index ?indexgS ?subsetIl ?subsetIr.
Qed.
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. rewrite [@generated]unlock; exact/bigcapsP. Qed.
Lemma sub_gen A B : A \subset B -> A \subset <<B>>.
Proof. by move/subset_trans=> -> //; apply: subset_gen. Qed.
Lemma mem_gen x A : x \in A -> x \in <<A>>.
Proof. exact: subsetP (subset_gen A) x. Qed.
Lemma generatedP x A : reflect (forall G, A \subset G -> x \in G) (x \in <<A>>).
Proof. rewrite [@generated]unlock; exact: bigcapP. Qed.
Lemma gen_subG A G : (<<A>> \subset G) = (A \subset G).
Proof.
apply/idP/idP=> [|sAG]; first exact: subset_trans (subset_gen A).
by apply/subsetP=> x /generatedP; apply.
Qed.
Lemma genGid G : <<G>> = G.
Proof. by apply/eqP; rewrite eqEsubset gen_subG subset_gen andbT. Qed.
Lemma genGidG G : <<G>>%G = G.
Proof. by apply: val_inj; apply: genGid. Qed.
Lemma gen_set_id A : group_set A -> <<A>> = A.
Proof. by move=> gA; apply: (genGid (group gA)). Qed.
Lemma genS A B : A \subset B -> <<A>> \subset <<B>>.
Proof. by move=> sAB; rewrite gen_subG sub_gen. Qed.
Lemma gen0 : <<set0>> = 1 :> {set gT}.
Proof. by apply/eqP; rewrite eqEsubset sub1G gen_subG sub0set. Qed.
Lemma gen_expgs A : {n | <<A>> = (1 |: A) ^+ n}.
Proof.
set B := (1 |: A); pose N := #|gT|.
have BsubG n : B ^+ n \subset <<A>>.
by elim: n => [|n IHn]; rewrite ?expgS ?mul_subG ?subUset ?sub1G ?subset_gen.
have B_1 n : 1 \in B ^+ n.
by elim: n => [|n IHn]; rewrite ?set11 // expgS mulUg mul1g inE IHn.
case: (pickP (fun i : 'I_N => B ^+ i.+1 \subset B ^+ i)) => [n fixBn | no_fix].
exists n; apply/eqP; rewrite eqEsubset BsubG andbT.
rewrite -[B ^+ n]gen_set_id ?genS ?subsetUr //.
by apply: subset_trans fixBn; rewrite expgS mulUg subsetU ?mulg_subl ?orbT.
rewrite /group_set B_1 /=.
elim: {2}(n : nat) => [|m IHm]; first by rewrite mulg1.
by apply: subset_trans fixBn; rewrite !expgSr mulgA mulSg.
suffices: N < #|B ^+ N| by rewrite ltnNge max_card.
have [] := ubnPgeq N; elim=> [|n IHn] lt_nN; first by rewrite cards1.
apply: leq_ltn_trans (IHn (ltnW lt_nN)) (proper_card _).
by rewrite /proper (no_fix (Ordinal lt_nN)) expgS mulUg mul1g subsetUl.
Qed.
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.
apply: (iffP idP) => [|[n [c Ac ->]]]; last first.
by apply: group_prod => i _; rewrite mem_gen ?Ac.
have [n ->] := gen_expgs A; rewrite /expgn Monoid.iteropE /=.
rewrite -[n]card_ord -big_const => /prodsgP[/= c Ac def_x].
have{Ac def_x} ->: x = \prod_(i | c i \in A) c i.
rewrite big_mkcond {x}def_x; apply: eq_bigr => i _.
by case/setU1P: (Ac i isT) => -> //; rewrite if_same.
have [e <- [_ /= mem_e] _] := big_enumP [preim c of A].
pose t := in_tuple e; rewrite -[e]/(val t) big_tuple.
by exists (size e), (c \o tnth t) => // i; rewrite -mem_e mem_tnth.
Qed.
Lemma genD A B : A \subset <<A :\: B>> -> <<A :\: B>> = <<A>>.
Proof.
by move=> sAB; apply/eqP; rewrite eqEsubset genS (subsetDl, gen_subG).
Qed.
Lemma genV A : <<A^-1>> = <<A>>.
Proof.
apply/eqP; rewrite eqEsubset !gen_subG -!(invSg _ <<_>>) invgK.
by rewrite !invGid !subset_gen.
Qed.
Lemma genJ A z : <<A :^z>> = <<A>> :^ z.
Proof.
by apply/eqP; rewrite eqEsubset sub_conjg !gen_subG conjSg -?sub_conjg !sub_gen.
Qed.
Lemma conjYg A B z : (A <*> B) :^z = A :^ z <*> B :^ z.
Proof. by rewrite -genJ conjUg. Qed.
Lemma genD1 A x : x \in <<A :\ x>> -> <<A :\ x>> = <<A>>.
Proof.
move=> gA'x; apply/eqP; rewrite eqEsubset genS; last by rewrite subsetDl.
rewrite gen_subG; apply/subsetP=> y Ay.
by case: (y =P x) => [-> //|]; move/eqP=> nyx; rewrite mem_gen // !inE nyx.
Qed.
Lemma genD1id A : <<A^#>> = <<A>>.
Proof. by rewrite genD1 ?group1. Qed.
Notation joingT := (@joing gT) (only parsing).
Notation joinGT := (@joinG gT) (only parsing).
Lemma joingE A B : A <*> B = <<A :|: B>>. Proof. by []. Qed.
Lemma joinGE G H : (G * H)%G = (G <*> H)%G. Proof. by []. Qed.
Lemma joingC : commutative joingT.
Proof. by move=> A B; rewrite /joing setUC. Qed.
Lemma joing_idr A B : A <*> <<B>> = A <*> B.
Proof.
apply/eqP; rewrite eqEsubset gen_subG subUset gen_subG /=.
by rewrite -subUset subset_gen genS // setUS // subset_gen.
Qed.
Lemma joing_idl A B : <<A>> <*> B = A <*> B.
Proof. by rewrite -!(joingC B) joing_idr. Qed.
Lemma joing_subl A B : A \subset A <*> B.
Proof. by rewrite sub_gen ?subsetUl. Qed.
Lemma joing_subr A B : B \subset A <*> B.
Proof. by rewrite sub_gen ?subsetUr. Qed.
Lemma join_subG A B G : (A <*> B \subset G) = (A \subset G) && (B \subset G).
Proof. by rewrite gen_subG subUset. Qed.
Lemma joing_idPl G A : reflect (G <*> A = G) (A \subset G).
Proof.
apply: (iffP idP) => [sHG | <-]; last by rewrite joing_subr.
by rewrite joingE (setUidPl sHG) genGid.
Qed.
Lemma joing_idPr A G : reflect (A <*> G = G) (A \subset G).
Proof. by rewrite joingC; apply: joing_idPl. Qed.
Lemma joing_subP A B G :
reflect (A \subset G /\ B \subset G) (A <*> B \subset G).
Proof. by rewrite join_subG; apply: andP. Qed.
Lemma joing_sub A B C : A <*> B = C -> A \subset C /\ B \subset C.
Proof. by move <-; apply/joing_subP. Qed.
Lemma genDU A B C : A \subset C -> <<C :\: A>> = <<B>> -> <<A :|: B>> = <<C>>.
Proof.
move=> sAC; rewrite -joingE -joing_idr => <- {B}; rewrite joing_idr.
by congr <<_>>; rewrite setDE setUIr setUCr setIT; apply/setUidPr.
Qed.
Lemma joingA : associative joingT.
Proof. by move=> A B C; rewrite joing_idl joing_idr /joing setUA. Qed.
Lemma joing1G G : 1 <*> G = G.
Proof. by rewrite -gen0 joing_idl /joing set0U genGid. Qed.
Lemma joingG1 G : G <*> 1 = G.
Proof. by rewrite joingC joing1G. Qed.
Lemma genM_join G H : <<G * H>> = G <*> H.
Proof.
apply/eqP; rewrite eqEsubset gen_subG /= -{1}[G <*> H]mulGid.
rewrite genS; last by rewrite subUset mulG_subl mulG_subr.
by rewrite mulgSS ?(sub_gen, subsetUl, subsetUr).
Qed.
Lemma mulG_subG G H K : (G * H \subset K) = (G \subset K) && (H \subset K).
Proof. by rewrite -gen_subG genM_join join_subG. Qed.
Lemma mulGsubP K H G : reflect (K \subset G /\ H \subset G) (K * H \subset G).
Proof. by rewrite mulG_subG; apply: andP. Qed.
Lemma mulG_sub K H A : K * H = A -> K \subset A /\ H \subset A.
Proof. by move <-; rewrite mulG_subl mulG_subr. Qed.
Lemma trivMg G H : (G * H == 1) = (G :==: 1) && (H :==: 1).
Proof.
by rewrite !eqEsubset -{2}[1]mulGid mulgSS ?sub1G // !andbT mulG_subG.
Qed.
Lemma comm_joingE G H : commute G H -> G <*> H = G * H.
Proof.
by move/comm_group_setP=> gGH; rewrite -genM_join; apply: (genGid (group gGH)).
Qed.
Lemma joinGC : commutative joinGT.
Proof. by move=> G H; apply: val_inj; apply: joingC. Qed.
Lemma joinGA : associative joinGT.
Proof. by move=> G H K; apply: val_inj; apply: joingA. Qed.
Lemma join1G : left_id 1%G joinGT.
Proof. by move=> G; apply: val_inj; apply: joing1G. Qed.
Lemma joinG1 : right_id 1%G joinGT.
Proof. by move=> G; apply: val_inj; apply: joingG1. Qed.
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.
elim/big_rec2: _ => /= [|i A _ _ ->]; first by rewrite gen0.
by rewrite joing_idl joing_idr.
Qed.
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.
rewrite -bigprodGEgen /=; apply: congr_group.
by apply: eq_bigr => i _; rewrite genGidG.
Qed.
Lemma mem_commg A B x y : x \in A -> y \in B -> [~ x, y] \in [~: A, B].
Proof. by move=> Ax By; rewrite mem_gen ?imset2_f. Qed.
Lemma commSg A B C : A \subset B -> [~: A, C] \subset [~: B, C].
Proof. by move=> sAC; rewrite genS ?imset2S. Qed.
Lemma commgS A B C : B \subset C -> [~: A, B] \subset [~: A, C].
Proof. by move=> sBC; rewrite genS ?imset2S. Qed.
Lemma commgSS A B C D :
A \subset B -> C \subset D -> [~: A, C] \subset [~: B, D].
Proof. by move=> sAB sCD; rewrite genS ?imset2S. Qed.
Lemma der1_subG G : [~: G, G] \subset G.
Proof.
by rewrite gen_subG; apply/subsetP=> _ /imset2P[x y Gx Gy ->]; apply: groupR.
Qed.
Lemma comm_subG A B G : A \subset G -> B \subset G -> [~: A, B] \subset G.
Proof.
by move=> sAG sBG; apply: subset_trans (der1_subG G); apply: commgSS.
Qed.
Lemma commGC A B : [~: A, B] = [~: B, A].
Proof.
rewrite -[[~: A, B]]genV; congr <<_>>; apply/setP=> z; rewrite inE.
by apply/imset2P/imset2P=> [] [x y Ax Ay]; last rewrite -{1}(invgK z);
rewrite -invg_comm => /invg_inj->; exists y x.
Qed.
Lemma conjsRg A B x : [~: A, B] :^ x = [~: A :^ x, B :^ x].
Proof.
wlog suffices: A B x / [~: A, B] :^ x \subset [~: A :^ x, B :^ x].
move=> subJ; apply/eqP; rewrite eqEsubset subJ /= -sub_conjgV.
by rewrite -{2}(conjsgK x A) -{2}(conjsgK x B).
rewrite -genJ gen_subG; apply/subsetP=> _ /imsetP[_ /imset2P[y z Ay Bz ->] ->].
by rewrite conjRg mem_commg ?memJ_conjg.
Qed.
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. exact: genGid. Qed.
Lemma order1 : #[1 : gT] = 1%N.
Proof. by rewrite /order cycle1 cards1. Qed.
Lemma cycle_id x : x \in <[x]>.
Proof. by rewrite mem_gen // set11. Qed.
Lemma mem_cycle x i : x ^+ i \in <[x]>.
Proof. by rewrite groupX // cycle_id. Qed.
Lemma cycle_subG x G : (<[x]> \subset G) = (x \in G).
Proof. by rewrite gen_subG sub1set. Qed.
Lemma cycle_eq1 x : (<[x]> == 1) = (x == 1).
Proof. by rewrite eqEsubset sub1G andbT cycle_subG inE. Qed.
Lemma orderE x : #[x] = #|<[x]>|. Proof. by []. Qed.
Lemma order_eq1 x : (#[x] == 1%N) = (x == 1).
Proof. by rewrite -trivg_card1 cycle_eq1. Qed.
Lemma order_gt1 x : (#[x] > 1) = (x != 1).
Proof. by rewrite ltnNge -trivg_card_le1 cycle_eq1. Qed.
Lemma cycle_traject x : <[x]> =i traject (mulg x) 1 #[x].
Proof.
set t := _ 1; apply: fsym; apply/subset_cardP; last first.
by apply/subsetP=> _ /trajectP[i _ ->]; rewrite -iteropE mem_cycle.
rewrite (card_uniqP _) ?size_traject //; case def_n: #[_] => // [n].
rewrite looping_uniq; apply: contraL (card_size (t n)) => /loopingP t_xi.
rewrite -ltnNge size_traject -def_n ?subset_leq_card //.
rewrite -(eq_subset_r (in_set _)) {}/t; set G := finset _.
rewrite -[x]mulg1 -[G]gen_set_id ?genS ?sub1set ?inE ?(t_xi 1%N)//.
apply/group_setP; split=> [|y z]; rewrite !inE ?(t_xi 0) //.
by do 2!case/trajectP=> ? _ ->; rewrite -!iteropE -expgD [x ^+ _]iteropE.
Qed.
Lemma cycle2g x : #[x] = 2 -> <[x]> = [set 1; x].
Proof. by move=> ox; apply/setP=> y; rewrite cycle_traject ox !inE mulg1. Qed.
Lemma cyclePmin x y : y \in <[x]> -> {i | i < #[x] & y = x ^+ i}.
Proof.
rewrite cycle_traject; set tx := traject _ _ #[x] => tx_y; pose i := index y tx.
have lt_i_x : i < #[x] by rewrite -index_mem size_traject in tx_y.
by exists i; rewrite // [x ^+ i]iteropE /= -(nth_traject _ lt_i_x) nth_index.
Qed.
Lemma cycleP x y : reflect (exists i, y = x ^+ i) (y \in <[x]>).
Proof.
by apply: (iffP idP) => [/cyclePmin[i _]|[i ->]]; [exists i | apply: mem_cycle].
Qed.
Lemma expg_order x : x ^+ #[x] = 1.
Proof.
have: uniq (traject (mulg x) 1 #[x]).
by apply/card_uniqP; rewrite size_traject -(eq_card (cycle_traject x)).
case/cyclePmin: (mem_cycle x #[x]) => [] [//|i] ltix.
rewrite -(subnKC ltix) addSnnS /= expgD; move: (_ - _) => j x_j1.
case/andP=> /trajectP[]; exists j; first exact: leq_addl.
by apply: (mulgI (x ^+ i.+1)); rewrite -iterSr iterS -iteropE -expgS mulg1.
Qed.
Lemma expg_mod p k x : x ^+ p = 1 -> x ^+ (k %% p) = x ^+ k.
Proof.
move=> xp.
by rewrite {2}(divn_eq k p) expgD mulnC expgM xp expg1n mul1g.
Qed.
Lemma expg_mod_order x i : x ^+ (i %% #[x]) = x ^+ i.
Proof. by rewrite expg_mod // expg_order. Qed.
Lemma invg_expg x : x^-1 = x ^+ #[x].-1.
Proof. by apply/eqP; rewrite eq_invg_mul -expgS prednK ?expg_order. Qed.
Lemma invg2id x : #[x] = 2 -> x^-1 = x.
Proof. by move=> ox; rewrite invg_expg ox. Qed.
Lemma cycleX x i : <[x ^+ i]> \subset <[x]>.
Proof. by rewrite cycle_subG; apply: mem_cycle. Qed.
Lemma cycleV x : <[x^-1]> = <[x]>.
Proof.
by apply/eqP; rewrite eq_sym eqEsubset !cycle_subG groupV -groupV !cycle_id.
Qed.
Lemma orderV x : #[x^-1] = #[x].
Proof. by rewrite /order cycleV. Qed.
Lemma cycleJ x y : <[x ^ y]> = <[x]> :^ y.
Proof. by rewrite -genJ conjg_set1. Qed.
Lemma orderJ x y : #[x ^ y] = #[x].
Proof. by rewrite /order cycleJ cardJg. Qed.
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.
suffices ->: (x \in 'N(A)) = (A :^ x == A) by apply: eqP.
by rewrite eqEcard cardJg leqnn andbT inE.
Qed.
Arguments normP {x A}.
Lemma group_set_normaliser A : group_set 'N(A).
Proof.
apply/group_setP; split=> [|x y Nx Ny]; rewrite inE ?conjsg1 //.
by rewrite conjsgM !(normP _).
Qed.
Canonical normaliser_group A := group (group_set_normaliser A).
Lemma normsP A B : reflect {in A, normalised B} (A \subset 'N(B)).
Proof.
apply: (iffP subsetP) => nBA x Ax; last by rewrite inE nBA //.
by apply/normP; apply: nBA.
Qed.
Arguments normsP {A B}.
Lemma memJ_norm x y A : x \in 'N(A) -> (y ^ x \in A) = (y \in A).
Proof. by move=> Nx; rewrite -{1}(normP Nx) memJ_conjg. Qed.
Lemma norms_cycle x y : (<[y]> \subset 'N(<[x]>)) = (x ^ y \in <[x]>).
Proof. by rewrite cycle_subG inE -cycleJ cycle_subG. Qed.
Lemma norm1 : 'N(1) = setT :> {set gT}.
Proof. by apply/setP=> x; rewrite !inE conjs1g subxx. Qed.
Lemma norms1 A : A \subset 'N(1).
Proof. by rewrite norm1 subsetT. Qed.
Lemma normCs A : 'N(~: A) = 'N(A).
Proof. by apply/setP=> x; rewrite -groupV !inE conjCg setCS sub_conjg. Qed.
Lemma normG G : G \subset 'N(G).
Proof. by apply/normsP; apply: conjGid. Qed.
Lemma normT : 'N([set: gT]) = [set: gT].
Proof. by apply/eqP; rewrite -subTset normG. Qed.
Lemma normsG A G : A \subset G -> A \subset 'N(G).
Proof. by move=> sAG; apply: subset_trans (normG G). Qed.
Lemma normC A B : A \subset 'N(B) -> commute A B.
Proof.
move/subsetP=> nBA; apply/setP=> u.
apply/mulsgP/mulsgP=> [[x y Ax By] | [y x By Ax]] -> {u}.
by exists (y ^ x^-1) x; rewrite -?conjgCV // memJ_norm // groupV nBA.
by exists x (y ^ x); rewrite -?conjgC // memJ_norm // nBA.
Qed.
Lemma norm_joinEl G H : G \subset 'N(H) -> G <*> H = G * H.
Proof. by move/normC/comm_joingE. Qed.
Lemma norm_joinEr G H : H \subset 'N(G) -> G <*> H = G * H.
Proof. by move/normC=> cHG; apply: comm_joingE. Qed.
Lemma norm_rlcoset G x : x \in 'N(G) -> G :* x = x *: G.
Proof. by rewrite -sub1set => /normC. Qed.
Lemma rcoset_mul G x y : x \in 'N(G) -> (G :* x) * (G :* y) = G :* (x * y).
Proof.
move/norm_rlcoset=> GxxG.
by rewrite mulgA -(mulgA _ _ G) -GxxG mulgA mulGid -mulgA mulg_set1.
Qed.
Lemma normJ A x : 'N(A :^ x) = 'N(A) :^ x.
Proof.
by apply/setP=> y; rewrite mem_conjg !inE -conjsgM conjgCV conjsgM conjSg.
Qed.
Lemma norm_conj_norm x A B :
x \in 'N(A) -> (A \subset 'N(B :^ x)) = (A \subset 'N(B)).
Proof. by move=> Nx; rewrite normJ -sub_conjgV (normP _) ?groupV. Qed.
Lemma norm_gen A : 'N(A) \subset 'N(<<A>>).
Proof. by apply/normsP=> x Nx; rewrite -genJ (normP Nx). Qed.
Lemma class_norm x G : G \subset 'N(x ^: G).
Proof. by apply/normsP=> y; apply: classGidr. Qed.
Lemma class_normal x G : x \in G -> x ^: G <| G.
Proof. by move=> Gx; rewrite /normal class_norm class_subG. Qed.
Lemma class_sub_norm G A x : G \subset 'N(A) -> (x ^: G \subset A) = (x \in A).
Proof.
move=> nAG; apply/subsetP/idP=> [-> // | Ax xy]; first exact: class_refl.
by case/imsetP=> y Gy ->; rewrite memJ_norm ?(subsetP nAG).
Qed.
Lemma class_support_norm A G : G \subset 'N(class_support A G).
Proof. by apply/normsP; apply: class_supportGidr. Qed.
Lemma class_support_sub_norm A B G :
A \subset G -> B \subset 'N(G) -> class_support A B \subset G.
Proof.
move=> sAG nGB; rewrite class_supportEr.
by apply/bigcupsP=> x Bx; rewrite -(normsP nGB x Bx) conjSg.
Qed.
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. exact: subset_trans nBA (norm_gen B). Qed.
Lemma norms_norm : A \subset 'N('N(B)).
Proof. by apply/normsP=> x Ax; rewrite -normJ (normsP nBA). Qed.
Lemma normsI : A \subset 'N(B :&: C).
Proof. by apply/normsP=> x Ax; rewrite conjIg !(normsP _ x Ax). Qed.
Lemma normsU : A \subset 'N(B :|: C).
Proof. by apply/normsP=> x Ax; rewrite conjUg !(normsP _ x Ax). Qed.
Lemma normsIs : B \subset 'N(D) -> A :&: B \subset 'N(C :&: D).
Proof.
move/normsP=> nDB; apply/normsP=> x; case/setIP=> Ax Bx.
by rewrite conjIg (normsP nCA) ?nDB.
Qed.
Lemma normsD : A \subset 'N(B :\: C).
Proof. by apply/normsP=> x Ax; rewrite conjDg !(normsP _ x Ax). Qed.
Lemma normsM : A \subset 'N(B * C).
Proof. by apply/normsP=> x Ax; rewrite conjsMg !(normsP _ x Ax). Qed.
Lemma normsY : A \subset 'N(B <*> C).
Proof. by apply/normsP=> x Ax; rewrite -genJ conjUg !(normsP _ x Ax). Qed.
Lemma normsR : A \subset 'N([~: B, C]).
Proof. by apply/normsP=> x Ax; rewrite conjsRg !(normsP _ x Ax). Qed.
Lemma norms_class_support : A \subset 'N(class_support B C).
Proof.
apply/subsetP=> x Ax; rewrite inE sub_conjg class_supportEr.
apply/bigcupsP=> y Cy; rewrite -sub_conjg -conjsgM conjgC conjsgM.
by rewrite (normsP nBA) // bigcup_sup ?memJ_norm ?(subsetP nCA).
Qed.
End norm_trans.
Lemma normsIG A B G : A \subset 'N(B) -> A :&: G \subset 'N(B :&: G).
Proof. by move/normsIs->; rewrite ?normG. Qed.
Lemma normsGI A B G : A \subset 'N(B) -> G :&: A \subset 'N(G :&: B).
Proof. by move=> nBA; rewrite !(setIC G) normsIG. Qed.
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.
elim/big_rec2: _ => [|i B N _ IH /subsetIP[nBiA /IH]]; last exact: normsI.
by rewrite normT.
Qed.
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.
move=> nBA; rewrite -normCs setC_bigcup norms_bigcap //.
by rewrite (eq_bigr _ (fun _ _ => normCs _)).
Qed.
Lemma normsD1 A B : A \subset 'N(B) -> A \subset 'N(B^#).
Proof. by move/normsD->; rewrite ?norms1. Qed.
Lemma normD1 A : 'N(A^#) = 'N(A).
Proof.
apply/eqP; rewrite eqEsubset normsD1 //.
rewrite -{2}(setID A 1) setIC normsU //; apply/normsP=> x _; apply/setP=> y.
by rewrite conjIg conjs1g !inE mem_conjg; case: eqP => // ->; rewrite conj1g.
Qed.
Lemma normalP A B : reflect (A \subset B /\ {in B, normalised A}) (A <| B).
Proof. by apply: (iffP andP)=> [] [sAB]; move/normsP. Qed.
Lemma normal_sub A B : A <| B -> A \subset B.
Proof. by case/andP. Qed.
Lemma normal_norm A B : A <| B -> B \subset 'N(A).
Proof. by case/andP. Qed.
Lemma normalS G H K : K \subset H -> H \subset G -> K <| G -> K <| H.
Proof.
by move=> sKH sHG /andP[_ nKG]; rewrite /(K <| _) sKH (subset_trans sHG).
Qed.
Lemma normal1 G : 1 <| G.
Proof. by rewrite /normal sub1set group1 norms1. Qed.
Lemma normal_refl G : G <| G.
Proof. by rewrite /(G <| _) normG subxx. Qed.
Lemma normalG G : G <| 'N(G).
Proof. by rewrite /(G <| _) normG subxx. Qed.
Lemma normalSG G H : H \subset G -> H <| 'N_G(H).
Proof. by move=> sHG; rewrite /normal subsetI sHG normG subsetIr. Qed.
Lemma normalJ A B x : (A :^ x <| B :^ x) = (A <| B).
Proof. by rewrite /normal normJ !conjSg. Qed.
Lemma normalM G A B : A <| G -> B <| G -> A * B <| G.
Proof.
by case/andP=> sAG nAG /andP[sBG nBG]; rewrite /normal mul_subG ?normsM.
Qed.
Lemma normalY G A B : A <| G -> B <| G -> A <*> B <| G.
Proof.
by case/andP=> sAG ? /andP[sBG ?]; rewrite /normal join_subG sAG sBG ?normsY.
Qed.
Lemma normalYl G H : (H <| H <*> G) = (G \subset 'N(H)).
Proof. by rewrite /normal joing_subl join_subG normG. Qed.
Lemma normalYr G H : (H <| G <*> H) = (G \subset 'N(H)).
Proof. by rewrite joingC normalYl. Qed.
Lemma normalI G A B : A <| G -> B <| G -> A :&: B <| G.
Proof.
by case/andP=> sAG nAG /andP[_ nBG]; rewrite /normal subIset ?sAG // normsI.
Qed.
Lemma norm_normalI G A : G \subset 'N(A) -> G :&: A <| G.
Proof. by move=> nAG; rewrite /normal subsetIl normsI ?normG. Qed.
Lemma normalGI G H A : H \subset G -> A <| G -> H :&: A <| H.
Proof.
by move=> sHG /andP[_ nAG]; apply: norm_normalI (subset_trans sHG nAG).
Qed.
Lemma normal_subnorm G H : (H <| 'N_G(H)) = (H \subset G).
Proof. by rewrite /normal subsetIr subsetI normG !andbT. Qed.
Lemma normalD1 A G : (A^# <| G) = (A <| G).
Proof. by rewrite /normal normD1 subDset (setUidPr (sub1G G)). Qed.
Lemma gcore_sub A G : gcore A G \subset A.
Proof. by rewrite (bigcap_min 1) ?conjsg1. Qed.
Lemma gcore_norm A G : G \subset 'N(gcore A G).
Proof.
apply/subsetP=> x Gx; rewrite inE; apply/bigcapsP=> y Gy.
by rewrite sub_conjg -conjsgM bigcap_inf ?groupM ?groupV.
Qed.
Lemma gcore_normal A G : A \subset G -> gcore A G <| G.
Proof.
by move=> sAG; rewrite /normal gcore_norm (subset_trans (gcore_sub A G)).
Qed.
Lemma gcore_max A B G : B \subset A -> G \subset 'N(B) -> B \subset gcore A G.
Proof.
move=> sBA nBG; apply/bigcapsP=> y Gy.
by rewrite -sub_conjgV (normsP nBG) ?groupV.
Qed.
Lemma sub_gcore A B G :
G \subset 'N(B) -> (B \subset gcore A G) = (B \subset A).
Proof.
move=> nBG; apply/idP/idP=> [sBAG | sBA]; last exact: gcore_max.
exact: subset_trans (gcore_sub A G).
Qed.
(* 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.
move=> sHG indexHG => /setDP[Gx notHx]; apply/eqP.
rewrite eqEcard -(leq_add2l #|G :&: H|) cardsID -(LagrangeI G H) indexHG muln2.
rewrite (setIidPr sHG) card_rcoset addnn leqnn andbT.
apply/subsetP=> _ /rcosetP[y Hy ->]; apply/setDP.
by rewrite !groupMl // (subsetP sHG).
Qed.
Lemma index2_normal G H : H \subset G -> #|G : H| = 2 -> H <| G.
Proof.
move=> sHG indexHG; rewrite /normal sHG; apply/subsetP=> x Gx.
case Hx: (x \in H); first by rewrite inE conjGid.
rewrite inE conjsgE mulgA -sub_rcosetV -invg_rcoset.
by rewrite !(rcoset_index2 sHG) ?inE ?groupV ?Hx // invDg !invGid.
Qed.
Lemma cent1P x y : reflect (commute x y) (x \in 'C[y]).
Proof.
rewrite [x \in _]inE conjg_set1 sub1set !inE (sameP eqP conjg_fixP)commg1_sym.
exact: commgP.
Qed.
Lemma cent1id x : x \in 'C[x]. Proof. exact/cent1P. Qed.
Lemma cent1E x y : (x \in 'C[y]) = (x * y == y * x).
Proof. by rewrite (sameP (cent1P x y) eqP). Qed.
Lemma cent1C x y : (x \in 'C[y]) = (y \in 'C[x]).
Proof. by rewrite !cent1E eq_sym. Qed.
Canonical centraliser_group A : {group _} := Eval hnf in [group of 'C(A)].
Lemma cent_set1 x : 'C([set x]) = 'C[x].
Proof. by apply: big_pred1 => y /=; rewrite !inE. Qed.
Lemma cent1J x y : 'C[x ^ y] = 'C[x] :^ y.
Proof. by rewrite -conjg_set1 normJ. Qed.
Lemma centP A x : reflect (centralises x A) (x \in 'C(A)).
Proof. by apply: (iffP bigcapP) => cxA y /cxA/cent1P. Qed.
Lemma centsP A B : reflect {in A, centralised B} (A \subset 'C(B)).
Proof. by apply: (iffP subsetP) => cAB x /cAB/centP. Qed.
Lemma centsC A B : (A \subset 'C(B)) = (B \subset 'C(A)).
Proof. by apply/centsP/centsP=> cAB x ? y ?; rewrite /commute -cAB. Qed.
Lemma cents1 A : A \subset 'C(1).
Proof. by rewrite centsC sub1G. Qed.
Lemma cent1T : 'C(1) = setT :> {set gT}.
Proof. by apply/eqP; rewrite -subTset cents1. Qed.
Lemma cent11T : 'C[1] = setT :> {set gT}.
Proof. by rewrite -cent_set1 cent1T. Qed.
Lemma cent_sub A : 'C(A) \subset 'N(A).
Proof.
apply/subsetP=> x /centP cAx; rewrite inE.
by apply/subsetP=> _ /imsetP[y Ay ->]; rewrite /conjg -cAx ?mulKg.
Qed.
Lemma cents_norm A B : A \subset 'C(B) -> A \subset 'N(B).
Proof. by move=> cAB; apply: subset_trans (cent_sub B). Qed.
Lemma centC A B : A \subset 'C(B) -> commute A B.
Proof. by move=> cAB; apply: normC (cents_norm cAB). Qed.
Lemma cent_joinEl G H : G \subset 'C(H) -> G <*> H = G * H.
Proof. by move=> cGH; apply: norm_joinEl (cents_norm cGH). Qed.
Lemma cent_joinEr G H : H \subset 'C(G) -> G <*> H = G * H.
Proof. by move=> cGH; apply: norm_joinEr (cents_norm cGH). Qed.
Lemma centJ A x : 'C(A :^ x) = 'C(A) :^ x.
Proof.
apply/setP=> y; rewrite mem_conjg; apply/centP/centP=> cAy z Az.
by apply: (conjg_inj x); rewrite 2!conjMg conjgKV cAy ?memJ_conjg.
by apply: (conjg_inj x^-1); rewrite 2!conjMg cAy -?mem_conjg.
Qed.
Lemma cent_norm A : 'N(A) \subset 'N('C(A)).
Proof. by apply/normsP=> x nCx; rewrite -centJ (normP nCx). Qed.
Lemma norms_cent A B : A \subset 'N(B) -> A \subset 'N('C(B)).
Proof. by move=> nBA; apply: subset_trans nBA (cent_norm B). Qed.
Lemma cent_normal A : 'C(A) <| 'N(A).
Proof. by rewrite /(_ <| _) cent_sub cent_norm. Qed.
Lemma centS A B : B \subset A -> 'C(A) \subset 'C(B).
Proof. by move=> sAB; rewrite centsC (subset_trans sAB) 1?centsC. Qed.
Lemma centsS A B C : A \subset B -> C \subset 'C(B) -> C \subset 'C(A).
Proof. by move=> sAB cCB; apply: subset_trans cCB (centS sAB). Qed.
Lemma centSS A B C D :
A \subset C -> B \subset D -> C \subset 'C(D) -> A \subset 'C(B).
Proof. by move=> sAC sBD cCD; apply: subset_trans (centsS sBD cCD). Qed.
Lemma centI A B : 'C(A) <*> 'C(B) \subset 'C(A :&: B).
Proof. by rewrite gen_subG subUset !centS ?(subsetIl, subsetIr). Qed.
Lemma centU A B : 'C(A :|: B) = 'C(A) :&: 'C(B).
Proof.
apply/eqP; rewrite eqEsubset subsetI 2?centS ?(subsetUl, subsetUr) //=.
by rewrite centsC subUset -centsC subsetIl -centsC subsetIr.
Qed.
Lemma cent_gen A : 'C(<<A>>) = 'C(A).
Proof. by apply/setP=> x; rewrite -!sub1set centsC gen_subG centsC. Qed.
Lemma cent_cycle x : 'C(<[x]>) = 'C[x].
Proof. by rewrite cent_gen cent_set1. Qed.
Lemma sub_cent1 A x : (A \subset 'C[x]) = (x \in 'C(A)).
Proof. by rewrite -cent_cycle centsC cycle_subG. Qed.
Lemma cents_cycle x y : commute x y -> <[x]> \subset 'C(<[y]>).
Proof. by move=> cxy; rewrite cent_cycle cycle_subG; apply/cent1P. Qed.
Lemma cycle_abelian x : abelian <[x]>.
Proof. exact: cents_cycle. Qed.
Lemma centY A B : 'C(A <*> B) = 'C(A) :&: 'C(B).
Proof. by rewrite cent_gen centU. Qed.
Lemma centM G H : 'C(G * H) = 'C(G) :&: 'C(H).
Proof. by rewrite -cent_gen genM_join centY. Qed.
Lemma cent_classP x G : reflect (x ^: G = [set x]) (x \in 'C(G)).
Proof.
apply: (iffP (centP _ _)) => [Cx | Cx1 y Gy].
apply/eqP; rewrite eqEsubset sub1set class_refl andbT.
by apply/subsetP=> _ /imsetP[y Gy ->]; rewrite !inE conjgE Cx ?mulKg.
by apply/commgP/conjg_fixP/set1P; rewrite -Cx1; apply/imsetP; exists y.
Qed.
Lemma commG1P A B : reflect ([~: A, B] = 1) (A \subset 'C(B)).
Proof.
apply: (iffP (centsP A B)) => [cAB | cAB1 x Ax y By].
apply/trivgP; rewrite gen_subG; apply/subsetP=> _ /imset2P[x y Ax Ay ->].
by rewrite inE; apply/commgP; apply: cAB.
by apply/commgP; rewrite -in_set1 -[[set 1]]cAB1 mem_commg.
Qed.
Lemma abelianE A : abelian A = (A \subset 'C(A)). Proof. by []. Qed.
Lemma abelian1 : abelian [1 gT]. Proof. exact: sub1G. Qed.
Lemma abelianS A B : A \subset B -> abelian B -> abelian A.
Proof. by move=> sAB; apply: centSS. Qed.
Lemma abelianJ A x : abelian (A :^ x) = abelian A.
Proof. by rewrite /abelian centJ conjSg. Qed.
Lemma abelian_gen A : abelian <<A>> = abelian A.
Proof. by rewrite /abelian cent_gen gen_subG. Qed.
Lemma abelianY A B :
abelian (A <*> B) = [&& abelian A, abelian B & B \subset 'C(A)].
Proof.
rewrite /abelian join_subG /= centY !subsetI -!andbA; congr (_ && _).
by rewrite centsC andbA andbb andbC.
Qed.
Lemma abelianM G H :
abelian (G * H) = [&& abelian G, abelian H & H \subset 'C(G)].
Proof. by rewrite -abelian_gen genM_join abelianY. Qed.
Section SubAbelian.
Variable A B C : {set gT}.
Hypothesis cAA : abelian A.
Lemma sub_abelian_cent : C \subset A -> A \subset 'C(C).
Proof. by move=> sCA; rewrite centsC (subset_trans sCA). Qed.
Lemma sub_abelian_cent2 : B \subset A -> C \subset A -> B \subset 'C(C).
Proof. by move=> sBA; move/sub_abelian_cent; apply: subset_trans. Qed.
Lemma sub_abelian_norm : C \subset A -> A \subset 'N(C).
Proof. by move=> sCA; rewrite cents_norm ?sub_abelian_cent. Qed.
Lemma sub_abelian_normal : (C \subset A) = (C <| A).
Proof.
by rewrite /normal; case sHG: (C \subset A); rewrite // sub_abelian_norm.
Qed.
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.
move=> exP; have [A maxA]: {A | maxgroup A gP}.
apply: ex_maxset; case: exP => G gPG.
by exists (G : {set gT}); rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (maxsetp maxA).
Qed.
Lemma ex_mingroup : (exists G, gP G) -> {G : {group gT} | mingroup G gP}.
Proof.
move=> exP; have [A minA]: {A | mingroup A gP}.
apply: ex_minset; case: exP => G gPG.
by exists (G : {set gT}); rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (minsetp minA).
Qed.
Variable G : {group gT}.
Lemma mingroupP :
reflect (gP G /\ forall H, gP H -> H \subset G -> H :=: G) (mingroup G gP).
Proof.
apply: (iffP minsetP); rewrite /= groupP genGidG /= => [] [-> minG].
by split=> // H gPH sGH; apply: minG; rewrite // groupP genGidG.
by split=> // A; case/andP=> gA gPA; rewrite -(gen_set_id gA); apply: minG.
Qed.
Lemma maxgroupP :
reflect (gP G /\ forall H, gP H -> G \subset H -> H :=: G) (maxgroup G gP).
Proof.
apply: (iffP maxsetP); rewrite /= groupP genGidG /= => [] [-> maxG].
by split=> // H gPH sGH; apply: maxG; rewrite // groupP genGidG.
by split=> // A; case/andP=> gA gPA; rewrite -(gen_set_id gA); apply: maxG.
Qed.
Lemma maxgroupp : maxgroup G gP -> gP G. Proof. by case/maxgroupP. Qed.
Lemma mingroupp : mingroup G gP -> gP G. Proof. by case/mingroupP. Qed.
Hypothesis gPG : gP G.
Lemma maxgroup_exists : {H : {group gT} | maxgroup H gP & G \subset H}.
Proof.
have [A maxA sGA]: {A | maxgroup A gP & G \subset A}.
by apply: maxset_exists; rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (maxsetp maxA).
Qed.
Lemma mingroup_exists : {H : {group gT} | mingroup H gP & H \subset G}.
Proof.
have [A maxA sGA]: {A | mingroup A gP & A \subset G}.
by apply: minset_exists; rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (minsetp maxA).
Qed.
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.
|
UniformFilterBasis.lean
|
/-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Topology.Algebra.IsUniformGroup.Defs
/-!
# Uniform properties of neighborhood bases in topological algebra
This files contains properties of filter bases on algebraic structures that also require the theory
of uniform spaces.
The only result so far is a characterization of Cauchy filters in topological groups.
-/
open uniformity Filter
open Filter
namespace AddGroupFilterBasis
variable {G : Type*} [AddCommGroup G] (B : AddGroupFilterBasis G)
/-- The uniform space structure associated to an abelian group filter basis via the associated
topological abelian group structure. -/
protected def uniformSpace : UniformSpace G :=
@IsTopologicalAddGroup.toUniformSpace G _ B.topology B.isTopologicalAddGroup
/-- The uniform space structure associated to an abelian group filter basis via the associated
topological abelian group structure is compatible with its group structure. -/
protected theorem isUniformAddGroup : @IsUniformAddGroup G B.uniformSpace _ :=
@isUniformAddGroup_of_addCommGroup G _ B.topology B.isTopologicalAddGroup
@[deprecated (since := "2025-03-27")] alias uniformAddGroup := AddGroupFilterBasis.isUniformAddGroup
theorem cauchy_iff {F : Filter G} :
@Cauchy G B.uniformSpace F ↔
F.NeBot ∧ ∀ U ∈ B, ∃ M ∈ F, ∀ᵉ (x ∈ M) (y ∈ M), y - x ∈ U := by
letI := B.uniformSpace
haveI := B.isUniformAddGroup
suffices F ×ˢ F ≤ uniformity G ↔ ∀ U ∈ B, ∃ M ∈ F, ∀ᵉ (x ∈ M) (y ∈ M), y - x ∈ U by
constructor <;> rintro ⟨h', h⟩ <;> refine ⟨h', ?_⟩ <;> [rwa [← this]; rwa [this]]
rw [uniformity_eq_comap_nhds_zero G, ← map_le_iff_le_comap]
change Tendsto _ _ _ ↔ _
simp [(basis_sets F).prod_self.tendsto_iff B.nhds_zero_hasBasis, @forall_swap (_ ∈ _) G]
end AddGroupFilterBasis
|
Use.lean
|
/-
Copyright (c) 2022 Arthur Paulino. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Arthur Paulino, Gabriel Ebner, Kyle Miller
-/
import Mathlib.Tactic.WithoutCDot
import Lean.Meta.Tactic.Util
import Lean.Elab.Tactic.Basic
/-!
# The `use` tactic
The `use` and `use!` tactics are for instantiating one-constructor inductive types
just like the `exists` tactic, but they can be a little more flexible.
`use` is the more restrained version for mathlib4, and `use!` is the exuberant version
that more closely matches `use` from mathlib3.
Note: The `use!` tactic is almost exactly the mathlib3 `use` except that it does not try
applying `exists_prop`. See the failing test in `MathlibTest/Use.lean`.
-/
namespace Mathlib.Tactic
open Lean Meta Elab Tactic
initialize registerTraceClass `tactic.use
/--
When the goal `mvarId` is an inductive datatype with a single constructor,
this applies that constructor, then returns metavariables for the non-parameter explicit arguments
along with metavariables for the parameters and implicit arguments.
The first list of returned metavariables correspond to the arguments that `⟨x,y,...⟩` notation uses.
The second list corresponds to everything else: the parameters and implicit arguments.
The third list consists of those implicit arguments that are instance implicits, which one can
try to synthesize. The third list is a sublist of the second list.
Returns metavariables for all arguments whether or not the metavariables are assigned.
-/
def applyTheConstructor (mvarId : MVarId) :
MetaM (List MVarId × List MVarId × List MVarId) := do
mvarId.withContext do
mvarId.checkNotAssigned `constructor
let target ← mvarId.getType'
matchConstInduct target.getAppFn
(fun _ => throwTacticEx `constructor mvarId
m!"target is not an inductive datatype{indentExpr target}")
fun ival us => do
match ival.ctors with
| [ctor] =>
let cinfo ← getConstInfoCtor ctor
let ctorConst := Lean.mkConst ctor us
let (args, binderInfos, _) ← forallMetaTelescopeReducing (← inferType ctorConst)
let mut explicit := #[]
let mut implicit := #[]
let mut insts := #[]
for arg in args, binderInfo in binderInfos, i in [0:args.size] do
if cinfo.numParams ≤ i ∧ binderInfo.isExplicit then
explicit := explicit.push arg.mvarId!
else
implicit := implicit.push arg.mvarId!
if binderInfo.isInstImplicit then
insts := insts.push arg.mvarId!
let e := mkAppN ctorConst args
let eType ← inferType e
unless (← withAssignableSyntheticOpaque <| isDefEq eType target) do
throwError m!"type mismatch{indentExpr e}\n{← mkHasTypeButIsExpectedMsg eType target}"
mvarId.assign e
return (explicit.toList, implicit.toList, insts.toList)
| _ => throwTacticEx `constructor mvarId
m!"target inductive type does not have exactly one constructor{indentExpr target}"
/-- Use the `args` to refine the goals `gs` in order, but whenever there is a single
goal remaining then first try applying a single constructor if it's for a single-constructor
inductive type. In `eager` mode, instead we always first try to refine, and if that fails we
always try to apply such a constructor no matter if it's the last goal.
Returns the remaining explicit goals `gs`, any goals `acc` due to `refine`, and a sublist of these
of instance arguments that we should try synthesizing after the loop.
The new set of goals should be `gs ++ acc`. -/
partial
def useLoop (eager : Bool) (gs : List MVarId) (args : List Term) (acc insts : List MVarId) :
TermElabM (List MVarId × List MVarId × List MVarId) := do
trace[tactic.use] "gs = {gs}\nargs = {args}\nacc = {acc}"
match gs, args with
| gs, [] =>
return (gs, acc, insts)
| [], arg :: _ =>
throwErrorAt arg "too many arguments supplied to `use`"
| g :: gs', arg :: args' => g.withContext do
if ← g.isAssigned then
-- Goals might become assigned in inductive types with indices.
-- Let's check that what's supplied is defeq to what's already there.
let e ← Term.elabTermEnsuringType arg (← g.getType)
unless ← isDefEq e (.mvar g) do
throwErrorAt arg
"argument is not definitionally equal to inferred value{indentExpr (.mvar g)}"
return ← useLoop eager gs' args' acc insts
-- Type ascription is a workaround for `refine` ensuring the type after synthesizing mvars.
let refineArg ← `(tactic| refine without_cdot($arg : $(← Term.exprToSyntax (← g.getType))))
if eager then
-- In eager mode, first try refining with the argument before applying the constructor
if let some newGoals ← observing? (run g do withoutRecover <| evalTactic refineArg) then
return ← useLoop eager gs' args' (acc ++ newGoals) insts
if eager || gs'.isEmpty then
if let some (expl, impl, insts') ← observing? do
try applyTheConstructor g
catch e => trace[tactic.use] "Constructor. {e.toMessageData}"; throw e then
trace[tactic.use] "expl.length = {expl.length}, impl.length = {impl.length}"
return ← useLoop eager (expl ++ gs') args (acc ++ impl) (insts ++ insts')
-- In eager mode, the following will give an error, which hopefully is more informative than
-- the one provided by `applyTheConstructor`.
let newGoals ← run g do evalTactic refineArg
useLoop eager gs' args' (acc ++ newGoals) insts
/-- Run the `useLoop` on the main goal then discharge remaining explicit `Prop` arguments. -/
def runUse (eager : Bool) (discharger : TacticM Unit) (args : List Term) : TacticM Unit := do
let egoals ← focus do
let (egoals, acc, insts) ← useLoop eager (← getGoals) args [] []
-- Try synthesizing instance arguments
for inst in insts do
if !(← inst.isAssigned) then
discard <| inst.withContext <| observing? do inst.assign (← synthInstance (← inst.getType))
-- Set the goals.
setGoals (egoals ++ acc)
pruneSolvedGoals
pure egoals
-- Run the discharger on non-assigned proposition metavariables
-- (`trivial` uses `assumption`, which isn't great for non-propositions)
for g in egoals do
if !(← g.isAssigned) then
g.withContext do
if ← isProp (← g.getType) then
trace[tactic.use] "running discharger on {g}"
discard <| run g discharger
/-- Default discharger to try to use for the `use` and `use!` tactics.
This is similar to the `trivial` tactic but doesn't do things like `contradiction` or `decide`. -/
syntax "use_discharger" : tactic
macro_rules | `(tactic| use_discharger) => `(tactic| apply exists_prop.mpr <;> use_discharger)
macro_rules | `(tactic| use_discharger) => `(tactic| apply And.intro <;> use_discharger)
macro_rules | `(tactic| use_discharger) => `(tactic| rfl)
macro_rules | `(tactic| use_discharger) => `(tactic| assumption)
macro_rules | `(tactic| use_discharger) => `(tactic| apply True.intro)
/-- Returns a `TacticM Unit` that either runs the tactic sequence from `discharger?` if it's
non-`none`, or it does `try with_reducible use_discharger`. -/
def mkUseDischarger (discharger? : Option (TSyntax ``Parser.Tactic.discharger)) :
TacticM (TacticM Unit) := do
let discharger ←
if let some disch := discharger? then
match disch with
| `(Parser.Tactic.discharger| ($_ := $d)) => `(tactic| ($d))
| _ => throwUnsupportedSyntax
else
`(tactic| try with_reducible use_discharger)
return evalTactic discharger
/--
`use e₁, e₂, ⋯` is similar to `exists`, but unlike `exists` it is equivalent to applying the tactic
`refine ⟨e₁, e₂, ⋯, ?_, ⋯, ?_⟩` with any number of placeholders (rather than just one) and
then trying to close goals associated to the placeholders with a configurable discharger (rather
than just `try trivial`).
Examples:
```lean
example : ∃ x : Nat, x = x := by use 42
example : ∃ x : Nat, ∃ y : Nat, x = y := by use 42, 42
example : ∃ x : String × String, x.1 = x.2 := by use ("forty-two", "forty-two")
```
`use! e₁, e₂, ⋯` is similar but it applies constructors everywhere rather than just for
goals that correspond to the last argument of a constructor. This gives the effect that
nested constructors are being flattened out, with the supplied values being used along the
leaves and nodes of the tree of constructors.
With `use!` one can feed in each `42` one at a time:
```lean
example : ∃ p : Nat × Nat, p.1 = p.2 := by use! 42, 42
example : ∃ p : Nat × Nat, p.1 = p.2 := by use! (42, 42)
```
The second line makes use of the fact that `use!` tries refining with the argument before
applying a constructor. Also note that `use`/`use!` by default uses a tactic
called `use_discharger` to discharge goals, so `use! 42` will close the goal in this example since
`use_discharger` applies `rfl`, which as a consequence solves for the other `Nat` metavariable.
These tactics take an optional discharger to handle remaining explicit `Prop` constructor arguments.
By default it is `use (discharger := try with_reducible use_discharger) e₁, e₂, ⋯`.
To turn off the discharger and keep all goals, use `(discharger := skip)`.
To allow "heavy refls", use `(discharger := try use_discharger)`.
-/
elab (name := useSyntax)
"use" discharger?:(Parser.Tactic.discharger)? ppSpace args:term,+ : tactic => do
runUse false (← mkUseDischarger discharger?) args.getElems.toList
@[inherit_doc useSyntax]
elab "use!" discharger?:(Parser.Tactic.discharger)? ppSpace args:term,+ : tactic => do
runUse true (← mkUseDischarger discharger?) args.getElems.toList
end Mathlib.Tactic
|
MoveAdd.lean
|
import Mathlib.Tactic.MoveAdd
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.Nat.Basic
universe u
variable {R : Type u}
section add
section semigroup
variable [AddCommSemigroup R] {a b c d e f g h : R}
example (h : a + b + c = d) : b + (a + c) = d := by
move_add [← a]
assumption
example : let k := c + (a + b); k = a + b + c := by
move_add [← a, c]
rfl
example (h : b + a = b + c + a) : a + b = a + b + c := by
move_add [a]; assumption
example [Mul R] [Neg R] : a + (b + c + a) * (- (d + e) + e) + f + g =
(c + b + a) * (e + - (e + d)) + g + f + a := by
move_add [b, d, g, f, a, e]; rfl
example (h : d + b + a = b + a → d + c + a = c + a) : a + d + b = b + a → d + c + a = a + c := by
move_add [a]
assumption
example [DecidableEq R] : if b + a = c + a then a + b = c + a else a + b ≠ c + a := by
move_add [← a]
split_ifs with h <;>
exact h
example (h : a + c + b = a + d + b) : c + b + a = b + a + d := by
move_add [← a, b] -- Goal before `exact h`: `a + c + b = a + d + b`
exact h
example [Mul R] (h : a * c + c + b * c = a * d + d + b * d) :
c + b * c + a * c = a * d + d + b * d := by
-- the first input `_ * c` unifies with `b * c` and moves to the right
-- the second input `_ * c` unifies with `a * c` and moves to the left
move_add [_ * c, ← _ * c] -- Goal before `exact h`: `a * c + c + b * c = a * d + d + b * d`
exact h
end semigroup
variable [AddCommMonoidWithOne R] [Mul R] {f g h X r s t u : R} (C D E : R → R)
example (he : E (C r * D X + D X * h + 7 + 42 + f) = C r * D X + h * D X + 7 + 42 + g) :
E (7 + f + (C r * D X + 42) + D X * h) = C r * D X + h * D X + g + 7 + 42 := by
-- move `7, 42, f, g` to the right of their respective sides
move_add [(7 : R), (42 : R), f, g]
assumption
end add
section mul
example [CommSemigroup R] (a b c d : R) (h : a * b * c = d) : b * (a * c) = d := by
move_mul [← a]
assumption
example (a b : ℕ) : a + max a b = max b a + a := by
move_oper Max.max [← a]
move_oper HAdd.hAdd [a]
rfl
example {R : Type u} [CommSemigroup R] {a b : R} :
∀ x : R, ∃ y : R, a * x * b * y = x * y * b * a := by
move_mul [a, b]
exact fun x ↦ ⟨x, rfl⟩
example {R : Type u} [Add R] [CommSemigroup R] {a b c d e f g : R} :
a * (b * c * a) * ((d * e) * e) * f * g = (c * b * a) * (e * (e * d)) * g * f * a := by
move_mul [a, a, b, c, d, e, f]
rfl
/-
# Sample usage of `move_oper`
-/
example (a b c : Prop) : a ∧ b ∧ c ↔ b ∧ c ∧ a := by
move_oper And [a]
rfl
example (a b c : Prop) : a ∨ b ∨ c ↔ b ∨ c ∨ a := by
move_oper Or [a]
rfl
example {R} [LinearOrder R] (a b c : R) : max (max a b) c = max (max b c) a := by
move_oper Max.max [a]
rfl
example {R} [LinearOrder R] (a b c : R) : min (min a b) c = min (min b c) a := by
move_oper Min.min [a]
rfl
end mul
section left_assoc
example {a b c d e : Prop} (h : a ∧ b ∧ c ∧ d ∧ e) : a ∧ c ∧ e ∧ b ∧ d := by
move_oper And [a, b, c, d, e]
exact h
example {a b c d e : Prop} (h : a ∨ b ∨ c ∨ d ∨ e) : a ∨ c ∨ e ∨ b ∨ d := by
move_oper Or [a, b, c, d, e]
exact h
end left_assoc
example (k : ℕ) (h0 : 0 + 2 = 9 + 0) (h9 : k + 2 = k + 9) : k + 2 = 9 + k := by
induction k with
| zero => exact h0
| succ n _ =>
move_add [9]
exact h9
-- Testing internals of the tactic `move_add`.
section tactic
open Mathlib.MoveAdd
#guard (uniquify [ 0, 1, 0, 1, 0, 3] =
[(0, 0), (1, 0), (0, 1), (1, 1), (0, 2), (3, 0)])
#guard
(let dat := [(0, true), (1, false), (2, true)]
#[0, 1, 2, 3, 4].qsort (weight dat · ≤ weight dat ·) = #[0, 2, 3, 4, 1])
#guard false = ( reorderUsing [0, 1, 2] [(0, false)] = [1, 2, 0] &&
reorderUsing [0, 1, 2] [(1, true)] = [1, 0, 2] &&
reorderUsing [0, 1, 2] [(1, true), (0, false)] != [1, 2, 0])
#guard reorderUsing [1, 5, 4, 3, 2, 1] [(3, true), (2, false), (1, false)] =
[3, 5, 4, 1, 2, 1]
end tactic
|
Equicontinuity.lean
|
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Topology.Algebra.UniformConvergence
import Mathlib.Topology.UniformSpace.Equicontinuity
/-!
# Algebra-related equicontinuity criterions
-/
open Function
open UniformConvergence
@[to_additive]
theorem equicontinuous_of_equicontinuousAt_one {ι G M hom : Type*} [TopologicalSpace G]
[UniformSpace M] [Group G] [Group M] [IsTopologicalGroup G] [IsUniformGroup M]
[FunLike hom G M] [MonoidHomClass hom G M] (F : ι → hom)
(hf : EquicontinuousAt ((↑) ∘ F) (1 : G)) :
Equicontinuous ((↑) ∘ F) := by
rw [equicontinuous_iff_continuous]
rw [equicontinuousAt_iff_continuousAt] at hf
let φ : G →* (ι →ᵤ M) :=
{ toFun := swap ((↑) ∘ F)
map_one' := by dsimp [UniformFun]; ext; exact map_one _
map_mul' := fun a b => by dsimp [UniformFun]; ext; exact map_mul _ _ _ }
exact continuous_of_continuousAt_one φ hf
@[to_additive]
theorem uniformEquicontinuous_of_equicontinuousAt_one {ι G M hom : Type*} [UniformSpace G]
[UniformSpace M] [Group G] [Group M] [IsUniformGroup G] [IsUniformGroup M]
[FunLike hom G M] [MonoidHomClass hom G M]
(F : ι → hom) (hf : EquicontinuousAt ((↑) ∘ F) (1 : G)) :
UniformEquicontinuous ((↑) ∘ F) := by
rw [uniformEquicontinuous_iff_uniformContinuous]
rw [equicontinuousAt_iff_continuousAt] at hf
let φ : G →* (ι →ᵤ M) :=
{ toFun := swap ((↑) ∘ F)
map_one' := by dsimp [UniformFun]; ext; exact map_one _
map_mul' := fun a b => by dsimp [UniformFun]; ext; exact map_mul _ _ _ }
exact uniformContinuous_of_continuousAt_one φ hf
|
FactorisationProperties.lean
|
/-
Copyright (c) 2024 Colin Jones. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Colin Jones
-/
import Mathlib.Algebra.Ring.GeomSum
import Mathlib.NumberTheory.Divisors
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.NormNum.Prime
/-!
# Factorisation properties of natural numbers
This file defines abundant, pseudoperfect, deficient, and weird numbers and formalizes their
relations with prime and perfect numbers.
## Main Definitions
* `Nat.Abundant`: a natural number `n` is _abundant_ if the sum of its proper divisors is greater
than `n`
* `Nat.Pseudoperfect`: a natural number `n` is _pseudoperfect_ if the sum of a subset of its proper
divisors equals `n`
* `Nat.Deficient`: a natural number `n` is _deficient_ if the sum of its proper divisors is less
than `n`
* `Nat.Weird`: a natural number is _weird_ if it is abundant but not pseudoperfect
## Main Results
* `Nat.deficient_or_perfect_or_abundant`: A positive natural number is either deficient,
perfect, or abundant.
* `Nat.Prime.deficient`: All prime natural numbers are deficient.
* `Nat.infinite_deficient`: There are infinitely many deficient numbers.
* `Nat.Prime.deficient_pow`: Any natural number power of a prime is deficient.
## Implementation Notes
* Zero is not included in any of the definitions and these definitions only apply to natural
numbers greater than zero.
## References
* [R. W. Prielipp, *PERFECT NUMBERS, ABUNDANT NUMBERS, AND DEFICIENT NUMBERS*][Prielipp1970]
## Tags
abundant, deficient, weird, pseudoperfect
-/
open Finset
namespace Nat
variable {n m p : ℕ}
/-- `n : ℕ` is _abundant_ if the sum of the proper divisors of `n` is greater than `n`. -/
def Abundant (n : ℕ) : Prop := n < ∑ i ∈ properDivisors n, i
/-- `n : ℕ` is _deficient_ if the sum of the proper divisors of `n` is less than `n`. -/
def Deficient (n : ℕ) : Prop := ∑ i ∈ properDivisors n, i < n
/-- A positive natural number `n` is _pseudoperfect_ if there exists a subset of the proper
divisors of `n` such that the sum of that subset is equal to `n`. -/
def Pseudoperfect (n : ℕ) : Prop :=
0 < n ∧ ∃ s ⊆ properDivisors n, ∑ i ∈ s, i = n
/-- `n : ℕ` is a _weird_ number if and only if it is abundant but not pseudoperfect. -/
def Weird (n : ℕ) : Prop := Abundant n ∧ ¬ Pseudoperfect n
theorem not_pseudoperfect_iff_forall :
¬ Pseudoperfect n ↔ n = 0 ∨ ∀ s ⊆ properDivisors n, ∑ i ∈ s, i ≠ n := by
rw [Pseudoperfect, not_and_or]
simp only [not_lt, nonpos_iff_eq_zero, not_exists, not_and, ne_eq]
theorem deficient_one : Deficient 1 := zero_lt_one
theorem deficient_two : Deficient 2 := one_lt_two
theorem deficient_three : Deficient 3 := by norm_num [Deficient]
theorem abundant_twelve : Abundant 12 := by
rw [Abundant, show properDivisors 12 = {1,2,3,4,6} by rfl]
norm_num
theorem weird_seventy : Weird 70 := by
rw [Weird, Abundant, not_pseudoperfect_iff_forall]
have h : properDivisors 70 = {1, 2, 5, 7, 10, 14, 35} := by rfl
constructor
· rw [h]
repeat norm_num
· rw [h]
right
intro s hs
have hs' := mem_powerset.mpr hs
fin_cases hs' <;> decide
lemma deficient_iff_not_abundant_and_not_perfect (hn : n ≠ 0) :
Deficient n ↔ ¬ Abundant n ∧ ¬ Perfect n := by
dsimp only [Perfect, Abundant, Deficient]
omega
lemma perfect_iff_not_abundant_and_not_deficient (hn : 0 ≠ n) :
Perfect n ↔ ¬ Abundant n ∧ ¬ Deficient n := by
dsimp only [Perfect, Abundant, Deficient]
omega
lemma abundant_iff_not_perfect_and_not_deficient (hn : 0 ≠ n) :
Abundant n ↔ ¬ Perfect n ∧ ¬ Deficient n := by
dsimp only [Perfect, Abundant, Deficient]
omega
/-- A positive natural number is either deficient, perfect, or abundant -/
theorem deficient_or_perfect_or_abundant (hn : 0 ≠ n) :
Deficient n ∨ Abundant n ∨ Perfect n := by
dsimp only [Perfect, Abundant, Deficient]
omega
theorem Perfect.pseudoperfect (h : Perfect n) : Pseudoperfect n :=
⟨h.2, ⟨properDivisors n, ⟨fun ⦃_⦄ a ↦ a, h.1⟩⟩⟩
theorem Prime.not_abundant (h : Prime n) : ¬ Abundant n :=
fun h1 ↦ (h.one_lt.trans h1).ne' (sum_properDivisors_eq_one_iff_prime.mpr h)
theorem Prime.not_weird (h : Prime n) : ¬ Weird n := by
simp only [Nat.Weird, not_and_or]
left
exact h.not_abundant
theorem Prime.not_pseudoperfect (h : Prime p) : ¬ Pseudoperfect p := by
simp_rw [not_pseudoperfect_iff_forall, ← mem_powerset,
show p.properDivisors.powerset = {∅, {1}} by rw [Prime.properDivisors h]; rfl]
refine Or.inr (fun s hs ↦ ?_)
fin_cases hs <;>
simp only [sum_empty, sum_singleton] <;>
linarith [Prime.one_lt h]
theorem Prime.not_perfect (h : Prime p) : ¬ Perfect p := by
have h1 := Prime.not_pseudoperfect h
revert h1
exact not_imp_not.mpr (Perfect.pseudoperfect)
/-- Any natural number power of a prime is deficient -/
theorem Prime.deficient_pow (h : Prime n) : Deficient (n ^ m) := by
rcases Nat.eq_zero_or_pos m with (rfl | _)
· simpa using deficient_one
· have h1 : (n ^ m).properDivisors = image (n ^ ·) (range m) := by
apply subset_antisymm <;> intro a
· simp only [mem_properDivisors, mem_image, mem_range, dvd_prime_pow h]
rintro ⟨⟨t, ht, rfl⟩, ha'⟩
exact ⟨t, lt_of_le_of_ne ht (fun ht' ↦ lt_irrefl _ (ht' ▸ ha')), rfl⟩
· simp only [mem_image, mem_range, mem_properDivisors, forall_exists_index, and_imp]
intro x hx hy
constructor
· rw [← hy, dvd_prime_pow h]
exact ⟨x, Nat.le_of_succ_le hx, rfl⟩
· rw [← hy]
exact (Nat.pow_lt_pow_iff_right (Prime.two_le h)).mpr hx
have h2 : ∑ i ∈ image (fun x => n ^ x) (range m), i = ∑ i ∈ range m, n^i := by
rw [Finset.sum_image]
rintro x _ y _
apply pow_injective_of_not_isUnit h.not_isUnit <| Prime.ne_zero h
rw [Deficient, h1, h2]
calc
∑ i ∈ range m, n ^ i
= (n ^ m - 1) / (n - 1) := (Nat.geomSum_eq (Prime.two_le h) _)
_ ≤ (n ^ m - 1) := Nat.div_le_self (n ^ m - 1) (n - 1)
_ < n ^ m := sub_lt (pow_pos (Prime.pos h) m) (Nat.one_pos)
theorem _root_.IsPrimePow.deficient (h : IsPrimePow n) : Deficient n := by
obtain ⟨p, k, hp, -, rfl⟩ := h
exact hp.nat_prime.deficient_pow
theorem Prime.deficient (h : Prime n) : Deficient n := by
rw [← pow_one n]
exact h.deficient_pow
/-- There exists infinitely many deficient numbers -/
theorem infinite_deficient : {n : ℕ | n.Deficient}.Infinite := by
rw [Set.infinite_iff_exists_gt]
intro a
obtain ⟨b, h1, h2⟩ := exists_infinite_primes a.succ
exact ⟨b, h2.deficient, h1⟩
theorem infinite_even_deficient : {n : ℕ | Even n ∧ n.Deficient}.Infinite := by
rw [Set.infinite_iff_exists_gt]
intro n
use 2 ^ (n + 1)
constructor
· exact ⟨⟨2 ^ n, by rw [pow_succ, mul_two]⟩, prime_two.deficient_pow⟩
· calc
n ≤ 2 ^ n := Nat.le_of_lt n.lt_two_pow_self
_ < 2 ^ (n + 1) := (Nat.pow_lt_pow_iff_right (Nat.one_lt_two)).mpr (lt_add_one n)
theorem infinite_odd_deficient : {n : ℕ | Odd n ∧ n.Deficient}.Infinite := by
rw [Set.infinite_iff_exists_gt]
intro n
obtain ⟨p, ⟨_, h2⟩⟩ := exists_infinite_primes (max (n + 1) 3)
exact ⟨p, Set.mem_setOf.mpr ⟨Prime.odd_of_ne_two h2 (Ne.symm (ne_of_lt (by omega))),
Prime.deficient h2⟩, by omega⟩
end Nat
|
Basic.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Chris Hughes, Mario Carneiro
-/
import Mathlib.Algebra.Field.IsField
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.LinearAlgebra.Finsupp.LinearCombination
import Mathlib.RingTheory.Ideal.Maximal
import Mathlib.Tactic.FinCases
/-!
# Ideals over a ring
This file contains an assortment of definitions and results for `Ideal R`,
the type of (left) ideals over a ring `R`.
Note that over commutative rings, left ideals and two-sided ideals are equivalent.
## Implementation notes
`Ideal R` is implemented using `Submodule R R`, where `•` is interpreted as `*`.
## TODO
Support right ideals, and two-sided ideals over non-commutative rings.
-/
variable {ι α β F : Type*}
open Set Function
open Pointwise
section Semiring
namespace Ideal
variable {α : ι → Type*} [Π i, Semiring (α i)] (I : Π i, Ideal (α i))
section Pi
/-- `Πᵢ Iᵢ` as an ideal of `Πᵢ Rᵢ`. -/
def pi : Ideal (Π i, α i) where
carrier := { x | ∀ i, x i ∈ I i }
zero_mem' i := (I i).zero_mem
add_mem' ha hb i := (I i).add_mem (ha i) (hb i)
smul_mem' a _b hb i := (I i).mul_mem_left (a i) (hb i)
theorem mem_pi (x : Π i, α i) : x ∈ pi I ↔ ∀ i, x i ∈ I i :=
Iff.rfl
instance (priority := low) [∀ i, (I i).IsTwoSided] : (pi I).IsTwoSided :=
⟨fun _b hb i ↦ mul_mem_right _ _ (hb i)⟩
end Pi
section Commute
variable {α : Type*} [Semiring α] (I : Ideal α) {a b : α}
theorem add_pow_mem_of_pow_mem_of_le_of_commute {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1)
(hab : Commute a b) :
(a + b) ^ k ∈ I := by
simp_rw [hab.add_pow, ← Nat.cast_comm]
apply I.sum_mem
intro c _
apply mul_mem_left
by_cases h : m ≤ c
· rw [hab.pow_pow]
exact I.mul_mem_left _ (I.pow_mem_of_pow_mem ha h)
· refine I.mul_mem_left _ (I.pow_mem_of_pow_mem hb ?_)
omega
theorem add_pow_add_pred_mem_of_pow_mem_of_commute {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hab : Commute a b) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb (by rw [← Nat.sub_le_iff_le_add]) hab
end Commute
end Ideal
end Semiring
section CommSemiring
variable {a b : α}
-- A separate namespace definition is needed because the variables were historically in a different
-- order.
namespace Ideal
variable [CommSemiring α] (I : Ideal α)
theorem add_pow_mem_of_pow_mem_of_le {m n k : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≤ k + 1) :
(a + b) ^ k ∈ I :=
I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb hk (Commute.all ..)
theorem add_pow_add_pred_mem_of_pow_mem {m n : ℕ}
(ha : a ^ m ∈ I) (hb : b ^ n ∈ I) :
(a + b) ^ (m + n - 1) ∈ I :=
I.add_pow_add_pred_mem_of_pow_mem_of_commute ha hb (Commute.all ..)
theorem pow_multiset_sum_mem_span_pow [DecidableEq α] (s : Multiset α) (n : ℕ) :
s.sum ^ (Multiset.card s * n + 1) ∈
span ((s.map fun (x : α) ↦ x ^ (n + 1)).toFinset : Set α) := by
induction' s using Multiset.induction_on with a s hs
· simp
simp only [Finset.coe_insert, Multiset.map_cons, Multiset.toFinset_cons, Multiset.sum_cons,
Multiset.card_cons, add_pow]
refine Submodule.sum_mem _ ?_
intro c _hc
rw [mem_span_insert]
by_cases h : n + 1 ≤ c
· refine ⟨a ^ (c - (n + 1)) * s.sum ^ ((Multiset.card s + 1) * n + 1 - c) *
((Multiset.card s + 1) * n + 1).choose c, 0, Submodule.zero_mem _, ?_⟩
rw [mul_comm _ (a ^ (n + 1))]
simp_rw [← mul_assoc]
rw [← pow_add, add_zero, add_tsub_cancel_of_le h]
· use 0
simp_rw [zero_mul, zero_add]
refine ⟨_, ?_, rfl⟩
replace h : c ≤ n := Nat.lt_succ_iff.mp (not_le.mp h)
have : (Multiset.card s + 1) * n + 1 - c = Multiset.card s * n + 1 + (n - c) := by
rw [add_mul, one_mul, add_assoc, add_comm n 1, ← add_assoc, add_tsub_assoc_of_le h]
rw [this, pow_add]
simp_rw [mul_assoc, mul_comm (s.sum ^ (Multiset.card s * n + 1)), ← mul_assoc]
exact mul_mem_left _ _ hs
theorem sum_pow_mem_span_pow {ι} (s : Finset ι) (f : ι → α) (n : ℕ) :
(∑ i ∈ s, f i) ^ (s.card * n + 1) ∈ span ((fun i => f i ^ (n + 1)) '' s) := by
classical
simpa only [Multiset.card_map, Multiset.map_map, comp_apply, Multiset.toFinset_map,
Finset.coe_image, Finset.val_toFinset] using pow_multiset_sum_mem_span_pow (s.1.map f) n
theorem span_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : ℕ) :
span ((fun (x : α) => x ^ n) '' s) = ⊤ := by
rw [eq_top_iff_one]
rcases n with - | n
· obtain rfl | ⟨x, hx⟩ := eq_empty_or_nonempty s
· rw [Set.image_empty, hs]
trivial
· exact subset_span ⟨_, hx, pow_zero _⟩
rw [eq_top_iff_one, span, Finsupp.mem_span_iff_linearCombination] at hs
rcases hs with ⟨f, hf⟩
have hf : (f.support.sum fun a => f a * a) = 1 := hf -- Porting note: was `change ... at hf`
have := sum_pow_mem_span_pow f.support (fun a => f a * a) n
rw [hf, one_pow] at this
refine span_le.mpr ?_ this
rintro _ hx
simp_rw [Set.mem_image] at hx
rcases hx with ⟨x, _, rfl⟩
have : span ({(x : α) ^ (n + 1)} : Set α) ≤ span ((fun x : α => x ^ (n + 1)) '' s) := by
rw [span_le, Set.singleton_subset_iff]
exact subset_span ⟨x, x.prop, rfl⟩
refine this ?_
rw [mul_pow, mem_span_singleton]
exact ⟨f x ^ (n + 1), mul_comm _ _⟩
theorem span_range_pow_eq_top (s : Set α) (hs : span s = ⊤) (n : s → ℕ) :
span (Set.range fun x ↦ x.1 ^ n x) = ⊤ := by
have ⟨t, hts, mem⟩ := Submodule.mem_span_finite_of_mem_span ((eq_top_iff_one _).mp hs)
refine top_unique ((span_pow_eq_top _ ((eq_top_iff_one _).mpr mem) <|
t.attach.sup fun x ↦ n ⟨x, hts x.2⟩).ge.trans <| span_le.mpr ?_)
rintro _ ⟨x, hxt, rfl⟩
rw [← Nat.sub_add_cancel (Finset.le_sup <| t.mem_attach ⟨x, hxt⟩)]
simp_rw [pow_add]
exact mul_mem_left _ _ (subset_span ⟨_, rfl⟩)
theorem prod_mem {ι : Type*} {f : ι → α} {s : Finset ι}
(I : Ideal α) {i : ι} (hi : i ∈ s) (hfi : f i ∈ I) :
∏ i ∈ s, f i ∈ I := by
classical
rw [Finset.prod_eq_prod_diff_singleton_mul hi]
exact Ideal.mul_mem_left _ _ hfi
end Ideal
end CommSemiring
section DivisionSemiring
variable {K : Type*} [DivisionSemiring K] (I : Ideal K)
namespace Ideal
variable (K) in
/-- A bijection between (left) ideals of a division ring and `{0, 1}`, sending `⊥` to `0`
and `⊤` to `1`. -/
def equivFinTwo [DecidableEq (Ideal K)] : Ideal K ≃ Fin 2 where
toFun := fun I ↦ if I = ⊥ then 0 else 1
invFun := ![⊥, ⊤]
left_inv := fun I ↦ by rcases eq_bot_or_top I with rfl | rfl <;> simp
right_inv := fun i ↦ by fin_cases i <;> simp
instance : Finite (Ideal K) := let _i := Classical.decEq (Ideal K); ⟨equivFinTwo K⟩
/-- Ideals of a `DivisionSemiring` are a simple order. Thanks to the way abbreviations work,
this automatically gives an `IsSimpleModule K` instance. -/
instance isSimpleOrder : IsSimpleOrder (Ideal K) :=
⟨eq_bot_or_top⟩
end Ideal
end DivisionSemiring
-- TODO: consider moving the lemmas below out of the `Ring` namespace since they are
-- about `CommSemiring`s.
namespace Ring
variable {R : Type*} [CommSemiring R]
theorem exists_not_isUnit_of_not_isField [Nontrivial R] (hf : ¬IsField R) :
∃ (x : R) (_hx : x ≠ (0 : R)), ¬IsUnit x := by
have : ¬_ := fun h => hf ⟨exists_pair_ne R, mul_comm, h⟩
simp_rw [isUnit_iff_exists_inv]
push_neg at this ⊢
obtain ⟨x, hx, not_unit⟩ := this
exact ⟨x, hx, not_unit⟩
theorem not_isField_iff_exists_ideal_bot_lt_and_lt_top [Nontrivial R] :
¬IsField R ↔ ∃ I : Ideal R, ⊥ < I ∧ I < ⊤ := by
constructor
· intro h
obtain ⟨x, nz, nu⟩ := exists_not_isUnit_of_not_isField h
use Ideal.span {x}
rw [bot_lt_iff_ne_bot, lt_top_iff_ne_top]
exact ⟨mt Ideal.span_singleton_eq_bot.mp nz, mt Ideal.span_singleton_eq_top.mp nu⟩
· rintro ⟨I, bot_lt, lt_top⟩ hf
obtain ⟨x, mem, ne_zero⟩ := SetLike.exists_of_lt bot_lt
rw [Submodule.mem_bot] at ne_zero
obtain ⟨y, hy⟩ := hf.mul_inv_cancel ne_zero
rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, ← hy] at lt_top
exact lt_top (I.mul_mem_right _ mem)
theorem not_isField_iff_exists_prime [Nontrivial R] :
¬IsField R ↔ ∃ p : Ideal R, p ≠ ⊥ ∧ p.IsPrime :=
not_isField_iff_exists_ideal_bot_lt_and_lt_top.trans
⟨fun ⟨I, bot_lt, lt_top⟩ =>
let ⟨p, hp, le_p⟩ := I.exists_le_maximal (lt_top_iff_ne_top.mp lt_top)
⟨p, bot_lt_iff_ne_bot.mp (lt_of_lt_of_le bot_lt le_p), hp.isPrime⟩,
fun ⟨p, ne_bot, Prime⟩ => ⟨p, bot_lt_iff_ne_bot.mpr ne_bot, lt_top_iff_ne_top.mpr Prime.1⟩⟩
/-- Also see `Ideal.isSimpleOrder` for the forward direction as an instance when `R` is a
division (semi)ring.
This result actually holds for all division semirings, but we lack the predicate to state it. -/
theorem isField_iff_isSimpleOrder_ideal : IsField R ↔ IsSimpleOrder (Ideal R) := by
cases subsingleton_or_nontrivial R
· exact
⟨fun h => (not_isField_of_subsingleton _ h).elim, fun h =>
(false_of_nontrivial_of_subsingleton <| Ideal R).elim⟩
rw [← not_iff_not, Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top, ← not_iff_not]
push_neg
simp_rw [lt_top_iff_ne_top, bot_lt_iff_ne_bot, ← or_iff_not_imp_left, not_ne_iff]
exact ⟨fun h => ⟨h⟩, fun h => h.2⟩
/-- When a ring is not a field, the maximal ideals are nontrivial. -/
theorem ne_bot_of_isMaximal_of_not_isField [Nontrivial R] {M : Ideal R} (max : M.IsMaximal)
(not_field : ¬IsField R) : M ≠ ⊥ := by
rintro h
rw [h] at max
rcases max with ⟨⟨_h1, h2⟩⟩
obtain ⟨I, hIbot, hItop⟩ := not_isField_iff_exists_ideal_bot_lt_and_lt_top.mp not_field
exact ne_of_lt hItop (h2 I hIbot)
end Ring
namespace Ideal
variable {R : Type*} [CommSemiring R] [Nontrivial R]
theorem bot_lt_of_maximal (M : Ideal R) [hm : M.IsMaximal] (non_field : ¬IsField R) : ⊥ < M := by
rcases Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top.1 non_field with ⟨I, Ibot, Itop⟩
constructor; · simp
intro mle
apply lt_irrefl (⊤ : Ideal R)
have : M = ⊥ := eq_bot_iff.mpr mle
rw [← this] at Ibot
rwa [hm.1.2 I Ibot] at Itop
end Ideal
|
SDiff.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.Lattice.Lemmas
/-!
# Difference of finite sets
## Main declarations
* `Finset.instSDiff`: Defines the set difference `s \ t` for finsets `s` and `t`.
* `Finset.instGeneralizedBooleanAlgebra`: Finsets almost have a boolean algebra structure
## 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
-- TODO: these should be global attributes, but this will require fixing other files
attribute [local trans] Subset.trans Superset.trans
/-! ### sdiff -/
section Sdiff
variable [DecidableEq α] {s t u v : Finset α} {a b : α}
/-- `s \ t` is the set consisting of the elements of `s` that are not in `t`. -/
instance instSDiff : SDiff (Finset α) :=
⟨fun s₁ s₂ => ⟨s₁.1 - s₂.1, nodup_of_le (Multiset.sub_le_self ..) s₁.2⟩⟩
@[simp]
theorem sdiff_val (s₁ s₂ : Finset α) : (s₁ \ s₂).val = s₁.val - s₂.val :=
rfl
@[simp, grind =]
theorem mem_sdiff : a ∈ s \ t ↔ a ∈ s ∧ a ∉ t :=
mem_sub_of_nodup s.2
@[simp]
theorem inter_sdiff_self (s₁ s₂ : Finset α) : s₁ ∩ (s₂ \ s₁) = ∅ := by grind
instance : GeneralizedBooleanAlgebra (Finset α) :=
{ sup_inf_sdiff := fun x y => by
simp only [Finset.ext_iff, mem_union, mem_sdiff, inf_eq_inter, sup_eq_union, mem_inter,
← and_or_left, em, and_true, implies_true]
inf_inf_sdiff := fun x y => by
simp only [inter_sdiff_self, inter_empty, inter_assoc,
inf_eq_inter, bot_eq_empty] }
theorem notMem_sdiff_of_mem_right (h : a ∈ t) : a ∉ s \ t := by grind
@[deprecated (since := "2025-05-23")] alias not_mem_sdiff_of_mem_right := notMem_sdiff_of_mem_right
theorem notMem_sdiff_of_notMem_left (h : a ∉ s) : a ∉ s \ t := by simp [h]
@[deprecated (since := "2025-05-23")]
alias not_mem_sdiff_of_not_mem_left := notMem_sdiff_of_notMem_left
theorem union_sdiff_of_subset (h : s ⊆ t) : s ∪ t \ s = t :=
sup_sdiff_cancel_right h
theorem sdiff_union_of_subset {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₂ \ s₁ ∪ s₁ = s₂ :=
(union_comm _ _).trans (union_sdiff_of_subset h)
/-- See also `Finset.sdiff_inter_right_comm`. -/
lemma inter_sdiff_assoc (s t u : Finset α) : (s ∩ t) \ u = s ∩ (t \ u) := inf_sdiff_assoc ..
/-- See also `Finset.inter_sdiff_assoc`. -/
lemma sdiff_inter_right_comm (s t u : Finset α) : s \ t ∩ u = (s ∩ u) \ t := sdiff_inf_right_comm ..
lemma inter_sdiff_left_comm (s t u : Finset α) : s ∩ (t \ u) = t ∩ (s \ u) := inf_sdiff_left_comm ..
@[simp]
theorem sdiff_inter_self (s₁ s₂ : Finset α) : s₂ \ s₁ ∩ s₁ = ∅ :=
inf_sdiff_self_left
protected theorem sdiff_self (s₁ : Finset α) : s₁ \ s₁ = ∅ :=
_root_.sdiff_self
theorem sdiff_inter_distrib_right (s t u : Finset α) : s \ (t ∩ u) = s \ t ∪ s \ u :=
sdiff_inf
@[simp]
theorem sdiff_inter_self_left (s t : Finset α) : s \ (s ∩ t) = s \ t :=
sdiff_inf_self_left _ _
@[simp]
theorem sdiff_inter_self_right (s t : Finset α) : s \ (t ∩ s) = s \ t :=
sdiff_inf_self_right _ _
@[simp]
theorem sdiff_empty : s \ ∅ = s :=
sdiff_bot
@[mono, gcongr]
theorem sdiff_subset_sdiff (hst : s ⊆ t) (hvu : v ⊆ u) : s \ u ⊆ t \ v :=
subset_of_le (sdiff_le_sdiff hst hvu)
theorem sdiff_subset_sdiff_iff_subset {r : Finset α} (hs : s ⊆ r) (ht : t ⊆ r) :
r \ s ⊆ r \ t ↔ t ⊆ s := by
simpa only [← le_eq_subset] using sdiff_le_sdiff_iff_le hs ht
@[simp, norm_cast]
theorem coe_sdiff (s₁ s₂ : Finset α) : ↑(s₁ \ s₂) = (s₁ \ s₂ : Set α) :=
Set.ext fun _ => mem_sdiff
@[simp]
theorem union_sdiff_self_eq_union : s ∪ t \ s = s ∪ t :=
sup_sdiff_self_right _ _
@[simp]
theorem sdiff_union_self_eq_union : s \ t ∪ t = s ∪ t :=
sup_sdiff_self_left _ _
theorem union_sdiff_left (s t : Finset α) : (s ∪ t) \ s = t \ s :=
sup_sdiff_left_self
theorem union_sdiff_right (s t : Finset α) : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
theorem union_sdiff_cancel_left (h : Disjoint s t) : (s ∪ t) \ s = t :=
h.sup_sdiff_cancel_left
theorem union_sdiff_cancel_right (h : Disjoint s t) : (s ∪ t) \ t = s :=
h.sup_sdiff_cancel_right
theorem union_sdiff_symm : s ∪ t \ s = t ∪ s \ t := by simp [union_comm]
theorem sdiff_union_inter (s t : Finset α) : s \ t ∪ s ∩ t = s :=
sup_sdiff_inf _ _
theorem sdiff_idem (s t : Finset α) : (s \ t) \ t = s \ t :=
_root_.sdiff_idem
theorem subset_sdiff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u :=
le_iff_subset.symm.trans le_sdiff
@[simp]
theorem sdiff_eq_empty_iff_subset : s \ t = ∅ ↔ s ⊆ t :=
sdiff_eq_bot_iff
theorem sdiff_nonempty : (s \ t).Nonempty ↔ ¬s ⊆ t :=
nonempty_iff_ne_empty.trans sdiff_eq_empty_iff_subset.not
@[simp]
theorem empty_sdiff (s : Finset α) : ∅ \ s = ∅ :=
bot_sdiff
theorem insert_sdiff_of_notMem (s : Finset α) {t : Finset α} {x : α} (h : x ∉ t) :
insert x s \ t = insert x (s \ t) := by grind
@[deprecated (since := "2025-05-23")] alias insert_sdiff_of_not_mem := insert_sdiff_of_notMem
theorem insert_sdiff_of_mem (s : Finset α) {x : α} (h : x ∈ t) : insert x s \ t = s \ t := by grind
@[simp] lemma insert_sdiff_self_of_mem (ha : a ∈ s) : insert a (s \ {a}) = s := by grind
@[simp] lemma insert_sdiff_cancel (ha : a ∉ s) : insert a s \ s = {a} := by grind
@[simp]
theorem insert_sdiff_insert (s t : Finset α) (x : α) : insert x s \ insert x t = s \ insert x t :=
insert_sdiff_of_mem _ (mem_insert_self _ _)
lemma insert_sdiff_insert' (hab : a ≠ b) (ha : a ∉ s) : insert a s \ insert b s = {a} := by
ext; aesop
lemma cons_sdiff_cons (hab : a ≠ b) (ha hb) : s.cons a ha \ s.cons b hb = {a} := by grind
theorem sdiff_insert_of_notMem {x : α} (h : x ∉ s) (t : Finset α) : s \ insert x t = s \ t := by
grind
@[deprecated (since := "2025-05-23")] alias sdiff_insert_of_not_mem := sdiff_insert_of_notMem
@[simp] theorem sdiff_subset {s t : Finset α} : s \ t ⊆ s := le_iff_subset.mp sdiff_le
theorem sdiff_ssubset (h : t ⊆ s) (ht : t.Nonempty) : s \ t ⊂ s :=
sdiff_lt (le_iff_subset.mpr h) ht.ne_empty
theorem union_sdiff_distrib (s₁ s₂ t : Finset α) : (s₁ ∪ s₂) \ t = s₁ \ t ∪ s₂ \ t :=
sup_sdiff
theorem sdiff_union_distrib (s t₁ t₂ : Finset α) : s \ (t₁ ∪ t₂) = s \ t₁ ∩ (s \ t₂) :=
sdiff_sup
theorem union_sdiff_self (s t : Finset α) : (s ∪ t) \ t = s \ t :=
sup_sdiff_right_self
theorem Nontrivial.sdiff_singleton_nonempty {c : α} {s : Finset α} (hS : s.Nontrivial) :
(s \ {c}).Nonempty := by
rw [Finset.sdiff_nonempty, Finset.subset_singleton_iff]
push_neg
exact ⟨by rintro rfl; exact Finset.not_nontrivial_empty hS, hS.ne_singleton⟩
theorem sdiff_sdiff_left' (s t u : Finset α) : (s \ t) \ u = s \ t ∩ (s \ u) :=
_root_.sdiff_sdiff_left'
theorem sdiff_union_sdiff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u :=
sdiff_sup_sdiff_cancel hts hut
theorem sdiff_sdiff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u :=
sdiff_sdiff_eq_sdiff_sup h
theorem sdiff_sdiff_self_left (s t : Finset α) : s \ (s \ t) = s ∩ t :=
sdiff_sdiff_right_self
theorem sdiff_sdiff_eq_self (h : t ⊆ s) : s \ (s \ t) = t :=
_root_.sdiff_sdiff_eq_self h
theorem sdiff_eq_sdiff_iff_inter_eq_inter {s t₁ t₂ : Finset α} :
s \ t₁ = s \ t₂ ↔ s ∩ t₁ = s ∩ t₂ :=
sdiff_eq_sdiff_iff_inf_eq_inf
theorem union_eq_sdiff_union_sdiff_union_inter (s t : Finset α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t :=
sup_eq_sdiff_sup_sdiff_sup_inf
theorem sdiff_eq_self_iff_disjoint : s \ t = s ↔ Disjoint s t :=
sdiff_eq_self_iff_disjoint'
theorem sdiff_eq_self_of_disjoint (h : Disjoint s t) : s \ t = s :=
sdiff_eq_self_iff_disjoint.2 h
end Sdiff
end Finset
|
Complex.lean
|
/-
Copyright (c) 2025 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import Mathlib.Analysis.Normed.Unbundled.SpectralNorm
import Mathlib.NumberTheory.Padics.PadicNumbers
import Mathlib.Topology.Algebra.Valued.NormedValued
import Mathlib.Topology.Algebra.Valued.ValuedField
/-!
# The field `ℂ_[p]` of `p`-adic complex numbers.
In this file we define the field `ℂ_[p]` of `p`-adic complex numbers as the `p`-adic completion of
an algebraic closure of `ℚ_[p]`. We endow `ℂ_[p]` with both a normed field and a valued field
structure, induced by the unique extension of the `p`-adic norm to `ℂ_[p]`.
## Main Definitions
* `PadicAlgCl p` : the algebraic closure of `ℚ_[p]`.
* `PadicComplex p` : the type of `p`-adic complex numbers, denoted by `ℂ_[p]`.
* `PadicComplexInt p` : the ring of integers of `ℂ_[p]`.
## Main Results
* `PadicComplex.norm_extends` : the norm on `ℂ_[p]` extends the norm on `PadicAlgCl p`, and hence
the norm on `ℚ_[p]`.
* `PadicComplex.isNonarchimedean` : The norm on `ℂ_[p]` is nonarchimedean.
## Notation
We introduce the notation `ℂ_[p]` for the `p`-adic complex numbers, and `𝓞_ℂ_[p]` for its ring of
integers.
## Tags
p-adic, p adic, padic, norm, valuation, Cauchy, completion, p-adic completion
-/
noncomputable section
open Valuation
open scoped NNReal
variable (p : ℕ) [hp : Fact (Nat.Prime p)]
/-- `PadicAlgCl p` is a fixed algebraic closure of `ℚ_[p]`. -/
abbrev PadicAlgCl := AlgebraicClosure ℚ_[p]
namespace PadicAlgCl
/-- `PadicAlgCl p` is an algebraic extension of `ℚ_[p]`. -/
theorem isAlgebraic : Algebra.IsAlgebraic ℚ_[p] (PadicAlgCl p) := AlgebraicClosure.isAlgebraic _
instance : Coe ℚ_[p] (PadicAlgCl p) := ⟨algebraMap ℚ_[p] (PadicAlgCl p)⟩
theorem coe_eq : (Coe.coe : ℚ_[p] → PadicAlgCl p) = algebraMap ℚ_[p] (PadicAlgCl p) := rfl
/-- `PadicAlgCl p` is a normed field, where the norm is the `p`-adic norm, that is, the
spectral norm induced by the `p`-adic norm on `ℚ_[p]`. -/
instance normedField : NormedField (PadicAlgCl p) := spectralNorm.normedField ℚ_[p] (PadicAlgCl p)
/-- The norm on `PadicAlgCl p` is nonarchimedean. -/
theorem isNonarchimedean : IsNonarchimedean (norm : PadicAlgCl p → ℝ) :=
isNonarchimedean_spectralNorm (K := ℚ_[p]) (L := PadicAlgCl p)
/-- The norm on `PadicAlgCl p` is the spectral norm induced by the `p`-adic norm on `ℚ_[p]`. -/
@[simp]
theorem spectralNorm_eq (x : PadicAlgCl p) : spectralNorm ℚ_[p] (PadicAlgCl p) x = ‖x‖ := rfl
/-- The norm on `PadicAlgCl p` extends the `p`-adic norm on `ℚ_[p]`. -/
@[simp] theorem norm_extends (x : ℚ_[p]) : ‖(x : PadicAlgCl p)‖ = ‖x‖ :=
spectralAlgNorm_extends (K := ℚ_[p]) (L := PadicAlgCl p) _
instance : IsUltrametricDist (PadicAlgCl p) :=
IsUltrametricDist.isUltrametricDist_of_forall_norm_add_le_max_norm (PadicAlgCl.isNonarchimedean p)
/-- `PadicAlgCl p` is a valued field, with the valuation corresponding to the `p`-adic norm. -/
instance valued : Valued (PadicAlgCl p) ℝ≥0 := NormedField.toValued
/-- The valuation of `x : PadicAlgCl p` agrees with its `ℝ≥0`-valued norm. -/
theorem valuation_def (x : PadicAlgCl p) : Valued.v x = ‖x‖₊ := rfl
/-- The coercion of the valuation of `x : PadicAlgCl p` to `ℝ` agrees with its norm. -/
@[simp] theorem valuation_coe (x : PadicAlgCl p) : ((Valued.v x : ℝ≥0) : ℝ) = ‖x‖ := rfl
/-- The valuation of `p : PadicAlgCl p` is `1/p`. -/
theorem valuation_p (p : ℕ) [Fact p.Prime] : Valued.v (p : PadicAlgCl p) = 1 / (p : ℝ≥0) := by
rw [← map_natCast (algebraMap ℚ_[p] (PadicAlgCl p))]
ext
rw [valuation_coe, norm_extends, padicNormE.norm_p, one_div, NNReal.coe_inv,
NNReal.coe_natCast]
/-- The valuation on `PadicAlgCl p` has rank one. -/
instance : RankOne (PadicAlgCl.valued p).v where
hom := MonoidWithZeroHom.id ℝ≥0
strictMono' := strictMono_id
exists_val_nontrivial := by
use p
have hp : Nat.Prime p := hp.1
simp only [valuation_p, one_div, ne_eq, inv_eq_zero, Nat.cast_eq_zero, inv_eq_one,
Nat.cast_eq_one]
exact ⟨hp.ne_zero, hp.ne_one⟩
instance : UniformContinuousConstSMul ℚ_[p] (PadicAlgCl p) :=
uniformContinuousConstSMul_of_continuousConstSMul ℚ_[p] (PadicAlgCl p)
end PadicAlgCl
/-- `ℂ_[p]` is the field of `p`-adic complex numbers, that is, the completion of `PadicAlgCl p` with
respect to the `p`-adic norm. -/
abbrev PadicComplex := UniformSpace.Completion (PadicAlgCl p)
/-- `ℂ_[p]` is the field of `p`-adic complex numbers. -/
notation "ℂ_[" p "]" => PadicComplex p
namespace PadicComplex
/-- `ℂ_[p]` is a valued field, where the valuation is the one extending that on `PadicAlgCl p`. -/
instance valued : Valued ℂ_[p] ℝ≥0 := inferInstance
/-- The valuation on `ℂ_[p]` extends the valuation on `PadicAlgCl p`. -/
theorem valuation_extends (x : PadicAlgCl p) : Valued.v (x : ℂ_[p]) = Valued.v x :=
Valued.extension_extends _
theorem coe_eq (x : PadicAlgCl p) : (x : ℂ_[p]) = algebraMap (PadicAlgCl p) ℂ_[p] x := rfl
@[simp] theorem coe_zero : ((0 : PadicAlgCl p) : ℂ_[p]) = 0 := rfl
/-- `ℂ_[p]` is an algebra over `ℚ_[p]`. -/
instance : Algebra ℚ_[p] ℂ_[p] where
smul := (UniformSpace.Completion.instSMul ℚ_[p] (PadicAlgCl p)).smul
algebraMap := (UniformSpace.Completion.coeRingHom).comp (algebraMap ℚ_[p] (PadicAlgCl p))
commutes' r x := by rw [mul_comm]
smul_def' r x := by
apply UniformSpace.Completion.ext' (continuous_const_smul r) (continuous_mul_left _)
intro a
rw [RingHom.coe_comp, Function.comp_apply, Algebra.smul_def]
rfl
instance : IsScalarTower ℚ_[p] (PadicAlgCl p) ℂ_[p] := IsScalarTower.of_algebraMap_eq (congrFun rfl)
@[simp, norm_cast]
lemma coe_natCast (n : ℕ) : ((n : PadicAlgCl p) : ℂ_[p]) = (n : ℂ_[p]) := by
rw [← map_natCast (algebraMap (PadicAlgCl p) ℂ_[p]) n, coe_eq]
/-- The valuation of `p : ℂ_[p]` is `1/p`. -/
theorem valuation_p : Valued.v (p : ℂ_[p]) = 1 / (p : ℝ≥0) := by
rw [← map_natCast (algebraMap (PadicAlgCl p) ℂ_[p]), ← coe_eq, valuation_extends,
PadicAlgCl.valuation_p]
/-- The valuation on `ℂ_[p]` has rank one. -/
instance : RankOne (PadicComplex.valued p).v where
hom := MonoidWithZeroHom.id ℝ≥0
strictMono' := strictMono_id
exists_val_nontrivial := by
use p
have hp : Nat.Prime p := hp.1
simp only [valuation_p, one_div, ne_eq, inv_eq_zero, Nat.cast_eq_zero, inv_eq_one,
Nat.cast_eq_one]
exact ⟨hp.ne_zero, hp.ne_one⟩
lemma rankOne_hom_eq :
RankOne.hom (PadicComplex.valued p).v = RankOne.hom (PadicAlgCl.valued p).v := rfl
/-- `ℂ_[p]` is a normed field, where the norm corresponds to the extension of the `p`-adic
valuation. -/
instance : NormedField ℂ_[p] := Valued.toNormedField _ _
theorem norm_def : (Norm.norm : ℂ_[p] → ℝ) = Valued.norm := rfl
/-- The norm on `ℂ_[p]` extends the norm on `PadicAlgCl p`. -/
theorem norm_extends (x : PadicAlgCl p) : ‖(x : ℂ_[p])‖ = ‖x‖ := by
rw [norm_def, Valued.norm, ← coe_nnnorm, valuation_extends p x, coe_nnnorm]
rfl
/-- The `ℝ≥0`-valued norm on `ℂ_[p]` extends that on `PadicAlgCl p`. -/
theorem nnnorm_extends (x : PadicAlgCl p) : ‖(x : ℂ_[p])‖₊ = ‖x‖₊ := by ext; exact norm_extends p x
/-- The norm on `ℂ_[p]` is nonarchimedean. -/
theorem isNonarchimedean : IsNonarchimedean (Norm.norm : ℂ_[p] → ℝ) := fun x y ↦ by
refine UniformSpace.Completion.induction_on₂ x y
(isClosed_le (continuous_norm.comp continuous_add) (by fun_prop)) (fun a b ↦ ?_)
rw [← UniformSpace.Completion.coe_add, norm_extends, norm_extends, norm_extends]
exact PadicAlgCl.isNonarchimedean p a b
end PadicComplex
/-- We define `𝓞_ℂ_[p]` as the valuation subring of of `ℂ_[p]`, consisting of those elements with
valuation `≤ 1`. -/
def PadicComplexInt : ValuationSubring ℂ_[p] := (PadicComplex.valued p).v.valuationSubring
/-- We define `𝓞_ℂ_[p]` as the subring of elements of `ℂ_[p]` with valuation `≤ 1`. -/
notation "𝓞_ℂ_[" p "]" => PadicComplexInt p
/-- `𝓞_ℂ_[p]` is the ring of integers of `ℂ_[p]`. -/
theorem PadicComplexInt.integers : Valuation.Integers (PadicComplex.valued p).v 𝓞_ℂ_[p] :=
Valuation.integer.integers _
|
LintStyle.lean
|
import Mathlib.Tactic.Linter.Style
import Mathlib.Order.SetNotation
/-! Tests for all the style linters. -/
/-! Tests for the `setOption` linter -/
section setOption
set_option linter.style.setOption true
-- All types of options are supported: boolean, numeric and string-valued.
-- On the top level, i.e. as commands.
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option pp.all'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option pp.all true
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option profiler'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option profiler false
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option pp.all'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option pp.all false
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option profiler.threshold'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option profiler.threshold 50
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option trace.profiler.output'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option trace.profiler.output "foo"
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option debug.moduleNameAtTimeout'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option debug.moduleNameAtTimeout false
-- The lint does not fire on arbitrary options.
set_option autoImplicit false
-- We also cover set_option tactics.
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option pp.all'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
lemma tactic : True := by
set_option pp.all true in
trivial
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option pp.raw.maxDepth'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
lemma tactic2 : True := by
set_option pp.raw.maxDepth 32 in
trivial
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option pp.all'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
lemma tactic3 : True := by
set_option pp.all false in
trivial
/--
warning: Setting options starting with 'debug', 'pp', 'profiler', 'trace' is only intended
for development and not for final code. If you intend to submit this contribution to the
Mathlib project, please remove 'set_option trace.profiler.output'.
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
lemma tactic4 : True := by
set_option trace.profiler.output "foo" in
trivial
-- This option is not affected, hence does not throw an error.
set_option autoImplicit true in
lemma foo' : True := trivial
-- TODO: add terms for the term form
/--
warning: Unscoped option maxHeartbeats is not allowed:
Please scope this to individual declarations, as in
```
set_option maxHeartbeats in
-- comment explaining why this is necessary
example : ... := ...
```
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option maxHeartbeats 20
#guard_msgs in
set_option maxHeartbeats 20 in
section
end
/--
warning: Unscoped option synthInstance.maxHeartbeats is not allowed:
Please scope this to individual declarations, as in
```
set_option synthInstance.maxHeartbeats in
-- comment explaining why this is necessary
example : ... := ...
```
Note: This linter can be disabled with `set_option linter.style.setOption false`
-/
#guard_msgs in
set_option synthInstance.maxHeartbeats 20
#guard_msgs in
set_option synthInstance.maxHeartbeats 20 in
section
end
end setOption
section cdotLinter
set_option linter.style.cdot true
set_option linter.globalAttributeIn false in
/--
warning: Please, use '·' (typed as `\.`) instead of '.' as 'cdot'.
Note: This linter can be disabled with `set_option linter.style.cdot false`
---
warning: Please, use '·' (typed as `\.`) instead of '.' as 'cdot'.
Note: This linter can be disabled with `set_option linter.style.cdot false`
---
warning: Please, use '·' (typed as `\.`) instead of '.' as 'cdot'.
Note: This linter can be disabled with `set_option linter.style.cdot false`
-/
#guard_msgs in
attribute [instance] Int.add in
instance : Inhabited Nat where
default := by
. have := 0
· have : Nat → Nat → Nat := (· + .)
. exact 0
/--
warning: Please, use '·' (typed as `\.`) instead of '.' as 'cdot'.
Note: This linter can be disabled with `set_option linter.style.cdot false`
-/
#guard_msgs in
example : Add Nat where add := (. + ·)
/--
warning: Please, use '·' (typed as `\.`) instead of '.' as 'cdot'.
Note: This linter can be disabled with `set_option linter.style.cdot false`
-/
#guard_msgs in
example : Add Nat where add := (. + ·)
/--
warning: Please, use '·' (typed as `\.`) instead of '.' as 'cdot'.
Note: This linter can be disabled with `set_option linter.style.cdot false`
---
warning: This central dot `·` is isolated; please merge it with the next line.
Note: This linter can be disabled with `set_option linter.style.cdot false`
---
warning: This central dot `·` is isolated; please merge it with the next line.
Note: This linter can be disabled with `set_option linter.style.cdot false`
-/
#guard_msgs in
example : Nat := by
have : Nat := by
·
-- some empty have
have := 0
·
-- another
have := 1
. exact 2
exact 0
#guard_msgs in
example : True := by
have : Nat := by
-- This is how code should look: no error.
· -- comment
exact 37
trivial
end cdotLinter
set_option linter.style.dollarSyntax true
set_option linter.globalAttributeIn false in
/--
warning: Please use '<|' instead of '$' for the pipe operator.
Note: This linter can be disabled with `set_option linter.style.dollarSyntax false`
---
warning: Please use '<|' instead of '$' for the pipe operator.
Note: This linter can be disabled with `set_option linter.style.dollarSyntax false`
-/
#guard_msgs in
attribute [instance] Int.add in
instance (f g : Nat → Nat) : Inhabited Nat where
default := by
· have := 0
· have : Nat := f $ g $ 0
· exact 0
section lambdaSyntaxLinter
set_option linter.style.lambdaSyntax true
/--
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
-/
#guard_msgs in
example : ℕ → ℕ := λ _ ↦ 0
/--
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
-/
#guard_msgs in
def foo : Bool := by
let _f : ℕ → ℕ := λ _ ↦ 0
exact true
example : ℕ → ℕ := fun n ↦ n - 1
/--
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
-/
#guard_msgs in
example : ℕ → ℕ := by exact λ n ↦ 3 * n + 1
/--
warning: declaration uses 'sorry'
---
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
---
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
---
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
-/
#guard_msgs in
example : ℕ → ℕ → ℕ → ℕ := by
have (n : ℕ) : True := trivial
have : (Set.univ : Set ℕ) = ⋃ (i : ℕ), (Set.iUnion λ j ↦ ({0, j} : Set ℕ)) := sorry
have : ∃ m : ℕ, ⋃ i : ℕ, (Set.univ : Set ℕ) = ∅ := sorry
exact λ _a ↦ fun _b ↦ λ _c ↦ 0
/--
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
---
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
---
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
-/
#guard_msgs in
example : True := by
have : 0 = 0 ∧ 0 = 0 ∧ 1 + 3 = 4 := by
refine ⟨by trivial, by
let _f := λ n : ℕ ↦ 0;
have : ℕ := by
· -- comment
· have := λ k : ℕ ↦ -5
· exact 0
refine ⟨by trivial, have := λ k : ℕ ↦ -5; by simp⟩
⟩
trivial
-- Code such as the following would require walking the infotree instead:
-- the inner set_option is ignore (in either direction).
-- As this seems unlikely to occur by accident and its use is dubious, we don't worry about this.
/--
warning: Please use 'fun' and not 'λ' to define anonymous functions.
The 'λ' syntax is deprecated in mathlib4.
Note: This linter can be disabled with `set_option linter.style.lambdaSyntax false`
-/
#guard_msgs in
example : ℕ → ℕ := λ _ ↦ 0
set_option linter.style.lambdaSyntax false
#guard_msgs in
example : ℕ → ℕ := λ _ ↦ 0
end lambdaSyntaxLinter
set_option linter.style.longLine true
/--
warning: This line exceeds the 100 character limit, please shorten it!
Note: This linter can be disabled with `set_option linter.style.longLine false`
-/
#guard_msgs in
/-! -/
#guard_msgs in
-- Lines with more than 100 characters containing URLs are allowed.
/-! http -/
set_option linter.style.longLine true
-- The *argument* of `#guard_msgs` is *not* exempt from the linter.
/--
warning: This line exceeds the 100 character limit, please shorten it!
Note: This linter can be disabled with `set_option linter.style.longLine false`
-/
#guard_msgs in #guard true
-- However, the *doc-string* of #guard_msgs is exempt from the linter:
-- these are automatically generated, hence linting them is not helpful.
/--
info: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
-/
#guard_msgs in
#eval List.range 27
-- TODO: this used to error about the 100 character limit (mentioning string gaps),
-- restore this test!
/-- info: " \" " : String -/
#guard_msgs in
#check " \" \
"
/- Tests for the `openClassical` linter -/
section openClassical
set_option linter.style.openClassical true
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements
which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open Classical
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements
which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open Nat Classical Nat
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements
which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open Classical hiding choose
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements
which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open Classical hiding choose axiomOfChoice
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements
which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open Classical renaming choose -> foo, byCases -> bar
-- Only opening specific items.
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements
which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open Classical (choose)
-- `open scoped Classical` is also linted
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements
which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open scoped Classical
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
---
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open scoped Int Classical Nat Classical
-- `open ... in` is *not* linted.
#guard_msgs in
open Classical (choose) in
def bar : Nat := 1
#guard_msgs in
open scoped Classical in
def baz : Nat := 1
-- After one `open Classical` statement, the linter does not fire on subsequent declarations.
/--
warning: please avoid 'open (scoped) Classical' statements: this can hide theorem statements which would be better stated with explicit decidability statements.
Instead, use `open Classical in` for definitions or instances, the `classical` tactic for proofs.
For theorem statements, either add missing decidability assumptions or use `open Classical in`.
Note: This linter can be disabled with `set_option linter.style.openClassical false`
-/
#guard_msgs in
open Classical
#guard_msgs in
def aux : Nat := 1
#guard_msgs in
def aux' : Nat := 1
end openClassical
/- Tests for the `show` linter -/
section showLinter
set_option linter.style.show true
-- The linter doesn't complain if the goal stays the same
#guard_msgs in
example : 1 + 2 = 3 := by
show 1 + 2 = 3
rfl
-- Binder names are ignored
#guard_msgs in
example : ∀ a : Nat, a = a := by
show ∀ b : Nat, b = b
intro
rfl
-- Goal changes are linted
/--
warning: The `show` tactic should only be used to indicate intermediate goal states for readability.
However, this tactic invocation changed the goal. Please use `change` instead for these purposes.
Note: This linter can be disabled with `set_option linter.style.show false`
-/
#guard_msgs in
example : (fun a => a) 1 = 1 := by
show 1 = 1
rfl
-- Assigning meta-variables in the goal is also linted
/--
warning: The `show` tactic should only be used to indicate intermediate goal states for readability.
However, this tactic invocation changed the goal. Please use `change` instead for these purposes.
Note: This linter can be disabled with `set_option linter.style.show false`
-/
#guard_msgs in
example := by
show 1 = 1
rfl
end showLinter
|
Liouville.lean
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Calculus.FDeriv.Analytic
import Mathlib.Analysis.Normed.Module.Completion
/-!
# Liouville's theorem
In this file we prove Liouville's theorem: if `f : E → F` is complex differentiable on the whole
space and its range is bounded, then the function is a constant. Various versions of this theorem
are formalized in `Differentiable.apply_eq_apply_of_bounded`,
`Differentiable.exists_const_forall_eq_of_bounded`, and
`Differentiable.exists_eq_const_of_bounded`.
The proof is based on the Cauchy integral formula for the derivative of an analytic function, see
`Complex.deriv_eq_smul_circleIntegral`.
-/
open TopologicalSpace Metric Set Filter Asymptotics Function MeasureTheory Bornology
open scoped Topology Filter NNReal Real
universe u v
variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] {F : Type v} [NormedAddCommGroup F]
[NormedSpace ℂ F]
local postfix:100 "̂" => UniformSpace.Completion
namespace Complex
/-- If `f` is complex differentiable on an open disc with center `c` and radius `R > 0` and is
continuous on its closure, then `f' c` can be represented as an integral over the corresponding
circle.
TODO: add a version for `w ∈ Metric.ball c R`.
TODO: add a version for higher derivatives. -/
theorem deriv_eq_smul_circleIntegral [CompleteSpace F] {R : ℝ} {c : ℂ} {f : ℂ → F} (hR : 0 < R)
(hf : DiffContOnCl ℂ f (ball c R)) :
deriv f c = (2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z := by
lift R to ℝ≥0 using hR.le
refine (hf.hasFPowerSeriesOnBall hR).hasFPowerSeriesAt.deriv.trans ?_
simp only [cauchyPowerSeries_apply, one_div, zpow_neg, pow_one, smul_smul, zpow_two, mul_inv]
theorem norm_deriv_le_aux [CompleteSpace F] {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R)
(hf : DiffContOnCl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) :
‖deriv f c‖ ≤ C / R := by
have : ∀ z ∈ sphere c R, ‖(z - c) ^ (-2 : ℤ) • f z‖ ≤ C / (R * R) :=
fun z (hz : ‖z - c‖ = R) => by
simpa [-mul_inv_rev, norm_smul, hz, zpow_two, ← div_eq_inv_mul] using
(div_le_div_iff_of_pos_right (mul_pos hR hR)).2 (hC z hz)
calc
‖deriv f c‖ = ‖(2 * π * I : ℂ)⁻¹ • ∮ z in C(c, R), (z - c) ^ (-2 : ℤ) • f z‖ :=
congr_arg norm (deriv_eq_smul_circleIntegral hR hf)
_ ≤ R * (C / (R * R)) :=
(circleIntegral.norm_two_pi_i_inv_smul_integral_le_of_norm_le_const hR.le this)
_ = C / R := by rw [mul_div_left_comm, div_self_mul_self', div_eq_mul_inv]
/-- If `f` is complex differentiable on an open disc of radius `R > 0`, is continuous on its
closure, and its values on the boundary circle of this disc are bounded from above by `C`, then the
norm of its derivative at the center is at most `C / R`. -/
theorem norm_deriv_le_of_forall_mem_sphere_norm_le {c : ℂ} {R C : ℝ} {f : ℂ → F} (hR : 0 < R)
(hd : DiffContOnCl ℂ f (ball c R)) (hC : ∀ z ∈ sphere c R, ‖f z‖ ≤ C) :
‖deriv f c‖ ≤ C / R := by
set e : F →L[ℂ] F̂ := UniformSpace.Completion.toComplL
have : HasDerivAt (e ∘ f) (e (deriv f c)) c :=
e.hasFDerivAt.comp_hasDerivAt c
(hd.differentiableAt isOpen_ball <| mem_ball_self hR).hasDerivAt
calc
‖deriv f c‖ = ‖deriv (e ∘ f) c‖ := by
rw [this.deriv]
exact (UniformSpace.Completion.norm_coe _).symm
_ ≤ C / R :=
norm_deriv_le_aux hR (e.differentiable.comp_diffContOnCl hd) fun z hz =>
(UniformSpace.Completion.norm_coe _).trans_le (hC z hz)
/-- An auxiliary lemma for Liouville's theorem `Differentiable.apply_eq_apply_of_bounded`. -/
theorem liouville_theorem_aux {f : ℂ → F} (hf : Differentiable ℂ f) (hb : IsBounded (range f))
(z w : ℂ) : f z = f w := by
suffices ∀ c, deriv f c = 0 from is_const_of_deriv_eq_zero hf this z w
clear z w; intro c
obtain ⟨C, C₀, hC⟩ : ∃ C > (0 : ℝ), ∀ z, ‖f z‖ ≤ C := by
rcases isBounded_iff_forall_norm_le.1 hb with ⟨C, hC⟩
exact
⟨max C 1, lt_max_iff.2 (Or.inr zero_lt_one), fun z =>
(hC (f z) (mem_range_self _)).trans (le_max_left _ _)⟩
refine norm_le_zero_iff.1 (le_of_forall_gt_imp_ge_of_dense fun ε ε₀ => ?_)
calc
‖deriv f c‖ ≤ C / (C / ε) :=
norm_deriv_le_of_forall_mem_sphere_norm_le (div_pos C₀ ε₀) hf.diffContOnCl fun z _ => hC z
_ = ε := div_div_cancel₀ C₀.lt.ne'
end Complex
namespace Differentiable
open Complex
/-- **Liouville's theorem**: a complex differentiable bounded function `f : E → F` is a constant. -/
theorem apply_eq_apply_of_bounded {f : E → F} (hf : Differentiable ℂ f) (hb : IsBounded (range f))
(z w : E) : f z = f w := by
set g : ℂ → F := f ∘ fun t : ℂ => t • (w - z) + z
suffices g 0 = g 1 by simpa [g]
apply liouville_theorem_aux
exacts [hf.comp ((differentiable_id.smul_const (w - z)).add_const z),
hb.subset (range_comp_subset_range _ _)]
/-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/
theorem exists_const_forall_eq_of_bounded {f : E → F} (hf : Differentiable ℂ f)
(hb : IsBounded (range f)) : ∃ c, ∀ z, f z = c :=
⟨f 0, fun _ => hf.apply_eq_apply_of_bounded hb _ _⟩
/-- **Liouville's theorem**: a complex differentiable bounded function is a constant. -/
theorem exists_eq_const_of_bounded {f : E → F} (hf : Differentiable ℂ f)
(hb : IsBounded (range f)) : ∃ c, f = const E c :=
(hf.exists_const_forall_eq_of_bounded hb).imp fun _ => funext
/-- A corollary of Liouville's theorem where the function tends to a finite value at infinity
(i.e., along `Filter.cocompact`, which in proper spaces coincides with `Bornology.cobounded`). -/
theorem eq_const_of_tendsto_cocompact [Nontrivial E] {f : E → F} (hf : Differentiable ℂ f) {c : F}
(hb : Tendsto f (cocompact E) (𝓝 c)) : f = Function.const E c := by
have h_bdd : Bornology.IsBounded (Set.range f) := by
obtain ⟨s, hs, hs_bdd⟩ := Metric.exists_isBounded_image_of_tendsto hb
obtain ⟨t, ht, hts⟩ := mem_cocompact.mp hs
apply ht.image hf.continuous |>.isBounded.union hs_bdd |>.subset
simpa [Set.image_union, Set.image_univ] using Set.image_mono <| calc
Set.univ = t ∪ tᶜ := t.union_compl_self.symm
_ ⊆ t ∪ s := by gcongr
obtain ⟨c', hc'⟩ := hf.exists_eq_const_of_bounded h_bdd
convert hc'
exact tendsto_nhds_unique hb (by simpa [hc'] using tendsto_const_nhds)
/-- A corollary of Liouville's theorem where the function tends to a finite value at infinity
(i.e., along `Filter.cocompact`, which in proper spaces coincides with `Bornology.cobounded`). -/
theorem apply_eq_of_tendsto_cocompact [Nontrivial E] {f : E → F} (hf : Differentiable ℂ f) {c : F}
(x : E) (hb : Tendsto f (cocompact E) (𝓝 c)) : f x = c :=
congr($(hf.eq_const_of_tendsto_cocompact hb) x)
end Differentiable
|
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.
|
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].
|
Shadow.lean
|
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Alena Gusakov, Yaël Dillies
-/
import Mathlib.Data.Finset.Grade
import Mathlib.Data.Finset.Sups
import Mathlib.Logic.Function.Iterate
/-!
# Shadows
This file defines shadows of a set family. The shadow of a set family is the set family of sets we
get by removing any element from any set of the original family. If one pictures `Finset α` as a big
hypercube (each dimension being membership of a given element), then taking the shadow corresponds
to projecting each finset down once in all available directions.
## Main definitions
* `Finset.shadow`: The shadow of a set family. Everything we can get by removing a new element from
some set.
* `Finset.upShadow`: The upper shadow of a set family. Everything we can get by adding an element
to some set.
## Notation
We define notation in locale `FinsetFamily`:
* `∂ 𝒜`: Shadow of `𝒜`.
* `∂⁺ 𝒜`: Upper shadow of `𝒜`.
We also maintain the convention that `a, b : α` are elements of the ground type, `s, t : Finset α`
are finsets, and `𝒜, ℬ : Finset (Finset α)` are finset families.
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
* http://discretemath.imp.fu-berlin.de/DMII-2015-16/kruskal.pdf
## Tags
shadow, set family
-/
open Finset Nat
variable {α : Type*}
namespace Finset
section Shadow
variable [DecidableEq α] {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} {a : α} {k r : ℕ}
/-- The shadow of a set family `𝒜` is all sets we can get by removing one element from any set in
`𝒜`, and the (`k` times) iterated shadow (`shadow^[k]`) is all sets we can get by removing `k`
elements from any set in `𝒜`. -/
def shadow (𝒜 : Finset (Finset α)) : Finset (Finset α) :=
𝒜.sup fun s => s.image (erase s)
@[inherit_doc] scoped[FinsetFamily] notation:max "∂ " => Finset.shadow
open FinsetFamily
/-- The shadow of the empty set is empty. -/
@[simp]
theorem shadow_empty : ∂ (∅ : Finset (Finset α)) = ∅ :=
rfl
@[simp] lemma shadow_iterate_empty (k : ℕ) : ∂^[k] (∅ : Finset (Finset α)) = ∅ := by
induction k <;> simp [*, shadow_empty]
@[simp]
theorem shadow_singleton_empty : ∂ ({∅} : Finset (Finset α)) = ∅ :=
rfl
@[simp]
theorem shadow_singleton (a : α) : ∂ {{a}} = {∅} := by
simp [shadow]
/-- The shadow is monotone. -/
@[mono]
theorem shadow_monotone : Monotone (shadow : Finset (Finset α) → Finset (Finset α)) := fun _ _ =>
sup_mono
@[gcongr] lemma shadow_mono (h𝒜ℬ : 𝒜 ⊆ ℬ) : ∂ 𝒜 ⊆ ∂ ℬ := shadow_monotone h𝒜ℬ
/-- `t` is in the shadow of `𝒜` iff there is a `s ∈ 𝒜` from which we can remove one element to
get `t`. -/
lemma mem_shadow_iff : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, ∃ a ∈ s, erase s a = t := by
simp only [shadow, mem_sup, mem_image]
theorem erase_mem_shadow (hs : s ∈ 𝒜) (ha : a ∈ s) : erase s a ∈ ∂ 𝒜 :=
mem_shadow_iff.2 ⟨s, hs, a, ha, rfl⟩
/-- `t ∈ ∂𝒜` iff `t` is exactly one element less than something from `𝒜`.
See also `Finset.mem_shadow_iff_exists_mem_card_add_one`. -/
lemma mem_shadow_iff_exists_sdiff : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #(s \ t) = 1 := by
simp_rw [mem_shadow_iff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_erase]
/-- `t` is in the shadow of `𝒜` iff we can add an element to it so that the resulting finset is in
`𝒜`. -/
lemma mem_shadow_iff_insert_mem : t ∈ ∂ 𝒜 ↔ ∃ a ∉ t, insert a t ∈ 𝒜 := by
simp_rw [mem_shadow_iff_exists_sdiff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_insert]
aesop
/-- `s ∈ ∂ 𝒜` iff `s` is exactly one element less than something from `𝒜`.
See also `Finset.mem_shadow_iff_exists_sdiff`. -/
lemma mem_shadow_iff_exists_mem_card_add_one : t ∈ ∂ 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #s = #t + 1 := by
refine mem_shadow_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
and_congr_right fun hst ↦ ?_
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
exact card_mono hst
lemma mem_shadow_iterate_iff_exists_card :
t ∈ ∂^[k] 𝒜 ↔ ∃ u : Finset α, #u = k ∧ Disjoint t u ∧ t ∪ u ∈ 𝒜 := by
induction k generalizing t with
| zero => simp
| succ k ih =>
simp only [mem_shadow_iff_insert_mem, ih, Function.iterate_succ_apply', card_eq_succ]
aesop
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something from `𝒜`.
See also `Finset.mem_shadow_iff_exists_mem_card_add`. -/
lemma mem_shadow_iterate_iff_exists_sdiff : t ∈ ∂^[k] 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #(s \ t) = k := by
rw [mem_shadow_iterate_iff_exists_card]
constructor
· rintro ⟨u, rfl, htu, hsuA⟩
exact ⟨_, hsuA, subset_union_left, by rw [union_sdiff_cancel_left htu]⟩
· rintro ⟨s, hs, hts, rfl⟩
refine ⟨s \ t, rfl, disjoint_sdiff, ?_⟩
rwa [union_sdiff_self_eq_union, union_eq_right.2 hts]
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`.
See also `Finset.mem_shadow_iterate_iff_exists_sdiff`. -/
lemma mem_shadow_iterate_iff_exists_mem_card_add :
t ∈ ∂^[k] 𝒜 ↔ ∃ s ∈ 𝒜, t ⊆ s ∧ #s = #t + k := by
refine mem_shadow_iterate_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
and_congr_right fun hst ↦ ?_
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
exact card_mono hst
/-- The shadow of a family of `r`-sets is a family of `r - 1`-sets. -/
protected theorem _root_.Set.Sized.shadow (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
(∂ 𝒜 : Set (Finset α)).Sized (r - 1) := by
intro A h
obtain ⟨A, hA, i, hi, rfl⟩ := mem_shadow_iff.1 h
rw [card_erase_of_mem hi, h𝒜 hA]
/-- The `k`-th shadow of a family of `r`-sets is a family of `r - k`-sets. -/
lemma _root_.Set.Sized.shadow_iterate (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
(∂^[k] 𝒜 : Set (Finset α)).Sized (r - k) := by
simp_rw [Set.Sized, mem_coe, mem_shadow_iterate_iff_exists_sdiff]
rintro t ⟨s, hs, hts, rfl⟩
rw [card_sdiff hts, ← h𝒜 hs, Nat.sub_sub_self (card_le_card hts)]
theorem sized_shadow_iff (h : ∅ ∉ 𝒜) :
(∂ 𝒜 : Set (Finset α)).Sized r ↔ (𝒜 : Set (Finset α)).Sized (r + 1) := by
refine ⟨fun h𝒜 s hs => ?_, Set.Sized.shadow⟩
obtain ⟨a, ha⟩ := nonempty_iff_ne_empty.2 (ne_of_mem_of_not_mem hs h)
rw [← h𝒜 (erase_mem_shadow hs ha), card_erase_add_one ha]
/-- Being in the shadow of `𝒜` means we have a superset in `𝒜`. -/
lemma exists_subset_of_mem_shadow (hs : t ∈ ∂ 𝒜) : ∃ s ∈ 𝒜, t ⊆ s :=
let ⟨t, ht, hst⟩ := mem_shadow_iff_exists_mem_card_add_one.1 hs
⟨t, ht, hst.1⟩
end Shadow
open FinsetFamily
section UpShadow
variable [DecidableEq α] [Fintype α] {𝒜 : Finset (Finset α)} {s t : Finset α} {a : α} {k r : ℕ}
/-- The upper shadow of a set family `𝒜` is all sets we can get by adding one element to any set in
`𝒜`, and the (`k` times) iterated upper shadow (`upShadow^[k]`) is all sets we can get by adding
`k` elements from any set in `𝒜`. -/
def upShadow (𝒜 : Finset (Finset α)) : Finset (Finset α) :=
𝒜.sup fun s => sᶜ.image fun a => insert a s
@[inherit_doc] scoped[FinsetFamily] notation:max "∂⁺ " => Finset.upShadow
/-- The upper shadow of the empty set is empty. -/
@[simp]
theorem upShadow_empty : ∂⁺ (∅ : Finset (Finset α)) = ∅ :=
rfl
/-- The upper shadow is monotone. -/
@[mono]
theorem upShadow_monotone : Monotone (upShadow : Finset (Finset α) → Finset (Finset α)) :=
fun _ _ => sup_mono
/-- `t` is in the upper shadow of `𝒜` iff there is a `s ∈ 𝒜` from which we can remove one element
to get `t`. -/
lemma mem_upShadow_iff : t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, ∃ a ∉ s, insert a s = t := by
simp_rw [upShadow, mem_sup, mem_image, mem_compl]
theorem insert_mem_upShadow (hs : s ∈ 𝒜) (ha : a ∉ s) : insert a s ∈ ∂⁺ 𝒜 :=
mem_upShadow_iff.2 ⟨s, hs, a, ha, rfl⟩
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly one element more than something from `𝒜`.
See also `Finset.mem_upShadow_iff_exists_mem_card_add_one`. -/
lemma mem_upShadow_iff_exists_sdiff : t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #(t \ s) = 1 := by
simp_rw [mem_upShadow_iff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_insert]
/-- `t` is in the upper shadow of `𝒜` iff we can remove an element from it so that the resulting
finset is in `𝒜`. -/
lemma mem_upShadow_iff_erase_mem : t ∈ ∂⁺ 𝒜 ↔ ∃ a, a ∈ t ∧ erase t a ∈ 𝒜 := by
simp_rw [mem_upShadow_iff_exists_sdiff, ← covBy_iff_card_sdiff_eq_one, covBy_iff_exists_erase]
aesop
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly one element less than something from `𝒜`.
See also `Finset.mem_upShadow_iff_exists_sdiff`. -/
lemma mem_upShadow_iff_exists_mem_card_add_one :
t ∈ ∂⁺ 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #t = #s + 1 := by
refine mem_upShadow_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
and_congr_right fun hst ↦ ?_
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
exact card_mono hst
lemma mem_upShadow_iterate_iff_exists_card :
t ∈ ∂⁺^[k] 𝒜 ↔ ∃ u : Finset α, #u = k ∧ u ⊆ t ∧ t \ u ∈ 𝒜 := by
induction k generalizing t with
| zero => simp
| succ k ih =>
simp only [mem_upShadow_iff_erase_mem, ih, Function.iterate_succ_apply', card_eq_succ,
subset_erase, erase_sdiff_comm, ← sdiff_insert]
constructor
· rintro ⟨a, hat, u, rfl, ⟨hut, hau⟩, htu⟩
exact ⟨_, ⟨_, _, hau, rfl, rfl⟩, insert_subset hat hut, htu⟩
· rintro ⟨_, ⟨a, u, hau, rfl, rfl⟩, hut, htu⟩
rw [insert_subset_iff] at hut
exact ⟨a, hut.1, _, rfl, ⟨hut.2, hau⟩, htu⟩
/-- `t` is in the upper shadow of `𝒜` iff `t` is exactly `k` elements less than something from `𝒜`.
See also `Finset.mem_upShadow_iff_exists_mem_card_add`. -/
lemma mem_upShadow_iterate_iff_exists_sdiff : t ∈ ∂⁺^[k] 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #(t \ s) = k := by
rw [mem_upShadow_iterate_iff_exists_card]
constructor
· rintro ⟨u, rfl, hut, htu⟩
exact ⟨_, htu, sdiff_subset, by rw [sdiff_sdiff_eq_self hut]⟩
· rintro ⟨s, hs, hst, rfl⟩
exact ⟨_, rfl, sdiff_subset, by rwa [sdiff_sdiff_eq_self hst]⟩
/-- `t ∈ ∂⁺^k 𝒜` iff `t` is exactly `k` elements less than something in `𝒜`.
See also `Finset.mem_upShadow_iterate_iff_exists_sdiff`. -/
lemma mem_upShadow_iterate_iff_exists_mem_card_add :
t ∈ ∂⁺^[k] 𝒜 ↔ ∃ s ∈ 𝒜, s ⊆ t ∧ #t = #s + k := by
refine mem_upShadow_iterate_iff_exists_sdiff.trans <| exists_congr fun t ↦ and_congr_right fun _ ↦
and_congr_right fun hst ↦ ?_
rw [card_sdiff hst, tsub_eq_iff_eq_add_of_le, add_comm]
exact card_mono hst
/-- The upper shadow of a family of `r`-sets is a family of `r + 1`-sets. -/
protected lemma _root_.Set.Sized.upShadow (h𝒜 : (𝒜 : Set (Finset α)).Sized r) :
(∂⁺ 𝒜 : Set (Finset α)).Sized (r + 1) := by
intro A h
obtain ⟨A, hA, i, hi, rfl⟩ := mem_upShadow_iff.1 h
rw [card_insert_of_notMem hi, h𝒜 hA]
/-- Being in the upper shadow of `𝒜` means we have a superset in `𝒜`. -/
theorem exists_subset_of_mem_upShadow (hs : s ∈ ∂⁺ 𝒜) : ∃ t ∈ 𝒜, t ⊆ s :=
let ⟨t, ht, hts, _⟩ := mem_upShadow_iff_exists_mem_card_add_one.1 hs
⟨t, ht, hts⟩
/-- `t ∈ ∂^k 𝒜` iff `t` is exactly `k` elements more than something in `𝒜`. -/
theorem mem_upShadow_iff_exists_mem_card_add :
s ∈ ∂⁺ ^[k] 𝒜 ↔ ∃ t ∈ 𝒜, t ⊆ s ∧ #t + k = #s := by
induction k generalizing 𝒜 s with
| zero =>
refine ⟨fun hs => ⟨s, hs, Subset.refl _, rfl⟩, ?_⟩
rintro ⟨t, ht, hst, hcard⟩
rwa [← eq_of_subset_of_card_le hst hcard.ge]
| succ k ih =>
simp only [Function.comp_apply, Function.iterate_succ]
refine ih.trans ?_
clear ih
constructor
· rintro ⟨t, ht, hts, hcardst⟩
obtain ⟨u, hu, hut, hcardtu⟩ := mem_upShadow_iff_exists_mem_card_add_one.1 ht
refine ⟨u, hu, hut.trans hts, ?_⟩
rw [← hcardst, hcardtu, add_right_comm]
rfl
· rintro ⟨t, ht, hts, hcard⟩
obtain ⟨u, htu, hus, hu⟩ := Finset.exists_subsuperset_card_eq hts (Nat.le_add_right _ 1)
(by omega)
refine ⟨u, mem_upShadow_iff_exists_mem_card_add_one.2 ⟨t, ht, htu, hu⟩, hus, ?_⟩
rw [hu, ← hcard, add_right_comm]
rfl
@[simp] lemma shadow_compls : ∂ 𝒜ᶜˢ = (∂⁺ 𝒜)ᶜˢ := by
ext s
simp only [mem_shadow_iff, mem_upShadow_iff, mem_compls]
refine (compl_involutive.toPerm _).exists_congr_left.trans ?_
simp [← compl_involutive.eq_iff]
@[simp] lemma upShadow_compls : ∂⁺ 𝒜ᶜˢ = (∂ 𝒜)ᶜˢ := by
ext s
simp only [mem_shadow_iff, mem_upShadow_iff, mem_compls]
refine (compl_involutive.toPerm _).exists_congr_left.trans ?_
simp [← compl_involutive.eq_iff]
end UpShadow
end Finset
|
Module.lean
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Frédéric Dupuis
-/
import Mathlib.Algebra.Star.SelfAdjoint
import Mathlib.Algebra.Module.Basic
import Mathlib.Algebra.Module.Equiv.Defs
import Mathlib.Algebra.Module.LinearMap.Star
import Mathlib.Algebra.Module.Rat
import Mathlib.LinearAlgebra.Prod
/-!
# The star operation, bundled as a star-linear equiv
We define `starLinearEquiv`, which is the star operation bundled as a star-linear map.
It is defined on a star algebra `A` over the base ring `R`.
This file also provides some lemmas that need `Algebra.Module.Basic` imported to prove.
## TODO
- Define `starLinearEquiv` for noncommutative `R`. We only the commutative case for now since,
in the noncommutative case, the ring hom needs to reverse the order of multiplication. This
requires a ring hom of type `R →+* Rᵐᵒᵖ`, which is very undesirable in the commutative case.
One way out would be to define a new typeclass `IsOp R S` and have an instance `IsOp R R`
for commutative `R`.
- Also note that such a definition involving `Rᵐᵒᵖ` or `is_op R S` would require adding
the appropriate `RingHomInvPair` instances to be able to define the semilinear
equivalence.
-/
section SMulLemmas
variable {R M : Type*}
@[simp]
theorem star_natCast_smul [Semiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ)
(x : M) : star ((n : R) • x) = (n : R) • star x :=
map_natCast_smul (starAddEquiv : M ≃+ M) R R n x
@[simp]
theorem star_intCast_smul [Ring R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℤ)
(x : M) : star ((n : R) • x) = (n : R) • star x :=
map_intCast_smul (starAddEquiv : M ≃+ M) R R n x
@[simp]
theorem star_inv_natCast_smul [DivisionSemiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M]
(n : ℕ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x :=
map_inv_natCast_smul (starAddEquiv : M ≃+ M) R R n x
@[simp]
theorem star_inv_intCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M]
(n : ℤ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x :=
map_inv_intCast_smul (starAddEquiv : M ≃+ M) R R n x
@[simp]
theorem star_ratCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℚ)
(x : M) : star ((n : R) • x) = (n : R) • star x :=
map_ratCast_smul (starAddEquiv : M ≃+ M) _ _ _ x
/-!
Per the naming convention, these two lemmas call `(q • ·)` `nnrat_smul` and `rat_smul` respectively,
rather than `nnqsmul` and `qsmul` because the latter are reserved to the actions coming from
`DivisionSemiring` and `DivisionRing`. We provide aliases with `nnqsmul` and `qsmul` for
discoverability.
-/
/-- Note that this lemma holds for an arbitrary `ℚ≥0`-action, rather than merely one coming from a
`DivisionSemiring`. We keep both the `nnqsmul` and `nnrat_smul` naming conventions for
discoverability. See `star_nnqsmul`. -/
@[simp high]
lemma star_nnrat_smul [AddCommMonoid R] [StarAddMonoid R] [Module ℚ≥0 R] (q : ℚ≥0) (x : R) :
star (q • x) = q • star x := map_nnrat_smul (starAddEquiv : R ≃+ R) _ _
/-- Note that this lemma holds for an arbitrary `ℚ`-action, rather than merely one coming from a
`DivisionRing`. We keep both the `qsmul` and `rat_smul` naming conventions for discoverability.
See `star_qsmul`. -/
@[simp high] lemma star_rat_smul [AddCommGroup R] [StarAddMonoid R] [Module ℚ R] (q : ℚ) (x : R) :
star (q • x) = q • star x :=
map_rat_smul (starAddEquiv : R ≃+ R) _ _
/-- Note that this lemma holds for an arbitrary `ℚ≥0`-action, rather than merely one coming from a
`DivisionSemiring`. We keep both the `nnqsmul` and `nnrat_smul` naming conventions for
discoverability. See `star_nnrat_smul`. -/
alias star_nnqsmul := star_nnrat_smul
/-- Note that this lemma holds for an arbitrary `ℚ`-action, rather than merely one coming from a
`DivisionRing`. We keep both the `qsmul` and `rat_smul` naming conventions for
discoverability. See `star_rat_smul`. -/
alias star_qsmul := star_rat_smul
instance StarAddMonoid.toStarModuleNNRat [AddCommMonoid R] [Module ℚ≥0 R] [StarAddMonoid R] :
StarModule ℚ≥0 R where star_smul := star_nnrat_smul
instance StarAddMonoid.toStarModuleRat [AddCommGroup R] [Module ℚ R] [StarAddMonoid R] :
StarModule ℚ R where star_smul := star_rat_smul
end SMulLemmas
/-- If `A` is a module over a commutative `R` with compatible actions,
then `star` is a semilinear equivalence. -/
@[simps]
def starLinearEquiv (R : Type*) {A : Type*} [CommSemiring R] [StarRing R] [AddCommMonoid A]
[StarAddMonoid A] [Module R A] [StarModule R A] : A ≃ₗ⋆[R] A :=
{ starAddEquiv with
toFun := star
map_smul' := star_smul }
section SelfSkewAdjoint
variable (R : Type*) (A : Type*) [Semiring R] [StarMul R] [TrivialStar R] [AddCommGroup A]
[Module R A] [StarAddMonoid A] [StarModule R A]
/-- The self-adjoint elements of a star module, as a submodule. -/
def selfAdjoint.submodule : Submodule R A :=
{ selfAdjoint A with smul_mem' := fun _ _ => (IsSelfAdjoint.all _).smul }
/-- The skew-adjoint elements of a star module, as a submodule. -/
def skewAdjoint.submodule : Submodule R A :=
{ skewAdjoint A with smul_mem' := skewAdjoint.smul_mem }
variable {A} [Invertible (2 : R)]
/-- The self-adjoint part of an element of a star module, as a linear map. -/
@[simps]
def selfAdjointPart : A →ₗ[R] selfAdjoint A where
toFun x :=
⟨(⅟2 : R) • (x + star x), by
rw [selfAdjoint.mem_iff, star_smul, star_trivial, star_add, star_star, add_comm]⟩
map_add' x y := by
ext
simp [add_add_add_comm]
map_smul' r x := by
ext
simp [← mul_smul, show ⅟2 * r = r * ⅟2 from Commute.invOf_left <| (2 : ℕ).cast_commute r]
/-- The skew-adjoint part of an element of a star module, as a linear map. -/
@[simps]
def skewAdjointPart : A →ₗ[R] skewAdjoint A where
toFun x :=
⟨(⅟2 : R) • (x - star x), by
simp only [skewAdjoint.mem_iff, star_smul, star_sub, star_star, star_trivial, ← smul_neg,
neg_sub]⟩
map_add' x y := by
ext
simp only [sub_add, ← smul_add, sub_sub_eq_add_sub, star_add, AddSubgroup.coe_add]
map_smul' r x := by
ext
simp [← mul_smul, ← smul_sub,
show r * ⅟2 = ⅟2 * r from Commute.invOf_right <| (2 : ℕ).commute_cast r]
theorem StarModule.selfAdjointPart_add_skewAdjointPart (x : A) :
(selfAdjointPart R x : A) + skewAdjointPart R x = x := by
simp only [smul_sub, selfAdjointPart_apply_coe, smul_add, skewAdjointPart_apply_coe,
add_add_sub_cancel, invOf_two_smul_add_invOf_two_smul]
theorem IsSelfAdjoint.coe_selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) :
(selfAdjointPart R x : A) = x := by
rw [selfAdjointPart_apply_coe, hx.star_eq, smul_add, invOf_two_smul_add_invOf_two_smul]
theorem IsSelfAdjoint.selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) :
selfAdjointPart R x = ⟨x, hx⟩ :=
Subtype.eq (hx.coe_selfAdjointPart_apply R)
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp`
theorem selfAdjointPart_comp_subtype_selfAdjoint :
(selfAdjointPart R).comp (selfAdjoint.submodule R A).subtype = .id :=
LinearMap.ext fun x ↦ x.2.selfAdjointPart_apply R
theorem IsSelfAdjoint.skewAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) :
skewAdjointPart R x = 0 := Subtype.eq <| by
rw [skewAdjointPart_apply_coe, hx.star_eq, sub_self, smul_zero, ZeroMemClass.coe_zero]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp`
theorem skewAdjointPart_comp_subtype_selfAdjoint :
(skewAdjointPart R).comp (selfAdjoint.submodule R A).subtype = 0 :=
LinearMap.ext fun x ↦ x.2.skewAdjointPart_apply R
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp`
theorem selfAdjointPart_comp_subtype_skewAdjoint :
(selfAdjointPart R).comp (skewAdjoint.submodule R A).subtype = 0 :=
LinearMap.ext fun ⟨x, (hx : _ = _)⟩ ↦ Subtype.eq <| by simp [hx]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp`
theorem skewAdjointPart_comp_subtype_skewAdjoint :
(skewAdjointPart R).comp (skewAdjoint.submodule R A).subtype = .id :=
LinearMap.ext fun ⟨x, (hx : _ = _)⟩ ↦ Subtype.eq <| by
simp only [LinearMap.comp_apply, Submodule.subtype_apply, skewAdjointPart_apply_coe, hx,
sub_neg_eq_add, smul_add, invOf_two_smul_add_invOf_two_smul]; rfl
variable (A)
/-- The decomposition of elements of a star module into their self- and skew-adjoint parts,
as a linear equivalence. -/
@[simps!]
def StarModule.decomposeProdAdjoint : A ≃ₗ[R] selfAdjoint A × skewAdjoint A := by
refine LinearEquiv.ofLinear ((selfAdjointPart R).prod (skewAdjointPart R))
(LinearMap.coprod ((selfAdjoint.submodule R A).subtype) (skewAdjoint.submodule R A).subtype)
?_ (LinearMap.ext <| StarModule.selfAdjointPart_add_skewAdjointPart R)
-- Note: with https://github.com/leanprover-community/mathlib4/pull/6965 `Submodule.coe_subtype` doesn't fire in `dsimp` or `simp`
ext x <;> dsimp <;> erw [Submodule.coe_subtype, Submodule.coe_subtype] <;> simp
end SelfSkewAdjoint
section algebraMap
variable {R A : Type*} [CommSemiring R] [StarRing R] [Semiring A]
variable [StarMul A] [Algebra R A] [StarModule R A]
@[simp]
theorem algebraMap_star_comm (r : R) : algebraMap R A (star r) = star (algebraMap R A r) := by
simp only [Algebra.algebraMap_eq_smul_one, star_smul, star_one]
variable (A) in
protected lemma IsSelfAdjoint.algebraMap {r : R} (hr : IsSelfAdjoint r) :
IsSelfAdjoint (algebraMap R A r) := by
simpa using congr(algebraMap R A $(hr.star_eq))
lemma isSelfAdjoint_algebraMap_iff {r : R} (h : Function.Injective (algebraMap R A)) :
IsSelfAdjoint (algebraMap R A r) ↔ IsSelfAdjoint r :=
⟨fun hr ↦ h <| algebraMap_star_comm r (A := A) ▸ hr.star_eq, IsSelfAdjoint.algebraMap A⟩
end algebraMap
theorem IsIdempotentElem.star_iff {R : Type*} [Mul R] [StarMul R] {a : R} :
IsIdempotentElem (star a) ↔ IsIdempotentElem a := by
simp [IsIdempotentElem, ← star_mul]
alias ⟨_, IsIdempotentElem.star⟩ := IsIdempotentElem.star_iff
|
PresheafedSpace.lean
|
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Adjunction.FullyFaithful
import Mathlib.CategoryTheory.Elementwise
import Mathlib.Topology.Sheaves.Presheaf
/-!
# Presheafed spaces
Introduces the category of topological spaces equipped with a presheaf (taking values in an
arbitrary target category `C`.)
We further describe how to apply functors and natural transformations to the values of the
presheaves.
-/
open Opposite CategoryTheory CategoryTheory.Category CategoryTheory.Functor TopCat TopologicalSpace
Topology
variable (C : Type*) [Category C]
-- Porting note: we used to have:
-- local attribute [tidy] tactic.auto_cases_opens
-- We would replace this by:
-- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opens
-- although it doesn't appear to help in this file, in any case.
-- Porting note: we used to have:
-- local attribute [tidy] tactic.op_induction'
-- A possible replacement would be:
-- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opposite
-- but this would probably require https://github.com/JLimperg/aesop/issues/59
-- In any case, it doesn't seem necessary here.
namespace AlgebraicGeometry
-- Porting note: `PresheafSpace.{w} C` is the type of topological spaces in `Type w` equipped
-- with a presheaf with values in `C`; then there is a total of three universe parameters
-- in `PresheafSpace.{w, v, u} C`, where `C : Type u` and `Category.{v} C`.
-- In mathlib3, some definitions in this file unnecessarily assumed `w=v`. This restriction
-- has been removed.
/-- A `PresheafedSpace C` is a topological space equipped with a presheaf of `C`s. -/
structure PresheafedSpace where
carrier : TopCat
protected presheaf : carrier.Presheaf C
variable {C}
namespace PresheafedSpace
instance coeCarrier : CoeOut (PresheafedSpace C) TopCat where coe X := X.carrier
attribute [coe] PresheafedSpace.carrier
instance : CoeSort (PresheafedSpace C) Type* where coe X := X.carrier
instance (X : PresheafedSpace C) : TopologicalSpace X :=
X.carrier.str
/-- The constant presheaf on `X` with value `Z`. -/
def const (X : TopCat) (Z : C) : PresheafedSpace C where
carrier := X
presheaf := (Functor.const _).obj Z
instance [Inhabited C] : Inhabited (PresheafedSpace C) :=
⟨const (TopCat.of PEmpty) default⟩
/-- A morphism between presheafed spaces `X` and `Y` consists of a continuous map
`f` between the underlying topological spaces, and a (notice contravariant!) map
from the presheaf on `Y` to the pushforward of the presheaf on `X` via `f`. -/
structure Hom (X Y : PresheafedSpace C) where
base : (X : TopCat) ⟶ (Y : TopCat)
c : Y.presheaf ⟶ base _* X.presheaf
@[ext (iff := false)]
theorem Hom.ext {X Y : PresheafedSpace C} (α β : Hom X Y) (w : α.base = β.base)
(h : α.c ≫ whiskerRight (eqToHom (by rw [w])) _ = β.c) : α = β := by
rcases α with ⟨base, c⟩
rcases β with ⟨base', c'⟩
dsimp at w
subst w
dsimp at h
erw [whiskerRight_id', comp_id] at h
subst h
rfl
-- TODO including `injections` would make tidy work earlier.
theorem hext {X Y : PresheafedSpace C} (α β : Hom X Y) (w : α.base = β.base) (h : α.c ≍ β.c) :
α = β := by
cases α
cases β
congr
/-- The identity morphism of a `PresheafedSpace`. -/
def id (X : PresheafedSpace C) : Hom X X where
base := 𝟙 (X : TopCat)
c := 𝟙 _
instance homInhabited (X : PresheafedSpace C) : Inhabited (Hom X X) :=
⟨id X⟩
/-- Composition of morphisms of `PresheafedSpace`s. -/
def comp {X Y Z : PresheafedSpace C} (α : Hom X Y) (β : Hom Y Z) : Hom X Z where
base := α.base ≫ β.base
c := β.c ≫ (Presheaf.pushforward _ β.base).map α.c
theorem comp_c {X Y Z : PresheafedSpace C} (α : Hom X Y) (β : Hom Y Z) :
(comp α β).c = β.c ≫ (Presheaf.pushforward _ β.base).map α.c :=
rfl
variable (C)
section
attribute [local simp] id comp
/-- The category of PresheafedSpaces. Morphisms are pairs, a continuous map and a presheaf map
from the presheaf on the target to the pushforward of the presheaf on the source. -/
instance categoryOfPresheafedSpaces : Category (PresheafedSpace C) where
Hom := Hom
id := id
comp := comp
variable {C}
/-- Cast `Hom X Y` as an arrow `X ⟶ Y` of presheaves. -/
abbrev Hom.toPshHom {X Y : PresheafedSpace C} (f : Hom X Y) : X ⟶ Y := f
@[ext (iff := false)]
theorem ext {X Y : PresheafedSpace C} (α β : X ⟶ Y) (w : α.base = β.base)
(h : α.c ≫ whiskerRight (eqToHom (by rw [w])) _ = β.c) : α = β :=
Hom.ext α β w h
end
variable {C}
attribute [local simp] eqToHom_map
@[simp]
theorem id_base (X : PresheafedSpace C) : (𝟙 X : X ⟶ X).base = 𝟙 (X : TopCat) :=
rfl
theorem id_c (X : PresheafedSpace C) :
(𝟙 X : X ⟶ X).c = 𝟙 X.presheaf :=
rfl
@[simp]
theorem id_c_app (X : PresheafedSpace C) (U) :
(𝟙 X : X ⟶ X).c.app U = X.presheaf.map (𝟙 U) := by
rw [id_c, map_id]
rfl
@[simp]
theorem comp_base {X Y Z : PresheafedSpace C} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).base = f.base ≫ g.base :=
rfl
instance (X Y : PresheafedSpace C) : CoeFun (X ⟶ Y) fun _ => (↑X → ↑Y) :=
⟨fun f => f.base⟩
/-!
Note that we don't include a `ConcreteCategory` instance, since equality of morphisms `X ⟶ Y`
does not follow from equality of their coercions `X → Y`.
-/
-- The `reassoc` attribute was added despite the LHS not being a composition of two homs,
-- for the reasons explained in the docstring.
-- Porting note: as there is no composition in the LHS it is purposely `@[reassoc, simp]` rather
-- than `@[reassoc (attr := simp)]`
/-- Sometimes rewriting with `comp_c_app` doesn't work because of dependent type issues.
In that case, `erw comp_c_app_assoc` might make progress.
The lemma `comp_c_app_assoc` is also better suited for rewrites in the opposite direction. -/
@[reassoc, simp]
theorem comp_c_app {X Y Z : PresheafedSpace C} (α : X ⟶ Y) (β : Y ⟶ Z) (U) :
(α ≫ β).c.app U = β.c.app U ≫ α.c.app (op ((Opens.map β.base).obj (unop U))) :=
rfl
theorem congr_app {X Y : PresheafedSpace C} {α β : X ⟶ Y} (h : α = β) (U) :
α.c.app U = β.c.app U ≫ X.presheaf.map (eqToHom (by subst h; rfl)) := by
subst h
simp
section
variable (C)
/-- The forgetful functor from `PresheafedSpace` to `TopCat`. -/
@[simps]
def forget : PresheafedSpace C ⥤ TopCat where
obj X := (X : TopCat)
map f := f.base
end
section Iso
variable {X Y : PresheafedSpace C}
/-- An isomorphism of `PresheafedSpace`s is a homeomorphism of the underlying space, and a
natural transformation between the sheaves.
-/
@[simps hom inv]
def isoOfComponents (H : X.1 ≅ Y.1) (α : H.hom _* X.2 ≅ Y.2) : X ≅ Y where
hom :=
{ base := H.hom
c := α.inv }
inv :=
{ base := H.inv
c := Presheaf.toPushforwardOfIso H α.hom }
hom_inv_id := by ext <;> simp
inv_hom_id := by
ext
· dsimp
exact H.inv_hom_id_apply _
dsimp
simp only [Presheaf.toPushforwardOfIso_app, assoc, ← α.hom.naturality]
simp only [eqToHom_map, eqToHom_app, eqToHom_trans_assoc, eqToHom_refl, id_comp]
apply Iso.inv_hom_id_app
/-- Isomorphic `PresheafedSpace`s have naturally isomorphic presheaves. -/
@[simps]
def sheafIsoOfIso (H : X ≅ Y) : Y.2 ≅ H.hom.base _* X.2 where
hom := H.hom.c
inv := Presheaf.pushforwardToOfIso ((forget _).mapIso H).symm H.inv.c
hom_inv_id := by
ext U
rw [NatTrans.comp_app]
simpa using congr_arg (fun f => f ≫ eqToHom _) (congr_app H.inv_hom_id (op U))
inv_hom_id := by
ext U
dsimp
rw [NatTrans.id_app]
simp only [Presheaf.pushforwardToOfIso_app, Iso.symm_inv, mapIso_hom, forget_map,
Iso.symm_hom, mapIso_inv, eqToHom_map, assoc]
have eq₁ := congr_app H.hom_inv_id (op ((Opens.map H.hom.base).obj U))
have eq₂ := H.hom.c.naturality (eqToHom (congr_obj (congr_arg Opens.map
((forget C).congr_map H.inv_hom_id.symm)) U)).op
rw [id_c, NatTrans.id_app, id_comp, eqToHom_map, comp_c_app] at eq₁
rw [eqToHom_op, eqToHom_map] at eq₂
erw [eq₂, reassoc_of% eq₁]
simp
instance base_isIso_of_iso (f : X ⟶ Y) [IsIso f] : IsIso f.base :=
((forget _).mapIso (asIso f)).isIso_hom
instance c_isIso_of_iso (f : X ⟶ Y) [IsIso f] : IsIso f.c :=
(sheafIsoOfIso (asIso f)).isIso_hom
/-- This could be used in conjunction with `CategoryTheory.NatIso.isIso_of_isIso_app`. -/
theorem isIso_of_components (f : X ⟶ Y) [IsIso f.base] [IsIso f.c] : IsIso f :=
(isoOfComponents (asIso f.base) (asIso f.c).symm).isIso_hom
end Iso
section Restrict
/-- The restriction of a presheafed space along an open embedding into the space.
-/
@[simps]
def restrict {U : TopCat} (X : PresheafedSpace C) {f : U ⟶ (X : TopCat)}
(h : IsOpenEmbedding f) : PresheafedSpace C where
carrier := U
presheaf := h.isOpenMap.functor.op ⋙ X.presheaf
/-- The map from the restriction of a presheafed space.
-/
@[simps]
def ofRestrict {U : TopCat} (X : PresheafedSpace C) {f : U ⟶ (X : TopCat)}
(h : IsOpenEmbedding f) : X.restrict h ⟶ X where
base := f
c :=
{ app := fun V => X.presheaf.map (h.isOpenMap.adjunction.counit.app V.unop).op
naturality := fun U V f =>
show _ = _ ≫ X.presheaf.map _ by
rw [← map_comp, ← map_comp]
rfl }
instance ofRestrict_mono {U : TopCat} (X : PresheafedSpace C) (f : U ⟶ X.1)
(hf : IsOpenEmbedding f) : Mono (X.ofRestrict hf) := by
haveI : Mono f := (TopCat.mono_iff_injective _).mpr hf.injective
constructor
intro Z g₁ g₂ eq
ext1
· have := congr_arg PresheafedSpace.Hom.base eq
simp only [PresheafedSpace.comp_base, PresheafedSpace.ofRestrict_base] at this
rw [cancel_mono] at this
exact this
· ext V
have hV : (Opens.map (X.ofRestrict hf).base).obj (hf.isOpenMap.functor.obj V) = V := by
ext1
exact Set.preimage_image_eq _ hf.injective
haveI :
IsIso (hf.isOpenMap.adjunction.counit.app (unop (op (hf.isOpenMap.functor.obj V)))) :=
NatIso.isIso_app_of_isIso
(whiskerLeft hf.isOpenMap.functor hf.isOpenMap.adjunction.counit) V
have := PresheafedSpace.congr_app eq (op (hf.isOpenMap.functor.obj V))
rw [PresheafedSpace.comp_c_app, PresheafedSpace.comp_c_app,
PresheafedSpace.ofRestrict_c_app, Category.assoc, cancel_epi] at this
have h : _ ≫ _ = _ ≫ _ ≫ _ :=
congr_arg (fun f => (X.restrict hf).presheaf.map (eqToHom hV).op ≫ f) this
simp only [g₁.c.naturality, g₂.c.naturality_assoc] at h
simp only [eqToHom_op, eqToHom_map, eqToHom_trans,
← IsIso.comp_inv_eq, inv_eqToHom, Category.assoc] at h
simpa using h
theorem restrict_top_presheaf (X : PresheafedSpace C) :
(X.restrict (Opens.isOpenEmbedding ⊤)).presheaf =
(Opens.inclusionTopIso X.carrier).inv _* X.presheaf := by
dsimp
rw [Opens.inclusion'_top_functor X.carrier]
rfl
theorem ofRestrict_top_c (X : PresheafedSpace C) :
(X.ofRestrict (Opens.isOpenEmbedding ⊤)).c =
eqToHom
(by
rw [restrict_top_presheaf, ← Presheaf.Pushforward.comp_eq]
erw [Iso.inv_hom_id]
rw [Presheaf.id_pushforward]
dsimp) := by
/- another approach would be to prove the left hand side
is a natural isomorphism, but I encountered a universe
issue when `apply NatIso.isIso_of_isIso_app`. -/
ext
dsimp [ofRestrict]
erw [eqToHom_map, eqToHom_app]
simp
/-- The map to the restriction of a presheafed space along the canonical inclusion from the top
subspace.
-/
@[simps]
def toRestrictTop (X : PresheafedSpace C) : X ⟶ X.restrict (Opens.isOpenEmbedding ⊤) where
base := (Opens.inclusionTopIso X.carrier).inv
c := eqToHom (restrict_top_presheaf X)
/-- The isomorphism from the restriction to the top subspace.
-/
@[simps]
def restrictTopIso (X : PresheafedSpace C) : X.restrict (Opens.isOpenEmbedding ⊤) ≅ X where
hom := X.ofRestrict _
inv := X.toRestrictTop
hom_inv_id := by
ext
· rfl
· erw [comp_c, toRestrictTop_c, whiskerRight_id',
comp_id, ofRestrict_top_c, eqToHom_map, eqToHom_trans, eqToHom_refl]
rfl
inv_hom_id := by
ext
· rfl
· erw [comp_c, ofRestrict_top_c, toRestrictTop_c, eqToHom_map, whiskerRight_id', comp_id,
eqToHom_trans, eqToHom_refl]
rfl
end Restrict
/-- The global sections, notated Gamma.
-/
@[simps]
def Γ : (PresheafedSpace C)ᵒᵖ ⥤ C where
obj X := (unop X).presheaf.obj (op ⊤)
map f := f.unop.c.app (op ⊤)
theorem Γ_obj_op (X : PresheafedSpace C) : Γ.obj (op X) = X.presheaf.obj (op ⊤) :=
rfl
theorem Γ_map_op {X Y : PresheafedSpace C} (f : X ⟶ Y) : Γ.map f.op = f.c.app (op ⊤) :=
rfl
end PresheafedSpace
end AlgebraicGeometry
open AlgebraicGeometry AlgebraicGeometry.PresheafedSpace
variable {C}
namespace CategoryTheory
variable {D : Type*} [Category D]
namespace Functor
/-- We can apply a functor `F : C ⥤ D` to the values of the presheaf in any `PresheafedSpace C`,
giving a functor `PresheafedSpace C ⥤ PresheafedSpace D` -/
def mapPresheaf (F : C ⥤ D) : PresheafedSpace C ⥤ PresheafedSpace D where
obj X :=
{ carrier := X.carrier
presheaf := X.presheaf ⋙ F }
map f :=
{ base := f.base
c := whiskerRight f.c F }
-- Porting note: these proofs were automatic in mathlib3
map_id X := by
ext U
· rfl
· simp
map_comp f g := by
ext U
· rfl
· simp
@[simp]
theorem mapPresheaf_obj_X (F : C ⥤ D) (X : PresheafedSpace C) :
(F.mapPresheaf.obj X : TopCat) = (X : TopCat) :=
rfl
@[simp]
theorem mapPresheaf_obj_presheaf (F : C ⥤ D) (X : PresheafedSpace C) :
(F.mapPresheaf.obj X).presheaf = X.presheaf ⋙ F :=
rfl
@[simp]
theorem mapPresheaf_map_f (F : C ⥤ D) {X Y : PresheafedSpace C} (f : X ⟶ Y) :
(F.mapPresheaf.map f).base = f.base :=
rfl
@[simp]
theorem mapPresheaf_map_c (F : C ⥤ D) {X Y : PresheafedSpace C} (f : X ⟶ Y) :
(F.mapPresheaf.map f).c = whiskerRight f.c F :=
rfl
end Functor
namespace NatTrans
/-- A natural transformation induces a natural transformation between the `map_presheaf` functors.
-/
def onPresheaf {F G : C ⥤ D} (α : F ⟶ G) : G.mapPresheaf ⟶ F.mapPresheaf where
app X :=
{ base := 𝟙 _
c := whiskerLeft X.presheaf α ≫ eqToHom (Presheaf.Pushforward.id_eq _).symm }
-- TODO Assemble the last two constructions into a functor
-- `(C ⥤ D) ⥤ (PresheafedSpace C ⥤ PresheafedSpace D)`
end NatTrans
end CategoryTheory
|
Vieta.lean
|
/-
Copyright (c) 2020 Hanting Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hanting Zhang
-/
import Mathlib.Algebra.Polynomial.Splits
import Mathlib.RingTheory.MvPolynomial.Symmetric.Defs
/-!
# Vieta's Formula
The main result is `Multiset.prod_X_add_C_eq_sum_esymm`, which shows that the product of
linear terms `X + λ` with `λ` in a `Multiset s` is equal to a linear combination of the
symmetric functions `esymm s`.
From this, we deduce `MvPolynomial.prod_X_add_C_eq_sum_esymm` which is the equivalent formula
for the product of linear terms `X + X i` with `i` in a `Fintype σ` as a linear combination
of the symmetric polynomials `esymm σ R j`.
For `R` be an integral domain (so that `p.roots` is defined for any `p : R[X]` as a multiset),
we derive `Polynomial.coeff_eq_esymm_roots_of_card`, the relationship between the coefficients and
the roots of `p` for a polynomial `p` that splits (i.e. having as many roots as its degree).
-/
open Finset Polynomial
namespace Multiset
section Semiring
variable {R : Type*} [CommSemiring R]
/-- A sum version of **Vieta's formula** for `Multiset`: the product of the linear terms `X + λ`
where `λ` runs through a multiset `s` is equal to a linear combination of the symmetric functions
`esymm s` of the `λ`'s . -/
theorem prod_X_add_C_eq_sum_esymm (s : Multiset R) :
(s.map fun r => X + C r).prod =
∑ j ∈ Finset.range (Multiset.card s + 1), (C (s.esymm j) * X ^ (Multiset.card s - j)) := by
classical
rw [prod_map_add, antidiagonal_eq_map_powerset, map_map, ← bind_powerset_len,
map_bind, sum_bind, Finset.sum_eq_multiset_sum, Finset.range_val, map_congr (Eq.refl _)]
intro _ _
rw [esymm, ← sum_hom', ← sum_map_mul_right, map_congr (Eq.refl _)]
intro s ht
rw [mem_powersetCard] at ht
dsimp
rw [prod_hom' s (Polynomial.C : R →+* R[X])]
simp [ht, prod_replicate, map_id', card_sub]
/-- Vieta's formula for the coefficients of the product of linear terms `X + λ` where `λ` runs
through a multiset `s` : the `k`th coefficient is the symmetric function `esymm (card s - k) s`. -/
theorem prod_X_add_C_coeff (s : Multiset R) {k : ℕ} (h : k ≤ Multiset.card s) :
(s.map fun r => X + C r).prod.coeff k = s.esymm (Multiset.card s - k) := by
convert Polynomial.ext_iff.mp (prod_X_add_C_eq_sum_esymm s) k using 1
simp_rw [finset_sum_coeff, coeff_C_mul_X_pow]
rw [Finset.sum_eq_single_of_mem (Multiset.card s - k) _] <;> grind
theorem prod_X_add_C_coeff' {σ} (s : Multiset σ) (r : σ → R) {k : ℕ} (h : k ≤ Multiset.card s) :
(s.map fun i => X + C (r i)).prod.coeff k = (s.map r).esymm (Multiset.card s - k) := by
rw [← Function.comp_def (f := fun r => X + C r) (g := r), ← map_map, prod_X_add_C_coeff]
<;> rw [s.card_map r]; assumption
theorem _root_.Finset.prod_X_add_C_coeff {σ} (s : Finset σ) (r : σ → R) {k : ℕ} (h : k ≤ #s) :
(∏ i ∈ s, (X + C (r i))).coeff k = ∑ t ∈ s.powersetCard (#s - k), ∏ i ∈ t, r i := by
rw [Finset.prod, prod_X_add_C_coeff' _ r h, Finset.esymm_map_val]
rfl
end Semiring
section Ring
variable {R : Type*} [CommRing R]
theorem esymm_neg (s : Multiset R) (k : ℕ) : (map Neg.neg s).esymm k = (-1) ^ k * esymm s k := by
rw [esymm, esymm, ← Multiset.sum_map_mul_left, Multiset.powersetCard_map, Multiset.map_map,
map_congr rfl]
intro x hx
rw [(mem_powersetCard.mp hx).right.symm, ← prod_replicate, ← Multiset.map_const]
nth_rw 3 [← map_id' x]
rw [← prod_map_mul, map_congr rfl, Function.comp_apply]
exact fun z _ => neg_one_mul z
theorem prod_X_sub_X_eq_sum_esymm (s : Multiset R) :
(s.map fun t => X - C t).prod =
∑ j ∈ Finset.range (Multiset.card s + 1),
(-1) ^ j * (C (s.esymm j) * X ^ (Multiset.card s - j)) := by
conv_lhs =>
congr
congr
ext x
rw [sub_eq_add_neg]
rw [← map_neg C x]
convert prod_X_add_C_eq_sum_esymm (map (fun t => -t) s) using 1
· rw [map_map]; rfl
· simp only [esymm_neg, card_map, mul_assoc, map_mul, map_pow, map_neg, map_one]
theorem prod_X_sub_C_coeff (s : Multiset R) {k : ℕ} (h : k ≤ Multiset.card s) :
(s.map fun t => X - C t).prod.coeff k =
(-1) ^ (Multiset.card s - k) * s.esymm (Multiset.card s - k) := by
conv_lhs =>
congr
congr
congr
ext x
rw [sub_eq_add_neg]
rw [← map_neg C x]
convert prod_X_add_C_coeff (map (fun t => -t) s) _ using 1
· rw [map_map]; rfl
· rw [esymm_neg, card_map]
· rwa [card_map]
/-- Vieta's formula for the coefficients and the roots of a polynomial over an integral domain
with as many roots as its degree. -/
theorem _root_.Polynomial.coeff_eq_esymm_roots_of_card [IsDomain R] {p : R[X]}
(hroots : Multiset.card p.roots = p.natDegree) {k : ℕ} (h : k ≤ p.natDegree) :
p.coeff k = p.leadingCoeff * (-1) ^ (p.natDegree - k) * p.roots.esymm (p.natDegree - k) := by
conv_lhs => rw [← C_leadingCoeff_mul_prod_multiset_X_sub_C hroots]
rw [coeff_C_mul, mul_assoc]; congr
have : k ≤ card (roots p) := by rw [hroots]; exact h
convert p.roots.prod_X_sub_C_coeff this using 3 <;> rw [hroots]
/-- Vieta's formula for split polynomials over a field. -/
theorem _root_.Polynomial.coeff_eq_esymm_roots_of_splits {F} [Field F] {p : F[X]}
(hsplit : p.Splits (RingHom.id F)) {k : ℕ} (h : k ≤ p.natDegree) :
p.coeff k = p.leadingCoeff * (-1) ^ (p.natDegree - k) * p.roots.esymm (p.natDegree - k) :=
Polynomial.coeff_eq_esymm_roots_of_card (splits_iff_card_roots.1 hsplit) h
end Ring
end Multiset
section MvPolynomial
open Finset Polynomial Fintype
variable (R σ : Type*) [CommSemiring R] [Fintype σ]
/-- A sum version of Vieta's formula for `MvPolynomial`: viewing `X i` as variables,
the product of linear terms `λ + X i` is equal to a linear combination of
the symmetric polynomials `esymm σ R j`. -/
theorem MvPolynomial.prod_C_add_X_eq_sum_esymm :
(∏ i : σ, (Polynomial.X + Polynomial.C (MvPolynomial.X i))) =
∑ j ∈ range (card σ + 1), Polynomial.C
(MvPolynomial.esymm σ R j) * Polynomial.X ^ (card σ - j) := by
let s := Finset.univ.val.map fun i : σ => (MvPolynomial.X i : MvPolynomial σ R)
have : Fintype.card σ = Multiset.card s := by
rw [Multiset.card_map, ← Finset.card_univ, Finset.card_def]
simp_rw [this, MvPolynomial.esymm_eq_multiset_esymm σ R, Finset.prod_eq_multiset_prod]
convert Multiset.prod_X_add_C_eq_sum_esymm s
simp_rw [s, Multiset.map_map, Function.comp_apply]
theorem MvPolynomial.prod_X_add_C_coeff (k : ℕ) (h : k ≤ card σ) :
(∏ i : σ, (Polynomial.X + Polynomial.C (MvPolynomial.X i)) : Polynomial _).coeff k =
MvPolynomial.esymm σ R (card σ - k) := by
let s := Finset.univ.val.map fun i => (MvPolynomial.X i : MvPolynomial σ R)
have : Fintype.card σ = Multiset.card s := by
rw [Multiset.card_map, ← Finset.card_univ, Finset.card_def]
rw [this] at h ⊢
rw [MvPolynomial.esymm_eq_multiset_esymm σ R, Finset.prod_eq_multiset_prod]
convert Multiset.prod_X_add_C_coeff s h
dsimp
simp_rw [s, Multiset.map_map, Function.comp_apply]
end MvPolynomial
|
Basic.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Order.Max
import Mathlib.Order.ULift
import Mathlib.Tactic.Push
import Mathlib.Tactic.Finiteness.Attr
import Mathlib.Util.AssertExists
/-!
# ⊤ and ⊥, bounded lattices and variants
This file defines top and bottom elements (greatest and least elements) of a type, the bounded
variants of different kinds of lattices, sets up the typeclass hierarchy between them and provides
instances for `Prop` and `fun`.
## Main declarations
* `<Top/Bot> α`: Typeclasses to declare the `⊤`/`⊥` notation.
* `Order<Top/Bot> α`: Order with a top/bottom element.
* `BoundedOrder α`: Order with a top and bottom element.
-/
assert_not_exists Monotone
universe u v
variable {α : Type u} {β : Type v}
/-! ### Top, bottom element -/
/-- An order is an `OrderTop` if it has a greatest element.
We state this using a data mixin, holding the value of `⊤` and the greatest element constraint. -/
class OrderTop (α : Type u) [LE α] extends Top α where
/-- `⊤` is the greatest element -/
le_top : ∀ a : α, a ≤ ⊤
section OrderTop
/-- An order is (noncomputably) either an `OrderTop` or a `NoTopOrder`. Use as
`casesI topOrderOrNoTopOrder α`. -/
noncomputable def topOrderOrNoTopOrder (α : Type*) [LE α] : OrderTop α ⊕' NoTopOrder α := by
by_cases H : ∀ a : α, ∃ b, ¬b ≤ a
· exact PSum.inr ⟨H⟩
· push_neg at H
letI : Top α := ⟨Classical.choose H⟩
exact PSum.inl ⟨Classical.choose_spec H⟩
section LE
variable [LE α] [OrderTop α] {a : α}
@[simp]
theorem le_top : a ≤ ⊤ :=
OrderTop.le_top a
@[simp]
theorem isTop_top : IsTop (⊤ : α) := fun _ => le_top
end LE
/-- A top element can be replaced with `⊤`.
Prefer `IsTop.eq_top` if `α` already has a top element. -/
@[elab_as_elim]
protected def IsTop.rec [LE α] {P : (x : α) → IsTop x → Sort*}
(h : ∀ [OrderTop α], P ⊤ isTop_top) (x : α) (hx : IsTop x) : P x hx := by
letI : OrderTop α := { top := x, le_top := hx }
apply h
section Preorder
variable [Preorder α] [OrderTop α] {a b : α}
@[simp]
theorem isMax_top : IsMax (⊤ : α) :=
isTop_top.isMax
@[simp]
theorem not_top_lt : ¬⊤ < a :=
isMax_top.not_lt
theorem ne_top_of_lt (h : a < b) : a ≠ ⊤ :=
(h.trans_le le_top).ne
alias LT.lt.ne_top := ne_top_of_lt
theorem lt_top_of_lt (h : a < b) : a < ⊤ :=
lt_of_lt_of_le h le_top
alias LT.lt.lt_top := lt_top_of_lt
attribute [aesop (rule_sets := [finiteness]) unsafe 20%] ne_top_of_lt
-- would have been better to implement this as a "safe" "forward" rule, why doesn't this work?
-- attribute [aesop (rule_sets := [finiteness]) safe forward] ne_top_of_lt
end Preorder
variable [PartialOrder α] [OrderTop α] [Preorder β] {f : α → β} {a b : α}
@[simp]
theorem isMax_iff_eq_top : IsMax a ↔ a = ⊤ :=
⟨fun h => h.eq_of_le le_top, fun h _ _ => h.symm ▸ le_top⟩
@[simp]
theorem isTop_iff_eq_top : IsTop a ↔ a = ⊤ :=
⟨fun h => h.isMax.eq_of_le le_top, fun h _ => h.symm ▸ le_top⟩
theorem not_isMax_iff_ne_top : ¬IsMax a ↔ a ≠ ⊤ :=
isMax_iff_eq_top.not
theorem not_isTop_iff_ne_top : ¬IsTop a ↔ a ≠ ⊤ :=
isTop_iff_eq_top.not
alias ⟨IsMax.eq_top, _⟩ := isMax_iff_eq_top
alias ⟨IsTop.eq_top, _⟩ := isTop_iff_eq_top
@[simp]
theorem top_le_iff : ⊤ ≤ a ↔ a = ⊤ :=
le_top.ge_iff_eq
theorem top_unique (h : ⊤ ≤ a) : a = ⊤ :=
le_top.antisymm h
theorem eq_top_iff : a = ⊤ ↔ ⊤ ≤ a :=
top_le_iff.symm
theorem eq_top_mono (h : a ≤ b) (h₂ : a = ⊤) : b = ⊤ :=
top_unique <| h₂ ▸ h
theorem lt_top_iff_ne_top : a < ⊤ ↔ a ≠ ⊤ :=
le_top.lt_iff_ne
@[simp]
theorem not_lt_top_iff : ¬a < ⊤ ↔ a = ⊤ :=
lt_top_iff_ne_top.not_left
theorem eq_top_or_lt_top (a : α) : a = ⊤ ∨ a < ⊤ :=
le_top.eq_or_lt
@[aesop (rule_sets := [finiteness]) safe apply]
theorem Ne.lt_top (h : a ≠ ⊤) : a < ⊤ :=
lt_top_iff_ne_top.mpr h
theorem Ne.lt_top' (h : ⊤ ≠ a) : a < ⊤ :=
h.symm.lt_top
theorem ne_top_of_le_ne_top (hb : b ≠ ⊤) (hab : a ≤ b) : a ≠ ⊤ :=
(hab.trans_lt hb.lt_top).ne
lemma top_notMem_iff {s : Set α} : ⊤ ∉ s ↔ ∀ x ∈ s, x < ⊤ :=
⟨fun h x hx ↦ Ne.lt_top (fun hx' : x = ⊤ ↦ h (hx' ▸ hx)), fun h h₀ ↦ (h ⊤ h₀).false⟩
@[deprecated (since := "2025-05-23")] alias top_not_mem_iff := top_notMem_iff
variable [Nontrivial α]
theorem not_isMin_top : ¬IsMin (⊤ : α) := fun h =>
let ⟨_, ha⟩ := exists_ne (⊤ : α)
ha <| top_le_iff.1 <| h le_top
end OrderTop
theorem OrderTop.ext_top {α} {hA : PartialOrder α} (A : OrderTop α) {hB : PartialOrder α}
(B : OrderTop α) (H : ∀ x y : α, (haveI := hA; x ≤ y) ↔ x ≤ y) :
(@Top.top α (@OrderTop.toTop α hA.toLE A)) = (@Top.top α (@OrderTop.toTop α hB.toLE B)) := by
cases PartialOrder.ext H
apply top_unique
exact @le_top _ _ A _
/-- An order is an `OrderBot` if it has a least element.
We state this using a data mixin, holding the value of `⊥` and the least element constraint. -/
class OrderBot (α : Type u) [LE α] extends Bot α where
/-- `⊥` is the least element -/
bot_le : ∀ a : α, ⊥ ≤ a
section OrderBot
/-- An order is (noncomputably) either an `OrderBot` or a `NoBotOrder`. Use as
`casesI botOrderOrNoBotOrder α`. -/
noncomputable def botOrderOrNoBotOrder (α : Type*) [LE α] : OrderBot α ⊕' NoBotOrder α := by
by_cases H : ∀ a : α, ∃ b, ¬a ≤ b
· exact PSum.inr ⟨H⟩
· push_neg at H
letI : Bot α := ⟨Classical.choose H⟩
exact PSum.inl ⟨Classical.choose_spec H⟩
section LE
variable [LE α] [OrderBot α] {a : α}
@[simp]
theorem bot_le : ⊥ ≤ a :=
OrderBot.bot_le a
@[simp]
theorem isBot_bot : IsBot (⊥ : α) := fun _ => bot_le
end LE
/-- A bottom element can be replaced with `⊥`.
Prefer `IsBot.eq_bot` if `α` already has a bottom element. -/
@[elab_as_elim]
protected def IsBot.rec [LE α] {P : (x : α) → IsBot x → Sort*}
(h : ∀ [OrderBot α], P ⊥ isBot_bot) (x : α) (hx : IsBot x) : P x hx := by
letI : OrderBot α := { bot := x, bot_le := hx }
apply h
namespace OrderDual
variable (α)
instance instTop [Bot α] : Top αᵒᵈ :=
⟨(⊥ : α)⟩
instance instBot [Top α] : Bot αᵒᵈ :=
⟨(⊤ : α)⟩
instance instOrderTop [LE α] [OrderBot α] : OrderTop αᵒᵈ where
__ := inferInstanceAs (Top αᵒᵈ)
le_top := @bot_le α _ _
instance instOrderBot [LE α] [OrderTop α] : OrderBot αᵒᵈ where
__ := inferInstanceAs (Bot αᵒᵈ)
bot_le := @le_top α _ _
@[simp]
theorem ofDual_bot [Top α] : ofDual ⊥ = (⊤ : α) :=
rfl
@[simp]
theorem ofDual_top [Bot α] : ofDual ⊤ = (⊥ : α) :=
rfl
@[simp]
theorem toDual_bot [Bot α] : toDual (⊥ : α) = ⊤ :=
rfl
@[simp]
theorem toDual_top [Top α] : toDual (⊤ : α) = ⊥ :=
rfl
end OrderDual
section Preorder
variable [Preorder α] [OrderBot α] {a b : α}
@[simp]
theorem isMin_bot : IsMin (⊥ : α) :=
isBot_bot.isMin
@[simp]
theorem not_lt_bot : ¬a < ⊥ :=
isMin_bot.not_lt
theorem ne_bot_of_gt (h : a < b) : b ≠ ⊥ :=
(bot_le.trans_lt h).ne'
alias LT.lt.ne_bot := ne_bot_of_gt
theorem bot_lt_of_lt (h : a < b) : ⊥ < b :=
lt_of_le_of_lt bot_le h
alias LT.lt.bot_lt := bot_lt_of_lt
end Preorder
variable [PartialOrder α] [OrderBot α] [Preorder β] {f : α → β} {a b : α}
@[simp]
theorem isMin_iff_eq_bot : IsMin a ↔ a = ⊥ :=
⟨fun h => h.eq_of_ge bot_le, fun h _ _ => h.symm ▸ bot_le⟩
@[simp]
theorem isBot_iff_eq_bot : IsBot a ↔ a = ⊥ :=
⟨fun h => h.isMin.eq_of_ge bot_le, fun h _ => h.symm ▸ bot_le⟩
theorem not_isMin_iff_ne_bot : ¬IsMin a ↔ a ≠ ⊥ :=
isMin_iff_eq_bot.not
theorem not_isBot_iff_ne_bot : ¬IsBot a ↔ a ≠ ⊥ :=
isBot_iff_eq_bot.not
alias ⟨IsMin.eq_bot, _⟩ := isMin_iff_eq_bot
alias ⟨IsBot.eq_bot, _⟩ := isBot_iff_eq_bot
@[simp]
theorem le_bot_iff : a ≤ ⊥ ↔ a = ⊥ :=
bot_le.ge_iff_eq'
theorem bot_unique (h : a ≤ ⊥) : a = ⊥ :=
h.antisymm bot_le
theorem eq_bot_iff : a = ⊥ ↔ a ≤ ⊥ :=
le_bot_iff.symm
theorem eq_bot_mono (h : a ≤ b) (h₂ : b = ⊥) : a = ⊥ :=
bot_unique <| h₂ ▸ h
theorem bot_lt_iff_ne_bot : ⊥ < a ↔ a ≠ ⊥ :=
bot_le.lt_iff_ne.trans ne_comm
@[simp]
theorem not_bot_lt_iff : ¬⊥ < a ↔ a = ⊥ :=
bot_lt_iff_ne_bot.not_left
theorem eq_bot_or_bot_lt (a : α) : a = ⊥ ∨ ⊥ < a :=
bot_le.eq_or_lt'
theorem eq_bot_of_minimal (h : ∀ b, ¬b < a) : a = ⊥ :=
(eq_bot_or_bot_lt a).resolve_right (h ⊥)
theorem Ne.bot_lt (h : a ≠ ⊥) : ⊥ < a :=
bot_lt_iff_ne_bot.mpr h
theorem Ne.bot_lt' (h : ⊥ ≠ a) : ⊥ < a :=
h.symm.bot_lt
theorem ne_bot_of_le_ne_bot (hb : b ≠ ⊥) (hab : b ≤ a) : a ≠ ⊥ :=
(hb.bot_lt.trans_le hab).ne'
lemma bot_notMem_iff {s : Set α} : ⊥ ∉ s ↔ ∀ x ∈ s, ⊥ < x :=
top_notMem_iff (α := αᵒᵈ)
@[deprecated (since := "2025-05-23")] alias bot_not_mem_iff := bot_notMem_iff
variable [Nontrivial α]
theorem not_isMax_bot : ¬IsMax (⊥ : α) :=
@not_isMin_top αᵒᵈ _ _ _
end OrderBot
theorem OrderBot.ext_bot {α} {hA : PartialOrder α} (A : OrderBot α) {hB : PartialOrder α}
(B : OrderBot α) (H : ∀ x y : α, (haveI := hA; x ≤ y) ↔ x ≤ y) :
(@Bot.bot α (@OrderBot.toBot α hA.toLE A)) = (@Bot.bot α (@OrderBot.toBot α hB.toLE B)) := by
cases PartialOrder.ext H
apply bot_unique
exact @bot_le _ _ A _
/-! ### Bounded order -/
/-- A bounded order describes an order `(≤)` with a top and bottom element,
denoted `⊤` and `⊥` respectively. -/
class BoundedOrder (α : Type u) [LE α] extends OrderTop α, OrderBot α
instance OrderDual.instBoundedOrder (α : Type u) [LE α] [BoundedOrder α] : BoundedOrder αᵒᵈ where
__ := inferInstanceAs (OrderTop αᵒᵈ)
__ := inferInstanceAs (OrderBot αᵒᵈ)
section PartialOrder
variable [PartialOrder α]
instance OrderBot.instSubsingleton : Subsingleton (OrderBot α) where
allEq := by rintro @⟨⟨a⟩, ha⟩ @⟨⟨b⟩, hb⟩; congr; exact le_antisymm (ha _) (hb _)
instance OrderTop.instSubsingleton : Subsingleton (OrderTop α) where
allEq := by rintro @⟨⟨a⟩, ha⟩ @⟨⟨b⟩, hb⟩; congr; exact le_antisymm (hb _) (ha _)
instance BoundedOrder.instSubsingleton : Subsingleton (BoundedOrder α) where
allEq := by rintro ⟨⟩ ⟨⟩; congr <;> exact Subsingleton.elim _ _
end PartialOrder
/-! ### Function lattices -/
namespace Pi
variable {ι : Type*} {α' : ι → Type*}
instance [∀ i, Bot (α' i)] : Bot (∀ i, α' i) :=
⟨fun _ => ⊥⟩
@[simp]
theorem bot_apply [∀ i, Bot (α' i)] (i : ι) : (⊥ : ∀ i, α' i) i = ⊥ :=
rfl
theorem bot_def [∀ i, Bot (α' i)] : (⊥ : ∀ i, α' i) = fun _ => ⊥ :=
rfl
@[simp]
theorem bot_comp {α β γ : Type*} [Bot γ] (x : α → β) : (⊥ : β → γ) ∘ x = ⊥ := by
rfl
instance [∀ i, Top (α' i)] : Top (∀ i, α' i) :=
⟨fun _ => ⊤⟩
@[simp]
theorem top_apply [∀ i, Top (α' i)] (i : ι) : (⊤ : ∀ i, α' i) i = ⊤ :=
rfl
theorem top_def [∀ i, Top (α' i)] : (⊤ : ∀ i, α' i) = fun _ => ⊤ :=
rfl
@[simp]
theorem top_comp {α β γ : Type*} [Top γ] (x : α → β) : (⊤ : β → γ) ∘ x = ⊤ := by
rfl
instance instOrderTop [∀ i, LE (α' i)] [∀ i, OrderTop (α' i)] : OrderTop (∀ i, α' i) where
le_top _ := fun _ => le_top
instance instOrderBot [∀ i, LE (α' i)] [∀ i, OrderBot (α' i)] : OrderBot (∀ i, α' i) where
bot_le _ := fun _ => bot_le
instance instBoundedOrder [∀ i, LE (α' i)] [∀ i, BoundedOrder (α' i)] :
BoundedOrder (∀ i, α' i) where
__ := inferInstanceAs (OrderTop (∀ i, α' i))
__ := inferInstanceAs (OrderBot (∀ i, α' i))
end Pi
section Subsingleton
variable [PartialOrder α] [BoundedOrder α]
theorem eq_bot_of_bot_eq_top (hα : (⊥ : α) = ⊤) (x : α) : x = (⊥ : α) :=
eq_bot_mono le_top (Eq.symm hα)
theorem eq_top_of_bot_eq_top (hα : (⊥ : α) = ⊤) (x : α) : x = (⊤ : α) :=
eq_top_mono bot_le hα
theorem subsingleton_of_top_le_bot (h : (⊤ : α) ≤ (⊥ : α)) : Subsingleton α :=
⟨fun _ _ => le_antisymm
(le_trans le_top <| le_trans h bot_le) (le_trans le_top <| le_trans h bot_le)⟩
theorem subsingleton_of_bot_eq_top (hα : (⊥ : α) = (⊤ : α)) : Subsingleton α :=
subsingleton_of_top_le_bot (ge_of_eq hα)
theorem subsingleton_iff_bot_eq_top : (⊥ : α) = (⊤ : α) ↔ Subsingleton α :=
⟨subsingleton_of_bot_eq_top, fun _ => Subsingleton.elim ⊥ ⊤⟩
end Subsingleton
section lift
-- See note [reducible non-instances]
/-- Pullback an `OrderTop`. -/
abbrev OrderTop.lift [LE α] [Top α] [LE β] [OrderTop β] (f : α → β)
(map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_top : f ⊤ = ⊤) : OrderTop α :=
⟨fun a =>
map_le _ _ <| by
rw [map_top]
exact le_top _⟩
-- See note [reducible non-instances]
/-- Pullback an `OrderBot`. -/
abbrev OrderBot.lift [LE α] [Bot α] [LE β] [OrderBot β] (f : α → β)
(map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_bot : f ⊥ = ⊥) : OrderBot α :=
⟨fun a =>
map_le _ _ <| by
rw [map_bot]
exact bot_le _⟩
-- See note [reducible non-instances]
/-- Pullback a `BoundedOrder`. -/
abbrev BoundedOrder.lift [LE α] [Top α] [Bot α] [LE β] [BoundedOrder β] (f : α → β)
(map_le : ∀ a b, f a ≤ f b → a ≤ b) (map_top : f ⊤ = ⊤) (map_bot : f ⊥ = ⊥) :
BoundedOrder α where
__ := OrderTop.lift f map_le map_top
__ := OrderBot.lift f map_le map_bot
end lift
/-! ### Subtype, order dual, product lattices -/
namespace Subtype
variable {p : α → Prop}
-- See note [reducible non-instances]
/-- A subtype remains a `⊥`-order if the property holds at `⊥`. -/
protected abbrev orderBot [LE α] [OrderBot α] (hbot : p ⊥) : OrderBot { x : α // p x } where
bot := ⟨⊥, hbot⟩
bot_le _ := bot_le
-- See note [reducible non-instances]
/-- A subtype remains a `⊤`-order if the property holds at `⊤`. -/
protected abbrev orderTop [LE α] [OrderTop α] (htop : p ⊤) : OrderTop { x : α // p x } where
top := ⟨⊤, htop⟩
le_top _ := le_top
-- See note [reducible non-instances]
/-- A subtype remains a bounded order if the property holds at `⊥` and `⊤`. -/
protected abbrev boundedOrder [LE α] [BoundedOrder α] (hbot : p ⊥) (htop : p ⊤) :
BoundedOrder (Subtype p) where
__ := Subtype.orderTop htop
__ := Subtype.orderBot hbot
variable [PartialOrder α]
@[simp]
theorem mk_bot [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) : mk ⊥ hbot = ⊥ :=
le_bot_iff.1 <| coe_le_coe.1 bot_le
@[simp]
theorem mk_top [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) : mk ⊤ htop = ⊤ :=
top_le_iff.1 <| coe_le_coe.1 le_top
theorem coe_bot [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) : ((⊥ : Subtype p) : α) = ⊥ :=
congr_arg Subtype.val (mk_bot hbot).symm
theorem coe_top [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) : ((⊤ : Subtype p) : α) = ⊤ :=
congr_arg Subtype.val (mk_top htop).symm
@[simp]
theorem coe_eq_bot_iff [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) {x : { x // p x }} :
(x : α) = ⊥ ↔ x = ⊥ := by
rw [← coe_bot hbot, Subtype.ext_iff]
@[simp]
theorem coe_eq_top_iff [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) {x : { x // p x }} :
(x : α) = ⊤ ↔ x = ⊤ := by
rw [← coe_top htop, Subtype.ext_iff]
@[simp]
theorem mk_eq_bot_iff [OrderBot α] [OrderBot (Subtype p)] (hbot : p ⊥) {x : α} (hx : p x) :
(⟨x, hx⟩ : Subtype p) = ⊥ ↔ x = ⊥ :=
(coe_eq_bot_iff hbot).symm
@[simp]
theorem mk_eq_top_iff [OrderTop α] [OrderTop (Subtype p)] (htop : p ⊤) {x : α} (hx : p x) :
(⟨x, hx⟩ : Subtype p) = ⊤ ↔ x = ⊤ :=
(coe_eq_top_iff htop).symm
end Subtype
namespace Prod
variable (α β)
instance instTop [Top α] [Top β] : Top (α × β) :=
⟨⟨⊤, ⊤⟩⟩
instance instBot [Bot α] [Bot β] : Bot (α × β) :=
⟨⟨⊥, ⊥⟩⟩
@[simp] lemma fst_top [Top α] [Top β] : (⊤ : α × β).fst = ⊤ := rfl
@[simp] lemma snd_top [Top α] [Top β] : (⊤ : α × β).snd = ⊤ := rfl
@[simp] lemma fst_bot [Bot α] [Bot β] : (⊥ : α × β).fst = ⊥ := rfl
@[simp] lemma snd_bot [Bot α] [Bot β] : (⊥ : α × β).snd = ⊥ := rfl
instance instOrderTop [LE α] [LE β] [OrderTop α] [OrderTop β] : OrderTop (α × β) where
__ := inferInstanceAs (Top (α × β))
le_top _ := ⟨le_top, le_top⟩
instance instOrderBot [LE α] [LE β] [OrderBot α] [OrderBot β] : OrderBot (α × β) where
__ := inferInstanceAs (Bot (α × β))
bot_le _ := ⟨bot_le, bot_le⟩
instance instBoundedOrder [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] :
BoundedOrder (α × β) where
__ := inferInstanceAs (OrderTop (α × β))
__ := inferInstanceAs (OrderBot (α × β))
end Prod
namespace ULift
instance [Top α] : Top (ULift.{v} α) where top := up ⊤
@[simp] theorem up_top [Top α] : up (⊤ : α) = ⊤ := rfl
@[simp] theorem down_top [Top α] : down (⊤ : ULift α) = ⊤ := rfl
instance [Bot α] : Bot (ULift.{v} α) where bot := up ⊥
@[simp] theorem up_bot [Bot α] : up (⊥ : α) = ⊥ := rfl
@[simp] theorem down_bot [Bot α] : down (⊥ : ULift α) = ⊥ := rfl
instance [LE α] [OrderBot α] : OrderBot (ULift.{v} α) :=
OrderBot.lift ULift.down (fun _ _ => down_le.mp) down_bot
instance [LE α] [OrderTop α] : OrderTop (ULift.{v} α) :=
OrderTop.lift ULift.down (fun _ _ => down_le.mp) down_top
instance [LE α] [BoundedOrder α] : BoundedOrder (ULift.{v} α) where
end ULift
section Nontrivial
variable [PartialOrder α] [BoundedOrder α] [Nontrivial α]
@[simp]
theorem bot_ne_top : (⊥ : α) ≠ ⊤ := fun h => not_subsingleton _ <| subsingleton_of_bot_eq_top h
@[simp]
theorem top_ne_bot : (⊤ : α) ≠ ⊥ :=
bot_ne_top.symm
@[simp]
theorem bot_lt_top : (⊥ : α) < ⊤ :=
lt_top_iff_ne_top.2 bot_ne_top
end Nontrivial
section Bool
open Bool
instance Bool.instBoundedOrder : BoundedOrder Bool where
top := true
le_top := Bool.le_true
bot := false
bot_le := Bool.false_le
@[simp]
theorem top_eq_true : ⊤ = true :=
rfl
@[simp]
theorem bot_eq_false : ⊥ = false :=
rfl
end Bool
|
HomologicalComplex.lean
|
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.Additive
import Mathlib.CategoryTheory.Idempotents.Karoubi
/-!
# Idempotent completeness and homological complexes
This file contains simplifications lemmas for categories
`Karoubi (HomologicalComplex C c)` and the construction of an equivalence
of categories `Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`.
When the category `C` is idempotent complete, it is shown that
`HomologicalComplex (Karoubi C) c` is also idempotent complete.
-/
namespace CategoryTheory
open Category
variable {C : Type*} [Category C] [Preadditive C] {ι : Type*} {c : ComplexShape ι}
namespace Idempotents
namespace Karoubi
namespace HomologicalComplex
variable {P Q : Karoubi (HomologicalComplex C c)} (f : P ⟶ Q) (n : ι)
@[simp, reassoc]
theorem p_comp_d : P.p.f n ≫ f.f.f n = f.f.f n :=
HomologicalComplex.congr_hom (p_comp f) n
@[simp, reassoc]
theorem comp_p_d : f.f.f n ≫ Q.p.f n = f.f.f n :=
HomologicalComplex.congr_hom (comp_p f) n
@[reassoc]
theorem p_comm_f : P.p.f n ≫ f.f.f n = f.f.f n ≫ Q.p.f n :=
HomologicalComplex.congr_hom (p_comm f) n
variable (P)
@[simp, reassoc]
theorem p_idem : P.p.f n ≫ P.p.f n = P.p.f n :=
HomologicalComplex.congr_hom P.idem n
end HomologicalComplex
end Karoubi
open Karoubi
namespace KaroubiHomologicalComplexEquivalence
namespace Functor
/-- The functor `Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c`,
on objects. -/
@[simps]
def obj (P : Karoubi (HomologicalComplex C c)) : HomologicalComplex (Karoubi C) c where
X n :=
⟨P.X.X n, P.p.f n, by
simpa only [HomologicalComplex.comp_f] using HomologicalComplex.congr_hom P.idem n⟩
d i j := { f := P.p.f i ≫ P.X.d i j }
shape i j hij := by simp only [hom_eq_zero_iff]; cat_disch
/-- The functor `Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c`,
on morphisms. -/
@[simps]
def map {P Q : Karoubi (HomologicalComplex C c)} (f : P ⟶ Q) : obj P ⟶ obj Q where
f n :=
{ f := f.f.f n }
end Functor
/-- The functor `Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c`. -/
@[simps]
def functor : Karoubi (HomologicalComplex C c) ⥤ HomologicalComplex (Karoubi C) c where
obj := Functor.obj
map f := Functor.map f
namespace Inverse
/-- The functor `HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c)`,
on objects -/
@[simps]
def obj (K : HomologicalComplex (Karoubi C) c) : Karoubi (HomologicalComplex C c) where
X :=
{ X := fun n => (K.X n).X
d := fun i j => (K.d i j).f
shape := fun i j hij => hom_eq_zero_iff.mp (K.shape i j hij)
d_comp_d' := fun i j k _ _ => by
simpa only [comp_f] using hom_eq_zero_iff.mp (K.d_comp_d i j k) }
p := { f := fun n => (K.X n).p }
/-- The functor `HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c)`,
on morphisms -/
@[simps]
def map {K L : HomologicalComplex (Karoubi C) c} (f : K ⟶ L) : obj K ⟶ obj L where
f :=
{ f := fun n => (f.f n).f
comm' := fun i j hij => by simpa only [comp_f] using hom_ext_iff.mp (f.comm' i j hij) }
end Inverse
/-- The functor `HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c)`. -/
@[simps]
def inverse : HomologicalComplex (Karoubi C) c ⥤ Karoubi (HomologicalComplex C c) where
obj := Inverse.obj
map f := Inverse.map f
/-- The counit isomorphism of the equivalence
`Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`. -/
@[simps!]
def counitIso : inverse ⋙ functor ≅ 𝟭 (HomologicalComplex (Karoubi C) c) :=
eqToIso (Functor.ext (fun P => HomologicalComplex.ext (by cat_disch) (by simp))
(by cat_disch))
/-- The unit isomorphism of the equivalence
`Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`. -/
@[simps]
def unitIso : 𝟭 (Karoubi (HomologicalComplex C c)) ≅ functor ⋙ inverse where
hom :=
{ app := fun P =>
{ f :=
{ f := fun n => P.p.f n
comm' := fun i j _ => by
dsimp
simp only [HomologicalComplex.Hom.comm, HomologicalComplex.Hom.comm_assoc,
HomologicalComplex.p_idem] }
comm := by
ext n
dsimp
simp only [HomologicalComplex.p_idem] }
naturality := fun P Q φ => by
ext
dsimp
simp only [HomologicalComplex.comp_p_d,
HomologicalComplex.p_comp_d] }
inv :=
{ app := fun P =>
{ f :=
{ f := fun n => P.p.f n
comm' := fun i j _ => by
dsimp
simp only [HomologicalComplex.Hom.comm, assoc, HomologicalComplex.p_idem] }
comm := by
ext n
dsimp
simp only [HomologicalComplex.p_idem] }
naturality := fun P Q φ => by
ext
dsimp
simp only [HomologicalComplex.comp_p_d, HomologicalComplex.p_comp_d] }
hom_inv_id := by
ext
dsimp
simp only [HomologicalComplex.p_idem]
inv_hom_id := by
ext
dsimp
simp only [HomologicalComplex.p_idem]
end KaroubiHomologicalComplexEquivalence
variable (C) (c)
/-- The equivalence `Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c`. -/
@[simps]
def karoubiHomologicalComplexEquivalence :
Karoubi (HomologicalComplex C c) ≌ HomologicalComplex (Karoubi C) c where
functor := KaroubiHomologicalComplexEquivalence.functor
inverse := KaroubiHomologicalComplexEquivalence.inverse
unitIso := KaroubiHomologicalComplexEquivalence.unitIso
counitIso := KaroubiHomologicalComplexEquivalence.counitIso
variable (α : Type*) [AddRightCancelSemigroup α] [One α]
/-- The equivalence `Karoubi (ChainComplex C α) ≌ ChainComplex (Karoubi C) α`. -/
@[simps!]
def karoubiChainComplexEquivalence : Karoubi (ChainComplex C α) ≌ ChainComplex (Karoubi C) α :=
karoubiHomologicalComplexEquivalence C (ComplexShape.down α)
/-- The equivalence `Karoubi (CochainComplex C α) ≌ CochainComplex (Karoubi C) α`. -/
@[simps!]
def karoubiCochainComplexEquivalence :
Karoubi (CochainComplex C α) ≌ CochainComplex (Karoubi C) α :=
karoubiHomologicalComplexEquivalence C (ComplexShape.up α)
instance [IsIdempotentComplete C] : IsIdempotentComplete (HomologicalComplex C c) := by
rw [isIdempotentComplete_iff_of_equivalence
((toKaroubiEquivalence C).mapHomologicalComplex c),
← isIdempotentComplete_iff_of_equivalence (karoubiHomologicalComplexEquivalence C c)]
infer_instance
end Idempotents
end CategoryTheory
|
Finite.lean
|
/-
Copyright (c) 2025 Floris van Doorn and Hannah Scholz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Hannah Scholz
-/
import Mathlib.Topology.CWComplex.Classical.Basic
/-!
# Finiteness notions on CW complexes
In this file we define what it means for a CW complex to be finite dimensional, of finite type or
finite. We define constructors with relaxed conditions for CW complexes of finite type and
finite CW complexes.
## Main definitions
* `RelCWComplex.FiniteDimensional`: a CW complex is finite dimensional if it has only finitely many
nonempty indexing types for the cells.
* `RelCWComplex.FiniteType`: a CW complex is of finite type if it has only finitely many cells in
each dimension.
* `RelCWComplex.Finite`: a CW complex is finite if it is finite dimensional and of finite type.
## Main statements
* `RelCWComplex.mkFiniteType`: if we want to construct a CW complex of finite type, we can relax the
condition `mapsTo`.
* `RelCWComplex.mkFinite`: if we want to construct a finite CW complex, we can relax the condition
`mapsTo` and can leave out the condition `closed'`.
* `RelCWComplex.finite_iff_finite_cells`: a CW complex is finite iff the total number of its cells
is finite.
-/
open Metric Set
namespace Topology
/-- A CW complex is finite dimensional if `cell C n` is empty for all but finitely many `n`. -/
class RelCWComplex.FiniteDimensional.{u} {X : Type u} [TopologicalSpace X] (C : Set X) {D : Set X}
[RelCWComplex C D] : Prop where
/-- For some natural number `n`, the type `cell C m` is empty for all `m ≥ n`. -/
eventually_isEmpty_cell : ∀ᶠ n in Filter.atTop, IsEmpty (cell C n)
/-- A CW complex is of finite type if `cell C n` is finite for every `n`. -/
class RelCWComplex.FiniteType.{u} {X : Type u} [TopologicalSpace X] (C : Set X) {D : Set X}
[RelCWComplex C D] : Prop where
/-- `cell C n` is finite for every `n`. -/
finite_cell (n : ℕ) : Finite (cell C n)
/-- A CW complex is finite if it is finite dimensional and of finite type. -/
class RelCWComplex.Finite {X : Type*} [TopologicalSpace X] (C : Set X) {D : Set X}
[RelCWComplex C D] extends FiniteDimensional C, FiniteType C
variable {X : Type*} [TopologicalSpace X] (C : Set X) {D : Set X} [RelCWComplex C D]
lemma RelCWComplex.finite_of_finiteDimensional_finiteType [FiniteDimensional C]
[FiniteType C] : Finite C where
eventually_isEmpty_cell := FiniteDimensional.eventually_isEmpty_cell
finite_cell n := FiniteType.finite_cell n
namespace CWComplex
export RelCWComplex (FiniteDimensional FiniteType Finite FiniteDimensional.eventually_isEmpty_cell
FiniteType.finite_cell finite_of_finiteDimensional_finiteType)
end CWComplex
/-- If we want to construct a relative CW complex of finite type, we can add the condition
`finite_cell` and relax the condition `mapsTo`. -/
def RelCWComplex.mkFiniteType.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(D : outParam (Set X))
(cell : (n : ℕ) → Type u) (map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(disjointBase' : ∀ (n : ℕ) (i : cell n), Disjoint (map n i '' ball 0 1) D)
(mapsTo : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (D ∪ ⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(closed' : ∀ (A : Set X) (_ : A ⊆ C),
((∀ n j, IsClosed (A ∩ map n j '' closedBall 0 1)) ∧ IsClosed (A ∩ D)) → IsClosed A)
(isClosedBase : IsClosed D)
(union' : D ∪ ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
RelCWComplex C D where
cell := cell
map := map
source_eq := source_eq
continuousOn := continuousOn
continuousOn_symm := continuousOn_symm
pairwiseDisjoint' := pairwiseDisjoint'
disjointBase' := disjointBase'
mapsTo n i := by
use fun m ↦ finite_univ.toFinset (s := (univ : Set (cell m)))
simp only [Finite.mem_toFinset, mem_univ, iUnion_true]
exact mapsTo n i
closed' := closed'
isClosedBase := isClosedBase
union' := union'
/-- A CW complex that was constructed using `RelCWComplex.mkFiniteType` is of finite type. -/
lemma RelCWComplex.finiteType_mkFiniteType.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(D : outParam (Set X))
(cell : (n : ℕ) → Type u) (map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(disjointBase' : ∀ (n : ℕ) (i : cell n), Disjoint (map n i '' ball 0 1) D)
(mapsTo : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (D ∪ ⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(closed' : ∀ (A : Set X) (_ : A ⊆ C),
((∀ n j, IsClosed (A ∩ map n j '' closedBall 0 1)) ∧ IsClosed (A ∩ D)) → IsClosed A)
(isClosedBase : IsClosed D)
(union' : D ∪ ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
letI := mkFiniteType C D cell map finite_cell source_eq continuousOn continuousOn_symm
pairwiseDisjoint' disjointBase' mapsTo closed' isClosedBase union'
FiniteType C :=
letI := mkFiniteType C D cell map finite_cell source_eq continuousOn continuousOn_symm
pairwiseDisjoint' disjointBase' mapsTo closed' isClosedBase union'
{ finite_cell := finite_cell }
/-- If we want to construct a CW complex of finite type, we can add the condition `finite_cell` and
relax the condition `mapsTo`. -/
def CWComplex.mkFiniteType.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(cell : (n : ℕ) → Type u) (map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(mapsTo : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(closed' : ∀ (A : Set X) (_ : A ⊆ C),
(∀ n j, IsClosed (A ∩ map n j '' closedBall 0 1)) → IsClosed A)
(union' : ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
CWComplex C where
cell := cell
map := map
source_eq := source_eq
continuousOn := continuousOn
continuousOn_symm := continuousOn_symm
pairwiseDisjoint' := pairwiseDisjoint'
mapsTo' n i := by
use fun m ↦ finite_univ.toFinset (s := (univ : Set (cell m)))
simp only [Finite.mem_toFinset, mem_univ, iUnion_true]
exact mapsTo n i
closed' := closed'
union' := union'
/-- A CW complex that was constructed using `CWComplex.mkFiniteType` is of finite type. -/
lemma CWComplex.finiteType_mkFiniteType.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(cell : (n : ℕ) → Type u) (map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(mapsTo : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(closed' : ∀ (A : Set X) (_ : A ⊆ C),
(∀ n j, IsClosed (A ∩ map n j '' closedBall 0 1)) → IsClosed A)
(union' : ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
letI := mkFiniteType C cell map finite_cell source_eq continuousOn continuousOn_symm
pairwiseDisjoint' mapsTo closed' union'
FiniteType C :=
letI := mkFiniteType C cell map finite_cell source_eq continuousOn continuousOn_symm
pairwiseDisjoint' mapsTo closed' union'
{ finite_cell := finite_cell }
/-- If we want to construct a finite relative CW complex we can add the conditions
`eventually_isEmpty_cell` and `finite_cell`, relax the condition `mapsTo` and remove the condition
`closed'`. -/
def RelCWComplex.mkFinite.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(D : outParam (Set X)) (cell : (n : ℕ) → Type u)
(map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(eventually_isEmpty_cell : ∀ᶠ n in Filter.atTop, IsEmpty (cell n))
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(disjointBase' : ∀ (n : ℕ) (i : cell n), Disjoint (map n i '' ball 0 1) D)
(mapsTo : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (D ∪ ⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(isClosedBase : IsClosed D)
(union' : D ∪ ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
RelCWComplex C D where
cell := cell
map := map
source_eq := source_eq
continuousOn := continuousOn
continuousOn_symm := continuousOn_symm
pairwiseDisjoint' := pairwiseDisjoint'
disjointBase' := disjointBase'
mapsTo n i := by
use fun m ↦ finite_univ.toFinset (s := (univ : Set (cell m)))
simp only [Finite.mem_toFinset, mem_univ, iUnion_true]
exact mapsTo n i
closed' A asubc := by
intro h
-- `A = A ∩ C = A ∩ (D ∪ ⋃ n, ⋃ j, closedCell n j)` is closed by assumption since `C` has only
-- finitely many cells.
rw [← inter_eq_left.2 asubc]
simp_rw [Filter.eventually_atTop, ge_iff_le] at eventually_isEmpty_cell
obtain ⟨N, hN⟩ := eventually_isEmpty_cell
suffices IsClosed (A ∩ (D ∪ ⋃ (n : {n : ℕ // n < N}), ⋃ j, ↑(map n j) '' closedBall 0 1)) by
convert this using 2
rw [← union', iUnion_subtype]
congrm D ∪ ⋃ n, ?_
refine subset_antisymm ?_ (iUnion_subset (fun i ↦ by rfl))
apply iUnion_subset
intro i
have : n < N := Decidable.byContradiction fun h ↦ (hN n (Nat.ge_of_not_lt h)).false i
exact subset_iUnion₂ (s := fun _ i ↦ (map n i) '' closedBall 0 1) this i
simp_rw [inter_union_distrib_left, inter_iUnion]
exact h.2.union (isClosed_iUnion_of_finite (fun n ↦ isClosed_iUnion_of_finite (h.1 n.1)))
isClosedBase := isClosedBase
union' := union'
/-- A CW complex that was constructed using `RelCWComplex.mkFinite` is finite. -/
lemma RelCWComplex.finite_mkFinite.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(D : outParam (Set X)) (cell : (n : ℕ) → Type u)
(map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(eventually_isEmpty_cell : ∀ᶠ n in Filter.atTop, IsEmpty (cell n))
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(disjointBase' : ∀ (n : ℕ) (i : cell n), Disjoint (map n i '' ball 0 1) D)
(mapsTo : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (D ∪ ⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(isClosedBase : IsClosed D)
(union' : D ∪ ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
letI := mkFinite C D cell map eventually_isEmpty_cell finite_cell source_eq continuousOn
continuousOn_symm pairwiseDisjoint' disjointBase' mapsTo isClosedBase union'
Finite C :=
letI := mkFinite C D cell map eventually_isEmpty_cell finite_cell source_eq continuousOn
continuousOn_symm pairwiseDisjoint' disjointBase' mapsTo isClosedBase union'
{ eventually_isEmpty_cell := eventually_isEmpty_cell
finite_cell := finite_cell }
/-- If we want to construct a finite CW complex we can add the conditions `eventually_isEmpty_cell`
and `finite_cell`, relax the condition `mapsTo` and remove the condition `closed'`. -/
def CWComplex.mkFinite.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(cell : (n : ℕ) → Type u) (map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(eventually_isEmpty_cell : ∀ᶠ n in Filter.atTop, IsEmpty (cell n))
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(mapsTo' : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(union' : ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
CWComplex C := (RelCWComplex.mkFinite C ∅
(cell := cell)
(map := map)
(eventually_isEmpty_cell := eventually_isEmpty_cell)
(finite_cell := finite_cell)
(source_eq := source_eq)
(continuousOn := continuousOn)
(continuousOn_symm := continuousOn_symm)
(pairwiseDisjoint' := pairwiseDisjoint')
(disjointBase' := by simp only [disjoint_empty, implies_true])
(mapsTo := by simpa only [empty_union])
(isClosedBase := isClosed_empty)
(union' := by simpa only [empty_union])).toCWComplex
/-- A CW complex that was constructed using `CWComplex.mkFinite` is finite. -/
lemma CWComplex.finite_mkFinite.{u} {X : Type u} [TopologicalSpace X] (C : Set X)
(cell : (n : ℕ) → Type u) (map : (n : ℕ) → (i : cell n) → PartialEquiv (Fin n → ℝ) X)
(eventually_isEmpty_cell : ∀ᶠ n in Filter.atTop, IsEmpty (cell n))
(finite_cell : ∀ (n : ℕ), _root_.Finite (cell n))
(source_eq : ∀ (n : ℕ) (i : cell n), (map n i).source = ball 0 1)
(continuousOn : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i) (closedBall 0 1))
(continuousOn_symm : ∀ (n : ℕ) (i : cell n), ContinuousOn (map n i).symm (map n i).target)
(pairwiseDisjoint' :
(univ : Set (Σ n, cell n)).PairwiseDisjoint (fun ni ↦ map ni.1 ni.2 '' ball 0 1))
(mapsTo : ∀ (n : ℕ) (i : cell n),
MapsTo (map n i) (sphere 0 1) (⋃ (m < n) (j : cell m), map m j '' closedBall 0 1))
(union' : ⋃ (n : ℕ) (j : cell n), map n j '' closedBall 0 1 = C) :
letI := mkFinite C cell map eventually_isEmpty_cell finite_cell source_eq continuousOn
continuousOn_symm pairwiseDisjoint' mapsTo union'
Finite C :=
letI := mkFinite C cell map eventually_isEmpty_cell finite_cell source_eq continuousOn
continuousOn_symm pairwiseDisjoint' mapsTo union'
{ eventually_isEmpty_cell := eventually_isEmpty_cell
finite_cell := finite_cell }
variable {X : Type*} [TopologicalSpace X] {C D : Set X} [RelCWComplex C D]
/-- If the collection of all cells (of any dimension) of a relative CW complex `C` is finite, then
`C` is finite as a CW complex. -/
lemma RelCWComplex.finite_of_finite_cells (finite : _root_.Finite (Σ n, cell C n)) : Finite C where
eventually_isEmpty_cell := by
simp only [Filter.eventually_atTop, ge_iff_le]
by_cases h : IsEmpty (Σ n, cell C n)
· exact ⟨0, by simp_all⟩
-- We take the greatest `n` such that there is a `j : cell C n` and show that this fulfills
-- the necessary conditions.
rw [not_isEmpty_iff] at h
have _ := Fintype.ofFinite (Σ n, cell C n)
classical
let A := (Finset.univ : Finset (Σ n, cell C n)).image Sigma.fst
use A.max' (Finset.image_nonempty.2 Finset.univ_nonempty) + 1
intro m _
by_contra h'
have hmA : m ∈ A := by
simp only [Finset.mem_image, Finset.mem_univ, true_and, A]
simp only [not_isEmpty_iff, ← exists_true_iff_nonempty] at h'
obtain ⟨j, _⟩ := h'
use ⟨m, j⟩
linarith [A.le_max' m hmA]
finite_cell _ := Finite.of_injective (Sigma.mk _) sigma_mk_injective
/-- If `C` is finite as a CW complex then the collection of all cells (of any dimension) is
finite. -/
lemma RelCWComplex.finite_cells_of_finite [finite : Finite C] : _root_.Finite (Σ n, cell C n) := by
-- We show that there is a bijection between `Σ n, cell C n` and
-- `Σ (m : {m : ℕ // m < n}), cell C m`.
have h := finite.eventually_isEmpty_cell
have _ := finite.finite_cell
simp only [Filter.eventually_atTop, ge_iff_le] at h
rcases h with ⟨n, hn⟩
have (m) (j : cell C m) : m < n := by
by_contra h
exact (hn m (not_lt.1 h)).false j
let f : (Σ (m : {m : ℕ // m < n}), cell C m) ≃ Σ m, cell C m := {
toFun := fun ⟨m, j⟩ ↦ ⟨m, j⟩
invFun := fun ⟨m, j⟩ ↦ ⟨⟨m, this m j⟩, j⟩
left_inv := by simp [Function.LeftInverse]
right_inv := by simp [Function.RightInverse, Function.LeftInverse]}
rw [← Equiv.finite_iff f]
exact Finite.instSigma
/-- A CW complex is finite iff the total number of its cells is finite. -/
lemma RelCWComplex.finite_iff_finite_cells : Finite C ↔ _root_.Finite (Σ n, cell C n) :=
⟨fun h ↦ finite_cells_of_finite (finite := h), finite_of_finite_cells⟩
namespace CWComplex
export RelCWComplex (finite_of_finite_cells finite_cells_of_finite finite_iff_finite_cells)
end CWComplex
end Topology
|
separable.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import choice fintype tuple finfun bigop finset prime.
From mathcomp Require Import binomial ssralg poly polydiv fingroup perm.
From mathcomp Require Import morphism quotient gproduct finalg zmodp cyclic.
From mathcomp Require Import matrix mxalgebra mxpoly polyXY vector falgebra.
From mathcomp Require Import fieldext.
(******************************************************************************)
(* This file provides a theory of separable and inseparable field extensions. *)
(* *)
(* separable_poly p <=> p has no multiple roots in any field extension. *)
(* separable_element K x <=> the minimal polynomial of x over K is separable. *)
(* separable K E <=> every member of E is separable over K. *)
(* separable_generator K E == some x \in E that generates the largest *)
(* subfield K[x] that is separable over K. *)
(* purely_inseparable_element K x <=> there is a [pchar L].-nat n such that *)
(* x ^+ n \in K. *)
(* purely_inseparable K E <=> every member of E is purely inseparable over K. *)
(* *)
(* Derivations are introduced to prove the adjoin_separableP Lemma: *)
(* Derivation K D <=> the linear operator D satisfies the Leibniz *)
(* product rule inside K. *)
(* extendDerivation x D K == given a derivation D on K and a separable *)
(* element x over K, this function returns the *)
(* unique extension of D to K(x). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import GRing.Theory.
HB.lock
Definition separable_poly {R : idomainType} (p : {poly R}) := coprimep p p^`().
Canonical separable_poly_unlockable := Unlockable separable_poly.unlock.
Section SeparablePoly.
Variable R : idomainType.
Implicit Types p q d u v : {poly R}.
Local Notation separable := (@separable_poly R).
Local Notation lcn_neq0 := (Pdiv.Idomain.lc_expn_scalp_neq0 _).
Lemma separable_poly_neq0 p : separable p -> p != 0.
Proof.
by apply: contraTneq => ->; rewrite unlock deriv0 coprime0p eqp01.
Qed.
Lemma poly_square_freeP p :
(forall u v, u * v %| p -> coprimep u v)
<-> (forall u, size u != 1 -> ~~ (u ^+ 2 %| p)).
Proof.
split=> [sq'p u | sq'p u v dvd_uv_p].
by apply: contra => /sq'p; rewrite coprimepp.
rewrite coprimep_def (contraLR (sq'p _)) // (dvdp_trans _ dvd_uv_p) //.
by rewrite dvdp_mul ?dvdp_gcdl ?dvdp_gcdr.
Qed.
Lemma separable_polyP {p} :
reflect [/\ forall u v, u * v %| p -> coprimep u v
& forall u, u %| p -> 1 < size u -> u^`() != 0]
(separable p).
Proof.
apply: (iffP idP) => [sep_p | [sq'p nz_der1p]].
split=> [u v | u u_dv_p]; last first.
apply: contraTneq => u'0; rewrite unlock in sep_p; rewrite -leqNgt -(eqnP sep_p).
rewrite dvdp_leq -?size_poly_eq0 ?(eqnP sep_p) // dvdp_gcd u_dv_p.
have /dvdpZr <-: lead_coef u ^+ scalp p u != 0 by rewrite lcn_neq0.
by rewrite -derivZ -Pdiv.Idomain.divpK //= derivM u'0 mulr0 addr0 dvdp_mull.
rewrite Pdiv.Idomain.dvdp_eq mulrCA mulrA; set c := _ ^+ _ => /eqP Dcp.
have nz_c: c != 0 by rewrite lcn_neq0.
move: sep_p; rewrite coprimep_sym unlock -(coprimepZl _ _ nz_c).
rewrite -(coprimepZr _ _ nz_c) -derivZ Dcp derivM coprimepMl.
by rewrite coprimep_addl_mul !coprimepMr -andbA => /and4P[].
rewrite unlock coprimep_def eqn_leq size_poly_gt0; set g := gcdp _ _.
have nz_g: g != 0.
rewrite -dvd0p dvdp_gcd -(mulr0 0); apply/nandP; left.
by have /poly_square_freeP-> := sq'p; rewrite ?size_poly0.
have [g_p]: g %| p /\ g %| p^`() by rewrite dvdp_gcdr ?dvdp_gcdl.
pose c := lead_coef g ^+ scalp p g; have nz_c: c != 0 by rewrite lcn_neq0.
have Dcp: c *: p = p %/ g * g by rewrite Pdiv.Idomain.divpK.
rewrite nz_g andbT leqNgt -(dvdpZr _ _ nz_c) -derivZ Dcp derivM.
rewrite dvdp_addr; last by rewrite dvdp_mull.
rewrite Gauss_dvdpr; last by rewrite sq'p // mulrC -Dcp dvdpZl.
by apply: contraL => /nz_der1p nz_g'; rewrite gtNdvdp ?nz_g' ?lt_size_deriv.
Qed.
Lemma separable_coprime p u v : separable p -> u * v %| p -> coprimep u v.
Proof. by move=> /separable_polyP[sq'p _] /sq'p. Qed.
Lemma separable_nosquare p u k :
separable p -> 1 < k -> size u != 1 -> (u ^+ k %| p) = false.
Proof.
move=> /separable_polyP[/poly_square_freeP sq'p _] /subnKC <- /sq'p.
by apply: contraNF; apply: dvdp_trans; rewrite exprD dvdp_mulr.
Qed.
Lemma separable_deriv_eq0 p u :
separable p -> u %| p -> 1 < size u -> (u^`() == 0) = false.
Proof. by move=> /separable_polyP[_ nz_der1p] u_p /nz_der1p/negPf->. Qed.
Lemma dvdp_separable p q : q %| p -> separable p -> separable q.
Proof.
move=> /(dvdp_trans _)q_dv_p /separable_polyP[sq'p nz_der1p].
by apply/separable_polyP; split=> [u v /q_dv_p/sq'p | u /q_dv_p/nz_der1p].
Qed.
Lemma separable_mul p q :
separable (p * q) = [&& separable p, separable q & coprimep p q].
Proof.
apply/idP/and3P => [sep_pq | [sep_p sep_q co_pq]].
rewrite !(dvdp_separable _ sep_pq) ?dvdp_mulIr ?dvdp_mulIl //.
by rewrite (separable_coprime sep_pq).
rewrite unlock in sep_p sep_q *.
rewrite derivM coprimepMl {1}addrC mulrC !coprimep_addl_mul.
by rewrite !coprimepMr (coprimep_sym q p) co_pq !andbT; apply/andP.
Qed.
Lemma eqp_separable p q : p %= q -> separable p = separable q.
Proof. by case/andP=> p_q q_p; apply/idP/idP=> /dvdp_separable->. Qed.
Lemma separable_root p x :
separable (p * ('X - x%:P)) = separable p && ~~ root p x.
Proof.
rewrite separable_mul; apply: andb_id2l => seq_p.
by rewrite unlock derivXsubC coprimep1 coprimep_XsubC.
Qed.
Lemma separable_prod_XsubC (r : seq R) :
separable (\prod_(x <- r) ('X - x%:P)) = uniq r.
Proof.
elim: r => [|x r IH]; first by rewrite big_nil unlock /separable_poly coprime1p.
by rewrite big_cons mulrC separable_root IH root_prod_XsubC andbC.
Qed.
Lemma make_separable p : p != 0 -> separable (p %/ gcdp p p^`()).
Proof.
set g := gcdp p p^`() => nz_p; apply/separable_polyP.
have max_dvd_u (u : {poly R}): 1 < size u -> exists k, ~~ (u ^+ k %| p).
move=> u_gt1; exists (size p); rewrite gtNdvdp // polySpred //.
by rewrite -(ltn_subRL 1) subn1 size_exp leq_pmull // -(subnKC u_gt1).
split=> [|u u_pg u_gt1]; last first.
apply/eqP=> u'0 /=; have [k /negP[]] := max_dvd_u u u_gt1.
elim: k => [|k IHk]; first by rewrite dvd1p.
suffices: u ^+ k.+1 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite exprS dvdp_mul // dvdp_gcd IHk //=.
suffices: u ^+ k %| (p %/ u ^+ k * u ^+ k)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE u'0 mul0r mul0rn mulr0 addr0 dvdp_mull.
have pg_dv_p: p %/ g %| p by rewrite divp_dvd ?dvdp_gcdl.
apply/poly_square_freeP=> u; rewrite neq_ltn ltnS leqn0 size_poly_eq0.
case/predU1P=> [-> | /max_dvd_u[k]].
by apply: contra nz_p; rewrite expr0n -dvd0p => /dvdp_trans->.
apply: contra => u2_dv_pg; case: k; [by rewrite dvd1p | elim=> [|n IHn]].
exact: dvdp_trans (dvdp_mulr _ _) (dvdp_trans u2_dv_pg pg_dv_p).
suff: u ^+ n.+2 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite -add2n exprD dvdp_mul // dvdp_gcd.
rewrite (dvdp_trans _ IHn) ?exprS ?dvdp_mull //=.
suff: u ^+ n %| ((p %/ u ^+ n.+1) * u ^+ n.+1)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE dvdp_add // -1?mulr_natl ?exprS !dvdp_mull.
Qed.
End SeparablePoly.
Arguments separable_polyP {R p}.
Lemma separable_map (F : fieldType) (R : idomainType)
(f : {rmorphism F -> R}) (p : {poly F}) :
separable_poly (map_poly f p) = separable_poly p.
Proof.
by rewrite unlock deriv_map /coprimep -gcdp_map size_map_poly.
Qed.
Section InfinitePrimitiveElementTheorem.
Local Notation "p ^ f" := (map_poly f p) : ring_scope.
Variables (F L : fieldType) (iota : {rmorphism F -> L}).
Variables (x y : L) (p : {poly F}).
Hypotheses (nz_p : p != 0) (px_0 : root (p ^ iota) x).
Let inFz z w := exists q, (q ^ iota).[z] = w.
Lemma large_field_PET q :
root (q ^ iota) y -> separable_poly q ->
exists2 r, r != 0
& forall t (z := iota t * y - x), ~~ root r (iota t) -> inFz z x /\ inFz z y.
Proof.
move=> qy_0 sep_q; have nz_q := separable_poly_neq0 sep_q.
have /factor_theorem[q0 Dq] := qy_0.
set p1 := p ^ iota \Po ('X + x%:P); set q1 := q0 \Po ('X + y%:P).
have nz_p1: p1 != 0.
apply: contraNneq nz_p => /(canRL (fun r => comp_polyXaddC_K r _))/eqP.
by rewrite comp_poly0 map_poly_eq0.
have{sep_q} nz_q10: q1.[0] != 0.
move: sep_q; rewrite -(separable_map iota) Dq separable_root => /andP[_].
by rewrite horner_comp !hornerE.
have nz_q1: q1 != 0 by apply: contraNneq nz_q10 => ->; rewrite horner0.
pose p2 := p1 ^ polyC \Po ('X * 'Y); pose q2 := q1 ^ polyC.
have /Bezout_coprimepP[[u v]]: coprimep p2 q2.
rewrite coprimep_def eqn_leq leqNgt andbC size_poly_gt0 gcdp_eq0 poly_XmY_eq0.
by rewrite map_polyC_eq0 (negPf nz_p1) -resultant_eq0 div_annihilant_neq0.
rewrite -size_poly_eq1 => /size_poly1P[r nzr Dr]; exists r => {nzr}// t z nz_rt.
have [r1 nz_r1 r1z_0]: algebraicOver iota z.
apply/algebraic_sub; last by exists p.
by apply: algebraic_mul; [apply: algebraic_id | exists q].
pose Fz := subFExtend iota z r1; pose kappa : Fz -> L := subfx_inj.
pose kappa' := inj_subfx iota z r1.
have /eq_map_poly Diota: kappa \o kappa' =1 iota.
by move=> w; rewrite /kappa /= subfx_inj_eval // map_polyC hornerC.
suffices [y3]: exists y3, y = kappa y3.
have [q3 ->] := subfxE y3; rewrite /kappa subfx_inj_eval // => Dy.
split; [exists (t *: q3 - 'X) | by exists q3].
by rewrite rmorphB /= linearZ map_polyX !hornerE -Dy opprB addrC addrNK.
pose p0 := p ^ iota \Po (iota t *: 'X - z%:P).
have co_p0_q0: coprimep p0 q0.
pose at_t := horner_eval (iota t); have at_t0: at_t 0 = 0 by apply: rmorph0.
have /map_polyK polyCK: cancel polyC at_t by move=> w; apply: hornerC.
have ->: p0 = p2 ^ at_t \Po ('X - y%:P).
rewrite map_comp_poly polyCK // rmorphM /= map_polyC map_polyX /=.
rewrite horner_evalE hornerX.
rewrite -!comp_polyA comp_polyM comp_polyD !comp_polyC !comp_polyX.
by rewrite mulrC mulrBr mul_polyC addrAC -addrA -opprB -rmorphM -rmorphB.
have ->: q0 = q2 ^ at_t \Po ('X - y%:P) by rewrite polyCK ?comp_polyXaddC_K.
apply/coprimep_comp_poly/Bezout_coprimepP; exists (u ^ at_t, v ^ at_t).
by rewrite /= -!rmorphM -rmorphD Dr /= map_polyC polyC_eqp1.
have{co_p0_q0}: gcdp p0 (q ^ iota) %= 'X - y%:P.
rewrite /eqp Dq (eqp_dvdl _ (Gauss_gcdpr _ _)) // dvdp_gcdr dvdp_gcd.
rewrite dvdp_mull // -root_factor_theorem rootE horner_comp !hornerE.
by rewrite opprB addrC subrK.
have{p0} [p3 ->]: exists p3, p0 = p3 ^ kappa.
exists (p ^ kappa' \Po (kappa' t *: 'X - (subfx_eval iota z r1 'X)%:P)).
rewrite map_comp_poly rmorphB /= linearZ /= map_polyC map_polyX /=.
rewrite !subfx_inj_eval // map_polyC hornerC map_polyX hornerX.
by rewrite -map_poly_comp Diota.
rewrite -Diota map_poly_comp -gcdp_map /= -/kappa.
move: (gcdp _ _) => r3 /eqpf_eq[c nz_c Dr3].
exists (- (r3`_0 / r3`_1)); rewrite [kappa _]rmorphN fmorph_div -!coef_map Dr3.
by rewrite !coefZ polyseqXsubC mulr1 mulrC mulKf ?opprK.
Qed.
Lemma pchar0_PET (q : {poly F}) :
q != 0 -> root (q ^ iota) y -> [pchar F] =i pred0 ->
exists n, let z := y *+ n - x in inFz z x /\ inFz z y.
Proof.
move=> nz_q qy_0 /pcharf0P pcharF0.
without loss{nz_q} sep_q: q qy_0 / separable_poly q.
move=> IHq; apply: IHq (make_separable nz_q).
have /dvdpP[q1 Dq] := dvdp_gcdl q q^`().
rewrite {1}Dq mulpK ?gcdp_eq0; last by apply/nandP; left.
have [n [r nz_ry Dr]] := multiplicity_XsubC (q ^ iota) y.
rewrite map_poly_eq0 nz_q /= in nz_ry.
case: n => [|n] in Dr; first by rewrite Dr mulr1 (negPf nz_ry) in qy_0.
have: ('X - y%:P) ^+ n.+1 %| q ^ iota by rewrite Dr dvdp_mulIr.
rewrite Dq rmorphM /= gcdp_map -(eqp_dvdr _ (gcdp_mul2l _ _ _)) -deriv_map Dr.
rewrite dvdp_gcd derivM deriv_exp derivXsubC mul1r !mulrA dvdp_mulIr /=.
rewrite mulrDr mulrA dvdp_addr ?dvdp_mulIr // exprS -scaler_nat -!scalerAr.
rewrite dvdpZr -?(rmorph_nat iota) ?fmorph_eq0 ?pcharF0 //.
rewrite mulrA dvdp_mul2r ?expf_neq0 ?polyXsubC_eq0 //.
by rewrite Gauss_dvdpl ?dvdp_XsubCl // coprimep_sym coprimep_XsubC.
have [r nz_r PETxy] := large_field_PET qy_0 sep_q.
pose ts := mkseq (fun n => iota n%:R) (size r).
have /(max_ring_poly_roots nz_r)/=/implyP: uniq_roots ts.
rewrite uniq_rootsE mkseq_uniq // => m n eq_mn; apply/eqP; rewrite eqn_leq.
wlog suffices: m n eq_mn / m <= n by move=> IHmn; rewrite !IHmn.
move/fmorph_inj/eqP: eq_mn; rewrite -subr_eq0 leqNgt; apply: contraL => lt_mn.
by rewrite -natrB ?(ltnW lt_mn) // pcharF0 -lt0n subn_gt0.
rewrite size_mkseq ltnn implybF all_map => /allPn[n _ /= /PETxy].
by rewrite rmorph_nat mulr_natl; exists n.
Qed.
End InfinitePrimitiveElementTheorem.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar0_PET instead.")]
Notation char0_PET := (pchar0_PET) (only parsing).
Section Separable.
Variables (F : fieldType) (L : fieldExtType F).
Implicit Types (U V W : {vspace L}) (E K M : {subfield L}) (D : 'End(L)).
Section Derivation.
Variables (K : {vspace L}) (D : 'End(L)).
(* A deriviation only needs to be additive and satisfy Lebniz's law, but all *)
(* the deriviations used here are going to be linear, so we only define *)
(* the Derivation predicate for linear endomorphisms. *)
Definition Derivation : bool :=
all2rel (fun u v => D (u * v) == D u * v + u * D v) (vbasis K).
Hypothesis derD : Derivation.
Lemma Derivation_mul : {in K &, forall u v, D (u * v) = D u * v + u * D v}.
Proof.
move=> u v /coord_vbasis-> /coord_vbasis->.
rewrite !(mulr_sumr, linear_sum) -big_split; apply: eq_bigr => /= j _.
rewrite !mulr_suml linear_sum -big_split; apply: eq_bigr => /= i _.
rewrite !(=^~ scalerAl, linearZZ) -!scalerAr linearZZ -!scalerDr !scalerA /=.
by congr (_ *: _); apply/eqP/(allrelP derD); exact: memt_nth.
Qed.
Lemma Derivation_mul_poly (Dp := map_poly D) :
{in polyOver K &, forall p q, Dp (p * q) = Dp p * q + p * Dp q}.
Proof.
move=> p q Kp Kq; apply/polyP=> i; rewrite {}/Dp coefD coef_map /= !coefM.
rewrite linear_sum -big_split; apply: eq_bigr => /= j _.
by rewrite !{1}coef_map Derivation_mul ?(polyOverP _).
Qed.
End Derivation.
Lemma DerivationS E K D : (K <= E)%VS -> Derivation E D -> Derivation K D.
Proof.
move/subvP=> sKE derD; apply/allrelP=> x y Kx Ky; apply/eqP.
by rewrite (Derivation_mul derD) ?sKE // vbasis_mem.
Qed.
Section DerivationAlgebra.
Variables (E : {subfield L}) (D : 'End(L)).
Hypothesis derD : Derivation E D.
Lemma Derivation1 : D 1 = 0.
Proof.
apply: (addIr (D (1 * 1))); rewrite add0r {1}mul1r.
by rewrite (Derivation_mul derD) ?mem1v // mulr1 mul1r.
Qed.
Lemma Derivation_scalar x : x \in 1%VS -> D x = 0.
Proof. by case/vlineP=> y ->; rewrite linearZ /= Derivation1 scaler0. Qed.
Lemma Derivation_exp x m : x \in E -> D (x ^+ m) = x ^+ m.-1 *+ m * D x.
Proof.
move=> Ex; case: m; first by rewrite expr0 mulr0n mul0r Derivation1.
elim=> [|m IHm]; first by rewrite mul1r.
rewrite exprS (Derivation_mul derD) //; last by apply: rpredX.
by rewrite mulrC IHm mulrA mulrnAr -exprS -mulrDl.
Qed.
Lemma Derivation_horner p x :
p \is a polyOver E -> x \in E ->
D p.[x] = (map_poly D p).[x] + p^`().[x] * D x.
Proof.
move=> Ep Ex; elim/poly_ind: p Ep => [|p c IHp] /polyOverP EpXc.
by rewrite !(raddf0, horner0) mul0r add0r.
have Ep: p \is a polyOver E.
by apply/polyOverP=> i; have:= EpXc i.+1; rewrite coefD coefMX coefC addr0.
have->: map_poly D (p * 'X + c%:P) = map_poly D p * 'X + (D c)%:P.
apply/polyP=> i; rewrite !(coefD, coefMX, coef_map) /= linearD /= !coefC.
by rewrite !(fun_if D) linear0.
rewrite derivMXaddC !hornerE mulrDl mulrAC addrAC linearD /=; congr (_ + _).
by rewrite addrCA -mulrDl -IHp // addrC (Derivation_mul derD) ?rpred_horner.
Qed.
End DerivationAlgebra.
Definition separable_element U x := separable_poly (minPoly U x).
Section SeparableElement.
Variables (K : {subfield L}) (x : L).
(* begin hide *)
Let sKxK : (K <= <<K; x>>)%VS := subv_adjoin K x.
Let Kx_x : x \in <<K; x>>%VS := memv_adjoin K x.
(* end hide *)
Lemma separable_elementP :
reflect (exists f, [/\ f \is a polyOver K, root f x & separable_poly f])
(separable_element K x).
Proof.
apply: (iffP idP) => [sep_x | [f [Kf /(minPoly_dvdp Kf)/dvdpP[g ->]]]].
by exists (minPoly K x); rewrite minPolyOver root_minPoly.
by rewrite separable_mul => /and3P[].
Qed.
Lemma base_separable : x \in K -> separable_element K x.
Proof.
move=> Kx; apply/separable_elementP; exists ('X - x%:P).
by rewrite polyOverXsubC root_XsubC unlock !derivCE coprimep1.
Qed.
Lemma separable_nz_der : separable_element K x = ((minPoly K x)^`() != 0).
Proof.
rewrite /separable_element unlock.
apply/idP/idP=> [|nzPx'].
by apply: contraTneq => ->; rewrite coprimep0 -size_poly_eq1 size_minPoly.
have gcdK : gcdp (minPoly K x) (minPoly K x)^`() \in polyOver K.
by rewrite gcdp_polyOver ?polyOver_deriv // minPolyOver.
rewrite -gcdp_eqp1 -size_poly_eq1 -dvdp1.
have /orP[/andP[_]|/andP[]//] := minPoly_irr gcdK (dvdp_gcdl _ _).
rewrite dvdp_gcd dvdpp /= => /(dvdp_leq nzPx')/leq_trans/(_ (size_poly _ _)).
by rewrite size_minPoly ltnn.
Qed.
Lemma separablePn_pchar :
reflect (exists2 p, p \in [pchar L] &
exists2 g, g \is a polyOver K & minPoly K x = g \Po 'X^p)
(~~ separable_element K x).
Proof.
rewrite separable_nz_der negbK; set f := minPoly K x.
apply: (iffP eqP) => [f'0 | [p Hp [g _ ->]]]; last first.
by rewrite deriv_comp derivXn -scaler_nat (pcharf0 Hp) scale0r mulr0.
pose n := adjoin_degree K x; have sz_f: size f = n.+1 := size_minPoly K x.
have fn1: f`_n = 1 by rewrite -(monicP (monic_minPoly K x)) lead_coefE sz_f.
have dimKx: (adjoin_degree K x)%:R == 0 :> L.
by rewrite -(coef0 _ n.-1) -f'0 coef_deriv fn1.
have /natf0_pchar[// | p pcharLp] := dimKx.
have /dvdnP[r Dn]: (p %| n)%N by rewrite (dvdn_pcharf pcharLp).
exists p => //; exists (\poly_(i < r.+1) f`_(i * p)).
by apply: polyOver_poly => i _; rewrite (polyOverP _) ?minPolyOver.
rewrite comp_polyE size_poly_eq -?Dn ?fn1 ?oner_eq0 //.
have pr_p := pcharf_prime pcharLp; have p_gt0 := prime_gt0 pr_p.
apply/polyP=> i; rewrite coef_sum.
have [[{}i ->] | p'i] := altP (@dvdnP p i); last first.
rewrite big1 => [|j _]; last first.
rewrite coefZ -exprM coefXn [_ == _](contraNF _ p'i) ?mulr0 // => /eqP->.
by rewrite dvdn_mulr.
rewrite (dvdn_pcharf pcharLp) in p'i; apply: mulfI p'i _ _ _.
by rewrite mulr0 mulr_natl; case: i => // i; rewrite -coef_deriv f'0 coef0.
have [ltri | leir] := leqP r.+1 i.
rewrite nth_default ?sz_f ?Dn ?ltn_pmul2r ?big1 // => j _.
rewrite coefZ -exprM coefXn mulnC gtn_eqF ?mulr0 //.
by rewrite ltn_pmul2l ?(leq_trans _ ltri).
rewrite (bigD1 (Sub i _)) //= big1 ?addr0 => [|j i'j]; last first.
by rewrite coefZ -exprM coefXn mulnC eqn_pmul2l // mulr_natr mulrb ifN_eqC.
by rewrite coef_poly leir coefZ -exprM coefXn mulnC eqxx mulr1.
Qed.
Lemma separable_root_der : separable_element K x (+) root (minPoly K x)^`() x.
Proof.
have KpKx': _^`() \is a polyOver K := polyOver_deriv (minPolyOver K x).
rewrite separable_nz_der addNb (root_small_adjoin_poly KpKx') ?addbb //.
by rewrite (leq_trans (size_poly _ _)) ?size_minPoly.
Qed.
Lemma Derivation_separable D :
Derivation <<K; x>> D -> separable_element K x ->
D x = - (map_poly D (minPoly K x)).[x] / (minPoly K x)^`().[x].
Proof.
move=> derD sepKx; have:= separable_root_der; rewrite {}sepKx -sub0r => nzKx'x.
apply: canRL (mulfK nzKx'x) (canRL (addrK _) _); rewrite mulrC addrC.
rewrite -(Derivation_horner derD) ?minPolyxx ?linear0 //.
exact: polyOverSv sKxK _ (minPolyOver _ _).
Qed.
Section ExtendDerivation.
Variable D : 'End(L).
Let Dx E := - (map_poly D (minPoly E x)).[x] / ((minPoly E x)^`()).[x].
Fact extendDerivation_zmod_morphism_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
zmod_morphism body.
Proof.
move: Dx => C /= u v; rewrite /adjEx.
rewrite raddfB /= derivB -/adjEx !hornerE /= raddfB /= !hornerE.
by rewrite mulrBl addrACA opprD.
Qed.
Fact extendDerivation_scalable_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
scalable body.
Proof.
move: Dx => C /= a u; rewrite /adjEx linearZ /= derivZ -/adjEx.
rewrite hornerE -[RHS]mulr_algl mulrDr mulrA -[in RHS]hornerZ.
congr (_.[x] + _); apply/polyP=> i.
by rewrite coefZ !coef_map coefZ !mulr_algl /= linearZ.
Qed.
Section DerivationLinear.
Variable (E : {subfield L}).
Let body (y : L) (p := Fadjoin_poly E x y) : L :=
(map_poly D p).[x] + p^`().[x] * Dx E.
HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ body
(extendDerivation_zmod_morphism_subproof E).
HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ body
(extendDerivation_scalable_subproof E).
Let extendDerivationLinear := Eval hnf in (body : {linear _ -> _}).
Definition extendDerivation : 'End(L) := linfun extendDerivationLinear.
End DerivationLinear.
Hypothesis derD : Derivation K D.
Lemma extendDerivation_id y : y \in K -> extendDerivation K y = D y.
Proof.
move=> yK; rewrite lfunE /= Fadjoin_polyC // derivC map_polyC hornerC.
by rewrite horner0 mul0r addr0.
Qed.
Lemma extendDerivation_horner p :
p \is a polyOver K -> separable_element K x ->
extendDerivation K p.[x] = (map_poly D p).[x] + p^`().[x] * Dx K.
Proof.
move=> Kp sepKx; have:= separable_root_der; rewrite {}sepKx /= => nz_pKx'x.
rewrite [in RHS](divp_eq p (minPoly K x)) lfunE /= Fadjoin_poly_mod ?raddfD //=.
rewrite (Derivation_mul_poly derD) ?divp_polyOver ?minPolyOver //.
rewrite derivM !{1}hornerD !{1}hornerM minPolyxx !{1}mulr0 !{1}add0r.
rewrite mulrDl addrA [_ + (_ * _ * _)]addrC {2}/Dx -mulrA -/Dx.
by rewrite [_ / _]mulrC (mulVKf nz_pKx'x) mulrN addKr.
Qed.
Lemma extendDerivationP :
separable_element K x -> Derivation <<K; x>> (extendDerivation K).
Proof.
move=> sep; apply/allrelP=> u v /vbasis_mem Hu /vbasis_mem Hv; apply/eqP.
rewrite -(Fadjoin_poly_eq Hu) -(Fadjoin_poly_eq Hv) -hornerM.
rewrite !{1}extendDerivation_horner ?{1}rpredM ?Fadjoin_polyOver //.
rewrite (Derivation_mul_poly derD) ?Fadjoin_polyOver //.
rewrite derivM !{1}hornerD !{1}hornerM !{1}mulrDl !{1}mulrDr -!addrA.
congr (_ + _); rewrite [Dx K]lock -!{1}mulrA !{1}addrA; congr (_ + _).
by rewrite addrC; congr (_ * _ + _); rewrite mulrC.
Qed.
End ExtendDerivation.
(* Reference:
http://www.math.uconn.edu/~kconrad/blurbs/galoistheory/separable2.pdf *)
Lemma Derivation_separableP :
reflect
(forall D, Derivation <<K; x>> D -> K <= lker D -> <<K; x>> <= lker D)%VS
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx D derD /subvP DK_0 | derKx_0].
have{} DK_0 q: q \is a polyOver K -> map_poly D q = 0.
move=> /polyOverP Kq; apply/polyP=> i; apply/eqP.
by rewrite coef0 coef_map -memv_ker DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->]; rewrite memv_ker.
rewrite (Derivation_horner derD) ?(polyOverSv sKxK) //.
rewrite (Derivation_separable derD sepKx) !DK_0 ?minPolyOver //.
by rewrite horner0 oppr0 mul0r mulr0 addr0.
apply: wlog_neg; rewrite {1}separable_nz_der negbK => /eqP pKx'_0.
pose Df := fun y => (Fadjoin_poly K x y)^`().[x].
have Dlin: linear Df.
move=> a u v; rewrite /Df linearP /= -mul_polyC derivD derivM derivC.
by rewrite mul0r add0r hornerD hornerM hornerC -scalerAl mul1r.
pose DlinM := GRing.isLinear.Build _ _ _ _ Df Dlin.
pose DL : {linear _ -> _} := HB.pack Df DlinM.
pose D := linfun DL; apply: base_separable.
have DK_0: (K <= lker D)%VS.
apply/subvP=> v Kv; rewrite memv_ker lfunE /= /Df Fadjoin_polyC //.
by rewrite derivC horner0.
have Dder: Derivation <<K; x>> D.
apply/allrelP=> u v /vbasis_mem Kx_u /vbasis_mem Kx_v; apply/eqP.
rewrite !lfunE /= /Df; set Px := Fadjoin_poly K x.
set Px_u := Px u; rewrite -(Fadjoin_poly_eq Kx_u) -/Px -/Px_u.
set Px_v := Px v; rewrite -(Fadjoin_poly_eq Kx_v) -/Px -/Px_v.
rewrite -!hornerM -hornerD -derivM.
rewrite /Px Fadjoin_poly_mod ?rpredM ?Fadjoin_polyOver //.
rewrite [in RHS](divp_eq (Px_u * Px_v) (minPoly K x)) derivD derivM.
by rewrite pKx'_0 mulr0 addr0 hornerD hornerM minPolyxx mulr0 add0r.
have{Dder DK_0}: x \in lker D by apply: subvP Kx_x; apply: derKx_0.
apply: contraLR => K'x; rewrite memv_ker lfunE /= /Df Fadjoin_polyX //.
by rewrite derivX hornerC oner_eq0.
Qed.
End SeparableElement.
#[deprecated(since="mathcomp 2.4.0", note="Use separablePn_pchar instead.")]
Notation separablePn := (separablePn_pchar) (only parsing).
Arguments separable_elementP {K x}.
Lemma separable_elementS K E x :
(K <= E)%VS -> separable_element K x -> separable_element E x.
Proof.
move=> sKE /separable_elementP[f [fK rootf sepf]]; apply/separable_elementP.
by exists f; rewrite (polyOverSv sKE).
Qed.
Lemma adjoin_separableP {K x} :
reflect (forall y, y \in <<K; x>>%VS -> separable_element K y)
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx | -> //]; last exact: memv_adjoin.
move=> _ /Fadjoin_polyP[q Kq ->]; apply/Derivation_separableP=> D derD DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->].
rewrite memv_ker -(extendDerivation_id x D (mempx_Fadjoin _ Kp)).
have sepFyx: (separable_element <<K; q.[x]>> x).
by apply: (separable_elementS (subv_adjoin _ _)).
have KyxEqKx: (<< <<K; q.[x]>>; x>> = <<K; x>>)%VS.
apply/eqP; rewrite eqEsubv andbC adjoinSl ?subv_adjoin //=.
apply/FadjoinP/andP; rewrite memv_adjoin andbT.
by apply/FadjoinP/andP; rewrite subv_adjoin mempx_Fadjoin.
have /[!KyxEqKx] derDx := extendDerivationP derD sepFyx.
rewrite -horner_comp (Derivation_horner derDx) ?memv_adjoin //; last first.
by apply: (polyOverSv (subv_adjoin _ _)); apply: polyOver_comp.
set Dx_p := map_poly _; have Dx_p_0 t: t \is a polyOver K -> (Dx_p t).[x] = 0.
move/polyOverP=> Kt; congr (_.[x] = 0): (horner0 x); apply/esym/polyP => i.
have /eqP Dti_0: D t`_i == 0 by rewrite -memv_ker (subvP DK_0) ?Kt.
by rewrite coef0 coef_map /= {1}extendDerivation_id ?subvP_adjoin.
rewrite (Derivation_separable derDx sepKx) -/Dx_p Dx_p_0 ?polyOver_comp //.
by rewrite add0r mulrCA Dx_p_0 ?minPolyOver ?oppr0 ?mul0r.
Qed.
Lemma separable_exponent_pchar K x :
exists n, [pchar L].-nat n && separable_element K (x ^+ n).
Proof.
pose d := adjoin_degree K x; move: {2}d.+1 (ltnSn d) => n.
elim: n => // n IHn in x @d *; rewrite ltnS => le_d_n.
have [[p pcharLp]|] := altP (separablePn_pchar K x); last by rewrite negbK; exists 1.
case=> g Kg defKx; have p_pr := pcharf_prime pcharLp.
suffices /IHn[m /andP[pcharLm sepKxpm]]: adjoin_degree K (x ^+ p) < n.
by exists (p * m)%N; rewrite pnatM pnatE // pcharLp pcharLm exprM.
apply: leq_trans le_d_n; rewrite -ltnS -!size_minPoly.
have nzKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have nzg: g != 0 by apply: contra_eqN defKx => /eqP->; rewrite comp_poly0.
apply: leq_ltn_trans (dvdp_leq nzg _) _.
by rewrite minPoly_dvdp // rootE -hornerXn -horner_comp -defKx minPolyxx.
rewrite (polySpred nzKx) ltnS defKx size_comp_poly size_polyXn /=.
suffices g_gt1: 1 < size g by rewrite -(subnKC g_gt1) ltn_Pmulr ?prime_gt1.
apply: contra_eqT (size_minPoly K x); rewrite defKx -leqNgt => /size1_polyC->.
by rewrite comp_polyC size_polyC; case: (_ != 0).
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use separable_exponent_pchar instead.")]
Notation separable_exponent := (separable_exponent_pchar) (only parsing).
Lemma pcharf0_separable K : [pchar L] =i pred0 -> forall x, separable_element K x.
Proof.
move=> pcharL0 x; have [n /andP[pcharLn]] := separable_exponent_pchar K x.
by rewrite (pnat_1 pcharLn (sub_in_pnat _ pcharLn)) // => p _; rewrite pcharL0.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0_separable instead.")]
Notation charf0_separable := (pcharf0_separable) (only parsing).
Lemma pcharf_p_separable K x e p :
p \in [pchar L] -> separable_element K x = (x \in <<K; x ^+ (p ^ e.+1)>>%VS).
Proof.
move=> pcharLp; apply/idP/idP=> [sepKx | /Fadjoin_poly_eq]; last first.
set m := p ^ _; set f := Fadjoin_poly K _ x => Dx; apply/separable_elementP.
have mL0: m%:R = 0 :> L by apply/eqP; rewrite -(dvdn_pcharf pcharLp) dvdn_exp.
exists ('X - (f \Po 'X^m)); split.
- by rewrite rpredB ?polyOver_comp ?rpredX ?polyOverX ?Fadjoin_polyOver.
- by rewrite rootE !hornerE horner_comp hornerXn Dx subrr.
rewrite unlock !(derivE, deriv_comp) -mulr_natr -rmorphMn /= mL0.
by rewrite !mulr0 subr0 coprimep1.
without loss{e} ->: e x sepKx / e = 0.
move=> IH; elim: {e}e.+1 => [|e]; [exact: memv_adjoin | apply: subvP].
apply/FadjoinP/andP; rewrite subv_adjoin expnSr exprM (IH 0) //.
by have /adjoin_separableP-> := sepKx; rewrite ?rpredX ?memv_adjoin.
set K' := <<K; x ^+ p>>%VS; have sKK': (K <= K')%VS := subv_adjoin _ _.
pose q := minPoly K' x; pose g := 'X^p - (x ^+ p)%:P.
have [K'g]: g \is a polyOver K' /\ q \is a polyOver K'.
by rewrite minPolyOver rpredB ?rpredX ?polyOverX // polyOverC memv_adjoin.
have /dvdpP[c Dq]: 'X - x%:P %| q by rewrite dvdp_XsubCl root_minPoly.
have co_c_g: coprimep c g.
have pcharPp: p \in [pchar {poly L}] := rmorph_pchar polyC pcharLp.
rewrite /g polyC_exp -!(pFrobenius_autE pcharPp) -rmorphB coprimep_expr //.
have: separable_poly q := separable_elementS sKK' sepKx.
by rewrite Dq separable_mul => /and3P[].
have{g K'g co_c_g} /size_poly1P[a nz_a Dc]: size c == 1.
suffices c_dv_g: c %| g by rewrite -(eqp_size (dvdp_gcd_idl c_dv_g)).
have: q %| g by rewrite minPoly_dvdp // rootE !hornerE subrr.
by apply: dvdp_trans; rewrite Dq dvdp_mulIl.
rewrite {q}Dq {c}Dc mulrBr -rmorphM -rmorphN -cons_poly_def qualifE /=.
by rewrite polyseq_cons !polyseqC nz_a /= rpredN andbCA => /and3P[/fpredMl->].
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_p_separable instead.")]
Notation charf_p_separable := (pcharf_p_separable) (only parsing).
Lemma pcharf_n_separable K x n :
[pchar L].-nat n -> 1 < n -> separable_element K x = (x \in <<K; x ^+ n>>%VS).
Proof.
rewrite -pi_pdiv; set p := pdiv n => pcharLn pi_n_p.
have pcharLp: p \in [pchar L] := pnatPpi pcharLn pi_n_p.
have <-: (n`_p)%N = n by rewrite -(eq_partn n (pcharf_eq pcharLp)) part_pnat_id.
by rewrite p_part lognE -mem_primes pi_n_p -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_n_separable instead.")]
Notation charf_n_separable := (pcharf_n_separable) (only parsing).
Definition purely_inseparable_element U x :=
x ^+ ex_minn (separable_exponent_pchar <<U>> x) \in U.
Lemma purely_inseparable_elementP_pchar {K x} :
reflect (exists2 n, [pchar L].-nat n & x ^+ n \in K)
(purely_inseparable_element K x).
Proof.
rewrite /purely_inseparable_element.
case: ex_minnP => n /andP[pcharLn /=]; rewrite subfield_closed => sepKxn min_xn.
apply: (iffP idP) => [Kxn | [m pcharLm Kxm]]; first by exists n.
have{min_xn}: n <= m by rewrite min_xn ?pcharLm ?base_separable.
rewrite leq_eqVlt => /predU1P[-> // | ltnm]; pose p := pdiv m.
have m_gt1: 1 < m by have [/leq_ltn_trans->] := andP pcharLn.
have pcharLp: p \in [pchar L] by rewrite (pnatPpi pcharLm) ?pi_pdiv.
have [/p_natP[em Dm] /p_natP[en Dn]]: p.-nat m /\ p.-nat n.
by rewrite -!(eq_pnat _ (pcharf_eq pcharLp)).
rewrite Dn Dm ltn_exp2l ?prime_gt1 ?pdiv_prime // in ltnm.
rewrite -(Fadjoin_idP Kxm) Dm -(subnKC ltnm) addSnnS expnD exprM -Dn.
by rewrite -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use purely_inseparable_elementP_pchar instead.")]
Notation purely_inseparable_elementP := (purely_inseparable_elementP_pchar) (only parsing).
Lemma separable_inseparable_element K x :
separable_element K x && purely_inseparable_element K x = (x \in K).
Proof.
rewrite /purely_inseparable_element; case: ex_minnP => [[|m]] //=.
rewrite subfield_closed; case: m => /= [-> //| m _ /(_ 1)/implyP/= insepKx].
by rewrite (negPf insepKx) (contraNF (@base_separable K x) insepKx).
Qed.
Lemma base_inseparable K x : x \in K -> purely_inseparable_element K x.
Proof. by rewrite -separable_inseparable_element => /andP[]. Qed.
Lemma sub_inseparable K E x :
(K <= E)%VS -> purely_inseparable_element K x ->
purely_inseparable_element E x.
Proof.
move/subvP=> sKE /purely_inseparable_elementP_pchar[n pcharLn /sKE Exn].
by apply/purely_inseparable_elementP_pchar; exists n.
Qed.
Section PrimitiveElementTheorem.
Variables (K : {subfield L}) (x y : L).
Section FiniteCase.
Variable N : nat.
Let K_is_large := exists s, [/\ uniq s, {subset s <= K} & N < size s].
Let cyclic_or_large (z : L) : z != 0 -> K_is_large \/ exists a, z ^+ a.+1 = 1.
Proof.
move=> nz_z; pose d := adjoin_degree K z.
pose h0 (i : 'I_(N ^ d).+1) (j : 'I_d) := (Fadjoin_poly K z (z ^+ i))`_j.
pose s := undup [seq h0 i j | i <- enum 'I_(N ^ d).+1, j <- enum 'I_d].
have s_h0 i j: h0 i j \in s.
by rewrite mem_undup; apply/allpairsP; exists (i, j); rewrite !mem_enum.
pose h i := [ffun j => Ordinal (etrans (index_mem _ _) (s_h0 i j))].
pose h' (f : {ffun 'I_d -> 'I_(size s)}) := \sum_(j < d) s`_(f j) * z ^+ j.
have hK i: h' (h i) = z ^+ i.
have Kz_zi: z ^+ i \in <<K; z>>%VS by rewrite rpredX ?memv_adjoin.
rewrite -(Fadjoin_poly_eq Kz_zi) (horner_coef_wide z (size_poly _ _)) -/d.
by apply: eq_bigr => j _; rewrite ffunE /= nth_index.
have [inj_h | ] := altP (@injectiveP _ _ h).
left; exists s; split=> [|zi_j|]; rewrite ?undup_uniq ?mem_undup //=.
by case/allpairsP=> ij [_ _ ->]; apply/polyOverP/Fadjoin_polyOver.
rewrite -[size s]card_ord -(@ltn_exp2r _ _ d) // -{2}[d]card_ord -card_ffun.
by rewrite -[_.+1]card_ord -(card_image inj_h) max_card.
case/injectivePn=> i1 [i2 i1'2 /(congr1 h')]; rewrite !hK => eq_zi12; right.
without loss{i1'2} lti12: i1 i2 eq_zi12 / i1 < i2.
by move=> IH; move: i1'2; rewrite neq_ltn => /orP[]; apply: IH.
by exists (i2 - i1.+1)%N; rewrite subnSK ?expfB // eq_zi12 divff ?expf_neq0.
Qed.
Lemma finite_PET : K_is_large \/ exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have [-> | /cyclic_or_large[|[a Dxa]]] := eqVneq x 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists y.
have [-> | /cyclic_or_large[|[b Dyb]]] := eqVneq y 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists x.
pose h0 (ij : 'I_a.+1 * 'I_b.+1) := x ^+ ij.1 * y ^+ ij.2.
pose H := <<[set ij | h0 ij == 1%R]>>%G; pose h (u : coset_of H) := h0 (repr u).
have h0M: {morph h0: ij1 ij2 / (ij1 * ij2)%g >-> ij1 * ij2}.
by rewrite /h0 => [] [i1 j1] [i2 j2] /=; rewrite mulrACA -!exprD !expr_mod.
have memH ij: (ij \in H) = (h0 ij == 1).
rewrite /= gen_set_id ?inE //; apply/group_setP; rewrite inE [h0 _]mulr1.
by split=> // ? ? /[!(inE, h0M)] /eqP-> /eqP->; rewrite mulr1.
have nH ij: ij \in 'N(H)%g.
by apply/(subsetP (cent_sub _))/centP=> ij1 _; congr (_, _); rewrite Zp_mulgC.
have hE ij: h (coset H ij) = h0 ij.
rewrite /h val_coset //; case: repr_rcosetP => ij1.
by rewrite memH h0M => /eqP->; rewrite mul1r.
have h1: h 1%g = 1 by rewrite /h repr_coset1 [h0 _]mulr1.
have hM: {morph h: u v / (u * v)%g >-> u * v}.
by do 2![move=> u; have{u} [? _ ->] := cosetP u]; rewrite -morphM // !hE h0M.
have /cyclicP[w defW]: cyclic [set: coset_of H].
apply: field_mul_group_cyclic (in2W hM) _ => u _; have [ij _ ->] := cosetP u.
by split=> [/eqP | -> //]; rewrite hE -memH => /coset_id.
have Kw_h ij t: h0 ij = t -> t \in <<K; h w>>%VS.
have /cycleP[k Dk]: coset H ij \in <[w]>%g by rewrite -defW inE.
rewrite -hE {}Dk => <-; elim: k => [|k IHk]; first by rewrite h1 rpred1.
by rewrite expgS hM rpredM // memv_adjoin.
right; exists (h w); apply/eqP; rewrite eqEsubv !(sameP FadjoinP andP).
rewrite subv_adjoin (subv_trans (subv_adjoin K y)) ?subv_adjoin //=.
rewrite (Kw_h (0, inZp 1)) 1?(Kw_h (inZp 1, 0)) /h0 ?mulr1 ?mul1r ?expr_mod //=.
by rewrite rpredM ?rpredX ?memv_adjoin // subvP_adjoin ?memv_adjoin.
Qed.
End FiniteCase.
Hypothesis sepKy : separable_element K y.
Lemma Primitive_Element_Theorem : exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have /polyOver_subvs[p Dp]: minPoly K x \is a polyOver K := minPolyOver K x.
have nz_pKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have{nz_pKx} nz_p: p != 0 by rewrite Dp map_poly_eq0 in nz_pKx.
have{Dp} px0: root (map_poly vsval p) x by rewrite -Dp root_minPoly.
have [q0 [Kq0 q0y0 sepKq0]] := separable_elementP sepKy.
have /polyOver_subvs[q Dq]: minPoly K y \is a polyOver K := minPolyOver K y.
have qy0: root (map_poly vsval q) y by rewrite -Dq root_minPoly.
have sep_pKy: separable_poly (minPoly K y).
by rewrite (dvdp_separable _ sepKq0) ?minPoly_dvdp.
have{sep_pKy} sep_q: separable_poly q by rewrite Dq separable_map in sep_pKy.
have [r nz_r PETr] := large_field_PET nz_p px0 qy0 sep_q.
have [[s [Us Ks /ltnW leNs]] | //] := finite_PET (size r).
have{s Us leNs} /allPn[t {}/Ks Kt nz_rt]: ~~ all (root r) s.
by apply: contraTN leNs; rewrite -ltnNge => /max_poly_roots->.
have{PETr} [/= [p1 Dx] [q1 Dy]] := PETr (Subvs Kt) nz_rt.
set z := t * y - x in Dx Dy; exists z; apply/eqP.
rewrite eqEsubv !(sameP FadjoinP andP) subv_adjoin.
have Kz_p1z (r1 : {poly subvs_of K}): (map_poly vsval r1).[z] \in <<K; z>>%VS.
rewrite rpred_horner ?memv_adjoin ?(polyOverSv (subv_adjoin K z)) //.
by apply/polyOver_subvs; exists r1.
rewrite -{1}Dx -{1}Dy !{Dx Dy}Kz_p1z /=.
rewrite (subv_trans (subv_adjoin K y)) ?subv_adjoin // rpredB ?memv_adjoin //.
by rewrite subvP_adjoin // rpredM ?memv_adjoin ?subvP_adjoin.
Qed.
Lemma adjoin_separable : separable_element <<K; y>> x -> separable_element K x.
Proof.
have /Derivation_separableP derKy := sepKy => /Derivation_separableP derKy_x.
have [z defKz] := Primitive_Element_Theorem.
suffices /adjoin_separableP: separable_element K z.
by apply; rewrite -defKz memv_adjoin.
apply/Derivation_separableP=> D; rewrite -defKz => derKxyD DK_0.
suffices derKyD: Derivation <<K; y>>%VS D by rewrite derKy_x // derKy.
by apply: DerivationS derKxyD; apply: subv_adjoin.
Qed.
End PrimitiveElementTheorem.
Lemma strong_Primitive_Element_Theorem K x y :
separable_element <<K; x>> y ->
exists2 z : L, (<< <<K; y>>; x>> = <<K; z>>)%VS
& separable_element K x -> separable_element K y.
Proof.
move=> sepKx_y; have [n /andP[pcharLn sepKyn]] := separable_exponent_pchar K y.
have adjK_C z t: (<<<<K; z>>; t>> = <<<<K; t>>; z>>)%VS.
by rewrite !agenv_add_id -!addvA (addvC <[_]>%VS).
have [z defKz] := Primitive_Element_Theorem x sepKyn.
exists z => [|/adjoin_separable->]; rewrite ?sepKx_y // -defKz.
have [|n_gt1|-> //] := ltngtP n 1; first by case: (n) pcharLn.
apply/eqP; rewrite !(adjK_C _ x) eqEsubv; apply/andP.
split; apply/FadjoinP/andP; rewrite subv_adjoin ?rpredX ?memv_adjoin //=.
by rewrite -pcharf_n_separable ?sepKx_y.
Qed.
Definition separable U W : bool :=
all (separable_element U) (vbasis W).
Definition purely_inseparable U W : bool :=
all (purely_inseparable_element U) (vbasis W).
Lemma separable_add K x y :
separable_element K x -> separable_element K y -> separable_element K (x + y).
Proof.
move/(separable_elementS (subv_adjoin K y))=> sepKy_x sepKy.
have [z defKz] := Primitive_Element_Theorem x sepKy.
have /(adjoin_separableP _): x + y \in <<K; z>>%VS.
by rewrite -defKz rpredD ?memv_adjoin // subvP_adjoin ?memv_adjoin.
apply; apply: adjoin_separable sepKy (adjoin_separable sepKy_x _).
by rewrite defKz base_separable ?memv_adjoin.
Qed.
Lemma separable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> separable_element K (v_ i)) ->
separable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> sepKi.
by elim/big_ind: _; [apply/base_separable/mem0v | apply: separable_add |].
Qed.
Lemma inseparable_add K x y :
purely_inseparable_element K x -> purely_inseparable_element K y ->
purely_inseparable_element K (x + y).
Proof.
have insepP := purely_inseparable_elementP_pchar.
move=> /insepP[n pcharLn Kxn] /insepP[m pcharLm Kym]; apply/insepP.
have pcharLnm: [pchar L].-nat (n * m)%N by rewrite pnatM pcharLn.
by exists (n * m)%N; rewrite ?exprDn_pchar // {2}mulnC !exprM memvD // rpredX.
Qed.
Lemma inseparable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> purely_inseparable_element K (v_ i)) ->
purely_inseparable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> insepKi.
by elim/big_ind: _; [apply/base_inseparable/mem0v | apply: inseparable_add |].
Qed.
Lemma separableP {K E} :
reflect (forall y, y \in E -> separable_element K y) (separable K E).
Proof.
apply/(iffP idP)=> [/allP|] sepK_E; last by apply/allP=> x /vbasis_mem/sepK_E.
move=> y /coord_vbasis->; apply/separable_sum=> i _.
have: separable_element K (vbasis E)`_i by apply/sepK_E/memt_nth.
by move/adjoin_separableP; apply; rewrite rpredZ ?memv_adjoin.
Qed.
Lemma purely_inseparableP {K E} :
reflect (forall y, y \in E -> purely_inseparable_element K y)
(purely_inseparable K E).
Proof.
apply/(iffP idP)=> [/allP|] sep'K_E; last by apply/allP=> x /vbasis_mem/sep'K_E.
move=> y /coord_vbasis->; apply/inseparable_sum=> i _.
have: purely_inseparable_element K (vbasis E)`_i by apply/sep'K_E/memt_nth.
case/purely_inseparable_elementP_pchar=> n pcharLn K_Ein.
by apply/purely_inseparable_elementP_pchar; exists n; rewrite // exprZn rpredZ.
Qed.
Lemma adjoin_separable_eq K x : separable_element K x = separable K <<K; x>>%VS.
Proof. exact: sameP adjoin_separableP separableP. Qed.
Lemma separable_inseparable_decomposition E K :
{x | x \in E /\ separable_element K x & purely_inseparable <<K; x>> E}.
Proof.
without loss sKE: K / (K <= E)%VS.
case/(_ _ (capvSr K E)) => x [Ex sepKEx] /purely_inseparableP sep'KExE.
exists x; first by split; last exact/(separable_elementS _ sepKEx)/capvSl.
apply/purely_inseparableP=> y /sep'KExE; apply: sub_inseparable.
exact/adjoinSl/capvSl.
pose E_ i := (vbasis E)`_i; pose fP i := separable_exponent_pchar K (E_ i).
pose f i := E_ i ^+ ex_minn (fP i); pose s := mkseq f (\dim E).
pose K' := <<K & s>>%VS.
have sepKs: all (separable_element K) s.
by rewrite all_map /f; apply/allP=> i _ /=; case: ex_minnP => m /andP[].
have [x sepKx defKx]: {x | x \in E /\ separable_element K x & K' = <<K; x>>%VS}.
have: all [in E] s.
rewrite all_map; apply/allP=> i; rewrite mem_iota => ltis /=.
by rewrite rpredX // vbasis_mem // memt_nth.
rewrite {}/K'; elim/last_ind: s sepKs => [|s t IHs].
by exists 0; [rewrite base_separable mem0v | rewrite adjoin_nil addv0].
rewrite adjoin_rcons !all_rcons => /andP[sepKt sepKs] /andP[/= Et Es].
have{IHs sepKs Es} [y [Ey sepKy] ->{s}] := IHs sepKs Es.
have /sig_eqW[x defKx] := Primitive_Element_Theorem t sepKy.
exists x; [split | exact: defKx].
suffices: (<<K; x>> <= E)%VS by case/FadjoinP.
by rewrite -defKx !(sameP FadjoinP andP) sKE Ey Et.
apply/adjoin_separableP=> z; rewrite -defKx => Kyt_z.
apply: adjoin_separable sepKy _; apply: adjoin_separableP Kyt_z.
exact: separable_elementS (subv_adjoin K y) sepKt.
exists x; rewrite // -defKx; apply/(all_nthP 0)=> i; rewrite size_tuple => ltiE.
apply/purely_inseparable_elementP_pchar.
exists (ex_minn (fP i)); first by case: ex_minnP => n /andP[].
by apply/seqv_sub_adjoin/map_f; rewrite mem_iota.
Qed.
Definition separable_generator K E : L :=
s2val (locked (separable_inseparable_decomposition E K)).
Lemma separable_generator_mem E K : separable_generator K E \in E.
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generatorP E K : separable_element K (separable_generator K E).
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generator_maximal E K :
purely_inseparable <<K; separable_generator K E>> E.
Proof. by rewrite /separable_generator; case: (locked _). Qed.
Lemma sub_adjoin_separable_generator E K :
separable K E -> (E <= <<K; separable_generator K E>>)%VS.
Proof.
move/separableP=> sepK_E; apply/subvP=> v Ev.
rewrite -separable_inseparable_element.
have /purely_inseparableP-> // := separable_generator_maximal E K.
by rewrite (separable_elementS _ (sepK_E _ Ev)) // subv_adjoin.
Qed.
Lemma eq_adjoin_separable_generator E K :
separable K E -> (K <= E)%VS ->
E = <<K; separable_generator K E>>%VS :> {vspace _}.
Proof.
move=> sepK_E sKE; apply/eqP; rewrite eqEsubv sub_adjoin_separable_generator //.
by apply/FadjoinP/andP; rewrite sKE separable_generator_mem.
Qed.
Lemma separable_refl K : separable K K.
Proof. exact/separableP/base_separable. Qed.
Lemma separable_trans M K E : separable K M -> separable M E -> separable K E.
Proof.
move/sub_adjoin_separable_generator.
set x := separable_generator K M => sMKx /separableP sepM_E.
apply/separableP => w /sepM_E/(separable_elementS sMKx).
case/strong_Primitive_Element_Theorem => _ _ -> //.
exact: separable_generatorP.
Qed.
Lemma separableS K1 K2 E2 E1 :
(K1 <= K2)%VS -> (E2 <= E1)%VS -> separable K1 E1 -> separable K2 E2.
Proof.
move=> sK12 /subvP sE21 /separableP sepK1_E1.
by apply/separableP=> y /sE21/sepK1_E1/(separable_elementS sK12).
Qed.
Lemma separableSl K M E : (K <= M)%VS -> separable K E -> separable M E.
Proof. by move/separableS; apply. Qed.
Lemma separableSr K M E : (M <= E)%VS -> separable K E -> separable K M.
Proof. exact: separableS. Qed.
Lemma separable_Fadjoin_seq K rs :
all (separable_element K) rs -> separable K <<K & rs>>.
Proof.
elim/last_ind: rs => [|s x IHs] in K *.
by rewrite adjoin_nil subfield_closed separable_refl.
rewrite all_rcons adjoin_rcons => /andP[sepKx /IHs/separable_trans-> //].
by rewrite -adjoin_separable_eq (separable_elementS _ sepKx) ?subv_adjoin_seq.
Qed.
Lemma purely_inseparable_refl K : purely_inseparable K K.
Proof. by apply/purely_inseparableP; apply: base_inseparable. Qed.
Lemma purely_inseparable_trans M K E :
purely_inseparable K M -> purely_inseparable M E -> purely_inseparable K E.
Proof.
have insepP := purely_inseparableP => /insepP insepK_M /insepP insepM_E.
have insepPe := purely_inseparable_elementP_pchar.
apply/insepP=> x /insepM_E/insepPe[n pcharLn /insepK_M/insepPe[m pcharLm Kxnm]].
by apply/insepPe; exists (n * m)%N; rewrite ?exprM // pnatM pcharLn pcharLm.
Qed.
End Separable.
Arguments separable_elementP {F L K x}.
Arguments separablePn_pchar {F L K x}.
Arguments Derivation_separableP {F L K x}.
Arguments adjoin_separableP {F L K x}.
Arguments purely_inseparable_elementP_pchar {F L K x}.
Arguments separableP {F L K E}.
Arguments purely_inseparableP {F L K E}.
|
ZPow.lean
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.Deriv.Inv
import Mathlib.Analysis.Calculus.Deriv.Shift
/-!
# Derivatives of `x ^ m`, `m : ℤ`
In this file we prove theorems about (iterated) derivatives of `x ^ m`, `m : ℤ`.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## Keywords
derivative, power
-/
universe u v w
open Topology Filter Asymptotics Set
open scoped Nat
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {E : Type v} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {x : 𝕜}
variable {s : Set 𝕜}
variable {m : ℤ}
/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/
theorem hasStrictDerivAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
HasStrictDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x := by
have : ∀ m : ℤ, 0 < m → HasStrictDerivAt (· ^ m) ((m : 𝕜) * x ^ (m - 1)) x := fun m hm ↦ by
lift m to ℕ using hm.le
simp only [zpow_natCast, Int.cast_natCast]
convert hasStrictDerivAt_pow m x using 2
rw [← Int.ofNat_one, ← Int.ofNat_sub, zpow_natCast]
norm_cast at hm
rcases lt_trichotomy m 0 with (hm | hm | hm)
· have hx : x ≠ 0 := h.resolve_right hm.not_ge
have := (hasStrictDerivAt_inv ?_).scomp _ (this (-m) (neg_pos.2 hm)) <;>
[skip; exact zpow_ne_zero _ hx]
simp only [Function.comp_def, zpow_neg, inv_inv, smul_eq_mul] at this
convert this using 1
rw [sq, mul_inv, inv_inv, Int.cast_neg, neg_mul, neg_mul_neg, ← zpow_add₀ hx, mul_assoc, ←
zpow_add₀ hx]
congr
abel
· simp only [hm, zpow_zero, Int.cast_zero, zero_mul, hasStrictDerivAt_const]
· exact this m hm
theorem hasDerivAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
HasDerivAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) x :=
(hasStrictDerivAt_zpow m x h).hasDerivAt
theorem hasDerivWithinAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) (s : Set 𝕜) :
HasDerivWithinAt (fun x => x ^ m) ((m : 𝕜) * x ^ (m - 1)) s x :=
(hasDerivAt_zpow m x h).hasDerivWithinAt
theorem differentiableAt_zpow : DifferentiableAt 𝕜 (fun x => x ^ m) x ↔ x ≠ 0 ∨ 0 ≤ m :=
⟨fun H => NormedField.continuousAt_zpow.1 H.continuousAt, fun H =>
(hasDerivAt_zpow m x H).differentiableAt⟩
theorem differentiableWithinAt_zpow (m : ℤ) (x : 𝕜) (h : x ≠ 0 ∨ 0 ≤ m) :
DifferentiableWithinAt 𝕜 (fun x => x ^ m) s x :=
(differentiableAt_zpow.mpr h).differentiableWithinAt
theorem differentiableOn_zpow (m : ℤ) (s : Set 𝕜) (h : (0 : 𝕜) ∉ s ∨ 0 ≤ m) :
DifferentiableOn 𝕜 (fun x => x ^ m) s := fun x hxs =>
differentiableWithinAt_zpow m x <| h.imp_left <| ne_of_mem_of_not_mem hxs
theorem deriv_zpow (m : ℤ) (x : 𝕜) : deriv (fun x => x ^ m) x = m * x ^ (m - 1) := by
by_cases H : x ≠ 0 ∨ 0 ≤ m
· exact (hasDerivAt_zpow m x H).deriv
· rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_zpow.1 H)]
push_neg at H
rcases H with ⟨rfl, hm⟩
rw [zero_zpow _ ((sub_one_lt _).trans hm).ne, mul_zero]
@[simp]
theorem deriv_zpow' (m : ℤ) : (deriv fun x : 𝕜 => x ^ m) = fun x => (m : 𝕜) * x ^ (m - 1) :=
funext <| deriv_zpow m
theorem derivWithin_zpow (hxs : UniqueDiffWithinAt 𝕜 s x) (h : x ≠ 0 ∨ 0 ≤ m) :
derivWithin (fun x => x ^ m) s x = (m : 𝕜) * x ^ (m - 1) :=
(hasDerivWithinAt_zpow m x h s).derivWithin hxs
@[simp]
theorem iter_deriv_zpow' (m : ℤ) (k : ℕ) :
(deriv^[k] fun x : 𝕜 => x ^ m) =
fun x => (∏ i ∈ Finset.range k, ((m : 𝕜) - i)) * x ^ (m - k) := by
induction' k with k ihk
· simp only [one_mul, Int.ofNat_zero, id, sub_zero, Finset.prod_range_zero,
Function.iterate_zero]
· simp only [Function.iterate_succ_apply', ihk, deriv_const_mul_field', deriv_zpow',
Finset.prod_range_succ, Int.natCast_succ, ← sub_sub, Int.cast_sub, Int.cast_natCast,
mul_assoc]
theorem iter_deriv_zpow (m : ℤ) (x : 𝕜) (k : ℕ) :
deriv^[k] (fun y => y ^ m) x = (∏ i ∈ Finset.range k, ((m : 𝕜) - i)) * x ^ (m - k) :=
congr_fun (iter_deriv_zpow' m k) x
theorem iter_deriv_pow (n : ℕ) (x : 𝕜) (k : ℕ) :
deriv^[k] (fun x : 𝕜 => x ^ n) x = (∏ i ∈ Finset.range k, ((n : 𝕜) - i)) * x ^ (n - k) := by
simp only [← zpow_natCast, iter_deriv_zpow, Int.cast_natCast]
rcases le_or_gt k n with hkn | hnk
· rw [Int.ofNat_sub hkn]
· have : (∏ i ∈ Finset.range k, (n - i : 𝕜)) = 0 :=
Finset.prod_eq_zero (Finset.mem_range.2 hnk) (sub_self _)
simp only [this, zero_mul]
@[simp]
theorem iter_deriv_pow' (n k : ℕ) :
(deriv^[k] fun x : 𝕜 => x ^ n) =
fun x => (∏ i ∈ Finset.range k, ((n : 𝕜) - i)) * x ^ (n - k) :=
funext fun x => iter_deriv_pow n x k
theorem iter_deriv_inv (k : ℕ) (x : 𝕜) :
deriv^[k] Inv.inv x = (-1) ^ k * k ! * x ^ (-1 - k : ℤ) := calc
deriv^[k] Inv.inv x = deriv^[k] (· ^ (-1 : ℤ)) x := by simp
_ = (∏ i ∈ Finset.range k, (-1 - i : 𝕜)) * x ^ (-1 - k : ℤ) := mod_cast iter_deriv_zpow (-1) x k
_ = (-1) ^ k * k ! * x ^ (-1 - k : ℤ) := by
simp only [← neg_add', Finset.prod_neg, ← Finset.prod_Ico_id_eq_factorial,
Finset.prod_Ico_eq_prod_range]
simp
@[simp]
theorem iter_deriv_inv' (k : ℕ) :
deriv^[k] Inv.inv = fun x : 𝕜 => (-1) ^ k * k ! * x ^ (-1 - k : ℤ) :=
funext (iter_deriv_inv k)
open Nat Function in
theorem iter_deriv_inv_linear (k : ℕ) (c d : 𝕜) :
deriv^[k] (fun x ↦ (c * x + d)⁻¹) =
(fun x : 𝕜 ↦ (-1) ^ k * k ! * c ^ k * (c * x + d) ^ (-1 - k : ℤ)) := by
induction k with
| zero => simp
| succ k ihk =>
rw [factorial_succ, add_comm k 1, iterate_add_apply, ihk]
ext z
simp only [Int.reduceNeg, iterate_one, deriv_const_mul_field', cast_add, cast_one]
by_cases hd : c = 0
· simp [hd]
· have := deriv_comp_add_const (fun x ↦ (c * x) ^ (-1 - k : ℤ)) (d / c) z
have h0 : (fun x ↦ (c * (x + d / c)) ^ (-1 - (k : ℤ))) =
(fun x ↦ (c * x + d) ^ (-1 - (k : ℤ))) := by
ext y
field_simp
ring_nf
rw [h0, deriv_comp_mul_left c (fun x ↦ (x) ^ (-1 - k : ℤ)) (z + d / c)] at this
field_simp [this]
ring_nf
theorem iter_deriv_inv_linear_sub (k : ℕ) (c d : 𝕜) :
deriv^[k] (fun x ↦ (c * x - d)⁻¹) =
(fun x : 𝕜 ↦ (-1) ^ k * k ! * c ^ k * (c * x - d) ^ (-1 - k : ℤ)) := by
simpa [sub_eq_add_neg] using iter_deriv_inv_linear k c (-d)
variable {f : E → 𝕜} {t : Set E} {a : E}
theorem DifferentiableWithinAt.zpow (hf : DifferentiableWithinAt 𝕜 f t a) (h : f a ≠ 0 ∨ 0 ≤ m) :
DifferentiableWithinAt 𝕜 (fun x => f x ^ m) t a :=
(differentiableAt_zpow.2 h).comp_differentiableWithinAt a hf
theorem DifferentiableAt.zpow (hf : DifferentiableAt 𝕜 f a) (h : f a ≠ 0 ∨ 0 ≤ m) :
DifferentiableAt 𝕜 (fun x => f x ^ m) a :=
(differentiableAt_zpow.2 h).comp a hf
theorem DifferentiableOn.zpow (hf : DifferentiableOn 𝕜 f t) (h : (∀ x ∈ t, f x ≠ 0) ∨ 0 ≤ m) :
DifferentiableOn 𝕜 (fun x => f x ^ m) t := fun x hx =>
(hf x hx).zpow <| h.imp_left fun h => h x hx
theorem Differentiable.zpow (hf : Differentiable 𝕜 f) (h : (∀ x, f x ≠ 0) ∨ 0 ≤ m) :
Differentiable 𝕜 fun x => f x ^ m := fun x => (hf x).zpow <| h.imp_left fun h => h x
|
ENat.lean
|
/-
Copyright (c) 2022 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.Data.ENat.Basic
import Mathlib.Topology.Instances.Discrete
import Mathlib.Order.Interval.Set.WithBotTop
import Mathlib.Order.Filter.Pointwise
import Mathlib.Topology.Algebra.Monoid.Defs
/-!
# Topology on extended natural numbers
-/
open Filter Set Topology
namespace ENat
/--
Topology on `ℕ∞`.
Note: this is different from the `EMetricSpace` topology. The `EMetricSpace` topology has
`IsOpen {∞}`, but all neighborhoods of `∞` in `ℕ∞` contain infinite intervals.
-/
instance : TopologicalSpace ℕ∞ := Preorder.topology ℕ∞
instance : OrderTopology ℕ∞ := ⟨rfl⟩
@[simp] theorem range_natCast : range ((↑) : ℕ → ℕ∞) = Iio ⊤ :=
WithTop.range_coe
theorem isEmbedding_natCast : IsEmbedding ((↑) : ℕ → ℕ∞) :=
Nat.strictMono_cast.isEmbedding_of_ordConnected <| range_natCast ▸ ordConnected_Iio
theorem isOpenEmbedding_natCast : IsOpenEmbedding ((↑) : ℕ → ℕ∞) :=
⟨isEmbedding_natCast, range_natCast ▸ isOpen_Iio⟩
theorem nhds_natCast (n : ℕ) : 𝓝 (n : ℕ∞) = pure (n : ℕ∞) := by
simp [← isOpenEmbedding_natCast.map_nhds_eq]
@[simp]
protected theorem nhds_eq_pure {n : ℕ∞} (h : n ≠ ⊤) : 𝓝 n = pure n := by
lift n to ℕ using h
simp [nhds_natCast]
theorem isOpen_singleton {x : ℕ∞} (hx : x ≠ ⊤) : IsOpen {x} := by
rw [isOpen_singleton_iff_nhds_eq_pure, ENat.nhds_eq_pure hx]
theorem mem_nhds_iff {x : ℕ∞} {s : Set ℕ∞} (hx : x ≠ ⊤) : s ∈ 𝓝 x ↔ x ∈ s := by
simp [hx]
theorem mem_nhds_natCast_iff (n : ℕ) {s : Set ℕ∞} : s ∈ 𝓝 (n : ℕ∞) ↔ (n : ℕ∞) ∈ s :=
mem_nhds_iff (coe_ne_top _)
theorem tendsto_nhds_top_iff_natCast_lt {α : Type*} {l : Filter α} {f : α → ℕ∞} :
Tendsto f l (𝓝 ⊤) ↔ ∀ n : ℕ, ∀ᶠ a in l, n < f a := by
simp_rw [nhds_top_order, lt_top_iff_ne_top, tendsto_iInf, tendsto_principal]
exact Option.forall_ne_none
instance : ContinuousAdd ℕ∞ := by
refine ⟨continuous_iff_continuousAt.2 fun (a, b) ↦ ?_⟩
match a, b with
| ⊤, _ => exact tendsto_nhds_top_mono' continuousAt_fst fun p ↦ le_add_right le_rfl
| (a : ℕ), ⊤ => exact tendsto_nhds_top_mono' continuousAt_snd fun p ↦ le_add_left le_rfl
| (a : ℕ), (b : ℕ) => simp [ContinuousAt, nhds_prod_eq, tendsto_pure_nhds]
instance : ContinuousMul ℕ∞ where
continuous_mul :=
have key (a : ℕ∞) : ContinuousAt (· * ·).uncurry (a, ⊤) := by
rcases (zero_le a).eq_or_lt with rfl | ha
· simp [ContinuousAt, nhds_prod_eq]
· simp only [ContinuousAt, Function.uncurry, mul_top ha.ne']
refine tendsto_nhds_top_mono continuousAt_snd ?_
filter_upwards [continuousAt_fst (lt_mem_nhds ha)] with (x, y) (hx : 0 < x)
exact le_mul_of_one_le_left (zero_le y) (Order.one_le_iff_pos.2 hx)
continuous_iff_continuousAt.2 <| Prod.forall.2 fun
| (a : ℕ∞), ⊤ => key a
| ⊤, (b : ℕ∞) =>
((key b).comp_of_eq (continuous_swap.tendsto (⊤, b)) rfl).congr <|
.of_forall fun _ ↦ mul_comm ..
| (a : ℕ), (b : ℕ) => by
simp [ContinuousAt, nhds_prod_eq, tendsto_pure_nhds]
protected theorem continuousAt_sub {a b : ℕ∞} (h : a ≠ ⊤ ∨ b ≠ ⊤) :
ContinuousAt (· - ·).uncurry (a, b) := by
match a, b, h with
| (a : ℕ), (b : ℕ), _ => simp [ContinuousAt, nhds_prod_eq]
| (a : ℕ), ⊤, _ =>
suffices ∀ᶠ b in 𝓝 ⊤, (a - b : ℕ∞) = 0 by
simpa [ContinuousAt, nhds_prod_eq, tsub_eq_zero_of_le]
filter_upwards [le_mem_nhds (WithTop.coe_lt_top a)] with b using tsub_eq_zero_of_le
| ⊤, (b : ℕ), _ =>
suffices ∀ n : ℕ, ∀ᶠ a : ℕ∞ in 𝓝 ⊤, b + n < a by
simpa [ContinuousAt, nhds_prod_eq, (· ∘ ·), lt_tsub_iff_left, tendsto_nhds_top_iff_natCast_lt]
exact fun n ↦ lt_mem_nhds <| WithTop.coe_lt_top (b + n)
end ENat
theorem Filter.Tendsto.enatSub {α : Type*} {l : Filter α} {f g : α → ℕ∞} {a b : ℕ∞}
(hf : Tendsto f l (𝓝 a)) (hg : Tendsto g l (𝓝 b)) (h : a ≠ ⊤ ∨ b ≠ ⊤) :
Tendsto (fun x ↦ f x - g x) l (𝓝 (a - b)) :=
(ENat.continuousAt_sub h).tendsto.comp (hf.prodMk_nhds hg)
variable {X : Type*} [TopologicalSpace X] {f g : X → ℕ∞} {s : Set X} {x : X}
nonrec theorem ContinuousWithinAt.enatSub
(hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) (h : f x ≠ ⊤ ∨ g x ≠ ⊤) :
ContinuousWithinAt (fun x ↦ f x - g x) s x :=
hf.enatSub hg h
nonrec theorem ContinuousAt.enatSub
(hf : ContinuousAt f x) (hg : ContinuousAt g x) (h : f x ≠ ⊤ ∨ g x ≠ ⊤) :
ContinuousAt (fun x ↦ f x - g x) x :=
hf.enatSub hg h
nonrec theorem ContinuousOn.enatSub
(hf : ContinuousOn f s) (hg : ContinuousOn g s) (h : ∀ x ∈ s, f x ≠ ⊤ ∨ g x ≠ ⊤) :
ContinuousOn (fun x ↦ f x - g x) s := fun x hx ↦
(hf x hx).enatSub (hg x hx) (h x hx)
nonrec theorem Continuous.enatSub
(hf : Continuous f) (hg : Continuous g) (h : ∀ x, f x ≠ ⊤ ∨ g x ≠ ⊤) :
Continuous (fun x ↦ f x - g x) :=
continuous_iff_continuousAt.2 fun x ↦ hf.continuousAt.enatSub hg.continuousAt (h x)
|
Polynomial.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.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.Tactic.ComputeDegree
/-!
# Matrices of polynomials and polynomials of matrices
In this file, we prove results about matrices over a polynomial ring.
In particular, we give results about the polynomial given by
`det (t * I + A)`.
## References
* "The trace Cayley-Hamilton theorem" by Darij Grinberg, Section 5.3
## Tags
matrix determinant, polynomial
-/
open Matrix Polynomial
variable {n α : Type*} [DecidableEq n] [Fintype n] [CommRing α]
open Polynomial Matrix Equiv.Perm
namespace Polynomial
theorem natDegree_det_X_add_C_le (A B : Matrix n n α) :
natDegree (det ((X : α[X]) • A.map C + B.map C : Matrix n n α[X])) ≤ Fintype.card n := by
rw [det_apply]
refine (natDegree_sum_le _ _).trans ?_
refine Multiset.max_le_of_forall_le _ _ ?_
simp only [forall_apply_eq_imp_iff, true_and, Function.comp_apply,
Multiset.mem_map, exists_imp, Finset.mem_univ_val]
intro g
calc
natDegree (sign g • ∏ i : n, (X • A.map C + B.map C : Matrix n n α[X]) (g i) i) ≤
natDegree (∏ i : n, (X • A.map C + B.map C : Matrix n n α[X]) (g i) i) := by
rcases Int.units_eq_one_or (sign g) with sg | sg
· rw [sg, one_smul]
· rw [sg, Units.neg_smul, one_smul, natDegree_neg]
_ ≤ ∑ i : n, natDegree (((X : α[X]) • A.map C + B.map C : Matrix n n α[X]) (g i) i) :=
(natDegree_prod_le (Finset.univ : Finset n) fun i : n =>
(X • A.map C + B.map C : Matrix n n α[X]) (g i) i)
_ ≤ Finset.univ.card • 1 := (Finset.sum_le_card_nsmul _ _ 1 fun (i : n) _ => ?_)
_ ≤ Fintype.card n := by simp [mul_one, Finset.card_univ]
dsimp only [add_apply, smul_apply, map_apply, smul_eq_mul]
compute_degree
theorem coeff_det_X_add_C_zero (A B : Matrix n n α) :
coeff (det ((X : α[X]) • A.map C + B.map C)) 0 = det B := by
rw [det_apply, finset_sum_coeff, det_apply]
refine Finset.sum_congr rfl ?_
rintro g -
convert coeff_smul (R := α) (sign g) _ 0
rw [coeff_zero_prod]
refine Finset.prod_congr rfl ?_
simp
theorem coeff_det_X_add_C_card (A B : Matrix n n α) :
coeff (det ((X : α[X]) • A.map C + B.map C)) (Fintype.card n) = det A := by
rw [det_apply, det_apply, finset_sum_coeff]
refine Finset.sum_congr rfl ?_
simp only [Finset.mem_univ, forall_true_left]
intro g
convert coeff_smul (R := α) (sign g) _ _
rw [← mul_one (Fintype.card n)]
convert (coeff_prod_of_natDegree_le (R := α) _ _ _ _).symm
· simp [coeff_C]
· rintro p -
dsimp only [add_apply, smul_apply, map_apply, smul_eq_mul]
compute_degree
theorem leadingCoeff_det_X_one_add_C (A : Matrix n n α) :
leadingCoeff (det ((X : α[X]) • (1 : Matrix n n α[X]) + A.map C)) = 1 := by
cases subsingleton_or_nontrivial α
· simp [eq_iff_true_of_subsingleton]
rw [← @det_one n, ← coeff_det_X_add_C_card _ A, leadingCoeff]
simp only [Matrix.map_one, C_eq_zero, RingHom.map_one]
rcases (natDegree_det_X_add_C_le 1 A).eq_or_lt with h | h
· simp only [RingHom.map_one, Matrix.map_one, C_eq_zero] at h
rw [h]
· -- contradiction. we have a hypothesis that the degree is less than |n|
-- but we know that coeff _ n = 1
have H := coeff_eq_zero_of_natDegree_lt h
rw [coeff_det_X_add_C_card] at H
simp at H
end Polynomial
|
Sqrt.lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Algebra.Order.Ring.Unbundled.Rat
import Mathlib.Data.Rat.Lemmas
import Mathlib.Data.Int.Sqrt
/-!
# Square root on rational numbers
This file defines the square root function on rational numbers `Rat.sqrt`
and proves several theorems about it.
-/
namespace Rat
/-- Square root function on rational numbers, defined by taking the (integer) square root of the
numerator and the square root (on natural numbers) of the denominator. -/
@[pp_nodot]
def sqrt (q : ℚ) : ℚ := mkRat (Int.sqrt q.num) (Nat.sqrt q.den)
theorem sqrt_eq (q : ℚ) : Rat.sqrt (q * q) = |q| := by
rw [sqrt, mul_self_num, mul_self_den, Int.sqrt_eq, Nat.sqrt_eq, abs_def, divInt_ofNat]
theorem exists_mul_self (x : ℚ) : (∃ q, q * q = x) ↔ Rat.sqrt x * Rat.sqrt x = x :=
⟨fun ⟨n, hn⟩ => by rw [← hn, sqrt_eq, abs_mul_abs_self], fun h => ⟨Rat.sqrt x, h⟩⟩
lemma sqrt_nonneg (q : ℚ) : 0 ≤ Rat.sqrt q := mkRat_nonneg (Int.sqrt_nonneg _) _
/-- `IsSquare` can be decided on `ℚ` by checking against the square root. -/
instance : DecidablePred (IsSquare : ℚ → Prop) :=
fun m => decidable_of_iff' (sqrt m * sqrt m = m) <| by
simp_rw [← exists_mul_self m, IsSquare, eq_comm]
@[simp, norm_cast]
theorem sqrt_intCast (z : ℤ) : Rat.sqrt (z : ℚ) = Int.sqrt z := by
simp only [sqrt, num_intCast, den_intCast, Nat.sqrt_one, mkRat_one]
@[simp, norm_cast]
theorem sqrt_natCast (n : ℕ) : Rat.sqrt (n : ℚ) = Nat.sqrt n := by
rw [← Int.cast_natCast, sqrt_intCast, Int.sqrt_natCast, Int.cast_natCast]
@[simp]
theorem sqrt_ofNat (n : ℕ) : Rat.sqrt (ofNat(n) : ℚ) = Nat.sqrt (OfNat.ofNat n) :=
sqrt_natCast _
end Rat
|
Resolution.lean
|
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Joël Riou
-/
import Mathlib.Algebra.Homology.QuasiIso
import Mathlib.Algebra.Homology.SingleHomology
import Mathlib.CategoryTheory.Preadditive.Projective.Preserves
/-!
# Projective resolutions
A projective resolution `P : ProjectiveResolution Z` of an object `Z : C` consists of
an `ℕ`-indexed chain complex `P.complex` of projective objects,
along with a quasi-isomorphism `P.π` from `C` to the chain complex consisting just
of `Z` in degree zero.
-/
universe v u v' u'
namespace CategoryTheory
open Category Limits ChainComplex HomologicalComplex
variable {C : Type u} [Category.{v} C]
open Projective
variable [HasZeroObject C] [HasZeroMorphisms C]
/--
A `ProjectiveResolution Z` consists of a bundled `ℕ`-indexed chain complex of projective objects,
along with a quasi-isomorphism to the complex consisting of just `Z` supported in degree `0`.
-/
structure ProjectiveResolution (Z : C) where
/-- the chain complex involved in the resolution -/
complex : ChainComplex C ℕ
/-- the chain complex must be degreewise projective -/
projective : ∀ n, Projective (complex.X n) := by infer_instance
/-- the chain complex must have homology -/
[hasHomology : ∀ i, complex.HasHomology i]
/-- the morphism to the single chain complex with `Z` in degree `0` -/
π : complex ⟶ (ChainComplex.single₀ C).obj Z
/-- the morphism to the single chain complex with `Z` in degree `0` is a quasi-isomorphism -/
quasiIso : QuasiIso π := by infer_instance
open ProjectiveResolution in
attribute [instance] projective hasHomology ProjectiveResolution.quasiIso
/-- An object admits a projective resolution.
-/
class HasProjectiveResolution (Z : C) : Prop where
out : Nonempty (ProjectiveResolution Z)
variable (C)
/-- You will rarely use this typeclass directly: it is implied by the combination
`[EnoughProjectives C]` and `[Abelian C]`.
By itself it's enough to set up the basic theory of derived functors.
-/
class HasProjectiveResolutions : Prop where
out : ∀ Z : C, HasProjectiveResolution Z
attribute [instance 100] HasProjectiveResolutions.out
namespace ProjectiveResolution
variable {C}
variable {Z : C} (P : ProjectiveResolution Z)
lemma complex_exactAt_succ (n : ℕ) :
P.complex.ExactAt (n + 1) := by
rw [← quasiIsoAt_iff_exactAt' P.π (n + 1) (exactAt_succ_single_obj _ _)]
infer_instance
lemma exact_succ (n : ℕ) :
(ShortComplex.mk _ _ (P.complex.d_comp_d (n + 2) (n + 1) n)).Exact :=
((HomologicalComplex.exactAt_iff' _ (n + 2) (n + 1) n) (by simp only [prev]; rfl)
(by simp)).1 (P.complex_exactAt_succ n)
@[simp]
theorem π_f_succ (n : ℕ) : P.π.f (n + 1) = 0 :=
(isZero_single_obj_X _ _ _ _ (by simp)).eq_of_tgt _ _
@[reassoc (attr := simp)]
theorem complex_d_comp_π_f_zero :
P.complex.d 1 0 ≫ P.π.f 0 = 0 := by
rw [← P.π.comm 1 0, single_obj_d, comp_zero]
theorem complex_d_succ_comp (n : ℕ) :
P.complex.d n (n + 1) ≫ P.complex.d (n + 1) (n + 2) = 0 := by
simp
/-- The (limit) cokernel cofork given by the composition
`P.complex.X 1 ⟶ P.complex.X 0 ⟶ Z` when `P : ProjectiveResolution Z`. -/
@[simp]
noncomputable def cokernelCofork : CokernelCofork (P.complex.d 1 0) :=
CokernelCofork.ofπ _ P.complex_d_comp_π_f_zero
/-- `Z` is the cokernel of `P.complex.X 1 ⟶ P.complex.X 0` when `P : ProjectiveResolution Z`. -/
noncomputable def isColimitCokernelCofork : IsColimit (P.cokernelCofork) := by
refine IsColimit.ofIsoColimit (P.complex.opcyclesIsCokernel 1 0 (by simp)) ?_
refine Cofork.ext (P.complex.isoHomologyι₀.symm ≪≫ isoOfQuasiIsoAt P.π 0 ≪≫
singleObjHomologySelfIso _ _ _) ?_
rw [← cancel_mono (singleObjHomologySelfIso (ComplexShape.down ℕ) 0 _).inv,
← cancel_mono (isoHomologyι₀ _).hom]
dsimp
simp only [isoHomologyι₀_inv_naturality_assoc, p_opcyclesMap_assoc, single₀_obj_zero, assoc,
Iso.hom_inv_id, comp_id, isoHomologyι_inv_hom_id, singleObjHomologySelfIso_inv_homologyι,
singleObjOpcyclesSelfIso_hom, single₀ObjXSelf, Iso.refl_inv, id_comp]
instance (n : ℕ) : Epi (P.π.f n) := by
cases n
· exact epi_of_isColimit_cofork P.isColimitCokernelCofork
· rw [π_f_succ]; infer_instance
variable (Z)
/-- A projective object admits a trivial projective resolution: itself in degree 0. -/
@[simps]
noncomputable def self [Projective Z] : ProjectiveResolution Z where
complex := (ChainComplex.single₀ C).obj Z
π := 𝟙 ((ChainComplex.single₀ C).obj Z)
projective n := by
cases n
· simpa
· apply IsZero.projective
apply HomologicalComplex.isZero_single_obj_X
simp
end ProjectiveResolution
namespace Functor
open Limits
variable {C : Type u} [Category C] [HasZeroObject C] [Preadditive C]
{D : Type u'} [Category.{v'} D] [HasZeroObject D] [Preadditive D] [CategoryWithHomology D]
/-- An additive functor `F` which preserves homology and sends projective objects to projective
objects sends a projective resolution of `Z` to a projective resolution of `F.obj Z`. -/
@[simps complex π]
noncomputable def mapProjectiveResolution (F : C ⥤ D) [F.Additive]
[F.PreservesProjectiveObjects] [F.PreservesHomology] {Z : C} (P : ProjectiveResolution Z) :
ProjectiveResolution (F.obj Z) where
complex := (F.mapHomologicalComplex _).obj P.complex
projective n := PreservesProjectiveObjects.projective_obj (P.projective n)
π := (F.mapHomologicalComplex _).map P.π ≫
(HomologicalComplex.singleMapHomologicalComplex _ _ _).hom.app _
quasiIso := inferInstance
end CategoryTheory.Functor
|
Delaborators.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.Init
import Mathlib.Util.PPOptions
import Lean.PrettyPrinter.Delaborator.Builtins
/-! # Pi type notation
Provides the `Π x : α, β x` notation as an alternative to Lean 4's built-in
`(x : α) → β x` notation. To get all non-`∀` pi types to pretty print this way
then do `open scoped PiNotation`.
The notation also accepts extended binders, like `Π x ∈ s, β x` for `Π x, x ∈ s → β x`.
This can be disabled with the `pp.mathlib.binderPredicates` option.
-/
namespace PiNotation
open Lean hiding binderIdent
open Lean.Parser Term
open Lean.PrettyPrinter.Delaborator
open Mathlib
/-- Dependent function type (a "pi type"). The notation `Π x : α, β x` can
also be written as `(x : α) → β x`. -/
-- A direct copy of forall notation but with `Π`/`Pi` instead of `∀`/`Forall`.
@[term_parser]
def piNotation := leading_parser:leadPrec
unicodeSymbol "Π" "PiType" >>
many1 (ppSpace >> (binderIdent <|> bracketedBinder)) >>
optType >> ", " >> termParser
/-- Dependent function type (a "pi type"). The notation `Π x ∈ s, β x` is
short for `Π x, x ∈ s → β x`. -/
-- A copy of forall notation from `Batteries.Util.ExtendedBinder` for pi notation
syntax "Π " binderIdent binderPred ", " term : term
macro_rules
| `(Π $x:ident $pred:binderPred, $p) => `(Π $x:ident, satisfies_binder_pred% $x $pred → $p)
| `(Π _ $pred:binderPred, $p) => `(Π x, satisfies_binder_pred% x $pred → $p)
/-- Since pi notation and forall notation are interchangeable, we can
parse it by simply using the pre-existing forall parser. -/
@[macro PiNotation.piNotation] def replacePiNotation : Lean.Macro
| .node info _ args => return .node info ``Lean.Parser.Term.forall args
| _ => Lean.Macro.throwUnsupported
/-- Override the Lean 4 pi notation delaborator with one that prints cute binders
such as `∀ ε > 0`. -/
@[delab forallE]
def delabPi : Delab := whenPPOption getPPBinderPredicates <| whenPPOption Lean.getPPNotation do
let stx ← delabForall
match stx with
| `(∀ ($i:ident : $_), $j:ident ∈ $s → $body) =>
if i == j then `(∀ $i:ident ∈ $s, $body) else pure stx
| `(∀ ($x:ident : $_), $y:ident > $z → $body) =>
if x == y then `(∀ $x:ident > $z, $body) else pure stx
| `(∀ ($x:ident : $_), $y:ident < $z → $body) =>
if x == y then `(∀ $x:ident < $z, $body) else pure stx
| `(∀ ($x:ident : $_), $y:ident ≥ $z → $body) =>
if x == y then `(∀ $x:ident ≥ $z, $body) else pure stx
| `(∀ ($x:ident : $_), $y:ident ≤ $z → $body) =>
if x == y then `(∀ $x:ident ≤ $z, $body) else pure stx
| `(Π ($i:ident : $_), $j:ident ∈ $s → $body) =>
if i == j then `(Π $i:ident ∈ $s, $body) else pure stx
| `(∀ ($i:ident : $_), $j:ident ∉ $s → $body) =>
if i == j then `(∀ $i:ident ∉ $s, $body) else pure stx
| `(∀ ($i:ident : $_), $j:ident ⊆ $s → $body) =>
if i == j then `(∀ $i:ident ⊆ $s, $body) else pure stx
| `(∀ ($i:ident : $_), $j:ident ⊂ $s → $body) =>
if i == j then `(∀ $i:ident ⊂ $s, $body) else pure stx
| `(∀ ($i:ident : $_), $j:ident ⊇ $s → $body) =>
if i == j then `(∀ $i:ident ⊇ $s, $body) else pure stx
| `(∀ ($i:ident : $_), $j:ident ⊃ $s → $body) =>
if i == j then `(∀ $i:ident ⊃ $s, $body) else pure stx
| _ => pure stx
/-- Override the Lean 4 pi notation delaborator with one that uses `Π` and prints
cute binders such as `∀ ε > 0`.
Note that this takes advantage of the fact that `(x : α) → p x` notation is
never used for propositions, so we can match on this result and rewrite it. -/
@[scoped delab forallE]
def delabPi' : Delab := whenPPOption Lean.getPPNotation do
-- Use delabForall as a backup if `pp.mathlib.binderPredicates` is false.
let stx ← delabPi <|> delabForall
-- Replacements
let stx : Term ←
match stx with
| `($group:bracketedBinder → $body) => `(Π $group:bracketedBinder, $body)
| _ => pure stx
-- Merging
match stx with
| `(Π $group, Π $groups*, $body) => `(Π $group $groups*, $body)
| _ => pure stx
end PiNotation
section existential
open Lean Parser Term PrettyPrinter Delaborator
/-- Delaborator for existential quantifier, including extended binders. -/
-- TODO: reduce the duplication in this code
@[app_delab Exists]
def exists_delab : Delab := whenPPOption Lean.getPPNotation do
let #[ι, f] := (← SubExpr.getExpr).getAppArgs | failure
unless f.isLambda do failure
let prop ← Meta.isProp ι
let dep := f.bindingBody!.hasLooseBVar 0
let ppTypes ← getPPOption getPPFunBinderTypes
let stx ← SubExpr.withAppArg do
let dom ← SubExpr.withBindingDomain delab
withBindingBodyUnusedName fun x => do
let x : TSyntax `ident := .mk x
let body ← delab
if prop && !dep then
`(∃ (_ : $dom), $body)
else if prop || ppTypes then
`(∃ ($x:ident : $dom), $body)
else
`(∃ $x:ident, $body)
-- Cute binders
let stx : Term ←
if ← getPPOption Mathlib.getPPBinderPredicates then
match stx with
| `(∃ $i:ident, $j:ident ∈ $s ∧ $body)
| `(∃ ($i:ident : $_), $j:ident ∈ $s ∧ $body) =>
if i == j then `(∃ $i:ident ∈ $s, $body) else pure stx
| `(∃ $x:ident, $y:ident > $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident > $z ∧ $body) =>
if x == y then `(∃ $x:ident > $z, $body) else pure stx
| `(∃ $x:ident, $y:ident < $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident < $z ∧ $body) =>
if x == y then `(∃ $x:ident < $z, $body) else pure stx
| `(∃ $x:ident, $y:ident ≥ $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident ≥ $z ∧ $body) =>
if x == y then `(∃ $x:ident ≥ $z, $body) else pure stx
| `(∃ $x:ident, $y:ident ≤ $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident ≤ $z ∧ $body) =>
if x == y then `(∃ $x:ident ≤ $z, $body) else pure stx
| `(∃ $x:ident, $y:ident ∉ $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident ∉ $z ∧ $body) => do
if x == y then `(∃ $x:ident ∉ $z, $body) else pure stx
| `(∃ $x:ident, $y:ident ⊆ $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident ⊆ $z ∧ $body) =>
if x == y then `(∃ $x:ident ⊆ $z, $body) else pure stx
| `(∃ $x:ident, $y:ident ⊂ $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident ⊂ $z ∧ $body) =>
if x == y then `(∃ $x:ident ⊂ $z, $body) else pure stx
| `(∃ $x:ident, $y:ident ⊇ $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident ⊇ $z ∧ $body) =>
if x == y then `(∃ $x:ident ⊇ $z, $body) else pure stx
| `(∃ $x:ident, $y:ident ⊃ $z ∧ $body)
| `(∃ ($x:ident : $_), $y:ident ⊃ $z ∧ $body) =>
if x == y then `(∃ $x:ident ⊃ $z, $body) else pure stx
| _ => pure stx
else
pure stx
match stx with
| `(∃ $group:bracketedExplicitBinders, ∃ $[$groups:bracketedExplicitBinders]*, $body) =>
`(∃ $group $groups*, $body)
| `(∃ $b:binderIdent, ∃ $[$bs:binderIdent]*, $body) => `(∃ $b:binderIdent $[$bs]*, $body)
| _ => pure stx
end existential
open Lean Lean.PrettyPrinter.Delaborator
/-- Delaborator for `∉`. -/
@[app_delab Not] def delab_not_in := whenPPOption Lean.getPPNotation do
let #[f] := (← SubExpr.getExpr).getAppArgs | failure
guard <| f.isAppOfArity ``Membership.mem 5
let stx₁ ← SubExpr.withAppArg <| SubExpr.withNaryArg 3 delab
let stx₂ ← SubExpr.withAppArg <| SubExpr.withNaryArg 4 delab
return ← `($stx₂ ∉ $stx₁)
|
UniversallyClosed.lean
|
/-
Copyright (c) 2023 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Etienne Marion
-/
import Mathlib.Topology.Maps.Proper.Basic
import Mathlib.Topology.Compactification.StoneCech
/-!
# A map is proper iff it is continuous and universally closed
-/
open Filter
universe u v
/-- A map `f : X → Y` is proper if and only if it is continuous and the map
`(Prod.map f id : X × Ultrafilter X → Y × Ultrafilter X)` is closed. This is stronger than
`isProperMap_iff_universally_closed` since it shows that there's only one space to check to get
properness, but in most cases it doesn't matter. -/
theorem isProperMap_iff_isClosedMap_ultrafilter {X : Type u} {Y : Type v} [TopologicalSpace X]
[TopologicalSpace Y] {f : X → Y} :
IsProperMap f ↔ Continuous f ∧ IsClosedMap
(Prod.map f id : X × Ultrafilter X → Y × Ultrafilter X) := by
-- The proof is basically the same as above.
constructor <;> intro H
· exact ⟨H.continuous, H.universally_closed _⟩
· rw [isProperMap_iff_ultrafilter]
refine ⟨H.1, fun 𝒰 y hy ↦ ?_⟩
let F : Set (X × Ultrafilter X) := closure {xℱ | xℱ.2 = pure xℱ.1}
have := H.2 F isClosed_closure
have : (y, 𝒰) ∈ Prod.map f id '' F :=
this.mem_of_tendsto (hy.prodMk_nhds (Ultrafilter.tendsto_pure_self 𝒰))
(Eventually.of_forall fun x ↦ ⟨⟨x, pure x⟩, subset_closure rfl, rfl⟩)
rcases this with ⟨⟨x, _⟩, hx, ⟨_, _⟩⟩
refine ⟨x, rfl, fun U hU ↦ Ultrafilter.compl_notMem_iff.mp fun hUc ↦ ?_⟩
rw [mem_closure_iff_nhds] at hx
rcases hx (U ×ˢ {𝒢 | Uᶜ ∈ 𝒢}) (prod_mem_nhds hU ((ultrafilter_isOpen_basic _).mem_nhds hUc))
with ⟨⟨y, 𝒢⟩, ⟨⟨hy : y ∈ U, hy' : Uᶜ ∈ 𝒢⟩, rfl : 𝒢 = pure y⟩⟩
exact hy' hy
/-- A map `f : X → Y` is proper if and only if it is continuous and **universally closed**, in the
sense that for any topological space `Z`, the map `Prod.map f id : X × Z → Y × Z` is closed. Note
that `Z` lives in the same universe as `X` here, but `IsProperMap.universally_closed` does not
have this restriction.
This is taken as the definition of properness in
[N. Bourbaki, *General Topology*][bourbaki1966]. -/
theorem isProperMap_iff_universally_closed {X : Type u} {Y : Type v} [TopologicalSpace X]
[TopologicalSpace Y] {f : X → Y} :
IsProperMap f ↔ Continuous f ∧ ∀ (Z : Type u) [TopologicalSpace Z],
IsClosedMap (Prod.map f id : X × Z → Y × Z) := by
constructor <;> intro H
· exact ⟨H.continuous, fun Z ↦ H.universally_closed _⟩
· rw [isProperMap_iff_isClosedMap_ultrafilter]
exact ⟨H.1, H.2 _⟩
|
Equiv.lean
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Topology.Algebra.Module.LinearMapPiProd
/-!
# Continuous linear equivalences
Continuous semilinear / linear / star-linear equivalences between topological modules are denoted
by `M ≃SL[σ] M₂`, `M ≃L[R] M₂` and `M ≃L⋆[R] M₂`.
-/
assert_not_exists TrivialStar
open LinearMap (ker range)
open Topology Filter Pointwise
universe u v w u'
section
/-- Continuous linear equivalences between modules. We only put the type classes that are necessary
for the definition, although in applications `M` and `M₂` will be topological modules over the
topological semiring `R`. -/
structure ContinuousLinearEquiv {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S)
{σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : Type*) [TopologicalSpace M]
[AddCommMonoid M] (M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M]
[Module S M₂] extends M ≃ₛₗ[σ] M₂ where
continuous_toFun : Continuous toFun := by continuity
continuous_invFun : Continuous invFun := by continuity
attribute [inherit_doc ContinuousLinearEquiv] ContinuousLinearEquiv.continuous_toFun
ContinuousLinearEquiv.continuous_invFun
@[inherit_doc]
notation:50 M " ≃SL[" σ "] " M₂ => ContinuousLinearEquiv σ M M₂
@[inherit_doc]
notation:50 M " ≃L[" R "] " M₂ => ContinuousLinearEquiv (RingHom.id R) M M₂
/-- `ContinuousSemilinearEquivClass F σ M M₂` asserts `F` is a type of bundled continuous
`σ`-semilinear equivs `M → M₂`. See also `ContinuousLinearEquivClass F R M M₂` for the case
where `σ` is the identity map on `R`. A map `f` between an `R`-module and an `S`-module over a ring
homomorphism `σ : R →+* S` is semilinear if it satisfies the two properties `f (x + y) = f x + f y`
and `f (c • x) = (σ c) • f x`. -/
class ContinuousSemilinearEquivClass (F : Type*) {R : outParam Type*} {S : outParam Type*}
[Semiring R] [Semiring S] (σ : outParam <| R →+* S) {σ' : outParam <| S →+* R}
[RingHomInvPair σ σ'] [RingHomInvPair σ' σ] (M : outParam Type*) [TopologicalSpace M]
[AddCommMonoid M] (M₂ : outParam Type*) [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M]
[Module S M₂] [EquivLike F M M₂] : Prop extends SemilinearEquivClass F σ M M₂ where
map_continuous : ∀ f : F, Continuous f := by continuity
inv_continuous : ∀ f : F, Continuous (EquivLike.inv f) := by continuity
attribute [inherit_doc ContinuousSemilinearEquivClass]
ContinuousSemilinearEquivClass.map_continuous
ContinuousSemilinearEquivClass.inv_continuous
/-- `ContinuousLinearEquivClass F σ M M₂` asserts `F` is a type of bundled continuous
`R`-linear equivs `M → M₂`. This is an abbreviation for
`ContinuousSemilinearEquivClass F (RingHom.id R) M M₂`. -/
abbrev ContinuousLinearEquivClass (F : Type*) (R : outParam Type*) [Semiring R]
(M : outParam Type*) [TopologicalSpace M] [AddCommMonoid M] (M₂ : outParam Type*)
[TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M] [Module R M₂] [EquivLike F M M₂] :=
ContinuousSemilinearEquivClass F (RingHom.id R) M M₂
namespace ContinuousSemilinearEquivClass
variable (F : Type*) {R : Type*} {S : Type*} [Semiring R] [Semiring S] (σ : R →+* S)
{σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
(M : Type*) [TopologicalSpace M] [AddCommMonoid M]
(M₂ : Type*) [TopologicalSpace M₂] [AddCommMonoid M₂]
[Module R M] [Module S M₂]
-- `σ'` becomes a metavariable, but it's OK since it's an outparam
instance (priority := 100) continuousSemilinearMapClass [EquivLike F M M₂]
[s : ContinuousSemilinearEquivClass F σ M M₂] : ContinuousSemilinearMapClass F σ M M₂ :=
{ s with }
instance (priority := 100) [EquivLike F M M₂]
[s : ContinuousSemilinearEquivClass F σ M M₂] : HomeomorphClass F M M₂ :=
{ s with }
end ContinuousSemilinearEquivClass
namespace ContinuousLinearMap
section Pi
variable {R : Type*} [Semiring R] {M : Type*} [TopologicalSpace M] [AddCommMonoid M] [Module R M]
{M₂ : Type*} [TopologicalSpace M₂] [AddCommMonoid M₂] [Module R M₂] {ι : Type*} {φ : ι → Type*}
[∀ i, TopologicalSpace (φ i)] [∀ i, AddCommMonoid (φ i)] [∀ i, Module R (φ i)]
variable (R φ)
/-- If `I` and `J` are complementary index sets, the product of the kernels of the `J`th projections
of `φ` is linearly equivalent to the product over `I`. -/
def iInfKerProjEquiv {I J : Set ι} [DecidablePred fun i => i ∈ I] (hd : Disjoint I J)
(hu : Set.univ ⊆ I ∪ J) :
(⨅ i ∈ J, ker (proj i : (∀ i, φ i) →L[R] φ i) :
Submodule R (∀ i, φ i)) ≃L[R] ∀ i : I, φ i where
toLinearEquiv := LinearMap.iInfKerProjEquiv R φ hd hu
continuous_toFun :=
continuous_pi fun i =>
Continuous.comp (continuous_apply (A := φ) i) <|
@continuous_subtype_val _ _ fun x =>
x ∈ (⨅ i ∈ J, ker (proj i : (∀ i, φ i) →L[R] φ i) : Submodule R (∀ i, φ i))
continuous_invFun :=
Continuous.subtype_mk
(continuous_pi fun i => by
dsimp
split_ifs <;> [apply continuous_apply; exact continuous_zero])
_
end Pi
end ContinuousLinearMap
namespace ContinuousLinearEquiv
section AddCommMonoid
variable {R₁ : Type*} {R₂ : Type*} {R₃ : Type*} [Semiring R₁] [Semiring R₂] [Semiring R₃]
{σ₁₂ : R₁ →+* R₂} {σ₂₁ : R₂ →+* R₁} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
{σ₂₃ : R₂ →+* R₃} {σ₃₂ : R₃ →+* R₂} [RingHomInvPair σ₂₃ σ₃₂] [RingHomInvPair σ₃₂ σ₂₃]
{σ₁₃ : R₁ →+* R₃} {σ₃₁ : R₃ →+* R₁} [RingHomInvPair σ₁₃ σ₃₁] [RingHomInvPair σ₃₁ σ₁₃]
[RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] [RingHomCompTriple σ₃₂ σ₂₁ σ₃₁] {M₁ : Type*}
[TopologicalSpace M₁] [AddCommMonoid M₁]
{M₂ : Type*} [TopologicalSpace M₂] [AddCommMonoid M₂] {M₃ : Type*} [TopologicalSpace M₃]
[AddCommMonoid M₃] {M₄ : Type*} [TopologicalSpace M₄] [AddCommMonoid M₄] [Module R₁ M₁]
[Module R₂ M₂] [Module R₃ M₃]
/-- A continuous linear equivalence induces a continuous linear map. -/
@[coe]
def toContinuousLinearMap (e : M₁ ≃SL[σ₁₂] M₂) : M₁ →SL[σ₁₂] M₂ :=
{ e.toLinearEquiv.toLinearMap with cont := e.continuous_toFun }
/-- Coerce continuous linear equivs to continuous linear maps. -/
instance ContinuousLinearMap.coe : Coe (M₁ ≃SL[σ₁₂] M₂) (M₁ →SL[σ₁₂] M₂) :=
⟨toContinuousLinearMap⟩
instance equivLike :
EquivLike (M₁ ≃SL[σ₁₂] M₂) M₁ M₂ where
coe f := f.toFun
inv f := f.invFun
coe_injective' f g h₁ h₂ := by
obtain ⟨f', _⟩ := f
obtain ⟨g', _⟩ := g
rcases f' with ⟨⟨⟨_, _⟩, _⟩, _⟩
rcases g' with ⟨⟨⟨_, _⟩, _⟩, _⟩
congr
left_inv f := f.left_inv
right_inv f := f.right_inv
instance continuousSemilinearEquivClass :
ContinuousSemilinearEquivClass (M₁ ≃SL[σ₁₂] M₂) σ₁₂ M₁ M₂ where
map_add f := f.map_add'
map_smulₛₗ f := f.map_smul'
map_continuous := continuous_toFun
inv_continuous := continuous_invFun
@[simp]
theorem coe_mk (e : M₁ ≃ₛₗ[σ₁₂] M₂) (a b) : ⇑(ContinuousLinearEquiv.mk e a b) = e := rfl
theorem coe_apply (e : M₁ ≃SL[σ₁₂] M₂) (b : M₁) : (e : M₁ →SL[σ₁₂] M₂) b = e b :=
rfl
@[simp]
theorem coe_toLinearEquiv (f : M₁ ≃SL[σ₁₂] M₂) : ⇑f.toLinearEquiv = f :=
rfl
@[simp, norm_cast]
theorem coe_coe (e : M₁ ≃SL[σ₁₂] M₂) : ⇑(e : M₁ →SL[σ₁₂] M₂) = e :=
rfl
theorem toLinearEquiv_injective :
Function.Injective (toLinearEquiv : (M₁ ≃SL[σ₁₂] M₂) → M₁ ≃ₛₗ[σ₁₂] M₂) := by
rintro ⟨e, _, _⟩ ⟨e', _, _⟩ rfl
rfl
@[ext]
theorem ext {f g : M₁ ≃SL[σ₁₂] M₂} (h : (f : M₁ → M₂) = g) : f = g :=
toLinearEquiv_injective <| LinearEquiv.ext <| congr_fun h
theorem coe_injective : Function.Injective ((↑) : (M₁ ≃SL[σ₁₂] M₂) → M₁ →SL[σ₁₂] M₂) :=
fun _e _e' h => ext <| funext <| ContinuousLinearMap.ext_iff.1 h
@[simp, norm_cast]
theorem coe_inj {e e' : M₁ ≃SL[σ₁₂] M₂} : (e : M₁ →SL[σ₁₂] M₂) = e' ↔ e = e' :=
coe_injective.eq_iff
/-- A continuous linear equivalence induces a homeomorphism. -/
def toHomeomorph (e : M₁ ≃SL[σ₁₂] M₂) : M₁ ≃ₜ M₂ :=
{ e with toEquiv := e.toLinearEquiv.toEquiv }
@[simp]
theorem coe_toHomeomorph (e : M₁ ≃SL[σ₁₂] M₂) : ⇑e.toHomeomorph = e :=
rfl
theorem isOpenMap (e : M₁ ≃SL[σ₁₂] M₂) : IsOpenMap e :=
(ContinuousLinearEquiv.toHomeomorph e).isOpenMap
theorem image_closure (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₁) : e '' closure s = closure (e '' s) :=
e.toHomeomorph.image_closure s
theorem preimage_closure (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₂) : e ⁻¹' closure s = closure (e ⁻¹' s) :=
e.toHomeomorph.preimage_closure s
@[simp]
theorem isClosed_image (e : M₁ ≃SL[σ₁₂] M₂) {s : Set M₁} : IsClosed (e '' s) ↔ IsClosed s :=
e.toHomeomorph.isClosed_image
theorem map_nhds_eq (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : map e (𝓝 x) = 𝓝 (e x) :=
e.toHomeomorph.map_nhds_eq x
-- Make some straightforward lemmas available to `simp`.
theorem map_zero (e : M₁ ≃SL[σ₁₂] M₂) : e (0 : M₁) = 0 :=
(e : M₁ →SL[σ₁₂] M₂).map_zero
theorem map_add (e : M₁ ≃SL[σ₁₂] M₂) (x y : M₁) : e (x + y) = e x + e y :=
(e : M₁ →SL[σ₁₂] M₂).map_add x y
@[simp]
theorem map_smulₛₗ (e : M₁ ≃SL[σ₁₂] M₂) (c : R₁) (x : M₁) : e (c • x) = σ₁₂ c • e x :=
(e : M₁ →SL[σ₁₂] M₂).map_smulₛₗ c x
theorem map_smul [Module R₁ M₂] (e : M₁ ≃L[R₁] M₂) (c : R₁) (x : M₁) : e (c • x) = c • e x :=
(e : M₁ →L[R₁] M₂).map_smul c x
theorem map_eq_zero_iff (e : M₁ ≃SL[σ₁₂] M₂) {x : M₁} : e x = 0 ↔ x = 0 :=
e.toLinearEquiv.map_eq_zero_iff
attribute [continuity]
ContinuousLinearEquiv.continuous_toFun ContinuousLinearEquiv.continuous_invFun
@[continuity]
protected theorem continuous (e : M₁ ≃SL[σ₁₂] M₂) : Continuous (e : M₁ → M₂) :=
e.continuous_toFun
protected theorem continuousOn (e : M₁ ≃SL[σ₁₂] M₂) {s : Set M₁} : ContinuousOn (e : M₁ → M₂) s :=
e.continuous.continuousOn
protected theorem continuousAt (e : M₁ ≃SL[σ₁₂] M₂) {x : M₁} : ContinuousAt (e : M₁ → M₂) x :=
e.continuous.continuousAt
protected theorem continuousWithinAt (e : M₁ ≃SL[σ₁₂] M₂) {s : Set M₁} {x : M₁} :
ContinuousWithinAt (e : M₁ → M₂) s x :=
e.continuous.continuousWithinAt
theorem comp_continuousOn_iff {α : Type*} [TopologicalSpace α] (e : M₁ ≃SL[σ₁₂] M₂) {f : α → M₁}
{s : Set α} : ContinuousOn (e ∘ f) s ↔ ContinuousOn f s :=
e.toHomeomorph.comp_continuousOn_iff _ _
theorem comp_continuous_iff {α : Type*} [TopologicalSpace α] (e : M₁ ≃SL[σ₁₂] M₂) {f : α → M₁} :
Continuous (e ∘ f) ↔ Continuous f :=
e.toHomeomorph.comp_continuous_iff
/-- An extensionality lemma for `R ≃L[R] M`. -/
theorem ext₁ [TopologicalSpace R₁] {f g : R₁ ≃L[R₁] M₁} (h : f 1 = g 1) : f = g :=
ext <| funext fun x => mul_one x ▸ by rw [← smul_eq_mul, map_smul, h, map_smul]
section
variable (R₁ M₁)
/-- The identity map as a continuous linear equivalence. -/
@[refl]
protected def refl : M₁ ≃L[R₁] M₁ :=
{ LinearEquiv.refl R₁ M₁ with
continuous_toFun := continuous_id
continuous_invFun := continuous_id }
@[simp]
theorem refl_apply (x : M₁) :
ContinuousLinearEquiv.refl R₁ M₁ x = x := rfl
end
@[simp, norm_cast]
theorem coe_refl : ↑(ContinuousLinearEquiv.refl R₁ M₁) = ContinuousLinearMap.id R₁ M₁ :=
rfl
@[simp, norm_cast]
theorem coe_refl' : ⇑(ContinuousLinearEquiv.refl R₁ M₁) = id :=
rfl
/-- The inverse of a continuous linear equivalence as a continuous linear equivalence -/
@[symm]
protected def symm (e : M₁ ≃SL[σ₁₂] M₂) : M₂ ≃SL[σ₂₁] M₁ :=
{ e.toLinearEquiv.symm with
continuous_toFun := e.continuous_invFun
continuous_invFun := e.continuous_toFun }
@[simp]
theorem toLinearEquiv_symm (e : M₁ ≃SL[σ₁₂] M₂) : e.symm.toLinearEquiv = e.toLinearEquiv.symm :=
rfl
@[deprecated (since := "2025-06-08")] alias symm_toLinearEquiv := toLinearEquiv_symm
@[simp]
theorem coe_symm_toLinearEquiv (e : M₁ ≃SL[σ₁₂] M₂) : ⇑e.toLinearEquiv.symm = e.symm :=
rfl
@[simp]
theorem toHomeomorph_symm (e : M₁ ≃SL[σ₁₂] M₂) : e.symm.toHomeomorph = e.toHomeomorph.symm :=
rfl
@[deprecated "use instead `toHomeomorph_symm`, in the reverse direction" (since := "2025-06-08")]
theorem symm_toHomeomorph (e : M₁ ≃SL[σ₁₂] M₂) : e.toHomeomorph.symm = e.symm.toHomeomorph :=
rfl
@[simp]
theorem coe_symm_toHomeomorph (e : M₁ ≃SL[σ₁₂] M₂) : ⇑e.toHomeomorph.symm = e.symm :=
rfl
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def Simps.apply (h : M₁ ≃SL[σ₁₂] M₂) : M₁ → M₂ :=
h
/-- See Note [custom simps projection] -/
def Simps.symm_apply (h : M₁ ≃SL[σ₁₂] M₂) : M₂ → M₁ :=
h.symm
initialize_simps_projections ContinuousLinearEquiv (toFun → apply, invFun → symm_apply)
theorem symm_map_nhds_eq (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : map e.symm (𝓝 (e x)) = 𝓝 x :=
e.toHomeomorph.symm_map_nhds_eq x
/-- The composition of two continuous linear equivalences as a continuous linear equivalence. -/
@[trans]
protected def trans (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) : M₁ ≃SL[σ₁₃] M₃ :=
{ e₁.toLinearEquiv.trans e₂.toLinearEquiv with
continuous_toFun := e₂.continuous_toFun.comp e₁.continuous_toFun
continuous_invFun := e₁.continuous_invFun.comp e₂.continuous_invFun }
@[simp]
theorem trans_toLinearEquiv (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) :
(e₁.trans e₂).toLinearEquiv = e₁.toLinearEquiv.trans e₂.toLinearEquiv := by
ext
rfl
/-- Product of two continuous linear equivalences. The map comes from `Equiv.prodCongr`. -/
def prodCongr [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (e : M₁ ≃L[R₁] M₂) (e' : M₃ ≃L[R₁] M₄) :
(M₁ × M₃) ≃L[R₁] M₂ × M₄ :=
{ e.toLinearEquiv.prodCongr e'.toLinearEquiv with
continuous_toFun := e.continuous_toFun.prodMap e'.continuous_toFun
continuous_invFun := e.continuous_invFun.prodMap e'.continuous_invFun }
@[deprecated (since := "2025-06-06")] alias prod := prodCongr
@[simp, norm_cast]
theorem prodCongr_apply [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (e : M₁ ≃L[R₁] M₂)
(e' : M₃ ≃L[R₁] M₄) (x) : e.prodCongr e' x = (e x.1, e' x.2) :=
rfl
@[deprecated (since := "2025-06-06")] alias prod_apply := prodCongr_apply
@[simp, norm_cast]
theorem coe_prodCongr [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (e : M₁ ≃L[R₁] M₂)
(e' : M₃ ≃L[R₁] M₄) :
(e.prodCongr e' : M₁ × M₃ →L[R₁] M₂ × M₄) = (e : M₁ →L[R₁] M₂).prodMap (e' : M₃ →L[R₁] M₄) :=
rfl
@[deprecated (since := "2025-06-06")] alias coe_prod := coe_prodCongr
theorem prodCongr_symm [Module R₁ M₂] [Module R₁ M₃] [Module R₁ M₄] (e : M₁ ≃L[R₁] M₂)
(e' : M₃ ≃L[R₁] M₄) : (e.prodCongr e').symm = e.symm.prodCongr e'.symm :=
rfl
@[deprecated (since := "2025-06-06")] alias prod_symm := prodCongr_symm
variable (R₁ M₁ M₂)
/-- Product of modules is commutative up to continuous linear isomorphism. -/
@[simps! apply toLinearEquiv]
def prodComm [Module R₁ M₂] : (M₁ × M₂) ≃L[R₁] M₂ × M₁ :=
{ LinearEquiv.prodComm R₁ M₁ M₂ with
continuous_toFun := continuous_swap
continuous_invFun := continuous_swap }
@[simp] lemma prodComm_symm [Module R₁ M₂] : (prodComm R₁ M₁ M₂).symm = prodComm R₁ M₂ M₁ := rfl
section prodAssoc
variable (R M₁ M₂ M₃ : Type*) [Semiring R]
[AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃] [Module R M₁] [Module R M₂] [Module R M₃]
[TopologicalSpace M₁] [TopologicalSpace M₂] [TopologicalSpace M₃]
/-- The product of topological modules is associative up to continuous linear isomorphism.
This is `LinearEquiv.prodAssoc` prodAssoc as a continuous linear equivalence. -/
def prodAssoc : ((M₁ × M₂) × M₃) ≃L[R] M₁ × M₂ × M₃ where
toLinearEquiv := LinearEquiv.prodAssoc R M₁ M₂ M₃
continuous_toFun := (continuous_fst.comp continuous_fst).prodMk
((continuous_snd.comp continuous_fst).prodMk continuous_snd)
continuous_invFun := (continuous_fst.prodMk (continuous_fst.comp continuous_snd)).prodMk
(continuous_snd.comp continuous_snd)
@[simp]
lemma prodAssoc_toLinearEquiv :
(prodAssoc R M₁ M₂ M₃).toLinearEquiv = LinearEquiv.prodAssoc R M₁ M₂ M₃ := rfl
@[simp]
lemma coe_prodAssoc :
(prodAssoc R M₁ M₂ M₃ : (M₁ × M₂) × M₃ → M₁ × M₂ × M₃) = Equiv.prodAssoc M₁ M₂ M₃ := rfl
@[simp]
lemma prodAssoc_apply (p₁ : M₁) (p₂ : M₂) (p₃ : M₃) :
prodAssoc R M₁ M₂ M₃ ((p₁, p₂), p₃) = (p₁, (p₂, p₃)) := rfl
@[simp]
lemma prodAssoc_symm_apply (p₁ : M₁) (p₂ : M₂) (p₃ : M₃) :
(prodAssoc R M₁ M₂ M₃).symm (p₁, (p₂, p₃)) = ((p₁, p₂), p₃) := rfl
end prodAssoc
section prodUnique
variable (R M N : Type*) [Semiring R]
[TopologicalSpace M] [AddCommMonoid M] [TopologicalSpace N] [AddCommMonoid N]
[Unique N] [Module R M] [Module R N]
/-- The natural equivalence `M × N ≃L[R] M` for any `Unique` type `N`.
This is `Equiv.prodUnique` as a continuous linear equivalence. -/
def prodUnique : (M × N) ≃L[R] M where
toLinearEquiv := LinearEquiv.prodUnique
continuous_toFun := by
change Continuous (Equiv.prodUnique M N)
dsimp; fun_prop
continuous_invFun := by
change Continuous fun x ↦ (x, default)
fun_prop
@[simp]
lemma coe_prodUnique : (prodUnique R M N).toEquiv = Equiv.prodUnique M N := rfl
@[simp]
lemma prodUnique_apply (x : M × N) : prodUnique R M N x = x.1 := rfl
@[simp]
lemma prodUnique_symm_apply (x : M) : (prodUnique R M N).symm x = (x, default) := rfl
/-- The natural equivalence `N × M ≃L[R] M` for any `Unique` type `N`.
This is `Equiv.uniqueProd` as a continuous linear equivalence. -/
def uniqueProd : (N × M) ≃L[R] M where
toLinearEquiv := LinearEquiv.uniqueProd
continuous_toFun := by
change Continuous (Equiv.uniqueProd M N)
dsimp; fun_prop
continuous_invFun := by
change Continuous fun x ↦ (default, x)
fun_prop
@[simp]
lemma coe_uniqueProd : (uniqueProd R M N).toEquiv = Equiv.uniqueProd M N := rfl
@[simp]
lemma uniqueProd_apply (x : N × M) : uniqueProd R M N x = x.2 := rfl
@[simp]
lemma uniqueProd_symm_apply (x : M) : (uniqueProd R M N).symm x = (default, x) := rfl
end prodUnique
variable {R₁ M₁ M₂}
protected theorem bijective (e : M₁ ≃SL[σ₁₂] M₂) : Function.Bijective e :=
e.toLinearEquiv.toEquiv.bijective
protected theorem injective (e : M₁ ≃SL[σ₁₂] M₂) : Function.Injective e :=
e.toLinearEquiv.toEquiv.injective
protected theorem surjective (e : M₁ ≃SL[σ₁₂] M₂) : Function.Surjective e :=
e.toLinearEquiv.toEquiv.surjective
@[simp]
theorem trans_apply (e₁ : M₁ ≃SL[σ₁₂] M₂) (e₂ : M₂ ≃SL[σ₂₃] M₃) (c : M₁) :
(e₁.trans e₂) c = e₂ (e₁ c) :=
rfl
@[simp]
theorem apply_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) (c : M₂) : e (e.symm c) = c :=
e.1.right_inv c
@[simp]
theorem symm_apply_apply (e : M₁ ≃SL[σ₁₂] M₂) (b : M₁) : e.symm (e b) = b :=
e.1.left_inv b
@[simp]
theorem symm_trans_apply (e₁ : M₂ ≃SL[σ₂₁] M₁) (e₂ : M₃ ≃SL[σ₃₂] M₂) (c : M₁) :
(e₂.trans e₁).symm c = e₂.symm (e₁.symm c) :=
rfl
@[simp]
theorem symm_image_image (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₁) : e.symm '' (e '' s) = s :=
e.toLinearEquiv.toEquiv.symm_image_image s
@[simp]
theorem image_symm_image (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₂) : e '' (e.symm '' s) = s :=
e.symm.symm_image_image s
@[simp, norm_cast]
theorem comp_coe (f : M₁ ≃SL[σ₁₂] M₂) (f' : M₂ ≃SL[σ₂₃] M₃) :
(f' : M₂ →SL[σ₂₃] M₃).comp (f : M₁ →SL[σ₁₂] M₂) = (f.trans f' : M₁ →SL[σ₁₃] M₃) :=
rfl
-- The priority should be higher than `comp_coe`.
@[simp high]
theorem coe_comp_coe_symm (e : M₁ ≃SL[σ₁₂] M₂) :
(e : M₁ →SL[σ₁₂] M₂).comp (e.symm : M₂ →SL[σ₂₁] M₁) = ContinuousLinearMap.id R₂ M₂ :=
ContinuousLinearMap.ext e.apply_symm_apply
-- The priority should be higher than `comp_coe`.
@[simp high]
theorem coe_symm_comp_coe (e : M₁ ≃SL[σ₁₂] M₂) :
(e.symm : M₂ →SL[σ₂₁] M₁).comp (e : M₁ →SL[σ₁₂] M₂) = ContinuousLinearMap.id R₁ M₁ :=
ContinuousLinearMap.ext e.symm_apply_apply
@[simp]
theorem symm_comp_self (e : M₁ ≃SL[σ₁₂] M₂) : (e.symm : M₂ → M₁) ∘ (e : M₁ → M₂) = id := by
ext x
exact symm_apply_apply e x
@[simp]
theorem self_comp_symm (e : M₁ ≃SL[σ₁₂] M₂) : (e : M₁ → M₂) ∘ (e.symm : M₂ → M₁) = id := by
ext x
exact apply_symm_apply e x
@[simp]
theorem symm_symm (e : M₁ ≃SL[σ₁₂] M₂) : e.symm.symm = e := rfl
theorem symm_bijective : Function.Bijective (ContinuousLinearEquiv.symm : (M₁ ≃SL[σ₁₂] M₂) → _) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp]
theorem refl_symm : (ContinuousLinearEquiv.refl R₁ M₁).symm = ContinuousLinearEquiv.refl R₁ M₁ :=
rfl
theorem symm_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) (x : M₁) : e.symm.symm x = e x :=
rfl
theorem symm_apply_eq (e : M₁ ≃SL[σ₁₂] M₂) {x y} : e.symm x = y ↔ x = e y :=
e.toLinearEquiv.symm_apply_eq
theorem eq_symm_apply (e : M₁ ≃SL[σ₁₂] M₂) {x y} : y = e.symm x ↔ e y = x :=
e.toLinearEquiv.eq_symm_apply
protected theorem image_eq_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₁) : e '' s = e.symm ⁻¹' s :=
e.toLinearEquiv.toEquiv.image_eq_preimage s
protected theorem image_symm_eq_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₂) :
e.symm '' s = e ⁻¹' s := by rw [e.symm.image_eq_preimage, e.symm_symm]
@[simp]
protected theorem symm_preimage_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₂) :
e.symm ⁻¹' (e ⁻¹' s) = s :=
e.toLinearEquiv.toEquiv.symm_preimage_preimage s
@[simp]
protected theorem preimage_symm_preimage (e : M₁ ≃SL[σ₁₂] M₂) (s : Set M₁) :
e ⁻¹' (e.symm ⁻¹' s) = s :=
e.symm.symm_preimage_preimage s
lemma isUniformEmbedding {E₁ E₂ : Type*} [UniformSpace E₁] [UniformSpace E₂]
[AddCommGroup E₁] [AddCommGroup E₂] [Module R₁ E₁] [Module R₂ E₂] [IsUniformAddGroup E₁]
[IsUniformAddGroup E₂] (e : E₁ ≃SL[σ₁₂] E₂) : IsUniformEmbedding e :=
e.toLinearEquiv.toEquiv.isUniformEmbedding e.toContinuousLinearMap.uniformContinuous
e.symm.toContinuousLinearMap.uniformContinuous
protected theorem _root_.LinearEquiv.isUniformEmbedding {E₁ E₂ : Type*} [UniformSpace E₁]
[UniformSpace E₂] [AddCommGroup E₁] [AddCommGroup E₂] [Module R₁ E₁] [Module R₂ E₂]
[IsUniformAddGroup E₁] [IsUniformAddGroup E₂] (e : E₁ ≃ₛₗ[σ₁₂] E₂)
(h₁ : Continuous e) (h₂ : Continuous e.symm) : IsUniformEmbedding e :=
ContinuousLinearEquiv.isUniformEmbedding
({ e with
continuous_toFun := h₁
continuous_invFun := h₂ } :
E₁ ≃SL[σ₁₂] E₂)
/-- Create a `ContinuousLinearEquiv` from two `ContinuousLinearMap`s that are
inverse of each other. See also `equivOfInverse'`. -/
def equivOfInverse (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M₁) (h₁ : Function.LeftInverse f₂ f₁)
(h₂ : Function.RightInverse f₂ f₁) : M₁ ≃SL[σ₁₂] M₂ :=
{ f₁ with
continuous_toFun := f₁.continuous
invFun := f₂
continuous_invFun := f₂.continuous
left_inv := h₁
right_inv := h₂ }
@[simp]
theorem equivOfInverse_apply (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂ x) :
equivOfInverse f₁ f₂ h₁ h₂ x = f₁ x :=
rfl
@[simp]
theorem symm_equivOfInverse (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂) :
(equivOfInverse f₁ f₂ h₁ h₂).symm = equivOfInverse f₂ f₁ h₂ h₁ :=
rfl
/-- Create a `ContinuousLinearEquiv` from two `ContinuousLinearMap`s that are
inverse of each other, in the `ContinuousLinearMap.comp` sense. See also `equivOfInverse`. -/
def equivOfInverse' (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ : M₂ →SL[σ₂₁] M₁)
(h₁ : f₁.comp f₂ = .id R₂ M₂) (h₂ : f₂.comp f₁ = .id R₁ M₁) : M₁ ≃SL[σ₁₂] M₂ :=
equivOfInverse f₁ f₂
(fun x ↦ by simpa using congr($(h₂) x)) (fun x ↦ by simpa using congr($(h₁) x))
@[simp]
theorem equivOfInverse'_apply (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂ x) :
equivOfInverse' f₁ f₂ h₁ h₂ x = f₁ x :=
rfl
/-- The inverse of `equivOfInverse'` is obtained by swapping the order of its parameters. -/
@[simp]
theorem symm_equivOfInverse' (f₁ : M₁ →SL[σ₁₂] M₂) (f₂ h₁ h₂) :
(equivOfInverse' f₁ f₂ h₁ h₂).symm = equivOfInverse' f₂ f₁ h₂ h₁ :=
rfl
variable (M₁)
/-- The continuous linear equivalences from `M` to itself form a group under composition. -/
instance automorphismGroup : Group (M₁ ≃L[R₁] M₁) where
mul f g := g.trans f
one := ContinuousLinearEquiv.refl R₁ M₁
inv f := f.symm
mul_assoc f g h := by
ext
rfl
mul_one f := by
ext
rfl
one_mul f := by
ext
rfl
inv_mul_cancel f := by
ext x
exact f.left_inv x
variable {M₁} {R₄ : Type*} [Semiring R₄] [Module R₄ M₄] {σ₃₄ : R₃ →+* R₄} {σ₄₃ : R₄ →+* R₃}
[RingHomInvPair σ₃₄ σ₄₃] [RingHomInvPair σ₄₃ σ₃₄] {σ₂₄ : R₂ →+* R₄} {σ₁₄ : R₁ →+* R₄}
[RingHomCompTriple σ₂₁ σ₁₄ σ₂₄] [RingHomCompTriple σ₂₄ σ₄₃ σ₂₃] [RingHomCompTriple σ₁₃ σ₃₄ σ₁₄]
/-- The continuous linear equivalence between `ULift M₁` and `M₁`.
This is a continuous version of `ULift.moduleEquiv`. -/
def ulift : ULift M₁ ≃L[R₁] M₁ :=
{ ULift.moduleEquiv with
continuous_toFun := continuous_uliftDown
continuous_invFun := continuous_uliftUp }
/-- A pair of continuous (semi)linear equivalences generates an equivalence between the spaces of
continuous linear maps. See also `ContinuousLinearEquiv.arrowCongr`. -/
@[simps]
def arrowCongrEquiv (e₁₂ : M₁ ≃SL[σ₁₂] M₂) (e₄₃ : M₄ ≃SL[σ₄₃] M₃) :
(M₁ →SL[σ₁₄] M₄) ≃ (M₂ →SL[σ₂₃] M₃) where
toFun f := (e₄₃ : M₄ →SL[σ₄₃] M₃).comp (f.comp (e₁₂.symm : M₂ →SL[σ₂₁] M₁))
invFun f := (e₄₃.symm : M₃ →SL[σ₃₄] M₄).comp (f.comp (e₁₂ : M₁ →SL[σ₁₂] M₂))
left_inv f :=
ContinuousLinearMap.ext fun x => by
simp only [ContinuousLinearMap.comp_apply, symm_apply_apply, coe_coe]
right_inv f :=
ContinuousLinearMap.ext fun x => by
simp only [ContinuousLinearMap.comp_apply, apply_symm_apply, coe_coe]
section Pi
/-- Combine a family of linear equivalences into a linear equivalence of `pi`-types.
This is `Equiv.piCongrLeft` as a `ContinuousLinearEquiv`.
-/
def piCongrLeft (R : Type*) [Semiring R] {ι ι' : Type*}
(φ : ι → Type*) [∀ i, AddCommMonoid (φ i)] [∀ i, Module R (φ i)]
[∀ i, TopologicalSpace (φ i)]
(e : ι' ≃ ι) : ((i' : ι') → φ (e i')) ≃L[R] (i : ι) → φ i where
__ := Homeomorph.piCongrLeft e
__ := LinearEquiv.piCongrLeft R φ e
/-- The product over `S ⊕ T` of a family of topological modules
is isomorphic (topologically and algebraically) to the product of
(the product over `S`) and (the product over `T`).
This is `Equiv.sumPiEquivProdPi` as a `ContinuousLinearEquiv`.
-/
def sumPiEquivProdPi (R : Type*) [Semiring R] (S T : Type*)
(A : S ⊕ T → Type*) [∀ st, AddCommMonoid (A st)] [∀ st, Module R (A st)]
[∀ st, TopologicalSpace (A st)] :
((st : S ⊕ T) → A st) ≃L[R] ((s : S) → A (Sum.inl s)) × ((t : T) → A (Sum.inr t)) where
__ := LinearEquiv.sumPiEquivProdPi R S T A
__ := Homeomorph.sumPiEquivProdPi S T A
/-- The product `Π t : α, f t` of a family of topological modules is isomorphic
(both topologically and algebraically) to the space `f ⬝` when `α` only contains `⬝`.
This is `Equiv.piUnique` as a `ContinuousLinearEquiv`.
-/
@[simps! -fullyApplied]
def piUnique {α : Type*} [Unique α] (R : Type*) [Semiring R] (f : α → Type*)
[∀ x, AddCommMonoid (f x)] [∀ x, Module R (f x)] [∀ x, TopologicalSpace (f x)] :
(Π t, f t) ≃L[R] f default where
__ := LinearEquiv.piUnique R f
__ := Homeomorph.piUnique f
end Pi
section piCongrRight
variable {ι : Type*} {M : ι → Type*} [∀ i, TopologicalSpace (M i)] [∀ i, AddCommMonoid (M i)]
[∀ i, Module R₁ (M i)] {N : ι → Type*} [∀ i, TopologicalSpace (N i)] [∀ i, AddCommMonoid (N i)]
[∀ i, Module R₁ (N i)] (f : (i : ι) → M i ≃L[R₁] N i)
/-- Combine a family of continuous linear equivalences into a continuous linear equivalence of
pi-types. -/
def piCongrRight : ((i : ι) → M i) ≃L[R₁] (i : ι) → N i :=
{ LinearEquiv.piCongrRight fun i ↦ f i with
continuous_toFun := by
exact continuous_pi fun i ↦ (f i).continuous_toFun.comp (continuous_apply i)
continuous_invFun := by
exact continuous_pi fun i => (f i).continuous_invFun.comp (continuous_apply i) }
@[simp]
theorem piCongrRight_apply (m : (i : ι) → M i) (i : ι) :
piCongrRight f m i = (f i) (m i) := rfl
@[simp]
theorem piCongrRight_symm_apply (n : (i : ι) → N i) (i : ι) :
(piCongrRight f).symm n i = (f i).symm (n i) := rfl
end piCongrRight
section DistribMulAction
variable {G : Type*} [Group G] [DistribMulAction G M₁] [ContinuousConstSMul G M₁]
[SMulCommClass G R₁ M₁]
/-- Scalar multiplication by a group element as a continuous linear equivalence. -/
@[simps! apply_toLinearEquiv apply_apply]
def smulLeft : G →* M₁ ≃L[R₁] M₁ where
toFun g := ⟨DistribMulAction.toModuleAut _ _ g, continuous_const_smul _, continuous_const_smul _⟩
map_mul' _ _ := toLinearEquiv_injective <| map_mul (DistribMulAction.toModuleAut _ _) _ _
map_one' := toLinearEquiv_injective <| map_one <| DistribMulAction.toModuleAut _ _
end DistribMulAction
end AddCommMonoid
section Aut
/-!
### Automorphisms as continuous linear equivalences and as units of the ring of endomorphisms
The next theorems cover the identification between `M ≃L[R] M`and the group of units of the ring
`M →L[R] M`.
-/
variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [TopologicalSpace M]
/-- An invertible continuous linear map `f` determines a continuous equivalence from `M` to itself.
-/
def ofUnit (f : (M →L[R] M)ˣ) : M ≃L[R] M where
toLinearEquiv :=
{ toFun := f.val
map_add' := by simp
map_smul' := by simp
invFun := f.inv
left_inv := fun x =>
show (f.inv * f.val) x = x by
rw [f.inv_val]
simp
right_inv := fun x =>
show (f.val * f.inv) x = x by
rw [f.val_inv]
simp }
continuous_toFun := f.val.continuous
continuous_invFun := f.inv.continuous
/-- A continuous equivalence from `M` to itself determines an invertible continuous linear map. -/
def toUnit (f : M ≃L[R] M) : (M →L[R] M)ˣ where
val := f
inv := f.symm
val_inv := by
ext
simp
inv_val := by
ext
simp
variable (R M)
/-- The units of the algebra of continuous `R`-linear endomorphisms of `M` is multiplicatively
equivalent to the type of continuous linear equivalences between `M` and itself. -/
def unitsEquiv : (M →L[R] M)ˣ ≃* M ≃L[R] M where
toFun := ofUnit
invFun := toUnit
map_mul' x y := by
ext
rfl
@[simp]
theorem unitsEquiv_apply (f : (M →L[R] M)ˣ) (x : M) : unitsEquiv R M f x = (f : M →L[R] M) x :=
rfl
end Aut
section AutRing
/-!
### Units of a ring as linear automorphisms
-/
variable (R : Type*) [Semiring R] [TopologicalSpace R] [ContinuousMul R]
/-- Continuous linear equivalences `R ≃L[R] R` are enumerated by `Rˣ`. -/
def unitsEquivAut : Rˣ ≃ R ≃L[R] R where
toFun u :=
equivOfInverse (ContinuousLinearMap.smulRight (1 : R →L[R] R) ↑u)
(ContinuousLinearMap.smulRight (1 : R →L[R] R) ↑u⁻¹) (fun x => by simp) fun x => by simp
invFun e :=
⟨e 1, e.symm 1, by rw [← smul_eq_mul, ← map_smul, smul_eq_mul, mul_one, symm_apply_apply], by
rw [← smul_eq_mul, ← map_smul, smul_eq_mul, mul_one, apply_symm_apply]⟩
left_inv u := Units.ext <| by simp
right_inv e := ext₁ <| by simp
variable {R}
@[simp]
theorem unitsEquivAut_apply (u : Rˣ) (x : R) : unitsEquivAut R u x = x * u :=
rfl
@[simp]
theorem unitsEquivAut_apply_symm (u : Rˣ) (x : R) : (unitsEquivAut R u).symm x = x * ↑u⁻¹ :=
rfl
@[simp]
theorem unitsEquivAut_symm_apply (e : R ≃L[R] R) : ↑((unitsEquivAut R).symm e) = e 1 :=
rfl
end AutRing
section Pi
variable (ι R M : Type*) [Unique ι] [Semiring R] [AddCommMonoid M] [Module R M]
[TopologicalSpace M]
/-- If `ι` has a unique element, then `ι → M` is continuously linear equivalent to `M`. -/
def funUnique : (ι → M) ≃L[R] M :=
{ Homeomorph.funUnique ι M with toLinearEquiv := LinearEquiv.funUnique ι R M }
variable {ι R M}
@[simp]
theorem coe_funUnique : ⇑(funUnique ι R M) = Function.eval default :=
rfl
@[simp]
theorem coe_funUnique_symm : ⇑(funUnique ι R M).symm = Function.const ι :=
rfl
variable (R M)
/-- Continuous linear equivalence between dependent functions `(i : Fin 2) → M i` and `M 0 × M 1`.
-/
@[simps! -fullyApplied apply symm_apply]
def piFinTwo (M : Fin 2 → Type*) [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
[∀ i, TopologicalSpace (M i)] : ((i : _) → M i) ≃L[R] M 0 × M 1 :=
{ Homeomorph.piFinTwo M with toLinearEquiv := LinearEquiv.piFinTwo R M }
/-- Continuous linear equivalence between vectors in `M² = Fin 2 → M` and `M × M`. -/
@[simps! -fullyApplied apply symm_apply]
def finTwoArrow : (Fin 2 → M) ≃L[R] M × M :=
{ piFinTwo R fun _ => M with toLinearEquiv := LinearEquiv.finTwoArrow R M }
section
variable {n : ℕ} {R : Type*} {M : Fin n.succ → Type*} {N : Type*}
variable [Semiring R]
variable [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] [∀ i, TopologicalSpace (M i)]
variable (R M) in
/-- `Fin.consEquiv` as a continuous linear equivalence. -/
@[simps!]
def _root_.Fin.consEquivL : (M 0 × Π i, M (Fin.succ i)) ≃L[R] (Π i, M i) where
__ := Fin.consLinearEquiv R M
continuous_toFun := continuous_id.fst.finCons continuous_id.snd
continuous_invFun := .prodMk (continuous_apply 0) (by continuity)
/-- `Fin.cons` in the codomain of continuous linear maps. -/
abbrev _root_.ContinuousLinearMap.finCons
[AddCommMonoid N] [Module R N] [TopologicalSpace N]
(f : N →L[R] M 0) (fs : N →L[R] Π i, M (Fin.succ i)) :
N →L[R] Π i, M i :=
Fin.consEquivL R M ∘L f.prod fs
end
end Pi
section AddCommGroup
variable {R : Type*} [Semiring R] {M : Type*} [TopologicalSpace M] [AddCommGroup M] {M₂ : Type*}
[TopologicalSpace M₂] [AddCommGroup M₂] {M₃ : Type*} [TopologicalSpace M₃] [AddCommGroup M₃]
{M₄ : Type*} [TopologicalSpace M₄] [AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃]
[Module R M₄]
variable [IsTopologicalAddGroup M₄]
/-- Equivalence given by a block lower diagonal matrix. `e` and `e'` are diagonal square blocks,
and `f` is a rectangular block below the diagonal. -/
def skewProd (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[R] M₄) : (M × M₃) ≃L[R] M₂ × M₄ :=
{ e.toLinearEquiv.skewProd e'.toLinearEquiv ↑f with
continuous_toFun :=
(e.continuous_toFun.comp continuous_fst).prodMk
((e'.continuous_toFun.comp continuous_snd).add <| f.continuous.comp continuous_fst)
continuous_invFun :=
(e.continuous_invFun.comp continuous_fst).prodMk
(e'.continuous_invFun.comp <|
continuous_snd.sub <| f.continuous.comp <| e.continuous_invFun.comp continuous_fst) }
@[simp]
theorem skewProd_apply (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[R] M₄) (x) :
e.skewProd e' f x = (e x.1, e' x.2 + f x.1) :=
rfl
@[simp]
theorem skewProd_symm_apply (e : M ≃L[R] M₂) (e' : M₃ ≃L[R] M₄) (f : M →L[R] M₄) (x) :
(e.skewProd e' f).symm x = (e.symm x.1, e'.symm (x.2 - f (e.symm x.1))) :=
rfl
variable (R) in
/-- The negation map as a continuous linear equivalence. -/
def neg [ContinuousNeg M] :
M ≃L[R] M :=
{ LinearEquiv.neg R with
continuous_toFun := continuous_neg
continuous_invFun := continuous_neg }
@[simp]
theorem coe_neg [ContinuousNeg M] :
(neg R : M → M) = -id := rfl
@[simp]
theorem neg_apply [ContinuousNeg M] (x : M) :
neg R x = -x := by simp
@[simp]
theorem symm_neg [ContinuousNeg M] :
(neg R : M ≃L[R] M).symm = neg R := rfl
end AddCommGroup
section Ring
variable {R : Type*} [Ring R] {R₂ : Type*} [Ring R₂] {M : Type*} [TopologicalSpace M]
[AddCommGroup M] [Module R M] {M₂ : Type*} [TopologicalSpace M₂] [AddCommGroup M₂] [Module R₂ M₂]
variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R} [RingHomInvPair σ₁₂ σ₂₁] [RingHomInvPair σ₂₁ σ₁₂]
theorem map_sub (e : M ≃SL[σ₁₂] M₂) (x y : M) : e (x - y) = e x - e y :=
(e : M →SL[σ₁₂] M₂).map_sub x y
theorem map_neg (e : M ≃SL[σ₁₂] M₂) (x : M) : e (-x) = -e x :=
(e : M →SL[σ₁₂] M₂).map_neg x
variable [Module R M₂] [IsTopologicalAddGroup M]
/-- A pair of continuous linear maps such that `f₁ ∘ f₂ = id` generates a continuous
linear equivalence `e` between `M` and `M₂ × f₁.ker` such that `(e x).2 = x` for `x ∈ f₁.ker`,
`(e x).1 = f₁ x`, and `(e (f₂ y)).2 = 0`. The map is given by `e x = (f₁ x, x - f₂ (f₁ x))`. -/
def equivOfRightInverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M) (h : Function.RightInverse f₂ f₁) :
M ≃L[R] M₂ × ker f₁ :=
equivOfInverse (f₁.prod (f₁.projKerOfRightInverse f₂ h)) (f₂.coprod (ker f₁).subtypeL)
(fun x => by simp) fun ⟨x, y⟩ => by simp [h x]
@[simp]
theorem fst_equivOfRightInverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : Function.RightInverse f₂ f₁) (x : M) : (equivOfRightInverse f₁ f₂ h x).1 = f₁ x :=
rfl
@[simp]
theorem snd_equivOfRightInverse (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : Function.RightInverse f₂ f₁) (x : M) :
((equivOfRightInverse f₁ f₂ h x).2 : M) = x - f₂ (f₁ x) :=
rfl
@[simp]
theorem equivOfRightInverse_symm_apply (f₁ : M →L[R] M₂) (f₂ : M₂ →L[R] M)
(h : Function.RightInverse f₂ f₁) (y : M₂ × ker f₁) :
(equivOfRightInverse f₁ f₂ h).symm y = f₂ y.1 + y.2 :=
rfl
end Ring
end ContinuousLinearEquiv
namespace ContinuousLinearMap
variable {R : Type*} {M M₂ M₃ : Type*}
[TopologicalSpace M] [TopologicalSpace M₂] [TopologicalSpace M₃]
variable [Semiring R]
[AddCommMonoid M] [Module R M]
[AddCommMonoid M₂] [Module R M₂]
[AddCommMonoid M₃] [Module R M₃]
/-- A continuous linear map is invertible if it is the forward direction of a continuous linear
equivalence. -/
def IsInvertible (f : M →L[R] M₂) : Prop :=
∃ (A : M ≃L[R] M₂), A = f
open Classical in
/-- Introduce a function `inverse` from `M →L[R] M₂` to `M₂ →L[R] M`, which sends `f` to `f.symm` if
`f` is a continuous linear equivalence and to `0` otherwise. This definition is somewhat ad hoc,
but one needs a fully (rather than partially) defined inverse function for some purposes, including
for calculus. -/
noncomputable def inverse : (M →L[R] M₂) → M₂ →L[R] M := fun f =>
if h : f.IsInvertible then ((Classical.choose h).symm : M₂ →L[R] M) else 0
@[simp] lemma isInvertible_equiv {f : M ≃L[R] M₂} : IsInvertible (f : M →L[R] M₂) := ⟨f, rfl⟩
/-- By definition, if `f` is invertible then `inverse f = f.symm`. -/
@[simp]
theorem inverse_equiv (e : M ≃L[R] M₂) : inverse (e : M →L[R] M₂) = e.symm := by
simp [inverse]
/-- By definition, if `f` is not invertible then `inverse f = 0`. -/
@[simp] lemma inverse_of_not_isInvertible
{f : M →L[R] M₂} (hf : ¬ f.IsInvertible) : f.inverse = 0 :=
dif_neg hf
@[simp]
theorem isInvertible_zero_iff :
IsInvertible (0 : M →L[R] M₂) ↔ Subsingleton M ∧ Subsingleton M₂ := by
refine ⟨fun ⟨e, he⟩ ↦ ?_, ?_⟩
· have A : Subsingleton M := by
refine ⟨fun x y ↦ e.injective ?_⟩
simp [he, ← ContinuousLinearEquiv.coe_coe]
exact ⟨A, e.toEquiv.symm.subsingleton⟩
· rintro ⟨hM, hM₂⟩
let e : M ≃L[R] M₂ :=
{ toFun := 0
invFun := 0
left_inv x := Subsingleton.elim _ _
right_inv x := Subsingleton.elim _ _
map_add' x y := Subsingleton.elim _ _
map_smul' c x := Subsingleton.elim _ _ }
refine ⟨e, ?_⟩
ext x
exact Subsingleton.elim _ _
@[simp] theorem inverse_zero : inverse (0 : M →L[R] M₂) = 0 := by
by_cases h : IsInvertible (0 : M →L[R] M₂)
· rcases isInvertible_zero_iff.1 h with ⟨hM, hM₂⟩
ext x
exact Subsingleton.elim _ _
· exact inverse_of_not_isInvertible h
lemma IsInvertible.comp {g : M₂ →L[R] M₃} {f : M →L[R] M₂}
(hg : g.IsInvertible) (hf : f.IsInvertible) : (g ∘L f).IsInvertible := by
rcases hg with ⟨N, rfl⟩
rcases hf with ⟨M, rfl⟩
exact ⟨M.trans N, rfl⟩
lemma IsInvertible.of_inverse {f : M →L[R] M₂} {g : M₂ →L[R] M}
(hf : f ∘L g = id R M₂) (hg : g ∘L f = id R M) :
f.IsInvertible :=
⟨ContinuousLinearEquiv.equivOfInverse' _ _ hf hg, rfl⟩
lemma inverse_eq {f : M →L[R] M₂} {g : M₂ →L[R] M} (hf : f ∘L g = id R M₂) (hg : g ∘L f = id R M) :
f.inverse = g := by
have : f = ContinuousLinearEquiv.equivOfInverse' f g hf hg := rfl
rw [this, inverse_equiv]
rfl
lemma IsInvertible.inverse_apply_eq {f : M →L[R] M₂} {x : M} {y : M₂} (hf : f.IsInvertible) :
f.inverse y = x ↔ y = f x := by
rcases hf with ⟨M, rfl⟩
simp only [inverse_equiv, ContinuousLinearEquiv.coe_coe]
exact ContinuousLinearEquiv.symm_apply_eq M
@[simp] lemma isInvertible_equiv_comp {e : M₂ ≃L[R] M₃} {f : M →L[R] M₂} :
((e : M₂ →L[R] M₃) ∘L f).IsInvertible ↔ f.IsInvertible := by
constructor
· rintro ⟨A, hA⟩
have : f = e.symm ∘L ((e : M₂ →L[R] M₃) ∘L f) := by ext; simp
rw [this, ← hA]
simp
· rintro ⟨M, rfl⟩
simp
@[simp] lemma isInvertible_comp_equiv {e : M₃ ≃L[R] M} {f : M →L[R] M₂} :
(f ∘L (e : M₃ →L[R] M)).IsInvertible ↔ f.IsInvertible := by
constructor
· rintro ⟨A, hA⟩
have : f = (f ∘L (e : M₃ →L[R] M)) ∘L e.symm := by ext; simp
rw [this, ← hA]
simp
· rintro ⟨M, rfl⟩
simp
@[simp] lemma inverse_equiv_comp {e : M₂ ≃L[R] M₃} {f : M →L[R] M₂} :
(e ∘L f).inverse = f.inverse ∘L (e.symm : M₃ →L[R] M₂) := by
by_cases hf : f.IsInvertible
· rcases hf with ⟨A, rfl⟩
simp only [ContinuousLinearEquiv.comp_coe, inverse_equiv, ContinuousLinearEquiv.coe_inj]
rfl
· rw [inverse_of_not_isInvertible (by simp [hf]), inverse_of_not_isInvertible hf, zero_comp]
@[simp] lemma inverse_comp_equiv {e : M₃ ≃L[R] M} {f : M →L[R] M₂} :
(f ∘L e).inverse = (e.symm : M →L[R] M₃) ∘L f.inverse := by
by_cases hf : f.IsInvertible
· rcases hf with ⟨A, rfl⟩
simp only [ContinuousLinearEquiv.comp_coe, inverse_equiv, ContinuousLinearEquiv.coe_inj]
rfl
· rw [inverse_of_not_isInvertible (by simp [hf]), inverse_of_not_isInvertible hf, comp_zero]
lemma IsInvertible.inverse_comp_of_left {g : M₂ →L[R] M₃} {f : M →L[R] M₂}
(hg : g.IsInvertible) : (g ∘L f).inverse = f.inverse ∘L g.inverse := by
rcases hg with ⟨N, rfl⟩
simp
lemma IsInvertible.inverse_comp_apply_of_left {g : M₂ →L[R] M₃} {f : M →L[R] M₂} {v : M₃}
(hg : g.IsInvertible) : (g ∘L f).inverse v = f.inverse (g.inverse v) := by
simp only [hg.inverse_comp_of_left, coe_comp', Function.comp_apply]
lemma IsInvertible.inverse_comp_of_right {g : M₂ →L[R] M₃} {f : M →L[R] M₂}
(hf : f.IsInvertible) : (g ∘L f).inverse = f.inverse ∘L g.inverse := by
rcases hf with ⟨M, rfl⟩
simp
lemma IsInvertible.inverse_comp_apply_of_right {g : M₂ →L[R] M₃} {f : M →L[R] M₂} {v : M₃}
(hf : f.IsInvertible) : (g ∘L f).inverse v = f.inverse (g.inverse v) := by
simp only [hf.inverse_comp_of_right, coe_comp', Function.comp_apply]
@[simp]
theorem ringInverse_equiv (e : M ≃L[R] M) : Ring.inverse ↑e = inverse (e : M →L[R] M) := by
suffices Ring.inverse ((ContinuousLinearEquiv.unitsEquiv _ _).symm e : M →L[R] M) = inverse ↑e by
convert this
simp
rfl
@[deprecated (since := "2025-04-22")] alias ring_inverse_equiv := ringInverse_equiv
/-- The function `ContinuousLinearEquiv.inverse` can be written in terms of `Ring.inverse` for the
ring of self-maps of the domain. -/
theorem inverse_eq_ringInverse (e : M ≃L[R] M₂) (f : M →L[R] M₂) :
inverse f = Ring.inverse ((e.symm : M₂ →L[R] M).comp f) ∘L e.symm := by
by_cases h₁ : f.IsInvertible
· obtain ⟨e', he'⟩ := h₁
rw [← he']
change _ = Ring.inverse (e'.trans e.symm : M →L[R] M) ∘L (e.symm : M₂ →L[R] M)
ext
simp
· suffices ¬IsUnit ((e.symm : M₂ →L[R] M).comp f) by simp [this, h₁]
contrapose! h₁
rcases h₁ with ⟨F, hF⟩
use (ContinuousLinearEquiv.unitsEquiv _ _ F).trans e
ext
dsimp
rw [hF]
simp
@[deprecated (since := "2025-04-22")] alias to_ring_inverse := inverse_eq_ringInverse
theorem ringInverse_eq_inverse : Ring.inverse = inverse (R := R) (M := M) := by
ext
simp [inverse_eq_ringInverse (ContinuousLinearEquiv.refl R M)]
@[deprecated (since := "2025-04-22")]
alias ring_inverse_eq_map_inverse := ringInverse_eq_inverse
@[simp] theorem inverse_id : (id R M).inverse = id R M := by
rw [← ringInverse_eq_inverse]
exact Ring.inverse_one _
/-- Composition of a map on a product with the exchange of the product factors -/
theorem coprod_comp_prodComm [ContinuousAdd M] (f : M₂ →L[R] M) (g : M₃ →L[R] M) :
f.coprod g ∘L ContinuousLinearEquiv.prodComm R M₃ M₂ = g.coprod f := by
ext <;> simp
end ContinuousLinearMap
namespace Submodule
variable {R : Type*} [Ring R] {M : Type*} [TopologicalSpace M] [AddCommGroup M] [Module R M]
open ContinuousLinearMap
/-- If `p` is a closed complemented submodule,
then there exists a submodule `q` and a continuous linear equivalence `M ≃L[R] (p × q)` such that
`e (x : p) = (x, 0)`, `e (y : q) = (0, y)`, and `e.symm x = x.1 + x.2`.
In fact, the properties of `e` imply the properties of `e.symm` and vice versa,
but we provide both for convenience. -/
lemma ClosedComplemented.exists_submodule_equiv_prod [IsTopologicalAddGroup M]
{p : Submodule R M} (hp : p.ClosedComplemented) :
∃ (q : Submodule R M) (e : M ≃L[R] (p × q)),
(∀ x : p, e x = (x, 0)) ∧ (∀ y : q, e y = (0, y)) ∧ (∀ x, e.symm x = x.1 + x.2) :=
let ⟨f, hf⟩ := hp
⟨LinearMap.ker f, .equivOfRightInverse _ p.subtypeL hf,
fun _ ↦ by ext <;> simp [hf], fun _ ↦ by ext <;> simp, fun _ ↦ rfl⟩
end Submodule
namespace MulOpposite
variable (R : Type*) [Semiring R] [τR : TopologicalSpace R] [IsTopologicalSemiring R]
{M : Type*} [AddCommMonoid M] [Module R M] [TopologicalSpace M] [ContinuousSMul R M]
/-- The function `op` is a continuous linear equivalence. -/
@[simps!]
def opContinuousLinearEquiv : M ≃L[R] Mᵐᵒᵖ where
__ := MulOpposite.opLinearEquiv R
end MulOpposite
end
|
fieldext.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div.
From mathcomp Require Import choice fintype tuple finfun bigop ssralg countalg.
From mathcomp Require Import finalg zmodp matrix vector falgebra poly polydiv.
From mathcomp Require Import mxpoly generic_quotient.
(******************************************************************************)
(* Finite dimensional field extensions *)
(* *)
(* fieldExtType F == the interface type for finite field extensions of F *)
(* it simply combines the fieldType and falgType F *)
(* interfaces *)
(* The HB class is called FieldExt. *)
(* {subfield L} == the type of subfields of L that are also extensions *)
(* of F; since we are in a finite dimensional setting *)
(* these are exactly the F-subalgebras of L, and *)
(* indeed {subfield L} is just display notation for *)
(* {aspace L} when L is an extFieldType *)
(* --> All aspace operations apply to {subfield L}, but there are several *)
(* additional lemmas and canonical instances specific to {subfield L} *)
(* spaces, e.g., subvs_of E is an extFieldType F when E : {subfield L}. *)
(* --> Also note that not all constructive subfields have type {subfield E} *)
(* in the same way that not all constructive subspaces have type *)
(* {vspace E}. These types only include the so called "detachable" *)
(* subspaces (and subalgebras). *)
(* *)
(* (E :&: F)%AS, (E * F)%AS == the intersection and product (meet and join) *)
(* of E and F as subfields *)
(* subFExtend iota z p == given a field morphism iota : F -> L, this is a *)
(* type for the field F^iota(z) obtained by *)
(* adjoining z to the image of F in L under iota *)
(* The construction requires a non-zero polynomial *)
(* p in F such that z is a root of p^iota; it *)
(* returns the field F^iota if this is not so. *)
(* However, p need not be irredicible. *)
(* subfx_inj x == the injection of F^iota(z) into L *)
(* inj_subfx iota z p x == the injection of F into F^iota(z) *)
(* subfx_eval iota z p q == given q : {poly F} returns q.[z] as a value of *)
(* type F^iota(z) *)
(* subfx_root iota z p == the generator of F^iota(z) over F *)
(* SubFieldExtType pz0 irr_p == a fieldExtType F structure for F^iota(z) *)
(* (more precisely, subFExtend iota z p), given *)
(* proofs pz0: root (map_poly iota p) z and *)
(* irr_p : irreducible_poly p. *)
(* The corresponding vectType substructure *)
(* (SubfxVectType pz0 irr_p) has dimension *)
(* (size p).-1 over F. *)
(* minPoly K x == the monic minimal polynomial of x over the *)
(* subfield K *)
(* adjoin_degree K x == the degree of the minimal polynomial or the *)
(* dimension of K(x)/K *)
(* Fadjoin_poly K x y == a polynomial p over K such that y = p.[x] *)
(* *)
(* fieldOver F == L, but with an extFieldType (subvs_of F) *)
(* structure, for F : {subfield L} *)
(* vspaceOver F V == the smallest subspace of fieldOver F containing *)
(* V; this coincides with V if V is an F-module *)
(* baseFieldType L == L, but with an extFieldType F0 structure, when L *)
(* has a canonical extFieldType F structure and F *)
(* in turn has an extFieldType F0 structure *)
(* baseVspace V == the subspace of baseFieldType L that coincides *)
(* with V : {vspace L} *)
(* --> Some caution must be exercised when using fieldOver and baseFieldType, *)
(* because these are convertible to L while carrying different Lmodule *)
(* structures. This means that the safeguards engineered in the ssralg *)
(* library that normally curb the Coq kernel's inclination to diverge are *)
(* no longer effectcive, so additional precautions should be taken when *)
(* matching or rewriting terms of the form a *: u, because Coq may take *)
(* forever to realize it's dealing with a *: in the wrong structure. The *)
(* baseField_scaleE and fieldOver_scaleE lemmas should be used to expand *)
(* or fold such "trans-structure" operations explicitly beforehand. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import GRing.Theory.
#[short(type="fieldExtType")]
HB.structure Definition FieldExt (R : nzRingType) := {T of Falgebra R T &
GRing.PzRing_hasCommutativeMul T & GRing.Field T}.
Module FieldExtExports.
Bind Scope ring_scope with FieldExt.sort.
Notation "{ 'subfield' L }" := (aspace L)
(* NB: was (@aspace_of _ (FalgType _) (Phant L)) *)
(format "{ 'subfield' L }") : type_scope.
End FieldExtExports.
HB.export FieldExtExports.
(* FIXME: strange way to build a FieldExt *)
HB.instance Definition _ (F : fieldType) := GRing.Field.on F^o.
Section FieldExtTheory.
Variables (F0 : fieldType) (L : fieldExtType F0).
Implicit Types (U V M : {vspace L}) (E F K : {subfield L}).
Lemma dim_cosetv U x : x != 0 -> \dim (U * <[x]>) = \dim U.
Proof.
move=> nz_x; rewrite -limg_amulr limg_dim_eq //.
apply/eqP; rewrite -subv0; apply/subvP=> y.
by rewrite memv_cap memv0 memv_ker lfunE mulf_eq0 (negPf nz_x) orbF => /andP[].
Qed.
Lemma prodvC : commutative (@prodv F0 L).
Proof.
move=> U V; without loss suffices subC: U V / (U * V <= V * U)%VS.
by apply/eqP; rewrite eqEsubv !{1}subC.
by apply/prodvP=> x y Ux Vy; rewrite mulrC memv_mul.
Qed.
HB.instance Definition _ :=
SemiGroup.isCommutativeLaw.Build {vspace L} (@prodv _ L) prodvC.
Lemma prodvCA : left_commutative (@prodv F0 L).
Proof. exact: Monoid.mulmCA. Qed.
Lemma prodvAC : right_commutative (@prodv F0 L).
Proof. exact: Monoid.mulmAC. Qed.
Lemma algid1 K : algid K = 1. Proof. exact/skew_field_algid1/fieldP. Qed.
Lemma mem1v K : 1 \in K. Proof. by rewrite -algid_eq1 algid1. Qed.
Lemma sub1v K : (1 <= K)%VS. Proof. exact: mem1v. Qed.
Lemma subfield_closed K : agenv K = K.
Proof.
by apply/eqP; rewrite eqEsubv sub_agenv agenv_sub_modr ?sub1v ?asubv.
Qed.
Lemma AHom_lker0 (rT : falgType F0) (f : 'AHom(L, rT)) : lker f == 0%VS.
Proof. by apply/lker0P; apply: fmorph_inj. Qed.
Lemma AEnd_lker0 (f : 'AEnd(L)) : lker f == 0%VS. Proof. exact: AHom_lker0. Qed.
Fact aimg_is_aspace (rT : falgType F0) (f : 'AHom(L, rT)) (E : {subfield L}) :
is_aspace (f @: E).
Proof.
rewrite /is_aspace -aimgM limgS ?prodv_id // has_algid1 //.
by apply/memv_imgP; exists 1; rewrite ?mem1v ?rmorph1.
Qed.
Canonical aimg_aspace rT f E := ASpace (@aimg_is_aspace rT f E).
Lemma Fadjoin_idP {K x} : reflect (<<K; x>>%VS = K) (x \in K).
Proof.
apply: (iffP idP) => [/addv_idPl-> | <-]; first exact: subfield_closed.
exact: memv_adjoin.
Qed.
Lemma Fadjoin0 K : <<K; 0>>%VS = K.
Proof. by rewrite addv0 subfield_closed. Qed.
Lemma Fadjoin_nil K : <<K & [::]>>%VS = K.
Proof. by rewrite adjoin_nil subfield_closed. Qed.
Lemma FadjoinP {K x E} :
reflect (K <= E /\ x \in E)%VS (<<K; x>>%AS <= E)%VS.
Proof.
apply: (iffP idP) => [sKxE | /andP].
by rewrite (subvP sKxE) ?memv_adjoin // (subv_trans _ sKxE) ?subv_adjoin.
by rewrite -subv_add => /agenvS; rewrite subfield_closed.
Qed.
Lemma Fadjoin_seqP {K} {rs : seq L} {E} :
reflect (K <= E /\ {subset rs <= E})%VS (<<K & rs>> <= E)%VS.
Proof.
apply: (iffP idP) => [sKrsE | [sKE /span_subvP/(conj sKE)/andP]].
split=> [|x rs_x]; first exact: subv_trans (subv_adjoin_seq _ _) sKrsE.
by rewrite (subvP sKrsE) ?seqv_sub_adjoin.
by rewrite -subv_add => /agenvS; rewrite subfield_closed.
Qed.
Lemma alg_polyOver E p : map_poly (in_alg L) p \is a polyOver E.
Proof. by apply/(polyOverS (subvP (sub1v _)))/polyOver1P; exists p. Qed.
Lemma sub_adjoin1v x E : (<<1; x>> <= E)%VS = (x \in E)%VS.
Proof. by rewrite (sameP FadjoinP andP) sub1v. Qed.
Fact vsval_monoid_morphism K : monoid_morphism (vsval : subvs_of K -> L).
Proof. by split => //=; apply: algid1. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `subfx_eval_is_monoid_morphism` instead")]
Definition vsval_is_multiplicative K :=
(fun g => (g.2,g.1)) (vsval_monoid_morphism K).
HB.instance Definition _ (K : {subfield L}) :=
GRing.isMonoidMorphism.Build (subvs_of K) L vsval (vsval_monoid_morphism K).
Lemma vsval_invf K (w : subvs_of K) : val w^-1 = (vsval w)^-1.
Proof.
have [-> | Uv] := eqVneq w 0; first by rewrite !invr0.
by apply: vsval_invr; rewrite unitfE.
Qed.
Fact aspace_divr_closed K : divr_closed K.
Proof. by split=> [|u v Ku Kv]; rewrite ?mem1v ?memvM ?memvV. Qed.
HB.instance Definition _ K :=
GRing.isDivClosed.Build L (pred_of_vspace K) (aspace_divr_closed K).
HB.instance Definition _ (K : {subfield L}) :=
GRing.isSubPzSemiRing.Build L (pred_of_vspace K) (subvs_of K)
(rmorph1 _, rmorphM _).
(* Note that the nzRingType structure was built in the SubFalgType
section of falgebra.v but the SubRing structure did not stand
there, it is thus built only here *)
HB.instance Definition _ (K : {subfield L}) :=
[SubNzRing_isSubComNzRing of subvs_of K by <:].
HB.instance Definition _ (K : {subfield L}) :=
[SubComUnitRing_isSubIntegralDomain of subvs_of K by <:].
Lemma subvs_fieldMixin K : GRing.field_axiom (subvs_of K).
Proof.
by move=> w nz_w; rewrite unitrE -val_eqE /= vsval_invf algid1 divff.
Qed.
HB.instance Definition _ K := GRing.UnitRing_isField.Build (subvs_of K)
(@subvs_fieldMixin K).
Lemma polyOver_subvs {K} {p : {poly L}} :
reflect (exists q : {poly subvs_of K}, p = map_poly vsval q)
(p \is a polyOver K).
Proof.
apply: (iffP polyOverP) => [Hp | [q ->] i]; last by rewrite coef_map // subvsP.
exists (\poly_(i < size p) (Subvs (Hp i))); rewrite -{1}[p]coefK.
by apply/polyP=> i; rewrite coef_map !coef_poly; case: ifP.
Qed.
Lemma divp_polyOver K : {in polyOver K &, forall p q, p %/ q \is a polyOver K}.
Proof.
move=> _ _ /polyOver_subvs[p ->] /polyOver_subvs[q ->].
by apply/polyOver_subvs; exists (p %/ q); rewrite map_divp.
Qed.
Lemma modp_polyOver K : {in polyOver K &, forall p q, p %% q \is a polyOver K}.
Proof.
move=> _ _ /polyOver_subvs[p ->] /polyOver_subvs[q ->].
by apply/polyOver_subvs; exists (p %% q); rewrite map_modp.
Qed.
Lemma gcdp_polyOver K :
{in polyOver K &, forall p q, gcdp p q \is a polyOver K}.
Proof.
move=> _ _ /polyOver_subvs[p ->] /polyOver_subvs[q ->].
by apply/polyOver_subvs; exists (gcdp p q); rewrite gcdp_map.
Qed.
Fact prodv_is_aspace E F : is_aspace (E * F).
Proof.
rewrite /is_aspace prodvCA -!prodvA prodvA !prodv_id has_algid1 //=.
by rewrite -[1]mulr1 memv_mul ?mem1v.
Qed.
Canonical prodv_aspace E F : {subfield L} := ASpace (prodv_is_aspace E F).
Fact field_mem_algid E F : algid E \in F. Proof. by rewrite algid1 mem1v. Qed.
Canonical capv_aspace E F : {subfield L} := aspace_cap (field_mem_algid E F).
Lemma polyOverSv U V : (U <= V)%VS -> {subset polyOver U <= polyOver V}.
Proof. by move/subvP=> sUV; apply: polyOverS. Qed.
Lemma field_subvMl F U : (U <= F * U)%VS.
Proof. by rewrite -{1}[U]prod1v prodvSl ?sub1v. Qed.
Lemma field_subvMr U F : (U <= U * F)%VS.
Proof. by rewrite prodvC field_subvMl. Qed.
Lemma field_module_eq F M : (F * M <= M)%VS -> (F * M)%VS = M.
Proof. by move=> modM; apply/eqP; rewrite eqEsubv modM field_subvMl. Qed.
Lemma sup_field_module F E : (F * E <= E)%VS = (F <= E)%VS.
Proof.
apply/idP/idP; first exact: subv_trans (field_subvMr F E).
by move/(prodvSl E)/subv_trans->; rewrite ?asubv.
Qed.
Lemma field_module_dimS F M : (F * M <= M)%VS -> (\dim F %| \dim M)%N.
Proof. exact/skew_field_module_dimS/fieldP. Qed.
Lemma field_dimS F E : (F <= E)%VS -> (\dim F %| \dim E)%N.
Proof. exact/skew_field_dimS/fieldP. Qed.
Lemma dim_field_module F M : (F * M <= M)%VS -> \dim M = (\dim_F M * \dim F)%N.
Proof. by move/field_module_dimS/divnK. Qed.
Lemma dim_sup_field F E : (F <= E)%VS -> \dim E = (\dim_F E * \dim F)%N.
Proof. by move/field_dimS/divnK. Qed.
Lemma field_module_semisimple F M (m := \dim_F M) :
(F * M <= M)%VS ->
{X : m.-tuple L | {subset X <= M} /\ 0 \notin X
& let FX := (\sum_(i < m) F * <[X`_i]>)%VS in FX = M /\ directv FX}.
Proof.
move=> modM; have dimM: (m * \dim F)%N = \dim M by rewrite -dim_field_module.
have [X [defM dxFX nzX]] := skew_field_module_semisimple (@fieldP L) modM.
have szX: size X == m.
rewrite -(eqn_pmul2r (adim_gt0 F)) dimM -defM (directvP dxFX) /=.
rewrite -sum1_size big_distrl; apply/eqP/eq_big_seq => x Xx /=.
by rewrite mul1n dim_cosetv ?(memPn nzX).
rewrite directvE /= (big_nth 0) [eqbRHS](big_nth 0) in defM dxFX.
rewrite (eqP szX) !big_mkord -directvE in defM dxFX.
exists (Tuple szX) => //; split=> // _ /tnthP[i ->]; rewrite (tnth_nth 0) /=.
by rewrite -defM memvE (sumv_sup i) ?field_subvMl.
Qed.
Section FadjoinPolyDefinitions.
Variables (U : {vspace L}) (x : L).
Definition adjoin_degree := (\dim_U <<U; x>>).-1.+1.
Local Notation n := adjoin_degree.
Definition Fadjoin_sum := (\sum_(i < n) U * <[x ^+ i]>)%VS.
Definition Fadjoin_poly v : {poly L} :=
\poly_(i < n) (sumv_pi Fadjoin_sum (inord i) v / x ^+ i).
Definition minPoly : {poly L} := 'X^n - Fadjoin_poly (x ^+ n).
Lemma size_Fadjoin_poly v : size (Fadjoin_poly v) <= n.
Proof. exact: size_poly. Qed.
Lemma Fadjoin_polyOver v : Fadjoin_poly v \is a polyOver U.
Proof.
apply/(all_nthP 0) => i _; rewrite coef_poly /=.
case: ifP => lti; last exact: mem0v.
have /memv_cosetP[y Uy ->] := memv_sum_pi (erefl Fadjoin_sum) (inord i) v.
rewrite inordK //; have [-> | /mulfK-> //] := eqVneq (x ^+ i) 0.
by rewrite mulr0 mul0r mem0v.
Qed.
Fact Fadjoin_poly_is_linear : linear_for (in_alg L \; *:%R) Fadjoin_poly.
Proof.
move=> a u v; apply/polyP=> i; rewrite coefD coefZ !coef_poly.
case: ifP => lti; last by rewrite mulr0 addr0.
by rewrite linearP mulrA -mulrDl mulr_algl.
Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build F0 L {poly L} _ Fadjoin_poly
(GRing.semilinear_linear Fadjoin_poly_is_linear).
Lemma size_minPoly : size minPoly = n.+1.
Proof. by rewrite size_polyDl ?size_polyXn // size_polyN ltnS size_poly. Qed.
Lemma monic_minPoly : minPoly \is monic.
Proof.
rewrite monicE /lead_coef size_minPoly coefB coefXn eqxx.
by rewrite nth_default ?subr0 ?size_poly.
Qed.
End FadjoinPolyDefinitions.
Section FadjoinPoly.
Variables (K : {subfield L}) (x : L).
Local Notation n := (adjoin_degree (asval K) x).
Local Notation sumKx := (Fadjoin_sum (asval K) x).
Lemma adjoin_degreeE : n = \dim_K <<K; x>>.
Proof. by rewrite [n]prednK // divn_gt0 ?adim_gt0 // dimvS ?subv_adjoin. Qed.
Lemma dim_Fadjoin : \dim <<K; x>> = (n * \dim K)%N.
Proof. by rewrite adjoin_degreeE -dim_sup_field ?subv_adjoin. Qed.
Lemma adjoin0_deg : adjoin_degree K 0 = 1.
Proof. by rewrite /adjoin_degree addv0 subfield_closed divnn adim_gt0. Qed.
Lemma adjoin_deg_eq1 : (n == 1) = (x \in K).
Proof.
rewrite (sameP Fadjoin_idP eqP) adjoin_degreeE; have sK_Kx := subv_adjoin K x.
apply/eqP/idP=> [dimKx1 | /eqP->]; last by rewrite divnn adim_gt0.
by rewrite eq_sym eqEdim sK_Kx /= (dim_sup_field sK_Kx) dimKx1 mul1n.
Qed.
Lemma Fadjoin_sum_direct : directv sumKx.
Proof.
rewrite directvE /=; case: (ubnPgeq n) (isT : n > 0) => -[//|m] ltmn _.
elim: m ltmn => [|m IHm] ltm1n; rewrite ?big_ord1 // !(big_ord_recr m.+1) /=.
do [move/(_ (ltnW ltm1n))/eqP; set S := (\sum_i _)%VS] in IHm *.
rewrite -IHm dimv_add_leqif; apply/subvP=> z; rewrite memv_cap => /andP[Sz].
case/memv_cosetP=> y Ky Dz; rewrite memv0 Dz mulf_eq0 expf_eq0 /=.
apply: contraLR ltm1n => /norP[nz_y nz_x].
rewrite -leqNgt -(leq_pmul2r (adim_gt0 K)) -dim_Fadjoin.
have{IHm} ->: (m.+1 * \dim K)%N = \dim S.
rewrite -[m.+1]card_ord -sum_nat_const IHm.
by apply: eq_bigr => i; rewrite dim_cosetv ?expf_neq0.
apply/dimvS/agenv_sub_modl; first by rewrite (sumv_sup 0) //= prodv1 sub1v.
rewrite prodvDl subv_add -[S]big_distrr prodvA prodv_id subvv !big_distrr /=.
apply/subv_sumP=> i _; rewrite -expv_line prodvCA -expvSl expv_line.
have [ltim | lemi] := ltnP i m; first by rewrite (sumv_sup (Sub i.+1 _)).
have{lemi} /eqP->: i == m :> nat by rewrite eqn_leq leq_ord.
rewrite -big_distrr -2!{2}(prodv_id K) /= -!prodvA big_distrr -/S prodvSr //=.
by rewrite -(canLR (mulKf nz_y) Dz) -memvE memv_mul ?rpredV.
Qed.
Let nz_x_i (i : 'I_n) : x ^+ i != 0.
Proof.
by rewrite expf_eq0; case: eqP i => [->|_] [[]] //; rewrite adjoin0_deg.
Qed.
Lemma Fadjoin_eq_sum : <<K; x>>%VS = sumKx.
Proof.
apply/esym/eqP; rewrite eqEdim eq_leq ?andbT.
apply/subv_sumP=> i _; rewrite -agenvM prodvS ?subv_adjoin //.
by rewrite -expv_line (subv_trans (subX_agenv _ _)) ?agenvS ?addvSr.
rewrite dim_Fadjoin -[n]card_ord -sum_nat_const (directvP Fadjoin_sum_direct).
by apply: eq_bigr => i _; rewrite /= dim_cosetv.
Qed.
Lemma Fadjoin_poly_eq v : v \in <<K; x>>%VS -> (Fadjoin_poly K x v).[x] = v.
Proof.
move/(sumv_pi_sum Fadjoin_eq_sum)=> {2}<-; rewrite horner_poly.
by apply: eq_bigr => i _; rewrite inord_val mulfVK.
Qed.
Lemma mempx_Fadjoin p : p \is a polyOver K -> p.[x] \in <<K; x>>%VS.
Proof.
move=> Kp; rewrite rpred_horner ?memv_adjoin ?(polyOverS _ Kp) //.
exact: subvP_adjoin.
Qed.
Lemma Fadjoin_polyP {v} :
reflect (exists2 p, p \in polyOver K & v = p.[x]) (v \in <<K; x>>%VS).
Proof.
apply: (iffP idP) => [Kx_v | [p Kp ->]]; last exact: mempx_Fadjoin.
by exists (Fadjoin_poly K x v); rewrite ?Fadjoin_polyOver ?Fadjoin_poly_eq.
Qed.
Lemma Fadjoin_poly_unique p v :
p \is a polyOver K -> size p <= n -> p.[x] = v -> Fadjoin_poly K x v = p.
Proof.
have polyKx q i: q \is a polyOver K -> q`_i * x ^+ i \in (K * <[x ^+ i]>)%VS.
by move/polyOverP=> Kq; rewrite memv_mul ?Kq ?memv_line.
move=> Kp szp Dv; have /Fadjoin_poly_eq/eqP := mempx_Fadjoin Kp.
rewrite {1}Dv {Dv} !(@horner_coef_wide _ n) ?size_poly //.
move/polyKx in Kp; have /polyKx K_pv := Fadjoin_polyOver K x v.
rewrite (directv_sum_unique Fadjoin_sum_direct) // => /eqfunP eq_pq.
apply/polyP=> i; have [leni|?] := leqP n i; last exact: mulIf (eq_pq (Sub i _)).
by rewrite !nth_default ?(leq_trans _ leni) ?size_poly.
Qed.
Lemma Fadjoin_polyC v : v \in K -> Fadjoin_poly K x v = v%:P.
Proof.
move=> Kv; apply: Fadjoin_poly_unique; rewrite ?polyOverC ?hornerC //.
by rewrite size_polyC (leq_trans (leq_b1 _)).
Qed.
Lemma Fadjoin_polyX : x \notin K -> Fadjoin_poly K x x = 'X.
Proof.
move=> K'x; apply: Fadjoin_poly_unique; rewrite ?polyOverX ?hornerX //.
by rewrite size_polyX ltn_neqAle andbT eq_sym adjoin_deg_eq1.
Qed.
Lemma minPolyOver : minPoly K x \is a polyOver K.
Proof. by rewrite /minPoly rpredB ?rpredX ?polyOverX ?Fadjoin_polyOver. Qed.
Lemma minPolyxx : (minPoly K x).[x] = 0.
Proof.
by rewrite !hornerE Fadjoin_poly_eq ?subrr ?rpredX ?memv_adjoin.
Qed.
Lemma root_minPoly : root (minPoly K x) x. Proof. exact/rootP/minPolyxx. Qed.
Lemma Fadjoin_poly_mod p :
p \is a polyOver K -> Fadjoin_poly K x p.[x] = p %% minPoly K x.
Proof.
move=> Kp; rewrite {1}(divp_eq p (minPoly K x)) 2!hornerE minPolyxx mulr0 add0r.
apply: Fadjoin_poly_unique => //; first by rewrite modp_polyOver // minPolyOver.
by rewrite -ltnS -size_minPoly ltn_modp // monic_neq0 ?monic_minPoly.
Qed.
Lemma minPoly_XsubC : reflect (minPoly K x = 'X - x%:P) (x \in K).
Proof.
set p := minPoly K x; apply: (iffP idP) => [Kx | Dp]; last first.
suffices ->: x = - p`_0 by rewrite rpredN (polyOverP minPolyOver).
by rewrite Dp coefB coefX coefC add0r opprK.
rewrite (@all_roots_prod_XsubC _ p [:: x]) /= ?root_minPoly //.
by rewrite big_seq1 (monicP (monic_minPoly K x)) scale1r.
by apply/eqP; rewrite size_minPoly eqSS adjoin_deg_eq1.
Qed.
Lemma root_small_adjoin_poly p :
p \is a polyOver K -> size p <= n -> root p x = (p == 0).
Proof.
move=> Kp szp; apply/rootP/eqP=> [px0 | ->]; last by rewrite horner0.
rewrite -(Fadjoin_poly_unique Kp szp px0).
by apply: Fadjoin_poly_unique; rewrite ?polyOver0 ?size_poly0 ?horner0.
Qed.
Lemma minPoly_irr p :
p \is a polyOver K -> p %| minPoly K x -> (p %= minPoly K x) || (p %= 1).
Proof.
rewrite dvdp_eq; set q := _ %/ _ => Kp def_pq.
have Kq: q \is a polyOver K by rewrite divp_polyOver // minPolyOver.
move: q Kq def_pq root_minPoly (size_minPoly K x) => q Kq /eqP->.
rewrite rootM => pqx0 szpq.
have [nzq nzp]: q != 0 /\ p != 0.
by apply/norP; rewrite -mulf_eq0 -size_poly_eq0 szpq.
without loss{pqx0} qx0: q p Kp Kq nzp nzq szpq / root q x.
move=> IH; case/orP: pqx0 => /IH{}IH; first exact: IH.
have{IH} /orP[]: (q %= p * q) || (q %= 1) by apply: IH => //; rewrite mulrC.
by rewrite orbC -{1}[q]mul1r eqp_mul2r // eqp_sym => ->.
by rewrite -{1}[p]mul1r eqp_sym eqp_mul2r // => ->.
apply/orP; right; rewrite -size_poly_eq1 eqn_leq lt0n size_poly_eq0 nzp andbT.
rewrite -(leq_add2r (size q)) -leq_subLR subn1 -size_mul // mulrC szpq.
by rewrite ltnNge; apply: contra nzq => /(root_small_adjoin_poly Kq) <-.
Qed.
Lemma minPoly_dvdp p : p \is a polyOver K -> root p x -> (minPoly K x) %| p.
Proof.
move=> Kp rootp.
have gcdK : gcdp (minPoly K x) p \is a polyOver K.
by rewrite gcdp_polyOver ?minPolyOver.
have /orP[gcd_eqK|gcd_eq1] := minPoly_irr gcdK (dvdp_gcdl (minPoly K x) p).
by rewrite -(eqp_dvdl _ gcd_eqK) dvdp_gcdr.
case/negP: (root1 x).
by rewrite -(eqp_root gcd_eq1) root_gcd rootp root_minPoly.
Qed.
End FadjoinPoly.
Lemma minPolyS K E a : (K <= E)%VS -> minPoly E a %| minPoly K a.
Proof.
move=> sKE; apply: minPoly_dvdp; last exact: root_minPoly.
by apply: (polyOverSv sKE); rewrite minPolyOver.
Qed.
Arguments Fadjoin_polyP {K x v}.
Lemma Fadjoin1_polyP x v :
reflect (exists p, v = (map_poly (in_alg L) p).[x]) (v \in <<1; x>>%VS).
Proof.
apply: (iffP Fadjoin_polyP) => [[_ /polyOver1P]|] [p ->]; first by exists p.
by exists (map_poly (in_alg L) p) => //; apply: alg_polyOver.
Qed.
Section Horner.
Variables z : L.
Definition fieldExt_horner := horner_morph (fun x => mulrC z (in_alg L x)).
HB.instance Definition _ := GRing.RMorphism.on fieldExt_horner.
Lemma fieldExt_hornerC b : fieldExt_horner b%:P = b%:A.
Proof. exact: horner_morphC. Qed.
Lemma fieldExt_hornerX : fieldExt_horner 'X = z.
Proof. exact: horner_morphX. Qed.
Fact fieldExt_hornerZ : scalable fieldExt_horner.
Proof.
move=> a p; rewrite -mul_polyC rmorphM /= fieldExt_hornerC.
by rewrite -scalerAl mul1r.
Qed.
HB.instance Definition _ :=
GRing.isScalable.Build F0 {poly F0} L *:%R fieldExt_horner fieldExt_hornerZ.
End Horner.
End FieldExtTheory.
Notation "E :&: F" := (capv_aspace E F) : aspace_scope.
Notation "'C_ E [ x ]" := (capv_aspace E 'C[x]) : aspace_scope.
Notation "'C_ ( E ) [ x ]" := (capv_aspace E 'C[x])
(only parsing) : aspace_scope.
Notation "'C_ E ( V )" := (capv_aspace E 'C(V)) : aspace_scope.
Notation "'C_ ( E ) ( V )" := (capv_aspace E 'C(V))
(only parsing) : aspace_scope.
Notation "E * F" := (prodv_aspace E F) : aspace_scope.
Notation "f @: E" := (aimg_aspace f E) : aspace_scope.
Arguments Fadjoin_idP {F0 L K x}.
Arguments FadjoinP {F0 L K x E}.
Arguments Fadjoin_seqP {F0 L K rs E}.
Arguments polyOver_subvs {F0 L K p}.
Arguments Fadjoin_polyP {F0 L K x v}.
Arguments Fadjoin1_polyP {F0 L x v}.
Arguments minPoly_XsubC {F0 L K x}.
Section MapMinPoly.
Variables (F0 : fieldType) (L rL : fieldExtType F0) (f : 'AHom(L, rL)).
Variables (K : {subfield L}) (x : L).
Lemma adjoin_degree_aimg : adjoin_degree (f @: K) (f x) = adjoin_degree K x.
Proof.
rewrite !adjoin_degreeE -aimg_adjoin.
by rewrite !limg_dim_eq ?(eqP (AHom_lker0 f)) ?capv0.
Qed.
Lemma map_minPoly : map_poly f (minPoly K x) = minPoly (f @: K) (f x).
Proof.
set fp := minPoly (f @: K) (f x).
have [p Kp Dp]: exists2 p, p \is a polyOver K & map_poly f p = fp.
have Kfp: fp \is a polyOver (f @: K)%VS by apply: minPolyOver.
exists (map_poly f^-1%VF fp).
apply/polyOver_poly=> j _; have /memv_imgP[y Ky ->] := polyOverP Kfp j.
by rewrite lker0_lfunK ?AHom_lker0.
rewrite -map_poly_comp map_poly_id // => _ /(allP Kfp)/memv_imgP[y _ ->].
by rewrite /= limg_lfunVK ?memv_img ?memvf.
apply/eqP; rewrite -eqp_monic ?monic_map ?monic_minPoly // -Dp eqp_map.
have: ~~ (p %= 1) by rewrite -size_poly_eq1 -(size_map_poly f) Dp size_minPoly.
apply: implyP; rewrite implyNb orbC eqp_sym minPoly_irr //.
rewrite -(dvdp_map f) Dp minPoly_dvdp ?fmorph_root ?root_minPoly //.
by apply/polyOver_poly=> j _; apply/memv_img/polyOverP/minPolyOver.
Qed.
End MapMinPoly.
(* Changing up the reference field of a fieldExtType. *)
Section FieldOver.
Variables (F0 : fieldType) (L : fieldExtType F0) (F : {subfield L}).
Definition fieldOver of {vspace L} : Type := L.
Local Notation K_F := (subvs_of F).
Local Notation L_F := (fieldOver F).
HB.instance Definition _ := GRing.Field.on L_F.
Definition fieldOver_scale (a : K_F) (u : L_F) : L_F := vsval a * u.
Local Infix "*F:" := fieldOver_scale (at level 40).
Fact fieldOver_scaleA a b u : a *F: (b *F: u) = (a * b) *F: u.
Proof. exact: mulrA. Qed.
Fact fieldOver_scale1 u : 1 *F: u = u.
Proof. by rewrite /(1 *F: u) /= algid1 mul1r. Qed.
Fact fieldOver_scaleDr a u v : a *F: (u + v) = a *F: u + a *F: v.
Proof. exact: mulrDr. Qed.
Fact fieldOver_scaleDl v a b : (a + b) *F: v = a *F: v + b *F: v.
Proof. exact: mulrDl. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build _ L_F
fieldOver_scaleA fieldOver_scale1 fieldOver_scaleDr fieldOver_scaleDl.
Lemma fieldOver_scaleE a (u : L) : a *: (u : L_F) = vsval a * u.
Proof. by []. Qed.
Fact fieldOver_scaleAl a u v : a *F: (u * v) = (a *F: u) * v.
Proof. exact: mulrA. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build _ L_F
fieldOver_scaleAl.
Fact fieldOver_scaleAr a u v : a *F: (u * v) = u * (a *F: v).
Proof. exact: mulrCA. Qed.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build _ L_F
fieldOver_scaleAr.
Fact fieldOver_vectMixin : Lmodule_hasFinDim K_F L_F.
Proof.
have [bL [_ nz_bL] [defL dxSbL]] := field_module_semisimple (subvf (F * _)).
do [set n := \dim_F {:L} in bL nz_bL *; set SbL := (\sum_i _)%VS] in defL dxSbL.
have in_bL i (a : K_F) : val a * (bL`_i : L_F) \in (F * <[bL`_i]>)%VS.
by rewrite memv_mul ?(valP a) ?memv_line.
have nz_bLi (i : 'I_n): bL`_i != 0 by rewrite (memPn nz_bL) ?memt_nth.
pose r2v (v : 'rV[K_F]_n) : L_F := \sum_i v 0 i *: (bL`_i : L_F).
have r2v_lin: linear r2v.
move=> a u v; rewrite /r2v scaler_sumr -big_split /=; apply: eq_bigr => i _.
by rewrite scalerA -scalerDl !mxE.
pose r2vlM := GRing.isLinear.Build _ _ _ _ r2v r2v_lin.
pose r2vL : {linear _ -> _} := HB.pack r2v r2vlM.
have v2rP x: {r : 'rV[K_F]_n | x = r2v r}.
apply: sig_eqW; have /memv_sumP[y Fy ->]: x \in SbL by rewrite defL memvf.
have /fin_all_exists[r Dr] i: exists r, y i = r *: (bL`_i : L_F).
by have /memv_cosetP[a Fa ->] := Fy i isT; exists (Subvs Fa).
by exists (\row_i r i); apply: eq_bigr => i _; rewrite mxE.
pose v2r x := sval (v2rP x).
have v2rK: cancel v2r r2vL by rewrite /v2r => x; case: (v2rP x).
suffices r2vK: cancel r2v v2r.
by exists n, v2r; [apply: can2_linear v2rK | exists r2v].
move=> r; apply/rowP=> i; apply/val_inj/(mulIf (nz_bLi i))/eqP; move: i isT.
by apply/forall_inP; move/directv_sum_unique: dxSbL => <- //; apply/eqP/v2rK.
Qed.
HB.instance Definition _ := fieldOver_vectMixin.
Implicit Types (V : {vspace L}) (E : {subfield L}).
Lemma trivial_fieldOver : (1%VS : {vspace L_F}) =i F.
Proof.
move=> x; apply/vlineP/idP=> [[{}x ->] | Fx].
by rewrite fieldOver_scaleE mulr1 (valP x).
by exists (vsproj F x); rewrite fieldOver_scaleE mulr1 vsprojK.
Qed.
Definition vspaceOver V := <<vbasis V : seq L_F>>%VS.
Lemma mem_vspaceOver V : vspaceOver V =i (F * V)%VS.
Proof.
move=> y; apply/idP/idP; last rewrite unlock; move/coord_span->.
rewrite (@memv_suml F0 L) // => i _.
by rewrite memv_mul ?subvsP // vbasis_mem ?memt_nth.
rewrite memv_suml // => ij _; rewrite -tnth_nth; set x := tnth _ ij.
have/allpairsP[[u z] /= [Fu Vz {x}->]]: x \in _ := mem_tnth ij _.
by rewrite scalerAl (memvZ (Subvs _)) ?memvZ ?memv_span //= vbasis_mem.
Qed.
Lemma mem_aspaceOver E : (F <= E)%VS -> vspaceOver E =i E.
Proof.
by move=> sFE y; rewrite mem_vspaceOver field_module_eq ?sup_field_module.
Qed.
Fact aspaceOver_suproof E : is_aspace (vspaceOver E).
Proof.
rewrite /is_aspace has_algid1; last by rewrite mem_vspaceOver (@mem1v _ L).
by apply/prodvP=> u v; rewrite !mem_vspaceOver; apply: memvM.
Qed.
Canonical aspaceOver E := ASpace (aspaceOver_suproof E).
Lemma dim_vspaceOver M : (F * M <= M)%VS -> \dim (vspaceOver M) = \dim_F M.
Proof.
move=> modM; have [] := field_module_semisimple modM.
set n := \dim_F M => b [Mb nz_b] [defM dx_b].
suff: basis_of (vspaceOver M) b by apply: size_basis.
apply/andP; split.
rewrite eqEsubv; apply/andP; split; apply/span_subvP=> u.
by rewrite mem_vspaceOver field_module_eq // => /Mb.
move/(@vbasis_mem _ _ _ M); rewrite -defM => /memv_sumP[{}u Fu ->].
apply: memv_suml => i _; have /memv_cosetP[a Fa ->] := Fu i isT.
by apply: (memvZ (Subvs Fa)); rewrite memv_span ?memt_nth.
apply/freeP=> a /(directv_sum_independent dx_b) a_0 i.
have{a_0}: a i *: (b`_i : L_F) == 0.
by rewrite a_0 {i}// => i _; rewrite memv_mul ?memv_line ?subvsP.
by rewrite scaler_eq0=> /predU1P[] // /idPn[]; rewrite (memPn nz_b) ?memt_nth.
Qed.
Lemma dim_aspaceOver E : (F <= E)%VS -> \dim (vspaceOver E) = \dim_F E.
Proof. by rewrite -sup_field_module; apply: dim_vspaceOver. Qed.
Lemma vspaceOverP V_F :
{V | [/\ V_F = vspaceOver V, (F * V <= V)%VS & V_F =i V]}.
Proof.
pose V := (F * <<vbasis V_F : seq L>>)%VS.
have idV: (F * V)%VS = V by rewrite prodvA prodv_id.
suffices defVF: V_F = vspaceOver V.
by exists V; split=> [||u]; rewrite ?defVF ?mem_vspaceOver ?idV.
apply/vspaceP=> v; rewrite mem_vspaceOver idV.
do [apply/idP/idP; last rewrite /V unlock] => [/coord_vbasis|/coord_span] ->.
by apply: memv_suml => i _; rewrite memv_mul ?subvsP ?memv_span ?memt_nth.
apply: memv_suml => i _; rewrite -tnth_nth; set xu := tnth _ i.
have /allpairsP[[x u] /=]: xu \in _ := mem_tnth i _.
case=> /vbasis_mem Fx /vbasis_mem Vu ->.
rewrite scalerAl (coord_span Vu) mulr_sumr memv_suml // => j_.
by rewrite -scalerCA (memvZ (Subvs _)) ?memvZ // vbasis_mem ?memt_nth.
Qed.
Lemma aspaceOverP (E_F : {subfield L_F}) :
{E | [/\ E_F = aspaceOver E, (F <= E)%VS & E_F =i E]}.
Proof.
have [V [defEF modV memV]] := vspaceOverP E_F.
have algE: has_algid V && (V * V <= V)%VS.
rewrite has_algid1; last by rewrite -memV mem1v.
by apply/prodvP=> u v; rewrite -!memV; apply: memvM.
by exists (ASpace algE); rewrite -sup_field_module; split; first apply: val_inj.
Qed.
End FieldOver.
(* Changing the reference field to a smaller field. *)
Section BaseField.
Variables (F0 : fieldType) (F : fieldExtType F0) (L : fieldExtType F).
Definition baseFieldType : Type := L.
Notation L0 := baseFieldType.
HB.instance Definition _ := GRing.Field.on L0.
Definition baseField_scale (a : F0) (u : L0) : L0 := in_alg F a *: u.
Local Infix "*F0:" := baseField_scale (at level 40).
Fact baseField_scaleA a b u : a *F0: (b *F0: u) = (a * b) *F0: u.
Proof. by rewrite [_ *F0: _]scalerA -rmorphM. Qed.
Fact baseField_scale1 u : 1 *F0: u = u.
Proof. by rewrite /(1 *F0: u) rmorph1 scale1r. Qed.
Fact baseField_scaleDr a u v : a *F0: (u + v) = a *F0: u + a *F0: v.
Proof. exact: scalerDr. Qed.
Fact baseField_scaleDl v a b : (a + b) *F0: v = a *F0: v + b *F0: v.
Proof. by rewrite -scalerDl -rmorphD. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build _ L0
baseField_scaleA baseField_scale1 baseField_scaleDr baseField_scaleDl.
Lemma baseField_scaleE a (u : L) : a *: (u : L0) = a%:A *: u.
Proof. by []. Qed.
Fact baseField_scaleAl a (u v : L0) : a *F0: (u * v) = (a *F0: u) * v.
Proof. exact: scalerAl. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build _ L0
baseField_scaleAl.
Fact baseField_scaleAr a u v : a *F0: (u * v) = u * (a *F0: v).
Proof. exact: scalerAr. Qed.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build _ L0
baseField_scaleAr.
Let n := \dim {:F}.
Let bF : n.-tuple F := vbasis {:F}.
Let coordF (x : F) := (coord_vbasis (memvf x)).
Fact baseField_vectMixin : Lmodule_hasFinDim F0 L0.
Proof.
pose bL := vbasis {:L}; set m := \dim {:L} in bL.
pose v2r (x : L0) := mxvec (\matrix_(i, j) coord bF j (coord bL i x)).
have v2r_lin: linear v2r.
move=> a x y; rewrite -linearP; congr mxvec; apply/matrixP=> i j.
by rewrite !mxE linearP /= mulr_algl linearP.
pose r2v r := \sum_(i < m) (\sum_(j < n) vec_mx r i j *: bF`_j) *: bL`_i.
have v2rK: cancel v2r r2v.
move=> x; transitivity (\sum_(i < m) coord bL i x *: bL`_i); last first.
by rewrite -coord_vbasis ?memvf.
(* GG: rewrite {2}(coord_vbasis (memvf x)) -/m would take 8s; *)
(* The -/m takes 8s, and without it then apply: eq_bigr takes 12s. *)
(* The time drops to 2s with a -[GRing.Field.ringType F]/(F : fieldType) *)
apply: eq_bigr => i _; rewrite mxvecK; congr (_ *: _ : L).
by rewrite (coordF (coord bL i x)); apply: eq_bigr => j _; rewrite mxE.
exists (m * n)%N, v2r => //; exists r2v => // r.
apply: (canLR vec_mxK); apply/matrixP=> i j; rewrite mxE.
by rewrite !coord_sum_free ?(basis_free (vbasisP _)).
Qed.
HB.instance Definition _ := baseField_vectMixin.
Let F0ZEZ a x v : a *: ((x *: v : L) : L0) = (a *: x) *: v.
Proof. by rewrite [a *: _]scalerA -scalerAl mul1r. Qed.
Let baseVspace_basis V : seq L0 :=
[seq tnth bF ij.2 *: tnth (vbasis V) ij.1 | ij : 'I_(\dim V) * 'I_n].
Definition baseVspace V := <<baseVspace_basis V>>%VS.
Lemma mem_baseVspace V : baseVspace V =i V.
Proof.
move=> y; apply/idP/idP=> [/coord_span->|/coord_vbasis->]; last first.
apply: memv_suml => i _; rewrite (coordF (coord _ i (y : L))) scaler_suml -/n.
apply: memv_suml => j _; rewrite -/bF -F0ZEZ memvZ ?memv_span // -!tnth_nth.
by apply/imageP; exists (i, j).
(* GG: the F0ZEZ lemma avoids serious performance issues here. *)
apply: memv_suml => k _; rewrite nth_image; case: (enum_val k) => i j /=.
by rewrite F0ZEZ memvZ ?vbasis_mem ?mem_tnth.
Qed.
Lemma dim_baseVspace V : \dim (baseVspace V) = (\dim V * n)%N.
Proof.
pose bV0 := baseVspace_basis V; set m := \dim V in bV0 *.
suffices /size_basis->: basis_of (baseVspace V) bV0.
by rewrite card_prod !card_ord.
rewrite /basis_of eqxx.
apply/freeP=> s sb0 k; rewrite -(enum_valK k); case/enum_val: k => i j.
have free_baseP := freeP (basis_free (vbasisP _)).
move: j; apply: (free_baseP _ _ fullv); move: i; apply: (free_baseP _ _ V).
transitivity (\sum_i \sum_j s (enum_rank (i, j)) *: bV0`_(enum_rank (i, j))).
apply: eq_bigr => i _; rewrite scaler_suml; apply: eq_bigr => j _.
by rewrite -F0ZEZ nth_image enum_rankK -!tnth_nth.
rewrite pair_bigA (reindex _ (onW_bij _ (enum_val_bij _))); apply: etrans sb0.
by apply: eq_bigr => k _; rewrite -{5 6}[k](enum_valK k); case/enum_val: k.
Qed.
Fact baseAspace_suproof (E : {subfield L}) : is_aspace (baseVspace E).
Proof.
rewrite /is_aspace has_algid1; last by rewrite mem_baseVspace (mem1v E).
by apply/prodvP=> u v; rewrite !mem_baseVspace; apply: memvM.
Qed.
Canonical baseAspace E := ASpace (baseAspace_suproof E).
End BaseField.
Arguments baseFieldType [F0 F]%_type L%_type.
HB.lock Definition refBaseField (F0 : fieldType) (F : fieldExtType F0)
(L : fieldExtType F) := baseAspace (1%AS : {aspace L}).
Canonical refBaseField_unlockable := Unlockable refBaseField.unlock.
Section RefBaseField.
Variables (F0 : fieldType) (F : fieldExtType F0) (L : fieldExtType F).
Notation F1 := (refBaseField L).
Notation F1unlock := refBaseField.unlock.
Notation L0 := (baseFieldType L).
Let n := \dim {:F}.
Let bF : n.-tuple F := vbasis {:F}.
Let coordF (x : F) := (coord_vbasis (memvf x)).
Lemma dim_refBaseField : \dim F1 = n.
Proof. by rewrite F1unlock dim_baseVspace dimv1 mul1n. Qed.
Lemma baseVspace_module V (V0 := baseVspace V) : (F1 * V0 <= V0)%VS.
Proof.
apply/prodvP=> u v; rewrite F1unlock !mem_baseVspace => /vlineP[x ->] Vv.
by rewrite -(@scalerAl F L) mul1r; apply: memvZ.
Qed.
Lemma sub_baseField (E : {subfield L}) : (F1 <= baseVspace E)%VS.
Proof. by rewrite -sup_field_module baseVspace_module. Qed.
Lemma vspaceOver_refBase V : vspaceOver F1 (baseVspace V) =i V.
Proof.
move=> v; rewrite mem_vspaceOver field_module_eq ?baseVspace_module //.
by rewrite mem_baseVspace.
Qed.
Lemma module_baseVspace M0 :
(F1 * M0 <= M0)%VS -> {V | M0 = baseVspace V & M0 =i V}.
Proof.
move=> modM0; pose V := <<vbasis (vspaceOver F1 M0) : seq L>>%VS.
suffices memM0: M0 =i V.
by exists V => //; apply/vspaceP=> v; rewrite mem_baseVspace memM0.
move=> v; rewrite -{1}(field_module_eq modM0) -(mem_vspaceOver M0) {}/V.
move: (vspaceOver F1 M0) => M.
apply/idP/idP=> [/coord_vbasis|/coord_span]->; apply/memv_suml=> i _.
rewrite /(_ *: _) /= /fieldOver_scale; case: (coord _ i _) => /= x.
rewrite {1}F1unlock mem_baseVspace => /vlineP[{}x ->].
by rewrite -(@scalerAl F L) mul1r memvZ ?memv_span ?memt_nth.
move: (coord _ i _) => x; rewrite -[_`_i]mul1r scalerAl -tnth_nth.
have F1x: x%:A \in F1.
by rewrite F1unlock mem_baseVspace (@memvZ F L) // mem1v.
by congr (_ \in M): (memvZ (Subvs F1x) (vbasis_mem (mem_tnth i _))).
Qed.
Lemma module_baseAspace (E0 : {subfield L0}) :
(F1 <= E0)%VS -> {E | E0 = baseAspace E & E0 =i E}.
Proof.
rewrite -sup_field_module => /module_baseVspace[E defE0 memE0].
suffices algE: is_aspace E by exists (ASpace algE); first apply: val_inj.
rewrite /is_aspace has_algid1 -?memE0 ?mem1v //.
by apply/prodvP=> u v; rewrite -!memE0; apply: memvM.
Qed.
End RefBaseField.
(* Base of fieldOver, finally. *)
Section MoreFieldOver.
Variables (F0 : fieldType) (L : fieldExtType F0) (F : {subfield L}).
Lemma base_vspaceOver V : baseVspace (vspaceOver F V) =i (F * V)%VS.
Proof. by move=> v; rewrite mem_baseVspace mem_vspaceOver. Qed.
Lemma base_moduleOver V : (F * V <= V)%VS -> baseVspace (vspaceOver F V) =i V.
Proof. by move=> /field_module_eq defV v; rewrite base_vspaceOver defV. Qed.
Lemma base_aspaceOver (E : {subfield L}) :
(F <= E)%VS -> baseVspace (vspaceOver F E) =i E.
Proof. by rewrite -sup_field_module; apply: base_moduleOver. Qed.
End MoreFieldOver.
Section SubFieldExtension.
Local Open Scope quotient_scope.
Variables (F L : fieldType) (iota : {rmorphism F -> L}).
Variables (z : L) (p : {poly F}).
Local Notation "p ^iota" := (map_poly (GRing.RMorphism.sort iota) p)
(format "p ^iota") : ring_scope.
Let wf_p := (p != 0) && root p^iota z.
Let p0 : {poly F} := if wf_p then (lead_coef p)^-1 *: p else 'X.
Let z0 := if wf_p then z else 0.
Let n := (size p0).-1.
Let p0_mon : p0 \is monic.
Proof.
rewrite /p0; case: ifP => [/andP[nz_p _] | _]; last exact: monicX.
by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0.
Qed.
Let nz_p0 : p0 != 0. Proof. by rewrite monic_neq0 // p0_mon. Qed.
Let p0z0 : root p0^iota z0.
Proof.
rewrite /p0 /z0; case: ifP => [/andP[_ pz0]|]; last by rewrite map_polyX rootX.
by rewrite map_polyZ rootE hornerZ (rootP pz0) mulr0.
Qed.
Let n_gt0: 0 < n.
Proof.
rewrite /n -subn1 subn_gt0 -(size_map_poly iota).
by rewrite (root_size_gt1 _ p0z0) ?map_poly_eq0.
Qed.
Let z0Ciota : commr_rmorph iota z0. Proof. by move=> x; apply: mulrC. Qed.
Local Notation iotaPz := (horner_morph z0Ciota).
Let iotaFz (x : 'rV[F]_n) := iotaPz (rVpoly x).
Definition equiv_subfext x y := (iotaFz x == iotaFz y).
Fact equiv_subfext_is_equiv : equiv_class_of equiv_subfext.
Proof. by rewrite /equiv_subfext; split=> x // y w /eqP->. Qed.
Canonical equiv_subfext_equiv := EquivRelPack equiv_subfext_is_equiv.
Canonical equiv_subfext_encModRel := defaultEncModRel equiv_subfext.
Definition subFExtend := {eq_quot equiv_subfext}.
HB.instance Definition _ := Choice.on subFExtend.
HB.instance Definition _ := Quotient.on subFExtend.
HB.instance Definition _ : EqQuotient 'M[F]_(1, n) equiv_subfext subFExtend :=
EqQuotient.on subFExtend.
Definition subfx_inj := lift_fun1 subFExtend iotaFz.
Fact pi_subfx_inj : {mono \pi : x / iotaFz x >-> subfx_inj x}.
Proof.
unlock subfx_inj => x; apply/eqP; rewrite -/(equiv_subfext _ x).
by rewrite -eqmodE reprK.
Qed.
Canonical pi_subfx_inj_morph := PiMono1 pi_subfx_inj.
Let iotaPz_repr x : iotaPz (rVpoly (repr (\pi_(subFExtend) x))) = iotaFz x.
Proof. by rewrite -/(iotaFz _) -!pi_subfx_inj reprK. Qed.
Definition subfext0 := lift_cst subFExtend 0.
Canonical subfext0_morph := PiConst subfext0.
Definition subfext_add := lift_op2 subFExtend +%R.
Fact pi_subfext_add : {morph \pi : x y / x + y >-> subfext_add x y}.
Proof.
unlock subfext_add => x y /=; apply/eqmodP/eqP.
by rewrite /iotaFz !linearD /= !iotaPz_repr.
Qed.
Canonical pi_subfx_add_morph := PiMorph2 pi_subfext_add.
Definition subfext_opp := lift_op1 subFExtend -%R.
Fact pi_subfext_opp : {morph \pi : x / - x >-> subfext_opp x}.
Proof.
unlock subfext_opp => y /=; apply/eqmodP/eqP.
by rewrite /iotaFz !linearN /= !iotaPz_repr.
Qed.
Canonical pi_subfext_opp_morph := PiMorph1 pi_subfext_opp.
Fact addfxA : associative subfext_add.
Proof. by move=> x y t; rewrite -[x]reprK -[y]reprK -[t]reprK !piE addrA. Qed.
Fact addfxC : commutative subfext_add.
Proof. by move=> x y; rewrite -[x]reprK -[y]reprK !piE addrC. Qed.
Fact add0fx : left_id subfext0 subfext_add.
Proof. by move=> x; rewrite -[x]reprK !piE add0r. Qed.
Fact addfxN : left_inverse subfext0 subfext_opp subfext_add.
Proof. by move=> x; rewrite -[x]reprK !piE addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build subFExtend
addfxA addfxC add0fx addfxN.
Let poly_rV_modp_K q : rVpoly (poly_rV (q %% p0) : 'rV[F]_n) = q %% p0.
Proof. by apply: poly_rV_K; rewrite -ltnS -polySpred // ltn_modp. Qed.
Let iotaPz_modp q : iotaPz (q %% p0) = iotaPz q.
Proof.
rewrite {2}(divp_eq q p0) rmorphD rmorphM /=.
by rewrite [iotaPz p0](rootP p0z0) mulr0 add0r.
Qed.
Definition subfx_mul_rep (x y : 'rV[F]_n) : 'rV[F]_n :=
poly_rV ((rVpoly x) * (rVpoly y) %% p0).
Definition subfext_mul := lift_op2 subFExtend subfx_mul_rep.
Fact pi_subfext_mul :
{morph \pi : x y / subfx_mul_rep x y >-> subfext_mul x y}.
Proof.
unlock subfext_mul => x y /=; apply/eqmodP/eqP.
by rewrite /iotaFz !poly_rV_modp_K !iotaPz_modp !rmorphM /= !iotaPz_repr.
Qed.
Canonical pi_subfext_mul_morph := PiMorph2 pi_subfext_mul.
Definition subfext1 := lift_cst subFExtend (poly_rV 1).
Canonical subfext1_morph := PiConst subfext1.
Fact mulfxA : associative (subfext_mul).
Proof.
elim/quotW=> x; elim/quotW=> y; elim/quotW=> w; rewrite !piE /subfx_mul_rep.
by rewrite !poly_rV_modp_K [_ %% p0 * _]mulrC !modp_mul // mulrA mulrC.
Qed.
Fact mulfxC : commutative subfext_mul.
Proof.
by elim/quotW=> x; elim/quotW=> y; rewrite !piE /subfx_mul_rep /= mulrC.
Qed.
Fact mul1fx : left_id subfext1 subfext_mul.
Proof.
elim/quotW=> x; rewrite !piE /subfx_mul_rep poly_rV_K ?size_poly1 // mul1r.
by rewrite modp_small ?rVpolyK // (polySpred nz_p0) ltnS size_poly.
Qed.
Fact mulfx_addl : left_distributive subfext_mul subfext_add.
Proof.
elim/quotW=> x; elim/quotW=> y; elim/quotW=> w.
by rewrite !piE /subfx_mul_rep linearD /= mulrDl modpD linearD.
Qed.
Fact nonzero1fx : subfext1 != subfext0.
Proof.
rewrite !piE /equiv_subfext /iotaFz !linear0.
by rewrite poly_rV_K ?rmorph1 ?oner_eq0 // size_poly1.
Qed.
HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build subFExtend
mulfxA mulfxC mul1fx mulfx_addl nonzero1fx.
Definition subfx_poly_inv (q : {poly F}) : {poly F} :=
if iotaPz q == 0 then 0 else
let r := gdcop q p0 in let: (u, v) := egcdp q r in
((u * q + v * r)`_0)^-1 *: u.
Let subfx_poly_invE q : iotaPz (subfx_poly_inv q) = (iotaPz q)^-1.
Proof.
rewrite /subfx_poly_inv.
have [-> | nzq] := eqVneq; first by rewrite rmorph0 invr0.
rewrite [nth]lock -[_^-1]mul1r; apply: canRL (mulfK nzq) _; rewrite -rmorphM /=.
have rz0: iotaPz (gdcop q p0) = 0.
by apply/rootP; rewrite gdcop_map root_gdco ?map_poly_eq0 // p0z0 nzq.
do [case: gdcopP => r _; rewrite (negPf nz_p0) orbF => co_r_q _] in rz0 *.
case: (egcdp q r) (egcdpE q r) => u v /=/eqp_size/esym/eqP.
rewrite coprimep_size_gcd 1?coprimep_sym // => /size_poly1P[a nz_a Da].
rewrite Da -scalerAl (canRL (addrK _) Da) -lock coefC linearZ linearB /=.
by rewrite rmorphM /= rz0 mulr0 subr0 horner_morphC -rmorphM mulVf ?rmorph1.
Qed.
Definition subfx_inv_rep (x : 'rV[F]_n) : 'rV[F]_n :=
poly_rV (subfx_poly_inv (rVpoly x) %% p0).
Definition subfext_inv := lift_op1 subFExtend subfx_inv_rep.
Fact pi_subfext_inv : {morph \pi : x / subfx_inv_rep x >-> subfext_inv x}.
Proof.
unlock subfext_inv => x /=; apply/eqmodP/eqP; rewrite /iotaFz.
by rewrite 2!{1}poly_rV_modp_K 2!{1}iotaPz_modp !subfx_poly_invE iotaPz_repr.
Qed.
Canonical pi_subfext_inv_morph := PiMorph1 pi_subfext_inv.
Fact subfx_fieldAxiom : forall x, x != 0 -> subfext_inv x * x = 1.
Proof.
elim/quotW=> x; apply: contraNeq; rewrite !piE /equiv_subfext /iotaFz !linear0.
apply: contraR => nz_x; rewrite poly_rV_K ?size_poly1 // !poly_rV_modp_K.
by rewrite iotaPz_modp rmorph1 rmorphM /= iotaPz_modp subfx_poly_invE mulVf.
Qed.
Fact subfx_inv0 : subfext_inv (0 : subFExtend) = (0 : subFExtend).
Proof.
apply/eqP; rewrite !piE /equiv_subfext /iotaFz /subfx_inv_rep !linear0.
by rewrite /subfx_poly_inv rmorph0 eqxx mod0p !linear0.
Qed.
HB.instance Definition _ := GRing.ComNzRing_isField.Build subFExtend
subfx_fieldAxiom subfx_inv0.
Fact subfx_inj_is_zmod_morphism : zmod_morphism subfx_inj.
Proof.
by elim/quotW => x; elim/quotW => y; rewrite !piE /iotaFz linearB rmorphB.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `subfx_inj_is_zmod_morphism` instead")]
Definition subfx_inj_is_additive := subfx_inj_is_zmod_morphism.
Fact subfx_inj_is_monoid_morphism : monoid_morphism subfx_inj.
Proof.
split; first by rewrite piE /iotaFz poly_rV_K ?rmorph1 ?size_poly1.
elim/quotW=> x; elim/quotW=> y; rewrite !piE /subfx_mul_rep /iotaFz.
by rewrite poly_rV_modp_K iotaPz_modp rmorphM.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `subfx_inj_is_monoid_morphism` instead")]
Definition subfx_inj_is_multiplicative :=
(fun g => (g.2,g.1)) subfx_inj_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build subFExtend L subfx_inj
subfx_inj_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build subFExtend L subfx_inj
subfx_inj_is_monoid_morphism.
Definition subfx_eval := lift_embed subFExtend (fun q => poly_rV (q %% p0)).
Canonical subfx_eval_morph := PiEmbed subfx_eval.
Definition subfx_root := subfx_eval 'X.
Lemma subfx_eval_is_zmod_morphism : zmod_morphism subfx_eval.
Proof. by move=> x y; apply/eqP; rewrite piE -linearB modpD modNp. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `subfx_eval_is_zmod_morphism` instead")]
Definition subfx_eval_is_additive := subfx_eval_is_zmod_morphism.
Lemma subfx_eval_is_monoid_morphism : monoid_morphism subfx_eval.
Proof.
split=> [|x y]; apply/eqP; rewrite piE.
by rewrite modp_small // size_poly1 -subn_gt0 subn1.
by rewrite /subfx_mul_rep !poly_rV_modp_K !(modp_mul, mulrC _ y).
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `subfx_eval_is_monoid_morphism` instead")]
Definition subfx_eval_is_multiplicative :=
(fun g => (g.2,g.1)) subfx_eval_is_monoid_morphism.
HB.instance Definition _ :=
GRing.isZmodMorphism.Build {poly F} subFExtend subfx_eval subfx_eval_is_zmod_morphism.
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly F} subFExtend subfx_eval
subfx_eval_is_monoid_morphism.
Definition inj_subfx := (subfx_eval \o polyC).
HB.instance Definition _ := GRing.RMorphism.on inj_subfx.
Lemma subfxE x: exists p, x = subfx_eval p.
Proof.
elim/quotW: x => x; exists (rVpoly x); apply/eqP; rewrite piE /equiv_subfext.
by rewrite /iotaFz poly_rV_modp_K iotaPz_modp.
Qed.
Definition subfx_scale a x := inj_subfx a * x.
Fact subfx_scalerA a b x :
subfx_scale a (subfx_scale b x) = subfx_scale (a * b) x.
Proof. by rewrite /subfx_scale rmorphM mulrA. Qed.
Fact subfx_scaler1r : left_id 1 subfx_scale.
Proof. by move=> x; rewrite /subfx_scale rmorph1 mul1r. Qed.
Fact subfx_scalerDr : right_distributive subfx_scale +%R.
Proof. by move=> a; apply: mulrDr. Qed.
Fact subfx_scalerDl x : {morph subfx_scale^~ x : a b / a + b}.
Proof. by move=> a b; rewrite /subfx_scale rmorphD mulrDl. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build _ subFExtend
subfx_scalerA subfx_scaler1r subfx_scalerDr subfx_scalerDl.
Fact subfx_scaleAl a u v : subfx_scale a (u * v) = (subfx_scale a u) * v.
Proof. exact: mulrA. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build _ subFExtend
subfx_scaleAl.
Fact subfx_scaleAr a u v : subfx_scale a (u * v) = u * (subfx_scale a v).
Proof. exact: mulrCA. Qed.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build _ subFExtend
subfx_scaleAr.
Fact subfx_evalZ : scalable subfx_eval.
Proof. by move=> a q; rewrite -mul_polyC rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build F {poly F} subFExtend *:%R subfx_eval subfx_evalZ.
Hypothesis (pz0 : root p^iota z).
Section NonZero.
Hypothesis nz_p : p != 0.
Lemma subfx_inj_eval q : subfx_inj (subfx_eval q) = (q^iota).[z].
Proof.
by rewrite piE /iotaFz poly_rV_modp_K iotaPz_modp /iotaPz /z0 /wf_p nz_p pz0.
Qed.
Lemma subfx_inj_root : subfx_inj subfx_root = z.
Proof. by rewrite subfx_inj_eval // map_polyX hornerX. Qed.
Lemma subfx_injZ b x : subfx_inj (b *: x) = iota b * subfx_inj x.
Proof. by rewrite rmorphM /= subfx_inj_eval // map_polyC hornerC. Qed.
Lemma subfx_inj_base b : subfx_inj b%:A = iota b.
Proof. by rewrite subfx_injZ rmorph1 mulr1. Qed.
Lemma subfxEroot x : {q | x = (map_poly (in_alg subFExtend) q).[subfx_root]}.
Proof.
have /sig_eqW[q ->] := subfxE x; exists q.
apply: (fmorph_inj subfx_inj).
rewrite -horner_map /= subfx_inj_root subfx_inj_eval //.
by rewrite -map_poly_comp (eq_map_poly subfx_inj_base).
Qed.
Lemma subfx_irreducibleP :
(forall q, root q^iota z -> q != 0 -> size p <= size q) <-> irreducible_poly p.
Proof.
split=> [min_p | irr_p q qz0 nz_q].
split=> [|q nonC_q q_dv_p].
by rewrite -(size_map_poly iota) (root_size_gt1 _ pz0) ?map_poly_eq0.
have /dvdpP[r Dp] := q_dv_p; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=.
have [nz_r nz_q]: r != 0 /\ q != 0 by apply/norP; rewrite -mulf_eq0 -Dp.
have: root r^iota z || root q^iota z by rewrite -rootM -rmorphM -Dp.
case/orP=> /min_p; [case/(_ _)/idPn=> // | exact].
rewrite polySpred // -leqNgt Dp size_mul //= polySpred // -subn2 ltn_subRL.
by rewrite addSnnS addnC ltn_add2l ltn_neqAle eq_sym nonC_q size_poly_gt0.
pose r := gcdp p q; have nz_r: r != 0 by rewrite gcdp_eq0 (negPf nz_p).
suffices /eqp_size <-: r %= p by rewrite dvdp_leq ?dvdp_gcdr.
rewrite (irr_p _) ?dvdp_gcdl // -(size_map_poly iota) gtn_eqF //.
by rewrite (@root_size_gt1 _ z) ?map_poly_eq0 // gcdp_map root_gcd pz0.
Qed.
End NonZero.
Section Irreducible.
Hypothesis irr_p : irreducible_poly p.
Let nz_p : p != 0. Proof. exact: irredp_neq0. Qed.
(* The Vector axiom requires irreducibility. *)
Lemma min_subfx_vect : Vector.axiom (size p).-1 subFExtend.
Proof.
move/subfx_irreducibleP: irr_p => /=/(_ nz_p) min_p; set d := (size p).-1.
have Dd: d.+1 = size p by rewrite polySpred.
pose Fz2v x : 'rV_d := poly_rV (sval (sig_eqW (subfxE x)) %% p).
pose vFz : 'rV_d -> subFExtend := subfx_eval \o rVpoly.
have FLinj: injective subfx_inj by apply: fmorph_inj.
have Fz2vK: cancel Fz2v vFz.
move=> x; rewrite /vFz /Fz2v; case: (sig_eqW _) => /= q ->.
apply: FLinj; rewrite !subfx_inj_eval // {2}(divp_eq q p) rmorphD rmorphM /=.
by rewrite !hornerE (eqP pz0) mulr0 add0r poly_rV_K // -ltnS Dd ltn_modpN0.
suffices vFzK: cancel vFz Fz2v.
by exists Fz2v; [apply: can2_linear Fz2vK | exists vFz].
apply: inj_can_sym Fz2vK _ => v1 v2 /(congr1 subfx_inj)/eqP.
rewrite -subr_eq0 -!raddfB /= subfx_inj_eval // => /min_p/implyP.
rewrite leqNgt implybNN -Dd ltnS size_poly linearB subr_eq0 /=.
by move/eqP/(can_inj rVpolyK).
Qed.
Definition SubfxVect := Lmodule_hasFinDim.Build _ subFExtend min_subfx_vect.
Definition SubFieldExtType : fieldExtType F := HB.pack subFExtend SubfxVect.
End Irreducible.
End SubFieldExtension.
Prenex Implicits subfx_inj.
Lemma irredp_FAdjoin (F : fieldType) (p : {poly F}) :
irreducible_poly p ->
{L : fieldExtType F & \dim {:L} = (size p).-1 &
{z | root (map_poly (in_alg L) p) z & <<1; z>>%VS = fullv}}.
Proof.
case=> p_gt1 irr_p; set n := (size p).-1; pose vL : vectType F := 'rV_n.
have Dn: n.+1 = size p := ltn_predK p_gt1.
have nz_p: p != 0 by rewrite -size_poly_eq0 -Dn.
suffices [L dimL [toPF [toL toPF_K toL_K]]]:
{L : fieldExtType F & \dim {:L} = (size p).-1
& {toPF : {linear L -> {poly F}} & {toL : {lrmorphism {poly F} -> L} |
cancel toPF toL & forall q, toPF (toL q) = q %% p}}}.
- exists L => //; pose z := toL 'X; set iota := in_alg _.
suffices q_z q: toPF (map_poly iota q).[z] = q %% p.
exists z; first by rewrite /root -(can_eq toPF_K) q_z modpp linear0.
apply/vspaceP=> x; rewrite memvf; apply/Fadjoin_polyP.
exists (map_poly iota (toPF x)).
by apply/polyOverP=> i; rewrite coef_map memvZ ?mem1v.
by apply: (can_inj toPF_K); rewrite q_z -toL_K toPF_K.
elim/poly_ind: q => [|a q IHq].
by rewrite map_poly0 horner0 linear0 mod0p.
rewrite rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC linearD /=.
rewrite linearZ /= -(rmorph1 toL) toL_K -modpZl alg_polyC modpD.
congr (_ + _); rewrite -toL_K rmorphM -/z; congr (toPF (_ * z)).
by apply: (can_inj toPF_K); rewrite toL_K.
pose toL q : vL := poly_rV (q %% p); pose toPF (x : vL) := rVpoly x.
have toL_K q : toPF (toL q) = q %% p.
by rewrite /toPF poly_rV_K // -ltnS Dn ?ltn_modp -?Dn.
have toPF_K: cancel toPF toL.
by move=> x; rewrite /toL modp_small ?rVpolyK // -Dn ltnS size_poly.
have toPinj := can_inj toPF_K.
pose mul x y := toL (toPF x * toPF y); pose L1 := toL 1.
have L1K: toPF L1 = 1 by rewrite toL_K modp_small ?size_poly1.
have mulC: commutative mul by rewrite /mul => x y; rewrite mulrC.
have mulA: associative mul.
by move=> x y z; apply: toPinj; rewrite -!(mulC z) !toL_K !modp_mul mulrCA.
have mul1: left_id L1 mul.
by move=> x; apply: toPinj; rewrite mulC !toL_K modp_mul mulr1 -toL_K toPF_K.
have mulD: left_distributive mul +%R.
move=> x y z; apply: toPinj; rewrite /toPF raddfD /= -!/(toPF _).
by rewrite !toL_K /toPF raddfD mulrDl modpD.
have nzL1: L1 != 0 by rewrite -(inj_eq toPinj) L1K /toPF raddf0 oner_eq0.
pose mulM := GRing.Zmodule_isComNzRing.Build _ mulA mulC mul1 mulD nzL1.
pose rL : comNzRingType := HB.pack vL mulM.
have mulZlM : GRing.Lmodule_isLalgebra F rL.
constructor => a x y; apply: toPinj.
by rewrite toL_K /toPF !linearZ /= -!/(toPF _) toL_K -scalerAl modpZl.
pose laL : lalgType F := HB.pack rL mulZlM.
have mulZrM : GRing.Lalgebra_isAlgebra F laL.
by constructor => a x y; rewrite !(mulrC x) scalerAl.
pose aL : algType F := HB.pack laL mulZrM.
pose uLM := Algebra_isFalgebra.Build F aL.
pose cuL : comUnitRingType := HB.pack aL uLM.
have unitM : GRing.ComUnitRing_isField cuL.
constructor => x nz_x; apply/unitrP; set q := toPF x.
have nz_q: q != 0 by rewrite -(inj_eq toPinj) /toPF raddf0 in nz_x.
have /Bezout_eq1_coprimepP[u upq1]: coprimep p q.
apply: contraLR (leq_gcdpr p nz_q) => /irr_p/implyP.
rewrite dvdp_gcdl -ltnNge /= => /eqp_size->.
by rewrite (polySpred nz_p) ltnS size_poly.
suffices: x * toL u.2 = 1 by exists (toL u.2); rewrite mulrC.
apply: toPinj; rewrite !toL_K -upq1 modp_mul modpD mulrC.
by rewrite modp_mull add0r.
pose feL : fieldExtType F := HB.pack vL aL cuL unitM.
exists feL; first by rewrite dimvf; apply: mul1n.
exists toPF.
have tol_lin: linear toL by move=> a q1 q2; rewrite -linearP -modpZl -modpD.
have tol_mul : monoid_morphism (toL : {poly F} -> aL).
by split=> [|q r];
apply: toPinj; rewrite !toL_K // modp_mul -!(mulrC r) modp_mul.
pose toLlM := GRing.isLinear.Build _ _ _ _ toL tol_lin.
pose toLmM := GRing.isMonoidMorphism.Build _ _ _ tol_mul.
pose toLLRM : {lrmorphism _ -> feL} := HB.pack toL toLlM toLmM.
by exists toLLRM.
Qed.
(*Coq 8.3 processes this shorter proof correctly, but then crashes on Qed.
In Coq 8.4 Qed takes about 18s.
In Coq 8.7, everything seems to be all right *)
(* Lemma Xirredp_FAdjoin' (F : fieldType) (p : {poly F}) : *)
(* irreducible_poly p -> *)
(* {L : fieldExtType F & \dim {: L} = (size p).-1 & *)
(* {z | root (map_poly (in_alg L) p) z & <<1; z>>%VS = fullv}}. *)
(* Proof. *)
(* case=> p_gt1 irr_p; set n := (size p).-1; pose vL := [vectType F of 'rV_n]. *)
(* have Dn: n.+1 = size p := ltn_predK p_gt1. *)
(* have nz_p: p != 0 by rewrite -size_poly_eq0 -Dn. *)
(* pose toL q : vL := poly_rV (q %% p). *)
(* have toL_K q : rVpoly (toL q) = q %% p. *)
(* by rewrite poly_rV_K // -ltnS Dn ?ltn_modp -?Dn. *)
(* pose mul (x y : vL) : vL := toL (rVpoly x * rVpoly y). *)
(* pose L1 : vL := poly_rV 1. *)
(* have L1K: rVpoly L1 = 1 by rewrite poly_rV_K // size_poly1 -ltnS Dn. *)
(* have mulC: commutative mul by rewrite /mul => x y; rewrite mulrC. *)
(* have mulA: associative mul. *)
(* by move=> x y z; rewrite -!(mulC z) /mul !toL_K /toL !modp_mul mulrCA. *)
(* have mul1: left_id L1 mul. *)
(* move=> x; rewrite /mul L1K mul1r /toL modp_small ?rVpolyK // -Dn ltnS. *)
(* by rewrite size_poly. *)
(* have mulD: left_distributive mul +%R. *)
(* move=> x y z; apply: canLR rVpolyK _. *)
(* by rewrite !raddfD mulrDl /= !toL_K /toL modpD. *)
(* have nzL1: L1 != 0 by rewrite -(can_eq rVpolyK) L1K raddf0 oner_eq0. *)
(* pose mulM := GRing.Zmodule_isComNzRing.Build vL mulA mulC mul1 mulD nzL1. *)
(* pose rL := ComNzRingType vL mulM. *)
(* have mulZlM : GRing.Lmodule_isLalgebra F rL. *)
(* constructor => a x y; apply: canRL rVpolyK _. *)
(* by rewrite !linearZ /= toL_K -scalerAl modpZl. *)
(* pose laL := LalgType F rL mulZlM. *)
(* have mulZrM : GRing.Lalgebra_isAlgebra F laL. *)
(* by constructor => a x y; rewrite !(mulrC x) scalerAl. *)
(* pose aL := AlgType F laL mulZrM. *)
(* pose uLM := Algebra_isFalgebra.Build F aL. *)
(* pose cuL := ComUnitRingType uLM _. *)
(* have unitM : GRing.ComUnitRing_isField cuL. *)
(* constructor => x nz_x; apply/unitrP; set q := rVpoly x. *)
(* have nz_q: q != 0 by rewrite -(can_eq rVpolyK) raddf0 in nz_x. *)
(* have /Bezout_eq1_coprimepP[u upq1]: coprimep p q. *)
(* have /contraR := irr_p _ _ (dvdp_gcdl p q); apply. *)
(* have: size (gcdp p q) <= size q by apply: leq_gcdpr. *)
(* rewrite leqNgt; apply: contra; move/eqp_size ->. *)
(* by rewrite (polySpred nz_p) ltnS size_poly. *)
(* suffices: x * toL u.2 = 1 by exists (toL u.2); rewrite mulrC. *)
(* congr (poly_rV _); rewrite toL_K modp_mul mulrC (canRL (addKr _) upq1). *)
(* by rewrite -mulNr modp_addl_mul_small ?size_poly1. *)
(* pose feL := FieldExtType _ unitM _. *)
(* exists feL; first by rewrite dimvf; apply: mul1n. *)
(* pose z : vL := toL 'X; set iota := in_alg _. *)
(* have q_z q: rVpoly (map_poly iota q).[z] = q %% p. *)
(* elim/poly_ind: q => [|a q IHq]. *)
(* by rewrite map_poly0 horner0 linear0 mod0p. *)
(* rewrite rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC linearD /=. *)
(* rewrite linearZ /= L1K alg_polyC modpD; congr (_ + _); last first. *)
(* by rewrite modp_small // size_polyC; case: (~~ _) => //; apply: ltnW. *)
(* by rewrite !toL_K IHq mulrC modp_mul mulrC modp_mul. *)
(* exists z; first by rewrite /root -(can_eq rVpolyK) q_z modpp linear0. *)
(* apply/vspaceP=> x; rewrite memvf; apply/Fadjoin_polyP. *)
(* exists (map_poly iota (rVpoly x)). *)
(* by apply/polyOverP=> i; rewrite coef_map memvZ ?mem1v. *)
(* by apply/(can_inj rVpolyK); rewrite q_z modp_small // -Dn ltnS size_poly. *)
(* Qed. *)
|
DershowitzManna.lean
|
/-
Copyright (c) 2024 Haitian Wang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Haitian Wang, Malvin Gattinger
-/
import Mathlib.Algebra.Order.Sub.Unbundled.Basic
import Mathlib.Data.Multiset.OrderedMonoid
/-!
# Dershowitz-Manna ordering
In this file we define the _Dershowitz-Manna ordering_ on multisets. Specifically, for two multisets
`M` and `N` in a partial order `(S, <)`, `M` is smaller than `N` in the Dershowitz-Manna ordering if
`M` can be obtained from `N` by replacing one or more elements in `N` by some finite number of
elements from `S`, each of which is smaller (in the underling ordering over `S`) than one of the
replaced elements from `N`. We prove that, given a well-founded partial order on the underlying set,
the Dershowitz-Manna ordering defined over multisets is also well-founded.
## Main results
- `Multiset.IsDershowitzMannaLT` : the standard definition fo the `Dershowitz-Manna ordering`.
- `Multiset.wellFounded_isDershowitzMannaLT` : the main theorem about the
`Dershowitz-Manna ordering` being well-founded.
## References
* [Wikipedia, Dershowitz–Manna ordering*]
(https://en.wikipedia.org/wiki/Dershowitz%E2%80%93Manna_ordering)
* [CoLoR](https://github.com/fblanqui/color), a Coq library on rewriting theory and termination.
Our code here is inspired by their formalization and the theorem is called `mOrd_wf` in the file
[MultisetList.v](https://github.com/fblanqui/color/blob/1.8.5/Util/Multiset/MultisetOrder.v).
-/
open Relation
namespace Multiset
variable {α : Type*} [Preorder α] {M N P : Multiset α} {a : α}
/-- The standard Dershowitz–Manna ordering. -/
def IsDershowitzMannaLT (M N : Multiset α) : Prop :=
∃ X Y Z,
Z ≠ ∅
∧ M = X + Y
∧ N = X + Z
∧ ∀ y ∈ Y, ∃ z ∈ Z, y < z
/-- `IsDershowitzMannaLT` is transitive. -/
lemma IsDershowitzMannaLT.trans :
IsDershowitzMannaLT M N → IsDershowitzMannaLT N P → IsDershowitzMannaLT M P := by
classical
rintro ⟨X₁, Y₁, Z₁, -, rfl, rfl, hYZ₁⟩ ⟨X₂, Y₂, Z₂, hZ₂, hXZXY, rfl, hYZ₂⟩
rw [add_comm X₁,add_comm X₂] at hXZXY
refine ⟨X₁ ∩ X₂, Y₁ + (Y₂ - Z₁), Z₂ + (Z₁ - Y₂), ?_, ?_, ?_, ?_⟩
· simpa [-not_and, not_and_or] using .inl hZ₂
· rwa [← add_assoc, add_right_comm, inter_add_sub_of_add_eq_add]
· rw [← add_assoc, add_right_comm, add_left_inj, inter_comm, inter_add_sub_of_add_eq_add]
rwa [eq_comm]
simp only [mem_add, or_imp, forall_and]
refine ⟨fun y hy ↦ ?_, fun y hy ↦ ?_⟩
· obtain ⟨z, hz, hyz⟩ := hYZ₁ y hy
by_cases z_in : z ∈ Y₂
· obtain ⟨w, hw, hzw⟩ := hYZ₂ z z_in
exact ⟨w, .inl hw, hyz.trans hzw⟩
· exact ⟨z, .inr <| by rwa [mem_sub, count_eq_zero_of_notMem z_in, count_pos], hyz⟩
· obtain ⟨z, hz, hyz⟩ := hYZ₂ y <| mem_of_le (Multiset.sub_le_self ..) hy
exact ⟨z, .inl hz, hyz⟩
/-- A special case of `IsDershowitzMannaLT`. The transitive closure of it is used to define
an equivalent (proved later) version of the ordering. -/
private def OneStep (M N : Multiset α) : Prop :=
∃ X Y a,
M = X + Y
∧ N = X + {a}
∧ ∀ y ∈ Y, y < a
private lemma isDershowitzMannaLT_of_oneStep : OneStep M N → IsDershowitzMannaLT M N := by
rintro ⟨X, Y, a, M_def, N_def, ys_lt_a⟩
use X, Y, {a}, by simp, M_def, N_def
· simpa
private lemma isDershowitzMannaLT_singleton_insert (h : OneStep N (a ::ₘ M)) :
∃ M', N = a ::ₘ M' ∧ OneStep M' M ∨ N = M + M' ∧ ∀ x ∈ M', x < a := by
classical
obtain ⟨X, Y, b, rfl, h0, h2⟩ := h
obtain rfl | hab := eq_or_ne a b
· refine ⟨Y, .inr ⟨?_, h2⟩⟩
simpa [add_comm _ {a}, singleton_add, eq_comm] using h0
refine ⟨Y + (M - {b}), .inl ⟨?_, M - {b}, Y, b, add_comm .., ?_, h2⟩⟩
· rw [← singleton_add, add_comm] at h0
rw [tsub_eq_tsub_of_add_eq_add h0, add_comm Y, ← singleton_add, ← add_assoc,
add_tsub_cancel_of_le]
have : a ∈ X + {b} := by simp [← h0]
simpa [hab] using this
· rw [tsub_add_cancel_of_le]
have : b ∈ a ::ₘ M := by simp [h0]
simpa [hab.symm] using this
private lemma acc_oneStep_cons_of_acc_lt (ha : Acc LT.lt a) :
∀ {M}, Acc OneStep M → Acc OneStep (a ::ₘ M) := by
induction' ha with a _ ha
rintro M hM
induction' hM with M hM ihM
refine .intro _ fun N hNM ↦ ?_
obtain ⟨N, ⟨rfl, hNM'⟩ | ⟨rfl, hN⟩⟩ := isDershowitzMannaLT_singleton_insert hNM
· exact ihM _ hNM'
clear hNM
induction N using Multiset.induction with
| empty =>
simpa using .intro _ hM
| @cons b N ihN =>
simp only [mem_cons, forall_eq_or_imp, add_cons] at hN ⊢
obtain ⟨hba, hN⟩ := hN
exact ha _ hba <| ihN hN
/-- If all elements of a multiset `M` are accessible with `<`, then the multiset `M` is
accessible given the `OneStep` relation. -/
private lemma acc_oneStep_of_acc_lt (hM : ∀ x ∈ M, Acc LT.lt x) : Acc OneStep M := by
induction M using Multiset.induction_on with
| empty =>
constructor
simp [OneStep, eq_comm (b := _ + _)]
| cons a M ih =>
exact acc_oneStep_cons_of_acc_lt (hM _ <| mem_cons_self ..) <| ih fun x hx ↦
hM _ <| mem_cons_of_mem hx
/-- Over a well-founded order, `OneStep` is well-founded. -/
private lemma isDershowitzMannaLT_singleton_wf [WellFoundedLT α] :
WellFounded (OneStep : Multiset α → Multiset α → Prop) :=
⟨fun _M ↦ acc_oneStep_of_acc_lt fun a _ ↦ WellFoundedLT.apply a⟩
private lemma transGen_oneStep_of_isDershowitzMannaLT :
IsDershowitzMannaLT M N → TransGen OneStep M N := by
classical
rintro ⟨X, Y, Z, hZ, hM, hN, hYZ⟩
induction' Z using Multiset.induction_on with z Z ih generalizing X Y M N
· simp at hZ
obtain rfl | hZ := eq_or_ne Z 0
· exact .single ⟨X, Y, z, hM, hN, by simpa using hYZ⟩
let Y' : Multiset α := Y.filter (· < z)
refine .tail (b := X + Y' + Z) (ih (X + Y') (Y - Y') hZ ?_ rfl fun y hy ↦ ?_) <|
⟨X + Z, Y', z, add_right_comm .., by simp [hN, add_comm (_ + _)], by simp [Y']⟩
· rw [add_add_tsub_cancel (filter_le ..), hM]
· simp only [sub_filter_eq_filter_not, mem_filter, Y'] at hy
simpa [hy.2] using hYZ y (by aesop)
private lemma isDershowitzMannaLT_of_transGen_oneStep (hMN : TransGen OneStep M N) :
IsDershowitzMannaLT M N :=
hMN.trans_induction_on (by rintro _ _ ⟨X, Y, a, rfl, rfl, hYa⟩; exact ⟨X, Y, {a}, by simpa⟩)
fun _ _ ↦ .trans
/-- `TransGen OneStep` and `IsDershowitzMannaLT` are equivalent. -/
private lemma transGen_oneStep_eq_isDershowitzMannaLT :
(TransGen OneStep : Multiset α → Multiset α → Prop) = IsDershowitzMannaLT := by
ext M N
exact ⟨isDershowitzMannaLT_of_transGen_oneStep, transGen_oneStep_of_isDershowitzMannaLT⟩
/-- Over a well-founded order, the Dershowitz-Manna order on multisets is well-founded. -/
theorem wellFounded_isDershowitzMannaLT [WellFoundedLT α] :
WellFounded (IsDershowitzMannaLT : Multiset α → Multiset α → Prop) := by
rw [← transGen_oneStep_eq_isDershowitzMannaLT]
exact isDershowitzMannaLT_singleton_wf.transGen
instance instWellFoundedIsDershowitzMannaLT [WellFoundedLT α] : WellFoundedRelation (Multiset α) :=
⟨IsDershowitzMannaLT, wellFounded_isDershowitzMannaLT⟩
end Multiset
|
Complex.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.Analysis.Complex.Basic
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
/-! # Equip `ℂ` with the Borel sigma-algebra -/
noncomputable section
instance (priority := 900) RCLike.measurableSpace {𝕜 : Type*} [RCLike 𝕜] : MeasurableSpace 𝕜 :=
borel 𝕜
instance (priority := 900) RCLike.borelSpace {𝕜 : Type*} [RCLike 𝕜] : BorelSpace 𝕜 :=
⟨rfl⟩
instance Complex.measurableSpace : MeasurableSpace ℂ :=
borel ℂ
instance Complex.borelSpace : BorelSpace ℂ :=
⟨rfl⟩
|
Init.lean
|
/-
Copyright (c) 2023 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import Mathlib.Init
import Aesop
/-!
# Category Theory Rule Set
This module defines the `CategoryTheory` Aesop rule set which is used by the
`aesop_cat` tactic. Aesop rule sets only become visible once the file in which
they're declared is imported, so we must put this declaration into its own file.
-/
declare_aesop_rule_sets [CategoryTheory]
/-- Option to control whether the category theory library should use `grind` or `aesop`
in the `cat_disch` tactic, which is widely used as an autoparameter. -/
register_option mathlib.tactic.category.grind : Bool := {
defValue := false
descr := "The category theory library should use `grind` instead of `aesop`."
}
/-- Log a message whenever the category theory discharger uses `grind`. -/
register_option mathlib.tactic.category.log_grind : Bool := {
defValue := false
descr := "Log a message whenever the category theory discharger uses `grind`."
}
/-- Log a message whenever the category theory discharger uses `aesop`. -/
register_option mathlib.tactic.category.log_aesop : Bool := {
defValue := false
descr := "Log a message whenever the category theory discharger uses `aesop`."
}
|
Basic.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.Tactic.Monotonicity.Attr
import Mathlib.Tactic.SetLike
import Mathlib.Data.Set.Basic
/-!
# Typeclass for types with a set-like extensionality property
The `Membership` typeclass is used to let terms of a type have elements.
Many instances of `Membership` have a set-like extensionality property:
things are equal iff they have the same elements. The `SetLike`
typeclass provides a unified interface to define a `Membership` that is
extensional in this way.
The main use of `SetLike` is for algebraic subobjects (such as
`Submonoid` and `Submodule`), whose non-proof data consists only of a
carrier set. In such a situation, the projection to the carrier set
is injective.
In general, a type `A` is `SetLike` with elements of type `B` if it
has an injective map to `Set B`. This module provides standard
boilerplate for every `SetLike`: a `coe_sort`, a `coe` to set, a
`PartialOrder`, and various extensionality and simp lemmas.
A typical subobject should be declared as:
```
structure MySubobject (X : Type*) [ObjectTypeclass X] where
(carrier : Set X)
(op_mem' : ∀ {x : X}, x ∈ carrier → sorry ∈ carrier)
namespace MySubobject
variable {X : Type*} [ObjectTypeclass X] {x : X}
instance : SetLike (MySubobject X) X :=
⟨MySubobject.carrier, fun p q h => by cases p; cases q; congr!⟩
@[simp] lemma mem_carrier {p : MySubobject X} : x ∈ p.carrier ↔ x ∈ (p : Set X) := Iff.rfl
@[ext] theorem ext {p q : MySubobject X} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q := SetLike.ext h
/-- Copy of a `MySubobject` with a new `carrier` equal to the old one. Useful to fix definitional
equalities. See Note [range copy pattern]. -/
protected def copy (p : MySubobject X) (s : Set X) (hs : s = ↑p) : MySubobject X :=
{ carrier := s
op_mem' := hs.symm ▸ p.op_mem' }
@[simp] lemma coe_copy (p : MySubobject X) (s : Set X) (hs : s = ↑p) :
(p.copy s hs : Set X) = s := rfl
lemma copy_eq (p : MySubobject X) (s : Set X) (hs : s = ↑p) : p.copy s hs = p :=
SetLike.coe_injective hs
end MySubobject
```
An alternative to `SetLike` could have been an extensional `Membership` typeclass:
```
class ExtMembership (α : out_param <| Type u) (β : Type v) extends Membership α β where
(ext_iff : ∀ {s t : β}, s = t ↔ ∀ (x : α), x ∈ s ↔ x ∈ t)
```
While this is equivalent, `SetLike` conveniently uses a carrier set projection directly.
## Tags
subobjects
-/
assert_not_exists RelIso
/-- A class to indicate that there is a canonical injection between `A` and `Set B`.
This has the effect of giving terms of `A` elements of type `B` (through a `Membership`
instance) and a compatible coercion to `Type*` as a subtype.
Note: if `SetLike.coe` is a projection, implementers should create a simp lemma such as
```
@[simp] lemma mem_carrier {p : MySubobject X} : x ∈ p.carrier ↔ x ∈ (p : Set X) := Iff.rfl
```
to normalize terms.
If you declare an unbundled subclass of `SetLike`, for example:
```
class MulMemClass (S : Type*) (M : Type*) [Mul M] [SetLike S M] where
...
```
Then you should *not* repeat the `outParam` declaration so `SetLike` will supply the value instead.
This ensures your subclass will not have issues with synthesis of the `[Mul M]` parameter starting
before the value of `M` is known.
-/
@[notation_class* carrier Simps.findCoercionArgs]
class SetLike (A : Type*) (B : outParam Type*) where
/-- The coercion from a term of a `SetLike` to its corresponding `Set`. -/
protected coe : A → Set B
/-- The coercion from a term of a `SetLike` to its corresponding `Set` is injective. -/
protected coe_injective' : Function.Injective coe
attribute [coe] SetLike.coe
namespace SetLike
variable {A : Type*} {B : Type*} [i : SetLike A B]
instance : CoeTC A (Set B) where coe := SetLike.coe
instance (priority := 100) instMembership : Membership B A :=
⟨fun p x => x ∈ (p : Set B)⟩
instance (priority := 100) : CoeSort A (Type _) :=
⟨fun p => { x : B // x ∈ p }⟩
section Delab
open Lean PrettyPrinter.Delaborator SubExpr
/-- For terms that match the `CoeSort` instance's body, pretty print as `↥S`
rather than as `{ x // x ∈ S }`. The discriminating feature is that membership
uses the `SetLike.instMembership` instance. -/
@[app_delab Subtype]
def delabSubtypeSetLike : Delab := whenPPOption getPPNotation do
let #[_, .lam n _ body _] := (← getExpr).getAppArgs | failure
guard <| body.isAppOf ``Membership.mem
let #[_, _, inst, _, .bvar 0] := body.getAppArgs | failure
guard <| inst.isAppOfArity ``instMembership 3
let S ← withAppArg <| withBindingBody n <| withNaryArg 3 delab
`(↥$S)
end Delab
variable (p q : A)
@[simp, norm_cast]
theorem coe_sort_coe : ((p : Set B) : Type _) = p :=
rfl
variable {p q}
protected theorem «exists» {q : p → Prop} : (∃ x, q x) ↔ ∃ (x : B) (h : x ∈ p), q ⟨x, ‹_›⟩ :=
SetCoe.exists
protected theorem «forall» {q : p → Prop} : (∀ x, q x) ↔ ∀ (x : B) (h : x ∈ p), q ⟨x, ‹_›⟩ :=
SetCoe.forall
theorem coe_injective : Function.Injective (SetLike.coe : A → Set B) := fun _ _ h =>
SetLike.coe_injective' h
@[simp, norm_cast]
theorem coe_set_eq : (p : Set B) = q ↔ p = q :=
coe_injective.eq_iff
@[norm_cast] lemma coe_ne_coe : (p : Set B) ≠ q ↔ p ≠ q := coe_injective.ne_iff
theorem ext' (h : (p : Set B) = q) : p = q :=
coe_injective h
theorem ext'_iff : p = q ↔ (p : Set B) = q :=
coe_set_eq.symm
/-- Note: implementers of `SetLike` must copy this lemma in order to tag it with `@[ext]`. -/
theorem ext (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q :=
coe_injective <| Set.ext h
theorem ext_iff : p = q ↔ ∀ x, x ∈ p ↔ x ∈ q :=
coe_injective.eq_iff.symm.trans Set.ext_iff
@[simp]
theorem mem_coe {x : B} : x ∈ (p : Set B) ↔ x ∈ p :=
Iff.rfl
@[simp, norm_cast]
theorem coe_eq_coe {x y : p} : (x : B) = y ↔ x = y :=
Subtype.ext_iff_val.symm
@[simp]
theorem coe_mem (x : p) : (x : B) ∈ p :=
x.2
@[aesop 5% (rule_sets := [SetLike!])]
lemma mem_of_subset {s : Set B} (hp : s ⊆ p) {x : B} (hx : x ∈ s) : x ∈ p := hp hx
@[simp]
protected theorem eta (x : p) (hx : (x : B) ∈ p) : (⟨x, hx⟩ : p) = x := rfl
@[simp] lemma setOf_mem_eq (a : A) : {b | b ∈ a} = a := rfl
instance (priority := 100) instPartialOrder : PartialOrder A :=
{ PartialOrder.lift (SetLike.coe : A → Set B) coe_injective with
le := fun H K => ∀ ⦃x⦄, x ∈ H → x ∈ K }
theorem le_def {S T : A} : S ≤ T ↔ ∀ ⦃x : B⦄, x ∈ S → x ∈ T :=
Iff.rfl
@[simp, norm_cast] lemma coe_subset_coe {S T : A} : (S : Set B) ⊆ T ↔ S ≤ T := .rfl
@[simp, norm_cast] lemma coe_ssubset_coe {S T : A} : (S : Set B) ⊂ T ↔ S < T := .rfl
@[gcongr low] -- lower priority than `Set.mem_of_subset_of_mem`
protected alias ⟨GCongr.mem_of_le_of_mem, _⟩ := le_def
@[gcongr] protected alias ⟨_, GCongr.coe_subset_coe⟩ := coe_subset_coe
@[gcongr] protected alias ⟨_, GCongr.coe_ssubset_coe⟩ := coe_ssubset_coe
@[mono]
theorem coe_mono : Monotone (SetLike.coe : A → Set B) := fun _ _ => coe_subset_coe.mpr
@[mono]
theorem coe_strictMono : StrictMono (SetLike.coe : A → Set B) := fun _ _ => coe_ssubset_coe.mpr
theorem not_le_iff_exists : ¬p ≤ q ↔ ∃ x ∈ p, x ∉ q :=
Set.not_subset
theorem exists_of_lt : p < q → ∃ x ∈ q, x ∉ p :=
Set.exists_of_ssubset
theorem lt_iff_le_and_exists : p < q ↔ p ≤ q ∧ ∃ x ∈ q, x ∉ p := by
rw [lt_iff_le_not_ge, not_le_iff_exists]
/-- membership is inherited from `Set X` -/
abbrev instSubtypeSet {X} {p : Set X → Prop} : SetLike {s // p s} X where
coe := (↑)
coe_injective' := Subtype.val_injective
/-- membership is inherited from `S` -/
abbrev instSubtype {X S} [SetLike S X] {p : S → Prop} : SetLike {s // p s} X where
coe := (↑)
coe_injective' := SetLike.coe_injective.comp Subtype.val_injective
section
attribute [local instance] instSubtypeSet instSubtype
@[simp] lemma mem_mk_set {X} {p : Set X → Prop} {U : Set X} {h : p U} {x : X} :
x ∈ Subtype.mk U h ↔ x ∈ U := Iff.rfl
@[simp] lemma mem_mk {X S} [SetLike S X] {p : S → Prop} {U : S} {h : p U} {x : X} :
x ∈ Subtype.mk U h ↔ x ∈ U := Iff.rfl
end
end SetLike
|
Quotient.lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Eric Wieser
-/
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.Ideal.Nonunits
import Mathlib.RingTheory.Ideal.Quotient.Defs
/-!
# Characteristic of quotient rings
-/
universe u v
namespace CharP
theorem ker_intAlgebraMap_eq_span
{R : Type*} [Ring R] (p : ℕ) [CharP R p] :
RingHom.ker (algebraMap ℤ R) = Ideal.span {(p : ℤ)} := by
ext a
simp [CharP.intCast_eq_zero_iff R p, Ideal.mem_span_singleton]
theorem quotient (R : Type u) [CommRing R] (p : ℕ) [hp1 : Fact p.Prime] (hp2 : ↑p ∈ nonunits R) :
CharP (R ⧸ (Ideal.span ({(p : R)} : Set R) : Ideal R)) p :=
have hp0 : (p : R ⧸ (Ideal.span {(p : R)} : Ideal R)) = 0 :=
map_natCast (Ideal.Quotient.mk (Ideal.span {(p : R)} : Ideal R)) p ▸
Ideal.Quotient.eq_zero_iff_mem.2 (Ideal.subset_span <| Set.mem_singleton _)
ringChar.of_eq <|
Or.resolve_left ((Nat.dvd_prime hp1.1).1 <| ringChar.dvd hp0) fun h1 =>
hp2 <|
isUnit_iff_dvd_one.2 <|
Ideal.mem_span_singleton.1 <|
Ideal.Quotient.eq_zero_iff_mem.1 <|
@Subsingleton.elim _ (@CharOne.subsingleton _ _ (ringChar.of_eq h1)) _ _
/-- If an ideal does not contain any coercions of natural numbers other than zero, then its quotient
inherits the characteristic of the underlying ring. -/
theorem quotient' {R : Type*} [CommRing R] (p : ℕ) [CharP R p] (I : Ideal R)
(h : ∀ x : ℕ, (x : R) ∈ I → (x : R) = 0) : CharP (R ⧸ I) p :=
⟨fun x => by
rw [← cast_eq_zero_iff R p x, ← map_natCast (Ideal.Quotient.mk I)]
refine Ideal.Quotient.eq.trans (?_ : ↑x - 0 ∈ I ↔ _)
rw [sub_zero]
exact ⟨h x, fun h' => h'.symm ▸ I.zero_mem⟩⟩
/-- `CharP.quotient'` as an `Iff`. -/
theorem quotient_iff {R : Type*} [CommRing R] (n : ℕ) [CharP R n] (I : Ideal R) :
CharP (R ⧸ I) n ↔ ∀ x : ℕ, ↑x ∈ I → (x : R) = 0 := by
refine ⟨fun _ x hx => ?_, CharP.quotient' n I⟩
rw [CharP.cast_eq_zero_iff R n, ← CharP.cast_eq_zero_iff (R ⧸ I) n _]
exact (Submodule.Quotient.mk_eq_zero I).mpr hx
/-- `CharP.quotient_iff`, but stated in terms of inclusions of ideals. -/
theorem quotient_iff_le_ker_natCast {R : Type*} [CommRing R] (n : ℕ) [CharP R n] (I : Ideal R) :
CharP (R ⧸ I) n ↔ I.comap (Nat.castRingHom R) ≤ RingHom.ker (Nat.castRingHom R) := by
rw [CharP.quotient_iff, RingHom.ker_eq_comap_bot]; rfl
end CharP
theorem Ideal.Quotient.index_eq_zero {R : Type*} [CommRing R] (I : Ideal R) :
(↑I.toAddSubgroup.index : R ⧸ I) = 0 := by
rw [AddSubgroup.index, Nat.card_eq]
split_ifs with hq; swap
· simp
letI : Fintype (R ⧸ I) := @Fintype.ofFinite _ hq
exact Nat.cast_card_eq_zero (R ⧸ I)
|
Basic.lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Algebra.Subalgebra.Tower
import Mathlib.Algebra.Field.IsField
import Mathlib.Algebra.Field.Subfield.Basic
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.RingTheory.LocalRing.Basic
/-!
# Intermediate fields
Let `L / K` be a field extension, given as an instance `Algebra K L`.
This file defines the type of fields in between `K` and `L`, `IntermediateField K L`.
An `IntermediateField K L` is a subfield of `L` which contains (the image of) `K`,
i.e. it is a `Subfield L` and a `Subalgebra K L`.
## Main definitions
* `IntermediateField K L` : the type of intermediate fields between `K` and `L`.
* `Subalgebra.to_intermediateField`: turns a subalgebra closed under `⁻¹`
into an intermediate field
* `Subfield.to_intermediateField`: turns a subfield containing the image of `K`
into an intermediate field
* `IntermediateField.map`: map an intermediate field along an `AlgHom`
* `IntermediateField.restrict_scalars`: restrict the scalars of an intermediate field to a smaller
field in a tower of fields.
## Implementation notes
Intermediate fields are defined with a structure extending `Subfield` and `Subalgebra`.
A `Subalgebra` is closed under all operations except `⁻¹`,
## Tags
intermediate field, field extension
-/
open Polynomial
variable (K L L' : Type*) [Field K] [Field L] [Field L'] [Algebra K L] [Algebra K L']
/-- `S : IntermediateField K L` is a subset of `L` such that there is a field
tower `L / S / K`. -/
structure IntermediateField extends Subalgebra K L where
inv_mem' : ∀ x ∈ carrier, x⁻¹ ∈ carrier
/-- Reinterpret an `IntermediateField` as a `Subalgebra`. -/
add_decl_doc IntermediateField.toSubalgebra
variable {K L L'}
variable (S : IntermediateField K L)
namespace IntermediateField
instance : SetLike (IntermediateField K L) L :=
⟨fun S => S.toSubalgebra.carrier, by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp ⟩
protected theorem neg_mem {x : L} (hx : x ∈ S) : -x ∈ S := by
change -x ∈S.toSubalgebra; simpa
/-- Reinterpret an `IntermediateField` as a `Subfield`. -/
def toSubfield : Subfield L :=
{ S.toSubalgebra with
neg_mem' := S.neg_mem,
inv_mem' := S.inv_mem' }
instance : SubfieldClass (IntermediateField K L) L where
add_mem {s} := s.add_mem'
zero_mem {s} := s.zero_mem'
neg_mem {s} := s.neg_mem
mul_mem {s} := s.mul_mem'
one_mem {s} := s.one_mem'
inv_mem {s} := s.inv_mem' _
theorem mem_carrier {s : IntermediateField K L} {x : L} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
/-- Two intermediate fields are equal if they have the same elements. -/
@[ext]
theorem ext {S T : IntermediateField K L} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
@[simp]
theorem coe_toSubalgebra : (S.toSubalgebra : Set L) = S :=
rfl
@[simp]
theorem coe_toSubfield : (S.toSubfield : Set L) = S :=
rfl
@[simp]
theorem coe_type_toSubalgebra : (S.toSubalgebra : Type _) = S :=
rfl
@[simp]
theorem coe_type_toSubfield : (S.toSubfield : Type _) = S :=
rfl
@[simp]
theorem mem_mk (s : Subsemiring L) (hK : ∀ x, algebraMap K L x ∈ s) (hi) (x : L) :
x ∈ IntermediateField.mk (Subalgebra.mk s hK) hi ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mem_toSubalgebra (s : IntermediateField K L) (x : L) : x ∈ s.toSubalgebra ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mem_toSubfield (s : IntermediateField K L) (x : L) : x ∈ s.toSubfield ↔ x ∈ s :=
Iff.rfl
theorem toSubalgebra_strictMono :
StrictMono (IntermediateField.toSubalgebra : _ → Subalgebra K L) := fun _ _ h ↦ h
/-- Copy of an intermediate field with a new `carrier` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (S : IntermediateField K L) (s : Set L) (hs : s = ↑S) :
IntermediateField K L where
toSubalgebra := S.toSubalgebra.copy s hs
inv_mem' := hs.symm ▸ S.inv_mem'
@[simp]
theorem coe_copy (S : IntermediateField K L) (s : Set L) (hs : s = ↑S) :
(S.copy s hs : Set L) = s :=
rfl
theorem copy_eq (S : IntermediateField K L) (s : Set L) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
section InheritedLemmas
/-! ### Lemmas inherited from more general structures
The declarations in this section derive from the fact that an `IntermediateField` is also a
subalgebra or subfield. Their use should be replaceable with the corresponding lemma from a
subobject class.
-/
/-- An intermediate field contains the image of the smaller field. -/
theorem algebraMap_mem (x : K) : algebraMap K L x ∈ S :=
S.algebraMap_mem' x
/-- An intermediate field is closed under scalar multiplication. -/
theorem smul_mem {y : L} : y ∈ S → ∀ {x : K}, x • y ∈ S :=
S.toSubalgebra.smul_mem
/-- An intermediate field contains the ring's 1. -/
protected theorem one_mem : (1 : L) ∈ S :=
one_mem S
/-- An intermediate field contains the ring's 0. -/
protected theorem zero_mem : (0 : L) ∈ S :=
zero_mem S
/-- An intermediate field is closed under multiplication. -/
protected theorem mul_mem {x y : L} : x ∈ S → y ∈ S → x * y ∈ S :=
mul_mem
/-- An intermediate field is closed under addition. -/
protected theorem add_mem {x y : L} : x ∈ S → y ∈ S → x + y ∈ S :=
add_mem
/-- An intermediate field is closed under subtraction. -/
protected theorem sub_mem {x y : L} : x ∈ S → y ∈ S → x - y ∈ S :=
sub_mem
/-- An intermediate field is closed under inverses. -/
protected theorem inv_mem {x : L} : x ∈ S → x⁻¹ ∈ S :=
inv_mem
/-- An intermediate field is closed under division. -/
protected theorem div_mem {x y : L} : x ∈ S → y ∈ S → x / y ∈ S :=
div_mem
/-- Product of a list of elements in an intermediate field is in the intermediate field. -/
protected theorem list_prod_mem {l : List L} : (∀ x ∈ l, x ∈ S) → l.prod ∈ S :=
list_prod_mem
/-- Sum of a list of elements in an intermediate field is in the intermediate field. -/
protected theorem list_sum_mem {l : List L} : (∀ x ∈ l, x ∈ S) → l.sum ∈ S :=
list_sum_mem
/-- Product of a multiset of elements in an intermediate field is in the intermediate field. -/
protected theorem multiset_prod_mem (m : Multiset L) : (∀ a ∈ m, a ∈ S) → m.prod ∈ S :=
multiset_prod_mem m
/-- Sum of a multiset of elements in an `IntermediateField` is in the `IntermediateField`. -/
protected theorem multiset_sum_mem (m : Multiset L) : (∀ a ∈ m, a ∈ S) → m.sum ∈ S :=
multiset_sum_mem m
/-- Product of elements of an intermediate field indexed by a `Finset` is in the intermediate field.
-/
protected theorem prod_mem {ι : Type*} {t : Finset ι} {f : ι → L} (h : ∀ c ∈ t, f c ∈ S) :
(∏ i ∈ t, f i) ∈ S :=
prod_mem h
/-- Sum of elements in an `IntermediateField` indexed by a `Finset` is in the `IntermediateField`.
-/
protected theorem sum_mem {ι : Type*} {t : Finset ι} {f : ι → L} (h : ∀ c ∈ t, f c ∈ S) :
(∑ i ∈ t, f i) ∈ S :=
sum_mem h
protected theorem pow_mem {x : L} (hx : x ∈ S) (n : ℤ) : x ^ n ∈ S :=
zpow_mem hx n
protected theorem zsmul_mem {x : L} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=
zsmul_mem hx n
protected theorem intCast_mem (n : ℤ) : (n : L) ∈ S :=
intCast_mem S n
protected theorem coe_add (x y : S) : (↑(x + y) : L) = ↑x + ↑y :=
rfl
protected theorem coe_neg (x : S) : (↑(-x) : L) = -↑x :=
rfl
protected theorem coe_mul (x y : S) : (↑(x * y) : L) = ↑x * ↑y :=
rfl
protected theorem coe_inv (x : S) : (↑x⁻¹ : L) = (↑x)⁻¹ :=
rfl
protected theorem coe_zero : ((0 : S) : L) = 0 :=
rfl
protected theorem coe_one : ((1 : S) : L) = 1 :=
rfl
protected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n : S) : L) = (x : L) ^ n :=
SubmonoidClass.coe_pow x n
end InheritedLemmas
theorem natCast_mem (n : ℕ) : (n : L) ∈ S := by simp
instance instSMulMemClass : SMulMemClass (IntermediateField K L) K L where
smul_mem := fun _ _ hx ↦ IntermediateField.smul_mem _ hx
end IntermediateField
/-- Turn a subalgebra closed under inverses into an intermediate field. -/
def Subalgebra.toIntermediateField (S : Subalgebra K L) (inv_mem : ∀ x ∈ S, x⁻¹ ∈ S) :
IntermediateField K L :=
{ S with
inv_mem' := inv_mem }
@[simp]
theorem toSubalgebra_toIntermediateField (S : Subalgebra K L) (inv_mem : ∀ x ∈ S, x⁻¹ ∈ S) :
(S.toIntermediateField inv_mem).toSubalgebra = S := by
ext
rfl
@[simp]
theorem toIntermediateField_toSubalgebra (S : IntermediateField K L) :
(S.toSubalgebra.toIntermediateField fun _ => S.inv_mem) = S := by
ext
rfl
/-- Turn a subalgebra satisfying `IsField` into an intermediate field. -/
def Subalgebra.toIntermediateField' (S : Subalgebra K L) (hS : IsField S) : IntermediateField K L :=
S.toIntermediateField fun x hx => by
by_cases hx0 : x = 0
· rw [hx0, inv_zero]
exact S.zero_mem
letI hS' := hS.toField
obtain ⟨y, hy⟩ := hS.mul_inv_cancel (show (⟨x, hx⟩ : S) ≠ 0 from Subtype.coe_ne_coe.1 hx0)
rw [Subtype.ext_iff, S.coe_mul, S.coe_one, Subtype.coe_mk, mul_eq_one_iff_inv_eq₀ hx0] at hy
exact hy.symm ▸ y.2
@[simp]
theorem toSubalgebra_toIntermediateField' (S : Subalgebra K L) (hS : IsField S) :
(S.toIntermediateField' hS).toSubalgebra = S := by
ext
rfl
@[simp]
theorem toIntermediateField'_toSubalgebra (S : IntermediateField K L) :
S.toSubalgebra.toIntermediateField' (Field.toIsField S) = S := by
ext
rfl
/-- Turn a subfield of `L` containing the image of `K` into an intermediate field. -/
def Subfield.toIntermediateField (S : Subfield L) (algebra_map_mem : ∀ x, algebraMap K L x ∈ S) :
IntermediateField K L :=
{ S with
algebraMap_mem' := algebra_map_mem }
@[simp]
theorem Subfield.toIntermediateField_toSubfield (S : Subfield L)
(algebra_map_mem : ∀ x, (algebraMap K L) x ∈ S) :
(S.toIntermediateField algebra_map_mem).toSubfield = S := rfl
@[simp]
theorem Subfield.coe_toIntermediateField (S : Subfield L)
(algebra_map_mem : ∀ x, (algebraMap K L) x ∈ S) :
((S.toIntermediateField algebra_map_mem) : Set L) = S := rfl
namespace IntermediateField
/-- An intermediate field inherits a field structure. -/
instance toField : Field S :=
S.toSubfield.toField
@[norm_cast]
theorem coe_sum {ι : Type*} [Fintype ι] (f : ι → S) : (↑(∑ i, f i) : L) = ∑ i, (f i : L) :=
AddSubmonoidClass.coe_finset_sum f Finset.univ
@[norm_cast]
theorem coe_prod {ι : Type*} [Fintype ι] (f : ι → S) : (↑(∏ i, f i) : L) = ∏ i, (f i : L) :=
SubmonoidClass.coe_finset_prod f Finset.univ
/-!
`IntermediateField`s inherit structure from their `Subfield` coercions.
-/
variable {X Y}
/-- The action by an intermediate field is the action by the underlying field. -/
instance [SMul L X] (F : IntermediateField K L) : SMul F X :=
inferInstanceAs (SMul F.toSubfield X)
theorem smul_def [SMul L X] {F : IntermediateField K L} (g : F) (m : X) : g • m = (g : L) • m :=
rfl
instance smulCommClass_left [SMul L Y] [SMul X Y] [SMulCommClass L X Y]
(F : IntermediateField K L) : SMulCommClass F X Y :=
inferInstanceAs (SMulCommClass F.toSubfield X Y)
instance smulCommClass_right [SMul X Y] [SMul L Y] [SMulCommClass X L Y]
(F : IntermediateField K L) : SMulCommClass X F Y :=
inferInstanceAs (SMulCommClass X F.toSubfield Y)
-- note: giving this instance the default priority may trigger trouble with synthesizing instances
-- for field extensions with more than one intermediate field. For example, in a field extension
-- `E/F`, and with `K₁ ≤ K₂` of type `IntermediateField F E`, this instance will cause a search
-- for `IsScalarTower K₁ K₂ E` to trigger a search for `IsScalarTower E K₂ E` which may
-- take a long time to fail.
/-- Note that this provides `IsScalarTower F K K` which is needed by `smul_mul_assoc`. -/
instance (priority := 900) [SMul X Y] [SMul L X] [SMul L Y] [IsScalarTower L X Y]
(F : IntermediateField K L) : IsScalarTower F X Y :=
inferInstanceAs (IsScalarTower F.toSubfield X Y)
instance [SMul L X] [FaithfulSMul L X] (F : IntermediateField K L) : FaithfulSMul F X :=
inferInstanceAs (FaithfulSMul F.toSubfield X)
/-- The action by an intermediate field is the action by the underlying field. -/
instance [MulAction L X] (F : IntermediateField K L) : MulAction F X :=
inferInstanceAs (MulAction F.toSubfield X)
/-- The action by an intermediate field is the action by the underlying field. -/
instance [AddMonoid X] [DistribMulAction L X] (F : IntermediateField K L) : DistribMulAction F X :=
inferInstanceAs (DistribMulAction F.toSubfield X)
/-- The action by an intermediate field is the action by the underlying field. -/
instance [Monoid X] [MulDistribMulAction L X] (F : IntermediateField K L) :
MulDistribMulAction F X :=
inferInstanceAs (MulDistribMulAction F.toSubfield X)
/-- The action by an intermediate field is the action by the underlying field. -/
instance [Zero X] [SMulWithZero L X] (F : IntermediateField K L) : SMulWithZero F X :=
inferInstanceAs (SMulWithZero F.toSubfield X)
/-- The action by an intermediate field is the action by the underlying field. -/
instance [Zero X] [MulActionWithZero L X] (F : IntermediateField K L) : MulActionWithZero F X :=
inferInstanceAs (MulActionWithZero F.toSubfield X)
/-- The action by an intermediate field is the action by the underlying field. -/
instance [AddCommMonoid X] [Module L X] (F : IntermediateField K L) : Module F X :=
inferInstanceAs (Module F.toSubfield X)
/-- The action by an intermediate field is the action by the underlying field. -/
instance [Semiring X] [MulSemiringAction L X] (F : IntermediateField K L) : MulSemiringAction F X :=
inferInstanceAs (MulSemiringAction F.toSubfield X)
/-! `IntermediateField`s inherit structure from their `Subalgebra` coercions. -/
instance toAlgebra : Algebra S L :=
inferInstanceAs (Algebra S.toSubalgebra L)
instance module' {R} [Semiring R] [SMul R K] [Module R L] [IsScalarTower R K L] : Module R S :=
inferInstanceAs (Module R S.toSubalgebra)
instance algebra' {R' K L : Type*} [Field K] [Field L] [Algebra K L] (S : IntermediateField K L)
[CommSemiring R'] [SMul R' K] [Algebra R' L] [IsScalarTower R' K L] : Algebra R' S :=
inferInstanceAs (Algebra R' S.toSubalgebra)
instance isScalarTower {R} [Semiring R] [SMul R K] [Module R L] [IsScalarTower R K L] :
IsScalarTower R K S :=
inferInstanceAs (IsScalarTower R K S.toSubalgebra)
@[simp]
theorem coe_smul {R} [SMul R K] [SMul R L] [IsScalarTower R K L] (r : R) (x : S) :
↑(r • x : S) = (r • (x : L)) :=
rfl
@[simp] lemma algebraMap_apply (x : S) : algebraMap S L x = x := rfl
@[simp] lemma coe_algebraMap_apply (x : K) : ↑(algebraMap K S x) = algebraMap K L x := rfl
instance isScalarTower_bot {R : Type*} [Semiring R] [Algebra L R] : IsScalarTower S L R :=
IsScalarTower.subalgebra _ _ _ S.toSubalgebra
instance isScalarTower_mid {R : Type*} [Semiring R] [Algebra L R] [Algebra K R]
[IsScalarTower K L R] : IsScalarTower K S R :=
IsScalarTower.subalgebra' _ _ _ S.toSubalgebra
/-- Specialize `isScalarTower_mid` to the common case where the top field is `L`. -/
instance isScalarTower_mid' : IsScalarTower K S L :=
inferInstance
instance {E} [Semiring E] [Algebra L E] : Algebra S E := inferInstanceAs (Algebra S.toSubalgebra E)
section shortcut_instances
variable {E} [Field E] [Algebra L E] (T : IntermediateField S E) {S}
instance : Algebra S T := T.algebra
instance : Module S T := Algebra.toModule
instance : SMul S T := Algebra.toSMul
instance [Algebra K E] [IsScalarTower K L E] : IsScalarTower K S T := T.isScalarTower
end shortcut_instances
/-- Given `f : L →ₐ[K] L'`, `S.comap f` is the intermediate field between `K` and `L`
such that `f x ∈ S ↔ x ∈ S.comap f`. -/
def comap (f : L →ₐ[K] L') (S : IntermediateField K L') : IntermediateField K L where
__ := S.toSubalgebra.comap f
inv_mem' x hx := show f x⁻¹ ∈ S by rw [map_inv₀ f x]; exact S.inv_mem hx
/-- Given `f : L →ₐ[K] L'`, `S.map f` is the intermediate field between `K` and `L'`
such that `x ∈ S ↔ f x ∈ S.map f`. -/
def map (f : L →ₐ[K] L') (S : IntermediateField K L) : IntermediateField K L' where
__ := S.toSubalgebra.map f
inv_mem' := by
rintro _ ⟨x, hx, rfl⟩
exact ⟨x⁻¹, S.inv_mem hx, map_inv₀ f x⟩
@[simp]
theorem coe_map (f : L →ₐ[K] L') : (S.map f : Set L') = f '' S :=
rfl
@[simp]
theorem toSubalgebra_map (f : L →ₐ[K] L') : (S.map f).toSubalgebra = S.toSubalgebra.map f :=
rfl
@[simp]
theorem toSubfield_map (f : L →ₐ[K] L') : (S.map f).toSubfield = S.toSubfield.map f :=
rfl
/-- Mapping intermediate fields along the identity does not change them. -/
theorem map_id : S.map (AlgHom.id K L) = S :=
SetLike.coe_injective <| Set.image_id _
theorem map_map {K L₁ L₂ L₃ : Type*} [Field K] [Field L₁] [Algebra K L₁] [Field L₂] [Algebra K L₂]
[Field L₃] [Algebra K L₃] (E : IntermediateField K L₁) (f : L₁ →ₐ[K] L₂) (g : L₂ →ₐ[K] L₃) :
(E.map f).map g = E.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
theorem map_mono (f : L →ₐ[K] L') {S T : IntermediateField K L} (h : S ≤ T) :
S.map f ≤ T.map f :=
SetLike.coe_mono (Set.image_mono h)
theorem map_le_iff_le_comap {f : L →ₐ[K] L'}
{s : IntermediateField K L} {t : IntermediateField K L'} :
s.map f ≤ t ↔ s ≤ t.comap f :=
Set.image_subset_iff
theorem gc_map_comap (f : L →ₐ[K] L') : GaloisConnection (map f) (comap f) :=
fun _ _ ↦ map_le_iff_le_comap
/-- Given an equivalence `e : L ≃ₐ[K] L'` of `K`-field extensions and an intermediate
field `E` of `L/K`, `intermediateFieldMap e E` is the induced equivalence
between `E` and `E.map e`. -/
def intermediateFieldMap (e : L ≃ₐ[K] L') (E : IntermediateField K L) : E ≃ₐ[K] E.map e.toAlgHom :=
e.subalgebraMap E.toSubalgebra
theorem intermediateFieldMap_apply_coe (e : L ≃ₐ[K] L') (E : IntermediateField K L) (a : E) :
↑(intermediateFieldMap e E a) = e a :=
rfl
theorem intermediateFieldMap_symm_apply_coe (e : L ≃ₐ[K] L') (E : IntermediateField K L)
(a : E.map e.toAlgHom) : ↑((intermediateFieldMap e E).symm a) = e.symm a :=
rfl
end IntermediateField
namespace AlgHom
variable (f : L →ₐ[K] L')
/-- The range of an algebra homomorphism, as an intermediate field. -/
@[simps toSubalgebra]
def fieldRange : IntermediateField K L' :=
{ f.range, (f : L →+* L').fieldRange with }
@[simp]
theorem coe_fieldRange : ↑f.fieldRange = Set.range f :=
rfl
@[simp]
theorem fieldRange_toSubfield : f.fieldRange.toSubfield = (f : L →+* L').fieldRange :=
rfl
variable {f}
@[simp]
theorem mem_fieldRange {y : L'} : y ∈ f.fieldRange ↔ ∃ x, f x = y :=
Iff.rfl
end AlgHom
namespace IntermediateField
/-- The embedding from an intermediate field of `L / K` to `L`. -/
def val : S →ₐ[K] L :=
S.toSubalgebra.val
@[simp]
theorem coe_val : ⇑S.val = ((↑) : S → L) :=
rfl
@[simp]
theorem val_mk {x : L} (hx : x ∈ S) : S.val ⟨x, hx⟩ = x :=
rfl
theorem range_val : S.val.range = S.toSubalgebra :=
S.toSubalgebra.range_val
@[simp]
theorem fieldRange_val : S.val.fieldRange = S :=
SetLike.ext' Subtype.range_val
instance AlgHom.inhabited : Inhabited (S →ₐ[K] L) :=
⟨S.val⟩
theorem aeval_coe {R : Type*} [CommSemiring R] [Algebra R K] [Algebra R L] [IsScalarTower R K L]
(x : S) (P : R[X]) : aeval (x : L) P = aeval x P :=
aeval_algHom_apply (S.val.restrictScalars R) x P
/-- The map `E → F` when `E` is an intermediate field contained in the intermediate field `F`.
This is the intermediate field version of `Subalgebra.inclusion`. -/
def inclusion {E F : IntermediateField K L} (hEF : E ≤ F) : E →ₐ[K] F :=
Subalgebra.inclusion hEF
theorem inclusion_injective {E F : IntermediateField K L} (hEF : E ≤ F) :
Function.Injective (inclusion hEF) :=
Subalgebra.inclusion_injective hEF
@[simp]
theorem inclusion_self {E : IntermediateField K L} : inclusion (le_refl E) = AlgHom.id K E :=
Subalgebra.inclusion_self
@[simp]
theorem inclusion_inclusion {E F G : IntermediateField K L} (hEF : E ≤ F) (hFG : F ≤ G) (x : E) :
inclusion hFG (inclusion hEF x) = inclusion (le_trans hEF hFG) x :=
Subalgebra.inclusion_inclusion hEF hFG x
@[simp]
theorem coe_inclusion {E F : IntermediateField K L} (hEF : E ≤ F) (e : E) :
(inclusion hEF e : L) = e :=
rfl
variable {S}
theorem toSubalgebra_injective : Function.Injective (toSubalgebra : IntermediateField K L → _) := by
intro _ _ h
ext
simp_rw [← mem_toSubalgebra, h]
theorem toSubfield_injective : Function.Injective (toSubfield : IntermediateField K L → _) := by
intro _ _ h
ext
simp_rw [← mem_toSubfield, h]
variable {F E : IntermediateField K L}
@[simp]
theorem toSubalgebra_inj : F.toSubalgebra = E.toSubalgebra ↔ F = E := toSubalgebra_injective.eq_iff
@[simp]
theorem toSubfield_inj : F.toSubfield = E.toSubfield ↔ F = E := toSubfield_injective.eq_iff
theorem map_injective (f : L →ₐ[K] L') : Function.Injective (map f) := by
intro _ _ h
rwa [← toSubalgebra_injective.eq_iff, toSubalgebra_map, toSubalgebra_map,
(Subalgebra.map_injective f.injective).eq_iff, toSubalgebra_inj] at h
variable (S)
theorem set_range_subset : Set.range (algebraMap K L) ⊆ S :=
S.toSubalgebra.range_subset
theorem fieldRange_le : (algebraMap K L).fieldRange ≤ S.toSubfield := fun x hx =>
S.toSubalgebra.range_subset (by rwa [Set.mem_range, ← RingHom.mem_fieldRange])
@[simp]
theorem toSubalgebra_le_toSubalgebra {S S' : IntermediateField K L} :
S.toSubalgebra ≤ S'.toSubalgebra ↔ S ≤ S' :=
Iff.rfl
@[simp]
theorem toSubalgebra_lt_toSubalgebra {S S' : IntermediateField K L} :
S.toSubalgebra < S'.toSubalgebra ↔ S < S' :=
Iff.rfl
variable {S}
section Tower
/-- Lift an intermediate field of an intermediate field. -/
def lift {F : IntermediateField K L} (E : IntermediateField K F) : IntermediateField K L :=
E.map (val F)
theorem lift_injective (F : IntermediateField K L) : Function.Injective F.lift :=
map_injective F.val
theorem lift_le {F : IntermediateField K L} (E : IntermediateField K F) : lift E ≤ F := by
rintro _ ⟨x, _, rfl⟩
exact x.2
theorem mem_lift {F : IntermediateField K L} {E : IntermediateField K F} (x : F) :
x.1 ∈ lift E ↔ x ∈ E :=
Subtype.val_injective.mem_set_image
/-- The algEquiv between an intermediate field and its lift. -/
def liftAlgEquiv {E : IntermediateField K L} (F : IntermediateField K E) : ↥F ≃ₐ[K] lift F where
toFun x := ⟨x.1.1, (mem_lift x.1).mpr x.2⟩
invFun x := ⟨⟨x.1, lift_le F x.2⟩, (mem_lift ⟨x.1, lift_le F x.2⟩).mp x.2⟩
left_inv := congrFun rfl
right_inv := congrFun rfl
map_mul' _ _ := rfl
map_add' _ _ := rfl
commutes' _ := rfl
lemma liftAlgEquiv_apply {E : IntermediateField K L} (F : IntermediateField K E) (x : F) :
(liftAlgEquiv F x).1 = x := rfl
section RestrictScalars
variable (K)
variable [Algebra L' L] [IsScalarTower K L' L]
/-- Given a tower `L / ↥E / L' / K` of field extensions, where `E` is an `L'`-intermediate field of
`L`, reinterpret `E` as a `K`-intermediate field of `L`. -/
def restrictScalars (E : IntermediateField L' L) : IntermediateField K L :=
{ E.toSubfield, E.toSubalgebra.restrictScalars K with
carrier := E.carrier }
@[simp]
theorem coe_restrictScalars {E : IntermediateField L' L} :
(restrictScalars K E : Set L) = (E : Set L) :=
rfl
@[simp]
theorem restrictScalars_toSubalgebra {E : IntermediateField L' L} :
(E.restrictScalars K).toSubalgebra = E.toSubalgebra.restrictScalars K :=
SetLike.coe_injective rfl
@[simp]
theorem restrictScalars_toSubfield {E : IntermediateField L' L} :
(E.restrictScalars K).toSubfield = E.toSubfield :=
SetLike.coe_injective rfl
@[simp]
theorem mem_restrictScalars {E : IntermediateField L' L} {x : L} :
x ∈ restrictScalars K E ↔ x ∈ E :=
Iff.rfl
theorem restrictScalars_injective :
Function.Injective (restrictScalars K : IntermediateField L' L → IntermediateField K L) :=
fun U V H => ext fun x => by rw [← mem_restrictScalars K, H, mem_restrictScalars]
end RestrictScalars
/-- This was formerly an instance called `lift2_alg`, but an instance above already provides it. -/
example {F : IntermediateField K L} {E : IntermediateField F L} : Algebra K E := by infer_instance
end Tower
section equivMap
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
{K : Type*} [Field K] [Algebra F K] (L : IntermediateField F E) (f : E →ₐ[F] K)
/-- Construct an algebra isomorphism from an equality of intermediate fields. -/
@[simps! apply]
def equivOfEq {S T : IntermediateField F E} (h : S = T) : S ≃ₐ[F] T :=
Subalgebra.equivOfEq _ _ (congr_arg toSubalgebra h)
@[simp]
theorem equivOfEq_symm {S T : IntermediateField F E} (h : S = T) :
(equivOfEq h).symm = equivOfEq h.symm :=
rfl
@[simp]
theorem equivOfEq_rfl (S : IntermediateField F E) : equivOfEq (rfl : S = S) = AlgEquiv.refl :=
AlgEquiv.ext fun _ ↦ rfl
@[simp]
theorem equivOfEq_trans {S T U : IntermediateField F E} (hST : S = T) (hTU : T = U) :
(equivOfEq hST).trans (equivOfEq hTU) = equivOfEq (hST.trans hTU) :=
rfl
theorem fieldRange_comp_val : (f.comp L.val).fieldRange = L.map f := toSubalgebra_injective <| by
rw [toSubalgebra_map, AlgHom.fieldRange_toSubalgebra, AlgHom.range_comp, range_val]
/-- An intermediate field is isomorphic to its image under an `AlgHom`
(which is automatically injective). -/
noncomputable def equivMap : L ≃ₐ[F] L.map f :=
(AlgEquiv.ofInjective _ (f.comp L.val).injective).trans (equivOfEq (fieldRange_comp_val L f))
@[simp]
theorem coe_equivMap_apply (x : L) : ↑(equivMap L f x) = f x := rfl
end equivMap
end IntermediateField
section ExtendScalars
namespace Subfield
variable {F E E' : Subfield L} (h : F ≤ E) (h' : F ≤ E') {x : L}
/-- If `F ≤ E` are two subfields of `L`, then `E` is also an intermediate field of
`L / F`. It can be viewed as an inverse to `IntermediateField.toSubfield`. -/
def extendScalars : IntermediateField F L := E.toIntermediateField fun ⟨_, hf⟩ ↦ h hf
@[simp]
theorem coe_extendScalars : (extendScalars h : Set L) = (E : Set L) := rfl
@[simp]
theorem extendScalars_toSubfield : (extendScalars h).toSubfield = E := SetLike.coe_injective rfl
@[simp]
theorem mem_extendScalars : x ∈ extendScalars h ↔ x ∈ E := Iff.rfl
theorem extendScalars_le_extendScalars_iff : extendScalars h ≤ extendScalars h' ↔ E ≤ E' := Iff.rfl
theorem extendScalars_le_iff (E' : IntermediateField F L) :
extendScalars h ≤ E' ↔ E ≤ E'.toSubfield := Iff.rfl
theorem le_extendScalars_iff (E' : IntermediateField F L) :
E' ≤ extendScalars h ↔ E'.toSubfield ≤ E := Iff.rfl
variable (F)
/-- `Subfield.extendScalars.orderIso` bundles `Subfield.extendScalars`
into an order isomorphism from
`{ E : Subfield L // F ≤ E }` to `IntermediateField F L`. Its inverse is
`IntermediateField.toSubfield`. -/
@[simps]
def extendScalars.orderIso :
{ E : Subfield L // F ≤ E } ≃o IntermediateField F L where
toFun E := extendScalars E.2
invFun E := ⟨E.toSubfield, fun x hx ↦ E.algebraMap_mem ⟨x, hx⟩⟩
map_rel_iff' {E E'} := by
simp only [Equiv.coe_fn_mk]
exact extendScalars_le_extendScalars_iff _ _
theorem extendScalars_injective :
Function.Injective fun E : { E : Subfield L // F ≤ E } ↦ extendScalars E.2 :=
(extendScalars.orderIso F).injective
end Subfield
namespace IntermediateField
variable {F E E' : IntermediateField K L} (h : F ≤ E) (h' : F ≤ E') {x : L}
/-- If `F ≤ E` are two intermediate fields of `L / K`, then `E` is also an intermediate field of
`L / F`. It can be viewed as an inverse to `IntermediateField.restrictScalars`. -/
def extendScalars : IntermediateField F L :=
Subfield.extendScalars (show F.toSubfield ≤ E.toSubfield from h)
@[simp]
theorem coe_extendScalars : (extendScalars h : Set L) = (E : Set L) := rfl
@[simp]
theorem extendScalars_toSubfield : (extendScalars h).toSubfield = E.toSubfield :=
SetLike.coe_injective rfl
@[simp]
theorem mem_extendScalars : x ∈ extendScalars h ↔ x ∈ E := Iff.rfl
@[simp]
theorem extendScalars_restrictScalars : (extendScalars h).restrictScalars K = E := rfl
theorem extendScalars_le_extendScalars_iff : extendScalars h ≤ extendScalars h' ↔ E ≤ E' := Iff.rfl
theorem extendScalars_le_iff (E' : IntermediateField F L) :
extendScalars h ≤ E' ↔ E ≤ E'.restrictScalars K := Iff.rfl
theorem le_extendScalars_iff (E' : IntermediateField F L) :
E' ≤ extendScalars h ↔ E'.restrictScalars K ≤ E := Iff.rfl
variable (F)
/-- `IntermediateField.extendScalars.orderIso` bundles `IntermediateField.extendScalars`
into an order isomorphism from
`{ E : IntermediateField K L // F ≤ E }` to `IntermediateField F L`. Its inverse is
`IntermediateField.restrictScalars`. -/
@[simps]
def extendScalars.orderIso : { E : IntermediateField K L // F ≤ E } ≃o IntermediateField F L where
toFun E := extendScalars E.2
invFun E := ⟨E.restrictScalars K, fun x hx ↦ E.algebraMap_mem ⟨x, hx⟩⟩
map_rel_iff' {E E'} := by
simp only [Equiv.coe_fn_mk]
exact extendScalars_le_extendScalars_iff _ _
theorem extendScalars_injective :
Function.Injective fun E : { E : IntermediateField K L // F ≤ E } ↦ extendScalars E.2 :=
(extendScalars.orderIso F).injective
end IntermediateField
end ExtendScalars
namespace IntermediateField
variable {S}
section Tower
section Restrict
variable {F E : IntermediateField K L} (h : F ≤ E)
/--
If `F ≤ E` are two intermediate fields of `L / K`, then `F` is also an intermediate field of
`E / K`. It is an inverse of `IntermediateField.lift`, and can be viewed as a dual to
`IntermediateField.extendScalars`.
-/
def restrict : IntermediateField K E :=
(IntermediateField.inclusion h).fieldRange
theorem mem_restrict (x : E) : x ∈ restrict h ↔ x.1 ∈ F :=
Set.ext_iff.mp (Set.range_inclusion h) x
@[simp]
theorem lift_restrict : lift (restrict h) = F := by
ext x
refine ⟨fun hx ↦ ?_, fun hx ↦ ?_⟩
· let y : E := ⟨x, lift_le (restrict h) hx⟩
exact (mem_restrict h y).1 ((mem_lift y).1 hx)
· let y : E := ⟨x, h hx⟩
exact (mem_lift y).2 ((mem_restrict h y).2 hx)
/--
`F` is equivalent to `F` as an intermediate field of `E / K`.
-/
noncomputable def restrict_algEquiv :
F ≃ₐ[K] ↥(IntermediateField.restrict h) :=
AlgEquiv.ofInjectiveField _
end Restrict
end Tower
end IntermediateField
|
countalg.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import fintype bigop ssralg.
(*****************************************************************************)
(* The algebraic part of the algebraic hierarchy for countable types *)
(* *)
(* This file clones part of ssralg hierarchy for countable types; it does *)
(* not cover the left module / algebra interfaces, providing only *)
(* countNmodType == countable nmodType interface *)
(* countZmodType == countable zmodType interface *)
(* countPzSemiRingType == countable pzSemiRingType interface *)
(* countNzSemiRingType == countable nzSemiRingType interface *)
(* countPzRingType == countable pzRingType interface *)
(* countNzRingType == countable nzRingType interface *)
(* countComPzSemiRingType == countable comPzSemiRingType interface *)
(* countComNzSemiRingType == countable comNzSemiRingType interface *)
(* countComPzRingType == countable comPzRingType interface *)
(* countComNzRingType == countable comNzRingType interface *)
(* countUnitRingType == countable unitRingType interface *)
(* countComUnitRingType == countable comUnitRingType interface *)
(* countIdomainType == countable idomainType interface *)
(* countFieldType == countable fieldType interface *)
(* countDecFieldType == countable decFieldType interface *)
(* countClosedFieldType == countable closedFieldType interface *)
(* *)
(* This file provides constructions for both simple extension and algebraic *)
(* closure of countable fields. *)
(*****************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import GRing.Theory CodeSeq.
Module CountRing.
Import GRing.Theory.
#[short(type="countNmodType")]
HB.structure Definition Nmodule := {M of GRing.Nmodule M & Countable M}.
#[short(type="countZmodType")]
HB.structure Definition Zmodule := {M of GRing.Zmodule M & Countable M}.
#[short(type="countPzSemiRingType")]
HB.structure Definition PzSemiRing := {R of GRing.PzSemiRing R & Countable R}.
#[short(type="countNzSemiRingType")]
HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing instead.")]
Notation SemiRing R := (NzSemiRing R) (only parsing).
Module SemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing.sort instead.")]
Notation sort := (NzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing.on instead.")]
Notation on R := (NzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing.copy instead.")]
Notation copy T U := (NzSemiRing.copy T U) (only parsing).
End SemiRing.
#[short(type="countPzRingType")]
HB.structure Definition PzRing := {R of GRing.PzRing R & Countable R}.
#[short(type="countNzRingType")]
HB.structure Definition NzRing := {R of GRing.NzRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing instead.")]
Notation Ring R := (NzRing R) (only parsing).
Module Ring.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing.sort instead.")]
Notation sort := (NzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing.on instead.")]
Notation on R := (NzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing.copy instead.")]
Notation copy T U := (NzRing.copy T U) (only parsing).
End Ring.
#[short(type="countComPzSemiRingType")]
HB.structure Definition ComPzSemiRing :=
{R of GRing.ComPzSemiRing R & Countable R}.
#[short(type="countComNzSemiRingType")]
HB.structure Definition ComNzSemiRing :=
{R of GRing.ComNzSemiRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing instead.")]
Notation ComSemiRing R := (ComNzSemiRing R) (only parsing).
Module ComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing.sort instead.")]
Notation sort := (ComNzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing.on instead.")]
Notation on R := (ComNzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing.copy instead.")]
Notation copy T U := (ComNzSemiRing.copy T U) (only parsing).
End ComSemiRing.
#[short(type="countComPzRingType")]
HB.structure Definition ComPzRing := {R of GRing.ComPzRing R & Countable R}.
#[short(type="countComNzRingType")]
HB.structure Definition ComNzRing := {R of GRing.ComNzRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing instead.")]
Notation ComRing R := (ComNzRing R) (only parsing).
Module ComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing.sort instead.")]
Notation sort := (ComNzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing.on instead.")]
Notation on R := (ComNzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing.copy instead.")]
Notation copy T U := (ComNzRing.copy T U) (only parsing).
End ComRing.
#[short(type="countUnitRingType")]
HB.structure Definition UnitRing := {R of GRing.UnitRing R & Countable R}.
#[short(type="countComUnitRingType")]
HB.structure Definition ComUnitRing := {R of GRing.ComUnitRing R & Countable R}.
#[short(type="countIdomainType")]
HB.structure Definition IntegralDomain :=
{R of GRing.IntegralDomain R & Countable R}.
#[short(type="countFieldType")]
HB.structure Definition Field := {R of GRing.Field R & Countable R}.
#[short(type="countDecFieldType")]
HB.structure Definition DecidableField :=
{R of GRing.DecidableField R & Countable R}.
#[short(type="countClosedFieldType")]
HB.structure Definition ClosedField := {R of GRing.ClosedField R & Countable R}.
Module ReguralExports.
HB.instance Definition _ (R : countType) := Countable.on R^o.
HB.instance Definition _ (R : countNmodType) := Nmodule.on R^o.
HB.instance Definition _ (R : countZmodType) := Zmodule.on R^o.
HB.instance Definition _ (R : countPzSemiRingType) := PzSemiRing.on R^o.
HB.instance Definition _ (R : countNzSemiRingType) := NzSemiRing.on R^o.
HB.instance Definition _ (R : countPzRingType) := PzRing.on R^o.
HB.instance Definition _ (R : countNzRingType) := NzRing.on R^o.
HB.instance Definition _ (R : countComPzSemiRingType) := ComPzSemiRing.on R^o.
HB.instance Definition _ (R : countComNzSemiRingType) := ComNzSemiRing.on R^o.
HB.instance Definition _ (R : countComPzRingType) := ComPzRing.on R^o.
HB.instance Definition _ (R : countComNzRingType) := ComNzRing.on R^o.
HB.instance Definition _ (R : countUnitRingType) := UnitRing.on R^o.
HB.instance Definition _ (R : countComUnitRingType) := ComUnitRing.on R^o.
HB.instance Definition _ (R : countIdomainType) := IntegralDomain.on R^o.
HB.instance Definition _ (R : countFieldType) := Field.on R^o.
HB.instance Definition _ (R : countDecFieldType) := DecidableField.on R^o.
HB.instance Definition _ (R : countClosedFieldType) := ClosedField.on R^o.
End ReguralExports.
HB.export ReguralExports.
End CountRing.
Import CountRing.
HB.reexport.
#[deprecated(since="mathcomp 2.4.0",
note="Use countNzSemiRingType instead.")]
Notation countSemiRingType := (countNzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use countNzRingType instead.")]
Notation countRingType := (countNzRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use countComNzSemiRingType instead.")]
Notation countComSemiRingType := (countComNzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use countComNzRingType instead.")]
Notation countComRingType := (countComNzRingType) (only parsing).
|
fingroup.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 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 *)
(* baseFinGroupType == the structure for finite types with a monoid law *)
(* and an involutive antimorphism; finGroupType is *)
(* derived from baseFinGroupType *)
(* The HB class is called BaseFinGroup. *)
(* FinGroupType mulVg == the finGroupType structure for an existing *)
(* baseFinGroupType 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 baseFinGroupType 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 (via Import GroupScope). *)
(* 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 baseFinGroupType, *)
(* 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.
(* This module can be imported to open the scope for group element *)
(* operations locally to a file, without exporting the Open to *)
(* clients of that file (as Open would do). *)
Module GroupScope.
Open Scope group_scope.
End GroupScope.
Import GroupScope.
(* 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 ']' ]").
(* We split the group axiomatisation in two. We define a *)
(* class of "base groups", which are basically monoids *)
(* with an involutive antimorphism, from which we derive *)
(* the class of groups proper. This allows us to reuse *)
(* much of the group notation and algebraic axioms for *)
(* group subsets, by defining a base group class on them. *)
(* We use class/mixins here rather than telescopes to *)
(* be able to interoperate with the type coercions. *)
(* Another potential benefit (not exploited here) would *)
(* be to define a class for infinite groups, which could *)
(* share all of the algebraic laws. *)
HB.mixin Record isMulBaseGroup G := {
mulg_subdef : G -> G -> G;
oneg_subdef : G;
invg_subdef : G -> G;
mulgA_subproof : associative mulg_subdef ;
mul1g_subproof : left_id oneg_subdef mulg_subdef ;
invgK_subproof : involutive invg_subdef ;
invMg_subproof : {morph invg_subdef : x y / mulg_subdef x y >-> mulg_subdef y x}
}.
(* We want to use sort as a coercion class, both to infer *)
(* argument scopes properly, and to allow groups and cosets to *)
(* coerce to the base group of group subsets. *)
(* However, the return type of group operations should NOT be a *)
(* coercion class, since this would trump the real (head-normal) *)
(* coercion class for concrete group types, thus spoiling the *)
(* coercion of A * B to pred_sort in x \in A * B, or rho * tau to *)
(* ffun and Funclass in (rho * tau) x, when rho tau : perm T. *)
(* Therefore we define an alias of sort for argument types, and *)
(* make it the default coercion FinGroup.base_type >-> Sortclass *)
(* so that arguments of a functions whose parameters are of type, *)
(* say, gT : finGroupType, can be coerced to the coercion class *)
(* of arg_sort. Care should be taken, however, to declare the *)
(* return type of functions and operators as FinGroup.sort gT *)
(* rather than gT, e.g., mulg : gT -> gT -> FinGroup.sort gT. *)
(* Note that since we do this here and in quotient.v for all the *)
(* basic functions, the inferred return type should generally be *)
(* correct. *)
#[arg_sort, short(type="baseFinGroupType")]
HB.structure Definition BaseFinGroup := { G of isMulBaseGroup G & Finite G }.
Module BaseFinGroupExports.
Bind Scope group_scope with BaseFinGroup.arg_sort.
Bind Scope group_scope with BaseFinGroup.sort.
End BaseFinGroupExports.
HB.export BaseFinGroupExports.
Module Notations.
Section ElementOps.
Variable T : baseFinGroupType.
Notation rT := (BaseFinGroup.sort T).
Definition oneg : rT := Eval unfold oneg_subdef in @oneg_subdef T.
Definition mulg : T -> T -> rT := Eval unfold mulg_subdef in @mulg_subdef T.
Definition invg : T -> rT := Eval unfold invg_subdef in @invg_subdef T.
Definition expgn (x : T) n : rT := iterop n mulg x oneg.
End ElementOps.
Arguments expgn : simpl never.
Notation "1" := (@oneg _) : group_scope.
Notation "x1 * x2" := (mulg x1 x2) : group_scope.
Notation "x ^-1" := (invg x) : group_scope.
Notation "x ^+ n" := (expgn x n) : group_scope.
Notation "x ^- n" := (x ^+ n)^-1 : group_scope.
End Notations.
HB.export Notations.
HB.mixin Record BaseFinGroup_isGroup G of BaseFinGroup G := {
mulVg_subproof : left_inverse (@oneg G) (@invg _) (@mulg _)
}.
#[short(type="finGroupType")]
HB.structure Definition FinGroup :=
{ G of BaseFinGroup_isGroup G & BaseFinGroup G }.
Module FinGroupExports.
Bind Scope group_scope with FinGroup.sort.
End FinGroupExports.
HB.export FinGroupExports.
HB.factory Record isMulGroup G of Finite G := {
mulg : G -> G -> G;
oneg : G;
invg : G -> G;
mulgA : associative mulg;
mul1g : left_id oneg mulg;
mulVg : left_inverse oneg invg mulg;
}.
HB.builders Context G of isMulGroup G.
Notation "1" := oneg.
Infix "*" := mulg.
Notation "x ^-1" := (invg x).
Lemma mk_invgK : involutive invg.
Proof.
have mulV21 x: x^-1^-1 * 1 = x by rewrite -(mulVg x) mulgA mulVg mul1g.
by move=> x; rewrite -[_ ^-1]mulV21 -(mul1g 1) mulgA !mulV21.
Qed.
Lemma mk_invMg : {morph invg : x y / x * y >-> y * x}.
Proof.
have mulgV x: x * x^-1 = 1 by rewrite -{1}[x]mk_invgK mulVg.
move=> x y /=; rewrite -[y^-1 * _]mul1g -(mulVg (x * y)) -2!mulgA (mulgA y).
by rewrite mulgV mul1g mulgV -(mulgV (x * y)) mulgA mulVg mul1g.
Qed.
HB.instance Definition _ :=
isMulBaseGroup.Build G mulgA mul1g mk_invgK mk_invMg.
HB.instance Definition _ := BaseFinGroup_isGroup.Build G mulVg.
HB.end.
#[compress_coercions]
HB.instance Definition _ (T : baseFinGroupType) :
Finite (BaseFinGroup.arg_sort T) := Finite.class T.
(* Arguments of conjg are restricted to true groups to avoid an *)
(* improper interpretation of A ^ B with A and B sets, namely: *)
(* {x^-1 * (y * z) | y \in A, x, z \in B} *)
Definition conjg (T : finGroupType) (x y : T) := y^-1 * (x * y).
Notation "x1 ^ x2" := (conjg x1 x2) : group_scope.
Definition commg (T : finGroupType) (x y : T) := x^-1 * x ^ y.
Notation "[ ~ x1 , x2 , .. , xn ]" := (commg .. (commg x1 x2) .. xn)
: group_scope.
Prenex Implicits mulg invg expgn conjg commg.
Notation "\prod_ ( i <- r | P ) F" :=
(\big[mulg/1]_(i <- r | P%B) F%g) : group_scope.
Notation "\prod_ ( i <- r ) F" :=
(\big[mulg/1]_(i <- r) F%g) : group_scope.
Notation "\prod_ ( m <= i < n | P ) F" :=
(\big[mulg/1]_(m <= i < n | P%B) F%g) : group_scope.
Notation "\prod_ ( m <= i < n ) F" :=
(\big[mulg/1]_(m <= i < n) F%g) : group_scope.
Notation "\prod_ ( i | P ) F" :=
(\big[mulg/1]_(i | P%B) F%g) : group_scope.
Notation "\prod_ i F" :=
(\big[mulg/1]_i F%g) : group_scope.
Notation "\prod_ ( i : t | P ) F" :=
(\big[mulg/1]_(i : t | P%B) F%g) (only parsing) : group_scope.
Notation "\prod_ ( i : t ) F" :=
(\big[mulg/1]_(i : t) F%g) (only parsing) : group_scope.
Notation "\prod_ ( i < n | P ) F" :=
(\big[mulg/1]_(i < n | P%B) F%g) : group_scope.
Notation "\prod_ ( i < n ) F" :=
(\big[mulg/1]_(i < n) F%g) : group_scope.
Notation "\prod_ ( i 'in' A | P ) F" :=
(\big[mulg/1]_(i in A | P%B) F%g) : group_scope.
Notation "\prod_ ( i 'in' A ) F" :=
(\big[mulg/1]_(i in A) F%g) : group_scope.
Section PreGroupIdentities.
Variable T : baseFinGroupType.
Implicit Types x y z : T.
Local Notation mulgT := (@mulg T).
Lemma mulgA : associative mulgT. Proof. exact: mulgA_subproof. Qed.
Lemma mul1g : left_id 1 mulgT. Proof. exact: mul1g_subproof. Qed.
Lemma invgK : @involutive T invg. Proof. exact: invgK_subproof. Qed.
Lemma invMg x y : (x * y)^-1 = y^-1 * x^-1. Proof. exact: invMg_subproof. Qed.
Lemma invg_inj : @injective T T invg. Proof. exact: can_inj invgK. Qed.
Lemma eq_invg_sym x y : (x^-1 == y) = (x == y^-1).
Proof. by apply: (inv_eq invgK). Qed.
Lemma invg1 : 1^-1 = 1 :> T.
Proof. by apply: invg_inj; rewrite -{1}[1^-1]mul1g invMg invgK mul1g. Qed.
Lemma eq_invg1 x : (x^-1 == 1) = (x == 1).
Proof. by rewrite eq_invg_sym invg1. Qed.
Lemma mulg1 : right_id 1 mulgT.
Proof. by move=> x; apply: invg_inj; rewrite invMg invg1 mul1g. Qed.
HB.instance Definition _ := Monoid.isLaw.Build T 1 mulgT mulgA mul1g mulg1.
Lemma expgnE x n : x ^+ n = iterop n mulg x 1. Proof. by []. Qed.
Lemma expg0 x : x ^+ 0 = 1. Proof. by []. Qed.
Lemma expg1 x : x ^+ 1 = x. Proof. by []. Qed.
Lemma expgS x n : x ^+ n.+1 = x * x ^+ n.
Proof. by case: n => //; rewrite mulg1. Qed.
Lemma expg1n n : 1 ^+ n = 1 :> T.
Proof. by elim: n => // n IHn; rewrite expgS mul1g. Qed.
Lemma expgD x n m : x ^+ (n + m) = x ^+ n * x ^+ m.
Proof. by elim: n => [|n IHn]; rewrite ?mul1g // !expgS IHn mulgA. Qed.
Lemma expgSr x n : x ^+ n.+1 = x ^+ n * x.
Proof. by rewrite -addn1 expgD expg1. Qed.
Lemma expgM x n m : x ^+ (n * m) = x ^+ n ^+ m.
Proof.
elim: m => [|m IHm]; first by rewrite muln0 expg0.
by rewrite mulnS expgD IHm expgS.
Qed.
Lemma expgAC x m n : x ^+ m ^+ n = x ^+ n ^+ m.
Proof. by rewrite -!expgM mulnC. Qed.
Definition commute x y := x * y = y * x.
Lemma commute_refl x : commute x x.
Proof. by []. Qed.
Lemma commute_sym x y : commute x y -> commute y x.
Proof. by []. Qed.
Lemma commute1 x : commute x 1.
Proof. by rewrite /commute mulg1 mul1g. Qed.
Lemma commuteM x y z : commute x y -> commute x z -> commute x (y * z).
Proof. by move=> cxy cxz; rewrite /commute -mulgA -cxz !mulgA cxy. Qed.
Lemma commuteX x y n : commute x y -> commute x (y ^+ n).
Proof.
by move=> cxy; case: n; [apply: commute1 | elim=> // n; apply: commuteM].
Qed.
Lemma commuteX2 x y m n : commute x y -> commute (x ^+ m) (y ^+ n).
Proof. by move=> cxy; apply/commuteX/commute_sym/commuteX. Qed.
Lemma expgVn x n : x^-1 ^+ n = x ^- n.
Proof. by elim: n => [|n IHn]; rewrite ?invg1 // expgSr expgS invMg IHn. Qed.
Lemma expgMn x y n : commute x y -> (x * y) ^+ n = x ^+ n * y ^+ n.
Proof.
move=> cxy; elim: n => [|n IHn]; first by rewrite mulg1.
by rewrite !expgS IHn -mulgA (mulgA y) (commuteX _ (commute_sym cxy)) !mulgA.
Qed.
End PreGroupIdentities.
#[global] Hint Resolve commute1 : core.
Arguments invg_inj {T} [x1 x2].
Prenex Implicits commute invgK.
Section GroupIdentities.
Variable T : finGroupType.
Implicit Types x y z : T.
Local Notation mulgT := (@mulg T).
Lemma mulVg : left_inverse 1 invg mulgT. Proof. exact: mulVg_subproof. Qed.
Lemma mulgV : right_inverse 1 invg mulgT.
Proof. by move=> x; rewrite -{1}(invgK x) mulVg. Qed.
Lemma mulKg : left_loop invg mulgT.
Proof. by move=> x y; rewrite mulgA mulVg mul1g. Qed.
Lemma mulKVg : rev_left_loop invg mulgT.
Proof. by move=> x y; rewrite mulgA mulgV mul1g. Qed.
Lemma mulgI : right_injective mulgT.
Proof. by move=> x; apply: can_inj (mulKg x). Qed.
Lemma mulgK : right_loop invg mulgT.
Proof. by move=> x y; rewrite -mulgA mulgV mulg1. Qed.
Lemma mulgKV : rev_right_loop invg mulgT.
Proof. by move=> x y; rewrite -mulgA mulVg mulg1. Qed.
Lemma mulIg : left_injective mulgT.
Proof. by move=> x; apply: can_inj (mulgK x). Qed.
Lemma eq_invg_mul x y : (x^-1 == y :> T) = (x * y == 1 :> T).
Proof. by rewrite -(inj_eq (@mulgI x)) mulgV eq_sym. Qed.
Lemma eq_mulgV1 x y : (x == y) = (x * y^-1 == 1 :> T).
Proof. by rewrite -(inj_eq invg_inj) eq_invg_mul. Qed.
Lemma eq_mulVg1 x y : (x == y) = (x^-1 * y == 1 :> T).
Proof. by rewrite -eq_invg_mul invgK. Qed.
Lemma commuteV x y : commute x y -> commute x y^-1.
Proof. by move=> cxy; apply: (@mulIg y); rewrite mulgKV -mulgA cxy mulKg. Qed.
Lemma conjgE x y : x ^ y = y^-1 * (x * y). Proof. by []. Qed.
Lemma conjgC x y : x * y = y * x ^ y.
Proof. by rewrite mulKVg. Qed.
Lemma conjgCV x y : x * y = y ^ x^-1 * x.
Proof. by rewrite -mulgA mulgKV invgK. Qed.
Lemma conjg1 x : x ^ 1 = x.
Proof. by rewrite conjgE commute1 mulKg. Qed.
Lemma conj1g x : 1 ^ x = 1.
Proof. by rewrite conjgE mul1g mulVg. Qed.
Lemma conjMg x y z : (x * y) ^ z = x ^ z * y ^ z.
Proof. by rewrite !conjgE !mulgA mulgK. Qed.
Lemma conjgM x y z : x ^ (y * z) = (x ^ y) ^ z.
Proof. by rewrite !conjgE invMg !mulgA. Qed.
Lemma conjVg x y : x^-1 ^ y = (x ^ y)^-1.
Proof. by rewrite !conjgE !invMg invgK mulgA. Qed.
Lemma conjJg x y z : (x ^ y) ^ z = (x ^ z) ^ y ^ z.
Proof. by rewrite 2!conjMg conjVg. Qed.
Lemma conjXg x y n : (x ^+ n) ^ y = (x ^ y) ^+ n.
Proof. by elim: n => [|n IHn]; rewrite ?conj1g // !expgS conjMg IHn. Qed.
Lemma conjgK : @right_loop T T invg conjg.
Proof. by move=> y x; rewrite -conjgM mulgV conjg1. Qed.
Lemma conjgKV : @rev_right_loop T T invg conjg.
Proof. by move=> y x; rewrite -conjgM mulVg conjg1. Qed.
Lemma conjg_inj : @left_injective T T T conjg.
Proof. by move=> y; apply: can_inj (conjgK y). Qed.
Lemma conjg_eq1 x y : (x ^ y == 1) = (x == 1).
Proof. by rewrite (canF_eq (conjgK _)) conj1g. Qed.
Lemma conjg_prod I r (P : pred I) F z :
(\prod_(i <- r | P i) F i) ^ z = \prod_(i <- r | P i) (F i ^ z).
Proof.
by apply: (big_morph (conjg^~ z)) => [x y|]; rewrite ?conj1g ?conjMg.
Qed.
Lemma commgEl x y : [~ x, y] = x^-1 * x ^ y. Proof. by []. Qed.
Lemma commgEr x y : [~ x, y] = y^-1 ^ x * y.
Proof. by rewrite -!mulgA. Qed.
Lemma commgC x y : x * y = y * x * [~ x, y].
Proof. by rewrite -mulgA !mulKVg. Qed.
Lemma commgCV x y : x * y = [~ x^-1, y^-1] * (y * x).
Proof. by rewrite commgEl !mulgA !invgK !mulgKV. Qed.
Lemma conjRg x y z : [~ x, y] ^ z = [~ x ^ z, y ^ z].
Proof. by rewrite !conjMg !conjVg. Qed.
Lemma invg_comm x y : [~ x, y]^-1 = [~ y, x].
Proof. by rewrite commgEr conjVg invMg invgK. Qed.
Lemma commgP x y : reflect (commute x y) ([~ x, y] == 1 :> T).
Proof. by rewrite [[~ x, y]]mulgA -invMg -eq_mulVg1 eq_sym; apply: eqP. Qed.
Lemma conjg_fixP x y : reflect (x ^ y = x) ([~ x, y] == 1 :> T).
Proof. by rewrite -eq_mulVg1 eq_sym; apply: eqP. Qed.
Lemma commg1_sym x y : ([~ x, y] == 1 :> T) = ([~ y, x] == 1 :> T).
Proof. by rewrite -invg_comm (inv_eq invgK) invg1. Qed.
Lemma commg1 x : [~ x, 1] = 1.
Proof. exact/eqP/commgP. Qed.
Lemma comm1g x : [~ 1, x] = 1.
Proof. by rewrite -invg_comm commg1 invg1. Qed.
Lemma commgg x : [~ x, x] = 1.
Proof. exact/eqP/commgP. Qed.
Lemma commgXg x n : [~ x, x ^+ n] = 1.
Proof. exact/eqP/commgP/commuteX. Qed.
Lemma commgVg x : [~ x, x^-1] = 1.
Proof. exact/eqP/commgP/commuteV. Qed.
Lemma commgXVg x n : [~ x, x ^- n] = 1.
Proof. exact/eqP/commgP/commuteV/commuteX. Qed.
(* Other commg identities should slot in here. *)
End GroupIdentities.
#[global] Hint Rewrite mulg1 @mul1g invg1 @mulVg mulgV (@invgK) mulgK mulgKV
@invMg @mulgA : gsimpl.
Ltac gsimpl := autorewrite with gsimpl; try done.
Definition gsimp := (@mulg1, @mul1g, (@invg1, @invgK), (@mulgV, @mulVg)).
Definition gnorm := (gsimp, (@mulgK, @mulgKV, (@mulgA, @invMg))).
Arguments mulgI [T].
Arguments mulIg [T].
Arguments conjg_inj {T} x [x1 x2].
Arguments commgP {T x y}.
Arguments conjg_fixP {T x y}.
Section Repr.
(* Plucking a set representative. *)
Variable gT : baseFinGroupType.
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.
by rewrite /repr; case: ifP => // _; case: pickP => // A0; rewrite [x \in A]A0.
Qed.
Lemma card_mem_repr A : #|A| > 0 -> repr A \in A.
Proof. by rewrite lt0n => /existsP[x]; apply: mem_repr. Qed.
Lemma repr_set1 x : repr [set x] = x.
Proof. by apply/set1P/card_mem_repr; rewrite cards1. Qed.
Lemma repr_set0 : repr set0 = 1.
Proof. by rewrite /repr; case: pickP => [x|_] /[!inE]. Qed.
End Repr.
Arguments mem_repr [gT A].
Section BaseSetMulDef.
(* We only assume a baseFinGroupType to allow this construct to be iterated. *)
Variable gT : baseFinGroupType.
Implicit Types A B : {set gT}.
(* Set-lifted group operations. *)
Definition set_mulg A B := mulg @2: (A, B).
Definition set_invg A := invg @^-1: A.
(* The pre-group structure of group subsets. *)
Lemma set_mul1g : left_id [set 1] set_mulg.
Proof.
move=> A; apply/setP=> y; apply/imset2P/idP=> [[_ x /set1P-> Ax ->] | Ay].
by rewrite mul1g.
by exists (1 : gT) y; rewrite ?(set11, mul1g).
Qed.
Lemma set_mulgA : associative set_mulg.
Proof.
move=> A B C; apply/setP=> y.
apply/imset2P/imset2P=> [[x1 z Ax1 /imset2P[x2 x3 Bx2 Cx3 ->] ->]| [z x3]].
by exists (x1 * x2) x3; rewrite ?mulgA //; apply/imset2P; exists x1 x2.
case/imset2P=> x1 x2 Ax1 Bx2 -> Cx3 ->.
by exists x1 (x2 * x3); rewrite ?mulgA //; apply/imset2P; exists x2 x3.
Qed.
Lemma set_invgK : involutive set_invg.
Proof. by move=> A; apply/setP=> x; rewrite !inE invgK. Qed.
Lemma set_invgM : {morph set_invg : A B / set_mulg A B >-> set_mulg B A}.
Proof.
move=> A B; apply/setP=> z; rewrite inE.
apply/imset2P/imset2P=> [[x y Ax By /(canRL invgK)->] | [y x]].
by exists y^-1 x^-1; rewrite ?invMg // inE invgK.
by rewrite !inE => By1 Ax1 ->; exists x^-1 y^-1; rewrite ?invMg.
Qed.
HB.instance Definition set_base_group := isMulBaseGroup.Build (set_type gT)
set_mulgA set_mul1g set_invgK set_invgM.
HB.instance Definition _ : isMulBaseGroup {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 : baseFinGroupType) := {set gT}.
End GroupSet.
Identity Coercion GroupSet_of_sort : GroupSet.sort >-> set_of.
Module Type GroupSetBaseGroupSig.
Definition sort (gT : baseFinGroupType) := BaseFinGroup.arg_sort {set gT}.
End GroupSetBaseGroupSig.
Module MakeGroupSetBaseGroup (Gset_base : GroupSetBaseGroupSig).
Identity Coercion of_sort : Gset_base.sort >-> BaseFinGroup.arg_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 baseFinGroupType. *)
(* 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 := mulg x @: A.
Definition rcoset A x := mulg^~ 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 : baseFinGroupType.
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 mulg (mem A) (fun _ => mem B) x) (x \in A * B).
Proof. exact: imset2P. Qed.
Lemma mem_mulg A B x y : x \in A -> y \in B -> x * y \in A * B.
Proof. by move=> Ax By; apply/mulsgP; exists x y. Qed.
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.
have [r big_r [Ur mem_r] _] := big_enumP P.
pose inA c := all (fun i => c i \in A i); rewrite -big_r; set piAx := x \in _.
suffices{big_r} IHr: reflect (exists2 c, inA c r & x = \prod_(i <- r) c i) piAx.
apply: (iffP IHr) => -[c inAc ->]; do [exists c; last by rewrite big_r].
by move=> i Pi; rewrite (allP inAc) ?mem_r.
by apply/allP=> i; rewrite mem_r => /inAc.
elim: {P mem_r}r x @piAx Ur => /= [x _ | i r IHr x /andP[r'i /IHr{}IHr]].
by rewrite unlock; apply: (iffP set1P) => [-> | [] //]; exists (fun=> x).
rewrite big_cons; apply: (iffP idP) => [|[c /andP[Aci Ac] ->]]; last first.
by rewrite big_cons mem_mulg //; apply/IHr=> //; exists c.
case/mulsgP=> c_i _ Ac_i /IHr[c /allP-inAcr ->] ->{x}.
exists [eta c with i |-> c_i]; rewrite /= ?big_cons eqxx ?Ac_i.
by apply/allP=> j rj; rewrite /= ifN ?(memPn r'i) ?inAcr.
by congr (_ * _); apply: eq_big_seq => j rj; rewrite ifN ?(memPn r'i).
Qed.
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. by move=> Ac; apply/prodsgP; exists c. Qed.
Lemma mulSg A B C : A \subset B -> A * C \subset B * C.
Proof. exact: imset2Sl. Qed.
Lemma mulgS A B C : B \subset C -> A * B \subset A * C.
Proof. exact: imset2Sr. Qed.
Lemma mulgSS A B C D : A \subset B -> C \subset D -> A * C \subset B * D.
Proof. exact: imset2S. Qed.
Lemma mulg_subl A B : 1 \in B -> A \subset A * B.
Proof. by move=> B1; rewrite -{1}(mulg1 A) mulgS ?sub1set. Qed.
Lemma mulg_subr A B : 1 \in A -> B \subset A * B.
Proof. by move=> A1; rewrite -{1}(mul1g B) mulSg ?sub1set. Qed.
Lemma mulUg A B C : (A :|: B) * C = (A * C) :|: (B * C).
Proof. exact: imset2Ul. Qed.
Lemma mulgU A B C : A * (B :|: C) = (A * B) :|: (A * C).
Proof. exact: imset2Ur. Qed.
(* Set (pointwise) inverse. *)
Lemma invUg A B : (A :|: B)^-1 = A^-1 :|: B^-1.
Proof. exact: preimsetU. Qed.
Lemma invIg A B : (A :&: B)^-1 = A^-1 :&: B^-1.
Proof. exact: preimsetI. Qed.
Lemma invDg A B : (A :\: B)^-1 = A^-1 :\: B^-1.
Proof. exact: preimsetD. Qed.
Lemma invCg A : (~: A)^-1 = ~: A^-1.
Proof. exact: preimsetC. Qed.
Lemma invSg A B : (A^-1 \subset B^-1) = (A \subset B).
Proof. by rewrite !(sameP setIidPl eqP) -invIg (inj_eq invg_inj). Qed.
Lemma mem_invg x A : (x \in A^-1) = (x^-1 \in A).
Proof. by rewrite inE. Qed.
Lemma memV_invg x A : (x^-1 \in A^-1) = (x \in A).
Proof. by rewrite inE invgK. Qed.
Lemma card_invg A : #|A^-1| = #|A|.
Proof. exact/card_preimset/invg_inj. Qed.
(* Product with singletons. *)
Lemma set1gE : 1 = [set 1] :> {set gT}. Proof. by []. Qed.
Lemma set1gP x : reflect (x = 1) (x \in [1 gT]).
Proof. exact: set1P. Qed.
Lemma mulg_set1 x y : [set x] :* y = [set x * y].
Proof. by rewrite [_ * _]imset2_set1l imset_set1. Qed.
Lemma invg_set1 x : [set x]^-1 = [set x^-1].
Proof. by apply/setP=> y; rewrite !inE inv_eq //; apply: invgK. Qed.
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. by rewrite [_ * _]imset2_set1l. Qed.
Lemma card_lcoset A x : #|x *: A| = #|A|.
Proof. by rewrite -lcosetE (card_imset _ (mulgI _)). Qed.
Lemma mem_lcoset A x y : (y \in x *: A) = (x^-1 * y \in A).
Proof. by rewrite -lcosetE [_ x](can_imset_pre _ (mulKg _)) inE. Qed.
Lemma lcosetP A x y : reflect (exists2 a, a \in A & y = x * a) (y \in x *: A).
Proof. by rewrite -lcosetE; apply: imsetP. Qed.
Lemma lcosetsP A B C :
reflect (exists2 x, x \in B & C = x *: A) (C \in lcosets A B).
Proof. by apply: (iffP imsetP) => [] [x Bx ->]; exists x; rewrite ?lcosetE. Qed.
Lemma lcosetM A x y : (x * y) *: A = x *: (y *: A).
Proof. by rewrite -mulg_set1 mulgA. Qed.
Lemma lcoset1 A : 1 *: A = A.
Proof. exact: mul1g. Qed.
Lemma lcosetK : left_loop invg (fun x A => x *: A).
Proof. by move=> x A; rewrite -lcosetM mulVg mul1g. Qed.
Lemma lcosetKV : rev_left_loop invg (fun x A => x *: A).
Proof. by move=> x A; rewrite -lcosetM mulgV mul1g. Qed.
Lemma lcoset_inj : right_injective (fun x A => x *: A).
Proof. by move=> x; apply: can_inj (lcosetK x). Qed.
Lemma lcosetS x A B : (x *: A \subset x *: B) = (A \subset B).
Proof.
apply/idP/idP=> sAB; last exact: mulgS.
by rewrite -(lcosetK x A) -(lcosetK x B) mulgS.
Qed.
Lemma sub_lcoset x A B : (A \subset x *: B) = (x^-1 *: A \subset B).
Proof. by rewrite -(lcosetS x^-1) lcosetK. Qed.
Lemma sub_lcosetV x A B : (A \subset x^-1 *: B) = (x *: A \subset B).
Proof. by rewrite sub_lcoset invgK. Qed.
(* Right cosets. *)
Lemma rcosetE A x : rcoset A x = A :* x.
Proof. by rewrite [_ * _]imset2_set1r. Qed.
Lemma card_rcoset A x : #|A :* x| = #|A|.
Proof. by rewrite -rcosetE (card_imset _ (mulIg _)). Qed.
Lemma mem_rcoset A x y : (y \in A :* x) = (y * x^-1 \in A).
Proof. by rewrite -rcosetE [_ x](can_imset_pre A (mulgK _)) inE. Qed.
Lemma rcosetP A x y : reflect (exists2 a, a \in A & y = a * x) (y \in A :* x).
Proof. by rewrite -rcosetE; apply: imsetP. Qed.
Lemma rcosetsP A B C :
reflect (exists2 x, x \in B & C = A :* x) (C \in rcosets A B).
Proof. by apply: (iffP imsetP) => [] [x Bx ->]; exists x; rewrite ?rcosetE. Qed.
Lemma rcosetM A x y : A :* (x * y) = A :* x :* y.
Proof. by rewrite -mulg_set1 mulgA. Qed.
Lemma rcoset1 A : A :* 1 = A.
Proof. exact: mulg1. Qed.
Lemma rcosetK : right_loop invg (fun A x => A :* x).
Proof. by move=> x A; rewrite -rcosetM mulgV mulg1. Qed.
Lemma rcosetKV : rev_right_loop invg (fun A x => A :* x).
Proof. by move=> x A; rewrite -rcosetM mulVg mulg1. Qed.
Lemma rcoset_inj : left_injective (fun A x => A :* x).
Proof. by move=> x; apply: can_inj (rcosetK x). Qed.
Lemma rcosetS x A B : (A :* x \subset B :* x) = (A \subset B).
Proof.
apply/idP/idP=> sAB; last exact: mulSg.
by rewrite -(rcosetK x A) -(rcosetK x B) mulSg.
Qed.
Lemma sub_rcoset x A B : (A \subset B :* x) = (A :* x ^-1 \subset B).
Proof. by rewrite -(rcosetS x^-1) rcosetK. Qed.
Lemma sub_rcosetV x A B : (A \subset B :* x^-1) = (A :* x \subset B).
Proof. by rewrite sub_rcoset invgK. Qed.
(* Inverse maps lcosets to rcosets *)
Lemma invg_lcosets A B : (lcosets A B)^-1 = rcosets A^-1 B^-1.
Proof.
rewrite /A^-1/= - -[RHS]imset_comp -imset_comp.
by apply: eq_imset => x /=; rewrite lcosetE rcosetE invMg invg_set1.
Qed.
(* Conjugates. *)
Lemma conjg_preim A x : A :^ x = (conjg^~ x^-1) @^-1: A.
Proof. exact: can_imset_pre (conjgK _). Qed.
Lemma mem_conjg A x y : (y \in A :^ x) = (y ^ x^-1 \in A).
Proof. by rewrite conjg_preim inE. Qed.
Lemma mem_conjgV A x y : (y \in A :^ x^-1) = (y ^ x \in A).
Proof. by rewrite mem_conjg invgK. Qed.
Lemma memJ_conjg A x y : (y ^ x \in A :^ x) = (y \in A).
Proof. by rewrite mem_conjg conjgK. Qed.
Lemma conjsgE A x : A :^ x = x^-1 *: (A :* x).
Proof. by apply/setP=> y; rewrite mem_lcoset mem_rcoset -mulgA mem_conjg. Qed.
Lemma conjsg1 A : A :^ 1 = A.
Proof. by rewrite conjsgE invg1 mul1g mulg1. Qed.
Lemma conjsgM A x y : A :^ (x * y) = (A :^ x) :^ y.
Proof. by rewrite !conjsgE invMg -!mulg_set1 !mulgA. Qed.
Lemma conjsgK : @right_loop _ gT invg conjugate.
Proof. by move=> x A; rewrite -conjsgM mulgV conjsg1. Qed.
Lemma conjsgKV : @rev_right_loop _ gT invg conjugate.
Proof. by move=> x A; rewrite -conjsgM mulVg conjsg1. Qed.
Lemma conjsg_inj : @left_injective _ gT _ conjugate.
Proof. by move=> x; apply: can_inj (conjsgK x). Qed.
Lemma cardJg A x : #|A :^ x| = #|A|.
Proof. by rewrite (card_imset _ (conjg_inj x)). Qed.
Lemma conjSg A B x : (A :^ x \subset B :^ x) = (A \subset B).
Proof. by rewrite !conjsgE lcosetS rcosetS. Qed.
Lemma properJ A B x : (A :^ x \proper B :^ x) = (A \proper B).
Proof. by rewrite /proper !conjSg. Qed.
Lemma sub_conjg A B x : (A :^ x \subset B) = (A \subset B :^ x^-1).
Proof. by rewrite -(conjSg A _ x) conjsgKV. Qed.
Lemma sub_conjgV A B x : (A :^ x^-1 \subset B) = (A \subset B :^ x).
Proof. by rewrite -(conjSg _ B x) conjsgKV. Qed.
Lemma conjg_set1 x y : [set x] :^ y = [set x ^ y].
Proof. by rewrite [_ :^ _]imset_set1. Qed.
Lemma conjs1g x : 1 :^ x = 1.
Proof. by rewrite conjg_set1 conj1g. Qed.
Lemma conjsg_eq1 A x : (A :^ x == 1%g) = (A == 1%g).
Proof. by rewrite (canF_eq (conjsgK x)) conjs1g. Qed.
Lemma conjsMg A B x : (A * B) :^ x = A :^ x * B :^ x.
Proof. by rewrite !conjsgE !mulgA rcosetK. Qed.
Lemma conjIg A B x : (A :&: B) :^ x = A :^ x :&: B :^ x.
Proof. by rewrite !conjg_preim preimsetI. Qed.
Lemma conj0g x : set0 :^ x = set0.
Proof. exact: imset0. Qed.
Lemma conjTg x : [set: gT] :^ x = [set: gT].
Proof. by rewrite conjg_preim preimsetT. Qed.
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.
by rewrite (big_endo (conjugate^~ x)) => // [B1 B2|]; rewrite (conjTg, conjIg).
Qed.
Lemma conjUg A B x : (A :|: B) :^ x = A :^ x :|: B :^ x.
Proof. by rewrite !conjg_preim preimsetU. Qed.
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.
rewrite (big_endo (conjugate^~ x)) => // [B1 B2|]; first by rewrite conjUg.
exact: imset0.
Qed.
Lemma conjCg A x : (~: A) :^ x = ~: A :^ x.
Proof. by rewrite !conjg_preim preimsetC. Qed.
Lemma conjDg A B x : (A :\: B) :^ x = A :^ x :\: B :^ x.
Proof. by rewrite !setDE !(conjCg, conjIg). Qed.
Lemma conjD1g A x : A^# :^ x = (A :^ x)^#.
Proof. by rewrite conjDg conjs1g. Qed.
(* Classes; not much for now. *)
Lemma memJ_class x y A : y \in A -> x ^ y \in x ^: A.
Proof. exact: imset_f. Qed.
Lemma classS x A B : A \subset B -> x ^: A \subset x ^: B.
Proof. exact: imsetS. Qed.
Lemma class_set1 x y : x ^: [set y] = [set x ^ y].
Proof. exact: imset_set1. Qed.
Lemma class1g x A : x \in A -> 1 ^: A = 1.
Proof.
move=> Ax; apply/setP=> y.
by apply/imsetP/set1P=> [[a Aa]|] ->; last exists x; rewrite ?conj1g.
Qed.
Lemma classVg x A : x^-1 ^: A = (x ^: A)^-1.
Proof.
apply/setP=> xy; rewrite inE; apply/imsetP/imsetP=> [] [y Ay def_xy].
by rewrite def_xy conjVg invgK; exists y.
by rewrite -[xy]invgK def_xy -conjVg; exists y.
Qed.
Lemma mem_classes x A : x \in A -> x ^: A \in classes A.
Proof. exact: imset_f. Qed.
Lemma memJ_class_support A B x y :
x \in A -> y \in B -> x ^ y \in class_support A B.
Proof. by move=> Ax By; apply: imset2_f. Qed.
Lemma class_supportM A B C :
class_support A (B * C) = class_support (class_support A B) C.
Proof.
apply/setP=> x; apply/imset2P/imset2P=> [[a y Aa] | [y c]].
case/mulsgP=> b c Bb Cc -> ->{x y}.
by exists (a ^ b) c; rewrite ?(imset2_f, conjgM).
case/imset2P=> a b Aa Bb -> Cc ->{x y}.
by exists a (b * c); rewrite ?(mem_mulg, conjgM).
Qed.
Lemma class_support_set1l A x : class_support [set x] A = x ^: A.
Proof. exact: imset2_set1l. Qed.
Lemma class_support_set1r A x : class_support A [set x] = A :^ x.
Proof. exact: imset2_set1r. Qed.
Lemma classM x A B : x ^: (A * B) = class_support (x ^: A) B.
Proof. by rewrite -!class_support_set1l class_supportM. Qed.
Lemma class_lcoset x y A : x ^: (y *: A) = (x ^ y) ^: A.
Proof. by rewrite classM class_set1 class_support_set1l. Qed.
Lemma class_rcoset x A y : x ^: (A :* y) = (x ^: A) :^ y.
Proof. by rewrite -class_support_set1r classM. Qed.
(* Conjugate set. *)
Lemma conjugatesS A B C : B \subset C -> A :^: B \subset A :^: C.
Proof. exact: imsetS. Qed.
Lemma conjugates_set1 A x : A :^: [set x] = [set A :^ x].
Proof. exact: imset_set1. Qed.
Lemma conjugates_conj A x B : (A :^ x) :^: B = A :^: (x *: B).
Proof.
rewrite /conjugates [x *: B]imset2_set1l -imset_comp.
by apply: eq_imset => y /=; rewrite conjsgM.
Qed.
(* Class support. *)
Lemma class_supportEl A B : class_support A B = \bigcup_(x in A) x ^: B.
Proof. exact: curry_imset2l. Qed.
Lemma class_supportEr A B : class_support A B = \bigcup_(x in B) A :^ x.
Proof. exact: curry_imset2r. Qed.
(* 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.
apply: (iffP andP) => [] [A1 AM]; split=> {A1}//.
by move=> x y Ax Ay; apply: (subsetP AM); rewrite mem_mulg.
by apply/subsetP=> _ /mulsgP[x y Ax Ay ->]; apply: AM.
Qed.
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 baseFinGroupType 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. exact: val_inj. Qed.
Lemma groupP (G : groupT) : group_set G. Proof. by case: G. Qed.
Lemma congr_group (H K : groupT) : H = K -> H :=: K.
Proof. exact: congr1. Qed.
Lemma isgroupP A : reflect (exists G : groupT, A = G) (group_set A).
Proof. by apply: (iffP idP) => [gA | [[B gB] -> //]]; exists (Group gA). Qed.
Lemma group_set_one : group_set 1.
Proof. by rewrite /group_set set11 mulg1 subxx. Qed.
Canonical one_group := group group_set_one.
Canonical set1_group := @group [set 1] group_set_one.
Lemma group_setT : group_set (setTfor gT).
Proof. by apply/group_setP; split=> [|x y _ _]; rewrite inE. Qed.
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 := (BaseFinGroup.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. by []. Qed.
(* Non-triviality. *)
Lemma group1 : 1 \in G. Proof. by case/group_setP: (valP G). Qed.
#[local] Hint Resolve group1 : core.
Lemma group1_contra x : x \notin G -> x != 1.
Proof. by apply: contraNneq => ->. Qed.
Lemma sub1G : [1 gT] \subset G. Proof. by rewrite sub1set. Qed.
Lemma subG1 : (G \subset [1]) = (G :==: 1).
Proof. by rewrite eqEsubset sub1G andbT. Qed.
Lemma setI1g : 1 :&: G = 1. Proof. exact: (setIidPl sub1G). Qed.
Lemma setIg1 : G :&: 1 = 1. Proof. exact: (setIidPr sub1G). Qed.
Lemma subG1_contra H : G \subset H -> G :!=: 1 -> H :!=: 1.
Proof. by move=> sGH; rewrite -subG1; apply: contraNneq => <-. Qed.
Lemma repr_group : repr G = 1. Proof. by rewrite /repr group1. Qed.
Lemma cardG_gt0 : 0 < #|G|.
Proof. by rewrite lt0n; apply/existsP; exists (1 : gT). Qed.
Lemma indexg_gt0 A : 0 < #|G : A|.
Proof.
rewrite lt0n; apply/existsP; exists A.
by rewrite -{2}[A]mulg1 -rcosetE; apply: imset_f.
Qed.
Lemma trivgP : reflect (G :=: 1) (G \subset [1]).
Proof. by rewrite subG1; apply: eqP. Qed.
Lemma trivGP : reflect (G = 1%G) (G \subset [1]).
Proof. by rewrite subG1; apply: eqP. Qed.
Lemma proper1G : ([1] \proper G) = (G :!=: 1).
Proof. by rewrite properEneq sub1G andbT eq_sym. Qed.
Lemma in_one_group x : (x \in 1%G) = (x == 1).
Proof. by rewrite -[x \in _]/(x \in [set 1]) !inE. Qed.
Definition inE := (in_one_group, inE).
Lemma trivgPn : reflect (exists2 x, x \in G & x != 1) (G :!=: 1).
Proof.
rewrite -subG1.
by apply: (iffP subsetPn) => [] [x Gx x1]; exists x; rewrite ?inE in x1 *.
Qed.
Lemma trivg_card_le1 : (G :==: 1) = (#|G| <= 1).
Proof. by rewrite eq_sym eqEcard cards1 sub1G. Qed.
Lemma trivg_card1 : (G :==: 1) = (#|G| == 1%N).
Proof. by rewrite trivg_card_le1 eqn_leq cardG_gt0 andbT. Qed.
Lemma cardG_gt1 : (#|G| > 1) = (G :!=: 1).
Proof. by rewrite trivg_card_le1 ltnNge. Qed.
Lemma card_le1_trivg : #|G| <= 1 -> G :=: 1.
Proof. by rewrite -trivg_card_le1; move/eqP. Qed.
Lemma card1_trivg : #|G| = 1%N -> G :=: 1.
Proof. by move=> G1; rewrite card_le1_trivg ?G1. Qed.
(* Inclusion and product. *)
Lemma mulG_subl A : A \subset A * G.
Proof. exact: mulg_subl group1. Qed.
Lemma mulG_subr A : A \subset ((G : {set gT}) * A ).
Proof. exact: mulg_subr group1. Qed.
Lemma mulGid : (G : {set gT}) * G = G.
Proof.
by apply/eqP; rewrite eqEsubset mulG_subr andbT; case/andP: (valP G).
Qed.
Lemma mulGS A B : (G * A \subset G * B) = (A \subset G * B).
Proof.
apply/idP/idP; first exact: subset_trans (mulG_subr A).
by move/(mulgS G); rewrite mulgA mulGid.
Qed.
Lemma mulSG A B : (A * G \subset B * G) = (A \subset B * G).
Proof.
apply/idP/idP; first exact: subset_trans (mulG_subl A).
by move/(mulSg G); rewrite -mulgA mulGid.
Qed.
Lemma mul_subG A B : A \subset G -> B \subset G -> A * B \subset G.
Proof. by move=> sAG sBG; rewrite -mulGid mulgSS. Qed.
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.
move=> subFG; elim/big_rec: _ => [|/= i A /subFG]; first by rewrite sub1set.
exact: mul_subG.
Qed.
(* Membership lemmas *)
Lemma groupM x y : x \in G -> y \in G -> x * y \in G.
Proof. by case/group_setP: (valP G) x y. Qed.
Lemma groupX x n : x \in G -> x ^+ n \in G.
Proof. by move=> Gx; elim: n => [|n IHn]; rewrite ?group1 // expgS groupM. Qed.
Lemma groupVr x : x \in G -> x^-1 \in G.
Proof.
move=> Gx; rewrite -(mul1g x^-1) -mem_rcoset ((G :* x =P G) _) //.
by rewrite eqEcard card_rcoset leqnn mul_subG ?sub1set.
Qed.
Lemma groupVl x : x^-1 \in G -> x \in G.
Proof. by move/groupVr; rewrite invgK. Qed.
Lemma groupV x : (x^-1 \in G) = (x \in G).
Proof. by apply/idP/idP; [apply: groupVl | apply: groupVr]. Qed.
Lemma groupMl x y : x \in G -> (x * y \in G) = (y \in G).
Proof.
move=> Gx; apply/idP/idP=> [Gxy|]; last exact: groupM.
by rewrite -(mulKg x y) groupM ?groupVr.
Qed.
Lemma groupMr x y : x \in G -> (y * x \in G) = (y \in G).
Proof. by move=> Gx; rewrite -[_ \in G]groupV invMg groupMl groupV. Qed.
Definition in_group := (group1, groupV, (groupMl, groupX)).
Lemma groupJ x y : x \in G -> y \in G -> x ^ y \in G.
Proof. by move=> Gx Gy; rewrite !in_group. Qed.
Lemma groupJr x y : y \in G -> (x ^ y \in G) = (x \in G).
Proof. by move=> Gy; rewrite groupMl (groupMr, groupV). Qed.
Lemma groupR x y : x \in G -> y \in G -> [~ x, y] \in G.
Proof. by move=> Gx Gy; rewrite !in_group. Qed.
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. by move=> G_P; elim/big_ind: _ => //; apply: groupM. Qed.
(* Inverse is an anti-morphism. *)
Lemma invGid : G^-1 = G. Proof. by apply/setP=> x; rewrite inE groupV. Qed.
Lemma inv_subG A : (A^-1 \subset G) = (A \subset G).
Proof. by rewrite -{1}invGid invSg. Qed.
Lemma invg_lcoset x : (x *: G)^-1 = G :* x^-1.
Proof. by rewrite invMg invGid invg_set1. Qed.
Lemma invg_rcoset x : (G :* x)^-1 = x^-1 *: G.
Proof. by rewrite invMg invGid invg_set1. Qed.
Lemma memV_lcosetV x y : (y^-1 \in x^-1 *: G) = (y \in G :* x).
Proof. by rewrite -invg_rcoset memV_invg. Qed.
Lemma memV_rcosetV x y : (y^-1 \in G :* x^-1) = (y \in x *: G).
Proof. by rewrite -invg_lcoset memV_invg. Qed.
(* Product idempotence *)
Lemma mulSgGid A x : x \in A -> A \subset G -> A * G = G.
Proof.
move=> Ax sAG; apply/eqP; rewrite eqEsubset -{2}mulGid mulSg //=.
apply/subsetP=> y Gy; rewrite -(mulKVg x y) mem_mulg // groupMr // groupV.
exact: (subsetP sAG).
Qed.
Lemma mulGSgid A x : x \in A -> A \subset G -> G * A = G.
Proof.
rewrite -memV_invg -invSg invGid => Ax sAG.
by apply: invg_inj; rewrite invMg invGid (mulSgGid Ax).
Qed.
(* Left cosets *)
Lemma lcoset_refl x : x \in x *: G.
Proof. by rewrite mem_lcoset mulVg group1. Qed.
Lemma lcoset_sym x y : (x \in y *: G) = (y \in x *: G).
Proof. by rewrite !mem_lcoset -groupV invMg invgK. Qed.
Lemma lcoset_eqP {x y} : reflect (x *: G = y *: G) (x \in y *: G).
Proof.
suffices <-: (x *: G == y *: G) = (x \in y *: G) by apply: eqP.
by rewrite eqEsubset !mulSG !sub1set lcoset_sym andbb.
Qed.
Lemma lcoset_transl x y z : x \in y *: G -> (x \in z *: G) = (y \in z *: G).
Proof. by move=> Gyx; rewrite -2!(lcoset_sym z) (lcoset_eqP Gyx). Qed.
Lemma lcoset_trans x y z : x \in y *: G -> y \in z *: G -> x \in z *: G.
Proof. by move/lcoset_transl->. Qed.
Lemma lcoset_id x : x \in G -> x *: G = G.
Proof. by move=> Gx; rewrite (lcoset_eqP (_ : x \in 1 *: G)) mul1g. Qed.
(* Right cosets, with an elimination form for repr. *)
Lemma rcoset_refl x : x \in G :* x.
Proof. by rewrite mem_rcoset mulgV group1. Qed.
Lemma rcoset_sym x y : (x \in G :* y) = (y \in G :* x).
Proof. by rewrite -!memV_lcosetV lcoset_sym. Qed.
Lemma rcoset_eqP {x y} : reflect (G :* x = G :* y) (x \in G :* y).
Proof.
suffices <-: (G :* x == G :* y) = (x \in G :* y) by apply: eqP.
by rewrite eqEsubset !mulGS !sub1set rcoset_sym andbb.
Qed.
Lemma rcoset_transl x y z : x \in G :* y -> (x \in G :* z) = (y \in G :* z).
Proof. by move=> Gyx; rewrite -2!(rcoset_sym z) (rcoset_eqP Gyx). Qed.
Lemma rcoset_trans x y z : x \in G :* y -> y \in G :* z -> x \in G :* z.
Proof. by move/rcoset_transl->. Qed.
Lemma rcoset_id x : x \in G -> G :* x = G.
Proof. by move=> Gx; rewrite (rcoset_eqP (_ : x \in G :* 1)) mulg1. Qed.
(* 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. exact: mem_repr (rcoset_refl x). Qed.
(* 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.
by rewrite -[repr _](mulgKV x); split; rewrite -mem_rcoset mem_repr_rcoset.
Qed.
Lemma rcoset_repr x : G :* (repr (G :* x)) = G :* x.
Proof. exact/rcoset_eqP/mem_repr_rcoset. Qed.
(* Coset spaces. *)
Lemma mem_rcosets A x : (G :* x \in rcosets G A) = (x \in G * A).
Proof.
apply/rcosetsP/mulsgP=> [[a Aa /rcoset_eqP/rcosetP[g]] | ]; first by exists g a.
by case=> g a Gg Aa ->{x}; exists a; rewrite // rcosetM rcoset_id.
Qed.
Lemma mem_lcosets A x : (x *: G \in lcosets G A) = (x \in A * G).
Proof.
rewrite -[LHS]memV_invg invg_lcoset invg_lcosets.
by rewrite -[RHS]memV_invg invMg invGid mem_rcosets.
Qed.
(* Conjugates. *)
Lemma group_setJ A x : group_set (A :^ x) = group_set A.
Proof. by rewrite /group_set mem_conjg conj1g -conjsMg conjSg. Qed.
Lemma group_set_conjG x : group_set (G :^ x).
Proof. by rewrite group_setJ groupP. Qed.
Canonical conjG_group x := group (group_set_conjG x).
Lemma conjGid : {in G, normalised G}.
Proof. by move=> x Gx; apply/setP=> y; rewrite mem_conjg groupJr ?groupV. Qed.
Lemma conj_subG x A : x \in G -> A \subset G -> A :^ x \subset G.
Proof. by move=> Gx sAG; rewrite -(conjGid Gx) conjSg. Qed.
(* Classes *)
Lemma class1G : 1 ^: G = 1. Proof. exact: class1g group1. Qed.
Lemma classes1 : [1] \in classes G. Proof. by rewrite -class1G mem_classes. Qed.
Lemma classGidl x y : y \in G -> (x ^ y) ^: G = x ^: G.
Proof. by move=> Gy; rewrite -class_lcoset lcoset_id. Qed.
Lemma classGidr x : {in G, normalised (x ^: G)}.
Proof. by move=> y Gy /=; rewrite -class_rcoset rcoset_id. Qed.
Lemma class_refl x : x \in x ^: G.
Proof. by apply/imsetP; exists 1; rewrite ?conjg1. Qed.
#[local] Hint Resolve class_refl : core.
Lemma class_eqP x y : reflect (x ^: G = y ^: G) (x \in y ^: G).
Proof.
by apply: (iffP idP) => [/imsetP[z Gz ->] | <-]; rewrite ?class_refl ?classGidl.
Qed.
Lemma class_sym x y : (x \in y ^: G) = (y \in x ^: G).
Proof. by apply/idP/idP=> /class_eqP->. Qed.
Lemma class_transl x y z : x \in y ^: G -> (x \in z ^: G) = (y \in z ^: G).
Proof. by rewrite -!(class_sym z) => /class_eqP->. Qed.
Lemma class_trans x y z : x \in y ^: G -> y \in z ^: G -> x \in z ^: G.
Proof. by move/class_transl->. Qed.
Lemma repr_class x : {y | y \in G & repr (x ^: G) = x ^ y}.
Proof.
set z := repr _; have: #|[set y in G | z == x ^ y]| > 0.
have: z \in x ^: G by apply: (mem_repr x).
by case/imsetP=> y Gy ->; rewrite (cardD1 y) inE Gy eqxx.
by move/card_mem_repr; move: (repr _) => y /setIdP[Gy /eqP]; exists y.
Qed.
Lemma classG_eq1 x : (x ^: G == 1) = (x == 1).
Proof.
apply/eqP/eqP=> [xG1 | ->]; last exact: class1G.
by have:= class_refl x; rewrite xG1 => /set1P.
Qed.
Lemma class_subG x A : x \in G -> A \subset G -> x ^: A \subset G.
Proof.
move=> Gx sAG; apply/subsetP=> _ /imsetP[y Ay ->].
by rewrite groupJ // (subsetP sAG).
Qed.
Lemma repr_classesP xG :
reflect (repr xG \in G /\ xG = repr xG ^: G) (xG \in classes G).
Proof.
apply: (iffP imsetP) => [[x Gx ->] | []]; last by exists (repr xG).
by have [y Gy ->] := repr_class x; rewrite classGidl ?groupJ.
Qed.
Lemma mem_repr_classes xG : xG \in classes G -> repr xG \in xG.
Proof. by case/repr_classesP=> _ {2}->; apply: class_refl. Qed.
Lemma classes_gt0 : 0 < #|classes G|.
Proof. by rewrite (cardsD1 1) classes1. Qed.
Lemma classes_gt1 : (#|classes G| > 1) = (G :!=: 1).
Proof.
rewrite (cardsD1 1) classes1 ltnS lt0n cards_eq0.
apply/set0Pn/trivgPn=> [[xG /setD1P[nt_xG]] | [x Gx ntx]].
by case/imsetP=> x Gx def_xG; rewrite def_xG classG_eq1 in nt_xG; exists x.
by exists (x ^: G); rewrite !inE classG_eq1 ntx; apply: imset_f.
Qed.
Lemma mem_class_support A x : x \in A -> x \in class_support A G.
Proof. by move=> Ax; rewrite -[x]conjg1 memJ_class_support. Qed.
Lemma class_supportGidl A x :
x \in G -> class_support (A :^ x) G = class_support A G.
Proof.
by move=> Gx; rewrite -class_support_set1r -class_supportM lcoset_id.
Qed.
Lemma class_supportGidr A : {in G, normalised (class_support A G)}.
Proof.
by move=> x Gx /=; rewrite -class_support_set1r -class_supportM rcoset_id.
Qed.
Lemma class_support_subG A : A \subset G -> class_support A G \subset G.
Proof.
by move=> sAG; rewrite class_supportEr; apply/bigcupsP=> x Gx; apply: conj_subG.
Qed.
Lemma sub_class_support A : A \subset class_support A G.
Proof. by rewrite class_supportEr (bigcup_max 1) ?conjsg1. Qed.
Lemma class_support_id : class_support G G = G.
Proof.
by apply/eqP; rewrite eqEsubset sub_class_support class_support_subG.
Qed.
Lemma class_supportD1 A : (class_support A G)^# = cover (A^# :^: G).
Proof.
rewrite cover_imset class_supportEr setDE big_distrl /=.
by apply: eq_bigr => x _; rewrite -setDE conjD1g.
Qed.
(* 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. exact: valP. Qed.
Lemma subg_inj : injective sgval.
Proof. exact: val_inj. Qed.
Lemma congr_subg u v : u = v -> sgval u = sgval v.
Proof. exact: congr1. Qed.
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. by move=> u; apply: val_inj; apply: mul1g. Qed.
Lemma subg_invP : left_inverse subg_one subg_inv subg_mul.
Proof. by move=> u; apply: val_inj; apply: mulVg. Qed.
Lemma subg_mulP : associative subg_mul.
Proof. by move=> u v w; apply: val_inj; apply: mulgA. Qed.
HB.instance Definition _ := isMulGroup.Build subg_of
subg_mulP subg_oneP subg_invP.
Lemma sgvalM : {in setT &, {morph sgval : x y / x * y}}. Proof. by []. Qed.
Lemma valgM : {in setT &, {morph val : x y / (x : subg_of) * y >-> x * y}}.
Proof. by []. Qed.
Definition subg : gT -> subg_of := insubd (1 : subg_of).
Lemma subgK x : x \in G -> val (subg x) = x.
Proof. by move=> Gx; rewrite insubdK. Qed.
Lemma sgvalK : cancel sgval subg.
Proof. by case=> x Gx; apply: val_inj; apply: subgK. Qed.
Lemma subg_default x : (x \in G) = false -> val (subg x) = 1.
Proof. by move=> Gx; rewrite val_insubd Gx. Qed.
Lemma subgM : {in G &, {morph subg : x y / x * y}}.
Proof. by move=> x y Gx Gy; apply: val_inj; rewrite /= !subgK ?groupM. Qed.
End OneGroup.
#[local] Hint Resolve group1 : core.
Lemma groupD1_inj G H : G^# = H^# -> G :=: H.
Proof. by move/(congr1 (setU 1)); rewrite !setD1K. Qed.
Lemma invMG G H : (G * H)^-1 = H * G.
Proof. by rewrite invMg !invGid. Qed.
Lemma mulSGid G H : H \subset G -> H * G = G.
Proof. exact: mulSgGid (group1 H). Qed.
Lemma mulGSid G H : H \subset G -> G * H = G.
Proof. exact: mulGSgid (group1 H). Qed.
Lemma mulGidPl G H : reflect (G * H = G) (H \subset G).
Proof. by apply: (iffP idP) => [|<-]; [apply: mulGSid | apply: mulG_subr]. Qed.
Lemma mulGidPr G H : reflect (G * H = H) (G \subset H).
Proof. by apply: (iffP idP) => [|<-]; [apply: mulSGid | apply: mulG_subl]. Qed.
Lemma comm_group_setP G H : reflect (commute G H) (group_set (G * H)).
Proof.
rewrite /group_set (subsetP (mulG_subl _ _)) ?group1 // andbC.
have <-: #|G * H| <= #|H * G| by rewrite -invMG card_invg.
by rewrite -mulgA mulGS mulgA mulSG -eqEcard eq_sym; apply: eqP.
Qed.
Lemma card_lcosets G H : #|lcosets H G| = #|G : H|.
Proof. by rewrite -card_invg invg_lcosets !invGid. Qed.
(* Group Modularity equations *)
Lemma group_modl A B G : A \subset G -> A * (B :&: G) = A * B :&: G.
Proof.
move=> sAG; apply/eqP; rewrite eqEsubset subsetI mulgS ?subsetIl //.
rewrite -{2}mulGid mulgSS ?subsetIr //.
apply/subsetP => _ /setIP[/mulsgP[a b Aa Bb ->] Gab].
by rewrite mem_mulg // inE Bb -(groupMl _ (subsetP sAG _ Aa)).
Qed.
Lemma group_modr A B G : B \subset G -> (G :&: A) * B = G :&: A * B.
Proof.
move=> sBG; apply: invg_inj; rewrite !(invMg, invIg) invGid !(setIC G).
by rewrite group_modl // -invGid invSg.
Qed.
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.
apply/group_setP; split=> [|x y]; rewrite !inE ?group1 //.
by case/andP=> Gx Hx; rewrite !groupMl.
Qed.
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.
by elim/big_rec: _ => [|i G _ gG]; rewrite -1?(insubdK 1%G gG) groupP.
Qed.
Canonical bigcap_group := group group_set_bigcap.
End Nary.
Lemma group_set_generated (A : {set gT}) : group_set <<A>>.
Proof. by rewrite unlock group_set_bigcap. Qed.
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. exact: cardG_gt0. Qed.
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.
rewrite -[#|G|]sum1_card (partition_big_imset (rcoset H)) /=.
rewrite mulnC -sum_nat_const; apply: eq_bigr => _ /rcosetsP[x Gx ->].
rewrite -(card_rcoset _ x) -sum1_card; apply: eq_bigl => y.
by rewrite rcosetE (sameP eqP rcoset_eqP) group_modr ?sub1set // !inE.
Qed.
Lemma divgI G H : #|G| %/ #|G :&: H| = #|G : H|.
Proof. by rewrite -(LagrangeI G H) mulKn ?cardG_gt0. Qed.
Lemma divg_index G H : #|G| %/ #|G : H| = #|G :&: H|.
Proof. by rewrite -(LagrangeI G H) mulnK. Qed.
Lemma dvdn_indexg G H : #|G : H| %| #|G|.
Proof. by rewrite -(LagrangeI G H) dvdn_mull. Qed.
Theorem Lagrange G H : H \subset G -> (#|H| * #|G : H|)%N = #|G|.
Proof. by move/setIidPr=> sHG; rewrite -{1}sHG LagrangeI. Qed.
Lemma cardSg G H : H \subset G -> #|H| %| #|G|.
Proof. by move/Lagrange <-; rewrite dvdn_mulr. Qed.
Lemma lognSg p G H : G \subset H -> logn p #|G| <= logn p #|H|.
Proof. by move=> sGH; rewrite dvdn_leq_log ?cardSg. Qed.
Lemma piSg G H : G \subset H -> {subset \pi(gval G) <= \pi(gval H)}.
Proof.
move=> sGH p; rewrite !mem_primes !cardG_gt0 => /and3P[-> _ pG].
exact: dvdn_trans (cardSg sGH).
Qed.
Lemma divgS G H : H \subset G -> #|G| %/ #|H| = #|G : H|.
Proof. by move/Lagrange <-; rewrite mulKn. Qed.
Lemma divg_indexS G H : H \subset G -> #|G| %/ #|G : H| = #|H|.
Proof. by move/Lagrange <-; rewrite mulnK. Qed.
Lemma coprimeSg G H p : H \subset G -> coprime #|G| p -> coprime #|H| p.
Proof. by move=> sHG; apply: coprime_dvdl (cardSg sHG). Qed.
Lemma coprimegS G H p : H \subset G -> coprime p #|G| -> coprime p #|H|.
Proof. by move=> sHG; apply: coprime_dvdr (cardSg sHG). Qed.
Lemma indexJg G H x : #|G :^ x : H :^ x| = #|G : H|.
Proof. by rewrite -!divgI -conjIg !cardJg. Qed.
Lemma indexgg G : #|G : G| = 1%N.
Proof. by rewrite -divgS // divnn cardG_gt0. Qed.
Lemma rcosets_id G : rcosets G G = [set G : {set gT}].
Proof.
apply/esym/eqP; rewrite eqEcard sub1set [#|_|]indexgg cards1 andbT.
by apply/rcosetsP; exists 1; rewrite ?mulg1.
Qed.
Lemma Lagrange_index G H K :
H \subset G -> K \subset H -> (#|G : H| * #|H : K|)%N = #|G : K|.
Proof.
move=> sHG sKH; apply/eqP; rewrite mulnC -(eqn_pmul2l (cardG_gt0 K)).
by rewrite mulnA !Lagrange // (subset_trans sKH).
Qed.
Lemma indexgI G H : #|G : G :&: H| = #|G : H|.
Proof. by rewrite -[RHS]divgI divgS ?subsetIl. Qed.
Lemma indexgS G H K : H \subset K -> #|G : K| %| #|G : H|.
Proof.
move=> sHK; rewrite -(@dvdn_pmul2l #|G :&: K|) ?cardG_gt0 // LagrangeI.
by rewrite -(Lagrange (setIS G sHK)) mulnAC LagrangeI dvdn_mulr.
Qed.
Lemma indexSg G H K : H \subset K -> K \subset G -> #|K : H| %| #|G : H|.
Proof.
move=> sHK sKG; rewrite -(@dvdn_pmul2l #|H|) ?cardG_gt0 //.
by rewrite !Lagrange ?(cardSg, subset_trans sHK).
Qed.
Lemma indexg_eq1 G H : (#|G : H| == 1%N) = (G \subset H).
Proof.
rewrite eqn_leq -(leq_pmul2l (cardG_gt0 (G :&: H))) LagrangeI muln1.
by rewrite indexg_gt0 andbT (sameP setIidPl eqP) eqEcard subsetIl.
Qed.
Lemma indexg_gt1 G H : (#|G : H| > 1) = ~~ (G \subset H).
Proof. by rewrite -indexg_eq1 eqn_leq indexg_gt0 andbT -ltnNge. Qed.
Lemma index1g G H : H \subset G -> #|G : H| = 1%N -> H :=: G.
Proof. by move=> sHG iHG; apply/eqP; rewrite eqEsubset sHG -indexg_eq1 iHG. Qed.
Lemma indexg1 G : #|G : 1| = #|G|.
Proof. by rewrite -divgS ?sub1G // cards1 divn1. Qed.
Lemma indexMg G A : #|G * A : G| = #|A : G|.
Proof.
apply/eq_card/setP/eqP; rewrite eqEsubset andbC imsetS ?mulG_subr //.
by apply/subsetP=> _ /rcosetsP[x GAx ->]; rewrite mem_rcosets.
Qed.
Lemma rcosets_partition_mul G H : partition (rcosets H G) (H * G).
Proof.
set HG := H * G; have sGHG: {subset G <= HG} by apply/subsetP/mulG_subr.
have defHx x: x \in HG -> [set y in HG | rcoset H x == rcoset H y] = H :* x.
move=> HGx; apply/setP=> y; rewrite inE !rcosetE (sameP eqP rcoset_eqP).
by rewrite rcoset_sym; apply/andb_idl/subsetP; rewrite mulGS sub1set.
have:= preim_partitionP (rcoset H) HG; congr (partition _ _); apply/setP=> Hx.
apply/imsetP/idP=> [[x HGx ->] | ]; first by rewrite defHx // mem_rcosets.
by case/rcosetsP=> x /sGHG-HGx ->; exists x; rewrite ?defHx.
Qed.
Lemma rcosets_partition G H : H \subset G -> partition (rcosets H G) G.
Proof. by move=> sHG; have:= rcosets_partition_mul G H; rewrite mulSGid. Qed.
Lemma LagrangeMl G H : (#|G| * #|H : G|)%N = #|G * H|.
Proof.
rewrite mulnC -(card_uniform_partition _ (rcosets_partition_mul H G)) //.
by move=> _ /rcosetsP[x Hx ->]; rewrite card_rcoset.
Qed.
Lemma LagrangeMr G H : (#|G : H| * #|H|)%N = #|G * H|.
Proof. by rewrite mulnC LagrangeMl -card_invg invMg !invGid. Qed.
Lemma mul_cardG G H : (#|G| * #|H| = #|G * H|%g * #|G :&: H|)%N.
Proof. by rewrite -LagrangeMr -(LagrangeI G H) -mulnA mulnC. Qed.
Lemma dvdn_cardMg G H : #|G * H| %| #|G| * #|H|.
Proof. by rewrite mul_cardG dvdn_mulr. Qed.
Lemma cardMg_divn G H : #|G * H| = (#|G| * #|H|) %/ #|G :&: H|.
Proof. by rewrite mul_cardG mulnK ?cardG_gt0. Qed.
Lemma cardIg_divn G H : #|G :&: H| = (#|G| * #|H|) %/ #|G * H|.
Proof. by rewrite mul_cardG mulKn // (cardD1 (1 * 1)) mem_mulg. Qed.
Lemma TI_cardMg G H : G :&: H = 1 -> #|G * H| = (#|G| * #|H|)%N.
Proof. by move=> tiGH; rewrite mul_cardG tiGH cards1 muln1. Qed.
Lemma cardMg_TI G H : #|G| * #|H| <= #|G * H| -> G :&: H = 1.
Proof.
move=> leGH; apply: card_le1_trivg.
rewrite -(@leq_pmul2l #|G * H|); first by rewrite -mul_cardG muln1.
by apply: leq_trans leGH; rewrite muln_gt0 !cardG_gt0.
Qed.
Lemma coprime_TIg G H : coprime #|G| #|H| -> G :&: H = 1.
Proof.
move=> coGH; apply/eqP; rewrite trivg_card1 -dvdn1 -{}(eqnP coGH).
by rewrite dvdn_gcd /= {2}setIC !cardSg ?subsetIl.
Qed.
Lemma prime_TIg G H : prime #|G| -> ~~ (G \subset H) -> G :&: H = 1.
Proof.
case/primeP=> _ /(_ _ (cardSg (subsetIl G H))).
rewrite (sameP setIidPl eqP) eqEcard subsetIl => /pred2P[/card1_trivg|] //= ->.
by case/negP.
Qed.
Lemma prime_meetG G H : prime #|G| -> G :&: H != 1 -> G \subset H.
Proof. by move=> prG; apply: contraR; move/prime_TIg->. Qed.
Lemma coprime_cardMg G H : coprime #|G| #|H| -> #|G * H| = (#|G| * #|H|)%N.
Proof. by move=> coGH; rewrite TI_cardMg ?coprime_TIg. Qed.
Lemma coprime_index_mulG G H K :
H \subset G -> K \subset G -> coprime #|G : H| #|G : K| -> H * K = G.
Proof.
move=> sHG sKG co_iG_HK; apply/eqP; rewrite eqEcard mul_subG //=.
rewrite -(@leq_pmul2r #|H :&: K|) ?cardG_gt0 // -mul_cardG.
rewrite -(Lagrange sHG) -(LagrangeI K H) mulnAC setIC -mulnA.
rewrite !leq_pmul2l ?cardG_gt0 // dvdn_leq // -(Gauss_dvdr _ co_iG_HK).
by rewrite -(indexgI K) Lagrange_index ?indexgS ?subsetIl ?subsetIr.
Qed.
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. rewrite [@generated]unlock; exact/bigcapsP. Qed.
Lemma sub_gen A B : A \subset B -> A \subset <<B>>.
Proof. by move/subset_trans=> -> //; apply: subset_gen. Qed.
Lemma mem_gen x A : x \in A -> x \in <<A>>.
Proof. exact: subsetP (subset_gen A) x. Qed.
Lemma generatedP x A : reflect (forall G, A \subset G -> x \in G) (x \in <<A>>).
Proof. rewrite [@generated]unlock; exact: bigcapP. Qed.
Lemma gen_subG A G : (<<A>> \subset G) = (A \subset G).
Proof.
apply/idP/idP=> [|sAG]; first exact: subset_trans (subset_gen A).
by apply/subsetP=> x /generatedP; apply.
Qed.
Lemma genGid G : <<G>> = G.
Proof. by apply/eqP; rewrite eqEsubset gen_subG subset_gen andbT. Qed.
Lemma genGidG G : <<G>>%G = G.
Proof. by apply: val_inj; apply: genGid. Qed.
Lemma gen_set_id A : group_set A -> <<A>> = A.
Proof. by move=> gA; apply: (genGid (group gA)). Qed.
Lemma genS A B : A \subset B -> <<A>> \subset <<B>>.
Proof. by move=> sAB; rewrite gen_subG sub_gen. Qed.
Lemma gen0 : <<set0>> = 1 :> {set gT}.
Proof. by apply/eqP; rewrite eqEsubset sub1G gen_subG sub0set. Qed.
Lemma gen_expgs A : {n | <<A>> = (1 |: A) ^+ n}.
Proof.
set B := (1 |: A); pose N := #|gT|.
have BsubG n : B ^+ n \subset <<A>>.
by elim: n => [|n IHn]; rewrite ?expgS ?mul_subG ?subUset ?sub1G ?subset_gen.
have B_1 n : 1 \in B ^+ n.
by elim: n => [|n IHn]; rewrite ?set11 // expgS mulUg mul1g inE IHn.
case: (pickP (fun i : 'I_N => B ^+ i.+1 \subset B ^+ i)) => [n fixBn | no_fix].
exists n; apply/eqP; rewrite eqEsubset BsubG andbT.
rewrite -[B ^+ n]gen_set_id ?genS ?subsetUr //.
by apply: subset_trans fixBn; rewrite expgS mulUg subsetU ?mulg_subl ?orbT.
rewrite /group_set B_1 /=.
elim: {2}(n : nat) => [|m IHm]; first by rewrite mulg1.
by apply: subset_trans fixBn; rewrite !expgSr mulgA mulSg.
suffices: N < #|B ^+ N| by rewrite ltnNge max_card.
have [] := ubnPgeq N; elim=> [|n IHn] lt_nN; first by rewrite cards1.
apply: leq_ltn_trans (IHn (ltnW lt_nN)) (proper_card _).
by rewrite /proper (no_fix (Ordinal lt_nN)) expgS mulUg mul1g subsetUl.
Qed.
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.
apply: (iffP idP) => [|[n [c Ac ->]]]; last first.
by apply: group_prod => i _; rewrite mem_gen ?Ac.
have [n ->] := gen_expgs A; rewrite /expgn Monoid.iteropE /=.
rewrite -[n]card_ord -big_const => /prodsgP[/= c Ac def_x].
have{Ac def_x} ->: x = \prod_(i | c i \in A) c i.
rewrite big_mkcond {x}def_x; apply: eq_bigr => i _.
by case/setU1P: (Ac i isT) => -> //; rewrite if_same.
have [e <- [_ /= mem_e] _] := big_enumP [preim c of A].
pose t := in_tuple e; rewrite -[e]/(val t) big_tuple.
by exists (size e), (c \o tnth t) => // i; rewrite -mem_e mem_tnth.
Qed.
Lemma genD A B : A \subset <<A :\: B>> -> <<A :\: B>> = <<A>>.
Proof.
by move=> sAB; apply/eqP; rewrite eqEsubset genS (subsetDl, gen_subG).
Qed.
Lemma genV A : <<A^-1>> = <<A>>.
Proof.
apply/eqP; rewrite eqEsubset !gen_subG -!(invSg _ <<_>>) invgK.
by rewrite !invGid !subset_gen.
Qed.
Lemma genJ A z : <<A :^z>> = <<A>> :^ z.
Proof.
by apply/eqP; rewrite eqEsubset sub_conjg !gen_subG conjSg -?sub_conjg !sub_gen.
Qed.
Lemma conjYg A B z : (A <*> B) :^z = A :^ z <*> B :^ z.
Proof. by rewrite -genJ conjUg. Qed.
Lemma genD1 A x : x \in <<A :\ x>> -> <<A :\ x>> = <<A>>.
Proof.
move=> gA'x; apply/eqP; rewrite eqEsubset genS; last by rewrite subsetDl.
rewrite gen_subG; apply/subsetP=> y Ay.
by case: (y =P x) => [-> //|]; move/eqP=> nyx; rewrite mem_gen // !inE nyx.
Qed.
Lemma genD1id A : <<A^#>> = <<A>>.
Proof. by rewrite genD1 ?group1. Qed.
Notation joingT := (@joing gT) (only parsing).
Notation joinGT := (@joinG gT) (only parsing).
Lemma joingE A B : A <*> B = <<A :|: B>>. Proof. by []. Qed.
Lemma joinGE G H : (G * H)%G = (G <*> H)%G. Proof. by []. Qed.
Lemma joingC : commutative joingT.
Proof. by move=> A B; rewrite /joing setUC. Qed.
Lemma joing_idr A B : A <*> <<B>> = A <*> B.
Proof.
apply/eqP; rewrite eqEsubset gen_subG subUset gen_subG /=.
by rewrite -subUset subset_gen genS // setUS // subset_gen.
Qed.
Lemma joing_idl A B : <<A>> <*> B = A <*> B.
Proof. by rewrite -!(joingC B) joing_idr. Qed.
Lemma joing_subl A B : A \subset A <*> B.
Proof. by rewrite sub_gen ?subsetUl. Qed.
Lemma joing_subr A B : B \subset A <*> B.
Proof. by rewrite sub_gen ?subsetUr. Qed.
Lemma join_subG A B G : (A <*> B \subset G) = (A \subset G) && (B \subset G).
Proof. by rewrite gen_subG subUset. Qed.
Lemma joing_idPl G A : reflect (G <*> A = G) (A \subset G).
Proof.
apply: (iffP idP) => [sHG | <-]; last by rewrite joing_subr.
by rewrite joingE (setUidPl sHG) genGid.
Qed.
Lemma joing_idPr A G : reflect (A <*> G = G) (A \subset G).
Proof. by rewrite joingC; apply: joing_idPl. Qed.
Lemma joing_subP A B G :
reflect (A \subset G /\ B \subset G) (A <*> B \subset G).
Proof. by rewrite join_subG; apply: andP. Qed.
Lemma joing_sub A B C : A <*> B = C -> A \subset C /\ B \subset C.
Proof. by move <-; apply/joing_subP. Qed.
Lemma genDU A B C : A \subset C -> <<C :\: A>> = <<B>> -> <<A :|: B>> = <<C>>.
Proof.
move=> sAC; rewrite -joingE -joing_idr => <- {B}; rewrite joing_idr.
by congr <<_>>; rewrite setDE setUIr setUCr setIT; apply/setUidPr.
Qed.
Lemma joingA : associative joingT.
Proof. by move=> A B C; rewrite joing_idl joing_idr /joing setUA. Qed.
Lemma joing1G G : 1 <*> G = G.
Proof. by rewrite -gen0 joing_idl /joing set0U genGid. Qed.
Lemma joingG1 G : G <*> 1 = G.
Proof. by rewrite joingC joing1G. Qed.
Lemma genM_join G H : <<G * H>> = G <*> H.
Proof.
apply/eqP; rewrite eqEsubset gen_subG /= -{1}[G <*> H]mulGid.
rewrite genS; last by rewrite subUset mulG_subl mulG_subr.
by rewrite mulgSS ?(sub_gen, subsetUl, subsetUr).
Qed.
Lemma mulG_subG G H K : (G * H \subset K) = (G \subset K) && (H \subset K).
Proof. by rewrite -gen_subG genM_join join_subG. Qed.
Lemma mulGsubP K H G : reflect (K \subset G /\ H \subset G) (K * H \subset G).
Proof. by rewrite mulG_subG; apply: andP. Qed.
Lemma mulG_sub K H A : K * H = A -> K \subset A /\ H \subset A.
Proof. by move <-; rewrite mulG_subl mulG_subr. Qed.
Lemma trivMg G H : (G * H == 1) = (G :==: 1) && (H :==: 1).
Proof.
by rewrite !eqEsubset -{2}[1]mulGid mulgSS ?sub1G // !andbT mulG_subG.
Qed.
Lemma comm_joingE G H : commute G H -> G <*> H = G * H.
Proof.
by move/comm_group_setP=> gGH; rewrite -genM_join; apply: (genGid (group gGH)).
Qed.
Lemma joinGC : commutative joinGT.
Proof. by move=> G H; apply: val_inj; apply: joingC. Qed.
Lemma joinGA : associative joinGT.
Proof. by move=> G H K; apply: val_inj; apply: joingA. Qed.
Lemma join1G : left_id 1%G joinGT.
Proof. by move=> G; apply: val_inj; apply: joing1G. Qed.
Lemma joinG1 : right_id 1%G joinGT.
Proof. by move=> G; apply: val_inj; apply: joingG1. Qed.
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.
elim/big_rec2: _ => /= [|i A _ _ ->]; first by rewrite gen0.
by rewrite joing_idl joing_idr.
Qed.
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.
rewrite -bigprodGEgen /=; apply: congr_group.
by apply: eq_bigr => i _; rewrite genGidG.
Qed.
Lemma mem_commg A B x y : x \in A -> y \in B -> [~ x, y] \in [~: A, B].
Proof. by move=> Ax By; rewrite mem_gen ?imset2_f. Qed.
Lemma commSg A B C : A \subset B -> [~: A, C] \subset [~: B, C].
Proof. by move=> sAC; rewrite genS ?imset2S. Qed.
Lemma commgS A B C : B \subset C -> [~: A, B] \subset [~: A, C].
Proof. by move=> sBC; rewrite genS ?imset2S. Qed.
Lemma commgSS A B C D :
A \subset B -> C \subset D -> [~: A, C] \subset [~: B, D].
Proof. by move=> sAB sCD; rewrite genS ?imset2S. Qed.
Lemma der1_subG G : [~: G, G] \subset G.
Proof.
by rewrite gen_subG; apply/subsetP=> _ /imset2P[x y Gx Gy ->]; apply: groupR.
Qed.
Lemma comm_subG A B G : A \subset G -> B \subset G -> [~: A, B] \subset G.
Proof.
by move=> sAG sBG; apply: subset_trans (der1_subG G); apply: commgSS.
Qed.
Lemma commGC A B : [~: A, B] = [~: B, A].
Proof.
rewrite -[[~: A, B]]genV; congr <<_>>; apply/setP=> z; rewrite inE.
by apply/imset2P/imset2P=> [] [x y Ax Ay]; last rewrite -{1}(invgK z);
rewrite -invg_comm => /invg_inj->; exists y x.
Qed.
Lemma conjsRg A B x : [~: A, B] :^ x = [~: A :^ x, B :^ x].
Proof.
wlog suffices: A B x / [~: A, B] :^ x \subset [~: A :^ x, B :^ x].
move=> subJ; apply/eqP; rewrite eqEsubset subJ /= -sub_conjgV.
by rewrite -{2}(conjsgK x A) -{2}(conjsgK x B).
rewrite -genJ gen_subG; apply/subsetP=> _ /imsetP[_ /imset2P[y z Ay Bz ->] ->].
by rewrite conjRg mem_commg ?memJ_conjg.
Qed.
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. exact: genGid. Qed.
Lemma order1 : #[1 : gT] = 1%N.
Proof. by rewrite /order cycle1 cards1. Qed.
Lemma cycle_id x : x \in <[x]>.
Proof. by rewrite mem_gen // set11. Qed.
Lemma mem_cycle x i : x ^+ i \in <[x]>.
Proof. by rewrite groupX // cycle_id. Qed.
Lemma cycle_subG x G : (<[x]> \subset G) = (x \in G).
Proof. by rewrite gen_subG sub1set. Qed.
Lemma cycle_eq1 x : (<[x]> == 1) = (x == 1).
Proof. by rewrite eqEsubset sub1G andbT cycle_subG inE. Qed.
Lemma orderE x : #[x] = #|<[x]>|. Proof. by []. Qed.
Lemma order_eq1 x : (#[x] == 1%N) = (x == 1).
Proof. by rewrite -trivg_card1 cycle_eq1. Qed.
Lemma order_gt1 x : (#[x] > 1) = (x != 1).
Proof. by rewrite ltnNge -trivg_card_le1 cycle_eq1. Qed.
Lemma cycle_traject x : <[x]> =i traject (mulg x) 1 #[x].
Proof.
set t := _ 1; apply: fsym; apply/subset_cardP; last first.
by apply/subsetP=> _ /trajectP[i _ ->]; rewrite -iteropE mem_cycle.
rewrite (card_uniqP _) ?size_traject //; case def_n: #[_] => // [n].
rewrite looping_uniq; apply: contraL (card_size (t n)) => /loopingP t_xi.
rewrite -ltnNge size_traject -def_n ?subset_leq_card //.
rewrite -(eq_subset_r (in_set _)) {}/t; set G := finset _.
rewrite -[x]mulg1 -[G]gen_set_id ?genS ?sub1set ?inE ?(t_xi 1%N)//.
apply/group_setP; split=> [|y z]; rewrite !inE ?(t_xi 0) //.
by do 2!case/trajectP=> ? _ ->; rewrite -!iteropE -expgD [x ^+ _]iteropE.
Qed.
Lemma cycle2g x : #[x] = 2 -> <[x]> = [set 1; x].
Proof. by move=> ox; apply/setP=> y; rewrite cycle_traject ox !inE mulg1. Qed.
Lemma cyclePmin x y : y \in <[x]> -> {i | i < #[x] & y = x ^+ i}.
Proof.
rewrite cycle_traject; set tx := traject _ _ #[x] => tx_y; pose i := index y tx.
have lt_i_x : i < #[x] by rewrite -index_mem size_traject in tx_y.
by exists i; rewrite // [x ^+ i]iteropE /= -(nth_traject _ lt_i_x) nth_index.
Qed.
Lemma cycleP x y : reflect (exists i, y = x ^+ i) (y \in <[x]>).
Proof.
by apply: (iffP idP) => [/cyclePmin[i _]|[i ->]]; [exists i | apply: mem_cycle].
Qed.
Lemma expg_order x : x ^+ #[x] = 1.
Proof.
have: uniq (traject (mulg x) 1 #[x]).
by apply/card_uniqP; rewrite size_traject -(eq_card (cycle_traject x)).
case/cyclePmin: (mem_cycle x #[x]) => [] [//|i] ltix.
rewrite -(subnKC ltix) addSnnS /= expgD; move: (_ - _) => j x_j1.
case/andP=> /trajectP[]; exists j; first exact: leq_addl.
by apply: (mulgI (x ^+ i.+1)); rewrite -iterSr iterS -iteropE -expgS mulg1.
Qed.
Lemma expg_mod p k x : x ^+ p = 1 -> x ^+ (k %% p) = x ^+ k.
Proof.
move=> xp.
by rewrite {2}(divn_eq k p) expgD mulnC expgM xp expg1n mul1g.
Qed.
Lemma expg_mod_order x i : x ^+ (i %% #[x]) = x ^+ i.
Proof. by rewrite expg_mod // expg_order. Qed.
Lemma invg_expg x : x^-1 = x ^+ #[x].-1.
Proof. by apply/eqP; rewrite eq_invg_mul -expgS prednK ?expg_order. Qed.
Lemma invg2id x : #[x] = 2 -> x^-1 = x.
Proof. by move=> ox; rewrite invg_expg ox. Qed.
Lemma cycleX x i : <[x ^+ i]> \subset <[x]>.
Proof. by rewrite cycle_subG; apply: mem_cycle. Qed.
Lemma cycleV x : <[x^-1]> = <[x]>.
Proof.
by apply/eqP; rewrite eq_sym eqEsubset !cycle_subG groupV -groupV !cycle_id.
Qed.
Lemma orderV x : #[x^-1] = #[x].
Proof. by rewrite /order cycleV. Qed.
Lemma cycleJ x y : <[x ^ y]> = <[x]> :^ y.
Proof. by rewrite -genJ conjg_set1. Qed.
Lemma orderJ x y : #[x ^ y] = #[x].
Proof. by rewrite /order cycleJ cardJg. Qed.
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.
suffices ->: (x \in 'N(A)) = (A :^ x == A) by apply: eqP.
by rewrite eqEcard cardJg leqnn andbT inE.
Qed.
Arguments normP {x A}.
Lemma group_set_normaliser A : group_set 'N(A).
Proof.
apply/group_setP; split=> [|x y Nx Ny]; rewrite inE ?conjsg1 //.
by rewrite conjsgM !(normP _).
Qed.
Canonical normaliser_group A := group (group_set_normaliser A).
Lemma normsP A B : reflect {in A, normalised B} (A \subset 'N(B)).
Proof.
apply: (iffP subsetP) => nBA x Ax; last by rewrite inE nBA //.
by apply/normP; apply: nBA.
Qed.
Arguments normsP {A B}.
Lemma memJ_norm x y A : x \in 'N(A) -> (y ^ x \in A) = (y \in A).
Proof. by move=> Nx; rewrite -{1}(normP Nx) memJ_conjg. Qed.
Lemma norms_cycle x y : (<[y]> \subset 'N(<[x]>)) = (x ^ y \in <[x]>).
Proof. by rewrite cycle_subG inE -cycleJ cycle_subG. Qed.
Lemma norm1 : 'N(1) = setT :> {set gT}.
Proof. by apply/setP=> x; rewrite !inE conjs1g subxx. Qed.
Lemma norms1 A : A \subset 'N(1).
Proof. by rewrite norm1 subsetT. Qed.
Lemma normCs A : 'N(~: A) = 'N(A).
Proof. by apply/setP=> x; rewrite -groupV !inE conjCg setCS sub_conjg. Qed.
Lemma normG G : G \subset 'N(G).
Proof. by apply/normsP; apply: conjGid. Qed.
Lemma normT : 'N([set: gT]) = [set: gT].
Proof. by apply/eqP; rewrite -subTset normG. Qed.
Lemma normsG A G : A \subset G -> A \subset 'N(G).
Proof. by move=> sAG; apply: subset_trans (normG G). Qed.
Lemma normC A B : A \subset 'N(B) -> commute A B.
Proof.
move/subsetP=> nBA; apply/setP=> u.
apply/mulsgP/mulsgP=> [[x y Ax By] | [y x By Ax]] -> {u}.
by exists (y ^ x^-1) x; rewrite -?conjgCV // memJ_norm // groupV nBA.
by exists x (y ^ x); rewrite -?conjgC // memJ_norm // nBA.
Qed.
Lemma norm_joinEl G H : G \subset 'N(H) -> G <*> H = G * H.
Proof. by move/normC/comm_joingE. Qed.
Lemma norm_joinEr G H : H \subset 'N(G) -> G <*> H = G * H.
Proof. by move/normC=> cHG; apply: comm_joingE. Qed.
Lemma norm_rlcoset G x : x \in 'N(G) -> G :* x = x *: G.
Proof. by rewrite -sub1set => /normC. Qed.
Lemma rcoset_mul G x y : x \in 'N(G) -> (G :* x) * (G :* y) = G :* (x * y).
Proof.
move/norm_rlcoset=> GxxG.
by rewrite mulgA -(mulgA _ _ G) -GxxG mulgA mulGid -mulgA mulg_set1.
Qed.
Lemma normJ A x : 'N(A :^ x) = 'N(A) :^ x.
Proof.
by apply/setP=> y; rewrite mem_conjg !inE -conjsgM conjgCV conjsgM conjSg.
Qed.
Lemma norm_conj_norm x A B :
x \in 'N(A) -> (A \subset 'N(B :^ x)) = (A \subset 'N(B)).
Proof. by move=> Nx; rewrite normJ -sub_conjgV (normP _) ?groupV. Qed.
Lemma norm_gen A : 'N(A) \subset 'N(<<A>>).
Proof. by apply/normsP=> x Nx; rewrite -genJ (normP Nx). Qed.
Lemma class_norm x G : G \subset 'N(x ^: G).
Proof. by apply/normsP=> y; apply: classGidr. Qed.
Lemma class_normal x G : x \in G -> x ^: G <| G.
Proof. by move=> Gx; rewrite /normal class_norm class_subG. Qed.
Lemma class_sub_norm G A x : G \subset 'N(A) -> (x ^: G \subset A) = (x \in A).
Proof.
move=> nAG; apply/subsetP/idP=> [-> // | Ax xy]; first exact: class_refl.
by case/imsetP=> y Gy ->; rewrite memJ_norm ?(subsetP nAG).
Qed.
Lemma class_support_norm A G : G \subset 'N(class_support A G).
Proof. by apply/normsP; apply: class_supportGidr. Qed.
Lemma class_support_sub_norm A B G :
A \subset G -> B \subset 'N(G) -> class_support A B \subset G.
Proof.
move=> sAG nGB; rewrite class_supportEr.
by apply/bigcupsP=> x Bx; rewrite -(normsP nGB x Bx) conjSg.
Qed.
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. exact: subset_trans nBA (norm_gen B). Qed.
Lemma norms_norm : A \subset 'N('N(B)).
Proof. by apply/normsP=> x Ax; rewrite -normJ (normsP nBA). Qed.
Lemma normsI : A \subset 'N(B :&: C).
Proof. by apply/normsP=> x Ax; rewrite conjIg !(normsP _ x Ax). Qed.
Lemma normsU : A \subset 'N(B :|: C).
Proof. by apply/normsP=> x Ax; rewrite conjUg !(normsP _ x Ax). Qed.
Lemma normsIs : B \subset 'N(D) -> A :&: B \subset 'N(C :&: D).
Proof.
move/normsP=> nDB; apply/normsP=> x; case/setIP=> Ax Bx.
by rewrite conjIg (normsP nCA) ?nDB.
Qed.
Lemma normsD : A \subset 'N(B :\: C).
Proof. by apply/normsP=> x Ax; rewrite conjDg !(normsP _ x Ax). Qed.
Lemma normsM : A \subset 'N(B * C).
Proof. by apply/normsP=> x Ax; rewrite conjsMg !(normsP _ x Ax). Qed.
Lemma normsY : A \subset 'N(B <*> C).
Proof. by apply/normsP=> x Ax; rewrite -genJ conjUg !(normsP _ x Ax). Qed.
Lemma normsR : A \subset 'N([~: B, C]).
Proof. by apply/normsP=> x Ax; rewrite conjsRg !(normsP _ x Ax). Qed.
Lemma norms_class_support : A \subset 'N(class_support B C).
Proof.
apply/subsetP=> x Ax; rewrite inE sub_conjg class_supportEr.
apply/bigcupsP=> y Cy; rewrite -sub_conjg -conjsgM conjgC conjsgM.
by rewrite (normsP nBA) // bigcup_sup ?memJ_norm ?(subsetP nCA).
Qed.
End norm_trans.
Lemma normsIG A B G : A \subset 'N(B) -> A :&: G \subset 'N(B :&: G).
Proof. by move/normsIs->; rewrite ?normG. Qed.
Lemma normsGI A B G : A \subset 'N(B) -> G :&: A \subset 'N(G :&: B).
Proof. by move=> nBA; rewrite !(setIC G) normsIG. Qed.
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.
elim/big_rec2: _ => [|i B N _ IH /subsetIP[nBiA /IH]]; last exact: normsI.
by rewrite normT.
Qed.
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.
move=> nBA; rewrite -normCs setC_bigcup norms_bigcap //.
by rewrite (eq_bigr _ (fun _ _ => normCs _)).
Qed.
Lemma normsD1 A B : A \subset 'N(B) -> A \subset 'N(B^#).
Proof. by move/normsD->; rewrite ?norms1. Qed.
Lemma normD1 A : 'N(A^#) = 'N(A).
Proof.
apply/eqP; rewrite eqEsubset normsD1 //.
rewrite -{2}(setID A 1) setIC normsU //; apply/normsP=> x _; apply/setP=> y.
by rewrite conjIg conjs1g !inE mem_conjg; case: eqP => // ->; rewrite conj1g.
Qed.
Lemma normalP A B : reflect (A \subset B /\ {in B, normalised A}) (A <| B).
Proof. by apply: (iffP andP)=> [] [sAB]; move/normsP. Qed.
Lemma normal_sub A B : A <| B -> A \subset B.
Proof. by case/andP. Qed.
Lemma normal_norm A B : A <| B -> B \subset 'N(A).
Proof. by case/andP. Qed.
Lemma normalS G H K : K \subset H -> H \subset G -> K <| G -> K <| H.
Proof.
by move=> sKH sHG /andP[_ nKG]; rewrite /(K <| _) sKH (subset_trans sHG).
Qed.
Lemma normal1 G : 1 <| G.
Proof. by rewrite /normal sub1set group1 norms1. Qed.
Lemma normal_refl G : G <| G.
Proof. by rewrite /(G <| _) normG subxx. Qed.
Lemma normalG G : G <| 'N(G).
Proof. by rewrite /(G <| _) normG subxx. Qed.
Lemma normalSG G H : H \subset G -> H <| 'N_G(H).
Proof. by move=> sHG; rewrite /normal subsetI sHG normG subsetIr. Qed.
Lemma normalJ A B x : (A :^ x <| B :^ x) = (A <| B).
Proof. by rewrite /normal normJ !conjSg. Qed.
Lemma normalM G A B : A <| G -> B <| G -> A * B <| G.
Proof.
by case/andP=> sAG nAG /andP[sBG nBG]; rewrite /normal mul_subG ?normsM.
Qed.
Lemma normalY G A B : A <| G -> B <| G -> A <*> B <| G.
Proof.
by case/andP=> sAG ? /andP[sBG ?]; rewrite /normal join_subG sAG sBG ?normsY.
Qed.
Lemma normalYl G H : (H <| H <*> G) = (G \subset 'N(H)).
Proof. by rewrite /normal joing_subl join_subG normG. Qed.
Lemma normalYr G H : (H <| G <*> H) = (G \subset 'N(H)).
Proof. by rewrite joingC normalYl. Qed.
Lemma normalI G A B : A <| G -> B <| G -> A :&: B <| G.
Proof.
by case/andP=> sAG nAG /andP[_ nBG]; rewrite /normal subIset ?sAG // normsI.
Qed.
Lemma norm_normalI G A : G \subset 'N(A) -> G :&: A <| G.
Proof. by move=> nAG; rewrite /normal subsetIl normsI ?normG. Qed.
Lemma normalGI G H A : H \subset G -> A <| G -> H :&: A <| H.
Proof.
by move=> sHG /andP[_ nAG]; apply: norm_normalI (subset_trans sHG nAG).
Qed.
Lemma normal_subnorm G H : (H <| 'N_G(H)) = (H \subset G).
Proof. by rewrite /normal subsetIr subsetI normG !andbT. Qed.
Lemma normalD1 A G : (A^# <| G) = (A <| G).
Proof. by rewrite /normal normD1 subDset (setUidPr (sub1G G)). Qed.
Lemma gcore_sub A G : gcore A G \subset A.
Proof. by rewrite (bigcap_min 1) ?conjsg1. Qed.
Lemma gcore_norm A G : G \subset 'N(gcore A G).
Proof.
apply/subsetP=> x Gx; rewrite inE; apply/bigcapsP=> y Gy.
by rewrite sub_conjg -conjsgM bigcap_inf ?groupM ?groupV.
Qed.
Lemma gcore_normal A G : A \subset G -> gcore A G <| G.
Proof.
by move=> sAG; rewrite /normal gcore_norm (subset_trans (gcore_sub A G)).
Qed.
Lemma gcore_max A B G : B \subset A -> G \subset 'N(B) -> B \subset gcore A G.
Proof.
move=> sBA nBG; apply/bigcapsP=> y Gy.
by rewrite -sub_conjgV (normsP nBG) ?groupV.
Qed.
Lemma sub_gcore A B G :
G \subset 'N(B) -> (B \subset gcore A G) = (B \subset A).
Proof.
move=> nBG; apply/idP/idP=> [sBAG | sBA]; last exact: gcore_max.
exact: subset_trans (gcore_sub A G).
Qed.
(* 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.
move=> sHG indexHG => /setDP[Gx notHx]; apply/eqP.
rewrite eqEcard -(leq_add2l #|G :&: H|) cardsID -(LagrangeI G H) indexHG muln2.
rewrite (setIidPr sHG) card_rcoset addnn leqnn andbT.
apply/subsetP=> _ /rcosetP[y Hy ->]; apply/setDP.
by rewrite !groupMl // (subsetP sHG).
Qed.
Lemma index2_normal G H : H \subset G -> #|G : H| = 2 -> H <| G.
Proof.
move=> sHG indexHG; rewrite /normal sHG; apply/subsetP=> x Gx.
case Hx: (x \in H); first by rewrite inE conjGid.
rewrite inE conjsgE mulgA -sub_rcosetV -invg_rcoset.
by rewrite !(rcoset_index2 sHG) ?inE ?groupV ?Hx // invDg !invGid.
Qed.
Lemma cent1P x y : reflect (commute x y) (x \in 'C[y]).
Proof.
rewrite [x \in _]inE conjg_set1 sub1set !inE (sameP eqP conjg_fixP)commg1_sym.
exact: commgP.
Qed.
Lemma cent1id x : x \in 'C[x]. Proof. exact/cent1P. Qed.
Lemma cent1E x y : (x \in 'C[y]) = (x * y == y * x).
Proof. by rewrite (sameP (cent1P x y) eqP). Qed.
Lemma cent1C x y : (x \in 'C[y]) = (y \in 'C[x]).
Proof. by rewrite !cent1E eq_sym. Qed.
Canonical centraliser_group A : {group _} := Eval hnf in [group of 'C(A)].
Lemma cent_set1 x : 'C([set x]) = 'C[x].
Proof. by apply: big_pred1 => y /=; rewrite !inE. Qed.
Lemma cent1J x y : 'C[x ^ y] = 'C[x] :^ y.
Proof. by rewrite -conjg_set1 normJ. Qed.
Lemma centP A x : reflect (centralises x A) (x \in 'C(A)).
Proof. by apply: (iffP bigcapP) => cxA y /cxA/cent1P. Qed.
Lemma centsP A B : reflect {in A, centralised B} (A \subset 'C(B)).
Proof. by apply: (iffP subsetP) => cAB x /cAB/centP. Qed.
Lemma centsC A B : (A \subset 'C(B)) = (B \subset 'C(A)).
Proof. by apply/centsP/centsP=> cAB x ? y ?; rewrite /commute -cAB. Qed.
Lemma cents1 A : A \subset 'C(1).
Proof. by rewrite centsC sub1G. Qed.
Lemma cent1T : 'C(1) = setT :> {set gT}.
Proof. by apply/eqP; rewrite -subTset cents1. Qed.
Lemma cent11T : 'C[1] = setT :> {set gT}.
Proof. by rewrite -cent_set1 cent1T. Qed.
Lemma cent_sub A : 'C(A) \subset 'N(A).
Proof.
apply/subsetP=> x /centP cAx; rewrite inE.
by apply/subsetP=> _ /imsetP[y Ay ->]; rewrite /conjg -cAx ?mulKg.
Qed.
Lemma cents_norm A B : A \subset 'C(B) -> A \subset 'N(B).
Proof. by move=> cAB; apply: subset_trans (cent_sub B). Qed.
Lemma centC A B : A \subset 'C(B) -> commute A B.
Proof. by move=> cAB; apply: normC (cents_norm cAB). Qed.
Lemma cent_joinEl G H : G \subset 'C(H) -> G <*> H = G * H.
Proof. by move=> cGH; apply: norm_joinEl (cents_norm cGH). Qed.
Lemma cent_joinEr G H : H \subset 'C(G) -> G <*> H = G * H.
Proof. by move=> cGH; apply: norm_joinEr (cents_norm cGH). Qed.
Lemma centJ A x : 'C(A :^ x) = 'C(A) :^ x.
Proof.
apply/setP=> y; rewrite mem_conjg; apply/centP/centP=> cAy z Az.
by apply: (conjg_inj x); rewrite 2!conjMg conjgKV cAy ?memJ_conjg.
by apply: (conjg_inj x^-1); rewrite 2!conjMg cAy -?mem_conjg.
Qed.
Lemma cent_norm A : 'N(A) \subset 'N('C(A)).
Proof. by apply/normsP=> x nCx; rewrite -centJ (normP nCx). Qed.
Lemma norms_cent A B : A \subset 'N(B) -> A \subset 'N('C(B)).
Proof. by move=> nBA; apply: subset_trans nBA (cent_norm B). Qed.
Lemma cent_normal A : 'C(A) <| 'N(A).
Proof. by rewrite /(_ <| _) cent_sub cent_norm. Qed.
Lemma centS A B : B \subset A -> 'C(A) \subset 'C(B).
Proof. by move=> sAB; rewrite centsC (subset_trans sAB) 1?centsC. Qed.
Lemma centsS A B C : A \subset B -> C \subset 'C(B) -> C \subset 'C(A).
Proof. by move=> sAB cCB; apply: subset_trans cCB (centS sAB). Qed.
Lemma centSS A B C D :
A \subset C -> B \subset D -> C \subset 'C(D) -> A \subset 'C(B).
Proof. by move=> sAC sBD cCD; apply: subset_trans (centsS sBD cCD). Qed.
Lemma centI A B : 'C(A) <*> 'C(B) \subset 'C(A :&: B).
Proof. by rewrite gen_subG subUset !centS ?(subsetIl, subsetIr). Qed.
Lemma centU A B : 'C(A :|: B) = 'C(A) :&: 'C(B).
Proof.
apply/eqP; rewrite eqEsubset subsetI 2?centS ?(subsetUl, subsetUr) //=.
by rewrite centsC subUset -centsC subsetIl -centsC subsetIr.
Qed.
Lemma cent_gen A : 'C(<<A>>) = 'C(A).
Proof. by apply/setP=> x; rewrite -!sub1set centsC gen_subG centsC. Qed.
Lemma cent_cycle x : 'C(<[x]>) = 'C[x].
Proof. by rewrite cent_gen cent_set1. Qed.
Lemma sub_cent1 A x : (A \subset 'C[x]) = (x \in 'C(A)).
Proof. by rewrite -cent_cycle centsC cycle_subG. Qed.
Lemma cents_cycle x y : commute x y -> <[x]> \subset 'C(<[y]>).
Proof. by move=> cxy; rewrite cent_cycle cycle_subG; apply/cent1P. Qed.
Lemma cycle_abelian x : abelian <[x]>.
Proof. exact: cents_cycle. Qed.
Lemma centY A B : 'C(A <*> B) = 'C(A) :&: 'C(B).
Proof. by rewrite cent_gen centU. Qed.
Lemma centM G H : 'C(G * H) = 'C(G) :&: 'C(H).
Proof. by rewrite -cent_gen genM_join centY. Qed.
Lemma cent_classP x G : reflect (x ^: G = [set x]) (x \in 'C(G)).
Proof.
apply: (iffP (centP _ _)) => [Cx | Cx1 y Gy].
apply/eqP; rewrite eqEsubset sub1set class_refl andbT.
by apply/subsetP=> _ /imsetP[y Gy ->]; rewrite !inE conjgE Cx ?mulKg.
by apply/commgP/conjg_fixP/set1P; rewrite -Cx1; apply/imsetP; exists y.
Qed.
Lemma commG1P A B : reflect ([~: A, B] = 1) (A \subset 'C(B)).
Proof.
apply: (iffP (centsP A B)) => [cAB | cAB1 x Ax y By].
apply/trivgP; rewrite gen_subG; apply/subsetP=> _ /imset2P[x y Ax Ay ->].
by rewrite inE; apply/commgP; apply: cAB.
by apply/commgP; rewrite -in_set1 -[[set 1]]cAB1 mem_commg.
Qed.
Lemma abelianE A : abelian A = (A \subset 'C(A)). Proof. by []. Qed.
Lemma abelian1 : abelian [1 gT]. Proof. exact: sub1G. Qed.
Lemma abelianS A B : A \subset B -> abelian B -> abelian A.
Proof. by move=> sAB; apply: centSS. Qed.
Lemma abelianJ A x : abelian (A :^ x) = abelian A.
Proof. by rewrite /abelian centJ conjSg. Qed.
Lemma abelian_gen A : abelian <<A>> = abelian A.
Proof. by rewrite /abelian cent_gen gen_subG. Qed.
Lemma abelianY A B :
abelian (A <*> B) = [&& abelian A, abelian B & B \subset 'C(A)].
Proof.
rewrite /abelian join_subG /= centY !subsetI -!andbA; congr (_ && _).
by rewrite centsC andbA andbb andbC.
Qed.
Lemma abelianM G H :
abelian (G * H) = [&& abelian G, abelian H & H \subset 'C(G)].
Proof. by rewrite -abelian_gen genM_join abelianY. Qed.
Section SubAbelian.
Variable A B C : {set gT}.
Hypothesis cAA : abelian A.
Lemma sub_abelian_cent : C \subset A -> A \subset 'C(C).
Proof. by move=> sCA; rewrite centsC (subset_trans sCA). Qed.
Lemma sub_abelian_cent2 : B \subset A -> C \subset A -> B \subset 'C(C).
Proof. by move=> sBA; move/sub_abelian_cent; apply: subset_trans. Qed.
Lemma sub_abelian_norm : C \subset A -> A \subset 'N(C).
Proof. by move=> sCA; rewrite cents_norm ?sub_abelian_cent. Qed.
Lemma sub_abelian_normal : (C \subset A) = (C <| A).
Proof.
by rewrite /normal; case sHG: (C \subset A); rewrite // sub_abelian_norm.
Qed.
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.
move=> exP; have [A maxA]: {A | maxgroup A gP}.
apply: ex_maxset; case: exP => G gPG.
by exists (G : {set gT}); rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (maxsetp maxA).
Qed.
Lemma ex_mingroup : (exists G, gP G) -> {G : {group gT} | mingroup G gP}.
Proof.
move=> exP; have [A minA]: {A | mingroup A gP}.
apply: ex_minset; case: exP => G gPG.
by exists (G : {set gT}); rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (minsetp minA).
Qed.
Variable G : {group gT}.
Lemma mingroupP :
reflect (gP G /\ forall H, gP H -> H \subset G -> H :=: G) (mingroup G gP).
Proof.
apply: (iffP minsetP); rewrite /= groupP genGidG /= => [] [-> minG].
by split=> // H gPH sGH; apply: minG; rewrite // groupP genGidG.
by split=> // A; case/andP=> gA gPA; rewrite -(gen_set_id gA); apply: minG.
Qed.
Lemma maxgroupP :
reflect (gP G /\ forall H, gP H -> G \subset H -> H :=: G) (maxgroup G gP).
Proof.
apply: (iffP maxsetP); rewrite /= groupP genGidG /= => [] [-> maxG].
by split=> // H gPH sGH; apply: maxG; rewrite // groupP genGidG.
by split=> // A; case/andP=> gA gPA; rewrite -(gen_set_id gA); apply: maxG.
Qed.
Lemma maxgroupp : maxgroup G gP -> gP G. Proof. by case/maxgroupP. Qed.
Lemma mingroupp : mingroup G gP -> gP G. Proof. by case/mingroupP. Qed.
Hypothesis gPG : gP G.
Lemma maxgroup_exists : {H : {group gT} | maxgroup H gP & G \subset H}.
Proof.
have [A maxA sGA]: {A | maxgroup A gP & G \subset A}.
by apply: maxset_exists; rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (maxsetp maxA).
Qed.
Lemma mingroup_exists : {H : {group gT} | mingroup H gP & H \subset G}.
Proof.
have [A maxA sGA]: {A | mingroup A gP & A \subset G}.
by apply: minset_exists; rewrite groupP genGidG.
by exists <<A>>%G; rewrite /= gen_set_id; case/andP: (minsetp maxA).
Qed.
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.
|
JacobiSymbol.lean
|
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll, Thomas Zhu, Mario Carneiro
-/
import Mathlib.NumberTheory.LegendreSymbol.QuadraticReciprocity
/-!
# The Jacobi Symbol
We define the Jacobi symbol and prove its main properties.
## Main definitions
We define the Jacobi symbol, `jacobiSym a b`, for integers `a` and natural numbers `b`
as the product over the prime factors `p` of `b` of the Legendre symbols `legendreSym p a`.
This agrees with the mathematical definition when `b` is odd.
The prime factors are obtained via `Nat.factors`. Since `Nat.factors 0 = []`,
this implies in particular that `jacobiSym a 0 = 1` for all `a`.
## Main statements
We prove the main properties of the Jacobi symbol, including the following.
* Multiplicativity in both arguments (`jacobiSym.mul_left`, `jacobiSym.mul_right`)
* The value of the symbol is `1` or `-1` when the arguments are coprime
(`jacobiSym.eq_one_or_neg_one`)
* The symbol vanishes if and only if `b ≠ 0` and the arguments are not coprime
(`jacobiSym.eq_zero_iff_not_coprime`)
* If the symbol has the value `-1`, then `a : ZMod b` is not a square
(`ZMod.nonsquare_of_jacobiSym_eq_neg_one`); the converse holds when `b = p` is a prime
(`ZMod.nonsquare_iff_jacobiSym_eq_neg_one`); in particular, in this case `a` is a
square mod `p` when the symbol has the value `1` (`ZMod.isSquare_of_jacobiSym_eq_one`).
* Quadratic reciprocity (`jacobiSym.quadratic_reciprocity`,
`jacobiSym.quadratic_reciprocity_one_mod_four`,
`jacobiSym.quadratic_reciprocity_three_mod_four`)
* The supplementary laws for `a = -1`, `a = 2`, `a = -2` (`jacobiSym.at_neg_one`,
`jacobiSym.at_two`, `jacobiSym.at_neg_two`)
* The symbol depends on `a` only via its residue class mod `b` (`jacobiSym.mod_left`)
and on `b` only via its residue class mod `4*a` (`jacobiSym.mod_right`)
* A `csimp` rule for `jacobiSym` and `legendreSym` that evaluates `J(a | b)` efficiently by
reducing to the case `0 ≤ a < b` and `a`, `b` odd, and then swaps `a`, `b` and recurses using
quadratic reciprocity.
## Notations
We define the notation `J(a | b)` for `jacobiSym a b`, localized to `NumberTheorySymbols`.
## Tags
Jacobi symbol, quadratic reciprocity
-/
section Jacobi
/-!
### Definition of the Jacobi symbol
We define the Jacobi symbol $\Bigl(\frac{a}{b}\Bigr)$ for integers `a` and natural numbers `b`
as the product of the Legendre symbols $\Bigl(\frac{a}{p}\Bigr)$, where `p` runs through the
prime divisors (with multiplicity) of `b`, as provided by `b.factors`. This agrees with the
Jacobi symbol when `b` is odd and gives less meaningful values when it is not (e.g., the symbol
is `1` when `b = 0`). This is called `jacobiSym a b`.
We define localized notation (locale `NumberTheorySymbols`) `J(a | b)` for the Jacobi
symbol `jacobiSym a b`.
-/
open Nat ZMod
-- Since we need the fact that the factors are prime, we use `List.pmap`.
/-- The Jacobi symbol of `a` and `b` -/
def jacobiSym (a : ℤ) (b : ℕ) : ℤ :=
(b.primeFactorsList.pmap (fun p pp => @legendreSym p ⟨pp⟩ a) fun _ pf =>
prime_of_mem_primeFactorsList pf).prod
-- Notation for the Jacobi symbol.
@[inherit_doc]
scoped[NumberTheorySymbols] notation "J(" a " | " b ")" => jacobiSym a b
open NumberTheorySymbols
/-!
### Properties of the Jacobi symbol
-/
namespace jacobiSym
/-- The symbol `J(a | 0)` has the value `1`. -/
@[simp]
theorem zero_right (a : ℤ) : J(a | 0) = 1 := by
simp only [jacobiSym, primeFactorsList_zero, List.prod_nil, List.pmap]
/-- The symbol `J(a | 1)` has the value `1`. -/
@[simp]
theorem one_right (a : ℤ) : J(a | 1) = 1 := by
simp only [jacobiSym, primeFactorsList_one, List.prod_nil, List.pmap]
/-- The Legendre symbol `legendreSym p a` with an integer `a` and a prime number `p`
is the same as the Jacobi symbol `J(a | p)`. -/
theorem legendreSym.to_jacobiSym (p : ℕ) [fp : Fact p.Prime] (a : ℤ) :
legendreSym p a = J(a | p) := by
simp only [jacobiSym, primeFactorsList_prime fp.1, List.prod_cons, List.prod_nil, mul_one,
List.pmap]
/-- The Jacobi symbol is multiplicative in its second argument. -/
theorem mul_right' (a : ℤ) {b₁ b₂ : ℕ} (hb₁ : b₁ ≠ 0) (hb₂ : b₂ ≠ 0) :
J(a | b₁ * b₂) = J(a | b₁) * J(a | b₂) := by
rw [jacobiSym, ((perm_primeFactorsList_mul hb₁ hb₂).pmap _).prod_eq, List.pmap_append,
List.prod_append]
pick_goal 2
· exact fun p hp =>
(List.mem_append.mp hp).elim prime_of_mem_primeFactorsList prime_of_mem_primeFactorsList
· rfl
/-- The Jacobi symbol is multiplicative in its second argument. -/
theorem mul_right (a : ℤ) (b₁ b₂ : ℕ) [NeZero b₁] [NeZero b₂] :
J(a | b₁ * b₂) = J(a | b₁) * J(a | b₂) :=
mul_right' a (NeZero.ne b₁) (NeZero.ne b₂)
/-- The Jacobi symbol takes only the values `0`, `1` and `-1`. -/
theorem trichotomy (a : ℤ) (b : ℕ) : J(a | b) = 0 ∨ J(a | b) = 1 ∨ J(a | b) = -1 :=
((MonoidHom.mrange (@SignType.castHom ℤ _ _).toMonoidHom).copy {0, 1, -1} <| by
rw [Set.pair_comm]
exact (SignType.range_eq SignType.castHom).symm).list_prod_mem
(by
intro _ ha'
rcases List.mem_pmap.mp ha' with ⟨p, hp, rfl⟩
haveI : Fact p.Prime := ⟨prime_of_mem_primeFactorsList hp⟩
exact quadraticChar_isQuadratic (ZMod p) a)
/-- The symbol `J(1 | b)` has the value `1`. -/
@[simp]
theorem one_left (b : ℕ) : J(1 | b) = 1 :=
List.prod_eq_one fun z hz => by
let ⟨p, hp, he⟩ := List.mem_pmap.1 hz
rw [← he, legendreSym.at_one]
/-- The Jacobi symbol is multiplicative in its first argument. -/
theorem mul_left (a₁ a₂ : ℤ) (b : ℕ) : J(a₁ * a₂ | b) = J(a₁ | b) * J(a₂ | b) := by
simp_rw [jacobiSym, List.pmap_eq_map_attach, legendreSym.mul _ _ _]
exact List.prod_map_mul (l := (primeFactorsList b).attach)
(f := fun x ↦ @legendreSym x {out := prime_of_mem_primeFactorsList x.2} a₁)
(g := fun x ↦ @legendreSym x {out := prime_of_mem_primeFactorsList x.2} a₂)
/-- The symbol `J(a | b)` vanishes iff `a` and `b` are not coprime (assuming `b ≠ 0`). -/
theorem eq_zero_iff_not_coprime {a : ℤ} {b : ℕ} [NeZero b] : J(a | b) = 0 ↔ a.gcd b ≠ 1 :=
List.prod_eq_zero_iff.trans
(by
rw [List.mem_pmap, Int.gcd_eq_natAbs, Ne, Prime.not_coprime_iff_dvd]
simp_rw [legendreSym.eq_zero_iff _ _, intCast_zmod_eq_zero_iff_dvd,
mem_primeFactorsList (NeZero.ne b), ← Int.natCast_dvd, Int.natCast_dvd_natCast, exists_prop,
and_assoc, _root_.and_comm])
/-- The symbol `J(a | b)` is nonzero when `a` and `b` are coprime. -/
protected theorem ne_zero {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) ≠ 0 := by
rcases eq_zero_or_neZero b with hb | _
· rw [hb, zero_right]
exact one_ne_zero
· contrapose! h; exact eq_zero_iff_not_coprime.1 h
/-- The symbol `J(a | b)` vanishes if and only if `b ≠ 0` and `a` and `b` are not coprime. -/
theorem eq_zero_iff {a : ℤ} {b : ℕ} : J(a | b) = 0 ↔ b ≠ 0 ∧ a.gcd b ≠ 1 :=
⟨fun h => by
rcases eq_or_ne b 0 with hb | hb
· rw [hb, zero_right] at h; cases h
exact ⟨hb, mt jacobiSym.ne_zero <| Classical.not_not.2 h⟩, fun ⟨hb, h⟩ => by
rw [← neZero_iff] at hb; exact eq_zero_iff_not_coprime.2 h⟩
/-- The symbol `J(0 | b)` vanishes when `b > 1`. -/
theorem zero_left {b : ℕ} (hb : 1 < b) : J(0 | b) = 0 :=
(@eq_zero_iff_not_coprime 0 b ⟨ne_zero_of_lt hb⟩).mpr <| by
rw [Int.gcd_zero_left, Int.natAbs_natCast]; exact hb.ne'
/-- The symbol `J(a | b)` takes the value `1` or `-1` if `a` and `b` are coprime. -/
theorem eq_one_or_neg_one {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) = 1 ∨ J(a | b) = -1 :=
(trichotomy a b).resolve_left <| jacobiSym.ne_zero h
/-- We have that `J(a^e | b) = J(a | b)^e`. -/
theorem pow_left (a : ℤ) (e b : ℕ) : J(a ^ e | b) = J(a | b) ^ e :=
Nat.recOn e (by rw [_root_.pow_zero, _root_.pow_zero, one_left]) fun _ ih => by
rw [_root_.pow_succ, _root_.pow_succ, mul_left, ih]
/-- We have that `J(a | b^e) = J(a | b)^e`. -/
theorem pow_right (a : ℤ) (b e : ℕ) : J(a | b ^ e) = J(a | b) ^ e := by
induction e with
| zero => rw [Nat.pow_zero, _root_.pow_zero, one_right]
| succ e ih =>
rcases eq_zero_or_neZero b with hb | _
· rw [hb, zero_pow e.succ_ne_zero, zero_right, one_pow]
· rw [_root_.pow_succ, _root_.pow_succ, mul_right, ih]
/-- The square of `J(a | b)` is `1` when `a` and `b` are coprime. -/
theorem sq_one {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a | b) ^ 2 = 1 := by
rcases eq_one_or_neg_one h with h₁ | h₁ <;> rw [h₁] <;> rfl
/-- The symbol `J(a^2 | b)` is `1` when `a` and `b` are coprime. -/
theorem sq_one' {a : ℤ} {b : ℕ} (h : a.gcd b = 1) : J(a ^ 2 | b) = 1 := by rw [pow_left, sq_one h]
/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/
theorem mod_left (a : ℤ) (b : ℕ) : J(a | b) = J(a % b | b) :=
congr_arg List.prod <|
List.pmap_congr_left _
(by
rintro p hp _ h₂
conv_rhs =>
rw [legendreSym.mod, Int.emod_emod_of_dvd _ (Int.natCast_dvd_natCast.2 <|
dvd_of_mem_primeFactorsList hp), ← legendreSym.mod])
/-- The symbol `J(a | b)` depends only on `a` mod `b`. -/
theorem mod_left' {a₁ a₂ : ℤ} {b : ℕ} (h : a₁ % b = a₂ % b) : J(a₁ | b) = J(a₂ | b) := by
rw [mod_left, h, ← mod_left]
/-- If `p` is prime, `J(a | p) = -1` and `p` divides `x^2 - a*y^2`, then `p` must divide
`x` and `y`. -/
theorem prime_dvd_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : J(a | p) = -1) {x y : ℤ}
(hxy : ↑p ∣ (x ^ 2 - a * y ^ 2 : ℤ)) : ↑p ∣ x ∧ ↑p ∣ y := by
rw [← legendreSym.to_jacobiSym] at h
exact legendreSym.prime_dvd_of_eq_neg_one h hxy
/-- We can pull out a product over a list in the first argument of the Jacobi symbol. -/
theorem list_prod_left {l : List ℤ} {n : ℕ} : J(l.prod | n) = (l.map fun a => J(a | n)).prod := by
induction l with
| nil => simp only [List.prod_nil, List.map_nil, one_left]
| cons n l' ih => rw [List.map, List.prod_cons, List.prod_cons, mul_left, ih]
/-- We can pull out a product over a list in the second argument of the Jacobi symbol. -/
theorem list_prod_right {a : ℤ} {l : List ℕ} (hl : ∀ n ∈ l, n ≠ 0) :
J(a | l.prod) = (l.map fun n => J(a | n)).prod := by
induction l with
| nil => simp only [List.prod_nil, one_right, List.map_nil]
| cons n l' ih =>
have hn := hl n List.mem_cons_self
-- `n ≠ 0`
have hl' := List.prod_ne_zero fun hf => hl 0 (List.mem_cons_of_mem _ hf) rfl
-- `l'.prod ≠ 0`
have h := fun m hm => hl m (List.mem_cons_of_mem _ hm)
-- `∀ (m : ℕ), m ∈ l' → m ≠ 0`
rw [List.map, List.prod_cons, List.prod_cons, mul_right' a hn hl', ih h]
/-- If `J(a | n) = -1`, then `n` has a prime divisor `p` such that `J(a | p) = -1`. -/
theorem eq_neg_one_at_prime_divisor_of_eq_neg_one {a : ℤ} {n : ℕ} (h : J(a | n) = -1) :
∃ p : ℕ, p.Prime ∧ p ∣ n ∧ J(a | p) = -1 := by
have hn₀ : n ≠ 0 := by
rintro rfl
rw [zero_right, CharZero.eq_neg_self_iff] at h
exact one_ne_zero h
have hf₀ (p) (hp : p ∈ n.primeFactorsList) : p ≠ 0 := (Nat.pos_of_mem_primeFactorsList hp).ne.symm
rw [← Nat.prod_primeFactorsList hn₀, list_prod_right hf₀] at h
obtain ⟨p, hmem, hj⟩ := List.mem_map.mp (List.neg_one_mem_of_prod_eq_neg_one h)
exact ⟨p, Nat.prime_of_mem_primeFactorsList hmem, Nat.dvd_of_mem_primeFactorsList hmem, hj⟩
end jacobiSym
namespace ZMod
open jacobiSym
/-- If `J(a | b)` is `-1`, then `a` is not a square modulo `b`. -/
theorem nonsquare_of_jacobiSym_eq_neg_one {a : ℤ} {b : ℕ} (h : J(a | b) = -1) :
¬IsSquare (a : ZMod b) := fun ⟨r, ha⟩ => by
rw [← r.coe_valMinAbs, ← Int.cast_mul, intCast_eq_intCast_iff', ← sq] at ha
apply (by simp : ¬(0 : ℤ) ≤ -1)
rw [← h, mod_left, ha, ← mod_left, pow_left]
apply sq_nonneg
/-- If `p` is prime, then `J(a | p)` is `-1` iff `a` is not a square modulo `p`. -/
theorem nonsquare_iff_jacobiSym_eq_neg_one {a : ℤ} {p : ℕ} [Fact p.Prime] :
J(a | p) = -1 ↔ ¬IsSquare (a : ZMod p) := by
rw [← legendreSym.to_jacobiSym]
exact legendreSym.eq_neg_one_iff p
/-- If `p` is prime and `J(a | p) = 1`, then `a` is a square mod `p`. -/
theorem isSquare_of_jacobiSym_eq_one {a : ℤ} {p : ℕ} [Fact p.Prime] (h : J(a | p) = 1) :
IsSquare (a : ZMod p) :=
Classical.not_not.mp <| by rw [← nonsquare_iff_jacobiSym_eq_neg_one, h]; decide
end ZMod
/-!
### Values at `-1`, `2` and `-2`
-/
namespace jacobiSym
/-- If `χ` is a multiplicative function such that `J(a | p) = χ p` for all odd primes `p`,
then `J(a | b)` equals `χ b` for all odd natural numbers `b`. -/
theorem value_at (a : ℤ) {R : Type*} [Semiring R] (χ : R →* ℤ)
(hp : ∀ (p : ℕ) (pp : p.Prime), p ≠ 2 → @legendreSym p ⟨pp⟩ a = χ p) {b : ℕ} (hb : Odd b) :
J(a | b) = χ b := by
conv_rhs => rw [← prod_primeFactorsList hb.pos.ne', cast_list_prod, map_list_prod χ]
rw [jacobiSym, List.map_map, ← List.pmap_eq_map
fun _ => prime_of_mem_primeFactorsList]
congr 1; apply List.pmap_congr_left
exact fun p h pp _ => hp p pp (hb.ne_two_of_dvd_nat <| dvd_of_mem_primeFactorsList h)
/-- If `b` is odd, then `J(-1 | b)` is given by `χ₄ b`. -/
theorem at_neg_one {b : ℕ} (hb : Odd b) : J(-1 | b) = χ₄ b :=
-- Porting note: In mathlib3, it was written `χ₄` and Lean could guess that it had to use
-- `χ₄.to_monoid_hom`. This is not the case with Lean 4.
value_at (-1) χ₄.toMonoidHom (fun p pp => @legendreSym.at_neg_one p ⟨pp⟩) hb
/-- If `b` is odd, then `J(-a | b) = χ₄ b * J(a | b)`. -/
protected theorem neg (a : ℤ) {b : ℕ} (hb : Odd b) : J(-a | b) = χ₄ b * J(a | b) := by
rw [neg_eq_neg_one_mul, mul_left, at_neg_one hb]
/-- If `b` is odd, then `J(2 | b)` is given by `χ₈ b`. -/
theorem at_two {b : ℕ} (hb : Odd b) : J(2 | b) = χ₈ b :=
value_at 2 χ₈.toMonoidHom (fun p pp => @legendreSym.at_two p ⟨pp⟩) hb
/-- If `b` is odd, then `J(-2 | b)` is given by `χ₈' b`. -/
theorem at_neg_two {b : ℕ} (hb : Odd b) : J(-2 | b) = χ₈' b :=
value_at (-2) χ₈'.toMonoidHom (fun p pp => @legendreSym.at_neg_two p ⟨pp⟩) hb
theorem div_four_left {a : ℤ} {b : ℕ} (ha4 : a % 4 = 0) (hb2 : b % 2 = 1) :
J(a / 4 | b) = J(a | b) := by
obtain ⟨a, rfl⟩ := Int.dvd_of_emod_eq_zero ha4
have : Int.gcd (2 : ℕ) b = 1 := by
rw [Int.gcd_natCast_natCast, ← b.mod_add_div 2, hb2, Nat.gcd_add_mul_left_right,
Nat.gcd_one_right]
rw [Int.mul_ediv_cancel_left _ (by decide), jacobiSym.mul_left,
(by decide : (4 : ℤ) = (2 : ℕ) ^ 2), jacobiSym.sq_one' this, one_mul]
theorem even_odd {a : ℤ} {b : ℕ} (ha2 : a % 2 = 0) (hb2 : b % 2 = 1) :
(if b % 8 = 3 ∨ b % 8 = 5 then -J(a / 2 | b) else J(a / 2 | b)) = J(a | b) := by
obtain ⟨a, rfl⟩ := Int.dvd_of_emod_eq_zero ha2
rw [Int.mul_ediv_cancel_left _ (by decide), jacobiSym.mul_left,
jacobiSym.at_two (Nat.odd_iff.mpr hb2), ZMod.χ₈_nat_eq_if_mod_eight,
if_neg (Nat.mod_two_ne_zero.mpr hb2)]
grind
end jacobiSym
/-!
### Quadratic Reciprocity
-/
/-- The bi-multiplicative map giving the sign in the Law of Quadratic Reciprocity -/
def qrSign (m n : ℕ) : ℤ :=
J(χ₄ m | n)
namespace qrSign
/-- We can express `qrSign m n` as a power of `-1` when `m` and `n` are odd. -/
theorem neg_one_pow {m n : ℕ} (hm : Odd m) (hn : Odd n) :
qrSign m n = (-1) ^ (m / 2 * (n / 2)) := by
rw [qrSign, pow_mul, ← χ₄_eq_neg_one_pow (odd_iff.mp hm)]
rcases odd_mod_four_iff.mp (odd_iff.mp hm) with h | h
· rw [χ₄_nat_one_mod_four h, jacobiSym.one_left, one_pow]
· rw [χ₄_nat_three_mod_four h, ← χ₄_eq_neg_one_pow (odd_iff.mp hn), jacobiSym.at_neg_one hn]
/-- When `m` and `n` are odd, then the square of `qrSign m n` is `1`. -/
theorem sq_eq_one {m n : ℕ} (hm : Odd m) (hn : Odd n) : qrSign m n ^ 2 = 1 := by
rw [neg_one_pow hm hn, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]
/-- `qrSign` is multiplicative in the first argument. -/
theorem mul_left (m₁ m₂ n : ℕ) : qrSign (m₁ * m₂) n = qrSign m₁ n * qrSign m₂ n := by
simp_rw [qrSign, Nat.cast_mul, map_mul, jacobiSym.mul_left]
/-- `qrSign` is multiplicative in the second argument. -/
theorem mul_right (m n₁ n₂ : ℕ) [NeZero n₁] [NeZero n₂] :
qrSign m (n₁ * n₂) = qrSign m n₁ * qrSign m n₂ :=
jacobiSym.mul_right (χ₄ m) n₁ n₂
/-- `qrSign` is symmetric when both arguments are odd. -/
protected theorem symm {m n : ℕ} (hm : Odd m) (hn : Odd n) : qrSign m n = qrSign n m := by
rw [neg_one_pow hm hn, neg_one_pow hn hm, mul_comm (m / 2)]
/-- We can move `qrSign m n` from one side of an equality to the other when `m` and `n` are odd. -/
theorem eq_iff_eq {m n : ℕ} (hm : Odd m) (hn : Odd n) (x y : ℤ) :
qrSign m n * x = y ↔ x = qrSign m n * y := by
refine
⟨fun h' =>
let h := h'.symm
?_,
fun h => ?_⟩ <;>
rw [h, ← mul_assoc, ← pow_two, sq_eq_one hm hn, one_mul]
end qrSign
namespace jacobiSym
/-- The **Law of Quadratic Reciprocity for the Jacobi symbol**, version with `qrSign` -/
theorem quadratic_reciprocity' {a b : ℕ} (ha : Odd a) (hb : Odd b) :
J(a | b) = qrSign b a * J(b | a) := by
-- define the right hand side for fixed `a` as a `ℕ →* ℤ`
let rhs : ℕ → ℕ →* ℤ := fun a =>
{ toFun := fun x => qrSign x a * J(x | a)
map_one' := by convert ← mul_one (M := ℤ) _; (on_goal 1 => symm); all_goals apply one_left
map_mul' := fun x y => by
simp_rw [qrSign.mul_left x y a, Nat.cast_mul, mul_left, mul_mul_mul_comm] }
have rhs_apply : ∀ a b : ℕ, rhs a b = qrSign b a * J(b | a) := fun a b => rfl
refine value_at a (rhs a) (fun p pp hp => Eq.symm ?_) hb
have hpo := pp.eq_two_or_odd'.resolve_left hp
rw [@legendreSym.to_jacobiSym p ⟨pp⟩, rhs_apply, Nat.cast_id, qrSign.eq_iff_eq hpo ha,
qrSign.symm hpo ha]
refine value_at p (rhs p) (fun q pq hq => ?_) ha
have hqo := pq.eq_two_or_odd'.resolve_left hq
rw [rhs_apply, Nat.cast_id, ← @legendreSym.to_jacobiSym p ⟨pp⟩, qrSign.symm hqo hpo,
qrSign.neg_one_pow hpo hqo, @legendreSym.quadratic_reciprocity' p q ⟨pp⟩ ⟨pq⟩ hp hq]
/-- The Law of Quadratic Reciprocity for the Jacobi symbol -/
theorem quadratic_reciprocity {a b : ℕ} (ha : Odd a) (hb : Odd b) :
J(a | b) = (-1) ^ (a / 2 * (b / 2)) * J(b | a) := by
rw [← qrSign.neg_one_pow ha hb, qrSign.symm ha hb, quadratic_reciprocity' ha hb]
/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers
with `a % 4 = 1` and `b` odd, then `J(a | b) = J(b | a)`. -/
theorem quadratic_reciprocity_one_mod_four {a b : ℕ} (ha : a % 4 = 1) (hb : Odd b) :
J(a | b) = J(b | a) := by
rw [quadratic_reciprocity (odd_iff.mpr (odd_of_mod_four_eq_one ha)) hb, pow_mul,
neg_one_pow_div_two_of_one_mod_four ha, one_pow, one_mul]
/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers
with `a` odd and `b % 4 = 1`, then `J(a | b) = J(b | a)`. -/
theorem quadratic_reciprocity_one_mod_four' {a b : ℕ} (ha : Odd a) (hb : b % 4 = 1) :
J(a | b) = J(b | a) :=
(quadratic_reciprocity_one_mod_four hb ha).symm
/-- The Law of Quadratic Reciprocity for the Jacobi symbol: if `a` and `b` are natural numbers
both congruent to `3` mod `4`, then `J(a | b) = -J(b | a)`. -/
theorem quadratic_reciprocity_three_mod_four {a b : ℕ} (ha : a % 4 = 3) (hb : b % 4 = 3) :
J(a | b) = -J(b | a) := by
let nop := @neg_one_pow_div_two_of_three_mod_four
rw [quadratic_reciprocity, pow_mul, nop ha, nop hb, neg_one_mul] <;>
rwa [odd_iff, odd_of_mod_four_eq_three]
theorem quadratic_reciprocity_if {a b : ℕ} (ha2 : a % 2 = 1) (hb2 : b % 2 = 1) :
(if a % 4 = 3 ∧ b % 4 = 3 then -J(b | a) else J(b | a)) = J(a | b) := by
rcases Nat.odd_mod_four_iff.mp ha2 with ha1 | ha3
· simpa [ha1] using jacobiSym.quadratic_reciprocity_one_mod_four' (Nat.odd_iff.mpr hb2) ha1
rcases Nat.odd_mod_four_iff.mp hb2 with hb1 | hb3
· simpa [hb1] using jacobiSym.quadratic_reciprocity_one_mod_four hb1 (Nat.odd_iff.mpr ha2)
simpa [ha3, hb3] using (jacobiSym.quadratic_reciprocity_three_mod_four ha3 hb3).symm
/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a` (version for `a : ℕ`). -/
theorem mod_right' (a : ℕ) {b : ℕ} (hb : Odd b) : J(a | b) = J(a | b % (4 * a)) := by
rcases eq_or_ne a 0 with (rfl | ha₀)
· rw [mul_zero, mod_zero]
have hb' : Odd (b % (4 * a)) := hb.mod_even (Even.mul_right (by decide) _)
rcases exists_eq_pow_mul_and_not_dvd ha₀ 2 (by simp) with ⟨e, a', ha₁', ha₂⟩
have ha₁ := odd_iff.mpr (two_dvd_ne_zero.mp ha₁')
nth_rw 2 [ha₂]; nth_rw 1 [ha₂]
rw [Nat.cast_mul, mul_left, mul_left, quadratic_reciprocity' ha₁ hb,
quadratic_reciprocity' ha₁ hb', Nat.cast_pow, pow_left, pow_left, Nat.cast_two, at_two hb,
at_two hb']
congr 1; swap
· congr 1
· simp_rw [qrSign]
rw [χ₄_nat_mod_four, χ₄_nat_mod_four (b % (4 * a)), mod_mod_of_dvd b (dvd_mul_right 4 a)]
· rw [mod_left ↑(b % _), mod_left b, Int.natCast_mod, Int.emod_emod_of_dvd b]
simp only [ha₂, Nat.cast_mul, ← mul_assoc]
apply dvd_mul_left
rcases e with - | e; · rfl
· rw [χ₈_nat_mod_eight, χ₈_nat_mod_eight (b % (4 * a)), mod_mod_of_dvd b]
use 2 ^ e * a'; rw [ha₂, Nat.pow_succ]; ring
/-- The Jacobi symbol `J(a | b)` depends only on `b` mod `4*a`. -/
theorem mod_right (a : ℤ) {b : ℕ} (hb : Odd b) : J(a | b) = J(a | b % (4 * a.natAbs)) := by
rcases Int.natAbs_eq a with ha | ha <;> nth_rw 2 [ha] <;> nth_rw 1 [ha]
· exact mod_right' a.natAbs hb
· have hb' : Odd (b % (4 * a.natAbs)) := hb.mod_even (Even.mul_right (by decide) _)
rw [jacobiSym.neg _ hb, jacobiSym.neg _ hb', mod_right' _ hb, χ₄_nat_mod_four,
χ₄_nat_mod_four (b % (4 * _)), mod_mod_of_dvd b (dvd_mul_right 4 _)]
end jacobiSym
end Jacobi
section FastJacobi
/-!
### Fast computation of the Jacobi symbol
We follow the implementation as in `Mathlib/Tactic/NormNum/LegendreSymbol.lean`.
-/
open NumberTheorySymbols jacobiSym
/-- Computes `J(a | b)` (or `-J(a | b)` if `flip` is set to `true`) given assumptions, by reducing
`a` to odd by repeated division and then using quadratic reciprocity to swap `a`, `b`. -/
private def fastJacobiSymAux (a b : ℕ) (flip : Bool) (ha0 : a > 0) : ℤ :=
if ha4 : a % 4 = 0 then
fastJacobiSymAux (a / 4) b flip
(Nat.div_pos (Nat.le_of_dvd ha0 (Nat.dvd_of_mod_eq_zero ha4)) (by decide))
else if ha2 : a % 2 = 0 then
fastJacobiSymAux (a / 2) b (xor (b % 8 = 3 ∨ b % 8 = 5) flip)
(Nat.div_pos (Nat.le_of_dvd ha0 (Nat.dvd_of_mod_eq_zero ha2)) (by decide))
else if ha1 : a = 1 then
if flip then -1 else 1
else if hba : b % a = 0 then
0
else
fastJacobiSymAux (b % a) a (xor (a % 4 = 3 ∧ b % 4 = 3) flip) (Nat.pos_of_ne_zero hba)
termination_by a
decreasing_by
· exact a.div_lt_self ha0 (by decide)
· exact a.div_lt_self ha0 (by decide)
· exact b.mod_lt ha0
private theorem fastJacobiSymAux.eq_jacobiSym {a b : ℕ} {flip : Bool} {ha0 : a > 0}
(hb2 : b % 2 = 1) (hb1 : b > 1) :
fastJacobiSymAux a b flip ha0 = if flip then -J(a | b) else J(a | b) := by
induction a using Nat.strongRecOn generalizing b flip with | ind a IH =>
unfold fastJacobiSymAux
split <;> rename_i ha4
· rw [IH (a / 4) (a.div_lt_self ha0 (by decide)) hb2 hb1]
simp only [Int.natCast_ediv, Nat.cast_ofNat, div_four_left (a := a) (mod_cast ha4) hb2]
split <;> rename_i ha2
· rw [IH (a / 2) (a.div_lt_self ha0 (by decide)) hb2 hb1]
simp only [Int.natCast_ediv, Nat.cast_ofNat, ← even_odd (a := a) (mod_cast ha2) hb2]
by_cases h : b % 8 = 3 ∨ b % 8 = 5 <;> simp [h]; cases flip <;> simp
split <;> rename_i ha1
· subst ha1; simp
split <;> rename_i hba
· suffices J(a | b) = 0 by simp [this]
refine eq_zero_iff.mpr ⟨fun h ↦ absurd (h ▸ hb1) (by decide), ?_⟩
rwa [Int.gcd_natCast_natCast, Nat.gcd_eq_left (Nat.dvd_of_mod_eq_zero hba)]
rw [IH (b % a) (b.mod_lt ha0) (Nat.mod_two_ne_zero.mp ha2) (lt_of_le_of_ne ha0 (Ne.symm ha1))]
simp only [Int.natCast_mod, ← mod_left]
rw [← quadratic_reciprocity_if (Nat.mod_two_ne_zero.mp ha2) hb2]
by_cases h : a % 4 = 3 ∧ b % 4 = 3 <;> simp [h]; cases flip <;> simp
/-- Computes `J(a | b)` by reducing `b` to odd by repeated division and then using
`fastJacobiSymAux`. -/
private def fastJacobiSym (a : ℤ) (b : ℕ) : ℤ :=
if hb0 : b = 0 then
1
else if _ : b % 2 = 0 then
if a % 2 = 0 then
0
else
have : b / 2 < b := b.div_lt_self (Nat.pos_of_ne_zero hb0) one_lt_two
fastJacobiSym a (b / 2)
else if b = 1 then
1
else if hab : a % b = 0 then
0
else
fastJacobiSymAux (a % b).natAbs b false (Int.natAbs_pos.mpr hab)
@[csimp] private theorem fastJacobiSym.eq : jacobiSym = fastJacobiSym := by
ext a b
induction b using Nat.strongRecOn with | ind b IH =>
unfold fastJacobiSym
split_ifs with hb0 hb2 ha2 hb1 hab
· rw [hb0, zero_right]
· refine eq_zero_iff.mpr ⟨hb0, ne_of_gt ?_⟩
refine Nat.le_of_dvd (Int.gcd_pos_iff.mpr (mod_cast .inr hb0)) ?_
refine Nat.dvd_gcd (Int.ofNat_dvd_left.mp (Int.dvd_of_emod_eq_zero ha2)) ?_
exact Int.ofNat_dvd_left.mp (Int.dvd_of_emod_eq_zero (mod_cast hb2))
· dsimp only
rw [← IH (b / 2) (b.div_lt_self (Nat.pos_of_ne_zero hb0) one_lt_two)]
obtain ⟨b, rfl⟩ := Nat.dvd_of_mod_eq_zero hb2
rw [mul_right' a (by decide) fun h ↦ hb0 (mul_eq_zero_of_right 2 h),
b.mul_div_cancel_left (by decide), mod_left a 2, Nat.cast_ofNat,
Int.emod_two_ne_zero.mp ha2, one_left, one_mul]
· rw [hb1, one_right]
· rw [mod_left, hab, zero_left (lt_of_le_of_ne (Nat.pos_of_ne_zero hb0) (Ne.symm hb1))]
· rw [fastJacobiSymAux.eq_jacobiSym, if_neg Bool.false_ne_true, mod_left a b,
Int.natAbs_of_nonneg (a.emod_nonneg (mod_cast hb0))]
· exact Nat.mod_two_ne_zero.mp hb2
· exact lt_of_le_of_ne (Nat.one_le_iff_ne_zero.mpr hb0) (Ne.symm hb1)
/-- Computes `legendreSym p a` using `fastJacobiSym`. -/
@[inline, nolint unusedArguments]
private def fastLegendreSym (p : ℕ) [Fact p.Prime] (a : ℤ) : ℤ := J(a | p)
@[csimp] private theorem fastLegendreSym.eq : legendreSym = fastLegendreSym := by
ext p _ a; rw [legendreSym.to_jacobiSym, fastLegendreSym]
end FastJacobi
|
Support.lean
|
/-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Exact
import Mathlib.RingTheory.Ideal.Colon
import Mathlib.RingTheory.Localization.Finiteness
import Mathlib.RingTheory.Nakayama
import Mathlib.RingTheory.Spectrum.Prime.Basic
/-!
# Support of a module
## Main results
- `Module.support`: The support of an `R`-module as a subset of `Spec R`.
- `Module.mem_support_iff_exists_annihilator`: `p ∈ Supp M ↔ ∃ m, Ann(m) ≤ p`.
- `Module.support_eq_empty_iff`: `Supp M = ∅ ↔ M = 0`
- `Module.support_of_exact`: `Supp N = Supp M ∪ Supp P` for an exact sequence `0 → M → N → P → 0`.
- `Module.support_eq_zeroLocus`: If `M` is `R`-finite, then `Supp M = Z(Ann(M))`.
- `LocalizedModule.exists_subsingleton_away`:
If `M` is `R`-finite and `Mₚ = 0`, then `M[1/f] = 0` for some `p ∈ D(f)`.
Also see `Mathlib/RingTheory/Spectrum/Prime/Module.lean` for other results
depending on the Zariski topology.
## TODO
- Connect to associated primes once we have them in mathlib.
- Given an `R`-algebra `f : R → A` and a finite `R`-module `M`,
`Supp_A (A ⊗ M) = f♯ ⁻¹ Supp M` where `f♯ : Spec A → Spec R`. (stacks#0BUR)
-/
-- Basic files in `RingTheory` should avoid depending on the Zariski topology
-- See `Mathlib/RingTheory/Spectrum/Prime/Module.lean`
assert_not_exists TopologicalSpace
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {p : PrimeSpectrum R}
variable (R M) in
/-- The support of a module, defined as the set of primes `p` such that `Mₚ ≠ 0`. -/
@[stacks 00L1]
def Module.support : Set (PrimeSpectrum R) :=
{ p | Nontrivial (LocalizedModule p.asIdeal.primeCompl M) }
lemma Module.mem_support_iff :
p ∈ Module.support R M ↔ Nontrivial (LocalizedModule p.asIdeal.primeCompl M) := Iff.rfl
lemma Module.notMem_support_iff :
p ∉ Module.support R M ↔ Subsingleton (LocalizedModule p.asIdeal.primeCompl M) :=
not_nontrivial_iff_subsingleton
@[deprecated (since := "2025-05-23")] alias Module.not_mem_support_iff := Module.notMem_support_iff
lemma Module.notMem_support_iff' :
p ∉ Module.support R M ↔ ∀ m : M, ∃ r ∉ p.asIdeal, r • m = 0 := by
simp only [notMem_support_iff, Ideal.primeCompl, LocalizedModule.subsingleton_iff,
Submonoid.mem_mk, Subsemigroup.mem_mk, Set.mem_compl_iff, SetLike.mem_coe]
@[deprecated (since := "2025-05-23")]
alias Module.not_mem_support_iff' := Module.notMem_support_iff'
lemma Module.mem_support_iff' :
p ∈ Module.support R M ↔ ∃ m : M, ∀ r ∉ p.asIdeal, r • m ≠ 0 := by
rw [← @not_not (_ ∈ _), notMem_support_iff']
push_neg
rfl
lemma Module.mem_support_iff_exists_annihilator :
p ∈ Module.support R M ↔ ∃ m : M, (R ∙ m).annihilator ≤ p.asIdeal := by
rw [Module.mem_support_iff']
simp_rw [not_imp_not, SetLike.le_def, Submodule.mem_annihilator_span_singleton]
lemma Module.mem_support_mono {p q : PrimeSpectrum R} (H : p ≤ q) (hp : p ∈ Module.support R M) :
q ∈ Module.support R M := by
rw [Module.mem_support_iff_exists_annihilator] at hp ⊢
exact ⟨_, hp.choose_spec.trans H⟩
lemma Module.mem_support_iff_of_span_eq_top {s : Set M} (hs : Submodule.span R s = ⊤) :
p ∈ Module.support R M ↔ ∃ m ∈ s, (R ∙ m).annihilator ≤ p.asIdeal := by
constructor
· contrapose
rw [notMem_support_iff, LocalizedModule.subsingleton_iff_ker_eq_top, ← top_le_iff,
← hs, Submodule.span_le, Set.subset_def]
simp_rw [SetLike.le_def, Submodule.mem_annihilator_span_singleton, SetLike.mem_coe,
LocalizedModule.mem_ker_mkLinearMap_iff]
push_neg
simp_rw [and_comm]
exact id
· intro ⟨m, _, hm⟩
exact mem_support_iff_exists_annihilator.mpr ⟨m, hm⟩
lemma Module.annihilator_le_of_mem_support (hp : p ∈ Module.support R M) :
Module.annihilator R M ≤ p.asIdeal := by
obtain ⟨m, hm⟩ := mem_support_iff_exists_annihilator.mp hp
exact le_trans ((Submodule.subtype _).annihilator_le_of_injective Subtype.val_injective) hm
lemma LocalizedModule.subsingleton_iff_support_subset {f : R} :
Subsingleton (LocalizedModule (.powers f) M) ↔
Module.support R M ⊆ PrimeSpectrum.zeroLocus {f} := by
rw [LocalizedModule.subsingleton_iff]
constructor
· rintro H x hx' f rfl
obtain ⟨m, hm⟩ := Module.mem_support_iff_exists_annihilator.mp hx'
obtain ⟨_, ⟨n, rfl⟩, e⟩ := H m
exact Ideal.IsPrime.mem_of_pow_mem inferInstance n
(hm ((Submodule.mem_annihilator_span_singleton _ _).mpr e))
· intro H m
by_cases h : (Submodule.span R {m}).annihilator = ⊤
· rw [Submodule.annihilator_eq_top_iff, Submodule.span_singleton_eq_bot] at h
exact ⟨1, one_mem _, by simpa using h⟩
obtain ⟨n, hn⟩ : f ∈ (Submodule.span R {m}).annihilator.radical := by
rw [Ideal.radical_eq_sInf, Ideal.mem_sInf]
rintro p ⟨hp, hp'⟩
simpa using H (Module.mem_support_iff_exists_annihilator (p := ⟨p, hp'⟩).mpr ⟨_, hp⟩)
exact ⟨_, ⟨n, rfl⟩, (Submodule.mem_annihilator_span_singleton _ _).mp hn⟩
lemma Module.support_eq_empty_iff :
Module.support R M = ∅ ↔ Subsingleton M := by
rw [← Set.subset_empty_iff, ← PrimeSpectrum.zeroLocus_singleton_one,
← LocalizedModule.subsingleton_iff_support_subset, LocalizedModule.subsingleton_iff,
subsingleton_iff_forall_eq 0]
simp only [Submonoid.powers_one, Submonoid.mem_bot, exists_eq_left, one_smul]
lemma Module.nonempty_support_iff :
(Module.support R M).Nonempty ↔ Nontrivial M := by
rw [Set.nonempty_iff_ne_empty, ne_eq,
Module.support_eq_empty_iff, ← not_subsingleton_iff_nontrivial]
lemma Module.support_eq_empty [Subsingleton M] :
Module.support R M = ∅ :=
Module.support_eq_empty_iff.mpr ‹_›
lemma Module.support_of_algebra {A : Type*} [Ring A] [Algebra R A] :
Module.support R A = PrimeSpectrum.zeroLocus (RingHom.ker (algebraMap R A)) := by
ext p
simp only [mem_support_iff', ne_eq, PrimeSpectrum.mem_zeroLocus, SetLike.coe_subset_coe]
refine ⟨fun ⟨m, hm⟩ x hx ↦ not_not.mp fun hx' ↦ ?_, fun H ↦ ⟨1, fun r hr e ↦ ?_⟩⟩
· simpa [Algebra.smul_def, (show _ = _ from hx)] using hm _ hx'
· exact hr (H ((Algebra.algebraMap_eq_smul_one _).trans e))
lemma Module.support_of_noZeroSMulDivisors [NoZeroSMulDivisors R M] [Nontrivial M] :
Module.support R M = Set.univ := by
simp only [Set.eq_univ_iff_forall, mem_support_iff', ne_eq, smul_eq_zero, not_or]
obtain ⟨x, hx⟩ := exists_ne (0 : M)
exact fun p ↦ ⟨x, fun r hr ↦ ⟨fun e ↦ hr (e ▸ p.asIdeal.zero_mem), hx⟩⟩
variable {N P : Type*} [AddCommGroup N] [Module R N] [AddCommGroup P] [Module R P]
variable (f : M →ₗ[R] N) (g : N →ₗ[R] P)
@[stacks 00L3 "(2)"]
lemma Module.support_subset_of_injective (hf : Function.Injective f) :
Module.support R M ⊆ Module.support R N := by
simp_rw [Set.subset_def, mem_support_iff']
rintro x ⟨m, hm⟩
exact ⟨f m, fun r hr ↦ by simpa using hf.ne (hm r hr)⟩
@[stacks 00L3 "(3)"]
lemma Module.support_subset_of_surjective (hf : Function.Surjective f) :
Module.support R N ⊆ Module.support R M := by
simp_rw [Set.subset_def, mem_support_iff']
rintro x ⟨m, hm⟩
obtain ⟨m, rfl⟩ := hf m
exact ⟨m, fun r hr e ↦ hm r hr (by simpa using congr(f $e))⟩
variable {f g} in
/-- Given an exact sequence `0 → M → N → P → 0` of `R`-modules, `Supp N = Supp M ∪ Supp P`. -/
@[stacks 00L3 "(4)"]
lemma Module.support_of_exact (h : Function.Exact f g)
(hf : Function.Injective f) (hg : Function.Surjective g) :
Module.support R N = Module.support R M ∪ Module.support R P := by
refine subset_antisymm ?_ (Set.union_subset (Module.support_subset_of_injective f hf)
(Module.support_subset_of_surjective g hg))
intro x
contrapose
simp only [Set.mem_union, not_or, and_imp, notMem_support_iff']
intro H₁ H₂ m
obtain ⟨r, hr, e₁⟩ := H₂ (g m)
rw [← map_smul, h] at e₁
obtain ⟨m', hm'⟩ := e₁
obtain ⟨s, hs, e₁⟩ := H₁ m'
exact ⟨_, x.asIdeal.primeCompl.mul_mem hs hr, by rw [mul_smul, ← hm', ← map_smul, e₁, map_zero]⟩
lemma LinearEquiv.support_eq (e : M ≃ₗ[R] N) :
Module.support R M = Module.support R N :=
(Module.support_subset_of_injective e.toLinearMap e.injective).antisymm
(Module.support_subset_of_surjective e.toLinearMap e.surjective)
section Finite
variable [Module.Finite R M]
open PrimeSpectrum
lemma Module.mem_support_iff_of_finite :
p ∈ Module.support R M ↔ Module.annihilator R M ≤ p.asIdeal := by
classical
obtain ⟨s, hs⟩ := ‹Module.Finite R M›
refine ⟨annihilator_le_of_mem_support, fun H ↦ (mem_support_iff_of_span_eq_top hs).mpr ?_⟩
simp only [SetLike.le_def, Submodule.mem_annihilator_span_singleton] at H ⊢
contrapose! H
choose x hx hx' using Subtype.forall'.mp H
refine ⟨s.attach.prod x, ?_, ?_⟩
· rw [← Submodule.annihilator_top, ← hs, Submodule.mem_annihilator_span]
intro m
obtain ⟨k, hk⟩ := Finset.dvd_prod_of_mem x (Finset.mem_attach _ m)
rw [hk, mul_comm, mul_smul, hx, smul_zero]
· exact p.asIdeal.primeCompl.prod_mem (fun x _ ↦ hx' x)
/-- If `M` is `R`-finite, then `Supp M = Z(Ann(M))`. -/
@[stacks 00L2]
lemma Module.support_eq_zeroLocus :
Module.support R M = zeroLocus (Module.annihilator R M) :=
Set.ext fun _ ↦ mem_support_iff_of_finite
/-- If `M` is a finite module such that `Mₚ = 0` for some `p`,
then `M[1/f] = 0` for some `p ∈ D(f)`. -/
lemma LocalizedModule.exists_subsingleton_away (p : Ideal R) [p.IsPrime]
[Subsingleton (LocalizedModule p.primeCompl M)] :
∃ f ∉ p, Subsingleton (LocalizedModule (.powers f) M) := by
have : ⟨p, inferInstance⟩ ∈ (Module.support R M)ᶜ := by
simpa [Module.notMem_support_iff]
rw [Module.support_eq_zeroLocus, ← Set.biUnion_of_singleton (Module.annihilator R M : Set R),
PrimeSpectrum.zeroLocus_iUnion₂, Set.compl_iInter₂, Set.mem_iUnion₂] at this
obtain ⟨f, hf, hf'⟩ := this
exact ⟨f, by simpa using hf', subsingleton_iff.mpr
fun m ↦ ⟨f, Submonoid.mem_powers f, Module.mem_annihilator.mp hf _⟩⟩
/-- `Supp(M/IM) = Supp(M) ∩ Z(I)`. -/
@[stacks 00L3 "(1)"]
theorem Module.support_quotient (I : Ideal R) :
support R (M ⧸ (I • ⊤ : Submodule R M)) = support R M ∩ zeroLocus I := by
apply subset_antisymm
· refine Set.subset_inter ?_ ?_
· exact Module.support_subset_of_surjective _ (Submodule.mkQ_surjective _)
· rw [support_eq_zeroLocus]
apply PrimeSpectrum.zeroLocus_anti_mono_ideal
rw [Submodule.annihilator_quotient]
exact fun x hx ↦ Submodule.mem_colon.mpr fun p ↦ Submodule.smul_mem_smul hx
· rintro p ⟨hp₁, hp₂⟩
rw [Module.mem_support_iff] at hp₁ ⊢
let Rₚ := Localization.AtPrime p.asIdeal
let Mₚ := LocalizedModule p.asIdeal.primeCompl M
set Mₚ' := LocalizedModule p.asIdeal.primeCompl (M ⧸ (I • ⊤ : Submodule R M))
let Mₚ'' := Mₚ ⧸ I.map (algebraMap R Rₚ) • (⊤ : Submodule Rₚ Mₚ)
let e : Mₚ' ≃ₗ[Rₚ] Mₚ'' := (localizedQuotientEquiv _ _).symm ≪≫ₗ
Submodule.quotEquivOfEq _ _ (by rw [Submodule.localized,
Submodule.localized'_smul, Ideal.localized'_eq_map, Submodule.localized'_top])
have : Nontrivial Mₚ'' := by
apply Submodule.Quotient.nontrivial_of_lt_top
rw [lt_top_iff_ne_top, ne_comm]
apply Submodule.top_ne_ideal_smul_of_le_jacobson_annihilator
refine trans ?_ (IsLocalRing.maximalIdeal_le_jacobson _)
rw [← Localization.AtPrime.map_eq_maximalIdeal]
exact Ideal.map_mono hp₂
exact e.nontrivial
end Finite
|
UnitTrinomial.lean
|
/-
Copyright (c) 2022 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.Polynomial.UnitTrinomial
import Mathlib.Analysis.Complex.Polynomial.Basic
/-!
# Irreducibility of unit trinomials
## TODO
Develop more theory (e.g., it suffices to check that `aeval z p ≠ 0` for `z = 0` and `z` a root of
unity).
-/
namespace Polynomial.IsUnitTrinomial
variable {p : ℤ[X]}
/-- A unit trinomial is irreducible if it has no complex roots in common with its mirror. -/
theorem irreducible_of_coprime' (hp : IsUnitTrinomial p)
(h : ∀ z : ℂ, ¬(aeval z p = 0 ∧ aeval z (mirror p) = 0)) : Irreducible p := by
refine hp.irreducible_of_coprime fun q hq hq' => ?_
suffices ¬0 < q.natDegree by
rcases hq with ⟨p, rfl⟩
replace hp := hp.leadingCoeff_isUnit
rw [leadingCoeff_mul] at hp
replace hp := isUnit_of_mul_isUnit_left hp
rw [not_lt, Nat.le_zero] at this
rwa [eq_C_of_natDegree_eq_zero this, isUnit_C, ← this]
intro hq''
rw [natDegree_pos_iff_degree_pos] at hq''
rw [← degree_map_eq_of_injective (algebraMap ℤ ℂ).injective_int] at hq''
obtain ⟨z, hz⟩ := Complex.exists_root hq''
rw [IsRoot, eval_map, ← aeval_def] at hz
refine h z ⟨?_, ?_⟩
· obtain ⟨g', hg'⟩ := hq
rw [hg', aeval_mul, hz, zero_mul]
· obtain ⟨g', hg'⟩ := hq'
rw [hg', aeval_mul, hz, zero_mul]
end Polynomial.IsUnitTrinomial
|
Ring.lean
|
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Order.Filter.AtTopBot.Group
/-!
# Convergence to ±infinity in ordered rings
-/
variable {α β : Type*}
namespace Filter
section OrderedSemiring
variable [Semiring α] [PartialOrder α] [IsOrderedRing α] {l : Filter β} {f g : β → α}
theorem Tendsto.atTop_mul_atTop₀ (hf : Tendsto f l atTop) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x * g x) l atTop := by
refine tendsto_atTop_mono' _ ?_ hg
filter_upwards [hg.eventually (eventually_ge_atTop 0),
hf.eventually (eventually_ge_atTop 1)] with _ using le_mul_of_one_le_left
theorem tendsto_mul_self_atTop : Tendsto (fun x : α => x * x) atTop atTop :=
tendsto_id.atTop_mul_atTop₀ tendsto_id
/-- The monomial function `x^n` tends to `+∞` at `+∞` for any positive natural `n`.
A version for positive real powers exists as `tendsto_rpow_atTop`. -/
theorem tendsto_pow_atTop {n : ℕ} (hn : n ≠ 0) : Tendsto (fun x : α => x ^ n) atTop atTop :=
tendsto_atTop_mono' _ ((eventually_ge_atTop 1).mono fun _x hx => le_self_pow₀ hx hn) tendsto_id
end OrderedSemiring
theorem zero_pow_eventuallyEq [MonoidWithZero α] :
(fun n : ℕ => (0 : α) ^ n) =ᶠ[atTop] fun _ => 0 :=
eventually_atTop.2 ⟨1, fun _n hn ↦ zero_pow <| Nat.one_le_iff_ne_zero.1 hn⟩
section OrderedRing
variable [Ring α] [PartialOrder α] [IsOrderedRing α] {l : Filter β} {f g : β → α}
theorem Tendsto.atTop_mul_atBot₀ (hf : Tendsto f l atTop) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x * g x) l atBot := by
have := hf.atTop_mul_atTop₀ <| tendsto_neg_atBot_atTop.comp hg
simpa only [Function.comp_def, neg_mul_eq_mul_neg, neg_neg] using
tendsto_neg_atTop_atBot.comp this
@[deprecated (since := "2025-02-13")]
alias Tendsto.atTop_mul_atBot := Tendsto.atTop_mul_atBot₀
theorem Tendsto.atBot_mul_atTop₀ (hf : Tendsto f l atBot) (hg : Tendsto g l atTop) :
Tendsto (fun x => f x * g x) l atBot := by
have : Tendsto (fun x => -f x * g x) l atTop :=
(tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop₀ hg
simpa only [Function.comp_def, neg_mul_eq_neg_mul, neg_neg] using
tendsto_neg_atTop_atBot.comp this
@[deprecated (since := "2025-02-13")]
alias Tendsto.atBot_mul_atTop := Tendsto.atBot_mul_atTop₀
theorem Tendsto.atBot_mul_atBot₀ (hf : Tendsto f l atBot) (hg : Tendsto g l atBot) :
Tendsto (fun x => f x * g x) l atTop := by
have : Tendsto (fun x => -f x * -g x) l atTop :=
(tendsto_neg_atBot_atTop.comp hf).atTop_mul_atTop₀ (tendsto_neg_atBot_atTop.comp hg)
simpa only [neg_mul_neg] using this
end OrderedRing
section LinearOrderedSemiring
variable [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {l : Filter β} {f : β → α}
theorem Tendsto.atTop_of_const_mul₀ {c : α} (hc : 0 < c) (hf : Tendsto (fun x => c * f x) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (c * b)).mono
fun _x hx => le_of_mul_le_mul_left hx hc
theorem Tendsto.atTop_of_mul_const₀ {c : α} (hc : 0 < c) (hf : Tendsto (fun x => f x * c) l atTop) :
Tendsto f l atTop :=
tendsto_atTop.2 fun b => (tendsto_atTop.1 hf (b * c)).mono
fun _x hx => le_of_mul_le_mul_right hx hc
@[simp]
theorem tendsto_pow_atTop_iff {n : ℕ} : Tendsto (fun x : α => x ^ n) atTop atTop ↔ n ≠ 0 :=
⟨fun h hn => by simp only [hn, pow_zero, not_tendsto_const_atTop] at h, tendsto_pow_atTop⟩
end LinearOrderedSemiring
theorem not_tendsto_pow_atTop_atBot [Ring α] [LinearOrder α] [IsStrictOrderedRing α] :
∀ {n : ℕ}, ¬Tendsto (fun x : α => x ^ n) atTop atBot
| 0 => by simp [not_tendsto_const_atBot]
| n + 1 => (tendsto_pow_atTop n.succ_ne_zero).not_tendsto disjoint_atTop_atBot
end Filter
open Filter
variable {R : Type*} [Semiring R] [LinearOrder R] [IsStrictOrderedRing R]
theorem exists_lt_mul_self (a : R) : ∃ x ≥ 0, a < x * x :=
((eventually_ge_atTop 0).and (tendsto_mul_self_atTop.eventually (eventually_gt_atTop a))).exists
theorem exists_le_mul_self (a : R) : ∃ x ≥ 0, a ≤ x * x :=
let ⟨x, hx0, hxa⟩ := exists_lt_mul_self a
⟨x, hx0, hxa.le⟩
|
Equalizers.lean
|
/-
Copyright (c) 2024 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.Indization.FilteredColimits
import Mathlib.CategoryTheory.Limits.FullSubcategory
import Mathlib.CategoryTheory.Limits.Indization.ParallelPair
/-!
# Equalizers of ind-objects
We show that if a category `C` has equalizers, then ind-objects are closed under equalizers.
# References
* [M. Kashiwara, P. Schapira, *Categories and Sheaves*][Kashiwara2006], Section 6.1
-/
universe v v' u u'
namespace CategoryTheory.Limits
variable {C : Type u} [Category.{v} C]
section
variable {I : Type v} [SmallCategory I] [IsFiltered I]
variable {J : Type} [SmallCategory J] [FinCategory J]
variable (F : J ⥤ I ⥤ C)
/--
Suppose `F : J ⥤ I ⥤ C` is a finite diagram in the functor category `I ⥤ C`, where `I` is small
and filtered. If `i : I`, we can apply the Yoneda embedding to `F(·, i)` to obtain a
diagram of presheaves `J ⥤ Cᵒᵖ ⥤ Type v`. Suppose that the limits of this diagram is always an
ind-object.
For `j : J` we can apply the Yoneda embedding to `F(j, ·)` and take colimits to obtain a finite
diagram `J ⥤ Cᵒᵖ ⥤ Type v` (which is actually a diagram `J ⥤ Ind C`). The theorem states that
the limit of this diagram is an ind-object.
This theorem will be used to construct equalizers in the category of ind-objects. It can be
interpreted as saying that ind-objects are closed under finite limits as long as the diagram
we are taking the limit of comes from a diagram in a functor category `I ⥤ C`. We will show (TODO)
that this is the case for any parallel pair of morphisms in `Ind C` and deduce that ind-objects
are closed under equalizers.
This is Proposition 6.1.16(i) in [Kashiwara2006].
-/
theorem isIndObject_limit_comp_yoneda_comp_colim
(hF : ∀ i, IsIndObject (limit (F.flip.obj i ⋙ yoneda))) :
IsIndObject (limit (F ⋙ (Functor.whiskeringRight _ _ _).obj yoneda ⋙ colim)) := by
let G : J ⥤ I ⥤ (Cᵒᵖ ⥤ Type v) := F ⋙ (Functor.whiskeringRight _ _ _).obj yoneda
apply IsIndObject.map (HasLimit.isoOfNatIso (colimitFlipIsoCompColim G)).hom
apply IsIndObject.map (colimitLimitIso G).hom
apply isIndObject_colimit
exact fun i => IsIndObject.map (limitObjIsoLimitCompEvaluation _ _).inv (hF i)
end
/-- If `C` has equalizers. then ind-objects are closed under equalizers.
This is Proposition 6.1.17(i) in [Kashiwara2006].
-/
theorem closedUnderLimitsOfShape_walkingParallelPair_isIndObject [HasEqualizers C] :
ClosedUnderLimitsOfShape WalkingParallelPair (IsIndObject (C := C)) := by
apply closedUnderLimitsOfShape_of_limit
intro F hF h
obtain ⟨P⟩ := nonempty_indParallelPairPresentation (h WalkingParallelPair.zero)
(h WalkingParallelPair.one) (F.map WalkingParallelPairHom.left)
(F.map WalkingParallelPairHom.right)
exact IsIndObject.map
(HasLimit.isoOfNatIso (P.parallelPairIsoParallelPairCompYoneda.symm ≪≫
(diagramIsoParallelPair _).symm)).hom
(isIndObject_limit_comp_yoneda_comp_colim (parallelPair P.φ P.ψ)
(fun i => isIndObject_limit_comp_yoneda _))
end CategoryTheory.Limits
|
Congr.lean
|
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.FDeriv.Basic
/-!
# The Fréchet derivative: congruence properties
Lemmas about congruence properties of the Frechet derivative under change of function, set, etc.
## Tags
derivative, differentiable, Fréchet, calculus
-/
open Filter Asymptotics ContinuousLinearMap Set Metric Topology NNReal ENNReal
noncomputable section
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f f₀ f₁ g : E → F}
variable {f' f₀' f₁' g' : E →L[𝕜] F}
variable {x : E}
variable {s t : Set E}
variable {L L₁ L₂ : Filter E}
section congr
/-! ### congr properties of the derivative -/
theorem hasFDerivWithinAt_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x :=
calc
HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' (s \ {y}) x :=
(hasFDerivWithinAt_diff_singleton _).symm
_ ↔ HasFDerivWithinAt f f' (t \ {y}) x := by
suffices 𝓝[s \ {y}] x = 𝓝[t \ {y}] x by simp only [HasFDerivWithinAt, this]
simpa only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter', diff_eq,
inter_comm] using h
_ ↔ HasFDerivWithinAt f f' t x := hasFDerivWithinAt_diff_singleton _
theorem hasFDerivWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) :
HasFDerivWithinAt f f' s x ↔ HasFDerivWithinAt f f' t x :=
hasFDerivWithinAt_congr_set' x <| h.filter_mono inf_le_left
theorem differentiableWithinAt_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x :=
exists_congr fun _ => hasFDerivWithinAt_congr_set' _ h
theorem differentiableWithinAt_congr_set (h : s =ᶠ[𝓝 x] t) :
DifferentiableWithinAt 𝕜 f s x ↔ DifferentiableWithinAt 𝕜 f t x :=
exists_congr fun _ => hasFDerivWithinAt_congr_set h
theorem fderivWithin_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x := by
classical
simp only [fderivWithin, differentiableWithinAt_congr_set' _ h, hasFDerivWithinAt_congr_set' _ h]
theorem fderivWithin_congr_set (h : s =ᶠ[𝓝 x] t) : fderivWithin 𝕜 f s x = fderivWithin 𝕜 f t x :=
fderivWithin_congr_set' x <| h.filter_mono inf_le_left
theorem fderivWithin_eventually_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) :
fderivWithin 𝕜 f s =ᶠ[𝓝 x] fderivWithin 𝕜 f t :=
(eventually_nhds_nhdsWithin.2 h).mono fun _ => fderivWithin_congr_set' y
theorem fderivWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) :
fderivWithin 𝕜 f s =ᶠ[𝓝 x] fderivWithin 𝕜 f t :=
fderivWithin_eventually_congr_set' x <| h.filter_mono inf_le_left
theorem Filter.EventuallyEq.hasStrictFDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) :
HasStrictFDerivAt f₀ f₀' x ↔ HasStrictFDerivAt f₁ f₁' x := by
rw [hasStrictFDerivAt_iff_isLittleOTVS, hasStrictFDerivAt_iff_isLittleOTVS]
refine isLittleOTVS_congr ((h.prodMk_nhds h).mono ?_) .rfl
rintro p ⟨hp₁, hp₂⟩
simp only [*]
theorem HasStrictFDerivAt.congr_fderiv (h : HasStrictFDerivAt f f' x) (h' : f' = g') :
HasStrictFDerivAt f g' x :=
h' ▸ h
theorem HasFDerivAt.congr_fderiv (h : HasFDerivAt f f' x) (h' : f' = g') : HasFDerivAt f g' x :=
h' ▸ h
theorem HasFDerivWithinAt.congr_fderiv (h : HasFDerivWithinAt f f' s x) (h' : f' = g') :
HasFDerivWithinAt f g' s x :=
h' ▸ h
theorem HasStrictFDerivAt.congr_of_eventuallyEq (h : HasStrictFDerivAt f f' x)
(h₁ : f =ᶠ[𝓝 x] f₁) : HasStrictFDerivAt f₁ f' x :=
(h₁.hasStrictFDerivAt_iff fun _ => rfl).1 h
theorem Filter.EventuallyEq.hasFDerivAtFilter_iff (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x)
(h₁ : ∀ x, f₀' x = f₁' x) : HasFDerivAtFilter f₀ f₀' x L ↔ HasFDerivAtFilter f₁ f₁' x L := by
simp only [hasFDerivAtFilter_iff_isLittleOTVS]
exact isLittleOTVS_congr (h₀.mono fun y hy => by simp only [hy, h₁, hx]) .rfl
theorem HasFDerivAtFilter.congr_of_eventuallyEq (h : HasFDerivAtFilter f f' x L) (hL : f₁ =ᶠ[L] f)
(hx : f₁ x = f x) : HasFDerivAtFilter f₁ f' x L :=
(hL.hasFDerivAtFilter_iff hx fun _ => rfl).2 h
theorem Filter.EventuallyEq.hasFDerivAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) :
HasFDerivAt f₀ f' x ↔ HasFDerivAt f₁ f' x :=
h.hasFDerivAtFilter_iff h.eq_of_nhds fun _ => _root_.rfl
theorem Filter.EventuallyEq.differentiableAt_iff (h : f₀ =ᶠ[𝓝 x] f₁) :
DifferentiableAt 𝕜 f₀ x ↔ DifferentiableAt 𝕜 f₁ x :=
exists_congr fun _ => h.hasFDerivAt_iff
theorem Filter.EventuallyEq.hasFDerivWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) :
HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x :=
h.hasFDerivAtFilter_iff hx fun _ => _root_.rfl
theorem Filter.EventuallyEq.hasFDerivWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) :
HasFDerivWithinAt f₀ f' s x ↔ HasFDerivWithinAt f₁ f' s x :=
h.hasFDerivWithinAt_iff (h.eq_of_nhdsWithin hx)
theorem Filter.EventuallyEq.differentiableWithinAt_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) :
DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x :=
exists_congr fun _ => h.hasFDerivWithinAt_iff hx
theorem Filter.EventuallyEq.differentiableWithinAt_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) :
DifferentiableWithinAt 𝕜 f₀ s x ↔ DifferentiableWithinAt 𝕜 f₁ s x :=
h.differentiableWithinAt_iff (h.eq_of_nhdsWithin hx)
theorem HasFDerivWithinAt.congr_mono (h : HasFDerivWithinAt f f' s x) (ht : EqOn f₁ f t)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : HasFDerivWithinAt f₁ f' t x :=
HasFDerivAtFilter.congr_of_eventuallyEq (h.mono h₁) (Filter.mem_inf_of_right ht) hx
theorem HasFDerivWithinAt.congr (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s)
(hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x :=
h.congr_mono hs hx (Subset.refl _)
theorem HasFDerivWithinAt.congr' (h : HasFDerivWithinAt f f' s x) (hs : EqOn f₁ f s) (hx : x ∈ s) :
HasFDerivWithinAt f₁ f' s x :=
h.congr hs (hs hx)
theorem HasFDerivWithinAt.congr_of_eventuallyEq (h : HasFDerivWithinAt f f' s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : HasFDerivWithinAt f₁ f' s x :=
HasFDerivAtFilter.congr_of_eventuallyEq h h₁ hx
theorem HasFDerivAt.congr_of_eventuallyEq (h : HasFDerivAt f f' x) (h₁ : f₁ =ᶠ[𝓝 x] f) :
HasFDerivAt f₁ f' x :=
HasFDerivAtFilter.congr_of_eventuallyEq h h₁ (mem_of_mem_nhds h₁ :)
theorem DifferentiableWithinAt.congr_mono (h : DifferentiableWithinAt 𝕜 f s x) (ht : EqOn f₁ f t)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : DifferentiableWithinAt 𝕜 f₁ t x :=
(HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt ht hx h₁).differentiableWithinAt
theorem DifferentiableWithinAt.congr (h : DifferentiableWithinAt 𝕜 f s x) (ht : ∀ x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x :=
DifferentiableWithinAt.congr_mono h ht hx (Subset.refl _)
theorem DifferentiableWithinAt.congr_of_eventuallyEq (h : DifferentiableWithinAt 𝕜 f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : DifferentiableWithinAt 𝕜 f₁ s x :=
(h.hasFDerivWithinAt.congr_of_eventuallyEq h₁ hx).differentiableWithinAt
theorem DifferentiableWithinAt.congr_of_eventuallyEq_of_mem (h : DifferentiableWithinAt 𝕜 f s x)
(h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : DifferentiableWithinAt 𝕜 f₁ s x :=
h.congr_of_eventuallyEq h₁ (mem_of_mem_nhdsWithin hx h₁ :)
theorem DifferentiableWithinAt.congr_of_eventuallyEq_insert (h : DifferentiableWithinAt 𝕜 f s x)
(h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : DifferentiableWithinAt 𝕜 f₁ s x :=
(h.insert.congr_of_eventuallyEq_of_mem h₁ (mem_insert _ _)).of_insert
theorem DifferentiableOn.congr_mono (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ t, f₁ x = f x)
(h₁ : t ⊆ s) : DifferentiableOn 𝕜 f₁ t := fun x hx => (h x (h₁ hx)).congr_mono h' (h' x hx) h₁
theorem DifferentiableOn.congr (h : DifferentiableOn 𝕜 f s) (h' : ∀ x ∈ s, f₁ x = f x) :
DifferentiableOn 𝕜 f₁ s := fun x hx => (h x hx).congr h' (h' x hx)
theorem differentiableOn_congr (h' : ∀ x ∈ s, f₁ x = f x) :
DifferentiableOn 𝕜 f₁ s ↔ DifferentiableOn 𝕜 f s :=
⟨fun h => DifferentiableOn.congr h fun y hy => (h' y hy).symm, fun h =>
DifferentiableOn.congr h h'⟩
theorem DifferentiableAt.congr_of_eventuallyEq (h : DifferentiableAt 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) :
DifferentiableAt 𝕜 f₁ x :=
hL.differentiableAt_iff.2 h
theorem DifferentiableWithinAt.fderivWithin_congr_mono (h : DifferentiableWithinAt 𝕜 f s x)
(hs : EqOn f₁ f t) (hx : f₁ x = f x) (hxt : UniqueDiffWithinAt 𝕜 t x) (h₁ : t ⊆ s) :
fderivWithin 𝕜 f₁ t x = fderivWithin 𝕜 f s x :=
(HasFDerivWithinAt.congr_mono h.hasFDerivWithinAt hs hx h₁).fderivWithin hxt
theorem Filter.EventuallyEq.fderivWithin_eq (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by
classical
simp only [fderivWithin, DifferentiableWithinAt, hs.hasFDerivWithinAt_iff hx]
theorem Filter.EventuallyEq.fderivWithin_eq_of_mem (hs : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
hs.fderivWithin_eq (mem_of_mem_nhdsWithin hx hs :)
theorem Filter.EventuallyEq.fderivWithin_eq_of_insert (hs : f₁ =ᶠ[𝓝[insert x s] x] f) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x := by
apply Filter.EventuallyEq.fderivWithin_eq (nhdsWithin_mono _ (subset_insert x s) hs)
exact (mem_of_mem_nhdsWithin (mem_insert x s) hs :)
theorem Filter.EventuallyEq.fderivWithin' (hs : f₁ =ᶠ[𝓝[s] x] f) (ht : t ⊆ s) :
fderivWithin 𝕜 f₁ t =ᶠ[𝓝[s] x] fderivWithin 𝕜 f t :=
(eventually_eventually_nhdsWithin.2 hs).mp <|
eventually_mem_nhdsWithin.mono fun _y hys hs =>
EventuallyEq.fderivWithin_eq (hs.filter_mono <| nhdsWithin_mono _ ht)
(hs.self_of_nhdsWithin hys)
protected theorem Filter.EventuallyEq.fderivWithin (hs : f₁ =ᶠ[𝓝[s] x] f) :
fderivWithin 𝕜 f₁ s =ᶠ[𝓝[s] x] fderivWithin 𝕜 f s :=
hs.fderivWithin' Subset.rfl
theorem Filter.EventuallyEq.fderivWithin_eq_of_nhds (h : f₁ =ᶠ[𝓝 x] f) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
(h.filter_mono nhdsWithin_le_nhds).fderivWithin_eq h.self_of_nhds
@[deprecated (since := "2025-05-20")]
alias Filter.EventuallyEq.fderivWithin_eq_nhds := Filter.EventuallyEq.fderivWithin_eq_of_nhds
theorem fderivWithin_congr (hs : EqOn f₁ f s) (hx : f₁ x = f x) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
(hs.eventuallyEq.filter_mono inf_le_right).fderivWithin_eq hx
theorem fderivWithin_congr' (hs : EqOn f₁ f s) (hx : x ∈ s) :
fderivWithin 𝕜 f₁ s x = fderivWithin 𝕜 f s x :=
fderivWithin_congr hs (hs hx)
theorem Filter.EventuallyEq.fderiv_eq (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ x = fderiv 𝕜 f x := by
rw [← fderivWithin_univ, ← fderivWithin_univ, h.fderivWithin_eq_of_nhds]
protected theorem Filter.EventuallyEq.fderiv (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f :=
h.eventuallyEq_nhds.mono fun _ h => h.fderiv_eq
end congr
end
|
Basic.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov
-/
import Mathlib.Order.Filter.Ultrafilter.Defs
import Mathlib.Order.Filter.Cofinite
import Mathlib.Order.ZornAtoms
/-!
# Ultrafilters
An ultrafilter is a minimal (maximal in the set order) proper filter.
In this file we define
* `hyperfilter`: the ultrafilter extending the cofinite filter.
-/
universe u v
variable {α : Type u} {β : Type v}
open Set Filter
namespace Ultrafilter
variable {f : Ultrafilter α} {s : Set α}
theorem finite_sUnion_mem_iff {s : Set (Set α)} (hs : s.Finite) : ⋃₀ s ∈ f ↔ ∃ t ∈ s, t ∈ f := by
induction s, hs using Set.Finite.induction_on with
| empty => simp
| insert _ _ his => simp [union_mem_iff, his, or_and_right, exists_or]
theorem finite_biUnion_mem_iff {is : Set β} {s : β → Set α} (his : is.Finite) :
(⋃ i ∈ is, s i) ∈ f ↔ ∃ i ∈ is, s i ∈ f := by
simp only [← sUnion_image, finite_sUnion_mem_iff (his.image s), exists_mem_image]
lemma eventually_exists_mem_iff {is : Set β} {P : β → α → Prop} (his : is.Finite) :
(∀ᶠ i in f, ∃ a ∈ is, P a i) ↔ ∃ a ∈ is, ∀ᶠ i in f, P a i := by
simp only [Filter.Eventually, Ultrafilter.mem_coe]
convert f.finite_biUnion_mem_iff his (s := P) with i
aesop
lemma eventually_exists_iff [Finite β] {P : β → α → Prop} :
(∀ᶠ i in f, ∃ a, P a i) ↔ ∃ a, ∀ᶠ i in f, P a i := by
simpa using eventually_exists_mem_iff (f := f) (P := P) Set.finite_univ
theorem eq_pure_of_finite_mem (h : s.Finite) (h' : s ∈ f) : ∃ x ∈ s, f = pure x := by
rw [← biUnion_of_singleton s] at h'
rcases (Ultrafilter.finite_biUnion_mem_iff h).mp h' with ⟨a, has, haf⟩
exact ⟨a, has, eq_of_le (Filter.le_pure_iff.2 haf)⟩
theorem eq_pure_of_finite [Finite α] (f : Ultrafilter α) : ∃ a, f = pure a :=
(eq_pure_of_finite_mem finite_univ univ_mem).imp fun _ ⟨_, ha⟩ => ha
theorem le_cofinite_or_eq_pure (f : Ultrafilter α) : (f : Filter α) ≤ cofinite ∨ ∃ a, f = pure a :=
or_iff_not_imp_left.2 fun h =>
let ⟨_, hs, hfin⟩ := Filter.disjoint_cofinite_right.1 (disjoint_iff_not_le.2 h)
let ⟨a, _, hf⟩ := eq_pure_of_finite_mem hfin hs
⟨a, hf⟩
theorem exists_ultrafilter_of_finite_inter_nonempty (S : Set (Set α))
(cond : ∀ T : Finset (Set α), (↑T : Set (Set α)) ⊆ S → (⋂₀ (↑T : Set (Set α))).Nonempty) :
∃ F : Ultrafilter α, S ⊆ F.sets :=
haveI : NeBot (generate S) :=
generate_neBot_iff.2 fun _ hts ht =>
ht.coe_toFinset ▸ cond ht.toFinset (ht.coe_toFinset.symm ▸ hts)
⟨of (generate S), fun _ ht => (of_le <| generate S) <| GenerateSets.basic ht⟩
end Ultrafilter
namespace Filter
open Ultrafilter
lemma atTop_eq_pure_of_isTop [PartialOrder α] {x : α} (hx : IsTop x) :
(atTop : Filter α) = pure x :=
{top := x, le_top := hx : OrderTop α}.atTop_eq
lemma atBot_eq_pure_of_isBot [PartialOrder α] {x : α} (hx : IsBot x) :
(atBot : Filter α) = pure x :=
@atTop_eq_pure_of_isTop αᵒᵈ _ _ hx
/-- The `tendsto` relation can be checked on ultrafilters. -/
theorem tendsto_iff_ultrafilter (f : α → β) (l₁ : Filter α) (l₂ : Filter β) :
Tendsto f l₁ l₂ ↔ ∀ g : Ultrafilter α, ↑g ≤ l₁ → Tendsto f g l₂ := by
simpa only [tendsto_iff_comap] using le_iff_ultrafilter
section Hyperfilter
variable (α) [Infinite α]
/-- The ultrafilter extending the cofinite filter. -/
noncomputable def hyperfilter : Ultrafilter α :=
Ultrafilter.of cofinite
variable {α}
theorem hyperfilter_le_cofinite : ↑(hyperfilter α) ≤ @cofinite α :=
Ultrafilter.of_le cofinite
theorem _root_.Nat.hyperfilter_le_atTop : (hyperfilter ℕ).toFilter ≤ atTop :=
hyperfilter_le_cofinite.trans_eq Nat.cofinite_eq_atTop
@[simp]
theorem bot_ne_hyperfilter : (⊥ : Filter α) ≠ hyperfilter α :=
(NeBot.ne inferInstance).symm
theorem notMem_hyperfilter_of_finite {s : Set α} (hf : s.Finite) : s ∉ hyperfilter α := fun hy =>
compl_notMem hy <| hyperfilter_le_cofinite hf.compl_mem_cofinite
@[deprecated (since := "2025-05-24")]
alias nmem_hyperfilter_of_finite := notMem_hyperfilter_of_finite
alias _root_.Set.Finite.notMem_hyperfilter := notMem_hyperfilter_of_finite
@[deprecated (since := "2025-05-24")]
alias _root_.Set.Finite.nmem_hyperfilter := _root_.Set.Finite.notMem_hyperfilter
theorem compl_mem_hyperfilter_of_finite {s : Set α} (hf : Set.Finite s) : sᶜ ∈ hyperfilter α :=
compl_mem_iff_notMem.2 hf.notMem_hyperfilter
alias _root_.Set.Finite.compl_mem_hyperfilter := compl_mem_hyperfilter_of_finite
theorem mem_hyperfilter_of_finite_compl {s : Set α} (hf : Set.Finite sᶜ) : s ∈ hyperfilter α :=
compl_compl s ▸ hf.compl_mem_hyperfilter
end Hyperfilter
end Filter
|
Presheaf.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Generator.Basic
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic
/-!
# Generators in the category of presheaves
In this file, we show that if `A` is a category with zero morphisms that
has a separator (and suitable coproducts), then the category of
presheaves `Cᵒᵖ ⥤ A` also has a separator.
-/
universe w v' v u' u
namespace CategoryTheory
open Limits Opposite
namespace Presheaf
variable {C : Type u} [Category.{v} C] {A : Type u'} [Category.{v'} A]
[HasCoproducts.{v} A]
/-- Given `X : C` and `M : A`, this is the presheaf `Cᵒᵖ ⥤ A` which sends
`Y : Cᵒᵖ` to the coproduct of copies of `M` indexed by `Y.unop ⟶ X`. -/
@[simps]
noncomputable def freeYoneda (X : C) (M : A) : Cᵒᵖ ⥤ A where
obj Y := ∐ (fun (i : (yoneda.obj X).obj Y) ↦ M)
map f := Sigma.map' ((yoneda.obj X).map f) (fun _ ↦ 𝟙 M)
/-- The bijection `(Presheaf.freeYoneda X M ⟶ F) ≃ (M ⟶ F.obj (op X))`. -/
noncomputable def freeYonedaHomEquiv {X : C} {M : A} {F : Cᵒᵖ ⥤ A} :
(freeYoneda X M ⟶ F) ≃ (M ⟶ F.obj (op X)) where
toFun f := Sigma.ι (fun (i : (yoneda.obj X).obj _) ↦ M) (𝟙 _) ≫ f.app (op X)
invFun g :=
{ app Y := Sigma.desc (fun φ ↦ g ≫ F.map φ.op)
naturality _ _ _ := Sigma.hom_ext _ _ (by simp)}
left_inv f := by
ext Y
refine Sigma.hom_ext _ _ (fun φ ↦ ?_)
simpa using (Sigma.ι _ (𝟙 _) ≫= f.naturality φ.op).symm
right_inv g := by simp
@[reassoc]
lemma freeYonedaHomEquiv_comp {X : C} {M : A} {F G : Cᵒᵖ ⥤ A}
(α : freeYoneda X M ⟶ F) (f : F ⟶ G) :
freeYonedaHomEquiv (α ≫ f) = freeYonedaHomEquiv α ≫ f.app (op X) := by
simp [freeYonedaHomEquiv]
@[reassoc]
lemma freeYonedaHomEquiv_symm_comp {X : C} {M : A} {F G : Cᵒᵖ ⥤ A} (α : M ⟶ F.obj (op X))
(f : F ⟶ G) :
freeYonedaHomEquiv.symm α ≫ f = freeYonedaHomEquiv.symm (α ≫ f.app (op X)) := by
obtain ⟨β, rfl⟩ := freeYonedaHomEquiv.surjective α
apply freeYonedaHomEquiv.injective
simp only [Equiv.symm_apply_apply, freeYonedaHomEquiv_comp, Equiv.apply_symm_apply]
variable (C)
lemma isSeparating {ι : Type w} {S : ι → A} (hS : IsSeparating (Set.range S)) :
IsSeparating (Set.range (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda X (S i))) := by
intro F G f g h
ext ⟨X⟩
refine hS _ _ ?_
rintro _ ⟨i, rfl⟩ α
apply freeYonedaHomEquiv.symm.injective
simpa only [freeYonedaHomEquiv_symm_comp] using
h _ ⟨⟨X, i⟩, rfl⟩ (freeYonedaHomEquiv.symm α)
lemma isSeparator {ι : Type w} {S : ι → A} (hS : IsSeparating (Set.range S))
[HasCoproduct (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda X (S i))]
[HasZeroMorphisms A] :
IsSeparator (∐ (fun (⟨X, i⟩ : C × ι) ↦ freeYoneda X (S i))) :=
(isSeparating C hS).isSeparator_coproduct
variable (A) in
instance hasSeparator [HasSeparator A] [HasZeroMorphisms A] [HasCoproducts.{u} A] :
HasSeparator (Cᵒᵖ ⥤ A) where
hasSeparator := ⟨_, isSeparator C (S := fun (_ : Unit) ↦ separator A)
(by simpa using isSeparator_separator A)⟩
end Presheaf
end CategoryTheory
|
AddTorsor.lean
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Yury Kudryashov
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic
import Mathlib.Topology.Instances.RealVectorSpace
/-!
# Torsors of normed space actions.
This file contains lemmas about normed additive torsors over normed spaces.
-/
noncomputable section
open NNReal Topology
open Filter
variable {V P W Q : Type*} [SeminormedAddCommGroup V] [PseudoMetricSpace P] [NormedAddTorsor V P]
[NormedAddCommGroup W] [MetricSpace Q] [NormedAddTorsor W Q]
section NormedSpace
variable {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 V] [NormedSpace 𝕜 W]
open AffineMap
theorem AffineSubspace.isClosed_direction_iff (s : AffineSubspace 𝕜 Q) :
IsClosed (s.direction : Set W) ↔ IsClosed (s : Set Q) := by
rcases s.eq_bot_or_nonempty with (rfl | ⟨x, hx⟩); · simp
rw [← (IsometryEquiv.vaddConst x).toHomeomorph.symm.isClosed_image,
AffineSubspace.coe_direction_eq_vsub_set_right hx]
rfl
@[simp]
theorem dist_center_homothety (p₁ p₂ : P) (c : 𝕜) :
dist p₁ (homothety p₁ c p₂) = ‖c‖ * dist p₁ p₂ := by
simp [homothety_def, norm_smul, ← dist_eq_norm_vsub, dist_comm]
@[simp]
theorem nndist_center_homothety (p₁ p₂ : P) (c : 𝕜) :
nndist p₁ (homothety p₁ c p₂) = ‖c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_center_homothety _ _ _
@[simp]
theorem dist_homothety_center (p₁ p₂ : P) (c : 𝕜) :
dist (homothety p₁ c p₂) p₁ = ‖c‖ * dist p₁ p₂ := by rw [dist_comm, dist_center_homothety]
@[simp]
theorem nndist_homothety_center (p₁ p₂ : P) (c : 𝕜) :
nndist (homothety p₁ c p₂) p₁ = ‖c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_homothety_center _ _ _
@[simp]
theorem dist_lineMap_lineMap (p₁ p₂ : P) (c₁ c₂ : 𝕜) :
dist (lineMap p₁ p₂ c₁) (lineMap p₁ p₂ c₂) = dist c₁ c₂ * dist p₁ p₂ := by
rw [dist_comm p₁ p₂]
simp only [lineMap_apply, dist_eq_norm_vsub, vadd_vsub_vadd_cancel_right,
← sub_smul, norm_smul, vsub_eq_sub]
@[simp]
theorem nndist_lineMap_lineMap (p₁ p₂ : P) (c₁ c₂ : 𝕜) :
nndist (lineMap p₁ p₂ c₁) (lineMap p₁ p₂ c₂) = nndist c₁ c₂ * nndist p₁ p₂ :=
NNReal.eq <| dist_lineMap_lineMap _ _ _ _
theorem lipschitzWith_lineMap (p₁ p₂ : P) : LipschitzWith (nndist p₁ p₂) (lineMap p₁ p₂ : 𝕜 → P) :=
LipschitzWith.of_dist_le_mul fun c₁ c₂ =>
((dist_lineMap_lineMap p₁ p₂ c₁ c₂).trans (mul_comm _ _)).le
@[simp]
theorem dist_lineMap_left (p₁ p₂ : P) (c : 𝕜) : dist (lineMap p₁ p₂ c) p₁ = ‖c‖ * dist p₁ p₂ := by
simpa only [lineMap_apply_zero, dist_zero_right] using dist_lineMap_lineMap p₁ p₂ c 0
@[simp]
theorem nndist_lineMap_left (p₁ p₂ : P) (c : 𝕜) :
nndist (lineMap p₁ p₂ c) p₁ = ‖c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_lineMap_left _ _ _
@[simp]
theorem dist_left_lineMap (p₁ p₂ : P) (c : 𝕜) : dist p₁ (lineMap p₁ p₂ c) = ‖c‖ * dist p₁ p₂ :=
(dist_comm _ _).trans (dist_lineMap_left _ _ _)
@[simp]
theorem nndist_left_lineMap (p₁ p₂ : P) (c : 𝕜) :
nndist p₁ (lineMap p₁ p₂ c) = ‖c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_left_lineMap _ _ _
@[simp]
theorem dist_lineMap_right (p₁ p₂ : P) (c : 𝕜) :
dist (lineMap p₁ p₂ c) p₂ = ‖1 - c‖ * dist p₁ p₂ := by
simpa only [lineMap_apply_one, dist_eq_norm'] using dist_lineMap_lineMap p₁ p₂ c 1
@[simp]
theorem nndist_lineMap_right (p₁ p₂ : P) (c : 𝕜) :
nndist (lineMap p₁ p₂ c) p₂ = ‖1 - c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_lineMap_right _ _ _
@[simp]
theorem dist_right_lineMap (p₁ p₂ : P) (c : 𝕜) : dist p₂ (lineMap p₁ p₂ c) = ‖1 - c‖ * dist p₁ p₂ :=
(dist_comm _ _).trans (dist_lineMap_right _ _ _)
@[simp]
theorem nndist_right_lineMap (p₁ p₂ : P) (c : 𝕜) :
nndist p₂ (lineMap p₁ p₂ c) = ‖1 - c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_right_lineMap _ _ _
@[simp]
theorem dist_homothety_self (p₁ p₂ : P) (c : 𝕜) :
dist (homothety p₁ c p₂) p₂ = ‖1 - c‖ * dist p₁ p₂ := by
rw [homothety_eq_lineMap, dist_lineMap_right]
@[simp]
theorem nndist_homothety_self (p₁ p₂ : P) (c : 𝕜) :
nndist (homothety p₁ c p₂) p₂ = ‖1 - c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_homothety_self _ _ _
@[simp]
theorem dist_self_homothety (p₁ p₂ : P) (c : 𝕜) :
dist p₂ (homothety p₁ c p₂) = ‖1 - c‖ * dist p₁ p₂ := by rw [dist_comm, dist_homothety_self]
@[simp]
theorem nndist_self_homothety (p₁ p₂ : P) (c : 𝕜) :
nndist p₂ (homothety p₁ c p₂) = ‖1 - c‖₊ * nndist p₁ p₂ :=
NNReal.eq <| dist_self_homothety _ _ _
section invertibleTwo
variable [Invertible (2 : 𝕜)]
@[simp]
theorem dist_left_midpoint (p₁ p₂ : P) : dist p₁ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by
rw [midpoint, dist_comm, dist_lineMap_left, invOf_eq_inv, ← norm_inv]
@[simp]
theorem nndist_left_midpoint (p₁ p₂ : P) :
nndist p₁ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ :=
NNReal.eq <| dist_left_midpoint _ _
@[simp]
theorem dist_midpoint_left (p₁ p₂ : P) : dist (midpoint 𝕜 p₁ p₂) p₁ = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by
rw [dist_comm, dist_left_midpoint]
@[simp]
theorem nndist_midpoint_left (p₁ p₂ : P) :
nndist (midpoint 𝕜 p₁ p₂) p₁ = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ :=
NNReal.eq <| dist_midpoint_left _ _
@[simp]
theorem dist_midpoint_right (p₁ p₂ : P) :
dist (midpoint 𝕜 p₁ p₂) p₂ = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by
rw [midpoint_comm, dist_midpoint_left, dist_comm]
@[simp]
theorem nndist_midpoint_right (p₁ p₂ : P) :
nndist (midpoint 𝕜 p₁ p₂) p₂ = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ :=
NNReal.eq <| dist_midpoint_right _ _
@[simp]
theorem dist_right_midpoint (p₁ p₂ : P) :
dist p₂ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖⁻¹ * dist p₁ p₂ := by
rw [dist_comm, dist_midpoint_right]
@[simp]
theorem nndist_right_midpoint (p₁ p₂ : P) :
nndist p₂ (midpoint 𝕜 p₁ p₂) = ‖(2 : 𝕜)‖₊⁻¹ * nndist p₁ p₂ :=
NNReal.eq <| dist_right_midpoint _ _
/-- The midpoint of the segment AB is the same distance from A as it is from B. -/
theorem dist_left_midpoint_eq_dist_right_midpoint (p₁ p₂ : P) :
dist p₁ (midpoint 𝕜 p₁ p₂) = dist p₂ (midpoint 𝕜 p₁ p₂) := by
rw [dist_left_midpoint p₁ p₂, dist_right_midpoint p₁ p₂]
theorem dist_midpoint_midpoint_le' (p₁ p₂ p₃ p₄ : P) :
dist (midpoint 𝕜 p₁ p₂) (midpoint 𝕜 p₃ p₄) ≤ (dist p₁ p₃ + dist p₂ p₄) / ‖(2 : 𝕜)‖ := by
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, midpoint_vsub_midpoint]
rw [midpoint_eq_smul_add, norm_smul, invOf_eq_inv, norm_inv, ← div_eq_inv_mul]
exact div_le_div_of_nonneg_right (norm_add_le _ _) (norm_nonneg _)
theorem nndist_midpoint_midpoint_le' (p₁ p₂ p₃ p₄ : P) :
nndist (midpoint 𝕜 p₁ p₂) (midpoint 𝕜 p₃ p₄) ≤ (nndist p₁ p₃ + nndist p₂ p₄) / ‖(2 : 𝕜)‖₊ :=
dist_midpoint_midpoint_le' _ _ _ _
end invertibleTwo
@[simp] theorem dist_pointReflection_left (p q : P) :
dist (Equiv.pointReflection p q) p = dist p q := by
simp [dist_eq_norm_vsub V, Equiv.pointReflection_vsub_left (G := V)]
@[simp] theorem dist_left_pointReflection (p q : P) :
dist p (Equiv.pointReflection p q) = dist p q :=
(dist_comm _ _).trans (dist_pointReflection_left _ _)
variable (𝕜) in
theorem dist_pointReflection_right (p q : P) :
dist (Equiv.pointReflection p q) q = ‖(2 : 𝕜)‖ * dist p q := by
simp [dist_eq_norm_vsub V, Equiv.pointReflection_vsub_right (G := V), ← Nat.cast_smul_eq_nsmul 𝕜,
norm_smul]
variable (𝕜) in
theorem dist_right_pointReflection (p q : P) :
dist q (Equiv.pointReflection p q) = ‖(2 : 𝕜)‖ * dist p q :=
(dist_comm _ _).trans (dist_pointReflection_right 𝕜 _ _)
theorem antilipschitzWith_lineMap {p₁ p₂ : Q} (h : p₁ ≠ p₂) :
AntilipschitzWith (nndist p₁ p₂)⁻¹ (lineMap p₁ p₂ : 𝕜 → Q) :=
AntilipschitzWith.of_le_mul_dist fun c₁ c₂ => by
rw [dist_lineMap_lineMap, NNReal.coe_inv, ← dist_nndist, mul_left_comm,
inv_mul_cancel₀ (dist_ne_zero.2 h), mul_one]
variable (𝕜)
theorem eventually_homothety_mem_of_mem_interior (x : Q) {s : Set Q} {y : Q} (hy : y ∈ interior s) :
∀ᶠ δ in 𝓝 (1 : 𝕜), homothety x δ y ∈ s := by
rw [(NormedAddCommGroup.nhds_basis_norm_lt (1 : 𝕜)).eventually_iff]
rcases eq_or_ne y x with h | h
· use 1
simp [h.symm, interior_subset hy]
have hxy : 0 < ‖y -ᵥ x‖ := by rwa [norm_pos_iff, vsub_ne_zero]
obtain ⟨u, hu₁, hu₂, hu₃⟩ := mem_interior.mp hy
obtain ⟨ε, hε, hyε⟩ := Metric.isOpen_iff.mp hu₂ y hu₃
refine ⟨ε / ‖y -ᵥ x‖, div_pos hε hxy, fun δ (hδ : ‖δ - 1‖ < ε / ‖y -ᵥ x‖) => hu₁ (hyε ?_)⟩
rw [lt_div_iff₀ hxy, ← norm_smul, sub_smul, one_smul] at hδ
rwa [homothety_apply, Metric.mem_ball, dist_eq_norm_vsub W, vadd_vsub_eq_sub_vsub]
theorem eventually_homothety_image_subset_of_finite_subset_interior (x : Q) {s : Set Q} {t : Set Q}
(ht : t.Finite) (h : t ⊆ interior s) : ∀ᶠ δ in 𝓝 (1 : 𝕜), homothety x δ '' t ⊆ s := by
suffices ∀ y ∈ t, ∀ᶠ δ in 𝓝 (1 : 𝕜), homothety x δ y ∈ s by
simp_rw [Set.image_subset_iff]
exact (Filter.eventually_all_finite ht).mpr this
intro y hy
exact eventually_homothety_mem_of_mem_interior 𝕜 x (h hy)
end NormedSpace
variable [NormedSpace ℝ V] [NormedSpace ℝ W]
theorem dist_midpoint_midpoint_le (p₁ p₂ p₃ p₄ : V) :
dist (midpoint ℝ p₁ p₂) (midpoint ℝ p₃ p₄) ≤ (dist p₁ p₃ + dist p₂ p₄) / 2 := by
simpa using dist_midpoint_midpoint_le' (𝕜 := ℝ) p₁ p₂ p₃ p₄
theorem nndist_midpoint_midpoint_le (p₁ p₂ p₃ p₄ : V) :
nndist (midpoint ℝ p₁ p₂) (midpoint ℝ p₃ p₄) ≤ (nndist p₁ p₃ + nndist p₂ p₄) / 2 :=
dist_midpoint_midpoint_le _ _ _ _
/-- A continuous map between two normed affine spaces is an affine map provided that
it sends midpoints to midpoints. -/
def AffineMap.ofMapMidpoint (f : P → Q) (h : ∀ x y, f (midpoint ℝ x y) = midpoint ℝ (f x) (f y))
(hfc : Continuous f) : P →ᵃ[ℝ] Q :=
let c := Classical.arbitrary P
AffineMap.mk' f (↑((AddMonoidHom.ofMapMidpoint ℝ ℝ
((AffineEquiv.vaddConst ℝ (f <| c)).symm ∘ f ∘ AffineEquiv.vaddConst ℝ c) (by simp)
fun x y => by simp [h]).toRealLinearMap <| by
apply_rules [Continuous.vadd, Continuous.vsub, continuous_const, hfc.comp, continuous_id]))
c fun p => by simp
end
section
open Dilation
variable {𝕜 E : Type*} [NormedDivisionRing 𝕜] [SeminormedAddCommGroup E]
variable [Module 𝕜 E] [NormSMulClass 𝕜 E] {P : Type*} [PseudoMetricSpace P] [NormedAddTorsor E P]
-- TODO: define `ContinuousAffineEquiv` and reimplement this as one of those.
/-- Scaling by an element `k` of the scalar ring as a `DilationEquiv` with ratio `‖k‖₊`, mapping
from a normed space to a normed torsor over that space sending `0` to `c`. -/
@[simps]
def DilationEquiv.smulTorsor (c : P) {k : 𝕜} (hk : k ≠ 0) : E ≃ᵈ P where
toFun := (k • · +ᵥ c)
invFun := k⁻¹ • (· -ᵥ c)
left_inv x := by simp [inv_smul_smul₀ hk]
right_inv p := by simp [smul_inv_smul₀ hk]
edist_eq' := ⟨‖k‖₊, nnnorm_ne_zero_iff.mpr hk, fun x y ↦ by
rw [show edist (k • x +ᵥ c) (k • y +ᵥ c) = _ from (IsometryEquiv.vaddConst c).isometry ..]
exact edist_smul₀ ..⟩
-- Cannot be @[simp] because `x` and `y` can not be inferred by `simp`.
lemma DilationEquiv.smulTorsor_ratio {c : P} {k : 𝕜} (hk : k ≠ 0) {x y : E}
(h : dist x y ≠ 0) : ratio (smulTorsor c hk) = ‖k‖₊ :=
Eq.symm <| ratio_unique_of_dist_ne_zero h <| by simp [dist_eq_norm, ← smul_sub, norm_smul]
@[simp]
lemma DilationEquiv.smulTorsor_preimage_ball {c : P} {k : 𝕜} (hk : k ≠ 0) :
smulTorsor c hk ⁻¹' (Metric.ball c ‖k‖) = Metric.ball (0 : E) 1 := by
aesop (add simp norm_smul)
end
|
FreeAlgebra.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.FreeAlgebra
import Mathlib.LinearAlgebra.Basis.Cardinality
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.Dimension.Subsingleton
import Mathlib.LinearAlgebra.Finsupp.VectorSpace
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.FreeModule.StrongRankCondition
/-!
# Linear algebra properties of `FreeAlgebra R X`
This file provides a `FreeMonoid X` basis on the `FreeAlgebra R X`, and uses it to show the
dimension of the algebra is the cardinality of `List X`
-/
open Module
universe u v
namespace FreeAlgebra
variable (R : Type u) (X : Type v)
section
variable [CommSemiring R]
/-- The `FreeMonoid X` basis on the `FreeAlgebra R X`,
mapping `[x₁, x₂, ..., xₙ]` to the "monomial" `1 • x₁ * x₂ * ⋯ * xₙ` -/
-- @[simps]
noncomputable def basisFreeMonoid : Basis (FreeMonoid X) R (FreeAlgebra R X) :=
Finsupp.basisSingleOne.map (equivMonoidAlgebraFreeMonoid (R := R) (X := X)).symm.toLinearEquiv
instance : Module.Free R (FreeAlgebra R X) :=
have : Module.Free R (MonoidAlgebra R (FreeMonoid X)) := Module.Free.finsupp _ _ _
Module.Free.of_equiv (equivMonoidAlgebraFreeMonoid (R := R) (X := X)).symm.toLinearEquiv
end
theorem rank_eq [CommRing R] [Nontrivial R] :
Module.rank R (FreeAlgebra R X) = Cardinal.lift.{u} (Cardinal.mk (List X)) := by
rw [← (Basis.mk_eq_rank'.{_,_,_,u} (basisFreeMonoid R X)).trans (Cardinal.lift_id _),
Cardinal.lift_umax.{v, u}, FreeMonoid]
end FreeAlgebra
open Cardinal
theorem Algebra.rank_adjoin_le {R : Type u} {S : Type v} [CommRing R] [Ring S] [Algebra R S]
(s : Set S) : Module.rank R (adjoin R s) ≤ max #s ℵ₀ := by
rw [adjoin_eq_range_freeAlgebra_lift]
cases subsingleton_or_nontrivial R
· rw [rank_subsingleton]; exact one_le_aleph0.trans (le_max_right _ _)
rw [← lift_le.{max u v}]
refine (lift_rank_range_le (FreeAlgebra.lift R ((↑) : s → S)).toLinearMap).trans ?_
rw [FreeAlgebra.rank_eq, lift_id'.{v,u}, lift_umax.{v,u}, lift_le, max_comm]
exact mk_list_le_max _
|
Pi.lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Patrick Massot
-/
import Mathlib.Algebra.Notation.Lemmas
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Algebra.Ring.Pi
/-!
# Pi instances for ordered groups and monoids
This file defines instances for ordered group, monoid, and related structures on Pi types.
-/
variable {I α β γ : Type*}
-- The indexing type
variable {f : I → Type*}
namespace Pi
/-- The product of a family of ordered commutative monoids is an ordered commutative monoid. -/
@[to_additive
/-- The product of a family of ordered additive commutative monoids is
an ordered additive commutative monoid. -/]
instance isOrderedMonoid {ι : Type*} {Z : ι → Type*} [∀ i, CommMonoid (Z i)]
[∀ i, PartialOrder (Z i)] [∀ i, IsOrderedMonoid (Z i)] :
IsOrderedMonoid (∀ i, Z i) where
mul_le_mul_left _ _ w _ := fun i => mul_le_mul_left' (w i) _
@[to_additive]
instance existsMulOfLe {ι : Type*} {α : ι → Type*} [∀ i, LE (α i)] [∀ i, Mul (α i)]
[∀ i, ExistsMulOfLE (α i)] : ExistsMulOfLE (∀ i, α i) :=
⟨fun h =>
⟨fun i => (exists_mul_of_le <| h i).choose,
funext fun i => (exists_mul_of_le <| h i).choose_spec⟩⟩
/-- The product of a family of canonically ordered monoids is a canonically ordered monoid. -/
@[to_additive
/-- The product of a family of canonically ordered additive monoids is
a canonically ordered additive monoid. -/]
instance {ι : Type*} {Z : ι → Type*} [∀ i, Monoid (Z i)] [∀ i, PartialOrder (Z i)]
[∀ i, CanonicallyOrderedMul (Z i)] :
CanonicallyOrderedMul (∀ i, Z i) where
__ := Pi.existsMulOfLe
le_self_mul _ _ := fun _ => le_self_mul
@[to_additive]
instance isOrderedCancelMonoid [∀ i, CommMonoid <| f i] [∀ i, PartialOrder <| f i]
[∀ i, IsOrderedCancelMonoid <| f i] :
IsOrderedCancelMonoid (∀ i : I, f i) where
le_of_mul_le_mul_left _ _ _ h i := le_of_mul_le_mul_left' (h i)
instance isOrderedRing [∀ i, Semiring (f i)] [∀ i, PartialOrder (f i)] [∀ i, IsOrderedRing (f i)] :
IsOrderedRing (∀ i, f i) where
add_le_add_left _ _ hab _ := fun _ => add_le_add_left (hab _) _
zero_le_one := fun i => zero_le_one (α := f i)
mul_le_mul_of_nonneg_left _ _ _ hab hc := fun _ => mul_le_mul_of_nonneg_left (hab _) <| hc _
mul_le_mul_of_nonneg_right _ _ _ hab hc := fun _ => mul_le_mul_of_nonneg_right (hab _) <| hc _
end Pi
namespace Function
section const
variable (β) [One α] [Preorder α] {a : α}
@[to_additive const_nonneg_of_nonneg]
theorem one_le_const_of_one_le (ha : 1 ≤ a) : 1 ≤ const β a := fun _ => ha
@[to_additive]
theorem const_le_one_of_le_one (ha : a ≤ 1) : const β a ≤ 1 := fun _ => ha
variable {β} [Nonempty β]
@[to_additive (attr := simp) const_nonneg]
theorem one_le_const : 1 ≤ const β a ↔ 1 ≤ a :=
const_le_const
@[to_additive (attr := simp) const_pos]
theorem one_lt_const : 1 < const β a ↔ 1 < a :=
const_lt_const
@[to_additive (attr := simp)]
theorem const_le_one : const β a ≤ 1 ↔ a ≤ 1 :=
const_le_const
@[to_additive (attr := simp) const_neg']
theorem const_lt_one : const β a < 1 ↔ a < 1 :=
const_lt_const
end const
section extend
variable [One γ] [LE γ] {f : α → β} {g : α → γ} {e : β → γ}
@[to_additive extend_nonneg] lemma one_le_extend (hg : 1 ≤ g) (he : 1 ≤ e) : 1 ≤ extend f g e :=
fun _b ↦ by classical exact one_le_dite (fun _ ↦ hg _) (fun _ ↦ he _)
@[to_additive] lemma extend_le_one (hg : g ≤ 1) (he : e ≤ 1) : extend f g e ≤ 1 :=
fun _b ↦ by classical exact dite_le_one (fun _ ↦ hg _) (fun _ ↦ he _)
end extend
end Function
namespace Pi
variable {ι : Type*} {α : ι → Type*} [DecidableEq ι] [∀ i, One (α i)] [∀ i, Preorder (α i)] {i : ι}
{a b : α i}
@[to_additive (attr := simp)]
lemma mulSingle_le_mulSingle : mulSingle i a ≤ mulSingle i b ↔ a ≤ b := by
simp [mulSingle]
@[to_additive (attr := gcongr)] alias ⟨_, GCongr.mulSingle_mono⟩ := mulSingle_le_mulSingle
@[to_additive (attr := simp) single_nonneg]
lemma one_le_mulSingle : 1 ≤ mulSingle i a ↔ 1 ≤ a := by simp [mulSingle]
@[to_additive (attr := simp)]
lemma mulSingle_le_one : mulSingle i a ≤ 1 ↔ a ≤ 1 := by simp [mulSingle]
end Pi
-- Porting note: Tactic code not ported yet
-- namespace Tactic
-- open Function
-- variable (ι) [Zero α] {a : α}
-- private theorem function_const_nonneg_of_pos [Preorder α] (ha : 0 < a) : 0 ≤ const ι a :=
-- const_nonneg_of_nonneg _ ha.le
-- variable [Nonempty ι]
-- private theorem function_const_ne_zero : a ≠ 0 → const ι a ≠ 0 :=
-- const_ne_zero.2
-- private theorem function_const_pos [Preorder α] : 0 < a → 0 < const ι a :=
-- const_pos.2
-- /-- Extension for the `positivity` tactic: `Function.const` is positive/nonnegative/nonzero if
-- its input is. -/
-- @[positivity]
-- unsafe def positivity_const : expr → tactic strictness
-- | q(Function.const $(ι) $(a)) => do
-- let strict_a ← core a
-- match strict_a with
-- | positive p =>
-- positive <$> to_expr ``(function_const_pos $(ι) $(p)) <|>
-- nonnegative <$> to_expr ``(function_const_nonneg_of_pos $(ι) $(p))
-- | nonnegative p => nonnegative <$> to_expr ``(const_nonneg_of_nonneg $(ι) $(p))
-- | nonzero p => nonzero <$> to_expr ``(function_const_ne_zero $(ι) $(p))
-- | e =>
-- pp e >>= fail ∘ format.bracket "The expression `" "` is not of the form `Function.const ι a`"
-- end Tactic
|
GradedModule.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.RingTheory.GradedAlgebra.Basic
import Mathlib.Algebra.GradedMulAction
import Mathlib.Algebra.DirectSum.Decomposition
import Mathlib.Algebra.Module.BigOperators
/-!
# Graded Module
Given an `R`-algebra `A` graded by `𝓐`, a graded `A`-module `M` is expressed as
`DirectSum.Decomposition 𝓜` and `SetLike.GradedSMul 𝓐 𝓜`.
Then `⨁ i, 𝓜 i` is an `A`-module and is isomorphic to `M`.
## Tags
graded module
-/
section
open DirectSum
variable {ιA ιB : Type*} (A : ιA → Type*) (M : ιB → Type*)
namespace DirectSum
open GradedMonoid
/-- A graded version of `DistribMulAction`. -/
class GdistribMulAction [AddMonoid ιA] [VAdd ιA ιB] [GMonoid A] [∀ i, AddMonoid (M i)]
extends GMulAction A M where
smul_add {i j} (a : A i) (b c : M j) : smul a (b + c) = smul a b + smul a c
smul_zero {i j} (a : A i) : smul a (0 : M j) = 0
/-- A graded version of `Module`. -/
class Gmodule [AddMonoid ιA] [VAdd ιA ιB] [∀ i, AddMonoid (A i)] [∀ i, AddMonoid (M i)] [GMonoid A]
extends GdistribMulAction A M where
add_smul {i j} (a a' : A i) (b : M j) : smul (a + a') b = smul a b + smul a' b
zero_smul {i j} (b : M j) : smul (0 : A i) b = 0
/-- A graded version of `Semiring.toModule`. -/
instance GSemiring.toGmodule [AddMonoid ιA] [∀ i : ιA, AddCommMonoid (A i)]
[h : GSemiring A] : Gmodule A A :=
{ GMonoid.toGMulAction A with
smul_add := fun _ _ _ => h.mul_add _ _ _
smul_zero := fun _ => h.mul_zero _
add_smul := fun _ _ => h.add_mul _ _
zero_smul := fun _ => h.zero_mul _ }
variable [AddMonoid ιA] [VAdd ιA ιB] [∀ i : ιA, AddCommMonoid (A i)] [∀ i, AddCommMonoid (M i)]
/-- The piecewise multiplication from the `Mul` instance, as a bundled homomorphism. -/
@[simps]
def gsmulHom [GMonoid A] [Gmodule A M] {i j} : A i →+ M j →+ M (i +ᵥ j) where
toFun a :=
{ toFun := fun b => GSMul.smul a b
map_zero' := GdistribMulAction.smul_zero _
map_add' := GdistribMulAction.smul_add _ }
map_zero' := AddMonoidHom.ext fun a => Gmodule.zero_smul a
map_add' _a₁ _a₂ := AddMonoidHom.ext fun _b => Gmodule.add_smul _ _ _
namespace Gmodule
/-- For graded monoid `A` and a graded module `M` over `A`. `Gmodule.smulAddMonoidHom` is the
`⨁ᵢ Aᵢ`-scalar multiplication on `⨁ᵢ Mᵢ` induced by `gsmul_hom`. -/
def smulAddMonoidHom [DecidableEq ιA] [DecidableEq ιB] [GMonoid A] [Gmodule A M] :
(⨁ i, A i) →+ (⨁ i, M i) →+ ⨁ i, M i :=
toAddMonoid fun _i =>
AddMonoidHom.flip <|
toAddMonoid fun _j => AddMonoidHom.flip <| (of M _).compHom.comp <| gsmulHom A M
section
open GradedMonoid DirectSum Gmodule
instance [DecidableEq ιA] [DecidableEq ιB] [GMonoid A] [Gmodule A M] :
SMul (⨁ i, A i) (⨁ i, M i) where
smul x y := smulAddMonoidHom A M x y
@[simp]
theorem smul_def [DecidableEq ιA] [DecidableEq ιB] [GMonoid A] [Gmodule A M]
(x : ⨁ i, A i) (y : ⨁ i, M i) :
x • y = smulAddMonoidHom _ _ x y := rfl
@[simp]
theorem smulAddMonoidHom_apply_of_of [DecidableEq ιA] [DecidableEq ιB] [GMonoid A] [Gmodule A M]
{i j} (x : A i) (y : M j) :
smulAddMonoidHom A M (DirectSum.of A i x) (of M j y) = of M (i +ᵥ j) (GSMul.smul x y) := by
simp [smulAddMonoidHom]
theorem of_smul_of [DecidableEq ιA] [DecidableEq ιB] [GMonoid A] [Gmodule A M]
{i j} (x : A i) (y : M j) :
DirectSum.of A i x • of M j y = of M (i +ᵥ j) (GSMul.smul x y) := by simp
open AddMonoidHom
-- Almost identical to the proof of `direct_sum.one_mul`
private theorem one_smul' [DecidableEq ιA] [DecidableEq ιB] [GMonoid A] [Gmodule A M]
(x : ⨁ i, M i) :
(1 : ⨁ i, A i) • x = x := by
suffices smulAddMonoidHom A M 1 = AddMonoidHom.id (⨁ i, M i) from DFunLike.congr_fun this x
apply DirectSum.addHom_ext; intro i xi
rw [show (1 : DirectSum ιA fun i => A i) = (of A 0) GOne.one by rfl]
rw [smulAddMonoidHom_apply_of_of]
exact DirectSum.of_eq_of_gradedMonoid_eq (one_smul (GradedMonoid A) <| GradedMonoid.mk i xi)
-- Almost identical to the proof of `direct_sum.mul_assoc`
private theorem mul_smul' [DecidableEq ιA] [DecidableEq ιB] [GSemiring A] [Gmodule A M]
(a b : ⨁ i, A i)
(c : ⨁ i, M i) : (a * b) • c = a • b • c := by
suffices
(-- `fun a b c ↦ (a * b) • c` as a bundled hom
smulAddMonoidHom
A M).compHom.comp
(DirectSum.mulHom A) =
(AddMonoidHom.compHom AddMonoidHom.flipHom <|
(smulAddMonoidHom A M).flip.compHom.comp <| smulAddMonoidHom A M).flip
from-- `fun a b c ↦ a • (b • c)` as a bundled hom
DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this a) b) c
ext ai ax bi bx ci cx : 6
dsimp only [coe_comp, Function.comp_apply, compHom_apply_apply, flip_apply, flipHom_apply]
rw [smulAddMonoidHom_apply_of_of, smulAddMonoidHom_apply_of_of, DirectSum.mulHom_of_of,
smulAddMonoidHom_apply_of_of]
exact
DirectSum.of_eq_of_gradedMonoid_eq
(mul_smul (GradedMonoid.mk ai ax) (GradedMonoid.mk bi bx) (GradedMonoid.mk ci cx))
/-- The `Module` derived from `gmodule A M`. -/
instance module [DecidableEq ιA] [DecidableEq ιB] [GSemiring A] [Gmodule A M] :
Module (⨁ i, A i) (⨁ i, M i) where
smul := (· • ·)
one_smul := one_smul' _ _
mul_smul := mul_smul' _ _
smul_add r := (smulAddMonoidHom A M r).map_add
smul_zero r := (smulAddMonoidHom A M r).map_zero
add_smul r s x := by simp only [smul_def, map_add, AddMonoidHom.add_apply]
zero_smul x := by simp only [smul_def, map_zero, AddMonoidHom.zero_apply]
end
end Gmodule
end DirectSum
end
open DirectSum
variable {ιA ιM R A M σ σ' : Type*}
variable [AddMonoid ιA] [AddAction ιA ιM] [CommSemiring R] [Semiring A] [Algebra R A]
variable (𝓐 : ιA → σ') [SetLike σ' A]
variable (𝓜 : ιM → σ)
namespace SetLike
instance gmulAction [AddMonoid M] [DistribMulAction A M] [SetLike σ M] [SetLike.GradedMonoid 𝓐]
[SetLike.GradedSMul 𝓐 𝓜] : GradedMonoid.GMulAction (fun i => 𝓐 i) fun i => 𝓜 i :=
{ SetLike.toGSMul 𝓐 𝓜 with
one_smul := fun ⟨_i, _m⟩ => Sigma.subtype_ext (zero_vadd _ _) (one_smul _ _)
mul_smul := fun ⟨_i, _a⟩ ⟨_j, _a'⟩ ⟨_k, _b⟩ =>
Sigma.subtype_ext (add_vadd _ _ _) (mul_smul _ _ _) }
instance gdistribMulAction [AddMonoid M] [DistribMulAction A M] [SetLike σ M]
[AddSubmonoidClass σ M] [SetLike.GradedMonoid 𝓐] [SetLike.GradedSMul 𝓐 𝓜] :
DirectSum.GdistribMulAction (fun i => 𝓐 i) fun i => 𝓜 i :=
{ SetLike.gmulAction 𝓐 𝓜 with
smul_add := fun _a _b _c => Subtype.ext <| smul_add _ _ _
smul_zero := fun _a => Subtype.ext <| smul_zero _ }
variable [AddCommMonoid M] [Module A M] [SetLike σ M] [AddSubmonoidClass σ' A]
[AddSubmonoidClass σ M] [SetLike.GradedMonoid 𝓐] [SetLike.GradedSMul 𝓐 𝓜]
/-- `[SetLike.GradedMonoid 𝓐] [SetLike.GradedSMul 𝓐 𝓜]` is the internal version of graded
module, the internal version can be translated into the external version `gmodule`. -/
instance gmodule : DirectSum.Gmodule (fun i => 𝓐 i) fun i => 𝓜 i :=
{ SetLike.gdistribMulAction 𝓐 𝓜 with
smul := fun x y => ⟨(x : A) • (y : M), SetLike.GradedSMul.smul_mem x.2 y.2⟩
add_smul := fun _a _a' _b => Subtype.ext <| add_smul _ _ _
zero_smul := fun _b => Subtype.ext <| zero_smul _ _ }
end SetLike
namespace GradedModule
variable [AddCommMonoid M] [Module A M] [SetLike σ M] [AddSubmonoidClass σ' A]
[AddSubmonoidClass σ M] [SetLike.GradedMonoid 𝓐] [SetLike.GradedSMul 𝓐 𝓜]
/-- The smul multiplication of `A` on `⨁ i, 𝓜 i` from `(⨁ i, 𝓐 i) →+ (⨁ i, 𝓜 i) →+ ⨁ i, 𝓜 i`
turns `⨁ i, 𝓜 i` into an `A`-module
-/
def isModule [DecidableEq ιA] [DecidableEq ιM] [GradedRing 𝓐] : Module A (⨁ i, 𝓜 i) :=
{ Module.compHom _ (DirectSum.decomposeRingEquiv 𝓐 : A ≃+* ⨁ i, 𝓐 i).toRingHom with
smul := fun a b => DirectSum.decompose 𝓐 a • b }
/-- `⨁ i, 𝓜 i` and `M` are isomorphic as `A`-modules.
"The internal version" and "the external version" are isomorphism as `A`-modules.
-/
def linearEquiv [DecidableEq ιA] [DecidableEq ιM] [GradedRing 𝓐] [DirectSum.Decomposition 𝓜] :
@LinearEquiv A A _ _ (RingHom.id A) (RingHom.id A) _ _ M (⨁ i, 𝓜 i) _
_ _ (by letI := isModule 𝓐 𝓜; infer_instance) := by
letI h := isModule 𝓐 𝓜
refine ⟨⟨(DirectSum.decomposeAddEquiv 𝓜).toAddHom, ?_⟩,
(DirectSum.decomposeAddEquiv 𝓜).symm.toFun, (DirectSum.decomposeAddEquiv 𝓜).left_inv,
(DirectSum.decomposeAddEquiv 𝓜).right_inv⟩
intro x y
classical
rw [AddHom.toFun_eq_coe, ← DirectSum.sum_support_decompose 𝓐 x, map_sum, Finset.sum_smul,
AddEquiv.coe_toAddHom, map_sum, Finset.sum_smul]
refine Finset.sum_congr rfl (fun i _hi => ?_)
rw [RingHom.id_apply, ← DirectSum.sum_support_decompose 𝓜 y, map_sum, Finset.smul_sum, map_sum,
Finset.smul_sum]
refine Finset.sum_congr rfl (fun j _hj => ?_)
rw [show (decompose 𝓐 x i : A) • (decomposeAddEquiv 𝓜 ↑(decompose 𝓜 y j) : (⨁ i, 𝓜 i)) =
DirectSum.Gmodule.smulAddMonoidHom _ _ (decompose 𝓐 ↑(decompose 𝓐 x i))
(decomposeAddEquiv 𝓜 ↑(decompose 𝓜 y j)) from DirectSum.Gmodule.smul_def _ _ _ _]
simp only [decomposeAddEquiv_apply, decompose_coe, Gmodule.smulAddMonoidHom_apply_of_of]
convert DirectSum.decompose_coe 𝓜 _
rfl
end GradedModule
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.