filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
Notation.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.Data.Finsupp.Single
/-!
# Notation for `Finsupp`
This file provides `fun₀ | 3 => a | 7 => b` notation for `Finsupp`, which desugars to
`Finsupp.update` and `Finsupp.single`, in the same way that `{a, b}` desugars to `insert` and
`singleton`.
-/
namespace Finsupp
open Lean Parser Term
-- A variant of `Lean.Parser.Term.matchAlts` with less line wrapping.
@[nolint docBlame] -- we do not want any doc hover on this notation.
def fun₀.matchAlts : Parser :=
leading_parser withPosition <| ppRealGroup <| many1Indent (ppSpace >> ppGroup matchAlt)
/-- `fun₀ | i => a` is notation for `Finsupp.single i a`, and with multiple match arms,
`fun₀ ... | i => a` is notation for `Finsupp.update (fun₀ ...) i a`.
As a result, if multiple match arms coincide, the last one takes precedence. -/
@[term_parser]
def fun₀ := leading_parser:maxPrec
ppAllowUngrouped >> unicodeSymbol "λ₀" "fun₀" >> fun₀.matchAlts
/-- Implementation detail for `fun₀`, used by both `Finsupp` and `DFinsupp` -/
local syntax:lead (name := stxSingle₀) "single₀" term:arg term:arg : term
/-- Implementation detail for `fun₀`, used by both `Finsupp` and `DFinsupp` -/
local syntax:lead (name := stxUpdate₀) "update₀" term:arg term:arg term:arg : term
/-- `Finsupp` elaborator for `single₀`. -/
@[term_elab stxSingle₀]
def elabSingle₀ : Elab.Term.TermElab
| `(term| single₀ $i $x) => fun ty => do Elab.Term.elabTerm (← `(Finsupp.single $i $x)) ty
| _ => fun _ => Elab.throwUnsupportedSyntax
/-- `Finsupp` elaborator for `update₀`. -/
@[term_elab stxUpdate₀]
def elabUpdate₀ : Elab.Term.TermElab
| `(term| update₀ $f $i $x) => fun ty => do Elab.Term.elabTerm (← `(Finsupp.update $f $i $x)) ty
| _ => fun _ => Elab.throwUnsupportedSyntax
macro_rules
| `(term| fun₀ $x:matchAlt*) => do
let mut stx : Term ← `(0)
let mut fst : Bool := true
for xi in x do
for xii in (← Elab.Term.expandMatchAlt xi) do
match xii with
| `(matchAltExpr| | $pat => $val) =>
if fst then
stx ← `(single₀ $pat $val)
else
stx ← `(update₀ $stx $pat $val)
fst := false
| _ => Macro.throwUnsupported
pure stx
/-- Unexpander for the `fun₀ | i => x` notation. -/
@[app_unexpander Finsupp.single]
def singleUnexpander : Lean.PrettyPrinter.Unexpander
| `($_ $pat $val) => `(fun₀ | $pat => $val)
| _ => throw ()
/-- Unexpander for the `fun₀ | i => x` notation. -/
@[app_unexpander Finsupp.update]
def updateUnexpander : Lean.PrettyPrinter.Unexpander
| `($_ $f $pat $val) => match f with
| `(fun₀ $xs:matchAlt*) => `(fun₀ $xs:matchAlt* | $pat => $val)
| _ => throw ()
| _ => throw ()
/-- Display `Finsupp` using `fun₀` notation. -/
unsafe instance instRepr {α β} [Repr α] [Repr β] [Zero β] : Repr (α →₀ β) where
reprPrec f p :=
if f.support.card = 0 then
"0"
else
let ret : Std.Format := f!"fun₀" ++ .nest 2 (
.group (.join <| f.support.val.unquot.map fun a =>
.line ++ .group (f!"| {repr a} =>" ++ .line ++ repr (f a))))
if p ≥ leadPrec then Format.paren ret else ret
-- This cannot be put in `Mathlib/Data/DFinsupp/Notation.lean` where it belongs, since doc-strings
-- can only be added/modified in the file where the corresponding declaration is defined.
extend_docs Finsupp.fun₀ after
"If the expected type is `Π₀ i, α i` (`DFinsupp`)
and `Mathlib/Data/DFinsupp/Notation.lean` is imported,
then this is notation for `DFinsupp.single` and `Dfinsupp.update` instead."
end Finsupp
|
Defs.lean
|
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Group.InjSurj
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Data.Setoid.Basic
import Mathlib.Tactic.FastInstance
/-!
# Congruence relations
This file defines congruence relations: equivalence relations that preserve a binary operation,
which in this case is multiplication or addition. The principal definition is a `structure`
extending a `Setoid` (an equivalence relation), and the inductive definition of the smallest
congruence relation containing a binary relation is also given (see `ConGen`).
The file also proves basic properties of the quotient of a type by a congruence relation, and the
complete lattice of congruence relations on a type. We then establish an order-preserving bijection
between the set of congruence relations containing a congruence relation `c` and the set of
congruence relations on the quotient by `c`.
The second half of the file concerns congruence relations on monoids, in which case the
quotient by the congruence relation is also a monoid.
## Implementation notes
The inductive definition of a congruence relation could be a nested inductive type, defined using
the equivalence closure of a binary relation `EqvGen`, but the recursor generated does not work.
A nested inductive definition could conceivably shorten proofs, because they would allow invocation
of the corresponding lemmas about `EqvGen`.
The lemmas `refl`, `symm` and `trans` are not tagged with `@[refl]`, `@[symm]`, and `@[trans]`
respectively as these tags do not work on a structure coerced to a binary relation.
There is a coercion from elements of a type to the element's equivalence class under a
congruence relation.
A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which
membership is an equivalence relation, but whilst this fact is established in the file, it is not
used, since this perspective adds more layers of definitional unfolding.
## Tags
congruence, congruence relation, quotient, quotient by congruence relation, monoid,
quotient monoid, isomorphism theorems
-/
variable (M : Type*) {N : Type*} {P : Type*}
open Function Setoid
/-- A congruence relation on a type with an addition is an equivalence relation which
preserves addition. -/
structure AddCon [Add M] extends Setoid M where
/-- Additive congruence relations are closed under addition -/
add' : ∀ {w x y z}, r w x → r y z → r (w + y) (x + z)
/-- A congruence relation on a type with a multiplication is an equivalence relation which
preserves multiplication. -/
@[to_additive AddCon]
structure Con [Mul M] extends Setoid M where
/-- Congruence relations are closed under multiplication -/
mul' : ∀ {w x y z}, r w x → r y z → r (w * y) (x * z)
/-- The equivalence relation underlying an additive congruence relation. -/
add_decl_doc AddCon.toSetoid
/-- The equivalence relation underlying a multiplicative congruence relation. -/
add_decl_doc Con.toSetoid
variable {M}
/-- The inductively defined smallest additive congruence relation containing a given binary
relation. -/
inductive AddConGen.Rel [Add M] (r : M → M → Prop) : M → M → Prop
| of : ∀ x y, r x y → AddConGen.Rel r x y
| refl : ∀ x, AddConGen.Rel r x x
| symm : ∀ {x y}, AddConGen.Rel r x y → AddConGen.Rel r y x
| trans : ∀ {x y z}, AddConGen.Rel r x y → AddConGen.Rel r y z → AddConGen.Rel r x z
| add : ∀ {w x y z}, AddConGen.Rel r w x → AddConGen.Rel r y z → AddConGen.Rel r (w + y) (x + z)
/-- The inductively defined smallest multiplicative congruence relation containing a given binary
relation. -/
@[to_additive AddConGen.Rel]
inductive ConGen.Rel [Mul M] (r : M → M → Prop) : M → M → Prop
| of : ∀ x y, r x y → ConGen.Rel r x y
| refl : ∀ x, ConGen.Rel r x x
| symm : ∀ {x y}, ConGen.Rel r x y → ConGen.Rel r y x
| trans : ∀ {x y z}, ConGen.Rel r x y → ConGen.Rel r y z → ConGen.Rel r x z
| mul : ∀ {w x y z}, ConGen.Rel r w x → ConGen.Rel r y z → ConGen.Rel r (w * y) (x * z)
/-- The inductively defined smallest multiplicative congruence relation containing a given binary
relation. -/
@[to_additive addConGen /-- The inductively defined smallest additive congruence relation containing
a given binary relation. -/]
def conGen [Mul M] (r : M → M → Prop) : Con M :=
⟨⟨ConGen.Rel r, ⟨ConGen.Rel.refl, ConGen.Rel.symm, ConGen.Rel.trans⟩⟩, ConGen.Rel.mul⟩
namespace Con
section
variable [Mul M] [Mul N] [Mul P] (c : Con M)
@[to_additive]
instance : Inhabited (Con M) :=
⟨conGen EmptyRelation⟩
/-- A coercion from a congruence relation to its underlying binary relation. -/
@[to_additive
/-- A coercion from an additive congruence relation to its underlying binary relation. -/]
instance : FunLike (Con M) M (M → Prop) where
coe c := c.r
coe_injective' x y h := by
rcases x with ⟨⟨x, _⟩, _⟩
rcases y with ⟨⟨y, _⟩, _⟩
have : x = y := h
subst x; rfl
@[to_additive (attr := simp)]
theorem rel_eq_coe (c : Con M) : c.r = c :=
rfl
/-- Congruence relations are reflexive. -/
@[to_additive /-- Additive congruence relations are reflexive. -/]
protected theorem refl (x) : c x x :=
c.toSetoid.refl' x
/-- Congruence relations are symmetric. -/
@[to_additive /-- Additive congruence relations are symmetric. -/]
protected theorem symm {x y} : c x y → c y x := c.toSetoid.symm'
/-- Congruence relations are transitive. -/
@[to_additive /-- Additive congruence relations are transitive. -/]
protected theorem trans {x y z} : c x y → c y z → c x z := c.toSetoid.trans'
/-- Multiplicative congruence relations preserve multiplication. -/
@[to_additive /-- Additive congruence relations preserve addition. -/]
protected theorem mul {w x y z} : c w x → c y z → c (w * y) (x * z) := c.mul'
@[to_additive (attr := simp)]
theorem rel_mk {s : Setoid M} {h a b} : Con.mk s h a b ↔ r a b :=
Iff.rfl
/-- Given a type `M` with a multiplication, a congruence relation `c` on `M`, and elements of `M`
`x, y`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`. -/
@[to_additive instMembershipProd
/-- Given a type `M` with an addition, `x, y ∈ M`, and an additive congruence relation
`c` on `M`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`. -/]
instance instMembershipProd : Membership (M × M) (Con M) :=
⟨fun c x => c x.1 x.2⟩
variable {c}
/-- The map sending a congruence relation to its underlying binary relation is injective. -/
@[to_additive /-- The map sending an additive congruence relation to its underlying binary relation
is injective. -/]
theorem ext' {c d : Con M} (H : ⇑c = ⇑d) : c = d := DFunLike.coe_injective H
/-- Extensionality rule for congruence relations. -/
@[to_additive (attr := ext) /-- Extensionality rule for additive congruence relations. -/]
theorem ext {c d : Con M} (H : ∀ x y, c x y ↔ d x y) : c = d :=
ext' <| by ext; apply H
/-- The map sending a congruence relation to its underlying equivalence relation is injective. -/
@[to_additive /-- The map sending an additive congruence relation to its underlying equivalence
relation is injective. -/]
theorem toSetoid_inj {c d : Con M} (H : c.toSetoid = d.toSetoid) : c = d :=
ext <| Setoid.ext_iff.1 H
/-- Two congruence relations are equal iff their underlying binary relations are equal. -/
@[to_additive /-- Two additive congruence relations are equal iff their underlying binary relations
are equal. -/]
theorem coe_inj {c d : Con M} : ⇑c = ⇑d ↔ c = d := DFunLike.coe_injective.eq_iff
variable (c)
-- Quotients
/-- Defining the quotient by a congruence relation of a type with a multiplication. -/
@[to_additive /-- Defining the quotient by an additive congruence relation of a type with
an addition. -/]
protected def Quotient :=
Quotient c.toSetoid
variable {c}
/-- The morphism into the quotient by a congruence relation -/
@[to_additive (attr := coe)
/-- The morphism into the quotient by an additive congruence relation -/]
def toQuotient : M → c.Quotient :=
Quotient.mk''
variable (c)
-- Porting note: was `priority 0`. why?
/-- Coercion from a type with a multiplication to its quotient by a congruence relation.
See Note [use has_coe_t]. -/
@[to_additive /-- Coercion from a type with an addition to its quotient by an additive congruence
relation -/]
instance (priority := 10) : CoeTC M c.Quotient :=
⟨toQuotient⟩
-- Lower the priority since it unifies with any quotient type.
/-- The quotient by a decidable congruence relation has decidable equality. -/
@[to_additive
/-- The quotient by a decidable additive congruence relation has decidable equality. -/]
instance (priority := 500) [∀ a b, Decidable (c a b)] : DecidableEq c.Quotient :=
inferInstanceAs (DecidableEq (Quotient c.toSetoid))
@[to_additive (attr := simp)]
theorem quot_mk_eq_coe {M : Type*} [Mul M] (c : Con M) (x : M) : Quot.mk c x = (x : c.Quotient) :=
rfl
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: restore `elab_as_elim`
/-- The function on the quotient by a congruence relation `c` induced by a function that is
constant on `c`'s equivalence classes. -/
@[to_additive /-- The function on the quotient by a congruence relation `c`
induced by a function that is constant on `c`'s equivalence classes. -/]
protected def liftOn {β} {c : Con M} (q : c.Quotient) (f : M → β) (h : ∀ a b, c a b → f a = f b) :
β :=
Quotient.liftOn' q f h
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: restore `elab_as_elim`
/-- The binary function on the quotient by a congruence relation `c` induced by a binary function
that is constant on `c`'s equivalence classes. -/
@[to_additive /-- The binary function on the quotient by a congruence relation `c`
induced by a binary function that is constant on `c`'s equivalence classes. -/]
protected def liftOn₂ {β} {c : Con M} (q r : c.Quotient) (f : M → M → β)
(h : ∀ a₁ a₂ b₁ b₂, c a₁ b₁ → c a₂ b₂ → f a₁ a₂ = f b₁ b₂) : β :=
Quotient.liftOn₂' q r f h
/-- A version of `Quotient.hrecOn₂'` for quotients by `Con`. -/
@[to_additive /-- A version of `Quotient.hrecOn₂'` for quotients by `AddCon`. -/]
protected def hrecOn₂ {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*}
(a : cM.Quotient) (b : cN.Quotient) (f : ∀ (x : M) (y : N), φ x y)
(h : ∀ x y x' y', cM x x' → cN y y' → f x y ≍ f x' y') : φ a b :=
Quotient.hrecOn₂' a b f h
@[to_additive (attr := simp)]
theorem hrec_on₂_coe {cM : Con M} {cN : Con N} {φ : cM.Quotient → cN.Quotient → Sort*} (a : M)
(b : N) (f : ∀ (x : M) (y : N), φ x y)
(h : ∀ x y x' y', cM x x' → cN y y' → f x y ≍ f x' y') :
Con.hrecOn₂ (↑a) (↑b) f h = f a b :=
rfl
variable {c}
/-- The inductive principle used to prove propositions about the elements of a quotient by a
congruence relation. -/
@[to_additive (attr := elab_as_elim) /-- The inductive principle used to prove propositions about
the elements of a quotient by an additive congruence relation. -/]
protected theorem induction_on {C : c.Quotient → Prop} (q : c.Quotient) (H : ∀ x : M, C x) : C q :=
Quotient.inductionOn' q H
/-- A version of `Con.induction_on` for predicates which takes two arguments. -/
@[to_additive (attr := elab_as_elim)
/-- A version of `AddCon.induction_on` for predicates which takes two arguments. -/]
protected theorem induction_on₂ {d : Con N} {C : c.Quotient → d.Quotient → Prop} (p : c.Quotient)
(q : d.Quotient) (H : ∀ (x : M) (y : N), C x y) : C p q :=
Quotient.inductionOn₂' p q H
variable (c)
/-- Two elements are related by a congruence relation `c` iff they are represented by the same
element of the quotient by `c`. -/
@[to_additive (attr := simp) /-- Two elements are related by an additive congruence relation `c` iff
they are represented by the same element of the quotient by `c`. -/]
protected theorem eq {a b : M} : (a : c.Quotient) = (b : c.Quotient) ↔ c a b :=
Quotient.eq''
/-- The multiplication induced on the quotient by a congruence relation on a type with a
multiplication. -/
@[to_additive /-- The addition induced on the quotient by an additive congruence relation on a type
with an addition. -/]
instance hasMul : Mul c.Quotient :=
⟨Quotient.map₂ (· * ·) fun _ _ h1 _ _ h2 => c.mul h1 h2⟩
variable {c}
/-- The coercion to the quotient of a congruence relation commutes with multiplication (by
definition). -/
@[to_additive (attr := simp) /-- The coercion to the quotient of an additive congruence relation
commutes with addition (by definition). -/]
theorem coe_mul (x y : M) : (↑(x * y) : c.Quotient) = ↑x * ↑y :=
rfl
/-- Definition of the function on the quotient by a congruence relation `c` induced by a function
that is constant on `c`'s equivalence classes. -/
@[to_additive (attr := simp) /-- Definition of the function on the quotient by an additive
congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/]
protected theorem liftOn_coe {β} (c : Con M) (f : M → β) (h : ∀ a b, c a b → f a = f b) (x : M) :
Con.liftOn (x : c.Quotient) f h = f x :=
rfl
-- The complete lattice of congruence relations on a type
/-- For congruence relations `c, d` on a type `M` with a multiplication, `c ≤ d` iff `∀ x y ∈ M`,
`x` is related to `y` by `d` if `x` is related to `y` by `c`. -/
@[to_additive /-- For additive congruence relations `c, d` on a type `M` with an addition, `c ≤ d`
iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`. -/]
instance : LE (Con M) where
le c d := ∀ ⦃x y⦄, c x y → d x y
/-- Definition of `≤` for congruence relations. -/
@[to_additive /-- Definition of `≤` for additive congruence relations. -/]
theorem le_def {c d : Con M} : c ≤ d ↔ ∀ {x y}, c x y → d x y :=
Iff.rfl
/-- The infimum of a set of congruence relations on a given type with a multiplication. -/
@[to_additive /-- The infimum of a set of additive congruence relations on a given type with
an addition. -/]
instance : InfSet (Con M) where
sInf S :=
{ r := fun x y => ∀ c : Con M, c ∈ S → c x y
iseqv := ⟨fun x c _ => c.refl x, fun h c hc => c.symm <| h c hc,
fun h1 h2 c hc => c.trans (h1 c hc) <| h2 c hc⟩
mul' := fun h1 h2 c hc => c.mul (h1 c hc) <| h2 c hc }
/-- The infimum of a set of congruence relations is the same as the infimum of the set's image
under the map to the underlying equivalence relation. -/
@[to_additive /-- The infimum of a set of additive congruence relations is the same as the infimum
of the set's image under the map to the underlying equivalence relation. -/]
theorem sInf_toSetoid (S : Set (Con M)) : (sInf S).toSetoid = sInf (toSetoid '' S) :=
Setoid.ext fun x y =>
⟨fun h r ⟨c, hS, hr⟩ => by rw [← hr]; exact h c hS, fun h c hS => h c.toSetoid ⟨c, hS, rfl⟩⟩
/-- The infimum of a set of congruence relations is the same as the infimum of the set's image
under the map to the underlying binary relation. -/
@[to_additive (attr := simp, norm_cast)
/-- The infimum of a set of additive congruence relations is the same as the infimum
of the set's image under the map to the underlying binary relation. -/]
theorem coe_sInf (S : Set (Con M)) :
⇑(sInf S) = sInf ((⇑) '' S) := by
ext
simp only [sInf_image, iInf_apply, iInf_Prop_eq]
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_iInf {ι : Sort*} (f : ι → Con M) : ⇑(iInf f) = ⨅ i, ⇑(f i) := by
rw [iInf, coe_sInf, ← Set.range_comp, sInf_range, Function.comp_def]
@[to_additive]
instance : PartialOrder (Con M) where
le_refl _ _ _ := id
le_trans _ _ _ h1 h2 _ _ h := h2 <| h1 h
le_antisymm _ _ hc hd := ext fun _ _ => ⟨fun h => hc h, fun h => hd h⟩
/-- The complete lattice of congruence relations on a given type with a multiplication. -/
@[to_additive /-- The complete lattice of additive congruence relations on a given type with
an addition. -/]
instance : CompleteLattice (Con M) where
__ := completeLatticeOfInf (Con M) fun s =>
⟨fun r hr x y h => (h : ∀ r ∈ s, (r : Con M) x y) r hr, fun r hr x y h r' hr' =>
hr hr'
h⟩
inf c d := ⟨c.toSetoid ⊓ d.toSetoid, fun h1 h2 => ⟨c.mul h1.1 h2.1, d.mul h1.2 h2.2⟩⟩
inf_le_left _ _ := fun _ _ h => h.1
inf_le_right _ _ := fun _ _ h => h.2
le_inf _ _ _ hb hc := fun _ _ h => ⟨hb h, hc h⟩
top := { Setoid.completeLattice.top with mul' := by tauto }
le_top _ := fun _ _ _ => trivial
bot := { Setoid.completeLattice.bot with mul' := fun h1 h2 => h1 ▸ h2 ▸ rfl }
bot_le c := fun x _ h => h ▸ c.refl x
/-- The infimum of two congruence relations equals the infimum of the underlying binary
operations. -/
@[to_additive (attr := simp, norm_cast)
/-- The infimum of two additive congruence relations equals the infimum of the underlying binary
operations. -/]
theorem coe_inf {c d : Con M} : ⇑(c ⊓ d) = ⇑c ⊓ ⇑d :=
rfl
/-- Definition of the infimum of two congruence relations. -/
@[to_additive /-- Definition of the infimum of two additive congruence relations. -/]
theorem inf_iff_and {c d : Con M} {x y} : (c ⊓ d) x y ↔ c x y ∧ d x y :=
Iff.rfl
/-- The inductively defined smallest congruence relation containing a binary relation `r` equals
the infimum of the set of congruence relations containing `r`. -/
@[to_additive addConGen_eq /-- The inductively defined smallest additive congruence relation
containing a binary relation `r` equals the infimum of the set of additive congruence relations
containing `r`. -/]
theorem conGen_eq (r : M → M → Prop) : conGen r = sInf { s : Con M | ∀ x y, r x y → s x y } :=
le_antisymm
(le_sInf (fun s hs x y (hxy : (conGen r) x y) =>
show s x y by
apply ConGen.Rel.recOn (motive := fun x y _ => s x y) hxy
· exact fun x y h => hs x y h
· exact s.refl'
· exact fun _ => s.symm'
· exact fun _ _ => s.trans'
· exact fun _ _ => s.mul))
(sInf_le ConGen.Rel.of)
/-- The smallest congruence relation containing a binary relation `r` is contained in any
congruence relation containing `r`. -/
@[to_additive addConGen_le /-- The smallest additive congruence relation containing a binary
relation `r` is contained in any additive congruence relation containing `r`. -/]
theorem conGen_le {r : M → M → Prop} {c : Con M} (h : ∀ x y, r x y → c x y) :
conGen r ≤ c := by rw [conGen_eq]; exact sInf_le h
/-- Given binary relations `r, s` with `r` contained in `s`, the smallest congruence relation
containing `s` contains the smallest congruence relation containing `r`. -/
@[to_additive addConGen_mono /-- Given binary relations `r, s` with `r` contained in `s`, the
smallest additive congruence relation containing `s` contains the smallest additive congruence
relation containing `r`. -/]
theorem conGen_mono {r s : M → M → Prop} (h : ∀ x y, r x y → s x y) : conGen r ≤ conGen s :=
conGen_le fun x y hr => ConGen.Rel.of _ _ <| h x y hr
/-- Congruence relations equal the smallest congruence relation in which they are contained. -/
@[to_additive (attr := simp) addConGen_of_addCon /-- Additive congruence relations equal the
smallest additive congruence relation in which they are contained. -/]
theorem conGen_of_con (c : Con M) : conGen c = c :=
le_antisymm (by rw [conGen_eq]; exact sInf_le fun _ _ => id) ConGen.Rel.of
/-- The map sending a binary relation to the smallest congruence relation in which it is
contained is idempotent. -/
@[to_additive addConGen_idem /-- The map sending a binary relation to the smallest additive
congruence relation in which it is contained is idempotent. -/]
theorem conGen_idem (r : M → M → Prop) : conGen (conGen r) = conGen r := by simp
/-- The supremum of congruence relations `c, d` equals the smallest congruence relation containing
the binary relation '`x` is related to `y` by `c` or `d`'. -/
@[to_additive sup_eq_addConGen /-- The supremum of additive congruence relations `c, d` equals the
smallest additive congruence relation containing the binary relation '`x` is related to `y`
by `c` or `d`'. -/]
theorem sup_eq_conGen (c d : Con M) : c ⊔ d = conGen fun x y => c x y ∨ d x y := by
rw [conGen_eq]
apply congr_arg sInf
simp only [le_def, or_imp, ← forall_and]
/-- The supremum of two congruence relations equals the smallest congruence relation containing
the supremum of the underlying binary operations. -/
@[to_additive /-- The supremum of two additive congruence relations equals the smallest additive
congruence relation containing the supremum of the underlying binary operations. -/]
theorem sup_def {c d : Con M} : c ⊔ d = conGen (⇑c ⊔ ⇑d) := by rw [sup_eq_conGen]; rfl
/-- The supremum of a set of congruence relations `S` equals the smallest congruence relation
containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by `c`'. -/
@[to_additive sSup_eq_addConGen /-- The supremum of a set of additive congruence relations `S`
equals the smallest additive congruence relation containing the binary relation 'there exists
`c ∈ S` such that `x` is related to `y` by `c`'. -/]
theorem sSup_eq_conGen (S : Set (Con M)) :
sSup S = conGen fun x y => ∃ c : Con M, c ∈ S ∧ c x y := by
rw [conGen_eq]
apply congr_arg sInf
ext
exact ⟨fun h _ _ ⟨r, hr⟩ => h hr.1 hr.2, fun h r hS _ _ hr => h _ _ ⟨r, hS, hr⟩⟩
/-- The supremum of a set of congruence relations is the same as the smallest congruence relation
containing the supremum of the set's image under the map to the underlying binary relation. -/
@[to_additive /-- The supremum of a set of additive congruence relations is the same as the smallest
additive congruence relation containing the supremum of the set's image under the map to the
underlying binary relation. -/]
theorem sSup_def {S : Set (Con M)} :
sSup S = conGen (sSup ((⇑) '' S)) := by
rw [sSup_eq_conGen, sSup_image]
congr with (x y)
simp only [iSup_apply, iSup_Prop_eq, exists_prop]
variable (M)
/-- There is a Galois insertion of congruence relations on a type with a multiplication `M` into
binary relations on `M`. -/
@[to_additive /-- There is a Galois insertion of additive congruence relations on a type with
an addition `M` into binary relations on `M`. -/]
protected def gi : @GaloisInsertion (M → M → Prop) (Con M) _ _ conGen DFunLike.coe where
choice r _ := conGen r
gc _ c := ⟨fun H _ _ h => H <| ConGen.Rel.of _ _ h, @fun H => conGen_of_con c ▸ conGen_mono H⟩
le_l_u x := (conGen_of_con x).symm ▸ le_refl x
choice_eq _ _ := rfl
variable {M} (c)
/-- Given types with multiplications `M, N` and a congruence relation `c` on `N`, a
multiplication-preserving map `f : M → N` induces a congruence relation on `f`'s domain
defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `c`.' -/
@[to_additive /-- Given types with additions `M, N` and an additive congruence relation `c` on `N`,
an addition-preserving map `f : M → N` induces an additive congruence relation on `f`'s domain
defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `c`.' -/]
def comap (f : M → N) (H : ∀ x y, f (x * y) = f x * f y) (c : Con N) : Con M :=
{ c.toSetoid.comap f with
mul' := @fun w x y z h1 h2 => show c (f (w * y)) (f (x * z)) by rw [H, H]; exact c.mul h1 h2 }
@[to_additive (attr := simp)]
theorem comap_rel {f : M → N} (H : ∀ x y, f (x * y) = f x * f y) {c : Con N} {x y : M} :
comap f H c x y ↔ c (f x) (f y) :=
Iff.rfl
section
open Quotient
end
end
section MulOneClass
variable [MulOneClass M] (c : Con M)
/-- The quotient of a monoid by a congruence relation is a monoid. -/
@[to_additive /-- The quotient of an `AddMonoid` by an additive congruence relation is
an `AddMonoid`. -/]
instance mulOneClass : MulOneClass c.Quotient where
one := ((1 : M) : c.Quotient)
mul_one x := Quotient.inductionOn' x fun _ => congr_arg ((↑) : M → c.Quotient) <| mul_one _
one_mul x := Quotient.inductionOn' x fun _ => congr_arg ((↑) : M → c.Quotient) <| one_mul _
variable {c}
/-- The 1 of the quotient of a monoid by a congruence relation is the equivalence class of the
monoid's 1. -/
@[to_additive (attr := simp) /-- The 0 of the quotient of an `AddMonoid` by an additive congruence
relation is the equivalence class of the `AddMonoid`'s 0. -/]
theorem coe_one : ((1 : M) : c.Quotient) = 1 :=
rfl
/-- There exists an element of the quotient of a monoid by a congruence relation (namely 1). -/
@[to_additive /-- There exists an element of the quotient of an `AddMonoid` by a congruence relation
(namely 0). -/]
instance Quotient.inhabited : Inhabited c.Quotient :=
⟨((1 : M) : c.Quotient)⟩
end MulOneClass
section Monoids
/-- Multiplicative congruence relations preserve natural powers. -/
@[to_additive /-- Additive congruence relations preserve natural scaling. -/]
protected theorem pow {M : Type*} [Monoid M] (c : Con M) :
∀ (n : ℕ) {w x}, c w x → c (w ^ n) (x ^ n)
| 0, w, x, _ => by simpa using c.refl _
| Nat.succ n, w, x, h => by simpa [pow_succ] using c.mul (Con.pow c n h) h
@[to_additive]
instance one [MulOneClass M] (c : Con M) : One c.Quotient where
-- Using Quotient.mk'' here instead of c.toQuotient
-- since c.toQuotient is not reducible.
-- This would lead to non-defeq diamonds since this instance ends up in
-- quotients modulo ideals.
one := Quotient.mk'' (1 : M)
-- one := ((1 : M) : c.Quotient)
instance _root_.AddCon.Quotient.nsmul {M : Type*} [AddMonoid M] (c : AddCon M) :
SMul ℕ c.Quotient where
smul n := (Quotient.map' (n • ·)) fun _ _ => c.nsmul n
@[to_additive existing AddCon.Quotient.nsmul]
instance {M : Type*} [Monoid M] (c : Con M) : Pow c.Quotient ℕ where
pow x n := Quotient.map' (fun x => x ^ n) (fun _ _ => c.pow n) x
/-- The quotient of a semigroup by a congruence relation is a semigroup. -/
@[to_additive /-- The quotient of an `AddSemigroup` by an additive congruence relation is
an `AddSemigroup`. -/]
instance semigroup {M : Type*} [Semigroup M] (c : Con M) : Semigroup c.Quotient := fast_instance%
Function.Surjective.semigroup _ Quotient.mk''_surjective fun _ _ => rfl
/-- The quotient of a commutative semigroup by a congruence relation is a semigroup. -/
@[to_additive /-- The quotient of an `AddCommSemigroup` by an additive congruence relation is
an `AddCommSemigroup`. -/]
instance commSemigroup {M : Type*} [CommSemigroup M] (c : Con M) : CommSemigroup c.Quotient :=
Function.Surjective.commSemigroup _ Quotient.mk''_surjective fun _ _ => rfl
/-- The quotient of a monoid by a congruence relation is a monoid. -/
@[to_additive /-- The quotient of an `AddMonoid` by an additive congruence relation is
an `AddMonoid`. -/]
instance monoid {M : Type*} [Monoid M] (c : Con M) : Monoid c.Quotient := fast_instance%
Function.Surjective.monoid _ Quotient.mk''_surjective rfl (fun _ _ => rfl) fun _ _ => rfl
/-- The quotient of a `CommMonoid` by a congruence relation is a `CommMonoid`. -/
@[to_additive /-- The quotient of an `AddCommMonoid` by an additive congruence
relation is an `AddCommMonoid`. -/]
instance commMonoid {M : Type*} [CommMonoid M] (c : Con M) : CommMonoid c.Quotient := fast_instance%
fast_instance% Function.Surjective.commMonoid _ Quotient.mk''_surjective rfl
(fun _ _ => rfl) fun _ _ => rfl
/-- Sometimes, a group is defined as a quotient of a monoid by a congruence relation.
Usually, the inverse operation is defined as `Setoid.map f _` for some `f`.
This lemma allows to avoid code duplication in the definition of the inverse operation:
instead of proving both `∀ x y, c x y → c (f x) (f y)` (to define the operation)
and `∀ x, c (f x * x) 1` (to prove the group laws), one can only prove the latter. -/
@[to_additive /-- Sometimes, an additive group is defined as a quotient of a monoid
by an additive congruence relation.
Usually, the inverse operation is defined as `Setoid.map f _` for some `f`.
This lemma allows to avoid code duplication in the definition of the inverse operation:
instead of proving both `∀ x y, c x y → c (f x) (f y)` (to define the operation)
and `∀ x, c (f x + x) 0` (to prove the group laws), one can only prove the latter. -/]
theorem map_of_mul_left_rel_one [Monoid M] (c : Con M)
(f : M → M) (hf : ∀ x, c (f x * x) 1) {x y} (h : c x y) : c (f x) (f y) := by
simp only [← Con.eq, coe_one, coe_mul] at *
have hf' : ∀ x : M, (x : c.Quotient) * f x = 1 := fun x ↦
calc
(x : c.Quotient) * f x = f (f x) * f x * (x * f x) := by simp [hf]
_ = f (f x) * (f x * x) * f x := by simp_rw [mul_assoc]
_ = 1 := by simp [hf]
have : (⟨_, _, hf' x, hf x⟩ : c.Quotientˣ) = ⟨_, _, hf' y, hf y⟩ := Units.ext h
exact congr_arg Units.inv this
end Monoids
section Groups
variable [Group M] (c : Con M)
/-- Multiplicative congruence relations preserve inversion. -/
@[to_additive /-- Additive congruence relations preserve negation. -/]
protected theorem inv {x y} (h : c x y) : c x⁻¹ y⁻¹ :=
c.map_of_mul_left_rel_one Inv.inv (fun x => by simp only [inv_mul_cancel, c.refl 1]) h
/-- Multiplicative congruence relations preserve division. -/
@[to_additive /-- Additive congruence relations preserve subtraction. -/]
protected theorem div : ∀ {w x y z}, c w x → c y z → c (w / y) (x / z) := @fun w x y z h1 h2 => by
simpa only [div_eq_mul_inv] using c.mul h1 (c.inv h2)
/-- Multiplicative congruence relations preserve integer powers. -/
@[to_additive /-- Additive congruence relations preserve integer scaling. -/]
protected theorem zpow : ∀ (n : ℤ) {w x}, c w x → c (w ^ n) (x ^ n)
| Int.ofNat n, w, x, h => by simpa only [zpow_natCast, Int.ofNat_eq_coe] using c.pow n h
| Int.negSucc n, w, x, h => by simpa only [zpow_negSucc] using c.inv (c.pow _ h)
/-- The inversion induced on the quotient by a congruence relation on a type with an
inversion. -/
@[to_additive /-- The negation induced on the quotient by an additive congruence relation on a type
with a negation. -/]
instance hasInv : Inv c.Quotient :=
⟨(Quotient.map' Inv.inv) fun _ _ => c.inv⟩
/-- The division induced on the quotient by a congruence relation on a type with a
division. -/
@[to_additive /-- The subtraction induced on the quotient by an additive congruence relation on a
type with a subtraction. -/]
instance hasDiv : Div c.Quotient :=
⟨(Quotient.map₂ (· / ·)) fun _ _ h₁ _ _ h₂ => c.div h₁ h₂⟩
/-- The integer scaling induced on the quotient by a congruence relation on a type with a
subtraction. -/
instance _root_.AddCon.Quotient.zsmul {M : Type*} [AddGroup M] (c : AddCon M) :
SMul ℤ c.Quotient :=
⟨fun z => (Quotient.map' (z • ·)) fun _ _ => c.zsmul z⟩
/-- The integer power induced on the quotient by a congruence relation on a type with a
division. -/
@[to_additive existing AddCon.Quotient.zsmul]
instance zpowinst : Pow c.Quotient ℤ :=
⟨fun x z => Quotient.map' (fun x => x ^ z) (fun _ _ h => c.zpow z h) x⟩
/-- The quotient of a group by a congruence relation is a group. -/
@[to_additive /-- The quotient of an `AddGroup` by an additive congruence relation is
an `AddGroup`. -/]
instance group : Group c.Quotient := fast_instance%
Function.Surjective.group Quotient.mk'' Quotient.mk''_surjective
rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl
/-- The quotient of a `CommGroup` by a congruence relation is a `CommGroup`. -/
@[to_additive /-- The quotient of an `AddCommGroup` by an additive congruence
relation is an `AddCommGroup`. -/]
instance commGroup {M : Type*} [CommGroup M] (c : Con M) : CommGroup c.Quotient := fast_instance%
Function.Surjective.commGroup _ Quotient.mk''_surjective rfl (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
end Groups
section Units
variable {α : Type*} [Monoid M] {c : Con M}
/-- In order to define a function `(Con.Quotient c)ˣ → α` on the units of `Con.Quotient c`,
where `c : Con M` is a multiplicative congruence on a monoid, it suffices to define a function `f`
that takes elements `x y : M` with proofs of `c (x * y) 1` and `c (y * x) 1`, and returns an element
of `α` provided that `f x y _ _ = f x' y' _ _` whenever `c x x'` and `c y y'`. -/
@[to_additive]
def liftOnUnits (u : Units c.Quotient) (f : ∀ x y : M, c (x * y) 1 → c (y * x) 1 → α)
(Hf : ∀ x y hxy hyx x' y' hxy' hyx',
c x x' → c y y' → f x y hxy hyx = f x' y' hxy' hyx') : α := by
refine
Con.hrecOn₂ (cN := c) (φ := fun x y => x * y = 1 → y * x = 1 → α) (u : c.Quotient)
(↑u⁻¹ : c.Quotient)
(fun (x y : M) (hxy : (x * y : c.Quotient) = 1) (hyx : (y * x : c.Quotient) = 1) =>
f x y (c.eq.1 hxy) (c.eq.1 hyx))
(fun x y x' y' hx hy => ?_) u.3 u.4
refine Function.hfunext ?_ ?_
· rw [c.eq.2 hx, c.eq.2 hy]
· rintro Hxy Hxy' -
refine Function.hfunext ?_ ?_
· rw [c.eq.2 hx, c.eq.2 hy]
· rintro Hyx Hyx' -
exact heq_of_eq (Hf _ _ _ _ _ _ _ _ hx hy)
/-- In order to define a function `(Con.Quotient c)ˣ → α` on the units of `Con.Quotient c`,
where `c : Con M` is a multiplicative congruence on a monoid, it suffices to define a function `f`
that takes elements `x y : M` with proofs of `c (x * y) 1` and `c (y * x) 1`, and returns an element
of `α` provided that `f x y _ _ = f x' y' _ _` whenever `c x x'` and `c y y'`. -/
add_decl_doc AddCon.liftOnAddUnits
@[to_additive (attr := simp)]
theorem liftOnUnits_mk (f : ∀ x y : M, c (x * y) 1 → c (y * x) 1 → α)
(Hf : ∀ x y hxy hyx x' y' hxy' hyx', c x x' → c y y' → f x y hxy hyx = f x' y' hxy' hyx')
(x y : M) (hxy hyx) :
liftOnUnits ⟨(x : c.Quotient), y, hxy, hyx⟩ f Hf = f x y (c.eq.1 hxy) (c.eq.1 hyx) :=
rfl
@[to_additive (attr := elab_as_elim)]
theorem induction_on_units {p : Units c.Quotient → Prop} (u : Units c.Quotient)
(H : ∀ (x y : M) (hxy : c (x * y) 1) (hyx : c (y * x) 1), p ⟨x, y, c.eq.2 hxy, c.eq.2 hyx⟩) :
p u := by
rcases u with ⟨⟨x⟩, ⟨y⟩, h₁, h₂⟩
exact H x y (c.eq.1 h₁) (c.eq.1 h₂)
end Units
end Con
|
LinearOrder.lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Batteries.Classes.Order
import Batteries.Tactic.Trans
import Mathlib.Data.Ordering.Basic
import Mathlib.Tactic.ExtendDoc
import Mathlib.Tactic.Lemma
import Mathlib.Tactic.SplitIfs
import Mathlib.Tactic.TypeStar
import Mathlib.Order.Defs.PartialOrder
/-!
# Orders
Defines classes for linear orders and proves some basic lemmas about them.
-/
variable {α : Type*}
section LinearOrder
/-!
### Definition of `LinearOrder` and lemmas about types with a linear order
-/
/-- Default definition of `max`. -/
def maxDefault [LE α] [DecidableLE α] (a b : α) :=
if a ≤ b then b else a
/-- Default definition of `min`. -/
def minDefault [LE α] [DecidableLE α] (a b : α) :=
if a ≤ b then a else b
/-- This attempts to prove that a given instance of `compare` is equal to `compareOfLessAndEq` by
introducing the arguments and trying the following approaches in order:
1. seeing if `rfl` works
2. seeing if the `compare` at hand is nonetheless essentially `compareOfLessAndEq`, but, because of
implicit arguments, requires us to unfold the defs and split the `if`s in the definition of
`compareOfLessAndEq`
3. seeing if we can split by cases on the arguments, then see if the defs work themselves out
(useful when `compare` is defined via a `match` statement, as it is for `Bool`) -/
macro "compareOfLessAndEq_rfl" : tactic =>
`(tactic| (intros a b; first | rfl |
(simp only [compare, compareOfLessAndEq]; split_ifs <;> rfl) |
(induction a <;> induction b <;> simp +decide only)))
/-- A linear order is reflexive, transitive, antisymmetric and total relation `≤`.
We assume that every linear ordered type has decidable `(≤)`, `(<)`, and `(=)`. -/
class LinearOrder (α : Type*) extends PartialOrder α, Min α, Max α, Ord α where
/-- A linear order is total. -/
le_total (a b : α) : a ≤ b ∨ b ≤ a
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
toDecidableLE : DecidableLE α
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
toDecidableEq : DecidableEq α := @decidableEqOfDecidableLE _ _ toDecidableLE
/-- In a linearly ordered type, we assume the order relations are all decidable. -/
toDecidableLT : DecidableLT α := @decidableLTOfDecidableLE _ _ toDecidableLE
min := fun a b => if a ≤ b then a else b
max := fun a b => if a ≤ b then b else a
/-- The minimum function is equivalent to the one you get from `minOfLe`. -/
min_def : ∀ a b, min a b = if a ≤ b then a else b := by intros; rfl
/-- The minimum function is equivalent to the one you get from `maxOfLe`. -/
max_def : ∀ a b, max a b = if a ≤ b then b else a := by intros; rfl
compare a b := compareOfLessAndEq a b
/-- Comparison via `compare` is equal to the canonical comparison given decidable `<` and `=`. -/
compare_eq_compareOfLessAndEq : ∀ a b, compare a b = compareOfLessAndEq a b := by
compareOfLessAndEq_rfl
variable [LinearOrder α] {a b c : α}
attribute [instance 900] LinearOrder.toDecidableLT
attribute [instance 900] LinearOrder.toDecidableLE
attribute [instance 900] LinearOrder.toDecidableEq
instance : Lean.Grind.LinearOrder α where
le_total := LinearOrder.le_total
lemma le_total : ∀ a b : α, a ≤ b ∨ b ≤ a := LinearOrder.le_total
lemma le_of_not_ge : ¬a ≤ b → b ≤ a := (le_total a b).resolve_left
lemma lt_of_not_ge (h : ¬b ≤ a) : a < b := lt_of_le_not_ge (le_of_not_ge h) h
@[deprecated (since := "2025-05-11")] alias le_of_not_le := le_of_not_ge
lemma lt_trichotomy (a b : α) : a < b ∨ a = b ∨ b < a :=
Or.elim (le_total a b)
(fun h : a ≤ b =>
Or.elim (Decidable.lt_or_eq_of_le h) (fun h : a < b => Or.inl h) fun h : a = b =>
Or.inr (Or.inl h))
fun h : b ≤ a =>
Or.elim (Decidable.lt_or_eq_of_le h) (fun h : b < a => Or.inr (Or.inr h)) fun h : b = a =>
Or.inr (Or.inl h.symm)
lemma le_of_not_gt (h : ¬b < a) : a ≤ b :=
match lt_trichotomy a b with
| Or.inl hlt => le_of_lt hlt
| Or.inr (Or.inl HEq) => HEq ▸ le_refl a
| Or.inr (Or.inr hgt) => absurd hgt h
@[deprecated (since := "2025-05-11")] alias le_of_not_lt := le_of_not_gt
lemma lt_or_ge (a b : α) : a < b ∨ b ≤ a :=
if hba : b ≤ a then Or.inr hba else Or.inl <| lt_of_not_ge hba
@[deprecated (since := "2025-05-11")] alias lt_or_le := lt_or_ge
lemma le_or_gt (a b : α) : a ≤ b ∨ b < a := (lt_or_ge b a).symm
@[deprecated (since := "2025-05-11")] alias le_or_lt := le_or_gt
lemma lt_or_gt_of_ne (h : a ≠ b) : a < b ∨ b < a := by simpa [h] using lt_trichotomy a b
lemma ne_iff_lt_or_gt : a ≠ b ↔ a < b ∨ b < a := ⟨lt_or_gt_of_ne, (Or.elim · ne_of_lt ne_of_gt)⟩
lemma lt_iff_not_ge : a < b ↔ ¬b ≤ a := ⟨not_le_of_gt, lt_of_not_ge⟩
@[simp] lemma not_lt : ¬a < b ↔ b ≤ a := ⟨le_of_not_gt, not_lt_of_ge⟩
@[simp] lemma not_le : ¬a ≤ b ↔ b < a := lt_iff_not_ge.symm
lemma eq_or_gt_of_not_lt (h : ¬a < b) : a = b ∨ b < a :=
if h₁ : a = b then Or.inl h₁ else Or.inr (lt_of_not_ge fun hge => h (lt_of_le_of_ne hge h₁))
@[deprecated (since := "2025-07-27")] alias eq_or_lt_of_not_gt := eq_or_gt_of_not_lt
@[deprecated (since := "2025-05-11")] alias eq_or_lt_of_not_lt := eq_or_gt_of_not_lt
/-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order. -/
@[deprecated lt_trichotomy (since := "2025-04-21")]
def ltByCases (x y : α) {P : Sort*} (h₁ : x < y → P) (h₂ : x = y → P) (h₃ : y < x → P) : P :=
if h : x < y then h₁ h
else if h' : y < x then h₃ h' else h₂ (le_antisymm (le_of_not_gt h') (le_of_not_gt h))
theorem le_imp_le_of_lt_imp_lt {α β} [Preorder α] [LinearOrder β] {a b : α} {c d : β}
(H : d < c → b < a) (h : a ≤ b) : c ≤ d :=
le_of_not_gt fun h' => not_le_of_gt (H h') h
lemma min_def (a b : α) : min a b = if a ≤ b then a else b := by rw [LinearOrder.min_def a]
lemma max_def (a b : α) : max a b = if a ≤ b then b else a := by rw [LinearOrder.max_def a]
lemma min_le_left (a b : α) : min a b ≤ a := by
if h : a ≤ b
then simp [min_def, if_pos h, le_refl]
else simpa [min_def, if_neg h] using le_of_not_ge h
lemma min_le_right (a b : α) : min a b ≤ b := by
if h : a ≤ b
then simpa [min_def, if_pos h] using h
else simp [min_def, if_neg h, le_refl]
lemma le_min (h₁ : c ≤ a) (h₂ : c ≤ b) : c ≤ min a b := by
if h : a ≤ b
then simpa [min_def, if_pos h] using h₁
else simpa [min_def, if_neg h] using h₂
lemma le_max_left (a b : α) : a ≤ max a b := by
if h : a ≤ b
then simpa [max_def, if_pos h] using h
else simp [max_def, if_neg h, le_refl]
lemma le_max_right (a b : α) : b ≤ max a b := by
if h : a ≤ b
then simp [max_def, if_pos h, le_refl]
else simpa [max_def, if_neg h] using le_of_not_ge h
lemma max_le (h₁ : a ≤ c) (h₂ : b ≤ c) : max a b ≤ c := by
if h : a ≤ b
then simpa [max_def, if_pos h] using h₂
else simpa [max_def, if_neg h] using h₁
lemma eq_min (h₁ : c ≤ a) (h₂ : c ≤ b) (h₃ : ∀ {d}, d ≤ a → d ≤ b → d ≤ c) : c = min a b :=
le_antisymm (le_min h₁ h₂) (h₃ (min_le_left a b) (min_le_right a b))
lemma min_comm (a b : α) : min a b = min b a :=
eq_min (min_le_right a b) (min_le_left a b) fun h₁ h₂ => le_min h₂ h₁
lemma min_assoc (a b c : α) : min (min a b) c = min a (min b c) := by
apply eq_min
· apply le_trans (min_le_left ..) (min_le_left ..)
· apply le_min
· apply le_trans (min_le_left ..) (min_le_right ..)
· apply min_le_right
· intro d h₁ h₂; apply le_min
· apply le_min h₁; apply le_trans h₂; apply min_le_left
· apply le_trans h₂; apply min_le_right
lemma min_left_comm (a b c : α) : min a (min b c) = min b (min a c) := by
rw [← min_assoc, min_comm a, min_assoc]
@[simp] lemma min_self (a : α) : min a a = a := by simp [min_def]
lemma min_eq_left (h : a ≤ b) : min a b = a := by
apply Eq.symm; apply eq_min (le_refl _) h; intros; assumption
lemma min_eq_right (h : b ≤ a) : min a b = b := min_comm b a ▸ min_eq_left h
lemma eq_max (h₁ : a ≤ c) (h₂ : b ≤ c) (h₃ : ∀ {d}, a ≤ d → b ≤ d → c ≤ d) :
c = max a b :=
le_antisymm (h₃ (le_max_left a b) (le_max_right a b)) (max_le h₁ h₂)
lemma max_comm (a b : α) : max a b = max b a :=
eq_max (le_max_right a b) (le_max_left a b) fun h₁ h₂ => max_le h₂ h₁
lemma max_assoc (a b c : α) : max (max a b) c = max a (max b c) := by
apply eq_max
· apply le_trans (le_max_left a b) (le_max_left ..)
· apply max_le
· apply le_trans (le_max_right a b) (le_max_left ..)
· apply le_max_right
· intro d h₁ h₂; apply max_le
· apply max_le h₁; apply le_trans (le_max_left _ _) h₂
· apply le_trans (le_max_right _ _) h₂
lemma max_left_comm (a b c : α) : max a (max b c) = max b (max a c) := by
rw [← max_assoc, max_comm a, max_assoc]
@[simp] lemma max_self (a : α) : max a a = a := by simp [max_def]
lemma max_eq_left (h : b ≤ a) : max a b = a := by
apply Eq.symm; apply eq_max (le_refl _) h; intros; assumption
lemma max_eq_right (h : a ≤ b) : max a b = b := max_comm b a ▸ max_eq_left h
lemma min_eq_left_of_lt (h : a < b) : min a b = a := min_eq_left (le_of_lt h)
lemma min_eq_right_of_lt (h : b < a) : min a b = b := min_eq_right (le_of_lt h)
lemma max_eq_left_of_lt (h : b < a) : max a b = a := max_eq_left (le_of_lt h)
lemma max_eq_right_of_lt (h : a < b) : max a b = b := max_eq_right (le_of_lt h)
lemma lt_min (h₁ : a < b) (h₂ : a < c) : a < min b c := by
cases le_total b c <;> simp [min_eq_left, min_eq_right, *]
lemma max_lt (h₁ : a < c) (h₂ : b < c) : max a b < c := by
cases le_total a b <;> simp [max_eq_left, max_eq_right, *]
section Ord
lemma compare_lt_iff_lt : compare a b = .lt ↔ a < b := by
rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq]
split_ifs <;> simp only [*, lt_irrefl]
lemma compare_gt_iff_gt : compare a b = .gt ↔ b < a := by
rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq]
split_ifs <;> simp only [*, lt_irrefl, not_lt_of_gt]
case _ h₁ h₂ =>
have h : b < a := lt_trichotomy a b |>.resolve_left h₁ |>.resolve_left h₂
rwa [true_iff]
lemma compare_eq_iff_eq : compare a b = .eq ↔ a = b := by
rw [LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq]
split_ifs <;> try simp only
case _ h => rw [false_iff]; exact ne_iff_lt_or_gt.2 <| .inl h
case _ _ h => rwa [true_iff]
case _ _ h => rwa [false_iff]
lemma compare_le_iff_le : compare a b ≠ .gt ↔ a ≤ b := by
cases h : compare a b <;> simp
· exact le_of_lt <| compare_lt_iff_lt.1 h
· exact le_of_eq <| compare_eq_iff_eq.1 h
· exact compare_gt_iff_gt.1 h
lemma compare_ge_iff_ge : compare a b ≠ .lt ↔ b ≤ a := by
cases h : compare a b <;> simp
· exact compare_lt_iff_lt.1 h
· exact le_of_eq <| (·.symm) <| compare_eq_iff_eq.1 h
· exact le_of_lt <| compare_gt_iff_gt.1 h
lemma compare_iff (a b : α) {o : Ordering} : compare a b = o ↔ o.Compares a b := by
cases o <;> simp only [Ordering.Compares]
· exact compare_lt_iff_lt
· exact compare_eq_iff_eq
· exact compare_gt_iff_gt
theorem cmp_eq_compare (a b : α) : cmp a b = compare a b := by
refine ((compare_iff ..).2 ?_).symm
unfold cmp cmpUsing; split_ifs with h1 h2
· exact h1
· exact h2
· exact le_antisymm (not_lt.1 h2) (not_lt.1 h1)
theorem cmp_eq_compareOfLessAndEq (a b : α) : cmp a b = compareOfLessAndEq a b :=
(cmp_eq_compare ..).trans (LinearOrder.compare_eq_compareOfLessAndEq ..)
instance : Std.LawfulBCmp (compare (α := α)) where
eq_swap {a b} := by
cases _ : compare b a <;>
simp_all [Ordering.swap, compare_eq_iff_eq, compare_lt_iff_lt, compare_gt_iff_gt]
isLE_trans h₁ h₂ := by
simp only [← Ordering.ne_gt_iff_isLE, compare_le_iff_le] at *
exact le_trans h₁ h₂
compare_eq_iff_beq := by simp [compare_eq_iff_eq]
eq_lt_iff_lt := by simp [compare_lt_iff_lt]
isLE_iff_le := by simp [← Ordering.ne_gt_iff_isLE, compare_le_iff_le]
end Ord
end LinearOrder
|
Defs.lean
|
/-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.Data.Nat.Notation
import Mathlib.Control.Functor
import Mathlib.Data.SProd
import Mathlib.Util.CompileInductive
import Batteries.Tactic.Lint.Basic
import Batteries.Data.List.Lemmas
import Batteries.Logic
/-!
## Definitions on lists
This file contains various definitions on lists. It does not contain
proofs about these definitions, those are contained in other files in `Data.List`
-/
namespace List
open Function Nat
universe u v w x
variable {α β γ δ ε ζ : Type*}
instance [DecidableEq α] : SDiff (List α) :=
⟨List.diff⟩
/-- "Inhabited" `get` function: returns `default` instead of `none` in the case
that the index is out of bounds. -/
def getI [Inhabited α] (l : List α) (n : Nat) : α :=
getD l n default
/-- The head of a list, or the default element of the type is the list is `nil`. -/
def headI [Inhabited α] : List α → α
| [] => default
| (a :: _) => a
@[simp] theorem headI_nil [Inhabited α] : ([] : List α).headI = default := rfl
@[simp] theorem headI_cons [Inhabited α] {h : α} {t : List α} : (h :: t).headI = h := rfl
/-- The last element of a list, with the default if list empty -/
def getLastI [Inhabited α] : List α → α
| [] => default
| [a] => a
| [_, b] => b
| _ :: _ :: l => getLastI l
/-- "Inhabited" `take` function: Take `n` elements from a list `l`. If `l` has less than `n`
elements, append `n - length l` elements `default`. -/
def takeI [Inhabited α] (n : Nat) (l : List α) : List α :=
takeD n l default
/-- `findM tac l` returns the first element of `l` on which `tac` succeeds, and
fails otherwise. -/
def findM {α} {m : Type u → Type v} [Alternative m] (tac : α → m PUnit) : List α → m α :=
List.firstM fun a => (tac a) $> a
/-- `findM? p l` returns the first element `a` of `l` for which `p a` returns
true. `findM?` short-circuits, so `p` is not necessarily run on every `a` in
`l`. This is a monadic version of `List.find`. -/
def findM?'
{m : Type u → Type v}
[Monad m] {α : Type u}
(p : α → m (ULift Bool)) : List α → m (Option α)
| [] => pure none
| x :: xs => do
let ⟨px⟩ ← p x
if px then pure (some x) else findM?' p xs
section
variable {m : Type → Type v} [Monad m]
/-- `orM xs` runs the actions in `xs`, returning true if any of them returns
true. `orM` short-circuits, so if an action returns true, later actions are
not run. -/
def orM : List (m Bool) → m Bool :=
anyM id
/-- `andM xs` runs the actions in `xs`, returning true if all of them return
true. `andM` short-circuits, so if an action returns false, later actions are
not run. -/
def andM : List (m Bool) → m Bool :=
allM id
end
section foldIdxM
variable {m : Type v → Type w} [Monad m]
/-- Monadic variant of `foldlIdx`. -/
def foldlIdxM {α β} (f : ℕ → β → α → m β) (b : β) (as : List α) : m β :=
as.foldlIdx
(fun i ma b => do
let a ← ma
f i a b)
(pure b)
/-- Monadic variant of `foldrIdx`. -/
def foldrIdxM {α β} (f : ℕ → α → β → m β) (b : β) (as : List α) : m β :=
as.foldrIdx
(fun i a mb => do
let b ← mb
f i a b)
(pure b)
end foldIdxM
section mapIdxM
variable {m : Type v → Type w} [Monad m]
/-- Auxiliary definition for `mapIdxM'`. -/
def mapIdxMAux' {α} (f : ℕ → α → m PUnit) : ℕ → List α → m PUnit
| _, [] => pure ⟨⟩
| i, a :: as => f i a *> mapIdxMAux' f (i + 1) as
/-- A variant of `mapIdxM` specialised to applicative actions which
return `Unit`. -/
def mapIdxM' {α} (f : ℕ → α → m PUnit) (as : List α) : m PUnit :=
mapIdxMAux' f 0 as
end mapIdxM
/-- `l.Forall p` is equivalent to `∀ a ∈ l, p a`, but unfolds directly to a conjunction, i.e.
`List.Forall p [0, 1, 2] = p 0 ∧ p 1 ∧ p 2`. -/
@[simp]
def Forall (p : α → Prop) : List α → Prop
| [] => True
| x :: [] => p x
| x :: l => p x ∧ Forall p l
section Permutations
/-- An auxiliary function for defining `permutations`. `permutationsAux2 t ts r ys f` is equal to
`(ys ++ ts, (insert_left ys t ts).map f ++ r)`, where `insert_left ys t ts` (not explicitly
defined) is the list of lists of the form `insert_nth n t (ys ++ ts)` for `0 ≤ n < length ys`.
permutations_aux2 10 [4, 5, 6] [] [1, 2, 3] id =
([1, 2, 3, 4, 5, 6],
[[10, 1, 2, 3, 4, 5, 6],
[1, 10, 2, 3, 4, 5, 6],
[1, 2, 10, 3, 4, 5, 6]]) -/
def permutationsAux2 (t : α) (ts : List α) (r : List β) : List α → (List α → β) → List α × List β
| [], _ => (ts, r)
| y :: ys, f =>
let (us, zs) := permutationsAux2 t ts r ys (fun x : List α => f (y :: x))
(y :: us, f (t :: y :: us) :: zs)
/-- A recursor for pairs of lists. To have `C l₁ l₂` for all `l₁`, `l₂`, it suffices to have it for
`l₂ = []` and to be able to pour the elements of `l₁` into `l₂`. -/
@[elab_as_elim]
def permutationsAux.rec {C : List α → List α → Sort v} (H0 : ∀ is, C [] is)
(H1 : ∀ t ts is, C ts (t :: is) → C is [] → C (t :: ts) is) : ∀ l₁ l₂, C l₁ l₂
| [], is => H0 is
| t :: ts, is =>
H1 t ts is (permutationsAux.rec H0 H1 ts (t :: is)) (permutationsAux.rec H0 H1 is [])
termination_by ts is => (length ts + length is, length ts)
decreasing_by all_goals (simp_wf; omega)
/-- An auxiliary function for defining `permutations`. `permutationsAux ts is` is the set of all
permutations of `is ++ ts` that do not fix `ts`. -/
def permutationsAux : List α → List α → List (List α) :=
permutationsAux.rec (fun _ => []) fun t ts is IH1 IH2 =>
foldr (fun y r => (permutationsAux2 t ts r y id).2) IH1 (is :: IH2)
/-- List of all permutations of `l`.
permutations [1, 2, 3] =
[[1, 2, 3], [2, 1, 3], [3, 2, 1],
[2, 3, 1], [3, 1, 2], [1, 3, 2]] -/
def permutations (l : List α) : List (List α) :=
l :: permutationsAux l []
/-- `permutations'Aux t ts` inserts `t` into every position in `ts`, including the last.
This function is intended for use in specifications, so it is simpler than `permutationsAux2`,
which plays roughly the same role in `permutations`.
Note that `(permutationsAux2 t [] [] ts id).2` is similar to this function, but skips the last
position:
permutations'Aux 10 [1, 2, 3] =
[[10, 1, 2, 3], [1, 10, 2, 3], [1, 2, 10, 3], [1, 2, 3, 10]]
(permutationsAux2 10 [] [] [1, 2, 3] id).2 =
[[10, 1, 2, 3], [1, 10, 2, 3], [1, 2, 10, 3]] -/
@[simp]
def permutations'Aux (t : α) : List α → List (List α)
| [] => [[t]]
| y :: ys => (t :: y :: ys) :: (permutations'Aux t ys).map (cons y)
/-- List of all permutations of `l`. This version of `permutations` is less efficient but has
simpler definitional equations. The permutations are in a different order,
but are equal up to permutation, as shown by `List.permutations_perm_permutations'`.
permutations [1, 2, 3] =
[[1, 2, 3], [2, 1, 3], [2, 3, 1],
[1, 3, 2], [3, 1, 2], [3, 2, 1]] -/
@[simp]
def permutations' : List α → List (List α)
| [] => [[]]
| t :: ts => (permutations' ts).flatMap <| permutations'Aux t
end Permutations
/-- `extractp p l` returns a pair of an element `a` of `l` satisfying the predicate
`p`, and `l`, with `a` removed. If there is no such element `a` it returns `(none, l)`. -/
def extractp (p : α → Prop) [DecidablePred p] : List α → Option α × List α
| [] => (none, [])
| a :: l =>
if p a then (some a, l)
else
let (a', l') := extractp p l
(a', a :: l')
/-- Notation for calculating the product of a `List` -/
instance instSProd : SProd (List α) (List β) (List (α × β)) where
sprod := List.product
section Chain
instance decidableChain {R : α → α → Prop} [DecidableRel R] (a : α) (l : List α) :
Decidable (Chain R a l) := by
induction l generalizing a with
| nil => exact decidable_of_decidable_of_iff (p := True) (by simp)
| cons b as ih =>
haveI := ih; exact decidable_of_decidable_of_iff (p := (R a b ∧ Chain R b as)) (by simp)
instance decidableChain' {R : α → α → Prop} [DecidableRel R] (l : List α) :
Decidable (Chain' R l) := by
cases l
· exact inferInstanceAs (Decidable True)
· exact inferInstanceAs (Decidable (Chain _ _ _))
end Chain
/-- `dedup l` removes duplicates from `l` (taking only the last occurrence).
Defined as `pwFilter (≠)`.
dedup [1, 0, 2, 2, 1] = [0, 2, 1] -/
def dedup [DecidableEq α] : List α → List α :=
pwFilter (· ≠ ·)
/-- Greedily create a sublist of `a :: l` such that, for every two adjacent elements `a, b`,
`R a b` holds. Mostly used with ≠; for example, `destutter' (≠) 1 [2, 2, 1, 1] = [1, 2, 1]`,
`destutter' (≠) 1, [2, 3, 3] = [1, 2, 3]`, `destutter' (<) 1 [2, 5, 2, 3, 4, 9] = [1, 2, 5, 9]`. -/
def destutter' (R : α → α → Prop) [DecidableRel R] : α → List α → List α
| a, [] => [a]
| a, h :: l => if R a h then a :: destutter' R h l else destutter' R a l
-- TODO: should below be "lazily"?
/-- Greedily create a sublist of `l` such that, for every two adjacent elements `a, b ∈ l`,
`R a b` holds. Mostly used with ≠; for example, `destutter (≠) [1, 2, 2, 1, 1] = [1, 2, 1]`,
`destutter (≠) [1, 2, 3, 3] = [1, 2, 3]`, `destutter (<) [1, 2, 5, 2, 3, 4, 9] = [1, 2, 5, 9]`. -/
def destutter (R : α → α → Prop) [DecidableRel R] : List α → List α
| h :: l => destutter' R h l
| [] => []
section Choose
variable (p : α → Prop) [DecidablePred p] (l : List α)
/-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`,
choose the first element with this property. This version returns both `a` and proofs
of `a ∈ l` and `p a`. -/
def chooseX : ∀ l : List α, ∀ _ : ∃ a, a ∈ l ∧ p a, { a // a ∈ l ∧ p a }
| [], hp => False.elim (Exists.elim hp fun _ h => not_mem_nil h.left)
| l :: ls, hp =>
if pl : p l then ⟨l, ⟨mem_cons.mpr <| Or.inl rfl, pl⟩⟩
else
-- pattern matching on `hx` too makes this not reducible!
let ⟨a, ha⟩ :=
chooseX ls
(hp.imp fun _ ⟨o, h₂⟩ => ⟨(mem_cons.mp o).resolve_left fun e => pl <| e ▸ h₂, h₂⟩)
⟨a, mem_cons.mpr <| Or.inr ha.1, ha.2⟩
/-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`,
choose the first element with this property. This version returns `a : α`, and properties
are given by `choose_mem` and `choose_property`. -/
def choose (hp : ∃ a, a ∈ l ∧ p a) : α :=
chooseX p l hp
end Choose
/-- `mapDiagM' f l` calls `f` on all elements in the upper triangular part of `l × l`.
That is, for each `e ∈ l`, it will run `f e e` and then `f e e'`
for each `e'` that appears after `e` in `l`.
Example: suppose `l = [1, 2, 3]`. `mapDiagM' f l` will evaluate, in this order,
`f 1 1`, `f 1 2`, `f 1 3`, `f 2 2`, `f 2 3`, `f 3 3`.
-/
def mapDiagM' {m} [Monad m] {α} (f : α → α → m Unit) : List α → m Unit
| [] => return ()
| h :: t => do
_ ← f h h
_ ← t.mapM' (f h)
t.mapDiagM' f
-- as ported:
-- | [] => return ()
-- | h :: t => (f h h >> t.mapM' (f h)) >> t.mapDiagM'
/-- Left-biased version of `List.map₂`. `map₂Left' f as bs` applies `f` to each
pair of elements `aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, `f` is
applied to `none` for the remaining `aᵢ`. Returns the results of the `f`
applications and the remaining `bs`.
```
map₂Left' prod.mk [1, 2] ['a'] = ([(1, some 'a'), (2, none)], [])
map₂Left' prod.mk [1] ['a', 'b'] = ([(1, some 'a')], ['b'])
```
-/
@[simp]
def map₂Left' (f : α → Option β → γ) : List α → List β → List γ × List β
| [], bs => ([], bs)
| a :: as, [] => ((a :: as).map fun a => f a none, [])
| a :: as, b :: bs =>
let rec' := map₂Left' f as bs
(f a (some b) :: rec'.fst, rec'.snd)
/-- Right-biased version of `List.map₂`. `map₂Right' f as bs` applies `f` to each
pair of elements `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, `f` is
applied to `none` for the remaining `bᵢ`. Returns the results of the `f`
applications and the remaining `as`.
```
map₂Right' prod.mk [1] ['a', 'b'] = ([(some 1, 'a'), (none, 'b')], [])
map₂Right' prod.mk [1, 2] ['a'] = ([(some 1, 'a')], [2])
```
-/
def map₂Right' (f : Option α → β → γ) (as : List α) (bs : List β) : List γ × List α :=
map₂Left' (flip f) bs as
/-- Left-biased version of `List.map₂`. `map₂Left f as bs` applies `f` to each pair
`aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, `f` is applied to `none`
for the remaining `aᵢ`.
```
map₂Left Prod.mk [1, 2] ['a'] = [(1, some 'a'), (2, none)]
map₂Left Prod.mk [1] ['a', 'b'] = [(1, some 'a')]
map₂Left f as bs = (map₂Left' f as bs).fst
```
-/
@[simp]
def map₂Left (f : α → Option β → γ) : List α → List β → List γ
| [], _ => []
| a :: as, [] => (a :: as).map fun a => f a none
| a :: as, b :: bs => f a (some b) :: map₂Left f as bs
/-- Right-biased version of `List.map₂`. `map₂Right f as bs` applies `f` to each
pair `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, `f` is applied to
`none` for the remaining `bᵢ`.
```
map₂Right Prod.mk [1, 2] ['a'] = [(some 1, 'a')]
map₂Right Prod.mk [1] ['a', 'b'] = [(some 1, 'a'), (none, 'b')]
map₂Right f as bs = (map₂Right' f as bs).fst
```
-/
def map₂Right (f : Option α → β → γ) (as : List α) (bs : List β) : List γ :=
map₂Left (flip f) bs as
-- TODO: naming is awkward...
/-- Asynchronous version of `List.map`.
-/
def mapAsyncChunked {α β} (f : α → β) (xs : List α) (chunk_size := 1024) : List β :=
((xs.toChunks chunk_size).map fun xs => Task.spawn fun _ => List.map f xs).flatMap Task.get
/-!
We add some n-ary versions of `List.zipWith` for functions with more than two arguments.
These can also be written in terms of `List.zip` or `List.zipWith`.
For example, `zipWith3 f xs ys zs` could also be written as
`zipWith id (zipWith f xs ys) zs`
or as
`(zip xs <| zip ys zs).map <| fun ⟨x, y, z⟩ ↦ f x y z`.
-/
/-- Ternary version of `List.zipWith`. -/
def zipWith3 (f : α → β → γ → δ) : List α → List β → List γ → List δ
| x :: xs, y :: ys, z :: zs => f x y z :: zipWith3 f xs ys zs
| _, _, _ => []
/-- Quaternary version of `list.zipWith`. -/
def zipWith4 (f : α → β → γ → δ → ε) : List α → List β → List γ → List δ → List ε
| x :: xs, y :: ys, z :: zs, u :: us => f x y z u :: zipWith4 f xs ys zs us
| _, _, _, _ => []
/-- Quinary version of `list.zipWith`. -/
def zipWith5 (f : α → β → γ → δ → ε → ζ) : List α → List β → List γ → List δ → List ε → List ζ
| x :: xs, y :: ys, z :: zs, u :: us, v :: vs => f x y z u v :: zipWith5 f xs ys zs us vs
| _, _, _, _, _ => []
/-- Given a starting list `old`, a list of booleans and a replacement list `new`,
read the items in `old` in succession and either replace them with the next element of `new` or
not, according as to whether the corresponding boolean is `true` or `false`. -/
def replaceIf : List α → List Bool → List α → List α
| l, _, [] => l
| [], _, _ => []
| l, [], _ => l
| n :: ns, tf :: bs, e@(c :: cs) => if tf then c :: ns.replaceIf bs cs else n :: ns.replaceIf bs e
/-- `iterate f a n` is `[a, f a, ..., f^[n - 1] a]`. -/
@[simp]
def iterate (f : α → α) (a : α) : (n : ℕ) → List α
| 0 => []
| n + 1 => a :: iterate f (f a) n
/-- Tail-recursive version of `List.iterate`. -/
@[inline]
def iterateTR (f : α → α) (a : α) (n : ℕ) : List α :=
loop a n []
where
/-- `iterateTR.loop f a n l := iterate f a n ++ reverse l`. -/
@[simp, specialize]
loop (a : α) (n : ℕ) (l : List α) : List α :=
match n with
| 0 => reverse l
| n + 1 => loop (f a) n (a :: l)
theorem iterateTR_loop_eq (f : α → α) (a : α) (n : ℕ) (l : List α) :
iterateTR.loop f a n l = reverse l ++ iterate f a n := by
induction n generalizing a l <;> simp [*]
@[csimp]
theorem iterate_eq_iterateTR : @iterate = @iterateTR := by
funext α f a n
exact Eq.symm <| iterateTR_loop_eq f a n []
section MapAccumr
/-- Runs a function over a list returning the intermediate results and a final result. -/
def mapAccumr (f : α → γ → γ × β) : List α → γ → γ × List β
| [], c => (c, [])
| y :: yr, c =>
let r := mapAccumr f yr c
let z := f y r.1
(z.1, z.2 :: r.2)
/-- Length of the list obtained by `mapAccumr`. -/
@[simp]
theorem length_mapAccumr :
∀ (f : α → γ → γ × β) (x : List α) (s : γ), length (mapAccumr f x s).2 = length x
| f, _ :: x, s => congr_arg succ (length_mapAccumr f x s)
| _, [], _ => rfl
/-- Runs a function over two lists returning the intermediate results and a final result. -/
def mapAccumr₂ (f : α → β → γ → γ × δ) : List α → List β → γ → γ × List δ
| [], _, c => (c, [])
| _, [], c => (c, [])
| x :: xr, y :: yr, c =>
let r := mapAccumr₂ f xr yr c
let q := f x y r.1
(q.1, q.2 :: r.2)
/-- Length of a list obtained using `mapAccumr₂`. -/
@[simp]
theorem length_mapAccumr₂ :
∀ (f : α → β → γ → γ × δ) (x y c), length (mapAccumr₂ f x y c).2 = min (length x) (length y)
| f, _ :: x, _ :: y, c =>
calc
succ (length (mapAccumr₂ f x y c).2) = succ (min (length x) (length y)) :=
congr_arg succ (length_mapAccumr₂ f x y c)
_ = min (succ (length x)) (succ (length y)) := Eq.symm (succ_min_succ (length x) (length y))
| _, _ :: _, [], _ => rfl
| _, [], _ :: _, _ => rfl
| _, [], [], _ => rfl
end MapAccumr
end List
|
Powerset.lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finset.Card
import Mathlib.Data.Finset.Lattice.Union
import Mathlib.Data.Multiset.Powerset
import Mathlib.Data.Set.Pairwise.Lattice
/-!
# The powerset of a finset
-/
namespace Finset
open Function Multiset
variable {α : Type*} {s t : Finset α}
/-! ### powerset -/
section Powerset
/-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/
def powerset (s : Finset α) : Finset (Finset α) :=
⟨(s.1.powerset.pmap Finset.mk) fun _t h => nodup_of_le (mem_powerset.1 h) s.nodup,
s.nodup.powerset.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩
@[simp, grind =]
theorem mem_powerset {s t : Finset α} : s ∈ powerset t ↔ s ⊆ t := by
cases s
simp [powerset, mem_mk, mem_pmap, mk.injEq, exists_prop, exists_eq_right,
← val_le_iff]
@[simp, norm_cast]
theorem coe_powerset (s : Finset α) :
(s.powerset : Set (Finset α)) = ((↑) : Finset α → Set α) ⁻¹' (s : Set α).powerset := by
ext
simp
theorem empty_mem_powerset (s : Finset α) : ∅ ∈ powerset s := by simp
theorem mem_powerset_self (s : Finset α) : s ∈ powerset s := by simp
@[aesop safe apply (rule_sets := [finsetNonempty])]
theorem powerset_nonempty (s : Finset α) : s.powerset.Nonempty :=
⟨∅, empty_mem_powerset _⟩
@[simp]
theorem powerset_mono {s t : Finset α} : powerset s ⊆ powerset t ↔ s ⊆ t :=
⟨fun h => mem_powerset.1 <| h <| mem_powerset_self _, fun st _u h =>
mem_powerset.2 <| Subset.trans (mem_powerset.1 h) st⟩
theorem powerset_injective : Injective (powerset : Finset α → Finset (Finset α)) :=
(injective_of_le_imp_le _) powerset_mono.1
@[simp]
theorem powerset_inj : powerset s = powerset t ↔ s = t :=
powerset_injective.eq_iff
@[simp]
theorem powerset_empty : (∅ : Finset α).powerset = {∅} :=
rfl
@[simp]
theorem powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ := by
rw [← powerset_empty, powerset_inj]
/-- **Number of Subsets of a Set** -/
@[simp]
theorem card_powerset (s : Finset α) : card (powerset s) = 2 ^ card s :=
(card_pmap _ _ _).trans (Multiset.card_powerset s.1)
theorem notMem_of_mem_powerset_of_notMem {s t : Finset α} {a : α} (ht : t ∈ s.powerset)
(h : a ∉ s) : a ∉ t := by
apply mt _ h
apply mem_powerset.1 ht
@[deprecated (since := "2025-05-23")]
alias not_mem_of_mem_powerset_of_not_mem := notMem_of_mem_powerset_of_notMem
theorem powerset_insert [DecidableEq α] (s : Finset α) (a : α) :
powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) := by
ext t
simp only [mem_powerset, mem_image, mem_union, subset_insert_iff]
by_cases h : a ∈ t
· constructor
· exact fun H => Or.inr ⟨_, H, insert_erase h⟩
· intro H
rcases H with H | H
· exact Subset.trans (erase_subset a t) H
· rcases H with ⟨u, hu⟩
rw [← hu.2]
exact Subset.trans (erase_insert_subset a u) hu.1
· have : ¬∃ u : Finset α, u ⊆ s ∧ insert a u = t := by simp [Ne.symm (ne_insert_of_notMem _ _ h)]
simp [Finset.erase_eq_of_notMem h, this]
lemma pairwiseDisjoint_pair_insert [DecidableEq α] {a : α} (ha : a ∉ s) :
(s.powerset : Set (Finset α)).PairwiseDisjoint fun t ↦ ({t, insert a t} : Set (Finset α)) := by
simp_rw [Set.pairwiseDisjoint_iff, mem_coe, mem_powerset]
rintro i hi j hj
simp only [Set.Nonempty, Set.mem_inter_iff, Set.mem_insert_iff, Set.mem_singleton_iff,
exists_eq_or_imp, exists_eq_left, or_imp, imp_self, true_and]
refine ⟨?_, ?_, insert_erase_invOn.2.injOn (notMem_mono hi ha) (notMem_mono hj ha)⟩ <;>
rintro rfl <;>
cases Finset.notMem_mono ‹_› ha (Finset.mem_insert_self _ _)
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidableExistsOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop}
[∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∃ (t : _) (h : t ⊆ s), p t h) :=
decidable_of_iff (∃ (t : _) (hs : t ∈ s.powerset), p t (mem_powerset.1 hs))
⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_powerset.2 hs, hp⟩⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidableForallOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop}
[∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∀ (t) (h : t ⊆ s), p t h) :=
decidable_of_iff (∀ (t) (h : t ∈ s.powerset), p t (mem_powerset.1 h))
⟨fun h t hs => h t (mem_powerset.2 hs), fun h _ _ => h _ _⟩
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/
instance decidableExistsOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop}
[∀ t, Decidable (p t)] : Decidable (∃ t ⊆ s, p t) :=
decidable_of_iff (∃ (t : _) (_h : t ⊆ s), p t) <| by simp
/-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/
instance decidableForallOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop}
[∀ t, Decidable (p t)] : Decidable (∀ t ⊆ s, p t) :=
decidable_of_iff (∀ (t : _) (_h : t ⊆ s), p t) <| by simp
end Powerset
section SSubsets
variable [DecidableEq α]
/-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/
def ssubsets (s : Finset α) : Finset (Finset α) :=
erase (powerset s) s
@[simp, grind =]
theorem mem_ssubsets {s t : Finset α} : t ∈ s.ssubsets ↔ t ⊂ s := by
rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and_comm]
theorem empty_mem_ssubsets {s : Finset α} (h : s.Nonempty) : ∅ ∈ s.ssubsets := by
rw [mem_ssubsets, ssubset_iff_subset_ne]
exact ⟨empty_subset s, h.ne_empty.symm⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/
def decidableExistsOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop}
[∀ t h, Decidable (p t h)] : Decidable (∃ t h, p t h) :=
decidable_of_iff (∃ (t : _) (hs : t ∈ s.ssubsets), p t (mem_ssubsets.1 hs))
⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_ssubsets.2 hs, hp⟩⟩
/-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/
def decidableForallOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop}
[∀ t h, Decidable (p t h)] : Decidable (∀ t h, p t h) :=
decidable_of_iff (∀ (t) (h : t ∈ s.ssubsets), p t (mem_ssubsets.1 h))
⟨fun h t hs => h t (mem_ssubsets.2 hs), fun h _ _ => h _ _⟩
/-- A version of `Finset.decidableExistsOfDecidableSSubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidableExistsOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop}
(hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∃ (t : _) (_h : t ⊂ s), p t) :=
@Finset.decidableExistsOfDecidableSSubsets _ _ _ _ hu
/-- A version of `Finset.decidableForallOfDecidableSSubsets` with a non-dependent `p`.
Typeclass inference cannot find `hu` here, so this is not an instance. -/
def decidableForallOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop}
(hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∀ t ⊂ s, p t) :=
@Finset.decidableForallOfDecidableSSubsets _ _ _ _ hu
end SSubsets
section powersetCard
variable {n} {s t : Finset α}
/-- Given an integer `n` and a finset `s`, then `powersetCard n s` is the finset of subsets of `s`
of cardinality `n`. -/
def powersetCard (n : ℕ) (s : Finset α) : Finset (Finset α) :=
⟨((s.1.powersetCard n).pmap Finset.mk) fun _t h => nodup_of_le (mem_powersetCard.1 h).1 s.2,
s.2.powersetCard.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩
@[simp, grind =] lemma mem_powersetCard : s ∈ powersetCard n t ↔ s ⊆ t ∧ card s = n := by
cases s; simp [powersetCard, val_le_iff.symm]
@[simp]
theorem powersetCard_mono {n} {s t : Finset α} (h : s ⊆ t) : powersetCard n s ⊆ powersetCard n t :=
fun _u h' => mem_powersetCard.2 <|
And.imp (fun h₂ => Subset.trans h₂ h) id (mem_powersetCard.1 h')
/-- **Formula for the Number of Combinations** -/
@[simp]
theorem card_powersetCard (n : ℕ) (s : Finset α) :
card (powersetCard n s) = Nat.choose (card s) n :=
(card_pmap _ _ _).trans (Multiset.card_powersetCard n s.1)
@[simp]
theorem powersetCard_zero (s : Finset α) : s.powersetCard 0 = {∅} := by
ext; rw [mem_powersetCard, mem_singleton, card_eq_zero]
refine
⟨fun h => h.2, fun h => by
rw [h]
exact ⟨empty_subset s, rfl⟩⟩
lemma powersetCard_empty_subsingleton (n : ℕ) :
(powersetCard n (∅ : Finset α) : Set <| Finset α).Subsingleton := by
simp [Set.Subsingleton, subset_empty]
@[simp]
theorem map_val_val_powersetCard (s : Finset α) (i : ℕ) :
(s.powersetCard i).val.map Finset.val = s.1.powersetCard i := by
simp [Finset.powersetCard, map_pmap, pmap_eq_map, map_id']
theorem powersetCard_one (s : Finset α) :
s.powersetCard 1 = s.map ⟨_, Finset.singleton_injective⟩ :=
eq_of_veq <| Multiset.map_injective val_injective <| by simp [Multiset.powersetCard_one]
@[simp]
lemma powersetCard_eq_empty : powersetCard n s = ∅ ↔ s.card < n := by
refine ⟨?_, fun h ↦ card_eq_zero.1 <| by rw [card_powersetCard, Nat.choose_eq_zero_of_lt h]⟩
contrapose!
exact fun h ↦ nonempty_iff_ne_empty.1 <| (exists_subset_card_eq h).imp <| by simp
@[simp] lemma powersetCard_card_add (s : Finset α) (hn : 0 < n) :
s.powersetCard (s.card + n) = ∅ := by simpa
theorem powersetCard_eq_filter {n} {s : Finset α} :
powersetCard n s = (powerset s).filter fun x => x.card = n := by
ext
simp [mem_powersetCard]
theorem powersetCard_succ_insert [DecidableEq α] {x : α} {s : Finset α} (h : x ∉ s) (n : ℕ) :
powersetCard n.succ (insert x s) =
powersetCard n.succ s ∪ (powersetCard n s).image (insert x) := by
rw [powersetCard_eq_filter, powerset_insert, filter_union, ← powersetCard_eq_filter]
congr
rw [powersetCard_eq_filter, filter_image]
congr 1
ext t
simp only [mem_powerset, mem_filter, and_congr_right_iff]
intro ht
have : x ∉ t := fun H => h (ht H)
simp [card_insert_of_notMem this]
@[simp]
lemma powersetCard_nonempty : (powersetCard n s).Nonempty ↔ n ≤ s.card := by
aesop (add simp [Finset.Nonempty, exists_subset_card_eq, card_le_card])
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, powersetCard_nonempty_of_le⟩ := powersetCard_nonempty
@[simp]
theorem powersetCard_self (s : Finset α) : powersetCard s.card s = {s} := by
ext
rw [mem_powersetCard, mem_singleton]
constructor
· exact fun ⟨hs, hc⟩ => eq_of_subset_of_card_le hs hc.ge
· rintro rfl
simp
theorem pairwise_disjoint_powersetCard (s : Finset α) :
Pairwise fun i j => Disjoint (s.powersetCard i) (s.powersetCard j) := fun _i _j hij =>
Finset.disjoint_left.mpr fun _x hi hj =>
hij <| (mem_powersetCard.mp hi).2.symm.trans (mem_powersetCard.mp hj).2
theorem powerset_card_disjiUnion (s : Finset α) :
Finset.powerset s =
(range (s.card + 1)).disjiUnion (fun i => powersetCard i s)
(s.pairwise_disjoint_powersetCard.set_pairwise _) := by
refine ext fun a => ⟨fun ha => ?_, fun ha => ?_⟩
· rw [mem_disjiUnion]
exact
⟨a.card, mem_range.mpr (Nat.lt_succ_of_le (card_le_card (mem_powerset.mp ha))),
mem_powersetCard.mpr ⟨mem_powerset.mp ha, rfl⟩⟩
· rcases mem_disjiUnion.mp ha with ⟨i, _hi, ha⟩
exact mem_powerset.mpr (mem_powersetCard.mp ha).1
theorem powerset_card_biUnion [DecidableEq (Finset α)] (s : Finset α) :
Finset.powerset s = (range (s.card + 1)).biUnion fun i => powersetCard i s := by
simpa only [disjiUnion_eq_biUnion] using powerset_card_disjiUnion s
theorem powersetCard_sup [DecidableEq α] (u : Finset α) (n : ℕ) (hn : n < u.card) :
(powersetCard n.succ u).sup id = u := by
apply le_antisymm
· simp_rw [Finset.sup_le_iff, mem_powersetCard]
rintro x ⟨h, -⟩
exact h
· rw [sup_eq_biUnion, le_iff_subset, subset_iff]
intro x hx
simp only [mem_biUnion, id]
obtain ⟨t, ht⟩ : ∃ t, t ∈ powersetCard n (u.erase x) := powersetCard_nonempty.2
(le_trans (Nat.le_sub_one_of_lt hn) pred_card_le_card_erase)
refine ⟨insert x t, ?_, mem_insert_self _ _⟩
rw [← insert_erase hx, powersetCard_succ_insert (notMem_erase _ _)]
exact mem_union_right _ (mem_image_of_mem _ ht)
theorem powersetCard_map {β : Type*} (f : α ↪ β) (n : ℕ) (s : Finset α) :
powersetCard n (s.map f) = (powersetCard n s).map (mapEmbedding f).toEmbedding :=
ext fun t => by
-- `le_eq_subset` is a dangerous lemma since it turns the type `↪o` into `(· ⊆ ·) ↪r (· ⊆ ·)`,
-- which makes `simp` have trouble working with `mapEmbedding_apply`.
simp only [mem_powersetCard, mem_map, RelEmbedding.coe_toEmbedding, mapEmbedding_apply]
constructor
· classical
intro h
have : map f (filter (fun x => (f x ∈ t)) s) = t := by
ext x
simp only [mem_map, mem_filter]
exact ⟨fun ⟨_y, ⟨_hy₁, hy₂⟩, hy₃⟩ => hy₃ ▸ hy₂,
fun hx => let ⟨y, hy⟩ := mem_map.1 (h.1 hx); ⟨y, ⟨hy.1, hy.2 ▸ hx⟩, hy.2⟩⟩
refine ⟨_, ?_, this⟩
rw [← card_map f, this, h.2]; simp
· rintro ⟨a, ⟨has, rfl⟩, rfl⟩
simp only [map_subset_map, has, card_map, and_self]
end powersetCard
end Finset
|
SmallHom.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.Localization.HomEquiv
import Mathlib.Logic.Small.Defs
/-!
# Shrinking morphisms in localized categories
Given a class of morphisms `W : MorphismProperty C`, and two objects `X` and `Y`,
we introduce a type-class `HasSmallLocalizedHom.{w} W X Y` which expresses
that in the localized category with respect to `W`, the type of morphisms from `X`
to `Y` is `w`-small for a certain universe `w`. Under this assumption,
we define `SmallHom.{w} W X Y : Type w` as the shrunk type. For any localization
functor `L : C ⥤ D` for `W`, we provide a bijection
`SmallHom.equiv.{w} W L : SmallHom.{w} W X Y ≃ (L.obj X ⟶ L.obj Y)` that is compatible
with the composition of morphisms.
-/
universe w'' w w' v₁ v₂ v₃ v₄ v₅ u₁ u₂ u₃ u₄ u₅
namespace CategoryTheory
open Category
namespace Localization
variable {C : Type u₁} [Category.{v₁} C] (W : MorphismProperty C)
{D : Type u₂} [Category.{v₂} D]
{D' : Type u₃} [Category.{v₃} D']
section
variable (L : C ⥤ D) [L.IsLocalization W] (X Y Z : C)
/-- This property holds if the type of morphisms between `X` and `Y`
in the localized category with respect to `W : MorphismProperty C`
is small. -/
class HasSmallLocalizedHom : Prop where
small : Small.{w} (W.Q.obj X ⟶ W.Q.obj Y)
attribute [instance] HasSmallLocalizedHom.small
variable {X Y Z}
lemma hasSmallLocalizedHom_iff :
HasSmallLocalizedHom.{w} W X Y ↔ Small.{w} (L.obj X ⟶ L.obj Y) := by
constructor
· intro h
have := h.small
exact small_map (homEquiv W W.Q L).symm
· intro h
exact ⟨small_map (homEquiv W W.Q L)⟩
include L in
lemma hasSmallLocalizedHom_of_isLocalization :
HasSmallLocalizedHom.{v₂} W X Y := by
rw [hasSmallLocalizedHom_iff W L]
infer_instance
variable (X Y) in
lemma small_of_hasSmallLocalizedHom [HasSmallLocalizedHom.{w} W X Y] :
Small.{w} (L.obj X ⟶ L.obj Y) := by
rwa [← hasSmallLocalizedHom_iff W]
lemma hasSmallLocalizedHom_iff_of_isos {X' Y' : C} (e : X ≅ X') (e' : Y ≅ Y') :
HasSmallLocalizedHom.{w} W X Y ↔ HasSmallLocalizedHom.{w} W X' Y' := by
simp only [hasSmallLocalizedHom_iff W W.Q]
exact small_congr (Iso.homCongr (W.Q.mapIso e) (W.Q.mapIso e'))
variable (X) in
lemma hasSmallLocalizedHom_iff_target {Y Y' : C} (f : Y ⟶ Y') (hf : W f) :
HasSmallLocalizedHom.{w} W X Y ↔ HasSmallLocalizedHom.{w} W X Y' := by
simp only [hasSmallLocalizedHom_iff W W.Q]
exact small_congr (Iso.homCongr (Iso.refl _) (Localization.isoOfHom W.Q W f hf))
lemma hasSmallLocalizedHom_iff_source {X' : C} (f : X ⟶ X') (hf : W f) (Y : C) :
HasSmallLocalizedHom.{w} W X Y ↔ HasSmallLocalizedHom.{w} W X' Y := by
simp only [hasSmallLocalizedHom_iff W W.Q]
exact small_congr (Iso.homCongr (Localization.isoOfHom W.Q W f hf) (Iso.refl _))
end
/-- The type of morphisms from `X` to `Y` in the localized category
with respect to `W : MorphismProperty C` that is shrunk to `Type w`
when `HasSmallLocalizedHom.{w} W X Y` holds. -/
def SmallHom (X Y : C) [HasSmallLocalizedHom.{w} W X Y] : Type w :=
Shrink.{w} (W.Q.obj X ⟶ W.Q.obj Y)
namespace SmallHom
/-- The canonical bijection `SmallHom.{w} W X Y ≃ (L.obj X ⟶ L.obj Y)`
when `L` is a localization functor for `W : MorphismProperty C` and
that `HasSmallLocalizedHom.{w} W X Y` holds. -/
noncomputable def equiv (L : C ⥤ D) [L.IsLocalization W] {X Y : C}
[HasSmallLocalizedHom.{w} W X Y] :
SmallHom.{w} W X Y ≃ (L.obj X ⟶ L.obj Y) :=
letI := small_of_hasSmallLocalizedHom.{w} W W.Q X Y
(equivShrink _).symm.trans (homEquiv W W.Q L)
lemma equiv_equiv_symm (L : C ⥤ D) [L.IsLocalization W]
(L' : C ⥤ D') [L'.IsLocalization W] (G : D ⥤ D')
(e : L ⋙ G ≅ L') {X Y : C} [HasSmallLocalizedHom.{w} W X Y]
(f : L.obj X ⟶ L.obj Y) :
equiv W L' ((equiv W L).symm f) =
e.inv.app X ≫ G.map f ≫ e.hom.app Y := by
dsimp [equiv]
rw [Equiv.symm_apply_apply, homEquiv_trans]
apply homEquiv_eq
/-- The element in `SmallHom W X Y` induced by `f : X ⟶ Y`. -/
noncomputable def mk {X Y : C} [HasSmallLocalizedHom.{w} W X Y] (f : X ⟶ Y) :
SmallHom.{w} W X Y :=
(equiv.{w} W W.Q).symm (W.Q.map f)
@[simp]
lemma equiv_mk (L : C ⥤ D) [L.IsLocalization W] {X Y : C}
[HasSmallLocalizedHom.{w} W X Y] (f : X ⟶ Y) :
equiv.{w} W L (mk W f) = L.map f := by
simp [equiv, mk]
variable {W}
/-- The formal inverse in `SmallHom W X Y` of a morphism `f : Y ⟶ X` such that `W f`. -/
noncomputable def mkInv {X Y : C} (f : Y ⟶ X) (hf : W f) [HasSmallLocalizedHom.{w} W X Y] :
SmallHom.{w} W X Y :=
(equiv.{w} W W.Q).symm (Localization.isoOfHom W.Q W f hf).inv
@[simp]
lemma equiv_mkInv (L : C ⥤ D) [L.IsLocalization W] {X Y : C} (f : Y ⟶ X) (hf : W f)
[HasSmallLocalizedHom.{w} W X Y] :
equiv.{w} W L (mkInv f hf) = (Localization.isoOfHom L W f hf).inv := by
simp only [equiv, mkInv, Equiv.symm_trans_apply, Equiv.symm_symm, homEquiv_symm_apply,
Equiv.trans_apply, Equiv.symm_apply_apply, homEquiv_isoOfHom_inv]
/-- The composition on `SmallHom W`. -/
noncomputable def comp {X Y Z : C} [HasSmallLocalizedHom.{w} W X Y]
[HasSmallLocalizedHom.{w} W Y Z] [HasSmallLocalizedHom.{w} W X Z]
(α : SmallHom.{w} W X Y) (β : SmallHom.{w} W Y Z) :
SmallHom.{w} W X Z :=
(equiv W W.Q).symm (equiv W W.Q α ≫ equiv W W.Q β)
lemma equiv_comp (L : C ⥤ D) [L.IsLocalization W] {X Y Z : C} [HasSmallLocalizedHom.{w} W X Y]
[HasSmallLocalizedHom.{w} W Y Z] [HasSmallLocalizedHom.{w} W X Z]
(α : SmallHom.{w} W X Y) (β : SmallHom.{w} W Y Z) :
equiv W L (α.comp β) = equiv W L α ≫ equiv W L β := by
letI := small_of_hasSmallLocalizedHom.{w} W W.Q X Y
letI := small_of_hasSmallLocalizedHom.{w} W W.Q Y Z
obtain ⟨α, rfl⟩ := (equivShrink _).surjective α
obtain ⟨β, rfl⟩ := (equivShrink _).surjective β
dsimp [equiv, comp]
rw [Equiv.symm_apply_apply]
erw [(equivShrink _).symm_apply_apply, (equivShrink _).symm_apply_apply]
simp only [homEquiv_refl, homEquiv_comp]
section
variable {X Y Z T : C}
lemma mk_comp_mk [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y Z]
[HasSmallLocalizedHom.{w} W X Z] (f : X ⟶ Y) (g : Y ⟶ Z) :
(mk W f).comp (mk W g) = mk W (f ≫ g) :=
(equiv W W.Q).injective (by simp [equiv_comp])
@[simp]
lemma comp_mk_id [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y Y]
(α : SmallHom.{w} W X Y) :
α.comp (mk W (𝟙 Y)) = α :=
(equiv W W.Q).injective (by simp [equiv_comp])
@[simp]
lemma mk_id_comp [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W X X]
(α : SmallHom.{w} W X Y) :
(mk W (𝟙 X)).comp α = α :=
(equiv W W.Q).injective (by simp [equiv_comp])
@[simp]
lemma comp_assoc [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W X Z]
[HasSmallLocalizedHom.{w} W X T] [HasSmallLocalizedHom.{w} W Y Z]
[HasSmallLocalizedHom.{w} W Y T] [HasSmallLocalizedHom.{w} W Z T]
(α : SmallHom.{w} W X Y) (β : SmallHom.{w} W Y Z) (γ : SmallHom.{w} W Z T) :
(α.comp β).comp γ = α.comp (β.comp γ) := by
apply (equiv W W.Q).injective
simp only [equiv_comp, assoc]
@[simp]
lemma mk_comp_mkInv [HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w} W Y X]
[HasSmallLocalizedHom.{w} W Y Y] (f : Y ⟶ X) (hf : W f) :
(mk W f).comp (mkInv f hf) = mk W (𝟙 Y) :=
(equiv W W.Q).injective (by simp [equiv_comp])
@[simp]
lemma mkInv_comp_mk [HasSmallLocalizedHom.{w} W X X] [HasSmallLocalizedHom.{w} W X Y]
[HasSmallLocalizedHom.{w} W Y X] (f : Y ⟶ X) (hf : W f) :
(mkInv f hf).comp (mk W f) = mk W (𝟙 X) :=
(equiv W W.Q).injective (by simp [equiv_comp])
end
section ChangeOfUniverse
/-- Up to an equivalence, the type `SmallHom.{w} W X Y n` does not depend on the universe `w`. -/
noncomputable def chgUniv {X Y : C}
[HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w''} W X Y] :
SmallHom.{w} W X Y ≃ SmallHom.{w''} W X Y :=
(equiv.{w} W W.Q).trans (equiv.{w''} W W.Q).symm
lemma equiv_chgUniv (L : C ⥤ D) [L.IsLocalization W] {X Y : C}
[HasSmallLocalizedHom.{w} W X Y] [HasSmallLocalizedHom.{w''} W X Y]
(e : SmallHom.{w} W X Y) :
equiv W L (chgUniv.{w''} e) = equiv W L e := by
obtain ⟨f, rfl⟩ := (equiv W W.Q).symm.surjective e
dsimp [chgUniv]
simp only [Equiv.apply_symm_apply,
equiv_equiv_symm W _ _ _ (Localization.compUniqFunctor W.Q L W)]
end ChangeOfUniverse
end SmallHom
end Localization
namespace LocalizerMorphism
open Localization
variable {C₁ : Type u₁} [Category.{v₁} C₁] {W₁ : MorphismProperty C₁}
{C₂ : Type u₂} [Category.{v₂} C₂] {W₂ : MorphismProperty C₂}
{D₁ : Type u₃} [Category.{v₃} D₁] {D₂ : Type u₄} [Category.{v₄} D₂]
(Φ : LocalizerMorphism W₁ W₂) (L₁ : C₁ ⥤ D₁) [L₁.IsLocalization W₁]
(L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂]
section
variable {X Y : C₁}
variable [HasSmallLocalizedHom.{w} W₁ X Y]
[HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Y)]
/-- The action of a localizer morphism on `SmallHom`. -/
noncomputable def smallHomMap (f : SmallHom.{w} W₁ X Y) :
SmallHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Y) :=
(SmallHom.equiv W₂ W₂.Q).symm
(Iso.homCongr ((CatCommSq.iso Φ.functor W₁.Q W₂.Q _).symm.app _)
((CatCommSq.iso Φ.functor W₁.Q W₂.Q _).symm.app _)
((Φ.localizedFunctor W₁.Q W₂.Q).map ((SmallHom.equiv W₁ W₁.Q) f)))
lemma equiv_smallHomMap (G : D₁ ⥤ D₂) (e : Φ.functor ⋙ L₂ ≅ L₁ ⋙ G)
(f : SmallHom.{w} W₁ X Y) :
(SmallHom.equiv W₂ L₂) (Φ.smallHomMap f) =
e.hom.app X ≫ G.map (SmallHom.equiv W₁ L₁ f) ≫ e.inv.app Y := by
obtain ⟨g, rfl⟩ := (SmallHom.equiv W₁ W₁.Q).symm.surjective f
simp only [smallHomMap, Equiv.apply_symm_apply]
let G' := Φ.localizedFunctor W₁.Q W₂.Q
let β := CatCommSq.iso Φ.functor W₁.Q W₂.Q G'
let E₁ := (uniq W₁.Q L₁ W₁).functor
let α₁ : W₁.Q ⋙ E₁ ≅ L₁ := compUniqFunctor W₁.Q L₁ W₁
let E₂ := (uniq W₂.Q L₂ W₂).functor
let α₂ : W₂.Q ⋙ E₂ ≅ L₂ := compUniqFunctor W₂.Q L₂ W₂
rw [SmallHom.equiv_equiv_symm W₁ W₁.Q L₁ E₁ α₁,
SmallHom.equiv_equiv_symm W₂ W₂.Q L₂ E₂ α₂]
change α₂.inv.app _ ≫ E₂.map (β.hom.app X ≫ G'.map g ≫ β.inv.app Y) ≫ _ = _
let γ : G' ⋙ E₂ ≅ E₁ ⋙ G := liftNatIso W₁.Q W₁ (W₁.Q ⋙ G' ⋙ E₂) (W₁.Q ⋙ E₁ ⋙ G) _ _
((Functor.associator _ _ _).symm ≪≫ Functor.isoWhiskerRight β.symm E₂ ≪≫
Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft _ α₂ ≪≫ e ≪≫
Functor.isoWhiskerRight α₁.symm G ≪≫ Functor.associator _ _ _)
have hγ : ∀ (X : C₁), γ.hom.app (W₁.Q.obj X) =
E₂.map (β.inv.app X) ≫ α₂.hom.app (Φ.functor.obj X) ≫
e.hom.app X ≫ G.map (α₁.inv.app X) := fun X ↦ by
simp [γ, id_comp, comp_id]
simp only [Functor.map_comp, assoc]
erw [← NatIso.naturality_1 γ]
simp only [Functor.comp_map, ← cancel_epi (e.inv.app X), ← cancel_epi (G.map (α₁.hom.app X)),
← cancel_epi (γ.hom.app (W₁.Q.obj X)), assoc, Iso.inv_hom_id_app_assoc,
← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, id_comp,
Iso.hom_inv_id_app_assoc]
simp only [hγ, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app,
Functor.map_id, id_comp, Iso.hom_inv_id_app_assoc,
Iso.inv_hom_id_app_assoc, Iso.hom_inv_id_app, Functor.comp_obj, comp_id]
end
variable {X Y Z : C₁}
variable [HasSmallLocalizedHom.{w} W₁ X Y] [HasSmallLocalizedHom.{w} W₁ Y Z]
[HasSmallLocalizedHom.{w} W₁ X Z]
[HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Y)]
[HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj Y) (Φ.functor.obj Z)]
[HasSmallLocalizedHom.{w'} W₂ (Φ.functor.obj X) (Φ.functor.obj Z)]
lemma smallHomMap_comp (f : SmallHom.{w} W₁ X Y) (g : SmallHom.{w} W₁ Y Z) :
Φ.smallHomMap (f.comp g) = (Φ.smallHomMap f).comp (Φ.smallHomMap g) := by
apply (SmallHom.equiv W₂ W₂.Q).injective
simp [Φ.equiv_smallHomMap W₁.Q W₂.Q (Φ.localizedFunctor W₁.Q W₂.Q) (CatCommSq.iso _ _ _ _),
SmallHom.equiv_comp]
end LocalizerMorphism
end CategoryTheory
|
Star.lean
|
/-
Copyright (c) 2021 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Algebra.Module.Equiv.Defs
import Mathlib.Algebra.Star.Basic
/-!
# Notation for star-linear maps
This is in a separate file as a it is not needed until much later,
and avoids importing the theory of star operations unnecessarily early.
-/
/-- `M →ₗ⋆[R] N` is the type of `R`-conjugate-linear maps from `M` to `N`. -/
notation:25 M " →ₗ⋆[" R:25 "] " M₂:0 => LinearMap (starRingEnd R) M M₂
/-- The notation `M ≃ₗ⋆[R] M₂` denotes the type of star-linear equivalences between `M` and `M₂`
over the `⋆` endomorphism of the underlying starred ring `R`. -/
notation:50 M " ≃ₗ⋆[" R "] " M₂ => LinearEquiv (starRingEnd R) M M₂
|
oldObtain.lean
|
/-
Copyright (c) 2024 Michael Rothgang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Rothgang
-/
import Mathlib.Tactic.Linter.OldObtain
/-! Tests for the `oldObtain` linter. -/
set_option linter.oldObtain true
-- These cases are fine.
theorem foo : True := by
obtain := trivial
obtain _h := trivial
obtain : True := trivial
obtain _h : True := trivial
trivial
-- These cases are linted against.
/--
warning: Please remove stream-of-consciousness `obtain` syntax
Note: This linter can be disabled with `set_option linter.oldObtain false`
-/
#guard_msgs in
theorem foo' : True := by
obtain : True
· trivial
trivial
/--
warning: Please remove stream-of-consciousness `obtain` syntax
Note: This linter can be disabled with `set_option linter.oldObtain false`
-/
#guard_msgs in
theorem foo'' : True := by
obtain h : True
· trivial
trivial
|
Centering.lean
|
/-
Copyright (c) 2022 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Probability.Martingale.Basic
/-!
# Centering lemma for stochastic processes
Any `ℕ`-indexed stochastic process which is adapted and integrable can be written as the sum of a
martingale and a predictable process. This result is also known as **Doob's decomposition theorem**.
From a process `f`, a filtration `ℱ` and a measure `μ`, we define two processes
`martingalePart f ℱ μ` and `predictablePart f ℱ μ`.
## Main definitions
* `MeasureTheory.predictablePart f ℱ μ`: a predictable process such that
`f = predictablePart f ℱ μ + martingalePart f ℱ μ`
* `MeasureTheory.martingalePart f ℱ μ`: a martingale such that
`f = predictablePart f ℱ μ + martingalePart f ℱ μ`
## Main statements
* `MeasureTheory.adapted_predictablePart`: `(fun n => predictablePart f ℱ μ (n+1))` is adapted.
That is, `predictablePart` is predictable.
* `MeasureTheory.martingale_martingalePart`: `martingalePart f ℱ μ` is a martingale.
-/
open TopologicalSpace Filter
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory
namespace MeasureTheory
variable {Ω E : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E] {f : ℕ → Ω → E} {ℱ : Filtration ℕ m0}
/-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable
process. This is the predictable process. See `martingalePart` for the martingale. -/
noncomputable def predictablePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0)
(μ : Measure Ω) : ℕ → Ω → E := fun n => ∑ i ∈ Finset.range n, μ[f (i + 1) - f i|ℱ i]
@[simp]
theorem predictablePart_zero : predictablePart f ℱ μ 0 = 0 := by
simp_rw [predictablePart, Finset.range_zero, Finset.sum_empty]
theorem adapted_predictablePart : Adapted ℱ fun n => predictablePart f ℱ μ (n + 1) := fun _ =>
Finset.stronglyMeasurable_sum _ fun _ hin =>
stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_succ_iff.mp hin))
theorem adapted_predictablePart' : Adapted ℱ fun n => predictablePart f ℱ μ n := fun _ =>
Finset.stronglyMeasurable_sum _ fun _ hin =>
stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_le hin))
/-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable
process. This is the martingale. See `predictablePart` for the predictable process. -/
noncomputable def martingalePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0)
(μ : Measure Ω) : ℕ → Ω → E := fun n => f n - predictablePart f ℱ μ n
theorem martingalePart_add_predictablePart (ℱ : Filtration ℕ m0) (μ : Measure Ω) (f : ℕ → Ω → E) :
martingalePart f ℱ μ + predictablePart f ℱ μ = f :=
sub_add_cancel _ _
theorem martingalePart_eq_sum : martingalePart f ℱ μ = fun n =>
f 0 + ∑ i ∈ Finset.range n, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]) := by
unfold martingalePart predictablePart
ext1 n
rw [Finset.eq_sum_range_sub f n, ← add_sub, ← Finset.sum_sub_distrib]
theorem adapted_martingalePart (hf : Adapted ℱ f) : Adapted ℱ (martingalePart f ℱ μ) :=
Adapted.sub hf adapted_predictablePart'
theorem integrable_martingalePart (hf_int : ∀ n, Integrable (f n) μ) (n : ℕ) :
Integrable (martingalePart f ℱ μ n) μ := by
rw [martingalePart_eq_sum]
fun_prop
theorem martingale_martingalePart (hf : Adapted ℱ f) (hf_int : ∀ n, Integrable (f n) μ)
[SigmaFiniteFiltration μ ℱ] : Martingale (martingalePart f ℱ μ) ℱ μ := by
refine ⟨adapted_martingalePart hf, fun i j hij => ?_⟩
-- ⊢ μ[martingalePart f ℱ μ j | ℱ i] =ᵐ[μ] martingalePart f ℱ μ i
have h_eq_sum : μ[martingalePart f ℱ μ j|ℱ i] =ᵐ[μ]
f 0 + ∑ k ∈ Finset.range j, (μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i]) := by
rw [martingalePart_eq_sum]
refine (condExp_add (hf_int 0) (by fun_prop) _).trans ?_
refine (EventuallyEq.rfl.add (condExp_finset_sum (fun i _ => by fun_prop) _)).trans ?_
refine EventuallyEq.add ?_ ?_
· rw [condExp_of_stronglyMeasurable (ℱ.le _) _ (hf_int 0)]
· exact (hf 0).mono (ℱ.mono (zero_le i))
· exact eventuallyEq_sum fun k _ => condExp_sub (by fun_prop) integrable_condExp _
refine h_eq_sum.trans ?_
have h_ge : ∀ k, i ≤ k → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] 0 := by
intro k hk
have : μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] μ[f (k + 1) - f k|ℱ i] :=
condExp_condExp_of_le (ℱ.mono hk) (ℱ.le k)
filter_upwards [this] with x hx
rw [Pi.sub_apply, Pi.zero_apply, hx, sub_self]
have h_lt : ∀ k, k < i → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ]
f (k + 1) - f k - μ[f (k + 1) - f k|ℱ k] := by
refine fun k hk => EventuallyEq.sub ?_ ?_
· rw [condExp_of_stronglyMeasurable]
· exact ((hf (k + 1)).mono (ℱ.mono (Nat.succ_le_of_lt hk))).sub ((hf k).mono (ℱ.mono hk.le))
· exact (hf_int _).sub (hf_int _)
· rw [condExp_of_stronglyMeasurable]
· exact stronglyMeasurable_condExp.mono (ℱ.mono hk.le)
· exact integrable_condExp
rw [martingalePart_eq_sum]
refine EventuallyEq.add EventuallyEq.rfl ?_
rw [← Finset.sum_range_add_sum_Ico _ hij, ←
add_zero (∑ i ∈ Finset.range i, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]))]
refine (eventuallyEq_sum fun k hk => h_lt k (Finset.mem_range.mp hk)).add ?_
refine (eventuallyEq_sum fun k hk => h_ge k (Finset.mem_Ico.mp hk).1).trans ?_
simp only [Finset.sum_const_zero]
rfl
-- The following two lemmas demonstrate the essential uniqueness of the decomposition
theorem martingalePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E}
(hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0)
(hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : martingalePart (f + g) ℱ μ n =ᵐ[μ] f n := by
set h := f - martingalePart (f + g) ℱ μ with hhdef
have hh : h = predictablePart (f + g) ℱ μ - g := by
rw [hhdef, sub_eq_sub_iff_add_eq_add, add_comm (predictablePart (f + g) ℱ μ),
martingalePart_add_predictablePart]
have hhpred : Adapted ℱ fun n => h (n + 1) := by
rw [hh]
exact adapted_predictablePart.sub hg
have hhmgle : Martingale h ℱ μ := hf.sub (martingale_martingalePart
(hf.adapted.add <| Predictable.adapted hg <| hg0.symm ▸ stronglyMeasurable_zero) fun n =>
(hf.integrable n).add <| hgint n)
refine (eventuallyEq_iff_sub.2 ?_).symm
filter_upwards [hhmgle.eq_zero_of_predictable hhpred n] with ω hω
unfold h at hω
rw [Pi.sub_apply] at hω
rw [hω, Pi.sub_apply, martingalePart]
simp [hg0]
theorem predictablePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E}
(hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0)
(hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : predictablePart (f + g) ℱ μ n =ᵐ[μ] g n := by
filter_upwards [martingalePart_add_ae_eq hf hg hg0 hgint n] with ω hω
rw [← add_right_inj (f n ω)]
conv_rhs => rw [← Pi.add_apply, ← Pi.add_apply, ← martingalePart_add_predictablePart ℱ μ (f + g)]
rw [Pi.add_apply, Pi.add_apply, hω]
section Difference
theorem predictablePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, ∀ i, |predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω| ≤ R := by
simp_rw [predictablePart, Finset.sum_apply, Finset.sum_range_succ_sub_sum]
exact ae_all_iff.2 fun i => ae_bdd_condExp_of_ae_bdd <| ae_all_iff.1 hbdd i
theorem martingalePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0)
(hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) :
∀ᵐ ω ∂μ, ∀ i, |martingalePart f ℱ μ (i + 1) ω - martingalePart f ℱ μ i ω| ≤ ↑(2 * R) := by
filter_upwards [hbdd, predictablePart_bdd_difference ℱ hbdd] with ω hω₁ hω₂ i
simp only [two_mul, martingalePart, Pi.sub_apply]
have : |f (i + 1) ω - predictablePart f ℱ μ (i + 1) ω - (f i ω - predictablePart f ℱ μ i ω)| =
|f (i + 1) ω - f i ω - (predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω)| := by
ring_nf -- `ring` suggests `ring_nf` despite proving the goal
rw [this]
exact (abs_sub _ _).trans (add_le_add (hω₁ i) (hω₂ i))
end Difference
end MeasureTheory
|
Enum.lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yakov Pechersky, Eric Wieser
-/
import Mathlib.Data.List.Basic
/-!
# Properties of `List.enum`
## Deprecation note
Many lemmas in this file have been replaced by theorems in Lean4,
in terms of `xs[i]?` and `xs[i]` rather than `get` and `get?`.
The deprecated results here are unused in Mathlib.
Any downstream users who can not easily adapt may remove the deprecations as needed.
-/
namespace List
variable {α : Type*}
theorem forall_mem_zipIdx {l : List α} {n : ℕ} {p : α × ℕ → Prop} :
(∀ x ∈ l.zipIdx n, p x) ↔ ∀ (i : ℕ) (_ : i < length l), p (l[i], n + i) := by
simp only [forall_mem_iff_getElem, getElem_zipIdx, length_zipIdx]
/-- Variant of `forall_mem_zipIdx` with the `zipIdx` argument specialized to `0`. -/
theorem forall_mem_zipIdx' {l : List α} {p : α × ℕ → Prop} :
(∀ x ∈ l.zipIdx, p x) ↔ ∀ (i : ℕ) (_ : i < length l), p (l[i], i) :=
forall_mem_zipIdx.trans <| by simp
theorem exists_mem_zipIdx {l : List α} {n : ℕ} {p : α × ℕ → Prop} :
(∃ x ∈ l.zipIdx n, p x) ↔ ∃ (i : ℕ) (_ : i < length l), p (l[i], n + i) := by
simp only [exists_mem_iff_getElem, getElem_zipIdx, length_zipIdx]
/-- Variant of `exists_mem_zipIdx` with the `zipIdx` argument specialized to `0`. -/
theorem exists_mem_zipIdx' {l : List α} {p : α × ℕ → Prop} :
(∃ x ∈ l.zipIdx, p x) ↔ ∃ (i : ℕ) (_ : i < length l), p (l[i], i) :=
exists_mem_zipIdx.trans <| by simp
end List
|
LiminfLimsup.lean
|
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.MeasureTheory.Covering.DensityTheorem
/-!
# Liminf, limsup, and uniformly locally doubling measures.
This file is a place to collect lemmas about liminf and limsup for subsets of a metric space
carrying a uniformly locally doubling measure.
## Main results:
* `blimsup_cthickening_mul_ae_eq`: the limsup of the closed thickening of a sequence of subsets
of a metric space is unchanged almost everywhere for a uniformly locally doubling measure if the
sequence of distances is multiplied by a positive scale factor. This is a generalisation of a
result of Cassels, appearing as Lemma 9 on page 217 of
[J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950).
* `blimsup_thickening_mul_ae_eq`: a variant of `blimsup_cthickening_mul_ae_eq` for thickenings
rather than closed thickenings.
-/
open Set Filter Metric MeasureTheory TopologicalSpace
open scoped NNReal ENNReal Topology
variable {α : Type*}
variable [PseudoMetricSpace α] [SecondCountableTopology α] [MeasurableSpace α] [BorelSpace α]
variable (μ : Measure α) [IsLocallyFiniteMeasure μ] [IsUnifLocDoublingMeasure μ]
/-- This is really an auxiliary result en route to `blimsup_cthickening_ae_le_of_eventually_mul_le`
(which is itself an auxiliary result en route to `blimsup_cthickening_mul_ae_eq`).
NB: The `: Set α` type ascription is present because of
https://github.com/leanprover-community/mathlib/issues/16932. -/
theorem blimsup_cthickening_ae_le_of_eventually_mul_le_aux (p : ℕ → Prop) {s : ℕ → Set α}
(hs : ∀ i, IsClosed (s i)) {r₁ r₂ : ℕ → ℝ} (hr : Tendsto r₁ atTop (𝓝[>] 0)) (hrp : 0 ≤ r₁)
{M : ℝ} (hM : 0 < M) (hM' : M < 1) (hMr : ∀ᶠ i in atTop, M * r₁ i ≤ r₂ i) :
(blimsup (fun i => cthickening (r₁ i) (s i)) atTop p : Set α) ≤ᵐ[μ]
(blimsup (fun i => cthickening (r₂ i) (s i)) atTop p : Set α) := by
/- Sketch of proof:
Assume that `p` is identically true for simplicity. Let `Y₁ i = cthickening (r₁ i) (s i)`, define
`Y₂` similarly except using `r₂`, and let `(Z i) = ⋃_{j ≥ i} (Y₂ j)`. Our goal is equivalent to
showing that `μ ((limsup Y₁) \ (Z i)) = 0` for all `i`.
Assume for contradiction that `μ ((limsup Y₁) \ (Z i)) ≠ 0` for some `i` and let
`W = (limsup Y₁) \ (Z i)`. Apply Lebesgue's density theorem to obtain a point `d` in `W` of
density `1`. Since `d ∈ limsup Y₁`, there is a subsequence of `j ↦ Y₁ j`, indexed by
`f 0 < f 1 < ...`, such that `d ∈ Y₁ (f j)` for all `j`. For each `j`, we may thus choose
`w j ∈ s (f j)` such that `d ∈ B j`, where `B j = closedBall (w j) (r₁ (f j))`. Note that
since `d` has density one, `μ (W ∩ (B j)) / μ (B j) → 1`.
We obtain our contradiction by showing that there exists `η < 1` such that
`μ (W ∩ (B j)) / μ (B j) ≤ η` for sufficiently large `j`. In fact we claim that `η = 1 - C⁻¹`
is such a value where `C` is the scaling constant of `M⁻¹` for the uniformly locally doubling
measure `μ`.
To prove the claim, let `b j = closedBall (w j) (M * r₁ (f j))` and for given `j` consider the
sets `b j` and `W ∩ (B j)`. These are both subsets of `B j` and are disjoint for large enough `j`
since `M * r₁ j ≤ r₂ j` and thus `b j ⊆ Z i ⊆ Wᶜ`. We thus have:
`μ (b j) + μ (W ∩ (B j)) ≤ μ (B j)`. Combining this with `μ (B j) ≤ C * μ (b j)` we obtain
the required inequality. -/
set Y₁ : ℕ → Set α := fun i => cthickening (r₁ i) (s i)
set Y₂ : ℕ → Set α := fun i => cthickening (r₂ i) (s i)
let Z : ℕ → Set α := fun i => ⋃ (j) (_ : p j ∧ i ≤ j), Y₂ j
suffices ∀ i, μ (atTop.blimsup Y₁ p \ Z i) = 0 by
rwa [ae_le_set, @blimsup_eq_iInf_biSup_of_nat _ _ _ Y₂, iInf_eq_iInter, diff_iInter,
measure_iUnion_null_iff]
intros i
set W := atTop.blimsup Y₁ p \ Z i
by_contra contra
obtain ⟨d, hd, hd'⟩ : ∃ d, d ∈ W ∧ ∀ {ι : Type _} {l : Filter ι} (w : ι → α) (δ : ι → ℝ),
Tendsto δ l (𝓝[>] 0) → (∀ᶠ j in l, d ∈ closedBall (w j) (2 * δ j)) →
Tendsto (fun j => μ (W ∩ closedBall (w j) (δ j)) / μ (closedBall (w j) (δ j))) l (𝓝 1) :=
Measure.exists_mem_of_measure_ne_zero_of_ae contra
(IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div μ W 2)
replace hd : d ∈ blimsup Y₁ atTop p := ((mem_diff _).mp hd).1
obtain ⟨f : ℕ → ℕ, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup' atTop_basis hd
simp only [forall_and] at hf
obtain ⟨hf₀ : ∀ j, d ∈ cthickening (r₁ (f j)) (s (f j)), hf₁, hf₂ : ∀ j, j ≤ f j⟩ := hf
have hf₃ : Tendsto f atTop atTop :=
tendsto_atTop_atTop.mpr fun j => ⟨f j, fun i hi => (hf₂ j).trans (hi.trans <| hf₂ i)⟩
replace hr : Tendsto (r₁ ∘ f) atTop (𝓝[>] 0) := hr.comp hf₃
replace hMr : ∀ᶠ j in atTop, M * r₁ (f j) ≤ r₂ (f j) := hf₃.eventually hMr
replace hf₀ : ∀ j, ∃ w ∈ s (f j), d ∈ closedBall w (2 * r₁ (f j)) := by
intro j
specialize hrp (f j)
rw [Pi.zero_apply] at hrp
rcases eq_or_lt_of_le hrp with (hr0 | hrp')
· specialize hf₀ j
rw [← hr0, cthickening_zero, (hs (f j)).closure_eq] at hf₀
exact ⟨d, hf₀, by simp [← hr0]⟩
· simpa using mem_iUnion₂.mp (cthickening_subset_iUnion_closedBall_of_lt (s (f j))
(by positivity) (lt_two_mul_self hrp') (hf₀ j))
choose w hw hw' using hf₀
let C := IsUnifLocDoublingMeasure.scalingConstantOf μ M⁻¹
have hC : 0 < C :=
lt_of_lt_of_le zero_lt_one (IsUnifLocDoublingMeasure.one_le_scalingConstantOf μ M⁻¹)
suffices ∃ η < (1 : ℝ≥0),
∀ᶠ j in atTop, μ (W ∩ closedBall (w j) (r₁ (f j))) / μ (closedBall (w j) (r₁ (f j))) ≤ η by
obtain ⟨η, hη, hη'⟩ := this
replace hη' : 1 ≤ η := by
simpa only [ENNReal.one_le_coe_iff] using
le_of_tendsto (hd' w (fun j => r₁ (f j)) hr <| Eventually.of_forall hw') hη'
exact (lt_self_iff_false _).mp (lt_of_lt_of_le hη hη')
refine ⟨1 - C⁻¹, tsub_lt_self zero_lt_one (inv_pos.mpr hC), ?_⟩
replace hC : C ≠ 0 := ne_of_gt hC
let b : ℕ → Set α := fun j => closedBall (w j) (M * r₁ (f j))
let B : ℕ → Set α := fun j => closedBall (w j) (r₁ (f j))
have h₁ : ∀ j, b j ⊆ B j := fun j =>
closedBall_subset_closedBall (mul_le_of_le_one_left (hrp (f j)) hM'.le)
have h₂ : ∀ j, W ∩ B j ⊆ B j := fun j => inter_subset_right
have h₃ : ∀ᶠ j in atTop, Disjoint (b j) (W ∩ B j) := by
apply hMr.mp
rw [eventually_atTop]
refine
⟨i, fun j hj hj' => Disjoint.inf_right (B j) <| Disjoint.inf_right' (blimsup Y₁ atTop p) ?_⟩
change Disjoint (b j) (Z i)ᶜ
rw [disjoint_compl_right_iff_subset]
refine (closedBall_subset_cthickening (hw j) (M * r₁ (f j))).trans
((cthickening_mono hj' _).trans fun a ha => ?_)
simp only [Z, mem_iUnion, exists_prop]
exact ⟨f j, ⟨hf₁ j, hj.le.trans (hf₂ j)⟩, ha⟩
have h₄ : ∀ᶠ j in atTop, μ (B j) ≤ C * μ (b j) :=
(hr.eventually (IsUnifLocDoublingMeasure.eventually_measure_le_scaling_constant_mul'
μ M hM)).mono fun j hj => hj (w j)
refine (h₃.and h₄).mono fun j hj₀ => ?_
change μ (W ∩ B j) / μ (B j) ≤ ↑(1 - C⁻¹)
rcases eq_or_ne (μ (B j)) ∞ with (hB | hB); · simp [hB]
apply ENNReal.div_le_of_le_mul
rw [ENNReal.coe_sub, ENNReal.coe_one, ENNReal.sub_mul fun _ _ => hB, one_mul]
replace hB : ↑C⁻¹ * μ (B j) ≠ ∞ := by finiteness
obtain ⟨hj₁ : Disjoint (b j) (W ∩ B j), hj₂ : μ (B j) ≤ C * μ (b j)⟩ := hj₀
replace hj₂ : ↑C⁻¹ * μ (B j) ≤ μ (b j) := by
rw [ENNReal.coe_inv hC, ← ENNReal.div_eq_inv_mul]
exact ENNReal.div_le_of_le_mul' hj₂
have hj₃ : ↑C⁻¹ * μ (B j) + μ (W ∩ B j) ≤ μ (B j) := by
refine le_trans (add_le_add_right hj₂ _) ?_
rw [← measure_union' hj₁ measurableSet_closedBall]
exact measure_mono (union_subset (h₁ j) (h₂ j))
replace hj₃ := tsub_le_tsub_right hj₃ (↑C⁻¹ * μ (B j))
rwa [ENNReal.add_sub_cancel_left hB] at hj₃
/-- This is really an auxiliary result en route to `blimsup_cthickening_mul_ae_eq`.
NB: The `: Set α` type ascription is present because of
https://github.com/leanprover-community/mathlib/issues/16932. -/
theorem blimsup_cthickening_ae_le_of_eventually_mul_le (p : ℕ → Prop) {s : ℕ → Set α} {M : ℝ}
(hM : 0 < M) {r₁ r₂ : ℕ → ℝ} (hr : Tendsto r₁ atTop (𝓝[>] 0))
(hMr : ∀ᶠ i in atTop, M * r₁ i ≤ r₂ i) :
(blimsup (fun i => cthickening (r₁ i) (s i)) atTop p : Set α) ≤ᵐ[μ]
(blimsup (fun i => cthickening (r₂ i) (s i)) atTop p : Set α) := by
let R₁ i := max 0 (r₁ i)
let R₂ i := max 0 (r₂ i)
have hRp : 0 ≤ R₁ := fun i => le_max_left 0 (r₁ i)
replace hMr : ∀ᶠ i in atTop, M * R₁ i ≤ R₂ i := by
refine hMr.mono fun i hi ↦ ?_
rw [mul_max_of_nonneg _ _ hM.le, mul_zero]
exact max_le_max (le_refl 0) hi
simp_rw [← cthickening_max_zero (r₁ _), ← cthickening_max_zero (r₂ _)]
rcases le_or_gt 1 M with hM' | hM'
· apply HasSubset.Subset.eventuallyLE
change _ ≤ _
refine mono_blimsup' (hMr.mono fun i hi _ => cthickening_mono ?_ (s i))
exact (le_mul_of_one_le_left (hRp i) hM').trans hi
· simp only [← @cthickening_closure _ _ _ (s _)]
have hs : ∀ i, IsClosed (closure (s i)) := fun i => isClosed_closure
exact blimsup_cthickening_ae_le_of_eventually_mul_le_aux μ p hs
(tendsto_nhds_max_right hr) hRp hM hM' hMr
/-- Given a sequence of subsets `sᵢ` of a metric space, together with a sequence of radii `rᵢ`
such that `rᵢ → 0`, the set of points which belong to infinitely many of the closed
`rᵢ`-thickenings of `sᵢ` is unchanged almost everywhere for a uniformly locally doubling measure if
the `rᵢ` are all scaled by a positive constant.
This lemma is a generalisation of Lemma 9 appearing on page 217 of
[J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950).
See also `blimsup_thickening_mul_ae_eq`.
NB: The `: Set α` type ascription is present because of
https://github.com/leanprover-community/mathlib/issues/16932. -/
theorem blimsup_cthickening_mul_ae_eq (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M)
(r : ℕ → ℝ) (hr : Tendsto r atTop (𝓝 0)) :
(blimsup (fun i => cthickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ]
(blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) := by
have : ∀ (p : ℕ → Prop) {r : ℕ → ℝ} (_ : Tendsto r atTop (𝓝[>] 0)),
(blimsup (fun i => cthickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ]
(blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) := by
clear p hr r; intro p r hr
have hr' : Tendsto (fun i => M * r i) atTop (𝓝[>] 0) := by
convert TendstoNhdsWithinIoi.const_mul hM hr <;> simp only [mul_zero]
refine eventuallyLE_antisymm_iff.mpr ⟨?_, ?_⟩
· exact blimsup_cthickening_ae_le_of_eventually_mul_le μ p (inv_pos.mpr hM) hr'
(Eventually.of_forall fun i => by rw [inv_mul_cancel_left₀ hM.ne' (r i)])
· exact blimsup_cthickening_ae_le_of_eventually_mul_le μ p hM hr
(Eventually.of_forall fun i => le_refl _)
let r' : ℕ → ℝ := fun i => if 0 < r i then r i else 1 / ((i : ℝ) + 1)
have hr' : Tendsto r' atTop (𝓝[>] 0) := by
refine tendsto_nhdsWithin_iff.mpr
⟨Tendsto.if' hr tendsto_one_div_add_atTop_nhds_zero_nat, Eventually.of_forall fun i => ?_⟩
by_cases hi : 0 < r i
· simp [r', hi]
· simp only [r', hi, one_div, mem_Ioi, if_false, inv_pos]; positivity
have h₀ : ∀ i, p i ∧ 0 < r i → cthickening (r i) (s i) = cthickening (r' i) (s i) := by
grind
have h₁ : ∀ i, p i ∧ 0 < r i → cthickening (M * r i) (s i) = cthickening (M * r' i) (s i) := by
rintro i ⟨-, hi⟩; simp only [r', hi, if_true]
have h₂ : ∀ i, p i ∧ r i ≤ 0 → cthickening (M * r i) (s i) = cthickening (r i) (s i) := by
rintro i ⟨-, hi⟩
have hi' : M * r i ≤ 0 := mul_nonpos_of_nonneg_of_nonpos hM.le hi
rw [cthickening_of_nonpos hi, cthickening_of_nonpos hi']
have hp : p = fun i => p i ∧ 0 < r i ∨ p i ∧ r i ≤ 0 := by
ext i; simp [← and_or_left, lt_or_ge 0 (r i)]
rw [hp, blimsup_or_eq_sup, blimsup_or_eq_sup]
simp only [sup_eq_union]
rw [blimsup_congr (Eventually.of_forall h₀), blimsup_congr (Eventually.of_forall h₁),
blimsup_congr (Eventually.of_forall h₂)]
exact ae_eq_set_union (this (fun i => p i ∧ 0 < r i) hr') (ae_eq_refl _)
theorem blimsup_cthickening_ae_eq_blimsup_thickening {p : ℕ → Prop} {s : ℕ → Set α} {r : ℕ → ℝ}
(hr : Tendsto r atTop (𝓝 0)) (hr' : ∀ᶠ i in atTop, p i → 0 < r i) :
(blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) =ᵐ[μ]
(blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by
refine eventuallyLE_antisymm_iff.mpr ⟨?_, HasSubset.Subset.eventuallyLE (?_ : _ ≤ _)⟩
· rw [eventuallyLE_congr (blimsup_cthickening_mul_ae_eq μ p s (one_half_pos (α := ℝ)) r hr).symm
EventuallyEq.rfl]
apply HasSubset.Subset.eventuallyLE
change _ ≤ _
refine mono_blimsup' (hr'.mono fun i hi pi => cthickening_subset_thickening' (hi pi) ?_ (s i))
nlinarith [hi pi]
· exact mono_blimsup fun i _ => thickening_subset_cthickening _ _
/-- An auxiliary result en route to `blimsup_thickening_mul_ae_eq`. -/
theorem blimsup_thickening_mul_ae_eq_aux (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M)
(r : ℕ → ℝ) (hr : Tendsto r atTop (𝓝 0)) (hr' : ∀ᶠ i in atTop, p i → 0 < r i) :
(blimsup (fun i => thickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ]
(blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by
have h₁ := blimsup_cthickening_ae_eq_blimsup_thickening (s := s) μ hr hr'
have h₂ := blimsup_cthickening_mul_ae_eq μ p s hM r hr
replace hr : Tendsto (fun i => M * r i) atTop (𝓝 0) := by convert hr.const_mul M; simp
replace hr' : ∀ᶠ i in atTop, p i → 0 < M * r i := hr'.mono fun i hi hip ↦ mul_pos hM (hi hip)
have h₃ := blimsup_cthickening_ae_eq_blimsup_thickening (s := s) μ hr hr'
exact h₃.symm.trans (h₂.trans h₁)
/-- Given a sequence of subsets `sᵢ` of a metric space, together with a sequence of radii `rᵢ`
such that `rᵢ → 0`, the set of points which belong to infinitely many of the
`rᵢ`-thickenings of `sᵢ` is unchanged almost everywhere for a uniformly locally doubling measure if
the `rᵢ` are all scaled by a positive constant.
This lemma is a generalisation of Lemma 9 appearing on page 217 of
[J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950).
See also `blimsup_cthickening_mul_ae_eq`.
NB: The `: Set α` type ascription is present because of
https://github.com/leanprover-community/mathlib/issues/16932. -/
theorem blimsup_thickening_mul_ae_eq (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M) (r : ℕ → ℝ)
(hr : Tendsto r atTop (𝓝 0)) :
(blimsup (fun i => thickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ]
(blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by
let q : ℕ → Prop := fun i => p i ∧ 0 < r i
have h₁ : blimsup (fun i => thickening (r i) (s i)) atTop p =
blimsup (fun i => thickening (r i) (s i)) atTop q := by
refine blimsup_congr' (Eventually.of_forall fun i h => ?_)
replace hi : 0 < r i := by contrapose! h; apply thickening_of_nonpos h
simp only [q, hi, iff_self_and, imp_true_iff]
have h₂ : blimsup (fun i => thickening (M * r i) (s i)) atTop p =
blimsup (fun i => thickening (M * r i) (s i)) atTop q := by
refine blimsup_congr' (Eventually.of_forall fun i h ↦ ?_)
replace h : 0 < r i := by
rw [← mul_pos_iff_of_pos_left hM]; contrapose! h; apply thickening_of_nonpos h
simp only [q, h, iff_self_and, imp_true_iff]
rw [h₁, h₂]
exact blimsup_thickening_mul_ae_eq_aux μ q s hM r hr (Eventually.of_forall fun i hi => hi.2)
|
RegularExpressions.lean
|
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson
-/
import Mathlib.Computability.Language
import Mathlib.Tactic.AdaptationNote
/-!
# Regular Expressions
This file contains the formal definition for regular expressions and basic lemmas. Note these are
regular expressions in terms of formal language theory. Note this is different to regex's used in
computer science such as the POSIX standard.
## TODO
Currently, we don't show that regular expressions and DFA/NFA's are equivalent.
Multiple competing PRs towards that goal are in review.
See https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Regular.20languages.3A.20the.20review.20queue
-/
open List Set
open Computability
universe u
variable {α β γ : Type*}
-- Disable generation of unneeded lemmas which the simpNF linter would complain about.
set_option genSizeOfSpec false in
set_option genInjectivity false in
/-- This is the definition of regular expressions. The names used here is to mirror the definition
of a Kleene algebra (https://en.wikipedia.org/wiki/Kleene_algebra).
* `0` (`zero`) matches nothing
* `1` (`epsilon`) matches only the empty string
* `char a` matches only the string 'a'
* `star P` matches any finite concatenation of strings which match `P`
* `P + Q` (`plus P Q`) matches anything which match `P` or `Q`
* `P * Q` (`comp P Q`) matches `x ++ y` if `x` matches `P` and `y` matches `Q`
-/
inductive RegularExpression (α : Type u) : Type u
| zero : RegularExpression α
| epsilon : RegularExpression α
| char : α → RegularExpression α
| plus : RegularExpression α → RegularExpression α → RegularExpression α
| comp : RegularExpression α → RegularExpression α → RegularExpression α
| star : RegularExpression α → RegularExpression α
namespace RegularExpression
variable {a b : α}
instance : Inhabited (RegularExpression α) :=
⟨zero⟩
instance : Add (RegularExpression α) :=
⟨plus⟩
instance : Mul (RegularExpression α) :=
⟨comp⟩
instance : One (RegularExpression α) :=
⟨epsilon⟩
instance : Zero (RegularExpression α) :=
⟨zero⟩
instance : Pow (RegularExpression α) ℕ :=
⟨fun n r => npowRec r n⟩
@[simp]
theorem zero_def : (zero : RegularExpression α) = 0 :=
rfl
@[simp]
theorem one_def : (epsilon : RegularExpression α) = 1 :=
rfl
@[simp]
theorem plus_def (P Q : RegularExpression α) : plus P Q = P + Q :=
rfl
@[simp]
theorem comp_def (P Q : RegularExpression α) : comp P Q = P * Q :=
rfl
-- This was renamed to `matches'` during the port of Lean 4 as `matches` is a reserved word.
/-- `matches' P` provides a language which contains all strings that `P` matches -/
-- Porting note: was '@[simp] but removed based on
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/simpNF.20issues.20in.20Computability.2ERegularExpressions.20!4.232306/near/328355362
def matches' : RegularExpression α → Language α
| 0 => 0
| 1 => 1
| char a => {[a]}
| P + Q => P.matches' + Q.matches'
| P * Q => P.matches' * Q.matches'
| star P => P.matches'∗
@[simp]
theorem matches'_zero : (0 : RegularExpression α).matches' = 0 :=
rfl
@[simp]
theorem matches'_epsilon : (1 : RegularExpression α).matches' = 1 :=
rfl
@[simp]
theorem matches'_char (a : α) : (char a).matches' = {[a]} :=
rfl
@[simp]
theorem matches'_add (P Q : RegularExpression α) : (P + Q).matches' = P.matches' + Q.matches' :=
rfl
@[simp]
theorem matches'_mul (P Q : RegularExpression α) : (P * Q).matches' = P.matches' * Q.matches' :=
rfl
@[simp]
theorem matches'_pow (P : RegularExpression α) : ∀ n : ℕ, (P ^ n).matches' = P.matches' ^ n
| 0 => matches'_epsilon
| n + 1 => (matches'_mul _ _).trans <| Eq.trans
(congrFun (congrArg HMul.hMul (matches'_pow P n)) (matches' P))
(pow_succ _ n).symm
@[simp]
theorem matches'_star (P : RegularExpression α) : P.star.matches' = P.matches'∗ :=
rfl
/-- `matchEpsilon P` is true if and only if `P` matches the empty string -/
def matchEpsilon : RegularExpression α → Bool
| 0 => false
| 1 => true
| char _ => false
| P + Q => P.matchEpsilon || Q.matchEpsilon
| P * Q => P.matchEpsilon && Q.matchEpsilon
| star _P => true
section DecidableEq
variable [DecidableEq α]
/-- `P.deriv a` matches `x` if `P` matches `a :: x`, the Brzozowski derivative of `P` with respect
to `a` -/
def deriv : RegularExpression α → α → RegularExpression α
| 0, _ => 0
| 1, _ => 0
| char a₁, a₂ => if a₁ = a₂ then 1 else 0
| P + Q, a => deriv P a + deriv Q a
| P * Q, a => if P.matchEpsilon then deriv P a * Q + deriv Q a else deriv P a * Q
| star P, a => deriv P a * star P
@[simp]
theorem deriv_zero (a : α) : deriv 0 a = 0 :=
rfl
@[simp]
theorem deriv_one (a : α) : deriv 1 a = 0 :=
rfl
@[simp]
theorem deriv_char_self (a : α) : deriv (char a) a = 1 :=
if_pos rfl
@[simp]
theorem deriv_char_of_ne (h : a ≠ b) : deriv (char a) b = 0 :=
if_neg h
@[simp]
theorem deriv_add (P Q : RegularExpression α) (a : α) : deriv (P + Q) a = deriv P a + deriv Q a :=
rfl
@[simp]
theorem deriv_star (P : RegularExpression α) (a : α) : deriv P.star a = deriv P a * star P :=
rfl
/-- `P.rmatch x` is true if and only if `P` matches `x`. This is a computable definition equivalent
to `matches'`. -/
def rmatch : RegularExpression α → List α → Bool
| P, [] => matchEpsilon P
| P, a :: as => rmatch (P.deriv a) as
@[simp]
theorem zero_rmatch (x : List α) : rmatch 0 x = false := by
induction x <;> simp [rmatch, matchEpsilon, *]
theorem one_rmatch_iff (x : List α) : rmatch 1 x ↔ x = [] := by
induction x <;> simp [rmatch, matchEpsilon, *]
theorem char_rmatch_iff (a : α) (x : List α) : rmatch (char a) x ↔ x = [a] := by
rcases x with - | ⟨_, x⟩
· exact of_decide_eq_true rfl
· rcases x with - | ⟨head, tail⟩
· rw [rmatch, deriv, List.singleton_inj]
split <;> tauto
· rw [rmatch, rmatch, deriv, cons.injEq]
split
· simp_rw [deriv_one, zero_rmatch, reduceCtorEq, and_false]
· simp_rw [deriv_zero, zero_rmatch, reduceCtorEq, and_false]
theorem add_rmatch_iff (P Q : RegularExpression α) (x : List α) :
(P + Q).rmatch x ↔ P.rmatch x ∨ Q.rmatch x := by
induction x generalizing P Q with
| nil => simp only [rmatch, matchEpsilon, Bool.or_eq_true_iff]
| cons _ _ ih =>
rw [rmatch, deriv_add]
exact ih _ _
theorem mul_rmatch_iff (P Q : RegularExpression α) (x : List α) :
(P * Q).rmatch x ↔ ∃ t u : List α, x = t ++ u ∧ P.rmatch t ∧ Q.rmatch u := by
induction x generalizing P Q with
| nil =>
rw [rmatch]; simp only [matchEpsilon]
constructor
· intro h
refine ⟨[], [], rfl, ?_⟩
rw [rmatch, rmatch]
rwa [Bool.and_eq_true_iff] at h
· rintro ⟨t, u, h₁, h₂⟩
obtain ⟨ht, hu⟩ := List.append_eq_nil_iff.1 h₁.symm
subst ht hu
repeat rw [rmatch] at h₂
simp [h₂]
| cons a x ih =>
rw [rmatch]; simp only [deriv]
split_ifs with hepsilon
· rw [add_rmatch_iff, ih]
constructor
· rintro (⟨t, u, _⟩ | h)
· exact ⟨a :: t, u, by tauto⟩
· exact ⟨[], a :: x, rfl, hepsilon, h⟩
· rintro ⟨t, u, h, hP, hQ⟩
rcases t with - | ⟨b, t⟩
· right
rw [List.nil_append] at h
rw [← h] at hQ
exact hQ
· left
rw [List.cons_append, List.cons_eq_cons] at h
refine ⟨t, u, h.2, ?_, hQ⟩
rw [rmatch] at hP
convert hP
exact h.1
· rw [ih]
constructor <;> rintro ⟨t, u, h, hP, hQ⟩
· exact ⟨a :: t, u, by tauto⟩
· rcases t with - | ⟨b, t⟩
· contradiction
· rw [List.cons_append, List.cons_eq_cons] at h
refine ⟨t, u, h.2, ?_, hQ⟩
rw [rmatch] at hP
convert hP
exact h.1
theorem star_rmatch_iff (P : RegularExpression α) :
∀ x : List α, (star P).rmatch x ↔ ∃ S : List (List α), x
= S.flatten ∧ ∀ t ∈ S, t ≠ [] ∧ P.rmatch t :=
fun x => by
have IH := fun t (_h : List.length t < List.length x) => star_rmatch_iff P t
clear star_rmatch_iff
constructor
· rcases x with - | ⟨a, x⟩
· intro _h
use []; dsimp; tauto
· rw [rmatch, deriv, mul_rmatch_iff]
rintro ⟨t, u, hs, ht, hu⟩
have hwf : u.length < (List.cons a x).length := by
rw [hs, List.length_cons, List.length_append]
omega
rw [IH _ hwf] at hu
rcases hu with ⟨S', hsum, helem⟩
use (a :: t) :: S'
constructor
· simp [hs, hsum]
· intro t' ht'
cases ht' with
| head ht' =>
simp only [ne_eq, not_false_iff, true_and, rmatch, reduceCtorEq]
exact ht
| tail _ ht' => exact helem t' ht'
· rintro ⟨S, hsum, helem⟩
rcases x with - | ⟨a, x⟩
· rfl
· rw [rmatch, deriv, mul_rmatch_iff]
rcases S with - | ⟨t', U⟩
· exact ⟨[], [], by tauto⟩
· obtain - | ⟨b, t⟩ := t'
· simp only [forall_eq_or_imp, List.mem_cons] at helem
simp only [not_true, Ne, false_and] at helem
simp only [List.flatten, List.cons_append, List.cons_eq_cons] at hsum
refine ⟨t, U.flatten, hsum.2, ?_, ?_⟩
· specialize helem (b :: t) (by simp)
rw [rmatch] at helem
convert helem.2
exact hsum.1
· grind
termination_by t => (P, t.length)
@[simp]
theorem rmatch_iff_matches' (P : RegularExpression α) (x : List α) :
P.rmatch x ↔ x ∈ P.matches' := by
induction P generalizing x with
| zero =>
rw [zero_def, zero_rmatch]
tauto
| epsilon =>
rw [one_def, one_rmatch_iff, matches'_epsilon, Language.mem_one]
| char =>
rw [char_rmatch_iff]
rfl
| plus _ _ ih₁ ih₂ =>
rw [plus_def, add_rmatch_iff, ih₁, ih₂]
rfl
| comp P Q ih₁ ih₂ =>
simp only [comp_def, mul_rmatch_iff, matches'_mul, Language.mem_mul, *]
tauto
| star _ ih =>
simp only [star_rmatch_iff, matches'_star, ih, Language.mem_kstar_iff_exists_nonempty, and_comm]
instance (P : RegularExpression α) : DecidablePred (· ∈ P.matches') := fun _ ↦
decidable_of_iff _ (rmatch_iff_matches' _ _)
end DecidableEq
/-- Map the alphabet of a regular expression. -/
@[simp]
def map (f : α → β) : RegularExpression α → RegularExpression β
| 0 => 0
| 1 => 1
| char a => char (f a)
| R + S => map f R + map f S
| R * S => map f R * map f S
| star R => star (map f R)
@[simp]
protected theorem map_pow (f : α → β) (P : RegularExpression α) :
∀ n : ℕ, map f (P ^ n) = map f P ^ n
| 0 => by unfold map; rfl
| n + 1 => (congr_arg (· * map f P) (RegularExpression.map_pow f P n) :)
@[simp]
theorem map_id : ∀ P : RegularExpression α, P.map id = P
| 0 => rfl
| 1 => rfl
| char _ => rfl
| R + S => by simp_rw [map, map_id]
| R * S => by simp_rw [map, map_id]
| star R => by simp_rw [map, map_id]
@[simp]
theorem map_map (g : β → γ) (f : α → β) : ∀ P : RegularExpression α, (P.map f).map g = P.map (g ∘ f)
| 0 => rfl
| 1 => rfl
| char _ => rfl
| R + S => by simp only [map, map_map]
| R * S => by simp only [map, map_map]
| star R => by simp only [map, map_map]
/-- The language of the map is the map of the language. -/
@[simp]
theorem matches'_map (f : α → β) :
∀ P : RegularExpression α, (P.map f).matches' = Language.map f P.matches'
| 0 => (map_zero _).symm
| 1 => (map_one _).symm
| char a => by
rw [eq_comm]
exact image_singleton
| R + S => by simp only [matches'_map, map, matches'_add, map_add]
| R * S => by simp [matches'_map]
| star R => by simp [matches'_map]
end RegularExpression
|
Covolume.lean
|
/-
Copyright (c) 2024 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Analysis.BoxIntegral.UnitPartition
import Mathlib.LinearAlgebra.FreeModule.Finite.CardQuotient
import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace
/-!
# Covolume of ℤ-lattices
Let `E` be a finite dimensional real vector space.
Let `L` be a `ℤ`-lattice `L` defined as a discrete `ℤ`-submodule of `E` that spans `E` over `ℝ`.
## Main definitions and results
* `ZLattice.covolume`: the covolume of `L` defined as the volume of an arbitrary fundamental
domain of `L`.
* `ZLattice.covolume_eq_measure_fundamentalDomain`: the covolume of `L` does not depend on the
choice of the fundamental domain of `L`.
* `ZLattice.covolume_eq_det`: if `L` is a lattice in `ℝ^n`, then its covolume is the absolute
value of the determinant of any `ℤ`-basis of `L`.
* `ZLattice.covolume_div_covolume_eq_relindex`: Let `L₁` be a sub-`ℤ`-lattice of `L₂`. Then the
index of `L₁` inside `L₂` is equal to `covolume L₁ / covolume L₂`.
* `ZLattice.covolume.tendsto_card_div_pow`: Let `s` be a bounded measurable set of `ι → ℝ`, then
the number of points in `s ∩ n⁻¹ • L` divided by `n ^ card ι` tends to `volume s / covolume L`
when `n : ℕ` tends to infinity.
See also `ZLattice.covolume.tendsto_card_div_pow'` for a version for `InnerProductSpace ℝ E` and
`ZLattice.covolume.tendsto_card_div_pow''` for the general version.
* `ZLattice.covolume.tendsto_card_le_div`: Let `X` be a cone in `ι → ℝ` and let `F : (ι → ℝ) → ℝ`
be a function such that `F (c • x) = c ^ card ι * F x`. Then the number of points `x ∈ X` such
that `F x ≤ c` divided by `c` tends to `volume {x ∈ X | F x ≤ 1} / covolume L`
when `c : ℝ` tends to infinity.
See also `ZLattice.covolume.tendsto_card_le_div'` for a version for `InnerProductSpace ℝ E` and
`ZLattice.covolume.tendsto_card_le_div''` for the general version.
## Naming convention
Some results are true in the case where the ambient finite dimensional real vector space is the
pi-space `ι → ℝ` and in the case where it is an `InnerProductSpace`. We use the following
convention: the plain name is for the pi case, for eg. `volume_image_eq_volume_div_covolume`. For
the same result in the `InnerProductSpace` case, we add a `prime`, for eg.
`volume_image_eq_volume_div_covolume'`. When the same result exists in the
general case, we had two primes, eg. `covolume.tendsto_card_div_pow''`.
-/
noncomputable section
namespace ZLattice
open Submodule MeasureTheory Module MeasureTheory Module ZSpan
section General
variable {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] (L : Submodule ℤ E)
/-- The covolume of a `ℤ`-lattice is the volume of some fundamental domain; see
`ZLattice.covolume_eq_volume` for the proof that the volume does not depend on the choice of
the fundamental domain. -/
def covolume (μ : Measure E := by volume_tac) : ℝ := (addCovolume L E μ).toReal
end General
section Basic
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E]
variable [MeasurableSpace E] [BorelSpace E]
variable (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L]
variable (μ : Measure E := by volume_tac) [Measure.IsAddHaarMeasure μ]
theorem covolume_eq_measure_fundamentalDomain {F : Set E} (h : IsAddFundamentalDomain L F μ) :
covolume L μ = μ.real F := by
have : MeasurableVAdd L E := (inferInstance : MeasurableVAdd L.toAddSubgroup E)
have : VAddInvariantMeasure L E μ := (inferInstance : VAddInvariantMeasure L.toAddSubgroup E μ)
exact congr_arg ENNReal.toReal (h.covolume_eq_volume μ)
theorem covolume_ne_zero : covolume L μ ≠ 0 := by
rw [covolume_eq_measure_fundamentalDomain L μ (isAddFundamentalDomain (Free.chooseBasis ℤ L) μ),
measureReal_ne_zero_iff (ne_of_lt _)]
· exact measure_fundamentalDomain_ne_zero _
· exact Bornology.IsBounded.measure_lt_top (fundamentalDomain_isBounded _)
theorem covolume_pos : 0 < covolume L μ :=
lt_of_le_of_ne ENNReal.toReal_nonneg (covolume_ne_zero L μ).symm
theorem covolume_comap {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [FiniteDimensional ℝ F]
[MeasurableSpace F] [BorelSpace F] (ν : Measure F := by volume_tac) [Measure.IsAddHaarMeasure ν]
{e : F ≃L[ℝ] E} (he : MeasurePreserving e ν μ) :
covolume (ZLattice.comap ℝ L e.toLinearMap) ν = covolume L μ := by
rw [covolume_eq_measure_fundamentalDomain _ _ (isAddFundamentalDomain (Free.chooseBasis ℤ L) μ),
covolume_eq_measure_fundamentalDomain _ _ ((isAddFundamentalDomain
((Free.chooseBasis ℤ L).ofZLatticeComap ℝ L e.toLinearEquiv) ν)), ← he.measureReal_preimage
(fundamentalDomain_measurableSet _).nullMeasurableSet, ← e.image_symm_eq_preimage,
← e.symm.coe_toLinearEquiv, map_fundamentalDomain]
congr!
ext; simp
theorem covolume_eq_det_mul_measureReal {ι : Type*} [Fintype ι] [DecidableEq ι] (b : Basis ι ℤ L)
(b₀ : Basis ι ℝ E) :
covolume L μ = |b₀.det ((↑) ∘ b)| * μ.real (fundamentalDomain b₀) := by
rw [covolume_eq_measure_fundamentalDomain L μ (isAddFundamentalDomain b μ),
measureReal_fundamentalDomain _ _ b₀,
measureReal_congr (fundamentalDomain_ae_parallelepiped b₀ μ)]
congr
ext
exact b.ofZLatticeBasis_apply ℝ L _
@[deprecated (since := "2025-04-19")]
alias covolume_eq_det_mul_measure := covolume_eq_det_mul_measureReal
theorem covolume_eq_det {ι : Type*} [Fintype ι] [DecidableEq ι] (L : Submodule ℤ (ι → ℝ))
[DiscreteTopology L] [IsZLattice ℝ L] (b : Basis ι ℤ L) :
covolume L = |(Matrix.of ((↑) ∘ b)).det| := by
rw [covolume_eq_measure_fundamentalDomain L volume (isAddFundamentalDomain b volume),
volume_real_fundamentalDomain]
congr
ext1
exact b.ofZLatticeBasis_apply ℝ L _
theorem covolume_eq_det_inv {ι : Type*} [Fintype ι] (L : Submodule ℤ (ι → ℝ))
[DiscreteTopology L] [IsZLattice ℝ L] (b : Basis ι ℤ L) :
covolume L = |(LinearEquiv.det (b.ofZLatticeBasis ℝ L).equivFun : ℝ)|⁻¹ := by
classical
rw [covolume_eq_det L b, ← Pi.basisFun_det_apply, show (((↑) : L → _) ∘ ⇑b) =
(b.ofZLatticeBasis ℝ) by ext; simp, ← Basis.det_inv, ← abs_inv, Units.val_inv_eq_inv_val,
IsUnit.unit_spec, ← Basis.det_basis, LinearEquiv.coe_det]
rfl
/--
Let `L₁` be a sub-`ℤ`-lattice of `L₂`. Then the index of `L₁` inside `L₂` is equal to
`covolume L₁ / covolume L₂`.
-/
theorem covolume_div_covolume_eq_relindex {ι : Type*} [Fintype ι] (L₁ L₂ : Submodule ℤ (ι → ℝ))
[DiscreteTopology L₁] [IsZLattice ℝ L₁] [DiscreteTopology L₂] [IsZLattice ℝ L₂] (h : L₁ ≤ L₂) :
covolume L₁ / covolume L₂ = L₁.toAddSubgroup.relindex L₂.toAddSubgroup := by
classical
let b₁ := IsZLattice.basis L₁
let b₂ := IsZLattice.basis L₂
rw [AddSubgroup.relindex_eq_natAbs_det L₁.toAddSubgroup L₂.toAddSubgroup h b₁ b₂,
Nat.cast_natAbs, Int.cast_abs]
trans |(b₂.ofZLatticeBasis ℝ).det (b₁.ofZLatticeBasis ℝ)|
· rw [← Basis.det_mul_det _ (Pi.basisFun ℝ ι) _, abs_mul, Pi.basisFun_det_apply,
← Basis.det_inv, Units.val_inv_eq_inv_val, IsUnit.unit_spec, Pi.basisFun_det_apply,
covolume_eq_det _ b₁, covolume_eq_det _ b₂, mul_comm, abs_inv]
congr 3 <;> ext <;> simp
· rw [Basis.det_apply, Basis.det_apply, Int.cast_det]
congr; ext i j
rw [Matrix.map_apply, Basis.toMatrix_apply, Basis.toMatrix_apply, Basis.ofZLatticeBasis_apply]
exact (b₂.ofZLatticeBasis_repr_apply ℝ L₂ ⟨b₁ j, h (coe_mem _)⟩ i)
/--
A more general version of `covolume_div_covolume_eq_relindex`;
see the `Naming conventions` section in the introduction.
-/
theorem covolume_div_covolume_eq_relindex' {E : Type*} [NormedAddCommGroup E]
[InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
(L₁ L₂ : Submodule ℤ E) [DiscreteTopology L₁] [IsZLattice ℝ L₁] [DiscreteTopology L₂]
[IsZLattice ℝ L₂] (h : L₁ ≤ L₂) :
covolume L₁ / covolume L₂ = L₁.toAddSubgroup.relindex L₂.toAddSubgroup := by
let f := (EuclideanSpace.equiv _ ℝ).symm.trans
(stdOrthonormalBasis ℝ E).repr.toContinuousLinearEquiv.symm
have hf : MeasurePreserving f := (stdOrthonormalBasis ℝ E).measurePreserving_repr_symm.comp
(EuclideanSpace.volume_preserving_measurableEquiv _).symm
rw [← covolume_comap L₁ volume volume hf, ← covolume_comap L₂ volume volume hf,
covolume_div_covolume_eq_relindex _ _ (fun _ h' ↦ h h'), ZLattice.comap_toAddSubgroup,
ZLattice.comap_toAddSubgroup, Nat.cast_inj, LinearEquiv.toAddMonoidHom_commutes,
AddSubgroup.comap_equiv_eq_map_symm', AddSubgroup.comap_equiv_eq_map_symm',
AddSubgroup.relindex_map_map_of_injective _ _ f.symm.injective]
theorem volume_image_eq_volume_div_covolume {ι : Type*} [Fintype ι] (L : Submodule ℤ (ι → ℝ))
[DiscreteTopology L] [IsZLattice ℝ L] (b : Basis ι ℤ L) {s : Set (ι → ℝ)} :
volume ((b.ofZLatticeBasis ℝ L).equivFun '' s) = volume s / ENNReal.ofReal (covolume L) := by
rw [LinearEquiv.image_eq_preimage, Measure.addHaar_preimage_linearEquiv, LinearEquiv.symm_symm,
covolume_eq_det_inv L b, ENNReal.div_eq_inv_mul, ENNReal.ofReal_inv_of_pos
(abs_pos.mpr (LinearEquiv.det _).ne_zero), inv_inv, LinearEquiv.coe_det]
/-- A more general version of `ZLattice.volume_image_eq_volume_div_covolume`;
see the `Naming conventions` section in the introduction. -/
theorem volume_image_eq_volume_div_covolume' {E : Type*} [NormedAddCommGroup E]
[InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
(L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L] {ι : Type*} [Fintype ι]
(b : Basis ι ℤ L) {s : Set E} (hs : NullMeasurableSet s) :
volume ((b.ofZLatticeBasis ℝ).equivFun '' s) = volume s / ENNReal.ofReal (covolume L) := by
classical
let e : Fin (finrank ℝ E) ≃ ι :=
Fintype.equivOfCardEq (by rw [Fintype.card_fin, finrank_eq_card_basis (b.ofZLatticeBasis ℝ)])
let f := (EuclideanSpace.equiv ι ℝ).symm.trans
((stdOrthonormalBasis ℝ E).reindex e).repr.toContinuousLinearEquiv.symm
have hf : MeasurePreserving f :=
((stdOrthonormalBasis ℝ E).reindex e).measurePreserving_repr_symm.comp
(EuclideanSpace.volume_preserving_measurableEquiv ι).symm
rw [← hf.measure_preimage hs, ← (covolume_comap L volume volume hf),
← volume_image_eq_volume_div_covolume (ZLattice.comap ℝ L f.toLinearMap)
(b.ofZLatticeComap ℝ L f.toLinearEquiv), Basis.ofZLatticeBasis_comap,
← f.image_symm_eq_preimage, ← Set.image_comp]
simp
end Basic
namespace covolume
section General
open Filter Fintype Pointwise Topology BoxIntegral Bornology
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
variable {L : Submodule ℤ E} [DiscreteTopology L] [IsZLattice ℝ L]
variable {ι : Type*} [Fintype ι] (b : Basis ι ℤ L)
/-- A version of `ZLattice.covolume.tendsto_card_div_pow` for the general case;
see the `Naming convention` section in the introduction. -/
theorem tendsto_card_div_pow'' [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
{s : Set E} (hs₁ : IsBounded s) (hs₂ : MeasurableSet s)
(hs₃ : volume (frontier ((b.ofZLatticeBasis ℝ).equivFun '' s)) = 0) :
Tendsto (fun n : ℕ ↦ (Nat.card (s ∩ (n : ℝ)⁻¹ • L : Set E) : ℝ) / n ^ card ι)
atTop (𝓝 (volume.real ((b.ofZLatticeBasis ℝ).equivFun '' s))) := by
refine Tendsto.congr' ?_
(tendsto_card_div_pow_atTop_volume ((b.ofZLatticeBasis ℝ).equivFun '' s) ?_ ?_ hs₃)
· filter_upwards [eventually_gt_atTop 0] with n hn
congr
refine Nat.card_congr <| ((b.ofZLatticeBasis ℝ).equivFun.toEquiv.subtypeEquiv fun x ↦ ?_).symm
simp_rw [Set.mem_inter_iff, ← b.ofZLatticeBasis_span ℝ, LinearEquiv.coe_toEquiv,
Basis.equivFun_apply, Set.mem_image, DFunLike.coe_fn_eq, EmbeddingLike.apply_eq_iff_eq,
exists_eq_right, and_congr_right_iff, Set.mem_inv_smul_set_iff₀
(mod_cast hn.ne' : (n : ℝ) ≠ 0), ← Finsupp.coe_smul, ← LinearEquiv.map_smul, SetLike.mem_coe,
Basis.mem_span_iff_repr_mem, Pi.basisFun_repr, implies_true]
· rw [← NormedSpace.isVonNBounded_iff ℝ] at hs₁ ⊢
exact Bornology.IsVonNBounded.image hs₁ ((b.ofZLatticeBasis ℝ).equivFunL : E →L[ℝ] ι → ℝ)
· exact (b.ofZLatticeBasis ℝ).equivFunL.toHomeomorph.toMeasurableEquiv.measurableSet_image.mpr hs₂
private theorem tendsto_card_le_div''_aux
{X : Set E} (hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X)
{F : E → ℝ} (hF₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ card ι * (F x)) {c : ℝ} (hc : 0 < c) :
c • {x ∈ X | F x ≤ 1} = {x ∈ X | F x ≤ c ^ card ι} := by
ext x
simp_rw [Set.mem_smul_set_iff_inv_smul_mem₀ hc.ne', Set.mem_setOf_eq, hF₁ _
(inv_pos_of_pos hc).le, inv_pow, inv_mul_le_iff₀ (pow_pos hc _), mul_one, and_congr_left_iff]
exact fun _ ↦ ⟨fun h ↦ (smul_inv_smul₀ hc.ne' x) ▸ hX h hc, fun h ↦ hX h (inv_pos_of_pos hc)⟩
/-- A version of `ZLattice.covolume.tendsto_card_le_div` for the general case;
see the `Naming conventions` section in the introduction. -/
theorem tendsto_card_le_div'' [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E]
[Nonempty ι] {X : Set E} (hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X)
{F : E → ℝ} (h₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ card ι * (F x))
(h₂ : IsBounded {x ∈ X | F x ≤ 1}) (h₃ : MeasurableSet {x ∈ X | F x ≤ 1})
(h₄ : volume (frontier ((b.ofZLatticeBasis ℝ L).equivFun '' {x | x ∈ X ∧ F x ≤ 1})) = 0) :
Tendsto (fun c : ℝ ↦
Nat.card ({x ∈ X | F x ≤ c} ∩ L : Set E) / (c : ℝ))
atTop (𝓝 (volume.real ((b.ofZLatticeBasis ℝ).equivFun '' {x ∈ X | F x ≤ 1}))) := by
refine Tendsto.congr' ?_ <| (tendsto_card_div_pow_atTop_volume'
((b.ofZLatticeBasis ℝ).equivFun '' {x ∈ X | F x ≤ 1}) ?_ ?_ h₄ fun x y hx hy ↦ ?_).comp
(tendsto_rpow_atTop <| inv_pos.mpr
(Nat.cast_pos.mpr card_pos) : Tendsto (fun x ↦ x ^ (card ι : ℝ)⁻¹) atTop atTop)
· filter_upwards [eventually_gt_atTop 0] with c hc
have aux₁ : (card ι : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr card_ne_zero
have aux₂ : 0 < c ^ (card ι : ℝ)⁻¹ := Real.rpow_pos_of_pos hc _
have aux₃ : (c ^ (card ι : ℝ)⁻¹)⁻¹ ≠ 0 := inv_ne_zero aux₂.ne'
have aux₄ : c ^ (-(card ι : ℝ)⁻¹) ≠ 0 := (Real.rpow_pos_of_pos hc _).ne'
obtain ⟨hc₁, hc₂⟩ := lt_iff_le_and_ne.mp hc
rw [Function.comp_apply, ← Real.rpow_natCast, Real.rpow_inv_rpow hc₁ aux₁, eq_comm]
congr
refine Nat.card_congr <| Equiv.subtypeEquiv ((b.ofZLatticeBasis ℝ).equivFun.toEquiv.trans
(Equiv.smulRight aux₄)) fun _ ↦ ?_
rw [Set.mem_inter_iff, Set.mem_inter_iff, Equiv.trans_apply, LinearEquiv.coe_toEquiv,
Equiv.smulRight_apply, Real.rpow_neg hc₁, Set.smul_mem_smul_set_iff₀ aux₃,
← Set.mem_smul_set_iff_inv_smul_mem₀ aux₂.ne', ← image_smul_set,
tendsto_card_le_div''_aux hX h₁ aux₂, ← Real.rpow_natCast, ← Real.rpow_mul hc₁,
inv_mul_cancel₀ aux₁, Real.rpow_one]
simp_rw [SetLike.mem_coe, Set.mem_image, EmbeddingLike.apply_eq_iff_eq, exists_eq_right,
and_congr_right_iff, ← b.ofZLatticeBasis_span ℝ, Basis.mem_span_iff_repr_mem,
Pi.basisFun_repr, Basis.equivFun_apply, implies_true]
· rw [← NormedSpace.isVonNBounded_iff ℝ] at h₂ ⊢
exact Bornology.IsVonNBounded.image h₂ ((b.ofZLatticeBasis ℝ).equivFunL : E →L[ℝ] ι → ℝ)
· exact (b.ofZLatticeBasis ℝ).equivFunL.toHomeomorph.toMeasurableEquiv.measurableSet_image.mpr h₃
· simp_rw [← image_smul_set]
apply Set.image_mono
rw [tendsto_card_le_div''_aux hX h₁ hx,
tendsto_card_le_div''_aux hX h₁ (lt_of_lt_of_le hx hy)]
exact fun a ⟨ha₁, ha₂⟩ ↦ ⟨ha₁, le_trans ha₂ <| pow_le_pow_left₀ (le_of_lt hx) hy _⟩
end General
section Pi
open Filter Fintype Pointwise Topology Bornology
private theorem frontier_equivFun {E : Type*} [AddCommGroup E] [Module ℝ E] {ι : Type*} [Fintype ι]
[TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] [T2Space E]
(b : Basis ι ℝ E) (s : Set E) :
frontier (b.equivFun '' s) = b.equivFun '' (frontier s) := by
rw [LinearEquiv.image_eq_preimage, LinearEquiv.image_eq_preimage]
exact (Homeomorph.preimage_frontier b.equivFunL.toHomeomorph.symm s).symm
variable {ι : Type*} [Fintype ι]
variable (L : Submodule ℤ (ι → ℝ)) [DiscreteTopology L] [IsZLattice ℝ L]
theorem tendsto_card_div_pow (b : Basis ι ℤ L) {s : Set (ι → ℝ)} (hs₁ : IsBounded s)
(hs₂ : MeasurableSet s) (hs₃ : volume (frontier s) = 0) :
Tendsto (fun n : ℕ ↦ (Nat.card (s ∩ (n : ℝ)⁻¹ • L : Set (ι → ℝ)) : ℝ) / n ^ card ι)
atTop (𝓝 (volume.real s / covolume L)) := by
classical
convert tendsto_card_div_pow'' b hs₁ hs₂ ?_
· simp only [measureReal_def]
rw [volume_image_eq_volume_div_covolume L b, ENNReal.toReal_div,
ENNReal.toReal_ofReal (covolume_pos L volume).le]
· rw [frontier_equivFun, volume_image_eq_volume_div_covolume, hs₃, ENNReal.zero_div]
theorem tendsto_card_le_div {X : Set (ι → ℝ)} (hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X)
{F : (ι → ℝ) → ℝ} (h₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ card ι * (F x))
(h₂ : IsBounded {x ∈ X | F x ≤ 1}) (h₃ : MeasurableSet {x ∈ X | F x ≤ 1})
(h₄ : volume (frontier {x | x ∈ X ∧ F x ≤ 1}) = 0) [Nonempty ι] :
Tendsto (fun c : ℝ ↦
Nat.card ({x ∈ X | F x ≤ c} ∩ L : Set (ι → ℝ)) / (c : ℝ))
atTop (𝓝 (volume.real {x ∈ X | F x ≤ 1} / covolume L)) := by
classical
let e : Free.ChooseBasisIndex ℤ ↥L ≃ ι := by
refine Fintype.equivOfCardEq ?_
rw [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ, finrank_fintype_fun_eq_card]
let b := (Module.Free.chooseBasis ℤ L).reindex e
convert tendsto_card_le_div'' b hX h₁ h₂ h₃ ?_
· simp only [measureReal_def]
rw [volume_image_eq_volume_div_covolume L b, ENNReal.toReal_div,
ENNReal.toReal_ofReal (covolume_pos L volume).le]
· rw [frontier_equivFun, volume_image_eq_volume_div_covolume, h₄, ENNReal.zero_div]
end Pi
section InnerProductSpace
open Filter Pointwise Topology Bornology
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E]
[MeasurableSpace E] [BorelSpace E]
variable (L : Submodule ℤ E) [DiscreteTopology L] [IsZLattice ℝ L]
/-- A version of `ZLattice.covolume.tendsto_card_div_pow` for the `InnerProductSpace` case;
see the `Naming convention` section in the introduction. -/
theorem tendsto_card_div_pow' {s : Set E} (hs₁ : IsBounded s) (hs₂ : MeasurableSet s)
(hs₃ : volume (frontier s) = 0) :
Tendsto (fun n : ℕ ↦ (Nat.card (s ∩ (n : ℝ)⁻¹ • L : Set E) : ℝ) / n ^ finrank ℝ E)
atTop (𝓝 (volume.real s / covolume L)) := by
let b := Module.Free.chooseBasis ℤ L
convert tendsto_card_div_pow'' b hs₁ hs₂ ?_
· rw [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ L]
· simp only [measureReal_def]
rw [volume_image_eq_volume_div_covolume' L b hs₂.nullMeasurableSet, ENNReal.toReal_div,
ENNReal.toReal_ofReal (covolume_pos L volume).le]
· rw [frontier_equivFun, volume_image_eq_volume_div_covolume', hs₃, ENNReal.zero_div]
exact NullMeasurableSet.of_null hs₃
/-- A version of `ZLattice.covolume.tendsto_card_le_div` for the `InnerProductSpace` case;
see the `Naming convention` section in the introduction. -/
theorem tendsto_card_le_div' [Nontrivial E] {X : Set E} {F : E → ℝ}
(hX : ∀ ⦃x⦄ ⦃r : ℝ⦄, x ∈ X → 0 < r → r • x ∈ X)
(h₁ : ∀ x ⦃r : ℝ⦄, 0 ≤ r → F (r • x) = r ^ finrank ℝ E * (F x))
(h₂ : IsBounded {x ∈ X | F x ≤ 1}) (h₃ : MeasurableSet {x ∈ X | F x ≤ 1})
(h₄ : volume (frontier {x ∈ X | F x ≤ 1}) = 0) :
Tendsto (fun c : ℝ ↦
Nat.card ({x ∈ X | F x ≤ c} ∩ L : Set E) / (c : ℝ))
atTop (𝓝 (volume.real {x ∈ X | F x ≤ 1} / covolume L)) := by
let b := Module.Free.chooseBasis ℤ L
convert tendsto_card_le_div'' b hX ?_ h₂ h₃ ?_
· simp only [measureReal_def]
rw [volume_image_eq_volume_div_covolume' L b h₃.nullMeasurableSet, ENNReal.toReal_div,
ENNReal.toReal_ofReal (covolume_pos L volume).le]
· have : Nontrivial L := nontrivial_of_finrank_pos <| (ZLattice.rank ℝ L).symm ▸ finrank_pos
infer_instance
· rwa [← finrank_eq_card_chooseBasisIndex, ZLattice.rank ℝ L]
· rw [frontier_equivFun, volume_image_eq_volume_div_covolume', h₄, ENNReal.zero_div]
exact NullMeasurableSet.of_null h₄
end InnerProductSpace
end covolume
end ZLattice
|
Girth.lean
|
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Combinatorics.SimpleGraph.Acyclic
import Mathlib.Data.ENat.Lattice
/-!
# Girth of a simple graph
This file defines the girth and the extended girth of a simple graph as the length of its smallest
cycle, they give `0` or `∞` respectively if the graph is acyclic.
## TODO
- Prove that `G.egirth ≤ 2 * G.ediam + 1` and `G.girth ≤ 2 * G.diam + 1` when the diameter is
non-zero.
-/
namespace SimpleGraph
variable {α : Type*} {G : SimpleGraph α}
section egirth
/--
The extended girth of a simple graph is the length of its smallest cycle, or `∞` if the graph is
acyclic.
-/
noncomputable def egirth (G : SimpleGraph α) : ℕ∞ :=
⨅ a, ⨅ w : G.Walk a a, ⨅ _ : w.IsCycle, w.length
@[simp]
lemma le_egirth {n : ℕ∞} : n ≤ G.egirth ↔ ∀ a (w : G.Walk a a), w.IsCycle → n ≤ w.length := by
simp [egirth]
lemma egirth_le_length {a} {w : G.Walk a a} (h : w.IsCycle) : G.egirth ≤ w.length :=
le_egirth.mp le_rfl a w h
@[simp]
lemma egirth_eq_top : G.egirth = ⊤ ↔ G.IsAcyclic := by simp [egirth, IsAcyclic]
protected alias ⟨_, IsAcyclic.egirth_eq_top⟩ := egirth_eq_top
lemma egirth_anti : Antitone (egirth : SimpleGraph α → ℕ∞) :=
fun G H h ↦ iInf_mono fun a ↦ iInf₂_mono' fun w hw ↦ ⟨w.mapLe h, hw.mapLe _, by simp⟩
lemma exists_egirth_eq_length :
(∃ (a : α) (w : G.Walk a a), w.IsCycle ∧ G.egirth = w.length) ↔ ¬ G.IsAcyclic := by
refine ⟨?_, fun h ↦ ?_⟩
· rintro ⟨a, w, hw, _⟩ hG
exact hG _ hw
· simp_rw [← egirth_eq_top, ← Ne.eq_def, egirth, iInf_subtype', iInf_sigma', ENat.iInf_coe_ne_top,
← exists_prop, Subtype.exists', Sigma.exists', eq_comm] at h ⊢
exact ciInf_mem _
lemma three_le_egirth : 3 ≤ G.egirth := by
by_cases h : G.IsAcyclic
· rw [← egirth_eq_top] at h
rw [h]
apply le_top
· rw [← exists_egirth_eq_length] at h
have ⟨_, _, _⟩ := h
simp_all only [Nat.cast_inj, Nat.ofNat_le_cast, Walk.IsCycle.three_le_length]
@[simp] lemma egirth_bot : egirth (⊥ : SimpleGraph α) = ⊤ := by simp
end egirth
section girth
/--
The girth of a simple graph is the length of its smallest cycle, or junk value `0` if the graph is
acyclic.
-/
noncomputable def girth (G : SimpleGraph α) : ℕ :=
G.egirth.toNat
lemma girth_le_length {a} {w : G.Walk a a} (h : w.IsCycle) : G.girth ≤ w.length :=
ENat.coe_le_coe.mp <| G.egirth.coe_toNat_le_self.trans <| egirth_le_length h
lemma three_le_girth (hG : ¬ G.IsAcyclic) : 3 ≤ G.girth :=
ENat.toNat_le_toNat three_le_egirth <| egirth_eq_top.not.mpr hG
lemma girth_eq_zero : G.girth = 0 ↔ G.IsAcyclic :=
⟨fun h ↦ not_not.mp <| three_le_girth.mt <| by omega, fun h ↦ by simp [girth, h]⟩
protected alias ⟨_, IsAcyclic.girth_eq_zero⟩ := girth_eq_zero
lemma girth_anti {G' : SimpleGraph α} (hab : G ≤ G') (h : ¬ G.IsAcyclic) : G'.girth ≤ G.girth :=
ENat.toNat_le_toNat (egirth_anti hab) <| egirth_eq_top.not.mpr h
lemma exists_girth_eq_length :
(∃ (a : α) (w : G.Walk a a), w.IsCycle ∧ G.girth = w.length) ↔ ¬ G.IsAcyclic := by
refine ⟨by tauto, fun h ↦ ?_⟩
obtain ⟨_, _, _⟩ := exists_egirth_eq_length.mpr h
simp_all only [girth, ENat.toNat_coe]
tauto
@[simp] lemma girth_bot : girth (⊥ : SimpleGraph α) = 0 := by
simp [girth]
end girth
end SimpleGraph
|
Generator.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Abelian
import Mathlib.Algebra.Category.ModuleCat.Presheaf.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Free
import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.CategoryTheory.Elements
import Mathlib.CategoryTheory.Generator.Basic
/-!
# Generators for the category of presheaves of modules
In this file, given a presheaf of rings `R` on a category `C`,
we study the set `freeYoneda R` of presheaves of modules
of form `(free R).obj (yoneda.obj X)` for `X : C`, i.e.
free presheaves of modules generated by the Yoneda
presheaf represented by some `X : C` (the functor
represented by such a presheaf of modules is the evaluation
functor `M ↦ M.obj (op X)`, see `freeYonedaEquiv`).
Lemmas `PresheafOfModules.freeYoneda.isSeparating` and
`PresheafOfModules.freeYoneda.isDetecting` assert that this
set `freeYoneda R` is separating and detecting.
We deduce that if `C : Type u` is a small category,
and `R : Cᵒᵖ ⥤ RingCat.{u}`, then `PresheafOfModules.{u} R`
is a well-powered category.
Finally, given `M : PresheafOfModules.{u} R`, we consider
the canonical epimorphism of presheaves of modules
`M.fromFreeYonedaCoproduct : M.freeYonedaCoproduct ⟶ M`
where `M.freeYonedaCoproduct` is a coproduct indexed
by elements of `M`, i.e. pairs `⟨X : Cᵒᵖ, a : M.obj X⟩`,
of the objects `(free R).obj (yoneda.obj X.unop)`.
This is used in the definition
`PresheafOfModules.isColimitFreeYonedaCoproductsCokernelCofork`
in order to obtain that any presheaf of modules is a cokernel
of a morphism between coproducts of objects in `freeYoneda R`.
-/
universe v v₁ u u₁
open CategoryTheory Limits
namespace PresheafOfModules
variable {C : Type u} [Category.{v} C] {R : Cᵒᵖ ⥤ RingCat.{v}}
/-- When `R : Cᵒᵖ ⥤ RingCat`, `M : PresheafOfModules R`, and `X : C`, this is the
bijection `((free R).obj (yoneda.obj X) ⟶ M) ≃ M.obj (Opposite.op X)`. -/
noncomputable def freeYonedaEquiv {M : PresheafOfModules.{v} R} {X : C} :
((free R).obj (yoneda.obj X) ⟶ M) ≃ M.obj (Opposite.op X) :=
freeHomEquiv.trans yonedaEquiv
lemma freeYonedaEquiv_symm_app (M : PresheafOfModules.{v} R) (X : C)
(x : M.obj (Opposite.op X)) :
(freeYonedaEquiv.symm x).app (Opposite.op X) (ModuleCat.freeMk (𝟙 _)) = x := by
dsimp [freeYonedaEquiv, freeHomEquiv, yonedaEquiv]
rw [ModuleCat.freeDesc_apply, op_id, M.presheaf.map_id]
rfl
lemma freeYonedaEquiv_comp {M N : PresheafOfModules.{v} R} {X : C}
(m : ((free R).obj (yoneda.obj X) ⟶ M)) (φ : M ⟶ N) :
freeYonedaEquiv (m ≫ φ) = φ.app _ (freeYonedaEquiv m) := rfl
variable (R) in
/-- The set of `PresheafOfModules.{v} R` consisting of objects of the
form `(free R).obj (yoneda.obj X)` for some `X`. -/
def freeYoneda : Set (PresheafOfModules.{v} R) := Set.range (yoneda ⋙ free R).obj
namespace freeYoneda
instance : Small.{u} (freeYoneda R) := by
let π : C → freeYoneda R := fun X ↦ ⟨_, ⟨X, rfl⟩⟩
have hπ : Function.Surjective π := by rintro ⟨_, ⟨X, rfl⟩⟩; exact ⟨X, rfl⟩
exact small_of_surjective hπ
variable (R)
lemma isSeparating : IsSeparating (freeYoneda R) := by
intro M N f₁ f₂ h
ext ⟨X⟩ m
obtain ⟨g, rfl⟩ := freeYonedaEquiv.surjective m
exact congr_arg freeYonedaEquiv (h _ ⟨X, rfl⟩ g)
lemma isDetecting : IsDetecting (freeYoneda R) :=
(isSeparating R).isDetecting
end freeYoneda
instance wellPowered {C₀ : Type u} [SmallCategory C₀] (R₀ : C₀ᵒᵖ ⥤ RingCat.{u}) :
WellPowered.{u} (PresheafOfModules.{u} R₀) :=
wellPowered_of_isDetecting (freeYoneda.isDetecting R₀)
/-- The type of elements of a presheaf of modules. A term of this type is a pair
`⟨X, a⟩` with `X : Cᵒᵖ` and `a : M.obj X`. -/
abbrev Elements {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
(M : PresheafOfModules.{v} R) := ((toPresheaf R).obj M ⋙ forget Ab).Elements
/-- Given a presheaf of modules `M`, this is a constructor for the type `M.Elements`. -/
noncomputable abbrev elementsMk {C : Type u₁} [Category.{v₁} C] {R : Cᵒᵖ ⥤ RingCat.{u}}
(M : PresheafOfModules.{v} R) (X : Cᵒᵖ) (x : M.obj X) : M.Elements :=
Functor.elementsMk _ X x
namespace Elements
variable {C : Type u} [Category.{v} C] {R : Cᵒᵖ ⥤ RingCat.{v}} {M : PresheafOfModules.{v} R}
/-- Given an element `m : M.Elements` of a presheaf of modules `M`, this is the
free presheaf of modules on the Yoneda presheaf of types corresponding to the
underlying object of `m`. -/
noncomputable abbrev freeYoneda (m : M.Elements) :
PresheafOfModules.{v} R := (free R).obj (yoneda.obj m.1.unop)
/-- Given an element `m : M.Elements` of a presheaf of modules `M`, this is
the canonical morphism `m.freeYoneda ⟶ M`. -/
noncomputable abbrev fromFreeYoneda (m : M.Elements) :
m.freeYoneda ⟶ M :=
freeYonedaEquiv.symm m.2
lemma fromFreeYoneda_app_apply (m : M.Elements) :
m.fromFreeYoneda.app m.1 (ModuleCat.freeMk (𝟙 _)) = m.2 := by
apply freeYonedaEquiv_symm_app
end Elements
section
variable {C : Type u} [SmallCategory.{u} C] {R : Cᵒᵖ ⥤ RingCat.{u}} (M : PresheafOfModules.{u} R)
/-- Given a presheaf of modules `M`, this is the coproduct of
all free Yoneda presheaves `m.freeYoneda` for all `m : M.Elements`. -/
noncomputable abbrev freeYonedaCoproduct : PresheafOfModules.{u} R :=
∐ (Elements.freeYoneda (M := M))
/-- Given an element `m : M.Elements` of a presheaf of modules `M`, this is the
canonical inclusion `m.freeYoneda ⟶ M.freeYonedaCoproduct`. -/
noncomputable abbrev ιFreeYonedaCoproduct (m : M.Elements) :
m.freeYoneda ⟶ M.freeYonedaCoproduct :=
Sigma.ι _ m
/-- Given a presheaf of modules `M`, this is the
canonical morphism `M.freeYonedaCoproduct ⟶ M`. -/
noncomputable def fromFreeYonedaCoproduct :
M.freeYonedaCoproduct ⟶ M :=
Sigma.desc Elements.fromFreeYoneda
/-- Given an element `m` of a presheaf of modules `M`, this is the associated
canonical section of the presheaf `M.freeYonedaCoproduct` over the object `m.1`. -/
noncomputable def freeYonedaCoproductMk (m : M.Elements) :
M.freeYonedaCoproduct.obj m.1 :=
(M.ιFreeYonedaCoproduct m).app _ (ModuleCat.freeMk (𝟙 _))
@[reassoc (attr := simp)]
lemma ι_fromFreeYonedaCoproduct (m : M.Elements) :
M.ιFreeYonedaCoproduct m ≫ M.fromFreeYonedaCoproduct = m.fromFreeYoneda := by
apply Sigma.ι_desc
lemma ι_fromFreeYonedaCoproduct_apply (m : M.Elements) (X : Cᵒᵖ) (x : m.freeYoneda.obj X) :
M.fromFreeYonedaCoproduct.app X ((M.ιFreeYonedaCoproduct m).app X x) =
m.fromFreeYoneda.app X x :=
congr_fun ((evaluation R X ⋙ forget _).congr_map (M.ι_fromFreeYonedaCoproduct m)) x
@[simp]
lemma fromFreeYonedaCoproduct_app_mk (m : M.Elements) :
M.fromFreeYonedaCoproduct.app _ (M.freeYonedaCoproductMk m) = m.2 := by
dsimp [freeYonedaCoproductMk]
erw [M.ι_fromFreeYonedaCoproduct_apply m]
rw [m.fromFreeYoneda_app_apply]
instance : Epi M.fromFreeYonedaCoproduct :=
epi_of_surjective (fun X m ↦ ⟨M.freeYonedaCoproductMk (M.elementsMk X m),
M.fromFreeYonedaCoproduct_app_mk (M.elementsMk X m)⟩)
/-- Given a presheaf of modules `M`, this is a morphism between coproducts
of free presheaves of modules on Yoneda presheaves which gives a presentation
of the module `M`, see `isColimitFreeYonedaCoproductsCokernelCofork`. -/
noncomputable def toFreeYonedaCoproduct :
(kernel M.fromFreeYonedaCoproduct).freeYonedaCoproduct ⟶ M.freeYonedaCoproduct :=
(kernel M.fromFreeYonedaCoproduct).fromFreeYonedaCoproduct ≫ kernel.ι _
@[reassoc (attr := simp)]
lemma toFreeYonedaCoproduct_fromFreeYonedaCoproduct :
M.toFreeYonedaCoproduct ≫ M.fromFreeYonedaCoproduct = 0 := by
simp [toFreeYonedaCoproduct]
/-- (Colimit) cofork which gives a presentation of a presheaf of modules `M` using
coproducts of free presheaves of modules on Yoneda presheaves. -/
noncomputable abbrev freeYonedaCoproductsCokernelCofork :
CokernelCofork M.toFreeYonedaCoproduct :=
CokernelCofork.ofπ _ M.toFreeYonedaCoproduct_fromFreeYonedaCoproduct
/-- If `M` is a presheaf of modules, the cokernel cofork
`M.freeYonedaCoproductsCokernelCofork` is a colimit, which means that
`M` can be expressed as a cokernel of the morphism `M.toFreeYonedaCoproduct`
between coproducts of free presheaves of modules on Yoneda presheaves. -/
noncomputable def isColimitFreeYonedaCoproductsCokernelCofork :
IsColimit M.freeYonedaCoproductsCokernelCofork := by
let S := ShortComplex.mk _ _ M.toFreeYonedaCoproduct_fromFreeYonedaCoproduct
let T := ShortComplex.mk _ _ (kernel.condition M.fromFreeYonedaCoproduct)
let φ : S ⟶ T :=
{ τ₁ := fromFreeYonedaCoproduct _
τ₂ := 𝟙 _
τ₃ := 𝟙 _ }
exact ((ShortComplex.exact_iff_of_epi_of_isIso_of_mono φ).2
(T.exact_of_f_is_kernel (kernelIsKernel _))).gIsCokernel
end
end PresheafOfModules
|
Reflexive.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Robin Carlier
-/
import Mathlib.CategoryTheory.Limits.Final
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.Shapes.KernelPair
/-!
# Reflexive coequalizers
This file deals with reflexive pairs, which are pairs of morphisms with a common section.
A reflexive coequalizer is a coequalizer of such a pair. These kind of coequalizers often enjoy
nicer properties than general coequalizers, and feature heavily in some versions of the monadicity
theorem.
We also give some examples of reflexive pairs: for an adjunction `F ⊣ G` with counit `ε`, the pair
`(FGε_B, ε_FGB)` is reflexive. If a pair `f,g` is a kernel pair for some morphism, then it is
reflexive.
## Main definitions
* `IsReflexivePair` is the predicate that f and g have a common section.
* `WalkingReflexivePair` is the diagram indexing pairs with a common section.
* A `reflexiveCofork` is a cocone on a diagram indexed by `WalkingReflexivePair`.
* `WalkingReflexivePair.inclusionWalkingReflexivePair` is the inclustion functor from
`WalkingParallelPair` to `WalkingReflexivePair`. It acts on reflexive pairs as forgetting
the common section.
* `HasReflexiveCoequalizers` is the predicate that a category has all colimits of reflexive pairs.
* `reflexiveCoequalizerIsoCoequalizer`: an isomorphism promoting the coequalizer of a reflexive pair
to the colimit of a diagram out of the walking reflexive pair.
## Main statements
* `IsKernelPair.isReflexivePair`: A kernel pair is a reflexive pair
* `WalkingParallelPair.inclusionWalkingReflexivePair_final`: The inclusion functor is final.
* `hasReflexiveCoequalizers_iff`: A category has coequalizers of reflexive pairs if and only iff it
has all colimits of shape `WalkingReflexivePair`.
# TODO
* If `C` has binary coproducts and reflexive coequalizers, then it has all coequalizers.
* If `T` is a monad on cocomplete category `C`, then `Algebra T` is cocomplete iff it has reflexive
coequalizers.
* If `C` is locally cartesian closed and has reflexive coequalizers, then it has images: in fact
regular epi (and hence strong epi) images.
* Bundle the reflexive pairs of kernel pairs and of adjunction as functors out of the walking
reflexive pair.
-/
namespace CategoryTheory
universe v v₂ u u₂
variable {C : Type u} [Category.{v} C]
variable {D : Type u₂} [Category.{v₂} D]
variable {A B : C} {f g : A ⟶ B}
/-- The pair `f g : A ⟶ B` is reflexive if there is a morphism `B ⟶ A` which is a section for both.
-/
class IsReflexivePair (f g : A ⟶ B) : Prop where
common_section' : ∃ s : B ⟶ A, s ≫ f = 𝟙 B ∧ s ≫ g = 𝟙 B
theorem IsReflexivePair.common_section (f g : A ⟶ B) [IsReflexivePair f g] :
∃ s : B ⟶ A, s ≫ f = 𝟙 B ∧ s ≫ g = 𝟙 B := IsReflexivePair.common_section'
/--
The pair `f g : A ⟶ B` is coreflexive if there is a morphism `B ⟶ A` which is a retraction for both.
-/
class IsCoreflexivePair (f g : A ⟶ B) : Prop where
common_retraction' : ∃ s : B ⟶ A, f ≫ s = 𝟙 A ∧ g ≫ s = 𝟙 A
theorem IsCoreflexivePair.common_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] :
∃ s : B ⟶ A, f ≫ s = 𝟙 A ∧ g ≫ s = 𝟙 A := IsCoreflexivePair.common_retraction'
theorem IsReflexivePair.mk' (s : B ⟶ A) (sf : s ≫ f = 𝟙 B) (sg : s ≫ g = 𝟙 B) :
IsReflexivePair f g :=
⟨⟨s, sf, sg⟩⟩
theorem IsCoreflexivePair.mk' (s : B ⟶ A) (fs : f ≫ s = 𝟙 A) (gs : g ≫ s = 𝟙 A) :
IsCoreflexivePair f g :=
⟨⟨s, fs, gs⟩⟩
/-- Get the common section for a reflexive pair. -/
noncomputable def commonSection (f g : A ⟶ B) [IsReflexivePair f g] : B ⟶ A :=
(IsReflexivePair.common_section f g).choose
@[reassoc (attr := simp)]
theorem section_comp_left (f g : A ⟶ B) [IsReflexivePair f g] : commonSection f g ≫ f = 𝟙 B :=
(IsReflexivePair.common_section f g).choose_spec.1
@[reassoc (attr := simp)]
theorem section_comp_right (f g : A ⟶ B) [IsReflexivePair f g] : commonSection f g ≫ g = 𝟙 B :=
(IsReflexivePair.common_section f g).choose_spec.2
/-- Get the common retraction for a coreflexive pair. -/
noncomputable def commonRetraction (f g : A ⟶ B) [IsCoreflexivePair f g] : B ⟶ A :=
(IsCoreflexivePair.common_retraction f g).choose
@[reassoc (attr := simp)]
theorem left_comp_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] :
f ≫ commonRetraction f g = 𝟙 A :=
(IsCoreflexivePair.common_retraction f g).choose_spec.1
@[reassoc (attr := simp)]
theorem right_comp_retraction (f g : A ⟶ B) [IsCoreflexivePair f g] :
g ≫ commonRetraction f g = 𝟙 A :=
(IsCoreflexivePair.common_retraction f g).choose_spec.2
/-- If `f,g` is a kernel pair for some morphism `q`, then it is reflexive. -/
theorem IsKernelPair.isReflexivePair {R : C} {f g : R ⟶ A} {q : A ⟶ B} (h : IsKernelPair q f g) :
IsReflexivePair f g :=
IsReflexivePair.mk' _ (h.lift' _ _ rfl).2.1 (h.lift' _ _ _).2.2
-- This shouldn't be an instance as it would instantly loop.
/-- If `f,g` is reflexive, then `g,f` is reflexive. -/
theorem IsReflexivePair.swap [IsReflexivePair f g] : IsReflexivePair g f :=
IsReflexivePair.mk' _ (section_comp_right f g) (section_comp_left f g)
-- This shouldn't be an instance as it would instantly loop.
/-- If `f,g` is coreflexive, then `g,f` is coreflexive. -/
theorem IsCoreflexivePair.swap [IsCoreflexivePair f g] : IsCoreflexivePair g f :=
IsCoreflexivePair.mk' _ (right_comp_retraction f g) (left_comp_retraction f g)
variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G)
/-- For an adjunction `F ⊣ G` with counit `ε`, the pair `(FGε_B, ε_FGB)` is reflexive. -/
instance (B : D) :
IsReflexivePair (F.map (G.map (adj.counit.app B))) (adj.counit.app (F.obj (G.obj B))) :=
IsReflexivePair.mk' (F.map (adj.unit.app (G.obj B)))
(by
rw [← F.map_comp, adj.right_triangle_components]
apply F.map_id)
(adj.left_triangle_components _)
namespace Limits
variable (C)
/-- `C` has reflexive coequalizers if it has coequalizers for every reflexive pair. -/
class HasReflexiveCoequalizers : Prop where
has_coeq : ∀ ⦃A B : C⦄ (f g : A ⟶ B) [IsReflexivePair f g], HasCoequalizer f g
/-- `C` has coreflexive equalizers if it has equalizers for every coreflexive pair. -/
class HasCoreflexiveEqualizers : Prop where
has_eq : ∀ ⦃A B : C⦄ (f g : A ⟶ B) [IsCoreflexivePair f g], HasEqualizer f g
attribute [instance 1] HasReflexiveCoequalizers.has_coeq
attribute [instance 1] HasCoreflexiveEqualizers.has_eq
theorem hasCoequalizer_of_common_section [HasReflexiveCoequalizers C] {A B : C} {f g : A ⟶ B}
(r : B ⟶ A) (rf : r ≫ f = 𝟙 _) (rg : r ≫ g = 𝟙 _) : HasCoequalizer f g := by
letI := IsReflexivePair.mk' r rf rg
infer_instance
theorem hasEqualizer_of_common_retraction [HasCoreflexiveEqualizers C] {A B : C} {f g : A ⟶ B}
(r : B ⟶ A) (fr : f ≫ r = 𝟙 _) (gr : g ≫ r = 𝟙 _) : HasEqualizer f g := by
letI := IsCoreflexivePair.mk' r fr gr
infer_instance
/-- If `C` has coequalizers, then it has reflexive coequalizers. -/
instance (priority := 100) hasReflexiveCoequalizers_of_hasCoequalizers [HasCoequalizers C] :
HasReflexiveCoequalizers C where has_coeq A B f g _ := by infer_instance
/-- If `C` has equalizers, then it has coreflexive equalizers. -/
instance (priority := 100) hasCoreflexiveEqualizers_of_hasEqualizers [HasEqualizers C] :
HasCoreflexiveEqualizers C where has_eq A B f g _ := by infer_instance
end Limits
end CategoryTheory
namespace CategoryTheory
universe v v₂ u u₂
namespace Limits
/-- The type of objects for the diagram indexing reflexive (co)equalizers -/
inductive WalkingReflexivePair : Type where
| zero
| one
deriving DecidableEq, Inhabited
open WalkingReflexivePair
namespace WalkingReflexivePair
-- Don't generate unnecessary `sizeOf_spec` lemma which the `simpNF` linter will complain about.
set_option genSizeOfSpec false in
/-- The type of morphisms for the diagram indexing reflexive (co)equalizers -/
inductive Hom : (WalkingReflexivePair → WalkingReflexivePair → Type)
| left : Hom one zero
| right : Hom one zero
| reflexion : Hom zero one
| leftCompReflexion : Hom one one
| rightCompReflexion : Hom one one
| id (X : WalkingReflexivePair) : Hom X X
deriving DecidableEq
/-- Composition of morphisms in the diagram indexing reflexive (co)equalizers -/
def Hom.comp :
∀ { X Y Z : WalkingReflexivePair } (_ : Hom X Y)
(_ : Hom Y Z), Hom X Z
| _, _, _, id _, h => h
| _, _, _, h, id _ => h
| _, _, _, reflexion, left => id zero
| _, _, _, reflexion, right => id zero
| _, _, _, reflexion, rightCompReflexion => reflexion
| _, _, _, reflexion, leftCompReflexion => reflexion
| _, _, _, left, reflexion => leftCompReflexion
| _, _, _, right, reflexion => rightCompReflexion
| _, _, _, rightCompReflexion, rightCompReflexion => rightCompReflexion
| _, _, _, rightCompReflexion, leftCompReflexion => rightCompReflexion
| _, _, _, rightCompReflexion, right => right
| _, _, _, rightCompReflexion, left => right
| _, _, _, leftCompReflexion, left => left
| _, _, _, leftCompReflexion, right => left
| _, _, _, leftCompReflexion, rightCompReflexion => leftCompReflexion
| _, _, _, leftCompReflexion, leftCompReflexion => leftCompReflexion
instance category : SmallCategory WalkingReflexivePair where
Hom := Hom
id := Hom.id
comp := Hom.comp
comp_id := by intro _ _ f; cases f <;> rfl
id_comp := by intro _ _ f; cases f <;> rfl
assoc := by intro _ _ _ _ f g h; cases f <;> cases g <;> cases h <;> rfl
open Hom
@[simp]
lemma Hom.id_eq (X : WalkingReflexivePair) :
Hom.id X = 𝟙 X := rfl
@[reassoc (attr := simp)]
lemma reflexion_comp_left : reflexion ≫ left = 𝟙 zero := rfl
@[reassoc (attr := simp)]
lemma reflexion_comp_right : reflexion ≫ right = 𝟙 zero := rfl
@[simp]
lemma leftCompReflexion_eq : leftCompReflexion = (left ≫ reflexion : one ⟶ one) := rfl
@[simp]
lemma rightCompReflexion_eq : rightCompReflexion = (right ≫ reflexion : one ⟶ one) := rfl
section FunctorsOutOfWalkingReflexivePair
variable {C : Type u} [Category.{v} C]
@[reassoc (attr := simp)]
lemma map_reflexion_comp_map_left (F : WalkingReflexivePair ⥤ C) :
F.map reflexion ≫ F.map left = 𝟙 (F.obj zero) := by
rw [← F.map_comp, reflexion_comp_left, F.map_id]
@[reassoc (attr := simp)]
lemma map_reflexion_comp_map_right (F : WalkingReflexivePair ⥤ C) :
F.map reflexion ≫ F.map right = 𝟙 (F.obj zero) := by
rw [← F.map_comp, reflexion_comp_right, F.map_id]
end FunctorsOutOfWalkingReflexivePair
end WalkingReflexivePair
namespace WalkingParallelPair
/-- The inclusion functor forgetting the common section -/
@[simps!]
def inclusionWalkingReflexivePair : WalkingParallelPair ⥤ WalkingReflexivePair where
obj := fun x => match x with
| one => WalkingReflexivePair.zero
| zero => WalkingReflexivePair.one
map := fun f => match f with
| .left => WalkingReflexivePair.Hom.left
| .right => WalkingReflexivePair.Hom.right
| .id _ => WalkingReflexivePair.Hom.id _
map_comp := by
intro _ _ _ f g; cases f <;> cases g <;> rfl
variable {C : Type u} [Category.{v} C]
instance (X : WalkingReflexivePair) :
Nonempty (StructuredArrow X inclusionWalkingReflexivePair) := by
cases X with
| zero => exact ⟨StructuredArrow.mk (Y := one) (𝟙 _)⟩
| one => exact ⟨StructuredArrow.mk (Y := zero) (𝟙 _)⟩
open WalkingReflexivePair.Hom in
instance (X : WalkingReflexivePair) :
IsConnected (StructuredArrow X inclusionWalkingReflexivePair) := by
cases X with
| zero =>
refine IsConnected.of_induct (j₀ := StructuredArrow.mk (Y := one) (𝟙 _)) ?_
rintro p h₁ h₂ ⟨⟨⟨⟩⟩, (_ | _), ⟨_⟩⟩
· exact (h₂ (StructuredArrow.homMk .left)).2 h₁
· exact h₁
| one =>
refine IsConnected.of_induct (j₀ := StructuredArrow.mk (Y := zero) (𝟙 _))
(fun p h₁ h₂ ↦ ?_)
have hₗ : StructuredArrow.mk left ∈ p := (h₂ (StructuredArrow.homMk .left)).1 h₁
have hᵣ : StructuredArrow.mk right ∈ p := (h₂ (StructuredArrow.homMk .right)).1 h₁
rintro ⟨⟨⟨⟩⟩, (_ | _), ⟨_⟩⟩
· exact (h₂ (StructuredArrow.homMk .left)).2 hₗ
· exact (h₂ (StructuredArrow.homMk .right)).2 hᵣ
all_goals assumption
/-- The inclusion functor is a final functor -/
instance inclusionWalkingReflexivePair_final : Functor.Final inclusionWalkingReflexivePair where
out := inferInstance
end WalkingParallelPair
end Limits
namespace Limits
open WalkingReflexivePair
variable {C : Type u} [Category.{v} C]
variable {A B : C}
/-- Bundle the data of a parallel pair along with a common section as a functor out of the walking
reflexive pair -/
def reflexivePair (f g : A ⟶ B) (s : B ⟶ A)
(sl : s ≫ f = 𝟙 B := by cat_disch) (sr : s ≫ g = 𝟙 B := by cat_disch) :
(WalkingReflexivePair ⥤ C) where
obj x :=
match x with
| zero => B
| one => A
map h :=
match h with
| .id _ => 𝟙 _
| .left => f
| .right => g
| .reflexion => s
| .rightCompReflexion => g ≫ s
| .leftCompReflexion => f ≫ s
map_comp := by
rintro _ _ _ ⟨⟩ g <;> cases g <;>
simp only [Category.id_comp, Category.comp_id, Category.assoc, sl, sr,
reassoc_of% sl, reassoc_of% sr] <;> rfl
section
variable {A B : C}
variable (f g : A ⟶ B) (s : B ⟶ A) {sl : s ≫ f = 𝟙 B} {sr : s ≫ g = 𝟙 B}
@[simp] lemma reflexivePair_obj_zero : (reflexivePair f g s sl sr).obj zero = B := rfl
@[simp] lemma reflexivePair_obj_one : (reflexivePair f g s sl sr).obj one = A := rfl
@[simp] lemma reflexivePair_map_right : (reflexivePair f g s sl sr).map .left = f := rfl
@[simp] lemma reflexivePair_map_left : (reflexivePair f g s sl sr).map .right = g := rfl
@[simp] lemma reflexivePair_map_reflexion : (reflexivePair f g s sl sr).map .reflexion = s := rfl
end
/-- (Noncomputably) bundle the data of a reflexive pair as a functor out of the walking reflexive
pair -/
noncomputable def ofIsReflexivePair (f g : A ⟶ B) [IsReflexivePair f g] :
WalkingReflexivePair ⥤ C := reflexivePair f g (commonSection f g)
@[simp]
lemma ofIsReflexivePair_map_left (f g : A ⟶ B) [IsReflexivePair f g] :
(ofIsReflexivePair f g).map .left = f := rfl
@[simp]
lemma ofIsReflexivePair_map_right (f g : A ⟶ B) [IsReflexivePair f g] :
(ofIsReflexivePair f g).map .right = g := rfl
/-- The natural isomorphism between the diagram obtained by forgetting the reflexion of
`ofIsReflexivePair f g` and the original parallel pair. -/
noncomputable def inclusionWalkingReflexivePairOfIsReflexivePairIso
(f g : A ⟶ B) [IsReflexivePair f g] :
WalkingParallelPair.inclusionWalkingReflexivePair ⋙ (ofIsReflexivePair f g) ≅
parallelPair f g :=
diagramIsoParallelPair _
end Limits
namespace Limits
variable {C : Type u} [Category.{v} C]
namespace reflexivePair
open WalkingReflexivePair WalkingReflexivePair.Hom
section
section NatTrans
variable {F G : WalkingReflexivePair ⥤ C}
(e₀ : F.obj zero ⟶ G.obj zero) (e₁ : F.obj one ⟶ G.obj one)
(h₁ : F.map left ≫ e₀ = e₁ ≫ G.map left := by cat_disch)
(h₂ : F.map right ≫ e₀ = e₁ ≫ G.map right := by cat_disch)
(h₃ : F.map reflexion ≫ e₁ = e₀ ≫ G.map reflexion := by cat_disch)
/-- A constructor for natural transformations between functors from `WalkingReflexivePair`. -/
def mkNatTrans : F ⟶ G where
app := fun x ↦ match x with
| zero => e₀
| one => e₁
naturality _ _ f := by
cases f
all_goals
dsimp
simp only [Functor.map_id, Category.id_comp, Category.comp_id, Functor.map_comp, h₁, h₂, h₃,
reassoc_of% h₁, reassoc_of% h₂, Category.assoc]
@[simp]
lemma mkNatTrans_app_zero : (mkNatTrans e₀ e₁ h₁ h₂ h₃).app zero = e₀ := rfl
@[simp]
lemma mkNatTrans_app_one : (mkNatTrans e₀ e₁ h₁ h₂ h₃).app one = e₁ := rfl
end NatTrans
section NatIso
variable {F G : WalkingReflexivePair ⥤ C}
/-- Constructor for natural isomorphisms between functors out of `WalkingReflexivePair`. -/
@[simps!]
def mkNatIso (e₀ : F.obj zero ≅ G.obj zero) (e₁ : F.obj one ≅ G.obj one)
(h₁ : F.map left ≫ e₀.hom = e₁.hom ≫ G.map left := by cat_disch)
(h₂ : F.map right ≫ e₀.hom = e₁.hom ≫ G.map right := by cat_disch)
(h₃ : F.map reflexion ≫ e₁.hom = e₀.hom ≫ G.map reflexion := by cat_disch) :
F ≅ G where
hom := mkNatTrans e₀.hom e₁.hom
inv := mkNatTrans e₀.inv e₁.inv
(by rw [← cancel_epi e₁.hom, e₁.hom_inv_id_assoc, ← reassoc_of% h₁, e₀.hom_inv_id,
Category.comp_id])
(by rw [← cancel_epi e₁.hom, e₁.hom_inv_id_assoc, ← reassoc_of% h₂, e₀.hom_inv_id,
Category.comp_id])
(by rw [← cancel_epi e₀.hom, e₀.hom_inv_id_assoc, ← reassoc_of% h₃, e₁.hom_inv_id,
Category.comp_id])
hom_inv_id := by ext x; cases x <;> simp
inv_hom_id := by ext x; cases x <;> simp
variable (F)
/-- Every functor out of `WalkingReflexivePair` is isomorphic to the `reflexivePair` given by
its components -/
@[simps!]
def diagramIsoReflexivePair :
F ≅ reflexivePair (F.map left) (F.map right) (F.map reflexion) :=
mkNatIso (Iso.refl _) (Iso.refl _)
end NatIso
/-- A `reflexivePair` composed with a functor is isomorphic to the `reflexivePair` obtained by
applying the functor at each map. -/
@[simps!]
def compRightIso {D : Type u₂} [Category.{v₂} D] {A B : C}
(f g : A ⟶ B) (s : B ⟶ A) (sl : s ≫ f = 𝟙 B) (sr : s ≫ g = 𝟙 B) (F : C ⥤ D) :
(reflexivePair f g s sl sr) ⋙ F ≅ reflexivePair (F.map f) (F.map g) (F.map s)
(by simp only [← Functor.map_comp, sl, Functor.map_id])
(by simp only [← Functor.map_comp, sr, Functor.map_id]) :=
mkNatIso (Iso.refl _) (Iso.refl _)
lemma whiskerRightMkNatTrans {F G : WalkingReflexivePair ⥤ C}
(e₀ : F.obj zero ⟶ G.obj zero) (e₁ : F.obj one ⟶ G.obj one)
{h₁ : F.map left ≫ e₀ = e₁ ≫ G.map left}
{h₂ : F.map right ≫ e₀ = e₁ ≫ G.map right}
{h₃ : F.map reflexion ≫ e₁ = e₀ ≫ G.map reflexion}
{D : Type u₂} [Category.{v₂} D] (H : C ⥤ D) :
Functor.whiskerRight (mkNatTrans e₀ e₁ : F ⟶ G) H =
mkNatTrans (H.map e₀) (H.map e₁)
(by simp only [Functor.comp_obj, Functor.comp_map, ← Functor.map_comp, h₁])
(by simp only [Functor.comp_obj, Functor.comp_map, ← Functor.map_comp, h₂])
(by simp only [Functor.comp_obj, Functor.comp_map, ← Functor.map_comp, h₃]) := by
ext x; cases x <;> simp
end
/-- Any functor out of the WalkingReflexivePair yields a reflexive pair -/
instance to_isReflexivePair {F : WalkingReflexivePair ⥤ C} :
IsReflexivePair (F.map .left) (F.map .right) :=
⟨F.map .reflexion, map_reflexion_comp_map_left F, map_reflexion_comp_map_right F⟩
end reflexivePair
/-- A `ReflexiveCofork` is a cocone over a `WalkingReflexivePair`-shaped diagram. -/
abbrev ReflexiveCofork (F : WalkingReflexivePair ⥤ C) := Cocone F
namespace ReflexiveCofork
open WalkingReflexivePair WalkingReflexivePair.Hom
variable {F : WalkingReflexivePair ⥤ C}
/-- The tail morphism of a reflexive cofork. -/
abbrev π (G : ReflexiveCofork F) : F.obj zero ⟶ G.pt := G.ι.app zero
/-- Constructor for `ReflexiveCofork` -/
@[simps pt]
def mk {X : C} (π : F.obj zero ⟶ X) (h : F.map left ≫ π = F.map right ≫ π) :
ReflexiveCofork F where
pt := X
ι := reflexivePair.mkNatTrans π (F.map left ≫ π)
@[simp]
lemma mk_π {X : C} (π : F.obj zero ⟶ X) (h : F.map left ≫ π = F.map right ≫ π) :
(mk π h).π = π := rfl
lemma condition (G : ReflexiveCofork F) : F.map left ≫ G.π = F.map right ≫ G.π := by
rw [Cocone.w G left, Cocone.w G right]
@[simp]
lemma app_one_eq_π (G : ReflexiveCofork F) : G.ι.app zero = G.π := rfl
/-- The underlying `Cofork` of a `ReflexiveCofork`. -/
abbrev toCofork (G : ReflexiveCofork F) : Cofork (F.map left) (F.map right) :=
Cofork.ofπ G.π (by simp)
end ReflexiveCofork
noncomputable section
open WalkingReflexivePair WalkingReflexivePair.Hom
variable (F : WalkingReflexivePair ⥤ C)
/-- Forgetting the reflexion yields an equivalence between cocones over a bundled reflexive pair and
coforks on the underlying parallel pair. -/
@[simps! functor_obj_pt inverse_obj_pt]
def reflexiveCoforkEquivCofork :
ReflexiveCofork F ≌ Cofork (F.map left) (F.map right) :=
(Functor.Final.coconesEquiv _ F).symm.trans (Cocones.precomposeEquivalence
(diagramIsoParallelPair (WalkingParallelPair.inclusionWalkingReflexivePair ⋙ F))).symm
@[simp]
lemma reflexiveCoforkEquivCofork_functor_obj_π (G : ReflexiveCofork F) :
((reflexiveCoforkEquivCofork F).functor.obj G).π = G.π := by
dsimp [reflexiveCoforkEquivCofork]
rw [ReflexiveCofork.π, Cofork.π]
simp
@[simp]
lemma reflexiveCoforkEquivCofork_inverse_obj_π
(G : Cofork (F.map left) (F.map right)) :
((reflexiveCoforkEquivCofork F).inverse.obj G).π = G.π := by
dsimp only [reflexiveCoforkEquivCofork, Equivalence.symm, Equivalence.trans,
ReflexiveCofork.π, Cocones.precomposeEquivalence, Cocones.precompose,
Functor.comp, Functor.Final.coconesEquiv]
rw [Functor.Final.extendCocone_obj_ι_app' (Y := .one) (f := 𝟙 zero)]
simp
/-- The equivalence between reflexive coforks and coforks sends a reflexive cofork to its underlying
cofork. -/
def reflexiveCoforkEquivCoforkObjIso (G : ReflexiveCofork F) :
(reflexiveCoforkEquivCofork F).functor.obj G ≅ G.toCofork :=
Cofork.ext (Iso.refl _)
(by simp [reflexiveCoforkEquivCofork, Cofork.π])
lemma hasReflexiveCoequalizer_iff_hasCoequalizer :
HasColimit F ↔ HasCoequalizer (F.map left) (F.map right) := by
simpa only [hasColimit_iff_hasInitial_cocone]
using Equivalence.hasInitial_iff (reflexiveCoforkEquivCofork F)
instance reflexivePair_hasColimit_of_hasCoequalizer
[h : HasCoequalizer (F.map left) (F.map right)] : HasColimit F :=
hasReflexiveCoequalizer_iff_hasCoequalizer _|>.mpr h
/-- A reflexive cofork is a colimit cocone if and only if the underlying cofork is. -/
def ReflexiveCofork.isColimitEquiv (G : ReflexiveCofork F) :
IsColimit (G.toCofork) ≃ IsColimit G :=
IsColimit.equivIsoColimit (reflexiveCoforkEquivCoforkObjIso F G).symm|>.trans <|
(IsColimit.precomposeHomEquiv (diagramIsoParallelPair _).symm (G.whisker _)).trans <|
Functor.Final.isColimitWhiskerEquiv _ _
section
variable [HasCoequalizer (F.map left) (F.map right)]
/-- The colimit of a functor out of the walking reflexive pair is the same as the colimit of the
underlying parallel pair. -/
def reflexiveCoequalizerIsoCoequalizer :
colimit F ≅ coequalizer (F.map left) (F.map right) :=
((ReflexiveCofork.isColimitEquiv _ _).symm (colimit.isColimit F)).coconePointUniqueUpToIso
(colimit.isColimit _)
@[reassoc (attr := simp)]
lemma ι_reflexiveCoequalizerIsoCoequalizer_hom :
colimit.ι F zero ≫ (reflexiveCoequalizerIsoCoequalizer F).hom =
coequalizer.π (F.map left) (F.map right) :=
IsColimit.comp_coconePointUniqueUpToIso_hom
((ReflexiveCofork.isColimitEquiv F _).symm _) _ WalkingParallelPair.one
@[reassoc (attr := simp)]
lemma π_reflexiveCoequalizerIsoCoequalizer_inv :
coequalizer.π _ _ ≫ (reflexiveCoequalizerIsoCoequalizer F).inv = colimit.ι F _ := by
rw [reflexiveCoequalizerIsoCoequalizer]
simp only [colimit.comp_coconePointUniqueUpToIso_inv, Cofork.ofπ_pt, colimit.cocone_x,
Cofork.ofπ_ι_app, colimit.cocone_ι]
end
variable {A B : C} {f g : A ⟶ B} [IsReflexivePair f g] [h : HasCoequalizer f g]
instance ofIsReflexivePair_hasColimit_of_hasCoequalizer :
HasColimit (ofIsReflexivePair f g) :=
hasReflexiveCoequalizer_iff_hasCoequalizer _|>.mpr h
/-- The coequalizer of a reflexive pair can be promoted to the colimit of a diagram out of the
walking reflexive pair -/
def colimitOfIsReflexivePairIsoCoequalizer :
colimit (ofIsReflexivePair f g) ≅ coequalizer f g :=
@reflexiveCoequalizerIsoCoequalizer _ _ (ofIsReflexivePair f g) h
@[reassoc (attr := simp)]
lemma ι_colimitOfIsReflexivePairIsoCoequalizer_hom :
colimit.ι (ofIsReflexivePair f g) zero ≫ colimitOfIsReflexivePairIsoCoequalizer.hom =
coequalizer.π f g := @ι_reflexiveCoequalizerIsoCoequalizer_hom _ _ _ h
@[reassoc (attr := simp)]
lemma π_colimitOfIsReflexivePairIsoCoequalizer_inv :
coequalizer.π f g ≫ colimitOfIsReflexivePairIsoCoequalizer.inv =
colimit.ι (ofIsReflexivePair f g) zero :=
@π_reflexiveCoequalizerIsoCoequalizer_inv _ _ (ofIsReflexivePair f g) h
end
end Limits
namespace Limits
open WalkingReflexivePair
variable {C : Type u} [Category.{v} C]
/-- A category has coequalizers of reflexive pairs if and only if it has all colimits indexed by the
walking reflexive pair. -/
theorem hasReflexiveCoequalizers_iff :
HasColimitsOfShape WalkingReflexivePair C ↔ HasReflexiveCoequalizers C :=
⟨fun _ ↦ ⟨fun _ _ f g _ ↦ (hasReflexiveCoequalizer_iff_hasCoequalizer
(reflexivePair f g (commonSection f g))).1 inferInstance⟩,
fun _ ↦ ⟨inferInstance⟩⟩
end Limits
end CategoryTheory
|
Comma.lean
|
/-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Comma.Arrow
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono
import Mathlib.CategoryTheory.Limits.Creates
import Mathlib.CategoryTheory.Limits.Unit
/-!
# Limits and colimits in comma categories
We build limits in the comma category `Comma L R` provided that the two source categories have
limits and `R` preserves them.
This is used to construct limits in the arrow category, structured arrow category and under
category, and show that the appropriate forgetful functors create limits.
The duals of all the above are also given.
-/
namespace CategoryTheory
open Category Limits Functor
universe w' w v₁ v₂ v₃ u₁ u₂ u₃
variable {J : Type w} [Category.{w'} J]
variable {A : Type u₁} [Category.{v₁} A]
variable {B : Type u₂} [Category.{v₂} B]
variable {T : Type u₃} [Category.{v₃} T]
namespace Comma
variable {L : A ⥤ T} {R : B ⥤ T}
variable (F : J ⥤ Comma L R)
/-- (Implementation). An auxiliary cone which is useful in order to construct limits
in the comma category. -/
@[simps!]
def limitAuxiliaryCone (c₁ : Cone (F ⋙ fst L R)) : Cone ((F ⋙ snd L R) ⋙ R) :=
(Cones.postcompose (whiskerLeft F (Comma.natTrans L R) :)).obj (L.mapCone c₁)
/-- If `R` preserves the appropriate limit, then given a cone for `F ⋙ fst L R : J ⥤ L` and a
limit cone for `F ⋙ snd L R : J ⥤ R` we can build a cone for `F` which will turn out to be a limit
cone.
-/
@[simps]
noncomputable def coneOfPreserves [PreservesLimit (F ⋙ snd L R) R] (c₁ : Cone (F ⋙ fst L R))
{c₂ : Cone (F ⋙ snd L R)} (t₂ : IsLimit c₂) : Cone F where
pt :=
{ left := c₁.pt
right := c₂.pt
hom := (isLimitOfPreserves R t₂).lift (limitAuxiliaryCone _ c₁) }
π :=
{ app := fun j =>
{ left := c₁.π.app j
right := c₂.π.app j
w := ((isLimitOfPreserves R t₂).fac (limitAuxiliaryCone F c₁) j).symm }
naturality := fun j₁ j₂ t => by
ext
· simp [← c₁.w t]
· simp [← c₂.w t] }
/-- Provided that `R` preserves the appropriate limit, then the cone in `coneOfPreserves` is a
limit. -/
noncomputable def coneOfPreservesIsLimit [PreservesLimit (F ⋙ snd L R) R] {c₁ : Cone (F ⋙ fst L R)}
(t₁ : IsLimit c₁) {c₂ : Cone (F ⋙ snd L R)} (t₂ : IsLimit c₂) :
IsLimit (coneOfPreserves F c₁ t₂) where
lift s :=
{ left := t₁.lift ((fst L R).mapCone s)
right := t₂.lift ((snd L R).mapCone s)
w :=
(isLimitOfPreserves R t₂).hom_ext fun j => by
rw [coneOfPreserves_pt_hom, assoc, assoc, (isLimitOfPreserves R t₂).fac,
limitAuxiliaryCone_π_app, ← L.map_comp_assoc, t₁.fac, R.mapCone_π_app,
← R.map_comp, t₂.fac]
exact (s.π.app j).w }
uniq s m w := by
apply CommaMorphism.ext
· exact t₁.uniq ((fst L R).mapCone s) _ (fun j => by simp [← w])
· exact t₂.uniq ((snd L R).mapCone s) _ (fun j => by simp [← w])
/-- (Implementation). An auxiliary cocone which is useful in order to construct colimits
in the comma category. -/
@[simps!]
def colimitAuxiliaryCocone (c₂ : Cocone (F ⋙ snd L R)) : Cocone ((F ⋙ fst L R) ⋙ L) :=
(Cocones.precompose (whiskerLeft F (Comma.natTrans L R) :)).obj (R.mapCocone c₂)
/--
If `L` preserves the appropriate colimit, then given a colimit cocone for `F ⋙ fst L R : J ⥤ L` and
a cocone for `F ⋙ snd L R : J ⥤ R` we can build a cocone for `F` which will turn out to be a
colimit cocone.
-/
@[simps]
noncomputable def coconeOfPreserves [PreservesColimit (F ⋙ fst L R) L] {c₁ : Cocone (F ⋙ fst L R)}
(t₁ : IsColimit c₁) (c₂ : Cocone (F ⋙ snd L R)) : Cocone F where
pt :=
{ left := c₁.pt
right := c₂.pt
hom := (isColimitOfPreserves L t₁).desc (colimitAuxiliaryCocone _ c₂) }
ι :=
{ app := fun j =>
{ left := c₁.ι.app j
right := c₂.ι.app j
w := (isColimitOfPreserves L t₁).fac (colimitAuxiliaryCocone _ c₂) j }
naturality := fun j₁ j₂ t => by
ext
· simp [← c₁.w t]
· simp [← c₂.w t] }
/-- Provided that `L` preserves the appropriate colimit, then the cocone in `coconeOfPreserves` is
a colimit. -/
noncomputable def coconeOfPreservesIsColimit [PreservesColimit (F ⋙ fst L R) L]
{c₁ : Cocone (F ⋙ fst L R)}
(t₁ : IsColimit c₁) {c₂ : Cocone (F ⋙ snd L R)} (t₂ : IsColimit c₂) :
IsColimit (coconeOfPreserves F t₁ c₂) where
desc s :=
{ left := t₁.desc ((fst L R).mapCocone s)
right := t₂.desc ((snd L R).mapCocone s)
w :=
(isColimitOfPreserves L t₁).hom_ext fun j => by
rw [coconeOfPreserves_pt_hom, (isColimitOfPreserves L t₁).fac_assoc,
colimitAuxiliaryCocone_ι_app, assoc, ← R.map_comp, t₂.fac, L.mapCocone_ι_app, ←
L.map_comp_assoc, t₁.fac]
exact (s.ι.app j).w }
uniq s m w := by
apply CommaMorphism.ext
· exact t₁.uniq ((fst L R).mapCocone s) _ (fun j => by simp [← w])
· exact t₂.uniq ((snd L R).mapCocone s) _ (fun j => by simp [← w])
instance hasLimit (F : J ⥤ Comma L R) [HasLimit (F ⋙ fst L R)] [HasLimit (F ⋙ snd L R)]
[PreservesLimit (F ⋙ snd L R) R] : HasLimit F :=
HasLimit.mk ⟨_, coneOfPreservesIsLimit _ (limit.isLimit _) (limit.isLimit _)⟩
instance hasLimitsOfShape [HasLimitsOfShape J A] [HasLimitsOfShape J B]
[PreservesLimitsOfShape J R] : HasLimitsOfShape J (Comma L R) where
instance hasLimitsOfSize [HasLimitsOfSize.{w, w'} A] [HasLimitsOfSize.{w, w'} B]
[PreservesLimitsOfSize.{w, w'} R] : HasLimitsOfSize.{w, w'} (Comma L R) :=
⟨fun _ _ => inferInstance⟩
instance hasColimit (F : J ⥤ Comma L R) [HasColimit (F ⋙ fst L R)] [HasColimit (F ⋙ snd L R)]
[PreservesColimit (F ⋙ fst L R) L] : HasColimit F :=
HasColimit.mk ⟨_, coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _)⟩
instance hasColimitsOfShape [HasColimitsOfShape J A] [HasColimitsOfShape J B]
[PreservesColimitsOfShape J L] : HasColimitsOfShape J (Comma L R) where
instance hasColimitsOfSize [HasColimitsOfSize.{w, w'} A] [HasColimitsOfSize.{w, w'} B]
[PreservesColimitsOfSize.{w, w'} L] : HasColimitsOfSize.{w, w'} (Comma L R) :=
⟨fun _ _ => inferInstance⟩
instance preservesColimitsOfShape_fst [HasColimitsOfShape J A] [HasColimitsOfShape J B]
[PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.fst L R) where
preservesColimit :=
preservesColimit_of_preserves_colimit_cocone
(coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _))
(colimit.isColimit _)
instance preservesColimitsOfShape_snd [HasColimitsOfShape J A] [HasColimitsOfShape J B]
[PreservesColimitsOfShape J L] : PreservesColimitsOfShape J (Comma.snd L R) where
preservesColimit :=
preservesColimit_of_preserves_colimit_cocone
(coconeOfPreservesIsColimit _ (colimit.isColimit _) (colimit.isColimit _))
(colimit.isColimit _)
end Comma
namespace Arrow
instance hasLimit (F : J ⥤ Arrow T) [i₁ : HasLimit (F ⋙ leftFunc)] [i₂ : HasLimit (F ⋙ rightFunc)] :
HasLimit F := by
haveI : HasLimit (F ⋙ Comma.fst _ _) := i₁
haveI : HasLimit (F ⋙ Comma.snd _ _) := i₂
apply Comma.hasLimit
instance hasLimitsOfShape [HasLimitsOfShape J T] : HasLimitsOfShape J (Arrow T) where
instance hasLimits [HasLimits T] : HasLimits (Arrow T) :=
⟨fun _ _ => inferInstance⟩
instance hasColimit (F : J ⥤ Arrow T) [i₁ : HasColimit (F ⋙ leftFunc)]
[i₂ : HasColimit (F ⋙ rightFunc)] : HasColimit F := by
haveI : HasColimit (F ⋙ Comma.fst _ _) := i₁
haveI : HasColimit (F ⋙ Comma.snd _ _) := i₂
apply Comma.hasColimit
instance hasColimitsOfShape [HasColimitsOfShape J T] : HasColimitsOfShape J (Arrow T) where
instance hasColimits [HasColimits T] : HasColimits (Arrow T) :=
⟨fun _ _ => inferInstance⟩
instance preservesColimitsOfShape_leftFunc [HasColimitsOfShape J T] :
PreservesColimitsOfShape J (Arrow.leftFunc : _ ⥤ T) := by
apply Comma.preservesColimitsOfShape_fst
instance preservesColimitsOfShape_rightFunc [HasColimitsOfShape J T] :
PreservesColimitsOfShape J (Arrow.rightFunc : _ ⥤ T) := by
apply Comma.preservesColimitsOfShape_snd
end Arrow
namespace StructuredArrow
variable {X : T} {G : A ⥤ T} (F : J ⥤ StructuredArrow X G)
instance hasLimit [i₁ : HasLimit (F ⋙ proj X G)] [i₂ : PreservesLimit (F ⋙ proj X G) G] :
HasLimit F := by
haveI : HasLimit (F ⋙ Comma.snd (Functor.fromPUnit X) G) := i₁
haveI : PreservesLimit (F ⋙ Comma.snd (Functor.fromPUnit X) G) _ := i₂
apply Comma.hasLimit
instance hasLimitsOfShape [HasLimitsOfShape J A] [PreservesLimitsOfShape J G] :
HasLimitsOfShape J (StructuredArrow X G) where
instance hasLimitsOfSize [HasLimitsOfSize.{w, w'} A] [PreservesLimitsOfSize.{w, w'} G] :
HasLimitsOfSize.{w, w'} (StructuredArrow X G) :=
⟨fun J hJ => by infer_instance⟩
noncomputable instance createsLimit [i : PreservesLimit (F ⋙ proj X G) G] :
CreatesLimit F (proj X G) :=
letI : PreservesLimit (F ⋙ Comma.snd (Functor.fromPUnit X) G) G := i
createsLimitOfReflectsIso fun _ t =>
{ liftedCone := Comma.coneOfPreserves F punitCone t
makesLimit := Comma.coneOfPreservesIsLimit _ punitConeIsLimit _
validLift := Cones.ext (Iso.refl _) fun _ => (id_comp _).symm }
noncomputable instance createsLimitsOfShape [PreservesLimitsOfShape J G] :
CreatesLimitsOfShape J (proj X G) where
noncomputable instance createsLimitsOfSize [PreservesLimitsOfSize.{w, w'} G] :
CreatesLimitsOfSize.{w, w'} (proj X G :) where
instance mono_right_of_mono [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G]
{Y Z : StructuredArrow X G} (f : Y ⟶ Z) [Mono f] : Mono f.right :=
show Mono ((proj X G).map f) from inferInstance
theorem mono_iff_mono_right [HasPullbacks A] [PreservesLimitsOfShape WalkingCospan G]
{Y Z : StructuredArrow X G} (f : Y ⟶ Z) : Mono f ↔ Mono f.right :=
⟨fun _ => inferInstance, fun _ => mono_of_mono_right f⟩
end StructuredArrow
namespace CostructuredArrow
variable {G : A ⥤ T} {X : T} (F : J ⥤ CostructuredArrow G X)
instance hasTerminal [G.Faithful] [G.Full] {Y : A} :
HasTerminal (CostructuredArrow G (G.obj Y)) :=
CostructuredArrow.mkIdTerminal.hasTerminal
instance hasColimit [i₁ : HasColimit (F ⋙ proj G X)] [i₂ : PreservesColimit (F ⋙ proj G X) G] :
HasColimit F := by
haveI : HasColimit (F ⋙ Comma.fst G (Functor.fromPUnit X)) := i₁
haveI : PreservesColimit (F ⋙ Comma.fst G (Functor.fromPUnit X)) _ := i₂
apply Comma.hasColimit
instance hasColimitsOfShape [HasColimitsOfShape J A] [PreservesColimitsOfShape J G] :
HasColimitsOfShape J (CostructuredArrow G X) where
instance hasColimitsOfSize [HasColimitsOfSize.{w, w'} A] [PreservesColimitsOfSize.{w, w'} G] :
HasColimitsOfSize.{w, w'} (CostructuredArrow G X) :=
⟨fun _ _ => inferInstance⟩
noncomputable instance createsColimit [i : PreservesColimit (F ⋙ proj G X) G] :
CreatesColimit F (proj G X) :=
letI : PreservesColimit (F ⋙ Comma.fst G (Functor.fromPUnit X)) G := i
createsColimitOfReflectsIso fun _ t =>
{ liftedCocone := Comma.coconeOfPreserves F t punitCocone
makesColimit := Comma.coconeOfPreservesIsColimit _ _ punitCoconeIsColimit
validLift := Cocones.ext (Iso.refl _) fun _ => comp_id _ }
noncomputable instance createsColimitsOfShape [PreservesColimitsOfShape J G] :
CreatesColimitsOfShape J (proj G X) where
noncomputable instance createsColimitsOfSize [PreservesColimitsOfSize.{w, w'} G] :
CreatesColimitsOfSize.{w, w'} (proj G X :) where
instance epi_left_of_epi [HasPushouts A] [PreservesColimitsOfShape WalkingSpan G]
{Y Z : CostructuredArrow G X} (f : Y ⟶ Z) [Epi f] : Epi f.left :=
show Epi ((proj G X).map f) from inferInstance
theorem epi_iff_epi_left [HasPushouts A] [PreservesColimitsOfShape WalkingSpan G]
{Y Z : CostructuredArrow G X} (f : Y ⟶ Z) : Epi f ↔ Epi f.left :=
⟨fun _ => inferInstance, fun _ => epi_of_epi_left f⟩
end CostructuredArrow
namespace Over
instance {X : T} : HasTerminal (Over X) := CostructuredArrow.hasTerminal
end Over
end CategoryTheory
|
frobenius.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div.
From mathcomp Require Import fintype bigop prime finset fingroup morphism.
From mathcomp Require Import perm action quotient gproduct cyclic center.
From mathcomp Require Import pgroup nilpotent sylow hall abelian.
(******************************************************************************)
(* Definition of Frobenius groups, some basic results, and the Frobenius *)
(* theorem on the number of solutions of x ^+ n = 1. *)
(* semiregular K H <-> *)
(* the internal action of H on K is semiregular, i.e., no nontrivial *)
(* elements of H and K commute; note that this is actually a symmetric *)
(* condition. *)
(* semiprime K H <-> *)
(* the internal action of H on K is "prime", i.e., an element of K that *)
(* centralises a nontrivial element of H must centralise all of H. *)
(* normedTI A G L <=> *)
(* A is nonempty, strictly disjoint from its conjugates in G, and has *)
(* normaliser L in G. *)
(* [Frobenius G = K ><| H] <=> *)
(* G is (isomorphic to) a Frobenius group with kernel K and complement *)
(* H. This is an effective predicate (in bool), which tests the *)
(* equality with the semidirect product, and then the fact that H is a *)
(* proper self-normalizing TI-subgroup of G. *)
(* [Frobenius G with kernel H] <=> *)
(* G is (isomorphic to) a Frobenius group with kernel K; same as above, *)
(* but without the semi-direct product. *)
(* [Frobenius G with complement H] <=> *)
(* G is (isomorphic to) a Frobenius group with complement H; same as *)
(* above, but without the semi-direct product. The proof that this form *)
(* is equivalent to the above (i.e., the existence of Frobenius *)
(* kernels) requires character theory and will only be proved in the *)
(* vcharacter.v file. *)
(* [Frobenius G] <=> G is a Frobenius group. *)
(* Frobenius_action G H S to <-> *)
(* The action to of G on S defines an isomorphism of G with a *)
(* (permutation) Frobenius group, i.e., to is faithful and transitive *)
(* on S, no nontrivial element of G fixes more than one point in S, and *)
(* H is the stabilizer of some element of S, and non-trivial. Thus, *)
(* Frobenius_action G H S 'P *)
(* asserts that G is a Frobenius group in the classic sense. *)
(* has_Frobenius_action G H <-> *)
(* Frobenius_action G H S to holds for some sT : finType, S : {set st} *)
(* and to : {action gT &-> sT}. This is a predicate in Prop, but is *)
(* exactly reflected by [Frobenius G with complement H] : bool. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Definitions.
Variable gT : finGroupType.
Implicit Types A G K H L : {set gT}.
(* Corresponds to "H acts on K in a regular manner" in B & G. *)
Definition semiregular K H := {in H^#, forall x, 'C_K[x] = 1}.
(* Corresponds to "H acts on K in a prime manner" in B & G. *)
Definition semiprime K H := {in H^#, forall x, 'C_K[x] = 'C_K(H)}.
Definition normedTI A G L := [&& A != set0, trivIset (A :^: G) & 'N_G(A) == L].
Definition Frobenius_group_with_complement G H := (H != G) && normedTI H^# G H.
Definition Frobenius_group G :=
[exists H : {group gT}, Frobenius_group_with_complement G H].
Definition Frobenius_group_with_kernel_and_complement G K H :=
(K ><| H == G) && Frobenius_group_with_complement G H.
Definition Frobenius_group_with_kernel G K :=
[exists H : {group gT}, Frobenius_group_with_kernel_and_complement G K H].
Section FrobeniusAction.
Variables G H : {set gT}.
Variables (sT : finType) (S : {set sT}) (to : {action gT &-> sT}).
Definition Frobenius_action :=
[/\ [faithful G, on S | to],
[transitive G, on S | to],
{in G^#, forall x, #|'Fix_(S | to)[x]| <= 1},
H != 1
& exists2 u, u \in S & H = 'C_G[u | to]].
End FrobeniusAction.
Variant has_Frobenius_action G H : Prop :=
hasFrobeniusAction sT S to of @Frobenius_action G H sT S to.
End Definitions.
Arguments semiregular {gT} K%_g H%_g.
Arguments semiprime {gT} K%_g H%_g.
Arguments normedTI {gT} A%_g G%_g L%_g.
Arguments Frobenius_group_with_complement {gT} G%_g H%_g.
Arguments Frobenius_group {gT} G%_g.
Arguments Frobenius_group_with_kernel {gT} G%_g K%_g.
Arguments Frobenius_group_with_kernel_and_complement {gT} G%_g K%_g H%_g.
Arguments Frobenius_action {gT} G%_g H%_g {sT} S%_g to%_act.
Arguments has_Frobenius_action {gT} G%_g H%_g.
Notation "[ 'Frobenius' G 'with' 'complement' H ]" :=
(Frobenius_group_with_complement G H)
(G at level 50,
format "[ 'Frobenius' G 'with' 'complement' H ]") : group_scope.
Notation "[ 'Frobenius' G 'with' 'kernel' K ]" :=
(Frobenius_group_with_kernel G K)
(format "[ 'Frobenius' G 'with' 'kernel' K ]") : group_scope.
Notation "[ 'Frobenius' G ]" := (Frobenius_group G)
(format "[ 'Frobenius' G ]") : group_scope.
Notation "[ 'Frobenius' G = K ><| H ]" :=
(Frobenius_group_with_kernel_and_complement G K H)
(K, H at level 35,
format "[ 'Frobenius' G = K ><| H ]") : group_scope.
Section FrobeniusBasics.
Variable gT : finGroupType.
Implicit Types (A B : {set gT}) (G H K L R X : {group gT}).
Lemma semiregular1l H : semiregular 1 H.
Proof. by move=> x _ /=; rewrite setI1g. Qed.
Lemma semiregular1r K : semiregular K 1.
Proof. by move=> x; rewrite setDv inE. Qed.
Lemma semiregular_sym H K : semiregular K H -> semiregular H K.
Proof.
move=> regH x /setD1P[ntx Kx]; apply: contraNeq ntx.
rewrite -subG1 -setD_eq0 -setIDAC => /set0Pn[y /setIP[Hy cxy]].
by rewrite (sameP eqP set1gP) -(regH y Hy) inE Kx cent1C.
Qed.
Lemma semiregularS K1 K2 A1 A2 :
K1 \subset K2 -> A1 \subset A2 -> semiregular K2 A2 -> semiregular K1 A1.
Proof.
move=> sK12 sA12 regKA2 x /setD1P[ntx /(subsetP sA12)A2x].
by apply/trivgP; rewrite -(regKA2 x) ?inE ?ntx ?setSI.
Qed.
Lemma semiregular_prime H K : semiregular K H -> semiprime K H.
Proof.
move=> regH x Hx; apply/eqP; rewrite eqEsubset {1}regH // sub1G.
by rewrite -cent_set1 setIS ?centS // sub1set; case/setD1P: Hx.
Qed.
Lemma semiprime_regular H K : semiprime K H -> 'C_K(H) = 1 -> semiregular K H.
Proof. by move=> prKH tiKcH x Hx; rewrite prKH. Qed.
Lemma semiprimeS K1 K2 A1 A2 :
K1 \subset K2 -> A1 \subset A2 -> semiprime K2 A2 -> semiprime K1 A1.
Proof.
move=> sK12 sA12 prKA2 x /setD1P[ntx A1x].
apply/eqP; rewrite eqEsubset andbC -{1}cent_set1 setIS ?centS ?sub1set //=.
rewrite -(setIidPl sK12) -!setIA prKA2 ?setIS ?centS //.
by rewrite !inE ntx (subsetP sA12).
Qed.
Lemma cent_semiprime H K X :
semiprime K H -> X \subset H -> X :!=: 1 -> 'C_K(X) = 'C_K(H).
Proof.
move=> prKH sXH /trivgPn[x Xx ntx]; apply/eqP.
rewrite eqEsubset -{1}(prKH x) ?inE ?(subsetP sXH) ?ntx //=.
by rewrite -cent_cycle !setIS ?centS ?cycle_subG.
Qed.
Lemma stab_semiprime H K X :
semiprime K H -> X \subset K -> 'C_H(X) != 1 -> 'C_H(X) = H.
Proof.
move=> prKH sXK ntCHX; apply/setIidPl; rewrite centsC -subsetIidl.
rewrite -{2}(setIidPl sXK) -setIA -(cent_semiprime prKH _ ntCHX) ?subsetIl //.
by rewrite !subsetI subxx sXK centsC subsetIr.
Qed.
Lemma cent_semiregular H K X :
semiregular K H -> X \subset H -> X :!=: 1 -> 'C_K(X) = 1.
Proof.
move=> regKH sXH /trivgPn[x Xx ntx]; apply/trivgP.
rewrite -(regKH x) ?inE ?(subsetP sXH) ?ntx ?setIS //=.
by rewrite -cent_cycle centS ?cycle_subG.
Qed.
Lemma regular_norm_dvd_pred K H :
H \subset 'N(K) -> semiregular K H -> #|H| %| #|K|.-1.
Proof.
move=> nKH regH; have actsH: [acts H, on K^# | 'J] by rewrite astabsJ normD1.
rewrite (cardsD1 1 K) group1 -(acts_sum_card_orbit actsH) /=.
rewrite (eq_bigr (fun _ => #|H|)) ?sum_nat_const ?dvdn_mull //.
move=> _ /imsetP[x /setIdP[ntx Kx] ->]; rewrite card_orbit astab1J.
rewrite ['C_H[x]](trivgP _) ?indexg1 //=.
apply/subsetP=> y /setIP[Hy cxy]; apply: contraR ntx => nty.
by rewrite -[[set 1]](regH y) inE ?nty // Kx cent1C.
Qed.
Lemma regular_norm_coprime K H :
H \subset 'N(K) -> semiregular K H -> coprime #|K| #|H|.
Proof.
move=> nKH regH.
by rewrite (coprime_dvdr (regular_norm_dvd_pred nKH regH)) ?coprimenP.
Qed.
Lemma semiregularJ K H x : semiregular K H -> semiregular (K :^ x) (H :^ x).
Proof.
move=> regH yx; rewrite -conjD1g => /imsetP[y Hy ->].
by rewrite cent1J -conjIg regH ?conjs1g.
Qed.
Lemma semiprimeJ K H x : semiprime K H -> semiprime (K :^ x) (H :^ x).
Proof.
move=> prH yx; rewrite -conjD1g => /imsetP[y Hy ->].
by rewrite cent1J centJ -!conjIg prH.
Qed.
Lemma normedTI_P A G L :
reflect [/\ A != set0, L \subset 'N_G(A)
& {in G, forall g, ~~ [disjoint A & A :^ g] -> g \in L}]
(normedTI A G L).
Proof.
apply: (iffP and3P) => [[nzA /trivIsetP tiAG /eqP <-] | [nzA sLN tiAG]].
split=> // g Gg; rewrite inE Gg (sameP normP eqP) /= eq_sym; apply: contraR.
by apply: tiAG; rewrite ?mem_orbit ?orbit_refl.
have [/set0Pn[a Aa] /subsetIP[_ nAL]] := (nzA, sLN); split=> //; last first.
rewrite eqEsubset sLN andbT; apply/subsetP=> x /setIP[Gx nAx].
by apply/tiAG/pred0Pn=> //; exists a; rewrite /= (normP nAx) Aa.
apply/trivIsetP=> _ _ /imsetP[x Gx ->] /imsetP[y Gy ->]; apply: contraR.
rewrite -setI_eq0 -(mulgKV x y) conjsgM; set g := (y * x^-1)%g.
have Gg: g \in G by rewrite groupMl ?groupV.
rewrite -conjIg (inj_eq (act_inj 'Js x)) (eq_sym A) (sameP eqP normP).
by rewrite -cards_eq0 cardJg cards_eq0 setI_eq0 => /tiAG/(subsetP nAL)->.
Qed.
Arguments normedTI_P {A G L}.
Lemma normedTI_memJ_P A G L :
reflect [/\ A != set0, L \subset G
& {in A & G, forall a g, (a ^ g \in A) = (g \in L)}]
(normedTI A G L).
Proof.
apply: (iffP normedTI_P) => [[-> /subsetIP[sLG nAL] tiAG] | [-> sLG tiAG]].
split=> // a g Aa Gg; apply/idP/idP=> [Aag | Lg]; last first.
by rewrite memJ_norm ?(subsetP nAL).
by apply/tiAG/pred0Pn=> //; exists (a ^ g)%g; rewrite /= Aag memJ_conjg.
split=> // [ | g Gg /pred0Pn[ag /=]]; last first.
by rewrite andbC => /andP[/imsetP[a Aa ->]]; rewrite tiAG.
apply/subsetP=> g Lg; have Gg := subsetP sLG g Lg.
by rewrite !inE Gg; apply/subsetP=> _ /imsetP[a Aa ->]; rewrite tiAG.
Qed.
Lemma partition_class_support A G :
A != set0 -> trivIset (A :^: G) -> partition (A :^: G) (class_support A G).
Proof.
rewrite /partition cover_imset -class_supportEr eqxx => nzA ->.
by apply: contra nzA => /imsetP[x _ /eqP]; rewrite eq_sym -!cards_eq0 cardJg.
Qed.
Lemma partition_normedTI A G L :
normedTI A G L -> partition (A :^: G) (class_support A G).
Proof. by case/and3P=> ntA tiAG _; apply: partition_class_support. Qed.
Lemma card_support_normedTI A G L :
normedTI A G L -> #|class_support A G| = (#|A| * #|G : L|)%N.
Proof.
case/and3P=> ntA tiAG /eqP <-; rewrite -card_conjugates mulnC.
apply: card_uniform_partition (partition_class_support ntA tiAG).
by move=> _ /imsetP[y _ ->]; rewrite cardJg.
Qed.
Lemma normedTI_S A B G L :
A != set0 -> L \subset 'N(A) -> A \subset B -> normedTI B G L ->
normedTI A G L.
Proof.
move=> nzA /subsetP nAL /subsetP sAB /normedTI_memJ_P[nzB sLG tiB].
apply/normedTI_memJ_P; split=> // a x Aa Gx.
by apply/idP/idP => [Aax | /nAL/memJ_norm-> //]; rewrite -(tiB a) ?sAB.
Qed.
Lemma cent1_normedTI A G L :
normedTI A G L -> {in A, forall x, 'C_G[x] \subset L}.
Proof.
case/normedTI_memJ_P=> [_ _ tiAG] x Ax; apply/subsetP=> y /setIP[Gy cxy].
by rewrite -(tiAG x) // /(x ^ y) -(cent1P cxy) mulKg.
Qed.
Lemma Frobenius_actionP G H :
reflect (has_Frobenius_action G H) [Frobenius G with complement H].
Proof.
apply: (iffP andP) => [[neqHG] | [sT S to [ffulG transG regG ntH [u Su defH]]]].
case/normedTI_P=> nzH /subsetIP[sHG _] tiHG.
suffices: Frobenius_action G H (rcosets H G) 'Rs by apply: hasFrobeniusAction.
pose Hfix x := 'Fix_(rcosets H G | 'Rs)[x].
have regG: {in G^#, forall x, #|Hfix x| <= 1}.
move=> x /setD1P[ntx Gx].
apply: wlog_neg; rewrite -ltnNge => /ltnW/card_gt0P/=[Hy].
rewrite -(cards1 Hy) => /setIP[/imsetP[y Gy ->{Hy}] cHyx].
apply/subset_leq_card/subsetP=> _ /setIP[/imsetP[z Gz ->] cHzx].
rewrite -!sub_astab1 !astab1_act !sub1set astab1Rs in cHyx cHzx *.
rewrite !rcosetE; apply/set1P/rcoset_eqP; rewrite mem_rcoset.
apply: tiHG; [by rewrite !in_group | apply/pred0Pn; exists (x ^ y^-1)].
by rewrite conjD1g !inE conjg_eq1 ntx -mem_conjg cHyx conjsgM memJ_conjg.
have ntH: H :!=: 1 by rewrite -subG1 -setD_eq0.
split=> //; first 1 last; first exact: transRs_rcosets.
by exists (val H); rewrite ?orbit_refl // astab1Rs (setIidPr sHG).
apply/subsetP=> y /setIP[Gy cHy]; apply: contraR neqHG => nt_y.
rewrite (index1g sHG) //; apply/eqP; rewrite eqn_leq indexg_gt0 andbT.
apply: leq_trans (regG y _); last by rewrite setDE 2!inE Gy nt_y /=.
by rewrite /Hfix (setIidPl _) -1?astabC ?sub1set.
have sHG: H \subset G by rewrite defH subsetIl.
split.
apply: contraNneq ntH => /= defG.
suffices defS: S = [set u] by rewrite -(trivgP ffulG) /= defS defH.
apply/eqP; rewrite eq_sym eqEcard sub1set Su.
by rewrite -(atransP transG u Su) card_orbit -defH defG indexgg cards1.
apply/normedTI_P; rewrite setD_eq0 subG1 normD1 subsetI sHG normG.
split=> // x Gx; rewrite -setI_eq0 conjD1g defH inE Gx conjIg conjGid //.
rewrite -setDIl -setIIr -astab1_act setDIl => /set0Pn[y /setIP[Gy /setD1P[_]]].
case/setIP; rewrite 2!(sameP astab1P afix1P) => cuy cuxy; apply/astab1P.
apply: contraTeq (regG y Gy) => cu'x.
rewrite (cardD1 u) (cardD1 (to u x)) inE Su cuy inE /= inE cu'x cuxy.
by rewrite (actsP (atrans_acts transG)) ?Su.
Qed.
Section FrobeniusProperties.
Variables G H K : {group gT}.
Hypothesis frobG : [Frobenius G = K ><| H].
Lemma FrobeniusWker : [Frobenius G with kernel K].
Proof. by apply/existsP; exists H. Qed.
Lemma FrobeniusWcompl : [Frobenius G with complement H].
Proof. by case/andP: frobG. Qed.
Lemma FrobeniusW : [Frobenius G].
Proof. by apply/existsP; exists H; apply: FrobeniusWcompl. Qed.
Lemma Frobenius_context :
[/\ K ><| H = G, K :!=: 1, H :!=: 1, K \proper G & H \proper G].
Proof.
have [/eqP defG neqHG ntH _] := and4P frobG; rewrite setD_eq0 subG1 in ntH.
have ntK: K :!=: 1 by apply: contraNneq neqHG => K1; rewrite -defG K1 sdprod1g.
rewrite properEcard properEneq neqHG; have /mulG_sub[-> ->] := sdprodW defG.
by rewrite -(sdprod_card defG) ltn_Pmulr ?cardG_gt1.
Qed.
Lemma Frobenius_partition : partition (gval K |: (H^# :^: K)) G.
Proof.
have [/eqP defG _ tiHG] := and3P frobG; have [_ tiH1G /eqP defN] := and3P tiHG.
have [[_ /mulG_sub[sKG sHG] nKH tiKH] mulHK] := (sdprodP defG, sdprodWC defG).
set HG := H^# :^: K; set KHG := _ |: _.
have defHG: HG = H^# :^: G.
have: 'C_G[H^# | 'Js] * K = G by rewrite astab1Js defN mulHK.
move/subgroup_transitiveP/atransP.
by apply; rewrite ?atrans_orbit ?orbit_refl.
have /and3P[defHK _ nzHG] := partition_normedTI tiHG.
rewrite -defHG in defHK nzHG tiH1G.
have [tiKHG HG'K]: trivIset KHG /\ gval K \notin HG.
apply: trivIsetU1 => // _ /imsetP[x Kx ->]; rewrite -setI_eq0.
by rewrite -(conjGid Kx) -conjIg setIDA tiKH setDv conj0g.
rewrite /partition andbC tiKHG !inE negb_or nzHG eq_sym -card_gt0 cardG_gt0 /=.
rewrite eqEcard; apply/andP; split.
rewrite /cover big_setU1 //= subUset sKG -/(cover HG) (eqP defHK).
by rewrite class_support_subG // (subset_trans _ sHG) ?subD1set.
rewrite -(eqnP tiKHG) big_setU1 //= (eqnP tiH1G) (eqP defHK).
rewrite (card_support_normedTI tiHG) -(Lagrange sHG) (cardsD1 1) group1 mulSn.
by rewrite leq_add2r -mulHK indexMg -indexgI tiKH indexg1.
Qed.
Lemma Frobenius_cent1_ker : {in K^#, forall x, 'C_G[x] \subset K}.
Proof.
have [/eqP defG _ /normedTI_memJ_P[_ _ tiHG]] := and3P frobG.
move=> x /setD1P[ntx Kx]; have [_ /mulG_sub[sKG _] _ tiKH] := sdprodP defG.
have [/eqP <- _ _] := and3P Frobenius_partition; rewrite big_distrl /=.
apply/bigcupsP=> _ /setU1P[|/imsetP[y Ky]] ->; first exact: subsetIl.
apply: contraR ntx => /subsetPn[z]; rewrite inE mem_conjg => /andP[Hzy cxz] _.
rewrite -(conjg_eq1 x y^-1) -in_set1 -set1gE -tiKH inE andbC.
rewrite -(tiHG _ _ Hzy) ?(subsetP sKG) ?in_group // Ky andbT -conjJg.
by rewrite /(z ^ x) (cent1P cxz) mulKg.
Qed.
Lemma Frobenius_reg_ker : semiregular K H.
Proof.
move=> x /setD1P[ntx Hx].
apply/trivgP/subsetP=> y /setIP[Ky cxy]; apply: contraR ntx => nty.
have K1y: y \in K^# by rewrite inE nty.
have [/eqP/sdprod_context[_ sHG _ _ tiKH] _] := andP frobG.
suffices: x \in K :&: H by rewrite tiKH inE.
by rewrite inE (subsetP (Frobenius_cent1_ker K1y)) // inE cent1C (subsetP sHG).
Qed.
Lemma Frobenius_reg_compl : semiregular H K.
Proof. by apply: semiregular_sym; apply: Frobenius_reg_ker. Qed.
Lemma Frobenius_dvd_ker1 : #|H| %| #|K|.-1.
Proof.
apply: regular_norm_dvd_pred Frobenius_reg_ker.
by have[/sdprodP[]] := Frobenius_context.
Qed.
Lemma ltn_odd_Frobenius_ker : odd #|G| -> #|H|.*2 < #|K|.
Proof.
move/oddSg=> oddG.
have [/sdprodW/mulG_sub[sKG sHG] ntK _ _ _] := Frobenius_context.
by rewrite dvdn_double_ltn ?oddG ?cardG_gt1 ?Frobenius_dvd_ker1.
Qed.
Lemma Frobenius_index_dvd_ker1 : #|G : K| %| #|K|.-1.
Proof.
have[defG _ _ /andP[sKG _] _] := Frobenius_context.
by rewrite -divgS // -(sdprod_card defG) mulKn ?Frobenius_dvd_ker1.
Qed.
Lemma Frobenius_coprime : coprime #|K| #|H|.
Proof. by rewrite (coprime_dvdr Frobenius_dvd_ker1) ?coprimenP. Qed.
Lemma Frobenius_trivg_cent : 'C_K(H) = 1.
Proof.
by apply: (cent_semiregular Frobenius_reg_ker); case: Frobenius_context.
Qed.
Lemma Frobenius_index_coprime : coprime #|K| #|G : K|.
Proof. by rewrite (coprime_dvdr Frobenius_index_dvd_ker1) ?coprimenP. Qed.
Lemma Frobenius_ker_Hall : Hall G K.
Proof.
have [_ _ _ /andP[sKG _] _] := Frobenius_context.
by rewrite /Hall sKG Frobenius_index_coprime.
Qed.
Lemma Frobenius_compl_Hall : Hall G H.
Proof.
have [defG _ _ _ _] := Frobenius_context.
by rewrite -(sdprod_Hall defG) Frobenius_ker_Hall.
Qed.
End FrobeniusProperties.
Lemma normedTI_J x A G L : normedTI (A :^ x) (G :^ x) (L :^ x) = normedTI A G L.
Proof.
rewrite {1}/normedTI normJ -conjIg -(conj0g x) !(can_eq (conjsgK x)).
congr [&& _, _ == _ & _]; rewrite /cover (reindex_inj (@conjsg_inj _ x)).
by apply: eq_big => Hy; rewrite ?orbit_conjsg ?cardJg.
by rewrite bigcupJ cardJg (eq_bigl _ _ (orbit_conjsg _ _ _ _)).
Qed.
Lemma FrobeniusJcompl x G H :
[Frobenius G :^ x with complement H :^ x] = [Frobenius G with complement H].
Proof.
by congr (_ && _); rewrite ?(can_eq (conjsgK x)) // -conjD1g normedTI_J.
Qed.
Lemma FrobeniusJ x G K H :
[Frobenius G :^ x = K :^ x ><| H :^ x] = [Frobenius G = K ><| H].
Proof.
by congr (_ && _); rewrite ?FrobeniusJcompl // -sdprodJ (can_eq (conjsgK x)).
Qed.
Lemma FrobeniusJker x G K :
[Frobenius G :^ x with kernel K :^ x] = [Frobenius G with kernel K].
Proof.
apply/existsP/existsP=> [] [H]; last by exists (H :^ x)%G; rewrite FrobeniusJ.
by rewrite -(conjsgKV x H) FrobeniusJ; exists (H :^ x^-1)%G.
Qed.
Lemma FrobeniusJgroup x G : [Frobenius G :^ x] = [Frobenius G].
Proof.
apply/existsP/existsP=> [] [H].
by rewrite -(conjsgKV x H) FrobeniusJcompl; exists (H :^ x^-1)%G.
by exists (H :^ x)%G; rewrite FrobeniusJcompl.
Qed.
Lemma Frobenius_ker_dvd_ker1 G K :
[Frobenius G with kernel K] -> #|G : K| %| #|K|.-1.
Proof. by case/existsP=> H; apply: Frobenius_index_dvd_ker1. Qed.
Lemma Frobenius_ker_coprime G K :
[Frobenius G with kernel K] -> coprime #|K| #|G : K|.
Proof. by case/existsP=> H; apply: Frobenius_index_coprime. Qed.
Lemma Frobenius_semiregularP G K H :
K ><| H = G -> K :!=: 1 -> H :!=: 1 ->
reflect (semiregular K H) [Frobenius G = K ><| H].
Proof.
move=> defG ntK ntH.
apply: (iffP idP) => [|regG]; first exact: Frobenius_reg_ker.
have [nsKG sHG defKH nKH tiKH]:= sdprod_context defG; have [sKG _]:= andP nsKG.
apply/and3P; split; first by rewrite defG.
by rewrite eqEcard sHG -(sdprod_card defG) -ltnNge ltn_Pmull ?cardG_gt1.
apply/normedTI_memJ_P; rewrite setD_eq0 subG1 sHG -defKH -(normC nKH).
split=> // z _ /setD1P[ntz Hz] /mulsgP[y x Hy Kx ->]; rewrite groupMl // !inE.
rewrite conjg_eq1 ntz; apply/idP/idP=> [Hzxy | Hx]; last by rewrite !in_group.
apply: (subsetP (sub1G H)); have Hzy: z ^ y \in H by apply: groupJ.
rewrite -(regG (z ^ y)); last by apply/setD1P; rewrite conjg_eq1.
rewrite inE Kx cent1C (sameP cent1P commgP) -in_set1 -[[set 1]]tiKH inE /=.
rewrite andbC groupM ?groupV -?conjgM //= commgEr groupMr //.
by rewrite memJ_norm ?(subsetP nKH) ?groupV.
Qed.
Lemma prime_FrobeniusP G K H :
K :!=: 1 -> prime #|H| ->
reflect (K ><| H = G /\ 'C_K(H) = 1) [Frobenius G = K ><| H].
Proof.
move=> ntK H_pr; have ntH: H :!=: 1 by rewrite -cardG_gt1 prime_gt1.
have [defG | not_sdG] := eqVneq (K ><| H) G; last first.
by apply: (iffP andP) => [] [defG]; rewrite defG ?eqxx in not_sdG.
apply: (iffP (Frobenius_semiregularP defG ntK ntH)) => [regH | [_ regH x]].
split=> //; have [x defH] := cyclicP (prime_cyclic H_pr).
by rewrite defH cent_cycle regH // !inE defH cycle_id andbT -cycle_eq1 -defH.
case/setD1P=> nt_x Hx; apply/trivgP; rewrite -regH setIS //= -cent_cycle.
by rewrite centS // prime_meetG // (setIidPr _) ?cycle_eq1 ?cycle_subG.
Qed.
Lemma Frobenius_subl G K K1 H :
K1 :!=: 1 -> K1 \subset K -> H \subset 'N(K1) -> [Frobenius G = K ><| H] ->
[Frobenius K1 <*> H = K1 ><| H].
Proof.
move=> ntK1 sK1K nK1H frobG; have [_ _ ntH _ _] := Frobenius_context frobG.
apply/Frobenius_semiregularP=> //.
by rewrite sdprodEY ?coprime_TIg ?(coprimeSg sK1K) ?(Frobenius_coprime frobG).
by move=> x /(Frobenius_reg_ker frobG) cKx1; apply/trivgP; rewrite -cKx1 setSI.
Qed.
Lemma Frobenius_subr G K H H1 :
H1 :!=: 1 -> H1 \subset H -> [Frobenius G = K ><| H] ->
[Frobenius K <*> H1 = K ><| H1].
Proof.
move=> ntH1 sH1H frobG; have [defG ntK _ _ _] := Frobenius_context frobG.
apply/Frobenius_semiregularP=> //.
have [_ _ /(subset_trans sH1H) nH1K tiHK] := sdprodP defG.
by rewrite sdprodEY //; apply/trivgP; rewrite -tiHK setIS.
by apply: sub_in1 (Frobenius_reg_ker frobG); apply/subsetP/setSD.
Qed.
Lemma Frobenius_kerP G K :
reflect [/\ K :!=: 1, K \proper G, K <| G
& {in K^#, forall x, 'C_G[x] \subset K}]
[Frobenius G with kernel K].
Proof.
apply: (iffP existsP) => [[H frobG] | [ntK ltKG nsKG regK]].
have [/sdprod_context[nsKG _ _ _ _] ntK _ ltKG _] := Frobenius_context frobG.
by split=> //; apply: Frobenius_cent1_ker frobG.
have /andP[sKG nKG] := nsKG.
have hallK: Hall G K.
rewrite /Hall sKG //= coprime_sym coprime_pi' //.
apply: sub_pgroup (pgroup_pi K) => p; have [P sylP] := Sylow_exists p G.
have [[sPG pP p'GiP] sylPK] := (and3P sylP, Hall_setI_normal nsKG sylP).
rewrite -p_rank_gt0 -(rank_Sylow sylPK) rank_gt0 => ntPK.
rewrite inE /= -p'natEpi // (pnat_dvd _ p'GiP) ?indexgS //.
have /trivgPn[z]: P :&: K :&: 'Z(P) != 1.
by rewrite meet_center_nil ?(pgroup_nil pP) ?(normalGI sPG nsKG).
rewrite !inE -andbA -sub_cent1=> /and4P[_ Kz _ cPz] ntz.
by apply: subset_trans (regK z _); [apply/subsetIP | apply/setD1P].
have /splitsP[H /complP[tiKH defG]] := SchurZassenhaus_split hallK nsKG.
have [_ sHG] := mulG_sub defG; have nKH := subset_trans sHG nKG.
exists H; apply/Frobenius_semiregularP; rewrite ?sdprodE //.
by apply: contraNneq (proper_subn ltKG) => H1; rewrite -defG H1 mulg1.
apply: semiregular_sym => x Kx; apply/trivgP; rewrite -tiKH.
by rewrite subsetI subsetIl (subset_trans _ (regK x _)) ?setSI.
Qed.
Lemma set_Frobenius_compl G K H :
K ><| H = G -> [Frobenius G with kernel K] -> [Frobenius G = K ><| H].
Proof.
move=> defG /Frobenius_kerP[ntK ltKG _ regKG].
apply/Frobenius_semiregularP=> //.
by apply: contraTneq ltKG => H_1; rewrite -defG H_1 sdprodg1 properxx.
apply: semiregular_sym => y /regKG sCyK.
have [_ sHG _ _ tiKH] := sdprod_context defG.
by apply/trivgP; rewrite /= -(setIidPr sHG) setIAC -tiKH setSI.
Qed.
Lemma Frobenius_kerS G K G1 :
G1 \subset G -> K \proper G1 ->
[Frobenius G with kernel K] -> [Frobenius G1 with kernel K].
Proof.
move=> sG1G ltKG1 /Frobenius_kerP[ntK _ /andP[_ nKG] regKG].
apply/Frobenius_kerP; rewrite /normal proper_sub // (subset_trans sG1G) //.
by split=> // x /regKG; apply: subset_trans; rewrite setSI.
Qed.
Lemma Frobenius_action_kernel_def G H K sT S to :
K ><| H = G -> @Frobenius_action _ G H sT S to ->
K :=: 1 :|: [set x in G | 'Fix_(S | to)[x] == set0].
Proof.
move=> defG FrobG.
have partG: partition (gval K |: (H^# :^: K)) G.
apply: Frobenius_partition; apply/andP; rewrite defG; split=> //.
by apply/Frobenius_actionP; apply: hasFrobeniusAction FrobG.
have{FrobG} [ffulG transG regG ntH [u Su defH]]:= FrobG.
apply/setP=> x /[!inE]; have [-> | ntx] := eqVneq; first exact: group1.
rewrite /= -(cover_partition partG) /cover.
have neKHy y: gval K <> H^# :^ y.
by move/setP/(_ 1); rewrite group1 conjD1g setD11.
rewrite big_setU1 /= ?inE; last by apply/imsetP=> [[y _ /neKHy]].
have [nsKG sHG _ _ tiKH] := sdprod_context defG; have [sKG nKG]:= andP nsKG.
symmetry; case Kx: (x \in K) => /=.
apply/set0Pn=> [[v /setIP[Sv]]]; have [y Gy ->] := atransP2 transG Su Sv.
rewrite -sub1set -astabC sub1set astab1_act mem_conjg => Hxy.
case/negP: ntx; rewrite -in_set1 -(conjgKV y x) -mem_conjgV conjs1g -tiKH.
by rewrite defH setIA inE -mem_conjg (setIidPl sKG) (normsP nKG) ?Kx.
apply/andP=> [[/bigcupP[_ /imsetP[y Ky ->] Hyx] /set0Pn[]]]; exists (to u y).
rewrite inE (actsP (atrans_acts transG)) ?(subsetP sKG) // Su.
rewrite -sub1set -astabC sub1set astab1_act.
by rewrite conjD1g defH conjIg !inE in Hyx; case/and3P: Hyx.
Qed.
End FrobeniusBasics.
Arguments normedTI_P {gT A G L}.
Arguments normedTI_memJ_P {gT A G L}.
Arguments Frobenius_kerP {gT G K}.
Lemma Frobenius_coprime_quotient (gT : finGroupType) (G K H N : {group gT}) :
K ><| H = G -> N <| G -> coprime #|K| #|H| /\ H :!=: 1%g ->
N \proper K /\ {in H^#, forall x, 'C_K[x] \subset N} ->
[Frobenius G / N = (K / N) ><| (H / N)]%g.
Proof.
move=> defG nsNG [coKH ntH] [ltNK regH].
have [[sNK _] [_ /mulG_sub[sKG sHG] _ _]] := (andP ltNK, sdprodP defG).
have [_ nNG] := andP nsNG; have nNH := subset_trans sHG nNG.
apply/Frobenius_semiregularP; first exact: quotient_coprime_sdprod.
- by rewrite quotient_neq1 ?(normalS _ sKG).
- by rewrite -(isog_eq1 (quotient_isog _ _)) ?coprime_TIg ?(coprimeSg sNK).
move=> _ /(subsetP (quotientD1 _ _))/morphimP[x nNx H1x ->].
rewrite -cent_cycle -quotient_cycle //=.
rewrite -strongest_coprime_quotient_cent ?cycle_subG //.
- by rewrite cent_cycle quotientS1 ?regH.
- by rewrite subIset ?sNK.
- rewrite (coprimeSg (subsetIl N _)) ?(coprimeSg sNK) ?(coprimegS _ coKH) //.
by rewrite cycle_subG; case/setD1P: H1x.
by rewrite orbC abelian_sol ?cycle_abelian.
Qed.
Section InjmFrobenius.
Variables (gT rT : finGroupType) (D G : {group gT}) (f : {morphism D >-> rT}).
Implicit Types (H K : {group gT}) (sGD : G \subset D) (injf : 'injm f).
Lemma injm_Frobenius_compl H sGD injf :
[Frobenius G with complement H] -> [Frobenius f @* G with complement f @* H].
Proof.
case/andP=> neqGH /normedTI_P[nzH /subsetIP[sHG _] tiHG].
have sHD := subset_trans sHG sGD; have sH1D := subset_trans (subD1set H 1) sHD.
apply/andP; rewrite (can_in_eq (injmK injf)) //; split=> //.
apply/normedTI_P; rewrite normD1 -injmD1 // -!cards_eq0 card_injm // in nzH *.
rewrite subsetI normG morphimS //; split=> // _ /morphimP[x Dx Gx ->] ti'fHx.
rewrite mem_morphim ?tiHG //; apply: contra ti'fHx; rewrite -!setI_eq0 => tiHx.
by rewrite -morphimJ // -injmI ?conj_subG // (eqP tiHx) morphim0.
Qed.
Lemma injm_Frobenius H K sGD injf :
[Frobenius G = K ><| H] -> [Frobenius f @* G = f @* K ><| f @* H].
Proof.
case/andP=> /eqP defG frobG.
by apply/andP; rewrite (injm_sdprod _ injf defG) // eqxx injm_Frobenius_compl.
Qed.
Lemma injm_Frobenius_ker K sGD injf :
[Frobenius G with kernel K] -> [Frobenius f @* G with kernel f @* K].
Proof.
case/existsP=> H frobG; apply/existsP.
by exists (f @* H)%G; apply: injm_Frobenius.
Qed.
Lemma injm_Frobenius_group sGD injf : [Frobenius G] -> [Frobenius f @* G].
Proof.
case/existsP=> H frobG; apply/existsP; exists (f @* H)%G.
exact: injm_Frobenius_compl.
Qed.
End InjmFrobenius.
Theorem Frobenius_Ldiv (gT : finGroupType) (G : {group gT}) n :
n %| #|G| -> n %| #|'Ldiv_n(G)|.
Proof.
move=> nG; move: {2}_.+1 (ltnSn (#|G| %/ n)) => mq.
elim: mq => // mq IHm in gT G n nG *; case/dvdnP: nG => q oG.
have [q_gt0 n_gt0] : 0 < q /\ 0 < n by apply/andP; rewrite -muln_gt0 -oG.
rewrite ltnS oG mulnK // => leqm.
have:= q_gt0; rewrite leq_eqVlt => /predU1P[q1 | lt1q].
rewrite -(mul1n n) q1 -oG (setIidPl _) //.
by apply/subsetP=> x Gx; rewrite inE -order_dvdn order_dvdG.
pose p := pdiv q; have pr_p: prime p by apply: pdiv_prime.
have lt1p: 1 < p := prime_gt1 pr_p; have p_gt0 := ltnW lt1p.
have{leqm} lt_qp_mq: q %/ p < mq by apply: leq_trans leqm; rewrite ltn_Pdiv.
have: n %| #|'Ldiv_(p * n)(G)|.
have: p * n %| #|G| by rewrite oG dvdn_pmul2r ?pdiv_dvd.
move/IHm=> IH; apply: dvdn_trans (IH _); first exact: dvdn_mull.
by rewrite oG divnMr.
rewrite -(cardsID 'Ldiv_n()) dvdn_addl.
rewrite -setIA ['Ldiv_n(_)](setIidPr _) //.
by apply/subsetP=> x; rewrite !inE -!order_dvdn; apply: dvdn_mull.
rewrite -setIDA; set A := _ :\: _.
have pA x: x \in A -> #[x]`_p = (n`_p * p)%N.
rewrite !inE -!order_dvdn => /andP[xn xnp].
rewrite !p_part // -expnSr; congr (p ^ _)%N; apply/eqP.
rewrite eqn_leq -{1}addn1 -(pfactorK 1 pr_p) -lognM ?expn1 // mulnC.
rewrite dvdn_leq_log ?muln_gt0 ?p_gt0 //= ltnNge; apply: contra xn => xn.
move: xnp; rewrite -[#[x]](partnC p) //.
rewrite !Gauss_dvd ?coprime_partC //; case/andP=> _.
rewrite p_part ?pfactor_dvdn // xn Gauss_dvdr // coprime_sym.
exact: pnat_coprime (pnat_id _) (part_pnat _ _).
rewrite -(partnC p n_gt0) Gauss_dvd ?coprime_partC //; apply/andP; split.
rewrite -sum1_card (partition_big_imset (@cycle _)) /=.
apply: dvdn_sum => _ /imsetP[x /setIP[Gx Ax] ->].
rewrite (eq_bigl (generator <[x]>)) => [|y].
rewrite sum1dep_card -totient_gen -[#[x]](partnC p) //.
rewrite totient_coprime ?coprime_partC // dvdn_mulr // .
by rewrite (pA x Ax) p_part // -expnSr totient_pfactor // dvdn_mull.
rewrite /generator eq_sym andbC; case xy: {+}(_ == _) => //.
rewrite !inE -!order_dvdn in Ax *.
by rewrite -cycle_subG /order -(eqP xy) cycle_subG Gx.
rewrite -sum1_card (partition_big_imset (fun x => x.`_p ^: G)) /=.
apply: dvdn_sum => _ /imsetP[x /setIP[Gx Ax] ->].
set y := x.`_p; have oy: #[y] = (n`_p * p)%N by rewrite order_constt pA.
rewrite (partition_big (fun x => x.`_p) [in y ^: G]) /= => [|z]; last first.
by case/andP=> _ /eqP <-; rewrite /= class_refl.
pose G' := ('C_G[y] / <[y]>)%G; pose n' := gcdn #|G'| n`_p^'.
have n'_gt0: 0 < n' by rewrite gcdn_gt0 cardG_gt0.
rewrite (eq_bigr (fun _ => #|'Ldiv_n'(G')|)) => [|_ /imsetP[a Ga ->]].
rewrite sum_nat_const -index_cent1 indexgI.
rewrite -(dvdn_pmul2l (cardG_gt0 'C_G[y])) mulnA LagrangeI.
have oCy: #|'C_G[y]| = (#[y] * #|G'|)%N.
rewrite card_quotient ?subcent1_cycle_norm // Lagrange //.
by rewrite subcent1_cycle_sub ?groupX.
rewrite oCy -mulnA -(muln_lcm_gcd #|G'|) -/n' mulnA dvdn_mul //.
rewrite muln_lcmr -oCy order_constt pA // mulnAC partnC // dvdn_lcm.
by rewrite cardSg ?subsetIl // mulnC oG dvdn_pmul2r ?pdiv_dvd.
apply: IHm; [exact: dvdn_gcdl | apply: leq_ltn_trans lt_qp_mq].
rewrite -(@divnMr n`_p^') // -muln_lcm_gcd mulnC divnMl //.
rewrite leq_divRL // divn_mulAC ?leq_divLR ?dvdn_mulr ?dvdn_lcmr //.
rewrite dvdn_leq ?muln_gt0 ?q_gt0 //= mulnC muln_lcmr dvdn_lcm.
rewrite -(@dvdn_pmul2l n`_p) // mulnA -oy -oCy mulnCA partnC // -oG.
by rewrite cardSg ?subsetIl // dvdn_mul ?pdiv_dvd.
pose h := [fun z => coset <[y]> (z ^ a^-1)].
pose h' := [fun Z : coset_of <[y]> => (y * (repr Z).`_p^') ^ a].
rewrite -sum1_card (reindex_onto h h') /= => [|Z]; last first.
rewrite conjgK coset_kerl ?cycle_id ?morph_constt ?repr_coset_norm //.
rewrite /= coset_reprK 2!inE -order_dvdn dvdn_gcd => /and3P[_ _ p'Z].
by apply: constt_p_elt (pnat_dvd p'Z _); apply: part_pnat.
apply: eq_bigl => z; apply/andP/andP=> [[]|[]].
rewrite inE -andbA => /and3P[Gz Az _] /eqP zp_ya.
have czy: z ^ a^-1 \in 'C[y].
rewrite -mem_conjg -normJ conjg_set1 -zp_ya.
by apply/cent1P; apply: commuteX.
have Nz: z ^ a^-1 \in 'N(<[y]>) by apply: subsetP czy; apply: norm_gen.
have G'z: h z \in G' by rewrite mem_morphim //= inE groupJ // groupV.
rewrite inE G'z inE -order_dvdn dvdn_gcd order_dvdG //=.
rewrite /order -morphim_cycle // -quotientE card_quotient ?cycle_subG //.
rewrite -(@dvdn_pmul2l #[y]) // Lagrange; last first.
by rewrite /= cycleJ cycle_subG mem_conjgV -zp_ya mem_cycle.
rewrite oy mulnAC partnC // [#|_|]orderJ; split.
by rewrite !inE -!order_dvdn mulnC in Az; case/andP: Az.
set Z := coset _ _; have NZ := repr_coset_norm Z; have:= coset_reprK Z.
case/kercoset_rcoset=> {NZ}// _ /cycleP[i ->] ->{Z}.
rewrite consttM; last exact/commute_sym/commuteX/cent1P.
rewrite (constt1P _) ?p_eltNK 1?p_eltX ?p_elt_constt // mul1g.
by rewrite conjMg consttJ conjgKV -zp_ya consttC.
rewrite 2!inE -order_dvdn; set Z := coset _ _ => /andP[Cz n'Z] /eqP def_z.
have Nz: z ^ a^-1 \in 'N(<[y]>).
rewrite -def_z conjgK groupMr; first by rewrite -(cycle_subG y) normG.
by rewrite groupX ?repr_coset_norm.
have{Cz} /setIP[Gz Cz]: z ^ a^-1 \in 'C_G[y].
case/morphimP: Cz => u Nu Cu /kercoset_rcoset[] // _ /cycleP[i ->] ->.
by rewrite groupMr // groupX // inE groupX //; apply/cent1P.
have{def_z} zp_ya: z.`_p = y ^ a.
rewrite -def_z consttJ consttM.
rewrite constt_p_elt ?p_elt_constt //.
by rewrite (constt1P _) ?p_eltNK ?p_elt_constt ?mulg1.
apply: commute_sym; apply/cent1P.
by rewrite -def_z conjgK groupMl // in Cz; apply/cent1P.
have ozp: #[z ^ a^-1]`_p = #[y] by rewrite -order_constt consttJ zp_ya conjgK.
split; rewrite zp_ya // -class_lcoset lcoset_id // eqxx andbT.
rewrite -(conjgKV a z) !inE groupJ //= -!order_dvdn orderJ; apply/andP; split.
apply: contra (partn_dvd p n_gt0) _.
by rewrite ozp -(muln1 n`_p) oy dvdn_pmul2l // dvdn1 neq_ltn lt1p orbT.
rewrite -(partnC p n_gt0) mulnCA mulnA -oy -(@partnC p #[_]) // ozp.
apply dvdn_mul => //; apply: dvdn_trans (dvdn_trans n'Z (dvdn_gcdr _ _)).
rewrite {2}/order -morphim_cycle // -quotientE card_quotient ?cycle_subG //.
rewrite -(@dvdn_pmul2l #|<[z ^ a^-1]> :&: <[y]>|) ?cardG_gt0 // LagrangeI.
rewrite -[#|<[_]>|](partnC p) ?order_gt0 // dvdn_pmul2r // ozp.
by rewrite cardSg ?subsetIr.
Qed.
|
FinitePresentation.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.LinearAlgebra.FreeModule.Finite.Basic
import Mathlib.LinearAlgebra.Isomorphisms
import Mathlib.LinearAlgebra.TensorProduct.RightExactness
import Mathlib.RingTheory.Finiteness.Projective
import Mathlib.RingTheory.Localization.BaseChange
import Mathlib.RingTheory.Noetherian.Basic
import Mathlib.RingTheory.TensorProduct.Finite
/-!
# Finitely Presented Modules
## Main definition
- `Module.FinitePresentation`: A module is finitely presented if it is generated by some
finite set `s` and the kernel of the presentation `Rˢ → M` is also finitely generated.
## Main results
- `Module.finitePresentation_iff_finite`: If `R` is noetherian, then f.p. iff f.g. on `R`-modules.
Suppose `0 → K → M → N → 0` is an exact sequence of `R`-modules.
- `Module.finitePresentation_of_surjective`: If `M` is f.p., `K` is f.g., then `N` is f.p.
- `Module.FinitePresentation.fg_ker`: If `M` is f.g., `N` is f.p., then `K` is f.g.
- `Module.finitePresentation_of_ker`: If `N` and `K` is f.p., then `M` is also f.p.
- `Module.FinitePresentation.isLocalizedModule_map`: If `M` and `N` are `R`-modules and `M` is f.p.,
and `S` is a submonoid of `R`, then `Hom(Mₛ, Nₛ)` is the localization of `Hom(M, N)`.
Also the instances finite + free => f.p. => finite are also provided
## TODO
Suppose `S` is an `R`-algebra, `M` is an `S`-module. Then
1. If `S` is f.p., then `M` is `R`-f.p. implies `M` is `S`-f.p.
2. If `S` is both f.p. (as an algebra) and finite (as a module),
then `M` is `S`-fp implies that `M` is `R`-f.p.
3. If `S` is f.p. as a module, then `S` is f.p. as an algebra.
In particular,
4. `S` is f.p. as an `R`-module iff it is f.p. as an algebra and is finite as a module.
For finitely presented algebras, see `Algebra.FinitePresentation`
in file `Mathlib/RingTheory/FinitePresentation.lean`.
-/
open Finsupp
section Semiring
variable (R M) [Semiring R] [AddCommMonoid M] [Module R M]
/--
A module is finitely presented if it is finitely generated by some set `s`
and the kernel of the presentation `Rˢ → M` is also finitely generated.
-/
class Module.FinitePresentation : Prop where
out : ∃ (s : Finset M), Submodule.span R (s : Set M) = ⊤ ∧
(LinearMap.ker (Finsupp.linearCombination R ((↑) : s → M))).FG
instance (priority := 100) [h : Module.FinitePresentation R M] : Module.Finite R M := by
obtain ⟨s, hs₁, _⟩ := h
exact ⟨s, hs₁⟩
end Semiring
section Ring
section
universe u v
variable (R : Type u) (M : Type*) [Ring R] [AddCommGroup M] [Module R M]
theorem Module.FinitePresentation.exists_fin [fp : Module.FinitePresentation R M] :
∃ (n : ℕ) (K : Submodule R (Fin n → R)) (_ : M ≃ₗ[R] (Fin n → R) ⧸ K), K.FG := by
have ⟨ι, ⟨hι₁, hι₂⟩⟩ := fp
refine ⟨_, LinearMap.ker (linearCombination R Subtype.val ∘ₗ
(lcongr ι.equivFin (.refl ..) ≪≫ₗ linearEquivFunOnFinite R R _).symm.toLinearMap),
(LinearMap.quotKerEquivOfSurjective _ <| LinearMap.range_eq_top.mp ?_).symm, ?_⟩
· simpa [range_linearCombination] using hι₁
· simpa [LinearMap.ker_comp, Submodule.comap_equiv_eq_map_symm] using hι₂.map _
/-- A finitely presented module is isomorphic to the quotient of a finite free module by a finitely
generated submodule. -/
theorem Module.FinitePresentation.equiv_quotient [Module.FinitePresentation R M] [Small.{v} R] :
∃ (L : Type v) (_ : AddCommGroup L) (_ : Module R L) (K : Submodule R L)
(_ : M ≃ₗ[R] L ⧸ K), Module.Free R L ∧ Module.Finite R L ∧ K.FG :=
have ⟨_n, _K, e, fg⟩ := Module.FinitePresentation.exists_fin R M
let es := Shrink.linearEquiv
⟨_, inferInstance, inferInstance, _, e ≪≫ₗ Submodule.Quotient.equiv _ _ (es ..).symm rfl,
.of_equiv (es ..).symm, .equiv (es ..).symm, fg.map (es ..).symm.toLinearMap⟩
end
variable (R M N) [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
-- Ideally this should be an instance but it makes mathlib much slower.
lemma Module.finitePresentation_of_finite [IsNoetherianRing R] [h : Module.Finite R M] :
Module.FinitePresentation R M := by
obtain ⟨s, hs⟩ := h
exact ⟨s, hs, IsNoetherian.noetherian _⟩
lemma Module.finitePresentation_iff_finite [IsNoetherianRing R] :
Module.FinitePresentation R M ↔ Module.Finite R M :=
⟨fun _ ↦ inferInstance, fun _ ↦ finitePresentation_of_finite R M⟩
variable {R M N}
lemma Module.finitePresentation_of_free_of_surjective [Module.Free R M] [Module.Finite R M]
(l : M →ₗ[R] N)
(hl : Function.Surjective l) (hl' : (LinearMap.ker l).FG) :
Module.FinitePresentation R N := by
classical
let b := Module.Free.chooseBasis R M
let π : Free.ChooseBasisIndex R M → (Set.finite_range (l ∘ b)).toFinset :=
fun i ↦ ⟨l (b i), by simp⟩
have : π.Surjective := fun ⟨x, hx⟩ ↦ by
obtain ⟨y, rfl⟩ : ∃ a, l (b a) = x := by simpa using hx
exact ⟨y, rfl⟩
choose σ hσ using this
have hπ : Subtype.val ∘ π = l ∘ b := rfl
have hσ₁ : π ∘ σ = id := by ext i; exact congr_arg Subtype.val (hσ i)
have hσ₂ : l ∘ b ∘ σ = Subtype.val := by ext i; exact congr_arg Subtype.val (hσ i)
refine ⟨(Set.finite_range (l ∘ b)).toFinset,
by simpa [Set.range_comp, LinearMap.range_eq_top], ?_⟩
let f : M →ₗ[R] (Set.finite_range (l ∘ b)).toFinset →₀ R :=
Finsupp.lmapDomain _ _ π ∘ₗ b.repr.toLinearMap
convert hl'.map f
ext x; simp only [LinearMap.mem_ker, Submodule.mem_map]
constructor
· intro hx
refine ⟨b.repr.symm (x.mapDomain σ), ?_, ?_⟩
· simp [Finsupp.apply_linearCombination, hσ₂, hx]
· simp only [f, LinearMap.comp_apply, b.repr.apply_symm_apply,
LinearEquiv.coe_toLinearMap, Finsupp.lmapDomain_apply]
rw [← Finsupp.mapDomain_comp, hσ₁, Finsupp.mapDomain_id]
· rintro ⟨y, hy, rfl⟩
simp [f, hπ, ← Finsupp.apply_linearCombination, hy]
-- Ideally this should be an instance but it makes mathlib much slower.
variable (R M) in
lemma Module.finitePresentation_of_projective [Projective R M] [Module.Finite R M] :
FinitePresentation R M :=
have ⟨_n, _f, _g, surj, _, hfg⟩ := Finite.exists_comp_eq_id_of_projective R M
Module.finitePresentation_of_free_of_surjective _ surj
(Finite.iff_fg.mp <| LinearMap.ker_eq_range_of_comp_eq_id hfg ▸ inferInstance)
variable {ι} [Finite ι]
instance : Module.FinitePresentation R R := Module.finitePresentation_of_projective _ _
instance : Module.FinitePresentation R (ι →₀ R) := Module.finitePresentation_of_projective _ _
instance : Module.FinitePresentation R (ι → R) := Module.finitePresentation_of_projective _ _
lemma Module.finitePresentation_of_surjective [h : Module.FinitePresentation R M] (l : M →ₗ[R] N)
(hl : Function.Surjective l) (hl' : (LinearMap.ker l).FG) :
Module.FinitePresentation R N := by
classical
obtain ⟨s, hs, hs'⟩ := h
obtain ⟨t, ht⟩ := hl'
have H : Function.Surjective (Finsupp.linearCombination R ((↑) : s → M)) :=
LinearMap.range_eq_top.mp
(by rw [range_linearCombination, Subtype.range_val, ← hs]; rfl)
apply Module.finitePresentation_of_free_of_surjective (l ∘ₗ linearCombination R Subtype.val)
(hl.comp H)
choose σ hσ using (show _ from H)
have : Finsupp.linearCombination R Subtype.val '' (σ '' t) = t := by
simp only [Set.image_image, hσ, Set.image_id']
rw [LinearMap.ker_comp, ← ht, ← this, ← Submodule.map_span, Submodule.comap_map_eq,
← Finset.coe_image]
exact Submodule.FG.sup ⟨_, rfl⟩ hs'
lemma Module.FinitePresentation.fg_ker [Module.Finite R M]
[h : Module.FinitePresentation R N] (l : M →ₗ[R] N) (hl : Function.Surjective l) :
(LinearMap.ker l).FG := by
classical
obtain ⟨s, hs, hs'⟩ := h
have H : Function.Surjective (Finsupp.linearCombination R ((↑) : s → N)) :=
LinearMap.range_eq_top.mp
(by rw [range_linearCombination, Subtype.range_val, ← hs]; rfl)
obtain ⟨f, hf⟩ : ∃ f : (s →₀ R) →ₗ[R] M, l ∘ₗ f = (Finsupp.linearCombination R Subtype.val) := by
choose f hf using show _ from hl
exact ⟨Finsupp.linearCombination R (fun i ↦ f i), by ext; simp [hf]⟩
have : (LinearMap.ker l).map (LinearMap.range f).mkQ = ⊤ := by
rw [← top_le_iff]
rintro x -
obtain ⟨x, rfl⟩ := Submodule.mkQ_surjective _ x
obtain ⟨y, hy⟩ := H (l x)
rw [← hf, LinearMap.comp_apply, eq_comm, ← sub_eq_zero, ← map_sub] at hy
exact ⟨_, hy, by simp⟩
apply Submodule.fg_of_fg_map_of_fg_inf_ker (LinearMap.range f).mkQ
· rw [this]
exact Module.Finite.fg_top
· rw [Submodule.ker_mkQ, inf_comm, ← Submodule.map_comap_eq, ← LinearMap.ker_comp, hf]
exact hs'.map f
lemma Module.FinitePresentation.fg_ker_iff [Module.FinitePresentation R M]
(l : M →ₗ[R] N) (hl : Function.Surjective l) :
Submodule.FG (LinearMap.ker l) ↔ Module.FinitePresentation R N :=
⟨finitePresentation_of_surjective l hl, fun _ ↦ fg_ker l hl⟩
lemma Module.finitePresentation_of_ker [Module.FinitePresentation R N]
(l : M →ₗ[R] N) (hl : Function.Surjective l) [Module.FinitePresentation R (LinearMap.ker l)] :
Module.FinitePresentation R M := by
obtain ⟨s, hs⟩ : (⊤ : Submodule R M).FG := by
apply Submodule.fg_of_fg_map_of_fg_inf_ker l
· rw [Submodule.map_top, LinearMap.range_eq_top.mpr hl]; exact Module.Finite.fg_top
· rw [top_inf_eq, ← Submodule.fg_top]; exact Module.Finite.fg_top
refine ⟨s, hs, ?_⟩
let π := Finsupp.linearCombination R ((↑) : s → M)
have H : Function.Surjective π :=
LinearMap.range_eq_top.mp
(by rw [range_linearCombination, Subtype.range_val, ← hs]; rfl)
have inst : Module.Finite R (LinearMap.ker (l ∘ₗ π)) := by
constructor
rw [Submodule.fg_top]; exact Module.FinitePresentation.fg_ker _ (hl.comp H)
letI : AddCommGroup (LinearMap.ker (l ∘ₗ π)) := inferInstance
let f : LinearMap.ker (l ∘ₗ π) →ₗ[R] LinearMap.ker l := LinearMap.restrict π (fun x ↦ id)
have e : π ∘ₗ Submodule.subtype _ = Submodule.subtype _ ∘ₗ f := by ext; rfl
have hf : Function.Surjective f := by
rw [← LinearMap.range_eq_top]
apply Submodule.map_injective_of_injective (Submodule.injective_subtype _)
rw [Submodule.map_top, Submodule.range_subtype, ← LinearMap.range_comp, ← e,
LinearMap.range_comp, Submodule.range_subtype, LinearMap.ker_comp,
Submodule.map_comap_eq_of_surjective H]
change (LinearMap.ker π).FG
have : LinearMap.ker π ≤ LinearMap.ker (l ∘ₗ π) :=
Submodule.comap_mono (f := π) (bot_le (a := LinearMap.ker l))
rw [← inf_eq_right.mpr this, ← Submodule.range_subtype (LinearMap.ker _),
← Submodule.map_comap_eq, ← LinearMap.ker_comp, e, LinearMap.ker_comp f,
LinearMap.ker_eq_bot.mpr (Submodule.injective_subtype (LinearMap.ker l)), Submodule.comap_bot]
exact (Module.FinitePresentation.fg_ker f hf).map (Submodule.subtype _)
/-- Given a split exact sequence `0 → M → N → P → 0` with `N` finitely presented,
then `M` is also finitely presented. -/
lemma Module.finitePresentation_of_split_exact
{P : Type*} [AddCommGroup P] [Module R P]
[Module.FinitePresentation R N]
(f : M →ₗ[R] N) (g : N →ₗ[R] P) (l : P →ₗ[R] N) (hl : g ∘ₗ l = .id)
(hf : Function.Injective f) (H : Function.Exact f g) :
Module.FinitePresentation R M := by
have hg : Function.Surjective g := Function.LeftInverse.surjective (DFunLike.congr_fun hl)
have := Module.Finite.of_surjective g hg
obtain ⟨e, rfl, rfl⟩ := ((Function.Exact.split_tfae' H).out 0 2 rfl rfl).mp
⟨hf, l, hl⟩
refine Module.finitePresentation_of_surjective (LinearMap.fst _ _ _ ∘ₗ e.toLinearMap)
(Prod.fst_surjective.comp e.surjective) ?_
rw [LinearMap.ker_comp, Submodule.comap_equiv_eq_map_symm,
LinearMap.exact_iff.mp Function.Exact.inr_fst, ← Submodule.map_top]
exact .map _ (.map _ (Module.Finite.fg_top))
/-- Given an exact sequence `0 → M → N → P → 0`
with `N` finitely presented and `P` projective, then `M` is also finitely presented. -/
lemma Module.finitePresentation_of_projective_of_exact
{P : Type*} [AddCommGroup P] [Module R P]
[Module.FinitePresentation R N] [Module.Projective R P]
(f : M →ₗ[R] N) (g : N →ₗ[R] P)
(hf : Function.Injective f) (hg : Function.Surjective g) (H : Function.Exact f g) :
Module.FinitePresentation R M :=
have ⟨l, hl⟩ := Module.projective_lifting_property g .id hg
Module.finitePresentation_of_split_exact f g l hl hf H
lemma Module.FinitePresentation.of_equiv (e : M ≃ₗ[R] N) [Module.FinitePresentation R M] :
Module.FinitePresentation R N := by
simp [← Module.FinitePresentation.fg_ker_iff e.toLinearMap e.surjective, Submodule.fg_bot]
lemma LinearEquiv.finitePresentation_iff (e : M ≃ₗ[R] N) :
Module.FinitePresentation R M ↔ Module.FinitePresentation R N :=
⟨fun _ ↦ .of_equiv e, fun _ ↦ .of_equiv e.symm⟩
namespace Module.FinitePresentation
variable (M) in
instance (priority := 900) of_subsingleton [Subsingleton M] :
Module.FinitePresentation R M :=
.of_equiv (default : (Fin 0 → R) ≃ₗ[R] M)
variable (M N) in
instance prod [Module.FinitePresentation R M] [Module.FinitePresentation R N] :
Module.FinitePresentation R (M × N) := by
have hf : Function.Surjective (LinearMap.fst R M N) := LinearMap.fst_surjective
have : FinitePresentation R ↥(LinearMap.ker (LinearMap.fst R M N)) := by
rw [LinearMap.ker_fst]
exact .of_equiv (LinearEquiv.ofInjective (LinearMap.inr R M N) LinearMap.inr_injective)
apply Module.finitePresentation_of_ker (.fst R M N) hf
instance pi {ι : Type*} (M : ι → Type*)
[∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [∀ i, Module.FinitePresentation R (M i)]
[Finite ι] : Module.FinitePresentation R (∀ i, M i) := by
refine Module.pi_induction' (motive := fun N _ _ ↦ Module.FinitePresentation R N)
(motive' := fun N _ _ ↦ Module.FinitePresentation R N) R ?_ ?_ ?_ ?_ M inferInstance
· exact fun e (hN : Module.FinitePresentation _ _) ↦ .of_equiv e
· exact fun e (hN : Module.FinitePresentation _ _) ↦ .of_equiv e
· infer_instance
· introv hN hN'
infer_instance
end Module.FinitePresentation
end Ring
section CommRing
variable {R M N N'} [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
variable [AddCommGroup N'] [Module R N'] (S : Submonoid R) (f : N →ₗ[R] N') [IsLocalizedModule S f]
variable (R M) in
lemma Module.FinitePresentation.trans (S : Type*) [CommRing S] [Algebra R S]
[Module S M] [IsScalarTower R S M] [Module.FinitePresentation R S]
[Module.FinitePresentation S M] : Module.FinitePresentation R M := by
obtain ⟨n, K, e, hK⟩ := Module.FinitePresentation.exists_fin S M
let f : (Fin n → S) →ₗ[R] M := (e.symm ∘ₗ K.mkQ).restrictScalars R
refine Module.finitePresentation_of_surjective f (fun m ↦ ?_) ?_
· obtain ⟨a, ha⟩ := K.mkQ_surjective (e m)
exact ⟨a, by simp [f, ha]⟩
· have : Module.Finite S
(Submodule.restrictScalars R (LinearMap.ker (e.symm.toLinearMap ∘ₗ K.mkQ))) := by
change Module.Finite S (LinearMap.ker (e.symm.toLinearMap ∘ₗ K.mkQ))
simpa [Finite.iff_fg]
simp only [f, LinearMap.ker_restrictScalars, ← Module.Finite.iff_fg]
exact Module.Finite.trans S _
open TensorProduct in
instance {A} [CommRing A] [Algebra R A] [Module.FinitePresentation R M] :
Module.FinitePresentation A (A ⊗[R] M) := by
classical
obtain ⟨n, f, hf⟩ := Module.Finite.exists_fin' R M
have inst := Module.finitePresentation_of_projective A (A ⊗[R] (Fin n → R))
apply Module.finitePresentation_of_surjective (f.baseChange A)
(LinearMap.lTensor_surjective A hf)
have : Function.Exact ((LinearMap.ker f).subtype.baseChange A) (f.baseChange A) :=
lTensor_exact A f.exact_subtype_ker_map hf
rw [LinearMap.exact_iff] at this
rw [this, ← Submodule.map_top]
apply Submodule.FG.map
have : Module.Finite R (LinearMap.ker f) :=
⟨(Submodule.fg_top _).mpr (Module.FinitePresentation.fg_ker f hf)⟩
exact Module.Finite.fg_top (R := A) (M := A ⊗[R] LinearMap.ker f)
open TensorProduct in
lemma FinitePresentation.of_isBaseChange
{A} [CommRing A] [Algebra R A] [Module A N] [IsScalarTower R A N]
(f : M →ₗ[R] N) (h : IsBaseChange A f) [Module.FinitePresentation R M] :
Module.FinitePresentation A N :=
Module.finitePresentation_of_surjective
h.equiv.toLinearMap h.equiv.surjective (by simpa using Submodule.fg_bot)
open TensorProduct in
instance (S : Submonoid R) [Module.FinitePresentation R M] :
Module.FinitePresentation (Localization S) (LocalizedModule S M) :=
FinitePresentation.of_isBaseChange (LocalizedModule.mkLinearMap S M)
((isLocalizedModule_iff_isBaseChange S _ _).mp inferInstance)
lemma Module.FinitePresentation.exists_lift_of_isLocalizedModule
[h : Module.FinitePresentation R M] (g : M →ₗ[R] N') :
∃ (h : M →ₗ[R] N) (s : S), f ∘ₗ h = s • g := by
obtain ⟨σ, hσ, τ, hτ⟩ := h
let π := Finsupp.linearCombination R ((↑) : σ → M)
have hπ : Function.Surjective π :=
LinearMap.range_eq_top.mp
(by rw [range_linearCombination, Subtype.range_val, ← hσ]; rfl)
classical
choose s hs using IsLocalizedModule.surj S f
let i : σ → N :=
fun x ↦ (∏ j ∈ σ.erase x.1, (s (g j)).2) • (s (g x)).1
let s₀ := ∏ j ∈ σ, (s (g j)).2
have hi : f ∘ₗ Finsupp.linearCombination R i = (s₀ • g) ∘ₗ π := by
ext j
simp only [LinearMap.coe_comp, Function.comp_apply, Finsupp.lsingle_apply,
linearCombination_single, one_smul, LinearMap.map_smul_of_tower, ← hs, LinearMap.smul_apply,
i, s₀, π]
rw [← mul_smul, Finset.prod_erase_mul]
exact j.prop
have : ∀ x : τ, ∃ s : S, s • (Finsupp.linearCombination R i x) = 0 := by
intros x
convert_to ∃ s : S, s • (Finsupp.linearCombination R i x) = s • 0
· simp only [smul_zero]
apply IsLocalizedModule.exists_of_eq (S := S) (f := f)
rw [← LinearMap.comp_apply, map_zero, hi, LinearMap.comp_apply]
convert map_zero (s₀ • g)
rw [← LinearMap.mem_ker, ← hτ]
exact Submodule.subset_span x.prop
choose s' hs' using this
let s₁ := ∏ i : τ, s' i
have : LinearMap.ker π ≤ LinearMap.ker (s₁ • Finsupp.linearCombination R i) := by
rw [← hτ, Submodule.span_le]
intro x hxσ
simp only [s₁]
rw [SetLike.mem_coe, LinearMap.mem_ker, LinearMap.smul_apply,
← Finset.prod_erase_mul _ _ (Finset.mem_univ ⟨x, hxσ⟩), mul_smul]
convert smul_zero _
exact hs' ⟨x, hxσ⟩
refine ⟨Submodule.liftQ _ _ this ∘ₗ
(LinearMap.quotKerEquivOfSurjective _ hπ).symm.toLinearMap, s₁ * s₀, ?_⟩
ext x
obtain ⟨x, rfl⟩ := hπ x
rw [← LinearMap.comp_apply, ← LinearMap.comp_apply, mul_smul, LinearMap.smul_comp, ← hi,
← LinearMap.comp_smul, LinearMap.comp_assoc, LinearMap.comp_assoc]
congr 2
convert Submodule.liftQ_mkQ _ _ this using 2
ext x
apply (LinearMap.quotKerEquivOfSurjective _ hπ).injective
simp [LinearMap.quotKerEquivOfSurjective]
lemma Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule
[hM : Module.Finite R M] (g₁ g₂ : M →ₗ[R] N) (h : f.comp g₁ = f.comp g₂) :
∃ (s : S), s • g₁ = s • g₂ := by
classical
have : ∀ x, ∃ s : S, s • g₁ x = s • g₂ x := fun x ↦
IsLocalizedModule.exists_of_eq (S := S) (f := f) (LinearMap.congr_fun h x)
choose s hs using this
obtain ⟨σ, hσ⟩ := hM
use σ.prod s
rw [← sub_eq_zero, ← LinearMap.ker_eq_top, ← top_le_iff, ← hσ, Submodule.span_le]
intro x hx
simp only [SetLike.mem_coe, LinearMap.mem_ker, LinearMap.sub_apply, LinearMap.smul_apply,
sub_eq_zero, ← Finset.prod_erase_mul σ s hx, mul_smul, hs]
variable {M' : Type*} [AddCommGroup M'] [Module R M'] (f : M →ₗ[R] M') [IsLocalizedModule S f]
variable {N' : Type*} [AddCommGroup N'] [Module R N'] (g : N →ₗ[R] N') [IsLocalizedModule S g]
/--
Let `M` be a finite `R`-module, and `N` be a finitely presented `R`-module.
If `l : M →ₗ[R] N` is a linear map whose localization at `S : Submonoid R` is bijective,
then `l` is already bijective under the localization at some `r ∈ S`.
-/
lemma exists_bijective_map_powers [Module.Finite R M] [Module.FinitePresentation R N]
(l : M →ₗ[R] N) (hf : Function.Bijective (IsLocalizedModule.map S f g l)) :
∃ r, r ∈ S ∧ ∀ t, r ∣ t → Function.Bijective (LocalizedModule.map (.powers t) l) := by
let e : M' ≃ₗ[R] N' := LinearEquiv.ofBijective _ hf
obtain ⟨l', s₀, H⟩ := Module.FinitePresentation.exists_lift_of_isLocalizedModule S f
(e.symm.toLinearMap.comp g)
have H₁ : g ∘ₗ l ∘ₗ l' = g ∘ₗ (s₀ • LinearMap.id) := by
ext a; simpa [-EmbeddingLike.apply_eq_iff_eq, e] using congr(e ($H a))
obtain ⟨s₁, hs₁⟩ := Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule S g _ _ H₁
have H₂ : f ∘ₗ l' ∘ₗ l = f ∘ₗ (s₀ • LinearMap.id) := by
rw [← LinearMap.comp_assoc, H, LinearMap.smul_comp, LinearMap.comp_assoc,
← IsLocalizedModule.map_comp S f g l, ← LinearMap.comp_assoc]
change s₀ • (e.symm.toLinearMap ∘ₗ e.toLinearMap) ∘ₗ _ = _
simp [LinearMap.comp_smul]
obtain ⟨s₂, hs₂⟩ := Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule S f _ _ H₂
refine ⟨s₀ * s₁ * s₂, (s₀ * s₁ * s₂).2, fun t ht ↦ ?_⟩
let Rₛ := Localization (.powers t)
let lₛ := LocalizedModule.map (.powers t) l
have hu₀ : IsUnit (algebraMap R Rₛ s₀) := isUnit_of_dvd_unit
(hu := IsLocalization.map_units (M := .powers t) Rₛ ⟨t, Submonoid.mem_powers t⟩)
(map_dvd (algebraMap R Rₛ) (dvd_trans ⟨s₁ * s₂, by simp [mul_assoc]⟩ ht))
have hu₁ : IsUnit (algebraMap R Rₛ s₁) := isUnit_of_dvd_unit
(hu := IsLocalization.map_units (M := .powers t) Rₛ ⟨t, Submonoid.mem_powers t⟩)
(map_dvd (algebraMap R Rₛ) (dvd_trans ⟨s₀ * s₂, by ring⟩ ht))
have hu₂ : IsUnit (algebraMap R Rₛ s₂) := isUnit_of_dvd_unit
(hu := IsLocalization.map_units (M := .powers t) Rₛ ⟨t, Submonoid.mem_powers t⟩)
(map_dvd (algebraMap R Rₛ) (dvd_trans ⟨s₀ * s₁, by ring⟩ ht))
let lₛ' := LocalizedModule.map (.powers t) l'
have H_left : ((hu₀.unit⁻¹).1 • lₛ') ∘ₗ lₛ = LinearMap.id := by
apply ((Module.End.isUnit_iff _).mp (hu₂.map (algebraMap Rₛ (Module.End Rₛ _)))).1
apply ((Module.End.isUnit_iff _).mp (hu₀.map (algebraMap Rₛ (Module.End Rₛ _)))).1
simp only [Module.algebraMap_end_apply, algebraMap_smul, LinearMap.map_smul_of_tower]
rw [LinearMap.smul_comp, ← smul_assoc s₀.1, Algebra.smul_def s₀.1, IsUnit.mul_val_inv, one_smul]
apply LinearMap.restrictScalars_injective R
apply IsLocalizedModule.ext (.powers t) (LocalizedModule.mkLinearMap (.powers t) M)
(IsLocalizedModule.map_units (LocalizedModule.mkLinearMap (.powers t) M))
ext x
have : s₂.1 • l' (l x) = s₂.1 • s₀.1 • x := congr($hs₂ x)
simp [lₛ, lₛ', LocalizedModule.smul'_mk, this]
have H_right : lₛ ∘ₗ ((hu₀.unit⁻¹).1 • lₛ') = LinearMap.id := by
apply ((Module.End.isUnit_iff _).mp (hu₁.map (algebraMap Rₛ (Module.End Rₛ _)))).1
apply ((Module.End.isUnit_iff _).mp (hu₀.map (algebraMap Rₛ (Module.End Rₛ _)))).1
simp only [Module.algebraMap_end_apply, algebraMap_smul, LinearMap.map_smul_of_tower]
rw [LinearMap.comp_smul, ← smul_assoc s₀.1, Algebra.smul_def s₀.1, IsUnit.mul_val_inv, one_smul]
apply LinearMap.restrictScalars_injective R
apply IsLocalizedModule.ext (.powers t) (LocalizedModule.mkLinearMap (.powers t) N)
(IsLocalizedModule.map_units (LocalizedModule.mkLinearMap (.powers t) N))
ext x
have : s₁.1 • l (l' x) = s₁.1 • s₀.1 • x := congr($hs₁ x)
simp [lₛ, lₛ', LocalizedModule.smul'_mk, this]
let eₛ : LocalizedModule (.powers t) M ≃ₗ[Rₛ] LocalizedModule (.powers t) N :=
{ __ := lₛ,
invFun := ((hu₀.unit⁻¹).1 • lₛ'),
left_inv := fun x ↦ congr($H_left x),
right_inv := fun x ↦ congr($H_right x) }
exact eₛ.bijective
open IsLocalizedModule in
/--
Let `M` `N` be a finitely presented `R`-modules.
Any `Mₛ ≃ₗ[R] Nₛ` between the localizations at `S : Submonoid R` can be lifted to an
isomorphism between `Mᵣ ≃ₗ[R] Nᵣ` for some `r ∈ S`.
-/
lemma Module.FinitePresentation.exists_lift_equiv_of_isLocalizedModule
[Module.FinitePresentation R M] [Module.FinitePresentation R N]
(l : M' ≃ₗ[R] N') :
∃ (r : R) (hr : r ∈ S)
(l' : LocalizedModule (.powers r) M ≃ₗ[Localization (.powers r)]
LocalizedModule (.powers r) N),
(LocalizedModule.lift (.powers r) g fun s ↦ map_units g ⟨s.1, SetLike.le_def.mp
(Submonoid.powers_le.mpr hr) s.2⟩) ∘ₗ l'.toLinearMap =
l ∘ₗ (LocalizedModule.lift (.powers r) f fun s ↦ map_units f ⟨s.1, SetLike.le_def.mp
(Submonoid.powers_le.mpr hr) s.2⟩) := by
obtain ⟨l', s, H⟩ := Module.FinitePresentation.exists_lift_of_isLocalizedModule S g (l ∘ₗ f)
have : Function.Bijective (IsLocalizedModule.map S f g l') := by
have : IsLocalizedModule.map S f g l' = (s • LinearMap.id) ∘ₗ l := by
apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g)
apply LinearMap.ext fun x ↦ ?_
simp only [LinearMap.coe_comp, Function.comp_apply, IsLocalizedModule.map_apply]
rw [← LinearMap.comp_apply, H]
simp
rw [this]
exact ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units g s)).comp l.bijective
obtain ⟨r, hr, hr'⟩ := exists_bijective_map_powers S f g _ this
let rs : Submonoid R := (.powers <| r * s)
let Rᵣₛ := Localization rs
have hsu : IsUnit (algebraMap R Rᵣₛ s) := isUnit_of_dvd_unit
(hu := IsLocalization.map_units (M := rs) Rᵣₛ ⟨_, Submonoid.mem_powers _⟩)
(map_dvd (algebraMap R Rᵣₛ) ⟨r, mul_comm _ _⟩)
have : Function.Bijective ((hsu.unit⁻¹).1 • LocalizedModule.map rs l') :=
((Module.End.isUnit_iff _).mp ((hsu.unit⁻¹).isUnit.map (algebraMap _ (End Rᵣₛ
(LocalizedModule rs N))))).comp (hr' (r * s) (dvd_mul_right _ _))
refine ⟨r * s, mul_mem hr s.2, LinearEquiv.ofBijective _ this, ?_⟩
apply IsLocalizedModule.ext rs (LocalizedModule.mkLinearMap rs M) fun x ↦ map_units g
⟨x.1, SetLike.le_def.mp (Submonoid.powers_le.mpr (mul_mem hr s.2)) x.2⟩
ext x
apply ((Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units g s)).1
have : ∀ x, g (l' x) = s.1 • (l (f x)) := LinearMap.congr_fun H
simp only [rs, LinearMap.coe_comp, LinearMap.coe_restrictScalars, LinearEquiv.coe_coe,
Function.comp_apply, LocalizedModule.mkLinearMap_apply, LinearEquiv.ofBijective_apply,
LinearMap.smul_apply, LocalizedModule.map_mk, algebraMap_end_apply]
rw [← map_smul, ← smul_assoc, Algebra.smul_def s.1, hsu.mul_val_inv, one_smul]
simp only [LocalizedModule.lift_mk, OneMemClass.coe_one, map_one, IsUnit.unit_one,
inv_one, Units.val_one, Module.End.one_apply, this]
instance Module.FinitePresentation.isLocalizedModule_map [Module.FinitePresentation R M] :
IsLocalizedModule S (IsLocalizedModule.map S f g) := by
constructor
· intro s
rw [Module.End.isUnit_iff]
have := (Module.End.isUnit_iff _).mp (IsLocalizedModule.map_units (S := S) (f := g) s)
constructor
· exact fun _ _ e ↦ LinearMap.ext fun m ↦ this.left (LinearMap.congr_fun e m)
· intro h
use ((IsLocalizedModule.map_units (S := S) (f := g) s).unit⁻¹).1 ∘ₗ h
ext x
exact Module.End.isUnit_apply_inv_apply_of_isUnit
(IsLocalizedModule.map_units (S := S) (f := g) s) (h x)
· intro h
obtain ⟨h', s, e⟩ := Module.FinitePresentation.exists_lift_of_isLocalizedModule S g (h ∘ₗ f)
refine ⟨⟨h', s⟩, ?_⟩
apply IsLocalizedModule.ext S f (IsLocalizedModule.map_units g)
refine e.symm.trans (by ext; simp)
· intro h₁ h₂ e
apply Module.Finite.exists_smul_of_comp_eq_of_isLocalizedModule S g
ext x
simpa using LinearMap.congr_fun e (f x)
instance Module.FinitePresentation.isLocalizedModule_mapExtendScalars
(Rₛ) [CommRing Rₛ] [Algebra R Rₛ] [Module Rₛ M'] [Module Rₛ N']
[IsScalarTower R Rₛ M'] [IsScalarTower R Rₛ N'] [IsLocalization S Rₛ]
[Module.FinitePresentation R M] :
IsLocalizedModule S (IsLocalizedModule.mapExtendScalars S f g Rₛ) :=
IsLocalizedModule.of_linearEquiv _ _ _
instance [Module.FinitePresentation R M] :
IsLocalizedModule S (LocalizedModule.map S (M := M) (N := N)) :=
Module.FinitePresentation.isLocalizedModule_mapExtendScalars _ _ _ _
/--
Let `M` be a finitely presented `R`-module, `N` a `R`-module, `S : Submonoid R`.
The linear equivalence between the `M →ₗ[R] N` localized at `S` and
`LocalizedModule S M →ₗ[R] LocalizedModule S N`
-/
noncomputable def Module.FinitePresentation.linearEquivMap [Module.FinitePresentation R M] :=
IsLocalizedModule.linearEquiv S (LocalizedModule.mkLinearMap S (M →ₗ[R] N))
(IsLocalizedModule.map S (LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N))
lemma Module.FinitePresentation.linearEquivMap_apply [Module.FinitePresentation R M]
(f : M →ₗ[R] N) : Module.FinitePresentation.linearEquivMap S
((LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f) = (IsLocalizedModule.map S
(LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N)) f :=
IsLocalizedModule.linearEquiv_apply S _ _ f
@[simp]
lemma Module.FinitePresentation.linearEquivMap_symm_apply [Module.FinitePresentation R M]
(f : M →ₗ[R] N) : (Module.FinitePresentation.linearEquivMap S).symm ((IsLocalizedModule.map S
(LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N)) f) =
(LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f :=
IsLocalizedModule.linearEquiv_symm_apply S _ _ f
/--
Let `M` be a finitely presented `R`-module, `N` a `R`-module, `S : Submonoid R`.
The linear equivalence between the `M →ₗ[R] N` localized at `S` and
`LocalizedModule S M →ₗ[Localization S] LocalizedModule S N`
-/
noncomputable def Module.FinitePresentation.linearEquivMapExtendScalars
[Module.FinitePresentation R M] :=
IsLocalizedModule.linearEquiv S (LocalizedModule.mkLinearMap S (M →ₗ[R] N))
(IsLocalizedModule.mapExtendScalars S (LocalizedModule.mkLinearMap S M)
(LocalizedModule.mkLinearMap S N) (Localization S))
lemma Module.FinitePresentation.linearEquivMapExtendScalars_apply [Module.FinitePresentation R M]
(f : M →ₗ[R] N) : Module.FinitePresentation.linearEquivMapExtendScalars S
((LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f) = (IsLocalizedModule.mapExtendScalars S
(LocalizedModule.mkLinearMap S M) (LocalizedModule.mkLinearMap S N) (Localization S)) f :=
IsLocalizedModule.linearEquiv_apply S _ _ f
@[simp]
lemma Module.FinitePresentation.linearEquivMapExtendScalars_symm_apply
[Module.FinitePresentation R M] (f : M →ₗ[R] N) :
(Module.FinitePresentation.linearEquivMapExtendScalars S).symm
((IsLocalizedModule.mapExtendScalars S (LocalizedModule.mkLinearMap S M)
(LocalizedModule.mkLinearMap S N) (Localization S)) f) =
(LocalizedModule.mkLinearMap S (M →ₗ[R] N)) f :=
IsLocalizedModule.linearEquiv_symm_apply S _ _ f
end CommRing
|
Pseudofunctor.lean
|
/-
Copyright (c) 2022 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno, Calle Sönne
-/
import Mathlib.CategoryTheory.Bicategory.Functor.Oplax
import Mathlib.CategoryTheory.Bicategory.Functor.Lax
import Mathlib.Tactic.CategoryTheory.ToApp
/-!
# Pseudofunctors
A pseudofunctor is an oplax (or lax) functor whose `mapId` and `mapComp` are isomorphisms.
We provide several constructors for pseudofunctors:
* `Pseudofunctor.mk` : the default constructor, which requires `map₂_whiskerLeft` and
`map₂_whiskerRight` instead of naturality of `mapComp`.
* `Pseudofunctor.mkOfOplax` : construct a pseudofunctor from an oplax functor whose
`mapId` and `mapComp` are isomorphisms. This constructor uses `Iso` to describe isomorphisms.
* `pseudofunctor.mkOfOplax'` : similar to `mkOfOplax`, but uses `IsIso` to describe isomorphisms.
* `Pseudofunctor.mkOfLax` : construct a pseudofunctor from a lax functor whose
`mapId` and `mapComp` are isomorphisms. This constructor uses `Iso` to describe isomorphisms.
* `pseudofunctor.mkOfLax'` : similar to `mkOfLax`, but uses `IsIso` to describe isomorphisms.
## Main definitions
* `CategoryTheory.Pseudofunctor B C` : a pseudofunctor between bicategories `B` and `C`
* `CategoryTheory.Pseudofunctor.comp F G` : the composition of pseudofunctors
-/
namespace CategoryTheory
open Category Bicategory
open Bicategory
universe w₁ w₂ w₃ v₁ v₂ v₃ u₁ u₂ u₃
variable {B : Type u₁} [Bicategory.{w₁, v₁} B] {C : Type u₂} [Bicategory.{w₂, v₂} C]
variable {D : Type u₃} [Bicategory.{w₃, v₃} D]
/-- A pseudofunctor `F` between bicategories `B` and `C` consists of a function between objects
`F.obj`, a function between 1-morphisms `F.map`, and a function between 2-morphisms `F.map₂`.
Unlike functors between categories, `F.map` do not need to strictly commute with the compositions,
and do not need to strictly preserve the identity. Instead, there are specified 2-isomorphisms
`F.map (𝟙 a) ≅ 𝟙 (F.obj a)` and `F.map (f ≫ g) ≅ F.map f ≫ F.map g`.
`F.map₂` strictly commute with compositions and preserve the identity. They also preserve the
associator, the left unitor, and the right unitor modulo some adjustments of domains and codomains
of 2-morphisms.
-/
structure Pseudofunctor (B : Type u₁) [Bicategory.{w₁, v₁} B] (C : Type u₂)
[Bicategory.{w₂, v₂} C] extends PrelaxFunctor B C where
mapId (a : B) : map (𝟙 a) ≅ 𝟙 (obj a)
mapComp {a b c : B} (f : a ⟶ b) (g : b ⟶ c) : map (f ≫ g) ≅ map f ≫ map g
map₂_whisker_left :
∀ {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h),
map₂ (f ◁ η) = (mapComp f g).hom ≫ map f ◁ map₂ η ≫ (mapComp f h).inv := by
cat_disch
map₂_whisker_right :
∀ {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c),
map₂ (η ▷ h) = (mapComp f h).hom ≫ map₂ η ▷ map h ≫ (mapComp g h).inv := by
cat_disch
map₂_associator :
∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d),
map₂ (α_ f g h).hom = (mapComp (f ≫ g) h).hom ≫ (mapComp f g).hom ▷ map h ≫
(α_ (map f) (map g) (map h)).hom ≫ map f ◁ (mapComp g h).inv ≫
(mapComp f (g ≫ h)).inv := by
cat_disch
map₂_left_unitor :
∀ {a b : B} (f : a ⟶ b),
map₂ (λ_ f).hom = (mapComp (𝟙 a) f).hom ≫ (mapId a).hom ▷ map f ≫ (λ_ (map f)).hom := by
cat_disch
map₂_right_unitor :
∀ {a b : B} (f : a ⟶ b),
map₂ (ρ_ f).hom = (mapComp f (𝟙 b)).hom ≫ map f ◁ (mapId b).hom ≫ (ρ_ (map f)).hom := by
cat_disch
initialize_simps_projections Pseudofunctor (+toPrelaxFunctor, -obj, -map, -map₂)
namespace Pseudofunctor
attribute [simp, reassoc, to_app]
map₂_whisker_left map₂_whisker_right map₂_associator map₂_left_unitor map₂_right_unitor
section
open Iso
/-- The underlying prelax functor. -/
add_decl_doc Pseudofunctor.toPrelaxFunctor
attribute [nolint docBlame] CategoryTheory.Pseudofunctor.mapId
CategoryTheory.Pseudofunctor.mapComp
CategoryTheory.Pseudofunctor.map₂_whisker_left
CategoryTheory.Pseudofunctor.map₂_whisker_right
CategoryTheory.Pseudofunctor.map₂_associator
CategoryTheory.Pseudofunctor.map₂_left_unitor
CategoryTheory.Pseudofunctor.map₂_right_unitor
variable (F : Pseudofunctor B C)
/-- The oplax functor associated with a pseudofunctor. -/
@[simps]
def toOplax : OplaxFunctor B C where
toPrelaxFunctor := F.toPrelaxFunctor
mapId := fun a => (F.mapId a).hom
mapComp := fun f g => (F.mapComp f g).hom
instance hasCoeToOplax : Coe (Pseudofunctor B C) (OplaxFunctor B C) :=
⟨toOplax⟩
/-- The Lax functor associated with a pseudofunctor. -/
@[simps]
def toLax : LaxFunctor B C where
toPrelaxFunctor := F.toPrelaxFunctor
mapId := fun a => (F.mapId a).inv
mapComp := fun f g => (F.mapComp f g).inv
map₂_leftUnitor f := by
rw [← F.map₂Iso_inv, eq_inv_comp, comp_inv_eq]
simp
map₂_rightUnitor f := by
rw [← F.map₂Iso_inv, eq_inv_comp, comp_inv_eq]
simp
instance hasCoeToLax : Coe (Pseudofunctor B C) (LaxFunctor B C) :=
⟨toLax⟩
/-- The identity pseudofunctor. -/
@[simps]
def id (B : Type u₁) [Bicategory.{w₁, v₁} B] : Pseudofunctor B B where
toPrelaxFunctor := PrelaxFunctor.id B
mapId := fun a => Iso.refl (𝟙 a)
mapComp := fun f g => Iso.refl (f ≫ g)
instance : Inhabited (Pseudofunctor B B) :=
⟨id B⟩
/-- Composition of pseudofunctors. -/
@[simps]
def comp (F : Pseudofunctor B C) (G : Pseudofunctor C D) : Pseudofunctor B D where
toPrelaxFunctor := F.toPrelaxFunctor.comp G.toPrelaxFunctor
mapId := fun a => G.map₂Iso (F.mapId a) ≪≫ G.mapId (F.obj a)
mapComp := fun f g => (G.map₂Iso (F.mapComp f g)) ≪≫ G.mapComp (F.map f) (F.map g)
-- Note: whilst these are all provable by `cat_disch`, the proof is very slow
map₂_whisker_left f η := by simp
map₂_whisker_right η h := by simp
map₂_associator f g h := by simp
map₂_left_unitor f := by simp
map₂_right_unitor f := by simp
section
variable (F : Pseudofunctor B C) {a b : B}
@[reassoc, to_app]
lemma mapComp_assoc_right_hom {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
(F.mapComp f (g ≫ h)).hom ≫ F.map f ◁ (F.mapComp g h).hom = F.map₂ (α_ f g h).inv ≫
(F.mapComp (f ≫ g) h).hom ≫ (F.mapComp f g).hom ▷ F.map h ≫
(α_ (F.map f) (F.map g) (F.map h)).hom :=
F.toOplax.mapComp_assoc_right _ _ _
@[reassoc, to_app]
lemma mapComp_assoc_left_hom {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
(F.mapComp (f ≫ g) h).hom ≫ (F.mapComp f g).hom ▷ F.map h =
F.map₂ (α_ f g h).hom ≫ (F.mapComp f (g ≫ h)).hom ≫ F.map f ◁ (F.mapComp g h).hom
≫ (α_ (F.map f) (F.map g) (F.map h)).inv :=
F.toOplax.mapComp_assoc_left _ _ _
@[reassoc, to_app]
lemma mapComp_assoc_right_inv {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
F.map f ◁ (F.mapComp g h).inv ≫ (F.mapComp f (g ≫ h)).inv =
(α_ (F.map f) (F.map g) (F.map h)).inv ≫ (F.mapComp f g).inv ▷ F.map h ≫
(F.mapComp (f ≫ g) h).inv ≫ F.map₂ (α_ f g h).hom :=
F.toLax.mapComp_assoc_right _ _ _
@[reassoc, to_app]
lemma mapComp_assoc_left_inv {c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
(F.mapComp f g).inv ▷ F.map h ≫ (F.mapComp (f ≫ g) h).inv =
(α_ (F.map f) (F.map g) (F.map h)).hom ≫ F.map f ◁ (F.mapComp g h).inv ≫
(F.mapComp f (g ≫ h)).inv ≫ F.map₂ (α_ f g h).inv :=
F.toLax.mapComp_assoc_left _ _ _
@[reassoc, to_app]
lemma mapComp_id_left_hom (f : a ⟶ b) : (F.mapComp (𝟙 a) f).hom =
F.map₂ (λ_ f).hom ≫ (λ_ (F.map f)).inv ≫ (F.mapId a).inv ▷ F.map f := by
simp
lemma mapComp_id_left (f : a ⟶ b) : (F.mapComp (𝟙 a) f) = F.map₂Iso (λ_ f) ≪≫
(λ_ (F.map f)).symm ≪≫ (whiskerRightIso (F.mapId a) (F.map f)).symm :=
Iso.ext <| F.mapComp_id_left_hom f
@[reassoc, to_app]
lemma mapComp_id_left_inv (f : a ⟶ b) : (F.mapComp (𝟙 a) f).inv =
(F.mapId a).hom ▷ F.map f ≫ (λ_ (F.map f)).hom ≫ F.map₂ (λ_ f).inv := by
simp [mapComp_id_left]
lemma whiskerRightIso_mapId (f : a ⟶ b) : whiskerRightIso (F.mapId a) (F.map f) =
(F.mapComp (𝟙 a) f).symm ≪≫ F.map₂Iso (λ_ f) ≪≫ (λ_ (F.map f)).symm := by
simp [mapComp_id_left]
@[reassoc, to_app]
lemma whiskerRight_mapId_hom (f : a ⟶ b) : (F.mapId a).hom ▷ F.map f =
(F.mapComp (𝟙 a) f).inv ≫ F.map₂ (λ_ f).hom ≫ (λ_ (F.map f)).inv := by
simp
@[reassoc, to_app]
lemma whiskerRight_mapId_inv (f : a ⟶ b) : (F.mapId a).inv ▷ F.map f =
(λ_ (F.map f)).hom ≫ F.map₂ (λ_ f).inv ≫ (F.mapComp (𝟙 a) f).hom := by
simpa using congrArg (·.inv) (F.whiskerRightIso_mapId f)
@[reassoc, to_app]
lemma mapComp_id_right_hom (f : a ⟶ b) : (F.mapComp f (𝟙 b)).hom =
F.map₂ (ρ_ f).hom ≫ (ρ_ (F.map f)).inv ≫ F.map f ◁ (F.mapId b).inv := by
simp
lemma mapComp_id_right (f : a ⟶ b) : (F.mapComp f (𝟙 b)) = F.map₂Iso (ρ_ f) ≪≫
(ρ_ (F.map f)).symm ≪≫ (whiskerLeftIso (F.map f) (F.mapId b)).symm :=
Iso.ext <| F.mapComp_id_right_hom f
@[reassoc, to_app]
lemma mapComp_id_right_inv (f : a ⟶ b) : (F.mapComp f (𝟙 b)).inv =
F.map f ◁ (F.mapId b).hom ≫ (ρ_ (F.map f)).hom ≫ F.map₂ (ρ_ f).inv := by
simp [mapComp_id_right]
lemma whiskerLeftIso_mapId (f : a ⟶ b) : whiskerLeftIso (F.map f) (F.mapId b) =
(F.mapComp f (𝟙 b)).symm ≪≫ F.map₂Iso (ρ_ f) ≪≫ (ρ_ (F.map f)).symm := by
simp [mapComp_id_right]
@[reassoc, to_app]
lemma whiskerLeft_mapId_hom (f : a ⟶ b) : F.map f ◁ (F.mapId b).hom =
(F.mapComp f (𝟙 b)).inv ≫ F.map₂ (ρ_ f).hom ≫ (ρ_ (F.map f)).inv := by
simp
@[reassoc, to_app]
lemma whiskerLeft_mapId_inv (f : a ⟶ b) : F.map f ◁ (F.mapId b).inv =
(ρ_ (F.map f)).hom ≫ F.map₂ (ρ_ f).inv ≫ (F.mapComp f (𝟙 b)).hom := by
simpa using congrArg (·.inv) (F.whiskerLeftIso_mapId f)
/-- More flexible variant of `mapId`. (See the file `Bicategory.Functor.Strict`
for applications to strict bicategories.) -/
def mapId' {b : B} (f : b ⟶ b) (hf : f = 𝟙 b := by cat_disch) :
F.map f ≅ 𝟙 (F.obj b) :=
F.map₂Iso (eqToIso (by rw [hf])) ≪≫ F.mapId _
lemma mapId'_eq_mapId (b : B) :
F.mapId' (𝟙 b) rfl = F.mapId b := by
simp [mapId']
/-- More flexible variant of `mapComp`. (See `Bicategory.Functor.Strict`
for applications to strict bicategories.) -/
def mapComp' {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) (fg : b₀ ⟶ b₂)
(h : f ≫ g = fg := by cat_disch) :
F.map fg ≅ F.map f ≫ F.map g :=
F.map₂Iso (eqToIso (by rw [h])) ≪≫ F.mapComp f g
lemma mapComp'_eq_mapComp {b₀ b₁ b₂ : B} (f : b₀ ⟶ b₁) (g : b₁ ⟶ b₂) :
F.mapComp' f g _ rfl = F.mapComp f g := by
simp [mapComp']
end
/-- Construct a pseudofunctor from an oplax functor whose `mapId` and `mapComp` are isomorphisms. -/
@[simps]
def mkOfOplax (F : OplaxFunctor B C) (F' : F.PseudoCore) : Pseudofunctor B C where
toPrelaxFunctor := F.toPrelaxFunctor
mapId := F'.mapIdIso
mapComp := F'.mapCompIso
map₂_whisker_left := fun f g h η => by
rw [F'.mapCompIso_hom f g, ← F.mapComp_naturality_right_assoc, ← F'.mapCompIso_hom f h,
hom_inv_id, comp_id]
map₂_whisker_right := fun η h => by
rw [F'.mapCompIso_hom _ h, ← F.mapComp_naturality_left_assoc, ← F'.mapCompIso_hom _ h,
hom_inv_id, comp_id]
map₂_associator := fun f g h => by
rw [F'.mapCompIso_hom (f ≫ g) h, F'.mapCompIso_hom f g, ← F.map₂_associator_assoc, ←
F'.mapCompIso_hom f (g ≫ h), ← F'.mapCompIso_hom g h, whiskerLeft_hom_inv_assoc,
hom_inv_id, comp_id]
/-- Construct a pseudofunctor from an oplax functor whose `mapId` and `mapComp` are isomorphisms. -/
@[simps!]
noncomputable def mkOfOplax' (F : OplaxFunctor B C) [∀ a, IsIso (F.mapId a)]
[∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), IsIso (F.mapComp f g)] : Pseudofunctor B C where
toPrelaxFunctor := F.toPrelaxFunctor
mapId := fun a => asIso (F.mapId a)
mapComp := fun f g => asIso (F.mapComp f g)
map₂_whisker_left := fun f g h η => by
dsimp
rw [← assoc, IsIso.eq_comp_inv, F.mapComp_naturality_right]
map₂_whisker_right := fun η h => by
dsimp
rw [← assoc, IsIso.eq_comp_inv, F.mapComp_naturality_left]
map₂_associator := fun f g h => by
dsimp
simp only [← assoc]
rw [IsIso.eq_comp_inv, ← Bicategory.inv_whiskerLeft, IsIso.eq_comp_inv]
simp only [assoc, F.map₂_associator]
/-- Construct a pseudofunctor from a lax functor whose `mapId` and `mapComp` are isomorphisms. -/
@[simps]
def mkOfLax (F : LaxFunctor B C) (F' : F.PseudoCore) : Pseudofunctor B C where
toPrelaxFunctor := F.toPrelaxFunctor
mapId := F'.mapIdIso
mapComp := F'.mapCompIso
map₂_whisker_left f g h η := by
rw [F'.mapCompIso_inv, ← LaxFunctor.mapComp_naturality_right, ← F'.mapCompIso_inv,
hom_inv_id_assoc]
map₂_whisker_right η h := by
rw [F'.mapCompIso_inv, ← LaxFunctor.mapComp_naturality_left, ← F'.mapCompIso_inv,
hom_inv_id_assoc]
map₂_associator {a b c d} f g h := by
rw [F'.mapCompIso_inv, F'.mapCompIso_inv, ← inv_comp_eq, ← IsIso.inv_comp_eq]
simp
map₂_left_unitor {a b} f := by rw [← IsIso.inv_eq_inv, ← F.map₂_inv]; simp
map₂_right_unitor {a b} f := by rw [← IsIso.inv_eq_inv, ← F.map₂_inv]; simp
/-- Construct a pseudofunctor from a lax functor whose `mapId` and `mapComp` are isomorphisms. -/
@[simps!]
noncomputable def mkOfLax' (F : LaxFunctor B C) [∀ a, IsIso (F.mapId a)]
[∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), IsIso (F.mapComp f g)] : Pseudofunctor B C :=
mkOfLax F
{ mapIdIso := fun a => (asIso (F.mapId a)).symm
mapCompIso := fun f g => (asIso (F.mapComp f g)).symm }
end
end Pseudofunctor
end CategoryTheory
|
UniformConvergence.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.Topology.UniformSpace.Cauchy
/-!
# Uniform convergence
A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a
function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality
`dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit,
most notably continuity. We prove this in the file, defining the notion of uniform convergence
in the more general setting of uniform spaces, and with respect to an arbitrary indexing set
endowed with a filter (instead of just `ℕ` with `atTop`).
## Main results
Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β`
(where the index `n` belongs to an indexing type `ι` endowed with a filter `p`).
* `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means
that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has
`(f y, Fₙ y) ∈ u` for all `y ∈ s`.
* `TendstoUniformly F f p`: same notion with `s = univ`.
* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous
on this set is itself continuous on this set.
* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.
* `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends
to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`.
* `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then
`Fₙ gₙ` tends to `f x`.
Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform
convergence what a Cauchy sequence is to the usual notion of convergence.
## Implementation notes
We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.
This definition in and of itself can sometimes be useful, e.g., when studying the local behavior
of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`.
Still, while this may be the "correct" definition (see
`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in
practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.
## Tags
Uniform limit, uniform convergence, tends uniformly to
-/
noncomputable section
open Topology Uniformity Filter Set Uniform
variable {α β γ ι : Type*} [UniformSpace β]
variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α}
/-!
### Different notions of uniform convergence
We define uniform convergence, on a set or in the whole space.
-/
/-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f`
with respect to the filter `p` if, for any entourage of the diagonal `u`, one has
`p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/
def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u
/--
A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.
-/
theorem tendstoUniformlyOnFilter_iff_tendsto :
TendstoUniformlyOnFilter F f p p' ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) :=
Iff.rfl
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with
respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/
def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u
theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :
TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by
simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]
apply forall₂_congr
simp_rw [eventually_prod_principal_iff]
simp
alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.
-/
theorem tendstoUniformlyOn_iff_tendsto :
TendstoUniformlyOn F f p s ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by
simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a
filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x`. -/
def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u
theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by
simp [TendstoUniformlyOn, TendstoUniformly]
theorem tendstoUniformly_iff_tendstoUniformlyOnFilter :
TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by
rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]
theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :
TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter]
theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :
TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p :=
forall₂_congr fun u _ => by simp
lemma tendstoUniformlyOn_iff_restrict {K : Set α} : TendstoUniformlyOn F f p K ↔
TendstoUniformly (fun n : ι => K.restrict (F n)) (K.restrict f) p :=
tendstoUniformlyOn_iff_tendstoUniformly_comp_coe
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit.
-/
theorem tendstoUniformly_iff_tendsto :
TendstoUniformly F f p ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ ⊤) (𝓤 β) := by
simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p')
(hx : 𝓟 {x} ≤ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by
refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_
filter_upwards [(h u hu).curry]
intro i h
simpa using h.filter_mono hx
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) (hx : x ∈ s) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at
(le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx)
/-- Uniform convergence implies pointwise convergence. -/
theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : α) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at le_top
theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ι} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu =>
(h u hu).filter_mono (p'.prod_mono_left hp)
theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter α} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu =>
(h u hu).filter_mono (p.prod_mono_right hp)
theorem TendstoUniformlyOn.mono (h : TendstoUniformlyOn F f p s) (h' : s' ⊆ s) :
TendstoUniformlyOn F f p s' :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h'))
theorem TendstoUniformlyOnFilter.congr {F' : ι → α → β} (hf : TendstoUniformlyOnFilter F f p p')
(hff' : ∀ᶠ n : ι × α in p ×ˢ p', F n.fst n.snd = F' n.fst n.snd) :
TendstoUniformlyOnFilter F' f p p' := by
refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_
rw [← h.right]
exact h.left
theorem TendstoUniformlyOn.congr {F' : ι → α → β} (hf : TendstoUniformlyOn F f p s)
(hff' : ∀ᶠ n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf ⊢
refine hf.congr ?_
rw [eventually_iff] at hff' ⊢
simp only [Set.EqOn] at hff'
simp only [mem_prod_principal, hff', mem_setOf_eq]
lemma tendstoUniformly_congr {F' : ι → α → β} (hF : F =ᶠ[p] F') :
TendstoUniformly F f p ↔ TendstoUniformly F' f p := by
simp_rw [← tendstoUniformlyOn_univ] at *
have HF := EventuallyEq.exists_mem hF
exact ⟨fun h => h.congr (by aesop), fun h => h.congr (by simp_rw [eqOn_comm]; aesop)⟩
theorem TendstoUniformlyOn.congr_right {g : α → β} (hf : TendstoUniformlyOn F f p s)
(hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by
filter_upwards [hf u hu] with i hi a ha using hfg ha ▸ hi a ha
protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) :
TendstoUniformlyOn F f p s :=
(tendstoUniformlyOn_univ.2 h).mono (subset_univ s)
/-- Composing on the right by a function preserves uniform convergence on a filter -/
theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : γ → α) :
TendstoUniformlyOnFilter (fun n => F n ∘ g) (f ∘ g) p (p'.comap g) := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h ⊢
exact h.comp (tendsto_id.prodMap tendsto_comap)
/-- Composing on the right by a function preserves uniform convergence on a set -/
theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : γ → α) :
TendstoUniformlyOn (fun n => F n ∘ g) (f ∘ g) p (g ⁻¹' s) := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g
/-- Composing on the right by a function preserves uniform convergence -/
theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : γ → α) :
TendstoUniformly (fun n => F n ∘ g) (f ∘ g) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [principal_univ, comap_principal] using h.comp g
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a filter -/
theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') :
TendstoUniformlyOnFilter (fun i => g ∘ F i) (g ∘ f) p p' := fun _u hu => h _ (hg hu)
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a set -/
theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) :
TendstoUniformlyOn (fun i => g ∘ F i) (g ∘ f) p s := fun _u hu => h _ (hg hu)
/-- Composing on the left by a uniformly continuous function preserves uniform convergence -/
theorem UniformContinuous.comp_tendstoUniformly [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformly F f p) :
TendstoUniformly (fun i => g ∘ F i) (g ∘ f) p := fun _u hu => h _ (hg hu)
theorem TendstoUniformlyOnFilter.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {q : Filter ι'} {q' : Filter α'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q q') :
TendstoUniformlyOnFilter (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ q)
(p' ×ˢ q') := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' ⊢
rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, ← map_swap4_prod, tendsto_map'_iff]
simpa using h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOnFilter.prod_map := TendstoUniformlyOnFilter.prodMap
theorem TendstoUniformlyOn.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} {s' : Set α'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s') :
TendstoUniformlyOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p')
(s ×ˢ s') := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' ⊢
simpa only [prod_principal_principal] using h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOn.prod_map := TendstoUniformlyOn.prodMap
theorem TendstoUniformly.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') := by
rw [← tendstoUniformlyOn_univ, ← univ_prod_univ] at *
exact h.prodMap h'
@[deprecated (since := "2025-03-10")]
alias TendstoUniformly.prod_map := TendstoUniformly.prodMap
theorem TendstoUniformlyOnFilter.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{f' : α → β'} {q : Filter ι'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q p') :
TendstoUniformlyOnFilter (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p ×ˢ q) p' :=
fun u hu => ((h.prodMap h') u hu).diag_of_prod_right
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOnFilter.prod := TendstoUniformlyOnFilter.prodMk
protected theorem TendstoUniformlyOn.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{f' : α → β'} {p' : Filter ι'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s) :
TendstoUniformlyOn (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p')
s :=
(congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a))
@[deprecated (since := "2025-03-10")]
alias TendstoUniformlyOn.prod := TendstoUniformlyOn.prodMk
theorem TendstoUniformly.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'}
{p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p') :=
(h.prodMap h').comp fun a => (a, a)
@[deprecated (since := "2025-03-10")]
alias TendstoUniformly.prod := TendstoUniformly.prodMk
/-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in
`p ×ˢ p'`. -/
theorem tendsto_prod_filter_iff {c : β} :
Tendsto ↿F (p ×ˢ p') (𝓝 c) ↔ TendstoUniformlyOnFilter F (fun _ => c) p p' := by
simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff]
rfl
/-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in
`p ×ˢ 𝓟 s`. -/
theorem tendsto_prod_principal_iff {c : β} :
Tendsto ↿F (p ×ˢ 𝓟 s) (𝓝 c) ↔ TendstoUniformlyOn F (fun _ => c) p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
/-- Uniform convergence to a constant function is equivalent to convergence in `p ×ˢ ⊤`. -/
theorem tendsto_prod_top_iff {c : β} :
Tendsto ↿F (p ×ˢ ⊤) (𝓝 c) ↔ TendstoUniformly F (fun _ => c) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
/-- Uniform convergence on the empty set is vacuously true -/
theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p ∅ := fun u _ => by simp
/-- Uniform convergence on a singleton is equivalent to regular convergence -/
theorem tendstoUniformlyOn_singleton_iff_tendsto :
TendstoUniformlyOn F f p {x} ↔ Tendsto (fun n : ι => F n x) p (𝓝 (f x)) := by
simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def]
exact forall₂_congr fun u _ => by simp [preimage]
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(p' : Filter α) :
TendstoUniformlyOnFilter (fun n : ι => fun _ : α => g n) (fun _ : α => b) p p' := by
simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p'))
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(s : Set α) : TendstoUniformlyOn (fun n : ι => fun _ : α => g n) (fun _ : α => b) p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (𝓟 s))
theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace α] [UniformSpace γ] {U : Set α}
{V : Set β} {F : α → β → γ} (hF : UniformContinuousOn ↿F (U ×ˢ V)) (hU : x ∈ U) :
TendstoUniformlyOn F (F x) (𝓝[U] x) V := by
set φ := fun q : α × β => ((x, q.2), q)
rw [tendstoUniformlyOn_iff_tendsto]
change Tendsto (Prod.map ↿F ↿F ∘ φ) (𝓝[U] x ×ˢ 𝓟 V) (𝓤 γ)
simp only [nhdsWithin, Filter.prod_eq_inf, comap_inf, inf_assoc, comap_principal, inf_principal]
refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => ⟨⟨hU, hx.2⟩, hx⟩)
simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff,
nhds_eq_comap_uniformity, comap_comap]
exact tendsto_comap.prodMk (tendsto_diag_uniformity _ _)
theorem UniformContinuousOn.tendstoUniformly [UniformSpace α] [UniformSpace γ] {U : Set α}
(hU : U ∈ 𝓝 x) {F : α → β → γ} (hF : UniformContinuousOn ↿F (U ×ˢ (univ : Set β))) :
TendstoUniformly F (F x) (𝓝 x) := by
simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU]
using hF.tendstoUniformlyOn (mem_of_mem_nhds hU)
theorem UniformContinuous₂.tendstoUniformly [UniformSpace α] [UniformSpace γ] {f : α → β → γ}
(h : UniformContinuous₂ f) : TendstoUniformly f (f x) (𝓝 x) :=
UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ]
namespace Filter.HasBasis
variable {X ιX ια ιβ : Type*}
/-- An anologue of `Filter.HasBasis.tendsto_right_iff` for `TendstoUniformlyOnFilter`. -/
lemma tendstoUniformlyOnFilter_iff_of_uniformity {F : X → α → β} {f : α → β}
{l : Filter X} {l' : Filter α} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)}
(hβ : (uniformity β).HasBasis pβ sβ) :
TendstoUniformlyOnFilter F f l l' ↔
(∀ i, pβ i → ∀ᶠ n in l ×ˢ l', (f n.2, F n.1 n.2) ∈ sβ i) := by
rw [tendstoUniformlyOnFilter_iff_tendsto, hβ.tendsto_right_iff]
/-- An anologue of `Filter.HasBasis.tendsto_iff` for `TendstoUniformlyOnFilter`. -/
lemma tendstoUniformlyOnFilter_iff {F : X → α → β} {f : α → β}
{l : Filter X} {l' : Filter α} {pX : ιX → Prop} {sX : ιX → Set X}
{pα : ια → Prop} {sα : ια → Set α} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)}
(hl : l.HasBasis pX sX) (hl' : l'.HasBasis pα sα)
(hβ : (uniformity β).HasBasis pβ sβ) :
TendstoUniformlyOnFilter F f l l' ↔
(∀ i, pβ i → ∃ j k, (pX j ∧ pα k) ∧ ∀ x a, x ∈ sX j → a ∈ sα k → (f a, F x a) ∈ sβ i) := by
simp [hβ.tendstoUniformlyOnFilter_iff_of_uniformity, (hl.prod hl').eventually_iff]
/-- An anologue of `Filter.HasBasis.tendsto_right_iff` for `TendstoUniformlyOn`. -/
lemma tendstoUniformlyOn_iff_of_uniformity {F : X → α → β} {f : α → β}
{l : Filter X} {s : Set α} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)}
(hβ : (uniformity β).HasBasis pβ sβ) :
TendstoUniformlyOn F f l s ↔
(∀ i, pβ i → ∀ᶠ n in l, ∀ x ∈ s, (f x, F n x) ∈ sβ i) := by
simp_rw [tendstoUniformlyOn_iff_tendsto, hβ.tendsto_right_iff, eventually_prod_principal_iff]
/-- An anologue of `Filter.HasBasis.tendsto_iff` for `TendstoUniformlyOn`. -/
lemma tendstoUniformlyOn_iff {F : X → α → β} {f : α → β}
{l : Filter X} {s : Set α} {pX : ιX → Prop} {sX : ιX → Set X} {pβ : ιβ → Prop}
{sβ : ιβ → Set (β × β)} (hl : l.HasBasis pX sX) (hβ : (uniformity β).HasBasis pβ sβ) :
TendstoUniformlyOn F f l s ↔
(∀ i, pβ i → ∃ j, pX j ∧ ∀ ⦃x⦄, x ∈ sX j → ∀ a ∈ s, (f a, F x a) ∈ sβ i) := by
simp [hβ.tendstoUniformlyOn_iff_of_uniformity, hl.eventually_iff]
/-- An anologue of `Filter.HasBasis.tendsto_right_iff` for `TendstoUniformly`. -/
lemma tendstoUniformly_iff_of_uniformity {F : X → α → β} {f : α → β}
{l : Filter X} {pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)}
(hβ : (uniformity β).HasBasis pβ sβ) :
TendstoUniformly F f l ↔
(∀ i, pβ i → ∀ᶠ n in l, ∀ x, (f x, F n x) ∈ sβ i) := by
simp_rw [← tendstoUniformlyOn_univ, hβ.tendstoUniformlyOn_iff_of_uniformity, mem_univ,
true_imp_iff]
/-- An anologue of `Filter.HasBasis.tendsto_iff` for `TendstoUniformly`. -/
lemma tendstoUniformly_iff {F : X → α → β} {f : α → β}
{l : Filter X} {pX : ιX → Prop} {sX : ιX → Set X} (hl : l.HasBasis pX sX)
{pβ : ιβ → Prop} {sβ : ιβ → Set (β × β)} (hβ : (uniformity β).HasBasis pβ sβ) :
TendstoUniformly F f l ↔
(∀ i, pβ i → ∃ j, pX j ∧ ∀ ⦃x⦄, x ∈ sX j → ∀ a, (f a, F x a) ∈ sβ i) := by
simp only [hβ.tendstoUniformly_iff_of_uniformity, hl.eventually_iff]
end Filter.HasBasis
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOnFilter (F : ι → α → β) (p : Filter ι) (p' : Filter α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : (ι × ι) × α in (p ×ˢ p) ×ˢ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) ∈ u
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOn (F : ι → α → β) (p : Filter ι) (s : Set α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : ι × ι in p ×ˢ p, ∀ x : α, x ∈ s → (F m.fst x, F m.snd x) ∈ u
theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter :
UniformCauchySeqOn F p s ↔ UniformCauchySeqOnFilter F p (𝓟 s) := by
simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter]
refine forall₂_congr fun u hu => ?_
rw [eventually_prod_principal_iff]
theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) :
UniformCauchySeqOnFilter F p (𝓟 s) := by rwa [← uniformCauchySeqOn_iff_uniformCauchySeqOnFilter]
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') :
UniformCauchySeqOnFilter F p p' := by
intro u hu
rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩
have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht))
apply this.diag_of_prod_right.mono
simp only [and_imp, Prod.forall]
intro n1 n2 x hl hr
exact Set.mem_of_mem_of_subset (prodMk_mem_compRel (htsymm hl) hr) htmem
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) :
UniformCauchySeqOn F p s :=
uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr
hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter
/-- A uniformly Cauchy sequence converges uniformly to its limit -/
theorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto
(hF : UniformCauchySeqOnFilter F p p')
(hF' : ∀ᶠ x : α in p', Tendsto (fun n => F n x) p (𝓝 (f x))) :
TendstoUniformlyOnFilter F f p p' := by
rcases p.eq_or_neBot with rfl | _
· simp only [TendstoUniformlyOnFilter, bot_prod, eventually_bot, implies_true]
-- Proof idea: |f_n(x) - f(x)| ≤ |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n`
-- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m ≥ n`. Then for
-- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small.
intro u hu
rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩
-- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF'
-- But we need to promote hF' to the full product filter to use it
have hmc : ∀ᶠ x in (p ×ˢ p) ×ˢ p', Tendsto (fun n : ι => F n x.snd) p (𝓝 (f x.snd)) := by
rw [eventually_prod_iff]
exact ⟨fun _ => True, by simp, _, hF', by simp⟩
-- To apply filter operations we'll need to do some order manipulation
rw [Filter.eventually_swap_iff]
have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc))
apply this.curry.mono
simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap,
and_imp, Prod.forall]
-- Complete the proof
intro x n hx hm'
refine Set.mem_of_mem_of_subset (mem_compRel.mpr ?_) htmem
rw [Uniform.tendsto_nhds_right] at hm'
have := hx.and (hm' ht)
obtain ⟨m, hm⟩ := this.exists
exact ⟨F m x, ⟨hm.2, htsymm hm.1⟩⟩
/-- A uniformly Cauchy sequence converges uniformly to its limit -/
theorem UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto (hF : UniformCauchySeqOn F p s)
(hF' : ∀ x : α, x ∈ s → Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOn F f p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(hF.uniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto hF')
theorem UniformCauchySeqOnFilter.mono_left {p'' : Filter ι} (hf : UniformCauchySeqOnFilter F p p')
(hp : p'' ≤ p) : UniformCauchySeqOnFilter F p'' p' := fun u hu =>
(hf u hu).filter_mono (p'.prod_mono_left (Filter.prod_mono hp hp))
theorem UniformCauchySeqOnFilter.mono_right {p'' : Filter α} (hf : UniformCauchySeqOnFilter F p p')
(hp : p'' ≤ p') : UniformCauchySeqOnFilter F p p'' := fun u hu =>
have := (hf u hu).filter_mono ((p ×ˢ p).prod_mono_right hp)
this.mono (by simp)
theorem UniformCauchySeqOn.mono (hf : UniformCauchySeqOn F p s) (hss' : s' ⊆ s) :
UniformCauchySeqOn F p s' := by
rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢
exact hf.mono_right (le_principal_iff.mpr <| mem_principal.mpr hss')
/-- Composing on the right by a function preserves uniform Cauchy sequences -/
theorem UniformCauchySeqOnFilter.comp {γ : Type*} (hf : UniformCauchySeqOnFilter F p p')
(g : γ → α) : UniformCauchySeqOnFilter (fun n => F n ∘ g) p (p'.comap g) := fun u hu => by
obtain ⟨pa, hpa, pb, hpb, hpapb⟩ := eventually_prod_iff.mp (hf u hu)
rw [eventually_prod_iff]
refine ⟨pa, hpa, pb ∘ g, ?_, fun hx _ hy => hpapb hx hy⟩
exact eventually_comap.mpr (hpb.mono fun x hx y hy => by simp only [hx, hy, Function.comp_apply])
/-- Composing on the right by a function preserves uniform Cauchy sequences -/
theorem UniformCauchySeqOn.comp {γ : Type*} (hf : UniformCauchySeqOn F p s) (g : γ → α) :
UniformCauchySeqOn (fun n => F n ∘ g) p (g ⁻¹' s) := by
rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢
simpa only [UniformCauchySeqOn, comap_principal] using hf.comp g
/-- Composing on the left by a uniformly continuous function preserves
uniform Cauchy sequences -/
theorem UniformContinuous.comp_uniformCauchySeqOn [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (hf : UniformCauchySeqOn F p s) :
UniformCauchySeqOn (fun n => g ∘ F n) p s := fun _u hu => hf _ (hg hu)
theorem UniformCauchySeqOn.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{p' : Filter ι'} {s' : Set α'} (h : UniformCauchySeqOn F p s)
(h' : UniformCauchySeqOn F' p' s') :
UniformCauchySeqOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (p ×ˢ p') (s ×ˢ s') := by
intro u hu
rw [uniformity_prod_eq_prod, mem_map, mem_prod_iff] at hu
obtain ⟨v, hv, w, hw, hvw⟩ := hu
simp_rw [mem_prod, and_imp, Prod.forall, Prod.map_apply]
rw [← Set.image_subset_iff] at hvw
apply (tendsto_swap4_prod.eventually ((h v hv).prod_mk (h' w hw))).mono
intro x hx a b ha hb
exact hvw ⟨_, mk_mem_prod (hx.1 a ha) (hx.2 b hb), rfl⟩
@[deprecated (since := "2025-03-10")]
alias UniformCauchySeqOn.prod_map := UniformCauchySeqOn.prodMap
theorem UniformCauchySeqOn.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{p' : Filter ι'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s) :
UniformCauchySeqOn (fun (i : ι × ι') a => (F i.fst a, F' i.snd a)) (p ×ˢ p') s :=
(congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a))
theorem UniformCauchySeqOn.prod' {β' : Type*} [UniformSpace β'] {F' : ι → α → β'}
(h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p s) :
UniformCauchySeqOn (fun (i : ι) a => (F i a, F' i a)) p s := fun u hu =>
have hh : Tendsto (fun x : ι => (x, x)) p (p ×ˢ p) := tendsto_diag
(hh.prodMap hh).eventually ((h.prod h') u hu)
/-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form
a Cauchy sequence. -/
theorem UniformCauchySeqOn.cauchy_map [hp : NeBot p] (hf : UniformCauchySeqOn F p s) (hx : x ∈ s) :
Cauchy (map (fun i => F i x) p) := by
simp only [cauchy_map_iff, hp, true_and]
intro u hu
rw [mem_map]
filter_upwards [hf u hu] with p hp using hp x hx
/-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form
a Cauchy sequence. See `UniformCauchySeqOn.cauchy_map` for the non-`atTop` case. -/
theorem UniformCauchySeqOn.cauchySeq [Nonempty ι] [SemilatticeSup ι]
(hf : UniformCauchySeqOn F atTop s) (hx : x ∈ s) :
CauchySeq fun i ↦ F i x :=
hf.cauchy_map (hp := atTop_neBot) hx
section SeqTendsto
theorem tendstoUniformlyOn_of_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated]
(h : ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s) :
TendstoUniformlyOn F f l s := by
rw [tendstoUniformlyOn_iff_tendsto, tendsto_iff_seq_tendsto]
intro u hu
rw [tendsto_prod_iff'] at hu
specialize h (fun n => (u n).fst) hu.1
rw [tendstoUniformlyOn_iff_tendsto] at h
exact h.comp (tendsto_id.prodMk hu.2)
theorem TendstoUniformlyOn.seq_tendstoUniformlyOn {l : Filter ι} (h : TendstoUniformlyOn F f l s)
(u : ℕ → ι) (hu : Tendsto u atTop l) : TendstoUniformlyOn (fun n => F (u n)) f atTop s := by
rw [tendstoUniformlyOn_iff_tendsto] at h ⊢
exact h.comp ((hu.comp tendsto_fst).prodMk tendsto_snd)
theorem tendstoUniformlyOn_iff_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated] :
TendstoUniformlyOn F f l s ↔
∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s :=
⟨TendstoUniformlyOn.seq_tendstoUniformlyOn, tendstoUniformlyOn_of_seq_tendstoUniformlyOn⟩
theorem tendstoUniformly_iff_seq_tendstoUniformly {l : Filter ι} [l.IsCountablyGenerated] :
TendstoUniformly F f l ↔
∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformly (fun n => F (u n)) f atTop := by
simp_rw [← tendstoUniformlyOn_univ]
exact tendstoUniformlyOn_iff_seq_tendstoUniformlyOn
end SeqTendsto
section
variable [NeBot p] {L : ι → β} {ℓ : β}
theorem TendstoUniformlyOnFilter.tendsto_of_eventually_tendsto
(h1 : TendstoUniformlyOnFilter F f p p') (h2 : ∀ᶠ i in p, Tendsto (F i) p' (𝓝 (L i)))
(h3 : Tendsto L p (𝓝 ℓ)) : Tendsto f p' (𝓝 ℓ) := by
rw [tendsto_nhds_left]
intro s hs
rw [mem_map, Set.preimage, ← eventually_iff]
obtain ⟨t, ht, hts⟩ := comp3_mem_uniformity hs
have p1 : ∀ᶠ i in p, (L i, ℓ) ∈ t := tendsto_nhds_left.mp h3 ht
have p2 : ∀ᶠ i in p, ∀ᶠ x in p', (F i x, L i) ∈ t := by
filter_upwards [h2] with i h2 using tendsto_nhds_left.mp h2 ht
have p3 : ∀ᶠ i in p, ∀ᶠ x in p', (f x, F i x) ∈ t := (h1 t ht).curry
obtain ⟨i, p4, p5, p6⟩ := (p1.and (p2.and p3)).exists
filter_upwards [p5, p6] with x p5 p6 using hts ⟨F i x, p6, L i, p5, p4⟩
theorem TendstoUniformly.tendsto_of_eventually_tendsto
(h1 : TendstoUniformly F f p) (h2 : ∀ᶠ i in p, Tendsto (F i) p' (𝓝 (L i)))
(h3 : Tendsto L p (𝓝 ℓ)) : Tendsto f p' (𝓝 ℓ) :=
(h1.tendstoUniformlyOnFilter.mono_right le_top).tendsto_of_eventually_tendsto h2 h3
end
|
CongruenceSubgroups.lean
|
/-
Copyright (c) 2022 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Data.Real.Basic
import Mathlib.LinearAlgebra.Matrix.Integer
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs
/-!
# Congruence subgroups
This defines congruence subgroups of `SL(2, ℤ)` such as `Γ(N)`, `Γ₀(N)` and `Γ₁(N)` for `N` a
natural number.
It also contains basic results about congruence subgroups.
-/
open Matrix.SpecialLinearGroup Matrix
open scoped MatrixGroups ModularGroup Real
variable (N : ℕ)
local notation "SLMOD(" N ")" =>
@Matrix.SpecialLinearGroup.map (Fin 2) _ _ _ _ _ _ (Int.castRingHom (ZMod N))
@[simp]
theorem SL_reduction_mod_hom_val (γ : SL(2, ℤ)) (i j : Fin 2) :
SLMOD(N) γ i j = (γ i j : ZMod N) :=
rfl
namespace CongruenceSubgroup
/-- The full level `N` congruence subgroup of `SL(2, ℤ)` of matrices that reduce to the identity
modulo `N`. -/
def Gamma : Subgroup SL(2, ℤ) :=
SLMOD(N).ker
@[inherit_doc] scoped notation "Γ(" n ")" => Gamma n
theorem Gamma_mem' {N} {γ : SL(2, ℤ)} : γ ∈ Gamma N ↔ SLMOD(N) γ = 1 :=
Iff.rfl
@[simp]
theorem Gamma_mem {N} {γ : SL(2, ℤ)} : γ ∈ Gamma N ↔ (γ 0 0 : ZMod N) = 1 ∧
(γ 0 1 : ZMod N) = 0 ∧ (γ 1 0 : ZMod N) = 0 ∧ (γ 1 1 : ZMod N) = 1 := by
rw [Gamma_mem']
constructor
· intro h
simp [← SL_reduction_mod_hom_val N γ, h]
· intro h
ext i j
rw [SL_reduction_mod_hom_val N γ]
fin_cases i <;> fin_cases j <;> simp only
exacts [h.1, h.2.1, h.2.2.1, h.2.2.2]
theorem Gamma_normal : Subgroup.Normal (Gamma N) :=
SLMOD(N).normal_ker
theorem Gamma_one_top : Gamma 1 = ⊤ := by
ext
simp [eq_iff_true_of_subsingleton]
lemma mem_Gamma_one (γ : SL(2, ℤ)) : γ ∈ Γ(1) := by
simp only [Gamma_one_top, Subgroup.mem_top]
theorem Gamma_zero_bot : Gamma 0 = ⊥ := rfl
lemma ModularGroup_T_pow_mem_Gamma (N M : ℤ) (hNM : N ∣ M) :
(ModularGroup.T ^ M) ∈ Gamma (Int.natAbs N) := by
simp only [Gamma_mem, Fin.isValue, ModularGroup.coe_T_zpow, of_apply, cons_val', cons_val_zero,
empty_val', cons_val_fin_one, Int.cast_one, cons_val_one,
Int.cast_zero, and_self, and_true, true_and]
refine Iff.mpr (ZMod.intCast_zmod_eq_zero_iff_dvd M (Int.natAbs N)) ?_
simp only [Int.natCast_natAbs, abs_dvd, hNM]
instance instFiniteIndexGamma [NeZero N] : (Gamma N).FiniteIndex := Subgroup.finiteIndex_ker _
/-- The congruence subgroup of `SL(2, ℤ)` of matrices whose lower left-hand entry reduces to zero
modulo `N`. -/
def Gamma0 : Subgroup SL(2, ℤ) where
carrier := { g | (g 1 0 : ZMod N) = 0 }
one_mem' := by simp
mul_mem' := by
intro a b ha hb
simp only [Set.mem_setOf_eq]
have h := (Matrix.two_mul_expl a.1 b.1).2.2.1
simp only [coe_mul, Set.mem_setOf_eq] at *
rw [h]
simp [ha, hb]
inv_mem' := by
intro a ha
simp only [Set.mem_setOf_eq]
rw [SL2_inv_expl a]
simp only [cons_val_zero, cons_val_one,
Int.cast_neg, neg_eq_zero, Set.mem_setOf_eq] at *
exact ha
@[simp]
theorem Gamma0_mem {N} {A : SL(2, ℤ)} : A ∈ Gamma0 N ↔ (A 1 0 : ZMod N) = 0 :=
Iff.rfl
/-- The group homomorphism from `CongruenceSubgroup.Gamma0` to `ZMod N` given by
mapping a matrix to its lower right-hand entry. -/
def Gamma0Map (N : ℕ) : Gamma0 N →* ZMod N where
toFun g := g.1 1 1
map_one' := by simp
map_mul' := by
rintro ⟨A, hA⟩ ⟨B, _⟩
simp only [MulMemClass.mk_mul_mk, Fin.isValue, coe_mul, (two_mul_expl A.1 B).2.2.2,
Int.cast_add, Int.cast_mul, Gamma0_mem.mp hA, zero_mul, zero_add]
/-- The congruence subgroup `Gamma1` (as a subgroup of `Gamma0`) of matrices whose bottom
row is congruent to `(0, 1)` modulo `N`. -/
def Gamma1' (N : ℕ) : Subgroup (Gamma0 N) :=
(Gamma0Map N).ker
@[simp]
theorem Gamma1_mem' {N} {γ : Gamma0 N} : γ ∈ Gamma1' N ↔ Gamma0Map N γ = 1 :=
Iff.rfl
theorem Gamma1_to_Gamma0_mem {N} (A : Gamma0 N) :
A ∈ Gamma1' N ↔
((A.1 0 0 : ℤ) : ZMod N) = 1 ∧ ((A.1 1 1 : ℤ) : ZMod N) = 1
∧ ((A.1 1 0 : ℤ) : ZMod N) = 0 := by
constructor
· intro ha
have adet : (A.1.1.det : ZMod N) = 1 := by simp only [A.1.property, Int.cast_one]
rw [Matrix.det_fin_two] at adet
simp only [Gamma1_mem', Gamma0Map, MonoidHom.coe_mk, OneHom.coe_mk, Int.cast_sub,
Int.cast_mul] at *
simpa only [Gamma1_mem', Gamma0Map, MonoidHom.coe_mk, OneHom.coe_mk, Int.cast_sub,
Int.cast_mul, ha, Gamma0_mem.mp A.property, and_self_iff, and_true, mul_one, mul_zero,
sub_zero] using adet
· intro ha
simp only [Gamma1_mem', Gamma0Map, MonoidHom.coe_mk]
exact ha.2.1
/-- The congruence subgroup `Gamma1` of `SL(2, ℤ)` consisting of matrices
whose bottom row is congruent to `(0,1)` modulo `N`. -/
def Gamma1 (N : ℕ) : Subgroup SL(2, ℤ) :=
Subgroup.map ((Gamma0 N).subtype.comp (Gamma1' N).subtype) ⊤
@[simp]
theorem Gamma1_mem (N : ℕ) (A : SL(2, ℤ)) : A ∈ Gamma1 N ↔
(A 0 0 : ZMod N) = 1 ∧ (A 1 1 : ZMod N) = 1 ∧ (A 1 0 : ZMod N) = 0 := by
constructor
· intro ha
simp_rw [Gamma1, Subgroup.mem_map] at ha
obtain ⟨⟨x, hx⟩, hxx⟩ := ha
rw [Gamma1_to_Gamma0_mem] at hx
simp only [Subgroup.mem_top, true_and] at hxx
rw [← hxx]
convert hx
· intro ha
simp_rw [Gamma1, Subgroup.mem_map]
have hA : A ∈ Gamma0 N := by simp [ha.right.right, Gamma0_mem]
have HA : (⟨A, hA⟩ : Gamma0 N) ∈ Gamma1' N := by
simp only [Gamma1_to_Gamma0_mem]
exact ha
refine ⟨(⟨(⟨A, hA⟩ : Gamma0 N), HA⟩ : (Gamma1' N : Subgroup (Gamma0 N))), ?_⟩
simp
theorem Gamma1_in_Gamma0 (N : ℕ) : Gamma1 N ≤ Gamma0 N := by
intro x HA
simp only [Gamma0_mem, Gamma1_mem] at *
exact HA.2.2
section CongruenceSubgroups
/-- A congruence subgroup is a subgroup of `SL(2, ℤ)` which contains some `Gamma N` for some
`N ≠ 0`. -/
def IsCongruenceSubgroup (Γ : Subgroup SL(2, ℤ)) : Prop :=
∃ N ≠ 0, Gamma N ≤ Γ
theorem isCongruenceSubgroup_trans (H K : Subgroup SL(2, ℤ)) (h : H ≤ K)
(h2 : IsCongruenceSubgroup H) : IsCongruenceSubgroup K := by
obtain ⟨N, hN⟩ := h2
exact ⟨N, hN.1, hN.2.trans h⟩
theorem Gamma_is_cong_sub (N : ℕ) [NeZero N] : IsCongruenceSubgroup (Gamma N) :=
⟨N, NeZero.ne _, le_rfl⟩
theorem Gamma1_is_congruence (N : ℕ) [NeZero N] : IsCongruenceSubgroup (Gamma1 N) := by
refine ⟨N, NeZero.ne _, fun A hA ↦ ?_⟩
simp_all [Gamma1_mem, Gamma_mem]
theorem Gamma0_is_congruence (N : ℕ) [NeZero N] : IsCongruenceSubgroup (Gamma0 N) :=
isCongruenceSubgroup_trans _ _ (Gamma1_in_Gamma0 N) (Gamma1_is_congruence N)
lemma IsCongruenceSubgroup.finiteIndex {Γ : Subgroup SL(2, ℤ)}
(h : IsCongruenceSubgroup Γ) : Γ.FiniteIndex := by
obtain ⟨N, hN⟩ := h
have : NeZero N := ⟨hN.1⟩
exact Subgroup.finiteIndex_of_le hN.2
instance instFiniteIndexGamma0 [NeZero N] : (Gamma0 N).FiniteIndex :=
(Gamma0_is_congruence N).finiteIndex
instance instFiniteIndexGamma1 [NeZero N] : (Gamma1 N).FiniteIndex :=
(Gamma1_is_congruence N).finiteIndex
end CongruenceSubgroups
section Conjugation
open Pointwise ConjAct
/-- The subgroup `SL(2, ℤ) ∩ g⁻¹ Γ g`, for `Γ` a subgroup of `SL(2, ℤ)` and `g ∈ GL(2, ℝ)`. -/
def conjGL (Γ : Subgroup SL(2, ℤ)) (g : GL (Fin 2) ℝ) : Subgroup SL(2, ℤ) :=
((toConjAct g⁻¹) • (Γ.map (SpecialLinearGroup.toGL.comp
<| SpecialLinearGroup.map (Int.castRingHom ℝ)))).comap
(SpecialLinearGroup.toGL.comp <| SpecialLinearGroup.map (Int.castRingHom ℝ))
@[simp] lemma mem_conjGL {Γ : Subgroup SL(2, ℤ)} {g : GL (Fin 2) ℝ} {x : SL(2, ℤ)} :
x ∈ conjGL Γ g ↔ ∃ y ∈ Γ, y = g * x * g⁻¹ := by
simp [conjGL, Subgroup.mem_inv_pointwise_smul_iff, toConjAct_smul]
lemma mem_conjGL' {Γ : Subgroup SL(2, ℤ)} {g : GL (Fin 2) ℝ} {x : SL(2, ℤ)} :
x ∈ conjGL Γ g ↔ ∃ y ∈ Γ, g⁻¹ * y * g = x := by
rw [mem_conjGL]
refine exists_congr fun y ↦ and_congr_right fun hy ↦ ?_
rw [eq_mul_inv_iff_mul_eq, mul_assoc, inv_mul_eq_iff_eq_mul]
@[simp]
lemma conjGL_coe (Γ : Subgroup SL(2, ℤ)) (g : SL(2, ℤ)) :
conjGL Γ g = (toConjAct g⁻¹) • Γ := by
ext x
simp_rw [mem_conjGL, ← map_inv, ← map_mul, toGL_injective.eq_iff, map_intCast_injective.eq_iff,
exists_eq_right, toConjAct_inv, Subgroup.mem_inv_pointwise_smul_iff, toConjAct_smul]
@[deprecated (since := "2025-05-15")] alias conjGLPos := conjGL
@[deprecated (since := "2025-05-15")] alias conjGLPos_coe := conjGL_coe
@[deprecated (since := "2025-05-15")] alias mem_conjGLPos := mem_conjGL
@[deprecated (since := "2025-05-15")] alias mem_conjGLPos' := mem_conjGL'
theorem Gamma_cong_eq_self (N : ℕ) (g : ConjAct SL(2, ℤ)) : g • Gamma N = Gamma N := by
apply Subgroup.Normal.conjAct (Gamma_normal N)
theorem conj_cong_is_cong (g : ConjAct SL(2, ℤ)) (Γ : Subgroup SL(2, ℤ))
(h : IsCongruenceSubgroup Γ) : IsCongruenceSubgroup (g • Γ) := by
obtain ⟨N, HN⟩ := h
refine ⟨N, ?_⟩
rw [← Gamma_cong_eq_self N g, Subgroup.pointwise_smul_le_pointwise_smul_iff]
exact HN
/-- For any `g ∈ GL(2, ℚ)` and `M ≠ 0`, there exists `N` such that `g x g⁻¹ ∈ Γ(M)` for all
`x ∈ Γ(N)`. -/
theorem exists_Gamma_le_conj (g : GL (Fin 2) ℚ) (M : ℕ) [NeZero M] :
∃ N ≠ 0, ∀ x ∈ Gamma N, g * (x.map (Int.castRingHom ℚ)).toGL * g⁻¹ ∈
(fun x : SL(2, ℤ) ↦ (x.map (Int.castRingHom ℚ)).toGL) '' (Gamma M) := by
-- Give names to the numerators and denominators of `g` and `g⁻¹`
let A₁ := g.1
let A₂ := (g⁻¹).1
have hA₁₂ : A₁ * A₂ = 1 := by simp only [← Matrix.GeneralLinearGroup.coe_mul,
mul_inv_cancel, Matrix.GeneralLinearGroup.coe_one, A₁, A₂]
let a₁ := A₁.den
let a₂ := A₂.den
-- we take `N = a₁ * a₂`
refine ⟨a₁ * a₂ * M, mul_ne_zero (mul_ne_zero A₁.den_ne_zero A₂.den_ne_zero) (NeZero.ne _),
fun ⟨y, hy⟩ hy' ↦ ?_⟩
-- Show that `y` is of the form `1 + (a₁ * a₂) • k` for some integer matrix `k`.
obtain ⟨k, hk⟩ : ∃ k, y = 1 + (a₁ * a₂ * M) • k := by
replace hy' : y.map (Int.cast : ℤ → ZMod (a₁ * a₂ * M)) = 1 := by
rw [CongruenceSubgroup.Gamma_mem', Subtype.ext_iff] at hy'
simpa using hy'
use Matrix.of fun i j ↦ (y - 1) i j / (a₁ * a₂ * M)
rw [← sub_eq_iff_eq_add']
ext i j
simp_rw [Matrix.smul_apply, Matrix.of_apply, nsmul_eq_mul, Nat.cast_mul]
refine (Int.mul_ediv_cancel_of_dvd ?_).symm
rw [← Matrix.map_one Int.cast (by simp) (by simp), ← sub_eq_zero,
← Matrix.map_sub _ (by simp)] at hy'
simpa only [Matrix.zero_apply, Matrix.map_apply, ZMod.intCast_zmod_eq_zero_iff_dvd,
Nat.cast_mul] using congr_fun₂ hy' i j
-- use this `k` to cook up a new integer matrix, which we will show comes from `SL(2, ℤ)`
let z := 1 + M • (A₁.num * k * A₂.num)
have hz_coe : z.map Int.cast = A₁ * (y.map Int.cast) * A₂ := by
simp only [Matrix.map_add _ Int.cast_add, Matrix.map_one _ Int.cast_zero Int.cast_one, hk,
mul_add, mul_one, add_mul, hA₁₂, add_right_inj, z]
conv_rhs => rw [← A₁.inv_denom_smul_num, ← A₂.inv_denom_smul_num, Matrix.map_smul _ _ (by simp)]
simp only [Matrix.smul_mul, Matrix.mul_smul, Matrix.map_smul (Int.cast : ℤ → ℚ) M (by simp),
Matrix.map_mul_intCast]
rw [← Nat.cast_smul_eq_nsmul ℚ (_ * M), ← MulAction.mul_smul, ← MulAction.mul_smul,
mul_comm a₁ a₂, Nat.cast_mul, Nat.cast_mul, mul_assoc _ _ (M : ℚ), mul_comm _ (M : ℚ),
inv_mul_cancel_left₀ (mod_cast A₂.den_ne_zero),
mul_inv_cancel_right₀ (mod_cast A₁.den_ne_zero), Nat.cast_smul_eq_nsmul]
have hz_det : z.det = 1 := by
have := congr_arg Matrix.det hz_coe
simp_rw [Matrix.det_mul, ← Int.cast_det] at this
rwa [mul_right_comm, ← Matrix.det_mul, hA₁₂, Matrix.det_one, one_mul, hy, Int.cast_inj] at this
refine ⟨⟨z, hz_det⟩, ?_, by simpa only [Subtype.ext_iff, Subgroup.coe_mul, Units.ext_iff,
Units.val_mul] using hz_coe⟩
rw [SetLike.mem_coe, CongruenceSubgroup.Gamma_mem', Subtype.ext_iff]
ext i j
simp_rw [map_apply_coe, z, map_add, map_one, RingHom.mapMatrix_apply, Int.coe_castRingHom,
add_apply, map_apply, coe_one, add_eq_left, Matrix.smul_apply, nsmul_eq_mul, Int.cast_mul,
Int.cast_natCast, ZMod.natCast_self M, zero_mul]
/-- For any `g ∈ GL(2, ℚ)` and `M ≠ 0`, there exists `N` such that `g Γ(N) g⁻¹ ≤ Γ(M)`. -/
theorem exists_Gamma_le_conj' (g : GL (Fin 2) ℚ) (M : ℕ) [NeZero M] :
∃ N ≠ 0, (toConjAct <| g.map (Rat.castHom ℝ)) • (Gamma N).map (mapGL ℝ)
≤ (Gamma M).map (mapGL ℝ) := by
obtain ⟨N, hN, h⟩ := exists_Gamma_le_conj g M
refine ⟨N, hN, fun y hy ↦ ?_⟩
simp_rw [Subgroup.mem_pointwise_smul_iff_inv_smul_mem, Subgroup.mem_map,
eq_inv_smul_iff] at hy
obtain ⟨x, hx, rfl⟩ := hy
obtain ⟨z, hz, hz'⟩ := h x hx
use z, hz
simpa only [Subtype.ext_iff, Units.ext_iff, map_mul] using
congr_arg (GeneralLinearGroup.map (Rat.castHom ℝ)) hz'
open Subgroup in
/-- If `Γ` has finite index in `SL(2, ℤ)`, then so does `g⁻¹ Γ g ∩ SL(2, ℤ)` for any
`g ∈ GL(2, ℚ)`. -/
lemma finiteIndex_conjGL (Γ : Subgroup SL(2, ℤ)) [Γ.FiniteIndex] (g : GL (Fin 2) ℚ) :
(conjGL Γ (g.map <| Rat.castHom ℝ)).FiniteIndex := by
constructor
let t := (toConjAct <| g.map <| Rat.castHom ℝ)⁻¹
let G := Γ.map (mapGL ℝ)
let A := MonoidHom.range (mapGL ℝ : SL(2, ℤ) →* _)
suffices (t • G ⊓ A).relindex A ≠ 0 by rwa [conjGL, index_comap, ← inf_relindex_right]
apply relindex_ne_zero_trans (K := t • A ⊓ A)
· -- Show that `[ (t • A ⊓ A) : (t • G ⊓ A)] < ∞`.
apply relindex_inter_ne_zero
rw [relindex_pointwise_smul, ← index_comap,
comap_map_eq_self_of_injective mapGL_injective]
exact FiniteIndex.index_ne_zero
· -- Show that `[A : (t • A ⊓ A)] < ∞` (note this is independent of `Γ`)
obtain ⟨N, hN, hN'⟩ := exists_Gamma_le_conj' g 1
rw [Gamma_one_top, ← MonoidHom.range_eq_map] at hN'
suffices Γ(N) ≤ (t • A ⊓ A).comap (mapGL ℝ) by
haveI _ : NeZero N := ⟨hN⟩
simpa only [index_comap] using (finiteIndex_of_le this).index_ne_zero
intro k hk
simpa [mem_pointwise_smul_iff_inv_smul_mem, A] using
hN' <| smul_mem_pointwise_smul _ _ _ ⟨k, hk, rfl⟩
/-- If `Γ` is a congruence subgroup, then so is `g⁻¹ Γ g ∩ SL(2, ℤ)` for any `g ∈ GL(2, ℚ)`. -/
lemma IsCongruenceSubgroup.conjGL {Γ : Subgroup SL(2, ℤ)} (hΓ : IsCongruenceSubgroup Γ)
(g : GL (Fin 2) ℚ) :
IsCongruenceSubgroup (conjGL Γ (g.map <| Rat.castHom ℝ)) := by
obtain ⟨M, hN, hΓM⟩ := hΓ
haveI _ : NeZero M := ⟨hN⟩
obtain ⟨N, hN, hN'⟩ := exists_Gamma_le_conj' g M
rw [Subgroup.pointwise_smul_subset_iff] at hN'
refine ⟨N, ‹_›, fun x hx ↦ ?_⟩
obtain ⟨y, hy, hy'⟩ := Subgroup.mem_inv_pointwise_smul_iff.mp <| hN' ⟨x, hx, rfl⟩
exact mem_conjGL.mpr ⟨y, hΓM hy, hy'⟩
end Conjugation
end CongruenceSubgroup
|
imset2_finset.v
|
From mathcomp Require Import all_boot.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Check @imset2_pair.
|
HomologicalFunctor.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.CategoryTheory.Shift.ShiftSequence
import Mathlib.CategoryTheory.Triangulated.Functor
import Mathlib.CategoryTheory.Triangulated.Subcategory
import Mathlib.Algebra.Homology.ExactSequence
/-! # Homological functors
In this file, given a functor `F : C ⥤ A` from a pretriangulated category to
an abelian category, we define the type class `F.IsHomological`, which is the property
that `F` sends distinguished triangles in `C` to exact sequences in `A`.
If `F` has been endowed with `[F.ShiftSequence ℤ]`, then we may think
of the functor `F` as a `H^0`, and then the `H^n` functors are the functors `F.shift n : C ⥤ A`:
we have isomorphisms `(F.shift n).obj X ≅ F.obj (X⟦n⟧)`, but through the choice of this
"shift sequence", the user may provide functors with better definitional properties.
Given a triangle `T` in `C`, we define a connecting homomorphism
`F.homologySequenceδ T n₀ n₁ h : (F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁`
under the assumption `h : n₀ + 1 = n₁`. When `T` is distinguished, this connecting
homomorphism is part of a long exact sequence
`... ⟶ (F.shift n₀).obj T.obj₁ ⟶ (F.shift n₀).obj T.obj₂ ⟶ (F.shift n₀).obj T.obj₃ ⟶ ...`
The exactness of this long exact sequence is given by three lemmas
`F.homologySequence_exact₁`, `F.homologySequence_exact₂` and `F.homologySequence_exact₃`.
If `F` is a homological functor, we define the strictly full triangulated subcategory
`F.homologicalKernel`: it consists of objects `X : C` such that for all `n : ℤ`,
`(F.shift n).obj X` (or `F.obj (X⟦n⟧)`) is zero. We show that a morphism `f` in `C`
belongs to `F.homologicalKernel.trW` (i.e. the cone of `f` is in this kernel) iff
`(F.shift n).map f` is an isomorphism for all `n : ℤ`.
Note: depending on the sources, homological functors are sometimes
called cohomological functors, while certain authors use "cohomological functors"
for "contravariant" functors (i.e. functors `Cᵒᵖ ⥤ A`).
## References
* [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996]
-/
namespace CategoryTheory
open Category Limits Pretriangulated ZeroObject Preadditive
variable {C D A : Type*} [Category C] [HasShift C ℤ]
[Category D] [HasZeroObject D] [HasShift D ℤ] [Preadditive D]
[∀ (n : ℤ), (CategoryTheory.shiftFunctor D n).Additive] [Pretriangulated D]
[Category A]
namespace Functor
variable (F : C ⥤ A)
/-- The kernel of a homological functor `F : C ⥤ A` is the strictly full
triangulated subcategory consisting of objects `X` such that
for all `n : ℤ`, `F.obj (X⟦n⟧)` is zero. -/
def homologicalKernel : ObjectProperty C :=
fun X ↦ ∀ (n : ℤ), IsZero (F.obj (X⟦n⟧))
lemma mem_homologicalKernel_iff [F.ShiftSequence ℤ] (X : C) :
F.homologicalKernel X ↔ ∀ (n : ℤ), IsZero ((F.shift n).obj X) := by
simp only [← fun (n : ℤ) => Iso.isZero_iff ((F.isoShift n).app X),
homologicalKernel, comp_obj]
section Pretriangulated
variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive]
[Pretriangulated C] [Abelian A]
/-- A functor from a pretriangulated category to an abelian category is an homological functor
if it sends distinguished triangles to exact sequences. -/
class IsHomological : Prop extends F.PreservesZeroMorphisms where
exact (T : Triangle C) (hT : T ∈ distTriang C) :
((shortComplexOfDistTriangle T hT).map F).Exact
lemma map_distinguished_exact [F.IsHomological] (T : Triangle C) (hT : T ∈ distTriang C) :
((shortComplexOfDistTriangle T hT).map F).Exact :=
IsHomological.exact _ hT
instance (L : C ⥤ D) (F : D ⥤ A) [L.CommShift ℤ] [L.IsTriangulated] [F.IsHomological] :
(L ⋙ F).IsHomological where
exact T hT := F.map_distinguished_exact _ (L.map_distinguished T hT)
lemma IsHomological.mk' [F.PreservesZeroMorphisms]
(hF : ∀ (T : Pretriangulated.Triangle C) (hT : T ∈ distTriang C),
∃ (T' : Pretriangulated.Triangle C) (e : T ≅ T'),
((shortComplexOfDistTriangle T' (isomorphic_distinguished _ hT _ e.symm)).map F).Exact) :
F.IsHomological where
exact T hT := by
obtain ⟨T', e, h'⟩ := hF T hT
exact (ShortComplex.exact_iff_of_iso
(F.mapShortComplex.mapIso ((shortComplexOfDistTriangleIsoOfIso e hT)))).2 h'
lemma IsHomological.of_iso {F₁ F₂ : C ⥤ A} [F₁.IsHomological] (e : F₁ ≅ F₂) :
F₂.IsHomological :=
have := preservesZeroMorphisms_of_iso e
⟨fun T hT => ShortComplex.exact_of_iso (ShortComplex.mapNatIso _ e)
(F₁.map_distinguished_exact T hT)⟩
section
variable [F.IsHomological]
instance : F.homologicalKernel.IsClosedUnderIsomorphisms where
of_iso e hX n := (hX n).of_iso ((shiftFunctor C n ⋙ F).mapIso e.symm)
instance : F.homologicalKernel.IsTriangulated where
exists_zero := ⟨0, isZero_zero C,
fun n ↦ (shiftFunctor C n ⋙ F).map_isZero (isZero_zero C)⟩
toIsStableUnderShift := ⟨fun a ↦ ⟨fun X hX b ↦
(hX (a + b)).of_iso (F.mapIso ((shiftFunctorAdd C a b).app X).symm)⟩⟩
toIsTriangulatedClosed₂ :=
ObjectProperty.IsTriangulatedClosed₂.mk' (fun T hT h₁ h₃ n ↦
(F.map_distinguished_exact _
(Triangle.shift_distinguished T hT n)).isZero_of_both_zeros
((h₁ n).eq_of_src _ _) ((h₃ n).eq_of_tgt _ _))
end
noncomputable instance (priority := 100) [F.IsHomological] :
PreservesLimitsOfShape (Discrete WalkingPair) F := by
suffices ∀ (X₁ X₂ : C), PreservesLimit (pair X₁ X₂) F from
⟨fun {X} => preservesLimit_of_iso_diagram F (diagramIsoPair X).symm⟩
intro X₁ X₂
have : HasBinaryBiproduct (F.obj X₁) (F.obj X₂) := HasBinaryBiproducts.has_binary_biproduct _ _
have : Mono (F.biprodComparison X₁ X₂) := by
rw [mono_iff_cancel_zero]
intro Z f hf
let S := (ShortComplex.mk _ _ (biprod.inl_snd (X := X₁) (Y := X₂))).map F
have : Mono S.f := by dsimp [S]; infer_instance
have ex : S.Exact := F.map_distinguished_exact _ (binaryBiproductTriangle_distinguished X₁ X₂)
obtain ⟨g, rfl⟩ := ex.lift' f (by simpa using hf =≫ biprod.snd)
dsimp [S] at hf ⊢
replace hf := hf =≫ biprod.fst
simp only [assoc, biprodComparison_fst, zero_comp, ← F.map_comp, biprod.inl_fst,
F.map_id, comp_id] at hf
rw [hf, zero_comp]
have : PreservesBinaryBiproduct X₁ X₂ F := preservesBinaryBiproduct_of_mono_biprodComparison _
apply Limits.preservesBinaryProduct_of_preservesBinaryBiproduct
instance (priority := 100) [F.IsHomological] : F.Additive :=
F.additive_of_preserves_binary_products
lemma isHomological_of_localization (L : C ⥤ D)
[L.CommShift ℤ] [L.IsTriangulated] [L.mapArrow.EssSurj] (F : D ⥤ A)
(G : C ⥤ A) (e : L ⋙ F ≅ G) [G.IsHomological] :
F.IsHomological := by
have : F.PreservesZeroMorphisms := preservesZeroMorphisms_of_map_zero_object
(F.mapIso L.mapZeroObject.symm ≪≫ e.app _ ≪≫ G.mapZeroObject)
have : (L ⋙ F).IsHomological := IsHomological.of_iso e.symm
refine IsHomological.mk' _ (fun T hT => ?_)
rw [L.distTriang_iff] at hT
obtain ⟨T₀, e, hT₀⟩ := hT
exact ⟨L.mapTriangle.obj T₀, e, (L ⋙ F).map_distinguished_exact _ hT₀⟩
end Pretriangulated
section
/-- The connecting homomorphism in the long exact sequence attached to an homological
functor and a distinguished triangle. -/
noncomputable def homologySequenceδ
[F.ShiftSequence ℤ] (T : Triangle C) (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) :
(F.shift n₀).obj T.obj₃ ⟶ (F.shift n₁).obj T.obj₁ :=
F.shiftMap T.mor₃ n₀ n₁ (by rw [add_comm 1, h])
variable {T T'}
@[reassoc]
lemma homologySequenceδ_naturality
[F.ShiftSequence ℤ] (T T' : Triangle C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁) :
(F.shift n₀).map φ.hom₃ ≫ F.homologySequenceδ T' n₀ n₁ h =
F.homologySequenceδ T n₀ n₁ h ≫ (F.shift n₁).map φ.hom₁ := by
dsimp only [homologySequenceδ]
rw [← shiftMap_comp', ← φ.comm₃, shiftMap_comp]
variable (T)
variable [HasZeroObject C] [Preadditive C] [∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive]
[Pretriangulated C] [Abelian A] [F.IsHomological]
variable [F.ShiftSequence ℤ] (T T' : Triangle C) (hT : T ∈ distTriang C)
(hT' : T' ∈ distTriang C) (φ : T ⟶ T') (n₀ n₁ : ℤ) (h : n₀ + 1 = n₁)
section
include hT
@[reassoc]
lemma comp_homologySequenceδ :
(F.shift n₀).map T.mor₂ ≫ F.homologySequenceδ T n₀ n₁ h = 0 := by
dsimp only [homologySequenceδ]
rw [← F.shiftMap_comp', comp_distTriang_mor_zero₂₃ _ hT, shiftMap_zero]
@[reassoc]
lemma homologySequenceδ_comp :
F.homologySequenceδ T n₀ n₁ h ≫ (F.shift n₁).map T.mor₁ = 0 := by
dsimp only [homologySequenceδ]
rw [← F.shiftMap_comp, comp_distTriang_mor_zero₃₁ _ hT, shiftMap_zero]
@[reassoc]
lemma homologySequence_comp :
(F.shift n₀).map T.mor₁ ≫ (F.shift n₀).map T.mor₂ = 0 := by
rw [← Functor.map_comp, comp_distTriang_mor_zero₁₂ _ hT, Functor.map_zero]
attribute [local simp] smul_smul
lemma homologySequence_exact₂ :
(ShortComplex.mk _ _ (F.homologySequence_comp T hT n₀)).Exact := by
refine ShortComplex.exact_of_iso ?_ (F.map_distinguished_exact _
(Triangle.shift_distinguished _ hT n₀))
exact ShortComplex.isoMk ((F.isoShift n₀).app _)
(n₀.negOnePow • ((F.isoShift n₀).app _)) ((F.isoShift n₀).app _)
(by simp) (by simp)
lemma homologySequence_exact₃ :
(ShortComplex.mk _ _ (F.comp_homologySequenceδ T hT _ _ h)).Exact := by
refine ShortComplex.exact_of_iso ?_ (F.homologySequence_exact₂ _ (rot_of_distTriang _ hT) n₀)
exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _)
((F.shiftIso 1 n₀ n₁ (by omega)).app _) (by simp) (by simp [homologySequenceδ, shiftMap])
lemma homologySequence_exact₁ :
(ShortComplex.mk _ _ (F.homologySequenceδ_comp T hT _ _ h)).Exact := by
refine ShortComplex.exact_of_iso ?_ (F.homologySequence_exact₂ _ (inv_rot_of_distTriang _ hT) n₁)
refine ShortComplex.isoMk (-((F.shiftIso (-1) n₁ n₀ (by omega)).app _))
(Iso.refl _) (Iso.refl _) ?_ (by simp)
dsimp
simp only [homologySequenceδ, neg_comp, map_neg, comp_id,
F.shiftIso_hom_app_comp_shiftMap_of_add_eq_zero T.mor₃ (-1) (neg_add_cancel 1) n₀ n₁ (by omega)]
lemma homologySequence_epi_shift_map_mor₁_iff :
Epi ((F.shift n₀).map T.mor₁) ↔ (F.shift n₀).map T.mor₂ = 0 :=
(F.homologySequence_exact₂ T hT n₀).epi_f_iff
lemma homologySequence_mono_shift_map_mor₁_iff :
Mono ((F.shift n₁).map T.mor₁) ↔ F.homologySequenceδ T n₀ n₁ h = 0 :=
(F.homologySequence_exact₁ T hT n₀ n₁ h).mono_g_iff
lemma homologySequence_epi_shift_map_mor₂_iff :
Epi ((F.shift n₀).map T.mor₂) ↔ F.homologySequenceδ T n₀ n₁ h = 0 :=
(F.homologySequence_exact₃ T hT n₀ n₁ h).epi_f_iff
lemma homologySequence_mono_shift_map_mor₂_iff :
Mono ((F.shift n₀).map T.mor₂) ↔ (F.shift n₀).map T.mor₁ = 0 :=
(F.homologySequence_exact₂ T hT n₀).mono_g_iff
end
lemma mem_homologicalKernel_trW_iff {X Y : C} (f : X ⟶ Y) :
F.homologicalKernel.trW f ↔ ∀ (n : ℤ), IsIso ((F.shift n).map f) := by
obtain ⟨Z, g, h, hT⟩ := distinguished_cocone_triangle f
apply (F.homologicalKernel.trW_iff_of_distinguished _ hT).trans
have h₁ := fun n => (F.homologySequence_exact₃ _ hT n _ rfl).isZero_X₂_iff
have h₂ := fun n => F.homologySequence_mono_shift_map_mor₁_iff _ hT n _ rfl
have h₃ := fun n => F.homologySequence_epi_shift_map_mor₁_iff _ hT n
dsimp at h₁ h₂ h₃ ⊢
simp only [mem_homologicalKernel_iff, h₁, ← h₂, ← h₃]
constructor
· intro h n
obtain ⟨m, rfl⟩ : ∃ (m : ℤ), n = m + 1 := ⟨n - 1, by simp⟩
have := (h (m + 1)).1
have := (h m).2
apply isIso_of_mono_of_epi
· intros
constructor <;> infer_instance
@[deprecated (since := "2025-07-21")]
alias mem_homologicalKernel_W_iff := mem_homologicalKernel_trW_iff
open ComposableArrows
/-- The exact sequence with six terms starting from `(F.shift n₀).obj T.obj₁` until
`(F.shift n₁).obj T.obj₃` when `T` is a distinguished triangle and `F` a homological functor. -/
@[simp] noncomputable def homologySequenceComposableArrows₅ : ComposableArrows A 5 :=
mk₅ ((F.shift n₀).map T.mor₁) ((F.shift n₀).map T.mor₂)
(F.homologySequenceδ T n₀ n₁ h) ((F.shift n₁).map T.mor₁) ((F.shift n₁).map T.mor₂)
include hT in
lemma homologySequenceComposableArrows₅_exact :
(F.homologySequenceComposableArrows₅ T n₀ n₁ h).Exact :=
exact_of_δ₀ (F.homologySequence_exact₂ T hT n₀).exact_toComposableArrows
(exact_of_δ₀ (F.homologySequence_exact₃ T hT n₀ n₁ h).exact_toComposableArrows
(exact_of_δ₀ (F.homologySequence_exact₁ T hT n₀ n₁ h).exact_toComposableArrows
(F.homologySequence_exact₂ T hT n₁).exact_toComposableArrows))
end
end Functor
end CategoryTheory
|
Evaluation.lean
|
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Functor.EpiMono
/-!
# Adjunctions involving evaluation
We show that evaluation of functors have adjoints, given the existence of (co)products.
-/
namespace CategoryTheory
open CategoryTheory.Limits
universe v₁ v₂ v₃ u₁ u₂ u₃
variable {C : Type u₁} [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D]
noncomputable section
section
variable [∀ a b : C, HasCoproductsOfShape (a ⟶ b) D]
/-- The left adjoint of evaluation. -/
@[simps]
def evaluationLeftAdjoint (c : C) : D ⥤ C ⥤ D where
obj d :=
{ obj := fun t => ∐ fun _ : c ⟶ t => d
map := fun f => Sigma.desc fun g => (Sigma.ι fun _ => d) <| g ≫ f}
map {_ d₂} f :=
{ app := fun _ => Sigma.desc fun h => f ≫ Sigma.ι (fun _ => d₂) h
naturality := by
intros
dsimp
ext
simp }
/-- The adjunction showing that evaluation is a right adjoint. -/
@[simps! unit_app counit_app_app]
def evaluationAdjunctionRight (c : C) : evaluationLeftAdjoint D c ⊣ (evaluation _ _).obj c :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun d F =>
{ toFun := fun f => Sigma.ι (fun _ => d) (𝟙 _) ≫ f.app c
invFun := fun f =>
{ app := fun _ => Sigma.desc fun h => f ≫ F.map h
naturality := by
intros
dsimp
ext
simp }
left_inv := by
intro f
ext x
dsimp
ext g
simp only [colimit.ι_desc, Cofan.mk_ι_app, Category.assoc, ← f.naturality,
evaluationLeftAdjoint_obj_map, colimit.ι_desc_assoc,
Discrete.functor_obj, Cofan.mk_pt, Category.id_comp]
right_inv := fun f => by
simp }
-- This used to be automatic before https://github.com/leanprover/lean4/pull/2644
homEquiv_naturality_right := by intros; simp }
instance evaluationIsRightAdjoint (c : C) : ((evaluation _ D).obj c).IsRightAdjoint :=
⟨_, ⟨evaluationAdjunctionRight _ _⟩⟩
/-- See also the file `CategoryTheory.Limits.FunctorCategory.EpiMono`
for a similar result under a `HasPullbacks` assumption. -/
theorem NatTrans.mono_iff_mono_app' {F G : C ⥤ D} (η : F ⟶ G) : Mono η ↔ ∀ c, Mono (η.app c) := by
constructor
· intro h c
exact (inferInstance : Mono (((evaluation _ _).obj c).map η))
· intro _
apply NatTrans.mono_of_mono_app
end
section
variable [∀ a b : C, HasProductsOfShape (a ⟶ b) D]
/-- The right adjoint of evaluation. -/
@[simps]
def evaluationRightAdjoint (c : C) : D ⥤ C ⥤ D where
obj d :=
{ obj := fun t => ∏ᶜ fun _ : t ⟶ c => d
map := fun f => Pi.lift fun g => Pi.π _ <| f ≫ g }
map f :=
{ app := fun _ => Pi.lift fun g => Pi.π _ g ≫ f
naturality := by
intros
dsimp
ext
simp }
/-- The adjunction showing that evaluation is a left adjoint. -/
@[simps! unit_app_app counit_app]
def evaluationAdjunctionLeft (c : C) : (evaluation _ _).obj c ⊣ evaluationRightAdjoint D c :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun F d =>
{ toFun := fun f =>
{ app := fun _ => Pi.lift fun g => F.map g ≫ f
naturality := by
intros
dsimp
ext
simp }
invFun := fun f => f.app _ ≫ Pi.π _ (𝟙 _)
left_inv := fun f => by simp
right_inv := by
intro f
ext x
dsimp
ext g
simp only [NatTrans.naturality_assoc,
evaluationRightAdjoint_obj_obj, evaluationRightAdjoint_obj_map, limit.lift_π,
Fan.mk_pt, Fan.mk_π_app, Category.comp_id] } }
instance evaluationIsLeftAdjoint (c : C) : ((evaluation _ D).obj c).IsLeftAdjoint :=
⟨_, ⟨evaluationAdjunctionLeft _ _⟩⟩
/-- See also the file `CategoryTheory.Limits.FunctorCategory.EpiMono`
for a similar result under a `HasPushouts` assumption. -/
theorem NatTrans.epi_iff_epi_app' {F G : C ⥤ D} (η : F ⟶ G) : Epi η ↔ ∀ c, Epi (η.app c) := by
constructor
· intro h c
exact (inferInstance : Epi (((evaluation _ _).obj c).map η))
· intros
apply NatTrans.epi_of_epi_app
end
end
end CategoryTheory
|
Imo2008Q2.lean
|
/-
Copyright (c) 2021 Manuel Candales. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Manuel Candales
-/
import Mathlib.Data.Real.Basic
import Mathlib.Data.Set.Finite.Lattice
import Mathlib.Tactic.Abel
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
/-!
# IMO 2008 Q2
(a) Prove that
```
x^2 / (x-1)^2 + y^2 / (y-1)^2 + z^2 / (z-1)^2 ≥ 1
```
for all real numbers `x`,`y`, `z`, each different from 1, and satisfying `xyz = 1`.
(b) Prove that equality holds above for infinitely many triples of rational numbers `x`, `y`, `z`,
each different from 1, and satisfying `xyz = 1`.
# Solution
(a) Since `xyz = 1`, we can apply the substitution `x = a/b`, `y = b/c`, `z = c/a`.
Then we define `m = c-b`, `n = b-a` and rewrite the inequality as `LHS - 1 ≥ 0`
using `c`, `m` and `n`. We factor `LHS - 1` as a square, which finishes the proof.
(b) We present a set `W` of rational triples. We prove that `W` is a subset of the
set of rational solutions to the equation, and that `W` is infinite.
-/
namespace Imo2008Q2
theorem subst_abc {x y z : ℝ} (h : x * y * z = 1) :
∃ a b c : ℝ, a ≠ 0 ∧ b ≠ 0 ∧ c ≠ 0 ∧ x = a / b ∧ y = b / c ∧ z = c / a := by
use x, 1, 1 / y
obtain ⟨⟨hx, hy⟩, _⟩ : (x ≠ 0 ∧ y ≠ 0) ∧ z ≠ 0 := by
have := h.symm ▸ one_ne_zero
simpa [not_or] using this
have : z * (y * x) = 1 := by rw [← h]; ac_rfl
field_simp [*]
theorem imo2008_q2a (x y z : ℝ) (h : x * y * z = 1) (hx : x ≠ 1) (hy : y ≠ 1) (hz : z ≠ 1) :
x ^ 2 / (x - 1) ^ 2 + y ^ 2 / (y - 1) ^ 2 + z ^ 2 / (z - 1) ^ 2 ≥ 1 := by
obtain ⟨a, b, c, ha, hb, hc, rfl, rfl, rfl⟩ := subst_abc h
obtain ⟨m, n, rfl, rfl⟩ : ∃ m n, b = c - m ∧ a = c - m - n := by use c - b, b - a; simp
have hm_ne_zero : m ≠ 0 := by contrapose! hy; field_simp; assumption
have hn_ne_zero : n ≠ 0 := by contrapose! hx; field_simp; assumption
have hmn_ne_zero : m + n ≠ 0 := by contrapose! hz; field_simp; linarith
have hc_sub_sub : c - (c - m - n) = m + n := by abel
rw [ge_iff_le, ← sub_nonneg]
convert sq_nonneg ((c * (m ^ 2 + n ^ 2 + m * n) - m * (m + n) ^ 2) / (m * n * (m + n)))
field_simp [hc_sub_sub]; ring
def rationalSolutions :=
{s : ℚ × ℚ × ℚ | ∃ x y z : ℚ, s = (x, y, z) ∧ x ≠ 1 ∧ y ≠ 1 ∧ z ≠ 1 ∧ x * y * z = 1 ∧
x ^ 2 / (x - 1) ^ 2 + y ^ 2 / (y - 1) ^ 2 + z ^ 2 / (z - 1) ^ 2 = 1}
theorem imo2008_q2b : Set.Infinite rationalSolutions := by
let W := {s : ℚ × ℚ × ℚ | ∃ x y z : ℚ, s = (x, y, z) ∧
∃ t : ℚ, t > 0 ∧ x = -(t + 1) / t ^ 2 ∧ y = t / (t + 1) ^ 2 ∧ z = -t * (t + 1)}
have hW_sub_S : W ⊆ rationalSolutions := by
intro s hs_in_W
rw [rationalSolutions]
simp only [Set.mem_setOf_eq] at hs_in_W ⊢
rcases hs_in_W with ⟨x, y, z, h₁, t, ht_gt_zero, hx_t, hy_t, hz_t⟩
use x, y, z
have key_gt_zero : t ^ 2 + t + 1 > 0 := by linarith [pow_pos ht_gt_zero 2, ht_gt_zero]
have h₂ : x ≠ 1 := by rw [hx_t]; field_simp; linarith [key_gt_zero]
have h₃ : y ≠ 1 := by rw [hy_t]; field_simp; linarith [key_gt_zero]
have h₄ : z ≠ 1 := by rw [hz_t]; linarith [key_gt_zero]
have h₅ : x * y * z = 1 := by rw [hx_t, hy_t, hz_t]; field_simp; ring
have h₆ : x ^ 2 / (x - 1) ^ 2 + y ^ 2 / (y - 1) ^ 2 + z ^ 2 / (z - 1) ^ 2 = 1 := by
have hx1 : (x - 1) ^ 2 = (t ^ 2 + t + 1) ^ 2 / t ^ 4 := by
field_simp; rw [hx_t]; field_simp; ring
have hy1 : (y - 1) ^ 2 = (t ^ 2 + t + 1) ^ 2 / (t + 1) ^ 4 := by
field_simp; rw [hy_t]; field_simp; ring
have hz1 : (z - 1) ^ 2 = (t ^ 2 + t + 1) ^ 2 := by rw [hz_t]; ring
calc
x ^ 2 / (x - 1) ^ 2 + y ^ 2 / (y - 1) ^ 2 + z ^ 2 / (z - 1) ^ 2 =
(x ^ 2 * t ^ 4 + y ^ 2 * (t + 1) ^ 4 + z ^ 2) / (t ^ 2 + t + 1) ^ 2 := by
rw [hx1, hy1, hz1]; field_simp
_ = 1 := by rw [hx_t, hy_t, hz_t]; field_simp; ring
exact ⟨h₁, h₂, h₃, h₄, h₅, h₆⟩
have hW_inf : Set.Infinite W := by
let g : ℚ × ℚ × ℚ → ℚ := fun s => -s.2.2
let K := g '' W
have hK_not_bdd : ¬BddAbove K := by
rw [not_bddAbove_iff]
intro q
let t : ℚ := max (q + 1) 1
use t * (t + 1)
have h₁ : t * (t + 1) ∈ K := by
let x : ℚ := -(t + 1) / t ^ 2
let y : ℚ := t / (t + 1) ^ 2
set z : ℚ := -t * (t + 1) with hz_def
simp only [t, W, K, g, Set.mem_image, Prod.exists]
use x, y, z; constructor
· simp only [Set.mem_setOf_eq]
use x, y, z; constructor
· rfl
· use t; constructor
· simp only [t, gt_iff_lt, lt_max_iff]; right; trivial
exact ⟨rfl, rfl, rfl⟩
· have hg : -z = g (x, y, z) := rfl
rw [hg, hz_def]; ring
have h₂ : q < t * (t + 1) := by linarith [sq_nonneg t, le_max_left (q + 1) 1]
exact ⟨h₁, h₂⟩
have hK_inf : Set.Infinite K := by intro h; apply hK_not_bdd; exact Set.Finite.bddAbove h
exact hK_inf.of_image g
exact hW_inf.mono hW_sub_S
end Imo2008Q2
|
Defs.lean
|
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Preimage
import Mathlib.Data.Finset.Prod
import Mathlib.Order.Hom.WithTopBot
import Mathlib.Order.Interval.Set.UnorderedInterval
/-!
# Locally finite orders
This file defines locally finite orders.
A locally finite order is an order for which all bounded intervals are finite. This allows to make
sense of `Icc`/`Ico`/`Ioc`/`Ioo` as lists, multisets, or finsets.
Further, if the order is bounded above (resp. below), then we can also make sense of the
"unbounded" intervals `Ici`/`Ioi` (resp. `Iic`/`Iio`).
Many theorems about these intervals can be found in `Mathlib/Order/Interval/Finset/Basic.lean`.
## Examples
Naturally occurring locally finite orders are `ℕ`, `ℤ`, `ℕ+`, `Fin n`, `α × β` the product of two
locally finite orders, `α →₀ β` the finitely supported functions to a locally finite order `β`...
## Main declarations
In a `LocallyFiniteOrder`,
* `Finset.Icc`: Closed-closed interval as a finset.
* `Finset.Ico`: Closed-open interval as a finset.
* `Finset.Ioc`: Open-closed interval as a finset.
* `Finset.Ioo`: Open-open interval as a finset.
* `Finset.uIcc`: Unordered closed interval as a finset.
In a `LocallyFiniteOrderTop`,
* `Finset.Ici`: Closed-infinite interval as a finset.
* `Finset.Ioi`: Open-infinite interval as a finset.
In a `LocallyFiniteOrderBot`,
* `Finset.Iic`: Infinite-open interval as a finset.
* `Finset.Iio`: Infinite-closed interval as a finset.
## Instances
A `LocallyFiniteOrder` instance can be built
* for a subtype of a locally finite order. See `Subtype.locallyFiniteOrder`.
* for the product of two locally finite orders. See `Prod.locallyFiniteOrder`.
* for any fintype (but not as an instance). See `Fintype.toLocallyFiniteOrder`.
* from a definition of `Finset.Icc` alone. See `LocallyFiniteOrder.ofIcc`.
* by pulling back `LocallyFiniteOrder β` through an order embedding `f : α →o β`. See
`OrderEmbedding.locallyFiniteOrder`.
Instances for concrete types are proved in their respective files:
* `ℕ` is in `Order.Interval.Finset.Nat`
* `ℤ` is in `Data.Int.Interval`
* `ℕ+` is in `Data.PNat.Interval`
* `Fin n` is in `Order.Interval.Finset.Fin`
* `Finset α` is in `Data.Finset.Interval`
* `Σ i, α i` is in `Data.Sigma.Interval`
Along, you will find lemmas about the cardinality of those finite intervals.
## TODO
Provide the `LocallyFiniteOrder` instance for `α ×ₗ β` where `LocallyFiniteOrder α` and
`Fintype β`.
Provide the `LocallyFiniteOrder` instance for `α →₀ β` where `β` is locally finite. Provide the
`LocallyFiniteOrder` instance for `Π₀ i, β i` where all the `β i` are locally finite.
From `LinearOrder α`, `NoMaxOrder α`, `LocallyFiniteOrder α`, we can also define an
order isomorphism `α ≃ ℕ` or `α ≃ ℤ`, depending on whether we have `OrderBot α` or
`NoMinOrder α` and `Nonempty α`. When `OrderBot α`, we can match `a : α` to `#(Iio a)`.
We can provide `SuccOrder α` from `LinearOrder α` and `LocallyFiniteOrder α` using
```lean
lemma exists_min_greater [LinearOrder α] [LocallyFiniteOrder α] {x ub : α} (hx : x < ub) :
∃ lub, x < lub ∧ ∀ y, x < y → lub ≤ y := by
-- very non golfed
have h : (Finset.Ioc x ub).Nonempty := ⟨ub, Finset.mem_Ioc.2 ⟨hx, le_rfl⟩⟩
use Finset.min' (Finset.Ioc x ub) h
constructor
· exact (Finset.mem_Ioc.mp <| Finset.min'_mem _ h).1
rintro y hxy
obtain hy | hy := le_total y ub
· refine Finset.min'_le (Ioc x ub) y ?_
simp [*] at *
· exact (Finset.min'_le _ _ (Finset.mem_Ioc.2 ⟨hx, le_rfl⟩)).trans hy
```
Note that the converse is not true. Consider `{-2^z | z : ℤ} ∪ {2^z | z : ℤ}`. Any element has a
successor (and actually a predecessor as well), so it is a `SuccOrder`, but it's not locally finite
as `Icc (-1) 1` is infinite.
-/
open Finset Function
/-- This is a mixin class describing a locally finite order,
that is, is an order where bounded intervals are finite.
When you don't care too much about definitional equality, you can use `LocallyFiniteOrder.ofIcc` or
`LocallyFiniteOrder.ofFiniteIcc` to build a locally finite order from just `Finset.Icc`. -/
class LocallyFiniteOrder (α : Type*) [Preorder α] where
/-- Left-closed right-closed interval -/
finsetIcc : α → α → Finset α
/-- Left-closed right-open interval -/
finsetIco : α → α → Finset α
/-- Left-open right-closed interval -/
finsetIoc : α → α → Finset α
/-- Left-open right-open interval -/
finsetIoo : α → α → Finset α
/-- `x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b` -/
finset_mem_Icc : ∀ a b x : α, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b
/-- `x ∈ finsetIco a b ↔ a ≤ x ∧ x < b` -/
finset_mem_Ico : ∀ a b x : α, x ∈ finsetIco a b ↔ a ≤ x ∧ x < b
/-- `x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b` -/
finset_mem_Ioc : ∀ a b x : α, x ∈ finsetIoc a b ↔ a < x ∧ x ≤ b
/-- `x ∈ finsetIoo a b ↔ a < x ∧ x < b` -/
finset_mem_Ioo : ∀ a b x : α, x ∈ finsetIoo a b ↔ a < x ∧ x < b
/-- This mixin class describes an order where all intervals bounded below are finite. This is
slightly weaker than `LocallyFiniteOrder` + `OrderTop` as it allows empty types. -/
class LocallyFiniteOrderTop (α : Type*) [Preorder α] where
/-- Left-open right-infinite interval -/
finsetIoi : α → Finset α
/-- Left-closed right-infinite interval -/
finsetIci : α → Finset α
/-- `x ∈ finsetIci a ↔ a ≤ x` -/
finset_mem_Ici : ∀ a x : α, x ∈ finsetIci a ↔ a ≤ x
/-- `x ∈ finsetIoi a ↔ a < x` -/
finset_mem_Ioi : ∀ a x : α, x ∈ finsetIoi a ↔ a < x
/-- This mixin class describes an order where all intervals bounded above are finite. This is
slightly weaker than `LocallyFiniteOrder` + `OrderBot` as it allows empty types. -/
class LocallyFiniteOrderBot (α : Type*) [Preorder α] where
/-- Left-infinite right-open interval -/
finsetIio : α → Finset α
/-- Left-infinite right-closed interval -/
finsetIic : α → Finset α
/-- `x ∈ finsetIic a ↔ x ≤ a` -/
finset_mem_Iic : ∀ a x : α, x ∈ finsetIic a ↔ x ≤ a
/-- `x ∈ finsetIio a ↔ x < a` -/
finset_mem_Iio : ∀ a x : α, x ∈ finsetIio a ↔ x < a
/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrder.ofIcc`, this one requires `DecidableLE` but
only `Preorder`. -/
def LocallyFiniteOrder.ofIcc' (α : Type*) [Preorder α] [DecidableLE α]
(finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) :
LocallyFiniteOrder α where
finsetIcc := finsetIcc
finsetIco a b := {x ∈ finsetIcc a b | ¬b ≤ x}
finsetIoc a b := {x ∈ finsetIcc a b | ¬x ≤ a}
finsetIoo a b := {x ∈ finsetIcc a b | ¬x ≤ a ∧ ¬b ≤ x}
finset_mem_Icc := mem_Icc
finset_mem_Ico a b x := by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_not_ge]
finset_mem_Ioc a b x := by rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_not_ge]
finset_mem_Ioo a b x := by
rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_not_ge, lt_iff_le_not_ge]
/-- A constructor from a definition of `Finset.Icc` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrder.ofIcc'`, this one requires `PartialOrder` but only
`DecidableEq`. -/
def LocallyFiniteOrder.ofIcc (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIcc : α → α → Finset α) (mem_Icc : ∀ a b x, x ∈ finsetIcc a b ↔ a ≤ x ∧ x ≤ b) :
LocallyFiniteOrder α where
finsetIcc := finsetIcc
finsetIco a b := {x ∈ finsetIcc a b | x ≠ b}
finsetIoc a b := {x ∈ finsetIcc a b | a ≠ x}
finsetIoo a b := {x ∈ finsetIcc a b | a ≠ x ∧ x ≠ b}
finset_mem_Icc := mem_Icc
finset_mem_Ico a b x := by rw [Finset.mem_filter, mem_Icc, and_assoc, lt_iff_le_and_ne]
finset_mem_Ioc a b x := by rw [Finset.mem_filter, mem_Icc, and_right_comm, lt_iff_le_and_ne]
finset_mem_Ioo a b x := by
rw [Finset.mem_filter, mem_Icc, and_and_and_comm, lt_iff_le_and_ne, lt_iff_le_and_ne]
/-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderTop.ofIci`, this one requires `DecidableLE` but
only `Preorder`. -/
def LocallyFiniteOrderTop.ofIci' (α : Type*) [Preorder α] [DecidableLE α]
(finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) :
LocallyFiniteOrderTop α where
finsetIci := finsetIci
finsetIoi a := {x ∈ finsetIci a | ¬x ≤ a}
finset_mem_Ici := mem_Ici
finset_mem_Ioi a x := by rw [mem_filter, mem_Ici, lt_iff_le_not_ge]
/-- A constructor from a definition of `Finset.Ici` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderTop.ofIci'`, this one requires `PartialOrder` but
only `DecidableEq`. -/
def LocallyFiniteOrderTop.ofIci (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIci : α → Finset α) (mem_Ici : ∀ a x, x ∈ finsetIci a ↔ a ≤ x) :
LocallyFiniteOrderTop α where
finsetIci := finsetIci
finsetIoi a := {x ∈ finsetIci a | a ≠ x}
finset_mem_Ici := mem_Ici
finset_mem_Ioi a x := by rw [mem_filter, mem_Ici, lt_iff_le_and_ne]
/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderBot.ofIic`, this one requires `DecidableLE` but
only `Preorder`. -/
def LocallyFiniteOrderBot.ofIic' (α : Type*) [Preorder α] [DecidableLE α]
(finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) :
LocallyFiniteOrderBot α where
finsetIic := finsetIic
finsetIio a := {x ∈ finsetIic a | ¬a ≤ x}
finset_mem_Iic := mem_Iic
finset_mem_Iio a x := by rw [mem_filter, mem_Iic, lt_iff_le_not_ge]
/-- A constructor from a definition of `Finset.Iic` alone, the other ones being derived by removing
the ends. As opposed to `LocallyFiniteOrderBot.ofIic'`, this one requires `PartialOrder` but
only `DecidableEq`. -/
def LocallyFiniteOrderBot.ofIic (α : Type*) [PartialOrder α] [DecidableEq α]
(finsetIic : α → Finset α) (mem_Iic : ∀ a x, x ∈ finsetIic a ↔ x ≤ a) :
LocallyFiniteOrderBot α where
finsetIic := finsetIic
finsetIio a := {x ∈ finsetIic a | x ≠ a}
finset_mem_Iic := mem_Iic
finset_mem_Iio a x := by rw [mem_filter, mem_Iic, lt_iff_le_and_ne]
variable {α β : Type*}
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrder [Preorder α] [IsEmpty α] : LocallyFiniteOrder α where
finsetIcc := isEmptyElim
finsetIco := isEmptyElim
finsetIoc := isEmptyElim
finsetIoo := isEmptyElim
finset_mem_Icc := isEmptyElim
finset_mem_Ico := isEmptyElim
finset_mem_Ioc := isEmptyElim
finset_mem_Ioo := isEmptyElim
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrderTop [Preorder α] [IsEmpty α] :
LocallyFiniteOrderTop α where
finsetIci := isEmptyElim
finsetIoi := isEmptyElim
finset_mem_Ici := isEmptyElim
finset_mem_Ioi := isEmptyElim
-- See note [reducible non-instances]
/-- An empty type is locally finite.
This is not an instance as it would not be defeq to more specific instances. -/
protected abbrev IsEmpty.toLocallyFiniteOrderBot [Preorder α] [IsEmpty α] :
LocallyFiniteOrderBot α where
finsetIic := isEmptyElim
finsetIio := isEmptyElim
finset_mem_Iic := isEmptyElim
finset_mem_Iio := isEmptyElim
/-! ### Intervals as finsets -/
namespace Finset
section Preorder
variable [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] {a b x : α}
/-- The finset $[a, b]$ of elements `x` such that `a ≤ x` and `x ≤ b`. Basically `Set.Icc a b` as a
finset. -/
def Icc (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIcc a b
/-- The finset $[a, b)$ of elements `x` such that `a ≤ x` and `x < b`. Basically `Set.Ico a b` as a
finset. -/
def Ico (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIco a b
/-- The finset $(a, b]$ of elements `x` such that `a < x` and `x ≤ b`. Basically `Set.Ioc a b` as a
finset. -/
def Ioc (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIoc a b
/-- The finset $(a, b)$ of elements `x` such that `a < x` and `x < b`. Basically `Set.Ioo a b` as a
finset. -/
def Ioo (a b : α) : Finset α :=
LocallyFiniteOrder.finsetIoo a b
@[simp]
theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b :=
LocallyFiniteOrder.finset_mem_Icc a b x
@[simp]
theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b :=
LocallyFiniteOrder.finset_mem_Ico a b x
@[simp]
theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b :=
LocallyFiniteOrder.finset_mem_Ioc a b x
@[simp]
theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b :=
LocallyFiniteOrder.finset_mem_Ioo a b x
@[simp, norm_cast]
theorem coe_Icc (a b : α) : (Icc a b : Set α) = Set.Icc a b :=
Set.ext fun _ => mem_Icc
@[simp, norm_cast]
theorem coe_Ico (a b : α) : (Ico a b : Set α) = Set.Ico a b :=
Set.ext fun _ => mem_Ico
@[simp, norm_cast]
theorem coe_Ioc (a b : α) : (Ioc a b : Set α) = Set.Ioc a b :=
Set.ext fun _ => mem_Ioc
@[simp, norm_cast]
theorem coe_Ioo (a b : α) : (Ioo a b : Set α) = Set.Ioo a b :=
Set.ext fun _ => mem_Ioo
@[simp]
theorem _root_.Fintype.card_Icc (a b : α) [Fintype (Set.Icc a b)] :
Fintype.card (Set.Icc a b) = #(Icc a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ico (a b : α) [Fintype (Set.Ico a b)] :
Fintype.card (Set.Ico a b) = #(Ico a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ioc (a b : α) [Fintype (Set.Ioc a b)] :
Fintype.card (Set.Ioc a b) = #(Ioc a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ioo (a b : α) [Fintype (Set.Ioo a b)] :
Fintype.card (Set.Ioo a b) = #(Ioo a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] {a x : α}
/-- The finset $[a, ∞)$ of elements `x` such that `a ≤ x`. Basically `Set.Ici a` as a finset. -/
def Ici (a : α) : Finset α :=
LocallyFiniteOrderTop.finsetIci a
/-- The finset $(a, ∞)$ of elements `x` such that `a < x`. Basically `Set.Ioi a` as a finset. -/
def Ioi (a : α) : Finset α :=
LocallyFiniteOrderTop.finsetIoi a
@[simp]
theorem mem_Ici : x ∈ Ici a ↔ a ≤ x :=
LocallyFiniteOrderTop.finset_mem_Ici _ _
@[simp]
theorem mem_Ioi : x ∈ Ioi a ↔ a < x :=
LocallyFiniteOrderTop.finset_mem_Ioi _ _
@[simp, norm_cast]
theorem coe_Ici (a : α) : (Ici a : Set α) = Set.Ici a :=
Set.ext fun _ => mem_Ici
@[simp, norm_cast]
theorem coe_Ioi (a : α) : (Ioi a : Set α) = Set.Ioi a :=
Set.ext fun _ => mem_Ioi
@[simp]
theorem _root_.Fintype.card_Ici (a : α) [Fintype (Set.Ici a)] :
Fintype.card (Set.Ici a) = #(Ici a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Ioi (a : α) [Fintype (Set.Ioi a)] :
Fintype.card (Set.Ioi a) = #(Ioi a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] {a x : α}
/-- The finset $(-∞, b]$ of elements `x` such that `x ≤ b`. Basically `Set.Iic b` as a finset. -/
def Iic (b : α) : Finset α :=
LocallyFiniteOrderBot.finsetIic b
/-- The finset $(-∞, b)$ of elements `x` such that `x < b`. Basically `Set.Iio b` as a finset. -/
def Iio (b : α) : Finset α :=
LocallyFiniteOrderBot.finsetIio b
@[simp]
theorem mem_Iic : x ∈ Iic a ↔ x ≤ a :=
LocallyFiniteOrderBot.finset_mem_Iic _ _
@[simp]
theorem mem_Iio : x ∈ Iio a ↔ x < a :=
LocallyFiniteOrderBot.finset_mem_Iio _ _
@[simp, norm_cast]
theorem coe_Iic (a : α) : (Iic a : Set α) = Set.Iic a :=
Set.ext fun _ => mem_Iic
@[simp, norm_cast]
theorem coe_Iio (a : α) : (Iio a : Set α) = Set.Iio a :=
Set.ext fun _ => mem_Iio
@[simp]
theorem _root_.Fintype.card_Iic (a : α) [Fintype (Set.Iic a)] :
Fintype.card (Set.Iic a) = #(Iic a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
@[simp]
theorem _root_.Fintype.card_Iio (a : α) [Fintype (Set.Iio a)] :
Fintype.card (Set.Iio a) = #(Iio a) :=
Fintype.card_of_finset' _ fun _ ↦ by simp
end LocallyFiniteOrderBot
section OrderTop
variable [LocallyFiniteOrder α] [OrderTop α] {a x : α}
-- See note [lower priority instance]
instance (priority := 100) _root_.LocallyFiniteOrder.toLocallyFiniteOrderTop :
LocallyFiniteOrderTop α where
finsetIci b := Icc b ⊤
finsetIoi b := Ioc b ⊤
finset_mem_Ici a x := by rw [mem_Icc, and_iff_left le_top]
finset_mem_Ioi a x := by rw [mem_Ioc, and_iff_left le_top]
theorem Ici_eq_Icc (a : α) : Ici a = Icc a ⊤ :=
rfl
theorem Ioi_eq_Ioc (a : α) : Ioi a = Ioc a ⊤ :=
rfl
end OrderTop
section OrderBot
variable [OrderBot α] [LocallyFiniteOrder α] {b x : α}
-- See note [lower priority instance]
instance (priority := 100) _root_.LocallyFiniteOrder.toLocallyFiniteOrderBot :
LocallyFiniteOrderBot α where
finsetIic := Icc ⊥
finsetIio := Ico ⊥
finset_mem_Iic a x := by rw [mem_Icc, and_iff_right bot_le]
finset_mem_Iio a x := by rw [mem_Ico, and_iff_right bot_le]
theorem Iic_eq_Icc : Iic = Icc (⊥ : α) :=
rfl
theorem Iio_eq_Ico : Iio = Ico (⊥ : α) :=
rfl
end OrderBot
end Preorder
section Lattice
variable [Lattice α] [LocallyFiniteOrder α] {a b x : α}
/-- `Finset.uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included.
Note that we define it more generally in a lattice as `Finset.Icc (a ⊓ b) (a ⊔ b)`. In a
product type, `Finset.uIcc` corresponds to the bounding box of the two elements. -/
def uIcc (a b : α) : Finset α :=
Icc (a ⊓ b) (a ⊔ b)
@[inherit_doc]
scoped[FinsetInterval] notation "[[" a ", " b "]]" => Finset.uIcc a b
@[simp]
theorem mem_uIcc : x ∈ uIcc a b ↔ a ⊓ b ≤ x ∧ x ≤ a ⊔ b :=
mem_Icc
@[simp, norm_cast]
theorem coe_uIcc (a b : α) : (Finset.uIcc a b : Set α) = Set.uIcc a b :=
coe_Icc _ _
@[simp]
theorem _root_.Fintype.card_uIcc (a b : α) [Fintype (Set.uIcc a b)] :
Fintype.card (Set.uIcc a b) = #(uIcc a b) :=
Fintype.card_of_finset' _ fun _ ↦ by simp [Set.uIcc]
end Lattice
end Finset
namespace Mathlib.Meta
open Lean Elab Term Meta Batteries.ExtendedBinder
/-- Elaborate set builder notation for `Finset`.
* `{x ≤ a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Iic a)` if the expected type
is `Finset ?α`.
* `{x ≥ a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Ici a)` if the expected type
is `Finset ?α`.
* `{x < a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Iio a)` if the expected type
is `Finset ?α`.
* `{x > a | p x}` is elaborated as `Finset.filter (fun x ↦ p x) (Finset.Ioi a)` if the expected type
is `Finset ?α`.
See also
* `Data.Set.Defs` for the `Set` builder notation elaborator that this elaborator partly overrides.
* `Data.Finset.Basic` for the `Finset` builder notation elaborator partly overriding this one for
syntax of the form `{x ∈ s | p x}`.
* `Data.Fintype.Basic` for the `Finset` builder notation elaborator handling syntax of the form
`{x | p x}`, `{x : α | p x}`, `{x ∉ s | p x}`, `{x ≠ a | p x}`.
TODO: Write a delaborator
-/
@[term_elab setBuilder]
def elabFinsetBuilderIxx : TermElab
| `({ $x:ident ≤ $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Iic $a))) expectedType?
| `({ $x:ident ≥ $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Ici $a))) expectedType?
| `({ $x:ident < $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Iio $a))) expectedType?
| `({ $x:ident > $a | $p }), expectedType? => do
-- If the expected type is not known to be `Finset ?α`, give up.
unless ← knownToBeFinsetNotSet expectedType? do throwUnsupportedSyntax
elabTerm (← `(Finset.filter (fun $x:ident ↦ $p) (Finset.Ioi $a))) expectedType?
| _, _ => throwUnsupportedSyntax
end Mathlib.Meta
/-! ### Finiteness of `Set` intervals -/
namespace Set
section Preorder
variable [Preorder α] [LocallyFiniteOrder α] (a b : α)
instance instFintypeIcc : Fintype (Icc a b) := .ofFinset (Finset.Icc a b) fun _ => Finset.mem_Icc
instance instFintypeIco : Fintype (Ico a b) := .ofFinset (Finset.Ico a b) fun _ => Finset.mem_Ico
instance instFintypeIoc : Fintype (Ioc a b) := .ofFinset (Finset.Ioc a b) fun _ => Finset.mem_Ioc
instance instFintypeIoo : Fintype (Ioo a b) := .ofFinset (Finset.Ioo a b) fun _ => Finset.mem_Ioo
theorem finite_Icc : (Icc a b).Finite :=
(Icc a b).toFinite
theorem finite_Ico : (Ico a b).Finite :=
(Ico a b).toFinite
theorem finite_Ioc : (Ioc a b).Finite :=
(Ioc a b).toFinite
theorem finite_Ioo : (Ioo a b).Finite :=
(Ioo a b).toFinite
end Preorder
section OrderTop
variable [Preorder α] [LocallyFiniteOrderTop α] (a : α)
instance instFintypeIci : Fintype (Ici a) := .ofFinset (Finset.Ici a) fun _ => Finset.mem_Ici
instance instFintypeIoi : Fintype (Ioi a) := .ofFinset (Finset.Ioi a) fun _ => Finset.mem_Ioi
theorem finite_Ici : (Ici a).Finite :=
(Ici a).toFinite
theorem finite_Ioi : (Ioi a).Finite :=
(Ioi a).toFinite
end OrderTop
section OrderBot
variable [Preorder α] [LocallyFiniteOrderBot α] (b : α)
instance instFintypeIic : Fintype (Iic b) := .ofFinset (Finset.Iic b) fun _ => Finset.mem_Iic
instance instFintypeIio : Fintype (Iio b) := .ofFinset (Finset.Iio b) fun _ => Finset.mem_Iio
theorem finite_Iic : (Iic b).Finite :=
(Iic b).toFinite
theorem finite_Iio : (Iio b).Finite :=
(Iio b).toFinite
end OrderBot
section Lattice
variable [Lattice α] [LocallyFiniteOrder α] (a b : α)
instance fintypeUIcc : Fintype (uIcc a b) :=
Fintype.ofFinset (Finset.uIcc a b) fun _ => Finset.mem_uIcc
@[simp]
theorem finite_interval : (uIcc a b).Finite := (uIcc _ _).toFinite
end Lattice
end Set
/-! ### Instances -/
section Preorder
variable [Preorder α] [Preorder β]
/-- A noncomputable constructor from the finiteness of all closed intervals. -/
noncomputable def LocallyFiniteOrder.ofFiniteIcc (h : ∀ a b : α, (Set.Icc a b).Finite) :
LocallyFiniteOrder α :=
@LocallyFiniteOrder.ofIcc' α _ (Classical.decRel _) (fun a b => (h a b).toFinset) fun a b x => by
rw [Set.Finite.mem_toFinset, Set.mem_Icc]
/-- A fintype is a locally finite order.
This is not an instance as it would not be defeq to better instances such as
`Fin.locallyFiniteOrder`.
-/
abbrev Fintype.toLocallyFiniteOrder [Fintype α] [DecidableLT α] [DecidableLE α] :
LocallyFiniteOrder α where
finsetIcc a b := (Set.Icc a b).toFinset
finsetIco a b := (Set.Ico a b).toFinset
finsetIoc a b := (Set.Ioc a b).toFinset
finsetIoo a b := (Set.Ioo a b).toFinset
finset_mem_Icc a b x := by simp only [Set.mem_toFinset, Set.mem_Icc]
finset_mem_Ico a b x := by simp only [Set.mem_toFinset, Set.mem_Ico]
finset_mem_Ioc a b x := by simp only [Set.mem_toFinset, Set.mem_Ioc]
finset_mem_Ioo a b x := by simp only [Set.mem_toFinset, Set.mem_Ioo]
instance : Subsingleton (LocallyFiniteOrder α) :=
Subsingleton.intro fun h₀ h₁ => by
obtain ⟨h₀_finset_Icc, h₀_finset_Ico, h₀_finset_Ioc, h₀_finset_Ioo,
h₀_finset_mem_Icc, h₀_finset_mem_Ico, h₀_finset_mem_Ioc, h₀_finset_mem_Ioo⟩ := h₀
obtain ⟨h₁_finset_Icc, h₁_finset_Ico, h₁_finset_Ioc, h₁_finset_Ioo,
h₁_finset_mem_Icc, h₁_finset_mem_Ico, h₁_finset_mem_Ioc, h₁_finset_mem_Ioo⟩ := h₁
have hIcc : h₀_finset_Icc = h₁_finset_Icc := by
ext a b x
rw [h₀_finset_mem_Icc, h₁_finset_mem_Icc]
have hIco : h₀_finset_Ico = h₁_finset_Ico := by
ext a b x
rw [h₀_finset_mem_Ico, h₁_finset_mem_Ico]
have hIoc : h₀_finset_Ioc = h₁_finset_Ioc := by
ext a b x
rw [h₀_finset_mem_Ioc, h₁_finset_mem_Ioc]
have hIoo : h₀_finset_Ioo = h₁_finset_Ioo := by
ext a b x
rw [h₀_finset_mem_Ioo, h₁_finset_mem_Ioo]
simp_rw [hIcc, hIco, hIoc, hIoo]
instance : Subsingleton (LocallyFiniteOrderTop α) :=
Subsingleton.intro fun h₀ h₁ => by
obtain ⟨h₀_finset_Ioi, h₀_finset_Ici, h₀_finset_mem_Ici, h₀_finset_mem_Ioi⟩ := h₀
obtain ⟨h₁_finset_Ioi, h₁_finset_Ici, h₁_finset_mem_Ici, h₁_finset_mem_Ioi⟩ := h₁
have hIci : h₀_finset_Ici = h₁_finset_Ici := by
ext a b
rw [h₀_finset_mem_Ici, h₁_finset_mem_Ici]
have hIoi : h₀_finset_Ioi = h₁_finset_Ioi := by
ext a b
rw [h₀_finset_mem_Ioi, h₁_finset_mem_Ioi]
simp_rw [hIci, hIoi]
instance : Subsingleton (LocallyFiniteOrderBot α) :=
Subsingleton.intro fun h₀ h₁ => by
obtain ⟨h₀_finset_Iio, h₀_finset_Iic, h₀_finset_mem_Iic, h₀_finset_mem_Iio⟩ := h₀
obtain ⟨h₁_finset_Iio, h₁_finset_Iic, h₁_finset_mem_Iic, h₁_finset_mem_Iio⟩ := h₁
have hIic : h₀_finset_Iic = h₁_finset_Iic := by
ext a b
rw [h₀_finset_mem_Iic, h₁_finset_mem_Iic]
have hIio : h₀_finset_Iio = h₁_finset_Iio := by
ext a b
rw [h₀_finset_mem_Iio, h₁_finset_mem_Iio]
simp_rw [hIic, hIio]
-- Should this be called `LocallyFiniteOrder.lift`?
/-- Given an order embedding `α ↪o β`, pulls back the `LocallyFiniteOrder` on `β` to `α`. -/
protected noncomputable def OrderEmbedding.locallyFiniteOrder [LocallyFiniteOrder β] (f : α ↪o β) :
LocallyFiniteOrder α where
finsetIcc a b := (Icc (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIco a b := (Ico (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIoc a b := (Ioc (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finsetIoo a b := (Ioo (f a) (f b)).preimage f f.toEmbedding.injective.injOn
finset_mem_Icc a b x := by rw [mem_preimage, mem_Icc, f.le_iff_le, f.le_iff_le]
finset_mem_Ico a b x := by rw [mem_preimage, mem_Ico, f.le_iff_le, f.lt_iff_lt]
finset_mem_Ioc a b x := by rw [mem_preimage, mem_Ioc, f.lt_iff_lt, f.le_iff_le]
finset_mem_Ioo a b x := by rw [mem_preimage, mem_Ioo, f.lt_iff_lt, f.lt_iff_lt]
/-! ### `OrderDual` -/
open OrderDual
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] (a b : α)
/-- Note we define `Icc (toDual a) (toDual b)` as `Icc α _ _ b a` (which has type `Finset α` not
`Finset αᵒᵈ`!) instead of `(Icc b a).map toDual.toEmbedding` as this means the
following is defeq:
```
lemma this : (Icc (toDual (toDual a)) (toDual (toDual b)) :) = (Icc a b :) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrder : LocallyFiniteOrder αᵒᵈ where
finsetIcc a b := @Icc α _ _ (ofDual b) (ofDual a)
finsetIco a b := @Ioc α _ _ (ofDual b) (ofDual a)
finsetIoc a b := @Ico α _ _ (ofDual b) (ofDual a)
finsetIoo a b := @Ioo α _ _ (ofDual b) (ofDual a)
finset_mem_Icc _ _ _ := (mem_Icc (α := α)).trans and_comm
finset_mem_Ico _ _ _ := (mem_Ioc (α := α)).trans and_comm
finset_mem_Ioc _ _ _ := (mem_Ico (α := α)).trans and_comm
finset_mem_Ioo _ _ _ := (mem_Ioo (α := α)).trans and_comm
lemma Finset.Icc_orderDual_def (a b : αᵒᵈ) :
Icc a b = (Icc (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ico_orderDual_def (a b : αᵒᵈ) :
Ico a b = (Ioc (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ioc_orderDual_def (a b : αᵒᵈ) :
Ioc a b = (Ico (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ioo_orderDual_def (a b : αᵒᵈ) :
Ioo a b = (Ioo (ofDual b) (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Icc_toDual : Icc (toDual a) (toDual b) = (Icc b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ico_toDual : Ico (toDual a) (toDual b) = (Ioc b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioc_toDual : Ioc (toDual a) (toDual b) = (Ico b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioo_toDual : Ioo (toDual a) (toDual b) = (Ioo b a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Icc_ofDual (a b : αᵒᵈ) :
Icc (ofDual a) (ofDual b) = (Icc b a).map ofDual.toEmbedding := map_refl.symm
lemma Finset.Ico_ofDual (a b : αᵒᵈ) :
Ico (ofDual a) (ofDual b) = (Ioc b a).map ofDual.toEmbedding := map_refl.symm
lemma Finset.Ioc_ofDual (a b : αᵒᵈ) :
Ioc (ofDual a) (ofDual b) = (Ico b a).map ofDual.toEmbedding := map_refl.symm
lemma Finset.Ioo_ofDual (a b : αᵒᵈ) :
Ioo (ofDual a) (ofDual b) = (Ioo b a).map ofDual.toEmbedding := map_refl.symm
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α]
/-- Note we define `Iic (toDual a)` as `Ici a` (which has type `Finset α` not `Finset αᵒᵈ`!)
instead of `(Ici a).map toDual.toEmbedding` as this means the following is defeq:
```
lemma this : (Iic (toDual (toDual a)) :) = (Iic a :) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrderBot : LocallyFiniteOrderBot αᵒᵈ where
finsetIic a := @Ici α _ _ (ofDual a)
finsetIio a := @Ioi α _ _ (ofDual a)
finset_mem_Iic _ _ := mem_Ici (α := α)
finset_mem_Iio _ _ := mem_Ioi (α := α)
lemma Iic_orderDual_def (a : αᵒᵈ) : Iic a = (Ici (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Iio_orderDual_def (a : αᵒᵈ) : Iio a = (Ioi (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Iic_toDual (a : α) : Iic (toDual a) = (Ici a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Iio_toDual (a : α) : Iio (toDual a) = (Ioi a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ici_ofDual (a : αᵒᵈ) : Ici (ofDual a) = (Iic a).map ofDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioi_ofDual (a : αᵒᵈ) : Ioi (ofDual a) = (Iio a).map ofDual.toEmbedding :=
map_refl.symm
end LocallyFiniteOrderTop
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderBot α]
/-- Note we define `Ici (toDual a)` as `Iic a` (which has type `Finset α` not `Finset αᵒᵈ`!)
instead of `(Iic a).map toDual.toEmbedding` as this means the following is defeq:
```
lemma this : (Ici (toDual (toDual a)) :) = (Ici a :) := rfl
```
-/
instance OrderDual.instLocallyFiniteOrderTop : LocallyFiniteOrderTop αᵒᵈ where
finsetIci a := @Iic α _ _ (ofDual a)
finsetIoi a := @Iio α _ _ (ofDual a)
finset_mem_Ici _ _ := mem_Iic (α := α)
finset_mem_Ioi _ _ := mem_Iio (α := α)
lemma Ici_orderDual_def (a : αᵒᵈ) : Ici a = (Iic (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Ioi_orderDual_def (a : αᵒᵈ) : Ioi a = (Iio (ofDual a)).map toDual.toEmbedding := map_refl.symm
lemma Finset.Ici_toDual (a : α) : Ici (toDual a) = (Iic a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Ioi_toDual (a : α) : Ioi (toDual a) = (Iio a).map toDual.toEmbedding :=
map_refl.symm
lemma Finset.Iic_ofDual (a : αᵒᵈ) : Iic (ofDual a) = (Ici a).map ofDual.toEmbedding :=
map_refl.symm
lemma Finset.Iio_ofDual (a : αᵒᵈ) : Iio (ofDual a) = (Ioi a).map ofDual.toEmbedding :=
map_refl.symm
end LocallyFiniteOrderTop
/-! ### `Prod` -/
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)]
instance Prod.instLocallyFiniteOrder : LocallyFiniteOrder (α × β) :=
LocallyFiniteOrder.ofIcc' (α × β) (fun x y ↦ Icc x.1 y.1 ×ˢ Icc x.2 y.2) fun a b x => by
rw [mem_product, mem_Icc, mem_Icc, and_and_and_comm, le_def, le_def]
lemma Finset.Icc_prod_def (x y : α × β) : Icc x y = Icc x.1 y.1 ×ˢ Icc x.2 y.2 := rfl
lemma Finset.Icc_product_Icc (a₁ a₂ : α) (b₁ b₂ : β) :
Icc a₁ a₂ ×ˢ Icc b₁ b₂ = Icc (a₁, b₁) (a₂, b₂) := rfl
lemma Finset.card_Icc_prod (x y : α × β) : #(Icc x y) = #(Icc x.1 y.1) * #(Icc x.2 y.2) :=
card_product ..
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderTop β] [DecidableLE (α × β)]
instance Prod.instLocallyFiniteOrderTop : LocallyFiniteOrderTop (α × β) :=
LocallyFiniteOrderTop.ofIci' (α × β) (fun x => Ici x.1 ×ˢ Ici x.2) fun a x => by
rw [mem_product, mem_Ici, mem_Ici, le_def]
lemma Finset.Ici_prod_def (x : α × β) : Ici x = Ici x.1 ×ˢ Ici x.2 := rfl
lemma Finset.Ici_product_Ici (a : α) (b : β) : Ici a ×ˢ Ici b = Ici (a, b) := rfl
lemma Finset.card_Ici_prod (x : α × β) : #(Ici x) = #(Ici x.1) * #(Ici x.2) :=
card_product _ _
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] [LocallyFiniteOrderBot β] [DecidableLE (α × β)]
instance Prod.instLocallyFiniteOrderBot : LocallyFiniteOrderBot (α × β) :=
LocallyFiniteOrderBot.ofIic' (α × β) (fun x ↦ Iic x.1 ×ˢ Iic x.2) fun a x ↦ by
rw [mem_product, mem_Iic, mem_Iic, le_def]
lemma Finset.Iic_prod_def (x : α × β) : Iic x = Iic x.1 ×ˢ Iic x.2 := rfl
lemma Finset.Iic_product_Iic (a : α) (b : β) : Iic a ×ˢ Iic b = Iic (a, b) := rfl
lemma Finset.card_Iic_prod (x : α × β) : #(Iic x) = #(Iic x.1) * #(Iic x.2) := card_product ..
end LocallyFiniteOrderBot
end Preorder
section Lattice
variable [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)]
lemma Finset.uIcc_prod_def (x y : α × β) : uIcc x y = uIcc x.1 y.1 ×ˢ uIcc x.2 y.2 := rfl
lemma Finset.uIcc_product_uIcc (a₁ a₂ : α) (b₁ b₂ : β) :
uIcc a₁ a₂ ×ˢ uIcc b₁ b₂ = uIcc (a₁, b₁) (a₂, b₂) := rfl
lemma Finset.card_uIcc_prod (x y : α × β) : #(uIcc x y) = #(uIcc x.1 y.1) * #(uIcc x.2 y.2) :=
card_product ..
end Lattice
/-!
#### `WithTop`, `WithBot`
Adding a `⊤` to a locally finite `OrderTop` keeps it locally finite.
Adding a `⊥` to a locally finite `OrderBot` keeps it locally finite.
-/
namespace WithTop
/-- Given a finset on `α`, lift it to being a finset on `WithTop α`
using `WithTop.some` and then insert `⊤`. -/
def insertTop : Finset α ↪o Finset (WithTop α) :=
OrderEmbedding.ofMapLEIff
(fun s => cons ⊤ (s.map Embedding.coeWithTop) <| by simp)
(fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset])
@[simp]
theorem some_mem_insertTop {s : Finset α} {a : α} : ↑a ∈ insertTop s ↔ a ∈ s := by
simp [insertTop]
@[simp]
theorem top_mem_insertTop {s : Finset α} : ⊤ ∈ insertTop s := by
simp [insertTop]
variable (α) [PartialOrder α] [OrderTop α] [LocallyFiniteOrder α]
instance locallyFiniteOrder : LocallyFiniteOrder (WithTop α) where
finsetIcc a b :=
match a, b with
| ⊤, ⊤ => {⊤}
| ⊤, (b : α) => ∅
| (a : α), ⊤ => insertTop (Ici a)
| (a : α), (b : α) => (Icc a b).map Embedding.coeWithTop
finsetIco a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => (Ici a).map Embedding.coeWithTop
| (a : α), (b : α) => (Ico a b).map Embedding.coeWithTop
finsetIoc a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => insertTop (Ioi a)
| (a : α), (b : α) => (Ioc a b).map Embedding.coeWithTop
finsetIoo a b :=
match a, b with
| ⊤, _ => ∅
| (a : α), ⊤ => (Ioi a).map Embedding.coeWithTop
| (a : α), (b : α) => (Ioo a b).map Embedding.coeWithTop
finset_mem_Icc a b x := by
cases a <;> cases b <;> cases x <;> simp
finset_mem_Ico a b x := by
cases a <;> cases b <;> cases x <;> simp
finset_mem_Ioc a b x := by
cases a <;> cases b <;> cases x <;> simp
finset_mem_Ioo a b x := by
cases a <;> cases b <;> cases x <;> simp
variable (a b : α)
theorem Icc_coe_top : Icc (a : WithTop α) ⊤ = insertNone (Ici a) :=
rfl
theorem Icc_coe_coe : Icc (a : WithTop α) b = (Icc a b).map Embedding.some :=
rfl
theorem Ico_coe_top : Ico (a : WithTop α) ⊤ = (Ici a).map Embedding.some :=
rfl
theorem Ico_coe_coe : Ico (a : WithTop α) b = (Ico a b).map Embedding.some :=
rfl
theorem Ioc_coe_top : Ioc (a : WithTop α) ⊤ = insertNone (Ioi a) :=
rfl
theorem Ioc_coe_coe : Ioc (a : WithTop α) b = (Ioc a b).map Embedding.some :=
rfl
theorem Ioo_coe_top : Ioo (a : WithTop α) ⊤ = (Ioi a).map Embedding.some :=
rfl
theorem Ioo_coe_coe : Ioo (a : WithTop α) b = (Ioo a b).map Embedding.some :=
rfl
end WithTop
namespace WithBot
/-- Given a finset on `α`, lift it to being a finset on `WithBot α`
using `WithBot.some` and then insert `⊥`. -/
def insertBot : Finset α ↪o Finset (WithBot α) :=
OrderEmbedding.ofMapLEIff
(fun s => cons ⊥ (s.map Embedding.coeWithBot) <| by simp)
(fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset])
@[simp]
theorem some_mem_insertBot {s : Finset α} {a : α} : ↑a ∈ insertBot s ↔ a ∈ s := by
simp [insertBot]
@[simp]
theorem bot_mem_insertBot {s : Finset α} : ⊥ ∈ insertBot s := by
simp [insertBot]
variable (α) [PartialOrder α] [OrderBot α] [LocallyFiniteOrder α]
instance instLocallyFiniteOrder : LocallyFiniteOrder (WithBot α) :=
OrderDual.instLocallyFiniteOrder (α := WithTop αᵒᵈ)
variable (a b : α)
theorem Icc_bot_coe : Icc (⊥ : WithBot α) b = insertNone (Iic b) :=
rfl
theorem Icc_coe_coe : Icc (a : WithBot α) b = (Icc a b).map Embedding.some :=
rfl
theorem Ico_bot_coe : Ico (⊥ : WithBot α) b = insertNone (Iio b) :=
rfl
theorem Ico_coe_coe : Ico (a : WithBot α) b = (Ico a b).map Embedding.some :=
rfl
theorem Ioc_bot_coe : Ioc (⊥ : WithBot α) b = (Iic b).map Embedding.some :=
rfl
theorem Ioc_coe_coe : Ioc (a : WithBot α) b = (Ioc a b).map Embedding.some :=
rfl
theorem Ioo_bot_coe : Ioo (⊥ : WithBot α) b = (Iio b).map Embedding.some :=
rfl
theorem Ioo_coe_coe : Ioo (a : WithBot α) b = (Ioo a b).map Embedding.some :=
rfl
end WithBot
namespace OrderIso
variable [Preorder α] [Preorder β]
/-! #### Transfer locally finite orders across order isomorphisms -/
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrder` across an `OrderIso`. -/
abbrev locallyFiniteOrder [LocallyFiniteOrder β] (f : α ≃o β) : LocallyFiniteOrder α where
finsetIcc a b := (Icc (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIco a b := (Ico (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIoc a b := (Ioc (f a) (f b)).map f.symm.toEquiv.toEmbedding
finsetIoo a b := (Ioo (f a) (f b)).map f.symm.toEquiv.toEmbedding
finset_mem_Icc := by simp
finset_mem_Ico := by simp
finset_mem_Ioc := by simp
finset_mem_Ioo := by simp
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrderTop` across an `OrderIso`. -/
abbrev locallyFiniteOrderTop [LocallyFiniteOrderTop β] (f : α ≃o β) : LocallyFiniteOrderTop α where
finsetIci a := (Ici (f a)).map f.symm.toEquiv.toEmbedding
finsetIoi a := (Ioi (f a)).map f.symm.toEquiv.toEmbedding
finset_mem_Ici := by simp
finset_mem_Ioi := by simp
-- See note [reducible non-instances]
/-- Transfer `LocallyFiniteOrderBot` across an `OrderIso`. -/
abbrev locallyFiniteOrderBot [LocallyFiniteOrderBot β] (f : α ≃o β) : LocallyFiniteOrderBot α where
finsetIic a := (Iic (f a)).map f.symm.toEquiv.toEmbedding
finsetIio a := (Iio (f a)).map f.symm.toEquiv.toEmbedding
finset_mem_Iic := by simp
finset_mem_Iio := by simp
end OrderIso
/-! #### Subtype of a locally finite order -/
variable [Preorder α] (p : α → Prop) [DecidablePred p]
instance Subtype.instLocallyFiniteOrder [LocallyFiniteOrder α] :
LocallyFiniteOrder (Subtype p) where
finsetIcc a b := (Icc (a : α) b).subtype p
finsetIco a b := (Ico (a : α) b).subtype p
finsetIoc a b := (Ioc (a : α) b).subtype p
finsetIoo a b := (Ioo (a : α) b).subtype p
finset_mem_Icc a b x := by simp_rw [Finset.mem_subtype, mem_Icc, Subtype.coe_le_coe]
finset_mem_Ico a b x := by
simp_rw [Finset.mem_subtype, mem_Ico, Subtype.coe_le_coe, Subtype.coe_lt_coe]
finset_mem_Ioc a b x := by
simp_rw [Finset.mem_subtype, mem_Ioc, Subtype.coe_le_coe, Subtype.coe_lt_coe]
finset_mem_Ioo a b x := by simp_rw [Finset.mem_subtype, mem_Ioo, Subtype.coe_lt_coe]
instance Subtype.instLocallyFiniteOrderTop [LocallyFiniteOrderTop α] :
LocallyFiniteOrderTop (Subtype p) where
finsetIci a := (Ici (a : α)).subtype p
finsetIoi a := (Ioi (a : α)).subtype p
finset_mem_Ici a x := by simp_rw [Finset.mem_subtype, mem_Ici, Subtype.coe_le_coe]
finset_mem_Ioi a x := by simp_rw [Finset.mem_subtype, mem_Ioi, Subtype.coe_lt_coe]
instance Subtype.instLocallyFiniteOrderBot [LocallyFiniteOrderBot α] :
LocallyFiniteOrderBot (Subtype p) where
finsetIic a := (Iic (a : α)).subtype p
finsetIio a := (Iio (a : α)).subtype p
finset_mem_Iic a x := by simp_rw [Finset.mem_subtype, mem_Iic, Subtype.coe_le_coe]
finset_mem_Iio a x := by simp_rw [Finset.mem_subtype, mem_Iio, Subtype.coe_lt_coe]
namespace Finset
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] (a b : Subtype p)
theorem subtype_Icc_eq : Icc a b = (Icc (a : α) b).subtype p :=
rfl
theorem subtype_Ico_eq : Ico a b = (Ico (a : α) b).subtype p :=
rfl
theorem subtype_Ioc_eq : Ioc a b = (Ioc (a : α) b).subtype p :=
rfl
theorem subtype_Ioo_eq : Ioo a b = (Ioo (a : α) b).subtype p :=
rfl
theorem map_subtype_embedding_Icc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) :
(Icc a b).map (Embedding.subtype p) = (Icc a b : Finset α) := by
rw [subtype_Icc_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Icc] at hx
exact hp hx.1 hx.2 a.prop b.prop
theorem map_subtype_embedding_Ico (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) :
(Ico a b).map (Embedding.subtype p) = (Ico a b : Finset α) := by
rw [subtype_Ico_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ico] at hx
exact hp hx.1 hx.2.le a.prop b.prop
theorem map_subtype_embedding_Ioc (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) :
(Ioc a b).map (Embedding.subtype p) = (Ioc a b : Finset α) := by
rw [subtype_Ioc_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ioc] at hx
exact hp hx.1.le hx.2 a.prop b.prop
theorem map_subtype_embedding_Ioo (hp : ∀ ⦃a b x⦄, a ≤ x → x ≤ b → p a → p b → p x) :
(Ioo a b).map (Embedding.subtype p) = (Ioo a b : Finset α) := by
rw [subtype_Ioo_eq]
refine Finset.subtype_map_of_mem fun x hx => ?_
rw [mem_Ioo] at hx
exact hp hx.1.le hx.2.le a.prop b.prop
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α] (a : Subtype p)
theorem subtype_Ici_eq : Ici a = (Ici (a : α)).subtype p :=
rfl
theorem subtype_Ioi_eq : Ioi a = (Ioi (a : α)).subtype p :=
rfl
theorem map_subtype_embedding_Ici (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) :
(Ici a).map (Embedding.subtype p) = (Ici a : Finset α) := by
rw [subtype_Ici_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ici.1 hx) a.prop
theorem map_subtype_embedding_Ioi (hp : ∀ ⦃a x⦄, a ≤ x → p a → p x) :
(Ioi a).map (Embedding.subtype p) = (Ioi a : Finset α) := by
rw [subtype_Ioi_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Ioi.1 hx).le a.prop
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α] (a : Subtype p)
theorem subtype_Iic_eq : Iic a = (Iic (a : α)).subtype p :=
rfl
theorem subtype_Iio_eq : Iio a = (Iio (a : α)).subtype p :=
rfl
theorem map_subtype_embedding_Iic (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) :
(Iic a).map (Embedding.subtype p) = (Iic a : Finset α) := by
rw [subtype_Iic_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iic.1 hx) a.prop
theorem map_subtype_embedding_Iio (hp : ∀ ⦃a x⦄, x ≤ a → p a → p x) :
(Iio a).map (Embedding.subtype p) = (Iio a : Finset α) := by
rw [subtype_Iio_eq]
exact Finset.subtype_map_of_mem fun x hx => hp (mem_Iio.1 hx).le a.prop
end LocallyFiniteOrderBot
end Finset
section Finite
variable {α : Type*} {s : Set α}
theorem BddBelow.finite_of_bddAbove [Preorder α] [LocallyFiniteOrder α]
{s : Set α} (h₀ : BddBelow s) (h₁ : BddAbove s) :
s.Finite :=
let ⟨a, ha⟩ := h₀
let ⟨b, hb⟩ := h₁
(Set.finite_Icc a b).subset fun _x hx ↦ ⟨ha hx, hb hx⟩
theorem Set.finite_iff_bddAbove [SemilatticeSup α] [LocallyFiniteOrder α] [OrderBot α] :
s.Finite ↔ BddAbove s :=
⟨fun h ↦ ⟨h.toFinset.sup id, fun _ hx ↦ Finset.le_sup (f := id) ((Finite.mem_toFinset h).mpr hx)⟩,
fun ⟨m, hm⟩ ↦ (Set.finite_Icc ⊥ m).subset (fun _ hx ↦ ⟨bot_le, hm hx⟩)⟩
theorem Set.finite_iff_bddBelow [SemilatticeInf α] [LocallyFiniteOrder α] [OrderTop α] :
s.Finite ↔ BddBelow s :=
finite_iff_bddAbove (α := αᵒᵈ)
theorem Set.finite_iff_bddBelow_bddAbove [Nonempty α] [Lattice α] [LocallyFiniteOrder α] :
s.Finite ↔ BddBelow s ∧ BddAbove s := by
obtain (rfl | hs) := s.eq_empty_or_nonempty
· simp only [Set.finite_empty, bddBelow_empty, bddAbove_empty, and_self]
exact ⟨fun h ↦ ⟨⟨h.toFinset.inf' ((Finite.toFinset_nonempty h).mpr hs) id,
fun x hx ↦ Finset.inf'_le id ((Finite.mem_toFinset h).mpr hx)⟩,
⟨h.toFinset.sup' ((Finite.toFinset_nonempty h).mpr hs) id, fun x hx ↦ Finset.le_sup' id
((Finite.mem_toFinset h).mpr hx)⟩⟩,
fun ⟨h₀, h₁⟩ ↦ BddBelow.finite_of_bddAbove h₀ h₁⟩
end Finite
/-! We make the instances below low priority
so when alternative constructions are available they are preferred. -/
variable {y : α}
instance (priority := low) [Preorder α] [DecidableLE α] [LocallyFiniteOrder α] :
LocallyFiniteOrderTop { x : α // x ≤ y } where
finsetIoi a := Finset.Ioc a ⟨y, by rfl⟩
finsetIci a := Finset.Icc a ⟨y, by rfl⟩
finset_mem_Ici a b := by
simp only [Finset.mem_Icc, and_iff_left_iff_imp]
exact fun _ => b.property
finset_mem_Ioi a b := by
simp only [Finset.mem_Ioc, and_iff_left_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableLT α] [LocallyFiniteOrder α] :
LocallyFiniteOrderTop { x : α // x < y } where
finsetIoi a := (Finset.Ioo ↑a y).subtype _
finsetIci a := (Finset.Ico ↑a y).subtype _
finset_mem_Ici a b := by
simp only [Finset.mem_subtype, Finset.mem_Ico, Subtype.coe_le_coe, and_iff_left_iff_imp]
exact fun _ => b.property
finset_mem_Ioi a b := by
simp only [Finset.mem_subtype, Finset.mem_Ioo, Subtype.coe_lt_coe, and_iff_left_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableLE α] [LocallyFiniteOrder α] :
LocallyFiniteOrderBot { x : α // y ≤ x } where
finsetIio a := Finset.Ico ⟨y, by rfl⟩ a
finsetIic a := Finset.Icc ⟨y, by rfl⟩ a
finset_mem_Iic a b := by
simp only [Finset.mem_Icc, and_iff_right_iff_imp]
exact fun _ => b.property
finset_mem_Iio a b := by
simp only [Finset.mem_Ico, and_iff_right_iff_imp]
exact fun _ => b.property
instance (priority := low) [Preorder α] [DecidableLT α] [LocallyFiniteOrder α] :
LocallyFiniteOrderBot { x : α // y < x } where
finsetIio a := (Finset.Ioo y ↑a).subtype _
finsetIic a := (Finset.Ioc y ↑a).subtype _
finset_mem_Iic a b := by
simp only [Finset.mem_subtype, Finset.mem_Ioc, Subtype.coe_le_coe, and_iff_right_iff_imp]
exact fun _ => b.property
finset_mem_Iio a b := by
simp only [Finset.mem_subtype, Finset.mem_Ioo, Subtype.coe_lt_coe, and_iff_right_iff_imp]
exact fun _ => b.property
instance [Preorder α] [LocallyFiniteOrderBot α] : Finite { x : α // x ≤ y } := by
simpa only [coe_Iic] using (Finset.Iic y).finite_toSet
instance [Preorder α] [LocallyFiniteOrderBot α] : Finite { x : α // x < y } := by
simpa only [coe_Iio] using (Finset.Iio y).finite_toSet
instance [Preorder α] [LocallyFiniteOrderTop α] : Finite { x : α // y ≤ x } := by
simpa only [coe_Ici] using (Finset.Ici y).finite_toSet
instance [Preorder α] [LocallyFiniteOrderTop α] : Finite { x : α // y < x } := by
simpa only [coe_Ioi] using (Finset.Ioi y).finite_toSet
namespace Set
variable {α : Type*} [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α]
@[simp] lemma toFinset_Icc (a b : α) [Fintype (Icc a b)] : (Icc a b).toFinset = Finset.Icc a b := by
ext; simp
@[simp] lemma toFinset_Ico (a b : α) [Fintype (Ico a b)] : (Ico a b).toFinset = Finset.Ico a b := by
ext; simp
@[simp] lemma toFinset_Ioc (a b : α) [Fintype (Ioc a b)] : (Ioc a b).toFinset = Finset.Ioc a b := by
ext; simp
@[simp] lemma toFinset_Ioo (a b : α) [Fintype (Ioo a b)] : (Ioo a b).toFinset = Finset.Ioo a b := by
ext; simp
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop α]
@[simp]
lemma toFinset_Ici (a : α) [Fintype (Ici a)] : (Ici a).toFinset = Finset.Ici a := by ext; simp
@[simp]
lemma toFinset_Ioi (a : α) [Fintype (Ioi a)] : (Ioi a).toFinset = Finset.Ioi a := by ext; simp
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot α]
@[simp]
lemma toFinset_Iic (a : α) [Fintype (Iic a)] : (Iic a).toFinset = Finset.Iic a := by ext; simp
@[simp]
lemma toFinset_Iio (a : α) [Fintype (Iio a)] : (Iio a).toFinset = Finset.Iio a := by ext; simp
end LocallyFiniteOrderBot
end Set
/-- A `LocallyFiniteOrder` can be transferred across an order isomorphism. -/
-- See note [reducible non instances]
abbrev LocallyFiniteOrder.ofOrderIsoClass {F M N : Type*} [Preorder M] [Preorder N]
[EquivLike F M N] [OrderIsoClass F M N] (f : F) [LocallyFiniteOrder N] :
LocallyFiniteOrder M where
finsetIcc x y := (finsetIcc (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩
finsetIco x y := (finsetIco (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩
finsetIoc x y := (finsetIoc (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩
finsetIoo x y := (finsetIoo (f x) (f y)).map ⟨EquivLike.inv f, (EquivLike.right_inv f).injective⟩
finset_mem_Icc := by simp [finset_mem_Icc, EquivLike.inv_apply_eq]
finset_mem_Ico := by
simp [finset_mem_Ico, EquivLike.inv_apply_eq, map_lt_map_iff]
finset_mem_Ioc := by
simp [finset_mem_Ioc, EquivLike.inv_apply_eq, map_lt_map_iff]
finset_mem_Ioo := by
simp [finset_mem_Ioo, EquivLike.inv_apply_eq, map_lt_map_iff]
|
VertexGroup.lean
|
/-
Copyright (c) 2022 Rémi Bottinelli. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémi Bottinelli
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.PathCategory.Basic
import Mathlib.Combinatorics.Quiver.Path
/-!
# Vertex group
This file defines the vertex group (*aka* isotropy group) of a groupoid at a vertex.
## Implementation notes
* The instance is defined "manually", instead of relying on `CategoryTheory.Aut.group` or
using `CategoryTheory.inv`.
* The multiplication order therefore matches the categorical one: `x * y = x ≫ y`.
* The inverse is directly defined in terms of the groupoidal inverse: `x ⁻¹ = Groupoid.inv x`.
## Tags
isotropy, vertex group, groupoid
-/
namespace CategoryTheory
namespace Groupoid
universe u v
variable {C : Type u} [Groupoid C]
/-- The vertex group at `c`. -/
@[simps mul one inv]
instance vertexGroup (c : C) : Group (c ⟶ c) where
mul := fun x y : c ⟶ c => x ≫ y
mul_assoc := Category.assoc
one := 𝟙 c
one_mul := Category.id_comp
mul_one := Category.comp_id
inv := Groupoid.inv
inv_mul_cancel := inv_comp
/-- The inverse in the group is equal to the inverse given by `CategoryTheory.inv`. -/
theorem vertexGroup.inv_eq_inv (c : C) (γ : c ⟶ c) : γ⁻¹ = CategoryTheory.inv γ :=
Groupoid.inv_eq_inv γ
/-- An arrow in the groupoid defines, by conjugation, an isomorphism of groups between
its endpoints.
-/
@[simps]
def vertexGroupIsomOfMap {c d : C} (f : c ⟶ d) : (c ⟶ c) ≃* (d ⟶ d) where
toFun γ := inv f ≫ γ ≫ f
invFun δ := f ≫ δ ≫ inv f
left_inv γ := by
simp_rw [Category.assoc, comp_inv, Category.comp_id, ← Category.assoc, comp_inv,
Category.id_comp]
right_inv δ := by
simp_rw [Category.assoc, inv_comp, ← Category.assoc, inv_comp, Category.id_comp,
Category.comp_id]
map_mul' γ₁ γ₂ := by
simp only [vertexGroup_mul, inv_eq_inv, Category.assoc, IsIso.hom_inv_id_assoc]
/-- A path in the groupoid defines an isomorphism between its endpoints.
-/
def vertexGroupIsomOfPath {c d : C} (p : Quiver.Path c d) : (c ⟶ c) ≃* (d ⟶ d) :=
vertexGroupIsomOfMap (composePath p)
/-- A functor defines a morphism of vertex group. -/
@[simps]
def CategoryTheory.Functor.mapVertexGroup {D : Type v} [Groupoid D] (φ : C ⥤ D) (c : C) :
(c ⟶ c) →* (φ.obj c ⟶ φ.obj c) where
toFun := φ.map
map_one' := φ.map_id c
map_mul' := φ.map_comp
end Groupoid
end CategoryTheory
|
Finiteness.lean
|
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.LinearAlgebra.Dimension.Constructions
import Mathlib.LinearAlgebra.Dimension.Finite
/-!
# A module over a division ring is noetherian if and only if it is finite.
-/
universe u v
open Cardinal Submodule Module Function
namespace IsNoetherian
variable {K : Type u} {V : Type v} [DivisionRing K] [AddCommGroup V] [Module K V]
/-- A module over a division ring is noetherian if and only if
its dimension (as a cardinal) is strictly less than the first infinite cardinal `ℵ₀`.
-/
theorem iff_rank_lt_aleph0 : IsNoetherian K V ↔ Module.rank K V < ℵ₀ := by
let b := Basis.ofVectorSpace K V
rw [← b.mk_eq_rank'', lt_aleph0_iff_set_finite]
constructor
· intro
exact (Basis.ofVectorSpaceIndex.linearIndependent K V).set_finite_of_isNoetherian
· intro hbfinite
refine
@isNoetherian_of_linearEquiv K (⊤ : Submodule K V) V _ _ _ _ _ (LinearEquiv.ofTop _ rfl)
(id ?_)
refine isNoetherian_of_fg_of_noetherian _ ⟨Set.Finite.toFinset hbfinite, ?_⟩
rw [Set.Finite.coe_toFinset, ← b.span_eq, Basis.coe_ofVectorSpace, Subtype.range_coe]
/-- In a noetherian module over a division ring, all bases are indexed by a finite type. -/
noncomputable def fintypeBasisIndex {ι : Type*} [IsNoetherian K V] (b : Basis ι K V) : Fintype ι :=
b.fintypeIndexOfRankLtAleph0 (rank_lt_aleph0 K V)
/-- In a noetherian module over a division ring,
`Basis.ofVectorSpace` is indexed by a finite type. -/
noncomputable instance [IsNoetherian K V] : Fintype (Basis.ofVectorSpaceIndex K V) :=
fintypeBasisIndex (Basis.ofVectorSpace K V)
/-- In a noetherian module over a division ring,
if a basis is indexed by a set, that set is finite. -/
theorem finite_basis_index {ι : Type*} {s : Set ι} [IsNoetherian K V] (b : Basis s K V) :
s.Finite :=
b.finite_index_of_rank_lt_aleph0 (rank_lt_aleph0 K V)
variable (K V)
/-- In a noetherian module over a division ring,
there exists a finite basis. This is the indexing `Finset`. -/
noncomputable def finsetBasisIndex [IsNoetherian K V] : Finset V :=
(finite_basis_index (Basis.ofVectorSpace K V)).toFinset
@[simp]
theorem coe_finsetBasisIndex [IsNoetherian K V] :
(↑(finsetBasisIndex K V) : Set V) = Basis.ofVectorSpaceIndex K V :=
Set.Finite.coe_toFinset _
@[simp]
theorem coeSort_finsetBasisIndex [IsNoetherian K V] :
(finsetBasisIndex K V : Type _) = Basis.ofVectorSpaceIndex K V :=
Set.Finite.coeSort_toFinset _
/-- In a noetherian module over a division ring, there exists a finite basis.
This is indexed by the `Finset` `IsNoetherian.finsetBasisIndex`.
This is in contrast to the result `finite_basis_index (Basis.ofVectorSpace K V)`,
which provides a set and a `Set.Finite`.
-/
noncomputable def finsetBasis [IsNoetherian K V] : Basis (finsetBasisIndex K V) K V :=
(Basis.ofVectorSpace K V).reindex (by rw [coeSort_finsetBasisIndex])
@[simp]
theorem range_finsetBasis [IsNoetherian K V] :
Set.range (finsetBasis K V) = Basis.ofVectorSpaceIndex K V := by
rw [finsetBasis, Basis.range_reindex, Basis.range_ofVectorSpace]
variable {K V}
theorem _root_.Module.card_eq_pow_finrank [Fintype K] [Fintype V] :
Fintype.card V = Fintype.card K ^ Module.finrank K V := by
let b := IsNoetherian.finsetBasis K V
rw [Module.card_fintype b, ← Module.finrank_eq_card_basis b]
@[deprecated (since := "2025-03-14")] alias _root_.card_eq_pow_finrank := Module.card_eq_pow_finrank
theorem _root_.Module.natCard_eq_pow_finrank [Module.Finite K V] :
Nat.card V = Nat.card K ^ finrank K V := by
let b := IsNoetherian.finsetBasis K V
rw [Nat.card_congr b.equivFun.toEquiv, Nat.card_fun, finrank_eq_nat_card_basis b]
/-- A module over a division ring is noetherian if and only if it is finitely generated. -/
theorem iff_fg : IsNoetherian K V ↔ Module.Finite K V := by
constructor
· intro h
exact
⟨⟨finsetBasisIndex K V, by
convert (finsetBasis K V).span_eq
simp⟩⟩
· rintro ⟨s, hs⟩
rw [IsNoetherian.iff_rank_lt_aleph0, ← rank_top, ← hs]
exact lt_of_le_of_lt (rank_span_le _) s.finite_toSet.lt_aleph0
end IsNoetherian
|
Lattice.lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Floris van Doorn, Gabriel Ebner, Yury Kudryashov
-/
import Mathlib.Data.Set.Accumulate
import Mathlib.Order.ConditionallyCompleteLattice.Finset
import Mathlib.Order.Interval.Finset.Nat
/-!
# Conditionally complete linear order structure on `ℕ`
In this file we
* define a `ConditionallyCompleteLinearOrderBot` structure on `ℕ`;
* prove a few lemmas about `iSup`/`iInf`/`Set.iUnion`/`Set.iInter` and natural numbers.
-/
assert_not_exists MonoidWithZero
open Set
namespace Nat
open scoped Classical in
noncomputable instance : InfSet ℕ :=
⟨fun s ↦ if h : ∃ n, n ∈ s then @Nat.find (fun n ↦ n ∈ s) _ h else 0⟩
open scoped Classical in
noncomputable instance : SupSet ℕ :=
⟨fun s ↦ if h : ∃ n, ∀ a ∈ s, a ≤ n then @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h else 0⟩
open scoped Classical in
theorem sInf_def {s : Set ℕ} (h : s.Nonempty) : sInf s = @Nat.find (fun n ↦ n ∈ s) _ h :=
dif_pos _
open scoped Classical in
theorem sSup_def {s : Set ℕ} (h : ∃ n, ∀ a ∈ s, a ≤ n) :
sSup s = @Nat.find (fun n ↦ ∀ a ∈ s, a ≤ n) _ h :=
dif_pos _
theorem _root_.Set.Infinite.Nat.sSup_eq_zero {s : Set ℕ} (h : s.Infinite) : sSup s = 0 :=
dif_neg fun ⟨n, hn⟩ ↦
let ⟨k, hks, hk⟩ := h.exists_gt n
(hn k hks).not_gt hk
@[simp]
theorem sInf_eq_zero {s : Set ℕ} : sInf s = 0 ↔ 0 ∈ s ∨ s = ∅ := by
cases eq_empty_or_nonempty s with
| inl h => subst h
simp only [or_true, InfSet.sInf,
mem_empty_iff_false, exists_false, dif_neg, not_false_iff]
| inr h => simp only [h.ne_empty, or_false, Nat.sInf_def, h, Nat.find_eq_zero]
@[simp]
theorem sInf_empty : sInf ∅ = 0 := by
rw [sInf_eq_zero]
right
rfl
@[simp]
theorem iInf_of_empty {ι : Sort*} [IsEmpty ι] (f : ι → ℕ) : iInf f = 0 := by
rw [iInf_of_isEmpty, sInf_empty]
/-- This combines `Nat.iInf_of_empty` with `ciInf_const`. -/
@[simp]
lemma iInf_const_zero {ι : Sort*} : ⨅ _ : ι, 0 = 0 :=
(isEmpty_or_nonempty ι).elim (fun h ↦ by simp) fun h ↦ sInf_eq_zero.2 <| by simp
theorem sInf_mem {s : Set ℕ} (h : s.Nonempty) : sInf s ∈ s := by
classical
rw [Nat.sInf_def h]
exact Nat.find_spec h
theorem notMem_of_lt_sInf {s : Set ℕ} {m : ℕ} (hm : m < sInf s) : m ∉ s := by
classical
cases eq_empty_or_nonempty s with
| inl h => subst h; apply notMem_empty
| inr h => rw [Nat.sInf_def h] at hm; exact Nat.find_min h hm
@[deprecated (since := "2025-05-23")] alias not_mem_of_lt_sInf := notMem_of_lt_sInf
protected theorem sInf_le {s : Set ℕ} {m : ℕ} (hm : m ∈ s) : sInf s ≤ m := by
classical
rw [Nat.sInf_def ⟨m, hm⟩]
exact Nat.find_min' ⟨m, hm⟩ hm
theorem nonempty_of_pos_sInf {s : Set ℕ} (h : 0 < sInf s) : s.Nonempty := by
by_contra contra
rw [Set.not_nonempty_iff_eq_empty] at contra
have h' : sInf s ≠ 0 := ne_of_gt h
apply h'
rw [Nat.sInf_eq_zero]
right
assumption
theorem nonempty_of_sInf_eq_succ {s : Set ℕ} {k : ℕ} (h : sInf s = k + 1) : s.Nonempty :=
nonempty_of_pos_sInf (h.symm ▸ succ_pos k : sInf s > 0)
theorem eq_Ici_of_nonempty_of_upward_closed {s : Set ℕ} (hs : s.Nonempty)
(hs' : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s) : s = Ici (sInf s) :=
ext fun n ↦ ⟨fun H ↦ Nat.sInf_le H, fun H ↦ hs' (sInf s) n H (sInf_mem hs)⟩
theorem sInf_upward_closed_eq_succ_iff {s : Set ℕ} (hs : ∀ k₁ k₂ : ℕ, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s)
(k : ℕ) : sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s := by
classical
constructor
· intro H
rw [eq_Ici_of_nonempty_of_upward_closed (nonempty_of_sInf_eq_succ _) hs, H, mem_Ici, mem_Ici]
· exact ⟨le_rfl, k.not_succ_le_self⟩
· exact k
· assumption
· rintro ⟨H, H'⟩
rw [sInf_def (⟨_, H⟩ : s.Nonempty), find_eq_iff]
exact ⟨H, fun n hnk hns ↦ H' <| hs n k (Nat.lt_succ_iff.mp hnk) hns⟩
/-- This instance is necessary, otherwise the lattice operations would be derived via
`ConditionallyCompleteLinearOrderBot` and marked as noncomputable. -/
instance : Lattice ℕ :=
LinearOrder.toLattice
open scoped Classical in
noncomputable instance : ConditionallyCompleteLinearOrderBot ℕ :=
{ (inferInstance : OrderBot ℕ), (LinearOrder.toLattice : Lattice ℕ),
(inferInstance : LinearOrder ℕ) with
le_csSup := fun s a hb ha ↦ by rw [sSup_def hb]; revert a ha; exact @Nat.find_spec _ _ hb
csSup_le := fun s a _ ha ↦ by rw [sSup_def ⟨a, ha⟩]; exact Nat.find_min' _ ha
le_csInf := fun s a hs hb ↦ by
rw [sInf_def hs]; exact hb (@Nat.find_spec (fun n ↦ n ∈ s) _ _)
csInf_le := fun s a _ ha ↦ by rw [sInf_def ⟨a, ha⟩]; exact Nat.find_min' _ ha
csSup_empty := by
simp only [sSup_def, Set.mem_empty_iff_false, forall_const, forall_prop_of_false,
not_false_iff, exists_const]
apply bot_unique (Nat.find_min' _ _)
trivial
csSup_of_not_bddAbove := by
intro s hs
simp only [sSup,
mem_empty_iff_false, IsEmpty.forall_iff, forall_const, exists_const, dite_true]
rw [dif_neg]
· exact le_antisymm (zero_le _) (find_le trivial)
· exact hs
csInf_of_not_bddBelow := fun s hs ↦ by simp at hs }
theorem sSup_mem {s : Set ℕ} (h₁ : s.Nonempty) (h₂ : BddAbove s) : sSup s ∈ s :=
let ⟨k, hk⟩ := h₂
h₁.csSup_mem ((finite_le_nat k).subset hk)
theorem sInf_add {n : ℕ} {p : ℕ → Prop} (hn : n ≤ sInf { m | p m }) :
sInf { m | p (m + n) } + n = sInf { m | p m } := by
classical
obtain h | ⟨m, hm⟩ := { m | p (m + n) }.eq_empty_or_nonempty
· rw [h, Nat.sInf_empty, zero_add]
obtain hnp | hnp := hn.eq_or_lt
· exact hnp
suffices hp : p (sInf { m | p m } - n + n) from (h.subset hp).elim
rw [Nat.sub_add_cancel hn]
exact csInf_mem (nonempty_of_pos_sInf <| n.zero_le.trans_lt hnp)
· have hp : ∃ n, n ∈ { m | p m } := ⟨_, hm⟩
rw [Nat.sInf_def ⟨m, hm⟩, Nat.sInf_def hp]
rw [Nat.sInf_def hp] at hn
exact find_add hn
theorem sInf_add' {n : ℕ} {p : ℕ → Prop} (h : 0 < sInf { m | p m }) :
sInf { m | p m } + n = sInf { m | p (m - n) } := by
suffices h₁ : n ≤ sInf {m | p (m - n)} by
convert sInf_add h₁
simp_rw [Nat.add_sub_cancel_right]
obtain ⟨m, hm⟩ := nonempty_of_pos_sInf h
refine
le_csInf ⟨m + n, ?_⟩ fun b hb ↦
le_of_not_gt fun hbn ↦
ne_of_mem_of_not_mem ?_ (notMem_of_lt_sInf h) (Nat.sub_eq_zero_of_le hbn.le)
· dsimp
rwa [Nat.add_sub_cancel_right]
· exact hb
section
variable {α : Type*} [CompleteLattice α]
theorem iSup_lt_succ (u : ℕ → α) (n : ℕ) : ⨆ k < n + 1, u k = (⨆ k < n, u k) ⊔ u n := by
simp_rw [Nat.lt_add_one_iff, biSup_le_eq_sup]
theorem iSup_lt_succ' (u : ℕ → α) (n : ℕ) : ⨆ k < n + 1, u k = u 0 ⊔ ⨆ k < n, u (k + 1) := by
rw [← sup_iSup_nat_succ]
simp
theorem iInf_lt_succ (u : ℕ → α) (n : ℕ) : ⨅ k < n + 1, u k = (⨅ k < n, u k) ⊓ u n :=
@iSup_lt_succ αᵒᵈ _ _ _
theorem iInf_lt_succ' (u : ℕ → α) (n : ℕ) : ⨅ k < n + 1, u k = u 0 ⊓ ⨅ k < n, u (k + 1) :=
@iSup_lt_succ' αᵒᵈ _ _ _
theorem iSup_le_succ (u : ℕ → α) (n : ℕ) : ⨆ k ≤ n + 1, u k = (⨆ k ≤ n, u k) ⊔ u (n + 1) := by
simp_rw [← Nat.lt_succ_iff, iSup_lt_succ]
theorem iSup_le_succ' (u : ℕ → α) (n : ℕ) : ⨆ k ≤ n + 1, u k = u 0 ⊔ ⨆ k ≤ n, u (k + 1) := by
simp_rw [← Nat.lt_succ_iff, iSup_lt_succ']
theorem iInf_le_succ (u : ℕ → α) (n : ℕ) : ⨅ k ≤ n + 1, u k = (⨅ k ≤ n, u k) ⊓ u (n + 1) :=
@iSup_le_succ αᵒᵈ _ _ _
theorem iInf_le_succ' (u : ℕ → α) (n : ℕ) : ⨅ k ≤ n + 1, u k = u 0 ⊓ ⨅ k ≤ n, u (k + 1) :=
@iSup_le_succ' αᵒᵈ _ _ _
end
end Nat
namespace Set
variable {α : Type*}
theorem biUnion_lt_succ (u : ℕ → Set α) (n : ℕ) : ⋃ k < n + 1, u k = (⋃ k < n, u k) ∪ u n :=
Nat.iSup_lt_succ u n
theorem biUnion_lt_succ' (u : ℕ → Set α) (n : ℕ) : ⋃ k < n + 1, u k = u 0 ∪ ⋃ k < n, u (k + 1) :=
Nat.iSup_lt_succ' u n
theorem biInter_lt_succ (u : ℕ → Set α) (n : ℕ) : ⋂ k < n + 1, u k = (⋂ k < n, u k) ∩ u n :=
Nat.iInf_lt_succ u n
theorem biInter_lt_succ' (u : ℕ → Set α) (n : ℕ) : ⋂ k < n + 1, u k = u 0 ∩ ⋂ k < n, u (k + 1) :=
Nat.iInf_lt_succ' u n
theorem biUnion_le_succ (u : ℕ → Set α) (n : ℕ) : ⋃ k ≤ n + 1, u k = (⋃ k ≤ n, u k) ∪ u (n + 1) :=
Nat.iSup_le_succ u n
theorem biUnion_le_succ' (u : ℕ → Set α) (n : ℕ) : ⋃ k ≤ n + 1, u k = u 0 ∪ ⋃ k ≤ n, u (k + 1) :=
Nat.iSup_le_succ' u n
theorem biInter_le_succ (u : ℕ → Set α) (n : ℕ) : ⋂ k ≤ n + 1, u k = (⋂ k ≤ n, u k) ∩ u (n + 1) :=
Nat.iInf_le_succ u n
theorem biInter_le_succ' (u : ℕ → Set α) (n : ℕ) : ⋂ k ≤ n + 1, u k = u 0 ∩ ⋂ k ≤ n, u (k + 1) :=
Nat.iInf_le_succ' u n
theorem accumulate_succ (u : ℕ → Set α) (n : ℕ) :
Accumulate u (n + 1) = Accumulate u n ∪ u (n + 1) := biUnion_le_succ u n
end Set
|
Presheaf.lean
|
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Mario Carneiro, Reid Barton, Andrew Yang
-/
import Mathlib.Topology.Category.TopCat.Opens
import Mathlib.CategoryTheory.Adjunction.Unique
import Mathlib.CategoryTheory.Functor.KanExtension.Adjunction
import Mathlib.Topology.Sheaves.Init
import Mathlib.Data.Set.Subsingleton
/-!
# Presheaves on a topological space
We define `TopCat.Presheaf C X` simply as `(TopologicalSpace.Opens X)ᵒᵖ ⥤ C`,
and inherit the category structure with natural transformations as morphisms.
We define
* Given `{X Y : TopCat.{w}}` and `f : X ⟶ Y`, we define
`TopCat.Presheaf.pushforward C f : X.Presheaf C ⥤ Y.Presheaf C`,
with notation `f _* ℱ` for `ℱ : X.Presheaf C`.
and for `ℱ : X.Presheaf C` provide the natural isomorphisms
* `TopCat.Presheaf.Pushforward.id : (𝟙 X) _* ℱ ≅ ℱ`
* `TopCat.Presheaf.Pushforward.comp : (f ≫ g) _* ℱ ≅ g _* (f _* ℱ)`
along with their `@[simp]` lemmas.
We also define the functors `pullback C f : Y.Presheaf C ⥤ X.Presheaf c`,
and provide their adjunction at
`TopCat.Presheaf.pushforwardPullbackAdjunction`.
-/
universe w v u
open CategoryTheory TopologicalSpace Opposite Functor
variable (C : Type u) [Category.{v} C]
namespace TopCat
/-- The category of `C`-valued presheaves on a (bundled) topological space `X`. -/
def Presheaf (X : TopCat.{w}) : Type max u v w :=
(Opens X)ᵒᵖ ⥤ C
instance (X : TopCat.{w}) : Category (Presheaf.{w, v, u} C X) :=
inferInstanceAs (Category ((Opens X)ᵒᵖ ⥤ C : Type max u v w))
variable {C}
namespace Presheaf
@[simp] theorem comp_app {X : TopCat} {U : (Opens X)ᵒᵖ} {P Q R : Presheaf C X}
(f : P ⟶ Q) (g : Q ⟶ R) :
(f ≫ g).app U = f.app U ≫ g.app U := rfl
@[ext]
lemma ext {X : TopCat} {P Q : Presheaf C X} {f g : P ⟶ Q}
(w : ∀ U : Opens X, f.app (op U) = g.app (op U)) :
f = g := by
apply NatTrans.ext
ext U
induction U with | _ U => ?_
apply w
/-- attribute `sheaf_restrict` to mark lemmas related to restricting sheaves -/
macro "sheaf_restrict" : attr =>
`(attr|aesop safe 50 apply (rule_sets := [$(Lean.mkIdent `Restrict):ident]))
attribute [sheaf_restrict] bot_le le_top le_refl inf_le_left inf_le_right
le_sup_left le_sup_right
/-- `restrict_tac` solves relations among subsets (copied from `aesop cat`) -/
macro (name := restrict_tac) "restrict_tac" c:Aesop.tactic_clause* : tactic =>
`(tactic| first | assumption |
aesop $c*
(config := { terminal := true
assumptionTransparency := .reducible
enableSimp := false })
(rule_sets := [-default, -builtin, $(Lean.mkIdent `Restrict):ident]))
/-- `restrict_tac?` passes along `Try this` from `aesop` -/
macro (name := restrict_tac?) "restrict_tac?" c:Aesop.tactic_clause* : tactic =>
`(tactic|
aesop? $c*
(config := { terminal := true
assumptionTransparency := .reducible
enableSimp := false
maxRuleApplications := 300 })
(rule_sets := [-default, -builtin, $(Lean.mkIdent `Restrict):ident]))
attribute[aesop 10% (rule_sets := [Restrict])] le_trans
attribute[aesop safe destruct (rule_sets := [Restrict])] Eq.trans_le
attribute[aesop safe -50 (rule_sets := [Restrict])] Aesop.BuiltinRules.assumption
example {X} [CompleteLattice X] (v : Nat → X) (w x y z : X) (e : v 0 = v 1) (_ : v 1 = v 2)
(h₀ : v 1 ≤ x) (_ : x ≤ z ⊓ w) (h₂ : x ≤ y ⊓ z) : v 0 ≤ y := by
restrict_tac
variable {X : TopCat} {C : Type*} [Category C] {FC : C → C → Type*} {CC : C → Type*}
variable [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC]
/-- The restriction of a section along an inclusion of open sets.
For `x : F.obj (op V)`, we provide the notation `x |_ₕ i` (`h` stands for `hom`) for `i : U ⟶ V`,
and the notation `x |_ₗ U ⟪i⟫` (`l` stands for `le`) for `i : U ≤ V`.
-/
def restrict {F : X.Presheaf C}
{V : Opens X} (x : ToType (F.obj (op V))) {U : Opens X} (h : U ⟶ V) : ToType (F.obj (op U)) :=
F.map h.op x
/-- restriction of a section along an inclusion -/
scoped[AlgebraicGeometry] infixl:80 " |_ₕ " => TopCat.Presheaf.restrict
/-- restriction of a section along a subset relation -/
scoped[AlgebraicGeometry] notation:80 x " |_ₗ " U " ⟪" e "⟫ " =>
@TopCat.Presheaf.restrict _ _ _ _ _ _ _ _ _ x U (@homOfLE (Opens _) _ U _ e)
open AlgebraicGeometry
/-- The restriction of a section along an inclusion of open sets.
For `x : F.obj (op V)`, we provide the notation `x |_ U`, where the proof `U ≤ V` is inferred by
the tactic `Top.presheaf.restrict_tac'` -/
abbrev restrictOpen {F : X.Presheaf C}
{V : Opens X} (x : ToType (F.obj (op V))) (U : Opens X)
(e : U ≤ V := by restrict_tac) :
ToType (F.obj (op U)) :=
x |_ₗ U ⟪e⟫
/-- restriction of a section to open subset -/
scoped[AlgebraicGeometry] infixl:80 " |_ " => TopCat.Presheaf.restrictOpen
theorem restrict_restrict
{F : X.Presheaf C} {U V W : Opens X} (e₁ : U ≤ V) (e₂ : V ≤ W) (x : ToType (F.obj (op W))) :
x |_ V |_ U = x |_ U := by
delta restrictOpen restrict
rw [← ConcreteCategory.comp_apply, ← Functor.map_comp]
rfl
theorem map_restrict
{F G : X.Presheaf C} (e : F ⟶ G) {U V : Opens X} (h : U ≤ V) (x : ToType (F.obj (op V))) :
e.app _ (x |_ U) = e.app _ x |_ U := by
delta restrictOpen restrict
rw [← ConcreteCategory.comp_apply, NatTrans.naturality, ConcreteCategory.comp_apply]
open CategoryTheory.Limits
variable (C)
/-- The pushforward functor. -/
@[simps!]
def pushforward {X Y : TopCat.{w}} (f : X ⟶ Y) : X.Presheaf C ⥤ Y.Presheaf C :=
(whiskeringLeft _ _ _).obj (Opens.map f).op
/-- push forward of a presheaf -/
scoped[AlgebraicGeometry] notation f:80 " _* " P:81 =>
Functor.obj (TopCat.Presheaf.pushforward _ f) P
@[simp]
theorem pushforward_map_app' {X Y : TopCat.{w}} (f : X ⟶ Y) {ℱ 𝒢 : X.Presheaf C} (α : ℱ ⟶ 𝒢)
{U : (Opens Y)ᵒᵖ} : ((pushforward C f).map α).app U = α.app (op <| (Opens.map f).obj U.unop) :=
rfl
lemma id_pushforward (X : TopCat.{w}) : pushforward C (𝟙 X) = 𝟭 (X.Presheaf C) := rfl
variable {C}
namespace Pushforward
/-- The natural isomorphism between the pushforward of a presheaf along the identity continuous map
and the original presheaf. -/
def id {X : TopCat.{w}} (ℱ : X.Presheaf C) : 𝟙 X _* ℱ ≅ ℱ := Iso.refl _
@[simp]
theorem id_hom_app {X : TopCat.{w}} (ℱ : X.Presheaf C) (U) : (id ℱ).hom.app U = 𝟙 _ := rfl
@[simp]
theorem id_inv_app {X : TopCat.{w}} (ℱ : X.Presheaf C) (U) :
(id ℱ).inv.app U = 𝟙 _ := rfl
theorem id_eq {X : TopCat.{w}} (ℱ : X.Presheaf C) : 𝟙 X _* ℱ = ℱ := rfl
/-- The natural isomorphism between
the pushforward of a presheaf along the composition of two continuous maps and
the corresponding pushforward of a pushforward. -/
def comp {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) :
(f ≫ g) _* ℱ ≅ g _* (f _* ℱ) := Iso.refl _
theorem comp_eq {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) :
(f ≫ g) _* ℱ = g _* (f _* ℱ) :=
rfl
@[simp]
theorem comp_hom_app {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) (U) :
(comp f g ℱ).hom.app U = 𝟙 _ := rfl
@[simp]
theorem comp_inv_app {X Y Z : TopCat.{w}} (f : X ⟶ Y) (g : Y ⟶ Z) (ℱ : X.Presheaf C) (U) :
(comp f g ℱ).inv.app U = 𝟙 _ := rfl
end Pushforward
/--
An equality of continuous maps induces a natural isomorphism between the pushforwards of a presheaf
along those maps.
-/
def pushforwardEq {X Y : TopCat.{w}} {f g : X ⟶ Y} (h : f = g) (ℱ : X.Presheaf C) :
f _* ℱ ≅ g _* ℱ :=
isoWhiskerRight (NatIso.op (Opens.mapIso f g h).symm) ℱ
theorem pushforward_eq' {X Y : TopCat.{w}} {f g : X ⟶ Y} (h : f = g) (ℱ : X.Presheaf C) :
f _* ℱ = g _* ℱ := by rw [h]
@[simp]
theorem pushforwardEq_hom_app {X Y : TopCat.{w}} {f g : X ⟶ Y}
(h : f = g) (ℱ : X.Presheaf C) (U) :
(pushforwardEq h ℱ).hom.app U = ℱ.map (eqToHom (by cat_disch)) := by
simp [pushforwardEq]
variable (C)
section Iso
/-- A homeomorphism of spaces gives an equivalence of categories of presheaves. -/
@[simps!]
def presheafEquivOfIso {X Y : TopCat} (H : X ≅ Y) : X.Presheaf C ≌ Y.Presheaf C :=
Equivalence.congrLeft (Opens.mapMapIso H).symm.op
variable {C}
/-- If `H : X ≅ Y` is a homeomorphism,
then given an `H _* ℱ ⟶ 𝒢`, we may obtain an `ℱ ⟶ H ⁻¹ _* 𝒢`.
-/
def toPushforwardOfIso {X Y : TopCat} (H : X ≅ Y) {ℱ : X.Presheaf C} {𝒢 : Y.Presheaf C}
(α : H.hom _* ℱ ⟶ 𝒢) : ℱ ⟶ H.inv _* 𝒢 :=
(presheafEquivOfIso _ H).toAdjunction.homEquiv ℱ 𝒢 α
@[simp]
theorem toPushforwardOfIso_app {X Y : TopCat} (H₁ : X ≅ Y) {ℱ : X.Presheaf C} {𝒢 : Y.Presheaf C}
(H₂ : H₁.hom _* ℱ ⟶ 𝒢) (U : (Opens X)ᵒᵖ) :
(toPushforwardOfIso H₁ H₂).app U =
ℱ.map (eqToHom (by simp [Opens.map, Set.preimage_preimage])) ≫
H₂.app (op ((Opens.map H₁.inv).obj (unop U))) := by
simp [toPushforwardOfIso, Adjunction.homEquiv_unit]
/-- If `H : X ≅ Y` is a homeomorphism,
then given an `H _* ℱ ⟶ 𝒢`, we may obtain an `ℱ ⟶ H ⁻¹ _* 𝒢`.
-/
def pushforwardToOfIso {X Y : TopCat} (H₁ : X ≅ Y) {ℱ : Y.Presheaf C} {𝒢 : X.Presheaf C}
(H₂ : ℱ ⟶ H₁.hom _* 𝒢) : H₁.inv _* ℱ ⟶ 𝒢 :=
((presheafEquivOfIso _ H₁.symm).toAdjunction.homEquiv ℱ 𝒢).symm H₂
@[simp]
theorem pushforwardToOfIso_app {X Y : TopCat} (H₁ : X ≅ Y) {ℱ : Y.Presheaf C} {𝒢 : X.Presheaf C}
(H₂ : ℱ ⟶ H₁.hom _* 𝒢) (U : (Opens X)ᵒᵖ) :
(pushforwardToOfIso H₁ H₂).app U =
H₂.app (op ((Opens.map H₁.inv).obj (unop U))) ≫
𝒢.map (eqToHom (by simp [Opens.map, Set.preimage_preimage])) := by
simp [pushforwardToOfIso, Equivalence.toAdjunction, Adjunction.homEquiv_counit]
end Iso
variable [HasColimits C]
noncomputable section
/-- Pullback a presheaf on `Y` along a continuous map `f : X ⟶ Y`, obtaining a presheaf
on `X`. -/
def pullback {X Y : TopCat.{v}} (f : X ⟶ Y) : Y.Presheaf C ⥤ X.Presheaf C :=
(Opens.map f).op.lan
/-- The pullback and pushforward along a continuous map are adjoint to each other. -/
def pushforwardPullbackAdjunction {X Y : TopCat.{v}} (f : X ⟶ Y) :
pullback C f ⊣ pushforward C f :=
Functor.lanAdjunction _ _
/-- Pulling back along a homeomorphism is the same as pushing forward along its inverse. -/
def pullbackHomIsoPushforwardInv {X Y : TopCat.{v}} (H : X ≅ Y) :
pullback C H.hom ≅ pushforward C H.inv :=
Adjunction.leftAdjointUniq (pushforwardPullbackAdjunction C H.hom)
(presheafEquivOfIso C H.symm).toAdjunction
/-- Pulling back along the inverse of a homeomorphism is the same as pushing forward along it. -/
def pullbackInvIsoPushforwardHom {X Y : TopCat.{v}} (H : X ≅ Y) :
pullback C H.inv ≅ pushforward C H.hom :=
Adjunction.leftAdjointUniq (pushforwardPullbackAdjunction C H.inv)
(presheafEquivOfIso C H).toAdjunction
variable {C}
/-- If `f '' U` is open, then `f⁻¹ℱ U ≅ ℱ (f '' U)`. -/
def pullbackObjObjOfImageOpen {X Y : TopCat.{v}} (f : X ⟶ Y) (ℱ : Y.Presheaf C) (U : Opens X)
(H : IsOpen (f '' SetLike.coe U)) : ((pullback C f).obj ℱ).obj (op U) ≅ ℱ.obj (op ⟨_, H⟩) := by
let x : CostructuredArrow (Opens.map f).op (op U) := CostructuredArrow.mk
(@homOfLE _ _ _ ((Opens.map f).obj ⟨_, H⟩) (Set.image_preimage.le_u_l _)).op
have hx : IsTerminal x :=
{ lift := fun s ↦ by
fapply CostructuredArrow.homMk
· change op (unop _) ⟶ op (⟨_, H⟩ : Opens _)
refine (homOfLE ?_).op
apply (Set.image_mono s.pt.hom.unop.le).trans
exact Set.image_preimage.l_u_le (SetLike.coe s.pt.left.unop)
· simp [eq_iff_true_of_subsingleton] }
exact IsColimit.coconePointUniqueUpToIso
((Opens.map f).op.isPointwiseLeftKanExtensionLeftKanExtensionUnit ℱ (op U))
(colimitOfDiagramTerminal hx _)
end
end Presheaf
end TopCat
|
DiscreteQuotient.lean
|
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne, Adam Topaz
-/
import Mathlib.Data.Setoid.Partition
import Mathlib.Topology.LocallyConstant.Basic
import Mathlib.Topology.Separation.Regular
import Mathlib.Topology.Connected.TotallyDisconnected
/-!
# Discrete quotients of a topological space.
This file defines the type of discrete quotients of a topological space,
denoted `DiscreteQuotient X`. To avoid quantifying over types, we model such
quotients as setoids whose equivalence classes are clopen.
## Definitions
1. `DiscreteQuotient X` is the type of discrete quotients of `X`.
It is endowed with a coercion to `Type`, which is defined as the
quotient associated to the setoid in question, and each such quotient
is endowed with the discrete topology.
2. Given `S : DiscreteQuotient X`, the projection `X → S` is denoted
`S.proj`.
3. When `X` is compact and `S : DiscreteQuotient X`, the space `S` is
endowed with a `Fintype` instance.
## Order structure
The type `DiscreteQuotient X` is endowed with an instance of a `SemilatticeInf` with `OrderTop`.
The partial ordering `A ≤ B` mathematically means that `B.proj` factors through `A.proj`.
The top element `⊤` is the trivial quotient, meaning that every element of `X` is collapsed
to a point. Given `h : A ≤ B`, the map `A → B` is `DiscreteQuotient.ofLE h`.
Whenever `X` is a locally connected space, the type `DiscreteQuotient X` is also endowed with an
instance of an `OrderBot`, where the bot element `⊥` is given by the `connectedComponentSetoid`,
i.e., `x ~ y` means that `x` and `y` belong to the same connected component. In particular, if `X`
is a discrete topological space, then `x ~ y` is equivalent (propositionally, not definitionally) to
`x = y`.
Given `f : C(X, Y)`, we define a predicate `DiscreteQuotient.LEComap f A B` for
`A : DiscreteQuotient X` and `B : DiscreteQuotient Y`, asserting that `f` descends to `A → B`. If
`cond : DiscreteQuotient.LEComap h A B`, the function `A → B` is obtained by
`DiscreteQuotient.map f cond`.
## Theorems
The two main results proved in this file are:
1. `DiscreteQuotient.eq_of_forall_proj_eq` which states that when `X` is compact, T₂, and totally
disconnected, any two elements of `X` are equal if their projections in `Q` agree for all
`Q : DiscreteQuotient X`.
2. `DiscreteQuotient.exists_of_compat` which states that when `X` is compact, then any
system of elements of `Q` as `Q : DiscreteQuotient X` varies, which is compatible with
respect to `DiscreteQuotient.ofLE`, must arise from some element of `X`.
## Remarks
The constructions in this file will be used to show that any profinite space is a limit
of finite discrete spaces.
-/
open Set Function TopologicalSpace Topology
variable {α X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z]
/-- The type of discrete quotients of a topological space. -/
@[ext]
structure DiscreteQuotient (X : Type*) [TopologicalSpace X] extends Setoid X where
/-- For every point `x`, the set `{ y | Rel x y }` is an open set. -/
protected isOpen_setOf_rel : ∀ x, IsOpen (setOf (toSetoid x))
namespace DiscreteQuotient
variable (S : DiscreteQuotient X)
lemma toSetoid_injective : Function.Injective (@toSetoid X _)
| ⟨_, _⟩, ⟨_, _⟩, _ => by congr
/-- Construct a discrete quotient from a clopen set. -/
def ofIsClopen {A : Set X} (h : IsClopen A) : DiscreteQuotient X where
toSetoid := ⟨fun x y => x ∈ A ↔ y ∈ A, fun _ => Iff.rfl, Iff.symm, Iff.trans⟩
isOpen_setOf_rel x := by by_cases hx : x ∈ A <;> simp [hx, h.1, h.2, ← compl_setOf]
theorem refl : ∀ x, S.toSetoid x x := S.refl'
theorem symm (x y : X) : S.toSetoid x y → S.toSetoid y x := S.symm'
theorem trans (x y z : X) : S.toSetoid x y → S.toSetoid y z → S.toSetoid x z := S.trans'
/-- The setoid whose quotient yields the discrete quotient. -/
add_decl_doc toSetoid
instance : CoeSort (DiscreteQuotient X) (Type _) :=
⟨fun S => Quotient S.toSetoid⟩
instance : TopologicalSpace S :=
inferInstanceAs (TopologicalSpace (Quotient S.toSetoid))
/-- The projection from `X` to the given discrete quotient. -/
def proj : X → S := Quotient.mk''
theorem fiber_eq (x : X) : S.proj ⁻¹' {S.proj x} = setOf (S.toSetoid x) :=
Set.ext fun _ => eq_comm.trans Quotient.eq''
theorem proj_surjective : Function.Surjective S.proj :=
Quotient.mk''_surjective
theorem proj_isQuotientMap : IsQuotientMap S.proj :=
isQuotientMap_quot_mk
theorem proj_continuous : Continuous S.proj :=
S.proj_isQuotientMap.continuous
instance : DiscreteTopology S :=
singletons_open_iff_discrete.1 <| S.proj_surjective.forall.2 fun x => by
rw [← S.proj_isQuotientMap.isOpen_preimage, fiber_eq]
exact S.isOpen_setOf_rel _
theorem proj_isLocallyConstant : IsLocallyConstant S.proj :=
(IsLocallyConstant.iff_continuous S.proj).2 S.proj_continuous
theorem isClopen_preimage (A : Set S) : IsClopen (S.proj ⁻¹' A) :=
(isClopen_discrete A).preimage S.proj_continuous
theorem isOpen_preimage (A : Set S) : IsOpen (S.proj ⁻¹' A) :=
(S.isClopen_preimage A).2
theorem isClosed_preimage (A : Set S) : IsClosed (S.proj ⁻¹' A) :=
(S.isClopen_preimage A).1
theorem isClopen_setOf_rel (x : X) : IsClopen (setOf (S.toSetoid x)) := by
rw [← fiber_eq]
apply isClopen_preimage
instance : Min (DiscreteQuotient X) :=
⟨fun S₁ S₂ => ⟨S₁.1 ⊓ S₂.1, fun x => (S₁.2 x).inter (S₂.2 x)⟩⟩
instance : SemilatticeInf (DiscreteQuotient X) :=
Injective.semilatticeInf toSetoid toSetoid_injective fun _ _ => rfl
instance : OrderTop (DiscreteQuotient X) where
top := ⟨⊤, fun _ => isOpen_univ⟩
le_top a := by tauto
instance : Inhabited (DiscreteQuotient X) := ⟨⊤⟩
instance inhabitedQuotient [Inhabited X] : Inhabited S := ⟨S.proj default⟩
-- TODO: add instances about `Nonempty (Quot _)`/`Nonempty (Quotient _)`
instance [Nonempty X] : Nonempty S := Nonempty.map S.proj ‹_›
/-- The quotient by `⊤ : DiscreteQuotient X` is a `Subsingleton`. -/
instance : Subsingleton (⊤ : DiscreteQuotient X) where
allEq := by rintro ⟨_⟩ ⟨_⟩; exact Quotient.sound trivial
section Comap
variable (g : C(Y, Z)) (f : C(X, Y))
/-- Comap a discrete quotient along a continuous map. -/
def comap (S : DiscreteQuotient Y) : DiscreteQuotient X where
toSetoid := Setoid.comap f S.1
isOpen_setOf_rel _ := (S.2 _).preimage f.continuous
@[simp]
theorem comap_id : S.comap (ContinuousMap.id X) = S := rfl
@[simp]
theorem comap_comp (S : DiscreteQuotient Z) : S.comap (g.comp f) = (S.comap g).comap f :=
rfl
@[mono]
theorem comap_mono {A B : DiscreteQuotient Y} (h : A ≤ B) : A.comap f ≤ B.comap f := by tauto
end Comap
section OfLE
variable {A B C : DiscreteQuotient X}
/-- The map induced by a refinement of a discrete quotient. -/
def ofLE (h : A ≤ B) : A → B :=
Quotient.map' id h
@[simp]
theorem ofLE_refl : ofLE (le_refl A) = id := by
ext ⟨⟩
rfl
theorem ofLE_refl_apply (a : A) : ofLE (le_refl A) a = a := by simp
@[simp]
theorem ofLE_ofLE (h₁ : A ≤ B) (h₂ : B ≤ C) (x : A) :
ofLE h₂ (ofLE h₁ x) = ofLE (h₁.trans h₂) x := by
rcases x with ⟨⟩
rfl
@[simp]
theorem ofLE_comp_ofLE (h₁ : A ≤ B) (h₂ : B ≤ C) : ofLE h₂ ∘ ofLE h₁ = ofLE (le_trans h₁ h₂) :=
funext <| ofLE_ofLE _ _
theorem ofLE_continuous (h : A ≤ B) : Continuous (ofLE h) :=
continuous_of_discreteTopology
@[simp]
theorem ofLE_proj (h : A ≤ B) (x : X) : ofLE h (A.proj x) = B.proj x :=
Quotient.sound' (B.refl _)
@[simp]
theorem ofLE_comp_proj (h : A ≤ B) : ofLE h ∘ A.proj = B.proj :=
funext <| ofLE_proj _
end OfLE
/-- When `X` is a locally connected space, there is an `OrderBot` instance on
`DiscreteQuotient X`. The bottom element is given by `connectedComponentSetoid X`
-/
instance [LocallyConnectedSpace X] : OrderBot (DiscreteQuotient X) where
bot :=
{ toSetoid := connectedComponentSetoid X
isOpen_setOf_rel := fun x => by
convert isOpen_connectedComponent (x := x)
ext y
simpa only [connectedComponentSetoid, ← connectedComponent_eq_iff_mem] using eq_comm }
bot_le S := fun x y (h : connectedComponent x = connectedComponent y) =>
(S.isClopen_setOf_rel x).connectedComponent_subset (S.refl _) <| h.symm ▸ mem_connectedComponent
@[simp]
theorem proj_bot_eq [LocallyConnectedSpace X] {x y : X} :
proj ⊥ x = proj ⊥ y ↔ connectedComponent x = connectedComponent y :=
Quotient.eq''
theorem proj_bot_inj [DiscreteTopology X] {x y : X} : proj ⊥ x = proj ⊥ y ↔ x = y := by simp
theorem proj_bot_injective [DiscreteTopology X] : Injective (⊥ : DiscreteQuotient X).proj :=
fun _ _ => proj_bot_inj.1
theorem proj_bot_bijective [DiscreteTopology X] : Bijective (⊥ : DiscreteQuotient X).proj :=
⟨proj_bot_injective, proj_surjective _⟩
section Map
variable (f : C(X, Y)) (A A' : DiscreteQuotient X) (B B' : DiscreteQuotient Y)
/-- Given `f : C(X, Y)`, `DiscreteQuotient.LEComap f A B` is defined as
`A ≤ B.comap f`. Mathematically this means that `f` descends to a morphism `A → B`. -/
def LEComap : Prop :=
A ≤ B.comap f
theorem leComap_id : LEComap (.id X) A A := le_rfl
variable {A A' B B'} {f} {g : C(Y, Z)} {C : DiscreteQuotient Z}
@[simp]
theorem leComap_id_iff : LEComap (ContinuousMap.id X) A A' ↔ A ≤ A' :=
Iff.rfl
theorem LEComap.comp : LEComap g B C → LEComap f A B → LEComap (g.comp f) A C := by tauto
@[mono]
theorem LEComap.mono (h : LEComap f A B) (hA : A' ≤ A) (hB : B ≤ B') : LEComap f A' B' :=
hA.trans <| h.trans <| comap_mono _ hB
/-- Map a discrete quotient along a continuous map. -/
def map (f : C(X, Y)) (cond : LEComap f A B) : A → B := Quotient.map' f cond
theorem map_continuous (cond : LEComap f A B) : Continuous (map f cond) :=
continuous_of_discreteTopology
@[simp]
theorem map_comp_proj (cond : LEComap f A B) : map f cond ∘ A.proj = B.proj ∘ f :=
rfl
@[simp]
theorem map_proj (cond : LEComap f A B) (x : X) : map f cond (A.proj x) = B.proj (f x) :=
rfl
@[simp]
theorem map_id : map _ (leComap_id A) = id := by ext ⟨⟩; rfl
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: figure out why `simpNF` says this is a bad `@[simp]` lemma
-- See https://github.com/leanprover-community/batteries/issues/365
theorem map_comp (h1 : LEComap g B C) (h2 : LEComap f A B) :
map (g.comp f) (h1.comp h2) = map g h1 ∘ map f h2 := by
ext ⟨⟩
rfl
@[simp]
theorem ofLE_map (cond : LEComap f A B) (h : B ≤ B') (a : A) :
ofLE h (map f cond a) = map f (cond.mono le_rfl h) a := by
rcases a with ⟨⟩
rfl
@[simp]
theorem ofLE_comp_map (cond : LEComap f A B) (h : B ≤ B') :
ofLE h ∘ map f cond = map f (cond.mono le_rfl h) :=
funext <| ofLE_map cond h
@[simp]
theorem map_ofLE (cond : LEComap f A B) (h : A' ≤ A) (c : A') :
map f cond (ofLE h c) = map f (cond.mono h le_rfl) c := by
rcases c with ⟨⟩
rfl
@[simp]
theorem map_comp_ofLE (cond : LEComap f A B) (h : A' ≤ A) :
map f cond ∘ ofLE h = map f (cond.mono h le_rfl) :=
funext <| map_ofLE cond h
end Map
theorem eq_of_forall_proj_eq [T2Space X] [CompactSpace X] [disc : TotallyDisconnectedSpace X]
{x y : X} (h : ∀ Q : DiscreteQuotient X, Q.proj x = Q.proj y) : x = y := by
rw [← mem_singleton_iff, ← connectedComponent_eq_singleton, connectedComponent_eq_iInter_isClopen,
mem_iInter]
rintro ⟨U, hU1, hU2⟩
exact (Quotient.exact' (h (ofIsClopen hU1))).mpr hU2
theorem fiber_subset_ofLE {A B : DiscreteQuotient X} (h : A ≤ B) (a : A) :
A.proj ⁻¹' {a} ⊆ B.proj ⁻¹' {ofLE h a} := by
rcases A.proj_surjective a with ⟨a, rfl⟩
rw [fiber_eq, ofLE_proj, fiber_eq]
exact fun _ h' => h h'
theorem exists_of_compat [CompactSpace X] (Qs : (Q : DiscreteQuotient X) → Q)
(compat : ∀ (A B : DiscreteQuotient X) (h : A ≤ B), ofLE h (Qs _) = Qs _) :
∃ x : X, ∀ Q : DiscreteQuotient X, Q.proj x = Qs _ := by
have H₁ : ∀ Q₁ Q₂, Q₁ ≤ Q₂ → proj Q₁ ⁻¹' {Qs Q₁} ⊆ proj Q₂ ⁻¹' {Qs Q₂} := fun _ _ h => by
rw [← compat _ _ h]
exact fiber_subset_ofLE _ _
obtain ⟨x, hx⟩ : Set.Nonempty (⋂ Q, proj Q ⁻¹' {Qs Q}) :=
IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
(fun Q : DiscreteQuotient X => Q.proj ⁻¹' {Qs _}) (directed_of_isDirected_ge H₁)
(fun Q => (singleton_nonempty _).preimage Q.proj_surjective)
(fun Q => (Q.isClosed_preimage {Qs _}).isCompact) fun Q => Q.isClosed_preimage _
exact ⟨x, mem_iInter.1 hx⟩
/-- If `X` is a compact space, then any discrete quotient of `X` is finite. -/
instance [CompactSpace X] : Finite S := by
have : CompactSpace S := Quotient.compactSpace
rwa [← isCompact_univ_iff, isCompact_iff_finite, finite_univ_iff] at this
variable (X)
open Classical in
/--
If `X` is a compact space, then we associate to any discrete quotient on `X` a finite set of
clopen subsets of `X`, given by the fibers of `proj`.
TODO: prove that these form a partition of `X`
-/
noncomputable def finsetClopens [CompactSpace X]
(d : DiscreteQuotient X) : Finset (Clopens X) := have : Fintype d := Fintype.ofFinite _
(Set.range (fun (x : d) ↦ ⟨_, d.isClopen_preimage {x}⟩) : Set (Clopens X)).toFinset
/-- A helper lemma to prove that `finsetClopens X` is injective, see `finsetClopens_inj`. -/
lemma comp_finsetClopens [CompactSpace X] :
(Set.image (fun (t : Clopens X) ↦ t.carrier) ∘ Finset.toSet) ∘
finsetClopens X = fun ⟨f, _⟩ ↦ f.classes := by
ext d
simp only [Setoid.classes, Set.mem_setOf_eq, Function.comp_apply,
finsetClopens, Set.coe_toFinset, Set.mem_image, Set.mem_range,
exists_exists_eq_and]
constructor
· refine fun ⟨y, h⟩ ↦ ⟨Quotient.out (s := d.toSetoid) y, ?_⟩
ext
simpa [← h] using Quotient.mk_eq_iff_out (s := d.toSetoid)
· exact fun ⟨y, h⟩ ↦ ⟨d.proj y, by ext; simp [h, proj]⟩
/-- `finsetClopens X` is injective. -/
theorem finsetClopens_inj [CompactSpace X] :
(finsetClopens X).Injective := by
apply Function.Injective.of_comp (f := Set.image (fun (t : Clopens X) ↦ t.carrier) ∘ Finset.toSet)
rw [comp_finsetClopens]
intro ⟨_, _⟩ ⟨_, _⟩ h
congr
rw [Setoid.classes_inj]
exact h
/--
The discrete quotients of a compact space are in bijection with a subtype of the type of
`Finset (Clopens X)`.
TODO: show that this is precisely those finsets of clopens which form a partition of `X`.
-/
noncomputable
def equivFinsetClopens [CompactSpace X] := Equiv.ofInjective _ (finsetClopens_inj X)
variable {X}
end DiscreteQuotient
namespace LocallyConstant
variable (f : LocallyConstant X α)
/-- Any locally constant function induces a discrete quotient. -/
def discreteQuotient : DiscreteQuotient X where
toSetoid := .comap f ⊥
isOpen_setOf_rel _ := f.isLocallyConstant _
/-- The (locally constant) function from the discrete quotient associated to a locally constant
function. -/
def lift : LocallyConstant f.discreteQuotient α :=
⟨fun a => Quotient.liftOn' a f fun _ _ => id, fun _ => isOpen_discrete _⟩
@[simp]
theorem lift_comp_proj : f.lift ∘ f.discreteQuotient.proj = f := rfl
end LocallyConstant
|
all_order.v
|
Require Export order.
|
Isometry.lean
|
/-
Copyright (c) 2021 François Sunatori. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: François Sunatori
-/
import Mathlib.Analysis.Complex.Circle
import Mathlib.LinearAlgebra.Determinant
import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Basic
/-!
# Isometries of the Complex Plane
The lemma `linear_isometry_complex` states the classification of isometries in the complex plane.
Specifically, isometries with rotations but without translation.
The proof involves:
1. creating a linear isometry `g` with two fixed points, `g(0) = 0`, `g(1) = 1`
2. applying `linear_isometry_complex_aux` to `g`
The proof of `linear_isometry_complex_aux` is separated in the following parts:
1. show that the real parts match up: `LinearIsometry.re_apply_eq_re`
2. show that I maps to either I or -I
3. every z is a linear combination of a + b * I
## References
* [Isometries of the Complex Plane](http://helmut.knaust.info/mediawiki/images/b/b5/Iso.pdf)
-/
noncomputable section
open Complex
open CharZero
open ComplexConjugate
local notation "|" x "|" => Complex.abs x
/-- An element of the unit circle defines a `LinearIsometryEquiv` from `ℂ` to itself, by
rotation. -/
def rotation : Circle →* ℂ ≃ₗᵢ[ℝ] ℂ where
toFun a :=
{ DistribMulAction.toLinearEquiv ℝ ℂ a with
norm_map' x := show ‖a * x‖ = ‖x‖ by
rw [norm_mul, Circle.norm_coe, one_mul] }
map_one' := LinearIsometryEquiv.ext <| by simp
map_mul' a b := LinearIsometryEquiv.ext <| mul_smul a b
@[simp]
theorem rotation_apply (a : Circle) (z : ℂ) : rotation a z = a * z :=
rfl
@[simp]
theorem rotation_symm (a : Circle) : (rotation a).symm = rotation a⁻¹ :=
LinearIsometryEquiv.ext fun _ => rfl
@[simp]
theorem rotation_trans (a b : Circle) : (rotation a).trans (rotation b) = rotation (b * a) := by
ext1
simp
theorem rotation_ne_conjLIE (a : Circle) : rotation a ≠ conjLIE := by
intro h
have h1 : rotation a 1 = conj 1 := LinearIsometryEquiv.congr_fun h 1
have hI : rotation a I = conj I := LinearIsometryEquiv.congr_fun h I
rw [rotation_apply, RingHom.map_one, mul_one] at h1
rw [rotation_apply, conj_I, ← neg_one_mul, mul_left_inj' I_ne_zero, h1, eq_neg_self_iff] at hI
exact one_ne_zero hI
/-- Takes an element of `ℂ ≃ₗᵢ[ℝ] ℂ` and checks if it is a rotation, returns an element of the
unit circle. -/
@[simps]
def rotationOf (e : ℂ ≃ₗᵢ[ℝ] ℂ) : Circle :=
⟨e 1 / ‖e 1‖, by simp [Submonoid.unitSphere]⟩
@[simp]
theorem rotationOf_rotation (a : Circle) : rotationOf (rotation a) = a :=
Subtype.ext <| by simp
theorem rotation_injective : Function.Injective rotation :=
Function.LeftInverse.injective rotationOf_rotation
theorem LinearIsometry.re_apply_eq_re_of_add_conj_eq (f : ℂ →ₗᵢ[ℝ] ℂ)
(h₃ : ∀ z, z + conj z = f z + conj (f z)) (z : ℂ) : (f z).re = z.re := by
simpa [Complex.ext_iff, add_re, add_im, conj_re, conj_im, ← two_mul,
show (2 : ℝ) ≠ 0 by simp] using (h₃ z).symm
theorem LinearIsometry.im_apply_eq_im_or_neg_of_re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ}
(h₂ : ∀ z, (f z).re = z.re) (z : ℂ) : (f z).im = z.im ∨ (f z).im = -z.im := by
have h₁ := f.norm_map z
simp only [norm_def] at h₁
rwa [Real.sqrt_inj (normSq_nonneg _) (normSq_nonneg _), normSq_apply (f z), normSq_apply z,
h₂, add_left_cancel_iff, mul_self_eq_mul_self_iff] at h₁
theorem LinearIsometry.im_apply_eq_im {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) :
z + conj z = f z + conj (f z) := by
have : ‖f z - 1‖ = ‖z - 1‖ := by rw [← f.norm_map (z - 1), f.map_sub, h]
apply_fun fun x => x ^ 2 at this
simp only [← normSq_eq_norm_sq] at this
rw [← ofReal_inj, ← mul_conj, ← mul_conj] at this
rw [RingHom.map_sub, RingHom.map_sub] at this
simp only [sub_mul, mul_sub, one_mul] at this
rw [mul_conj, normSq_eq_norm_sq, LinearIsometry.norm_map] at this
rw [mul_conj, normSq_eq_norm_sq] at this
simp only [sub_sub, sub_right_inj, mul_one, ofReal_pow, RingHom.map_one] at this
simp only [add_sub, sub_left_inj] at this
rw [add_comm, ← this, add_comm]
theorem LinearIsometry.re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : (f z).re = z.re := by
apply LinearIsometry.re_apply_eq_re_of_add_conj_eq
intro z
apply LinearIsometry.im_apply_eq_im h
theorem linear_isometry_complex_aux {f : ℂ ≃ₗᵢ[ℝ] ℂ} (h : f 1 = 1) :
f = LinearIsometryEquiv.refl ℝ ℂ ∨ f = conjLIE := by
have h0 : f I = I ∨ f I = -I := by
simp only [Complex.ext_iff, ← and_or_left, neg_re, I_re, neg_im, neg_zero]
constructor
· rw [← I_re]
exact @LinearIsometry.re_apply_eq_re f.toLinearIsometry h I
· apply @LinearIsometry.im_apply_eq_im_or_neg_of_re_apply_eq_re f.toLinearIsometry
intro z
rw [@LinearIsometry.re_apply_eq_re f.toLinearIsometry h]
refine h0.imp (fun h' : f I = I => ?_) fun h' : f I = -I => ?_ <;>
· apply LinearIsometryEquiv.toLinearEquiv_injective
apply Complex.basisOneI.ext'
intro i
fin_cases i <;> simp [h, h']
theorem linear_isometry_complex (f : ℂ ≃ₗᵢ[ℝ] ℂ) :
∃ a : Circle, f = rotation a ∨ f = conjLIE.trans (rotation a) := by
let a : Circle := ⟨f 1, by simp [Submonoid.unitSphere, f.norm_map]⟩
use a
have : (f.trans (rotation a).symm) 1 = 1 := by simpa [a] using rotation_apply a⁻¹ (f 1)
refine (linear_isometry_complex_aux this).imp (fun h₁ => ?_) fun h₂ => ?_
· simpa using eq_mul_of_inv_mul_eq h₁
· exact eq_mul_of_inv_mul_eq h₂
/-- The matrix representation of `rotation a` is equal to the conformal matrix
`!![re a, -im a; im a, re a]`. -/
theorem toMatrix_rotation (a : Circle) :
LinearMap.toMatrix basisOneI basisOneI (rotation a).toLinearEquiv =
Matrix.planeConformalMatrix (re a) (im a) (by simp [pow_two, ← normSq_apply]) := by
ext i j
simp only [LinearMap.toMatrix_apply, coe_basisOneI, LinearEquiv.coe_coe,
LinearIsometryEquiv.coe_toLinearEquiv, rotation_apply, coe_basisOneI_repr, mul_re, mul_im,
Matrix.val_planeConformalMatrix, Matrix.of_apply, Matrix.cons_val', Matrix.empty_val',
Matrix.cons_val_fin_one]
fin_cases i <;> fin_cases j <;> simp
/-- The determinant of `rotation` (as a linear map) is equal to `1`. -/
@[simp]
theorem det_rotation (a : Circle) : LinearMap.det ((rotation a).toLinearEquiv : ℂ →ₗ[ℝ] ℂ) = 1 := by
rw [← LinearMap.det_toMatrix basisOneI, toMatrix_rotation, Matrix.det_fin_two]
simp [← normSq_apply]
/-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/
@[simp]
theorem linearEquiv_det_rotation (a : Circle) : LinearEquiv.det (rotation a).toLinearEquiv = 1 := by
rw [← Units.val_inj, LinearEquiv.coe_det, det_rotation, Units.val_one]
|
Average.lean
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Lua Viana Reis, Oliver Butterley
-/
import Mathlib.Dynamics.BirkhoffSum.Basic
import Mathlib.Algebra.Module.Basic
/-!
# Birkhoff average
In this file we define `birkhoffAverage f g n x` to be
$$
\frac{1}{n}\sum_{k=0}^{n-1}g(f^{[k]}(x)),
$$
where `f : α → α` is a self-map on some type `α`,
`g : α → M` is a function from `α` to a module over a division semiring `R`,
and `R` is used to formalize division by `n` as `(n : R)⁻¹ • _`.
While we need an auxiliary division semiring `R` to define `birkhoffAverage`,
the definition does not depend on the choice of `R`,
see `birkhoffAverage_congr_ring`.
-/
open Finset
section birkhoffAverage
variable (R : Type*) {α M : Type*} [DivisionSemiring R] [AddCommMonoid M] [Module R M]
/-- The average value of `g` on the first `n` points of the orbit of `x` under `f`,
i.e. the Birkhoff sum `∑ k ∈ Finset.range n, g (f^[k] x)` divided by `n`.
This average appears in many ergodic theorems
which say that `(birkhoffAverage R f g · x)`
converges to the "space average" `⨍ x, g x ∂μ` as `n → ∞`.
We use an auxiliary `[DivisionSemiring R]` to define division by `n`.
However, the definition does not depend on the choice of `R`,
see `birkhoffAverage_congr_ring`. -/
def birkhoffAverage (f : α → α) (g : α → M) (n : ℕ) (x : α) : M := (n : R)⁻¹ • birkhoffSum f g n x
theorem birkhoffAverage_zero (f : α → α) (g : α → M) (x : α) :
birkhoffAverage R f g 0 x = 0 := by simp [birkhoffAverage]
@[simp] theorem birkhoffAverage_zero' (f : α → α) (g : α → M) : birkhoffAverage R f g 0 = 0 :=
funext <| birkhoffAverage_zero _ _ _
theorem birkhoffAverage_one (f : α → α) (g : α → M) (x : α) :
birkhoffAverage R f g 1 x = g x := by simp [birkhoffAverage]
@[simp]
theorem birkhoffAverage_one' (f : α → α) (g : α → M) : birkhoffAverage R f g 1 = g :=
funext <| birkhoffAverage_one R f g
theorem map_birkhoffAverage (S : Type*) {F N : Type*}
[DivisionSemiring S] [AddCommMonoid N] [Module S N] [FunLike F M N]
[AddMonoidHomClass F M N] (g' : F) (f : α → α) (g : α → M) (n : ℕ) (x : α) :
g' (birkhoffAverage R f g n x) = birkhoffAverage S f (g' ∘ g) n x := by
simp only [birkhoffAverage, map_inv_natCast_smul g' R S, map_birkhoffSum]
theorem birkhoffAverage_congr_ring (S : Type*) [DivisionSemiring S] [Module S M]
(f : α → α) (g : α → M) (n : ℕ) (x : α) :
birkhoffAverage R f g n x = birkhoffAverage S f g n x :=
map_birkhoffAverage R S (AddMonoidHom.id M) f g n x
theorem birkhoffAverage_congr_ring' (S : Type*) [DivisionSemiring S] [Module S M] :
birkhoffAverage (α := α) (M := M) R = birkhoffAverage S := by
ext; apply birkhoffAverage_congr_ring
theorem Function.IsFixedPt.birkhoffAverage_eq [CharZero R] {f : α → α} {x : α} (h : IsFixedPt f x)
(g : α → M) {n : ℕ} (hn : n ≠ 0) : birkhoffAverage R f g n x = g x := by
rw [birkhoffAverage, h.birkhoffSum_eq, ← Nat.cast_smul_eq_nsmul R, inv_smul_smul₀]
rwa [Nat.cast_ne_zero]
lemma birkhoffAverage_add {f : α → α} {g g' : α → M} :
birkhoffAverage R f (g + g') = birkhoffAverage R f g + birkhoffAverage R f g' := by
funext _ x
simp [birkhoffAverage, birkhoffSum, sum_add_distrib, smul_add]
end birkhoffAverage
section AddCommGroup
variable {R : Type*} {α M : Type*} [DivisionSemiring R] [AddCommGroup M] [Module R M]
lemma birkhoffAverage_neg {f : α → α} {g : α → M} :
birkhoffAverage R f (-g) = - birkhoffAverage R f g := by
funext _ x
simp [birkhoffAverage, birkhoffSum]
lemma birkhoffAverage_sub {f : α → α} {g g' : α → M} :
birkhoffAverage R f (g - g') = birkhoffAverage R f g - birkhoffAverage R f g' := by
funext _ x
simp [birkhoffAverage, birkhoffSum, smul_sub]
/-- Birkhoff average is "almost invariant" under `f`:
the difference between `birkhoffAverage R f g n (f x)` and `birkhoffAverage R f g n x`
is equal to `(n : R)⁻¹ • (g (f^[n] x) - g x)`. -/
theorem birkhoffAverage_apply_sub_birkhoffAverage (f : α → α) (g : α → M) (n : ℕ) (x : α) :
birkhoffAverage R f g n (f x) - birkhoffAverage R f g n x =
(n : R)⁻¹ • (g (f^[n] x) - g x) := by
simp only [birkhoffAverage, birkhoffSum_apply_sub_birkhoffSum, ← smul_sub]
/-- If a function `g` is invariant under a function `f` (i.e., `g ∘ f = g`), then the Birkhoff
average of `g` over `f` for `n` iterations is equal to `g`. Requires that `0 < n`. -/
theorem birkhoffAverage_of_comp_eq [CharZero R] {f : α → α} {g : α → M} (h : g ∘ f = g)
{n : ℕ} (hn : n ≠ 0) : birkhoffAverage R f g n = g := by
funext x
suffices (n : R)⁻¹ • n • g x = g x by simpa [birkhoffAverage, birkhoffSum_of_comp_eq h]
rw [← Nat.cast_smul_eq_nsmul (R := R), ← mul_smul, inv_mul_cancel₀ (by norm_cast), one_smul]
end AddCommGroup
|
Extension.lean
|
import Mathlib.RingTheory.Extension.Basic
deprecated_module (since := "2025-05-11")
|
instances.lean
|
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Order.GroupWithZero.Synonym
import Mathlib.Algebra.Order.Ring.Nat
lemma foo (a b : ℕ) (ha : a ≠ 0) (hb : b ≠ 0) : a * b ≠ 0 := by
apply_rules [mul_ne_zero]
|
Prod.lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Order.Monoid.Prod
import Mathlib.Tactic.Linter.DeprecatedModule
deprecated_module (since := "2025-04-16")
|
Finite.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Data.Finite.Sum
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.GroupTheory.Perm.Support
import Mathlib.Logic.Equiv.Fintype
/-!
# Permutations on `Fintype`s
This file contains miscellaneous lemmas about `Equiv.Perm` and `Equiv.swap`, building on top
of those in `Mathlib/Logic/Equiv/Basic.lean` and other files in `Mathlib/GroupTheory/Perm/*`.
-/
universe u v
open Equiv Function Fintype Finset
variable {α : Type u} {β : Type v}
-- An example on how to determine the order of an element of a finite group.
-- import Mathlib.Data.Int.Order.Units
-- example : orderOf (-1 : ℤˣ) = 2 :=
-- orderOf_eq_prime (Int.units_sq _) (by decide)
namespace Equiv.Perm
section Conjugation
variable [DecidableEq α] [Fintype α] {σ τ : Perm α}
theorem isConj_of_support_equiv
(f : { x // x ∈ (σ.support : Set α) } ≃ { x // x ∈ (τ.support : Set α) })
(hf : ∀ (x : α) (hx : x ∈ (σ.support : Set α)),
(f ⟨σ x, apply_mem_support.2 hx⟩ : α) = τ ↑(f ⟨x, hx⟩)) :
IsConj σ τ := by
refine isConj_iff.2 ⟨Equiv.extendSubtype f, ?_⟩
rw [mul_inv_eq_iff_eq_mul]
ext x
simp only [Perm.mul_apply]
by_cases hx : x ∈ σ.support
· rw [Equiv.extendSubtype_apply_of_mem, Equiv.extendSubtype_apply_of_mem]
· exact hf x (Finset.mem_coe.2 hx)
· rwa [Classical.not_not.1 ((not_congr mem_support).1 (Equiv.extendSubtype_not_mem f _ _)),
Classical.not_not.1 ((not_congr mem_support).mp hx)]
end Conjugation
theorem perm_inv_on_of_perm_on_finset {s : Finset α} {f : Perm α} (h : ∀ x ∈ s, f x ∈ s) {y : α}
(hy : y ∈ s) : f⁻¹ y ∈ s := by
have h0 : ∀ y ∈ s, ∃ (x : _) (hx : x ∈ s), y = (fun i (_ : i ∈ s) => f i) x hx :=
Finset.surj_on_of_inj_on_of_card_le (fun x hx => (fun i _ => f i) x hx) (fun a ha => h a ha)
(fun a₁ a₂ ha₁ ha₂ heq => (Equiv.apply_eq_iff_eq f).mp heq) rfl.ge
obtain ⟨y2, hy2, heq⟩ := h0 y hy
convert hy2
rw [heq]
simp only [inv_apply_self]
theorem perm_inv_mapsTo_of_mapsTo (f : Perm α) {s : Set α} [Finite s] (h : Set.MapsTo f s s) :
Set.MapsTo (f⁻¹ :) s s := by
cases nonempty_fintype s
exact fun x hx =>
Set.mem_toFinset.mp <|
perm_inv_on_of_perm_on_finset
(fun a ha => Set.mem_toFinset.mpr (h (Set.mem_toFinset.mp ha)))
(Set.mem_toFinset.mpr hx)
@[simp]
theorem perm_inv_mapsTo_iff_mapsTo {f : Perm α} {s : Set α} [Finite s] :
Set.MapsTo (f⁻¹ :) s s ↔ Set.MapsTo f s s :=
⟨perm_inv_mapsTo_of_mapsTo f⁻¹, perm_inv_mapsTo_of_mapsTo f⟩
theorem perm_inv_on_of_perm_on_finite {f : Perm α} {p : α → Prop} [Finite { x // p x }]
(h : ∀ x, p x → p (f x)) {x : α} (hx : p x) : p (f⁻¹ x) := by
have : Finite { x | p x } := by simpa
simpa using perm_inv_mapsTo_of_mapsTo (s := {x | p x}) f h hx
/-- If the permutation `f` maps `{x // p x}` into itself, then this returns the permutation
on `{x // p x}` induced by `f`. Note that the `h` hypothesis is weaker than for
`Equiv.Perm.subtypePerm`. -/
abbrev subtypePermOfFintype (f : Perm α) {p : α → Prop} [Finite { x // p x }]
(h : ∀ x, p x → p (f x)) : Perm { x // p x } :=
f.subtypePerm fun x => ⟨fun h₂ => f.inv_apply_self x ▸ perm_inv_on_of_perm_on_finite h h₂, h x⟩
@[simp]
theorem subtypePermOfFintype_apply (f : Perm α) {p : α → Prop} [Finite { x // p x }]
(h : ∀ x, p x → p (f x)) (x : { x // p x }) : subtypePermOfFintype f h x = ⟨f x, h x x.2⟩ :=
rfl
theorem subtypePermOfFintype_one (p : α → Prop) [Finite { x // p x }]
(h : ∀ x, p x → p ((1 : Perm α) x)) : @subtypePermOfFintype α 1 p _ h = 1 :=
rfl
theorem perm_mapsTo_inl_iff_mapsTo_inr {m n : Type*} [Finite m] [Finite n] (σ : Perm (m ⊕ n)) :
Set.MapsTo σ (Set.range Sum.inl) (Set.range Sum.inl) ↔
Set.MapsTo σ (Set.range Sum.inr) (Set.range Sum.inr) := by
constructor <;>
( intro h
classical
rw [← perm_inv_mapsTo_iff_mapsTo] at h
intro x
rcases hx : σ x with l | r)
· rintro ⟨a, rfl⟩
obtain ⟨y, hy⟩ := h ⟨l, rfl⟩
rw [← hx, σ.inv_apply_self] at hy
exact absurd hy Sum.inl_ne_inr
· rintro _; exact ⟨r, rfl⟩
· rintro _; exact ⟨l, rfl⟩
· rintro ⟨a, rfl⟩
obtain ⟨y, hy⟩ := h ⟨r, rfl⟩
rw [← hx, σ.inv_apply_self] at hy
exact absurd hy Sum.inr_ne_inl
theorem mem_sumCongrHom_range_of_perm_mapsTo_inl {m n : Type*} [Finite m] [Finite n]
{σ : Perm (m ⊕ n)} (h : Set.MapsTo σ (Set.range Sum.inl) (Set.range Sum.inl)) :
σ ∈ (sumCongrHom m n).range := by
classical
have h1 : ∀ x : m ⊕ n, (∃ a : m, Sum.inl a = x) → ∃ a : m, Sum.inl a = σ x := by
rintro x ⟨a, ha⟩
apply h
rw [← ha]
exact ⟨a, rfl⟩
have h3 : ∀ x : m ⊕ n, (∃ b : n, Sum.inr b = x) → ∃ b : n, Sum.inr b = σ x := by
rintro x ⟨b, hb⟩
apply (perm_mapsTo_inl_iff_mapsTo_inr σ).mp h
rw [← hb]
exact ⟨b, rfl⟩
let σ₁' := subtypePermOfFintype σ h1
let σ₂' := subtypePermOfFintype σ h3
let σ₁ := permCongr (Equiv.ofInjective _ Sum.inl_injective).symm σ₁'
let σ₂ := permCongr (Equiv.ofInjective _ Sum.inr_injective).symm σ₂'
rw [MonoidHom.mem_range, Prod.exists]
use σ₁, σ₂
rw [Perm.sumCongrHom_apply]
ext x
rcases x with a | b
· rw [Equiv.sumCongr_apply, Sum.map_inl, permCongr_apply, Equiv.symm_symm,
apply_ofInjective_symm Sum.inl_injective]
rw [ofInjective_apply, Subtype.coe_mk, Subtype.coe_mk]
dsimp [Set.range]
rw [subtypePerm_apply]
· rw [Equiv.sumCongr_apply, Sum.map_inr, permCongr_apply, Equiv.symm_symm,
apply_ofInjective_symm Sum.inr_injective, ofInjective_apply]
dsimp [Set.range]
rw [subtypePerm_apply]
nonrec theorem Disjoint.orderOf {σ τ : Perm α} (hστ : Disjoint σ τ) :
orderOf (σ * τ) = Nat.lcm (orderOf σ) (orderOf τ) :=
haveI h : ∀ n : ℕ, (σ * τ) ^ n = 1 ↔ σ ^ n = 1 ∧ τ ^ n = 1 := fun n => by
rw [hστ.commute.mul_pow, Disjoint.mul_eq_one_iff (hστ.pow_disjoint_pow n n)]
Nat.dvd_antisymm hστ.commute.orderOf_mul_dvd_lcm
(Nat.lcm_dvd
(orderOf_dvd_of_pow_eq_one ((h (orderOf (σ * τ))).mp (pow_orderOf_eq_one (σ * τ))).1)
(orderOf_dvd_of_pow_eq_one ((h (orderOf (σ * τ))).mp (pow_orderOf_eq_one (σ * τ))).2))
theorem Disjoint.extendDomain {p : β → Prop} [DecidablePred p] (f : α ≃ Subtype p)
{σ τ : Perm α} (h : Disjoint σ τ) : Disjoint (σ.extendDomain f) (τ.extendDomain f) := by
intro b
by_cases pb : p b
· refine (h (f.symm ⟨b, pb⟩)).imp ?_ ?_ <;>
· intro h
rw [extendDomain_apply_subtype _ _ pb, h, apply_symm_apply, Subtype.coe_mk]
· left
rw [extendDomain_apply_not_subtype _ _ pb]
theorem Disjoint.isConj_mul [Finite α] {σ τ π ρ : Perm α} (hc1 : IsConj σ π)
(hc2 : IsConj τ ρ) (hd1 : Disjoint σ τ) (hd2 : Disjoint π ρ) : IsConj (σ * τ) (π * ρ) := by
classical
cases nonempty_fintype α
obtain ⟨f, rfl⟩ := isConj_iff.1 hc1
obtain ⟨g, rfl⟩ := isConj_iff.1 hc2
have hd1' := coe_inj.2 hd1.support_mul
have hd2' := coe_inj.2 hd2.support_mul
rw [coe_union] at *
have hd1'' := disjoint_coe.2 (disjoint_iff_disjoint_support.1 hd1)
have hd2'' := disjoint_coe.2 (disjoint_iff_disjoint_support.1 hd2)
refine isConj_of_support_equiv ?_ ?_
· refine
((Equiv.setCongr hd1').trans (Equiv.Set.union hd1'')).trans
((Equiv.sumCongr (subtypeEquiv f fun a => ?_) (subtypeEquiv g fun a => ?_)).trans
((Equiv.setCongr hd2').trans (Equiv.Set.union hd2'')).symm) <;>
· simp only [Set.mem_image, toEmbedding_apply, exists_eq_right, support_conj, coe_map,
apply_eq_iff_eq]
· intro x hx
simp only [trans_apply, symm_trans_apply, Equiv.setCongr_apply, Equiv.setCongr_symm_apply,
Equiv.sumCongr_apply]
rw [hd1', Set.mem_union] at hx
rcases hx with hxσ | hxτ
· rw [mem_coe, mem_support] at hxσ
rw [Set.union_apply_left, Set.union_apply_left]
· simp only [subtypeEquiv_apply, Perm.coe_mul, Sum.map_inl, comp_apply,
Set.union_symm_apply_left, Subtype.coe_mk, apply_eq_iff_eq]
have h := (hd2 (f x)).resolve_left ?_
· rw [mul_apply, mul_apply] at h
rw [h, inv_apply_self, (hd1 x).resolve_left hxσ]
· rwa [mul_apply, mul_apply, inv_apply_self, apply_eq_iff_eq]
· rwa [Subtype.coe_mk, mem_coe, mem_support]
· rwa [Subtype.coe_mk, Perm.mul_apply, (hd1 x).resolve_left hxσ, mem_coe,
apply_mem_support, mem_support]
· rw [mem_coe, ← apply_mem_support, mem_support] at hxτ
rw [Set.union_apply_right, Set.union_apply_right]
· simp only [subtypeEquiv_apply, Perm.coe_mul, Sum.map_inr, comp_apply,
Set.union_symm_apply_right, Subtype.coe_mk]
have h := (hd2 (g (τ x))).resolve_right ?_
· rw [mul_apply, mul_apply] at h
rw [inv_apply_self, h, (hd1 (τ x)).resolve_right hxτ]
· rwa [mul_apply, mul_apply, inv_apply_self, apply_eq_iff_eq]
· rwa [Subtype.coe_mk, mem_coe, ← apply_mem_support, mem_support]
· rwa [Subtype.coe_mk, Perm.mul_apply, (hd1 (τ x)).resolve_right hxτ,
mem_coe, mem_support]
theorem apply_mem_fixedPoints_iff_mem_of_mem_centralizer {g p : Perm α}
(hp : p ∈ Subgroup.centralizer {g}) {x : α} :
p x ∈ Function.fixedPoints g ↔ x ∈ Function.fixedPoints g := by
simp only [Subgroup.mem_centralizer_singleton_iff] at hp
simp only [Function.mem_fixedPoints_iff]
rw [← mul_apply, ← hp, mul_apply, EmbeddingLike.apply_eq_iff_eq]
@[deprecated (since := "2025-05-19")]
alias mem_fixedPoints_iff_apply_mem_of_mem_centralizer :=
apply_mem_fixedPoints_iff_mem_of_mem_centralizer
variable [DecidableEq α]
lemma disjoint_ofSubtype_of_memFixedPoints_self {g : Perm α}
(u : Perm (Function.fixedPoints g)) :
Disjoint (ofSubtype u) g := by
rw [disjoint_iff_eq_or_eq]
intro x
by_cases hx : x ∈ Function.fixedPoints g
· right; exact hx
· left; rw [ofSubtype_apply_of_not_mem u hx]
section Fintype
variable [Fintype α]
theorem support_pow_coprime {σ : Perm α} {n : ℕ} (h : Nat.Coprime n (orderOf σ)) :
(σ ^ n).support = σ.support := by
obtain ⟨m, hm⟩ := exists_pow_eq_self_of_coprime h
exact
le_antisymm (support_pow_le σ n)
(le_trans (ge_of_eq (congr_arg support hm)) (support_pow_le (σ ^ n) m))
lemma ofSubtype_support_disjoint {σ : Perm α} (x : Perm (Function.fixedPoints σ)) :
_root_.Disjoint x.ofSubtype.support σ.support := by
rw [Finset.disjoint_iff_ne]
rintro a ha b hb rfl
rw [mem_support] at ha hb
exact ha (ofSubtype_apply_of_not_mem x (mt Function.mem_fixedPoints_iff.mp hb))
open Subgroup
lemma disjoint_of_disjoint_support {H K : Subgroup (Perm α)}
(h : ∀ a ∈ H, ∀ b ∈ K, _root_.Disjoint a.support b.support) :
_root_.Disjoint H K := by
rw [disjoint_iff_inf_le]
intro x ⟨hx1, hx2⟩
specialize h x hx1 x hx2
rwa [disjoint_self, Finset.bot_eq_empty, support_eq_empty_iff] at h
lemma support_closure_subset_union (S : Set (Perm α)) :
∀ a ∈ closure S, (a.support : Set α) ⊆ ⋃ b ∈ S, b.support := by
apply closure_induction
· exact fun x hx ↦ Set.subset_iUnion₂_of_subset x hx subset_rfl
· simp only [support_one, Finset.coe_empty, Set.empty_subset]
· intro a b ha hb hc hd
refine (Finset.coe_subset.mpr (support_mul_le a b)).trans ?_
rw [Finset.sup_eq_union, Finset.coe_union, Set.union_subset_iff]
exact ⟨hc, hd⟩
· simp only [support_inv, imp_self, implies_true]
lemma disjoint_support_closure_of_disjoint_support {S T : Set (Perm α)}
(h : ∀ a ∈ S, ∀ b ∈ T, _root_.Disjoint a.support b.support) :
∀ a ∈ closure S, ∀ b ∈ closure T, _root_.Disjoint a.support b.support := by
intro a ha b hb
have key1 := support_closure_subset_union S a ha
have key2 := support_closure_subset_union T b hb
have key := Set.disjoint_of_subset key1 key2
simp_rw [Set.disjoint_iUnion_left, Set.disjoint_iUnion_right, Finset.disjoint_coe] at key
exact key h
lemma disjoint_closure_of_disjoint_support {S T : Set (Perm α)}
(h : ∀ a ∈ S, ∀ b ∈ T, _root_.Disjoint a.support b.support) :
_root_.Disjoint (closure S) (closure T) := by
apply disjoint_of_disjoint_support
apply disjoint_support_closure_of_disjoint_support
exact h
end Fintype
end Equiv.Perm
|
all_field.v
|
From mathcomp Require Export algC.
From mathcomp Require Export algebraics_fundamentals.
From mathcomp Require Export algnum.
From mathcomp Require Export closed_field.
From mathcomp Require Export cyclotomic.
From mathcomp Require Export falgebra.
From mathcomp Require Export fieldext.
From mathcomp Require Export finfield.
From mathcomp Require Export galois.
From mathcomp Require Export separable.
From mathcomp Require Export qfpoly.
|
Pi.lean
|
/-
Copyright (c) 2024 Judith Ludwig, Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Judith Ludwig, Christian Merten
-/
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.LinearAlgebra.Pi
/-!
# Tensor product and products
In this file we examine the behaviour of the tensor product with arbitrary and finite products.
Let `S` be an `R`-algebra, `N` an `S`-module, `ι` an index type and `Mᵢ` a family of `R`-modules.
We then have a natural map
`TensorProduct.piRightHom`: `N ⊗[R] (∀ i, M i) →ₗ[S] ∀ i, N ⊗[R] M i`
In general, this is not an isomorphism, but if `ι` is finite, then it is
and it is packaged as `TensorProduct.piRight`. Also a special case for when `Mᵢ = R` is given.
## Notes
See `Mathlib/LinearAlgebra/TensorProduct/Prod.lean` for binary products.
-/
variable (R : Type*) [CommSemiring R]
variable (S : Type*) [CommSemiring S] [Algebra R S]
variable (N : Type*) [AddCommMonoid N] [Module R N] [Module S N] [IsScalarTower R S N]
variable (ι : Type*)
open LinearMap
namespace TensorProduct
section
variable {ι} (M : ι → Type*) [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
private def piRightHomBil : N →ₗ[S] (∀ i, M i) →ₗ[R] ∀ i, N ⊗[R] M i where
toFun n := LinearMap.pi (fun i ↦ mk R N (M i) n ∘ₗ LinearMap.proj i)
map_add' _ _ := by
ext
simp
map_smul' _ _ := rfl
/-- For any `R`-module `N`, index type `ι` and family of `R`-modules `Mᵢ`, there is a natural
linear map `N ⊗[R] (∀ i, M i) →ₗ ∀ i, N ⊗[R] M i`. This map is an isomorphism if `ι` is finite. -/
def piRightHom : N ⊗[R] (∀ i, M i) →ₗ[S] ∀ i, N ⊗[R] M i :=
AlgebraTensorModule.lift <| piRightHomBil R S N M
@[simp]
lemma piRightHom_tmul (x : N) (f : ∀ i, M i) :
piRightHom R S N M (x ⊗ₜ f) = (fun j ↦ x ⊗ₜ f j) :=
rfl
variable [Fintype ι] [DecidableEq ι]
private
def piRightInv : (∀ i, N ⊗[R] M i) →ₗ[S] N ⊗[R] ∀ i, M i :=
LinearMap.lsum S (fun i ↦ N ⊗[R] M i) S <| fun i ↦
AlgebraTensorModule.map LinearMap.id (single R M i)
@[simp]
private lemma piRightInv_apply (x : N) (m : ∀ i, M i) :
piRightInv R S N M (fun i ↦ x ⊗ₜ m i) = x ⊗ₜ m := by
simp only [piRightInv, lsum_apply, coeFn_sum, coe_comp, coe_proj, Finset.sum_apply,
Function.comp_apply, Function.eval, AlgebraTensorModule.map_tmul, id_coe, id_eq, coe_single]
rw [← tmul_sum]
congr
ext j
simp
@[simp]
private lemma piRightInv_single (x : N) (i : ι) (m : M i) :
piRightInv R S N M (Pi.single i (x ⊗ₜ m)) = x ⊗ₜ Pi.single i m := by
have : Pi.single i (x ⊗ₜ m) = fun j ↦ x ⊗ₜ[R] (Pi.single i m j) := by
ext j
rw [← tmul_single]
rw [this]
simp
/-- Tensor product commutes with finite products on the right. -/
def piRight : N ⊗[R] (∀ i, M i) ≃ₗ[S] ∀ i, N ⊗[R] M i :=
LinearEquiv.ofLinear
(piRightHom R S N M)
(piRightInv R S N M)
(by ext i x m j; simp [tmul_single])
(by ext x j m; simp)
@[simp]
lemma piRight_apply (x : N ⊗[R] (∀ i, M i)) :
piRight R S N M x = piRightHom R S N M x := by
rfl
@[simp]
lemma piRight_symm_apply (x : N) (m : ∀ i, M i) :
(piRight R S N M).symm (fun i ↦ x ⊗ₜ m i) = x ⊗ₜ m := by
simp [piRight]
@[simp]
lemma piRight_symm_single (x : N) (i : ι) (m : M i) :
(piRight R S N M).symm (Pi.single i (x ⊗ₜ m)) = x ⊗ₜ Pi.single i m := by
simp [piRight]
end
private def piScalarRightHomBil : N →ₗ[S] (ι → R) →ₗ[R] (ι → N) where
toFun n := LinearMap.compLeft (toSpanSingleton R N n) ι
map_add' x y := by
ext i j
simp
map_smul' s x := by
ext i j
dsimp only [coe_comp, coe_single, Function.comp_apply, compLeft_apply, toSpanSingleton_apply,
RingHom.id_apply, smul_apply, Pi.smul_apply]
rw [← IsScalarTower.smul_assoc, _root_.Algebra.smul_def, mul_comm, mul_smul]
simp
/-- For any `R`-module `N` and index type `ι`, there is a natural
linear map `N ⊗[R] (ι → R) →ₗ (ι → N)`. This map is an isomorphism if `ι` is finite. -/
def piScalarRightHom : N ⊗[R] (ι → R) →ₗ[S] (ι → N) :=
AlgebraTensorModule.lift <| piScalarRightHomBil R S N ι
@[simp]
lemma piScalarRightHom_tmul (x : N) (f : ι → R) :
piScalarRightHom R S N ι (x ⊗ₜ f) = (fun j ↦ f j • x) := by
ext j
simp [piScalarRightHom, piScalarRightHomBil]
variable [Fintype ι] [DecidableEq ι]
private
def piScalarRightInv : (ι → N) →ₗ[S] N ⊗[R] (ι → R) :=
LinearMap.lsum S (fun _ ↦ N) S <| fun i ↦ {
toFun := fun n ↦ n ⊗ₜ Pi.single i 1
map_add' := fun x y ↦ by simp [add_tmul]
map_smul' := fun _ _ ↦ rfl
}
@[simp]
private lemma piScalarRightInv_single (x : N) (i : ι) :
piScalarRightInv R S N ι (Pi.single i x) = x ⊗ₜ Pi.single i 1 := by
simp [piScalarRightInv, Pi.single_apply, TensorProduct.ite_tmul]
/-- For any `R`-module `N` and finite index type `ι`, `N ⊗[R] (ι → R)` is canonically
isomorphic to `ι → N`. -/
def piScalarRight : N ⊗[R] (ι → R) ≃ₗ[S] (ι → N) :=
LinearEquiv.ofLinear
(piScalarRightHom R S N ι)
(piScalarRightInv R S N ι)
(by ext i x j; simp [Pi.single_apply])
(by ext x i; simp [Pi.single_apply_smul])
@[simp]
lemma piScalarRight_apply (x : N ⊗[R] (ι → R)) :
piScalarRight R S N ι x = piScalarRightHom R S N ι x := by
rfl
@[simp]
lemma piScalarRight_symm_single (x : N) (i : ι) :
(piScalarRight R S N ι).symm (Pi.single i x) = x ⊗ₜ Pi.single i 1 := by
simp [piScalarRight]
end TensorProduct
|
Basic.lean
|
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Jireh Loreaux
-/
import Mathlib.Algebra.Ring.Hom.InjSurj
import Mathlib.Deprecated.RingHom
import Mathlib.Tactic.Linter.DeprecatedModule
deprecated_module (since := "2025-06-09")
|
Basic.lean
|
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Probability.Independence.Kernel
import Mathlib.MeasureTheory.Constructions.Pi
import Mathlib.MeasureTheory.Group.Convolution
/-!
# Independence of sets of sets and measure spaces (σ-algebras)
* A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for
any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`,
`μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. It will be used for families of π-systems.
* A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. I.e., `m : ι → MeasurableSpace Ω` is independent with respect to a
measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`.
* Independence of sets (or events in probabilistic parlance) is defined as independence of the
measurable space structures they generate: a set `s` generates the measurable space structure with
measurable sets `∅, s, sᶜ, univ`.
* Independence of functions (or random variables) is also defined as independence of the measurable
space structures they generate: a function `f` for which we have a measurable space `m` on the
codomain generates `MeasurableSpace.comap f m`.
## Main statements
* `iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the
measurable space structures they generate are independent.
* `IndepSets.indep`: variant with two π-systems.
## Implementation notes
The definitions of independence in this file are a particular case of independence with respect to a
kernel and a measure, as defined in the file `Kernel.lean`.
We provide four definitions of independence:
* `iIndepSets`: independence of a family of sets of sets `pi : ι → Set (Set Ω)`. This is meant to
be used with π-systems.
* `iIndep`: independence of a family of measurable space structures `m : ι → MeasurableSpace Ω`,
* `iIndepSet`: independence of a family of sets `s : ι → Set Ω`,
* `iIndepFun`: independence of a family of functions. For measurable spaces
`m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`.
Additionally, we provide four corresponding statements for two measurable space structures (resp.
sets of sets, sets, functions) instead of a family. These properties are denoted by the same names
as for a family, but without the starting `i`, for example `IndepFun` is the version of `iIndepFun`
for two functions.
The definition of independence for `iIndepSets` uses finite sets (`Finset`). See
`ProbabilityTheory.Kernel.iIndepSets`. An alternative and equivalent way of defining independence
would have been to use countable sets.
Most of the definitions and lemmas in this file list all variables instead of using the `variable`
keyword at the beginning of a section, for example
`lemma Indep.symm {Ω} {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : measure Ω} ...` .
This is intentional, to be able to control the order of the `MeasurableSpace` variables. Indeed
when defining `μ` in the example above, the measurable space used is the last one defined, here
`{_mΩ : MeasurableSpace Ω}`, and not `m₁` or `m₂`.
## References
* Williams, David. Probability with martingales. Cambridge university press, 1991.
Part A, Chapter 4.
-/
assert_not_exists MeasureTheory.Integrable
open MeasureTheory MeasurableSpace Set
open scoped MeasureTheory ENNReal
namespace ProbabilityTheory
variable {Ω ι β γ : Type*} {κ : ι → Type*}
section Definitions
/-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i) `.
It will be used for families of pi_systems. -/
def iIndepSets {_mΩ : MeasurableSpace Ω}
(π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.iIndepSets π (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two sets of sets `s₁, s₂` are independent with respect to a measure `μ` if for any sets
`t₁ ∈ p₁, t₂ ∈ s₂`, then `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def IndepSets {_mΩ : MeasurableSpace Ω}
(s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.IndepSets s1 s2 (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a
measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they
define is independent. `m : ι → MeasurableSpace Ω` is independent with respect to measure `μ` if
for any finite set of indices `s = {i_1, ..., i_n}`, for any sets
`f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. -/
def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) :
Prop :=
Kernel.iIndep m (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a
measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`,
`μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/
def Indep (m₁ m₂ : MeasurableSpace Ω)
{_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.Indep m₁ m₂ (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- A family of sets is independent if the family of measurable space structures they generate is
independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/
def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.iIndepSet s (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two sets are independent if the two measurable space structures they generate are independent.
For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/
def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.IndepSet s t (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- A family of functions defined on the same space `Ω` and taking values in possibly different
spaces, each with a measurable space structure, is independent if the family of measurable space
structures they generate on `Ω` is independent. For a function `g` with codomain having measurable
space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/
def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)]
(f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.iIndepFun f (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
/-- Two functions are independent if the two measurable space structures they generate are
independent. For a function `f` with codomain having measurable space structure `m`, the generated
measurable space structure is `MeasurableSpace.comap f m`. -/
def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [MeasurableSpace β] [MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) : Prop :=
Kernel.IndepFun f g (Kernel.const Unit μ) (Measure.dirac () : Measure Unit)
end Definitions
section Definition_lemmas
variable {π : ι → Set (Set Ω)} {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω}
{S : Finset ι} {s : ι → Set Ω}
lemma iIndepSets_iff (π : ι → Set (Set Ω)) (μ : Measure Ω) :
iIndepSets π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i),
μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simp only [iIndepSets, Kernel.iIndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply]
lemma iIndepSets.meas_biInter (h : iIndepSets π μ) (s : Finset ι) {f : ι → Set Ω}
(hf : ∀ i, i ∈ s → f i ∈ π i) : μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) :=
(iIndepSets_iff _ _).1 h s hf
lemma iIndepSets.isProbabilityMeasure (h : iIndepSets π μ) : IsProbabilityMeasure μ :=
⟨by simpa using h ∅ (f := fun _ ↦ univ)⟩
lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π μ) (hs : ∀ i, s i ∈ π i) :
μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← h.meas_biInter _ fun _i _ ↦ hs _]
lemma IndepSets_iff (s1 s2 : Set (Set Ω)) (μ : Measure Ω) :
IndepSets s1 s2 μ ↔ ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (μ (t1 ∩ t2) = μ t1 * μ t2) := by
simp only [IndepSets, Kernel.IndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply]
lemma iIndep_iff_iIndepSets (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
iIndep m μ ↔ iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := by
simp only [iIndep, iIndepSets, Kernel.iIndep]
lemma iIndep.iIndepSets' {m : ι → MeasurableSpace Ω}
{_ : MeasurableSpace Ω} {μ : Measure Ω} (hμ : iIndep m μ) :
iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := (iIndep_iff_iIndepSets _ _).1 hμ
lemma iIndep.isProbabilityMeasure (h : iIndep m μ) : IsProbabilityMeasure μ :=
h.iIndepSets'.isProbabilityMeasure
lemma iIndep_iff (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
iIndep m μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)),
μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simp only [iIndep_iff_iIndepSets, iIndepSets_iff]; rfl
lemma iIndep.meas_biInter (hμ : iIndep m μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) :
μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := (iIndep_iff _ _).1 hμ _ hs
lemma iIndep.meas_iInter [Fintype ι] (hμ : iIndep m μ) (hs : ∀ i, MeasurableSet[m i] (s i)) :
μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← hμ.meas_biInter fun _ _ ↦ hs _]
lemma Indep_iff_IndepSets (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
Indep m₁ m₂ μ ↔ IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by
simp only [Indep, IndepSets, Kernel.Indep]
lemma Indep_iff (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) :
Indep m₁ m₂ μ
↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by
rw [Indep_iff_IndepSets, IndepSets_iff]; rfl
lemma iIndepSet_iff_iIndep (s : ι → Set Ω) (μ : Measure Ω) :
iIndepSet s μ ↔ iIndep (fun i ↦ generateFrom {s i}) μ := by
simp only [iIndepSet, iIndep, Kernel.iIndepSet]
lemma iIndepSet.isProbabilityMeasure (h : iIndepSet s μ) : IsProbabilityMeasure μ :=
((iIndepSet_iff_iIndep _ _).1 h).isProbabilityMeasure
lemma iIndepSet_iff (s : ι → Set Ω) (μ : Measure Ω) :
iIndepSet s μ ↔ ∀ (s' : Finset ι) {f : ι → Set Ω}
(_H : ∀ i, i ∈ s' → MeasurableSet[generateFrom {s i}] (f i)),
μ (⋂ i ∈ s', f i) = ∏ i ∈ s', μ (f i) := by
simp only [iIndepSet_iff_iIndep, iIndep_iff]
lemma IndepSet_iff_Indep (s t : Set Ω) (μ : Measure Ω) :
IndepSet s t μ ↔ Indep (generateFrom {s}) (generateFrom {t}) μ := by
simp only [IndepSet, Indep, Kernel.IndepSet]
lemma IndepSet_iff (s t : Set Ω) (μ : Measure Ω) :
IndepSet s t μ ↔ ∀ t1 t2, MeasurableSet[generateFrom {s}] t1
→ MeasurableSet[generateFrom {t}] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by
simp only [IndepSet_iff_Indep, Indep_iff]
lemma iIndepFun_iff_iIndep {β : ι → Type*}
(m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) :
iIndepFun f μ ↔ iIndep (fun x ↦ (m x).comap (f x)) μ := by
simp only [iIndepFun, iIndep, Kernel.iIndepFun]
@[nontriviality, simp]
lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} [IsProbabilityMeasure μ] :
iIndepSets m μ := Kernel.iIndepSets.of_subsingleton
@[nontriviality, simp]
lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} [IsProbabilityMeasure μ] :
iIndep m μ := Kernel.iIndep.of_subsingleton
@[nontriviality, simp]
lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)}
{f : ∀ i, Ω → β i} [IsProbabilityMeasure μ] : iIndepFun f μ :=
Kernel.iIndepFun.of_subsingleton
protected lemma iIndepFun.iIndep {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x}
(hf : iIndepFun f μ) :
iIndep (fun x ↦ (m x).comap (f x)) μ := hf
lemma iIndepFun_iff {β : ι → Type*}
(m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) :
iIndepFun f μ ↔ ∀ (s : Finset ι) {f' : ι → Set Ω}
(_H : ∀ i, i ∈ s → MeasurableSet[(m i).comap (f i)] (f' i)),
μ (⋂ i ∈ s, f' i) = ∏ i ∈ s, μ (f' i) := by
simp only [iIndepFun_iff_iIndep, iIndep_iff]
lemma iIndepFun.meas_biInter {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x}
(hf : iIndepFun f μ) (hs : ∀ i, i ∈ S → MeasurableSet[(m i).comap (f i)] (s i)) :
μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := hf.iIndep.meas_biInter hs
lemma iIndepFun.meas_iInter [Fintype ι] {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x}
(hf : iIndepFun f μ) (hs : ∀ i, MeasurableSet[(m i).comap (f i)] (s i)) :
μ (⋂ i, s i) = ∏ i, μ (s i) := hf.iIndep.meas_iInter hs
lemma IndepFun_iff_Indep [mβ : MeasurableSpace β]
[mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) :
IndepFun f g μ ↔ Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) μ := by
simp only [IndepFun, Indep, Kernel.IndepFun]
lemma IndepFun_iff {β γ} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ]
(f : Ω → β) (g : Ω → γ) (μ : Measure Ω) :
IndepFun f g μ ↔ ∀ t1 t2, MeasurableSet[MeasurableSpace.comap f mβ] t1
→ MeasurableSet[MeasurableSpace.comap g mγ] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by
rw [IndepFun_iff_Indep, Indep_iff]
lemma IndepFun.meas_inter [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ}
(hfg : IndepFun f g μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s)
(ht : MeasurableSet[mγ.comap g] t) :
μ (s ∩ t) = μ s * μ t :=
(IndepFun_iff _ _ _).1 hfg _ _ hs ht
end Definition_lemmas
section Indep
variable {m₁ m₂ m₃ : MeasurableSpace Ω} (m' : MeasurableSpace Ω)
{_mΩ : MeasurableSpace Ω} {μ : Measure Ω}
@[symm]
theorem IndepSets.symm {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ μ) : IndepSets s₂ s₁ μ :=
Kernel.IndepSets.symm h
@[symm]
theorem Indep.symm (h : Indep m₁ m₂ μ) : Indep m₂ m₁ μ := IndepSets.symm h
theorem indep_bot_right [IsZeroOrProbabilityMeasure μ] : Indep m' ⊥ μ :=
Kernel.indep_bot_right m'
theorem indep_bot_left [IsZeroOrProbabilityMeasure μ] : Indep ⊥ m' μ := (indep_bot_right m').symm
theorem indepSet_empty_right [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet s ∅ μ :=
Kernel.indepSet_empty_right s
theorem indepSet_empty_left [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet ∅ s μ :=
Kernel.indepSet_empty_left s
theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)}
(h_indep : IndepSets s₁ s₂ μ) (h31 : s₃ ⊆ s₁) :
IndepSets s₃ s₂ μ :=
Kernel.indepSets_of_indepSets_of_le_left h_indep h31
theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)}
(h_indep : IndepSets s₁ s₂ μ) (h32 : s₃ ⊆ s₂) :
IndepSets s₁ s₃ μ :=
Kernel.indepSets_of_indepSets_of_le_right h_indep h32
theorem indep_of_indep_of_le_left (h_indep : Indep m₁ m₂ μ) (h31 : m₃ ≤ m₁) :
Indep m₃ m₂ μ :=
Kernel.indep_of_indep_of_le_left h_indep h31
theorem indep_of_indep_of_le_right (h_indep : Indep m₁ m₂ μ) (h32 : m₃ ≤ m₂) :
Indep m₁ m₃ μ :=
Kernel.indep_of_indep_of_le_right h_indep h32
theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} (h₁ : IndepSets s₁ s' μ) (h₂ : IndepSets s₂ s' μ) :
IndepSets (s₁ ∪ s₂) s' μ :=
Kernel.IndepSets.union h₁ h₂
@[simp]
theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} :
IndepSets (s₁ ∪ s₂) s' μ ↔ IndepSets s₁ s' μ ∧ IndepSets s₂ s' μ :=
Kernel.IndepSets.union_iff
theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
(hyp : ∀ n, IndepSets (s n) s' μ) :
IndepSets (⋃ n, s n) s' μ :=
Kernel.IndepSets.iUnion hyp
theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
{u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' μ) :
IndepSets (⋃ n ∈ u, s n) s' μ :=
Kernel.IndepSets.bUnion hyp
theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) (h₁ : IndepSets s₁ s' μ) :
IndepSets (s₁ ∩ s₂) s' μ :=
Kernel.IndepSets.inter s₂ h₁
theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
(h : ∃ n, IndepSets (s n) s' μ) :
IndepSets (⋂ n, s n) s' μ :=
Kernel.IndepSets.iInter h
theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)}
{u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' μ) :
IndepSets (⋂ n ∈ u, s n) s' μ :=
Kernel.IndepSets.bInter h
theorem indepSets_singleton_iff {s t : Set Ω} :
IndepSets {s} {t} μ ↔ μ (s ∩ t) = μ s * μ t := by
simp only [IndepSets, Kernel.indepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure,
Kernel.const_apply]
end Indep
/-! ### Deducing `Indep` from `iIndep` -/
section FromIndepToIndep
variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω}
theorem iIndepSets.indepSets {s : ι → Set (Set Ω)}
(h_indep : iIndepSets s μ) {i j : ι} (hij : i ≠ j) : IndepSets (s i) (s j) μ :=
Kernel.iIndepSets.indepSets h_indep hij
theorem iIndep.indep
(h_indep : iIndep m μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) μ :=
Kernel.iIndep.indep h_indep hij
theorem iIndepFun.indepFun {β : ι → Type*}
{m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun f μ) {i j : ι}
(hij : i ≠ j) :
IndepFun (f i) (f j) μ :=
Kernel.iIndepFun.indepFun hf_Indep hij
end FromIndepToIndep
/-!
## π-system lemma
Independence of measurable spaces is equivalent to independence of generating π-systems.
-/
section FromMeasurableSpacesToSetsOfSets
variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω}
/-! ### Independence of measurable space structures implies independence of generating π-systems -/
theorem iIndep.iIndepSets
{s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m μ) :
iIndepSets s μ :=
Kernel.iIndep.iIndepSets hms h_indep
theorem Indep.indepSets {s1 s2 : Set (Set Ω)}
(h_indep : Indep (generateFrom s1) (generateFrom s2) μ) :
IndepSets s1 s2 μ :=
Kernel.Indep.indepSets h_indep
end FromMeasurableSpacesToSetsOfSets
section FromPiSystemsToMeasurableSpaces
variable {m : ι → MeasurableSpace Ω} {m1 m2 _mΩ : MeasurableSpace Ω} {μ : Measure Ω}
/-! ### Independence of generating π-systems implies independence of measurable space structures -/
theorem IndepSets.indep [IsZeroOrProbabilityMeasure μ]
{p1 p2 : Set (Set Ω)} (h1 : m1 ≤ _mΩ) (h2 : m2 ≤ _mΩ) (hp1 : IsPiSystem p1)
(hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2)
(hyp : IndepSets p1 p2 μ) :
Indep m1 m2 μ :=
Kernel.IndepSets.indep h1 h2 hp1 hp2 hpm1 hpm2 hyp
theorem IndepSets.indep' [IsZeroOrProbabilityMeasure μ]
{p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s)
(hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 μ) :
Indep (generateFrom p1) (generateFrom p2) μ :=
Kernel.IndepSets.indep' hp1m hp2m hp1 hp2 hyp
theorem indepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)}
{S T : Set ι} (h_indep : iIndepSets s μ) (hST : Disjoint S T) :
IndepSets (piiUnionInter s S) (piiUnionInter s T) μ :=
Kernel.indepSets_piiUnionInter_of_disjoint h_indep hST
theorem iIndepSet.indep_generateFrom_of_disjoint {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (S T : Set ι) (hST : Disjoint S T) :
Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_of_disjoint hsm hs S T hST
theorem indep_iSup_of_disjoint
(h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m μ) {S T : Set ι} (hST : Disjoint S T) :
Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) μ :=
Kernel.indep_iSup_of_disjoint h_le h_indep hST
theorem indep_iSup_of_directed_le
[IsZeroOrProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ)
(h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Directed (· ≤ ·) m) :
Indep (⨆ i, m i) m1 μ :=
Kernel.indep_iSup_of_directed_le h_indep h_le h_le' hm
theorem iIndepSet.indep_generateFrom_lt [Preorder ι] {s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) :
Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_lt hsm hs i
theorem iIndepSet.indep_generateFrom_le [Preorder ι]
{s : ι → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) {k : ι} (hk : i < k) :
Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_le hsm hs i hk
theorem iIndepSet.indep_generateFrom_le_nat {s : ℕ → Set Ω}
(hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (n : ℕ) :
Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) μ :=
Kernel.iIndepSet.indep_generateFrom_le_nat hsm hs n
theorem indep_iSup_of_monotone [SemilatticeSup ι] [IsZeroOrProbabilityMeasure μ]
(h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Monotone m) :
Indep (⨆ i, m i) m1 μ :=
Kernel.indep_iSup_of_monotone h_indep h_le h_le' hm
theorem indep_iSup_of_antitone [SemilatticeInf ι] [IsZeroOrProbabilityMeasure μ]
(h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Antitone m) :
Indep (⨆ i, m i) m1 μ :=
Kernel.indep_iSup_of_antitone h_indep h_le h_le' hm
theorem iIndepSets.piiUnionInter_of_notMem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι}
(hp_ind : iIndepSets π μ) (haS : a ∉ S) :
IndepSets (piiUnionInter π S) (π a) μ :=
Kernel.iIndepSets.piiUnionInter_of_notMem hp_ind haS
@[deprecated (since := "2025-05-23")]
alias iIndepSets.piiUnionInter_of_not_mem := iIndepSets.piiUnionInter_of_notMem
/-- The measurable space structures generated by independent pi-systems are independent. -/
theorem iIndepSets.iIndep
(h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n))
(h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π μ) :
iIndep m μ :=
Kernel.iIndepSets.iIndep m h_le π h_pi h_generate h_ind
end FromPiSystemsToMeasurableSpaces
section IndepSet
/-! ### Independence of measurable sets
We prove the following equivalences on `IndepSet`, for measurable sets `s, t`.
* `IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t`,
* `IndepSet s t μ ↔ IndepSets {s} {t} μ`.
-/
variable {m₁ m₂ _mΩ : MeasurableSpace Ω} {μ : Measure Ω} {s t : Set Ω} (S T : Set (Set Ω))
theorem indepSet_iff_indepSets_singleton (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac)
[IsZeroOrProbabilityMeasure μ] : IndepSet s t μ ↔ IndepSets {s} {t} μ :=
Kernel.indepSet_iff_indepSets_singleton hs_meas ht_meas _ _
theorem indepSet_iff_measure_inter_eq_mul (hs_meas : MeasurableSet s)
(ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac)
[IsZeroOrProbabilityMeasure μ] : IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t :=
(indepSet_iff_indepSets_singleton hs_meas ht_meas μ).trans indepSets_singleton_iff
lemma IndepSet.measure_inter_eq_mul {μ : Measure Ω} (h : IndepSet s t μ) :
μ (s ∩ t) = μ s * μ t := by
simpa using Kernel.IndepSet.measure_inter_eq_mul _ _ h
theorem IndepSets.indepSet_of_mem (hs : s ∈ S) (ht : t ∈ T)
(hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t)
(μ : Measure Ω := by volume_tac) [IsZeroOrProbabilityMeasure μ]
(h_indep : IndepSets S T μ) :
IndepSet s t μ :=
Kernel.IndepSets.indepSet_of_mem _ _ hs ht hs_meas ht_meas _ _ h_indep
theorem Indep.indepSet_of_measurableSet
(h_indep : Indep m₁ m₂ μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s) (ht : MeasurableSet[m₂] t) :
IndepSet s t μ :=
Kernel.Indep.indepSet_of_measurableSet h_indep hs ht
theorem indep_iff_forall_indepSet (μ : Measure Ω) :
Indep m₁ m₂ μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → IndepSet s t μ :=
Kernel.indep_iff_forall_indepSet m₁ m₂ _ _
theorem iIndep_comap_mem_iff {f : ι → Set Ω} :
iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) μ ↔ iIndepSet f μ :=
Kernel.iIndep_comap_mem_iff
alias ⟨_, iIndepSet.iIndep_comap_mem⟩ := iIndep_comap_mem_iff
theorem iIndepSets_singleton_iff {s : ι → Set Ω} :
iIndepSets (fun i ↦ {s i}) μ ↔ ∀ t, μ (⋂ i ∈ t, s i) = ∏ i ∈ t, μ (s i) := by
simp_rw [iIndepSets, Kernel.iIndepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure,
Kernel.const_apply]
theorem iIndepSet.meas_biInter {f : ι → Set Ω} (h : iIndepSet f μ) (s : Finset ι) :
μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simpa using Kernel.iIndepSet.meas_biInter h s
theorem iIndepSet_iff_iIndepSets_singleton {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f μ ↔ iIndepSets (fun i ↦ {f i}) μ :=
Kernel.iIndepSet_iff_iIndepSets_singleton hf
theorem iIndepSet_iff_meas_biInter {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) :
iIndepSet f μ ↔ ∀ s, μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by
simp_rw [iIndepSet, Kernel.iIndepSet_iff_meas_biInter hf, ae_dirac_eq, Filter.eventually_pure,
Kernel.const_apply]
theorem iIndepSets.iIndepSet_of_mem {π : ι → Set (Set Ω)} {f : ι → Set Ω}
(hfπ : ∀ i, f i ∈ π i) (hf : ∀ i, MeasurableSet (f i))
(hπ : iIndepSets π μ) : iIndepSet f μ :=
Kernel.iIndepSets.iIndepSet_of_mem hfπ hf hπ
end IndepSet
section IndepFun
/-! ### Independence of random variables
-/
variable {β β' γ γ' : Type*} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → β} {g : Ω → β'}
theorem indepFun_iff_measure_inter_preimage_eq_mul {mβ : MeasurableSpace β}
{mβ' : MeasurableSpace β'} :
IndepFun f g μ ↔
∀ s t, MeasurableSet s → MeasurableSet t
→ μ (f ⁻¹' s ∩ g ⁻¹' t) = μ (f ⁻¹' s) * μ (g ⁻¹' t) := by
simp only [IndepFun, Kernel.indepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq,
Filter.eventually_pure, Kernel.const_apply]
alias ⟨IndepFun.measure_inter_preimage_eq_mul, _⟩ := indepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*}
{m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} :
iIndepFun f μ ↔
∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)),
μ (⋂ i ∈ S, f i ⁻¹' sets i) = ∏ i ∈ S, μ (f i ⁻¹' sets i) := by
simp only [iIndepFun, Kernel.iIndepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq,
Filter.eventually_pure, Kernel.const_apply]
alias ⟨iIndepFun.measure_inter_preimage_eq_mul, _⟩ := iIndepFun_iff_measure_inter_preimage_eq_mul
theorem iIndepFun_congr {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{f g : Π i, Ω → β i} (h : ∀ i, f i =ᵐ[μ] g i) :
iIndepFun f μ ↔ iIndepFun g μ := Kernel.iIndepFun_congr' (by simp [h])
alias ⟨iIndepFun.congr, _⟩ := iIndepFun_congr
nonrec lemma iIndepFun.comp {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f μ) (g : ∀ i, β i → γ i) (hg : ∀ i, Measurable (g i)) :
iIndepFun (fun i ↦ g i ∘ f i) μ := h.comp _ hg
nonrec lemma iIndepFun.comp₀ {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)}
{mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i}
(h : iIndepFun f μ) (g : ∀ i, β i → γ i)
(hf : ∀ i, AEMeasurable (f i) μ) (hg : ∀ i, AEMeasurable (g i) (μ.map (f i))) :
iIndepFun (fun i ↦ g i ∘ f i) μ := h.comp₀ _ (by simp [hf]) (by simp [hg])
theorem indepFun_iff_indepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsZeroOrProbabilityMeasure μ] (hf : Measurable f) (hg : Measurable g) :
IndepFun f g μ ↔
∀ s t, MeasurableSet s → MeasurableSet t → IndepSet (f ⁻¹' s) (g ⁻¹' t) μ := by
simp only [IndepFun, IndepSet, Kernel.indepFun_iff_indepSet_preimage hf hg]
theorem indepFun_iff_map_prod_eq_prod_map_map' {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
(hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(σf : SigmaFinite (μ.map f)) (σg : SigmaFinite (μ.map g)) :
IndepFun f g μ ↔ μ.map (fun ω ↦ (f ω, g ω)) = (μ.map f).prod (μ.map g) := by
rw [indepFun_iff_measure_inter_preimage_eq_mul]
have h₀ {s : Set β} {t : Set β'} (hs : MeasurableSet s) (ht : MeasurableSet t) :
μ (f ⁻¹' s) * μ (g ⁻¹' t) = μ.map f s * μ.map g t ∧
μ (f ⁻¹' s ∩ g ⁻¹' t) = μ.map (fun ω ↦ (f ω, g ω)) (s ×ˢ t) :=
⟨by rw [Measure.map_apply_of_aemeasurable hf hs, Measure.map_apply_of_aemeasurable hg ht],
(Measure.map_apply_of_aemeasurable (hf.prodMk hg) (hs.prod ht)).symm⟩
constructor
· refine fun h ↦ (Measure.prod_eq fun s t hs ht ↦ ?_).symm
rw [← (h₀ hs ht).1, ← (h₀ hs ht).2, h s t hs ht]
· intro h s t hs ht
rw [(h₀ hs ht).1, (h₀ hs ht).2, h, Measure.prod_prod]
theorem indepFun_iff_map_prod_eq_prod_map_map {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
[IsFiniteMeasure μ] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
IndepFun f g μ ↔ μ.map (fun ω ↦ (f ω, g ω)) = (μ.map f).prod (μ.map g) := by
apply indepFun_iff_map_prod_eq_prod_map_map' hf hg <;> apply IsFiniteMeasure.toSigmaFinite
theorem iIndepFun_iff_map_fun_eq_pi_map [Fintype ι] {β : ι → Type*}
{m : ∀ i, MeasurableSpace (β i)} {f : Π i, Ω → β i} [IsProbabilityMeasure μ]
(hf : ∀ i, AEMeasurable (f i) μ) :
iIndepFun f μ ↔ μ.map (fun ω i ↦ f i ω) = Measure.pi (fun i ↦ μ.map (f i)) := by
classical
rw [iIndepFun_iff_measure_inter_preimage_eq_mul]
have h₀ {s : ∀ i, Set (β i)} (hm : ∀ (i : ι), MeasurableSet (s i)) :
∏ i : ι, μ (f i ⁻¹' s i) = ∏ i : ι, μ.map (f i) (s i) ∧
μ (⋂ i : ι, (f i ⁻¹' s i)) = μ.map (fun ω i ↦ f i ω) (univ.pi s) := by
constructor
· congr with x
rw [Measure.map_apply_of_aemeasurable (hf x) (hm x)]
· rw [Measure.map_apply_of_aemeasurable (aemeasurable_pi_lambda _ fun x ↦ hf x)
(.univ_pi hm)]
congr with x
simp
constructor
· refine fun hS ↦ (Measure.pi_eq fun h hm ↦ ?_).symm
rw [← (h₀ hm).1, ← (h₀ hm).2]
simpa [hm] using hS Finset.univ (sets := h)
· intro h S s hs
specialize h₀ (s := fun i ↦ if i ∈ S then s i else univ)
fun i ↦ by beta_reduce; split_ifs with hiS <;> simp [hiS, hs]
simp only [apply_ite, preimage_univ, measure_univ, Finset.prod_ite_mem, Finset.univ_inter,
Finset.prod_ite, Finset.filter_univ_mem, iInter_ite, iInter_univ, inter_univ, h,
Measure.pi_pi] at h₀
rw [h₀.2, ← h₀.1]
@[symm]
nonrec theorem IndepFun.symm {_ : MeasurableSpace β} {_ : MeasurableSpace β'}
(hfg : IndepFun f g μ) : IndepFun g f μ := hfg.symm
theorem IndepFun.congr {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'}
{f' : Ω → β} {g' : Ω → β'} (hfg : IndepFun f g μ)
(hf : f =ᵐ[μ] f') (hg : g =ᵐ[μ] g') : IndepFun f' g' μ := by
refine Kernel.IndepFun.congr' hfg ?_ ?_ <;> simpa
@[deprecated (since := "2025-03-18")] alias IndepFun.ae_eq := IndepFun.congr
section Prod
variable {Ω Ω' : Type*} {mΩ : MeasurableSpace Ω} {mΩ' : MeasurableSpace Ω'}
{μ : Measure Ω} {ν : Measure Ω'} [IsProbabilityMeasure μ] [IsProbabilityMeasure ν]
{𝓧 𝓨 : Type*} [MeasurableSpace 𝓧] [MeasurableSpace 𝓨] {X : Ω → 𝓧} {Y : Ω' → 𝓨}
/-- Given random variables `X : Ω → 𝓧` and `Y : Ω' → 𝓨`, they are independent when viewed as random
variables defined on the product space `Ω × Ω'`. -/
lemma indepFun_prod (mX : Measurable X) (mY : Measurable Y) :
IndepFun (fun ω ↦ X ω.1) (fun ω ↦ Y ω.2) (μ.prod ν) := by
refine indepFun_iff_map_prod_eq_prod_map_map (by fun_prop) (by fun_prop) |>.2 ?_
convert Measure.map_prod_map μ ν mX mY |>.symm
· change Measure.map (X ∘ _) _ = _
rw [← Measure.map_map mX measurable_fst, Measure.map_fst_prod, measure_univ, one_smul]
· change Measure.map (Y ∘ _) _ = _
rw [← Measure.map_map mY measurable_snd, Measure.map_snd_prod, measure_univ, one_smul]
/-- Given random variables `X : Ω → 𝓧` and `Y : Ω' → 𝓨`, they are independent when viewed as random
variables defined on the product space `Ω × Ω'`. -/
lemma indepFun_prod₀ (mX : AEMeasurable X μ) (mY : AEMeasurable Y ν) :
IndepFun (fun ω ↦ X ω.1) (fun ω ↦ Y ω.2) (μ.prod ν) := by
have : IndepFun (fun ω ↦ mX.mk X ω.1) (fun ω ↦ mY.mk Y ω.2) (μ.prod ν) :=
indepFun_prod mX.measurable_mk mY.measurable_mk
refine this.congr ?_ ?_
· change (mX.mk X) ∘ Prod.fst =ᶠ[_] X ∘ Prod.fst
apply ae_eq_comp
· exact measurable_fst.aemeasurable
· rw [measurePreserving_fst.map_eq]
exact (AEMeasurable.ae_eq_mk mX).symm
· change (mY.mk Y) ∘ Prod.snd =ᶠ[_] Y ∘ Prod.snd
apply ae_eq_comp
· exact measurable_snd.aemeasurable
· rw [measurePreserving_snd.map_eq]
exact (AEMeasurable.ae_eq_mk mY).symm
variable {ι : Type*} [Fintype ι] {Ω : ι → Type*} {mΩ : ∀ i, MeasurableSpace (Ω i)}
{μ : (i : ι) → Measure (Ω i)} [∀ i, IsProbabilityMeasure (μ i)]
{𝓧 : ι → Type*} [∀ i, MeasurableSpace (𝓧 i)] {X : (i : ι) → Ω i → 𝓧 i}
/-- Given random variables `X i : Ω i → 𝓧 i`, they are independent when viewed as random
variables defined on the product space `Π i, Ω i`. -/
lemma iIndepFun_pi (mX : ∀ i, AEMeasurable (X i) (μ i)) :
iIndepFun (fun i ω ↦ X i (ω i)) (Measure.pi μ) := by
refine iIndepFun_iff_map_fun_eq_pi_map ?_ |>.2 ?_
· exact fun i ↦ (mX i).comp_quasiMeasurePreserving (Measure.quasiMeasurePreserving_eval _ i)
rw [Measure.pi_map_pi mX]
congr
ext i : 1
rw [← (measurePreserving_eval μ i).map_eq, AEMeasurable.map_map_of_aemeasurable]
· rfl
· rw [(measurePreserving_eval μ i).map_eq]
exact mX i
· exact (measurable_pi_apply i).aemeasurable
end Prod
theorem IndepFun.comp {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'}
{_mγ : MeasurableSpace γ} {_mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : IndepFun f g μ) (hφ : Measurable φ) (hψ : Measurable ψ) :
IndepFun (φ ∘ f) (ψ ∘ g) μ :=
Kernel.IndepFun.comp hfg hφ hψ
theorem IndepFun.comp₀ {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'}
{_mγ : MeasurableSpace γ} {_mγ' : MeasurableSpace γ'} {φ : β → γ} {ψ : β' → γ'}
(hfg : IndepFun f g μ) (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(hφ : AEMeasurable φ (μ.map f)) (hψ : AEMeasurable ψ (μ.map g)) :
IndepFun (φ ∘ f) (ψ ∘ g) μ :=
Kernel.IndepFun.comp₀ hfg (by simp [hf]) (by simp [hg]) (by simp [hφ]) (by simp [hψ])
theorem IndepFun.neg_right {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β']
[MeasurableNeg β'] (hfg : IndepFun f g μ) :
IndepFun f (-g) μ := hfg.comp measurable_id measurable_neg
theorem IndepFun.neg_left {_mβ : MeasurableSpace β} {_mβ' : MeasurableSpace β'} [Neg β]
[MeasurableNeg β] (hfg : IndepFun f g μ) :
IndepFun (-f) g μ := hfg.comp measurable_neg measurable_id
section iIndepFun
variable {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i}
lemma iIndepFun.isProbabilityMeasure (h : iIndepFun f μ) : IsProbabilityMeasure μ :=
⟨by simpa using h.meas_biInter (S := ∅) (s := fun _ ↦ univ)⟩
/-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
lemma iIndepFun.indepFun_finset (S T : Finset ι) (hST : Disjoint S T) (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) :
IndepFun (fun a (i : S) ↦ f i a) (fun a (i : T) ↦ f i a) μ :=
Kernel.iIndepFun.indepFun_finset S T hST hf_Indep hf_meas
/-- If `f` is a family of mutually independent random variables (`iIndepFun m f μ`) and `S, T` are
two disjoint finite index sets, then the tuple formed by `f i` for `i ∈ S` is independent of the
tuple `(f i)_i` for `i ∈ T`. -/
lemma iIndepFun.indepFun_finset₀ (S T : Finset ι) (hST : Disjoint S T) (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) :
IndepFun (fun a (i : S) ↦ f i a) (fun a (i : T) ↦ f i a) μ :=
Kernel.iIndepFun.indepFun_finset₀ S T hST hf_Indep (by simp [hf_meas])
lemma iIndepFun.indepFun_prodMk (hf_Indep : iIndepFun f μ) (hf_meas : ∀ i, Measurable (f i))
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (fun a => (f i a, f j a)) (f k) μ :=
Kernel.iIndepFun.indepFun_prodMk hf_Indep hf_meas i j k hik hjk
@[deprecated (since := "2025-03-05")]
alias iIndepFun.indepFun_prod_mk := iIndepFun.indepFun_prodMk
lemma iIndepFun.indepFun_prodMk₀ (hf_Indep : iIndepFun f μ) (hf_meas : ∀ i, AEMeasurable (f i) μ)
(i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (fun a => (f i a, f j a)) (f k) μ :=
Kernel.iIndepFun.indepFun_prodMk₀ hf_Indep (by simp [hf_meas]) i j k hik hjk
lemma iIndepFun.indepFun_prodMk_prodMk (h_indep : iIndepFun f μ) (hf : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) μ :=
Kernel.iIndepFun.indepFun_prodMk_prodMk h_indep hf i j k l hik hil hjk hjl
@[deprecated (since := "2025-03-05")]
alias iIndepFun.indepFun_prod_mk_prod_mk := iIndepFun.indepFun_prodMk_prodMk
lemma iIndepFun.indepFun_prodMk_prodMk₀ (h_indep : iIndepFun f μ) (hf : ∀ i, AEMeasurable (f i) μ)
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (fun a ↦ (f i a, f j a)) (fun a ↦ (f k a, f l a)) μ :=
Kernel.iIndepFun.indepFun_prodMk_prodMk₀ h_indep (by simp [hf]) i j k l hik hil hjk hjl
variable {ι' : Type*} {α : ι → Type*} [∀ i, MeasurableSpace (α i)]
open Function in
lemma iIndepFun.precomp {g : ι' → ι} (hg : g.Injective) (h : iIndepFun f μ) :
iIndepFun (m := fun i ↦ m (g i)) (fun i ↦ f (g i)) μ := by
have : IsProbabilityMeasure μ := h.isProbabilityMeasure
nontriviality ι'
have A (x) : Function.invFun g (g x) = x := Function.leftInverse_invFun hg x
rw [iIndepFun_iff] at h ⊢
intro t s' hs'
simpa [A] using h (t.map ⟨g, hg⟩) (f' := fun i ↦ s' (invFun g i)) (by simpa [A] using hs')
lemma iIndepFun_iff_finset : iIndepFun f μ ↔ ∀ s : Finset ι, iIndepFun (s.restrict f) μ where
mp h s := h.precomp (g := ((↑) : s → ι)) Subtype.val_injective
mpr h := by
rw [iIndepFun_iff]
intro s f hs
have : ⋂ i ∈ s, f i = ⋂ i : s, f i := by ext; simp
rw [← Finset.prod_coe_sort, this]
exact (h s).meas_iInter fun i ↦ hs i i.2
lemma iIndepFun.of_precomp {g : ι' → ι} (hg : g.Surjective)
(h : iIndepFun (m := fun i ↦ m (g i)) (fun i ↦ f (g i)) μ) : iIndepFun f μ := by
have : IsProbabilityMeasure μ := h.isProbabilityMeasure
nontriviality ι
have := hg.nontrivial
classical
rw [iIndepFun_iff] at h ⊢
intro t s hs
have A (x) : g (Function.invFun g x) = x := Function.rightInverse_invFun hg x
have : ∀ i ∈ Finset.image (Function.invFun g) t,
@MeasurableSet _ (MeasurableSpace.comap (f <| g i) (m <| g i)) (s <| g i) := by
intro i hi
obtain ⟨j, hj, rfl⟩ := Finset.mem_image.mp hi
simpa [A] using (A j).symm ▸ hs j hj
have eq : ∏ i ∈ Finset.image (Function.invFun g) t, μ (s (g i)) = ∏ i ∈ t, μ (s i) := by
rw [Finset.prod_image (fun x hx y hy h => ?_), Finset.prod_congr rfl (fun x _ => by rw [A])]
rw [← A x, ← A y, h]
simpa [A, eq] using h (t.image (Function.invFun g)) (f' := fun i ↦ s (g i)) this
lemma iIndepFun_precomp_of_bijective {g : ι' → ι} (hg : g.Bijective) :
iIndepFun (m := fun i ↦ m (g i)) (fun i ↦ f (g i)) μ ↔ iIndepFun f μ where
mp := .of_precomp hg.surjective
mpr := .precomp hg.injective
end iIndepFun
section Mul
variable {β : Type*} {m : MeasurableSpace β} [Mul β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_mul_left (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i * f j) (f k) μ :=
Kernel.iIndepFun.indepFun_mul_left hf_indep hf_meas i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_mul_left₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i * f j) (f k) μ :=
Kernel.iIndepFun.indepFun_mul_left₀ hf_indep (by simp [hf_meas]) i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_mul_right (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j * f k) μ :=
Kernel.iIndepFun.indepFun_mul_right hf_indep hf_meas i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_mul_right₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j * f k) μ :=
Kernel.iIndepFun.indepFun_mul_right₀ hf_indep (by simp [hf_meas]) i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_mul_mul (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i * f j) (f k * f l) μ :=
Kernel.iIndepFun.indepFun_mul_mul hf_indep hf_meas i j k l hik hil hjk hjl
@[to_additive]
lemma iIndepFun.indepFun_mul_mul₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ)
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i * f j) (f k * f l) μ :=
Kernel.iIndepFun.indepFun_mul_mul₀ hf_indep (by simp [hf_meas]) i j k l hik hil hjk hjl
end Mul
section Div
variable {β : Type*} {m : MeasurableSpace β} [Div β] [MeasurableDiv₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_div_left (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i / f j) (f k) μ :=
Kernel.iIndepFun.indepFun_div_left hf_indep hf_meas i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_div_left₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hik : i ≠ k) (hjk : j ≠ k) :
IndepFun (f i / f j) (f k) μ :=
Kernel.iIndepFun.indepFun_div_left₀ hf_indep (by simp [hf_meas]) i j k hik hjk
@[to_additive]
lemma iIndepFun.indepFun_div_right (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j / f k) μ :=
Kernel.iIndepFun.indepFun_div_right hf_indep hf_meas i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_div_right₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (i j k : ι) (hij : i ≠ j) (hik : i ≠ k) :
IndepFun (f i) (f j / f k) μ :=
Kernel.iIndepFun.indepFun_div_right₀ hf_indep (by simp [hf_meas]) i j k hij hik
@[to_additive]
lemma iIndepFun.indepFun_div_div (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i))
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i / f j) (f k / f l) μ :=
Kernel.iIndepFun.indepFun_div_div hf_indep hf_meas i j k l hik hil hjk hjl
@[to_additive]
lemma iIndepFun.indepFun_div_div₀ (hf_indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ)
(i j k l : ι) (hik : i ≠ k) (hil : i ≠ l) (hjk : j ≠ k) (hjl : j ≠ l) :
IndepFun (f i / f j) (f k / f l) μ :=
Kernel.iIndepFun.indepFun_div_div₀ hf_indep (by simp [hf_meas]) i j k l hik hil hjk hjl
end Div
section CommMonoid
variable {β : Type*} {m : MeasurableSpace β} [CommMonoid β] [MeasurableMul₂ β] {f : ι → Ω → β}
@[to_additive]
lemma iIndepFun.indepFun_finset_prod_of_notMem (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) {s : Finset ι} {i : ι} (hi : i ∉ s) :
IndepFun (∏ j ∈ s, f j) (f i) μ :=
Kernel.iIndepFun.indepFun_finset_prod_of_notMem hf_Indep hf_meas hi
@[deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_sum_of_not_mem := iIndepFun.indepFun_finset_sum_of_notMem
@[to_additive existing, deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_prod_of_not_mem := iIndepFun.indepFun_finset_prod_of_notMem
@[to_additive]
lemma iIndepFun.indepFun_finset_prod_of_notMem₀ (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) {s : Finset ι} {i : ι} (hi : i ∉ s) :
IndepFun (∏ j ∈ s, f j) (f i) μ :=
Kernel.iIndepFun.indepFun_finset_prod_of_notMem₀ hf_Indep (by simp [hf_meas]) hi
@[deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_sum_of_not_mem₀ := iIndepFun.indepFun_finset_sum_of_notMem₀
@[to_additive existing, deprecated (since := "2025-05-23")]
alias iIndepFun.indepFun_finset_prod_of_not_mem₀ := iIndepFun.indepFun_finset_prod_of_notMem₀
@[to_additive]
lemma iIndepFun.indepFun_prod_range_succ {f : ℕ → Ω → β} (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, Measurable (f i)) (n : ℕ) : IndepFun (∏ j ∈ Finset.range n, f j) (f n) μ :=
Kernel.iIndepFun.indepFun_prod_range_succ hf_Indep hf_meas n
@[to_additive]
lemma iIndepFun.indepFun_prod_range_succ₀ {f : ℕ → Ω → β} (hf_Indep : iIndepFun f μ)
(hf_meas : ∀ i, AEMeasurable (f i) μ) (n : ℕ) :
IndepFun (∏ j ∈ Finset.range n, f j) (f n) μ :=
hf_Indep.indepFun_finset_prod_of_notMem₀ hf_meas (by simp)
end CommMonoid
theorem iIndepSet.iIndepFun_indicator [Zero β] [One β] {m : MeasurableSpace β} {s : ι → Set Ω}
(hs : iIndepSet s μ) :
iIndepFun (fun n => (s n).indicator fun _ω => (1 : β)) μ :=
Kernel.iIndepSet.iIndepFun_indicator hs
end IndepFun
variable {ι Ω α β : Type*} {mΩ : MeasurableSpace Ω} {mα : MeasurableSpace α}
{mβ : MeasurableSpace β} {μ : Measure Ω} {X : ι → Ω → α} {Y : ι → Ω → β} {f : _ → Set Ω}
{t : ι → Set β} {s : Finset ι}
/-- The probability of an intersection of preimages conditioning on another intersection factors
into a product. -/
lemma cond_iInter [Finite ι] (hY : ∀ i, Measurable (Y i))
(hindep : iIndepFun (fun i ω ↦ (X i ω, Y i ω)) μ)
(hf : ∀ i ∈ s, MeasurableSet[mα.comap (X i)] (f i))
(hy : ∀ i ∉ s, μ (Y i ⁻¹' t i) ≠ 0) (ht : ∀ i, MeasurableSet (t i)) :
μ[⋂ i ∈ s, f i | ⋂ i, Y i ⁻¹' t i] = ∏ i ∈ s, μ[f i | Y i in t i] := by
have : IsProbabilityMeasure (μ : Measure Ω) := hindep.isProbabilityMeasure
classical
cases nonempty_fintype ι
let g (i' : ι) := if i' ∈ s then Y i' ⁻¹' t i' ∩ f i' else Y i' ⁻¹' t i'
calc
_ = (μ (⋂ i, Y i ⁻¹' t i))⁻¹ * μ ((⋂ i, Y i ⁻¹' t i) ∩ ⋂ i ∈ s, f i) := by
rw [cond_apply]; exact .iInter fun i ↦ hY i (ht i)
_ = (μ (⋂ i, Y i ⁻¹' t i))⁻¹ * μ (⋂ i, g i) := by
congr
calc
_ = (⋂ i, Y i ⁻¹' t i) ∩ ⋂ i, if i ∈ s then f i else .univ := by
congr 1
simp only [Set.iInter_ite, Set.iInter_univ, Set.inter_univ]
_ = ⋂ i, Y i ⁻¹' t i ∩ (if i ∈ s then f i else .univ) := by rw [Set.iInter_inter_distrib]
_ = _ := Set.iInter_congr fun i ↦ by by_cases hi : i ∈ s <;> simp [hi, g]
_ = (∏ i, μ (Y i ⁻¹' t i))⁻¹ * μ (⋂ i, g i) := by
rw [hindep.meas_iInter]
exact fun i ↦ ⟨.univ ×ˢ t i, MeasurableSet.univ.prod (ht _), by ext; simp⟩
_ = (∏ i, μ (Y i ⁻¹' t i))⁻¹ * ∏ i, μ (g i) := by
rw [hindep.meas_iInter]
intro i
by_cases hi : i ∈ s <;> simp only [hi, ↓reduceIte, g]
· obtain ⟨A, hA, hA'⟩ := hf i hi
exact .inter ⟨.univ ×ˢ t i, MeasurableSet.univ.prod (ht _), by ext; simp⟩
⟨A ×ˢ Set.univ, hA.prod .univ, by ext; simp [← hA']⟩
· exact ⟨.univ ×ˢ t i, MeasurableSet.univ.prod (ht _), by ext; simp⟩
_ = ∏ i, (μ (Y i ⁻¹' t i))⁻¹ * μ (g i) := by
rw [Finset.prod_mul_distrib, ENNReal.prod_inv_distrib]
exact fun _ _ i _ _ ↦ .inr <| measure_ne_top _ _
_ = ∏ i, if i ∈ s then μ[f i | Y i ⁻¹' t i] else 1 := by
refine Finset.prod_congr rfl fun i _ ↦ ?_
by_cases hi : i ∈ s
· simp only [hi, ↓reduceIte, g, cond_apply (hY i (ht i))]
· simp only [hi, ↓reduceIte, g, ENNReal.inv_mul_cancel (hy i hi) (measure_ne_top μ _)]
_ = _ := by simp
lemma iIndepFun.cond [Finite ι] (hY : ∀ i, Measurable (Y i))
(hindep : iIndepFun (fun i ω ↦ (X i ω, Y i ω)) μ)
(hy : ∀ i, μ (Y i ⁻¹' t i) ≠ 0) (ht : ∀ i, MeasurableSet (t i)) :
iIndepFun X μ[|⋂ i, Y i ⁻¹' t i] := by
rw [iIndepFun_iff]
intro s f hf
convert cond_iInter hY hindep hf (fun i _ ↦ hy _) ht using 2 with i hi
simpa using cond_iInter hY hindep (fun j hj ↦ hf _ <| Finset.mem_singleton.1 hj ▸ hi)
(fun i _ ↦ hy _) ht
section Monoid
variable {M : Type*} [Monoid M] [MeasurableSpace M] [MeasurableMul₂ M]
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map₀'
{f g : Ω → M} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(σf : SigmaFinite (μ.map f)) (σg : SigmaFinite (μ.map g)) (hfg : IndepFun f g μ) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) := by
conv in f * g => change (fun x ↦ x.1 * x.2) ∘ (fun ω ↦ (f ω, g ω))
rw [← measurable_mul.aemeasurable.map_map_of_aemeasurable (hf.prodMk hg),
(indepFun_iff_map_prod_eq_prod_map_map' hf hg σf σg).mp hfg, Measure.mconv]
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map'
{f g : Ω → M} (hf : Measurable f) (hg : Measurable g)
(σf : SigmaFinite (μ.map f)) (σg : SigmaFinite (μ.map g)) (hfg : IndepFun f g μ) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) :=
hfg.map_mul_eq_map_mconv_map₀' hf.aemeasurable hg.aemeasurable σf σg
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map₀
[IsFiniteMeasure μ] {f g : Ω → M} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(hfg : IndepFun f g μ) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) := by
apply hfg.map_mul_eq_map_mconv_map₀' hf hg
<;> apply IsFiniteMeasure.toSigmaFinite
@[to_additive]
theorem IndepFun.map_mul_eq_map_mconv_map
[IsFiniteMeasure μ] {f g : Ω → M} (hf : Measurable f) (hg : Measurable g)
(hfg : IndepFun f g μ) :
μ.map (f * g) = (μ.map f) ∗ₘ (μ.map g) :=
hfg.map_mul_eq_map_mconv_map₀ hf.aemeasurable hg.aemeasurable
end Monoid
end ProbabilityTheory
|
Imo1994Q1.lean
|
/-
Copyright (c) 2021 Antoine Labelle. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Labelle
-/
import Mathlib.Algebra.Group.Fin.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sort
import Mathlib.Order.Interval.Finset.Fin
import Mathlib.Tactic.Linarith
/-!
# IMO 1994 Q1
Let `m` and `n` be two positive integers.
Let `a₁, a₂, ..., aₘ` be `m` different numbers from the set `{1, 2, ..., n}`
such that for any two indices `i` and `j` with `1 ≤ i ≤ j ≤ m` and `aᵢ + aⱼ ≤ n`,
there exists an index `k` such that `aᵢ + aⱼ = aₖ`.
Show that `(a₁+a₂+...+aₘ)/m ≥ (n+1)/2`
# Sketch of solution
We can order the numbers so that `a₁ ≤ a₂ ≤ ... ≤ aₘ`.
The key idea is to pair the numbers in the sum and show that `aᵢ + aₘ₊₁₋ᵢ ≥ n+1`.
Indeed, if we had `aᵢ + aₘ₊₁₋ᵢ ≤ n`, then `a₁ + aₘ₊₁₋ᵢ, a₂ + aₘ₊₁₋ᵢ, ..., aᵢ + aₘ₊₁₋ᵢ`
would be `m` elements of the set of `aᵢ`'s all larger than `aₘ₊₁₋ᵢ`, which is impossible.
-/
open Finset
namespace Imo1994Q1
theorem tedious (m : ℕ) (k : Fin (m + 1)) : m - ((m + 1 - ↑k) + m) % (m + 1) = ↑k := by
obtain ⟨k, hk⟩ := k
rw [Nat.lt_succ_iff, le_iff_exists_add] at hk
rcases hk with ⟨c, rfl⟩
have : (k + c + 1 - k) + (k + c) = c + (k + c + 1) := by omega
rw [Fin.val_mk, this, Nat.add_mod_right, Nat.mod_eq_of_lt, Nat.add_sub_cancel]
omega
end Imo1994Q1
open Imo1994Q1
theorem imo1994_q1 (n : ℕ) (m : ℕ) (A : Finset ℕ) (hm : #A = m + 1)
(hrange : ∀ a ∈ A, 0 < a ∧ a ≤ n)
(hadd : ∀ a ∈ A, ∀ b ∈ A, a + b ≤ n → a + b ∈ A) :
(m + 1) * (n + 1) ≤ 2 * ∑ x ∈ A, x := by
set a := orderEmbOfFin A hm
-- We sort the elements of `A`
have ha : ∀ i, a i ∈ A := fun i => orderEmbOfFin_mem A hm i
set rev := Equiv.subLeft (Fin.last m)
-- `i ↦ m-i`
-- We reindex the sum by fin (m+1)
have : ∑ x ∈ A, x = ∑ i : Fin (m + 1), a i := by
convert sum_image fun x _ y _ => a.eq_iff_eq.1
rw [← coe_inj]; simp [a]
rw [this]; clear this
-- The main proof is a simple calculation by rearranging one of the two sums
suffices hpair : ∀ k ∈ univ, a k + a (rev k) ≥ n + 1 by calc
2 * ∑ i : Fin (m + 1), a i = ∑ i : Fin (m + 1), a i + ∑ i : Fin (m + 1), a i := two_mul _
_ = ∑ i : Fin (m + 1), a i + ∑ i : Fin (m + 1), a (rev i) := by rw [Equiv.sum_comp rev]
_ = ∑ i : Fin (m + 1), (a i + a (rev i)) := sum_add_distrib.symm
_ ≥ ∑ i : Fin (m + 1), (n + 1) := sum_le_sum hpair
_ = (m + 1) * (n + 1) := by rw [sum_const, card_fin, Nat.nsmul_eq_mul]
-- It remains to prove the key inequality, by contradiction
rintro k -
by_contra! h : a k + a (rev k) < n + 1
-- We exhibit `k+1` elements of `A` greater than `a (rev k)`
set f : Fin (m + 1) ↪ ℕ :=
⟨fun i => a i + a (rev k), by
apply injective_of_le_imp_le
intro i j hij
rwa [add_le_add_iff_right, a.map_rel_iff] at hij ⟩
-- Proof that the `f i` are greater than `a (rev k)` for `i ≤ k`
have hf : map f (Icc 0 k) ⊆ map a.toEmbedding (Ioc (rev k) (Fin.last m)) := by
intro x hx
simp only [Equiv.subLeft_apply, a, rev] at h
simp only [mem_map, mem_Icc, mem_Ioc, Fin.zero_le, true_and, Equiv.subLeft_apply,
Function.Embedding.coeFn_mk, RelEmbedding.coe_toEmbedding, f, rev] at hx ⊢
rcases hx with ⟨i, ⟨hi, rfl⟩⟩
have h1 : a i + a (Fin.last m - k) ≤ n := by unfold a; linarith only [h, a.monotone hi]
have h2 : a i + a (Fin.last m - k) ∈ A := hadd _ (ha _) _ (ha _) h1
rw [← mem_coe, ← range_orderEmbOfFin A hm, Set.mem_range] at h2
obtain ⟨j, hj⟩ := h2
refine ⟨j, ⟨?_, Fin.le_last j⟩, hj⟩
rw [← a.strictMono.lt_iff_lt, hj]
simpa using (hrange (a i) (ha i)).1
-- A set of size `k+1` embed in one of size `k`, which yields a contradiction
simpa [Fin.coe_sub, tedious, rev] using card_le_card hf
|
Ker.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, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.Module.Submodule.Map
/-!
# Kernel of a linear map
This file defines the kernel of a linear map.
## Main definitions
* `LinearMap.ker`: the kernel of a linear map as a submodule of the domain
## Notations
* We continue to use the notations `M →ₛₗ[σ] M₂` and `M →ₗ[R] M₂` for the type of semilinear
(resp. linear) maps from `M` to `M₂` over the ring homomorphism `σ` (resp. over the ring `R`).
## Tags
linear algebra, vector space, module
-/
open Function
open Pointwise
variable {R : Type*} {R₂ : Type*} {R₃ : Type*}
variable {K : Type*}
variable {M : Type*} {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
variable {V : Type*} {V₂ : Type*}
/-! ### Properties of linear maps -/
namespace LinearMap
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
open Submodule
variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
/-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the
set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/
def ker (f : F) : Submodule R M :=
comap f ⊥
@[simp]
theorem mem_ker {f : F} {y} : y ∈ ker f ↔ f y = 0 :=
mem_bot R₂
@[simp]
theorem ker_id : ker (LinearMap.id : M →ₗ[R] M) = ⊥ :=
rfl
@[simp]
theorem map_coe_ker (f : F) (x : ker f) : f x = 0 :=
mem_ker.1 x.2
theorem ker_toAddSubmonoid (f : M →ₛₗ[τ₁₂] M₂) : (ker f).toAddSubmonoid = (AddMonoidHom.mker f) :=
rfl
theorem le_ker_iff_comp_subtype_eq_zero {N : Submodule R M} {f : M →ₛₗ[τ₁₂] M₂} :
N ≤ ker f ↔ f ∘ₛₗ N.subtype = 0 := by
rw [SetLike.le_def, LinearMap.ext_iff, Subtype.forall]; rfl
theorem comp_ker_subtype (f : M →ₛₗ[τ₁₂] M₂) : f.comp (ker f).subtype = 0 :=
LinearMap.ext fun x => mem_ker.1 x.2
theorem ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = comap f (ker g) :=
rfl
theorem ker_le_ker_comp (f : M →ₛₗ[τ₁₂] M₂) (g : M₂ →ₛₗ[τ₂₃] M₃) :
ker f ≤ ker (g.comp f : M →ₛₗ[τ₁₃] M₃) := by rw [ker_comp]; exact comap_mono bot_le
theorem ker_sup_ker_le_ker_comp_of_commute {f g : M →ₗ[R] M} (h : Commute f g) :
ker f ⊔ ker g ≤ ker (f ∘ₗ g) := by
refine sup_le_iff.mpr ⟨?_, ker_le_ker_comp g f⟩
rw [← Module.End.mul_eq_comp, h.eq, Module.End.mul_eq_comp]
exact ker_le_ker_comp f g
@[simp]
theorem ker_le_comap {p : Submodule R₂ M₂} (f : M →ₛₗ[τ₁₂] M₂) :
ker f ≤ p.comap f :=
fun x hx ↦ by simp [mem_ker.mp hx]
theorem disjoint_ker {f : F} {p : Submodule R M} :
Disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 := by
simp [disjoint_def]
theorem ker_eq_bot' {f : F} : ker f = ⊥ ↔ ∀ m, f m = 0 → m = 0 := by
simpa [disjoint_iff_inf_le] using disjoint_ker (f := f) (p := ⊤)
theorem ker_eq_bot_of_inverse {τ₂₁ : R₂ →+* R} [RingHomInvPair τ₁₂ τ₂₁] {f : M →ₛₗ[τ₁₂] M₂}
{g : M₂ →ₛₗ[τ₂₁] M} (h : (g.comp f : M →ₗ[R] M) = id) : ker f = ⊥ :=
ker_eq_bot'.2 fun m hm => by rw [← id_apply (R := R) m, ← h, comp_apply, hm, g.map_zero]
theorem le_ker_iff_map [RingHomSurjective τ₁₂] {f : F} {p : Submodule R M} :
p ≤ ker f ↔ map f p = ⊥ := by rw [ker, eq_bot_iff, map_le_iff_le_comap]
theorem ker_codRestrict {τ₂₁ : R₂ →+* R} (p : Submodule R M) (f : M₂ →ₛₗ[τ₂₁] M) (hf) :
ker (codRestrict p f hf) = ker f := by rw [ker, comap_codRestrict, Submodule.map_bot]; rfl
lemma ker_domRestrict [AddCommMonoid M₁] [Module R M₁] (p : Submodule R M) (f : M →ₗ[R] M₁) :
ker (domRestrict f p) = (ker f).comap p.subtype := ker_comp ..
theorem ker_restrict [AddCommMonoid M₁] [Module R M₁] {p : Submodule R M} {q : Submodule R M₁}
{f : M →ₗ[R] M₁} (hf : ∀ x : M, x ∈ p → f x ∈ q) :
ker (f.restrict hf) = (ker f).comap p.subtype := by
rw [restrict_eq_codRestrict_domRestrict, ker_codRestrict, ker_domRestrict]
@[simp]
theorem ker_zero : ker (0 : M →ₛₗ[τ₁₂] M₂) = ⊤ :=
eq_top_iff'.2 fun x => by simp
@[simp]
theorem ker_eq_top {f : M →ₛₗ[τ₁₂] M₂} : ker f = ⊤ ↔ f = 0 :=
⟨fun h => ext fun _ => mem_ker.1 <| h.symm ▸ trivial, fun h => h.symm ▸ ker_zero⟩
theorem exists_ne_zero_of_sSup_eq_top {f : M →ₛₗ[τ₁₂] M₂} (h : f ≠ 0) (s : Set (Submodule R M))
(hs : sSup s = ⊤) : ∃ m ∈ s, f ∘ₛₗ m.subtype ≠ 0 := by
contrapose! h
simp_rw [← ker_eq_top, eq_top_iff, ← hs, sSup_le_iff, le_ker_iff_comp_subtype_eq_zero]
exact h
@[simp]
theorem _root_.AddMonoidHom.coe_toIntLinearMap_ker {M M₂ : Type*} [AddCommGroup M] [AddCommGroup M₂]
(f : M →+ M₂) : LinearMap.ker f.toIntLinearMap = AddSubgroup.toIntSubmodule f.ker := rfl
theorem ker_eq_bot_of_injective {f : F} (hf : Injective f) : ker f = ⊥ := by
rw [eq_bot_iff]
intro x hx
simpa only [mem_ker, mem_bot, ← map_zero f, hf.eq_iff] using hx
/-- The increasing sequence of submodules consisting of the kernels of the iterates of a linear map.
-/
@[simps]
def iterateKer (f : M →ₗ[R] M) : ℕ →o Submodule R M where
toFun n := ker (f ^ n)
monotone' n m w x h := by
obtain ⟨c, rfl⟩ := Nat.exists_eq_add_of_le w
rw [LinearMap.mem_ker] at h
rw [LinearMap.mem_ker, add_comm, pow_add, Module.End.mul_apply, h, LinearMap.map_zero]
end AddCommMonoid
section Ring
variable [Ring R] [Ring R₂]
variable [AddCommGroup M] [AddCommGroup M₂]
variable [Module R M] [Module R₂ M₂]
variable {τ₁₂ : R →+* R₂}
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
variable {f : F}
open Submodule
theorem ker_toAddSubgroup (f : M →ₛₗ[τ₁₂] M₂) : (ker f).toAddSubgroup = f.toAddMonoidHom.ker :=
rfl
theorem sub_mem_ker_iff {x y} : x - y ∈ ker f ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero]
theorem disjoint_ker' {p : Submodule R M} :
Disjoint p (ker f) ↔ ∀ x ∈ p, ∀ y ∈ p, f x = f y → x = y :=
disjoint_ker.trans
⟨fun H x hx y hy h => eq_of_sub_eq_zero <| H _ (sub_mem hx hy) (by simp [h]),
fun H x h₁ h₂ => H x h₁ 0 (zero_mem _) (by simpa using h₂)⟩
theorem injOn_of_disjoint_ker {p : Submodule R M} {s : Set M} (h : s ⊆ p)
(hd : Disjoint p (ker f)) : Set.InjOn f s := fun _ hx _ hy =>
disjoint_ker'.1 hd _ (h hx) _ (h hy)
variable (F) in
theorem _root_.LinearMapClass.ker_eq_bot : ker f = ⊥ ↔ Injective f := by
simpa [disjoint_iff_inf_le] using disjoint_ker' (f := f) (p := ⊤)
theorem ker_eq_bot {f : M →ₛₗ[τ₁₂] M₂} : ker f = ⊥ ↔ Injective f :=
LinearMapClass.ker_eq_bot _
@[simp] lemma injective_domRestrict_iff {f : M →ₛₗ[τ₁₂] M₂} {S : Submodule R M} :
Injective (f.domRestrict S) ↔ S ⊓ LinearMap.ker f = ⊥ := by
rw [← LinearMap.ker_eq_bot]
refine ⟨fun h ↦ le_bot_iff.1 ?_, fun h ↦ le_bot_iff.1 ?_⟩
· intro x ⟨hx, h'x⟩
have : ⟨x, hx⟩ ∈ LinearMap.ker (LinearMap.domRestrict f S) := by simpa using h'x
rw [h] at this
simpa [mk_eq_zero] using this
· rintro ⟨x, hx⟩ h'x
have : x ∈ S ⊓ LinearMap.ker f := ⟨hx, h'x⟩
rw [h] at this
simpa [mk_eq_zero] using this
@[simp] theorem injective_restrict_iff_disjoint {p : Submodule R M} {f : M →ₗ[R] M}
(hf : ∀ x ∈ p, f x ∈ p) :
Injective (f.restrict hf) ↔ Disjoint p (ker f) := by
rw [← ker_eq_bot, ker_restrict hf, ← ker_domRestrict, ker_eq_bot, injective_domRestrict_iff,
disjoint_iff]
end Ring
section Semifield
variable [Semifield K]
variable [AddCommMonoid V] [Module K V]
variable [AddCommMonoid V₂] [Module K V₂]
theorem ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f :=
Submodule.comap_smul f _ a h
theorem ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅ _ : a ≠ 0, ker f :=
Submodule.comap_smul' f _ a
end Semifield
end LinearMap
namespace Submodule
section AddCommMonoid
variable [Semiring R] [Semiring R₂] [AddCommMonoid M] [AddCommMonoid M₂]
variable [Module R M] [Module R₂ M₂]
variable (p : Submodule R M)
variable {τ₁₂ : R →+* R₂}
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F τ₁₂ M M₂]
open LinearMap
@[simp]
theorem comap_bot (f : F) : comap f ⊥ = ker f :=
rfl
@[simp]
theorem ker_subtype : ker p.subtype = ⊥ :=
ker_eq_bot_of_injective fun _ _ => Subtype.ext_val
@[simp]
theorem ker_inclusion (p p' : Submodule R M) (h : p ≤ p') : ker (inclusion h) = ⊥ := by
rw [inclusion, ker_codRestrict, ker_subtype]
end AddCommMonoid
end Submodule
namespace LinearMap
section Semiring
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable [Module R M] [Module R₂ M₂] [Module R₃ M₃]
variable {τ₁₂ : R →+* R₂} {τ₂₃ : R₂ →+* R₃} {τ₁₃ : R →+* R₃}
variable [RingHomCompTriple τ₁₂ τ₂₃ τ₁₃]
theorem ker_comp_of_ker_eq_bot (f : M →ₛₗ[τ₁₂] M₂) {g : M₂ →ₛₗ[τ₂₃] M₃} (hg : ker g = ⊥) :
ker (g.comp f : M →ₛₗ[τ₁₃] M₃) = ker f := by rw [ker_comp, hg, Submodule.comap_bot]
end Semiring
end LinearMap
/-! ### Linear equivalences -/
namespace LinearEquiv
section AddCommMonoid
section
variable [Semiring R] [Semiring R₂] [Semiring R₃]
variable [AddCommMonoid M] [AddCommMonoid M₂] [AddCommMonoid M₃]
variable {module_M : Module R M} {module_M₂ : Module R₂ M₂} {module_M₃ : Module R₃ M₃}
variable {σ₁₂ : R →+* R₂} {σ₂₁ : R₂ →+* R}
variable {σ₂₃ : R₂ →+* R₃} {σ₁₃ : R →+* R₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃]
variable {σ₃₂ : R₃ →+* R₂}
variable {re₁₂ : RingHomInvPair σ₁₂ σ₂₁} {re₂₁ : RingHomInvPair σ₂₁ σ₁₂}
variable {re₂₃ : RingHomInvPair σ₂₃ σ₃₂} {re₃₂ : RingHomInvPair σ₃₂ σ₂₃}
variable (e : M ≃ₛₗ[σ₁₂] M₂) (e'' : M₂ ≃ₛₗ[σ₂₃] M₃)
@[simp]
protected theorem ker : LinearMap.ker (e : M →ₛₗ[σ₁₂] M₂) = ⊥ :=
LinearMap.ker_eq_bot_of_injective e.toEquiv.injective
@[simp]
theorem ker_comp (l : M →ₛₗ[σ₁₂] M₂) :
LinearMap.ker (((e'' : M₂ →ₛₗ[σ₂₃] M₃).comp l : M →ₛₗ[σ₁₃] M₃) : M →ₛₗ[σ₁₃] M₃) =
LinearMap.ker l :=
LinearMap.ker_comp_of_ker_eq_bot _ e''.ker
end
end AddCommMonoid
end LinearEquiv
|
autolabel.lean
|
/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster, Damiano Testa
-/
import Lean.Elab.Command
/-!
# Automatic labelling of PRs
This file contains the script to automatically assign a GitHub label to a PR.
## Label definition
The mapping from GitHub labels to Mathlib folders is done in this file and
needs to be updated here if necessary:
* `AutoLabel.mathlibLabels` contains an assignment of GitHub labels to folders inside
the mathlib repository. If no folder is specified, a label like `t-set-theory` will be
interpreted as matching the folder `"Mathlib" / "SetTheory"`.
* `AutoLabel.mathlibUnlabelled` contains subfolders of `Mathlib/` which are deliberately
left without topic label.
## lake exe autolabel
`lake exe autolabel` uses `git diff --name-only origin/master...HEAD` to determine which
files have been modified and then finds all labels which should be added based on these changes.
These are printed for testing purposes.
`lake exe autolabel [NUMBER]` will further try to add the applicable labels
to the PR specified. This requires the **GitHub CLI** `gh` to be installed!
Example: `lake exe autolabel 10402` for PR https://github.com/leanprover-community/mathlib4/pull/10402.
For the time being, the script only adds a label if it finds a **single unique label**
which would apply. If multiple labels are found, nothing happens.
## Workflow
There is a mathlib workflow `.github/workflows/add_label_from_diff.yaml` which executes
this script automatically.
Currently it is set to run only one time when a PR is created.
## Tests
Additionally, the script does a few consistency checks:
- it ensures all paths in specified in `AutoLabel.mathlibLabels` exist
- It makes sure all subfolders of `Mathlib/` belong to at least one label.
There is `AutoLabel.mathlibUnlabelled` to add exceptions for this test.
-/
open Lean System
namespace AutoLabel
/--
A `Label` consists of the
* The `label` field is the actual GitHub label name.
* The `dirs` field is the array of all "root paths" such that a modification in a file contained
in one of these paths should be labelled with `label`.
* The `exclusions` field is the array of all "root paths" that are excluded, among the
ones that start with the ones in `dirs`.
Any modifications to a file in an excluded path is ignored for the purposes of labelling.
-/
structure Label where
/-- The label name as it appears on GitHub -/
label : String
/-- Array of paths which fall under this label. e.g. `"Mathlib" / "Algebra"`.
For a label of the form `t-set-theory` this defaults to `#["Mathlib" / "SetTheory"]`. -/
dirs : Array FilePath := if label.startsWith "t-" then
#["Mathlib" / ("".intercalate (label.splitOn "-" |>.drop 1 |>.map .capitalize))]
else #[]
/-- Array of paths which should be excluded.
Any modifications to a file in an excluded path are ignored for the purposes of labelling. -/
exclusions : Array FilePath := #[]
deriving BEq, Hashable
/--
Mathlib labels and their corresponding folders. Add new labels and folders here!
-/
def mathlibLabels : Array Label := #[
{ label := "t-algebra",
dirs := #[
"Mathlib" / "Algebra",
"Mathlib" / "FieldTheory",
"Mathlib" / "RepresentationTheory",
"Mathlib" / "LinearAlgebra"] },
{ label := "t-algebraic-geometry",
dirs := #[
"Mathlib" / "AlgebraicGeometry",
"Mathlib" / "Geometry" / "RingedSpace"] },
{ label := "t-algebraic-topology",
dirs := #["Mathlib" / "AlgebraicTopology"] },
{ label := "t-analysis" },
{ label := "t-category-theory" },
{ label := "t-combinatorics" },
{ label := "t-computability" },
{ label := "t-condensed" },
{ label := "t-convex-geometry",
dirs := #["Mathlib" / "Geometry" / "Convex"] },
{ label := "t-data"
dirs := #[
"Mathlib" / "Control",
"Mathlib" / "Data",] },
{ label := "t-differential-geometry",
dirs := #["Mathlib" / "Geometry" / "Manifold"] },
{ label := "t-dynamics" },
{ label := "t-euclidean-geometry",
dirs := #["Mathlib" / "Geometry" / "Euclidean"] },
{ label := "t-geometric-group-theory",
dirs := #["Mathlib" / "Geometry" / "Group"] },
{ label := "t-group-theory",
dirs := #["Mathlib" / "GroupTheory"] },
{ label := "t-linter",
dirs := #[
"Mathlib" / "Tactic" / "Linter",
"scripts" / "lint-style.lean",
"scripts" / "lint-style.py",
] },
{ label := "t-logic",
dirs := #[
"Mathlib" / "Logic",
"Mathlib" / "ModelTheory"] },
{ label := "t-measure-probability",
dirs := #[
"Mathlib" / "MeasureTheory",
"Mathlib" / "Probability",
"Mathlib" / "InformationTheory"] },
{ label := "t-meta",
dirs := #[
"Mathlib" / "Lean",
"Mathlib" / "Mathport",
"Mathlib" / "Tactic",
"Mathlib" / "Util"],
exclusions := #["Mathlib" / "Tactic" / "Linter"] },
{ label := "t-number-theory" },
{ label := "t-order" },
{ label := "t-ring-theory",
dirs := #["Mathlib" / "RingTheory"] },
{ label := "t-set-theory" },
{ label := "t-topology",
dirs := #["Mathlib" / "Topology"] },
{ label := "CI",
dirs := #[
".github",
"scripts" /"bench",
"scripts",
],
exclusions := #[
"scripts" / "lint-style.lean",
"scripts" / "lint-style.py",
"scripts" / "noshake.json",
"scripts" / "nolints.json",
"scripts" / "nolints-style.txt",
"scripts" / "nolints_prime_decls.txt",
] },
{ label := "IMO",
dirs := #["Archive" / "Imo"] },
{ label := "dependency-bump",
dirs := #["lake-manifest.json"] } ]
/-- Exceptions inside `Mathlib/` which are not covered by any label. -/
def mathlibUnlabelled : Array FilePath := #[
"Mathlib" / "Deprecated",
"Mathlib" / "Init",
"Mathlib" / "Testing",
"Mathlib" / "Std" ]
/-- Checks if the folder `path` lies inside the folder `dir`. -/
def _root_.System.FilePath.isPrefixOf (dir path : FilePath) : Bool :=
-- use `dir / ""` to prevent partial matching of folder names
(dir / "").normalize.toString.isPrefixOf (path / "").normalize.toString
/--
Return all names of labels in `mathlibLabels` which match
at least one of the `files`.
* `files`: array of relative paths starting from the mathlib root directory.
-/
def getMatchingLabels (files : Array FilePath) : Array String :=
let applicable := mathlibLabels.filter fun label ↦
-- first exclude all files the label excludes,
-- then see if any file remains included by the label
let notExcludedFiles := files.filter fun file ↦
label.exclusions.all (!·.isPrefixOf file)
label.dirs.any (fun dir ↦ notExcludedFiles.any (dir.isPrefixOf ·))
-- return sorted list of label names
applicable.map (·.label) |>.qsort (· < ·)
/-!
Testing the functionality of the declarations defined in this script
-/
section Tests
-- Test `FilePath.isPrefixOf`
#guard ("Mathlib" / "Algebra" : FilePath).isPrefixOf ("Mathlib" / "Algebra" / "Basic.lean")
-- Test `FilePath.isPrefixOf` does not trigger on partial prefixes
#guard ! ("Mathlib" / "Algebra" : FilePath).isPrefixOf ("Mathlib" / "AlgebraicGeometry")
#guard getMatchingLabels #[] == #[]
-- Test default value for `label.dirs` works
#guard getMatchingLabels #["Mathlib" / "SetTheory" / "ZFC"] == #["t-set-theory"]
-- Test exclusion
#guard getMatchingLabels #["Mathlib" / "Tactic"/ "Abel.lean"] == #["t-meta"]
#guard getMatchingLabels #["Mathlib" / "Tactic"/ "Linter" / "Lint.lean"] == #["t-linter"]
#guard getMatchingLabels #[
"Mathlib" / "Tactic"/ "Linter" / "Lint.lean",
"Mathlib" / "Tactic" / "Abel.lean" ] == #["t-linter", "t-meta"]
-- Test targeting a file instead of a directory
#guard getMatchingLabels #["lake-manifest.json"] == #["dependency-bump"]
-- Test linting of specific changes touching linting and CI.
#guard getMatchingLabels #["scripts" / "add_deprecations.sh"] == #["CI"]
#guard getMatchingLabels #["scripts" / "lint-style.lean"] == #["t-linter"]
#guard getMatchingLabels #["Mathlib" / "Tactic" / "Linter" / "TextBased.lean",
"scripts" / "lint-style.lean", "scripts" / "lint-style.py"] == #["t-linter"]
#guard getMatchingLabels #["scripts" / "noshake.json"] == #[]
/-- Testing function to ensure the labels defined in `mathlibLabels` cover all
subfolders of `Mathlib/`. -/
partial def findUncoveredPaths (path : FilePath) (exceptions : Array FilePath := #[]) :
IO <| Array FilePath := do
let mut notMatched : Array FilePath := #[]
-- all directories inside `path`
let subDirs ← (← path.readDir).map (·.path) |>.filterM (do FilePath.isDir ·)
for dir in subDirs do
-- if the sub directory is not matched by a label,
-- we go recursively into it
if (getMatchingLabels #[dir]).size == 0 then
notMatched := notMatched ++ (← findUncoveredPaths dir exceptions)
-- a directory should be flagged if none of its sub-directories is matched by a label
-- note: we assume here the base directory, i.e. "Mathlib" is never matched by a label,
-- therefore we skip this test.
if notMatched.size == subDirs.size then
if exceptions.contains path then
return #[]
else
return #[path]
else
return notMatched
end Tests
/--
Create a message which GitHub CI parses as annotation and displays at the specified file.
Note: `file` is duplicated below so that it is also visible in the plain text output.
* `type`: "error" or "warning"
* `file`: file where the annotation should be displayed
* `title`: title of the annotation
* `message`: annotation message
-/
def githubAnnotation (type file title message : String) : String :=
s!"::{type} file={file},title={title}::{file}: {message}"
end AutoLabel
open IO AutoLabel in
/-- `args` is expected to have length 0 or 1, where the first argument is the PR number.
If a PR number is provided, the script requires GitHub CLI `gh` to be installed in order
to add the label to the PR.
## Exit codes:
- `0`: success
- `1`: invalid arguments provided
- `2`: invalid labels defined
- `3`: ~labels do not cover all of `Mathlib/`~ (unused; only emitting warning)
-/
unsafe def main (args : List String): IO UInt32 := do
if args.length > 1 then
println s!"::error:: autolabel: invalid number of arguments ({args.length}), \
expected at most 1. Please run without arguments or provide the target PR's \
number as a single argument!"
return 1
let prNumber? := args[0]?
-- test: validate that all paths in `mathlibLabels` actually exist
let mut valid := true
for label in mathlibLabels do
for dir in label.dirs do
unless ← FilePath.pathExists dir do
-- print github annotation error
println <| AutoLabel.githubAnnotation "error" "scripts/autolabel.lean"
s!"Misformatted `{ ``AutoLabel.mathlibLabels }`"
s!"directory '{dir}' does not exist but is included by label '{label.label}'. \
Please update `{ ``AutoLabel.mathlibLabels }`!"
valid := false
for dir in label.exclusions do
unless ← FilePath.pathExists dir do
-- print github annotation error
println <| AutoLabel.githubAnnotation "error" "scripts/autolabel.lean"
s!"Misformatted `{ ``AutoLabel.mathlibLabels }`"
s!"directory '{dir}' does not exist but is excluded by label '{label.label}'. \
Please update `{ ``AutoLabel.mathlibLabels }`!"
valid := false
unless valid do
return 2
-- test: validate that the labels cover all of the `Mathlib/` folder
let notMatchedPaths ← findUncoveredPaths "Mathlib" (exceptions := mathlibUnlabelled)
if notMatchedPaths.size > 0 then
-- print github annotation warning
-- note: only emitting a warning because the workflow is only triggered on the first commit
-- of a PR and could therefore lead to unexpected behaviour if a folder was created later.
println <| AutoLabel.githubAnnotation "warning" "scripts/autolabel.lean"
s!"Incomplete `{ ``AutoLabel.mathlibLabels }`"
s!"the following paths inside `Mathlib/` are not covered \
by any label: {notMatchedPaths} Please modify `AutoLabel.mathlibLabels` accordingly!"
-- return 3
-- get the modified files
println "Computing 'git diff --name-only origin/master...HEAD'"
let gitDiff ← IO.Process.run {
cmd := "git",
args := #["diff", "--name-only", "origin/master...HEAD"] }
println s!"---\n{gitDiff}\n---"
let modifiedFiles : Array FilePath := (gitDiff.splitOn "\n").toArray.map (⟨·⟩)
-- find labels covering the modified files
let labels := getMatchingLabels modifiedFiles
println s!"::notice::Applicable labels: {labels}"
match labels with
| #[] =>
println s!"::warning::no label to add"
| #[label] =>
match prNumber? with
| some n =>
let labelsPresent ← IO.Process.run {
cmd := "gh"
args := #["pr", "view", n, "--json", "labels", "--jq", ".labels .[] .name"]}
let labels := labelsPresent.split (· == '\n')
let autoLabels := mathlibLabels.map (·.label)
match labels.filter autoLabels.contains with
| [] => -- if the PR does not have a label that this script could add, then we add a label
let _ ← IO.Process.run {
cmd := "gh",
args := #["pr", "edit", n, "--add-label", label] }
println s!"::notice::added label: {label}"
| t_labels_already_present =>
println s!"::notice::Did not add label '{label}', since {t_labels_already_present} \
were already present"
| none =>
println s!"::warning::no PR-number provided, not adding labels. \
(call `lake exe autolabel 150602` to add the labels to PR `150602`)"
| _ =>
println s!"::notice::not adding multiple labels: {labels}"
return 0
|
AlgebraInstances.lean
|
/-
Copyright (c) 2024 María Inés de Frutos-Fernández, Filippo A. E. Nuccio. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández, Filippo A. E. Nuccio
-/
import Mathlib.RingTheory.IntegralClosure.IsIntegralClosure.Basic
import Mathlib.RingTheory.Valuation.ValuationSubring
/-!
# Algebra instances
This file contains several `Algebra` and `IsScalarTower` instances related to extensions
of a field with a valuation, as well as their unit balls.
# Main Definitions
* `ValuationSubring.algebra` : Given an algebra between two field extensions `L` and `E` of a
field `K` with a valuation, create an algebra between their two rings of integers.
# Main Results
* `integralClosure_algebraMap_injective` : the unit ball of a field `K` with respect to a
valuation injects into its integral closure in a field extension `L` of `K`.
-/
open Function Valuation
open scoped WithZero
variable {K : Type*} [Field K] (v : Valuation K ℤᵐ⁰) (L : Type*) [Field L] [Algebra K L]
namespace ValuationSubring
-- Implementation note : this instance was automatic in Lean3
instance : Algebra v.valuationSubring L := Algebra.ofSubring v.valuationSubring.toSubring
theorem algebraMap_injective : Injective (algebraMap v.valuationSubring L) :=
(FaithfulSMul.algebraMap_injective K L).comp (IsFractionRing.injective _ _)
theorem isIntegral_of_mem_ringOfIntegers {x : L} (hx : x ∈ integralClosure v.valuationSubring L) :
IsIntegral v.valuationSubring (⟨x, hx⟩ : integralClosure v.valuationSubring L) := by
obtain ⟨P, hPm, hP⟩ := hx
refine ⟨P, hPm, ?_⟩
rw [← Polynomial.aeval_def, ← Subalgebra.coe_eq_zero, Polynomial.aeval_subalgebra_coe,
Polynomial.aeval_def, Subtype.coe_mk, hP]
theorem isIntegral_of_mem_ringOfIntegers' {x : (integralClosure v.valuationSubring L)} :
IsIntegral v.valuationSubring (x : integralClosure v.valuationSubring L) := by
apply isIntegral_of_mem_ringOfIntegers
variable (E : Type _) [Field E] [Algebra K E] [Algebra L E] [IsScalarTower K L E]
instance : IsScalarTower v.valuationSubring L E := Subring.instIsScalarTowerSubtypeMem _
/-- Given an algebra between two field extensions `L` and `E` of a field `K` with a valuation `v`,
create an algebra between their two rings of integers. -/
instance algebra :
Algebra (integralClosure v.valuationSubring L) (integralClosure v.valuationSubring E) :=
RingHom.toAlgebra
{ toFun := fun k => ⟨algebraMap L E k, IsIntegral.algebraMap k.2⟩
map_zero' :=
Subtype.ext <| by simp only [Subalgebra.coe_zero, map_zero]
map_one' := Subtype.ext <| by simp only [Subalgebra.coe_one, map_one]
map_add' := fun x y =>
Subtype.ext <| by simp only [map_add, Subalgebra.coe_add]
map_mul' := fun x y =>
Subtype.ext <| by simp only [Subalgebra.coe_mul, map_mul] }
/-- A ring equivalence between the integral closure of the valuation subring of `K` in `L`
and a ring `R` satisfying `isIntegralClosure R v.valuationSubring L`. -/
protected noncomputable def equiv (R : Type*) [CommRing R] [Algebra v.valuationSubring R]
[Algebra R L] [IsScalarTower v.valuationSubring R L]
[IsIntegralClosure R v.valuationSubring L] : integralClosure v.valuationSubring L ≃+* R := by
have := IsScalarTower.subalgebra' (valuationSubring v) L L
(integralClosure (valuationSubring v) L)
exact (IsIntegralClosure.equiv v.valuationSubring R L
(integralClosure v.valuationSubring L)).symm.toRingEquiv
theorem integralClosure_algebraMap_injective :
Injective (algebraMap v.valuationSubring (integralClosure v.valuationSubring L)) :=
FaithfulSMul.algebraMap_injective ↥v.valuationSubring ↥(integralClosure (↥v.valuationSubring) L)
end ValuationSubring
|
Union.lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Finset.Fold
import Mathlib.Data.Multiset.Bind
import Mathlib.Order.SetNotation
/-!
# Unions of finite sets
This file defines the union of a family `t : α → Finset β` of finsets bounded by a finset
`s : Finset α`.
## Main declarations
* `Finset.disjUnion`: Given a hypothesis `h` which states that finsets `s` and `t` are disjoint,
`s.disjUnion t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`; this does
not require decidable equality on the type `α`.
* `Finset.biUnion`: Finite unions of finsets; given an indexing function `f : α → Finset β` and an
`s : Finset α`, `s.biUnion f` is the union of all finsets of the form `f a` for `a ∈ s`.
## TODO
Remove `Finset.biUnion` in favour of `Finset.sup`.
-/
assert_not_exists MonoidWithZero MulAction
variable {α β γ : Type*} {s s₁ s₂ : Finset α} {t t₁ t₂ : α → Finset β}
namespace Finset
section DisjiUnion
/-- `disjiUnion s f h` is the set such that `a ∈ disjiUnion s f` iff `a ∈ f i` for some `i ∈ s`.
It is the same as `s.biUnion f`, but it does not require decidable equality on the type. The
hypothesis ensures that the sets are disjoint. -/
def disjiUnion (s : Finset α) (t : α → Finset β) (hf : (s : Set α).PairwiseDisjoint t) : Finset β :=
⟨s.val.bind (Finset.val ∘ t), Multiset.nodup_bind.2
⟨fun a _ ↦ (t a).nodup, s.nodup.pairwise fun _ ha _ hb hab ↦ disjoint_val.2 <| hf ha hb hab⟩⟩
@[simp]
lemma disjiUnion_val (s : Finset α) (t : α → Finset β) (h) :
(s.disjiUnion t h).1 = s.1.bind fun a ↦ (t a).1 := rfl
@[simp] lemma disjiUnion_empty (t : α → Finset β) : disjiUnion ∅ t (by simp) = ∅ := rfl
@[simp, grind =] lemma mem_disjiUnion {b : β} {h} : b ∈ s.disjiUnion t h ↔ ∃ a ∈ s, b ∈ t a := by
simp only [mem_def, disjiUnion_val, Multiset.mem_bind]
@[simp, norm_cast]
lemma coe_disjiUnion {h} : (s.disjiUnion t h : Set β) = ⋃ x ∈ (s : Set α), t x := by
simp [Set.ext_iff, mem_disjiUnion, Set.mem_iUnion, mem_coe]
@[simp] lemma disjiUnion_cons (a : α) (s : Finset α) (ha : a ∉ s) (f : α → Finset β) (H) :
disjiUnion (cons a s ha) f H =
(f a).disjUnion ((s.disjiUnion f) fun _ hb _ hc ↦ H (mem_cons_of_mem hb) (mem_cons_of_mem hc))
(disjoint_left.2 fun _ hb h ↦
let ⟨_, hc, h⟩ := mem_disjiUnion.mp h
disjoint_left.mp
(H (mem_cons_self a s) (mem_cons_of_mem hc) (ne_of_mem_of_not_mem hc ha).symm) hb h) :=
eq_of_veq <| Multiset.cons_bind _ _ _
@[simp] lemma singleton_disjiUnion (a : α) {h} : Finset.disjiUnion {a} t h = t a :=
eq_of_veq <| Multiset.singleton_bind _ _
lemma disjiUnion_disjiUnion (s : Finset α) (f : α → Finset β) (g : β → Finset γ) (h1 h2) :
(s.disjiUnion f h1).disjiUnion g h2 =
s.attach.disjiUnion
(fun a ↦ ((f a).disjiUnion g) fun _ hb _ hc ↦
h2 (mem_disjiUnion.mpr ⟨_, a.prop, hb⟩) (mem_disjiUnion.mpr ⟨_, a.prop, hc⟩))
fun a _ b _ hab ↦
disjoint_left.mpr fun x hxa hxb ↦ by
obtain ⟨xa, hfa, hga⟩ := mem_disjiUnion.mp hxa
obtain ⟨xb, hfb, hgb⟩ := mem_disjiUnion.mp hxb
refine disjoint_left.mp
(h2 (mem_disjiUnion.mpr ⟨_, a.prop, hfa⟩) (mem_disjiUnion.mpr ⟨_, b.prop, hfb⟩) ?_) hga
hgb
rintro rfl
exact disjoint_left.mp (h1 a.prop b.prop <| Subtype.coe_injective.ne hab) hfa hfb :=
eq_of_veq <| Multiset.bind_assoc.trans (Multiset.attach_bind_coe _ _).symm
lemma sUnion_disjiUnion {f : α → Finset (Set β)} (I : Finset α)
(hf : (I : Set α).PairwiseDisjoint f) :
⋃₀ (I.disjiUnion f hf : Set (Set β)) = ⋃ a ∈ I, ⋃₀ ↑(f a) := by
ext
simp only [coe_disjiUnion, Set.mem_sUnion, Set.mem_iUnion, mem_coe, exists_prop]
tauto
section DecidableEq
variable [DecidableEq β] {s : Finset α} {t : Finset β} {f : α → β}
private lemma pairwiseDisjoint_fibers : Set.PairwiseDisjoint ↑t fun a ↦ s.filter (f · = a) :=
fun x' hx y' hy hne ↦ by
simp_rw [disjoint_left, mem_filter]; rintro i ⟨_, rfl⟩ ⟨_, rfl⟩; exact hne rfl
@[simp] lemma disjiUnion_filter_eq (s : Finset α) (t : Finset β) (f : α → β) :
t.disjiUnion (fun a ↦ s.filter (f · = a)) pairwiseDisjoint_fibers =
s.filter fun c ↦ f c ∈ t :=
ext fun b => by simpa using and_comm
lemma disjiUnion_filter_eq_of_maps_to (h : ∀ x ∈ s, f x ∈ t) :
t.disjiUnion (fun a ↦ s.filter (f · = a)) pairwiseDisjoint_fibers = s := by
simpa [filter_eq_self]
end DecidableEq
theorem map_disjiUnion {f : α ↪ β} {s : Finset α} {t : β → Finset γ} {h} :
(s.map f).disjiUnion t h =
s.disjiUnion (fun a => t (f a)) fun _ ha _ hb hab =>
h (mem_map_of_mem _ ha) (mem_map_of_mem _ hb) (f.injective.ne hab) :=
eq_of_veq <| Multiset.bind_map _ _ _
theorem disjiUnion_map {s : Finset α} {t : α → Finset β} {f : β ↪ γ} {h} :
(s.disjiUnion t h).map f =
s.disjiUnion (fun a => (t a).map f) (h.mono' fun _ _ ↦ (disjoint_map _).2) :=
eq_of_veq <| Multiset.map_bind _ _ _
variable {f : α → β} {op : β → β → β} [hc : Std.Commutative op] [ha : Std.Associative op]
theorem fold_disjiUnion {ι : Type*} {s : Finset ι} {t : ι → Finset α} {b : ι → β} {b₀ : β} (h) :
(s.disjiUnion t h).fold op (s.fold op b₀ b) f = s.fold op b₀ fun i => (t i).fold op (b i) f :=
(congr_arg _ <| Multiset.map_bind _ _ _).trans (Multiset.fold_bind _ _ _ _ _)
end DisjiUnion
section BUnion
variable [DecidableEq β]
/-- `Finset.biUnion s t` is the union of `t a` over `a ∈ s`.
(This was formerly `bind` due to the monad structure on types with `DecidableEq`.) -/
protected def biUnion (s : Finset α) (t : α → Finset β) : Finset β :=
(s.1.bind fun a ↦ (t a).1).toFinset
@[simp] lemma biUnion_val (s : Finset α) (t : α → Finset β) :
(s.biUnion t).1 = (s.1.bind fun a ↦ (t a).1).dedup := rfl
@[simp] lemma biUnion_empty : Finset.biUnion ∅ t = ∅ := rfl
@[simp, grind =] lemma mem_biUnion {b : β} : b ∈ s.biUnion t ↔ ∃ a ∈ s, b ∈ t a := by
simp only [mem_def, biUnion_val, Multiset.mem_dedup, Multiset.mem_bind]
@[simp, norm_cast]
lemma coe_biUnion : (s.biUnion t : Set β) = ⋃ x ∈ (s : Set α), t x := by
simp [Set.ext_iff, mem_biUnion, Set.mem_iUnion, mem_coe]
@[simp]
lemma biUnion_insert [DecidableEq α] {a : α} : (insert a s).biUnion t = t a ∪ s.biUnion t := by
aesop
lemma biUnion_congr (hs : s₁ = s₂) (ht : ∀ a ∈ s₁, t₁ a = t₂ a) :
s₁.biUnion t₁ = s₂.biUnion t₂ := by
aesop
@[simp]
lemma disjiUnion_eq_biUnion (s : Finset α) (f : α → Finset β) (hf) :
s.disjiUnion f hf = s.biUnion f := eq_of_veq (s.disjiUnion f hf).nodup.dedup.symm
lemma biUnion_subset {s' : Finset β} : s.biUnion t ⊆ s' ↔ ∀ x ∈ s, t x ⊆ s' := by grind
@[simp]
lemma singleton_biUnion {a : α} : Finset.biUnion {a} t = t a := by grind
lemma biUnion_inter (s : Finset α) (f : α → Finset β) (t : Finset β) :
s.biUnion f ∩ t = s.biUnion fun x ↦ f x ∩ t := by grind
lemma inter_biUnion (t : Finset β) (s : Finset α) (f : α → Finset β) :
t ∩ s.biUnion f = s.biUnion fun x ↦ t ∩ f x := by grind
lemma biUnion_biUnion [DecidableEq γ] (s : Finset α) (f : α → Finset β) (g : β → Finset γ) :
(s.biUnion f).biUnion g = s.biUnion fun a ↦ (f a).biUnion g := by grind
lemma bind_toFinset [DecidableEq α] (s : Multiset α) (t : α → Multiset β) :
(s.bind t).toFinset = s.toFinset.biUnion fun a ↦ (t a).toFinset :=
ext fun x ↦ by simp only [Multiset.mem_toFinset, mem_biUnion, Multiset.mem_bind]
lemma biUnion_mono (h : ∀ a ∈ s, t₁ a ⊆ t₂ a) : s.biUnion t₁ ⊆ s.biUnion t₂ := by grind
lemma biUnion_subset_biUnion_of_subset_left (t : α → Finset β) (h : s₁ ⊆ s₂) :
s₁.biUnion t ⊆ s₂.biUnion t := by grind
lemma subset_biUnion_of_mem (u : α → Finset β) {x : α} (xs : x ∈ s) : u x ⊆ s.biUnion u := by grind
@[simp]
lemma biUnion_subset_iff_forall_subset {α β : Type*} [DecidableEq β] {s : Finset α}
{t : Finset β} {f : α → Finset β} : s.biUnion f ⊆ t ↔ ∀ x ∈ s, f x ⊆ t := by grind
@[simp]
lemma biUnion_singleton_eq_self [DecidableEq α] : s.biUnion (singleton : α → Finset α) = s := by
grind
lemma filter_biUnion (s : Finset α) (f : α → Finset β) (p : β → Prop) [DecidablePred p] :
(s.biUnion f).filter p = s.biUnion fun a ↦ (f a).filter p := by grind
lemma biUnion_filter_eq_of_maps_to [DecidableEq α] {s : Finset α} {t : Finset β} {f : α → β}
(h : ∀ x ∈ s, f x ∈ t) : (t.biUnion fun a ↦ s.filter fun c ↦ f c = a) = s := by grind
lemma erase_biUnion (f : α → Finset β) (s : Finset α) (b : β) :
(s.biUnion f).erase b = s.biUnion fun x ↦ (f x).erase b := by grind
@[simp]
lemma biUnion_nonempty : (s.biUnion t).Nonempty ↔ ∃ x ∈ s, (t x).Nonempty := by
simp only [Finset.Nonempty, mem_biUnion]
rw [exists_swap]
simp [exists_and_left]
lemma Nonempty.biUnion (hs : s.Nonempty) (ht : ∀ x ∈ s, (t x).Nonempty) :
(s.biUnion t).Nonempty := biUnion_nonempty.2 <| hs.imp fun x hx ↦ ⟨hx, ht x hx⟩
lemma disjoint_biUnion_left (s : Finset α) (f : α → Finset β) (t : Finset β) :
Disjoint (s.biUnion f) t ↔ ∀ i ∈ s, Disjoint (f i) t := by
classical
refine s.induction ?_ ?_
· simp only [forall_mem_empty_iff, biUnion_empty, disjoint_empty_left]
· intro i s his ih
simp only [disjoint_union_left, biUnion_insert, forall_mem_insert, ih]
lemma disjoint_biUnion_right (s : Finset β) (t : Finset α) (f : α → Finset β) :
Disjoint s (t.biUnion f) ↔ ∀ i ∈ t, Disjoint s (f i) := by
simpa only [_root_.disjoint_comm] using disjoint_biUnion_left t f s
theorem image_biUnion [DecidableEq γ] {f : α → β} {s : Finset α} {t : β → Finset γ} :
(s.image f).biUnion t = s.biUnion fun a => t (f a) :=
haveI := Classical.decEq α
Finset.induction_on s rfl fun a s _ ih => by simp only [image_insert, biUnion_insert, ih]
theorem biUnion_image [DecidableEq γ] {s : Finset α} {t : α → Finset β} {f : β → γ} :
(s.biUnion t).image f = s.biUnion fun a => (t a).image f :=
haveI := Classical.decEq α
Finset.induction_on s rfl fun a s _ ih => by simp only [biUnion_insert, image_union, ih]
theorem image_biUnion_filter_eq [DecidableEq α] (s : Finset β) (g : β → α) :
((s.image g).biUnion fun a => s.filter fun c => g c = a) = s :=
biUnion_filter_eq_of_maps_to fun _ => mem_image_of_mem g
theorem biUnion_singleton {f : α → β} : (s.biUnion fun a => {f a}) = s.image f := by grind
end BUnion
end Finset
|
BumpFunction.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.BumpFunction.FiniteDimension
import Mathlib.Geometry.Manifold.ContMDiff.Atlas
import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace
import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas
/-!
# Smooth bump functions on a smooth manifold
In this file we define `SmoothBumpFunction I c` to be a bundled smooth "bump" function centered at
`c`. It is a structure that consists of two real numbers `0 < rIn < rOut` with small enough `rOut`.
We define a coercion to function for this type, and for `f : SmoothBumpFunction I c`, the function
`⇑f` written in the extended chart at `c` has the following properties:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `c`;
* `0 ≤ f x ≤ 1` for all `x`.
The actual statements involve (pre)images under `extChartAt I f` and are given as lemmas in the
`SmoothBumpFunction` namespace.
## Tags
manifold, smooth bump function
-/
universe uE uF uH uM
variable {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E]
{H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M]
[ChartedSpace H M]
open Function Filter Module Set Metric
open scoped Topology Manifold ContDiff
noncomputable section
/-!
### Smooth bump function
In this section we define a structure for a bundled smooth bump function and prove its properties.
-/
variable (I) in
/-- Given a smooth manifold modelled on a finite dimensional space `E`,
`f : SmoothBumpFunction I M` is a smooth function on `M` such that in the extended chart `e` at
`f.c`:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `f.c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `f.c`;
* `0 ≤ f x ≤ 1` for all `x`.
The structure contains data required to construct a function with these properties. The function is
available as `⇑f` or `f x`. Formal statements of the properties listed above involve some
(pre)images under `extChartAt I f.c` and are given as lemmas in the `SmoothBumpFunction`
namespace. -/
structure SmoothBumpFunction (c : M) extends ContDiffBump (extChartAt I c c) where
closedBall_subset : closedBall (extChartAt I c c) rOut ∩ range I ⊆ (extChartAt I c).target
namespace SmoothBumpFunction
section FiniteDimensional
variable [FiniteDimensional ℝ E]
variable {c : M} (f : SmoothBumpFunction I c) {x : M}
/-- The function defined by `f : SmoothBumpFunction c`. Use automatic coercion to function
instead. -/
@[coe] def toFun : M → ℝ :=
indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c)
instance : CoeFun (SmoothBumpFunction I c) fun _ => M → ℝ :=
⟨toFun⟩
theorem coe_def : ⇑f = indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c) :=
rfl
end FiniteDimensional
variable {c : M} (f : SmoothBumpFunction I c) {x : M}
theorem rOut_pos : 0 < f.rOut :=
f.toContDiffBump.rOut_pos
theorem ball_subset : ball (extChartAt I c c) f.rOut ∩ range I ⊆ (extChartAt I c).target :=
Subset.trans (inter_subset_inter_left _ ball_subset_closedBall) f.closedBall_subset
theorem ball_inter_range_eq_ball_inter_target :
ball (extChartAt I c c) f.rOut ∩ range I =
ball (extChartAt I c c) f.rOut ∩ (extChartAt I c).target :=
(subset_inter inter_subset_left f.ball_subset).antisymm <| inter_subset_inter_right _ <|
extChartAt_target_subset_range _
section FiniteDimensional
variable [FiniteDimensional ℝ E]
theorem eqOn_source : EqOn f (f.toContDiffBump ∘ extChartAt I c) (chartAt H c).source :=
eqOn_indicator
theorem eventuallyEq_of_mem_source (hx : x ∈ (chartAt H c).source) :
f =ᶠ[𝓝 x] f.toContDiffBump ∘ extChartAt I c :=
f.eqOn_source.eventuallyEq_of_mem <| (chartAt H c).open_source.mem_nhds hx
theorem one_of_dist_le (hs : x ∈ (chartAt H c).source)
(hd : dist (extChartAt I c x) (extChartAt I c c) ≤ f.rIn) : f x = 1 := by
simp only [f.eqOn_source hs, (· ∘ ·), f.one_of_mem_closedBall hd]
theorem support_eq_inter_preimage :
support f = (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) f.rOut := by
rw [coe_def, support_indicator, support_comp_eq_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', ← (extChartAt I c).symm_image_target_inter_eq',
f.support_eq]
theorem isOpen_support : IsOpen (support f) := by
rw [support_eq_inter_preimage]
exact isOpen_extChartAt_preimage c isOpen_ball
theorem support_eq_symm_image :
support f = (extChartAt I c).symm '' (ball (extChartAt I c c) f.rOut ∩ range I) := by
rw [f.support_eq_inter_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', inter_comm,
ball_inter_range_eq_ball_inter_target]
theorem support_subset_source : support f ⊆ (chartAt H c).source := by
rw [f.support_eq_inter_preimage, ← extChartAt_source I]; exact inter_subset_left
theorem image_eq_inter_preimage_of_subset_support {s : Set M} (hs : s ⊆ support f) :
extChartAt I c '' s =
closedBall (extChartAt I c c) f.rOut ∩ range I ∩ (extChartAt I c).symm ⁻¹' s := by
rw [support_eq_inter_preimage, subset_inter_iff, ← extChartAt_source I, ← image_subset_iff] at hs
obtain ⟨hse, hsf⟩ := hs
apply Subset.antisymm
· refine subset_inter (subset_inter (hsf.trans ball_subset_closedBall) ?_) ?_
· rintro _ ⟨x, -, rfl⟩; exact mem_range_self _
· rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse]
exact inter_subset_right
· refine Subset.trans (inter_subset_inter_left _ f.closedBall_subset) ?_
rw [(extChartAt I c).image_eq_target_inter_inv_preimage hse]
theorem mem_Icc : f x ∈ Icc (0 : ℝ) 1 := by
have : f x = 0 ∨ f x = _ := indicator_eq_zero_or_self _ _ _
rcases this with h | h <;> rw [h]
exacts [left_mem_Icc.2 zero_le_one, ⟨f.nonneg, f.le_one⟩]
theorem nonneg : 0 ≤ f x :=
f.mem_Icc.1
theorem le_one : f x ≤ 1 :=
f.mem_Icc.2
theorem eventuallyEq_one_of_dist_lt (hs : x ∈ (chartAt H c).source)
(hd : dist (extChartAt I c x) (extChartAt I c c) < f.rIn) : f =ᶠ[𝓝 x] 1 := by
filter_upwards [IsOpen.mem_nhds (isOpen_extChartAt_preimage c isOpen_ball) ⟨hs, hd⟩]
rintro z ⟨hzs, hzd⟩
exact f.one_of_dist_le hzs <| le_of_lt hzd
theorem eventuallyEq_one : f =ᶠ[𝓝 c] 1 :=
f.eventuallyEq_one_of_dist_lt (mem_chart_source _ _) <| by rw [dist_self]; exact f.rIn_pos
@[simp]
theorem eq_one : f c = 1 :=
f.eventuallyEq_one.eq_of_nhds
theorem support_mem_nhds : support f ∈ 𝓝 c :=
f.eventuallyEq_one.mono fun x hx => by rw [hx]; exact one_ne_zero
theorem tsupport_mem_nhds : tsupport f ∈ 𝓝 c :=
mem_of_superset f.support_mem_nhds subset_closure
theorem c_mem_support : c ∈ support f :=
mem_of_mem_nhds f.support_mem_nhds
theorem nonempty_support : (support f).Nonempty :=
⟨c, f.c_mem_support⟩
theorem isCompact_symm_image_closedBall :
IsCompact ((extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I)) :=
((isCompact_closedBall _ _).inter_right I.isClosed_range).image_of_continuousOn <|
(continuousOn_extChartAt_symm _).mono f.closedBall_subset
end FiniteDimensional
/-- Given a smooth bump function `f : SmoothBumpFunction I c`, the closed ball of radius `f.R` is
known to include the support of `f`. These closed balls (in the model normed space `E`) intersected
with `Set.range I` form a basis of `𝓝[range I] (extChartAt I c c)`. -/
theorem nhdsWithin_range_basis :
(𝓝[range I] extChartAt I c c).HasBasis (fun _ : SmoothBumpFunction I c => True) fun f =>
closedBall (extChartAt I c c) f.rOut ∩ range I := by
refine ((nhdsWithin_hasBasis nhds_basis_closedBall _).restrict_subset
(extChartAt_target_mem_nhdsWithin _)).to_hasBasis' ?_ ?_
· rintro R ⟨hR0, hsub⟩
exact ⟨⟨⟨R / 2, R, half_pos hR0, half_lt_self hR0⟩, hsub⟩, trivial, Subset.rfl⟩
· exact fun f _ => inter_mem (mem_nhdsWithin_of_mem_nhds <| closedBall_mem_nhds _ f.rOut_pos)
self_mem_nhdsWithin
variable [FiniteDimensional ℝ E]
theorem isClosed_image_of_isClosed {s : Set M} (hsc : IsClosed s) (hs : s ⊆ support f) :
IsClosed (extChartAt I c '' s) := by
rw [f.image_eq_inter_preimage_of_subset_support hs]
refine ContinuousOn.preimage_isClosed_of_isClosed
((continuousOn_extChartAt_symm _).mono f.closedBall_subset) ?_ hsc
exact IsClosed.inter isClosed_closedBall I.isClosed_range
/-- If `f` is a smooth bump function and `s` closed subset of the support of `f` (i.e., of the open
ball of radius `f.rOut`), then there exists `0 < r < f.rOut` such that `s` is a subset of the open
ball of radius `r`. Formally, `s ⊆ e.source ∩ e ⁻¹' (ball (e c) r)`, where `e = extChartAt I c`. -/
theorem exists_r_pos_lt_subset_ball {s : Set M} (hsc : IsClosed s) (hs : s ⊆ support f) :
∃ r ∈ Ioo 0 f.rOut,
s ⊆ (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) r := by
set e := extChartAt I c
have : IsClosed (e '' s) := f.isClosed_image_of_isClosed hsc hs
rw [support_eq_inter_preimage, subset_inter_iff, ← image_subset_iff] at hs
rcases exists_pos_lt_subset_ball f.rOut_pos this hs.2 with ⟨r, hrR, hr⟩
exact ⟨r, hrR, subset_inter hs.1 (image_subset_iff.1 hr)⟩
/-- Replace `rIn` with another value in the interval `(0, f.rOut)`. -/
@[simps rOut rIn]
def updateRIn (r : ℝ) (hr : r ∈ Ioo 0 f.rOut) : SmoothBumpFunction I c :=
⟨⟨r, f.rOut, hr.1, hr.2⟩, f.closedBall_subset⟩
@[simp]
theorem support_updateRIn {r : ℝ} (hr : r ∈ Ioo 0 f.rOut) :
support (f.updateRIn r hr) = support f := by
simp only [support_eq_inter_preimage, updateRIn_rOut]
-- Porting note: was an `Inhabited` instance
instance : Nonempty (SmoothBumpFunction I c) := nhdsWithin_range_basis.nonempty
variable [T2Space M]
theorem isClosed_symm_image_closedBall :
IsClosed ((extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I)) :=
f.isCompact_symm_image_closedBall.isClosed
theorem tsupport_subset_symm_image_closedBall :
tsupport f ⊆ (extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I) := by
rw [tsupport, support_eq_symm_image]
exact closure_minimal (image_mono <| inter_subset_inter_left _ ball_subset_closedBall)
f.isClosed_symm_image_closedBall
theorem tsupport_subset_extChartAt_source : tsupport f ⊆ (extChartAt I c).source :=
calc
tsupport f ⊆ (extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I) :=
f.tsupport_subset_symm_image_closedBall
_ ⊆ (extChartAt I c).symm '' (extChartAt I c).target := image_mono f.closedBall_subset
_ = (extChartAt I c).source := (extChartAt I c).symm_image_target_eq_source
theorem tsupport_subset_chartAt_source : tsupport f ⊆ (chartAt H c).source := by
simpa only [extChartAt_source] using f.tsupport_subset_extChartAt_source
protected theorem hasCompactSupport : HasCompactSupport f :=
f.isCompact_symm_image_closedBall.of_isClosed_subset isClosed_closure
f.tsupport_subset_symm_image_closedBall
variable (c) in
/-- The closures of supports of smooth bump functions centered at `c` form a basis of `𝓝 c`.
In other words, each of these closures is a neighborhood of `c` and each neighborhood of `c`
includes `tsupport f` for some `f : SmoothBumpFunction I c`. -/
theorem nhds_basis_tsupport :
(𝓝 c).HasBasis (fun _ : SmoothBumpFunction I c => True) fun f => tsupport f := by
have :
(𝓝 c).HasBasis (fun _ : SmoothBumpFunction I c => True) fun f =>
(extChartAt I c).symm '' (closedBall (extChartAt I c c) f.rOut ∩ range I) := by
rw [← map_extChartAt_symm_nhdsWithin_range (I := I) c]
exact nhdsWithin_range_basis.map _
exact this.to_hasBasis' (fun f _ => ⟨f, trivial, f.tsupport_subset_symm_image_closedBall⟩)
fun f _ => f.tsupport_mem_nhds
/-- Given `s ∈ 𝓝 c`, the supports of smooth bump functions `f : SmoothBumpFunction I c` such that
`tsupport f ⊆ s` form a basis of `𝓝 c`. In other words, each of these supports is a
neighborhood of `c` and each neighborhood of `c` includes `support f` for some
`f : SmoothBumpFunction I c` such that `tsupport f ⊆ s`. -/
theorem nhds_basis_support {s : Set M} (hs : s ∈ 𝓝 c) :
(𝓝 c).HasBasis (fun f : SmoothBumpFunction I c => tsupport f ⊆ s) fun f => support f :=
((nhds_basis_tsupport c).restrict_subset hs).to_hasBasis'
(fun f hf => ⟨f, hf.2, subset_closure⟩) fun f _ => f.support_mem_nhds
variable [IsManifold I ∞ M]
/-- A smooth bump function is infinitely smooth. -/
protected theorem contMDiff : ContMDiff I 𝓘(ℝ) ∞ f := by
refine contMDiff_of_tsupport fun x hx => ?_
have : x ∈ (chartAt H c).source := f.tsupport_subset_chartAt_source hx
refine ContMDiffAt.congr_of_eventuallyEq ?_ <| f.eqOn_source.eventuallyEq_of_mem <|
(chartAt H c).open_source.mem_nhds this
exact f.contDiffAt.contMDiffAt.comp _ (contMDiffAt_extChartAt' this)
protected theorem contMDiffAt {x} : ContMDiffAt I 𝓘(ℝ) ∞ f x :=
f.contMDiff.contMDiffAt
protected theorem continuous : Continuous f :=
f.contMDiff.continuous
/-- If `f : SmoothBumpFunction I c` is a smooth bump function and `g : M → G` is a function smooth
on the source of the chart at `c`, then `f • g` is smooth on the whole manifold. -/
theorem contMDiff_smul {G} [NormedAddCommGroup G] [NormedSpace ℝ G] {g : M → G}
(hg : ContMDiffOn I 𝓘(ℝ, G) ∞ g (chartAt H c).source) :
ContMDiff I 𝓘(ℝ, G) ∞ fun x => f x • g x := by
refine contMDiff_of_tsupport fun x hx => ?_
have : x ∈ (chartAt H c).source :=
-- Porting note: was a more readable `calc`
-- calc
-- x ∈ tsupport fun x => f x • g x := hx
-- _ ⊆ tsupport f := tsupport_smul_subset_left _ _
-- _ ⊆ (chart_at _ c).source := f.tsupport_subset_chartAt_source
f.tsupport_subset_chartAt_source <| tsupport_smul_subset_left _ _ hx
exact f.contMDiffAt.smul ((hg _ this).contMDiffAt <| (chartAt _ _).open_source.mem_nhds this)
end SmoothBumpFunction
|
AEMeasurable.lean
|
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.MeasureTheory.Measure.Trim
import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. This property, called `AEMeasurable f μ`, is defined in the file `MeasureSpaceDef`.
We discuss several of its properties that are analogous to properties of measurable functions.
-/
open MeasureTheory MeasureTheory.Measure Filter Set Function ENNReal
variable {ι α β γ δ R : Type*} {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
[MeasurableSpace δ] {f g : α → β} {μ ν : Measure α}
section
@[nontriviality, measurability]
theorem Subsingleton.aemeasurable [Subsingleton α] : AEMeasurable f μ :=
Subsingleton.measurable.aemeasurable
@[nontriviality, measurability]
theorem aemeasurable_of_subsingleton_codomain [Subsingleton β] : AEMeasurable f μ :=
(measurable_of_subsingleton_codomain f).aemeasurable
@[simp, fun_prop, measurability]
theorem aemeasurable_zero_measure : AEMeasurable f (0 : Measure α) := by
nontriviality α; inhabit α
exact ⟨fun _ => f default, measurable_const, rfl⟩
theorem aemeasurable_id'' (μ : Measure α) {m : MeasurableSpace α} (hm : m ≤ m0) :
@AEMeasurable α α m m0 id μ :=
@Measurable.aemeasurable α α m0 m id μ (measurable_id'' hm)
lemma aemeasurable_of_map_neZero {μ : Measure α}
{f : α → β} (h : NeZero (μ.map f)) :
AEMeasurable f μ := by
by_contra h'
simp [h'] at h
namespace AEMeasurable
lemma mono_ac (hf : AEMeasurable f ν) (hμν : μ ≪ ν) : AEMeasurable f μ :=
⟨hf.mk f, hf.measurable_mk, hμν.ae_le hf.ae_eq_mk⟩
theorem mono_measure (h : AEMeasurable f μ) (h' : ν ≤ μ) : AEMeasurable f ν :=
mono_ac h h'.absolutelyContinuous
theorem mono_set {s t} (h : s ⊆ t) (ht : AEMeasurable f (μ.restrict t)) :
AEMeasurable f (μ.restrict s) :=
ht.mono_measure (restrict_mono h le_rfl)
@[fun_prop]
protected theorem mono' (h : AEMeasurable f μ) (h' : ν ≪ μ) : AEMeasurable f ν :=
⟨h.mk f, h.measurable_mk, h' h.ae_eq_mk⟩
theorem ae_mem_imp_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) :
∀ᵐ x ∂μ, x ∈ s → f x = h.mk f x :=
ae_imp_of_ae_restrict h.ae_eq_mk
theorem ae_inf_principal_eq_mk {s} (h : AEMeasurable f (μ.restrict s)) : f =ᶠ[ae μ ⊓ 𝓟 s] h.mk f :=
le_ae_restrict h.ae_eq_mk
@[measurability]
theorem sum_measure [Countable ι] {μ : ι → Measure α} (h : ∀ i, AEMeasurable f (μ i)) :
AEMeasurable f (sum μ) := by
classical
nontriviality β
inhabit β
set s : ι → Set α := fun i => toMeasurable (μ i) { x | f x ≠ (h i).mk f x }
have hsμ : ∀ i, μ i (s i) = 0 := by
intro i
rw [measure_toMeasurable]
exact (h i).ae_eq_mk
have hsm : MeasurableSet (⋂ i, s i) :=
MeasurableSet.iInter fun i => measurableSet_toMeasurable _ _
have hs : ∀ i x, x ∉ s i → f x = (h i).mk f x := by
intro i x hx
contrapose! hx
exact subset_toMeasurable _ _ hx
set g : α → β := (⋂ i, s i).piecewise (const α default) f
refine ⟨g, measurable_of_restrict_of_restrict_compl hsm ?_ ?_, ae_sum_iff.mpr fun i => ?_⟩
· rw [restrict_piecewise]
simp only [s]
exact measurable_const
· rw [restrict_piecewise_compl, compl_iInter]
intro t ht
refine ⟨⋃ i, (h i).mk f ⁻¹' t ∩ (s i)ᶜ, MeasurableSet.iUnion fun i ↦
(measurable_mk _ ht).inter (measurableSet_toMeasurable _ _).compl, ?_⟩
ext ⟨x, hx⟩
simp only [mem_preimage, mem_iUnion, Set.restrict, mem_inter_iff,
mem_compl_iff] at hx ⊢
constructor
· rintro ⟨i, hxt, hxs⟩
rwa [hs _ _ hxs]
· rcases hx with ⟨i, hi⟩
rw [hs _ _ hi]
exact fun h => ⟨i, h, hi⟩
· refine measure_mono_null (fun x (hx : f x ≠ g x) => ?_) (hsμ i)
contrapose! hx
refine (piecewise_eq_of_notMem _ _ _ ?_).symm
exact fun h => hx (mem_iInter.1 h i)
@[simp]
theorem _root_.aemeasurable_sum_measure_iff [Countable ι] {μ : ι → Measure α} :
AEMeasurable f (sum μ) ↔ ∀ i, AEMeasurable f (μ i) :=
⟨fun h _ => h.mono_measure (le_sum _ _), sum_measure⟩
@[simp]
theorem _root_.aemeasurable_add_measure_iff :
AEMeasurable f (μ + ν) ↔ AEMeasurable f μ ∧ AEMeasurable f ν := by
rw [← sum_cond, aemeasurable_sum_measure_iff, Bool.forall_bool, and_comm]
rfl
@[measurability]
theorem add_measure {f : α → β} (hμ : AEMeasurable f μ) (hν : AEMeasurable f ν) :
AEMeasurable f (μ + ν) :=
aemeasurable_add_measure_iff.2 ⟨hμ, hν⟩
@[measurability]
protected theorem iUnion [Countable ι] {s : ι → Set α}
(h : ∀ i, AEMeasurable f (μ.restrict (s i))) : AEMeasurable f (μ.restrict (⋃ i, s i)) :=
(sum_measure h).mono_measure <| restrict_iUnion_le
@[simp]
theorem _root_.aemeasurable_iUnion_iff [Countable ι] {s : ι → Set α} :
AEMeasurable f (μ.restrict (⋃ i, s i)) ↔ ∀ i, AEMeasurable f (μ.restrict (s i)) :=
⟨fun h _ => h.mono_measure <| restrict_mono (subset_iUnion _ _) le_rfl, AEMeasurable.iUnion⟩
@[simp]
theorem _root_.aemeasurable_union_iff {s t : Set α} :
AEMeasurable f (μ.restrict (s ∪ t)) ↔
AEMeasurable f (μ.restrict s) ∧ AEMeasurable f (μ.restrict t) := by
simp only [union_eq_iUnion, aemeasurable_iUnion_iff, Bool.forall_bool, cond, and_comm]
@[measurability]
theorem smul_measure [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞]
(h : AEMeasurable f μ) (c : R) : AEMeasurable f (c • μ) :=
⟨h.mk f, h.measurable_mk, ae_smul_measure h.ae_eq_mk c⟩
theorem comp_aemeasurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : AEMeasurable f μ) : AEMeasurable (g ∘ f) μ :=
⟨hg.mk g ∘ hf.mk f, hg.measurable_mk.comp hf.measurable_mk,
(ae_eq_comp hf hg.ae_eq_mk).trans (hf.ae_eq_mk.fun_comp (mk g hg))⟩
@[fun_prop]
theorem comp_aemeasurable' {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : AEMeasurable f μ) : AEMeasurable (fun x ↦ g (f x)) μ := comp_aemeasurable hg hf
theorem comp_measurable {f : α → δ} {g : δ → β} (hg : AEMeasurable g (μ.map f))
(hf : Measurable f) : AEMeasurable (g ∘ f) μ :=
hg.comp_aemeasurable hf.aemeasurable
@[fun_prop]
theorem comp_quasiMeasurePreserving {ν : Measure δ} {f : α → δ} {g : δ → β} (hg : AEMeasurable g ν)
(hf : QuasiMeasurePreserving f μ ν) : AEMeasurable (g ∘ f) μ :=
(hg.mono' hf.absolutelyContinuous).comp_measurable hf.measurable
theorem map_map_of_aemeasurable {g : β → γ} {f : α → β} (hg : AEMeasurable g (Measure.map f μ))
(hf : AEMeasurable f μ) : (μ.map f).map g = μ.map (g ∘ f) := by
ext1 s hs
rw [map_apply_of_aemeasurable hg hs, map_apply₀ hf (hg.nullMeasurable hs),
map_apply_of_aemeasurable (hg.comp_aemeasurable hf) hs, preimage_comp]
@[fun_prop, measurability]
protected theorem fst {f : α → β × γ} (hf : AEMeasurable f μ) :
AEMeasurable (fun x ↦ (f x).1) μ :=
measurable_fst.comp_aemeasurable hf
@[fun_prop, measurability]
protected theorem snd {f : α → β × γ} (hf : AEMeasurable f μ) :
AEMeasurable (fun x ↦ (f x).2) μ :=
measurable_snd.comp_aemeasurable hf
@[fun_prop, measurability]
theorem prodMk {f : α → β} {g : α → γ} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
AEMeasurable (fun x => (f x, g x)) μ :=
⟨fun a => (hf.mk f a, hg.mk g a), hf.measurable_mk.prodMk hg.measurable_mk,
hf.ae_eq_mk.prodMk hg.ae_eq_mk⟩
@[deprecated (since := "2025-03-05")]
alias prod_mk := prodMk
theorem exists_ae_eq_range_subset (H : AEMeasurable f μ) {t : Set β} (ht : ∀ᵐ x ∂μ, f x ∈ t)
(h₀ : t.Nonempty) : ∃ g, Measurable g ∧ range g ⊆ t ∧ f =ᵐ[μ] g := by
classical
let s : Set α := toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ
let g : α → β := piecewise s (fun _ => h₀.some) (H.mk f)
refine ⟨g, ?_, ?_, ?_⟩
· exact Measurable.piecewise (measurableSet_toMeasurable _ _) measurable_const H.measurable_mk
· rintro _ ⟨x, rfl⟩
by_cases hx : x ∈ s
· simpa [g, hx] using h₀.some_mem
· simp only [g, hx, piecewise_eq_of_notMem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp +contextual only [hx, mem_compl_iff, mem_setOf_eq, not_and,
not_false_iff, imp_true_iff]
· have A : μ (toMeasurable μ { x | f x = H.mk f x ∧ f x ∈ t }ᶜ) = 0 := by
rw [measure_toMeasurable, ← compl_mem_ae_iff, compl_compl]
exact H.ae_eq_mk.and ht
filter_upwards [compl_mem_ae_iff.2 A] with x hx
rw [mem_compl_iff] at hx
simp only [s, g, hx, piecewise_eq_of_notMem, not_false_iff]
contrapose! hx
apply subset_toMeasurable
simp only [hx, mem_compl_iff, mem_setOf_eq, false_and, not_false_iff]
theorem exists_measurable_nonneg {β} [Preorder β] [Zero β] {mβ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (f_nn : ∀ᵐ t ∂μ, 0 ≤ f t) : ∃ g, Measurable g ∧ 0 ≤ g ∧ f =ᵐ[μ] g := by
obtain ⟨G, hG_meas, hG_mem, hG_ae_eq⟩ := hf.exists_ae_eq_range_subset f_nn ⟨0, le_rfl⟩
exact ⟨G, hG_meas, fun x => hG_mem (mem_range_self x), hG_ae_eq⟩
theorem subtype_mk (h : AEMeasurable f μ) {s : Set β} {hfs : ∀ x, f x ∈ s} :
AEMeasurable (codRestrict f s hfs) μ := by
nontriviality α; inhabit α
obtain ⟨g, g_meas, hg, fg⟩ : ∃ g : α → β, Measurable g ∧ range g ⊆ s ∧ f =ᵐ[μ] g :=
h.exists_ae_eq_range_subset (Eventually.of_forall hfs) ⟨_, hfs default⟩
refine ⟨codRestrict g s fun x => hg (mem_range_self _), Measurable.subtype_mk g_meas, ?_⟩
filter_upwards [fg] with x hx
simpa [Subtype.ext_iff]
end AEMeasurable
theorem aemeasurable_const' (h : ∀ᵐ (x) (y) ∂μ, f x = f y) : AEMeasurable f μ := by
rcases eq_or_ne μ 0 with (rfl | hμ)
· exact aemeasurable_zero_measure
· haveI := ae_neBot.2 hμ
rcases h.exists with ⟨x, hx⟩
exact ⟨const α (f x), measurable_const, EventuallyEq.symm hx⟩
open scoped Interval in
theorem aemeasurable_uIoc_iff [LinearOrder α] {f : α → β} {a b : α} :
(AEMeasurable f <| μ.restrict <| Ι a b) ↔
(AEMeasurable f <| μ.restrict <| Ioc a b) ∧ (AEMeasurable f <| μ.restrict <| Ioc b a) := by
rw [uIoc_eq_union, aemeasurable_union_iff]
theorem aemeasurable_iff_measurable [μ.IsComplete] : AEMeasurable f μ ↔ Measurable f :=
⟨fun h => h.nullMeasurable.measurable_of_complete, fun h => h.aemeasurable⟩
theorem MeasurableEmbedding.aemeasurable_map_iff {g : β → γ} (hf : MeasurableEmbedding f) :
AEMeasurable g (μ.map f) ↔ AEMeasurable (g ∘ f) μ := by
refine ⟨fun H => H.comp_measurable hf.measurable, ?_⟩
rintro ⟨g₁, hgm₁, heq⟩
rcases hf.exists_measurable_extend hgm₁ fun x => ⟨g x⟩ with ⟨g₂, hgm₂, rfl⟩
exact ⟨g₂, hgm₂, hf.ae_map_iff.2 heq⟩
theorem MeasurableEmbedding.aemeasurable_comp_iff {g : β → γ} (hg : MeasurableEmbedding g)
{μ : Measure α} : AEMeasurable (g ∘ f) μ ↔ AEMeasurable f μ := by
refine ⟨fun H => ?_, hg.measurable.comp_aemeasurable⟩
suffices AEMeasurable ((rangeSplitting g ∘ rangeFactorization g) ∘ f) μ by
rwa [(rightInverse_rangeSplitting hg.injective).comp_eq_id] at this
exact hg.measurable_rangeSplitting.comp_aemeasurable H.subtype_mk
theorem aemeasurable_restrict_iff_comap_subtype {s : Set α} (hs : MeasurableSet s) {μ : Measure α}
{f : α → β} : AEMeasurable f (μ.restrict s) ↔ AEMeasurable (f ∘ (↑) : s → β) (comap (↑) μ) := by
rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).aemeasurable_map_iff]
@[to_additive]
theorem aemeasurable_one [One β] : AEMeasurable (fun _ : α => (1 : β)) μ :=
measurable_one.aemeasurable
@[simp]
theorem aemeasurable_smul_measure_iff {c : ℝ≥0∞} (hc : c ≠ 0) :
AEMeasurable f (c • μ) ↔ AEMeasurable f μ :=
⟨fun h => ⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).1 h.ae_eq_mk⟩, fun h =>
⟨h.mk f, h.measurable_mk, (ae_smul_measure_iff hc).2 h.ae_eq_mk⟩⟩
theorem aemeasurable_of_aemeasurable_trim {α} {m m0 : MeasurableSpace α} {μ : Measure α}
(hm : m ≤ m0) {f : α → β} (hf : AEMeasurable f (μ.trim hm)) : AEMeasurable f μ :=
⟨hf.mk f, Measurable.mono hf.measurable_mk hm le_rfl, ae_eq_of_ae_eq_trim hf.ae_eq_mk⟩
theorem aemeasurable_restrict_of_measurable_subtype {s : Set α} (hs : MeasurableSet s)
(hf : Measurable fun x : s => f x) : AEMeasurable f (μ.restrict s) :=
(aemeasurable_restrict_iff_comap_subtype hs).2 hf.aemeasurable
theorem aemeasurable_map_equiv_iff (e : α ≃ᵐ β) {f : β → γ} :
AEMeasurable f (μ.map e) ↔ AEMeasurable (f ∘ e) μ :=
e.measurableEmbedding.aemeasurable_map_iff
end
theorem AEMeasurable.restrict (hfm : AEMeasurable f μ) {s} : AEMeasurable f (μ.restrict s) :=
⟨AEMeasurable.mk f hfm, hfm.measurable_mk, ae_restrict_of_ae hfm.ae_eq_mk⟩
theorem aemeasurable_Ioi_of_forall_Ioc {β} {mβ : MeasurableSpace β} [LinearOrder α]
[(atTop : Filter α).IsCountablyGenerated] {x : α} {g : α → β}
(g_meas : ∀ t > x, AEMeasurable g (μ.restrict (Ioc x t))) :
AEMeasurable g (μ.restrict (Ioi x)) := by
haveI : Nonempty α := ⟨x⟩
obtain ⟨u, hu_tendsto⟩ := exists_seq_tendsto (atTop : Filter α)
have Ioi_eq_iUnion : Ioi x = ⋃ n : ℕ, Ioc x (u n) := by
rw [iUnion_Ioc_eq_Ioi_self_iff.mpr _]
exact fun y _ => (hu_tendsto.eventually (eventually_ge_atTop y)).exists
rw [Ioi_eq_iUnion, aemeasurable_iUnion_iff]
intro n
rcases lt_or_ge x (u n) with h | h
· exact g_meas (u n) h
· rw [Ioc_eq_empty (not_lt.mpr h), Measure.restrict_empty]
exact aemeasurable_zero_measure
section Zero
variable [Zero β]
theorem aemeasurable_indicator_iff {s} (hs : MeasurableSet s) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
constructor
· intro h
exact (h.mono_measure Measure.restrict_le_self).congr (indicator_ae_eq_restrict hs)
· intro h
refine ⟨indicator s (h.mk f), h.measurable_mk.indicator hs, ?_⟩
have A : s.indicator f =ᵐ[μ.restrict s] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict hs).trans (h.ae_eq_mk.trans <| (indicator_ae_eq_restrict hs).symm)
have B : s.indicator f =ᵐ[μ.restrict sᶜ] s.indicator (AEMeasurable.mk f h) :=
(indicator_ae_eq_restrict_compl hs).trans (indicator_ae_eq_restrict_compl hs).symm
exact ae_of_ae_restrict_of_ae_restrict_compl _ A B
theorem aemeasurable_indicator_iff₀ {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (indicator s f) μ ↔ AEMeasurable f (μ.restrict s) := by
rcases hs with ⟨t, ht, hst⟩
rw [← aemeasurable_congr (indicator_ae_eq_of_ae_eq_set hst.symm), aemeasurable_indicator_iff ht,
restrict_congr_set hst]
/-- A characterization of the a.e.-measurability of the indicator function which takes a constant
value `b` on a set `A` and `0` elsewhere. -/
lemma aemeasurable_indicator_const_iff {s} [MeasurableSingletonClass β] (b : β) [NeZero b] :
AEMeasurable (s.indicator (fun _ ↦ b)) μ ↔ NullMeasurableSet s μ := by
classical
constructor <;> intro h
· convert h.nullMeasurable (MeasurableSet.singleton (0 : β)).compl
rw [indicator_const_preimage_eq_union s {0}ᶜ b]
simp [NeZero.ne b]
· exact (aemeasurable_indicator_iff₀ h).mpr aemeasurable_const
@[measurability]
theorem AEMeasurable.indicator (hfm : AEMeasurable f μ) {s} (hs : MeasurableSet s) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff hs).mpr hfm.restrict
theorem AEMeasurable.indicator₀ (hfm : AEMeasurable f μ) {s} (hs : NullMeasurableSet s μ) :
AEMeasurable (s.indicator f) μ :=
(aemeasurable_indicator_iff₀ hs).mpr hfm.restrict
end Zero
theorem MeasureTheory.Measure.restrict_map_of_aemeasurable {f : α → δ} (hf : AEMeasurable f μ)
{s : Set δ} (hs : MeasurableSet s) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f :=
calc
(μ.map f).restrict s = (μ.map (hf.mk f)).restrict s := by
congr 1
apply Measure.map_congr hf.ae_eq_mk
_ = (μ.restrict <| hf.mk f ⁻¹' s).map (hf.mk f) := Measure.restrict_map hf.measurable_mk hs
_ = (μ.restrict <| hf.mk f ⁻¹' s).map f :=
(Measure.map_congr (ae_restrict_of_ae hf.ae_eq_mk.symm))
_ = (μ.restrict <| f ⁻¹' s).map f := by
apply congr_arg
ext1 t ht
simp only [ht, Measure.restrict_apply]
apply measure_congr
apply (EventuallyEq.refl _ _).inter (hf.ae_eq_mk.symm.preimage s)
theorem MeasureTheory.Measure.map_mono_of_aemeasurable {f : α → δ} (h : μ ≤ ν)
(hf : AEMeasurable f ν) : μ.map f ≤ ν.map f :=
le_iff.2 fun s hs ↦ by simpa [hf, hs, hf.mono_measure h] using h (f ⁻¹' s)
/-- If the `σ`-algebra of the codomain of a null measurable function is countably generated,
then the function is a.e.-measurable. -/
lemma MeasureTheory.NullMeasurable.aemeasurable {f : α → β}
[hc : MeasurableSpace.CountablyGenerated β] (h : NullMeasurable f μ) : AEMeasurable f μ := by
classical
nontriviality β; inhabit β
rcases hc.1 with ⟨S, hSc, rfl⟩
choose! T hTf hTm hTeq using fun s hs ↦ (h <| .basic s hs).exists_measurable_subset_ae_eq
choose! U hUf hUm hUeq using fun s hs ↦ (h <| .basic s hs).exists_measurable_superset_ae_eq
set v := ⋃ s ∈ S, U s \ T s
have hvm : MeasurableSet v := .biUnion hSc fun s hs ↦ (hUm s hs).diff (hTm s hs)
have hvμ : μ v = 0 := (measure_biUnion_null_iff hSc).2 fun s hs ↦ ae_le_set.1 <|
((hUeq s hs).trans (hTeq s hs).symm).le
refine ⟨v.piecewise (fun _ ↦ default) f, ?_, measure_mono_null (fun x ↦
not_imp_comm.2 fun hxv ↦ (piecewise_eq_of_notMem _ _ _ hxv).symm) hvμ⟩
refine measurable_of_restrict_of_restrict_compl hvm ?_ ?_
· rw [restrict_piecewise]
apply measurable_const
· rw [restrict_piecewise_compl, restrict_eq]
refine measurable_generateFrom fun s hs ↦ .of_subtype_image ?_
rw [preimage_comp, Subtype.image_preimage_coe]
convert (hTm s hs).diff hvm using 1
rw [inter_comm]
refine Set.ext fun x ↦ and_congr_left fun hxv ↦ ⟨fun hx ↦ ?_, fun hx ↦ hTf s hs hx⟩
exact by_contra fun hx' ↦ hxv <| mem_biUnion hs ⟨hUf s hs hx, hx'⟩
/-- Let `f : α → β` be a null measurable function
such that a.e. all values of `f` belong to a set `t`
such that the restriction of the `σ`-algebra in the codomain to `t` is countably generated,
then `f` is a.e.-measurable. -/
lemma MeasureTheory.NullMeasurable.aemeasurable_of_aerange {f : α → β} {t : Set β}
[MeasurableSpace.CountablyGenerated t] (h : NullMeasurable f μ) (hft : ∀ᵐ x ∂μ, f x ∈ t) :
AEMeasurable f μ := by
rcases eq_empty_or_nonempty t with rfl | hne
· obtain rfl : μ = 0 := by simpa using hft
apply aemeasurable_zero_measure
· rw [← μ.ae_completion] at hft
obtain ⟨f', hf'm, hf't, hff'⟩ :
∃ f' : α → β, NullMeasurable f' μ ∧ range f' ⊆ t ∧ f =ᵐ[μ] f' :=
h.measurable'.aemeasurable.exists_ae_eq_range_subset hft hne
rw [range_subset_iff] at hf't
lift f' to α → t using hf't
replace hf'm : NullMeasurable f' μ := hf'm.measurable'.subtype_mk
exact (measurable_subtype_coe.comp_aemeasurable hf'm.aemeasurable).congr hff'.symm
namespace MeasureTheory
namespace Measure
lemma map_sum {ι : Type*} {m : ι → Measure α} {f : α → β} (hf : AEMeasurable f (Measure.sum m)) :
Measure.map f (Measure.sum m) = Measure.sum (fun i ↦ Measure.map f (m i)) := by
ext s hs
rw [map_apply_of_aemeasurable hf hs, sum_apply₀ _ (hf.nullMeasurable hs), sum_apply _ hs]
have M i : AEMeasurable f (m i) := hf.mono_measure (le_sum m i)
simp_rw [map_apply_of_aemeasurable (M _) hs]
instance (μ : Measure α) (f : α → β) [SFinite μ] : SFinite (μ.map f) := by
by_cases H : AEMeasurable f μ
· rw [← sum_sfiniteSeq μ] at H ⊢
rw [map_sum H]
infer_instance
· rw [map_of_not_aemeasurable H]
infer_instance
end Measure
end MeasureTheory
|
nilpotent.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import fintype div bigop prime finset fingroup morphism.
From mathcomp Require Import automorphism quotient commutator gproduct.
From mathcomp Require Import perm gfunctor center gseries cyclic.
From mathcomp Require finfun.
(******************************************************************************)
(* This file defines nilpotent and solvable groups, and give some of their *)
(* elementary properties; more will be added later (e.g., the nilpotence of *)
(* p-groups in sylow.v, or the fact that minimal normal subgroups of solvable *)
(* groups are elementary abelian in maximal.v). This file defines: *)
(* nilpotent G == G is nilpotent, i.e., [~: H, G] is a proper subgroup of H *)
(* for all nontrivial H <| G. *)
(* solvable G == G is solvable, i.e., H^`(1) is a proper subgroup of H for *)
(* all nontrivial subgroups H of G. *)
(* 'L_n(G) == the nth term of the lower central series, namely *)
(* [~: G, ..., G] (n Gs) if n > 0, with 'L_0(G) = G. *)
(* G is nilpotent iff 'L_n(G) = 1 for some n. *)
(* 'Z_n(G) == the nth term of the upper central series, i.e., *)
(* with 'Z_0(G) = 1, 'Z_n.+1(G) / 'Z_n(G) = 'Z(G / 'Z_n(G)). *)
(* nil_class G == the nilpotence class of G, i.e., the least n such that *)
(* 'L_n.+1(G) = 1 (or, equivalently, 'Z_n(G) = G), if G is *)
(* nilpotent; we take nil_class G = #|G| when G is not *)
(* nilpotent, so nil_class G < #|G| iff G is nilpotent. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section SeriesDefs.
Variables (n : nat) (gT : finGroupType) (A : {set gT}).
(* By convention, the lower central series starts at 1 while the upper series *)
(* starts at 0 (sic). *)
Definition lower_central_at := iter n.-1 (fun B => [~: B, A]) A.
Definition upper_central_at := iter n (fun B => coset B @*^-1 'Z(A / B)) 1.
End SeriesDefs.
Arguments lower_central_at n%_N {gT} A%_g.
Arguments upper_central_at n%_N {gT} A%_g : simpl never.
Notation "''L_' n ( G )" := (lower_central_at n G)
(n at level 2, format "''L_' n ( G )") : group_scope.
Notation "''Z_' n ( G )" := (upper_central_at n G)
(n at level 2, format "''Z_' n ( G )") : group_scope.
Section PropertiesDefs.
Variables (gT : finGroupType) (A : {set gT}).
Definition nilpotent :=
[forall (G : {group gT} | G \subset A :&: [~: G, A]), G :==: 1].
Definition nil_class := index 1 (mkseq (fun n => 'L_n.+1(A)) #|A|).
Definition solvable :=
[forall (G : {group gT} | G \subset A :&: [~: G, G]), G :==: 1].
End PropertiesDefs.
Arguments nilpotent {gT} A%_g.
Arguments nil_class {gT} A%_g.
Arguments solvable {gT} A%_g.
Section NilpotentProps.
Variable gT: finGroupType.
Implicit Types (A B : {set gT}) (G H : {group gT}).
Lemma nilpotent1 : nilpotent [1 gT].
Proof. by apply/forall_inP=> H; rewrite commG1 setIid -subG1. Qed.
Lemma nilpotentS A B : B \subset A -> nilpotent A -> nilpotent B.
Proof.
move=> sBA nilA; apply/forall_inP=> H sHR.
have:= forallP nilA H; rewrite (subset_trans sHR) //.
by apply: subset_trans (setIS _ _) (setSI _ _); rewrite ?commgS.
Qed.
Lemma nil_comm_properl G H A :
nilpotent G -> H \subset G -> H :!=: 1 -> A \subset 'N_G(H) ->
[~: H, A] \proper H.
Proof.
move=> nilG sHG ntH; rewrite subsetI properE; case/andP=> sAG nHA.
rewrite (subset_trans (commgS H (subset_gen A))) ?commg_subl ?gen_subG //.
apply: contra ntH => sHR; have:= forallP nilG H; rewrite subsetI sHG.
by rewrite (subset_trans sHR) ?commgS.
Qed.
Lemma nil_comm_properr G A H :
nilpotent G -> H \subset G -> H :!=: 1 -> A \subset 'N_G(H) ->
[~: A, H] \proper H.
Proof. by rewrite commGC; apply: nil_comm_properl. Qed.
Lemma centrals_nil (s : seq {group gT}) G :
G.-central.-series 1%G s -> last 1%G s = G -> nilpotent G.
Proof.
move=> cGs defG; apply/forall_inP=> H /subsetIP[sHG sHR].
move: sHG; rewrite -{}defG -subG1 -[1]/(gval 1%G).
elim: s 1%G cGs => //= L s IHs K /andP[/and3P[sRK sKL sLG] /IHs sHL] sHs.
exact: subset_trans sHR (subset_trans (commSg _ (sHL sHs)) sRK).
Qed.
End NilpotentProps.
Section LowerCentral.
Variable gT : finGroupType.
Implicit Types (A B : {set gT}) (G H : {group gT}).
Lemma lcn0 A : 'L_0(A) = A. Proof. by []. Qed.
Lemma lcn1 A : 'L_1(A) = A. Proof. by []. Qed.
Lemma lcnSn n A : 'L_n.+2(A) = [~: 'L_n.+1(A), A]. Proof. by []. Qed.
Lemma lcnSnS n G : [~: 'L_n(G), G] \subset 'L_n.+1(G).
Proof. by case: n => //; apply: der1_subG. Qed.
Lemma lcnE n A : 'L_n.+1(A) = iter n (fun B => [~: B, A]) A.
Proof. by []. Qed.
Lemma lcn2 A : 'L_2(A) = A^`(1). Proof. by []. Qed.
Lemma lcn_group_set n G : group_set 'L_n(G).
Proof. by case: n => [|[|n]]; apply: groupP. Qed.
Canonical lower_central_at_group n G := Group (lcn_group_set n G).
Lemma lcn_char n G : 'L_n(G) \char G.
Proof. by case: n; last elim=> [|n IHn]; rewrite ?char_refl ?lcnSn ?charR. Qed.
Lemma lcn_normal n G : 'L_n(G) <| G.
Proof. exact/char_normal/lcn_char. Qed.
Lemma lcn_sub n G : 'L_n(G) \subset G.
Proof. exact/char_sub/lcn_char. Qed.
Lemma lcn_norm n G : G \subset 'N('L_n(G)).
Proof. exact/char_norm/lcn_char. Qed.
Lemma lcn_subS n G : 'L_n.+1(G) \subset 'L_n(G).
Proof.
case: n => // n; rewrite lcnSn commGC commg_subr.
by case/andP: (lcn_normal n.+1 G).
Qed.
Lemma lcn_normalS n G : 'L_n.+1(G) <| 'L_n(G).
Proof. by apply: normalS (lcn_normal _ _); rewrite (lcn_subS, lcn_sub). Qed.
Lemma lcn_central n G : 'L_n(G) / 'L_n.+1(G) \subset 'Z(G / 'L_n.+1(G)).
Proof.
case: n => [|n]; first by rewrite trivg_quotient sub1G.
by rewrite subsetI quotientS ?lcn_sub ?quotient_cents2r.
Qed.
Lemma lcn_sub_leq m n G : n <= m -> 'L_m(G) \subset 'L_n(G).
Proof.
by move/subnK <-; elim: {m}(m - n) => // m; apply: subset_trans (lcn_subS _ _).
Qed.
Lemma lcnS n A B : A \subset B -> 'L_n(A) \subset 'L_n(B).
Proof.
by case: n => // n sAB; elim: n => // n IHn; rewrite !lcnSn genS ?imset2S.
Qed.
Lemma lcn_cprod n A B G : A \* B = G -> 'L_n(A) \* 'L_n(B) = 'L_n(G).
Proof.
case: n => // n /cprodP[[H K -> ->{A B}] defG cHK].
have sL := subset_trans (lcn_sub _ _); rewrite cprodE ?(centSS _ _ cHK) ?sL //.
symmetry; elim: n => // n; rewrite lcnSn => ->; rewrite commMG /=; last first.
by apply: subset_trans (commg_normr _ _); rewrite sL // -defG mulG_subr.
rewrite -!(commGC G) -defG -{1}(centC cHK).
rewrite !commMG ?normsR ?lcn_norm ?cents_norm // 1?centsC //.
by rewrite -!(commGC 'L__(_)) -!lcnSn !(commG1P _) ?mul1g ?sL // centsC.
Qed.
Lemma lcn_dprod n A B G : A \x B = G -> 'L_n(A) \x 'L_n(B) = 'L_n(G).
Proof.
move=> defG; have [[K H defA defB] _ _ tiAB] := dprodP defG.
rewrite !dprodEcp // in defG *; first exact: lcn_cprod.
by rewrite defA defB; apply/trivgP; rewrite -tiAB defA defB setISS ?lcn_sub.
Qed.
Lemma der_cprod n A B G : A \* B = G -> A^`(n) \* B^`(n) = G^`(n).
Proof. by move=> defG; elim: n => {defG}// n; apply: (lcn_cprod 2). Qed.
Lemma der_dprod n A B G : A \x B = G -> A^`(n) \x B^`(n) = G^`(n).
Proof. by move=> defG; elim: n => {defG}// n; apply: (lcn_dprod 2). Qed.
Lemma lcn_bigcprod n I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) 'L_n(F i) = 'L_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first exact/esym/trivgP/lcn_sub.
by rewrite -(lcn_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H).
Qed.
Lemma lcn_bigdprod n I r P (F : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) 'L_n(F i) = 'L_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first exact/esym/trivgP/lcn_sub.
by rewrite -(lcn_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H).
Qed.
Lemma der_bigcprod n I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) (F i)^`(n) = G^`(n).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(der_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H).
Qed.
Lemma der_bigdprod n I r P (F : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) (F i)^`(n) = G^`(n).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(der_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H).
Qed.
Lemma nilpotent_class G : nilpotent G = (nil_class G < #|G|).
Proof.
rewrite /nil_class; set s := mkseq _ _.
transitivity (1 \in s); last by rewrite -index_mem size_mkseq.
apply/idP/mapP=> {s}/= [nilG | [n _ Ln1]]; last first.
apply/forall_inP=> H /subsetIP[sHG sHR].
rewrite -subG1 {}Ln1; elim: n => // n IHn.
by rewrite (subset_trans sHR) ?commSg.
pose m := #|G|.-1; exists m; first by rewrite mem_iota /= prednK.
set n := m; rewrite ['L__(G)]card_le1_trivg //= -(subnn m) -[m in _ - m]/n.
elim: n => [|n]; [by rewrite subn0 prednK | rewrite lcnSn subnS].
case: (eqsVneq 'L_n.+1(G) 1) => [-> | ntLn]; first by rewrite comm1G cards1.
case: (m - n) => [|m' /= IHn]; first by rewrite leqNgt cardG_gt1 ntLn.
rewrite -ltnS (leq_trans (proper_card _) IHn) //.
by rewrite (nil_comm_properl nilG) ?lcn_sub // subsetI subxx lcn_norm.
Qed.
Lemma lcn_nil_classP n G :
nilpotent G -> reflect ('L_n.+1(G) = 1) (nil_class G <= n).
Proof.
rewrite nilpotent_class /nil_class; set s := mkseq _ _.
set c := index 1 s => lt_c_G; case: leqP => [le_c_n | lt_n_c].
have Lc1: nth 1 s c = 1 by rewrite nth_index // -index_mem size_mkseq.
by left; apply/trivgP; rewrite -Lc1 nth_mkseq ?lcn_sub_leq.
right; apply/eqP/negPf; rewrite -(before_find 1 lt_n_c) nth_mkseq //.
exact: ltn_trans lt_n_c lt_c_G.
Qed.
Lemma lcnP G : reflect (exists n, 'L_n.+1(G) = 1) (nilpotent G).
Proof.
apply: (iffP idP) => [nilG | [n Ln1]].
by exists (nil_class G); apply/lcn_nil_classP.
apply/forall_inP=> H /subsetIP[sHG sHR]; rewrite -subG1 -{}Ln1.
by elim: n => // n IHn; rewrite (subset_trans sHR) ?commSg.
Qed.
Lemma abelian_nil G : abelian G -> nilpotent G.
Proof. by move=> abG; apply/lcnP; exists 1%N; apply/commG1P. Qed.
Lemma nil_class0 G : (nil_class G == 0) = (G :==: 1).
Proof.
apply/idP/eqP=> [nilG | ->].
by apply/(lcn_nil_classP 0); rewrite ?nilpotent_class (eqP nilG) ?cardG_gt0.
by rewrite -leqn0; apply/(lcn_nil_classP 0); rewrite ?nilpotent1.
Qed.
Lemma nil_class1 G : (nil_class G <= 1) = abelian G.
Proof.
have [-> | ntG] := eqsVneq G 1.
by rewrite abelian1 leq_eqVlt ltnS leqn0 nil_class0 eqxx orbT.
apply/idP/idP=> cGG.
apply/commG1P; apply/(lcn_nil_classP 1); rewrite // nilpotent_class.
by rewrite (leq_ltn_trans cGG) // cardG_gt1.
by apply/(lcn_nil_classP 1); rewrite ?abelian_nil //; apply/commG1P.
Qed.
Lemma cprod_nil A B G : A \* B = G -> nilpotent G = nilpotent A && nilpotent B.
Proof.
move=> defG; case/cprodP: defG (defG) => [[H K -> ->{A B}] defG _] defGc.
apply/idP/andP=> [nilG | [/lcnP[m LmH1] /lcnP[n LnK1]]].
by rewrite !(nilpotentS _ nilG) // -defG (mulG_subr, mulG_subl).
apply/lcnP; exists (m + n.+1); apply/trivgP.
case/cprodP: (lcn_cprod (m.+1 + n.+1) defGc) => _ <- _.
by rewrite mulG_subG /= -{1}LmH1 -LnK1 !lcn_sub_leq ?leq_addl ?leq_addr.
Qed.
Lemma mulg_nil G H :
H \subset 'C(G) -> nilpotent (G * H) = nilpotent G && nilpotent H.
Proof. by move=> cGH; rewrite -(cprod_nil (cprodEY cGH)) /= cent_joinEr. Qed.
Lemma dprod_nil A B G : A \x B = G -> nilpotent G = nilpotent A && nilpotent B.
Proof. by case/dprodP=> [[H K -> ->] <- cHK _]; rewrite mulg_nil.
Qed.
Lemma bigdprod_nil I r (P : pred I) (A_ : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) A_ i = G
-> (forall i, P i -> nilpotent (A_ i)) -> nilpotent G.
Proof.
move=> defG nilA; elim/big_rec: _ => [|i B Pi nilB] in G defG *.
by rewrite -defG nilpotent1.
have [[_ H _ defB] _ _ _] := dprodP defG.
by rewrite (dprod_nil defG) nilA //= defB nilB.
Qed.
End LowerCentral.
Notation "''L_' n ( G )" := (lower_central_at_group n G) : Group_scope.
Lemma lcn_cont n : GFunctor.continuous (@lower_central_at n).
Proof.
case: n => //; elim=> // n IHn g0T h0T H phi.
by rewrite !lcnSn morphimR ?lcn_sub // commSg ?IHn.
Qed.
Canonical lcn_igFun n := [igFun by lcn_sub^~ n & lcn_cont n].
Canonical lcn_gFun n := [gFun by lcn_cont n].
Canonical lcn_mgFun n := [mgFun by fun _ G H => @lcnS _ n G H].
Section UpperCentralFunctor.
Variable n : nat.
Implicit Type gT : finGroupType.
Lemma ucn_pmap : exists hZ : GFunctor.pmap, @upper_central_at n = hZ.
Proof.
elim: n => [|n' [hZ defZ]]; first by exists trivGfun_pgFun.
by exists [pgFun of @center %% hZ]; rewrite /= -defZ.
Qed.
(* Now extract all the intermediate facts of the last proof. *)
Lemma ucn_group_set gT (G : {group gT}) : group_set 'Z_n(G).
Proof. by have [hZ ->] := ucn_pmap; apply: groupP. Qed.
Canonical upper_central_at_group gT G := Group (@ucn_group_set gT G).
Lemma ucn_sub gT (G : {group gT}) : 'Z_n(G) \subset G.
Proof. by have [hZ ->] := ucn_pmap; apply: gFsub. Qed.
Lemma morphim_ucn : GFunctor.pcontinuous (@upper_central_at n).
Proof. by have [hZ ->] := ucn_pmap; apply: pmorphimF. Qed.
Canonical ucn_igFun := [igFun by ucn_sub & morphim_ucn].
Canonical ucn_gFun := [gFun by morphim_ucn].
Canonical ucn_pgFun := [pgFun by morphim_ucn].
Variable (gT : finGroupType) (G : {group gT}).
Lemma ucn_char : 'Z_n(G) \char G. Proof. exact: gFchar. Qed.
Lemma ucn_norm : G \subset 'N('Z_n(G)). Proof. exact: gFnorm. Qed.
Lemma ucn_normal : 'Z_n(G) <| G. Proof. exact: gFnormal. Qed.
End UpperCentralFunctor.
Notation "''Z_' n ( G )" := (upper_central_at_group n G) : Group_scope.
Section UpperCentral.
Variable gT : finGroupType.
Implicit Types (A B : {set gT}) (G H : {group gT}).
Lemma ucn0 A : 'Z_0(A) = 1.
Proof. by []. Qed.
Lemma ucnSn n A : 'Z_n.+1(A) = coset 'Z_n(A) @*^-1 'Z(A / 'Z_n(A)).
Proof. by []. Qed.
Lemma ucnE n A : 'Z_n(A) = iter n (fun B => coset B @*^-1 'Z(A / B)) 1.
Proof. by []. Qed.
Lemma ucn_subS n G : 'Z_n(G) \subset 'Z_n.+1(G).
Proof. by rewrite -{1}['Z_n(G)]ker_coset morphpreS ?sub1G. Qed.
Lemma ucn_sub_geq m n G : n >= m -> 'Z_m(G) \subset 'Z_n(G).
Proof.
move/subnK <-; elim: {n}(n - m) => // n IHn.
exact: subset_trans (ucn_subS _ _).
Qed.
Lemma ucn_central n G : 'Z_n.+1(G) / 'Z_n(G) = 'Z(G / 'Z_n(G)).
Proof. by rewrite ucnSn cosetpreK. Qed.
Lemma ucn_normalS n G : 'Z_n(G) <| 'Z_n.+1(G).
Proof. by rewrite (normalS _ _ (ucn_normal n G)) ?ucn_subS ?ucn_sub. Qed.
Lemma ucn_comm n G : [~: 'Z_n.+1(G), G] \subset 'Z_n(G).
Proof.
rewrite -quotient_cents2 ?normal_norm ?ucn_normal ?ucn_normalS //.
by rewrite ucn_central subsetIr.
Qed.
Lemma ucn1 G : 'Z_1(G) = 'Z(G).
Proof.
apply: (quotient_inj (normal1 _) (normal1 _)).
by rewrite /= (ucn_central 0) -injmF ?norms1 ?coset1_injm.
Qed.
Lemma ucnSnR n G : 'Z_n.+1(G) = [set x in G | [~: [set x], G] \subset 'Z_n(G)].
Proof.
(* apply/setP=> x; rewrite inE -(setIidPr (ucn_sub n.+1 G)) inE ucnSn. *)
(* FIXME: before, we got a `rewrite inE` right after the apply/setP=> x. *
* However, this rewrite unfolds termes to strange internal HB names. *
* We fixed the issue by applying the inE more carefully, but the problem *
* needs to be investigated. *)
apply/setP=> x; rewrite -(setIidPr (ucn_sub n.+1 G)) [LHS]inE [RHS]inE ucnSn.
case Gx: (x \in G) => //=; have nZG := ucn_norm n G.
rewrite -sub1set -sub_quotient_pre -?quotient_cents2 ?sub1set ?(subsetP nZG) //.
by rewrite subsetI quotientS ?sub1set.
Qed.
Lemma ucn_cprod n A B G : A \* B = G -> 'Z_n(A) \* 'Z_n(B) = 'Z_n(G).
Proof.
case/cprodP=> [[H K -> ->{A B}] mulHK cHK].
elim: n => [|n /cprodP[_ /= defZ cZn]]; first exact: cprod1g.
set Z := 'Z_n(G) in defZ cZn; rewrite (ucnSn n G) /= -/Z.
have /mulGsubP[nZH nZK]: H * K \subset 'N(Z) by rewrite mulHK gFnorm.
have <-: 'Z(H / Z) * 'Z(K / Z) = 'Z(G / Z).
by rewrite -mulHK quotientMl // center_prod ?quotient_cents.
have ZquoZ (B A : {group gT}):
B \subset 'C(A) -> 'Z_n(A) * 'Z_n(B) = Z -> 'Z(A / Z) = 'Z_n.+1(A) / Z.
- move=> cAB {}defZ; have cAZnB: 'Z_n(B) \subset 'C(A) := gFsub_trans _ cAB.
have /second_isom[/=]: A \subset 'N(Z).
by rewrite -defZ normsM ?gFnorm ?cents_norm // centsC.
suffices ->: Z :&: A = 'Z_n(A).
by move=> f inj_f im_f; rewrite -!im_f ?gFsub // ucn_central injm_center.
rewrite -defZ -group_modl ?gFsub //; apply/mulGidPl.
have [-> | n_gt0] := posnP n; first exact: subsetIl.
by apply: subset_trans (ucn_sub_geq A n_gt0); rewrite /= setIC ucn1 setIS.
rewrite (ZquoZ H K) 1?centsC 1?(centC cZn) // {ZquoZ}(ZquoZ K H) //.
have cZn1: 'Z_n.+1(K) \subset 'C('Z_n.+1(H)) by apply: centSS cHK; apply: gFsub.
rewrite -quotientMl ?quotientK ?mul_subG ?gFsub_trans //=.
rewrite cprodE // -cent_joinEr ?mulSGid //= cent_joinEr //= -/Z.
by rewrite -defZ mulgSS ?ucn_subS.
Qed.
Lemma ucn_dprod n A B G : A \x B = G -> 'Z_n(A) \x 'Z_n(B) = 'Z_n(G).
Proof.
move=> defG; have [[K H defA defB] _ _ tiAB] := dprodP defG.
rewrite !dprodEcp // in defG *; first exact: ucn_cprod.
by rewrite defA defB; apply/trivgP; rewrite -tiAB defA defB setISS ?ucn_sub.
Qed.
Lemma ucn_bigcprod n I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) 'Z_n(F i) = 'Z_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(ucn_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H).
Qed.
Lemma ucn_bigdprod n I r P (F : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) 'Z_n(F i) = 'Z_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(ucn_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H).
Qed.
Lemma ucn_lcnP n G : ('L_n.+1(G) == 1) = ('Z_n(G) == G).
Proof.
rewrite !eqEsubset sub1G ucn_sub /= andbT -(ucn0 G); set i := (n in LHS).
have: i + 0 = n by [rewrite addn0]; elim: i 0 => [j <- //|i IHi j].
rewrite addSnnS => /IHi <- {IHi}; rewrite ucnSn lcnSn.
rewrite -sub_morphim_pre ?gFsub_trans ?gFnorm_trans // subsetI.
by rewrite morphimS ?gFsub // quotient_cents2 ?gFsub_trans ?gFnorm_trans.
Qed.
Lemma ucnP G : reflect (exists n, 'Z_n(G) = G) (nilpotent G).
Proof.
apply: (iffP (lcnP G)) => -[n /eqP-clGn];
by exists n; apply/eqP; rewrite ucn_lcnP in clGn *.
Qed.
Lemma ucn_nil_classP n G :
nilpotent G -> reflect ('Z_n(G) = G) (nil_class G <= n).
Proof.
move=> nilG; rewrite (sameP (lcn_nil_classP n nilG) eqP) ucn_lcnP; apply: eqP.
Qed.
Lemma ucn_id n G : 'Z_n('Z_n(G)) = 'Z_n(G).
Proof. exact: gFid. Qed.
Lemma ucn_nilpotent n G : nilpotent 'Z_n(G).
Proof. by apply/ucnP; exists n; rewrite ucn_id. Qed.
Lemma nil_class_ucn n G : nil_class 'Z_n(G) <= n.
Proof. by apply/ucn_nil_classP; rewrite ?ucn_nilpotent // ucn_id. Qed.
End UpperCentral.
Section MorphNil.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Implicit Type G : {group aT}.
Lemma morphim_lcn n G : G \subset D -> f @* 'L_n(G) = 'L_n(f @* G).
Proof.
move=> sHG; case: n => //; elim=> // n IHn.
by rewrite !lcnSn -IHn morphimR // (subset_trans _ sHG) // lcn_sub.
Qed.
Lemma injm_ucn n G : 'injm f -> G \subset D -> f @* 'Z_n(G) = 'Z_n(f @* G).
Proof. exact: injmF. Qed.
Lemma morphim_nil G : nilpotent G -> nilpotent (f @* G).
Proof.
case/ucnP=> n ZnG; apply/ucnP; exists n; apply/eqP.
by rewrite eqEsubset ucn_sub /= -{1}ZnG morphim_ucn.
Qed.
Lemma injm_nil G : 'injm f -> G \subset D -> nilpotent (f @* G) = nilpotent G.
Proof.
move=> injf sGD; apply/idP/idP; last exact: morphim_nil.
case/ucnP=> n; rewrite -injm_ucn // => /injm_morphim_inj defZ.
by apply/ucnP; exists n; rewrite defZ ?gFsub_trans.
Qed.
Lemma nil_class_morphim G : nilpotent G -> nil_class (f @* G) <= nil_class G.
Proof.
move=> nilG; rewrite (sameP (ucn_nil_classP _ (morphim_nil nilG)) eqP) /=.
by rewrite eqEsubset ucn_sub -{1}(ucn_nil_classP _ nilG (leqnn _)) morphim_ucn.
Qed.
Lemma nil_class_injm G :
'injm f -> G \subset D -> nil_class (f @* G) = nil_class G.
Proof.
move=> injf sGD; case nilG: (nilpotent G).
apply/eqP; rewrite eqn_leq nil_class_morphim //.
rewrite (sameP (lcn_nil_classP _ nilG) eqP) -subG1.
rewrite -(injmSK injf) ?gFsub_trans // morphim1.
by rewrite morphim_lcn // (lcn_nil_classP _ _ (leqnn _)) //= injm_nil.
transitivity #|G|; apply/eqP; rewrite eqn_leq.
rewrite -(card_injm injf sGD) (leq_trans (index_size _ _)) ?size_mkseq //.
by rewrite leqNgt -nilpotent_class injm_nil ?nilG.
rewrite (leq_trans (index_size _ _)) ?size_mkseq // leqNgt -nilpotent_class.
by rewrite nilG.
Qed.
End MorphNil.
Section QuotientNil.
Variables gT : finGroupType.
Implicit Types (rT : finGroupType) (G H : {group gT}).
Lemma quotient_ucn_add m n G : 'Z_(m + n)(G) / 'Z_n(G) = 'Z_m(G / 'Z_n(G)).
Proof.
elim: m => [|m IHm]; first exact: trivg_quotient.
apply/setP=> Zx; have [x Nx ->{Zx}] := cosetP Zx.
have [sZG nZG] := andP (ucn_normal n G).
rewrite (ucnSnR m) inE -!sub1set -morphim_set1 //= -quotientR ?sub1set // -IHm.
rewrite !quotientSGK ?(ucn_sub_geq, leq_addl, comm_subG _ nZG, sub1set) //=.
by rewrite addSn /= ucnSnR inE.
Qed.
Lemma isog_nil rT G (L : {group rT}) : G \isog L -> nilpotent G = nilpotent L.
Proof. by case/isogP=> f injf <-; rewrite injm_nil. Qed.
Lemma isog_nil_class rT G (L : {group rT}) :
G \isog L -> nil_class G = nil_class L.
Proof. by case/isogP=> f injf <-; rewrite nil_class_injm. Qed.
Lemma quotient_nil G H : nilpotent G -> nilpotent (G / H).
Proof. exact: morphim_nil. Qed.
Lemma quotient_center_nil G : nilpotent (G / 'Z(G)) = nilpotent G.
Proof.
rewrite -ucn1; apply/idP/idP; last exact: quotient_nil.
case/ucnP=> c nilGq; apply/ucnP; exists c.+1; have nsZ1G := ucn_normal 1 G.
apply: (quotient_inj _ nsZ1G); last by rewrite /= -(addn1 c) quotient_ucn_add.
by rewrite (normalS _ _ nsZ1G) ?ucn_sub ?ucn_sub_geq.
Qed.
Lemma nil_class_quotient_center G :
nilpotent (G) -> nil_class (G / 'Z(G)) = (nil_class G).-1.
Proof.
move=> nilG; have nsZ1G := ucn_normal 1 G.
apply/eqP; rewrite -ucn1 eqn_leq; apply/andP; split.
apply/ucn_nil_classP; rewrite ?quotient_nil //= -quotient_ucn_add ucn1.
by rewrite (ucn_nil_classP _ _ _) ?addn1 ?leqSpred.
rewrite -subn1 leq_subLR addnC; apply/ucn_nil_classP => //=.
apply: (quotient_inj _ nsZ1G) => /=.
by apply: normalS (ucn_sub _ _) nsZ1G; rewrite /= addnS ucn_sub_geq.
by rewrite quotient_ucn_add; apply/ucn_nil_classP; rewrite //= quotient_nil.
Qed.
Lemma nilpotent_sub_norm G H :
nilpotent G -> H \subset G -> 'N_G(H) \subset H -> G :=: H.
Proof.
move=> nilG sHG sNH; apply/eqP; rewrite eqEsubset sHG andbT; apply/negP=> nsGH.
have{nsGH} [i sZH []]: exists2 i, 'Z_i(G) \subset H & ~ 'Z_i.+1(G) \subset H.
case/ucnP: nilG => n ZnG; rewrite -{}ZnG in nsGH.
elim: n => [|i IHi] in nsGH *; first by rewrite sub1G in nsGH.
by case sZH: ('Z_i(G) \subset H); [exists i | apply: IHi; rewrite sZH].
apply: subset_trans sNH; rewrite subsetI ucn_sub -commg_subr.
by apply: subset_trans sZH; apply: subset_trans (ucn_comm i G); apply: commgS.
Qed.
Lemma nilpotent_proper_norm G H :
nilpotent G -> H \proper G -> H \proper 'N_G(H).
Proof.
move=> nilG; rewrite properEneq properE subsetI normG => /andP[neHG sHG].
by rewrite sHG; apply: contra neHG => /(nilpotent_sub_norm nilG)->.
Qed.
Lemma nilpotent_subnormal G H : nilpotent G -> H \subset G -> H <|<| G.
Proof.
move=> nilG; have [m] := ubnP (#|G| - #|H|).
elim: m H => // m IHm H /ltnSE-leGHm sHG.
have [->|] := eqVproper sHG; first exact: subnormal_refl.
move/(nilpotent_proper_norm nilG); set K := 'N_G(H) => prHK.
have snHK: H <|<| K by rewrite normal_subnormal ?normalSG.
have sKG: K \subset G by rewrite subsetIl.
apply: subnormal_trans snHK (IHm _ (leq_trans _ leGHm) sKG).
by rewrite ltn_sub2l ?proper_card ?(proper_sub_trans prHK).
Qed.
Lemma TI_center_nil G H : nilpotent G -> H <| G -> H :&: 'Z(G) = 1 -> H :=: 1.
Proof.
move=> nilG /andP[sHG nHG] tiHZ.
rewrite -{1}(setIidPl sHG); have{nilG} /ucnP[n <-] := nilG.
elim: n => [|n IHn]; apply/trivgP; rewrite ?subsetIr // -tiHZ.
rewrite [H :&: 'Z(G)]setIA subsetI setIS ?ucn_sub //= (sameP commG1P trivgP).
rewrite -commg_subr commGC in nHG.
rewrite -IHn subsetI (subset_trans _ nHG) ?commSg ?subsetIl //=.
by rewrite (subset_trans _ (ucn_comm n G)) ?commSg ?subsetIr.
Qed.
Lemma meet_center_nil G H :
nilpotent G -> H <| G -> H :!=: 1 -> H :&: 'Z(G) != 1.
Proof. by move=> nilG nsHG; apply: contraNneq => /TI_center_nil->. Qed.
Lemma center_nil_eq1 G : nilpotent G -> ('Z(G) == 1) = (G :==: 1).
Proof.
move=> nilG; apply/eqP/eqP=> [Z1 | ->]; last exact: center1.
by rewrite (TI_center_nil nilG) // (setIidPr (center_sub G)).
Qed.
Lemma cyclic_nilpotent_quo_der1_cyclic G :
nilpotent G -> cyclic (G / G^`(1)) -> cyclic G.
Proof.
move=> nG; rewrite (isog_cyclic (quotient1_isog G)).
have [-> // | ntG' cGG'] := (eqVneq G^`(1) 1)%g.
suffices: 'L_2(G) \subset G :&: 'L_3(G) by move/(eqfun_inP nG)=> <-.
rewrite subsetI lcn_sub /= -quotient_cents2 ?lcn_norm //.
apply: cyclic_factor_abelian (lcn_central 2 G) _.
by rewrite (isog_cyclic (third_isog _ _ _)) ?lcn_normal // lcn_subS.
Qed.
End QuotientNil.
Section Solvable.
Variable gT : finGroupType.
Implicit Types G H : {group gT}.
Lemma nilpotent_sol G : nilpotent G -> solvable G.
Proof.
move=> nilG; apply/forall_inP=> H /subsetIP[sHG sHH'].
by rewrite (forall_inP nilG) // subsetI sHG (subset_trans sHH') ?commgS.
Qed.
Lemma abelian_sol G : abelian G -> solvable G.
Proof. by move/abelian_nil/nilpotent_sol. Qed.
Lemma solvable1 : solvable [1 gT]. Proof. exact: abelian_sol (abelian1 gT). Qed.
Lemma solvableS G H : H \subset G -> solvable G -> solvable H.
Proof.
move=> sHG solG; apply/forall_inP=> K /subsetIP[sKH sKK'].
by rewrite (forall_inP solG) // subsetI (subset_trans sKH).
Qed.
Lemma sol_der1_proper G H :
solvable G -> H \subset G -> H :!=: 1 -> H^`(1) \proper H.
Proof.
move=> solG sHG ntH; rewrite properE comm_subG //; apply: implyP ntH.
by have:= forallP solG H; rewrite subsetI sHG implybNN.
Qed.
Lemma derivedP G : reflect (exists n, G^`(n) = 1) (solvable G).
Proof.
apply: (iffP idP) => [solG | [n solGn]]; last first.
apply/forall_inP=> H /subsetIP[sHG sHH'].
rewrite -subG1 -{}solGn; elim: n => // n IHn.
exact: subset_trans sHH' (commgSS _ _).
suffices IHn n: #|G^`(n)| <= (#|G|.-1 - n).+1.
by exists #|G|.-1; rewrite [G^`(_)]card_le1_trivg ?(leq_trans (IHn _)) ?subnn.
elim: n => [|n IHn]; first by rewrite subn0 prednK.
rewrite dergSn subnS -ltnS.
have [-> | ntGn] := eqVneq G^`(n) 1; first by rewrite commG1 cards1.
case: (_ - _) IHn => [|n']; first by rewrite leqNgt cardG_gt1 ntGn.
by apply: leq_trans (proper_card _); apply: sol_der1_proper (der_sub _ _) _.
Qed.
End Solvable.
Section MorphSol.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Variable G : {group gT}.
Lemma morphim_sol : solvable G -> solvable (f @* G).
Proof.
move/(solvableS (subsetIr D G)); case/derivedP=> n Gn1; apply/derivedP.
by exists n; rewrite /= -morphimIdom -morphim_der ?subsetIl // Gn1 morphim1.
Qed.
Lemma injm_sol : 'injm f -> G \subset D -> solvable (f @* G) = solvable G.
Proof.
move=> injf sGD; apply/idP/idP; last exact: morphim_sol.
case/derivedP=> n Gn1; apply/derivedP; exists n; apply/trivgP.
by rewrite -(injmSK injf) ?gFsub_trans ?morphim_der // Gn1 morphim1.
Qed.
End MorphSol.
Section QuotientSol.
Variables gT rT : finGroupType.
Implicit Types G H K : {group gT}.
Lemma isog_sol G (L : {group rT}) : G \isog L -> solvable G = solvable L.
Proof. by case/isogP=> f injf <-; rewrite injm_sol. Qed.
Lemma quotient_sol G H : solvable G -> solvable (G / H).
Proof. exact: morphim_sol. Qed.
Lemma series_sol G H : H <| G -> solvable G = solvable H && solvable (G / H).
Proof.
case/andP=> sHG nHG; apply/idP/andP=> [solG | [solH solGH]].
by rewrite quotient_sol // (solvableS sHG).
apply/forall_inP=> K /subsetIP[sKG sK'K].
suffices sKH: K \subset H by rewrite (forall_inP solH) // subsetI sKH.
have nHK := subset_trans sKG nHG.
rewrite -quotient_sub1 // subG1 (forall_inP solGH) //.
by rewrite subsetI -morphimR ?morphimS.
Qed.
Lemma metacyclic_sol G : metacyclic G -> solvable G.
Proof.
case/metacyclicP=> K [cycK nsKG cycGq].
by rewrite (series_sol nsKG) !abelian_sol ?cyclic_abelian.
Qed.
End QuotientSol.
Section setXn.
Import finfun.
Lemma setXn_sol n (gT : 'I_n -> finGroupType) (G : forall i, {group gT i}) :
(forall i, solvable (G i)) -> solvable (setXn G).
Proof.
elim: n => [|n IHn] in gT G * => solG; first by rewrite groupX0 solvable1.
pose gT' (i : 'I_n) := gT (lift ord0 i).
pose prod_group_gT := [the finGroupType of {dffun forall i, gT i}].
pose prod_group_gT' := [the finGroupType of {dffun forall i, gT' i}].
pose f (x : prod_group_gT) : prod_group_gT' := [ffun i => x (lift ord0 i)].
have fm : morphic (setXn G) f.
apply/'forall_implyP => -[a b]; rewrite !inE/=.
by move=> /andP[/forallP aG /forallP bG]; apply/eqP/ffunP => i; rewrite !ffunE.
rewrite (@series_sol _ [group of setXn G] ('ker (morphm fm))) ?ker_normal//=.
rewrite (isog_sol (first_isog _))/=.
have -> : (morphm fm @* setXn G)%g = setXn (fun i => G (lift ord0 i)).
apply/setP => v; rewrite !inE morphimEdom; apply/idP/forallP => /=.
move=> /imsetP[/=x]; rewrite inE => /forallP/= xG ->.
by move=> i; rewrite morphmE ffunE xG.
move=> vG; apply/imsetP.
pose w := [ffun i : 'I_n.+1 =>
match unliftP ord0 i return (gT i) : Type with
| UnliftSome j i_eq => ecast i (gT i) (esym i_eq) (v j)
| UnliftNone i0 => 1%g
end].
have wl i : w (lift ord0 i) = v i.
rewrite ffunE; case: unliftP => //= j elij.
have eij : i = j by case: elij; apply/val_inj.
by rewrite [elij](eq_irrelevance _ (congr1 _ eij)); case: _ / eij.
have w0 : w ord0 = 1%g by rewrite ffunE; case: unliftP.
exists w; last by apply/ffunP => i; rewrite morphmE ffunE/= wl.
apply/setXnP => i.
case: (unliftP ord0 i) => [j|]->; rewrite ?wl ?w0 ?vG//.
rewrite IHn ?andbT//; last by move=> i; apply: solG.
pose k (x : gT ord0) : prod_group_gT :=
[ffun i : 'I_n.+1 =>
match (ord0 =P i) return (gT i) : Type with
| ReflectT P => ecast i (gT i) P x
| _ => 1%g
end].
have km : morphic (G ord0) k.
apply/'forall_implyP => -[a b]; rewrite !inE/= => /andP[aG bG].
apply/eqP/ffunP => i; rewrite !ffunE; case: eqP => //; rewrite ?mulg1//.
by case: _ /.
suff -> : ('ker (morphm fm) = morphm km @* G ord0)%g by rewrite morphim_sol.
apply/setP => x; rewrite morphimEdom; apply/idP/imsetP => [xker|].
exists (x ord0).
by have := dom_ker xker; rewrite inE => /forallP/(_ ord0).
rewrite /= morphmE; apply/ffunP => i; rewrite ffunE; case: eqP => //=.
by case: _ /.
move/eqP; rewrite eq_sym; have /mker/= := xker; rewrite morphmE => /ffunP.
by case: (@unliftP _ ord0 i) => [j|] ->//= /(_ j); rewrite !ffunE.
move=> [x0 xG0 -> /=]; rewrite morphmE; apply/kerP; rewrite ?inE.
by apply/forallP => i; rewrite ffunE; case: eqP => //=; case: _ /.
by rewrite /= morphmE; apply/ffunP => i; rewrite !ffunE; case: eqP.
Qed.
End setXn.
|
Set.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Set.Notation
import Mathlib.Order.SetNotation
import Mathlib.Logic.Embedding.Basic
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.Image
/-!
# Interactions between embeddings and sets.
-/
assert_not_exists WithTop
universe u v w x
open Set Set.Notation
section Equiv
variable {α : Sort u} {β : Sort v} (f : α ≃ β)
@[simp]
theorem Equiv.asEmbedding_range {α β : Sort _} {p : β → Prop} (e : α ≃ Subtype p) :
Set.range e.asEmbedding = setOf p :=
Set.ext fun x ↦ ⟨fun ⟨y, h⟩ ↦ h ▸ Subtype.coe_prop (e y), fun hs ↦ ⟨e.symm ⟨x, hs⟩, by simp⟩⟩
end Equiv
namespace Function
namespace Embedding
/-- Given an embedding `f : α ↪ β` and a point outside of `Set.range f`, construct an embedding
`Option α ↪ β`. -/
@[simps]
def optionElim {α β} (f : α ↪ β) (x : β) (h : x ∉ Set.range f) : Option α ↪ β :=
⟨Option.elim' x f, Option.injective_iff.2 ⟨f.2, h⟩⟩
/-- Equivalence between embeddings of `Option α` and a sigma type over the embeddings of `α`. -/
@[simps]
def optionEmbeddingEquiv (α β) : (Option α ↪ β) ≃ Σ f : α ↪ β, ↥(Set.range f)ᶜ where
toFun f := ⟨Embedding.some.trans f, f none, fun ⟨x, hx⟩ ↦ Option.some_ne_none x <| f.injective hx⟩
invFun f := f.1.optionElim f.2 f.2.2
left_inv f := ext <| by rintro (_ | _) <;> simp
right_inv := fun ⟨f, y, hy⟩ ↦ by ext <;> simp
/-- Restrict the codomain of an embedding. -/
def codRestrict {α β} (p : Set β) (f : α ↪ β) (H : ∀ a, f a ∈ p) : α ↪ p :=
⟨fun a ↦ ⟨f a, H a⟩, fun _ _ h ↦ f.injective (congr_arg Subtype.val h)⟩
@[simp]
theorem codRestrict_apply {α β} (p) (f : α ↪ β) (H a) : codRestrict p f H a = ⟨f a, H a⟩ :=
rfl
/-- `Set.image` as an embedding `Set α ↪ Set β`. -/
@[simps apply]
protected def image {α β} (f : α ↪ β) : Set α ↪ Set β :=
⟨image f, f.2.image_injective⟩
end Embedding
end Function
namespace Set
/-- The injection map is an embedding between subsets. -/
@[simps apply_coe]
def embeddingOfSubset {α} (s t : Set α) (h : s ⊆ t) : s ↪ t :=
⟨fun x ↦ ⟨x.1, h x.2⟩, fun ⟨x, hx⟩ ⟨y, hy⟩ h ↦ by
congr
injection h⟩
end Set
section Subtype
variable {α : Type*}
/-- A subtype `{x // p x ∨ q x}` over a disjunction of `p q : α → Prop` is equivalent to a sum of
subtypes `{x // p x} ⊕ {x // q x}` such that `¬ p x` is sent to the right, when
`Disjoint p q`.
See also `Equiv.sumCompl`, for when `IsCompl p q`. -/
@[simps apply]
def subtypeOrEquiv (p q : α → Prop) [DecidablePred p] (h : Disjoint p q) :
{ x // p x ∨ q x } ≃ { x // p x } ⊕ { x // q x } where
toFun := subtypeOrLeftEmbedding p q
invFun :=
Sum.elim (Subtype.impEmbedding _ _ fun x hx ↦ (Or.inl hx : p x ∨ q x))
(Subtype.impEmbedding _ _ fun x hx ↦ (Or.inr hx : p x ∨ q x))
left_inv x := by
by_cases hx : p x
· rw [subtypeOrLeftEmbedding_apply_left _ hx]
simp [Subtype.ext_iff]
· rw [subtypeOrLeftEmbedding_apply_right _ hx]
simp [Subtype.ext_iff]
right_inv x := by
cases x with
| inl x =>
simp only [Sum.elim_inl]
rw [subtypeOrLeftEmbedding_apply_left]
· simp
· simpa using x.prop
| inr x =>
simp only [Sum.elim_inr]
rw [subtypeOrLeftEmbedding_apply_right]
· simp
· suffices ¬p x by simpa
intro hp
simpa using h.le_bot x ⟨hp, x.prop⟩
@[simp]
theorem subtypeOrEquiv_symm_inl (p q : α → Prop) [DecidablePred p] (h : Disjoint p q)
(x : { x // p x }) : (subtypeOrEquiv p q h).symm (Sum.inl x) = ⟨x, Or.inl x.prop⟩ :=
rfl
@[simp]
theorem subtypeOrEquiv_symm_inr (p q : α → Prop) [DecidablePred p] (h : Disjoint p q)
(x : { x // q x }) : (subtypeOrEquiv p q h).symm (Sum.inr x) = ⟨x, Or.inr x.prop⟩ :=
rfl
end Subtype
section Disjoint
variable {α ι : Type*} {s t r : Set α}
/-- For disjoint `s t : Set α`, the natural injection from `↑s ⊕ ↑t` to `α`. -/
@[simps] def Function.Embedding.sumSet (h : Disjoint s t) : s ⊕ t ↪ α where
toFun := Sum.elim (↑) (↑)
inj' := by
rintro (⟨a, ha⟩ | ⟨a, ha⟩) (⟨b, hb⟩ | ⟨b, hb⟩)
· simp
· simpa using h.ne_of_mem ha hb
· simpa using h.symm.ne_of_mem ha hb
simp
@[norm_cast] lemma Function.Embedding.coe_sumSet (h : Disjoint s t) :
(Function.Embedding.sumSet h : s ⊕ t → α) = Sum.elim (↑) (↑) := rfl
@[simp] theorem Function.Embedding.sumSet_preimage_inl (h : Disjoint s t) :
.inl ⁻¹' (Function.Embedding.sumSet h ⁻¹' r) = r ∩ s := by
simp [Set.ext_iff]
@[simp] theorem Function.Embedding.sumSet_preimage_inr (h : Disjoint s t) :
.inr ⁻¹' (Function.Embedding.sumSet h ⁻¹' r) = r ∩ t := by
simp [Set.ext_iff]
@[simp] theorem Function.Embedding.sumSet_range {s t : Set α} (h : Disjoint s t) :
range (Function.Embedding.sumSet h) = s ∪ t := by
simp [Set.ext_iff]
open scoped Function -- required for scoped `on` notation
/-- For an indexed family `s : ι → Set α` of disjoint sets,
the natural injection from the sigma-type `(i : ι) × ↑(s i)` to `α`. -/
@[simps] def Function.Embedding.sigmaSet {s : ι → Set α} (h : Pairwise (Disjoint on s)) :
(i : ι) × s i ↪ α where
toFun x := x.2.1
inj' := by
rintro ⟨i, x, hx⟩ ⟨j, -, hx'⟩ rfl
obtain rfl : i = j := h.eq (not_disjoint_iff.2 ⟨_, hx, hx'⟩)
rfl
@[norm_cast] lemma Function.Embedding.coe_sigmaSet {s : ι → Set α} (h) :
(Function.Embedding.sigmaSet h : ((i : ι) × s i) → α) = fun x ↦ x.2.1 := rfl
@[simp] theorem Function.Embedding.sigmaSet_preimage {s : ι → Set α}
(h : Pairwise (Disjoint on s)) (i : ι) (r : Set α) :
Sigma.mk i ⁻¹' (Function.Embedding.sigmaSet h ⁻¹' r) = r ∩ s i := by
simp [Set.ext_iff]
@[simp] theorem Function.Embedding.sigmaSet_range {s : ι → Set α}
(h : Pairwise (Disjoint on s)) : Set.range (Function.Embedding.sigmaSet h) = ⋃ i, s i := by
simp [Set.ext_iff]
end Disjoint
|
VerticalComposition.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.CatCommSq
import Mathlib.CategoryTheory.GuitartExact.Basic
/-!
# Vertical composition of Guitart exact squares
In this file, we show that the vertical composition of Guitart exact squares
is Guitart exact.
-/
namespace CategoryTheory
open Category
variable {C₁ C₂ C₃ D₁ D₂ D₃ : Type*} [Category C₁] [Category C₂] [Category C₃]
[Category D₁] [Category D₂] [Category D₃]
namespace TwoSquare
section WhiskerVertical
variable {T : C₁ ⥤ D₁} {L : C₁ ⥤ C₂} {R : D₁ ⥤ D₂} {B : C₂ ⥤ D₂} (w : TwoSquare T L R B)
{L' : C₁ ⥤ C₂} {R' : D₁ ⥤ D₂}
/-- Given `w : TwoSquare T L R B`, one may obtain a 2-square `TwoSquare T L' R' B` if we
provide natural transformations `α : L ⟶ L'` and `β : R' ⟶ R`. -/
@[simps!]
def whiskerVertical (α : L ⟶ L') (β : R' ⟶ R) :
TwoSquare T L' R' B :=
(w.whiskerLeft α).whiskerRight β
namespace GuitartExact
/-- A 2-square stays Guitart exact if we replace the left and right functors
by isomorphic functors. See also `whiskerVertical_iff`. -/
lemma whiskerVertical [w.GuitartExact] (α : L ≅ L') (β : R ≅ R') :
(w.whiskerVertical α.hom β.inv).GuitartExact := by
rw [guitartExact_iff_initial]
intro X₂
let e : structuredArrowDownwards (w.whiskerVertical α.hom β.inv) X₂ ≅
w.structuredArrowDownwards X₂ ⋙ (StructuredArrow.mapIso (β.app X₂) ).functor :=
NatIso.ofComponents (fun f => StructuredArrow.isoMk (α.symm.app f.right) (by
dsimp
simp only [NatTrans.naturality_assoc, assoc, ← B.map_comp,
Iso.hom_inv_id_app, B.map_id, comp_id]))
rw [Functor.initial_natIso_iff e]
infer_instance
/-- A 2-square is Guitart exact iff it is so after replacing the left and right functors by
isomorphic functors. -/
@[simp]
lemma whiskerVertical_iff (α : L ≅ L') (β : R ≅ R') :
(w.whiskerVertical α.hom β.inv).GuitartExact ↔ w.GuitartExact := by
constructor
· intro h
have : w = (w.whiskerVertical α.hom β.inv).whiskerVertical α.inv β.hom := by
ext X₁
simp only [Functor.comp_obj, whiskerVertical_app, assoc, Iso.hom_inv_id_app_assoc,
← B.map_comp, Iso.hom_inv_id_app, B.map_id, comp_id]
rw [this]
exact whiskerVertical (w.whiskerVertical α.hom β.inv) α.symm β.symm
· intro h
exact whiskerVertical w α β
instance [w.GuitartExact] (α : L ⟶ L') (β : R' ⟶ R)
[IsIso α] [IsIso β] : (w.whiskerVertical α β).GuitartExact :=
whiskerVertical w (asIso α) (asIso β).symm
end GuitartExact
end WhiskerVertical
section VerticalComposition
variable {H₁ : C₁ ⥤ D₁} {L₁ : C₁ ⥤ C₂} {R₁ : D₁ ⥤ D₂} {H₂ : C₂ ⥤ D₂}
(w : TwoSquare H₁ L₁ R₁ H₂)
{L₂ : C₂ ⥤ C₃} {R₂ : D₂ ⥤ D₃} {H₃ : C₃ ⥤ D₃}
(w' : TwoSquare H₂ L₂ R₂ H₃)
/-- The canonical isomorphism between
`w.structuredArrowDownwards Y₁ ⋙ w'.structuredArrowDownwards (R₁.obj Y₁)` and
`(w ≫ᵥ w').structuredArrowDownwards Y₁.` -/
def structuredArrowDownwardsComp (Y₁ : D₁) :
w.structuredArrowDownwards Y₁ ⋙ w'.structuredArrowDownwards (R₁.obj Y₁) ≅
(w ≫ᵥ w').structuredArrowDownwards Y₁ :=
NatIso.ofComponents (fun _ => StructuredArrow.isoMk (Iso.refl _))
/-- The vertical composition of 2-squares. (Variant where we allow the replacement of
the vertical compositions by isomorphic functors.) -/
@[simps!]
def vComp' {L₁₂ : C₁ ⥤ C₃} {R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ L₂ ≅ L₁₂)
(eR : R₁ ⋙ R₂ ≅ R₁₂) : TwoSquare H₁ L₁₂ R₁₂ H₃ :=
(w ≫ᵥ w').whiskerVertical eL.hom eR.inv
namespace GuitartExact
instance vComp [hw : w.GuitartExact] [hw' : w'.GuitartExact] :
(w ≫ᵥ w').GuitartExact := by
simp only [TwoSquare.guitartExact_iff_initial]
intro Y₁
rw [← Functor.initial_natIso_iff (structuredArrowDownwardsComp w w' Y₁)]
infer_instance
instance vComp' [GuitartExact w] [GuitartExact w'] {L₁₂ : C₁ ⥤ C₃}
{R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ L₂ ≅ L₁₂)
(eR : R₁ ⋙ R₂ ≅ R₁₂) : (w.vComp' w' eL eR).GuitartExact := by
dsimp only [TwoSquare.vComp']
infer_instance
lemma vComp_iff_of_equivalences (eL : C₂ ≌ C₃) (eR : D₂ ≌ D₃)
(w' : H₂ ⋙ eR.functor ≅ eL.functor ⋙ H₃) :
(w ≫ᵥ w'.hom).GuitartExact ↔ w.GuitartExact := by
constructor
· intro hww'
letI : CatCommSq H₂ eL.functor eR.functor H₃ := ⟨w'⟩
have hw' : CatCommSq.iso H₂ eL.functor eR.functor H₃ = w' := rfl
letI : CatCommSq H₃ eL.inverse eR.inverse H₂ := CatCommSq.vInvEquiv _ _ _ _ inferInstance
let w'' := CatCommSq.iso H₃ eL.inverse eR.inverse H₂
let α : (L₁ ⋙ eL.functor) ⋙ eL.inverse ≅ L₁ :=
Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft L₁ eL.unitIso.symm ≪≫ L₁.rightUnitor
let β : (R₁ ⋙ eR.functor) ⋙ eR.inverse ≅ R₁ :=
Functor.associator _ _ _ ≪≫ Functor.isoWhiskerLeft R₁ eR.unitIso.symm ≪≫ R₁.rightUnitor
have : w = (w ≫ᵥ w'.hom).vComp' w''.hom α β := by
ext X₁
simp? [w'', α, β] says
simp only [Functor.comp_obj, vComp'_app, Iso.trans_inv, Functor.isoWhiskerLeft_inv,
Iso.symm_inv, assoc, NatTrans.comp_app, Functor.id_obj, Functor.rightUnitor_inv_app,
Functor.whiskerLeft_app, Functor.associator_inv_app, comp_id, id_comp, vComp_app,
Functor.map_comp, Equivalence.inv_fun_map, CatCommSq.vInv_iso_hom_app, Iso.trans_hom,
Functor.isoWhiskerLeft_hom, Iso.symm_hom, Functor.associator_hom_app,
Functor.rightUnitor_hom_app, Iso.hom_inv_id_app_assoc, w'', this, α, β]
simp only [hw', ← eR.inverse.map_comp_assoc]
rw [Equivalence.counitInv_app_functor, ← Functor.comp_map, ← NatTrans.naturality_assoc]
simp [← H₂.map_comp]
rw [this]
infer_instance
· intro
exact vComp w w'.hom
lemma vComp'_iff_of_equivalences (E : C₂ ≌ C₃) (E' : D₂ ≌ D₃)
(w' : H₂ ⋙ E'.functor ≅ E.functor ⋙ H₃) {L₁₂ : C₁ ⥤ C₃}
{R₁₂ : D₁ ⥤ D₃} (eL : L₁ ⋙ E.functor ≅ L₁₂)
(eR : R₁ ⋙ E'.functor ≅ R₁₂) :
(w.vComp' w'.hom eL eR).GuitartExact ↔ w.GuitartExact := by
rw [← vComp_iff_of_equivalences w E E' w', TwoSquare.vComp', whiskerVertical_iff]
end GuitartExact
end VerticalComposition
end TwoSquare
end CategoryTheory
|
Blocks.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.Algebra.Pointwise.Stabilizer
import Mathlib.Data.Setoid.Partition
import Mathlib.GroupTheory.GroupAction.Pointwise
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.GroupTheory.Index
import Mathlib.Tactic.IntervalCases
/-! # Blocks
Given `SMul G X`, an action of a type `G` on a type `X`, we define
- the predicate `MulAction.IsBlock G B` states that `B : Set X` is a block,
which means that the sets `g • B`, for `g ∈ G`, are equal or disjoint.
Under `Group G` and `MulAction G X`, this is equivalent to the classical
definition `MulAction.IsBlock.def_one`
- a bunch of lemmas that give examples of “trivial” blocks : ⊥, ⊤, singletons,
and non trivial blocks: orbit of the group, orbit of a normal subgroup…
The non-existence of nontrivial blocks is the definition of primitive actions.
## Results for actions on finite sets
- `MulAction.IsBlock.ncard_block_mul_ncard_orbit_eq` : The cardinality of a block
multiplied by the number of its translates is the cardinal of the ambient type
- `MulAction.IsBlock.eq_univ_of_card_lt` : a too large block is equal to `Set.univ`
- `MulAction.IsBlock.subsingleton_of_card_lt` : a too small block is a subsingleton
- `MulAction.IsBlock.of_subset` : the intersections of the translates of a finite subset
that contain a given point is a block
- `MulAction.BlockMem` : the type of blocks containing a given element
- `MulAction.BlockMem.instBoundedOrder` :
the type of blocks containing a given element is a bounded order.
## References
We follow [Wielandt-1964].
-/
open Set
open scoped Pointwise
namespace MulAction
section orbits
variable {G : Type*} [Group G] {X : Type*} [MulAction G X]
@[to_additive]
theorem orbit.eq_or_disjoint (a b : X) :
orbit G a = orbit G b ∨ Disjoint (orbit G a) (orbit G b) := by
apply (em (Disjoint (orbit G a) (orbit G b))).symm.imp _ id
simp +contextual
only [Set.not_disjoint_iff, ← orbit_eq_iff, forall_exists_index, eq_comm, implies_true]
@[to_additive]
theorem orbit.pairwiseDisjoint :
(Set.range fun x : X => orbit G x).PairwiseDisjoint id := by
rintro s ⟨x, rfl⟩ t ⟨y, rfl⟩ h
contrapose! h
exact (orbit.eq_or_disjoint x y).resolve_right h
/-- Orbits of an element form a partition -/
@[to_additive /-- Orbits of an element form a partition -/]
theorem IsPartition.of_orbits :
Setoid.IsPartition (Set.range fun a : X => orbit G a) := by
apply orbit.pairwiseDisjoint.isPartition_of_exists_of_ne_empty
· intro x
exact ⟨_, ⟨x, rfl⟩, mem_orbit_self x⟩
· rintro ⟨a, ha : orbit G a = ∅⟩
exact (MulAction.orbit_nonempty a).ne_empty ha
end orbits
section SMul
variable (G : Type*) {X : Type*} [SMul G X] {B : Set X} {a : X}
-- Change terminology to IsFullyInvariant?
/-- A set `B` is a `G`-fixed block if `g • B = B` for all `g : G`. -/
@[to_additive /-- A set `B` is a `G`-fixed block if `g +ᵥ B = B` for all `g : G`. -/]
def IsFixedBlock (B : Set X) := ∀ g : G, g • B = B
/-- A set `B` is a `G`-invariant block if `g • B ⊆ B` for all `g : G`.
Note: It is not necessarily a block when the action is not by a group. -/
@[to_additive
/-- A set `B` is a `G`-invariant block if `g +ᵥ B ⊆ B` for all `g : G`.
Note: It is not necessarily a block when the action is not by a group. -/]
def IsInvariantBlock (B : Set X) := ∀ g : G, g • B ⊆ B
section IsTrivialBlock
/-- A trivial block is a `Set X` which is either a subsingleton or `univ`.
Note: It is not necessarily a block when the action is not by a group. -/
@[to_additive
/-- A trivial block is a `Set X` which is either a subsingleton or `univ`.
Note: It is not necessarily a block when the action is not by a group. -/]
def IsTrivialBlock (B : Set X) := B.Subsingleton ∨ B = univ
variable {M α N β : Type*}
section monoid
variable [Monoid M] [MulAction M α] [Monoid N] [MulAction N β]
@[to_additive]
theorem IsTrivialBlock.image {φ : M → N} {f : α →ₑ[φ] β}
(hf : Function.Surjective f) {B : Set α} (hB : IsTrivialBlock B) :
IsTrivialBlock (f '' B) := by
obtain hB | hB := hB
· apply Or.intro_left; apply Set.Subsingleton.image hB
· apply Or.intro_right; rw [hB]
simp only [Set.image_univ, Set.range_eq_univ, hf]
@[to_additive]
theorem IsTrivialBlock.preimage {φ : M → N} {f : α →ₑ[φ] β}
(hf : Function.Injective f) {B : Set β} (hB : IsTrivialBlock B) :
IsTrivialBlock (f ⁻¹' B) := by
obtain hB | hB := hB
· apply Or.intro_left; exact Set.Subsingleton.preimage hB hf
· apply Or.intro_right; simp only [hB]; apply Set.preimage_univ
end monoid
variable [Group M] [MulAction M α] [Monoid N] [MulAction N β]
@[to_additive]
theorem IsTrivialBlock.smul {B : Set α} (hB : IsTrivialBlock B) (g : M) :
IsTrivialBlock (g • B) := by
cases hB with
| inl h =>
left
exact (Function.Injective.subsingleton_image_iff (MulAction.injective g)).mpr h
| inr h =>
right
rw [h, ← Set.image_smul, Set.image_univ_of_surjective (MulAction.surjective g)]
@[to_additive]
theorem IsTrivialBlock.smul_iff {B : Set α} (g : M) :
IsTrivialBlock (g • B) ↔ IsTrivialBlock B := by
constructor
· intro H
convert IsTrivialBlock.smul H g⁻¹
simp only [inv_smul_smul]
· intro H
exact IsTrivialBlock.smul H g
end IsTrivialBlock
/-- A set `B` is a `G`-block iff the sets of the form `g • B` are pairwise equal or disjoint. -/
@[to_additive
/-- A set `B` is a `G`-block iff the sets of the form `g +ᵥ B` are pairwise equal or disjoint. -/]
def IsBlock (B : Set X) := ∀ ⦃g₁ g₂ : G⦄, g₁ • B ≠ g₂ • B → Disjoint (g₁ • B) (g₂ • B)
variable {G} {s : Set G} {g g₁ g₂ : G}
@[to_additive]
lemma isBlock_iff_smul_eq_smul_of_nonempty :
IsBlock G B ↔ ∀ ⦃g₁ g₂ : G⦄, (g₁ • B ∩ g₂ • B).Nonempty → g₁ • B = g₂ • B := by
simp_rw [IsBlock, ← not_disjoint_iff_nonempty_inter, not_imp_comm]
@[to_additive]
lemma isBlock_iff_pairwiseDisjoint_range_smul :
IsBlock G B ↔ (range fun g : G ↦ g • B).PairwiseDisjoint id := pairwiseDisjoint_range_iff.symm
@[to_additive]
lemma isBlock_iff_smul_eq_smul_or_disjoint :
IsBlock G B ↔ ∀ g₁ g₂ : G, g₁ • B = g₂ • B ∨ Disjoint (g₁ • B) (g₂ • B) :=
forall₂_congr fun _ _ ↦ or_iff_not_imp_left.symm
@[to_additive]
lemma IsBlock.smul_eq_smul_of_subset (hB : IsBlock G B) (hg : g₁ • B ⊆ g₂ • B) :
g₁ • B = g₂ • B := by
by_contra! hg'
obtain rfl : B = ∅ := by simpa using (hB hg').eq_bot_of_le hg
simp at hg'
@[to_additive]
lemma IsBlock.not_smul_set_ssubset_smul_set (hB : IsBlock G B) : ¬ g₁ • B ⊂ g₂ • B :=
fun hab ↦ hab.ne <| hB.smul_eq_smul_of_subset hab.subset
@[to_additive]
lemma IsBlock.disjoint_smul_set_smul (hB : IsBlock G B) (hgs : ¬ g • B ⊆ s • B) :
Disjoint (g • B) (s • B) := by
rw [← iUnion_smul_set, disjoint_iUnion₂_right]
exact fun b hb ↦ hB fun h ↦ hgs <| h.trans_subset <| smul_set_subset_smul hb
@[to_additive]
lemma IsBlock.disjoint_smul_smul_set (hB : IsBlock G B) (hgs : ¬ g • B ⊆ s • B) :
Disjoint (s • B) (g • B) := (hB.disjoint_smul_set_smul hgs).symm
@[to_additive]
alias ⟨IsBlock.smul_eq_smul_of_nonempty, _⟩ := isBlock_iff_smul_eq_smul_of_nonempty
@[to_additive]
alias ⟨IsBlock.pairwiseDisjoint_range_smul, _⟩ := isBlock_iff_pairwiseDisjoint_range_smul
@[to_additive]
alias ⟨IsBlock.smul_eq_smul_or_disjoint, _⟩ := isBlock_iff_smul_eq_smul_or_disjoint
/-- A fixed block is a block. -/
@[to_additive /-- A fixed block is a block. -/]
lemma IsFixedBlock.isBlock (hfB : IsFixedBlock G B) : IsBlock G B := by simp [IsBlock, hfB _]
/-- The empty set is a block. -/
@[to_additive (attr := simp) /-- The empty set is a block. -/]
lemma IsBlock.empty : IsBlock G (∅ : Set X) := by simp [IsBlock]
/-- A singleton is a block. -/
@[to_additive /-- A singleton is a block. -/]
lemma IsBlock.singleton : IsBlock G ({a} : Set X) := by simp [IsBlock]
/-- Subsingletons are (trivial) blocks. -/
@[to_additive /-- Subsingletons are (trivial) blocks. -/]
lemma IsBlock.of_subsingleton (hB : B.Subsingleton) : IsBlock G B :=
hB.induction_on .empty fun _ ↦ .singleton
/-- A fixed block is an invariant block. -/
@[to_additive /-- A fixed block is an invariant block. -/]
lemma IsFixedBlock.isInvariantBlock (hB : IsFixedBlock G B) : IsInvariantBlock G B :=
fun _ ↦ (hB _).le
end SMul
section Monoid
variable {M X : Type*} [Monoid M] [MulAction M X] {B : Set X} {s : Set M}
@[to_additive]
lemma IsBlock.disjoint_smul_right (hB : IsBlock M B) (hs : ¬ B ⊆ s • B) : Disjoint B (s • B) := by
simpa using hB.disjoint_smul_set_smul (g := 1) (by simpa using hs)
@[to_additive]
lemma IsBlock.disjoint_smul_left (hB : IsBlock M B) (hs : ¬ B ⊆ s • B) : Disjoint (s • B) B :=
(hB.disjoint_smul_right hs).symm
end Monoid
section Group
variable {G : Type*} [Group G] {X : Type*} [MulAction G X] {B : Set X}
@[to_additive]
lemma isBlock_iff_disjoint_smul_of_ne :
IsBlock G B ↔ ∀ ⦃g : G⦄, g • B ≠ B → Disjoint (g • B) B := by
refine ⟨fun hB g ↦ by simpa using hB (g₂ := 1), fun hB g₁ g₂ h ↦ ?_⟩
simp only [disjoint_smul_set_right, ne_eq, ← inv_smul_eq_iff, smul_smul] at h ⊢
exact hB h
@[to_additive]
lemma isBlock_iff_smul_eq_of_nonempty :
IsBlock G B ↔ ∀ ⦃g : G⦄, (g • B ∩ B).Nonempty → g • B = B := by
simp_rw [isBlock_iff_disjoint_smul_of_ne, ← not_disjoint_iff_nonempty_inter, not_imp_comm]
@[to_additive]
lemma isBlock_iff_smul_eq_or_disjoint :
IsBlock G B ↔ ∀ g : G, g • B = B ∨ Disjoint (g • B) B :=
isBlock_iff_disjoint_smul_of_ne.trans <| forall_congr' fun _ ↦ or_iff_not_imp_left.symm
@[to_additive]
lemma isBlock_iff_smul_eq_of_mem :
IsBlock G B ↔ ∀ ⦃g : G⦄ ⦃a : X⦄, a ∈ B → g • a ∈ B → g • B = B := by
simp [isBlock_iff_smul_eq_of_nonempty, Set.Nonempty, mem_smul_set]
@[to_additive] alias ⟨IsBlock.disjoint_smul_of_ne, _⟩ := isBlock_iff_disjoint_smul_of_ne
@[to_additive] alias ⟨IsBlock.smul_eq_of_nonempty, _⟩ := isBlock_iff_smul_eq_of_nonempty
@[to_additive] alias ⟨IsBlock.smul_eq_or_disjoint, _⟩ := isBlock_iff_smul_eq_or_disjoint
@[to_additive] alias ⟨IsBlock.smul_eq_of_mem, _⟩ := isBlock_iff_smul_eq_of_mem
-- TODO: Generalise to `SubgroupClass`
/-- If `B` is a `G`-block, then it is also a `H`-block for any subgroup `H` of `G`. -/
@[to_additive
/-- If `B` is a `G`-block, then it is also a `H`-block for any subgroup `H` of `G`. -/]
lemma IsBlock.subgroup {H : Subgroup G} (hB : IsBlock G B) : IsBlock H B := fun _ _ h ↦ hB h
/-- A block of a group action is invariant iff it is fixed. -/
@[to_additive /-- A block of a group action is invariant iff it is fixed. -/]
lemma isInvariantBlock_iff_isFixedBlock : IsInvariantBlock G B ↔ IsFixedBlock G B :=
⟨fun hB g ↦ (hB g).antisymm <| subset_smul_set_iff.2 <| hB _, IsFixedBlock.isInvariantBlock⟩
/-- An invariant block of a group action is a fixed block. -/
@[to_additive /-- An invariant block of a group action is a fixed block. -/]
alias ⟨IsInvariantBlock.isFixedBlock, _⟩ := isInvariantBlock_iff_isFixedBlock
/-- An invariant block of a group action is a block. -/
@[to_additive /-- An invariant block of a group action is a block. -/]
lemma IsInvariantBlock.isBlock (hB : IsInvariantBlock G B) : IsBlock G B := hB.isFixedBlock.isBlock
/-- The full set is a fixed block. -/
@[to_additive /-- The full set is a fixed block. -/]
lemma IsFixedBlock.univ : IsFixedBlock G (univ : Set X) := fun _ ↦ by simp
/-- The full set is a block. -/
@[to_additive (attr := simp) /-- The full set is a block. -/]
lemma IsBlock.univ : IsBlock G (univ : Set X) := IsFixedBlock.univ.isBlock
/-- The intersection of two blocks is a block. -/
@[to_additive /-- The intersection of two blocks is a block. -/]
lemma IsBlock.inter {B₁ B₂ : Set X} (h₁ : IsBlock G B₁) (h₂ : IsBlock G B₂) :
IsBlock G (B₁ ∩ B₂) := by
simp only [isBlock_iff_smul_eq_smul_of_nonempty, smul_set_inter] at h₁ h₂ ⊢
rintro g₁ g₂ ⟨a, ha₁, ha₂⟩
rw [h₁ ⟨a, ha₁.1, ha₂.1⟩, h₂ ⟨a, ha₁.2, ha₂.2⟩]
/-- An intersection of blocks is a block. -/
@[to_additive /-- An intersection of blocks is a block. -/]
lemma IsBlock.iInter {ι : Sort*} {B : ι → Set X} (hB : ∀ i, IsBlock G (B i)) :
IsBlock G (⋂ i, B i) := by
simp only [isBlock_iff_smul_eq_smul_of_nonempty, smul_set_iInter] at hB ⊢
rintro g₁ g₂ ⟨a, ha₁, ha₂⟩
simp_rw [fun i ↦ hB i ⟨a, iInter_subset _ i ha₁, iInter_subset _ i ha₂⟩]
/-- A trivial block is a block. -/
@[to_additive /-- A trivial block is a block. -/]
lemma IsTrivialBlock.isBlock (hB : IsTrivialBlock B) : IsBlock G B := by
obtain hB | rfl := hB
· exact .of_subsingleton hB
· exact .univ
/-- An orbit is a fixed block. -/
@[to_additive /-- An orbit is a fixed block. -/]
protected lemma IsFixedBlock.orbit (a : X) : IsFixedBlock G (orbit G a) := (smul_orbit · a)
/-- An orbit is a block. -/
@[to_additive /-- An orbit is a block. -/]
protected lemma IsBlock.orbit (a : X) : IsBlock G (orbit G a) := (IsFixedBlock.orbit a).isBlock
@[to_additive]
lemma isBlock_top : IsBlock (⊤ : Subgroup G) B ↔ IsBlock G B :=
Subgroup.topEquiv.toEquiv.forall_congr fun _ ↦ Subgroup.topEquiv.toEquiv.forall_congr_left
@[to_additive]
lemma IsBlock.preimage {H Y : Type*} [Group H] [MulAction H Y]
{φ : H → G} (j : Y →ₑ[φ] X) (hB : IsBlock G B) :
IsBlock H (j ⁻¹' B) := by
rintro g₁ g₂ hg
rw [← Group.preimage_smul_setₛₗ, ← Group.preimage_smul_setₛₗ] at hg ⊢
exact (hB <| ne_of_apply_ne _ hg).preimage _
@[to_additive]
theorem IsBlock.image {H Y : Type*} [SMul H Y] {φ : G → H} (j : X →ₑ[φ] Y)
(hφ : Function.Surjective φ) (hj : Function.Injective j) (hB : IsBlock G B) :
IsBlock H (j '' B) := by
simp only [IsBlock, hφ.forall, ← image_smul_setₛₗ]
exact fun g₁ g₂ hg ↦ disjoint_image_of_injective hj <| hB <| ne_of_apply_ne _ hg
@[to_additive]
theorem IsBlock.subtype_val_preimage {C : SubMulAction G X} (hB : IsBlock G B) :
IsBlock G (Subtype.val ⁻¹' B : Set C) :=
hB.preimage C.inclusion
@[to_additive]
theorem isBlock_subtypeVal {C : SubMulAction G X} {B : Set C} :
IsBlock G (Subtype.val '' B : Set X) ↔ IsBlock G B := by
refine forall₂_congr fun g₁ g₂ ↦ ?_
rw [← SubMulAction.inclusion.coe_eq, ← image_smul_set, ← image_smul_set, ne_eq,
Set.image_eq_image C.inclusion_injective, disjoint_image_iff C.inclusion_injective]
theorem _root_.AddAction.IsBlock.of_addSubgroup_of_conjugate
{G : Type*} [AddGroup G] {X : Type*} [AddAction G X] {B : Set X}
{H : AddSubgroup G} (hB : AddAction.IsBlock H B) (g : G) :
AddAction.IsBlock (H.map (AddAut.conj g).toMul.toAddMonoidHom) (g +ᵥ B) := by
rw [AddAction.isBlock_iff_vadd_eq_or_disjoint]
intro h'
obtain ⟨h, hH, hh⟩ := AddSubgroup.mem_map.mp (SetLike.coe_mem h')
simp only [AddEquiv.coe_toAddMonoidHom, AddAut.conj_apply] at hh
suffices h' +ᵥ (g +ᵥ B) = g +ᵥ (h +ᵥ B) by
simp only [this]
apply (hB.vadd_eq_or_disjoint ⟨h, hH⟩).imp
· intro hB'; congr
· exact Set.disjoint_image_of_injective (AddAction.injective g)
suffices (h' : G) +ᵥ (g +ᵥ B) = g +ᵥ (h +ᵥ B) by
exact this
rw [← hh, vadd_vadd, vadd_vadd]
simp
theorem IsBlock.of_subgroup_of_conjugate {H : Subgroup G} (hB : IsBlock H B) (g : G) :
IsBlock (H.map (MulAut.conj g).toMonoidHom) (g • B) := by
rw [isBlock_iff_smul_eq_or_disjoint]
intro h'
obtain ⟨h, hH, hh⟩ := Subgroup.mem_map.mp (SetLike.coe_mem h')
simp only [MulEquiv.coe_toMonoidHom, MulAut.conj_apply] at hh
suffices h' • g • B = g • h • B by
simp only [this]
apply (hB.smul_eq_or_disjoint ⟨h, hH⟩).imp
· intro; congr
· exact Set.disjoint_image_of_injective (MulAction.injective g)
suffices (h' : G) • g • B = g • h • B by
rw [← this]; rfl
rw [← hh, smul_smul (g * h * g⁻¹) g B, smul_smul g h B, inv_mul_cancel_right]
/-- A translate of a block is a block -/
theorem _root_.AddAction.IsBlock.translate
{G : Type*} [AddGroup G] {X : Type*} [AddAction G X] (B : Set X)
(g : G) (hB : AddAction.IsBlock G B) :
AddAction.IsBlock G (g +ᵥ B) := by
rw [← AddAction.isBlock_top] at hB ⊢
rw [← AddSubgroup.map_comap_eq_self_of_surjective (G := G) ?_ ⊤]
· apply AddAction.IsBlock.of_addSubgroup_of_conjugate
rwa [AddSubgroup.comap_top]
· exact (AddAut.conj g).surjective
/-- A translate of a block is a block -/
@[to_additive existing]
theorem IsBlock.translate (g : G) (hB : IsBlock G B) :
IsBlock G (g • B) := by
rw [← isBlock_top] at hB ⊢
rw [← Subgroup.map_comap_eq_self_of_surjective
(G := G) (f := MulAut.conj g) (MulAut.conj g).surjective ⊤]
apply IsBlock.of_subgroup_of_conjugate
rwa [Subgroup.comap_top]
variable (G) in
/-- For `SMul G X`, a block system of `X` is a partition of `X` into blocks
for the action of `G` -/
@[to_additive /-- For `VAdd G X`, a block system of `X` is a partition of `X` into blocks
for the additive action of `G` -/]
def IsBlockSystem (ℬ : Set (Set X)) := Setoid.IsPartition ℬ ∧ ∀ ⦃B⦄, B ∈ ℬ → IsBlock G B
/-- Translates of a block form a block system -/
@[to_additive /-- Translates of a block form a block system -/]
theorem IsBlock.isBlockSystem [hGX : MulAction.IsPretransitive G X]
(hB : IsBlock G B) (hBe : B.Nonempty) :
IsBlockSystem G (Set.range fun g : G => g • B) := by
refine ⟨⟨?nonempty, ?cover⟩, ?mem_blocks⟩
case mem_blocks => rintro B' ⟨g, rfl⟩; exact hB.translate g
· simp only [Set.mem_range, not_exists]
intro g hg
apply hBe.ne_empty
simpa only [Set.smul_set_eq_empty] using hg
· intro a
obtain ⟨b : X, hb : b ∈ B⟩ := hBe
obtain ⟨g, rfl⟩ := exists_smul_eq G b a
use g • B
simp only [Set.smul_mem_smul_set_iff, hb, Set.mem_range,
exists_apply_eq_apply, and_imp, forall_exists_index,
forall_apply_eq_imp_iff, true_and]
exact fun g' ha ↦ hB.smul_eq_smul_of_nonempty ⟨g • b, ha, ⟨b, hb, rfl⟩⟩
section Normal
@[to_additive]
lemma smul_orbit_eq_orbit_smul (N : Subgroup G) [nN : N.Normal] (a : X) (g : G) :
g • orbit N a = orbit N (g • a) := by
simp only [orbit, Set.smul_set_range]
ext
simp only [Set.mem_range]
constructor
· rintro ⟨⟨k, hk⟩, rfl⟩
use ⟨g * k * g⁻¹, nN.conj_mem k hk g⟩
simp only [Subgroup.mk_smul]
rw [smul_smul, inv_mul_cancel_right, ← smul_smul]
· rintro ⟨⟨k, hk⟩, rfl⟩
use ⟨g⁻¹ * k * g, nN.conj_mem' k hk g⟩
simp only [Subgroup.mk_smul]
simp only [← smul_smul, smul_inv_smul]
/-- An orbit of a normal subgroup is a block -/
@[to_additive /-- An orbit of a normal subgroup is a block -/]
theorem IsBlock.orbit_of_normal {N : Subgroup G} [N.Normal] (a : X) :
IsBlock G (orbit N a) := by
rw [isBlock_iff_smul_eq_or_disjoint]
intro g
rw [smul_orbit_eq_orbit_smul]
apply orbit.eq_or_disjoint
/-- The orbits of a normal subgroup form a block system -/
@[to_additive /-- The orbits of a normal subgroup form a block system -/]
theorem IsBlockSystem.of_normal {N : Subgroup G} [N.Normal] :
IsBlockSystem G (Set.range fun a : X => orbit N a) := by
constructor
· apply IsPartition.of_orbits
· intro b; rintro ⟨a, rfl⟩
exact .orbit_of_normal a
section Group
variable {S H : Type*} [Group H] [SetLike S H] [SubgroupClass S H] {s : S} {a : G}
/-!
Annoyingly, it seems like the following two lemmas cannot be unified.
-/
section Left
variable [MulAction G H] [IsScalarTower G H H]
/-- See `MulAction.isBlock_subgroup'` for a version that works for the right action of a group on
itself. -/
@[to_additive /-- See `AddAction.isBlock_subgroup'` for a version that works for the right action
of a group on itself. -/]
lemma isBlock_subgroup : IsBlock G (s : Set H) := by
simp only [IsBlock, disjoint_left]
rintro a b hab _ ⟨c, hc, rfl⟩ ⟨d, hd, (hcd : b • d = a • c)⟩
refine hab ?_
rw [← smul_coe_set hc, ← smul_assoc, ← hcd, smul_assoc, smul_coe_set hc, smul_coe_set hd]
end Left
section Right
variable [MulAction G H] [IsScalarTower G Hᵐᵒᵖ H]
open MulOpposite
/-- See `MulAction.isBlock_subgroup` for a version that works for the left action of a group on
itself. -/
@[to_additive /-- See `AddAction.isBlock_subgroup` for a version that works for the left action
of a group on itself. -/]
lemma isBlock_subgroup' : IsBlock G (s : Set H) := by
simp only [IsBlock, disjoint_left]
rintro a b hab _ ⟨c, hc, rfl⟩ ⟨d, hd, (hcd : b • d = a • c)⟩
refine hab ?_
rw [← op_smul_coe_set hc, ← smul_assoc, ← op_smul, ← hcd, op_smul, smul_assoc, op_smul_coe_set hc,
op_smul_coe_set hd]
end Right
end Group
end Normal
section Stabilizer
/- For transitive actions, construction of the lattice equivalence
`block_stabilizerOrderIso` between
- blocks of `MulAction G X` containing a point `a ∈ X`,
and
- subgroups of G containing `stabilizer G a`.
(Wielandt, th. 7.5) -/
/-- The orbit of `a` under a subgroup containing the stabilizer of `a` is a block -/
@[to_additive /-- The orbit of `a` under a subgroup containing the stabilizer of `a` is a block -/]
theorem IsBlock.of_orbit {H : Subgroup G} {a : X} (hH : stabilizer G a ≤ H) :
IsBlock G (MulAction.orbit H a) := by
rw [isBlock_iff_smul_eq_of_nonempty]
rintro g ⟨-, ⟨-, ⟨h₁, rfl⟩, h⟩, h₂, rfl⟩
suffices g ∈ H by
rw [← Subgroup.coe_mk H g this, ← H.toSubmonoid.smul_def, smul_orbit (⟨g, this⟩ : H) a]
rw [← mul_mem_cancel_left h₂⁻¹.2, ← mul_mem_cancel_right h₁.2]
apply hH
simpa only [mem_stabilizer_iff, InvMemClass.coe_inv, mul_smul, inv_smul_eq_iff]
/-- If `B` is a block containing `a`, then the stabilizer of `B` contains the stabilizer of `a` -/
@[to_additive
/-- If `B` is a block containing `a`, then the stabilizer of `B` contains the stabilizer of `a` -/]
theorem IsBlock.stabilizer_le (hB : IsBlock G B) {a : X} (ha : a ∈ B) :
stabilizer G a ≤ stabilizer G B :=
fun g hg ↦ hB.smul_eq_of_nonempty ⟨a, by rwa [← hg, smul_mem_smul_set_iff], ha⟩
/-- A block containing `a` is the orbit of `a` under its stabilizer -/
@[to_additive /-- A block containing `a` is the orbit of `a` under its stabilizer -/]
theorem IsBlock.orbit_stabilizer_eq [IsPretransitive G X] (hB : IsBlock G B) {a : X} (ha : a ∈ B) :
MulAction.orbit (stabilizer G B) a = B := by
ext x
constructor
· rintro ⟨⟨k, k_mem⟩, rfl⟩
simp only [Subgroup.mk_smul]
rw [← k_mem, Set.smul_mem_smul_set_iff]
exact ha
· intro hx
obtain ⟨k, rfl⟩ := exists_smul_eq G a x
exact ⟨⟨k, hB.smul_eq_of_mem ha hx⟩, rfl⟩
/-- A subgroup containing the stabilizer of `a`
is the stabilizer of the orbit of `a` under that subgroup -/
@[to_additive
/-- A subgroup containing the stabilizer of `a`
is the stabilizer of the orbit of `a` under that subgroup -/]
theorem stabilizer_orbit_eq {a : X} {H : Subgroup G} (hH : stabilizer G a ≤ H) :
stabilizer G (orbit H a) = H := by
ext g
constructor
· intro hg
obtain ⟨-, ⟨b, rfl⟩, h⟩ := hg.symm ▸ mem_orbit_self a
simp_rw [H.toSubmonoid.smul_def, ← mul_smul, ← mem_stabilizer_iff] at h
exact (mul_mem_cancel_right b.2).mp (hH h)
· intro hg
rw [mem_stabilizer_iff, ← Subgroup.coe_mk H g hg, ← Submonoid.smul_def (S := H.toSubmonoid)]
apply smul_orbit (G := H)
variable (G)
/-- Order equivalence between blocks in `X` containing a point `a`
and subgroups of `G` containing the stabilizer of `a` (Wielandt, th. 7.5) -/
@[to_additive
/-- Order equivalence between blocks in `X` containing a point `a`
and subgroups of `G` containing the stabilizer of `a` (Wielandt, th. 7.5) -/]
def block_stabilizerOrderIso [htGX : IsPretransitive G X] (a : X) :
{ B : Set X // a ∈ B ∧ IsBlock G B } ≃o Set.Ici (stabilizer G a) where
toFun := fun ⟨B, ha, hB⟩ => ⟨stabilizer G B, hB.stabilizer_le ha⟩
invFun := fun ⟨H, hH⟩ =>
⟨MulAction.orbit H a, MulAction.mem_orbit_self a, IsBlock.of_orbit hH⟩
left_inv := fun ⟨_, ha, hB⟩ =>
(id (propext Subtype.mk_eq_mk)).mpr (hB.orbit_stabilizer_eq ha)
right_inv := fun ⟨_, hH⟩ =>
(id (propext Subtype.mk_eq_mk)).mpr (stabilizer_orbit_eq hH)
map_rel_iff' := by
rintro ⟨B, ha, hB⟩; rintro ⟨B', ha', hB'⟩
simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, Set.le_eq_subset]
constructor
· rintro hBB' b hb
obtain ⟨k, rfl⟩ := htGX.exists_smul_eq a b
suffices k ∈ stabilizer G B' by
exact this.symm ▸ (Set.smul_mem_smul_set ha')
exact hBB' (hB.smul_eq_of_mem ha hb)
· intro hBB' g hgB
apply hB'.smul_eq_of_mem ha'
exact hBB' <| hgB.symm ▸ (Set.smul_mem_smul_set ha)
/-- The type of blocks for a group action containing a given element -/
@[to_additive
/-- The type of blocks for an additive group action containing a given element -/]
abbrev BlockMem (a : X) : Type _ := {B : Set X // a ∈ B ∧ IsBlock G B}
namespace BlockMem
/-- The type of blocks for a group action containing a given element is a bounded order. -/
@[to_additive /-- The type of blocks for an additive group action containing a given element is a
bounded order. -/]
instance (a : X) : BoundedOrder (BlockMem G a) where
top := ⟨Set.univ, Set.mem_univ a, .univ⟩
le_top := by
rintro ⟨B, ha, hB⟩
simp only [Subtype.mk_le_mk, le_eq_subset, subset_univ]
bot := ⟨{a}, Set.mem_singleton a, IsBlock.singleton⟩
bot_le := by
rintro ⟨B, ha, hB⟩
simp only [Subtype.mk_le_mk, Set.le_eq_subset, Set.singleton_subset_iff]
exact ha
@[to_additive (attr := simp, norm_cast)]
theorem coe_top (a : X) :
((⊤ : BlockMem G a) : Set X) = Set.univ :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_bot (a : X) :
((⊥ : BlockMem G a) : Set X) = {a} :=
rfl
@[to_additive]
instance [Nontrivial X] (a : X) : Nontrivial (BlockMem G a) := by
rw [nontrivial_iff]
use ⊥, ⊤
intro h
rw [← Subtype.coe_inj] at h
simp only [coe_top, coe_bot] at h
obtain ⟨b, hb⟩ := exists_ne a
apply hb
rw [← Set.mem_singleton_iff, h]
apply Set.mem_univ
end BlockMem
end Stabilizer
section Finite
namespace IsBlock
variable [IsPretransitive G X] {B : Set X}
@[to_additive]
theorem ncard_block_eq_relindex (hB : IsBlock G B) {x : X} (hx : x ∈ B) :
B.ncard = (stabilizer G x).relindex (stabilizer G B) := by
have key : (stabilizer G x).subgroupOf (stabilizer G B) = stabilizer (stabilizer G B) x := by
ext; rfl
rw [Subgroup.relindex, key, index_stabilizer, hB.orbit_stabilizer_eq hx]
/-- The cardinality of the ambient space is the product of the cardinality of a block
by the cardinality of the set of translates of that block -/
@[to_additive
/-- The cardinality of the ambient space is the product of the cardinality of a block
by the cardinality of the set of translates of that block -/]
theorem ncard_block_mul_ncard_orbit_eq (hB : IsBlock G B) (hB_ne : B.Nonempty) :
Set.ncard B * Set.ncard (orbit G B) = Nat.card X := by
obtain ⟨x, hx⟩ := hB_ne
rw [ncard_block_eq_relindex hB hx, ← index_stabilizer,
Subgroup.relindex_mul_index (hB.stabilizer_le hx), index_stabilizer_of_transitive]
/-- The cardinality of a block divides the cardinality of the ambient type -/
@[to_additive /-- The cardinality of a block divides the cardinality of the ambient type -/]
theorem ncard_dvd_card (hB : IsBlock G B) (hB_ne : B.Nonempty) :
Set.ncard B ∣ Nat.card X :=
Dvd.intro _ (hB.ncard_block_mul_ncard_orbit_eq hB_ne)
/-- A too large block is equal to `univ` -/
@[to_additive /-- A too large block is equal to `univ` -/]
theorem eq_univ_of_card_lt [hX : Finite X] (hB : IsBlock G B) (hB' : Nat.card X < Set.ncard B * 2) :
B = Set.univ := by
rcases Set.eq_empty_or_nonempty B with rfl | hB_ne
· simp only [Set.ncard_empty, zero_mul, not_lt_zero'] at hB'
have key := hB.ncard_block_mul_ncard_orbit_eq hB_ne
rw [← key, mul_lt_mul_iff_of_pos_left (by rwa [Set.ncard_pos])] at hB'
interval_cases (orbit G B).ncard
· rw [mul_zero, eq_comm, Nat.card_eq_zero, or_iff_left hX.not_infinite] at key
exact (IsEmpty.exists_iff.mp hB_ne).elim
· rw [mul_one, ← Set.ncard_univ] at key
rw [Set.eq_of_subset_of_ncard_le (Set.subset_univ B) key.ge]
/-- If a block has too many translates, then it is a (sub)singleton -/
@[to_additive /-- If a block has too many translates, then it is a (sub)singleton -/]
theorem subsingleton_of_card_lt [Finite X] (hB : IsBlock G B)
(hB' : Nat.card X < 2 * Set.ncard (orbit G B)) :
B.Subsingleton := by
suffices Set.ncard B < 2 by
rw [Nat.lt_succ_iff, Set.ncard_le_one_iff_eq] at this
cases this with
| inl h => rw [h]; exact Set.subsingleton_empty
| inr h =>
obtain ⟨a, ha⟩ := h; rw [ha]; exact Set.subsingleton_singleton
cases Set.eq_empty_or_nonempty B with
| inl h => rw [h, Set.ncard_empty]; norm_num
| inr h =>
rw [← hB.ncard_block_mul_ncard_orbit_eq h, lt_iff_not_ge] at hB'
rw [← not_le]
exact fun hb ↦ hB' (Nat.mul_le_mul_right _ hb)
/- The assumption `B.Finite` is necessary :
For G = ℤ acting on itself, a = 0 and B = ℕ, the translates `k • B` of the statement
are just `k + ℕ`, for `k ≤ 0`, and the corresponding intersection is `ℕ`, which is not a block.
(Remark by Thomas Browning) -/
/-- The intersection of the translates of a *finite* subset which contain a given point
is a block (Wielandt, th. 7.3). -/
@[to_additive
/-- The intersection of the translates of a *finite* subset which contain a given point
is a block (Wielandt, th. 7.3). -/]
theorem of_subset (a : X) (hfB : B.Finite) :
IsBlock G (⋂ (k : G) (_ : a ∈ k • B), k • B) := by
let B' := ⋂ (k : G) (_ : a ∈ k • B), k • B
rcases Set.eq_empty_or_nonempty B with hfB_e | hfB_ne
· simp [hfB_e]
have hB'₀ : ∀ (k : G) (_ : a ∈ k • B), B' ≤ k • B := by
intro k hk
exact Set.biInter_subset_of_mem hk
have hfB' : B'.Finite := by
obtain ⟨b, hb : b ∈ B⟩ := hfB_ne
obtain ⟨k, hk : k • b = a⟩ := exists_smul_eq G b a
apply Set.Finite.subset (Set.Finite.map _ hfB) (hB'₀ k ⟨b, hb, hk⟩)
have hag : ∀ g : G, a ∈ g • B' → B' ≤ g • B' := by
intro g hg x hx
-- a = g • b; b ∈ B'; a ∈ k • B → b ∈ k • B
simp only [B', Set.mem_iInter, Set.mem_smul_set_iff_inv_smul_mem,
smul_smul, ← mul_inv_rev] at hg hx ⊢
exact fun _ ↦ hx _ ∘ hg _
have hag' (g : G) (hg : a ∈ g • B') : B' = g • B' := by
rw [eq_comm, ← mem_stabilizer_iff, mem_stabilizer_set_iff_subset_smul_set hfB']
exact hag g hg
rw [isBlock_iff_smul_eq_of_nonempty]
rintro g ⟨b : X, hb' : b ∈ g • B', hb : b ∈ B'⟩
obtain ⟨k : G, hk : k • a = b⟩ := exists_smul_eq G a b
have hak : a ∈ k⁻¹ • B' := by
refine ⟨b, hb, ?_⟩
simp only [← hk, inv_smul_smul]
have hagk : a ∈ (k⁻¹ * g) • B' := by
rw [mul_smul, Set.mem_smul_set_iff_inv_smul_mem, inv_inv, hk]
exact hb'
have hkB' : B' = k⁻¹ • B' := hag' k⁻¹ hak
have hgkB' : B' = (k⁻¹ * g) • B' := hag' (k⁻¹ * g) hagk
rw [mul_smul] at hgkB'
rw [← smul_eq_iff_eq_inv_smul] at hkB' hgkB'
rw [← hgkB', hkB']
end IsBlock
end Finite
end Group
end MulAction
|
cyclotomic.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime.
From mathcomp Require Import ssralg poly finset fingroup finalg zmodp cyclic.
From mathcomp Require Import ssrnum ssrint archimedean polydiv intdiv mxpoly.
From mathcomp Require Import rat vector falgebra fieldext separable galois algC.
(******************************************************************************)
(* This file provides few basic properties of cyclotomic polynomials. *)
(* We define: *)
(* cyclotomic z n == the factorization of the nth cyclotomic polynomial in *)
(* a ring R in which z is an nth primitive root of unity. *)
(* 'Phi_n == the nth cyclotomic polynomial in int. *)
(* This library is quite limited, and should be extended in the future. In *)
(* particular the irreducibity of 'Phi_n is only stated indirectly, as the *)
(* fact that its embedding in the algebraics (algC) is the minimal polynomial *)
(* of an nth primitive root of unity. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section CyclotomicPoly.
Section NzRing.
Variable R : nzRingType.
Definition cyclotomic (z : R) n :=
\prod_(k < n | coprime k n) ('X - (z ^+ k)%:P).
Lemma cyclotomic_monic z n : cyclotomic z n \is monic.
Proof. exact: monic_prod_XsubC. Qed.
Lemma size_cyclotomic z n : size (cyclotomic z n) = (totient n).+1.
Proof.
rewrite /cyclotomic -big_filter size_prod_XsubC; congr _.+1.
case: big_enumP => _ _ _ [_ ->].
rewrite totient_count_coprime -big_mkcond big_mkord -sum1_card.
by apply: eq_bigl => k; rewrite coprime_sym.
Qed.
End NzRing.
Lemma separable_Xn_sub_1 (R : idomainType) n :
n%:R != 0 :> R -> @separable_poly R ('X^n - 1).
Proof.
case: n => [/eqP// | n nz_n]; rewrite unlock linearB /= derivC subr0.
rewrite derivXn -scaler_nat coprimepZr //= exprS -scaleN1r coprimep_sym.
by rewrite coprimep_addl_mul coprimepZr ?coprimep1 // (signr_eq0 _ 1).
Qed.
Section Field.
Variables (F : fieldType) (n : nat) (z : F).
Hypothesis prim_z : n.-primitive_root z.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma root_cyclotomic x : root (cyclotomic z n) x = n.-primitive_root x.
Proof.
transitivity (x \in [seq z ^+ i | i : 'I_n in [pred i : 'I_n | coprime i n]]).
by rewrite -root_prod_XsubC big_image.
apply/imageP/idP=> [[k co_k_n ->] | prim_x].
by rewrite prim_root_exp_coprime.
have [k Dx] := prim_rootP prim_z (prim_expr_order prim_x).
exists (Ordinal (ltn_pmod k n_gt0)) => /=; last by rewrite prim_expr_mod.
by rewrite inE coprime_modl -(prim_root_exp_coprime k prim_z) -Dx.
Qed.
Lemma prod_cyclotomic :
'X^n - 1 = \prod_(d <- divisors n) cyclotomic (z ^+ (n %/ d)) d.
Proof.
have in_d d: (d %| n)%N -> val (@inord n d) = d by move/dvdn_leq/inordK=> /= ->.
have dv_n k: (n %/ gcdn k n %| n)%N.
by rewrite -{3}(divnK (dvdn_gcdr k n)) dvdn_mulr.
have [uDn _ inDn] := divisors_correct n_gt0.
have defDn: divisors n = map val (map (@inord n) (divisors n)).
by rewrite -map_comp map_id_in // => d; rewrite inDn => /in_d.
rewrite defDn big_map big_uniq /=; last first.
by rewrite -(map_inj_uniq val_inj) -defDn.
pose h (k : 'I_n) : 'I_n.+1 := inord (n %/ gcdn k n).
rewrite -(factor_Xn_sub_1 prim_z) big_mkord.
rewrite (partition_big h (dvdn^~ n)) /= => [|k _]; last by rewrite in_d ?dv_n.
apply: eq_big => d; first by rewrite -(mem_map val_inj) -defDn inDn.
set q := (n %/ d)%N => d_dv_n.
have [q_gt0 d_gt0]: (0 < q /\ 0 < d)%N by apply/andP; rewrite -muln_gt0 divnK.
have fP (k : 'I_d): (q * k < n)%N by rewrite divn_mulAC ?ltn_divLR ?ltn_pmul2l.
rewrite (reindex (fun k => Ordinal (fP k))); last first.
have f'P (k : 'I_n): (k %/ q < d)%N by rewrite ltn_divLR // mulnC divnK.
exists (fun k => Ordinal (f'P k)) => [k _ | k /eqnP/=].
by apply: val_inj; rewrite /= mulKn.
rewrite in_d // => Dd; apply: val_inj; rewrite /= mulnC divnK // /q -Dd.
by rewrite divnA ?mulKn ?dvdn_gcdl ?dvdn_gcdr.
apply: eq_big => k; rewrite ?exprM // -val_eqE in_d //=.
rewrite -eqn_mul ?dvdn_gcdr ?gcdn_gt0 ?n_gt0 ?orbT //.
rewrite -[n in gcdn _ n](divnK d_dv_n) -muln_gcdr mulnCA mulnA divnK //.
by rewrite mulnC eqn_mul // divnn n_gt0 eq_sym.
Qed.
End Field.
End CyclotomicPoly.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Local Definition algC_intr_inj := @intr_inj algC.
#[local] Hint Resolve algC_intr_inj : core.
Local Notation intCK := (@intrKfloor algC).
Lemma C_prim_root_exists n : (n > 0)%N -> {z : algC | n.-primitive_root z}.
Proof.
pose p : {poly algC} := 'X^n - 1; have [r Dp] := closed_field_poly_normal p.
move=> n_gt0; apply/sigW; rewrite (monicP _) ?monicXnsubC // scale1r in Dp.
have rn1: all n.-unity_root r by apply/allP=> z; rewrite -root_prod_XsubC -Dp.
have sz_r: (n < (size r).+1)%N.
by rewrite -(size_prod_XsubC r id) -Dp size_XnsubC.
have [|z] := hasP (has_prim_root n_gt0 rn1 _ sz_r); last by exists z.
by rewrite -separable_prod_XsubC -Dp separable_Xn_sub_1 // pnatr_eq0 -lt0n.
Qed.
(* (Integral) Cyclotomic polynomials. *)
Definition Cyclotomic n : {poly int} :=
let: exist z _ := C_prim_root_exists (ltn0Sn n.-1) in
map_poly Num.floor (cyclotomic z n).
Notation "''Phi_' n" := (Cyclotomic n)
(at level 8, n at level 2, format "''Phi_' n").
Lemma Cyclotomic_monic n : 'Phi_n \is monic.
Proof.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /= _.
rewrite monicE lead_coefE coef_map_id0 ?(int_algC_K 0) ?floor0 //.
by rewrite size_poly_eq -lead_coefE (monicP (cyclotomic_monic _ _)) (intCK 1).
Qed.
Lemma Cintr_Cyclotomic n z :
n.-primitive_root z -> pZtoC 'Phi_n = cyclotomic z n.
Proof.
elim/ltn_ind: n z => n IHn z0 prim_z0.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /=.
have n_gt0 := prim_order_gt0 prim_z0; rewrite prednK // => prim_z.
have [uDn _ inDn] := divisors_correct n_gt0.
pose q := \prod_(d <- rem n (divisors n)) 'Phi_d.
have mon_q: q \is monic by apply: monic_prod => d _; apply: Cyclotomic_monic.
have defXn1: cyclotomic z n * pZtoC q = 'X^n - 1.
rewrite (prod_cyclotomic prim_z) (big_rem n) ?inDn //=.
rewrite divnn n_gt0 rmorph_prod /=; congr (_ * _).
apply: eq_big_seq => d; rewrite mem_rem_uniq ?inE //= inDn => /andP[n'd ddvn].
by rewrite -IHn ?dvdn_prim_root // ltn_neqAle n'd dvdn_leq.
have mapXn1 (R1 R2 : nzRingType) (f : {rmorphism R1 -> R2}):
map_poly f ('X^n - 1) = 'X^n - 1.
- by rewrite rmorphB /= rmorph1 map_polyXn.
have nz_q: pZtoC q != 0.
by rewrite -size_poly_eq0 size_map_inj_poly // size_poly_eq0 monic_neq0.
have [r def_zn]: exists r, cyclotomic z n = pZtoC r.
have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> a; rewrite /= rmorph_int.
have /dvdpP[r0 Dr0]: map_poly ZtoQ q %| 'X^n - 1.
rewrite -(dvdp_map (@ratr algC)) mapXn1 -map_poly_comp.
by rewrite -(eq_map_poly defZtoC) -defXn1 dvdp_mull.
have [r [a nz_a Dr]] := rat_poly_scale r0.
exists (zprimitive r); apply: (mulIf nz_q); rewrite defXn1.
rewrite -rmorphM -(zprimitive_monic mon_q) -zprimitiveM /=.
have ->: r * q = a *: ('X^n - 1).
apply: (map_inj_poly (intr_inj : injective ZtoQ)) => //.
rewrite map_polyZ mapXn1 Dr0 Dr -scalerAl scalerKV ?intr_eq0 //.
by rewrite rmorphM.
by rewrite zprimitiveZ // zprimitive_monic ?monicXnsubC ?mapXn1.
rewrite floorpK; last by apply/polyOverP=> i; rewrite def_zn coef_map /=.
pose f e (k : 'I_n) := Ordinal (ltn_pmod (k * e) n_gt0).
have [e Dz0] := prim_rootP prim_z (prim_expr_order prim_z0).
have co_e_n: coprime e n by rewrite -(prim_root_exp_coprime e prim_z) -Dz0.
have injf: injective (f e).
apply: can_inj (f (egcdn e n).1) _ => k; apply: val_inj => /=.
rewrite modnMml -mulnA -modnMmr -{1}(mul1n e).
by rewrite (chinese_modr co_e_n 0) modnMmr muln1 modn_small.
rewrite [_ n](reindex_inj injf); apply: eq_big => k /=.
by rewrite coprime_modl coprimeMl co_e_n andbT.
by rewrite prim_expr_mod // mulnC exprM -Dz0.
Qed.
Lemma prod_Cyclotomic n :
(n > 0)%N -> \prod_(d <- divisors n) 'Phi_d = 'X^n - 1.
Proof.
move=> n_gt0; have [z prim_z] := C_prim_root_exists n_gt0.
apply: (map_inj_poly (intr_inj : injective ZtoC)) => //.
rewrite rmorphB rmorph1 rmorph_prod /= map_polyXn (prod_cyclotomic prim_z).
apply: eq_big_seq => d; rewrite -dvdn_divisors // => d_dv_n.
by rewrite -Cintr_Cyclotomic ?dvdn_prim_root.
Qed.
Lemma Cyclotomic0 : 'Phi_0 = 1.
Proof.
rewrite /'Phi_0; case: (C_prim_root_exists _) => z /= _.
by rewrite -[1]polyseqK /cyclotomic big_ord0 map_polyE !polyseq1 /= (intCK 1).
Qed.
Lemma size_Cyclotomic n : size 'Phi_n = (totient n).+1.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite Cyclotomic0 polyseq1.
have [z prim_z] := C_prim_root_exists n_gt0.
rewrite -(size_map_inj_poly (can_inj intCK)) //.
by rewrite (Cintr_Cyclotomic prim_z) size_cyclotomic.
Qed.
Lemma minCpoly_cyclotomic n z :
n.-primitive_root z -> minCpoly z = cyclotomic z n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
have Dpz := Cintr_Cyclotomic prim_z; set pz := cyclotomic z n in Dpz *.
have mon_pz: pz \is monic by apply: cyclotomic_monic.
have pz0: root pz z by rewrite root_cyclotomic.
have [pf [Dpf mon_pf] dv_pf] := minCpolyP z.
have /dvdpP_rat_int[f [af nz_af Df] [g /esym Dfg]]: pf %| pZtoQ 'Phi_n.
rewrite -dv_pf; congr (root _ z): pz0; rewrite -Dpz -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
without loss{nz_af} [mon_f mon_g]: af f g Df Dfg / f \is monic /\ g \is monic.
move=> IH; pose cf := lead_coef f; pose cg := lead_coef g.
have cfg1: cf * cg = 1.
by rewrite -lead_coefM Dfg (monicP (Cyclotomic_monic n)).
apply: (IH (af *~ cf) (f *~ cg) (g *~ cf)).
- by rewrite rmorphMz -scalerMzr scalerMzl -mulrzA cfg1.
- by rewrite mulrzAl mulrzAr -mulrzA cfg1.
by rewrite !(intz, =^~ scaler_int) !monicE !lead_coefZ mulrC cfg1.
have{af} Df: pQtoC pf = pZtoC f.
have:= congr1 lead_coef Df.
rewrite lead_coefZ lead_coef_map_inj //; last exact: intr_inj.
rewrite !(monicP _) // mulr1 Df => <-; rewrite scale1r -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
have [/size1_polyC Dg | g_gt1] := leqP (size g) 1.
rewrite monicE Dg lead_coefC in mon_g.
by rewrite -Dpz -Dfg Dg (eqP mon_g) mulr1 Dpf.
have [zk gzk0]: exists zk, root (pZtoC g) zk.
have [rg] := closed_field_poly_normal (pZtoC g).
rewrite lead_coef_map_inj // (monicP mon_g) scale1r => Dg.
rewrite -(size_map_inj_poly (can_inj intCK)) // Dg in g_gt1.
rewrite size_prod_XsubC in g_gt1.
by exists rg`_0; rewrite Dg root_prod_XsubC mem_nth.
have [k cokn Dzk]: exists2 k, coprime k n & zk = z ^+ k.
have: root pz zk by rewrite -Dpz -Dfg rmorphM rootM gzk0 orbT.
rewrite -[pz](big_image _ _ _ _ (fun r => 'X - r%:P)) root_prod_XsubC.
by case/imageP=> k; exists k.
have co_fg (R : idomainType): n%:R != 0 :> R -> @coprimep R (intrp f) (intrp g).
move=> nz_n; have: separable_poly (intrp ('X^n - 1) : {poly R}).
by rewrite rmorphB rmorph1 /= map_polyXn separable_Xn_sub_1.
rewrite -prod_Cyclotomic // (big_rem n) -?dvdn_divisors //= -Dfg.
by rewrite !rmorphM /= !separable_mul => /and3P[] /and3P[].
suffices fzk0: root (pZtoC f) zk.
have [] // := negP (coprimep_root (co_fg _ _) fzk0).
by rewrite pnatr_eq0 -lt0n.
move: gzk0 cokn; rewrite {zk}Dzk; elim/ltn_ind: k => k IHk gzk0 cokn.
have [|k_gt1] := leqP k 1; last have [p p_pr /dvdnP[k1 Dk]] := pdivP k_gt1.
rewrite -[leq k 1](mem_iota 0 2) !inE => /pred2P[k0 | ->]; last first.
by rewrite -Df dv_pf.
have /eqP := size_Cyclotomic n; rewrite -Dfg size_Mmonic ?monic_neq0 //.
rewrite k0 /coprime gcd0n in cokn; rewrite (eqP cokn).
rewrite -(size_map_inj_poly (can_inj intCK)) // -Df -Dpf.
by rewrite -(subnKC g_gt1) -(subnKC (size_minCpoly z)) !addnS.
move: cokn; rewrite Dk coprimeMl => /andP[cok1n].
rewrite prime_coprime // (dvdn_pcharf (pchar_Fp p_pr)) => /co_fg {co_fg}.
have pcharFpX: p \in [pchar {poly 'F_p}] by rewrite (rmorph_pchar polyC) ?pchar_Fp.
rewrite -(coprimep_pexpr _ _ (prime_gt0 p_pr)) -(pFrobenius_autE pcharFpX).
rewrite -[g]comp_polyXr map_comp_poly -horner_map /= pFrobenius_autE -rmorphXn.
rewrite -!map_poly_comp (@eq_map_poly _ _ _ (polyC \o *~%R 1)); last first.
by move=> a; rewrite /= !rmorph_int.
rewrite map_poly_comp -[_.[_]]map_comp_poly /= => co_fg.
suffices: coprimep (pZtoC f) (pZtoC (g \Po 'X^p)).
move/coprimep_root=> /=/(_ (z ^+ k1))/implyP.
rewrite map_comp_poly map_polyXn horner_comp hornerXn.
rewrite -exprM -Dk [_ == 0]gzk0 implybF => /negP[].
have: root pz (z ^+ k1).
by rewrite root_cyclotomic // prim_root_exp_coprime.
rewrite -Dpz -Dfg rmorphM rootM => /orP[] //= /IHk-> //.
rewrite -[k1]muln1 Dk ltn_pmul2l ?prime_gt1 //.
by have:= ltnW k_gt1; rewrite Dk muln_gt0 => /andP[].
suffices: coprimep f (g \Po 'X^p).
case/Bezout_coprimepP=> [[u v]]; rewrite -size_poly_eq1.
rewrite -(size_map_inj_poly (can_inj intCK)) // rmorphD !rmorphM /=.
rewrite size_poly_eq1 => {}co_fg; apply/Bezout_coprimepP.
by exists (pZtoC u, pZtoC v).
apply: contraLR co_fg => /coprimepPn[|d]; first exact: monic_neq0.
rewrite andbC -size_poly_eq1 dvdp_gcd => /and3P[sz_d].
pose d1 := zprimitive d.
have d_dv_mon h: d %| h -> h \is monic -> exists h1, h = d1 * h1.
case/Pdiv.Idomain.dvdpP=> [[c h1] /= nz_c Dh] mon_h; exists (zprimitive h1).
by rewrite -zprimitiveM mulrC -Dh zprimitiveZ ?zprimitive_monic.
case/d_dv_mon=> // f1 Df1 /d_dv_mon[|f2 ->].
rewrite monicE lead_coefE size_comp_poly size_polyXn /=.
rewrite comp_polyE coef_sum polySpred ?monic_neq0 //= mulnC.
rewrite big_ord_recr /= -lead_coefE (monicP mon_g) scale1r.
rewrite -exprM coefXn eqxx big1 ?add0r // => i _.
rewrite coefZ -exprM coefXn eqn_pmul2l ?prime_gt0 //.
by rewrite eqn_leq leqNgt ltn_ord mulr0.
have monFp h: h \is monic -> size (map_poly intr h) = size h.
by move=> mon_h; rewrite size_poly_eq // -lead_coefE (monicP mon_h) oner_eq0.
apply/coprimepPn; last exists (map_poly intr d1).
by rewrite -size_poly_eq0 monFp // size_poly_eq0 monic_neq0.
rewrite Df1 !rmorphM dvdp_gcd !dvdp_mulr //= -size_poly_eq1.
rewrite monFp ?size_zprimitive //.
rewrite monicE [_ d1]intEsg sgz_lead_primitive -zprimitive_eq0 -/d1.
rewrite -lead_coef_eq0 -absz_eq0.
have/esym/eqP := congr1 (absz \o lead_coef) Df1.
by rewrite /= (monicP mon_f) lead_coefM abszM muln_eq1 => /andP[/eqP-> _].
Qed.
|
Torsion.lean
|
/-
Copyright (c) 2022 Julian Berman. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Berman
-/
import Mathlib.GroupTheory.PGroup
import Mathlib.LinearAlgebra.Quotient.Defs
/-!
# Torsion groups
This file defines torsion groups, i.e. groups where all elements have finite order.
## Main definitions
* `Monoid.IsTorsion` a predicate asserting `G` is torsion, i.e. that all
elements are of finite order.
* `CommGroup.torsion G`, the torsion subgroup of an abelian group `G`
* `CommMonoid.torsion G`, the above stated for commutative monoids
* `Monoid.IsTorsionFree`, asserting no nontrivial elements have finite order in `G`
* `AddMonoid.IsTorsion` and `AddMonoid.IsTorsionFree` the additive versions of the above
## Implementation
All torsion monoids are really groups (which is proven here as `Monoid.IsTorsion.group`), but since
the definition can be stated on monoids it is implemented on `Monoid` to match other declarations in
the group theory library.
## Tags
periodic group, aperiodic group, torsion subgroup, torsion abelian group
## Future work
* generalize to π-torsion(-free) groups for a set of primes π
* free, free solvable and free abelian groups are torsion free
* complete direct and free products of torsion free groups are torsion free
* groups which are residually finite p-groups with respect to 2 distinct primes are torsion free
-/
variable {G H : Type*}
namespace Monoid
variable (G) [Monoid G]
/-- A predicate on a monoid saying that all elements are of finite order. -/
@[to_additive
/-- A predicate on an additive monoid saying that all elements are of finite order. -/]
def IsTorsion :=
∀ g : G, IsOfFinOrder g
/-- A monoid is not a torsion monoid if it has an element of infinite order. -/
@[to_additive (attr := simp) /-- An additive monoid is not a torsion monoid if it
has an element of infinite order. -/]
theorem not_isTorsion_iff : ¬IsTorsion G ↔ ∃ g : G, ¬IsOfFinOrder g := by
rw [IsTorsion, not_forall]
end Monoid
open Monoid
/-- Torsion monoids are really groups. -/
@[to_additive /-- Torsion additive monoids are really additive groups -/]
noncomputable def IsTorsion.group [Monoid G] (tG : IsTorsion G) : Group G :=
{ ‹Monoid G› with
inv := fun g => g ^ (orderOf g - 1)
inv_mul_cancel := fun g => by
rw [← pow_succ, tsub_add_cancel_of_le, pow_orderOf_eq_one]
exact (tG g).orderOf_pos }
section Group
variable [Group G] {N : Subgroup G} [Group H]
/-- Subgroups of torsion groups are torsion groups. -/
@[to_additive /-- Subgroups of additive torsion groups are additive torsion groups. -/]
theorem IsTorsion.subgroup (tG : IsTorsion G) (H : Subgroup G) : IsTorsion H := fun h =>
Submonoid.isOfFinOrder_coe.1 <| tG h
/-- The image of a surjective torsion group homomorphism is torsion. -/
@[to_additive AddIsTorsion.of_surjective
/-- The image of a surjective additive torsion group homomorphism is torsion. -/]
theorem IsTorsion.of_surjective {f : G →* H} (hf : Function.Surjective f) (tG : IsTorsion G) :
IsTorsion H := fun h => by
obtain ⟨g, hg⟩ := hf h
rw [← hg]
exact f.isOfFinOrder (tG g)
/-- Torsion groups are closed under extensions. -/
@[to_additive AddIsTorsion.extension_closed
/-- Additive torsion groups are closed under extensions. -/]
theorem IsTorsion.extension_closed {f : G →* H} (hN : N = f.ker) (tH : IsTorsion H)
(tN : IsTorsion N) : IsTorsion G := fun g => by
obtain ⟨ngn, ngnpos, hngn⟩ := (tH <| f g).exists_pow_eq_one
have hmem := MonoidHom.mem_ker.mpr ((f.map_pow g ngn).trans hngn)
lift g ^ ngn to N using hN.symm ▸ hmem with gn h
obtain ⟨nn, nnpos, hnn⟩ := (tN gn).exists_pow_eq_one
exact isOfFinOrder_iff_pow_eq_one.mpr <| ⟨ngn * nn, mul_pos ngnpos nnpos, by
rw [pow_mul, ← h, ← Subgroup.coe_pow, hnn, Subgroup.coe_one]⟩
/-- The image of a quotient is torsion iff the group is torsion. -/
@[to_additive AddIsTorsion.quotient_iff
/-- The image of a quotient is additively torsion iff the group is torsion. -/]
theorem IsTorsion.quotient_iff {f : G →* H} (hf : Function.Surjective f) (hN : N = f.ker)
(tN : IsTorsion N) : IsTorsion H ↔ IsTorsion G :=
⟨fun tH => IsTorsion.extension_closed hN tH tN, fun tG => IsTorsion.of_surjective hf tG⟩
/-- If a group exponent exists, the group is torsion. -/
@[to_additive ExponentExists.is_add_torsion
/-- If a group exponent exists, the group is additively torsion. -/]
theorem ExponentExists.isTorsion (h : ExponentExists G) : IsTorsion G := fun g => by
obtain ⟨n, npos, hn⟩ := h
exact isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, hn g⟩
/-- The group exponent exists for any bounded torsion group. -/
@[to_additive IsAddTorsion.exponentExists
/-- The group exponent exists for any bounded additive torsion group. -/]
theorem IsTorsion.exponentExists (tG : IsTorsion G)
(bounded : (Set.range fun g : G => orderOf g).Finite) : ExponentExists G :=
exponent_ne_zero.mp <|
(exponent_ne_zero_iff_range_orderOf_finite fun g => (tG g).orderOf_pos).mpr bounded
/-- Finite groups are torsion groups. -/
@[to_additive is_add_torsion_of_finite /-- Finite additive groups are additive torsion groups. -/]
theorem isTorsion_of_finite [Finite G] : IsTorsion G :=
ExponentExists.isTorsion .of_finite
end Group
section CommGroup
variable [CommGroup G]
/-- A nontrivial torsion abelian group is not torsion-free. -/
@[to_additive /-- A nontrivial additive torsion abelian group is not torsion-free. -/]
lemma not_isMulTorsionFree_of_isTorsion [Nontrivial G] (hG : IsTorsion G) : ¬ IsMulTorsionFree G :=
not_isMulTorsionFree_iff_isOfFinOrder.2 <| let ⟨x, hx⟩ := exists_ne (1 : G); ⟨x, hx, hG x⟩
/-- A nontrivial torsion-free abelian group is not torsion. -/
@[to_additive /-- A nontrivial additive torsion-free abelian group is not torsion. -/]
lemma not_isTorsion_of_isMulTorsionFree [Nontrivial G] [IsMulTorsionFree G] : ¬ IsTorsion G :=
(not_isMulTorsionFree_of_isTorsion · ‹_›)
end CommGroup
section Module
-- A (semi/)ring of scalars and a commutative monoid of elements
variable (R M : Type*) [AddCommMonoid M]
namespace AddMonoid
/-- A module whose scalars are additively torsion is additively torsion. -/
theorem IsTorsion.module_of_torsion [Semiring R] [Module R M] (tR : IsTorsion R) : IsTorsion M :=
fun f =>
isOfFinAddOrder_iff_nsmul_eq_zero.mpr <| by
obtain ⟨n, npos, hn⟩ := (tR 1).exists_nsmul_eq_zero
exact ⟨n, npos, by simp only [← Nat.cast_smul_eq_nsmul R _ f, ← nsmul_one, hn, zero_smul]⟩
/-- A module with a finite ring of scalars is additively torsion. -/
theorem IsTorsion.module_of_finite [Ring R] [Finite R] [Module R M] : IsTorsion M :=
(is_add_torsion_of_finite : IsTorsion R).module_of_torsion _ _
end AddMonoid
end Module
section CommMonoid
variable (G) [CommMonoid G]
namespace CommMonoid
/-- The torsion submonoid of a commutative monoid.
(Note that by `Monoid.IsTorsion.group` torsion monoids are truthfully groups.)
-/
@[to_additive addTorsion /-- The torsion submonoid of an additive commutative monoid. -/]
def torsion : Submonoid G where
carrier := { x | IsOfFinOrder x }
one_mem' := IsOfFinOrder.one
mul_mem' hx hy := hx.mul hy
variable {G}
/-- Torsion submonoids are torsion. -/
@[to_additive /-- Additive torsion submonoids are additively torsion. -/]
theorem torsion.isTorsion : IsTorsion <| torsion G := fun ⟨x, n, npos, hn⟩ =>
⟨n, npos,
Subtype.ext <| by
dsimp
rw [mul_left_iterate]
change _ * 1 = 1
rw [_root_.mul_one, SubmonoidClass.coe_pow, Subtype.coe_mk,
(isPeriodicPt_mul_iff_pow_eq_one _).mp hn]⟩
variable (G) (p : ℕ) [hp : Fact p.Prime]
/-- The `p`-primary component is the submonoid of elements with order prime-power of `p`. -/
@[to_additive (attr := simps)
/-- The `p`-primary component is the submonoid of elements with additive
order prime-power of `p`. -/]
def primaryComponent : Submonoid G where
carrier := { g | ∃ n : ℕ, orderOf g = p ^ n }
one_mem' := ⟨0, by rw [pow_zero, orderOf_one]⟩
mul_mem' hg₁ hg₂ :=
exists_orderOf_eq_prime_pow_iff.mpr <| by
obtain ⟨m, hm⟩ := exists_orderOf_eq_prime_pow_iff.mp hg₁
obtain ⟨n, hn⟩ := exists_orderOf_eq_prime_pow_iff.mp hg₂
exact
⟨m + n, by
rw [mul_pow, pow_add, pow_mul, hm, one_pow, Monoid.one_mul, mul_comm, pow_mul, hn,
one_pow]⟩
variable {G} {p}
/-- Elements of the `p`-primary component have order `p^n` for some `n`. -/
@[to_additive primaryComponent.exists_orderOf_eq_prime_nsmul
/-- Elements of the `p`-primary component have additive order `p^n` for some `n` -/]
theorem primaryComponent.exists_orderOf_eq_prime_pow (g : CommMonoid.primaryComponent G p) :
∃ n : ℕ, orderOf g = p ^ n := by
obtain ⟨_, hn⟩ := g.property
rw [orderOf_submonoid g] at hn
exact ⟨_, hn⟩
/-- The `p`- and `q`-primary components are disjoint for `p ≠ q`. -/
@[to_additive /-- The `p`- and `q`-primary components are disjoint for `p ≠ q`. -/]
theorem primaryComponent.disjoint {p' : ℕ} [hp' : Fact p'.Prime] (hne : p ≠ p') :
Disjoint (CommMonoid.primaryComponent G p) (CommMonoid.primaryComponent G p') :=
Submonoid.disjoint_def.mpr <| by
rintro g ⟨_ | n, hn⟩ ⟨n', hn'⟩
· rwa [pow_zero, orderOf_eq_one_iff] at hn
· exact
absurd (eq_of_prime_pow_eq hp.out.prime hp'.out.prime n.succ_pos (hn.symm.trans hn')) hne
end CommMonoid
open CommMonoid (torsion)
namespace Monoid.IsTorsion
variable {G}
/-- The torsion submonoid of a torsion monoid is `⊤`. -/
@[to_additive (attr := simp)
/-- The additive torsion submonoid of an additive torsion monoid is `⊤`. -/]
theorem torsion_eq_top (tG : IsTorsion G) : torsion G = ⊤ := by ext; tauto
/-- A torsion monoid is isomorphic to its torsion submonoid. -/
@[to_additive /-- An additive torsion monoid is isomorphic to its torsion submonoid. -/]
def torsionMulEquiv (tG : IsTorsion G) : torsion G ≃* G :=
(MulEquiv.submonoidCongr tG.torsion_eq_top).trans Submonoid.topEquiv
@[to_additive]
theorem torsionMulEquiv_apply (tG : IsTorsion G) (a : torsion G) :
tG.torsionMulEquiv a = MulEquiv.submonoidCongr tG.torsion_eq_top a :=
rfl
@[to_additive]
theorem torsionMulEquiv_symm_apply_coe (tG : IsTorsion G) (a : G) :
tG.torsionMulEquiv.symm a = ⟨Submonoid.topEquiv.symm a, tG _⟩ :=
rfl
end Monoid.IsTorsion
/-- Torsion submonoids of a torsion submonoid are isomorphic to the submonoid. -/
@[to_additive (attr := simp) AddCommMonoid.Torsion.ofTorsion
/-- Additive torsion submonoids of an additive torsion submonoid are
isomorphic to the submonoid. -/]
def Torsion.ofTorsion : torsion (torsion G) ≃* torsion G :=
Monoid.IsTorsion.torsionMulEquiv CommMonoid.torsion.isTorsion
end CommMonoid
section CommGroup
variable (G) [CommGroup G]
namespace CommGroup
/-- The torsion subgroup of an abelian group. -/
@[to_additive /-- The torsion subgroup of an additive abelian group. -/]
def torsion : Subgroup G :=
{ CommMonoid.torsion G with inv_mem' := fun hx => IsOfFinOrder.inv hx }
/-- The torsion submonoid of an abelian group equals the torsion subgroup as a submonoid. -/
@[to_additive add_torsion_eq_add_torsion_submonoid
/-- The additive torsion submonoid of an abelian group equals the torsion
subgroup as a submonoid. -/]
theorem torsion_eq_torsion_submonoid : CommMonoid.torsion G = (torsion G).toSubmonoid :=
rfl
@[to_additive]
theorem mem_torsion (g : G) : g ∈ torsion G ↔ IsOfFinOrder g := Iff.rfl
@[to_additive]
lemma isMulTorsionFree_iff_torsion_eq_bot : IsMulTorsionFree G ↔ CommGroup.torsion G = ⊥ := by
rw [isMulTorsionFree_iff_not_isOfFinOrder, eq_bot_iff, SetLike.le_def]
simp [not_imp_not, CommGroup.mem_torsion]
variable (p : ℕ) [hp : Fact p.Prime]
/-- The `p`-primary component is the subgroup of elements with order prime-power of `p`. -/
@[to_additive (attr := simps!)
/-- The `p`-primary component is the subgroup of elements with additive order
prime-power of `p`. -/]
def primaryComponent : Subgroup G :=
{ CommMonoid.primaryComponent G p with
inv_mem' := fun {g} ⟨n, hn⟩ => ⟨n, (orderOf_inv g).trans hn⟩ }
variable {G} {p}
/-- The `p`-primary component is a `p` group. -/
theorem primaryComponent.isPGroup : IsPGroup p <| primaryComponent G p := fun g =>
(propext exists_orderOf_eq_prime_pow_iff.symm).mpr
(CommMonoid.primaryComponent.exists_orderOf_eq_prime_pow g)
end CommGroup
end CommGroup
namespace Monoid
section Monoid
variable (G) [Monoid G]
/-- A predicate on a monoid saying that only 1 is of finite order.
This definition is mathematically incorrect for monoids which are not groups.
Please use `IsMulTorsionFree` instead. -/
@[to_additive /-- A predicate on an additive monoid saying that only 0 is of finite order.
This definition is mathematically incorrect for monoids which are not groups.
Please use `IsAddTorsionFree` instead. -/]
def IsTorsionFree :=
∀ g : G, g ≠ 1 → ¬IsOfFinOrder g
attribute [deprecated IsMulTorsionFree (since := "2025-04-23")] Monoid.IsTorsionFree
attribute [deprecated IsAddTorsionFree (since := "2025-04-23")] AddMonoid.IsTorsionFree
variable {G}
set_option linter.deprecated false in
/-- A nontrivial monoid is not torsion-free if any nontrivial element has finite order. -/
@[to_additive (attr := deprecated not_isMulTorsionFree_iff_isOfFinOrder (since := "2025-04-23"))
/-- An additive monoid is not torsion free if any nontrivial element has finite order. -/]
theorem not_isTorsionFree_iff : ¬IsTorsionFree G ↔ ∃ g : G, g ≠ 1 ∧ IsOfFinOrder g := by
simp_rw [IsTorsionFree, Ne, not_forall, Classical.not_not, exists_prop]
set_option linter.deprecated false in
@[to_additive (attr := deprecated Subsingleton.to_isMulTorsionFree (since := "2025-04-23"))]
lemma isTorsionFree_of_subsingleton [Subsingleton G] : IsTorsionFree G :=
fun _a ha _ => ha <| Subsingleton.elim _ _
set_option linter.deprecated false in
@[to_additive
(attr := deprecated CommGroup.isMulTorsionFree_iff_torsion_eq_bot (since := "2025-04-23"))]
lemma isTorsionFree_iff_torsion_eq_bot {G} [CommGroup G] :
IsTorsionFree G ↔ CommGroup.torsion G = ⊥ := by
rw [IsTorsionFree, eq_bot_iff, SetLike.le_def]
simp [not_imp_not, CommGroup.mem_torsion]
end Monoid
section Group
variable [Group G]
set_option linter.deprecated false in
/-- A nontrivial torsion group is not torsion-free. -/
@[to_additive (attr := deprecated not_isMulTorsionFree_of_isTorsion (since := "2025-04-23"))
/-- A nontrivial additive torsion group is not torsion-free. -/]
theorem IsTorsion.not_torsion_free [hN : Nontrivial G] : IsTorsion G → ¬IsTorsionFree G := fun tG =>
not_isTorsionFree_iff.mpr <| by
obtain ⟨x, hx⟩ := (nontrivial_iff_exists_ne (1 : G)).mp hN
exact ⟨x, hx, tG x⟩
set_option linter.deprecated false in
/-- A nontrivial torsion-free group is not torsion. -/
@[to_additive (attr := deprecated not_isTorsion_of_isMulTorsionFree (since := "2025-04-23"))
/-- A nontrivial torsion-free additive group is not torsion. -/]
theorem IsTorsionFree.not_torsion [hN : Nontrivial G] : IsTorsionFree G → ¬IsTorsion G := fun tfG =>
(not_isTorsion_iff _).mpr <| by
obtain ⟨x, hx⟩ := (nontrivial_iff_exists_ne (1 : G)).mp hN
exact ⟨x, (tfG x) hx⟩
set_option linter.deprecated false in
/-- Subgroups of torsion-free groups are torsion-free. -/
@[to_additive (attr := deprecated Subgroup.instIsMulTorsionFree (since := "2025-04-23"))
/-- Subgroups of additive torsion-free groups are additively torsion-free. -/]
theorem IsTorsionFree.subgroup (tG : IsTorsionFree G) (H : Subgroup G) : IsTorsionFree H :=
fun h hne ↦ Submonoid.isOfFinOrder_coe.not.1 <| tG h <| by norm_cast
set_option linter.deprecated false in
/-- Direct products of torsion free groups are torsion free. -/
@[to_additive (attr := deprecated Pi.instIsMulTorsionFree (since := "2025-04-23"))
AddMonoid.IsTorsionFree.prod
/-- Direct products of additive torsion free groups are torsion free. -/]
theorem IsTorsionFree.prod {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)]
(tfGs : ∀ i, IsTorsionFree (Gs i)) : IsTorsionFree <| ∀ i, Gs i := fun w hne h =>
hne <|
funext fun i => Classical.not_not.mp <| mt (tfGs i (w i)) <| Classical.not_not.mpr <| h.apply i
end Group
section CommGroup
open Monoid (IsTorsionFree)
open CommGroup (torsion)
variable (G) [CommGroup G]
/-- Quotienting a group by its torsion subgroup yields a torsion-free group. -/
@[to_additive
/-- Quotienting a group by its additive torsion subgroup yields an additive torsion-free group. -/]
instance _root_.QuotientGroup.instIsMulTorsionFree : IsMulTorsionFree <| G ⧸ torsion G := by
refine .of_not_isOfFinOrder fun g hne hfin ↦ hne ?_
obtain ⟨g⟩ := g
obtain ⟨m, mpos, hm⟩ := hfin.exists_pow_eq_one
obtain ⟨n, npos, hn⟩ := ((QuotientGroup.eq_one_iff _).mp hm).exists_pow_eq_one
exact (QuotientGroup.eq_one_iff g).mpr
(isOfFinOrder_iff_pow_eq_one.mpr ⟨m * n, mul_pos mpos npos, (pow_mul g m n).symm ▸ hn⟩)
set_option linter.deprecated false in
/-- Quotienting a group by its torsion subgroup yields a torsion free group. -/
@[to_additive
(attr := deprecated QuotientGroup.instIsMulTorsionFree (since := "2025-04-23"))
/-- Quotienting a group by its additive torsion subgroup yields an additive torsion free group. -/]
theorem IsTorsionFree.quotient_torsion : IsTorsionFree <| G ⧸ torsion G := fun g hne hfin =>
hne <| by
obtain ⟨g⟩ := g
obtain ⟨m, mpos, hm⟩ := hfin.exists_pow_eq_one
obtain ⟨n, npos, hn⟩ := ((QuotientGroup.eq_one_iff _).mp hm).exists_pow_eq_one
exact
(QuotientGroup.eq_one_iff g).mpr
(isOfFinOrder_iff_pow_eq_one.mpr ⟨m * n, mul_pos mpos npos, (pow_mul g m n).symm ▸ hn⟩)
end CommGroup
end Monoid
namespace AddMonoid
set_option linter.deprecated false in
@[deprecated noZeroSMulDivisors_nat_iff_isAddTorsionFree (since := "2025-04-23")]
lemma isTorsionFree_iff_noZeroSMulDivisors_nat {M : Type*} [AddMonoid M] :
IsTorsionFree M ↔ NoZeroSMulDivisors ℕ M := by
simp_rw [AddMonoid.IsTorsionFree, isOfFinAddOrder_iff_nsmul_eq_zero, not_exists, not_and,
pos_iff_ne_zero, noZeroSMulDivisors_iff, forall_swap (β := ℕ)]
exact forall₂_congr fun _ _ ↦ by tauto
set_option linter.deprecated false in
@[deprecated noZeroSMulDivisors_int_iff_isAddTorsionFree (since := "2025-04-23")]
lemma isTorsionFree_iff_noZeroSMulDivisors_int [SubtractionMonoid G] :
IsTorsionFree G ↔ NoZeroSMulDivisors ℤ G := by
simp_rw [AddMonoid.IsTorsionFree, isOfFinAddOrder_iff_zsmul_eq_zero, not_exists, not_and,
noZeroSMulDivisors_iff, forall_swap (β := ℤ)]
exact forall₂_congr fun _ _ ↦ by tauto
set_option linter.deprecated false in
@[deprecated IsAddTorsionFree.of_noZeroSMulDivisors_nat (since := "2025-04-23")]
lemma IsTorsionFree.of_noZeroSMulDivisors {M : Type*} [AddMonoid M] [NoZeroSMulDivisors ℕ M] :
IsTorsionFree M := isTorsionFree_iff_noZeroSMulDivisors_nat.2 ‹_›
@[deprecated IsAddTorsionFree.to_noZeroSMulDivisors_nat (since := "2025-04-23")]
alias ⟨IsTorsionFree.noZeroSMulDivisors_nat, _⟩ := isTorsionFree_iff_noZeroSMulDivisors_nat
@[deprecated IsAddTorsionFree.to_noZeroSMulDivisors_int (since := "2025-04-23")]
alias ⟨IsTorsionFree.noZeroSMulDivisors_int, _⟩ := isTorsionFree_iff_noZeroSMulDivisors_int
end AddMonoid
section AddCommGroup
instance {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] :
Module R (M ⧸ AddCommGroup.torsion M) :=
letI : Submodule R M := { AddCommGroup.torsion M with smul_mem' := fun r m ⟨n, hn, hn'⟩ ↦
⟨n, hn, by { simp only [Function.IsPeriodicPt, Function.IsFixedPt, add_left_iterate, add_zero,
smul_comm n] at hn' ⊢; simp only [hn', smul_zero] }⟩ }
inferInstanceAs (Module R (M ⧸ this))
end AddCommGroup
section
variable {M : Type*} [CommMonoid M] [HasDistribNeg M]
theorem neg_one_mem_torsion : -1 ∈ CommMonoid.torsion M :=
⟨2, zero_lt_two, (isPeriodicPt_mul_iff_pow_eq_one _).mpr (by simp)⟩
end
|
Module.lean
|
/-
Copyright (c) 2022 Dylan MacKenzie. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dylan MacKenzie
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.Module.Defs
import Mathlib.Tactic.Abel
/-!
# Summation by parts
-/
namespace Finset
variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] (f : ℕ → R) (g : ℕ → M) {m n : ℕ}
-- The partial sum of `g`, starting from zero
local notation "G " n:80 => ∑ i ∈ range n, g i
/-- **Summation by parts**, also known as **Abel's lemma** or an **Abel transformation** -/
theorem sum_Ico_by_parts (hmn : m < n) :
∑ i ∈ Ico m n, f i • g i =
f (n - 1) • G n - f m • G m - ∑ i ∈ Ico m (n - 1), (f (i + 1) - f i) • G (i + 1) := by
have h₁ : (∑ i ∈ Ico (m + 1) n, f i • G i) = ∑ i ∈ Ico m (n - 1), f (i + 1) • G (i + 1) := by
rw [← Nat.sub_add_cancel (Nat.one_le_of_lt hmn), ← sum_Ico_add']
simp only [add_tsub_cancel_right]
have h₂ :
(∑ i ∈ Ico (m + 1) n, f i • G (i + 1)) =
(∑ i ∈ Ico m (n - 1), f i • G (i + 1)) + f (n - 1) • G n - f m • G (m + 1) := by
rw [← sum_Ico_sub_bot _ hmn, ← sum_Ico_succ_sub_top _ (Nat.le_sub_one_of_lt hmn),
Nat.sub_add_cancel (pos_of_gt hmn), sub_add_cancel]
rw [sum_eq_sum_Ico_succ_bot hmn]
conv in (occs := 3) (f _ • g _) => rw [← sum_range_succ_sub_sum g]
simp_rw [smul_sub, sum_sub_distrib, h₂, h₁]
conv_lhs => congr; rfl; rw [← add_sub, add_comm, ← add_sub, ← sum_sub_distrib]
have : ∀ i, f i • G (i + 1) - f (i + 1) • G (i + 1) = -((f (i + 1) - f i) • G (i + 1)) := by
intro i
rw [sub_smul]
abel
simp_rw [this, sum_neg_distrib, sum_range_succ, smul_add]
abel
theorem sum_Ioc_by_parts (hmn : m < n) :
∑ i ∈ Ioc m n, f i • g i =
f n • G (n + 1) - f (m + 1) • G (m + 1)
- ∑ i ∈ Ioc m (n - 1), (f (i + 1) - f i) • G (i + 1) := by
simpa only [← Ico_add_one_add_one_eq_Ioc, Nat.sub_add_cancel (Nat.one_le_of_lt hmn),
add_tsub_cancel_right] using sum_Ico_by_parts f g (Nat.succ_lt_succ hmn)
variable (n)
/-- **Summation by parts** for ranges -/
theorem sum_range_by_parts :
∑ i ∈ range n, f i • g i =
f (n - 1) • G n - ∑ i ∈ range (n - 1), (f (i + 1) - f i) • G (i + 1) := by
by_cases hn : n = 0
· simp [hn]
· rw [range_eq_Ico, sum_Ico_by_parts f g (Nat.pos_of_ne_zero hn), sum_range_zero, smul_zero,
sub_zero, range_eq_Ico]
end Finset
|
center.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import fintype bigop finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient action gproduct gfunctor.
From mathcomp Require Import cyclic.
(******************************************************************************)
(* Definition of the center of a group and of external central products: *)
(* 'Z(G) == the center of the group G, i.e., 'C_G(G). *)
(* cprod_by isoZ == the finGroupType for the central product of H and K *)
(* with centers identified by the isomorphism gz on 'Z(H); *)
(* here isoZ : isom 'Z(H) 'Z(K) gz. Note that the actual *)
(* central product is [set: cprod_by isoZ]. *)
(* cpairg1 isoZ == the isomorphism from H to cprod_by isoZ, isoZ as above. *)
(* cpair1g isoZ == the isomorphism from K to cprod_by isoZ, isoZ as above. *)
(* xcprod H K == the finGroupType for the external central product of H *)
(* and K with identified centers, provided the dynamically *)
(* tested condition 'Z(H) \isog 'Z(K) holds. *)
(* ncprod H n == the finGroupType for the central product of n copies of *)
(* H with their centers identified; [set: ncprod H 0] is *)
(* isomorphic to 'Z(H). *)
(* xcprodm cf eqf == the morphism induced on cprod_by isoZ, where as above *)
(* isoZ : isom 'Z(H) 'Z(K) gz, by fH : {morphism H >-> rT} *)
(* and fK : {morphism K >-> rT}, given both *)
(* cf : fH @* H \subset 'C(fK @* K) and *)
(* eqf : {in 'Z(H), fH =1 fK \o gz}. *)
(* Following Aschbacher, we only provide external central products with *)
(* identified centers, as these are well defined provided the local center *)
(* isomorphism group of one of the subgroups is full. Nevertheless the *)
(* entire construction could be carried out under the weaker assumption that *)
(* gz is an isomorphism between subgroups of 'Z(H) and 'Z(K), and even the *)
(* uniqueness theorem holds under the weaker assumption that gz map 'Z(H) to *)
(* a characteristic subgroup of 'Z(K) not isomorphic to any other subgroup of *)
(* 'Z(K), a condition that holds for example when K is cyclic, as in the *)
(* structure theorem for p-groups of symplectic type. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Defs.
Variable gT : finGroupType.
Definition center (A : {set gT}) := 'C_A(A).
Canonical center_group (G : {group gT}) : {group gT} :=
Eval hnf in [group of center G].
End Defs.
Arguments center {gT} A%_g.
Notation "''Z' ( A )" := (center A) : group_scope.
Notation "''Z' ( H )" := (center_group H) : Group_scope.
Lemma morphim_center : GFunctor.pcontinuous (@center).
Proof. by move=> gT rT G D f; apply: morphim_subcent. Qed.
Canonical center_igFun := [igFun by fun _ _ => subsetIl _ _ & morphim_center].
Canonical center_gFun := [gFun by morphim_center].
Canonical center_pgFun := [pgFun by morphim_center].
Section Center.
Variables gT : finGroupType.
Implicit Type rT : finGroupType.
Implicit Types (x y : gT) (A B : {set gT}) (G H K D : {group gT}).
Lemma subcentP A B x : reflect (x \in A /\ centralises x B) (x \in 'C_A(B)).
Proof.
rewrite inE. case: (x \in A); last by right; case.
by apply: (iffP centP) => [|[]].
Qed.
Lemma subcent_sub A B : 'C_A(B) \subset 'N_A(B).
Proof. by rewrite setIS ?cent_sub. Qed.
Lemma subcent_norm G B : 'N_G(B) \subset 'N('C_G(B)).
Proof. by rewrite normsI ?subIset ?normG // orbC cent_norm. Qed.
Lemma subcent_normal G B : 'C_G(B) <| 'N_G(B).
Proof. by rewrite /normal subcent_sub subcent_norm. Qed.
Lemma subcent_char G H K : H \char G -> K \char G -> 'C_H(K) \char G.
Proof.
case/charP=> sHG chHG /charP[sKG chKG]; apply/charP.
split=> [|f injf Gf]; first by rewrite subIset ?sHG.
by rewrite injm_subcent ?chHG ?chKG.
Qed.
Lemma centerP A x : reflect (x \in A /\ centralises x A) (x \in 'Z(A)).
Proof. exact: subcentP. Qed.
Lemma center_sub A : 'Z(A) \subset A.
Proof. exact: subsetIl. Qed.
Lemma center1 : 'Z(1) = 1 :> {set gT}.
Proof. exact: gF1. Qed.
Lemma centerC A : {in A, centralised 'Z(A)}.
Proof. by apply/centsP; rewrite centsC subsetIr. Qed.
Lemma center_normal G : 'Z(G) <| G.
Proof. exact: gFnormal. Qed.
Lemma sub_center_normal H G : H \subset 'Z(G) -> H <| G.
Proof. by rewrite subsetI centsC /normal => /andP[-> /cents_norm]. Qed.
Lemma center_abelian G : abelian 'Z(G).
Proof. by rewrite /abelian subIset // centsC subIset // subxx orbT. Qed.
Lemma center_char G : 'Z(G) \char G.
Proof. exact: gFchar. Qed.
Lemma center_idP A : reflect ('Z(A) = A) (abelian A).
Proof. exact: setIidPl. Qed.
Lemma center_class_formula G :
#|G| = #|'Z(G)| + \sum_(xG in [set x ^: G | x in G :\: 'C(G)]) #|xG|.
Proof.
by rewrite acts_sum_card_orbit ?cardsID // astabsJ normsD ?norms_cent ?normG.
Qed.
Lemma subcent1P A x y : reflect (y \in A /\ commute x y) (y \in 'C_A[x]).
Proof.
rewrite inE; case: (y \in A); last by right; case.
by apply: (iffP cent1P) => [|[]].
Qed.
Lemma subcent1_id x G : x \in G -> x \in 'C_G[x].
Proof. by move=> Gx; rewrite inE Gx; apply/cent1P. Qed.
Lemma subcent1_sub x G : 'C_G[x] \subset G.
Proof. exact: subsetIl. Qed.
Lemma subcent1C x y G : x \in G -> y \in 'C_G[x] -> x \in 'C_G[y].
Proof. by move=> Gx /subcent1P[_ cxy]; apply/subcent1P. Qed.
Lemma subcent1_cycle_sub x G : x \in G -> <[x]> \subset 'C_G[x].
Proof. by move=> Gx; rewrite cycle_subG ?subcent1_id. Qed.
Lemma subcent1_cycle_norm x G : 'C_G[x] \subset 'N(<[x]>).
Proof. by rewrite cents_norm // cent_gen cent_set1 subsetIr. Qed.
Lemma subcent1_cycle_normal x G : x \in G -> <[x]> <| 'C_G[x].
Proof.
by move=> Gx; rewrite /normal subcent1_cycle_norm subcent1_cycle_sub.
Qed.
(* Gorenstein. 1.3.4 *)
Lemma cyclic_center_factor_abelian G : cyclic (G / 'Z(G)) -> abelian G.
Proof.
case/cyclicP=> a Ga; case: (cosetP a) => /= z Nz def_a.
have G_Zz: G :=: 'Z(G) * <[z]>.
rewrite -quotientK ?cycle_subG ?quotient_cycle //=.
by rewrite -def_a -Ga quotientGK // center_normal.
rewrite G_Zz abelianM cycle_abelian center_abelian centsC /= G_Zz.
by rewrite subIset ?centS ?orbT ?mulG_subr.
Qed.
Lemma cyclic_factor_abelian H G :
H \subset 'Z(G) -> cyclic (G / H) -> abelian G.
Proof.
move=> sHZ cycGH; apply: cyclic_center_factor_abelian.
have /andP[_ nHG]: H <| G := sub_center_normal sHZ.
have [f <-]:= homgP (homg_quotientS nHG (gFnorm _ G) sHZ).
exact: morphim_cyclic cycGH.
Qed.
Section Injm.
Variables (rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma injm_center G : G \subset D -> f @* 'Z(G) = 'Z(f @* G).
Proof. exact: injm_subcent. Qed.
End Injm.
End Center.
Arguments center_idP {gT A}.
Lemma isog_center (aT rT : finGroupType) (G : {group aT}) (H : {group rT}) :
G \isog H -> 'Z(G) \isog 'Z(H).
Proof. exact: gFisog. Qed.
Section Product.
Variable gT : finGroupType.
Implicit Types (A B C : {set gT}) (G H K : {group gT}).
Lemma center_prod H K : K \subset 'C(H) -> 'Z(H) * 'Z(K) = 'Z(H * K).
Proof.
move=> cHK; apply/setP=> z; rewrite {3}/center centM !inE.
have cKH: H \subset 'C(K) by rewrite centsC.
apply/imset2P/and3P=> [[x y /setIP[Hx cHx] /setIP[Ky cKy] ->{z}]| []].
by rewrite imset2_f ?groupM // ?(subsetP cHK) ?(subsetP cKH).
case/imset2P=> x y Hx Ky ->{z}.
rewrite groupMr => [cHx|]; last exact: subsetP Ky.
rewrite groupMl => [cKy|]; last exact: subsetP Hx.
by exists x y; rewrite ?inE ?Hx ?Ky.
Qed.
Lemma center_cprod A B G : A \* B = G -> 'Z(A) \* 'Z(B) = 'Z(G).
Proof.
case/cprodP => [[H K -> ->] <- cHK].
rewrite cprodE ?center_prod //= subIset ?(subset_trans cHK) //.
by rewrite centS ?center_sub.
Qed.
Lemma center_bigcprod I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G).
Proof.
elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //.
case/cprodP: dG IHA IHB (dG) => [[H K -> ->] _ _] IHH IHK dG.
by rewrite (IHH H) // (IHK K) // (center_cprod dG).
Qed.
Lemma cprod_center_id G : G \* 'Z(G) = G.
Proof. by rewrite cprodE ?subsetIr // mulGSid ?center_sub. Qed.
Lemma center_dprod A B G : A \x B = G -> 'Z(A) \x 'Z(B) = 'Z(G).
Proof.
case/dprodP=> [[H1 H2 -> ->] defG cH12 trH12].
move: defG; rewrite -cprodE // => /center_cprod/cprodP[_ /= <- cZ12].
by apply: dprodE; rewrite //= setIAC setIA -setIA trH12 (setIidPl _) ?sub1G.
Qed.
Lemma center_bigdprod I r P (F: I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) 'Z(F i) = 'Z(G).
Proof.
elim/big_ind2: _ G => [_ <-|A B C D IHA IHB G dG|_ _ G ->]; rewrite ?center1 //.
case/dprodP: dG IHA IHB (dG) => [[H K -> ->] _ _ _] IHH IHK dG.
by rewrite (IHH H) // (IHK K) // (center_dprod dG).
Qed.
Lemma Aut_cprod_full G H K :
H \* K = G -> 'Z(H) = 'Z(K) ->
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) ->
Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G).
Proof.
move=> defG eqZHK; have [_ defHK cHK] := cprodP defG.
have defZ: 'Z(G) = 'Z(H) by rewrite -defHK -center_prod // eqZHK mulGid.
have ziHK: H :&: K = 'Z(K).
by apply/eqP; rewrite eqEsubset subsetI -{1 2}eqZHK !center_sub setIS.
have AutZP := Aut_sub_fullP (@center_sub gT _).
move/AutZP=> AutZHfull /AutZP AutZKfull; apply/AutZP=> g injg gZ.
have [gH [def_gH ker_gH _ im_gH]] := domP g defZ.
have [gK [def_gK ker_gK _ im_gK]] := domP g (etrans defZ eqZHK).
have [injgH injgK]: 'injm gH /\ 'injm gK by rewrite ker_gH ker_gK.
have [gHH gKK]: gH @* 'Z(H) = 'Z(H) /\ gK @* 'Z(K) = 'Z(K).
by rewrite im_gH im_gK -eqZHK -defZ.
have [|fH [injfH im_fH fHZ]] := AutZHfull gH injgH.
by rewrite im_gH /= -defZ.
have [|fK [injfK im_fK fKZ]] := AutZKfull gK injgK.
by rewrite im_gK /= -eqZHK -defZ.
have cfHK: fK @* K \subset 'C(fH @* H) by rewrite im_fH im_fK.
have eq_fHK: {in H :&: K, fH =1 fK}.
by move=> z; rewrite ziHK => Zz; rewrite fHZ ?fKZ /= ?eqZHK // def_gH def_gK.
exists (cprodm_morphism defG cfHK eq_fHK).
rewrite injm_cprodm injfH injfK im_cprodm im_fH im_fK defHK.
rewrite -morphimIdom ziHK -eqZHK injm_center // im_fH eqxx.
split=> //= z; rewrite {1}defZ => Zz; have [Hz _] := setIP Zz.
by rewrite cprodmEl // fHZ // def_gH.
Qed.
End Product.
Section CprodBy.
Variables gTH gTK : finGroupType.
Variables (H : {group gTH}) (K : {group gTK}) (gz : {morphism 'Z(H) >-> gTK}).
Definition ker_cprod_by of isom 'Z(H) 'Z(K) gz :=
[set xy | let: (x, y) := xy in (x \in 'Z(H)) && (y == (gz x)^-1)].
Hypothesis isoZ : isom 'Z(H) 'Z(K) gz.
Let kerHK := ker_cprod_by isoZ.
Let injgz : 'injm gz. Proof. by case/isomP: isoZ. Qed.
Let gzZ : gz @* 'Z(H) = 'Z(K). Proof. by case/isomP: isoZ. Qed.
Let gzZchar : gz @* 'Z(H) \char 'Z(K). Proof. by rewrite gzZ. Qed.
Let sgzZZ : gz @* 'Z(H) \subset 'Z(K) := char_sub gzZchar.
Let sZH := center_sub H.
Let sZK := center_sub K.
Let sgzZG : gz @* 'Z(H) \subset K := subset_trans sgzZZ sZK.
Lemma ker_cprod_by_is_group : group_set kerHK.
Proof.
apply/group_setP; rewrite inE /= group1 morph1 invg1 /=.
split=> // [[x1 y1] [x2 y2]].
rewrite inE /= => /andP[Zx1 /eqP->]; have [_ cGx1] := setIP Zx1.
rewrite inE /= => /andP[Zx2 /eqP->]; have [Gx2 _] := setIP Zx2.
by rewrite inE /= groupM //= -invMg (centP cGx1) // morphM.
Qed.
Canonical ker_cprod_by_group := Group ker_cprod_by_is_group.
Lemma ker_cprod_by_central : kerHK \subset 'Z(setX H K).
Proof.
rewrite -(center_dprod (setX_dprod H K)) -morphim_pairg1 -morphim_pair1g.
rewrite -!injm_center ?subsetT ?injm_pair1g ?injm_pairg1 //=.
rewrite morphim_pairg1 morphim_pair1g setX_dprod.
apply/subsetP=> [[x y]] /[1!inE] /andP[Zx /eqP->].
by rewrite inE /= Zx groupV (subsetP sgzZZ) ?mem_morphim.
Qed.
Fact cprod_by_key : unit. Proof. by []. Qed.
Definition cprod_by_def : finGroupType := subg_of (setX H K / kerHK).
Definition cprod_by := locked_with cprod_by_key cprod_by_def.
Local Notation C := [set: FinGroup.sort cprod_by].
(*FIXME : Check if we need arg_sort instead of sort*)
Definition in_cprod : gTH * gTK -> cprod_by :=
let: tt as k := cprod_by_key return _ -> locked_with k cprod_by_def in
subg _ \o coset kerHK.
Lemma in_cprodM : {in setX H K &, {morph in_cprod : u v / u * v}}.
Proof.
rewrite /in_cprod /cprod_by; case: cprod_by_key => /= u v Gu Gv.
have nkerHKG := normal_norm (sub_center_normal ker_cprod_by_central).
by rewrite -!morphM ?mem_quotient // (subsetP nkerHKG).
Qed.
Canonical in_cprod_morphism := Morphism in_cprodM.
Lemma ker_in_cprod : 'ker in_cprod = kerHK.
Proof.
transitivity ('ker (subg [group of setX H K / kerHK] \o coset kerHK)).
rewrite /ker /morphpre /= /in_cprod /cprod_by; case: cprod_by_key => /=.
by rewrite ['N(_) :&: _]quotientGK ?sub_center_normal ?ker_cprod_by_central.
by rewrite ker_comp ker_subg -kerE ker_coset.
Qed.
Lemma cpairg1_dom : H \subset 'dom (in_cprod \o @pairg1 gTH gTK).
Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pairg1 setXS ?sub1G. Qed.
Lemma cpair1g_dom : K \subset 'dom (in_cprod \o @pair1g gTH gTK).
Proof. by rewrite -sub_morphim_pre ?subsetT // morphim_pair1g setXS ?sub1G. Qed.
Definition cpairg1 := tag (restrmP _ cpairg1_dom).
Definition cpair1g := tag (restrmP _ cpair1g_dom).
Local Notation CH := (mfun cpairg1 @* gval H).
Local Notation CK := (mfun cpair1g @* gval K).
Lemma injm_cpairg1 : 'injm cpairg1.
Proof.
rewrite /cpairg1; case: restrmP => _ [_ -> _ _].
rewrite ker_comp ker_in_cprod; apply/subsetP=> x; rewrite !inE /=.
by case/and3P=> _ Zx; rewrite eq_sym (inv_eq invgK) invg1 morph_injm_eq1.
Qed.
Let injH := injm_cpairg1.
Lemma injm_cpair1g : 'injm cpair1g.
Proof.
rewrite /cpair1g; case: restrmP => _ [_ -> _ _].
rewrite ker_comp ker_in_cprod; apply/subsetP=> y; rewrite !inE /= morph1 invg1.
by case/and3P.
Qed.
Let injK := injm_cpair1g.
Lemma im_cpair_cent : CK \subset 'C(CH).
Proof.
rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //].
rewrite !morphim_comp morphim_cents // morphim_pair1g morphim_pairg1.
by case/dprodP: (setX_dprod H K).
Qed.
Hint Resolve im_cpair_cent : core.
Lemma im_cpair : CH * CK = C.
Proof.
rewrite /cpairg1 /cpair1g; do 2!case: restrmP => _ [_ _ _ -> //].
rewrite !morphim_comp -morphimMl morphim_pairg1 ?setXS ?sub1G //.
rewrite morphim_pair1g setX_prod morphimEdom /= /in_cprod /cprod_by.
by case: cprod_by_key; rewrite /= imset_comp imset_coset -morphimEdom im_subg.
Qed.
Lemma im_cpair_cprod : CH \* CK = C. Proof. by rewrite cprodE ?im_cpair. Qed.
Lemma eq_cpairZ : {in 'Z(H), cpairg1 =1 cpair1g \o gz}.
Proof.
rewrite /cpairg1 /cpair1g => z1 Zz1; set z2 := gz z1.
have Zz2: z2 \in 'Z(K) by rewrite (subsetP sgzZZ) ?mem_morphim.
have [[Gz1 _] [/= Gz2 _]]:= (setIP Zz1, setIP Zz2).
do 2![case: restrmP => f /= [df _ _ _]; rewrite {f}df].
apply/rcoset_kerP; rewrite ?inE ?group1 ?andbT //.
by rewrite ker_in_cprod mem_rcoset inE /= invg1 mulg1 mul1g Zz1 /=.
Qed.
Lemma setI_im_cpair : CH :&: CK = 'Z(CH).
Proof.
apply/eqP; rewrite eqEsubset setIS //=.
rewrite subsetI center_sub -injm_center //.
rewrite (eq_in_morphim _ eq_cpairZ); first by rewrite morphim_comp morphimS.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
Lemma cpair1g_center : cpair1g @* 'Z(K) = 'Z(C).
Proof.
case/cprodP: (center_cprod im_cpair_cprod) => _ <- _.
by rewrite injm_center // -setI_im_cpair mulSGid //= setIC setIS 1?centsC.
Qed.
(* Uses gzZ. *)
Lemma cpair_center_id : 'Z(CH) = 'Z(CK).
Proof.
rewrite -!injm_center // -gzZ -morphim_comp; apply: eq_in_morphim eq_cpairZ.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
(* Uses gzZ. *)
Lemma cpairg1_center : cpairg1 @* 'Z(H) = 'Z(C).
Proof. by rewrite -cpair1g_center !injm_center // cpair_center_id. Qed.
Section ExtCprodm.
Variable rT : finGroupType.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis cfHK : fK @* K \subset 'C(fH @* H).
Hypothesis eq_fHK : {in 'Z(H), fH =1 fK \o gz}.
Let gH := ifactm fH injm_cpairg1.
Let gK := ifactm fK injm_cpair1g.
Lemma xcprodm_cent : gK @* CK \subset 'C(gH @* CH).
Proof. by rewrite !im_ifactm. Qed.
Lemma xcprodmI : {in CH :&: CK, gH =1 gK}.
Proof.
rewrite setI_im_cpair -injm_center // => fHx; case/morphimP=> x Gx Zx ->{fHx}.
by rewrite {2}eq_cpairZ //= ?ifactmE ?eq_fHK //= (subsetP sgzZG) ?mem_morphim.
Qed.
Definition xcprodm := cprodm im_cpair_cprod xcprodm_cent xcprodmI.
Canonical xcprod_morphism := [morphism of xcprodm].
Lemma xcprodmEl : {in H, forall x, xcprodm (cpairg1 x) = fH x}.
Proof. by move=> x Hx; rewrite /xcprodm cprodmEl ?mem_morphim ?ifactmE. Qed.
Lemma xcprodmEr : {in K, forall y, xcprodm (cpair1g y) = fK y}.
Proof. by move=> y Ky; rewrite /xcprodm cprodmEr ?mem_morphim ?ifactmE. Qed.
Lemma xcprodmE :
{in H & K, forall x y, xcprodm (cpairg1 x * cpair1g y) = fH x * fK y}.
Proof.
by move=> x y Hx Ky; rewrite /xcprodm cprodmE ?mem_morphim ?ifactmE.
Qed.
Lemma im_xcprodm : xcprodm @* C = fH @* H * fK @* K.
Proof. by rewrite -im_cpair morphim_cprodm // !im_ifactm. Qed.
Lemma im_xcprodml A : xcprodm @* (cpairg1 @* A) = fH @* A.
Proof.
rewrite -!(morphimIdom _ A) morphim_cprodml ?morphimS ?subsetIl //.
by rewrite morphim_ifactm ?subsetIl.
Qed.
Lemma im_xcprodmr A : xcprodm @* (cpair1g @* A) = fK @* A.
Proof.
rewrite -!(morphimIdom _ A) morphim_cprodmr ?morphimS ?subsetIl //.
by rewrite morphim_ifactm ?subsetIl.
Qed.
Lemma injm_xcprodm : 'injm xcprodm = 'injm fH && 'injm fK.
Proof.
rewrite injm_cprodm !ker_ifactm !subG1 !morphim_injm_eq1 ?subsetIl // -!subG1.
apply: andb_id2l => /= injfH; apply: andb_idr => _.
rewrite !im_ifactm // -(morphimIdom gH) setI_im_cpair -injm_center //.
rewrite morphim_ifactm // eqEsubset subsetI morphimS //=.
rewrite {1}injm_center // setIS //=.
rewrite (eq_in_morphim _ eq_fHK); first by rewrite morphim_comp morphimS.
by rewrite !(setIidPr _) // -sub_morphim_pre.
Qed.
End ExtCprodm.
(* Uses gzZchar. *)
Lemma Aut_cprod_by_full :
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
Aut_in (Aut K) 'Z(K) \isog Aut 'Z(K) ->
Aut_in (Aut C) 'Z(C) \isog Aut 'Z(C).
Proof.
move=> AutZinH AutZinK.
have Cfull:= Aut_cprod_full im_cpair_cprod cpair_center_id.
by rewrite Cfull // -injm_center // injm_Aut_full ?center_sub.
Qed.
Section Isomorphism.
Let gzZ_lone (Y : {group gTK}) :
Y \subset 'Z(K) -> gz @* 'Z(H) \isog Y -> gz @* 'Z(H) = Y.
Proof.
move=> sYZ isoY; apply/eqP.
by rewrite eq_sym eqEcard (card_isog isoY) gzZ sYZ /=.
Qed.
Variables (rT : finGroupType) (GH GK G : {group rT}).
Hypotheses (defG : GH \* GK = G) (ziGHK : GH :&: GK = 'Z(GH)).
Hypothesis AutZHfull : Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H).
Hypotheses (isoGH : GH \isog H) (isoGK : GK \isog K).
(* Uses gzZ_lone *)
Lemma cprod_by_uniq :
exists f : {morphism G >-> cprod_by},
[/\ isom G C f, f @* GH = CH & f @* GK = CK].
Proof.
have [_ defGHK cGKH] := cprodP defG.
have AutZinH := Aut_sub_fullP sZH AutZHfull.
have [fH injfH defGH]:= isogP (isog_symr isoGH).
have [fK injfK defGK]:= isogP (isog_symr isoGK).
have sfHZfK: fH @* 'Z(H) \subset fK @* K.
by rewrite injm_center //= defGH defGK -ziGHK subsetIr.
have gzZ_id: gz @* 'Z(H) = invm injfK @* (fH @* 'Z(H)).
apply: gzZ_lone => /=.
rewrite injm_center // defGH -ziGHK sub_morphim_pre /= ?defGK ?subsetIr //.
by rewrite setIC morphpre_invm injm_center // defGK setIS 1?centsC.
rewrite -morphim_comp.
apply: isog_trans (sub_isog _ _); first by rewrite isog_sym sub_isog.
by rewrite -sub_morphim_pre.
by rewrite !injm_comp ?injm_invm.
have: 'dom (invm injfH \o fK \o gz) = 'Z(H).
rewrite /dom /= -(morphpreIdom gz); apply/setIidPl.
by rewrite -2?sub_morphim_pre // gzZ_id morphim_invmE morphpreK ?morphimS.
case/domP=> gzH [def_gzH ker_gzH _ im_gzH].
have{ker_gzH} injgzH: 'injm gzH by rewrite ker_gzH !injm_comp ?injm_invm.
have{AutZinH} [|gH [injgH gH_H def_gH]] := AutZinH _ injgzH.
by rewrite im_gzH !morphim_comp /= gzZ_id !morphim_invmE morphpreK ?injmK.
have: 'dom (fH \o gH) = H by rewrite /dom /= -{3}gH_H injmK.
case/domP=> gfH [def_gfH ker_gfH _ im_gfH].
have{im_gfH} gfH_H: gfH @* H = GH by rewrite im_gfH morphim_comp gH_H.
have cgfHfK: fK @* K \subset 'C(gfH @* H) by rewrite gfH_H defGK.
have eq_gfHK: {in 'Z(H), gfH =1 fK \o gz}.
move=> z Zz; rewrite def_gfH /= def_gH //= def_gzH /= invmK //.
have {Zz}: gz z \in gz @* 'Z(H) by rewrite mem_morphim.
rewrite gzZ_id morphim_invmE; case/morphpreP=> _.
exact: (subsetP (morphimS _ _)).
pose f := xcprodm cgfHfK eq_gfHK.
have injf: 'injm f by rewrite injm_xcprodm ker_gfH injm_comp.
have fCH: f @* CH = GH by rewrite im_xcprodml gfH_H.
have fCK: f @* CK = GK by rewrite im_xcprodmr defGK.
have fC: f @* C = G by rewrite im_xcprodm gfH_H defGK defGHK.
have [f' [_ ker_f' _ im_f']] := domP (invm_morphism injf) fC.
exists f'; rewrite -fCH -fCK !{1}im_f' !{1}morphim_invm ?subsetT //.
by split=> //; apply/isomP; rewrite ker_f' injm_invm im_f' -fC im_invm.
Qed.
Lemma isog_cprod_by : G \isog C.
Proof. by have [f [isoG _ _]] := cprod_by_uniq; apply: isom_isog isoG. Qed.
End Isomorphism.
End CprodBy.
Section ExtCprod.
Import finfun.
Variables gTH gTK : finGroupType.
Variables (H : {group gTH}) (K : {group gTK}).
Let gt_ b := if b then gTK else gTH.
Local Notation isob := ('Z(H) \isog 'Z(K)) (only parsing).
Let G_ b := if b as b' return {group gt_ b'} then K else H.
Lemma xcprod_subproof :
{gz : {morphism 'Z(H) >-> gt_ isob} | isom 'Z(H) 'Z(G_ isob) gz}.
Proof.
case: (pickP [pred f : {ffun _} | misom 'Z(H) 'Z(K) f]) => [f isoZ | no_f].
rewrite (misom_isog isoZ); case/andP: isoZ => fM isoZ.
by exists [morphism of morphm fM].
move/pred0P: no_f => not_isoZ; rewrite [isob](congr1 negb not_isoZ).
by exists (idm_morphism _); apply/isomP; rewrite injm_idm im_idm.
Qed.
Definition xcprod := cprod_by (svalP xcprod_subproof).
Inductive xcprod_spec : finGroupType -> Prop :=
XcprodSpec gz isoZ : xcprod_spec (@cprod_by gTH gTK H K gz isoZ).
Lemma xcprodP : 'Z(H) \isog 'Z(K) -> xcprod_spec xcprod.
Proof. by rewrite /xcprod => isoZ; move: xcprod_subproof; rewrite isoZ. Qed.
Lemma isog_xcprod (rT : finGroupType) (GH GK G : {group rT}) :
Aut_in (Aut H) 'Z(H) \isog Aut 'Z(H) ->
GH \isog H -> GK \isog K -> GH \* GK = G -> 'Z(GH) = 'Z(GK) ->
G \isog [set: xcprod].
Proof.
move=> AutZinH isoGH isoGK defG eqZGHK; have [_ _ cGHK] := cprodP defG.
have [|gz isoZ] := xcprodP.
have [[fH injfH <-] [fK injfK <-]] := (isogP isoGH, isogP isoGK).
rewrite -!injm_center -?(isog_transl _ (sub_isog _ _)) ?center_sub //=.
by rewrite eqZGHK sub_isog ?center_sub.
rewrite (isog_cprod_by _ defG) //.
by apply/eqP; rewrite eqEsubset setIS // subsetI {2}eqZGHK !center_sub.
Qed.
End ExtCprod.
Section IterCprod.
Variables (gT : finGroupType) (G : {group gT}).
Fixpoint ncprod_def n : finGroupType :=
if n is n'.+1 then xcprod G [set: ncprod_def n']
else subg_of 'Z(G).
Fact ncprod_key : unit. Proof. by []. Qed.
Definition ncprod := locked_with ncprod_key ncprod_def.
Local Notation G_ n := [set: gsort (ncprod n)].
Lemma ncprod0 : G_ 0 \isog 'Z(G).
Proof. by rewrite [ncprod]unlock isog_sym isog_subg. Qed.
Lemma center_ncprod0 : 'Z(G_ 0) = G_ 0.
Proof. by apply: center_idP; rewrite (isog_abelian ncprod0) center_abelian. Qed.
Lemma center_ncprod n : 'Z(G_ n) \isog 'Z(G).
Proof.
elim: n => [|n]; first by rewrite center_ncprod0 ncprod0.
rewrite [ncprod]unlock=> /isog_symr/xcprodP[gz isoZ] /=.
by rewrite -cpairg1_center isog_sym sub_isog ?center_sub ?injm_cpairg1.
Qed.
Lemma ncprodS n : xcprod_spec G [set: ncprod n] (ncprod n.+1).
Proof.
by have:= xcprodP (isog_symr (center_ncprod n)); rewrite [ncprod]unlock.
Qed.
Lemma ncprod1 : G_ 1 \isog G.
Proof.
case: ncprodS => gz isoZ; rewrite isog_sym /= -im_cpair.
rewrite mulGSid /=; first by rewrite sub_isog ?injm_cpairg1.
rewrite -{3}center_ncprod0 injm_center ?injm_cpair1g //.
by rewrite -cpair_center_id center_sub.
Qed.
Lemma Aut_ncprod_full n :
Aut_in (Aut G) 'Z(G) \isog Aut 'Z(G) ->
Aut_in (Aut (G_ n)) 'Z(G_ n) \isog Aut 'Z(G_ n).
Proof.
move=> AutZinG; elim: n => [|n IHn].
by rewrite center_ncprod0; apply/Aut_sub_fullP=> // g injg gG0; exists g.
by case: ncprodS => gz isoZ; apply: Aut_cprod_by_full.
Qed.
End IterCprod.
|
Center.lean
|
/-
Copyright (c) 2020 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.GroupTheory.Submonoid.Center
/-!
# Centers of subgroups
-/
assert_not_exists MonoidWithZero Multiset
variable {G : Type*} [Group G]
namespace Subgroup
variable (G)
/-- The center of a group `G` is the set of elements that commute with everything in `G` -/
@[to_additive
/-- The center of an additive group `G` is the set of elements that commute with
everything in `G` -/]
def center : Subgroup G :=
{ Submonoid.center G with
carrier := Set.center G
inv_mem' := Set.inv_mem_center }
@[to_additive]
theorem coe_center : ↑(center G) = Set.center G :=
rfl
@[to_additive (attr := simp)]
theorem center_toSubmonoid : (center G).toSubmonoid = Submonoid.center G :=
rfl
instance center.isMulCommutative : IsMulCommutative (center G) :=
⟨⟨fun a b => Subtype.ext (b.2.comm a).symm⟩⟩
@[deprecated (since := "2025-04-09")] alias center.isCommutative := Subgroup.center.isMulCommutative
variable {G} in
/-- The center of isomorphic groups are isomorphic. -/
@[to_additive (attr := simps!) /-- The center of isomorphic additive groups are isomorphic. -/]
def centerCongr {H} [Group H] (e : G ≃* H) : center G ≃* center H := Submonoid.centerCongr e
/-- The center of a group is isomorphic to the center of its opposite. -/
@[to_additive (attr := simps!)
/-- The center of an additive group is isomorphic to the center of its opposite. -/]
def centerToMulOpposite : center G ≃* center Gᵐᵒᵖ := Submonoid.centerToMulOpposite
variable {G}
@[to_additive]
theorem mem_center_iff {z : G} : z ∈ center G ↔ ∀ g, g * z = z * g := by
rw [← Semigroup.mem_center_iff]
exact Iff.rfl
instance decidableMemCenter (z : G) [Decidable (∀ g, g * z = z * g)] : Decidable (z ∈ center G) :=
decidable_of_iff' _ mem_center_iff
@[to_additive]
instance centerCharacteristic : (center G).Characteristic := by
refine characteristic_iff_comap_le.mpr fun ϕ g hg => ?_
rw [mem_center_iff]
intro h
rw [← ϕ.injective.eq_iff, map_mul, map_mul]
exact (hg.comm (ϕ h)).symm
theorem _root_.CommGroup.center_eq_top {G : Type*} [CommGroup G] : center G = ⊤ := by
rw [eq_top_iff']
intro x
rw [Subgroup.mem_center_iff]
intro y
exact mul_comm y x
/-- A group is commutative if the center is the whole group -/
def _root_.Group.commGroupOfCenterEqTop (h : center G = ⊤) : CommGroup G :=
{ ‹Group G› with
mul_comm := by
rw [eq_top_iff'] at h
intro x y
apply Subgroup.mem_center_iff.mp _ x
exact h y
}
variable {H : Subgroup G}
section Normalizer
@[to_additive]
instance instNormalCenter : (center G).Normal :=
⟨fun a ha b ↦ by simp [mul_assoc, mem_center_iff.mp ha b, ha]⟩
@[to_additive]
theorem center_le_normalizer : center G ≤ H.normalizer := fun x hx y => by
simp [← mem_center_iff.mp hx y, mul_assoc]
end Normalizer
end Subgroup
namespace IsConj
variable {M : Type*} [Monoid M]
theorem eq_of_left_mem_center {g h : M} (H : IsConj g h) (Hg : g ∈ Set.center M) : g = h := by
rcases H with ⟨u, hu⟩; rwa [← u.mul_left_inj, Hg.comm u]
theorem eq_of_right_mem_center {g h : M} (H : IsConj g h) (Hh : h ∈ Set.center M) : g = h :=
(H.symm.eq_of_left_mem_center Hh).symm
end IsConj
namespace ConjClasses
theorem mk_bijOn (G : Type*) [Group G] :
Set.BijOn ConjClasses.mk (↑(Subgroup.center G)) (noncenter G)ᶜ := by
refine ⟨fun g hg ↦ ?_, fun x hx y _ H ↦ ?_, ?_⟩
· simp only [mem_noncenter, Set.compl_def, Set.mem_setOf, Set.not_nontrivial_iff]
intro x hx y hy
simp only [mem_carrier_iff_mk_eq, mk_eq_mk_iff_isConj] at hx hy
rw [hx.eq_of_right_mem_center hg, hy.eq_of_right_mem_center hg]
· rw [mk_eq_mk_iff_isConj] at H
exact H.eq_of_left_mem_center hx
· rintro ⟨g⟩ hg
refine ⟨g, ?_, rfl⟩
simp only [mem_noncenter, Set.compl_def, Set.mem_setOf, Set.not_nontrivial_iff] at hg
rw [SetLike.mem_coe, Subgroup.mem_center_iff]
intro h
rw [← mul_inv_eq_iff_eq_mul]
refine hg ?_ mem_carrier_mk
rw [mem_carrier_iff_mk_eq]
apply mk_eq_mk_iff_isConj.mpr
rw [isConj_comm, isConj_iff]
exact ⟨h, rfl⟩
end ConjClasses
|
PrimeMultiplicity.lean
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.RingTheory.Multiplicity
import Mathlib.RingTheory.Valuation.Basic
/-!
# `multiplicity` of a prime in an integral domain as an additive valuation
-/
variable {R : Type*} [CommRing R] [IsDomain R] {p : R}
/-- `multiplicity` of a prime in an integral domain as an additive valuation to `ℕ∞`. -/
noncomputable def multiplicity_addValuation (hp : Prime p) : AddValuation R ℕ∞ :=
AddValuation.of (emultiplicity p) (emultiplicity_zero _) (emultiplicity_of_one_right hp.not_unit)
(fun _ _ => min_le_emultiplicity_add) fun _ _ => emultiplicity_mul hp
@[simp]
theorem multiplicity_addValuation_apply {hp : Prime p} {r : R} :
multiplicity_addValuation hp r = emultiplicity p r :=
rfl
|
Antisymmetrization.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.Logic.Relation
import Mathlib.Order.Hom.Basic
import Mathlib.Tactic.Tauto
/-!
# Turning a preorder into a partial order
This file allows to make a preorder into a partial order by quotienting out the elements `a`, `b`
such that `a ≤ b` and `b ≤ a`.
`Antisymmetrization` is a functor from `Preorder` to `PartialOrder`. See `Preorder_to_PartialOrder`.
## Main declarations
* `AntisymmRel`: The antisymmetrization relation. `AntisymmRel r a b` means that `a` and `b` are
related both ways by `r`.
* `Antisymmetrization α r`: The quotient of `α` by `AntisymmRel r`. Even when `r` is just a
preorder, `Antisymmetrization α` is a partial order.
-/
open Function OrderDual
variable {α β : Type*} {a b c d : α}
section Relation
variable (r : α → α → Prop)
/-- The antisymmetrization relation `AntisymmRel r` is defined so that
`AntisymmRel r a b ↔ r a b ∧ r b a`. -/
def AntisymmRel (a b : α) : Prop :=
r a b ∧ r b a
theorem antisymmRel_swap : AntisymmRel (swap r) = AntisymmRel r :=
funext₂ fun _ _ ↦ propext and_comm
theorem antisymmRel_swap_apply : AntisymmRel (swap r) a b ↔ AntisymmRel r a b :=
and_comm
@[simp, refl]
theorem AntisymmRel.refl [IsRefl α r] (a : α) : AntisymmRel r a a :=
⟨_root_.refl _, _root_.refl _⟩
variable {r} in
lemma AntisymmRel.rfl [IsRefl α r] {a : α} : AntisymmRel r a a := .refl ..
instance [IsRefl α r] : IsRefl α (AntisymmRel r) where
refl := .refl r
variable {r}
theorem AntisymmRel.of_eq [IsRefl α r] {a b : α} (h : a = b) : AntisymmRel r a b := h ▸ .rfl
alias Eq.antisymmRel := AntisymmRel.of_eq
@[symm]
theorem AntisymmRel.symm : AntisymmRel r a b → AntisymmRel r b a :=
And.symm
instance : IsSymm α (AntisymmRel r) where
symm _ _ := AntisymmRel.symm
theorem antisymmRel_comm : AntisymmRel r a b ↔ AntisymmRel r b a :=
And.comm
@[trans]
theorem AntisymmRel.trans [IsTrans α r] (hab : AntisymmRel r a b) (hbc : AntisymmRel r b c) :
AntisymmRel r a c :=
⟨_root_.trans hab.1 hbc.1, _root_.trans hbc.2 hab.2⟩
instance [IsTrans α r] : IsTrans α (AntisymmRel r) where
trans _ _ _ := .trans
instance AntisymmRel.decidableRel [DecidableRel r] : DecidableRel (AntisymmRel r) :=
fun _ _ ↦ instDecidableAnd
@[simp]
theorem antisymmRel_iff_eq [IsRefl α r] [IsAntisymm α r] : AntisymmRel r a b ↔ a = b :=
antisymm_iff
alias ⟨AntisymmRel.eq, _⟩ := antisymmRel_iff_eq
end Relation
section LE
variable [LE α]
theorem AntisymmRel.le (h : AntisymmRel (· ≤ ·) a b) : a ≤ b := h.1
theorem AntisymmRel.ge (h : AntisymmRel (· ≤ ·) a b) : b ≤ a := h.2
end LE
section IsPreorder
variable (α) (r : α → α → Prop) [IsPreorder α r]
/-- The antisymmetrization relation as an equivalence relation. -/
@[simps]
def AntisymmRel.setoid : Setoid α :=
⟨AntisymmRel r, .refl r, .symm, .trans⟩
/-- The partial order derived from a preorder by making pairwise comparable elements equal. This is
the quotient by `fun a b => a ≤ b ∧ b ≤ a`. -/
def Antisymmetrization : Type _ :=
Quotient <| AntisymmRel.setoid α r
variable {α}
/-- Turn an element into its antisymmetrization. -/
def toAntisymmetrization : α → Antisymmetrization α r :=
Quotient.mk _
/-- Get a representative from the antisymmetrization. -/
noncomputable def ofAntisymmetrization : Antisymmetrization α r → α :=
Quotient.out
instance [Inhabited α] : Inhabited (Antisymmetrization α r) := by
unfold Antisymmetrization; infer_instance
@[elab_as_elim]
protected theorem Antisymmetrization.ind {p : Antisymmetrization α r → Prop} :
(∀ a, p <| toAntisymmetrization r a) → ∀ q, p q :=
Quot.ind
@[elab_as_elim]
protected theorem Antisymmetrization.induction_on {p : Antisymmetrization α r → Prop}
(a : Antisymmetrization α r) (h : ∀ a, p <| toAntisymmetrization r a) : p a :=
Quotient.inductionOn' a h
@[simp]
theorem toAntisymmetrization_ofAntisymmetrization (a : Antisymmetrization α r) :
toAntisymmetrization r (ofAntisymmetrization r a) = a :=
Quotient.out_eq' _
end IsPreorder
section Preorder
variable [Preorder α] [Preorder β]
theorem le_iff_lt_or_antisymmRel : a ≤ b ↔ a < b ∨ AntisymmRel (· ≤ ·) a b := by
rw [lt_iff_le_not_ge, AntisymmRel]
tauto
theorem le_of_le_of_antisymmRel (h₁ : a ≤ b) (h₂ : AntisymmRel (· ≤ ·) b c) : a ≤ c :=
h₁.trans h₂.le
theorem le_of_antisymmRel_of_le (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : b ≤ c) : a ≤ c :=
h₁.le.trans h₂
theorem lt_of_lt_of_antisymmRel (h₁ : a < b) (h₂ : AntisymmRel (· ≤ ·) b c) : a < c :=
h₁.trans_le h₂.le
theorem lt_of_antisymmRel_of_lt (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : b < c) : a < c :=
h₁.le.trans_lt h₂
alias ⟨LE.le.lt_or_antisymmRel, _⟩ := le_iff_lt_or_antisymmRel
alias LE.le.trans_antisymmRel := le_of_le_of_antisymmRel
alias AntisymmRel.trans_le := le_of_antisymmRel_of_le
alias LT.lt.trans_antisymmRel := lt_of_lt_of_antisymmRel
alias AntisymmRel.trans_lt := lt_of_antisymmRel_of_lt
instance : @Trans α α α (· ≤ ·) (AntisymmRel (· ≤ ·)) (· ≤ ·) where
trans := le_of_le_of_antisymmRel
instance : @Trans α α α (AntisymmRel (· ≤ ·)) (· ≤ ·) (· ≤ ·) where
trans := le_of_antisymmRel_of_le
instance : @Trans α α α (· < ·) (AntisymmRel (· ≤ ·)) (· < ·) where
trans := lt_of_lt_of_antisymmRel
instance : @Trans α α α (AntisymmRel (· ≤ ·)) (· < ·) (· < ·) where
trans := lt_of_antisymmRel_of_lt
theorem AntisymmRel.le_congr (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : AntisymmRel (· ≤ ·) c d) :
a ≤ c ↔ b ≤ d where
mp h := (h₁.symm.trans_le h).trans_antisymmRel h₂
mpr h := (h₁.trans_le h).trans_antisymmRel h₂.symm
theorem AntisymmRel.le_congr_left (h : AntisymmRel (· ≤ ·) a b) : a ≤ c ↔ b ≤ c :=
h.le_congr .rfl
theorem AntisymmRel.le_congr_right (h : AntisymmRel (· ≤ ·) b c) : a ≤ b ↔ a ≤ c :=
AntisymmRel.rfl.le_congr h
theorem AntisymmRel.lt_congr (h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : AntisymmRel (· ≤ ·) c d) :
a < c ↔ b < d where
mp h := (h₁.symm.trans_lt h).trans_antisymmRel h₂
mpr h := (h₁.trans_lt h).trans_antisymmRel h₂.symm
theorem AntisymmRel.lt_congr_left (h : AntisymmRel (· ≤ ·) a b) : a < c ↔ b < c :=
h.lt_congr .rfl
theorem AntisymmRel.lt_congr_right (h : AntisymmRel (· ≤ ·) b c) : a < b ↔ a < c :=
AntisymmRel.rfl.lt_congr h
theorem AntisymmRel.antisymmRel_congr
(h₁ : AntisymmRel (· ≤ ·) a b) (h₂ : AntisymmRel (· ≤ ·) c d) :
AntisymmRel (· ≤ ·) a c ↔ AntisymmRel (· ≤ ·) b d :=
rel_congr h₁ h₂
theorem AntisymmRel.antisymmRel_congr_left (h : AntisymmRel (· ≤ ·) a b) :
AntisymmRel (· ≤ ·) a c ↔ AntisymmRel (· ≤ ·) b c :=
rel_congr_left h
theorem AntisymmRel.antisymmRel_congr_right (h : AntisymmRel (· ≤ ·) b c) :
AntisymmRel (· ≤ ·) a b ↔ AntisymmRel (· ≤ ·) a c :=
rel_congr_right h
theorem AntisymmRel.image (h : AntisymmRel (· ≤ ·) a b) {f : α → β} (hf : Monotone f) :
AntisymmRel (· ≤ ·) (f a) (f b) :=
⟨hf h.1, hf h.2⟩
instance instPartialOrderAntisymmetrization : PartialOrder (Antisymmetrization α (· ≤ ·)) where
le :=
Quotient.lift₂ (· ≤ ·) fun (_ _ _ _ : α) h₁ h₂ =>
propext ⟨fun h => h₁.2.trans <| h.trans h₂.1, fun h => h₁.1.trans <| h.trans h₂.2⟩
lt :=
Quotient.lift₂ (· < ·) fun (_ _ _ _ : α) h₁ h₂ =>
propext ⟨fun h => h₁.2.trans_lt <| h.trans_le h₂.1, fun h =>
h₁.1.trans_lt <| h.trans_le h₂.2⟩
le_refl a := Quotient.inductionOn' a le_refl
le_trans a b c := Quotient.inductionOn₃' a b c fun _ _ _ => le_trans
lt_iff_le_not_ge a b := Quotient.inductionOn₂' a b fun _ _ => lt_iff_le_not_ge
le_antisymm a b := Quotient.inductionOn₂' a b fun _ _ hab hba => Quotient.sound' ⟨hab, hba⟩
theorem antisymmetrization_fibration :
Relation.Fibration (· < ·) (· < ·) (toAntisymmetrization (α := α) (· ≤ ·)) := by
rintro a ⟨b⟩ h
exact ⟨b, h, rfl⟩
theorem acc_antisymmetrization_iff : Acc (· < ·)
(toAntisymmetrization (α := α) (· ≤ ·) a) ↔ Acc (· < ·) a :=
acc_lift₂_iff
theorem wellFounded_antisymmetrization_iff :
WellFounded (@LT.lt (Antisymmetrization α (· ≤ ·)) _) ↔ WellFounded (@LT.lt α _) :=
wellFounded_lift₂_iff
theorem wellFoundedLT_antisymmetrization_iff :
WellFoundedLT (Antisymmetrization α (· ≤ ·)) ↔ WellFoundedLT α := by
simp_rw [isWellFounded_iff, wellFounded_antisymmetrization_iff]
theorem wellFoundedGT_antisymmetrization_iff :
WellFoundedGT (Antisymmetrization α (· ≤ ·)) ↔ WellFoundedGT α := by
simp_rw [isWellFounded_iff]
convert wellFounded_liftOn₂'_iff with ⟨_⟩ ⟨_⟩
exact fun _ _ _ _ h₁ h₂ ↦ propext
⟨fun h ↦ (h₂.2.trans_lt h).trans_le h₁.1, fun h ↦ (h₂.1.trans_lt h).trans_le h₁.2⟩
instance [WellFoundedLT α] : WellFoundedLT (Antisymmetrization α (· ≤ ·)) :=
wellFoundedLT_antisymmetrization_iff.mpr ‹_›
instance [WellFoundedGT α] : WellFoundedGT (Antisymmetrization α (· ≤ ·)) :=
wellFoundedGT_antisymmetrization_iff.mpr ‹_›
instance [DecidableLE α] [DecidableLT α] [IsTotal α (· ≤ ·)] :
LinearOrder (Antisymmetrization α (· ≤ ·)) :=
{ instPartialOrderAntisymmetrization with
le_total := fun a b => Quotient.inductionOn₂' a b <| total_of (· ≤ ·),
toDecidableLE := fun _ _ => show Decidable (Quotient.liftOn₂' _ _ _ _) from inferInstance,
toDecidableLT := fun _ _ => show Decidable (Quotient.liftOn₂' _ _ _ _) from inferInstance }
@[simp]
theorem toAntisymmetrization_le_toAntisymmetrization_iff :
toAntisymmetrization (α := α) (· ≤ ·) a ≤ toAntisymmetrization (α := α) (· ≤ ·) b ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem toAntisymmetrization_lt_toAntisymmetrization_iff :
toAntisymmetrization (α := α) (· ≤ ·) a < toAntisymmetrization (α := α) (· ≤ ·) b ↔ a < b :=
Iff.rfl
@[simp]
theorem ofAntisymmetrization_le_ofAntisymmetrization_iff {a b : Antisymmetrization α (· ≤ ·)} :
ofAntisymmetrization (· ≤ ·) a ≤ ofAntisymmetrization (· ≤ ·) b ↔ a ≤ b :=
(Quotient.outRelEmbedding _).map_rel_iff
@[simp]
theorem ofAntisymmetrization_lt_ofAntisymmetrization_iff {a b : Antisymmetrization α (· ≤ ·)} :
ofAntisymmetrization (· ≤ ·) a < ofAntisymmetrization (· ≤ ·) b ↔ a < b :=
(Quotient.outRelEmbedding _).map_rel_iff
@[mono]
theorem toAntisymmetrization_mono : Monotone (toAntisymmetrization (α := α) (· ≤ ·)) :=
fun _ _ => id
open scoped Relator in
private theorem liftFun_antisymmRel (f : α →o β) :
((AntisymmRel.setoid α (· ≤ ·)).r ⇒ (AntisymmRel.setoid β (· ≤ ·)).r) f f := fun _ _ h =>
⟨f.mono h.1, f.mono h.2⟩
/-- Turns an order homomorphism from `α` to `β` into one from `Antisymmetrization α` to
`Antisymmetrization β`. `Antisymmetrization` is actually a functor. See `Preorder_to_PartialOrder`.
-/
protected def OrderHom.antisymmetrization (f : α →o β) :
Antisymmetrization α (· ≤ ·) →o Antisymmetrization β (· ≤ ·) :=
⟨Quotient.map' f <| liftFun_antisymmRel f, fun a b => Quotient.inductionOn₂' a b <| f.mono⟩
@[simp]
theorem OrderHom.coe_antisymmetrization (f : α →o β) :
⇑f.antisymmetrization = Quotient.map' f (liftFun_antisymmRel f) :=
rfl
theorem OrderHom.antisymmetrization_apply (f : α →o β) (a : Antisymmetrization α (· ≤ ·)) :
f.antisymmetrization a = Quotient.map' f (liftFun_antisymmRel f) a :=
rfl
@[simp]
theorem OrderHom.antisymmetrization_apply_mk (f : α →o β) (a : α) :
f.antisymmetrization (toAntisymmetrization _ a) = toAntisymmetrization _ (f a) :=
@Quotient.map_mk _ _ (_root_.id _) (_root_.id _) f (liftFun_antisymmRel f) _
variable (α)
/-- `ofAntisymmetrization` as an order embedding. -/
@[simps]
noncomputable def OrderEmbedding.ofAntisymmetrization : Antisymmetrization α (· ≤ ·) ↪o α :=
{ Quotient.outRelEmbedding _ with toFun := _root_.ofAntisymmetrization _ }
/-- `Antisymmetrization` and `orderDual` commute. -/
def OrderIso.dualAntisymmetrization :
(Antisymmetrization α (· ≤ ·))ᵒᵈ ≃o Antisymmetrization αᵒᵈ (· ≤ ·) where
toFun := (Quotient.map' id) fun _ _ => And.symm
invFun := (Quotient.map' id) fun _ _ => And.symm
left_inv a := Quotient.inductionOn' a fun a => by simp_rw [Quotient.map'_mk'', id]
right_inv a := Quotient.inductionOn' a fun a => by simp_rw [Quotient.map'_mk'', id]
map_rel_iff' := @fun a b => Quotient.inductionOn₂' a b fun _ _ => Iff.rfl
@[simp]
theorem OrderIso.dualAntisymmetrization_apply (a : α) :
OrderIso.dualAntisymmetrization _ (toDual <| toAntisymmetrization _ a) =
toAntisymmetrization _ (toDual a) :=
rfl
@[simp]
theorem OrderIso.dualAntisymmetrization_symm_apply (a : α) :
(OrderIso.dualAntisymmetrization _).symm (toAntisymmetrization _ <| toDual a) =
toDual (toAntisymmetrization _ a) :=
rfl
end Preorder
section Prod
variable (α β) [Preorder α] [Preorder β]
namespace Antisymmetrization
/-- The antisymmetrization of a product preorder is order isomorphic
to the product of antisymmetrizations. -/
def prodEquiv : Antisymmetrization (α × β) (· ≤ ·) ≃o
Antisymmetrization α (· ≤ ·) × Antisymmetrization β (· ≤ ·) where
toFun := Quotient.lift (fun ab ↦ (⟦ab.1⟧, ⟦ab.2⟧)) fun ab₁ ab₂ h ↦
Prod.ext (Quotient.sound ⟨h.1.1, h.2.1⟩) (Quotient.sound ⟨h.1.2, h.2.2⟩)
invFun := Function.uncurry <| Quotient.lift₂ (fun a b ↦ ⟦(a, b)⟧)
fun a₁ b₁ a₂ b₂ h₁ h₂ ↦ Quotient.sound ⟨⟨h₁.1, h₂.1⟩, h₁.2, h₂.2⟩
left_inv := by rintro ⟨_⟩; rfl
right_inv := by rintro ⟨⟨_⟩, ⟨_⟩⟩; rfl
map_rel_iff' := by rintro ⟨_⟩ ⟨_⟩; rfl
@[simp] lemma prodEquiv_apply_mk {ab} : prodEquiv α β ⟦ab⟧ = (⟦ab.1⟧, ⟦ab.2⟧) := rfl
@[simp] lemma prodEquiv_symm_apply_mk {a b} : (prodEquiv α β).symm (⟦a⟧, ⟦b⟧) = ⟦(a, b)⟧ := rfl
end Antisymmetrization
attribute [local instance] Prod.wellFoundedLT' Prod.wellFoundedGT'
instance Prod.wellFoundedLT [WellFoundedLT α] [WellFoundedLT β] : WellFoundedLT (α × β) :=
wellFoundedLT_antisymmetrization_iff.mp <|
(Antisymmetrization.prodEquiv α β).strictMono.wellFoundedLT
instance Prod.wellFoundedGT [WellFoundedGT α] [WellFoundedGT β] : WellFoundedGT (α × β) :=
wellFoundedGT_antisymmetrization_iff.mp <|
(Antisymmetrization.prodEquiv α β).strictMono.wellFoundedGT
end Prod
|
Order.lean
|
/-
Copyright (c) 2025 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Topology.Algebra.IsUniformGroup.Defs
import Mathlib.Topology.Order.Basic
import Mathlib.Topology.UniformSpace.UniformConvergence
/-!
# TendstoUniformlyOn on ordered spaces
We gather some results about `TendstoUniformlyOn f g K` on ordered spaces,
in particular bounding the values of `f` in terms of bounds on the limit `g`.
-/
open Filter Function Finset Topology
variable {α ι : Type*}
section order
variable {β : Type*} [UniformSpace β] [AddGroup β] [IsUniformAddGroup β] [PartialOrder β]
[OrderTopology β] [AddLeftMono β] [AddRightMono β]
variable {f : ι → α → β} {g : α → β} {K : Set α} {p : Filter ι}
/-- If a sequence of functions converges uniformly on a set to a function `g` which is bounded above
by a value `u`, then the sequence is strictly bounded by any `v` such that `u < v`. -/
lemma TendstoUniformlyOn.eventually_forall_lt {u v : β} (huv : u < v)
(hf : TendstoUniformlyOn f g p K) (hg : ∀ x ∈ K, g x ≤ u) :
∀ᶠ i in p, ∀ x ∈ K, f i x < v := by
simp only [tendstoUniformlyOn_iff_tendsto, uniformity_eq_comap_neg_add_nhds_zero,
tendsto_iff_eventually, eventually_comap, Prod.forall] at *
conv at hf => enter [2]; rw [eventually_iff_exists_mem]
have hf2 := hf (fun x ↦ -x.1 + x.2 < -u + v) ⟨_, (isOpen_gt' (-u + v)).mem_nhds (by simp [huv]),
fun y hy a b hab ↦ (hab.symm ▸ hy :)⟩
filter_upwards [eventually_prod_principal_iff.mp hf2] with i hi x hx
simpa using add_lt_add_of_le_of_lt (hg x hx) (hi x hx)
lemma TendstoUniformlyOn.eventually_forall_le {u v : β} (huv : u < v)
(hf : TendstoUniformlyOn f g p K) (hg : ∀ x ∈ K, g x ≤ u) :
∀ᶠ i in p, ∀ x ∈ K, f i x ≤ v := by
filter_upwards [hf.eventually_forall_lt huv hg] with i hi x hx using (hi x hx).le
end order
|
Embedding.lean
|
/-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
-/
import Mathlib.Data.Fin.Basic
import Mathlib.Logic.Embedding.Basic
/-!
# Embeddings of `Fin n`
`Fin n` is the type whose elements are natural numbers smaller than `n`.
This file defines embeddings between `Fin n` and other types,
## Main definitions
* `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`;
* `Fin.succEmb` : `Fin.succ` as an `Embedding`;
* `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`;
* `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`;
* `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`;
* `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`;
* `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right,
generalizes `Fin.succ`;
* `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left;
-/
assert_not_exists Monoid Finset
open Fin Nat Function
namespace Fin
variable {n m : ℕ}
section Order
/-!
### order
-/
/-- The inclusion map `Fin n → ℕ` is an embedding. -/
@[simps -fullyApplied apply]
def valEmbedding : Fin n ↪ ℕ :=
⟨val, val_injective⟩
@[simp]
theorem equivSubtype_symm_trans_valEmbedding :
equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) :=
rfl
end Order
section Succ
/-!
### succ and casts into larger Fin types
-/
/-- `Fin.succ` as an `Embedding` -/
def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where
toFun := succ
inj' := succ_injective _
@[simp]
theorem coe_succEmb : ⇑(succEmb n) = Fin.succ :=
rfl
@[deprecated (since := "2025-04-12")]
alias val_succEmb := coe_succEmb
attribute [simp] castSucc_inj
/-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/
@[simps apply]
def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where
toFun := castLE h
inj' := castLE_injective _
@[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl
/- The next proof can be golfed a lot using `Fintype.card`.
It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency
(not done yet). -/
lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by
refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩
induction n generalizing m with
| zero => exact m.zero_le
| succ n ihn =>
obtain ⟨e⟩ := h
rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne'
with ⟨m, rfl⟩
refine Nat.succ_le_succ <| ihn ⟨?_⟩
refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero),
fun i j h ↦ ?_⟩
simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h
lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n :=
⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩),
fun h ↦ h ▸ ⟨.refl _⟩⟩
/-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`.
See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/
def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m)
@[simp]
lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl
lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl
/-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/
def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _
@[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl
lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl
/-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/
@[simps! apply]
def addNatEmb (m) : Fin n ↪ Fin (n + m) where
toFun := (addNat · m)
inj' a b := by simp [Fin.ext_iff]
/-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/
@[simps! apply]
def natAddEmb (n) {m} : Fin m ↪ Fin (n + m) where
toFun := natAdd n
inj' a b := by simp [Fin.ext_iff]
end Succ
section SuccAbove
variable {p : Fin (n + 1)}
/-- `Fin.succAbove p` as an `Embedding`. -/
@[simps!]
def succAboveEmb (p : Fin (n + 1)) : Fin n ↪ Fin (n + 1) := ⟨p.succAbove, succAbove_right_injective⟩
@[simp, norm_cast] lemma coe_succAboveEmb (p : Fin (n + 1)) : p.succAboveEmb = p.succAbove := rfl
end SuccAbove
end Fin
|
rat.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 prime fintype finfun bigop order tuple ssralg.
From mathcomp Require Import countalg div ssrnum ssrint archimedean poly zmodp.
From mathcomp Require Import polydiv intdiv matrix mxalgebra vector.
(******************************************************************************)
(* This file defines a datatype for rational numbers and equips it with a *)
(* structure of archimedean, real field, with int and nat declared as closed *)
(* subrings. *)
(* rat == the type of rational number, with single constructor Rat *)
(* <number> == <number> as a rat with <number> a decimal constant. *)
(* This notation is in rat_scope (delimited with %Q). *)
(* n%:Q == explicit cast from int to rat, ie. the specialization to *)
(* rationals of the generic ring morphism n%:~R *)
(* numq r == numerator of (r : rat) *)
(* denq r == denominator of (r : rat) *)
(* ratr r == generic embedding of (r : rat) into an arbitrary unit ring.*)
(* [rat x // y] == smart constructor for rationals, definitionally equal *)
(* to x / y for concrete values, intended for printing only *)
(* of normal forms. The parsable notation is for debugging. *)
(* inIntSpan X v <-> v is an integral linear combination of elements of *)
(* X : seq V, where V is a zmodType. We prove that this is a *)
(* decidable property for Q-vector spaces. *)
(******************************************************************************)
Import Order.TTheory GRing.Theory Num.Theory.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "[ 'rat' x // y ]" (format "[ 'rat' x // y ]").
Reserved Notation "n %:Q" (left associativity, format "n %:Q").
Local Open Scope ring_scope.
Local Notation sgr := Num.sg.
Record rat : Set := Rat {
valq : (int * int);
_ : (0 < valq.2) && coprime `|valq.1| `|valq.2|
}.
Bind Scope ring_scope with rat.
Delimit Scope rat_scope with Q.
Definition ratz (n : int) := @Rat (n, 1) (coprimen1 _).
(* Coercion ratz (n : int) := @Rat (n, 1) (coprimen1 _). *)
Definition rat_isSub := Eval hnf in [isSub for valq].
HB.instance Definition _ := rat_isSub.
#[hnf] HB.instance Definition _ := [Equality of rat by <:].
HB.instance Definition _ := [Countable of rat by <:].
Definition numq x := (valq x).1.
Definition denq x := (valq x).2.
Arguments numq : simpl never.
Arguments denq : simpl never.
Lemma denq_gt0 x : 0 < denq x.
Proof. by rewrite /denq; case: x=> [[a b] /= /andP []]. Qed.
#[global] Hint Resolve denq_gt0 : core.
Definition denq_ge0 x := ltW (denq_gt0 x).
Lemma denq_lt0 x : (denq x < 0) = false. Proof. by rewrite lt_gtF. Qed.
Lemma denq_neq0 x : denq x != 0.
Proof. by rewrite /denq gt_eqF ?denq_gt0. Qed.
#[global] Hint Resolve denq_neq0 : core.
Lemma denq_eq0 x : (denq x == 0) = false.
Proof. exact: negPf (denq_neq0 _). Qed.
Lemma coprime_num_den x : coprime `|numq x| `|denq x|.
Proof. by rewrite /numq /denq; case: x=> [[a b] /= /andP []]. Qed.
Fact RatK x P : @Rat (numq x, denq x) P = x.
Proof. by move: x P => [[a b] P'] P; apply: val_inj. Qed.
Definition fracq_subdef x :=
if x.2 != 0 then let g := gcdn `|x.1| `|x.2| in
((-1) ^ ((x.2 < 0) (+) (x.1 < 0)) * (`|x.1| %/ g)%:Z, (`|x.2| %/ g)%:Z)
else (0, 1).
Arguments fracq_subdef /.
Definition fracq_opt_subdef (x : int * int) :=
if (0 < x.2) && coprime `|x.1| `|x.2| then x else fracq_subdef x.
Lemma fracq_opt_subdefE x : fracq_opt_subdef x = fracq_subdef x.
Proof.
rewrite /fracq_opt_subdef; case: ifP => //; case: x => n d /= /andP[d_gt0 cnd].
rewrite /fracq_subdef gt_eqF//= lt_gtF//= (eqP cnd) !divn1 abszEsg gtz0_abs//.
rewrite mulrA sgz_def mulrnAr -signr_addb addbb expr0.
by have [->|] := eqVneq n 0; rewrite (mulr0, mul1r).
Qed.
Fact fracq_subproof x (y := fracq_opt_subdef x) :
(0 < y.2) && (coprime `|y.1| `|y.2|).
Proof.
rewrite {}/y fracq_opt_subdefE /=; have [] //= := eqVneq x.2 0.
case: x => [/= n d]; rewrite -absz_gt0 => dN0.
have ggt0 : (0 < gcdn `|n| `|d|)%N by rewrite gcdn_gt0 dN0 orbT.
rewrite ltz_nat divn_gt0// dvdn_leq ?dvdn_gcdr//=.
rewrite abszM abszX abszN1 exp1n mul1n absz_nat.
rewrite /coprime -(@eqn_pmul2r (gcdn `|n| `|d|))// mul1n.
by rewrite muln_gcdl !divnK ?(dvdn_gcdl, dvdn_gcdr).
Qed.
Lemma fracq_opt_subdef_id x :
fracq_opt_subdef (fracq_opt_subdef x) = fracq_subdef x.
Proof.
rewrite [fracq_opt_subdef (_ x)]/fracq_opt_subdef.
by rewrite fracq_subproof fracq_opt_subdefE.
Qed.
(* We use a match expression in order to "lock" the definition of fracq. *)
(* Indeed, the kernel will try to reduce a fracq only when applied to *)
(* a term which has "enough" constructors: i.e. it reduces to a pair of *)
(* a Posz or Negz on the first component, and a Posz of 0 or S, or a Negz *)
(* on the second component. See issue #698. *)
(* Additionally, we use fracq_opt_subdef to precompute the normal form *)
(* before we use fracq_subproof in order to make sure the proof will be *)
(* independent from the input of fracq. This ensure reflexivity of any *)
(* computation involving rationals as long as all operators use fracq. *)
(* As a consequence val (fracq x) = fracq_opt_subdef (fracq_opt_subdef x)) *)
Definition fracq '((n', d')) : rat :=
match d', n' with
| Posz 0 as d, _ as n => Rat (fracq_subproof (1, 0))
| _ as d, Posz _ as n | _ as d, _ as n =>
Rat (fracq_subproof (fracq_opt_subdef (n, d)))
end.
Arguments fracq : simpl never.
(* Define a Number Notation for rat in rat_scope *)
(* Since rat values obtained from fracq contain fracq_subdef, which is not *)
(* an inductive constructor, we need to go through an intermediate *)
(* inductive type. *)
Variant Irat_prf := Ifracq_subproof : (int * int) -> Irat_prf.
Variant Irat := IRat : (int * int) -> Irat_prf -> Irat.
Definition parse (x : Number.number) : option Irat :=
let parse_pos i f :=
let nf := Decimal.nb_digits f in
let d := (10 ^ nf)%nat in
let n := (Nat.of_uint i * d + Nat.of_uint f)%nat in
valq (fracq (Posz n, Posz d)) in
let parse i f :=
match i with
| Decimal.Pos i => parse_pos i f
| Decimal.Neg i => let (n, d) := parse_pos i f in ((- n)%R, d)
end in
match x with
| Number.Decimal (Decimal.Decimal i f) =>
let nd := parse i f in
Some (IRat nd (Ifracq_subproof nd))
| Number.Decimal (Decimal.DecimalExp _ _ _) => None
| Number.Hexadecimal _ => None
end.
Definition print (r : Irat) : option Number.number :=
let print_pos n d :=
if d == 1%nat then Some (Nat.to_uint n, Decimal.Nil) else
let d2d5 :=
match prime_decomp d with
| [:: (2, d2); (5, d5)] => Some (d2, d5)
| [:: (2, d2)] => Some (d2, O)
| [:: (5, d5)] => Some (O, d5)
| _ => None
end in
match d2d5 with
| Some (d2, d5) =>
let f := (2 ^ (d5 - d2) * 5 ^ (d2 - d5))%nat in
let (i, f) := edivn (n * f) (d * f) in
Some (Nat.to_uint i, Nat.to_uint f)
| None => None
end in
let print_IRat nd :=
match nd with
| (Posz n, Posz d) =>
match print_pos n d with
| Some (i, f) => Some (Decimal.Pos i, f)
| None => None
end
| (Negz n, Posz d) =>
match print_pos n.+1 d with
| Some (i, f) => Some (Decimal.Neg i, f)
| None => None
end
| (_, Negz _) => None
end in
match r with
| IRat nd _ =>
match print_IRat nd with
| Some (i, f) => Some (Number.Decimal (Decimal.Decimal i f))
| None => None
end
end.
Number Notation rat parse print (via Irat
mapping [Rat => IRat, fracq_subproof => Ifracq_subproof])
: rat_scope.
(* Now, the following should parse as rat (and print unchanged) *)
(* Check 12%Q. *)
(* Check 3.14%Q. *)
(* Check (-3.14)%Q. *)
(* Check 0.5%Q. *)
(* Check 0.2%Q. *)
Lemma val_fracq x : val (fracq x) = fracq_subdef x.
Proof. by case: x => [[n|n] [[|[|d]]|d]]//=; rewrite !fracq_opt_subdef_id. Qed.
Lemma num_fracq x : numq (fracq x) = if x.2 != 0 then
(-1) ^ ((x.2 < 0) (+) (x.1 < 0)) * (`|x.1| %/ gcdn `|x.1| `|x.2|)%:Z else 0.
Proof. by rewrite /numq val_fracq/=; case: ifP. Qed.
Lemma den_fracq x : denq (fracq x) =
if x.2 != 0 then (`|x.2| %/ gcdn `|x.1| `|x.2|)%:Z else 1.
Proof. by rewrite /denq val_fracq/=; case: ifP. Qed.
Fact ratz_frac n : ratz n = fracq (n, 1).
Proof.
by apply: val_inj; rewrite val_fracq/= gcdn1 !divn1 abszE mulr_sign_norm.
Qed.
Fact valqK x : fracq (valq x) = x.
Proof.
move: x => [[n d] /= Pnd]; apply: val_inj; rewrite ?val_fracq/=.
move: Pnd; rewrite /coprime /fracq /= => /andP[] hd -/eqP hnd.
by rewrite lt_gtF ?gt_eqF //= hnd !divn1 mulz_sign_abs abszE gtr0_norm.
Qed.
Definition scalq '(n, d) := sgr d * (gcdn `|n| `|d|)%:Z.
Lemma scalq_def x : scalq x = sgr x.2 * (gcdn `|x.1| `|x.2|)%:Z.
Proof. by case: x. Qed.
Fact scalq_eq0 x : (scalq x == 0) = (x.2 == 0).
Proof.
case: x => n d; rewrite scalq_def /= mulf_eq0 sgr_eq0 /= eqz_nat.
rewrite -[gcdn _ _ == 0]negbK -lt0n gcdn_gt0 ?absz_gt0 [X in ~~ X]orbC.
by case: sgrP.
Qed.
Lemma sgr_scalq x : sgr (scalq x) = sgr x.2.
Proof.
rewrite scalq_def sgrM sgr_id -[(gcdn _ _)%:Z]intz sgr_nat.
by rewrite -lt0n gcdn_gt0 ?absz_gt0 orbC; case: sgrP; rewrite // mul0r.
Qed.
Lemma signr_scalq x : (scalq x < 0) = (x.2 < 0).
Proof. by rewrite -!sgr_cp0 sgr_scalq. Qed.
Lemma scalqE x :
x.2 != 0 -> scalq x = (-1) ^+ (x.2 < 0)%R * (gcdn `|x.1| `|x.2|)%:Z.
Proof. by rewrite scalq_def; case: sgrP. Qed.
Fact valq_frac x :
x.2 != 0 -> x = (scalq x * numq (fracq x), scalq x * denq (fracq x)).
Proof.
move=> x2_neq0; rewrite scalqE//; move: x2_neq0.
case: x => [n d] /= d_neq0; rewrite num_fracq den_fracq/= ?d_neq0.
rewrite mulr_signM -mulrA -!PoszM addKb.
do 2!rewrite muln_divCA ?(dvdn_gcdl, dvdn_gcdr) // divnn.
by rewrite gcdn_gt0 !absz_gt0 d_neq0 orbT !muln1 !mulz_sign_abs.
Qed.
Definition zeroq := 0%Q.
Definition oneq := 1%Q.
Fact frac0q x : fracq (0, x) = zeroq.
Proof.
apply: val_inj; rewrite //= val_fracq/= div0n !gcd0n !mulr0 !divnn.
by have [//|x_neq0] := eqVneq; rewrite absz_gt0 x_neq0.
Qed.
Fact fracq0 x : fracq (x, 0) = zeroq. Proof. exact/eqP. Qed.
Variant fracq_spec (x : int * int) : int * int -> rat -> Type :=
| FracqSpecN of x.2 = 0 : fracq_spec x (x.1, 0) zeroq
| FracqSpecP k fx of k != 0 : fracq_spec x (k * numq fx, k * denq fx) fx.
Fact fracqP x : fracq_spec x x (fracq x).
Proof.
case: x => n d /=; have [d_eq0 | d_neq0] := eqVneq d 0.
by rewrite d_eq0 fracq0; constructor.
by rewrite {2}[(_, _)]valq_frac //; constructor; rewrite scalq_eq0.
Qed.
Lemma rat_eqE x y : (x == y) = (numq x == numq y) && (denq x == denq y).
Proof.
rewrite -val_eqE [val x]surjective_pairing [val y]surjective_pairing /=.
by rewrite xpair_eqE.
Qed.
Lemma sgr_denq x : sgr (denq x) = 1. Proof. by apply/eqP; rewrite sgr_cp0. Qed.
Lemma normr_denq x : `|denq x| = denq x. Proof. by rewrite gtr0_norm. Qed.
Lemma absz_denq x : `|denq x|%N = denq x :> int.
Proof. by rewrite abszE normr_denq. Qed.
Lemma rat_eq x y : (x == y) = (numq x * denq y == numq y * denq x).
Proof.
symmetry; rewrite rat_eqE andbC.
have [->|] /= := eqVneq (denq _); first by rewrite (inj_eq (mulIf _)).
apply: contraNF => /eqP hxy; rewrite -absz_denq -[eqbRHS]absz_denq.
rewrite eqz_nat /= eqn_dvd.
rewrite -(@Gauss_dvdr _ `|numq x|) 1?coprime_sym ?coprime_num_den // andbC.
rewrite -(@Gauss_dvdr _ `|numq y|) 1?coprime_sym ?coprime_num_den //.
by rewrite -!abszM hxy -{1}hxy !abszM !dvdn_mull ?dvdnn.
Qed.
Fact fracq_eq x y : x.2 != 0 -> y.2 != 0 ->
(fracq x == fracq y) = (x.1 * y.2 == y.1 * x.2).
Proof.
case: fracqP=> //= u fx u_neq0 _; case: fracqP=> //= v fy v_neq0 _; symmetry.
rewrite [eqbRHS]mulrC mulrACA [eqbRHS]mulrACA.
by rewrite [denq _ * _]mulrC (inj_eq (mulfI _)) ?mulf_neq0 // rat_eq.
Qed.
Fact fracq_eq0 x : (fracq x == zeroq) = (x.1 == 0) || (x.2 == 0).
Proof.
move: x=> [n d] /=; have [->|d0] := eqVneq d 0.
by rewrite fracq0 eqxx orbT.
by rewrite -[zeroq]valqK orbF fracq_eq ?d0 //= mulr1 mul0r.
Qed.
Fact fracqMM x n d : x != 0 -> fracq (x * n, x * d) = fracq (n, d).
Proof.
move=> x_neq0; apply/eqP.
have [->|d_neq0] := eqVneq d 0; first by rewrite mulr0 !fracq0.
by rewrite fracq_eq ?mulf_neq0 //= mulrCA mulrA.
Qed.
(* We "lock" the definition of addq, oppq, mulq and invq, using a match on *)
(* the constructor Rat for both arguments, so that it may only be reduced *)
(* when applied to explicit rationals. Since fracq is also "locked" in a *)
(* similar way, fracq will not reduce to a Rat x xP unless it is also applied *)
(* to "enough" constructors. This preserves the reduction on gound elements *)
(* while it suspends it when applied to at least one variable at the leaf of *)
(* the arithmetic operation. *)
(* Moreover we optimize addition when one or both arguments are integers, *)
(* in which case we presimplify the output, this shortens the size of the hnf *)
(* of terms of the form N%:Q when N is a concrete natural number. *)
Definition addq_subdef (x y : int * int) :=
let: (x1, x2) := x in
let: (y1, y2) := y in
match x2, y2 with
| Posz 1, Posz 1 =>
match x1, y1 with
| Posz 0, _ => (y1, 1)
| _, Posz 0 => (x1, 1)
| Posz n, Posz 1 => (Posz n.+1, 1)
| Posz 1, Posz n => (Posz n.+1, 1)
| _, _ => (x1 + y1, 1)
end
| Posz 1, _ => (x1 * y2 + y1, y2)
| _, Posz 1 => (x1 + y1 * x2, x2)
| _, _ => (x1 * y2 + y1 * x2, x2 * y2)
end.
Definition addq '(Rat x xP) '(Rat y yP) := fracq (addq_subdef x y).
Lemma addq_def x y : addq x y = fracq (addq_subdef (valq x) (valq y)).
Proof. by case: x; case: y. Qed.
Lemma addq_subdefE x y : addq_subdef x y = (x.1 * y.2 + y.1 * x.2, x.2 * y.2).
Proof.
case: x y => [x1 [[|[|x2]]|x2]] [y1 [[|[|y2]]|y2]]/=; rewrite ?Monoid.simpm//.
by case: x1 y1 => [[|[|m]]|m] [[|[|n]]|n]; rewrite ?Monoid.simpm// -PoszD addn1.
Qed.
Definition oppq_subdef (x : int * int) := (- x.1, x.2).
Definition oppq '(Rat x xP) := fracq (oppq_subdef x).
Definition oppq_def x : oppq x = fracq (oppq_subdef (valq x)).
Proof. by case: x. Qed.
Fact addq_subdefC : commutative addq_subdef.
Proof. by move=> x y; rewrite !addq_subdefE addrC [x.2 * _]mulrC. Qed.
Fact addq_subdefA : associative addq_subdef.
Proof.
move=> x y z; rewrite !addq_subdefE.
by rewrite !mulrA !mulrDl addrA ![_ * x.2]mulrC !mulrA.
Qed.
Fact addq_frac x y : x.2 != 0 -> y.2 != 0 ->
(addq (fracq x) (fracq y)) = fracq (addq_subdef x y).
Proof.
case: fracqP => // u fx u_neq0 _; case: fracqP => // v fy v_neq0 _.
rewrite addq_def !addq_subdefE /=.
rewrite ![(_ * numq _) * _]mulrACA [(_ * denq _) * _]mulrACA.
by rewrite [v * _]mulrC -mulrDr fracqMM ?mulf_neq0.
Qed.
Fact ratzD : {morph ratz : x y / x + y >-> addq x y}.
Proof. by move=> x y; rewrite !ratz_frac addq_frac// addq_subdefE/= !mulr1. Qed.
Fact oppq_frac x : oppq (fracq x) = fracq (oppq_subdef x).
Proof.
rewrite /oppq_subdef; case: fracqP => /= [|u fx u_neq0].
by rewrite fracq0.
by rewrite oppq_def -mulrN fracqMM.
Qed.
Fact ratzN : {morph ratz : x / - x >-> oppq x}.
Proof. by move=> x /=; rewrite !ratz_frac // /add /= !mulr1. Qed.
Fact addqC : commutative addq.
Proof. by move=> x y; rewrite !addq_def /= addq_subdefC. Qed.
Fact addqA : associative addq.
Proof.
move=> x y z; rewrite -[x]valqK -[y]valqK -[z]valqK.
by rewrite ?addq_frac ?addq_subdefA// ?addq_subdefE ?mulf_neq0 ?denq_neq0.
Qed.
Fact add0q : left_id zeroq addq.
Proof.
move=> x; rewrite -[x]valqK -[zeroq]valqK addq_frac ?denq_neq0 // !addq_subdefE.
by rewrite mul0r add0r mulr1 mul1r -surjective_pairing.
Qed.
Fact addNq : left_inverse (fracq (0, 1)) oppq addq.
Proof.
move=> x; rewrite -[x]valqK !(addq_frac, oppq_frac) ?denq_neq0 //.
rewrite !addq_subdefE /oppq_subdef //= mulNr addNr; apply/eqP.
by rewrite fracq_eq ?mulf_neq0 ?denq_neq0 //= !mul0r.
Qed.
HB.instance Definition _ := GRing.isZmodule.Build rat addqA addqC add0q addNq.
Definition mulq_subdef (x y : int * int) :=
let: (x1, x2) := x in
let: (y1, y2) := y in
match x2, y2 with
| Posz 1, Posz 1 => (x1 * y1, 1)
| Posz 1, _ => (x1 * y1, y2)
| _, Posz 1 => (x1 * y1, x2)
| _, _ => (x1 * y1, x2 * y2)
end.
Definition mulq '(Rat x xP) '(Rat y yP) := fracq (mulq_subdef x y).
Lemma mulq_def x y : mulq x y = fracq (mulq_subdef (valq x) (valq y)).
Proof. by case: x; case: y. Qed.
Lemma mulq_subdefE x y : mulq_subdef x y = (x.1 * y.1, x.2 * y.2).
Proof.
by case: x y => [x1 [[|[|x2]]|x2]] [y1 [[|[|y2]]|y2]]/=; rewrite ?Monoid.simpm.
Qed.
Fact mulq_subdefC : commutative mulq_subdef.
Proof. by move=> x y; rewrite !mulq_subdefE mulrC [_ * x.2]mulrC. Qed.
Fact mul_subdefA : associative mulq_subdef.
Proof. by move=> x y z; rewrite !mulq_subdefE !mulrA. Qed.
Definition invq_subdef (x : int * int) := (x.2, x.1).
Definition invq '(Rat x xP) := fracq (invq_subdef x).
Lemma invq_def x : invq x = fracq (invq_subdef (valq x)).
Proof. by case: x. Qed.
Fact mulq_frac x y : (mulq (fracq x) (fracq y)) = fracq (mulq_subdef x y).
Proof.
rewrite mulq_def !mulq_subdefE; case: (fracqP x) => /= [|u fx u_neq0].
by rewrite !mul0r !mul1r fracq0 frac0q.
case: (fracqP y) => /= [|v fy v_neq0].
by rewrite !mulr0 !mulr1 fracq0 frac0q.
by rewrite ![_ * (v * _)]mulrACA [RHS]fracqMM ?mulf_neq0.
Qed.
Fact ratzM : {morph ratz : x y / x * y >-> mulq x y}.
Proof. by move=> x y /=; rewrite !ratz_frac //= !mulr1. Qed.
Fact invq_frac x :
x.1 != 0 -> x.2 != 0 -> invq (fracq x) = fracq (invq_subdef x).
Proof. by rewrite invq_def; case: (fracqP x) => // k ? k0; rewrite fracqMM. Qed.
Fact mulqC : commutative mulq.
Proof. by move=> x y; rewrite !mulq_def mulq_subdefC. Qed.
Fact mulqA : associative mulq.
Proof.
by move=> x y z; rewrite -[x]valqK -[y]valqK -[z]valqK !mulq_frac mul_subdefA.
Qed.
Fact mul1q : left_id oneq mulq.
Proof.
move=> x; rewrite -[x]valqK -[oneq]valqK; rewrite mulq_frac !mulq_subdefE.
by rewrite !mul1r -surjective_pairing.
Qed.
Fact mulq_addl : left_distributive mulq addq.
Proof.
move=> x y z; rewrite -[x]valqK -[y]valqK -[z]valqK /=.
rewrite !(mulq_frac, addq_frac, mulq_subdefE, addq_subdefE) ?mulf_neq0 ?denq_neq0 //=.
apply/eqP; rewrite fracq_eq ?mulf_neq0 ?denq_neq0 //= !mulrDl; apply/eqP.
by rewrite !mulrA ![_ * (valq z).1]mulrC !mulrA ![_ * (valq x).2]mulrC !mulrA.
Qed.
Fact nonzero1q : oneq != zeroq. Proof. by []. Qed.
HB.instance Definition _ :=
GRing.Zmodule_isComNzRing.Build rat mulqA mulqC mul1q mulq_addl nonzero1q.
Fact mulVq x : x != 0 -> mulq (invq x) x = 1.
Proof.
rewrite -[x]valqK -[0]valqK fracq_eq ?denq_neq0 //= mulr1 mul0r=> nx0.
rewrite !(mulq_frac, invq_frac, mulq_subdefE) ?denq_neq0 // -[1]valqK.
by apply/eqP; rewrite fracq_eq ?mulf_neq0 ?denq_neq0 //= mulr1 mul1r mulrC.
Qed.
Fact invq0 : invq 0 = 0. Proof. exact/eqP. Qed.
HB.instance Definition _ := GRing.ComNzRing_isField.Build rat mulVq invq0.
Lemma numq_eq0 x : (numq x == 0) = (x == 0).
Proof.
rewrite -[x]valqK fracq_eq0; case: fracqP=> /= [|k {}x k0].
by rewrite eqxx orbT.
by rewrite !mulf_eq0 (negPf k0) /= denq_eq0 orbF.
Qed.
Notation "n %:Q" := ((n : int)%:~R : rat) : ring_scope.
#[global] Hint Resolve denq_neq0 denq_gt0 denq_ge0 : core.
Definition subq (x y : rat) : rat := (addq x (oppq y)).
Definition divq (x y : rat) : rat := (mulq x (invq y)).
Infix "+" := addq : rat_scope.
Notation "- x" := (oppq x) : rat_scope.
Infix "*" := mulq : rat_scope.
Notation "x ^-1" := (invq x) : rat_scope.
Infix "-" := subq : rat_scope.
Infix "/" := divq : rat_scope.
(* ratz should not be used, %:Q should be used instead *)
Lemma ratzE n : ratz n = n%:Q.
Proof.
elim: n=> [|n ihn|n ihn]; first by rewrite mulr0z ratz_frac.
by rewrite intS mulrzDr ratzD ihn.
by rewrite intS opprD mulrzDr ratzD ihn.
Qed.
Lemma numq_int n : numq n%:Q = n. Proof. by rewrite -ratzE. Qed.
Lemma denq_int n : denq n%:Q = 1. Proof. by rewrite -ratzE. Qed.
Lemma rat0 : 0%:Q = 0. Proof. by []. Qed.
Lemma rat1 : 1%:Q = 1. Proof. by []. Qed.
Lemma numqN x : numq (- x) = - numq x.
Proof.
rewrite [- _]oppq_def/= num_fracq.
case: x => -[a b]; rewrite /numq/= => /andP[b_gt0].
rewrite /coprime => /eqP cab.
by rewrite lt_gtF ?gt_eqF // {2}abszN cab divn1 mulz_sign_abs.
Qed.
Lemma denqN x : denq (- x) = denq x.
Proof.
rewrite [- _]oppq_def den_fracq.
case: x => -[a b]; rewrite /denq/= => /andP[b_gt0].
by rewrite /coprime=> /eqP cab; rewrite gt_eqF // abszN cab divn1 gtz0_abs.
Qed.
(* Will be subsumed by pnatr_eq0 *)
Fact intq_eq0 n : (n%:~R == 0 :> rat) = (n == 0)%N.
Proof. by rewrite -ratzE /ratz rat_eqE/= /numq /denq/= eqxx andbT. Qed.
(* fracq should never appear, its canonical form is _%:Q / _%:Q *)
Lemma fracqE x : fracq x = x.1%:Q / x.2%:Q.
Proof.
move: x => [m n] /=; apply/val_inj; rewrite val_fracq/=.
case: eqVneq => //= [->|n_neq0]; first by rewrite rat0 invr0 mulr0.
rewrite -[m%:Q]valqK -[n%:Q]valqK.
rewrite [_^-1]invq_frac ?denq_neq0 ?numq_eq0 ?intq_eq0//=.
rewrite [X in valq X]mulq_frac val_fracq /invq_subdef !mulq_subdefE/=.
by rewrite -!/(numq _) -!/(denq _) !numq_int !denq_int mul1r mulr1 n_neq0.
Qed.
Lemma divq_num_den x : (numq x)%:Q / (denq x)%:Q = x.
Proof. by rewrite -{3}[x]valqK [valq _]surjective_pairing /= fracqE. Qed.
Variant divq_spec (n d : int) : int -> int -> rat -> Type :=
| DivqSpecN of d = 0 : divq_spec n d n 0 0
| DivqSpecP k x of k != 0 : divq_spec n d (k * numq x) (k * denq x) x.
(* replaces fracqP *)
Lemma divqP n d : divq_spec n d n d (n%:Q / d%:Q).
Proof.
set x := (n, d); rewrite -[n]/x.1 -[d]/x.2 -fracqE.
by case: fracqP => [_|k fx k_neq0] /=; constructor.
Qed.
Variant rat_spec (* (x : rat) *) : rat -> int -> int -> Type :=
Rat_spec (n : int) (d : nat) & coprime `|n| d.+1
: rat_spec (* x *) (n%:Q / d.+1%:Q) n d.+1.
Lemma ratP x : rat_spec x (numq x) (denq x).
Proof.
rewrite -{1}[x](divq_num_den); case hd: denq => [p|n].
have: 0 < p%:Z by rewrite -hd denq_gt0.
case: p hd=> //= n hd; constructor; rewrite -?hd ?divq_num_den //.
by rewrite -[n.+1]/`|n.+1|%N -hd coprime_num_den.
by move: (denq_gt0 x); rewrite hd.
Qed.
Lemma coprimeq_num n d : coprime `|n| `|d| -> numq (n%:~R / d%:~R) = sgr d * n.
Proof.
move=> cnd /=; have <- := fracqE (n, d).
rewrite num_fracq/= (eqP (cnd : _ == 1)) divn1.
have [|d_gt0|d_lt0] := sgrP d;
by rewrite (mul0r, mul1r, mulN1r) //= ?[_ ^ _]signrN ?mulNr mulz_sign_abs.
Qed.
Lemma coprimeq_den n d :
coprime `|n| `|d| -> denq (n%:~R / d%:~R) = (if d == 0 then 1 else `|d|).
Proof.
move=> cnd; have <- := fracqE (n, d).
by rewrite den_fracq/= (eqP (cnd : _ == 1)) divn1; case: d {cnd}; case.
Qed.
Lemma denqVz (i : int) : i != 0 -> denq (i%:~R^-1) = `|i|.
Proof.
move=> h; rewrite -div1r -[1]/(1%:~R).
by rewrite coprimeq_den /= ?coprime1n // (negPf h).
Qed.
Lemma numqE x : (numq x)%:~R = x * (denq x)%:~R.
Proof. by rewrite -{2}[x]divq_num_den divfK // intq_eq0 denq_eq0. Qed.
Lemma denqP x : {d | denq x = d.+1}.
Proof. by rewrite /denq; case: x => [[_ [[|d]|]] //= _]; exists d. Qed.
Definition normq '(Rat x _) : rat := `|x.1|%:~R / (x.2)%:~R.
Definition le_rat '(Rat x _) '(Rat y _) := x.1 * y.2 <= y.1 * x.2.
Definition lt_rat '(Rat x _) '(Rat y _) := x.1 * y.2 < y.1 * x.2.
Lemma normqE x : normq x = `|numq x|%:~R / (denq x)%:~R.
Proof. by case: x. Qed.
Lemma le_ratE x y : le_rat x y = (numq x * denq y <= numq y * denq x).
Proof. by case: x; case: y. Qed.
Lemma lt_ratE x y : lt_rat x y = (numq x * denq y < numq y * denq x).
Proof. by case: x; case: y. Qed.
Lemma gt_rat0 x : lt_rat 0 x = (0 < numq x).
Proof. by rewrite lt_ratE mul0r mulr1. Qed.
Lemma lt_rat0 x : lt_rat x 0 = (numq x < 0).
Proof. by rewrite lt_ratE mul0r mulr1. Qed.
Lemma ge_rat0 x : le_rat 0 x = (0 <= numq x).
Proof. by rewrite le_ratE mul0r mulr1. Qed.
Lemma le_rat0 x : le_rat x 0 = (numq x <= 0).
Proof. by rewrite le_ratE mul0r mulr1. Qed.
Fact le_rat0D x y : le_rat 0 x -> le_rat 0 y -> le_rat 0 (x + y).
Proof.
rewrite !ge_rat0 => hnx hny.
have hxy: (0 <= numq x * denq y + numq y * denq x).
by rewrite addr_ge0 ?mulr_ge0.
rewrite [_ + _]addq_def /numq /= -!/(denq _) ?mulf_eq0 ?denq_eq0.
rewrite val_fracq/=; case: ifP => //=.
by rewrite ?addq_subdefE !mulr_ge0// !le_gtF ?mulr_ge0 ?denq_ge0//=.
Qed.
Fact le_rat0M x y : le_rat 0 x -> le_rat 0 y -> le_rat 0 (x * y).
Proof.
rewrite !ge_rat0 => hnx hny.
have hxy: (0 <= numq x * denq y + numq y * denq x).
by rewrite addr_ge0 ?mulr_ge0.
rewrite [_ * _]mulq_def /numq /= -!/(denq _) ?mulf_eq0 ?denq_eq0.
rewrite val_fracq/=; case: ifP => //=.
by rewrite ?mulq_subdefE !mulr_ge0// !le_gtF ?mulr_ge0 ?denq_ge0//=.
Qed.
Fact le_rat0_anti x : le_rat 0 x -> le_rat x 0 -> x = 0.
Proof.
by move=> hx hy; apply/eqP; rewrite -numq_eq0 eq_le -ge_rat0 -le_rat0 hx hy.
Qed.
Lemma sgr_numq_div (n d : int) : sgr (numq (n%:Q / d%:Q)) = sgr n * sgr d.
Proof.
set x := (n, d); rewrite -[n]/x.1 -[d]/x.2 -fracqE.
case: fracqP => [|k fx k_neq0] /=; first by rewrite mulr0.
by rewrite !sgrM mulrACA -expr2 sqr_sg k_neq0 sgr_denq mulr1 mul1r.
Qed.
Fact subq_ge0 x y : le_rat 0 (y - x) = le_rat x y.
Proof.
symmetry; rewrite ge_rat0 !le_ratE -subr_ge0.
case: ratP => nx dx cndx; case: ratP => ny dy cndy.
rewrite -!mulNr addf_div ?intq_eq0 // !mulNr -!rmorphM -rmorphB /=.
symmetry; rewrite !leNgt -sgr_cp0 sgr_numq_div mulrC gtr0_sg //.
by rewrite mul1r sgr_cp0.
Qed.
Fact le_rat_total : total le_rat.
Proof. by move=> x y; rewrite !le_ratE; apply: le_total. Qed.
Fact numq_sign_mul (b : bool) x : numq ((-1) ^+ b * x) = (-1) ^+ b * numq x.
Proof. by case: b; rewrite ?(mul1r, mulN1r) // numqN. Qed.
Fact numq_div_lt0 n d : n != 0 -> d != 0 ->
(numq (n%:~R / d%:~R) < 0)%R = (n < 0)%R (+) (d < 0)%R.
Proof.
move=> n0 d0; rewrite -sgr_cp0 sgr_numq_div !sgr_def n0 d0.
by rewrite !mulr1n -signr_addb; case: (_ (+) _).
Qed.
Lemma normr_num_div n d : `|numq (n%:~R / d%:~R)| = numq (`|n|%:~R / `|d|%:~R).
Proof.
rewrite (normrEsg n) (normrEsg d) !rmorphM /= invfM mulrACA !sgr_def.
have [->|n_neq0] := eqVneq; first by rewrite mul0r mulr0.
have [->|d_neq0] := eqVneq; first by rewrite invr0 !mulr0.
rewrite !intr_sign invr_sign -signr_addb numq_sign_mul -numq_div_lt0 //.
by apply: (canRL (signrMK _)); rewrite mulz_sign_abs.
Qed.
Fact norm_ratN x : normq (- x) = normq x.
Proof. by rewrite !normqE numqN denqN normrN. Qed.
Fact ge_rat0_norm x : le_rat 0 x -> normq x = x.
Proof.
rewrite ge_rat0; case: ratP=> [] // n d cnd n_ge0.
by rewrite normqE /= normr_num_div ?ger0_norm // divq_num_den.
Qed.
Fact lt_rat_def x y : (lt_rat x y) = (y != x) && (le_rat x y).
Proof. by rewrite lt_ratE le_ratE lt_def rat_eq. Qed.
HB.instance Definition _ :=
Num.IntegralDomain_isLeReal.Build rat le_rat0D le_rat0M le_rat0_anti
subq_ge0 (@le_rat_total 0) norm_ratN ge_rat0_norm lt_rat_def.
Lemma numq_ge0 x : (0 <= numq x) = (0 <= x).
Proof.
by case: ratP => n d cnd; rewrite ?pmulr_lge0 ?invr_gt0 (ler0z, ltr0z).
Qed.
Lemma numq_le0 x : (numq x <= 0) = (x <= 0).
Proof. by rewrite -oppr_ge0 -numqN numq_ge0 oppr_ge0. Qed.
Lemma numq_gt0 x : (0 < numq x) = (0 < x).
Proof. by rewrite !ltNge numq_le0. Qed.
Lemma numq_lt0 x : (numq x < 0) = (x < 0).
Proof. by rewrite !ltNge numq_ge0. Qed.
Lemma sgr_numq x : sgz (numq x) = sgz x.
Proof.
apply/eqP; case: (sgzP x); rewrite sgz_cp0 ?(numq_gt0, numq_lt0) //.
by move->.
Qed.
Lemma denq_mulr_sign (b : bool) x : denq ((-1) ^+ b * x) = denq x.
Proof. by case: b; rewrite ?(mul1r, mulN1r) // denqN. Qed.
Lemma denq_norm x : denq `|x| = denq x.
Proof. by rewrite normrEsign denq_mulr_sign. Qed.
Module ratArchimedean.
Section ratArchimedean.
Implicit Types x : rat.
Definition floor x : int := (numq x %/ denq x)%Z.
Definition ceil x : int := - (- numq x %/ denq x)%Z.
Definition truncn x : nat :=
if 0 <= x then (`|numq x| %/ `|denq x|)%N else 0%N.
Let is_int x := denq x == 1.
Let is_nat x := (0 <= x) && (denq x == 1).
Fact floorP x :
if x \is Num.real then (floor x)%:~R <= x < (floor x + 1)%:~R
else floor x == 0.
Proof.
rewrite num_real /floor; case: (ratP x) => n d _ {x}; rewrite ler_pdivlMr//.
by rewrite ltr_pdivrMr// -!intrM ler_int ltr_int lez_floor ?ltz_ceil.
Qed.
Fact ceilP x : ceil x = - floor (- x).
Proof. by rewrite /ceil /floor numqN denqN. Qed.
Fact truncnP x : truncn x = if floor x is Posz n then n else 0.
Proof.
rewrite /truncn /floor; case: (ratP x) => n d _ {x} /=.
by rewrite !ler_pdivlMr// mul0r; case: n => n; rewrite ler0z//= mul1n.
Qed.
Fact intrP x : reflect (exists n, x = n%:~R) (is_int x).
Proof.
apply: (iffP idP) => [/eqP d1 | [i ->]]; [|by rewrite /is_int denq_int].
by exists (numq x); case: (ratP x) d1 => n d _ ->; rewrite divr1.
Qed.
Fact natrP x : reflect (exists n, x = n%:R) (is_nat x).
Proof.
apply: (iffP idP) => [/andP[]/[swap]/intrP[i ->]|[n ->]].
by rewrite ler0z; case: i => [n _|//]; exists n.
by rewrite /is_nat pmulrn ler0z denq_int.
Qed.
End ratArchimedean.
End ratArchimedean.
HB.instance Definition _ :=
Num.NumDomain_hasFloorCeilTruncn.Build rat
ratArchimedean.floorP ratArchimedean.ceilP ratArchimedean.truncnP
ratArchimedean.intrP ratArchimedean.natrP.
Lemma floorErat (x : rat) : Num.floor x = (numq x %/ denq x)%Z.
Proof. by []. Qed.
Lemma ceilErat (x : rat) : Num.ceil x = - (- numq x %/ denq x)%Z.
Proof. by []. Qed.
Lemma Qint_def (x : rat) : (x \is a Num.int) = (denq x == 1). Proof. by []. Qed.
Lemma numqK : {in Num.int, cancel (fun x => numq x) intr}.
Proof. by move=> _ /intrP [x ->]; rewrite numq_int. Qed.
Lemma natq_div m n : (n %| m)%N -> (m %/ n)%:R = m%:R / n%:R :> rat.
Proof. exact/pchar0_natf_div/pchar_num. Qed.
Section InRing.
Variable R : unitRingType.
Definition ratr x : R := (numq x)%:~R / (denq x)%:~R.
Lemma ratr_int z : ratr z%:~R = z%:~R.
Proof. by rewrite /ratr numq_int denq_int divr1. Qed.
Lemma ratr_nat n : ratr n%:R = n%:R.
Proof. exact: ratr_int n. Qed.
Lemma rpred_rat (S : divringClosed R) a : ratr a \in S.
Proof. by rewrite rpred_div ?rpred_int. Qed.
End InRing.
Section Fmorph.
Implicit Type rR : unitRingType.
Lemma fmorph_rat (aR : fieldType) rR (f : {rmorphism aR -> rR}) a :
f (ratr _ a) = ratr _ a.
Proof. by rewrite fmorph_div !rmorph_int. Qed.
Lemma fmorph_eq_rat rR (f : {rmorphism rat -> rR}) : f =1 ratr _.
Proof. by move=> a; rewrite -{1}[a]divq_num_den fmorph_div !rmorph_int. Qed.
End Fmorph.
Section Linear.
Implicit Types (U V : lmodType rat) (A B : lalgType rat).
Lemma rat_linear U V (f : U -> V) : zmod_morphism f -> scalable f.
Proof.
move=> fB a u.
pose aM := GRing.isZmodMorphism.Build U V f fB.
pose phi : {additive U -> V} := HB.pack f aM.
rewrite -[f]/(phi : _ -> _) -{2}[a]divq_num_den mulrC -scalerA.
apply: canRL (scalerK _) _; first by rewrite intr_eq0 denq_neq0.
rewrite 2!scaler_int -3!raddfMz /=.
by rewrite -scalerMzr scalerMzl -mulrzr -numqE scaler_int.
Qed.
End Linear.
Section InPrealField.
Variable F : numFieldType.
Fact ratr_is_zmod_morphism : zmod_morphism (@ratr F).
Proof.
have injZtoQ: @injective rat int intr by apply: intr_inj.
have nz_den x: (denq x)%:~R != 0 :> F by rewrite intr_eq0 denq_eq0.
move=> x y.
apply: (canLR (mulfK (nz_den _))); apply: (mulIf (nz_den x)).
rewrite mulrAC mulrBl divfK ?nz_den // mulrAC -!rmorphM.
apply: (mulIf (nz_den y)); rewrite mulrAC mulrBl divfK ?nz_den //.
rewrite -!(rmorphM, rmorphB); congr _%:~R; apply: injZtoQ.
rewrite !(rmorphM, rmorphB) /= [_ - _]lock /= -lock !numqE.
by rewrite (mulrAC y) -!mulrBl -mulrA mulrAC !mulrA.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `ratr_is_additive` instead")]
Definition ratr_is_additive := ratr_is_zmod_morphism.
Fact ratr_is_monoid_morphism : monoid_morphism (@ratr F).
Proof.
have injZtoQ: @injective rat int intr by apply: intr_inj.
have nz_den x: (denq x)%:~R != 0 :> F by rewrite intr_eq0 denq_eq0.
split=> [|x y]; first by rewrite /ratr divr1.
rewrite /ratr mulrC mulrAC; apply: canLR (mulKf (nz_den _)) _; rewrite !mulrA.
do 2!apply: canRL (mulfK (nz_den _)) _; rewrite -!rmorphM; congr _%:~R.
apply: injZtoQ; rewrite !rmorphM [x * y]lock /= !numqE -lock.
by rewrite -!mulrA mulrA mulrCA -!mulrA (mulrCA y).
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `ratr_is_monoid_morphism` instead")]
Definition ratr_is_multiplicative :=
(fun g => (g.2,g.1)) ratr_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build rat F (@ratr F)
ratr_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build rat F (@ratr F)
ratr_is_monoid_morphism.
Lemma ler_rat : {mono (@ratr F) : x y / x <= y}.
Proof.
move=> x y /=; case: (ratP x) => nx dx cndx; case: (ratP y) => ny dy cndy.
rewrite !fmorph_div /= !ratr_int !ler_pdivlMr ?ltr0z //.
by rewrite ![_ / _ * _]mulrAC !ler_pdivrMr ?ltr0z // -!rmorphM /= !ler_int.
Qed.
Lemma ltr_rat : {mono (@ratr F) : x y / x < y}.
Proof. exact: leW_mono ler_rat. Qed.
Lemma ler0q x : (0 <= ratr F x) = (0 <= x).
Proof. by rewrite (_ : 0 = ratr F 0) ?ler_rat ?rmorph0. Qed.
Lemma lerq0 x : (ratr F x <= 0) = (x <= 0).
Proof. by rewrite (_ : 0 = ratr F 0) ?ler_rat ?rmorph0. Qed.
Lemma ltr0q x : (0 < ratr F x) = (0 < x).
Proof. by rewrite (_ : 0 = ratr F 0) ?ltr_rat ?rmorph0. Qed.
Lemma ltrq0 x : (ratr F x < 0) = (x < 0).
Proof. by rewrite (_ : 0 = ratr F 0) ?ltr_rat ?rmorph0. Qed.
Lemma ratr_sg x : ratr F (sgr x) = sgr (ratr F x).
Proof. by rewrite !sgr_def fmorph_eq0 ltrq0 rmorphMn /= rmorph_sign. Qed.
Lemma ratr_norm x : ratr F `|x| = `|ratr F x|.
Proof.
by rewrite {2}[x]numEsign rmorphMsign normrMsign [`|ratr F _|]ger0_norm ?ler0q.
Qed.
Lemma minr_rat : {morph ratr F : x y / Num.min x y}.
Proof. by move=> x y; rewrite !minEle ler_rat; case: leP. Qed.
Lemma maxr_rat : {morph ratr F : x y / Num.max x y}.
Proof. by move=> x y; rewrite !maxEle ler_rat; case: leP. Qed.
End InPrealField.
Section InParchiField.
Variable F : archiNumFieldType.
Lemma floor_rat : {mono (@ratr F) : x / Num.floor x}.
Proof.
move=> x; apply: floor_def; apply/andP; split.
- by rewrite -ratr_int ler_rat floor_le_tmp.
- by rewrite -ratr_int ltr_rat floorD1_gt.
Qed.
Lemma ceil_rat : {mono (@ratr F) : x / Num.ceil x}.
Proof. by move=> x; rewrite !ceilNfloor -rmorphN floor_rat. Qed.
End InParchiField.
Arguments ratr {R}.
Lemma Qint_dvdz (m d : int) : (d %| m)%Z -> (m%:~R / d%:~R : rat) \is a Num.int.
Proof.
case/dvdzP=> z ->; rewrite rmorphM /=; have [->|dn0] := eqVneq d 0.
by rewrite mulr0 mul0r.
by rewrite mulfK ?intr_eq0.
Qed.
Lemma Qnat_dvd (m d : nat) : (d %| m)%N -> (m%:R / d%:R : rat) \is a Num.nat.
Proof. by move=> h; rewrite natrEint divr_ge0 ?ler0n // !pmulrn Qint_dvdz. Qed.
Section ZpolyScale.
Local Notation pZtoQ := (map_poly (intr : int -> rat)).
Lemma size_rat_int_poly p : size (pZtoQ p) = size p.
Proof. by apply: size_map_inj_poly; first apply: intr_inj. Qed.
Lemma rat_poly_scale (p : {poly rat}) :
{q : {poly int} & {a | a != 0 & p = a%:~R^-1 *: pZtoQ q}}.
Proof.
pose a := \prod_(i < size p) denq p`_i.
have nz_a: a != 0 by apply/prodf_neq0=> i _; apply: denq_neq0.
exists (map_poly numq (a%:~R *: p)), a => //.
apply: canRL (scalerK _) _; rewrite ?intr_eq0 //.
apply/polyP=> i; rewrite !(coefZ, coef_map_id0) // numqK // Qint_def mulrC.
have [ltip | /(nth_default 0)->] := ltnP i (size p); last by rewrite mul0r.
by rewrite [a](bigD1 (Ordinal ltip)) // rmorphM mulrA -numqE -rmorphM denq_int.
Qed.
Lemma dvdp_rat_int p q : (pZtoQ p %| pZtoQ q) = (p %| q).
Proof.
apply/dvdpP/Pdiv.Idomain.dvdpP=> [[/= r1 Dq] | [[/= a r] nz_a Dq]]; last first.
exists (a%:~R^-1 *: pZtoQ r).
by rewrite -scalerAl -rmorphM -Dq /= linearZ/= scalerK ?intr_eq0.
have [r [a nz_a Dr1]] := rat_poly_scale r1; exists (a, r) => //=.
apply: (map_inj_poly _ _ : injective pZtoQ) => //; first exact: intr_inj.
by rewrite linearZ /= Dq Dr1 -scalerAl -rmorphM scalerKV ?intr_eq0.
Qed.
Lemma dvdpP_rat_int p q :
p %| pZtoQ q ->
{p1 : {poly int} & {a | a != 0 & p = a *: pZtoQ p1} & {r | q = p1 * r}}.
Proof.
have{p} [p [a nz_a ->]] := rat_poly_scale p.
rewrite dvdpZl ?invr_eq0 ?intr_eq0 // dvdp_rat_int => dv_p_q.
exists (zprimitive p); last exact: dvdpP_int.
have [-> | nz_p] := eqVneq p 0.
by exists 1; rewrite ?oner_eq0 // zprimitive0 map_poly0 !scaler0.
exists ((zcontents p)%:~R / a%:~R).
by rewrite mulf_neq0 ?invr_eq0 ?intr_eq0 ?zcontents_eq0.
by rewrite mulrC -scalerA -map_polyZ -zpolyEprim.
Qed.
Lemma irreducible_rat_int p :
irreducible_poly (pZtoQ p) <-> irreducible_poly p.
Proof.
rewrite /irreducible_poly size_rat_int_poly; split=> -[] p1 p_irr; split=> //.
move=> q q1; rewrite /eqp -!dvdp_rat_int => rq.
by apply/p_irr => //; rewrite size_rat_int_poly.
move=> q + /dvdpP_rat_int [] r [] c c0 qE [] s sE.
rewrite qE size_scale// size_rat_int_poly => r1.
apply/(eqp_trans (eqp_scale _ c0)).
rewrite /eqp !dvdp_rat_int; apply/p_irr => //.
by rewrite sE dvdp_mulIl.
Qed.
End ZpolyScale.
(* Integral spans. *)
Definition inIntSpan (V : zmodType) m (s : m.-tuple V) v :=
exists a : int ^ m, v = \sum_(i < m) s`_i *~ a i.
Lemma solve_Qint_span (vT : vectType rat) m (s : m.-tuple vT) v :
{b : int ^ m &
{p : seq (int ^ m) &
forall a : int ^ m,
v = \sum_(i < m) s`_i *~ a i <->
exists c : seq int, a = b + \sum_(i < size p) p`_i *~ c`_i}} +
(~ inIntSpan s v).
Proof.
have s_s (i : 'I_m): s`_i \in <<s>>%VS by rewrite memv_span ?memt_nth.
have s_Zs a: \sum_(i < m) s`_i *~ a i \in <<s>>%VS.
by apply/rpred_sum => i _; apply/rpredMz.
case s_v: (v \in <<s>>%VS); last by right=> [[a Dv]]; rewrite Dv s_Zs in s_v.
move SE : (\matrix_(i < m, j < _) coord (vbasis <<s>>) j s`_i) => S.
move rE : (\rank S) => r; move kE : (m - r)%N => k.
have Dm: (m = k + r)%N by rewrite -kE -rE subnK ?rank_leq_row.
rewrite Dm in s s_s s_Zs s_v S SE rE kE *.
move=> {Dm m}; pose m := (k + r)%N.
have [K kerK]: {K : 'M_(k, m) | map_mx intr K == kermx S}%MS.
move: (mxrank_ker S); rewrite rE kE => krk.
pose B := row_base (kermx S); pose d := \prod_ij denq (B ij.1 ij.2).
exists (castmx (krk, erefl m) (map_mx numq (intr d *: B))).
rewrite map_castmx !eqmx_cast -map_mx_comp map_mx_id_in => [|i j]; last first.
rewrite mxE mulrC [d](bigD1 (i, j)) //= rmorphM mulrA.
by rewrite -numqE -rmorphM numq_int.
suff nz_d: d%:Q != 0 by rewrite !eqmx_scale // !eq_row_base andbb.
by rewrite intr_eq0; apply/prodf_neq0 => i _; apply: denq_neq0.
have [L _ [G uG [D _ defK]]] := int_Smith_normal_form K.
have {K L D defK kerK} [kerGu kerS_sub_Gu]: map_mx intr (usubmx G) *m S = 0 /\
(kermx S <= map_mx intr (usubmx G))%MS.
pose Kl : 'M[rat]_k := map_mx intr (lsubmx (K *m invmx G)).
have {}defK: map_mx intr K = Kl *m map_mx intr (usubmx G).
rewrite /Kl -map_mxM; congr map_mx.
rewrite -[LHS](mulmxKV uG) -{2}[G]vsubmxK -{1}[K *m _]hsubmxK.
rewrite mul_row_col -[RHS]addr0; congr (_ + _).
rewrite defK mulmxK //= -[RHS](mul0mx _ (dsubmx G)); congr (_ *m _).
apply/matrixP => i j; rewrite !mxE big1 //= => j1 _.
rewrite mxE /= eqn_leq andbC.
by rewrite leqNgt (leq_trans (valP j1)) ?mulr0 ?leq_addr.
split; last by rewrite -(eqmxP kerK); apply/submxP; exists Kl.
suff /row_full_inj: row_full Kl.
by apply; rewrite mulmx0 mulmxA (sub_kermxP _) // -(eqmxP kerK) defK.
rewrite /row_full eqn_leq rank_leq_row /= -{1}kE -{2}rE -(mxrank_ker S).
by rewrite -(eqmxP kerK) defK mxrankM_maxl.
pose T := map_mx intr (dsubmx G) *m S.
have defS: map_mx intr (rsubmx (invmx G)) *m T = S.
rewrite mulmxA -map_mxM /=; move: (mulVmx uG).
rewrite -{2}[G]vsubmxK -{1}[invmx G]hsubmxK mul_row_col.
move/(canRL (addKr _)) ->; rewrite -mulNmx raddfD /= map_mx1 map_mxM /=.
by rewrite mulmxDl -mulmxA kerGu mulmx0 add0r mul1mx.
pose vv := \row_j coord (vbasis <<s>>) j v.
have uS: row_full S.
apply/row_fullP; exists (\matrix_(i, j) coord s j (vbasis <<s>>)`_i).
apply/matrixP => j1 j2; rewrite !mxE.
rewrite -(coord_free _ _ (basis_free (vbasisP _))).
rewrite -!tnth_nth (coord_span (vbasis_mem (mem_tnth j1 _))) linear_sum.
by apply: eq_bigr => /= i _; rewrite -SE !mxE (tnth_nth 0) !linearZ.
have eqST: (S :=: T)%MS by apply/eqmxP; rewrite -{1}defS !submxMl.
case Zv: (map_mx denq (vv *m pinvmx T) == const_mx 1); last first.
right=> [[a Dv]]; case/eqP: Zv; apply/rowP.
have ->: vv = map_mx intr (\row_i a i) *m S.
apply/rowP => j; rewrite !mxE Dv linear_sum.
by apply: eq_bigr => i _; rewrite -SE -scaler_int linearZ !mxE.
rewrite -defS -2!mulmxA; have ->: T *m pinvmx T = 1%:M.
have uT: row_free T by rewrite /row_free -eqST rE.
by apply: (row_free_inj uT); rewrite mul1mx mulmxKpV.
by move=> i; rewrite mulmx1 -map_mxM 2!mxE denq_int mxE.
pose b := map_mx numq (vv *m pinvmx T) *m dsubmx G.
left; exists [ffun j => b 0 j], [seq [ffun j => (usubmx G) i j] | i : 'I_k].
rewrite size_image card_ord => a; rewrite -[a](addNKr [ffun j => b 0 j]).
move: (_ + a) => h; under eq_bigr => i _ do rewrite !ffunE mulrzDr.
rewrite big_split /=.
have <-: v = \sum_(i < m) s`_i *~ b 0 i.
transitivity (\sum_j (map_mx intr b *m S) 0 j *: (vbasis <<s>>)`_j).
rewrite {1}(coord_vbasis s_v); apply: eq_bigr => j _; congr (_ *: _).
suff ->: map_mx intr b = vv *m pinvmx T *m map_mx intr (dsubmx G).
by rewrite -(mulmxA _ _ S) mulmxKpV ?mxE // -eqST submx_full.
rewrite map_mxM /=; congr (_ *m _); apply/rowP => i; rewrite 2!mxE numqE.
by have /eqP/rowP/(_ i)/[!mxE] -> := Zv; rewrite mulr1.
rewrite (coord_vbasis (s_Zs _)); apply: eq_bigr => j _; congr (_ *: _).
rewrite linear_sum mxE; apply: eq_bigr => i _.
by rewrite -SE -scaler_int linearZ [b]lock !mxE.
split.
rewrite -[LHS]addr0 => /addrI hP; pose c := \row_i h i *m lsubmx (invmx G).
exists [seq c 0 i | i : 'I_k]; congr (_ + _).
have/sub_kermxP: map_mx intr (\row_i h i) *m S = 0.
transitivity (\row_j coord (vbasis <<s>>) j (\sum_(i < m) s`_i *~ h i)).
apply/rowP => j; rewrite !mxE linear_sum; apply: eq_bigr => i _.
by rewrite -SE !mxE -scaler_int linearZ.
by apply/rowP => j; rewrite !mxE -hP linear0.
case/submx_trans/(_ kerS_sub_Gu)/submxP => c' /[dup].
move/(congr1 (mulmx^~ (map_mx intr (lsubmx (invmx G))))).
rewrite -mulmxA -!map_mxM [in RHS]mulmx_lsub mul_usub_mx -/c mulmxV //=.
rewrite scalar_mx_block -/(ulsubmx _) block_mxKul map_scalar_mx mulmx1.
move=> <- {c'}; rewrite -map_mxM /= => defh; apply/ffunP => j.
move/rowP/(_ j): defh; rewrite sum_ffunE !mxE => /intr_inj ->.
apply: eq_bigr => i _; rewrite ffunMzE mulrzz mulrC.
rewrite (nth_map i) ?size_enum_ord // nth_ord_enum ffunE.
by rewrite (nth_map i) ?size_enum_ord // nth_ord_enum.
case=> c /addrI -> {h}; rewrite -[LHS]addr0; congr (_ + _).
pose h := \row_(j < k) c`_j *m usubmx G.
transitivity (\sum_j (map_mx intr h *m S) 0 j *: (vbasis <<s>>)`_j).
by rewrite map_mxM -mulmxA kerGu mulmx0 big1 // => j _; rewrite mxE scale0r.
rewrite (coord_vbasis (s_Zs _)); apply: eq_bigr => i _; congr (_ *: _).
rewrite linear_sum -SE mxE; apply: eq_bigr => j _.
rewrite -scaler_int linearZ !mxE sum_ffunE; congr (_%:~R * _).
apply: {i} eq_bigr => i _; rewrite mxE ffunMzE mulrzz mulrC.
by rewrite (nth_map i) ?size_enum_ord // ffunE nth_ord_enum.
Qed.
Lemma dec_Qint_span (vT : vectType rat) m (s : m.-tuple vT) v :
decidable (inIntSpan s v).
Proof.
have [[b [p aP]]|] := solve_Qint_span s v; last by right.
left; exists b; apply/(aP b); exists [::]; rewrite big1 ?addr0 // => i _.
by rewrite nth_nil mulr0z.
Qed.
Lemma eisenstein_crit (p : nat) (q : {poly int}) : prime p -> (size q != 1)%N ->
~~ (p %| lead_coef q)%Z -> ~~ (p ^+ 2 %| q`_0)%Z ->
(forall i, (i < (size q).-1)%N -> p %| q`_i)%Z ->
irreducible_poly q.
Proof.
move=> p_prime qN1 Ndvd_pql Ndvd_pq0 dvd_pq.
apply/irreducible_rat_int.
have qN0 : q != 0 by rewrite -lead_coef_eq0; apply: contraNneq Ndvd_pql => ->.
split.
rewrite size_map_poly_id0 ?intr_eq0 ?lead_coef_eq0//.
by rewrite ltn_neqAle eq_sym qN1 size_poly_gt0.
move=> f' +/dvdpP_rat_int[f [d dN0 feq]]; rewrite {f'}feq size_scale// => fN1.
move=> /= [g q_eq]; rewrite q_eq (eqp_trans (eqp_scale _ _))//.
have fN0 : f != 0 by apply: contra_neq qN0; rewrite q_eq => ->; rewrite mul0r.
have gN0 : g != 0 by apply: contra_neq qN0; rewrite q_eq => ->; rewrite mulr0.
rewrite size_map_poly_id0 ?intr_eq0 ?lead_coef_eq0// in fN1.
have [/eqP/size_poly1P[c cN0 ->]|gN1] := eqVneq (size g) 1%N.
by rewrite mulrC mul_polyC map_polyZ/= eqp_sym eqp_scale// intr_eq0.
have c_neq0 : (lead_coef q)%:~R != 0 :> 'F_p
by rewrite -(dvdz_pcharf (pchar_Fp _)).
have : map_poly (intr : int -> 'F_p) q = (lead_coef q)%:~R *: 'X^((size q).-1).
apply/val_inj/(@eq_from_nth _ 0) => [|i]; rewrite size_map_poly_id0//.
by rewrite size_scale// size_polyXn -polySpred.
move=> i_small; rewrite coef_poly i_small coefZ coefXn lead_coefE.
move: i_small; rewrite polySpred// ltnS/=.
case: ltngtP => // [i_lt|->]; rewrite (mulr1, mulr0)//= => _.
by apply/eqP; rewrite -(dvdz_pcharf (pchar_Fp _))// dvd_pq.
rewrite [in LHS]q_eq rmorphM/=.
set c := (X in X *: _); set n := (_.-1).
set pf := map_poly _ f; set pg := map_poly _ g => pfMpg.
have dvdXn (r : {poly _}) : size r != 1%N -> r %| c *: 'X^n -> r`_0 = 0.
move=> rN1; rewrite (eqp_dvdr _ (eqp_scale _ _))//.
rewrite -['X]subr0; move=> /dvdp_exp_XsubCP[k lekn]; rewrite subr0.
move=> /eqpP[u /andP[u1N0 u2N0]]; have [->|k_gt0] := posnP k.
move=> /(congr1 (size \o val))/eqP.
by rewrite /= !size_scale// size_polyXn (negPf rN1).
move=> /(congr1 (fun p : {poly _} => p`_0))/eqP.
by rewrite !coefZ coefXn [0 == _]ltn_eqF// mulr0 mulf_eq0 (negPf u1N0)=> /eqP.
suff : ((p : int) ^+ 2 %| q`_0)%Z by rewrite (negPf Ndvd_pq0).
have := c_neq0; rewrite q_eq coefM big_ord1.
rewrite lead_coefM rmorphM mulf_eq0 negb_or => /andP[lpfN0 qfN0].
have pfN1 : size pf != 1%N by rewrite size_map_poly_id0.
have pgN1 : size pg != 1%N by rewrite size_map_poly_id0.
have /(dvdXn _ pgN1) /eqP : pg %| c *: 'X^n by rewrite -pfMpg dvdp_mull.
have /(dvdXn _ pfN1) /eqP : pf %| c *: 'X^n by rewrite -pfMpg dvdp_mulr.
by rewrite !coef_map// -!(dvdz_pcharf (pchar_Fp _))//; apply: dvdz_mul.
Qed.
(* Connecting rationals to the ring and field tactics *)
Ltac rat_to_ring :=
rewrite -?[0%Q]/(0 : rat)%R -?[1%Q]/(1 : rat)%R
-?[(_ - _)%Q]/(_ - _ : rat)%R -?[(_ / _)%Q]/(_ / _ : rat)%R
-?[(_ + _)%Q]/(_ + _ : rat)%R -?[(_ * _)%Q]/(_ * _ : rat)%R
-?[(- _)%Q]/(- _ : rat)%R -?[(_ ^-1)%Q]/(_ ^-1 : rat)%R /=.
Ltac ring_to_rat :=
rewrite -?[0%R]/0%Q -?[1%R]/1%Q
-?[(_ - _)%R]/(_ - _)%Q -?[(_ / _)%R]/(_ / _)%Q
-?[(_ + _)%R]/(_ + _)%Q -?[(_ * _)%R]/(_ * _)%Q
-?[(- _)%R]/(- _)%Q -?[(_ ^-1)%R]/(_ ^-1)%Q /=.
(* Pretty printing or normal element of rat. *)
Notation "[ 'rat' x // y ]" := (@Rat (x, y) _) (only printing) : ring_scope.
(* For debugging purposes we provide the parsable version *)
Notation "[ 'rat' x // y ]" :=
(@Rat (x : int, y : int) (fracq_subproof (x : int, y : int))) : ring_scope.
(* A specialization of vm_compute rewrite rule for pattern _%:Q *)
Lemma rat_vm_compute n (x : rat) : vm_compute_eq n%:Q x -> n%:Q = x.
Proof. exact. Qed.
|
DoublingConst.lean
|
/-
Copyright (c) 2024 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Combinatorics.Additive.PluenneckeRuzsa
import Mathlib.Data.Finset.Density
/-!
# Doubling and difference constants
This file defines the doubling and difference constants of two finsets in a group.
-/
open Finset
open scoped Pointwise
namespace Finset
section Group
variable {G G' : Type*} [Group G] [AddGroup G'] [DecidableEq G] [DecidableEq G'] {A B : Finset G}
/-- The doubling constant `σₘ[A, B]` of two finsets `A` and `B` in a group is `|A * B| / |A|`.
The notation `σₘ[A, B]` is available in scope `Combinatorics.Additive`. -/
@[to_additive
/-- The doubling constant `σ[A, B]` of two finsets `A` and `B` in a group is `|A + B| / |A|`.
The notation `σ[A, B]` is available in scope `Combinatorics.Additive`. -/]
def mulConst (A B : Finset G) : ℚ≥0 := #(A * B) / #A
/-- The difference constant `δₘ[A, B]` of two finsets `A` and `B` in a group is `|A / B| / |A|`.
The notation `δₘ[A, B]` is available in scope `Combinatorics.Additive`. -/
@[to_additive
/-- The difference constant `σ[A, B]` of two finsets `A` and `B` in a group is `|A - B| / |A|`.
The notation `δ[A, B]` is available in scope `Combinatorics.Additive`. -/]
def divConst (A B : Finset G) : ℚ≥0 := #(A / B) / #A
/-- The doubling constant `σₘ[A, B]` of two finsets `A` and `B` in a group is `|A * B| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "σₘ[" A ", " B "]" => Finset.mulConst A B
/-- The doubling constant `σₘ[A]` of a finset `A` in a group is `|A * A| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "σₘ[" A "]" => Finset.mulConst A A
/-- The doubling constant `σ[A, B]` of two finsets `A` and `B` in a group is `|A + B| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "σ[" A ", " B "]" => Finset.addConst A B
/-- The doubling constant `σ[A]` of a finset `A` in a group is `|A + A| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "σ[" A "]" => Finset.addConst A A
/-- The difference constant `σₘ[A, B]` of two finsets `A` and `B` in a group is `|A / B| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "δₘ[" A ", " B "]" => Finset.divConst A B
/-- The difference constant `σₘ[A]` of a finset `A` in a group is `|A / A| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "δₘ[" A "]" => Finset.divConst A A
/-- The difference constant `σ[A, B]` of two finsets `A` and `B` in a group is `|A - B| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "δ[" A ", " B "]" => Finset.subConst A B
/-- The difference constant `σ[A]` of a finset `A` in a group is `|A - A| / |A|`. -/
scoped[Combinatorics.Additive] notation3:max "δ[" A "]" => Finset.subConst A A
open scoped Combinatorics.Additive
@[to_additive (attr := simp) addConst_mul_card]
lemma mulConst_mul_card (A B : Finset G) : σₘ[A, B] * #A = #(A * B) := by
obtain rfl | hA := A.eq_empty_or_nonempty
· simp
· exact div_mul_cancel₀ _ (by positivity)
@[to_additive (attr := simp) subConst_mul_card]
lemma divConst_mul_card (A B : Finset G) : δₘ[A, B] * #A = #(A / B) := by
obtain rfl | hA := A.eq_empty_or_nonempty
· simp
· exact div_mul_cancel₀ _ (by positivity)
@[to_additive (attr := simp) card_mul_addConst]
lemma card_mul_mulConst (A B : Finset G) : #A * σₘ[A, B] = #(A * B) := by
rw [mul_comm, mulConst_mul_card]
@[to_additive (attr := simp) card_mul_subConst]
lemma card_mul_divConst (A B : Finset G) : #A * δₘ[A, B] = #(A / B) := by
rw [mul_comm, divConst_mul_card]
@[to_additive (attr := simp)]
lemma mulConst_empty_left (B : Finset G) : σₘ[∅, B] = 0 := by simp [mulConst]
@[to_additive (attr := simp)]
lemma divConst_empty_left (B : Finset G) : δₘ[∅, B] = 0 := by simp [divConst]
@[to_additive (attr := simp)]
lemma mulConst_empty_right (A : Finset G) : σₘ[A, ∅] = 0 := by simp [mulConst]
@[to_additive (attr := simp)]
lemma divConst_empty_right (A : Finset G) : δₘ[A, ∅] = 0 := by simp [divConst]
@[to_additive (attr := simp)]
lemma mulConst_inv_right (A B : Finset G) : σₘ[A, B⁻¹] = δₘ[A, B] := by
rw [mulConst, divConst, ← div_eq_mul_inv]
@[to_additive (attr := simp)]
lemma divConst_inv_right (A B : Finset G) : δₘ[A, B⁻¹] = σₘ[A, B] := by
rw [mulConst, divConst, div_inv_eq_mul]
@[to_additive]
lemma one_le_mulConst (hA : A.Nonempty) (hB : B.Nonempty) : 1 ≤ σₘ[A, B] := by
rw [mulConst, one_le_div₀]
· exact mod_cast card_le_card_mul_right hB
· simpa
@[to_additive]
lemma one_le_mulConst_self (hA : A.Nonempty) : 1 ≤ σₘ[A] := one_le_mulConst hA hA
@[to_additive]
lemma one_le_divConst (hA : A.Nonempty) (hB : B.Nonempty) : 1 ≤ δₘ[A, B] := by
rw [← mulConst_inv_right]
apply one_le_mulConst hA (by simpa)
@[to_additive]
lemma one_le_divConst_self (hA : A.Nonempty) : 1 ≤ δₘ[A] := one_le_divConst hA hA
@[to_additive]
lemma mulConst_le_card : σₘ[A, B] ≤ #B := by
obtain rfl | hA' := A.eq_empty_or_nonempty
· simp
rw [mulConst, div_le_iff₀' (by positivity)]
exact mod_cast card_mul_le
@[to_additive]
lemma divConst_le_card : δₘ[A, B] ≤ #B := by
obtain rfl | hA' := A.eq_empty_or_nonempty
· simp
rw [divConst, div_le_iff₀' (by positivity)]
exact mod_cast card_div_le
section Fintype
variable [Fintype G]
/-- Dense sets have small doubling. -/
@[to_additive addConst_le_inv_dens /-- Dense sets have small doubling. -/]
lemma mulConst_le_inv_dens : σₘ[A, B] ≤ A.dens⁻¹ := by
rw [dens, inv_div, mulConst]; gcongr; exact card_le_univ _
/-- Dense sets have small difference constant. -/
@[to_additive subConst_le_inv_dens /-- Dense sets have small difference constant. -/]
lemma divConst_le_inv_dens : δₘ[A, B] ≤ A.dens⁻¹ := by
rw [dens, inv_div, divConst]; gcongr; exact card_le_univ _
end Fintype
variable {𝕜 : Type*} [Semifield 𝕜] [CharZero 𝕜]
-- we can't use `to_additive`, because it tries to translate `/` to `-`
lemma cast_addConst (A B : Finset G') : (σ[A, B] : 𝕜) = #(A + B) / #A := by
simp [addConst]
lemma cast_subConst (A B : Finset G') : (δ[A, B] : 𝕜) = #(A - B) / #A := by
simp [subConst]
lemma cast_mulConst (A B : Finset G) : (σₘ[A, B] : 𝕜) = #(A * B) / #A := by simp [mulConst]
lemma cast_divConst (A B : Finset G) : (δₘ[A, B] : 𝕜) = #(A / B) / #A := by simp [divConst]
lemma cast_addConst_mul_card (A B : Finset G') : (σ[A, B] * #A : 𝕜) = #(A + B) := by
norm_cast; exact addConst_mul_card _ _
lemma cast_subConst_mul_card (A B : Finset G') : (δ[A, B] * #A : 𝕜) = #(A - B) := by
norm_cast; exact subConst_mul_card _ _
lemma card_mul_cast_addConst (A B : Finset G') : (#A * σ[A, B] : 𝕜) = #(A + B) := by
norm_cast; exact card_mul_addConst _ _
lemma card_mul_cast_subConst (A B : Finset G') : (#A * δ[A, B] : 𝕜) = #(A - B) := by
norm_cast; exact card_mul_subConst _ _
@[simp]
lemma cast_mulConst_mul_card (A B : Finset G) : (σₘ[A, B] * #A : 𝕜) = #(A * B) := by
norm_cast; exact mulConst_mul_card _ _
@[simp]
lemma cast_divConst_mul_card (A B : Finset G) : (δₘ[A, B] * #A : 𝕜) = #(A / B) := by
norm_cast; exact divConst_mul_card _ _
@[simp]
lemma card_mul_cast_mulConst (A B : Finset G) : (#A * σₘ[A, B] : 𝕜) = #(A * B) := by
norm_cast; exact card_mul_mulConst _ _
@[simp]
lemma card_mul_cast_divConst (A B : Finset G) : (#A * δₘ[A, B] : 𝕜) = #(A / B) := by
norm_cast; exact card_mul_divConst _ _
/-- If `A` has small doubling, then it has small difference, with the constant squared.
This is a consequence of the Ruzsa triangle inequality. -/
@[to_additive
/-- If `A` has small doubling, then it has small difference, with the constant squared.
This is a consequence of the Ruzsa triangle inequality. -/]
lemma divConst_le_mulConst_sq : δₘ[A] ≤ σₘ[A] ^ 2 := by
obtain rfl | hA' := A.eq_empty_or_nonempty
· simp
refine le_of_mul_le_mul_right ?_ (by positivity : (0 : ℚ≥0) < #A * #A)
calc
_ = #(A / A) * (#A : ℚ≥0) := by rw [← mul_assoc, divConst_mul_card]
_ ≤ #(A * A) * #(A * A) := by norm_cast; exact ruzsa_triangle_inequality_div_mul_mul ..
_ = _ := by rw [← mulConst_mul_card]; ring
end Group
open scoped Combinatorics.Additive
section CommGroup
variable {G : Type*} [CommGroup G] [DecidableEq G] {A B : Finset G}
@[to_additive (attr := simp)]
lemma mulConst_inv_left (A B : Finset G) : σₘ[A⁻¹, B] = δₘ[A, B] := by
rw [mulConst, divConst, card_inv, ← card_inv, mul_inv_rev, inv_inv, inv_mul_eq_div]
@[to_additive (attr := simp)]
lemma divConst_inv_left (A B : Finset G) : δₘ[A⁻¹, B] = σₘ[A, B] := by
rw [mulConst, divConst, card_inv, ← card_inv, inv_div, div_inv_eq_mul, mul_comm]
/-- If `A` has small difference, then it has small doubling, with the constant squared.
This is a consequence of the Ruzsa triangle inequality. -/
@[to_additive
/-- If `A` has small difference, then it has small doubling, with the constant squared.
This is a consequence of the Ruzsa triangle inequality. -/]
lemma mulConst_le_divConst_sq : σₘ[A] ≤ δₘ[A] ^ 2 := by
obtain rfl | hA' := A.eq_empty_or_nonempty
· simp
refine le_of_mul_le_mul_right ?_ (by positivity : (0 : ℚ≥0) < #A * #A)
calc
_ = #(A * A) * (#A : ℚ≥0) := by rw [← mul_assoc, mulConst_mul_card]
_ ≤ #(A / A) * #(A / A) := by norm_cast; exact ruzsa_triangle_inequality_mul_div_div ..
_ = _ := by rw [← divConst_mul_card]; ring
end CommGroup
end Finset
|
Trigonometric.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
-/
import Mathlib.Data.Complex.Exponential
/-!
# Trigonometric and hyperbolic trigonometric functions
This file contains the definitions of the sine, cosine, tangent,
hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
noncomputable section
/-- The complex sine function, defined via `exp` -/
@[pp_nodot]
def sin (z : ℂ) : ℂ :=
(exp (-z * I) - exp (z * I)) * I / 2
/-- The complex cosine function, defined via `exp` -/
@[pp_nodot]
def cos (z : ℂ) : ℂ :=
(exp (z * I) + exp (-z * I)) / 2
/-- The complex tangent function, defined as `sin z / cos z` -/
@[pp_nodot]
def tan (z : ℂ) : ℂ :=
sin z / cos z
/-- The complex cotangent function, defined as `cos z / sin z` -/
def cot (z : ℂ) : ℂ :=
cos z / sin z
/-- The complex hyperbolic sine function, defined via `exp` -/
@[pp_nodot]
def sinh (z : ℂ) : ℂ :=
(exp z - exp (-z)) / 2
/-- The complex hyperbolic cosine function, defined via `exp` -/
@[pp_nodot]
def cosh (z : ℂ) : ℂ :=
(exp z + exp (-z)) / 2
/-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/
@[pp_nodot]
def tanh (z : ℂ) : ℂ :=
sinh z / cosh z
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real sine function, defined as the real part of the complex sine -/
@[pp_nodot]
nonrec def sin (x : ℝ) : ℝ :=
(sin x).re
/-- The real cosine function, defined as the real part of the complex cosine -/
@[pp_nodot]
nonrec def cos (x : ℝ) : ℝ :=
(cos x).re
/-- The real tangent function, defined as the real part of the complex tangent -/
@[pp_nodot]
nonrec def tan (x : ℝ) : ℝ :=
(tan x).re
/-- The real cotangent function, defined as the real part of the complex cotangent -/
nonrec def cot (x : ℝ) : ℝ :=
(cot x).re
/-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/
@[pp_nodot]
nonrec def sinh (x : ℝ) : ℝ :=
(sinh x).re
/-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/
@[pp_nodot]
nonrec def cosh (x : ℝ) : ℝ :=
(cosh x).re
/-- The real hypebolic tangent function, defined as the real part of
the complex hyperbolic tangent -/
@[pp_nodot]
nonrec def tanh (x : ℝ) : ℝ :=
(tanh x).re
end
end Real
namespace Complex
variable (x y : ℂ)
theorem two_sinh : 2 * sinh x = exp x - exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
theorem two_cosh : 2 * cosh x = exp x + exp (-x) :=
mul_div_cancel₀ _ two_ne_zero
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm]
private theorem sinh_add_aux {a b c d : ℂ} :
(a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring
theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, ← mul_assoc, two_cosh]
exact sinh_add_aux
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
@[simp]
theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg]
private theorem cosh_add_aux {a b c d : ℂ} :
(a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring
theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ←
mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add,
mul_left_comm, two_cosh, mul_left_comm, two_sinh]
exact cosh_add_aux
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
theorem sinh_conj : sinh (conj x) = conj (sinh x) := by
rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀, map_ofNat]
@[simp]
theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x :=
conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x :=
ofReal_sinh_ofReal_re _
@[simp]
theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im]
theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x :=
rfl
theorem cosh_conj : cosh (conj x) = conj (cosh x) := by
rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀, map_ofNat]
theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x :=
conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x :=
ofReal_cosh_ofReal_re _
@[simp]
theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im]
@[simp]
theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x :=
rfl
theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
rfl
@[simp]
theorem tanh_zero : tanh 0 = 0 := by simp [tanh]
@[simp]
theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div]
theorem tanh_conj : tanh (conj x) = conj (tanh x) := by
rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh]
@[simp]
theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x :=
conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x :=
ofReal_tanh_ofReal_re _
@[simp]
theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im]
theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x :=
rfl
@[simp]
theorem cosh_add_sinh : cosh x + sinh x = exp x := by
rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul]
@[simp]
theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh]
@[simp]
theorem exp_sub_cosh : exp x - cosh x = sinh x :=
sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm
@[simp]
theorem exp_sub_sinh : exp x - sinh x = cosh x :=
sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm
@[simp]
theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by
rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul]
@[simp]
theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh]
@[simp]
theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by
rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_cancel, exp_zero]
theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by
rw [← cosh_sq_sub_sinh_sq x]
ring
theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by
rw [← cosh_sq_sub_sinh_sq x]
ring
theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq]
theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by
rw [two_mul, sinh_add]
ring
theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, cosh_add x (2 * x)]
simp only [cosh_two_mul, sinh_two_mul]
have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring
rw [h2, sinh_sq]
ring
theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, sinh_add x (2 * x)]
simp only [cosh_two_mul, sinh_two_mul]
have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring
rw [h2, cosh_sq]
ring
@[simp]
theorem sin_zero : sin 0 = 0 := by simp [sin]
@[simp]
theorem sin_neg : sin (-x) = -sin x := by
simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul]
theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I :=
mul_div_cancel₀ _ two_ne_zero
theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) :=
mul_div_cancel₀ _ two_ne_zero
theorem sinh_mul_I : sinh (x * I) = sin x * I := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I,
mul_neg_one, neg_sub, neg_mul_eq_neg_mul]
theorem cosh_mul_I : cosh (x * I) = cos x := by
rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul]
theorem tanh_mul_I : tanh (x * I) = tan x * I := by
rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan]
theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp
theorem sin_mul_I : sin (x * I) = sinh x * I := by
have h : I * sin (x * I) = -sinh x := by
rw [mul_comm, ← sinh_mul_I]
ring_nf
simp
rw [← neg_neg (sinh x), ← h]
apply Complex.ext <;> simp
theorem tan_mul_I : tan (x * I) = tanh x * I := by
rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh]
theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by
rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I,
mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add]
@[simp]
theorem cos_zero : cos 0 = 1 := by simp [cos]
@[simp]
theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg, add_comm]
theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by
rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I,
mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg]
theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by
simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by
simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by
rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc]
theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by
convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm
theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by
rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc]
theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by
convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm
theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by
have s1 := sin_add ((x + y) / 2) ((x - y) / 2)
have s2 := sin_sub ((x + y) / 2) ((x - y) / 2)
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, add_self_div_two] at s1
rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, add_self_div_two] at s2
rw [s1, s2]
ring
theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by
have s1 := cos_add ((x + y) / 2) ((x - y) / 2)
have s2 := cos_sub ((x + y) / 2) ((x - y) / 2)
rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, add_self_div_two] at s1
rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, add_self_div_two] at s2
rw [s1, s2]
ring
theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by
simpa using sin_sub_sin x (-y)
theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by
calc
cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_
_ =
cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) +
(cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) :=
?_
_ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_
· congr <;> field_simp
· rw [cos_add, cos_sub]
ring
theorem sin_conj : sin (conj x) = conj (sin x) := by
rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul,
sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg]
@[simp]
theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x :=
conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x :=
ofReal_sin_ofReal_re _
@[simp]
theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im]
theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x :=
rfl
theorem cos_conj : cos (conj x) = conj (cos x) := by
rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg]
@[simp]
theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x :=
conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x :=
ofReal_cos_ofReal_re _
@[simp]
theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im]
theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x :=
rfl
@[simp]
theorem tan_zero : tan 0 = 0 := by simp [tan]
theorem tan_eq_sin_div_cos : tan x = sin x / cos x :=
rfl
theorem cot_eq_cos_div_sin : cot x = cos x / sin x :=
rfl
theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by
rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx]
@[simp]
theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div]
theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan]
theorem cot_conj : cot (conj x) = conj (cot x) := by rw [cot, sin_conj, cos_conj, ← map_div₀, cot]
@[simp]
theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x :=
conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal]
@[simp]
theorem ofReal_cot_ofReal_re (x : ℝ) : ((cot x).re : ℂ) = cot x :=
conj_eq_iff_re.1 <| by rw [← cot_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x :=
ofReal_tan_ofReal_re _
@[simp, norm_cast]
theorem ofReal_cot (x : ℝ) : (Real.cot x : ℂ) = cot x :=
ofReal_cot_ofReal_re _
@[simp]
theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im]
theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x :=
rfl
theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by
rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I]
theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by
rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I]
@[simp]
theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 :=
Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm])
(cosh_sq_sub_sinh_sq (x * I))
@[simp]
theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq]
theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq]
theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by
rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub,
two_mul]
theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by
rw [two_mul, sin_add, two_mul, add_mul, mul_comm]
theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by
simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, -one_div]
theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left]
theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right]
theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by
rw [tan_eq_sin_div_cos, div_pow]
field_simp
theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) :
tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by
simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv]
theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, cos_add x (2 * x)]
simp only [cos_two_mul, sin_two_mul, mul_sub, mul_one, sq]
have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring
rw [h2, cos_sq']
ring
theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by
have h1 : x + 2 * x = 3 * x := by ring
rw [← h1, sin_add x (2 * x)]
simp only [cos_two_mul, sin_two_mul, cos_sq']
have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring
rw [h2, cos_sq']
ring
theorem exp_mul_I : exp (x * I) = cos x + sin x * I :=
(cos_add_sin_I _).symm
theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I]
theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by
rw [← exp_add_mul_I, re_add_im]
theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by
rw [exp_eq_exp_re_mul_sin_add_cos]
simp [exp_ofReal_re, cos_ofReal_re]
theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by
rw [exp_eq_exp_re_mul_sin_add_cos]
simp [exp_ofReal_re, sin_ofReal_re]
@[simp]
theorem exp_ofReal_mul_I_re (x : ℝ) : (exp (x * I)).re = Real.cos x := by
simp [exp_mul_I, cos_ofReal_re]
@[simp]
theorem exp_ofReal_mul_I_im (x : ℝ) : (exp (x * I)).im = Real.sin x := by
simp [exp_mul_I, sin_ofReal_re]
/-- **De Moivre's formula** -/
theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) :
(cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := by
rw [← exp_mul_I, ← exp_mul_I, ← exp_nat_mul, mul_assoc]
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem sin_zero : sin 0 = 0 := by simp [sin]
@[simp]
theorem sin_neg : sin (-x) = -sin x := by simp [sin]
nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y :=
ofReal_injective <| by simp [sin_add]
@[simp]
theorem cos_zero : cos 0 = 1 := by simp [cos]
@[simp]
theorem cos_neg : cos (-x) = cos x := by simp [cos]
@[simp]
theorem cos_abs : cos |x| = cos x := by
cases le_total x 0 <;> simp only [*, abs_of_nonneg, abs_of_nonpos, cos_neg]
nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y :=
ofReal_injective <| by simp [cos_add]
theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by
simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg]
theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by
simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg]
nonrec theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) :=
ofReal_injective <| by simp [sin_add_sin]
nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) :=
ofReal_injective <| by simp [sin_sub_sin]
nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) :=
ofReal_injective <| by simp [cos_add_cos]
nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) :=
ofReal_injective <| by simp [cos_sub_cos]
theorem two_mul_sin_mul_sin (x y : ℝ) : 2 * sin x * sin y = cos (x - y) - cos (x + y) := by
simp [cos_add, cos_sub]
ring
theorem two_mul_cos_mul_cos (x y : ℝ) : 2 * cos x * cos y = cos (x - y) + cos (x + y) := by
simp [cos_add, cos_sub]
ring
theorem two_mul_sin_mul_cos (x y : ℝ) : 2 * sin x * cos y = sin (x - y) + sin (x + y) := by
simp [sin_add, sin_sub]
ring
nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x :=
ofReal_injective <| by simp only [ofReal_tan, tan_eq_sin_div_cos, ofReal_div, ofReal_sin,
ofReal_cos]
nonrec theorem cot_eq_cos_div_sin : cot x = cos x / sin x :=
ofReal_injective <| by simp [cot_eq_cos_div_sin]
theorem tan_mul_cos {x : ℝ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by
rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx]
@[simp]
theorem tan_zero : tan 0 = 0 := by simp [tan]
@[simp]
theorem tan_neg : tan (-x) = -tan x := by simp [tan]
@[simp]
nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 :=
ofReal_injective (by simp [sin_sq_add_cos_sq])
@[simp]
theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq]
theorem sin_sq_le_one : sin x ^ 2 ≤ 1 := by
rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_right (sq_nonneg _)
theorem cos_sq_le_one : cos x ^ 2 ≤ 1 := by
rw [← sin_sq_add_cos_sq x]; exact le_add_of_nonneg_left (sq_nonneg _)
theorem abs_sin_le_one : |sin x| ≤ 1 :=
abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, sin_sq_le_one]
theorem abs_cos_le_one : |cos x| ≤ 1 :=
abs_le_one_iff_mul_self_le_one.2 <| by simp only [← sq, cos_sq_le_one]
theorem sin_le_one : sin x ≤ 1 :=
(abs_le.1 (abs_sin_le_one _)).2
theorem cos_le_one : cos x ≤ 1 :=
(abs_le.1 (abs_cos_le_one _)).2
theorem neg_one_le_sin : -1 ≤ sin x :=
(abs_le.1 (abs_sin_le_one _)).1
theorem neg_one_le_cos : -1 ≤ cos x :=
(abs_le.1 (abs_cos_le_one _)).1
nonrec theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 :=
ofReal_injective <| by simp [cos_two_mul]
nonrec theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 :=
ofReal_injective <| by simp [cos_two_mul']
nonrec theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x :=
ofReal_injective <| by simp [sin_two_mul]
nonrec theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 :=
ofReal_injective <| by simp [cos_sq]
theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left]
theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 :=
eq_sub_iff_add_eq.2 <| sin_sq_add_cos_sq _
lemma sin_sq_eq_half_sub : sin x ^ 2 = 1 / 2 - cos (2 * x) / 2 := by
rw [sin_sq, cos_sq, ← sub_sub, sub_half]
theorem abs_sin_eq_sqrt_one_sub_cos_sq (x : ℝ) : |sin x| = √(1 - cos x ^ 2) := by
rw [← sin_sq, sqrt_sq_eq_abs]
theorem abs_cos_eq_sqrt_one_sub_sin_sq (x : ℝ) : |cos x| = √(1 - sin x ^ 2) := by
rw [← cos_sq', sqrt_sq_eq_abs]
theorem inv_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 :=
have : Complex.cos x ≠ 0 := mt (congr_arg re) hx
ofReal_inj.1 <| by simpa using Complex.inv_one_add_tan_sq this
theorem tan_sq_div_one_add_tan_sq {x : ℝ} (hx : cos x ≠ 0) :
tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by
simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv]
theorem inv_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) : (√(1 + tan x ^ 2))⁻¹ = cos x := by
rw [← sqrt_sq hx.le, ← sqrt_inv, inv_one_add_tan_sq hx.ne']
theorem tan_div_sqrt_one_add_tan_sq {x : ℝ} (hx : 0 < cos x) :
tan x / √(1 + tan x ^ 2) = sin x := by
rw [← tan_mul_cos hx.ne', ← inv_sqrt_one_add_tan_sq hx, div_eq_mul_inv]
nonrec theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by
rw [← ofReal_inj]; simp [cos_three_mul]
nonrec theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by
rw [← ofReal_inj]; simp [sin_three_mul]
/-- The definition of `sinh` in terms of `exp`. -/
nonrec theorem sinh_eq (x : ℝ) : sinh x = (exp x - exp (-x)) / 2 :=
ofReal_injective <| by simp [Complex.sinh]
@[simp]
theorem sinh_zero : sinh 0 = 0 := by simp [sinh]
@[simp]
theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh]
nonrec theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by
rw [← ofReal_inj]; simp [sinh_add]
/-- The definition of `cosh` in terms of `exp`. -/
theorem cosh_eq (x : ℝ) : cosh x = (exp x + exp (-x)) / 2 :=
eq_div_of_mul_eq two_ne_zero <| by
rw [cosh, exp, exp, Complex.ofReal_neg, Complex.cosh, mul_two, ← Complex.add_re, ← mul_two,
div_mul_cancel₀ _ (two_ne_zero' ℂ), Complex.add_re]
@[simp]
theorem cosh_zero : cosh 0 = 1 := by simp [cosh]
@[simp]
theorem cosh_neg : cosh (-x) = cosh x :=
ofReal_inj.1 <| by simp
@[simp]
theorem cosh_abs : cosh |x| = cosh x := by
cases le_total x 0 <;> simp [*, abs_of_nonneg, abs_of_nonpos]
nonrec theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by
rw [← ofReal_inj]; simp [cosh_add]
theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by
simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg]
theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by
simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg]
nonrec theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x :=
ofReal_inj.1 <| by simp [tanh_eq_sinh_div_cosh]
@[simp]
theorem tanh_zero : tanh 0 = 0 := by simp [tanh]
@[simp]
theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh]
@[simp]
theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← ofReal_inj]; simp
@[simp]
theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh]
@[simp]
theorem exp_sub_cosh : exp x - cosh x = sinh x :=
sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm
@[simp]
theorem exp_sub_sinh : exp x - sinh x = cosh x :=
sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm
@[simp]
theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by
rw [← ofReal_inj]
simp
@[simp]
theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh]
@[simp]
theorem cosh_sq_sub_sinh_sq (x : ℝ) : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [← ofReal_inj]; simp
nonrec theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← ofReal_inj]; simp [cosh_sq]
theorem cosh_sq' : cosh x ^ 2 = 1 + sinh x ^ 2 :=
(cosh_sq x).trans (add_comm _ _)
nonrec theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← ofReal_inj]; simp [sinh_sq]
nonrec theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by
rw [← ofReal_inj]; simp [cosh_two_mul]
nonrec theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by
rw [← ofReal_inj]; simp [sinh_two_mul]
nonrec theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by
rw [← ofReal_inj]; simp [cosh_three_mul]
nonrec theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by
rw [← ofReal_inj]; simp [sinh_three_mul]
open IsAbsoluteValue Nat
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
/-- `Real.cosh` is always positive -/
theorem cosh_pos (x : ℝ) : 0 < Real.cosh x :=
(cosh_eq x).symm ▸ half_pos (add_pos (exp_pos x) (exp_pos (-x)))
theorem sinh_lt_cosh : sinh x < cosh x :=
lt_of_pow_lt_pow_left₀ 2 (cosh_pos _).le <| (cosh_sq x).symm ▸ lt_add_one _
end Real
namespace Real
open Complex Finset
theorem cos_bound {x : ℝ} (hx : |x| ≤ 1) : |cos x - (1 - x ^ 2 / 2)| ≤ |x| ^ 4 * (5 / 96) :=
calc
|cos x - (1 - x ^ 2 / 2)| = ‖Complex.cos x - (1 - (x : ℂ) ^ 2 / 2)‖ := by
rw [← Real.norm_eq_abs, ← norm_real]; simp
_ = ‖(Complex.exp (x * I) + Complex.exp (-x * I) - (2 - (x : ℂ) ^ 2)) / 2‖ := by
simp [Complex.cos, sub_div, add_div]
_ = ‖((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) +
(Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial)) / 2‖ :=
(congr_arg (‖·‖ : ℂ → ℝ)
(congr_arg (fun x : ℂ => x / 2) (by
simp only [neg_mul, pow_succ, pow_zero, sum_range_succ, range_zero, sum_empty,
Nat.factorial, Nat.cast_succ, zero_add, mul_one, Nat.mul_one, mul_neg, neg_neg]
apply Complex.ext <;> simp [div_eq_mul_inv, normSq] <;> ring_nf)))
_ ≤ ‖(Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) / 2‖ +
‖(Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) / 2‖ := by
rw [add_div]; exact norm_add_le _ _
_ = ‖Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial‖ / 2 +
‖Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial‖ / 2 := by
simp
_ ≤ ‖x * I‖ ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 +
‖-x * I‖ ^ 4 * (Nat.succ 4 * ((Nat.factorial 4) * (4 : ℕ) : ℝ)⁻¹) / 2 := by
gcongr
· exact Complex.exp_bound (by simpa) (by decide)
· exact Complex.exp_bound (by simpa) (by decide)
_ ≤ |x| ^ 4 * (5 / 96) := by norm_num [Nat.factorial]
theorem sin_bound {x : ℝ} (hx : |x| ≤ 1) : |sin x - (x - x ^ 3 / 6)| ≤ |x| ^ 4 * (5 / 96) :=
calc
|sin x - (x - x ^ 3 / 6)| = ‖Complex.sin x - (x - x ^ 3 / 6 : ℝ)‖ := by
rw [← Real.norm_eq_abs, ← norm_real]; simp
_ = ‖((Complex.exp (-x * I) - Complex.exp (x * I)) * I -
(2 * x - x ^ 3 / 3 : ℝ)) / 2‖ := by
simp [Complex.sin, sub_div, mul_div_cancel_left₀ _ (two_ne_zero' ℂ),
div_div, show (3 : ℂ) * 2 = 6 by norm_num]
_ = ‖((Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) -
(Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial)) * I / 2‖ :=
(congr_arg (‖·‖ : ℂ → ℝ)
(congr_arg (fun x : ℂ => x / 2)
(by
simp only [neg_mul, pow_succ, pow_zero, ofReal_sub, ofReal_mul, ofReal_ofNat,
ofReal_div, sum_range_succ, range_zero, sum_empty, Nat.factorial, Nat.cast_succ,
zero_add, mul_neg, mul_one, neg_neg, Nat.mul_one]
apply Complex.ext <;> simp [div_eq_mul_inv, normSq]; ring)))
_ ≤ ‖(Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial) * I / 2‖ +
‖-((Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial) * I) / 2‖ := by
rw [sub_mul, sub_eq_add_neg, add_div]; exact norm_add_le _ _
_ = ‖Complex.exp (x * I) - ∑ m ∈ range 4, (x * I) ^ m / m.factorial‖ / 2 +
‖Complex.exp (-x * I) - ∑ m ∈ range 4, (-x * I) ^ m / m.factorial‖ / 2 := by
simp [add_comm]
_ ≤ ‖x * I‖ ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : ℕ) : ℝ)⁻¹) / 2 +
‖-x * I‖ ^ 4 * (Nat.succ 4 * (Nat.factorial 4 * (4 : ℕ) : ℝ)⁻¹) / 2 := by
gcongr
· exact Complex.exp_bound (by simpa) (by decide)
· exact Complex.exp_bound (by simpa) (by decide)
_ ≤ |x| ^ 4 * (5 / 96) := by norm_num [Nat.factorial]
theorem cos_pos_of_le_one {x : ℝ} (hx : |x| ≤ 1) : 0 < cos x :=
calc 0 < 1 - x ^ 2 / 2 - |x| ^ 4 * (5 / 96) :=
sub_pos.2 <|
lt_sub_iff_add_lt.2
(calc
|x| ^ 4 * (5 / 96) + x ^ 2 / 2 ≤ 1 * (5 / 96) + 1 / 2 := by
gcongr
· exact pow_le_one₀ (abs_nonneg _) hx
· rw [sq, ← abs_mul_self, abs_mul]
exact mul_le_one₀ hx (abs_nonneg _) hx
_ < 1 := by norm_num)
_ ≤ cos x := sub_le_comm.1 (abs_sub_le_iff.1 (cos_bound hx)).2
theorem sin_pos_of_pos_of_le_one {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 1) : 0 < sin x :=
calc 0 < x - x ^ 3 / 6 - |x| ^ 4 * (5 / 96) :=
sub_pos.2 <| lt_sub_iff_add_lt.2
(calc
|x| ^ 4 * (5 / 96) + x ^ 3 / 6 ≤ x * (5 / 96) + x / 6 := by
gcongr
· calc
|x| ^ 4 ≤ |x| ^ 1 :=
pow_le_pow_of_le_one (abs_nonneg _)
(by rwa [abs_of_nonneg (le_of_lt hx0)]) (by decide)
_ = x := by simp [abs_of_nonneg (le_of_lt hx0)]
· calc
x ^ 3 ≤ x ^ 1 := pow_le_pow_of_le_one (le_of_lt hx0) hx (by decide)
_ = x := pow_one _
_ < x := by linarith)
_ ≤ sin x :=
sub_le_comm.1 (abs_sub_le_iff.1 (sin_bound (by rwa [abs_of_nonneg (le_of_lt hx0)]))).2
theorem sin_pos_of_pos_of_le_two {x : ℝ} (hx0 : 0 < x) (hx : x ≤ 2) : 0 < sin x :=
have : x / 2 ≤ 1 := (div_le_iff₀ (by simp)).mpr (by simpa)
calc
0 < 2 * sin (x / 2) * cos (x / 2) :=
mul_pos (mul_pos (by norm_num) (sin_pos_of_pos_of_le_one (half_pos hx0) this))
(cos_pos_of_le_one (by rwa [abs_of_nonneg (le_of_lt (half_pos hx0))]))
_ = sin x := by rw [← sin_two_mul, two_mul, add_halves]
theorem cos_one_le : cos 1 ≤ 5 / 9 :=
calc
cos 1 ≤ |(1 : ℝ)| ^ 4 * (5 / 96) + (1 - 1 ^ 2 / 2) :=
sub_le_iff_le_add.1 (abs_sub_le_iff.1 (cos_bound (by simp))).1
_ ≤ 5 / 9 := by norm_num
theorem cos_one_pos : 0 < cos 1 :=
cos_pos_of_le_one (le_of_eq abs_one)
theorem cos_two_neg : cos 2 < 0 :=
calc cos 2 = cos (2 * 1) := congr_arg cos (mul_one _).symm
_ = _ := Real.cos_two_mul 1
_ ≤ 2 * (5 / 9) ^ 2 - 1 := by
gcongr
· exact cos_one_pos.le
· apply cos_one_le
_ < 0 := by norm_num
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `Real.cosh` is always positive. -/
@[positivity Real.cosh _]
def evalCosh : PositivityExt where eval {u α} _ _ e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.cosh $a) =>
assertInstancesCommute
return .positive q(Real.cosh_pos $a)
| _, _, _ => throwError "not Real.cosh"
example (x : ℝ) : 0 < x.cosh := by positivity
end Mathlib.Meta.Positivity
namespace Complex
@[simp]
theorem norm_cos_add_sin_mul_I (x : ℝ) : ‖cos x + sin x * I‖ = 1 := by
have := Real.sin_sq_add_cos_sq x
simp_all [add_comm, norm_def, normSq, sq, sin_ofReal_re, cos_ofReal_re, mul_re]
@[simp]
theorem norm_exp_ofReal_mul_I (x : ℝ) : ‖exp (x * I)‖ = 1 := by
rw [exp_mul_I, norm_cos_add_sin_mul_I]
theorem norm_exp (z : ℂ) : ‖exp z‖ = Real.exp z.re := by
rw [exp_eq_exp_re_mul_sin_add_cos, Complex.norm_mul, norm_exp_ofReal, norm_cos_add_sin_mul_I,
mul_one]
theorem norm_exp_eq_iff_re_eq {x y : ℂ} : ‖exp x‖ = ‖exp y‖ ↔ x.re = y.re := by
rw [norm_exp, norm_exp, Real.exp_eq_exp]
@[deprecated (since := "2025-02-16")] alias abs_cos_add_sin_mul_I := norm_cos_add_sin_mul_I
@[deprecated (since := "2025-02-16")] alias abs_exp_ofReal_mul_I := norm_exp_ofReal_mul_I
@[deprecated (since := "2025-02-16")] alias abs_exp := norm_exp
@[deprecated (since := "2025-02-16")] alias abs_exp_eq_iff_re_eq := norm_exp_eq_iff_re_eq
end Complex
|
MatrixExponential.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.Analysis.Normed.Algebra.Exponential
import Mathlib.Analysis.Matrix
import Mathlib.LinearAlgebra.Matrix.ZPow
import Mathlib.LinearAlgebra.Matrix.Hermitian
import Mathlib.LinearAlgebra.Matrix.Symmetric
import Mathlib.Topology.UniformSpace.Matrix
/-!
# Lemmas about the matrix exponential
In this file, we provide results about `NormedSpace.exp` on `Matrix`s
over a topological or normed algebra.
Note that generic results over all topological spaces such as `NormedSpace.exp_zero`
can be used on matrices without issue, so are not repeated here.
The topological results specific to matrices are:
* `Matrix.exp_transpose`
* `Matrix.exp_conjTranspose`
* `Matrix.exp_diagonal`
* `Matrix.exp_blockDiagonal`
* `Matrix.exp_blockDiagonal'`
Lemmas like `NormedSpace.exp_add_of_commute` require a canonical norm on the type;
while there are multiple sensible choices for the norm of a `Matrix` (`Matrix.normedAddCommGroup`,
`Matrix.frobeniusNormedAddCommGroup`, `Matrix.linftyOpNormedAddCommGroup`), none of them
are canonical. In an application where a particular norm is chosen using
`attribute [local instance]`, then the usual lemmas about `NormedSpace.exp` are fine.
When choosing a norm is undesirable, the results in this file can be used.
In this file, we copy across the lemmas about `NormedSpace.exp`,
but hide the requirement for a norm inside the proof.
* `Matrix.exp_add_of_commute`
* `Matrix.exp_sum_of_commute`
* `Matrix.exp_nsmul`
* `Matrix.isUnit_exp`
* `Matrix.exp_units_conj`
* `Matrix.exp_units_conj'`
Additionally, we prove some results about `matrix.has_inv` and `matrix.div_inv_monoid`, as the
results for general rings are instead stated about `Ring.inverse`:
* `Matrix.exp_neg`
* `Matrix.exp_zsmul`
* `Matrix.exp_conj`
* `Matrix.exp_conj'`
## TODO
* Show that `Matrix.det (NormedSpace.exp 𝕂 A) = NormedSpace.exp 𝕂 (Matrix.trace A)`
## References
* https://en.wikipedia.org/wiki/Matrix_exponential
-/
open scoped Matrix
open NormedSpace -- For `exp`.
variable (𝕂 : Type*) {m n : Type*} {n' : m → Type*} {𝔸 : Type*}
namespace Matrix
section Topological
section Ring
variable [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] [∀ i, Fintype (n' i)]
[∀ i, DecidableEq (n' i)] [Field 𝕂] [Ring 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸]
[Algebra 𝕂 𝔸] [T2Space 𝔸]
theorem exp_diagonal (v : m → 𝔸) : exp 𝕂 (diagonal v) = diagonal (exp 𝕂 v) := by
simp_rw [exp_eq_tsum, diagonal_pow, ← diagonal_smul, ← diagonal_tsum]
theorem exp_blockDiagonal (v : m → Matrix n n 𝔸) :
exp 𝕂 (blockDiagonal v) = blockDiagonal (exp 𝕂 v) := by
simp_rw [exp_eq_tsum, ← blockDiagonal_pow, ← blockDiagonal_smul, ← blockDiagonal_tsum]
theorem exp_blockDiagonal' (v : ∀ i, Matrix (n' i) (n' i) 𝔸) :
exp 𝕂 (blockDiagonal' v) = blockDiagonal' (exp 𝕂 v) := by
simp_rw [exp_eq_tsum, ← blockDiagonal'_pow, ← blockDiagonal'_smul, ← blockDiagonal'_tsum]
theorem exp_conjTranspose [StarRing 𝔸] [ContinuousStar 𝔸] (A : Matrix m m 𝔸) :
exp 𝕂 Aᴴ = (exp 𝕂 A)ᴴ :=
(star_exp A).symm
theorem IsHermitian.exp [StarRing 𝔸] [ContinuousStar 𝔸] {A : Matrix m m 𝔸} (h : A.IsHermitian) :
(exp 𝕂 A).IsHermitian :=
(exp_conjTranspose _ _).symm.trans <| congr_arg _ h
end Ring
section CommRing
variable [Fintype m] [DecidableEq m] [Field 𝕂] [CommRing 𝔸] [TopologicalSpace 𝔸]
[IsTopologicalRing 𝔸] [Algebra 𝕂 𝔸] [T2Space 𝔸]
theorem exp_transpose (A : Matrix m m 𝔸) : exp 𝕂 Aᵀ = (exp 𝕂 A)ᵀ := by
simp_rw [exp_eq_tsum, transpose_tsum, transpose_smul, transpose_pow]
theorem IsSymm.exp {A : Matrix m m 𝔸} (h : A.IsSymm) : (exp 𝕂 A).IsSymm :=
(exp_transpose _ _).symm.trans <| congr_arg _ h
end CommRing
end Topological
section Normed
variable [RCLike 𝕂] [Fintype m] [DecidableEq m]
[NormedRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸]
nonrec theorem exp_add_of_commute (A B : Matrix m m 𝔸) (h : Commute A B) :
exp 𝕂 (A + B) = exp 𝕂 A * exp 𝕂 B :=
open scoped Norms.Operator in exp_add_of_commute h
open scoped Function in -- required for scoped `on` notation
nonrec theorem exp_sum_of_commute {ι} (s : Finset ι) (f : ι → Matrix m m 𝔸)
(h : (s : Set ι).Pairwise (Commute on f)) :
exp 𝕂 (∑ i ∈ s, f i) =
s.noncommProd (fun i => exp 𝕂 (f i)) fun _ hi _ hj _ => (h.of_refl hi hj).exp 𝕂 :=
open scoped Norms.Operator in exp_sum_of_commute s f h
nonrec theorem exp_nsmul (n : ℕ) (A : Matrix m m 𝔸) : exp 𝕂 (n • A) = exp 𝕂 A ^ n :=
open scoped Norms.Operator in exp_nsmul n A
nonrec theorem isUnit_exp (A : Matrix m m 𝔸) : IsUnit (exp 𝕂 A) :=
open scoped Norms.Operator in isUnit_exp _ A
nonrec theorem exp_units_conj (U : (Matrix m m 𝔸)ˣ) (A : Matrix m m 𝔸) :
exp 𝕂 (U * A * U⁻¹) = U * exp 𝕂 A * U⁻¹ :=
open scoped Norms.Operator in exp_units_conj _ U A
theorem exp_units_conj' (U : (Matrix m m 𝔸)ˣ) (A : Matrix m m 𝔸) :
exp 𝕂 (U⁻¹ * A * U) = U⁻¹ * exp 𝕂 A * U :=
exp_units_conj 𝕂 U⁻¹ A
end Normed
section NormedComm
variable [RCLike 𝕂] [Fintype m] [DecidableEq m]
[NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸]
theorem exp_neg (A : Matrix m m 𝔸) : exp 𝕂 (-A) = (exp 𝕂 A)⁻¹ := by
rw [nonsing_inv_eq_ringInverse]
open scoped Norms.Operator in exact (Ring.inverse_exp _ A).symm
theorem exp_zsmul (z : ℤ) (A : Matrix m m 𝔸) : exp 𝕂 (z • A) = exp 𝕂 A ^ z := by
obtain ⟨n, rfl | rfl⟩ := z.eq_nat_or_neg
· rw [zpow_natCast, natCast_zsmul, exp_nsmul]
· have : IsUnit (exp 𝕂 A).det := (Matrix.isUnit_iff_isUnit_det _).mp (isUnit_exp _ _)
rw [Matrix.zpow_neg this, zpow_natCast, neg_smul, exp_neg, natCast_zsmul, exp_nsmul]
theorem exp_conj (U : Matrix m m 𝔸) (A : Matrix m m 𝔸) (hy : IsUnit U) :
exp 𝕂 (U * A * U⁻¹) = U * exp 𝕂 A * U⁻¹ :=
let ⟨u, hu⟩ := hy
hu ▸ by simpa only [Matrix.coe_units_inv] using exp_units_conj 𝕂 u A
theorem exp_conj' (U : Matrix m m 𝔸) (A : Matrix m m 𝔸) (hy : IsUnit U) :
exp 𝕂 (U⁻¹ * A * U) = U⁻¹ * exp 𝕂 A * U :=
let ⟨u, hu⟩ := hy
hu ▸ by simpa only [Matrix.coe_units_inv] using exp_units_conj' 𝕂 u A
end NormedComm
end Matrix
|
Relation.lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.WSeq.Basic
import Mathlib.Logic.Relation
/-!
# Relations between and equivalence of weak sequences
This file defines a relation between weak sequences as a relation between their `some` elements,
ignoring computation time (`none` elements). Equivalence is then defined in the obvious way.
## Main definitions
* `Stream'.WSeq.LiftRelO`: Lift a relation to a relation over weak sequences.
* `Stream'.WSeq.LiftRel`: Two sequences are `LiftRel R`-related if their corresponding `some`
elements are `R`-related.
* `Stream'.WSeq.Equiv`: Two sequences are equivalent if they are `LiftRel (· = ·)`-related.
-/
universe u v w
namespace Stream'.WSeq
variable {α : Type u} {β : Type v} {γ : Type w}
open Function
/-- lift a relation to a relation over weak sequences -/
@[simp]
def LiftRelO (R : α → β → Prop) (C : WSeq α → WSeq β → Prop) :
Option (α × WSeq α) → Option (β × WSeq β) → Prop
| none, none => True
| some (a, s), some (b, t) => R a b ∧ C s t
| _, _ => False
attribute [nolint simpNF] LiftRelO.eq_3
theorem LiftRelO.imp {R S : α → β → Prop} {C D : WSeq α → WSeq β → Prop} (H1 : ∀ a b, R a b → S a b)
(H2 : ∀ s t, C s t → D s t) : ∀ {o p}, LiftRelO R C o p → LiftRelO S D o p
| none, none, _ => trivial
| some (_, _), some (_, _), h => And.imp (H1 _ _) (H2 _ _) h
| none, some _, h => False.elim h
| some (_, _), none, h => False.elim h
theorem LiftRelO.imp_right (R : α → β → Prop) {C D : WSeq α → WSeq β → Prop}
(H : ∀ s t, C s t → D s t) {o p} : LiftRelO R C o p → LiftRelO R D o p :=
LiftRelO.imp (fun _ _ => id) H
theorem LiftRelO.swap (R : α → β → Prop) (C) :
swap (LiftRelO R C) = LiftRelO (swap R) (swap C) := by
funext x y
rcases x with ⟨⟩ | ⟨hx, jx⟩ <;> rcases y with ⟨⟩ | ⟨hy, jy⟩ <;> rfl
/-- Definition of bisimilarity for weak sequences -/
@[simp]
def BisimO (R : WSeq α → WSeq α → Prop) : Option (α × WSeq α) → Option (α × WSeq α) → Prop :=
LiftRelO (· = ·) R
theorem BisimO.imp {R S : WSeq α → WSeq α → Prop} (H : ∀ s t, R s t → S s t) {o p} :
BisimO R o p → BisimO S o p :=
LiftRelO.imp_right _ H
/-- Two weak sequences are `LiftRel R` related if they are either both empty,
or they are both nonempty and the heads are `R` related and the tails are
`LiftRel R` related. (This is a coinductive definition.) -/
def LiftRel (R : α → β → Prop) (s : WSeq α) (t : WSeq β) : Prop :=
∃ C : WSeq α → WSeq β → Prop,
C s t ∧ ∀ {s t}, C s t → Computation.LiftRel (LiftRelO R C) (destruct s) (destruct t)
theorem liftRel_destruct {R : α → β → Prop} {s : WSeq α} {t : WSeq β} :
LiftRel R s t → Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t)
| ⟨R, h1, h2⟩ => by
refine Computation.LiftRel.imp ?_ _ _ (h2 h1)
apply LiftRelO.imp_right
exact fun s' t' h' => ⟨R, h', @h2⟩
theorem liftRel_destruct_iff {R : α → β → Prop} {s : WSeq α} {t : WSeq β} :
LiftRel R s t ↔ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) :=
⟨liftRel_destruct, fun h =>
⟨fun s t =>
LiftRel R s t ∨ Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t),
Or.inr h, fun {s t} h => by
have h : Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct s) (destruct t) := by
obtain h | h := h
· exact liftRel_destruct h
· assumption
apply Computation.LiftRel.imp _ _ _ h
intro a b
apply LiftRelO.imp_right
intro s t
apply Or.inl⟩⟩
theorem LiftRel.swap_lem {R : α → β → Prop} {s1 s2} (h : LiftRel R s1 s2) :
LiftRel (swap R) s2 s1 := by
refine ⟨swap (LiftRel R), h, fun {s t} (h : LiftRel R t s) => ?_⟩
rw [← LiftRelO.swap, Computation.LiftRel.swap]
apply liftRel_destruct h
theorem LiftRel.swap (R : α → β → Prop) : swap (LiftRel R) = LiftRel (swap R) :=
funext fun _ => funext fun _ => propext ⟨LiftRel.swap_lem, LiftRel.swap_lem⟩
theorem LiftRel.refl (R : α → α → Prop) (H : Reflexive R) : Reflexive (LiftRel R) := fun s => by
refine ⟨(· = ·), rfl, fun {s t} (h : s = t) => ?_⟩
rw [← h]
apply Computation.LiftRel.refl
intro a
rcases a with - | a
· simp
· cases a
simp only [LiftRelO, and_true]
apply H
theorem LiftRel.symm (R : α → α → Prop) (H : Symmetric R) : Symmetric (LiftRel R) :=
fun s1 s2 (h : Function.swap (LiftRel R) s2 s1) => by rwa [LiftRel.swap, H.swap_eq] at h
theorem LiftRel.trans (R : α → α → Prop) (H : Transitive R) : Transitive (LiftRel R) :=
fun s t u h1 h2 => by
refine ⟨fun s u => ∃ t, LiftRel R s t ∧ LiftRel R t u, ⟨t, h1, h2⟩, fun {s u} h => ?_⟩
rcases h with ⟨t, h1, h2⟩
have h1 := liftRel_destruct h1
have h2 := liftRel_destruct h2
refine
Computation.liftRel_def.2
⟨(Computation.terminates_of_liftRel h1).trans (Computation.terminates_of_liftRel h2),
fun {a c} ha hc => ?_⟩
rcases h1.left ha with ⟨b, hb, t1⟩
have t2 := Computation.rel_of_liftRel h2 hb hc
obtain - | a := a <;> obtain - | c := c
· trivial
· cases b
· cases t2
· cases t1
· cases a
rcases b with - | b
· cases t1
· cases b
cases t2
· obtain ⟨a, s⟩ := a
rcases b with - | b
· cases t1
obtain ⟨b, t⟩ := b
obtain ⟨c, u⟩ := c
obtain ⟨ab, st⟩ := t1
obtain ⟨bc, tu⟩ := t2
exact ⟨H ab bc, t, st, tu⟩
theorem LiftRel.equiv (R : α → α → Prop) : Equivalence R → Equivalence (LiftRel R)
| ⟨refl, symm, trans⟩ => ⟨LiftRel.refl R refl, @(LiftRel.symm R @symm), @(LiftRel.trans R @trans)⟩
/-- If two sequences are equivalent, then they have the same values and
the same computational behavior (i.e. if one loops forever then so does
the other), although they may differ in the number of `think`s needed to
arrive at the answer. -/
def Equiv : WSeq α → WSeq α → Prop :=
LiftRel (· = ·)
@[inherit_doc] infixl:50 " ~ʷ " => Equiv
@[refl]
theorem Equiv.refl : ∀ s : WSeq α, s ~ʷ s :=
LiftRel.refl (· = ·) Eq.refl
@[symm]
theorem Equiv.symm : ∀ {s t : WSeq α}, s ~ʷ t → t ~ʷ s :=
@(LiftRel.symm (· = ·) (@Eq.symm _))
@[trans]
theorem Equiv.trans : ∀ {s t u : WSeq α}, s ~ʷ t → t ~ʷ u → s ~ʷ u :=
@(LiftRel.trans (· = ·) (@Eq.trans _))
theorem Equiv.equivalence : Equivalence (@Equiv α) :=
⟨@Equiv.refl _, @Equiv.symm _, @Equiv.trans _⟩
theorem destruct_congr {s t : WSeq α} :
s ~ʷ t → Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) :=
liftRel_destruct
theorem destruct_congr_iff {s t : WSeq α} :
s ~ʷ t ↔ Computation.LiftRel (BisimO (· ~ʷ ·)) (destruct s) (destruct t) :=
liftRel_destruct_iff
open Computation
theorem liftRel_dropn_destruct {R : α → β → Prop} {s t} (H : LiftRel R s t) :
∀ n, Computation.LiftRel (LiftRelO R (LiftRel R)) (destruct (drop s n)) (destruct (drop t n))
| 0 => liftRel_destruct H
| n + 1 => by
simp only [drop, destruct_tail]
apply liftRel_bind
· apply liftRel_dropn_destruct H n
exact fun {a b} o =>
match a, b, o with
| none, none, _ => by simp
| some (a, s), some (b, t), ⟨_, h2⟩ => by simpa [tail.aux] using liftRel_destruct h2
theorem exists_of_liftRel_left {R : α → β → Prop} {s t} (H : LiftRel R s t) {a} (h : a ∈ s) :
∃ b, b ∈ t ∧ R a b := by
let ⟨n, h⟩ := exists_get?_of_mem h
let ⟨some (_, s'), sd, rfl⟩ := Computation.exists_of_mem_map h
let ⟨some (b, t'), td, ⟨ab, _⟩⟩ := (liftRel_dropn_destruct H n).left sd
exact ⟨b, get?_mem (Computation.mem_map (Prod.fst.{v, v} <$> ·) td), ab⟩
theorem exists_of_liftRel_right {R : α → β → Prop} {s t} (H : LiftRel R s t) {b} (h : b ∈ t) :
∃ a, a ∈ s ∧ R a b := by rw [← LiftRel.swap] at H; exact exists_of_liftRel_left H h
@[simp]
theorem liftRel_nil (R : α → β → Prop) : LiftRel R nil nil := by
simp [liftRel_destruct_iff]
@[simp]
theorem liftRel_cons (R : α → β → Prop) (a b s t) :
LiftRel R (cons a s) (cons b t) ↔ R a b ∧ LiftRel R s t := by
simp [liftRel_destruct_iff]
@[simp]
theorem liftRel_think_left (R : α → β → Prop) (s t) : LiftRel R (think s) t ↔ LiftRel R s t := by
rw [liftRel_destruct_iff, liftRel_destruct_iff]; simp
@[simp]
theorem liftRel_think_right (R : α → β → Prop) (s t) : LiftRel R s (think t) ↔ LiftRel R s t := by
rw [liftRel_destruct_iff, liftRel_destruct_iff]; simp
theorem cons_congr {s t : WSeq α} (a : α) (h : s ~ʷ t) : cons a s ~ʷ cons a t := by
unfold Equiv; simpa using h
theorem think_equiv (s : WSeq α) : think s ~ʷ s := by unfold Equiv; simpa using Equiv.refl _
theorem think_congr {s t : WSeq α} (h : s ~ʷ t) : think s ~ʷ think t := by
unfold Equiv; simpa using h
theorem head_congr : ∀ {s t : WSeq α}, s ~ʷ t → head s ~ head t := by
suffices ∀ {s t : WSeq α}, s ~ʷ t → ∀ {o}, o ∈ head s → o ∈ head t from fun s t h o =>
⟨this h, this h.symm⟩
intro s t h o ho
rcases @Computation.exists_of_mem_map _ _ _ _ (destruct s) ho with ⟨ds, dsm, dse⟩
rw [← dse]
obtain ⟨l, r⟩ := destruct_congr h
rcases l dsm with ⟨dt, dtm, dst⟩
rcases ds with - | a <;> rcases dt with - | b
· apply Computation.mem_map _ dtm
· cases b
cases dst
· cases a
cases dst
· obtain ⟨a, s'⟩ := a
obtain ⟨b, t'⟩ := b
rw [dst.left]
exact @Computation.mem_map _ _ (@Functor.map _ _ (α × WSeq α) _ Prod.fst)
(some (b, t')) (destruct t) dtm
theorem flatten_equiv {c : Computation (WSeq α)} {s} (h : s ∈ c) : flatten c ~ʷ s := by
apply Computation.memRecOn h
· simp [Equiv.refl]
· intro s'
apply Equiv.trans
simp [think_equiv]
theorem liftRel_flatten {R : α → β → Prop} {c1 : Computation (WSeq α)} {c2 : Computation (WSeq β)}
(h : c1.LiftRel (LiftRel R) c2) : LiftRel R (flatten c1) (flatten c2) :=
let S s t := ∃ c1 c2, s = flatten c1 ∧ t = flatten c2 ∧ Computation.LiftRel (LiftRel R) c1 c2
⟨S, ⟨c1, c2, rfl, rfl, h⟩, fun {s t} h =>
match s, t, h with
| _, _, ⟨c1, c2, rfl, rfl, h⟩ => by
simp only [destruct_flatten]; apply liftRel_bind _ _ h
intro a b ab; apply Computation.LiftRel.imp _ _ _ (liftRel_destruct ab)
intro a b; apply LiftRelO.imp_right
intro s t h; refine ⟨Computation.pure s, Computation.pure t, ?_, ?_, ?_⟩ <;> simp [h]⟩
theorem flatten_congr {c1 c2 : Computation (WSeq α)} :
Computation.LiftRel Equiv c1 c2 → flatten c1 ~ʷ flatten c2 :=
liftRel_flatten
theorem tail_congr {s t : WSeq α} (h : s ~ʷ t) : tail s ~ʷ tail t := by
apply flatten_congr
dsimp only [(· <$> ·)]; rw [← Computation.bind_pure, ← Computation.bind_pure]
apply liftRel_bind _ _ (destruct_congr h)
intro a b h; simp only [comp_apply, liftRel_pure]
rcases a with - | a <;> rcases b with - | b
· trivial
· cases h
· cases a
cases h
· obtain ⟨a, s'⟩ := a
obtain ⟨b, t'⟩ := b
exact h.right
theorem dropn_congr {s t : WSeq α} (h : s ~ʷ t) (n) : drop s n ~ʷ drop t n := by
induction n <;> simp [*, tail_congr, drop]
theorem get?_congr {s t : WSeq α} (h : s ~ʷ t) (n) : get? s n ~ get? t n :=
head_congr (dropn_congr h _)
theorem mem_congr {s t : WSeq α} (h : s ~ʷ t) (a) : a ∈ s ↔ a ∈ t :=
suffices ∀ {s t : WSeq α}, s ~ʷ t → a ∈ s → a ∈ t from ⟨this h, this h.symm⟩
fun {_ _} h as =>
let ⟨_, hn⟩ := exists_get?_of_mem as
get?_mem ((get?_congr h _ _).1 hn)
theorem Equiv.ext {s t : WSeq α} (h : ∀ n, get? s n ~ get? t n) : s ~ʷ t :=
⟨fun s t => ∀ n, get? s n ~ get? t n, h, fun {s t} h => by
refine liftRel_def.2 ⟨?_, ?_⟩
· rw [← head_terminates_iff, ← head_terminates_iff]
exact terminates_congr (h 0)
· intro a b ma mb
rcases a with - | a <;> rcases b with - | b
· trivial
· injection mem_unique (Computation.mem_map _ ma) ((h 0 _).2 (Computation.mem_map _ mb))
· injection mem_unique (Computation.mem_map _ ma) ((h 0 _).2 (Computation.mem_map _ mb))
· obtain ⟨a, s'⟩ := a
obtain ⟨b, t'⟩ := b
injection mem_unique (Computation.mem_map _ ma) ((h 0 _).2 (Computation.mem_map _ mb)) with
ab
refine ⟨ab, fun n => ?_⟩
refine
(get?_congr (flatten_equiv (Computation.mem_map _ ma)) n).symm.trans
((?_ : get? (tail s) n ~ get? (tail t) n).trans
(get?_congr (flatten_equiv (Computation.mem_map _ mb)) n))
rw [get?_tail, get?_tail]
apply h⟩
theorem liftRel_map {δ} (R : α → β → Prop) (S : γ → δ → Prop) {s1 : WSeq α} {s2 : WSeq β}
{f1 : α → γ} {f2 : β → δ} (h1 : LiftRel R s1 s2) (h2 : ∀ {a b}, R a b → S (f1 a) (f2 b)) :
LiftRel S (map f1 s1) (map f2 s2) :=
⟨fun s1 s2 => ∃ s t, s1 = map f1 s ∧ s2 = map f2 t ∧ LiftRel R s t, ⟨s1, s2, rfl, rfl, h1⟩,
fun {s1 s2} h =>
match s1, s2, h with
| _, _, ⟨s, t, rfl, rfl, h⟩ => by
simp only [exists_and_left, destruct_map]
apply Computation.liftRel_map _ _ (liftRel_destruct h)
intro o p h
rcases o with - | a <;> rcases p with - | b
· simp
· cases b; cases h
· cases a; cases h
· obtain ⟨a, s⟩ := a; obtain ⟨b, t⟩ := b
obtain ⟨r, h⟩ := h
exact ⟨h2 r, s, rfl, t, rfl, h⟩⟩
theorem map_congr (f : α → β) {s t : WSeq α} (h : s ~ʷ t) : map f s ~ʷ map f t :=
liftRel_map _ _ h fun {_ _} => congr_arg _
theorem liftRel_append (R : α → β → Prop) {s1 s2 : WSeq α} {t1 t2 : WSeq β} (h1 : LiftRel R s1 t1)
(h2 : LiftRel R s2 t2) : LiftRel R (append s1 s2) (append t1 t2) :=
⟨fun s t => LiftRel R s t ∨ ∃ s1 t1, s = append s1 s2 ∧ t = append t1 t2 ∧ LiftRel R s1 t1,
Or.inr ⟨s1, t1, rfl, rfl, h1⟩, fun {s t} h =>
match s, t, h with
| s, t, Or.inl h => by
apply Computation.LiftRel.imp _ _ _ (liftRel_destruct h)
intro a b; apply LiftRelO.imp_right
intro s t; apply Or.inl
| _, _, Or.inr ⟨s1, t1, rfl, rfl, h⟩ => by
simp only [exists_and_left, destruct_append]
apply Computation.liftRel_bind _ _ (liftRel_destruct h)
intro o p h
rcases o with - | a <;> rcases p with - | b
· simp only [destruct_append.aux]
apply Computation.LiftRel.imp _ _ _ (liftRel_destruct h2)
intro a b
apply LiftRelO.imp_right
intro s t
apply Or.inl
· cases b; cases h
· cases a; cases h
· obtain ⟨a, s⟩ := a; obtain ⟨b, t⟩ := b
obtain ⟨r, h⟩ := h
simpa using ⟨r, Or.inr ⟨s, rfl, t, rfl, h⟩⟩⟩
theorem liftRel_join.lem (R : α → β → Prop) {S T} {U : WSeq α → WSeq β → Prop}
(ST : LiftRel (LiftRel R) S T)
(HU :
∀ s1 s2,
(∃ s t S T,
s1 = append s (join S) ∧
s2 = append t (join T) ∧ LiftRel R s t ∧ LiftRel (LiftRel R) S T) →
U s1 s2)
{a} (ma : a ∈ destruct (join S)) : ∃ b, b ∈ destruct (join T) ∧ LiftRelO R U a b := by
obtain ⟨n, h⟩ := exists_results_of_mem ma; clear ma; revert S T ST a
induction' n using Nat.strongRecOn with n IH
intro S T ST a ra; simp only [destruct_join] at ra
exact
let ⟨o, m, k, rs1, rs2, en⟩ := of_results_bind ra
let ⟨p, mT, rop⟩ := Computation.exists_of_liftRel_left (liftRel_destruct ST) rs1.mem
match o, p, rop, rs1, rs2, mT with
| none, none, _, _, rs2, mT => by
simp only [destruct_join]
exact ⟨none, mem_bind mT (ret_mem _), by rw [eq_of_pure_mem rs2.mem]; trivial⟩
| some (s, S'), some (t, T'), ⟨st, ST'⟩, _, rs2, mT => by
simp? [destruct_append] at rs2 says simp only [destruct_join.aux, destruct_append] at rs2
exact
let ⟨k1, rs3, ek⟩ := of_results_think rs2
let ⟨o', m1, n1, rs4, rs5, ek1⟩ := of_results_bind rs3
let ⟨p', mt, rop'⟩ := Computation.exists_of_liftRel_left (liftRel_destruct st) rs4.mem
match o', p', rop', rs4, rs5, mt with
| none, none, _, _, rs5', mt => by
have : n1 < n := by
rw [en, ek, ek1]
apply lt_of_lt_of_le _ (Nat.le_add_right _ _)
apply Nat.lt_succ_of_le (Nat.le_add_right _ _)
let ⟨ob, mb, rob⟩ := IH _ this ST' rs5'
refine ⟨ob, ?_, rob⟩
· simp +unfoldPartialApp only [destruct_join, destruct_join.aux]
apply mem_bind mT
simp only [destruct_append]
apply think_mem
apply mem_bind mt
exact mb
| some (a, s'), some (b, t'), ⟨ab, st'⟩, _, rs5, mt => by
simp? at rs5 says simp only [destruct_append.aux] at rs5
refine ⟨some (b, append t' (join T')), ?_, ?_⟩
· simp +unfoldPartialApp only [destruct_join, destruct_join.aux]
apply mem_bind mT
simp only [destruct_append]
apply think_mem
apply mem_bind mt
apply ret_mem
rw [eq_of_pure_mem rs5.mem]
exact ⟨ab, HU _ _ ⟨s', t', S', T', rfl, rfl, st', ST'⟩⟩
theorem liftRel_join (R : α → β → Prop) {S : WSeq (WSeq α)} {T : WSeq (WSeq β)}
(h : LiftRel (LiftRel R) S T) : LiftRel R (join S) (join T) :=
⟨fun s1 s2 =>
∃ s t S T,
s1 = append s (join S) ∧ s2 = append t (join T) ∧ LiftRel R s t ∧ LiftRel (LiftRel R) S T,
⟨nil, nil, S, T, by simp, by simp, by simp, h⟩, fun {s1 s2} ⟨s, t, S, T, h1, h2, st, ST⟩ => by
rw [h1, h2]; rw [destruct_append, destruct_append]
apply Computation.liftRel_bind _ _ (liftRel_destruct st)
exact fun {o p} h =>
match o, p, h with
| some (a, s), some (b, t), ⟨h1, h2⟩ => by
simpa using ⟨h1, s, t, S, rfl, T, rfl, h2, ST⟩
| none, none, _ => by
-- We do not `dsimp` with `LiftRelO` since `liftRel_join.lem` uses `LiftRelO`.
dsimp only [destruct_append.aux, Computation.LiftRel]; constructor
· intro
apply liftRel_join.lem _ ST fun _ _ => id
· intro b mb
rw [← LiftRelO.swap]
apply liftRel_join.lem (swap R)
· rw [← LiftRel.swap R, ← LiftRel.swap]
apply ST
· rw [← LiftRel.swap R, ← LiftRel.swap (LiftRel R)]
exact fun s1 s2 ⟨s, t, S, T, h1, h2, st, ST⟩ => ⟨t, s, T, S, h2, h1, st, ST⟩
· exact mb⟩
theorem join_congr {S T : WSeq (WSeq α)} (h : LiftRel Equiv S T) : join S ~ʷ join T :=
liftRel_join _ h
theorem liftRel_bind {δ} (R : α → β → Prop) (S : γ → δ → Prop) {s1 : WSeq α} {s2 : WSeq β}
{f1 : α → WSeq γ} {f2 : β → WSeq δ} (h1 : LiftRel R s1 s2)
(h2 : ∀ {a b}, R a b → LiftRel S (f1 a) (f2 b)) : LiftRel S (bind s1 f1) (bind s2 f2) :=
liftRel_join _ (liftRel_map _ _ h1 @h2)
theorem bind_congr {s1 s2 : WSeq α} {f1 f2 : α → WSeq β} (h1 : s1 ~ʷ s2) (h2 : ∀ a, f1 a ~ʷ f2 a) :
bind s1 f1 ~ʷ bind s2 f2 :=
liftRel_bind _ _ h1 fun {a b} h => by rw [h]; apply h2
@[simp]
theorem join_ret (s : WSeq α) : join (ret s) ~ʷ s := by simpa [ret] using think_equiv _
@[simp]
theorem join_map_ret (s : WSeq α) : join (map ret s) ~ʷ s := by
refine ⟨fun s1 s2 => join (map ret s2) = s1, rfl, ?_⟩
intro s' s h; rw [← h]
apply liftRel_rec fun c1 c2 => ∃ s, c1 = destruct (join (map ret s)) ∧ c2 = destruct s
· exact fun {c1 c2} h =>
match c1, c2, h with
| _, _, ⟨s, rfl, rfl⟩ => by
clear h
have (s : WSeq α) : ∃ s' : WSeq α,
(map ret s).join.destruct = (map ret s').join.destruct ∧ destruct s = s'.destruct :=
⟨s, rfl, rfl⟩
induction' s using WSeq.recOn with a s s <;> simp [ret, this]
· exact ⟨s, rfl, rfl⟩
@[simp]
theorem join_append (S T : WSeq (WSeq α)) : join (append S T) ~ʷ append (join S) (join T) := by
refine
⟨fun s1 s2 =>
∃ s S T, s1 = append s (join (append S T)) ∧ s2 = append s (append (join S) (join T)),
⟨nil, S, T, by simp, by simp⟩, ?_⟩
intro s1 s2 h
apply
liftRel_rec
(fun c1 c2 =>
∃ (s : WSeq α) (S T : _),
c1 = destruct (append s (join (append S T))) ∧
c2 = destruct (append s (append (join S) (join T))))
_ _ _
(let ⟨s, S, T, h1, h2⟩ := h
⟨s, S, T, congr_arg destruct h1, congr_arg destruct h2⟩)
rintro c1 c2 ⟨s, S, T, rfl, rfl⟩
induction' s using WSeq.recOn with a s s
· induction' S using WSeq.recOn with s S S
· simp only [nil_append, join_nil]
induction' T using WSeq.recOn with s T T
· simp
· simp only [join_cons, destruct_think, Computation.destruct_think, liftRelAux_inr_inr]
refine ⟨s, nil, T, ?_, ?_⟩ <;> simp
· simp only [join_think, destruct_think, Computation.destruct_think, liftRelAux_inr_inr]
refine ⟨nil, nil, T, ?_, ?_⟩ <;> simp
· simpa using ⟨s, S, T, rfl, rfl⟩
· refine ⟨nil, S, T, ?_, ?_⟩ <;> simp
· simpa using ⟨s, S, T, rfl, rfl⟩
· simpa using ⟨s, S, T, rfl, rfl⟩
@[simp]
theorem bind_ret (f : α → β) (s) : bind s (ret ∘ f) ~ʷ map f s := by
dsimp [bind]
rw [map_comp]
apply join_map_ret
@[simp]
theorem ret_bind (a : α) (f : α → WSeq β) : bind (ret a) f ~ʷ f a := by simp [bind]
@[simp]
theorem join_join (SS : WSeq (WSeq (WSeq α))) : join (join SS) ~ʷ join (map join SS) := by
refine
⟨fun s1 s2 =>
∃ s S SS,
s1 = append s (join (append S (join SS))) ∧
s2 = append s (append (join S) (join (map join SS))),
⟨nil, nil, SS, by simp, by simp⟩, ?_⟩
intro s1 s2 h
apply
liftRel_rec
(fun c1 c2 =>
∃ s S SS,
c1 = destruct (append s (join (append S (join SS)))) ∧
c2 = destruct (append s (append (join S) (join (map join SS)))))
_ (destruct s1) (destruct s2)
(let ⟨s, S, SS, h1, h2⟩ := h
⟨s, S, SS, by simp [h1], by simp [h2]⟩)
intro c1 c2 h
exact
match c1, c2, h with
| _, _, ⟨s, S, SS, rfl, rfl⟩ => by
clear h
induction' s using WSeq.recOn with a s s
· induction' S using WSeq.recOn with s S S
· simp only [nil_append, join_nil]
induction' SS using WSeq.recOn with S SS SS
· simp
· refine ⟨nil, S, SS, ?_, ?_⟩ <;> simp
· refine ⟨nil, nil, SS, ?_, ?_⟩ <;> simp
· simpa using ⟨s, S, SS, rfl, rfl⟩
· refine ⟨nil, S, SS, ?_, ?_⟩ <;> simp
· simpa using ⟨s, S, SS, rfl, rfl⟩
· simpa using ⟨s, S, SS, rfl, rfl⟩
@[simp]
theorem bind_assoc_comp (s : WSeq α) (f : α → WSeq β) (g : β → WSeq γ) :
bind (bind s f) g ~ʷ bind s ((fun y : WSeq β => bind y g) ∘ f) := by
simp only [bind, map_join]
rw [← map_comp f (map g), ← Function.comp_def, comp_assoc, map_comp (map g ∘ f) join s]
exact join_join (map (map g ∘ f) s)
@[simp]
theorem bind_assoc (s : WSeq α) (f : α → WSeq β) (g : β → WSeq γ) :
bind (bind s f) g ~ʷ bind s fun x : α => bind (f x) g := by
exact bind_assoc_comp s f g
end Stream'.WSeq
|
Bivariate.lean
|
/-
Copyright (c) 2024 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.RingTheory.AdjoinRoot
/-!
# Bivariate polynomials
This file introduces the notation `R[X][Y]` for the polynomial ring `R[X][X]` in two variables,
and the notation `Y` for the second variable, in the `Polynomial.Bivariate` scope.
It also defines `Polynomial.evalEval` for the evaluation of a bivariate polynomial at a point
on the affine plane, which is a ring homomorphism (`Polynomial.evalEvalRingHom`), as well as
the abbreviation `CC` to view a constant in the base ring `R` as a bivariate polynomial.
-/
/-- The notation `Y` for `X` in the `Polynomial` scope. -/
scoped[Polynomial.Bivariate] notation3:max "Y" => Polynomial.X (R := Polynomial _)
/-- The notation `R[X][Y]` for `R[X][X]` in the `Polynomial` scope. -/
scoped[Polynomial.Bivariate] notation3:max R "[X][Y]" => Polynomial (Polynomial R)
open scoped Polynomial.Bivariate
namespace Polynomial
noncomputable section
variable {R S : Type*}
section Semiring
variable [Semiring R]
/-- `evalEval x y p` is the evaluation `p(x,y)` of a two-variable polynomial `p : R[X][Y]`. -/
abbrev evalEval (x y : R) (p : R[X][Y]) : R := eval x (eval (C y) p)
/-- A constant viewed as a polynomial in two variables. -/
abbrev CC (r : R) : R[X][Y] := C (C r)
lemma evalEval_C (x y : R) (p : R[X]) : (C p).evalEval x y = p.eval x := by
rw [evalEval, eval_C]
@[simp]
lemma evalEval_CC (x y : R) (p : R) : (CC p).evalEval x y = p := by
rw [evalEval_C, eval_C]
@[simp]
lemma evalEval_zero (x y : R) : (0 : R[X][Y]).evalEval x y = 0 := by
simp only [evalEval, eval_zero]
@[simp]
lemma evalEval_one (x y : R) : (1 : R[X][Y]).evalEval x y = 1 := by
simp only [evalEval, eval_one]
@[simp]
lemma evalEval_natCast (x y : R) (n : ℕ) : (n : R[X][Y]).evalEval x y = n := by
simp only [evalEval, eval_natCast]
@[simp]
lemma evalEval_X (x y : R) : X.evalEval x y = y := by
rw [evalEval, eval_X, eval_C]
@[simp]
lemma evalEval_add (x y : R) (p q : R[X][Y]) :
(p + q).evalEval x y = p.evalEval x y + q.evalEval x y := by
simp only [evalEval, eval_add]
lemma evalEval_sum (x y : R) (p : R[X]) (f : ℕ → R → R[X][Y]) :
(p.sum f).evalEval x y = p.sum fun n a => (f n a).evalEval x y := by
simp only [evalEval, eval, eval₂_sum]
lemma evalEval_finset_sum {ι : Type*} (s : Finset ι) (x y : R) (f : ι → R[X][Y]) :
(∑ i ∈ s, f i).evalEval x y = ∑ i ∈ s, (f i).evalEval x y := by
simp only [evalEval, eval_finset_sum]
@[simp]
lemma evalEval_smul [DistribSMul S R] [IsScalarTower S R R] (x y : R) (s : S)
(p : R[X][Y]) : (s • p).evalEval x y = s • p.evalEval x y := by
simp only [evalEval, eval_smul]
lemma evalEval_surjective (x y : R) : Function.Surjective <| evalEval x y :=
fun y => ⟨CC y, evalEval_CC ..⟩
end Semiring
section Ring
variable [Ring R]
@[simp]
lemma evalEval_neg (x y : R) (p : R[X][Y]) : (-p).evalEval x y = -p.evalEval x y := by
simp only [evalEval, eval_neg]
@[simp]
lemma evalEval_sub (x y : R) (p q : R[X][Y]) :
(p - q).evalEval x y = p.evalEval x y - q.evalEval x y := by
simp only [evalEval, eval_sub]
@[simp]
lemma evalEval_intCast (x y : R) (n : ℤ) : (n : R[X][Y]).evalEval x y = n := by
simp only [evalEval, eval_intCast]
end Ring
section CommSemiring
variable [CommSemiring R]
@[simp]
lemma evalEval_mul (x y : R) (p q : R[X][Y]) :
(p * q).evalEval x y = p.evalEval x y * q.evalEval x y := by
simp only [evalEval, eval_mul]
lemma evalEval_prod {ι : Type*} (s : Finset ι) (x y : R) (p : ι → R[X][Y]) :
(∏ j ∈ s, p j).evalEval x y = ∏ j ∈ s, (p j).evalEval x y := by
simp only [evalEval, eval_prod]
lemma evalEval_list_prod (x y : R) (l : List R[X][Y]) :
l.prod.evalEval x y = (l.map <| evalEval x y).prod := by
simpa only [evalEval, eval_list_prod, List.map_map] using by rfl
lemma evalEval_multiset_prod (x y : R) (l : Multiset R[X][Y]) :
l.prod.evalEval x y = (l.map <| evalEval x y).prod := by
simpa only [evalEval, eval_multiset_prod, Multiset.map_map] using by rfl
@[simp]
lemma evalEval_pow (x y : R) (p : R[X][Y]) (n : ℕ) : (p ^ n).evalEval x y = p.evalEval x y ^ n := by
simp only [evalEval, eval_pow]
lemma evalEval_dvd (x y : R) {p q : R[X][Y]} : p ∣ q → p.evalEval x y ∣ q.evalEval x y :=
eval_dvd ∘ eval_dvd
lemma coe_algebraMap_eq_CC : algebraMap R R[X][Y] = CC (R := R) := rfl
/-- `evalEval x y` as a ring homomorphism. -/
@[simps!] abbrev evalEvalRingHom (x y : R) : R[X][Y] →+* R :=
(evalRingHom x).comp (evalRingHom <| C y)
lemma coe_evalEvalRingHom (x y : R) : evalEvalRingHom x y = evalEval x y := rfl
lemma evalEvalRingHom_eq (x : R) : evalEvalRingHom x = eval₂RingHom (evalRingHom x) := by
ext <;> simp
lemma eval₂_evalRingHom (x : R) : eval₂ (evalRingHom x) = evalEval x := by
ext1; rw [← coe_evalEvalRingHom, evalEvalRingHom_eq, coe_eval₂RingHom]
lemma map_evalRingHom_eval (x y : R) (p : R[X][Y]) :
(p.map <| evalRingHom x).eval y = p.evalEval x y := by
rw [eval_map, eval₂_evalRingHom]
end CommSemiring
section
variable [Semiring R] [Semiring S] (f : R →+* S) (p : R[X][Y]) (q : R[X])
lemma map_mapRingHom_eval_map : (p.map <| mapRingHom f).eval (q.map f) = (p.eval q).map f := by
rw [eval_map, ← coe_mapRingHom, eval₂_hom]
lemma map_mapRingHom_eval_map_eval (r : R) :
((p.map <| mapRingHom f).eval <| q.map f).eval (f r) = f ((p.eval q).eval r) := by
rw [map_mapRingHom_eval_map, eval_map, eval₂_hom]
lemma map_mapRingHom_evalEval (x y : R) :
(p.map <| mapRingHom f).evalEval (f x) (f y) = f (p.evalEval x y) := by
rw [evalEval, ← map_mapRingHom_eval_map_eval, map_C]
end
variable [CommSemiring R] [CommSemiring S]
/-- Two equivalent ways to express the evaluation of a bivariate polynomial over `R`
at a point in the affine plane over an `R`-algebra `S`. -/
lemma eval₂RingHom_eval₂RingHom (f : R →+* S) (x y : S) :
eval₂RingHom (eval₂RingHom f x) y =
(evalEvalRingHom x y).comp (mapRingHom <| mapRingHom f) := by
ext <;> simp
lemma eval₂_eval₂RingHom_apply (f : R →+* S) (x y : S) (p : R[X][Y]) :
eval₂ (eval₂RingHom f x) y p = (p.map <| mapRingHom f).evalEval x y :=
congr($(eval₂RingHom_eval₂RingHom f x y) p)
lemma eval_C_X_comp_eval₂_map_C_X :
(evalRingHom (C X : R[X][Y])).comp (eval₂RingHom (mapRingHom <| algebraMap R R[X][Y]) (C Y)) =
.id _ := by
ext <;> simp
/-- Viewing `R[X,Y,X']` as an `R[X']`-algebra, a polynomial `p : R[X',Y']` can be evaluated at
`Y : R[X,Y,X']` (substitution of `Y'` by `Y`), obtaining another polynomial in `R[X,Y,X']`.
When this polynomial is then evaluated at `X' = X`, the original polynomial `p` is recovered. -/
lemma eval_C_X_eval₂_map_C_X {p : R[X][Y]} :
eval (C X) (eval₂ (mapRingHom <| algebraMap R R[X][Y]) (C Y) p) = p :=
congr($eval_C_X_comp_eval₂_map_C_X p)
end
section aevalAeval
noncomputable section
variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]
/-- `aevalAeval x y` is the `R`-algebra evaluation morphism sending a two-variable polynomial
`p : R[X][Y]` to `p(x,y)`. -/
abbrev aevalAeval (x y : A) : R[X][Y] →ₐ[R] A :=
((aeval x).restrictScalars R).comp
(letI := Polynomial.algebra; (aeval (R := R[X]) (C y)).restrictScalars R)
theorem coe_aevalAeval_eq_evalEval (x y : A) : ⇑(aevalAeval x y) = evalEval x y := by
ext p; simp [aevalAeval, evalEval, aeval, eval, Algebra.ofId]
/-- The R-algebra automorphism given by `X ↦ Y` and `Y ↦ X`. -/
def Bivariate.swap : R[X][Y] ≃ₐ[R] R[X][Y] := by
apply AlgEquiv.ofAlgHom (aevalAeval (Y : R[X][Y]) (C X)) (aevalAeval (Y : R[X][Y]) (C X))
<;> (ext n m <;> simp)
@[simp]
theorem Bivariate.swap_apply (p : R[X][Y]) : swap p = p.aevalAeval (A := R[X][Y]) Y (C X) := rfl
theorem Bivariate.swap_X : swap (R := R) (C X) = Y := by simp
theorem Bivariate.swap_Y : swap (R := R) Y = (C X) := by simp
theorem Bivariate.swap_monomial_monomial (n m : ℕ) (r : R) :
swap (monomial n (monomial m r)) = (monomial m (monomial n r)) := by
simp [← C_mul_X_pow_eq_monomial]; ac_rfl
/-- Evaluating `swap p` at `x`, `y` is the same as evaluating `p` at `y` `x`. -/
theorem Bivariate.aevalAeval_swap (x y : A) (p : R[X][Y]) :
aevalAeval x y (swap p) = aevalAeval y x p := by
induction p using Polynomial.induction_on' with
| add => aesop
| monomial n a =>
simp
induction a using Polynomial.induction_on' <;> aesop (add norm add_mul)
attribute [local instance] Polynomial.algebra in
theorem Bivariate.aveal_eq_map_swap (x : A) (p : R[X][Y]) :
aeval (C x) p = mapAlgHom (aeval x) (swap p) := by
induction p using Polynomial.induction_on' with
| add => aesop
| monomial n a =>
simp
induction a using Polynomial.induction_on'
<;> aesop (add norm [add_mul, C_mul_X_pow_eq_monomial])
end
end aevalAeval
end Polynomial
open Polynomial
namespace AdjoinRoot
variable {R : Type*} [CommRing R] {x y : R} {p : R[X][Y]} (h : p.evalEval x y = 0)
/-- If the evaluation (`evalEval`) of a bivariate polynomial `p : R[X][Y]` at a point (x,y)
is zero, then `Polynomial.evalEval x y` factors through `AdjoinRoot.evalEval`, a ring homomorphism
from `AdjoinRoot p` to `R`. -/
@[simps!] noncomputable def evalEval : AdjoinRoot p →+* R :=
lift (evalRingHom x) y <| eval₂_evalRingHom x ▸ h
lemma evalEval_mk (g : R[X][Y]) : evalEval h (mk p g) = g.evalEval x y := by
rw [evalEval, lift_mk, eval₂_evalRingHom]
end AdjoinRoot
|
qpoly.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import fintype tuple bigop binomial finset finfun ssralg.
From mathcomp Require Import countalg finalg poly polydiv perm fingroup matrix.
From mathcomp Require Import mxalgebra mxpoly vector countalg.
(******************************************************************************)
(* This file defines the algebras R[X]/<p> and their theory. *)
(* It mimics the zmod file for polynomials *)
(* First, it defines polynomials of bounded size (equivalent of 'I_n), *)
(* gives it a structure of choice, finite and countable ring, ..., and *)
(* lmodule, when possible. *)
(* Internally, the construction uses poly_rV and rVpoly, but they should not *)
(* be exposed. *)
(* We provide two bases: the 'X^i and the lagrange polynomials. *)
(* {poly_n R} == the type of polynomial of size at most n *)
(* irreducibleb p == boolean decision procedure for irreducibility *)
(* of a bounded size polynomial over a finite idomain *)
(* Considering {poly_n F} over a field F, it is a vectType and *)
(* 'nX^i == 'X^i as an element of {poly_n R} *)
(* polynX == [tuple 'X^0, ..., 'X^(n - 1)], basis of {poly_n R} *)
(* x.-lagrange == lagrange basis of {poly_n R} wrt x : nat -> F *)
(* x.-lagrange_ i == the ith lagrange polynomial wrt the sampling points x *)
(* Second, it defines polynomials quotiented by a poly (equivalent of 'Z_p), *)
(* as bounded polynomial. As we are aiming to build a ring structure we need *)
(* the polynomial to be monic and of size greater than one. If it is not the *)
(* case we quotient by 'X *)
(* mk_monic p == the actual polynomial on which we quotient *)
(* if p is monic and of size > 1 it is p otherwise 'X *)
(* {poly %/ p} == defined as {poly_(size (mk_poly p)).-1 R} on which *)
(* there is a ring structure *)
(* in_qpoly q == turn the polynomial q into an element of {poly %/ p} by *)
(* taking a modulo *)
(* 'qX == in_qpoly 'X *)
(* The last part that defines the field structure when the quotient is an *)
(* irreducible polynomial is defined in field/qfpoly *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory.
Import Pdiv.CommonRing.
Import Pdiv.RingMonic.
Import Pdiv.Field.
Import FinRing.Theory.
Local Open Scope ring_scope.
Reserved Notation "'{poly_' n R }" (n at level 2, format "'{poly_' n R }").
Reserved Notation "''nX^' i" (at level 1, format "''nX^' i").
Reserved Notation "x .-lagrange" (format "x .-lagrange").
Reserved Notation "x .-lagrange_" (format "x .-lagrange_").
Reserved Notation "'qX".
Reserved Notation "{ 'poly' '%/' p }"
(p at level 2, format "{ 'poly' '%/' p }").
Section poly_of_size_zmod.
Context {R : nzRingType}.
Implicit Types (n : nat).
Section poly_of_size.
Variable (n : nat).
Definition poly_of_size_pred := fun p : {poly R} => size p <= n.
Arguments poly_of_size_pred _ /.
Definition poly_of_size := [qualify a p | poly_of_size_pred p].
Lemma npoly_submod_closed : submod_closed poly_of_size.
Proof.
split=> [|x p q sp sq]; rewrite qualifE/= ?size_polyC ?eqxx//.
rewrite (leq_trans (size_polyD _ _)) // geq_max.
by rewrite (leq_trans (size_scale_leq _ _)).
Qed.
HB.instance Definition _ :=
GRing.isSubmodClosed.Build R {poly R} poly_of_size_pred npoly_submod_closed.
End poly_of_size.
Arguments poly_of_size_pred _ _ /.
Section npoly.
Variable (n : nat).
Record npoly : predArgType := NPoly {
polyn :> {poly R};
_ : polyn \is a poly_of_size n
}.
HB.instance Definition _ := [isSub for @polyn].
Lemma npoly_is_a_poly_of_size (p : npoly) : val p \is a poly_of_size n.
Proof. by case: p. Qed.
Hint Resolve npoly_is_a_poly_of_size : core.
Lemma size_npoly (p : npoly) : size p <= n.
Proof. exact: npoly_is_a_poly_of_size. Qed.
Hint Resolve size_npoly : core.
HB.instance Definition _ := [Choice of npoly by <:].
HB.instance Definition _ := [SubChoice_isSubLmodule of npoly by <:].
Definition npoly_rV : npoly -> 'rV[R]_n := poly_rV \o val.
Definition rVnpoly : 'rV[R]_n -> npoly :=
insubd (0 : npoly) \o rVpoly.
Arguments rVnpoly /.
Arguments npoly_rV /.
Lemma npoly_rV_K : cancel npoly_rV rVnpoly.
Proof.
move=> p /=; apply/val_inj.
by rewrite val_insubd [_ \is a _]size_poly ?poly_rV_K.
Qed.
Lemma rVnpolyK : cancel rVnpoly npoly_rV.
Proof. by move=> p /=; rewrite val_insubd [_ \is a _]size_poly rVpolyK. Qed.
Hint Resolve npoly_rV_K rVnpolyK : core.
Lemma npoly_vect_axiom : Vector.axiom n npoly.
Proof. by exists npoly_rV; [exact:linearPZ | exists rVnpoly]. Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build R npoly npoly_vect_axiom.
End npoly.
End poly_of_size_zmod.
Arguments npoly {R}%_type n%_N.
Notation "'{poly_' n R }" := (@npoly R n) : type_scope.
#[global]
Hint Resolve size_npoly npoly_is_a_poly_of_size : core.
Arguments poly_of_size_pred _ _ _ /.
Arguments npoly : clear implicits.
HB.instance Definition _ (R : countNzRingType) n :=
[Countable of {poly_n R} by <:].
HB.instance Definition _ (R : finNzRingType) n : isFinite {poly_n R} :=
CanIsFinite (@npoly_rV_K R n).
Section npoly_theory.
Context (R : nzRingType) {n : nat}.
Lemma polyn_is_linear : linear (@polyn _ _ : {poly_n R} -> _).
Proof. by []. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly_n R} {poly R} _ (polyn (n:=n))
(GRing.semilinear_linear polyn_is_linear).
Canonical mk_npoly (E : nat -> R) : {poly_n R} :=
@NPoly R _ (\poly_(i < n) E i) (size_poly _ _).
Fact size_npoly0 : size (0 : {poly R}) <= n.
Proof. by rewrite size_poly0. Qed.
Definition npoly0 := NPoly (size_npoly0).
Fact npolyp_key : unit. Proof. exact: tt. Qed.
Definition npolyp : {poly R} -> {poly_n R} :=
locked_with npolyp_key (mk_npoly \o (nth 0)).
Definition npoly_of_seq := npolyp \o Poly.
Lemma npolyP (p q : {poly_n R}) : nth 0 p =1 nth 0 q <-> p = q.
Proof. by split => [/polyP/val_inj|->]. Qed.
Lemma coef_npolyp (p : {poly R}) i : (npolyp p)`_i = if i < n then p`_i else 0.
Proof. by rewrite /npolyp unlock /= coef_poly. Qed.
Lemma big_coef_npoly (p : {poly_n R}) i : n <= i -> p`_i = 0.
Proof.
by move=> i_big; rewrite nth_default // (leq_trans _ i_big) ?size_npoly.
Qed.
Lemma npolypK (p : {poly R}) : size p <= n -> npolyp p = p :> {poly R}.
Proof.
move=> spn; apply/polyP=> i; rewrite coef_npolyp.
by have [i_big|i_small] // := ltnP; rewrite nth_default ?(leq_trans spn).
Qed.
Lemma coefn_sum (I : Type) (r : seq I) (P : pred I)
(F : I -> {poly_n R}) (k : nat) :
(\sum_(i <- r | P i) F i)`_k = \sum_(i <- r | P i) (F i)`_k.
Proof. by rewrite !raddf_sum //= coef_sum. Qed.
End npoly_theory.
Arguments mk_npoly {R} n E.
Arguments npolyp {R} n p.
Section fin_npoly.
Variable R : finNzRingType.
Variable n : nat.
Implicit Types p q : {poly_n R}.
Definition npoly_enum : seq {poly_n R} :=
if n isn't n.+1 then [:: npoly0 _] else
pmap insub [seq \poly_(i < n.+1) c (inord i) | c : (R ^ n.+1)%type].
Lemma npoly_enum_uniq : uniq npoly_enum.
Proof.
rewrite /npoly_enum; case: n=> [|k] //.
rewrite pmap_sub_uniq // map_inj_uniq => [|f g eqfg]; rewrite ?enum_uniq //.
apply/ffunP => /= i; have /(congr1 (fun p : {poly _} => p`_i)) := eqfg.
by rewrite !coef_poly ltn_ord inord_val.
Qed.
Lemma mem_npoly_enum p : p \in npoly_enum.
Proof.
rewrite /npoly_enum; case: n => [|k] // in p *.
case: p => [p sp] /=.
by rewrite in_cons -val_eqE /= -size_poly_leq0 [size _ <= _]sp.
rewrite mem_pmap_sub; apply/mapP.
eexists [ffun i : 'I__ => p`_i]; first by rewrite mem_enum.
apply/polyP => i; rewrite coef_poly.
have [i_small|i_big] := ltnP; first by rewrite ffunE /= inordK.
by rewrite nth_default // 1?(leq_trans _ i_big) // size_npoly.
Qed.
Lemma card_npoly : #|{poly_n R}| = (#|R| ^ n)%N.
Proof.
rewrite -(card_imset _ (can_inj (@npoly_rV_K _ _))) eq_cardT.
by rewrite -cardT /= card_mx mul1n.
by move=> v; apply/imsetP; exists (rVnpoly v); rewrite ?rVnpolyK //.
Qed.
End fin_npoly.
Section Irreducible.
Variable R : finIdomainType.
Variable p : {poly R}.
Definition irreducibleb :=
((1 < size p) &&
[forall q : {poly_((size p).-1) R},
(Pdiv.Ring.rdvdp q p)%R ==> (size q <= 1)])%N.
Lemma irreducibleP : reflect (irreducible_poly p) irreducibleb.
Proof.
rewrite /irreducibleb /irreducible_poly.
apply: (iffP idP) => [/andP[sp /'forall_implyP /= Fp]|[sp Fpoly]].
have sp_gt0 : size p > 0 by case: size sp.
have p_neq0 : p != 0 by rewrite -size_poly_eq0; case: size sp.
split => // q sq_neq1 dvd_qp; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=.
apply: contraNT sq_neq1; rewrite -ltnNge => sq_lt_sp.
have q_small: (size q <= (size p).-1)%N by rewrite -ltnS prednK.
rewrite Pdiv.Idomain.dvdpE in dvd_qp.
have /= := Fp (NPoly q_small) dvd_qp.
rewrite leq_eqVlt ltnS => /orP[//|]; rewrite size_poly_leq0 => /eqP q_eq0.
by rewrite -Pdiv.Idomain.dvdpE q_eq0 dvd0p (negPf p_neq0) in dvd_qp.
have sp_gt0 : size p > 0 by case: size sp.
rewrite sp /=; apply/'forall_implyP => /= q.
rewrite -Pdiv.Idomain.dvdpE=> dvd_qp.
have [/eqP->//|/Fpoly/(_ dvd_qp)/eqp_size sq_eq_sp] := boolP (size q == 1%N).
by have := size_npoly q; rewrite sq_eq_sp -ltnS prednK ?ltnn.
Qed.
End Irreducible.
Section Vspace.
Variable (K : fieldType) (n : nat).
Lemma dim_polyn : \dim (fullv : {vspace {poly_n K}}) = n.
Proof. by rewrite [LHS]mxrank_gen mxrank1. Qed.
Definition npolyX : n.-tuple {poly_n K} := [tuple npolyp n 'X^i | i < n].
Notation "''nX^' i" := (tnth npolyX i).
Lemma npolyXE (i : 'I_n) : 'nX^i = 'X^i :> {poly _}.
Proof. by rewrite tnth_map tnth_ord_tuple npolypK // size_polyXn. Qed.
Lemma nth_npolyX (i : 'I_n) : npolyX`_i = 'nX^i.
Proof. by rewrite -tnth_nth. Qed.
Lemma npolyX_free : free npolyX.
Proof.
apply/freeP=> u /= sum_uX_eq0 i; have /npolyP /(_ i) := sum_uX_eq0.
rewrite (@big_morph _ _ _ 0%R +%R) // coef_sum coef0.
rewrite (bigD1 i) ?big1 /= ?addr0 ?coefZ ?(nth_map 0%N) ?size_iota //.
by rewrite nth_npolyX npolyXE coefXn eqxx mulr1.
move=> j; rewrite -val_eqE /= => neq_ji.
by rewrite nth_npolyX npolyXE coefZ coefXn eq_sym (negPf neq_ji) mulr0.
Qed.
Lemma npolyX_full : basis_of fullv npolyX.
Proof.
by rewrite basisEfree npolyX_free subvf size_map size_enum_ord dim_polyn /=.
Qed.
Lemma npolyX_coords (p : {poly_n K}) i : coord npolyX i p = p`_i.
Proof.
rewrite [p in RHS](coord_basis npolyX_full) ?memvf // coefn_sum.
rewrite (bigD1 i) //= coefZ nth_npolyX npolyXE coefXn eqxx mulr1 big1 ?addr0//.
move=> j; rewrite -val_eqE => /= neq_ji.
by rewrite coefZ nth_npolyX npolyXE coefXn eq_sym (negPf neq_ji) mulr0.
Qed.
Lemma npolyX_gen (p : {poly K}) : (size p <= n)%N ->
p = \sum_(i < n) p`_i *: 'nX^i.
Proof.
move=> sp; rewrite -[p](@npolypK _ n) //.
rewrite [npolyp _ _ in LHS](coord_basis npolyX_full) ?memvf //.
rewrite (@big_morph _ _ _ 0%R +%R) // !raddf_sum.
by apply: eq_bigr=> i _; rewrite npolyX_coords //= nth_npolyX npolyXE.
Qed.
Section lagrange.
Variables (x : nat -> K).
Notation lagrange_def := (fun i :'I_n =>
let k := i in let p := \prod_(j < n | j != k) ('X - (x j)%:P)
in (p.[x k]^-1)%:P * p).
Fact lagrange_key : unit. Proof. exact: tt. Qed.
Definition lagrange := locked_with lagrange_key
[tuple npolyp n (lagrange_def i) | i < n].
Notation lagrange_ := (tnth lagrange).
Hypothesis n_gt0 : (0 < n)%N.
Hypothesis x_inj : injective x.
Let lagrange_def_sample (i j : 'I_n) : (lagrange_def i).[x j] = (i == j)%:R.
Proof.
clear n_gt0; rewrite hornerM hornerC; set p := (\prod_(_ < _ | _) _).
have [<-|neq_ij] /= := altP eqP.
rewrite mulVf // horner_prod; apply/prodf_neq0 => k neq_ki.
by rewrite hornerXsubC subr_eq0 inj_eq // eq_sym.
rewrite [X in _ * X]horner_prod (bigD1 j) 1?eq_sym //=.
by rewrite hornerXsubC subrr mul0r mulr0.
Qed.
Let size_lagrange_def i : size (lagrange_def i) = n.
Proof.
rewrite size_Cmul; last first.
suff : (lagrange_def i).[x i] != 0.
by rewrite hornerE mulf_eq0 => /norP [].
by rewrite lagrange_def_sample ?eqxx ?oner_eq0.
rewrite size_prod /=; last first.
by move=> j neq_ji; rewrite polyXsubC_eq0.
rewrite (eq_bigr (fun=> (2 * 1)%N)); last first.
by move=> j neq_ji; rewrite size_XsubC.
rewrite -big_distrr /= sum1_card cardC1 card_ord /=.
by case: (n) {i} n_gt0 => ?; rewrite mul2n -addnn -addSn addnK.
Qed.
Lemma lagrangeE i : lagrange_ i = lagrange_def i :> {poly _}.
Proof.
rewrite [lagrange]unlock tnth_map.
by rewrite [val _]npolypK tnth_ord_tuple // size_lagrange_def.
Qed.
Lemma nth_lagrange (i : 'I_n) : lagrange`_i = lagrange_ i.
Proof. by rewrite -tnth_nth. Qed.
Lemma size_lagrange_ i : size (lagrange_ i) = n.
Proof. by rewrite lagrangeE size_lagrange_def. Qed.
Lemma size_lagrange : size lagrange = n.
Proof. by rewrite size_tuple. Qed.
Lemma lagrange_sample (i j : 'I_n) : (lagrange_ i).[x j] = (i == j)%:R.
Proof. by rewrite lagrangeE lagrange_def_sample. Qed.
Lemma lagrange_free : free lagrange.
Proof.
apply/freeP=> lambda eq_l i.
have /(congr1 (fun p : {poly__ _} => p.[x i])) := eq_l.
rewrite (@big_morph _ _ _ 0%R +%R) // horner_sum horner0.
rewrite (bigD1 i) // big1 => [|j /= /negPf ji] /=;
by rewrite ?hornerE nth_lagrange lagrange_sample ?eqxx ?ji ?mulr1 ?mulr0.
Qed.
Lemma lagrange_full : basis_of fullv lagrange.
Proof.
by rewrite basisEfree lagrange_free subvf size_lagrange dim_polyn /=.
Qed.
Lemma lagrange_coords (p : {poly_n K}) i : coord lagrange i p = p.[x i].
Proof.
rewrite [p in RHS](coord_basis lagrange_full) ?memvf //.
rewrite (@big_morph _ _ _ 0%R +%R) // horner_sum.
rewrite (bigD1 i) // big1 => [|j /= /negPf ji] /=;
by rewrite ?hornerE nth_lagrange lagrange_sample ?eqxx ?ji ?mulr1 ?mulr0.
Qed.
Lemma lagrange_gen (p : {poly K}) : (size p <= n)%N ->
p = \sum_(i < n) p.[x i]%:P * lagrange_ i.
Proof.
move=> sp; rewrite -[p](@npolypK _ n) //.
rewrite [npolyp _ _ in LHS](coord_basis lagrange_full) ?memvf //.
rewrite (@big_morph _ _ _ 0%R +%R) //; apply: eq_bigr=> i _.
by rewrite lagrange_coords mul_polyC nth_lagrange.
Qed.
End lagrange.
End Vspace.
Notation "''nX^' i" := (tnth (npolyX _) i) : ring_scope.
Notation "x .-lagrange" := (lagrange x) : ring_scope.
Notation "x .-lagrange_" := (tnth x.-lagrange) : ring_scope.
Section Qpoly.
Variable R : nzRingType.
Variable h : {poly R}.
Definition mk_monic :=
if (1 < size h)%N && (h \is monic) then h else 'X.
Definition qpoly := {poly_(size mk_monic).-1 R}.
End Qpoly.
Notation "{ 'poly' '%/' p }" := (qpoly p) : type_scope.
Section QpolyProp.
Variable R : nzRingType.
Variable h : {poly R}.
Lemma monic_mk_monic : (mk_monic h) \is monic.
Proof.
rewrite /mk_monic; case: leqP=> [_|/=]; first by apply: monicX.
by case E : (h \is monic) => [->//|] => _; apply: monicX.
Qed.
Lemma size_mk_monic_gt1 : (1 < size (mk_monic h))%N.
Proof.
by rewrite !fun_if size_polyX; case: leqP => //=; rewrite if_same.
Qed.
Lemma size_mk_monic_gt0 : (0 < size (mk_monic h))%N.
Proof. by rewrite (leq_trans _ size_mk_monic_gt1). Qed.
Lemma mk_monic_neq0 : mk_monic h != 0.
Proof. by rewrite -size_poly_gt0 size_mk_monic_gt0. Qed.
Lemma size_mk_monic (p : {poly %/ h}) : size p < size (mk_monic h).
Proof.
have: (p : {poly R}) \is a poly_of_size (size (mk_monic h)).-1 by case: p.
by rewrite qualifE/= -ltnS prednK // size_mk_monic_gt0.
Qed.
(* standard inject *)
Lemma poly_of_size_mod p :
rmodp p (mk_monic h) \is a poly_of_size (size (mk_monic h)).-1.
Proof.
rewrite qualifE/= -ltnS prednK ?size_mk_monic_gt0 //.
by apply: ltn_rmodpN0; rewrite mk_monic_neq0.
Qed.
Definition in_qpoly p : {poly %/ h} := NPoly (poly_of_size_mod p).
Lemma in_qpoly_small (p : {poly R}) :
size p < size (mk_monic h) -> in_qpoly p = p :> {poly R}.
Proof. exact: rmodp_small. Qed.
Lemma in_qpoly0 : in_qpoly 0 = 0.
Proof. by apply/val_eqP; rewrite /= rmod0p. Qed.
Lemma in_qpolyD p q : in_qpoly (p + q) = in_qpoly p + in_qpoly q.
Proof. by apply/val_eqP=> /=; rewrite rmodpD ?monic_mk_monic. Qed.
Lemma in_qpolyZ a p : in_qpoly (a *: p) = a *: in_qpoly p.
Proof. apply/val_eqP=> /=; rewrite rmodpZ ?monic_mk_monic //. Qed.
Fact in_qpoly_is_linear : linear in_qpoly.
Proof. by move=> k p q; rewrite in_qpolyD in_qpolyZ. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly R} {poly_(size (mk_monic h)).-1 R} _ in_qpoly
(GRing.semilinear_linear in_qpoly_is_linear).
Lemma qpolyC_proof k :
(k%:P : {poly R}) \is a poly_of_size (size (mk_monic h)).-1.
Proof.
rewrite qualifE/= -ltnS size_polyC prednK ?size_mk_monic_gt0 //.
by rewrite (leq_ltn_trans _ size_mk_monic_gt1) //; case: eqP.
Qed.
Definition qpolyC k : {poly %/ h} := NPoly (qpolyC_proof k).
Lemma qpolyCE k : qpolyC k = k%:P :> {poly R}.
Proof. by []. Qed.
Lemma qpolyC0 : qpolyC 0 = 0.
Proof. by apply/val_eqP/eqP. Qed.
Definition qpoly1 := qpolyC 1.
Definition qpoly_mul (q1 q2 : {poly %/ h}) : {poly %/ h} :=
in_qpoly ((q1 : {poly R}) * q2).
Lemma qpoly_mul1z : left_id qpoly1 qpoly_mul.
Proof.
by move=> x; apply: val_inj; rewrite /= mul1r rmodp_small // size_mk_monic.
Qed.
Lemma qpoly_mulz1 : right_id qpoly1 qpoly_mul.
Proof.
by move=> x; apply: val_inj; rewrite /= mulr1 rmodp_small // size_mk_monic.
Qed.
Lemma qpoly_nontrivial : qpoly1 != 0.
Proof. by apply/eqP/val_eqP; rewrite /= oner_eq0. Qed.
Definition qpolyX := in_qpoly 'X.
Notation "'qX" := qpolyX.
Lemma qpolyXE : 2 < size h -> h \is monic -> 'qX = 'X :> {poly R}.
Proof.
move=> sh_gt2 h_mo.
by rewrite in_qpoly_small // size_polyX /mk_monic ifT // (ltn_trans _ sh_gt2).
Qed.
End QpolyProp.
Notation "'qX" := (qpolyX _) : ring_scope.
Lemma mk_monic_X (R : nzRingType) : mk_monic 'X = 'X :> {poly R}.
Proof. by rewrite /mk_monic size_polyX monicX. Qed.
Lemma mk_monic_Xn (R : nzRingType) n : mk_monic 'X^n = 'X^(n.-1.+1) :> {poly R}.
Proof. by case: n => [|n]; rewrite /mk_monic size_polyXn monicXn /= ?expr1. Qed.
Lemma card_qpoly (R : finNzRingType) (h : {poly R}):
#|{poly %/ h}| = #|R| ^ (size (mk_monic h)).-1.
Proof. by rewrite card_npoly. Qed.
Lemma card_monic_qpoly (R : finNzRingType) (h : {poly R}):
1 < size h -> h \is monic -> #|{poly %/ h}| = #|R| ^ (size h).-1.
Proof. by move=> sh_gt1 hM; rewrite card_qpoly /mk_monic sh_gt1 hM. Qed.
Section QRing.
Variable A : comNzRingType.
Variable h : {poly A}.
(* Ring operations *)
Lemma qpoly_mulC : commutative (@qpoly_mul A h).
Proof. by move=> p q; apply: val_inj; rewrite /= mulrC. Qed.
Lemma qpoly_mulA : associative (@qpoly_mul A h).
Proof.
have rPM := monic_mk_monic h; move=> p q r; apply: val_inj.
by rewrite /= rmodp_mulml // rmodp_mulmr // mulrA.
Qed.
Lemma qpoly_mul_addr : right_distributive (@qpoly_mul A h) +%R.
Proof.
have rPM := monic_mk_monic h; move=> p q r; apply: val_inj.
by rewrite /= !(mulrDr, rmodp_mulmr, rmodpD).
Qed.
Lemma qpoly_mul_addl : left_distributive (@qpoly_mul A h) +%R.
Proof. by move=> p q r; rewrite -!(qpoly_mulC r) qpoly_mul_addr. Qed.
HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build {poly__ A} qpoly_mulA
qpoly_mulC (@qpoly_mul1z _ h) qpoly_mul_addl (@qpoly_nontrivial _ h).
HB.instance Definition _ := GRing.ComNzRing.on {poly %/ h}.
Lemma in_qpoly1 : in_qpoly h 1 = 1.
Proof.
apply/val_eqP/eqP/in_qpoly_small.
by rewrite size_polyC oner_eq0 /= size_mk_monic_gt1.
Qed.
Lemma in_qpolyM q1 q2 : in_qpoly h (q1 * q2) = in_qpoly h q1 * in_qpoly h q2.
Proof.
apply/val_eqP => /=.
by rewrite rmodp_mulml ?rmodp_mulmr // monic_mk_monic.
Qed.
Fact in_qpoly_monoid_morphism : monoid_morphism (in_qpoly h).
Proof. by split; [ apply: in_qpoly1 | apply: in_qpolyM]. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `in_qpoly_is_monoid_morphism` instead")]
Definition in_qpoly_is_multiplicative :=
(fun g => (g.2,g.1)) in_qpoly_monoid_morphism.
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly A} {poly %/ h} (in_qpoly h)
in_qpoly_monoid_morphism.
Lemma poly_of_qpoly_sum I (r : seq I) (P1 : pred I) (F : I -> {poly %/ h}) :
((\sum_(i <- r | P1 i) F i) =
\sum_(p <- r | P1 p) ((F p) : {poly A}) :> {poly A})%R.
Proof. by elim/big_rec2: _ => // i p q IH <-. Qed.
Lemma poly_of_qpolyD (p q : {poly %/ h}) :
p + q= (p : {poly A}) + q :> {poly A}.
Proof. by []. Qed.
Lemma qpolyC_natr p : (p%:R : {poly %/ h}) = p%:R :> {poly A}.
Proof. by elim: p => //= p IH; rewrite !mulrS poly_of_qpolyD IH. Qed.
Lemma pchar_qpoly : [pchar {poly %/ h}] =i [pchar A].
Proof.
move=> p; rewrite !inE; congr (_ && _).
apply/eqP/eqP=> [/(congr1 val) /=|pE]; last first.
by apply: val_inj => //=; rewrite qpolyC_natr /= -polyC_natr pE.
rewrite !qpolyC_natr -!polyC_natr => /(congr1 val) /=.
by rewrite polyseqC polyseq0; case: eqP.
Qed.
Lemma poly_of_qpolyM (p q : {poly %/ h}) :
p * q = rmodp ((p : {poly A}) * q) (mk_monic h) :> {poly A}.
Proof. by []. Qed.
Lemma poly_of_qpolyX (p : {poly %/ h}) n :
p ^+ n = rmodp ((p : {poly A}) ^+ n) (mk_monic h) :> {poly A}.
Proof.
have HhQ := monic_mk_monic h.
elim: n => //= [|n IH].
rewrite rmodp_small // size_polyC ?(leq_ltn_trans _ (size_mk_monic_gt1 _)) //.
by case: eqP.
by rewrite exprS /= IH // rmodp_mulmr // -exprS.
Qed.
Lemma qpolyCN (a : A) : qpolyC h (- a) = -(qpolyC h a).
Proof. apply: val_inj; rewrite /= raddfN //= raddfN. Qed.
Lemma qpolyCD : {morph (qpolyC h) : a b / a + b >-> a + b}%R.
Proof. by move=> a b; apply/val_eqP/eqP=> /=; rewrite -!raddfD. Qed.
Lemma qpolyCM : {morph (qpolyC h) : a b / a * b >-> a * b}%R.
Proof.
move=> a b; apply/val_eqP/eqP=> /=; rewrite -polyCM rmodp_small //=.
have := qpolyC_proof h (a * b).
by rewrite qualifE/= -ltnS prednK // size_mk_monic_gt0.
Qed.
Lemma qpolyC_is_zmod_morphism : zmod_morphism (qpolyC h).
Proof. by move=> x y; rewrite qpolyCD qpolyCN. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `qpolyC_is_zmod_morphism` instead")]
Definition qpolyC_is_additive := qpolyC_is_zmod_morphism.
Lemma qpolyC_is_monoid_morphism : monoid_morphism (qpolyC h).
Proof. by split=> // x y; rewrite qpolyCM. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `qpolyC_is_monoid_morphism` instead")]
Definition qpolyC_is_multiplicative :=
(fun g => (g.2,g.1)) qpolyC_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build A {poly %/ h} (qpolyC h)
qpolyC_is_zmod_morphism.
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build A {poly %/ h} (qpolyC h)
qpolyC_is_monoid_morphism.
Definition qpoly_scale k (p : {poly %/ h}) : {poly %/ h} := (k *: p)%R.
Fact qpoly_scaleA a b p :
qpoly_scale a (qpoly_scale b p) = qpoly_scale (a * b) p.
Proof. by apply/val_eqP; rewrite /= scalerA. Qed.
Fact qpoly_scale1l : left_id 1%R qpoly_scale.
Proof. by move=> p; apply/val_eqP; rewrite /= scale1r. Qed.
Fact qpoly_scaleDr a : {morph qpoly_scale a : p q / (p + q)%R}.
Proof. by move=> p q; apply/val_eqP; rewrite /= scalerDr. Qed.
Fact qpoly_scaleDl p : {morph qpoly_scale^~ p : a b / a + b}%R.
Proof. by move=> a b; apply/val_eqP; rewrite /= scalerDl. Qed.
Fact qpoly_scaleAl a p q : qpoly_scale a (p * q) = (qpoly_scale a p * q).
Proof. by apply/val_eqP; rewrite /= -scalerAl rmodpZ // monic_mk_monic. Qed.
Fact qpoly_scaleAr a p q : qpoly_scale a (p * q) = p * (qpoly_scale a q).
Proof. by apply/val_eqP; rewrite /= -scalerAr rmodpZ // monic_mk_monic. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build A {poly__ A}
qpoly_scaleAl.
HB.instance Definition _ := GRing.Lalgebra.on {poly %/ h}.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build A {poly__ A}
qpoly_scaleAr.
HB.instance Definition _ := GRing.Algebra.on {poly %/ h}.
Lemma poly_of_qpolyZ (p : {poly %/ h}) a :
a *: p = a *: (p : {poly A}) :> {poly A}.
Proof. by []. Qed.
End QRing.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_qpoly instead.")]
Notation char_qpoly := (pchar_qpoly) (only parsing).
Section Field.
Variable R : fieldType.
Variable h : {poly R}.
Local Notation hQ := (mk_monic h).
Definition qpoly_inv (p : {poly %/ h}) :=
if coprimep hQ p then let v : {poly %/ h} := in_qpoly h (egcdp hQ p).2 in
((lead_coef (v * p)) ^-1 *: v) else p.
(* Ugly *)
Lemma qpoly_mulVz (p : {poly %/ h}) : coprimep hQ p -> (qpoly_inv p * p = 1)%R.
Proof.
have hQM := monic_mk_monic h.
move=> hCp; apply: val_inj; rewrite /qpoly_inv /in_qpoly hCp /=.
have p_neq0 : p != 0%R.
apply/eqP=> pZ; move: hCp; rewrite pZ.
rewrite coprimep0 -size_poly_eq1.
by case: size (size_mk_monic_gt1 h) => [|[]].
have F : (egcdp hQ p).1 * hQ + (egcdp hQ p).2 * p %= 1.
apply: eqp_trans _ (_ : gcdp hQ p %= _).
rewrite eqp_sym.
by case: (egcdpP (mk_monic_neq0 h) p_neq0).
by rewrite -size_poly_eq1.
rewrite rmodp_mulml // -scalerAl rmodpZ // rmodp_mulml //.
rewrite -[rmodp]/Pdiv.Ring.rmodp -!Pdiv.IdomainMonic.modpE //.
have := eqp_modpl hQ F.
rewrite modpD // modp_mull add0r // .
rewrite [(1 %% _)%R]modp_small => // [egcdE|]; last first.
by rewrite size_polyC oner_eq0 size_mk_monic_gt1.
rewrite {2}(eqpfP egcdE) lead_coefC divr1 alg_polyC scale_polyC mulVf //.
rewrite lead_coef_eq0.
apply/eqP => egcdZ.
by move: egcdE; rewrite -size_poly_eq1 egcdZ size_polyC eq_sym eqxx.
Qed.
Lemma qpoly_mulzV (p : {poly %/ h}) :
coprimep hQ p -> (p * (qpoly_inv p) = 1)%R.
Proof. by move=> hCp; rewrite /= mulrC qpoly_mulVz. Qed.
Lemma qpoly_intro_unit (p q : {poly %/ h}) : (q * p = 1)%R -> coprimep hQ p.
Proof.
have hQM := monic_mk_monic h.
case; rewrite -[rmodp]/Pdiv.Ring.rmodp -!Pdiv.IdomainMonic.modpE // => qp1.
have:= coprimep1 hQ.
rewrite -coprimep_modr -[1%R]qp1 !coprimep_modr coprimepMr; by case/andP.
Qed.
Lemma qpoly_inv_out (p : {poly %/ h}) : ~~ coprimep hQ p -> qpoly_inv p = p.
Proof. by rewrite /qpoly_inv => /negPf->. Qed.
HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build {poly__ _}
qpoly_mulVz qpoly_intro_unit qpoly_inv_out.
HB.instance Definition _ := GRing.ComUnitAlgebra.on {poly %/ h}.
Lemma irreducible_poly_coprime (A : idomainType) (p q : {poly A}) :
irreducible_poly p -> coprimep p q = ~~(p %| q)%R.
Proof.
case => H1 H2; apply/coprimepP/negP.
move=> sPq H.
by have := sPq p (dvdpp _) H; rewrite -size_poly_eq1; case: size H1 => [|[]].
move=> pNDq d dDp dPq.
rewrite -size_poly_eq1; case: eqP => // /eqP /(H2 _) => /(_ dDp) dEp.
by case: pNDq; rewrite -(eqp_dvdl _ dEp).
Qed.
End Field.
|
Pow.lean
|
/-
Copyright (c) 2023 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
/-!
# Convexity properties of `rpow`
We prove basic convexity properties of the `rpow` function. The proofs are elementary and do not
require calculus, and as such this file has only moderate dependencies.
## Main declarations
* `NNReal.strictConcaveOn_rpow`, `Real.strictConcaveOn_rpow`: strict concavity of
`fun x ↦ x ^ p` for p ∈ (0,1)
* `NNReal.concaveOn_rpow`, `Real.concaveOn_rpow`: concavity of `fun x ↦ x ^ p` for p ∈ [0,1]
Note that convexity for `p > 1` can be found in `Analysis.Convex.SpecificFunctions.Basic`, which
requires slightly less imports.
## TODO
* Prove convexity for negative powers.
-/
open Set
namespace NNReal
lemma strictConcaveOn_rpow {p : ℝ} (hp₀ : 0 < p) (hp₁ : p < 1) :
StrictConcaveOn ℝ≥0 univ fun x : ℝ≥0 ↦ x ^ p := by
have hp₀' : 0 < 1 / p := div_pos zero_lt_one hp₀
have hp₁' : 1 < 1 / p := by rw [one_lt_div hp₀]; exact hp₁
let f := NNReal.orderIsoRpow (1 / p) hp₀'
have h₁ : StrictConvexOn ℝ≥0 univ f := by
refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩
exact (strictConvexOn_rpow hp₁').2 x.2 y.2 (by simp [hxy]) ha hb (by simp; norm_cast)
have h₂ : ∀ x, f.symm x = x ^ p := by simp [f, NNReal.orderIsoRpow_symm_eq]
refine ⟨convex_univ, fun x mx y my hxy a b ha hb hab => ?_⟩
simp only [← h₂]
exact (f.strictConcaveOn_symm h₁).2 mx my hxy ha hb hab
lemma concaveOn_rpow {p : ℝ} (hp₀ : 0 ≤ p) (hp₁ : p ≤ 1) :
ConcaveOn ℝ≥0 univ fun x : ℝ≥0 ↦ x ^ p := by
rcases eq_or_lt_of_le hp₀ with (rfl | hp₀)
· simpa only [rpow_zero] using concaveOn_const (c := 1) convex_univ
rcases eq_or_lt_of_le hp₁ with (rfl | hp₁)
· simpa only [rpow_one] using concaveOn_id convex_univ
exact (strictConcaveOn_rpow hp₀ hp₁).concaveOn
lemma strictConcaveOn_sqrt : StrictConcaveOn ℝ≥0 univ NNReal.sqrt := by
have : NNReal.sqrt = fun x : ℝ≥0 ↦ x ^ (1 / (2 : ℝ)) := by
ext x; exact mod_cast NNReal.sqrt_eq_rpow x
rw [this]
exact strictConcaveOn_rpow (by positivity) (by linarith)
end NNReal
namespace Real
open NNReal
lemma strictConcaveOn_rpow {p : ℝ} (hp₀ : 0 < p) (hp₁ : p < 1) :
StrictConcaveOn ℝ (Set.Ici 0) fun x : ℝ ↦ x ^ p := by
refine ⟨convex_Ici _, fun x hx y hy hxy a b ha hb hab => ?_⟩
let x' : ℝ≥0 := ⟨x, hx⟩
let y' : ℝ≥0 := ⟨y, hy⟩
let a' : ℝ≥0 := ⟨a, ha.le⟩
let b' : ℝ≥0 := ⟨b, hb.le⟩
have hxy' : x' ≠ y' := Subtype.coe_ne_coe.1 hxy
have hab' : a' + b' = 1 := by ext; simp [a', b', hab]
exact_mod_cast (NNReal.strictConcaveOn_rpow hp₀ hp₁).2 (Set.mem_univ x') (Set.mem_univ y')
hxy' (mod_cast ha) (mod_cast hb) hab'
lemma concaveOn_rpow {p : ℝ} (hp₀ : 0 ≤ p) (hp₁ : p ≤ 1) :
ConcaveOn ℝ (Set.Ici 0) fun x : ℝ ↦ x ^ p := by
rcases eq_or_lt_of_le hp₀ with (rfl | hp₀)
· simpa only [rpow_zero] using concaveOn_const (c := 1) (convex_Ici _)
rcases eq_or_lt_of_le hp₁ with (rfl | hp₁)
· simpa only [rpow_one] using concaveOn_id (convex_Ici _)
exact (strictConcaveOn_rpow hp₀ hp₁).concaveOn
lemma strictConcaveOn_sqrt : StrictConcaveOn ℝ (Set.Ici 0) (√· : ℝ → ℝ) := by
rw [funext Real.sqrt_eq_rpow]
exact strictConcaveOn_rpow (by positivity) (by linarith)
end Real
|
Card.lean
|
/-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta, Huỳnh Trần Khanh, Stuart Presnell
-/
import Mathlib.Data.Finset.Sym
import Mathlib.Data.Fintype.Sum
import Mathlib.Data.Fintype.Prod
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Stars and bars
In this file, we prove (in `Sym.card_sym_eq_multichoose`) that the function `multichoose n k`
defined in `Data/Nat/Choose/Basic` counts the number of multisets of cardinality `k` over an
alphabet of cardinality `n`. In conjunction with `Nat.multichoose_eq` proved in
`Data/Nat/Choose/Basic`, which shows that `multichoose n k = choose (n + k - 1) k`,
this is central to the "stars and bars" technique in combinatorics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars").
## Informal statement
Many problems in mathematics are of the form of (or can be reduced to) putting `k` indistinguishable
objects into `n` distinguishable boxes; for example, the problem of finding natural numbers
`x1, ..., xn` whose sum is `k`. This is equivalent to forming a multiset of cardinality `k` from
an alphabet of cardinality `n` -- for each box `i ∈ [1, n]` the multiset contains as many copies
of `i` as there are items in the `i`th box.
The "stars and bars" technique arises from another way of presenting the same problem. Instead of
putting `k` items into `n` boxes, we take a row of `k` items (the "stars") and separate them by
inserting `n-1` dividers (the "bars"). For example, the pattern `*|||**|*|` exhibits 4 items
distributed into 6 boxes -- note that any box, including the first and last, may be empty.
Such arrangements of `k` stars and `n-1` bars are in 1-1 correspondence with multisets of size `k`
over an alphabet of size `n`, and are counted by `choose (n + k - 1) k`.
Note that this problem is one component of Gian-Carlo Rota's "Twelvefold Way"
https://en.wikipedia.org/wiki/Twelvefold_way
## Formal statement
Here we generalise the alphabet to an arbitrary fintype `α`, and we use `Sym α k` as the type of
multisets of size `k` over `α`. Thus the statement that these are counted by `multichoose` is:
`Sym.card_sym_eq_multichoose : card (Sym α k) = multichoose (card α) k`
while the "stars and bars" technique gives
`Sym.card_sym_eq_choose : card (Sym α k) = choose (card α + k - 1) k`
## Tags
stars and bars, multichoose
-/
open Finset Fintype Function Sum Nat
variable {α : Type*}
namespace Sym
section Sym
variable (α) (n : ℕ)
/-- Over `Fin (n + 1)`, the multisets of size `k + 1` containing `0` are equivalent to those of size
`k`, as demonstrated by respectively erasing or appending `0`. -/
protected def e1 {n k : ℕ} : { s : Sym (Fin (n + 1)) (k + 1) // ↑0 ∈ s } ≃ Sym (Fin n.succ) k where
toFun s := s.1.erase 0 s.2
invFun s := ⟨cons 0 s, mem_cons_self 0 s⟩
left_inv s := by simp
right_inv s := by simp
/-- The multisets of size `k` over `Fin n+2` not containing `0`
are equivalent to those of size `k` over `Fin n+1`,
as demonstrated by respectively decrementing or incrementing every element of the multiset.
-/
protected def e2 {n k : ℕ} : { s : Sym (Fin n.succ.succ) k // ↑0 ∉ s } ≃ Sym (Fin n.succ) k where
toFun s := map (Fin.predAbove 0) s.1
invFun s :=
⟨map (Fin.succAbove 0) s,
(mt mem_map.1) (not_exists.2 fun t => not_and.2 fun _ => Fin.succAbove_ne _ t)⟩
left_inv s := by
ext1
simp only [map_map]
refine (Sym.map_congr fun v hv ↦ ?_).trans (map_id' _)
exact Fin.succAbove_predAbove (ne_of_mem_of_not_mem hv s.2)
right_inv s := by
simp only [map_map, comp_apply, ← Fin.castSucc_zero, Fin.predAbove_succAbove, map_id']
theorem card_sym_fin_eq_multichoose : ∀ n k : ℕ, card (Sym (Fin n) k) = multichoose n k
| n, 0 => by simp
| 0, k + 1 => by rw [multichoose_zero_succ]; exact card_eq_zero
| 1, k + 1 => by simp
| n + 2, k + 1 => by
rw [multichoose_succ_succ, ← card_sym_fin_eq_multichoose (n + 1) (k + 1),
← card_sym_fin_eq_multichoose (n + 2) k, add_comm (Fintype.card _), ← card_sum]
refine Fintype.card_congr (Equiv.symm ?_)
apply (Sym.e1.symm.sumCongr Sym.e2.symm).trans
apply Equiv.sumCompl
/-- For any fintype `α` of cardinality `n`, `card (Sym α k) = multichoose (card α) k`. -/
theorem card_sym_eq_multichoose (α : Type*) (k : ℕ) [Fintype α] [Fintype (Sym α k)] :
card (Sym α k) = multichoose (card α) k := by
rw [← card_sym_fin_eq_multichoose]
exact card_congr (equivCongr (equivFin α))
/-- The *stars and bars* lemma: the cardinality of `Sym α k` is equal to
`Nat.choose (card α + k - 1) k`. -/
theorem card_sym_eq_choose {α : Type*} [Fintype α] (k : ℕ) [Fintype (Sym α k)] :
card (Sym α k) = (card α + k - 1).choose k := by
rw [card_sym_eq_multichoose, Nat.multichoose_eq]
end Sym
end Sym
namespace Sym2
variable [DecidableEq α]
/-- The `diag` of `s : Finset α` is sent on a finset of `Sym2 α` of card `#s`. -/
theorem card_image_diag (s : Finset α) : #(s.diag.image Sym2.mk) = #s := by
rw [card_image_of_injOn, diag_card]
rintro ⟨x₀, x₁⟩ hx _ _ h
cases Sym2.eq.1 h
· rfl
· simp only [mem_coe, mem_diag] at hx
rw [hx.2]
lemma two_mul_card_image_offDiag (s : Finset α) : 2 * #(s.offDiag.image Sym2.mk) = #s.offDiag := by
rw [card_eq_sum_card_image (Sym2.mk : α × α → _), sum_const_nat (Sym2.ind _), mul_comm]
rintro x y hxy
simp_rw [mem_image, mem_offDiag] at hxy
obtain ⟨a, ⟨ha₁, ha₂, ha⟩, h⟩ := hxy
replace h := Sym2.eq.1 h
obtain ⟨hx, hy, hxy⟩ : x ∈ s ∧ y ∈ s ∧ x ≠ y := by
cases h <;> refine ⟨‹_›, ‹_›, ?_⟩ <;> [exact ha; exact ha.symm]
have hxy' : y ≠ x := hxy.symm
have : {z ∈ s.offDiag | Sym2.mk z = s(x, y)} = {(x, y), (y, x)} := by
ext ⟨x₁, y₁⟩
rw [mem_filter, mem_insert, mem_singleton, Sym2.eq_iff, Prod.mk_inj, Prod.mk_inj,
and_iff_right_iff_imp]
-- `hxy'` is used in `exact`
rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) <;> rw [mem_offDiag] <;> exact ⟨‹_›, ‹_›, ‹_›⟩
rw [this, card_insert_of_notMem, card_singleton]
simp only [not_and, Prod.mk_inj, mem_singleton]
exact fun _ => hxy'
/-- The `offDiag` of `s : Finset α` is sent on a finset of `Sym2 α` of card `#s.offDiag / 2`.
This is because every element `s(x, y)` of `Sym2 α` not on the diagonal comes from exactly two
pairs: `(x, y)` and `(y, x)`. -/
theorem card_image_offDiag (s : Finset α) : #(s.offDiag.image Sym2.mk) = (#s).choose 2 := by
rw [Nat.choose_two_right, Nat.mul_sub_left_distrib, mul_one, ← offDiag_card,
Nat.div_eq_of_eq_mul_right Nat.zero_lt_two (two_mul_card_image_offDiag s).symm]
theorem card_subtype_diag [Fintype α] : card { a : Sym2 α // a.IsDiag } = card α := by
convert card_image_diag (univ : Finset α)
rw [← filter_image_mk_isDiag, Fintype.card_of_subtype]
rintro x
rw [mem_filter, univ_product_univ, mem_image]
obtain ⟨a, ha⟩ := Quot.exists_rep x
exact and_iff_right ⟨a, mem_univ _, ha⟩
theorem card_subtype_not_diag [Fintype α] :
card { a : Sym2 α // ¬a.IsDiag } = (card α).choose 2 := by
convert card_image_offDiag (univ : Finset α)
rw [← filter_image_mk_not_isDiag, Fintype.card_of_subtype]
rintro x
rw [mem_filter, univ_product_univ, mem_image]
obtain ⟨a, ha⟩ := Quot.exists_rep x
exact and_iff_right ⟨a, mem_univ _, ha⟩
/-- Type **stars and bars** for the case `n = 2`. -/
protected theorem card {α} [Fintype α] : card (Sym2 α) = Nat.choose (card α + 1) 2 :=
Finset.card_sym2 _
end Sym2
|
all_ssreflect.v
|
Attributes deprecated(since="mathcomp 2.5.0",
note="Use 'all_boot' and/or 'all_order' instead.").
From mathcomp Require Export all_boot.
From mathcomp Require Export preorder.
From mathcomp Require Export order.
|
Matrix.lean
|
/-
Copyright (c) 2025 Yunzhou Xie. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yunzhou Xie, Jujian Zhang
-/
import Mathlib.Algebra.Azumaya.Defs
import Mathlib.LinearAlgebra.FreeModule.Finite.Basic
/-!
# Matrix algebra is an Azumaya algebra over R
In this file we prove that finite dimensional matrix algebra `Matrix n n R` over `R`
is an Azumaya algebra where `R` is a commutative ring.
## Main Results
- `IsAzumaya.Matrix`: Finite dimensional matrix algebra over `R` is Azumaya.
-/
open scoped TensorProduct
variable (R n : Type*) [CommSemiring R] [Fintype n] [DecidableEq n]
noncomputable section
open Matrix MulOpposite
/-- `AlgHom.mulLeftRight` for matrix algebra sends basis Eᵢⱼ⊗Eₖₗ to
the map `f : Eₛₜ ↦ Eᵢⱼ * Eₛₜ * Eₖₗ = δⱼₛδₜₖEᵢₗ`, therefore we construct the inverse
by sending `f` to `∑ᵢₗₛₜ f(Eₛₜ)ᵢₗ • Eᵢₛ⊗Eₜₗ`. -/
abbrev AlgHom.mulLeftRightMatrix_inv :
Module.End R (Matrix n n R) →ₗ[R] Matrix n n R ⊗[R] (Matrix n n R)ᵐᵒᵖ where
toFun f := ∑ ⟨⟨i, j⟩, k, l⟩ : (n × n) × n × n,
f (single j k 1) i l • (single i j 1) ⊗ₜ[R] op (single k l 1)
map_add' f1 f2 := by simp [add_smul, Finset.sum_add_distrib]
map_smul' r f := by simp [MulAction.mul_smul, Finset.smul_sum]
lemma AlgHom.mulLeftRightMatrix.inv_comp :
(AlgHom.mulLeftRightMatrix_inv R n).comp
(AlgHom.mulLeftRight R (Matrix n n R)).toLinearMap = .id :=
((Matrix.stdBasis _ _ _).tensorProduct ((Matrix.stdBasis _ _ _).map (opLinearEquiv ..))).ext
fun ⟨⟨i0, j0⟩, k0, l0⟩ ↦ by
simp [stdBasis_eq_single, ite_and, Fintype.sum_prod_type,
mulLeftRight_apply, single, Matrix.mul_apply]
lemma AlgHom.mulLeftRightMatrix.comp_inv :
(AlgHom.mulLeftRight R (Matrix n n R)).toLinearMap.comp
(AlgHom.mulLeftRightMatrix_inv R n) = .id := by
ext f : 1
apply (Matrix.stdBasis _ _ _).ext
intro ⟨i, j⟩
simp only [LinearMap.coe_comp, LinearMap.coe_mk, AddHom.coe_mk, Function.comp_apply, map_sum,
map_smul, stdBasis_eq_single, LinearMap.coeFn_sum, Finset.sum_apply,
LinearMap.smul_apply, LinearMap.id_coe, id_eq]
ext k l
simp [sum_apply, Matrix.mul_apply, single, Fintype.sum_prod_type, ite_and]
namespace IsAzumaya
/-- A nontrivial matrix ring over `R` is an Azumaya algebra over `R`. -/
theorem matrix [Nonempty n] : IsAzumaya R (Matrix n n R) where
eq_of_smul_eq_smul := by nontriviality R; exact eq_of_smul_eq_smul
bij := Function.bijective_iff_has_inverse.mpr
⟨AlgHom.mulLeftRightMatrix_inv R n,
DFunLike.congr_fun (AlgHom.mulLeftRightMatrix.inv_comp R n),
DFunLike.congr_fun (AlgHom.mulLeftRightMatrix.comp_inv R n)⟩
end IsAzumaya
end
|
cyclotomic.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime.
From mathcomp Require Import ssralg poly finset fingroup finalg zmodp cyclic.
From mathcomp Require Import ssrnum ssrint archimedean polydiv intdiv mxpoly.
From mathcomp Require Import rat vector falgebra fieldext separable galois algC.
(******************************************************************************)
(* This file provides few basic properties of cyclotomic polynomials. *)
(* We define: *)
(* cyclotomic z n == the factorization of the nth cyclotomic polynomial in *)
(* a ring R in which z is an nth primitive root of unity. *)
(* 'Phi_n == the nth cyclotomic polynomial in int. *)
(* This library is quite limited, and should be extended in the future. In *)
(* particular the irreducibity of 'Phi_n is only stated indirectly, as the *)
(* fact that its embedding in the algebraics (algC) is the minimal polynomial *)
(* of an nth primitive root of unity. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section CyclotomicPoly.
Section NzRing.
Variable R : nzRingType.
Definition cyclotomic (z : R) n :=
\prod_(k < n | coprime k n) ('X - (z ^+ k)%:P).
Lemma cyclotomic_monic z n : cyclotomic z n \is monic.
Proof. exact: monic_prod_XsubC. Qed.
Lemma size_cyclotomic z n : size (cyclotomic z n) = (totient n).+1.
Proof.
rewrite /cyclotomic -big_filter size_prod_XsubC; congr _.+1.
case: big_enumP => _ _ _ [_ ->].
rewrite totient_count_coprime -big_mkcond big_mkord -sum1_card.
by apply: eq_bigl => k; rewrite coprime_sym.
Qed.
End NzRing.
Lemma separable_Xn_sub_1 (R : idomainType) n :
n%:R != 0 :> R -> @separable_poly R ('X^n - 1).
Proof.
case: n => [/eqP// | n nz_n]; rewrite unlock linearB /= derivC subr0.
rewrite derivXn -scaler_nat coprimepZr //= exprS -scaleN1r coprimep_sym.
by rewrite coprimep_addl_mul coprimepZr ?coprimep1 // (signr_eq0 _ 1).
Qed.
Section Field.
Variables (F : fieldType) (n : nat) (z : F).
Hypothesis prim_z : n.-primitive_root z.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma root_cyclotomic x : root (cyclotomic z n) x = n.-primitive_root x.
Proof.
transitivity (x \in [seq z ^+ i | i : 'I_n in [pred i : 'I_n | coprime i n]]).
by rewrite -root_prod_XsubC big_image.
apply/imageP/idP=> [[k co_k_n ->] | prim_x].
by rewrite prim_root_exp_coprime.
have [k Dx] := prim_rootP prim_z (prim_expr_order prim_x).
exists (Ordinal (ltn_pmod k n_gt0)) => /=; last by rewrite prim_expr_mod.
by rewrite inE coprime_modl -(prim_root_exp_coprime k prim_z) -Dx.
Qed.
Lemma prod_cyclotomic :
'X^n - 1 = \prod_(d <- divisors n) cyclotomic (z ^+ (n %/ d)) d.
Proof.
have in_d d: (d %| n)%N -> val (@inord n d) = d by move/dvdn_leq/inordK=> /= ->.
have dv_n k: (n %/ gcdn k n %| n)%N.
by rewrite -{3}(divnK (dvdn_gcdr k n)) dvdn_mulr.
have [uDn _ inDn] := divisors_correct n_gt0.
have defDn: divisors n = map val (map (@inord n) (divisors n)).
by rewrite -map_comp map_id_in // => d; rewrite inDn => /in_d.
rewrite defDn big_map big_uniq /=; last first.
by rewrite -(map_inj_uniq val_inj) -defDn.
pose h (k : 'I_n) : 'I_n.+1 := inord (n %/ gcdn k n).
rewrite -(factor_Xn_sub_1 prim_z) big_mkord.
rewrite (partition_big h (dvdn^~ n)) /= => [|k _]; last by rewrite in_d ?dv_n.
apply: eq_big => d; first by rewrite -(mem_map val_inj) -defDn inDn.
set q := (n %/ d)%N => d_dv_n.
have [q_gt0 d_gt0]: (0 < q /\ 0 < d)%N by apply/andP; rewrite -muln_gt0 divnK.
have fP (k : 'I_d): (q * k < n)%N by rewrite divn_mulAC ?ltn_divLR ?ltn_pmul2l.
rewrite (reindex (fun k => Ordinal (fP k))); last first.
have f'P (k : 'I_n): (k %/ q < d)%N by rewrite ltn_divLR // mulnC divnK.
exists (fun k => Ordinal (f'P k)) => [k _ | k /eqnP/=].
by apply: val_inj; rewrite /= mulKn.
rewrite in_d // => Dd; apply: val_inj; rewrite /= mulnC divnK // /q -Dd.
by rewrite divnA ?mulKn ?dvdn_gcdl ?dvdn_gcdr.
apply: eq_big => k; rewrite ?exprM // -val_eqE in_d //=.
rewrite -eqn_mul ?dvdn_gcdr ?gcdn_gt0 ?n_gt0 ?orbT //.
rewrite -[n in gcdn _ n](divnK d_dv_n) -muln_gcdr mulnCA mulnA divnK //.
by rewrite mulnC eqn_mul // divnn n_gt0 eq_sym.
Qed.
End Field.
End CyclotomicPoly.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Local Definition algC_intr_inj := @intr_inj algC.
#[local] Hint Resolve algC_intr_inj : core.
Local Notation intCK := (@intrKfloor algC).
Lemma C_prim_root_exists n : (n > 0)%N -> {z : algC | n.-primitive_root z}.
Proof.
pose p : {poly algC} := 'X^n - 1; have [r Dp] := closed_field_poly_normal p.
move=> n_gt0; apply/sigW; rewrite (monicP _) ?monicXnsubC // scale1r in Dp.
have rn1: all n.-unity_root r by apply/allP=> z; rewrite -root_prod_XsubC -Dp.
have sz_r: (n < (size r).+1)%N.
by rewrite -(size_prod_XsubC r id) -Dp size_XnsubC.
have [|z] := hasP (has_prim_root n_gt0 rn1 _ sz_r); last by exists z.
by rewrite -separable_prod_XsubC -Dp separable_Xn_sub_1 // pnatr_eq0 -lt0n.
Qed.
(* (Integral) Cyclotomic polynomials. *)
Definition Cyclotomic n : {poly int} :=
let: exist z _ := C_prim_root_exists (ltn0Sn n.-1) in
map_poly Num.floor (cyclotomic z n).
Notation "''Phi_' n" := (Cyclotomic n)
(at level 8, n at level 2, format "''Phi_' n").
Lemma Cyclotomic_monic n : 'Phi_n \is monic.
Proof.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /= _.
rewrite monicE lead_coefE coef_map_id0 ?(int_algC_K 0) ?floor0 //.
by rewrite size_poly_eq -lead_coefE (monicP (cyclotomic_monic _ _)) (intCK 1).
Qed.
Lemma Cintr_Cyclotomic n z :
n.-primitive_root z -> pZtoC 'Phi_n = cyclotomic z n.
Proof.
elim/ltn_ind: n z => n IHn z0 prim_z0.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /=.
have n_gt0 := prim_order_gt0 prim_z0; rewrite prednK // => prim_z.
have [uDn _ inDn] := divisors_correct n_gt0.
pose q := \prod_(d <- rem n (divisors n)) 'Phi_d.
have mon_q: q \is monic by apply: monic_prod => d _; apply: Cyclotomic_monic.
have defXn1: cyclotomic z n * pZtoC q = 'X^n - 1.
rewrite (prod_cyclotomic prim_z) (big_rem n) ?inDn //=.
rewrite divnn n_gt0 rmorph_prod /=; congr (_ * _).
apply: eq_big_seq => d; rewrite mem_rem_uniq ?inE //= inDn => /andP[n'd ddvn].
by rewrite -IHn ?dvdn_prim_root // ltn_neqAle n'd dvdn_leq.
have mapXn1 (R1 R2 : nzRingType) (f : {rmorphism R1 -> R2}):
map_poly f ('X^n - 1) = 'X^n - 1.
- by rewrite rmorphB /= rmorph1 map_polyXn.
have nz_q: pZtoC q != 0.
by rewrite -size_poly_eq0 size_map_inj_poly // size_poly_eq0 monic_neq0.
have [r def_zn]: exists r, cyclotomic z n = pZtoC r.
have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> a; rewrite /= rmorph_int.
have /dvdpP[r0 Dr0]: map_poly ZtoQ q %| 'X^n - 1.
rewrite -(dvdp_map (@ratr algC)) mapXn1 -map_poly_comp.
by rewrite -(eq_map_poly defZtoC) -defXn1 dvdp_mull.
have [r [a nz_a Dr]] := rat_poly_scale r0.
exists (zprimitive r); apply: (mulIf nz_q); rewrite defXn1.
rewrite -rmorphM -(zprimitive_monic mon_q) -zprimitiveM /=.
have ->: r * q = a *: ('X^n - 1).
apply: (map_inj_poly (intr_inj : injective ZtoQ)) => //.
rewrite map_polyZ mapXn1 Dr0 Dr -scalerAl scalerKV ?intr_eq0 //.
by rewrite rmorphM.
by rewrite zprimitiveZ // zprimitive_monic ?monicXnsubC ?mapXn1.
rewrite floorpK; last by apply/polyOverP=> i; rewrite def_zn coef_map /=.
pose f e (k : 'I_n) := Ordinal (ltn_pmod (k * e) n_gt0).
have [e Dz0] := prim_rootP prim_z (prim_expr_order prim_z0).
have co_e_n: coprime e n by rewrite -(prim_root_exp_coprime e prim_z) -Dz0.
have injf: injective (f e).
apply: can_inj (f (egcdn e n).1) _ => k; apply: val_inj => /=.
rewrite modnMml -mulnA -modnMmr -{1}(mul1n e).
by rewrite (chinese_modr co_e_n 0) modnMmr muln1 modn_small.
rewrite [_ n](reindex_inj injf); apply: eq_big => k /=.
by rewrite coprime_modl coprimeMl co_e_n andbT.
by rewrite prim_expr_mod // mulnC exprM -Dz0.
Qed.
Lemma prod_Cyclotomic n :
(n > 0)%N -> \prod_(d <- divisors n) 'Phi_d = 'X^n - 1.
Proof.
move=> n_gt0; have [z prim_z] := C_prim_root_exists n_gt0.
apply: (map_inj_poly (intr_inj : injective ZtoC)) => //.
rewrite rmorphB rmorph1 rmorph_prod /= map_polyXn (prod_cyclotomic prim_z).
apply: eq_big_seq => d; rewrite -dvdn_divisors // => d_dv_n.
by rewrite -Cintr_Cyclotomic ?dvdn_prim_root.
Qed.
Lemma Cyclotomic0 : 'Phi_0 = 1.
Proof.
rewrite /'Phi_0; case: (C_prim_root_exists _) => z /= _.
by rewrite -[1]polyseqK /cyclotomic big_ord0 map_polyE !polyseq1 /= (intCK 1).
Qed.
Lemma size_Cyclotomic n : size 'Phi_n = (totient n).+1.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite Cyclotomic0 polyseq1.
have [z prim_z] := C_prim_root_exists n_gt0.
rewrite -(size_map_inj_poly (can_inj intCK)) //.
by rewrite (Cintr_Cyclotomic prim_z) size_cyclotomic.
Qed.
Lemma minCpoly_cyclotomic n z :
n.-primitive_root z -> minCpoly z = cyclotomic z n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
have Dpz := Cintr_Cyclotomic prim_z; set pz := cyclotomic z n in Dpz *.
have mon_pz: pz \is monic by apply: cyclotomic_monic.
have pz0: root pz z by rewrite root_cyclotomic.
have [pf [Dpf mon_pf] dv_pf] := minCpolyP z.
have /dvdpP_rat_int[f [af nz_af Df] [g /esym Dfg]]: pf %| pZtoQ 'Phi_n.
rewrite -dv_pf; congr (root _ z): pz0; rewrite -Dpz -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
without loss{nz_af} [mon_f mon_g]: af f g Df Dfg / f \is monic /\ g \is monic.
move=> IH; pose cf := lead_coef f; pose cg := lead_coef g.
have cfg1: cf * cg = 1.
by rewrite -lead_coefM Dfg (monicP (Cyclotomic_monic n)).
apply: (IH (af *~ cf) (f *~ cg) (g *~ cf)).
- by rewrite rmorphMz -scalerMzr scalerMzl -mulrzA cfg1.
- by rewrite mulrzAl mulrzAr -mulrzA cfg1.
by rewrite !(intz, =^~ scaler_int) !monicE !lead_coefZ mulrC cfg1.
have{af} Df: pQtoC pf = pZtoC f.
have:= congr1 lead_coef Df.
rewrite lead_coefZ lead_coef_map_inj //; last exact: intr_inj.
rewrite !(monicP _) // mulr1 Df => <-; rewrite scale1r -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
have [/size1_polyC Dg | g_gt1] := leqP (size g) 1.
rewrite monicE Dg lead_coefC in mon_g.
by rewrite -Dpz -Dfg Dg (eqP mon_g) mulr1 Dpf.
have [zk gzk0]: exists zk, root (pZtoC g) zk.
have [rg] := closed_field_poly_normal (pZtoC g).
rewrite lead_coef_map_inj // (monicP mon_g) scale1r => Dg.
rewrite -(size_map_inj_poly (can_inj intCK)) // Dg in g_gt1.
rewrite size_prod_XsubC in g_gt1.
by exists rg`_0; rewrite Dg root_prod_XsubC mem_nth.
have [k cokn Dzk]: exists2 k, coprime k n & zk = z ^+ k.
have: root pz zk by rewrite -Dpz -Dfg rmorphM rootM gzk0 orbT.
rewrite -[pz](big_image _ _ _ _ (fun r => 'X - r%:P)) root_prod_XsubC.
by case/imageP=> k; exists k.
have co_fg (R : idomainType): n%:R != 0 :> R -> @coprimep R (intrp f) (intrp g).
move=> nz_n; have: separable_poly (intrp ('X^n - 1) : {poly R}).
by rewrite rmorphB rmorph1 /= map_polyXn separable_Xn_sub_1.
rewrite -prod_Cyclotomic // (big_rem n) -?dvdn_divisors //= -Dfg.
by rewrite !rmorphM /= !separable_mul => /and3P[] /and3P[].
suffices fzk0: root (pZtoC f) zk.
have [] // := negP (coprimep_root (co_fg _ _) fzk0).
by rewrite pnatr_eq0 -lt0n.
move: gzk0 cokn; rewrite {zk}Dzk; elim/ltn_ind: k => k IHk gzk0 cokn.
have [|k_gt1] := leqP k 1; last have [p p_pr /dvdnP[k1 Dk]] := pdivP k_gt1.
rewrite -[leq k 1](mem_iota 0 2) !inE => /pred2P[k0 | ->]; last first.
by rewrite -Df dv_pf.
have /eqP := size_Cyclotomic n; rewrite -Dfg size_Mmonic ?monic_neq0 //.
rewrite k0 /coprime gcd0n in cokn; rewrite (eqP cokn).
rewrite -(size_map_inj_poly (can_inj intCK)) // -Df -Dpf.
by rewrite -(subnKC g_gt1) -(subnKC (size_minCpoly z)) !addnS.
move: cokn; rewrite Dk coprimeMl => /andP[cok1n].
rewrite prime_coprime // (dvdn_pcharf (pchar_Fp p_pr)) => /co_fg {co_fg}.
have pcharFpX: p \in [pchar {poly 'F_p}] by rewrite (rmorph_pchar polyC) ?pchar_Fp.
rewrite -(coprimep_pexpr _ _ (prime_gt0 p_pr)) -(pFrobenius_autE pcharFpX).
rewrite -[g]comp_polyXr map_comp_poly -horner_map /= pFrobenius_autE -rmorphXn.
rewrite -!map_poly_comp (@eq_map_poly _ _ _ (polyC \o *~%R 1)); last first.
by move=> a; rewrite /= !rmorph_int.
rewrite map_poly_comp -[_.[_]]map_comp_poly /= => co_fg.
suffices: coprimep (pZtoC f) (pZtoC (g \Po 'X^p)).
move/coprimep_root=> /=/(_ (z ^+ k1))/implyP.
rewrite map_comp_poly map_polyXn horner_comp hornerXn.
rewrite -exprM -Dk [_ == 0]gzk0 implybF => /negP[].
have: root pz (z ^+ k1).
by rewrite root_cyclotomic // prim_root_exp_coprime.
rewrite -Dpz -Dfg rmorphM rootM => /orP[] //= /IHk-> //.
rewrite -[k1]muln1 Dk ltn_pmul2l ?prime_gt1 //.
by have:= ltnW k_gt1; rewrite Dk muln_gt0 => /andP[].
suffices: coprimep f (g \Po 'X^p).
case/Bezout_coprimepP=> [[u v]]; rewrite -size_poly_eq1.
rewrite -(size_map_inj_poly (can_inj intCK)) // rmorphD !rmorphM /=.
rewrite size_poly_eq1 => {}co_fg; apply/Bezout_coprimepP.
by exists (pZtoC u, pZtoC v).
apply: contraLR co_fg => /coprimepPn[|d]; first exact: monic_neq0.
rewrite andbC -size_poly_eq1 dvdp_gcd => /and3P[sz_d].
pose d1 := zprimitive d.
have d_dv_mon h: d %| h -> h \is monic -> exists h1, h = d1 * h1.
case/Pdiv.Idomain.dvdpP=> [[c h1] /= nz_c Dh] mon_h; exists (zprimitive h1).
by rewrite -zprimitiveM mulrC -Dh zprimitiveZ ?zprimitive_monic.
case/d_dv_mon=> // f1 Df1 /d_dv_mon[|f2 ->].
rewrite monicE lead_coefE size_comp_poly size_polyXn /=.
rewrite comp_polyE coef_sum polySpred ?monic_neq0 //= mulnC.
rewrite big_ord_recr /= -lead_coefE (monicP mon_g) scale1r.
rewrite -exprM coefXn eqxx big1 ?add0r // => i _.
rewrite coefZ -exprM coefXn eqn_pmul2l ?prime_gt0 //.
by rewrite eqn_leq leqNgt ltn_ord mulr0.
have monFp h: h \is monic -> size (map_poly intr h) = size h.
by move=> mon_h; rewrite size_poly_eq // -lead_coefE (monicP mon_h) oner_eq0.
apply/coprimepPn; last exists (map_poly intr d1).
by rewrite -size_poly_eq0 monFp // size_poly_eq0 monic_neq0.
rewrite Df1 !rmorphM dvdp_gcd !dvdp_mulr //= -size_poly_eq1.
rewrite monFp ?size_zprimitive //.
rewrite monicE [_ d1]intEsg sgz_lead_primitive -zprimitive_eq0 -/d1.
rewrite -lead_coef_eq0 -absz_eq0.
have/esym/eqP := congr1 (absz \o lead_coef) Df1.
by rewrite /= (monicP mon_f) lead_coefM abszM muln_eq1 => /andP[/eqP-> _].
Qed.
|
IdempotentFG.lean
|
/-
Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Buzzard
-/
import Mathlib.Algebra.Ring.Idempotent
import Mathlib.Order.Basic
import Mathlib.RingTheory.Finiteness.Nakayama
/-!
## Lemmas on idempotent finitely generated ideals
-/
namespace Ideal
/-- A finitely generated idempotent ideal is generated by an idempotent element -/
theorem isIdempotentElem_iff_of_fg {R : Type*} [CommRing R] (I : Ideal R) (h : I.FG) :
IsIdempotentElem I ↔ ∃ e : R, IsIdempotentElem e ∧ I = R ∙ e := by
constructor
· intro e
obtain ⟨r, hr, hr'⟩ :=
Submodule.exists_mem_and_smul_eq_self_of_fg_of_le_smul I I h
(by
rw [smul_eq_mul]
exact e.ge)
simp_rw [smul_eq_mul] at hr'
refine ⟨r, hr' r hr, antisymm ?_ ((Submodule.span_singleton_le_iff_mem _ _).mpr hr)⟩
intro x hx
rw [← hr' x hx]
exact Ideal.mem_span_singleton'.mpr ⟨_, mul_comm _ _⟩
· rintro ⟨e, he, rfl⟩
simp [IsIdempotentElem, Ideal.span_singleton_mul_span_singleton, he.eq]
theorem isIdempotentElem_iff_eq_bot_or_top {R : Type*} [CommRing R] [IsDomain R] (I : Ideal R)
(h : I.FG) : IsIdempotentElem I ↔ I = ⊥ ∨ I = ⊤ := by
constructor
· intro H
obtain ⟨e, he, rfl⟩ := (I.isIdempotentElem_iff_of_fg h).mp H
simp only [Ideal.submodule_span_eq, Ideal.span_singleton_eq_bot]
apply Or.imp id _ (IsIdempotentElem.iff_eq_zero_or_one.mp he)
rintro rfl
simp
· rintro (rfl | rfl) <;> simp [IsIdempotentElem]
end Ideal
|
ProjectiveSpecialLinearGroup.lean
|
/-
Copyright (c) 2023 Wen Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wen Yang
-/
import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup
/-!
# Projective Special Linear Group
## Notation
In the `MatrixGroups` locale:
* `PSL(n, R)` is a shorthand for `Matrix.ProjectiveSpecialLinearGroup (Fin n) R`
-/
namespace Matrix
universe u v
open Matrix LinearMap
open scoped MatrixGroups
variable (n : Type u) [DecidableEq n] [Fintype n] (R : Type v) [CommRing R]
/-- A projective special linear group is the quotient of a special linear group by its center. -/
abbrev ProjectiveSpecialLinearGroup : Type _ :=
SpecialLinearGroup n R ⧸ Subgroup.center (SpecialLinearGroup n R)
/-- `PSL(n, R)` is the projective special linear group `SL(n, R)/Z(SL(n, R))`. -/
scoped[MatrixGroups] notation "PSL(" n ", " R ")" => Matrix.ProjectiveSpecialLinearGroup (Fin n) R
end Matrix
|
Coherence.lean
|
import Mathlib.Tactic.CategoryTheory.Coherence
open CategoryTheory
universe w v u
section Monoidal
variable {C : Type u} [Category.{v} C] [MonoidalCategory C]
open scoped MonoidalCategory
-- Internal tactics
example (X₁ X₂ : C) :
((λ_ (𝟙_ C)).inv ⊗ₘ 𝟙 (X₁ ⊗ X₂)) ≫ (α_ (𝟙_ C) (𝟙_ C) (X₁ ⊗ X₂)).hom ≫
(𝟙 (𝟙_ C) ⊗ₘ (α_ (𝟙_ C) X₁ X₂).inv) =
𝟙 (𝟙_ C) ⊗ₘ ((λ_ X₁).inv ⊗ₘ 𝟙 X₂) := by
pure_coherence
-- This is just running:
-- change projectMap id _ _ (LiftHom.lift (((λ_ (𝟙_ C)).inv ⊗ 𝟙 (X₁ ⊗ X₂)) ≫
-- (α_ (𝟙_ C) (𝟙_ C) (X₁ ⊗ X₂)).hom ≫ (𝟙 (𝟙_ C) ⊗ (α_ (𝟙_ C) X₁ X₂).inv))) =
-- projectMap id _ _ (LiftHom.lift (𝟙 (𝟙_ C) ⊗ ((λ_ X₁).inv ⊗ 𝟙 X₂)))
-- exact congrArg _ (Subsingleton.elim _ _)
example {Y Z : C} (f : Y ⟶ Z) (g) (w : false) : (λ_ _).hom ≫ f = g := by
liftable_prefixes
guard_target = (𝟙 _ ≫ (λ_ _).hom) ≫ f = (𝟙 _) ≫ g
cases w
-- `coherence`
example (f : 𝟙_ C ⟶ _) : f ≫ (λ_ (𝟙_ C)).hom = f ≫ (ρ_ (𝟙_ C)).hom := by
coherence
example (f) : (λ_ (𝟙_ C)).hom ≫ f ≫ (λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom ≫ f ≫ (ρ_ (𝟙_ C)).hom := by
coherence
example {U : C} (f : U ⟶ 𝟙_ C) : f ≫ (ρ_ (𝟙_ C)).inv ≫ (λ_ (𝟙_ C)).hom = f := by
coherence
example (W X Y Z : C) (f) :
((α_ W X Y).hom ⊗ₘ 𝟙 Z) ≫ (α_ W (X ⊗ Y) Z).hom ≫ (𝟙 W ⊗ₘ (α_ X Y Z).hom) ≫ f ≫
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom =
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom ≫ f ≫
((α_ W X Y).hom ⊗ₘ 𝟙 Z) ≫ (α_ W (X ⊗ Y) Z).hom ≫ (𝟙 W ⊗ₘ (α_ X Y Z).hom) := by
coherence
example {U V W X Y : C} (f : U ⟶ V ⊗ (W ⊗ X)) (g : (V ⊗ W) ⊗ X ⟶ Y) :
f ⊗≫ g = f ≫ (α_ _ _ _).inv ≫ g := by
coherence
example : (λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom := by coherence
example : (λ_ (𝟙_ C)).inv = (ρ_ (𝟙_ C)).inv := by coherence
example (X Y Z : C) : (α_ X Y Z).inv ≫ (α_ X Y Z).hom = 𝟙 (X ⊗ Y ⊗ Z) := by coherence
example (X Y Z W : C) :
(𝟙 X ⊗ₘ (α_ Y Z W).hom) ≫ (α_ X Y (Z ⊗ W)).inv ≫ (α_ (X ⊗ Y) Z W).inv =
(α_ X (Y ⊗ Z) W).inv ≫ ((α_ X Y Z).inv ⊗ₘ 𝟙 W) := by
coherence
example (X Y : C) :
(𝟙 X ⊗ₘ (λ_ Y).inv) ≫ (α_ X (𝟙_ C) Y).inv = (ρ_ X).inv ⊗ₘ 𝟙 Y := by
coherence
example (X Y : C) (f : 𝟙_ C ⟶ X) (g : X ⟶ Y) (_w : false) :
(λ_ (𝟙_ C)).hom ≫ f ≫ 𝟙 X ≫ g = (ρ_ (𝟙_ C)).hom ≫ f ≫ g := by
coherence
example (X₁ X₂ : C) :
(α_ (𝟙_ C) (𝟙_ C) (X₁ ⊗ X₂)).hom ≫
(𝟙 (𝟙_ C) ⊗ₘ (α_ (𝟙_ C) X₁ X₂).inv) ≫
(𝟙 (𝟙_ C) ⊗ₘ (λ_ _).hom ≫ (ρ_ X₁).inv ⊗ₘ 𝟙 X₂) ≫
(𝟙 (𝟙_ C) ⊗ₘ (α_ X₁ (𝟙_ C) X₂).hom) ≫
(α_ (𝟙_ C) X₁ (𝟙_ C ⊗ X₂)).inv ≫
((λ_ X₁).hom ≫ (ρ_ X₁).inv ⊗ₘ 𝟙 (𝟙_ C ⊗ X₂)) ≫
(α_ X₁ (𝟙_ C) (𝟙_ C ⊗ X₂)).hom ≫
(𝟙 X₁ ⊗ₘ 𝟙 (𝟙_ C) ⊗ₘ (λ_ X₂).hom ≫ (ρ_ X₂).inv) ≫
(𝟙 X₁ ⊗ₘ (α_ (𝟙_ C) X₂ (𝟙_ C)).inv) ≫
(𝟙 X₁ ⊗ₘ (λ_ X₂).hom ≫ (ρ_ X₂).inv ⊗ₘ 𝟙 (𝟙_ C)) ≫
(𝟙 X₁ ⊗ₘ (α_ X₂ (𝟙_ C) (𝟙_ C)).hom) ≫
(α_ X₁ X₂ (𝟙_ C ⊗ 𝟙_ C)).inv =
(((λ_ (𝟙_ C)).hom ⊗ₘ 𝟙 (X₁ ⊗ X₂)) ≫ (λ_ (X₁ ⊗ X₂)).hom ≫ (ρ_ (X₁ ⊗ X₂)).inv) ≫
(𝟙 (X₁ ⊗ X₂) ⊗ₘ (λ_ (𝟙_ C)).inv) := by
coherence
end Monoidal
section Bicategory
open scoped Bicategory
variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B}
example {a : B} (f : a ⟶ a) : 𝟙 f ▷ f = 𝟙 (f ≫ f) := by whisker_simps
example : (λ_ (𝟙 a)).hom = (ρ_ (𝟙 a)).hom := by bicategory_coherence
example : (λ_ (𝟙 a)).inv = (ρ_ (𝟙 a)).inv := by bicategory_coherence
example (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) :
(α_ f g h).inv ≫ (α_ f g h).hom = 𝟙 (f ≫ g ≫ h) := by
bicategory_coherence
example (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) :
f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv =
(α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by
bicategory_coherence
example (f : a ⟶ b) (g : b ⟶ c) :
f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by
bicategory_coherence
example : 𝟙 (𝟙 a ≫ 𝟙 a) ≫ (λ_ (𝟙 a)).hom = 𝟙 (𝟙 a ≫ 𝟙 a) ≫ (ρ_ (𝟙 a)).hom := by
bicategory_coherence
set_option linter.unusedVariables false in
example (f g : a ⟶ a) (η : 𝟙 a ⟶ f) (θ : f ⟶ g) (w : false) :
(λ_ (𝟙 a)).hom ≫ η ≫ θ = (ρ_ (𝟙 a)).hom ≫ η ≫ θ := by
coherence
example (f₁ : a ⟶ b) (f₂ : b ⟶ c) :
(α_ (𝟙 a) (𝟙 a) (f₁ ≫ f₂)).hom ≫
𝟙 a ◁ (α_ (𝟙 a) f₁ f₂).inv ≫
𝟙 a ◁ ((λ_ f₁).hom ≫ (ρ_ f₁).inv) ▷ f₂ ≫
𝟙 a ◁ (α_ f₁ (𝟙 b) f₂).hom ≫
(α_ (𝟙 a) f₁ (𝟙 b ≫ f₂)).inv ≫
((λ_ f₁).hom ≫ (ρ_ f₁).inv) ▷ (𝟙 b ≫ f₂) ≫
(α_ f₁ (𝟙 b) (𝟙 b ≫ f₂)).hom ≫
f₁ ◁ 𝟙 b ◁ ((λ_ f₂).hom ≫ (ρ_ f₂).inv) ≫
f₁ ◁ (α_ (𝟙 b) f₂ (𝟙 c)).inv ≫
f₁ ◁ ((λ_ f₂).hom ≫ (ρ_ f₂).inv) ▷ 𝟙 c ≫
(f₁ ◁ (α_ f₂ (𝟙 c) (𝟙 c)).hom) ≫
(α_ f₁ f₂ (𝟙 c ≫ 𝟙 c)).inv =
((λ_ (𝟙 a)).hom ▷ (f₁ ≫ f₂) ≫ (λ_ (f₁ ≫ f₂)).hom ≫ (ρ_ (f₁ ≫ f₂)).inv) ≫
(f₁ ≫ f₂) ◁ (λ_ (𝟙 c)).inv := by
pure_coherence
end Bicategory
|
Contraction.lean
|
/-
Copyright (c) 2020 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Antoine Labelle
-/
import Mathlib.LinearAlgebra.Dual.Lemmas
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Contractions
Given modules $M, N$ over a commutative ring $R$, this file defines the natural linear maps:
$M^* \otimes M \to R$, $M \otimes M^* \to R$, and $M^* \otimes N → Hom(M, N)$, as well as proving
some basic properties of these maps.
## Tags
contraction, dual module, tensor product
-/
variable {ι : Type*} (R M N P Q : Type*)
-- Porting note: we need high priority for this to fire first; not the case in ML3
attribute [local ext high] TensorProduct.ext
section Contraction
open TensorProduct LinearMap Matrix Module
open TensorProduct
section CommSemiring
variable [CommSemiring R]
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [DecidableEq ι] [Fintype ι] (b : Basis ι R M)
/-- The natural left-handed pairing between a module and its dual. -/
def contractLeft : Module.Dual R M ⊗[R] M →ₗ[R] R :=
(uncurry _ _ _ _).toFun LinearMap.id
/-- The natural right-handed pairing between a module and its dual. -/
def contractRight : M ⊗[R] Module.Dual R M →ₗ[R] R :=
(uncurry _ _ _ _).toFun (LinearMap.flip LinearMap.id)
/-- The natural map associating a linear map to the tensor product of two modules. -/
def dualTensorHom : Module.Dual R M ⊗[R] N →ₗ[R] M →ₗ[R] N :=
let M' := Module.Dual R M
(uncurry R M' N (M →ₗ[R] N) : _ → M' ⊗ N →ₗ[R] M →ₗ[R] N) LinearMap.smulRightₗ
variable {R M N P Q}
@[simp]
theorem contractLeft_apply (f : Module.Dual R M) (m : M) : contractLeft R M (f ⊗ₜ m) = f m :=
rfl
@[simp]
theorem contractRight_apply (f : Module.Dual R M) (m : M) : contractRight R M (m ⊗ₜ f) = f m :=
rfl
@[simp]
theorem dualTensorHom_apply (f : Module.Dual R M) (m : M) (n : N) :
dualTensorHom R M N (f ⊗ₜ n) m = f m • n :=
rfl
@[simp]
theorem transpose_dualTensorHom (f : Module.Dual R M) (m : M) :
Dual.transpose (R := R) (dualTensorHom R M M (f ⊗ₜ m)) =
dualTensorHom R _ _ (Dual.eval R M m ⊗ₜ f) := by
ext f' m'
simp only [Dual.transpose_apply, coe_comp, Function.comp_apply, dualTensorHom_apply,
LinearMap.map_smulₛₗ, RingHom.id_apply, Algebra.id.smul_eq_mul, Dual.eval_apply,
LinearMap.smul_apply]
exact mul_comm _ _
@[simp]
theorem dualTensorHom_prodMap_zero (f : Module.Dual R M) (p : P) :
((dualTensorHom R M P) (f ⊗ₜ[R] p)).prodMap (0 : N →ₗ[R] Q) =
dualTensorHom R (M × N) (P × Q) ((f ∘ₗ fst R M N) ⊗ₜ inl R P Q p) := by
ext <;>
simp only [coe_comp, coe_inl, Function.comp_apply, prodMap_apply, dualTensorHom_apply,
fst_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero]
@[simp]
theorem zero_prodMap_dualTensorHom (g : Module.Dual R N) (q : Q) :
(0 : M →ₗ[R] P).prodMap ((dualTensorHom R N Q) (g ⊗ₜ[R] q)) =
dualTensorHom R (M × N) (P × Q) ((g ∘ₗ snd R M N) ⊗ₜ inr R P Q q) := by
ext <;>
simp only [coe_comp, coe_inr, Function.comp_apply, prodMap_apply, dualTensorHom_apply,
snd_apply, Prod.smul_mk, LinearMap.zero_apply, smul_zero]
theorem map_dualTensorHom (f : Module.Dual R M) (p : P) (g : Module.Dual R N) (q : Q) :
TensorProduct.map (dualTensorHom R M P (f ⊗ₜ[R] p)) (dualTensorHom R N Q (g ⊗ₜ[R] q)) =
dualTensorHom R (M ⊗[R] N) (P ⊗[R] Q) (dualDistrib R M N (f ⊗ₜ g) ⊗ₜ[R] (p ⊗ₜ[R] q)) := by
ext m n
simp only [compr₂_apply, mk_apply, map_tmul, dualTensorHom_apply, dualDistrib_apply, ←
smul_tmul_smul]
@[simp]
theorem comp_dualTensorHom (f : Module.Dual R M) (n : N) (g : Module.Dual R N) (p : P) :
dualTensorHom R N P (g ⊗ₜ[R] p) ∘ₗ dualTensorHom R M N (f ⊗ₜ[R] n) =
g n • dualTensorHom R M P (f ⊗ₜ p) := by
ext m
simp only [coe_comp, Function.comp_apply, dualTensorHom_apply, LinearMap.map_smul,
LinearMap.smul_apply]
rw [smul_comm]
/-- As a matrix, `dualTensorHom` evaluated on a basis element of `M* ⊗ N` is a matrix with a
single one and zeros elsewhere -/
theorem toMatrix_dualTensorHom {m : Type*} {n : Type*} [Fintype m] [Finite n] [DecidableEq m]
[DecidableEq n] (bM : Basis m R M) (bN : Basis n R N) (j : m) (i : n) :
toMatrix bM bN (dualTensorHom R M N (bM.coord j ⊗ₜ bN i)) = single i j 1 := by
ext i' j'
by_cases hij : i = i' ∧ j = j' <;>
simp [LinearMap.toMatrix_apply, Finsupp.single_eq_pi_single, hij]
rw [and_iff_not_or_not, Classical.not_not] at hij
rcases hij with hij | hij <;> simp [hij]
/-- If `M` is free, the natural linear map $M^* ⊗ N → Hom(M, N)$ is an equivalence. This function
provides this equivalence in return for a basis of `M`. -/
-- We manually create simp-lemmas because `@[simps]` generates a malformed lemma
noncomputable def dualTensorHomEquivOfBasis : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N :=
LinearEquiv.ofLinear (dualTensorHom R M N)
(∑ i, TensorProduct.mk R _ N (b.dualBasis i) ∘ₗ (LinearMap.applyₗ (R := R) (b i)))
(by
ext f m
simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id,
Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, Basis.coord_apply, ←
f.map_smul, _root_.map_sum (dualTensorHom R M N), ← _root_.map_sum f, b.sum_repr])
(by
ext f m
simp only [applyₗ_apply_apply, coeFn_sum, dualTensorHom_apply, mk_apply, id_coe, _root_.id,
Fintype.sum_apply, Function.comp_apply, Basis.coe_dualBasis, coe_comp, compr₂_apply,
tmul_smul, smul_tmul', ← sum_tmul, Basis.sum_dual_apply_smul_coord])
@[simp]
theorem dualTensorHomEquivOfBasis_apply (x : Module.Dual R M ⊗[R] N) :
dualTensorHomEquivOfBasis b x = dualTensorHom R M N x := by
ext; rfl
@[simp]
theorem dualTensorHomEquivOfBasis_toLinearMap :
(dualTensorHomEquivOfBasis b).toLinearMap = dualTensorHom R M N :=
rfl
@[simp]
theorem dualTensorHomEquivOfBasis_symm_cancel_left (x : Module.Dual R M ⊗[R] N) :
(dualTensorHomEquivOfBasis b).symm (dualTensorHom R M N x) = x := by
rw [← dualTensorHomEquivOfBasis_apply b,
LinearEquiv.symm_apply_apply <| dualTensorHomEquivOfBasis (N := N) b]
@[simp]
theorem dualTensorHomEquivOfBasis_symm_cancel_right (x : M →ₗ[R] N) :
dualTensorHom R M N ((dualTensorHomEquivOfBasis b).symm x) = x := by
rw [← dualTensorHomEquivOfBasis_apply b, LinearEquiv.apply_symm_apply]
variable (R M N P Q)
variable [Module.Free R M] [Module.Finite R M]
/-- If `M` is finite free, the natural map $M^* ⊗ N → Hom(M, N)$ is an
equivalence. -/
@[simp]
noncomputable def dualTensorHomEquiv : Module.Dual R M ⊗[R] N ≃ₗ[R] M →ₗ[R] N :=
dualTensorHomEquivOfBasis (Module.Free.chooseBasis R M)
end CommSemiring
end Contraction
section HomTensorHom
open TensorProduct
open Module TensorProduct LinearMap
section CommSemiring
variable [CommSemiring R]
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q]
variable [Module R M] [Module R N] [Module R P] [Module R Q]
variable [Free R M] [Module.Finite R M] [Free R N] [Module.Finite R N]
/-- When `M` is a finite free module, the map `lTensorHomToHomLTensor` is an equivalence. Note
that `lTensorHomEquivHomLTensor` is not defined directly in terms of
`lTensorHomToHomLTensor`, but the equivalence between the two is given by
`lTensorHomEquivHomLTensor_toLinearMap` and `lTensorHomEquivHomLTensor_apply`. -/
noncomputable def lTensorHomEquivHomLTensor : P ⊗[R] (M →ₗ[R] Q) ≃ₗ[R] M →ₗ[R] P ⊗[R] Q :=
congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q).symm ≪≫ₗ
TensorProduct.leftComm R P _ Q ≪≫ₗ
dualTensorHomEquiv R M _
/-- When `M` is a finite free module, the map `rTensorHomToHomRTensor` is an equivalence. Note
that `rTensorHomEquivHomRTensor` is not defined directly in terms of
`rTensorHomToHomRTensor`, but the equivalence between the two is given by
`rTensorHomEquivHomRTensor_toLinearMap` and `rTensorHomEquivHomRTensor_apply`. -/
noncomputable def rTensorHomEquivHomRTensor : (M →ₗ[R] P) ⊗[R] Q ≃ₗ[R] M →ₗ[R] P ⊗[R] Q :=
congr (dualTensorHomEquiv R M P).symm (LinearEquiv.refl R Q) ≪≫ₗ TensorProduct.assoc R _ P Q ≪≫ₗ
dualTensorHomEquiv R M _
@[simp]
theorem lTensorHomEquivHomLTensor_toLinearMap :
(lTensorHomEquivHomLTensor R M P Q).toLinearMap = lTensorHomToHomLTensor R M P Q := by
let e := congr (LinearEquiv.refl R P) (dualTensorHomEquiv R M Q)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f q m
simp only [e, lTensorHomEquivHomLTensor, dualTensorHomEquiv, LinearEquiv.comp_coe, compr₂_apply,
mk_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply, congr_tmul, LinearEquiv.refl_apply,
dualTensorHomEquivOfBasis_apply, dualTensorHomEquivOfBasis_symm_cancel_left, leftComm_tmul,
dualTensorHom_apply, coe_comp, Function.comp_apply, lTensorHomToHomLTensor_apply, tmul_smul]
@[simp]
theorem rTensorHomEquivHomRTensor_toLinearMap :
(rTensorHomEquivHomRTensor R M P Q).toLinearMap = rTensorHomToHomRTensor R M P Q := by
let e := congr (dualTensorHomEquiv R M P) (LinearEquiv.refl R Q)
have h : Function.Surjective e.toLinearMap := e.surjective
refine (cancel_right h).1 ?_
ext f p q m
simp only [e, rTensorHomEquivHomRTensor, dualTensorHomEquiv, compr₂_apply, mk_apply, coe_comp,
LinearEquiv.coe_toLinearMap, Function.comp_apply,
dualTensorHomEquivOfBasis_apply, LinearEquiv.trans_apply, congr_tmul,
dualTensorHomEquivOfBasis_symm_cancel_left, LinearEquiv.refl_apply, assoc_tmul,
dualTensorHom_apply, rTensorHomToHomRTensor_apply, smul_tmul']
variable {R M N P Q}
@[simp]
theorem lTensorHomEquivHomLTensor_apply (x : P ⊗[R] (M →ₗ[R] Q)) :
lTensorHomEquivHomLTensor R M P Q x = lTensorHomToHomLTensor R M P Q x := by
rw [← LinearEquiv.coe_toLinearMap, lTensorHomEquivHomLTensor_toLinearMap]
@[simp]
theorem rTensorHomEquivHomRTensor_apply (x : (M →ₗ[R] P) ⊗[R] Q) :
rTensorHomEquivHomRTensor R M P Q x = rTensorHomToHomRTensor R M P Q x := by
rw [← LinearEquiv.coe_toLinearMap, rTensorHomEquivHomRTensor_toLinearMap]
variable (R M N P Q)
/-- When `M` and `N` are free `R` modules, the map `homTensorHomMap` is an equivalence. Note that
`homTensorHomEquiv` is not defined directly in terms of `homTensorHomMap`, but the equivalence
between the two is given by `homTensorHomEquiv_toLinearMap` and `homTensorHomEquiv_apply`.
-/
noncomputable def homTensorHomEquiv : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q) ≃ₗ[R] M ⊗[R] N →ₗ[R] P ⊗[R] Q :=
rTensorHomEquivHomRTensor R M P _ ≪≫ₗ
(LinearEquiv.refl R M).arrowCongr (lTensorHomEquivHomLTensor R N _ Q) ≪≫ₗ
lift.equiv R M N _
@[simp]
theorem homTensorHomEquiv_toLinearMap :
(homTensorHomEquiv R M N P Q).toLinearMap = homTensorHomMap R M N P Q := by
ext m n
simp only [homTensorHomEquiv, compr₂_apply, mk_apply, LinearEquiv.coe_toLinearMap,
LinearEquiv.trans_apply, lift.equiv_apply, LinearEquiv.arrowCongr_apply, LinearEquiv.refl_symm,
LinearEquiv.refl_apply, rTensorHomEquivHomRTensor_apply, lTensorHomEquivHomLTensor_apply,
lTensorHomToHomLTensor_apply, rTensorHomToHomRTensor_apply, homTensorHomMap_apply,
map_tmul]
variable {R M N P Q}
@[simp]
theorem homTensorHomEquiv_apply (x : (M →ₗ[R] P) ⊗[R] (N →ₗ[R] Q)) :
homTensorHomEquiv R M N P Q x = homTensorHomMap R M N P Q x := by
rw [← LinearEquiv.coe_toLinearMap, homTensorHomEquiv_toLinearMap]
end CommSemiring
end HomTensorHom
|
Real.lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Patrick Massot, Eric Wieser, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Module.Basic
import Mathlib.LinearAlgebra.Basis.VectorSpace
/-!
# Basic facts about real (semi)normed spaces
In this file we prove some theorems about (semi)normed spaces over real numberes.
## Main results
- `closure_ball`, `frontier_ball`, `interior_closedBall`, `frontier_closedBall`, `interior_sphere`,
`frontier_sphere`: formulas for the closure/interior/frontier
of nontrivial balls and spheres in a real seminormed space;
- `interior_closedBall'`, `frontier_closedBall'`, `interior_sphere'`, `frontier_sphere'`:
similar lemmas assuming that the ambient space is separated and nontrivial instead of `r ≠ 0`.
-/
open Metric Set Function Filter
open scoped NNReal Topology
/-- If `E` is a nontrivial topological module over `ℝ`, then `E` has no isolated points.
This is a particular case of `Module.punctured_nhds_neBot`. -/
instance Real.punctured_nhds_module_neBot {E : Type*} [AddCommGroup E] [TopologicalSpace E]
[ContinuousAdd E] [Nontrivial E] [Module ℝ E] [ContinuousSMul ℝ E] (x : E) : NeBot (𝓝[≠] x) :=
Module.punctured_nhds_neBot ℝ E x
section Seminormed
variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E]
theorem inv_norm_smul_mem_unitClosedBall (x : E) :
‖x‖⁻¹ • x ∈ closedBall (0 : E) 1 := by
simp only [mem_closedBall_zero_iff, norm_smul, norm_inv, norm_norm, ← div_eq_inv_mul,
div_self_le_one]
theorem norm_smul_of_nonneg {t : ℝ} (ht : 0 ≤ t) (x : E) : ‖t • x‖ = t * ‖x‖ := by
rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht]
theorem dist_smul_add_one_sub_smul_le {r : ℝ} {x y : E} (h : r ∈ Icc 0 1) :
dist (r • x + (1 - r) • y) x ≤ dist y x :=
calc
dist (r • x + (1 - r) • y) x = ‖1 - r‖ * ‖x - y‖ := by
simp_rw [dist_eq_norm', ← norm_smul, sub_smul, one_smul, smul_sub, ← sub_sub, ← sub_add,
sub_right_comm]
_ = (1 - r) * dist y x := by
rw [Real.norm_eq_abs, abs_eq_self.mpr (sub_nonneg.mpr h.2), dist_eq_norm']
_ ≤ (1 - 0) * dist y x := by gcongr; exact h.1
_ = dist y x := by rw [sub_zero, one_mul]
theorem closure_ball (x : E) {r : ℝ} (hr : r ≠ 0) : closure (ball x r) = closedBall x r := by
refine Subset.antisymm closure_ball_subset_closedBall fun y hy => ?_
have : ContinuousWithinAt (fun c : ℝ => c • (y - x) + x) (Ico 0 1) 1 :=
((continuous_id.smul continuous_const).add continuous_const).continuousWithinAt
convert this.mem_closure _ _
· rw [one_smul, sub_add_cancel]
· simp [closure_Ico zero_ne_one, zero_le_one]
· rintro c ⟨hc0, hc1⟩
rw [mem_ball, dist_eq_norm, add_sub_cancel_right, norm_smul, Real.norm_eq_abs,
abs_of_nonneg hc0, mul_comm, ← mul_one r]
rw [mem_closedBall, dist_eq_norm] at hy
replace hr : 0 < r := ((norm_nonneg _).trans hy).lt_of_ne hr.symm
apply mul_lt_mul' <;> assumption
theorem frontier_ball (x : E) {r : ℝ} (hr : r ≠ 0) :
frontier (ball x r) = sphere x r := by
rw [frontier, closure_ball x hr, isOpen_ball.interior_eq, closedBall_diff_ball]
theorem interior_closedBall (x : E) {r : ℝ} (hr : r ≠ 0) :
interior (closedBall x r) = ball x r := by
rcases hr.lt_or_gt with hr | hr
· rw [closedBall_eq_empty.2 hr, ball_eq_empty.2 hr.le, interior_empty]
refine Subset.antisymm ?_ ball_subset_interior_closedBall
intro y hy
rcases (mem_closedBall.1 <| interior_subset hy).lt_or_eq with (hr | rfl)
· exact hr
set f : ℝ → E := fun c : ℝ => c • (y - x) + x
suffices f ⁻¹' closedBall x (dist y x) ⊆ Icc (-1) 1 by
have hfc : Continuous f := (continuous_id.smul continuous_const).add continuous_const
have hf1 : (1 : ℝ) ∈ f ⁻¹' interior (closedBall x <| dist y x) := by simpa [f]
have h1 : (1 : ℝ) ∈ interior (Icc (-1 : ℝ) 1) :=
interior_mono this (preimage_interior_subset_interior_preimage hfc hf1)
simp at h1
intro c hc
rw [mem_Icc, ← abs_le, ← Real.norm_eq_abs, ← mul_le_mul_right hr]
simpa [f, dist_eq_norm, norm_smul] using hc
theorem frontier_closedBall (x : E) {r : ℝ} (hr : r ≠ 0) :
frontier (closedBall x r) = sphere x r := by
rw [frontier, closure_closedBall, interior_closedBall x hr, closedBall_diff_ball]
theorem interior_sphere (x : E) {r : ℝ} (hr : r ≠ 0) : interior (sphere x r) = ∅ := by
rw [← frontier_closedBall x hr, interior_frontier isClosed_closedBall]
theorem frontier_sphere (x : E) {r : ℝ} (hr : r ≠ 0) : frontier (sphere x r) = sphere x r := by
rw [isClosed_sphere.frontier_eq, interior_sphere x hr, diff_empty]
end Seminormed
section Normed
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [Nontrivial E]
section Surj
variable (E)
theorem exists_norm_eq {c : ℝ} (hc : 0 ≤ c) : ∃ x : E, ‖x‖ = c := by
rcases exists_ne (0 : E) with ⟨x, hx⟩
rw [← norm_ne_zero_iff] at hx
use c • ‖x‖⁻¹ • x
simp [norm_smul, Real.norm_of_nonneg hc, inv_mul_cancel₀ hx]
@[simp]
theorem range_norm : range (norm : E → ℝ) = Ici 0 :=
Subset.antisymm (range_subset_iff.2 norm_nonneg) fun _ => exists_norm_eq E
theorem nnnorm_surjective : Surjective (nnnorm : E → ℝ≥0) := fun c =>
(exists_norm_eq E c.coe_nonneg).imp fun _ h => NNReal.eq h
@[simp]
theorem range_nnnorm : range (nnnorm : E → ℝ≥0) = univ :=
(nnnorm_surjective E).range_eq
variable {E} in
/-- In a nontrivial real normed space, a sphere is nonempty if and only if its radius is
nonnegative. -/
@[simp]
theorem NormedSpace.sphere_nonempty {x : E} {r : ℝ} : (sphere x r).Nonempty ↔ 0 ≤ r := by
refine ⟨fun h => nonempty_closedBall.1 (h.mono sphere_subset_closedBall), fun hr => ?_⟩
obtain ⟨y, hy⟩ := exists_norm_eq E hr
exact ⟨x + y, by simpa using hy⟩
end Surj
theorem interior_closedBall' (x : E) (r : ℝ) : interior (closedBall x r) = ball x r := by
rcases eq_or_ne r 0 with (rfl | hr)
· rw [closedBall_zero, ball_zero, interior_singleton]
· exact interior_closedBall x hr
theorem frontier_closedBall' (x : E) (r : ℝ) : frontier (closedBall x r) = sphere x r := by
rw [frontier, closure_closedBall, interior_closedBall' x r, closedBall_diff_ball]
@[simp]
theorem interior_sphere' (x : E) (r : ℝ) : interior (sphere x r) = ∅ := by
rw [← frontier_closedBall' x, interior_frontier isClosed_closedBall]
@[simp]
theorem frontier_sphere' (x : E) (r : ℝ) : frontier (sphere x r) = sphere x r := by
rw [isClosed_sphere.frontier_eq, interior_sphere' x, diff_empty]
end Normed
|
integral_char.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient action countalg finalg zmodp.
From mathcomp Require Import commutator cyclic center pgroup sylow gseries.
From mathcomp Require Import nilpotent abelian ssrnum ssrint archimedean.
From mathcomp Require Import polydiv rat matrix mxalgebra intdiv mxpoly vector.
From mathcomp Require Import falgebra fieldext separable galois algC cyclotomic.
From mathcomp Require Import algnum mxrepresentation classfun character.
(******************************************************************************)
(* This file provides some standard results based on integrality properties *)
(* of characters, such as theorem asserting that the degree of an irreducible *)
(* character of G divides the order of G (Isaacs 3.11), or the famous p^a.q^b *)
(* solvability theorem of Burnside. *)
(* Defined here: *)
(* 'K_k == the kth class sum in gring F G, where k : 'I_#|classes G|, and *)
(* F is inferred from the context. *)
(* := gset_mx F G (enum_val k) (see mxrepresentation.v). *)
(* --> The 'K_k form a basis of 'Z(group_ring F G)%MS. *)
(* gring_classM_coef i j k == the coordinate of 'K_i *m 'K_j on 'K_k; this *)
(* is usually abbreviated as a i j k. *)
(* gring_classM_coef_set A B z == the set of all (x, y) in setX A B such *)
(* that x * y = z; if A and B are respectively the ith and jth *)
(* conjugacy class of G, and z is in the kth conjugacy class, then *)
(* gring_classM_coef i j k is exactly the cardinal of this set. *)
(* 'omega_i[A] == the mode of 'chi[G]_i on (A \in 'Z(group_ring algC G))%MS, *)
(* i.e., the z such that gring_op 'Chi_i A = z%:M. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Lemma group_num_field_exists (gT : finGroupType) (G : {group gT}) :
{Qn : splittingFieldType rat & galois 1 {:Qn} &
{QnC : {rmorphism Qn -> algC}
& forall nuQn : argumentType [in 'Gal({:Qn} / 1)],
{nu : {rmorphism algC -> algC} |
{morph QnC: a / nuQn a >-> nu a}}
& {w : Qn & #|G|.-primitive_root w /\ <<1; w>>%VS = fullv
& forall (hT : finGroupType) (H : {group hT}) (phi : 'CF(H)),
phi \is a character ->
forall x, (#[x] %| #|G|)%N -> {a | QnC a = phi x}}}}.
Proof.
have [z prim_z] := C_prim_root_exists (cardG_gt0 G); set n := #|G| in prim_z *.
have [Qn [QnC [[|w []] // [Dz] genQn]]] := num_field_exists [:: z].
have prim_w: n.-primitive_root w by rewrite -Dz fmorph_primitive_root in prim_z.
have Q_Xn1: ('X^n - 1 : {poly Qn}) \is a polyOver 1%AS.
by rewrite rpredB ?rpred1 ?rpredX //= polyOverX.
have splitXn1: splittingFieldFor 1 ('X^n - 1) {:Qn}.
pose r := codom (fun i : 'I_n => w ^+ i).
have Dr: 'X^n - 1 = \prod_(y <- r) ('X - y%:P).
by rewrite -(factor_Xn_sub_1 prim_w) big_mkord big_image.
exists r; first by rewrite -Dr eqpxx.
apply/eqP; rewrite eqEsubv subvf -genQn adjoin_seqSr //; apply/allP=> /=.
by rewrite andbT -root_prod_XsubC -Dr; apply/unity_rootP/prim_expr_order.
have Qn_ax : FieldExt_isSplittingField _ Qn by constructor; exists ('X^n - 1).
exists (HB.pack_for (splittingFieldType rat) Qn Qn_ax).
apply/splitting_galoisField.
exists ('X^n - 1); split => //.
apply: separable_Xn_sub_1; rewrite -(fmorph_eq0 QnC) rmorph_nat.
by rewrite pnatr_eq0 -lt0n cardG_gt0.
exists QnC => [// nuQn|]; first exact: (extend_algC_subfield_aut QnC nuQn).
rewrite span_seq1 in genQn.
exists w => // hT H phi Nphi x x_dv_n.
apply: sig_eqW; have [rH ->] := char_reprP Nphi.
have [Hx | /cfun0->] := boolP (x \in H); last by exists 0; rewrite rmorph0.
have [e [_ [enx1 _] [-> _] _]] := repr_rsim_diag rH Hx.
have /fin_all_exists[k Dk] i: exists k, e 0 i = z ^+ k.
have [|k ->] := (prim_rootP prim_z) (e 0 i); last by exists k.
by have /dvdnP[q ->] := x_dv_n; rewrite mulnC exprM enx1 expr1n.
exists (\sum_i w ^+ k i); rewrite rmorph_sum; apply/eq_bigr => i _.
by rewrite rmorphXn /= Dz Dk.
Qed.
Section GenericClassSums.
(* This is Isaacs, Theorem (2.4), generalized to an arbitrary field, and with *)
(* the combinatorial definition of the coefficients exposed. *)
(* This part could move to mxrepresentation.*)
Variable (gT : finGroupType) (G : {group gT}) (F : fieldType).
Definition gring_classM_coef_set (Ki Kj : {set gT}) g :=
[set xy in [predX Ki & Kj] | let: (x, y) := xy in x * y == g]%g.
Definition gring_classM_coef (i j k : 'I_#|classes G|) :=
#|gring_classM_coef_set (enum_val i) (enum_val j) (repr (enum_val k))|.
Definition gring_class_sum (i : 'I_#|classes G|) := gset_mx F G (enum_val i).
Local Notation "''K_' i" := (gring_class_sum i)
(at level 8, i at level 2, format "''K_' i") : ring_scope.
Local Notation a := gring_classM_coef.
Lemma gring_class_sum_central i : ('K_i \in 'Z(group_ring F G))%MS.
Proof. by rewrite -classg_base_center (eq_row_sub i) // rowK. Qed.
Lemma set_gring_classM_coef (i j k : 'I_#|classes G|) g :
g \in enum_val k ->
a i j k = #|gring_classM_coef_set (enum_val i) (enum_val j) g|.
Proof.
rewrite /a; have /repr_classesP[] := enum_valP k; move: (repr _) => g1 Gg1 ->.
have [/imsetP[zi Gzi ->] /imsetP[zj Gzj ->]] := (enum_valP i, enum_valP j).
move=> g1Gg; have Gg := subsetP (class_subG Gg1 (subxx _)) _ g1Gg.
set Aij := gring_classM_coef_set _ _.
without loss suffices IH: g g1 Gg Gg1 g1Gg / (#|Aij g1| <= #|Aij g|)%N.
by apply/eqP; rewrite eqn_leq !IH // class_sym.
have [w Gw Dg] := imsetP g1Gg; pose J2 (v : gT) xy := (xy.1 ^ v, xy.2 ^ v)%g.
have J2inj: injective (J2 w).
by apply: can_inj (J2 w^-1)%g _ => [[x y]]; rewrite /J2 /= !conjgK.
rewrite -(card_imset _ J2inj) subset_leq_card //; apply/subsetP.
move=> _ /imsetP[[x y] /setIdP[/andP[/= x1Gx y1Gy] Dxy1] ->] /[!inE]/=.
rewrite !(class_sym _ (_ ^ _)) !classGidl // class_sym x1Gx class_sym y1Gy.
by rewrite -conjMg (eqP Dxy1) /= -Dg.
Qed.
Theorem gring_classM_expansion i j : 'K_i *m 'K_j = \sum_k (a i j k)%:R *: 'K_k.
Proof.
have [/imsetP[zi Gzi dKi] /imsetP[zj Gzj dKj]] := (enum_valP i, enum_valP j).
pose aG := regular_repr F G; have sKG := subsetP (class_subG _ (subxx G)).
transitivity (\sum_(x in zi ^: G) \sum_(y in zj ^: G) aG (x * y)%g).
rewrite mulmx_suml -/aG dKi; apply: eq_bigr => x /sKG Gx.
rewrite mulmx_sumr -/aG dKj; apply: eq_bigr => y /sKG Gy.
by rewrite repr_mxM ?Gx ?Gy.
pose h2 xy : gT := (xy.1 * xy.2)%g.
pose h1 xy := enum_rank_in (classes1 G) (h2 xy ^: G).
rewrite pair_big (partition_big h1 xpredT) //=; apply: eq_bigr => k _.
rewrite (partition_big h2 [in enum_val k]) /= => [|[x y]]; last first.
case/andP=> /andP[/= /sKG Gx /sKG Gy] /eqP <-.
by rewrite enum_rankK_in ?class_refl ?mem_classes ?groupM ?Gx ?Gy.
rewrite scaler_sumr; apply: eq_bigr => g Kk_g; rewrite scaler_nat.
rewrite (set_gring_classM_coef _ _ Kk_g) -sumr_const; apply: eq_big => [] [x y].
rewrite !inE /= dKi dKj /h1 /h2 /=; apply: andb_id2r => /eqP ->.
have /imsetP[zk Gzk dKk] := enum_valP k; rewrite dKk in Kk_g.
by rewrite (class_eqP Kk_g) -dKk enum_valK_in eqxx andbT.
by rewrite /h2 /= => /andP[_ /eqP->].
Qed.
End GenericClassSums.
HB.lock Definition gring_irr_mode (gT : finGroupType) (G : {group gT})
(i : Iirr G) := ('chi_i 1%g)^-1 *: 'chi_i.
Canonical gring_irr_mode_unlockable := Unlockable gring_irr_mode.unlock.
Arguments gring_irr_mode {gT G%_G} i%_R _%_g : extra scopes.
Notation "''K_' i" := (gring_class_sum _ i)
(at level 8, i at level 2, format "''K_' i") : ring_scope.
Notation "''omega_' i [ A ]" := (xcfun (gring_irr_mode i) A)
(i at level 2, format "''omega_' i [ A ]") : ring_scope.
Section IntegralChar.
Variables (gT : finGroupType) (G : {group gT}).
(* This is Isaacs, Corollary (3.6). *)
Lemma Aint_char (chi : 'CF(G)) x : chi \is a character -> chi x \in Aint.
Proof.
have [Gx /char_reprP[rG ->] {chi} | /cfun0->//] := boolP (x \in G).
have [e [_ [unit_e _] [-> _] _]] := repr_rsim_diag rG Gx.
rewrite rpred_sum // => i _; apply: (@Aint_unity_root #[x]) => //.
exact/unity_rootP.
Qed.
Lemma Aint_irr i x : 'chi[G]_i x \in Aint.
Proof. exact/Aint_char/irr_char. Qed.
Local Notation R_G := (group_ring algCfield G).
Local Notation a := gring_classM_coef.
(* This is Isaacs (2.25). *)
Lemma mx_irr_gring_op_center_scalar n (rG : mx_representation algCfield G n) A :
mx_irreducible rG -> (A \in 'Z(R_G))%MS -> is_scalar_mx (gring_op rG A).
Proof.
move/groupC=> irrG /center_mxP[R_A cGA].
apply: mx_abs_irr_cent_scalar irrG _ _; apply/centgmxP => x Gx.
by rewrite -(gring_opG rG Gx) -!gring_opM ?cGA // envelop_mx_id.
Qed.
Section GringIrrMode.
Variable i : Iirr G.
Let n := irr_degree (socle_of_Iirr i).
Let mxZn_inj: injective (@scalar_mx algCfield n).
Proof. by rewrite -[n]prednK ?irr_degree_gt0 //; apply: fmorph_inj. Qed.
Lemma cfRepr_gring_center n1 (rG : mx_representation algCfield G n1) A :
cfRepr rG = 'chi_i -> (A \in 'Z(R_G))%MS -> gring_op rG A = 'omega_i[A]%:M.
Proof.
move=> def_rG Z_A; rewrite unlock xcfunZl -{2}def_rG xcfun_repr.
have irr_rG: mx_irreducible rG.
have sim_rG: mx_rsim 'Chi_i rG by apply: cfRepr_inj; rewrite irrRepr.
exact: mx_rsim_irr sim_rG (socle_irr _).
have /is_scalar_mxP[e ->] := mx_irr_gring_op_center_scalar irr_rG Z_A.
congr _%:M; apply: (canRL (mulKf (irr1_neq0 i))).
by rewrite mulrC -def_rG cfunE repr_mx1 group1 -mxtraceZ scalemx1.
Qed.
Lemma irr_gring_center A :
(A \in 'Z(R_G))%MS -> gring_op 'Chi_i A = 'omega_i[A]%:M.
Proof. exact: cfRepr_gring_center (irrRepr i). Qed.
Lemma gring_irr_modeM A B :
(A \in 'Z(R_G))%MS -> (B \in 'Z(R_G))%MS ->
'omega_i[A *m B] = 'omega_i[A] * 'omega_i[B].
Proof.
move=> Z_A Z_B; have [[R_A cRA] [R_B cRB]] := (center_mxP Z_A, center_mxP Z_B).
apply: mxZn_inj; rewrite scalar_mxM -!irr_gring_center ?gring_opM //.
apply/center_mxP; split=> [|C R_C]; first exact: envelop_mxM.
by rewrite mulmxA cRA // -!mulmxA cRB.
Qed.
Lemma gring_mode_class_sum_eq (k : 'I_#|classes G|) g :
g \in enum_val k -> 'omega_i['K_k] = #|g ^: G|%:R * 'chi_i g / 'chi_i 1%g.
Proof.
have /imsetP[x Gx DxG] := enum_valP k; rewrite DxG => /imsetP[u Gu ->{g}].
rewrite unlock classGidl ?cfunJ {u Gu}// mulrC mulr_natl.
rewrite xcfunZl raddf_sum DxG -sumr_const /=; congr (_ * _).
by apply: eq_bigr => _ /imsetP[u Gu ->]; rewrite xcfunG ?groupJ ?cfunJ.
Qed.
(* This is Isaacs, Theorem (3.7). *)
Lemma Aint_gring_mode_class_sum k : 'omega_i['K_k] \in Aint.
Proof.
move: k; pose X := [tuple 'omega_i['K_k] | k < #|classes G| ].
have memX k: 'omega_i['K_k] \in X by apply: image_f.
have S_P := Cint_spanP X; set S := Cint_span X in S_P.
have S_X: {subset X <= S} by apply: mem_Cint_span.
have S_1: 1 \in S.
apply: S_X; apply/codomP; exists (enum_rank_in (classes1 G) 1%g).
rewrite (@gring_mode_class_sum_eq _ 1%g) ?enum_rankK_in ?classes1 //.
by rewrite mulfK ?irr1_neq0 // class1G cards1.
suffices Smul: mulr_closed S.
by move=> k; apply: fin_Csubring_Aint S_P _ _; rewrite ?S_X.
split=> // _ _ /S_P[x ->] /S_P[y ->].
rewrite mulr_sumr rpred_sum // => j _.
rewrite mulrzAr mulr_suml rpredMz ?rpred_sum // => k _.
rewrite mulrzAl rpredMz {x y}// !nth_mktuple.
rewrite -gring_irr_modeM ?gring_class_sum_central //.
rewrite gring_classM_expansion raddf_sum rpred_sum // => jk _.
by rewrite scaler_nat raddfMn rpredMn ?S_X ?memX.
Qed.
(* A more usable reformulation that does not involve the class sums. *)
Corollary Aint_class_div_irr1 x :
x \in G -> #|x ^: G|%:R * 'chi_i x / 'chi_i 1%g \in Aint.
Proof.
move=> Gx; have clGxG := mem_classes Gx; pose k := enum_rank_in clGxG (x ^: G).
have k_x: x \in enum_val k by rewrite enum_rankK_in // class_refl.
by rewrite -(gring_mode_class_sum_eq k_x) Aint_gring_mode_class_sum.
Qed.
(* This is Isaacs, Theorem (3.8). *)
Theorem coprime_degree_support_cfcenter g :
coprime (Num.truncn ('chi_i 1%g)) #|g ^: G| -> g \notin ('Z('chi_i))%CF ->
'chi_i g = 0.
Proof.
set m := Num.truncn _ => co_m_gG notZg.
have [Gg | /cfun0-> //] := boolP (g \in G).
have Dm: 'chi_i 1%g = m%:R by rewrite truncnK ?Cnat_irr1.
have m_gt0: (0 < m)%N by rewrite -ltC_nat -Dm irr1_gt0.
have nz_m: m%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n.
pose alpha := 'chi_i g / m%:R.
have a_lt1: `|alpha| < 1.
rewrite normrM normfV normr_nat -{2}(divff nz_m).
rewrite lt_def (can_eq (mulfVK nz_m)) eq_sym -{1}Dm -irr_cfcenterE // notZg.
by rewrite ler_pM2r ?invr_gt0 ?ltr0n // -Dm char1_ge_norm ?irr_char.
have Za: alpha \in Aint.
have [u _ /dvdnP[v eq_uv]] := Bezoutl #|g ^: G| m_gt0.
suffices ->: alpha = v%:R * 'chi_i g - u%:R * (alpha * #|g ^: G|%:R).
rewrite rpredB // rpredM ?rpred_nat ?Aint_irr //.
by rewrite mulrC mulrA -Dm Aint_class_div_irr1.
rewrite -mulrCA -[v%:R](mulfK nz_m) -!natrM -eq_uv (eqnP co_m_gG).
by rewrite mulrAC -mulrA -/alpha mulr_natl mulr_natr mulrS addrK.
have [Qn galQn [QnC gQnC [_ _ Qn_g]]] := group_num_field_exists <[g]>.
have{Qn_g} [a Da]: exists a, QnC a = alpha.
rewrite /alpha; have [a <-] := Qn_g _ G _ (irr_char i) g (dvdnn _).
by exists (a / m%:R); rewrite fmorph_div rmorph_nat.
have Za_nu nu: sval (gQnC nu) alpha \in Aint by rewrite Aint_aut.
have norm_a_nu nu: `|sval (gQnC nu) alpha| <= 1.
move: {nu}(sval _) => nu; rewrite fmorph_div rmorph_nat normrM normfV.
rewrite normr_nat -Dm -(ler_pM2r (irr1_gt0 (aut_Iirr nu i))) mul1r.
congr (_ <= _): (char1_ge_norm g (irr_char (aut_Iirr nu i))).
by rewrite !aut_IirrE !cfunE Dm rmorph_nat divfK.
pose beta := QnC (galNorm 1 {:Qn} a).
have Dbeta: beta = \prod_(nu in 'Gal({:Qn} / 1)) sval (gQnC nu) alpha.
rewrite /beta rmorph_prod. apply: eq_bigr => nu _.
by case: (gQnC nu) => f /= ->; rewrite Da.
have Zbeta: beta \in Num.int.
apply: Cint_rat_Aint; last by rewrite Dbeta rpred_prod.
rewrite /beta; have /vlineP[/= c ->] := mem_galNorm galQn (memvf a).
by rewrite alg_num_field fmorph_rat rpred_rat.
have [|nz_a] := boolP (alpha == 0).
by rewrite (can2_eq (divfK _) (mulfK _)) // mul0r => /eqP.
have: beta != 0 by rewrite Dbeta; apply/prodf_neq0 => nu _; rewrite fmorph_eq0.
move/(norm_intr_ge1 Zbeta); rewrite lt_geF //; apply: le_lt_trans a_lt1.
rewrite -[`|alpha|]mulr1 Dbeta (bigD1 1%g) ?group1 //= -Da.
case: (gQnC _) => /= _ <-.
rewrite gal_id normrM -subr_ge0 -mulrBr mulr_ge0 // Da subr_ge0.
elim/big_rec: _ => [|nu c _]; first by rewrite normr1 lexx.
apply: le_trans; rewrite -subr_ge0 -{1}[`|c|]mul1r normrM -mulrBl.
by rewrite mulr_ge0 // subr_ge0 norm_a_nu.
Qed.
End GringIrrMode.
(* This is Isaacs, Theorem (3.9). *)
Theorem primes_class_simple_gt1 C :
simple G -> ~~ abelian G -> C \in (classes G)^# -> (size (primes #|C|) > 1)%N.
Proof.
move=> simpleG not_cGG /setD1P[ntC /imsetP[g Gg defC]].
have{ntC} nt_g: g != 1%g by rewrite defC classG_eq1 in ntC.
rewrite ltnNge {C}defC; set m := #|_|; apply/negP=> p_natC.
have{p_natC} [p p_pr [a Dm]]: {p : nat & prime p & {a | m = p ^ a}%N}.
have /prod_prime_decomp->: (0 < m)%N by rewrite /m -index_cent1.
rewrite prime_decompE; case Dpr: (primes _) p_natC => [|p []] // _.
by exists 2%N => //; rewrite big_nil; exists 0.
rewrite big_seq1; exists p; last by exists (logn p m).
by have:= mem_primes p m; rewrite Dpr mem_head => /esym/and3P[].
have{simpleG} [ntG minG] := simpleP _ simpleG.
pose p_dv1 i := (p %| 'chi[G]_i 1%g)%C.
have p_dvd_supp_g i: ~~ p_dv1 i && (i != 0) -> 'chi_i g = 0.
rewrite /p_dv1 irr1_degree dvdC_nat -prime_coprime // => /andP[co_p_i1 nz_i].
have fful_i: cfker 'chi_i = [1].
have /minG[//|/eqP] := cfker_normal 'chi_i.
by rewrite eqEsubset subGcfker (negPf nz_i) andbF.
have trivZ: 'Z(G) = [1] by have /minG[|/center_idP/idPn] := center_normal G.
have trivZi: ('Z('chi_i))%CF = [1].
apply/trivgP; rewrite -quotient_sub1 ?norms1 //= -fful_i cfcenter_eq_center.
rewrite fful_i subG1 -(isog_eq1 (isog_center (quotient1_isog G))) /=.
by rewrite trivZ.
rewrite coprime_degree_support_cfcenter ?trivZi ?inE //.
by rewrite -/m Dm irr1_degree natrK coprime_sym coprimeXl.
pose alpha := \sum_(i | p_dv1 i && (i != 0)) 'chi_i 1%g / p%:R * 'chi_i g.
have nz_p: p%:R != 0 :> algC by rewrite pnatr_eq0 -lt0n prime_gt0.
have Dalpha: alpha = - 1 / p%:R.
apply/(canRL (mulfK nz_p))/eqP; rewrite -addr_eq0 addrC; apply/eqP/esym.
transitivity (cfReg G g); first by rewrite cfRegE (negPf nt_g).
rewrite cfReg_sum sum_cfunE (bigD1 0) //= irr0 !cfunE cfun11 cfun1E Gg.
rewrite mulr1; congr (1 + _); rewrite (bigID p_dv1) /= addrC big_andbC.
rewrite big1 => [|i /p_dvd_supp_g chig0]; last by rewrite cfunE chig0 mulr0.
rewrite add0r big_andbC mulr_suml; apply: eq_bigr => i _.
by rewrite mulrAC divfK // cfunE.
suffices: (p %| 1)%C by rewrite (dvdC_nat p 1) dvdn1 -(subnKC (prime_gt1 p_pr)).
rewrite unfold_in (negPf nz_p).
rewrite Cint_rat_Aint ?rpred_div ?rpred1 ?rpred_nat //.
rewrite -rpredN // -mulNr -Dalpha rpred_sum // => i /andP[/dvdCP[c Zc ->] _].
by rewrite mulfK // rpredM ?Aint_irr ?Aint_Cint.
Qed.
End IntegralChar.
Section MoreIntegralChar.
Implicit Type gT : finGroupType.
(* This is Burnside's famous p^a.q^b theorem (Isaacs, Theorem (3.10)). *)
Theorem Burnside_p_a_q_b gT (G : {group gT}) :
(size (primes #|G|) <= 2)%N -> solvable G.
Proof.
move: {2}_.+1 (ltnSn #|G|) => n; elim: n => // n IHn in gT G *.
rewrite ltnS => leGn piGle2; have [simpleG | ] := boolP (simple G); last first.
rewrite negb_forall_in => /exists_inP[N sNG]; rewrite eq_sym.
have [->|] := eqVneq N G.
rewrite groupP /= genGid normG andbT eqb_id negbK => /eqP->.
exact: solvable1.
rewrite [N == G]eqEproper sNG eqbF_neg !negbK => ltNG /and3P[grN].
case/isgroupP: grN => {}N -> in sNG ltNG *; rewrite /= genGid => ntN nNG.
have nsNG: N <| G by apply/andP.
have dv_le_pi m: (m %| #|G| -> size (primes m) <= 2)%N.
move=> m_dv_G; apply: leq_trans piGle2.
by rewrite uniq_leq_size ?primes_uniq //; apply: pi_of_dvd.
rewrite (series_sol nsNG) !IHn ?dv_le_pi ?cardSg ?dvdn_quotient //.
by apply: leq_trans leGn; apply: ltn_quotient.
by apply: leq_trans leGn; apply: proper_card.
have [->|[p p_pr p_dv_G]] := trivgVpdiv G; first exact: solvable1.
have piGp: p \in \pi(G) by rewrite mem_primes p_pr cardG_gt0.
have [P sylP] := Sylow_exists p G; have [sPG pP p'GP] := and3P sylP.
have ntP: P :!=: 1%g by rewrite -rank_gt0 (rank_Sylow sylP) p_rank_gt0.
have /trivgPn[g /setIP[Pg cPg] nt_g]: 'Z(P) != 1%g.
by rewrite center_nil_eq1 // (pgroup_nil pP).
apply: abelian_sol; have: (size (primes #|g ^: G|) <= 1)%N.
rewrite -ltnS -[_.+1]/(size (p :: _)) (leq_trans _ piGle2) //.
rewrite -index_cent1 uniq_leq_size // => [/= | q].
rewrite primes_uniq -p'natEpi ?(pnat_dvd _ p'GP) ?indexgS //.
by rewrite subsetI sPG sub_cent1.
by rewrite inE => /predU1P[-> // |]; apply: pi_of_dvd; rewrite ?dvdn_indexg.
rewrite leqNgt; apply: contraR => /primes_class_simple_gt1-> //.
by rewrite !inE classG_eq1 nt_g mem_classes // (subsetP sPG).
Qed.
(* This is Isaacs, Theorem (3.11). *)
Theorem dvd_irr1_cardG gT (G : {group gT}) i : ('chi[G]_i 1%g %| #|G|)%C.
Proof.
rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //=.
by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1.
rewrite -[n in n / _]/(_ *+ true) -(eqxx i) -mulr_natr.
rewrite -first_orthogonality_relation mulVKf ?neq0CG //.
rewrite sum_by_classes => [|x y Gx Gy]; rewrite -?conjVg ?cfunJ //.
rewrite mulr_suml rpred_sum // => K /repr_classesP[Gx {1}->].
by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1.
Qed.
(* This is Isaacs, Theorem (3.12). *)
Theorem dvd_irr1_index_center gT (G : {group gT}) i :
('chi[G]_i 1%g %| #|G : 'Z('chi_i)%CF|)%C.
Proof.
without loss fful: gT G i / cfaithful 'chi_i.
rewrite -{2}[i](quo_IirrK _ (subxx _)) 1?mod_IirrE ?cfModE ?cfker_normal //.
rewrite morph1; set i1 := quo_Iirr _ i => /(_ _ _ i1) IH.
have fful_i1: cfaithful 'chi_i1.
by rewrite quo_IirrE ?cfker_normal ?cfaithful_quo.
have:= IH fful_i1; rewrite cfcenter_fful_irr // -cfcenter_eq_center.
rewrite index_quotient_eq ?cfcenter_sub ?cfker_norm //.
by rewrite setIC subIset // normal_sub ?cfker_center_normal.
have [lambda lin_lambda Dlambda] := cfcenter_Res 'chi_i.
have DchiZ: {in G & 'Z(G), forall x y, 'chi_i (x * y)%g = 'chi_i x * lambda y}.
rewrite -(cfcenter_fful_irr fful) => x y Gx Zy.
apply: (mulfI (irr1_neq0 i)); rewrite mulrCA.
transitivity ('chi_i x * ('chi_i 1%g *: lambda) y); last by rewrite !cfunE.
rewrite -Dlambda cfResE ?cfcenter_sub //.
rewrite -irrRepr cfcenter_repr !cfunE in Zy *.
case/setIdP: Zy => Gy /is_scalar_mxP[e De].
rewrite repr_mx1 group1 (groupM Gx Gy) (repr_mxM _ Gx Gy) Gx Gy De.
by rewrite mul_mx_scalar mxtraceZ mulrCA mulrA mulrC -mxtraceZ scalemx1.
have inj_lambda: {in 'Z(G) &, injective lambda}.
rewrite -(cfcenter_fful_irr fful) => x y Zx Zy eq_xy.
apply/eqP; rewrite eq_mulVg1 -in_set1 (subsetP fful) // cfkerEirr inE.
apply/eqP; transitivity ('Res['Z('chi_i)%CF] 'chi_i (x^-1 * y)%g).
by rewrite cfResE ?cfcenter_sub // groupM ?groupV.
rewrite Dlambda !cfunE lin_charM ?groupV // -eq_xy -lin_charM ?groupV //.
by rewrite mulrC mulVg lin_char1 ?mul1r.
rewrite unfold_in -if_neg irr1_neq0 Cint_rat_Aint //.
by rewrite rpred_div ?rpred_nat // rpred_nat_num ?Cnat_irr1.
rewrite (cfcenter_fful_irr fful) nCdivE natf_indexg ?center_sub //=.
have ->: #|G|%:R = \sum_(x in G) 'chi_i x * 'chi_i (x^-1)%g.
rewrite -[_%:R]mulr1; apply: canLR (mulVKf (neq0CG G)) _.
by rewrite first_orthogonality_relation eqxx.
rewrite (big_setID [set x | 'chi_i x == 0]) /= -setIdE.
rewrite big1 ?add0r => [| x /setIdP[_ /eqP->]]; last by rewrite mul0r.
pose h x := (x ^: G * 'Z(G))%g; rewrite (partition_big_imset h).
rewrite !mulr_suml rpred_sum //= => _ /imsetP[x /setDP[Gx nz_chi_x] ->].
have: #|x ^: G|%:R * ('chi_i x * 'chi_i x^-1%g) / 'chi_i 1%g \in Aint.
by rewrite !mulrA mulrAC rpredM ?Aint_irr ?Aint_class_div_irr1.
congr 2 (_ * _ \in Aint); apply: canRL (mulfK (neq0CG _)) _.
rewrite inE in nz_chi_x.
transitivity ('chi_i x * 'chi_i (x^-1)%g *+ #|h x|); last first.
rewrite -sumr_const.
apply: eq_big => [y | _ /mulsgP[_ z /imsetP[u Gu ->] Zz] ->].
rewrite !inE -andbA; apply/idP/and3P=> [|[_ _ /eqP <-]]; last first.
by rewrite -{1}[y]mulg1 mem_mulg ?class_refl.
case/mulsgP=> _ z /imsetP[u Gu ->] Zz ->; have /centerP[Gz cGz] := Zz.
rewrite groupM 1?DchiZ ?groupJ ?cfunJ //; split=> //.
by rewrite mulf_neq0 // lin_char_neq0 /= ?cfcenter_fful_irr.
rewrite -[z](mulKg u) -cGz // -conjMg /h classGidl {u Gu}//.
apply/eqP/setP=> w; apply/mulsgP/mulsgP=> [][_ z1 /imsetP[v Gv ->] Zz1 ->].
exists (x ^ v)%g (z * z1)%g; rewrite ?imset_f ?groupM //.
by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg.
exists ((x * z) ^ v)%g (z^-1 * z1)%g; rewrite ?imset_f ?groupM ?groupV //.
by rewrite conjMg -mulgA /(z ^ v)%g cGz // mulKg mulKVg.
rewrite !irr_inv DchiZ ?groupJ ?cfunJ // rmorphM mulrACA -!normCK -exprMn.
by rewrite (normC_lin_char lin_lambda) ?mulr1 //= cfcenter_fful_irr.
rewrite mulrAC -natrM mulr_natl; congr (_ *+ _).
symmetry; rewrite /h /mulg /= /set_mulg [in _ @2: (_, _)]unlock cardsE.
rewrite -cardX card_in_image // => [] [y1 z1] [y2 z2] /=.
move=> /andP[/=/imsetP[u1 Gu1 ->] Zz1] /andP[/=/imsetP[u2 Gu2 ->] Zz2] {y1 y2}.
move=> eq12; have /eqP := congr1 'chi_i eq12.
rewrite !(cfunJ, DchiZ) ?groupJ // (can_eq (mulKf nz_chi_x)).
rewrite (inj_in_eq inj_lambda) // => /eqP eq_z12; rewrite eq_z12 in eq12 *.
by rewrite (mulIg _ _ _ eq12).
Qed.
(* This is Isaacs, Problem (3.7). *)
Lemma gring_classM_coef_sum_eq gT (G : {group gT}) j1 j2 k g1 g2 g :
let a := @gring_classM_coef gT G j1 j2 in let a_k := a k in
g1 \in enum_val j1 -> g2 \in enum_val j2 -> g \in enum_val k ->
let sum12g := \sum_i 'chi[G]_i g1 * 'chi_i g2 * ('chi_i g)^* / 'chi_i 1%g in
a_k%:R = (#|enum_val j1| * #|enum_val j2|)%:R / #|G|%:R * sum12g.
Proof.
move=> a /= Kg1 Kg2 Kg; rewrite mulrAC; apply: canRL (mulfK (neq0CG G)) _.
transitivity (\sum_j (#|G| * a j)%:R *+ (j == k) : algC).
by rewrite (bigD1 k) //= eqxx -natrM mulnC big1 ?addr0 // => j /negPf->.
have defK (j : 'I_#|classes G|) x: x \in enum_val j -> enum_val j = x ^: G.
by have /imsetP[y Gy ->] := enum_valP j => /class_eqP.
have Gg: g \in G.
by case/imsetP: (enum_valP k) Kg => x Gx -> /imsetP[y Gy ->]; apply: groupJ.
transitivity (\sum_j \sum_i 'omega_i['K_j] * 'chi_i 1%g * ('chi_i g)^* *+ a j).
apply: eq_bigr => j _; have /imsetP[z Gz Dj] := enum_valP j.
have Kz: z \in enum_val j by rewrite Dj class_refl.
rewrite -(Lagrange (subsetIl G 'C[z])) index_cent1 -mulnA natrM -mulrnAl.
have ->: (j == k) = (z \in enum_val k).
by rewrite -(inj_eq enum_val_inj); apply/eqP/idP=> [<-|/defK->].
rewrite (defK _ g) // -second_orthogonality_relation // mulr_suml.
apply: eq_bigr=> i _; rewrite natrM mulrA mulr_natr mulrC mulrA.
by rewrite (gring_mode_class_sum_eq i Kz) divfK ?irr1_neq0.
rewrite exchange_big /= mulr_sumr; apply: eq_bigr => i _.
transitivity ('omega_i['K_j1 *m 'K_j2] * 'chi_i 1%g * ('chi_i g)^*).
rewrite gring_classM_expansion -/a raddf_sum !mulr_suml /=.
by apply: eq_bigr => j _; rewrite xcfunZr -!mulrA mulr_natl.
rewrite !mulrA 2![_ / _]mulrAC (defK _ _ Kg1) (defK _ _ Kg2); congr (_ * _).
rewrite gring_irr_modeM ?gring_class_sum_central // mulnC natrM.
rewrite (gring_mode_class_sum_eq i Kg2) !mulrA divfK ?irr1_neq0 //.
by congr (_ * _); rewrite [_ * _]mulrC (gring_mode_class_sum_eq i Kg1) !mulrA.
Qed.
(* This is Isaacs, Problem (2.16). *)
Lemma index_support_dvd_degree gT (G H : {group gT}) chi :
H \subset G -> chi \is a character -> chi \in 'CF(G, H) ->
(H :==: 1%g) || abelian G ->
(#|G : H| %| chi 1%g)%C.
Proof.
move=> sHG Nchi Hchi ZHG.
suffices: (#|G : H| %| 'Res[H] chi 1%g)%C by rewrite cfResE ?group1.
rewrite ['Res _]cfun_sum_cfdot sum_cfunE rpred_sum // => i _.
rewrite cfunE dvdC_mulr ?intr_nat ?Cnat_irr1 //.
have [j ->]: exists j, 'chi_i = 'Res 'chi[G]_j.
case/predU1P: ZHG => [-> | cGG] in i *.
suffices ->: i = 0 by exists 0; rewrite !irr0 cfRes_cfun1 ?sub1G.
apply/val_inj; case: i => [[|i] //=]; rewrite ltnNge NirrE.
by rewrite (@leq_trans 1) // leqNgt classes_gt1 eqxx.
have linG := char_abelianP G cGG; have linG1 j := eqP (proj2 (andP (linG j))).
have /fin_all_exists[rH DrH] j: exists k, 'Res[H, G] 'chi_j = 'chi_k.
apply/irrP/lin_char_irr/andP.
by rewrite cfRes_char ?irr_char // cfRes1 ?linG1.
suffices{i} all_rH: codom rH =i Iirr H.
by exists (iinv (all_rH i)); rewrite DrH f_iinv.
apply/subset_cardP; last exact/subsetP; apply/esym/eqP.
rewrite card_Iirr_abelian ?(abelianS sHG) //.
rewrite -(eqn_pmul2r (indexg_gt0 G H)) Lagrange //; apply/eqP.
rewrite -sum_nat_const -card_Iirr_abelian // -sum1_card.
rewrite (partition_big rH [in codom rH]) /=; last exact: image_f.
have nsHG: H <| G by rewrite -sub_abelian_normal.
apply: eq_bigr => _ /codomP[i ->]; rewrite -card_quotient ?normal_norm //.
rewrite -card_Iirr_abelian ?quotient_abelian //.
have Mlin j1 j2: exists k, 'chi_j1 * 'chi_j2 = 'chi[G]_k.
exact/irrP/lin_char_irr/rpredM.
have /fin_all_exists[rQ DrQ] (j : Iirr (G / H)) := Mlin i (mod_Iirr j).
have mulJi: ('chi[G]_i)^*%CF * 'chi_i = 1.
apply/cfun_inP=> x Gx; rewrite !cfunE /= -lin_charV_conj ?linG // cfun1E Gx.
by rewrite lin_charV ?mulVf ?lin_char_neq0 ?linG.
have inj_rQ: injective rQ.
move=> j1 j2 /(congr1 (fun k => (('chi_i)^*%CF * 'chi_k) / H)%CF).
by rewrite -!DrQ !mulrA mulJi !mul1r !mod_IirrE ?cfModK // => /irr_inj.
rewrite -(card_imset _ inj_rQ) -sum1_card; apply: eq_bigl => j.
rewrite -(inj_eq irr_inj) -!DrH; apply/eqP/imsetP=> [eq_ij | [k _ ->]].
have [k Dk] := Mlin (conjC_Iirr i) j; exists (quo_Iirr H k) => //.
apply/irr_inj; rewrite -DrQ quo_IirrK //.
by rewrite -Dk conjC_IirrE mulrCA mulrA mulJi mul1r.
apply/subsetP=> x Hx; have Gx := subsetP sHG x Hx.
rewrite cfkerEirr inE linG1 -Dk conjC_IirrE; apply/eqP.
transitivity ((1 : 'CF(G)) x); last by rewrite cfun1E Gx.
by rewrite -mulJi !cfunE -!(cfResE _ sHG Hx) eq_ij.
rewrite -DrQ; apply/cfun_inP=> x Hx; rewrite !cfResE // cfunE mulrC.
by rewrite cfker1 ?linG1 ?mul1r ?(subsetP _ x Hx) // mod_IirrE ?cfker_mod.
have: (#|G : H| %| #|G : H|%:R * '[chi, 'chi_j])%C.
by rewrite dvdC_mulr ?intr_nat ?Cnat_cfdot_char_irr.
congr (_ %| _)%C; rewrite (cfdotEl _ Hchi) -(Lagrange sHG) mulnC natrM.
rewrite invfM -mulrA mulVKf ?neq0CiG //; congr (_ * _).
by apply: eq_bigr => x Hx; rewrite !cfResE.
Qed.
(* This is Isaacs, Theorem (3.13). *)
Theorem faithful_degree_p_part gT (p : nat) (G P : {group gT}) i :
cfaithful 'chi[G]_i -> p.-nat (Num.truncn ('chi_i 1%g)) ->
p.-Sylow(G) P -> abelian P ->
'chi_i 1%g = (#|G : 'Z(G)|`_p)%:R.
Proof.
have [p_pr | pr'p] := boolP (prime p); last first.
have p'n n: (n > 0)%N -> p^'.-nat n.
by move/p'natEpi->; rewrite mem_primes (negPf pr'p).
rewrite irr1_degree natrK => _ /pnat_1-> => [_ _|].
by rewrite part_p'nat ?p'n.
by rewrite p'n ?irr_degree_gt0.
move=> fful_i /p_natP[a Dchi1] sylP cPP.
have Dchi1C: 'chi_i 1%g = (p ^ a)%:R by rewrite -Dchi1 irr1_degree natrK.
have pa_dv_ZiG: (p ^ a %| #|G : 'Z(G)|)%N.
rewrite -dvdC_nat -[pa in (pa %| _)%C]Dchi1C -(cfcenter_fful_irr fful_i).
exact: dvd_irr1_index_center.
have [sPG pP p'PiG] := and3P sylP.
have ZchiP: 'Res[P] 'chi_i \in 'CF(P, P :&: 'Z(G)).
apply/cfun_onP=> x /[1!inE]; have [Px | /cfun0->//] := boolP (x \in P).
rewrite /= -(cfcenter_fful_irr fful_i) cfResE //.
apply: coprime_degree_support_cfcenter.
rewrite Dchi1 coprimeXl // prime_coprime // -p'natE //.
apply: pnat_dvd p'PiG; rewrite -index_cent1 indexgS // subsetI sPG.
by rewrite sub_cent1 (subsetP cPP).
have /andP[_ nZG] := center_normal G; have nZP := subset_trans sPG nZG.
apply/eqP; rewrite Dchi1C eqr_nat eqn_dvd -{1}(pfactorK a p_pr) -p_part.
rewrite partn_dvd //= -dvdC_nat -[pa in (_ %| pa)%C]Dchi1C -card_quotient //=.
rewrite -(card_Hall (quotient_pHall nZP sylP)) card_quotient // -indexgI.
rewrite -(cfResE _ sPG) // index_support_dvd_degree ?subsetIl ?cPP ?orbT //.
by rewrite cfRes_char ?irr_char.
Qed.
(* This is Isaacs, Lemma (3.14). *)
(* Note that the assumption that G be cyclic is unnecessary, as S will be *)
(* empty if this is not the case. *)
Lemma sum_norm2_char_generators gT (G : {group gT}) (chi : 'CF(G)) :
let S := [pred s | generator G s] in
chi \is a character -> {in S, forall s, chi s != 0} ->
\sum_(s in S) `|chi s| ^+ 2 >= #|S|%:R.
Proof.
move=> S Nchi nz_chi_S; pose n := #|G|.
have [g Sg | S_0] := pickP (generator G); last first.
by rewrite eq_card0 // big_pred0 ?lerr.
have defG: <[g]> = G by apply/esym/eqP.
have [cycG Gg]: cyclic G /\ g \in G by rewrite -defG cycle_cyclic cycle_id.
pose I := {k : 'I_n | coprime n k}; pose ItoS (k : I) := (g ^+ sval k)%g.
have imItoS: codom ItoS =i S.
move=> s; rewrite inE /= /ItoS /I /n /S -defG -orderE.
apply/codomP/idP=> [[[i cogi] ->] | Ss]; first by rewrite generator_coprime.
have [m ltmg Ds] := cyclePmin (cycle_generator Ss).
by rewrite Ds generator_coprime in Ss; apply: ex_intro (Sub (Sub m _) _) _.
have /injectiveP injItoS: injective ItoS.
move=> k1 k2 /eqP; apply: contraTeq.
by rewrite eq_expg_mod_order orderE defG -/n !modn_small.
have [Qn galQn [QnC gQnC [eps [pr_eps defQn] QnG]]] := group_num_field_exists G.
have{QnG} QnGg := QnG _ G _ _ g (order_dvdG Gg).
pose calG := 'Gal({:Qn} / 1).
have /fin_all_exists2[ItoQ inItoQ defItoQ] (k : I):
exists2 nu, nu \in calG & nu eps = eps ^+ val k.
- case: k => [[m _] /=]; rewrite coprime_sym => /Qn_aut_exists[nuC DnuC].
have [nuQ DnuQ] := restrict_aut_to_normal_num_field QnC nuC.
have hom_nu: kHom 1 {:Qn} (linfun nuQ).
rewrite k1HomE; apply/ahom_inP.
by split=> [u v | ]; rewrite !lfunE ?rmorphM ?rmorph1.
have [|nu cGnu Dnu] := kHom_to_gal _ (normalFieldf 1) hom_nu.
by rewrite !subvf.
exists nu => //; apply: (fmorph_inj QnC).
rewrite -Dnu ?memvf // lfunE DnuQ rmorphXn DnuC //.
by rewrite prim_expr_order // fmorph_primitive_root.
have{defQn} imItoQ: calG = ItoQ @: {:I}.
apply/setP=> nu; apply/idP/imsetP=> [cGnu | [k _ ->] //].
have pr_nu_e: n.-primitive_root (nu eps) by rewrite fmorph_primitive_root.
have [i Dnue] := prim_rootP pr_eps (prim_expr_order pr_nu_e).
rewrite Dnue prim_root_exp_coprime // coprime_sym in pr_nu_e.
apply: ex_intro2 (Sub i _) _ _ => //; apply/eqP.
rewrite /calG /= -defQn in ItoQ inItoQ defItoQ nu cGnu Dnue *.
by rewrite gal_adjoin_eq // defItoQ -Dnue.
have injItoQ: {in {:I} &, injective ItoQ}.
move=> k1 k2 _ _ /(congr1 (fun nu : gal_of _ => nu eps))/eqP.
by apply: contraTeq; rewrite !defItoQ (eq_prim_root_expr pr_eps) !modn_small.
pose pi1 := \prod_(s in S) chi s; pose pi2 := \prod_(s in S) `|chi s| ^+ 2.
have Qpi1: pi1 \in Crat.
have [a Da] := QnGg _ Nchi; suffices ->: pi1 = QnC (galNorm 1 {:Qn} a).
have /vlineP[q ->] := mem_galNorm galQn (memvf a).
by rewrite rmorphZ_num rmorph1 mulr1 Crat_rat.
rewrite /galNorm rmorph_prod -/calG imItoQ big_imset //=.
rewrite /pi1 -(eq_bigl _ _ imItoS) -big_uniq // big_image /=.
apply: eq_bigr => k _; have [nuC DnuC] := gQnC (ItoQ k); rewrite DnuC Da.
have [r ->] := char_sum_irr Nchi; rewrite !sum_cfunE rmorph_sum.
apply: eq_bigr => i _; have /QnGg[b Db] := irr_char i.
have Lchi_i: 'chi_i \is a linear_char by rewrite irr_cyclic_lin.
have /(prim_rootP pr_eps)[m Dem]: b ^+ n = 1.
apply/eqP; rewrite -(fmorph_eq1 QnC) rmorphXn /= Db -lin_charX //.
by rewrite -expg_mod_order orderE defG modnn lin_char1.
rewrite -Db /= -DnuC Dem rmorphXn /= defItoQ exprAC -{m}Dem rmorphXn /= {b}Db.
by rewrite lin_charX.
clear I ItoS imItoS injItoS ItoQ inItoQ defItoQ imItoQ injItoQ.
clear Qn galQn QnC gQnC eps pr_eps QnGg calG.
have{Qpi1} Zpi1: pi1 \in Num.int.
by rewrite Cint_rat_Aint // rpred_prod // => s _; apply: Aint_char.
have{pi1 Zpi1} pi2_ge1: 1 <= pi2.
have ->: pi2 = `|pi1| ^+ 2.
by rewrite (big_morph Num.norm (@normrM _) (@normr1 _)) -prodrXl.
by rewrite intr_normK // sqr_intr_ge1 //; apply/prodf_neq0.
have Sgt0: (#|S| > 0)%N by rewrite (cardD1 g) [g \in S]Sg.
rewrite -mulr_natr -ler_pdivlMr ?ltr0n //.
have n2chi_ge0 s: s \in S -> 0 <= `|chi s| ^+ 2 by rewrite exprn_ge0.
rewrite -(expr_ge1 Sgt0); last by rewrite divr_ge0 ?ler0n ?sumr_ge0.
by rewrite (le_trans pi2_ge1) // leif_AGM.
Qed.
(* This is Burnside's vanishing theorem (Isaacs, Theorem (3.15)). *)
Theorem nonlinear_irr_vanish gT (G : {group gT}) i :
'chi[G]_i 1%g > 1 -> exists2 x, x \in G & 'chi_i x = 0.
Proof.
move=> chi1gt1; apply/exists_eq_inP; apply: contraFT (lt_geF chi1gt1).
move=> /exists_inPn-nz_chi.
rewrite -(norm_natr (Cnat_irr1 i)) -(@expr_le1 _ 2)//.
rewrite -(lerD2r (#|G|%:R * '['chi_i])) {1}cfnorm_irr mulr1.
rewrite (cfnormE (cfun_onG _)) mulVKf ?neq0CG // (big_setD1 1%g) //=.
rewrite addrCA lerD2l (cardsD1 1%g) group1 mulrS lerD2l.
rewrite -sumr_const !(partition_big_imset (fun s => <[s]>)) /=.
apply: ler_sum => _ /imsetP[g /setD1P[ntg Gg] ->].
have sgG: <[g]> \subset G by rewrite cycle_subG.
pose S := [pred s | generator <[g]> s]; pose chi := 'Res[<[g]>] 'chi_i.
have defS: [pred s in G^# | <[s]> == <[g]>] =i S.
move=> s; rewrite inE /= eq_sym andb_idl // !inE -cycle_eq1 -cycle_subG.
by move/eqP <-; rewrite cycle_eq1 ntg.
have resS: {in S, 'chi_i =1 chi}.
by move=> s /cycle_generator=> g_s; rewrite cfResE ?cycle_subG.
rewrite !(eq_bigl _ _ defS) sumr_const.
rewrite (eq_bigr (fun s => `|chi s| ^+ 2)) => [|s /resS-> //].
apply: sum_norm2_char_generators => [|s Ss].
by rewrite cfRes_char ?irr_char.
by rewrite -resS // nz_chi ?(subsetP sgG) ?cycle_generator.
Qed.
End MoreIntegralChar.
|
Configuration.lean
|
/-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Combinatorics.Hall.Basic
import Mathlib.Data.Matrix.Rank
import Mathlib.LinearAlgebra.Projectivization.Constructions
/-!
# Configurations of Points and lines
This file introduces abstract configurations of points and lines, and proves some basic properties.
## Main definitions
* `Configuration.Nondegenerate`: Excludes certain degenerate configurations,
and imposes uniqueness of intersection points.
* `Configuration.HasPoints`: A nondegenerate configuration in which
every pair of lines has an intersection point.
* `Configuration.HasLines`: A nondegenerate configuration in which
every pair of points has a line through them.
* `Configuration.lineCount`: The number of lines through a given point.
* `Configuration.pointCount`: The number of lines through a given line.
## Main statements
* `Configuration.HasLines.card_le`: `HasLines` implies `|P| ≤ |L|`.
* `Configuration.HasPoints.card_le`: `HasPoints` implies `|L| ≤ |P|`.
* `Configuration.HasLines.hasPoints`: `HasLines` and `|P| = |L|` implies `HasPoints`.
* `Configuration.HasPoints.hasLines`: `HasPoints` and `|P| = |L|` implies `HasLines`.
Together, these four statements say that any two of the following properties imply the third:
(a) `HasLines`, (b) `HasPoints`, (c) `|P| = |L|`.
-/
open Finset
namespace Configuration
variable (P L : Type*) [Membership P L]
/-- A type synonym. -/
def Dual :=
P
instance [h : Inhabited P] : Inhabited (Dual P) :=
h
instance [Finite P] : Finite (Dual P) :=
‹Finite P›
instance [h : Fintype P] : Fintype (Dual P) :=
h
set_option synthInstance.checkSynthOrder false in
instance : Membership (Dual L) (Dual P) :=
⟨Function.swap (Membership.mem : L → P → Prop)⟩
/-- A configuration is nondegenerate if:
1) there does not exist a line that passes through all of the points,
2) there does not exist a point that is on all of the lines,
3) there is at most one line through any two points,
4) any two lines have at most one intersection point.
Conditions 3 and 4 are equivalent. -/
class Nondegenerate : Prop where
exists_point : ∀ l : L, ∃ p, p ∉ l
exists_line : ∀ p, ∃ l : L, p ∉ l
eq_or_eq : ∀ {p₁ p₂ : P} {l₁ l₂ : L}, p₁ ∈ l₁ → p₂ ∈ l₁ → p₁ ∈ l₂ → p₂ ∈ l₂ → p₁ = p₂ ∨ l₁ = l₂
/-- A nondegenerate configuration in which every pair of lines has an intersection point. -/
class HasPoints extends Nondegenerate P L where
/-- Intersection of two lines -/
mkPoint : ∀ {l₁ l₂ : L}, l₁ ≠ l₂ → P
mkPoint_ax : ∀ {l₁ l₂ : L} (h : l₁ ≠ l₂), mkPoint h ∈ l₁ ∧ mkPoint h ∈ l₂
/-- A nondegenerate configuration in which every pair of points has a line through them. -/
class HasLines extends Nondegenerate P L where
/-- Line through two points -/
mkLine : ∀ {p₁ p₂ : P}, p₁ ≠ p₂ → L
mkLine_ax : ∀ {p₁ p₂ : P} (h : p₁ ≠ p₂), p₁ ∈ mkLine h ∧ p₂ ∈ mkLine h
open Nondegenerate
open HasPoints (mkPoint mkPoint_ax)
open HasLines (mkLine mkLine_ax)
instance Dual.Nondegenerate [Nondegenerate P L] : Nondegenerate (Dual L) (Dual P) where
exists_point := @exists_line P L _ _
exists_line := @exists_point P L _ _
eq_or_eq := @fun l₁ l₂ p₁ p₂ h₁ h₂ h₃ h₄ => (@eq_or_eq P L _ _ p₁ p₂ l₁ l₂ h₁ h₃ h₂ h₄).symm
instance Dual.hasLines [HasPoints P L] : HasLines (Dual L) (Dual P) :=
{ Dual.Nondegenerate _ _ with
mkLine := @mkPoint P L _ _
mkLine_ax := @mkPoint_ax P L _ _ }
instance Dual.hasPoints [HasLines P L] : HasPoints (Dual L) (Dual P) :=
{ Dual.Nondegenerate _ _ with
mkPoint := @mkLine P L _ _
mkPoint_ax := @mkLine_ax P L _ _ }
theorem HasPoints.existsUnique_point [HasPoints P L] (l₁ l₂ : L) (hl : l₁ ≠ l₂) :
∃! p, p ∈ l₁ ∧ p ∈ l₂ :=
⟨mkPoint hl, mkPoint_ax hl, fun _ hp =>
(eq_or_eq hp.1 (mkPoint_ax hl).1 hp.2 (mkPoint_ax hl).2).resolve_right hl⟩
theorem HasLines.existsUnique_line [HasLines P L] (p₁ p₂ : P) (hp : p₁ ≠ p₂) :
∃! l : L, p₁ ∈ l ∧ p₂ ∈ l :=
HasPoints.existsUnique_point (Dual L) (Dual P) p₁ p₂ hp
variable {P L}
/-- If a nondegenerate configuration has at least as many points as lines, then there exists
an injective function `f` from lines to points, such that `f l` does not lie on `l`. -/
theorem Nondegenerate.exists_injective_of_card_le [Nondegenerate P L] [Fintype P] [Fintype L]
(h : Fintype.card L ≤ Fintype.card P) : ∃ f : L → P, Function.Injective f ∧ ∀ l, f l ∉ l := by
classical
let t : L → Finset P := fun l => Set.toFinset { p | p ∉ l }
suffices ∀ s : Finset L, #s ≤ (s.biUnion t).card by
-- Hall's marriage theorem
obtain ⟨f, hf1, hf2⟩ := (Finset.all_card_le_biUnion_card_iff_exists_injective t).mp this
exact ⟨f, hf1, fun l => Set.mem_toFinset.mp (hf2 l)⟩
intro s
by_cases hs₀ : #s = 0
-- If `s = ∅`, then `#s = 0 ≤ #(s.bUnion t)`
· simp_rw [hs₀, zero_le]
by_cases hs₁ : #s = 1
-- If `s = {l}`, then pick a point `p ∉ l`
· obtain ⟨l, rfl⟩ := Finset.card_eq_one.mp hs₁
obtain ⟨p, hl⟩ := exists_point (P := P) l
rw [Finset.card_singleton, Finset.singleton_biUnion, Nat.one_le_iff_ne_zero]
exact Finset.card_ne_zero_of_mem (Set.mem_toFinset.mpr hl)
suffices #(s.biUnion t)ᶜ ≤ #sᶜ by
-- Rephrase in terms of complements (uses `h`)
rw [Finset.card_compl, Finset.card_compl, tsub_le_iff_left] at this
replace := h.trans this
rwa [← add_tsub_assoc_of_le s.card_le_univ, le_tsub_iff_left (le_add_left s.card_le_univ),
add_le_add_iff_right] at this
have hs₂ : #(s.biUnion t)ᶜ ≤ 1 := by
-- At most one line through two points of `s`
refine Finset.card_le_one_iff.mpr @fun p₁ p₂ hp₁ hp₂ => ?_
simp_rw [t, Finset.mem_compl, Finset.mem_biUnion, not_exists, not_and,
Set.mem_toFinset, Set.mem_setOf_eq, Classical.not_not] at hp₁ hp₂
obtain ⟨l₁, l₂, hl₁, hl₂, hl₃⟩ :=
Finset.one_lt_card_iff.mp (Nat.one_lt_iff_ne_zero_and_ne_one.mpr ⟨hs₀, hs₁⟩)
exact (eq_or_eq (hp₁ l₁ hl₁) (hp₂ l₁ hl₁) (hp₁ l₂ hl₂) (hp₂ l₂ hl₂)).resolve_right hl₃
by_cases hs₃ : #sᶜ = 0
· rw [hs₃, Nat.le_zero]
rw [Finset.card_compl, tsub_eq_zero_iff_le, (Finset.card_le_univ _).ge_iff_eq', eq_comm,
Finset.card_eq_iff_eq_univ] at hs₃ ⊢
rw [hs₃]
rw [Finset.eq_univ_iff_forall] at hs₃ ⊢
exact fun p =>
Exists.elim (exists_line p)-- If `s = univ`, then show `s.bUnion t = univ`
fun l hl => Finset.mem_biUnion.mpr ⟨l, Finset.mem_univ l, Set.mem_toFinset.mpr hl⟩
· exact hs₂.trans (Nat.one_le_iff_ne_zero.mpr hs₃)
-- If `s < univ`, then consequence of `hs₂`
variable (L)
/-- Number of points on a given line. -/
noncomputable def lineCount (p : P) : ℕ :=
Nat.card { l : L // p ∈ l }
variable (P) {L}
/-- Number of lines through a given point. -/
noncomputable def pointCount (l : L) : ℕ :=
Nat.card { p : P // p ∈ l }
variable (L)
theorem sum_lineCount_eq_sum_pointCount [Fintype P] [Fintype L] :
∑ p : P, lineCount L p = ∑ l : L, pointCount P l := by
classical
simp only [lineCount, pointCount, Nat.card_eq_fintype_card, ← Fintype.card_sigma]
apply Fintype.card_congr
calc
(Σ p, { l : L // p ∈ l }) ≃ { x : P × L // x.1 ∈ x.2 } :=
(Equiv.subtypeProdEquivSigmaSubtype (· ∈ ·)).symm
_ ≃ { x : L × P // x.2 ∈ x.1 } := (Equiv.prodComm P L).subtypeEquiv fun x => Iff.rfl
_ ≃ Σ l, { p // p ∈ l } := Equiv.subtypeProdEquivSigmaSubtype fun (l : L) (p : P) => p ∈ l
variable {P L}
theorem HasLines.pointCount_le_lineCount [HasLines P L] {p : P} {l : L} (h : p ∉ l)
[Finite { l : L // p ∈ l }] : pointCount P l ≤ lineCount L p := by
by_cases hf : Infinite { p : P // p ∈ l }
· exact (le_of_eq Nat.card_eq_zero_of_infinite).trans (zero_le (lineCount L p))
haveI := fintypeOfNotInfinite hf
cases nonempty_fintype { l : L // p ∈ l }
rw [lineCount, pointCount, Nat.card_eq_fintype_card, Nat.card_eq_fintype_card]
have : ∀ p' : { p // p ∈ l }, p ≠ p' := fun p' hp' => h ((congr_arg (· ∈ l) hp').mpr p'.2)
exact
Fintype.card_le_of_injective (fun p' => ⟨mkLine (this p'), (mkLine_ax (this p')).1⟩)
fun p₁ p₂ hp =>
Subtype.ext ((eq_or_eq p₁.2 p₂.2 (mkLine_ax (this p₁)).2
((congr_arg (_ ∈ ·) (Subtype.ext_iff.mp hp)).mpr (mkLine_ax (this p₂)).2)).resolve_right
fun h' => (congr_arg (p ∉ ·) h').mp h (mkLine_ax (this p₁)).1)
theorem HasPoints.lineCount_le_pointCount [HasPoints P L] {p : P} {l : L} (h : p ∉ l)
[hf : Finite { p : P // p ∈ l }] : lineCount L p ≤ pointCount P l :=
@HasLines.pointCount_le_lineCount (Dual L) (Dual P) _ _ l p h hf
variable (P L)
/-- If a nondegenerate configuration has a unique line through any two points, then `|P| ≤ |L|`. -/
theorem HasLines.card_le [HasLines P L] [Fintype P] [Fintype L] :
Fintype.card P ≤ Fintype.card L := by
classical
by_contra hc₂
obtain ⟨f, hf₁, hf₂⟩ := Nondegenerate.exists_injective_of_card_le (le_of_not_ge hc₂)
have :=
calc
∑ p, lineCount L p = ∑ l, pointCount P l := sum_lineCount_eq_sum_pointCount P L
_ ≤ ∑ l, lineCount L (f l) :=
(Finset.sum_le_sum fun l _ => HasLines.pointCount_le_lineCount (hf₂ l))
_ = ∑ p ∈ univ.map ⟨f, hf₁⟩, lineCount L p := by rw [sum_map]; dsimp
_ < ∑ p, lineCount L p := by
obtain ⟨p, hp⟩ := not_forall.mp (mt (Fintype.card_le_of_surjective f) hc₂)
refine sum_lt_sum_of_subset (subset_univ _) (mem_univ p) ?_ ?_ fun p _ _ ↦ zero_le _
· simpa only [Finset.mem_map, exists_prop, Finset.mem_univ, true_and]
· rw [lineCount, Nat.card_eq_fintype_card, Fintype.card_pos_iff]
obtain ⟨l, _⟩ := @exists_line P L _ _ p
exact
let this := not_exists.mp hp l
⟨⟨mkLine this, (mkLine_ax this).2⟩⟩
exact lt_irrefl _ this
/-- If a nondegenerate configuration has a unique point on any two lines, then `|L| ≤ |P|`. -/
theorem HasPoints.card_le [HasPoints P L] [Fintype P] [Fintype L] :
Fintype.card L ≤ Fintype.card P :=
@HasLines.card_le (Dual L) (Dual P) _ _ _ _
variable {P L}
theorem HasLines.exists_bijective_of_card_eq [HasLines P L] [Fintype P] [Fintype L]
(h : Fintype.card P = Fintype.card L) :
∃ f : L → P, Function.Bijective f ∧ ∀ l, pointCount P l = lineCount L (f l) := by
classical
obtain ⟨f, hf1, hf2⟩ := Nondegenerate.exists_injective_of_card_le (ge_of_eq h)
have hf3 := (Fintype.bijective_iff_injective_and_card f).mpr ⟨hf1, h.symm⟩
exact ⟨f, hf3, fun l ↦ (sum_eq_sum_iff_of_le fun l _ ↦ pointCount_le_lineCount (hf2 l)).1
((hf3.sum_comp _).trans (sum_lineCount_eq_sum_pointCount P L)).symm _ <| mem_univ _⟩
theorem HasLines.lineCount_eq_pointCount [HasLines P L] [Fintype P] [Fintype L]
(hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p ∉ l) :
lineCount L p = pointCount P l := by
classical
obtain ⟨f, hf1, hf2⟩ := HasLines.exists_bijective_of_card_eq hPL
let s : Finset (P × L) := Set.toFinset { i | i.1 ∈ i.2 }
have step1 : ∑ i : P × L, lineCount L i.1 = ∑ i : P × L, pointCount P i.2 := by
rw [← Finset.univ_product_univ, Finset.sum_product_right, Finset.sum_product]
simp_rw [Finset.sum_const, Finset.card_univ, hPL, sum_lineCount_eq_sum_pointCount]
have step2 : ∑ i ∈ s, lineCount L i.1 = ∑ i ∈ s, pointCount P i.2 := by
rw [s.sum_finset_product Finset.univ fun p => Set.toFinset { l | p ∈ l }]
on_goal 1 =>
rw [s.sum_finset_product_right Finset.univ fun l => Set.toFinset { p | p ∈ l }, eq_comm]
· refine sum_bijective _ hf1 (by simp) fun l _ ↦ ?_
simp_rw [hf2, sum_const, Set.toFinset_card, ← Nat.card_eq_fintype_card]
change pointCount P l • _ = lineCount L (f l) • _
rw [hf2]
all_goals simp_rw [s, Finset.mem_univ, true_and, Set.mem_toFinset]; exact fun p => Iff.rfl
have step3 : ∑ i ∈ sᶜ, lineCount L i.1 = ∑ i ∈ sᶜ, pointCount P i.2 := by
rwa [← s.sum_add_sum_compl, ← s.sum_add_sum_compl, step2, add_left_cancel_iff] at step1
rw [← Set.toFinset_compl] at step3
exact
((Finset.sum_eq_sum_iff_of_le fun i hi =>
HasLines.pointCount_le_lineCount (by exact Set.mem_toFinset.mp hi)).mp
step3.symm (p, l) (Set.mem_toFinset.mpr hpl)).symm
theorem HasPoints.lineCount_eq_pointCount [HasPoints P L] [Fintype P] [Fintype L]
(hPL : Fintype.card P = Fintype.card L) {p : P} {l : L} (hpl : p ∉ l) :
lineCount L p = pointCount P l :=
(@HasLines.lineCount_eq_pointCount (Dual L) (Dual P) _ _ _ _ hPL.symm l p hpl).symm
/-- If a nondegenerate configuration has a unique line through any two points, and if `|P| = |L|`,
then there is a unique point on any two lines. -/
noncomputable def HasLines.hasPoints [HasLines P L] [Fintype P] [Fintype L]
(h : Fintype.card P = Fintype.card L) : HasPoints P L :=
let this : ∀ l₁ l₂ : L, l₁ ≠ l₂ → ∃ p : P, p ∈ l₁ ∧ p ∈ l₂ := fun l₁ l₂ hl => by
classical
obtain ⟨f, _, hf2⟩ := HasLines.exists_bijective_of_card_eq h
haveI : Nontrivial L := ⟨⟨l₁, l₂, hl⟩⟩
haveI := Fintype.one_lt_card_iff_nontrivial.mp ((congr_arg _ h).mpr Fintype.one_lt_card)
have h₁ : ∀ p : P, 0 < lineCount L p := fun p =>
Exists.elim (exists_ne p) fun q hq =>
(congr_arg _ Nat.card_eq_fintype_card).mpr
(Fintype.card_pos_iff.mpr ⟨⟨mkLine hq, (mkLine_ax hq).2⟩⟩)
have h₂ : ∀ l : L, 0 < pointCount P l := fun l => (congr_arg _ (hf2 l)).mpr (h₁ (f l))
obtain ⟨p, hl₁⟩ := Fintype.card_pos_iff.mp ((congr_arg _ Nat.card_eq_fintype_card).mp (h₂ l₁))
by_cases hl₂ : p ∈ l₂
· exact ⟨p, hl₁, hl₂⟩
have key' : Fintype.card { q : P // q ∈ l₂ } = Fintype.card { l : L // p ∈ l } :=
((HasLines.lineCount_eq_pointCount h hl₂).trans Nat.card_eq_fintype_card).symm.trans
Nat.card_eq_fintype_card
have : ∀ q : { q // q ∈ l₂ }, p ≠ q := fun q hq => hl₂ ((congr_arg (· ∈ l₂) hq).mpr q.2)
let f : { q : P // q ∈ l₂ } → { l : L // p ∈ l } := fun q =>
⟨mkLine (this q), (mkLine_ax (this q)).1⟩
have hf : Function.Injective f := fun q₁ q₂ hq =>
Subtype.ext ((eq_or_eq q₁.2 q₂.2 (mkLine_ax (this q₁)).2
((congr_arg (_ ∈ ·) (Subtype.ext_iff.mp hq)).mpr (mkLine_ax (this q₂)).2)).resolve_right
fun h => (congr_arg (p ∉ ·) h).mp hl₂ (mkLine_ax (this q₁)).1)
have key' := ((Fintype.bijective_iff_injective_and_card f).mpr ⟨hf, key'⟩).2
obtain ⟨q, hq⟩ := key' ⟨l₁, hl₁⟩
exact ⟨q, (congr_arg (_ ∈ ·) (Subtype.ext_iff.mp hq)).mp (mkLine_ax (this q)).2, q.2⟩
{ ‹HasLines P L› with
mkPoint := fun {l₁ l₂} hl => Classical.choose (this l₁ l₂ hl)
mkPoint_ax := fun {l₁ l₂} hl => Classical.choose_spec (this l₁ l₂ hl) }
/-- If a nondegenerate configuration has a unique point on any two lines, and if `|P| = |L|`,
then there is a unique line through any two points. -/
noncomputable def HasPoints.hasLines [HasPoints P L] [Fintype P] [Fintype L]
(h : Fintype.card P = Fintype.card L) : HasLines P L :=
let this := @HasLines.hasPoints (Dual L) (Dual P) _ _ _ _ h.symm
{ ‹HasPoints P L› with
mkLine := @fun _ _ => this.mkPoint
mkLine_ax := @fun _ _ => this.mkPoint_ax }
variable (P L)
/-- A projective plane is a nondegenerate configuration in which every pair of lines has
an intersection point, every pair of points has a line through them,
and which has three points in general position. -/
class ProjectivePlane extends HasPoints P L, HasLines P L where
exists_config :
∃ (p₁ p₂ p₃ : P) (l₁ l₂ l₃ : L),
p₁ ∉ l₂ ∧ p₁ ∉ l₃ ∧ p₂ ∉ l₁ ∧ p₂ ∈ l₂ ∧ p₂ ∈ l₃ ∧ p₃ ∉ l₁ ∧ p₃ ∈ l₂ ∧ p₃ ∉ l₃
namespace ProjectivePlane
variable [ProjectivePlane P L]
instance : ProjectivePlane (Dual L) (Dual P) :=
{ Dual.hasPoints _ _, Dual.hasLines _ _ with
exists_config :=
let ⟨p₁, p₂, p₃, l₁, l₂, l₃, h₁₂, h₁₃, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _
⟨l₁, l₂, l₃, p₁, p₂, p₃, h₂₁, h₃₁, h₁₂, h₂₂, h₃₂, h₁₃, h₂₃, h₃₃⟩ }
/-- The order of a projective plane is one less than the number of lines through an arbitrary point.
Equivalently, it is one less than the number of points on an arbitrary line. -/
noncomputable def order : ℕ :=
lineCount L (Classical.choose (@exists_config P L _ _)) - 1
theorem card_points_eq_card_lines [Fintype P] [Fintype L] : Fintype.card P = Fintype.card L :=
le_antisymm (HasLines.card_le P L) (HasPoints.card_le P L)
variable {P}
theorem lineCount_eq_lineCount [Finite P] [Finite L] (p q : P) : lineCount L p = lineCount L q := by
cases nonempty_fintype P
cases nonempty_fintype L
obtain ⟨p₁, p₂, p₃, l₁, l₂, l₃, h₁₂, h₁₃, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _
have h := card_points_eq_card_lines P L
let n := lineCount L p₂
have hp₂ : lineCount L p₂ = n := rfl
have hl₁ : pointCount P l₁ = n := (HasLines.lineCount_eq_pointCount h h₂₁).symm.trans hp₂
have hp₃ : lineCount L p₃ = n := (HasLines.lineCount_eq_pointCount h h₃₁).trans hl₁
have hl₃ : pointCount P l₃ = n := (HasLines.lineCount_eq_pointCount h h₃₃).symm.trans hp₃
have hp₁ : lineCount L p₁ = n := (HasLines.lineCount_eq_pointCount h h₁₃).trans hl₃
have hl₂ : pointCount P l₂ = n := (HasLines.lineCount_eq_pointCount h h₁₂).symm.trans hp₁
suffices ∀ p : P, lineCount L p = n by exact (this p).trans (this q).symm
refine fun p =>
or_not.elim (fun h₂ => ?_) fun h₂ => (HasLines.lineCount_eq_pointCount h h₂).trans hl₂
refine or_not.elim (fun h₃ => ?_) fun h₃ => (HasLines.lineCount_eq_pointCount h h₃).trans hl₃
rw [(eq_or_eq h₂ h₂₂ h₃ h₂₃).resolve_right fun h =>
h₃₃ ((congr_arg (p₃ ∈ ·) h).mp h₃₂)]
variable (P) {L}
theorem pointCount_eq_pointCount [Finite P] [Finite L] (l m : L) :
pointCount P l = pointCount P m := by
apply lineCount_eq_lineCount (Dual P)
variable {P}
theorem lineCount_eq_pointCount [Finite P] [Finite L] (p : P) (l : L) :
lineCount L p = pointCount P l :=
Exists.elim (exists_point l) fun q hq =>
(lineCount_eq_lineCount L p q).trans <| by
cases nonempty_fintype P
cases nonempty_fintype L
exact HasLines.lineCount_eq_pointCount (card_points_eq_card_lines P L) hq
variable (P L)
theorem Dual.order [Finite P] [Finite L] : order (Dual L) (Dual P) = order P L :=
congr_arg (fun n => n - 1) (lineCount_eq_pointCount _ _)
variable {P}
theorem lineCount_eq [Finite P] [Finite L] (p : P) : lineCount L p = order P L + 1 := by
classical
obtain ⟨q, -, -, l, -, -, -, -, h, -⟩ := Classical.choose_spec (@exists_config P L _ _)
cases nonempty_fintype { l : L // q ∈ l }
rw [order, lineCount_eq_lineCount L p q, lineCount_eq_lineCount L (Classical.choose _) q,
lineCount, Nat.card_eq_fintype_card, Nat.sub_add_cancel]
exact Fintype.card_pos_iff.mpr ⟨⟨l, h⟩⟩
variable (P) {L}
theorem pointCount_eq [Finite P] [Finite L] (l : L) : pointCount P l = order P L + 1 :=
(lineCount_eq (Dual P) _).trans (congr_arg (fun n => n + 1) (Dual.order P L))
variable (L)
theorem one_lt_order [Finite P] [Finite L] : 1 < order P L := by
obtain ⟨p₁, p₂, p₃, l₁, l₂, l₃, -, -, h₂₁, h₂₂, h₂₃, h₃₁, h₃₂, h₃₃⟩ := @exists_config P L _ _
cases nonempty_fintype { p : P // p ∈ l₂ }
rw [← add_lt_add_iff_right 1, ← pointCount_eq _ l₂, pointCount, Nat.card_eq_fintype_card,
Fintype.two_lt_card_iff]
simp_rw [Ne, Subtype.ext_iff]
have h := mkPoint_ax (P := P) (L := L) fun h => h₂₁ ((congr_arg (p₂ ∈ ·) h).mpr h₂₂)
exact
⟨⟨mkPoint _, h.2⟩, ⟨p₂, h₂₂⟩, ⟨p₃, h₃₂⟩, ne_of_mem_of_not_mem h.1 h₂₁,
ne_of_mem_of_not_mem h.1 h₃₁, ne_of_mem_of_not_mem h₂₃ h₃₃⟩
variable {P}
theorem two_lt_lineCount [Finite P] [Finite L] (p : P) : 2 < lineCount L p := by
simpa only [lineCount_eq L p, Nat.succ_lt_succ_iff] using one_lt_order P L
variable (P) {L}
theorem two_lt_pointCount [Finite P] [Finite L] (l : L) : 2 < pointCount P l := by
simpa only [pointCount_eq P l, Nat.succ_lt_succ_iff] using one_lt_order P L
variable (L)
theorem card_points [Fintype P] [Finite L] : Fintype.card P = order P L ^ 2 + order P L + 1 := by
cases nonempty_fintype L
obtain ⟨p, -⟩ := @exists_config P L _ _
let ϕ : { q // q ≠ p } ≃ Σ l : { l : L // p ∈ l }, { q // q ∈ l.1 ∧ q ≠ p } :=
{ toFun := fun q => ⟨⟨mkLine q.2, (mkLine_ax q.2).2⟩, q, (mkLine_ax q.2).1, q.2⟩
invFun := fun lq => ⟨lq.2, lq.2.2.2⟩
right_inv := fun lq =>
Sigma.subtype_ext
(Subtype.ext
((eq_or_eq (mkLine_ax lq.2.2.2).1 (mkLine_ax lq.2.2.2).2 lq.2.2.1 lq.1.2).resolve_left
lq.2.2.2))
rfl }
classical
have h1 : Fintype.card { q // q ≠ p } + 1 = Fintype.card P := by
apply (eq_tsub_iff_add_eq_of_le (Nat.succ_le_of_lt (Fintype.card_pos_iff.mpr ⟨p⟩))).mp
convert (Fintype.card_subtype_compl _).trans (congr_arg _ (Fintype.card_subtype_eq p))
have h2 : ∀ l : { l : L // p ∈ l }, Fintype.card { q // q ∈ l.1 ∧ q ≠ p } = order P L := by
intro l
rw [← Fintype.card_congr (Equiv.subtypeSubtypeEquivSubtypeInter (· ∈ l.val) (· ≠ p)),
Fintype.card_subtype_compl fun x : Subtype (· ∈ l.val) => x.val = p, ←
Nat.card_eq_fintype_card]
refine tsub_eq_of_eq_add ((pointCount_eq P l.1).trans ?_)
rw [← Fintype.card_subtype_eq (⟨p, l.2⟩ : { q : P // q ∈ l.1 })]
simp_rw [Subtype.ext_iff_val]
simp_rw [← h1, Fintype.card_congr ϕ, Fintype.card_sigma, h2, Finset.sum_const, Finset.card_univ]
rw [← Nat.card_eq_fintype_card, ← lineCount, lineCount_eq, smul_eq_mul, Nat.succ_mul, sq]
theorem card_lines [Finite P] [Fintype L] : Fintype.card L = order P L ^ 2 + order P L + 1 :=
(card_points (Dual L) (Dual P)).trans (congr_arg (fun n => n ^ 2 + n + 1) (Dual.order P L))
end ProjectivePlane
namespace ofField
variable {K : Type*} [Field K]
open scoped LinearAlgebra.Projectivization
open Matrix Projectivization
instance : Membership (ℙ K (Fin 3 → K)) (ℙ K (Fin 3 → K)) :=
⟨Function.swap orthogonal⟩
lemma mem_iff (v w : ℙ K (Fin 3 → K)) : v ∈ w ↔ orthogonal v w :=
Iff.rfl
-- This lemma can't be moved to the crossProduct file due to heavy imports
lemma crossProduct_eq_zero_of_dotProduct_eq_zero {a b c d : Fin 3 → K} (hac : a ⬝ᵥ c = 0)
(hbc : b ⬝ᵥ c = 0) (had : a ⬝ᵥ d = 0) (hbd : b ⬝ᵥ d = 0) :
crossProduct a b = 0 ∨ crossProduct c d = 0 := by
by_contra h
simp_rw [not_or, ← ne_eq, crossProduct_ne_zero_iff_linearIndependent] at h
rw [← Matrix.of_row (![a,b]), ← Matrix.of_row (![c,d])] at h
let A : Matrix (Fin 2) (Fin 3) K := .of ![a, b]
let B : Matrix (Fin 2) (Fin 3) K := .of ![c, d]
have hAB : A * B.transpose = 0 := by
ext i j
fin_cases i <;> fin_cases j <;> assumption
replace hAB := rank_add_rank_le_card_of_mul_eq_zero hAB
rw [rank_transpose, h.1.rank_matrix, h.2.rank_matrix, Fintype.card_fin, Fintype.card_fin] at hAB
contradiction
lemma eq_or_eq_of_orthogonal {a b c d : ℙ K (Fin 3 → K)} (hac : a.orthogonal c)
(hbc : b.orthogonal c) (had : a.orthogonal d) (hbd : b.orthogonal d) :
a = b ∨ c = d := by
induction a with | h a ha =>
induction b with | h b hb =>
induction c with | h c hc =>
induction d with | h d hd =>
rw [mk_eq_mk_iff_crossProduct_eq_zero, mk_eq_mk_iff_crossProduct_eq_zero]
exact crossProduct_eq_zero_of_dotProduct_eq_zero hac hbc had hbd
instance : Nondegenerate (ℙ K (Fin 3 → K)) (ℙ K (Fin 3 → K)) :=
{ exists_point := exists_not_orthogonal_self
exists_line := exists_not_self_orthogonal
eq_or_eq := eq_or_eq_of_orthogonal }
noncomputable instance [DecidableEq K] : ProjectivePlane (ℙ K (Fin 3 → K)) (ℙ K (Fin 3 → K)) :=
{ mkPoint := by
intro v w _
exact cross v w
mkPoint_ax := fun h ↦ ⟨cross_orthogonal_left h, cross_orthogonal_right h⟩
mkLine := by
intro v w _
exact cross v w
mkLine_ax := fun h ↦ ⟨orthogonal_cross_left h, orthogonal_cross_right h⟩
exists_config := by
refine ⟨mk K ![0, 1, 1] ?_, mk K ![1, 0, 0] ?_, mk K ![1, 0, 1] ?_, mk K ![1, 0, 0] ?_,
mk K ![0, 1, 0] ?_, mk K ![0, 0, 1] ?_, ?_⟩ <;> simp [mem_iff, orthogonal_mk] }
end ofField
end Configuration
|
Basic.lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Order.PropInstances
import Mathlib.Tactic.ByContra
import Mathlib.Tactic.Lift
import Mathlib.Tactic.Tauto
import Mathlib.Util.Delaborators
/-!
# Basic properties of sets
Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements
have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not
be decidable. The definition is in the module `Mathlib/Data/Set/Defs.lean`.
This file provides some basic definitions related to sets and functions not present in the
definitions file, as well as extra lemmas for functions defined in the definitions file and
`Mathlib/Data/Set/Operations.lean` (empty set, univ, union, intersection, insert, singleton and
powerset).
Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending
`s` to the corresponding subtype `↥s`.
See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean.
## Main definitions
Notation used here:
- `f : α → β` is a function,
- `s : Set α` and `s₁ s₂ : Set α` are subsets of `α`
- `t : Set β` is a subset of `β`.
Definitions in the file:
* `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the
fact that `s` has an element (see the Implementation Notes).
* `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`.
## Implementation notes
* `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that
the `s.Nonempty` dot notation can be used.
* For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`.
## Tags
set, sets, subset, subsets, union, intersection, insert, singleton, powerset
-/
assert_not_exists HeytingAlgebra RelIso
/-! ### Set coercion to a type -/
open Function
universe u v
namespace Set
variable {α : Type u} {s t : Set α}
instance instDistribLattice : DistribLattice (Set α) where
__ : DistribLattice (α → Prop) := inferInstance
le := (· ≤ ·)
lt := fun s t => s ⊆ t ∧ ¬t ⊆ s
sup := (· ∪ ·)
inf := (· ∩ ·)
instance instBoundedOrder : BoundedOrder (Set α) where
__ : BoundedOrder (α → Prop) := inferInstance
bot := ∅
top := univ
instance : HasSSubset (Set α) :=
⟨(· < ·)⟩
@[simp]
theorem top_eq_univ : (⊤ : Set α) = univ :=
rfl
@[simp]
theorem bot_eq_empty : (⊥ : Set α) = ∅ :=
rfl
@[simp]
theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) :=
rfl
@[simp]
theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) :=
rfl
@[simp]
theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) :=
rfl
@[simp]
theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) :=
rfl
theorem le_iff_subset : s ≤ t ↔ s ⊆ t :=
Iff.rfl
theorem lt_iff_ssubset : s < t ↔ s ⊂ t :=
Iff.rfl
alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset
alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset
instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) :
CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True :=
PiSubtype.canLift ι α s
instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) :
CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True :=
PiSetCoe.canLift ι (fun _ => α) s
end Set
section SetCoe
variable {α : Type u}
instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩
theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } :=
rfl
@[simp]
theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } :=
rfl
theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.forall
theorem SetCoe.exists {s : Set α} {p : s → Prop} :
(∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ :=
Subtype.exists
theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 :=
(@SetCoe.exists _ _ fun x => p x.1 x.2).symm
theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} :
(∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 :=
(@SetCoe.forall _ _ fun x => p x.1 x.2).symm
@[simp]
theorem set_coe_cast :
∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩
| _, _, rfl, _, _ => rfl
theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b :=
Subtype.eq
theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b :=
Iff.intro SetCoe.ext fun h => h ▸ rfl
end SetCoe
/-- See also `Subtype.prop` -/
theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s :=
p.prop
/-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/
theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t :=
fun h₁ _ h₂ => by rw [← h₁]; exact h₂
namespace Set
variable {α : Type u} {β : Type v} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α}
instance : Inhabited (Set α) :=
⟨∅⟩
@[trans]
theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t :=
h hx
@[deprecated forall_swap (since := "2025-06-10")]
theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by
tauto
theorem setOf_injective : Function.Injective (@setOf α) := injective_id
theorem setOf_inj {p q : α → Prop} : { x | p x } = { x | q x } ↔ p = q := Iff.rfl
/-! ### Lemmas about `mem` and `setOf` -/
@[deprecated "This lemma abuses the `Set α := α → Prop` defeq.
If you think you need it you have already taken a wrong turn." (since := "2025-06-10")]
theorem setOf_set {s : Set α} : setOf s = s :=
rfl
@[deprecated "This lemma abuses the `Set α := α → Prop` defeq.
If you think you need it you have already taken a wrong turn." (since := "2025-06-10")]
theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x :=
Iff.rfl
@[deprecated "This lemma abuses the `Set α := α → Prop` defeq.
If you think you need it you have already taken a wrong turn." (since := "2025-06-10")]
theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a :=
Iff.rfl
theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) :=
bijective_id
theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x :=
Iff.rfl
theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s :=
Iff.rfl
@[simp]
theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a :=
Iff.rfl
@[gcongr]
alias ⟨_, setOf_subset_setOf_of_imp⟩ := setOf_subset_setOf
theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } :=
rfl
theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } :=
rfl
/-! ### Subset and strict subset relations -/
instance : IsRefl (Set α) (· ⊆ ·) :=
show IsRefl (Set α) (· ≤ ·) by infer_instance
instance : IsTrans (Set α) (· ⊆ ·) :=
show IsTrans (Set α) (· ≤ ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) :=
show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance
instance : IsAntisymm (Set α) (· ⊆ ·) :=
show IsAntisymm (Set α) (· ≤ ·) by infer_instance
instance : IsIrrefl (Set α) (· ⊂ ·) :=
show IsIrrefl (Set α) (· < ·) by infer_instance
instance : IsTrans (Set α) (· ⊂ ·) :=
show IsTrans (Set α) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· < ·) (· < ·) (· < ·) by infer_instance
instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) :=
show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance
instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) :=
show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance
instance : IsAsymm (Set α) (· ⊂ ·) :=
show IsAsymm (Set α) (· < ·) by infer_instance
instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) :=
⟨fun _ _ => Iff.rfl⟩
-- TODO(Jeremy): write a tactic to unfold specific instances of generic notation?
@[grind =]
theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t :=
rfl
@[grind =]
theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) :=
rfl
@[refl]
theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id
theorem Subset.rfl {s : Set α} : s ⊆ s :=
Subset.refl s
@[trans]
theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h
@[trans]
theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s :=
hx.symm ▸ h
theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b :=
Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩
theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a :=
⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩
-- an alternative name
theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b :=
Subset.antisymm
@[gcongr] theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ :=
@h _
theorem notMem_subset (h : s ⊆ t) : a ∉ t → a ∉ s :=
mt <| mem_of_subset_of_mem h
@[deprecated (since := "2025-05-23")] alias not_mem_subset := notMem_subset
theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by
simp only [subset_def, not_forall, exists_prop]
theorem not_top_subset : ¬⊤ ⊆ s ↔ ∃ a, a ∉ s := by
simp [not_subset]
lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h
/-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/
protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t :=
eq_or_lt_of_le h
theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s :=
not_subset.1 h.2
protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t :=
@lt_iff_le_and_ne (Set α) _ s t
theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s :=
⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩
theorem ssubset_iff_exists {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ ∃ x ∈ t, x ∉ s :=
⟨fun h ↦ ⟨h.le, Set.exists_of_ssubset h⟩, fun ⟨h1, h2⟩ ↦ (Set.ssubset_iff_of_subset h1).mpr h2⟩
protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂)
(hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩
protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂)
(hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ :=
⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩
theorem notMem_empty (x : α) : x ∉ (∅ : Set α) :=
id
@[deprecated (since := "2025-05-23")] alias not_mem_empty := notMem_empty
theorem not_notMem : ¬a ∉ s ↔ a ∈ s :=
not_not
@[deprecated (since := "2025-05-23")] alias not_not_mem := not_notMem
/-! ### Non-empty sets -/
theorem nonempty_coe_sort {s : Set α} : Nonempty ↥s ↔ s.Nonempty :=
nonempty_subtype
alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort
theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s :=
Iff.rfl
theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty :=
⟨x, h⟩
theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅
| ⟨_, hx⟩, hs => hs hx
/-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis
on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/
protected noncomputable def Nonempty.some (h : s.Nonempty) : α :=
Classical.choose h
protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s :=
Classical.choose_spec h
@[gcongr] theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty :=
hs.imp ht
theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty :=
let ⟨x, xs, xt⟩ := not_subset.1 h
⟨x, xs, xt⟩
theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty :=
nonempty_of_not_subset ht.2
theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty :=
(nonempty_of_ssubset ht).of_diff
theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty :=
hs.imp fun _ => Or.inl
theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty :=
ht.imp fun _ => Or.inr
@[simp]
theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty :=
exists_or
theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty :=
h.imp fun _ => And.left
theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty :=
h.imp fun _ => And.right
theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t :=
Iff.rfl
theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by
simp_rw [inter_nonempty]
theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by
simp_rw [inter_nonempty, and_comm]
theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty :=
⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩
@[simp]
theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty
| ⟨x⟩ => ⟨x, trivial⟩
theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) :=
nonempty_subtype.2
theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩
instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) :=
Set.univ_nonempty.to_subtype
-- Redeclare for refined keys
-- `Nonempty (@Subtype _ (@Membership.mem _ (Set _) _ (@Top.top (Set _) _)))`
instance instNonemptyTop [Nonempty α] : Nonempty (⊤ : Set α) :=
inferInstanceAs (Nonempty (univ : Set α))
theorem Nonempty.of_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_›
/-! ### Lemmas about the empty set -/
theorem empty_def : (∅ : Set α) = { _x : α | False } :=
rfl
@[simp, grind =]
theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False :=
Iff.rfl
@[simp, grind =]
theorem setOf_false : { _a : α | False } = ∅ :=
rfl
@[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl
@[simp]
theorem empty_subset (s : Set α) : ∅ ⊆ s :=
nofun
@[simp, grind =]
theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ :=
(Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm
theorem eq_empty_iff_forall_notMem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s :=
subset_empty_iff.symm
@[deprecated (since := "2025-05-23")]
alias eq_empty_iff_forall_not_mem := eq_empty_iff_forall_notMem
theorem eq_empty_of_forall_notMem (h : ∀ x, x ∉ s) : s = ∅ :=
subset_empty_iff.1 h
@[deprecated (since := "2025-05-23")] alias eq_empty_of_forall_not_mem := eq_empty_of_forall_notMem
theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ :=
subset_empty_iff.1
theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ :=
eq_empty_of_subset_empty fun x _ => isEmptyElim x
/-- There is exactly one set of a type that is empty. -/
instance uniqueEmpty [IsEmpty α] : Unique (Set α) where
default := ∅
uniq := eq_empty_of_isEmpty
/-- See also `Set.nonempty_iff_ne_empty`. -/
theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by
simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_notMem]
/-- See also `Set.not_nonempty_iff_eq_empty`. -/
theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty.not_right
/-- See also `nonempty_iff_ne_empty'`. -/
theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by
rw [nonempty_subtype, not_exists, eq_empty_iff_forall_notMem]
/-- See also `not_nonempty_iff_eq_empty'`. -/
theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ :=
not_nonempty_iff_eq_empty'.not_right
alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty
@[simp]
theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx
@[simp]
theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ :=
not_iff_not.1 <| by simpa using nonempty_iff_ne_empty
theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty :=
or_iff_not_imp_left.2 nonempty_iff_ne_empty.2
theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ :=
subset_empty_iff.1 <| e ▸ h
theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True :=
iff_true_intro fun _ => False.elim
instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) :=
⟨fun x => x.2⟩
@[simp]
theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty :=
(@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm
alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset
/-!
### Universal set.
In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`.
Mathematically it is the same as `α` but it has a different type.
-/
@[simp, grind =]
theorem setOf_true : { _x : α | True } = univ :=
rfl
@[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl
@[simp]
theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α :=
eq_empty_iff_forall_notMem.trans
⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩
theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e =>
not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm
@[simp, grind]
theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial
@[simp, grind =]
theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ :=
@top_le_iff _ _ _ s
alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff
theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s :=
univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial
theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ :=
eq_univ_iff_forall.2
theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by
rintro ⟨x, hx⟩
exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x]
theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ :=
eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t)
theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α)
| ⟨x⟩ => ⟨x, trivial⟩
theorem ne_univ_iff_exists_notMem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by
rw [← not_forall, ← eq_univ_iff_forall]
@[deprecated (since := "2025-05-23")] alias ne_univ_iff_exists_not_mem := ne_univ_iff_exists_notMem
theorem not_subset_iff_exists_mem_notMem {α : Type*} {s t : Set α} :
¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def]
@[deprecated (since := "2025-05-23")]
alias not_subset_iff_exists_mem_not_mem := not_subset_iff_exists_mem_notMem
theorem univ_unique [Unique α] : @Set.univ α = {default} :=
Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default
theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ :=
lt_top_iff_ne_top
instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) :=
⟨⟨∅, univ, empty_ne_univ⟩⟩
/-! ### Lemmas about union -/
theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } :=
rfl
theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b :=
Or.inl
theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b :=
Or.inr
theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b :=
H
theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P)
(H₃ : x ∈ b → P) : P :=
Or.elim H₁ H₂ H₃
@[simp, grind =]
theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b :=
Iff.rfl
@[simp]
theorem union_self (a : Set α) : a ∪ a = a :=
ext fun _ => or_self_iff
@[simp]
theorem union_empty (a : Set α) : a ∪ ∅ = a :=
ext fun _ => iff_of_eq (or_false _)
@[simp]
theorem empty_union (a : Set α) : ∅ ∪ a = a :=
ext fun _ => iff_of_eq (false_or _)
theorem union_comm (a b : Set α) : a ∪ b = b ∪ a :=
ext fun _ => or_comm
theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) :=
ext fun _ => or_assoc
instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) :=
⟨union_assoc⟩
instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) :=
⟨union_comm⟩
theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) :=
ext fun _ => or_left_comm
theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ :=
ext fun _ => or_right_comm
@[simp]
theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s :=
sup_eq_left
@[simp]
theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t :=
sup_eq_right
theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t :=
union_eq_right.mpr h
theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s :=
union_eq_left.mpr h
@[simp]
theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl
@[simp]
theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr
theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ =>
Or.rec (@sr _) (@tr _)
@[simp]
theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u :=
(forall_congr' fun _ => or_imp).trans forall_and
@[gcongr]
theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) :
s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _)
theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t :=
union_subset_union h Subset.rfl
theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ :=
union_subset_union Subset.rfl h
theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_left
theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u :=
h.trans subset_union_right
theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u :=
sup_congr_left ht hu
theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u :=
sup_congr_right hs ht
theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t :=
sup_eq_sup_iff_left
theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u :=
sup_eq_sup_iff_right
@[simp]
theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by
simp only [← subset_empty_iff]
exact union_subset_iff
@[simp]
theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _
@[simp]
theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _
@[simp]
theorem ssubset_union_left_iff : s ⊂ s ∪ t ↔ ¬ t ⊆ s :=
left_lt_sup
@[simp]
theorem ssubset_union_right_iff : t ⊂ s ∪ t ↔ ¬ s ⊆ t :=
right_lt_sup
/-! ### Lemmas about intersection -/
theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } :=
rfl
@[simp, mfld_simps, grind =]
theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b :=
Iff.rfl
theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b :=
⟨ha, hb⟩
theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a :=
h.left
theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b :=
h.right
@[simp]
theorem inter_self (a : Set α) : a ∩ a = a :=
ext fun _ => and_self_iff
@[simp]
theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ :=
ext fun _ => iff_of_eq (and_false _)
@[simp]
theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ :=
ext fun _ => iff_of_eq (false_and _)
theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a :=
ext fun _ => and_comm
theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) :=
ext fun _ => and_assoc
instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) :=
⟨inter_assoc⟩
instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) :=
⟨inter_comm⟩
theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) :=
ext fun _ => and_left_comm
theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ :=
ext fun _ => and_right_comm
@[simp, mfld_simps]
theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left
@[simp]
theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right
theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h =>
⟨rs h, rt h⟩
@[simp]
theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t :=
(forall_congr' fun _ => imp_and).trans forall_and
@[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left
@[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right
@[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf
@[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf
theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s :=
inter_eq_left.mpr
theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t :=
inter_eq_right.mpr
theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u :=
inf_congr_left ht hu
theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u :=
inf_congr_right hs ht
theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u :=
inf_eq_inf_iff_left
theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t :=
inf_eq_inf_iff_right
@[simp, mfld_simps]
theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _
@[simp, mfld_simps]
theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _
@[gcongr]
theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) :
s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _)
theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u :=
inter_subset_inter H Subset.rfl
theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t :=
inter_subset_inter Subset.rfl H
theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s :=
inter_eq_self_of_subset_right subset_union_left
theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t :=
inter_eq_self_of_subset_right subset_union_right
theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} :=
rfl
theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} :=
inter_comm _ _
@[simp]
theorem inter_ssubset_right_iff : s ∩ t ⊂ t ↔ ¬ t ⊆ s :=
inf_lt_right
@[simp]
theorem inter_ssubset_left_iff : s ∩ t ⊂ s ↔ ¬ s ⊆ t :=
inf_lt_left
/-! ### Distributivity laws -/
theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u :=
inf_sup_left _ _ _
theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u :=
inf_sup_right _ _ _
theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) :=
sup_inf_left _ _ _
theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) :=
sup_inf_right _ _ _
theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) :=
sup_sup_distrib_left _ _ _
theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) :=
sup_sup_distrib_right _ _ _
theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) :=
inf_inf_distrib_left _ _ _
theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) :=
inf_inf_distrib_right _ _ _
theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) :=
sup_sup_sup_comm _ _ _ _
theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) :=
inf_inf_inf_comm _ _ _ _
/-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/
section Sep
variable {p q : α → Prop} {x : α}
theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } :=
⟨xs, px⟩
@[simp]
theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t :=
rfl
@[simp]
theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x :=
Iff.rfl
theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_congr_right_iff]
theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s :=
inter_eq_self_of_subset_right h
@[simp]
theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left
theorem sep_subset_setOf (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ { x | p x } :=
fun _ => And.right
@[simp]
theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by
simp_rw [Set.ext_iff, mem_sep_iff, and_iff_left_iff_imp]
@[simp]
theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by
simp_rw [Set.ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false, not_and]
theorem sep_true : { x ∈ s | True } = s :=
inter_univ s
theorem sep_false : { x ∈ s | False } = ∅ :=
inter_empty s
theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ :=
empty_inter {x | p x}
theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } :=
univ_inter {x | p x}
@[simp]
theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } :=
union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p
@[simp]
theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } :=
inter_inter_distrib_right s t {x | p x}
@[simp]
theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } :=
inter_inter_distrib_left s {x | p x} {x | q x}
@[simp]
theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } :=
inter_union_distrib_left s p q
@[simp]
theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } :=
rfl
end Sep
/-! ### Powerset -/
theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h
theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h
@[simp, grind =]
theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s :=
Iff.rfl
theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t :=
ext fun _ => subset_inter_iff
@[simp]
theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t :=
⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩
theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2
@[simp]
theorem powerset_nonempty : (𝒫 s).Nonempty :=
⟨∅, fun _ h => empty_subset s h⟩
@[simp]
theorem powerset_empty : 𝒫(∅ : Set α) = {∅} :=
ext fun _ => subset_empty_iff
@[simp]
theorem powerset_univ : 𝒫(univ : Set α) = univ :=
eq_univ_of_forall subset_univ
/-! ### Sets defined as an if-then-else -/
theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by
simp [mem_dite]
@[simp]
theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t Set.univ ↔ p → x ∈ t :=
mem_dite_univ_right p (fun _ => t) x
theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by
split_ifs <;> simp_all
@[simp]
theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p Set.univ t ↔ ¬p → x ∈ t :=
mem_dite_univ_left p (fun _ => t) x
theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) :
(x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false, not_not]
exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩
@[simp]
theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p t ∅ ↔ p ∧ x ∈ t :=
(mem_dite_empty_right p (fun _ => t) x).trans (by simp)
theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) :
(x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by
simp only [mem_dite, mem_empty_iff_false, imp_false]
exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩
@[simp]
theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) :
x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t :=
(mem_dite_empty_left p (fun _ => t) x).trans (by simp)
end Set
open Set
namespace Function
variable {α : Type*} {β : Type*}
theorem Injective.nonempty_apply_iff {f : Set α → Set β} (hf : Injective f) (h2 : f ∅ = ∅)
{s : Set α} : (f s).Nonempty ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, ← h2, nonempty_iff_ne_empty, hf.ne_iff]
end Function
namespace Subsingleton
variable {α : Type*} [Subsingleton α]
theorem eq_univ_of_nonempty {s : Set α} : s.Nonempty → s = univ := fun ⟨x, hx⟩ =>
eq_univ_of_forall fun y => Subsingleton.elim x y ▸ hx
@[elab_as_elim]
theorem set_cases {p : Set α → Prop} (h0 : p ∅) (h1 : p univ) (s) : p s :=
(s.eq_empty_or_nonempty.elim fun h => h.symm ▸ h0) fun h => (eq_univ_of_nonempty h).symm ▸ h1
theorem mem_iff_nonempty {α : Type*} [Subsingleton α] {s : Set α} {x : α} : x ∈ s ↔ s.Nonempty :=
⟨fun hx => ⟨x, hx⟩, fun ⟨y, hy⟩ => Subsingleton.elim y x ▸ hy⟩
end Subsingleton
/-! ### Decidability instances for sets -/
namespace Set
variable {α : Type u} (s t : Set α) (a b : α)
instance decidableSdiff [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s \ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∉ t))
instance decidableInter [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∩ t) :=
inferInstanceAs (Decidable (a ∈ s ∧ a ∈ t))
instance decidableUnion [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∪ t) :=
inferInstanceAs (Decidable (a ∈ s ∨ a ∈ t))
instance decidableCompl [Decidable (a ∈ s)] : Decidable (a ∈ sᶜ) :=
inferInstanceAs (Decidable (a ∉ s))
instance decidableEmptyset : Decidable (a ∈ (∅ : Set α)) := Decidable.isFalse (by simp)
instance decidableUniv : Decidable (a ∈ univ) := Decidable.isTrue (by simp)
instance decidableInsert [Decidable (a = b)] [Decidable (a ∈ s)] : Decidable (a ∈ insert b s) :=
inferInstanceAs (Decidable (_ ∨ _))
instance decidableSetOf (p : α → Prop) [Decidable (p a)] : Decidable (a ∈ { a | p a }) := by
assumption
end Set
variable {α : Type*} {s t u : Set α}
namespace Equiv
/-- Given a predicate `p : α → Prop`, produces an equivalence between
`Set {a : α // p a}` and `{s : Set α // ∀ a ∈ s, p a}`. -/
protected def setSubtypeComm (p : α → Prop) :
Set {a : α // p a} ≃ {s : Set α // ∀ a ∈ s, p a} where
toFun s := ⟨{a | ∃ h : p a, s ⟨a, h⟩}, fun _ h ↦ h.1⟩
invFun s := {a | a.val ∈ s.val}
left_inv s := by ext a; exact ⟨fun h ↦ h.2, fun h ↦ ⟨a.property, h⟩⟩
right_inv s := by ext; exact ⟨fun h ↦ h.2, fun h ↦ ⟨s.property _ h, h⟩⟩
@[simp]
protected lemma setSubtypeComm_apply (p : α → Prop) (s : Set {a // p a}) :
(Equiv.setSubtypeComm p) s = ⟨{a | ∃ h : p a, ⟨a, h⟩ ∈ s}, fun _ h ↦ h.1⟩ :=
rfl
@[simp]
protected lemma setSubtypeComm_symm_apply (p : α → Prop) (s : {s // ∀ a ∈ s, p a}) :
(Equiv.setSubtypeComm p).symm s = {a | a.val ∈ s.val} :=
rfl
end Equiv
|
SmoothApprox.lean
|
/-
Copyright (c) 2025 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.BumpFunction.Convolution
import Mathlib.Analysis.Calculus.BumpFunction.FiniteDimension
/-!
# Density of smooth functions in the space of continuous functions
In this file we prove that smooth functions are dense in the set of continuous functions
from a real finite dimensional vector space to a Banach space,
see `ContinuousMap.dense_setOf_contDiff`.
We also prove several unbundled versions of this statement.
The heavy part of the proof is done upstream in `ContDiffBump.dist_normed_convolution_le`
and `HasCompactSupport.contDiff_convolution_left`.
Here we wrap these results removing measure-related arguments from the assumptions.
-/
variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E]
[NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {f : E → F} {ε : ℝ}
open scoped ContDiff unitInterval Topology
open Function Set Metric MeasureTheory
theorem MeasureTheory.LocallyIntegrable.exists_contDiff_dist_le_of_forall_mem_ball_dist_le
[MeasurableSpace E] [BorelSpace E] {μ : Measure E} [μ.IsAddHaarMeasure]
(hf : LocallyIntegrable f μ) (hε : 0 < ε) :
∃ g : E → F, ContDiff ℝ ∞ g ∧ ∀ a, ∀ δ, (∀ x ∈ ball a ε, dist (f x) (f a) ≤ δ) →
dist (g a) (f a) ≤ δ := by
set φ : ContDiffBump (0 : E) := ⟨ε / 2, ε, half_pos hε, half_lt_self hε⟩
refine ⟨_, ?_, fun a δ ↦ φ.dist_normed_convolution_le hf.aestronglyMeasurable⟩
exact φ.hasCompactSupport_normed.contDiff_convolution_left _ φ.contDiff_normed hf
theorem Continuous.exists_contDiff_dist_le_of_forall_mem_ball_dist_le (hf : Continuous f)
(hε : 0 < ε) :
∃ g : E → F, ContDiff ℝ ∞ g ∧ ∀ a, ∀ δ, (∀ x ∈ ball a ε, dist (f x) (f a) ≤ δ) →
dist (g a) (f a) ≤ δ := by
borelize E
exact (hf.locallyIntegrable (μ := .addHaar)).exists_contDiff_dist_le_of_forall_mem_ball_dist_le hε
theorem UniformContinuous.exists_contDiff_dist_le (hf : UniformContinuous f) (hε : 0 < ε) :
∃ g : E → F, ContDiff ℝ ∞ g ∧ ∀ a, dist (g a) (f a) < ε := by
rcases Metric.uniformContinuous_iff.mp hf (ε / 2) (half_pos hε) with ⟨δ, hδ, hfδ⟩
rcases hf.continuous.exists_contDiff_dist_le_of_forall_mem_ball_dist_le hδ with ⟨g, hgc, hg⟩
exact ⟨g, hgc, fun a ↦ (hg a _ fun _ h ↦ (hfδ h).le).trans_lt (half_lt_self hε)⟩
/-- Infinitely smooth functions are dense in the space of continuous functions. -/
theorem ContinuousMap.dense_setOf_contDiff : Dense {f : C(E, F) | ContDiff ℝ ∞ f} := by
intro f
rw [mem_closure_iff_nhds_basis
(nhds_basis_uniformity uniformity_basis_dist.compactConvergenceUniformity)]
simp only [Prod.forall, mem_setOf_eq, and_imp]
intro K ε hK hε
have : UniformContinuousOn f (cthickening 1 K) :=
hK.cthickening.uniformContinuousOn_of_continuous <| by fun_prop
rcases Metric.uniformContinuousOn_iff.mp this (ε / 2) (half_pos hε) with ⟨δ, hδ, hfδ⟩
rcases (map_continuous f).exists_contDiff_dist_le_of_forall_mem_ball_dist_le
(lt_min one_pos hδ) with ⟨g, hgc, hg⟩
refine ⟨⟨g, hgc.continuous⟩, hgc, fun x hx ↦ (hg _ _ fun y hy ↦ ?_).trans_lt (half_lt_self hε)⟩
rw [mem_ball, lt_min_iff] at hy
exact hfδ _ (mem_cthickening_of_dist_le _ x _ _ hx hy.1.le) _
(self_subset_cthickening _ hx) hy.2 |>.le
|
Similarity.lean
|
/-
Copyright (c) 2024 Jovan Gerbscheid. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jovan Gerbscheid, Newell Jensen
-/
import Mathlib.Topology.MetricSpace.Congruence
/-!
# Similarities
This file defines `Similar`, i.e., the equivalence between indexed sets of points in a metric space
where all corresponding pairwise distances have the same ratio. The motivating example is
triangles in the plane.
## Implementation notes
For more details see the [Zulip discussion](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Euclidean.20Geometry).
## Notation
Let `P₁` and `P₂` be metric spaces, let `ι` be an index set, and let `v₁ : ι → P₁` and
`v₂ : ι → P₂` be indexed families of points.
* `(v₁ ∼ v₂ : Prop)` represents that `(v₁ : ι → P₁)` and `(v₂ : ι → P₂)` are similar.
-/
open scoped NNReal
variable {ι ι' : Type*} {P₁ P₂ P₃ : Type*} {v₁ : ι → P₁} {v₂ : ι → P₂} {v₃ : ι → P₃}
section PseudoEMetricSpace
variable [PseudoEMetricSpace P₁] [PseudoEMetricSpace P₂] [PseudoEMetricSpace P₃]
/-- Similarity between indexed sets of vertices v₁ and v₂.
Use `open scoped Similar` to access the `v₁ ∼ v₂` notation. -/
def Similar (v₁ : ι → P₁) (v₂ : ι → P₂) : Prop :=
∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (edist (v₁ i₁) (v₁ i₂) = r * edist (v₂ i₁) (v₂ i₂))
@[inherit_doc]
scoped[Similar] infixl:25 " ∼ " => Similar
/-- Similarity holds if and only if all extended distances are proportional. -/
lemma similar_iff_exists_edist_eq :
Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (edist (v₁ i₁) (v₁ i₂) =
r * edist (v₂ i₁) (v₂ i₂))) :=
Iff.rfl
/-- Similarity holds if and only if all extended distances between points with different
indices are proportional. -/
lemma similar_iff_exists_pairwise_edist_eq :
Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ Pairwise fun i₁ i₂ ↦ (edist (v₁ i₁) (v₁ i₂) =
r * edist (v₂ i₁) (v₂ i₂))) := by
rw [similar_iff_exists_edist_eq]
refine ⟨?_, ?_⟩ <;> rintro ⟨r, hr, h⟩ <;> refine ⟨r, hr, fun i₁ i₂ ↦ ?_⟩
· exact fun _ ↦ h i₁ i₂
· by_cases hi : i₁ = i₂
· simp [hi]
· exact h hi
lemma Congruent.similar {v₁ : ι → P₁} {v₂ : ι → P₂} (h : Congruent v₁ v₂) : Similar v₁ v₂ :=
⟨1, one_ne_zero, fun i₁ i₂ ↦ by simpa using h i₁ i₂⟩
namespace Similar
/-- A similarity scales extended distance. Forward direction of `similar_iff_exists_edist_eq`. -/
alias ⟨exists_edist_eq, _⟩ := similar_iff_exists_edist_eq
/-- Similarity follows from scaled extended distance. Backward direction of
`similar_iff_exists_edist_eq`. -/
alias ⟨_, of_exists_edist_eq⟩ := similar_iff_exists_edist_eq
/-- A similarity pairwise scales extended distance. Forward direction of
`similar_iff_exists_pairwise_edist_eq`. -/
alias ⟨exists_pairwise_edist_eq, _⟩ := similar_iff_exists_pairwise_edist_eq
/-- Similarity follows from pairwise scaled extended distance. Backward direction of
`similar_iff_exists_pairwise_edist_eq`. -/
alias ⟨_, of_exists_pairwise_edist_eq⟩ := similar_iff_exists_pairwise_edist_eq
@[refl] protected lemma refl (v₁ : ι → P₁) : v₁ ∼ v₁ :=
⟨1, one_ne_zero, fun _ _ => by {norm_cast; rw [one_mul]}⟩
@[symm] protected lemma symm (h : v₁ ∼ v₂) : v₂ ∼ v₁ := by
rcases h with ⟨r, hr, h⟩
refine ⟨r⁻¹, inv_ne_zero hr, fun _ _ => ?_⟩
rw [ENNReal.coe_inv hr, ← ENNReal.div_eq_inv_mul, ENNReal.eq_div_iff _ ENNReal.coe_ne_top, h]
norm_cast
lemma _root_.similar_comm : v₁ ∼ v₂ ↔ v₂ ∼ v₁ := ⟨Similar.symm, Similar.symm⟩
@[trans] protected lemma trans (h₁ : v₁ ∼ v₂) (h₂ : v₂ ∼ v₃) : v₁ ∼ v₃ := by
rcases h₁ with ⟨r₁, hr₁, h₁⟩; rcases h₂ with ⟨r₂, hr₂, h₂⟩
refine ⟨r₁ * r₂, mul_ne_zero hr₁ hr₂, fun _ _ => ?_⟩
rw [ENNReal.coe_mul, mul_assoc, h₁, h₂]
/-- Change the index set ι to an index ι' that maps to ι. -/
lemma index_map (h : v₁ ∼ v₂) (f : ι' → ι) : (v₁ ∘ f) ∼ (v₂ ∘ f) := by
rcases h with ⟨r, hr, h⟩
refine ⟨r, hr, fun _ _ => ?_⟩
apply h
/-- Change between equivalent index sets ι and ι'. -/
@[simp]
lemma index_equiv (f : ι' ≃ ι) (v₁ : ι → P₁) (v₂ : ι → P₂) :
v₁ ∘ f ∼ v₂ ∘ f ↔ v₁ ∼ v₂ := by
refine ⟨fun h => ?_, fun h => Similar.index_map h f⟩
rcases h with ⟨r, hr, h⟩
refine ⟨r, hr, fun i₁ i₂ => ?_⟩
simpa [f.right_inv i₁, f.right_inv i₂] using h (f.symm i₁) (f.symm i₂)
end Similar
end PseudoEMetricSpace
section PseudoMetricSpace
variable [PseudoMetricSpace P₁] [PseudoMetricSpace P₂]
/-- Similarity holds if and only if all non-negative distances are proportional. -/
lemma similar_iff_exists_nndist_eq :
Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (nndist (v₁ i₁) (v₁ i₂) =
r * nndist (v₂ i₁) (v₂ i₂))) :=
exists_congr <| fun _ => and_congr Iff.rfl <| forall₂_congr <|
fun _ _ => by { rw [edist_nndist, edist_nndist]; norm_cast }
/-- Similarity holds if and only if all non-negative distances between points with different
indices are proportional. -/
lemma similar_iff_exists_pairwise_nndist_eq :
Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ Pairwise fun i₁ i₂ ↦ (nndist (v₁ i₁) (v₁ i₂) =
r * nndist (v₂ i₁) (v₂ i₂))) := by
simp_rw [similar_iff_exists_pairwise_edist_eq, edist_nndist]
exact_mod_cast Iff.rfl
/-- Similarity holds if and only if all distances are proportional. -/
lemma similar_iff_exists_dist_eq :
Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ ∀ (i₁ i₂ : ι), (dist (v₁ i₁) (v₁ i₂) =
r * dist (v₂ i₁) (v₂ i₂))) :=
similar_iff_exists_nndist_eq.trans
(exists_congr <| fun _ => and_congr Iff.rfl <| forall₂_congr <|
fun _ _ => by { rw [dist_nndist, dist_nndist]; norm_cast })
/-- Similarity holds if and only if all distances between points with different indices are
proportional. -/
lemma similar_iff_exists_pairwise_dist_eq :
Similar v₁ v₂ ↔ (∃ r : ℝ≥0, r ≠ 0 ∧ Pairwise fun i₁ i₂ ↦ (dist (v₁ i₁) (v₁ i₂) =
r * dist (v₂ i₁) (v₂ i₂))) := by
simp_rw [similar_iff_exists_pairwise_nndist_eq, dist_nndist]
exact_mod_cast Iff.rfl
namespace Similar
/-- A similarity scales non-negative distance. Forward direction of
`similar_iff_exists_nndist_eq`. -/
alias ⟨exists_nndist_eq, _⟩ := similar_iff_exists_nndist_eq
/-- Similarity follows from scaled non-negative distance. Backward direction of
`similar_iff_exists_nndist_eq`. -/
alias ⟨_, of_exists_nndist_eq⟩ := similar_iff_exists_nndist_eq
/-- A similarity scales distance. Forward direction of `similar_iff_exists_dist_eq`. -/
alias ⟨exists_dist_eq, _⟩ := similar_iff_exists_dist_eq
/-- Similarity follows from scaled distance. Backward direction of
`similar_iff_exists_dist_eq`. -/
alias ⟨_, of_exists_dist_eq⟩ := similar_iff_exists_dist_eq
/-- A similarity pairwise scales non-negative distance. Forward direction of
`similar_iff_exists_pairwise_nndist_eq`. -/
alias ⟨exists_pairwise_nndist_eq, _⟩ := similar_iff_exists_pairwise_nndist_eq
/-- Similarity follows from pairwise scaled non-negative distance. Backward direction of
`similar_iff_exists_pairwise_nndist_eq`. -/
alias ⟨_, of_exists_pairwise_nndist_eq⟩ := similar_iff_exists_pairwise_nndist_eq
/-- A similarity pairwise scales distance. Forward direction of
`similar_iff_exists_pairwise_dist_eq`. -/
alias ⟨exists_pairwise_dist_eq, _⟩ := similar_iff_exists_pairwise_dist_eq
/-- Similarity follows from pairwise scaled distance. Backward direction of
`similar_iff_exists_pairwise_dist_eq`. -/
alias ⟨_, of_exists_pairwise_dist_eq⟩ := similar_iff_exists_pairwise_dist_eq
end Similar
end PseudoMetricSpace
|
NhdsSet.lean
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Topology.Order.Basic
/-!
# Set neighborhoods of intervals
In this file we prove basic theorems about `𝓝ˢ s`,
where `s` is one of the intervals
`Set.Ici`, `Set.Iic`, `Set.Ioi`, `Set.Iio`, `Set.Ico`, `Set.Ioc`, `Set.Ioo`, and `Set.Icc`.
First, we prove lemmas in terms of filter equalities.
Then we prove lemmas about `s ∈ 𝓝ˢ t`, where both `s` and `t` are intervals.
Finally, we prove a few lemmas about filter bases of `𝓝ˢ (Iic a)` and `𝓝ˢ (Ici a)`.
-/
open Set Filter OrderDual
open scoped Topology
section OrderClosedTopology
variable {α : Type*} [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] {a b c d : α}
/-!
# Formulae for `𝓝ˢ` of intervals
-/
@[simp] theorem nhdsSet_Ioi : 𝓝ˢ (Ioi a) = 𝓟 (Ioi a) := isOpen_Ioi.nhdsSet_eq
@[simp] theorem nhdsSet_Iio : 𝓝ˢ (Iio a) = 𝓟 (Iio a) := isOpen_Iio.nhdsSet_eq
@[simp] theorem nhdsSet_Ioo : 𝓝ˢ (Ioo a b) = 𝓟 (Ioo a b) := isOpen_Ioo.nhdsSet_eq
theorem nhdsSet_Ici : 𝓝ˢ (Ici a) = 𝓝 a ⊔ 𝓟 (Ioi a) := by
rw [← Ioi_insert, nhdsSet_insert, nhdsSet_Ioi]
theorem nhdsSet_Iic : 𝓝ˢ (Iic a) = 𝓝 a ⊔ 𝓟 (Iio a) := nhdsSet_Ici (α := αᵒᵈ)
theorem nhdsSet_Ico (h : a < b) : 𝓝ˢ (Ico a b) = 𝓝 a ⊔ 𝓟 (Ioo a b) := by
rw [← Ioo_insert_left h, nhdsSet_insert, nhdsSet_Ioo]
theorem nhdsSet_Ioc (h : a < b) : 𝓝ˢ (Ioc a b) = 𝓝 b ⊔ 𝓟 (Ioo a b) := by
rw [← Ioo_insert_right h, nhdsSet_insert, nhdsSet_Ioo]
theorem nhdsSet_Icc (h : a ≤ b) : 𝓝ˢ (Icc a b) = 𝓝 a ⊔ 𝓝 b ⊔ 𝓟 (Ioo a b) := by
rcases h.eq_or_lt with rfl | hlt
· simp
· rw [← Ioc_insert_left h, nhdsSet_insert, nhdsSet_Ioc hlt, sup_assoc]
/-!
### Lemmas about `Ixi _ ∈ 𝓝ˢ (Set.Ici _)`
-/
@[simp]
theorem Ioi_mem_nhdsSet_Ici_iff : Ioi a ∈ 𝓝ˢ (Ici b) ↔ a < b := by
rw [isOpen_Ioi.mem_nhdsSet, Ici_subset_Ioi]
alias ⟨_, Ioi_mem_nhdsSet_Ici⟩ := Ioi_mem_nhdsSet_Ici_iff
theorem Ici_mem_nhdsSet_Ici (h : a < b) : Ici a ∈ 𝓝ˢ (Ici b) :=
mem_of_superset (Ioi_mem_nhdsSet_Ici h) Ioi_subset_Ici_self
/-!
### Lemmas about `Iix _ ∈ 𝓝ˢ (Set.Iic _)`
-/
theorem Iio_mem_nhdsSet_Iic_iff : Iio b ∈ 𝓝ˢ (Iic a) ↔ a < b :=
Ioi_mem_nhdsSet_Ici_iff (α := αᵒᵈ)
alias ⟨_, Iio_mem_nhdsSet_Iic⟩ := Iio_mem_nhdsSet_Iic_iff
theorem Iic_mem_nhdsSet_Iic (h : a < b) : Iic b ∈ 𝓝ˢ (Iic a) :=
Ici_mem_nhdsSet_Ici (α := αᵒᵈ) h
/-!
### Lemmas about `Ixx _ ?_ ∈ 𝓝ˢ (Set.Icc _ _)`
-/
theorem Ioi_mem_nhdsSet_Icc (h : a < b) : Ioi a ∈ 𝓝ˢ (Icc b c) :=
nhdsSet_mono Icc_subset_Ici_self <| Ioi_mem_nhdsSet_Ici h
theorem Ici_mem_nhdsSet_Icc (h : a < b) : Ici a ∈ 𝓝ˢ (Icc b c) :=
mem_of_superset (Ioi_mem_nhdsSet_Icc h) Ioi_subset_Ici_self
theorem Iio_mem_nhdsSet_Icc (h : b < c) : Iio c ∈ 𝓝ˢ (Icc a b) :=
nhdsSet_mono Icc_subset_Iic_self <| Iio_mem_nhdsSet_Iic h
theorem Iic_mem_nhdsSet_Icc (h : b < c) : Iic c ∈ 𝓝ˢ (Icc a b) :=
mem_of_superset (Iio_mem_nhdsSet_Icc h) Iio_subset_Iic_self
theorem Ioo_mem_nhdsSet_Icc (h : a < b) (h' : c < d) : Ioo a d ∈ 𝓝ˢ (Icc b c) :=
inter_mem (Ioi_mem_nhdsSet_Icc h) (Iio_mem_nhdsSet_Icc h')
theorem Ico_mem_nhdsSet_Icc (h : a < b) (h' : c < d) : Ico a d ∈ 𝓝ˢ (Icc b c) :=
inter_mem (Ici_mem_nhdsSet_Icc h) (Iio_mem_nhdsSet_Icc h')
theorem Ioc_mem_nhdsSet_Icc (h : a < b) (h' : c < d) : Ioc a d ∈ 𝓝ˢ (Icc b c) :=
inter_mem (Ioi_mem_nhdsSet_Icc h) (Iic_mem_nhdsSet_Icc h')
theorem Icc_mem_nhdsSet_Icc (h : a < b) (h' : c < d) : Icc a d ∈ 𝓝ˢ (Icc b c) :=
inter_mem (Ici_mem_nhdsSet_Icc h) (Iic_mem_nhdsSet_Icc h')
/-!
### Lemmas about `Ixx _ ?_ ∈ 𝓝ˢ (Set.Ico _ _)`
-/
theorem Ici_mem_nhdsSet_Ico (h : a < b) : Ici a ∈ 𝓝ˢ (Ico b c) :=
nhdsSet_mono Ico_subset_Icc_self <| Ici_mem_nhdsSet_Icc h
theorem Ioi_mem_nhdsSet_Ico (h : a < b) : Ioi a ∈ 𝓝ˢ (Ico b c) :=
nhdsSet_mono Ico_subset_Icc_self <| Ioi_mem_nhdsSet_Icc h
theorem Iio_mem_nhdsSet_Ico (h : b ≤ c) : Iio c ∈ 𝓝ˢ (Ico a b) :=
nhdsSet_mono Ico_subset_Iio_self <| by simpa
theorem Iic_mem_nhdsSet_Ico (h : b ≤ c) : Iic c ∈ 𝓝ˢ (Ico a b) :=
mem_of_superset (Iio_mem_nhdsSet_Ico h) Iio_subset_Iic_self
theorem Ioo_mem_nhdsSet_Ico (h : a < b) (h' : c ≤ d) : Ioo a d ∈ 𝓝ˢ (Ico b c) :=
inter_mem (Ioi_mem_nhdsSet_Ico h) (Iio_mem_nhdsSet_Ico h')
theorem Icc_mem_nhdsSet_Ico (h : a < b) (h' : c ≤ d) : Icc a d ∈ 𝓝ˢ (Ico b c) :=
inter_mem (Ici_mem_nhdsSet_Ico h) (Iic_mem_nhdsSet_Ico h')
theorem Ioc_mem_nhdsSet_Ico (h : a < b) (h' : c ≤ d) : Ioc a d ∈ 𝓝ˢ (Ico b c) :=
inter_mem (Ioi_mem_nhdsSet_Ico h) (Iic_mem_nhdsSet_Ico h')
theorem Ico_mem_nhdsSet_Ico (h : a < b) (h' : c ≤ d) : Ico a d ∈ 𝓝ˢ (Ico b c) :=
inter_mem (Ici_mem_nhdsSet_Ico h) (Iio_mem_nhdsSet_Ico h')
/-!
### Lemmas about `Ixx _ ?_ ∈ 𝓝ˢ (Set.Ioc _ _)`
-/
theorem Ioi_mem_nhdsSet_Ioc (h : a ≤ b) : Ioi a ∈ 𝓝ˢ (Ioc b c) :=
nhdsSet_mono Ioc_subset_Ioi_self <| by simpa
theorem Iio_mem_nhdsSet_Ioc (h : b < c) : Iio c ∈ 𝓝ˢ (Ioc a b) :=
nhdsSet_mono Ioc_subset_Icc_self <| Iio_mem_nhdsSet_Icc h
theorem Ici_mem_nhdsSet_Ioc (h : a ≤ b) : Ici a ∈ 𝓝ˢ (Ioc b c) :=
mem_of_superset (Ioi_mem_nhdsSet_Ioc h) Ioi_subset_Ici_self
theorem Iic_mem_nhdsSet_Ioc (h : b < c) : Iic c ∈ 𝓝ˢ (Ioc a b) :=
nhdsSet_mono Ioc_subset_Icc_self <| Iic_mem_nhdsSet_Icc h
theorem Ioo_mem_nhdsSet_Ioc (h : a ≤ b) (h' : c < d) : Ioo a d ∈ 𝓝ˢ (Ioc b c) :=
inter_mem (Ioi_mem_nhdsSet_Ioc h) (Iio_mem_nhdsSet_Ioc h')
theorem Icc_mem_nhdsSet_Ioc (h : a ≤ b) (h' : c < d) : Icc a d ∈ 𝓝ˢ (Ioc b c) :=
inter_mem (Ici_mem_nhdsSet_Ioc h) (Iic_mem_nhdsSet_Ioc h')
theorem Ioc_mem_nhdsSet_Ioc (h : a ≤ b) (h' : c < d) : Ioc a d ∈ 𝓝ˢ (Ioc b c) :=
inter_mem (Ioi_mem_nhdsSet_Ioc h) (Iic_mem_nhdsSet_Ioc h')
theorem Ico_mem_nhdsSet_Ioc (h : a ≤ b) (h' : c < d) : Ico a d ∈ 𝓝ˢ (Ioc b c) :=
inter_mem (Ici_mem_nhdsSet_Ioc h) (Iio_mem_nhdsSet_Ioc h')
end OrderClosedTopology
/-!
### Filter bases of `𝓝ˢ (Iic a)` and `𝓝ˢ (Ici a)`
-/
variable {α : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
theorem hasBasis_nhdsSet_Iic_Iio (a : α) [h : Nonempty (Ioi a)] :
HasBasis (𝓝ˢ (Iic a)) (a < ·) Iio := by
refine ⟨fun s ↦ ⟨fun hs ↦ ?_, fun ⟨b, hab, hb⟩ ↦ mem_of_superset (Iio_mem_nhdsSet_Iic hab) hb⟩⟩
rw [nhdsSet_Iic, mem_sup, mem_principal] at hs
rcases exists_Ico_subset_of_mem_nhds hs.1 (Set.nonempty_coe_sort.1 h) with ⟨b, hab, hbs⟩
exact ⟨b, hab, Iio_subset_Iio_union_Ico.trans (union_subset hs.2 hbs)⟩
theorem hasBasis_nhdsSet_Iic_Iic (a : α) [NeBot (𝓝[>] a)] :
HasBasis (𝓝ˢ (Iic a)) (a < ·) Iic := by
have : Nonempty (Ioi a) :=
(Filter.nonempty_of_mem (self_mem_nhdsWithin : Ioi a ∈ 𝓝[>] a)).to_subtype
refine (hasBasis_nhdsSet_Iic_Iio _).to_hasBasis
(fun c hc ↦ ?_) (fun _ h ↦ ⟨_, h, Iio_subset_Iic_self⟩)
simpa only [Iic_subset_Iio] using Filter.nonempty_of_mem (Ioo_mem_nhdsGT hc)
@[simp]
theorem Iic_mem_nhdsSet_Iic_iff {a b : α} [NeBot (𝓝[>] b)] : Iic a ∈ 𝓝ˢ (Iic b) ↔ b < a :=
(hasBasis_nhdsSet_Iic_Iic b).mem_iff.trans
⟨fun ⟨_c, hbc, hca⟩ ↦ hbc.trans_le (Iic_subset_Iic.1 hca), fun h ↦ ⟨_, h, Subset.rfl⟩⟩
theorem hasBasis_nhdsSet_Ici_Ioi (a : α) [Nonempty (Iio a)] :
HasBasis (𝓝ˢ (Ici a)) (· < a) Ioi :=
have : Nonempty (Ioi (toDual a)) := ‹_›; hasBasis_nhdsSet_Iic_Iio (toDual a)
theorem hasBasis_nhdsSet_Ici_Ici (a : α) [NeBot (𝓝[<] a)] :
HasBasis (𝓝ˢ (Ici a)) (· < a) Ici :=
have : NeBot (𝓝[>] (toDual a)) := ‹_›; hasBasis_nhdsSet_Iic_Iic (toDual a)
@[simp]
theorem Ici_mem_nhdsSet_Ici_iff {a b : α} [NeBot (𝓝[<] b)] : Ici a ∈ 𝓝ˢ (Ici b) ↔ a < b :=
have : NeBot (𝓝[>] (toDual b)) := ‹_›; Iic_mem_nhdsSet_Iic_iff (a := toDual a) (b := toDual b)
|
CoherentSheaves.lean
|
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Sites.Canonical
import Mathlib.CategoryTheory.Sites.Coherent.Basic
import Mathlib.CategoryTheory.Sites.EffectiveEpimorphic
/-!
# Sheaves for the coherent topology
This file characterises sheaves for the coherent topology
## Main result
* `isSheaf_coherent`: a presheaf of types for the is a sheaf for the coherent topology if and only
if it satisfies the sheaf condition with respect to every presieve consisting of a finite
effective epimorphic family.
-/
namespace CategoryTheory
variable {C : Type*} [Category C] [Precoherent C]
universe w in
lemma isSheaf_coherent (P : Cᵒᵖ ⥤ Type w) :
Presieve.IsSheaf (coherentTopology C) P ↔
(∀ (B : C) (α : Type) [Finite α] (X : α → C) (π : (a : α) → (X a ⟶ B)),
EffectiveEpiFamily X π → (Presieve.ofArrows X π).IsSheafFor P) := by
constructor
· intro hP B α _ X π h
simp only [coherentTopology, Presieve.isSheaf_coverage] at hP
apply hP
exact ⟨α, inferInstance, X, π, rfl, h⟩
· intro h
simp only [coherentTopology, Presieve.isSheaf_coverage]
rintro B S ⟨α, _, X, π, rfl, hS⟩
exact h _ _ _ _ hS
namespace coherentTopology
/-- Every Yoneda-presheaf is a sheaf for the coherent topology. -/
theorem isSheaf_yoneda_obj (W : C) : Presieve.IsSheaf (coherentTopology C) (yoneda.obj W) := by
rw [isSheaf_coherent]
intro X α _ Y π H
have h_colim := isColimitOfEffectiveEpiFamilyStruct Y π H.effectiveEpiFamily.some
rw [← Sieve.generateFamily_eq] at h_colim
intro x hx
let x_ext := Presieve.FamilyOfElements.sieveExtend x
have hx_ext := Presieve.FamilyOfElements.Compatible.sieveExtend hx
let S := Sieve.generate (Presieve.ofArrows Y π)
obtain ⟨t, t_amalg, t_uniq⟩ : ∃! t, x_ext.IsAmalgamation t :=
(Sieve.forallYonedaIsSheaf_iff_colimit S).mpr ⟨h_colim⟩ W x_ext hx_ext
refine ⟨t, ?_, ?_⟩
· convert Presieve.isAmalgamation_restrict (Sieve.le_generate (Presieve.ofArrows Y π)) _ _ t_amalg
exact (Presieve.restrict_extend hx).symm
· exact fun y hy ↦ t_uniq y <| Presieve.isAmalgamation_sieveExtend x y hy
variable (C) in
/-- The coherent topology on a precoherent category is subcanonical. -/
instance subcanonical : (coherentTopology C).Subcanonical :=
GrothendieckTopology.Subcanonical.of_isSheaf_yoneda_obj _ isSheaf_yoneda_obj
end coherentTopology
end CategoryTheory
|
Basic.lean
|
/-
Copyright (c) 2023 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Jon Eugster
-/
import Mathlib.Lean.Meta
/-!
# Additions to `Lean.Elab.Tactic.Basic`
-/
open Lean Elab Tactic
namespace Lean.Elab.Tactic
/-- Return expected type for the main goal, cleaning up annotations, using `Lean.MVarId.getType''`.
Remark: note that `MVarId.getType'` uses `whnf` instead of `cleanupAnnotations`, and
`MVarId.getType''` also uses `cleanupAnnotations` -/
def getMainTarget'' : TacticM Expr := do
(← getMainGoal).getType''
/--
Like `done` but takes a scope (e.g. a tactic name) as an argument
to produce more detailed error messages.
-/
def doneWithScope (scope : MessageData) : TacticM Unit := do
let gs ← getUnsolvedGoals
unless gs.isEmpty do
logError m!"{scope} failed to solve some goals.\n"
Term.reportUnsolvedGoals gs
throwAbortTactic
/--
Like `focusAndDone` but takes a scope (e.g. tactic name) as an argument to
produce more detailed error messages.
-/
def focusAndDoneWithScope {α : Type} (scope : MessageData) (tactic : TacticM α) : TacticM α :=
focus do
let a ← try tactic catch e =>
if isAbortTacticException e then throw e
else throwError "{scope} failed.\n{← nestedExceptionToMessageData e}"
doneWithScope scope
pure a
end Lean.Elab.Tactic
|
Finset.lean
|
/-
Copyright (c) 2024 Yaël Dillies, Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Andrew Yang
-/
import Mathlib.Algebra.Order.Group.OrderIso
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
import Mathlib.Data.Finset.Lattice.Prod
/-!
# `Finset.sup` in a group
-/
open scoped Finset
assert_not_exists MonoidWithZero
namespace Multiset
variable {α : Type*} [DecidableEq α]
@[simp] lemma toFinset_nsmul (s : Multiset α) : ∀ n ≠ 0, (n • s).toFinset = s.toFinset
| 0, h => by contradiction
| n + 1, _ => by
by_cases h : n = 0
· rw [h, zero_add, one_nsmul]
· rw [add_nsmul, toFinset_add, one_nsmul, toFinset_nsmul s n h, Finset.union_idempotent]
lemma toFinset_eq_singleton_iff (s : Multiset α) (a : α) :
s.toFinset = {a} ↔ card s ≠ 0 ∧ s = card s • {a} := by
refine ⟨fun H ↦ ⟨fun h ↦ ?_, ext' fun x ↦ ?_⟩, fun H ↦ ?_⟩
· rw [card_eq_zero.1 h, toFinset_zero] at H
exact Finset.singleton_ne_empty _ H.symm
· rw [count_nsmul, count_singleton]
by_cases hx : x = a
· simp_rw [hx, ite_true, mul_one, count_eq_card]
intro y hy
rw [← mem_toFinset, H, Finset.mem_singleton] at hy
exact hy.symm
have hx' : x ∉ s := fun h' ↦ hx <| by rwa [← mem_toFinset, H, Finset.mem_singleton] at h'
simp_rw [count_eq_zero_of_notMem hx', hx, ite_false, Nat.mul_zero]
simpa only [toFinset_nsmul _ _ H.1, toFinset_singleton] using congr($(H.2).toFinset)
lemma toFinset_card_eq_one_iff (s : Multiset α) :
#s.toFinset = 1 ↔ Multiset.card s ≠ 0 ∧ ∃ a : α, s = Multiset.card s • {a} := by
simp_rw [Finset.card_eq_one, Multiset.toFinset_eq_singleton_iff, exists_and_left]
end Multiset
namespace Finset
variable {ι κ M G : Type*}
lemma fold_max_add [LinearOrder M] [Add M] [AddRightMono M] (s : Finset ι) (a : WithBot M)
(f : ι → M) : s.fold max ⊥ (fun i ↦ ↑(f i) + a) = s.fold max ⊥ ((↑) ∘ f) + a := by
classical
induction' s using Finset.induction_on with a s _ ih <;> simp [*, max_add_add_right]
@[to_additive nsmul_inf']
lemma inf'_pow [LinearOrder M] [Monoid M] [MulLeftMono M] [MulRightMono M] (s : Finset ι)
(f : ι → M) (n : ℕ) (hs) : s.inf' hs f ^ n = s.inf' hs fun a ↦ f a ^ n :=
map_finset_inf' (OrderHom.mk _ <| pow_left_mono n) hs _
@[to_additive nsmul_sup']
lemma sup'_pow [LinearOrder M] [Monoid M] [MulLeftMono M] [MulRightMono M] (s : Finset ι)
(f : ι → M) (n : ℕ) (hs) : s.sup' hs f ^ n = s.sup' hs fun a ↦ f a ^ n :=
map_finset_sup' (OrderHom.mk _ <| pow_left_mono n) hs _
section Group
variable [Group G] [LinearOrder G]
@[to_additive /-- Also see `Finset.sup'_add'` that works for canonically ordered monoids. -/]
lemma sup'_mul [MulRightMono G] (s : Finset ι) (f : ι → G) (a : G) (hs) :
s.sup' hs f * a = s.sup' hs fun i ↦ f i * a := map_finset_sup' (OrderIso.mulRight a) hs f
set_option linter.docPrime false in
@[to_additive /-- Also see `Finset.add_sup''` that works for canonically ordered monoids. -/]
lemma mul_sup' [MulLeftMono G] (s : Finset ι) (f : ι → G) (a : G) (hs) :
a * s.sup' hs f = s.sup' hs fun i ↦ a * f i := map_finset_sup' (OrderIso.mulLeft a) hs f
end Group
section CanonicallyLinearOrderedAddCommMonoid
variable [AddCommMonoid M] [LinearOrder M] [CanonicallyOrderedAdd M]
[Sub M] [AddLeftReflectLE M] [OrderedSub M] {s : Finset ι} {t : Finset κ}
/-- Also see `Finset.sup'_add` that works for ordered groups. -/
lemma sup'_add' (s : Finset ι) (f : ι → M) (a : M) (hs : s.Nonempty) :
s.sup' hs f + a = s.sup' hs fun i ↦ f i + a := by
apply le_antisymm
· apply add_le_of_le_tsub_right_of_le
· exact Finset.le_sup'_of_le _ hs.choose_spec le_add_self
· exact Finset.sup'_le _ _ fun i hi ↦ le_tsub_of_add_le_right (Finset.le_sup' (f · + a) hi)
· exact Finset.sup'_le _ _ fun i hi ↦ add_le_add_right (Finset.le_sup' _ hi) _
/-- Also see `Finset.add_sup'` that works for ordered groups. -/
lemma add_sup'' (hs : s.Nonempty) (f : ι → M) (a : M) :
a + s.sup' hs f = s.sup' hs fun i ↦ a + f i := by simp_rw [add_comm a, Finset.sup'_add']
variable [OrderBot M]
protected lemma sup_add (hs : s.Nonempty) (f : ι → M) (a : M) :
s.sup f + a = s.sup fun i ↦ f i + a := by
rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs, sup'_add']
protected lemma add_sup (hs : s.Nonempty) (f : ι → M) (a : M) :
a + s.sup f = s.sup fun i ↦ a + f i := by
rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs, add_sup'']
lemma sup_add_sup (hs : s.Nonempty) (ht : t.Nonempty) (f : ι → M) (g : κ → M) :
s.sup f + t.sup g = (s ×ˢ t).sup fun ij ↦ f ij.1 + g ij.2 := by
simp only [Finset.sup_add hs, Finset.add_sup ht, Finset.sup_product_left]
end CanonicallyLinearOrderedAddCommMonoid
end Finset
|
RestrictScalars.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Module.Presentation.DirectSum
import Mathlib.Algebra.Module.Presentation.Cokernel
/-!
# Presentation of the restriction of scalars of a module
Given a morphism of rings `A → B` and a `B`-module `M`, we obtain a presentation
of `M` as a `A`-module from a presentation of `M` as `B`-module,
a presentation of `B` as a `A`-module (and some additional data).
## TODO
* deduce that if `B` is a finitely presented as an `A`-module and `M` is
finitely presented as an `B`-module, then `M` is finitely presented as an `A`-module
-/
namespace Module
variable {B : Type*} [Ring B] {M : Type*} [AddCommGroup M] [Module B M]
[DecidableEq B]
(presM : Presentation B M) [DecidableEq presM.G]
{A : Type*} [CommRing A] [Algebra A B] [Module A M] [IsScalarTower A B M]
(presB : Presentation A B)
namespace Presentation
/-- The additional data that is necessary in order to obtain a presentation
of the restriction of scalars of a module. -/
abbrev RestrictScalarsData : Type _ :=
(presB.finsupp presM.G).CokernelData
(LinearMap.restrictScalars A presM.map)
(fun (⟨g, g'⟩ : presB.G × presM.R) ↦ presB.var g • Finsupp.single g' (1 : B))
variable (data : presM.RestrictScalarsData presB)
/-- A presentation of the restriction of scalars from `B` to `A` of a `B`-module `M`,
given a presentation of `M` as a `B`-module, a presentation of `B` as an `A`-module,
and an additional data. -/
noncomputable def restrictScalars : Presentation A M :=
ofExact (g := LinearMap.restrictScalars A presM.π) (presB.finsupp presM.G) data
presM.exact presM.surjective_π (by
ext v
dsimp
simp only [Submodule.mem_top, iff_true]
apply Finsupp.induction
· simp
· intro r b w _ _ hw
refine Submodule.add_mem _ ?_ hw
obtain ⟨β, rfl⟩ := presB.surjective_π b
apply Finsupp.induction (motive := fun β ↦ Finsupp.single r (presB.π β) ∈ _)
· simp
· intro g a f _ _ hf
rw [map_add, Finsupp.single_add]
refine Submodule.add_mem _ ?_ hf
rw [← Finsupp.smul_single_one, ← Finsupp.smul_single_one,
map_smul, Relations.Solution.π_single, smul_assoc]
exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨⟨g, r⟩, rfl⟩))
end Presentation
end Module
|
AddChar.lean
|
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Algebra.Group.TransferInstance
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.Algebra.Ring.Regular
/-!
# Characters from additive to multiplicative monoids
Let `A` be an additive monoid, and `M` a multiplicative one. An *additive character* of `A` with
values in `M` is simply a map `A → M` which intertwines the addition operation on `A` with the
multiplicative operation on `M`.
We define these objects, using the namespace `AddChar`, and show that if `A` is a commutative group
under addition, then the additive characters are also a group (written multiplicatively). Note that
we do not need `M` to be a group here.
We also include some constructions specific to the case when `A = R` is a ring; then we define
`mulShift ψ r`, where `ψ : AddChar R M` and `r : R`, to be the character defined by
`x ↦ ψ (r * x)`.
For more refined results of a number-theoretic nature (primitive characters, Gauss sums, etc)
see `Mathlib/NumberTheory/LegendreSymbol/AddCharacter.lean`.
# Implementation notes
Due to their role as the dual of an additive group, additive characters must themselves be an
additive group. This contrasts to their pointwise operations which make them a multiplicative group.
We simply define both the additive and multiplicative group structures and prove them equal.
For more information on this design decision, see the following zulip thread:
https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Additive.20characters
## Tags
additive character
-/
/-!
### Definitions related to and results on additive characters
-/
open Function Multiplicative
open Finset hiding card
open Fintype (card)
section AddCharDef
-- The domain of our additive characters
variable (A : Type*) [AddMonoid A]
-- The target
variable (M : Type*) [Monoid M]
/-- `AddChar A M` is the type of maps `A → M`, for `A` an additive monoid and `M` a multiplicative
monoid, which intertwine addition in `A` with multiplication in `M`.
We only put the typeclasses needed for the definition, although in practice we are usually
interested in much more specific cases (e.g. when `A` is a group and `M` a commutative ring).
-/
structure AddChar where
/-- The underlying function.
Do not use this function directly. Instead use the coercion coming from the `FunLike`
instance. -/
toFun : A → M
/-- The function maps `0` to `1`.
Do not use this directly. Instead use `AddChar.map_zero_eq_one`. -/
map_zero_eq_one' : toFun 0 = 1
/-- The function maps addition in `A` to multiplication in `M`.
Do not use this directly. Instead use `AddChar.map_add_eq_mul`. -/
map_add_eq_mul' : ∀ a b : A, toFun (a + b) = toFun a * toFun b
end AddCharDef
namespace AddChar
section Basic
-- results which don't require commutativity or inverses
variable {A B M N : Type*} [AddMonoid A] [AddMonoid B] [Monoid M] [Monoid N] {ψ : AddChar A M}
/-- Define coercion to a function. -/
instance instFunLike : FunLike (AddChar A M) A M where
coe := AddChar.toFun
coe_injective' φ ψ h := by cases φ; cases ψ; congr
@[ext] lemma ext (f g : AddChar A M) (h : ∀ x : A, f x = g x) : f = g :=
DFunLike.ext f g h
@[simp] lemma coe_mk (f : A → M)
(map_zero_eq_one' : f 0 = 1) (map_add_eq_mul' : ∀ a b : A, f (a + b) = f a * f b) :
AddChar.mk f map_zero_eq_one' map_add_eq_mul' = f := by
rfl
/-- An additive character maps `0` to `1`. -/
@[simp] lemma map_zero_eq_one (ψ : AddChar A M) : ψ 0 = 1 := ψ.map_zero_eq_one'
/-- An additive character maps sums to products. -/
lemma map_add_eq_mul (ψ : AddChar A M) (x y : A) : ψ (x + y) = ψ x * ψ y := ψ.map_add_eq_mul' x y
/-- Interpret an additive character as a monoid homomorphism. -/
def toMonoidHom (φ : AddChar A M) : Multiplicative A →* M where
toFun := φ.toFun
map_one' := φ.map_zero_eq_one'
map_mul' := φ.map_add_eq_mul'
-- this instance was a bad idea and conflicted with `instFunLike` above
@[simp] lemma toMonoidHom_apply (ψ : AddChar A M) (a : Multiplicative A) :
ψ.toMonoidHom a = ψ a.toAdd :=
rfl
/-- An additive character maps multiples by natural numbers to powers. -/
lemma map_nsmul_eq_pow (ψ : AddChar A M) (n : ℕ) (x : A) : ψ (n • x) = ψ x ^ n :=
ψ.toMonoidHom.map_pow x n
/-- Additive characters `A → M` are the same thing as monoid homomorphisms from `Multiplicative A`
to `M`. -/
def toMonoidHomEquiv : AddChar A M ≃ (Multiplicative A →* M) where
toFun φ := φ.toMonoidHom
invFun f :=
{ toFun := f.toFun
map_zero_eq_one' := f.map_one'
map_add_eq_mul' := f.map_mul' }
@[simp, norm_cast] lemma coe_toMonoidHomEquiv (ψ : AddChar A M) :
⇑(toMonoidHomEquiv ψ) = ψ ∘ Multiplicative.toAdd := rfl
@[simp, norm_cast] lemma coe_toMonoidHomEquiv_symm (ψ : Multiplicative A →* M) :
⇑(toMonoidHomEquiv.symm ψ) = ψ ∘ Multiplicative.ofAdd := rfl
@[simp] lemma toMonoidHomEquiv_apply (ψ : AddChar A M) (a : Multiplicative A) :
toMonoidHomEquiv ψ a = ψ a.toAdd := rfl
@[simp] lemma toMonoidHomEquiv_symm_apply (ψ : Multiplicative A →* M) (a : A) :
toMonoidHomEquiv.symm ψ a = ψ (Multiplicative.ofAdd a) := rfl
/-- Interpret an additive character as a monoid homomorphism. -/
def toAddMonoidHom (φ : AddChar A M) : A →+ Additive M where
toFun := φ.toFun
map_zero' := φ.map_zero_eq_one'
map_add' := φ.map_add_eq_mul'
@[simp] lemma coe_toAddMonoidHom (ψ : AddChar A M) : ⇑ψ.toAddMonoidHom = Additive.ofMul ∘ ψ := rfl
@[simp] lemma toAddMonoidHom_apply (ψ : AddChar A M) (a : A) :
ψ.toAddMonoidHom a = Additive.ofMul (ψ a) := rfl
/-- Additive characters `A → M` are the same thing as additive homomorphisms from `A` to
`Additive M`. -/
def toAddMonoidHomEquiv : AddChar A M ≃ (A →+ Additive M) where
toFun φ := φ.toAddMonoidHom
invFun f :=
{ toFun := f.toFun
map_zero_eq_one' := f.map_zero'
map_add_eq_mul' := f.map_add' }
@[simp, norm_cast]
lemma coe_toAddMonoidHomEquiv (ψ : AddChar A M) :
⇑(toAddMonoidHomEquiv ψ) = Additive.ofMul ∘ ψ := rfl
@[simp, norm_cast] lemma coe_toAddMonoidHomEquiv_symm (ψ : A →+ Additive M) :
⇑(toAddMonoidHomEquiv.symm ψ) = Additive.toMul ∘ ψ := rfl
@[simp] lemma toAddMonoidHomEquiv_apply (ψ : AddChar A M) (a : A) :
toAddMonoidHomEquiv ψ a = Additive.ofMul (ψ a) := rfl
@[simp] lemma toAddMonoidHomEquiv_symm_apply (ψ : A →+ Additive M) (a : A) :
toAddMonoidHomEquiv.symm ψ a = (ψ a).toMul := rfl
/-- The trivial additive character (sending everything to `1`). -/
instance instOne : One (AddChar A M) := toMonoidHomEquiv.one
/-- The trivial additive character (sending everything to `1`). -/
instance instZero : Zero (AddChar A M) := ⟨1⟩
@[simp, norm_cast] lemma coe_one : ⇑(1 : AddChar A M) = 1 := rfl
@[simp, norm_cast] lemma coe_zero : ⇑(0 : AddChar A M) = 1 := rfl
@[simp] lemma one_apply (a : A) : (1 : AddChar A M) a = 1 := rfl
@[simp] lemma zero_apply (a : A) : (0 : AddChar A M) a = 1 := rfl
lemma one_eq_zero : (1 : AddChar A M) = (0 : AddChar A M) := rfl
@[simp, norm_cast] lemma coe_eq_one : ⇑ψ = 1 ↔ ψ = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq]
@[simp] lemma toMonoidHomEquiv_zero : toMonoidHomEquiv (0 : AddChar A M) = 1 := rfl
@[simp] lemma toMonoidHomEquiv_symm_one :
toMonoidHomEquiv.symm (1 : Multiplicative A →* M) = 0 := rfl
@[simp] lemma toAddMonoidHomEquiv_zero : toAddMonoidHomEquiv (0 : AddChar A M) = 0 := rfl
@[simp] lemma toAddMonoidHomEquiv_symm_zero :
toAddMonoidHomEquiv.symm (0 : A →+ Additive M) = 0 := rfl
instance instInhabited : Inhabited (AddChar A M) := ⟨1⟩
/-- Composing a `MonoidHom` with an `AddChar` yields another `AddChar`. -/
def _root_.MonoidHom.compAddChar {N : Type*} [Monoid N] (f : M →* N) (φ : AddChar A M) :
AddChar A N := toMonoidHomEquiv.symm (f.comp φ.toMonoidHom)
@[simp, norm_cast]
lemma _root_.MonoidHom.coe_compAddChar {N : Type*} [Monoid N] (f : M →* N) (φ : AddChar A M) :
f.compAddChar φ = f ∘ φ :=
rfl
@[simp, norm_cast]
lemma _root_.MonoidHom.compAddChar_apply (f : M →* N) (φ : AddChar A M) : f.compAddChar φ = f ∘ φ :=
rfl
lemma _root_.MonoidHom.compAddChar_injective_left (ψ : AddChar A M) (hψ : Surjective ψ) :
Injective fun f : M →* N ↦ f.compAddChar ψ := by
rintro f g h; rw [DFunLike.ext'_iff] at h ⊢; exact hψ.injective_comp_right h
lemma _root_.MonoidHom.compAddChar_injective_right (f : M →* N) (hf : Injective f) :
Injective fun ψ : AddChar B M ↦ f.compAddChar ψ := by
rintro ψ χ h; rw [DFunLike.ext'_iff] at h ⊢; exact hf.comp_left h
/-- Composing an `AddChar` with an `AddMonoidHom` yields another `AddChar`. -/
def compAddMonoidHom (φ : AddChar B M) (f : A →+ B) : AddChar A M :=
toAddMonoidHomEquiv.symm (φ.toAddMonoidHom.comp f)
@[simp, norm_cast]
lemma coe_compAddMonoidHom (φ : AddChar B M) (f : A →+ B) : φ.compAddMonoidHom f = φ ∘ f := rfl
@[simp] lemma compAddMonoidHom_apply (ψ : AddChar B M) (f : A →+ B)
(a : A) : ψ.compAddMonoidHom f a = ψ (f a) := rfl
lemma compAddMonoidHom_injective_left (f : A →+ B) (hf : Surjective f) :
Injective fun ψ : AddChar B M ↦ ψ.compAddMonoidHom f := by
rintro ψ χ h; rw [DFunLike.ext'_iff] at h ⊢; exact hf.injective_comp_right h
lemma compAddMonoidHom_injective_right (ψ : AddChar B M) (hψ : Injective ψ) :
Injective fun f : A →+ B ↦ ψ.compAddMonoidHom f := by
rintro f g h
rw [DFunLike.ext'_iff] at h ⊢; exact hψ.comp_left h
lemma eq_one_iff : ψ = 1 ↔ ∀ x, ψ x = 1 := DFunLike.ext_iff
lemma eq_zero_iff : ψ = 0 ↔ ∀ x, ψ x = 1 := DFunLike.ext_iff
lemma ne_one_iff : ψ ≠ 1 ↔ ∃ x, ψ x ≠ 1 := DFunLike.ne_iff
lemma ne_zero_iff : ψ ≠ 0 ↔ ∃ x, ψ x ≠ 1 := DFunLike.ne_iff
noncomputable instance : DecidableEq (AddChar A M) := Classical.decEq _
end Basic
section toCommMonoid
variable {ι A M : Type*} [AddMonoid A] [CommMonoid M]
/-- When `M` is commutative, `AddChar A M` is a commutative monoid. -/
instance instCommMonoid : CommMonoid (AddChar A M) := toMonoidHomEquiv.commMonoid
/-- When `M` is commutative, `AddChar A M` is an additive commutative monoid. -/
instance instAddCommMonoid : AddCommMonoid (AddChar A M) := Additive.addCommMonoid
@[simp, norm_cast] lemma coe_mul (ψ χ : AddChar A M) : ⇑(ψ * χ) = ψ * χ := rfl
@[simp, norm_cast] lemma coe_add (ψ χ : AddChar A M) : ⇑(ψ + χ) = ψ * χ := rfl
@[simp, norm_cast] lemma coe_pow (ψ : AddChar A M) (n : ℕ) : ⇑(ψ ^ n) = ψ ^ n := rfl
@[simp, norm_cast] lemma coe_nsmul (n : ℕ) (ψ : AddChar A M) : ⇑(n • ψ) = ψ ^ n := rfl
@[simp, norm_cast]
lemma coe_prod (s : Finset ι) (ψ : ι → AddChar A M) : ∏ i ∈ s, ψ i = ∏ i ∈ s, ⇑(ψ i) := by
induction s using Finset.cons_induction <;> simp [*]
@[simp, norm_cast]
lemma coe_sum (s : Finset ι) (ψ : ι → AddChar A M) : ∑ i ∈ s, ψ i = ∏ i ∈ s, ⇑(ψ i) := by
induction s using Finset.cons_induction <;> simp [*]
@[simp] lemma mul_apply (ψ φ : AddChar A M) (a : A) : (ψ * φ) a = ψ a * φ a := rfl
@[simp] lemma add_apply (ψ φ : AddChar A M) (a : A) : (ψ + φ) a = ψ a * φ a := rfl
@[simp] lemma pow_apply (ψ : AddChar A M) (n : ℕ) (a : A) : (ψ ^ n) a = (ψ a) ^ n := rfl
@[simp] lemma nsmul_apply (ψ : AddChar A M) (n : ℕ) (a : A) : (n • ψ) a = (ψ a) ^ n := rfl
lemma prod_apply (s : Finset ι) (ψ : ι → AddChar A M) (a : A) :
(∏ i ∈ s, ψ i) a = ∏ i ∈ s, ψ i a := by rw [coe_prod, Finset.prod_apply]
lemma sum_apply (s : Finset ι) (ψ : ι → AddChar A M) (a : A) :
(∑ i ∈ s, ψ i) a = ∏ i ∈ s, ψ i a := by rw [coe_sum, Finset.prod_apply]
lemma mul_eq_add (ψ χ : AddChar A M) : ψ * χ = ψ + χ := rfl
lemma pow_eq_nsmul (ψ : AddChar A M) (n : ℕ) : ψ ^ n = n • ψ := rfl
lemma prod_eq_sum (s : Finset ι) (ψ : ι → AddChar A M) : ∏ i ∈ s, ψ i = ∑ i ∈ s, ψ i := rfl
@[simp] lemma toMonoidHomEquiv_add (ψ φ : AddChar A M) :
toMonoidHomEquiv (ψ + φ) = toMonoidHomEquiv ψ * toMonoidHomEquiv φ := rfl
@[simp] lemma toMonoidHomEquiv_symm_mul (ψ φ : Multiplicative A →* M) :
toMonoidHomEquiv.symm (ψ * φ) = toMonoidHomEquiv.symm ψ + toMonoidHomEquiv.symm φ := rfl
/-- The natural equivalence to `(Multiplicative A →* M)` is a monoid isomorphism. -/
def toMonoidHomMulEquiv : AddChar A M ≃* (Multiplicative A →* M) :=
{ toMonoidHomEquiv with map_mul' := fun φ ψ ↦ by rfl }
/-- Additive characters `A → M` are the same thing as additive homomorphisms from `A` to
`Additive M`. -/
def toAddMonoidAddEquiv : Additive (AddChar A M) ≃+ (A →+ Additive M) :=
{ toAddMonoidHomEquiv with map_add' := fun φ ψ ↦ by rfl }
/-- The double dual embedding. -/
def doubleDualEmb : A →+ AddChar (AddChar A M) M where
toFun a := { toFun := fun ψ ↦ ψ a
map_zero_eq_one' := by simp
map_add_eq_mul' := by simp }
map_zero' := by ext; simp
map_add' _ _ := by ext; simp [map_add_eq_mul]
@[simp] lemma doubleDualEmb_apply (a : A) (ψ : AddChar A M) : doubleDualEmb a ψ = ψ a := rfl
end toCommMonoid
section CommSemiring
variable {A R : Type*} [AddGroup A] [Fintype A] [CommSemiring R] [IsDomain R]
{ψ : AddChar A R}
lemma sum_eq_ite (ψ : AddChar A R) [Decidable (ψ = 0)] :
∑ a, ψ a = if ψ = 0 then ↑(card A) else 0 := by
split_ifs with h
· simp [h]
obtain ⟨x, hx⟩ := ne_one_iff.1 h
refine eq_zero_of_mul_eq_self_left hx ?_
rw [Finset.mul_sum]
exact Fintype.sum_equiv (Equiv.addLeft x) _ _ fun y ↦ (map_add_eq_mul ..).symm
variable [CharZero R]
lemma sum_eq_zero_iff_ne_zero : ∑ x, ψ x = 0 ↔ ψ ≠ 0 := by
classical
rw [sum_eq_ite, Ne.ite_eq_right_iff]; exact Nat.cast_ne_zero.2 Fintype.card_ne_zero
lemma sum_ne_zero_iff_eq_zero : ∑ x, ψ x ≠ 0 ↔ ψ = 0 := sum_eq_zero_iff_ne_zero.not_left
end CommSemiring
/-!
## Additive characters of additive abelian groups
-/
section fromAddCommGroup
variable {A M : Type*} [AddCommGroup A] [CommMonoid M]
/-- The additive characters on a commutative additive group form a commutative group.
Note that the inverse is defined using negation on the domain; we do not assume `M` has an
inversion operation for the definition (but see `AddChar.map_neg_eq_inv` below). -/
instance instCommGroup : CommGroup (AddChar A M) :=
{ instCommMonoid with
inv := fun ψ ↦ ψ.compAddMonoidHom negAddMonoidHom
inv_mul_cancel := fun ψ ↦ by ext1 x; simp [negAddMonoidHom, ← map_add_eq_mul]}
/-- The additive characters on a commutative additive group form a commutative group. -/
instance : AddCommGroup (AddChar A M) := Additive.addCommGroup
@[simp] lemma inv_apply (ψ : AddChar A M) (a : A) : ψ⁻¹ a = ψ (-a) := rfl
@[simp] lemma neg_apply (ψ : AddChar A M) (a : A) : (-ψ) a = ψ (-a) := rfl
lemma div_apply (ψ χ : AddChar A M) (a : A) : (ψ / χ) a = ψ a * χ (-a) := rfl
lemma sub_apply (ψ χ : AddChar A M) (a : A) : (ψ - χ) a = ψ a * χ (-a) := rfl
end fromAddCommGroup
section fromAddGrouptoCommMonoid
/-- The values of an additive character on an additive group are units. -/
lemma val_isUnit {A M} [AddGroup A] [Monoid M] (φ : AddChar A M) (a : A) : IsUnit (φ a) :=
IsUnit.map φ.toMonoidHom <| Group.isUnit (Multiplicative.ofAdd a)
end fromAddGrouptoCommMonoid
section fromAddGrouptoDivisionMonoid
variable {A M : Type*} [AddGroup A] [DivisionMonoid M]
/-- An additive character maps negatives to inverses (when defined) -/
lemma map_neg_eq_inv (ψ : AddChar A M) (a : A) : ψ (-a) = (ψ a)⁻¹ := by
apply eq_inv_of_mul_eq_one_left
simp only [← map_add_eq_mul, neg_add_cancel, map_zero_eq_one]
/-- An additive character maps integer scalar multiples to integer powers. -/
lemma map_zsmul_eq_zpow (ψ : AddChar A M) (n : ℤ) (a : A) : ψ (n • a) = (ψ a) ^ n :=
ψ.toMonoidHom.map_zpow a n
end fromAddGrouptoDivisionMonoid
section fromAddCommGrouptoDivisionCommMonoid
variable {A M : Type*} [AddCommGroup A] [DivisionCommMonoid M]
lemma inv_apply' (ψ : AddChar A M) (a : A) : ψ⁻¹ a = (ψ a)⁻¹ := by rw [inv_apply, map_neg_eq_inv]
lemma neg_apply' (ψ : AddChar A M) (a : A) : (-ψ) a = (ψ a)⁻¹ := map_neg_eq_inv _ _
lemma div_apply' (ψ χ : AddChar A M) (a : A) : (ψ / χ) a = ψ a / χ a := by
rw [div_apply, map_neg_eq_inv, div_eq_mul_inv]
lemma sub_apply' (ψ χ : AddChar A M) (a : A) : (ψ - χ) a = ψ a / χ a := by
rw [sub_apply, map_neg_eq_inv, div_eq_mul_inv]
@[simp] lemma zsmul_apply (n : ℤ) (ψ : AddChar A M) (a : A) : (n • ψ) a = ψ a ^ n := by
cases n <;> simp [-neg_apply, neg_apply']
@[simp] lemma zpow_apply (ψ : AddChar A M) (n : ℤ) (a : A) : (ψ ^ n) a = ψ a ^ n := zsmul_apply ..
lemma map_sub_eq_div (ψ : AddChar A M) (a b : A) : ψ (a - b) = ψ a / ψ b :=
ψ.toMonoidHom.map_div _ _
lemma injective_iff {ψ : AddChar A M} : Injective ψ ↔ ∀ ⦃x⦄, ψ x = 1 → x = 0 :=
ψ.toMonoidHom.ker_eq_bot_iff.symm.trans eq_bot_iff
end fromAddCommGrouptoDivisionCommMonoid
section MonoidWithZero
variable {A M₀ : Type*} [AddGroup A] [MonoidWithZero M₀] [Nontrivial M₀]
@[simp] lemma coe_ne_zero (ψ : AddChar A M₀) : (ψ : A → M₀) ≠ 0 :=
ne_iff.2 ⟨0, fun h ↦ by simpa only [h, Pi.zero_apply, zero_ne_one] using map_zero_eq_one ψ⟩
end MonoidWithZero
/-!
## Additive characters of rings
-/
section Ring
-- The domain and target of our additive characters. Now we restrict to a ring in the domain.
variable {R M : Type*} [Ring R] [CommMonoid M]
/-- Define the multiplicative shift of an additive character.
This satisfies `mulShift ψ a x = ψ (a * x)`. -/
def mulShift (ψ : AddChar R M) (r : R) : AddChar R M :=
ψ.compAddMonoidHom (AddMonoidHom.mulLeft r)
@[simp] lemma mulShift_apply {ψ : AddChar R M} {r : R} {x : R} : mulShift ψ r x = ψ (r * x) :=
rfl
/-- `ψ⁻¹ = mulShift ψ (-1))`. -/
theorem inv_mulShift (ψ : AddChar R M) : ψ⁻¹ = mulShift ψ (-1) := by
ext
rw [inv_apply, mulShift_apply, neg_mul, one_mul]
/-- If `n` is a natural number, then `mulShift ψ n x = (ψ x) ^ n`. -/
theorem mulShift_spec' (ψ : AddChar R M) (n : ℕ) (x : R) : mulShift ψ n x = ψ x ^ n := by
rw [mulShift_apply, ← nsmul_eq_mul, map_nsmul_eq_pow]
/-- If `n` is a natural number, then `ψ ^ n = mulShift ψ n`. -/
theorem pow_mulShift (ψ : AddChar R M) (n : ℕ) : ψ ^ n = mulShift ψ n := by
ext x
rw [pow_apply, ← mulShift_spec']
/-- The product of `mulShift ψ r` and `mulShift ψ s` is `mulShift ψ (r + s)`. -/
theorem mulShift_mul (ψ : AddChar R M) (r s : R) :
mulShift ψ r * mulShift ψ s = mulShift ψ (r + s) := by
ext
rw [mulShift_apply, right_distrib, map_add_eq_mul]; norm_cast
lemma mulShift_mulShift (ψ : AddChar R M) (r s : R) :
mulShift (mulShift ψ r) s = mulShift ψ (r * s) := by
ext
simp only [mulShift_apply, mul_assoc]
/-- `mulShift ψ 0` is the trivial character. -/
@[simp]
theorem mulShift_zero (ψ : AddChar R M) : mulShift ψ 0 = 1 := by
ext; rw [mulShift_apply, zero_mul, map_zero_eq_one, one_apply]
@[simp]
lemma mulShift_one (ψ : AddChar R M) : mulShift ψ 1 = ψ := by
ext; rw [mulShift_apply, one_mul]
lemma mulShift_unit_eq_one_iff (ψ : AddChar R M) {u : R} (hu : IsUnit u) :
ψ.mulShift u = 1 ↔ ψ = 1 := by
refine ⟨fun h ↦ ?_, ?_⟩
· ext1 y
rw [show y = u * (hu.unit⁻¹ * y) by rw [← mul_assoc, IsUnit.mul_val_inv, one_mul]]
simpa only [mulShift_apply] using DFunLike.ext_iff.mp h (hu.unit⁻¹ * y)
· solve_by_elim
end Ring
end AddChar
|
DocPrime.lean
|
import Mathlib.Tactic.Linter.DocPrime
import Mathlib.Tactic.Lemma
set_option linter.docPrime true
-- no warning on a primed-declaration with a doc-string containing `'`
/-- X' has a doc-string -/
def X' := 0
-- no warning on a declaration whose name contains a `'` *and does not end with it*
def X'X := 0
-- A list of universe names in the declaration is handled correctly, i.e. warns.
/--
warning: `Y'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
def Y'.{u} := ULift.{u} Nat
namespace X
/--
warning: `ABC.thm_no_doc1'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
theorem _root_.ABC.thm_no_doc1' : True := .intro
/--
warning: `X.thm_no_doc2'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
theorem thm_no_doc2' : True := .intro
end X
/--
warning: `thm_no_doc'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
theorem thm_no_doc' : True := .intro
/--
warning: `thm_with_attr_no_doc'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
@[simp]
theorem thm_with_attr_no_doc' : True := .intro
/--
warning: `inst_no_doc'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
instance inst_no_doc' : True := .intro
/--
warning: `abbrev_no_doc'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
abbrev abbrev_no_doc' : True := .intro
/--
warning: `def_no_doc'` is missing a doc-string, please add one.
Declarations whose name ends with a `'` are expected to contain an explanation for the presence of a `'` in their doc-string. This may consist of discussion of the difference relative to the unprimed version, or an explanation as to why no better naming scheme is possible.
Note: This linter can be disabled with `set_option linter.docPrime false`
-/
#guard_msgs in
def def_no_doc' : True := .intro
-- Anonymous declarations in a primed namespace should not get flagged by the linter.
namespace Foo'
example : True := .intro
instance : True := .intro
end Foo'
|
Ext.lean
|
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Adam Topaz
-/
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.Algebra.Homology.Opposite
import Mathlib.CategoryTheory.Abelian.LeftDerived
import Mathlib.CategoryTheory.Abelian.Opposite
import Mathlib.CategoryTheory.Abelian.Projective.Resolution
import Mathlib.CategoryTheory.Linear.Yoneda
/-!
# Ext
We define `Ext R C n : Cᵒᵖ ⥤ C ⥤ Module R` for any `R`-linear abelian category `C`
by (left) deriving in the first argument of the bifunctor `(X, Y) ↦ ModuleCat.of R (unop X ⟶ Y)`.
## Implementation
TODO (@joelriou): When the derived category enters mathlib, the Ext groups shall be
redefined using morphisms in the derived category, and then it will be possible to
compute `Ext` using both projective or injective resolutions.
-/
noncomputable section
open CategoryTheory Limits
variable (R : Type*) [Ring R] (C : Type*) [Category C] [Abelian C] [Linear R C]
[EnoughProjectives C]
/-- `Ext R C n` is defined by deriving in
the first argument of `(X, Y) ↦ ModuleCat.of R (unop X ⟶ Y)`
(which is the second argument of `linearYoneda`).
-/
def Ext (n : ℕ) : Cᵒᵖ ⥤ C ⥤ ModuleCat R :=
Functor.flip
{ obj := fun Y => (((linearYoneda R C).obj Y).rightOp.leftDerived n).leftOp
-- Porting note: if we use dot notation for any of
-- `NatTrans.leftOp` / `NatTrans.rightOp` / `NatTrans.leftDerived`
-- then `cat_disch` can not discharge the `map_id` and `map_comp` goals.
-- This should be investigated further.
map := fun f =>
NatTrans.leftOp (NatTrans.leftDerived (NatTrans.rightOp ((linearYoneda R C).map f)) n) }
open ZeroObject
variable {R C}
/-- Given a chain complex `X` and an object `Y`, this is the cochain complex
which in degree `i` consists of the module of morphisms `X.X i ⟶ Y`. -/
@[simps! X d]
def ChainComplex.linearYonedaObj {α : Type*} [AddRightCancelSemigroup α] [One α]
(X : ChainComplex C α) (A : Type*) [Ring A] [Linear A C] (Y : C) :
CochainComplex (ModuleCat A) α :=
((((linearYoneda A C).obj Y).rightOp.mapHomologicalComplex _).obj X).unop
namespace CategoryTheory
namespace ProjectiveResolution
variable {X : C} (P : ProjectiveResolution X)
/-- `Ext` can be computed using a projective resolution. -/
def isoExt (n : ℕ) (Y : C) : ((Ext R C n).obj (Opposite.op X)).obj Y ≅
(P.complex.linearYonedaObj R Y).homology n :=
(P.isoLeftDerivedObj ((linearYoneda R C).obj Y).rightOp n).unop.symm ≪≫
(HomologicalComplex.homologyUnop _ _).symm
end ProjectiveResolution
end CategoryTheory
/-- If `X : C` is projective and `n : ℕ`, then `Ext^(n + 1) X Y ≅ 0` for any `Y`. -/
lemma isZero_Ext_succ_of_projective (X Y : C) [Projective X] (n : ℕ) :
IsZero (((Ext R C (n + 1)).obj (Opposite.op X)).obj Y) := by
refine IsZero.of_iso ?_ ((ProjectiveResolution.self X).isoExt (n + 1) Y)
rw [← HomologicalComplex.exactAt_iff_isZero_homology, HomologicalComplex.exactAt_iff]
refine ShortComplex.exact_of_isZero_X₂ _ ?_
dsimp
rw [IsZero.iff_id_eq_zero]
ext (x : _ ⟶ _)
obtain rfl : x = 0 := (HomologicalComplex.isZero_single_obj_X
(ComplexShape.down ℕ) 0 X (n + 1) (by simp)).eq_of_src _ _
rfl
|
all_field.v
|
From mathcomp Require Export algC.
From mathcomp Require Export algebraics_fundamentals.
From mathcomp Require Export algnum.
From mathcomp Require Export closed_field.
From mathcomp Require Export cyclotomic.
From mathcomp Require Export falgebra.
From mathcomp Require Export fieldext.
From mathcomp Require Export finfield.
From mathcomp Require Export galois.
From mathcomp Require Export separable.
From mathcomp Require Export qfpoly.
|
Bracket.lean
|
/-
Copyright (c) 2021 Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Lutz, Oliver Nash
-/
import Mathlib.Tactic.TypeStar
/-!
# Bracket Notation
This file provides notation which can be used for the Lie bracket, for the commutator of two
subgroups, and for other similar operations.
## Main Definitions
* `Bracket L M` for a binary operation that takes something in `L` and something in `M` and
produces something in `M`.
Defining an instance of this structure gives access to the notation `⁅ ⁆`
## Notation
We introduce the notation `⁅x, y⁆` for the `bracket` of any `Bracket` structure. Note that
these are the Unicode "square with quill" brackets rather than the usual square brackets.
-/
/-- The `Bracket` class has three intended uses:
1. for certain binary operations on structures, like the product `⁅x, y⁆` of two elements
`x`, `y` in a Lie algebra or the commutator of two elements `x` and `y` in a group.
2. for certain actions of one structure on another, like the action `⁅x, m⁆` of an element `x`
of a Lie algebra on an element `m` in one of its modules (analogous to `SMul` in the
associative setting).
3. for binary operations on substructures, like the commutator `⁅H, K⁆` of two subgroups `H` and
`K` of a group. -/
class Bracket (L M : Type*) where
/-- `⁅x, y⁆` is the result of a bracket operation on elements `x` and `y`.
It is supported by the `Bracket` typeclass. -/
bracket : L → M → M
@[inherit_doc] notation "⁅" x ", " y "⁆" => Bracket.bracket x y
|
WhatsNew.lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import Mathlib.Init
/-!
Defines a command wrapper that prints the changes the command makes to the
environment.
```
whatsnew in
theorem foo : 42 = 6 * 7 := rfl
```
-/
open Lean Elab Command
namespace Mathlib.WhatsNew
private def throwUnknownId (id : Name) : CommandElabM Unit :=
throwError "unknown identifier '{mkConst id}'"
private def levelParamsToMessageData (levelParams : List Name) : MessageData :=
match levelParams with
| [] => ""
| u::us => Id.run <| do
let mut m := m!".\{{u}"
for u in us do
m := m ++ ", " ++ toMessageData u
return m ++ "}"
private def mkHeader (kind : String) (id : Name) (levelParams : List Name) (type : Expr)
(safety : DefinitionSafety) : CoreM MessageData := do
let m : MessageData :=
match safety with
| DefinitionSafety.unsafe => "unsafe "
| DefinitionSafety.partial => "partial "
| DefinitionSafety.safe => ""
let m := if isProtected (← getEnv) id then m ++ "protected " else m
let (m, id) := match privateToUserName? id with
| some id => (m ++ "private ", id)
| none => (m, id)
let m := m ++ kind ++ " " ++ id ++ levelParamsToMessageData levelParams ++ " : " ++ type
pure m
private def mkHeader' (kind : String) (id : Name) (levelParams : List Name) (type : Expr)
(isUnsafe : Bool) : CoreM MessageData :=
mkHeader kind id levelParams type
(if isUnsafe then DefinitionSafety.unsafe else DefinitionSafety.safe)
private def printDefLike (kind : String) (id : Name) (levelParams : List Name) (type : Expr)
(value : Expr) (safety := DefinitionSafety.safe) : CoreM MessageData :=
return (← mkHeader kind id levelParams type safety) ++ " :=" ++ Format.line ++ value
private def printInduct (id : Name) (levelParams : List Name) (_numParams : Nat) (_numIndices : Nat)
(type : Expr) (ctors : List Name) (isUnsafe : Bool) : CoreM MessageData := do
let mut m ← mkHeader' "inductive" id levelParams type isUnsafe
m := m ++ Format.line ++ "constructors:"
for ctor in ctors do
let cinfo ← getConstInfo ctor
m := m ++ Format.line ++ ctor ++ " : " ++ cinfo.type
pure m
private def printIdCore (id : Name) : ConstantInfo → CoreM MessageData
| ConstantInfo.axiomInfo { levelParams := us, type := t, isUnsafe := u, .. } =>
mkHeader' "axiom" id us t u
| ConstantInfo.defnInfo { levelParams := us, type := t, value := v, safety := s, .. } =>
printDefLike "def" id us t v s
| ConstantInfo.thmInfo { levelParams := us, type := t, value := v, .. } =>
printDefLike "theorem" id us t v
| ConstantInfo.opaqueInfo { levelParams := us, type := t, isUnsafe := u, .. } =>
mkHeader' "constant" id us t u
| ConstantInfo.quotInfo { levelParams := us, type := t, .. } =>
mkHeader' "Quotient primitive" id us t false
| ConstantInfo.ctorInfo { levelParams := us, type := t, isUnsafe := u, .. } =>
mkHeader' "constructor" id us t u
| ConstantInfo.recInfo { levelParams := us, type := t, isUnsafe := u, .. } =>
mkHeader' "recursor" id us t u
| ConstantInfo.inductInfo
{ levelParams := us, numParams, numIndices, type := t, ctors, isUnsafe := u, .. } =>
printInduct id us numParams numIndices t ctors u
def diffExtension (old new : Environment)
(ext : PersistentEnvExtension EnvExtensionEntry EnvExtensionEntry EnvExtensionState) :
CoreM (Option MessageData) := unsafe do
let mut asyncMode := ext.toEnvExtension.asyncMode
if asyncMode matches .async .. then
-- allow for diffing async extensions by bumping mode to sync
asyncMode := .sync
let oldSt := ext.toEnvExtension.getState (asyncMode := asyncMode) old
let newSt := ext.toEnvExtension.getState (asyncMode := asyncMode) new
if ptrAddrUnsafe oldSt == ptrAddrUnsafe newSt then return none
let oldEntries := ext.exportEntriesFn (← getEnv) oldSt.state .private
let newEntries := ext.exportEntriesFn (← getEnv) newSt.state .private
pure m!"-- {ext.name} extension: {(newEntries.size - oldEntries.size : Int)} new entries"
def whatsNew (old new : Environment) : CoreM MessageData := do
let mut diffs := #[]
for (c, i) in new.constants.map₂.toList do
unless old.constants.map₂.contains c do
diffs := diffs.push (← printIdCore c i)
for ext in ← persistentEnvExtensionsRef.get do
if let some diff := ← diffExtension old new ext then
diffs := diffs.push diff
if diffs.isEmpty then return "no new constants"
pure <| MessageData.joinSep diffs.toList "\n\n"
/-- `whatsnew in $command` executes the command and then prints the
declarations that were added to the environment. -/
elab "whatsnew " "in" ppLine cmd:command : command => do
let oldEnv ← getEnv
try
elabCommand cmd
finally
let newEnv ← getEnv
logInfo (← liftCoreM <| whatsNew oldEnv newEnv)
end Mathlib.WhatsNew
|
Nilpotent.lean
|
/-
Copyright (c) 2021 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Ines Wright, Joachim Breitner
-/
import Mathlib.GroupTheory.Solvable
import Mathlib.GroupTheory.Sylow
import Mathlib.Algebra.Group.Subgroup.Order
import Mathlib.GroupTheory.Commutator.Finite
/-!
# Nilpotent groups
An API for nilpotent groups, that is, groups for which the upper central series
reaches `⊤`.
## Main definitions
Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated
by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the
subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`.
* `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`.
This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and
`H (n + 1) / H n` is the centre of `G / H n`.
* `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`.
This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and
`H (n + 1) = ⁅H n, G⁆`.
* `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or
equivalently if its lower central series reaches `⊥`.
* `Group.nilpotencyClass` : the length of the upper central series of a nilpotent group.
* `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and
* `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature
a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups
`H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)`
central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates
on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central
series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series
may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an
*ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no
requirement that the series reaches `⊤` or that the `H i` are normal.
## Main theorems
`G` is *defined* to be nilpotent if the upper central series reaches `⊤`.
* `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central
series reaches `⊤`.
* `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central
series reaches `⊥`.
* `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`.
* The `Group.nilpotencyClass` can likewise be obtained from these equivalent
definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`,
`least_descending_central_series_length_eq_nilpotencyClass` and
`lowerCentralSeries_length_eq_nilpotencyClass`.
* If `G` is nilpotent, then so are its subgroups, images, quotients and preimages.
Binary and finite products of nilpotent groups are nilpotent.
Infinite products are nilpotent if their nilpotent class is bounded.
Corresponding lemmas about the `Group.nilpotencyClass` are provided.
* The `Group.nilpotencyClass` of `G ⧸ center G` is given explicitly, and an induction principle
is derived from that.
* `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable.
## Warning
A "central series" is usually defined to be a finite sequence of normal subgroups going
from `⊥` to `⊤` with the property that each subquotient is contained within the centre of
the associated quotient of `G`. This means that if `G` is not nilpotent, then
none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or
the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries`
are actually central series. Note that the fact that the upper and lower central series
are not central series if `G` is not nilpotent is a standard abuse of notation.
-/
open Subgroup
section WithGroup
variable {G : Type*} [Group G] (H : Subgroup G) [Normal H]
/-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}`
is a subgroup of `G` (because it is the preimage in `G` of the centre of the
quotient group `G/H`.)
-/
def upperCentralSeriesStep : Subgroup G where
carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H }
one_mem' y := by simp
mul_mem' {a b} ha hb y := by
convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1
group
inv_mem' {x} hx y := by
specialize hx y⁻¹
rw [mul_assoc, inv_inv] at hx ⊢
exact Subgroup.Normal.mem_comm inferInstance hx
theorem mem_upperCentralSeriesStep (x : G) :
x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl
open QuotientGroup
/-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under
the canonical surjection. -/
theorem upperCentralSeriesStep_eq_comap_center :
upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by
ext
rw [mem_comap, mem_center_iff, forall_mk]
apply forall_congr'
intro y
rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem,
div_eq_mul_inv, mul_inv_rev, mul_assoc]
instance : Normal (upperCentralSeriesStep H) := by
rw [upperCentralSeriesStep_eq_comap_center]
infer_instance
variable (G)
/-- An auxiliary type-theoretic definition defining both the upper central series of
a group, and a proof that it is normal, all in one go. -/
def upperCentralSeriesAux : ℕ → Σ' H : Subgroup G, Normal H
| 0 => ⟨⊥, inferInstance⟩
| n + 1 =>
let un := upperCentralSeriesAux n
let _un_normal := un.2
⟨upperCentralSeriesStep un.1, inferInstance⟩
/-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`.
This is the increasing chain of subgroups of `G` that starts with the trivial subgroup `⊥` of `G`
and then continues defining `upperCentralSeries G (n + 1)` to be all the elements of `G`
that, modulo `upperCentralSeries G n`, belong to the center of the quotient
`G ⧸ upperCentralSeries G n`.
In particular, the identities
* `upperCentralSeries G 0 = ⊥` (`upperCentralSeries_zero`);
* `upperCentralSeries G 1 = center G` (`upperCentralSeries_one`);
hold.
-/
def upperCentralSeries (n : ℕ) : Subgroup G :=
(upperCentralSeriesAux G n).1
instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) :=
(upperCentralSeriesAux G n).2
@[simp]
theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl
@[simp]
theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by
ext
simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep, mem_bot, mem_mk,
Submonoid.mem_mk, Subsemigroup.mem_mk, Set.mem_setOf_eq, mem_center_iff]
exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm]
variable {G}
/-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such
that `⁅x,G⁆ ⊆ H n`. -/
theorem mem_upperCentralSeries_succ_iff {n : ℕ} {x : G} :
x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n :=
Iff.rfl
@[simp] lemma comap_upperCentralSeries {H : Type*} [Group H] (e : H ≃* G) :
∀ n, (upperCentralSeries G n).comap e = upperCentralSeries H n
| 0 => by simpa [MonoidHom.ker_eq_bot_iff] using e.injective
| n + 1 => by
ext
simp [mem_upperCentralSeries_succ_iff, ← comap_upperCentralSeries e n,
← e.toEquiv.forall_congr_right]
namespace Group
variable (G) in
-- `IsNilpotent` is already defined in the root namespace (for elements of rings).
-- TODO: Rename it to `IsNilpotentElement`?
/-- A group `G` is nilpotent if its upper central series is eventually `G`. -/
@[mk_iff]
class IsNilpotent (G : Type*) [Group G] : Prop where
nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤
lemma IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] :
∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent'
lemma isNilpotent_congr {H : Type*} [Group H] (e : G ≃* H) : IsNilpotent G ↔ IsNilpotent H := by
simp_rw [isNilpotent_iff]
refine exists_congr fun n ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simp [← Subgroup.comap_top e.symm.toMonoidHom, ← h]
· simp [← Subgroup.comap_top e.toMonoidHom, ← h]
@[simp] lemma isNilpotent_top : IsNilpotent (⊤ : Subgroup G) ↔ IsNilpotent G :=
isNilpotent_congr Subgroup.topEquiv
variable (G) in
/-- A group `G` is virtually nilpotent if it has a nilpotent cofinite subgroup `N`. -/
def IsVirtuallyNilpotent : Prop := ∃ N : Subgroup G, IsNilpotent N ∧ FiniteIndex N
lemma IsNilpotent.isVirtuallyNilpotent (hG : IsNilpotent G) : IsVirtuallyNilpotent G :=
⟨⊤, by simpa, inferInstance⟩
end Group
open Group
/-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and
`⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/
def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop :=
H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n
/-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and
`⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/
def IsDescendingCentralSeries (H : ℕ → Subgroup G) :=
H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1)
/-- Any ascending central series for a group is bounded above by the upper central series. -/
theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) :
∀ n : ℕ, H n ≤ upperCentralSeries G n
| 0 => hH.1.symm ▸ le_refl ⊥
| n + 1 => by
intro x hx
rw [mem_upperCentralSeries_succ_iff]
exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y)
variable (G)
/-- The upper central series of a group is an ascending central series. -/
theorem upperCentralSeries_isAscendingCentralSeries :
IsAscendingCentralSeries (upperCentralSeries G) :=
⟨rfl, fun _x _n h => h⟩
theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by
refine monotone_nat_of_le_succ ?_
intro n x hx y
rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹]
exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y)
/-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in
finitely many steps. -/
theorem nilpotent_iff_finite_ascending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by
constructor
· rintro ⟨n, nH⟩
exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩
· rintro ⟨n, H, hH, hn⟩
use n
rw [eq_top_iff, ← hn]
exact ascending_central_series_le_upper H hH n
theorem is_descending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤)
(hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hasc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp at hx
by_cases hm : n ≤ m
· rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx
subst hx
rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group]
exact Subgroup.one_mem _
· push_neg at hm
apply hH
convert hx using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥)
(hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hdesc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp only at hx ⊢
by_cases hm : n ≤ m
· have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm
rw [hnm, h0]
exact mem_top _
· push_neg at hm
convert hH x _ hx g using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
/-- A group `G` is nilpotent iff there exists a descending central series which reaches the
trivial group in a finite time. -/
theorem nilpotent_iff_finite_descending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by
rw [nilpotent_iff_finite_ascending_central_series]
constructor
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
/-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined
by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/
def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G
| 0 => ⊤
| n + 1 => ⁅lowerCentralSeries G n, ⊤⁆
variable {G}
@[simp]
theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl
@[simp]
theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl
theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) :
q ∈ lowerCentralSeries G (n + 1) ↔
q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n,
∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl
theorem lowerCentralSeries_succ (n : ℕ) :
lowerCentralSeries G (n + 1) =
closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } :=
rfl
instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by
induction n with
| zero => exact (⊤ : Subgroup G).normal_of_characteristic
| succ d hd => exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _
theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by
refine antitone_nat_of_succ_le fun n x hx => ?_
simp only [mem_lowerCentralSeries_succ_iff, mem_top,
true_and] at hx
refine
closure_induction ?_ (Subgroup.one_mem _) (fun _ _ _ _ ↦ mul_mem) (fun _ _ ↦ inv_mem) hx
rintro y ⟨z, hz, a, ha⟩
rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹]
exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a)
/-- The lower central series of a group is a descending central series. -/
theorem lowerCentralSeries_isDescendingCentralSeries :
IsDescendingCentralSeries (lowerCentralSeries G) := by
constructor
· rfl
intro x n hxn g
exact commutator_mem_commutator hxn (mem_top g)
/-- Any descending central series for a group is bounded below by the lower central series. -/
theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) :
∀ n : ℕ, lowerCentralSeries G n ≤ H n
| 0 => hH.1.symm ▸ le_refl ⊤
| n + 1 => commutator_le.mpr fun x hx q _ =>
hH.2 x n (descending_central_series_ge_lower H hH n hx) q
/-- A group is nilpotent if and only if its lower central series eventually reaches
the trivial subgroup. -/
theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by
rw [nilpotent_iff_finite_descending_central_series]
constructor
· rintro ⟨n, H, ⟨h0, hs⟩, hn⟩
use n
rw [eq_bot_iff, ← hn]
exact descending_central_series_ge_lower H ⟨h0, hs⟩ n
· rintro ⟨n, hn⟩
exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩
section Classical
variable [hG : IsNilpotent G]
variable (G) in
open scoped Classical in
/-- The nilpotency class of a nilpotent group is the smallest natural `n` such that
the `n`'th term of the upper central series is `G`. -/
noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G)
open scoped Classical in
@[simp]
theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ :=
Nat.find_spec (IsNilpotent.nilpotent G)
theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} :
upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
exact Nat.find_le h
· intro h
rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass]
exact upperCentralSeries_mono _ h
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending
central series reaches `G` in its `n`'th term. -/
theorem least_ascending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) =
Group.nilpotencyClass G := by
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· intro n hn
exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← top_le_iff, ← hn]
exact ascending_central_series_le_upper H hH n
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending
central series reaches `⊥` in its `n`'th term. -/
theorem least_descending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) =
Group.nilpotencyClass G := by
rw [← least_ascending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/
theorem lowerCentralSeries_length_eq_nilpotencyClass :
Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = Group.nilpotencyClass (G := G) := by
rw [← least_descending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← le_bot_iff, ← hn]
exact descending_central_series_ge_lower H hH n
· rintro n h
exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩
@[simp]
theorem lowerCentralSeries_nilpotencyClass :
lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ := by
classical
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG)
theorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} :
lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_le h
· intro h
rw [eq_bot_iff, ← lowerCentralSeries_nilpotencyClass]
exact lowerCentralSeries_antitone h
end Classical
theorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) :
(lowerCentralSeries H n).map H.subtype ≤ lowerCentralSeries G n := by
induction n with
| zero => simp
| succ d hd =>
rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure]
apply Subgroup.closure_mono
rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩
exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩
/-- A subgroup of a nilpotent group is nilpotent -/
instance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H := by
rw [nilpotent_iff_lowerCentralSeries] at *
rcases hG with ⟨n, hG⟩
use n
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
/-- The nilpotency class of a subgroup is less or equal to the nilpotency class of the group -/
theorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] :
Group.nilpotencyClass H ≤ Group.nilpotencyClass G := by
repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass]
classical apply Nat.find_mono
intro n hG
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
instance (priority := 100) Group.isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G :=
nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩
theorem upperCentralSeries.map {H : Type*} [Group H] {f : G →* H} (h : Function.Surjective f)
(n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n := by
induction n with
| zero => simp
| succ d hd =>
rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y'
rcases h y' with ⟨y, rfl⟩
simpa using hd (mem_map_of_mem f (hx y))
theorem lowerCentralSeries.map {H : Type*} [Group H] (f : G →* H) (n : ℕ) :
Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n := by
induction n with
| zero => simp
| succ d hd =>
rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩
refine closure_induction (hx := hx) ?_ (by simp [f.map_one, Subgroup.one_mem _])
(fun y z _ _ hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y _ hy => by
rw [f.map_inv]; exact Subgroup.inv_mem _ hy)
rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩
apply mem_closure.mpr
exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩
theorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) :
lowerCentralSeries G (n + 1) = ⊥ := by
rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff]
rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩
rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm]
exact mem_center_iff.mp (h hy1) z
/-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained
in the center -/
theorem isNilpotent_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G)
(hH : IsNilpotent H) : IsNilpotent G := by
rw [nilpotent_iff_lowerCentralSeries] at *
rcases hH with ⟨n, hn⟩
use n + 1
refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1)
exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n)
theorem nilpotencyClass_le_of_ker_le_center {H : Type*} [Group H] (f : G →* H)
(hf1 : f.ker ≤ center G) (hH : IsNilpotent H) :
Group.nilpotencyClass (hG := isNilpotent_of_ker_le_center f hf1 hH) ≤
Group.nilpotencyClass H + 1 := by
haveI : IsNilpotent G := isNilpotent_of_ker_le_center f hf1 hH
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
classical apply Nat.find_min'
refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1)
rw [eq_bot_iff]
apply le_trans (lowerCentralSeries.map f _)
simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff]
/-- The range of a surjective homomorphism from a nilpotent group is nilpotent -/
theorem nilpotent_of_surjective {G' : Type*} [Group G'] [h : IsNilpotent G] (f : G →* G')
(hf : Function.Surjective f) : IsNilpotent G' := by
rcases h with ⟨n, hn⟩
use n
apply eq_top_iff.mpr
calc
⊤ = f.range := symm (f.range_eq_top_of_surjective hf)
_ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _
_ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]
_ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n
/-- The nilpotency class of the range of a surjective homomorphism from a
nilpotent group is less or equal the nilpotency class of the domain -/
theorem nilpotencyClass_le_of_surjective {G' : Type*} [Group G'] (f : G →* G')
(hf : Function.Surjective f) [h : IsNilpotent G] :
Group.nilpotencyClass (hG := nilpotent_of_surjective _ hf) ≤ Group.nilpotencyClass G := by
classical apply Nat.find_mono
intro n hn
rw [eq_top_iff]
calc
⊤ = f.range := symm (f.range_eq_top_of_surjective hf)
_ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _
_ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]
_ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n
/-- Nilpotency respects isomorphisms -/
theorem nilpotent_of_mulEquiv {G' : Type*} [Group G'] [_h : IsNilpotent G] (f : G ≃* G') :
IsNilpotent G' :=
nilpotent_of_surjective f.toMonoidHom (MulEquiv.surjective f)
/-- A quotient of a nilpotent group is nilpotent -/
instance nilpotent_quotient_of_nilpotent (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] :
IsNilpotent (G ⧸ H) :=
nilpotent_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective
/-- The nilpotency class of a quotient of `G` is less or equal the nilpotency class of `G` -/
theorem nilpotencyClass_quotient_le (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] :
Group.nilpotencyClass (G ⧸ H) ≤ Group.nilpotencyClass G :=
nilpotencyClass_le_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective
-- This technical lemma helps with rewriting the subgroup, which occurs in indices
private theorem comap_center_subst {H₁ H₂ : Subgroup G} [Normal H₁] [Normal H₂] (h : H₁ = H₂) :
comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) := by subst h; rfl
theorem comap_upperCentralSeries_quotient_center (n : ℕ) :
comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G n.succ := by
induction n with
| zero =>
simp only [upperCentralSeries_zero, MonoidHom.comap_bot, ker_mk',
(upperCentralSeries_one G).symm]
| succ n ih =>
let Hn := upperCentralSeries (G ⧸ center G) n
calc
comap (mk' (center G)) (upperCentralSeriesStep Hn) =
comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) := by
rw [upperCentralSeriesStep_eq_comap_center]
_ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) :=
QuotientGroup.comap_comap_center
_ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) :=
(comap_center_subst ih)
_ = upperCentralSeriesStep (upperCentralSeries G n.succ) :=
symm (upperCentralSeriesStep_eq_comap_center _)
theorem nilpotencyClass_zero_iff_subsingleton [IsNilpotent G] :
Group.nilpotencyClass G = 0 ↔ Subsingleton G := by
classical
rw [Group.nilpotencyClass, Nat.find_eq_zero, upperCentralSeries_zero,
subsingleton_iff_bot_eq_top, Subgroup.subsingleton_iff]
/-- Quotienting the `center G` reduces the nilpotency class by 1 -/
theorem nilpotencyClass_quotient_center [hH : IsNilpotent G] :
Group.nilpotencyClass (G ⧸ center G) = Group.nilpotencyClass G - 1 := by
generalize hn : Group.nilpotencyClass G = n
rcases n with (rfl | n)
· simp only [nilpotencyClass_zero_iff_subsingleton, zero_tsub] at *
exact Quotient.instSubsingletonQuotient (leftRel (center G))
· suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa
apply le_antisymm
· apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp
apply comap_injective (f := (mk' (center G))) Quot.mk_surjective
rw [comap_upperCentralSeries_quotient_center, comap_top, Nat.succ_eq_add_one, ← hn]
exact upperCentralSeries_nilpotencyClass
· apply le_of_add_le_add_right
calc
n + 1 = Group.nilpotencyClass G := hn.symm
_ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 :=
nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk' _)) _
/-- The nilpotency class of a non-trivial group is one more than its quotient by the center -/
theorem nilpotencyClass_eq_quotient_center_plus_one [hH : IsNilpotent G] [Nontrivial G] :
Group.nilpotencyClass G = Group.nilpotencyClass (G ⧸ center G) + 1 := by
rw [nilpotencyClass_quotient_center]
rcases h : Group.nilpotencyClass G with ⟨⟩
· exfalso
rw [nilpotencyClass_zero_iff_subsingleton] at h
apply false_of_nontrivial_of_subsingleton G
· simp
/-- If the quotient by `center G` is nilpotent, then so is G. -/
theorem of_quotient_center_nilpotent (h : IsNilpotent (G ⧸ center G)) : IsNilpotent G := by
obtain ⟨n, hn⟩ := h.nilpotent
use n.succ
simp [← comap_upperCentralSeries_quotient_center, hn]
/-- A custom induction principle for nilpotent groups. The base case is a trivial group
(`subsingleton G`), and in the induction step, one can assume the hypothesis for
the group quotiented by its center. -/
@[elab_as_elim]
theorem nilpotent_center_quotient_ind {P : ∀ (G) [Group G] [IsNilpotent G], Prop}
(G : Type*) [Group G] [IsNilpotent G]
(hbase : ∀ (G) [Group G] [Subsingleton G], P G)
(hstep : ∀ (G) [Group G] [IsNilpotent G], P (G ⧸ center G) → P G) : P G := by
obtain ⟨n, h⟩ : ∃ n, Group.nilpotencyClass G = n := ⟨_, rfl⟩
induction n generalizing G with
| zero =>
haveI := nilpotencyClass_zero_iff_subsingleton.mp h
exact hbase _
| succ n ih =>
have hn : Group.nilpotencyClass (G ⧸ center G) = n := by
simp [nilpotencyClass_quotient_center, h]
exact hstep _ (ih _ hn)
theorem derived_le_lower_central (n : ℕ) : derivedSeries G n ≤ lowerCentralSeries G n := by
induction n with
| zero => simp
| succ i ih => apply commutator_mono ih; simp
/-- Abelian groups are nilpotent -/
instance (priority := 100) CommGroup.isNilpotent {G : Type*} [CommGroup G] : IsNilpotent G := by
use 1
rw [upperCentralSeries_one]
apply CommGroup.center_eq_top
/-- Abelian groups have nilpotency class at most one -/
theorem CommGroup.nilpotencyClass_le_one {G : Type*} [CommGroup G] :
Group.nilpotencyClass G ≤ 1 := by
rw [← upperCentralSeries_eq_top_iff_nilpotencyClass_le, upperCentralSeries_one]
apply CommGroup.center_eq_top
/-- Groups with nilpotency class at most one are abelian -/
def commGroupOfNilpotencyClass [IsNilpotent G] (h : Group.nilpotencyClass G ≤ 1) : CommGroup G :=
Group.commGroupOfCenterEqTop <| by
rw [← upperCentralSeries_one]
exact upperCentralSeries_eq_top_iff_nilpotencyClass_le.mpr h
section Prod
variable {G₁ G₂ : Type*} [Group G₁] [Group G₂]
theorem lowerCentralSeries_prod (n : ℕ) :
lowerCentralSeries (G₁ × G₂) n = (lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n) := by
induction n with
| zero => simp
| succ n ih =>
calc
lowerCentralSeries (G₁ × G₂) n.succ = ⁅lowerCentralSeries (G₁ × G₂) n, ⊤⁆ := rfl
_ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), ⊤⁆ := by rw [ih]
_ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), (⊤ : Subgroup G₁).prod ⊤⁆ := by
simp
_ = ⁅lowerCentralSeries G₁ n, (⊤ : Subgroup G₁)⁆.prod ⁅lowerCentralSeries G₂ n, ⊤⁆ :=
(commutator_prod_prod _ _ _ _)
_ = (lowerCentralSeries G₁ n.succ).prod (lowerCentralSeries G₂ n.succ) := rfl
/-- Products of nilpotent groups are nilpotent -/
instance isNilpotent_prod [IsNilpotent G₁] [IsNilpotent G₂] : IsNilpotent (G₁ × G₂) := by
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂), ?_⟩
rw [lowerCentralSeries_prod,
lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_left _ _),
lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_right _ _), bot_prod_bot]
/-- The nilpotency class of a product is the max of the nilpotency classes of the factors -/
theorem nilpotencyClass_prod [IsNilpotent G₁] [IsNilpotent G₂] :
Group.nilpotencyClass (G₁ × G₂) =
max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂) := by
refine eq_of_forall_ge_iff fun k => ?_
simp only [max_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,
lowerCentralSeries_prod, prod_eq_bot_iff]
end Prod
section BoundedPi
-- First the case of infinite products with bounded nilpotency class
variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)]
theorem lowerCentralSeries_pi_le (n : ℕ) :
lowerCentralSeries (∀ i, Gs i) n ≤ Subgroup.pi Set.univ
fun i => lowerCentralSeries (Gs i) n := by
let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f
induction n with
| zero => simp [pi_top]
| succ n ih =>
calc
lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl
_ ≤ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_mono ih (le_refl _)
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]
_ ≤ pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_le _ _
_ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl
/-- products of nilpotent groups are nilpotent if their nilpotency class is bounded -/
theorem isNilpotent_pi_of_bounded_class [∀ i, IsNilpotent (Gs i)] (n : ℕ)
(h : ∀ i, Group.nilpotencyClass (Gs i) ≤ n) : IsNilpotent (∀ i, Gs i) := by
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨n, ?_⟩
rw [eq_bot_iff]
apply le_trans (lowerCentralSeries_pi_le _)
rw [← eq_bot_iff, pi_eq_bot_iff]
intro i
apply lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (h i)
end BoundedPi
section FinitePi
-- Now for finite products
variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)]
theorem lowerCentralSeries_pi_of_finite [Finite η] (n : ℕ) :
lowerCentralSeries (∀ i, Gs i) n = Subgroup.pi Set.univ
fun i => lowerCentralSeries (Gs i) n := by
let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f
induction n with
| zero => simp [pi_top]
| succ n ih =>
calc
lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := by rw [ih]
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]
_ = pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_of_finite _ _
_ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl
/-- n-ary products of nilpotent groups are nilpotent -/
instance isNilpotent_pi [Finite η] [∀ i, IsNilpotent (Gs i)] : IsNilpotent (∀ i, Gs i) := by
cases nonempty_fintype η
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨Finset.univ.sup fun i => Group.nilpotencyClass (Gs i), ?_⟩
rw [lowerCentralSeries_pi_of_finite, pi_eq_bot_iff]
intro i
rw [lowerCentralSeries_eq_bot_iff_nilpotencyClass_le]
exact Finset.le_sup (f := fun i => Group.nilpotencyClass (Gs i)) (Finset.mem_univ i)
/-- The nilpotency class of an n-ary product is the sup of the nilpotency classes of the factors -/
theorem nilpotencyClass_pi [Fintype η] [∀ i, IsNilpotent (Gs i)] :
Group.nilpotencyClass (∀ i, Gs i) = Finset.univ.sup fun i => Group.nilpotencyClass (Gs i) := by
apply eq_of_forall_ge_iff
intro k
simp only [Finset.sup_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,
lowerCentralSeries_pi_of_finite, pi_eq_bot_iff, Finset.mem_univ, true_imp_iff]
end FinitePi
/-- A nilpotent subgroup is solvable -/
instance (priority := 100) IsNilpotent.to_isSolvable [h : IsNilpotent G] : IsSolvable G := by
obtain ⟨n, hn⟩ := nilpotent_iff_lowerCentralSeries.1 h
use n
rw [eq_bot_iff, ← hn]
exact derived_le_lower_central n
theorem normalizerCondition_of_isNilpotent [h : IsNilpotent G] : NormalizerCondition G := by
-- roughly based on https://groupprops.subwiki.org/wiki/Nilpotent_implies_normalizer_condition
rw [normalizerCondition_iff_only_full_group_self_normalizing]
apply @nilpotent_center_quotient_ind _ G _ _ <;> clear! G
· intro G _ _ H _
exact @Subsingleton.elim _ Unique.instSubsingleton _ _
· intro G _ _ ih H hH
have hch : center G ≤ H := Subgroup.center_le_normalizer.trans (le_of_eq hH)
have hkh : (mk' (center G)).ker ≤ H := by simpa using hch
have hsur : Function.Surjective (mk' (center G)) := Quot.mk_surjective
let H' := H.map (mk' (center G))
have hH' : H'.normalizer = H' := by
apply comap_injective hsur
rw [comap_normalizer_eq_of_surjective _ hsur, comap_map_eq_self hkh]
exact hH
apply map_injective_of_ker_le (mk' (center G)) hkh le_top
exact (ih H' hH').trans (symm (map_top_of_surjective _ hsur))
end WithGroup
section WithFiniteGroup
open Group Fintype
variable {G : Type*} [hG : Group G]
/-- A p-group is nilpotent -/
theorem IsPGroup.isNilpotent [Finite G] {p : ℕ} [hp : Fact (Nat.Prime p)] (h : IsPGroup p G) :
IsNilpotent G := by
cases nonempty_fintype G
classical
revert hG
apply @Fintype.induction_subsingleton_or_nontrivial _ G _
· intro _ _ _ _
infer_instance
· intro G _ _ ih _ h
have hcq : Fintype.card (G ⧸ center G) < Fintype.card G := by
simp only [← Nat.card_eq_fintype_card]
rw [card_eq_card_quotient_mul_card_subgroup (center G)]
simp only [Nat.card_eq_fintype_card]
apply lt_mul_of_one_lt_right
· exact Fintype.card_pos_iff.mpr One.instNonempty
· simp only [← Nat.card_eq_fintype_card]
exact (Subgroup.one_lt_card_iff_ne_bot _).mpr (ne_of_gt h.bot_lt_center)
have hnq : IsNilpotent (G ⧸ center G) := ih _ hcq (h.to_quotient (center G))
exact of_quotient_center_nilpotent hnq
variable [Finite G]
/-- If a finite group is the direct product of its Sylow groups, it is nilpotent -/
theorem isNilpotent_of_product_of_sylow_group
(e : (∀ p : (Nat.card G).primeFactors, ∀ P : Sylow p G, (↑P : Subgroup G)) ≃* G) :
IsNilpotent G := by
classical
let ps := (Nat.card G).primeFactors
have : ∀ (p : ps) (P : Sylow p G), IsNilpotent (↑P : Subgroup G) := by
intro p P
haveI : Fact (Nat.Prime ↑p) := Fact.mk <| Nat.prime_of_mem_primeFactors p.2
exact P.isPGroup'.isNilpotent
exact nilpotent_of_mulEquiv e
/-- A finite group is nilpotent iff the normalizer condition holds, and iff all maximal groups are
normal and iff all Sylow groups are normal and iff the group is the direct product of its Sylow
groups. -/
theorem isNilpotent_of_finite_tfae :
List.TFAE
[IsNilpotent G, NormalizerCondition G, ∀ H : Subgroup G, IsCoatom H → H.Normal,
∀ (p : ℕ) (_hp : Fact p.Prime) (P : Sylow p G), (↑P : Subgroup G).Normal,
Nonempty
((∀ p : (Nat.card G).primeFactors, ∀ P : Sylow p G, (↑P : Subgroup G)) ≃* G)] := by
tfae_have 1 → 2 := @normalizerCondition_of_isNilpotent _ _
tfae_have 2 → 3
| h, H => NormalizerCondition.normal_of_coatom H h
tfae_have 3 → 4
| h, p, _, P => Sylow.normal_of_all_max_subgroups_normal h _
tfae_have 4 → 5
| h => Nonempty.intro (Sylow.directProductOfNormal fun {p hp hP} => h p hp hP)
tfae_have 5 → 1
| ⟨e⟩ => isNilpotent_of_product_of_sylow_group e
tfae_finish
end WithFiniteGroup
|
AlgebraicClosure.lean
|
import Mathlib.Algebra.Algebra.Rat
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
variable {k : Type*} [Field k]
example : (AddCommMonoid.toNatModule : Module ℕ (AlgebraicClosure k)) =
@Algebra.toModule _ _ _ _ (AlgebraicClosure.instAlgebra k) := by
with_reducible_and_instances rfl
example : (AddCommGroup.toIntModule _ : Module ℤ (AlgebraicClosure k)) =
@Algebra.toModule _ _ _ _ (AlgebraicClosure.instAlgebra k) := by
with_reducible_and_instances rfl
example [CharZero k] : AlgebraicClosure.instAlgebra k = DivisionRing.toRatAlgebra :=
rfl
-- TODO: by with_reducible_and_instances rfl fails
example : Ring.toIntAlgebra (AlgebraicClosure ℚ) = AlgebraicClosure.instAlgebra ℚ :=
rfl
-- TODO: by with_reducible_and_instances rfl fails
|
choice.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.
(******************************************************************************)
(* Types with a choice operator *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file contains the definitions of: *)
(* choiceType == interface for types with a choice operator *)
(* The HB class is Choice. *)
(* The exact contents is documented below just before *)
(* hasChoice. *)
(* subChoiceType == interface for types that are both subType and choiceType *)
(* The HB class is SubChoice. *)
(* countType == interface for countable types (implies choiceType) *)
(* The HB class is Countable. *)
(* subCountType == interface for types that are both subType and countType *)
(* The HB class is SubCountable. *)
(* *)
(* xchoose exP == a standard x such that P x, given exP : exists x : T, P x *)
(* when T is a choiceType *)
(* The choice depends only on the extent of P (in particular,*)
(* it is independent of exP). *)
(* choose P x0 == if P x0, a standard x such that P x *)
(* pickle x == a nat encoding the value x : T, where T is a countType *)
(* unpickle n == a partial inverse to pickle: unpickle (pickle x) = Some x *)
(* pickle_inv n == a sharp partial inverse to pickle pickle_inv n = Some x *)
(* if and only if pickle x = n *)
(* *)
(* PCanIsCountable ff' == builds an instance of the isCountable interface *)
(* given ff' : pcancel f f' where the codomain of f is *)
(* a countType *)
(* CanIsCountable ff' == builds an instance of the isCountable interface *)
(* given ff' : cancel f f' where the codomain of f is *)
(* a countType *)
(* *)
(* [Choice of T by <:], [Countable of T by <:] == Choice/Countable interface *)
(* for T when T has a subType p structure with p : pred cT *)
(* and cT has a Choice/Countable interface *)
(* The corresponding structure is Canonical. This notation *)
(* is in form_scope. *)
(* *)
(* List of Choice/Countable factories with a dedicated alias: *)
(* pcan_type fK == Choice/Countable for T, given f : T -> cT where cT *)
(* has a Choice/Countable structure, a left inverse *)
(* partial function g and fK : pcancel f g *)
(* can_type fK == Choice/Countable for T, given f : T -> cT, g and *)
(* fK : cancel f g *)
(* *)
(* GenTree.tree T == generic n-ary tree type with nat-labeled nodes and *)
(* T-labeled leaves, for example GenTree.Leaf (x : T), *)
(* GenTree.Node 5 [:: t; t'] *)
(* GenTree.tree is equipped with eqType, choiceType, *)
(* and countType instances, and so simple datatypes *)
(* can be similarly equipped by encoding into *)
(* GenTree.tree and using the interfaces above. *)
(* CodeSeq.code == bijection from seq nat to nat *)
(* CodeSeq.decode == bijection inverse to CodeSeq.code *)
(* *)
(* In addition to the lemmas relevant to these definitions, this file also *)
(* contains definitions of choiceType and countType instances for all basic *)
(* basic datatypes (e.g., nat, bool, subTypes, pairs, sums, etc.). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(* Technical definitions about coding and decoding of nat sequences, which *)
(* are used below to define various Canonical instances of the choice and *)
(* countable interfaces. *)
Module CodeSeq.
(* Goedel-style one-to-one encoding of seq nat into nat. *)
(* The code for [:: n1; ...; nk] has binary representation *)
(* 1 0 ... 0 1 ... 1 0 ... 0 1 0 ... 0 *)
(* <-----> <-----> <-----> *)
(* nk 0s n2 0s n1 0s *)
Definition code := foldr (fun n m => 2 ^ n * m.*2.+1) 0.
Fixpoint decode_rec (v q r : nat) {struct q} :=
match q, r with
| 0, _ => [:: v]
| q'.+1, 0 => v :: [rec 0, q', q']
| q'.+1, 1 => [rec v.+1, q', q']
| q'.+1, r'.+2 => [rec v, q', r']
end where "[ 'rec' v , q , r ]" := (decode_rec v q r).
Arguments decode_rec : simpl nomatch.
Definition decode n := if n is 0 then [::] else [rec 0, n.-1, n.-1].
Lemma decodeK : cancel decode code.
Proof.
have m2s: forall n, n.*2 - n = n by move=> n; rewrite -addnn addnK.
case=> //= n; rewrite -[n.+1]mul1n -(expn0 2) -[n in RHS]m2s.
elim: n {2 4}n {1 3}0 => [|q IHq] [|[|r]] v //=; rewrite {}IHq ?mul1n ?m2s //.
by rewrite expnSr -mulnA mul2n.
Qed.
Lemma codeK : cancel code decode.
Proof.
elim=> //= v s IHs; rewrite -[_ * _]prednK ?muln_gt0 ?expn_gt0 //=.
set two := 2; rewrite -[v in RHS]addn0; elim: v 0 => [|v IHv {IHs}] q.
rewrite mul1n add0n /= -{}[in RHS]IHs; case: (code s) => // u; pose n := u.+1.
by transitivity [rec q, n + u.+1, n.*2]; [rewrite addnn | elim: n => //=].
rewrite expnS -mulnA mul2n -{1}addnn -[_ * _]prednK ?muln_gt0 ?expn_gt0 //.
set u := _.-1 in IHv *; set n := u; rewrite [in u1 in _ + u1]/n.
by rewrite [in RHS]addSnnS -{}IHv; elim: n.
Qed.
Lemma ltn_code s : all (fun j => j < code s) s.
Proof.
elim: s => //= i s IHs; rewrite -[_.+1]muln1 leq_mul 1?ltn_expl //=.
apply: sub_all IHs => j /leqW lejs; rewrite -[j.+1]mul1n leq_mul ?expn_gt0 //.
by rewrite ltnS -[j]mul1n -mul2n leq_mul.
Qed.
Lemma gtn_decode n : all (ltn^~ n) (decode n).
Proof. by rewrite -{1}[n]decodeK ltn_code. Qed.
End CodeSeq.
Section OtherEncodings.
(* Miscellaneous encodings: option T -c-> seq T, T1 * T2 -c-> {i : T1 & T2} *)
(* T1 + T2 -c-> option T1 * option T2, unit -c-> bool; bool -c-> nat is *)
(* already covered in ssrnat by the nat_of_bool coercion, the odd predicate, *)
(* and their "cancellation" lemma oddb. We use these encodings to propagate *)
(* canonical structures through these type constructors so that ultimately *)
(* all Choice and Countable instanced derive from nat and the seq and sigT *)
(* constructors. *)
Variables T T1 T2 : Type.
Definition seq_of_opt := @oapp T _ (nseq 1) [::].
Lemma seq_of_optK : cancel seq_of_opt ohead. Proof. by case. Qed.
Definition tag_of_pair (p : T1 * T2) := @Tagged T1 p.1 (fun _ => T2) p.2.
Definition pair_of_tag (u : {i : T1 & T2}) := (tag u, tagged u).
Lemma tag_of_pairK : cancel tag_of_pair pair_of_tag. Proof. by case. Qed.
Lemma pair_of_tagK : cancel pair_of_tag tag_of_pair. Proof. by case. Qed.
Definition opair_of_sum (s : T1 + T2) :=
match s with inl x => (Some x, None) | inr y => (None, Some y) end.
Definition sum_of_opair p :=
oapp (some \o @inr T1 T2) (omap (@inl _ T2) p.1) p.2.
Lemma opair_of_sumK : pcancel opair_of_sum sum_of_opair. Proof. by case. Qed.
Lemma bool_of_unitK : cancel (fun _ => true) (fun _ => tt).
Proof. by case. Qed.
End OtherEncodings.
Prenex Implicits seq_of_opt tag_of_pair pair_of_tag opair_of_sum sum_of_opair.
Prenex Implicits seq_of_optK tag_of_pairK pair_of_tagK opair_of_sumK.
(* Generic variable-arity tree type, providing an encoding target for *)
(* miscellaneous user datatypes. The GenTree.tree type can be combined with *)
(* a sigT type to model multi-sorted concrete datatypes. *)
Module GenTree.
Section Def.
Variable T : Type.
Unset Elimination Schemes.
Inductive tree := Leaf of T | Node of nat & seq tree.
Definition tree_rect K IH_leaf IH_node :=
fix loop t : K t := match t with
| Leaf x => IH_leaf x
| Node n f0 =>
let fix iter_pair f : foldr (fun t => prod (K t)) unit f :=
if f is t :: f' then (loop t, iter_pair f') else tt in
IH_node n f0 (iter_pair f0)
end.
Definition tree_rec (K : tree -> Set) := @tree_rect K.
Definition tree_ind K IH_leaf IH_node :=
fix loop t : K t : Prop := match t with
| Leaf x => IH_leaf x
| Node n f0 =>
let fix iter_conj f : foldr (fun t => and (K t)) True f :=
if f is t :: f' then conj (loop t) (iter_conj f') else Logic.I
in IH_node n f0 (iter_conj f0)
end.
Fixpoint encode t : seq (nat + T) :=
match t with
| Leaf x => [:: inr _ x]
| Node n f => inl _ n.+1 :: rcons (flatten (map encode f)) (inl _ 0)
end.
Definition decode_step c fs :=
match c with
| inr x => (Leaf x :: fs.1, fs.2)
| inl 0 => ([::], fs.1 :: fs.2)
| inl n.+1 => (Node n fs.1 :: head [::] fs.2, behead fs.2)
end.
Definition decode c := ohead (foldr decode_step ([::], [::]) c).1.
Lemma codeK : pcancel encode decode.
Proof.
move=> t; rewrite /decode; set fs := (_, _).
suffices ->: foldr decode_step fs (encode t) = (t :: fs.1, fs.2) by [].
elim: t => //= n f IHt in (fs) *; elim: f IHt => //= t f IHf [].
by rewrite rcons_cat foldr_cat => -> /= /IHf[-> -> ->].
Qed.
End Def.
End GenTree.
Arguments GenTree.codeK : clear implicits.
HB.instance Definition _ (T : eqType) := Equality.copy (GenTree.tree T)
(pcan_type (GenTree.codeK T)).
(* Structures for Types with a choice function, and for Types with countably *)
(* many elements. The two concepts are closely linked: we indeed make *)
(* Countable a subclass of Choice, as countable choice is valid in CiC. This *)
(* apparent redundancy is needed to ensure the consistency of the Canonical *)
(* inference, as the canonical Choice for a given type may differ from the *)
(* countable choice for its canonical Countable structure, e.g., for options. *)
(* The Choice interface exposes two choice functions; for T : choiceType *)
(* and P : pred T, we provide: *)
(* xchoose : (exists x, P x) -> T *)
(* choose : pred T -> T -> T *)
(* While P (xchoose exP) will always hold, P (choose P x0) will be true if *)
(* and only if P x0 holds. Both xchoose and choose are extensional in P and *)
(* do not depend on the witness exP or x0 (provided P x0 holds). Note that *)
(* xchoose is slightly more powerful, but less convenient to use. *)
(* However, neither choose nor xchoose are composable: it would not be *)
(* be possible to extend the Choice structure to arbitrary pairs using only *)
(* these functions, for instance. Internally, the interfaces provides a *)
(* subtly stronger operation, Choice.InternalTheory.find, which performs a *)
(* limited search using an integer parameter only rather than a full value as *)
(* [x]choose does. This is not a restriction in a constructive theory, where *)
(* all types are concrete and hence countable. In the case of an axiomatic *)
(* theory, such as that of the Coq reals library, postulating a suitable *)
(* axiom of choice suppresses the need for guidance. Nevertheless this *)
(* operation is just what is needed to make the Choice interface compose. *)
(* The Countable interface provides three functions; for T : countType we *)
(* get pickle : T -> nat, and unpickle, pickle_inv : nat -> option T. *)
(* The functions provide an effective embedding of T in nat: unpickle is a *)
(* left inverse to pickle, which satisfies pcancel pickle unpickle, i.e., *)
(* unpickle \o pickle =1 some; pickle_inv is a more precise inverse for which *)
(* we also have ocancel pickle_inv pickle. Both unpickle and pickle need to *)
(* be partial functions to allow for possibly empty types such as {x | P x}. *)
(* The names of these functions underline the correspondence with the *)
(* notion of "Serializable" types in programming languages. *)
(* Finally, we need to provide a join class to let type inference unify *)
(* subType and countType class constraints, e.g., for a countable subType of *)
(* an uncountable choiceType (the issue does not arise earlier with eqType or *)
(* choiceType because in practice the base type of an Equality/Choice subType *)
(* is always an Equality/Choice Type). *)
HB.mixin Record hasChoice T := Mixin {
find_subdef : pred T -> nat -> option T;
choice_correct_subdef {P n x} : find_subdef P n = Some x -> P x;
choice_complete_subdef {P : pred T} :
(exists x, P x) -> exists n, find_subdef P n;
choice_extensional_subdef {P Q : pred T} :
P =1 Q -> find_subdef P =1 find_subdef Q
}.
#[short(type="choiceType")]
HB.structure Definition Choice := { T of hasChoice T & hasDecEq T}.
Module Export ChoiceNamespace.
Module Choice.
Module InternalTheory.
Notation find := find_subdef.
Notation correct := choice_correct_subdef.
Arguments correct {_ _ _ _}.
Notation complete := choice_complete_subdef.
Arguments complete {_ _}.
Notation extensional := choice_extensional_subdef.
Arguments extensional {_ _ _}.
Section InternalTheory.
Variable T : Choice.type.
Implicit Types P Q : pred T.
Fact xchoose_subproof P exP :
{x | find P (ex_minn (@choice_complete_subdef _ P exP)) = Some x}.
Proof.
case: (ex_minnP (complete exP)) => n.
by case: (find P n) => // x; exists x.
Qed.
End InternalTheory.
End InternalTheory.
End Choice.
End ChoiceNamespace.
Section ChoiceTheory.
Implicit Type T : choiceType.
Import Choice.InternalTheory CodeSeq.
Local Notation dc := decode.
Section OneType.
Variable T : choiceType.
Implicit Types P Q : pred T.
Definition xchoose P exP := sval (@xchoose_subproof T P exP).
Lemma xchooseP P exP : P (@xchoose P exP).
Proof. by rewrite /xchoose; case: (xchoose_subproof exP) => x /= /correct. Qed.
Lemma eq_xchoose P Q exP exQ : P =1 Q -> @xchoose P exP = @xchoose Q exQ.
Proof.
rewrite /xchoose => eqPQ.
case: (xchoose_subproof exP) => x; case: (xchoose_subproof exQ) => y /=.
case: ex_minnP => n; rewrite -(extensional eqPQ) => Pn minQn.
case: ex_minnP => m; rewrite !(extensional eqPQ) => Qm minPm.
by case: (eqVneq m n) => [-> -> [] //|]; rewrite eqn_leq minQn ?minPm.
Qed.
Lemma sigW P : (exists x, P x) -> {x | P x}.
Proof. by move=> exP; exists (xchoose exP); apply: xchooseP. Qed.
Lemma sig2W P Q : (exists2 x, P x & Q x) -> {x | P x & Q x}.
Proof.
move=> exPQ; have [|x /andP[]] := @sigW (predI P Q); last by exists x.
by have [x Px Qx] := exPQ; exists x; apply/andP.
Qed.
Lemma sig_eqW (vT : eqType) (lhs rhs : T -> vT) :
(exists x, lhs x = rhs x) -> {x | lhs x = rhs x}.
Proof.
move=> exP; suffices [x /eqP Ex]: {x | lhs x == rhs x} by exists x.
by apply: sigW; have [x /eqP Ex] := exP; exists x.
Qed.
Lemma sig2_eqW (vT : eqType) (P : pred T) (lhs rhs : T -> vT) :
(exists2 x, P x & lhs x = rhs x) -> {x | P x & lhs x = rhs x}.
Proof.
move=> exP; suffices [x Px /eqP Ex]: {x | P x & lhs x == rhs x} by exists x.
by apply: sig2W; have [x Px /eqP Ex] := exP; exists x.
Qed.
Definition choose P x0 :=
if insub x0 : {? x | P x} is Some (exist x Px) then
xchoose (ex_intro [eta P] x Px)
else x0.
Lemma chooseP P x0 : P x0 -> P (choose P x0).
Proof. by move=> Px0; rewrite /choose insubT xchooseP. Qed.
Lemma choose_id P x0 y0 : P x0 -> P y0 -> choose P x0 = choose P y0.
Proof. by move=> Px0 Py0; rewrite /choose !insubT /=; apply: eq_xchoose. Qed.
Lemma eq_choose P Q : P =1 Q -> choose P =1 choose Q.
Proof.
rewrite /choose => eqPQ x0.
do [case: insubP; rewrite eqPQ] => [[x Px] Qx0 _| ?]; last by rewrite insubN.
by rewrite insubT; apply: eq_xchoose.
Qed.
Section CanChoice.
Variables (sT : Type) (f : sT -> T).
Lemma PCanHasChoice f' : pcancel f f' -> hasChoice sT.
Proof.
move=> fK; pose liftP sP := [pred x | oapp sP false (f' x)].
pose sf sP := [fun n => obind f' (find (liftP sP) n)].
exists sf => [sP n x | sP [y sPy] | sP sQ eqPQ n] /=.
- by case Df: (find _ n) => //= [?] Dx; have:= correct Df; rewrite /= Dx.
- have [|n Pn] := @complete T (liftP sP); first by exists (f y); rewrite /= fK.
exists n; case Df: (find _ n) Pn => //= [x] _.
by have:= correct Df => /=; case: (f' x).
by congr (obind _ _); apply: extensional => x /=; case: (f' x) => /=.
Qed.
Definition CanHasChoice f' (fK : cancel f f') :=
PCanHasChoice (can_pcan fK).
HB.instance Definition _ f' (fK : pcancel f f') : hasChoice (pcan_type fK) :=
PCanHasChoice fK.
HB.instance Definition _ f' (fK : cancel f f') : hasChoice (can_type fK) :=
PCanHasChoice (can_pcan fK).
End CanChoice.
Section SubChoice.
Variables (P : pred T) (sT : subType P).
#[hnf] HB.instance Definition _ := Choice.copy (sub_type sT) (pcan_type valK).
End SubChoice.
Fact seq_hasChoice : hasChoice (seq T).
Proof.
pose r f := [fun xs => fun x : T => f (x :: xs) : option (seq T)].
pose fix f sP ns xs {struct ns} :=
if ns is n :: ns1 then let fr := r (f sP ns1) xs in obind fr (find fr n)
else if sP xs then Some xs else None.
exists (fun sP nn => f sP (dc nn) nil) => [sP n ys | sP [ys] | sP sQ eqPQ n].
- elim: {n}(dc n) nil => [|n ns IHs] xs /=; first by case: ifP => // sPxs [<-].
by case: (find _ n) => //= [x]; apply: IHs.
- rewrite -(cats0 ys); elim/last_ind: ys nil => [|ys y IHs] xs /=.
by move=> sPxs; exists 0; rewrite /= sPxs.
rewrite cat_rcons => /IHs[n1 sPn1] {IHs}.
have /complete[n]: exists z, f sP (dc n1) (z :: xs) by exists y.
case Df: (find _ n)=> // [x] _; exists (code (n :: dc n1)).
by rewrite codeK /= Df /= (correct Df).
elim: {n}(dc n) nil => [|n ns IHs] xs /=; first by rewrite eqPQ.
rewrite (@extensional _ _ (r (f sQ ns) xs)) => [|x]; last by rewrite IHs.
by case: find => /=.
Qed.
HB.instance Definition _ := seq_hasChoice.
End OneType.
Section TagChoice.
Variables (I : choiceType) (T_ : I -> choiceType).
Fact tagged_hasChoice : hasChoice {i : I & T_ i}.
Proof.
pose mkT i (x : T_ i) := Tagged T_ x.
pose ft tP n i := omap (mkT i) (find (tP \o mkT i) n).
pose fi tP ni nt := obind (ft tP nt) (find (ft tP nt) ni).
pose f tP n := if dc n is [:: ni; nt] then fi tP ni nt else None.
exists f => [tP n u | tP [[i x] tPxi] | sP sQ eqPQ n].
- rewrite /f /fi; case: (dc n) => [|ni [|nt []]] //=.
case: (find _ _) => //= [i]; rewrite /ft.
by case Df: (find _ _) => //= [x] [<-]; have:= correct Df.
- have /complete[nt tPnt]: exists y, (tP \o mkT i) y by exists x.
have{tPnt}: exists j, ft tP nt j by exists i; rewrite /ft; case: find tPnt.
case/complete=> ni tPn; exists (code [:: ni; nt]); rewrite /f codeK /fi.
by case Df: find tPn => //= [j] _; have:= correct Df.
rewrite /f /fi; case: (dc n) => [|ni [|nt []]] //=.
rewrite (@extensional _ _ (ft sQ nt)) => [|i].
by case: find => //= i; congr (omap _ _); apply: extensional => x /=.
by congr (omap _ _); apply: extensional => x /=.
Qed.
HB.instance Definition _ := tagged_hasChoice.
End TagChoice.
Fact nat_hasChoice : hasChoice nat.
Proof.
pose f := [fun (P : pred nat) n => if P n then Some n else None].
exists f => [P n m | P [n Pn] | P Q eqPQ n] /=; last by rewrite eqPQ.
by case: ifP => // Pn [<-].
by exists n; rewrite Pn.
Qed.
HB.instance Definition _ := nat_hasChoice.
HB.instance Definition _ := Choice.copy bool (can_type oddb).
HB.instance Definition _ := Choice.on bitseq.
HB.instance Definition _ := Choice.copy unit (can_type bool_of_unitK).
HB.instance Definition _ := Choice.copy void (pcan_type (of_voidK unit)).
HB.instance Definition _ T :=
Choice.copy (option T) (can_type (@seq_of_optK (Choice.sort T))).
HB.instance Definition _ (T1 T2 : choiceType) :=
Choice.copy (T1 * T2)%type (can_type (@tag_of_pairK T1 T2)).
HB.instance Definition _ (T1 T2 : choiceType) :=
Choice.copy (T1 + T2)%type (pcan_type (@opair_of_sumK T1 T2)).
HB.instance Definition _ T :=
Choice.copy (GenTree.tree T) (pcan_type (GenTree.codeK T)).
End ChoiceTheory.
#[short(type="subChoiceType")]
HB.structure Definition SubChoice T (P : pred T) :=
{ sT of Choice sT & isSub T P sT }.
Prenex Implicits xchoose choose.
Notation "[ 'Choice' 'of' T 'by' <: ]" := (Choice.copy T%type (sub_type T%type))
(format "[ 'Choice' 'of' T 'by' <: ]") : form_scope.
HB.instance Definition _ (T : choiceType) (P : pred T) :=
[Choice of {x | P x} by <:].
HB.mixin Record Choice_isCountable (T : Type) : Type := {
pickle : T -> nat;
unpickle : nat -> option T;
pickleK : pcancel pickle unpickle
}.
Arguments Choice_isCountable.axioms_ T%_type_scope.
#[short(type="countType")]
HB.structure Definition Countable := { T of Choice T & Choice_isCountable T }.
HB.factory Record isCountable (T : Type) : Type := {
pickle : T -> nat;
unpickle : nat -> option T;
pickleK : pcancel pickle unpickle
}.
HB.builders Context T of isCountable T.
HB.instance Definition _ := Equality.copy T (pcan_type pickleK).
HB.instance Definition _ := PCanHasChoice pickleK.
HB.instance Definition _ := Choice_isCountable.Build T pickleK.
HB.end.
Arguments isCountable.axioms_ T%_type_scope.
Section CountableTheory.
Variable T : countType.
Definition pickle_inv n :=
obind (fun x : T => if pickle x == n then Some x else None) (unpickle n).
Lemma pickle_invK : ocancel pickle_inv pickle.
Proof.
by rewrite /pickle_inv => n; case def_x: (unpickle n) => //= [x]; case: eqP.
Qed.
Lemma pickleK_inv : pcancel pickle pickle_inv.
Proof. by rewrite /pickle_inv => x; rewrite pickleK /= eqxx. Qed.
Lemma pcan_pickleK sT f f' :
@pcancel T sT f f' -> pcancel (pickle \o f) (pcomp f' unpickle).
Proof. by move=> fK x; rewrite /pcomp pickleK /= fK. Qed.
Definition PCanIsCountable sT (f : sT -> T) f' (fK : pcancel f f') :=
isCountable.Build sT (pcan_pickleK fK).
Definition CanIsCountable sT f f' (fK : cancel f f') :=
@PCanIsCountable sT _ _ (can_pcan fK).
HB.instance Definition _ sT (f : sT -> T) f' (fK : pcancel f f') :
isCountable (pcan_type fK) := PCanIsCountable fK.
HB.instance Definition _ sT (f : sT -> T) f' (fK : cancel f f') :
isCountable (can_type fK) := CanIsCountable fK.
#[hnf] HB.instance Definition _ (P : pred T) (sT : subType P) :=
Countable.copy (sub_type sT) (pcan_type valK).
Definition pickle_seq s := CodeSeq.code (map (@pickle T) s).
Definition unpickle_seq n := Some (pmap (@unpickle T) (CodeSeq.decode n)).
Lemma pickle_seqK : pcancel pickle_seq unpickle_seq.
Proof. by move=> s; rewrite /unpickle_seq CodeSeq.codeK (map_pK pickleK). Qed.
HB.instance Definition _ := isCountable.Build (seq T) pickle_seqK.
End CountableTheory.
Notation "[ 'Countable' 'of' T 'by' <: ]" :=
(Countable.copy T%type (sub_type T%type))
(format "[ 'Countable' 'of' T 'by' <: ]") : form_scope.
Arguments pickle_inv {T} n.
Arguments pickleK {T} x : rename.
Arguments pickleK_inv {T} x.
Arguments pickle_invK {T} n : rename.
#[short(type="subCountType")]
HB.structure Definition SubCountable T (P : pred T) :=
{ sT of Countable sT & isSub T P sT}.
Section TagCountType.
Variables (I : countType) (T_ : I -> countType).
Definition pickle_tagged (u : {i : I & T_ i}) :=
CodeSeq.code [:: pickle (tag u); pickle (tagged u)].
Definition unpickle_tagged s :=
if CodeSeq.decode s is [:: ni; nx] then
obind (fun i => omap (@Tagged I i T_) (unpickle nx)) (unpickle ni)
else None.
Lemma pickle_taggedK : pcancel pickle_tagged unpickle_tagged.
Proof.
by case=> i x; rewrite /unpickle_tagged CodeSeq.codeK /= pickleK /= pickleK.
Qed.
HB.instance Definition _ :=
Choice_isCountable.Build {i : I & T_ i} pickle_taggedK.
End TagCountType.
(* The remaining instances for standard datatypes. *)
Section CountableDataTypes.
Implicit Type T : countType.
Lemma nat_pickleK : pcancel id (@Some nat). Proof. by []. Qed.
HB.instance Definition _ := Choice_isCountable.Build nat nat_pickleK.
HB.instance Definition _ := Countable.copy bool (can_type oddb).
HB.instance Definition _ := Countable.on bitseq.
HB.instance Definition _ := Countable.copy unit (can_type bool_of_unitK).
HB.instance Definition _ := Countable.copy void
(pcan_type (of_voidK unit)).
HB.instance Definition _ T := Countable.copy (option T)
(can_type (@seq_of_optK T)).
HB.instance Definition _ T (P : pred T) := [Countable of {x | P x} by <:].
HB.instance Definition _ T1 T2 :=
Countable.copy (T1 * T2)%type (can_type (@tag_of_pairK T1 T2)).
HB.instance Definition _ (T1 T2 : countType) :=
Countable.copy (T1 + T2)%type (pcan_type (@opair_of_sumK T1 T2)).
HB.instance Definition _ T := Countable.copy (GenTree.tree T)
(pcan_type (GenTree.codeK T)).
End CountableDataTypes.
|
monoid.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat seq.
From mathcomp Require Import bigop fintype finfun.
(******************************************************************************)
(* Group-like structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines the following algebraic structures: *)
(* *)
(* magmaType == magma *)
(* The HB class is called Magma. *)
(* ChoiceMagma.type == join of magmaType and choiceType *)
(* The HB class is called ChoiceMagma. *)
(* semigroupType == associative magma *)
(* The HB class is called Semigroup. *)
(* baseUMagmaType == pointed magma *)
(* The HB class is called BaseUMagma. *)
(* ChoiceBaseUMagma.type == join of baseUMagmaType and choiceType *)
(* The HB class is called ChoiceBaseUMagma. *)
(* umagmaType == unitary magma *)
(* The HB class is called UMagma. *)
(* monoidType == monoid *)
(* The HB class is called Monoid. *)
(* baseGroupType == pointed magma with an inversion operator *)
(* The HB class is called BaseGroup. *)
(* groupType == group *)
(* The HB class is called Group. *)
(* *)
(* and their joins with subType: *)
(* *)
(* subMagmaType V P == join of magmaType and subType (P : pred V) such *)
(* that val is multiplicative *)
(* The HB class is called SubMagma. *)
(* subSemigroupType V P == join of semigroupType and subType (P : pred V) *)
(* such that val is multiplicative *)
(* The HB class is called SubSemigroup. *)
(* subBaseUMagmaType V P == join of baseUMagmaType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubBaseUMagma. *)
(* subUMagmaType V P == join of UMagmaType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubUMagma. *)
(* subMonoidType V P == join of monoidType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubMonoid. *)
(* subGroupType V P == join of groupType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubGroup. *)
(* *)
(* Morphisms between the above structures: *)
(* *)
(* Multiplicative.type G H == multiplicative functions between magmaType *)
(* instances G and H *)
(* UMagmaMorphism.type G H == multiplicative functions preserving 1 between *)
(* baseUMagmaType instances G and H *)
(* *)
(* Closedness predicates for the algebraic structures: *)
(* *)
(* mulgClosed V == predicate closed under multiplication on G : magmaType *)
(* The HB class is called MulClosed. *)
(* umagmaClosed V == predicate closed under multiplication and containing 1 *)
(* on G : baseUMagmaType *)
(* The HB class is called UMagmaClosed. *)
(* invgClosed V == predicate closed under inversion on G : baseGroupType *)
(* The HB class is called InvClosed. *)
(* groupClosed V == predicate closed under multiplication and inversion and *)
(* containing 1 on G : baseGroupType *)
(* The HB class is called InvClosed. *)
(* *)
(* Canonical properties of the algebraic structures: *)
(* * magmaType (magmas): *)
(* x * y == the product of x and y *)
(* commute x y <-> x and y commute (i.e. x * y = y * x) *)
(* mulg_closed S <-> collective predicate S is closed under *)
(* multiplication *)
(* *)
(* * baseUMagmaType (pointed magmas): *)
(* 1 == the unit of a unitary magma *)
(* x ^+ n == x to the power n, with n in nat (non-negative), *)
(* i.e. x * (x * .. (x * x)..) (n terms); x ^+ 1 is *)
(* thus convertible to x, and x ^+ 2 to x * x *)
(* \prod<range> e == iterated product for a baseUMagmaType (cf bigop.v)*)
(* umagma_closed S <-> collective predicate S is closed under *)
(* multiplication and contains 1 *)
(* *)
(* * monoidType (monoids): *)
(* monoid_closed S := umagma_closed S *)
(* *)
(* * baseGroupType (pointed magmas with an inversion operator): *)
(* x ^-1 == the inverse of x *)
(* x / y == x * (y ^- 1) *)
(* x ^- n == (x ^+ n)^-1 *)
(* x ^ y := y^-1 * (x * y) *)
(* == the conjugate of x by y *)
(* [~ x, y] := x^-1 * (y^-1 * (x * y) *)
(* == the commutator of x and y *)
(* invg_closed S <-> collective predicate S is closed under inversion *)
(* divg_closed S <-> collective predicate S is closed under division *)
(* group_closed S <-> collective predicate S is closed under division *)
(* and contains 1 *)
(* *)
(* In addition to this structure hierarchy, we also develop a separate, *)
(* *)
(* * Multiplicative (magma morphisms): *)
(* {multiplicative U -> V} == the interface type for magma morphisms, i.e. *)
(* functions from U to V which maps * in U to * in *)
(* V; both U and V must have magmaType instances *)
(* := GRing.RMorphism.type R S *)
(* *)
(* * UMagmaMorphism (unitary magma morphisms): *)
(* monoid_morphism f <-> f of type U -> V is a multiplicative monoid *)
(* morphism, i.e., f maps 1 and * in U to 1 and *)
(* * in V, respectively. U and V must have *)
(* canonical baseUMagmaType instances. *)
(*Algebra.UMagmaMorphism.type == the interface type for unitary magma *)
(* morphisms; both U and V must have magmaType *)
(* instances *)
(* *)
(* Notations are defined in scope group_scope (delimiter %g) *)
(* This library also extends the conventional suffixes described in library *)
(* ssrbool.v with the following: *)
(* 1 -- unitary magma 1, as in mulg1 : x * 1 = x *)
(* M -- magma multiplication, as in conjgM : x ^ (y * z) = (x ^ y) ^ z *)
(* Mn -- ring by nat multiplication, as in expgMn : *)
(* (x * y) ^+ n = x ^+ n * y ^+ n *)
(* V -- group inverse, as in expVgn : (x^-1) ^+ n = x ^- n *)
(* F -- group division, as in invgF : (x / y)^-1 = y / x *)
(* X -- unitary magma exponentiation, as in conjXg : *)
(* (x ^+ n) ^ y = (x ^ y) ^+ n *)
(* J -- group conjugation, as in conjJg : (x ^ y) ^ z = (x ^ z) ^ y ^ z *)
(* R -- group commutator, as in conjRg : [~ x, y] ^ z = [~ x ^ z, y ^ z] *)
(* The operator suffixes D, B, M and X are also used for the corresponding *)
(* operations on nat, as in expgnDr : x ^+ (m + n) = x ^+ m * x ^+ n. For the *)
(* binary power operator, a trailing "n" suffix is used to indicate the *)
(* operator suffix applies to the left-hand group argument, as in *)
(* expg1n : 1 ^+ n = 1 vs. expg1 : x ^+ 1 = x. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "*%g" (at level 0).
Reserved Notation "\1" (at level 0).
Reserved Notation "f \* g" (at level 40, left associativity).
Reserved Notation "'{' 'multiplicative' G '->' H '}'"
(at level 0, G at level 98, H at level 99,
format "{ 'multiplicative' G -> H }").
Declare Scope group_scope.
Delimit Scope group_scope with g.
Local Open Scope group_scope.
HB.mixin Record hasMul G := {
mul : G -> G -> G
}.
#[short(type="magmaType")]
HB.structure Definition Magma := {G of hasMul G}.
Bind Scope group_scope with Magma.sort.
HB.structure Definition ChoiceMagma := {G of Magma G & Choice G}.
Bind Scope group_scope with ChoiceMagma.sort.
Local Notation "*%g" := (@mul _) : function_scope.
Local Notation "x * y" := (mul x y) : group_scope.
Section MagmaTheory.
Variable G : magmaType.
Implicit Types x y : G.
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.
Section ClosedPredicates.
Variable S : {pred G}.
Definition mulg_closed := {in S &, forall u v, u * v \in S}.
End ClosedPredicates.
End MagmaTheory.
HB.mixin Record Magma_isSemigroup G of Magma G := {
mulgA : associative (@mul G)
}.
#[short(type="semigroupType")]
HB.structure Definition Semigroup := {G of Magma_isSemigroup G & ChoiceMagma G}.
HB.factory Record isSemigroup G of Choice G := {
mul : G -> G -> G;
mulgA : associative mul
}.
HB.builders Context G of isSemigroup G.
HB.instance Definition _ := hasMul.Build G mul.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.end.
Bind Scope group_scope with Semigroup.sort.
Section SemigroupTheory.
Variable G : semigroupType.
Implicit Types x y : G.
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.
End SemigroupTheory.
HB.mixin Record hasOne G := {
one : G
}.
#[short(type="baseUMagmaType")]
HB.structure Definition BaseUMagma := {G of hasOne G & Magma G}.
Bind Scope group_scope with BaseUMagma.sort.
HB.structure Definition ChoiceBaseUMagma := {G of BaseUMagma G & Choice G}.
Bind Scope group_scope with ChoiceBaseUMagma.sort.
Local Notation "1" := (@one _) : group_scope.
Local Notation "s `_ i" := (nth 1 s i) : group_scope.
Local Notation "\prod_ ( i <- r | P ) F" := (\big[*%g/1]_(i <- r | P) F).
Local Notation "\prod_ ( i | P ) F" := (\big[*%g/1]_(i | P) F).
Local Notation "\prod_ ( i 'in' A ) F" := (\big[*%g/1]_(i in A) F).
Local Notation "\prod_ ( m <= i < n ) F" := (\big[*%g/1%g]_(m <= i < n) F%g).
Definition natexp (G : baseUMagmaType) (x : G) n : G := iterop n *%g x 1.
Arguments natexp : simpl never.
Local Notation "x ^+ n" := (natexp x n) : group_scope.
Section baseUMagmaTheory.
Variable G : baseUMagmaType.
Implicit Types x : G.
Lemma expg0 x : x ^+ 0 = 1. Proof. by []. Qed.
Lemma expg1 x : x ^+ 1 = x. Proof. by []. Qed.
Lemma expg2 x : x ^+ 2 = x * x. Proof. by []. Qed.
Lemma expgSS x n : x ^+ n.+2 = x * x ^+ n.+1.
Proof. by []. Qed.
Lemma expgb x (b : bool) : x ^+ b = (if b then x else 1).
Proof. by case: b. Qed.
Section ClosedPredicates.
Variable S : {pred G}.
Definition umagma_closed := 1 \in S /\ mulg_closed S.
End ClosedPredicates.
End baseUMagmaTheory.
HB.mixin Record BaseUMagma_isUMagma G of BaseUMagma G := {
mul1g : left_id one (@mul G);
mulg1 : right_id one (@mul G)
}.
HB.factory Record Magma_isUMagma G of Magma G := {
one : G;
mul1g : left_id one (@mul G);
mulg1 : right_id one (@mul G)
}.
HB.builders Context G of Magma_isUMagma G.
HB.instance Definition _ := hasOne.Build G one.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := BaseUMagma_isUMagma.Build G mul1g mulg1.
HB.end.
#[short(type="umagmaType")]
HB.structure Definition UMagma := {G of Magma_isUMagma G & ChoiceMagma G}.
Bind Scope group_scope with UMagma.sort.
Section UMagmaTheory.
Variable G : umagmaType.
Implicit Types x y : G.
Lemma expgS x n : x ^+ n.+1 = x * x ^+ n.
Proof. by case: n => //=; rewrite mulg1. Qed.
Lemma expg1n n : 1 ^+ n = 1 :> G.
Proof. by elim: n => // n IHn; rewrite expgS mul1g. Qed.
Lemma commute1 x : commute x 1.
Proof. by rewrite /commute mulg1 mul1g. Qed.
End UMagmaTheory.
#[short(type="monoidType")]
HB.structure Definition Monoid := {G of Magma_isUMagma G & Semigroup G}.
HB.factory Record Semigroup_isMonoid G of Semigroup G := {
one : G;
mul1g : left_id one mul;
mulg1 : right_id one mul
}.
HB.builders Context G of Semigroup_isMonoid G.
HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1.
HB.end.
HB.factory Record UMagma_isMonoid G of UMagma G := {
mulgA : associative (@mul G)
}.
HB.builders Context G of UMagma_isMonoid G.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.end.
HB.factory Record isMonoid G of Choice G := {
mul : G -> G -> G;
one : G;
mulgA : associative mul;
mul1g : left_id one mul;
mulg1 : right_id one mul
}.
HB.builders Context G of isMonoid G.
HB.instance Definition _ := hasMul.Build G mul.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1.
HB.end.
#[export]
HB.instance Definition _ (G : monoidType) := Monoid.isLaw.Build G 1 *%g mulgA mul1g mulg1.
Bind Scope group_scope with Monoid.sort.
Section MonoidTheory.
Variable G : monoidType.
Implicit Types x y : G.
Lemma expgSr x n : x ^+ n.+1 = x ^+ n * x.
Proof.
elim: n => [|n IHn]; first by rewrite mul1g.
by rewrite expgS [in LHS]IHn expgS mulgA.
Qed.
Lemma expgnDr x m n : x ^+ (m + n) = x ^+ m * x ^+ n.
Proof.
elim: m => [|m IHm]; first by rewrite mul1g.
by rewrite 2!expgS IHm mulgA.
Qed.
Lemma expgnA x m n : x ^+ (m * n) = x ^+ m ^+ n.
Proof. by rewrite mulnC; elim: n => //= n IHn; rewrite expgS expgnDr IHn. Qed.
Lemma expgnAC x m n : x ^+ m ^+ n = x ^+ n ^+ m.
Proof. by rewrite -2!expgnA mulnC. Qed.
Lemma iter_mulg n x y : iter n ( *%g x) y = x ^+ n * y.
Proof. by elim: n => [|n IHn]; rewrite ?mul1g //= IHn expgS mulgA. Qed.
Lemma iter_mulg_1 n x : iter n ( *%g x) 1 = x ^+ n.
Proof. by rewrite iter_mulg mulg1. Qed.
Lemma prodg_const (I : finType) (A : pred I) x : \prod_(i in A) x = x ^+ #|A|.
Proof. by rewrite big_const -Monoid.iteropE. Qed.
Lemma prodg_const_nat n m x : \prod_(n <= i < m) x = x ^+ (m - n).
Proof. by rewrite big_const_nat -Monoid.iteropE. Qed.
Lemma prodgXr x I r P (F : I -> nat) :
\prod_(i <- r | P i) x ^+ F i = x ^+ (\sum_(i <- r | P i) F i).
Proof. by rewrite (big_morph _ (expgnDr _) (erefl _)). Qed.
Lemma commute_prod (I : Type) (s : seq I) (P : pred I) (F : I -> G) x :
(forall i, P i -> commute x (F i)) -> commute x (\prod_(i <- s | P i) F i).
Proof. exact: (big_ind _ (commute1 x) (@commuteM _ x)). Qed.
Lemma prodgM_commute {I : eqType} r (P : pred I) (F H : I -> G) :
(forall i j, P i -> P j -> commute (F i) (H j)) ->
\prod_(i <- r | P i) (F i * H i) =
\prod_(i <- r | P i) F i * \prod_(i <- r | P i) H i.
Proof.
move=> FH; elim: r => [|i r IHr]; rewrite !(big_nil, big_cons) ?mulg1//.
case: ifPn => // Pi; rewrite IHr !mulgA; congr (_ * _); rewrite -!mulgA.
by rewrite commute_prod // => j Pj; apply/commute_sym/FH.
Qed.
Lemma prodgMl_commute {I : finType} (A : pred I) (x : G) F :
(forall i, A i -> commute x (F i)) ->
\prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i.
Proof. by move=> xF; rewrite prodgM_commute ?prodg_const// => i j _ /xF. Qed.
Lemma prodgMr_commute {I : finType} (A : pred I) (x : G) F :
(forall i, A i -> commute x (F i)) ->
\prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|.
Proof. by move=> xF; rewrite prodgM_commute ?prodg_const// => i j /xF. 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 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 MonoidTheory.
Notation monoid_closed := umagma_closed.
HB.mixin Record hasInv G := {
inv : G -> G
}.
#[short(type="baseGroupType")]
HB.structure Definition BaseGroup := {G of hasInv G & BaseUMagma G}.
Bind Scope group_scope with BaseGroup.sort.
HB.mixin Record Monoid_isGroup G of BaseGroup G := {
mulVg : left_inverse one inv (@mul G);
mulgV : right_inverse one inv (@mul G)
}.
#[short(type="groupType")]
HB.structure Definition Group :=
{G of Monoid_isGroup G & BaseGroup G & Monoid G}.
HB.factory Record isGroup G of Choice G := {
one : G;
inv : G -> G;
mul : G -> G -> G;
mulgA : associative mul;
mul1g : left_id one mul;
mulg1 : right_id one mul;
mulVg : left_inverse one inv mul;
mulgV : right_inverse one inv mul
}.
HB.builders Context G of isGroup G.
HB.instance Definition _ := hasMul.Build G mul.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1.
HB.instance Definition _ := hasInv.Build G inv.
HB.instance Definition _ := Monoid_isGroup.Build G mulVg mulgV.
HB.end.
Bind Scope group_scope with Group.sort.
Local Notation "x ^-1" := (inv x) : group_scope.
Local Notation "x / y" := (x * y^-1) : group_scope.
Local Notation "x ^- n" := ((x ^+ n)^-1) : group_scope.
Definition conjg (G : groupType) (x y : G) := y^-1 * (x * y).
Local Notation "x ^ y" := (conjg x y) : group_scope.
Definition commg (G : groupType) (x y : G) := x^-1 * (conjg x y).
Local Notation "[~ x , y ]" := (commg x y) : group_scope.
Section GroupTheory.
Variable G : groupType.
Implicit Types x y : G.
Definition divgg := @mulgV G.
Lemma mulKg : @left_loop G G (@inv G) *%g.
Proof. by move=> x y; rewrite mulgA mulVg mul1g. Qed.
Lemma mulVKg : @rev_left_loop G G (@inv G) *%g.
Proof. by move=> x y ; rewrite mulgA mulgV mul1g. Qed.
Lemma mulgK : @right_loop G G (@inv G) *%g.
Proof. by move=> x y; rewrite -mulgA mulgV mulg1. Qed.
Lemma mulgVK : @rev_right_loop G G (@inv G) *%g.
Proof. by move=> x y ; rewrite -mulgA mulVg mulg1. Qed.
Definition divgK := mulgVK.
Lemma mulgI : @right_injective G G G *%g.
Proof. by move=> x; apply: can_inj (mulKg x). Qed.
Lemma mulIg : @left_injective G G G *%g.
Proof. by move=> x; apply: can_inj (mulgK x). Qed.
Lemma invgK : @involutive G (@inv G).
Proof. by move=> x; rewrite -[LHS](mulVKg x) divgg mulg1. Qed.
Lemma invg_inj : @injective G G (@inv G).
Proof. exact: inv_inj invgK. Qed.
Lemma divgI : @right_injective G G G (fun x y => x / y).
Proof. by move=> x y z /mulgI/invg_inj. Qed.
Lemma divIg : @left_injective G G G (fun x y => x / y).
Proof. by move=> x y z /mulIg. Qed.
Lemma invg1 : 1 ^-1 = 1 :> G.
Proof. by rewrite -[LHS]mul1g divgg. Qed.
Lemma invg_eq1 x : (x ^-1 == 1) = (x == 1).
Proof. by rewrite (inv_eq invgK) invg1. Qed.
Lemma divg1 x : x / 1 = x. Proof. by rewrite invg1 mulg1. Qed.
Lemma div1g x : 1 / x = x^-1. Proof. by rewrite mul1g. Qed.
Lemma invgF x y : (x / y)^-1 = y / x.
Proof. by apply/(canRL (mulgK x))/(@divIg y); rewrite -mulgA mulVg divgg. Qed.
Lemma invgM : {morph (@inv G): x y / x * y >-> y * x : G}.
Proof. by move=> x y; rewrite -[y in LHS]invgK invgF. Qed.
Lemma prodgV I r (P : pred I) (E : I -> G) :
\prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- rev r | P i) E i)^-1.
Proof.
elim: r => [|x r IHr]; first by rewrite !big_nil invg1.
rewrite big_cons rev_cons big_rcons/= IHr.
by case: ifP => _; rewrite ?mulg1// invgM.
Qed.
Lemma divKg x y : commute x y -> x / (x / y) = y.
Proof. by move=> xyC; rewrite invgF mulgA xyC mulgK. Qed.
(* TOTHINK : This does not have the same form as addrKA in ssralg.v *)
Lemma mulgKA z x y : (x * z) / (y * z) = x / y.
Proof. by rewrite invgM mulgA mulgK. Qed.
Lemma divgKA z x y : (x / z) * (z * y) = x * y.
Proof. by rewrite mulgA mulgVK. Qed.
Lemma mulg1_eq x y : x * y = 1 -> x^-1 = y.
Proof. by rewrite -[x^-1]mulg1 => <-; rewrite mulKg. Qed.
Lemma divg1_eq x y : x / y = 1 -> x = y.
Proof. by move/mulg1_eq/invg_inj. Qed.
Lemma divg_eq x y z : (x / z == y) = (x == y * z).
Proof. exact: can2_eq (divgK z) (mulgK z) x y. Qed.
Lemma divg_eq1 x y : (x / y == 1) = (x == y).
Proof. by rewrite divg_eq mul1g. Qed.
Lemma mulg_eq1 x y : (x * y == 1) = (x == y^-1).
Proof. by rewrite -[y in LHS]invgK divg_eq1. Qed.
Lemma eqg_inv x y : (x^-1 == y^-1) = (x == y).
Proof. exact: can_eq invgK x y. Qed.
Lemma eqg_invLR x y : (x^-1 == y) = (x == y^-1).
Proof. exact: inv_eq invgK x y. Qed.
Lemma commuteV x y : commute x y -> commute x y^-1.
Proof. by move=> cxy; apply: (@mulIg y); rewrite mulgVK -mulgA cxy mulKg. Qed.
Lemma expVgn x n : (x^-1) ^+ n = x ^- n.
Proof.
apply/esym/mulg1_eq; rewrite -expgMn; first by rewrite divgg expg1n.
exact/commuteV.
Qed.
Lemma expgnFr x m n : n <= m -> x ^+ (m - n) = x ^+ m / x ^+ n.
Proof. by move=> lenm; rewrite -[in RHS](subnK lenm) expgnDr mulgK. Qed.
Lemma expgnFl x y n : commute x y -> (x / y) ^+ n = x ^+ n / y ^+ n.
Proof. by move=> xyC; rewrite expgMn 1?expVgn; last exact/commuteV. 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 mulVKg. Qed.
Lemma conjgCV x y : x * y = y ^ x^-1 * x.
Proof. by rewrite -mulgA mulgVK 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 invgM !mulgA. Qed.
Lemma conjVg x y : x^-1 ^ y = (x ^ y)^-1.
Proof. by rewrite !conjgE !invgM 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 G G (@inv G) (@conjg G).
Proof. by move=> y x; rewrite -conjgM mulgV conjg1. Qed.
Lemma conjgKV : @rev_right_loop G G (@inv G) (@conjg G).
Proof. by move=> y x; rewrite -conjgM mulVg conjg1. Qed.
Lemma conjg_inj : @left_injective G G G (@conjg G).
Proof. by move=> y; apply: can_inj (conjgK y). Qed.
Lemma conjg_eq1 x y : (x ^ y == 1) = (x == 1).
Proof. by rewrite (can2_eq (conjgK _) (conjgKV _)) conj1g. 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 !mulVKg. Qed.
Lemma commgCV x y : x * y = [~ x^-1, y^-1] * (y * x).
Proof. by rewrite commgEl !mulgA !invgK !mulgVK. Qed.
Lemma conjRg x y z : [~ x, y] ^ z = [~ x ^ z, y ^ z].
Proof. by rewrite !conjMg !conjVg. Qed.
Lemma invgR x y : [~ x, y]^-1 = [~ y, x].
Proof. by rewrite commgEr conjVg invgM invgK. Qed.
Lemma commgP x y : reflect (commute x y) ([~ x, y] == 1).
Proof. rewrite [[~ x, y]]mulgA -invgM mulg_eq1 eqg_inv eq_sym; apply: eqP. Qed.
Lemma conjg_fix x y : x ^ y == x = ([~ x, y] == 1).
Proof. by rewrite mulg_eq1 eqg_inv. Qed.
Lemma conjg_fixP x y : reflect (x ^ y = x) ([~ x, y] == 1).
Proof. by rewrite -conjg_fix; apply: eqP. Qed.
Lemma commg1_sym x y : ([~ x, y] == 1) = ([~ y, x] == 1).
Proof. by rewrite -invgR (inv_eq invgK) invg1. Qed.
Lemma commg1 x : [~ x, 1] = 1.
Proof. exact/eqP/commgP/commute1. Qed.
Lemma comm1g x : [~ 1, x] = 1.
Proof. by rewrite -invgR 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.
Section ClosedPredicates.
Variable S : {pred G}.
Definition invg_closed := {in S, forall u, u^-1 \in S}.
Definition divg_closed := {in S &, forall u v, u / v \in S}.
Definition group_closed := 1 \in S /\ divg_closed.
Lemma group_closedV : group_closed -> invg_closed.
Proof. by move=> [S1 SB] x /(SB 1)-/(_ S1); rewrite div1g. Qed.
Lemma group_closedM : group_closed -> mulg_closed S.
Proof.
move=> /[dup]-[S1 SB] /group_closedV SV x y xS /SV yS.
rewrite -[y]invgK; exact: SB.
Qed.
End ClosedPredicates.
End GroupTheory.
(* Morphism hierarchy. *)
HB.mixin Record isMultiplicative (G H : magmaType) (apply : G -> H) := {
gmulfM : {morph apply : x y / x * y}
}.
HB.structure Definition Multiplicative (G H : magmaType) :=
{f of isMultiplicative G H f}.
(* TODO: define pointedTypes and generalize this to pointedTypes. *)
HB.mixin Record Multiplicative_isUMagmaMorphism (G H : baseUMagmaType)
(f : G -> H) := {
gmulf1 : f 1 = 1
}.
HB.structure Definition UMagmaMorphism (G H : baseUMagmaType) :=
{f of Multiplicative_isUMagmaMorphism G H f & isMultiplicative G H f}.
Definition monoid_morphism (G H : baseUMagmaType) (f : G -> H) : Prop :=
(f 1 = 1) * {morph f : x y / x * y}.
HB.factory Record isUMagmaMorphism (G H : baseUMagmaType) (f : G -> H) := {
monoid_morphism_subproof : monoid_morphism f
}.
HB.builders Context G H apply of isUMagmaMorphism G H apply.
HB.instance Definition _ :=
isMultiplicative.Build G H apply monoid_morphism_subproof.2.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G H apply monoid_morphism_subproof.1.
HB.end.
HB.factory Record isGroupMorphism (G H : groupType) (f : G -> H) := {
gmulfF : {morph f : x y / x / y}
}.
HB.builders Context G H apply of isGroupMorphism G H apply.
Local Lemma gmulf1 : apply 1 = 1.
Proof. by rewrite -[1]divg1 gmulfF divgg. Qed.
Local Lemma gmulfM : {morph apply : x y / x * y}.
Proof.
move=> x y; rewrite -[y in LHS] invgK -[y^-1]mul1g.
by rewrite !gmulfF gmulf1 div1g invgK.
Qed.
HB.instance Definition _ := isMultiplicative.Build G H apply gmulfM.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G H apply gmulf1.
HB.end.
Module MultiplicativeExports.
Notation "{ 'multiplicative' U -> V }" :=
(Multiplicative.type U%type V%type) : type_scope.
End MultiplicativeExports.
HB.export MultiplicativeExports.
(* FIXME: The instance below makes sure that the join instance between *)
(* Multiplicative.type and UMagmaMorphism.type is declared in both directions.*)
(* HB should do this automatically. *)
#[non_forgetful_inheritance]
HB.instance Definition _ G H (f : UMagmaMorphism.type G H) :=
UMagmaMorphism.on (Multiplicative.sort f).
Section LiftedMagma.
Variables (T : Type) (G : magmaType).
Definition mul_fun (f g : T -> G) x := f x * g x.
End LiftedMagma.
Section LiftedBaseUMagma.
Variables (T : Type) (G : baseUMagmaType).
Definition one_fun : T -> G := fun=> 1.
End LiftedBaseUMagma.
Local Notation "\1" := (one_fun _) : function_scope.
Local Notation "f \* g" := (mul_fun f g) : function_scope.
Arguments one_fun {_} G _ /.
Arguments mul_fun {_ _} f g _ /.
Section MorphismTheory.
Section Magma.
Variables (G H : magmaType) (f : {multiplicative G -> H}).
Lemma can2_gmulfM f' : cancel f f' -> cancel f' f -> {morph f' : x y / x * y}.
Proof. by move=> fK f'K x y; apply: (canLR fK); rewrite gmulfM !f'K. Qed.
Lemma gmulf_commute x y : commute x y -> commute (f x) (f y).
Proof. by move=> xy; rewrite /commute -!gmulfM xy. Qed.
End Magma.
Section UMagma.
Variables (G H : umagmaType) (f : UMagmaMorphism.type G H).
Lemma gmulf_eq1 x : injective f -> (f x == 1) = (x == 1).
Proof. by move=> /inj_eq <-; rewrite gmulf1. Qed.
Lemma can2_gmulf1 f' : cancel f f' -> cancel f' f -> f' 1 = 1.
Proof. by move=> fK f'K; apply: (canLR fK); rewrite gmulf1. Qed.
Lemma gmulfXn n : {morph f : x / x ^+ n}.
Proof. by elim: n => [|[|n] IHn] x /=; rewrite ?(gmulf1, gmulfM) // IHn. Qed.
Lemma gmulf_prod I r (P : pred I) E :
f (\prod_(i <- r | P i) E i) = \prod_(i <- r | P i) f (E i).
Proof. exact: (big_morph f gmulfM gmulf1). Qed.
End UMagma.
Section Group.
Variables (G H : groupType) (f : UMagmaMorphism.type G H).
Lemma gmulfV : {morph f : x / x^-1}.
Proof. by move=> x; apply/divg1_eq; rewrite invgK -gmulfM mulVg gmulf1. Qed.
Lemma gmulfF : {morph f : x y / x / y}.
Proof. by move=> x y; rewrite gmulfM gmulfV. Qed.
Lemma gmulf_inj : (forall x, f x = 1 -> x = 1) -> injective f.
Proof. by move=> fI x y xy; apply/divg1_eq/fI; rewrite gmulfF xy divgg. Qed.
Lemma gmulfXVn n : {morph f : x / x ^- n}.
Proof. by move=> x /=; rewrite gmulfV gmulfXn. Qed.
Lemma gmulfJ : {morph f : x y / x ^ y}.
Proof. by move=> x y; rewrite !gmulfM/= gmulfV. Qed.
Lemma gmulfR : {morph f : x y / [~ x, y]}.
Proof. by move=> x y; rewrite !gmulfM/= !gmulfV. Qed.
End Group.
Section MulFun.
Variables (G H K : magmaType).
Variables (f g : {multiplicative H -> K}) (h : {multiplicative G -> H}).
Fact idfun_gmulfM : {morph @idfun G : x y / x * y}.
Proof. by []. Qed.
HB.instance Definition _ := isMultiplicative.Build G G idfun idfun_gmulfM.
Fact comp_gmulfM : {morph f \o h : x y / x * y}.
Proof. by move=> x y /=; rewrite !gmulfM. Qed.
HB.instance Definition _ := isMultiplicative.Build G K (f \o h) comp_gmulfM.
End MulFun.
Section Mul1Fun.
Variables (G : magmaType) (H : umagmaType).
Fact idfun_gmulf1 : idfun 1 = 1 :> H.
Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build H H idfun idfun_gmulf1.
Fact one_fun_gmulfM : {morph @one_fun G H : x y / x * y}.
Proof. by move=> x y; rewrite mulg1. Qed.
HB.instance Definition _ :=
isMultiplicative.Build G H (@one_fun G H) one_fun_gmulfM.
End Mul1Fun.
Section Mul11Fun.
Variables (G H K : umagmaType).
Variables (f g : UMagmaMorphism.type H K) (h : UMagmaMorphism.type G H).
Fact comp_gmulf1 : (f \o h) 1 = 1.
Proof. by rewrite /= !gmulf1. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G K (f \o h) comp_gmulf1.
Fact one_fun_gmulf1 : @one_fun G H 1 = 1.
Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G H (@one_fun G H) one_fun_gmulf1.
Fact mul_fun_gmulf1 : (f \* g) 1 = 1.
Proof. by rewrite /= !gmulf1 mulg1. Qed.
End Mul11Fun.
End MorphismTheory.
(* Mixins for stability properties *)
HB.mixin Record isMulClosed (G : magmaType) (S : {pred G}) := {
gpredM : mulg_closed S
}.
HB.mixin Record isMul1Closed (G : baseUMagmaType) (S : {pred G}) := {
gpred1 : 1 \in S
}.
HB.mixin Record isInvClosed (G : groupType) (S : {pred G}) := {
gpredVr : invg_closed S
}.
(* Structures for stability properties *)
#[short(type="mulgClosed")]
HB.structure Definition MulClosed G := {S of isMulClosed G S}.
#[short(type="umagmaClosed")]
HB.structure Definition UMagmaClosed G :=
{S of isMul1Closed G S & isMulClosed G S}.
#[short(type="invgClosed")]
HB.structure Definition InvClosed G := {S of isInvClosed G S}.
#[short(type="groupClosed")]
HB.structure Definition GroupClosed G :=
{S of isInvClosed G S & isMul1Closed G S & isMulClosed G S}.
Section UMagmaPred.
Variables (G : baseUMagmaType).
Section UMagma.
Variables S : umagmaClosed G.
Lemma gpred_prod I r (P : pred I) F :
(forall i, P i -> F i \in S) -> \prod_(i <- r | P i) F i \in S.
Proof. by move=> IH; elim/big_ind: _; [apply: gpred1 | apply: gpredM |]. Qed.
Lemma gpredXn n : {in S, forall u, u ^+ n \in S}.
Proof.
by move=> x xS; elim: n => [|[//|n] IHn]; [exact: gpred1 | exact: gpredM].
Qed.
End UMagma.
End UMagmaPred.
Section GroupPred.
Variables (G : groupType).
Lemma gpredV (S : invgClosed G) : {mono (@inv G): u / u \in S}.
Proof. by move=> u; apply/idP/idP=> /gpredVr; rewrite ?invgK; apply. Qed.
Section Group.
Variables S : groupClosed G.
Lemma gpredF : {in S &, forall u v, u / v \in S}.
Proof. by move=> x y xS yS; rewrite gpredM// gpredV. Qed.
Lemma gpredFC u v : u / v \in S = (v / u \in S).
Proof. by rewrite -gpredV invgF. Qed.
Lemma gpredXNn n: {in S, forall u, u ^- n \in S}.
Proof. by move=> x xS; apply/gpredVr/gpredXn. Qed.
Lemma gpredMr x y : x \in S -> (y * x \in S) = (y \in S).
Proof.
move=> Sx; apply/idP/idP => [Sxy|/gpredM-> //].
by rewrite -(mulgK x y) gpredF.
Qed.
Lemma gpredMl x y : x \in S -> (x * y \in S) = (y \in S).
Proof.
move=> Sx; apply/idP/idP => [Sxy|/(gpredM x y Sx)//].
by rewrite -(mulKg x y) gpredM// gpredV.
Qed.
Lemma gpredFr x y : x \in S -> (y / x \in S) = (y \in S).
Proof. by rewrite -gpredV; apply: gpredMr. Qed.
Lemma gpredFl x y : x \in S -> (x / y \in S) = (y \in S).
Proof. by rewrite -(gpredV S y); apply: gpredMl. Qed.
Lemma gpredJ x y : x \in S -> y \in S -> x ^ y \in S.
Proof. by move=> xS yS; apply/gpredM; [apply/gpredVr|apply/gpredM]. Qed.
Lemma gpredR x y : x \in S -> y \in S -> [~ x, y] \in S.
Proof. by move=> xS yS; apply/gpredM; [apply/gpredVr|apply/gpredJ]. Qed.
End Group.
End GroupPred.
HB.mixin Record isSubMagma (G : magmaType) (S : pred G) H
of SubType G S H & Magma H := {
valM_subproof : {morph (val : H -> G) : x y / x * y}
}.
#[short(type="subMagmaType")]
HB.structure Definition SubMagma (G : magmaType) S :=
{ H of SubChoice G S H & Magma H & isSubMagma G S H }.
Section subMagma.
Context (G : magmaType) (S : pred G) (H : subMagmaType S).
Notation val := (val : H -> G).
HB.instance Definition _ := isMultiplicative.Build H G val valM_subproof.
Lemma valM : {morph val : x y / x * y}. Proof. exact: gmulfM. Qed.
End subMagma.
HB.factory Record SubChoice_isSubMagma (G : magmaType) S H
of SubChoice G S H := {
mulg_closed_subproof : mulg_closed S
}.
HB.builders Context G S H of SubChoice_isSubMagma G S H.
HB.instance Definition _ := isMulClosed.Build G S mulg_closed_subproof.
Let inH v Sv : H := Sub v Sv.
Let mulH (u1 u2 : H) := inH (gpredM _ _ (valP u1) (valP u2)).
HB.instance Definition _ := hasMul.Build H mulH.
Lemma valM : {morph (val : H -> G) : x y / x * y}.
Proof. by move=> x y; rewrite SubK. Qed.
HB.instance Definition _ := isSubMagma.Build G S H valM.
HB.end.
#[short(type="subSemigroupType")]
HB.structure Definition SubSemigroup (G : semigroupType) S :=
{ H of SubMagma G S H & Semigroup H}.
HB.factory Record SubChoice_isSubSemigroup (G : semigroupType) S H
of SubChoice G S H := {
mulg_closed_subproof : mulg_closed S
}.
HB.builders Context G S H of SubChoice_isSubSemigroup G S H.
HB.instance Definition _ :=
SubChoice_isSubMagma.Build G S H mulg_closed_subproof.
Lemma mulgA : associative (@mul H).
Proof. by move=> x y z; apply/val_inj; rewrite !valM mulgA. Qed.
HB.instance Definition _ := isSemigroup.Build H mulgA.
HB.end.
HB.mixin Record isSubBaseUMagma (G : baseUMagmaType) (S : pred G) H
of SubMagma G S H & BaseUMagma H := {
val1_subproof : (val : H -> G) 1 = 1
}.
#[short(type="subBaseUMagmaType")]
HB.structure Definition SubBaseUMagma (G : umagmaType) S :=
{ H of SubMagma G S H & BaseUMagma H & isSubBaseUMagma G S H}.
#[short(type="subUMagmaType")]
HB.structure Definition SubUMagma (G : umagmaType) S :=
{ H of SubMagma G S H & UMagma H & isSubBaseUMagma G S H}.
Section subUMagma.
Context (G : umagmaType) (S : pred G) (H : subUMagmaType S).
Notation val := (val : H -> G).
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build H G val val1_subproof.
Lemma val1 : val 1 = 1. Proof. exact: gmulf1. Qed.
End subUMagma.
HB.factory Record SubChoice_isSubUMagma (G : umagmaType) S H
of SubChoice G S H := {
umagma_closed_subproof : umagma_closed S
}.
HB.builders Context G S H of SubChoice_isSubUMagma G S H.
HB.instance Definition _ :=
SubChoice_isSubMagma.Build G S H (snd umagma_closed_subproof).
Let inH v Sv : H := Sub v Sv.
Let oneH := inH (fst umagma_closed_subproof).
HB.instance Definition _ := hasOne.Build H oneH.
Lemma val1 : (val : H -> G) 1 = 1.
Proof. exact/SubK. Qed.
HB.instance Definition _ := isSubBaseUMagma.Build G S H val1.
Lemma mul1g : left_id 1 (@mul H).
Proof. by move=> x; apply/val_inj; rewrite valM val1 mul1g. Qed.
Lemma mulg1 : right_id 1 (@mul H).
Proof. by move=> x; apply/val_inj; rewrite valM val1 mulg1. Qed.
HB.instance Definition _ := BaseUMagma_isUMagma.Build H mul1g mulg1.
HB.end.
#[short(type="subMonoidType")]
HB.structure Definition SubMonoid (G : monoidType) S :=
{ H of SubUMagma G S H & Monoid H}.
HB.factory Record SubChoice_isSubMonoid (G : monoidType) S H
of SubChoice G S H := {
monoid_closed_subproof : monoid_closed S
}.
HB.builders Context G S H of SubChoice_isSubMonoid G S H.
HB.instance Definition _ :=
SubChoice_isSubUMagma.Build G S H monoid_closed_subproof.
HB.instance Definition _ :=
SubChoice_isSubSemigroup.Build G S H (snd monoid_closed_subproof).
HB.end.
#[short(type="subGroupType")]
HB.structure Definition SubGroup (G : groupType) S :=
{ H of SubUMagma G S H & Group H}.
HB.factory Record SubChoice_isSubGroup (G : groupType) S H
of SubChoice G S H := {
group_closed_subproof : group_closed S
}.
HB.builders Context G S H of SubChoice_isSubGroup G S H.
Lemma umagma_closed : umagma_closed S.
Proof.
split; first exact/(fst group_closed_subproof).
exact/group_closedM/group_closed_subproof.
Qed.
HB.instance Definition _ := SubChoice_isSubMonoid.Build G S H umagma_closed.
HB.instance Definition _ :=
isInvClosed.Build G S (group_closedV group_closed_subproof).
Let inH v Sv : H := Sub v Sv.
Let invH (u : H) := inH (gpredVr _ (valP u)).
HB.instance Definition _ := hasInv.Build H invH.
Lemma mulVg : left_inverse 1%g invH *%g.
Proof. by move=> x; apply/val_inj; rewrite valM SubK mulVg val1. Qed.
Lemma mulgV : right_inverse 1%g invH *%g.
Proof. by move=> x; apply/val_inj; rewrite valM SubK mulgV val1. Qed.
HB.instance Definition _ := Monoid_isGroup.Build H mulVg mulgV.
HB.end.
(* Lifting Structure from the codomain of finfuns. *)
Section FinFunMagma.
Variable (aT : finType) (rT : magmaType).
Implicit Types f g : {ffun aT -> rT}.
Definition ffun_mul f g := [ffun a => f a * g a].
HB.instance Definition _ := hasMul.Build {ffun aT -> rT} ffun_mul.
End FinFunMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (aT : finType) (rT : ChoiceMagma.type) :=
Magma.on {ffun aT -> rT}.
Section FinFunSemigroup.
Variable (aT : finType) (rT : semigroupType).
Implicit Types f g : {ffun aT -> rT}.
Fact ffun_mulgA : associative (@ffun_mul aT rT).
Proof. by move=> f1 f2 f3; apply/ffunP=> a; rewrite !ffunE mulgA. Qed.
HB.instance Definition _ := isSemigroup.Build {ffun aT -> rT} ffun_mulgA.
End FinFunSemigroup.
Section FinFunBaseUMagma.
Variable (aT : finType) (rT : baseUMagmaType).
Implicit Types f g : {ffun aT -> rT}.
Definition ffun_one := [ffun a : aT => (1 : rT)].
HB.instance Definition _ :=
hasOne.Build {ffun aT -> rT} ffun_one.
End FinFunBaseUMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (aT : finType) (rT : ChoiceBaseUMagma.type) :=
BaseUMagma.on {ffun aT -> rT}.
Section FinFunUMagma.
Variable (aT : finType) (rT : umagmaType).
Implicit Types f g : {ffun aT -> rT}.
Fact ffun_mul1g : left_id (@ffun_one aT rT) *%g.
Proof. by move=> f; apply/ffunP => a; rewrite !ffunE mul1g. Qed.
Fact ffun_mulg1 : right_id (@ffun_one aT rT) *%g.
Proof. by move=> f; apply/ffunP => a; rewrite !ffunE mulg1. Qed.
HB.instance Definition _ :=
Magma_isUMagma.Build {ffun aT -> rT} ffun_mul1g ffun_mulg1.
End FinFunUMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (aT : finType) (rT : monoidType) :=
UMagma.on {ffun aT -> rT}.
Section FinFunBaseGroup.
Variable (aT : finType) (rT : baseGroupType).
Implicit Types f g : {ffun aT -> rT}.
Definition ffun_inv f := [ffun a => (f a)^-1].
HB.instance Definition _ := hasInv.Build {ffun aT -> rT} ffun_inv.
End FinFunBaseGroup.
Section FinFunGroup.
Variable (aT : finType) (rT : groupType).
Implicit Types f g : {ffun aT -> rT}.
Fact ffun_mulVg :
left_inverse (@ffun_one aT rT) (@ffun_inv _ _) (@ffun_mul _ _).
Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE mulVg. Qed.
Fact ffun_mulgV :
right_inverse (@ffun_one aT rT) (@ffun_inv _ _) (@ffun_mul _ _).
Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE mulgV. Qed.
HB.instance Definition _ := Monoid_isGroup.Build {ffun aT -> rT}
ffun_mulVg ffun_mulgV.
End FinFunGroup.
(* External direct product *)
Section PairMagma.
Variables G H : magmaType.
Definition mul_pair (x y : G * H) := (x.1 * y.1, x.2 * y.2).
HB.instance Definition _ := hasMul.Build (G * H)%type mul_pair.
Fact fst_is_multiplicative : {morph fst : x y / x * y}. Proof. by []. Qed.
HB.instance Definition _ :=
isMultiplicative.Build _ _ fst fst_is_multiplicative.
Fact snd_is_multiplicative : {morph snd : x y / x * y}. Proof. by []. Qed.
HB.instance Definition _ :=
isMultiplicative.Build _ _ snd snd_is_multiplicative.
End PairMagma.
Section PairSemigroup.
Variables G H : semigroupType.
Lemma pair_mulgA : associative (@mul (G * H)%type).
Proof. by move=> x y z; congr (_, _); apply/mulgA. Qed.
HB.instance Definition _ := Magma_isSemigroup.Build (G * H)%type pair_mulgA.
End PairSemigroup.
Section PairBaseUMagma.
Variables G H : baseUMagmaType.
Definition one_pair : G * H := (1, 1).
HB.instance Definition _ := hasOne.Build (G * H)%type one_pair.
Fact fst_is_umagma_morphism : fst (1 : G * H) = 1. Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build _ _ fst fst_is_umagma_morphism.
Fact snd_is_umagma_morphism : snd (1 : G * H) = 1. Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build _ _ snd snd_is_umagma_morphism.
End PairBaseUMagma.
Section PairUMagma.
Variables G H : umagmaType.
Lemma pair_mul1g : left_id (@one_pair G H) *%g.
Proof. by move=> [x y]; congr (_, _); rewrite mul1g. Qed.
Lemma pair_mulg1 : right_id (@one_pair G H) *%g.
Proof. by move=> [x y]; congr (_, _); rewrite mulg1. Qed.
HB.instance Definition _ :=
BaseUMagma_isUMagma.Build (G * H)%type pair_mul1g pair_mulg1.
End PairUMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (G H : ChoiceMagma.type) := Magma.on (G * H)%type.
HB.instance Definition _ (G H : ChoiceBaseUMagma.type) :=
BaseUMagma.on (G * H)%type.
HB.instance Definition _ (G H : monoidType) := Semigroup.on (G * H)%type.
(* /FIXME *)
Section PairBaseGroup.
Variables G H : baseGroupType.
Definition inv_pair (u : G * H) := (u.1 ^-1, u.2 ^-1).
HB.instance Definition _ := hasInv.Build (G * H)%type inv_pair.
End PairBaseGroup.
Section PairGroup.
Variables G H : groupType.
Lemma pair_mulVg : left_inverse one (@inv_pair G H) mul.
Proof. by move=> x; congr (_, _); apply/mulVg. Qed.
Lemma pair_mulgV : right_inverse one (@inv_pair G H) mul.
Proof. by move=> x; congr (_, _); apply/mulgV. Qed.
HB.instance Definition _ :=
Monoid_isGroup.Build (G * H)%type pair_mulVg pair_mulgV.
End PairGroup.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.