filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
Multiset.lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Algebra.BigOperators.Group.Multiset.Defs
import Mathlib.Algebra.Order.BigOperators.Group.List
import Mathlib.Algebra.Order.Group.Abs
import Mathlib.Algebra.Order.Monoid.OrderDual
import Mathlib.Data.List.MinMax
import Mathlib.Data.Multiset.Fold
/-!
# Big operators on a multiset in ordered groups
This file contains the results concerning the interaction of multiset big operators with ordered
groups.
-/
assert_not_exists MonoidWithZero
variable {ι α β : Type*}
namespace Multiset
section OrderedCommMonoid
variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] {s t : Multiset α} {a : α}
@[to_additive sum_nonneg]
lemma one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=
Quotient.inductionOn s fun l hl => by simpa using List.one_le_prod_of_one_le hl
@[to_additive]
lemma single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=
Quotient.inductionOn s fun l hl x hx => by simpa using List.single_le_prod hl x hx
@[to_additive sum_le_card_nsmul]
lemma prod_le_pow_card (s : Multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ card s := by
induction s using Quotient.inductionOn
simpa using List.prod_le_pow_card _ _ h
@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]
lemma all_one_of_le_one_le_of_prod_eq_one :
(∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=
Quotient.inductionOn s (by
simp only [quot_mk_to_coe, prod_coe, mem_coe]
exact fun l => List.all_one_of_le_one_le_of_prod_eq_one)
@[to_additive]
lemma prod_le_prod_of_rel_le (h : s.Rel (· ≤ ·) t) : s.prod ≤ t.prod := by
induction h with
| zero => rfl
| cons rh _ rt =>
rw [prod_cons, prod_cons]
exact mul_le_mul' rh rt
@[to_additive]
lemma prod_map_le_prod_map {s : Multiset ι} (f : ι → α) (g : ι → α) (h : ∀ i, i ∈ s → f i ≤ g i) :
(s.map f).prod ≤ (s.map g).prod :=
prod_le_prod_of_rel_le <| rel_map.2 <| rel_refl_of_refl_on h
@[to_additive]
lemma prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=
prod_le_prod_of_rel_le <| rel_map_left.2 <| rel_refl_of_refl_on h
@[to_additive]
lemma prod_le_prod_map (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=
prod_map_le_prod (α := αᵒᵈ) f h
@[to_additive card_nsmul_le_sum]
lemma pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ card s ≤ s.prod := by
rw [← Multiset.prod_replicate, ← Multiset.map_const]
exact prod_map_le_prod _ h
end OrderedCommMonoid
section
variable [CommMonoid α] [CommMonoid β] [PartialOrder β] [IsOrderedMonoid β]
@[to_additive le_sum_of_subadditive_on_pred]
lemma le_prod_of_submultiplicative_on_pred (f : α → β)
(p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)
(h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b) (hp_mul : ∀ a b, p a → p b → p (a * b))
(s : Multiset α) (hps : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by
revert s
refine Multiset.induction ?_ ?_
· simp [le_of_eq h_one]
intro a s hs hpsa
have hps : ∀ x, x ∈ s → p x := fun x hx => hpsa x (mem_cons_of_mem hx)
have hp_prod : p s.prod := prod_induction p s hp_mul hp_one hps
rw [prod_cons, map_cons, prod_cons]
exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _)
@[to_additive le_sum_of_subadditive]
lemma le_prod_of_submultiplicative (f : α → β) (h_one : f 1 = 1)
(h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : Multiset α) : f s.prod ≤ (s.map f).prod :=
le_prod_of_submultiplicative_on_pred f (fun _ => True) h_one trivial (fun x y _ _ => h_mul x y)
(by simp) s (by simp)
@[to_additive le_sum_nonempty_of_subadditive_on_pred]
lemma le_prod_nonempty_of_submultiplicative_on_pred (f : α → β) (p : α → Prop)
(h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b) (hp_mul : ∀ a b, p a → p b → p (a * b))
(s : Multiset α) (hs_nonempty : s ≠ ∅) (hs : ∀ a, a ∈ s → p a) : f s.prod ≤ (s.map f).prod := by
revert s
refine Multiset.induction ?_ ?_
· simp
rintro a s hs - hsa_prop
rw [prod_cons, map_cons, prod_cons]
by_cases hs_empty : s = ∅
· simp [hs_empty]
have hsa_restrict : ∀ x, x ∈ s → p x := fun x hx => hsa_prop x (mem_cons_of_mem hx)
have hp_sup : p s.prod := prod_induction_nonempty p hp_mul hs_empty hsa_restrict
have hp_a : p a := hsa_prop a (mem_cons_self a s)
exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _)
@[to_additive le_sum_nonempty_of_subadditive]
lemma le_prod_nonempty_of_submultiplicative (f : α → β) (h_mul : ∀ a b, f (a * b) ≤ f a * f b)
(s : Multiset α) (hs_nonempty : s ≠ ∅) : f s.prod ≤ (s.map f).prod :=
le_prod_nonempty_of_submultiplicative_on_pred f (fun _ => True) (by simp [h_mul]) (by simp) s
hs_nonempty (by simp)
end
section OrderedCancelCommMonoid
variable [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] {s : Multiset ι} {f g : ι → α}
@[to_additive sum_lt_sum]
lemma prod_lt_prod' (hle : ∀ i ∈ s, f i ≤ g i) (hlt : ∃ i ∈ s, f i < g i) :
(s.map f).prod < (s.map g).prod := by
obtain ⟨l⟩ := s
simp only [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.prod_coe]
exact List.prod_lt_prod' f g hle hlt
@[to_additive sum_lt_sum_of_nonempty]
lemma prod_lt_prod_of_nonempty' (hs : s ≠ ∅) (hfg : ∀ i ∈ s, f i < g i) :
(s.map f).prod < (s.map g).prod := by
obtain ⟨i, hi⟩ := exists_mem_of_ne_zero hs
exact prod_lt_prod' (fun i hi => le_of_lt (hfg i hi)) ⟨i, hi, hfg i hi⟩
end OrderedCancelCommMonoid
section CanonicallyOrderedMul
variable [CommMonoid α] [PartialOrder α] [CanonicallyOrderedMul α] {m : Multiset α} {a : α}
@[to_additive] lemma prod_eq_one_iff [IsOrderedMonoid α] : m.prod = 1 ↔ ∀ x ∈ m, x = (1 : α) :=
Quotient.inductionOn m fun l ↦ by simpa using List.prod_eq_one_iff
@[to_additive] lemma le_prod_of_mem (ha : a ∈ m) : a ≤ m.prod := by
obtain ⟨t, rfl⟩ := exists_cons_of_mem ha
rw [prod_cons]
exact _root_.le_mul_right (le_refl a)
end CanonicallyOrderedMul
lemma max_le_of_forall_le {α : Type*} [LinearOrder α] [OrderBot α] (l : Multiset α)
(n : α) (h : ∀ x ∈ l, x ≤ n) : l.fold max ⊥ ≤ n := by
induction l using Quotient.inductionOn
simpa using List.max_le_of_forall_le _ _ h
@[to_additive]
lemma max_prod_le [CommMonoid α] [LinearOrder α] [IsOrderedMonoid α]
{s : Multiset ι} {f g : ι → α} :
max (s.map f).prod (s.map g).prod ≤ (s.map fun i ↦ max (f i) (g i)).prod := by
obtain ⟨l⟩ := s
simp_rw [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.prod_coe]
apply List.max_prod_le
@[to_additive]
lemma prod_min_le [CommMonoid α] [LinearOrder α] [IsOrderedMonoid α]
{s : Multiset ι} {f g : ι → α} :
(s.map fun i ↦ min (f i) (g i)).prod ≤ min (s.map f).prod (s.map g).prod := by
obtain ⟨l⟩ := s
simp_rw [Multiset.quot_mk_to_coe'', Multiset.map_coe, Multiset.prod_coe]
apply List.prod_min_le
lemma abs_sum_le_sum_abs [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] {s : Multiset α} :
|s.sum| ≤ (s.map abs).sum :=
le_sum_of_subadditive _ abs_zero abs_add s
end Multiset
|
all_boot.v
|
Require Export ssreflect.
Require Export ssrbool.
Require Export ssrfun.
Require Export eqtype.
Require Export ssrnat.
Require Export seq.
Require Export choice.
Require Export monoid.
Require Export nmodule.
Require Export path.
Require Export div.
Require Export fintype.
Require Export fingraph.
Require Export tuple.
Require Export finfun.
Require Export bigop.
Require Export prime.
Require Export finset.
Require Export binomial.
Require Export generic_quotient.
Require Export ssrAC.
|
Frontend.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
-/
import Mathlib.Control.Basic
import Mathlib.Tactic.Linarith.Verification
import Mathlib.Tactic.Linarith.Preprocessing
import Mathlib.Tactic.Linarith.Oracle.SimplexAlgorithm
import Mathlib.Tactic.Ring.Basic
/-!
# `linarith`: solving linear arithmetic goals
`linarith` is a tactic for solving goals with linear arithmetic.
Suppose we have a set of hypotheses in `n` variables
`S = {a₁x₁ + a₂x₂ + ... + aₙxₙ R b₁x₁ + b₂x₂ + ... + bₙxₙ}`,
where `R ∈ {<, ≤, =, ≥, >}`.
Our goal is to determine if the inequalities in `S` are jointly satisfiable, that is, if there is
an assignment of values to `x₁, ..., xₙ` such that every inequality in `S` is true.
Specifically, we aim to show that they are *not* satisfiable. This amounts to proving a
contradiction. If our goal is also a linear inequality, we negate it and move it to a hypothesis
before trying to prove `False`.
When the inequalities are over a dense linear order, `linarith` is a decision procedure: it will
prove `False` if and only if the inequalities are unsatisfiable. `linarith` will also run on some
types like `ℤ` that are not dense orders, but it will fail to prove `False` on some unsatisfiable
problems. It will run over concrete types like `ℕ`, `ℚ`, and `ℝ`, as well as abstract types that
are instances of `CommRing`, `LinearOrder` and `IsStrictOrderedRing`.
## Algorithm sketch
First, the inequalities in the set `S` are rearranged into the form `tᵢ Rᵢ 0`, where
`Rᵢ ∈ {<, ≤, =}` and each `tᵢ` is of the form `∑ cⱼxⱼ`.
`linarith` uses an untrusted oracle to search for a certificate of unsatisfiability.
The oracle searches for a list of natural number coefficients `kᵢ` such that `∑ kᵢtᵢ = 0`, where for
at least one `i`, `kᵢ > 0` and `Rᵢ = <`.
Given a list of such coefficients, `linarith` verifies that `∑ kᵢtᵢ = 0` using a normalization
tactic such as `ring`. It proves that `∑ kᵢtᵢ < 0` by transitivity, since each component of the sum
is either equal to, less than or equal to, or less than zero by hypothesis. This produces a
contradiction.
## Preprocessing
`linarith` does some basic preprocessing before running. Most relevantly, inequalities over natural
numbers are cast into inequalities about integers, and rational division by numerals is canceled
into multiplication. We do this so that we can guarantee the coefficients in the certificate are
natural numbers, which allows the tactic to solve goals over types that are not fields.
Preprocessors are allowed to branch, that is, to case split on disjunctions. `linarith` will succeed
overall if it succeeds in all cases. This leads to exponential blowup in the number of `linarith`
calls, and should be used sparingly. The default preprocessor set does not include case splits.
## Oracles
There are two oracles that can be used in `linarith` so far.
1. **Fourier-Motzkin elimination.**
This technique transforms a set of inequalities in `n` variables to an equisatisfiable set in
`n - 1` variables. Once all variables have been eliminated, we conclude that the original set was
unsatisfiable iff the comparison `0 < 0` is in the resulting set.
While performing this elimination, we track the history of each derived comparison. This allows us
to represent any comparison at any step as a positive combination of comparisons from the original
set. In particular, if we derive `0 < 0`, we can find our desired list of coefficients
by counting how many copies of each original comparison appear in the history.
This oracle was historically implemented earlier, and is sometimes faster on small states, but it
has [bugs](https://github.com/leanprover-community/mathlib4/issues/2717) and can not handle
large problems. You can use it with `linarith (oracle := .fourierMotzkin)`.
2. **Simplex Algorithm (default).**
This oracle reduces the search for a unsatisfiability certificate to some Linear Programming
problem. The problem is then solved by a standard Simplex Algorithm. We use
[Bland's pivot rule](https://en.wikipedia.org/wiki/Bland%27s_rule) to guarantee that the algorithm
terminates.
The default version of the algorithm operates with sparse matrices as it is usually faster. You
can invoke the dense version by `linarith (oracle := .simplexAlgorithmDense)`.
## Implementation details
`linarith` homogenizes numerical constants: the expression `1` is treated as a variable `t₀`.
Often `linarith` is called on goals that have comparison hypotheses over multiple types. This
creates multiple `linarith` problems, each of which is handled separately; the goal is solved as
soon as one problem is found to be contradictory.
Disequality hypotheses `t ≠ 0` do not fit in this pattern. `linarith` will attempt to prove equality
goals by splitting them into two weak inequalities and running twice. But it does not split
disequality hypotheses, since this would lead to a number of runs exponential in the number of
disequalities in the context.
The oracle is very modular. It can easily be replaced with another function of type
`List Comp → ℕ → MetaM ((Std.HashMap ℕ ℕ))`,
which takes a list of comparisons and the largest variable
index appearing in those comparisons, and returns a map from comparison indices to coefficients.
An alternate oracle can be specified in the `LinarithConfig` object.
A variant, `nlinarith`, adds an extra preprocessing step to handle some basic nonlinear goals.
There is a hook in the `LinarithConfig` configuration object to add custom preprocessing routines.
The certificate checking step is *not* by reflection. `linarith` converts the certificate into a
proof term of type `False`.
Some of the behavior of `linarith` can be inspected with the option
`set_option trace.linarith true`.
However, both oracles mainly runs outside the tactic monad, so we cannot trace intermediate
steps there.
## File structure
The components of `linarith` are spread between a number of files for the sake of organization.
* `Lemmas.lean` contains proofs of some arithmetic lemmas that are used in preprocessing and in
verification.
* `Datatypes.lean` contains data structures that are used across multiple files, along with some
useful auxiliary functions.
* `Preprocessing.lean` contains functions used at the beginning of the tactic to transform
hypotheses into a shape suitable for the main routine.
* `Parsing.lean` contains functions used to compute the linear structure of an expression.
* The `Oracle` folder contains files implementing the oracles that can be used to produce a
certificate of unsatisfiability.
* `Verification.lean` contains the certificate checking functions that produce a proof of `False`.
* `Frontend.lean` contains the control methods and user-facing components of the tactic.
## Tags
linarith, nlinarith, lra, nra, Fourier-Motzkin, linear arithmetic, linear programming
-/
open Lean Elab Parser Tactic Meta
open Batteries
namespace Mathlib.Tactic.Linarith
/-! ### Config objects
The config object is defined in the frontend, instead of in `Datatypes.lean`, since the oracles must
be in context to choose a default.
-/
section
/-- A configuration object for `linarith`. -/
structure LinarithConfig : Type where
/-- Discharger to prove that a candidate linear combination of hypothesis is zero. -/
-- TODO There should be a def for this, rather than calling `evalTactic`?
discharger : TacticM Unit := do evalTactic (← `(tactic| ring1))
-- We can't actually store a `Type` here,
-- as we want `LinarithConfig : Type` rather than ` : Type 1`,
-- so that we can define `elabLinarithConfig : Lean.Syntax → Lean.Elab.TermElabM LinarithConfig`.
-- For now, we simply don't support restricting the type.
-- (restrict_type : Option Type := none)
/-- Prove goals which are not linear comparisons by first calling `exfalso`. -/
exfalso : Bool := true
/-- Transparency mode for identifying atomic expressions in comparisons. -/
transparency : TransparencyMode := .reducible
/-- Split conjunctions in hypotheses. -/
splitHypotheses : Bool := true
/-- Split `≠` in hypotheses, by branching in cases `<` and `>`. -/
splitNe : Bool := false
/-- Override the list of preprocessors. -/
preprocessors : List GlobalBranchingPreprocessor := defaultPreprocessors
/-- Specify an oracle for identifying candidate contradictions.
`.simplexAlgorithmSparse`, `.simplexAlgorithmSparse`, and `.fourierMotzkin` are available. -/
oracle : CertificateOracle := .simplexAlgorithmSparse
/--
`cfg.updateReducibility reduce_default` will change the transparency setting of `cfg` to
`default` if `reduce_default` is true. In this case, it also sets the discharger to `ring!`,
since this is typically needed when using stronger unification.
-/
def LinarithConfig.updateReducibility (cfg : LinarithConfig) (reduce_default : Bool) :
LinarithConfig :=
if reduce_default then
{ cfg with transparency := .default, discharger := do evalTactic (← `(tactic| ring1!)) }
else cfg
end
/-! ### Control -/
/--
If `e` is a comparison `a R b` or the negation of a comparison `¬ a R b`, found in the target,
`getContrLemma e` returns the name of a lemma that will change the goal to an
implication, along with the type of `a` and `b`.
For example, if `e` is `(a : ℕ) < b`, returns ``(`lt_of_not_ge, ℕ)``.
-/
def getContrLemma (e : Expr) : MetaM (Name × Expr) := do
match ← e.ineqOrNotIneq? with
| (true, Ineq.lt, t, _) => pure (``lt_of_not_ge, t)
| (true, Ineq.le, t, _) => pure (``le_of_not_gt, t)
| (true, Ineq.eq, t, _) => pure (``eq_of_not_lt_of_not_gt, t)
| (false, _, t, _) => pure (``Not.intro, t)
/--
`applyContrLemma` inspects the target to see if it can be moved to a hypothesis by negation.
For example, a goal `⊢ a ≤ b` can become `b < a ⊢ false`.
If this is the case, it applies the appropriate lemma and introduces the new hypothesis.
It returns the type of the terms in the comparison (e.g. the type of `a` and `b` above) and the
newly introduced local constant.
Otherwise returns `none`.
-/
def applyContrLemma (g : MVarId) : MetaM (Option (Expr × Expr) × MVarId) := do
try
let (nm, tp) ← getContrLemma (← withReducible g.getType')
let [g] ← g.apply (← mkConst' nm) | failure
let (f, g) ← g.intro1P
return (some (tp, .fvar f), g)
catch _ => return (none, g)
/-- A map of keys to values, where the keys are `Expr` up to defeq and one key can be
associated to multiple values. -/
abbrev ExprMultiMap α := Array (Expr × List α)
/-- Retrieves the list of values at a key, as well as the index of the key for later modification.
(If the key is not in the map it returns `self.size` as the index.) -/
def ExprMultiMap.find {α : Type} (self : ExprMultiMap α) (k : Expr) : MetaM (Nat × List α) := do
for h : i in [:self.size] do
let (k', vs) := self[i]
if ← isDefEq k' k then
return (i, vs)
return (self.size, [])
/-- Insert a new value into the map at key `k`. This does a defeq check with all other keys
in the map. -/
def ExprMultiMap.insert {α : Type} (self : ExprMultiMap α) (k : Expr) (v : α) :
MetaM (ExprMultiMap α) := do
for h : i in [:self.size] do
if ← isDefEq self[i].1 k then
return self.modify i fun (k, vs) => (k, v::vs)
return self.push (k, [v])
/--
`partitionByType l` takes a list `l` of proofs of comparisons. It sorts these proofs by
the type of the variables in the comparison, e.g. `(a : ℚ) < 1` and `(b : ℤ) > c` will be separated.
Returns a map from a type to a list of comparisons over that type.
-/
def partitionByType (l : List Expr) : MetaM (ExprMultiMap Expr) :=
l.foldlM (fun m h => do m.insert (← typeOfIneqProof h) h) #[]
/--
Given a list `ls` of lists of proofs of comparisons, `findLinarithContradiction cfg ls` will try to
prove `False` by calling `linarith` on each list in succession. It will stop at the first proof of
`False`, and fail if no contradiction is found with any list.
-/
def findLinarithContradiction (cfg : LinarithConfig) (g : MVarId) (ls : List (Expr × List Expr)) :
MetaM Expr :=
try
ls.firstM (fun ⟨α, L⟩ =>
withTraceNode `linarith (return m!"{exceptEmoji ·} running on type {α}") <|
proveFalseByLinarith cfg.transparency cfg.oracle cfg.discharger g L)
catch e => throwError "linarith failed to find a contradiction\n{g}\n{e.toMessageData}"
/--
Given a list `hyps` of proofs of comparisons, `runLinarith cfg hyps prefType`
preprocesses `hyps` according to the list of preprocessors in `cfg`.
This results in a list of branches (typically only one),
each of which must succeed in order to close the goal.
In each branch, we partition the list of hypotheses by type, and run `linarith` on each class
in the partition; one of these must succeed in order for `linarith` to succeed on this branch.
If `prefType` is given, it will first use the class of proofs of comparisons over that type.
-/
-- If it succeeds, the passed metavariable should have been assigned.
def runLinarith (cfg : LinarithConfig) (prefType : Option Expr) (g : MVarId)
(hyps : List Expr) : MetaM Unit := do
let singleProcess (g : MVarId) (hyps : List Expr) : MetaM Expr := g.withContext do
linarithTraceProofs s!"after preprocessing, linarith has {hyps.length} facts:" hyps
let mut hyp_set ← partitionByType hyps
trace[linarith] "hypotheses appear in {hyp_set.size} different types"
-- If we have a preferred type, strip it from `hyp_set` and prepare a handler with a custom
-- trace message
let pref : MetaM _ ← do
if let some t := prefType then
let (i, vs) ← hyp_set.find t
hyp_set := hyp_set.eraseIdxIfInBounds i
pure <|
withTraceNode `linarith (return m!"{exceptEmoji ·} running on preferred type {t}") <|
proveFalseByLinarith cfg.transparency cfg.oracle cfg.discharger g vs
else
pure failure
pref <|> findLinarithContradiction cfg g hyp_set.toList
let mut preprocessors := cfg.preprocessors
if cfg.splitNe then
preprocessors := Linarith.removeNe :: preprocessors
if cfg.splitHypotheses then
preprocessors := Linarith.splitConjunctions.globalize.branching :: preprocessors
let branches ← preprocess preprocessors g hyps
for (g, es) in branches do
let r ← singleProcess g es
g.assign r
-- Verify that we closed the goal. Failure here should only result from a bad `Preprocessor`.
(Expr.mvar g).ensureHasNoMVars
-- /--
-- `filterHyps restr_type hyps` takes a list of proofs of comparisons `hyps`, and filters it
-- to only those that are comparisons over the type `restr_type`.
-- -/
-- def filterHyps (restr_type : Expr) (hyps : List Expr) : MetaM (List Expr) :=
-- hyps.filterM (fun h => do
-- let ht ← inferType h
-- match getContrLemma ht with
-- | some (_, htype) => isDefEq htype restr_type
-- | none => return false)
/--
`linarith only_on hyps cfg` tries to close the goal using linear arithmetic. It fails
if it does not succeed at doing this.
* `hyps` is a list of proofs of comparisons to include in the search.
* If `only_on` is true, the search will be restricted to `hyps`. Otherwise it will use all
comparisons in the local context.
* If `cfg.transparency := semireducible`,
it will unfold semireducible definitions when trying to match atomic expressions.
-/
partial def linarith (only_on : Bool) (hyps : List Expr) (cfg : LinarithConfig := {})
(g : MVarId) : MetaM Unit := g.withContext do
-- if the target is an equality, we run `linarith` twice, to prove ≤ and ≥.
if (← whnfR (← instantiateMVars (← g.getType))).isEq then
trace[linarith] "target is an equality: splitting"
if let some [g₁, g₂] ← try? (g.apply (← mkConst' ``eq_of_not_lt_of_not_gt)) then
withTraceNode `linarith (return m!"{exceptEmoji ·} proving ≥") <| linarith only_on hyps cfg g₁
withTraceNode `linarith (return m!"{exceptEmoji ·} proving ≤") <| linarith only_on hyps cfg g₂
return
/- If we are proving a comparison goal (and not just `False`), we consider the type of the
elements in the comparison to be the "preferred" type. That is, if we find comparison
hypotheses in multiple types, we will run `linarith` on the goal type first.
In this case we also receive a new variable from moving the goal to a hypothesis.
Otherwise, there is no preferred type and no new variable; we simply change the goal to `False`.
-/
let (g, target_type, new_var) ← match ← applyContrLemma g with
| (none, g) =>
if cfg.exfalso then
trace[linarith] "using exfalso"
pure (← g.exfalso, none, none)
else
pure (g, none, none)
| (some (t, v), g) => pure (g, some t, some v)
g.withContext do
-- set up the list of hypotheses, considering the `only_on` and `restrict_type` options
let hyps ← (if only_on then return new_var.toList ++ hyps
else return (← getLocalHyps).toList ++ hyps)
-- TODO in mathlib3 we could specify a restriction to a single type.
-- I haven't done that here because I don't know how to store a `Type` in `LinarithConfig`.
-- There's only one use of the `restrict_type` configuration option in mathlib3,
-- and it can be avoided just by using `linarith only`.
linarithTraceProofs "linarith is running on the following hypotheses:" hyps
runLinarith cfg target_type g hyps
end Linarith
/-! ### User facing functions -/
open Syntax
/-- Syntax for the arguments of `linarith`, after the optional `!`. -/
syntax linarithArgsRest := optConfig (&" only")? (" [" term,* "]")?
/--
`linarith` attempts to find a contradiction between hypotheses that are linear (in)equalities.
Equivalently, it can prove a linear inequality by assuming its negation and proving `False`.
In theory, `linarith` should prove any goal that is true in the theory of linear arithmetic over
the rationals. While there is some special handling for non-dense orders like `Nat` and `Int`,
this tactic is not complete for these theories and will not prove every true goal. It will solve
goals over arbitrary types that instantiate `CommRing`, `LinearOrder` and `IsStrictOrderedRing`.
An example:
```lean
example (x y z : ℚ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0)
(h3 : 12*y - 4* z < 0) : False := by
linarith
```
`linarith` will use all appropriate hypotheses and the negation of the goal, if applicable.
Disequality hypotheses require case splitting and are not normally considered
(see the `splitNe` option below).
`linarith [t1, t2, t3]` will additionally use proof terms `t1, t2, t3`.
`linarith only [h1, h2, h3, t1, t2, t3]` will use only the goal (if relevant), local hypotheses
`h1`, `h2`, `h3`, and proofs `t1`, `t2`, `t3`. It will ignore the rest of the local context.
`linarith!` will use a stronger reducibility setting to try to identify atoms. For example,
```lean
example (x : ℚ) : id x ≥ x := by
linarith
```
will fail, because `linarith` will not identify `x` and `id x`. `linarith!` will.
This can sometimes be expensive.
`linarith (config := { .. })` takes a config object with five
optional arguments:
* `discharger` specifies a tactic to be used for reducing an algebraic equation in the
proof stage. The default is `ring`. Other options include `simp` for basic
problems.
* `transparency` controls how hard `linarith` will try to match atoms to each other. By default
it will only unfold `reducible` definitions.
* If `splitHypotheses` is true, `linarith` will split conjunctions in the context into separate
hypotheses.
* If `splitNe` is `true`, `linarith` will case split on disequality hypotheses.
For a given `x ≠ y` hypothesis, `linarith` is run with both `x < y` and `x > y`,
and so this runs linarith exponentially many times with respect to the number of
disequality hypotheses. (`false` by default.)
* If `exfalso` is `false`, `linarith` will fail when the goal is neither an inequality nor `False`.
(`true` by default.)
* `restrict_type` (not yet implemented in mathlib4)
will only use hypotheses that are inequalities over `tp`. This is useful
if you have e.g. both integer and rational valued inequalities in the local context, which can
sometimes confuse the tactic.
A variant, `nlinarith`, does some basic preprocessing to handle some nonlinear goals.
The option `set_option trace.linarith true` will trace certain intermediate stages of the `linarith`
routine.
-/
syntax (name := linarith) "linarith" "!"? linarithArgsRest : tactic
@[inherit_doc linarith] macro "linarith!" rest:linarithArgsRest : tactic =>
`(tactic| linarith ! $rest:linarithArgsRest)
/--
An extension of `linarith` with some preprocessing to allow it to solve some nonlinear arithmetic
problems. (Based on Coq's `nra` tactic.) See `linarith` for the available syntax of options,
which are inherited by `nlinarith`; that is, `nlinarith!` and `nlinarith only [h1, h2]` all work as
in `linarith`. The preprocessing is as follows:
* For every subterm `a ^ 2` or `a * a` in a hypothesis or the goal,
the assumption `0 ≤ a ^ 2` or `0 ≤ a * a` is added to the context.
* For every pair of hypotheses `a1 R1 b1`, `a2 R2 b2` in the context, `R1, R2 ∈ {<, ≤, =}`,
the assumption `0 R' (b1 - a1) * (b2 - a2)` is added to the context (non-recursively),
where `R ∈ {<, ≤, =}` is the appropriate comparison derived from `R1, R2`.
-/
syntax (name := nlinarith) "nlinarith" "!"? linarithArgsRest : tactic
@[inherit_doc nlinarith] macro "nlinarith!" rest:linarithArgsRest : tactic =>
`(tactic| nlinarith ! $rest:linarithArgsRest)
/-- Elaborate `t` in a way that is suitable for linarith. -/
def elabLinarithArg (tactic : Name) (t : Term) : TacticM Expr := Term.withoutErrToSorry do
let (e, mvars) ← elabTermWithHoles t none tactic
unless mvars.isEmpty do
throwErrorAt t "Argument passed to {tactic} has metavariables:{indentD e}"
return e
/--
Allow elaboration of `LinarithConfig` arguments to tactics.
-/
declare_config_elab elabLinarithConfig Linarith.LinarithConfig
elab_rules : tactic
| `(tactic| linarith $[!%$bang]? $cfg:optConfig $[only%$o]? $[[$args,*]]?) => withMainContext do
let args ← ((args.map (TSepArray.getElems)).getD {}).mapM (elabLinarithArg `linarith)
let cfg := (← elabLinarithConfig cfg).updateReducibility bang.isSome
commitIfNoEx do liftMetaFinishingTactic <| Linarith.linarith o.isSome args.toList cfg
-- TODO restore this when `add_tactic_doc` is ported
-- add_tactic_doc
-- { name := "linarith",
-- category := doc_category.tactic,
-- decl_names := [`tactic.interactive.linarith],
-- tags := ["arithmetic", "decision procedure", "finishing"] }
open Linarith
elab_rules : tactic
| `(tactic| nlinarith $[!%$bang]? $cfg:optConfig $[only%$o]? $[[$args,*]]?) => withMainContext do
let args ← ((args.map (TSepArray.getElems)).getD {}).mapM (elabLinarithArg `nlinarith)
let cfg := (← elabLinarithConfig cfg).updateReducibility bang.isSome
let cfg := { cfg with
preprocessors := cfg.preprocessors.concat nlinarithExtras }
commitIfNoEx do liftMetaFinishingTactic <| Linarith.linarith o.isSome args.toList cfg
-- TODO restore this when `add_tactic_doc` is ported
-- add_tactic_doc
-- { name := "nlinarith",
-- category := doc_category.tactic,
-- decl_names := [`tactic.interactive.nlinarith],
-- tags := ["arithmetic", "decision procedure", "finishing"] }
end Mathlib.Tactic
|
test_intro_rw.v
|
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Lemma test_dup1 : forall n : nat, odd n.
Proof. move=> /[dup] m n; suff: odd n by []. Abort.
Lemma test_dup2 : let n := 1 in False.
Proof. move=> /[dup] m n; have : m = n := erefl. Abort.
Lemma test_swap1 : forall (n : nat) (b : bool), odd n = b.
Proof. move=> /[swap] b n; suff: odd n = b by []. Abort.
Lemma test_swap1 : let n := 1 in let b := true in False.
Proof. move=> /[swap] b n; have : odd n = b := erefl. Abort.
Lemma test_apply A B : forall (f : A -> B) (a : A), False.
Proof.
move=> /[apply] b.
Check (b : B).
Abort.
Lemma test_swap_plus P Q : P -> Q -> False.
Proof.
move=> + /[dup] q.
suff: P -> Q -> False by [].
Abort.
Lemma test_dup_plus2 P : P -> let x := 0 in False.
Proof.
move=> + /[dup] y.
suff: P -> let x := 0 in False by [].
Abort.
Lemma test_swap_plus P Q R : P -> Q -> R -> False.
Proof.
move=> + /[swap].
suff: P -> R -> Q -> False by [].
Abort.
Lemma test_swap_plus2 P : P -> let x := 0 in let y := 1 in False.
Proof.
move=> + /[swap].
suff: P -> let y := 1 in let x := 0 in False by [].
Abort.
|
Basic.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 Batteries.Data.String.Lemmas
import Mathlib.Data.List.Lex
import Mathlib.Data.Char
import Mathlib.Algebra.Order.Group.Nat
/-!
# Strings
Supplementary theorems about the `String` type.
-/
namespace String
@[simp] theorem endPos_empty : "".endPos = 0 := rfl
/-- `<` on string iterators. This coincides with `<` on strings as lists. -/
def ltb (s₁ s₂ : Iterator) : Bool :=
if s₂.hasNext then
if s₁.hasNext then
if s₁.curr = s₂.curr then
ltb s₁.next s₂.next
else s₁.curr < s₂.curr
else true
else false
/-- This overrides an instance in core Lean. -/
instance LT' : LT String :=
⟨fun s₁ s₂ ↦ ltb s₁.iter s₂.iter⟩
/-- This instance has a prime to avoid the name of the corresponding instance in core Lean. -/
instance decidableLT' : DecidableLT String := by
simp only [DecidableLT, LT']
infer_instance -- short-circuit type class inference
/-- Induction on `String.ltb`. -/
def ltb.inductionOn.{u} {motive : Iterator → Iterator → Sort u} (it₁ it₂ : Iterator)
(ind : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → Iterator.hasNext ⟨s₁, i₁⟩ →
get s₁ i₁ = get s₂ i₂ → motive (Iterator.next ⟨s₁, i₁⟩) (Iterator.next ⟨s₂, i₂⟩) →
motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩)
(eq : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → Iterator.hasNext ⟨s₁, i₁⟩ →
¬ get s₁ i₁ = get s₂ i₂ → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩)
(base₁ : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → ¬ Iterator.hasNext ⟨s₁, i₁⟩ →
motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩)
(base₂ : ∀ s₁ s₂ i₁ i₂, ¬ Iterator.hasNext ⟨s₂, i₂⟩ → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩) :
motive it₁ it₂ :=
if h₂ : it₂.hasNext then
if h₁ : it₁.hasNext then
if heq : it₁.curr = it₂.curr then
ind it₁.s it₂.s it₁.i it₂.i h₂ h₁ heq (inductionOn it₁.next it₂.next ind eq base₁ base₂)
else eq it₁.s it₂.s it₁.i it₂.i h₂ h₁ heq
else base₁ it₁.s it₂.s it₁.i it₂.i h₂ h₁
else base₂ it₁.s it₂.s it₁.i it₂.i h₂
theorem ltb_cons_addChar (c : Char) (cs₁ cs₂ : List Char) (i₁ i₂ : Pos) :
ltb ⟨⟨c :: cs₁⟩, i₁ + c⟩ ⟨⟨c :: cs₂⟩, i₂ + c⟩ = ltb ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ := by
apply ltb.inductionOn ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ (motive := fun ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ ↦
ltb ⟨⟨c :: cs₁⟩, i₁ + c⟩ ⟨⟨c :: cs₂⟩, i₂ + c⟩ =
ltb ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩) <;> simp only <;>
intro ⟨cs₁⟩ ⟨cs₂⟩ i₁ i₂ <;>
intros <;>
(conv => lhs; unfold ltb) <;> (conv => rhs; unfold ltb) <;>
simp only [Iterator.hasNext_cons_addChar, ite_false, ite_true, *, reduceCtorEq]
· rename_i h₂ h₁ heq ih
simp only [Iterator.next, next, heq, Iterator.curr, get_cons_addChar, ite_true] at ih ⊢
repeat rw [Pos.addChar_right_comm _ c]
exact ih
· rename_i h₂ h₁ hne
simp [Iterator.curr, get_cons_addChar, hne]
@[simp]
theorem lt_iff_toList_lt : ∀ {s₁ s₂ : String}, s₁ < s₂ ↔ s₁.toList < s₂.toList
| ⟨s₁⟩, ⟨s₂⟩ => show ltb ⟨⟨s₁⟩, 0⟩ ⟨⟨s₂⟩, 0⟩ ↔ s₁ < s₂ by
induction s₁ generalizing s₂ <;> cases s₂
· unfold ltb; decide
· rename_i c₂ cs₂; apply iff_of_true
· unfold ltb
simp [Iterator.hasNext, Char.utf8Size_pos]
· apply List.nil_lt_cons
· rename_i c₁ cs₁ ih; apply iff_of_false
· unfold ltb
simp [Iterator.hasNext]
· apply not_lt_of_gt; apply List.nil_lt_cons
· rename_i c₁ cs₁ ih c₂ cs₂; unfold ltb
simp only [Iterator.hasNext, Pos.byteIdx_zero, endPos, utf8ByteSize, utf8ByteSize.go,
add_pos_iff, Char.utf8Size_pos, or_true, decide_eq_true_eq, ↓reduceIte, Iterator.curr, get,
utf8GetAux, Iterator.next, next, Bool.ite_eq_true_distrib]
split_ifs with h
· subst c₂
suffices ltb ⟨⟨c₁ :: cs₁⟩, (0 : Pos) + c₁⟩ ⟨⟨c₁ :: cs₂⟩, (0 : Pos) + c₁⟩ =
ltb ⟨⟨cs₁⟩, 0⟩ ⟨⟨cs₂⟩, 0⟩ by rw [this]; exact (ih cs₂).trans List.lex_cons_iff.symm
apply ltb_cons_addChar
· refine ⟨List.Lex.rel, fun e ↦ ?_⟩
cases e <;> rename_i h'
· assumption
· contradiction
instance LE : LE String :=
⟨fun s₁ s₂ ↦ ¬s₂ < s₁⟩
instance decidableLE : DecidableLE String := by
simp only [DecidableLE, LE]
infer_instance -- short-circuit type class inference
@[simp]
theorem le_iff_toList_le {s₁ s₂ : String} : s₁ ≤ s₂ ↔ s₁.toList ≤ s₂.toList :=
(not_congr lt_iff_toList_lt).trans not_lt
theorem toList_inj {s₁ s₂ : String} : s₁.toList = s₂.toList ↔ s₁ = s₂ :=
⟨congr_arg mk, congr_arg toList⟩
theorem asString_nil : [].asString = "" :=
rfl
@[simp]
theorem toList_empty : "".toList = [] :=
rfl
theorem asString_toList (s : String) : s.toList.asString = s :=
rfl
theorem toList_nonempty : ∀ {s : String}, s ≠ "" → s.toList = s.head :: (s.drop 1).toList
| ⟨s⟩, h => by
cases s with
| nil => simp at h
| cons c cs =>
simp only [toList, data_drop, List.drop_succ_cons, List.drop_zero, List.cons.injEq, and_true]
rfl
@[simp]
theorem head_empty : "".data.head! = default :=
rfl
instance : LinearOrder String where
le_refl _ := le_iff_toList_le.mpr le_rfl
le_trans a b c := by
simp only [le_iff_toList_le]
apply le_trans
lt_iff_le_not_ge a b := by
simp only [lt_iff_toList_lt, le_iff_toList_le, lt_iff_le_not_ge]
le_antisymm a b := by
simp only [le_iff_toList_le, ← toList_inj]
apply le_antisymm
le_total a b := by
simp only [le_iff_toList_le]
apply le_total
toDecidableLE := String.decidableLE
toDecidableEq := inferInstance
toDecidableLT := String.decidableLT'
compare_eq_compareOfLessAndEq a b := by
simp only [compare, compareOfLessAndEq, instLT, List.instLT, lt_iff_toList_lt, toList]
split_ifs <;>
simp only [List.lt_iff_lex_lt] at *
end String
open String
namespace List
theorem toList_asString (l : List Char) : l.asString.toList = l :=
rfl
@[simp]
theorem length_asString (l : List Char) : l.asString.length = l.length :=
rfl
@[simp]
theorem asString_inj {l l' : List Char} : l.asString = l'.asString ↔ l = l' :=
⟨fun h ↦ by rw [← toList_asString l, ← toList_asString l', toList_inj, h],
fun h ↦ h ▸ rfl⟩
theorem asString_eq {l : List Char} {s : String} : l.asString = s ↔ l = s.toList := by
rw [← asString_toList s, asString_inj, asString_toList s]
end List
@[simp]
theorem String.length_data (s : String) : s.data.length = s.length :=
rfl
|
Integral.lean
|
/-
Copyright (c) 2024 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Anatole Dedecker
-/
import Mathlib.Analysis.Normed.Algebra.Spectrum
import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unital
import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.NonUnital
import Mathlib.MeasureTheory.SpecificCodomains.ContinuousMapZero
/-!
# Integrals and the continuous functional calculus
This file gives results about integrals of the form `∫ x, cfc (f x) a`. Most notably, we show
that the integral commutes with the continuous functional calculus under appropriate conditions.
## Main declarations
+ `cfc_setIntegral` (resp. `cfc_integral`): given a function `f : X → 𝕜 → 𝕜`, we have that
`cfc (fun r => ∫ x in s, f x r ∂μ) a = ∫ x in s, cfc (f x) a ∂μ`
under appropriate conditions (resp. with `s = univ`)
+ `cfcₙ_setIntegral`, `cfcₙ_integral`: the same for the non-unital continuous functional calculus
+ `integrableOn_cfc`, `integrableOn_cfcₙ`, `integrable_cfc`, `integrable_cfcₙ`:
functions of the form `fun x => cfc (f x) a` are integrable.
## Implementation Notes
The lemmas mentioned above are stated under much stricter hypotheses than necessary
(typically, simultaneous continuity of `f` in the parameter and the spectrum element).
They all come with primed version which only assume what's needed, and may be used together
with the API developed in `Mathlib.MeasureTheory.SpecificCodomains.ContinuousMap`.
## TODO
+ Lift this to the case where the CFC is over `ℝ≥0`
+ Use this to prove operator monotonicity and concavity/convexity of `rpow` and `log`
-/
open MeasureTheory Topology
open scoped ContinuousMapZero
section unital
open ContinuousMap
variable {X : Type*} {𝕜 : Type*} {A : Type*} {p : A → Prop} [RCLike 𝕜]
[MeasurableSpace X] {μ : Measure X}
[NormedRing A] [StarRing A] [NormedAlgebra 𝕜 A]
[ContinuousFunctionalCalculus 𝕜 A p]
[CompleteSpace A]
lemma cfcL_integral [NormedSpace ℝ A] (a : A) (f : X → C(spectrum 𝕜 a, 𝕜)) (hf₁ : Integrable f μ)
(ha : p a := by cfc_tac) :
∫ x, cfcL (a := a) ha (f x) ∂μ = cfcL (a := a) ha (∫ x, f x ∂μ) := by
rw [ContinuousLinearMap.integral_comp_comm _ hf₁]
lemma cfcL_integrable (a : A) (f : X → C(spectrum 𝕜 a, 𝕜))
(hf₁ : Integrable f μ) (ha : p a := by cfc_tac) :
Integrable (fun x ↦ cfcL (a := a) ha (f x)) μ :=
ContinuousLinearMap.integrable_comp _ hf₁
lemma cfcHom_integral [NormedSpace ℝ A] (a : A) (f : X → C(spectrum 𝕜 a, 𝕜))
(hf₁ : Integrable f μ) (ha : p a := by cfc_tac) :
∫ x, cfcHom (a := a) ha (f x) ∂μ = cfcHom (a := a) ha (∫ x, f x ∂μ) :=
cfcL_integral a f hf₁ ha
/-- An integrability criterion for the continuous functional calculus.
For a version with stronger assumptions which in practice are often easier to verify, see
`integrable_cfc`. -/
lemma integrable_cfc' (f : X → 𝕜 → 𝕜) (a : A)
(hf : Integrable
(fun x : X => mkD ((spectrum 𝕜 a).restrict (f x)) 0) μ)
(ha : p a := by cfc_tac) :
Integrable (fun x => cfc (f x) a) μ := by
conv in cfc _ _ => rw [cfc_eq_cfcL_mkD _ a]
exact cfcL_integrable _ _ hf ha
/-- An integrability criterion for the continuous functional calculus.
For a version with stronger assumptions which in practice are often easier to verify, see
`integrableOn_cfc`. -/
lemma integrableOn_cfc' {s : Set X} (f : X → 𝕜 → 𝕜) (a : A)
(hf : IntegrableOn
(fun x : X => mkD ((spectrum 𝕜 a).restrict (f x)) 0) s μ)
(ha : p a := by cfc_tac) :
IntegrableOn (fun x => cfc (f x) a) s μ := by
exact integrable_cfc' _ _ hf ha
open Set Function in
/-- An integrability criterion for the continuous functional calculus.
This version assumes joint continuity of `f`, see `integrable_cfc'` for a statement
with weaker assumptions. -/
lemma integrable_cfc [TopologicalSpace X] [OpensMeasurableSpace X] (f : X → 𝕜 → 𝕜)
(bound : X → ℝ) (a : A) [SecondCountableTopologyEither X C(spectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (univ ×ˢ spectrum 𝕜 a))
(bound_ge : ∀ᵐ x ∂μ, ∀ z ∈ spectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound μ) (ha : p a := by cfc_tac) :
Integrable (fun x => cfc (f x) a) μ := by
refine integrable_cfc' _ _ ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_mkD_restrict_of_uncurry _ _ hf
· refine hasFiniteIntegral_mkD_restrict_of_bound f _ ?_ bound bound_int bound_ge
exact .of_forall fun x ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨Set.mem_univ _, hz⟩
open Set Function in
/-- An integrability criterion for the continuous functional calculus.
This version assumes joint continuity of `f`, see `integrableOn_cfc'` for a statement
with weaker assumptions. -/
lemma integrableOn_cfc [TopologicalSpace X] [OpensMeasurableSpace X] {s : Set X}
(hs : MeasurableSet s) (f : X → 𝕜 → 𝕜) (bound : X → ℝ) (a : A)
[SecondCountableTopologyEither X C(spectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (s ×ˢ spectrum 𝕜 a))
(bound_ge : ∀ᵐ x ∂(μ.restrict s), ∀ z ∈ spectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound (μ.restrict s)) (ha : p a := by cfc_tac) :
IntegrableOn (fun x => cfc (f x) a) s μ := by
refine integrableOn_cfc' _ _ ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_restrict_mkD_restrict_of_uncurry hs _ _ hf
· refine hasFiniteIntegral_mkD_restrict_of_bound f _ ?_ bound bound_int bound_ge
exact ae_restrict_of_forall_mem hs fun x hx ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨hx, hz⟩
open Set in
/-- The continuous functional calculus commutes with integration.
For a version with stronger assumptions which in practice are often easier to verify, see
`cfc_integral`. -/
lemma cfc_integral' [NormedSpace ℝ A] (f : X → 𝕜 → 𝕜) (a : A)
(hf₁ : ∀ᵐ x ∂μ, ContinuousOn (f x) (spectrum 𝕜 a))
(hf₂ : Integrable
(fun x : X => mkD ((spectrum 𝕜 a).restrict (f x)) 0) μ)
(ha : p a := by cfc_tac) :
cfc (fun z => ∫ x, f x z ∂μ) a = ∫ x, cfc (f x) a ∂μ := by
have key₁ (z : spectrum 𝕜 a) :
∫ x, f x z ∂μ = (∫ x, mkD ((spectrum 𝕜 a).restrict (f x)) 0 ∂μ) z := by
rw [integral_apply hf₂]
refine integral_congr_ae ?_
filter_upwards [hf₁] with x cont_x
rw [mkD_apply_of_continuousOn cont_x]
have key₂ (z : spectrum 𝕜 a) :
∫ x, f x z ∂μ = mkD ((spectrum 𝕜 a).restrict (fun z ↦ ∫ x, f x z ∂μ)) 0 z := by
rw [mkD_apply_of_continuousOn]
rw [continuousOn_iff_continuous_restrict]
refine continuous_congr key₁ |>.mpr ?_
exact map_continuous (∫ x, mkD ((spectrum 𝕜 a).restrict (f x)) 0 ∂μ)
simp_rw [cfc_eq_cfcL_mkD _ a, cfcL_integral a _ hf₂ ha]
congr
ext z
rw [← key₁, key₂]
open Set in
/-- The continuous functional calculus commutes with integration.
For a version with stronger assumptions which in practice are often easier to verify, see
`cfc_setIntegral`. -/
lemma cfc_setIntegral' {s : Set X} [NormedSpace ℝ A] (f : X → 𝕜 → 𝕜) (a : A)
(hf₁ : ∀ᵐ x ∂(μ.restrict s), ContinuousOn (f x) (spectrum 𝕜 a))
(hf₂ : IntegrableOn
(fun x : X => mkD ((spectrum 𝕜 a).restrict (f x)) 0) s μ)
(ha : p a := by cfc_tac) :
cfc (fun z => ∫ x in s, f x z ∂μ) a = ∫ x in s, cfc (f x) a ∂μ :=
cfc_integral' _ _ hf₁ hf₂ ha
open Function Set in
/-- The continuous functional calculus commutes with integration.
This version assumes joint continuity of `f`, see `cfc_integral'` for a statement
with weaker assumptions. -/
lemma cfc_integral [NormedSpace ℝ A] [TopologicalSpace X] [OpensMeasurableSpace X]
(f : X → 𝕜 → 𝕜) (bound : X → ℝ) (a : A) [SecondCountableTopologyEither X C(spectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (univ ×ˢ spectrum 𝕜 a))
(bound_ge : ∀ᵐ x ∂μ, ∀ z ∈ spectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound μ) (ha : p a := by cfc_tac) :
cfc (fun r => ∫ x, f x r ∂μ) a = ∫ x, cfc (f x) a ∂μ := by
have : ∀ᵐ (x : X) ∂μ, ContinuousOn (f x) (spectrum 𝕜 a) := .of_forall fun x ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨Set.mem_univ _, hz⟩
refine cfc_integral' _ _ this ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_mkD_restrict_of_uncurry _ _ hf
· exact hasFiniteIntegral_mkD_restrict_of_bound f _ this bound bound_int bound_ge
open Function Set in
/-- The continuous functional calculus commutes with integration.
This version assumes joint continuity of `f`, see `cfc_setIntegral'` for a statement
with weaker assumptions. -/
lemma cfc_setIntegral [NormedSpace ℝ A] [TopologicalSpace X] [OpensMeasurableSpace X] {s : Set X}
(hs : MeasurableSet s) (f : X → 𝕜 → 𝕜) (bound : X → ℝ) (a : A)
[SecondCountableTopologyEither X C(spectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (s ×ˢ spectrum 𝕜 a))
(bound_ge : ∀ᵐ x ∂(μ.restrict s), ∀ z ∈ spectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound (μ.restrict s)) (ha : p a := by cfc_tac) :
cfc (fun r => ∫ x in s, f x r ∂μ) a = ∫ x in s, cfc (f x) a ∂μ := by
have : ∀ᵐ (x : X) ∂(μ.restrict s), ContinuousOn (f x) (spectrum 𝕜 a) :=
ae_restrict_of_forall_mem hs fun x hx ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨hx, hz⟩
refine cfc_setIntegral' _ _ this ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_restrict_mkD_restrict_of_uncurry hs _ _ hf
· exact hasFiniteIntegral_mkD_restrict_of_bound f _ this bound bound_int bound_ge
end unital
section nonunital
open ContinuousMapZero
variable {X : Type*} {𝕜 : Type*} {A : Type*} {p : A → Prop} [RCLike 𝕜]
[MeasurableSpace X] {μ : Measure X} [NonUnitalNormedRing A] [StarRing A]
[NormedSpace 𝕜 A] [IsScalarTower 𝕜 A A] [SMulCommClass 𝕜 A A]
[NonUnitalContinuousFunctionalCalculus 𝕜 A p]
[CompleteSpace A]
lemma cfcₙL_integral [NormedSpace ℝ A] (a : A) (f : X → C(quasispectrum 𝕜 a, 𝕜)₀)
(hf₁ : Integrable f μ) (ha : p a := by cfc_tac) :
∫ x, cfcₙL (a := a) ha (f x) ∂μ = cfcₙL (a := a) ha (∫ x, f x ∂μ) := by
rw [ContinuousLinearMap.integral_comp_comm _ hf₁]
lemma cfcₙHom_integral [NormedSpace ℝ A] (a : A) (f : X → C(quasispectrum 𝕜 a, 𝕜)₀)
(hf₁ : Integrable f μ) (ha : p a := by cfc_tac) :
∫ x, cfcₙHom (a := a) ha (f x) ∂μ = cfcₙHom (a := a) ha (∫ x, f x ∂μ) :=
cfcₙL_integral a f hf₁ ha
lemma cfcₙL_integrable (a : A) (f : X → C(quasispectrum 𝕜 a, 𝕜)₀)
(hf₁ : Integrable f μ) (ha : p a := by cfc_tac) :
Integrable (fun x ↦ cfcₙL (a := a) ha (f x)) μ :=
ContinuousLinearMap.integrable_comp _ hf₁
/-- An integrability criterion for the continuous functional calculus.
For a version with stronger assumptions which in practice are often easier to verify, see
`integrable_cfcₙ`. -/
lemma integrable_cfcₙ' (f : X → 𝕜 → 𝕜) (a : A)
(hf : Integrable
(fun x : X => mkD ((quasispectrum 𝕜 a).restrict (f x)) 0) μ)
(ha : p a := by cfc_tac) :
Integrable (fun x => cfcₙ (f x) a) μ := by
conv in cfcₙ _ _ => rw [cfcₙ_eq_cfcₙL_mkD _ a]
exact cfcₙL_integrable _ _ hf ha
/-- An integrability criterion for the continuous functional calculus.
For a version with stronger assumptions which in practice are often easier to verify, see
`integrableOn_cfcₙ`. -/
lemma integrableOn_cfcₙ' {s : Set X} (f : X → 𝕜 → 𝕜) (a : A)
(hf : IntegrableOn
(fun x : X => mkD ((quasispectrum 𝕜 a).restrict (f x)) 0) s μ)
(ha : p a := by cfc_tac) :
IntegrableOn (fun x => cfcₙ (f x) a) s μ := by
exact integrable_cfcₙ' _ _ hf ha
open Set Function in
/-- An integrability criterion for the continuous functional calculus.
This version assumes joint continuity of `f`, see `integrable_cfcₙ'` for a statement
with weaker assumptions. -/
lemma integrable_cfcₙ [TopologicalSpace X] [OpensMeasurableSpace X] (f : X → 𝕜 → 𝕜)
(bound : X → ℝ) (a : A)
[SecondCountableTopologyEither X C(quasispectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (univ ×ˢ quasispectrum 𝕜 a))
(f_zero : ∀ᵐ x ∂μ, f x 0 = 0)
(bound_ge : ∀ᵐ x ∂μ, ∀ z ∈ quasispectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound μ) (ha : p a := by cfc_tac) :
Integrable (fun x => cfcₙ (f x) a) μ := by
refine integrable_cfcₙ' _ _ ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_mkD_restrict_of_uncurry _ _ hf f_zero
· refine hasFiniteIntegral_mkD_restrict_of_bound f _ ?_ f_zero bound bound_int bound_ge
exact .of_forall fun x ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨Set.mem_univ _, hz⟩
open Set Function in
/-- An integrability criterion for the continuous functional calculus.
This version assumes joint continuity of `f`, see `integrableOn_cfcₙ'` for a statement
with weaker assumptions. -/
lemma integrableOn_cfcₙ [TopologicalSpace X] [OpensMeasurableSpace X] {s : Set X}
(hs : MeasurableSet s) (f : X → 𝕜 → 𝕜) (bound : X → ℝ) (a : A)
[SecondCountableTopologyEither X C(quasispectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (s ×ˢ quasispectrum 𝕜 a))
(f_zero : ∀ᵐ x ∂(μ.restrict s), f x 0 = 0)
(bound_ge : ∀ᵐ x ∂(μ.restrict s), ∀ z ∈ quasispectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound (μ.restrict s)) (ha : p a := by cfc_tac) :
IntegrableOn (fun x => cfcₙ (f x) a) s μ := by
refine integrableOn_cfcₙ' _ _ ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_restrict_mkD_restrict_of_uncurry hs _ _ hf f_zero
· refine hasFiniteIntegral_mkD_restrict_of_bound f _ ?_ f_zero bound bound_int bound_ge
exact ae_restrict_of_forall_mem hs fun x hx ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨hx, hz⟩
open Set in
/-- The continuous functional calculus commutes with integration.
For a version with stronger assumptions which in practice are often easier to verify, see
`cfcₙ_integral`. -/
lemma cfcₙ_integral' [NormedSpace ℝ A] (f : X → 𝕜 → 𝕜) (a : A)
(hf₁ : ∀ᵐ x ∂μ, ContinuousOn (f x) (quasispectrum 𝕜 a))
(hf₂ : ∀ᵐ x ∂μ, f x 0 = 0)
(hf₃ : Integrable
(fun x : X => mkD ((quasispectrum 𝕜 a).restrict (f x)) 0) μ)
(ha : p a := by cfc_tac) :
cfcₙ (fun z => ∫ x, f x z ∂μ) a = ∫ x, cfcₙ (f x) a ∂μ := by
have key₁ (z : quasispectrum 𝕜 a) :
∫ x, f x z ∂μ = (∫ x, mkD ((quasispectrum 𝕜 a).restrict (f x)) 0 ∂μ) z := by
rw [integral_apply hf₃]
refine integral_congr_ae ?_
filter_upwards [hf₁, hf₂] with x cont_x zero_x
rw [mkD_apply_of_continuousOn cont_x zero_x]
have key₂ (z : quasispectrum 𝕜 a) :
∫ x, f x z ∂μ = mkD ((quasispectrum 𝕜 a).restrict (fun z ↦ ∫ x, f x z ∂μ)) 0 z := by
rw [mkD_apply_of_continuousOn]
· rw [continuousOn_iff_continuous_restrict]
refine continuous_congr key₁ |>.mpr ?_
exact map_continuous (∫ x, mkD ((quasispectrum 𝕜 a).restrict (f x)) 0 ∂μ)
· exact integral_eq_zero_of_ae hf₂
simp_rw [cfcₙ_eq_cfcₙL_mkD _ a, cfcₙL_integral a _ hf₃ ha]
congr
ext z
rw [← key₁, key₂]
open Set in
/-- The continuous functional calculus commutes with integration.
For a version with stronger assumptions which in practice are often easier to verify, see
`cfcₙ_setIntegral`. -/
lemma cfcₙ_setIntegral' {s : Set X} [NormedSpace ℝ A] (f : X → 𝕜 → 𝕜) (a : A)
(hf₁ : ∀ᵐ x ∂(μ.restrict s), ContinuousOn (f x) (quasispectrum 𝕜 a))
(hf₂ : ∀ᵐ x ∂(μ.restrict s), f x 0 = 0)
(hf₃ : IntegrableOn
(fun x : X => mkD ((quasispectrum 𝕜 a).restrict (f x)) 0) s μ)
(ha : p a := by cfc_tac) :
cfcₙ (fun z => ∫ x in s, f x z ∂μ) a = ∫ x in s, cfcₙ (f x) a ∂μ :=
cfcₙ_integral' _ _ hf₁ hf₂ hf₃ ha
open Function Set in
/-- The continuous functional calculus commutes with integration.
This version assumes joint continuity of `f`, see `cfcₙ_integral'` for a statement
with weaker assumptions. -/
lemma cfcₙ_integral [NormedSpace ℝ A] [TopologicalSpace X] [OpensMeasurableSpace X]
(f : X → 𝕜 → 𝕜) (bound : X → ℝ) (a : A)
[SecondCountableTopologyEither X C(quasispectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (univ ×ˢ quasispectrum 𝕜 a))
(f_zero : ∀ᵐ x ∂μ, f x 0 = 0)
(bound_ge : ∀ᵐ x ∂μ, ∀ z ∈ quasispectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound μ) (ha : p a := by cfc_tac) :
cfcₙ (fun r => ∫ x, f x r ∂μ) a = ∫ x, cfcₙ (f x) a ∂μ := by
have : ∀ᵐ (x : X) ∂μ, ContinuousOn (f x) (quasispectrum 𝕜 a) := .of_forall fun x ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨Set.mem_univ _, hz⟩
refine cfcₙ_integral' _ _ this f_zero ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_mkD_restrict_of_uncurry _ _ hf f_zero
· exact hasFiniteIntegral_mkD_restrict_of_bound f _ this f_zero bound bound_int bound_ge
open Function Set in
/-- The continuous functional calculus commutes with integration.
This version assumes joint continuity of `f`, see `cfcₙ_setIntegral'` for a statement
with weaker assumptions. -/
lemma cfcₙ_setIntegral [NormedSpace ℝ A] [TopologicalSpace X] [OpensMeasurableSpace X] {s : Set X}
(hs : MeasurableSet s) (f : X → 𝕜 → 𝕜) (bound : X → ℝ) (a : A)
[SecondCountableTopologyEither X C(quasispectrum 𝕜 a, 𝕜)]
(hf : ContinuousOn (uncurry f) (s ×ˢ quasispectrum 𝕜 a))
(f_zero : ∀ᵐ x ∂(μ.restrict s), f x 0 = 0)
(bound_ge : ∀ᵐ x ∂(μ.restrict s), ∀ z ∈ quasispectrum 𝕜 a, ‖f x z‖ ≤ bound x)
(bound_int : HasFiniteIntegral bound (μ.restrict s)) (ha : p a := by cfc_tac) :
cfcₙ (fun r => ∫ x in s, f x r ∂μ) a = ∫ x in s, cfcₙ (f x) a ∂μ := by
have : ∀ᵐ (x : X) ∂(μ.restrict s), ContinuousOn (f x) (quasispectrum 𝕜 a) :=
ae_restrict_of_forall_mem hs fun x hx ↦
hf.comp (Continuous.prodMk_right x).continuousOn fun _ hz ↦ ⟨hx, hz⟩
refine cfcₙ_setIntegral' _ _ this f_zero ⟨?_, ?_⟩ ha
· exact aeStronglyMeasurable_restrict_mkD_restrict_of_uncurry hs _ _ hf f_zero
· exact hasFiniteIntegral_mkD_restrict_of_bound f _ this f_zero bound bound_int bound_ge
end nonunital
|
Instances.lean
|
/-
Copyright (c) 2025 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.LocalRing.ResidueField.Ideal
import Mathlib.FieldTheory.Separable
/-! # Instances on residue fields -/
variable {R A B : Type*} [CommRing R] [CommRing A] [CommRing B] [Algebra R A] [Algebra A B]
[Algebra R B] [IsScalarTower R A B]
variable (p : Ideal A) [p.IsMaximal] (q : Ideal B) [q.IsMaximal] [q.LiesOver p]
attribute [local instance] Ideal.Quotient.field
instance [Algebra.IsSeparable (A ⧸ p) (B ⧸ q)] :
Algebra.IsSeparable p.ResidueField q.ResidueField := by
refine Algebra.IsSeparable.of_equiv_equiv
(.ofBijective _ p.bijective_algebraMap_quotient_residueField)
(.ofBijective _ q.bijective_algebraMap_quotient_residueField) ?_
ext x
simp [RingHom.algebraMap_toAlgebra, Algebra.ofId_apply]
instance [Algebra.IsSeparable p.ResidueField q.ResidueField] :
Algebra.IsSeparable (A ⧸ p) (B ⧸ q) := by
refine Algebra.IsSeparable.of_equiv_equiv
(.symm <| .ofBijective _ p.bijective_algebraMap_quotient_residueField)
(.symm <| .ofBijective _ q.bijective_algebraMap_quotient_residueField) ?_
ext x
obtain ⟨x, rfl⟩ :=
(RingEquiv.ofBijective _ p.bijective_algebraMap_quotient_residueField).surjective x
obtain ⟨x, rfl⟩ := Ideal.Quotient.mk_surjective x
apply (RingEquiv.ofBijective _ q.bijective_algebraMap_quotient_residueField).injective
simp only [RingHom.coe_comp, RingHom.coe_coe, Function.comp_apply, RingEquiv.symm_apply_apply,
RingEquiv.apply_symm_apply]
simp [RingHom.algebraMap_toAlgebra, Algebra.ofId_apply]
lemma Algebra.isSeparable_residueField_iff
{p : Ideal A} [p.IsMaximal] {q : Ideal B} [q.IsMaximal] [q.LiesOver p] :
Algebra.IsSeparable p.ResidueField q.ResidueField ↔ Algebra.IsSeparable (A ⧸ p) (B ⧸ q) :=
⟨fun _ ↦ inferInstance, fun _ ↦ inferInstance⟩
|
MaxPowDiv.lean
|
/-
Copyright (c) 2023 Matthew Robert Ballard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Matthew Robert Ballard
-/
import Mathlib.Algebra.Divisibility.Units
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Tactic.Common
/-!
# The maximal power of one natural number dividing another
Here we introduce `p.maxPowDiv n` which returns the maximal `k : ℕ` for
which `p ^ k ∣ n` with the convention that `maxPowDiv 1 n = 0` for all `n`.
We prove enough about `maxPowDiv` in this file to show equality with `Nat.padicValNat` in
`padicValNat.padicValNat_eq_maxPowDiv`.
The implementation of `maxPowDiv` improves on the speed of `padicValNat`.
-/
namespace Nat
/--
Tail recursive function which returns the largest `k : ℕ` such that `p ^ k ∣ n` for any `p : ℕ`.
`padicValNat_eq_maxPowDiv` allows the code generator to use this definition for `padicValNat`
-/
def maxPowDiv (p n : ℕ) : ℕ :=
go 0 p n
where go (k p n : ℕ) : ℕ :=
if 1 < p ∧ 0 < n ∧ n % p = 0 then
go (k+1) p (n / p)
else
k
termination_by n
decreasing_by apply Nat.div_lt_self <;> tauto
attribute [inherit_doc maxPowDiv] maxPowDiv.go
end Nat
namespace Nat.maxPowDiv
theorem go_succ {k p n : ℕ} : go (k+1) p n = go k p n + 1 := by
fun_induction go
case case1 h ih =>
conv_lhs => unfold go
simpa [if_pos h] using ih
case case2 h =>
conv_lhs => unfold go
simp [if_neg h]
@[simp]
theorem zero_base {n : ℕ} : maxPowDiv 0 n = 0 := by
dsimp [maxPowDiv]
rw [maxPowDiv.go]
simp
@[simp]
theorem zero {p : ℕ} : maxPowDiv p 0 = 0 := by
dsimp [maxPowDiv]
rw [maxPowDiv.go]
simp
theorem base_mul_eq_succ {p n : ℕ} (hp : 1 < p) (hn : 0 < n) :
p.maxPowDiv (p*n) = p.maxPowDiv n + 1 := by
have : 0 < p := lt_trans (b := 1) (by simp) hp
dsimp [maxPowDiv]
rw [maxPowDiv.go, if_pos, mul_div_right _ this]
· apply go_succ
· refine ⟨hp, ?_, by simp⟩
apply Nat.mul_pos this hn
theorem base_pow_mul {p n exp : ℕ} (hp : 1 < p) (hn : 0 < n) :
p.maxPowDiv (p ^ exp * n) = p.maxPowDiv n + exp := by
match exp with
| 0 => simp
| e + 1 =>
rw [Nat.pow_succ, mul_assoc, mul_comm, mul_assoc, base_mul_eq_succ hp, mul_comm,
base_pow_mul hp hn]
· ac_rfl
· apply Nat.mul_pos hn <| pow_pos (pos_of_gt hp) e
theorem pow_dvd (p n : ℕ) : p ^ (p.maxPowDiv n) ∣ n := by
dsimp [maxPowDiv]
rw [go]
by_cases h : (1 < p ∧ 0 < n ∧ n % p = 0)
· have : n / p < n := by apply Nat.div_lt_self <;> aesop
rw [if_pos h]
have ⟨c,hc⟩ := pow_dvd p (n / p)
rw [go_succ, pow_succ]
nth_rw 2 [← mod_add_div' n p]
rw [h.right.right, zero_add]
exact ⟨c,by nth_rw 1 [hc]; ac_rfl⟩
· rw [if_neg h]
simp
theorem le_of_dvd {p n pow : ℕ} (hp : 1 < p) (hn : n ≠ 0) (h : p ^ pow ∣ n) :
pow ≤ p.maxPowDiv n := by
have ⟨c, hc⟩ := h
have : 0 < c := by
apply Nat.pos_of_ne_zero
intro h'
rw [h',mul_zero] at hc
omega
simp [hc, base_pow_mul hp this]
end maxPowDiv
end Nat
|
Hom.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, Floris van Doorn, Amelia Livingston, Yury Kudryashov,
Neil Strickland, Aaron Anderson
-/
import Mathlib.Algebra.Divisibility.Basic
import Mathlib.Algebra.Group.Hom.Defs
/-!
# Mapping divisibility across multiplication-preserving homomorphisms
## Main definitions
* `map_dvd`
## Tags
divisibility, divides
-/
attribute [local simp] mul_assoc mul_comm mul_left_comm
variable {M N : Type*}
@[gcongr]
theorem map_dvd [Semigroup M] [Semigroup N] {F : Type*} [FunLike F M N] [MulHomClass F M N]
(f : F) {a b} : a ∣ b → f a ∣ f b
| ⟨c, h⟩ => ⟨f c, h.symm ▸ map_mul f a c⟩
theorem MulHom.map_dvd [Semigroup M] [Semigroup N] (f : M →ₙ* N) {a b} : a ∣ b → f a ∣ f b :=
_root_.map_dvd f
theorem MonoidHom.map_dvd [Monoid M] [Monoid N] (f : M →* N) {a b} : a ∣ b → f a ∣ f b :=
_root_.map_dvd f
|
Functors.lean
|
/-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.CategoryTheory.Sites.Coherent.CoherentSheaves
import Mathlib.Condensed.Light.Basic
/-!
# Functors from categories of topological spaces to light condensed sets
This file defines the embedding of the test objects (light profinite sets) into light condensed
sets.
## Main definitions
* `lightProfiniteToLightCondSet : LightProfinite.{u} ⥤ LightCondSet.{u}`
is the yoneda presheaf functor.
-/
universe u v
open CategoryTheory Limits
/-- The functor from `LightProfinite.{u}` to `LightCondSet.{u}` given by the Yoneda sheaf. -/
def lightProfiniteToLightCondSet : LightProfinite.{u} ⥤ LightCondSet.{u} :=
(coherentTopology LightProfinite).yoneda
/-- Dot notation for the value of `lightProfiniteToLightCondSet`. -/
abbrev LightProfinite.toCondensed (S : LightProfinite.{u}) : LightCondSet.{u} :=
lightProfiniteToLightCondSet.obj S
/-- `lightProfiniteToLightCondSet` is fully faithful. -/
abbrev lightProfiniteToLightCondSetFullyFaithful :
lightProfiniteToLightCondSet.FullyFaithful :=
(coherentTopology LightProfinite).yonedaFullyFaithful
instance : lightProfiniteToLightCondSet.Full :=
inferInstanceAs ((coherentTopology LightProfinite).yoneda).Full
instance : lightProfiniteToLightCondSet.Faithful :=
inferInstanceAs ((coherentTopology LightProfinite).yoneda).Faithful
|
Compact.lean
|
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Analysis.LocallyConvex.Bounded
import Mathlib.Topology.Algebra.Module.StrongTopology
/-!
# Compact operators
In this file we define compact linear operators between two topological vector spaces (TVS).
## Main definitions
* `IsCompactOperator` : predicate for compact operators
## Main statements
* `isCompactOperator_iff_isCompact_closure_image_ball` : the usual characterization of
compact operators from a normed space to a T2 TVS.
* `IsCompactOperator.comp_clm` : precomposing a compact operator by a continuous linear map gives
a compact operator
* `IsCompactOperator.clm_comp` : postcomposing a compact operator by a continuous linear map
gives a compact operator
* `IsCompactOperator.continuous` : compact operators are automatically continuous
* `isClosed_setOf_isCompactOperator` : the set of compact operators is closed for the operator
norm
## Implementation details
We define `IsCompactOperator` as a predicate, because the space of compact operators inherits all
of its structure from the space of continuous linear maps (e.g we want to have the usual operator
norm on compact operators).
The two natural options then would be to make it a predicate over linear maps or continuous linear
maps. Instead we define it as a predicate over bare functions, although it really only makes sense
for linear functions, because Lean is really good at finding coercions to bare functions (whereas
coercing from continuous linear maps to linear maps often needs type ascriptions).
## References
* [N. Bourbaki, *Théories Spectrales*, Chapitre 3][bourbaki2023]
## Tags
Compact operator
-/
open Function Set Filter Bornology Metric Pointwise Topology
/-- A compact operator between two topological vector spaces. This definition is usually
given as "there exists a neighborhood of zero whose image is contained in a compact set",
but we choose a definition which involves fewer existential quantifiers and replaces images
with preimages.
We prove the equivalence in `isCompactOperator_iff_exists_mem_nhds_image_subset_compact`. -/
def IsCompactOperator {M₁ M₂ : Type*} [Zero M₁] [TopologicalSpace M₁] [TopologicalSpace M₂]
(f : M₁ → M₂) : Prop :=
∃ K, IsCompact K ∧ f ⁻¹' K ∈ (𝓝 0 : Filter M₁)
theorem isCompactOperator_zero {M₁ M₂ : Type*} [Zero M₁] [TopologicalSpace M₁]
[TopologicalSpace M₂] [Zero M₂] : IsCompactOperator (0 : M₁ → M₂) :=
⟨{0}, isCompact_singleton, mem_of_superset univ_mem fun _ _ => rfl⟩
section Characterizations
section
variable {R₁ : Type*} [Semiring R₁] {M₁ M₂ : Type*}
[TopologicalSpace M₁] [AddCommMonoid M₁] [TopologicalSpace M₂]
theorem isCompactOperator_iff_exists_mem_nhds_image_subset_compact (f : M₁ → M₂) :
IsCompactOperator f ↔ ∃ V ∈ (𝓝 0 : Filter M₁), ∃ K : Set M₂, IsCompact K ∧ f '' V ⊆ K :=
⟨fun ⟨K, hK, hKf⟩ => ⟨f ⁻¹' K, hKf, K, hK, image_preimage_subset _ _⟩, fun ⟨_, hV, K, hK, hVK⟩ =>
⟨K, hK, mem_of_superset hV (image_subset_iff.mp hVK)⟩⟩
theorem isCompactOperator_iff_exists_mem_nhds_isCompact_closure_image [T2Space M₂] (f : M₁ → M₂) :
IsCompactOperator f ↔ ∃ V ∈ (𝓝 0 : Filter M₁), IsCompact (closure <| f '' V) := by
rw [isCompactOperator_iff_exists_mem_nhds_image_subset_compact]
exact
⟨fun ⟨V, hV, K, hK, hKV⟩ => ⟨V, hV, hK.closure_of_subset hKV⟩,
fun ⟨V, hV, hVc⟩ => ⟨V, hV, closure (f '' V), hVc, subset_closure⟩⟩
end
section Bounded
variable {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁] [SeminormedRing 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂}
{M₁ M₂ : Type*} [TopologicalSpace M₁] [AddCommMonoid M₁] [TopologicalSpace M₂] [AddCommMonoid M₂]
[Module 𝕜₁ M₁] [Module 𝕜₂ M₂] [ContinuousConstSMul 𝕜₂ M₂]
theorem IsCompactOperator.image_subset_compact_of_isVonNBounded {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : IsCompactOperator f) {S : Set M₁} (hS : IsVonNBounded 𝕜₁ S) :
∃ K : Set M₂, IsCompact K ∧ f '' S ⊆ K :=
let ⟨K, hK, hKf⟩ := hf
let ⟨r, hr, hrS⟩ := (hS hKf).exists_pos
let ⟨c, hc⟩ := NormedField.exists_lt_norm 𝕜₁ r
let this := ne_zero_of_norm_ne_zero (hr.trans hc).ne.symm
⟨σ₁₂ c • K, hK.image <| continuous_id.const_smul (σ₁₂ c), by
rw [image_subset_iff, this.isUnit.preimage_smul_setₛₗ σ₁₂]; exact hrS c hc.le⟩
theorem IsCompactOperator.isCompact_closure_image_of_isVonNBounded [T2Space M₂] {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : IsCompactOperator f) {S : Set M₁} (hS : IsVonNBounded 𝕜₁ S) :
IsCompact (closure <| f '' S) :=
let ⟨_, hK, hKf⟩ := hf.image_subset_compact_of_isVonNBounded hS
hK.closure_of_subset hKf
end Bounded
section NormedSpace
variable {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁] [SeminormedRing 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂}
{M₁ M₂ : Type*} [SeminormedAddCommGroup M₁] [TopologicalSpace M₂] [AddCommMonoid M₂]
[NormedSpace 𝕜₁ M₁] [Module 𝕜₂ M₂]
theorem IsCompactOperator.image_subset_compact_of_bounded [ContinuousConstSMul 𝕜₂ M₂]
{f : M₁ →ₛₗ[σ₁₂] M₂} (hf : IsCompactOperator f) {S : Set M₁} (hS : Bornology.IsBounded S) :
∃ K : Set M₂, IsCompact K ∧ f '' S ⊆ K :=
hf.image_subset_compact_of_isVonNBounded <| by rwa [NormedSpace.isVonNBounded_iff]
theorem IsCompactOperator.isCompact_closure_image_of_bounded [ContinuousConstSMul 𝕜₂ M₂]
[T2Space M₂] {f : M₁ →ₛₗ[σ₁₂] M₂} (hf : IsCompactOperator f) {S : Set M₁}
(hS : Bornology.IsBounded S) : IsCompact (closure <| f '' S) :=
hf.isCompact_closure_image_of_isVonNBounded <| by rwa [NormedSpace.isVonNBounded_iff]
theorem IsCompactOperator.image_ball_subset_compact [ContinuousConstSMul 𝕜₂ M₂] {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : IsCompactOperator f) (r : ℝ) : ∃ K : Set M₂, IsCompact K ∧ f '' Metric.ball 0 r ⊆ K :=
hf.image_subset_compact_of_isVonNBounded (NormedSpace.isVonNBounded_ball 𝕜₁ M₁ r)
theorem IsCompactOperator.image_closedBall_subset_compact [ContinuousConstSMul 𝕜₂ M₂]
{f : M₁ →ₛₗ[σ₁₂] M₂} (hf : IsCompactOperator f) (r : ℝ) :
∃ K : Set M₂, IsCompact K ∧ f '' Metric.closedBall 0 r ⊆ K :=
hf.image_subset_compact_of_isVonNBounded (NormedSpace.isVonNBounded_closedBall 𝕜₁ M₁ r)
theorem IsCompactOperator.isCompact_closure_image_ball [ContinuousConstSMul 𝕜₂ M₂] [T2Space M₂]
{f : M₁ →ₛₗ[σ₁₂] M₂} (hf : IsCompactOperator f) (r : ℝ) :
IsCompact (closure <| f '' Metric.ball 0 r) :=
hf.isCompact_closure_image_of_isVonNBounded (NormedSpace.isVonNBounded_ball 𝕜₁ M₁ r)
theorem IsCompactOperator.isCompact_closure_image_closedBall [ContinuousConstSMul 𝕜₂ M₂]
[T2Space M₂] {f : M₁ →ₛₗ[σ₁₂] M₂} (hf : IsCompactOperator f) (r : ℝ) :
IsCompact (closure <| f '' Metric.closedBall 0 r) :=
hf.isCompact_closure_image_of_isVonNBounded (NormedSpace.isVonNBounded_closedBall 𝕜₁ M₁ r)
theorem isCompactOperator_iff_image_ball_subset_compact [ContinuousConstSMul 𝕜₂ M₂]
(f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
IsCompactOperator f ↔ ∃ K : Set M₂, IsCompact K ∧ f '' Metric.ball 0 r ⊆ K :=
⟨fun hf => hf.image_ball_subset_compact r, fun ⟨K, hK, hKr⟩ =>
(isCompactOperator_iff_exists_mem_nhds_image_subset_compact f).mpr
⟨Metric.ball 0 r, ball_mem_nhds _ hr, K, hK, hKr⟩⟩
theorem isCompactOperator_iff_image_closedBall_subset_compact [ContinuousConstSMul 𝕜₂ M₂]
(f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
IsCompactOperator f ↔ ∃ K : Set M₂, IsCompact K ∧ f '' Metric.closedBall 0 r ⊆ K :=
⟨fun hf => hf.image_closedBall_subset_compact r, fun ⟨K, hK, hKr⟩ =>
(isCompactOperator_iff_exists_mem_nhds_image_subset_compact f).mpr
⟨Metric.closedBall 0 r, closedBall_mem_nhds _ hr, K, hK, hKr⟩⟩
theorem isCompactOperator_iff_isCompact_closure_image_ball [ContinuousConstSMul 𝕜₂ M₂] [T2Space M₂]
(f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
IsCompactOperator f ↔ IsCompact (closure <| f '' Metric.ball 0 r) :=
⟨fun hf => hf.isCompact_closure_image_ball r, fun hf =>
(isCompactOperator_iff_exists_mem_nhds_isCompact_closure_image f).mpr
⟨Metric.ball 0 r, ball_mem_nhds _ hr, hf⟩⟩
theorem isCompactOperator_iff_isCompact_closure_image_closedBall [ContinuousConstSMul 𝕜₂ M₂]
[T2Space M₂] (f : M₁ →ₛₗ[σ₁₂] M₂) {r : ℝ} (hr : 0 < r) :
IsCompactOperator f ↔ IsCompact (closure <| f '' Metric.closedBall 0 r) :=
⟨fun hf => hf.isCompact_closure_image_closedBall r, fun hf =>
(isCompactOperator_iff_exists_mem_nhds_isCompact_closure_image f).mpr
⟨Metric.closedBall 0 r, closedBall_mem_nhds _ hr, hf⟩⟩
end NormedSpace
end Characterizations
section Operations
variable {R₁ R₄ : Type*} [Semiring R₁] [CommSemiring R₄]
{σ₁₄ : R₁ →+* R₄} {M₁ M₂ M₄ : Type*} [TopologicalSpace M₁]
[AddCommMonoid M₁] [TopologicalSpace M₂] [AddCommMonoid M₂]
[TopologicalSpace M₄] [AddCommGroup M₄]
theorem IsCompactOperator.smul {S : Type*} [Monoid S] [DistribMulAction S M₂]
[ContinuousConstSMul S M₂] {f : M₁ → M₂} (hf : IsCompactOperator f) (c : S) :
IsCompactOperator (c • f) :=
let ⟨K, hK, hKf⟩ := hf
⟨c • K, hK.image <| continuous_id.const_smul c,
mem_of_superset hKf fun _ hx => smul_mem_smul_set hx⟩
theorem IsCompactOperator.add [ContinuousAdd M₂] {f g : M₁ → M₂} (hf : IsCompactOperator f)
(hg : IsCompactOperator g) : IsCompactOperator (f + g) :=
let ⟨A, hA, hAf⟩ := hf
let ⟨B, hB, hBg⟩ := hg
⟨A + B, hA.add hB,
mem_of_superset (inter_mem hAf hBg) fun _ ⟨hxA, hxB⟩ => Set.add_mem_add hxA hxB⟩
theorem IsCompactOperator.neg [ContinuousNeg M₄] {f : M₁ → M₄} (hf : IsCompactOperator f) :
IsCompactOperator (-f) :=
let ⟨K, hK, hKf⟩ := hf
⟨-K, hK.neg, mem_of_superset hKf fun x (hx : f x ∈ K) => Set.neg_mem_neg.mpr hx⟩
theorem IsCompactOperator.sub [IsTopologicalAddGroup M₄] {f g : M₁ → M₄} (hf : IsCompactOperator f)
(hg : IsCompactOperator g) : IsCompactOperator (f - g) := by
rw [sub_eq_add_neg]; exact hf.add hg.neg
variable (σ₁₄ M₁ M₄)
/-- The submodule of compact continuous linear maps. -/
def compactOperator [Module R₁ M₁] [Module R₄ M₄] [ContinuousConstSMul R₄ M₄]
[IsTopologicalAddGroup M₄] : Submodule R₄ (M₁ →SL[σ₁₄] M₄) where
carrier := { f | IsCompactOperator f }
add_mem' hf hg := hf.add hg
zero_mem' := isCompactOperator_zero
smul_mem' c _ hf := hf.smul c
end Operations
section Comp
variable {R₁ R₂ R₃ : Type*} [Semiring R₁] [Semiring R₂] [Semiring R₃] {σ₁₂ : R₁ →+* R₂}
{σ₂₃ : R₂ →+* R₃} {M₁ M₂ M₃ : Type*} [TopologicalSpace M₁] [TopologicalSpace M₂]
[TopologicalSpace M₃] [AddCommMonoid M₁] [Module R₁ M₁]
theorem IsCompactOperator.comp_clm [AddCommMonoid M₂] [Module R₂ M₂] {f : M₂ → M₃}
(hf : IsCompactOperator f) (g : M₁ →SL[σ₁₂] M₂) : IsCompactOperator (f ∘ g) := by
have := g.continuous.tendsto 0
rw [map_zero] at this
rcases hf with ⟨K, hK, hKf⟩
exact ⟨K, hK, this hKf⟩
theorem IsCompactOperator.continuous_comp {f : M₁ → M₂} (hf : IsCompactOperator f) {g : M₂ → M₃}
(hg : Continuous g) : IsCompactOperator (g ∘ f) := by
rcases hf with ⟨K, hK, hKf⟩
refine ⟨g '' K, hK.image hg, mem_of_superset hKf ?_⟩
rw [preimage_comp]
exact preimage_mono (subset_preimage_image _ _)
theorem IsCompactOperator.clm_comp [AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid M₃]
[Module R₃ M₃] {f : M₁ → M₂} (hf : IsCompactOperator f) (g : M₂ →SL[σ₂₃] M₃) :
IsCompactOperator (g ∘ f) :=
hf.continuous_comp g.continuous
end Comp
section CodRestrict
variable {R₂ : Type*} [Semiring R₂] {M₁ M₂ : Type*}
[TopologicalSpace M₁] [TopologicalSpace M₂] [AddCommMonoid M₁] [AddCommMonoid M₂]
[Module R₂ M₂]
theorem IsCompactOperator.codRestrict {f : M₁ → M₂} (hf : IsCompactOperator f) {V : Submodule R₂ M₂}
(hV : ∀ x, f x ∈ V) (h_closed : IsClosed (V : Set M₂)) :
IsCompactOperator (Set.codRestrict f V hV) :=
let ⟨_, hK, hKf⟩ := hf
⟨_, h_closed.isClosedEmbedding_subtypeVal.isCompact_preimage hK, hKf⟩
end CodRestrict
section Restrict
variable {R₁ R₂ : Type*} [Semiring R₁] [Semiring R₂] {σ₁₂ : R₁ →+* R₂}
{M₁ M₂ : Type*} [TopologicalSpace M₁] [UniformSpace M₂]
[AddCommMonoid M₁] [AddCommMonoid M₂] [Module R₁ M₁]
[Module R₂ M₂]
/-- If a compact operator preserves a closed submodule, its restriction to that submodule is
compact.
Note that, following mathlib's convention in linear algebra, `restrict` designates the restriction
of an endomorphism `f : E →ₗ E` to an endomorphism `f' : ↥V →ₗ ↥V`. To prove that the restriction
`f' : ↥U →ₛₗ ↥V` of a compact operator `f : E →ₛₗ F` is compact, apply
`IsCompactOperator.codRestrict` to `f ∘ U.subtypeL`, which is compact by
`IsCompactOperator.comp_clm`. -/
theorem IsCompactOperator.restrict {f : M₁ →ₗ[R₁] M₁} (hf : IsCompactOperator f)
{V : Submodule R₁ M₁} (hV : ∀ v ∈ V, f v ∈ V) (h_closed : IsClosed (V : Set M₁)) :
IsCompactOperator (f.restrict hV) :=
(hf.comp_clm V.subtypeL).codRestrict (SetLike.forall.2 hV) h_closed
/-- If a compact operator preserves a complete submodule, its restriction to that submodule is
compact.
Note that, following mathlib's convention in linear algebra, `restrict` designates the restriction
of an endomorphism `f : E →ₗ E` to an endomorphism `f' : ↥V →ₗ ↥V`. To prove that the restriction
`f' : ↥U →ₛₗ ↥V` of a compact operator `f : E →ₛₗ F` is compact, apply
`IsCompactOperator.codRestrict` to `f ∘ U.subtypeL`, which is compact by
`IsCompactOperator.comp_clm`. -/
theorem IsCompactOperator.restrict' [T0Space M₂] {f : M₂ →ₗ[R₂] M₂}
(hf : IsCompactOperator f) {V : Submodule R₂ M₂} (hV : ∀ v ∈ V, f v ∈ V)
[hcomplete : CompleteSpace V] : IsCompactOperator (f.restrict hV) :=
hf.restrict hV (completeSpace_coe_iff_isComplete.mp hcomplete).isClosed
end Restrict
section Continuous
variable {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁] [NontriviallyNormedField 𝕜₂]
{σ₁₂ : 𝕜₁ →+* 𝕜₂} [RingHomIsometric σ₁₂] {M₁ M₂ : Type*} [TopologicalSpace M₁] [AddCommGroup M₁]
[TopologicalSpace M₂] [AddCommGroup M₂] [Module 𝕜₁ M₁] [Module 𝕜₂ M₂] [IsTopologicalAddGroup M₁]
[ContinuousConstSMul 𝕜₁ M₁] [IsTopologicalAddGroup M₂] [ContinuousSMul 𝕜₂ M₂]
@[continuity]
theorem IsCompactOperator.continuous {f : M₁ →ₛₗ[σ₁₂] M₂} (hf : IsCompactOperator f) :
Continuous f := by
letI : UniformSpace M₂ := IsTopologicalAddGroup.toUniformSpace _
haveI : IsUniformAddGroup M₂ := isUniformAddGroup_of_addCommGroup
-- Since `f` is linear, we only need to show that it is continuous at zero.
-- Let `U` be a neighborhood of `0` in `M₂`.
refine continuous_of_continuousAt_zero f fun U hU => ?_
rw [map_zero] at hU
-- The compactness of `f` gives us a compact set `K : Set M₂` such that `f ⁻¹' K` is a
-- neighborhood of `0` in `M₁`.
rcases hf with ⟨K, hK, hKf⟩
-- But any compact set is totally bounded, hence Von-Neumann bounded. Thus, `K` absorbs `U`.
-- This gives `r > 0` such that `∀ a : 𝕜₂, r ≤ ‖a‖ → K ⊆ a • U`.
rcases (hK.totallyBounded.isVonNBounded 𝕜₂ hU).exists_pos with ⟨r, hr, hrU⟩
-- Choose `c : 𝕜₂` with `r < ‖c‖`.
rcases NormedField.exists_lt_norm 𝕜₁ r with ⟨c, hc⟩
have hcnz : c ≠ 0 := ne_zero_of_norm_ne_zero (hr.trans hc).ne.symm
-- We have `f ⁻¹' ((σ₁₂ c⁻¹) • K) = c⁻¹ • f ⁻¹' K ∈ 𝓝 0`. Thus, showing that
-- `(σ₁₂ c⁻¹) • K ⊆ U` is enough to deduce that `f ⁻¹' U ∈ 𝓝 0`.
suffices (σ₁₂ <| c⁻¹) • K ⊆ U by
refine mem_of_superset ?_ this
have : IsUnit c⁻¹ := hcnz.isUnit.inv
rwa [mem_map, this.preimage_smul_setₛₗ σ₁₂, set_smul_mem_nhds_zero_iff (inv_ne_zero hcnz)]
-- Since `σ₁₂ c⁻¹` = `(σ₁₂ c)⁻¹`, we have to prove that `K ⊆ σ₁₂ c • U`.
rw [map_inv₀, ← subset_smul_set_iff₀ ((map_ne_zero σ₁₂).mpr hcnz)]
-- But `σ₁₂` is isometric, so `‖σ₁₂ c‖ = ‖c‖ > r`, which concludes the argument since
-- `∀ a : 𝕜₂, r ≤ ‖a‖ → K ⊆ a • U`.
refine hrU (σ₁₂ c) ?_
rw [RingHomIsometric.norm_map]
exact hc.le
/-- Upgrade a compact `LinearMap` to a `ContinuousLinearMap`. -/
def ContinuousLinearMap.mkOfIsCompactOperator {f : M₁ →ₛₗ[σ₁₂] M₂} (hf : IsCompactOperator f) :
M₁ →SL[σ₁₂] M₂ :=
⟨f, hf.continuous⟩
@[simp]
theorem ContinuousLinearMap.mkOfIsCompactOperator_to_linearMap {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : IsCompactOperator f) :
(ContinuousLinearMap.mkOfIsCompactOperator hf : M₁ →ₛₗ[σ₁₂] M₂) = f :=
rfl
@[simp]
theorem ContinuousLinearMap.coe_mkOfIsCompactOperator {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : IsCompactOperator f) : (ContinuousLinearMap.mkOfIsCompactOperator hf : M₁ → M₂) = f :=
rfl
theorem ContinuousLinearMap.mkOfIsCompactOperator_mem_compactOperator {f : M₁ →ₛₗ[σ₁₂] M₂}
(hf : IsCompactOperator f) :
ContinuousLinearMap.mkOfIsCompactOperator hf ∈ compactOperator σ₁₂ M₁ M₂ :=
hf
end Continuous
/-- The set of compact operators from a normed space to a complete topological vector space is
closed. -/
theorem isClosed_setOf_isCompactOperator {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁]
[NormedField 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂} {M₁ M₂ : Type*} [SeminormedAddCommGroup M₁]
[AddCommGroup M₂] [NormedSpace 𝕜₁ M₁] [Module 𝕜₂ M₂] [UniformSpace M₂] [IsUniformAddGroup M₂]
[ContinuousConstSMul 𝕜₂ M₂] [T2Space M₂] [CompleteSpace M₂] :
IsClosed { f : M₁ →SL[σ₁₂] M₂ | IsCompactOperator f } := by
refine isClosed_of_closure_subset ?_
rintro u hu
rw [mem_closure_iff_nhds_zero] at hu
suffices TotallyBounded (u '' Metric.closedBall 0 1) by
change IsCompactOperator (u : M₁ →ₛₗ[σ₁₂] M₂)
rw [isCompactOperator_iff_isCompact_closure_image_closedBall (u : M₁ →ₛₗ[σ₁₂] M₂) zero_lt_one]
exact isCompact_of_totallyBounded_isClosed this.closure isClosed_closure
rw [totallyBounded_iff_subset_finite_iUnion_nhds_zero]
intro U hU
rcases exists_nhds_zero_half hU with ⟨V, hV, hVU⟩
let SV : Set M₁ × Set M₂ := ⟨closedBall 0 1, -V⟩
rcases hu { f | ∀ x ∈ SV.1, f x ∈ SV.2 }
(ContinuousLinearMap.hasBasis_nhds_zero.mem_of_mem
⟨NormedSpace.isVonNBounded_closedBall _ _ _, neg_mem_nhds_zero M₂ hV⟩) with
⟨v, hv, huv⟩
rcases totallyBounded_iff_subset_finite_iUnion_nhds_zero.mp
(hv.isCompact_closure_image_closedBall 1).totallyBounded V hV with
⟨T, hT, hTv⟩
have hTv : v '' closedBall 0 1 ⊆ _ := subset_closure.trans hTv
refine ⟨T, hT, ?_⟩
rw [image_subset_iff, preimage_iUnion₂] at hTv ⊢
intro x hx
specialize hTv hx
rw [mem_iUnion₂] at hTv ⊢
rcases hTv with ⟨t, ht, htx⟩
refine ⟨t, ht, ?_⟩
rw [mem_preimage, mem_vadd_set_iff_neg_vadd_mem, vadd_eq_add, neg_add_eq_sub] at htx ⊢
convert hVU _ htx _ (huv x hx) using 1
rw [ContinuousLinearMap.sub_apply]
abel
theorem compactOperator_topologicalClosure {𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁]
[NormedField 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂} {M₁ M₂ : Type*} [SeminormedAddCommGroup M₁]
[AddCommGroup M₂] [NormedSpace 𝕜₁ M₁] [Module 𝕜₂ M₂] [UniformSpace M₂] [IsUniformAddGroup M₂]
[ContinuousConstSMul 𝕜₂ M₂] [T2Space M₂] [CompleteSpace M₂] :
(compactOperator σ₁₂ M₁ M₂).topologicalClosure = compactOperator σ₁₂ M₁ M₂ :=
SetLike.ext' isClosed_setOf_isCompactOperator.closure_eq
theorem isCompactOperator_of_tendsto {ι 𝕜₁ 𝕜₂ : Type*} [NontriviallyNormedField 𝕜₁]
[NormedField 𝕜₂] {σ₁₂ : 𝕜₁ →+* 𝕜₂} {M₁ M₂ : Type*} [SeminormedAddCommGroup M₁]
[AddCommGroup M₂] [NormedSpace 𝕜₁ M₁] [Module 𝕜₂ M₂] [UniformSpace M₂] [IsUniformAddGroup M₂]
[ContinuousConstSMul 𝕜₂ M₂] [T2Space M₂] [CompleteSpace M₂] {l : Filter ι} [l.NeBot]
{F : ι → M₁ →SL[σ₁₂] M₂} {f : M₁ →SL[σ₁₂] M₂} (hf : Tendsto F l (𝓝 f))
(hF : ∀ᶠ i in l, IsCompactOperator (F i)) : IsCompactOperator f :=
isClosed_setOf_isCompactOperator.mem_of_tendsto hf hF
|
PFilter.lean
|
/-
Copyright (c) 2020 Mathieu Guay-Paquet. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mathieu Guay-Paquet
-/
import Mathlib.Order.Ideal
/-!
# Order filters
## Main definitions
Throughout this file, `P` is at least a preorder, but some sections require more structure,
such as a bottom element, a top element, or a join-semilattice structure.
- `Order.PFilter P`: The type of nonempty, downward directed, upward closed subsets of `P`.
This is dual to `Order.Ideal`, so it simply wraps `Order.Ideal Pᵒᵈ`.
- `Order.IsPFilter P`: a predicate for when a `Set P` is a filter.
Note the relation between `Order/Filter` and `Order/PFilter`: for any type `α`,
`Filter α` represents the same mathematical object as `PFilter (Set α)`.
## References
- <https://en.wikipedia.org/wiki/Filter_(mathematics)>
## Tags
pfilter, filter, ideal, dual
-/
open OrderDual
namespace Order
/-- A filter on a preorder `P` is a subset of `P` that is
- nonempty
- downward directed
- upward closed. -/
structure PFilter (P : Type*) [Preorder P] where
dual : Ideal Pᵒᵈ
variable {P : Type*}
/-- A predicate for when a subset of `P` is a filter. -/
def IsPFilter [Preorder P] (F : Set P) : Prop :=
IsIdeal (OrderDual.ofDual ⁻¹' F)
theorem IsPFilter.of_def [Preorder P] {F : Set P} (nonempty : F.Nonempty)
(directed : DirectedOn (· ≥ ·) F) (mem_of_le : ∀ {x y : P}, x ≤ y → x ∈ F → y ∈ F) :
IsPFilter F :=
⟨fun _ _ _ _ => mem_of_le ‹_› ‹_›, nonempty, directed⟩
/-- Create an element of type `Order.PFilter` from a set satisfying the predicate
`Order.IsPFilter`. -/
def IsPFilter.toPFilter [Preorder P] {F : Set P} (h : IsPFilter F) : PFilter P :=
⟨h.toIdeal⟩
namespace PFilter
section Preorder
variable [Preorder P] {x y : P} (F s t : PFilter P)
instance [Inhabited P] : Inhabited (PFilter P) := ⟨⟨default⟩⟩
/-- A filter on `P` is a subset of `P`. -/
instance : SetLike (PFilter P) P where
coe F := toDual ⁻¹' F.dual.carrier
coe_injective' := fun ⟨_⟩ ⟨_⟩ h => congr_arg mk <| Ideal.ext h
theorem isPFilter : IsPFilter (F : Set P) := F.dual.isIdeal
protected theorem nonempty : (F : Set P).Nonempty := F.dual.nonempty
theorem directed : DirectedOn (· ≥ ·) (F : Set P) := F.dual.directed
theorem mem_of_le {F : PFilter P} : x ≤ y → x ∈ F → y ∈ F := fun h => F.dual.lower h
/-- Two filters are equal when their underlying sets are equal. -/
@[ext]
theorem ext (h : (s : Set P) = t) : s = t := SetLike.ext' h
@[trans]
theorem mem_of_mem_of_le {F G : PFilter P} (hx : x ∈ F) (hle : F ≤ G) : x ∈ G :=
hle hx
/-- The smallest filter containing a given element. -/
def principal (p : P) : PFilter P :=
⟨Ideal.principal (toDual p)⟩
@[simp]
theorem mem_mk (x : P) (I : Ideal Pᵒᵈ) : x ∈ (⟨I⟩ : PFilter P) ↔ toDual x ∈ I :=
Iff.rfl
@[simp]
theorem principal_le_iff {F : PFilter P} : principal x ≤ F ↔ x ∈ F :=
Ideal.principal_le_iff (x := toDual x)
@[simp] theorem mem_principal : x ∈ principal y ↔ y ≤ x := Iff.rfl
theorem principal_le_principal_iff {p q : P} : principal q ≤ principal p ↔ p ≤ q := by simp
-- defeq abuse
theorem antitone_principal : Antitone (principal : P → PFilter P) := fun _ _ =>
principal_le_principal_iff.2
end Preorder
section OrderTop
variable [Preorder P] [OrderTop P] {F : PFilter P}
/-- A specific witness of `pfilter.nonempty` when `P` has a top element. -/
@[simp] theorem top_mem : ⊤ ∈ F := Ideal.bot_mem _
/-- There is a bottom filter when `P` has a top element. -/
instance : OrderBot (PFilter P) where
bot := ⟨⊥⟩
bot_le F := (bot_le : ⊥ ≤ F.dual)
end OrderTop
/-- There is a top filter when `P` has a bottom element. -/
instance {P} [Preorder P] [OrderBot P] : OrderTop (PFilter P) where
top := ⟨⊤⟩
le_top F := (le_top : F.dual ≤ ⊤)
section SemilatticeInf
variable [SemilatticeInf P] {x y : P} {F : PFilter P}
/-- A specific witness of `pfilter.directed` when `P` has meets. -/
theorem inf_mem (hx : x ∈ F) (hy : y ∈ F) : x ⊓ y ∈ F :=
Ideal.sup_mem hx hy
@[simp]
theorem inf_mem_iff : x ⊓ y ∈ F ↔ x ∈ F ∧ y ∈ F :=
Ideal.sup_mem_iff
end SemilatticeInf
section CompleteSemilatticeInf
variable [CompleteSemilatticeInf P]
theorem sInf_gc :
GaloisConnection (fun x => toDual (principal x)) fun F => sInf (ofDual F : PFilter P) :=
fun x F => by simp only [le_sInf_iff, SetLike.mem_coe, toDual_le, SetLike.le_def, mem_principal]
/-- If a poset `P` admits arbitrary `Inf`s, then `principal` and `Inf` form a Galois coinsertion. -/
def infGi :
GaloisCoinsertion (fun x => toDual (principal x)) fun F => sInf (ofDual F : PFilter P) :=
sInf_gc.toGaloisCoinsertion fun _ => sInf_le <| mem_principal.2 le_rfl
end CompleteSemilatticeInf
end PFilter
end Order
|
ProperSpace.lean
|
/-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.MetricSpace.Pseudo.Basic
import Mathlib.Topology.MetricSpace.Pseudo.Lemmas
import Mathlib.Topology.MetricSpace.Pseudo.Pi
import Mathlib.Topology.Order.IsLUB
/-! ## Proper spaces
## Main definitions and results
* `ProperSpace α`: a `PseudoMetricSpace` where all closed balls are compact
* `isCompact_sphere`: any sphere in a proper space is compact.
* `proper_of_compact`: compact spaces are proper.
* `secondCountable_of_proper`: proper spaces are sigma-compact, hence second countable.
* `locallyCompact_of_proper`: proper spaces are locally compact.
* `pi_properSpace`: finite products of proper spaces are proper.
-/
open Set Filter
universe u v w
variable {α : Type u} {β : Type v} {X ι : Type*}
section ProperSpace
open Metric
/-- A pseudometric space is proper if all closed balls are compact. -/
class ProperSpace (α : Type u) [PseudoMetricSpace α] : Prop where
isCompact_closedBall : ∀ x : α, ∀ r, IsCompact (closedBall x r)
export ProperSpace (isCompact_closedBall)
/-- In a proper pseudometric space, all spheres are compact. -/
theorem isCompact_sphere {α : Type*} [PseudoMetricSpace α] [ProperSpace α] (x : α) (r : ℝ) :
IsCompact (sphere x r) :=
(isCompact_closedBall x r).of_isClosed_subset isClosed_sphere sphere_subset_closedBall
/-- In a proper pseudometric space, any sphere is a `CompactSpace` when considered as a subtype. -/
instance Metric.sphere.compactSpace {α : Type*} [PseudoMetricSpace α] [ProperSpace α]
(x : α) (r : ℝ) : CompactSpace (sphere x r) :=
isCompact_iff_compactSpace.mp (isCompact_sphere _ _)
variable [PseudoMetricSpace α]
-- see Note [lower instance priority]
/-- A proper pseudo metric space is sigma compact, and therefore second countable. -/
instance (priority := 100) secondCountable_of_proper [ProperSpace α] :
SecondCountableTopology α := by
-- We already have `sigmaCompactSpace_of_locallyCompact_secondCountable`, so we don't
-- add an instance for `SigmaCompactSpace`.
suffices SigmaCompactSpace α from EMetric.secondCountable_of_sigmaCompact α
rcases em (Nonempty α) with (⟨⟨x⟩⟩ | hn)
· exact ⟨⟨fun n => closedBall x n, fun n => isCompact_closedBall _ _, iUnion_closedBall_nat _⟩⟩
· exact ⟨⟨fun _ => ∅, fun _ => isCompact_empty, iUnion_eq_univ_iff.2 fun x => (hn ⟨x⟩).elim⟩⟩
/-- If all closed balls of large enough radius are compact, then the space is proper. Especially
useful when the lower bound for the radius is 0. -/
theorem ProperSpace.of_isCompact_closedBall_of_le (R : ℝ)
(h : ∀ x : α, ∀ r, R ≤ r → IsCompact (closedBall x r)) : ProperSpace α :=
⟨fun x r => IsCompact.of_isClosed_subset (h x (max r R) (le_max_right _ _)) isClosed_closedBall
(closedBall_subset_closedBall <| le_max_left _ _)⟩
/-- If there exists a sequence of compact closed balls with the same center
such that the radii tend to infinity, then the space is proper. -/
theorem ProperSpace.of_seq_closedBall {β : Type*} {l : Filter β} [NeBot l] {x : α} {r : β → ℝ}
(hr : Tendsto r l atTop) (hc : ∀ᶠ i in l, IsCompact (closedBall x (r i))) :
ProperSpace α where
isCompact_closedBall a r :=
let ⟨_i, hci, hir⟩ := (hc.and <| hr.eventually_ge_atTop <| r + dist a x).exists
hci.of_isClosed_subset isClosed_closedBall <| closedBall_subset_closedBall' hir
-- A compact pseudometric space is proper
-- see Note [lower instance priority]
instance (priority := 100) proper_of_compact [CompactSpace α] : ProperSpace α :=
⟨fun _ _ => isClosed_closedBall.isCompact⟩
-- see Note [lower instance priority]
/-- A proper space is locally compact -/
instance (priority := 100) locallyCompact_of_proper [ProperSpace α] : LocallyCompactSpace α :=
.of_hasBasis (fun _ => nhds_basis_closedBall) fun _ _ _ =>
isCompact_closedBall _ _
-- see Note [lower instance priority]
/-- A proper space is complete -/
instance (priority := 100) complete_of_proper [ProperSpace α] : CompleteSpace α :=
⟨fun {f} hf => by
/- We want to show that the Cauchy filter `f` is converging. It suffices to find a closed
ball (therefore compact by properness) where it is nontrivial. -/
obtain ⟨t, t_fset, ht⟩ : ∃ t ∈ f, ∀ x ∈ t, ∀ y ∈ t, dist x y < 1 :=
(Metric.cauchy_iff.1 hf).2 1 zero_lt_one
rcases hf.1.nonempty_of_mem t_fset with ⟨x, xt⟩
have : closedBall x 1 ∈ f := mem_of_superset t_fset fun y yt => (ht y yt x xt).le
rcases (isCompact_iff_totallyBounded_isComplete.1 (isCompact_closedBall x 1)).2 f hf
(le_principal_iff.2 this) with
⟨y, -, hy⟩
exact ⟨y, hy⟩⟩
/-- A binary product of proper spaces is proper. -/
instance prod_properSpace {α : Type*} {β : Type*} [PseudoMetricSpace α] [PseudoMetricSpace β]
[ProperSpace α] [ProperSpace β] : ProperSpace (α × β) where
isCompact_closedBall := by
rintro ⟨x, y⟩ r
rw [← closedBall_prod_same x y]
exact (isCompact_closedBall x r).prod (isCompact_closedBall y r)
/-- A finite product of proper spaces is proper. -/
instance pi_properSpace {X : β → Type*} [Fintype β] [∀ b, PseudoMetricSpace (X b)]
[h : ∀ b, ProperSpace (X b)] : ProperSpace (∀ b, X b) := by
refine .of_isCompact_closedBall_of_le 0 fun x r hr => ?_
rw [closedBall_pi _ hr]
exact isCompact_univ_pi fun _ => isCompact_closedBall _ _
/-- A closed subspace of a proper space is proper.
This is true for any proper lipschitz map. See `LipschitzWith.properSpace`. -/
lemma ProperSpace.of_isClosed {X : Type*} [PseudoMetricSpace X] [ProperSpace X]
{s : Set X} (hs : IsClosed s) :
ProperSpace s :=
⟨fun x r ↦ Topology.IsEmbedding.subtypeVal.isCompact_iff.mpr
((isCompact_closedBall x.1 r).of_isClosed_subset
(hs.isClosedMap_subtype_val _ isClosed_closedBall) (Set.image_subset_iff.mpr subset_rfl))⟩
end ProperSpace
instance [PseudoMetricSpace X] [ProperSpace X] : ProperSpace (Additive X) := ‹ProperSpace X›
instance [PseudoMetricSpace X] [ProperSpace X] : ProperSpace (Multiplicative X) := ‹ProperSpace X›
instance [PseudoMetricSpace X] [ProperSpace X] : ProperSpace Xᵒᵈ := ‹ProperSpace X›
|
HomogeneousLocalization.lean
|
/-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Eric Wieser
-/
import Mathlib.Algebra.Group.Submonoid.Finsupp
import Mathlib.Order.Filter.AtTopBot.Defs
import Mathlib.RingTheory.Adjoin.Basic
import Mathlib.RingTheory.GradedAlgebra.FiniteType
import Mathlib.RingTheory.Localization.AtPrime.Basic
import Mathlib.RingTheory.Localization.Away.Basic
/-!
# Homogeneous Localization
## Notation
- `ι` is a commutative monoid;
- `R` is a commutative semiring;
- `A` is a commutative ring and an `R`-algebra;
- `𝒜 : ι → Submodule R A` is the grading of `A`;
- `x : Submonoid A` is a submonoid
## Main definitions and results
This file constructs the subring of `Aₓ` where the numerator and denominator have the same grading,
i.e. `{a/b ∈ Aₓ | ∃ (i : ι), a ∈ 𝒜ᵢ ∧ b ∈ 𝒜ᵢ}`.
* `HomogeneousLocalization.NumDenSameDeg`: a structure with a numerator and denominator field
where they are required to have the same grading.
However `NumDenSameDeg 𝒜 x` cannot have a ring structure for many reasons, for example if `c`
is a `NumDenSameDeg`, then generally, `c + (-c)` is not necessarily `0` for degree reasons ---
`0` is considered to have grade zero (see `deg_zero`) but `c + (-c)` has the same degree as `c`. To
circumvent this, we quotient `NumDenSameDeg 𝒜 x` by the kernel of `c ↦ c.num / c.den`.
* `HomogeneousLocalization.NumDenSameDeg.embedding`: for `x : Submonoid A` and any
`c : NumDenSameDeg 𝒜 x`, or equivalent a numerator and a denominator of the same degree,
we get an element `c.num / c.den` of `Aₓ`.
* `HomogeneousLocalization`: `NumDenSameDeg 𝒜 x` quotiented by kernel of `embedding 𝒜 x`.
* `HomogeneousLocalization.val`: if `f : HomogeneousLocalization 𝒜 x`, then `f.val` is an element
of `Aₓ`. In another word, one can view `HomogeneousLocalization 𝒜 x` as a subring of `Aₓ`
through `HomogeneousLocalization.val`.
* `HomogeneousLocalization.num`: if `f : HomogeneousLocalization 𝒜 x`, then `f.num : A` is the
numerator of `f`.
* `HomogeneousLocalization.den`: if `f : HomogeneousLocalization 𝒜 x`, then `f.den : A` is the
denominator of `f`.
* `HomogeneousLocalization.deg`: if `f : HomogeneousLocalization 𝒜 x`, then `f.deg : ι` is the
degree of `f` such that `f.num ∈ 𝒜 f.deg` and `f.den ∈ 𝒜 f.deg`
(see `HomogeneousLocalization.num_mem_deg` and `HomogeneousLocalization.den_mem_deg`).
* `HomogeneousLocalization.num_mem_deg`: if `f : HomogeneousLocalization 𝒜 x`, then
`f.num_mem_deg` is a proof that `f.num ∈ 𝒜 f.deg`.
* `HomogeneousLocalization.den_mem_deg`: if `f : HomogeneousLocalization 𝒜 x`, then
`f.den_mem_deg` is a proof that `f.den ∈ 𝒜 f.deg`.
* `HomogeneousLocalization.eq_num_div_den`: if `f : HomogeneousLocalization 𝒜 x`, then
`f.val : Aₓ` is equal to `f.num / f.den`.
* `HomogeneousLocalization.isLocalRing`: `HomogeneousLocalization 𝒜 x` is a local ring when `x` is
the complement of some prime ideals.
* `HomogeneousLocalization.map`: Let `A` and `B` be two graded rings and `g : A → B` a grading
preserving ring map. If `P ≤ A` and `Q ≤ B` are submonoids such that `P ≤ g⁻¹(Q)`, then `g`
induces a ring map between the homogeneous localization of `A` at `P` and the homogeneous
localization of `B` at `Q`.
## References
* [Robin Hartshorne, *Algebraic Geometry*][Har77]
-/
noncomputable section
open DirectSum Pointwise
open DirectSum SetLike
variable {ι R A : Type*}
variable [CommRing R] [CommRing A] [Algebra R A]
variable (𝒜 : ι → Submodule R A)
variable (x : Submonoid A)
local notation "at " x => Localization x
namespace HomogeneousLocalization
section
/-- Let `x` be a submonoid of `A`, then `NumDenSameDeg 𝒜 x` is a structure with a numerator and a
denominator with same grading such that the denominator is contained in `x`.
-/
structure NumDenSameDeg where
deg : ι
(num den : 𝒜 deg)
den_mem : (den : A) ∈ x
end
namespace NumDenSameDeg
open SetLike.GradedMonoid Submodule
variable {𝒜}
@[ext]
theorem ext {c1 c2 : NumDenSameDeg 𝒜 x} (hdeg : c1.deg = c2.deg) (hnum : (c1.num : A) = c2.num)
(hden : (c1.den : A) = c2.den) : c1 = c2 := by
rcases c1 with ⟨i1, ⟨n1, hn1⟩, ⟨d1, hd1⟩, h1⟩
rcases c2 with ⟨i2, ⟨n2, hn2⟩, ⟨d2, hd2⟩, h2⟩
dsimp only [Subtype.coe_mk] at *
subst hdeg hnum hden
congr
instance : Neg (NumDenSameDeg 𝒜 x) where
neg c := ⟨c.deg, ⟨-c.num, neg_mem c.num.2⟩, c.den, c.den_mem⟩
@[simp]
theorem deg_neg (c : NumDenSameDeg 𝒜 x) : (-c).deg = c.deg :=
rfl
@[simp]
theorem num_neg (c : NumDenSameDeg 𝒜 x) : ((-c).num : A) = -c.num :=
rfl
@[simp]
theorem den_neg (c : NumDenSameDeg 𝒜 x) : ((-c).den : A) = c.den :=
rfl
section SMul
variable {α : Type*} [SMul α R] [SMul α A] [IsScalarTower α R A]
instance : SMul α (NumDenSameDeg 𝒜 x) where
smul m c := ⟨c.deg, m • c.num, c.den, c.den_mem⟩
@[simp]
theorem deg_smul (c : NumDenSameDeg 𝒜 x) (m : α) : (m • c).deg = c.deg :=
rfl
@[simp]
theorem num_smul (c : NumDenSameDeg 𝒜 x) (m : α) : ((m • c).num : A) = m • c.num :=
rfl
@[simp]
theorem den_smul (c : NumDenSameDeg 𝒜 x) (m : α) : ((m • c).den : A) = c.den :=
rfl
end SMul
variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜]
instance : One (NumDenSameDeg 𝒜 x) where
one :=
{ deg := 0
-- Porting note: Changed `one_mem` to `GradedOne.one_mem`
num := ⟨1, GradedOne.one_mem⟩
den := ⟨1, GradedOne.one_mem⟩
den_mem := Submonoid.one_mem _ }
@[simp]
theorem deg_one : (1 : NumDenSameDeg 𝒜 x).deg = 0 :=
rfl
@[simp]
theorem num_one : ((1 : NumDenSameDeg 𝒜 x).num : A) = 1 :=
rfl
@[simp]
theorem den_one : ((1 : NumDenSameDeg 𝒜 x).den : A) = 1 :=
rfl
instance : Zero (NumDenSameDeg 𝒜 x) where
zero := ⟨0, 0, ⟨1, GradedOne.one_mem⟩, Submonoid.one_mem _⟩
@[simp]
theorem deg_zero : (0 : NumDenSameDeg 𝒜 x).deg = 0 :=
rfl
@[simp]
theorem num_zero : (0 : NumDenSameDeg 𝒜 x).num = 0 :=
rfl
@[simp]
theorem den_zero : ((0 : NumDenSameDeg 𝒜 x).den : A) = 1 :=
rfl
instance : Mul (NumDenSameDeg 𝒜 x) where
mul p q :=
{ deg := p.deg + q.deg
-- Porting note: Changed `mul_mem` to `GradedMul.mul_mem`
num := ⟨p.num * q.num, GradedMul.mul_mem p.num.prop q.num.prop⟩
den := ⟨p.den * q.den, GradedMul.mul_mem p.den.prop q.den.prop⟩
den_mem := Submonoid.mul_mem _ p.den_mem q.den_mem }
@[simp]
theorem deg_mul (c1 c2 : NumDenSameDeg 𝒜 x) : (c1 * c2).deg = c1.deg + c2.deg :=
rfl
@[simp]
theorem num_mul (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 * c2).num : A) = c1.num * c2.num :=
rfl
@[simp]
theorem den_mul (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 * c2).den : A) = c1.den * c2.den :=
rfl
instance : Add (NumDenSameDeg 𝒜 x) where
add c1 c2 :=
{ deg := c1.deg + c2.deg
num := ⟨c1.den * c2.num + c2.den * c1.num,
add_mem (GradedMul.mul_mem c1.den.2 c2.num.2)
(add_comm c2.deg c1.deg ▸ GradedMul.mul_mem c2.den.2 c1.num.2)⟩
den := ⟨c1.den * c2.den, GradedMul.mul_mem c1.den.2 c2.den.2⟩
den_mem := Submonoid.mul_mem _ c1.den_mem c2.den_mem }
@[simp]
theorem deg_add (c1 c2 : NumDenSameDeg 𝒜 x) : (c1 + c2).deg = c1.deg + c2.deg :=
rfl
@[simp]
theorem num_add (c1 c2 : NumDenSameDeg 𝒜 x) :
((c1 + c2).num : A) = c1.den * c2.num + c2.den * c1.num :=
rfl
@[simp]
theorem den_add (c1 c2 : NumDenSameDeg 𝒜 x) : ((c1 + c2).den : A) = c1.den * c2.den :=
rfl
instance : CommMonoid (NumDenSameDeg 𝒜 x) where
one := 1
mul := (· * ·)
mul_assoc _ _ _ := ext _ (add_assoc _ _ _) (mul_assoc _ _ _) (mul_assoc _ _ _)
one_mul _ := ext _ (zero_add _) (one_mul _) (one_mul _)
mul_one _ := ext _ (add_zero _) (mul_one _) (mul_one _)
mul_comm _ _ := ext _ (add_comm _ _) (mul_comm _ _) (mul_comm _ _)
instance : Pow (NumDenSameDeg 𝒜 x) ℕ where
pow c n :=
⟨n • c.deg, @GradedMonoid.GMonoid.gnpow _ (fun i => ↥(𝒜 i)) _ _ n _ c.num,
@GradedMonoid.GMonoid.gnpow _ (fun i => ↥(𝒜 i)) _ _ n _ c.den, by
induction' n with n ih
· simp only [coe_gnpow, pow_zero, one_mem]
· simpa only [pow_succ, coe_gnpow] using x.mul_mem ih c.den_mem⟩
@[simp]
theorem deg_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : (c ^ n).deg = n • c.deg :=
rfl
@[simp]
theorem num_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : ((c ^ n).num : A) = (c.num : A) ^ n :=
rfl
@[simp]
theorem den_pow (c : NumDenSameDeg 𝒜 x) (n : ℕ) : ((c ^ n).den : A) = (c.den : A) ^ n :=
rfl
variable (𝒜)
/-- For `x : prime ideal of A` and any `p : NumDenSameDeg 𝒜 x`, or equivalent a numerator and a
denominator of the same degree, we get an element `p.num / p.den` of `Aₓ`.
-/
def embedding (p : NumDenSameDeg 𝒜 x) : at x :=
Localization.mk p.num ⟨p.den, p.den_mem⟩
end NumDenSameDeg
end HomogeneousLocalization
/-- For `x : prime ideal of A`, `HomogeneousLocalization 𝒜 x` is `NumDenSameDeg 𝒜 x` modulo the
kernel of `embedding 𝒜 x`. This is essentially the subring of `Aₓ` where the numerator and
denominator share the same grading.
-/
def HomogeneousLocalization : Type _ :=
Quotient (Setoid.ker <| HomogeneousLocalization.NumDenSameDeg.embedding 𝒜 x)
namespace HomogeneousLocalization
open HomogeneousLocalization HomogeneousLocalization.NumDenSameDeg
variable {𝒜} {x}
/-- Construct an element of `HomogeneousLocalization 𝒜 x` from a homogeneous fraction. -/
abbrev mk (y : HomogeneousLocalization.NumDenSameDeg 𝒜 x) : HomogeneousLocalization 𝒜 x :=
Quotient.mk'' y
lemma mk_surjective : Function.Surjective (mk (𝒜 := 𝒜) (x := x)) :=
Quotient.mk''_surjective
/-- View an element of `HomogeneousLocalization 𝒜 x` as an element of `Aₓ` by forgetting that the
numerator and denominator are of the same grading.
-/
def val (y : HomogeneousLocalization 𝒜 x) : at x :=
Quotient.liftOn' y (NumDenSameDeg.embedding 𝒜 x) fun _ _ => id
@[simp]
theorem val_mk (i : NumDenSameDeg 𝒜 x) :
val (mk i) = Localization.mk (i.num : A) ⟨i.den, i.den_mem⟩ :=
rfl
variable (x)
@[ext]
theorem val_injective : Function.Injective (HomogeneousLocalization.val (𝒜 := 𝒜) (x := x)) :=
fun a b => Quotient.recOnSubsingleton₂' a b fun _ _ h => Quotient.sound' h
variable (𝒜) {x} in
lemma subsingleton (hx : 0 ∈ x) : Subsingleton (HomogeneousLocalization 𝒜 x) :=
have := IsLocalization.subsingleton (S := at x) hx
(HomogeneousLocalization.val_injective (𝒜 := 𝒜) (x := x)).subsingleton
section SMul
variable {α : Type*} [SMul α R] [SMul α A] [IsScalarTower α R A]
variable [IsScalarTower α A A]
instance : SMul α (HomogeneousLocalization 𝒜 x) where
smul m := Quotient.map' (m • ·) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_smul, den_smul]
convert congr_arg (fun z : at x => m • z) h <;> rw [Localization.smul_mk]
@[simp] lemma mk_smul (i : NumDenSameDeg 𝒜 x) (m : α) : mk (m • i) = m • mk i := rfl
@[simp]
theorem val_smul (n : α) : ∀ y : HomogeneousLocalization 𝒜 x, (n • y).val = n • y.val :=
Quotient.ind' fun _ ↦ by rw [← mk_smul, val_mk, val_mk, Localization.smul_mk]; rfl
theorem val_nsmul (n : ℕ) (y : HomogeneousLocalization 𝒜 x) : (n • y).val = n • y.val := by
rw [val_smul, OreLocalization.nsmul_eq_nsmul]
theorem val_zsmul (n : ℤ) (y : HomogeneousLocalization 𝒜 x) : (n • y).val = n • y.val := by
rw [val_smul, OreLocalization.zsmul_eq_zsmul]
end SMul
instance : Neg (HomogeneousLocalization 𝒜 x) where
neg := Quotient.map' Neg.neg fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_neg, den_neg, ← Localization.neg_mk]
exact congr_arg Neg.neg h
@[simp] lemma mk_neg (i : NumDenSameDeg 𝒜 x) : mk (-i) = -mk i := rfl
@[simp]
theorem val_neg {x} : ∀ y : HomogeneousLocalization 𝒜 x, (-y).val = -y.val :=
Quotient.ind' fun y ↦ by rw [← mk_neg, val_mk, val_mk, Localization.neg_mk]; rfl
variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜]
instance hasPow : Pow (HomogeneousLocalization 𝒜 x) ℕ where
pow z n :=
(Quotient.map' (· ^ n) fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_pow, den_pow]
convert congr_arg (fun z : at x => z ^ n) h <;> rw [Localization.mk_pow] <;> rfl :
HomogeneousLocalization 𝒜 x → HomogeneousLocalization 𝒜 x)
z
@[simp] lemma mk_pow (i : NumDenSameDeg 𝒜 x) (n : ℕ) : mk (i ^ n) = mk i ^ n := rfl
instance : Add (HomogeneousLocalization 𝒜 x) where
add :=
Quotient.map₂ (· + ·)
fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) c3 c4
(h' : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_add, den_add]
convert congr_arg₂ (· + ·) h h' <;> rw [Localization.add_mk] <;> rfl
@[simp] lemma mk_add (i j : NumDenSameDeg 𝒜 x) : mk (i + j) = mk i + mk j := rfl
instance : Sub (HomogeneousLocalization 𝒜 x) where sub z1 z2 := z1 + -z2
instance : Mul (HomogeneousLocalization 𝒜 x) where
mul :=
Quotient.map₂ (· * ·)
fun c1 c2 (h : Localization.mk _ _ = Localization.mk _ _) c3 c4
(h' : Localization.mk _ _ = Localization.mk _ _) => by
change Localization.mk _ _ = Localization.mk _ _
simp only [num_mul, den_mul]
convert congr_arg₂ (· * ·) h h' <;> rw [Localization.mk_mul] <;> rfl
@[simp] lemma mk_mul (i j : NumDenSameDeg 𝒜 x) : mk (i * j) = mk i * mk j := rfl
instance : One (HomogeneousLocalization 𝒜 x) where one := Quotient.mk'' 1
@[simp] lemma mk_one : mk (1 : NumDenSameDeg 𝒜 x) = 1 := rfl
instance : Zero (HomogeneousLocalization 𝒜 x) where zero := Quotient.mk'' 0
@[simp] lemma mk_zero : mk (0 : NumDenSameDeg 𝒜 x) = 0 := rfl
theorem zero_eq : (0 : HomogeneousLocalization 𝒜 x) = Quotient.mk'' 0 :=
rfl
theorem one_eq : (1 : HomogeneousLocalization 𝒜 x) = Quotient.mk'' 1 :=
rfl
variable {x}
@[simp]
theorem val_zero : (0 : HomogeneousLocalization 𝒜 x).val = 0 :=
Localization.mk_zero _
@[simp]
theorem val_one : (1 : HomogeneousLocalization 𝒜 x).val = 1 :=
Localization.mk_one
@[simp]
theorem val_add : ∀ y1 y2 : HomogeneousLocalization 𝒜 x, (y1 + y2).val = y1.val + y2.val :=
Quotient.ind₂' fun y1 y2 ↦ by rw [← mk_add, val_mk, val_mk, val_mk, Localization.add_mk]; rfl
@[simp]
theorem val_mul : ∀ y1 y2 : HomogeneousLocalization 𝒜 x, (y1 * y2).val = y1.val * y2.val :=
Quotient.ind₂' fun y1 y2 ↦ by rw [← mk_mul, val_mk, val_mk, val_mk, Localization.mk_mul]; rfl
@[simp]
theorem val_sub (y1 y2 : HomogeneousLocalization 𝒜 x) : (y1 - y2).val = y1.val - y2.val := by
rw [sub_eq_add_neg, ← val_neg, ← val_add]; rfl
@[simp]
theorem val_pow : ∀ (y : HomogeneousLocalization 𝒜 x) (n : ℕ), (y ^ n).val = y.val ^ n :=
Quotient.ind' fun y n ↦ by rw [← mk_pow, val_mk, val_mk, Localization.mk_pow]; rfl
instance : NatCast (HomogeneousLocalization 𝒜 x) :=
⟨Nat.unaryCast⟩
instance : IntCast (HomogeneousLocalization 𝒜 x) :=
⟨Int.castDef⟩
@[simp]
theorem val_natCast (n : ℕ) : (n : HomogeneousLocalization 𝒜 x).val = n :=
show val (Nat.unaryCast n) = _ by induction n <;> simp [Nat.unaryCast, *]
@[simp]
theorem val_intCast (n : ℤ) : (n : HomogeneousLocalization 𝒜 x).val = n :=
show val (Int.castDef n) = _ by cases n <;> simp [Int.castDef, *]
instance homogeneousLocalizationCommRing : CommRing (HomogeneousLocalization 𝒜 x) :=
(HomogeneousLocalization.val_injective x).commRing _ val_zero val_one val_add val_mul val_neg
val_sub (val_nsmul x · ·) (val_zsmul x · ·) val_pow val_natCast val_intCast
instance homogeneousLocalizationAlgebra :
Algebra (HomogeneousLocalization 𝒜 x) (Localization x) where
smul p q := p.val * q
algebraMap :=
{ toFun := val
map_one' := val_one
map_mul' := val_mul
map_zero' := val_zero
map_add' := val_add }
commutes' _ _ := mul_comm _ _
smul_def' _ _ := rfl
@[simp] lemma algebraMap_apply (y) :
algebraMap (HomogeneousLocalization 𝒜 x) (Localization x) y = y.val := rfl
lemma mk_eq_zero_of_num (f : NumDenSameDeg 𝒜 x) (h : f.num = 0) : mk f = 0 := by
apply val_injective
simp only [val_mk, val_zero, h, ZeroMemClass.coe_zero, Localization.mk_zero]
lemma mk_eq_zero_of_den (f : NumDenSameDeg 𝒜 x) (h : f.den = 0) : mk f = 0 := by
have := subsingleton 𝒜 (h ▸ f.den_mem)
exact Subsingleton.elim _ _
variable (𝒜 x) in
/-- The map from `𝒜 0` to the degree `0` part of `𝒜ₓ` sending `f ↦ f/1`. -/
def fromZeroRingHom : 𝒜 0 →+* HomogeneousLocalization 𝒜 x where
toFun f := .mk ⟨0, f, 1, one_mem _⟩
map_one' := rfl
map_mul' f g := by ext; simp [Localization.mk_mul]
map_zero' := rfl
map_add' f g := by ext; simp [Localization.add_mk, add_comm f.1 g.1]
instance : Algebra (𝒜 0) (HomogeneousLocalization 𝒜 x) :=
(fromZeroRingHom 𝒜 x).toAlgebra
lemma algebraMap_eq : algebraMap (𝒜 0) (HomogeneousLocalization 𝒜 x) = fromZeroRingHom 𝒜 x := rfl
instance : IsScalarTower (𝒜 0) (HomogeneousLocalization 𝒜 x) (Localization x) :=
.of_algebraMap_eq' rfl
end HomogeneousLocalization
namespace HomogeneousLocalization
open HomogeneousLocalization HomogeneousLocalization.NumDenSameDeg
variable {𝒜} {x}
/-- Numerator of an element in `HomogeneousLocalization x`. -/
def num (f : HomogeneousLocalization 𝒜 x) : A :=
(Quotient.out f).num
/-- Denominator of an element in `HomogeneousLocalization x`. -/
def den (f : HomogeneousLocalization 𝒜 x) : A :=
(Quotient.out f).den
/-- For an element in `HomogeneousLocalization x`, degree is the natural number `i` such that
`𝒜 i` contains both numerator and denominator. -/
def deg (f : HomogeneousLocalization 𝒜 x) : ι :=
(Quotient.out f).deg
theorem den_mem (f : HomogeneousLocalization 𝒜 x) : f.den ∈ x :=
(Quotient.out f).den_mem
theorem num_mem_deg (f : HomogeneousLocalization 𝒜 x) : f.num ∈ 𝒜 f.deg :=
(Quotient.out f).num.2
theorem den_mem_deg (f : HomogeneousLocalization 𝒜 x) : f.den ∈ 𝒜 f.deg :=
(Quotient.out f).den.2
theorem eq_num_div_den (f : HomogeneousLocalization 𝒜 x) :
f.val = Localization.mk f.num ⟨f.den, f.den_mem⟩ :=
congr_arg HomogeneousLocalization.val (Quotient.out_eq' f).symm
theorem den_smul_val (f : HomogeneousLocalization 𝒜 x) :
f.den • f.val = algebraMap _ _ f.num := by
rw [eq_num_div_den, Localization.mk_eq_mk', IsLocalization.smul_mk']
exact IsLocalization.mk'_mul_cancel_left _ ⟨_, _⟩
theorem ext_iff_val (f g : HomogeneousLocalization 𝒜 x) : f = g ↔ f.val = g.val :=
⟨congr_arg val, fun e ↦ val_injective x e⟩
section
variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜]
variable (𝒜) (𝔭 : Ideal A) [Ideal.IsPrime 𝔭]
/-- Localizing a ring homogeneously at a prime ideal. -/
abbrev AtPrime :=
HomogeneousLocalization 𝒜 𝔭.primeCompl
theorem isUnit_iff_isUnit_val (f : HomogeneousLocalization.AtPrime 𝒜 𝔭) :
IsUnit f.val ↔ IsUnit f := by
refine ⟨fun h1 ↦ ?_, IsUnit.map (algebraMap _ _)⟩
rcases h1 with ⟨⟨a, b, eq0, eq1⟩, rfl : a = f.val⟩
obtain ⟨f, rfl⟩ := mk_surjective f
obtain ⟨b, s, rfl⟩ := IsLocalization.mk'_surjective 𝔭.primeCompl b
rw [val_mk, Localization.mk_eq_mk', ← IsLocalization.mk'_mul, IsLocalization.mk'_eq_iff_eq_mul,
one_mul, IsLocalization.eq_iff_exists (M := 𝔭.primeCompl)] at eq0
obtain ⟨c, hc : _ = c.1 * (f.den.1 * s.1)⟩ := eq0
have : f.num.1 ∉ 𝔭 := by
exact fun h ↦ mul_mem c.2 (mul_mem f.den_mem s.2)
(hc ▸ Ideal.mul_mem_left _ c.1 (Ideal.mul_mem_right b _ h))
refine isUnit_of_mul_eq_one _ (Quotient.mk'' ⟨f.1, f.3, f.2, this⟩) ?_
rw [← mk_mul, ext_iff_val, val_mk]
simp [mul_comm f.den.1]
instance : Nontrivial (HomogeneousLocalization.AtPrime 𝒜 𝔭) :=
⟨⟨0, 1, fun r => by simp [ext_iff_val, val_zero, val_one, zero_ne_one] at r⟩⟩
instance isLocalRing : IsLocalRing (HomogeneousLocalization.AtPrime 𝒜 𝔭) :=
IsLocalRing.of_isUnit_or_isUnit_one_sub_self fun a => by
simpa only [← isUnit_iff_isUnit_val, val_sub, val_one]
using IsLocalRing.isUnit_or_isUnit_one_sub_self _
end
section
variable (𝒜) (f : A)
/-- Localizing away from powers of `f` homogeneously. -/
abbrev Away :=
HomogeneousLocalization 𝒜 (Submonoid.powers f)
variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜]
variable {𝒜} {f}
theorem Away.eventually_smul_mem {m} (hf : f ∈ 𝒜 m) (z : Away 𝒜 f) :
∀ᶠ n in Filter.atTop, f ^ n • z.val ∈ algebraMap _ _ '' (𝒜 (n • m) : Set A) := by
obtain ⟨k, hk : f ^ k = _⟩ := z.den_mem
apply Filter.mem_of_superset (Filter.Ici_mem_atTop k)
rintro k' (hk' : k ≤ k')
simp only [Set.mem_image, SetLike.mem_coe, Set.mem_setOf_eq]
by_cases hfk : f ^ k = 0
· refine ⟨0, zero_mem _, ?_⟩
rw [← tsub_add_cancel_of_le hk', map_zero, pow_add, hfk, mul_zero, zero_smul]
rw [← tsub_add_cancel_of_le hk', pow_add, mul_smul, hk, den_smul_val,
Algebra.smul_def, ← map_mul]
rw [← smul_eq_mul, add_smul,
DirectSum.degree_eq_of_mem_mem 𝒜 (SetLike.pow_mem_graded _ hf) (hk.symm ▸ z.den_mem_deg) hfk]
exact ⟨_, SetLike.mul_mem_graded (SetLike.pow_mem_graded _ hf) z.num_mem_deg, rfl⟩
end
section
variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜]
variable (𝒜)
variable {B : Type*} [CommRing B] [Algebra R B]
variable (ℬ : ι → Submodule R B) [GradedAlgebra ℬ]
variable {P : Submonoid A} {Q : Submonoid B}
/--
Let `A, B` be two graded algebras with the same indexing set and `g : A → B` be a graded algebra
homomorphism (i.e. `g(Aₘ) ⊆ Bₘ`). Let `P ≤ A` be a submonoid and `Q ≤ B` be a submonoid such that
`P ≤ g⁻¹ Q`, then `g` induce a map from the homogeneous localizations `A⁰_P` to the homogeneous
localizations `B⁰_Q`.
-/
def map (g : A →+* B)
(comap_le : P ≤ Q.comap g) (hg : ∀ i, ∀ a ∈ 𝒜 i, g a ∈ ℬ i) :
HomogeneousLocalization 𝒜 P →+* HomogeneousLocalization ℬ Q where
toFun := Quotient.map'
(fun x ↦ ⟨x.1, ⟨_, hg _ _ x.2.2⟩, ⟨_, hg _ _ x.3.2⟩, comap_le x.4⟩)
fun x y (e : x.embedding = y.embedding) ↦ by
apply_fun IsLocalization.map (Localization Q) g comap_le at e
simp_rw [HomogeneousLocalization.NumDenSameDeg.embedding, Localization.mk_eq_mk',
IsLocalization.map_mk', ← Localization.mk_eq_mk'] at e
exact e
map_add' := Quotient.ind₂' fun x y ↦ by
simp only [← mk_add, Quotient.map'_mk'', num_add, map_add, map_mul, den_add]; rfl
map_mul' := Quotient.ind₂' fun x y ↦ by
simp only [← mk_mul, Quotient.map'_mk'', num_mul, map_mul, den_mul]; rfl
map_zero' := by simp only [← mk_zero (𝒜 := 𝒜), Quotient.map'_mk'', deg_zero,
num_zero, ZeroMemClass.coe_zero, map_zero, den_zero, map_one]; rfl
map_one' := by simp only [← mk_one (𝒜 := 𝒜), Quotient.map'_mk'',
num_one, den_one, map_one]; rfl
/--
Let `A` be a graded algebra and `P ≤ Q` be two submonoids, then the homogeneous localization of `A`
at `P` embeds into the homogeneous localization of `A` at `Q`.
-/
abbrev mapId {P Q : Submonoid A} (h : P ≤ Q) :
HomogeneousLocalization 𝒜 P →+* HomogeneousLocalization 𝒜 Q :=
map 𝒜 𝒜 (RingHom.id _) h (fun _ _ ↦ id)
lemma map_mk (g : A →+* B)
(comap_le : P ≤ Q.comap g) (hg : ∀ i, ∀ a ∈ 𝒜 i, g a ∈ ℬ i) (x) :
map 𝒜 ℬ g comap_le hg (mk x) =
mk ⟨x.1, ⟨_, hg _ _ x.2.2⟩, ⟨_, hg _ _ x.3.2⟩, comap_le x.4⟩ :=
rfl
end
section mapAway
variable [AddCommMonoid ι] [DecidableEq ι] [GradedAlgebra 𝒜]
variable {e : ι} {f : A} {g : A} (hg : g ∈ 𝒜 e) {x : A} (hx : x = f * g)
variable (𝒜)
/-- Given `f ∣ x`, this is the map `A_{(f)} → A_f → A_x`. We will lift this to a map
`A_{(f)} → A_{(x)}` in `awayMap`. -/
private def awayMapAux (hx : f ∣ x) : Away 𝒜 f →+* Localization.Away x :=
(Localization.awayLift (algebraMap A _) _
(isUnit_of_dvd_unit (map_dvd _ hx) (IsLocalization.Away.algebraMap_isUnit x))).comp
(algebraMap (Away 𝒜 f) (Localization.Away f))
lemma awayMapAux_mk (n a i hi) :
awayMapAux 𝒜 ⟨_, hx⟩ (mk ⟨n, a, ⟨f ^ i, hi⟩, ⟨i, rfl⟩⟩) =
Localization.mk (a * g ^ i) ⟨x ^ i, (Submonoid.mem_powers_iff _ _).mpr ⟨i, rfl⟩⟩ := by
have : algebraMap A (Localization.Away x) f *
(Localization.mk g ⟨f * g, (Submonoid.mem_powers_iff _ _).mpr ⟨1, by simp [hx]⟩⟩) = 1 := by
rw [← Algebra.smul_def, Localization.smul_mk]
exact Localization.mk_self ⟨f*g, _⟩
simp [awayMapAux]
rw [Localization.awayLift_mk (hv := this), ← Algebra.smul_def,
Localization.mk_pow, Localization.smul_mk]
subst hx
rfl
include hg in
lemma range_awayMapAux_subset :
Set.range (awayMapAux 𝒜 (f := f) ⟨_, hx⟩) ⊆ Set.range (val (𝒜 := 𝒜)) := by
rintro _ ⟨z, rfl⟩
obtain ⟨⟨n, ⟨a, ha⟩, ⟨b, hb'⟩, j, rfl : _ = b⟩, rfl⟩ := mk_surjective z
use mk ⟨n+j•e,⟨a*g^j, ?_⟩ ,⟨x^j, ?_⟩, j, rfl⟩
· simp [awayMapAux_mk 𝒜 (hx := hx)]
· apply SetLike.mul_mem_graded ha
exact SetLike.pow_mem_graded _ hg
· rw [hx, mul_pow]
apply SetLike.mul_mem_graded hb'
exact SetLike.pow_mem_graded _ hg
/-- Given `x = f * g` with `g` homogeneous of positive degree,
this is the map `A_{(f)} → A_{(x)}` taking `a/f^i` to `ag^i/(fg)^i`. -/
def awayMap : Away 𝒜 f →+* Away 𝒜 x := by
let e := RingEquiv.ofLeftInverse (f := algebraMap (Away 𝒜 x) (Localization.Away x))
(h := (val_injective _).hasLeftInverse.choose_spec)
refine RingHom.comp (e.symm.toRingHom.comp (Subring.inclusion ?_))
(awayMapAux 𝒜 (f := f) ⟨_, hx⟩).rangeRestrict
exact range_awayMapAux_subset 𝒜 hg hx
lemma val_awayMap_eq_aux (a) : (awayMap 𝒜 hg hx a).val = awayMapAux 𝒜 ⟨_, hx⟩ a := by
let e := RingEquiv.ofLeftInverse (f := algebraMap (Away 𝒜 x) (Localization.Away x))
(h := (val_injective _).hasLeftInverse.choose_spec)
dsimp [awayMap]
convert_to (e (e.symm ⟨awayMapAux 𝒜 (f := f) ⟨_, hx⟩ a,
range_awayMapAux_subset 𝒜 hg hx ⟨_, rfl⟩⟩)).1 = _
rw [e.apply_symm_apply]
lemma val_awayMap (a) : (awayMap 𝒜 hg hx a).val = Localization.awayLift (algebraMap A _) _
(isUnit_of_dvd_unit (map_dvd _ ⟨_, hx⟩) (IsLocalization.Away.algebraMap_isUnit x)) a.val := by
rw [val_awayMap_eq_aux]
rfl
lemma awayMap_fromZeroRingHom (a) :
awayMap 𝒜 hg hx (fromZeroRingHom 𝒜 _ a) = fromZeroRingHom 𝒜 _ a := by
ext
simp only [fromZeroRingHom, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk,
val_awayMap, val_mk, SetLike.GradeZero.coe_one]
convert IsLocalization.lift_eq _ _
lemma val_awayMap_mk (n a i hi) : (awayMap 𝒜 hg hx (mk ⟨n, a, ⟨f ^ i, hi⟩, ⟨i, rfl⟩⟩)).val =
Localization.mk (a * g ^ i) ⟨x ^ i, (Submonoid.mem_powers_iff _ _).mpr ⟨i, rfl⟩⟩ := by
rw [val_awayMap_eq_aux, awayMapAux_mk 𝒜 (hx := hx)]
/-- Given `x = f * g` with `g` homogeneous of positive degree,
this is the map `A_{(f)} → A_{(x)}` taking `a/f^i` to `ag^i/(fg)^i`. -/
def awayMapₐ : Away 𝒜 f →ₐ[𝒜 0] Away 𝒜 x where
__ := awayMap 𝒜 hg hx
commutes' _ := awayMap_fromZeroRingHom ..
@[simp] lemma awayMapₐ_apply (a) : awayMapₐ 𝒜 hg hx a = awayMap 𝒜 hg hx a := rfl
/-- This is a convenient constructor for `Away 𝒜 f` when `f` is homogeneous.
`Away.mk 𝒜 hf n x hx` is the fraction `x / f ^ n`. -/
protected def Away.mk {d : ι} (hf : f ∈ 𝒜 d) (n : ℕ) (x : A) (hx : x ∈ 𝒜 (n • d)) : Away 𝒜 f :=
HomogeneousLocalization.mk ⟨n • d, ⟨x, hx⟩, ⟨f ^ n, SetLike.pow_mem_graded n hf⟩, ⟨n, rfl⟩⟩
@[simp]
lemma Away.val_mk {d : ι} (n : ℕ) (hf : f ∈ 𝒜 d) (x : A) (hx : x ∈ 𝒜 (n • d)) :
(Away.mk 𝒜 hf n x hx).val = Localization.mk x ⟨f ^ n, by use n⟩ :=
rfl
protected
lemma Away.mk_surjective {d : ι} (hf : f ∈ 𝒜 d) (x : Away 𝒜 f) :
∃ n a ha, Away.mk 𝒜 hf n a ha = x := by
obtain ⟨⟨N, ⟨s, hs⟩, ⟨b, hn⟩, ⟨n, (rfl : _ = b)⟩⟩, rfl⟩ := mk_surjective x
by_cases hfn : f ^ n = 0
· have := HomogeneousLocalization.subsingleton 𝒜 (x := .powers f) ⟨n, hfn⟩
exact ⟨0, 0, zero_mem _, Subsingleton.elim _ _⟩
obtain rfl := DirectSum.degree_eq_of_mem_mem 𝒜 hn (SetLike.pow_mem_graded n hf) hfn
exact ⟨n, s, hs, by ext; simp⟩
open SetLike in
@[simp]
lemma awayMap_mk {d : ι} (n : ℕ) (hf : f ∈ 𝒜 d) (a : A) (ha : a ∈ 𝒜 (n • d)) :
awayMap 𝒜 hg hx (Away.mk 𝒜 hf n a ha) = Away.mk 𝒜 (hx ▸ mul_mem_graded hf hg) n
(a * g ^ n) (by rw [smul_add]; exact mul_mem_graded ha (pow_mem_graded n hg)) := by
ext
exact val_awayMap_mk ..
end mapAway
section isLocalization
variable {𝒜 : ℕ → Submodule R A} [GradedAlgebra 𝒜]
variable {e d : ℕ} {f : A} (hf : f ∈ 𝒜 d) {g : A} (hg : g ∈ 𝒜 e)
/-- The element `t := g ^ d / f ^ e` such that `A_{(fg)} = A_{(f)}[1/t]`. -/
abbrev Away.isLocalizationElem : Away 𝒜 f :=
Away.mk 𝒜 hf e (g ^ d) (by convert SetLike.pow_mem_graded d hg using 2; exact mul_comm _ _)
variable {x : A} (hx : x = f * g)
/-- Let `t := g ^ d / f ^ e`, then `A_{(fg)} = A_{(f)}[1/t]`. -/
theorem Away.isLocalization_mul (hd : d ≠ 0) :
letI := (awayMap 𝒜 hg hx).toAlgebra
IsLocalization.Away (isLocalizationElem hf hg) (Away 𝒜 x) := by
letI := (awayMap 𝒜 hg hx).toAlgebra
constructor
· rintro ⟨r, n, rfl⟩
rw [map_pow, RingHom.algebraMap_toAlgebra]
let z : Away 𝒜 x := Away.mk 𝒜 (hx ▸ SetLike.mul_mem_graded hf hg) (d + e)
(g ^ e * f ^ (2 * e + d)) <| by
convert SetLike.mul_mem_graded (SetLike.pow_mem_graded e hg)
(SetLike.pow_mem_graded (2 * e + d) hf) using 2
ring
refine (isUnit_iff_exists_inv.mpr ⟨z, ?_⟩).pow _
ext
simp only [val_mul, val_one, awayMap_mk, Away.val_mk, z, Localization.mk_mul]
rw [← Localization.mk_one, Localization.mk_eq_mk_iff, Localization.r_iff_exists]
use 1
simp only [OneMemClass.coe_one, one_mul, Submonoid.coe_mul, mul_one, hx]
ring
· intro z
obtain ⟨n, s, hs, rfl⟩ := Away.mk_surjective 𝒜 (hx ▸ SetLike.mul_mem_graded hf hg) z
rcases d with - | d
· contradiction
let t : Away 𝒜 f := Away.mk 𝒜 hf (n * (e + 1)) (s * g ^ (n * d)) <| by
convert SetLike.mul_mem_graded hs (SetLike.pow_mem_graded _ hg) using 2; simp; ring
refine ⟨⟨t, ⟨_, ⟨n, rfl⟩⟩⟩, ?_⟩
ext
simp only [RingHom.algebraMap_toAlgebra, map_pow, awayMap_mk, val_mul, val_mk, val_pow,
Localization.mk_pow, Localization.mk_mul, t]
rw [Localization.mk_eq_mk_iff, Localization.r_iff_exists]
exact ⟨1, by simp; ring⟩
· intro a b e
obtain ⟨n, a, ha, rfl⟩ := Away.mk_surjective 𝒜 hf a
obtain ⟨m, b, hb, rfl⟩ := Away.mk_surjective 𝒜 hf b
replace e := congr_arg val e
simp only [RingHom.algebraMap_toAlgebra, awayMap_mk, val_mk,
Localization.mk_eq_mk_iff, Localization.r_iff_exists] at e
obtain ⟨⟨_, k, rfl⟩, hc⟩ := e
refine ⟨⟨_, k + m + n, rfl⟩, ?_⟩
ext
simp only [val_mul, val_pow, val_mk, Localization.mk_pow,
Localization.mk_eq_mk_iff, Localization.r_iff_exists, Submonoid.coe_mul, Localization.mk_mul,
SubmonoidClass.coe_pow, Subtype.exists, exists_prop]
refine ⟨_, ⟨k, rfl⟩, ?_⟩
rcases d with - | d
· contradiction
subst hx
convert congr(f ^ (e * (k + m + n)) * g ^ (d * (k + m + n)) * $hc) using 1 <;> ring
end isLocalization
section span
variable [AddCommMonoid ι] [DecidableEq ι] {𝒜 : ι → Submodule R A} [GradedAlgebra 𝒜] in
/--
Let `𝒜` be a graded algebra, finitely generated (as an algebra) over `𝒜₀` by `{ vᵢ }`,
where `vᵢ` has degree `dvᵢ`.
If `f : A` has degree `d`, then `𝒜_(f)` is generated (as a module) over `𝒜₀` by
elements of the form `(∏ i, vᵢ ^ aᵢ) / fᵃ` such that `∑ aᵢ • dvᵢ = a • d`.
-/
theorem Away.span_mk_prod_pow_eq_top {f : A} {d : ι} (hf : f ∈ 𝒜 d)
{ι' : Type*} [Fintype ι'] (v : ι' → A)
(hx : Algebra.adjoin (𝒜 0) (Set.range v) = ⊤) (dv : ι' → ι) (hxd : ∀ i, v i ∈ 𝒜 (dv i)) :
Submodule.span (𝒜 0) { (Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) : Away 𝒜 f) |
(a : ℕ) (ai : ι' → ℕ) (hai : ∑ i, ai i • dv i = a • d) } = ⊤ := by
by_cases HH : Subsingleton (HomogeneousLocalization.Away 𝒜 f)
· exact Subsingleton.elim _ _
rw [← top_le_iff]
rintro x -
obtain ⟨⟨n, ⟨a, ha⟩, ⟨b, hb'⟩, ⟨j, (rfl : _ = b)⟩⟩, rfl⟩ := mk_surjective x
by_cases hfj : f ^ j = 0
· exact (HH (HomogeneousLocalization.subsingleton _ ⟨_, hfj⟩)).elim
have : DirectSum.decompose 𝒜 a n = ⟨a, ha⟩ := Subtype.ext (DirectSum.decompose_of_mem_same 𝒜 ha)
simp_rw [← this]
clear this ha
have : a ∈ Submodule.span (𝒜 0) (Submonoid.closure (Set.range v)) := by
rw [← Algebra.adjoin_eq_span, hx]
trivial
induction this using Submodule.span_induction with
| mem a ha' =>
obtain ⟨ai, rfl⟩ := Submonoid.exists_of_mem_closure_range _ _ ha'
clear ha'
by_cases H : ∑ i, ai i • dv i = n
· apply Submodule.subset_span
refine ⟨j, ai, H.trans ?_, ?_⟩
· exact DirectSum.degree_eq_of_mem_mem 𝒜 hb'
(SetLike.pow_mem_graded j hf) hfj
· ext
simp only [val_mk, Away.val_mk]
congr
refine (DirectSum.decompose_of_mem_same _ ?_).symm
exact H ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i
· convert zero_mem (Submodule.span (𝒜 0) _)
ext
have : (DirectSum.decompose 𝒜 (∏ i : ι', v i ^ ai i) n).1 = 0 := by
refine DirectSum.decompose_of_mem_ne _ ?_ H
exact SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i
simp [this, Localization.mk_zero]
| zero =>
convert zero_mem (Submodule.span (𝒜 0) _)
ext; simp [Localization.mk_zero]
| add s t hs ht hs' ht' =>
convert add_mem hs' ht'
ext; simp [← Localization.add_mk_self]
| smul r x hx hx' =>
convert Submodule.smul_mem _ r hx'
ext
simp [Algebra.smul_def, algebraMap_eq, fromZeroRingHom, Localization.mk_mul,
-decompose_mul, coe_decompose_mul_of_left_mem_zero 𝒜 r.2]
variable {𝒜 : ℕ → Submodule R A} [GradedAlgebra 𝒜] in
/-- This is strictly weaker than `Away.adjoin_mk_prod_pow_eq_top`. -/
private
theorem Away.adjoin_mk_prod_pow_eq_top_of_pos {f : A} {d : ℕ} (hf : f ∈ 𝒜 d)
{ι' : Type*} [Fintype ι'] (v : ι' → A)
(hx : Algebra.adjoin (𝒜 0) (Set.range v) = ⊤) (dv : ι' → ℕ)
(hxd : ∀ i, v i ∈ 𝒜 (dv i)) (hxd' : ∀ i, 0 < dv i) :
Algebra.adjoin (𝒜 0) { Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) |
(a : ℕ) (ai : ι' → ℕ) (hai : ∑ i, ai i • dv i = a • d) (_ : ∀ i, ai i ≤ d) } = ⊤ := by
rw [← top_le_iff]
change ⊤ ≤ (Algebra.adjoin (𝒜 0) _).toSubmodule
rw [← HomogeneousLocalization.Away.span_mk_prod_pow_eq_top hf v hx dv hxd, Submodule.span_le]
rintro _ ⟨a, ai, hai, rfl⟩
have H₀ : (a - ∑ i : ι', dv i * (ai i / d)) • d = ∑ k : ι', (ai k % d) • dv k := by
rw [smul_eq_mul, tsub_mul, ← smul_eq_mul, ← hai]
conv => enter [1, 1, 2, i]; rw [← Nat.mod_add_div (ai i) d]
simp_rw [smul_eq_mul, add_mul, Finset.sum_add_distrib,
mul_assoc, ← Finset.mul_sum, mul_comm d, mul_comm (_ / _)]
simp only [add_tsub_cancel_right]
have H : Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) =
Away.mk 𝒜 hf (a - ∑ i : ι', dv i * (ai i / d)) (∏ i, v i ^ (ai i % d))
(H₀ ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) *
∏ i, Away.isLocalizationElem hf (hxd i) ^ (ai i / d) := by
apply (show Function.Injective (algebraMap (Away 𝒜 f) (Localization.Away f))
from val_injective _)
simp only [map_pow, map_prod, map_mul]
simp only [HomogeneousLocalization.algebraMap_apply, val_mk,
Localization.mk_pow, Localization.mk_prod, Localization.mk_mul,
← Finset.prod_mul_distrib, ← pow_add, ← pow_mul]
congr
· ext i
congr
exact Eq.symm (Nat.mod_add_div (ai i) d)
· simp only [SubmonoidClass.coe_finset_prod, ← pow_add, ← pow_mul,
Finset.prod_pow_eq_pow_sum, SubmonoidClass.coe_pow]
rw [tsub_add_cancel_of_le]
rcases d.eq_zero_or_pos with hd | hd
· simp [hd]
rw [← mul_le_mul_iff_of_pos_right hd, ← smul_eq_mul (a := a), ← hai, Finset.sum_mul]
simp_rw [smul_eq_mul, mul_comm (ai _), mul_assoc]
gcongr
exact Nat.div_mul_le_self (ai _) d
rw [H, SetLike.mem_coe]
apply (Algebra.adjoin (𝒜 0) _).mul_mem
· apply Algebra.subset_adjoin
refine ⟨a - ∑ i : ι', dv i * (ai i / d), (ai · % d), H₀.symm, ?_, rfl⟩
rcases d.eq_zero_or_pos with hd | hd
· have : ∀ (x : ι'), ai x = 0 := by simpa [hd, fun i ↦ (hxd' i).ne'] using hai
simp [this]
exact fun i ↦ (Nat.mod_lt _ hd).le
apply prod_mem
· classical
rintro j -
apply pow_mem
apply Algebra.subset_adjoin
refine ⟨dv j, Pi.single j d, ?_, ?_, ?_⟩
· simp [Pi.single_apply, mul_comm]
· aesop (add simp Pi.single_apply)
ext
simp [Pi.single_apply]
variable {𝒜 : ℕ → Submodule R A} [GradedAlgebra 𝒜] in
/--
Let `𝒜` be a graded algebra, finitely generated (as an algebra) over `𝒜₀` by `{ vᵢ }`,
where `vᵢ` has degree `dvᵢ`.
If `f : A` has degree `d`, then `𝒜_(f)` is generated (as an algebra) over `𝒜₀` by
elements of the form `(∏ i, vᵢ ^ aᵢ) / fᵃ` such that `∑ aᵢ • dvᵢ = a • d` and `∀ i, aᵢ ≤ d`.
-/
theorem Away.adjoin_mk_prod_pow_eq_top {f : A} {d : ℕ} (hf : f ∈ 𝒜 d)
(ι' : Type*) [Fintype ι'] (v : ι' → A)
(hx : Algebra.adjoin (𝒜 0) (Set.range v) = ⊤) (dv : ι' → ℕ) (hxd : ∀ i, v i ∈ 𝒜 (dv i)) :
Algebra.adjoin (𝒜 0) { Away.mk 𝒜 hf a (∏ i, v i ^ ai i)
(hai ▸ SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i) |
(a : ℕ) (ai : ι' → ℕ) (hai : ∑ i, ai i • dv i = a • d) (_ : ∀ i, ai i ≤ d) } = ⊤ := by
classical
let s := Finset.univ.filter (0 < dv ·)
have := Away.adjoin_mk_prod_pow_eq_top_of_pos hf (ι' := s) (v ∘ Subtype.val) ?_
(dv ∘ Subtype.val) (fun _ ↦ hxd _) (by simp [s])
swap
· rw [← top_le_iff, ← hx, Algebra.adjoin_le_iff, Set.range_subset_iff]
intro i
rcases (dv i).eq_zero_or_pos with hi | hi
· exact algebraMap_mem (R := 𝒜 0) _ ⟨v i, hi ▸ hxd i⟩
exact Algebra.subset_adjoin ⟨⟨i, by simpa [s] using hi⟩, rfl⟩
rw [← top_le_iff, ← this]
apply Algebra.adjoin_mono
rintro _ ⟨a, ai, hai : ∑ x ∈ s.attach, _ = _, h, rfl⟩
refine ⟨a, fun i ↦ if hi : i ∈ s then ai ⟨i, hi⟩ else 0, ?_, ?_, ?_⟩
· simpa [Finset.sum_attach_eq_sum_dite] using hai
· simp [apply_dite, dite_apply, h]
· congr 1
change _ = ∏ x ∈ s.attach, _
simp [Finset.prod_attach_eq_prod_dite]
variable {𝒜 : ℕ → Submodule R A} [GradedAlgebra 𝒜] [Algebra.FiniteType (𝒜 0) A] in
lemma Away.finiteType (f : A) (d : ℕ) (hf : f ∈ 𝒜 d) :
Algebra.FiniteType (𝒜 0) (Away 𝒜 f) := by
constructor
obtain ⟨s, hs, hs'⟩ := GradedAlgebra.exists_finset_adjoin_eq_top_and_homogeneous_ne_zero 𝒜
choose dx hdx hxd using Subtype.forall'.mp hs'
simp_rw [Subalgebra.fg_def, ← top_le_iff,
← Away.adjoin_mk_prod_pow_eq_top hf (ι' := s) Subtype.val (by simpa) dx hxd]
rcases d.eq_zero_or_pos with hd | hd
· let f' := Away.mk 𝒜 hf 1 1 (by simp [hd, GradedOne.one_mem])
refine ⟨{f'}, Set.finite_singleton f', ?_⟩
rw [Algebra.adjoin_le_iff]
rintro _ ⟨a, ai, hai, hai', rfl⟩
obtain rfl : ai = 0 := funext <| by simpa [hd, hdx] using hai
simp only [Finset.univ_eq_attach, Pi.zero_apply, pow_zero, Finset.prod_const_one, mem_coe]
convert pow_mem (Algebra.self_mem_adjoin_singleton (𝒜 0) f') a using 1
ext
simp [f', Localization.mk_pow]
refine ⟨_, ?_, le_rfl⟩
let b := ∑ i, dx i
let s' : Set ((Fin (b + 1)) × (s → Fin (d + 1))) := { ai | ∑ i, (ai.2 i).1 * dx i = ai.1 * d }
let F : s' → Away 𝒜 f := fun ai ↦ Away.mk 𝒜 hf ai.1.1.1 (∏ i, i ^ (ai.1.2 i).1)
(by convert SetLike.prod_pow_mem_graded _ _ _ _ fun i _ ↦ hxd i; exact ai.2.symm)
apply (Set.finite_range F).subset
rintro _ ⟨a, ai, hai, hai', rfl⟩
refine ⟨⟨⟨⟨a, ?_⟩, fun i ↦ ⟨ai i, (hai' i).trans_lt d.lt_succ_self⟩⟩, hai⟩, rfl⟩
rw [Nat.lt_succ, ← mul_le_mul_iff_of_pos_right hd, ← smul_eq_mul, ← hai, Finset.sum_mul]
simp_rw [smul_eq_mul, mul_comm _ d]
gcongr
exact hai' _
end span
end HomogeneousLocalization
|
PrincipalIdealDomain.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Morenikeji Neri
-/
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.EuclideanDomain.Field
import Mathlib.Algebra.GCDMonoid.Basic
import Mathlib.RingTheory.Ideal.Prod
import Mathlib.RingTheory.Ideal.Nonunits
import Mathlib.RingTheory.Noetherian.UniqueFactorizationDomain
/-!
# Principal ideal rings, principal ideal domains, and Bézout rings
A principal ideal ring (PIR) is a ring in which all left ideals are principal. A
principal ideal domain (PID) is an integral domain which is a principal ideal ring.
The definition of `IsPrincipalIdealRing` can be found in `Mathlib/RingTheory/Ideal/Span.lean`.
# Main definitions
Note that for principal ideal domains, one should use
`[IsDomain R] [IsPrincipalIdealRing R]`. There is no explicit definition of a PID.
Theorems about PID's are in the `PrincipalIdealRing` namespace.
- `IsBezout`: the predicate saying that every finitely generated left ideal is principal.
- `generator`: a generator of a principal ideal (or more generally submodule)
- `to_uniqueFactorizationMonoid`: a PID is a unique factorization domain
# Main results
- `Ideal.IsPrime.to_maximal_ideal`: a non-zero prime ideal in a PID is maximal.
- `EuclideanDomain.to_principal_ideal_domain` : a Euclidean domain is a PID.
- `IsBezout.nonemptyGCDMonoid`: Every Bézout domain is a GCD domain.
-/
universe u v
variable {R : Type u} {M : Type v}
open Set Function
open Submodule
section
variable [Semiring R] [AddCommMonoid M] [Module R M]
instance bot_isPrincipal : (⊥ : Submodule R M).IsPrincipal :=
⟨⟨0, by simp⟩⟩
instance top_isPrincipal : (⊤ : Submodule R R).IsPrincipal :=
⟨⟨1, Ideal.span_singleton_one.symm⟩⟩
variable (R)
/-- A Bézout ring is a ring whose finitely generated ideals are principal. -/
class IsBezout : Prop where
/-- Any finitely generated ideal is principal. -/
isPrincipal_of_FG : ∀ I : Ideal R, I.FG → I.IsPrincipal
instance (priority := 100) IsBezout.of_isPrincipalIdealRing [IsPrincipalIdealRing R] : IsBezout R :=
⟨fun I _ => IsPrincipalIdealRing.principal I⟩
instance (priority := 100) DivisionSemiring.isPrincipalIdealRing (K : Type u) [DivisionSemiring K] :
IsPrincipalIdealRing K where
principal S := by
rcases Ideal.eq_bot_or_top S with (rfl | rfl)
· apply bot_isPrincipal
· apply top_isPrincipal
end
namespace Submodule.IsPrincipal
variable [AddCommMonoid M]
section Semiring
variable [Semiring R] [Module R M]
/-- `generator I`, if `I` is a principal submodule, is an `x ∈ M` such that `span R {x} = I` -/
noncomputable def generator (S : Submodule R M) [S.IsPrincipal] : M :=
Classical.choose (principal S)
theorem span_singleton_generator (S : Submodule R M) [S.IsPrincipal] : span R {generator S} = S :=
Eq.symm (Classical.choose_spec (principal S))
@[simp]
theorem _root_.Ideal.span_singleton_generator (I : Ideal R) [I.IsPrincipal] :
Ideal.span ({generator I} : Set R) = I :=
Eq.symm (Classical.choose_spec (principal I))
@[simp]
theorem generator_mem (S : Submodule R M) [S.IsPrincipal] : generator S ∈ S := by
have : generator S ∈ span R {generator S} := subset_span (mem_singleton _)
convert this
exact span_singleton_generator S |>.symm
theorem mem_iff_eq_smul_generator (S : Submodule R M) [S.IsPrincipal] {x : M} :
x ∈ S ↔ ∃ s : R, x = s • generator S := by
simp_rw [@eq_comm _ x, ← mem_span_singleton, span_singleton_generator]
theorem eq_bot_iff_generator_eq_zero (S : Submodule R M) [S.IsPrincipal] :
S = ⊥ ↔ generator S = 0 := by rw [← @span_singleton_eq_bot R M, span_singleton_generator]
protected lemma fg {S : Submodule R M} (h : S.IsPrincipal) : S.FG :=
⟨{h.generator}, by simp only [Finset.coe_singleton, span_singleton_generator]⟩
-- See note [lower instance priority]
instance (priority := 100) _root_.PrincipalIdealRing.isNoetherianRing [IsPrincipalIdealRing R] :
IsNoetherianRing R where
noetherian S := (IsPrincipalIdealRing.principal S).fg
-- See note [lower instance priority]
instance (priority := 100) _root_.IsPrincipalIdealRing.of_isNoetherianRing_of_isBezout
[IsNoetherianRing R] [IsBezout R] : IsPrincipalIdealRing R where
principal S := IsBezout.isPrincipal_of_FG S (IsNoetherian.noetherian S)
end Semiring
section CommRing
variable [CommRing R] [Module R M]
theorem associated_generator_span_self [IsDomain R] (r : R) :
Associated (generator <| Ideal.span {r}) r := by
rw [← Ideal.span_singleton_eq_span_singleton]
exact Ideal.span_singleton_generator _
theorem mem_iff_generator_dvd (S : Ideal R) [S.IsPrincipal] {x : R} : x ∈ S ↔ generator S ∣ x :=
(mem_iff_eq_smul_generator S).trans (exists_congr fun a => by simp only [mul_comm, smul_eq_mul])
theorem prime_generator_of_isPrime (S : Ideal R) [S.IsPrincipal] [is_prime : S.IsPrime]
(ne_bot : S ≠ ⊥) : Prime (generator S) :=
⟨fun h => ne_bot ((eq_bot_iff_generator_eq_zero S).2 h), fun h =>
is_prime.ne_top (S.eq_top_of_isUnit_mem (generator_mem S) h), fun _ _ => by
simpa only [← mem_iff_generator_dvd S] using is_prime.2⟩
-- Note that the converse may not hold if `ϕ` is not injective.
theorem generator_map_dvd_of_mem {N : Submodule R M} (ϕ : M →ₗ[R] R) [(N.map ϕ).IsPrincipal] {x : M}
(hx : x ∈ N) : generator (N.map ϕ) ∣ ϕ x := by
rw [← mem_iff_generator_dvd, Submodule.mem_map]
exact ⟨x, hx, rfl⟩
-- Note that the converse may not hold if `ϕ` is not injective.
theorem generator_submoduleImage_dvd_of_mem {N O : Submodule R M} (hNO : N ≤ O) (ϕ : O →ₗ[R] R)
[(ϕ.submoduleImage N).IsPrincipal] {x : M} (hx : x ∈ N) :
generator (ϕ.submoduleImage N) ∣ ϕ ⟨x, hNO hx⟩ := by
rw [← mem_iff_generator_dvd, LinearMap.mem_submoduleImage_of_le hNO]
exact ⟨x, hx, rfl⟩
end CommRing
end Submodule.IsPrincipal
namespace IsBezout
section
variable [Ring R]
instance span_pair_isPrincipal [IsBezout R] (x y : R) : (Ideal.span {x, y}).IsPrincipal := by
classical exact isPrincipal_of_FG (Ideal.span {x, y}) ⟨{x, y}, by simp⟩
variable (x y : R) [(Ideal.span {x, y}).IsPrincipal]
/-- A choice of gcd of two elements in a Bézout domain.
Note that the choice is usually not unique. -/
noncomputable def gcd : R := Submodule.IsPrincipal.generator (Ideal.span {x, y})
theorem span_gcd : Ideal.span {gcd x y} = Ideal.span {x, y} :=
Ideal.span_singleton_generator _
end
variable [CommRing R] (x y z : R) [(Ideal.span {x, y}).IsPrincipal]
theorem gcd_dvd_left : gcd x y ∣ x :=
(Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp))
theorem gcd_dvd_right : gcd x y ∣ y :=
(Submodule.IsPrincipal.mem_iff_generator_dvd _).mp (Ideal.subset_span (by simp))
variable {x y z} in
theorem dvd_gcd (hx : z ∣ x) (hy : z ∣ y) : z ∣ gcd x y := by
rw [← Ideal.span_singleton_le_span_singleton] at hx hy ⊢
rw [span_gcd, Ideal.span_insert, sup_le_iff]
exact ⟨hx, hy⟩
theorem gcd_eq_sum : ∃ a b : R, a * x + b * y = gcd x y :=
Ideal.mem_span_pair.mp (by rw [← span_gcd]; apply Ideal.subset_span; simp)
variable {x y}
theorem _root_.IsRelPrime.isCoprime (h : IsRelPrime x y) : IsCoprime x y := by
rw [← Ideal.isCoprime_span_singleton_iff, Ideal.isCoprime_iff_sup_eq, ← Ideal.span_union,
Set.singleton_union, ← span_gcd, Ideal.span_singleton_eq_top]
exact h (gcd_dvd_left x y) (gcd_dvd_right x y)
theorem _root_.isRelPrime_iff_isCoprime : IsRelPrime x y ↔ IsCoprime x y :=
⟨IsRelPrime.isCoprime, IsCoprime.isRelPrime⟩
variable (R)
/-- Any Bézout domain is a GCD domain. This is not an instance since `GCDMonoid` contains data,
and this might not be how we would like to construct it. -/
noncomputable def toGCDDomain [IsBezout R] [IsDomain R] [DecidableEq R] : GCDMonoid R :=
gcdMonoidOfGCD (gcd · ·) (gcd_dvd_left · ·) (gcd_dvd_right · ·) dvd_gcd
instance nonemptyGCDMonoid [IsBezout R] [IsDomain R] : Nonempty (GCDMonoid R) := by
classical exact ⟨toGCDDomain R⟩
theorem associated_gcd_gcd [IsDomain R] [GCDMonoid R] :
Associated (IsBezout.gcd x y) (GCDMonoid.gcd x y) :=
gcd_greatest_associated (gcd_dvd_left _ _) (gcd_dvd_right _ _) (fun _ => dvd_gcd)
end IsBezout
namespace IsPrime
open Submodule.IsPrincipal Ideal
-- TODO -- for a non-ID one could perhaps prove that if p < q are prime then q maximal;
-- 0 isn't prime in a non-ID PIR but the Krull dimension is still <= 1.
-- The below result follows from this, but we could also use the below result to
-- prove this (quotient out by p).
theorem to_maximal_ideal [CommRing R] [IsDomain R] [IsPrincipalIdealRing R] {S : Ideal R}
[hpi : IsPrime S] (hS : S ≠ ⊥) : IsMaximal S :=
isMaximal_iff.2
⟨(ne_top_iff_one S).1 hpi.1, by
intro T x hST hxS hxT
obtain ⟨z, hz⟩ := (mem_iff_generator_dvd _).1 (hST <| generator_mem S)
cases hpi.mem_or_mem (show generator T * z ∈ S from hz ▸ generator_mem S) with
| inl h =>
have hTS : T ≤ S := by
rwa [← T.span_singleton_generator, Ideal.span_le, singleton_subset_iff]
exact (hxS <| hTS hxT).elim
| inr h =>
obtain ⟨y, hy⟩ := (mem_iff_generator_dvd _).1 h
have : generator S ≠ 0 := mt (eq_bot_iff_generator_eq_zero _).2 hS
rw [← mul_one (generator S), hy, mul_left_comm, mul_right_inj' this] at hz
exact hz.symm ▸ T.mul_mem_right _ (generator_mem T)⟩
end IsPrime
section
open EuclideanDomain
variable [EuclideanDomain R]
theorem mod_mem_iff {S : Ideal R} {x y : R} (hy : y ∈ S) : x % y ∈ S ↔ x ∈ S :=
⟨fun hxy => div_add_mod x y ▸ S.add_mem (S.mul_mem_right _ hy) hxy, fun hx =>
(mod_eq_sub_mul_div x y).symm ▸ S.sub_mem hx (S.mul_mem_right _ hy)⟩
-- see Note [lower instance priority]
instance (priority := 100) EuclideanDomain.to_principal_ideal_domain : IsPrincipalIdealRing R where
principal S := by classical exact
⟨if h : { x : R | x ∈ S ∧ x ≠ 0 }.Nonempty then
have wf : WellFounded (EuclideanDomain.r : R → R → Prop) := EuclideanDomain.r_wellFounded
have hmin : WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ∈ S ∧
WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ≠ 0 :=
WellFounded.min_mem wf { x : R | x ∈ S ∧ x ≠ 0 } h
⟨WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h,
Submodule.ext fun x => ⟨fun hx =>
div_add_mod x (WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h) ▸
(Ideal.mem_span_singleton.2 <| dvd_add (dvd_mul_right _ _) <| by
have : x % WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h ∉
{ x : R | x ∈ S ∧ x ≠ 0 } :=
fun h₁ => WellFounded.not_lt_min wf _ h h₁ (mod_lt x hmin.2)
have : x % WellFounded.min wf { x : R | x ∈ S ∧ x ≠ 0 } h = 0 := by
simp only [not_and_or, Set.mem_setOf_eq, not_ne_iff] at this
exact this.neg_resolve_left <| (mod_mem_iff hmin.1).2 hx
simp [*]),
fun hx =>
let ⟨y, hy⟩ := Ideal.mem_span_singleton.1 hx
hy.symm ▸ S.mul_mem_right _ hmin.1⟩⟩
else ⟨0, Submodule.ext fun a => by
rw [← @Submodule.bot_coe R R _ _ _, span_eq, Submodule.mem_bot]
exact ⟨fun haS => by_contra fun ha0 => h ⟨a, ⟨haS, ha0⟩⟩,
fun h₁ => h₁.symm ▸ S.zero_mem⟩⟩⟩
end
theorem IsField.isPrincipalIdealRing {R : Type*} [Ring R] (h : IsField R) :
IsPrincipalIdealRing R :=
@EuclideanDomain.to_principal_ideal_domain R (@Field.toEuclideanDomain R h.toField)
namespace PrincipalIdealRing
open IsPrincipalIdealRing
theorem isMaximal_of_irreducible [CommSemiring R] [IsPrincipalIdealRing R] {p : R}
(hp : Irreducible p) : Ideal.IsMaximal (span R ({p} : Set R)) :=
⟨⟨mt Ideal.span_singleton_eq_top.1 hp.1, fun I hI => by
rcases principal I with ⟨a, rfl⟩
rw [Ideal.submodule_span_eq, Ideal.span_singleton_eq_top]
rcases Ideal.span_singleton_le_span_singleton.1 (le_of_lt hI) with ⟨b, rfl⟩
refine (of_irreducible_mul hp).resolve_right (mt (fun hb => ?_) (not_le_of_gt hI))
rw [Ideal.submodule_span_eq, Ideal.submodule_span_eq,
Ideal.span_singleton_le_span_singleton, IsUnit.mul_right_dvd hb]⟩⟩
variable [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
section
open scoped Classical in
/-- `factors a` is a multiset of irreducible elements whose product is `a`, up to units -/
noncomputable def factors (a : R) : Multiset R :=
if h : a = 0 then ∅ else Classical.choose (WfDvdMonoid.exists_factors a h)
theorem factors_spec (a : R) (h : a ≠ 0) :
(∀ b ∈ factors a, Irreducible b) ∧ Associated (factors a).prod a := by
unfold factors; rw [dif_neg h]
exact Classical.choose_spec (WfDvdMonoid.exists_factors a h)
theorem ne_zero_of_mem_factors {R : Type v} [CommRing R] [IsDomain R] [IsPrincipalIdealRing R]
{a b : R} (ha : a ≠ 0) (hb : b ∈ factors a) : b ≠ 0 :=
Irreducible.ne_zero ((factors_spec a ha).1 b hb)
theorem mem_submonoid_of_factors_subset_of_units_subset (s : Submonoid R) {a : R} (ha : a ≠ 0)
(hfac : ∀ b ∈ factors a, b ∈ s) (hunit : ∀ c : Rˣ, (c : R) ∈ s) : a ∈ s := by
rcases (factors_spec a ha).2 with ⟨c, hc⟩
rw [← hc]
exact mul_mem (multiset_prod_mem _ hfac) (hunit _)
/-- If a `RingHom` maps all units and all factors of an element `a` into a submonoid `s`, then it
also maps `a` into that submonoid. -/
theorem ringHom_mem_submonoid_of_factors_subset_of_units_subset {R S : Type*} [CommRing R]
[IsDomain R] [IsPrincipalIdealRing R] [NonAssocSemiring S] (f : R →+* S) (s : Submonoid S)
(a : R) (ha : a ≠ 0) (h : ∀ b ∈ factors a, f b ∈ s) (hf : ∀ c : Rˣ, f c ∈ s) : f a ∈ s :=
mem_submonoid_of_factors_subset_of_units_subset (s.comap f.toMonoidHom) ha h hf
-- see Note [lower instance priority]
/-- A principal ideal domain has unique factorization -/
instance (priority := 100) to_uniqueFactorizationMonoid : UniqueFactorizationMonoid R :=
{ (IsNoetherianRing.wfDvdMonoid : WfDvdMonoid R) with
irreducible_iff_prime := irreducible_iff_prime }
end
end PrincipalIdealRing
section Surjective
open Submodule
variable {S N F : Type*} [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Semiring S]
variable [Module R M] [Module R N] [FunLike F R S] [RingHomClass F R S]
theorem Submodule.IsPrincipal.map (f : M →ₗ[R] N) {S : Submodule R M}
(hI : IsPrincipal S) : IsPrincipal (map f S) :=
⟨⟨f (IsPrincipal.generator S), by
rw [← Set.image_singleton, ← map_span, span_singleton_generator]⟩⟩
theorem Submodule.IsPrincipal.of_comap (f : M →ₗ[R] N) (hf : Function.Surjective f)
(S : Submodule R N) [hI : IsPrincipal (S.comap f)] : IsPrincipal S := by
rw [← Submodule.map_comap_eq_of_surjective hf S]
exact hI.map f
theorem Submodule.IsPrincipal.map_ringHom (f : F) {I : Ideal R}
(hI : IsPrincipal I) : IsPrincipal (Ideal.map f I) :=
⟨⟨f (IsPrincipal.generator I), by
rw [Ideal.submodule_span_eq, ← Set.image_singleton, ← Ideal.map_span,
Ideal.span_singleton_generator]⟩⟩
theorem Ideal.IsPrincipal.of_comap (f : F) (hf : Function.Surjective f) (I : Ideal S)
[hI : IsPrincipal (I.comap f)] : IsPrincipal I := by
rw [← map_comap_of_surjective f hf I]
exact hI.map_ringHom f
/-- The surjective image of a principal ideal ring is again a principal ideal ring. -/
theorem IsPrincipalIdealRing.of_surjective [IsPrincipalIdealRing R] (f : F)
(hf : Function.Surjective f) : IsPrincipalIdealRing S :=
⟨fun I => Ideal.IsPrincipal.of_comap f hf I⟩
instance [IsPrincipalIdealRing R] [IsPrincipalIdealRing S] : IsPrincipalIdealRing (R × S) where
principal I := by
rw [I.ideal_prod_eq, ← (I.map _).span_singleton_generator,
← (I.map (RingHom.snd R S)).span_singleton_generator,
← Ideal.span_prod (iff_of_true (by simp) (by simp)), Set.singleton_prod_singleton]
exact ⟨_, rfl⟩
theorem isPrincipalIdealRing_prod_iff :
IsPrincipalIdealRing (R × S) ↔ IsPrincipalIdealRing R ∧ IsPrincipalIdealRing S where
mp h := ⟨h.of_surjective (RingHom.fst R S) Prod.fst_surjective,
h.of_surjective (RingHom.snd R S) Prod.snd_surjective⟩
mpr := fun ⟨_, _⟩ ↦ inferInstance
end Surjective
section
open Ideal
variable [CommRing R]
section Bezout
variable [IsBezout R]
theorem isCoprime_of_dvd (x y : R) (nonzero : ¬(x = 0 ∧ y = 0))
(H : ∀ z ∈ nonunits R, z ≠ 0 → z ∣ x → ¬z ∣ y) : IsCoprime x y :=
(isRelPrime_of_no_nonunits_factors nonzero H).isCoprime
theorem dvd_or_isCoprime (x y : R) (h : Irreducible x) : x ∣ y ∨ IsCoprime x y :=
h.dvd_or_isRelPrime.imp_right IsRelPrime.isCoprime
/-- See also `Irreducible.isRelPrime_iff_not_dvd`. -/
theorem Irreducible.coprime_iff_not_dvd {p n : R} (hp : Irreducible p) :
IsCoprime p n ↔ ¬p ∣ n := by rw [← isRelPrime_iff_isCoprime, hp.isRelPrime_iff_not_dvd]
/-- See also `Irreducible.coprime_iff_not_dvd'`. -/
theorem Irreducible.dvd_iff_not_isCoprime {p n : R} (hp : Irreducible p) : p ∣ n ↔ ¬IsCoprime p n :=
iff_not_comm.2 hp.coprime_iff_not_dvd
theorem Irreducible.coprime_pow_of_not_dvd {p a : R} (m : ℕ) (hp : Irreducible p) (h : ¬p ∣ a) :
IsCoprime a (p ^ m) :=
(hp.coprime_iff_not_dvd.2 h).symm.pow_right
theorem Irreducible.isCoprime_or_dvd {p : R} (hp : Irreducible p) (i : R) : IsCoprime p i ∨ p ∣ i :=
(_root_.em _).imp_right hp.dvd_iff_not_isCoprime.2
variable [IsDomain R]
section GCD
variable [GCDMonoid R]
theorem IsBezout.span_gcd_eq_span_gcd (x y : R) :
span {GCDMonoid.gcd x y} = span {IsBezout.gcd x y} := by
rw [Ideal.span_singleton_eq_span_singleton]
exact associated_of_dvd_dvd
(IsBezout.dvd_gcd (GCDMonoid.gcd_dvd_left _ _) <| GCDMonoid.gcd_dvd_right _ _)
(GCDMonoid.dvd_gcd (IsBezout.gcd_dvd_left _ _) <| IsBezout.gcd_dvd_right _ _)
theorem span_gcd (x y : R) : span {gcd x y} = span {x, y} := by
rw [← IsBezout.span_gcd, IsBezout.span_gcd_eq_span_gcd]
theorem gcd_dvd_iff_exists (a b : R) {z} : gcd a b ∣ z ↔ ∃ x y, z = a * x + b * y := by
simp_rw [mul_comm a, mul_comm b, @eq_comm _ z, ← Ideal.mem_span_pair, ← span_gcd,
Ideal.mem_span_singleton]
/-- **Bézout's lemma** -/
theorem exists_gcd_eq_mul_add_mul (a b : R) : ∃ x y, gcd a b = a * x + b * y := by
rw [← gcd_dvd_iff_exists]
theorem gcd_isUnit_iff (x y : R) : IsUnit (gcd x y) ↔ IsCoprime x y := by
rw [IsCoprime, ← Ideal.mem_span_pair, ← span_gcd, ← span_singleton_eq_top, eq_top_iff_one]
end GCD
theorem Prime.coprime_iff_not_dvd {p n : R} (hp : Prime p) : IsCoprime p n ↔ ¬p ∣ n :=
hp.irreducible.coprime_iff_not_dvd
theorem exists_associated_pow_of_mul_eq_pow' {a b c : R} (hab : IsCoprime a b) {k : ℕ}
(h : a * b = c ^ k) : ∃ d : R, Associated (d ^ k) a := by
classical
letI := IsBezout.toGCDDomain R
exact exists_associated_pow_of_mul_eq_pow ((gcd_isUnit_iff _ _).mpr hab) h
theorem exists_associated_pow_of_associated_pow_mul {a b c : R} (hab : IsCoprime a b) {k : ℕ}
(h : Associated (c ^ k) (a * b)) : ∃ d : R, Associated (d ^ k) a := by
obtain ⟨u, hu⟩ := h.symm
exact exists_associated_pow_of_mul_eq_pow'
((isCoprime_mul_unit_right_right u.isUnit a b).mpr hab) <| mul_assoc a _ _ ▸ hu
end Bezout
variable [IsDomain R] [IsPrincipalIdealRing R]
theorem isCoprime_of_irreducible_dvd {x y : R} (nonzero : ¬(x = 0 ∧ y = 0))
(H : ∀ z : R, Irreducible z → z ∣ x → ¬z ∣ y) : IsCoprime x y :=
(WfDvdMonoid.isRelPrime_of_no_irreducible_factors nonzero H).isCoprime
theorem isCoprime_of_prime_dvd {x y : R} (nonzero : ¬(x = 0 ∧ y = 0))
(H : ∀ z : R, Prime z → z ∣ x → ¬z ∣ y) : IsCoprime x y :=
isCoprime_of_irreducible_dvd nonzero fun z zi ↦ H z zi.prime
end
section PrincipalOfPrime
open Set Ideal
variable (R) [CommRing R]
/-- `nonPrincipals R` is the set of all ideals of `R` that are not principal ideals. -/
def nonPrincipals :=
{ I : Ideal R | ¬I.IsPrincipal }
theorem nonPrincipals_def {I : Ideal R} : I ∈ nonPrincipals R ↔ ¬I.IsPrincipal :=
Iff.rfl
variable {R}
theorem nonPrincipals_eq_empty_iff : nonPrincipals R = ∅ ↔ IsPrincipalIdealRing R := by
simp [Set.eq_empty_iff_forall_notMem, isPrincipalIdealRing_iff, nonPrincipals_def]
/-- Any chain in the set of non-principal ideals has an upper bound which is non-principal.
(Namely, the union of the chain is such an upper bound.)
-/
theorem nonPrincipals_zorn (c : Set (Ideal R)) (hs : c ⊆ nonPrincipals R)
(hchain : IsChain (· ≤ ·) c) {K : Ideal R} (hKmem : K ∈ c) :
∃ I ∈ nonPrincipals R, ∀ J ∈ c, J ≤ I := by
refine ⟨sSup c, ?_, fun J hJ => le_sSup hJ⟩
rintro ⟨x, hx⟩
have hxmem : x ∈ sSup c := hx.symm ▸ Submodule.mem_span_singleton_self x
obtain ⟨J, hJc, hxJ⟩ := (Submodule.mem_sSup_of_directed ⟨K, hKmem⟩ hchain.directedOn).1 hxmem
have hsSupJ : sSup c = J := le_antisymm (by simp [hx, Ideal.span_le, hxJ]) (le_sSup hJc)
specialize hs hJc
rw [← hsSupJ, hx, nonPrincipals_def] at hs
exact hs ⟨⟨x, rfl⟩⟩
end PrincipalOfPrime
|
Int.lean
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Basic
import Mathlib.Topology.Instances.Int
/-! # ℤ as a normed group -/
open NNReal
variable {α : Type*}
namespace Int
instance instNormedAddCommGroup : NormedAddCommGroup ℤ where
norm n := ‖(n : ℝ)‖
dist_eq m n := by simp only [Int.dist_eq, norm, Int.cast_sub]
@[norm_cast]
theorem norm_cast_real (m : ℤ) : ‖(m : ℝ)‖ = ‖m‖ :=
rfl
theorem norm_eq_abs (n : ℤ) : ‖n‖ = |(n : ℝ)| :=
rfl
@[simp]
theorem norm_natCast (n : ℕ) : ‖(n : ℤ)‖ = n := by simp [Int.norm_eq_abs]
theorem _root_.NNReal.natCast_natAbs (n : ℤ) : (n.natAbs : ℝ≥0) = ‖n‖₊ :=
NNReal.eq <|
calc
((n.natAbs : ℝ≥0) : ℝ) = (n.natAbs : ℤ) := by simp only [Int.cast_natCast, NNReal.coe_natCast]
_ = |(n : ℝ)| := by simp only [Int.natCast_natAbs, Int.cast_abs]
_ = ‖n‖ := (norm_eq_abs n).symm
theorem abs_le_floor_nnreal_iff (z : ℤ) (c : ℝ≥0) : |z| ≤ ⌊c⌋₊ ↔ ‖z‖₊ ≤ c := by
rw [Int.abs_eq_natAbs, Int.ofNat_le, Nat.le_floor_iff (zero_le c), NNReal.natCast_natAbs z]
end Int
-- Now that we've installed the norm on `ℤ`,
-- we can state some lemmas about `zsmul`.
section
variable [SeminormedCommGroup α]
@[to_additive norm_zsmul_le]
theorem norm_zpow_le_mul_norm (n : ℤ) (a : α) : ‖a ^ n‖ ≤ ‖n‖ * ‖a‖ := by
rcases n.eq_nat_or_neg with ⟨n, rfl | rfl⟩ <;> simpa using norm_pow_le_mul_norm
@[to_additive nnnorm_zsmul_le]
theorem nnnorm_zpow_le_mul_norm (n : ℤ) (a : α) : ‖a ^ n‖₊ ≤ ‖n‖₊ * ‖a‖₊ := by
simpa only [← NNReal.coe_le_coe, NNReal.coe_mul] using norm_zpow_le_mul_norm n a
end
|
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.
|
SheafComparison.lean
|
/-
Copyright (c) 2024 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.CategoryTheory.Sites.Coherent.Comparison
import Mathlib.CategoryTheory.Sites.Coherent.ExtensiveSheaves
import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPrecoherent
import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPreregular
import Mathlib.CategoryTheory.Sites.DenseSubsite.InducedTopology
import Mathlib.CategoryTheory.Sites.Whiskering
/-!
# Categories of coherent sheaves
Given a fully faithful functor `F : C ⥤ D` into a precoherent category, which preserves and reflects
finite effective epi families, and satisfies the property `F.EffectivelyEnough` (meaning that to
every object in `C` there is an effective epi from an object in the image of `F`), the categories
of coherent sheaves on `C` and `D` are equivalent (see
`CategoryTheory.coherentTopology.equivalence`).
The main application of this equivalence is the characterisation of condensed sets as coherent
sheaves on either `CompHaus`, `Profinite` or `Stonean`. See the file `Condensed/Equivalence.lean`
We give the corresponding result for the regular topology as well (see
`CategoryTheory.regularTopology.equivalence`).
-/
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace CategoryTheory
open Limits Functor regularTopology
variable {C D : Type*} [Category C] [Category D] (F : C ⥤ D)
namespace coherentTopology
variable [F.PreservesFiniteEffectiveEpiFamilies] [F.ReflectsFiniteEffectiveEpiFamilies]
[F.Full] [F.Faithful] [F.EffectivelyEnough] [Precoherent D]
instance : F.IsCoverDense (coherentTopology _) := by
refine F.isCoverDense_of_generate_singleton_functor_π_mem _ fun B ↦ ⟨_, F.effectiveEpiOver B, ?_⟩
apply Coverage.Saturate.of
refine ⟨Unit, inferInstance, fun _ => F.effectiveEpiOverObj B,
fun _ => F.effectiveEpiOver B, ?_ , ?_⟩
· funext; ext -- Do we want `Presieve.ext`?
refine ⟨fun ⟨⟩ ↦ ⟨()⟩, ?_⟩
rintro ⟨⟩
simp
· rw [← effectiveEpi_iff_effectiveEpiFamily]
infer_instance
theorem exists_effectiveEpiFamily_iff_mem_induced (X : C) (S : Sieve X) :
(∃ (α : Type) (_ : Finite α) (Y : α → C) (π : (a : α) → (Y a ⟶ X)),
EffectiveEpiFamily Y π ∧ (∀ a : α, (S.arrows) (π a)) ) ↔
(S ∈ F.inducedTopology (coherentTopology _) X) := by
refine ⟨fun ⟨α, _, Y, π, ⟨H₁, H₂⟩⟩ ↦ ?_, fun hS ↦ ?_⟩
· apply (mem_sieves_iff_hasEffectiveEpiFamily (Sieve.functorPushforward _ S)).mpr
refine ⟨α, inferInstance, fun i => F.obj (Y i),
fun i => F.map (π i), ⟨?_,
fun a => Sieve.image_mem_functorPushforward F S (H₂ a)⟩⟩
exact F.map_finite_effectiveEpiFamily _ _
· obtain ⟨α, _, Y, π, ⟨H₁, H₂⟩⟩ := (mem_sieves_iff_hasEffectiveEpiFamily _).mp hS
refine ⟨α, inferInstance, ?_⟩
let Z : α → C := fun a ↦ (Functor.EffectivelyEnough.presentation (F := F) (Y a)).some.p
let g₀ : (a : α) → F.obj (Z a) ⟶ Y a := fun a ↦ F.effectiveEpiOver (Y a)
have : EffectiveEpiFamily _ (fun a ↦ g₀ a ≫ π a) := inferInstance
refine ⟨Z , fun a ↦ F.preimage (g₀ a ≫ π a), ?_, fun a ↦ (?_ : S.arrows (F.preimage _))⟩
· refine F.finite_effectiveEpiFamily_of_map _ _ ?_
simpa using this
· obtain ⟨W, g₁, g₂, h₁, h₂⟩ := H₂ a
rw [h₂]
convert S.downward_closed h₁ (F.preimage (g₀ a ≫ g₂))
exact F.map_injective (by simp)
lemma eq_induced : haveI := F.reflects_precoherent
coherentTopology C =
F.inducedTopology (coherentTopology _) := by
ext X S
have := F.reflects_precoherent
rw [← exists_effectiveEpiFamily_iff_mem_induced F X]
rw [← coherentTopology.mem_sieves_iff_hasEffectiveEpiFamily S]
instance : haveI := F.reflects_precoherent;
F.IsDenseSubsite (coherentTopology C) (coherentTopology D) where
functorPushforward_mem_iff := by
rw [eq_induced F]
rfl
lemma coverPreserving : haveI := F.reflects_precoherent
CoverPreserving (coherentTopology _) (coherentTopology _) F :=
IsDenseSubsite.coverPreserving _ _ _
section SheafEquiv
variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (F : C ⥤ D)
[F.PreservesFiniteEffectiveEpiFamilies] [F.ReflectsFiniteEffectiveEpiFamilies]
[F.Full] [F.Faithful]
[Precoherent D]
[F.EffectivelyEnough]
/--
The equivalence from coherent sheaves on `C` to coherent sheaves on `D`, given a fully faithful
functor `F : C ⥤ D` to a precoherent category, which preserves and reflects effective epimorphic
families, and satisfies `F.EffectivelyEnough`.
-/
noncomputable
def equivalence (A : Type u₃) [Category.{v₃} A] [∀ X, HasLimitsOfShape (StructuredArrow X F.op) A] :
haveI := F.reflects_precoherent
Sheaf (coherentTopology C) A ≌ Sheaf (coherentTopology D) A :=
Functor.IsDenseSubsite.sheafEquiv F _ _ _
end SheafEquiv
section RegularExtensive
variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (F : C ⥤ D)
[F.PreservesEffectiveEpis] [F.ReflectsEffectiveEpis]
[F.Full] [F.Faithful]
[FinitaryExtensive D] [Preregular D]
[FinitaryPreExtensive C]
[PreservesFiniteCoproducts F]
[F.EffectivelyEnough]
/--
The equivalence from coherent sheaves on `C` to coherent sheaves on `D`, given a fully faithful
functor `F : C ⥤ D` to an extensive preregular category, which preserves and reflects effective
epimorphisms and satisfies `F.EffectivelyEnough`.
-/
noncomputable
def equivalence' (A : Type u₃) [Category.{v₃} A]
[∀ X, HasLimitsOfShape (StructuredArrow X F.op) A] :
haveI := F.reflects_precoherent
Sheaf (coherentTopology C) A ≌ Sheaf (coherentTopology D) A :=
Functor.IsDenseSubsite.sheafEquiv F _ _ _
end RegularExtensive
end coherentTopology
namespace regularTopology
variable [F.PreservesEffectiveEpis] [F.ReflectsEffectiveEpis] [F.Full] [F.Faithful]
[F.EffectivelyEnough] [Preregular D]
instance : F.IsCoverDense (regularTopology _) := by
refine F.isCoverDense_of_generate_singleton_functor_π_mem _ fun B ↦ ⟨_, F.effectiveEpiOver B, ?_⟩
apply Coverage.Saturate.of
refine ⟨F.effectiveEpiOverObj B, F.effectiveEpiOver B, ?_, inferInstance⟩
funext; ext -- Do we want `Presieve.ext`?
refine ⟨fun ⟨⟩ ↦ ⟨()⟩, ?_⟩
rintro ⟨⟩
simp
theorem exists_effectiveEpi_iff_mem_induced (X : C) (S : Sieve X) :
(∃ (Y : C) (π : Y ⟶ X),
EffectiveEpi π ∧ S.arrows π) ↔
(S ∈ F.inducedTopology (regularTopology _) X) := by
refine ⟨fun ⟨Y, π, ⟨H₁, H₂⟩⟩ ↦ ?_, fun hS ↦ ?_⟩
· apply (mem_sieves_iff_hasEffectiveEpi (Sieve.functorPushforward _ S)).mpr
refine ⟨F.obj Y, F.map π, ⟨?_, Sieve.image_mem_functorPushforward F S H₂⟩⟩
exact F.map_effectiveEpi _
· obtain ⟨Y, π, ⟨H₁, H₂⟩⟩ := (mem_sieves_iff_hasEffectiveEpi _).mp hS
let g₀ := F.effectiveEpiOver Y
refine ⟨_, F.preimage (g₀ ≫ π), ?_, (?_ : S.arrows (F.preimage _))⟩
· refine F.effectiveEpi_of_map _ ?_
simp only [map_preimage]
infer_instance
· obtain ⟨W, g₁, g₂, h₁, h₂⟩ := H₂
rw [h₂]
convert S.downward_closed h₁ (F.preimage (g₀ ≫ g₂))
exact F.map_injective (by simp)
lemma eq_induced : haveI := F.reflects_preregular
regularTopology C =
F.inducedTopology (regularTopology _) := by
ext X S
have := F.reflects_preregular
rw [← exists_effectiveEpi_iff_mem_induced F X]
rw [← mem_sieves_iff_hasEffectiveEpi S]
instance : haveI := F.reflects_preregular;
F.IsDenseSubsite (regularTopology C) (regularTopology D) where
functorPushforward_mem_iff := by
rw [eq_induced F]
rfl
lemma coverPreserving : haveI := F.reflects_preregular
CoverPreserving (regularTopology _) (regularTopology _) F :=
IsDenseSubsite.coverPreserving _ _ _
section SheafEquiv
variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (F : C ⥤ D)
[F.PreservesEffectiveEpis] [F.ReflectsEffectiveEpis]
[F.Full] [F.Faithful]
[Preregular D]
[F.EffectivelyEnough]
/--
The equivalence from regular sheaves on `C` to regular sheaves on `D`, given a fully faithful
functor `F : C ⥤ D` to a preregular category, which preserves and reflects effective
epimorphisms and satisfies `F.EffectivelyEnough`.
-/
noncomputable
def equivalence (A : Type u₃) [Category.{v₃} A] [∀ X, HasLimitsOfShape (StructuredArrow X F.op) A] :
haveI := F.reflects_preregular
Sheaf (regularTopology C) A ≌ Sheaf (regularTopology D) A :=
Functor.IsDenseSubsite.sheafEquiv F _ _ _
end SheafEquiv
end regularTopology
namespace Presheaf
variable {A : Type u₃} [Category.{v₃} A] (F : Cᵒᵖ ⥤ A)
theorem isSheaf_coherent_iff_regular_and_extensive [Preregular C] [FinitaryPreExtensive C] :
IsSheaf (coherentTopology C) F ↔
IsSheaf (extensiveTopology C) F ∧ IsSheaf (regularTopology C) F := by
rw [← extensive_regular_generate_coherent]
exact isSheaf_sup (extensiveCoverage C) (regularCoverage C) F
theorem isSheaf_iff_preservesFiniteProducts_and_equalizerCondition
[Preregular C] [FinitaryExtensive C]
[h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] :
IsSheaf (coherentTopology C) F ↔ PreservesFiniteProducts F ∧
EqualizerCondition F := by
rw [isSheaf_coherent_iff_regular_and_extensive]
exact and_congr (isSheaf_iff_preservesFiniteProducts _)
(@equalizerCondition_iff_isSheaf _ _ _ _ F _ h).symm
noncomputable instance [Preregular C] [FinitaryExtensive C]
(F : Sheaf (coherentTopology C) A) : PreservesFiniteProducts F.val :=
(Presheaf.isSheaf_iff_preservesFiniteProducts F.val).1
((Presheaf.isSheaf_coherent_iff_regular_and_extensive F.val).mp F.cond).1
theorem isSheaf_iff_preservesFiniteProducts_of_projective [Preregular C] [FinitaryExtensive C]
[∀ (X : C), Projective X] :
IsSheaf (coherentTopology C) F ↔ PreservesFiniteProducts F := by
rw [isSheaf_coherent_iff_regular_and_extensive, and_iff_left (isSheaf_of_projective F),
isSheaf_iff_preservesFiniteProducts]
theorem isSheaf_iff_extensiveSheaf_of_projective [Preregular C] [FinitaryExtensive C]
[∀ (X : C), Projective X] :
IsSheaf (coherentTopology C) F ↔ IsSheaf (extensiveTopology C) F := by
rw [isSheaf_iff_preservesFiniteProducts_of_projective, isSheaf_iff_preservesFiniteProducts]
/--
The categories of coherent sheaves and extensive sheaves on `C` are equivalent if `C` is
preregular, finitary extensive, and every object is projective.
-/
@[simps]
def coherentExtensiveEquivalence [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X] :
Sheaf (coherentTopology C) A ≌ Sheaf (extensiveTopology C) A where
functor := {
obj := fun F ↦ ⟨F.val, (isSheaf_iff_extensiveSheaf_of_projective F.val).mp F.cond⟩
map := fun f ↦ ⟨f.val⟩ }
inverse := {
obj := fun F ↦ ⟨F.val, (isSheaf_iff_extensiveSheaf_of_projective F.val).mpr F.cond⟩
map := fun f ↦ ⟨f.val⟩ }
unitIso := Iso.refl _
counitIso := Iso.refl _
variable {B : Type u₄} [Category.{v₄} B]
variable (s : A ⥤ B)
lemma isSheaf_coherent_of_hasPullbacks_comp [Preregular C] [FinitaryExtensive C]
[h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f] [PreservesFiniteLimits s]
(hF : IsSheaf (coherentTopology C) F) : IsSheaf (coherentTopology C) (F ⋙ s) := by
rw [isSheaf_iff_preservesFiniteProducts_and_equalizerCondition (h := h)] at hF ⊢
have := hF.1
refine ⟨inferInstance, fun _ _ π _ c hc ↦ ⟨?_⟩⟩
exact isLimitForkMapOfIsLimit s _ (hF.2 π c hc).some
lemma isSheaf_coherent_of_hasPullbacks_of_comp [Preregular C] [FinitaryExtensive C]
[h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f]
[ReflectsFiniteLimits s]
(hF : IsSheaf (coherentTopology C) (F ⋙ s)) : IsSheaf (coherentTopology C) F := by
rw [isSheaf_iff_preservesFiniteProducts_and_equalizerCondition (h := h)] at hF ⊢
obtain ⟨_, hF₂⟩ := hF
refine ⟨⟨fun n ↦ ⟨fun {K} ↦ ⟨fun {c} hc ↦ ?_⟩⟩⟩, fun _ _ π _ c hc ↦ ⟨?_⟩⟩
· exact ⟨isLimitOfReflects s (isLimitOfPreserves (F ⋙ s) hc)⟩
· exact isLimitOfIsLimitForkMap s _ (hF₂ π c hc).some
lemma isSheaf_coherent_of_projective_comp [Preregular C] [FinitaryExtensive C]
[∀ (X : C), Projective X] [PreservesFiniteProducts s]
(hF : IsSheaf (coherentTopology C) F) : IsSheaf (coherentTopology C) (F ⋙ s) := by
rw [isSheaf_iff_preservesFiniteProducts_of_projective] at hF ⊢
infer_instance
lemma isSheaf_coherent_of_projective_of_comp [Preregular C] [FinitaryExtensive C]
[∀ (X : C), Projective X]
[ReflectsFiniteProducts s]
(hF : IsSheaf (coherentTopology C) (F ⋙ s)) : IsSheaf (coherentTopology C) F := by
rw [isSheaf_iff_preservesFiniteProducts_of_projective] at hF ⊢
exact ⟨fun n ↦ ⟨fun {K} ↦ ⟨fun {c} hc ↦ ⟨isLimitOfReflects s (isLimitOfPreserves (F ⋙ s) hc)⟩⟩⟩⟩
instance [Preregular C] [FinitaryExtensive C]
[h : ∀ {Y X : C} (f : Y ⟶ X) [EffectiveEpi f], HasPullback f f]
[PreservesFiniteLimits s] : (coherentTopology C).HasSheafCompose s where
isSheaf F hF := isSheaf_coherent_of_hasPullbacks_comp (h := h) F s hF
instance [Preregular C] [FinitaryExtensive C] [∀ (X : C), Projective X]
[PreservesFiniteProducts s] : (coherentTopology C).HasSheafCompose s where
isSheaf F hF := isSheaf_coherent_of_projective_comp F s hF
end CategoryTheory.Presheaf
|
LpEquiv.lean
|
/-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Analysis.Normed.Lp.PiLp
import Mathlib.Analysis.Normed.Lp.lpSpace
import Mathlib.Topology.ContinuousMap.Bounded.Normed
/-!
# Equivalences among $L^p$ spaces
In this file we collect a variety of equivalences among various $L^p$ spaces. In particular,
when `α` is a `Fintype`, given `E : α → Type u` and `p : ℝ≥0∞`, there is a natural linear isometric
equivalence `lpPiLpₗᵢₓ : lp E p ≃ₗᵢ PiLp p E`. In addition, when `α` is a discrete topological
space, the bounded continuous functions `α →ᵇ β` correspond exactly to `lp (fun _ ↦ β) ∞`.
Here there can be more structure, including ring and algebra structures,
and we implement these equivalences accordingly as well.
We keep this as a separate file so that the various $L^p$ space files don't import the others.
Recall that `PiLp` is just a type synonym for `Π i, E i` but given a different metric and norm
structure, although the topological, uniform and bornological structures coincide definitionally.
These structures are only defined on `PiLp` for `Fintype α`, so there are no issues of convergence
to consider.
While `PreLp` is also a type synonym for `Π i, E i`, it allows for infinite index types. On this
type there is a predicate `Memℓp` which says that the relevant `p`-norm is finite and `lp E p` is
the subtype of `PreLp` satisfying `Memℓp`.
## TODO
* Equivalence between `lp` and `MeasureTheory.Lp`, for `f : α → E` (i.e., functions rather than
pi-types) and the counting measure on `α`
-/
open scoped ENNReal
section LpPiLp
variable {α : Type*} {E : α → Type*} [∀ i, NormedAddCommGroup (E i)] {p : ℝ≥0∞}
section Finite
variable [Finite α]
/-- When `α` is `Finite`, every `f : PreLp E p` satisfies `Memℓp f p`. -/
theorem Memℓp.all (f : ∀ i, E i) : Memℓp f p := by
rcases p.trichotomy with (rfl | rfl | _h)
· exact memℓp_zero_iff.mpr { i : α | f i ≠ 0 }.toFinite
· exact memℓp_infty_iff.mpr (Set.Finite.bddAbove (Set.range fun i : α ↦ ‖f i‖).toFinite)
· cases nonempty_fintype α; exact memℓp_gen ⟨Finset.univ.sum _, hasSum_fintype _⟩
/-- The canonical `Equiv` between `lp E p ≃ PiLp p E` when `E : α → Type u` with `[Finite α]`. -/
def Equiv.lpPiLp : lp E p ≃ PiLp p E where
toFun f := ⇑f
invFun f := ⟨f, Memℓp.all f⟩
theorem coe_equiv_lpPiLp (f : lp E p) : Equiv.lpPiLp f = ⇑f :=
rfl
theorem coe_equiv_lpPiLp_symm (f : PiLp p E) : (Equiv.lpPiLp.symm f : ∀ i, E i) = f :=
rfl
/-- The canonical `AddEquiv` between `lp E p` and `PiLp p E` when `E : α → Type u` with
`[Fintype α]`. -/
def AddEquiv.lpPiLp : lp E p ≃+ PiLp p E :=
{ Equiv.lpPiLp with map_add' := fun _f _g ↦ rfl }
theorem coe_addEquiv_lpPiLp (f : lp E p) : AddEquiv.lpPiLp f = ⇑f :=
rfl
theorem coe_addEquiv_lpPiLp_symm (f : PiLp p E) :
(AddEquiv.lpPiLp.symm f : ∀ i, E i) = f :=
rfl
end Finite
theorem equiv_lpPiLp_norm [Fintype α] (f : lp E p) : ‖Equiv.lpPiLp f‖ = ‖f‖ := by
rcases p.trichotomy with (rfl | rfl | h)
· simp [Equiv.lpPiLp, PiLp.norm_eq_card, lp.norm_eq_card_dsupport]
· rw [PiLp.norm_eq_ciSup, lp.norm_eq_ciSup]; rfl
· rw [PiLp.norm_eq_sum h, lp.norm_eq_tsum_rpow h, tsum_fintype]; rfl
section Equivₗᵢ
variable [Fintype α] (𝕜 : Type*) [NontriviallyNormedField 𝕜] [∀ i, NormedSpace 𝕜 (E i)]
variable (E)
/-- The canonical `LinearIsometryEquiv` between `lp E p` and `PiLp p E` when `E : α → Type u`
with `[Fintype α]` and `[Fact (1 ≤ p)]`. -/
noncomputable def lpPiLpₗᵢ [Fact (1 ≤ p)] : lp E p ≃ₗᵢ[𝕜] PiLp p E :=
{ AddEquiv.lpPiLp with
map_smul' := fun _k _f ↦ rfl
norm_map' := equiv_lpPiLp_norm }
variable {𝕜 E}
theorem coe_lpPiLpₗᵢ [Fact (1 ≤ p)] (f : lp E p) : (lpPiLpₗᵢ E 𝕜 f : ∀ i, E i) = ⇑f :=
rfl
theorem coe_lpPiLpₗᵢ_symm [Fact (1 ≤ p)] (f : PiLp p E) :
((lpPiLpₗᵢ E 𝕜).symm f : ∀ i, E i) = f :=
rfl
end Equivₗᵢ
end LpPiLp
section LpBCF
open scoped BoundedContinuousFunction
open BoundedContinuousFunction
-- note: `R` and `A` are explicit because otherwise Lean has elaboration problems
variable {α E : Type*} (R A 𝕜 : Type*) [TopologicalSpace α] [DiscreteTopology α]
variable [NormedRing A] [NormOneClass A] [NontriviallyNormedField 𝕜] [NormedAlgebra 𝕜 A]
variable [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NonUnitalNormedRing R]
section NormedAddCommGroup
/-- The canonical map between `lp (fun _ : α ↦ E) ∞` and `α →ᵇ E` as an `AddEquiv`. -/
noncomputable def AddEquiv.lpBCF : lp (fun _ : α ↦ E) ∞ ≃+ (α →ᵇ E) where
toFun f := ofNormedAddCommGroupDiscrete f ‖f‖ <| le_ciSup (memℓp_infty_iff.mp f.prop)
invFun f := ⟨⇑f, f.bddAbove_range_norm_comp⟩
map_add' _f _g := rfl
theorem coe_addEquiv_lpBCF (f : lp (fun _ : α ↦ E) ∞) : (AddEquiv.lpBCF f : α → E) = f :=
rfl
theorem coe_addEquiv_lpBCF_symm (f : α →ᵇ E) : (AddEquiv.lpBCF.symm f : α → E) = f :=
rfl
variable (E)
/-- The canonical map between `lp (fun _ : α ↦ E) ∞` and `α →ᵇ E` as a `LinearIsometryEquiv`. -/
noncomputable def lpBCFₗᵢ : lp (fun _ : α ↦ E) ∞ ≃ₗᵢ[𝕜] α →ᵇ E :=
{ AddEquiv.lpBCF with
map_smul' := fun _ _ ↦ rfl
norm_map' := fun f ↦ by simp only [norm_eq_iSup_norm, lp.norm_eq_ciSup]; rfl }
variable {𝕜 E}
theorem coe_lpBCFₗᵢ (f : lp (fun _ : α ↦ E) ∞) : (lpBCFₗᵢ E 𝕜 f : α → E) = f :=
rfl
theorem coe_lpBCFₗᵢ_symm (f : α →ᵇ E) : ((lpBCFₗᵢ E 𝕜).symm f : α → E) = f :=
rfl
end NormedAddCommGroup
section RingAlgebra
/-- The canonical map between `lp (fun _ : α ↦ R) ∞` and `α →ᵇ R` as a `RingEquiv`. -/
noncomputable def RingEquiv.lpBCF : lp (fun _ : α ↦ R) ∞ ≃+* (α →ᵇ R) :=
{ @AddEquiv.lpBCF _ R _ _ _ with
map_mul' := fun _f _g => rfl }
variable {R}
theorem coe_ringEquiv_lpBCF (f : lp (fun _ : α ↦ R) ∞) : (RingEquiv.lpBCF R f : α → R) = f :=
rfl
theorem coe_ringEquiv_lpBCF_symm (f : α →ᵇ R) : ((RingEquiv.lpBCF R).symm f : α → R) = f :=
rfl
variable (α)
-- even `α` needs to be explicit here for elaboration
-- the `NormOneClass A` shouldn't really be necessary, but currently it is for
-- `one_memℓp_infty` to get the `Ring` instance on `lp`.
/-- The canonical map between `lp (fun _ : α ↦ A) ∞` and `α →ᵇ A` as an `AlgEquiv`. -/
noncomputable def AlgEquiv.lpBCF : lp (fun _ : α ↦ A) ∞ ≃ₐ[𝕜] α →ᵇ A :=
{ RingEquiv.lpBCF A with commutes' := fun _k ↦ rfl }
variable {α A 𝕜}
theorem coe_algEquiv_lpBCF (f : lp (fun _ : α ↦ A) ∞) : (AlgEquiv.lpBCF α A 𝕜 f : α → A) = f :=
rfl
theorem coe_algEquiv_lpBCF_symm (f : α →ᵇ A) : ((AlgEquiv.lpBCF α A 𝕜).symm f : α → A) = f :=
rfl
end RingAlgebra
end LpBCF
|
RenameBVar.lean
|
/-
Copyright (c) 2019 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Arthur Paulino, Patrick Massot
-/
import Lean.Elab.Tactic.Location
import Mathlib.Util.Tactic
import Mathlib.Lean.Expr.Basic
/-!
# The `rename_bvar` tactic
This file defines the `rename_bvar` tactic, for renaming bound variables.
-/
namespace Mathlib.Tactic
open Lean Parser Elab Tactic
/-- Renames a bound variable in a hypothesis. -/
def renameBVarHyp (mvarId : MVarId) (fvarId : FVarId) (old new : Name) :
MetaM Unit :=
modifyLocalDecl mvarId fvarId fun ldecl ↦
ldecl.setType <| ldecl.type.renameBVar old new
/-- Renames a bound variable in the target. -/
def renameBVarTarget (mvarId : MVarId) (old new : Name) : MetaM Unit :=
modifyTarget mvarId fun e ↦ e.renameBVar old new
/--
* `rename_bvar old → new` renames all bound variables named `old` to `new` in the target.
* `rename_bvar old → new at h` does the same in hypothesis `h`.
```lean
example (P : ℕ → ℕ → Prop) (h : ∀ n, ∃ m, P n m) : ∀ l, ∃ m, P l m := by
rename_bvar n → q at h -- h is now ∀ (q : ℕ), ∃ (m : ℕ), P q m,
rename_bvar m → n -- target is now ∀ (l : ℕ), ∃ (n : ℕ), P k n,
exact h -- Lean does not care about those bound variable names
```
Note: name clashes are resolved automatically.
-/
elab "rename_bvar " old:ident " → " new:ident loc?:(location)? : tactic => do
let mvarId ← getMainGoal
instantiateMVarDeclMVars mvarId
match loc? with
| none => renameBVarTarget mvarId old.getId new.getId
| some loc =>
withLocation (expandLocation loc)
(fun fvarId ↦ renameBVarHyp mvarId fvarId old.getId new.getId)
(renameBVarTarget mvarId old.getId new.getId)
fun _ ↦ throwError "unexpected location syntax"
end Mathlib.Tactic
|
IsLocallyClosed.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.Topology.Order.OrderClosed
import Mathlib.Topology.LocallyClosed
/-!
# Intervals are locally closed
We prove that the intervals on a topological ordered space are locally closed.
-/
variable {X : Type*} [TopologicalSpace X] {a b : X}
theorem isLocallyClosed_Icc [Preorder X] [OrderClosedTopology X] :
IsLocallyClosed (Set.Icc a b) :=
isClosed_Icc.isLocallyClosed
theorem isLocallyClosed_Ioo [LinearOrder X] [OrderClosedTopology X] :
IsLocallyClosed (Set.Ioo a b) :=
isOpen_Ioo.isLocallyClosed
theorem isLocallyClosed_Ici [Preorder X] [ClosedIciTopology X] :
IsLocallyClosed (Set.Ici a) :=
isClosed_Ici.isLocallyClosed
theorem isLocallyClosed_Iic [Preorder X] [ClosedIicTopology X] :
IsLocallyClosed (Set.Iic a) :=
isClosed_Iic.isLocallyClosed
theorem isLocallyClosed_Ioi [LinearOrder X] [ClosedIicTopology X] :
IsLocallyClosed (Set.Ioi a) :=
isOpen_Ioi.isLocallyClosed
theorem isLocallyClosed_Iio [LinearOrder X] [ClosedIciTopology X] :
IsLocallyClosed (Set.Iio a) :=
isOpen_Iio.isLocallyClosed
theorem isLocallyClosed_Ioc [LinearOrder X] [ClosedIicTopology X] :
IsLocallyClosed (Set.Ioc a b) := by
rw [← Set.Iic_inter_Ioi]
exact isLocallyClosed_Iic.inter isLocallyClosed_Ioi
theorem isLocallyClosed_Ico [LinearOrder X] [ClosedIciTopology X] :
IsLocallyClosed (Set.Ico a b) := by
rw [← Set.Iio_inter_Ici]
exact isLocallyClosed_Iio.inter isLocallyClosed_Ici
|
Matrix.lean
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash, Eric Wieser
-/
import Mathlib.Topology.Algebra.InfiniteSum.Basic
import Mathlib.Topology.Algebra.Ring.Basic
import Mathlib.Topology.Algebra.Star
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Trace
/-!
# Topological properties of matrices
This file is a place to collect topological results about matrices.
## Main definitions:
* `Matrix.topologicalRing`: square matrices form a topological ring
## Main results
* Sets of matrices:
* `IsOpen.matrix`: the set of finite matrices with entries in an open set
is itself an open set.
* `IsCompact.matrix`: the set of matrices with entries in a compact set
is itself a compact set.
* Continuity:
* `Continuous.matrix_det`: the determinant is continuous over a topological ring.
* `Continuous.matrix_adjugate`: the adjugate is continuous over a topological ring.
* Infinite sums
* `Matrix.transpose_tsum`: transpose commutes with infinite sums
* `Matrix.diagonal_tsum`: diagonal commutes with infinite sums
* `Matrix.blockDiagonal_tsum`: block diagonal commutes with infinite sums
* `Matrix.blockDiagonal'_tsum`: non-uniform block diagonal commutes with infinite sums
-/
open Matrix
variable {X α l m n p S R : Type*} {m' n' : l → Type*}
instance [TopologicalSpace R] : TopologicalSpace (Matrix m n R) :=
Pi.topologicalSpace
instance [TopologicalSpace R] [T2Space R] : T2Space (Matrix m n R) :=
Pi.t2Space
section Set
theorem IsOpen.matrix [Fintype m] [Fintype n]
[TopologicalSpace R] {S : Set R} (hS : IsOpen S) :
IsOpen (S.matrix : Set (Matrix m n R)) :=
Set.matrix_eq_pi ▸
(isOpen_set_pi Set.finite_univ fun _ _ =>
isOpen_set_pi Set.finite_univ fun _ _ => hS).preimage continuous_id
theorem IsCompact.matrix [TopologicalSpace R] {S : Set R} (hS : IsCompact S) :
IsCompact (S.matrix : Set (Matrix m n R)) :=
isCompact_pi_infinite fun _ => isCompact_pi_infinite fun _ => hS
end Set
/-! ### Lemmas about continuity of operations -/
section Continuity
variable [TopologicalSpace X] [TopologicalSpace R]
instance [SMul α R] [ContinuousConstSMul α R] : ContinuousConstSMul α (Matrix m n R) :=
inferInstanceAs (ContinuousConstSMul α (m → n → R))
instance [TopologicalSpace α] [SMul α R] [ContinuousSMul α R] : ContinuousSMul α (Matrix m n R) :=
inferInstanceAs (ContinuousSMul α (m → n → R))
instance [Add R] [ContinuousAdd R] : ContinuousAdd (Matrix m n R) :=
Pi.continuousAdd
instance [Neg R] [ContinuousNeg R] : ContinuousNeg (Matrix m n R) :=
Pi.continuousNeg
instance [AddGroup R] [IsTopologicalAddGroup R] : IsTopologicalAddGroup (Matrix m n R) :=
Pi.topologicalAddGroup
/-- To show a function into matrices is continuous it suffices to show the coefficients of the
resulting matrix are continuous -/
@[continuity]
theorem continuous_matrix [TopologicalSpace α] {f : α → Matrix m n R}
(h : ∀ i j, Continuous fun a => f a i j) : Continuous f :=
continuous_pi fun _ => continuous_pi fun _ => h _ _
theorem Continuous.matrix_elem {A : X → Matrix m n R} (hA : Continuous A) (i : m) (j : n) :
Continuous fun x => A x i j :=
(continuous_apply_apply i j).comp hA
@[continuity, fun_prop]
theorem Continuous.matrix_map [TopologicalSpace S] {A : X → Matrix m n S} {f : S → R}
(hA : Continuous A) (hf : Continuous f) : Continuous fun x => (A x).map f :=
continuous_matrix fun _ _ => hf.comp <| hA.matrix_elem _ _
@[continuity, fun_prop]
theorem Continuous.matrix_transpose {A : X → Matrix m n R} (hA : Continuous A) :
Continuous fun x => (A x)ᵀ :=
continuous_matrix fun i j => hA.matrix_elem j i
@[continuity, fun_prop]
theorem Continuous.matrix_conjTranspose [Star R] [ContinuousStar R] {A : X → Matrix m n R}
(hA : Continuous A) : Continuous fun x => (A x)ᴴ :=
hA.matrix_transpose.matrix_map continuous_star
instance [Star R] [ContinuousStar R] : ContinuousStar (Matrix m m R) :=
⟨continuous_id.matrix_conjTranspose⟩
@[continuity, fun_prop]
theorem Continuous.matrix_replicateCol {ι : Type*} {A : X → n → R} (hA : Continuous A) :
Continuous fun x => replicateCol ι (A x) :=
continuous_matrix fun i _ => (continuous_apply i).comp hA
@[deprecated (since := "2025-03-15")] alias Continuous.matrix_col := Continuous.matrix_replicateCol
@[continuity, fun_prop]
theorem Continuous.matrix_replicateRow {ι : Type*} {A : X → n → R} (hA : Continuous A) :
Continuous fun x => replicateRow ι (A x) :=
continuous_matrix fun _ _ => (continuous_apply _).comp hA
@[deprecated (since := "2025-03-15")] alias Continuous.matrix_row := Continuous.matrix_replicateRow
@[continuity, fun_prop]
theorem Continuous.matrix_diagonal [Zero R] [DecidableEq n] {A : X → n → R} (hA : Continuous A) :
Continuous fun x => diagonal (A x) :=
continuous_matrix fun i _ => ((continuous_apply i).comp hA).if_const _ continuous_zero
@[continuity, fun_prop]
protected theorem Continuous.dotProduct [Fintype n] [Mul R] [AddCommMonoid R] [ContinuousAdd R]
[ContinuousMul R] {A : X → n → R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) :
Continuous fun x => A x ⬝ᵥ B x := by
dsimp only [dotProduct]
fun_prop
@[deprecated (since := "2025-05-09")]
alias Continuous.matrix_dotProduct := Continuous.dotProduct
/-- For square matrices the usual `continuous_mul` can be used. -/
@[continuity, fun_prop]
theorem Continuous.matrix_mul [Fintype n] [Mul R] [AddCommMonoid R] [ContinuousAdd R]
[ContinuousMul R] {A : X → Matrix m n R} {B : X → Matrix n p R} (hA : Continuous A)
(hB : Continuous B) : Continuous fun x => A x * B x :=
continuous_matrix fun _ _ =>
continuous_finset_sum _ fun _ _ => (hA.matrix_elem _ _).mul (hB.matrix_elem _ _)
instance [Fintype n] [Mul R] [AddCommMonoid R] [ContinuousAdd R] [ContinuousMul R] :
ContinuousMul (Matrix n n R) :=
⟨continuous_fst.matrix_mul continuous_snd⟩
instance [Fintype n] [NonUnitalNonAssocSemiring R] [IsTopologicalSemiring R] :
IsTopologicalSemiring (Matrix n n R) where
instance Matrix.topologicalRing [Fintype n] [NonUnitalNonAssocRing R] [IsTopologicalRing R] :
IsTopologicalRing (Matrix n n R) where
@[continuity, fun_prop]
theorem Continuous.matrix_vecMulVec [Mul R] [ContinuousMul R] {A : X → m → R} {B : X → n → R}
(hA : Continuous A) (hB : Continuous B) : Continuous fun x => vecMulVec (A x) (B x) :=
continuous_matrix fun _ _ => ((continuous_apply _).comp hA).mul ((continuous_apply _).comp hB)
@[continuity, fun_prop]
theorem Continuous.matrix_mulVec [NonUnitalNonAssocSemiring R] [ContinuousAdd R] [ContinuousMul R]
[Fintype n] {A : X → Matrix m n R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) :
Continuous fun x => A x *ᵥ B x :=
continuous_pi fun i => ((continuous_apply i).comp hA).dotProduct hB
@[continuity, fun_prop]
theorem Continuous.matrix_vecMul [NonUnitalNonAssocSemiring R] [ContinuousAdd R] [ContinuousMul R]
[Fintype m] {A : X → m → R} {B : X → Matrix m n R} (hA : Continuous A) (hB : Continuous B) :
Continuous fun x => A x ᵥ* B x :=
continuous_pi fun _i => hA.dotProduct <| continuous_pi fun _j => hB.matrix_elem _ _
@[continuity, fun_prop]
theorem Continuous.matrix_submatrix {A : X → Matrix l n R} (hA : Continuous A) (e₁ : m → l)
(e₂ : p → n) : Continuous fun x => (A x).submatrix e₁ e₂ :=
continuous_matrix fun _i _j => hA.matrix_elem _ _
@[continuity, fun_prop]
theorem Continuous.matrix_reindex {A : X → Matrix l n R} (hA : Continuous A) (e₁ : l ≃ m)
(e₂ : n ≃ p) : Continuous fun x => reindex e₁ e₂ (A x) :=
hA.matrix_submatrix _ _
@[continuity, fun_prop]
theorem Continuous.matrix_diag {A : X → Matrix n n R} (hA : Continuous A) :
Continuous fun x => Matrix.diag (A x) :=
continuous_pi fun _ => hA.matrix_elem _ _
-- note this doesn't elaborate well from the above
theorem continuous_matrix_diag : Continuous (Matrix.diag : Matrix n n R → n → R) :=
show Continuous fun x : Matrix n n R => Matrix.diag x from continuous_id.matrix_diag
@[continuity, fun_prop]
theorem Continuous.matrix_trace [Fintype n] [AddCommMonoid R] [ContinuousAdd R]
{A : X → Matrix n n R} (hA : Continuous A) : Continuous fun x => trace (A x) :=
continuous_finset_sum _ fun _ _ => hA.matrix_elem _ _
@[continuity, fun_prop]
theorem Continuous.matrix_det [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R]
{A : X → Matrix n n R} (hA : Continuous A) : Continuous fun x => (A x).det := by
simp_rw [Matrix.det_apply]
refine continuous_finset_sum _ fun l _ => Continuous.const_smul ?_ _
exact continuous_finset_prod _ fun l _ => hA.matrix_elem _ _
@[continuity, fun_prop]
theorem Continuous.matrix_updateCol [DecidableEq n] (i : n) {A : X → Matrix m n R}
{B : X → m → R} (hA : Continuous A) (hB : Continuous B) :
Continuous fun x => (A x).updateCol i (B x) :=
continuous_matrix fun _j k =>
(continuous_apply k).comp <|
((continuous_apply _).comp hA).update i ((continuous_apply _).comp hB)
@[continuity, fun_prop]
theorem Continuous.matrix_updateRow [DecidableEq m] (i : m) {A : X → Matrix m n R} {B : X → n → R}
(hA : Continuous A) (hB : Continuous B) : Continuous fun x => (A x).updateRow i (B x) :=
hA.update i hB
@[continuity, fun_prop]
theorem Continuous.matrix_cramer [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R]
{A : X → Matrix n n R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) :
Continuous fun x => cramer (A x) (B x) :=
continuous_pi fun _ => (hA.matrix_updateCol _ hB).matrix_det
@[continuity, fun_prop]
theorem Continuous.matrix_adjugate [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R]
{A : X → Matrix n n R} (hA : Continuous A) : Continuous fun x => (A x).adjugate :=
continuous_matrix fun _j k =>
(hA.matrix_transpose.matrix_updateCol k continuous_const).matrix_det
/-- When `Ring.inverse` is continuous at the determinant (such as in a `NormedRing`, or a
topological field), so is `Matrix.inv`. -/
theorem continuousAt_matrix_inv [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R]
(A : Matrix n n R) (h : ContinuousAt Ring.inverse A.det) : ContinuousAt Inv.inv A :=
(h.comp continuous_id.matrix_det.continuousAt).smul continuous_id.matrix_adjugate.continuousAt
-- lemmas about functions in `Data/Matrix/Block.lean`
section BlockMatrices
@[continuity, fun_prop]
theorem Continuous.matrix_fromBlocks {A : X → Matrix n l R} {B : X → Matrix n m R}
{C : X → Matrix p l R} {D : X → Matrix p m R} (hA : Continuous A) (hB : Continuous B)
(hC : Continuous C) (hD : Continuous D) :
Continuous fun x => Matrix.fromBlocks (A x) (B x) (C x) (D x) :=
continuous_matrix <| by
rintro (i | i) (j | j) <;> refine Continuous.matrix_elem ?_ i j <;> assumption
@[continuity, fun_prop]
theorem Continuous.matrix_blockDiagonal [Zero R] [DecidableEq p] {A : X → p → Matrix m n R}
(hA : Continuous A) : Continuous fun x => blockDiagonal (A x) :=
continuous_matrix fun ⟨i₁, i₂⟩ ⟨j₁, _j₂⟩ =>
(((continuous_apply i₂).comp hA).matrix_elem i₁ j₁).if_const _ continuous_zero
@[continuity, fun_prop]
theorem Continuous.matrix_blockDiag {A : X → Matrix (m × p) (n × p) R} (hA : Continuous A) :
Continuous fun x => blockDiag (A x) :=
continuous_pi fun _i => continuous_matrix fun _j _k => hA.matrix_elem _ _
@[continuity, fun_prop]
theorem Continuous.matrix_blockDiagonal' [Zero R] [DecidableEq l]
{A : X → ∀ i, Matrix (m' i) (n' i) R} (hA : Continuous A) :
Continuous fun x => blockDiagonal' (A x) :=
continuous_matrix fun ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ => by
dsimp only [blockDiagonal'_apply']
split_ifs with h
· subst h
exact ((continuous_apply i₁).comp hA).matrix_elem i₂ j₂
· exact continuous_const
@[continuity, fun_prop]
theorem Continuous.matrix_blockDiag'
{A : X → Matrix (Σ i, m' i) (Σ i, n' i) R} (hA : Continuous A) :
Continuous fun x => blockDiag' (A x) :=
continuous_pi fun _i => continuous_matrix fun _j _k => hA.matrix_elem _ _
end BlockMatrices
end Continuity
/-! ### Lemmas about infinite sums -/
section tsum
variable [AddCommMonoid R] [TopologicalSpace R]
theorem HasSum.matrix_transpose {f : X → Matrix m n R} {a : Matrix m n R} (hf : HasSum f a) :
HasSum (fun x => (f x)ᵀ) aᵀ :=
(hf.map (Matrix.transposeAddEquiv m n R) continuous_id.matrix_transpose :)
theorem Summable.matrix_transpose {f : X → Matrix m n R} (hf : Summable f) :
Summable fun x => (f x)ᵀ :=
hf.hasSum.matrix_transpose.summable
@[simp]
theorem summable_matrix_transpose {f : X → Matrix m n R} :
(Summable fun x => (f x)ᵀ) ↔ Summable f :=
Summable.map_iff_of_equiv (Matrix.transposeAddEquiv m n R)
continuous_id.matrix_transpose continuous_id.matrix_transpose
theorem Matrix.transpose_tsum [T2Space R] {f : X → Matrix m n R} : (∑' x, f x)ᵀ = ∑' x, (f x)ᵀ := by
by_cases hf : Summable f
· exact hf.hasSum.matrix_transpose.tsum_eq.symm
· have hft := summable_matrix_transpose.not.mpr hf
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, transpose_zero]
theorem HasSum.matrix_conjTranspose [StarAddMonoid R] [ContinuousStar R] {f : X → Matrix m n R}
{a : Matrix m n R} (hf : HasSum f a) : HasSum (fun x => (f x)ᴴ) aᴴ :=
(hf.map (Matrix.conjTransposeAddEquiv m n R) continuous_id.matrix_conjTranspose :)
theorem Summable.matrix_conjTranspose [StarAddMonoid R] [ContinuousStar R] {f : X → Matrix m n R}
(hf : Summable f) : Summable fun x => (f x)ᴴ :=
hf.hasSum.matrix_conjTranspose.summable
@[simp]
theorem summable_matrix_conjTranspose [StarAddMonoid R] [ContinuousStar R] {f : X → Matrix m n R} :
(Summable fun x => (f x)ᴴ) ↔ Summable f :=
Summable.map_iff_of_equiv (Matrix.conjTransposeAddEquiv m n R)
continuous_id.matrix_conjTranspose continuous_id.matrix_conjTranspose
theorem Matrix.conjTranspose_tsum [StarAddMonoid R] [ContinuousStar R] [T2Space R]
{f : X → Matrix m n R} : (∑' x, f x)ᴴ = ∑' x, (f x)ᴴ := by
by_cases hf : Summable f
· exact hf.hasSum.matrix_conjTranspose.tsum_eq.symm
· have hft := summable_matrix_conjTranspose.not.mpr hf
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, conjTranspose_zero]
theorem HasSum.matrix_diagonal [DecidableEq n] {f : X → n → R} {a : n → R} (hf : HasSum f a) :
HasSum (fun x => diagonal (f x)) (diagonal a) :=
hf.map (diagonalAddMonoidHom n R) continuous_id.matrix_diagonal
theorem Summable.matrix_diagonal [DecidableEq n] {f : X → n → R} (hf : Summable f) :
Summable fun x => diagonal (f x) :=
hf.hasSum.matrix_diagonal.summable
@[simp]
theorem summable_matrix_diagonal [DecidableEq n] {f : X → n → R} :
(Summable fun x => diagonal (f x)) ↔ Summable f :=
Summable.map_iff_of_leftInverse (Matrix.diagonalAddMonoidHom n R) (Matrix.diagAddMonoidHom n R)
continuous_id.matrix_diagonal continuous_matrix_diag fun A => diag_diagonal A
theorem Matrix.diagonal_tsum [DecidableEq n] [T2Space R] {f : X → n → R} :
diagonal (∑' x, f x) = ∑' x, diagonal (f x) := by
by_cases hf : Summable f
· exact hf.hasSum.matrix_diagonal.tsum_eq.symm
· have hft := summable_matrix_diagonal.not.mpr hf
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft]
exact diagonal_zero
theorem HasSum.matrix_diag {f : X → Matrix n n R} {a : Matrix n n R} (hf : HasSum f a) :
HasSum (fun x => diag (f x)) (diag a) :=
hf.map (diagAddMonoidHom n R) continuous_matrix_diag
theorem Summable.matrix_diag {f : X → Matrix n n R} (hf : Summable f) :
Summable fun x => diag (f x) :=
hf.hasSum.matrix_diag.summable
section BlockMatrices
theorem HasSum.matrix_blockDiagonal [DecidableEq p] {f : X → p → Matrix m n R}
{a : p → Matrix m n R} (hf : HasSum f a) :
HasSum (fun x => blockDiagonal (f x)) (blockDiagonal a) :=
hf.map (blockDiagonalAddMonoidHom m n p R) continuous_id.matrix_blockDiagonal
theorem Summable.matrix_blockDiagonal [DecidableEq p] {f : X → p → Matrix m n R} (hf : Summable f) :
Summable fun x => blockDiagonal (f x) :=
hf.hasSum.matrix_blockDiagonal.summable
theorem summable_matrix_blockDiagonal [DecidableEq p] {f : X → p → Matrix m n R} :
(Summable fun x => blockDiagonal (f x)) ↔ Summable f :=
Summable.map_iff_of_leftInverse (blockDiagonalAddMonoidHom m n p R)
(blockDiagAddMonoidHom m n p R) continuous_id.matrix_blockDiagonal
continuous_id.matrix_blockDiag fun A => blockDiag_blockDiagonal A
theorem Matrix.blockDiagonal_tsum [DecidableEq p] [T2Space R] {f : X → p → Matrix m n R} :
blockDiagonal (∑' x, f x) = ∑' x, blockDiagonal (f x) := by
by_cases hf : Summable f
· exact hf.hasSum.matrix_blockDiagonal.tsum_eq.symm
· have hft := summable_matrix_blockDiagonal.not.mpr hf
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft]
exact blockDiagonal_zero
theorem HasSum.matrix_blockDiag {f : X → Matrix (m × p) (n × p) R} {a : Matrix (m × p) (n × p) R}
(hf : HasSum f a) : HasSum (fun x => blockDiag (f x)) (blockDiag a) :=
(hf.map (blockDiagAddMonoidHom m n p R) <| Continuous.matrix_blockDiag continuous_id :)
theorem Summable.matrix_blockDiag {f : X → Matrix (m × p) (n × p) R} (hf : Summable f) :
Summable fun x => blockDiag (f x) :=
hf.hasSum.matrix_blockDiag.summable
theorem HasSum.matrix_blockDiagonal' [DecidableEq l] {f : X → ∀ i, Matrix (m' i) (n' i) R}
{a : ∀ i, Matrix (m' i) (n' i) R} (hf : HasSum f a) :
HasSum (fun x => blockDiagonal' (f x)) (blockDiagonal' a) :=
hf.map (blockDiagonal'AddMonoidHom m' n' R) continuous_id.matrix_blockDiagonal'
theorem Summable.matrix_blockDiagonal' [DecidableEq l] {f : X → ∀ i, Matrix (m' i) (n' i) R}
(hf : Summable f) : Summable fun x => blockDiagonal' (f x) :=
hf.hasSum.matrix_blockDiagonal'.summable
theorem summable_matrix_blockDiagonal' [DecidableEq l] {f : X → ∀ i, Matrix (m' i) (n' i) R} :
(Summable fun x => blockDiagonal' (f x)) ↔ Summable f :=
Summable.map_iff_of_leftInverse (blockDiagonal'AddMonoidHom m' n' R)
(blockDiag'AddMonoidHom m' n' R) continuous_id.matrix_blockDiagonal'
continuous_id.matrix_blockDiag' fun A => blockDiag'_blockDiagonal' A
theorem Matrix.blockDiagonal'_tsum [DecidableEq l] [T2Space R]
{f : X → ∀ i, Matrix (m' i) (n' i) R} :
blockDiagonal' (∑' x, f x) = ∑' x, blockDiagonal' (f x) := by
by_cases hf : Summable f
· exact hf.hasSum.matrix_blockDiagonal'.tsum_eq.symm
· have hft := summable_matrix_blockDiagonal'.not.mpr hf
rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft]
exact blockDiagonal'_zero
theorem HasSum.matrix_blockDiag' {f : X → Matrix (Σ i, m' i) (Σ i, n' i) R}
{a : Matrix (Σ i, m' i) (Σ i, n' i) R} (hf : HasSum f a) :
HasSum (fun x => blockDiag' (f x)) (blockDiag' a) :=
hf.map (blockDiag'AddMonoidHom m' n' R) continuous_id.matrix_blockDiag'
theorem Summable.matrix_blockDiag' {f : X → Matrix (Σ i, m' i) (Σ i, n' i) R} (hf : Summable f) :
Summable fun x => blockDiag' (f x) :=
hf.hasSum.matrix_blockDiag'.summable
end BlockMatrices
end tsum
|
all_boot.v
|
Require Export ssreflect.
Require Export ssrbool.
Require Export ssrfun.
Require Export eqtype.
Require Export ssrnat.
Require Export seq.
Require Export choice.
Require Export monoid.
Require Export nmodule.
Require Export path.
Require Export div.
Require Export fintype.
Require Export fingraph.
Require Export tuple.
Require Export finfun.
Require Export bigop.
Require Export prime.
Require Export finset.
Require Export binomial.
Require Export generic_quotient.
Require Export ssrAC.
|
test_ssrAC.v
|
From mathcomp Require Import all_boot ssralg.
Section Tests.
Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d).
Proof. time by rewrite orbACA. Abort.
Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d).
Proof. time by rewrite (AC (2*2) ((1*3)*(2*4))). Abort.
Lemma test_orb (a b c d : bool) : (a || b) || (c || d) = (a || c) || (b || d).
Proof. time by rewrite orb.[AC (2*2) ((1*3)*(2*4))]. Qed.
Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d.
Proof. time by rewrite -addnA addnAC addnA addnAC. Abort.
Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d.
Proof. time by rewrite (ACl (1*3*2*4)). Abort.
Lemma test_addn (a b c d : nat) : a + b + c + d = a + c + b + d.
Proof. time by rewrite addn.[ACl 1*3*2*4]. Qed.
Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R.
Proof. time by rewrite -GRing.addrA GRing.addrAC GRing.addrA GRing.addrAC. Abort.
Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R.
Proof. time by rewrite (ACl (1*3*2*4)). Abort.
Lemma test_addr (R : comRingType) (a b c d : R) : (a + b + c + d = a + c + b + d)%R.
Proof. time by rewrite (@GRing.add R).[ACl 1*3*2*4]. Qed.
Local Open Scope ring_scope.
Import GRing.Theory.
Lemma test_mulr (R : comRingType) (x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 : R)
(x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 : R) :
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) =
(x0 * x2 * x4 * x9) * (x1 * x3 * x5 * x7) * x6 * x8 *
(x10 * x12 * x14 * x19) * (x11 * x13 * x15 * x17) * x16 * x18 * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19)
*(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19)
*(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19)
*(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19)
*(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19)
*(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9)*
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19)
*(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) * (x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19)
*(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) *
(x10 * x11) * (x12 * x13) * (x14 * x15) * (x16 * x17 * x18 * x19) *
(x0 * x1) * (x2 * x3) * (x4 * x5) * (x6 * x7 * x8 * x9) .
Proof.
pose s := ((2 * 4 * 9 * 1 * 3 * 5 * 7 * 6 * 8 * 20 * 21 * 22 * 23) * 25 * 26 * 27 * 28
* (29 * 30 * 31) * 32 * 33 * 34 * 35 * 36 * 37 * 38 * 39 * 40 * 41
* (10 * 12 * 14 * 19 * 11 * 13 * 15 * 17 * 16 * 18 * 24)
* (42 * 43 * 44 * 45 * 46 * 47 * 48 * 49) * 50
* 52 * 53 * 54 * 55 * 56 * 57 * 58 * 59 * 51* 60
* 62 * 63 * 64 * 65 * 66 * 67 * 68 * 69 * 61* 70
* 72 * 73 * 74 * 75 * 76 * 77 * 78 * 79 * 71 * 80
* 82 * 83 * 84 * 85 * 86 * 87 * 88 * 89 * 81* 90
* 92 * 93 * 94 * 95 * 96 * 97 * 98 * 99 * 91 * 100 *
((102 * 104 * 109 * 101 * 103 * 105 * 107 * 106 * 108 * 120 * 121 * 122 * 123) * 125 * 126 * 127 * 128
* (129 * 130 * 131) * 132 * 133 * 134 * 135 * 136 * 137 * 138 * 139 * 140 * 141
* (110 * 112 * 114 * 119 * 111 * 113 * 115 * 117 * 116 * 118 * 124)
* (142 * 143 * 144 * 145 * 146 * 147 * 148 * 149) * 150
* 152 * 153 * 154 * 155 * 156 * 157 * 158 * 159 * 151* 160
* 162 * 163 * 164 * 165 * 166 * 167 * 168 * 169 * 161* 170
* 172 * 173 * 174 * 175 * 176 * 177 * 178 * 179 * 171 * 180
* 182 * 183 * 184 * 185 * 186 * 187 * 188 * 189 * 181* 190
* 192 * 193 * 194 * 195 * 196 * 197 * 198 * 199 * 191)
)%AC.
time have := (@GRing.mul R).[ACl s].
time rewrite (@GRing.mul R).[ACl s].
Abort.
End Tests.
|
Valuation.lean
|
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.RingTheory.HahnSeries.Multiplication
import Mathlib.RingTheory.Valuation.Basic
/-!
# Valuations on Hahn Series rings
If `Γ` is a `LinearOrderedCancelAddCommMonoid` and `R` is a domain, then the domain `HahnSeries Γ R`
admits an additive valuation given by `orderTop`.
## Main Definitions
* `HahnSeries.addVal Γ R` defines an `AddValuation` on `HahnSeries Γ R` when `Γ` is linearly
ordered.
## TODO
* Multiplicative valuations
* Add any API for Laurent series valuations that do not depend on `Γ = ℤ`.
## References
- [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven]
-/
noncomputable section
variable {Γ R : Type*}
namespace HahnSeries
section Valuation
variable (Γ R) [AddCommMonoid Γ] [LinearOrder Γ] [IsOrderedCancelAddMonoid Γ] [Ring R] [IsDomain R]
/-- The additive valuation on `HahnSeries Γ R`, returning the smallest index at which
a Hahn Series has a nonzero coefficient, or `⊤` for the 0 series. -/
def addVal : AddValuation (HahnSeries Γ R) (WithTop Γ) :=
AddValuation.of orderTop orderTop_zero (orderTop_one) (fun _ _ => min_orderTop_le_orderTop_add)
fun x y => by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [← order_eq_orderTop_of_ne hx, ← order_eq_orderTop_of_ne hy,
← order_eq_orderTop_of_ne (mul_ne_zero hx hy), ← WithTop.coe_add, WithTop.coe_eq_coe,
order_mul hx hy]
variable {Γ} {R}
theorem addVal_apply {x : HahnSeries Γ R} :
addVal Γ R x = x.orderTop :=
AddValuation.of_apply _
@[simp]
theorem addVal_apply_of_ne {x : HahnSeries Γ R} (hx : x ≠ 0) : addVal Γ R x = x.order :=
addVal_apply.trans (order_eq_orderTop_of_ne hx).symm
theorem addVal_le_of_coeff_ne_zero {x : HahnSeries Γ R} {g : Γ} (h : x.coeff g ≠ 0) :
addVal Γ R x ≤ g :=
orderTop_le_of_coeff_ne_zero h
end Valuation
end HahnSeries
|
GuardGoalNums.lean
|
import Mathlib.Tactic.GuardGoalNums
set_option linter.unusedTactic false
example : true ∧ true := by
constructor
guard_goal_nums 2
all_goals {constructor}
example : (true ∧ true) ∧ (true ∧ true) := by
constructor <;> constructor
guard_goal_nums 4
all_goals {constructor}
|
LocallyFinite.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.Topology.LocallyFinite
import Mathlib.Topology.Compactness.Compact
/-!
# Compact sets and compact spaces and locally finite functions
-/
open Set
variable {X ι : Type*} [TopologicalSpace X] {s : Set X}
namespace LocallyFinite
/-- If `s` is a compact set in a topological space `X` and `f : ι → Set X` is a locally finite
family of sets, then `f i ∩ s` is nonempty only for a finitely many `i`. -/
theorem finite_nonempty_inter_compact {f : ι → Set X}
(hf : LocallyFinite f) (hs : IsCompact s) : { i | (f i ∩ s).Nonempty }.Finite := by
choose U hxU hUf using hf
rcases hs.elim_nhds_subcover U fun x _ => hxU x with ⟨t, -, hsU⟩
refine (t.finite_toSet.biUnion fun x _ => hUf x).subset ?_
rintro i ⟨x, hx⟩
rcases mem_iUnion₂.1 (hsU hx.2) with ⟨c, hct, hcx⟩
exact mem_biUnion hct ⟨x, hx.1, hcx⟩
/-- If `X` is a compact space, then a locally finite family of sets of `X` can have only finitely
many nonempty elements. -/
theorem finite_nonempty_of_compact [CompactSpace X] {f : ι → Set X}
(hf : LocallyFinite f) : { i | (f i).Nonempty }.Finite := by
simpa only [inter_univ] using hf.finite_nonempty_inter_compact isCompact_univ
/-- If `X` is a compact space, then a locally finite family of nonempty sets of `X` can have only
finitely many elements, `Set.Finite` version. -/
theorem finite_of_compact [CompactSpace X] {f : ι → Set X}
(hf : LocallyFinite f) (hne : ∀ i, (f i).Nonempty) : (univ : Set ι).Finite := by
simpa only [hne] using hf.finite_nonempty_of_compact
/-- If `X` is a compact space, then a locally finite family of nonempty sets of `X` can have only
finitely many elements, `Fintype` version. -/
noncomputable def fintypeOfCompact [CompactSpace X] {f : ι → Set X}
(hf : LocallyFinite f) (hne : ∀ i, (f i).Nonempty) : Fintype ι :=
fintypeOfFiniteUniv (hf.finite_of_compact hne)
end LocallyFinite
|
mxred.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div.
From mathcomp Require Import choice fintype finfun bigop fingroup perm order.
From mathcomp Require Import ssralg zmodp matrix mxalgebra poly polydiv mxpoly.
(*****************************************************************************)
(* In this file, we prove diagonalization theorems. For this purpose, we *)
(* define conjugation, similarity and diagonalizability. *)
(* *)
(* conjmx V f := V *m f *m pinvmx V *)
(* == the conjugation of f by V, i.e. "the" matrix of f *)
(* in the basis of row vectors of V. *)
(* Although this makes sense only when f stabilizes V, *)
(* the definition can be stated more generally. *)
(* similar_to P A C == where P is a base change matrix, A is a matrix, *)
(* and C is a class of matrices, *)
(* this states that conjmx P A is in C, *)
(* which means A is similar to a matrix in C. *)
(* *)
(* From the latter, we derive serveral related notions: *)
(* similar P A B := similar_to P A (pred1 B) *)
(* == A is similar to B, with base change matrix P *)
(* similar_in D A B == A is similar to B, *)
(* with a base change matrix in D *)
(* similar_in_to D A C == A is similar to a matrix in the class C, *)
(* with a base change matrix in D *)
(* all_similar_to D As C == all the matrices in the sequence As are similar *)
(* to some matrix in the class C, *)
(* with a base change matrix in D. *)
(* *)
(* We also specialize the class C, to diagonalizability: *)
(* similar_diag P A := (similar_to P A is_diag_mx). *)
(* diagonalizable_in D A := (similar_in_to D A is_diag_mx). *)
(* diagonalizable A := (diagonalizable_in unitmx A). *)
(* codiagonalizable_in D As := (all_similar_to D As is_diag_mx). *)
(* codiagonalizable As := (codiagonalizable_in unitmx As). *)
(* *)
(* The main results of this file are: *)
(* diagonalizablePeigen: *)
(* a matrix is diagonalizable iff there is a sequence *)
(* of scalars r, such that the sum of the associated *)
(* eigenspaces is full. *)
(* diagonalizableP: *)
(* a matrix is diagonalizable iff its minimal polynomial *)
(* divides a split polynomial with simple roots. *)
(* codiagonalizableP: *)
(* a sequence of matrices are diagonalizable in the same basis *)
(* iff they are all diagonalizable and commute pairwize. *)
(* *)
(* We also specialize the class C, to trigonalizablility: *)
(* similar_trig P A := (similar_to P A is_trig_mx). *)
(* trigonalizable_in D A := (similar_in_to D A is_trig_mx). *)
(* trigonalizable A := (trigonalizable_in unitmx A). *)
(* cotrigonalizable_in D As := (all_similar_to D As is_trig_mx). *)
(* cotrigonalizable As := (cotrigonalizable_in unitmx As). *)
(* The theory of trigonalization is however not developed in this file. *)
(*****************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory.
Import Monoid.Theory.
Local Open Scope ring_scope.
Section ConjMx.
Context {F : fieldType}.
Definition conjmx (m n : nat)
(V : 'M_(m, n)) (f : 'M[F]_n) : 'M_m := V *m f *m pinvmx V.
Notation restrictmx V := (conjmx (row_base V)).
Lemma stablemx_comp (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) :
stablemx W f -> stablemx V (conjmx W f) -> stablemx (V *m W) f.
Proof. by move=> Wf /(submxMr W); rewrite -mulmxA mulmxKpV// mulmxA. Qed.
Lemma stablemx_restrict m n (A : 'M[F]_n) (V : 'M_n) (W : 'M_(m, \rank V)):
stablemx V A -> stablemx W (restrictmx V A) = stablemx (W *m row_base V) A.
Proof.
move=> A_stabV; rewrite mulmxA -[in RHS]mulmxA.
rewrite -(submxMfree _ W (row_base_free V)) mulmxKpV //.
by rewrite mulmx_sub ?stablemx_row_base.
Qed.
Lemma conjmxM (m n : nat) (V : 'M[F]_(m, n)) :
{in [pred f | stablemx V f] &, {morph conjmx V : f g / f *m g}}.
Proof.
move=> f g; rewrite !inE => Vf Vg /=.
by rewrite /conjmx 2!mulmxA mulmxA mulmxKpV ?stablemx_row_base.
Qed.
Lemma conjMmx (m n p : nat) (V : 'M[F]_(m, n)) (W : 'M_(n, p)) (f : 'M_p) :
row_free (V *m W) -> stablemx W f -> stablemx V (conjmx W f) ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof.
move=> rfVW Wf VWf; apply: (row_free_inj rfVW); rewrite mulmxKpV ?stablemx_comp//.
by rewrite mulmxA mulmxKpV// -[RHS]mulmxA mulmxKpV ?mulmxA.
Qed.
Lemma conjuMmx (m n : nat) (V : 'M[F]_m) (W : 'M_(m, n)) (f : 'M_n) :
V \in unitmx -> row_free W -> stablemx W f ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof.
move=> Vu rfW Wf; rewrite conjMmx ?stablemx_unit//.
by rewrite /row_free mxrankMfree// -/(row_free V) row_free_unit.
Qed.
Lemma conjMumx (m n : nat) (V : 'M[F]_(m, n)) (W f : 'M_n) :
W \in unitmx -> row_free V -> stablemx V (conjmx W f) ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof.
move=> Wu rfW Wf; rewrite conjMmx ?stablemx_unit//.
by rewrite /row_free mxrankMfree ?row_free_unit.
Qed.
Lemma conjuMumx (n : nat) (V W f : 'M[F]_n) :
V \in unitmx -> W \in unitmx ->
conjmx (V *m W) f = conjmx V (conjmx W f).
Proof. by move=> Vu Wu; rewrite conjuMmx ?stablemx_unit ?row_free_unit. Qed.
Lemma conjmx_scalar (m n : nat) (V : 'M[F]_(m, n)) (a : F) :
row_free V -> conjmx V a%:M = a%:M.
Proof. by move=> rfV; rewrite /conjmx scalar_mxC mulmxKp. Qed.
Lemma conj0mx (m n : nat) f : conjmx (0 : 'M[F]_(m, n)) f = 0.
Proof. by rewrite /conjmx !mul0mx. Qed.
Lemma conjmx0 (m n : nat) (V : 'M[F]_(m, n)) : conjmx V 0 = 0.
Proof. by rewrite /conjmx mulmx0 mul0mx. Qed.
Lemma conjumx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx ->
conjmx V f = V *m f *m invmx V.
Proof. by move=> uV; rewrite /conjmx pinvmxE. Qed.
Lemma conj1mx (n : nat) (f : 'M[F]_n) : conjmx 1%:M f = f.
Proof. by rewrite conjumx ?unitmx1// invmx1 mulmx1 mul1mx. Qed.
Lemma conjVmx (n : nat) (V : 'M_n) (f : 'M[F]_n) : V \in unitmx ->
conjmx (invmx V) f = invmx V *m f *m V.
Proof. by move=> Vunit; rewrite conjumx ?invmxK ?unitmx_inv. Qed.
Lemma conjmxK (n : nat) (V f : 'M[F]_n) :
V \in unitmx -> conjmx (invmx V) (conjmx V f) = f.
Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulVmx ?conj1mx. Qed.
Lemma conjmxVK (n : nat) (V f : 'M[F]_n) :
V \in unitmx -> conjmx V (conjmx (invmx V) f) = f.
Proof. by move=> Vu; rewrite -conjuMumx ?unitmx_inv// mulmxV ?conj1mx. Qed.
Lemma horner_mx_conj m n p (B : 'M[F]_(n.+1, m.+1)) (f : 'M_m.+1) :
row_free B -> stablemx B f ->
horner_mx (conjmx B f) p = conjmx B (horner_mx f p).
Proof.
move=> B_free B_stab; rewrite/conjmx; elim/poly_ind: p => [|p c].
by rewrite !rmorph0 mulmx0 mul0mx.
rewrite !(rmorphD, rmorphM)/= !(horner_mx_X, horner_mx_C) => ->.
rewrite [_ * _]mulmxA [_ *m (B *m _)]mulmxA mulmxKpV ?horner_mx_stable//.
apply: (row_free_inj B_free); rewrite [_ *m B]mulmxDl.
pose stablemxE := (stablemxD, stablemxM, stablemxC, horner_mx_stable).
by rewrite !mulmxKpV -?[B *m _ *m _]mulmxA ?stablemxE// mulmxDr -scalar_mxC.
Qed.
Lemma horner_mx_uconj n p (B : 'M[F]_(n.+1)) (f : 'M_n.+1) :
B \is a GRing.unit ->
horner_mx (B *m f *m invmx B) p = B *m horner_mx f p *m invmx B.
Proof.
move=> B_unit; rewrite -!conjumx//.
by rewrite horner_mx_conj ?row_free_unit ?stablemx_unit.
Qed.
Lemma horner_mx_uconjC n p (B : 'M[F]_(n.+1)) (f : 'M_n.+1) :
B \is a GRing.unit ->
horner_mx (invmx B *m f *m B) p = invmx B *m horner_mx f p *m B.
Proof.
move=> B_unit; rewrite -[X in _ *m X](invmxK B).
by rewrite horner_mx_uconj ?invmxK ?unitmx_inv.
Qed.
Lemma mxminpoly_conj m n (V : 'M[F]_(m.+1, n.+1)) (f : 'M_n.+1) :
row_free V -> stablemx V f -> mxminpoly (conjmx V f) %| mxminpoly f.
Proof.
by move=> *; rewrite mxminpoly_min// horner_mx_conj// mx_root_minpoly conjmx0.
Qed.
Lemma mxminpoly_uconj n (V : 'M[F]_(n.+1)) (f : 'M_n.+1) :
V \in unitmx -> mxminpoly (conjmx V f) = mxminpoly f.
Proof.
have simp := (row_free_unit, stablemx_unit, unitmx_inv, unitmx1).
move=> Vu; apply/eqP; rewrite -eqp_monic ?mxminpoly_monic// /eqp.
apply/andP; split; first by rewrite mxminpoly_conj ?simp.
by rewrite -[f in X in X %| _](conjmxK _ Vu) mxminpoly_conj ?simp.
Qed.
Section fixed_stablemx_space.
Variables (m n : nat).
Implicit Types (V : 'M[F]_(m, n)) (f : 'M[F]_n).
Implicit Types (a : F) (p : {poly F}).
Section Sub.
Variable (k : nat).
Implicit Types (W : 'M[F]_(k, m)).
Lemma sub_kermxpoly_conjmx V f p W : stablemx V f -> row_free V ->
(W <= kermxpoly (conjmx V f) p)%MS = (W *m V <= kermxpoly f p)%MS.
Proof.
move: n m => [|n'] [|m']// in V f W *; rewrite ?thinmx0// => fV rfV.
- by rewrite /row_free mxrank0 in rfV.
- by rewrite mul0mx !sub0mx.
- apply/sub_kermxP/sub_kermxP; rewrite horner_mx_conj//; last first.
by move=> /(congr1 (mulmxr (pinvmx V)))/=; rewrite mul0mx !mulmxA.
move=> /(congr1 (mulmxr V))/=; rewrite ![W *m _]mulmxA ?mul0mx mulmxKpV//.
by rewrite -mulmxA mulmx_sub// horner_mx_stable//.
Qed.
Lemma sub_eigenspace_conjmx V f a W : stablemx V f -> row_free V ->
(W <= eigenspace (conjmx V f) a)%MS = (W *m V <= eigenspace f a)%MS.
Proof. by move=> fV rfV; rewrite !eigenspace_poly sub_kermxpoly_conjmx. Qed.
End Sub.
Lemma eigenpoly_conjmx V f : stablemx V f -> row_free V ->
{subset eigenpoly (conjmx V f) <= eigenpoly f}.
Proof.
move=> fV rfV a /eigenpolyP [x]; rewrite sub_kermxpoly_conjmx//.
move=> xV_le_fa x_neq0; apply/eigenpolyP.
by exists (x *m V); rewrite ?mulmx_free_eq0.
Qed.
Lemma eigenvalue_conjmx V f : stablemx V f -> row_free V ->
{subset eigenvalue (conjmx V f) <= eigenvalue f}.
Proof.
by move=> fV rfV a; rewrite ![_ \in _]eigenvalue_poly; apply: eigenpoly_conjmx.
Qed.
Lemma conjmx_eigenvalue a V f : (V <= eigenspace f a)%MS -> row_free V ->
conjmx V f = a%:M.
Proof.
by move=> /eigenspaceP Vfa rfV; rewrite /conjmx Vfa -mul_scalar_mx mulmxKp.
Qed.
End fixed_stablemx_space.
End ConjMx.
Notation restrictmx V := (conjmx (row_base V)).
Definition similar_to {F : fieldType} {m n} (P : 'M_(m, n)) A
(C : {pred 'M[F]_m}) := C (conjmx P A).
Notation similar P A B := (similar_to P A (PredOfSimpl.coerce (pred1 B))).
Notation similar_in D A B := (exists2 P, P \in D & similar P A B).
Notation similar_in_to D A C := (exists2 P, P \in D & similar_to P A C).
Notation all_similar_to D As C := (exists2 P, P \in D & all [pred A | similar_to P A C] As).
Notation similar_diag P A := (similar_to P A is_diag_mx).
Notation diagonalizable_in D A := (similar_in_to D A is_diag_mx).
Notation diagonalizable A := (diagonalizable_in unitmx A).
Notation codiagonalizable_in D As := (all_similar_to D As is_diag_mx).
Notation codiagonalizable As := (codiagonalizable_in unitmx As).
Notation similar_trig P A := (similar_to P A is_trig_mx).
Notation trigonalizable_in D A := (similar_in_to D A is_trig_mx).
Notation trigonalizable A := (trigonalizable_in unitmx A).
Notation cotrigonalizable_in D As := (all_similar_to D As is_trig_mx).
Notation cotrigonalizable As := (cotrigonalizable_in unitmx As).
Section Similarity.
Context {F : fieldType}.
Lemma similarPp m n {P : 'M[F]_(m, n)} {A B} :
stablemx P A -> similar P A B -> P *m A = B *m P.
Proof. by move=> stablemxPA /eqP <-; rewrite mulmxKpV. Qed.
Lemma similarW m n {P : 'M[F]_(m, n)} {A B} : row_free P ->
P *m A = B *m P -> similar P A B.
Proof. by rewrite /similar_to/= /conjmx => fP ->; rewrite mulmxKp. Qed.
Section Similar.
Context {n : nat}.
Implicit Types (f g p : 'M[F]_n) (fs : seq 'M[F]_n) (d : 'rV[F]_n).
Lemma similarP {p f g} : p \in unitmx ->
reflect (p *m f = g *m p) (similar p f g).
Proof.
move=> p_unit; apply: (iffP idP); first exact/similarPp/stablemx_unit.
by apply: similarW; rewrite row_free_unit.
Qed.
Lemma similarRL {p f g} : p \in unitmx ->
reflect (g = p *m f *m invmx p) (similar p f g).
Proof. by move=> ?; apply: (iffP eqP); rewrite conjumx. Qed.
Lemma similarLR {p f g} : p \in unitmx ->
reflect (f = conjmx (invmx p) g) (similar p f g).
Proof.
by move=> pu; rewrite conjVmx//; apply: (iffP (similarRL pu)) => ->;
rewrite !mulmxA ?(mulmxK, mulmxKV, mulVmx, mulmxV, mul1mx, mulmx1).
Qed.
End Similar.
Lemma similar_mxminpoly {n} {p f g : 'M[F]_n.+1} : p \in unitmx ->
similar p f g -> mxminpoly f = mxminpoly g.
Proof. by move=> pu /eqP<-; rewrite mxminpoly_uconj. Qed.
Lemma similar_diag_row_base m n (P : 'M[F]_(m, n)) (A : 'M_n) :
similar_diag (row_base P) A = is_diag_mx (restrictmx P A).
Proof. by []. Qed.
Lemma similar_diagPp m n (P : 'M[F]_(m, n)) A :
reflect (forall i j : 'I__, i != j :> nat -> conjmx P A i j = 0)
(similar_diag P A).
Proof. exact: @is_diag_mxP. Qed.
Lemma similar_diagP n (P : 'M[F]_n) A : P \in unitmx ->
reflect (forall i j : 'I__, i != j :> nat -> (P *m A *m invmx P) i j = 0)
(similar_diag P A).
Proof. by move=> Pu; rewrite -conjumx//; exact: is_diag_mxP. Qed.
Lemma similar_diagPex {m} {n} {P : 'M[F]_(m, n)} {A} :
reflect (exists D, similar P A (diag_mx D)) (similar_diag P A).
Proof. by apply: (iffP (diag_mxP _)) => -[D]/eqP; exists D. Qed.
Lemma similar_diagLR n {P : 'M[F]_n} {A} : P \in unitmx ->
reflect (exists D, A = conjmx (invmx P) (diag_mx D)) (similar_diag P A).
Proof.
by move=> Punit; apply: (iffP similar_diagPex) => -[D /(similarLR Punit)]; exists D.
Qed.
Lemma similar_diag_mxminpoly {n} {p f : 'M[F]_n.+1}
(rs := undup [seq conjmx p f i i | i <- enum 'I_n.+1]) :
p \in unitmx -> similar_diag p f ->
mxminpoly f = \prod_(r <- rs) ('X - r%:P).
Proof.
rewrite /rs => pu /(similar_diagLR pu)[d {f rs}->].
rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag.
by rewrite [in RHS](@eq_map _ _ _ (d 0))// => i; rewrite conjmxVK// mxE eqxx.
Qed.
End Similarity.
Lemma similar_diag_sum (F : fieldType) (m n : nat) (p_ : 'I_n -> nat)
(V_ : forall i, 'M[F]_(p_ i, m)) (f : 'M[F]_m) :
mxdirect (\sum_i <<V_ i>>) ->
(forall i, stablemx (V_ i) f) ->
(forall i, row_free (V_ i)) ->
similar_diag (\mxcol_i V_ i) f = [forall i, similar_diag (V_ i) f].
Proof.
move=> Vd Vf rfV; have aVf : stablemx (\mxcol_i V_ i) f.
rewrite (eqmx_stable _ (eqmx_col _)) stablemx_sums//.
by move=> i; rewrite (eqmx_stable _ (genmxE _)).
apply/similar_diagPex/'forall_similar_diagPex => /=
[[D /(similarPp aVf) +] i|/(_ _)/sigW Dof].
rewrite mxcol_mul -[D]submxrowK diag_mxrow mul_mxdiag_mxcol.
move=> /eq_mxcolP/(_ i); set D0 := (submxrow _ _) => VMeq.
by exists D0; apply/similarW.
exists (\mxrow_i tag (Dof i)); apply/similarW.
rewrite -row_leq_rank eqmx_col (mxdirectP Vd)/=.
by under [X in (_ <= X)%N]eq_bigr do rewrite genmxE (eqP (rfV _)).
rewrite mxcol_mul diag_mxrow mul_mxdiag_mxcol; apply: eq_mxcol => i.
by case: Dof => /= k /(similarPp); rewrite Vf => /(_ isT) ->.
Qed.
Section Diag.
Variable (F : fieldType).
Lemma codiagonalizable1 n (A : 'M[F]_n) :
codiagonalizable [:: A] <-> diagonalizable A.
Proof. by split=> -[P Punit PA]; exists P; move: PA; rewrite //= andbT. Qed.
Lemma codiagonalizablePfull n (As : seq 'M[F]_n) :
codiagonalizable As <-> exists m,
exists2 P : 'M_(m, n), row_full P & all [pred A | similar_diag P A] As.
Proof.
split => [[P Punit SPA]|[m [P Pfull SPA]]].
by exists n => //; exists P; rewrite ?row_full_unit.
have Qfull := fullrowsub_unit Pfull.
exists (rowsub (fullrankfun Pfull) P) => //; apply/allP => A AAs/=.
have /allP /(_ _ AAs)/= /similar_diagPex[d /similarPp] := SPA.
rewrite submx_full// => /(_ isT) PA_eq.
apply/similar_diagPex; exists (colsub (fullrankfun Pfull) d).
apply/similarP => //; apply/row_matrixP => i.
rewrite !row_mul row_diag_mx -scalemxAl -rowE !row_rowsub !mxE.
have /(congr1 (row (fullrankfun Pfull i))) := PA_eq.
by rewrite !row_mul row_diag_mx -scalemxAl -rowE => ->.
Qed.
Lemma codiagonalizable_on m n (V_ : 'I_n -> 'M[F]_m) (As : seq 'M[F]_m) :
(\sum_i V_ i :=: 1%:M)%MS -> mxdirect (\sum_i V_ i) ->
(forall i, all (fun A => stablemx (V_ i) A) As) ->
(forall i, codiagonalizable (map (restrictmx (V_ i)) As)) -> codiagonalizable As.
Proof.
move=> V1 Vdirect /(_ _)/allP AV /(_ _) /sig2W/= Pof.
pose P_ i := tag (Pof i).
have P_unit i : P_ i \in unitmx by rewrite /P_; case: {+}Pof.
have P_diag i A : A \in As -> similar_diag (P_ i *m row_base (V_ i)) A.
move=> AAs; rewrite /P_; case: {+}Pof => /= P Punit.
rewrite all_map => /allP/(_ A AAs); rewrite /similar_to/=.
by rewrite conjuMmx ?row_base_free ?stablemx_row_base ?AV.
pose P := \mxcol_i (P_ i *m row_base (V_ i)).
have P_full i : row_full (P_ i) by rewrite row_full_unit.
have PrV i : (P_ i *m row_base (V_ i) :=: V_ i)%MS.
exact/(eqmx_trans _ (eq_row_base _))/eqmxMfull.
apply/codiagonalizablePfull; eexists _; last exists P; rewrite /=.
- rewrite -sub1mx eqmx_col.
by under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1.
apply/allP => A AAs /=; rewrite similar_diag_sum.
- by apply/forallP => i; apply: P_diag.
- rewrite mxdirectE/=.
under eq_bigr do rewrite (eq_genmx (PrV _)); rewrite -genmx_sums genmxE V1.
by under eq_bigr do rewrite genmxE PrV; rewrite -(mxdirectP Vdirect)//= V1.
- by move=> i; rewrite (eqmx_stable _ (PrV _)) ?AV.
- by move=> i; rewrite /row_free eqmxMfull ?eq_row_base ?row_full_unit.
Qed.
Lemma diagonalizable_diag {n} (d : 'rV[F]_n) : diagonalizable (diag_mx d).
Proof.
by exists 1%:M; rewrite ?unitmx1// /similar_to conj1mx diag_mx_is_diag.
Qed.
Hint Resolve diagonalizable_diag : core.
Lemma diagonalizable_scalar {n} (a : F) : diagonalizable (a%:M : 'M_n).
Proof. by rewrite -diag_const_mx. Qed.
Hint Resolve diagonalizable_scalar : core.
Lemma diagonalizable0 {n} : diagonalizable (0 : 'M[F]_n).
Proof.
by rewrite (_ : 0 = 0%:M)//; apply/matrixP => i j; rewrite !mxE// mul0rn.
Qed.
Hint Resolve diagonalizable0 : core.
Lemma diagonalizablePeigen {n} {f : 'M[F]_n} :
diagonalizable f <->
exists2 rs, uniq rs & (\sum_(r <- rs) eigenspace f r :=: 1%:M)%MS.
Proof.
split=> [df|[rs urs rsP]].
suff [rs rsP] : exists rs, (\sum_(r <- rs) eigenspace f r :=: 1%:M)%MS.
exists (undup rs); rewrite ?undup_uniq//; apply: eqmx_trans rsP.
elim: rs => //= r rs IHrs; rewrite big_cons.
case: ifPn => in_rs; rewrite ?big_cons; last exact: adds_eqmx.
apply/(eqmx_trans IHrs)/eqmx_sym/addsmx_idPr.
have rrs : (index r rs < size rs)%N by rewrite index_mem.
rewrite (big_nth 0) big_mkord (sumsmx_sup (Ordinal rrs)) ?nth_index//.
move: df => [P Punit /(similar_diagLR Punit)[d ->]].
exists [seq d 0 i | i <- enum 'I_n]; rewrite big_image/=.
apply: (@eqmx_trans _ _ _ _ _ _ P); apply/eqmxP;
rewrite ?sub1mx ?submx1 ?row_full_unit//.
rewrite submx_full ?row_full_unit//=.
apply/row_subP => i; rewrite rowE (sumsmx_sup i)//.
apply/eigenspaceP; rewrite conjVmx// !mulmxA mulmxK//.
by rewrite -rowE row_diag_mx scalemxAl.
have mxdirect_eigenspaces : mxdirect (\sum_(i < size rs) eigenspace f rs`_i).
apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj.
by apply: uniqP rsij; rewrite ?inE.
rewrite (big_nth 0) big_mkord in rsP; apply/codiagonalizable1.
apply/(codiagonalizable_on _ mxdirect_eigenspaces) => // i/=.
case: n => [|n] in f {mxdirect_eigenspaces} rsP *.
by rewrite thinmx0 sub0mx.
by rewrite comm_mx_stable_eigenspace.
apply/codiagonalizable1.
by rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free.
Qed.
Lemma diagonalizableP n' (n := n'.+1) (f : 'M[F]_n) :
diagonalizable f <->
exists2 rs, uniq rs & mxminpoly f %| \prod_(x <- rs) ('X - x%:P).
Proof.
split=> [[P Punit /similar_diagPex[d /(similarLR Punit)->]]|].
rewrite mxminpoly_uconj ?unitmx_inv// mxminpoly_diag.
by eexists; [|by []]; rewrite undup_uniq.
move=> [rs rsU rsP]; apply: diagonalizablePeigen.2.
exists rs => //.
rewrite (big_nth 0) big_mkord (eq_bigr _ (fun _ _ => eigenspace_poly _ _)).
apply: (eqmx_trans (eqmx_sym (kermxpoly_prod _ _)) (kermxpoly_min _)).
by move=> i j _ _; rewrite coprimep_XsubC root_XsubC nth_uniq.
by rewrite (big_nth 0) big_mkord in rsP.
Qed.
Lemma diagonalizable_conj_diag m n (V : 'M[F]_(m, n)) (d : 'rV[F]_n) :
stablemx V (diag_mx d) -> row_free V -> diagonalizable (conjmx V (diag_mx d)).
Proof.
(move: m n => [|m] [|n] in V d *; rewrite ?thinmx0; [by []|by []| |]) => Vd rdV.
- by rewrite /row_free mxrank0 in rdV.
- apply/diagonalizableP; pose u := undup [seq d 0 i | i <- enum 'I_n.+1].
exists u; first by rewrite undup_uniq.
by rewrite (dvdp_trans (mxminpoly_conj rdV _))// mxminpoly_diag.
Qed.
Lemma codiagonalizableP n (fs : seq 'M[F]_n) :
{in fs &, forall f g, comm_mx f g} /\ (forall f, f \in fs -> diagonalizable f)
<-> codiagonalizable fs.
Proof.
split => [cdfs|[P Punit /allP/= fsD]]/=; last first.
split; last by exists P; rewrite // fsD.
move=> f g ffs gfs; move=> /(_ _ _)/similar_diagPex/sigW in fsD.
have [[df /similarLR->//] [dg /similarLR->//]] := (fsD _ ffs, fsD _ gfs).
by rewrite /comm_mx -!conjmxM 1?diag_mxC// inE stablemx_unit ?unitmx_inv.
move: cdfs => [/(rwP (all_comm_mxP _)).1 cdfs1 cdfs2].
have [k] := ubnP (size fs); elim: k => [|k IHk]//= in n fs cdfs1 cdfs2 *.
case: fs cdfs1 cdfs2 => [|f fs]//=; first by exists 1%:M; rewrite ?unitmx1.
rewrite ltnS all_comm_mx_cons => /andP[/allP/(_ _ _)/eqP ffsC fsC dffs] fsk.
have /diagonalizablePeigen [rs urs rs1] := dffs _ (mem_head _ _).
rewrite (big_nth 0) big_mkord in rs1.
have efg (i : 'I_(size rs)) g : g \in f :: fs -> stablemx (eigenspace f rs`_i) g.
case: n => [|n'] in g f fs ffsC fsC {dffs rs1 fsk} * => g_ffs.
by rewrite thinmx0 sub0mx.
rewrite comm_mx_stable_eigenspace//.
by move: g_ffs; rewrite !inE => /predU1P [->//|/ffsC].
apply/(@codiagonalizable_on _ _ _ (_ :: _) rs1) => [|i|i /=].
- apply: mxdirect_sum_eigenspace => i j _ _ rsij; apply/val_inj.
by apply: uniqP rsij; rewrite ?inE.
- by apply/allP => g g_ffs; rewrite efg.
rewrite (@conjmx_eigenvalue _ _ _ rs`_i) ?eq_row_base ?row_base_free//.
set gs := map _ _; suff [P Punit /= Pgs] : codiagonalizable gs.
exists P; rewrite /= ?Pgs ?andbT// /similar_to.
by rewrite conjmx_scalar ?mx_scalar_is_diag// row_free_unit.
apply: IHk; rewrite ?size_map/= ?ltnS//.
apply/all_comm_mxP => _ _ /mapP[/= g gfs ->] /mapP[/= h hfs ->].
rewrite -!conjmxM ?inE ?stablemx_row_base ?efg ?inE ?gfs ?hfs ?orbT//.
by rewrite (all_comm_mxP _ fsC).
move=> _ /mapP[/= g gfs ->].
have: stablemx (row_base (eigenspace f rs`_i)) g.
by rewrite stablemx_row_base efg// inE gfs orbT.
have := dffs g; rewrite inE gfs orbT => /(_ isT) [P Punit].
move=> /similar_diagPex[D /(similarLR Punit)->] sePD.
have rfeP : row_free (row_base (eigenspace f rs`_i) *m invmx P).
by rewrite /row_free mxrankMfree ?row_free_unit ?unitmx_inv// eq_row_base.
rewrite -conjMumx ?unitmx_inv ?row_base_free//.
apply/diagonalizable_conj_diag => //.
by rewrite stablemx_comp// stablemx_unit ?unitmx_inv.
Qed.
End Diag.
|
PullbackContinuous.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.Pullback
import Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafification
import Mathlib.Algebra.Category.ModuleCat.Sheaf.PushforwardContinuous
/-!
# Pullback of sheaves of modules
Let `S` and `R` be sheaves of rings over sites `(C, J)` and `(D, K)` respectively.
Let `F : C ⥤ D` be a continuous functor between these sites, and
let `φ : S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R` be a morphism
of sheaves of rings.
In this file, we define the pullback functor for sheaves of modules
`pullback.{v} φ : SheafOfModules.{v} S ⥤ SheafOfModules.{v} R`
that is left adjoint to `pushforward.{v} φ`. We show that it exists
under suitable assumptions, and prove that the pullback of (pre)sheaves of
modules commutes with the sheafification.
-/
universe v v₁ v₂ u₁ u₂ u
open CategoryTheory
namespace SheafOfModules
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
{J : GrothendieckTopology C} {K : GrothendieckTopology D} {F : C ⥤ D}
{S : Sheaf J RingCat.{u}} {R : Sheaf K RingCat.{u}}
[Functor.IsContinuous.{u} F J K] [Functor.IsContinuous.{v} F J K]
(φ : S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R)
section
variable [(pushforward.{v} φ).IsRightAdjoint]
/-- The pullback functor `SheafOfModules S ⥤ SheafOfModules R` induced by
a morphism of sheaves of rings `S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R`,
defined as the left adjoint functor to the pushforward, when it exists. -/
noncomputable def pullback : SheafOfModules.{v} S ⥤ SheafOfModules.{v} R :=
(pushforward.{v} φ).leftAdjoint
/-- Given a continuous functor between sites `F`, and a morphism of sheaves of rings
`S ⟶ (F.sheafPushforwardContinuous RingCat.{u} J K).obj R`, this is the adjunction
between the corresponding pullback and pushforward functors on the categories
of sheaves of modules. -/
noncomputable def pullbackPushforwardAdjunction : pullback.{v} φ ⊣ pushforward.{v} φ :=
Adjunction.ofIsRightAdjoint (pushforward φ)
end
section
variable [(PresheafOfModules.pushforward.{v} φ.val).IsRightAdjoint]
[HasWeakSheafify K AddCommGrp.{v}] [K.WEqualsLocallyBijective AddCommGrp.{v}]
namespace PullbackConstruction
/-- Construction of a left adjoint to the functor `pushforward.{v} φ` by using the
pullback of presheaves of modules and the sheafification. -/
noncomputable def adjunction :
(forget S ⋙ PresheafOfModules.pullback.{v} φ.val ⋙
PresheafOfModules.sheafification (𝟙 R.val)) ⊣ pushforward.{v} φ :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun F G ↦
((PresheafOfModules.sheafificationAdjunction (𝟙 R.val)).homEquiv _ _).trans
(((PresheafOfModules.pullbackPushforwardAdjunction φ.val).homEquiv F.val G.val).trans
((fullyFaithfulForget S).homEquiv (Y := (pushforward φ).obj G)).symm)
homEquiv_naturality_left_symm := by
intros
dsimp [Functor.FullyFaithful.homEquiv]
-- these erw seem difficult to remove
erw [Adjunction.homEquiv_naturality_left_symm,
Adjunction.homEquiv_naturality_left_symm]
dsimp
simp only [Functor.map_comp, Category.assoc]
homEquiv_naturality_right := by
tauto }
end PullbackConstruction
instance : (pushforward.{v} φ).IsRightAdjoint :=
(PullbackConstruction.adjunction.{v} φ).isRightAdjoint
/-- The pullback functor on sheaves of modules can be described as a composition
of the forget functor to presheaves, the pullback on presheaves of modules, and
the sheafification functor. -/
noncomputable def pullbackIso :
pullback.{v} φ ≅
forget S ⋙ PresheafOfModules.pullback.{v} φ.val ⋙
PresheafOfModules.sheafification (𝟙 R.val) :=
Adjunction.leftAdjointUniq (pullbackPushforwardAdjunction φ)
(PullbackConstruction.adjunction φ)
section
variable [HasWeakSheafify J AddCommGrp.{v}] [J.WEqualsLocallyBijective AddCommGrp.{v}]
/-- The pullback of (pre)sheaves of modules commutes with the sheafification. -/
noncomputable def sheafificationCompPullback :
PresheafOfModules.sheafification (𝟙 S.val) ⋙ pullback.{v} φ ≅
PresheafOfModules.pullback.{v} φ.val ⋙
PresheafOfModules.sheafification (𝟙 R.val) :=
Adjunction.leftAdjointUniq
((PresheafOfModules.sheafificationAdjunction (𝟙 S.val)).comp
(pullbackPushforwardAdjunction φ))
((PresheafOfModules.pullbackPushforwardAdjunction φ.val).comp
(PresheafOfModules.sheafificationAdjunction (𝟙 R.val)))
end
end
end SheafOfModules
|
Basic.lean
|
/-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.Group.Submonoid.BigOperators
import Mathlib.Algebra.Module.Submodule.Defs
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Submodules of a module
This file contains basic results on submodules that require further theory to be defined.
As such it is a good target for organizing and splitting further.
## Tags
submodule, subspace, linear map
-/
open Function
universe u'' u' u v w
variable {G : Type u''} {S : Type u'} {R : Type u} {M : Type v} {ι : Type w}
namespace Submodule
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable {p q : Submodule R M}
@[mono]
theorem toAddSubmonoid_strictMono : StrictMono (toAddSubmonoid : Submodule R M → AddSubmonoid M) :=
fun _ _ => id
theorem toAddSubmonoid_le : p.toAddSubmonoid ≤ q.toAddSubmonoid ↔ p ≤ q :=
Iff.rfl
@[mono]
theorem toAddSubmonoid_mono : Monotone (toAddSubmonoid : Submodule R M → AddSubmonoid M) :=
toAddSubmonoid_strictMono.monotone
@[mono]
theorem toSubMulAction_strictMono :
StrictMono (toSubMulAction : Submodule R M → SubMulAction R M) := fun _ _ => id
@[mono]
theorem toSubMulAction_mono : Monotone (toSubMulAction : Submodule R M → SubMulAction R M) :=
toSubMulAction_strictMono.monotone
end Submodule
namespace Submodule
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M]
-- We can infer the module structure implicitly from the bundled submodule,
-- rather than via typeclass resolution.
variable {module_M : Module R M}
variable {p q : Submodule R M}
variable {r : R} {x y : M}
variable (p)
protected theorem sum_mem {t : Finset ι} {f : ι → M} : (∀ c ∈ t, f c ∈ p) → (∑ i ∈ t, f i) ∈ p :=
sum_mem
theorem sum_smul_mem {t : Finset ι} {f : ι → M} (r : ι → R) (hyp : ∀ c ∈ t, f c ∈ p) :
(∑ i ∈ t, r i • f i) ∈ p :=
sum_mem fun i hi => smul_mem _ _ (hyp i hi)
instance isCentralScalar [SMul S R] [SMul S M] [IsScalarTower S R M] [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M]
[IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S p :=
p.toSubMulAction.isCentralScalar
instance noZeroSMulDivisors [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R p :=
⟨fun {c} {x : p} h =>
have : c = 0 ∨ (x : M) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg Subtype.val h)
this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩
section AddAction
/-! ### Additive actions by `Submodule`s
These instances transfer the action by an element `m : M` of an `R`-module `M` written as `m +ᵥ a`
onto the action by an element `s : S` of a submodule `S : Submodule R M` such that
`s +ᵥ a = (s : M) +ᵥ a`.
These instances work particularly well in conjunction with `AddGroup.toAddAction`, enabling
`s +ᵥ m` as an alias for `↑s + m`.
-/
variable {α β : Type*}
instance [VAdd M α] : VAdd p α :=
p.toAddSubmonoid.vadd
instance vaddCommClass [VAdd M β] [VAdd α β] [VAddCommClass M α β] : VAddCommClass p α β :=
⟨fun a => vadd_comm (a : M)⟩
instance [VAdd M α] [FaithfulVAdd M α] : FaithfulVAdd p α :=
⟨fun h => Subtype.ext <| eq_of_vadd_eq_vadd h⟩
variable {p}
theorem vadd_def [VAdd M α] (g : p) (m : α) : g +ᵥ m = (g : M) +ᵥ m :=
rfl
end AddAction
end AddCommMonoid
section AddCommGroup
variable [Ring R] [AddCommGroup M]
variable {module_M : Module R M}
variable (p p' : Submodule R M)
variable {r : R} {x y : M}
@[mono]
theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : Submodule R M → AddSubgroup M) :=
fun _ _ => id
theorem toAddSubgroup_le : p.toAddSubgroup ≤ p'.toAddSubgroup ↔ p ≤ p' :=
Iff.rfl
@[mono]
theorem toAddSubgroup_mono : Monotone (toAddSubgroup : Submodule R M → AddSubgroup M) :=
toAddSubgroup_strictMono.monotone
@[gcongr]
protected alias ⟨_, _root_.GCongr.Submodule.toAddSubgroup_le⟩ := Submodule.toAddSubgroup_le
-- See `neg_coe_set`
theorem neg_coe : -(p : Set M) = p :=
Set.ext fun _ => p.neg_mem_iff
end AddCommGroup
section IsDomain
variable [Ring R] [IsDomain R]
variable [AddCommGroup M] [Module R M] {b : ι → M}
theorem notMem_of_ortho {x : M} {N : Submodule R M}
(ortho : ∀ (c : R), ∀ y ∈ N, c • x + y = (0 : M) → c = 0) : x ∉ N := by
intro hx
simpa using ortho (-1) x hx
@[deprecated (since := "2025-05-23")] alias not_mem_of_ortho := notMem_of_ortho
theorem ne_zero_of_ortho {x : M} {N : Submodule R M}
(ortho : ∀ (c : R), ∀ y ∈ N, c • x + y = (0 : M) → c = 0) : x ≠ 0 :=
mt (fun h => show x ∈ N from h.symm ▸ N.zero_mem) (notMem_of_ortho ortho)
end IsDomain
end Submodule
namespace Submodule
variable [DivisionSemiring S] [Semiring R] [AddCommMonoid M] [Module R M]
variable [SMul S R] [Module S M] [IsScalarTower S R M]
variable (p : Submodule R M) {s : S} {x y : M}
theorem smul_mem_iff (s0 : s ≠ 0) : s • x ∈ p ↔ x ∈ p :=
p.toSubMulAction.smul_mem_iff s0
end Submodule
/-- Subspace of a vector space. Defined to equal `Submodule`. -/
abbrev Subspace (R : Type u) (M : Type v) [DivisionRing R] [AddCommGroup M] [Module R M] :=
Submodule R M
|
Uniform.lean
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies
-/
import Mathlib.Analysis.Normed.Group.Continuity
import Mathlib.Topology.Algebra.IsUniformGroup.Basic
import Mathlib.Topology.MetricSpace.Algebra
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Normed groups are uniform groups
This file proves lipschitzness of normed group operations and shows that normed groups are uniform
groups.
-/
variable {𝓕 E F : Type*}
open Filter Function Metric Bornology
open scoped ENNReal NNReal Uniformity Pointwise Topology
section SeminormedGroup
variable [SeminormedGroup E] [SeminormedGroup F] {s : Set E} {a b : E} {r : ℝ}
@[to_additive]
instance NormedGroup.to_isIsometricSMul_right : IsIsometricSMul Eᵐᵒᵖ E :=
⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩
@[to_additive]
theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) :
‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right]
@[to_additive (attr := simp) norm_map]
theorem norm_map' [FunLike 𝓕 E F] [IsometryClass 𝓕 E F] [OneHomClass 𝓕 E F] (f : 𝓕) (x : E) :
‖f x‖ = ‖x‖ :=
(IsometryClass.isometry f).norm_map_of_map_one (map_one f) x
@[to_additive (attr := simp) nnnorm_map]
theorem nnnorm_map' [FunLike 𝓕 E F] [IsometryClass 𝓕 E F] [OneHomClass 𝓕 E F] (f : 𝓕) (x : E) :
‖f x‖₊ = ‖x‖₊ :=
NNReal.eq <| norm_map' f x
@[to_additive (attr := simp)]
theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by
rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul]
@[to_additive (attr := simp)]
theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by
rw [dist_comm, dist_mul_self_right]
@[to_additive (attr := simp)]
theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by
rw [← dist_mul_right _ _ b, div_mul_cancel]
@[to_additive (attr := simp)]
theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by
rw [← dist_mul_right _ _ c, div_mul_cancel]
open Finset
variable [FunLike 𝓕 E F]
/-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that
for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of
(semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/
@[to_additive /-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant
`C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of
(semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/]
theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f :=
LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive]
theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} :
LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by
simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div]
alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le
attribute [to_additive] LipschitzOnWith.norm_div_le
@[to_additive]
theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s)
(ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r :=
(h.norm_div_le ha hb).trans <| by gcongr
@[to_additive]
theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} :
LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by
simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div]
alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le
attribute [to_additive] LipschitzWith.norm_div_le
@[to_additive]
theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f)
(hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r :=
(h.norm_div_le _ _).trans <| by gcongr
/-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that
for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/
@[to_additive /-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant
`C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/]
theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f :=
(MonoidHomClass.lipschitz_of_bound f C h).continuous
@[to_additive]
theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ)
(h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f :=
(MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous
@[to_additive]
theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) :
Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by
simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div]
refine ⟨fun h x => ?_, fun h x y => h _⟩
simpa using h x 1
alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm
attribute [to_additive] MonoidHomClass.isometry_of_norm
section NNNorm
@[to_additive]
theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0)
(h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f :=
@Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h
@[to_additive]
theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0}
(h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f :=
AntilipschitzWith.of_le_mul_dist fun x y => by
simpa only [dist_eq_norm_div, map_div] using h (x / y)
@[to_additive LipschitzWith.norm_le_mul]
theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1)
(x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1
@[to_additive LipschitzWith.nnorm_le_mul]
theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1)
(x) : ‖f x‖₊ ≤ K * ‖x‖₊ :=
h.norm_le_mul' hf x
@[to_additive AntilipschitzWith.le_mul_norm]
theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f)
(hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by
simpa only [dist_one_right, hf] using h.le_mul_dist x 1
@[to_additive AntilipschitzWith.le_mul_nnnorm]
theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f)
(hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ :=
h.le_mul_norm' hf x
@[to_additive]
theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0}
(h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ :=
h.le_mul_nnnorm' (map_one f) x
@[to_additive]
theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) :
‖f x‖₊ = ‖x‖₊ :=
Subtype.ext <| hi.norm_map_of_map_one h₁ x
end NNNorm
@[to_additive lipschitzWith_one_norm]
theorem lipschitzWith_one_norm' : LipschitzWith 1 (norm : E → ℝ) := by
simpa using LipschitzWith.dist_right (1 : E)
@[to_additive lipschitzWith_one_nnnorm]
theorem lipschitzWith_one_nnnorm' : LipschitzWith 1 (NNNorm.nnnorm : E → ℝ≥0) :=
lipschitzWith_one_norm'
@[to_additive uniformContinuous_norm]
theorem uniformContinuous_norm' : UniformContinuous (norm : E → ℝ) :=
lipschitzWith_one_norm'.uniformContinuous
@[to_additive uniformContinuous_nnnorm]
theorem uniformContinuous_nnnorm' : UniformContinuous fun a : E => ‖a‖₊ :=
uniformContinuous_norm'.subtype_mk _
end SeminormedGroup
section SeminormedCommGroup
variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a₁ a₂ b₁ b₂ : E} {r₁ r₂ : ℝ}
@[to_additive]
instance NormedGroup.to_isIsometricSMul_left : IsIsometricSMul E E :=
⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩
@[to_additive (attr := simp)]
theorem dist_self_mul_right (a b : E) : dist a (a * b) = ‖b‖ := by
rw [← dist_one_left, ← dist_mul_left a 1 b, mul_one]
@[to_additive (attr := simp)]
theorem dist_self_mul_left (a b : E) : dist (a * b) a = ‖b‖ := by
rw [dist_comm, dist_self_mul_right]
@[to_additive (attr := simp 1001)] -- Increase priority because `simp` can prove this
theorem dist_self_div_right (a b : E) : dist a (a / b) = ‖b‖ := by
rw [div_eq_mul_inv, dist_self_mul_right, norm_inv']
@[to_additive (attr := simp 1001)] -- Increase priority because `simp` can prove this
theorem dist_self_div_left (a b : E) : dist (a / b) a = ‖b‖ := by
rw [dist_comm, dist_self_div_right]
@[to_additive]
theorem dist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ * a₂) (b₁ * b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by
simpa only [dist_mul_left, dist_mul_right] using dist_triangle (a₁ * a₂) (b₁ * a₂) (b₁ * b₂)
@[to_additive]
theorem dist_mul_mul_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) :
dist (a₁ * a₂) (b₁ * b₂) ≤ r₁ + r₂ :=
(dist_mul_mul_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂
@[to_additive]
theorem dist_div_div_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ / a₂) (b₁ / b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by
simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le a₁ a₂⁻¹ b₁ b₂⁻¹
@[to_additive]
theorem dist_div_div_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) :
dist (a₁ / a₂) (b₁ / b₂) ≤ r₁ + r₂ :=
(dist_div_div_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂
@[to_additive]
theorem abs_dist_sub_le_dist_mul_mul (a₁ a₂ b₁ b₂ : E) :
|dist a₁ b₁ - dist a₂ b₂| ≤ dist (a₁ * a₂) (b₁ * b₂) := by
simpa only [dist_mul_left, dist_mul_right, dist_comm b₂] using
abs_dist_sub_le (a₁ * a₂) (b₁ * b₂) (b₁ * a₂)
open Finset
@[to_additive]
theorem nndist_mul_mul_le (a₁ a₂ b₁ b₂ : E) :
nndist (a₁ * a₂) (b₁ * b₂) ≤ nndist a₁ b₁ + nndist a₂ b₂ :=
NNReal.coe_le_coe.1 <| dist_mul_mul_le a₁ a₂ b₁ b₂
@[to_additive]
theorem edist_mul_mul_le (a₁ a₂ b₁ b₂ : E) :
edist (a₁ * a₂) (b₁ * b₂) ≤ edist a₁ b₁ + edist a₂ b₂ := by
simp only [edist_nndist]
norm_cast
apply nndist_mul_mul_le
section PseudoEMetricSpace
variable {α E : Type*} [SeminormedCommGroup E] [PseudoEMetricSpace α] {K Kf Kg : ℝ≥0}
{f g : α → E} {s : Set α}
@[to_additive (attr := simp)]
lemma lipschitzWith_inv_iff : LipschitzWith K f⁻¹ ↔ LipschitzWith K f := by simp [LipschitzWith]
@[to_additive (attr := simp)]
lemma antilipschitzWith_inv_iff : AntilipschitzWith K f⁻¹ ↔ AntilipschitzWith K f := by
simp [AntilipschitzWith]
@[to_additive (attr := simp)]
lemma lipschitzOnWith_inv_iff : LipschitzOnWith K f⁻¹ s ↔ LipschitzOnWith K f s := by
simp [LipschitzOnWith]
@[to_additive (attr := simp)]
lemma locallyLipschitz_inv_iff : LocallyLipschitz f⁻¹ ↔ LocallyLipschitz f := by
simp [LocallyLipschitz]
@[to_additive (attr := simp)]
lemma locallyLipschitzOn_inv_iff : LocallyLipschitzOn s f⁻¹ ↔ LocallyLipschitzOn s f := by
simp [LocallyLipschitzOn]
@[to_additive] alias ⟨LipschitzWith.of_inv, LipschitzWith.inv⟩ := lipschitzWith_inv_iff
@[to_additive] alias ⟨AntilipschitzWith.of_inv, AntilipschitzWith.inv⟩ := antilipschitzWith_inv_iff
@[to_additive] alias ⟨LipschitzOnWith.of_inv, LipschitzOnWith.inv⟩ := lipschitzOnWith_inv_iff
@[to_additive] alias ⟨LocallyLipschitz.of_inv, LocallyLipschitz.inv⟩ := locallyLipschitz_inv_iff
@[to_additive]
alias ⟨LocallyLipschitzOn.of_inv, LocallyLipschitzOn.inv⟩ := locallyLipschitzOn_inv_iff
@[to_additive]
lemma LipschitzOnWith.mul (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) :
LipschitzOnWith (Kf + Kg) (fun x ↦ f x * g x) s := fun x hx y hy ↦
calc
edist (f x * g x) (f y * g y) ≤ edist (f x) (f y) + edist (g x) (g y) :=
edist_mul_mul_le _ _ _ _
_ ≤ Kf * edist x y + Kg * edist x y := add_le_add (hf hx hy) (hg hx hy)
_ = (Kf + Kg) * edist x y := (add_mul _ _ _).symm
@[to_additive]
lemma LipschitzWith.mul (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (Kf + Kg) fun x ↦ f x * g x := by
simpa [← lipschitzOnWith_univ] using hf.lipschitzOnWith.mul hg.lipschitzOnWith
@[to_additive]
lemma LocallyLipschitzOn.mul (hf : LocallyLipschitzOn s f) (hg : LocallyLipschitzOn s g) :
LocallyLipschitzOn s fun x ↦ f x * g x := fun x hx ↦ by
obtain ⟨Kf, t, ht, hKf⟩ := hf hx
obtain ⟨Kg, u, hu, hKg⟩ := hg hx
exact ⟨Kf + Kg, t ∩ u, inter_mem ht hu,
(hKf.mono Set.inter_subset_left).mul (hKg.mono Set.inter_subset_right)⟩
@[to_additive]
lemma LocallyLipschitz.mul (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz fun x ↦ f x * g x := by
simpa [← locallyLipschitzOn_univ] using hf.locallyLipschitzOn.mul hg.locallyLipschitzOn
@[to_additive]
lemma LipschitzOnWith.div (hf : LipschitzOnWith Kf f s) (hg : LipschitzOnWith Kg g s) :
LipschitzOnWith (Kf + Kg) (fun x ↦ f x / g x) s := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
theorem LipschitzWith.div (hf : LipschitzWith Kf f) (hg : LipschitzWith Kg g) :
LipschitzWith (Kf + Kg) fun x => f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
lemma LocallyLipschitzOn.div (hf : LocallyLipschitzOn s f) (hg : LocallyLipschitzOn s g) :
LocallyLipschitzOn s fun x ↦ f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
@[to_additive]
lemma LocallyLipschitz.div (hf : LocallyLipschitz f) (hg : LocallyLipschitz g) :
LocallyLipschitz fun x ↦ f x / g x := by
simpa only [div_eq_mul_inv] using hf.mul hg.inv
namespace AntilipschitzWith
@[to_additive]
theorem mul_lipschitzWith (hf : AntilipschitzWith Kf f) (hg : LipschitzWith Kg g) (hK : Kg < Kf⁻¹) :
AntilipschitzWith (Kf⁻¹ - Kg)⁻¹ fun x => f x * g x := by
letI : PseudoMetricSpace α := PseudoEMetricSpace.toPseudoMetricSpace hf.edist_ne_top
refine AntilipschitzWith.of_le_mul_dist fun x y => ?_
rw [NNReal.coe_inv, ← _root_.div_eq_inv_mul]
rw [le_div_iff₀ (NNReal.coe_pos.2 <| tsub_pos_iff_lt.2 hK)]
rw [mul_comm, NNReal.coe_sub hK.le, sub_mul]
calc
↑Kf⁻¹ * dist x y - Kg * dist x y ≤ dist (f x) (f y) - dist (g x) (g y) :=
sub_le_sub (hf.mul_le_dist x y) (hg.dist_le_mul x y)
_ ≤ _ := le_trans (le_abs_self _) (abs_dist_sub_le_dist_mul_mul _ _ _ _)
@[to_additive]
theorem mul_div_lipschitzWith (hf : AntilipschitzWith Kf f) (hg : LipschitzWith Kg (g / f))
(hK : Kg < Kf⁻¹) : AntilipschitzWith (Kf⁻¹ - Kg)⁻¹ g := by
simpa only [Pi.div_apply, mul_div_cancel] using hf.mul_lipschitzWith hg hK
@[to_additive le_mul_norm_sub]
theorem le_mul_norm_div {f : E → F} (hf : AntilipschitzWith K f) (x y : E) :
‖x / y‖ ≤ K * ‖f x / f y‖ := by simp [← dist_eq_norm_div, hf.le_mul_dist x y]
end AntilipschitzWith
end PseudoEMetricSpace
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) SeminormedCommGroup.to_lipschitzMul : LipschitzMul E :=
⟨⟨1 + 1, LipschitzWith.prod_fst.mul LipschitzWith.prod_snd⟩⟩
-- See note [lower instance priority]
/-- A seminormed group is a uniform group, i.e., multiplication and division are uniformly
continuous. -/
@[to_additive /-- A seminormed group is a uniform additive group, i.e., addition and subtraction are
uniformly continuous. -/]
instance (priority := 100) SeminormedCommGroup.to_isUniformGroup : IsUniformGroup E :=
⟨(LipschitzWith.prod_fst.div LipschitzWith.prod_snd).uniformContinuous⟩
-- short-circuit type class inference
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) SeminormedCommGroup.toIsTopologicalGroup : IsTopologicalGroup E :=
inferInstance
/-! ### SeparationQuotient -/
namespace SeparationQuotient
@[to_additive instNorm]
instance instMulNorm : Norm (SeparationQuotient E) where
norm := lift Norm.norm fun _ _ h => h.norm_eq_norm'
set_option linter.docPrime false in
@[to_additive (attr := simp) norm_mk]
theorem norm_mk' (p : E) : ‖mk p‖ = ‖p‖ := rfl
@[to_additive]
instance : NormedCommGroup (SeparationQuotient E) where
__ : CommGroup (SeparationQuotient E) := instCommGroup
dist_eq := Quotient.ind₂ dist_eq_norm_div
@[to_additive]
theorem mk_eq_one_iff {p : E} : mk p = 1 ↔ ‖p‖ = 0 := by
rw [← norm_mk', norm_eq_zero']
set_option linter.docPrime false in
@[to_additive (attr := simp) nnnorm_mk]
theorem nnnorm_mk' (p : E) : ‖mk p‖₊ = ‖p‖₊ := rfl
end SeparationQuotient
@[to_additive]
theorem cauchySeq_prod_of_eventually_eq {u v : ℕ → E} {N : ℕ} (huv : ∀ n ≥ N, u n = v n)
(hv : CauchySeq fun n => ∏ k ∈ range (n + 1), v k) :
CauchySeq fun n => ∏ k ∈ range (n + 1), u k := by
let d : ℕ → E := fun n => ∏ k ∈ range (n + 1), u k / v k
rw [show (fun n => ∏ k ∈ range (n + 1), u k) = d * fun n => ∏ k ∈ range (n + 1), v k
by ext n; simp [d]]
suffices ∀ n ≥ N, d n = d N from (tendsto_atTop_of_eventually_const this).cauchySeq.mul hv
intro n hn
dsimp [d]
rw [eventually_constant_prod _ (add_le_add_right hn 1)]
intro m hm
simp [huv m (le_of_lt hm)]
@[to_additive CauchySeq.norm_bddAbove]
lemma CauchySeq.mul_norm_bddAbove {G : Type*} [SeminormedGroup G] {u : ℕ → G}
(hu : CauchySeq u) : BddAbove (Set.range (fun n ↦ ‖u n‖)) := by
obtain ⟨C, -, hC⟩ := cauchySeq_bdd hu
simp_rw [SeminormedGroup.dist_eq] at hC
have : ∀ n, ‖u n‖ ≤ C + ‖u 0‖ := by
intro n
rw [add_comm]
refine (norm_le_norm_add_norm_div' (u n) (u 0)).trans ?_
simp [(hC _ _).le]
rw [bddAbove_def]
exact ⟨C + ‖u 0‖, by simpa using this⟩
end SeminormedCommGroup
|
Contraction.lean
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold
import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic
import Mathlib.LinearAlgebra.Dual.Defs
/-!
# Contraction in Clifford Algebras
This file contains some of the results from [grinberg_clifford_2016][].
The key result is `CliffordAlgebra.equivExterior`.
## Main definitions
* `CliffordAlgebra.contractLeft`: contract a multivector by a `Module.Dual R M` on the left.
* `CliffordAlgebra.contractRight`: contract a multivector by a `Module.Dual R M` on the right.
* `CliffordAlgebra.changeForm`: convert between two algebras of different quadratic form, sending
vectors to vectors. The difference of the quadratic forms must be a bilinear form.
* `CliffordAlgebra.equivExterior`: in characteristic not-two, the `CliffordAlgebra Q` is
isomorphic as a module to the exterior algebra.
## Implementation notes
This file somewhat follows [grinberg_clifford_2016][], although we are missing some of the induction
principles needed to prove many of the results. Here, we avoid the quotient-based approach described
in [grinberg_clifford_2016][], instead directly constructing our objects using the universal
property.
Note that [grinberg_clifford_2016][] concludes that its contents are not novel, and are in fact just
a rehash of parts of [bourbaki2007][]; we should at some point consider swapping our references to
refer to the latter.
Within this file, we use the local notation
* `x ⌊ d` for `contractRight x d`
* `d ⌋ x` for `contractLeft d x`
-/
open LinearMap (BilinMap BilinForm)
universe u1 u2 u3
variable {R : Type u1} [CommRing R]
variable {M : Type u2} [AddCommGroup M] [Module R M]
variable (Q : QuadraticForm R M)
namespace CliffordAlgebra
section contractLeft
variable (d d' : Module.Dual R M)
/-- Auxiliary construction for `CliffordAlgebra.contractLeft` -/
@[simps!]
def contractLeftAux (d : Module.Dual R M) :
M →ₗ[R] CliffordAlgebra Q × CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q :=
haveI v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q
d.smulRight (LinearMap.fst _ (CliffordAlgebra Q) (CliffordAlgebra Q)) -
v_mul.compl₂ (LinearMap.snd _ (CliffordAlgebra Q) _)
theorem contractLeftAux_contractLeftAux (v : M) (x : CliffordAlgebra Q) (fx : CliffordAlgebra Q) :
contractLeftAux Q d v (ι Q v * x, contractLeftAux Q d v (x, fx)) = Q v • fx := by
simp only [contractLeftAux_apply_apply]
rw [mul_sub, ← mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← sub_add, mul_smul_comm, sub_self,
zero_add]
variable {Q}
/-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the left.
Note that $v ⌋ x$ is spelt `contractLeft (Q.associated v) x`.
This includes [grinberg_clifford_2016][] Theorem 10.75 -/
def contractLeft : Module.Dual R M →ₗ[R] CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q where
toFun d := foldr' Q (contractLeftAux Q d) (contractLeftAux_contractLeftAux Q d) 0
map_add' d₁ d₂ :=
LinearMap.ext fun x => by
rw [LinearMap.add_apply]
induction x using CliffordAlgebra.left_induction with
| algebraMap => simp_rw [foldr'_algebraMap, smul_zero, zero_add]
| add _ _ hx hy => rw [map_add, map_add, map_add, add_add_add_comm, hx, hy]
| ι_mul _ _ hx =>
rw [foldr'_ι_mul, foldr'_ι_mul, foldr'_ι_mul, hx]
dsimp only [contractLeftAux_apply_apply]
rw [sub_add_sub_comm, mul_add, LinearMap.add_apply, add_smul]
map_smul' c d :=
LinearMap.ext fun x => by
rw [LinearMap.smul_apply, RingHom.id_apply]
induction x using CliffordAlgebra.left_induction with
| algebraMap => simp_rw [foldr'_algebraMap, smul_zero]
| add _ _ hx hy => rw [map_add, map_add, smul_add, hx, hy]
| ι_mul _ _ hx =>
rw [foldr'_ι_mul, foldr'_ι_mul, hx]
dsimp only [contractLeftAux_apply_apply]
rw [LinearMap.smul_apply, smul_assoc, mul_smul_comm, smul_sub]
/-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the
right.
Note that $x ⌊ v$ is spelt `contractRight x (Q.associated v)`.
This includes [grinberg_clifford_2016][] Theorem 16.75 -/
def contractRight : CliffordAlgebra Q →ₗ[R] Module.Dual R M →ₗ[R] CliffordAlgebra Q :=
LinearMap.flip (LinearMap.compl₂ (LinearMap.compr₂ contractLeft reverse) reverse)
theorem contractRight_eq (x : CliffordAlgebra Q) :
contractRight (Q := Q) x d = reverse (contractLeft (R := R) (M := M) d <| reverse x) :=
rfl
local infixl:70 "⌋" => contractLeft (R := R) (M := M)
local infixl:70 "⌊" => contractRight (R := R) (M := M) (Q := Q)
/-- This is [grinberg_clifford_2016][] Theorem 6 -/
theorem contractLeft_ι_mul (a : M) (b : CliffordAlgebra Q) :
d⌋(ι Q a * b) = d a • b - ι Q a * (d⌋b) := by
-- Porting note: Lean cannot figure out anymore the third argument
refine foldr'_ι_mul _ _ ?_ _ _ _
exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx
/-- This is [grinberg_clifford_2016][] Theorem 12 -/
theorem contractRight_mul_ι (a : M) (b : CliffordAlgebra Q) :
b * ι Q a⌊d = d a • b - b⌊d * ι Q a := by
rw [contractRight_eq, reverse.map_mul, reverse_ι, contractLeft_ι_mul, map_sub, map_smul,
reverse_reverse, reverse.map_mul, reverse_ι, contractRight_eq]
theorem contractLeft_algebraMap_mul (r : R) (b : CliffordAlgebra Q) :
d⌋(algebraMap _ _ r * b) = algebraMap _ _ r * (d⌋b) := by
rw [← Algebra.smul_def, map_smul, Algebra.smul_def]
theorem contractLeft_mul_algebraMap (a : CliffordAlgebra Q) (r : R) :
d⌋(a * algebraMap _ _ r) = d⌋a * algebraMap _ _ r := by
rw [← Algebra.commutes, contractLeft_algebraMap_mul, Algebra.commutes]
theorem contractRight_algebraMap_mul (r : R) (b : CliffordAlgebra Q) :
algebraMap _ _ r * b⌊d = algebraMap _ _ r * (b⌊d) := by
rw [← Algebra.smul_def, LinearMap.map_smul₂, Algebra.smul_def]
theorem contractRight_mul_algebraMap (a : CliffordAlgebra Q) (r : R) :
a * algebraMap _ _ r⌊d = a⌊d * algebraMap _ _ r := by
rw [← Algebra.commutes, contractRight_algebraMap_mul, Algebra.commutes]
variable (Q)
@[simp]
theorem contractLeft_ι (x : M) : d⌋ι Q x = algebraMap R _ (d x) := by
-- Porting note: Lean cannot figure out anymore the third argument
refine (foldr'_ι _ _ ?_ _ _).trans <| by
simp_rw [contractLeftAux_apply_apply, mul_zero, sub_zero,
Algebra.algebraMap_eq_smul_one]
exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx
@[simp]
theorem contractRight_ι (x : M) : ι Q x⌊d = algebraMap R _ (d x) := by
rw [contractRight_eq, reverse_ι, contractLeft_ι, reverse.commutes]
@[simp]
theorem contractLeft_algebraMap (r : R) : d⌋algebraMap R (CliffordAlgebra Q) r = 0 := by
-- Porting note: Lean cannot figure out anymore the third argument
refine (foldr'_algebraMap _ _ ?_ _ _).trans <| smul_zero _
exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx
@[simp]
theorem contractRight_algebraMap (r : R) : algebraMap R (CliffordAlgebra Q) r⌊d = 0 := by
rw [contractRight_eq, reverse.commutes, contractLeft_algebraMap, map_zero]
@[simp]
theorem contractLeft_one : d⌋(1 : CliffordAlgebra Q) = 0 := by
simpa only [map_one] using contractLeft_algebraMap Q d 1
@[simp]
theorem contractRight_one : (1 : CliffordAlgebra Q)⌊d = 0 := by
simpa only [map_one] using contractRight_algebraMap Q d 1
variable {Q}
/-- This is [grinberg_clifford_2016][] Theorem 7 -/
theorem contractLeft_contractLeft (x : CliffordAlgebra Q) : d⌋(d⌋x) = 0 := by
induction x using CliffordAlgebra.left_induction with
| algebraMap => simp_rw [contractLeft_algebraMap, map_zero]
| add _ _ hx hy => rw [map_add, map_add, hx, hy, add_zero]
| ι_mul _ _ hx =>
rw [contractLeft_ι_mul, map_sub, contractLeft_ι_mul, hx, LinearMap.map_smul,
mul_zero, sub_zero, sub_self]
/-- This is [grinberg_clifford_2016][] Theorem 13 -/
theorem contractRight_contractRight (x : CliffordAlgebra Q) : x⌊d⌊d = 0 := by
rw [contractRight_eq, contractRight_eq, reverse_reverse, contractLeft_contractLeft, map_zero]
/-- This is [grinberg_clifford_2016][] Theorem 8 -/
theorem contractLeft_comm (x : CliffordAlgebra Q) : d⌋(d'⌋x) = -(d'⌋(d⌋x)) := by
induction x using CliffordAlgebra.left_induction with
| algebraMap => simp_rw [contractLeft_algebraMap, map_zero, neg_zero]
| add _ _ hx hy => rw [map_add, map_add, map_add, map_add, hx, hy, neg_add]
| ι_mul _ _ hx =>
simp only [contractLeft_ι_mul, map_sub, LinearMap.map_smul]
rw [neg_sub, sub_sub_eq_add_sub, hx, mul_neg, ← sub_eq_add_neg]
/-- This is [grinberg_clifford_2016][] Theorem 14 -/
theorem contractRight_comm (x : CliffordAlgebra Q) : x⌊d⌊d' = -(x⌊d'⌊d) := by
rw [contractRight_eq, contractRight_eq, contractRight_eq, contractRight_eq, reverse_reverse,
reverse_reverse, contractLeft_comm, map_neg]
/- TODO:
lemma contractRight_contractLeft (x : CliffordAlgebra Q) : (d ⌋ x) ⌊ d' = d ⌋ (x ⌊ d') :=
-/
end contractLeft
local infixl:70 "⌋" => contractLeft
local infixl:70 "⌊" => contractRight
/-- Auxiliary construction for `CliffordAlgebra.changeForm` -/
@[simps!]
def changeFormAux (B : BilinForm R M) : M →ₗ[R] CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q :=
haveI v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q
v_mul - contractLeft ∘ₗ B
theorem changeFormAux_changeFormAux (B : BilinForm R M) (v : M) (x : CliffordAlgebra Q) :
changeFormAux Q B v (changeFormAux Q B v x) = (Q v - B v v) • x := by
simp only [changeFormAux_apply_apply]
rw [mul_sub, ← mul_assoc, ι_sq_scalar, map_sub, contractLeft_ι_mul, ← sub_add, sub_sub_sub_comm,
← Algebra.smul_def, sub_self, sub_zero, contractLeft_contractLeft, add_zero, sub_smul]
variable {Q}
variable {Q' Q'' : QuadraticForm R M} {B B' : BilinForm R M}
/-- Convert between two algebras of different quadratic form, sending vector to vectors, scalars to
scalars, and adjusting products by a contraction term.
This is $\lambda_B$ from [bourbaki2007][] $9 Lemma 2. -/
def changeForm (h : B.toQuadraticMap = Q' - Q) : CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q' :=
foldr Q (changeFormAux Q' B)
(fun m x =>
(changeFormAux_changeFormAux Q' B m x).trans <| by
dsimp only [← BilinMap.toQuadraticMap_apply]
rw [h, QuadraticMap.sub_apply, sub_sub_cancel])
1
/-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/
theorem changeForm.zero_proof : (0 : BilinForm R M).toQuadraticMap = Q - Q :=
(sub_self _).symm
variable (h : B.toQuadraticMap = Q' - Q) (h' : B'.toQuadraticMap = Q'' - Q')
include h h' in
/-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/
theorem changeForm.add_proof : (B + B').toQuadraticMap = Q'' - Q :=
(congr_arg₂ (· + ·) h h').trans <| sub_add_sub_cancel' _ _ _
include h in
/-- Auxiliary lemma used as an argument to `CliffordAlgebra.changeForm` -/
theorem changeForm.neg_proof : (-B).toQuadraticMap = Q - Q' :=
(congr_arg Neg.neg h).trans <| neg_sub _ _
theorem changeForm.associated_neg_proof [Invertible (2 : R)] :
(QuadraticMap.associated (R := R) (M := M) (-Q)).toQuadraticMap = 0 - Q := by
simp [QuadraticMap.toQuadraticMap_associated]
@[simp]
theorem changeForm_algebraMap (r : R) : changeForm h (algebraMap R _ r) = algebraMap R _ r :=
(foldr_algebraMap _ _ _ _ _).trans <| Eq.symm <| Algebra.algebraMap_eq_smul_one r
@[simp]
theorem changeForm_one : changeForm h (1 : CliffordAlgebra Q) = 1 := by
simpa using changeForm_algebraMap h (1 : R)
@[simp]
theorem changeForm_ι (m : M) : changeForm h (ι (M := M) Q m) = ι (M := M) Q' m :=
(foldr_ι _ _ _ _ _).trans <|
Eq.symm <| by rw [changeFormAux_apply_apply, mul_one, contractLeft_one, sub_zero]
theorem changeForm_ι_mul (m : M) (x : CliffordAlgebra Q) :
changeForm h (ι Q m * x) = ι Q' m * changeForm h x - B m⌋changeForm h x :=
(foldr_mul _ _ _ _ _ _).trans <| by rw [foldr_ι]; rfl
theorem changeForm_ι_mul_ι (m₁ m₂ : M) :
changeForm h (ι Q m₁ * ι Q m₂) = ι Q' m₁ * ι Q' m₂ - algebraMap _ _ (B m₁ m₂) := by
rw [changeForm_ι_mul, changeForm_ι, contractLeft_ι]
/-- Theorem 23 of [grinberg_clifford_2016][] -/
theorem changeForm_contractLeft (d : Module.Dual R M) (x : CliffordAlgebra Q) :
changeForm h (d⌋x) = d⌋(changeForm h x) := by
induction x using CliffordAlgebra.left_induction with
| algebraMap => simp only [contractLeft_algebraMap, changeForm_algebraMap, map_zero]
| add _ _ hx hy => rw [map_add, map_add, map_add, map_add, hx, hy]
| ι_mul _ _ hx =>
simp only [contractLeft_ι_mul, changeForm_ι_mul, map_sub, LinearMap.map_smul]
rw [← hx, contractLeft_comm, ← sub_add, sub_neg_eq_add, ← hx]
theorem changeForm_self_apply (x : CliffordAlgebra Q) : changeForm (Q' := Q)
changeForm.zero_proof x = x := by
induction x using CliffordAlgebra.left_induction with
| algebraMap => simp_rw [changeForm_algebraMap]
| add _ _ hx hy => rw [map_add, hx, hy]
| ι_mul _ _ hx => rw [changeForm_ι_mul, hx, LinearMap.zero_apply, map_zero, LinearMap.zero_apply,
sub_zero]
@[simp]
theorem changeForm_self :
changeForm changeForm.zero_proof = (LinearMap.id : CliffordAlgebra Q →ₗ[R] _) :=
LinearMap.ext <| changeForm_self_apply
/-- This is [bourbaki2007][] $9 Lemma 3. -/
theorem changeForm_changeForm (x : CliffordAlgebra Q) :
changeForm h' (changeForm h x) = changeForm (changeForm.add_proof h h') x := by
induction x using CliffordAlgebra.left_induction with
| algebraMap => simp_rw [changeForm_algebraMap]
| add _ _ hx hy => rw [map_add, map_add, map_add, hx, hy]
| ι_mul _ _ hx => rw [changeForm_ι_mul, map_sub, changeForm_ι_mul, changeForm_ι_mul, hx, sub_sub,
LinearMap.add_apply, map_add, LinearMap.add_apply, changeForm_contractLeft, hx,
add_comm (_ : CliffordAlgebra Q'')]
theorem changeForm_comp_changeForm :
(changeForm h').comp (changeForm h) = changeForm (changeForm.add_proof h h') :=
LinearMap.ext <| changeForm_changeForm _ h'
/-- Any two algebras whose quadratic forms differ by a bilinear form are isomorphic as modules.
This is $\bar \lambda_B$ from [bourbaki2007][] $9 Proposition 3. -/
@[simps apply]
def changeFormEquiv : CliffordAlgebra Q ≃ₗ[R] CliffordAlgebra Q' :=
{ changeForm h with
toFun := changeForm h
invFun := changeForm (changeForm.neg_proof h)
left_inv := fun x => by
exact (changeForm_changeForm _ _ x).trans <|
by simp_rw [(add_neg_cancel B), changeForm_self_apply]
right_inv := fun x => by
exact (changeForm_changeForm _ _ x).trans <|
by simp_rw [(neg_add_cancel B), changeForm_self_apply] }
@[simp]
theorem changeFormEquiv_symm :
(changeFormEquiv h).symm = changeFormEquiv (changeForm.neg_proof h) :=
LinearEquiv.ext fun _ => rfl
variable (Q)
/-- The module isomorphism to the exterior algebra.
Note that this holds more generally when `Q` is divisible by two, rather than only when `1` is
divisible by two; but that would be more awkward to use. -/
@[simp]
def equivExterior [Invertible (2 : R)] : CliffordAlgebra Q ≃ₗ[R] ExteriorAlgebra R M :=
changeFormEquiv changeForm.associated_neg_proof
/-- A `CliffordAlgebra` over a nontrivial ring is nontrivial, in characteristic not two. -/
instance [Nontrivial R] [Invertible (2 : R)] :
Nontrivial (CliffordAlgebra Q) := (equivExterior Q).symm.injective.nontrivial
end CliffordAlgebra
|
DirectoryDependency.lean
|
/-
Copyright (c) 2025 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Lean.Elab.Command
import Lean.Elab.ParseImportsFast
/-! # The `directoryDependency` linter
The `directoryDependency` linter detects imports between directories that are supposed to be
independent. By specifying that one directory does not import from another, we can improve the
modularity of Mathlib.
-/
-- XXX: is there a better long-time place for this
/-- Parse all imports in a text file at `path` and return just their names:
this is just a thin wrapper around `Lean.parseImports'`.
Omit `Init` (which is part of the prelude). -/
def findImports (path : System.FilePath) : IO (Array Lean.Name) := do
return (← Lean.parseImports' (← IO.FS.readFile path) path.toString).imports
|>.map (fun imp ↦ imp.module) |>.erase `Init
/-- Find the longest prefix of `n` such that `f` returns `some` (or return `none` otherwise). -/
def Lean.Name.findPrefix {α} (f : Name → Option α) (n : Name) : Option α := do
f n <|> match n with
| anonymous => none
| str n' _ => n'.findPrefix f
| num n' _ => n'.findPrefix f
/-- Make a `NameSet` containing all prefixes of `n`. -/
def Lean.Name.prefixes (n : Name) : NameSet :=
NameSet.insert (n := n) <| match n with
| anonymous => ∅
| str n' _ => n'.prefixes
| num n' _ => n'.prefixes
/-- Return the immediate prefix of `n` (if any). -/
def Lean.Name.prefix? (n : Name) : Option Name :=
match n with
| anonymous => none
| str n' _ => some n'
| num n' _ => some n'
/-- Collect all prefixes of names in `ns` into a single `NameSet`. -/
def Lean.Name.collectPrefixes (ns : Array Name) : NameSet :=
ns.foldl (fun ns n => ns.append n.prefixes) ∅
/-- Find a name in `ns` that starts with prefix `p`. -/
def Lean.Name.prefixToName (p : Name) (ns : Array Name) : Option Name :=
ns.find? p.isPrefixOf
/-- Find the dependency chain, starting at a module that imports `imported`, and ends with the
current module.
The path only contains the intermediate steps: it excludes `imported` and the current module.
-/
def Lean.Environment.importPath (env : Environment) (imported : Name) : Array Name := Id.run do
let mut result := #[]
let modData := env.header.moduleData
let modNames := env.header.moduleNames
if let some idx := env.getModuleIdx? imported then
let mut target := imported
for i in [idx.toNat + 1 : modData.size] do
if modData[i]!.imports.any (·.module == target) then
target := modNames[i]!
result := result.push modNames[i]!
return result
namespace Mathlib.Linter
open Lean Elab Command Linter
/--
The `directoryDependency` linter detects detects imports between directories that are supposed to be
independent. If this is the case, it emits a warning.
-/
register_option linter.directoryDependency : Bool := {
defValue := true
descr := "enable the directoryDependency linter"
}
namespace DirectoryDependency
/-- `NamePrefixRel` is a datatype for storing relations between name prefixes.
That is, `R : NamePrefixRel` is supposed to answer given names `(n₁, n₂)` whether there are any
prefixes `n₁'` of `n₁` and `n₂'` of `n₂` such that `n₁' R n₂'`.
The current implementation is a `NameMap` of `NameSet`s, testing each prefix of `n₁` and `n₂` in
turn. This can probably be optimized.
-/
def NamePrefixRel := NameMap NameSet
namespace NamePrefixRel
instance : EmptyCollection NamePrefixRel := inferInstanceAs (EmptyCollection (NameMap _))
/-- Make all names with prefix `n₁` related to names with prefix `n₂`. -/
def insert (r : NamePrefixRel) (n₁ n₂ : Name) : NamePrefixRel :=
match r.find? n₁ with
| some ns => NameMap.insert r n₁ (ns.insert n₂)
| none => NameMap.insert r n₁ (.insert ∅ n₂)
/-- Convert an array of prefix pairs to a `NamePrefixRel`. -/
def ofArray (xs : Array (Name × Name)) : NamePrefixRel :=
xs.foldl (init := ∅)
fun r (n₁, n₂) => r.insert n₁ n₂
/-- Get a prefix of `n₁` that is related to a prefix of `n₂`. -/
def find (r : NamePrefixRel) (n₁ n₂ : Name) : Option (Name × Name) :=
n₁.findPrefix fun n₁' => do
let ns ← r.find? n₁'
n₂.findPrefix fun n₂' =>
if ns.contains n₂' then
(n₁', n₂')
else
none
/-- Get a prefix of `n₁` that is related to any prefix of the names in `ns`; return the prefixes.
This should be more efficient than iterating over all names in `ns` and calling `find`,
since it doesn't need to worry about overlapping prefixes.
-/
def findAny (r : NamePrefixRel) (n₁ : Name) (ns : Array Name) : Option (Name × Name) :=
let prefixes := Lean.Name.collectPrefixes ns
n₁.findPrefix fun n₁' => do
let ns ← r.find? n₁'
for n₂' in prefixes do
if ns.contains n₂' then
return (n₁', n₂')
else
pure ()
none
/-- Does `r` contain any entries with key `n`? -/
def containsKey (r : NamePrefixRel) (n : Name) : Bool := NameMap.contains r n
/-- Is a prefix of `n₁` related to a prefix of `n₂`? -/
def contains (r : NamePrefixRel) (n₁ n₂ : Name) : Bool := (r.find n₁ n₂).isSome
/-- Look up all names `m` which are values of some prefix of `n` under this relation. -/
def getAllLeft (r : NamePrefixRel) (n : Name) : NameSet := Id.run do
let matchingPrefixes := n.prefixes.filter (fun prf ↦ r.containsKey prf)
let mut allRules := NameSet.empty
for prefix_ in matchingPrefixes do
let some rules := r.find? prefix_ | unreachable!
allRules := allRules.append rules
allRules
end NamePrefixRel
-- TODO: add/extend tests for this linter, to ensure the allow-list works
-- TODO: move the following three lists to a JSON file, for easier evolution over time!
-- Future: enforce that allowed and forbidden keys are disjoint
-- Future: move further directories to use this allow-list instead of the blocklist
/-- `allowedImportDirs` relates module prefixes, specifying that modules with the first prefix
are only allowed to import modules in the second directory.
For directories which are low in the import hierarchy, this opt-out approach is both more ergonomic
(fewer updates needed) and needs less configuration.
We always allow imports of `Init`, `Lean`, `Std`, `Qq` and
`Mathlib.Init` (as well as their transitive dependencies.)
-/
def allowedImportDirs : NamePrefixRel := .ofArray #[
-- This is used to test the linter.
(`MathlibTest.DirectoryDependencyLinter, `Mathlib.Lean),
-- Mathlib.Tactic has large transitive imports: just allow all of mathlib,
-- as we don't care about the details a lot.
(`MathlibTest.Header, `Mathlib),
(`MathlibTest.Header, `Aesop),
(`MathlibTest.Header, `ImportGraph),
(`MathlibTest.Header, `LeanSearchClient),
(`MathlibTest.Header, `Plausible),
(`MathlibTest.Header, `ProofWidgets),
(`MathlibTest.Header, `Qq),
-- (`MathlibTest.Header, `Mathlib.Tactic),
-- (`MathlibTest.Header, `Mathlib.Deprecated),
(`MathlibTest.Header, `Batteries),
(`MathlibTest.Header, `Lake),
(`Mathlib.Util, `Batteries),
(`Mathlib.Util, `Mathlib.Lean),
(`Mathlib.Util, `Mathlib.Tactic),
-- TODO: reduce this dependency by upstreaming `Data.String.Defs to batteries
(`Mathlib.Util.FormatTable, `Mathlib.Data.String.Defs),
(`Mathlib.Lean, `Batteries.CodeAction),
(`Mathlib.Lean, `Batteries.Tactic.Lint),
-- TODO: decide if this is acceptable or should be split in a more fine-grained way
(`Mathlib.Lean, `Batteries),
(`Mathlib.Lean.Expr, `Mathlib.Util),
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Util),
-- Fine-grained exceptions: TODO decide if these are fine, or should be scoped more broadly.
(`Mathlib.Lean.CoreM, `Mathlib.Tactic.ToExpr),
(`Mathlib.Lean.CoreM, `Mathlib.Util.WhatsNew),
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Tactic.Lemma),
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Tactic.TypeStar),
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Tactic.ToAdditive),
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Tactic), -- split this up further?
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Data), -- split this up further?
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Algebra.Notation),
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Data.Notation),
(`Mathlib.Lean.Meta.RefinedDiscrTree, `Mathlib.Data.Array),
(`Mathlib.Lean.Meta.CongrTheorems, `Mathlib.Data),
(`Mathlib.Lean.Meta.CongrTheorems, `Mathlib.Logic),
(`Mathlib.Lean.Meta.CongrTheorems, `Mathlib.Order.Defs),
(`Mathlib.Lean.Meta.CongrTheorems, `Mathlib.Tactic),
(`Mathlib.Lean.Expr.ExtraRecognizers, `Mathlib.Data),
(`Mathlib.Lean.Expr.ExtraRecognizers, `Mathlib.Order),
(`Mathlib.Lean.Expr.ExtraRecognizers, `Mathlib.Logic),
(`Mathlib.Lean.Expr.ExtraRecognizers, `Mathlib.Tactic),
(`Mathlib.Tactic.Linter, `Batteries),
-- The Mathlib.Tactic.Linter *module* imports all linters, hence requires all the imports.
-- For more fine-grained exceptions of the next two imports, one needs to rename that file.
(`Mathlib.Tactic.Linter, `ImportGraph),
(`Mathlib.Tactic.Linter, `Mathlib.Tactic.MinImports),
(`Mathlib.Tactic.Linter.TextBased, `Mathlib.Data.Nat.Notation),
(`Mathlib.Logic, `Batteries),
-- TODO: should the next import direction be flipped?
(`Mathlib.Logic, `Mathlib.Control),
(`Mathlib.Logic, `Mathlib.Lean),
(`Mathlib.Logic, `Mathlib.Util),
(`Mathlib.Logic, `Mathlib.Tactic),
(`Mathlib.Logic.Fin.Rotate, `Mathlib.Algebra.Group.Fin.Basic),
(`Mathlib.Logic.Hydra, `Mathlib.GroupTheory),
(`Mathlib.Logic, `Mathlib.Algebra.Notation),
(`Mathlib.Logic, `Mathlib.Algebra.NeZero),
(`Mathlib.Logic, `Mathlib.Data),
-- TODO: this next dependency should be made more fine-grained.
(`Mathlib.Logic, `Mathlib.Order),
-- Particular modules with larger imports.
(`Mathlib.Logic.Hydra, `Mathlib.GroupTheory),
(`Mathlib.Logic.Hydra, `Mathlib.Algebra),
(`Mathlib.Logic.Encodable.Pi, `Mathlib.Algebra),
(`Mathlib.Logic.Equiv.Fin.Rotate, `Mathlib.Algebra.Group),
(`Mathlib.Logic.Equiv.Fin.Rotate, `Mathlib.Algebra.Regular),
(`Mathlib.Logic.Equiv.Array, `Mathlib.Algebra),
(`Mathlib.Logic.Equiv.Finset, `Mathlib.Algebra),
(`Mathlib.Logic.Godel.GodelBetaFunction, `Mathlib.Algebra),
(`Mathlib.Logic.Small.List, `Mathlib.Algebra),
(`Mathlib.Testing, `Batteries),
-- TODO: this next import should be eliminated.
(`Mathlib.Testing, `Mathlib.GroupTheory),
(`Mathlib.Testing, `Mathlib.Control),
(`Mathlib.Testing, `Mathlib.Algebra),
(`Mathlib.Testing, `Mathlib.Data),
(`Mathlib.Testing, `Mathlib.Logic),
(`Mathlib.Testing, `Mathlib.Order),
(`Mathlib.Testing, `Mathlib.Lean),
(`Mathlib.Testing, `Mathlib.Tactic),
(`Mathlib.Testing, `Mathlib.Util),
]
/-- `forbiddenImportDirs` relates module prefixes, specifying that modules with the first prefix
should not import modules with the second prefix (except if specifically allowed in
`overrideAllowedImportDirs`).
For example, ``(`Mathlib.Algebra.Notation, `Mathlib.Algebra)`` is in `forbiddenImportDirs` and
``(`Mathlib.Algebra.Notation, `Mathlib.Algebra.Notation)`` is in `overrideAllowedImportDirs`
because modules in `Mathlib/Algebra/Notation.lean` cannot import modules in `Mathlib.Algebra` that are
outside `Mathlib/Algebra/Notation.lean`.
-/
def forbiddenImportDirs : NamePrefixRel := .ofArray #[
(`Mathlib.Algebra.Notation, `Mathlib.Algebra),
(`Mathlib, `Mathlib.Deprecated),
-- This is used to test the linter.
(`MathlibTest.Header, `Mathlib.Deprecated),
-- TODO:
-- (`Mathlib.Data, `Mathlib.Dynamics),
-- (`Mathlib.Topology, `Mathlib.Algebra),
-- The following are a list of existing non-dependent top-level directory pairs.
(`Mathlib.Algebra, `Mathlib.AlgebraicGeometry),
(`Mathlib.Algebra, `Mathlib.Computability),
(`Mathlib.Algebra, `Mathlib.Condensed),
(`Mathlib.Algebra, `Mathlib.Geometry),
(`Mathlib.Algebra, `Mathlib.InformationTheory),
(`Mathlib.Algebra, `Mathlib.ModelTheory),
(`Mathlib.Algebra, `Mathlib.RepresentationTheory),
(`Mathlib.Algebra, `Mathlib.Testing),
(`Mathlib.AlgebraicGeometry, `Mathlib.AlgebraicTopology),
(`Mathlib.AlgebraicGeometry, `Mathlib.Analysis),
(`Mathlib.AlgebraicGeometry, `Mathlib.Computability),
(`Mathlib.AlgebraicGeometry, `Mathlib.Condensed),
(`Mathlib.AlgebraicGeometry, `Mathlib.InformationTheory),
(`Mathlib.AlgebraicGeometry, `Mathlib.MeasureTheory),
(`Mathlib.AlgebraicGeometry, `Mathlib.ModelTheory),
(`Mathlib.AlgebraicGeometry, `Mathlib.Probability),
(`Mathlib.AlgebraicGeometry, `Mathlib.RepresentationTheory),
(`Mathlib.AlgebraicGeometry, `Mathlib.Testing),
(`Mathlib.AlgebraicTopology, `Mathlib.AlgebraicGeometry),
(`Mathlib.AlgebraicTopology, `Mathlib.Computability),
(`Mathlib.AlgebraicTopology, `Mathlib.Condensed),
(`Mathlib.AlgebraicTopology, `Mathlib.FieldTheory),
(`Mathlib.AlgebraicTopology, `Mathlib.Geometry),
(`Mathlib.AlgebraicTopology, `Mathlib.InformationTheory),
(`Mathlib.AlgebraicTopology, `Mathlib.MeasureTheory),
(`Mathlib.AlgebraicTopology, `Mathlib.ModelTheory),
(`Mathlib.AlgebraicTopology, `Mathlib.NumberTheory),
(`Mathlib.AlgebraicTopology, `Mathlib.Probability),
(`Mathlib.AlgebraicTopology, `Mathlib.RepresentationTheory),
(`Mathlib.AlgebraicTopology, `Mathlib.SetTheory),
(`Mathlib.AlgebraicTopology, `Mathlib.Testing),
(`Mathlib.Analysis, `Mathlib.AlgebraicGeometry),
(`Mathlib.Analysis, `Mathlib.AlgebraicTopology),
(`Mathlib.Analysis, `Mathlib.Computability),
(`Mathlib.Analysis, `Mathlib.Condensed),
(`Mathlib.Analysis, `Mathlib.InformationTheory),
(`Mathlib.Analysis, `Mathlib.ModelTheory),
(`Mathlib.Analysis, `Mathlib.RepresentationTheory),
(`Mathlib.Analysis, `Mathlib.Testing),
(`Mathlib.CategoryTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.CategoryTheory, `Mathlib.Analysis),
(`Mathlib.CategoryTheory, `Mathlib.Computability),
(`Mathlib.CategoryTheory, `Mathlib.Condensed),
(`Mathlib.CategoryTheory, `Mathlib.Geometry),
(`Mathlib.CategoryTheory, `Mathlib.InformationTheory),
(`Mathlib.CategoryTheory, `Mathlib.MeasureTheory),
(`Mathlib.CategoryTheory, `Mathlib.ModelTheory),
(`Mathlib.CategoryTheory, `Mathlib.Probability),
(`Mathlib.CategoryTheory, `Mathlib.RepresentationTheory),
(`Mathlib.CategoryTheory, `Mathlib.Testing),
(`Mathlib.Combinatorics, `Mathlib.AlgebraicGeometry),
(`Mathlib.Combinatorics, `Mathlib.AlgebraicTopology),
(`Mathlib.Combinatorics, `Mathlib.Computability),
(`Mathlib.Combinatorics, `Mathlib.Condensed),
(`Mathlib.Combinatorics, `Mathlib.Geometry.Euclidean),
(`Mathlib.Combinatorics, `Mathlib.Geometry.Group),
(`Mathlib.Combinatorics, `Mathlib.Geometry.Manifold),
(`Mathlib.Combinatorics, `Mathlib.Geometry.RingedSpace),
(`Mathlib.Combinatorics, `Mathlib.InformationTheory),
(`Mathlib.Combinatorics, `Mathlib.MeasureTheory),
(`Mathlib.Combinatorics, `Mathlib.ModelTheory),
(`Mathlib.Combinatorics, `Mathlib.Probability),
(`Mathlib.Combinatorics, `Mathlib.RepresentationTheory),
(`Mathlib.Combinatorics, `Mathlib.Testing),
(`Mathlib.Computability, `Mathlib.AlgebraicGeometry),
(`Mathlib.Computability, `Mathlib.AlgebraicTopology),
(`Mathlib.Computability, `Mathlib.CategoryTheory),
(`Mathlib.Computability, `Mathlib.Condensed),
(`Mathlib.Computability, `Mathlib.FieldTheory),
(`Mathlib.Computability, `Mathlib.Geometry),
(`Mathlib.Computability, `Mathlib.InformationTheory),
(`Mathlib.Computability, `Mathlib.MeasureTheory),
(`Mathlib.Computability, `Mathlib.ModelTheory),
(`Mathlib.Computability, `Mathlib.Probability),
(`Mathlib.Computability, `Mathlib.RepresentationTheory),
(`Mathlib.Computability, `Mathlib.Testing),
(`Mathlib.Condensed, `Mathlib.AlgebraicGeometry),
(`Mathlib.Condensed, `Mathlib.AlgebraicTopology),
(`Mathlib.Condensed, `Mathlib.Computability),
(`Mathlib.Condensed, `Mathlib.FieldTheory),
(`Mathlib.Condensed, `Mathlib.Geometry),
(`Mathlib.Condensed, `Mathlib.InformationTheory),
(`Mathlib.Condensed, `Mathlib.MeasureTheory),
(`Mathlib.Condensed, `Mathlib.ModelTheory),
(`Mathlib.Condensed, `Mathlib.Probability),
(`Mathlib.Condensed, `Mathlib.RepresentationTheory),
(`Mathlib.Condensed, `Mathlib.Testing),
(`Mathlib.Control, `Mathlib.AlgebraicGeometry),
(`Mathlib.Control, `Mathlib.AlgebraicTopology),
(`Mathlib.Control, `Mathlib.Analysis),
(`Mathlib.Control, `Mathlib.Computability),
(`Mathlib.Control, `Mathlib.Condensed),
(`Mathlib.Control, `Mathlib.FieldTheory),
(`Mathlib.Control, `Mathlib.Geometry),
(`Mathlib.Control, `Mathlib.GroupTheory),
(`Mathlib.Control, `Mathlib.InformationTheory),
(`Mathlib.Control, `Mathlib.LinearAlgebra),
(`Mathlib.Control, `Mathlib.MeasureTheory),
(`Mathlib.Control, `Mathlib.ModelTheory),
(`Mathlib.Control, `Mathlib.NumberTheory),
(`Mathlib.Control, `Mathlib.Probability),
(`Mathlib.Control, `Mathlib.RepresentationTheory),
(`Mathlib.Control, `Mathlib.RingTheory),
(`Mathlib.Control, `Mathlib.SetTheory),
(`Mathlib.Control, `Mathlib.Testing),
(`Mathlib.Control, `Mathlib.Topology),
(`Mathlib.Data, `Mathlib.AlgebraicGeometry),
(`Mathlib.Data, `Mathlib.AlgebraicTopology),
(`Mathlib.Data, `Mathlib.Computability),
(`Mathlib.Data, `Mathlib.Condensed),
(`Mathlib.Data, `Mathlib.Geometry.Euclidean),
(`Mathlib.Data, `Mathlib.Geometry.Group),
(`Mathlib.Data, `Mathlib.Geometry.Manifold),
(`Mathlib.Data, `Mathlib.Geometry.RingedSpace),
(`Mathlib.Data, `Mathlib.InformationTheory),
(`Mathlib.Data, `Mathlib.ModelTheory),
(`Mathlib.Data, `Mathlib.RepresentationTheory),
(`Mathlib.Data, `Mathlib.Testing),
(`Mathlib.Dynamics, `Mathlib.AlgebraicGeometry),
(`Mathlib.Dynamics, `Mathlib.AlgebraicTopology),
(`Mathlib.Dynamics, `Mathlib.CategoryTheory),
(`Mathlib.Dynamics, `Mathlib.Computability),
(`Mathlib.Dynamics, `Mathlib.Condensed),
(`Mathlib.Dynamics, `Mathlib.Geometry.Euclidean),
(`Mathlib.Dynamics, `Mathlib.Geometry.Group),
(`Mathlib.Dynamics, `Mathlib.Geometry.Manifold),
(`Mathlib.Dynamics, `Mathlib.Geometry.RingedSpace),
(`Mathlib.Dynamics, `Mathlib.InformationTheory),
(`Mathlib.Dynamics, `Mathlib.ModelTheory),
(`Mathlib.Dynamics, `Mathlib.RepresentationTheory),
(`Mathlib.Dynamics, `Mathlib.Testing),
(`Mathlib.FieldTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.FieldTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.FieldTheory, `Mathlib.Condensed),
(`Mathlib.FieldTheory, `Mathlib.Geometry),
(`Mathlib.FieldTheory, `Mathlib.InformationTheory),
(`Mathlib.FieldTheory, `Mathlib.MeasureTheory),
(`Mathlib.FieldTheory, `Mathlib.Probability),
(`Mathlib.FieldTheory, `Mathlib.RepresentationTheory),
(`Mathlib.FieldTheory, `Mathlib.Testing),
(`Mathlib.Geometry, `Mathlib.AlgebraicGeometry),
(`Mathlib.Geometry, `Mathlib.Computability),
(`Mathlib.Geometry, `Mathlib.Condensed),
(`Mathlib.Geometry, `Mathlib.InformationTheory),
(`Mathlib.Geometry, `Mathlib.ModelTheory),
(`Mathlib.Geometry, `Mathlib.RepresentationTheory),
(`Mathlib.Geometry, `Mathlib.Testing),
(`Mathlib.GroupTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.GroupTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.GroupTheory, `Mathlib.Analysis),
(`Mathlib.GroupTheory, `Mathlib.Computability),
(`Mathlib.GroupTheory, `Mathlib.Condensed),
(`Mathlib.GroupTheory, `Mathlib.Geometry),
(`Mathlib.GroupTheory, `Mathlib.InformationTheory),
(`Mathlib.GroupTheory, `Mathlib.MeasureTheory),
(`Mathlib.GroupTheory, `Mathlib.ModelTheory),
(`Mathlib.GroupTheory, `Mathlib.Probability),
(`Mathlib.GroupTheory, `Mathlib.RepresentationTheory),
(`Mathlib.GroupTheory, `Mathlib.Testing),
(`Mathlib.GroupTheory, `Mathlib.Topology),
(`Mathlib.InformationTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.InformationTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.InformationTheory, `Mathlib.CategoryTheory),
(`Mathlib.InformationTheory, `Mathlib.Computability),
(`Mathlib.InformationTheory, `Mathlib.Condensed),
(`Mathlib.InformationTheory, `Mathlib.Geometry.Euclidean),
(`Mathlib.InformationTheory, `Mathlib.Geometry.Group),
(`Mathlib.InformationTheory, `Mathlib.Geometry.Manifold),
(`Mathlib.InformationTheory, `Mathlib.Geometry.RingedSpace),
(`Mathlib.InformationTheory, `Mathlib.ModelTheory),
(`Mathlib.InformationTheory, `Mathlib.RepresentationTheory),
(`Mathlib.InformationTheory, `Mathlib.Testing),
(`Mathlib.LinearAlgebra, `Mathlib.AlgebraicGeometry),
(`Mathlib.LinearAlgebra, `Mathlib.AlgebraicTopology),
(`Mathlib.LinearAlgebra, `Mathlib.Computability),
(`Mathlib.LinearAlgebra, `Mathlib.Condensed),
(`Mathlib.LinearAlgebra, `Mathlib.Geometry.Euclidean),
(`Mathlib.LinearAlgebra, `Mathlib.Geometry.Group),
(`Mathlib.LinearAlgebra, `Mathlib.Geometry.Manifold),
(`Mathlib.LinearAlgebra, `Mathlib.Geometry.RingedSpace),
(`Mathlib.LinearAlgebra, `Mathlib.InformationTheory),
(`Mathlib.LinearAlgebra, `Mathlib.MeasureTheory),
(`Mathlib.LinearAlgebra, `Mathlib.ModelTheory),
(`Mathlib.LinearAlgebra, `Mathlib.Probability),
(`Mathlib.LinearAlgebra, `Mathlib.Testing),
(`Mathlib.MeasureTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.MeasureTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.MeasureTheory, `Mathlib.Computability),
(`Mathlib.MeasureTheory, `Mathlib.Condensed),
(`Mathlib.MeasureTheory, `Mathlib.Geometry.Euclidean),
(`Mathlib.MeasureTheory, `Mathlib.Geometry.Group),
(`Mathlib.MeasureTheory, `Mathlib.Geometry.Manifold),
(`Mathlib.MeasureTheory, `Mathlib.Geometry.RingedSpace),
(`Mathlib.MeasureTheory, `Mathlib.InformationTheory),
(`Mathlib.MeasureTheory, `Mathlib.ModelTheory),
(`Mathlib.MeasureTheory, `Mathlib.RepresentationTheory),
(`Mathlib.MeasureTheory, `Mathlib.Testing),
(`Mathlib.ModelTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.ModelTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.ModelTheory, `Mathlib.Analysis),
(`Mathlib.ModelTheory, `Mathlib.Condensed),
(`Mathlib.ModelTheory, `Mathlib.Geometry),
(`Mathlib.ModelTheory, `Mathlib.InformationTheory),
(`Mathlib.ModelTheory, `Mathlib.MeasureTheory),
(`Mathlib.ModelTheory, `Mathlib.Probability),
(`Mathlib.ModelTheory, `Mathlib.RepresentationTheory),
(`Mathlib.ModelTheory, `Mathlib.Testing),
(`Mathlib.ModelTheory, `Mathlib.Topology),
(`Mathlib.NumberTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.NumberTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.NumberTheory, `Mathlib.Computability),
(`Mathlib.NumberTheory, `Mathlib.Condensed),
(`Mathlib.NumberTheory, `Mathlib.InformationTheory),
(`Mathlib.NumberTheory, `Mathlib.ModelTheory),
(`Mathlib.NumberTheory, `Mathlib.RepresentationTheory),
(`Mathlib.NumberTheory, `Mathlib.Testing),
(`Mathlib.Order, `Mathlib.AlgebraicGeometry),
(`Mathlib.Order, `Mathlib.AlgebraicTopology),
(`Mathlib.Order, `Mathlib.Computability),
(`Mathlib.Order, `Mathlib.Condensed),
(`Mathlib.Order, `Mathlib.FieldTheory),
(`Mathlib.Order, `Mathlib.Geometry),
(`Mathlib.Order, `Mathlib.InformationTheory),
(`Mathlib.Order, `Mathlib.MeasureTheory),
(`Mathlib.Order, `Mathlib.ModelTheory),
(`Mathlib.Order, `Mathlib.NumberTheory),
(`Mathlib.Order, `Mathlib.Probability),
(`Mathlib.Order, `Mathlib.RepresentationTheory),
(`Mathlib.Order, `Mathlib.Testing),
(`Mathlib.Probability, `Mathlib.AlgebraicGeometry),
(`Mathlib.Probability, `Mathlib.AlgebraicTopology),
(`Mathlib.Probability, `Mathlib.CategoryTheory),
(`Mathlib.Probability, `Mathlib.Computability),
(`Mathlib.Probability, `Mathlib.Condensed),
(`Mathlib.Probability, `Mathlib.Geometry.Euclidean),
(`Mathlib.Probability, `Mathlib.Geometry.Group),
(`Mathlib.Probability, `Mathlib.Geometry.Manifold),
(`Mathlib.Probability, `Mathlib.Geometry.RingedSpace),
(`Mathlib.Probability, `Mathlib.InformationTheory),
(`Mathlib.Probability, `Mathlib.ModelTheory),
(`Mathlib.Probability, `Mathlib.RepresentationTheory),
(`Mathlib.Probability, `Mathlib.Testing),
(`Mathlib.RepresentationTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.RepresentationTheory, `Mathlib.Analysis),
(`Mathlib.RepresentationTheory, `Mathlib.Computability),
(`Mathlib.RepresentationTheory, `Mathlib.Condensed),
(`Mathlib.RepresentationTheory, `Mathlib.Geometry),
(`Mathlib.RepresentationTheory, `Mathlib.InformationTheory),
(`Mathlib.RepresentationTheory, `Mathlib.MeasureTheory),
(`Mathlib.RepresentationTheory, `Mathlib.ModelTheory),
(`Mathlib.RepresentationTheory, `Mathlib.Probability),
(`Mathlib.RepresentationTheory, `Mathlib.Testing),
(`Mathlib.RepresentationTheory, `Mathlib.Topology),
(`Mathlib.RingTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.RingTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.RingTheory, `Mathlib.Computability),
(`Mathlib.RingTheory, `Mathlib.Condensed),
(`Mathlib.RingTheory, `Mathlib.Geometry.Euclidean),
(`Mathlib.RingTheory, `Mathlib.Geometry.Group),
(`Mathlib.RingTheory, `Mathlib.Geometry.Manifold),
(`Mathlib.RingTheory, `Mathlib.Geometry.RingedSpace),
(`Mathlib.RingTheory, `Mathlib.InformationTheory),
(`Mathlib.RingTheory, `Mathlib.ModelTheory),
(`Mathlib.RingTheory, `Mathlib.RepresentationTheory),
(`Mathlib.RingTheory, `Mathlib.Testing),
(`Mathlib.SetTheory, `Mathlib.AlgebraicGeometry),
(`Mathlib.SetTheory, `Mathlib.AlgebraicTopology),
(`Mathlib.SetTheory, `Mathlib.Analysis),
(`Mathlib.SetTheory, `Mathlib.CategoryTheory),
(`Mathlib.SetTheory, `Mathlib.Combinatorics),
(`Mathlib.SetTheory, `Mathlib.Computability),
(`Mathlib.SetTheory, `Mathlib.Condensed),
(`Mathlib.SetTheory, `Mathlib.FieldTheory),
(`Mathlib.SetTheory, `Mathlib.Geometry),
(`Mathlib.SetTheory, `Mathlib.InformationTheory),
(`Mathlib.SetTheory, `Mathlib.MeasureTheory),
(`Mathlib.SetTheory, `Mathlib.ModelTheory),
(`Mathlib.SetTheory, `Mathlib.Probability),
(`Mathlib.SetTheory, `Mathlib.RepresentationTheory),
(`Mathlib.SetTheory, `Mathlib.Testing),
(`Mathlib.Topology, `Mathlib.AlgebraicGeometry),
(`Mathlib.Topology, `Mathlib.Computability),
(`Mathlib.Topology, `Mathlib.Condensed),
(`Mathlib.Topology, `Mathlib.Geometry),
(`Mathlib.Topology, `Mathlib.InformationTheory),
(`Mathlib.Topology, `Mathlib.ModelTheory),
(`Mathlib.Topology, `Mathlib.Probability),
(`Mathlib.Topology, `Mathlib.RepresentationTheory),
(`Mathlib.Topology, `Mathlib.Testing),
]
/-- `overrideAllowedImportDirs` relates module prefixes, specifying that modules with the first
prefix are allowed to import modules with the second prefix, even if disallowed in
`forbiddenImportDirs`.
For example, ``(`Mathlib.Algebra.Notation, `Mathlib.Algebra)`` is in `forbiddenImportDirs` and
``(`Mathlib.Algebra.Notation, `Mathlib.Algebra.Notation)`` is in `overrideAllowedImportDirs`
because modules in `Mathlib/Algebra/Notation.lean` cannot import modules in `Mathlib.Algebra` that are
outside `Mathlib/Algebra/Notation.lean`.
-/
def overrideAllowedImportDirs : NamePrefixRel := .ofArray #[
(`Mathlib.Algebra.Lie, `Mathlib.RepresentationTheory),
(`Mathlib.Algebra.Notation, `Mathlib.Algebra.Notation),
(`Mathlib.Deprecated, `Mathlib.Deprecated),
(`Mathlib.Topology.Algebra, `Mathlib.Algebra),
(`Mathlib.Topology.Compactification, `Mathlib.Geometry.Manifold)
]
end DirectoryDependency
open DirectoryDependency
/-- Check if one of the imports `imports` to `mainModule` is forbidden by `forbiddenImportDirs`;
if so, return an error describing how the import transitively arises. -/
private def checkBlocklist (env : Environment) (mainModule : Name) (imports : Array Name) : Option MessageData := Id.run do
match forbiddenImportDirs.findAny mainModule imports with
| some (n₁, n₂) => do
if let some imported := n₂.prefixToName imports then
if !overrideAllowedImportDirs.contains mainModule imported then
let mut msg := m!"Modules starting with {n₁} are not allowed to import modules starting with {n₂}. \
This module depends on {imported}\n"
for dep in env.importPath imported do
msg := msg ++ m!"which is imported by {dep},\n"
return some (msg ++ m!"which is imported by this module. \
(Exceptions can be added to `overrideAllowedImportDirs`.)")
else none
else
return some m!"Internal error in `directoryDependency` linter: this module claims to depend \
on a module starting with {n₂} but a module with that prefix was not found in the import graph."
| none => none
@[inherit_doc Mathlib.Linter.linter.directoryDependency]
def directoryDependencyCheck (mainModule : Name) : CommandElabM (Array MessageData) := do
unless Linter.getLinterValue linter.directoryDependency (← getLinterOptions) do
return #[]
let env ← getEnv
let imports := env.allImportedModuleNames
-- If this module is in the allow-list, we only allow imports from directories specified there.
-- Collect all prefixes which have a matching entry.
let matchingPrefixes := mainModule.prefixes.filter (fun prf ↦ allowedImportDirs.containsKey prf)
if matchingPrefixes.isEmpty then
-- Otherwise, we fall back to the blocklist `forbiddenImportDirs`.
if let some msg := checkBlocklist env mainModule imports then return #[msg] else return #[]
else
-- We always allow imports in the same directory (for each matching prefix),
-- from `Init`, `Lean` and `Std`, as well as imports in `Aesop`, `Qq`, `Plausible`,
-- `ImportGraph`, `ProofWidgets` or `LeanSearchClient` (as these are imported in Tactic.Common).
-- We also allow transitive imports of Mathlib.Init, as well as Mathlib.Init itself.
let initImports := (← findImports ("Mathlib" / "Init.lean")).append
#[`Mathlib.Init, `Mathlib.Tactic.DeclarationNames]
let exclude := [
`Init, `Std, `Lean,
`Aesop, `Qq, `Plausible, `ImportGraph, `ProofWidgets, `LeanSearchClient
]
let importsToCheck := imports.filter (fun imp ↦ !exclude.any (·.isPrefixOf imp))
|>.filter (fun imp ↦ !matchingPrefixes.any (·.isPrefixOf imp))
|>.filter (!initImports.contains ·)
-- Find all prefixes which are allowed for one of these directories.
let allRules := allowedImportDirs.getAllLeft mainModule
-- Error about those imports which are not covered by allowedImportDirs.
let mut messages := #[]
for imported in importsToCheck do
if !allowedImportDirs.contains mainModule imported then
let importPath := env.importPath imported
let mut msg := m!"Module {mainModule} depends on {imported},\n\
but is only allowed to import modules starting with one of \
{allRules.toArray.qsort (·.toString < ·.toString)}.\n\
Note: module {imported}"
let mut superseded := false
match importPath.toList with
| [] => msg := msg ++ " is directly imported by this module"
| a :: rest =>
-- Only add messages about imports that aren't themselves transitive imports of
-- forbidden imports.
-- This should prevent redundant messages.
if !allowedImportDirs.contains mainModule a then
superseded := true
else
msg := msg ++ s!" is imported by {a},\n"
for dep in rest do
if !allowedImportDirs.contains mainModule dep then
superseded := true
break
msg := msg ++ m!"which is imported by {dep},\n"
msg := msg ++ m!"which is imported by this module."
msg := msg ++ "(Exceptions can be added to `allowedImportDirs`.)"
if !superseded then
messages := messages.push msg
return messages
end Mathlib.Linter
|
Normalize.lean
|
import Mathlib.Tactic.CategoryTheory.Bicategory.Normalize
open CategoryTheory Mathlib.Tactic BicategoryLike
open Bicategory
namespace CategoryTheory.Bicategory
/-- `normalize% η` is the normalization of the 2-morphism `η`.
1. The normalized 2-morphism is of the form `α₀ ≫ η₀ ≫ α₁ ≫ η₁ ≫ ... αₘ ≫ ηₘ ≫ αₘ₊₁` where
each `αᵢ` is a structural 2-morphism (consisting of associators and unitors),
2. each `ηᵢ` is a non-structural 2-morphism of the form `f₁ ◁ ... ◁ fₘ ◁ θ`, and
3. `θ` is of the form `ι ▷ g₁ ▷ ... ▷ gₗ`
-/
elab "normalize% " t:term:51 : term => do
let e ← Lean.Elab.Term.elabTerm t none
let ctx : Bicategory.Context ← BicategoryLike.mkContext e
CoherenceM.run (ctx := ctx) do
return (← BicategoryLike.eval `bicategory (← MkMor₂.ofExpr e)).expr.e.e
universe w v u
variable {B : Type u} [Bicategory.{w, v} B]
variable {a b c d e : B}
variable {f : a ⟶ b} {g : b ⟶ c} in
#guard_expr normalize% f ◁ 𝟙 g = (whiskerLeftIso f (Iso.refl g)).hom
variable {f : a ⟶ b} {g : b ⟶ c} in
#guard_expr normalize% 𝟙 f ▷ g = (whiskerRightIso (Iso.refl f) g).hom
variable {f : a ⟶ b} {g h i : b ⟶ c} {η : g ⟶ h} {θ : h ⟶ i} in
#guard_expr normalize% f ◁ (η ≫ θ) = _ ≫ f ◁ η ≫ _ ≫ f ◁ θ ≫ _
variable {f g h : a ⟶ b} {i : b ⟶ c} {η : f ⟶ g} {θ : g ⟶ h} in
#guard_expr normalize% (η ≫ θ) ▷ i = _ ≫ η ▷ i ≫ _ ≫ θ ▷ i ≫ _
variable {η : 𝟙 a ⟶ 𝟙 a} in
#guard_expr normalize% 𝟙 a ◁ η = _ ≫ η ≫ _
variable {f : a ⟶ b} {g : b ⟶ c} {h i : c ⟶ d} {η : h ⟶ i} in
#guard_expr normalize% (f ≫ g) ◁ η = _ ≫ f ◁ g ◁ η ≫ _
variable {η : 𝟙 a ⟶ 𝟙 a} in
#guard_expr normalize% η ▷ 𝟙 a = _ ≫ η ≫ _
variable {f g : a ⟶ b} {h : b ⟶ c} {i : c ⟶ d} {η : f ⟶ g} in
#guard_expr normalize% η ▷ (h ≫ i) = _ ≫ η ▷ h ▷ i ≫ _
variable {f : a ⟶ b} {g h : b ⟶ c} {i : c ⟶ d} {η : g ⟶ h} in
#guard_expr normalize% (f ◁ η) ▷ i = _ ≫ f ◁ η ▷ i ≫ _
variable {f : a ⟶ b} in
#guard_expr normalize% (λ_ f).hom = (λ_ f).hom
variable {f : a ⟶ b} in
#guard_expr normalize% (λ_ f).inv = ((λ_ f).symm).hom
variable {f : a ⟶ b} in
#guard_expr normalize% (ρ_ f).hom = (ρ_ f).hom
variable {f : a ⟶ b} in
#guard_expr normalize% (ρ_ f).inv = ((ρ_ f).symm).hom
variable {f : a ⟶ b} {g : b ⟶ c} {h : c ⟶ d} in
#guard_expr normalize% (α_ f g h).hom = (α_ _ _ _).hom
variable {f : a ⟶ b} {g : b ⟶ c} {h : c ⟶ d} in
#guard_expr normalize% (α_ f g h).inv = ((α_ f g h).symm).hom
variable {f : a ⟶ b} {g : b ⟶ c} in
#guard_expr normalize% 𝟙 (f ≫ g) = (Iso.refl (f ≫ g)).hom
end CategoryTheory.Bicategory
|
Basic.lean
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Analysis.Normed.Group.Constructions
import Mathlib.Analysis.Normed.Group.Subgroup
import Mathlib.Analysis.Normed.Group.Submodule
/-!
# Normed rings
In this file we define (semi)normed rings. We also prove some theorems about these definitions.
A normed ring instance can be constructed from a given real absolute value on a ring via
`AbsoluteValue.toNormedRing`.
-/
-- Guard against import creep.
assert_not_exists AddChar comap_norm_atTop DilationEquiv Finset.sup_mul_le_mul_sup_of_nonneg
IsOfFinOrder Isometry.norm_map_of_map_one NNReal.isOpen_Ico_zero Rat.norm_cast_real
RestrictScalars
variable {G α β ι : Type*}
open Filter
open scoped Topology NNReal
/-- A non-unital seminormed ring is a not-necessarily-unital ring
endowed with a seminorm which satisfies the inequality `‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class NonUnitalSeminormedRing (α : Type*) extends Norm α, NonUnitalRing α,
PseudoMetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is submultiplicative. -/
protected norm_mul_le : ∀ a b, norm (a * b) ≤ norm a * norm b
/-- A seminormed ring is a ring endowed with a seminorm which satisfies the inequality
`‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class SeminormedRing (α : Type*) extends Norm α, Ring α, PseudoMetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is submultiplicative. -/
norm_mul_le : ∀ a b, norm (a * b) ≤ norm a * norm b
-- see Note [lower instance priority]
/-- A seminormed ring is a non-unital seminormed ring. -/
instance (priority := 100) SeminormedRing.toNonUnitalSeminormedRing [β : SeminormedRing α] :
NonUnitalSeminormedRing α :=
{ β with }
/-- A non-unital normed ring is a not-necessarily-unital ring
endowed with a norm which satisfies the inequality `‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class NonUnitalNormedRing (α : Type*) extends Norm α, NonUnitalRing α, MetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is submultiplicative. -/
norm_mul_le : ∀ a b, norm (a * b) ≤ norm a * norm b
-- see Note [lower instance priority]
/-- A non-unital normed ring is a non-unital seminormed ring. -/
instance (priority := 100) NonUnitalNormedRing.toNonUnitalSeminormedRing
[β : NonUnitalNormedRing α] : NonUnitalSeminormedRing α :=
{ β with }
/-- A normed ring is a ring endowed with a norm which satisfies the inequality `‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class NormedRing (α : Type*) extends Norm α, Ring α, MetricSpace α where
/-- The distance is induced by the norm. -/
dist_eq : ∀ x y, dist x y = norm (x - y)
/-- The norm is submultiplicative. -/
norm_mul_le : ∀ a b, norm (a * b) ≤ norm a * norm b
-- see Note [lower instance priority]
/-- A normed ring is a seminormed ring. -/
instance (priority := 100) NormedRing.toSeminormedRing [β : NormedRing α] : SeminormedRing α :=
{ β with }
-- see Note [lower instance priority]
/-- A normed ring is a non-unital normed ring. -/
instance (priority := 100) NormedRing.toNonUnitalNormedRing [β : NormedRing α] :
NonUnitalNormedRing α :=
{ β with }
/-- A non-unital seminormed commutative ring is a non-unital commutative ring endowed with a
seminorm which satisfies the inequality `‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class NonUnitalSeminormedCommRing (α : Type*)
extends NonUnitalSeminormedRing α, NonUnitalCommRing α where
-- see Note [lower instance priority]
attribute [instance 100] NonUnitalSeminormedCommRing.toNonUnitalCommRing
/-- A non-unital normed commutative ring is a non-unital commutative ring endowed with a
norm which satisfies the inequality `‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class NonUnitalNormedCommRing (α : Type*) extends NonUnitalNormedRing α, NonUnitalCommRing α where
-- see Note [lower instance priority]
attribute [instance 100] NonUnitalNormedCommRing.toNonUnitalCommRing
-- see Note [lower instance priority]
/-- A non-unital normed commutative ring is a non-unital seminormed commutative ring. -/
instance (priority := 100) NonUnitalNormedCommRing.toNonUnitalSeminormedCommRing
[β : NonUnitalNormedCommRing α] : NonUnitalSeminormedCommRing α :=
{ β with }
/-- A seminormed commutative ring is a commutative ring endowed with a seminorm which satisfies
the inequality `‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class SeminormedCommRing (α : Type*) extends SeminormedRing α, CommRing α where
-- see Note [lower instance priority]
attribute [instance 100] SeminormedCommRing.toCommRing
/-- A normed commutative ring is a commutative ring endowed with a norm which satisfies
the inequality `‖x y‖ ≤ ‖x‖ ‖y‖`. -/
class NormedCommRing (α : Type*) extends NormedRing α, CommRing α where
-- see Note [lower instance priority]
attribute [instance 100] NormedCommRing.toCommRing
-- see Note [lower instance priority]
/-- A seminormed commutative ring is a non-unital seminormed commutative ring. -/
instance (priority := 100) SeminormedCommRing.toNonUnitalSeminormedCommRing
[β : SeminormedCommRing α] : NonUnitalSeminormedCommRing α :=
{ β with }
-- see Note [lower instance priority]
/-- A normed commutative ring is a non-unital normed commutative ring. -/
instance (priority := 100) NormedCommRing.toNonUnitalNormedCommRing
[β : NormedCommRing α] : NonUnitalNormedCommRing α :=
{ β with }
-- see Note [lower instance priority]
/-- A normed commutative ring is a seminormed commutative ring. -/
instance (priority := 100) NormedCommRing.toSeminormedCommRing [β : NormedCommRing α] :
SeminormedCommRing α :=
{ β with }
instance PUnit.normedCommRing : NormedCommRing PUnit :=
{ PUnit.normedAddCommGroup, PUnit.commRing with
norm_mul_le _ _ := by simp }
section NormOneClass
/-- A mixin class with the axiom `‖1‖ = 1`. Many `NormedRing`s and all `NormedField`s satisfy this
axiom. -/
class NormOneClass (α : Type*) [Norm α] [One α] : Prop where
/-- The norm of the multiplicative identity is 1. -/
norm_one : ‖(1 : α)‖ = 1
export NormOneClass (norm_one)
attribute [simp] norm_one
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup G] [One G] [NormOneClass G]
@[simp] lemma nnnorm_one : ‖(1 : G)‖₊ = 1 := NNReal.eq norm_one
@[simp] lemma enorm_one : ‖(1 : G)‖ₑ = 1 := by simp [enorm]
theorem NormOneClass.nontrivial : Nontrivial G :=
nontrivial_of_ne 0 1 <| ne_of_apply_ne norm <| by simp
end SeminormedAddCommGroup
end NormOneClass
-- see Note [lower instance priority]
instance (priority := 100) NonUnitalNormedRing.toNormedAddCommGroup [β : NonUnitalNormedRing α] :
NormedAddCommGroup α :=
{ β with }
-- see Note [lower instance priority]
instance (priority := 100) NonUnitalSeminormedRing.toSeminormedAddCommGroup
[NonUnitalSeminormedRing α] : SeminormedAddCommGroup α :=
{ ‹NonUnitalSeminormedRing α› with }
instance ULift.normOneClass [SeminormedAddCommGroup α] [One α] [NormOneClass α] :
NormOneClass (ULift α) :=
⟨by simp [ULift.norm_def]⟩
instance Prod.normOneClass [SeminormedAddCommGroup α] [One α] [NormOneClass α]
[SeminormedAddCommGroup β] [One β] [NormOneClass β] : NormOneClass (α × β) :=
⟨by simp [Prod.norm_def]⟩
instance Pi.normOneClass {ι : Type*} {α : ι → Type*} [Nonempty ι] [Fintype ι]
[∀ i, SeminormedAddCommGroup (α i)] [∀ i, One (α i)] [∀ i, NormOneClass (α i)] :
NormOneClass (∀ i, α i) :=
⟨by simpa [Pi.norm_def] using Finset.sup_const Finset.univ_nonempty 1⟩
instance MulOpposite.normOneClass [SeminormedAddCommGroup α] [One α] [NormOneClass α] :
NormOneClass αᵐᵒᵖ :=
⟨@norm_one α _ _ _⟩
section NonUnitalSeminormedRing
variable [NonUnitalSeminormedRing α] {a a₁ a₂ b c : α}
/-- The norm is submultiplicative. -/
theorem norm_mul_le (a b : α) : ‖a * b‖ ≤ ‖a‖ * ‖b‖ :=
NonUnitalSeminormedRing.norm_mul_le a b
theorem nnnorm_mul_le (a b : α) : ‖a * b‖₊ ≤ ‖a‖₊ * ‖b‖₊ := norm_mul_le a b
lemma norm_mul_le_of_le {r₁ r₂ : ℝ} (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ * r₂ :=
(norm_mul_le ..).trans <| mul_le_mul h₁ h₂ (norm_nonneg _) ((norm_nonneg _).trans h₁)
lemma nnnorm_mul_le_of_le {r₁ r₂ : ℝ≥0} (h₁ : ‖a₁‖₊ ≤ r₁) (h₂ : ‖a₂‖₊ ≤ r₂) :
‖a₁ * a₂‖₊ ≤ r₁ * r₂ := (nnnorm_mul_le ..).trans <| mul_le_mul' h₁ h₂
lemma norm_mul₃_le : ‖a * b * c‖ ≤ ‖a‖ * ‖b‖ * ‖c‖ := norm_mul_le_of_le (norm_mul_le ..) le_rfl
lemma nnnorm_mul₃_le : ‖a * b * c‖₊ ≤ ‖a‖₊ * ‖b‖₊ * ‖c‖₊ :=
nnnorm_mul_le_of_le (norm_mul_le ..) le_rfl
theorem one_le_norm_one (β) [NormedRing β] [Nontrivial β] : 1 ≤ ‖(1 : β)‖ :=
(le_mul_iff_one_le_left <| norm_pos_iff.mpr (one_ne_zero : (1 : β) ≠ 0)).mp
(by simpa only [mul_one] using norm_mul_le (1 : β) 1)
theorem one_le_nnnorm_one (β) [NormedRing β] [Nontrivial β] : 1 ≤ ‖(1 : β)‖₊ :=
one_le_norm_one β
/-- In a seminormed ring, the left-multiplication `AddMonoidHom` is bounded. -/
theorem mulLeft_bound (x : α) : ∀ y : α, ‖AddMonoidHom.mulLeft x y‖ ≤ ‖x‖ * ‖y‖ :=
norm_mul_le x
/-- In a seminormed ring, the right-multiplication `AddMonoidHom` is bounded. -/
theorem mulRight_bound (x : α) : ∀ y : α, ‖AddMonoidHom.mulRight x y‖ ≤ ‖x‖ * ‖y‖ := fun y => by
rw [mul_comm]
exact norm_mul_le y x
/-- A non-unital subalgebra of a non-unital seminormed ring is also a non-unital seminormed ring,
with the restriction of the norm. -/
instance NonUnitalSubalgebra.nonUnitalSeminormedRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*}
[NonUnitalSeminormedRing E] [Module 𝕜 E] (s : NonUnitalSubalgebra 𝕜 E) :
NonUnitalSeminormedRing s :=
{ s.toSubmodule.seminormedAddCommGroup, s.toNonUnitalRing with
norm_mul_le a b := norm_mul_le a.1 b.1 }
/-- A non-unital subalgebra of a non-unital seminormed ring is also a non-unital seminormed ring,
with the restriction of the norm. -/
-- necessary to require `SMulMemClass S 𝕜 E` so that `𝕜` can be determined as an `outParam`
@[nolint unusedArguments]
instance (priority := 75) NonUnitalSubalgebraClass.nonUnitalSeminormedRing {S 𝕜 E : Type*}
[CommRing 𝕜] [NonUnitalSeminormedRing E] [Module 𝕜 E] [SetLike S E] [NonUnitalSubringClass S E]
[SMulMemClass S 𝕜 E] (s : S) :
NonUnitalSeminormedRing s :=
{ AddSubgroupClass.seminormedAddCommGroup s, NonUnitalSubringClass.toNonUnitalRing s with
norm_mul_le a b := norm_mul_le a.1 b.1 }
/-- A non-unital subalgebra of a non-unital normed ring is also a non-unital normed ring, with the
restriction of the norm. -/
instance NonUnitalSubalgebra.nonUnitalNormedRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*}
[NonUnitalNormedRing E] [Module 𝕜 E] (s : NonUnitalSubalgebra 𝕜 E) : NonUnitalNormedRing s :=
{ s.nonUnitalSeminormedRing with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
/-- A non-unital subalgebra of a non-unital normed ring is also a non-unital normed ring,
with the restriction of the norm. -/
instance (priority := 75) NonUnitalSubalgebraClass.nonUnitalNormedRing {S 𝕜 E : Type*}
[CommRing 𝕜] [NonUnitalNormedRing E] [Module 𝕜 E] [SetLike S E] [NonUnitalSubringClass S E]
[SMulMemClass S 𝕜 E] (s : S) :
NonUnitalNormedRing s :=
{ nonUnitalSeminormedRing s with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
instance ULift.nonUnitalSeminormedRing : NonUnitalSeminormedRing (ULift α) :=
{ ULift.seminormedAddCommGroup, ULift.nonUnitalRing with
norm_mul_le x y := norm_mul_le x.down y.down }
/-- Non-unital seminormed ring structure on the product of two non-unital seminormed rings,
using the sup norm. -/
instance Prod.nonUnitalSeminormedRing [NonUnitalSeminormedRing β] :
NonUnitalSeminormedRing (α × β) :=
{ seminormedAddCommGroup, instNonUnitalRing with
norm_mul_le x y := calc
‖x * y‖ = ‖(x.1 * y.1, x.2 * y.2)‖ := rfl
_ = max ‖x.1 * y.1‖ ‖x.2 * y.2‖ := rfl
_ ≤ max (‖x.1‖ * ‖y.1‖) (‖x.2‖ * ‖y.2‖) :=
(max_le_max (norm_mul_le x.1 y.1) (norm_mul_le x.2 y.2))
_ = max (‖x.1‖ * ‖y.1‖) (‖y.2‖ * ‖x.2‖) := by simp [mul_comm]
_ ≤ max ‖x.1‖ ‖x.2‖ * max ‖y.2‖ ‖y.1‖ := by
apply max_mul_mul_le_max_mul_max <;> simp [norm_nonneg]
_ = max ‖x.1‖ ‖x.2‖ * max ‖y.1‖ ‖y.2‖ := by simp [max_comm]
_ = ‖x‖ * ‖y‖ := rfl }
instance MulOpposite.instNonUnitalSeminormedRing : NonUnitalSeminormedRing αᵐᵒᵖ where
__ := instNonUnitalRing
__ := instSeminormedAddCommGroup
norm_mul_le := MulOpposite.rec' fun x ↦ MulOpposite.rec' fun y ↦
(norm_mul_le y x).trans_eq (mul_comm _ _)
end NonUnitalSeminormedRing
section SeminormedRing
variable [SeminormedRing α] {a b c : α}
/-- A subalgebra of a seminormed ring is also a seminormed ring, with the restriction of the
norm. -/
instance Subalgebra.seminormedRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*} [SeminormedRing E]
[Algebra 𝕜 E] (s : Subalgebra 𝕜 E) : SeminormedRing s :=
{ s.toSubmodule.seminormedAddCommGroup, s.toRing with
norm_mul_le a b := norm_mul_le a.1 b.1 }
/-- A subalgebra of a seminormed ring is also a seminormed ring, with the restriction of the
norm. -/
-- necessary to require `SMulMemClass S 𝕜 E` so that `𝕜` can be determined as an `outParam`
@[nolint unusedArguments]
instance (priority := 75) SubalgebraClass.seminormedRing {S 𝕜 E : Type*} [CommRing 𝕜]
[SeminormedRing E] [Algebra 𝕜 E] [SetLike S E] [SubringClass S E] [SMulMemClass S 𝕜 E]
(s : S) : SeminormedRing s :=
{ AddSubgroupClass.seminormedAddCommGroup s, SubringClass.toRing s with
norm_mul_le a b := norm_mul_le a.1 b.1 }
/-- A subalgebra of a normed ring is also a normed ring, with the restriction of the norm. -/
instance Subalgebra.normedRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*} [NormedRing E]
[Algebra 𝕜 E] (s : Subalgebra 𝕜 E) : NormedRing s :=
{ s.seminormedRing with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
/-- A subalgebra of a normed ring is also a normed ring, with the restriction of the
norm. -/
instance (priority := 75) SubalgebraClass.normedRing {S 𝕜 E : Type*} [CommRing 𝕜]
[NormedRing E] [Algebra 𝕜 E] [SetLike S E] [SubringClass S E] [SMulMemClass S 𝕜 E]
(s : S) : NormedRing s :=
{ seminormedRing s with
eq_of_dist_eq_zero := eq_of_dist_eq_zero }
theorem Nat.norm_cast_le : ∀ n : ℕ, ‖(n : α)‖ ≤ n * ‖(1 : α)‖
| 0 => by simp
| n + 1 => by
rw [n.cast_succ, n.cast_succ, add_mul, one_mul]
exact norm_add_le_of_le (Nat.norm_cast_le n) le_rfl
theorem List.norm_prod_le' : ∀ {l : List α}, l ≠ [] → ‖l.prod‖ ≤ (l.map norm).prod
| [], h => (h rfl).elim
| [a], _ => by simp
| a::b::l, _ => by
rw [List.map_cons, List.prod_cons, List.prod_cons (a := ‖a‖)]
refine le_trans (norm_mul_le _ _) (mul_le_mul_of_nonneg_left ?_ (norm_nonneg _))
exact List.norm_prod_le' (List.cons_ne_nil b l)
theorem List.nnnorm_prod_le' {l : List α} (hl : l ≠ []) : ‖l.prod‖₊ ≤ (l.map nnnorm).prod :=
(List.norm_prod_le' hl).trans_eq <| by simp [NNReal.coe_list_prod, List.map_map]
theorem List.norm_prod_le [NormOneClass α] : ∀ l : List α, ‖l.prod‖ ≤ (l.map norm).prod
| [] => by simp
| a::l => List.norm_prod_le' (List.cons_ne_nil a l)
theorem List.nnnorm_prod_le [NormOneClass α] (l : List α) : ‖l.prod‖₊ ≤ (l.map nnnorm).prod :=
l.norm_prod_le.trans_eq <| by simp [NNReal.coe_list_prod, List.map_map]
theorem Finset.norm_prod_le' {α : Type*} [NormedCommRing α] (s : Finset ι) (hs : s.Nonempty)
(f : ι → α) : ‖∏ i ∈ s, f i‖ ≤ ∏ i ∈ s, ‖f i‖ := by
rcases s with ⟨⟨l⟩, hl⟩
have : l.map f ≠ [] := by simpa using hs
simpa using List.norm_prod_le' this
theorem Finset.nnnorm_prod_le' {α : Type*} [NormedCommRing α] (s : Finset ι) (hs : s.Nonempty)
(f : ι → α) : ‖∏ i ∈ s, f i‖₊ ≤ ∏ i ∈ s, ‖f i‖₊ :=
(s.norm_prod_le' hs f).trans_eq <| by simp [NNReal.coe_prod]
theorem Finset.norm_prod_le {α : Type*} [NormedCommRing α] [NormOneClass α] (s : Finset ι)
(f : ι → α) : ‖∏ i ∈ s, f i‖ ≤ ∏ i ∈ s, ‖f i‖ := by
rcases s with ⟨⟨l⟩, hl⟩
simpa using (l.map f).norm_prod_le
theorem Finset.nnnorm_prod_le {α : Type*} [NormedCommRing α] [NormOneClass α] (s : Finset ι)
(f : ι → α) : ‖∏ i ∈ s, f i‖₊ ≤ ∏ i ∈ s, ‖f i‖₊ :=
(s.norm_prod_le f).trans_eq <| by simp [NNReal.coe_prod]
/-- If `α` is a seminormed ring, then `‖a ^ n‖₊ ≤ ‖a‖₊ ^ n` for `n > 0`.
See also `nnnorm_pow_le`. -/
theorem nnnorm_pow_le' (a : α) : ∀ {n : ℕ}, 0 < n → ‖a ^ n‖₊ ≤ ‖a‖₊ ^ n
| 1, _ => by simp only [pow_one, le_rfl]
| n + 2, _ => by
simpa only [pow_succ' _ (n + 1)] using
le_trans (nnnorm_mul_le _ _) (mul_le_mul_left' (nnnorm_pow_le' a n.succ_pos) _)
/-- If `α` is a seminormed ring with `‖1‖₊ = 1`, then `‖a ^ n‖₊ ≤ ‖a‖₊ ^ n`.
See also `nnnorm_pow_le'`. -/
theorem nnnorm_pow_le [NormOneClass α] (a : α) (n : ℕ) : ‖a ^ n‖₊ ≤ ‖a‖₊ ^ n :=
Nat.recOn n (by simp only [pow_zero, nnnorm_one, le_rfl])
fun k _hk => nnnorm_pow_le' a k.succ_pos
/-- If `α` is a seminormed ring, then `‖a ^ n‖ ≤ ‖a‖ ^ n` for `n > 0`. See also `norm_pow_le`. -/
theorem norm_pow_le' (a : α) {n : ℕ} (h : 0 < n) : ‖a ^ n‖ ≤ ‖a‖ ^ n := by
simpa only [NNReal.coe_pow, coe_nnnorm] using NNReal.coe_mono (nnnorm_pow_le' a h)
/-- If `α` is a seminormed ring with `‖1‖ = 1`, then `‖a ^ n‖ ≤ ‖a‖ ^ n`.
See also `norm_pow_le'`. -/
theorem norm_pow_le [NormOneClass α] (a : α) (n : ℕ) : ‖a ^ n‖ ≤ ‖a‖ ^ n :=
Nat.recOn n (by simp only [pow_zero, norm_one, le_rfl])
fun n _hn => norm_pow_le' a n.succ_pos
theorem eventually_norm_pow_le (a : α) : ∀ᶠ n : ℕ in atTop, ‖a ^ n‖ ≤ ‖a‖ ^ n :=
eventually_atTop.mpr ⟨1, fun _b h => norm_pow_le' a (Nat.succ_le_iff.mp h)⟩
instance ULift.seminormedRing : SeminormedRing (ULift α) :=
{ ULift.nonUnitalSeminormedRing, ULift.ring with }
/-- Seminormed ring structure on the product of two seminormed rings,
using the sup norm. -/
instance Prod.seminormedRing [SeminormedRing β] : SeminormedRing (α × β) :=
{ nonUnitalSeminormedRing, instRing with }
instance MulOpposite.instSeminormedRing : SeminormedRing αᵐᵒᵖ where
__ := instRing
__ := instNonUnitalSeminormedRing
/-- This inequality is particularly useful when `c = 1` and `‖a‖ = ‖b‖ = 1` as it then shows that
chord length is a metric on the unit complex numbers. -/
lemma norm_sub_mul_le (ha : ‖a‖ ≤ 1) : ‖c - a * b‖ ≤ ‖c - a‖ + ‖1 - b‖ :=
calc
_ ≤ ‖c - a‖ + ‖a * (1 - b)‖ := by
simpa [mul_one_sub] using norm_sub_le_norm_sub_add_norm_sub c a (a * b)
_ ≤ ‖c - a‖ + ‖a‖ * ‖1 - b‖ := by gcongr; exact norm_mul_le ..
_ ≤ ‖c - a‖ + 1 * ‖1 - b‖ := by gcongr
_ = ‖c - a‖ + ‖1 - b‖ := by simp
/-- This inequality is particularly useful when `c = 1` and `‖a‖ = ‖b‖ = 1` as it then shows that
chord length is a metric on the unit complex numbers. -/
lemma norm_sub_mul_le' (hb : ‖b‖ ≤ 1) : ‖c - a * b‖ ≤ ‖1 - a‖ + ‖c - b‖ := by
rw [add_comm]; exact norm_sub_mul_le (α := αᵐᵒᵖ) hb
/-- This inequality is particularly useful when `c = 1` and `‖a‖ = ‖b‖ = 1` as it then shows that
chord length is a metric on the unit complex numbers. -/
lemma nnnorm_sub_mul_le (ha : ‖a‖₊ ≤ 1) : ‖c - a * b‖₊ ≤ ‖c - a‖₊ + ‖1 - b‖₊ := norm_sub_mul_le ha
/-- This inequality is particularly useful when `c = 1` and `‖a‖ = ‖b‖ = 1` as it then shows that
chord length is a metric on the unit complex numbers. -/
lemma nnnorm_sub_mul_le' (hb : ‖b‖₊ ≤ 1) : ‖c - a * b‖₊ ≤ ‖1 - a‖₊ + ‖c - b‖₊ := norm_sub_mul_le' hb
lemma norm_commutator_units_sub_one_le (a b : αˣ) :
‖(a * b * a⁻¹ * b⁻¹).val - 1‖ ≤ 2 * ‖a⁻¹.val‖ * ‖b⁻¹.val‖ * ‖a.val - 1‖ * ‖b.val - 1‖ :=
calc
‖(a * b * a⁻¹ * b⁻¹).val - 1‖ = ‖(a * b - b * a) * a⁻¹.val * b⁻¹.val‖ := by simp [sub_mul, *]
_ ≤ ‖(a * b - b * a : α)‖ * ‖a⁻¹.val‖ * ‖b⁻¹.val‖ := norm_mul₃_le
_ = ‖(a - 1 : α) * (b - 1) - (b - 1) * (a - 1)‖ * ‖a⁻¹.val‖ * ‖b⁻¹.val‖ := by
simp_rw [sub_one_mul, mul_sub_one]; abel_nf
_ ≤ (‖(a - 1 : α) * (b - 1)‖ + ‖(b - 1 : α) * (a - 1)‖) * ‖a⁻¹.val‖ * ‖b⁻¹.val‖ := by
gcongr; exact norm_sub_le ..
_ ≤ (‖a.val - 1‖ * ‖b.val - 1‖ + ‖b.val - 1‖ * ‖a.val - 1‖) * ‖a⁻¹.val‖ * ‖b⁻¹.val‖ := by
gcongr <;> exact norm_mul_le ..
_ = 2 * ‖a⁻¹.val‖ * ‖b⁻¹.val‖ * ‖a.val - 1‖ * ‖b.val - 1‖ := by ring
lemma nnnorm_commutator_units_sub_one_le (a b : αˣ) :
‖(a * b * a⁻¹ * b⁻¹).val - 1‖₊ ≤ 2 * ‖a⁻¹.val‖₊ * ‖b⁻¹.val‖₊ * ‖a.val - 1‖₊ * ‖b.val - 1‖₊ := by
simpa using norm_commutator_units_sub_one_le a b
/-- A homomorphism `f` between semi_normed_rings is bounded if there exists a positive
constant `C` such that for all `x` in `α`, `norm (f x) ≤ C * norm x`. -/
def RingHom.IsBounded {α : Type*} [SeminormedRing α] {β : Type*} [SeminormedRing β]
(f : α →+* β) : Prop :=
∃ C : ℝ, 0 < C ∧ ∀ x : α, norm (f x) ≤ C * norm x
end SeminormedRing
section NonUnitalNormedRing
variable [NonUnitalNormedRing α]
instance ULift.nonUnitalNormedRing : NonUnitalNormedRing (ULift α) :=
{ ULift.nonUnitalSeminormedRing, ULift.normedAddCommGroup with }
/-- Non-unital normed ring structure on the product of two non-unital normed rings,
using the sup norm. -/
instance Prod.nonUnitalNormedRing [NonUnitalNormedRing β] : NonUnitalNormedRing (α × β) :=
{ Prod.nonUnitalSeminormedRing, Prod.normedAddCommGroup with }
instance MulOpposite.instNonUnitalNormedRing : NonUnitalNormedRing αᵐᵒᵖ where
__ := instNonUnitalRing
__ := instNonUnitalSeminormedRing
__ := instNormedAddCommGroup
end NonUnitalNormedRing
section NormedRing
variable [NormedRing α]
theorem Units.norm_pos [Nontrivial α] (x : αˣ) : 0 < ‖(x : α)‖ :=
norm_pos_iff.mpr (Units.ne_zero x)
theorem Units.nnnorm_pos [Nontrivial α] (x : αˣ) : 0 < ‖(x : α)‖₊ :=
x.norm_pos
instance ULift.normedRing : NormedRing (ULift α) :=
{ ULift.seminormedRing, ULift.normedAddCommGroup with }
/-- Normed ring structure on the product of two normed rings, using the sup norm. -/
instance Prod.normedRing [NormedRing β] : NormedRing (α × β) :=
{ nonUnitalNormedRing, instRing with }
instance MulOpposite.instNormedRing : NormedRing αᵐᵒᵖ where
__ := instRing
__ := instSeminormedRing
__ := instNormedAddCommGroup
end NormedRing
section NonUnitalSeminormedCommRing
variable [NonUnitalSeminormedCommRing α]
instance ULift.nonUnitalSeminormedCommRing : NonUnitalSeminormedCommRing (ULift α) :=
{ ULift.nonUnitalSeminormedRing, ULift.nonUnitalCommRing with }
/-- Non-unital seminormed commutative ring structure on the product of two non-unital seminormed
commutative rings, using the sup norm. -/
instance Prod.nonUnitalSeminormedCommRing [NonUnitalSeminormedCommRing β] :
NonUnitalSeminormedCommRing (α × β) :=
{ nonUnitalSeminormedRing, instNonUnitalCommRing with }
instance MulOpposite.instNonUnitalSeminormedCommRing : NonUnitalSeminormedCommRing αᵐᵒᵖ where
__ := instNonUnitalSeminormedRing
__ := instNonUnitalCommRing
end NonUnitalSeminormedCommRing
section NonUnitalNormedCommRing
variable [NonUnitalNormedCommRing α]
/-- A non-unital subalgebra of a non-unital seminormed commutative ring is also a non-unital
seminormed commutative ring, with the restriction of the norm. -/
instance NonUnitalSubalgebra.nonUnitalSeminormedCommRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*}
[NonUnitalSeminormedCommRing E] [Module 𝕜 E] (s : NonUnitalSubalgebra 𝕜 E) :
NonUnitalSeminormedCommRing s :=
{ s.nonUnitalSeminormedRing, s.toNonUnitalCommRing with }
/-- A non-unital subalgebra of a non-unital normed commutative ring is also a non-unital normed
commutative ring, with the restriction of the norm. -/
instance NonUnitalSubalgebra.nonUnitalNormedCommRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*}
[NonUnitalNormedCommRing E] [Module 𝕜 E] (s : NonUnitalSubalgebra 𝕜 E) :
NonUnitalNormedCommRing s :=
{ s.nonUnitalSeminormedCommRing, s.nonUnitalNormedRing with }
instance ULift.nonUnitalNormedCommRing : NonUnitalNormedCommRing (ULift α) :=
{ ULift.nonUnitalSeminormedCommRing, ULift.normedAddCommGroup with }
/-- Non-unital normed commutative ring structure on the product of two non-unital normed
commutative rings, using the sup norm. -/
instance Prod.nonUnitalNormedCommRing [NonUnitalNormedCommRing β] :
NonUnitalNormedCommRing (α × β) :=
{ Prod.nonUnitalSeminormedCommRing, Prod.normedAddCommGroup with }
instance MulOpposite.instNonUnitalNormedCommRing : NonUnitalNormedCommRing αᵐᵒᵖ where
__ := instNonUnitalNormedRing
__ := instNonUnitalSeminormedCommRing
end NonUnitalNormedCommRing
section SeminormedCommRing
variable [SeminormedCommRing α]
instance ULift.seminormedCommRing : SeminormedCommRing (ULift α) :=
{ ULift.nonUnitalSeminormedRing, ULift.commRing with }
/-- Seminormed commutative ring structure on the product of two seminormed commutative rings,
using the sup norm. -/
instance Prod.seminormedCommRing [SeminormedCommRing β] : SeminormedCommRing (α × β) :=
{ Prod.nonUnitalSeminormedCommRing, instCommRing with }
instance MulOpposite.instSeminormedCommRing : SeminormedCommRing αᵐᵒᵖ where
__ := instSeminormedRing
__ := instNonUnitalSeminormedCommRing
end SeminormedCommRing
section NormedCommRing
/-- A subalgebra of a seminormed commutative ring is also a seminormed commutative ring, with the
restriction of the norm. -/
instance Subalgebra.seminormedCommRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*} [SeminormedCommRing E]
[Algebra 𝕜 E] (s : Subalgebra 𝕜 E) : SeminormedCommRing s :=
{ s.seminormedRing, s.toCommRing with }
/-- A subalgebra of a normed commutative ring is also a normed commutative ring, with the
restriction of the norm. -/
instance Subalgebra.normedCommRing {𝕜 : Type*} [CommRing 𝕜] {E : Type*} [NormedCommRing E]
[Algebra 𝕜 E] (s : Subalgebra 𝕜 E) : NormedCommRing s :=
{ s.seminormedCommRing, s.normedRing with }
variable [NormedCommRing α]
instance ULift.normedCommRing : NormedCommRing (ULift α) :=
{ ULift.normedRing (α := α), ULift.seminormedCommRing with }
/-- Normed commutative ring structure on the product of two normed commutative rings, using the sup
norm. -/
instance Prod.normedCommRing [NormedCommRing β] : NormedCommRing (α × β) :=
{ nonUnitalNormedRing, instCommRing with }
instance MulOpposite.instNormedCommRing : NormedCommRing αᵐᵒᵖ where
__ := instNormedRing
__ := instSeminormedCommRing
/-- The restriction of a power-multiplicative function to a subalgebra is power-multiplicative. -/
theorem IsPowMul.restriction {R S : Type*} [CommRing R] [Ring S] [Algebra R S]
(A : Subalgebra R S) {f : S → ℝ} (hf_pm : IsPowMul f) :
IsPowMul fun x : A => f x.val := fun x n hn => by
simpa [SubsemiringClass.coe_pow] using hf_pm (↑x) hn
end NormedCommRing
instance Real.normedCommRing : NormedCommRing ℝ :=
{ Real.normedAddCommGroup, Real.commRing with norm_mul_le x y := (abs_mul x y).le }
namespace NNReal
open NNReal
theorem norm_eq (x : ℝ≥0) : ‖(x : ℝ)‖ = x := by rw [Real.norm_eq_abs, x.abs_eq]
@[simp] lemma nnnorm_eq (x : ℝ≥0) : ‖(x : ℝ)‖₊ = x := by ext; simp [nnnorm]
@[simp] lemma enorm_eq (x : ℝ≥0) : ‖(x : ℝ)‖ₑ = x := by simp [enorm]
end NNReal
/-- A restatement of `MetricSpace.tendsto_atTop` in terms of the norm. -/
theorem NormedAddCommGroup.tendsto_atTop [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)]
{β : Type*} [SeminormedAddCommGroup β] {f : α → β} {b : β} :
Tendsto f atTop (𝓝 b) ↔ ∀ ε, 0 < ε → ∃ N, ∀ n, N ≤ n → ‖f n - b‖ < ε :=
(atTop_basis.tendsto_iff Metric.nhds_basis_ball).trans (by simp [dist_eq_norm])
/-- A variant of `NormedAddCommGroup.tendsto_atTop` that
uses `∃ N, ∀ n > N, ...` rather than `∃ N, ∀ n ≥ N, ...`
-/
theorem NormedAddCommGroup.tendsto_atTop' [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)]
[NoMaxOrder α] {β : Type*} [SeminormedAddCommGroup β] {f : α → β} {b : β} :
Tendsto f atTop (𝓝 b) ↔ ∀ ε, 0 < ε → ∃ N, ∀ n, N < n → ‖f n - b‖ < ε :=
(atTop_basis_Ioi.tendsto_iff Metric.nhds_basis_ball).trans (by simp [dist_eq_norm])
section RingHomIsometric
variable {R₁ R₂ : Type*}
/-- This class states that a ring homomorphism is isometric. This is a sufficient assumption
for a continuous semilinear map to be bounded and this is the main use for this typeclass. -/
class RingHomIsometric [Semiring R₁] [Semiring R₂] [Norm R₁] [Norm R₂] (σ : R₁ →+* R₂) : Prop where
/-- The ring homomorphism is an isometry. -/
norm_map : ∀ {x : R₁}, ‖σ x‖ = ‖x‖
@[deprecated (since := "2025-08-03")] alias RingHomIsometric.is_iso := RingHomIsometric.norm_map
attribute [simp] RingHomIsometric.norm_map
@[simp]
theorem RingHomIsometric.nnnorm_map [SeminormedRing R₁] [SeminormedRing R₂] (σ : R₁ →+* R₂)
[RingHomIsometric σ] (x : R₁) : ‖σ x‖₊ = ‖x‖₊ :=
NNReal.eq norm_map
@[simp]
theorem RingHomIsometric.enorm_map [SeminormedRing R₁] [SeminormedRing R₂] (σ : R₁ →+* R₂)
[RingHomIsometric σ] (x : R₁) : ‖σ x‖ₑ = ‖x‖ₑ :=
congrArg ENNReal.ofNNReal <| nnnorm_map σ x
variable [SeminormedRing R₁]
instance RingHomIsometric.ids : RingHomIsometric (RingHom.id R₁) :=
⟨rfl⟩
end RingHomIsometric
section NormMulClass
/-- A mixin class for strict multiplicativity of the norm, `‖a * b‖ = ‖a‖ * ‖b‖` (rather than
`≤` as in the definition of `NormedRing`). Many `NormedRing`s satisfy this stronger property,
including all `NormedDivisionRing`s and `NormedField`s. -/
class NormMulClass (α : Type*) [Norm α] [Mul α] : Prop where
/-- The norm is multiplicative. -/
protected norm_mul : ∀ (a b : α), ‖a * b‖ = ‖a‖ * ‖b‖
@[simp] lemma norm_mul [Norm α] [Mul α] [NormMulClass α] (a b : α) :
‖a * b‖ = ‖a‖ * ‖b‖ :=
NormMulClass.norm_mul a b
section SeminormedAddCommGroup
variable [SeminormedAddCommGroup α] [Mul α] [NormMulClass α] (a b : α)
@[simp] lemma nnnorm_mul : ‖a * b‖₊ = ‖a‖₊ * ‖b‖₊ := NNReal.eq <| norm_mul a b
@[simp] lemma enorm_mul : ‖a * b‖ₑ = ‖a‖ₑ * ‖b‖ₑ := by simp [enorm]
end SeminormedAddCommGroup
section SeminormedRing
variable [SeminormedRing α] [NormOneClass α] [NormMulClass α]
/-- `norm` as a `MonoidWithZeroHom`. -/
@[simps]
def normHom : α →*₀ ℝ where
toFun := (‖·‖)
map_zero' := norm_zero
map_one' := norm_one
map_mul' := norm_mul
/-- `nnnorm` as a `MonoidWithZeroHom`. -/
@[simps]
def nnnormHom : α →*₀ ℝ≥0 where
toFun := (‖·‖₊)
map_zero' := nnnorm_zero
map_one' := nnnorm_one
map_mul' := nnnorm_mul
@[simp]
theorem norm_pow (a : α) : ∀ n : ℕ, ‖a ^ n‖ = ‖a‖ ^ n :=
(normHom.toMonoidHom : α →* ℝ).map_pow a
@[simp]
theorem nnnorm_pow (a : α) (n : ℕ) : ‖a ^ n‖₊ = ‖a‖₊ ^ n :=
(nnnormHom.toMonoidHom : α →* ℝ≥0).map_pow a n
@[simp] lemma enorm_pow (a : α) (n : ℕ) : ‖a ^ n‖ₑ = ‖a‖ₑ ^ n := by simp [enorm]
protected theorem List.norm_prod (l : List α) : ‖l.prod‖ = (l.map norm).prod :=
map_list_prod (normHom.toMonoidHom : α →* ℝ) _
protected theorem List.nnnorm_prod (l : List α) : ‖l.prod‖₊ = (l.map nnnorm).prod :=
map_list_prod (nnnormHom.toMonoidHom : α →* ℝ≥0) _
end SeminormedRing
section SeminormedCommRing
variable [SeminormedCommRing α] [NormMulClass α] [NormOneClass α]
@[simp]
theorem norm_prod (s : Finset β) (f : β → α) : ‖∏ b ∈ s, f b‖ = ∏ b ∈ s, ‖f b‖ :=
map_prod normHom.toMonoidHom f s
@[simp]
theorem nnnorm_prod (s : Finset β) (f : β → α) : ‖∏ b ∈ s, f b‖₊ = ∏ b ∈ s, ‖f b‖₊ :=
map_prod nnnormHom.toMonoidHom f s
end SeminormedCommRing
section NormedAddCommGroup
variable [NormedAddCommGroup α] [MulOneClass α] [NormMulClass α] [Nontrivial α]
/-- Deduce `NormOneClass` from `NormMulClass` under a suitable nontriviality hypothesis. Not
an instance, in order to avoid loops with `NormOneClass.nontrivial`. -/
lemma NormMulClass.toNormOneClass : NormOneClass α where
norm_one := by
obtain ⟨u, hu⟩ := exists_ne (0 : α)
simpa [mul_eq_left₀ (norm_ne_zero_iff.mpr hu)] using (norm_mul u 1).symm
end NormedAddCommGroup
section NormedRing
variable [NormedRing α] [NormMulClass α]
instance NormMulClass.isAbsoluteValue_norm : IsAbsoluteValue (norm : α → ℝ) where
abv_nonneg' := norm_nonneg
abv_eq_zero' := norm_eq_zero
abv_add' := norm_add_le
abv_mul' := norm_mul
instance NormMulClass.toNoZeroDivisors : NoZeroDivisors α where
eq_zero_or_eq_zero_of_mul_eq_zero h := by
simpa only [← norm_eq_zero (E := α), norm_mul, mul_eq_zero] using h
end NormedRing
end NormMulClass
/-! ### Induced normed structures -/
section Induced
variable {F : Type*} (R S : Type*) [FunLike F R S]
/-- A non-unital ring homomorphism from a `NonUnitalRing` to a `NonUnitalSeminormedRing`
induces a `NonUnitalSeminormedRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NonUnitalSeminormedRing.induced [NonUnitalRing R] [NonUnitalSeminormedRing S]
[NonUnitalRingHomClass F R S] (f : F) : NonUnitalSeminormedRing R :=
{ SeminormedAddCommGroup.induced R S f, ‹NonUnitalRing R› with
norm_mul_le x y := show ‖f _‖ ≤ _ from (map_mul f x y).symm ▸ norm_mul_le (f x) (f y) }
/-- An injective non-unital ring homomorphism from a `NonUnitalRing` to a
`NonUnitalNormedRing` induces a `NonUnitalNormedRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NonUnitalNormedRing.induced [NonUnitalRing R] [NonUnitalNormedRing S]
[NonUnitalRingHomClass F R S] (f : F) (hf : Function.Injective f) : NonUnitalNormedRing R :=
{ NonUnitalSeminormedRing.induced R S f, NormedAddCommGroup.induced R S f hf with }
/-- A non-unital ring homomorphism from a `Ring` to a `SeminormedRing` induces a
`SeminormedRing` structure on the domain.
See note [reducible non-instances] -/
abbrev SeminormedRing.induced [Ring R] [SeminormedRing S] [NonUnitalRingHomClass F R S] (f : F) :
SeminormedRing R :=
{ NonUnitalSeminormedRing.induced R S f, SeminormedAddCommGroup.induced R S f, ‹Ring R› with }
/-- An injective non-unital ring homomorphism from a `Ring` to a `NormedRing` induces a
`NormedRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NormedRing.induced [Ring R] [NormedRing S] [NonUnitalRingHomClass F R S] (f : F)
(hf : Function.Injective f) : NormedRing R :=
{ NonUnitalSeminormedRing.induced R S f, NormedAddCommGroup.induced R S f hf, ‹Ring R› with }
/-- A non-unital ring homomorphism from a `NonUnitalCommRing` to a `NonUnitalSeminormedCommRing`
induces a `NonUnitalSeminormedCommRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NonUnitalSeminormedCommRing.induced [NonUnitalCommRing R] [NonUnitalSeminormedCommRing S]
[NonUnitalRingHomClass F R S] (f : F) : NonUnitalSeminormedCommRing R :=
{ NonUnitalSeminormedRing.induced R S f, ‹NonUnitalCommRing R› with }
/-- An injective non-unital ring homomorphism from a `NonUnitalCommRing` to a
`NonUnitalNormedCommRing` induces a `NonUnitalNormedCommRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NonUnitalNormedCommRing.induced [NonUnitalCommRing R] [NonUnitalNormedCommRing S]
[NonUnitalRingHomClass F R S] (f : F) (hf : Function.Injective f) : NonUnitalNormedCommRing R :=
{ NonUnitalNormedRing.induced R S f hf, ‹NonUnitalCommRing R› with }
/-- A non-unital ring homomorphism from a `CommRing` to a `SeminormedRing` induces a
`SeminormedCommRing` structure on the domain.
See note [reducible non-instances] -/
abbrev SeminormedCommRing.induced [CommRing R] [SeminormedRing S] [NonUnitalRingHomClass F R S]
(f : F) : SeminormedCommRing R :=
{ NonUnitalSeminormedRing.induced R S f, SeminormedAddCommGroup.induced R S f, ‹CommRing R› with }
/-- An injective non-unital ring homomorphism from a `CommRing` to a `NormedRing` induces a
`NormedCommRing` structure on the domain.
See note [reducible non-instances] -/
abbrev NormedCommRing.induced [CommRing R] [NormedRing S] [NonUnitalRingHomClass F R S] (f : F)
(hf : Function.Injective f) : NormedCommRing R :=
{ SeminormedCommRing.induced R S f, NormedAddCommGroup.induced R S f hf with }
/-- A ring homomorphism from a `Ring R` to a `SeminormedRing S` which induces the norm structure
`SeminormedRing.induced` makes `R` satisfy `‖(1 : R)‖ = 1` whenever `‖(1 : S)‖ = 1`. -/
theorem NormOneClass.induced {F : Type*} (R S : Type*) [Ring R] [SeminormedRing S]
[NormOneClass S] [FunLike F R S] [RingHomClass F R S] (f : F) :
@NormOneClass R (SeminormedRing.induced R S f).toNorm _ :=
let _ : SeminormedRing R := SeminormedRing.induced R S f
{ norm_one := (congr_arg norm (map_one f)).trans norm_one }
/-- A ring homomorphism from a `Ring R` to a `SeminormedRing S` which induces the norm structure
`SeminormedRing.induced` makes `R` satisfy `‖(1 : R)‖ = 1` whenever `‖(1 : S)‖ = 1`. -/
theorem NormMulClass.induced {F : Type*} (R S : Type*) [Ring R] [SeminormedRing S]
[NormMulClass S] [FunLike F R S] [RingHomClass F R S] (f : F) :
@NormMulClass R (SeminormedRing.induced R S f).toNorm _ :=
let _ : SeminormedRing R := SeminormedRing.induced R S f
{ norm_mul x y := (congr_arg norm (map_mul f x y)).trans <| norm_mul _ _ }
end Induced
namespace SubringClass
variable {S R : Type*} [SetLike S R]
instance toSeminormedRing [SeminormedRing R] [SubringClass S R] (s : S) : SeminormedRing s :=
SeminormedRing.induced s R (SubringClass.subtype s)
instance toNormedRing [NormedRing R] [SubringClass S R] (s : S) : NormedRing s :=
NormedRing.induced s R (SubringClass.subtype s) Subtype.val_injective
instance toSeminormedCommRing [SeminormedCommRing R] [_h : SubringClass S R] (s : S) :
SeminormedCommRing s :=
{ SubringClass.toSeminormedRing s with mul_comm := mul_comm }
instance toNormedCommRing [NormedCommRing R] [SubringClass S R] (s : S) : NormedCommRing s :=
{ SubringClass.toNormedRing s with mul_comm := mul_comm }
instance toNormOneClass [SeminormedRing R] [NormOneClass R] [SubringClass S R] (s : S) :
NormOneClass s :=
.induced s R <| SubringClass.subtype _
instance toNormMulClass [SeminormedRing R] [NormMulClass R] [SubringClass S R] (s : S) :
NormMulClass s :=
.induced s R <| SubringClass.subtype _
end SubringClass
namespace AbsoluteValue
/-- A real absolute value on a ring determines a `NormedRing` structure. -/
noncomputable def toNormedRing {R : Type*} [Ring R] (v : AbsoluteValue R ℝ) : NormedRing R where
norm := v
dist x y := v (x - y)
dist_eq _ _ := rfl
dist_self x := by simp only [sub_self, map_zero]
dist_comm := v.map_sub
dist_triangle := v.sub_le
edist_dist x y := rfl
norm_mul_le x y := (v.map_mul x y).le
eq_of_dist_eq_zero := by simp only [AbsoluteValue.map_sub_eq_zero_iff, imp_self, implies_true]
end AbsoluteValue
|
Main.lean
|
/-
Copyright (c) 2023 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import ImportGraph.CurrentModule
import ImportGraph.Imports
import Mathlib.Data.String.Defs
import Mathlib.Util.FormatTable
import Cli
import LongestPole.SpeedCenterJson
/-!
# `lake exe pole`
Longest pole analysis for Mathlib build times.
-/
open Cli
open Lean Meta
/-- Runs a terminal command and retrieves its output -/
def runCmd (cmd : String) (args : Array String) (throwFailure := true) : IO String := do
let out ← IO.Process.output { cmd := cmd, args := args }
if out.exitCode != 0 && throwFailure then throw <| IO.userError out.stderr
else return out.stdout
def runCurl (args : Array String) (throwFailure := true) : IO String := do
runCmd "curl" args throwFailure
def mathlib4RepoId : String := "e7b27246-a3e6-496a-b552-ff4b45c7236e"
namespace SpeedCenterAPI
def runJson (hash : String) (repoId : String := mathlib4RepoId) : IO String :=
runCurl #[s!"https://speed.lean-lang.org/mathlib4/api/run/{repoId}?hash={hash}"]
def getRunResponse (hash : String) : IO RunResponse := do
let r ← runJson hash
match Json.parse r with
| .error e => throw <| IO.userError s!"Could not parse speed center JSON: {e}\n{r}"
| .ok j => match fromJson? j with
| .ok v => pure v
| .error e => match fromJson? j with
| .ok (v : ErrorMessage) =>
IO.eprintln s!"https://speed.lean-lang.org says: {v.message}"
IO.eprintln s!"If you are working on a Mathlib PR, you can comment !bench to make the bot run benchmarks."
IO.eprintln s!"Otherwise, try moving to an older commit?"
IO.Process.exit 1
| .error _ => throw <| IO.userError s!"Could not parse speed center JSON: {e}\n{j}"
def RunResponse.instructions (response : RunResponse) :
NameMap Float := Id.run do
let mut r : NameMap Float := ∅
for m in response.run.result.measurements do
let n := m.dimension.benchmark
if n.startsWith "~" then
r := r.insert (n.drop 1).toName (m.value/10^6)
return r
def instructions (run : String) : IO (NameMap Float) :=
return (← getRunResponse run).instructions
end SpeedCenterAPI
def headSha : IO String := return (← runCmd "git" #["rev-parse", "HEAD"]).trim
/-- Given `NameMap`s indicating how many instructions are in each file and which files are imported
by which others, returns a new `NameMap` of the cumulative instructions taken in the longest pole
of imports including that file. -/
partial def cumulativeInstructions (instructions : NameMap Float) (graph : NameMap (Array Name)) :
NameMap Float :=
graph.fold (init := ∅) fun m n _ => go n m
where
-- Helper which adds the entry for `n` to `m` if it's not already there.
go (n : Name) (m : NameMap Float) : NameMap Float :=
if m.contains n then
m
else
let parents := graph.find! n
-- Add all parents to the map first
let m := parents.foldr (init := m) fun parent m => go parent m
-- Determine the maximum cumulative instruction count among the parents
let t := (parents.map fun parent => (m.find! parent)).foldr max 0
m.insert n (instructions.findD n 0 + t)
/-- Given `NameMap`s indicating how many instructions are in each file and which files are imported
by which others, returns a new `NameMap` indicating the last of the parents of each file that would
be built in a totally parallel setting. -/
def slowestParents (cumulative : NameMap Float) (graph : NameMap (Array Name)) :
NameMap Name :=
graph.fold (init := ∅) fun m n parents =>
match parents.toList with
-- If there are no parents, return the file itself
| [] => m
| h :: t => Id.run do
let mut slowestParent := h
for parent in t do
if cumulative.find! parent > cumulative.find! slowestParent then
slowestParent := parent
return m.insert n slowestParent
/-- Given `NameMap`s indicating how many instructions are in each file and which files are imported
by which others, returns a new `NameMap` indicating the total instructions taken to compile the
file, including all instructions in transitively imported files.
-/
def totalInstructions (instructions : NameMap Float) (graph : NameMap (Array Name)) :
NameMap Float :=
let transitive := graph.transitiveClosure
transitive.filterMap
fun n s => some <| s.fold (init := instructions.findD n 0)
fun t n' => t + (instructions.findD n' 0)
/-- Convert a float to a string with a fixed number of decimal places. -/
def Float.toStringDecimals (r : Float) (digits : Nat) : String :=
match r.toString.split (· = '.') with
| [a, b] => a ++ "." ++ b.take digits
| _ => r.toString
open System in
-- Lines of code is obviously a `Nat` not a `Float`,
-- but we're using it here as a very rough proxy for instruction count.
def countLOC (modules : List Name) : IO (NameMap Float) := do
let mut r := {}
for m in modules do
if let .some fp ← Lean.SearchPath.findModuleWithExt [s!".{FilePath.pathSeparator}"] "lean" m
then
let src ← IO.FS.readFile fp
r := r.insert m (src.toList.count '\n').toFloat
return r
/-- Implementation of the longest pole command line program. -/
def longestPoleCLI (args : Cli.Parsed) : IO UInt32 := do
let to ← match args.flag? "to" with
| some to => pure <| to.as! ModuleName
| none => ImportGraph.getCurrentModule -- autodetect the main module from the `lakefile.lean`
searchPathRef.set compile_time_search_path%
-- It may be reasonable to remove this again after https://github.com/leanprover/lean4/pull/6325
unsafe enableInitializersExecution
unsafe withImportModules #[{module := to}] {} (trustLevel := 1024) fun env => do
let graph := env.importGraph
let sha ← headSha
IO.eprintln s!"Analyzing {to} at {sha}"
let instructions ← if args.hasFlag "loc" then
countLOC (graph.toList.map (·.1))
else
SpeedCenterAPI.instructions sha
let cumulative := cumulativeInstructions instructions graph
let total := totalInstructions instructions graph
let slowest := slowestParents cumulative graph
let mut table := #[]
let mut n := some to
while hn : n.isSome do
let n' := n.get hn
let i := instructions.findD n' 0
let c := cumulative.find! n'
let t := total.find! n'
let r := (t / c).toStringDecimals 2
table := table.push #[n.get!.toString, toString i.toUInt64, toString c.toUInt64, r]
n := slowest.find? n'
let instructionsHeader := if args.hasFlag "loc" then "LoC" else "instructions"
IO.println (formatTable
#["file", instructionsHeader, "cumulative", "parallelism"]
table
#[Alignment.left, Alignment.right, Alignment.right, Alignment.center])
return 0
/-- Setting up command line options and help text for `lake exe pole`. -/
def pole : Cmd := `[Cli|
pole VIA longestPoleCLI; ["0.0.1"]
"Calculate the longest pole for building Mathlib (or downstream projects).\n" ++
"Use as `lake exe pole` or `lake exe pole --to MyProject.MyFile`.\n\n" ++
"Prints a sequence of imports starting at the target.\n" ++
"For each file, prints the cumulative instructions (in billions)\n" ++
"assuming infinite parallelism, and the speed-up factor over sequential processing."
FLAGS:
to : ModuleName; "Calculate the longest pole to the specified module."
loc; "Use lines of code instead of speedcenter instruction counts."
]
/-- `lake exe pole` -/
def main (args : List String) : IO UInt32 :=
pole.validate args
|
Basic.lean
|
/-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Reid Barton, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.Connected
import Mathlib.CategoryTheory.Limits.Constructions.Over.Products
import Mathlib.CategoryTheory.Limits.Constructions.Over.Connected
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
import Mathlib.CategoryTheory.Limits.Constructions.Equalizers
/-!
# Limits in the over category
Declare instances for limits in the over category: If `C` has finite wide pullbacks, `Over B` has
finite limits, and if `C` has arbitrary wide pullbacks then `Over B` has limits.
-/
universe w v u
-- morphism levels before object levels. See note [category_theory universes].
open CategoryTheory CategoryTheory.Limits
variable {C : Type u} [Category.{v} C]
variable {X : C}
namespace CategoryTheory.Over
/-- Make sure we can derive pullbacks in `Over B`. -/
instance {B : C} [HasPullbacks C] : HasPullbacks (Over B) := inferInstance
/-- Make sure we can derive equalizers in `Over B`. -/
instance {B : C} [HasEqualizers C] : HasEqualizers (Over B) := inferInstance
instance hasFiniteLimits {B : C} [HasFiniteWidePullbacks C] : HasFiniteLimits (Over B) := by
have := ConstructProducts.over_finiteProducts_of_finiteWidePullbacks (B := B)
have := hasEqualizers_of_hasPullbacks_and_binary_products (C := Over B)
apply hasFiniteLimits_of_hasEqualizers_and_finite_products
instance hasLimits {B : C} [HasWidePullbacks.{w} C] : HasLimitsOfSize.{w, w} (Over B) := by
have := ConstructProducts.over_binaryProduct_of_pullback (B := B)
have := hasEqualizers_of_hasPullbacks_and_binary_products (C := Over B)
have := ConstructProducts.over_products_of_widePullbacks (B := B)
apply has_limits_of_hasEqualizers_and_products
end CategoryTheory.Over
|
SelectInsertParamsClass.lean
|
/-
Copyright (c) 2023 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Init
import Lean.Widget.InteractiveGoal
import Lean.Elab.Deriving.Basic
/-! # SelectInsertParamsClass
Defines the basic class of parameters for a select and insert widget.
This needs to be in a separate file in order to initialize the deriving handler.
-/
open Lean Meta Server
/-- Structures providing parameters for a Select and insert widget. -/
class SelectInsertParamsClass (α : Type) where
/-- Cursor position in the file at which the widget is being displayed. -/
pos : α → Lsp.Position
/-- The current tactic-mode goals. -/
goals : α → Array Widget.InteractiveGoal
/-- Locations currently selected in the goal state. -/
selectedLocations : α → Array SubExpr.GoalsLocation
/-- The range in the source document where the command will be inserted. -/
replaceRange : α → Lsp.Range
namespace Lean.Elab
open Command Parser
private def mkSelectInsertParamsInstance (declName : Name) : TermElabM Syntax.Command :=
`(command|instance : SelectInsertParamsClass (@$(mkCIdent declName)) :=
⟨fun prop => prop.pos, fun prop => prop.goals,
fun prop => prop.selectedLocations, fun prop => prop.replaceRange⟩)
/-- Handler deriving a `SelectInsertParamsClass` instance. -/
def mkSelectInsertParamsInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
if (← declNames.allM isInductive) then
for declName in declNames do
elabCommand (← liftTermElabM do mkSelectInsertParamsInstance declName)
return true
else
return false
initialize registerDerivingHandler ``SelectInsertParamsClass mkSelectInsertParamsInstanceHandler
end Lean.Elab
|
classfun.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient finalg action gproduct zmodp.
From mathcomp Require Import commutator cyclic center pgroup sylow matrix.
From mathcomp Require Import vector falgebra ssrnum algC algnum archimedean.
(******************************************************************************)
(* This file contains the basic theory of class functions: *)
(* 'CF(G) == the type of class functions on G : {group gT}, i.e., *)
(* which map gT to the type algC of complex algebraics, *)
(* have support in G, and are constant on each conjugacy *)
(* class of G. 'CF(G) implements the falgType interface of *)
(* finite-dimensional F-algebras. *)
(* The identity 1 : 'CF(G) is the indicator function of G, *)
(* and (later) the principal character. *)
(* --> The %CF scope (cfun_scope) is bound to the 'CF(_) types. *)
(* 'CF(G)%VS == the (total) vector space of 'CF(G). *)
(* 'CF(G, A) == the subspace of functions in 'CF(G) with support in A. *)
(* phi x == the image of x : gT under phi : 'CF(G). *)
(* #[phi]%CF == the multiplicative order of phi : 'CF(G). *)
(* cfker phi == the kernel of phi : 'CF(G); note that cfker phi <| G. *)
(* cfaithful phi <=> phi : 'CF(G) is faithful (has a trivial kernel). *)
(* '1_A == the indicator function of A as a function of 'CF(G). *)
(* (Provided A <| G; G is determined by the context.) *)
(* phi^*%CF == the function conjugate to phi : 'CF(G). *)
(* cfAut u phi == the function conjugate to phi by an algC-automorphism u *)
(* phi^u The notation "_ ^u" is only reserved; it is up to *)
(* clients to set Notation "phi ^u" := (cfAut u phi). *)
(* '[phi, psi] == the convolution of phi, psi : 'CF(G) over G, normalised *)
(* '[phi, psi]_G by #|G| so that '[1, 1]_G = 1 (G is usually inferred). *)
(* cfdotr psi phi == '[phi, psi] (self-expanding). *)
(* '[phi], '[phi]_G == the squared norm '[phi, phi] of phi : 'CF(G). *)
(* orthogonal R S <=> each phi in R : seq 'CF(G) is orthogonal to each psi in *)
(* S, i.e., '[phi, psi] = 0. As 'CF(G) coerces to seq, one *)
(* can write orthogonal phi S and orthogonal phi psi. *)
(* pairwise_orthogonal S <=> the class functions in S are pairwise orthogonal *)
(* AND non-zero. *)
(* orthonormal S <=> S is pairwise orthogonal and all class functions in S *)
(* have norm 1. *)
(* isometry tau <-> tau : 'CF(D) -> 'CF(R) is an isometry, mapping *)
(* '[_, _]_D to '[_, _]_R. *)
(* {in CD, isometry tau, to CR} <-> in the domain CD, tau is an isometry *)
(* whose range is contained in CR. *)
(* cfReal phi <=> phi is real, i.e., phi^* == phi. *)
(* cfAut_closed u S <-> S : seq 'CF(G) is closed under conjugation by u. *)
(* cfConjC_closed S <-> S : seq 'CF(G) is closed under complex conjugation. *)
(* conjC_subset S1 S2 <-> S1 : seq 'CF(G) represents a subset of S2 closed *)
(* under complex conjugation. *)
(* := [/\ uniq S1, {subset S1 <= S2} & cfConjC_closed S1]. *)
(* 'Res[H] phi == the restriction of phi : 'CF(G) to a function of 'CF(H) *)
(* 'Res[H, G] phi 'Res[H] phi x = phi x if x \in H (when H \subset G), *)
(* 'Res phi 'Res[H] phi x = 0 if x \notin H. The syntax variants *)
(* allow H and G to be inferred; the default is to specify *)
(* H explicitly, and infer G from the type of phi. *)
(* 'Ind[G] phi == the class function of 'CF(G) induced by phi : 'CF(H), *)
(* 'Ind[G, H] phi when H \subset G. As with 'Res phi, both G and H can *)
(* 'Ind phi be inferred, though usually G isn't. *)
(* cfMorph phi == the class function in 'CF(G) that maps x to phi (f x), *)
(* where phi : 'CF(f @* G), provided G \subset 'dom f. *)
(* cfIsom isoGR phi == the class function in 'CF(R) that maps f x to phi x, *)
(* given isoGR : isom G R f, f : {morphism G >-> rT} and *)
(* phi : 'CF(G). *)
(* (phi %% H)%CF == special case of cfMorph phi, when phi : 'CF(G / H). *)
(* (phi / H)%CF == the class function in 'CF(G / H) that coincides with *)
(* phi : 'CF(G) on cosets of H \subset cfker phi. *)
(* For a group G that is a semidirect product (defG : K ><| H = G), we have *)
(* cfSdprod KxH phi == for phi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* For a group G that is a direct product (with KxH : K \x H = G), we have *)
(* cfDprodl KxH phi == for phi : 'CF(K), the class function of 'CF(G) that *)
(* maps k * h to phi k when k \in K and h \in H. *)
(* cfDprodr KxH psi == for psi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* cfDprod KxH phi psi == for phi : 'CF(K), psi : 'CF(H), the class function *)
(* of 'CF(G) that maps k * h to phi k * psi h (this is *)
(* the product of the two functions above). *)
(* Finally, given defG : \big[dprod/1]_(i | P i) A i = G, with G and A i *)
(* groups and i ranges over a finType, we have *)
(* cfBigdprodi defG phi == for phi : 'CF(A i) s.t. P i, the class function *)
(* of 'CF(G) that maps x to phi x_i, where x_i is the *)
(* (A i)-component of x : G. *)
(* cfBigdprod defG phi == for phi : forall i, 'CF(A i), the class function *)
(* of 'CF(G) that maps x to \prod_(i | P i) phi i x_i, *)
(* where x_i is the (A i)-component of x : G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope cfun_scope.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Delimit Scope cfun_scope with CF.
Reserved Notation "''CF' ( G , A )" (format "''CF' ( G , A )").
Reserved Notation "''CF' ( G )" (format "''CF' ( G )").
Reserved Notation "''1_' G" (at level 8, G at level 2, format "''1_' G").
Reserved Notation "''Res[' H , G ]". (* only parsing *)
Reserved Notation "''Res[' H ]" (format "''Res[' H ]").
Reserved Notation "''Res'". (* only parsing *)
Reserved Notation "''Ind[' G , H ]". (* only parsing *)
Reserved Notation "''Ind[' G ]". (* only "''Ind[' G ]" *)
Reserved Notation "''Ind'". (* only parsing *)
Reserved Notation "'[ phi , psi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "'[ phi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "phi ^u" (format "phi ^u").
Section AlgC.
(* Arithmetic properties of group orders in the characteristic 0 field algC. *)
Variable (gT : finGroupType).
Implicit Types (G : {group gT}) (B : {set gT}).
Lemma neq0CG G : (#|G|)%:R != 0 :> algC. Proof. exact: natrG_neq0. Qed.
Lemma neq0CiG G B : (#|G : B|)%:R != 0 :> algC.
Proof. exact: natr_indexg_neq0. Qed.
Lemma gt0CG G : 0 < #|G|%:R :> algC. Proof. exact: natrG_gt0. Qed.
Lemma gt0CiG G B : 0 < #|G : B|%:R :> algC. Proof. exact: natr_indexg_gt0. Qed.
Lemma algC'G_pchar G : [pchar algC]^'.-group G.
Proof. by apply/pgroupP=> p _; rewrite inE /= pchar_num. Qed.
End AlgC.
#[deprecated(since="mathcomp 2.4.0", note="Use algC'G_pchar instead.")]
Notation algC'G := (algC'G_pchar) (only parsing).
Section Defs.
Variable gT : finGroupType.
Definition is_class_fun (B : {set gT}) (f : {ffun gT -> algC}) :=
[forall x, forall y in B, f (x ^ y) == f x] && (support f \subset B).
Lemma intro_class_fun (G : {group gT}) f :
{in G &, forall x y, f (x ^ y) = f x} ->
(forall x, x \notin G -> f x = 0) ->
is_class_fun G (finfun f).
Proof.
move=> fJ Gf; apply/andP; split; last first.
by apply/supportP=> x notAf; rewrite ffunE Gf.
apply/'forall_eqfun_inP=> x y Gy; rewrite !ffunE.
by have [/fJ-> // | notGx] := boolP (x \in G); rewrite !Gf ?groupJr.
Qed.
Variable B : {set gT}.
Local Notation G := <<B>>.
Record classfun : predArgType :=
Classfun {cfun_val; _ : is_class_fun G cfun_val}.
Implicit Types phi psi xi : classfun.
(* The default expansion lemma cfunE requires key = 0. *)
Fact classfun_key : unit. Proof. by []. Qed.
Definition Cfun := locked_with classfun_key (fun flag : nat => Classfun).
HB.instance Definition _ := [isSub for cfun_val].
HB.instance Definition _ := [Choice of classfun by <:].
Definition cfun_eqType : eqType := classfun.
Definition fun_of_cfun phi := cfun_val phi : gT -> algC.
Coercion fun_of_cfun : classfun >-> Funclass.
Lemma cfunElock k f fP : @Cfun k (finfun f) fP =1 f.
Proof. by rewrite locked_withE; apply: ffunE. Qed.
Lemma cfunE f fP : @Cfun 0 (finfun f) fP =1 f.
Proof. exact: cfunElock. Qed.
Lemma cfunP phi psi : phi =1 psi <-> phi = psi.
Proof. by split=> [/ffunP/val_inj | ->]. Qed.
Lemma cfun0gen phi x : x \notin G -> phi x = 0.
Proof. by case: phi => f fP; case: (andP fP) => _ /supportP; apply. Qed.
Lemma cfun_in_genP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof.
move=> eq_phi; apply/cfunP=> x.
by have [/eq_phi-> // | notAx] := boolP (x \in G); rewrite !cfun0gen.
Qed.
Lemma cfunJgen phi x y : y \in G -> phi (x ^ y) = phi x.
Proof.
case: phi => f fP Gy; apply/eqP.
by case: (andP fP) => /'forall_forall_inP->.
Qed.
Fact cfun_zero_subproof : is_class_fun G (0 : {ffun _}).
Proof. exact: intro_class_fun. Qed.
Definition cfun_zero := Cfun 0 cfun_zero_subproof.
Fact cfun_comp_subproof f phi :
f 0 = 0 -> is_class_fun G [ffun x => f (phi x)].
Proof.
by move=> f0; apply: intro_class_fun => [x y _ /cfunJgen | x /cfun0gen] ->.
Qed.
Definition cfun_comp f f0 phi := Cfun 0 (@cfun_comp_subproof f phi f0).
Definition cfun_opp := cfun_comp (oppr0 _).
Fact cfun_add_subproof phi psi : is_class_fun G [ffun x => phi x + psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite !cfun0gen ?add0r.
Qed.
Definition cfun_add phi psi := Cfun 0 (cfun_add_subproof phi psi).
Fact cfun_indicator_subproof (A : {set gT}) :
is_class_fun G [ffun x => ((x \in G) && (x ^: G \subset A))%:R].
Proof.
apply: intro_class_fun => [x y Gx Gy | x /negbTE/= -> //].
by rewrite groupJr ?classGidl.
Qed.
Definition cfun_indicator A := Cfun 1 (cfun_indicator_subproof A).
Local Notation "''1_' A" := (cfun_indicator A) : ring_scope.
Lemma cfun1Egen x : '1_G x = (x \in G)%:R.
Proof. by rewrite cfunElock andb_idr // => /class_subG->. Qed.
Fact cfun_mul_subproof phi psi : is_class_fun G [ffun x => phi x * psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite cfun0gen ?mul0r.
Qed.
Definition cfun_mul phi psi := Cfun 0 (cfun_mul_subproof phi psi).
Definition cfun_unit := [pred phi : classfun | [forall x in G, phi x != 0]].
Definition cfun_inv phi :=
if phi \in cfun_unit then cfun_comp (invr0 _) phi else phi.
Definition cfun_scale a := cfun_comp (mulr0 a).
Fact cfun_addA : associative cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE addrA. Qed.
Fact cfun_addC : commutative cfun_add.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE addrC. Qed.
Fact cfun_add0 : left_id cfun_zero cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE add0r. Qed.
Fact cfun_addN : left_inverse cfun_zero cfun_opp cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build classfun
cfun_addA cfun_addC cfun_add0 cfun_addN.
Lemma muln_cfunE phi n x : (phi *+ n) x = phi x *+ n.
Proof. by elim: n => [|n IHn]; rewrite ?mulrS !cfunE ?IHn. Qed.
Lemma sum_cfunE I r (P : pred I) (phi : I -> classfun) x :
(\sum_(i <- r | P i) phi i) x = \sum_(i <- r | P i) (phi i) x.
Proof. by elim/big_rec2: _ => [|i _ psi _ <-]; rewrite cfunE. Qed.
Fact cfun_mulA : associative cfun_mul.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_mulC : commutative cfun_mul.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE mulrC. Qed.
Fact cfun_mul1 : left_id '1_G cfun_mul.
Proof.
by move=> phi; apply: cfun_in_genP => x Gx; rewrite !cfunE cfun1Egen Gx mul1r.
Qed.
Fact cfun_mulD : left_distributive cfun_mul cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
Fact cfun_nz1 : '1_G != 0.
Proof.
by apply/eqP=> /cfunP/(_ 1%g)/eqP; rewrite cfun1Egen cfunE group1 oner_eq0.
Qed.
HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build classfun
cfun_mulA cfun_mulC cfun_mul1 cfun_mulD cfun_nz1.
Definition cfun_nzRingType : nzRingType := classfun.
#[deprecated(since="mathcomp 2.4.0",
note="Use cfun_nzRingType instead.")]
Notation cfun_ringType := (cfun_nzRingType) (only parsing).
Lemma expS_cfunE phi n x : (phi ^+ n.+1) x = phi x ^+ n.+1.
Proof. by elim: n => //= n IHn; rewrite !cfunE IHn. Qed.
Fact cfun_mulV : {in cfun_unit, left_inverse 1 cfun_inv *%R}.
Proof.
move=> phi Uphi; rewrite /cfun_inv Uphi; apply/cfun_in_genP=> x Gx.
by rewrite !cfunE cfun1Egen Gx mulVf ?(forall_inP Uphi).
Qed.
Fact cfun_unitP phi psi : psi * phi = 1 -> phi \in cfun_unit.
Proof.
move/cfunP=> phiK; apply/forall_inP=> x Gx; rewrite -unitfE; apply/unitrP.
by exists (psi x); have:= phiK x; rewrite !cfunE cfun1Egen Gx mulrC.
Qed.
Fact cfun_inv0id : {in [predC cfun_unit], cfun_inv =1 id}.
Proof. by rewrite /cfun_inv => phi /negbTE/= ->. Qed.
HB.instance Definition _ :=
GRing.ComNzRing_hasMulInverse.Build classfun cfun_mulV cfun_unitP cfun_inv0id.
Fact cfun_scaleA a b phi :
cfun_scale a (cfun_scale b phi) = cfun_scale (a * b) phi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scale1 : left_id 1 cfun_scale.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE mul1r. Qed.
Fact cfun_scaleDr : right_distributive cfun_scale +%R.
Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunE mulrDr. Qed.
Fact cfun_scaleDl phi : {morph cfun_scale^~ phi : a b / a + b}.
Proof. by move=> a b; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build algC classfun
cfun_scaleA cfun_scale1 cfun_scaleDr cfun_scaleDl.
Fact cfun_scaleAl a phi psi : a *: (phi * psi) = (a *: phi) * psi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scaleAr a phi psi : a *: (phi * psi) = phi * (a *: psi).
Proof. by rewrite !(mulrC phi) cfun_scaleAl. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build algC classfun
cfun_scaleAl.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build algC classfun
cfun_scaleAr.
Section Automorphism.
Variable u : {rmorphism algC -> algC}.
Definition cfAut := cfun_comp (rmorph0 u).
Lemma cfAut_cfun1i A : cfAut '1_A = '1_A.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cfAutZ a phi : cfAut (a *: phi) = u a *: cfAut phi.
Proof. by apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
Lemma cfAut_is_zmod_morphism : zmod_morphism cfAut.
Proof.
by move=> phi psi; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE /= rmorphB.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_zmod_morphism` instead")]
Definition cfAut_is_additive := cfAut_is_zmod_morphism.
Lemma cfAut_is_monoid_morphism : monoid_morphism cfAut.
Proof.
by split=> [|phi psi]; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE rmorphM.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_monoid_morphism` instead")]
Definition cfAut_is_multiplicative :=
(fun g => (g.2,g.1)) cfAut_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build classfun classfun cfAut
cfAut_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build classfun classfun cfAut
cfAut_is_monoid_morphism.
Lemma cfAut_cfun1 : cfAut 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfAut_scalable : scalable_for (u \; *:%R) cfAut.
Proof. by move=> a phi; apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build algC classfun classfun (u \; *:%R) cfAut
cfAut_scalable.
Definition cfAut_closed (S : seq classfun) :=
{in S, forall phi, cfAut phi \in S}.
End Automorphism.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Definition cfReal phi := cfAut conjC phi == phi.
Definition cfConjC_subset (S1 S2 : seq classfun) :=
[/\ uniq S1, {subset S1 <= S2} & cfAut_closed conjC S1].
Fact cfun_vect_iso : Vector.axiom #|classes G| classfun.
Proof.
exists (fun phi => \row_i phi (repr (enum_val i))) => [a phi psi|].
by apply/rowP=> i; rewrite !(mxE, cfunE).
set n := #|_|; pose eK x : 'I_n := enum_rank_in (classes1 _) (x ^: G).
have rV2vP v : is_class_fun G [ffun x => v (eK x) *+ (x \in G)].
apply: intro_class_fun => [x y Gx Gy | x /negbTE/=-> //].
by rewrite groupJr // /eK classGidl.
exists (fun v : 'rV_n => Cfun 0 (rV2vP (v 0))) => [phi | v].
apply/cfun_in_genP=> x Gx; rewrite cfunE Gx mxE enum_rankK_in ?mem_classes //.
by have [y Gy ->] := repr_class <<B>> x; rewrite cfunJgen.
apply/rowP=> i; rewrite mxE cfunE; have /imsetP[x Gx def_i] := enum_valP i.
rewrite def_i; have [y Gy ->] := repr_class <<B>> x.
by rewrite groupJ // /eK classGidl // -def_i enum_valK_in.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build algC classfun cfun_vect_iso.
Definition cfun_vectType : vectType _ := classfun.
Definition cfun_base A : #|classes B ::&: A|.-tuple classfun :=
[tuple of [seq '1_xB | xB in classes B ::&: A]].
Definition classfun_on A := <<cfun_base A>>%VS.
Definition cfdot phi psi := #|B|%:R^-1 * \sum_(x in B) phi x * (psi x)^*.
Definition cfdotr psi phi := cfdot phi psi.
Definition cfnorm phi := cfdot phi phi.
Coercion seq_of_cfun phi := [:: phi].
Definition cforder phi := \big[lcmn/1]_(x in <<B>>) #[phi x]%C.
End Defs.
Bind Scope cfun_scope with classfun.
Arguments classfun {gT} B%_g.
Arguments classfun_on {gT} B%_g A%_g.
Arguments cfun_indicator {gT} B%_g.
Arguments cfAut {gT B%_g} u phi%_CF.
Arguments cfReal {gT B%_g} phi%_CF.
Arguments cfdot {gT B%_g} phi%_CF psi%_CF.
Arguments cfdotr {gT B%_g} psi%_CF phi%_CF /.
Arguments cfnorm {gT B%_g} phi%_CF /.
Notation "''CF' ( G )" := (classfun G) : type_scope.
Notation "''CF' ( G )" := (@fullv _ (cfun_vectType G)) : vspace_scope.
Notation "''1_' A" := (cfun_indicator _ A) : ring_scope.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Notation "1" := (@GRing.one (cfun_nzRingType _)) (only parsing) : cfun_scope.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Notation "phi ^*" := (cfAut conjC phi) : cfun_scope.
Notation cfConjC_closed := (cfAut_closed conjC).
Prenex Implicits cfReal.
(* Workaround for overeager projection reduction. *)
Notation eqcfP := (@eqP (cfun_eqType _) _ _) (only parsing).
Notation "#[ phi ]" := (cforder phi) : cfun_scope.
Notation "''[' u , v ]_ G":= (@cfdot _ G u v) (only parsing) : ring_scope.
Notation "''[' u , v ]" := (cfdot u v) : ring_scope.
Notation "''[' u ]_ G" := '[u, u]_G (only parsing) : ring_scope.
Notation "''[' u ]" := '[u, u] : ring_scope.
Section Predicates.
Variables (gT rT : finGroupType) (D : {set gT}) (R : {set rT}).
Implicit Types (phi psi : 'CF(D)) (S : seq 'CF(D)) (tau : 'CF(D) -> 'CF(R)).
Definition cfker phi := [set x in D | [forall y, phi (x * y)%g == phi y]].
Definition cfaithful phi := cfker phi \subset [1].
Definition ortho_rec S1 S2 :=
all [pred phi | all [pred psi | '[phi, psi] == 0] S2] S1.
Definition orthogonal := ortho_rec.
Arguments orthogonal : simpl never.
Fixpoint pair_ortho_rec S :=
if S is psi :: S' then ortho_rec psi S' && pair_ortho_rec S' else true.
(* We exclude 0 from pairwise orthogonal sets. *)
Definition pairwise_orthogonal S := (0 \notin S) && pair_ortho_rec S.
Definition orthonormal S := all [pred psi | '[psi] == 1] S && pair_ortho_rec S.
Definition isometry tau := forall phi psi, '[tau phi, tau psi] = '[phi, psi].
Definition isometry_from_to mCFD tau mCFR :=
prop_in2 mCFD (inPhantom (isometry tau))
/\ prop_in1 mCFD (inPhantom (forall phi, in_mem (tau phi) mCFR)).
End Predicates.
Arguments orthogonal : simpl never.
Arguments cfker {gT D%_g} phi%_CF.
Arguments cfaithful {gT D%_g} phi%_CF.
Arguments orthogonal {gT D%_g} S1%_CF S2%_CF.
Arguments pairwise_orthogonal {gT D%_g} S%_CF.
Arguments orthonormal {gT D%_g} S%_CF.
Arguments isometry {gT rT D%_g R%_g} tau%_CF.
Notation "{ 'in' CFD , 'isometry' tau , 'to' CFR }" :=
(isometry_from_to (mem CFD) tau (mem CFR))
(format "{ 'in' CFD , 'isometry' tau , 'to' CFR }")
: type_scope.
Section ClassFun.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (A B : {set gT}) (H K : {group gT}) (phi psi xi : 'CF(G)).
Local Notation "''1_' A" := (cfun_indicator G A).
Lemma cfun0 phi x : x \notin G -> phi x = 0.
Proof. by rewrite -{1}(genGid G) => /(cfun0gen phi). Qed.
Lemma support_cfun phi : support phi \subset G.
Proof. by apply/subsetP=> g; apply: contraR => /cfun0->. Qed.
Lemma cfunJ phi x y : y \in G -> phi (x ^ y) = phi x.
Proof. by rewrite -{1}(genGid G) => /(cfunJgen phi)->. Qed.
Lemma cfun_repr phi x : phi (repr (x ^: G)) = phi x.
Proof. by have [y Gy ->] := repr_class G x; apply: cfunJ. Qed.
Lemma cfun_inP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof. by rewrite -{1}genGid => /cfun_in_genP. Qed.
Lemma cfuniE A x : A <| G -> '1_A x = (x \in A)%:R.
Proof.
case/andP=> sAG nAG; rewrite cfunElock genGid.
by rewrite class_sub_norm // andb_idl // => /(subsetP sAG).
Qed.
Lemma support_cfuni A : A <| G -> support '1_A =i A.
Proof. by move=> nsAG x; rewrite !inE cfuniE // pnatr_eq0 -lt0n lt0b. Qed.
Lemma eq_mul_cfuni A phi : A <| G -> {in A, phi * '1_A =1 phi}.
Proof. by move=> nsAG x Ax; rewrite cfunE cfuniE // Ax mulr1. Qed.
Lemma eq_cfuni A : A <| G -> {in A, '1_A =1 (1 : 'CF(G))}.
Proof. by rewrite -['1_A]mul1r; apply: eq_mul_cfuni. Qed.
Lemma cfuniG : '1_G = 1.
Proof. by rewrite -[G in '1_G]genGid. Qed.
Lemma cfun1E g : (1 : 'CF(G)) g = (g \in G)%:R.
Proof. by rewrite -cfuniG cfuniE. Qed.
Lemma cfun11 : (1 : 'CF(G)) 1%g = 1.
Proof. by rewrite cfun1E group1. Qed.
Lemma prod_cfunE I r (P : pred I) (phi : I -> 'CF(G)) x :
x \in G -> (\prod_(i <- r | P i) phi i) x = \prod_(i <- r | P i) (phi i) x.
Proof.
by move=> Gx; elim/big_rec2: _ => [|i _ psi _ <-]; rewrite ?cfunE ?cfun1E ?Gx.
Qed.
Lemma exp_cfunE phi n x : x \in G -> (phi ^+ n) x = phi x ^+ n.
Proof. by rewrite -[n]card_ord -!prodr_const; apply: prod_cfunE. Qed.
Lemma mul_cfuni A B : '1_A * '1_B = '1_(A :&: B) :> 'CF(G).
Proof.
apply/cfunP=> g; rewrite !cfunElock -natrM mulnb subsetI.
by rewrite andbCA !andbA andbb.
Qed.
Lemma cfun_classE x y : '1_(x ^: G) y = ((x \in G) && (y \in x ^: G))%:R.
Proof.
rewrite cfunElock genGid class_sub_norm ?class_norm //; congr (_ : bool)%:R.
by apply: andb_id2r => /imsetP[z Gz ->]; rewrite groupJr.
Qed.
Lemma cfun_on_sum A :
'CF(G, A) = (\sum_(xG in classes G | xG \subset A) <['1_xG]>)%VS.
Proof.
by rewrite ['CF(G, A)]span_def big_image; apply: eq_bigl => xG; rewrite !inE.
Qed.
Lemma cfun_onP A phi :
reflect (forall x, x \notin A -> phi x = 0) (phi \in 'CF(G, A)).
Proof.
apply: (iffP idP) => [/coord_span-> x notAx | Aphi].
set b := cfun_base G A; rewrite sum_cfunE big1 // => i _; rewrite cfunE.
have /mapP[xG]: b`_i \in b by rewrite -tnth_nth mem_tnth.
rewrite mem_enum => /setIdP[/imsetP[y Gy ->] Ay] ->.
by rewrite cfun_classE Gy (contraNF (subsetP Ay x)) ?mulr0.
suffices <-: \sum_(xG in classes G) phi (repr xG) *: '1_xG = phi.
apply: memv_suml => _ /imsetP[x Gx ->]; rewrite rpredZeq cfun_repr.
have [s_xG_A | /subsetPn[_ /imsetP[y Gy ->]]] := boolP (x ^: G \subset A).
by rewrite cfun_on_sum [_ \in _](sumv_sup (x ^: G)) ?mem_classes ?orbT.
by move/Aphi; rewrite cfunJ // => ->; rewrite eqxx.
apply/cfun_inP=> x Gx; rewrite sum_cfunE (bigD1 (x ^: G)) ?mem_classes //=.
rewrite cfunE cfun_repr cfun_classE Gx class_refl mulr1.
rewrite big1 ?addr0 // => _ /andP[/imsetP[y Gy ->]]; apply: contraNeq.
rewrite cfunE cfun_repr cfun_classE Gy mulf_eq0 => /norP[_].
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Arguments cfun_onP {A phi}.
Lemma cfun_on0 A phi x : phi \in 'CF(G, A) -> x \notin A -> phi x = 0.
Proof. by move/cfun_onP; apply. Qed.
Lemma sum_by_classes (R : nzRingType) (F : gT -> R) :
{in G &, forall g h, F (g ^ h) = F g} ->
\sum_(g in G) F g = \sum_(xG in classes G) #|xG|%:R * F (repr xG).
Proof.
move=> FJ; rewrite {1}(partition_big _ _ ((@mem_classes gT)^~ G)) /=.
apply: eq_bigr => _ /imsetP[x Gx ->]; have [y Gy ->] := repr_class G x.
rewrite mulr_natl -sumr_const FJ {y Gy}//; apply/esym/eq_big=> y /=.
apply/idP/andP=> [xGy | [Gy /eqP<-]]; last exact: class_refl.
by rewrite (class_eqP xGy) (subsetP (class_subG Gx (subxx _))).
by case/imsetP=> z Gz ->; rewrite FJ.
Qed.
Lemma cfun_base_free A : free (cfun_base G A).
Proof.
have b_i (i : 'I_#|classes G ::&: A|) : (cfun_base G A)`_i = '1_(enum_val i).
by rewrite /enum_val -!tnth_nth tnth_map.
apply/freeP => s S0 i; move/cfunP/(_ (repr (enum_val i))): S0.
rewrite sum_cfunE (bigD1 i) //= big1 ?addr0 => [|j].
rewrite b_i !cfunE; have /setIdP[/imsetP[x Gx ->] _] := enum_valP i.
by rewrite cfun_repr cfun_classE Gx class_refl mulr1.
apply: contraNeq; rewrite b_i !cfunE mulf_eq0 => /norP[_].
rewrite -(inj_eq enum_val_inj).
have /setIdP[/imsetP[x _ ->] _] := enum_valP i; rewrite cfun_repr.
have /setIdP[/imsetP[y Gy ->] _] := enum_valP j; rewrite cfun_classE Gy.
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Lemma dim_cfun : \dim 'CF(G) = #|classes G|.
Proof. by rewrite dimvf /dim /= genGid. Qed.
Lemma dim_cfun_on A : \dim 'CF(G, A) = #|classes G ::&: A|.
Proof. by rewrite (eqnP (cfun_base_free A)) size_tuple. Qed.
Lemma dim_cfun_on_abelian A : abelian G -> A \subset G -> \dim 'CF(G, A) = #|A|.
Proof.
move/abelian_classP=> cGG sAG; rewrite -(card_imset _ set1_inj) dim_cfun_on.
apply/eq_card=> xG; rewrite !inE.
apply/andP/imsetP=> [[/imsetP[x Gx ->] Ax] | [x Ax ->]] {xG}.
by rewrite cGG ?sub1set // in Ax *; exists x.
by rewrite -{1}(cGG x) ?mem_classes ?(subsetP sAG) ?sub1set.
Qed.
Lemma cfuni_on A : '1_A \in 'CF(G, A).
Proof.
apply/cfun_onP=> x notAx; rewrite cfunElock genGid.
by case: andP => // [[_ s_xG_A]]; rewrite (subsetP s_xG_A) ?class_refl in notAx.
Qed.
Lemma mul_cfuni_on A phi : phi * '1_A \in 'CF(G, A).
Proof.
by apply/cfun_onP=> x /(cfun_onP (cfuni_on A)) Ax0; rewrite cfunE Ax0 mulr0.
Qed.
Lemma cfun_onE phi A : (phi \in 'CF(G, A)) = (support phi \subset A).
Proof. exact: (sameP cfun_onP supportP). Qed.
Lemma cfun_onT phi : phi \in 'CF(G, [set: gT]).
Proof. by rewrite cfun_onE. Qed.
Lemma cfun_onD1 phi A :
(phi \in 'CF(G, A^#)) = (phi \in 'CF(G, A)) && (phi 1%g == 0).
Proof.
by rewrite !cfun_onE -!(eq_subset (in_set (support _))) subsetD1 !inE negbK.
Qed.
Lemma cfun_onG phi : phi \in 'CF(G, G).
Proof. by rewrite cfun_onE support_cfun. Qed.
Lemma cfunD1E phi : (phi \in 'CF(G, G^#)) = (phi 1%g == 0).
Proof. by rewrite cfun_onD1 cfun_onG. Qed.
Lemma cfunGid : 'CF(G, G) = 'CF(G)%VS.
Proof. by apply/vspaceP=> phi; rewrite cfun_onG memvf. Qed.
Lemma cfun_onS A B phi : B \subset A -> phi \in 'CF(G, B) -> phi \in 'CF(G, A).
Proof. by rewrite !cfun_onE => sBA /subset_trans->. Qed.
Lemma cfun_complement A :
A <| G -> ('CF(G, A) + 'CF(G, G :\: A)%SET = 'CF(G))%VS.
Proof.
case/andP=> sAG nAG; rewrite -cfunGid [rhs in _ = rhs]cfun_on_sum.
rewrite (bigID (fun B => B \subset A)) /=.
congr (_ + _)%VS; rewrite cfun_on_sum; apply: eq_bigl => /= xG.
rewrite andbAC; apply/esym/andb_idr=> /andP[/imsetP[x Gx ->] _].
by rewrite class_subG.
rewrite -andbA; apply: andb_id2l => /imsetP[x Gx ->].
by rewrite !class_sub_norm ?normsD ?normG // inE andbC.
Qed.
Lemma cfConjCE phi x : ( phi^* )%CF x = (phi x)^*.
Proof. by rewrite cfunE. Qed.
Lemma cfConjCK : involutive (fun phi => phi^* )%CF.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= conjCK. Qed.
Lemma cfConjC_cfun1 : ( 1^* )%CF = 1 :> 'CF(G).
Proof. exact: rmorph1. Qed.
(* Class function kernel and faithful class functions *)
Fact cfker_is_group phi : group_set (cfker phi).
Proof.
apply/group_setP; split=> [|x y]; rewrite !inE ?group1.
by apply/forallP=> y; rewrite mul1g.
case/andP=> Gx /forallP-Kx /andP[Gy /forallP-Ky]; rewrite groupM //.
by apply/forallP=> z; rewrite -mulgA (eqP (Kx _)) Ky.
Qed.
Canonical cfker_group phi := Group (cfker_is_group phi).
Lemma cfker_sub phi : cfker phi \subset G.
Proof. by rewrite /cfker setIdE subsetIl. Qed.
Lemma cfker_norm phi : G \subset 'N(cfker phi).
Proof.
apply/subsetP=> z Gz; have phiJz := cfunJ phi _ (groupVr Gz).
rewrite inE; apply/subsetP=> _ /imsetP[x /setIdP[Gx /forallP-Kx] ->].
rewrite inE groupJ //; apply/forallP=> y.
by rewrite -(phiJz y) -phiJz conjMg conjgK Kx.
Qed.
Lemma cfker_normal phi : cfker phi <| G.
Proof. by rewrite /normal cfker_sub cfker_norm. Qed.
Lemma cfkerMl phi x y : x \in cfker phi -> phi (x * y)%g = phi y.
Proof. by case/setIdP=> _ /eqfunP->. Qed.
Lemma cfkerMr phi x y : x \in cfker phi -> phi (y * x)%g = phi y.
Proof.
by move=> Kx; rewrite conjgC cfkerMl ?cfunJ ?(subsetP (cfker_sub phi)).
Qed.
Lemma cfker1 phi x : x \in cfker phi -> phi x = phi 1%g.
Proof. by move=> Kx; rewrite -[x]mulg1 cfkerMl. Qed.
Lemma cfker_cfun0 : @cfker _ G 0 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfunE.
Qed.
Lemma cfker_add phi psi : cfker phi :&: cfker psi \subset cfker (phi + psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_sum I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\sum_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun0.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_add _ _).
Qed.
Lemma cfker_scale a phi : cfker phi \subset cfker (a *: phi).
Proof.
apply/subsetP=> x Kphi_x; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE cfkerMl.
Qed.
Lemma cfker_scale_nz a phi : a != 0 -> cfker (a *: phi) = cfker phi.
Proof.
move=> nz_a; apply/eqP.
by rewrite eqEsubset -{2}(scalerK nz_a phi) !cfker_scale.
Qed.
Lemma cfker_opp phi : cfker (- phi) = cfker phi.
Proof. by rewrite -scaleN1r cfker_scale_nz // oppr_eq0 oner_eq0. Qed.
Lemma cfker_cfun1 : @cfker _ G 1 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfun1E groupMl.
Qed.
Lemma cfker_mul phi psi : cfker phi :&: cfker psi \subset cfker (phi * psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_prod I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\prod_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun1.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_mul _ _).
Qed.
Lemma cfaithfulE phi : cfaithful phi = (cfker phi \subset [1]).
Proof. by []. Qed.
End ClassFun.
Arguments classfun_on {gT} B%_g A%_g.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Arguments cfun_onP {gT G A phi}.
Arguments cfConjCK {gT G} phi : rename.
#[global] Hint Resolve cfun_onT : core.
Section DotProduct.
Variable (gT : finGroupType) (G : {group gT}).
Implicit Types (M : {group gT}) (phi psi xi : 'CF(G)) (R S : seq 'CF(G)).
Lemma cfdotE phi psi :
'[phi, psi] = #|G|%:R^-1 * \sum_(x in G) phi x * (psi x)^*.
Proof. by []. Qed.
Lemma cfdotElr A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A :&: B) phi x * (psi x)^*.
Proof.
move=> Aphi Bpsi; rewrite (big_setID G)/= cfdotE (big_setID (A :&: B))/= setIC.
congr (_ * (_ + _)); rewrite !big1 // => x /setDP[_].
by move/cfun0->; rewrite mul0r.
rewrite inE; case/nandP=> notABx; first by rewrite (cfun_on0 Aphi) ?mul0r.
by rewrite (cfun_on0 Bpsi) // rmorph0 mulr0.
Qed.
Lemma cfdotEl A phi psi :
phi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Aphi; rewrite (cfdotElr Aphi (cfun_onT psi)) setIT. Qed.
Lemma cfdotEr A phi psi :
psi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Apsi; rewrite (cfdotElr (cfun_onT phi) Apsi) setTI. Qed.
Lemma cfdot_complement A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, G :\: A) -> '[phi, psi] = 0.
Proof.
move=> Aphi A'psi; rewrite (cfdotElr Aphi A'psi).
by rewrite setDE setICA setICr setI0 big_set0 mulr0.
Qed.
Lemma cfnormE A phi :
phi \in 'CF(G, A) -> '[phi] = #|G|%:R^-1 * (\sum_(x in A) `|phi x| ^+ 2).
Proof. by move/cfdotEl->; rewrite (eq_bigr _ (fun _ _ => normCK _)). Qed.
Lemma eq_cfdotl A phi1 phi2 psi :
psi \in 'CF(G, A) -> {in A, phi1 =1 phi2} -> '[phi1, psi] = '[phi2, psi].
Proof.
move/cfdotEr=> eq_dot eq_phi; rewrite !eq_dot; congr (_ * _).
by apply: eq_bigr => x Ax; rewrite eq_phi.
Qed.
Lemma cfdot_cfuni A B :
A <| G -> B <| G -> '['1_A, '1_B]_G = #|A :&: B|%:R / #|G|%:R.
Proof.
move=> nsAG nsBG; rewrite (cfdotElr (cfuni_on G A) (cfuni_on G B)) mulrC.
congr (_ / _); rewrite -sumr_const; apply: eq_bigr => x /setIP[Ax Bx].
by rewrite !cfuniE // Ax Bx mul1r rmorph1.
Qed.
Lemma cfnorm1 : '[1]_G = 1.
Proof. by rewrite cfdot_cfuni ?genGid // setIid divff ?neq0CG. Qed.
Lemma cfdotrE psi phi : cfdotr psi phi = '[phi, psi]. Proof. by []. Qed.
Lemma cfdotr_is_linear xi : linear (cfdotr xi : 'CF(G) -> algC^o).
Proof.
move=> a phi psi; rewrite scalerAr -mulrDr; congr (_ * _).
rewrite linear_sum -big_split; apply: eq_bigr => x _ /=.
by rewrite !cfunE mulrDl -mulrA.
Qed.
HB.instance Definition _ xi := GRing.isSemilinear.Build algC _ _ _ (cfdotr xi)
(GRing.semilinear_linear (cfdotr_is_linear xi)).
Lemma cfdot0l xi : '[0, xi] = 0.
Proof. by rewrite -cfdotrE linear0. Qed.
Lemma cfdotNl xi phi : '[- phi, xi] = - '[phi, xi].
Proof. by rewrite -!cfdotrE linearN. Qed.
Lemma cfdotDl xi phi psi : '[phi + psi, xi] = '[phi, xi] + '[psi, xi].
Proof. by rewrite -!cfdotrE linearD. Qed.
Lemma cfdotBl xi phi psi : '[phi - psi, xi] = '[phi, xi] - '[psi, xi].
Proof. by rewrite -!cfdotrE linearB. Qed.
Lemma cfdotMnl xi phi n : '[phi *+ n, xi] = '[phi, xi] *+ n.
Proof. by rewrite -!cfdotrE linearMn. Qed.
Lemma cfdot_suml xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[\sum_(i <- r | P i) phi i, xi] = \sum_(i <- r | P i) '[phi i, xi].
Proof. by rewrite -!cfdotrE linear_sum. Qed.
Lemma cfdotZl xi a phi : '[a *: phi, xi] = a * '[phi, xi].
Proof. by rewrite -!cfdotrE linearZ. Qed.
Lemma cfdotC phi psi : '[phi, psi] = ('[psi, phi])^*.
Proof.
rewrite /cfdot rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr=> x _; rewrite rmorphM /= conjCK mulrC.
Qed.
Lemma eq_cfdotr A phi psi1 psi2 :
phi \in 'CF(G, A) -> {in A, psi1 =1 psi2} -> '[phi, psi1] = '[phi, psi2].
Proof. by move=> Aphi /eq_cfdotl eq_dot; rewrite cfdotC eq_dot // -cfdotC. Qed.
Lemma cfdotBr xi phi psi : '[xi, phi - psi] = '[xi, phi] - '[xi, psi].
Proof. by rewrite !(cfdotC xi) -rmorphB cfdotBl. Qed.
HB.instance Definition _ xi :=
GRing.isZmodMorphism.Build _ _ (cfdot xi) (cfdotBr xi).
Lemma cfdot0r xi : '[xi, 0] = 0. Proof. exact: raddf0. Qed.
Lemma cfdotNr xi phi : '[xi, - phi] = - '[xi, phi].
Proof. exact: raddfN. Qed.
Lemma cfdotDr xi phi psi : '[xi, phi + psi] = '[xi, phi] + '[xi, psi].
Proof. exact: raddfD. Qed.
Lemma cfdotMnr xi phi n : '[xi, phi *+ n] = '[xi, phi] *+ n.
Proof. exact: raddfMn. Qed.
Lemma cfdot_sumr xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[xi, \sum_(i <- r | P i) phi i] = \sum_(i <- r | P i) '[xi, phi i].
Proof. exact: raddf_sum. Qed.
Lemma cfdotZr a xi phi : '[xi, a *: phi] = a^* * '[xi, phi].
Proof. by rewrite !(cfdotC xi) cfdotZl rmorphM. Qed.
Lemma cfdot_cfAut (u : {rmorphism algC -> algC}) phi psi :
{in image psi G, {morph u : x / x^*}} ->
'[cfAut u phi, cfAut u psi] = u '[phi, psi].
Proof.
move=> uC; rewrite rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr => x Gx; rewrite !cfunE rmorphM /= uC ?map_f ?mem_enum.
Qed.
Lemma cfdot_conjC phi psi : '[phi^*, psi^*] = '[phi, psi]^*.
Proof. by rewrite cfdot_cfAut. Qed.
Lemma cfdot_conjCl phi psi : '[phi^*, psi] = '[phi, psi^*]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfdot_conjCr phi psi : '[phi, psi^*] = '[phi^*, psi]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfnorm_ge0 phi : 0 <= '[phi].
Proof.
by rewrite mulr_ge0 ?invr_ge0 ?ler0n ?sumr_ge0 // => x _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_eq0 phi : ('[phi] == 0) = (phi == 0).
Proof.
apply/idP/eqP=> [|->]; last by rewrite cfdot0r.
rewrite mulf_eq0 invr_eq0 (negbTE (neq0CG G)) /= => /eqP/psumr_eq0P phi0.
apply/cfun_inP=> x Gx; apply/eqP; rewrite cfunE -mul_conjC_eq0.
by rewrite phi0 // => y _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_gt0 phi : ('[phi] > 0) = (phi != 0).
Proof. by rewrite lt_def cfnorm_ge0 cfnorm_eq0 andbT. Qed.
Lemma sqrt_cfnorm_ge0 phi : 0 <= sqrtC '[phi].
Proof. by rewrite sqrtC_ge0 cfnorm_ge0. Qed.
Lemma sqrt_cfnorm_eq0 phi : (sqrtC '[phi] == 0) = (phi == 0).
Proof. by rewrite sqrtC_eq0 cfnorm_eq0. Qed.
Lemma sqrt_cfnorm_gt0 phi : (sqrtC '[phi] > 0) = (phi != 0).
Proof. by rewrite sqrtC_gt0 cfnorm_gt0. Qed.
Lemma cfnormZ a phi : '[a *: phi]= `|a| ^+ 2 * '[phi]_G.
Proof. by rewrite cfdotZl cfdotZr mulrA normCK. Qed.
Lemma cfnormN phi : '[- phi] = '[phi].
Proof. by rewrite cfdotNl raddfN opprK. Qed.
Lemma cfnorm_sign n phi : '[(-1) ^+ n *: phi] = '[phi].
Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?cfnormN. Qed.
Lemma cfnormD phi psi :
let d := '[phi, psi] in '[phi + psi] = '[phi] + '[psi] + ( d + d^* ).
Proof. by rewrite /= addrAC -cfdotC cfdotDl !cfdotDr !addrA. Qed.
Lemma cfnormB phi psi :
let d := '[phi, psi] in '[phi - psi] = '[phi] + '[psi] - ( d + d^* ).
Proof. by rewrite /= cfnormD cfnormN cfdotNr rmorphN -opprD. Qed.
Lemma cfnormDd phi psi : '[phi, psi] = 0 -> '[phi + psi] = '[phi] + '[psi].
Proof. by move=> ophipsi; rewrite cfnormD ophipsi rmorph0 !addr0. Qed.
Lemma cfnormBd phi psi : '[phi, psi] = 0 -> '[phi - psi] = '[phi] + '[psi].
Proof.
by move=> ophipsi; rewrite cfnormDd ?cfnormN // cfdotNr ophipsi oppr0.
Qed.
Lemma cfnorm_conjC phi : '[phi^*] = '[phi].
Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed.
Lemma cfCauchySchwarz phi psi :
`|'[phi, psi]| ^+ 2 <= '[phi] * '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_psi] /= := eqVneq psi 0.
by apply/leifP; rewrite !cfdot0r normCK mul0r mulr0.
without loss ophi: phi / '[phi, psi] = 0.
move=> IHo; pose a := '[phi, psi] / '[psi]; pose phi1 := phi - a *: psi.
have ophi: '[phi1, psi] = 0.
by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr.
rewrite (canRL (subrK _) (erefl phi1)) rpredDr ?rpredZ ?memv_line //.
rewrite cfdotDl ophi add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)).
rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ophi mulr0.
by have:= IHo _ ophi; rewrite mulrDl -leifBLR subrr ophi normCK mul0r.
rewrite ophi normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0.
rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_psi) /=.
apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ophi mulr0.
by rewrite cfnorm_eq0 => /eqP->; apply: rpred0.
Qed.
Lemma cfCauchySchwarz_sqrt phi psi :
`|'[phi, psi]| <= sqrtC '[phi] * sqrtC '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?qualifE/= ?cfnorm_ge0 //.
rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM ?qualifE/= ?cfnorm_ge0 //;
[ exact: cfCauchySchwarz | exact: O.. ].
Qed.
Lemma cf_triangle_leif phi psi :
sqrtC '[phi + psi] <= sqrtC '[phi] + sqrtC '[psi]
?= iff ~~ free (phi :: psi) && (0 <= coord [tuple psi] 0 phi).
Proof.
rewrite -(mono_in_leif ler_sqr) ?rpredD ?qualifE/= ?sqrtC_ge0 ?cfnorm_ge0 //;
[| exact: O.. ].
rewrite andbC sqrrD !sqrtCK addrAC cfnormD (mono_leif (lerD2l _)).
rewrite -mulr_natr -[_ + _](divfK (negbT (eqC_nat 2 0))) -/('Re _).
rewrite (mono_leif (ler_pM2r _)) ?ltr0n //.
have:= leif_trans (leif_Re_Creal '[phi, psi]) (cfCauchySchwarz_sqrt phi psi).
congr (_ <= _ ?= iff _); first by rewrite ReE.
apply: andb_id2r; rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC /=.
have [-> | nz_psi] := eqVneq psi 0; first by rewrite cfdot0r coord0.
case/vlineP=> [x ->]; rewrite cfdotZl linearZ pmulr_lge0 ?cfnorm_gt0 //=.
by rewrite (coord_free 0) ?seq1_free // eqxx mulr1.
Qed.
Lemma orthogonal_cons phi R S :
orthogonal (phi :: R) S = orthogonal phi S && orthogonal R S.
Proof. by rewrite /orthogonal /= andbT. Qed.
Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal phi psi).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthogonalP S R :
reflect {in S & R, forall phi psi, '[phi, psi] = 0} (orthogonal S R).
Proof.
apply: (iffP allP) => oSR phi => [psi /oSR/allP opS /opS/eqP // | /oSR opS].
by apply/allP=> psi /= /opS->.
Qed.
Lemma orthoPl phi S :
reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal phi S).
Proof.
by rewrite [orthogonal _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP.
Qed.
Arguments orthoPl {phi S}.
Lemma orthogonal_sym : symmetric (@orthogonal _ G).
Proof.
apply: symmetric_from_pre => R S /orthogonalP oRS.
by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite cfdotC oRS ?rmorph0.
Qed.
Lemma orthoPr S psi :
reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal S psi).
Proof.
rewrite orthogonal_sym.
by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite cfdotC oSpsi ?conjC0.
Qed.
Lemma eq_orthogonal R1 R2 S1 S2 :
R1 =i R2 -> S1 =i S2 -> orthogonal R1 S1 = orthogonal R2 S2.
Proof.
move=> eqR eqS; rewrite [orthogonal _ _](eq_all_r eqR).
by apply: eq_all => psi /=; apply: eq_all_r.
Qed.
Lemma orthogonal_catl R1 R2 S :
orthogonal (R1 ++ R2) S = orthogonal R1 S && orthogonal R2 S.
Proof. exact: all_cat. Qed.
Lemma orthogonal_catr R S1 S2 :
orthogonal R (S1 ++ S2) = orthogonal R S1 && orthogonal R S2.
Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed.
Lemma span_orthogonal S1 S2 phi1 phi2 :
orthogonal S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS ->
'[phi1, phi2] = 0.
Proof.
move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->.
rewrite cfdot_suml big1 // => i _; rewrite cfdot_sumr big1 // => j _.
by rewrite cfdotZl cfdotZr oS12 ?mem_nth ?mulr0.
Qed.
Lemma orthogonal_split S beta :
{X : 'CF(G) & X \in <<S>>%VS &
{Y | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal Y S]}}.
Proof.
suffices [X S_X [Y -> oYS]]:
{X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal Y S}}.
- exists X => //; exists Y.
by rewrite cfdotC (span_orthogonal oYS) ?memv_span1 ?conjC0.
elim: S beta => [|phi S IHS] beta.
by exists 0; last exists beta; rewrite ?mem0v ?add0r.
have [[U S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta).
pose Z := '[Y, V] / '[V] *: V; exists (X + Z).
rewrite /Z -{4}(addKr U V) scalerDr scalerN addrA addrC span_cons.
by rewrite memv_add ?memvB ?memvZ ?memv_line.
exists (Y - Z); first by rewrite addrCA !addrA addrK addrC.
apply/orthoPl=> psi /[!inE] /predU1P[-> | Spsi]; last first.
by rewrite cfdotBl cfdotZl (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS).
rewrite cfdotBl !cfdotDr (span_orthogonal oYS) // ?memv_span ?mem_head //.
rewrite !cfdotZl (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //.
have [-> | nzV] := eqVneq V 0; first by rewrite cfdot0r !mul0r subrr.
by rewrite divfK ?cfnorm_eq0 ?subrr.
Qed.
Lemma map_orthogonal M (nu : 'CF(G) -> 'CF(M)) S R (A : {pred 'CF(G)}) :
{in A &, isometry nu} -> {subset S <= A} -> {subset R <= A} ->
orthogonal (map nu S) (map nu R) = orthogonal S R.
Proof.
move=> Inu sSA sRA; rewrite [orthogonal _ _]all_map.
apply: eq_in_all => phi Sphi; rewrite /= all_map.
by apply: eq_in_all => psi Rpsi; rewrite /= Inu ?(sSA phi) ?(sRA psi).
Qed.
Lemma orthogonal_oppr S R : orthogonal S (map -%R R) = orthogonal S R.
Proof.
wlog suffices IH: S R / orthogonal S R -> orthogonal S (map -%R R).
by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK.
move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->].
by rewrite cfdotNr oSR ?oppr0.
Qed.
Lemma orthogonal_oppl S R : orthogonal (map -%R S) R = orthogonal S R.
Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed.
Lemma pairwise_orthogonalP S :
reflect (uniq (0 :: S)
/\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0})
(pairwise_orthogonal S).
Proof.
rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case.
elim: S notS0 => [|phi S IH] /=; first by left.
rewrite inE eq_sym andbT => /norP[nz_phi /IH{}IH].
have [opS | not_opS] := allP; last first.
right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=.
by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp).
rewrite (contra (opS _)) /= ?cfnorm_eq0 //.
apply: (iffP IH) => [] [uniqS oSS]; last first.
by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead.
split=> // psi xi /[!inE] /predU1P[-> // | Spsi].
by case/predU1P=> [-> | /opS] /eqP.
case/predU1P=> [-> _ | Sxi /oSS-> //].
by apply/eqP; rewrite cfdotC conjC_eq0 [_ == 0]opS.
Qed.
Lemma pairwise_orthogonal_cat R S :
pairwise_orthogonal (R ++ S) =
[&& pairwise_orthogonal R, pairwise_orthogonal S & orthogonal R S].
Proof.
rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr.
elim: R => [|phi R /= ->]; rewrite ?andbT // orthogonal_cons all_cat -!andbA /=.
by do !bool_congr.
Qed.
Lemma eq_pairwise_orthogonal R S :
perm_eq R S -> pairwise_orthogonal R = pairwise_orthogonal S.
Proof.
apply: catCA_perm_subst R S => R S S'.
rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA.
by do !bool_congr.
Qed.
Lemma sub_pairwise_orthogonal S1 S2 :
{subset S1 <= S2} -> uniq S1 ->
pairwise_orthogonal S2 -> pairwise_orthogonal S1.
Proof.
move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2].
apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //.
by split=> //; apply: sub_in2 oS2.
Qed.
Lemma orthogonal_free S : pairwise_orthogonal S -> free S.
Proof.
case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS].
rewrite -(in_tupleE S); apply/freeP => a aS0 i.
have S_i: S`_i \in S by apply: mem_nth.
have /eqP: '[S`_i, 0]_G = 0 := cfdot0r _.
rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first.
by rewrite cfdotZr oSS ?mulr0 ?mem_nth // eq_sym nth_uniq.
rewrite addr0 cfdotZr mulf_eq0 conjC_eq0 cfnorm_eq0.
by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0.
Qed.
Lemma filter_pairwise_orthogonal S p :
pairwise_orthogonal S -> pairwise_orthogonal (filter p S).
Proof.
move=> orthoS; apply: sub_pairwise_orthogonal (orthoS).
exact: mem_subseq (filter_subseq p S).
exact/filter_uniq/free_uniq/orthogonal_free.
Qed.
Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S.
Proof.
by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= cfdot0r eq_sym oner_eq0.
Qed.
Lemma orthonormalE S :
orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S.
Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed.
Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S.
Proof. by rewrite orthonormalE => /andP[_]. Qed.
Lemma orthonormal_cat R S :
orthonormal (R ++ S) = [&& orthonormal R, orthonormal S & orthogonal R S].
Proof.
rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA.
by do !bool_congr.
Qed.
Lemma eq_orthonormal R S : perm_eq R S -> orthonormal R = orthonormal S.
Proof.
move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)).
by rewrite (eq_pairwise_orthogonal eqRS).
Qed.
Lemma orthonormal_free S : orthonormal S -> free S.
Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed.
Lemma orthonormalP S :
reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi]_G = (phi == psi)%:R})
(orthonormal S).
Proof.
rewrite orthonormalE; have [/= normS | not_normS] := allP; last first.
by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx.
apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS].
split=> // [|phi psi]; first by case/andP: uniqS.
by have [-> _ /normS/eqP | /oSS] := eqVneq.
split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->.
by rewrite /= (contra (normS _)) // cfdot0r eq_sym oner_eq0.
Qed.
Lemma sub_orthonormal S1 S2 :
{subset S1 <= S2} -> uniq S1 -> orthonormal S2 -> orthonormal S1.
Proof.
move=> sS12 uniqS1 /orthonormalP[_ oS1].
by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _.
Qed.
Lemma orthonormal2P phi psi :
reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1]
(orthonormal [:: phi; psi]).
Proof.
rewrite /orthonormal /= !andbT andbC.
by apply: (iffP and3P) => [] []; do 3!move/eqP->.
Qed.
Lemma conjC_pair_orthogonal S chi :
cfConjC_closed S -> ~~ has cfReal S -> pairwise_orthogonal S -> chi \in S ->
pairwise_orthogonal (chi :: chi^*%CF).
Proof.
move=> ccS /hasPn nrS oSS Schi; apply: sub_pairwise_orthogonal oSS.
by apply/allP; rewrite /= Schi ccS.
by rewrite /= inE eq_sym nrS.
Qed.
Lemma cfdot_real_conjC phi psi : cfReal phi -> '[phi, psi^*]_G = '[phi, psi]^*.
Proof. by rewrite -cfdot_conjC => /eqcfP->. Qed.
Lemma extend_cfConjC_subset S X phi :
cfConjC_closed S -> ~~ has cfReal S -> phi \in S -> phi \notin X ->
cfConjC_subset X S -> cfConjC_subset [:: phi, phi^* & X]%CF S.
Proof.
move=> ccS nrS Sphi X'phi [uniqX /allP-sXS ccX].
split; last 1 [by apply/allP; rewrite /= Sphi ccS | apply/allP]; rewrite /= inE.
by rewrite negb_or X'phi eq_sym (hasPn nrS) // (contra (ccX _)) ?cfConjCK.
by rewrite cfConjCK !mem_head orbT; apply/allP=> xi Xxi; rewrite !inE ccX ?orbT.
Qed.
(* Note: other isometry lemmas, and the dot product lemmas for orthogonal *)
(* and orthonormal sequences are in vcharacter, because we need the 'Z[S] *)
(* notation for the isometry domains. Alternatively, this could be moved to *)
(* cfun. *)
End DotProduct.
Arguments orthoP {gT G phi psi}.
Arguments orthoPl {gT G phi S}.
Arguments orthoPr {gT G S psi}.
Arguments orthogonalP {gT G S R}.
Arguments pairwise_orthogonalP {gT G S}.
Arguments orthonormalP {gT G S}.
Section CfunOrder.
Variables (gT : finGroupType) (G : {group gT}) (phi : 'CF(G)).
Lemma dvdn_cforderP n :
reflect {in G, forall x, phi x ^+ n = 1} (#[phi]%CF %| n)%N.
Proof.
apply: (iffP (dvdn_biglcmP _ _ _)); rewrite genGid => phiG1 x Gx.
by apply/eqP; rewrite -dvdn_orderC phiG1.
by rewrite dvdn_orderC phiG1.
Qed.
Lemma dvdn_cforder n : (#[phi]%CF %| n) = (phi ^+ n == 1).
Proof.
apply/dvdn_cforderP/eqP=> phi_n_1 => [|x Gx].
by apply/cfun_inP=> x Gx; rewrite exp_cfunE // cfun1E Gx phi_n_1.
by rewrite -exp_cfunE // phi_n_1 // cfun1E Gx.
Qed.
Lemma exp_cforder : phi ^+ #[phi]%CF = 1.
Proof. by apply/eqP; rewrite -dvdn_cforder. Qed.
End CfunOrder.
Arguments dvdn_cforderP {gT G phi n}.
Section MorphOrder.
Variables (aT rT : finGroupType) (G : {group aT}) (R : {group rT}).
Variable f : {rmorphism 'CF(G) -> 'CF(R)}.
Lemma cforder_rmorph phi : #[f phi]%CF %| #[phi]%CF.
Proof. by rewrite dvdn_cforder -rmorphXn exp_cforder rmorph1. Qed.
Lemma cforder_inj_rmorph phi : injective f -> #[f phi]%CF = #[phi]%CF.
Proof.
move=> inj_f; apply/eqP; rewrite eqn_dvd cforder_rmorph dvdn_cforder /=.
by rewrite -(rmorph_eq1 _ inj_f) rmorphXn exp_cforder.
Qed.
End MorphOrder.
Section BuildIsometries.
Variable (gT : finGroupType) (L G : {group gT}).
Implicit Types (phi psi xi : 'CF(L)) (R S : seq 'CF(L)).
Implicit Types (U : {pred 'CF(L)}) (W : {pred 'CF(G)}).
Lemma sub_iso_to U1 U2 W1 W2 tau :
{subset U2 <= U1} -> {subset W1 <= W2} ->
{in U1, isometry tau, to W1} -> {in U2, isometry tau, to W2}.
Proof.
by move=> sU sW [Itau Wtau]; split=> [|u /sU/Wtau/sW //]; apply: sub_in2 Itau.
Qed.
Lemma isometry_of_free S f :
free S -> {in S &, isometry f} ->
{tau : {linear 'CF(L) -> 'CF(G)} |
{in S, tau =1 f} & {in <<S>>%VS &, isometry tau}}.
Proof.
move=> freeS If; have defS := free_span freeS.
have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S).
have{} Dtau: {in S, tau =1 f}.
by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau.
exists tau => // _ _ /defS[a -> _] /defS[b -> _].
rewrite !{1}linear_sum !{1}cfdot_suml; apply/eq_big_seq=> xi1 Sxi1.
rewrite !{1}cfdot_sumr; apply/eq_big_seq=> xi2 Sxi2.
by rewrite !linearZ /= !Dtau // !cfdotZl !cfdotZr If.
Qed.
Lemma isometry_of_cfnorm S tauS :
pairwise_orthogonal S -> pairwise_orthogonal tauS ->
map cfnorm tauS = map cfnorm S ->
{tau : {linear 'CF(L) -> 'CF(G)} | map tau S = tauS
& {in <<S>>%VS &, isometry tau}}.
Proof.
move=> oS oT eq_nST; have freeS := orthogonal_free oS.
have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map.
have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)).
exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=.
apply: eq_bigr => i _ /=; rewrite linearZ !cfdotZr !cfdot_suml; congr (_ * _).
apply: eq_bigr => j _ /=; rewrite linearZ !cfdotZl; congr (_ * _).
rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i.
by rewrite -!['[_]](nth_map 0 0 cfnorm) ?eq_sz // eq_nST.
have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS.
have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT.
by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz.
Qed.
Lemma isometry_raddf_inj U (tau : {additive 'CF(L) -> 'CF(G)}) :
{in U &, isometry tau} -> {in U &, forall u v, u - v \in U} ->
{in U &, injective tau}.
Proof.
move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB.
by rewrite -cfnorm_eq0 Itau ?linU // cfnorm_eq0 subr_eq0 => /eqP.
Qed.
Lemma opp_isometry : @isometry _ _ G G -%R.
Proof. by move=> x y; rewrite cfdotNl cfdotNr opprK. Qed.
End BuildIsometries.
Section Restrict.
Variables (gT : finGroupType) (A B : {set gT}).
Local Notation H := <<A>>.
Local Notation G := <<B>>.
Fact cfRes_subproof (phi : 'CF(B)) :
is_class_fun H [ffun x => phi (if H \subset G then x else 1%g) *+ (x \in H)].
Proof.
apply: intro_class_fun => /= [x y Hx Hy | x /negbTE/=-> //].
by rewrite Hx (groupJ Hx) //; case: subsetP => // sHG; rewrite cfunJgen ?sHG.
Qed.
Definition cfRes phi := Cfun 1 (cfRes_subproof phi).
Lemma cfResE phi : A \subset B -> {in A, cfRes phi =1 phi}.
Proof. by move=> sAB x Ax; rewrite cfunElock mem_gen ?genS. Qed.
Lemma cfRes1 phi : cfRes phi 1%g = phi 1%g.
Proof. by rewrite cfunElock if_same group1. Qed.
Lemma cfRes_is_linear : linear cfRes.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfRes
(GRing.semilinear_linear cfRes_is_linear).
Lemma cfRes_cfun1 : cfRes 1 = 1.
Proof.
apply: cfun_in_genP => x Hx; rewrite cfunElock Hx !cfun1Egen Hx.
by case: subsetP => [-> // | _]; rewrite group1.
Qed.
Lemma cfRes_is_monoid_morphism : monoid_morphism cfRes.
Proof.
split=> [|phi psi]; [exact: cfRes_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfRes_is_monoid_morphism` instead")]
Definition cfRes_is_multiplicative :=
(fun g => (g.2,g.1)) cfRes_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfRes
cfRes_is_monoid_morphism.
End Restrict.
Arguments cfRes {gT} A%_g {B%_g} phi%_CF.
Notation "''Res[' H , G ]" := (@cfRes _ H G) (only parsing) : ring_scope.
Notation "''Res[' H ]" := 'Res[H, _] : ring_scope.
Notation "''Res'" := 'Res[_] (only parsing) : ring_scope.
Section MoreRestrict.
Variables (gT : finGroupType) (G H : {group gT}).
Implicit Types (A : {set gT}) (phi : 'CF(G)).
Lemma cfResEout phi : ~~ (H \subset G) -> 'Res[H] phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x.
by rewrite cfunE cfun1E mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfResRes A phi :
A \subset H -> H \subset G -> 'Res[A] ('Res[H] phi) = 'Res[A] phi.
Proof.
move=> sAH sHG; apply/cfunP=> x; rewrite !cfunElock !genGid !gen_subG sAH sHG.
by rewrite (subset_trans sAH) // -mulrnA mulnb -in_setI (setIidPr _) ?gen_subG.
Qed.
Lemma cfRes_id A psi : 'Res[A] psi = psi.
Proof. by apply/cfun_in_genP=> x Ax; rewrite cfunElock Ax subxx. Qed.
Lemma sub_cfker_Res A phi :
A \subset H -> A \subset cfker phi -> A \subset cfker ('Res[H, G] phi).
Proof.
move=> sAH kerA; apply/subsetP=> x Ax; have Hx := subsetP sAH x Ax.
rewrite inE Hx; apply/forallP=> y; rewrite !cfunElock !genGid groupMl //.
by rewrite !(fun_if phi) cfkerMl // (subsetP kerA).
Qed.
Lemma eq_cfker_Res phi : H \subset cfker phi -> cfker ('Res[H, G] phi) = H.
Proof. by move=> kH; apply/eqP; rewrite eqEsubset cfker_sub sub_cfker_Res. Qed.
Lemma cfRes_sub_ker phi : H \subset cfker phi -> 'Res[H, G] phi = (phi 1%g)%:A.
Proof.
move=> kerHphi; have sHG := subset_trans kerHphi (cfker_sub phi).
apply/cfun_inP=> x Hx; have ker_x := subsetP kerHphi x Hx.
by rewrite cfResE // cfunE cfun1E Hx mulr1 cfker1.
Qed.
Lemma cforder_Res phi : #['Res[H] phi]%CF %| #[phi]%CF.
Proof. exact: cforder_rmorph. Qed.
End MoreRestrict.
Section Morphim.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Section Main.
Variable G : {group aT}.
Implicit Type phi : 'CF(f @* G).
Fact cfMorph_subproof phi :
is_class_fun <<G>>
[ffun x => phi (if G \subset D then f x else 1%g) *+ (x \in G)].
Proof.
rewrite genGid; apply: intro_class_fun => [x y Gx Gy | x /negPf-> //].
rewrite Gx groupJ //; case subsetP => // sGD.
by rewrite morphJ ?cfunJ ?mem_morphim ?sGD.
Qed.
Definition cfMorph phi := Cfun 1 (cfMorph_subproof phi).
Lemma cfMorphE phi x : G \subset D -> x \in G -> cfMorph phi x = phi (f x).
Proof. by rewrite cfunElock => -> ->. Qed.
Lemma cfMorph1 phi : cfMorph phi 1%g = phi 1%g.
Proof. by rewrite cfunElock morph1 if_same group1. Qed.
Lemma cfMorphEout phi : ~~ (G \subset D) -> cfMorph phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sGD; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_sGD.
Qed.
Lemma cfMorph_cfun1 : cfMorph 1 = 1.
Proof.
apply/cfun_inP=> x Gx; rewrite cfunElock !cfun1E Gx.
by case: subsetP => [sGD | _]; rewrite ?group1 // mem_morphim ?sGD.
Qed.
Fact cfMorph_is_linear : linear cfMorph.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr -mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfMorph
(GRing.semilinear_linear cfMorph_is_linear).
Fact cfMorph_is_monoid_morphism : monoid_morphism cfMorph.
Proof.
split=> [|phi psi]; [exact: cfMorph_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfMorph
cfMorph_is_monoid_morphism.
Hypothesis sGD : G \subset D.
Lemma cfMorph_inj : injective cfMorph.
Proof.
move=> phi1 phi2 eq_phi; apply/cfun_inP=> _ /morphimP[x Dx Gx ->].
by rewrite -!cfMorphE // eq_phi.
Qed.
Lemma cfMorph_eq1 phi : (cfMorph phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfMorph_inj. Qed.
Lemma cfker_morph phi : cfker (cfMorph phi) = G :&: f @*^-1 (cfker phi).
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
have Dx := subsetP sGD x Gx; rewrite Dx mem_morphim //=.
apply/forallP/forallP=> Kx y.
have [{y} /morphimP[y Dy Gy ->] | fG'y] := boolP (y \in f @* G).
by rewrite -morphM // -!(cfMorphE phi) ?groupM.
by rewrite !cfun0 ?groupMl // mem_morphim.
have [Gy | G'y] := boolP (y \in G); last by rewrite !cfun0 ?groupMl.
by rewrite !cfMorphE ?groupM ?morphM // (subsetP sGD).
Qed.
Lemma cfker_morph_im phi : f @* cfker (cfMorph phi) = cfker phi.
Proof. by rewrite cfker_morph // morphim_setIpre (setIidPr (cfker_sub _)). Qed.
Lemma sub_cfker_morph phi (A : {set aT}) :
(A \subset cfker (cfMorph phi)) = (A \subset G) && (f @* A \subset cfker phi).
Proof.
rewrite cfker_morph // subsetI; apply: andb_id2l => sAG.
by rewrite sub_morphim_pre // (subset_trans sAG).
Qed.
Lemma sub_morphim_cfker phi (A : {set aT}) :
A \subset G -> (f @* A \subset cfker phi) = (A \subset cfker (cfMorph phi)).
Proof. by move=> sAG; rewrite sub_cfker_morph ?sAG. Qed.
Lemma cforder_morph phi : #[cfMorph phi]%CF = #[phi]%CF.
Proof. exact/cforder_inj_rmorph/cfMorph_inj. Qed.
End Main.
Lemma cfResMorph (G H : {group aT}) (phi : 'CF(f @* G)) :
H \subset G -> G \subset D -> 'Res (cfMorph phi) = cfMorph ('Res[f @* H] phi).
Proof.
move=> sHG sGD; have sHD := subset_trans sHG sGD.
apply/cfun_inP=> x Hx; have [Gx Dx] := (subsetP sHG x Hx, subsetP sHD x Hx).
by rewrite !(cfMorphE, cfResE) ?morphimS ?mem_morphim //.
Qed.
End Morphim.
Prenex Implicits cfMorph.
Section Isomorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Let defR := isom_im isoGR.
Local Notation G1 := (isom_inv isoGR @* R).
Let defG : G1 = G := isom_im (isom_sym isoGR).
Fact cfIsom_key : unit. Proof. by []. Qed.
Definition cfIsom :=
locked_with cfIsom_key (cfMorph \o 'Res[G1] : 'CF(G) -> 'CF(R)).
Canonical cfIsom_unlockable := [unlockable of cfIsom].
Lemma cfIsomE phi (x : aT : finType) : x \in G -> cfIsom phi (f x) = phi x.
Proof.
move=> Gx; rewrite unlock cfMorphE //= /restrm ?defG ?cfRes_id ?invmE //.
by rewrite -defR mem_morphim.
Qed.
Lemma cfIsom1 phi : cfIsom phi 1%g = phi 1%g.
Proof. by rewrite -(morph1 f) cfIsomE. Qed.
Lemma cfIsom_is_zmod_morphism : zmod_morphism cfIsom.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_zmod_morphism` instead")]
Definition cfIsom_is_additive := cfIsom_is_zmod_morphism.
Lemma cfIsom_is_monoid_morphism : monoid_morphism cfIsom.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_monoid_morphism` instead")]
Definition cfIsom_is_multiplicative :=
(fun g => (g.2,g.1)) cfIsom_is_monoid_morphism.
Lemma cfIsom_is_scalable : scalable cfIsom.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfIsom cfIsom_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfIsom
cfIsom_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfIsom
cfIsom_is_scalable.
Lemma cfIsom_cfun1 : cfIsom 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_isom phi : cfker (cfIsom phi) = f @* cfker phi.
Proof.
rewrite unlock cfker_morph // defG cfRes_id morphpre_restrm morphpre_invm.
by rewrite -defR !morphimIim.
Qed.
End Isomorphism.
Prenex Implicits cfIsom.
Section InvMorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Lemma cfIsomK : cancel (cfIsom isoGR) (cfIsom (isom_sym isoGR)).
Proof.
move=> phi; apply/cfun_inP=> x Gx; rewrite -{1}(invmE (isom_inj isoGR) Gx).
by rewrite !cfIsomE // -(isom_im isoGR) mem_morphim.
Qed.
Lemma cfIsomKV : cancel (cfIsom (isom_sym isoGR)) (cfIsom isoGR).
Proof.
move=> phi; apply/cfun_inP=> y Ry; pose injGR := isom_inj isoGR.
rewrite -{1}[y](invmK injGR) ?(isom_im isoGR) //.
suffices /morphpreP[fGy Gf'y]: y \in invm injGR @*^-1 G by rewrite !cfIsomE.
by rewrite morphpre_invm (isom_im isoGR).
Qed.
Lemma cfIsom_inj : injective (cfIsom isoGR). Proof. exact: can_inj cfIsomK. Qed.
Lemma cfIsom_eq1 phi : (cfIsom isoGR phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfIsom_inj. Qed.
Lemma cforder_isom phi : #[cfIsom isoGR phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfIsom_inj. Qed.
End InvMorphism.
Arguments cfIsom_inj {aT rT G f R} isoGR [phi1 phi2] : rename.
Section Coset.
Variables (gT : finGroupType) (G : {group gT}) (B : {set gT}).
Implicit Type rT : finGroupType.
Local Notation H := <<B>>%g.
Definition cfMod : 'CF(G / B) -> 'CF(G) := cfMorph.
Definition ffun_Quo (phi : 'CF(G)) :=
[ffun Hx : coset_of B =>
phi (if B \subset cfker phi then repr Hx else 1%g) *+ (Hx \in G / B)%g].
Fact cfQuo_subproof phi : is_class_fun <<G / B>> (ffun_Quo phi).
Proof.
rewrite genGid; apply: intro_class_fun => [|Hx /negPf-> //].
move=> _ _ /morphimP[x Nx Gx ->] /morphimP[z Nz Gz ->].
rewrite -morphJ ?mem_morphim ?val_coset_prim ?groupJ //= -gen_subG.
case: subsetP => // KphiH; do 2!case: repr_rcosetP => _ /KphiH/cfkerMl->.
by rewrite cfunJ.
Qed.
Definition cfQuo phi := Cfun 1 (cfQuo_subproof phi).
Local Notation "phi / 'B'" := (cfQuo phi)
(at level 40, left associativity) : cfun_scope.
Local Notation "phi %% 'B'" := (cfMod phi) (at level 40) : cfun_scope.
(* We specialize the cfMorph lemmas to cfMod by strengthening the domain *)
(* condition G \subset 'N(H) to H <| G; the cfMorph lemmas can be used if the *)
(* stronger results are needed. *)
Lemma cfModE phi x : B <| G -> x \in G -> (phi %% B)%CF x = phi (coset B x).
Proof. by move/normal_norm=> nBG; apply: cfMorphE. Qed.
Lemma cfMod1 phi : (phi %% B)%CF 1%g = phi 1%g. Proof. exact: cfMorph1. Qed.
HB.instance Definition _ := GRing.LRMorphism.on cfMod.
Lemma cfMod_cfun1 : (1 %% B)%CF = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_mod phi : B <| G -> B \subset cfker (phi %% B).
Proof.
case/andP=> sBG nBG; rewrite cfker_morph // subsetI sBG.
apply: subset_trans _ (ker_sub_pre _ _); rewrite ker_coset_prim subsetI.
by rewrite (subset_trans sBG nBG) sub_gen.
Qed.
(* Note that cfQuo is nondegenerate even when G does not normalize B. *)
Lemma cfQuoEnorm (phi : 'CF(G)) x :
B \subset cfker phi -> x \in 'N_G(B) -> (phi / B)%CF (coset B x) = phi x.
Proof.
rewrite cfunElock -gen_subG => sHK /setIP[Gx nHx]; rewrite sHK /=.
rewrite mem_morphim // val_coset_prim //.
by case: repr_rcosetP => _ /(subsetP sHK)/cfkerMl->.
Qed.
Lemma cfQuoE (phi : 'CF(G)) x :
B <| G -> B \subset cfker phi -> x \in G -> (phi / B)%CF (coset B x) = phi x.
Proof. by case/andP=> _ nBG sBK Gx; rewrite cfQuoEnorm // (setIidPl _). Qed.
Lemma cfQuo1 (phi : 'CF(G)) : (phi / B)%CF 1%g = phi 1%g.
Proof. by rewrite cfunElock repr_coset1 group1 if_same. Qed.
Lemma cfQuoEout (phi : 'CF(G)) :
~~ (B \subset cfker phi) -> (phi / B)%CF = (phi 1%g)%:A.
Proof.
move/negPf=> not_kerB; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_kerB.
Qed.
(* cfQuo is only linear on the class functions that have H in their kernel. *)
Lemma cfQuo_cfun1 : (1 / B)%CF = 1.
Proof.
apply/cfun_inP=> Hx G_Hx; rewrite cfunElock !cfun1E G_Hx cfker_cfun1 -gen_subG.
have [x nHx Gx ->] := morphimP G_Hx.
case: subsetP=> [sHG | _]; last by rewrite group1.
by rewrite val_coset_prim //; case: repr_rcosetP => y /sHG/groupM->.
Qed.
(* Cancellation properties *)
Lemma cfModK : B <| G -> cancel cfMod cfQuo.
Proof.
move=> nsBG phi; apply/cfun_inP=> _ /morphimP[x Nx Gx ->] //.
by rewrite cfQuoE ?cfker_mod ?cfModE.
Qed.
Lemma cfQuoK :
B <| G -> forall phi, B \subset cfker phi -> (phi / B %% B)%CF = phi.
Proof.
by move=> nsHG phi sHK; apply/cfun_inP=> x Gx; rewrite cfModE ?cfQuoE.
Qed.
Lemma cfMod_eq1 psi : B <| G -> (psi %% B == 1)%CF = (psi == 1).
Proof. by move/cfModK/can_eq <-; rewrite rmorph1. Qed.
Lemma cfQuo_eq1 phi :
B <| G -> B \subset cfker phi -> (phi / B == 1)%CF = (phi == 1).
Proof. by move=> nsBG kerH; rewrite -cfMod_eq1 // cfQuoK. Qed.
End Coset.
Arguments cfQuo {gT G%_G} B%_g phi%_CF.
Arguments cfMod {gT G%_G B%_g} phi%_CF.
Notation "phi / H" := (cfQuo H phi) : cfun_scope.
Notation "phi %% H" := (@cfMod _ _ H phi) : cfun_scope.
Section MoreCoset.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (H K : {group gT}) (phi : 'CF(G)).
Lemma cfResMod H K (psi : 'CF(G / K)) :
H \subset G -> K <| G -> ('Res (psi %% K) = 'Res[H / K] psi %% K)%CF.
Proof. by move=> sHG /andP[_]; apply: cfResMorph. Qed.
Lemma quotient_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> (cfker (psi %% K) / K)%g = cfker psi.
Proof. by case/andP=> _ /cfker_morph_im <-. Qed.
Lemma sub_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> A \subset 'N(K) ->
(A \subset cfker (psi %% K)) = (A / K \subset cfker psi)%g.
Proof.
by move=> nsKG nKA; rewrite -(quotientSGK nKA) ?quotient_cfker_mod// cfker_mod.
Qed.
Lemma cfker_quo H phi :
H <| G -> H \subset cfker (phi) -> cfker (phi / H) = (cfker phi / H)%g.
Proof.
move=> nsHG /cfQuoK {2}<- //; have [sHG nHG] := andP nsHG.
by rewrite cfker_morph 1?quotientGI // cosetpreK (setIidPr _) ?cfker_sub.
Qed.
Lemma cfQuoEker phi x :
x \in G -> (phi / cfker phi)%CF (coset (cfker phi) x) = phi x.
Proof. by move/cfQuoE->; rewrite ?cfker_normal. Qed.
Lemma cfaithful_quo phi : cfaithful (phi / cfker phi).
Proof. by rewrite cfaithfulE cfker_quo ?cfker_normal ?trivg_quotient. Qed.
(* Note that there is no requirement that K be normal in H or G. *)
Lemma cfResQuo H K phi :
K \subset cfker phi -> K \subset H -> H \subset G ->
('Res[H / K] (phi / K) = 'Res[H] phi / K)%CF.
Proof.
move=> kerK sKH sHG; apply/cfun_inP=> xb Hxb; rewrite cfResE ?quotientS //.
have{xb Hxb} [x nKx Hx ->] := morphimP Hxb.
by rewrite !cfQuoEnorm ?cfResE// 1?inE ?Hx ?(subsetP sHG)// sub_cfker_Res.
Qed.
Lemma cfQuoInorm K phi :
K \subset cfker phi -> (phi / K)%CF = 'Res ('Res['N_G(K)] phi / K)%CF.
Proof.
move=> kerK; rewrite -cfResQuo ?subsetIl ?quotientInorm ?cfRes_id //.
by rewrite subsetI normG (subset_trans kerK) ?cfker_sub.
Qed.
Lemma cforder_mod H (psi : 'CF(G / H)) : H <| G -> #[psi %% H]%CF = #[psi]%CF.
Proof. by move/cfModK/can_inj/cforder_inj_rmorph->. Qed.
Lemma cforder_quo H phi :
H <| G -> H \subset cfker phi -> #[phi / H]%CF = #[phi]%CF.
Proof. by move=> nsHG kerHphi; rewrite -cforder_mod ?cfQuoK. Qed.
End MoreCoset.
Section Product.
Variable (gT : finGroupType) (G : {group gT}).
Lemma cfunM_onI A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) -> phi * psi \in 'CF(G, A :&: B).
Proof.
rewrite !cfun_onE => Aphi Bpsi; apply/subsetP=> x; rewrite !inE cfunE mulf_eq0.
by case/norP=> /(subsetP Aphi)-> /(subsetP Bpsi).
Qed.
Lemma cfunM_on A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, A) -> phi * psi \in 'CF(G, A).
Proof. by move=> Aphi Bpsi; rewrite -[A]setIid cfunM_onI. Qed.
End Product.
Section SDproduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis defG : K ><| H = G.
Fact cfSdprodKey : unit. Proof. by []. Qed.
Definition cfSdprod :=
locked_with cfSdprodKey
(cfMorph \o cfIsom (tagged (sdprod_isom defG)) : 'CF(H) -> 'CF(G)).
Canonical cfSdprod_unlockable := [unlockable of cfSdprod].
Lemma cfSdprod_is_zmod_morphism : zmod_morphism cfSdprod.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_zmod_morphism` instead")]
Definition cfSdprod_is_additive := cfSdprod_is_zmod_morphism.
Lemma cfSdprod_is_monoid_morphism : monoid_morphism cfSdprod.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_monoid_morphism` instead")]
Definition cfSdprod_is_multiplicative :=
(fun g => (g.2,g.1)) cfSdprod_is_monoid_morphism.
Lemma cfSdprod_is_scalable : scalable cfSdprod.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfSdprod cfSdprod_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfSdprod
cfSdprod_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfSdprod
cfSdprod_is_scalable.
Lemma cfSdprod1 phi : cfSdprod phi 1%g = phi 1%g.
Proof. by rewrite unlock /= cfMorph1 cfIsom1. Qed.
Let nsKG : K <| G. Proof. by have [] := sdprod_context defG. Qed.
Let sHG : H \subset G. Proof. by have [] := sdprod_context defG. Qed.
Let sKG : K \subset G. Proof. by have [] := andP nsKG. Qed.
Lemma cfker_sdprod phi : K \subset cfker (cfSdprod phi).
Proof. by rewrite unlock_with cfker_mod. Qed.
Lemma cfSdprodEr phi : {in H, cfSdprod phi =1 phi}.
Proof. by move=> y Hy; rewrite unlock cfModE ?cfIsomE ?(subsetP sHG). Qed.
Lemma cfSdprodE phi : {in K & H, forall x y, cfSdprod phi (x * y)%g = phi y}.
Proof.
by move=> x y Kx Hy; rewrite /= cfkerMl ?(subsetP (cfker_sdprod _)) ?cfSdprodEr.
Qed.
Lemma cfSdprodK : cancel cfSdprod 'Res[H].
Proof. by move=> phi; apply/cfun_inP=> x Hx; rewrite cfResE ?cfSdprodEr. Qed.
Lemma cfSdprod_inj : injective cfSdprod. Proof. exact: can_inj cfSdprodK. Qed.
Lemma cfSdprod_eq1 phi : (cfSdprod phi == 1) = (phi == 1).
Proof. exact: rmorph_eq1 cfSdprod_inj. Qed.
Lemma cfRes_sdprodK phi : K \subset cfker phi -> cfSdprod ('Res[H] phi) = phi.
Proof.
move=> kerK; apply/cfun_inP=> _ /(mem_sdprod defG)[x [y [Kx Hy -> _]]].
by rewrite cfSdprodE // cfResE // cfkerMl ?(subsetP kerK).
Qed.
Lemma sdprod_cfker phi : K ><| cfker phi = cfker (cfSdprod phi).
Proof.
have [skerH [_ _ nKH tiKH]] := (cfker_sub phi, sdprodP defG).
rewrite unlock cfker_morph ?normal_norm // cfker_isom restrmEsub //=.
rewrite -(sdprod_modl defG) ?sub_cosetpre //=; congr (_ ><| _).
by rewrite quotientK ?(subset_trans skerH) // -group_modr //= setIC tiKH mul1g.
Qed.
Lemma cforder_sdprod phi : #[cfSdprod phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfSdprod_inj. Qed.
End SDproduct.
Section DProduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis KxH : K \x H = G.
Lemma reindex_dprod R idx (op : Monoid.com_law idx) (F : gT -> R) :
\big[op/idx]_(g in G) F g =
\big[op/idx]_(k in K) \big[op/idx]_(h in H) F (k * h)%g.
Proof.
have /mulgmP/misomP[fM /isomP[injf im_f]] := KxH.
rewrite pair_big_dep -im_f morphimEdom big_imset; last exact/injmP.
by apply: eq_big => [][x y]; rewrite ?inE.
Qed.
Definition cfDprodr := cfSdprod (dprodWsd KxH).
Definition cfDprodl := cfSdprod (dprodWsdC KxH).
Definition cfDprod phi psi := cfDprodl phi * cfDprodr psi.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodl.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodr.
Lemma cfDprodl1 phi : cfDprodl phi 1%g = phi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprodr1 psi : cfDprodr psi 1%g = psi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprod1 phi psi : cfDprod phi psi 1%g = phi 1%g * psi 1%g.
Proof. by rewrite cfunE /= !cfSdprod1. Qed.
Lemma cfDprodl_eq1 phi : (cfDprodl phi == 1) = (phi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprodr_eq1 psi : (cfDprodr psi == 1) = (psi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprod_cfun1r phi : cfDprod phi 1 = cfDprodl phi.
Proof. by rewrite /cfDprod rmorph1 mulr1. Qed.
Lemma cfDprod_cfun1l psi : cfDprod 1 psi = cfDprodr psi.
Proof. by rewrite /cfDprod rmorph1 mul1r. Qed.
Lemma cfDprod_cfun1 : cfDprod 1 1 = 1.
Proof. by rewrite cfDprod_cfun1l rmorph1. Qed.
Lemma cfDprod_split phi psi : cfDprod phi psi = cfDprod phi 1 * cfDprod 1 psi.
Proof. by rewrite cfDprod_cfun1l cfDprod_cfun1r. Qed.
Let nsKG : K <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let nsHG : H <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let cKH : H \subset 'C(K). Proof. by have [] := dprodP KxH. Qed.
Let sKG := normal_sub nsKG.
Let sHG := normal_sub nsHG.
Lemma cfDprodlK : cancel cfDprodl 'Res[K]. Proof. exact: cfSdprodK. Qed.
Lemma cfDprodrK : cancel cfDprodr 'Res[H]. Proof. exact: cfSdprodK. Qed.
Lemma cfker_dprodl phi : cfker phi \x H = cfker (cfDprodl phi).
Proof.
by rewrite dprodC -sdprod_cfker dprodEsd // centsC (centsS (cfker_sub _)).
Qed.
Lemma cfker_dprodr psi : K \x cfker psi = cfker (cfDprodr psi).
Proof. by rewrite -sdprod_cfker dprodEsd // (subset_trans (cfker_sub _)). Qed.
Lemma cfDprodEl phi : {in K & H, forall k h, cfDprodl phi (k * h)%g = phi k}.
Proof. by move=> k h Kk Hh /=; rewrite -(centsP cKH) // cfSdprodE. Qed.
Lemma cfDprodEr psi : {in K & H, forall k h, cfDprodr psi (k * h)%g = psi h}.
Proof. exact: cfSdprodE. Qed.
Lemma cfDprodE phi psi :
{in K & H, forall h k, cfDprod phi psi (h * k)%g = phi h * psi k}.
Proof. by move=> k h Kk Hh /=; rewrite cfunE cfDprodEl ?cfDprodEr. Qed.
Lemma cfDprod_Resl phi psi : 'Res[K] (cfDprod phi psi) = psi 1%g *: phi.
Proof.
by apply/cfun_inP=> x Kx; rewrite cfunE cfResE // -{1}[x]mulg1 mulrC cfDprodE.
Qed.
Lemma cfDprod_Resr phi psi : 'Res[H] (cfDprod phi psi) = phi 1%g *: psi.
Proof.
by apply/cfun_inP=> y Hy; rewrite cfunE cfResE // -{1}[y]mul1g cfDprodE.
Qed.
Lemma cfDprodKl (psi : 'CF(H)) : psi 1%g = 1 -> cancel (cfDprod^~ psi) 'Res.
Proof. by move=> psi1 phi; rewrite cfDprod_Resl psi1 scale1r. Qed.
Lemma cfDprodKr (phi : 'CF(K)) : phi 1%g = 1 -> cancel (cfDprod phi) 'Res.
Proof. by move=> phi1 psi; rewrite cfDprod_Resr phi1 scale1r. Qed.
(* Note that equality holds here iff either cfker phi = K and cfker psi = H, *)
(* or else phi != 0, psi != 0 and coprime #|K : cfker phi| #|H : cfker phi|. *)
Lemma cfker_dprod phi psi :
cfker phi <*> cfker psi \subset cfker (cfDprod phi psi).
Proof.
rewrite -genM_join gen_subG; apply/subsetP=> _ /mulsgP[x y kKx kHy ->] /=.
have [[Kx _] [Hy _]] := (setIdP kKx, setIdP kHy).
have Gxy: (x * y)%g \in G by rewrite -(dprodW KxH) mem_mulg.
rewrite inE Gxy; apply/forallP=> g.
have [Gg | G'g] := boolP (g \in G); last by rewrite !cfun0 1?groupMl.
have{g Gg} [k [h [Kk Hh -> _]]] := mem_dprod KxH Gg.
rewrite mulgA -(mulgA x) (centsP cKH y) // mulgA -mulgA !cfDprodE ?groupM //.
by rewrite !cfkerMl.
Qed.
Lemma cfdot_dprod phi1 phi2 psi1 psi2 :
'[cfDprod phi1 psi1, cfDprod phi2 psi2] = '[phi1, phi2] * '[psi1, psi2].
Proof.
rewrite !cfdotE mulrCA -mulrA mulrCA mulrA -invfM -natrM (dprod_card KxH).
congr (_ * _); rewrite big_distrl reindex_dprod /=; apply: eq_bigr => k Kk.
rewrite big_distrr; apply: eq_bigr => h Hh /=.
by rewrite mulrCA -mulrA -rmorphM mulrCA mulrA !cfDprodE.
Qed.
Lemma cfDprodl_iso : isometry cfDprodl.
Proof.
by move=> phi1 phi2; rewrite -!cfDprod_cfun1r cfdot_dprod cfnorm1 mulr1.
Qed.
Lemma cfDprodr_iso : isometry cfDprodr.
Proof.
by move=> psi1 psi2; rewrite -!cfDprod_cfun1l cfdot_dprod cfnorm1 mul1r.
Qed.
Lemma cforder_dprodl phi : #[cfDprodl phi]%CF = #[phi]%CF.
Proof. exact: cforder_sdprod. Qed.
Lemma cforder_dprodr psi : #[cfDprodr psi]%CF = #[psi]%CF.
Proof. exact: cforder_sdprod. Qed.
End DProduct.
Lemma cfDprodC (gT : finGroupType) (G K H : {group gT})
(KxH : K \x H = G) (HxK : H \x K = G) chi psi :
cfDprod KxH chi psi = cfDprod HxK psi chi.
Proof.
rewrite /cfDprod mulrC.
by congr (_ * _); congr (cfSdprod _ _); apply: eq_irrelevance.
Qed.
Section Bigdproduct.
Variables (gT : finGroupType) (I : finType) (P : pred I).
Variables (A : I -> {group gT}) (G : {group gT}).
Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G.
Let sAG i : P i -> A i \subset G.
Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed.
Fact cfBigdprodi_subproof i :
gval (if P i then A i else 1%G) \x <<\bigcup_(j | P j && (j != i)) A j>> = G.
Proof.
have:= defG; rewrite fun_if big_mkcond (bigD1 i) // -big_mkcondl /= => defGi.
by have [[_ Gi' _ defGi']] := dprodP defGi; rewrite (bigdprodWY defGi') -defGi'.
Qed.
Definition cfBigdprodi i := cfDprodl (cfBigdprodi_subproof i) \o 'Res[_, A i].
HB.instance Definition _ i := GRing.LRMorphism.on (@cfBigdprodi i).
Lemma cfBigdprodi1 i (phi : 'CF(A i)) : cfBigdprodi phi 1%g = phi 1%g.
Proof. by rewrite cfDprodl1 cfRes1. Qed.
Lemma cfBigdprodi_eq1 i (phi : 'CF(A i)) :
P i -> (cfBigdprodi phi == 1) = (phi == 1).
Proof. by move=> Pi; rewrite cfSdprod_eq1 Pi cfRes_id. Qed.
Lemma cfBigdprodiK i : P i -> cancel (@cfBigdprodi i) 'Res[A i].
Proof.
move=> Pi phi; have:= cfDprodlK (cfBigdprodi_subproof i) ('Res phi).
by rewrite -[cfDprodl _ _]/(cfBigdprodi phi) Pi cfRes_id.
Qed.
Lemma cfBigdprodi_inj i : P i -> injective (@cfBigdprodi i).
Proof. by move/cfBigdprodiK; apply: can_inj. Qed.
Lemma cfBigdprodEi i (phi : 'CF(A i)) x :
P i -> (forall j, P j -> x j \in A j) ->
cfBigdprodi phi (\prod_(j | P j) x j)%g = phi (x i).
Proof.
have [r big_r [Ur mem_r] _] := big_enumP P => Pi AxP.
have:= bigdprodWcp defG; rewrite -!big_r => defGr.
have{AxP} [r_i Axr]: i \in r /\ {in r, forall j, x j \in A j}.
by split=> [|j]; rewrite mem_r // => /AxP.
rewrite (perm_bigcprod defGr Axr (perm_to_rem r_i)) big_cons.
rewrite cfDprodEl ?Pi ?cfRes_id ?Axr // big_seq group_prod // => j.
rewrite mem_rem_uniq // => /andP[i'j /= r_j].
by apply/mem_gen/bigcupP; exists j; [rewrite -mem_r r_j | apply: Axr].
Qed.
Lemma cfBigdprodi_iso i : P i -> isometry (@cfBigdprodi i).
Proof. by move=> Pi phi psi; rewrite cfDprodl_iso Pi !cfRes_id. Qed.
Definition cfBigdprod (phi : forall i, 'CF(A i)) :=
\prod_(i | P i) cfBigdprodi (phi i).
Lemma cfBigdprodE phi x :
(forall i, P i -> x i \in A i) ->
cfBigdprod phi (\prod_(i | P i) x i)%g = \prod_(i | P i) phi i (x i).
Proof.
move=> Ax; rewrite prod_cfunE; last by rewrite -(bigdprodW defG) mem_prodg.
by apply: eq_bigr => i Pi; rewrite cfBigdprodEi.
Qed.
Lemma cfBigdprod1 phi : cfBigdprod phi 1%g = \prod_(i | P i) phi i 1%g.
Proof. by rewrite prod_cfunE //; apply/eq_bigr=> i _; apply: cfBigdprodi1. Qed.
Lemma cfBigdprodK phi (Phi := cfBigdprod phi) i (a := phi i 1%g / Phi 1%g) :
Phi 1%g != 0 -> P i -> a != 0 /\ a *: 'Res[A i] Phi = phi i.
Proof.
move=> nzPhi Pi; split.
rewrite mulf_neq0 ?invr_eq0 // (contraNneq _ nzPhi) // => phi_i0.
by rewrite cfBigdprod1 (bigD1 i) //= phi_i0 mul0r.
apply/cfun_inP=> x Aix; rewrite cfunE cfResE ?sAG // mulrAC.
have {1}->: x = (\prod_(j | P j) (if j == i then x else 1))%g.
rewrite -big_mkcondr (big_pred1 i) ?eqxx // => j /=.
by apply: andb_idl => /eqP->.
rewrite cfBigdprodE => [|j _]; last by case: eqP => // ->.
apply: canLR (mulfK nzPhi) _; rewrite cfBigdprod1 !(bigD1 i Pi) /= eqxx.
by rewrite mulrCA !mulrA; congr (_ * _); apply: eq_bigr => j /andP[_ /negPf->].
Qed.
Lemma cfdot_bigdprod phi psi :
'[cfBigdprod phi, cfBigdprod psi] = \prod_(i | P i) '[phi i, psi i].
Proof.
apply: canLR (mulKf (neq0CG G)) _; rewrite -(bigdprod_card defG).
rewrite (big_morph _ (@natrM _) (erefl _)) -big_split /=.
rewrite (eq_bigr _ (fun i _ => mulVKf (neq0CG _) _)) (big_distr_big_dep 1%g) /=.
set F := pfamily _ _ _; pose h (f : {ffun I -> gT}) := (\prod_(i | P i) f i)%g.
pose is_hK x f := forall f1, (f1 \in F) && (h f1 == x) = (f == f1).
have /fin_all_exists[h1 Dh1] x: exists f, x \in G -> is_hK x f.
case Gx: (x \in G); last by exists [ffun _ => x].
have [f [Af fK Uf]] := mem_bigdprod defG Gx.
exists [ffun i => if P i then f i else 1%g] => _ f1.
apply/andP/eqP=> [[/pfamilyP[Pf1 Af1] /eqP Dx] | <-].
by apply/ffunP=> i; rewrite ffunE; case: ifPn => [/Uf-> | /(supportP Pf1)].
split; last by rewrite fK; apply/eqP/eq_bigr=> i Pi; rewrite ffunE Pi.
by apply/familyP=> i; rewrite ffunE !unfold_in; case: ifP => //= /Af.
rewrite (reindex_onto h h1) /= => [|x /Dh1/(_ (h1 x))]; last first.
by rewrite eqxx => /andP[_ /eqP].
apply/eq_big => [f | f /andP[/Dh1<- /andP[/pfamilyP[_ Af] _]]]; last first.
by rewrite !cfBigdprodE // rmorph_prod -big_split /=.
apply/idP/idP=> [/andP[/Dh1<-] | Ff]; first by rewrite eqxx andbT.
have /pfamilyP[_ Af] := Ff; suffices Ghf: h f \in G by rewrite -Dh1 ?Ghf ?Ff /=.
by apply/group_prod=> i Pi; rewrite (subsetP (sAG Pi)) ?Af.
Qed.
End Bigdproduct.
Section MorphIsometry.
Variable gT : finGroupType.
Implicit Types (D G H K : {group gT}) (aT rT : finGroupType).
Lemma cfMorph_iso aT rT (G D : {group aT}) (f : {morphism D >-> rT}) :
G \subset D -> isometry (cfMorph : 'CF(f @* G) -> 'CF(G)).
Proof.
move=> sGD phi psi; rewrite !cfdotE card_morphim (setIidPr sGD).
rewrite -(LagrangeI G ('ker f)) /= mulnC natrM invfM -mulrA.
congr (_ * _); apply: (canLR (mulKf (neq0CG _))).
rewrite mulr_sumr (partition_big_imset f) /= -morphimEsub //.
apply: eq_bigr => _ /morphimP[x Dx Gx ->].
rewrite -(card_rcoset _ x) mulr_natl -sumr_const.
apply/eq_big => [y | y /andP[Gy /eqP <-]]; last by rewrite !cfMorphE.
rewrite mem_rcoset inE groupMr ?groupV // -mem_rcoset.
by apply: andb_id2l => /(subsetP sGD) Dy; apply: sameP eqP (rcoset_kerP f _ _).
Qed.
Lemma cfIsom_iso rT G (R : {group rT}) (f : {morphism G >-> rT}) :
forall isoG : isom G R f, isometry (cfIsom isoG).
Proof.
move=> isoG phi psi; rewrite unlock cfMorph_iso //; set G1 := _ @* R.
by rewrite -(isom_im (isom_sym isoG)) -/G1 in phi psi *; rewrite !cfRes_id.
Qed.
Lemma cfMod_iso H G : H <| G -> isometry (@cfMod _ G H).
Proof. by case/andP=> _; apply: cfMorph_iso. Qed.
Lemma cfQuo_iso H G :
H <| G -> {in [pred phi | H \subset cfker phi] &, isometry (@cfQuo _ G H)}.
Proof.
by move=> nsHG phi psi sHkphi sHkpsi; rewrite -(cfMod_iso nsHG) !cfQuoK.
Qed.
Lemma cfnorm_quo H G phi :
H <| G -> H \subset cfker phi -> '[phi / H] = '[phi]_G.
Proof. by move=> nsHG sHker; apply: cfQuo_iso. Qed.
Lemma cfSdprod_iso K H G (defG : K ><| H = G) : isometry (cfSdprod defG).
Proof.
move=> phi psi; have [/andP[_ nKG] _ _ _ _] := sdprod_context defG.
by rewrite [cfSdprod _]locked_withE cfMorph_iso ?cfIsom_iso.
Qed.
End MorphIsometry.
Section Induced.
Variable gT : finGroupType.
Section Def.
Variables B A : {set gT}.
Local Notation G := <<B>>.
Local Notation H := <<A>>.
(* The default value for the ~~ (H \subset G) case matches the one for cfRes *)
(* so that Frobenius reciprocity holds even in this degenerate case. *)
Definition ffun_cfInd (phi : 'CF(A)) :=
[ffun x => if H \subset G then #|A|%:R^-1 * (\sum_(y in G) phi (x ^ y))
else #|G|%:R * '[phi, 1] *+ (x == 1%g)].
Fact cfInd_subproof phi : is_class_fun G (ffun_cfInd phi).
Proof.
apply: intro_class_fun => [x y Gx Gy | x H'x]; last first.
case: subsetP => [sHG | _]; last by rewrite (negPf (group1_contra H'x)).
rewrite big1 ?mulr0 // => y Gy; rewrite cfun0gen ?(contra _ H'x) //= => /sHG.
by rewrite memJ_norm ?(subsetP (normG _)).
rewrite conjg_eq1 (reindex_inj (mulgI y^-1)%g); congr (if _ then _ * _ else _).
by apply: eq_big => [z | z Gz]; rewrite ?groupMl ?groupV // -conjgM mulKVg.
Qed.
Definition cfInd phi := Cfun 1 (cfInd_subproof phi).
Lemma cfInd_is_linear : linear cfInd.
Proof.
move=> c phi psi; apply/cfunP=> x; rewrite !cfunElock; case: ifP => _.
rewrite mulrCA -mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * _); apply: eq_bigr => y _; rewrite !cfunE.
rewrite mulrnAr -mulrnDl !(mulrCA c) -!mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * (_ * _) *+ _); apply: eq_bigr => y; rewrite !cfunE mulrA mulrDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfInd
(GRing.semilinear_linear cfInd_is_linear).
End Def.
Local Notation "''Ind[' B , A ]" := (@cfInd B A) : ring_scope.
Local Notation "''Ind[' B ]" := 'Ind[B, _] : ring_scope.
Lemma cfIndE (G H : {group gT}) phi x :
H \subset G -> 'Ind[G, H] phi x = #|H|%:R^-1 * (\sum_(y in G) phi (x ^ y)).
Proof. by rewrite cfunElock !genGid => ->. Qed.
Variables G K H : {group gT}.
Implicit Types (phi : 'CF(H)) (psi : 'CF(G)).
Lemma cfIndEout phi :
~~ (H \subset G) -> 'Ind[G] phi = (#|G|%:R * '[phi, 1]) *: '1_1%G.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x; rewrite cfunE cfuniE ?normal1 // inE.
by rewrite mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfIndEsdprod (phi : 'CF(K)) x :
K ><| H = G -> 'Ind[G] phi x = \sum_(w in H) phi (x ^ w)%g.
Proof.
move=> defG; have [/andP[sKG _] _ mulKH nKH _] := sdprod_context defG.
rewrite cfIndE //; apply: canLR (mulKf (neq0CG _)) _; rewrite -mulKH mulr_sumr.
rewrite (set_partition_big _ (rcosets_partition_mul H K)) ?big_imset /=.
apply: eq_bigr => y Hy; rewrite rcosetE norm_rlcoset ?(subsetP nKH) //.
rewrite -lcosetE mulr_natl big_imset /=; last exact: in2W (mulgI _).
by rewrite -sumr_const; apply: eq_bigr => z Kz; rewrite conjgM cfunJ.
have [{}nKH /isomP[injf _]] := sdprod_isom defG.
apply: can_in_inj (fun Ky => invm injf (coset K (repr Ky))) _ => y Hy.
by rewrite rcosetE -val_coset ?(subsetP nKH) // coset_reprK invmE.
Qed.
Lemma cfInd_on A phi :
H \subset G -> phi \in 'CF(H, A) -> 'Ind[G] phi \in 'CF(G, class_support A G).
Proof.
move=> sHG Af; apply/cfun_onP=> g AG'g; rewrite cfIndE ?big1 ?mulr0 // => h Gh.
apply: (cfun_on0 Af); apply: contra AG'g => Agh.
by rewrite -[g](conjgK h) memJ_class_support // groupV.
Qed.
Lemma cfInd_id phi : 'Ind[H] phi = phi.
Proof.
apply/cfun_inP=> x Hx; rewrite cfIndE // (eq_bigr _ (cfunJ phi x)) sumr_const.
by rewrite -[phi x *+ _]mulr_natl mulKf ?neq0CG.
Qed.
Lemma cfInd_normal phi : H <| G -> 'Ind[G] phi \in 'CF(G, H).
Proof.
case/andP=> sHG nHG; apply: (cfun_onS (class_support_sub_norm (subxx _) nHG)).
by rewrite cfInd_on ?cfun_onG.
Qed.
Lemma cfInd1 phi : H \subset G -> 'Ind[G] phi 1%g = #|G : H|%:R * phi 1%g.
Proof.
move=> sHG; rewrite cfIndE // natf_indexg // -mulrA mulrCA; congr (_ * _).
by rewrite mulr_natl -sumr_const; apply: eq_bigr => x; rewrite conj1g.
Qed.
Lemma cfInd_cfun1 : H <| G -> 'Ind[G, H] 1 = #|G : H|%:R *: '1_H.
Proof.
move=> nsHG; have [sHG nHG] := andP nsHG; rewrite natf_indexg // mulrC.
apply/cfunP=> x; rewrite cfIndE ?cfunE ?cfuniE // -mulrA; congr (_ * _).
rewrite mulr_natl -sumr_const; apply: eq_bigr => y Gy.
by rewrite cfun1E -{1}(normsP nHG y Gy) memJ_conjg.
Qed.
Lemma cfnorm_Ind_cfun1 : H <| G -> '['Ind[G, H] 1] = #|G : H|%:R.
Proof.
move=> nsHG; rewrite cfInd_cfun1 // cfnormZ normr_nat cfdot_cfuni // setIid.
by rewrite expr2 {2}natf_indexg ?normal_sub // !mulrA divfK ?mulfK ?neq0CG.
Qed.
Lemma cfIndInd phi :
K \subset G -> H \subset K -> 'Ind[G] ('Ind[K] phi) = 'Ind[G] phi.
Proof.
move=> sKG sHK; apply/cfun_inP=> x Gx; rewrite !cfIndE ?(subset_trans sHK) //.
apply: canLR (mulKf (neq0CG K)) _; rewrite mulr_sumr mulr_natl.
transitivity (\sum_(y in G) \sum_(z in K) #|H|%:R^-1 * phi ((x ^ y) ^ z)).
by apply: eq_bigr => y Gy; rewrite cfIndE // -mulr_sumr.
symmetry; rewrite exchange_big /= -sumr_const; apply: eq_bigr => z Kz.
rewrite (reindex_inj (mulIg z)).
by apply: eq_big => [y | y _]; rewrite ?conjgM // groupMr // (subsetP sKG).
Qed.
(* This is Isaacs, Lemma (5.2). *)
Lemma Frobenius_reciprocity phi psi : '[phi, 'Res[H] psi] = '['Ind[G] phi, psi].
Proof.
have [sHG | not_sHG] := boolP (H \subset G); last first.
rewrite cfResEout // cfIndEout // cfdotZr cfdotZl mulrAC; congr (_ * _).
rewrite (cfdotEl _ (cfuni_on _ _)) mulVKf ?neq0CG // big_set1.
by rewrite cfuniE ?normal1 ?set11 ?mul1r.
transitivity (#|H|%:R^-1 * \sum_(x in G) phi x * (psi x)^* ).
rewrite (big_setID H) /= (setIidPr sHG) addrC big1 ?add0r; last first.
by move=> x /setDP[_ /cfun0->]; rewrite mul0r.
by congr (_ * _); apply: eq_bigr => x Hx; rewrite cfResE.
set h' := _^-1; apply: canRL (mulKf (neq0CG G)) _.
transitivity (h' * \sum_(y in G) \sum_(x in G) phi (x ^ y) * (psi (x ^ y))^* ).
rewrite mulrCA mulr_natl -sumr_const; congr (_ * _); apply: eq_bigr => y Gy.
by rewrite (reindex_acts 'J _ Gy) ?astabsJ ?normG.
rewrite exchange_big mulr_sumr; apply: eq_bigr => x _; rewrite cfIndE //=.
by rewrite -mulrA mulr_suml; congr (_ * _); apply: eq_bigr => y /(cfunJ psi)->.
Qed.
Definition cfdot_Res_r := Frobenius_reciprocity.
Lemma cfdot_Res_l psi phi : '['Res[H] psi, phi] = '[psi, 'Ind[G] phi].
Proof. by rewrite cfdotC cfdot_Res_r -cfdotC. Qed.
Lemma cfIndM phi psi: H \subset G ->
'Ind[G] (phi * ('Res[H] psi)) = 'Ind[G] phi * psi.
Proof.
move=> HsG; apply/cfun_inP=> x Gx; rewrite !cfIndE // !cfunE !cfIndE // -mulrA.
congr (_ * _); rewrite mulr_suml; apply: eq_bigr=> i iG; rewrite !cfunE.
case: (boolP (x ^ i \in H)) => xJi; last by rewrite cfun0gen ?mul0r ?genGid.
by rewrite !cfResE //; congr (_ * _); rewrite cfunJgen ?genGid.
Qed.
End Induced.
Arguments cfInd {gT} B%_g {A%_g} phi%_CF.
Notation "''Ind[' G , H ]" := (@cfInd _ G H) (only parsing) : ring_scope.
Notation "''Ind[' G ]" := 'Ind[G, _] : ring_scope.
Notation "''Ind'" := 'Ind[_] (only parsing) : ring_scope.
Section MorphInduced.
Variables (aT rT : finGroupType) (D G H : {group aT}) (R S : {group rT}).
Lemma cfIndMorph (f : {morphism D >-> rT}) (phi : 'CF(f @* H)) :
'ker f \subset H -> H \subset G -> G \subset D ->
'Ind[G] (cfMorph phi) = cfMorph ('Ind[f @* G] phi).
Proof.
move=> sKH sHG sGD; have [sHD inD] := (subset_trans sHG sGD, subsetP sGD).
apply/cfun_inP=> /= x Gx; have [Dx sKG] := (inD x Gx, subset_trans sKH sHG).
rewrite cfMorphE ?cfIndE ?morphimS // (partition_big_imset f) -morphimEsub //=.
rewrite card_morphim (setIidPr sHD) natf_indexg // invfM invrK -mulrA.
congr (_ * _); rewrite mulr_sumr; apply: eq_bigr => _ /morphimP[y Dy Gy ->].
rewrite -(card_rcoset _ y) mulr_natl -sumr_const.
apply: eq_big => [z | z /andP[Gz /eqP <-]].
have [Gz | G'z] := boolP (z \in G).
by rewrite (sameP eqP (rcoset_kerP _ _ _)) ?inD.
by case: rcosetP G'z => // [[t Kt ->]]; rewrite groupM // (subsetP sKG).
have [Dz Dxz] := (inD z Gz, inD (x ^ z) (groupJ Gx Gz)); rewrite -morphJ //.
have [Hxz | notHxz] := boolP (x ^ z \in H); first by rewrite cfMorphE.
by rewrite !cfun0 // -sub1set -morphim_set1 // morphimSGK ?sub1set.
Qed.
Variables (g : {morphism G >-> rT}) (h : {morphism H >-> rT}).
Hypotheses (isoG : isom G R g) (isoH : isom H S h) (eq_hg : {in H, h =1 g}).
Hypothesis sHG : H \subset G.
Lemma cfResIsom phi : 'Res[S] (cfIsom isoG phi) = cfIsom isoH ('Res[H] phi).
Proof.
have [[injg defR] [injh defS]] := (isomP isoG, isomP isoH).
rewrite !morphimEdom in defS defR; apply/cfun_inP=> s.
rewrite -{1}defS => /imsetP[x Hx ->] {s}; have Gx := subsetP sHG x Hx.
rewrite {1}eq_hg ?(cfResE, cfIsomE) // -defS -?eq_hg ?imset_f // -defR.
by rewrite (eq_in_imset eq_hg) imsetS.
Qed.
Lemma cfIndIsom phi : 'Ind[R] (cfIsom isoH phi) = cfIsom isoG ('Ind[G] phi).
Proof.
have [[injg defR] [_ defS]] := (isomP isoG, isomP isoH).
rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS.
apply/cfun_inP=> s; rewrite -{1}defR => /morphimP[x _ Gx ->]{s}.
rewrite cfIsomE ?cfIndE // -defR -{1}defS ?morphimS ?card_injm // morphimEdom.
congr (_ * _); rewrite big_imset //=; last exact/injmP.
apply: eq_bigr => y Gy; rewrite -morphJ //.
have [Hxy | H'xy] := boolP (x ^ y \in H); first by rewrite -eq_hg ?cfIsomE.
by rewrite !cfun0 -?defS // -sub1set -morphim_set1 ?injmSK ?sub1set // groupJ.
Qed.
End MorphInduced.
Section FieldAutomorphism.
Variables (u : {rmorphism algC -> algC}) (gT rT : finGroupType).
Variables (G K H : {group gT}) (f : {morphism G >-> rT}) (R : {group rT}).
Implicit Types (phi : 'CF(G)) (S : seq 'CF(G)).
Local Notation "phi ^u" := (cfAut u phi).
Lemma cfAutZ_nat n phi : (n%:R *: phi)^u = n%:R *: phi^u.
Proof. exact: raddfZnat. Qed.
Lemma cfAutZ_Cnat z phi : z \in Num.nat -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_nat. Qed.
Lemma cfAutZ_Cint z phi : z \in Num.int -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_int. Qed.
Lemma cfAutK : cancel (@cfAut gT G u) (cfAut (algC_invaut u)).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_autK. Qed.
Lemma cfAutVK : cancel (cfAut (algC_invaut u)) (@cfAut gT G u).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_invautK. Qed.
Lemma cfAut_inj : injective (@cfAut gT G u).
Proof. exact: can_inj cfAutK. Qed.
Lemma cfAut_eq1 phi : (cfAut u phi == 1) = (phi == 1).
Proof. by rewrite rmorph_eq1 //; apply: cfAut_inj. Qed.
Lemma support_cfAut phi : support phi^u =i support phi.
Proof. by move=> x; rewrite !inE cfunE fmorph_eq0. Qed.
Lemma map_cfAut_free S : cfAut_closed u S -> free S -> free (map (cfAut u) S).
Proof.
set Su := map _ S => sSuS freeS; have uniqS := free_uniq freeS.
have uniqSu: uniq Su by rewrite (map_inj_uniq cfAut_inj).
have{} sSuS: {subset Su <= S} by move=> _ /mapP[phi Sphi ->]; apply: sSuS.
have [|_ eqSuS] := uniq_min_size uniqSu sSuS; first by rewrite size_map.
by rewrite (perm_free (uniq_perm uniqSu uniqS eqSuS)).
Qed.
Lemma cfAut_on A phi : (phi^u \in 'CF(G, A)) = (phi \in 'CF(G, A)).
Proof. by rewrite !cfun_onE (eq_subset (support_cfAut phi)). Qed.
Lemma cfker_aut phi : cfker phi^u = cfker phi.
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
by apply/forallP/forallP=> Kx y;
have:= Kx y; rewrite !cfunE (inj_eq (fmorph_inj u)).
Qed.
Lemma cfAut_cfuni A : ('1_A)^u = '1_A :> 'CF(G).
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cforder_aut phi : #[phi^u]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfAut_inj. Qed.
Lemma cfAutRes phi : ('Res[H] phi)^u = 'Res phi^u.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutMorph (psi : 'CF(f @* H)) : (cfMorph psi)^u = cfMorph psi^u.
Proof. by apply/cfun_inP=> x Hx; rewrite !cfunElock Hx. Qed.
Lemma cfAutIsom (isoGR : isom G R f) phi :
(cfIsom isoGR phi)^u = cfIsom isoGR phi^u.
Proof.
apply/cfun_inP=> y; have [_ {1}<-] := isomP isoGR => /morphimP[x _ Gx ->{y}].
by rewrite !(cfunE, cfIsomE).
Qed.
Lemma cfAutQuo phi : (phi / H)^u = (phi^u / H)%CF.
Proof. by apply/cfunP=> Hx; rewrite !cfunElock cfker_aut rmorphMn. Qed.
Lemma cfAutMod (psi : 'CF(G / H)) : (psi %% H)^u = (psi^u %% H)%CF.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutInd (psi : 'CF(H)) : ('Ind[G] psi)^u = 'Ind psi^u.
Proof.
have [sHG | not_sHG] := boolP (H \subset G).
apply/cfunP=> x; rewrite !(cfunE, cfIndE) // rmorphM /= fmorphV rmorph_nat.
by congr (_ * _); rewrite rmorph_sum; apply: eq_bigr => y; rewrite !cfunE.
rewrite !cfIndEout // linearZ /= cfAut_cfuni rmorphM rmorph_nat /=.
rewrite -cfdot_cfAut ?rmorph1 // => _ /imageP[x Hx ->].
by rewrite cfun1E Hx !rmorph1.
Qed.
Hypothesis KxH : K \x H = G.
Lemma cfAutDprodl (phi : 'CF(K)) : (cfDprodl KxH phi)^u = cfDprodl KxH phi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEl).
Qed.
Lemma cfAutDprodr (psi : 'CF(H)) : (cfDprodr KxH psi)^u = cfDprodr KxH psi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEr).
Qed.
Lemma cfAutDprod (phi : 'CF(K)) (psi : 'CF(H)) :
(cfDprod KxH phi psi)^u = cfDprod KxH phi^u psi^u.
Proof. by rewrite rmorphM /= cfAutDprodl cfAutDprodr. Qed.
End FieldAutomorphism.
Arguments cfAutK u {gT G}.
Arguments cfAutVK u {gT G}.
Arguments cfAut_inj u {gT G} [phi1 phi2] : rename.
Definition conj_cfRes := cfAutRes conjC.
Definition cfker_conjC := cfker_aut conjC.
Definition conj_cfQuo := cfAutQuo conjC.
Definition conj_cfMod := cfAutMod conjC.
Definition conj_cfInd := cfAutInd conjC.
Definition cfconjC_eq1 := cfAut_eq1 conjC.
|
OrderDual.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.Synonym
import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual
import Mathlib.Algebra.Order.Monoid.Defs
/-! # Ordered monoid structures on the order dual. -/
universe u
variable {α : Type u}
open Function
namespace OrderDual
@[to_additive]
instance isOrderedMonoid [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α] :
IsOrderedMonoid αᵒᵈ :=
{ mul_le_mul_left := fun _ _ h c => mul_le_mul_left' h c }
@[to_additive]
instance isOrderedCancelMonoid [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] :
IsOrderedCancelMonoid αᵒᵈ :=
{ le_of_mul_le_mul_left := fun _ _ _ : α => le_of_mul_le_mul_left' }
end OrderDual
|
Semiconj.lean
|
/-
Copyright (c) 2024 Damien Thomine. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damien Thomine, Pietro Monticone
-/
import Mathlib.Dynamics.TopologicalEntropy.CoverEntropy
/-!
# Topological entropy of the image of a set under a semiconjugacy
Consider two dynamical systems `(X, S)` and `(Y, T)` together with a semiconjugacy `φ`:
```
X ---S--> X
| |
φ φ
| |
v v
Y ---T--> Y
```
We relate the topological entropy of a subset `F ⊆ X` with the topological entropy
of its image `φ '' F ⊆ Y`.
The best-known theorem is that, if all maps are uniformly continuous, then
`coverEntropy T (φ '' F) ≤ coverEntropy S F`. This is theorem
`coverEntropy_image_le_of_uniformContinuous` herein. We actually prove the much more general
statement that `coverEntropy T (φ '' F) = coverEntropy S F` if `X` is endowed with the pullback
by `φ` of the uniform structure of `Y`.
This more general statement has another direct consequence: if `F` is `S`-invariant, then the
topological entropy of the restriction of `S` to `F` is exactly `coverEntropy S F`. This
corollary is essential: in most references, the entropy of an invariant subset (or subsystem) `F` is
defined as the entropy of the restriction to `F` of the system. We chose instead to give a direct
definition of the topological entropy of a subset, so as to avoid working with subtypes. Theorem
`coverEntropy_restrict` shows that this choice is coherent with the literature.
## Implementation notes
We use only the definition of the topological entropy using covers; the simplest version of
`IsDynCoverOf.image` for nets fails.
## Main results
- `coverEntropy_image_of_comap`/`coverEntropyInf_image_of_comap`: the entropy of `φ '' F` equals
the entropy of `F` if `X` is endowed with the pullback by `φ` of the uniform structure of `Y`.
- `coverEntropy_image_le_of_uniformContinuous`/`coverEntropyInf_image_le_of_uniformContinuous`:
the entropy of `φ '' F` is lower than the entropy of `F` if `φ` is uniformly continuous.
- `coverEntropy_restrict`: the entropy of the restriction of `S` to an invariant set `F` is
`coverEntropy S F`.
## Tags
entropy, semiconjugacy
-/
namespace Dynamics
open Function Prod Set Uniformity UniformSpace
variable {X Y : Type*} {S : X → X} {T : Y → Y} {φ : X → Y}
lemma IsDynCoverOf.image (h : Semiconj φ S T) {F : Set X} {V : Set (Y × Y)} {n : ℕ} {s : Set X}
(h' : IsDynCoverOf S F ((map φ φ) ⁻¹' V) n s) :
IsDynCoverOf T (φ '' F) V n (φ '' s) := by
simp only [IsDynCoverOf, image_subset_iff, preimage_iUnion₂, biUnion_image]
refine h'.trans (iUnion₂_mono fun i _ ↦ subset_of_eq ?_)
rw [← h.preimage_dynEntourage V n, ball_preimage]
lemma IsDynCoverOf.preimage (h : Semiconj φ S T) {F : Set X} {V : Set (Y × Y)}
(V_symm : IsSymmetricRel V) {n : ℕ} {t : Finset Y} (h' : IsDynCoverOf T (φ '' F) V n t) :
∃ s : Finset X, IsDynCoverOf S F ((map φ φ) ⁻¹' (V ○ V)) n s ∧ s.card ≤ t.card := by
classical
rcases isEmpty_or_nonempty X with _ | _
· exact ⟨∅, eq_empty_of_isEmpty F ▸ ⟨isDynCoverOf_empty, Finset.card_empty ▸ zero_le t.card⟩⟩
-- If `t` is a dynamical cover of `φ '' F`, then we want to choose one preimage by `φ` for each
-- element of `t`. This is complicated by the fact that `t` may not be a subset of `φ '' F`,
-- and may not even be in the range of `φ`. Hence, we first modify `t` to make it a subset
-- of `φ '' F`. This requires taking larger entourages.
obtain ⟨s, s_cover, s_card, s_inter⟩ := h'.nonempty_inter
choose! g gs_cover using fun (x : Y) (h : x ∈ s) ↦ nonempty_def.1 (s_inter x h)
choose! f f_section using fun (y : Y) (a : y ∈ φ '' F) ↦ a
refine ⟨s.image (f ∘ g), ?_, Finset.card_image_le.trans s_card⟩
simp only [IsDynCoverOf, Finset.mem_coe, image_subset_iff, preimage_iUnion₂] at s_cover ⊢
apply s_cover.trans
rw [← h.preimage_dynEntourage (V ○ V) n, Finset.set_biUnion_finset_image]
refine iUnion₂_mono fun i i_s ↦ ?_
rw [comp_apply, ball_preimage, (f_section (g i) (gs_cover i i_s).2).2]
refine preimage_mono fun x x_i ↦ mem_ball_dynEntourage_comp T n V_symm x (g i) ⟨i, ?_⟩
replace gs_cover := (gs_cover i i_s).1
rw [mem_ball_symmetry (V_symm.dynEntourage T n)] at x_i gs_cover
exact ⟨x_i, gs_cover⟩
lemma le_coverMincard_image (h : Semiconj φ S T) (F : Set X) {V : Set (Y × Y)}
(V_symm : IsSymmetricRel V) (n : ℕ) :
coverMincard S F ((map φ φ) ⁻¹' (V ○ V)) n ≤ coverMincard T (φ '' F) V n := by
rcases eq_top_or_lt_top (coverMincard T (φ '' F) V n) with h' | h'
· exact h' ▸ le_top
obtain ⟨t, t_cover, t_card⟩ := (coverMincard_finite_iff T (φ '' F) V n).1 h'
obtain ⟨s, s_cover, s_card⟩ := t_cover.preimage h V_symm
rw [← t_card]
exact s_cover.coverMincard_le_card.trans (WithTop.coe_le_coe.2 s_card)
lemma coverMincard_image_le (h : Semiconj φ S T) (F : Set X) (V : Set (Y × Y)) (n : ℕ) :
coverMincard T (φ '' F) V n ≤ coverMincard S F ((map φ φ) ⁻¹' V) n := by
classical
rcases eq_top_or_lt_top (coverMincard S F ((map φ φ) ⁻¹' V) n) with h' | h'
· exact h' ▸ le_top
obtain ⟨s, s_cover, s_card⟩ := (coverMincard_finite_iff S F ((map φ φ) ⁻¹' V) n).1 h'
rw [← s_card]
have := s_cover.image h
rw [← s.coe_image] at this
exact this.coverMincard_le_card.trans (WithTop.coe_le_coe.2 s.card_image_le)
open ENNReal EReal ExpGrowth Filter
lemma le_coverEntropyEntourage_image (h : Semiconj φ S T) (F : Set X) {V : Set (Y × Y)}
(V_symm : IsSymmetricRel V) :
coverEntropyEntourage S F ((map φ φ) ⁻¹' (V ○ V)) ≤ coverEntropyEntourage T (φ '' F) V :=
expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (le_coverMincard_image h F V_symm n)
lemma le_coverEntropyInfEntourage_image (h : Semiconj φ S T) (F : Set X) {V : Set (Y × Y)}
(V_symm : IsSymmetricRel V) :
coverEntropyInfEntourage S F ((map φ φ) ⁻¹' (V ○ V)) ≤ coverEntropyInfEntourage T (φ '' F) V :=
expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (le_coverMincard_image h F V_symm n)
lemma coverEntropyEntourage_image_le (h : Semiconj φ S T) (F : Set X) (V : Set (Y × Y)) :
coverEntropyEntourage T (φ '' F) V ≤ coverEntropyEntourage S F ((map φ φ) ⁻¹' V) :=
expGrowthSup_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_image_le h F V n)
lemma coverEntropyInfEntourage_image_le (h : Semiconj φ S T) (F : Set X) (V : Set (Y × Y)) :
coverEntropyInfEntourage T (φ '' F) V ≤ coverEntropyInfEntourage S F ((map φ φ) ⁻¹' V) :=
expGrowthInf_monotone fun n ↦ ENat.toENNReal_mono (coverMincard_image_le h F V n)
/-- The entropy of `φ '' F` equals the entropy of `F` if `X` is endowed with the pullback by `φ`
of the uniform structure of `Y`. -/
theorem coverEntropy_image_of_comap (u : UniformSpace Y) {S : X → X} {T : Y → Y} {φ : X → Y}
(h : Semiconj φ S T) (F : Set X) :
coverEntropy T (φ '' F) = @coverEntropy X (comap φ u) S F := by
apply le_antisymm
· refine iSup₂_le fun V V_uni ↦ (coverEntropyEntourage_image_le h F V).trans ?_
apply @coverEntropyEntourage_le_coverEntropy X (comap φ u) S F
rw [uniformity_comap φ, mem_comap]
exact ⟨V, V_uni, Subset.rfl⟩
· refine iSup₂_le fun U U_uni ↦ ?_
simp only [uniformity_comap φ, mem_comap] at U_uni
obtain ⟨V, V_uni, V_sub⟩ := U_uni
obtain ⟨W, W_uni, W_symm, W_V⟩ := comp_symm_mem_uniformity_sets V_uni
apply (coverEntropyEntourage_antitone S F ((preimage_mono W_V).trans V_sub)).trans
apply (le_coverEntropyEntourage_image h F W_symm).trans
exact coverEntropyEntourage_le_coverEntropy T (φ '' F) W_uni
/-- The entropy of `φ '' F` equals the entropy of `F` if `X` is endowed with the pullback by `φ`
of the uniform structure of `Y`. This version uses a `liminf`. -/
theorem coverEntropyInf_image_of_comap (u : UniformSpace Y) {S : X → X} {T : Y → Y} {φ : X → Y}
(h : Semiconj φ S T) (F : Set X) :
coverEntropyInf T (φ '' F) = @coverEntropyInf X (comap φ u) S F := by
apply le_antisymm
· refine iSup₂_le fun V V_uni ↦ (coverEntropyInfEntourage_image_le h F V).trans ?_
apply @coverEntropyInfEntourage_le_coverEntropyInf X (comap φ u) S F
rw [uniformity_comap φ, mem_comap]
exact ⟨V, V_uni, Subset.rfl⟩
· refine iSup₂_le fun U U_uni ↦ ?_
simp only [uniformity_comap φ, mem_comap] at U_uni
obtain ⟨V, V_uni, V_sub⟩ := U_uni
obtain ⟨W, W_uni, W_symm, W_V⟩ := comp_symm_mem_uniformity_sets V_uni
apply (coverEntropyInfEntourage_antitone S F ((preimage_mono W_V).trans V_sub)).trans
apply (le_coverEntropyInfEntourage_image h F W_symm).trans
exact coverEntropyInfEntourage_le_coverEntropyInf T (φ '' F) W_uni
open Subtype
lemma coverEntropy_restrict_subset [UniformSpace X] {T : X → X} {F G : Set X} (hF : F ⊆ G)
(hG : MapsTo T G G) :
coverEntropy (hG.restrict T G G) (val ⁻¹' F) = coverEntropy T F := by
rw [← coverEntropy_image_of_comap _ hG.val_restrict_apply (val ⁻¹' F), image_preimage_coe G F,
inter_eq_right.2 hF]
lemma coverEntropyInf_restrict_subset [UniformSpace X] {T : X → X} {F G : Set X} (hF : F ⊆ G)
(hG : MapsTo T G G) :
coverEntropyInf (hG.restrict T G G) (val ⁻¹' F) = coverEntropyInf T F := by
rw [← coverEntropyInf_image_of_comap _ hG.val_restrict_apply (val ⁻¹' F), image_preimage_coe G F,
inter_eq_right.2 hF]
/-- The entropy of the restriction of `T` to an invariant set `F` is `coverEntropy S F`. This
theorem justifies our definition of `coverEntropy T F`. -/
theorem coverEntropy_restrict [UniformSpace X] {T : X → X} {F : Set X} (h : MapsTo T F F) :
coverEntropy (h.restrict T F F) univ = coverEntropy T F := by
rw [← coverEntropy_restrict_subset Subset.rfl h, coe_preimage_self F]
/-- The entropy of `φ '' F` is lower than entropy of `F` if `φ` is uniformly continuous. -/
theorem coverEntropy_image_le_of_uniformContinuous [UniformSpace X] [UniformSpace Y] {S : X → X}
{T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) (h' : UniformContinuous φ) (F : Set X) :
coverEntropy T (φ '' F) ≤ coverEntropy S F := by
rw [coverEntropy_image_of_comap _ h F]
exact coverEntropy_antitone S F (uniformContinuous_iff.1 h')
/-- The entropy of `φ '' F` is lower than entropy of `F` if `φ` is uniformly continuous. This
version uses a `liminf`. -/
theorem coverEntropyInf_image_le_of_uniformContinuous [UniformSpace X] [UniformSpace Y] {S : X → X}
{T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) (h' : UniformContinuous φ) (F : Set X) :
coverEntropyInf T (φ '' F) ≤ coverEntropyInf S F := by
rw [coverEntropyInf_image_of_comap _ h F]
exact coverEntropyInf_antitone S F (uniformContinuous_iff.1 h')
lemma coverEntropy_image_le_of_uniformContinuousOn_invariant [UniformSpace X] [UniformSpace Y]
{S : X → X} {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) {F G : Set X}
(h' : UniformContinuousOn φ G) (hF : F ⊆ G) (hG : MapsTo S G G) :
coverEntropy T (φ '' F) ≤ coverEntropy S F := by
rw [← coverEntropy_restrict_subset hF hG]
have hφ : Semiconj (G.restrict φ) (hG.restrict S G G) T := by
intro x
rw [G.restrict_apply, G.restrict_apply, hG.val_restrict_apply, h.eq x]
apply (coverEntropy_image_le_of_uniformContinuous hφ
(uniformContinuousOn_iff_restrict.1 h') (val ⁻¹' F)).trans_eq'
rw [← image_image_val_eq_restrict_image, image_preimage_coe G F, inter_eq_right.2 hF]
lemma coverEntropyInf_image_le_of_uniformContinuousOn_invariant [UniformSpace X] [UniformSpace Y]
{S : X → X} {T : Y → Y} {φ : X → Y} (h : Semiconj φ S T) {F G : Set X}
(h' : UniformContinuousOn φ G) (hF : F ⊆ G) (hG : MapsTo S G G) :
coverEntropyInf T (φ '' F) ≤ coverEntropyInf S F := by
rw [← coverEntropyInf_restrict_subset hF hG]
have hφ : Semiconj (G.restrict φ) (hG.restrict S G G) T := by
intro a
rw [G.restrict_apply, G.restrict_apply, hG.val_restrict_apply, h.eq a]
apply (coverEntropyInf_image_le_of_uniformContinuous hφ
(uniformContinuousOn_iff_restrict.1 h') (val ⁻¹' F)).trans_eq'
rw [← image_image_val_eq_restrict_image, image_preimage_coe G F, inter_eq_right.2 hF]
end Dynamics
|
all_character.v
|
From mathcomp Require Export character.
From mathcomp Require Export classfun.
From mathcomp Require Export inertia.
From mathcomp Require Export integral_char.
From mathcomp Require Export mxabelem.
From mathcomp Require Export mxrepresentation.
From mathcomp Require Export vcharacter.
|
NatCount.lean
|
/-
Copyright (c) 2021 Vladimir Goryachev. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Vladimir Goryachev
-/
import Mathlib.Data.Nat.Count
import Mathlib.Data.Set.Card
/-!
# Counting on ℕ
This file provides lemmas about the relation of `Nat.count` with cardinality functions.
-/
namespace Nat
open Nat Count
variable {p : ℕ → Prop} [DecidablePred p] (n : ℕ)
theorem count_le_cardinal : (count p n : Cardinal) ≤ Cardinal.mk { k | p k } := by
rw [count_eq_card_fintype, ← Cardinal.mk_fintype]
exact Cardinal.mk_subtype_mono fun x hx ↦ hx.2
theorem count_le_setENCard : count p n ≤ Set.encard { k | p k } := by
simp only [Set.encard, ENat.card, Set.coe_setOf, Cardinal.natCast_le_toENat_iff]
exact Nat.count_le_cardinal n
theorem count_le_setNCard (h : { k | p k }.Finite) : count p n ≤ Set.ncard { k | p k } := by
rw [Set.ncard_def, ← ENat.coe_le_coe, ENat.coe_toNat (by simpa)]
exact count_le_setENCard n
end Nat
|
fail_if_no_progress.lean
|
import Mathlib.Tactic.FailIfNoProgress
import Mathlib.Tactic.Basic
set_option linter.unusedVariables false
set_option linter.style.setOption false
set_option pp.unicode.fun true
section success
example : 1 = 1 := by fail_if_no_progress rfl
example (h : 1 = 1) : True := by
fail_if_no_progress simp at h
trivial
example : let x := 1; x = x := by
intro x
fail_if_no_progress clear_value x
rfl
-- New fvarids. This is not easily avoided without remapping fvarids manually.
example : let x := 1; x = x := by
intro x
fail_if_no_progress
revert x
intro x
rfl
open Lean Elab Tactic in
example : let x := id 0; x = x := by
intro x
fail_if_no_progress
-- Reduce the value of `x` to `Nat.zero`
run_tac do
let g ← getMainGoal
let decl ← g.getDecl
let some d := decl.lctx.findFromUserName? `x | throwError "no x"
let lctx := decl.lctx.modifyLocalDecl d.fvarId fun d =>
d.setValue (.const ``Nat.zero [])
let g' ← Meta.mkFreshExprMVarAt lctx decl.localInstances decl.type
g.assign g'
replaceMainGoal [g'.mvarId!]
guard_hyp x : Nat :=ₛ Nat.zero
rfl
end success
section failure
/--
error: no progress made on
x : Bool
h : x = true
⊢ x = true
-/
#guard_msgs in
example (x : Bool) (h : x = true) : x = true := by
fail_if_no_progress skip
/--
error: no progress made on
x : Bool
h : x = true
⊢ x = true
-/
#guard_msgs in
example (x : Bool) (h : x = true) : x = true := by
fail_if_no_progress simp -failIfUnchanged
/--
error: no progress made on
x : Bool
h : x = true
⊢ True
-/
#guard_msgs in
example (x : Bool) (h : x = true) : True := by
fail_if_no_progress simp -failIfUnchanged at h
/--
error: no progress made on
x : Nat := (fun x ↦ x) Nat.zero
⊢ x = x
-/
#guard_msgs in
open Lean Elab Tactic in
example : let x := (fun x => x) Nat.zero; x = x := by
intro x
fail_if_no_progress
-- Reduce the value of `x` to `Nat.zero`
run_tac do
let g ← getMainGoal
let decl ← g.getDecl
let some d := decl.lctx.findFromUserName? `x | throwError "no x"
let lctx := decl.lctx.modifyLocalDecl d.fvarId fun d =>
d.setValue (.const ``Nat.zero [])
let g' ← Meta.mkFreshExprMVarAt lctx decl.localInstances decl.type
g.assign g'
replaceMainGoal [g'.mvarId!]
guard_hyp x : Nat :=ₛ Nat.zero
end failure
|
Subperm.lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Batteries.Data.List.Perm
import Mathlib.Data.List.Basic
/-!
# List Sub-permutations
This file develops theory about the `List.Subperm` relation.
## Notation
The notation `<+~` is used for sub-permutations.
-/
open Nat
namespace List
variable {α : Type*} {l l₁ l₂ : List α} {a : α}
open Perm
section Subperm
attribute [trans] Subperm.trans
end Subperm
/-- See also `List.subperm_ext_iff`. -/
lemma subperm_iff_count [DecidableEq α] : l₁ <+~ l₂ ↔ ∀ a, count a l₁ ≤ count a l₂ :=
subperm_ext_iff.trans <| forall_congr' fun a ↦ by
by_cases ha : a ∈ l₁ <;> simp [ha, count_eq_zero_of_not_mem]
lemma subperm_iff : l₁ <+~ l₂ ↔ ∃ l, l ~ l₂ ∧ l₁ <+ l := by
refine ⟨?_, fun ⟨l, h₁, h₂⟩ ↦ h₂.subperm.trans h₁.subperm⟩
rintro ⟨l, h₁, h₂⟩
obtain ⟨l', h₂⟩ := h₂.exists_perm_append
exact ⟨l₁ ++ l', (h₂.trans (h₁.append_right _)).symm, (prefix_append _ _).sublist⟩
@[simp] lemma subperm_singleton_iff : l <+~ [a] ↔ l = [] ∨ l = [a] := by
constructor
· rw [subperm_iff]
rintro ⟨s, hla, h⟩
rwa [perm_singleton.mp hla, sublist_singleton] at h
· rintro (rfl | rfl)
exacts [nil_subperm, Subperm.refl _]
lemma subperm_cons_self : l <+~ a :: l := ⟨l, Perm.refl _, sublist_cons_self _ _⟩
protected alias ⟨subperm.of_cons, subperm.cons⟩ := subperm_cons
protected theorem Nodup.subperm (d : Nodup l₁) (H : l₁ ⊆ l₂) : l₁ <+~ l₂ :=
subperm_of_subset d H
end List
|
ssrbool.v
|
From mathcomp Require Import ssreflect ssrfun.
From Corelib Require Export ssrbool.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(**********************)
(* not yet backported *)
(**********************)
Lemma homo_mono1 [aT rT : Type] [f : aT -> rT] [g : rT -> aT]
[aP : pred aT] [rP : pred rT] :
cancel g f ->
{homo f : x / aP x >-> rP x} ->
{homo g : x / rP x >-> aP x} -> {mono g : x / rP x >-> aP x}.
Proof. by move=> gK fP gP x; apply/idP/idP => [/fP|/gP//]; rewrite gK. Qed.
Lemma if_and b1 b2 T (x y : T) :
(if b1 && b2 then x else y) = (if b1 then if b2 then x else y else y).
Proof. by case: b1 b2 => [] []. Qed.
Lemma if_or b1 b2 T (x y : T) :
(if b1 || b2 then x else y) = (if b1 then x else if b2 then x else y).
Proof. by case: b1 b2 => [] []. Qed.
Lemma if_implyb b1 b2 T (x y : T) :
(if b1 ==> b2 then x else y) = (if b1 then if b2 then x else y else x).
Proof. by case: b1 b2 => [] []. Qed.
Lemma if_implybC b1 b2 T (x y : T) :
(if b1 ==> b2 then x else y) = (if b2 then x else if b1 then y else x).
Proof. by case: b1 b2 => [] []. Qed.
Lemma if_add b1 b2 T (x y : T) :
(if b1 (+) b2 then x else y) = (if b1 then if b2 then y else x else if b2 then x else y).
Proof. by case: b1 b2 => [] []. Qed.
Lemma relpre_trans {T' T : Type} {leT : rel T} {f : T' -> T} :
transitive leT -> transitive (relpre f leT).
Proof. by move=> + y x z; apply. Qed.
|
SimpleFuncDenseLp.lean
|
/-
Copyright (c) 2022 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Heather Macbeth
-/
import Mathlib.MeasureTheory.Function.L1Space.AEEqFun
import Mathlib.MeasureTheory.Function.LpSpace.Complete
import Mathlib.MeasureTheory.Function.LpSpace.Indicator
/-!
# Density of simple functions
Show that each `Lᵖ` Borel measurable function can be approximated in `Lᵖ` norm
by a sequence of simple functions.
## Main definitions
* `MeasureTheory.Lp.simpleFunc`, the type of `Lp` simple functions
* `coeToLp`, the embedding of `Lp.simpleFunc E p μ` into `Lp E p μ`
## Main results
* `tendsto_approxOn_Lp_eLpNorm` (Lᵖ convergence): If `E` is a `NormedAddCommGroup` and `f` is
measurable and `MemLp` (for `p < ∞`), then the simple functions
`SimpleFunc.approxOn f hf s 0 h₀ n` may be considered as elements of `Lp E p μ`, and they tend
in Lᵖ to `f`.
* `Lp.simpleFunc.isDenseEmbedding`: the embedding `coeToLp` of the `Lp` simple functions into
`Lp` is dense.
* `Lp.simpleFunc.induction`, `Lp.induction`, `MemLp.induction`, `Integrable.induction`: to prove
a predicate for all elements of one of these classes of functions, it suffices to check that it
behaves correctly on simple functions.
## TODO
For `E` finite-dimensional, simple functions `α →ₛ E` are dense in L^∞ -- prove this.
## Notations
* `α →ₛ β` (local notation): the type of simple functions `α → β`.
* `α →₁ₛ[μ] E`: the type of `L1` simple functions `α → β`.
-/
noncomputable section
open Set Function Filter TopologicalSpace ENNReal EMetric Finset
open scoped Topology ENNReal MeasureTheory
variable {α β ι E F 𝕜 : Type*}
namespace MeasureTheory
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
/-! ### Lp approximation by simple functions -/
section Lp
variable [MeasurableSpace β] [MeasurableSpace E] [NormedAddCommGroup E] [NormedAddCommGroup F]
{q : ℝ} {p : ℝ≥0∞}
theorem nnnorm_approxOn_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E}
{y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (x : β) (n : ℕ) :
‖approxOn f hf s y₀ h₀ n x - f x‖₊ ≤ ‖f x - y₀‖₊ := by
have := edist_approxOn_le hf h₀ x n
rw [edist_comm y₀] at this
simp only [edist_nndist, nndist_eq_nnnorm] at this
exact mod_cast this
theorem norm_approxOn_y₀_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E}
{y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (x : β) (n : ℕ) :
‖approxOn f hf s y₀ h₀ n x - y₀‖ ≤ ‖f x - y₀‖ + ‖f x - y₀‖ := by
simpa [enorm, edist_eq_enorm_sub, ← ENNReal.coe_add, norm_sub_rev]
using edist_approxOn_y0_le hf h₀ x n
theorem norm_approxOn_zero_le [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f) {s : Set E}
(h₀ : (0 : E) ∈ s) [SeparableSpace s] (x : β) (n : ℕ) :
‖approxOn f hf s 0 h₀ n x‖ ≤ ‖f x‖ + ‖f x‖ := by
simpa [enorm, edist_eq_enorm_sub, ← ENNReal.coe_add, norm_sub_rev]
using edist_approxOn_y0_le hf h₀ x n
theorem tendsto_approxOn_Lp_eLpNorm [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f)
{s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] (hp_ne_top : p ≠ ∞) {μ : Measure β}
(hμ : ∀ᵐ x ∂μ, f x ∈ closure s) (hi : eLpNorm (fun x => f x - y₀) p μ < ∞) :
Tendsto (fun n => eLpNorm (⇑(approxOn f hf s y₀ h₀ n) - f) p μ) atTop (𝓝 0) := by
by_cases hp_zero : p = 0
· simpa only [hp_zero, eLpNorm_exponent_zero] using tendsto_const_nhds
have hp : 0 < p.toReal := toReal_pos hp_zero hp_ne_top
suffices Tendsto (fun n => ∫⁻ x, ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal ∂μ) atTop (𝓝 0) by
simp only [eLpNorm_eq_lintegral_rpow_enorm hp_zero hp_ne_top]
convert continuous_rpow_const.continuousAt.tendsto.comp this
simp [zero_rpow_of_pos (_root_.inv_pos.mpr hp)]
-- We simply check the conditions of the Dominated Convergence Theorem:
-- (1) The function "`p`-th power of distance between `f` and the approximation" is measurable
have hF_meas n : Measurable fun x => ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal := by
simpa only [← edist_eq_enorm_sub] using
(approxOn f hf s y₀ h₀ n).measurable_bind (fun y x => edist y (f x) ^ p.toReal) fun y =>
(measurable_edist_right.comp hf).pow_const p.toReal
-- (2) The functions "`p`-th power of distance between `f` and the approximation" are uniformly
-- bounded, at any given point, by `fun x => ‖f x - y₀‖ ^ p.toReal`
have h_bound n :
(fun x ↦ ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ^ p.toReal) ≤ᵐ[μ] (‖f · - y₀‖ₑ ^ p.toReal) :=
.of_forall fun x => rpow_le_rpow (coe_mono (nnnorm_approxOn_le hf h₀ x n)) toReal_nonneg
-- (3) The bounding function `fun x => ‖f x - y₀‖ ^ p.toReal` has finite integral
have h_fin : (∫⁻ a : β, ‖f a - y₀‖ₑ ^ p.toReal ∂μ) ≠ ⊤ :=
(lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_zero hp_ne_top hi).ne
-- (4) The functions "`p`-th power of distance between `f` and the approximation" tend pointwise
-- to zero
have h_lim :
∀ᵐ a : β ∂μ, Tendsto (‖approxOn f hf s y₀ h₀ · a - f a‖ₑ ^ p.toReal) atTop (𝓝 0) := by
filter_upwards [hμ] with a ha
have : Tendsto (fun n => (approxOn f hf s y₀ h₀ n) a - f a) atTop (𝓝 (f a - f a)) :=
(tendsto_approxOn hf h₀ ha).sub tendsto_const_nhds
convert continuous_rpow_const.continuousAt.tendsto.comp (tendsto_coe.mpr this.nnnorm)
simp [zero_rpow_of_pos hp]
-- Then we apply the Dominated Convergence Theorem
simpa using tendsto_lintegral_of_dominated_convergence _ hF_meas h_bound h_fin h_lim
theorem memLp_approxOn [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
(hf : MemLp f p μ) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s]
(hi₀ : MemLp (fun _ => y₀) p μ) (n : ℕ) : MemLp (approxOn f fmeas s y₀ h₀ n) p μ := by
refine ⟨(approxOn f fmeas s y₀ h₀ n).aestronglyMeasurable, ?_⟩
suffices eLpNorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ < ⊤ by
have : MemLp (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ :=
⟨(approxOn f fmeas s y₀ h₀ n - const β y₀).aestronglyMeasurable, this⟩
convert eLpNorm_add_lt_top this hi₀
ext x
simp
have hf' : MemLp (fun x => ‖f x - y₀‖) p μ := by
have h_meas : Measurable fun x => ‖f x - y₀‖ := by
simp only [← dist_eq_norm]
exact (continuous_id.dist continuous_const).measurable.comp fmeas
refine ⟨h_meas.aemeasurable.aestronglyMeasurable, ?_⟩
rw [eLpNorm_norm]
convert eLpNorm_add_lt_top hf hi₀.neg with x
simp [sub_eq_add_neg]
have : ∀ᵐ x ∂μ, ‖approxOn f fmeas s y₀ h₀ n x - y₀‖ ≤ ‖‖f x - y₀‖ + ‖f x - y₀‖‖ := by
filter_upwards with x
convert norm_approxOn_y₀_le fmeas h₀ x n using 1
rw [Real.norm_eq_abs, abs_of_nonneg]
positivity
calc
eLpNorm (fun x => approxOn f fmeas s y₀ h₀ n x - y₀) p μ ≤
eLpNorm (fun x => ‖f x - y₀‖ + ‖f x - y₀‖) p μ :=
eLpNorm_mono_ae this
_ < ⊤ := eLpNorm_add_lt_top hf' hf'
theorem tendsto_approxOn_range_Lp_eLpNorm [BorelSpace E] {f : β → E} (hp_ne_top : p ≠ ∞)
{μ : Measure β} (fmeas : Measurable f) [SeparableSpace (range f ∪ {0} : Set E)]
(hf : eLpNorm f p μ < ∞) :
Tendsto (fun n => eLpNorm (⇑(approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) - f) p μ)
atTop (𝓝 0) := by
refine tendsto_approxOn_Lp_eLpNorm fmeas _ hp_ne_top ?_ ?_
· filter_upwards with x using subset_closure (by simp)
· simpa using hf
theorem memLp_approxOn_range [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
[SeparableSpace (range f ∪ {0} : Set E)] (hf : MemLp f p μ) (n : ℕ) :
MemLp (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) p μ :=
memLp_approxOn fmeas hf (y₀ := 0) (by simp) MemLp.zero n
theorem tendsto_approxOn_range_Lp [BorelSpace E] {f : β → E} [hp : Fact (1 ≤ p)] (hp_ne_top : p ≠ ∞)
{μ : Measure β} (fmeas : Measurable f) [SeparableSpace (range f ∪ {0} : Set E)]
(hf : MemLp f p μ) :
Tendsto
(fun n =>
(memLp_approxOn_range fmeas hf n).toLp (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n))
atTop (𝓝 (hf.toLp f)) := by
simpa only [Lp.tendsto_Lp_iff_tendsto_eLpNorm''] using
tendsto_approxOn_range_Lp_eLpNorm hp_ne_top fmeas hf.2
/-- Any function in `ℒp` can be approximated by a simple function if `p < ∞`. -/
theorem _root_.MeasureTheory.MemLp.exists_simpleFunc_eLpNorm_sub_lt {E : Type*}
[NormedAddCommGroup E] {f : β → E} {μ : Measure β} (hf : MemLp f p μ) (hp_ne_top : p ≠ ∞)
{ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ g : β →ₛ E, eLpNorm (f - ⇑g) p μ < ε ∧ MemLp g p μ := by
borelize E
let f' := hf.1.mk f
rsuffices ⟨g, hg, g_mem⟩ : ∃ g : β →ₛ E, eLpNorm (f' - ⇑g) p μ < ε ∧ MemLp g p μ
· refine ⟨g, ?_, g_mem⟩
suffices eLpNorm (f - ⇑g) p μ = eLpNorm (f' - ⇑g) p μ by rwa [this]
apply eLpNorm_congr_ae
filter_upwards [hf.1.ae_eq_mk] with x hx
simpa only [Pi.sub_apply, sub_left_inj] using hx
have hf' : MemLp f' p μ := hf.ae_eq hf.1.ae_eq_mk
have f'meas : Measurable f' := hf.1.measurable_mk
have : SeparableSpace (range f' ∪ {0} : Set E) :=
StronglyMeasurable.separableSpace_range_union_singleton hf.1.stronglyMeasurable_mk
rcases ((tendsto_approxOn_range_Lp_eLpNorm hp_ne_top f'meas hf'.2).eventually <|
gt_mem_nhds hε.bot_lt).exists with ⟨n, hn⟩
rw [← eLpNorm_neg, neg_sub] at hn
exact ⟨_, hn, memLp_approxOn_range f'meas hf' _⟩
end Lp
/-! ### L1 approximation by simple functions -/
section Integrable
variable [MeasurableSpace β]
variable [MeasurableSpace E] [NormedAddCommGroup E]
theorem tendsto_approxOn_L1_enorm [OpensMeasurableSpace E] {f : β → E} (hf : Measurable f)
{s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s] {μ : Measure β}
(hμ : ∀ᵐ x ∂μ, f x ∈ closure s) (hi : HasFiniteIntegral (fun x => f x - y₀) μ) :
Tendsto (fun n => ∫⁻ x, ‖approxOn f hf s y₀ h₀ n x - f x‖ₑ ∂μ) atTop (𝓝 0) := by
simpa [eLpNorm_one_eq_lintegral_enorm] using
tendsto_approxOn_Lp_eLpNorm hf h₀ one_ne_top hμ
(by simpa [eLpNorm_one_eq_lintegral_enorm] using hi)
theorem integrable_approxOn [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
(hf : Integrable f μ) {s : Set E} {y₀ : E} (h₀ : y₀ ∈ s) [SeparableSpace s]
(hi₀ : Integrable (fun _ => y₀) μ) (n : ℕ) : Integrable (approxOn f fmeas s y₀ h₀ n) μ := by
rw [← memLp_one_iff_integrable] at hf hi₀ ⊢
exact memLp_approxOn fmeas hf h₀ hi₀ n
theorem tendsto_approxOn_range_L1_enorm [OpensMeasurableSpace E] {f : β → E} {μ : Measure β}
[SeparableSpace (range f ∪ {0} : Set E)] (fmeas : Measurable f) (hf : Integrable f μ) :
Tendsto (fun n => ∫⁻ x, ‖approxOn f fmeas (range f ∪ {0}) 0 (by simp) n x - f x‖ₑ ∂μ) atTop
(𝓝 0) := by
apply tendsto_approxOn_L1_enorm fmeas
· filter_upwards with x using subset_closure (by simp)
· simpa using hf.2
theorem integrable_approxOn_range [BorelSpace E] {f : β → E} {μ : Measure β} (fmeas : Measurable f)
[SeparableSpace (range f ∪ {0} : Set E)] (hf : Integrable f μ) (n : ℕ) :
Integrable (approxOn f fmeas (range f ∪ {0}) 0 (by simp) n) μ :=
integrable_approxOn fmeas hf _ (integrable_zero _ _ _) n
end Integrable
section SimpleFuncProperties
variable [MeasurableSpace α]
variable [NormedAddCommGroup E] [NormedAddCommGroup F]
variable {μ : Measure α} {p : ℝ≥0∞}
/-!
### Properties of simple functions in `Lp` spaces
A simple function `f : α →ₛ E` into a normed group `E` verifies, for a measure `μ`:
- `MemLp f 0 μ` and `MemLp f ∞ μ`, since `f` is a.e.-measurable and bounded,
- for `0 < p < ∞`,
`MemLp f p μ ↔ Integrable f μ ↔ f.FinMeasSupp μ ↔ ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞`.
-/
theorem exists_forall_norm_le (f : α →ₛ F) : ∃ C, ∀ x, ‖f x‖ ≤ C :=
exists_forall_le (f.map fun x => ‖x‖)
theorem memLp_zero (f : α →ₛ E) (μ : Measure α) : MemLp f 0 μ :=
memLp_zero_iff_aestronglyMeasurable.mpr f.aestronglyMeasurable
theorem memLp_top (f : α →ₛ E) (μ : Measure α) : MemLp f ∞ μ :=
let ⟨C, hfC⟩ := f.exists_forall_norm_le
memLp_top_of_bound f.aestronglyMeasurable C <| Eventually.of_forall hfC
protected theorem eLpNorm'_eq {p : ℝ} (f : α →ₛ F) (μ : Measure α) :
eLpNorm' f p μ = (∑ y ∈ f.range, ‖y‖ₑ ^ p * μ (f ⁻¹' {y})) ^ (1 / p) := by
have h_map : (‖f ·‖ₑ ^ p) = f.map (‖·‖ₑ ^ p) := by simp; rfl
rw [eLpNorm'_eq_lintegral_enorm, h_map, lintegral_eq_lintegral, map_lintegral]
theorem measure_preimage_lt_top_of_memLp (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) (f : α →ₛ E)
(hf : MemLp f p μ) (y : E) (hy_ne : y ≠ 0) : μ (f ⁻¹' {y}) < ∞ := by
have hp_pos_real : 0 < p.toReal := ENNReal.toReal_pos hp_pos hp_ne_top
have hf_eLpNorm := MemLp.eLpNorm_lt_top hf
rw [eLpNorm_eq_eLpNorm' hp_pos hp_ne_top, f.eLpNorm'_eq, one_div,
← @ENNReal.lt_rpow_inv_iff _ _ p.toReal⁻¹ (by simp [hp_pos_real]),
@ENNReal.top_rpow_of_pos p.toReal⁻¹⁻¹ (by simp [hp_pos_real]),
ENNReal.sum_lt_top] at hf_eLpNorm
by_cases hyf : y ∈ f.range
swap
· suffices h_empty : f ⁻¹' {y} = ∅ by
rw [h_empty, measure_empty]; exact ENNReal.coe_lt_top
ext1 x
rw [Set.mem_preimage, Set.mem_singleton_iff, mem_empty_iff_false, iff_false]
refine fun hxy => hyf ?_
rw [mem_range, Set.mem_range]
exact ⟨x, hxy⟩
specialize hf_eLpNorm y hyf
rw [ENNReal.mul_lt_top_iff] at hf_eLpNorm
cases hf_eLpNorm with
| inl hf_eLpNorm => exact hf_eLpNorm.2
| inr hf_eLpNorm =>
cases hf_eLpNorm with
| inl hf_eLpNorm =>
refine absurd ?_ hy_ne
simpa [hp_pos_real] using hf_eLpNorm
| inr hf_eLpNorm => simp [hf_eLpNorm]
theorem memLp_of_finite_measure_preimage (p : ℝ≥0∞) {f : α →ₛ E}
(hf : ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞) : MemLp f p μ := by
by_cases hp0 : p = 0
· rw [hp0, memLp_zero_iff_aestronglyMeasurable]; exact f.aestronglyMeasurable
by_cases hp_top : p = ∞
· rw [hp_top]; exact memLp_top f μ
refine ⟨f.aestronglyMeasurable, ?_⟩
rw [eLpNorm_eq_eLpNorm' hp0 hp_top, f.eLpNorm'_eq]
refine ENNReal.rpow_lt_top_of_nonneg (by simp) (ENNReal.sum_lt_top.mpr fun y _ => ?_).ne
by_cases hy0 : y = 0
· simp [hy0, ENNReal.toReal_pos hp0 hp_top]
· refine ENNReal.mul_lt_top ?_ (hf y hy0)
exact ENNReal.rpow_lt_top_of_nonneg ENNReal.toReal_nonneg ENNReal.coe_ne_top
theorem memLp_iff {f : α →ₛ E} (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp f p μ ↔ ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞ :=
⟨fun h => measure_preimage_lt_top_of_memLp hp_pos hp_ne_top f h, fun h =>
memLp_of_finite_measure_preimage p h⟩
theorem integrable_iff {f : α →ₛ E} : Integrable f μ ↔ ∀ y, y ≠ 0 → μ (f ⁻¹' {y}) < ∞ :=
memLp_one_iff_integrable.symm.trans <| memLp_iff one_ne_zero ENNReal.coe_ne_top
theorem memLp_iff_integrable {f : α →ₛ E} (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp f p μ ↔ Integrable f μ :=
(memLp_iff hp_pos hp_ne_top).trans integrable_iff.symm
theorem memLp_iff_finMeasSupp {f : α →ₛ E} (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) :
MemLp f p μ ↔ f.FinMeasSupp μ :=
(memLp_iff hp_pos hp_ne_top).trans finMeasSupp_iff.symm
theorem integrable_iff_finMeasSupp {f : α →ₛ E} : Integrable f μ ↔ f.FinMeasSupp μ :=
integrable_iff.trans finMeasSupp_iff.symm
theorem FinMeasSupp.integrable {f : α →ₛ E} (h : f.FinMeasSupp μ) : Integrable f μ :=
integrable_iff_finMeasSupp.2 h
theorem integrable_pair {f : α →ₛ E} {g : α →ₛ F} :
Integrable f μ → Integrable g μ → Integrable (pair f g) μ := by
simpa only [integrable_iff_finMeasSupp] using FinMeasSupp.pair
theorem memLp_of_isFiniteMeasure (f : α →ₛ E) (p : ℝ≥0∞) (μ : Measure α) [IsFiniteMeasure μ] :
MemLp f p μ :=
let ⟨C, hfC⟩ := f.exists_forall_norm_le
MemLp.of_bound f.aestronglyMeasurable C <| Eventually.of_forall hfC
@[fun_prop]
theorem integrable_of_isFiniteMeasure [IsFiniteMeasure μ] (f : α →ₛ E) : Integrable f μ :=
memLp_one_iff_integrable.mp (f.memLp_of_isFiniteMeasure 1 μ)
theorem measure_preimage_lt_top_of_integrable (f : α →ₛ E) (hf : Integrable f μ) {x : E}
(hx : x ≠ 0) : μ (f ⁻¹' {x}) < ∞ :=
integrable_iff.mp hf x hx
theorem measure_support_lt_top_of_memLp (f : α →ₛ E) (hf : MemLp f p μ) (hp_ne_zero : p ≠ 0)
(hp_ne_top : p ≠ ∞) : μ (support f) < ∞ :=
f.measure_support_lt_top ((memLp_iff hp_ne_zero hp_ne_top).mp hf)
theorem measure_support_lt_top_of_integrable (f : α →ₛ E) (hf : Integrable f μ) :
μ (support f) < ∞ :=
f.measure_support_lt_top (integrable_iff.mp hf)
theorem measure_lt_top_of_memLp_indicator (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) {c : E} (hc : c ≠ 0)
{s : Set α} (hs : MeasurableSet s) (hcs : MemLp ((const α c).piecewise s hs (const α 0)) p μ) :
μ s < ⊤ := by
have : Function.support (const α c) = Set.univ := Function.support_const hc
simpa only [memLp_iff_finMeasSupp hp_pos hp_ne_top, finMeasSupp_iff_support,
support_indicator, Set.inter_univ, this] using hcs
end SimpleFuncProperties
end SimpleFunc
/-! Construction of the space of `Lp` simple functions, and its dense embedding into `Lp`. -/
namespace Lp
open AEEqFun
variable [MeasurableSpace α] [NormedAddCommGroup E] [NormedAddCommGroup F] (p : ℝ≥0∞)
(μ : Measure α)
variable (E)
/-- `Lp.simpleFunc` is a subspace of Lp consisting of equivalence classes of an integrable simple
function. -/
def simpleFunc : AddSubgroup (Lp E p μ) where
carrier := { f : Lp E p μ | ∃ s : α →ₛ E, (AEEqFun.mk s s.aestronglyMeasurable : α →ₘ[μ] E) = f }
zero_mem' := ⟨0, rfl⟩
add_mem' := by
rintro f g ⟨s, hs⟩ ⟨t, ht⟩
use s + t
simp only [← hs, ← ht, AEEqFun.mk_add_mk, AddSubgroup.coe_add,
SimpleFunc.coe_add]
neg_mem' := by
rintro f ⟨s, hs⟩
use -s
simp only [← hs, AEEqFun.neg_mk, SimpleFunc.coe_neg, AddSubgroup.coe_neg]
variable {E p μ}
namespace simpleFunc
section Instances
/-! Simple functions in Lp space form a `NormedSpace`. -/
protected theorem eq' {f g : Lp.simpleFunc E p μ} : (f : α →ₘ[μ] E) = (g : α →ₘ[μ] E) → f = g :=
Subtype.eq ∘ Subtype.eq
/-! Implementation note: If `Lp.simpleFunc E p μ` were defined as a `𝕜`-submodule of `Lp E p μ`,
then the next few lemmas, putting a normed `𝕜`-group structure on `Lp.simpleFunc E p μ`, would be
unnecessary. But instead, `Lp.simpleFunc E p μ` is defined as an `AddSubgroup` of `Lp E p μ`,
which does not permit this (but has the advantage of working when `E` itself is a normed group,
i.e. has no scalar action). -/
variable [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
/-- If `E` is a normed space, `Lp.simpleFunc E p μ` is a `SMul`. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def smul : SMul 𝕜 (Lp.simpleFunc E p μ) :=
⟨fun k f =>
⟨k • (f : Lp E p μ), by
rcases f with ⟨f, ⟨s, hs⟩⟩
use k • s
apply Eq.trans (AEEqFun.smul_mk k s s.aestronglyMeasurable).symm _
rw [hs]
rfl⟩⟩
attribute [local instance] simpleFunc.smul
@[simp, norm_cast]
theorem coe_smul (c : 𝕜) (f : Lp.simpleFunc E p μ) :
((c • f : Lp.simpleFunc E p μ) : Lp E p μ) = c • (f : Lp E p μ) :=
rfl
/-- If `E` is a normed space, `Lp.simpleFunc E p μ` is a module. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def module : Module 𝕜 (Lp.simpleFunc E p μ) where
one_smul f := by ext1; exact one_smul _ _
mul_smul x y f := by ext1; exact mul_smul _ _ _
smul_add x f g := by ext1; exact smul_add _ _ _
smul_zero x := by ext1; exact smul_zero _
add_smul x y f := by ext1; exact add_smul _ _ _
zero_smul f := by ext1; exact zero_smul _ _
attribute [local instance] simpleFunc.module
/-- If `E` is a normed space, `Lp.simpleFunc E p μ` is a normed space. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected theorem isBoundedSMul [Fact (1 ≤ p)] : IsBoundedSMul 𝕜 (Lp.simpleFunc E p μ) :=
IsBoundedSMul.of_norm_smul_le fun r f => (norm_smul_le r (f : Lp E p μ) :)
@[deprecated (since := "2025-03-10")] protected alias boundedSMul := simpleFunc.isBoundedSMul
attribute [local instance] simpleFunc.isBoundedSMul
/-- If `E` is a normed space, `Lp.simpleFunc E p μ` is a normed space. Not declared as an
instance as it is (as of writing) used only in the construction of the Bochner integral. -/
protected def normedSpace {𝕜} [NormedField 𝕜] [NormedSpace 𝕜 E] [Fact (1 ≤ p)] :
NormedSpace 𝕜 (Lp.simpleFunc E p μ) :=
⟨norm_smul_le (α := 𝕜) (β := Lp.simpleFunc E p μ)⟩
end Instances
attribute [local instance] simpleFunc.module simpleFunc.normedSpace simpleFunc.isBoundedSMul
section ToLp
/-- Construct the equivalence class `[f]` of a simple function `f` satisfying `MemLp`. -/
abbrev toLp (f : α →ₛ E) (hf : MemLp f p μ) : Lp.simpleFunc E p μ :=
⟨hf.toLp f, ⟨f, rfl⟩⟩
theorem toLp_eq_toLp (f : α →ₛ E) (hf : MemLp f p μ) : (toLp f hf : Lp E p μ) = hf.toLp f :=
rfl
theorem toLp_eq_mk (f : α →ₛ E) (hf : MemLp f p μ) :
(toLp f hf : α →ₘ[μ] E) = AEEqFun.mk f f.aestronglyMeasurable :=
rfl
theorem toLp_zero : toLp (0 : α →ₛ E) MemLp.zero = (0 : Lp.simpleFunc E p μ) :=
rfl
theorem toLp_add (f g : α →ₛ E) (hf : MemLp f p μ) (hg : MemLp g p μ) :
toLp (f + g) (hf.add hg) = toLp f hf + toLp g hg :=
rfl
theorem toLp_neg (f : α →ₛ E) (hf : MemLp f p μ) : toLp (-f) hf.neg = -toLp f hf :=
rfl
theorem toLp_sub (f g : α →ₛ E) (hf : MemLp f p μ) (hg : MemLp g p μ) :
toLp (f - g) (hf.sub hg) = toLp f hf - toLp g hg := by
simp only [sub_eq_add_neg, ← toLp_neg, ← toLp_add]
variable [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
theorem toLp_smul (f : α →ₛ E) (hf : MemLp f p μ) (c : 𝕜) :
toLp (c • f) (hf.const_smul c) = c • toLp f hf :=
rfl
nonrec theorem norm_toLp [Fact (1 ≤ p)] (f : α →ₛ E) (hf : MemLp f p μ) :
‖toLp f hf‖ = ENNReal.toReal (eLpNorm f p μ) :=
norm_toLp f hf
end ToLp
section ToSimpleFunc
/-- Find a representative of a `Lp.simpleFunc`. -/
def toSimpleFunc (f : Lp.simpleFunc E p μ) : α →ₛ E :=
Classical.choose f.2
/-- `(toSimpleFunc f)` is measurable. -/
@[measurability]
protected theorem measurable [MeasurableSpace E] (f : Lp.simpleFunc E p μ) :
Measurable (toSimpleFunc f) :=
(toSimpleFunc f).measurable
protected theorem stronglyMeasurable (f : Lp.simpleFunc E p μ) :
StronglyMeasurable (toSimpleFunc f) :=
(toSimpleFunc f).stronglyMeasurable
@[measurability]
protected theorem aemeasurable [MeasurableSpace E] (f : Lp.simpleFunc E p μ) :
AEMeasurable (toSimpleFunc f) μ :=
(simpleFunc.measurable f).aemeasurable
protected theorem aestronglyMeasurable (f : Lp.simpleFunc E p μ) :
AEStronglyMeasurable (toSimpleFunc f) μ :=
(simpleFunc.stronglyMeasurable f).aestronglyMeasurable
theorem toSimpleFunc_eq_toFun (f : Lp.simpleFunc E p μ) : toSimpleFunc f =ᵐ[μ] f :=
show ⇑(toSimpleFunc f) =ᵐ[μ] ⇑(f : α →ₘ[μ] E) by
convert (AEEqFun.coeFn_mk (toSimpleFunc f)
(toSimpleFunc f).aestronglyMeasurable).symm using 2
exact (Classical.choose_spec f.2).symm
/-- `toSimpleFunc f` satisfies the predicate `MemLp`. -/
protected theorem memLp (f : Lp.simpleFunc E p μ) : MemLp (toSimpleFunc f) p μ :=
MemLp.ae_eq (toSimpleFunc_eq_toFun f).symm <| mem_Lp_iff_memLp.mp (f : Lp E p μ).2
theorem toLp_toSimpleFunc (f : Lp.simpleFunc E p μ) :
toLp (toSimpleFunc f) (simpleFunc.memLp f) = f :=
simpleFunc.eq' (Classical.choose_spec f.2)
theorem toSimpleFunc_toLp (f : α →ₛ E) (hfi : MemLp f p μ) : toSimpleFunc (toLp f hfi) =ᵐ[μ] f := by
rw [← AEEqFun.mk_eq_mk]; exact Classical.choose_spec (toLp f hfi).2
variable (E μ)
theorem zero_toSimpleFunc : toSimpleFunc (0 : Lp.simpleFunc E p μ) =ᵐ[μ] 0 := by
filter_upwards [toSimpleFunc_eq_toFun (0 : Lp.simpleFunc E p μ),
Lp.coeFn_zero E 1 μ] with _ h₁ _
rwa [h₁]
variable {E μ}
theorem add_toSimpleFunc (f g : Lp.simpleFunc E p μ) :
toSimpleFunc (f + g) =ᵐ[μ] toSimpleFunc f + toSimpleFunc g := by
filter_upwards [toSimpleFunc_eq_toFun (f + g), toSimpleFunc_eq_toFun f,
toSimpleFunc_eq_toFun g, Lp.coeFn_add (f : Lp E p μ) g] with _
simp only [AddSubgroup.coe_add, Pi.add_apply]
iterate 4 intro h; rw [h]
theorem neg_toSimpleFunc (f : Lp.simpleFunc E p μ) : toSimpleFunc (-f) =ᵐ[μ] -toSimpleFunc f := by
filter_upwards [toSimpleFunc_eq_toFun (-f), toSimpleFunc_eq_toFun f,
Lp.coeFn_neg (f : Lp E p μ)] with _
simp only [Pi.neg_apply, AddSubgroup.coe_neg]
repeat intro h; rw [h]
theorem sub_toSimpleFunc (f g : Lp.simpleFunc E p μ) :
toSimpleFunc (f - g) =ᵐ[μ] toSimpleFunc f - toSimpleFunc g := by
filter_upwards [toSimpleFunc_eq_toFun (f - g), toSimpleFunc_eq_toFun f,
toSimpleFunc_eq_toFun g, Lp.coeFn_sub (f : Lp E p μ) g] with _
simp only [AddSubgroup.coe_sub, Pi.sub_apply]
repeat' intro h; rw [h]
variable [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
theorem smul_toSimpleFunc (k : 𝕜) (f : Lp.simpleFunc E p μ) :
toSimpleFunc (k • f) =ᵐ[μ] k • ⇑(toSimpleFunc f) := by
filter_upwards [toSimpleFunc_eq_toFun (k • f), toSimpleFunc_eq_toFun f,
Lp.coeFn_smul k (f : Lp E p μ)] with _
simp only [Pi.smul_apply, coe_smul]
repeat intro h; rw [h]
theorem norm_toSimpleFunc [Fact (1 ≤ p)] (f : Lp.simpleFunc E p μ) :
‖f‖ = ENNReal.toReal (eLpNorm (toSimpleFunc f) p μ) := by
simpa [toLp_toSimpleFunc] using norm_toLp (toSimpleFunc f) (simpleFunc.memLp f)
end ToSimpleFunc
section Induction
variable (p) in
/-- The characteristic function of a finite-measure measurable set `s`, as an `Lp` simple function.
-/
def indicatorConst {s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) :
Lp.simpleFunc E p μ :=
toLp ((SimpleFunc.const _ c).piecewise s hs (SimpleFunc.const _ 0))
(memLp_indicator_const p hs c (Or.inr hμs))
@[simp]
theorem coe_indicatorConst {s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) :
(↑(indicatorConst p hs hμs c) : Lp E p μ) = indicatorConstLp p hs hμs c :=
rfl
theorem toSimpleFunc_indicatorConst {s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) :
toSimpleFunc (indicatorConst p hs hμs c) =ᵐ[μ]
(SimpleFunc.const _ c).piecewise s hs (SimpleFunc.const _ 0) :=
Lp.simpleFunc.toSimpleFunc_toLp _ _
/-- To prove something for an arbitrary `Lp` simple function, with `0 < p < ∞`, it suffices to show
that the property holds for (multiples of) characteristic functions of finite-measure measurable
sets and is closed under addition (of functions with disjoint support). -/
@[elab_as_elim]
protected theorem induction (hp_pos : p ≠ 0) (hp_ne_top : p ≠ ∞) {P : Lp.simpleFunc E p μ → Prop}
(indicatorConst :
∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : μ s < ∞),
P (Lp.simpleFunc.indicatorConst p hs hμs.ne c))
(add :
∀ ⦃f g : α →ₛ E⦄,
∀ hf : MemLp f p μ,
∀ hg : MemLp g p μ,
Disjoint (support f) (support g) →
P (Lp.simpleFunc.toLp f hf) →
P (Lp.simpleFunc.toLp g hg) → P (Lp.simpleFunc.toLp f hf + Lp.simpleFunc.toLp g hg))
(f : Lp.simpleFunc E p μ) : P f := by
suffices ∀ f : α →ₛ E, ∀ hf : MemLp f p μ, P (toLp f hf) by
rw [← toLp_toSimpleFunc f]
apply this
clear f
apply SimpleFunc.induction
· intro c s hs hf
by_cases hc : c = 0
· convert indicatorConst 0 MeasurableSet.empty (by simp) using 1
ext1
simp [hc]
exact indicatorConst c hs
(SimpleFunc.measure_lt_top_of_memLp_indicator hp_pos hp_ne_top hc hs hf)
· intro f g hfg hf hg hfg'
obtain ⟨hf', hg'⟩ : MemLp f p μ ∧ MemLp g p μ :=
(memLp_add_of_disjoint hfg f.stronglyMeasurable g.stronglyMeasurable).mp hfg'
exact add hf' hg' hfg (hf hf') (hg hg')
end Induction
section CoeToLp
variable [Fact (1 ≤ p)]
protected theorem uniformContinuous : UniformContinuous ((↑) : Lp.simpleFunc E p μ → Lp E p μ) :=
uniformContinuous_comap
lemma isUniformEmbedding : IsUniformEmbedding ((↑) : Lp.simpleFunc E p μ → Lp E p μ) :=
isUniformEmbedding_comap Subtype.val_injective
theorem isUniformInducing : IsUniformInducing ((↑) : Lp.simpleFunc E p μ → Lp E p μ) :=
simpleFunc.isUniformEmbedding.isUniformInducing
lemma isDenseEmbedding (hp_ne_top : p ≠ ∞) :
IsDenseEmbedding ((↑) : Lp.simpleFunc E p μ → Lp E p μ) := by
borelize E
apply simpleFunc.isUniformEmbedding.isDenseEmbedding
intro f
rw [mem_closure_iff_seq_limit]
have hfi' : MemLp f p μ := Lp.memLp f
haveI : SeparableSpace (range f ∪ {0} : Set E) :=
(Lp.stronglyMeasurable f).separableSpace_range_union_singleton
refine
⟨fun n =>
toLp
(SimpleFunc.approxOn f (Lp.stronglyMeasurable f).measurable (range f ∪ {0}) 0 _ n)
(SimpleFunc.memLp_approxOn_range (Lp.stronglyMeasurable f).measurable hfi' n),
fun n => mem_range_self _, ?_⟩
convert SimpleFunc.tendsto_approxOn_range_Lp hp_ne_top (Lp.stronglyMeasurable f).measurable hfi'
rw [toLp_coeFn f (Lp.memLp f)]
protected theorem isDenseInducing (hp_ne_top : p ≠ ∞) :
IsDenseInducing ((↑) : Lp.simpleFunc E p μ → Lp E p μ) :=
(simpleFunc.isDenseEmbedding hp_ne_top).isDenseInducing
protected theorem denseRange (hp_ne_top : p ≠ ∞) :
DenseRange ((↑) : Lp.simpleFunc E p μ → Lp E p μ) :=
(simpleFunc.isDenseInducing hp_ne_top).dense
protected theorem dense (hp_ne_top : p ≠ ∞) : Dense (Lp.simpleFunc E p μ : Set (Lp E p μ)) := by
simpa only [denseRange_subtype_val] using simpleFunc.denseRange (E := E) (μ := μ) hp_ne_top
variable [NormedRing 𝕜] [Module 𝕜 E] [IsBoundedSMul 𝕜 E]
variable (α E 𝕜)
/-- The embedding of Lp simple functions into Lp functions, as a continuous linear map. -/
def coeToLp : Lp.simpleFunc E p μ →L[𝕜] Lp E p μ :=
{ AddSubgroup.subtype (Lp.simpleFunc E p μ) with
map_smul' := fun _ _ => rfl
cont := Lp.simpleFunc.uniformContinuous.continuous }
variable {α E 𝕜}
end CoeToLp
section Order
variable {G : Type*} [NormedAddCommGroup G]
theorem coeFn_le [PartialOrder G] (f g : Lp.simpleFunc G p μ) : (f : α → G) ≤ᵐ[μ] g ↔ f ≤ g := by
rw [← Subtype.coe_le_coe, ← Lp.coeFn_le]
instance instAddLeftMono [PartialOrder G] [IsOrderedAddMonoid G] :
AddLeftMono (Lp.simpleFunc G p μ) := by
refine ⟨fun f g₁ g₂ hg₁₂ => ?_⟩
exact add_le_add_left hg₁₂ f
variable (p μ G)
theorem coeFn_zero : (0 : Lp.simpleFunc G p μ) =ᵐ[μ] (0 : α → G) :=
Lp.coeFn_zero _ _ _
variable {p μ G}
variable [PartialOrder G]
theorem coeFn_nonneg (f : Lp.simpleFunc G p μ) : (0 : α → G) ≤ᵐ[μ] f ↔ 0 ≤ f := by
rw [← Subtype.coe_le_coe, Lp.coeFn_nonneg, AddSubmonoid.coe_zero]
theorem exists_simpleFunc_nonneg_ae_eq {f : Lp.simpleFunc G p μ} (hf : 0 ≤ f) :
∃ f' : α →ₛ G, 0 ≤ f' ∧ f =ᵐ[μ] f' := by
rcases f with ⟨⟨f, hp⟩, g, (rfl : _ = f)⟩
change 0 ≤ᵐ[μ] g at hf
classical
refine ⟨g.map ({x : G | 0 ≤ x}.piecewise id 0), fun x ↦ ?_, (AEEqFun.coeFn_mk _ _).trans ?_⟩
· simpa using Set.indicator_apply_nonneg id
· filter_upwards [hf] with x (hx : 0 ≤ g x)
simpa using Set.indicator_of_mem hx id |>.symm
variable (p μ G)
/-- Coercion from nonnegative simple functions of Lp to nonnegative functions of Lp. -/
def coeSimpleFuncNonnegToLpNonneg :
{ g : Lp.simpleFunc G p μ // 0 ≤ g } → { g : Lp G p μ // 0 ≤ g } := fun g => ⟨g, g.2⟩
theorem denseRange_coeSimpleFuncNonnegToLpNonneg [hp : Fact (1 ≤ p)] (hp_ne_top : p ≠ ∞) :
DenseRange (coeSimpleFuncNonnegToLpNonneg p μ G) := fun g ↦ by
borelize G
rw [mem_closure_iff_seq_limit]
have hg_memLp : MemLp (g : α → G) p μ := Lp.memLp (g : Lp G p μ)
have zero_mem : (0 : G) ∈ (range (g : α → G) ∪ {0} : Set G) ∩ { y | 0 ≤ y } := by
simp only [union_singleton, mem_inter_iff, mem_insert_iff, true_or,
mem_setOf_eq, le_refl, and_self_iff]
have : SeparableSpace ((range (g : α → G) ∪ {0}) ∩ { y | 0 ≤ y } : Set G) := by
apply IsSeparable.separableSpace
apply IsSeparable.mono _ Set.inter_subset_left
exact
(Lp.stronglyMeasurable (g : Lp G p μ)).isSeparable_range.union
(finite_singleton _).isSeparable
have g_meas : Measurable (g : α → G) := (Lp.stronglyMeasurable (g : Lp G p μ)).measurable
let x n := SimpleFunc.approxOn (g : α → G) g_meas
((range (g : α → G) ∪ {0}) ∩ { y | 0 ≤ y }) 0 zero_mem n
have hx_nonneg : ∀ n, 0 ≤ x n := by
intro n a
change x n a ∈ { y : G | 0 ≤ y }
have A : (range (g : α → G) ∪ {0} : Set G) ∩ { y | 0 ≤ y } ⊆ { y | 0 ≤ y } :=
inter_subset_right
apply A
exact SimpleFunc.approxOn_mem g_meas _ n a
have hx_memLp : ∀ n, MemLp (x n) p μ :=
SimpleFunc.memLp_approxOn _ hg_memLp _ ⟨aestronglyMeasurable_const, by simp⟩
have h_toLp := fun n => MemLp.coeFn_toLp (hx_memLp n)
have hx_nonneg_Lp : ∀ n, 0 ≤ toLp (x n) (hx_memLp n) := by
intro n
rw [← Lp.simpleFunc.coeFn_le, Lp.simpleFunc.toLp_eq_toLp]
filter_upwards [Lp.simpleFunc.coeFn_zero p μ G, h_toLp n] with a ha0 ha_toLp
rw [ha0, ha_toLp]
exact hx_nonneg n a
have hx_tendsto :
Tendsto (fun n : ℕ => eLpNorm ((x n : α → G) - (g : α → G)) p μ) atTop (𝓝 0) := by
apply SimpleFunc.tendsto_approxOn_Lp_eLpNorm g_meas zero_mem hp_ne_top
· have hg_nonneg : (0 : α → G) ≤ᵐ[μ] g := (Lp.coeFn_nonneg _).mpr g.2
refine hg_nonneg.mono fun a ha => subset_closure ?_
simpa using ha
· simp_rw [sub_zero]; exact hg_memLp.eLpNorm_lt_top
refine
⟨fun n =>
(coeSimpleFuncNonnegToLpNonneg p μ G) ⟨toLp (x n) (hx_memLp n), hx_nonneg_Lp n⟩,
fun n => mem_range_self _, ?_⟩
suffices Tendsto (fun n : ℕ => (toLp (x n) (hx_memLp n) : Lp G p μ)) atTop (𝓝 (g : Lp G p μ)) by
rw [tendsto_iff_dist_tendsto_zero] at this ⊢
simp_rw [Subtype.dist_eq]
exact this
rw [Lp.tendsto_Lp_iff_tendsto_eLpNorm']
refine Filter.Tendsto.congr (fun n => eLpNorm_congr_ae (EventuallyEq.sub ?_ ?_)) hx_tendsto
· symm
rw [Lp.simpleFunc.toLp_eq_toLp]
exact h_toLp n
· rfl
variable {p μ G}
end Order
end simpleFunc
end Lp
variable [MeasurableSpace α] [NormedAddCommGroup E] {f : α → E} {p : ℝ≥0∞} {μ : Measure α}
/-- To prove something for an arbitrary `Lp` function in a second countable Borel normed group, it
suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in `Lp` for which the property holds is closed.
-/
@[elab_as_elim]
theorem Lp.induction [_i : Fact (1 ≤ p)] (hp_ne_top : p ≠ ∞) (motive : Lp E p μ → Prop)
(indicatorConst : ∀ (c : E) {s : Set α} (hs : MeasurableSet s) (hμs : μ s < ∞),
motive (Lp.simpleFunc.indicatorConst p hs hμs.ne c))
(add : ∀ ⦃f g⦄, ∀ hf : MemLp f p μ, ∀ hg : MemLp g p μ, Disjoint (support f) (support g) →
motive (hf.toLp f) → motive (hg.toLp g) → motive (hf.toLp f + hg.toLp g))
(isClosed : IsClosed { f : Lp E p μ | motive f }) : ∀ f : Lp E p μ, motive f := by
refine fun f => (Lp.simpleFunc.denseRange hp_ne_top).induction_on f isClosed ?_
refine Lp.simpleFunc.induction (α := α) (E := E) (lt_of_lt_of_le zero_lt_one _i.elim).ne'
hp_ne_top ?_ ?_
· exact fun c s => indicatorConst c
· exact fun f g hf hg => add hf hg
/-- To prove something for an arbitrary `MemLp` function in a second countable
Borel normed group, it suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in the `Lᵖ` space for which the property holds is closed.
* the property is closed under the almost-everywhere equal relation.
It is possible to make the hypotheses in the induction steps a bit stronger, and such conditions
can be added once we need them (for example in `h_add` it is only necessary to consider the sum of
a simple function with a multiple of a characteristic function and that the intersection
of their images is a subset of `{0}`).
-/
@[elab_as_elim]
theorem MemLp.induction [_i : Fact (1 ≤ p)] (hp_ne_top : p ≠ ∞) (motive : (α → E) → Prop)
(indicator : ∀ (c : E) ⦃s⦄, MeasurableSet s → μ s < ∞ → motive (s.indicator fun _ => c))
(add : ∀ ⦃f g : α → E⦄, Disjoint (support f) (support g) → MemLp f p μ → MemLp g p μ →
motive f → motive g → motive (f + g))
(closed : IsClosed { f : Lp E p μ | motive f })
(ae : ∀ ⦃f g⦄, f =ᵐ[μ] g → MemLp f p μ → motive f → motive g) :
∀ ⦃f : α → E⦄, MemLp f p μ → motive f := by
have : ∀ f : SimpleFunc α E, MemLp f p μ → motive f := by
apply SimpleFunc.induction
· intro c s hs h
by_cases hc : c = 0
· subst hc; convert indicator 0 MeasurableSet.empty (by simp) using 1; ext; simp
have hp_pos : p ≠ 0 := (lt_of_lt_of_le zero_lt_one _i.elim).ne'
exact indicator c hs (SimpleFunc.measure_lt_top_of_memLp_indicator hp_pos hp_ne_top hc hs h)
· intro f g hfg hf hg int_fg
rw [SimpleFunc.coe_add,
memLp_add_of_disjoint hfg f.stronglyMeasurable g.stronglyMeasurable] at int_fg
exact add hfg int_fg.1 int_fg.2 (hf int_fg.1) (hg int_fg.2)
have : ∀ f : Lp.simpleFunc E p μ, motive f := by
intro f
exact
ae (Lp.simpleFunc.toSimpleFunc_eq_toFun f) (Lp.simpleFunc.memLp f)
(this (Lp.simpleFunc.toSimpleFunc f) (Lp.simpleFunc.memLp f))
have : ∀ f : Lp E p μ, motive f := fun f =>
(Lp.simpleFunc.denseRange hp_ne_top).induction_on f closed this
exact fun f hf => ae hf.coeFn_toLp (Lp.memLp _) (this (hf.toLp f))
/-- If a set of ae strongly measurable functions is stable under addition and approximates
characteristic functions in `ℒp`, then it is dense in `ℒp`. -/
theorem MemLp.induction_dense (hp_ne_top : p ≠ ∞) (P : (α → E) → Prop)
(h0P :
∀ (c : E) ⦃s : Set α⦄,
MeasurableSet s →
μ s < ∞ →
∀ {ε : ℝ≥0∞}, ε ≠ 0 → ∃ g : α → E, eLpNorm (g - s.indicator fun _ => c) p μ ≤ ε ∧ P g)
(h1P : ∀ f g, P f → P g → P (f + g)) (h2P : ∀ f, P f → AEStronglyMeasurable f μ) {f : α → E}
(hf : MemLp f p μ) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ g : α → E, eLpNorm (f - g) p μ ≤ ε ∧ P g := by
rcases eq_or_ne p 0 with (rfl | hp_pos)
· rcases h0P (0 : E) MeasurableSet.empty (by simp only [measure_empty, zero_lt_top])
hε with ⟨g, _, Pg⟩
exact ⟨g, by simp only [eLpNorm_exponent_zero, zero_le'], Pg⟩
suffices H : ∀ (f' : α →ₛ E) (δ : ℝ≥0∞) (hδ : δ ≠ 0), MemLp f' p μ →
∃ g, eLpNorm (⇑f' - g) p μ ≤ δ ∧ P g by
obtain ⟨η, ηpos, hη⟩ := exists_Lp_half E μ p hε
rcases hf.exists_simpleFunc_eLpNorm_sub_lt hp_ne_top ηpos.ne' with ⟨f', hf', f'_mem⟩
rcases H f' η ηpos.ne' f'_mem with ⟨g, hg, Pg⟩
refine ⟨g, ?_, Pg⟩
convert (hη _ _ (hf.aestronglyMeasurable.sub f'.aestronglyMeasurable)
(f'.aestronglyMeasurable.sub (h2P g Pg)) hf'.le hg).le using 2
simp only [sub_add_sub_cancel]
apply SimpleFunc.induction
· intro c s hs ε εpos Hs
rcases eq_or_ne c 0 with (rfl | hc)
· rcases h0P (0 : E) MeasurableSet.empty (by simp only [measure_empty, zero_lt_top])
εpos with ⟨g, hg, Pg⟩
rw [← eLpNorm_neg, neg_sub] at hg
refine ⟨g, ?_, Pg⟩
convert hg
ext x
simp only [SimpleFunc.const_zero, SimpleFunc.coe_piecewise, SimpleFunc.coe_zero,
piecewise_eq_indicator, indicator_zero', Pi.zero_apply, indicator_zero]
· have : μ s < ∞ := SimpleFunc.measure_lt_top_of_memLp_indicator hp_pos hp_ne_top hc hs Hs
rcases h0P c hs this εpos with ⟨g, hg, Pg⟩
rw [← eLpNorm_neg, neg_sub] at hg
exact ⟨g, hg, Pg⟩
· intro f f' hff' hf hf' δ δpos int_ff'
obtain ⟨η, ηpos, hη⟩ := exists_Lp_half E μ p δpos
rw [SimpleFunc.coe_add,
memLp_add_of_disjoint hff' f.stronglyMeasurable f'.stronglyMeasurable] at int_ff'
rcases hf η ηpos.ne' int_ff'.1 with ⟨g, hg, Pg⟩
rcases hf' η ηpos.ne' int_ff'.2 with ⟨g', hg', Pg'⟩
refine ⟨g + g', ?_, h1P g g' Pg Pg'⟩
convert (hη _ _ (f.aestronglyMeasurable.sub (h2P g Pg))
(f'.aestronglyMeasurable.sub (h2P g' Pg')) hg hg').le using 2
rw [SimpleFunc.coe_add]
abel
section Integrable
@[inherit_doc MeasureTheory.Lp.simpleFunc]
notation:25 α " →₁ₛ[" μ "] " E => @MeasureTheory.Lp.simpleFunc α E _ _ 1 μ
theorem L1.SimpleFunc.toLp_one_eq_toL1 (f : α →ₛ E) (hf : Integrable f μ) :
(Lp.simpleFunc.toLp f (memLp_one_iff_integrable.2 hf) : α →₁[μ] E) = hf.toL1 f :=
rfl
@[fun_prop]
protected theorem L1.SimpleFunc.integrable (f : α →₁ₛ[μ] E) :
Integrable (Lp.simpleFunc.toSimpleFunc f) μ := by
rw [← memLp_one_iff_integrable]; exact Lp.simpleFunc.memLp f
/-- To prove something for an arbitrary integrable function in a normed group,
it suffices to show that
* the property holds for (multiples of) characteristic functions;
* is closed under addition;
* the set of functions in the `L¹` space for which the property holds is closed.
* the property is closed under the almost-everywhere equal relation.
It is possible to make the hypotheses in the induction steps a bit stronger, and such conditions
can be added once we need them (for example in `h_add` it is only necessary to consider the sum of
a simple function with a multiple of a characteristic function and that the intersection
of their images is a subset of `{0}`).
-/
@[elab_as_elim]
theorem Integrable.induction (P : (α → E) → Prop)
(h_ind : ∀ (c : E) ⦃s⦄, MeasurableSet s → μ s < ∞ → P (s.indicator fun _ => c))
(h_add :
∀ ⦃f g : α → E⦄,
Disjoint (support f) (support g) → Integrable f μ → Integrable g μ → P f → P g → P (f + g))
(h_closed : IsClosed { f : α →₁[μ] E | P f })
(h_ae : ∀ ⦃f g⦄, f =ᵐ[μ] g → Integrable f μ → P f → P g) :
∀ ⦃f : α → E⦄, Integrable f μ → P f := by
simp only [← memLp_one_iff_integrable] at *
exact MemLp.induction one_ne_top (motive := P) h_ind h_add h_closed h_ae
end Integrable
end MeasureTheory
|
Pointwise.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.Functor.KanExtension.Basic
/-!
# Pointwise Kan extensions
In this file, we define the notion of pointwise (left) Kan extension. Given two functors
`L : C ⥤ D` and `F : C ⥤ H`, and `E : LeftExtension L F`, we introduce a cocone
`E.coconeAt Y` for the functor `CostructuredArrow.proj L Y ⋙ F : CostructuredArrow L Y ⥤ H`
the point of which is `E.right.obj Y`, and the type `E.IsPointwiseLeftKanExtensionAt Y`
which expresses that `E.coconeAt Y` is colimit. When this holds for all `Y : D`,
we may say that `E` is a pointwise left Kan extension (`E.IsPointwiseLeftKanExtension`).
Conversely, when `CostructuredArrow.proj L Y ⋙ F` has a colimit, we say that
`F` has a pointwise left Kan extension at `Y : D` (`HasPointwiseLeftKanExtensionAt L F Y`),
and if this holds for all `Y : D`, we construct a functor
`pointwiseLeftKanExtension L F : D ⥤ H` and show it is a pointwise Kan extension.
A dual API for pointwise right Kan extension is also formalized.
## References
* https://ncatlab.org/nlab/show/Kan+extension
-/
namespace CategoryTheory
open Category Limits
namespace Functor
variable {C D D' H : Type*} [Category C] [Category D] [Category D'] [Category H]
(L : C ⥤ D) (L' : C ⥤ D') (F : C ⥤ H)
/-- The condition that a functor `F` has a pointwise left Kan extension along `L` at `Y`.
It means that the functor `CostructuredArrow.proj L Y ⋙ F : CostructuredArrow L Y ⥤ H`
has a colimit. -/
abbrev HasPointwiseLeftKanExtensionAt (Y : D) :=
HasColimit (CostructuredArrow.proj L Y ⋙ F)
/-- The condition that a functor `F` has a pointwise left Kan extension along `L`: it means
that it has a pointwise left Kan extension at any object. -/
abbrev HasPointwiseLeftKanExtension := ∀ (Y : D), HasPointwiseLeftKanExtensionAt L F Y
/-- The condition that a functor `F` has a pointwise right Kan extension along `L` at `Y`.
It means that the functor `StructuredArrow.proj Y L ⋙ F : StructuredArrow Y L ⥤ H`
has a limit. -/
abbrev HasPointwiseRightKanExtensionAt (Y : D) :=
HasLimit (StructuredArrow.proj Y L ⋙ F)
/-- The condition that a functor `F` has a pointwise right Kan extension along `L`: it means
that it has a pointwise right Kan extension at any object. -/
abbrev HasPointwiseRightKanExtension := ∀ (Y : D), HasPointwiseRightKanExtensionAt L F Y
lemma hasPointwiseLeftKanExtensionAt_iff_of_iso {Y₁ Y₂ : D} (e : Y₁ ≅ Y₂) :
HasPointwiseLeftKanExtensionAt L F Y₁ ↔
HasPointwiseLeftKanExtensionAt L F Y₂ := by
revert Y₁ Y₂ e
suffices ∀ ⦃Y₁ Y₂ : D⦄ (_ : Y₁ ≅ Y₂) [HasPointwiseLeftKanExtensionAt L F Y₁],
HasPointwiseLeftKanExtensionAt L F Y₂ from
fun Y₁ Y₂ e => ⟨fun _ => this e, fun _ => this e.symm⟩
intro Y₁ Y₂ e _
change HasColimit ((CostructuredArrow.mapIso e.symm).functor ⋙ CostructuredArrow.proj L Y₁ ⋙ F)
infer_instance
lemma hasPointwiseRightKanExtensionAt_iff_of_iso {Y₁ Y₂ : D} (e : Y₁ ≅ Y₂) :
HasPointwiseRightKanExtensionAt L F Y₁ ↔
HasPointwiseRightKanExtensionAt L F Y₂ := by
revert Y₁ Y₂ e
suffices ∀ ⦃Y₁ Y₂ : D⦄ (_ : Y₁ ≅ Y₂) [HasPointwiseRightKanExtensionAt L F Y₁],
HasPointwiseRightKanExtensionAt L F Y₂ from
fun Y₁ Y₂ e => ⟨fun _ => this e, fun _ => this e.symm⟩
intro Y₁ Y₂ e _
change HasLimit ((StructuredArrow.mapIso e.symm).functor ⋙ StructuredArrow.proj Y₁ L ⋙ F)
infer_instance
variable {L} in
/-- `HasPointwiseLeftKanExtensionAt` is invariant when we replace `L` by an equivalent functor. -/
lemma hasPointwiseLeftKanExtensionAt_iff_of_natIso {L' : C ⥤ D} (e : L ≅ L') (Y : D) :
HasPointwiseLeftKanExtensionAt L F Y ↔
HasPointwiseLeftKanExtensionAt L' F Y := by
revert L L' e
suffices ∀ ⦃L L' : C ⥤ D⦄ (_ : L ≅ L') [HasPointwiseLeftKanExtensionAt L F Y],
HasPointwiseLeftKanExtensionAt L' F Y from
fun L L' e => ⟨fun _ => this e, fun _ => this e.symm⟩
intro L L' e _
let Φ : CostructuredArrow L' Y ≌ CostructuredArrow L Y := Comma.mapLeftIso _ e.symm
let e' : CostructuredArrow.proj L' Y ⋙ F ≅
Φ.functor ⋙ CostructuredArrow.proj L Y ⋙ F := Iso.refl _
exact hasColimit_of_iso e'
variable {L} in
/-- `HasPointwiseRightKanExtensionAt` is invariant when we replace `L` by an equivalent functor. -/
lemma hasPointwiseRightKanExtensionAt_iff_of_natIso {L' : C ⥤ D} (e : L ≅ L') (Y : D) :
HasPointwiseRightKanExtensionAt L F Y ↔
HasPointwiseRightKanExtensionAt L' F Y := by
revert L L' e
suffices ∀ ⦃L L' : C ⥤ D⦄ (_ : L ≅ L') [HasPointwiseRightKanExtensionAt L F Y],
HasPointwiseRightKanExtensionAt L' F Y from
fun L L' e => ⟨fun _ => this e, fun _ => this e.symm⟩
intro L L' e _
let Φ : StructuredArrow Y L' ≌ StructuredArrow Y L := Comma.mapRightIso _ e.symm
let e' : StructuredArrow.proj Y L' ⋙ F ≅
Φ.functor ⋙ StructuredArrow.proj Y L ⋙ F := Iso.refl _
exact hasLimit_of_iso e'.symm
lemma hasPointwiseLeftKanExtensionAt_of_equivalence
(E : D ≌ D') (eL : L ⋙ E.functor ≅ L') (Y : D) (Y' : D') (e : E.functor.obj Y ≅ Y')
[HasPointwiseLeftKanExtensionAt L F Y] :
HasPointwiseLeftKanExtensionAt L' F Y' := by
rw [← hasPointwiseLeftKanExtensionAt_iff_of_natIso F eL,
hasPointwiseLeftKanExtensionAt_iff_of_iso _ F e.symm]
let Φ := CostructuredArrow.post L E.functor Y
have : HasColimit ((asEquivalence Φ).functor ⋙
CostructuredArrow.proj (L ⋙ E.functor) (E.functor.obj Y) ⋙ F) :=
(inferInstance : HasPointwiseLeftKanExtensionAt L F Y)
exact hasColimit_of_equivalence_comp (asEquivalence Φ)
lemma hasPointwiseLeftKanExtensionAt_iff_of_equivalence
(E : D ≌ D') (eL : L ⋙ E.functor ≅ L') (Y : D) (Y' : D') (e : E.functor.obj Y ≅ Y') :
HasPointwiseLeftKanExtensionAt L F Y ↔
HasPointwiseLeftKanExtensionAt L' F Y' := by
constructor
· intro
exact hasPointwiseLeftKanExtensionAt_of_equivalence L L' F E eL Y Y' e
· intro
exact hasPointwiseLeftKanExtensionAt_of_equivalence L' L F E.symm
(isoWhiskerRight eL.symm _ ≪≫ Functor.associator _ _ _ ≪≫
isoWhiskerLeft L E.unitIso.symm ≪≫ L.rightUnitor) Y' Y
(E.inverse.mapIso e.symm ≪≫ E.unitIso.symm.app Y)
lemma hasPointwiseRightKanExtensionAt_of_equivalence
(E : D ≌ D') (eL : L ⋙ E.functor ≅ L') (Y : D) (Y' : D') (e : E.functor.obj Y ≅ Y')
[HasPointwiseRightKanExtensionAt L F Y] :
HasPointwiseRightKanExtensionAt L' F Y' := by
rw [← hasPointwiseRightKanExtensionAt_iff_of_natIso F eL,
hasPointwiseRightKanExtensionAt_iff_of_iso _ F e.symm]
let Φ := StructuredArrow.post Y L E.functor
have : HasLimit ((asEquivalence Φ).functor ⋙
StructuredArrow.proj (E.functor.obj Y) (L ⋙ E.functor) ⋙ F) :=
(inferInstance : HasPointwiseRightKanExtensionAt L F Y)
exact hasLimit_of_equivalence_comp (asEquivalence Φ)
lemma hasPointwiseRightKanExtensionAt_iff_of_equivalence
(E : D ≌ D') (eL : L ⋙ E.functor ≅ L') (Y : D) (Y' : D') (e : E.functor.obj Y ≅ Y') :
HasPointwiseRightKanExtensionAt L F Y ↔
HasPointwiseRightKanExtensionAt L' F Y' := by
constructor
· intro
exact hasPointwiseRightKanExtensionAt_of_equivalence L L' F E eL Y Y' e
· intro
exact hasPointwiseRightKanExtensionAt_of_equivalence L' L F E.symm
(isoWhiskerRight eL.symm _ ≪≫ Functor.associator _ _ _ ≪≫
isoWhiskerLeft L E.unitIso.symm ≪≫ L.rightUnitor) Y' Y
(E.inverse.mapIso e.symm ≪≫ E.unitIso.symm.app Y)
namespace LeftExtension
variable {F L}
variable (E : LeftExtension L F)
/-- The cocone for `CostructuredArrow.proj L Y ⋙ F` attached to `E : LeftExtension L F`.
The point of this cocone is `E.right.obj Y` -/
@[simps]
def coconeAt (Y : D) : Cocone (CostructuredArrow.proj L Y ⋙ F) where
pt := E.right.obj Y
ι :=
{ app := fun g => E.hom.app g.left ≫ E.right.map g.hom
naturality := fun g₁ g₂ φ => by
dsimp
rw [← CostructuredArrow.w φ]
simp only [NatTrans.naturality_assoc, Functor.comp_map,
Functor.map_comp, comp_id] }
variable (L F) in
/-- The cocones for `CostructuredArrow.proj L Y ⋙ F`, as a functor from `LeftExtension L F`. -/
@[simps]
def coconeAtFunctor (Y : D) :
LeftExtension L F ⥤ Cocone (CostructuredArrow.proj L Y ⋙ F) where
obj E := E.coconeAt Y
map {E E'} φ := CoconeMorphism.mk (φ.right.app Y) (fun G => by
dsimp
rw [← StructuredArrow.w φ]
simp)
/-- A left extension `E : LeftExtension L F` is a pointwise left Kan extension at `Y` when
`E.coconeAt Y` is a colimit cocone. -/
def IsPointwiseLeftKanExtensionAt (Y : D) := IsColimit (E.coconeAt Y)
variable {E} in
lemma IsPointwiseLeftKanExtensionAt.hasPointwiseLeftKanExtensionAt
{Y : D} (h : E.IsPointwiseLeftKanExtensionAt Y) :
HasPointwiseLeftKanExtensionAt L F Y := ⟨_, h⟩
lemma IsPointwiseLeftKanExtensionAt.isIso_hom_app
{X : C} (h : E.IsPointwiseLeftKanExtensionAt (L.obj X)) [L.Full] [L.Faithful] :
IsIso (E.hom.app X) := by
simpa using h.isIso_ι_app_of_isTerminal _ CostructuredArrow.mkIdTerminal
/-- The condition of being a pointwise left Kan extension at an object `Y` is
unchanged by replacing `Y` by an isomorphic object `Y'`. -/
def isPointwiseLeftKanExtensionAtOfIso'
{Y : D} (hY : E.IsPointwiseLeftKanExtensionAt Y) {Y' : D} (e : Y ≅ Y') :
E.IsPointwiseLeftKanExtensionAt Y' :=
IsColimit.ofIsoColimit (hY.whiskerEquivalence (CostructuredArrow.mapIso e.symm))
(Cocones.ext (E.right.mapIso e))
/-- The condition of being a pointwise left Kan extension at an object `Y` is
unchanged by replacing `Y` by an isomorphic object `Y'`. -/
def isPointwiseLeftKanExtensionAtEquivOfIso' {Y Y' : D} (e : Y ≅ Y') :
E.IsPointwiseLeftKanExtensionAt Y ≃ E.IsPointwiseLeftKanExtensionAt Y' where
toFun h := E.isPointwiseLeftKanExtensionAtOfIso' h e
invFun h := E.isPointwiseLeftKanExtensionAtOfIso' h e.symm
left_inv h := by
dsimp only [IsPointwiseLeftKanExtensionAt]
apply Subsingleton.elim
right_inv h := by
dsimp only [IsPointwiseLeftKanExtensionAt]
apply Subsingleton.elim
namespace IsPointwiseLeftKanExtensionAt
variable {E} {Y : D} (h : E.IsPointwiseLeftKanExtensionAt Y)
[HasColimit (CostructuredArrow.proj L Y ⋙ F)]
/-- A pointwise left Kan extension of `F` along `L` applied to an object `Y` is isomorphic to
`colimit (CostructuredArrow.proj L Y ⋙ F)`. -/
noncomputable def isoColimit :
E.right.obj Y ≅ colimit (CostructuredArrow.proj L Y ⋙ F) :=
h.coconePointUniqueUpToIso (colimit.isColimit _)
@[reassoc (attr := simp)]
lemma ι_isoColimit_inv (g : CostructuredArrow L Y) :
colimit.ι _ g ≫ h.isoColimit.inv = E.hom.app g.left ≫ E.right.map g.hom :=
IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _
@[reassoc (attr := simp)]
lemma ι_isoColimit_hom (g : CostructuredArrow L Y) :
E.hom.app g.left ≫ E.right.map g.hom ≫ h.isoColimit.hom =
colimit.ι (CostructuredArrow.proj L Y ⋙ F) g := by
simpa using h.comp_coconePointUniqueUpToIso_hom (colimit.isColimit _) g
end IsPointwiseLeftKanExtensionAt
/-- A left extension `E : LeftExtension L F` is a pointwise left Kan extension when
it is a pointwise left Kan extension at any object. -/
abbrev IsPointwiseLeftKanExtension := ∀ (Y : D), E.IsPointwiseLeftKanExtensionAt Y
variable {E E'}
/-- If two left extensions `E` and `E'` are isomorphic, `E` is a pointwise
left Kan extension at `Y` iff `E'` is. -/
def isPointwiseLeftKanExtensionAtEquivOfIso (e : E ≅ E') (Y : D) :
E.IsPointwiseLeftKanExtensionAt Y ≃ E'.IsPointwiseLeftKanExtensionAt Y :=
IsColimit.equivIsoColimit ((coconeAtFunctor L F Y).mapIso e)
/-- If two left extensions `E` and `E'` are isomorphic, `E` is a pointwise
left Kan extension iff `E'` is. -/
def isPointwiseLeftKanExtensionEquivOfIso (e : E ≅ E') :
E.IsPointwiseLeftKanExtension ≃ E'.IsPointwiseLeftKanExtension where
toFun h := fun Y => (isPointwiseLeftKanExtensionAtEquivOfIso e Y) (h Y)
invFun h := fun Y => (isPointwiseLeftKanExtensionAtEquivOfIso e Y).symm (h Y)
left_inv h := by simp
right_inv h := by simp
variable (h : E.IsPointwiseLeftKanExtension)
include h
lemma IsPointwiseLeftKanExtension.hasPointwiseLeftKanExtension :
HasPointwiseLeftKanExtension L F :=
fun Y => (h Y).hasPointwiseLeftKanExtensionAt
/-- The (unique) morphism from a pointwise left Kan extension. -/
def IsPointwiseLeftKanExtension.homFrom (G : LeftExtension L F) : E ⟶ G :=
StructuredArrow.homMk
{ app := fun Y => (h Y).desc (LeftExtension.coconeAt G Y)
naturality := fun Y₁ Y₂ φ => (h Y₁).hom_ext (fun X => by
rw [(h Y₁).fac_assoc (coconeAt G Y₁) X]
simpa using (h Y₂).fac (coconeAt G Y₂) ((CostructuredArrow.map φ).obj X)) }
(by
ext X
simpa using (h (L.obj X)).fac (LeftExtension.coconeAt G _) (CostructuredArrow.mk (𝟙 _)))
lemma IsPointwiseLeftKanExtension.hom_ext
{G : LeftExtension L F} {f₁ f₂ : E ⟶ G} : f₁ = f₂ := by
ext Y
apply (h Y).hom_ext
intro X
have eq₁ := congr_app (StructuredArrow.w f₁) X.left
have eq₂ := congr_app (StructuredArrow.w f₂) X.left
dsimp at eq₁ eq₂ ⊢
simp only [assoc, NatTrans.naturality]
rw [reassoc_of% eq₁, reassoc_of% eq₂]
/-- A pointwise left Kan extension is universal, i.e. it is a left Kan extension. -/
def IsPointwiseLeftKanExtension.isUniversal : E.IsUniversal :=
IsInitial.ofUniqueHom h.homFrom (fun _ _ => h.hom_ext)
lemma IsPointwiseLeftKanExtension.isLeftKanExtension :
E.right.IsLeftKanExtension E.hom where
nonempty_isUniversal := ⟨h.isUniversal⟩
lemma IsPointwiseLeftKanExtension.hasLeftKanExtension :
HasLeftKanExtension L F :=
have := h.isLeftKanExtension
HasLeftKanExtension.mk E.right E.hom
lemma IsPointwiseLeftKanExtension.isIso_hom [L.Full] [L.Faithful] :
IsIso (E.hom) :=
have := fun X => (h (L.obj X)).isIso_hom_app
NatIso.isIso_of_isIso_app ..
end LeftExtension
namespace RightExtension
variable {F L}
variable (E E' : RightExtension L F)
/-- The cone for `StructuredArrow.proj Y L ⋙ F` attached to `E : RightExtension L F`.
The point of this cone is `E.left.obj Y` -/
@[simps]
def coneAt (Y : D) : Cone (StructuredArrow.proj Y L ⋙ F) where
pt := E.left.obj Y
π :=
{ app := fun g ↦ E.left.map g.hom ≫ E.hom.app g.right
naturality := fun g₁ g₂ φ ↦ by
dsimp
rw [assoc, id_comp, ← StructuredArrow.w φ, Functor.map_comp, assoc]
congr 1
apply E.hom.naturality }
variable (L F) in
/-- The cones for `StructuredArrow.proj Y L ⋙ F`, as a functor from `RightExtension L F`. -/
@[simps]
def coneAtFunctor (Y : D) :
RightExtension L F ⥤ Cone (StructuredArrow.proj Y L ⋙ F) where
obj E := E.coneAt Y
map {E E'} φ := ConeMorphism.mk (φ.left.app Y) (fun G ↦ by
dsimp
rw [← CostructuredArrow.w φ]
simp)
/-- A right extension `E : RightExtension L F` is a pointwise right Kan extension at `Y` when
`E.coneAt Y` is a limit cone. -/
def IsPointwiseRightKanExtensionAt (Y : D) := IsLimit (E.coneAt Y)
variable {E} in
lemma IsPointwiseRightKanExtensionAt.hasPointwiseRightKanExtensionAt
{Y : D} (h : E.IsPointwiseRightKanExtensionAt Y) :
HasPointwiseRightKanExtensionAt L F Y := ⟨_, h⟩
lemma IsPointwiseRightKanExtensionAt.isIso_hom_app
{X : C} (h : E.IsPointwiseRightKanExtensionAt (L.obj X)) [L.Full] [L.Faithful] :
IsIso (E.hom.app X) := by
simpa using h.isIso_π_app_of_isInitial _ StructuredArrow.mkIdInitial
/-- The condition of being a pointwise right Kan extension at an object `Y` is
unchanged by replacing `Y` by an isomorphic object `Y'`. -/
def isPointwiseRightKanExtensionAtOfIso'
{Y : D} (hY : E.IsPointwiseRightKanExtensionAt Y) {Y' : D} (e : Y ≅ Y') :
E.IsPointwiseRightKanExtensionAt Y' :=
IsLimit.ofIsoLimit (hY.whiskerEquivalence (StructuredArrow.mapIso e.symm))
(Cones.ext (E.left.mapIso e))
/-- The condition of being a pointwise right Kan extension at an object `Y` is
unchanged by replacing `Y` by an isomorphic object `Y'`. -/
def isPointwiseRightKanExtensionAtEquivOfIso' {Y Y' : D} (e : Y ≅ Y') :
E.IsPointwiseRightKanExtensionAt Y ≃ E.IsPointwiseRightKanExtensionAt Y' where
toFun h := E.isPointwiseRightKanExtensionAtOfIso' h e
invFun h := E.isPointwiseRightKanExtensionAtOfIso' h e.symm
left_inv h := by
dsimp only [IsPointwiseRightKanExtensionAt]
apply Subsingleton.elim
right_inv h := by
dsimp only [IsPointwiseRightKanExtensionAt]
apply Subsingleton.elim
namespace IsPointwiseRightKanExtensionAt
variable {E} {Y : D} (h : E.IsPointwiseRightKanExtensionAt Y)
[HasLimit (StructuredArrow.proj Y L ⋙ F)]
/-- A pointwise right Kan extension of `F` along `L` applied to an object `Y` is isomorphic to
`limit (StructuredArrow.proj Y L ⋙ F)`. -/
noncomputable def isoLimit :
E.left.obj Y ≅ limit (StructuredArrow.proj Y L ⋙ F) :=
h.conePointUniqueUpToIso (limit.isLimit _)
@[reassoc (attr := simp)]
lemma isoLimit_hom_π (g : StructuredArrow Y L) :
h.isoLimit.hom ≫ limit.π _ g = E.left.map g.hom ≫ E.hom.app g.right :=
IsLimit.conePointUniqueUpToIso_hom_comp _ _ _
@[reassoc (attr := simp)]
lemma isoLimit_inv_π (g : StructuredArrow Y L) :
h.isoLimit.inv ≫ E.left.map g.hom ≫ E.hom.app g.right =
limit.π (StructuredArrow.proj Y L ⋙ F) g := by
simpa using h.conePointUniqueUpToIso_inv_comp (limit.isLimit _) g
end IsPointwiseRightKanExtensionAt
/-- A right extension `E : RightExtension L F` is a pointwise right Kan extension when
it is a pointwise right Kan extension at any object. -/
abbrev IsPointwiseRightKanExtension := ∀ (Y : D), E.IsPointwiseRightKanExtensionAt Y
variable {E E'}
/-- If two right extensions `E` and `E'` are isomorphic, `E` is a pointwise
right Kan extension at `Y` iff `E'` is. -/
def isPointwiseRightKanExtensionAtEquivOfIso (e : E ≅ E') (Y : D) :
E.IsPointwiseRightKanExtensionAt Y ≃ E'.IsPointwiseRightKanExtensionAt Y :=
IsLimit.equivIsoLimit ((coneAtFunctor L F Y).mapIso e)
/-- If two right extensions `E` and `E'` are isomorphic, `E` is a pointwise
right Kan extension iff `E'` is. -/
def isPointwiseRightKanExtensionEquivOfIso (e : E ≅ E') :
E.IsPointwiseRightKanExtension ≃ E'.IsPointwiseRightKanExtension where
toFun h := fun Y => (isPointwiseRightKanExtensionAtEquivOfIso e Y) (h Y)
invFun h := fun Y => (isPointwiseRightKanExtensionAtEquivOfIso e Y).symm (h Y)
left_inv h := by simp
right_inv h := by simp
variable (h : E.IsPointwiseRightKanExtension)
include h
lemma IsPointwiseRightKanExtension.hasPointwiseRightKanExtension :
HasPointwiseRightKanExtension L F :=
fun Y => (h Y).hasPointwiseRightKanExtensionAt
/-- The (unique) morphism to a pointwise right Kan extension. -/
def IsPointwiseRightKanExtension.homTo (G : RightExtension L F) : G ⟶ E :=
CostructuredArrow.homMk
{ app := fun Y ↦ (h Y).lift (RightExtension.coneAt G Y)
naturality := fun Y₁ Y₂ φ ↦ (h Y₂).hom_ext (fun X ↦ by
rw [assoc, (h Y₂).fac (coneAt G Y₂) X]
simpa using ((h Y₁).fac (coneAt G Y₁) ((StructuredArrow.map φ).obj X)).symm) }
(by
ext X
simpa using (h (L.obj X)).fac (RightExtension.coneAt G _) (StructuredArrow.mk (𝟙 _)) )
lemma IsPointwiseRightKanExtension.hom_ext
{G : RightExtension L F} {f₁ f₂ : G ⟶ E} : f₁ = f₂ := by
ext Y
apply (h Y).hom_ext
intro X
have eq₁ := congr_app (CostructuredArrow.w f₁) X.right
have eq₂ := congr_app (CostructuredArrow.w f₂) X.right
dsimp at eq₁ eq₂ ⊢
simp only [← NatTrans.naturality_assoc, eq₁, eq₂]
/-- A pointwise right Kan extension is universal, i.e. it is a right Kan extension. -/
def IsPointwiseRightKanExtension.isUniversal : E.IsUniversal :=
IsTerminal.ofUniqueHom h.homTo (fun _ _ => h.hom_ext)
lemma IsPointwiseRightKanExtension.isRightKanExtension :
E.left.IsRightKanExtension E.hom where
nonempty_isUniversal := ⟨h.isUniversal⟩
lemma IsPointwiseRightKanExtension.hasRightKanExtension :
HasRightKanExtension L F :=
have := h.isRightKanExtension
HasRightKanExtension.mk E.left E.hom
lemma IsPointwiseRightKanExtension.isIso_hom [L.Full] [L.Faithful] :
IsIso (E.hom) :=
have := fun X => (h (L.obj X)).isIso_hom_app
NatIso.isIso_of_isIso_app ..
end RightExtension
section
variable [HasPointwiseLeftKanExtension L F]
/-- The constructed pointwise left Kan extension when `HasPointwiseLeftKanExtension L F` holds. -/
@[simps]
noncomputable def pointwiseLeftKanExtension : D ⥤ H where
obj Y := colimit (CostructuredArrow.proj L Y ⋙ F)
map {Y₁ Y₂} f :=
colimit.desc (CostructuredArrow.proj L Y₁ ⋙ F)
(Cocone.mk (colimit (CostructuredArrow.proj L Y₂ ⋙ F))
{ app := fun g => colimit.ι (CostructuredArrow.proj L Y₂ ⋙ F)
((CostructuredArrow.map f).obj g)
naturality := fun g₁ g₂ φ => by
simpa using colimit.w (CostructuredArrow.proj L Y₂ ⋙ F)
((CostructuredArrow.map f).map φ) })
map_id Y := colimit.hom_ext (fun j => by
dsimp
simp only [colimit.ι_desc, comp_id]
congr
apply CostructuredArrow.map_id)
map_comp {Y₁ Y₂ Y₃} f f' := colimit.hom_ext (fun j => by
dsimp
simp only [colimit.ι_desc, colimit.ι_desc_assoc, comp_obj, CostructuredArrow.proj_obj]
congr 1
apply CostructuredArrow.map_comp)
/-- The unit of the constructed pointwise left Kan extension when
`HasPointwiseLeftKanExtension L F` holds. -/
@[simps]
noncomputable def pointwiseLeftKanExtensionUnit : F ⟶ L ⋙ pointwiseLeftKanExtension L F where
app X := colimit.ι (CostructuredArrow.proj L (L.obj X) ⋙ F)
(CostructuredArrow.mk (𝟙 (L.obj X)))
naturality {X₁ X₂} f := by
simp only [comp_obj, pointwiseLeftKanExtension_obj, comp_map,
pointwiseLeftKanExtension_map, colimit.ι_desc, CostructuredArrow.map_mk]
rw [id_comp]
let φ : CostructuredArrow.mk (L.map f) ⟶ CostructuredArrow.mk (𝟙 (L.obj X₂)) :=
CostructuredArrow.homMk f
exact colimit.w (CostructuredArrow.proj L (L.obj X₂) ⋙ F) φ
/-- The functor `pointwiseLeftKanExtension L F` is a pointwise left Kan
extension of `F` along `L`. -/
noncomputable def pointwiseLeftKanExtensionIsPointwiseLeftKanExtension :
(LeftExtension.mk _ (pointwiseLeftKanExtensionUnit L F)).IsPointwiseLeftKanExtension :=
fun X => IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (Iso.refl _) (fun j => by
dsimp
simp only [comp_id, colimit.ι_desc, CostructuredArrow.map_mk]
congr 1
rw [id_comp, ← CostructuredArrow.eq_mk]))
/-- The functor `pointwiseLeftKanExtension L F` is a left Kan extension of `F` along `L`. -/
noncomputable def pointwiseLeftKanExtensionIsUniversal :
(LeftExtension.mk _ (pointwiseLeftKanExtensionUnit L F)).IsUniversal :=
(pointwiseLeftKanExtensionIsPointwiseLeftKanExtension L F).isUniversal
instance : (pointwiseLeftKanExtension L F).IsLeftKanExtension
(pointwiseLeftKanExtensionUnit L F) where
nonempty_isUniversal := ⟨pointwiseLeftKanExtensionIsUniversal L F⟩
instance : HasLeftKanExtension L F :=
HasLeftKanExtension.mk _ (pointwiseLeftKanExtensionUnit L F)
/-- An auxiliary cocone used in the lemma `pointwiseLeftKanExtension_desc_app` -/
@[simps]
def costructuredArrowMapCocone (G : D ⥤ H) (α : F ⟶ L ⋙ G) (Y : D) :
Cocone (CostructuredArrow.proj L Y ⋙ F) where
pt := G.obj Y
ι := {
app := fun f ↦ α.app f.left ≫ G.map f.hom
naturality := by simp [← G.map_comp] }
@[simp]
lemma pointwiseLeftKanExtension_desc_app (G : D ⥤ H) (α : F ⟶ L ⋙ G) (Y : D) :
((pointwiseLeftKanExtension L F).descOfIsLeftKanExtension (pointwiseLeftKanExtensionUnit L F)
G α |>.app Y) = colimit.desc _ (costructuredArrowMapCocone L F G α Y) := by
let β : L.pointwiseLeftKanExtension F ⟶ G :=
{ app := fun Y ↦ colimit.desc _ (costructuredArrowMapCocone L F G α Y) }
have h : (pointwiseLeftKanExtension L F).descOfIsLeftKanExtension
(pointwiseLeftKanExtensionUnit L F) G α = β := by
apply hom_ext_of_isLeftKanExtension (α := pointwiseLeftKanExtensionUnit L F)
aesop
exact NatTrans.congr_app h Y
variable {F L}
/-- If `F` admits a pointwise left Kan extension along `L`, then any left Kan extension of `F`
along `L` is a pointwise left Kan extension. -/
noncomputable def isPointwiseLeftKanExtensionOfIsLeftKanExtension (F' : D ⥤ H) (α : F ⟶ L ⋙ F')
[F'.IsLeftKanExtension α] :
(LeftExtension.mk _ α).IsPointwiseLeftKanExtension :=
LeftExtension.isPointwiseLeftKanExtensionEquivOfIso
(IsColimit.coconePointUniqueUpToIso (pointwiseLeftKanExtensionIsUniversal L F)
(F'.isUniversalOfIsLeftKanExtension α))
(pointwiseLeftKanExtensionIsPointwiseLeftKanExtension L F)
end
section
variable [HasPointwiseRightKanExtension L F]
/-- The constructed pointwise right Kan extension
when `HasPointwiseRightKanExtension L F` holds. -/
@[simps]
noncomputable def pointwiseRightKanExtension : D ⥤ H where
obj Y := limit (StructuredArrow.proj Y L ⋙ F)
map {Y₁ Y₂} f := limit.lift (StructuredArrow.proj Y₂ L ⋙ F)
(Cone.mk (limit (StructuredArrow.proj Y₁ L ⋙ F))
{ app := fun g ↦ limit.π (StructuredArrow.proj Y₁ L ⋙ F)
((StructuredArrow.map f).obj g)
naturality := fun g₁ g₂ φ ↦ by
simpa using (limit.w (StructuredArrow.proj Y₁ L ⋙ F)
((StructuredArrow.map f).map φ)).symm })
map_id Y := limit.hom_ext (fun j => by
dsimp
simp only [limit.lift_π, id_comp]
congr
apply StructuredArrow.map_id)
map_comp {Y₁ Y₂ Y₃} f f' := limit.hom_ext (fun j => by
dsimp
simp only [limit.lift_π, assoc]
congr 1
apply StructuredArrow.map_comp)
/-- The counit of the constructed pointwise right Kan extension when
`HasPointwiseRightKanExtension L F` holds. -/
@[simps]
noncomputable def pointwiseRightKanExtensionCounit :
L ⋙ pointwiseRightKanExtension L F ⟶ F where
app X := limit.π (StructuredArrow.proj (L.obj X) L ⋙ F)
(StructuredArrow.mk (𝟙 (L.obj X)))
naturality {X₁ X₂} f := by
simp only [comp_obj, pointwiseRightKanExtension_obj, comp_map,
pointwiseRightKanExtension_map, limit.lift_π, StructuredArrow.map_mk]
rw [comp_id]
let φ : StructuredArrow.mk (𝟙 (L.obj X₁)) ⟶ StructuredArrow.mk (L.map f) :=
StructuredArrow.homMk f
exact (limit.w (StructuredArrow.proj (L.obj X₁) L ⋙ F) φ).symm
/-- The functor `pointwiseRightKanExtension L F` is a pointwise right Kan
extension of `F` along `L`. -/
noncomputable def pointwiseRightKanExtensionIsPointwiseRightKanExtension :
(RightExtension.mk _ (pointwiseRightKanExtensionCounit L F)).IsPointwiseRightKanExtension :=
fun X => IsLimit.ofIsoLimit (limit.isLimit _) (Cones.ext (Iso.refl _) (fun j => by
dsimp
simp only [limit.lift_π, StructuredArrow.map_mk, id_comp]
congr
rw [comp_id, ← StructuredArrow.eq_mk]))
/-- The functor `pointwiseRightKanExtension L F` is a right Kan extension of `F` along `L`. -/
noncomputable def pointwiseRightKanExtensionIsUniversal :
(RightExtension.mk _ (pointwiseRightKanExtensionCounit L F)).IsUniversal :=
(pointwiseRightKanExtensionIsPointwiseRightKanExtension L F).isUniversal
instance : (pointwiseRightKanExtension L F).IsRightKanExtension
(pointwiseRightKanExtensionCounit L F) where
nonempty_isUniversal := ⟨pointwiseRightKanExtensionIsUniversal L F⟩
instance : HasRightKanExtension L F :=
HasRightKanExtension.mk _ (pointwiseRightKanExtensionCounit L F)
/-- An auxiliary cocone used in the lemma `pointwiseRightKanExtension_lift_app` -/
@[simps]
def structuredArrowMapCone (G : D ⥤ H) (α : L ⋙ G ⟶ F) (Y : D) :
Cone (StructuredArrow.proj Y L ⋙ F) where
pt := G.obj Y
π := {
app := fun f ↦ G.map f.hom ≫ α.app f.right
naturality := by simp [← α.naturality, ← G.map_comp_assoc] }
@[simp]
lemma pointwiseRightKanExtension_lift_app (G : D ⥤ H) (α : L ⋙ G ⟶ F) (Y : D) :
((pointwiseRightKanExtension L F).liftOfIsRightKanExtension
(pointwiseRightKanExtensionCounit L F) G α |>.app Y) =
limit.lift _ (structuredArrowMapCone L F G α Y) := by
let β : G ⟶ L.pointwiseRightKanExtension F :=
{ app := fun Y ↦ limit.lift _ (structuredArrowMapCone L F G α Y) }
have h : (pointwiseRightKanExtension L F).liftOfIsRightKanExtension
(pointwiseRightKanExtensionCounit L F) G α = β := by
apply hom_ext_of_isRightKanExtension (α := pointwiseRightKanExtensionCounit L F)
aesop
exact NatTrans.congr_app h Y
variable {F L}
/-- If `F` admits a pointwise right Kan extension along `L`, then any right Kan extension of `F`
along `L` is a pointwise right Kan extension. -/
noncomputable def isPointwiseRightKanExtensionOfIsRightKanExtension (F' : D ⥤ H) (α : L ⋙ F' ⟶ F)
[F'.IsRightKanExtension α] :
(RightExtension.mk _ α).IsPointwiseRightKanExtension :=
RightExtension.isPointwiseRightKanExtensionEquivOfIso
(IsLimit.conePointUniqueUpToIso (pointwiseRightKanExtensionIsUniversal L F)
(F'.isUniversalOfIsRightKanExtension α))
(pointwiseRightKanExtensionIsPointwiseRightKanExtension L F)
end
end Functor
end CategoryTheory
|
Prod.lean
|
/-
Copyright (c) 2014 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Group.Prod
import Mathlib.Data.Nat.Cast.Defs
/-!
# The product of two `AddMonoidWithOne`s.
-/
assert_not_exists MonoidWithZero
variable {α β : Type*}
namespace Prod
variable [AddMonoidWithOne α] [AddMonoidWithOne β]
instance instAddMonoidWithOne : AddMonoidWithOne (α × β) :=
{ Prod.instAddMonoid, @Prod.instOne α β _ _ with
natCast := fun n => (n, n)
natCast_zero := congr_arg₂ Prod.mk Nat.cast_zero Nat.cast_zero
natCast_succ := fun _ => congr_arg₂ Prod.mk (Nat.cast_succ _) (Nat.cast_succ _) }
@[simp]
theorem fst_natCast (n : ℕ) : (n : α × β).fst = n := by induction n <;> simp [*]
@[simp]
theorem fst_ofNat (n : ℕ) [n.AtLeastTwo] :
(ofNat(n) : α × β).1 = (ofNat(n) : α) :=
rfl
@[simp]
theorem snd_natCast (n : ℕ) : (n : α × β).snd = n := by induction n <;> simp [*]
@[simp]
theorem snd_ofNat (n : ℕ) [n.AtLeastTwo] :
(ofNat(n) : α × β).2 = (ofNat(n) : β) :=
rfl
end Prod
|
MinimalAxioms.lean
|
/-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Ring.Defs
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.MinimalAxioms
/-!
# Minimal Axioms for a Ring
This file defines constructors to define a `Ring` or `CommRing` structure on a Type, while proving
a minimum number of equalities.
## Main Definitions
* `Ring.ofMinimalAxioms`: Define a `Ring` structure on a Type by proving a minimized set of axioms
* `CommRing.ofMinimalAxioms`: Define a `CommRing` structure on a Type by proving a minimized set of
axioms
-/
universe u
/-- Define a `Ring` structure on a Type by proving a minimized set of axioms.
Note that this uses the default definitions for `npow`, `nsmul`, `zsmul` and `sub`
See note [reducible non-instances]. -/
abbrev Ring.ofMinimalAxioms {R : Type u}
[Add R] [Mul R] [Neg R] [Zero R] [One R]
(add_assoc : ∀ a b c : R, a + b + c = a + (b + c))
(zero_add : ∀ a : R, 0 + a = a)
(neg_add_cancel : ∀ a : R, -a + a = 0)
(mul_assoc : ∀ a b c : R, a * b * c = a * (b * c))
(one_mul : ∀ a : R, 1 * a = a)
(mul_one : ∀ a : R, a * 1 = a)
(left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c)
(right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c) : Ring R :=
letI := AddGroup.ofLeftAxioms add_assoc zero_add neg_add_cancel
haveI add_comm : ∀ a b, a + b = b + a := by
intro a b
have h₁ : (1 + 1 : R) * (a + b) = a + (a + b) + b := by
rw [left_distrib]
simp only [right_distrib, one_mul, add_assoc]
have h₂ : (1 + 1 : R) * (a + b) = a + (b + a) + b := by
rw [right_distrib]
simp only [left_distrib, one_mul, add_assoc]
have := h₁.symm.trans h₂
rwa [add_left_inj, add_right_inj] at this
haveI zero_mul : ∀ a, (0 : R) * a = 0 := fun a => by
have : 0 * a = 0 * a + 0 * a :=
calc 0 * a = (0 + 0) * a := by rw [zero_add]
_ = 0 * a + 0 * a := by rw [right_distrib]
rwa [left_eq_add] at this
haveI mul_zero : ∀ a, a * (0 : R) = 0 := fun a => by
have : a * 0 = a * 0 + a * 0 :=
calc a * 0 = a * (0 + 0) := by rw [zero_add]
_ = a * 0 + a * 0 := by rw [left_distrib]
rwa [left_eq_add] at this
{ add_comm := add_comm
left_distrib := left_distrib
right_distrib := right_distrib
zero_mul := zero_mul
mul_zero := mul_zero
mul_assoc := mul_assoc
one_mul := one_mul
mul_one := mul_one
neg_add_cancel := neg_add_cancel
zsmul := (· • ·) }
/-- Define a `CommRing` structure on a Type by proving a minimized set of axioms.
Note that this uses the default definitions for `npow`, `nsmul`, `zsmul` and `sub`
See note [reducible non-instances]. -/
abbrev CommRing.ofMinimalAxioms {R : Type u}
[Add R] [Mul R] [Neg R] [Zero R] [One R]
(add_assoc : ∀ a b c : R, a + b + c = a + (b + c))
(zero_add : ∀ a : R, 0 + a = a)
(neg_add_cancel : ∀ a : R, -a + a = 0)
(mul_assoc : ∀ a b c : R, a * b * c = a * (b * c))
(mul_comm : ∀ a b : R, a * b = b * a)
(one_mul : ∀ a : R, 1 * a = a)
(left_distrib : ∀ a b c : R, a * (b + c) = a * b + a * c) : CommRing R :=
haveI mul_one : ∀ a : R, a * 1 = a := fun a => by
rw [mul_comm, one_mul]
haveI right_distrib : ∀ a b c : R, (a + b) * c = a * c + b * c := fun a b c => by
rw [mul_comm, left_distrib, mul_comm, mul_comm b c]
letI := Ring.ofMinimalAxioms add_assoc zero_add neg_add_cancel mul_assoc
one_mul mul_one left_distrib right_distrib
{ mul_comm := mul_comm }
|
KernelPair.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.CategoryTheory.Limits.Shapes.RegularMono
/-!
# Kernel pairs
This file defines what it means for a parallel pair of morphisms `a b : R ⟶ X` to be the kernel pair
for a morphism `f`.
Some properties of kernel pairs are given, namely allowing one to transfer between
the kernel pair of `f₁ ≫ f₂` to the kernel pair of `f₁`.
It is also proved that if `f` is a coequalizer of some pair, and `a`,`b` is a kernel pair for `f`
then it is a coequalizer of `a`,`b`.
## Implementation
The definition is essentially just a wrapper for `IsLimit (PullbackCone.mk _ _ _)`, but the
constructions given here are useful, yet awkward to present in that language, so a basic API
is developed here.
## TODO
- Internal equivalence relations (or congruences) and the fact that every kernel pair induces one,
and the converse in an effective regular category (WIP by b-mehta).
-/
universe v u u₂
namespace CategoryTheory
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
variable {C : Type u} [Category.{v} C]
variable {R X Y Z : C} (f : X ⟶ Y) (a b : R ⟶ X)
/-- `IsKernelPair f a b` expresses that `(a, b)` is a kernel pair for `f`, i.e. `a ≫ f = b ≫ f`
and the square
R → X
↓ ↓
X → Y
is a pullback square.
This is just an abbreviation for `IsPullback a b f f`.
-/
abbrev IsKernelPair :=
IsPullback a b f f
namespace IsKernelPair
/-- The data expressing that `(a, b)` is a kernel pair is subsingleton. -/
instance : Subsingleton (IsKernelPair f a b) :=
⟨fun P Q => by constructor⟩
/-- If `f` is a monomorphism, then `(𝟙 _, 𝟙 _)` is a kernel pair for `f`. -/
theorem id_of_mono [Mono f] : IsKernelPair f (𝟙 _) (𝟙 _) :=
⟨⟨rfl⟩, ⟨PullbackCone.isLimitMkIdId _⟩⟩
instance [Mono f] : Inhabited (IsKernelPair f (𝟙 _) (𝟙 _)) :=
⟨id_of_mono f⟩
variable {f a b}
-- Porting note: `lift` and the two following simp lemmas were introduced to ease the port
/--
Given a pair of morphisms `p`, `q` to `X` which factor through `f`, they factor through any kernel
pair of `f`.
-/
noncomputable def lift {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) :
S ⟶ R :=
PullbackCone.IsLimit.lift k.isLimit _ _ w
@[reassoc (attr := simp)]
lemma lift_fst {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) :
k.lift p q w ≫ a = p :=
PullbackCone.IsLimit.lift_fst _ _ _ _
@[reassoc (attr := simp)]
lemma lift_snd {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) :
k.lift p q w ≫ b = q :=
PullbackCone.IsLimit.lift_snd _ _ _ _
/--
Given a pair of morphisms `p`, `q` to `X` which factor through `f`, they factor through any kernel
pair of `f`.
-/
noncomputable def lift' {S : C} (k : IsKernelPair f a b) (p q : S ⟶ X) (w : p ≫ f = q ≫ f) :
{ t : S ⟶ R // t ≫ a = p ∧ t ≫ b = q } :=
⟨k.lift p q w, by simp⟩
/--
If `(a,b)` is a kernel pair for `f₁ ≫ f₂` and `a ≫ f₁ = b ≫ f₁`, then `(a,b)` is a kernel pair for
just `f₁`.
That is, to show that `(a,b)` is a kernel pair for `f₁` it suffices to only show the square
commutes, rather than to additionally show it's a pullback.
-/
theorem cancel_right {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} (comm : a ≫ f₁ = b ≫ f₁)
(big_k : IsKernelPair (f₁ ≫ f₂) a b) : IsKernelPair f₁ a b :=
{ w := comm
isLimit' :=
⟨PullbackCone.isLimitAux' _ fun s => by
let s' : PullbackCone (f₁ ≫ f₂) (f₁ ≫ f₂) :=
PullbackCone.mk s.fst s.snd (s.condition_assoc _)
refine ⟨big_k.isLimit.lift s', big_k.isLimit.fac _ WalkingCospan.left,
big_k.isLimit.fac _ WalkingCospan.right, fun m₁ m₂ => ?_⟩
apply big_k.isLimit.hom_ext
refine (PullbackCone.mk a b ?_ : PullbackCone (f₁ ≫ f₂) _).equalizer_ext ?_ ?_
· apply reassoc_of% comm
· apply m₁.trans (big_k.isLimit.fac s' WalkingCospan.left).symm
· apply m₂.trans (big_k.isLimit.fac s' WalkingCospan.right).symm⟩ }
/-- If `(a,b)` is a kernel pair for `f₁ ≫ f₂` and `f₂` is mono, then `(a,b)` is a kernel pair for
just `f₁`.
The converse of `comp_of_mono`.
-/
theorem cancel_right_of_mono {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} [Mono f₂]
(big_k : IsKernelPair (f₁ ≫ f₂) a b) : IsKernelPair f₁ a b :=
cancel_right (by rw [← cancel_mono f₂, assoc, assoc, big_k.w]) big_k
/--
If `(a,b)` is a kernel pair for `f₁` and `f₂` is mono, then `(a,b)` is a kernel pair for `f₁ ≫ f₂`.
The converse of `cancel_right_of_mono`.
-/
theorem comp_of_mono {f₁ : X ⟶ Y} {f₂ : Y ⟶ Z} [Mono f₂] (small_k : IsKernelPair f₁ a b) :
IsKernelPair (f₁ ≫ f₂) a b :=
{ w := by rw [small_k.w_assoc]
isLimit' := ⟨by
refine PullbackCone.isLimitAux _
(fun s => small_k.lift s.fst s.snd (by rw [← cancel_mono f₂, assoc, s.condition, assoc]))
(by simp) (by simp) ?_
intro s m hm
apply small_k.isLimit.hom_ext
apply PullbackCone.equalizer_ext small_k.cone _ _
· exact (hm WalkingCospan.left).trans (by simp)
· exact (hm WalkingCospan.right).trans (by simp)⟩ }
/--
If `(a,b)` is the kernel pair of `f`, and `f` is a coequalizer morphism for some parallel pair, then
`f` is a coequalizer morphism of `a` and `b`.
-/
def toCoequalizer (k : IsKernelPair f a b) [r : RegularEpi f] : IsColimit (Cofork.ofπ f k.w) := by
let t := k.isLimit.lift (PullbackCone.mk _ _ r.w)
have ht : t ≫ a = r.left := k.isLimit.fac _ WalkingCospan.left
have kt : t ≫ b = r.right := k.isLimit.fac _ WalkingCospan.right
refine Cofork.IsColimit.mk _
(fun s => Cofork.IsColimit.desc r.isColimit s.π
(by rw [← ht, assoc, s.condition, reassoc_of% kt]))
(fun s => ?_) (fun s m w => ?_)
· apply Cofork.IsColimit.π_desc' r.isColimit
· apply Cofork.IsColimit.hom_ext r.isColimit
exact w.trans (Cofork.IsColimit.π_desc' r.isColimit _ _).symm
/-- If `a₁ a₂ : A ⟶ Y` is a kernel pair for `g : Y ⟶ Z`, then `a₁ ×[Z] X` and `a₂ ×[Z] X`
(`A ×[Z] X ⟶ Y ×[Z] X`) is a kernel pair for `Y ×[Z] X ⟶ X`. -/
protected theorem pullback {X Y Z A : C} {g : Y ⟶ Z} {a₁ a₂ : A ⟶ Y} (h : IsKernelPair g a₁ a₂)
(f : X ⟶ Z) [HasPullback f g] [HasPullback f (a₁ ≫ g)] :
IsKernelPair (pullback.fst f g)
(pullback.map f _ f _ (𝟙 X) a₁ (𝟙 Z) (by simp) <| Category.comp_id _)
(pullback.map _ _ _ _ (𝟙 X) a₂ (𝟙 Z) (by simp) <| (Category.comp_id _).trans h.1.1) := by
refine ⟨⟨by rw [pullback.lift_fst, pullback.lift_fst]⟩, ⟨PullbackCone.isLimitAux _
(fun s => pullback.lift (s.fst ≫ pullback.fst _ _)
(h.lift (s.fst ≫ pullback.snd _ _) (s.snd ≫ pullback.snd _ _) ?_ ) ?_) (fun s => ?_)
(fun s => ?_) (fun s (m : _ ⟶ pullback f (a₁ ≫ g)) hm => ?_)⟩⟩
· simp_rw [Category.assoc, ← pullback.condition, ← Category.assoc, s.condition]
· simp only [assoc, lift_fst_assoc, pullback.condition]
· ext <;> simp
· ext
· simp [s.condition]
· simp
· apply pullback.hom_ext
· simpa using hm WalkingCospan.left =≫ pullback.fst f g
· apply PullbackCone.IsLimit.hom_ext h.isLimit
· simpa using hm WalkingCospan.left =≫ pullback.snd f g
· simpa using hm WalkingCospan.right =≫ pullback.snd f g
theorem mono_of_isIso_fst (h : IsKernelPair f a b) [IsIso a] : Mono f := by
obtain ⟨l, h₁, h₂⟩ := Limits.PullbackCone.IsLimit.lift' h.isLimit (𝟙 _) (𝟙 _) (by simp)
rw [IsPullback.cone_fst, ← IsIso.eq_comp_inv, Category.id_comp] at h₁
rw [h₁, IsIso.inv_comp_eq, Category.comp_id] at h₂
constructor
intro Z g₁ g₂ e
obtain ⟨l', rfl, rfl⟩ := Limits.PullbackCone.IsLimit.lift' h.isLimit _ _ e
rw [IsPullback.cone_fst, h₂]
theorem isIso_of_mono (h : IsKernelPair f a b) [Mono f] : IsIso a := by
rw [←
show _ = a from
(Category.comp_id _).symm.trans
((IsKernelPair.id_of_mono f).isLimit.conePointUniqueUpToIso_inv_comp h.isLimit
WalkingCospan.left)]
infer_instance
theorem of_isIso_of_mono [IsIso a] [Mono f] : IsKernelPair f a a := by
change IsPullback _ _ _ _
convert (IsPullback.of_horiz_isIso ⟨(rfl : a ≫ 𝟙 X = _ )⟩).paste_vert (IsKernelPair.id_of_mono f)
all_goals { simp }
end IsKernelPair
end CategoryTheory
|
separable.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import choice fintype tuple finfun bigop finset prime.
From mathcomp Require Import binomial ssralg poly polydiv fingroup perm.
From mathcomp Require Import morphism quotient gproduct finalg zmodp cyclic.
From mathcomp Require Import matrix mxalgebra mxpoly polyXY vector falgebra.
From mathcomp Require Import fieldext.
(******************************************************************************)
(* This file provides a theory of separable and inseparable field extensions. *)
(* *)
(* separable_poly p <=> p has no multiple roots in any field extension. *)
(* separable_element K x <=> the minimal polynomial of x over K is separable. *)
(* separable K E <=> every member of E is separable over K. *)
(* separable_generator K E == some x \in E that generates the largest *)
(* subfield K[x] that is separable over K. *)
(* purely_inseparable_element K x <=> there is a [pchar L].-nat n such that *)
(* x ^+ n \in K. *)
(* purely_inseparable K E <=> every member of E is purely inseparable over K. *)
(* *)
(* Derivations are introduced to prove the adjoin_separableP Lemma: *)
(* Derivation K D <=> the linear operator D satisfies the Leibniz *)
(* product rule inside K. *)
(* extendDerivation x D K == given a derivation D on K and a separable *)
(* element x over K, this function returns the *)
(* unique extension of D to K(x). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import GRing.Theory.
HB.lock
Definition separable_poly {R : idomainType} (p : {poly R}) := coprimep p p^`().
Canonical separable_poly_unlockable := Unlockable separable_poly.unlock.
Section SeparablePoly.
Variable R : idomainType.
Implicit Types p q d u v : {poly R}.
Local Notation separable := (@separable_poly R).
Local Notation lcn_neq0 := (Pdiv.Idomain.lc_expn_scalp_neq0 _).
Lemma separable_poly_neq0 p : separable p -> p != 0.
Proof.
by apply: contraTneq => ->; rewrite unlock deriv0 coprime0p eqp01.
Qed.
Lemma poly_square_freeP p :
(forall u v, u * v %| p -> coprimep u v)
<-> (forall u, size u != 1 -> ~~ (u ^+ 2 %| p)).
Proof.
split=> [sq'p u | sq'p u v dvd_uv_p].
by apply: contra => /sq'p; rewrite coprimepp.
rewrite coprimep_def (contraLR (sq'p _)) // (dvdp_trans _ dvd_uv_p) //.
by rewrite dvdp_mul ?dvdp_gcdl ?dvdp_gcdr.
Qed.
Lemma separable_polyP {p} :
reflect [/\ forall u v, u * v %| p -> coprimep u v
& forall u, u %| p -> 1 < size u -> u^`() != 0]
(separable p).
Proof.
apply: (iffP idP) => [sep_p | [sq'p nz_der1p]].
split=> [u v | u u_dv_p]; last first.
apply: contraTneq => u'0; rewrite unlock in sep_p; rewrite -leqNgt -(eqnP sep_p).
rewrite dvdp_leq -?size_poly_eq0 ?(eqnP sep_p) // dvdp_gcd u_dv_p.
have /dvdpZr <-: lead_coef u ^+ scalp p u != 0 by rewrite lcn_neq0.
by rewrite -derivZ -Pdiv.Idomain.divpK //= derivM u'0 mulr0 addr0 dvdp_mull.
rewrite Pdiv.Idomain.dvdp_eq mulrCA mulrA; set c := _ ^+ _ => /eqP Dcp.
have nz_c: c != 0 by rewrite lcn_neq0.
move: sep_p; rewrite coprimep_sym unlock -(coprimepZl _ _ nz_c).
rewrite -(coprimepZr _ _ nz_c) -derivZ Dcp derivM coprimepMl.
by rewrite coprimep_addl_mul !coprimepMr -andbA => /and4P[].
rewrite unlock coprimep_def eqn_leq size_poly_gt0; set g := gcdp _ _.
have nz_g: g != 0.
rewrite -dvd0p dvdp_gcd -(mulr0 0); apply/nandP; left.
by have /poly_square_freeP-> := sq'p; rewrite ?size_poly0.
have [g_p]: g %| p /\ g %| p^`() by rewrite dvdp_gcdr ?dvdp_gcdl.
pose c := lead_coef g ^+ scalp p g; have nz_c: c != 0 by rewrite lcn_neq0.
have Dcp: c *: p = p %/ g * g by rewrite Pdiv.Idomain.divpK.
rewrite nz_g andbT leqNgt -(dvdpZr _ _ nz_c) -derivZ Dcp derivM.
rewrite dvdp_addr; last by rewrite dvdp_mull.
rewrite Gauss_dvdpr; last by rewrite sq'p // mulrC -Dcp dvdpZl.
by apply: contraL => /nz_der1p nz_g'; rewrite gtNdvdp ?nz_g' ?lt_size_deriv.
Qed.
Lemma separable_coprime p u v : separable p -> u * v %| p -> coprimep u v.
Proof. by move=> /separable_polyP[sq'p _] /sq'p. Qed.
Lemma separable_nosquare p u k :
separable p -> 1 < k -> size u != 1 -> (u ^+ k %| p) = false.
Proof.
move=> /separable_polyP[/poly_square_freeP sq'p _] /subnKC <- /sq'p.
by apply: contraNF; apply: dvdp_trans; rewrite exprD dvdp_mulr.
Qed.
Lemma separable_deriv_eq0 p u :
separable p -> u %| p -> 1 < size u -> (u^`() == 0) = false.
Proof. by move=> /separable_polyP[_ nz_der1p] u_p /nz_der1p/negPf->. Qed.
Lemma dvdp_separable p q : q %| p -> separable p -> separable q.
Proof.
move=> /(dvdp_trans _)q_dv_p /separable_polyP[sq'p nz_der1p].
by apply/separable_polyP; split=> [u v /q_dv_p/sq'p | u /q_dv_p/nz_der1p].
Qed.
Lemma separable_mul p q :
separable (p * q) = [&& separable p, separable q & coprimep p q].
Proof.
apply/idP/and3P => [sep_pq | [sep_p sep_q co_pq]].
rewrite !(dvdp_separable _ sep_pq) ?dvdp_mulIr ?dvdp_mulIl //.
by rewrite (separable_coprime sep_pq).
rewrite unlock in sep_p sep_q *.
rewrite derivM coprimepMl {1}addrC mulrC !coprimep_addl_mul.
by rewrite !coprimepMr (coprimep_sym q p) co_pq !andbT; apply/andP.
Qed.
Lemma eqp_separable p q : p %= q -> separable p = separable q.
Proof. by case/andP=> p_q q_p; apply/idP/idP=> /dvdp_separable->. Qed.
Lemma separable_root p x :
separable (p * ('X - x%:P)) = separable p && ~~ root p x.
Proof.
rewrite separable_mul; apply: andb_id2l => seq_p.
by rewrite unlock derivXsubC coprimep1 coprimep_XsubC.
Qed.
Lemma separable_prod_XsubC (r : seq R) :
separable (\prod_(x <- r) ('X - x%:P)) = uniq r.
Proof.
elim: r => [|x r IH]; first by rewrite big_nil unlock /separable_poly coprime1p.
by rewrite big_cons mulrC separable_root IH root_prod_XsubC andbC.
Qed.
Lemma make_separable p : p != 0 -> separable (p %/ gcdp p p^`()).
Proof.
set g := gcdp p p^`() => nz_p; apply/separable_polyP.
have max_dvd_u (u : {poly R}): 1 < size u -> exists k, ~~ (u ^+ k %| p).
move=> u_gt1; exists (size p); rewrite gtNdvdp // polySpred //.
by rewrite -(ltn_subRL 1) subn1 size_exp leq_pmull // -(subnKC u_gt1).
split=> [|u u_pg u_gt1]; last first.
apply/eqP=> u'0 /=; have [k /negP[]] := max_dvd_u u u_gt1.
elim: k => [|k IHk]; first by rewrite dvd1p.
suffices: u ^+ k.+1 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite exprS dvdp_mul // dvdp_gcd IHk //=.
suffices: u ^+ k %| (p %/ u ^+ k * u ^+ k)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE u'0 mul0r mul0rn mulr0 addr0 dvdp_mull.
have pg_dv_p: p %/ g %| p by rewrite divp_dvd ?dvdp_gcdl.
apply/poly_square_freeP=> u; rewrite neq_ltn ltnS leqn0 size_poly_eq0.
case/predU1P=> [-> | /max_dvd_u[k]].
by apply: contra nz_p; rewrite expr0n -dvd0p => /dvdp_trans->.
apply: contra => u2_dv_pg; case: k; [by rewrite dvd1p | elim=> [|n IHn]].
exact: dvdp_trans (dvdp_mulr _ _) (dvdp_trans u2_dv_pg pg_dv_p).
suff: u ^+ n.+2 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite -add2n exprD dvdp_mul // dvdp_gcd.
rewrite (dvdp_trans _ IHn) ?exprS ?dvdp_mull //=.
suff: u ^+ n %| ((p %/ u ^+ n.+1) * u ^+ n.+1)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE dvdp_add // -1?mulr_natl ?exprS !dvdp_mull.
Qed.
End SeparablePoly.
Arguments separable_polyP {R p}.
Lemma separable_map (F : fieldType) (R : idomainType)
(f : {rmorphism F -> R}) (p : {poly F}) :
separable_poly (map_poly f p) = separable_poly p.
Proof.
by rewrite unlock deriv_map /coprimep -gcdp_map size_map_poly.
Qed.
Section InfinitePrimitiveElementTheorem.
Local Notation "p ^ f" := (map_poly f p) : ring_scope.
Variables (F L : fieldType) (iota : {rmorphism F -> L}).
Variables (x y : L) (p : {poly F}).
Hypotheses (nz_p : p != 0) (px_0 : root (p ^ iota) x).
Let inFz z w := exists q, (q ^ iota).[z] = w.
Lemma large_field_PET q :
root (q ^ iota) y -> separable_poly q ->
exists2 r, r != 0
& forall t (z := iota t * y - x), ~~ root r (iota t) -> inFz z x /\ inFz z y.
Proof.
move=> qy_0 sep_q; have nz_q := separable_poly_neq0 sep_q.
have /factor_theorem[q0 Dq] := qy_0.
set p1 := p ^ iota \Po ('X + x%:P); set q1 := q0 \Po ('X + y%:P).
have nz_p1: p1 != 0.
apply: contraNneq nz_p => /(canRL (fun r => comp_polyXaddC_K r _))/eqP.
by rewrite comp_poly0 map_poly_eq0.
have{sep_q} nz_q10: q1.[0] != 0.
move: sep_q; rewrite -(separable_map iota) Dq separable_root => /andP[_].
by rewrite horner_comp !hornerE.
have nz_q1: q1 != 0 by apply: contraNneq nz_q10 => ->; rewrite horner0.
pose p2 := p1 ^ polyC \Po ('X * 'Y); pose q2 := q1 ^ polyC.
have /Bezout_coprimepP[[u v]]: coprimep p2 q2.
rewrite coprimep_def eqn_leq leqNgt andbC size_poly_gt0 gcdp_eq0 poly_XmY_eq0.
by rewrite map_polyC_eq0 (negPf nz_p1) -resultant_eq0 div_annihilant_neq0.
rewrite -size_poly_eq1 => /size_poly1P[r nzr Dr]; exists r => {nzr}// t z nz_rt.
have [r1 nz_r1 r1z_0]: algebraicOver iota z.
apply/algebraic_sub; last by exists p.
by apply: algebraic_mul; [apply: algebraic_id | exists q].
pose Fz := subFExtend iota z r1; pose kappa : Fz -> L := subfx_inj.
pose kappa' := inj_subfx iota z r1.
have /eq_map_poly Diota: kappa \o kappa' =1 iota.
by move=> w; rewrite /kappa /= subfx_inj_eval // map_polyC hornerC.
suffices [y3]: exists y3, y = kappa y3.
have [q3 ->] := subfxE y3; rewrite /kappa subfx_inj_eval // => Dy.
split; [exists (t *: q3 - 'X) | by exists q3].
by rewrite rmorphB /= linearZ map_polyX !hornerE -Dy opprB addrC addrNK.
pose p0 := p ^ iota \Po (iota t *: 'X - z%:P).
have co_p0_q0: coprimep p0 q0.
pose at_t := horner_eval (iota t); have at_t0: at_t 0 = 0 by apply: rmorph0.
have /map_polyK polyCK: cancel polyC at_t by move=> w; apply: hornerC.
have ->: p0 = p2 ^ at_t \Po ('X - y%:P).
rewrite map_comp_poly polyCK // rmorphM /= map_polyC map_polyX /=.
rewrite horner_evalE hornerX.
rewrite -!comp_polyA comp_polyM comp_polyD !comp_polyC !comp_polyX.
by rewrite mulrC mulrBr mul_polyC addrAC -addrA -opprB -rmorphM -rmorphB.
have ->: q0 = q2 ^ at_t \Po ('X - y%:P) by rewrite polyCK ?comp_polyXaddC_K.
apply/coprimep_comp_poly/Bezout_coprimepP; exists (u ^ at_t, v ^ at_t).
by rewrite /= -!rmorphM -rmorphD Dr /= map_polyC polyC_eqp1.
have{co_p0_q0}: gcdp p0 (q ^ iota) %= 'X - y%:P.
rewrite /eqp Dq (eqp_dvdl _ (Gauss_gcdpr _ _)) // dvdp_gcdr dvdp_gcd.
rewrite dvdp_mull // -root_factor_theorem rootE horner_comp !hornerE.
by rewrite opprB addrC subrK.
have{p0} [p3 ->]: exists p3, p0 = p3 ^ kappa.
exists (p ^ kappa' \Po (kappa' t *: 'X - (subfx_eval iota z r1 'X)%:P)).
rewrite map_comp_poly rmorphB /= linearZ /= map_polyC map_polyX /=.
rewrite !subfx_inj_eval // map_polyC hornerC map_polyX hornerX.
by rewrite -map_poly_comp Diota.
rewrite -Diota map_poly_comp -gcdp_map /= -/kappa.
move: (gcdp _ _) => r3 /eqpf_eq[c nz_c Dr3].
exists (- (r3`_0 / r3`_1)); rewrite [kappa _]rmorphN fmorph_div -!coef_map Dr3.
by rewrite !coefZ polyseqXsubC mulr1 mulrC mulKf ?opprK.
Qed.
Lemma pchar0_PET (q : {poly F}) :
q != 0 -> root (q ^ iota) y -> [pchar F] =i pred0 ->
exists n, let z := y *+ n - x in inFz z x /\ inFz z y.
Proof.
move=> nz_q qy_0 /pcharf0P pcharF0.
without loss{nz_q} sep_q: q qy_0 / separable_poly q.
move=> IHq; apply: IHq (make_separable nz_q).
have /dvdpP[q1 Dq] := dvdp_gcdl q q^`().
rewrite {1}Dq mulpK ?gcdp_eq0; last by apply/nandP; left.
have [n [r nz_ry Dr]] := multiplicity_XsubC (q ^ iota) y.
rewrite map_poly_eq0 nz_q /= in nz_ry.
case: n => [|n] in Dr; first by rewrite Dr mulr1 (negPf nz_ry) in qy_0.
have: ('X - y%:P) ^+ n.+1 %| q ^ iota by rewrite Dr dvdp_mulIr.
rewrite Dq rmorphM /= gcdp_map -(eqp_dvdr _ (gcdp_mul2l _ _ _)) -deriv_map Dr.
rewrite dvdp_gcd derivM deriv_exp derivXsubC mul1r !mulrA dvdp_mulIr /=.
rewrite mulrDr mulrA dvdp_addr ?dvdp_mulIr // exprS -scaler_nat -!scalerAr.
rewrite dvdpZr -?(rmorph_nat iota) ?fmorph_eq0 ?pcharF0 //.
rewrite mulrA dvdp_mul2r ?expf_neq0 ?polyXsubC_eq0 //.
by rewrite Gauss_dvdpl ?dvdp_XsubCl // coprimep_sym coprimep_XsubC.
have [r nz_r PETxy] := large_field_PET qy_0 sep_q.
pose ts := mkseq (fun n => iota n%:R) (size r).
have /(max_ring_poly_roots nz_r)/=/implyP: uniq_roots ts.
rewrite uniq_rootsE mkseq_uniq // => m n eq_mn; apply/eqP; rewrite eqn_leq.
wlog suffices: m n eq_mn / m <= n by move=> IHmn; rewrite !IHmn.
move/fmorph_inj/eqP: eq_mn; rewrite -subr_eq0 leqNgt; apply: contraL => lt_mn.
by rewrite -natrB ?(ltnW lt_mn) // pcharF0 -lt0n subn_gt0.
rewrite size_mkseq ltnn implybF all_map => /allPn[n _ /= /PETxy].
by rewrite rmorph_nat mulr_natl; exists n.
Qed.
End InfinitePrimitiveElementTheorem.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar0_PET instead.")]
Notation char0_PET := (pchar0_PET) (only parsing).
Section Separable.
Variables (F : fieldType) (L : fieldExtType F).
Implicit Types (U V W : {vspace L}) (E K M : {subfield L}) (D : 'End(L)).
Section Derivation.
Variables (K : {vspace L}) (D : 'End(L)).
(* A deriviation only needs to be additive and satisfy Lebniz's law, but all *)
(* the deriviations used here are going to be linear, so we only define *)
(* the Derivation predicate for linear endomorphisms. *)
Definition Derivation : bool :=
all2rel (fun u v => D (u * v) == D u * v + u * D v) (vbasis K).
Hypothesis derD : Derivation.
Lemma Derivation_mul : {in K &, forall u v, D (u * v) = D u * v + u * D v}.
Proof.
move=> u v /coord_vbasis-> /coord_vbasis->.
rewrite !(mulr_sumr, linear_sum) -big_split; apply: eq_bigr => /= j _.
rewrite !mulr_suml linear_sum -big_split; apply: eq_bigr => /= i _.
rewrite !(=^~ scalerAl, linearZZ) -!scalerAr linearZZ -!scalerDr !scalerA /=.
by congr (_ *: _); apply/eqP/(allrelP derD); exact: memt_nth.
Qed.
Lemma Derivation_mul_poly (Dp := map_poly D) :
{in polyOver K &, forall p q, Dp (p * q) = Dp p * q + p * Dp q}.
Proof.
move=> p q Kp Kq; apply/polyP=> i; rewrite {}/Dp coefD coef_map /= !coefM.
rewrite linear_sum -big_split; apply: eq_bigr => /= j _.
by rewrite !{1}coef_map Derivation_mul ?(polyOverP _).
Qed.
End Derivation.
Lemma DerivationS E K D : (K <= E)%VS -> Derivation E D -> Derivation K D.
Proof.
move/subvP=> sKE derD; apply/allrelP=> x y Kx Ky; apply/eqP.
by rewrite (Derivation_mul derD) ?sKE // vbasis_mem.
Qed.
Section DerivationAlgebra.
Variables (E : {subfield L}) (D : 'End(L)).
Hypothesis derD : Derivation E D.
Lemma Derivation1 : D 1 = 0.
Proof.
apply: (addIr (D (1 * 1))); rewrite add0r {1}mul1r.
by rewrite (Derivation_mul derD) ?mem1v // mulr1 mul1r.
Qed.
Lemma Derivation_scalar x : x \in 1%VS -> D x = 0.
Proof. by case/vlineP=> y ->; rewrite linearZ /= Derivation1 scaler0. Qed.
Lemma Derivation_exp x m : x \in E -> D (x ^+ m) = x ^+ m.-1 *+ m * D x.
Proof.
move=> Ex; case: m; first by rewrite expr0 mulr0n mul0r Derivation1.
elim=> [|m IHm]; first by rewrite mul1r.
rewrite exprS (Derivation_mul derD) //; last by apply: rpredX.
by rewrite mulrC IHm mulrA mulrnAr -exprS -mulrDl.
Qed.
Lemma Derivation_horner p x :
p \is a polyOver E -> x \in E ->
D p.[x] = (map_poly D p).[x] + p^`().[x] * D x.
Proof.
move=> Ep Ex; elim/poly_ind: p Ep => [|p c IHp] /polyOverP EpXc.
by rewrite !(raddf0, horner0) mul0r add0r.
have Ep: p \is a polyOver E.
by apply/polyOverP=> i; have:= EpXc i.+1; rewrite coefD coefMX coefC addr0.
have->: map_poly D (p * 'X + c%:P) = map_poly D p * 'X + (D c)%:P.
apply/polyP=> i; rewrite !(coefD, coefMX, coef_map) /= linearD /= !coefC.
by rewrite !(fun_if D) linear0.
rewrite derivMXaddC !hornerE mulrDl mulrAC addrAC linearD /=; congr (_ + _).
by rewrite addrCA -mulrDl -IHp // addrC (Derivation_mul derD) ?rpred_horner.
Qed.
End DerivationAlgebra.
Definition separable_element U x := separable_poly (minPoly U x).
Section SeparableElement.
Variables (K : {subfield L}) (x : L).
(* begin hide *)
Let sKxK : (K <= <<K; x>>)%VS := subv_adjoin K x.
Let Kx_x : x \in <<K; x>>%VS := memv_adjoin K x.
(* end hide *)
Lemma separable_elementP :
reflect (exists f, [/\ f \is a polyOver K, root f x & separable_poly f])
(separable_element K x).
Proof.
apply: (iffP idP) => [sep_x | [f [Kf /(minPoly_dvdp Kf)/dvdpP[g ->]]]].
by exists (minPoly K x); rewrite minPolyOver root_minPoly.
by rewrite separable_mul => /and3P[].
Qed.
Lemma base_separable : x \in K -> separable_element K x.
Proof.
move=> Kx; apply/separable_elementP; exists ('X - x%:P).
by rewrite polyOverXsubC root_XsubC unlock !derivCE coprimep1.
Qed.
Lemma separable_nz_der : separable_element K x = ((minPoly K x)^`() != 0).
Proof.
rewrite /separable_element unlock.
apply/idP/idP=> [|nzPx'].
by apply: contraTneq => ->; rewrite coprimep0 -size_poly_eq1 size_minPoly.
have gcdK : gcdp (minPoly K x) (minPoly K x)^`() \in polyOver K.
by rewrite gcdp_polyOver ?polyOver_deriv // minPolyOver.
rewrite -gcdp_eqp1 -size_poly_eq1 -dvdp1.
have /orP[/andP[_]|/andP[]//] := minPoly_irr gcdK (dvdp_gcdl _ _).
rewrite dvdp_gcd dvdpp /= => /(dvdp_leq nzPx')/leq_trans/(_ (size_poly _ _)).
by rewrite size_minPoly ltnn.
Qed.
Lemma separablePn_pchar :
reflect (exists2 p, p \in [pchar L] &
exists2 g, g \is a polyOver K & minPoly K x = g \Po 'X^p)
(~~ separable_element K x).
Proof.
rewrite separable_nz_der negbK; set f := minPoly K x.
apply: (iffP eqP) => [f'0 | [p Hp [g _ ->]]]; last first.
by rewrite deriv_comp derivXn -scaler_nat (pcharf0 Hp) scale0r mulr0.
pose n := adjoin_degree K x; have sz_f: size f = n.+1 := size_minPoly K x.
have fn1: f`_n = 1 by rewrite -(monicP (monic_minPoly K x)) lead_coefE sz_f.
have dimKx: (adjoin_degree K x)%:R == 0 :> L.
by rewrite -(coef0 _ n.-1) -f'0 coef_deriv fn1.
have /natf0_pchar[// | p pcharLp] := dimKx.
have /dvdnP[r Dn]: (p %| n)%N by rewrite (dvdn_pcharf pcharLp).
exists p => //; exists (\poly_(i < r.+1) f`_(i * p)).
by apply: polyOver_poly => i _; rewrite (polyOverP _) ?minPolyOver.
rewrite comp_polyE size_poly_eq -?Dn ?fn1 ?oner_eq0 //.
have pr_p := pcharf_prime pcharLp; have p_gt0 := prime_gt0 pr_p.
apply/polyP=> i; rewrite coef_sum.
have [[{}i ->] | p'i] := altP (@dvdnP p i); last first.
rewrite big1 => [|j _]; last first.
rewrite coefZ -exprM coefXn [_ == _](contraNF _ p'i) ?mulr0 // => /eqP->.
by rewrite dvdn_mulr.
rewrite (dvdn_pcharf pcharLp) in p'i; apply: mulfI p'i _ _ _.
by rewrite mulr0 mulr_natl; case: i => // i; rewrite -coef_deriv f'0 coef0.
have [ltri | leir] := leqP r.+1 i.
rewrite nth_default ?sz_f ?Dn ?ltn_pmul2r ?big1 // => j _.
rewrite coefZ -exprM coefXn mulnC gtn_eqF ?mulr0 //.
by rewrite ltn_pmul2l ?(leq_trans _ ltri).
rewrite (bigD1 (Sub i _)) //= big1 ?addr0 => [|j i'j]; last first.
by rewrite coefZ -exprM coefXn mulnC eqn_pmul2l // mulr_natr mulrb ifN_eqC.
by rewrite coef_poly leir coefZ -exprM coefXn mulnC eqxx mulr1.
Qed.
Lemma separable_root_der : separable_element K x (+) root (minPoly K x)^`() x.
Proof.
have KpKx': _^`() \is a polyOver K := polyOver_deriv (minPolyOver K x).
rewrite separable_nz_der addNb (root_small_adjoin_poly KpKx') ?addbb //.
by rewrite (leq_trans (size_poly _ _)) ?size_minPoly.
Qed.
Lemma Derivation_separable D :
Derivation <<K; x>> D -> separable_element K x ->
D x = - (map_poly D (minPoly K x)).[x] / (minPoly K x)^`().[x].
Proof.
move=> derD sepKx; have:= separable_root_der; rewrite {}sepKx -sub0r => nzKx'x.
apply: canRL (mulfK nzKx'x) (canRL (addrK _) _); rewrite mulrC addrC.
rewrite -(Derivation_horner derD) ?minPolyxx ?linear0 //.
exact: polyOverSv sKxK _ (minPolyOver _ _).
Qed.
Section ExtendDerivation.
Variable D : 'End(L).
Let Dx E := - (map_poly D (minPoly E x)).[x] / ((minPoly E x)^`()).[x].
Fact extendDerivation_zmod_morphism_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
zmod_morphism body.
Proof.
move: Dx => C /= u v; rewrite /adjEx.
rewrite raddfB /= derivB -/adjEx !hornerE /= raddfB /= !hornerE.
by rewrite mulrBl addrACA opprD.
Qed.
Fact extendDerivation_scalable_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
scalable body.
Proof.
move: Dx => C /= a u; rewrite /adjEx linearZ /= derivZ -/adjEx.
rewrite hornerE -[RHS]mulr_algl mulrDr mulrA -[in RHS]hornerZ.
congr (_.[x] + _); apply/polyP=> i.
by rewrite coefZ !coef_map coefZ !mulr_algl /= linearZ.
Qed.
Section DerivationLinear.
Variable (E : {subfield L}).
Let body (y : L) (p := Fadjoin_poly E x y) : L :=
(map_poly D p).[x] + p^`().[x] * Dx E.
HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ body
(extendDerivation_zmod_morphism_subproof E).
HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ body
(extendDerivation_scalable_subproof E).
Let extendDerivationLinear := Eval hnf in (body : {linear _ -> _}).
Definition extendDerivation : 'End(L) := linfun extendDerivationLinear.
End DerivationLinear.
Hypothesis derD : Derivation K D.
Lemma extendDerivation_id y : y \in K -> extendDerivation K y = D y.
Proof.
move=> yK; rewrite lfunE /= Fadjoin_polyC // derivC map_polyC hornerC.
by rewrite horner0 mul0r addr0.
Qed.
Lemma extendDerivation_horner p :
p \is a polyOver K -> separable_element K x ->
extendDerivation K p.[x] = (map_poly D p).[x] + p^`().[x] * Dx K.
Proof.
move=> Kp sepKx; have:= separable_root_der; rewrite {}sepKx /= => nz_pKx'x.
rewrite [in RHS](divp_eq p (minPoly K x)) lfunE /= Fadjoin_poly_mod ?raddfD //=.
rewrite (Derivation_mul_poly derD) ?divp_polyOver ?minPolyOver //.
rewrite derivM !{1}hornerD !{1}hornerM minPolyxx !{1}mulr0 !{1}add0r.
rewrite mulrDl addrA [_ + (_ * _ * _)]addrC {2}/Dx -mulrA -/Dx.
by rewrite [_ / _]mulrC (mulVKf nz_pKx'x) mulrN addKr.
Qed.
Lemma extendDerivationP :
separable_element K x -> Derivation <<K; x>> (extendDerivation K).
Proof.
move=> sep; apply/allrelP=> u v /vbasis_mem Hu /vbasis_mem Hv; apply/eqP.
rewrite -(Fadjoin_poly_eq Hu) -(Fadjoin_poly_eq Hv) -hornerM.
rewrite !{1}extendDerivation_horner ?{1}rpredM ?Fadjoin_polyOver //.
rewrite (Derivation_mul_poly derD) ?Fadjoin_polyOver //.
rewrite derivM !{1}hornerD !{1}hornerM !{1}mulrDl !{1}mulrDr -!addrA.
congr (_ + _); rewrite [Dx K]lock -!{1}mulrA !{1}addrA; congr (_ + _).
by rewrite addrC; congr (_ * _ + _); rewrite mulrC.
Qed.
End ExtendDerivation.
(* Reference:
http://www.math.uconn.edu/~kconrad/blurbs/galoistheory/separable2.pdf *)
Lemma Derivation_separableP :
reflect
(forall D, Derivation <<K; x>> D -> K <= lker D -> <<K; x>> <= lker D)%VS
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx D derD /subvP DK_0 | derKx_0].
have{} DK_0 q: q \is a polyOver K -> map_poly D q = 0.
move=> /polyOverP Kq; apply/polyP=> i; apply/eqP.
by rewrite coef0 coef_map -memv_ker DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->]; rewrite memv_ker.
rewrite (Derivation_horner derD) ?(polyOverSv sKxK) //.
rewrite (Derivation_separable derD sepKx) !DK_0 ?minPolyOver //.
by rewrite horner0 oppr0 mul0r mulr0 addr0.
apply: wlog_neg; rewrite {1}separable_nz_der negbK => /eqP pKx'_0.
pose Df := fun y => (Fadjoin_poly K x y)^`().[x].
have Dlin: linear Df.
move=> a u v; rewrite /Df linearP /= -mul_polyC derivD derivM derivC.
by rewrite mul0r add0r hornerD hornerM hornerC -scalerAl mul1r.
pose DlinM := GRing.isLinear.Build _ _ _ _ Df Dlin.
pose DL : {linear _ -> _} := HB.pack Df DlinM.
pose D := linfun DL; apply: base_separable.
have DK_0: (K <= lker D)%VS.
apply/subvP=> v Kv; rewrite memv_ker lfunE /= /Df Fadjoin_polyC //.
by rewrite derivC horner0.
have Dder: Derivation <<K; x>> D.
apply/allrelP=> u v /vbasis_mem Kx_u /vbasis_mem Kx_v; apply/eqP.
rewrite !lfunE /= /Df; set Px := Fadjoin_poly K x.
set Px_u := Px u; rewrite -(Fadjoin_poly_eq Kx_u) -/Px -/Px_u.
set Px_v := Px v; rewrite -(Fadjoin_poly_eq Kx_v) -/Px -/Px_v.
rewrite -!hornerM -hornerD -derivM.
rewrite /Px Fadjoin_poly_mod ?rpredM ?Fadjoin_polyOver //.
rewrite [in RHS](divp_eq (Px_u * Px_v) (minPoly K x)) derivD derivM.
by rewrite pKx'_0 mulr0 addr0 hornerD hornerM minPolyxx mulr0 add0r.
have{Dder DK_0}: x \in lker D by apply: subvP Kx_x; apply: derKx_0.
apply: contraLR => K'x; rewrite memv_ker lfunE /= /Df Fadjoin_polyX //.
by rewrite derivX hornerC oner_eq0.
Qed.
End SeparableElement.
#[deprecated(since="mathcomp 2.4.0", note="Use separablePn_pchar instead.")]
Notation separablePn := (separablePn_pchar) (only parsing).
Arguments separable_elementP {K x}.
Lemma separable_elementS K E x :
(K <= E)%VS -> separable_element K x -> separable_element E x.
Proof.
move=> sKE /separable_elementP[f [fK rootf sepf]]; apply/separable_elementP.
by exists f; rewrite (polyOverSv sKE).
Qed.
Lemma adjoin_separableP {K x} :
reflect (forall y, y \in <<K; x>>%VS -> separable_element K y)
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx | -> //]; last exact: memv_adjoin.
move=> _ /Fadjoin_polyP[q Kq ->]; apply/Derivation_separableP=> D derD DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->].
rewrite memv_ker -(extendDerivation_id x D (mempx_Fadjoin _ Kp)).
have sepFyx: (separable_element <<K; q.[x]>> x).
by apply: (separable_elementS (subv_adjoin _ _)).
have KyxEqKx: (<< <<K; q.[x]>>; x>> = <<K; x>>)%VS.
apply/eqP; rewrite eqEsubv andbC adjoinSl ?subv_adjoin //=.
apply/FadjoinP/andP; rewrite memv_adjoin andbT.
by apply/FadjoinP/andP; rewrite subv_adjoin mempx_Fadjoin.
have /[!KyxEqKx] derDx := extendDerivationP derD sepFyx.
rewrite -horner_comp (Derivation_horner derDx) ?memv_adjoin //; last first.
by apply: (polyOverSv (subv_adjoin _ _)); apply: polyOver_comp.
set Dx_p := map_poly _; have Dx_p_0 t: t \is a polyOver K -> (Dx_p t).[x] = 0.
move/polyOverP=> Kt; congr (_.[x] = 0): (horner0 x); apply/esym/polyP => i.
have /eqP Dti_0: D t`_i == 0 by rewrite -memv_ker (subvP DK_0) ?Kt.
by rewrite coef0 coef_map /= {1}extendDerivation_id ?subvP_adjoin.
rewrite (Derivation_separable derDx sepKx) -/Dx_p Dx_p_0 ?polyOver_comp //.
by rewrite add0r mulrCA Dx_p_0 ?minPolyOver ?oppr0 ?mul0r.
Qed.
Lemma separable_exponent_pchar K x :
exists n, [pchar L].-nat n && separable_element K (x ^+ n).
Proof.
pose d := adjoin_degree K x; move: {2}d.+1 (ltnSn d) => n.
elim: n => // n IHn in x @d *; rewrite ltnS => le_d_n.
have [[p pcharLp]|] := altP (separablePn_pchar K x); last by rewrite negbK; exists 1.
case=> g Kg defKx; have p_pr := pcharf_prime pcharLp.
suffices /IHn[m /andP[pcharLm sepKxpm]]: adjoin_degree K (x ^+ p) < n.
by exists (p * m)%N; rewrite pnatM pnatE // pcharLp pcharLm exprM.
apply: leq_trans le_d_n; rewrite -ltnS -!size_minPoly.
have nzKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have nzg: g != 0 by apply: contra_eqN defKx => /eqP->; rewrite comp_poly0.
apply: leq_ltn_trans (dvdp_leq nzg _) _.
by rewrite minPoly_dvdp // rootE -hornerXn -horner_comp -defKx minPolyxx.
rewrite (polySpred nzKx) ltnS defKx size_comp_poly size_polyXn /=.
suffices g_gt1: 1 < size g by rewrite -(subnKC g_gt1) ltn_Pmulr ?prime_gt1.
apply: contra_eqT (size_minPoly K x); rewrite defKx -leqNgt => /size1_polyC->.
by rewrite comp_polyC size_polyC; case: (_ != 0).
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use separable_exponent_pchar instead.")]
Notation separable_exponent := (separable_exponent_pchar) (only parsing).
Lemma pcharf0_separable K : [pchar L] =i pred0 -> forall x, separable_element K x.
Proof.
move=> pcharL0 x; have [n /andP[pcharLn]] := separable_exponent_pchar K x.
by rewrite (pnat_1 pcharLn (sub_in_pnat _ pcharLn)) // => p _; rewrite pcharL0.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0_separable instead.")]
Notation charf0_separable := (pcharf0_separable) (only parsing).
Lemma pcharf_p_separable K x e p :
p \in [pchar L] -> separable_element K x = (x \in <<K; x ^+ (p ^ e.+1)>>%VS).
Proof.
move=> pcharLp; apply/idP/idP=> [sepKx | /Fadjoin_poly_eq]; last first.
set m := p ^ _; set f := Fadjoin_poly K _ x => Dx; apply/separable_elementP.
have mL0: m%:R = 0 :> L by apply/eqP; rewrite -(dvdn_pcharf pcharLp) dvdn_exp.
exists ('X - (f \Po 'X^m)); split.
- by rewrite rpredB ?polyOver_comp ?rpredX ?polyOverX ?Fadjoin_polyOver.
- by rewrite rootE !hornerE horner_comp hornerXn Dx subrr.
rewrite unlock !(derivE, deriv_comp) -mulr_natr -rmorphMn /= mL0.
by rewrite !mulr0 subr0 coprimep1.
without loss{e} ->: e x sepKx / e = 0.
move=> IH; elim: {e}e.+1 => [|e]; [exact: memv_adjoin | apply: subvP].
apply/FadjoinP/andP; rewrite subv_adjoin expnSr exprM (IH 0) //.
by have /adjoin_separableP-> := sepKx; rewrite ?rpredX ?memv_adjoin.
set K' := <<K; x ^+ p>>%VS; have sKK': (K <= K')%VS := subv_adjoin _ _.
pose q := minPoly K' x; pose g := 'X^p - (x ^+ p)%:P.
have [K'g]: g \is a polyOver K' /\ q \is a polyOver K'.
by rewrite minPolyOver rpredB ?rpredX ?polyOverX // polyOverC memv_adjoin.
have /dvdpP[c Dq]: 'X - x%:P %| q by rewrite dvdp_XsubCl root_minPoly.
have co_c_g: coprimep c g.
have pcharPp: p \in [pchar {poly L}] := rmorph_pchar polyC pcharLp.
rewrite /g polyC_exp -!(pFrobenius_autE pcharPp) -rmorphB coprimep_expr //.
have: separable_poly q := separable_elementS sKK' sepKx.
by rewrite Dq separable_mul => /and3P[].
have{g K'g co_c_g} /size_poly1P[a nz_a Dc]: size c == 1.
suffices c_dv_g: c %| g by rewrite -(eqp_size (dvdp_gcd_idl c_dv_g)).
have: q %| g by rewrite minPoly_dvdp // rootE !hornerE subrr.
by apply: dvdp_trans; rewrite Dq dvdp_mulIl.
rewrite {q}Dq {c}Dc mulrBr -rmorphM -rmorphN -cons_poly_def qualifE /=.
by rewrite polyseq_cons !polyseqC nz_a /= rpredN andbCA => /and3P[/fpredMl->].
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_p_separable instead.")]
Notation charf_p_separable := (pcharf_p_separable) (only parsing).
Lemma pcharf_n_separable K x n :
[pchar L].-nat n -> 1 < n -> separable_element K x = (x \in <<K; x ^+ n>>%VS).
Proof.
rewrite -pi_pdiv; set p := pdiv n => pcharLn pi_n_p.
have pcharLp: p \in [pchar L] := pnatPpi pcharLn pi_n_p.
have <-: (n`_p)%N = n by rewrite -(eq_partn n (pcharf_eq pcharLp)) part_pnat_id.
by rewrite p_part lognE -mem_primes pi_n_p -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_n_separable instead.")]
Notation charf_n_separable := (pcharf_n_separable) (only parsing).
Definition purely_inseparable_element U x :=
x ^+ ex_minn (separable_exponent_pchar <<U>> x) \in U.
Lemma purely_inseparable_elementP_pchar {K x} :
reflect (exists2 n, [pchar L].-nat n & x ^+ n \in K)
(purely_inseparable_element K x).
Proof.
rewrite /purely_inseparable_element.
case: ex_minnP => n /andP[pcharLn /=]; rewrite subfield_closed => sepKxn min_xn.
apply: (iffP idP) => [Kxn | [m pcharLm Kxm]]; first by exists n.
have{min_xn}: n <= m by rewrite min_xn ?pcharLm ?base_separable.
rewrite leq_eqVlt => /predU1P[-> // | ltnm]; pose p := pdiv m.
have m_gt1: 1 < m by have [/leq_ltn_trans->] := andP pcharLn.
have pcharLp: p \in [pchar L] by rewrite (pnatPpi pcharLm) ?pi_pdiv.
have [/p_natP[em Dm] /p_natP[en Dn]]: p.-nat m /\ p.-nat n.
by rewrite -!(eq_pnat _ (pcharf_eq pcharLp)).
rewrite Dn Dm ltn_exp2l ?prime_gt1 ?pdiv_prime // in ltnm.
rewrite -(Fadjoin_idP Kxm) Dm -(subnKC ltnm) addSnnS expnD exprM -Dn.
by rewrite -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use purely_inseparable_elementP_pchar instead.")]
Notation purely_inseparable_elementP := (purely_inseparable_elementP_pchar) (only parsing).
Lemma separable_inseparable_element K x :
separable_element K x && purely_inseparable_element K x = (x \in K).
Proof.
rewrite /purely_inseparable_element; case: ex_minnP => [[|m]] //=.
rewrite subfield_closed; case: m => /= [-> //| m _ /(_ 1)/implyP/= insepKx].
by rewrite (negPf insepKx) (contraNF (@base_separable K x) insepKx).
Qed.
Lemma base_inseparable K x : x \in K -> purely_inseparable_element K x.
Proof. by rewrite -separable_inseparable_element => /andP[]. Qed.
Lemma sub_inseparable K E x :
(K <= E)%VS -> purely_inseparable_element K x ->
purely_inseparable_element E x.
Proof.
move/subvP=> sKE /purely_inseparable_elementP_pchar[n pcharLn /sKE Exn].
by apply/purely_inseparable_elementP_pchar; exists n.
Qed.
Section PrimitiveElementTheorem.
Variables (K : {subfield L}) (x y : L).
Section FiniteCase.
Variable N : nat.
Let K_is_large := exists s, [/\ uniq s, {subset s <= K} & N < size s].
Let cyclic_or_large (z : L) : z != 0 -> K_is_large \/ exists a, z ^+ a.+1 = 1.
Proof.
move=> nz_z; pose d := adjoin_degree K z.
pose h0 (i : 'I_(N ^ d).+1) (j : 'I_d) := (Fadjoin_poly K z (z ^+ i))`_j.
pose s := undup [seq h0 i j | i <- enum 'I_(N ^ d).+1, j <- enum 'I_d].
have s_h0 i j: h0 i j \in s.
by rewrite mem_undup; apply/allpairsP; exists (i, j); rewrite !mem_enum.
pose h i := [ffun j => Ordinal (etrans (index_mem _ _) (s_h0 i j))].
pose h' (f : {ffun 'I_d -> 'I_(size s)}) := \sum_(j < d) s`_(f j) * z ^+ j.
have hK i: h' (h i) = z ^+ i.
have Kz_zi: z ^+ i \in <<K; z>>%VS by rewrite rpredX ?memv_adjoin.
rewrite -(Fadjoin_poly_eq Kz_zi) (horner_coef_wide z (size_poly _ _)) -/d.
by apply: eq_bigr => j _; rewrite ffunE /= nth_index.
have [inj_h | ] := altP (@injectiveP _ _ h).
left; exists s; split=> [|zi_j|]; rewrite ?undup_uniq ?mem_undup //=.
by case/allpairsP=> ij [_ _ ->]; apply/polyOverP/Fadjoin_polyOver.
rewrite -[size s]card_ord -(@ltn_exp2r _ _ d) // -{2}[d]card_ord -card_ffun.
by rewrite -[_.+1]card_ord -(card_image inj_h) max_card.
case/injectivePn=> i1 [i2 i1'2 /(congr1 h')]; rewrite !hK => eq_zi12; right.
without loss{i1'2} lti12: i1 i2 eq_zi12 / i1 < i2.
by move=> IH; move: i1'2; rewrite neq_ltn => /orP[]; apply: IH.
by exists (i2 - i1.+1)%N; rewrite subnSK ?expfB // eq_zi12 divff ?expf_neq0.
Qed.
Lemma finite_PET : K_is_large \/ exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have [-> | /cyclic_or_large[|[a Dxa]]] := eqVneq x 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists y.
have [-> | /cyclic_or_large[|[b Dyb]]] := eqVneq y 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists x.
pose h0 (ij : 'I_a.+1 * 'I_b.+1) := x ^+ ij.1 * y ^+ ij.2.
pose H := <<[set ij | h0 ij == 1%R]>>%G; pose h (u : coset_of H) := h0 (repr u).
have h0M: {morph h0: ij1 ij2 / (ij1 * ij2)%g >-> ij1 * ij2}.
by rewrite /h0 => [] [i1 j1] [i2 j2] /=; rewrite mulrACA -!exprD !expr_mod.
have memH ij: (ij \in H) = (h0 ij == 1).
rewrite /= gen_set_id ?inE //; apply/group_setP; rewrite inE [h0 _]mulr1.
by split=> // ? ? /[!(inE, h0M)] /eqP-> /eqP->; rewrite mulr1.
have nH ij: ij \in 'N(H)%g.
by apply/(subsetP (cent_sub _))/centP=> ij1 _; congr (_, _); rewrite Zp_mulgC.
have hE ij: h (coset H ij) = h0 ij.
rewrite /h val_coset //; case: repr_rcosetP => ij1.
by rewrite memH h0M => /eqP->; rewrite mul1r.
have h1: h 1%g = 1 by rewrite /h repr_coset1 [h0 _]mulr1.
have hM: {morph h: u v / (u * v)%g >-> u * v}.
by do 2![move=> u; have{u} [? _ ->] := cosetP u]; rewrite -morphM // !hE h0M.
have /cyclicP[w defW]: cyclic [set: coset_of H].
apply: field_mul_group_cyclic (in2W hM) _ => u _; have [ij _ ->] := cosetP u.
by split=> [/eqP | -> //]; rewrite hE -memH => /coset_id.
have Kw_h ij t: h0 ij = t -> t \in <<K; h w>>%VS.
have /cycleP[k Dk]: coset H ij \in <[w]>%g by rewrite -defW inE.
rewrite -hE {}Dk => <-; elim: k => [|k IHk]; first by rewrite h1 rpred1.
by rewrite expgS hM rpredM // memv_adjoin.
right; exists (h w); apply/eqP; rewrite eqEsubv !(sameP FadjoinP andP).
rewrite subv_adjoin (subv_trans (subv_adjoin K y)) ?subv_adjoin //=.
rewrite (Kw_h (0, inZp 1)) 1?(Kw_h (inZp 1, 0)) /h0 ?mulr1 ?mul1r ?expr_mod //=.
by rewrite rpredM ?rpredX ?memv_adjoin // subvP_adjoin ?memv_adjoin.
Qed.
End FiniteCase.
Hypothesis sepKy : separable_element K y.
Lemma Primitive_Element_Theorem : exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have /polyOver_subvs[p Dp]: minPoly K x \is a polyOver K := minPolyOver K x.
have nz_pKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have{nz_pKx} nz_p: p != 0 by rewrite Dp map_poly_eq0 in nz_pKx.
have{Dp} px0: root (map_poly vsval p) x by rewrite -Dp root_minPoly.
have [q0 [Kq0 q0y0 sepKq0]] := separable_elementP sepKy.
have /polyOver_subvs[q Dq]: minPoly K y \is a polyOver K := minPolyOver K y.
have qy0: root (map_poly vsval q) y by rewrite -Dq root_minPoly.
have sep_pKy: separable_poly (minPoly K y).
by rewrite (dvdp_separable _ sepKq0) ?minPoly_dvdp.
have{sep_pKy} sep_q: separable_poly q by rewrite Dq separable_map in sep_pKy.
have [r nz_r PETr] := large_field_PET nz_p px0 qy0 sep_q.
have [[s [Us Ks /ltnW leNs]] | //] := finite_PET (size r).
have{s Us leNs} /allPn[t {}/Ks Kt nz_rt]: ~~ all (root r) s.
by apply: contraTN leNs; rewrite -ltnNge => /max_poly_roots->.
have{PETr} [/= [p1 Dx] [q1 Dy]] := PETr (Subvs Kt) nz_rt.
set z := t * y - x in Dx Dy; exists z; apply/eqP.
rewrite eqEsubv !(sameP FadjoinP andP) subv_adjoin.
have Kz_p1z (r1 : {poly subvs_of K}): (map_poly vsval r1).[z] \in <<K; z>>%VS.
rewrite rpred_horner ?memv_adjoin ?(polyOverSv (subv_adjoin K z)) //.
by apply/polyOver_subvs; exists r1.
rewrite -{1}Dx -{1}Dy !{Dx Dy}Kz_p1z /=.
rewrite (subv_trans (subv_adjoin K y)) ?subv_adjoin // rpredB ?memv_adjoin //.
by rewrite subvP_adjoin // rpredM ?memv_adjoin ?subvP_adjoin.
Qed.
Lemma adjoin_separable : separable_element <<K; y>> x -> separable_element K x.
Proof.
have /Derivation_separableP derKy := sepKy => /Derivation_separableP derKy_x.
have [z defKz] := Primitive_Element_Theorem.
suffices /adjoin_separableP: separable_element K z.
by apply; rewrite -defKz memv_adjoin.
apply/Derivation_separableP=> D; rewrite -defKz => derKxyD DK_0.
suffices derKyD: Derivation <<K; y>>%VS D by rewrite derKy_x // derKy.
by apply: DerivationS derKxyD; apply: subv_adjoin.
Qed.
End PrimitiveElementTheorem.
Lemma strong_Primitive_Element_Theorem K x y :
separable_element <<K; x>> y ->
exists2 z : L, (<< <<K; y>>; x>> = <<K; z>>)%VS
& separable_element K x -> separable_element K y.
Proof.
move=> sepKx_y; have [n /andP[pcharLn sepKyn]] := separable_exponent_pchar K y.
have adjK_C z t: (<<<<K; z>>; t>> = <<<<K; t>>; z>>)%VS.
by rewrite !agenv_add_id -!addvA (addvC <[_]>%VS).
have [z defKz] := Primitive_Element_Theorem x sepKyn.
exists z => [|/adjoin_separable->]; rewrite ?sepKx_y // -defKz.
have [|n_gt1|-> //] := ltngtP n 1; first by case: (n) pcharLn.
apply/eqP; rewrite !(adjK_C _ x) eqEsubv; apply/andP.
split; apply/FadjoinP/andP; rewrite subv_adjoin ?rpredX ?memv_adjoin //=.
by rewrite -pcharf_n_separable ?sepKx_y.
Qed.
Definition separable U W : bool :=
all (separable_element U) (vbasis W).
Definition purely_inseparable U W : bool :=
all (purely_inseparable_element U) (vbasis W).
Lemma separable_add K x y :
separable_element K x -> separable_element K y -> separable_element K (x + y).
Proof.
move/(separable_elementS (subv_adjoin K y))=> sepKy_x sepKy.
have [z defKz] := Primitive_Element_Theorem x sepKy.
have /(adjoin_separableP _): x + y \in <<K; z>>%VS.
by rewrite -defKz rpredD ?memv_adjoin // subvP_adjoin ?memv_adjoin.
apply; apply: adjoin_separable sepKy (adjoin_separable sepKy_x _).
by rewrite defKz base_separable ?memv_adjoin.
Qed.
Lemma separable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> separable_element K (v_ i)) ->
separable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> sepKi.
by elim/big_ind: _; [apply/base_separable/mem0v | apply: separable_add |].
Qed.
Lemma inseparable_add K x y :
purely_inseparable_element K x -> purely_inseparable_element K y ->
purely_inseparable_element K (x + y).
Proof.
have insepP := purely_inseparable_elementP_pchar.
move=> /insepP[n pcharLn Kxn] /insepP[m pcharLm Kym]; apply/insepP.
have pcharLnm: [pchar L].-nat (n * m)%N by rewrite pnatM pcharLn.
by exists (n * m)%N; rewrite ?exprDn_pchar // {2}mulnC !exprM memvD // rpredX.
Qed.
Lemma inseparable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> purely_inseparable_element K (v_ i)) ->
purely_inseparable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> insepKi.
by elim/big_ind: _; [apply/base_inseparable/mem0v | apply: inseparable_add |].
Qed.
Lemma separableP {K E} :
reflect (forall y, y \in E -> separable_element K y) (separable K E).
Proof.
apply/(iffP idP)=> [/allP|] sepK_E; last by apply/allP=> x /vbasis_mem/sepK_E.
move=> y /coord_vbasis->; apply/separable_sum=> i _.
have: separable_element K (vbasis E)`_i by apply/sepK_E/memt_nth.
by move/adjoin_separableP; apply; rewrite rpredZ ?memv_adjoin.
Qed.
Lemma purely_inseparableP {K E} :
reflect (forall y, y \in E -> purely_inseparable_element K y)
(purely_inseparable K E).
Proof.
apply/(iffP idP)=> [/allP|] sep'K_E; last by apply/allP=> x /vbasis_mem/sep'K_E.
move=> y /coord_vbasis->; apply/inseparable_sum=> i _.
have: purely_inseparable_element K (vbasis E)`_i by apply/sep'K_E/memt_nth.
case/purely_inseparable_elementP_pchar=> n pcharLn K_Ein.
by apply/purely_inseparable_elementP_pchar; exists n; rewrite // exprZn rpredZ.
Qed.
Lemma adjoin_separable_eq K x : separable_element K x = separable K <<K; x>>%VS.
Proof. exact: sameP adjoin_separableP separableP. Qed.
Lemma separable_inseparable_decomposition E K :
{x | x \in E /\ separable_element K x & purely_inseparable <<K; x>> E}.
Proof.
without loss sKE: K / (K <= E)%VS.
case/(_ _ (capvSr K E)) => x [Ex sepKEx] /purely_inseparableP sep'KExE.
exists x; first by split; last exact/(separable_elementS _ sepKEx)/capvSl.
apply/purely_inseparableP=> y /sep'KExE; apply: sub_inseparable.
exact/adjoinSl/capvSl.
pose E_ i := (vbasis E)`_i; pose fP i := separable_exponent_pchar K (E_ i).
pose f i := E_ i ^+ ex_minn (fP i); pose s := mkseq f (\dim E).
pose K' := <<K & s>>%VS.
have sepKs: all (separable_element K) s.
by rewrite all_map /f; apply/allP=> i _ /=; case: ex_minnP => m /andP[].
have [x sepKx defKx]: {x | x \in E /\ separable_element K x & K' = <<K; x>>%VS}.
have: all [in E] s.
rewrite all_map; apply/allP=> i; rewrite mem_iota => ltis /=.
by rewrite rpredX // vbasis_mem // memt_nth.
rewrite {}/K'; elim/last_ind: s sepKs => [|s t IHs].
by exists 0; [rewrite base_separable mem0v | rewrite adjoin_nil addv0].
rewrite adjoin_rcons !all_rcons => /andP[sepKt sepKs] /andP[/= Et Es].
have{IHs sepKs Es} [y [Ey sepKy] ->{s}] := IHs sepKs Es.
have /sig_eqW[x defKx] := Primitive_Element_Theorem t sepKy.
exists x; [split | exact: defKx].
suffices: (<<K; x>> <= E)%VS by case/FadjoinP.
by rewrite -defKx !(sameP FadjoinP andP) sKE Ey Et.
apply/adjoin_separableP=> z; rewrite -defKx => Kyt_z.
apply: adjoin_separable sepKy _; apply: adjoin_separableP Kyt_z.
exact: separable_elementS (subv_adjoin K y) sepKt.
exists x; rewrite // -defKx; apply/(all_nthP 0)=> i; rewrite size_tuple => ltiE.
apply/purely_inseparable_elementP_pchar.
exists (ex_minn (fP i)); first by case: ex_minnP => n /andP[].
by apply/seqv_sub_adjoin/map_f; rewrite mem_iota.
Qed.
Definition separable_generator K E : L :=
s2val (locked (separable_inseparable_decomposition E K)).
Lemma separable_generator_mem E K : separable_generator K E \in E.
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generatorP E K : separable_element K (separable_generator K E).
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generator_maximal E K :
purely_inseparable <<K; separable_generator K E>> E.
Proof. by rewrite /separable_generator; case: (locked _). Qed.
Lemma sub_adjoin_separable_generator E K :
separable K E -> (E <= <<K; separable_generator K E>>)%VS.
Proof.
move/separableP=> sepK_E; apply/subvP=> v Ev.
rewrite -separable_inseparable_element.
have /purely_inseparableP-> // := separable_generator_maximal E K.
by rewrite (separable_elementS _ (sepK_E _ Ev)) // subv_adjoin.
Qed.
Lemma eq_adjoin_separable_generator E K :
separable K E -> (K <= E)%VS ->
E = <<K; separable_generator K E>>%VS :> {vspace _}.
Proof.
move=> sepK_E sKE; apply/eqP; rewrite eqEsubv sub_adjoin_separable_generator //.
by apply/FadjoinP/andP; rewrite sKE separable_generator_mem.
Qed.
Lemma separable_refl K : separable K K.
Proof. exact/separableP/base_separable. Qed.
Lemma separable_trans M K E : separable K M -> separable M E -> separable K E.
Proof.
move/sub_adjoin_separable_generator.
set x := separable_generator K M => sMKx /separableP sepM_E.
apply/separableP => w /sepM_E/(separable_elementS sMKx).
case/strong_Primitive_Element_Theorem => _ _ -> //.
exact: separable_generatorP.
Qed.
Lemma separableS K1 K2 E2 E1 :
(K1 <= K2)%VS -> (E2 <= E1)%VS -> separable K1 E1 -> separable K2 E2.
Proof.
move=> sK12 /subvP sE21 /separableP sepK1_E1.
by apply/separableP=> y /sE21/sepK1_E1/(separable_elementS sK12).
Qed.
Lemma separableSl K M E : (K <= M)%VS -> separable K E -> separable M E.
Proof. by move/separableS; apply. Qed.
Lemma separableSr K M E : (M <= E)%VS -> separable K E -> separable K M.
Proof. exact: separableS. Qed.
Lemma separable_Fadjoin_seq K rs :
all (separable_element K) rs -> separable K <<K & rs>>.
Proof.
elim/last_ind: rs => [|s x IHs] in K *.
by rewrite adjoin_nil subfield_closed separable_refl.
rewrite all_rcons adjoin_rcons => /andP[sepKx /IHs/separable_trans-> //].
by rewrite -adjoin_separable_eq (separable_elementS _ sepKx) ?subv_adjoin_seq.
Qed.
Lemma purely_inseparable_refl K : purely_inseparable K K.
Proof. by apply/purely_inseparableP; apply: base_inseparable. Qed.
Lemma purely_inseparable_trans M K E :
purely_inseparable K M -> purely_inseparable M E -> purely_inseparable K E.
Proof.
have insepP := purely_inseparableP => /insepP insepK_M /insepP insepM_E.
have insepPe := purely_inseparable_elementP_pchar.
apply/insepP=> x /insepM_E/insepPe[n pcharLn /insepK_M/insepPe[m pcharLm Kxnm]].
by apply/insepPe; exists (n * m)%N; rewrite ?exprM // pnatM pcharLn pcharLm.
Qed.
End Separable.
Arguments separable_elementP {F L K x}.
Arguments separablePn_pchar {F L K x}.
Arguments Derivation_separableP {F L K x}.
Arguments adjoin_separableP {F L K x}.
Arguments purely_inseparable_elementP_pchar {F L K x}.
Arguments separableP {F L K E}.
Arguments purely_inseparableP {F L K E}.
|
pgroup.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import fintype bigop finset prime fingroup morphism.
From mathcomp Require Import gfunctor automorphism quotient action gproduct.
From mathcomp Require Import cyclic.
(******************************************************************************)
(* Standard group notions and constructions based on the prime decomposition *)
(* of the order of the group or its elements: *)
(* pi.-group G <=> G is a pi-group, i.e., pi.-nat #|G|. *)
(* -> Recall that here and in the sequel pi can be a single prime p. *)
(* pi.-subgroup(H) G <=> H is a pi-subgroup of G. *)
(* := (H \subset G) && pi.-group H. *)
(* -> This is provided mostly as a shorhand, with few associated lemmas. *)
(* However, we do establish some results on maximal pi-subgroups. *)
(* pi.-elt x <=> x is a pi-element. *)
(* := pi.-nat #[x] or pi.-group <[x]>. *)
(* x.`_pi == the pi-constituent of x: the (unique) pi-element *)
(* y \in <[x]> such that x * y^-1 is a pi'-element. *)
(* pi.-Hall(G) H <=> H is a Hall pi-subgroup of G. *)
(* := [&& H \subset G, pi.-group H & pi^'.-nat #|G : H|]. *)
(* -> This is also equivalent to H \subset G /\ #|H| = #|G|`_pi. *)
(* p.-Sylow(G) P <=> P is a Sylow p-subgroup of G. *)
(* -> This is the display and preferred input notation for p.-Hall(G) P. *)
(* 'Syl_p(G) == the set of the p-Sylow subgroups of G. *)
(* := [set P : {group _} | p.-Sylow(G) P]. *)
(* p_group P <=> P is a p-group for some prime p. *)
(* Hall G H <=> H is a Hall pi-subgroup of G for some pi. *)
(* := coprime #|H| #|G : H| && (H \subset G). *)
(* Sylow G P <=> P is a Sylow p-subgroup of G for some p. *)
(* := p_group P && Hall G P. *)
(* 'O_pi(G) == the pi-core (largest normal pi-subgroup) of G. *)
(* pcore_mod pi G H == the pi-core of G mod H. *)
(* := G :&: (coset H @*^-1 'O_pi(G / H)). *)
(* 'O_{pi2, pi1}(G) == the pi1,pi2-core of G. *)
(* := the pi1-core of G mod 'O_pi2(G). *)
(* -> We have 'O_{pi2, pi1}(G) / 'O_pi2(G) = 'O_pi1(G / 'O_pi2(G)) *)
(* with 'O_pi2(G) <| 'O_{pi2, pi1}(G) <| G. *)
(* 'O_{pn, ..., p1}(G) == the p1, ..., pn-core of G. *)
(* := the p1-core of G mod 'O_{pn, ..., p2}(G). *)
(* Note that notions are always defined on sets even though their name *)
(* indicates "group" properties; the actual definition of the notion never *)
(* tests for the group property, since this property will always be provided *)
(* by a (canonical) group structure. Similarly, p-group properties assume *)
(* without test that p is a prime. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section PgroupDefs.
(* We defer the definition of the functors ('0_p(G), etc) because they need *)
(* to quantify over the finGroupType explicitly. *)
Variable gT : finGroupType.
Implicit Type (x : gT) (A B : {set gT}) (pi : nat_pred) (p n : nat).
Definition pgroup pi A := pi.-nat #|A|.
Definition psubgroup pi A B := (B \subset A) && pgroup pi B.
Definition p_group A := pgroup (pdiv #|A|) A.
Definition p_elt pi x := pi.-nat #[x].
Definition constt x pi := x ^+ (chinese #[x]`_pi #[x]`_pi^' 1 0).
Definition Hall A B := (B \subset A) && coprime #|B| #|A : B|.
Definition pHall pi A B := [&& B \subset A, pgroup pi B & pi^'.-nat #|A : B|].
Definition Syl p A := [set P : {group gT} | pHall p A P].
Definition Sylow A B := p_group B && Hall A B.
End PgroupDefs.
Arguments pgroup {gT} pi%_N A%_g.
Arguments psubgroup {gT} pi%_N A%_g B%_g.
Arguments p_group {gT} A%_g.
Arguments p_elt {gT} pi%_N x.
Arguments constt {gT} x%_g pi%_N.
Arguments Hall {gT} A%_g B%_g.
Arguments pHall {gT} pi%_N A%_g B%_g.
Arguments Syl {gT} p%_N A%_g.
Arguments Sylow {gT} A%_g B%_g.
Notation "pi .-group" := (pgroup pi) (format "pi .-group") : group_scope.
Notation "pi .-subgroup ( A )" := (psubgroup pi A)
(format "pi .-subgroup ( A )") : group_scope.
Notation "pi .-elt" := (p_elt pi) (format "pi .-elt") : group_scope.
Notation "x .`_ pi" := (constt x pi)
(at level 3, left associativity, format "x .`_ pi") : group_scope.
Notation "pi .-Hall ( G )" := (pHall pi G)
(format "pi .-Hall ( G )") : group_scope.
Notation "p .-Sylow ( G )" := (nat_pred_of_nat p).-Hall(G)
(format "p .-Sylow ( G )") : group_scope.
Notation "''Syl_' p ( G )" := (Syl p G)
(p at level 2, format "''Syl_' p ( G )") : group_scope.
Section PgroupProps.
Variable gT : finGroupType.
Implicit Types (pi rho : nat_pred) (p : nat).
Implicit Types (x y z : gT) (A B C D : {set gT}) (G H K P Q R : {group gT}).
Lemma trivgVpdiv G : G :=: 1 \/ (exists2 p, prime p & p %| #|G|).
Proof.
have [leG1|lt1G] := leqP #|G| 1; first by left; apply: card_le1_trivg.
by right; exists (pdiv #|G|); rewrite ?pdiv_dvd ?pdiv_prime.
Qed.
Lemma prime_subgroupVti G H : prime #|G| -> G \subset H \/ H :&: G = 1.
Proof.
move=> prG; have [|[p p_pr pG]] := trivgVpdiv (H :&: G); first by right.
left; rewrite (sameP setIidPr eqP) eqEcard subsetIr.
suffices <-: p = #|G| by rewrite dvdn_leq ?cardG_gt0.
by apply/eqP; rewrite -dvdn_prime2 // -(LagrangeI G H) setIC dvdn_mulr.
Qed.
Lemma pgroupE pi A : pi.-group A = pi.-nat #|A|. Proof. by []. Qed.
Lemma sub_pgroup pi rho A : {subset pi <= rho} -> pi.-group A -> rho.-group A.
Proof. by move=> pi_sub_rho; apply: sub_in_pnat (in1W pi_sub_rho). Qed.
Lemma eq_pgroup pi rho A : pi =i rho -> pi.-group A = rho.-group A.
Proof. exact: eq_pnat. Qed.
Lemma eq_p'group pi rho A : pi =i rho -> pi^'.-group A = rho^'.-group A.
Proof. by move/eq_negn; apply: eq_pnat. Qed.
Lemma pgroupNK pi A : pi^'^'.-group A = pi.-group A.
Proof. exact: pnatNK. Qed.
Lemma pi_pgroup p pi A : p.-group A -> p \in pi -> pi.-group A.
Proof. exact: pi_pnat. Qed.
Lemma pi_p'group p pi A : pi.-group A -> p \in pi^' -> p^'.-group A.
Proof. exact: pi_p'nat. Qed.
Lemma pi'_p'group p pi A : pi^'.-group A -> p \in pi -> p^'.-group A.
Proof. exact: pi'_p'nat. Qed.
Lemma p'groupEpi p G : p^'.-group G = (p \notin \pi(G)).
Proof. exact: p'natEpi (cardG_gt0 G). Qed.
Lemma pgroup_pi G : \pi(G).-group G.
Proof. by rewrite /=; apply: pnat_pi. Qed.
Lemma partG_eq1 pi G : (#|G|`_pi == 1%N) = pi^'.-group G.
Proof. exact: partn_eq1 (cardG_gt0 G). Qed.
Lemma pgroupP pi G :
reflect (forall p, prime p -> p %| #|G| -> p \in pi) (pi.-group G).
Proof. exact: pnatP. Qed.
Arguments pgroupP {pi G}.
Lemma pgroup1 pi : pi.-group [1 gT].
Proof. by rewrite /pgroup cards1. Qed.
Lemma pgroupS pi G H : H \subset G -> pi.-group G -> pi.-group H.
Proof. by move=> sHG; apply: pnat_dvd (cardSg sHG). Qed.
Lemma oddSg G H : H \subset G -> odd #|G| -> odd #|H|.
Proof. by rewrite !odd_2'nat; apply: pgroupS. Qed.
Lemma odd_pgroup_odd p G : odd p -> p.-group G -> odd #|G|.
Proof.
move=> p_odd pG; rewrite odd_2'nat (pi_pnat pG) // !inE.
by case: eqP p_odd => // ->.
Qed.
Lemma card_pgroup p G : p.-group G -> #|G| = (p ^ logn p #|G|)%N.
Proof. by move=> pG; rewrite -p_part part_pnat_id. Qed.
Lemma properG_ltn_log p G H :
p.-group G -> H \proper G -> logn p #|H| < logn p #|G|.
Proof.
move=> pG; rewrite properEneq eqEcard andbC ltnNge => /andP[sHG].
rewrite sHG /= {1}(card_pgroup pG) {1}(card_pgroup (pgroupS sHG pG)).
by apply: contra; case: p {pG} => [|p] leHG; rewrite ?logn0 // leq_pexp2l.
Qed.
Lemma pgroupM pi G H : pi.-group (G * H) = pi.-group G && pi.-group H.
Proof.
have GH_gt0: 0 < #|G :&: H| := cardG_gt0 _.
rewrite /pgroup -(mulnK #|_| GH_gt0) -mul_cardG -(LagrangeI G H) -mulnA.
by rewrite mulKn // -(LagrangeI H G) setIC !pnatM andbCA; case: (pnat _).
Qed.
Lemma pgroupJ pi G x : pi.-group (G :^ x) = pi.-group G.
Proof. by rewrite /pgroup cardJg. Qed.
Lemma pgroup_p p P : p.-group P -> p_group P.
Proof.
case: (leqP #|P| 1); first by move=> /card_le1_trivg-> _; apply: pgroup1.
move/pdiv_prime=> pr_q pgP; have:= pgroupP pgP _ pr_q (pdiv_dvd _).
by rewrite /p_group => /eqnP->.
Qed.
Lemma p_groupP P : p_group P -> exists2 p, prime p & p.-group P.
Proof.
case: (ltnP 1 #|P|); first by move/pdiv_prime; exists (pdiv #|P|).
by move/card_le1_trivg=> -> _; exists 2 => //; apply: pgroup1.
Qed.
Lemma pgroup_pdiv p G :
p.-group G -> G :!=: 1 ->
[/\ prime p, p %| #|G| & exists m, #|G| = p ^ m.+1]%N.
Proof.
move=> pG; rewrite trivg_card1; case/p_groupP: (pgroup_p pG) => q q_pr qG.
move/implyP: (pgroupP pG q q_pr); case/p_natP: qG => // [[|m] ->] //.
by rewrite dvdn_exp // => /eqnP <- _; split; rewrite ?dvdn_exp //; exists m.
Qed.
Lemma coprime_p'group p K R :
coprime #|K| #|R| -> p.-group R -> R :!=: 1 -> p^'.-group K.
Proof.
move=> coKR pR ntR; have [p_pr _ [e oK]] := pgroup_pdiv pR ntR.
by rewrite oK coprime_sym coprime_pexpl // prime_coprime // -p'natE in coKR.
Qed.
Lemma card_Hall pi G H : pi.-Hall(G) H -> #|H| = #|G|`_pi.
Proof.
case/and3P=> sHG piH pi'H; rewrite -(Lagrange sHG).
by rewrite partnM ?Lagrange // part_pnat_id ?part_p'nat ?muln1.
Qed.
Lemma pHall_sub pi A B : pi.-Hall(A) B -> B \subset A.
Proof. by case/andP. Qed.
Lemma pHall_pgroup pi A B : pi.-Hall(A) B -> pi.-group B.
Proof. by case/and3P. Qed.
Lemma pHallP pi G H : reflect (H \subset G /\ #|H| = #|G|`_pi) (pi.-Hall(G) H).
Proof.
apply: (iffP idP) => [piH | [sHG oH]].
by split; [apply: pHall_sub piH | apply: card_Hall].
rewrite /pHall sHG -divgS // /pgroup oH.
by rewrite -{2}(@partnC pi #|G|) ?mulKn ?part_pnat.
Qed.
Lemma pHallE pi G H : pi.-Hall(G) H = (H \subset G) && (#|H| == #|G|`_pi).
Proof. by apply/pHallP/andP=> [] [->] /eqP. Qed.
Lemma coprime_mulpG_Hall pi G K R :
K * R = G -> pi.-group K -> pi^'.-group R ->
pi.-Hall(G) K /\ pi^'.-Hall(G) R.
Proof.
move=> defG piK pi'R; apply/andP.
rewrite /pHall piK -!divgS /= -defG ?mulG_subl ?mulg_subr //= pnatNK.
by rewrite coprime_cardMg ?(pnat_coprime piK) // mulKn ?mulnK //; apply/and3P.
Qed.
Lemma coprime_mulGp_Hall pi G K R :
K * R = G -> pi^'.-group K -> pi.-group R ->
pi^'.-Hall(G) K /\ pi.-Hall(G) R.
Proof.
move=> defG pi'K piR; apply/andP; rewrite andbC; apply/andP.
by apply: coprime_mulpG_Hall => //; rewrite -(comm_group_setP _) defG ?groupP.
Qed.
Lemma eq_in_pHall pi rho G H :
{in \pi(G), pi =i rho} -> pi.-Hall(G) H = rho.-Hall(G) H.
Proof.
move=> eq_pi_rho; apply: andb_id2l => sHG.
congr (_ && _); apply: eq_in_pnat => p piHp.
by apply: eq_pi_rho; apply: (piSg sHG).
by congr (~~ _); apply: eq_pi_rho; apply: (pi_of_dvd (dvdn_indexg G H)).
Qed.
Lemma eq_pHall pi rho G H : pi =i rho -> pi.-Hall(G) H = rho.-Hall(G) H.
Proof. by move=> eq_pi_rho; apply: eq_in_pHall (in1W eq_pi_rho). Qed.
Lemma eq_p'Hall pi rho G H : pi =i rho -> pi^'.-Hall(G) H = rho^'.-Hall(G) H.
Proof. by move=> eq_pi_rho; apply: eq_pHall (eq_negn _). Qed.
Lemma pHallNK pi G H : pi^'^'.-Hall(G) H = pi.-Hall(G) H.
Proof. exact: eq_pHall (negnK _). Qed.
Lemma subHall_Hall pi rho G H K :
rho.-Hall(G) H -> {subset pi <= rho} -> pi.-Hall(H) K -> pi.-Hall(G) K.
Proof.
move=> hallH pi_sub_rho hallK.
rewrite pHallE (subset_trans (pHall_sub hallK) (pHall_sub hallH)) /=.
by rewrite (card_Hall hallK) (card_Hall hallH) partn_part.
Qed.
Lemma subHall_Sylow pi p G H P :
pi.-Hall(G) H -> p \in pi -> p.-Sylow(H) P -> p.-Sylow(G) P.
Proof.
move=> hallH pi_p sylP; have [sHG piH _] := and3P hallH.
rewrite pHallE (subset_trans (pHall_sub sylP) sHG) /=.
by rewrite (card_Hall sylP) (card_Hall hallH) partn_part // => q; move/eqnP->.
Qed.
Lemma pHall_Hall pi A B : pi.-Hall(A) B -> Hall A B.
Proof. by case/and3P=> sBA piB pi'B; rewrite /Hall sBA (pnat_coprime piB). Qed.
Lemma Hall_pi G H : Hall G H -> \pi(H).-Hall(G) H.
Proof.
by case/andP=> sHG coHG /=; rewrite /pHall sHG /pgroup pnat_pi -?coprime_pi'.
Qed.
Lemma HallP G H : Hall G H -> exists pi, pi.-Hall(G) H.
Proof. by exists \pi(H); apply: Hall_pi. Qed.
Lemma sdprod_Hall G K H : K ><| H = G -> Hall G K = Hall G H.
Proof.
case/sdprod_context=> /andP[sKG _] sHG defG _ tiKH.
by rewrite /Hall sKG sHG -!divgS // -defG TI_cardMg // coprime_sym mulKn ?mulnK.
Qed.
Lemma coprime_sdprod_Hall_l G K H : K ><| H = G -> coprime #|K| #|H| = Hall G K.
Proof.
case/sdprod_context=> /andP[sKG _] _ defG _ tiKH.
by rewrite /Hall sKG -divgS // -defG TI_cardMg ?mulKn.
Qed.
Lemma coprime_sdprod_Hall_r G K H : K ><| H = G -> coprime #|K| #|H| = Hall G H.
Proof.
by move=> defG; rewrite (coprime_sdprod_Hall_l defG) (sdprod_Hall defG).
Qed.
Lemma compl_pHall pi K H G :
pi.-Hall(G) K -> (H \in [complements to K in G]) = pi^'.-Hall(G) H.
Proof.
move=> hallK; apply/complP/idP=> [[tiKH mulKH] | hallH].
have [_] := andP hallK; rewrite /pHall pnatNK -{3}(invGid G) -mulKH mulG_subr.
rewrite invMG !indexMg -indexgI andbC.
by rewrite -[#|K : H|]indexgI setIC tiKH !indexg1.
have [[sKG piK _] [sHG pi'H _]] := (and3P hallK, and3P hallH).
have tiKH: K :&: H = 1 := coprime_TIg (pnat_coprime piK pi'H).
split=> //; apply/eqP; rewrite eqEcard mul_subG //= TI_cardMg //.
by rewrite (card_Hall hallK) (card_Hall hallH) partnC.
Qed.
Lemma compl_p'Hall pi K H G :
pi^'.-Hall(G) K -> (H \in [complements to K in G]) = pi.-Hall(G) H.
Proof. by move/compl_pHall->; apply: eq_pHall (negnK pi). Qed.
Lemma sdprod_normal_p'HallP pi K H G :
K <| G -> pi^'.-Hall(G) H -> reflect (K ><| H = G) (pi.-Hall(G) K).
Proof.
move=> nsKG hallH; rewrite -(compl_p'Hall K hallH).
exact: sdprod_normal_complP.
Qed.
Lemma sdprod_normal_pHallP pi K H G :
K <| G -> pi.-Hall(G) H -> reflect (K ><| H = G) (pi^'.-Hall(G) K).
Proof.
by move=> nsKG hallH; apply: sdprod_normal_p'HallP; rewrite ?pHallNK.
Qed.
Lemma pHallJ2 pi G H x : pi.-Hall(G :^ x) (H :^ x) = pi.-Hall(G) H.
Proof. by rewrite !pHallE conjSg !cardJg. Qed.
Lemma pHallJnorm pi G H x : x \in 'N(G) -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H.
Proof. by move=> Nx; rewrite -{1}(normP Nx) pHallJ2. Qed.
Lemma pHallJ pi G H x : x \in G -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H.
Proof. by move=> Gx; rewrite -{1}(conjGid Gx) pHallJ2. Qed.
Lemma HallJ G H x : x \in G -> Hall G (H :^ x) = Hall G H.
Proof.
by move=> Gx; rewrite /Hall -!divgI -{1 3}(conjGid Gx) conjSg -conjIg !cardJg.
Qed.
Lemma psubgroupJ pi G H x :
x \in G -> pi.-subgroup(G) (H :^ x) = pi.-subgroup(G) H.
Proof. by move=> Gx; rewrite /psubgroup pgroupJ -{1}(conjGid Gx) conjSg. Qed.
Lemma p_groupJ P x : p_group (P :^ x) = p_group P.
Proof. by rewrite /p_group cardJg pgroupJ. Qed.
Lemma SylowJ G P x : x \in G -> Sylow G (P :^ x) = Sylow G P.
Proof. by move=> Gx; rewrite /Sylow p_groupJ HallJ. Qed.
Lemma p_Sylow p G P : p.-Sylow(G) P -> Sylow G P.
Proof.
by move=> pP; rewrite /Sylow (pgroup_p (pHall_pgroup pP)) (pHall_Hall pP).
Qed.
Lemma pHall_subl pi G K H :
H \subset K -> K \subset G -> pi.-Hall(G) H -> pi.-Hall(K) H.
Proof.
by move=> sHK sKG; rewrite /pHall sHK => /and3P[_ ->]; apply/pnat_dvd/indexSg.
Qed.
Lemma Hall1 G : Hall G 1.
Proof. by rewrite /Hall sub1G cards1 coprime1n. Qed.
Lemma p_group1 : @p_group gT 1.
Proof. by rewrite (@pgroup_p 2) ?pgroup1. Qed.
Lemma Sylow1 G : Sylow G 1.
Proof. by rewrite /Sylow p_group1 Hall1. Qed.
Lemma SylowP G P : reflect (exists2 p, prime p & p.-Sylow(G) P) (Sylow G P).
Proof.
apply: (iffP idP) => [| [p _]]; last exact: p_Sylow.
case/andP=> /p_groupP[p p_pr] /p_natP[[P1 _ | n oP /Hall_pi]]; last first.
by rewrite /= oP pi_of_exp // (eq_pHall _ _ (pi_of_prime _)) //; exists p.
have{p p_pr P1} ->: P :=: 1 by apply: card1_trivg; rewrite P1.
pose p := pdiv #|G|.+1; have p_pr: prime p by rewrite pdiv_prime ?ltnS.
exists p; rewrite // pHallE sub1G cards1 part_p'nat //.
apply/pgroupP=> q pr_q qG; apply/eqnP=> def_q.
have: p %| #|G| + 1 by rewrite addn1 pdiv_dvd.
by rewrite dvdn_addr -def_q // Euclid_dvd1.
Qed.
Lemma p_elt_exp pi x m : pi.-elt (x ^+ m) = (#[x]`_pi^' %| m).
Proof.
apply/idP/idP=> [pi_xm | /dvdnP[q ->{m}]]; last first.
rewrite mulnC; apply: pnat_dvd (part_pnat pi #[x]).
by rewrite order_dvdn -expgM mulnC mulnA partnC // -order_dvdn dvdn_mulr.
rewrite -(@Gauss_dvdr _ #[x ^+ m]); last first.
by rewrite coprime_sym (pnat_coprime pi_xm) ?part_pnat.
apply: (@dvdn_trans #[x]); first by rewrite -{2}[#[x]](partnC pi) ?dvdn_mull.
by rewrite order_dvdn mulnC expgM expg_order.
Qed.
Lemma mem_p_elt pi x G : pi.-group G -> x \in G -> pi.-elt x.
Proof. by move=> piG Gx; apply: pgroupS piG; rewrite cycle_subG. Qed.
Lemma p_eltM_norm pi x y :
x \in 'N(<[y]>) -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y).
Proof.
move=> nyx pi_x pi_y; apply: (@mem_p_elt pi _ (<[x]> <*> <[y]>)%G).
by rewrite /= norm_joinEl ?cycle_subG // pgroupM; apply/andP.
by rewrite groupM // mem_gen // inE cycle_id ?orbT.
Qed.
Lemma p_eltM pi x y : commute x y -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y).
Proof.
move=> cxy; apply: p_eltM_norm; apply: (subsetP (cent_sub _)).
by rewrite cent_gen cent_set1; apply/cent1P.
Qed.
Lemma p_elt1 pi : pi.-elt (1 : gT).
Proof. by rewrite /p_elt order1. Qed.
Lemma p_eltV pi x : pi.-elt x^-1 = pi.-elt x.
Proof. by rewrite /p_elt orderV. Qed.
Lemma p_eltX pi x n : pi.-elt x -> pi.-elt (x ^+ n).
Proof. by rewrite -{1}[x]expg1 !p_elt_exp dvdn1 => /eqnP->. Qed.
Lemma p_eltJ pi x y : pi.-elt (x ^ y) = pi.-elt x.
Proof. by congr pnat; rewrite orderJ. Qed.
Lemma sub_p_elt pi1 pi2 x : {subset pi1 <= pi2} -> pi1.-elt x -> pi2.-elt x.
Proof. by move=> pi12; apply: sub_in_pnat => q _; apply: pi12. Qed.
Lemma eq_p_elt pi1 pi2 x : pi1 =i pi2 -> pi1.-elt x = pi2.-elt x.
Proof. by move=> pi12; apply: eq_pnat. Qed.
Lemma p_eltNK pi x : pi^'^'.-elt x = pi.-elt x.
Proof. exact: pnatNK. Qed.
Lemma eq_constt pi1 pi2 x : pi1 =i pi2 -> x.`_pi1 = x.`_pi2.
Proof.
move=> pi12; congr (x ^+ (chinese _ _ 1 0)); apply: eq_partn => // a.
by congr (~~ _); apply: pi12.
Qed.
Lemma consttNK pi x : x.`_pi^'^' = x.`_pi.
Proof. by rewrite /constt !partnNK. Qed.
Lemma cycle_constt pi x : x.`_pi \in <[x]>.
Proof. exact: mem_cycle. Qed.
Lemma consttV pi x : (x^-1).`_pi = (x.`_pi)^-1.
Proof. by rewrite /constt expgVn orderV. Qed.
Lemma constt1 pi : 1.`_pi = 1 :> gT.
Proof. exact: expg1n. Qed.
Lemma consttJ pi x y : (x ^ y).`_pi = x.`_pi ^ y.
Proof. by rewrite /constt orderJ conjXg. Qed.
Lemma p_elt_constt pi x : pi.-elt x.`_pi.
Proof. by rewrite p_elt_exp /chinese addn0 mul1n dvdn_mulr. Qed.
Lemma consttC pi x : x.`_pi * x.`_pi^' = x.
Proof.
apply/eqP; rewrite -{3}[x]expg1 -expgD eq_expg_mod_order.
rewrite partnNK -{5 6}(@partnC pi #[x]) // /chinese !addn0.
by rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC ?eqxx.
Qed.
Lemma p'_elt_constt pi x : pi^'.-elt (x * (x.`_pi)^-1).
Proof. by rewrite -{1}(consttC pi^' x) consttNK mulgK p_elt_constt. Qed.
Lemma order_constt pi (x : gT) : #[x.`_pi] = #[x]`_pi.
Proof.
rewrite -{2}(consttC pi x) orderM; [|exact: commuteX2|]; last first.
by apply: (@pnat_coprime pi); apply: p_elt_constt.
by rewrite partnM // part_pnat_id ?part_p'nat ?muln1 //; apply: p_elt_constt.
Qed.
Lemma consttM pi x y : commute x y -> (x * y).`_pi = x.`_pi * y.`_pi.
Proof.
move=> cxy; pose m := #|<<[set x; y]>>|; have m_gt0: 0 < m := cardG_gt0 _.
pose k := chinese m`_pi m`_pi^' 1 0.
suffices kXpi z: z \in <<[set x; y]>> -> z.`_pi = z ^+ k.
by rewrite !kXpi ?expgMn // ?groupM ?mem_gen // !inE eqxx ?orbT.
move=> xyz; have{xyz} zm: #[z] %| m by rewrite cardSg ?cycle_subG.
apply/eqP; rewrite eq_expg_mod_order -{3 4}[#[z]](partnC pi) //.
rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC //.
rewrite -!(modn_dvdm k (partn_dvd _ m_gt0 zm)).
rewrite chinese_modl ?chinese_modr ?coprime_partC //.
by rewrite !modn_dvdm ?partn_dvd ?eqxx.
Qed.
Lemma consttX pi x n : (x ^+ n).`_pi = x.`_pi ^+ n.
Proof.
elim: n => [|n IHn]; first exact: constt1.
by rewrite !expgS consttM ?IHn //; apply: commuteX.
Qed.
Lemma constt1P pi x : reflect (x.`_pi = 1) (pi^'.-elt x).
Proof.
rewrite -{2}[x]expg1 p_elt_exp -order_constt consttNK order_dvdn expg1.
exact: eqP.
Qed.
Lemma constt_p_elt pi x : pi.-elt x -> x.`_pi = x.
Proof.
by rewrite -p_eltNK -{3}(consttC pi x) => /constt1P->; rewrite mulg1.
Qed.
Lemma sub_in_constt pi1 pi2 x :
{in \pi(#[x]), {subset pi1 <= pi2}} -> x.`_pi2.`_pi1 = x.`_pi1.
Proof.
move=> pi12; rewrite -{2}(consttC pi2 x) consttM; last exact: commuteX2.
rewrite (constt1P _ x.`_pi2^' _) ?mulg1 //.
apply: sub_in_pnat (p_elt_constt _ x) => p; rewrite order_constt => pi_p.
by apply/contra/pi12; rewrite -[#[x]](partnC pi2^') // primesM // pi_p.
Qed.
Lemma prod_constt x : \prod_(0 <= p < #[x].+1) x.`_p = x.
Proof.
pose lp n := [pred p | p < n].
have: (lp #[x].+1).-elt x by apply/pnatP=> // p _; apply: dvdn_leq.
move/constt_p_elt=> def_x; symmetry; rewrite -{1}def_x {def_x}.
elim: _.+1 => [|p IHp].
by rewrite big_nil; apply/constt1P; apply/pgroupP.
rewrite big_nat_recr //= -{}IHp -(consttC (lp p) x.`__); congr (_ * _).
by rewrite sub_in_constt // => q _; apply: leqW.
set y := _.`__; rewrite -(consttC p y) (constt1P p^' _ _) ?mulg1.
by rewrite 2?sub_in_constt // => q _; move/eqnP->; rewrite !inE ?ltnn.
rewrite /p_elt pnatNK !order_constt -partnI.
apply: sub_in_pnat (part_pnat _ _) => q _.
by rewrite !inE ltnS -leqNgt -eqn_leq.
Qed.
Lemma max_pgroupJ pi M G x :
x \in G -> [max M | pi.-subgroup(G) M] ->
[max M :^ x of M | pi.-subgroup(G) M].
Proof.
move=> Gx /maxgroupP[piM maxM]; apply/maxgroupP.
split=> [|H piH]; first by rewrite psubgroupJ.
by rewrite -(conjsgKV x H) conjSg => /maxM/=-> //; rewrite psubgroupJ ?groupV.
Qed.
Lemma comm_sub_max_pgroup pi H M G :
[max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G ->
commute H M -> H \subset M.
Proof.
case/maxgroupP=> /andP[sMG piM] maxM piH sHG cHM.
rewrite -(maxM (H <*> M)%G) /= comm_joingE ?(mulG_subl, mulG_subr) //.
by rewrite /psubgroup pgroupM piM piH mul_subG.
Qed.
Lemma normal_sub_max_pgroup pi H M G :
[max M | pi.-subgroup(G) M] -> pi.-group H -> H <| G -> H \subset M.
Proof.
move=> maxM piH /andP[sHG nHG].
apply: comm_sub_max_pgroup piH sHG _ => //; apply: commute_sym; apply: normC.
by apply: subset_trans nHG; case/andP: (maxgroupp maxM).
Qed.
Lemma norm_sub_max_pgroup pi H M G :
[max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G ->
H \subset 'N(M) -> H \subset M.
Proof. by move=> maxM piH sHG /normC; apply: comm_sub_max_pgroup piH sHG. Qed.
Lemma sub_pHall pi H G K :
pi.-Hall(G) H -> pi.-group K -> H \subset K -> K \subset G -> K :=: H.
Proof.
move=> hallH piK sHK sKG; apply/eqP; rewrite eq_sym eqEcard sHK.
by rewrite (card_Hall hallH) -(part_pnat_id piK) dvdn_leq ?partn_dvd ?cardSg.
Qed.
Lemma Hall_max pi H G : pi.-Hall(G) H -> [max H | pi.-subgroup(G) H].
Proof.
move=> hallH; apply/maxgroupP; split=> [|K /andP[sKG piK] sHK].
by rewrite /psubgroup; case/and3P: hallH => ->.
exact: (sub_pHall hallH).
Qed.
Lemma pHall_id pi H G : pi.-Hall(G) H -> pi.-group G -> H :=: G.
Proof.
by move=> hallH piG; rewrite (sub_pHall hallH piG) ?(pHall_sub hallH).
Qed.
Lemma psubgroup1 pi G : pi.-subgroup(G) 1.
Proof. by rewrite /psubgroup sub1G pgroup1. Qed.
Lemma Cauchy p G : prime p -> p %| #|G| -> {x | x \in G & #[x] = p}.
Proof.
move=> p_pr; have [n] := ubnP #|G|; elim: n G => // n IHn G /ltnSE-leGn pG.
pose xpG := [pred x in G | #[x] == p].
have [x /andP[Gx /eqP] | no_x] := pickP xpG; first by exists x.
have{pG n leGn IHn} pZ: p %| #|'C_G(G)|.
suffices /dvdn_addl <-: p %| #|G :\: 'C(G)| by rewrite cardsID.
have /acts_sum_card_orbit <-: [acts G, on G :\: 'C(G) | 'J].
by apply/actsP=> x Gx y; rewrite !inE -!mem_conjgV -centJ conjGid ?groupV.
elim/big_rec: _ => // _ _ /imsetP[x /setDP[Gx nCx] ->] /dvdn_addl->.
have ltCx: 'C_G[x] \proper G by rewrite properE subsetIl subsetIidl sub_cent1.
have /negP: ~ p %| #|'C_G[x]|.
case/(IHn _ (leq_trans (proper_card ltCx) leGn))=> y /setIP[Gy _] /eqP-oy.
by have /andP[] := no_x y.
by apply/implyP; rewrite -index_cent1 indexgI implyNb -Euclid_dvdM ?LagrangeI.
have [Q maxQ _]: {Q | [max Q | p^'.-subgroup('C_G(G)) Q] & 1%G \subset Q}.
by apply: maxgroup_exists; apply: psubgroup1.
case/andP: (maxgroupp maxQ) => sQC; rewrite /pgroup p'natE // => /negP[].
apply: dvdn_trans pZ (cardSg _); apply/subsetP=> x /setIP[Gx Cx].
rewrite -sub1set -gen_subG (normal_sub_max_pgroup maxQ) //; last first.
rewrite /normal subsetI !cycle_subG ?Gx ?cents_norm ?subIset ?andbT //=.
by rewrite centsC cycle_subG Cx.
rewrite /pgroup p'natE //= -[#|_|]/#[x]; apply/dvdnP=> [[m oxm]].
have m_gt0: 0 < m by apply: dvdn_gt0 (order_gt0 x) _; rewrite oxm dvdn_mulr.
case/idP: (no_x (x ^+ m)); rewrite /= groupX //= orderXgcd //= oxm.
by rewrite gcdnC gcdnMr mulKn.
Qed.
(* These lemmas actually hold for maximal pi-groups, but below we'll *)
(* derive from the Cauchy lemma that a normal max pi-group is Hall. *)
Lemma sub_normal_Hall pi G H K :
pi.-Hall(G) H -> H <| G -> K \subset G -> (K \subset H) = pi.-group K.
Proof.
move=> hallH nsHG sKG; apply/idP/idP=> [sKH | piK].
by rewrite (pgroupS sKH) ?(pHall_pgroup hallH).
apply: norm_sub_max_pgroup (Hall_max hallH) piK _ _ => //.
exact: subset_trans sKG (normal_norm nsHG).
Qed.
Lemma mem_normal_Hall pi H G x :
pi.-Hall(G) H -> H <| G -> x \in G -> (x \in H) = pi.-elt x.
Proof. by rewrite -!cycle_subG; apply: sub_normal_Hall. Qed.
Lemma uniq_normal_Hall pi H G K :
pi.-Hall(G) H -> H <| G -> [max K | pi.-subgroup(G) K] -> K :=: H.
Proof.
move=> hallH nHG /maxgroupP[/andP[sKG piK] /(_ H) -> //].
exact: (maxgroupp (Hall_max hallH)).
by rewrite (sub_normal_Hall hallH).
Qed.
End PgroupProps.
Arguments pgroupP {gT pi G}.
Arguments constt1P {gT pi x}.
Section NormalHall.
Variables (gT : finGroupType) (pi : nat_pred).
Implicit Types G H K : {group gT}.
Lemma normal_max_pgroup_Hall G H :
[max H | pi.-subgroup(G) H] -> H <| G -> pi.-Hall(G) H.
Proof.
case/maxgroupP=> /andP[sHG piH] maxH nsHG; have [_ nHG] := andP nsHG.
rewrite /pHall sHG piH; apply/pnatP=> // p p_pr.
rewrite inE /= -pnatE // -card_quotient //.
case/Cauchy=> //= Hx; rewrite -sub1set -gen_subG -/<[Hx]> /order.
case/inv_quotientS=> //= K -> sHK sKG {Hx}.
rewrite card_quotient ?(subset_trans sKG) // => iKH; apply/negP=> pi_p.
rewrite -iKH -divgS // (maxH K) ?divnn ?cardG_gt0 // in p_pr.
by rewrite /psubgroup sKG /pgroup -(Lagrange sHK) mulnC pnatM iKH pi_p.
Qed.
Lemma setI_normal_Hall G H K :
H <| G -> pi.-Hall(G) H -> K \subset G -> pi.-Hall(K) (H :&: K).
Proof.
move=> nsHG hallH sKG; apply: normal_max_pgroup_Hall; last first.
by rewrite /= setIC (normalGI sKG nsHG).
apply/maxgroupP; split=> [|M /andP[sMK piM] sHK_M].
by rewrite /psubgroup subsetIr (pgroupS (subsetIl _ _) (pHall_pgroup hallH)).
apply/eqP; rewrite eqEsubset sHK_M subsetI sMK !andbT.
by rewrite (sub_normal_Hall hallH) // (subset_trans sMK).
Qed.
End NormalHall.
Section Morphim.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Implicit Types (pi : nat_pred) (G H P : {group aT}).
Lemma morphim_pgroup pi G : pi.-group G -> pi.-group (f @* G).
Proof. by apply: pnat_dvd; apply: dvdn_morphim. Qed.
Lemma morphim_odd G : odd #|G| -> odd #|f @* G|.
Proof. by rewrite !odd_2'nat; apply: morphim_pgroup. Qed.
Lemma pmorphim_pgroup pi G :
pi.-group ('ker f) -> G \subset D -> pi.-group (f @* G) = pi.-group G.
Proof.
move=> piker sGD; apply/idP/idP=> [pifG|]; last exact: morphim_pgroup.
apply: (@pgroupS _ _ (f @*^-1 (f @* G))); first by rewrite -sub_morphim_pre.
by rewrite /pgroup card_morphpre ?morphimS // pnatM; apply/andP.
Qed.
Lemma morphim_p_index pi G H :
H \subset D -> pi.-nat #|G : H| -> pi.-nat #|f @* G : f @* H|.
Proof.
by move=> sHD; apply: pnat_dvd; rewrite index_morphim ?subIset // sHD orbT.
Qed.
Lemma morphim_pHall pi G H :
H \subset D -> pi.-Hall(G) H -> pi.-Hall(f @* G) (f @* H).
Proof.
move=> sHD /and3P[sHG piH pi'GH].
by rewrite /pHall morphimS // morphim_pgroup // morphim_p_index.
Qed.
Lemma pmorphim_pHall pi G H :
G \subset D -> H \subset D -> pi.-subgroup(H :&: G) ('ker f) ->
pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H.
Proof.
move=> sGD sHD /andP[/subsetIP[sKH sKG] piK]; rewrite !pHallE morphimSGK //.
apply: andb_id2l => sHG; rewrite -(Lagrange sKH) -(Lagrange sKG) partnM //.
by rewrite (part_pnat_id piK) !card_morphim !(setIidPr _) // eqn_pmul2l.
Qed.
Lemma morphim_Hall G H : H \subset D -> Hall G H -> Hall (f @* G) (f @* H).
Proof.
by move=> sHD /HallP[pi piH]; apply: (@pHall_Hall _ pi); apply: morphim_pHall.
Qed.
Lemma morphim_pSylow p G P :
P \subset D -> p.-Sylow(G) P -> p.-Sylow(f @* G) (f @* P).
Proof. exact: morphim_pHall. Qed.
Lemma morphim_p_group P : p_group P -> p_group (f @* P).
Proof. by move/morphim_pgroup; apply: pgroup_p. Qed.
Lemma morphim_Sylow G P : P \subset D -> Sylow G P -> Sylow (f @* G) (f @* P).
Proof.
by move=> sPD /andP[pP hallP]; rewrite /Sylow morphim_p_group // morphim_Hall.
Qed.
Lemma morph_p_elt pi x : x \in D -> pi.-elt x -> pi.-elt (f x).
Proof. by move=> Dx; apply: pnat_dvd; apply: morph_order. Qed.
Lemma morph_constt pi x : x \in D -> f x.`_pi = (f x).`_pi.
Proof.
move=> Dx; rewrite -{2}(consttC pi x) morphM ?groupX //.
rewrite consttM; last by rewrite !morphX //; apply: commuteX2.
have: pi.-elt (f x.`_pi) by rewrite morph_p_elt ?groupX ?p_elt_constt //.
have: pi^'.-elt (f x.`_pi^') by rewrite morph_p_elt ?groupX ?p_elt_constt //.
by move/constt1P->; move/constt_p_elt->; rewrite mulg1.
Qed.
End Morphim.
Section Pquotient.
Variables (pi : nat_pred) (gT : finGroupType) (p : nat) (G H K : {group gT}).
Hypothesis piK : pi.-group K.
Lemma quotient_pgroup : pi.-group (K / H). Proof. exact: morphim_pgroup. Qed.
Lemma quotient_pHall :
K \subset 'N(H) -> pi.-Hall(G) K -> pi.-Hall(G / H) (K / H).
Proof. exact: morphim_pHall. Qed.
Lemma quotient_odd : odd #|K| -> odd #|K / H|. Proof. exact: morphim_odd. Qed.
Lemma pquotient_pgroup : G \subset 'N(K) -> pi.-group (G / K) = pi.-group G.
Proof. by move=> nKG; rewrite pmorphim_pgroup ?ker_coset. Qed.
Lemma pquotient_pHall :
K <| G -> K <| H -> pi.-Hall(G / K) (H / K) = pi.-Hall(G) H.
Proof.
case/andP=> sKG nKG; case/andP=> sKH nKH.
by rewrite pmorphim_pHall // ker_coset /psubgroup subsetI sKH sKG.
Qed.
Lemma ltn_log_quotient :
p.-group G -> H :!=: 1 -> H \subset G -> logn p #|G / H| < logn p #|G|.
Proof.
move=> pG ntH sHG; apply: contraLR (ltn_quotient ntH sHG); rewrite -!leqNgt.
rewrite {2}(card_pgroup pG) {2}(card_pgroup (morphim_pgroup _ pG)).
by case: (posnP p) => [-> //|]; apply: leq_pexp2l.
Qed.
End Pquotient.
(* Application of card_Aut_cyclic to internal faithful action on cyclic *)
(* p-subgroups. *)
Section InnerAutCyclicPgroup.
Variables (gT : finGroupType) (p : nat) (G C : {group gT}).
Hypothesis nCG : G \subset 'N(C).
Lemma logn_quotient_cent_cyclic_pgroup :
p.-group C -> cyclic C -> logn p #|G / 'C_G(C)| <= (logn p #|C|).-1.
Proof.
move=> pC cycC; have [-> | ntC] := eqsVneq C 1.
by rewrite cent1T setIT trivg_quotient cards1 logn1.
have [p_pr _ [e oC]] := pgroup_pdiv pC ntC.
rewrite -ker_conj_aut (card_isog (first_isog_loc _ _)) //.
apply: leq_trans (dvdn_leq_log _ _ (cardSg (Aut_conj_aut _ _))) _ => //.
rewrite card_Aut_cyclic // oC totient_pfactor //= logn_Gauss ?pfactorK //.
by rewrite prime_coprime // gtnNdvd // -(subnKC (prime_gt1 p_pr)).
Qed.
Lemma p'group_quotient_cent_prime :
prime p -> #|C| %| p -> p^'.-group (G / 'C_G(C)).
Proof.
move=> p_pr pC; have pgC: p.-group C := pnat_dvd pC (pnat_id p_pr).
have [_ dv_p] := primeP p_pr; case/pred2P: {dv_p pC}(dv_p _ pC) => [|pC].
by move/card1_trivg->; rewrite cent1T setIT trivg_quotient pgroup1.
have le_oGC := logn_quotient_cent_cyclic_pgroup pgC.
rewrite /pgroup -partn_eq1 ?cardG_gt0 // -dvdn1 p_part pfactor_dvdn // logn1.
by rewrite (leq_trans (le_oGC _)) ?prime_cyclic // pC ?(pfactorK 1).
Qed.
End InnerAutCyclicPgroup.
Section PcoreDef.
(* A functor needs to quantify over the finGroupType just beore the set. *)
Variables (pi : nat_pred) (gT : finGroupType) (A : {set gT}).
Definition pcore := \bigcap_(G | [max G | pi.-subgroup(A) G]) G.
Canonical pcore_group : {group gT} := Eval hnf in [group of pcore].
End PcoreDef.
Arguments pcore pi%_N {gT} A%_g.
Arguments pcore_group pi%_N {gT} A%_G.
Notation "''O_' pi ( G )" := (pcore pi G)
(pi at level 2, format "''O_' pi ( G )") : group_scope.
Notation "''O_' pi ( G )" := (pcore_group pi G) : Group_scope.
Section PseriesDefs.
Variables (pis : seq nat_pred) (gT : finGroupType) (A : {set gT}).
Definition pcore_mod pi B := coset B @*^-1 'O_pi(A / B).
Canonical pcore_mod_group pi B : {group gT} :=
Eval hnf in [group of pcore_mod pi B].
Definition pseries := foldr pcore_mod 1 (rev pis).
Lemma pseries_group_set : group_set pseries.
Proof. by rewrite /pseries; case: rev => [|pi1 pi1']; apply: groupP. Qed.
Canonical pseries_group : {group gT} := group pseries_group_set.
End PseriesDefs.
Arguments pseries pis%_SEQ {gT} _%_g.
Local Notation ConsPred p := (@Cons nat_pred p%N) (only parsing).
Notation "''O_{' p1 , .. , pn } ( A )" :=
(pseries (ConsPred p1 .. (ConsPred pn [::]) ..) A)
(format "''O_{' p1 , .. , pn } ( A )") : group_scope.
Notation "''O_{' p1 , .. , pn } ( A )" :=
(pseries_group (ConsPred p1 .. (ConsPred pn [::]) ..) A) : Group_scope.
Section PCoreProps.
Variables (pi : nat_pred) (gT : finGroupType).
Implicit Types (A : {set gT}) (G H M K : {group gT}).
Lemma pcore_psubgroup G : pi.-subgroup(G) 'O_pi(G).
Proof.
have [M maxM _]: {M | [max M | pi.-subgroup(G) M] & 1%G \subset M}.
by apply: maxgroup_exists; rewrite /psubgroup sub1G pgroup1.
have sOM: 'O_pi(G) \subset M by apply: bigcap_inf.
have /andP[piM sMG] := maxgroupp maxM.
by rewrite /psubgroup (pgroupS sOM) // (subset_trans sOM).
Qed.
Lemma pcore_pgroup G : pi.-group 'O_pi(G).
Proof. by case/andP: (pcore_psubgroup G). Qed.
Lemma pcore_sub G : 'O_pi(G) \subset G.
Proof. by case/andP: (pcore_psubgroup G). Qed.
Lemma pcore_sub_Hall G H : pi.-Hall(G) H -> 'O_pi(G) \subset H.
Proof. by move/Hall_max=> maxH; apply: bigcap_inf. Qed.
Lemma pcore_max G H : pi.-group H -> H <| G -> H \subset 'O_pi(G).
Proof.
move=> piH nHG; apply/bigcapsP=> M maxM.
exact: normal_sub_max_pgroup piH nHG.
Qed.
Lemma pcore_pgroup_id G : pi.-group G -> 'O_pi(G) = G.
Proof. by move=> piG; apply/eqP; rewrite eqEsubset pcore_sub pcore_max. Qed.
Lemma pcore_normal G : 'O_pi(G) <| G.
Proof.
rewrite /(_ <| G) pcore_sub; apply/subsetP=> x Gx.
rewrite inE; apply/bigcapsP=> M maxM; rewrite sub_conjg.
by apply: bigcap_inf; apply: max_pgroupJ; rewrite ?groupV.
Qed.
Lemma normal_Hall_pcore H G : pi.-Hall(G) H -> H <| G -> 'O_pi(G) = H.
Proof.
move=> hallH nHG; apply/eqP.
rewrite eqEsubset (sub_normal_Hall hallH) ?pcore_sub ?pcore_pgroup //=.
by rewrite pcore_max //= (pHall_pgroup hallH).
Qed.
Lemma eq_Hall_pcore G H :
pi.-Hall(G) 'O_pi(G) -> pi.-Hall(G) H -> H :=: 'O_pi(G).
Proof.
move=> hallGpi hallH.
exact: uniq_normal_Hall (pcore_normal G) (Hall_max hallH).
Qed.
Lemma sub_Hall_pcore G K :
pi.-Hall(G) 'O_pi(G) -> K \subset G -> (K \subset 'O_pi(G)) = pi.-group K.
Proof. by move=> hallGpi; apply: sub_normal_Hall (pcore_normal G). Qed.
Lemma mem_Hall_pcore G x :
pi.-Hall(G) 'O_pi(G) -> x \in G -> (x \in 'O_pi(G)) = pi.-elt x.
Proof. by move=> hallGpi; apply: mem_normal_Hall (pcore_normal G). Qed.
Lemma sdprod_Hall_pcoreP H G :
pi.-Hall(G) 'O_pi(G) -> reflect ('O_pi(G) ><| H = G) (pi^'.-Hall(G) H).
Proof.
move=> hallGpi; rewrite -(compl_pHall H hallGpi) complgC.
exact: sdprod_normal_complP (pcore_normal G).
Qed.
Lemma sdprod_pcore_HallP H G :
pi^'.-Hall(G) H -> reflect ('O_pi(G) ><| H = G) (pi.-Hall(G) 'O_pi(G)).
Proof. exact: sdprod_normal_p'HallP (pcore_normal G). Qed.
Lemma pcoreJ G x : 'O_pi(G :^ x) = 'O_pi(G) :^ x.
Proof.
apply/eqP; rewrite eqEsubset -sub_conjgV.
rewrite !pcore_max ?pgroupJ ?pcore_pgroup ?normalJ ?pcore_normal //.
by rewrite -(normalJ _ _ x) conjsgKV pcore_normal.
Qed.
End PCoreProps.
Section MorphPcore.
Implicit Types (pi : nat_pred) (gT rT : finGroupType).
Lemma morphim_pcore pi : GFunctor.pcontinuous (@pcore pi).
Proof.
move=> gT rT D G f; apply/bigcapsP=> M /normal_sub_max_pgroup; apply.
by rewrite morphim_pgroup ?pcore_pgroup.
by apply: morphim_normal; apply: pcore_normal.
Qed.
Lemma pcoreS pi gT (G H : {group gT}) :
H \subset G -> H :&: 'O_pi(G) \subset 'O_pi(H).
Proof.
move=> sHG; rewrite -{2}(setIidPl sHG).
by do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom; apply: morphim_pcore.
Qed.
Canonical pcore_igFun pi := [igFun by pcore_sub pi & morphim_pcore pi].
Canonical pcore_gFun pi := [gFun by morphim_pcore pi].
Canonical pcore_pgFun pi := [pgFun by morphim_pcore pi].
Lemma pcore_char pi gT (G : {group gT}) : 'O_pi(G) \char G.
Proof. exact: gFchar. Qed.
Section PcoreMod.
Variable F : GFunctor.pmap.
Lemma pcore_mod_sub pi gT (G : {group gT}) : pcore_mod G pi (F _ G) \subset G.
Proof.
by rewrite sub_morphpre_im ?gFsub_trans ?morphimS ?gFnorm //= ker_coset gFsub.
Qed.
Lemma quotient_pcore_mod pi gT (G : {group gT}) (B : {set gT}) :
pcore_mod G pi B / B = 'O_pi(G / B).
Proof. exact/morphpreK/gFsub_trans/morphim_sub. Qed.
Lemma morphim_pcore_mod pi gT rT (D G : {group gT}) (f : {morphism D >-> rT}) :
f @* pcore_mod G pi (F _ G) \subset pcore_mod (f @* G) pi (F _ (f @* G)).
Proof.
have sDF: D :&: G \subset 'dom (coset (F _ G)).
by rewrite setIC subIset ?gFnorm.
have sDFf: D :&: G \subset 'dom (coset (F _ (f @* G)) \o f).
by rewrite -sub_morphim_pre ?subsetIl // morphimIdom gFnorm.
pose K := 'ker (restrm sDFf (coset (F _ (f @* G)) \o f)).
have sFK: 'ker (restrm sDF (coset (F _ G))) \subset K.
rewrite /K !ker_restrm ker_comp /= subsetI subsetIl /= -setIA.
rewrite -sub_morphim_pre ?subsetIl //.
by rewrite morphimIdom !ker_coset (setIidPr _) ?pmorphimF ?gFsub.
have sOF := pcore_sub pi (G / F _ G); have sDD: D :&: G \subset D :&: G by [].
rewrite -sub_morphim_pre -?quotientE; last first.
by apply: subset_trans (gFnorm F _); rewrite morphimS ?pcore_mod_sub.
suffices im_fact (H : {group gT}) : F _ G \subset H -> H \subset G ->
factm sFK sDD @* (H / F _ G) = f @* H / F _ (f @* G).
- rewrite -2?im_fact ?pcore_mod_sub ?gFsub //;
try by rewrite -{1}[F _ G]ker_coset morphpreS ?sub1G.
by rewrite quotient_pcore_mod morphim_pcore.
move=> sFH sHG; rewrite -(morphimIdom _ (H / _)) /= {2}morphim_restrm setIid.
rewrite -morphimIG ?ker_coset //.
rewrite -(morphim_restrm sDF) morphim_factm morphim_restrm.
by rewrite morphim_comp -quotientE -setIA morphimIdom (setIidPr _).
Qed.
Lemma pcore_mod_res pi gT rT (D : {group gT}) (f : {morphism D >-> rT}) :
f @* pcore_mod D pi (F _ D) \subset pcore_mod (f @* D) pi (F _ (f @* D)).
Proof. exact: morphim_pcore_mod. Qed.
Lemma pcore_mod1 pi gT (G : {group gT}) : pcore_mod G pi 1 = 'O_pi(G).
Proof.
rewrite /pcore_mod; have inj1 := coset1_injm gT; rewrite -injmF ?norms1 //.
by rewrite -(morphim_invmE inj1) morphim_invm ?norms1.
Qed.
End PcoreMod.
Lemma pseries_rcons pi pis gT (A : {set gT}) :
pseries (rcons pis pi) A = pcore_mod A pi (pseries pis A).
Proof. by rewrite /pseries rev_rcons. Qed.
Lemma pseries_subfun pis :
GFunctor.closed (@pseries pis) /\ GFunctor.pcontinuous (@pseries pis).
Proof.
elim/last_ind: pis => [|pis pi [sFpi fFpi]].
by split=> [gT G | gT rT D G f]; rewrite (sub1G, morphim1).
pose fF := [gFun by fFpi : GFunctor.continuous [igFun by sFpi & fFpi]].
pose F := [pgFun by fFpi : GFunctor.hereditary fF].
split=> [gT G | gT rT D G f]; rewrite !pseries_rcons ?(pcore_mod_sub F) //.
exact: (morphim_pcore_mod F).
Qed.
Lemma pseries_sub pis : GFunctor.closed (@pseries pis).
Proof. by case: (pseries_subfun pis). Qed.
Lemma morphim_pseries pis : GFunctor.pcontinuous (@pseries pis).
Proof. by case: (pseries_subfun pis). Qed.
Lemma pseriesS pis : GFunctor.hereditary (@pseries pis).
Proof. exact: (morphim_pseries pis). Qed.
Canonical pseries_igFun pis := [igFun by pseries_sub pis & morphim_pseries pis].
Canonical pseries_gFun pis := [gFun by morphim_pseries pis].
Canonical pseries_pgFun pis := [pgFun by morphim_pseries pis].
Lemma pseries_char pis gT (G : {group gT}) : pseries pis G \char G.
Proof. exact: gFchar. Qed.
Lemma pseries_normal pis gT (G : {group gT}) : pseries pis G <| G.
Proof. exact: gFnormal. Qed.
Lemma pseriesJ pis gT (G : {group gT}) x :
pseries pis (G :^ x) = pseries pis G :^ x.
Proof.
rewrite -{1}(setIid G) -morphim_conj -(injmF _ (injm_conj G x)) //=.
by rewrite morphim_conj (setIidPr (pseries_sub _ _)).
Qed.
Lemma pseries1 pi gT (G : {group gT}) : 'O_{pi}(G) = 'O_pi(G).
Proof. exact: pcore_mod1. Qed.
Lemma pseries_pop pi pis gT (G : {group gT}) :
'O_pi(G) = 1 -> pseries (pi :: pis) G = pseries pis G.
Proof.
by move=> OG1; rewrite /pseries rev_cons -cats1 foldr_cat /= pcore_mod1 OG1.
Qed.
Lemma pseries_pop2 pi1 pi2 gT (G : {group gT}) :
'O_pi1(G) = 1 -> 'O_{pi1, pi2}(G) = 'O_pi2(G).
Proof. by move/pseries_pop->; apply: pseries1. Qed.
Lemma pseries_sub_catl pi1s pi2s gT (G : {group gT}) :
pseries pi1s G \subset pseries (pi1s ++ pi2s) G.
Proof.
elim/last_ind: pi2s => [|pi pis IHpi]; rewrite ?cats0 // -rcons_cat.
by rewrite pseries_rcons; apply: subset_trans IHpi _; rewrite sub_cosetpre.
Qed.
Lemma quotient_pseries pis pi gT (G : {group gT}) :
pseries (rcons pis pi) G / pseries pis G = 'O_pi(G / pseries pis G).
Proof. by rewrite pseries_rcons quotient_pcore_mod. Qed.
Lemma pseries_norm2 pi1s pi2s gT (G : {group gT}) :
pseries pi2s G \subset 'N(pseries pi1s G).
Proof. by rewrite gFsub_trans ?gFnorm. Qed.
Lemma pseries_sub_catr pi1s pi2s gT (G : {group gT}) :
pseries pi2s G \subset pseries (pi1s ++ pi2s) G.
Proof.
elim: pi1s => //= pi1 pi1s /subset_trans; apply.
elim/last_ind: {pi1s pi2s}(_ ++ _) => [|pis pi IHpi]; first exact: sub1G.
rewrite -rcons_cons (pseries_rcons _ (pi1 :: pis)).
rewrite -sub_morphim_pre ?pseries_norm2 //.
apply: pcore_max; last by rewrite morphim_normal ?pseries_normal.
have: pi.-group (pseries (rcons pis pi) G / pseries pis G).
by rewrite quotient_pseries pcore_pgroup.
by apply: pnat_dvd; rewrite !card_quotient ?pseries_norm2 // indexgS.
Qed.
Lemma quotient_pseries2 pi1 pi2 gT (G : {group gT}) :
'O_{pi1, pi2}(G) / 'O_pi1(G) = 'O_pi2(G / 'O_pi1(G)).
Proof. by rewrite -pseries1 -quotient_pseries. Qed.
Lemma quotient_pseries_cat pi1s pi2s gT (G : {group gT}) :
pseries (pi1s ++ pi2s) G / pseries pi1s G
= pseries pi2s (G / pseries pi1s G).
Proof.
elim/last_ind: pi2s => [|pi2s pi IHpi]; first by rewrite cats0 trivg_quotient.
have psN := pseries_normal _ G; set K := pseries _ G.
case: (third_isom (pseries_sub_catl pi1s pi2s G) (psN _)) => //= f inj_f im_f.
have nH2H: pseries pi2s (G / K) <| pseries (pi1s ++ rcons pi2s pi) G / K.
rewrite -IHpi morphim_normal // -cats1 catA.
by apply/andP; rewrite pseries_sub_catl pseries_norm2.
apply: (quotient_inj nH2H).
by apply/andP; rewrite /= -cats1 pseries_sub_catl pseries_norm2.
rewrite /= quotient_pseries /= -IHpi -rcons_cat.
rewrite -[G / _ / _](morphim_invm inj_f) //= {2}im_f //.
rewrite -(@injmF [igFun of @pcore pi]) /= ?injm_invm ?im_f // -quotient_pseries.
by rewrite -im_f ?morphim_invm ?morphimS ?normal_sub.
Qed.
Lemma pseries_catl_id pi1s pi2s gT (G : {group gT}) :
pseries pi1s (pseries (pi1s ++ pi2s) G) = pseries pi1s G.
Proof.
elim/last_ind: pi1s => [//|pi1s pi IHpi] in pi2s *.
apply: (@quotient_inj _ (pseries_group pi1s G)).
- rewrite /= -(IHpi (pi :: pi2s)) cat_rcons /(_ <| _) pseries_norm2.
by rewrite -cats1 pseries_sub_catl.
- by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl.
rewrite /= cat_rcons -(IHpi (pi :: pi2s)) {1}quotient_pseries IHpi.
apply/eqP; rewrite quotient_pseries eqEsubset !pcore_max ?pcore_pgroup //=.
rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2.
by rewrite -cat_rcons pseries_sub_catl.
by rewrite gFnormal_trans ?quotient_normal ?gFnormal.
Qed.
Lemma pseries_char_catl pi1s pi2s gT (G : {group gT}) :
pseries pi1s G \char pseries (pi1s ++ pi2s) G.
Proof. by rewrite -(pseries_catl_id pi1s pi2s G) pseries_char. Qed.
Lemma pseries_catr_id pi1s pi2s gT (G : {group gT}) :
pseries pi2s (pseries (pi1s ++ pi2s) G) = pseries pi2s G.
Proof.
elim/last_ind: pi2s => [//|pi2s pi IHpi] in G *.
have Epis: pseries pi2s (pseries (pi1s ++ rcons pi2s pi) G) = pseries pi2s G.
by rewrite -cats1 catA -[RHS]IHpi -[LHS]IHpi /= [pseries (_ ++ _) _]pseries_catl_id.
apply: (@quotient_inj _ (pseries_group pi2s G)).
- by rewrite /= -Epis /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl.
- by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl.
rewrite /= -Epis {1}quotient_pseries Epis quotient_pseries.
apply/eqP; rewrite eqEsubset !pcore_max ?pcore_pgroup //=.
rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2.
by rewrite pseries_sub_catr.
by rewrite gFnormal_trans ?morphim_normal ?gFnormal.
Qed.
Lemma pseries_char_catr pi1s pi2s gT (G : {group gT}) :
pseries pi2s G \char pseries (pi1s ++ pi2s) G.
Proof. by rewrite -(pseries_catr_id pi1s pi2s G) pseries_char. Qed.
Lemma pcore_modp pi gT (G H : {group gT}) :
H <| G -> pi.-group H -> pcore_mod G pi H = 'O_pi(G).
Proof.
move=> nsHG piH; have nHG := normal_norm nsHG; apply/eqP.
rewrite eqEsubset andbC -sub_morphim_pre ?(gFsub_trans, morphim_pcore) //=.
rewrite -[G in 'O_pi(G)](quotientGK nsHG) pcore_max //.
by rewrite -(pquotient_pgroup piH) ?subsetIl // cosetpreK pcore_pgroup.
by rewrite morphpre_normal ?gFnormal ?gFsub_trans ?morphim_sub.
Qed.
Lemma pquotient_pcore pi gT (G H : {group gT}) :
H <| G -> pi.-group H -> 'O_pi(G / H) = 'O_pi(G) / H.
Proof. by move=> nsHG piH; rewrite -quotient_pcore_mod pcore_modp. Qed.
Lemma trivg_pcore_quotient pi gT (G : {group gT}) : 'O_pi(G / 'O_pi(G)) = 1.
Proof. by rewrite pquotient_pcore ?gFnormal ?pcore_pgroup ?trivg_quotient. Qed.
Lemma pseries_rcons_id pis pi gT (G : {group gT}) :
pseries (rcons (rcons pis pi) pi) G = pseries (rcons pis pi) G.
Proof.
apply/eqP; rewrite -!cats1 eqEsubset pseries_sub_catl andbT -catA.
rewrite -(quotientSGK _ (pseries_sub_catl _ _ _)) ?pseries_norm2 //.
rewrite !quotient_pseries_cat -quotient_sub1 ?pseries_norm2 //.
by rewrite quotient_pseries_cat /= !pseries1 trivg_pcore_quotient.
Qed.
End MorphPcore.
Section EqPcore.
Variables gT : finGroupType.
Implicit Types (pi rho : nat_pred) (G H : {group gT}).
Lemma sub_in_pcore pi rho G :
{in \pi(G), {subset pi <= rho}} -> 'O_pi(G) \subset 'O_rho(G).
Proof.
move=> pi_sub_rho; rewrite pcore_max ?pcore_normal //.
apply: sub_in_pnat (pcore_pgroup _ _) => p.
by move/(piSg (pcore_sub _ _)); apply: pi_sub_rho.
Qed.
Lemma sub_pcore pi rho G : {subset pi <= rho} -> 'O_pi(G) \subset 'O_rho(G).
Proof. by move=> pi_sub_rho; apply: sub_in_pcore (in1W pi_sub_rho). Qed.
Lemma eq_in_pcore pi rho G : {in \pi(G), pi =i rho} -> 'O_pi(G) = 'O_rho(G).
Proof.
move=> eq_pi_rho; apply/eqP; rewrite eqEsubset.
by rewrite !sub_in_pcore // => p /eq_pi_rho->.
Qed.
Lemma eq_pcore pi rho G : pi =i rho -> 'O_pi(G) = 'O_rho(G).
Proof. by move=> eq_pi_rho; apply: eq_in_pcore (in1W eq_pi_rho). Qed.
Lemma pcoreNK pi G : 'O_pi^'^'(G) = 'O_pi(G).
Proof. by apply: eq_pcore; apply: negnK. Qed.
Lemma eq_p'core pi rho G : pi =i rho -> 'O_pi^'(G) = 'O_rho^'(G).
Proof. by move/eq_negn; apply: eq_pcore. Qed.
Lemma sdprod_Hall_p'coreP pi H G :
pi^'.-Hall(G) 'O_pi^'(G) -> reflect ('O_pi^'(G) ><| H = G) (pi.-Hall(G) H).
Proof. by rewrite -(pHallNK pi G H); apply: sdprod_Hall_pcoreP. Qed.
Lemma sdprod_p'core_HallP pi H G :
pi.-Hall(G) H -> reflect ('O_pi^'(G) ><| H = G) (pi^'.-Hall(G) 'O_pi^'(G)).
Proof. by rewrite -(pHallNK pi G H); apply: sdprod_pcore_HallP. Qed.
Lemma pcoreI pi rho G : 'O_[predI pi & rho](G) = 'O_pi('O_rho(G)).
Proof.
apply/eqP; rewrite eqEsubset !pcore_max //.
- rewrite /pgroup pnatI -!pgroupE.
by rewrite pcore_pgroup (pgroupS (pcore_sub pi _))// pcore_pgroup.
- by rewrite !gFnormal_trans.
- by apply: sub_pgroup (pcore_pgroup _ _) => p /andP[].
apply/andP; split; first by apply: sub_pcore => p /andP[].
by rewrite gFnorm_trans ?normsG ?gFsub.
Qed.
Lemma bigcap_p'core pi G :
G :&: \bigcap_(p < #|G|.+1 | (p : nat) \in pi) 'O_p^'(G) = 'O_pi^'(G).
Proof.
apply/eqP; rewrite eqEsubset subsetI pcore_sub pcore_max /=.
- by apply/bigcapsP=> p pi_p; apply: sub_pcore => r; apply: contraNneq => ->.
- apply/pgroupP=> q q_pr qGpi'; apply: contraL (eqxx q) => /= pi_q.
apply: (pgroupP (pcore_pgroup q^' G)) => //.
have qG: q %| #|G| by rewrite (dvdn_trans qGpi') // cardSg ?subsetIl.
have ltqG: q < #|G|.+1 by rewrite ltnS dvdn_leq.
rewrite (dvdn_trans qGpi') ?cardSg ?subIset //= orbC.
by rewrite (bigcap_inf (Ordinal ltqG)).
rewrite /normal subsetIl normsI ?normG // norms_bigcap //.
by apply/bigcapsP => p _; apply: gFnorm.
Qed.
Lemma coprime_pcoreC (rT : finGroupType) pi G (R : {group rT}) :
coprime #|'O_pi(G)| #|'O_pi^'(R)|.
Proof. exact: pnat_coprime (pcore_pgroup _ _) (pcore_pgroup _ _). Qed.
Lemma TI_pcoreC pi G H : 'O_pi(G) :&: 'O_pi^'(H) = 1.
Proof. by rewrite coprime_TIg ?coprime_pcoreC. Qed.
Lemma pcore_setI_normal pi G H : H <| G -> 'O_pi(G) :&: H = 'O_pi(H).
Proof.
move=> nsHG; apply/eqP; rewrite eqEsubset subsetI pcore_sub setIC.
rewrite !pcore_max ?(pgroupS (subsetIr H _)) ?pcore_pgroup ?gFnormal_trans //=.
by rewrite norm_normalI ?gFnorm_trans ?normsG ?normal_sub.
Qed.
End EqPcore.
Arguments sdprod_Hall_pcoreP {pi gT H G}.
Arguments sdprod_Hall_p'coreP {gT pi H G}.
Section Injm.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Implicit Types (A : {set aT}) (G H : {group aT}).
Lemma injm_pgroup pi A : A \subset D -> pi.-group (f @* A) = pi.-group A.
Proof. by move=> sAD; rewrite /pgroup card_injm. Qed.
Lemma injm_pelt pi x : x \in D -> pi.-elt (f x) = pi.-elt x.
Proof. by move=> Dx; rewrite /p_elt order_injm. Qed.
Lemma injm_pHall pi G H :
G \subset D -> H \subset D -> pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H.
Proof. by move=> sGD sGH; rewrite !pHallE injmSK ?card_injm. Qed.
Lemma injm_pcore pi G : G \subset D -> f @* 'O_pi(G) = 'O_pi(f @* G).
Proof. exact: injmF. Qed.
Lemma injm_pseries pis G :
G \subset D -> f @* pseries pis G = pseries pis (f @* G).
Proof. exact: injmF. Qed.
End Injm.
Section Isog.
Variables (aT rT : finGroupType) (G : {group aT}) (H : {group rT}).
Lemma isog_pgroup pi : G \isog H -> pi.-group G = pi.-group H.
Proof. by move=> isoGH; rewrite /pgroup (card_isog isoGH). Qed.
Lemma isog_pcore pi : G \isog H -> 'O_pi(G) \isog 'O_pi(H).
Proof. exact: gFisog. Qed.
Lemma isog_pseries pis : G \isog H -> pseries pis G \isog pseries pis H.
Proof. exact: gFisog. Qed.
End Isog.
|
Defs.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov
-/
import Mathlib.Algebra.Module.Equiv.Defs
import Mathlib.Algebra.Module.Submodule.Defs
import Mathlib.GroupTheory.QuotientGroup.Defs
/-!
# Quotients by submodules
* If `p` is a submodule of `M`, `M ⧸ p` is the quotient of `M` with respect to `p`:
that is, elements of `M` are identified if their difference is in `p`. This is itself a module.
## Main definitions
* `Submodule.Quotient.mk`: a function sending an element of `M` to `M ⧸ p`
* `Submodule.Quotient.module`: `M ⧸ p` is a module
* `Submodule.Quotient.mkQ`: a linear map sending an element of `M` to `M ⧸ p`
* `Submodule.quotEquivOfEq`: if `p` and `p'` are equal, their quotients are equivalent
-/
-- For most of this file we work over a noncommutative ring
section Ring
namespace Submodule
variable {R M : Type*} {r : R} {x y : M} [Ring R] [AddCommGroup M] [Module R M]
variable (p p' : Submodule R M)
open QuotientAddGroup
/-- The equivalence relation associated to a submodule `p`, defined by `x ≈ y` iff `-x + y ∈ p`.
Note this is equivalent to `y - x ∈ p`, but defined this way to be defeq to the `AddSubgroup`
version, where commutativity can't be assumed. -/
def quotientRel : Setoid M :=
QuotientAddGroup.leftRel p.toAddSubgroup
theorem quotientRel_def {x y : M} : p.quotientRel x y ↔ x - y ∈ p :=
Iff.trans
(by
rw [leftRel_apply, sub_eq_add_neg, neg_add, neg_neg]
rfl)
neg_mem_iff
/-- The quotient of a module `M` by a submodule `p ⊆ M`. -/
instance hasQuotient : HasQuotient M (Submodule R M) :=
⟨fun p => Quotient (quotientRel p)⟩
namespace Quotient
/-- Map associating to an element of `M` the corresponding element of `M/p`,
when `p` is a submodule of `M`. -/
def mk {p : Submodule R M} : M → M ⧸ p :=
Quotient.mk''
theorem mk'_eq_mk' {p : Submodule R M} (x : M) :
@Quotient.mk' _ (quotientRel p) x = mk x :=
rfl
theorem mk''_eq_mk {p : Submodule R M} (x : M) : (Quotient.mk'' x : M ⧸ p) = mk x :=
rfl
theorem quot_mk_eq_mk {p : Submodule R M} (x : M) : (Quot.mk _ x : M ⧸ p) = mk x :=
rfl
protected theorem eq' {x y : M} : (mk x : M ⧸ p) = mk y ↔ -x + y ∈ p :=
QuotientAddGroup.eq
protected theorem eq {x y : M} : (mk x : M ⧸ p) = mk y ↔ x - y ∈ p :=
(Submodule.Quotient.eq' p).trans (leftRel_apply.symm.trans p.quotientRel_def)
instance : Zero (M ⧸ p) where
-- Use Quotient.mk'' instead of mk here because mk is not reducible.
-- This would lead to non-defeq diamonds.
-- See also the same comment at the One instance for Con.
zero := Quotient.mk'' 0
instance : Inhabited (M ⧸ p) :=
⟨0⟩
@[simp]
theorem mk_zero : mk 0 = (0 : M ⧸ p) :=
rfl
@[simp]
theorem mk_eq_zero : (mk x : M ⧸ p) = 0 ↔ x ∈ p := by simpa using (Quotient.eq' p : mk x = 0 ↔ _)
instance addCommGroup : AddCommGroup (M ⧸ p) :=
QuotientAddGroup.Quotient.addCommGroup p.toAddSubgroup
@[simp]
theorem mk_add : (mk (x + y) : M ⧸ p) = mk x + mk y :=
rfl
@[simp]
theorem mk_neg : (mk (-x) : M ⧸ p) = -(mk x) :=
rfl
@[simp]
theorem mk_sub : (mk (x - y) : M ⧸ p) = mk x - mk y :=
rfl
variable {p} in
@[simp]
theorem mk_out (m : M ⧸ p) : Submodule.Quotient.mk (Quotient.out m) = m :=
Quotient.out_eq m
protected nonrec lemma «forall» {P : M ⧸ p → Prop} : (∀ a, P a) ↔ ∀ a, P (mk a) := Quotient.forall
theorem subsingleton_iff : Subsingleton (M ⧸ p) ↔ ∀ x : M, x ∈ p := by
rw [subsingleton_iff_forall_eq 0, Submodule.Quotient.forall]
simp_rw [Submodule.Quotient.mk_eq_zero]
section SMul
variable {S : Type*} [SMul S R] [SMul S M] [IsScalarTower S R M] (P : Submodule R M)
instance instSMul' : SMul S (M ⧸ P) :=
⟨fun a =>
Quotient.map' (a • ·) fun x y h =>
leftRel_apply.mpr <| by simpa using Submodule.smul_mem P (a • (1 : R)) (leftRel_apply.mp h)⟩
/-- Shortcut to help the elaborator in the common case. -/
instance instSMul : SMul R (M ⧸ P) :=
Quotient.instSMul' P
@[simp]
theorem mk_smul (r : S) (x : M) : (mk (r • x) : M ⧸ p) = r • mk x :=
rfl
instance smulCommClass (T : Type*) [SMul T R] [SMul T M] [IsScalarTower T R M]
[SMulCommClass S T M] : SMulCommClass S T (M ⧸ P) where
smul_comm _x _y := Quotient.ind' fun _z => congr_arg mk (smul_comm _ _ _)
instance isScalarTower (T : Type*) [SMul T R] [SMul T M] [IsScalarTower T R M] [SMul S T]
[IsScalarTower S T M] : IsScalarTower S T (M ⧸ P) where
smul_assoc _x _y := Quotient.ind' fun _z => congr_arg mk (smul_assoc _ _ _)
instance isCentralScalar [SMul Sᵐᵒᵖ R] [SMul Sᵐᵒᵖ M] [IsScalarTower Sᵐᵒᵖ R M]
[IsCentralScalar S M] : IsCentralScalar S (M ⧸ P) where
op_smul_eq_smul _x := Quotient.ind' fun _z => congr_arg mk <| op_smul_eq_smul _ _
end SMul
section Module
variable {S : Type*}
instance mulAction' [Monoid S] [SMul S R] [MulAction S M] [IsScalarTower S R M]
(P : Submodule R M) : MulAction S (M ⧸ P) := fast_instance%
Function.Surjective.mulAction mk Quot.mk_surjective <| Submodule.Quotient.mk_smul P
instance mulAction (P : Submodule R M) : MulAction R (M ⧸ P) :=
Quotient.mulAction' P
instance smulZeroClass' [SMul S R] [SMulZeroClass S M] [IsScalarTower S R M] (P : Submodule R M) :
SMulZeroClass S (M ⧸ P) :=
ZeroHom.smulZeroClass ⟨mk, mk_zero _⟩ <| Submodule.Quotient.mk_smul P
instance smulZeroClass (P : Submodule R M) : SMulZeroClass R (M ⧸ P) :=
Quotient.smulZeroClass' P
instance distribSMul' [SMul S R] [DistribSMul S M] [IsScalarTower S R M] (P : Submodule R M) :
DistribSMul S (M ⧸ P) := fast_instance%
Function.Surjective.distribSMul {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl}
Quot.mk_surjective (Submodule.Quotient.mk_smul P)
instance distribSMul (P : Submodule R M) : DistribSMul R (M ⧸ P) :=
Quotient.distribSMul' P
instance distribMulAction' [Monoid S] [SMul S R] [DistribMulAction S M] [IsScalarTower S R M]
(P : Submodule R M) : DistribMulAction S (M ⧸ P) := fast_instance%
Function.Surjective.distribMulAction {toFun := mk, map_zero' := rfl, map_add' := fun _ _ => rfl}
Quot.mk_surjective (Submodule.Quotient.mk_smul P)
instance distribMulAction (P : Submodule R M) : DistribMulAction R (M ⧸ P) :=
Quotient.distribMulAction' P
instance module' [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] (P : Submodule R M) :
Module S (M ⧸ P) := fast_instance%
Function.Surjective.module _ {toFun := mk, map_zero' := by rfl, map_add' := fun _ _ => by rfl}
Quot.mk_surjective (Submodule.Quotient.mk_smul P)
instance module (P : Submodule R M) : Module R (M ⧸ P) :=
Quotient.module' P
end Module
@[elab_as_elim]
theorem induction_on {C : M ⧸ p → Prop} (x : M ⧸ p) (H : ∀ z, C (Submodule.Quotient.mk z)) :
C x := Quotient.inductionOn' x H
theorem mk_surjective : Function.Surjective (@mk _ _ _ _ _ p) := by
rintro ⟨x⟩
exact ⟨x, rfl⟩
end Quotient
section
variable {M₂ : Type*} [AddCommGroup M₂] [Module R M₂]
theorem quot_hom_ext (f g : (M ⧸ p) →ₗ[R] M₂) (h : ∀ x : M, f (Quotient.mk x) = g (Quotient.mk x)) :
f = g :=
LinearMap.ext fun x => Submodule.Quotient.induction_on _ x h
/-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/
def mkQ : M →ₗ[R] M ⧸ p where
toFun := Quotient.mk
map_add' := by simp
map_smul' := by simp
@[simp]
theorem mkQ_apply (x : M) : p.mkQ x = Quotient.mk x :=
rfl
theorem mkQ_surjective : Function.Surjective p.mkQ := by
rintro ⟨x⟩; exact ⟨x, rfl⟩
end
variable {R₂ M₂ : Type*} [Ring R₂] [AddCommGroup M₂] [Module R₂ M₂] {τ₁₂ : R →+* R₂}
/-- Two `LinearMap`s from a quotient module are equal if their compositions with
`submodule.mkQ` are equal.
See note [partially-applied ext lemmas]. -/
@[ext 1100] -- Porting note: increase priority so this applies before `LinearMap.ext`
theorem linearMap_qext ⦃f g : M ⧸ p →ₛₗ[τ₁₂] M₂⦄ (h : f.comp p.mkQ = g.comp p.mkQ) : f = g :=
LinearMap.ext fun x => Submodule.Quotient.induction_on _ x <| (LinearMap.congr_fun h :)
/-- Quotienting by equal submodules gives linearly equivalent quotients. -/
def quotEquivOfEq (h : p = p') : (M ⧸ p) ≃ₗ[R] M ⧸ p' :=
{ @Quotient.congr _ _ (quotientRel p) (quotientRel p') (Equiv.refl _) fun a b => by
subst h
rfl with
map_add' := by
rintro ⟨x⟩ ⟨y⟩
rfl
map_smul' := by
rintro x ⟨y⟩
rfl }
@[simp]
theorem quotEquivOfEq_mk (h : p = p') (x : M) :
Submodule.quotEquivOfEq p p' h (Submodule.Quotient.mk x) =
(Submodule.Quotient.mk x) :=
rfl
end Submodule
end Ring
|
Taylor.lean
|
/-
Copyright (c) 2022 Moritz Doll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Doll
-/
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.EuclideanDomain.Field
import Mathlib.Algebra.Polynomial.Module.Basic
import Mathlib.Analysis.Calculus.ContDiff.Basic
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.IteratedDeriv.Defs
import Mathlib.Analysis.Calculus.MeanValue
import Mathlib.Analysis.Calculus.Deriv.MeanValue
/-!
# Taylor's theorem
This file defines the Taylor polynomial of a real function `f : ℝ → E`,
where `E` is a normed vector space over `ℝ` and proves Taylor's theorem,
which states that if `f` is sufficiently smooth, then
`f` can be approximated by the Taylor polynomial up to an explicit error term.
## Main definitions
* `taylorCoeffWithin`: the Taylor coefficient using `iteratedDerivWithin`
* `taylorWithin`: the Taylor polynomial using `iteratedDerivWithin`
## Main statements
* `taylor_tendsto`: Taylor's theorem as a limit
* `taylor_isLittleO`: Taylor's theorem using little-o notation
* `taylor_mean_remainder`: Taylor's theorem with the general form of the remainder term
* `taylor_mean_remainder_lagrange`: Taylor's theorem with the Lagrange remainder
* `taylor_mean_remainder_cauchy`: Taylor's theorem with the Cauchy remainder
* `exists_taylor_mean_remainder_bound`: Taylor's theorem for vector valued functions with a
polynomial bound on the remainder
## TODO
* the integral form of the remainder
* Generalization to higher dimensions
## Tags
Taylor polynomial, Taylor's theorem
-/
open scoped Interval Topology Nat
open Set
variable {𝕜 E F : Type*}
variable [NormedAddCommGroup E] [NormedSpace ℝ E]
/-- The `k`th coefficient of the Taylor polynomial. -/
noncomputable def taylorCoeffWithin (f : ℝ → E) (k : ℕ) (s : Set ℝ) (x₀ : ℝ) : E :=
(k ! : ℝ)⁻¹ • iteratedDerivWithin k f s x₀
/-- The Taylor polynomial with derivatives inside of a set `s`.
The Taylor polynomial is given by
$$∑_{k=0}^n \frac{(x - x₀)^k}{k!} f^{(k)}(x₀),$$
where $f^{(k)}(x₀)$ denotes the iterated derivative in the set `s`. -/
noncomputable def taylorWithin (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) : PolynomialModule ℝ E :=
(Finset.range (n + 1)).sum fun k =>
PolynomialModule.comp (Polynomial.X - Polynomial.C x₀)
(PolynomialModule.single ℝ k (taylorCoeffWithin f k s x₀))
/-- The Taylor polynomial with derivatives inside of a set `s` considered as a function `ℝ → E` -/
noncomputable def taylorWithinEval (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) : E :=
PolynomialModule.eval x (taylorWithin f n s x₀)
theorem taylorWithin_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) :
taylorWithin f (n + 1) s x₀ = taylorWithin f n s x₀ +
PolynomialModule.comp (Polynomial.X - Polynomial.C x₀)
(PolynomialModule.single ℝ (n + 1) (taylorCoeffWithin f (n + 1) s x₀)) := by
dsimp only [taylorWithin]
rw [Finset.sum_range_succ]
@[simp]
theorem taylorWithinEval_succ (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) :
taylorWithinEval f (n + 1) s x₀ x = taylorWithinEval f n s x₀ x +
(((n + 1 : ℝ) * n !)⁻¹ * (x - x₀) ^ (n + 1)) • iteratedDerivWithin (n + 1) f s x₀ := by
simp_rw [taylorWithinEval, taylorWithin_succ, LinearMap.map_add, PolynomialModule.comp_eval]
congr
simp only [Polynomial.eval_sub, Polynomial.eval_X, Polynomial.eval_C,
PolynomialModule.eval_single, mul_inv_rev]
dsimp only [taylorCoeffWithin]
rw [← mul_smul, mul_comm, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one,
mul_inv_rev]
/-- The Taylor polynomial of order zero evaluates to `f x`. -/
@[simp]
theorem taylor_within_zero_eval (f : ℝ → E) (s : Set ℝ) (x₀ x : ℝ) :
taylorWithinEval f 0 s x₀ x = f x₀ := by
dsimp only [taylorWithinEval]
dsimp only [taylorWithin]
dsimp only [taylorCoeffWithin]
simp
/-- Evaluating the Taylor polynomial at `x = x₀` yields `f x`. -/
@[simp]
theorem taylorWithinEval_self (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ : ℝ) :
taylorWithinEval f n s x₀ x₀ = f x₀ := by
induction n with
| zero => exact taylor_within_zero_eval _ _ _ _
| succ k hk => simp [hk]
theorem taylor_within_apply (f : ℝ → E) (n : ℕ) (s : Set ℝ) (x₀ x : ℝ) :
taylorWithinEval f n s x₀ x =
∑ k ∈ Finset.range (n + 1), ((k ! : ℝ)⁻¹ * (x - x₀) ^ k) • iteratedDerivWithin k f s x₀ := by
induction n with
| zero => simp
| succ k hk =>
rw [taylorWithinEval_succ, Finset.sum_range_succ, hk]
simp [Nat.factorial]
/-- If `f` is `n` times continuous differentiable on a set `s`, then the Taylor polynomial
`taylorWithinEval f n s x₀ x` is continuous in `x₀`. -/
theorem continuousOn_taylorWithinEval {f : ℝ → E} {x : ℝ} {n : ℕ} {s : Set ℝ}
(hs : UniqueDiffOn ℝ s) (hf : ContDiffOn ℝ n f s) :
ContinuousOn (fun t => taylorWithinEval f n s t x) s := by
simp_rw [taylor_within_apply]
refine continuousOn_finset_sum (Finset.range (n + 1)) fun i hi => ?_
refine (continuousOn_const.mul ((continuousOn_const.sub continuousOn_id).pow _)).smul ?_
rw [contDiffOn_nat_iff_continuousOn_differentiableOn_deriv hs] at hf
simp only [Finset.mem_range] at hi
refine hf.1 i ?_
simp only [Nat.lt_succ_iff.mp hi]
/-- Helper lemma for calculating the derivative of the monomial that appears in Taylor
expansions. -/
theorem monomial_has_deriv_aux (t x : ℝ) (n : ℕ) :
HasDerivAt (fun y => (x - y) ^ (n + 1)) (-(n + 1) * (x - t) ^ n) t := by
simp_rw [sub_eq_neg_add]
rw [← neg_one_mul, mul_comm (-1 : ℝ), mul_assoc, mul_comm (-1 : ℝ), ← mul_assoc]
convert ((hasDerivAt_id t).neg.add_const x).pow (n + 1)
simp only [Nat.cast_add, Nat.cast_one]
theorem hasDerivWithinAt_taylor_coeff_within {f : ℝ → E} {x y : ℝ} {k : ℕ} {s t : Set ℝ}
(ht : UniqueDiffWithinAt ℝ t y) (hs : s ∈ 𝓝[t] y)
(hf : DifferentiableWithinAt ℝ (iteratedDerivWithin (k + 1) f s) s y) :
HasDerivWithinAt
(fun z => (((k + 1 : ℝ) * k !)⁻¹ * (x - z) ^ (k + 1)) • iteratedDerivWithin (k + 1) f s z)
((((k + 1 : ℝ) * k !)⁻¹ * (x - y) ^ (k + 1)) • iteratedDerivWithin (k + 2) f s y -
((k ! : ℝ)⁻¹ * (x - y) ^ k) • iteratedDerivWithin (k + 1) f s y) t y := by
replace hf :
HasDerivWithinAt (iteratedDerivWithin (k + 1) f s) (iteratedDerivWithin (k + 2) f s y) t y := by
convert (hf.mono_of_mem_nhdsWithin hs).hasDerivWithinAt using 1
rw [iteratedDerivWithin_succ]
exact (derivWithin_of_mem_nhdsWithin hs ht hf).symm
have : HasDerivWithinAt (fun t => ((k + 1 : ℝ) * k !)⁻¹ * (x - t) ^ (k + 1))
(-((k ! : ℝ)⁻¹ * (x - y) ^ k)) t y := by
-- Commuting the factors:
have : -((k ! : ℝ)⁻¹ * (x - y) ^ k) = ((k + 1 : ℝ) * k !)⁻¹ * (-(k + 1) * (x - y) ^ k) := by
field_simp; ring
rw [this]
exact (monomial_has_deriv_aux y x _).hasDerivWithinAt.const_mul _
convert this.smul hf using 1
field_simp
rw [neg_div, neg_smul, sub_eq_add_neg]
/-- Calculate the derivative of the Taylor polynomial with respect to `x₀`.
Version for arbitrary sets -/
theorem hasDerivWithinAt_taylorWithinEval {f : ℝ → E} {x y : ℝ} {n : ℕ} {s s' : Set ℝ}
(hs_unique : UniqueDiffOn ℝ s) (hs' : s' ∈ 𝓝[s] y)
(hy : y ∈ s') (h : s' ⊆ s) (hf : ContDiffOn ℝ n f s)
(hf' : DifferentiableWithinAt ℝ (iteratedDerivWithin n f s) s y) :
HasDerivWithinAt (fun t => taylorWithinEval f n s t x)
(((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f s y) s' y := by
have hs'_unique : UniqueDiffWithinAt ℝ s' y :=
UniqueDiffWithinAt.mono_nhds (hs_unique _ (h hy)) (nhdsWithin_le_iff.mpr hs')
induction n with
| zero =>
simp only [taylor_within_zero_eval, Nat.factorial_zero, Nat.cast_one, inv_one, pow_zero,
mul_one, zero_add, one_smul]
simp only [iteratedDerivWithin_zero] at hf'
rw [iteratedDerivWithin_one]
exact hf'.hasDerivWithinAt.mono h
| succ k hk =>
simp_rw [Nat.add_succ, taylorWithinEval_succ]
simp only [add_zero, Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one]
have coe_lt_succ : (k : WithTop ℕ) < k.succ := Nat.cast_lt.2 k.lt_succ_self
have hdiff : DifferentiableOn ℝ (iteratedDerivWithin k f s) s' :=
(hf.differentiableOn_iteratedDerivWithin (mod_cast coe_lt_succ) hs_unique).mono h
specialize hk hf.of_succ ((hdiff y hy).mono_of_mem_nhdsWithin hs')
convert hk.add (hasDerivWithinAt_taylor_coeff_within hs'_unique
(nhdsWithin_mono _ h self_mem_nhdsWithin) hf') using 1
exact (add_sub_cancel _ _).symm
/-- Calculate the derivative of the Taylor polynomial with respect to `x₀`.
Version for open intervals -/
theorem taylorWithinEval_hasDerivAt_Ioo {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ} (hx : a < b)
(ht : t ∈ Ioo a b) (hf : ContDiffOn ℝ n f (Icc a b))
(hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Ioo a b)) :
HasDerivAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) t :=
have h_nhds : Ioo a b ∈ 𝓝 t := isOpen_Ioo.mem_nhds ht
have h_nhds' : Ioo a b ∈ 𝓝[Icc a b] t := nhdsWithin_le_nhds h_nhds
(hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx) h_nhds' ht
Ioo_subset_Icc_self hf <| (hf' t ht).mono_of_mem_nhdsWithin h_nhds').hasDerivAt h_nhds
/-- Calculate the derivative of the Taylor polynomial with respect to `x₀`.
Version for closed intervals -/
theorem hasDerivWithinAt_taylorWithinEval_at_Icc {f : ℝ → E} {a b t : ℝ} (x : ℝ) {n : ℕ}
(hx : a < b) (ht : t ∈ Icc a b) (hf : ContDiffOn ℝ n f (Icc a b))
(hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b)) :
HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a b) t :=
hasDerivWithinAt_taylorWithinEval (uniqueDiffOn_Icc hx)
self_mem_nhdsWithin ht rfl.subset hf (hf' t ht)
/-- Calculate the derivative of the Taylor polynomial with respect to `x`. -/
theorem hasDerivAt_taylorWithinEval_succ {x₀ x : ℝ} {s : Set ℝ} (f : ℝ → E) (n : ℕ) :
HasDerivAt (taylorWithinEval f (n + 1) s x₀)
(taylorWithinEval (derivWithin f s) n s x₀ x) x := by
change HasDerivAt (fun x ↦ taylorWithinEval f _ s x₀ x) _ _
simp_rw [taylor_within_apply]
have : ∀ (i : ℕ) {c : ℝ} {c' : E},
HasDerivAt (fun x ↦ (c * (x - x₀) ^ i) • c') ((c * (i * (x - x₀) ^ (i - 1) * 1)) • c') x :=
fun _ _ ↦ hasDerivAt_id _ |>.sub_const _ |>.pow _ |>.const_mul _ |>.smul_const _
apply HasDerivAt.fun_sum (fun i _ => this i) |>.congr_deriv
rw [Finset.sum_range_succ', Nat.cast_zero, zero_mul, zero_mul, mul_zero, zero_smul, add_zero]
apply Finset.sum_congr rfl
intro i _
rw [← iteratedDerivWithin_succ']
congr 1
field_simp [Nat.factorial_succ]
ring
/-- **Taylor's theorem** using little-o notation. -/
theorem taylor_isLittleO {f : ℝ → E} {x₀ : ℝ} {n : ℕ} {s : Set ℝ}
(hs : Convex ℝ s) (hx₀s : x₀ ∈ s) (hf : ContDiffOn ℝ n f s) :
(fun x ↦ f x - taylorWithinEval f n s x₀ x) =o[𝓝[s] x₀] fun x ↦ (x - x₀) ^ n := by
induction n generalizing f with
| zero =>
simp only [taylor_within_zero_eval, pow_zero, Asymptotics.isLittleO_one_iff]
rw [tendsto_sub_nhds_zero_iff]
exact hf.continuousOn.continuousWithinAt hx₀s
| succ n h =>
rcases s.eq_singleton_or_nontrivial hx₀s with rfl | hs'
· simp
replace hs' := uniqueDiffOn_convex hs (hs.nontrivial_iff_nonempty_interior.1 hs')
simp only [Nat.cast_add, Nat.cast_one] at hf
convert Convex.isLittleO_pow_succ_real hs hx₀s ?_ (h (hf.derivWithin hs' le_rfl))
(f := fun x ↦ f x - taylorWithinEval f (n + 1) s x₀ x) using 1
· simp
· intro x hx
refine HasDerivWithinAt.sub ?_ (hasDerivAt_taylorWithinEval_succ f n).hasDerivWithinAt
exact (hf.differentiableOn le_add_self _ hx).hasDerivWithinAt
/-- **Taylor's theorem** as a limit. -/
theorem taylor_tendsto {f : ℝ → E} {x₀ : ℝ} {n : ℕ} {s : Set ℝ}
(hs : Convex ℝ s) (hx₀s : x₀ ∈ s) (hf : ContDiffOn ℝ n f s) :
Filter.Tendsto (fun x ↦ ((x - x₀) ^ n)⁻¹ • (f x - taylorWithinEval f n s x₀ x))
(𝓝[s] x₀) (𝓝 0) := by
have h_isLittleO := (taylor_isLittleO hs hx₀s hf).norm_norm
rw [Asymptotics.isLittleO_iff_tendsto] at h_isLittleO
· rw [tendsto_zero_iff_norm_tendsto_zero]
simpa [norm_smul, div_eq_inv_mul] using h_isLittleO
· simp only [norm_pow, Real.norm_eq_abs, pow_eq_zero_iff', abs_eq_zero, ne_eq, norm_eq_zero,
and_imp]
intro x hx
rw [sub_eq_zero] at hx
simp [hx]
/-- **Taylor's theorem** as a limit. -/
theorem Real.taylor_tendsto {f : ℝ → ℝ} {x₀ : ℝ} {n : ℕ} {s : Set ℝ}
(hs : Convex ℝ s) (hx₀s : x₀ ∈ s) (hf : ContDiffOn ℝ n f s) :
Filter.Tendsto (fun x ↦ (f x - taylorWithinEval f n s x₀ x) / (x - x₀) ^ n)
(𝓝[s] x₀) (𝓝 0) := by
convert _root_.taylor_tendsto hs hx₀s hf using 2 with x
simp [div_eq_inv_mul]
/-! ### Taylor's theorem with mean value type remainder estimate -/
/-- **Taylor's theorem** with the general mean value form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and
`n+1`-times differentiable on the open set `Ioo x₀ x`, and `g` is a differentiable function on
`Ioo x₀ x` and continuous on `Icc x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such that
$$f(x) - (P_n f)(x₀, x) = \frac{(x - x')^n}{n!} \frac{g(x) - g(x₀)}{g' x'},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$. -/
theorem taylor_mean_remainder {f : ℝ → ℝ} {g g' : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x)
(hf : ContDiffOn ℝ n f (Icc x₀ x))
(hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x))
(gcont : ContinuousOn g (Icc x₀ x))
(gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt g (g' x_1) x_1)
(g'_ne : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → g' x_1 ≠ 0) :
∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x =
((x - x') ^ n / n ! * (g x - g x₀) / g' x') • iteratedDerivWithin (n + 1) f (Icc x₀ x) x' := by
-- We apply the mean value theorem
rcases exists_ratio_hasDerivAt_eq_ratio_slope (fun t => taylorWithinEval f n (Icc x₀ x) t x)
(fun t => ((n ! : ℝ)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc x₀ x) t) hx
(continuousOn_taylorWithinEval (uniqueDiffOn_Icc hx) hf)
(fun _ hy => taylorWithinEval_hasDerivAt_Ioo x hx hy hf hf') g g' gcont gdiff with ⟨y, hy, h⟩
use y, hy
-- The rest is simplifications and trivial calculations
simp only [taylorWithinEval_self] at h
rw [mul_comm, ← div_left_inj' (g'_ne y hy), mul_div_cancel_right₀ _ (g'_ne y hy)] at h
rw [← h]
field_simp [g'_ne y hy]
ring
/-- **Taylor's theorem** with the Lagrange form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable in the closed set `Icc x₀ x` and
`n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such
that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x₀)^{n+1}}{(n+1)!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_lagrange {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x)
(hf : ContDiffOn ℝ n f (Icc x₀ x))
(hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) :
∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x =
iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x₀) ^ (n + 1) / (n + 1)! := by
have gcont : ContinuousOn (fun t : ℝ => (x - t) ^ (n + 1)) (Icc x₀ x) := by fun_prop
have xy_ne : ∀ y : ℝ, y ∈ Ioo x₀ x → (x - y) ^ n ≠ 0 := by
intro y hy
refine pow_ne_zero _ ?_
rw [mem_Ioo] at hy
rw [sub_ne_zero]
exact hy.2.ne'
have hg' : ∀ y : ℝ, y ∈ Ioo x₀ x → -(↑n + 1) * (x - y) ^ n ≠ 0 := fun y hy =>
mul_ne_zero (neg_ne_zero.mpr (Nat.cast_add_one_ne_zero n)) (xy_ne y hy)
-- We apply the general theorem with g(t) = (x - t)^(n+1)
rcases taylor_mean_remainder hx hf hf' gcont (fun y _ => monomial_has_deriv_aux y x _) hg' with
⟨y, hy, h⟩
use y, hy
simp only [sub_self, zero_pow, Ne, Nat.succ_ne_zero, not_false_iff, zero_sub, mul_neg] at h
rw [h, neg_div, ← div_neg, neg_mul, neg_neg]
field_simp [xy_ne y hy, Nat.factorial]; ring
/-- A corollary of Taylor's theorem with the Lagrange form of the remainder. -/
lemma taylor_mean_remainder_lagrange_iteratedDeriv {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x)
(hf : ContDiffOn ℝ (n + 1) f (Icc x₀ x)) :
∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x =
iteratedDeriv (n + 1) f x' * (x - x₀) ^ (n + 1) / (n + 1)! := by
have hu : UniqueDiffOn ℝ (Icc x₀ x) := uniqueDiffOn_Icc hx
have hd : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Icc x₀ x) := by
refine hf.differentiableOn_iteratedDerivWithin ?_ hu
norm_cast
norm_num
obtain ⟨x', h1, h2⟩ := taylor_mean_remainder_lagrange hx hf.of_succ (hd.mono Ioo_subset_Icc_self)
use x', h1
rw [h2, iteratedDeriv_eq_iteratedFDeriv, iteratedDerivWithin_eq_iteratedFDerivWithin,
iteratedFDerivWithin_eq_iteratedFDeriv hu _ ⟨le_of_lt h1.1, le_of_lt h1.2⟩]
exact hf.contDiffAt (Icc_mem_nhds_iff.2 h1)
/-- **Taylor's theorem** with the Cauchy form of the remainder.
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc x₀ x` and
`n+1`-times differentiable on the open set `Ioo x₀ x`. Then there exists an `x' ∈ Ioo x₀ x` such
that $$f(x) - (P_n f)(x₀, x) = \frac{f^{(n+1)}(x') (x - x')^n (x-x₀)}{n!},$$
where $P_n f$ denotes the Taylor polynomial of degree $n$ and $f^{(n+1)}$ is the $n+1$-th iterated
derivative. -/
theorem taylor_mean_remainder_cauchy {f : ℝ → ℝ} {x x₀ : ℝ} {n : ℕ} (hx : x₀ < x)
(hf : ContDiffOn ℝ n f (Icc x₀ x))
(hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc x₀ x)) (Ioo x₀ x)) :
∃ x' ∈ Ioo x₀ x, f x - taylorWithinEval f n (Icc x₀ x) x₀ x =
iteratedDerivWithin (n + 1) f (Icc x₀ x) x' * (x - x') ^ n / n ! * (x - x₀) := by
have gcont : ContinuousOn id (Icc x₀ x) := by fun_prop
have gdiff : ∀ x_1 : ℝ, x_1 ∈ Ioo x₀ x → HasDerivAt id ((fun _ : ℝ => (1 : ℝ)) x_1) x_1 :=
fun _ _ => hasDerivAt_id _
-- We apply the general theorem with g = id
rcases taylor_mean_remainder hx hf hf' gcont gdiff fun _ _ => by simp with ⟨y, hy, h⟩
use y, hy
rw [h]
field_simp [n.factorial_ne_zero]
ring
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
The difference of `f` and its `n`-th Taylor polynomial can be estimated by
`C * (x - a)^(n+1) / n!` where `C` is a bound for the `n+1`-th iterated derivative of `f`. -/
theorem taylor_mean_remainder_bound {f : ℝ → E} {a b C x : ℝ} {n : ℕ} (hab : a ≤ b)
(hf : ContDiffOn ℝ (n + 1) f (Icc a b)) (hx : x ∈ Icc a b)
(hC : ∀ y ∈ Icc a b, ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≤ C) :
‖f x - taylorWithinEval f n (Icc a b) a x‖ ≤ C * (x - a) ^ (n + 1) / n ! := by
rcases eq_or_lt_of_le hab with (rfl | h)
· rw [Icc_self, mem_singleton_iff] at hx
simp [hx]
-- The nth iterated derivative is differentiable
have hf' : DifferentiableOn ℝ (iteratedDerivWithin n f (Icc a b)) (Icc a b) :=
hf.differentiableOn_iteratedDerivWithin (mod_cast n.lt_succ_self)
(uniqueDiffOn_Icc h)
-- We can uniformly bound the derivative of the Taylor polynomial
have h' : ∀ y ∈ Ico a x,
‖((n ! : ℝ)⁻¹ * (x - y) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) y‖ ≤
(n ! : ℝ)⁻¹ * |x - a| ^ n * C := by
rintro y ⟨hay, hyx⟩
rw [norm_smul, Real.norm_eq_abs]
gcongr
· rw [abs_mul, abs_pow, abs_inv, Nat.abs_cast]
gcongr
exact sub_nonneg.2 hyx.le
-- Estimate the iterated derivative by `C`
· exact hC y ⟨hay, hyx.le.trans hx.2⟩
-- Apply the mean value theorem for vector valued functions:
have A : ∀ t ∈ Icc a x, HasDerivWithinAt (fun y => taylorWithinEval f n (Icc a b) y x)
(((↑n !)⁻¹ * (x - t) ^ n) • iteratedDerivWithin (n + 1) f (Icc a b) t) (Icc a x) t := by
intro t ht
have I : Icc a x ⊆ Icc a b := Icc_subset_Icc_right hx.2
exact (hasDerivWithinAt_taylorWithinEval_at_Icc x h (I ht) hf.of_succ hf').mono I
have := norm_image_sub_le_of_norm_deriv_le_segment' A h' x (right_mem_Icc.2 hx.1)
simp only [taylorWithinEval_self] at this
refine this.trans_eq ?_
-- The rest is a trivial calculation
rw [abs_of_nonneg (sub_nonneg.mpr hx.1)]
ring
/-- **Taylor's theorem** with a polynomial bound on the remainder
We assume that `f` is `n+1`-times continuously differentiable on the closed set `Icc a b`.
There exists a constant `C` such that for all `x ∈ Icc a b` the difference of `f` and its `n`-th
Taylor polynomial can be estimated by `C * (x - a)^(n+1)`. -/
theorem exists_taylor_mean_remainder_bound {f : ℝ → E} {a b : ℝ} {n : ℕ} (hab : a ≤ b)
(hf : ContDiffOn ℝ (n + 1) f (Icc a b)) :
∃ C, ∀ x ∈ Icc a b, ‖f x - taylorWithinEval f n (Icc a b) a x‖ ≤ C * (x - a) ^ (n + 1) := by
rcases eq_or_lt_of_le hab with (rfl | h)
· refine ⟨0, fun x hx => ?_⟩
have : x = a := by simpa [← le_antisymm_iff] using hx
simp [← this]
-- We estimate by the supremum of the norm of the iterated derivative
let g : ℝ → ℝ := fun y => ‖iteratedDerivWithin (n + 1) f (Icc a b) y‖
use SupSet.sSup (g '' Icc a b) / (n !)
intro x hx
rw [div_mul_eq_mul_div₀]
refine taylor_mean_remainder_bound hab hf hx fun y => ?_
exact (hf.continuousOn_iteratedDerivWithin rfl.le <| uniqueDiffOn_Icc h).norm.le_sSup_image_Icc
|
gseries.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 bigop finset fingroup morphism.
From mathcomp Require Import automorphism quotient action commutator center.
(******************************************************************************)
(* H <|<| G <=> H is subnormal in G, i.e., H <| ... <| G. *)
(* invariant_factor A H G <=> A normalises both H and G, and H <| G. *)
(* A.-invariant <=> the (invariant_factor A) relation, in the context *)
(* of the g_rel.-series notation. *)
(* g_rel.-series H s <=> H :: s is a sequence of groups whose projection *)
(* to sets satisfies relation g_rel pairwise; for *)
(* example H <|<| G iff G = last H s for some s such *)
(* that normal.-series H s. *)
(* stable_factor A H G == H <| G and A centralises G / H. *)
(* A.-stable == the stable_factor relation, in the scope of the *)
(* r.-series notation. *)
(* G.-central == the central_factor relation, in the scope of the *)
(* r.-series notation. *)
(* maximal M G == M is a maximal proper subgroup of G. *)
(* maximal_eq M G == (M == G) or (maximal M G). *)
(* maxnormal M G N == M is a maximal subgroup of G normalized by N. *)
(* minnormal M N == M is a minimal nontrivial group normalized by N. *)
(* simple G == G is a (nontrivial) simple group. *)
(* := minnormal G G *)
(* G.-chief == the chief_factor relation, in the scope of the *)
(* r.-series notation. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope group_rel_scope.
Import GroupScope.
Section GroupDefs.
Variable gT : finGroupType.
Implicit Types A B U V : {set gT}.
Local Notation groupT := (group_of gT).
Definition subnormal A B :=
(A \subset B) && (iter #|B| (fun N => generated (class_support A N)) B == A).
Definition invariant_factor A B C :=
[&& A \subset 'N(B), A \subset 'N(C) & B <| C].
Definition group_rel_of (r : rel {set gT}) := [rel H G : groupT | r H G].
Definition stable_factor A V U :=
([~: U, A] \subset V) && (V <| U). (* this orders allows and3P to be used *)
Definition central_factor A V U :=
[&& [~: U, A] \subset V, V \subset U & U \subset A].
Definition maximal A B := [max A of G | G \proper B].
Definition maximal_eq A B := (A == B) || maximal A B.
Definition maxnormal A B U := [max A of G | G \proper B & U \subset 'N(G)].
Definition minnormal A B := [min A of G | G :!=: 1 & B \subset 'N(G)].
Definition simple A := minnormal A A.
Definition chief_factor A V U := maxnormal V U A && (U <| A).
End GroupDefs.
Arguments subnormal {gT} A%_g B%_g.
Arguments invariant_factor {gT} A%_g B%_g C%_g.
Arguments stable_factor {gT} A%_g V%_g U%_g.
Arguments central_factor {gT} A%_g V%_g U%_g.
Arguments maximal {gT} A%_g B%_g.
Arguments maximal_eq {gT} A%_g B%_g.
Arguments maxnormal {gT} A%_g B%_g U%_g.
Arguments minnormal {gT} A%_g B%_g.
Arguments simple {gT} A%_g.
Arguments chief_factor {gT} A%_g V%_g U%_g.
Notation "H <|<| G" := (subnormal H G)
(at level 70, no associativity) : group_scope.
Notation "A .-invariant" := (invariant_factor A)
(format "A .-invariant") : group_rel_scope.
Notation "A .-stable" := (stable_factor A)
(format "A .-stable") : group_rel_scope.
Notation "A .-central" := (central_factor A)
(format "A .-central") : group_rel_scope.
Notation "G .-chief" := (chief_factor G)
(format "G .-chief") : group_rel_scope.
Arguments group_rel_of {gT} r%_group_rel_scope _%_G _%_G : extra scopes.
Notation "r .-series" := (path (rel_of_simpl (group_rel_of r)))
(format "r .-series") : group_scope.
Section Subnormal.
Variable gT : finGroupType.
Implicit Types (A B C D : {set gT}) (G H K : {group gT}).
Let setIgr H G := (G :&: H)%G.
Let sub_setIgr G H : G \subset H -> G = setIgr H G.
Proof. by move/setIidPl/group_inj. Qed.
Let path_setIgr H G s :
normal.-series H s -> normal.-series (setIgr G H) (map (setIgr G) s).
Proof.
elim: s H => //= K s IHs H /andP[/andP[sHK nHK] Ksn].
by rewrite /normal setSI ?normsIG ?IHs.
Qed.
Lemma subnormalP H G :
reflect (exists2 s, normal.-series H s & last H s = G) (H <|<| G).
Proof.
apply: (iffP andP) => [[sHG snHG] | [s Hsn <-{G}]].
move: #|G| snHG => m; elim: m => [|m IHm] in G sHG *.
by exists [::]; last by apply/eqP; rewrite eq_sym.
rewrite iterSr => /IHm[|s Hsn defG].
by rewrite sub_gen // class_supportEr (bigD1 1) //= conjsg1 subsetUl.
exists (rcons s G); rewrite ?last_rcons // -cats1 cat_path Hsn defG /=.
rewrite /normal gen_subG class_support_subG //=.
by rewrite norms_gen ?class_support_norm.
set f := fun _ => <<_>>; have idf: iter _ f H == H.
by elim=> //= m IHm; rewrite (eqP IHm) /f class_support_id genGid.
have [m] := ubnP (size s); elim: m s Hsn => // m IHm /lastP[//|s G].
rewrite size_rcons last_rcons rcons_path /= ltnS.
set K := last H s => /andP[Hsn /andP[sKG nKG]] lt_s_m.
have /[1!subEproper]/predU1P[<-|prKG] := sKG; first exact: IHm.
pose L := [group of f G].
have sHK: H \subset K by case/IHm: Hsn.
have sLK: L \subset K by rewrite gen_subG class_support_sub_norm.
rewrite -(subnK (proper_card (sub_proper_trans sLK prKG))) iterD iterSr.
have defH: H = setIgr L H by rewrite -sub_setIgr ?sub_gen ?sub_class_support.
have: normal.-series H (map (setIgr L) s) by rewrite defH path_setIgr.
case/IHm=> [|_]; first by rewrite size_map.
rewrite [in last _]defH last_map (subset_trans sHK) //=.
by rewrite (setIidPr sLK) => /eqP->.
Qed.
Lemma subnormal_refl G : G <|<| G.
Proof. by apply/subnormalP; exists [::]. Qed.
Lemma subnormal_trans K H G : H <|<| K -> K <|<| G -> H <|<| G.
Proof.
case/subnormalP=> [s1 Hs1 <-] /subnormalP[s2 Hs12 <-].
by apply/subnormalP; exists (s1 ++ s2); rewrite ?last_cat // cat_path Hs1.
Qed.
Lemma normal_subnormal H G : H <| G -> H <|<| G.
Proof. by move=> nsHG; apply/subnormalP; exists [:: G]; rewrite //= nsHG. Qed.
Lemma setI_subnormal G H K : K \subset G -> H <|<| G -> H :&: K <|<| K.
Proof.
move=> sKG /subnormalP[s Hs defG]; apply/subnormalP.
exists (map (setIgr K) s); first exact: path_setIgr.
rewrite (last_map (setIgr K)) defG.
by apply: val_inj; rewrite /= (setIidPr sKG).
Qed.
Lemma subnormal_sub G H : H <|<| G -> H \subset G.
Proof. by case/andP. Qed.
Lemma invariant_subnormal A G H :
A \subset 'N(G) -> A \subset 'N(H) -> H <|<| G ->
exists2 s, (A.-invariant).-series H s & last H s = G.
Proof.
move=> nGA nHA /andP[]; move: #|G| => m.
elim: m => [|m IHm] in G nGA * => sHG.
by rewrite eq_sym; exists [::]; last apply/eqP.
rewrite iterSr; set K := <<_>>.
have nKA: A \subset 'N(K) by rewrite norms_gen ?norms_class_support.
have sHK: H \subset K by rewrite sub_gen ?sub_class_support.
case/IHm=> // s Hsn defK; exists (rcons s G); last by rewrite last_rcons.
rewrite rcons_path Hsn !andbA defK nGA nKA /= -/K.
by rewrite gen_subG class_support_subG ?norms_gen ?class_support_norm.
Qed.
Lemma subnormalEsupport G H :
H <|<| G -> H :=: G \/ <<class_support H G>> \proper G.
Proof.
case/andP=> sHG; set K := <<_>> => /eqP <-.
have: K \subset G by rewrite gen_subG class_support_subG.
rewrite subEproper; case/predU1P=> [defK|]; [left | by right].
by elim: #|G| => //= _ ->.
Qed.
Lemma subnormalEr G H : H <|<| G ->
H :=: G \/ (exists K : {group gT}, [/\ H <|<| K, K <| G & K \proper G]).
Proof.
case/subnormalP=> s Hs <-{G}.
elim/last_ind: s Hs => [|s G IHs]; first by left.
rewrite last_rcons -cats1 cat_path /= andbT; set K := last H s.
case/andP=> Hs nsKG; have /[1!subEproper] := normal_sub nsKG.
case/predU1P=> [<- | prKG]; [exact: IHs | right; exists K; split=> //].
by apply/subnormalP; exists s.
Qed.
Lemma subnormalEl G H : H <|<| G ->
H :=: G \/ (exists K : {group gT}, [/\ H <| K, K <|<| G & H \proper K]).
Proof.
case/subnormalP=> s Hs <-{G}; elim: s H Hs => /= [|K s IHs] H; first by left.
case/andP=> nsHK Ks; have /[1!subEproper] := normal_sub nsHK.
case/predU1P=> [-> | prHK]; [exact: IHs | right; exists K; split=> //].
by apply/subnormalP; exists s.
Qed.
End Subnormal.
Arguments subnormalP {gT H G}.
Section MorphSubNormal.
Variable gT : finGroupType.
Implicit Type G H K : {group gT}.
Lemma morphim_subnormal (rT : finGroupType) G (f : {morphism G >-> rT}) H K :
H <|<| K -> f @* H <|<| f @* K.
Proof.
case/subnormalP => s Hs <-{K}; apply/subnormalP.
elim: s H Hs => [|K s IHs] H /=; first by exists [::].
case/andP=> nsHK /IHs[fs Hfs <-].
by exists ([group of f @* K] :: fs); rewrite /= ?morphim_normal.
Qed.
Lemma quotient_subnormal H G K : G <|<| K -> G / H <|<| K / H.
Proof. exact: morphim_subnormal. Qed.
End MorphSubNormal.
Section MaxProps.
Variable gT : finGroupType.
Implicit Types G H M : {group gT}.
Lemma maximal_eqP M G :
reflect (M \subset G /\
forall H, M \subset H -> H \subset G -> H :=: M \/ H :=: G)
(maximal_eq M G).
Proof.
rewrite subEproper /maximal_eq; case: eqP => [->|_]; first left.
by split=> // H sGH sHG; right; apply/eqP; rewrite eqEsubset sHG.
apply: (iffP maxgroupP) => [] [sMG maxM]; split=> // H.
by move/maxM=> maxMH; rewrite subEproper; case/predU1P; auto.
by rewrite properEneq => /andP[/eqP neHG sHG] /maxM[].
Qed.
Lemma maximal_exists H G :
H \subset G ->
H :=: G \/ (exists2 M : {group gT}, maximal M G & H \subset M).
Proof.
rewrite subEproper; case/predU1P=> sHG; first by left.
suff [M *]: {M : {group gT} | maximal M G & H \subset M} by right; exists M.
exact: maxgroup_exists.
Qed.
Lemma mulg_normal_maximal G M H :
M <| G -> maximal M G -> H \subset G -> ~~ (H \subset M) -> (M * H = G)%g.
Proof.
case/andP=> sMG nMG /maxgroupP[_ maxM] sHG not_sHM.
apply/eqP; rewrite eqEproper mul_subG // -norm_joinEr ?(subset_trans sHG) //.
by apply: contra not_sHM => /maxM <-; rewrite ?joing_subl ?joing_subr.
Qed.
End MaxProps.
Section MinProps.
Variable gT : finGroupType.
Implicit Types G H M : {group gT}.
Lemma minnormal_exists G H : H :!=: 1 -> G \subset 'N(H) ->
{M : {group gT} | minnormal M G & M \subset H}.
Proof. by move=> ntH nHG; apply: mingroup_exists (H) _; rewrite ntH. Qed.
End MinProps.
Section MorphPreMax.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Variables (M G : {group rT}).
Hypotheses (dM : M \subset f @* D) (dG : G \subset f @* D).
Lemma morphpre_maximal : maximal (f @*^-1 M) (f @*^-1 G) = maximal M G.
Proof.
apply/maxgroupP/maxgroupP; rewrite morphpre_proper //= => [] [ltMG maxM].
split=> // H ltHG sMH; have dH := subset_trans (proper_sub ltHG) dG.
rewrite -(morphpreK dH) [f @*^-1 H]maxM ?morphpreK ?morphpreSK //.
by rewrite morphpre_proper.
split=> // H ltHG sMH.
have dH: H \subset D := subset_trans (proper_sub ltHG) (subsetIl D _).
have defH: f @*^-1 (f @* H) = H.
by apply: morphimGK dH; apply: subset_trans sMH; apply: ker_sub_pre.
rewrite -defH morphpre_proper ?morphimS // in ltHG.
by rewrite -defH [f @* H]maxM // -(morphpreK dM) morphimS.
Qed.
Lemma morphpre_maximal_eq : maximal_eq (f @*^-1 M) (f @*^-1 G) = maximal_eq M G.
Proof. by rewrite /maximal_eq morphpre_maximal !eqEsubset !morphpreSK. Qed.
End MorphPreMax.
Section InjmMax.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Variables M G L : {group gT}.
Hypothesis injf : 'injm f.
Hypotheses (dM : M \subset D) (dG : G \subset D) (dL : L \subset D).
Lemma injm_maximal : maximal (f @* M) (f @* G) = maximal M G.
Proof.
rewrite -(morphpre_invm injf) -(morphpre_invm injf G).
by rewrite morphpre_maximal ?morphim_invm.
Qed.
Lemma injm_maximal_eq : maximal_eq (f @* M) (f @* G) = maximal_eq M G.
Proof. by rewrite /maximal_eq injm_maximal // injm_eq. Qed.
Lemma injm_maxnormal : maxnormal (f @* M) (f @* G) (f @* L) = maxnormal M G L.
Proof.
pose injfm := (injm_proper injf, injm_norms, injmSK injf, subsetIl).
apply/maxgroupP/maxgroupP; rewrite !injfm // => [[nML maxM]].
split=> // H nHL sMH; have [/proper_sub sHG _] := andP nHL.
have dH := subset_trans sHG dG; apply: (injm_morphim_inj injf) => //.
by apply: maxM; rewrite !injfm.
split=> // fH nHL sMH; have [/proper_sub sfHG _] := andP nHL.
have{sfHG} dfH: fH \subset f @* D := subset_trans sfHG (morphim_sub f G).
by rewrite -(morphpreK dfH) !injfm // in nHL sMH *; rewrite (maxM _ nHL).
Qed.
Lemma injm_minnormal : minnormal (f @* M) (f @* G) = minnormal M G.
Proof.
pose injfm := (morphim_injm_eq1 injf, injm_norms, injmSK injf, subsetIl).
apply/mingroupP/mingroupP; rewrite !injfm // => [[nML minM]].
split=> // H nHG sHM; have dH := subset_trans sHM dM.
by apply: (injm_morphim_inj injf) => //; apply: minM; rewrite !injfm.
split=> // fH nHG sHM; have dfH := subset_trans sHM (morphim_sub f M).
by rewrite -(morphpreK dfH) !injfm // in nHG sHM *; rewrite (minM _ nHG).
Qed.
End InjmMax.
Section QuoMax.
Variables (gT : finGroupType) (K G H : {group gT}).
Lemma cosetpre_maximal (Q R : {group coset_of K}) :
maximal (coset K @*^-1 Q) (coset K @*^-1 R) = maximal Q R.
Proof. by rewrite morphpre_maximal ?sub_im_coset. Qed.
Lemma cosetpre_maximal_eq (Q R : {group coset_of K}) :
maximal_eq (coset K @*^-1 Q) (coset K @*^-1 R) = maximal_eq Q R.
Proof. by rewrite /maximal_eq !eqEsubset !cosetpreSK cosetpre_maximal. Qed.
Lemma quotient_maximal :
K <| G -> K <| H -> maximal (G / K) (H / K) = maximal G H.
Proof. by move=> nKG nKH; rewrite -cosetpre_maximal ?quotientGK. Qed.
Lemma quotient_maximal_eq :
K <| G -> K <| H -> maximal_eq (G / K) (H / K) = maximal_eq G H.
Proof. by move=> nKG nKH; rewrite -cosetpre_maximal_eq ?quotientGK. Qed.
Lemma maximalJ x : maximal (G :^ x) (H :^ x) = maximal G H.
Proof.
rewrite -{1}(setTI G) -{1}(setTI H) -!morphim_conj.
by rewrite injm_maximal ?subsetT ?injm_conj.
Qed.
Lemma maximal_eqJ x : maximal_eq (G :^ x) (H :^ x) = maximal_eq G H.
Proof. by rewrite /maximal_eq !eqEsubset !conjSg maximalJ. Qed.
End QuoMax.
Section MaxNormalProps.
Variables (gT : finGroupType).
Implicit Types (A B C : {set gT}) (G H K L M : {group gT}).
Lemma maxnormal_normal A B : maxnormal A B B -> A <| B.
Proof.
by case/maxsetP=> /and3P[/gen_set_id /= -> pAB nAB]; rewrite /normal proper_sub.
Qed.
Lemma maxnormal_proper A B C : maxnormal A B C -> A \proper B.
Proof.
by case/maxsetP=> /and3P[gA pAB _] _; apply: (sub_proper_trans (subset_gen A)).
Qed.
Lemma maxnormal_sub A B C : maxnormal A B C -> A \subset B.
Proof.
by move=> maxA; rewrite proper_sub //; apply: (maxnormal_proper maxA).
Qed.
Lemma ex_maxnormal_ntrivg G : G :!=: 1-> {N : {group gT} | maxnormal N G G}.
Proof.
move=> ntG; apply: ex_maxgroup; exists [1 gT]%G; rewrite norm1 proper1G.
by rewrite subsetT ntG.
Qed.
Lemma maxnormalM G H K :
maxnormal H G G -> maxnormal K G G -> H :<>: K -> H * K = G.
Proof.
move=> maxH maxK /eqP; apply: contraNeq => ltHK_G.
have [nsHG nsKG] := (maxnormal_normal maxH, maxnormal_normal maxK).
have cHK: commute H K.
exact: normC (subset_trans (normal_sub nsHG) (normal_norm nsKG)).
wlog suffices: H K {maxH} maxK nsHG nsKG cHK ltHK_G / H \subset K.
by move=> IH; rewrite eqEsubset !IH // -cHK.
have{maxK} /maxgroupP[_ maxK] := maxK.
apply/joing_idPr/maxK; rewrite ?joing_subr //= comm_joingE //.
by rewrite properEneq ltHK_G; apply: normalM.
Qed.
Lemma maxnormal_minnormal G L M :
G \subset 'N(M) -> L \subset 'N(G) -> maxnormal M G L ->
minnormal (G / M) (L / M).
Proof.
move=> nMG nGL /maxgroupP[/andP[/andP[sMG ltMG] nML] maxM]; apply/mingroupP.
rewrite -subG1 quotient_sub1 ?ltMG ?quotient_norms //.
split=> // Hb /andP[ntHb nHbL]; have nsMG: M <| G by apply/andP.
case/inv_quotientS=> // H defHb sMH sHG; rewrite defHb; congr (_ / M).
apply/eqP; rewrite eqEproper sHG /=; apply: contra ntHb => ltHG.
have nsMH: M <| H := normalS sMH sHG nsMG.
rewrite defHb quotientS1 // (maxM H) // ltHG /= -(quotientGK nsMH) -defHb.
exact: norm_quotient_pre.
Qed.
Lemma minnormal_maxnormal G L M :
M <| G -> L \subset 'N(M) -> minnormal (G / M) (L / M) -> maxnormal M G L.
Proof.
case/andP=> sMG nMG nML /mingroupP[/andP[/= ntGM _] minGM]; apply/maxgroupP.
split=> [|H /andP[/andP[sHG ltHG] nHL] sMH].
by rewrite /proper sMG nML andbT; apply: contra ntGM => /quotientS1 ->.
apply/eqP; rewrite eqEsubset sMH andbT -quotient_sub1 ?(subset_trans sHG) //.
rewrite subG1; apply: contraR ltHG => ntHM; rewrite -(quotientSGK nMG) //.
by rewrite (minGM (H / M)%G) ?quotientS // ntHM quotient_norms.
Qed.
End MaxNormalProps.
Section Simple.
Implicit Types gT rT : finGroupType.
Lemma simpleP gT (G : {group gT}) :
reflect (G :!=: 1 /\ forall H : {group gT}, H <| G -> H :=: 1 \/ H :=: G)
(simple G).
Proof.
apply: (iffP mingroupP); rewrite normG andbT => [[ntG simG]].
split=> // N /andP[sNG nNG].
by case: (eqsVneq N 1) => [|ntN]; [left | right; apply: simG; rewrite ?ntN].
split=> // N /andP[ntN nNG] sNG.
by case: (simG N) ntN => // [|->]; [apply/andP | case/eqP].
Qed.
Lemma quotient_simple gT (G H : {group gT}) :
H <| G -> simple (G / H) = maxnormal H G G.
Proof.
move=> nsHG; have nGH := normal_norm nsHG.
by apply/idP/idP; [apply: minnormal_maxnormal | apply: maxnormal_minnormal].
Qed.
Lemma isog_simple gT rT (G : {group gT}) (M : {group rT}) :
G \isog M -> simple G = simple M.
Proof.
move=> eqGM; wlog suffices: gT rT G M eqGM / simple M -> simple G.
by move=> IH; apply/idP/idP; apply: IH; rewrite // isog_sym.
case/isogP: eqGM => f injf <- /simpleP[ntGf simGf].
apply/simpleP; split=> [|N nsNG]; first by rewrite -(morphim_injm_eq1 injf).
rewrite -(morphim_invm injf (normal_sub nsNG)).
have: f @* N <| f @* G by rewrite morphim_normal.
by case/simGf=> /= ->; [left | right]; rewrite (morphim1, morphim_invm).
Qed.
Lemma simple_maxnormal gT (G : {group gT}) : simple G = maxnormal 1 G G.
Proof.
by rewrite -quotient_simple ?normal1 // -(isog_simple (quotient1_isog G)).
Qed.
End Simple.
Section Chiefs.
Variable gT : finGroupType.
Implicit Types G H U V : {group gT}.
Lemma chief_factor_minnormal G V U :
chief_factor G V U -> minnormal (U / V) (G / V).
Proof.
case/andP=> maxV /andP[sUG nUG]; apply: maxnormal_minnormal => //.
by have /andP[_ nVG] := maxgroupp maxV; apply: subset_trans sUG nVG.
Qed.
Lemma acts_irrQ G U V :
G \subset 'N(V) -> V <| U ->
acts_irreducibly G (U / V) 'Q = minnormal (U / V) (G / V).
Proof.
move=> nVG nsVU; apply/mingroupP/mingroupP; case=> /andP[->] /=.
rewrite astabsQ // subsetI nVG /= => nUG minUV.
rewrite quotient_norms //; split=> // H /andP[ntH nHG] sHU.
by apply: minUV (sHU); rewrite ntH -(cosetpreK H) actsQ // norm_quotient_pre.
rewrite sub_quotient_pre // => nUG minU; rewrite astabsQ //.
rewrite (subset_trans nUG); last first.
by rewrite subsetI subsetIl /= -{2}(quotientGK nsVU) morphpre_norm.
split=> // H /andP[ntH nHG] sHU.
rewrite -{1}(cosetpreK H) astabsQ ?normal_cosetpre ?subsetI ?nVG //= in nHG.
apply: minU sHU; rewrite ntH; apply: subset_trans (quotientS _ nHG) _.
by rewrite -{2}(cosetpreK H) quotient_norm.
Qed.
Lemma chief_series_exists H G :
H <| G -> {s | (G.-chief).-series 1%G s & last 1%G s = H}.
Proof.
have [m] := ubnP #|H|; elim: m H => // m IHm U leUm nsUG.
have [-> | ntU] := eqVneq U 1%G; first by exists [::].
have [V maxV]: {V : {group gT} | maxnormal V U G}.
by apply: ex_maxgroup; exists 1%G; rewrite proper1G ntU norms1.
have /andP[ltVU nVG] := maxgroupp maxV.
have [||s ch_s defV] := IHm V; first exact: leq_trans (proper_card ltVU) _.
by rewrite /normal (subset_trans (proper_sub ltVU) (normal_sub nsUG)).
exists (rcons s U); last by rewrite last_rcons.
by rewrite rcons_path defV /= ch_s /chief_factor; apply/and3P.
Qed.
End Chiefs.
Section Central.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types H K : {group gT}.
Lemma central_factor_central H K :
central_factor G H K -> (K / H) \subset 'Z(G / H).
Proof. by case/and3P=> /quotient_cents2r *; rewrite subsetI quotientS. Qed.
Lemma central_central_factor H K :
(K / H) \subset 'Z(G / H) -> H <| K -> H <| G -> central_factor G H K.
Proof.
case/subsetIP=> sKGb cGKb /andP[sHK nHK] /andP[sHG nHG].
by rewrite /central_factor -quotient_cents2 // cGKb sHK -(quotientSGK nHK).
Qed.
End Central.
|
Normalizer.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.Algebra.Lie.Abelian
import Mathlib.Algebra.Lie.IdealOperations
import Mathlib.Algebra.Lie.Quotient
/-!
# The normalizer of Lie submodules and subalgebras.
Given a Lie module `M` over a Lie subalgebra `L`, the normalizer of a Lie submodule `N ⊆ M` is
the Lie submodule with underlying set `{ m | ∀ (x : L), ⁅x, m⁆ ∈ N }`.
The lattice of Lie submodules thus has two natural operations, the normalizer: `N ↦ N.normalizer`
and the ideal operation: `N ↦ ⁅⊤, N⁆`; these are adjoint, i.e., they form a Galois connection. This
adjointness is the reason that we may define nilpotency in terms of either the upper or lower
central series.
Given a Lie subalgebra `H ⊆ L`, we may regard `H` as a Lie submodule of `L` over `H`, and thus
consider the normalizer. This turns out to be a Lie subalgebra.
## Main definitions
* `LieSubmodule.normalizer`
* `LieSubalgebra.normalizer`
* `LieSubmodule.gc_top_lie_normalizer`
## Tags
lie algebra, normalizer
-/
variable {R L M M' : Type*}
variable [CommRing R] [LieRing L] [LieAlgebra R L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M]
variable [AddCommGroup M'] [Module R M'] [LieRingModule L M'] [LieModule R L M']
namespace LieSubmodule
variable (N : LieSubmodule R L M) {N₁ N₂ : LieSubmodule R L M}
/-- The normalizer of a Lie submodule.
See also `LieSubmodule.idealizer`. -/
def normalizer : LieSubmodule R L M where
carrier := {m | ∀ x : L, ⁅x, m⁆ ∈ N}
add_mem' hm₁ hm₂ x := by rw [lie_add]; exact N.add_mem' (hm₁ x) (hm₂ x)
zero_mem' x := by simp
smul_mem' t m hm x := by rw [lie_smul]; exact N.smul_mem' t (hm x)
lie_mem {x m} hm y := by rw [leibniz_lie]; exact N.add_mem' (hm ⁅y, x⁆) (N.lie_mem (hm y))
@[simp]
theorem mem_normalizer (m : M) : m ∈ N.normalizer ↔ ∀ x : L, ⁅x, m⁆ ∈ N :=
Iff.rfl
@[simp]
theorem le_normalizer : N ≤ N.normalizer := by
intro m hm
rw [mem_normalizer]
exact fun x => N.lie_mem hm
theorem normalizer_inf : (N₁ ⊓ N₂).normalizer = N₁.normalizer ⊓ N₂.normalizer := by
ext; simp [← forall_and]
@[gcongr, mono]
theorem normalizer_mono (h : N₁ ≤ N₂) : normalizer N₁ ≤ normalizer N₂ := by
intro m hm
rw [mem_normalizer] at hm ⊢
exact fun x ↦ h (hm x)
theorem monotone_normalizer : Monotone (normalizer : LieSubmodule R L M → LieSubmodule R L M) :=
fun _ _ ↦ normalizer_mono
@[simp]
theorem comap_normalizer (f : M' →ₗ⁅R,L⁆ M) : N.normalizer.comap f = (N.comap f).normalizer := by
ext; simp
theorem top_lie_le_iff_le_normalizer (N' : LieSubmodule R L M) :
⁅(⊤ : LieIdeal R L), N⁆ ≤ N' ↔ N ≤ N'.normalizer := by rw [lie_le_iff]; tauto
theorem gc_top_lie_normalizer :
GaloisConnection (fun N : LieSubmodule R L M => ⁅(⊤ : LieIdeal R L), N⁆) normalizer :=
top_lie_le_iff_le_normalizer
variable (R L M) in
theorem normalizer_bot_eq_maxTrivSubmodule :
(⊥ : LieSubmodule R L M).normalizer = LieModule.maxTrivSubmodule R L M :=
rfl
/-- The idealizer of a Lie submodule.
See also `LieSubmodule.normalizer`. -/
def idealizer : LieIdeal R L where
carrier := {x : L | ∀ m : M, ⁅x, m⁆ ∈ N}
add_mem' := fun {x} {y} hx hy m ↦ by rw [add_lie]; exact N.add_mem (hx m) (hy m)
zero_mem' := by simp
smul_mem' := fun t {x} hx m ↦ by rw [smul_lie]; exact N.smul_mem t (hx m)
lie_mem := fun {x} {y} hy m ↦ by rw [lie_lie]; exact sub_mem (N.lie_mem (hy m)) (hy ⁅x, m⁆)
@[simp]
lemma mem_idealizer {x : L} : x ∈ N.idealizer ↔ ∀ m : M, ⁅x, m⁆ ∈ N := Iff.rfl
@[simp]
lemma _root_.LieIdeal.idealizer_eq_normalizer (I : LieIdeal R L) :
I.idealizer = I.normalizer := by
ext x; exact forall_congr' fun y ↦ by simp only [← lie_skew x y, neg_mem_iff]
end LieSubmodule
namespace LieSubalgebra
variable (H : LieSubalgebra R L)
/-- Regarding a Lie subalgebra `H ⊆ L` as a module over itself, its normalizer is in fact a Lie
subalgebra. -/
def normalizer : LieSubalgebra R L :=
{ H.toLieSubmodule.normalizer with
lie_mem' := fun {y z} hy hz x => by
rw [coe_bracket_of_module, mem_toLieSubmodule, leibniz_lie, ← lie_skew y, ← sub_eq_add_neg]
exact H.sub_mem (hz ⟨_, hy x⟩) (hy ⟨_, hz x⟩) }
theorem mem_normalizer_iff' (x : L) : x ∈ H.normalizer ↔ ∀ y : L, y ∈ H → ⁅y, x⁆ ∈ H := by
rw [Subtype.forall']; rfl
theorem mem_normalizer_iff (x : L) : x ∈ H.normalizer ↔ ∀ y : L, y ∈ H → ⁅x, y⁆ ∈ H := by
rw [mem_normalizer_iff']
refine forall₂_congr fun y hy => ?_
rw [← lie_skew, neg_mem_iff (G := L)]
theorem le_normalizer : H ≤ H.normalizer :=
H.toLieSubmodule.le_normalizer
theorem coe_normalizer_eq_normalizer :
(H.toLieSubmodule.normalizer : Submodule R L) = H.normalizer :=
rfl
variable {H}
theorem lie_mem_sup_of_mem_normalizer {x y z : L} (hx : x ∈ H.normalizer) (hy : y ∈ (R ∙ x) ⊔ ↑H)
(hz : z ∈ (R ∙ x) ⊔ ↑H) : ⁅y, z⁆ ∈ (R ∙ x) ⊔ ↑H := by
rw [Submodule.mem_sup] at hy hz
obtain ⟨u₁, hu₁, v, hv : v ∈ H, rfl⟩ := hy
obtain ⟨u₂, hu₂, w, hw : w ∈ H, rfl⟩ := hz
obtain ⟨t, rfl⟩ := Submodule.mem_span_singleton.mp hu₁
obtain ⟨s, rfl⟩ := Submodule.mem_span_singleton.mp hu₂
apply Submodule.mem_sup_right
simp only [LieSubalgebra.mem_toSubmodule, smul_lie, add_lie, zero_add, lie_add, smul_zero,
lie_smul, lie_self]
refine H.add_mem (H.smul_mem s ?_) (H.add_mem (H.smul_mem t ?_) (H.lie_mem hv hw))
exacts [(H.mem_normalizer_iff' x).mp hx v hv, (H.mem_normalizer_iff x).mp hx w hw]
/-- A Lie subalgebra is an ideal of its normalizer. -/
theorem ideal_in_normalizer {x y : L} (hx : x ∈ H.normalizer) (hy : y ∈ H) : ⁅x, y⁆ ∈ H := by
rw [← lie_skew, neg_mem_iff (G := L)]
exact hx ⟨y, hy⟩
/-- A Lie subalgebra `H` is an ideal of any Lie subalgebra `K` containing `H` and contained in the
normalizer of `H`. -/
theorem exists_nested_lieIdeal_ofLe_normalizer {K : LieSubalgebra R L} (h₁ : H ≤ K)
(h₂ : K ≤ H.normalizer) : ∃ I : LieIdeal R K, (I : LieSubalgebra R K) = ofLe h₁ := by
rw [exists_nested_lieIdeal_coe_eq_iff]
exact fun x y hx hy => ideal_in_normalizer (h₂ hx) hy
variable (H)
theorem normalizer_eq_self_iff :
H.normalizer = H ↔ (LieModule.maxTrivSubmodule R H <| L ⧸ H.toLieSubmodule) = ⊥ := by
rw [LieSubmodule.eq_bot_iff]
refine ⟨fun h => ?_, fun h => le_antisymm ?_ H.le_normalizer⟩
· rintro ⟨x⟩ hx
suffices x ∈ H by rwa [Submodule.Quotient.quot_mk_eq_mk, Submodule.Quotient.mk_eq_zero,
coe_toLieSubmodule, mem_toSubmodule]
rw [← h, H.mem_normalizer_iff']
intro y hy
replace hx : ⁅_, LieSubmodule.Quotient.mk' _ x⁆ = 0 := hx ⟨y, hy⟩
rwa [← LieModuleHom.map_lie, LieSubmodule.Quotient.mk_eq_zero] at hx
· intro x hx
let y := LieSubmodule.Quotient.mk' H.toLieSubmodule x
have hy : y ∈ LieModule.maxTrivSubmodule R H (L ⧸ H.toLieSubmodule) := by
rintro ⟨z, hz⟩
rw [← LieModuleHom.map_lie, LieSubmodule.Quotient.mk_eq_zero, coe_bracket_of_module,
Submodule.coe_mk, mem_toLieSubmodule]
exact (H.mem_normalizer_iff' x).mp hx z hz
simpa [y] using h y hy
end LieSubalgebra
|
GammaDeriv.lean
|
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.Convex.Deriv
import Mathlib.Analysis.SpecialFunctions.Gamma.Deligne
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.NumberTheory.Harmonic.EulerMascheroni
/-!
# Derivative of Γ at positive integers
We prove the formula for the derivative of `Real.Gamma` at a positive integer:
`deriv Real.Gamma (n + 1) = Nat.factorial n * (-Real.eulerMascheroniConstant + harmonic n)`
-/
open Nat Set Filter Topology
local notation "γ" => Real.eulerMascheroniConstant
namespace Real
/-- Explicit formula for the derivative of the Gamma function at positive integers, in terms of
harmonic numbers and the Euler-Mascheroni constant `γ`. -/
lemma deriv_Gamma_nat (n : ℕ) :
deriv Gamma (n + 1) = n ! * (-γ + harmonic n) := by
/- This follows from two properties of the function `f n = log (Gamma n)`:
firstly, the elementary computation that `deriv f (n + 1) = deriv f n + 1 / n`, so that
`deriv f n = deriv f 1 + harmonic n`; secondly, the convexity of `f` (the Bohr-Mollerup theorem),
which shows that `deriv f n` is `log n + o(1)` as `n → ∞`. -/
let f := log ∘ Gamma
-- First reduce to computing derivative of `log ∘ Gamma`.
suffices deriv (log ∘ Gamma) (n + 1) = -γ + harmonic n by
rwa [Function.comp_def, deriv.log (differentiableAt_Gamma (fun m ↦ by linarith))
(by positivity), Gamma_nat_eq_factorial, div_eq_iff_mul_eq (by positivity),
mul_comm, Eq.comm] at this
have hc : ConvexOn ℝ (Ioi 0) f := convexOn_log_Gamma
have h_rec (x : ℝ) (hx : 0 < x) : f (x + 1) = f x + log x := by simp only [f, Function.comp_apply,
Gamma_add_one hx.ne', log_mul hx.ne' (Gamma_pos_of_pos hx).ne', add_comm]
have hder {x : ℝ} (hx : 0 < x) : DifferentiableAt ℝ f x := by
refine ((differentiableAt_Gamma ?_).log (Gamma_ne_zero ?_)) <;>
exact fun m ↦ ne_of_gt (by linarith)
-- Express derivative at general `n` in terms of value at `1` using recurrence relation
have hder_rec (x : ℝ) (hx : 0 < x) : deriv f (x + 1) = deriv f x + 1 / x := by
rw [← deriv_comp_add_const, one_div, ← deriv_log,
← deriv_add (hder <| by positivity) (differentiableAt_log hx.ne')]
apply EventuallyEq.deriv_eq
filter_upwards [eventually_gt_nhds hx] using h_rec
have hder_nat (n : ℕ) : deriv f (n + 1) = deriv f 1 + harmonic n := by
induction n with
| zero => simp
| succ n hn =>
rw [cast_succ, hder_rec (n + 1) (by positivity), hn, harmonic_succ]
push_cast
ring
suffices -deriv f 1 = γ by rw [hder_nat n, ← this, neg_neg]
-- Use convexity to show derivative of `f` at `n + 1` is between `log n` and `log (n + 1)`
have derivLB (n : ℕ) (hn : 0 < n) : log n ≤ deriv f (n + 1) := by
refine (le_of_eq ?_).trans <| hc.slope_le_deriv (mem_Ioi.mpr <| Nat.cast_pos.mpr hn)
(by positivity : _ < (_ : ℝ)) (by linarith) (hder <| by positivity)
rw [slope_def_field, show n + 1 - n = (1 : ℝ) by ring, div_one, h_rec n (by positivity),
add_sub_cancel_left]
have derivUB (n : ℕ) : deriv f (n + 1) ≤ log (n + 1) := by
refine (hc.deriv_le_slope (by positivity : (0 : ℝ) < n + 1) (by positivity : (0 : ℝ) < n + 2)
(by linarith) (hder <| by positivity)).trans (le_of_eq ?_)
rw [slope_def_field, show n + 2 - (n + 1) = (1 : ℝ) by ring, div_one,
show n + 2 = (n + 1) + (1 : ℝ) by ring, h_rec (n + 1) (by positivity), add_sub_cancel_left]
-- deduce `-deriv f 1` is bounded above + below by sequences which both tend to `γ`
apply le_antisymm
· apply ge_of_tendsto tendsto_harmonic_sub_log
filter_upwards [eventually_gt_atTop 0] with n hn
rw [le_sub_iff_add_le', ← sub_eq_add_neg, sub_le_iff_le_add', ← hder_nat]
exact derivLB n hn
· apply le_of_tendsto tendsto_harmonic_sub_log_add_one
filter_upwards with n
rw [sub_le_iff_le_add', ← sub_eq_add_neg, le_sub_iff_add_le', ← hder_nat]
exact derivUB n
lemma hasDerivAt_Gamma_nat (n : ℕ) :
HasDerivAt Gamma (n ! * (-γ + harmonic n)) (n + 1) :=
(deriv_Gamma_nat n).symm ▸
(differentiableAt_Gamma fun m ↦ (by linarith : (n : ℝ) + 1 ≠ -m)).hasDerivAt
lemma eulerMascheroniConstant_eq_neg_deriv : γ = -deriv Gamma 1 := by
rw [show (1 : ℝ) = ↑(0 : ℕ) + 1 by simp, deriv_Gamma_nat 0]
simp
lemma hasDerivAt_Gamma_one : HasDerivAt Gamma (-γ) 1 := by
simpa only [factorial_zero, cast_one, harmonic_zero, Rat.cast_zero, add_zero, mul_neg, one_mul,
cast_zero, zero_add] using hasDerivAt_Gamma_nat 0
lemma hasDerivAt_Gamma_one_half : HasDerivAt Gamma (-√π * (γ + 2 * log 2)) (1 / 2) := by
have h_diff {s : ℝ} (hs : 0 < s) : DifferentiableAt ℝ Gamma s :=
differentiableAt_Gamma fun m ↦ ((neg_nonpos.mpr m.cast_nonneg).trans_lt hs).ne'
have h_diff' {s : ℝ} (hs : 0 < s) : DifferentiableAt ℝ (fun s ↦ Gamma (2 * s)) s :=
.comp (g := Gamma) _ (h_diff <| mul_pos two_pos hs) (differentiableAt_id.const_mul _)
refine (h_diff one_half_pos).hasDerivAt.congr_deriv ?_
-- We calculate the deriv of Gamma at 1/2 using the doubling formula, since we already know
-- the derivative of Gamma at 1.
calc deriv Gamma (1 / 2)
_ = (deriv (fun s ↦ Gamma s * Gamma (s + 1 / 2)) (1 / 2)) + √π * γ := by
rw [deriv_fun_mul, Gamma_one_half_eq,
add_assoc, ← mul_add, deriv_comp_add_const,
(by norm_num : 1 / 2 + 1 / 2 = (1 : ℝ)), Gamma_one, mul_one,
eulerMascheroniConstant_eq_neg_deriv, add_neg_cancel, mul_zero, add_zero]
· apply h_diff; norm_num -- s = 1
· exact ((h_diff (by simp)).hasDerivAt.comp_add_const).differentiableAt -- s = 1
_ = (deriv (fun s ↦ Gamma (2 * s) * 2 ^ (1 - 2 * s) * √π) (1 / 2)) + √π * γ := by
rw [funext Gamma_mul_Gamma_add_half]
_ = √π * (deriv (fun s ↦ Gamma (2 * s) * 2 ^ (1 - 2 * s)) (1 / 2) + γ) := by
rw [mul_comm √π, mul_comm √π, deriv_mul_const, add_mul]
apply DifferentiableAt.mul
· exact .comp (g := Gamma) _ (by apply h_diff; norm_num) -- s = 1
(differentiableAt_id.const_mul _)
· exact (differentiableAt_const _).rpow (by fun_prop) two_ne_zero
_ = √π * (deriv (fun s ↦ Gamma (2 * s)) (1 / 2) +
deriv (fun s : ℝ ↦ 2 ^ (1 - 2 * s)) (1 / 2) + γ) := by
congr 2
rw [deriv_fun_mul]
· congr 1 <;> norm_num
· exact h_diff' one_half_pos
· exact DifferentiableAt.rpow (by fun_prop) (by fun_prop) two_ne_zero
_ = √π * (-2 * γ + deriv (fun s : ℝ ↦ 2 ^ (1 - 2 * s)) (1 / 2) + γ) := by
congr 3
change deriv (Gamma ∘ fun s ↦ 2 * s) _ = _
rw [deriv_comp, deriv_const_mul, mul_one_div, div_self two_ne_zero, deriv_id''] <;>
dsimp only
· rw [mul_one, mul_comm, hasDerivAt_Gamma_one.deriv, mul_neg, neg_mul]
· fun_prop
· apply h_diff; norm_num -- s = 1
· fun_prop
_ = √π * (-2 * γ + -(2 * log 2) + γ) := by
congr 3
apply HasDerivAt.deriv
have := HasDerivAt.rpow (hasDerivAt_const (1 / 2 : ℝ) (2 : ℝ))
(?_ : HasDerivAt (fun s : ℝ ↦ 1 - 2 * s) (-2) (1 / 2)) two_pos
· norm_num at this; exact this
simp_rw [mul_comm (2 : ℝ) _]
apply HasDerivAt.const_sub
exact hasDerivAt_mul_const (2 : ℝ)
_ = -√π * (γ + 2 * log 2) := by ring
end Real
namespace Complex
open scoped Real
private lemma HasDerivAt.complex_of_real {f : ℂ → ℂ} {g : ℝ → ℝ} {g' s : ℝ}
(hf : DifferentiableAt ℂ f s) (hg : HasDerivAt g g' s) (hfg : ∀ s : ℝ, f ↑s = ↑(g s)) :
HasDerivAt f ↑g' s := by
refine HasDerivAt.congr_deriv hf.hasDerivAt ?_
rw [← (funext hfg ▸ hf.hasDerivAt.comp_ofReal.deriv :)]
exact hg.ofReal_comp.deriv
lemma differentiableAt_Gamma_nat_add_one (n : ℕ) :
DifferentiableAt ℂ Gamma (n + 1) := by
refine differentiableAt_Gamma _ (fun m ↦ ?_)
simp only [Ne, ← ofReal_natCast, ← ofReal_one, ← ofReal_add, ← ofReal_neg, ofReal_inj,
eq_neg_iff_add_eq_zero]
positivity
@[deprecated (since := "2025-06-06")] alias differentiable_at_Gamma_nat_add_one :=
differentiableAt_Gamma_nat_add_one
lemma hasDerivAt_Gamma_nat (n : ℕ) :
HasDerivAt Gamma (n ! * (-γ + harmonic n)) (n + 1) := by
exact_mod_cast HasDerivAt.complex_of_real
(by exact_mod_cast differentiableAt_Gamma_nat_add_one n)
(Real.hasDerivAt_Gamma_nat n) Gamma_ofReal
/-- Explicit formula for the derivative of the complex Gamma function at positive integers, in
terms of harmonic numbers and the Euler-Mascheroni constant `γ`. -/
lemma deriv_Gamma_nat (n : ℕ) :
deriv Gamma (n + 1) = n ! * (-γ + harmonic n) :=
(hasDerivAt_Gamma_nat n).deriv
lemma hasDerivAt_Gamma_one : HasDerivAt Gamma (-γ) 1 := by
simpa only [factorial_zero, cast_one, harmonic_zero, Rat.cast_zero, add_zero, mul_neg, one_mul,
cast_zero, zero_add] using hasDerivAt_Gamma_nat 0
lemma hasDerivAt_Gamma_one_half : HasDerivAt Gamma (-√π * (γ + 2 * log 2)) (1 / 2) := by
have := HasDerivAt.complex_of_real
(differentiableAt_Gamma _ ?_) Real.hasDerivAt_Gamma_one_half Gamma_ofReal
· simpa only [neg_mul, one_div, ofReal_neg, ofReal_mul, ofReal_add, ofReal_ofNat, ofNat_log,
ofReal_inv] using this
· intro m
rw [← ofReal_natCast, ← ofReal_neg, ne_eq, ofReal_inj]
exact ((neg_nonpos.mpr m.cast_nonneg).trans_lt one_half_pos).ne'
lemma hasDerivAt_Gammaℂ_one : HasDerivAt Gammaℂ (-(γ + log (2 * π)) / π) 1 := by
let f (s : ℂ) : ℂ := 2 * (2 * π) ^ (-s)
have : HasDerivAt (fun s : ℂ ↦ 2 * (2 * π : ℂ) ^ (-s)) (-log (2 * π) / π) 1 := by
have := (hasDerivAt_neg' (1 : ℂ)).const_cpow (c := 2 * π)
(Or.inl (by exact_mod_cast Real.two_pi_pos.ne'))
refine (this.const_mul 2).congr_deriv ?_
rw [mul_neg_one, mul_neg, cpow_neg_one, ← div_eq_inv_mul, ← mul_div_assoc,
mul_div_mul_left _ _ two_ne_zero, neg_div]
have := this.mul hasDerivAt_Gamma_one
simp only at this
rwa [Gamma_one, mul_one, cpow_neg_one, ← div_eq_mul_inv, ← div_div, div_self two_ne_zero,
mul_comm (1 / _), mul_one_div, ← _root_.add_div, ← neg_add, add_comm] at this
lemma hasDerivAt_Gammaℝ_one : HasDerivAt Gammaℝ (-(γ + log (4 * π)) / 2) 1 := by
let f (s : ℂ) : ℂ := π ^ (-s / 2)
let g (s : ℂ) : ℂ := Gamma (s / 2)
have aux : (π : ℂ) ^ (1 / 2 : ℂ) = ↑√π := by
rw [Real.sqrt_eq_rpow, ofReal_cpow Real.pi_pos.le, ofReal_div, ofReal_one, ofReal_ofNat]
have aux2 : (√π : ℂ) ≠ 0 := by rw [ofReal_ne_zero]; positivity
have hf : HasDerivAt f (-log π / 2 / √π) 1 := by
have := ((hasDerivAt_neg (1 : ℂ)).div_const 2).const_cpow (c := π) (Or.inr (by norm_num))
refine this.congr_deriv ?_
rw [mul_assoc, ← mul_div_assoc, mul_neg_one, neg_div, cpow_neg, ← div_eq_inv_mul, aux]
have hg : HasDerivAt g (-√π * (γ + 2 * log 2) / 2) 1 := by
have := hasDerivAt_Gamma_one_half.comp 1 (?_ : HasDerivAt (fun s : ℂ ↦ s / 2) (1 / 2) 1)
· rwa [mul_one_div] at this
· exact (hasDerivAt_id _).div_const _
refine HasDerivAt.congr_deriv (hf.mul hg) ?_
simp only [f]
rw [Gamma_one_half_eq, aux, div_mul_cancel₀ _ aux2, neg_div _ (1 : ℂ), cpow_neg, aux,
mul_div_assoc, ← mul_assoc, mul_neg, inv_mul_cancel₀ aux2, neg_one_mul, ← neg_div,
← _root_.add_div, ← neg_add, add_comm, add_assoc, ← ofReal_log Real.pi_pos.le, ← ofReal_ofNat,
← ofReal_log zero_le_two,
← ofReal_mul, ← Nat.cast_ofNat (R := ℝ), ← Real.log_pow, ← ofReal_add,
← Real.log_mul (by positivity) (by positivity),
Nat.cast_ofNat, ofReal_ofNat, ofReal_log (by positivity)]
norm_num
end Complex
|
Periodic.lean
|
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Nicolò Cavalleri
-/
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Topology.ContinuousMap.Algebra
/-!
# Sums of translates of a continuous function is a period continuous function.
-/
assert_not_exists StoneCech StarModule
namespace ContinuousMap
section Periodicity
variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y]
/-! ### Summing translates of a function -/
/-- Summing the translates of `f` by `ℤ • p` gives a map which is periodic with period `p`.
(This is true without any convergence conditions, since if the sum doesn't converge it is taken to
be the zero map, which is periodic.) -/
theorem periodic_tsum_comp_add_zsmul [AddCommGroup X] [ContinuousAdd X] [AddCommMonoid Y]
[ContinuousAdd Y] [T2Space Y] (f : C(X, Y)) (p : X) :
Function.Periodic (⇑(∑' n : ℤ, f.comp (ContinuousMap.addRight (n • p)))) p := by
intro x
by_cases h : Summable fun n : ℤ => f.comp (ContinuousMap.addRight (n • p))
· convert congr_arg (fun f : C(X, Y) => f x) ((Equiv.addRight (1 : ℤ)).tsum_eq _) using 1
-- Porting note: in mathlib3 the proof from here was:
-- simp_rw [← tsum_apply h, ← tsum_apply ((equiv.add_right (1 : ℤ)).summable_iff.mpr h),
-- equiv.coe_add_right, comp_apply, coe_add_right, add_one_zsmul, add_comm (_ • p) p,
-- ← add_assoc]
-- However now the second `← tsum_apply` doesn't fire unless we use `erw`.
simp_rw [← tsum_apply h]
erw [← tsum_apply ((Equiv.addRight (1 : ℤ)).summable_iff.mpr h)]
simp [coe_addRight, add_one_zsmul, add_comm (_ • p) p, ← add_assoc]
· rw [tsum_eq_zero_of_not_summable h]
simp only [coe_zero, Pi.zero_apply]
end Periodicity
end ContinuousMap
|
Finite.lean
|
/-
Copyright (c) 2025 Yaël Dillies, Patrick Luo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Patrick Luo
-/
import Mathlib.GroupTheory.Finiteness
import Mathlib.GroupTheory.MonoidLocalization.GrothendieckGroup
/-!
# Localization of a finitely generated submonoid
## TODO
If `Mathlib/GroupTheory/Finiteness.lean` wasn't so heavy, this could move earlier.
-/
open Localization
variable {M : Type*} [CommMonoid M] {S : Submonoid M}
namespace Localization
/-- The localization of a finitely generated monoid at a finitely generated submonoid is
finitely generated. -/
@[to_additive /-- The localization of a finitely generated monoid at a finitely generated submonoid
is finitely generated. -/]
lemma fg [Monoid.FG M] (hS : S.FG) : Monoid.FG <| Localization S := by
rw [← Monoid.fg_iff_submonoid_fg] at hS; exact Monoid.fg_of_surjective mkHom mkHom_surjective
end Localization
namespace Algebra.GrothendieckGroup
/-- The Grothendieck group of a finitely generated monoid is finitely generated. -/
@[to_additive /-- The Grothendieck group of a finitely generated monoid is finitely generated. -/]
instance instFG [Monoid.FG M] : Monoid.FG <| GrothendieckGroup M := fg Monoid.FG.fg_top
end Algebra.GrothendieckGroup
|
separable.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq div.
From mathcomp Require Import choice fintype tuple finfun bigop finset prime.
From mathcomp Require Import binomial ssralg poly polydiv fingroup perm.
From mathcomp Require Import morphism quotient gproduct finalg zmodp cyclic.
From mathcomp Require Import matrix mxalgebra mxpoly polyXY vector falgebra.
From mathcomp Require Import fieldext.
(******************************************************************************)
(* This file provides a theory of separable and inseparable field extensions. *)
(* *)
(* separable_poly p <=> p has no multiple roots in any field extension. *)
(* separable_element K x <=> the minimal polynomial of x over K is separable. *)
(* separable K E <=> every member of E is separable over K. *)
(* separable_generator K E == some x \in E that generates the largest *)
(* subfield K[x] that is separable over K. *)
(* purely_inseparable_element K x <=> there is a [pchar L].-nat n such that *)
(* x ^+ n \in K. *)
(* purely_inseparable K E <=> every member of E is purely inseparable over K. *)
(* *)
(* Derivations are introduced to prove the adjoin_separableP Lemma: *)
(* Derivation K D <=> the linear operator D satisfies the Leibniz *)
(* product rule inside K. *)
(* extendDerivation x D K == given a derivation D on K and a separable *)
(* element x over K, this function returns the *)
(* unique extension of D to K(x). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import GRing.Theory.
HB.lock
Definition separable_poly {R : idomainType} (p : {poly R}) := coprimep p p^`().
Canonical separable_poly_unlockable := Unlockable separable_poly.unlock.
Section SeparablePoly.
Variable R : idomainType.
Implicit Types p q d u v : {poly R}.
Local Notation separable := (@separable_poly R).
Local Notation lcn_neq0 := (Pdiv.Idomain.lc_expn_scalp_neq0 _).
Lemma separable_poly_neq0 p : separable p -> p != 0.
Proof.
by apply: contraTneq => ->; rewrite unlock deriv0 coprime0p eqp01.
Qed.
Lemma poly_square_freeP p :
(forall u v, u * v %| p -> coprimep u v)
<-> (forall u, size u != 1 -> ~~ (u ^+ 2 %| p)).
Proof.
split=> [sq'p u | sq'p u v dvd_uv_p].
by apply: contra => /sq'p; rewrite coprimepp.
rewrite coprimep_def (contraLR (sq'p _)) // (dvdp_trans _ dvd_uv_p) //.
by rewrite dvdp_mul ?dvdp_gcdl ?dvdp_gcdr.
Qed.
Lemma separable_polyP {p} :
reflect [/\ forall u v, u * v %| p -> coprimep u v
& forall u, u %| p -> 1 < size u -> u^`() != 0]
(separable p).
Proof.
apply: (iffP idP) => [sep_p | [sq'p nz_der1p]].
split=> [u v | u u_dv_p]; last first.
apply: contraTneq => u'0; rewrite unlock in sep_p; rewrite -leqNgt -(eqnP sep_p).
rewrite dvdp_leq -?size_poly_eq0 ?(eqnP sep_p) // dvdp_gcd u_dv_p.
have /dvdpZr <-: lead_coef u ^+ scalp p u != 0 by rewrite lcn_neq0.
by rewrite -derivZ -Pdiv.Idomain.divpK //= derivM u'0 mulr0 addr0 dvdp_mull.
rewrite Pdiv.Idomain.dvdp_eq mulrCA mulrA; set c := _ ^+ _ => /eqP Dcp.
have nz_c: c != 0 by rewrite lcn_neq0.
move: sep_p; rewrite coprimep_sym unlock -(coprimepZl _ _ nz_c).
rewrite -(coprimepZr _ _ nz_c) -derivZ Dcp derivM coprimepMl.
by rewrite coprimep_addl_mul !coprimepMr -andbA => /and4P[].
rewrite unlock coprimep_def eqn_leq size_poly_gt0; set g := gcdp _ _.
have nz_g: g != 0.
rewrite -dvd0p dvdp_gcd -(mulr0 0); apply/nandP; left.
by have /poly_square_freeP-> := sq'p; rewrite ?size_poly0.
have [g_p]: g %| p /\ g %| p^`() by rewrite dvdp_gcdr ?dvdp_gcdl.
pose c := lead_coef g ^+ scalp p g; have nz_c: c != 0 by rewrite lcn_neq0.
have Dcp: c *: p = p %/ g * g by rewrite Pdiv.Idomain.divpK.
rewrite nz_g andbT leqNgt -(dvdpZr _ _ nz_c) -derivZ Dcp derivM.
rewrite dvdp_addr; last by rewrite dvdp_mull.
rewrite Gauss_dvdpr; last by rewrite sq'p // mulrC -Dcp dvdpZl.
by apply: contraL => /nz_der1p nz_g'; rewrite gtNdvdp ?nz_g' ?lt_size_deriv.
Qed.
Lemma separable_coprime p u v : separable p -> u * v %| p -> coprimep u v.
Proof. by move=> /separable_polyP[sq'p _] /sq'p. Qed.
Lemma separable_nosquare p u k :
separable p -> 1 < k -> size u != 1 -> (u ^+ k %| p) = false.
Proof.
move=> /separable_polyP[/poly_square_freeP sq'p _] /subnKC <- /sq'p.
by apply: contraNF; apply: dvdp_trans; rewrite exprD dvdp_mulr.
Qed.
Lemma separable_deriv_eq0 p u :
separable p -> u %| p -> 1 < size u -> (u^`() == 0) = false.
Proof. by move=> /separable_polyP[_ nz_der1p] u_p /nz_der1p/negPf->. Qed.
Lemma dvdp_separable p q : q %| p -> separable p -> separable q.
Proof.
move=> /(dvdp_trans _)q_dv_p /separable_polyP[sq'p nz_der1p].
by apply/separable_polyP; split=> [u v /q_dv_p/sq'p | u /q_dv_p/nz_der1p].
Qed.
Lemma separable_mul p q :
separable (p * q) = [&& separable p, separable q & coprimep p q].
Proof.
apply/idP/and3P => [sep_pq | [sep_p sep_q co_pq]].
rewrite !(dvdp_separable _ sep_pq) ?dvdp_mulIr ?dvdp_mulIl //.
by rewrite (separable_coprime sep_pq).
rewrite unlock in sep_p sep_q *.
rewrite derivM coprimepMl {1}addrC mulrC !coprimep_addl_mul.
by rewrite !coprimepMr (coprimep_sym q p) co_pq !andbT; apply/andP.
Qed.
Lemma eqp_separable p q : p %= q -> separable p = separable q.
Proof. by case/andP=> p_q q_p; apply/idP/idP=> /dvdp_separable->. Qed.
Lemma separable_root p x :
separable (p * ('X - x%:P)) = separable p && ~~ root p x.
Proof.
rewrite separable_mul; apply: andb_id2l => seq_p.
by rewrite unlock derivXsubC coprimep1 coprimep_XsubC.
Qed.
Lemma separable_prod_XsubC (r : seq R) :
separable (\prod_(x <- r) ('X - x%:P)) = uniq r.
Proof.
elim: r => [|x r IH]; first by rewrite big_nil unlock /separable_poly coprime1p.
by rewrite big_cons mulrC separable_root IH root_prod_XsubC andbC.
Qed.
Lemma make_separable p : p != 0 -> separable (p %/ gcdp p p^`()).
Proof.
set g := gcdp p p^`() => nz_p; apply/separable_polyP.
have max_dvd_u (u : {poly R}): 1 < size u -> exists k, ~~ (u ^+ k %| p).
move=> u_gt1; exists (size p); rewrite gtNdvdp // polySpred //.
by rewrite -(ltn_subRL 1) subn1 size_exp leq_pmull // -(subnKC u_gt1).
split=> [|u u_pg u_gt1]; last first.
apply/eqP=> u'0 /=; have [k /negP[]] := max_dvd_u u u_gt1.
elim: k => [|k IHk]; first by rewrite dvd1p.
suffices: u ^+ k.+1 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite exprS dvdp_mul // dvdp_gcd IHk //=.
suffices: u ^+ k %| (p %/ u ^+ k * u ^+ k)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE u'0 mul0r mul0rn mulr0 addr0 dvdp_mull.
have pg_dv_p: p %/ g %| p by rewrite divp_dvd ?dvdp_gcdl.
apply/poly_square_freeP=> u; rewrite neq_ltn ltnS leqn0 size_poly_eq0.
case/predU1P=> [-> | /max_dvd_u[k]].
by apply: contra nz_p; rewrite expr0n -dvd0p => /dvdp_trans->.
apply: contra => u2_dv_pg; case: k; [by rewrite dvd1p | elim=> [|n IHn]].
exact: dvdp_trans (dvdp_mulr _ _) (dvdp_trans u2_dv_pg pg_dv_p).
suff: u ^+ n.+2 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite -add2n exprD dvdp_mul // dvdp_gcd.
rewrite (dvdp_trans _ IHn) ?exprS ?dvdp_mull //=.
suff: u ^+ n %| ((p %/ u ^+ n.+1) * u ^+ n.+1)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE dvdp_add // -1?mulr_natl ?exprS !dvdp_mull.
Qed.
End SeparablePoly.
Arguments separable_polyP {R p}.
Lemma separable_map (F : fieldType) (R : idomainType)
(f : {rmorphism F -> R}) (p : {poly F}) :
separable_poly (map_poly f p) = separable_poly p.
Proof.
by rewrite unlock deriv_map /coprimep -gcdp_map size_map_poly.
Qed.
Section InfinitePrimitiveElementTheorem.
Local Notation "p ^ f" := (map_poly f p) : ring_scope.
Variables (F L : fieldType) (iota : {rmorphism F -> L}).
Variables (x y : L) (p : {poly F}).
Hypotheses (nz_p : p != 0) (px_0 : root (p ^ iota) x).
Let inFz z w := exists q, (q ^ iota).[z] = w.
Lemma large_field_PET q :
root (q ^ iota) y -> separable_poly q ->
exists2 r, r != 0
& forall t (z := iota t * y - x), ~~ root r (iota t) -> inFz z x /\ inFz z y.
Proof.
move=> qy_0 sep_q; have nz_q := separable_poly_neq0 sep_q.
have /factor_theorem[q0 Dq] := qy_0.
set p1 := p ^ iota \Po ('X + x%:P); set q1 := q0 \Po ('X + y%:P).
have nz_p1: p1 != 0.
apply: contraNneq nz_p => /(canRL (fun r => comp_polyXaddC_K r _))/eqP.
by rewrite comp_poly0 map_poly_eq0.
have{sep_q} nz_q10: q1.[0] != 0.
move: sep_q; rewrite -(separable_map iota) Dq separable_root => /andP[_].
by rewrite horner_comp !hornerE.
have nz_q1: q1 != 0 by apply: contraNneq nz_q10 => ->; rewrite horner0.
pose p2 := p1 ^ polyC \Po ('X * 'Y); pose q2 := q1 ^ polyC.
have /Bezout_coprimepP[[u v]]: coprimep p2 q2.
rewrite coprimep_def eqn_leq leqNgt andbC size_poly_gt0 gcdp_eq0 poly_XmY_eq0.
by rewrite map_polyC_eq0 (negPf nz_p1) -resultant_eq0 div_annihilant_neq0.
rewrite -size_poly_eq1 => /size_poly1P[r nzr Dr]; exists r => {nzr}// t z nz_rt.
have [r1 nz_r1 r1z_0]: algebraicOver iota z.
apply/algebraic_sub; last by exists p.
by apply: algebraic_mul; [apply: algebraic_id | exists q].
pose Fz := subFExtend iota z r1; pose kappa : Fz -> L := subfx_inj.
pose kappa' := inj_subfx iota z r1.
have /eq_map_poly Diota: kappa \o kappa' =1 iota.
by move=> w; rewrite /kappa /= subfx_inj_eval // map_polyC hornerC.
suffices [y3]: exists y3, y = kappa y3.
have [q3 ->] := subfxE y3; rewrite /kappa subfx_inj_eval // => Dy.
split; [exists (t *: q3 - 'X) | by exists q3].
by rewrite rmorphB /= linearZ map_polyX !hornerE -Dy opprB addrC addrNK.
pose p0 := p ^ iota \Po (iota t *: 'X - z%:P).
have co_p0_q0: coprimep p0 q0.
pose at_t := horner_eval (iota t); have at_t0: at_t 0 = 0 by apply: rmorph0.
have /map_polyK polyCK: cancel polyC at_t by move=> w; apply: hornerC.
have ->: p0 = p2 ^ at_t \Po ('X - y%:P).
rewrite map_comp_poly polyCK // rmorphM /= map_polyC map_polyX /=.
rewrite horner_evalE hornerX.
rewrite -!comp_polyA comp_polyM comp_polyD !comp_polyC !comp_polyX.
by rewrite mulrC mulrBr mul_polyC addrAC -addrA -opprB -rmorphM -rmorphB.
have ->: q0 = q2 ^ at_t \Po ('X - y%:P) by rewrite polyCK ?comp_polyXaddC_K.
apply/coprimep_comp_poly/Bezout_coprimepP; exists (u ^ at_t, v ^ at_t).
by rewrite /= -!rmorphM -rmorphD Dr /= map_polyC polyC_eqp1.
have{co_p0_q0}: gcdp p0 (q ^ iota) %= 'X - y%:P.
rewrite /eqp Dq (eqp_dvdl _ (Gauss_gcdpr _ _)) // dvdp_gcdr dvdp_gcd.
rewrite dvdp_mull // -root_factor_theorem rootE horner_comp !hornerE.
by rewrite opprB addrC subrK.
have{p0} [p3 ->]: exists p3, p0 = p3 ^ kappa.
exists (p ^ kappa' \Po (kappa' t *: 'X - (subfx_eval iota z r1 'X)%:P)).
rewrite map_comp_poly rmorphB /= linearZ /= map_polyC map_polyX /=.
rewrite !subfx_inj_eval // map_polyC hornerC map_polyX hornerX.
by rewrite -map_poly_comp Diota.
rewrite -Diota map_poly_comp -gcdp_map /= -/kappa.
move: (gcdp _ _) => r3 /eqpf_eq[c nz_c Dr3].
exists (- (r3`_0 / r3`_1)); rewrite [kappa _]rmorphN fmorph_div -!coef_map Dr3.
by rewrite !coefZ polyseqXsubC mulr1 mulrC mulKf ?opprK.
Qed.
Lemma pchar0_PET (q : {poly F}) :
q != 0 -> root (q ^ iota) y -> [pchar F] =i pred0 ->
exists n, let z := y *+ n - x in inFz z x /\ inFz z y.
Proof.
move=> nz_q qy_0 /pcharf0P pcharF0.
without loss{nz_q} sep_q: q qy_0 / separable_poly q.
move=> IHq; apply: IHq (make_separable nz_q).
have /dvdpP[q1 Dq] := dvdp_gcdl q q^`().
rewrite {1}Dq mulpK ?gcdp_eq0; last by apply/nandP; left.
have [n [r nz_ry Dr]] := multiplicity_XsubC (q ^ iota) y.
rewrite map_poly_eq0 nz_q /= in nz_ry.
case: n => [|n] in Dr; first by rewrite Dr mulr1 (negPf nz_ry) in qy_0.
have: ('X - y%:P) ^+ n.+1 %| q ^ iota by rewrite Dr dvdp_mulIr.
rewrite Dq rmorphM /= gcdp_map -(eqp_dvdr _ (gcdp_mul2l _ _ _)) -deriv_map Dr.
rewrite dvdp_gcd derivM deriv_exp derivXsubC mul1r !mulrA dvdp_mulIr /=.
rewrite mulrDr mulrA dvdp_addr ?dvdp_mulIr // exprS -scaler_nat -!scalerAr.
rewrite dvdpZr -?(rmorph_nat iota) ?fmorph_eq0 ?pcharF0 //.
rewrite mulrA dvdp_mul2r ?expf_neq0 ?polyXsubC_eq0 //.
by rewrite Gauss_dvdpl ?dvdp_XsubCl // coprimep_sym coprimep_XsubC.
have [r nz_r PETxy] := large_field_PET qy_0 sep_q.
pose ts := mkseq (fun n => iota n%:R) (size r).
have /(max_ring_poly_roots nz_r)/=/implyP: uniq_roots ts.
rewrite uniq_rootsE mkseq_uniq // => m n eq_mn; apply/eqP; rewrite eqn_leq.
wlog suffices: m n eq_mn / m <= n by move=> IHmn; rewrite !IHmn.
move/fmorph_inj/eqP: eq_mn; rewrite -subr_eq0 leqNgt; apply: contraL => lt_mn.
by rewrite -natrB ?(ltnW lt_mn) // pcharF0 -lt0n subn_gt0.
rewrite size_mkseq ltnn implybF all_map => /allPn[n _ /= /PETxy].
by rewrite rmorph_nat mulr_natl; exists n.
Qed.
End InfinitePrimitiveElementTheorem.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar0_PET instead.")]
Notation char0_PET := (pchar0_PET) (only parsing).
Section Separable.
Variables (F : fieldType) (L : fieldExtType F).
Implicit Types (U V W : {vspace L}) (E K M : {subfield L}) (D : 'End(L)).
Section Derivation.
Variables (K : {vspace L}) (D : 'End(L)).
(* A deriviation only needs to be additive and satisfy Lebniz's law, but all *)
(* the deriviations used here are going to be linear, so we only define *)
(* the Derivation predicate for linear endomorphisms. *)
Definition Derivation : bool :=
all2rel (fun u v => D (u * v) == D u * v + u * D v) (vbasis K).
Hypothesis derD : Derivation.
Lemma Derivation_mul : {in K &, forall u v, D (u * v) = D u * v + u * D v}.
Proof.
move=> u v /coord_vbasis-> /coord_vbasis->.
rewrite !(mulr_sumr, linear_sum) -big_split; apply: eq_bigr => /= j _.
rewrite !mulr_suml linear_sum -big_split; apply: eq_bigr => /= i _.
rewrite !(=^~ scalerAl, linearZZ) -!scalerAr linearZZ -!scalerDr !scalerA /=.
by congr (_ *: _); apply/eqP/(allrelP derD); exact: memt_nth.
Qed.
Lemma Derivation_mul_poly (Dp := map_poly D) :
{in polyOver K &, forall p q, Dp (p * q) = Dp p * q + p * Dp q}.
Proof.
move=> p q Kp Kq; apply/polyP=> i; rewrite {}/Dp coefD coef_map /= !coefM.
rewrite linear_sum -big_split; apply: eq_bigr => /= j _.
by rewrite !{1}coef_map Derivation_mul ?(polyOverP _).
Qed.
End Derivation.
Lemma DerivationS E K D : (K <= E)%VS -> Derivation E D -> Derivation K D.
Proof.
move/subvP=> sKE derD; apply/allrelP=> x y Kx Ky; apply/eqP.
by rewrite (Derivation_mul derD) ?sKE // vbasis_mem.
Qed.
Section DerivationAlgebra.
Variables (E : {subfield L}) (D : 'End(L)).
Hypothesis derD : Derivation E D.
Lemma Derivation1 : D 1 = 0.
Proof.
apply: (addIr (D (1 * 1))); rewrite add0r {1}mul1r.
by rewrite (Derivation_mul derD) ?mem1v // mulr1 mul1r.
Qed.
Lemma Derivation_scalar x : x \in 1%VS -> D x = 0.
Proof. by case/vlineP=> y ->; rewrite linearZ /= Derivation1 scaler0. Qed.
Lemma Derivation_exp x m : x \in E -> D (x ^+ m) = x ^+ m.-1 *+ m * D x.
Proof.
move=> Ex; case: m; first by rewrite expr0 mulr0n mul0r Derivation1.
elim=> [|m IHm]; first by rewrite mul1r.
rewrite exprS (Derivation_mul derD) //; last by apply: rpredX.
by rewrite mulrC IHm mulrA mulrnAr -exprS -mulrDl.
Qed.
Lemma Derivation_horner p x :
p \is a polyOver E -> x \in E ->
D p.[x] = (map_poly D p).[x] + p^`().[x] * D x.
Proof.
move=> Ep Ex; elim/poly_ind: p Ep => [|p c IHp] /polyOverP EpXc.
by rewrite !(raddf0, horner0) mul0r add0r.
have Ep: p \is a polyOver E.
by apply/polyOverP=> i; have:= EpXc i.+1; rewrite coefD coefMX coefC addr0.
have->: map_poly D (p * 'X + c%:P) = map_poly D p * 'X + (D c)%:P.
apply/polyP=> i; rewrite !(coefD, coefMX, coef_map) /= linearD /= !coefC.
by rewrite !(fun_if D) linear0.
rewrite derivMXaddC !hornerE mulrDl mulrAC addrAC linearD /=; congr (_ + _).
by rewrite addrCA -mulrDl -IHp // addrC (Derivation_mul derD) ?rpred_horner.
Qed.
End DerivationAlgebra.
Definition separable_element U x := separable_poly (minPoly U x).
Section SeparableElement.
Variables (K : {subfield L}) (x : L).
(* begin hide *)
Let sKxK : (K <= <<K; x>>)%VS := subv_adjoin K x.
Let Kx_x : x \in <<K; x>>%VS := memv_adjoin K x.
(* end hide *)
Lemma separable_elementP :
reflect (exists f, [/\ f \is a polyOver K, root f x & separable_poly f])
(separable_element K x).
Proof.
apply: (iffP idP) => [sep_x | [f [Kf /(minPoly_dvdp Kf)/dvdpP[g ->]]]].
by exists (minPoly K x); rewrite minPolyOver root_minPoly.
by rewrite separable_mul => /and3P[].
Qed.
Lemma base_separable : x \in K -> separable_element K x.
Proof.
move=> Kx; apply/separable_elementP; exists ('X - x%:P).
by rewrite polyOverXsubC root_XsubC unlock !derivCE coprimep1.
Qed.
Lemma separable_nz_der : separable_element K x = ((minPoly K x)^`() != 0).
Proof.
rewrite /separable_element unlock.
apply/idP/idP=> [|nzPx'].
by apply: contraTneq => ->; rewrite coprimep0 -size_poly_eq1 size_minPoly.
have gcdK : gcdp (minPoly K x) (minPoly K x)^`() \in polyOver K.
by rewrite gcdp_polyOver ?polyOver_deriv // minPolyOver.
rewrite -gcdp_eqp1 -size_poly_eq1 -dvdp1.
have /orP[/andP[_]|/andP[]//] := minPoly_irr gcdK (dvdp_gcdl _ _).
rewrite dvdp_gcd dvdpp /= => /(dvdp_leq nzPx')/leq_trans/(_ (size_poly _ _)).
by rewrite size_minPoly ltnn.
Qed.
Lemma separablePn_pchar :
reflect (exists2 p, p \in [pchar L] &
exists2 g, g \is a polyOver K & minPoly K x = g \Po 'X^p)
(~~ separable_element K x).
Proof.
rewrite separable_nz_der negbK; set f := minPoly K x.
apply: (iffP eqP) => [f'0 | [p Hp [g _ ->]]]; last first.
by rewrite deriv_comp derivXn -scaler_nat (pcharf0 Hp) scale0r mulr0.
pose n := adjoin_degree K x; have sz_f: size f = n.+1 := size_minPoly K x.
have fn1: f`_n = 1 by rewrite -(monicP (monic_minPoly K x)) lead_coefE sz_f.
have dimKx: (adjoin_degree K x)%:R == 0 :> L.
by rewrite -(coef0 _ n.-1) -f'0 coef_deriv fn1.
have /natf0_pchar[// | p pcharLp] := dimKx.
have /dvdnP[r Dn]: (p %| n)%N by rewrite (dvdn_pcharf pcharLp).
exists p => //; exists (\poly_(i < r.+1) f`_(i * p)).
by apply: polyOver_poly => i _; rewrite (polyOverP _) ?minPolyOver.
rewrite comp_polyE size_poly_eq -?Dn ?fn1 ?oner_eq0 //.
have pr_p := pcharf_prime pcharLp; have p_gt0 := prime_gt0 pr_p.
apply/polyP=> i; rewrite coef_sum.
have [[{}i ->] | p'i] := altP (@dvdnP p i); last first.
rewrite big1 => [|j _]; last first.
rewrite coefZ -exprM coefXn [_ == _](contraNF _ p'i) ?mulr0 // => /eqP->.
by rewrite dvdn_mulr.
rewrite (dvdn_pcharf pcharLp) in p'i; apply: mulfI p'i _ _ _.
by rewrite mulr0 mulr_natl; case: i => // i; rewrite -coef_deriv f'0 coef0.
have [ltri | leir] := leqP r.+1 i.
rewrite nth_default ?sz_f ?Dn ?ltn_pmul2r ?big1 // => j _.
rewrite coefZ -exprM coefXn mulnC gtn_eqF ?mulr0 //.
by rewrite ltn_pmul2l ?(leq_trans _ ltri).
rewrite (bigD1 (Sub i _)) //= big1 ?addr0 => [|j i'j]; last first.
by rewrite coefZ -exprM coefXn mulnC eqn_pmul2l // mulr_natr mulrb ifN_eqC.
by rewrite coef_poly leir coefZ -exprM coefXn mulnC eqxx mulr1.
Qed.
Lemma separable_root_der : separable_element K x (+) root (minPoly K x)^`() x.
Proof.
have KpKx': _^`() \is a polyOver K := polyOver_deriv (minPolyOver K x).
rewrite separable_nz_der addNb (root_small_adjoin_poly KpKx') ?addbb //.
by rewrite (leq_trans (size_poly _ _)) ?size_minPoly.
Qed.
Lemma Derivation_separable D :
Derivation <<K; x>> D -> separable_element K x ->
D x = - (map_poly D (minPoly K x)).[x] / (minPoly K x)^`().[x].
Proof.
move=> derD sepKx; have:= separable_root_der; rewrite {}sepKx -sub0r => nzKx'x.
apply: canRL (mulfK nzKx'x) (canRL (addrK _) _); rewrite mulrC addrC.
rewrite -(Derivation_horner derD) ?minPolyxx ?linear0 //.
exact: polyOverSv sKxK _ (minPolyOver _ _).
Qed.
Section ExtendDerivation.
Variable D : 'End(L).
Let Dx E := - (map_poly D (minPoly E x)).[x] / ((minPoly E x)^`()).[x].
Fact extendDerivation_zmod_morphism_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
zmod_morphism body.
Proof.
move: Dx => C /= u v; rewrite /adjEx.
rewrite raddfB /= derivB -/adjEx !hornerE /= raddfB /= !hornerE.
by rewrite mulrBl addrACA opprD.
Qed.
Fact extendDerivation_scalable_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
scalable body.
Proof.
move: Dx => C /= a u; rewrite /adjEx linearZ /= derivZ -/adjEx.
rewrite hornerE -[RHS]mulr_algl mulrDr mulrA -[in RHS]hornerZ.
congr (_.[x] + _); apply/polyP=> i.
by rewrite coefZ !coef_map coefZ !mulr_algl /= linearZ.
Qed.
Section DerivationLinear.
Variable (E : {subfield L}).
Let body (y : L) (p := Fadjoin_poly E x y) : L :=
(map_poly D p).[x] + p^`().[x] * Dx E.
HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ body
(extendDerivation_zmod_morphism_subproof E).
HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ body
(extendDerivation_scalable_subproof E).
Let extendDerivationLinear := Eval hnf in (body : {linear _ -> _}).
Definition extendDerivation : 'End(L) := linfun extendDerivationLinear.
End DerivationLinear.
Hypothesis derD : Derivation K D.
Lemma extendDerivation_id y : y \in K -> extendDerivation K y = D y.
Proof.
move=> yK; rewrite lfunE /= Fadjoin_polyC // derivC map_polyC hornerC.
by rewrite horner0 mul0r addr0.
Qed.
Lemma extendDerivation_horner p :
p \is a polyOver K -> separable_element K x ->
extendDerivation K p.[x] = (map_poly D p).[x] + p^`().[x] * Dx K.
Proof.
move=> Kp sepKx; have:= separable_root_der; rewrite {}sepKx /= => nz_pKx'x.
rewrite [in RHS](divp_eq p (minPoly K x)) lfunE /= Fadjoin_poly_mod ?raddfD //=.
rewrite (Derivation_mul_poly derD) ?divp_polyOver ?minPolyOver //.
rewrite derivM !{1}hornerD !{1}hornerM minPolyxx !{1}mulr0 !{1}add0r.
rewrite mulrDl addrA [_ + (_ * _ * _)]addrC {2}/Dx -mulrA -/Dx.
by rewrite [_ / _]mulrC (mulVKf nz_pKx'x) mulrN addKr.
Qed.
Lemma extendDerivationP :
separable_element K x -> Derivation <<K; x>> (extendDerivation K).
Proof.
move=> sep; apply/allrelP=> u v /vbasis_mem Hu /vbasis_mem Hv; apply/eqP.
rewrite -(Fadjoin_poly_eq Hu) -(Fadjoin_poly_eq Hv) -hornerM.
rewrite !{1}extendDerivation_horner ?{1}rpredM ?Fadjoin_polyOver //.
rewrite (Derivation_mul_poly derD) ?Fadjoin_polyOver //.
rewrite derivM !{1}hornerD !{1}hornerM !{1}mulrDl !{1}mulrDr -!addrA.
congr (_ + _); rewrite [Dx K]lock -!{1}mulrA !{1}addrA; congr (_ + _).
by rewrite addrC; congr (_ * _ + _); rewrite mulrC.
Qed.
End ExtendDerivation.
(* Reference:
http://www.math.uconn.edu/~kconrad/blurbs/galoistheory/separable2.pdf *)
Lemma Derivation_separableP :
reflect
(forall D, Derivation <<K; x>> D -> K <= lker D -> <<K; x>> <= lker D)%VS
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx D derD /subvP DK_0 | derKx_0].
have{} DK_0 q: q \is a polyOver K -> map_poly D q = 0.
move=> /polyOverP Kq; apply/polyP=> i; apply/eqP.
by rewrite coef0 coef_map -memv_ker DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->]; rewrite memv_ker.
rewrite (Derivation_horner derD) ?(polyOverSv sKxK) //.
rewrite (Derivation_separable derD sepKx) !DK_0 ?minPolyOver //.
by rewrite horner0 oppr0 mul0r mulr0 addr0.
apply: wlog_neg; rewrite {1}separable_nz_der negbK => /eqP pKx'_0.
pose Df := fun y => (Fadjoin_poly K x y)^`().[x].
have Dlin: linear Df.
move=> a u v; rewrite /Df linearP /= -mul_polyC derivD derivM derivC.
by rewrite mul0r add0r hornerD hornerM hornerC -scalerAl mul1r.
pose DlinM := GRing.isLinear.Build _ _ _ _ Df Dlin.
pose DL : {linear _ -> _} := HB.pack Df DlinM.
pose D := linfun DL; apply: base_separable.
have DK_0: (K <= lker D)%VS.
apply/subvP=> v Kv; rewrite memv_ker lfunE /= /Df Fadjoin_polyC //.
by rewrite derivC horner0.
have Dder: Derivation <<K; x>> D.
apply/allrelP=> u v /vbasis_mem Kx_u /vbasis_mem Kx_v; apply/eqP.
rewrite !lfunE /= /Df; set Px := Fadjoin_poly K x.
set Px_u := Px u; rewrite -(Fadjoin_poly_eq Kx_u) -/Px -/Px_u.
set Px_v := Px v; rewrite -(Fadjoin_poly_eq Kx_v) -/Px -/Px_v.
rewrite -!hornerM -hornerD -derivM.
rewrite /Px Fadjoin_poly_mod ?rpredM ?Fadjoin_polyOver //.
rewrite [in RHS](divp_eq (Px_u * Px_v) (minPoly K x)) derivD derivM.
by rewrite pKx'_0 mulr0 addr0 hornerD hornerM minPolyxx mulr0 add0r.
have{Dder DK_0}: x \in lker D by apply: subvP Kx_x; apply: derKx_0.
apply: contraLR => K'x; rewrite memv_ker lfunE /= /Df Fadjoin_polyX //.
by rewrite derivX hornerC oner_eq0.
Qed.
End SeparableElement.
#[deprecated(since="mathcomp 2.4.0", note="Use separablePn_pchar instead.")]
Notation separablePn := (separablePn_pchar) (only parsing).
Arguments separable_elementP {K x}.
Lemma separable_elementS K E x :
(K <= E)%VS -> separable_element K x -> separable_element E x.
Proof.
move=> sKE /separable_elementP[f [fK rootf sepf]]; apply/separable_elementP.
by exists f; rewrite (polyOverSv sKE).
Qed.
Lemma adjoin_separableP {K x} :
reflect (forall y, y \in <<K; x>>%VS -> separable_element K y)
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx | -> //]; last exact: memv_adjoin.
move=> _ /Fadjoin_polyP[q Kq ->]; apply/Derivation_separableP=> D derD DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->].
rewrite memv_ker -(extendDerivation_id x D (mempx_Fadjoin _ Kp)).
have sepFyx: (separable_element <<K; q.[x]>> x).
by apply: (separable_elementS (subv_adjoin _ _)).
have KyxEqKx: (<< <<K; q.[x]>>; x>> = <<K; x>>)%VS.
apply/eqP; rewrite eqEsubv andbC adjoinSl ?subv_adjoin //=.
apply/FadjoinP/andP; rewrite memv_adjoin andbT.
by apply/FadjoinP/andP; rewrite subv_adjoin mempx_Fadjoin.
have /[!KyxEqKx] derDx := extendDerivationP derD sepFyx.
rewrite -horner_comp (Derivation_horner derDx) ?memv_adjoin //; last first.
by apply: (polyOverSv (subv_adjoin _ _)); apply: polyOver_comp.
set Dx_p := map_poly _; have Dx_p_0 t: t \is a polyOver K -> (Dx_p t).[x] = 0.
move/polyOverP=> Kt; congr (_.[x] = 0): (horner0 x); apply/esym/polyP => i.
have /eqP Dti_0: D t`_i == 0 by rewrite -memv_ker (subvP DK_0) ?Kt.
by rewrite coef0 coef_map /= {1}extendDerivation_id ?subvP_adjoin.
rewrite (Derivation_separable derDx sepKx) -/Dx_p Dx_p_0 ?polyOver_comp //.
by rewrite add0r mulrCA Dx_p_0 ?minPolyOver ?oppr0 ?mul0r.
Qed.
Lemma separable_exponent_pchar K x :
exists n, [pchar L].-nat n && separable_element K (x ^+ n).
Proof.
pose d := adjoin_degree K x; move: {2}d.+1 (ltnSn d) => n.
elim: n => // n IHn in x @d *; rewrite ltnS => le_d_n.
have [[p pcharLp]|] := altP (separablePn_pchar K x); last by rewrite negbK; exists 1.
case=> g Kg defKx; have p_pr := pcharf_prime pcharLp.
suffices /IHn[m /andP[pcharLm sepKxpm]]: adjoin_degree K (x ^+ p) < n.
by exists (p * m)%N; rewrite pnatM pnatE // pcharLp pcharLm exprM.
apply: leq_trans le_d_n; rewrite -ltnS -!size_minPoly.
have nzKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have nzg: g != 0 by apply: contra_eqN defKx => /eqP->; rewrite comp_poly0.
apply: leq_ltn_trans (dvdp_leq nzg _) _.
by rewrite minPoly_dvdp // rootE -hornerXn -horner_comp -defKx minPolyxx.
rewrite (polySpred nzKx) ltnS defKx size_comp_poly size_polyXn /=.
suffices g_gt1: 1 < size g by rewrite -(subnKC g_gt1) ltn_Pmulr ?prime_gt1.
apply: contra_eqT (size_minPoly K x); rewrite defKx -leqNgt => /size1_polyC->.
by rewrite comp_polyC size_polyC; case: (_ != 0).
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use separable_exponent_pchar instead.")]
Notation separable_exponent := (separable_exponent_pchar) (only parsing).
Lemma pcharf0_separable K : [pchar L] =i pred0 -> forall x, separable_element K x.
Proof.
move=> pcharL0 x; have [n /andP[pcharLn]] := separable_exponent_pchar K x.
by rewrite (pnat_1 pcharLn (sub_in_pnat _ pcharLn)) // => p _; rewrite pcharL0.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0_separable instead.")]
Notation charf0_separable := (pcharf0_separable) (only parsing).
Lemma pcharf_p_separable K x e p :
p \in [pchar L] -> separable_element K x = (x \in <<K; x ^+ (p ^ e.+1)>>%VS).
Proof.
move=> pcharLp; apply/idP/idP=> [sepKx | /Fadjoin_poly_eq]; last first.
set m := p ^ _; set f := Fadjoin_poly K _ x => Dx; apply/separable_elementP.
have mL0: m%:R = 0 :> L by apply/eqP; rewrite -(dvdn_pcharf pcharLp) dvdn_exp.
exists ('X - (f \Po 'X^m)); split.
- by rewrite rpredB ?polyOver_comp ?rpredX ?polyOverX ?Fadjoin_polyOver.
- by rewrite rootE !hornerE horner_comp hornerXn Dx subrr.
rewrite unlock !(derivE, deriv_comp) -mulr_natr -rmorphMn /= mL0.
by rewrite !mulr0 subr0 coprimep1.
without loss{e} ->: e x sepKx / e = 0.
move=> IH; elim: {e}e.+1 => [|e]; [exact: memv_adjoin | apply: subvP].
apply/FadjoinP/andP; rewrite subv_adjoin expnSr exprM (IH 0) //.
by have /adjoin_separableP-> := sepKx; rewrite ?rpredX ?memv_adjoin.
set K' := <<K; x ^+ p>>%VS; have sKK': (K <= K')%VS := subv_adjoin _ _.
pose q := minPoly K' x; pose g := 'X^p - (x ^+ p)%:P.
have [K'g]: g \is a polyOver K' /\ q \is a polyOver K'.
by rewrite minPolyOver rpredB ?rpredX ?polyOverX // polyOverC memv_adjoin.
have /dvdpP[c Dq]: 'X - x%:P %| q by rewrite dvdp_XsubCl root_minPoly.
have co_c_g: coprimep c g.
have pcharPp: p \in [pchar {poly L}] := rmorph_pchar polyC pcharLp.
rewrite /g polyC_exp -!(pFrobenius_autE pcharPp) -rmorphB coprimep_expr //.
have: separable_poly q := separable_elementS sKK' sepKx.
by rewrite Dq separable_mul => /and3P[].
have{g K'g co_c_g} /size_poly1P[a nz_a Dc]: size c == 1.
suffices c_dv_g: c %| g by rewrite -(eqp_size (dvdp_gcd_idl c_dv_g)).
have: q %| g by rewrite minPoly_dvdp // rootE !hornerE subrr.
by apply: dvdp_trans; rewrite Dq dvdp_mulIl.
rewrite {q}Dq {c}Dc mulrBr -rmorphM -rmorphN -cons_poly_def qualifE /=.
by rewrite polyseq_cons !polyseqC nz_a /= rpredN andbCA => /and3P[/fpredMl->].
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_p_separable instead.")]
Notation charf_p_separable := (pcharf_p_separable) (only parsing).
Lemma pcharf_n_separable K x n :
[pchar L].-nat n -> 1 < n -> separable_element K x = (x \in <<K; x ^+ n>>%VS).
Proof.
rewrite -pi_pdiv; set p := pdiv n => pcharLn pi_n_p.
have pcharLp: p \in [pchar L] := pnatPpi pcharLn pi_n_p.
have <-: (n`_p)%N = n by rewrite -(eq_partn n (pcharf_eq pcharLp)) part_pnat_id.
by rewrite p_part lognE -mem_primes pi_n_p -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_n_separable instead.")]
Notation charf_n_separable := (pcharf_n_separable) (only parsing).
Definition purely_inseparable_element U x :=
x ^+ ex_minn (separable_exponent_pchar <<U>> x) \in U.
Lemma purely_inseparable_elementP_pchar {K x} :
reflect (exists2 n, [pchar L].-nat n & x ^+ n \in K)
(purely_inseparable_element K x).
Proof.
rewrite /purely_inseparable_element.
case: ex_minnP => n /andP[pcharLn /=]; rewrite subfield_closed => sepKxn min_xn.
apply: (iffP idP) => [Kxn | [m pcharLm Kxm]]; first by exists n.
have{min_xn}: n <= m by rewrite min_xn ?pcharLm ?base_separable.
rewrite leq_eqVlt => /predU1P[-> // | ltnm]; pose p := pdiv m.
have m_gt1: 1 < m by have [/leq_ltn_trans->] := andP pcharLn.
have pcharLp: p \in [pchar L] by rewrite (pnatPpi pcharLm) ?pi_pdiv.
have [/p_natP[em Dm] /p_natP[en Dn]]: p.-nat m /\ p.-nat n.
by rewrite -!(eq_pnat _ (pcharf_eq pcharLp)).
rewrite Dn Dm ltn_exp2l ?prime_gt1 ?pdiv_prime // in ltnm.
rewrite -(Fadjoin_idP Kxm) Dm -(subnKC ltnm) addSnnS expnD exprM -Dn.
by rewrite -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use purely_inseparable_elementP_pchar instead.")]
Notation purely_inseparable_elementP := (purely_inseparable_elementP_pchar) (only parsing).
Lemma separable_inseparable_element K x :
separable_element K x && purely_inseparable_element K x = (x \in K).
Proof.
rewrite /purely_inseparable_element; case: ex_minnP => [[|m]] //=.
rewrite subfield_closed; case: m => /= [-> //| m _ /(_ 1)/implyP/= insepKx].
by rewrite (negPf insepKx) (contraNF (@base_separable K x) insepKx).
Qed.
Lemma base_inseparable K x : x \in K -> purely_inseparable_element K x.
Proof. by rewrite -separable_inseparable_element => /andP[]. Qed.
Lemma sub_inseparable K E x :
(K <= E)%VS -> purely_inseparable_element K x ->
purely_inseparable_element E x.
Proof.
move/subvP=> sKE /purely_inseparable_elementP_pchar[n pcharLn /sKE Exn].
by apply/purely_inseparable_elementP_pchar; exists n.
Qed.
Section PrimitiveElementTheorem.
Variables (K : {subfield L}) (x y : L).
Section FiniteCase.
Variable N : nat.
Let K_is_large := exists s, [/\ uniq s, {subset s <= K} & N < size s].
Let cyclic_or_large (z : L) : z != 0 -> K_is_large \/ exists a, z ^+ a.+1 = 1.
Proof.
move=> nz_z; pose d := adjoin_degree K z.
pose h0 (i : 'I_(N ^ d).+1) (j : 'I_d) := (Fadjoin_poly K z (z ^+ i))`_j.
pose s := undup [seq h0 i j | i <- enum 'I_(N ^ d).+1, j <- enum 'I_d].
have s_h0 i j: h0 i j \in s.
by rewrite mem_undup; apply/allpairsP; exists (i, j); rewrite !mem_enum.
pose h i := [ffun j => Ordinal (etrans (index_mem _ _) (s_h0 i j))].
pose h' (f : {ffun 'I_d -> 'I_(size s)}) := \sum_(j < d) s`_(f j) * z ^+ j.
have hK i: h' (h i) = z ^+ i.
have Kz_zi: z ^+ i \in <<K; z>>%VS by rewrite rpredX ?memv_adjoin.
rewrite -(Fadjoin_poly_eq Kz_zi) (horner_coef_wide z (size_poly _ _)) -/d.
by apply: eq_bigr => j _; rewrite ffunE /= nth_index.
have [inj_h | ] := altP (@injectiveP _ _ h).
left; exists s; split=> [|zi_j|]; rewrite ?undup_uniq ?mem_undup //=.
by case/allpairsP=> ij [_ _ ->]; apply/polyOverP/Fadjoin_polyOver.
rewrite -[size s]card_ord -(@ltn_exp2r _ _ d) // -{2}[d]card_ord -card_ffun.
by rewrite -[_.+1]card_ord -(card_image inj_h) max_card.
case/injectivePn=> i1 [i2 i1'2 /(congr1 h')]; rewrite !hK => eq_zi12; right.
without loss{i1'2} lti12: i1 i2 eq_zi12 / i1 < i2.
by move=> IH; move: i1'2; rewrite neq_ltn => /orP[]; apply: IH.
by exists (i2 - i1.+1)%N; rewrite subnSK ?expfB // eq_zi12 divff ?expf_neq0.
Qed.
Lemma finite_PET : K_is_large \/ exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have [-> | /cyclic_or_large[|[a Dxa]]] := eqVneq x 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists y.
have [-> | /cyclic_or_large[|[b Dyb]]] := eqVneq y 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists x.
pose h0 (ij : 'I_a.+1 * 'I_b.+1) := x ^+ ij.1 * y ^+ ij.2.
pose H := <<[set ij | h0 ij == 1%R]>>%G; pose h (u : coset_of H) := h0 (repr u).
have h0M: {morph h0: ij1 ij2 / (ij1 * ij2)%g >-> ij1 * ij2}.
by rewrite /h0 => [] [i1 j1] [i2 j2] /=; rewrite mulrACA -!exprD !expr_mod.
have memH ij: (ij \in H) = (h0 ij == 1).
rewrite /= gen_set_id ?inE //; apply/group_setP; rewrite inE [h0 _]mulr1.
by split=> // ? ? /[!(inE, h0M)] /eqP-> /eqP->; rewrite mulr1.
have nH ij: ij \in 'N(H)%g.
by apply/(subsetP (cent_sub _))/centP=> ij1 _; congr (_, _); rewrite Zp_mulgC.
have hE ij: h (coset H ij) = h0 ij.
rewrite /h val_coset //; case: repr_rcosetP => ij1.
by rewrite memH h0M => /eqP->; rewrite mul1r.
have h1: h 1%g = 1 by rewrite /h repr_coset1 [h0 _]mulr1.
have hM: {morph h: u v / (u * v)%g >-> u * v}.
by do 2![move=> u; have{u} [? _ ->] := cosetP u]; rewrite -morphM // !hE h0M.
have /cyclicP[w defW]: cyclic [set: coset_of H].
apply: field_mul_group_cyclic (in2W hM) _ => u _; have [ij _ ->] := cosetP u.
by split=> [/eqP | -> //]; rewrite hE -memH => /coset_id.
have Kw_h ij t: h0 ij = t -> t \in <<K; h w>>%VS.
have /cycleP[k Dk]: coset H ij \in <[w]>%g by rewrite -defW inE.
rewrite -hE {}Dk => <-; elim: k => [|k IHk]; first by rewrite h1 rpred1.
by rewrite expgS hM rpredM // memv_adjoin.
right; exists (h w); apply/eqP; rewrite eqEsubv !(sameP FadjoinP andP).
rewrite subv_adjoin (subv_trans (subv_adjoin K y)) ?subv_adjoin //=.
rewrite (Kw_h (0, inZp 1)) 1?(Kw_h (inZp 1, 0)) /h0 ?mulr1 ?mul1r ?expr_mod //=.
by rewrite rpredM ?rpredX ?memv_adjoin // subvP_adjoin ?memv_adjoin.
Qed.
End FiniteCase.
Hypothesis sepKy : separable_element K y.
Lemma Primitive_Element_Theorem : exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have /polyOver_subvs[p Dp]: minPoly K x \is a polyOver K := minPolyOver K x.
have nz_pKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have{nz_pKx} nz_p: p != 0 by rewrite Dp map_poly_eq0 in nz_pKx.
have{Dp} px0: root (map_poly vsval p) x by rewrite -Dp root_minPoly.
have [q0 [Kq0 q0y0 sepKq0]] := separable_elementP sepKy.
have /polyOver_subvs[q Dq]: minPoly K y \is a polyOver K := minPolyOver K y.
have qy0: root (map_poly vsval q) y by rewrite -Dq root_minPoly.
have sep_pKy: separable_poly (minPoly K y).
by rewrite (dvdp_separable _ sepKq0) ?minPoly_dvdp.
have{sep_pKy} sep_q: separable_poly q by rewrite Dq separable_map in sep_pKy.
have [r nz_r PETr] := large_field_PET nz_p px0 qy0 sep_q.
have [[s [Us Ks /ltnW leNs]] | //] := finite_PET (size r).
have{s Us leNs} /allPn[t {}/Ks Kt nz_rt]: ~~ all (root r) s.
by apply: contraTN leNs; rewrite -ltnNge => /max_poly_roots->.
have{PETr} [/= [p1 Dx] [q1 Dy]] := PETr (Subvs Kt) nz_rt.
set z := t * y - x in Dx Dy; exists z; apply/eqP.
rewrite eqEsubv !(sameP FadjoinP andP) subv_adjoin.
have Kz_p1z (r1 : {poly subvs_of K}): (map_poly vsval r1).[z] \in <<K; z>>%VS.
rewrite rpred_horner ?memv_adjoin ?(polyOverSv (subv_adjoin K z)) //.
by apply/polyOver_subvs; exists r1.
rewrite -{1}Dx -{1}Dy !{Dx Dy}Kz_p1z /=.
rewrite (subv_trans (subv_adjoin K y)) ?subv_adjoin // rpredB ?memv_adjoin //.
by rewrite subvP_adjoin // rpredM ?memv_adjoin ?subvP_adjoin.
Qed.
Lemma adjoin_separable : separable_element <<K; y>> x -> separable_element K x.
Proof.
have /Derivation_separableP derKy := sepKy => /Derivation_separableP derKy_x.
have [z defKz] := Primitive_Element_Theorem.
suffices /adjoin_separableP: separable_element K z.
by apply; rewrite -defKz memv_adjoin.
apply/Derivation_separableP=> D; rewrite -defKz => derKxyD DK_0.
suffices derKyD: Derivation <<K; y>>%VS D by rewrite derKy_x // derKy.
by apply: DerivationS derKxyD; apply: subv_adjoin.
Qed.
End PrimitiveElementTheorem.
Lemma strong_Primitive_Element_Theorem K x y :
separable_element <<K; x>> y ->
exists2 z : L, (<< <<K; y>>; x>> = <<K; z>>)%VS
& separable_element K x -> separable_element K y.
Proof.
move=> sepKx_y; have [n /andP[pcharLn sepKyn]] := separable_exponent_pchar K y.
have adjK_C z t: (<<<<K; z>>; t>> = <<<<K; t>>; z>>)%VS.
by rewrite !agenv_add_id -!addvA (addvC <[_]>%VS).
have [z defKz] := Primitive_Element_Theorem x sepKyn.
exists z => [|/adjoin_separable->]; rewrite ?sepKx_y // -defKz.
have [|n_gt1|-> //] := ltngtP n 1; first by case: (n) pcharLn.
apply/eqP; rewrite !(adjK_C _ x) eqEsubv; apply/andP.
split; apply/FadjoinP/andP; rewrite subv_adjoin ?rpredX ?memv_adjoin //=.
by rewrite -pcharf_n_separable ?sepKx_y.
Qed.
Definition separable U W : bool :=
all (separable_element U) (vbasis W).
Definition purely_inseparable U W : bool :=
all (purely_inseparable_element U) (vbasis W).
Lemma separable_add K x y :
separable_element K x -> separable_element K y -> separable_element K (x + y).
Proof.
move/(separable_elementS (subv_adjoin K y))=> sepKy_x sepKy.
have [z defKz] := Primitive_Element_Theorem x sepKy.
have /(adjoin_separableP _): x + y \in <<K; z>>%VS.
by rewrite -defKz rpredD ?memv_adjoin // subvP_adjoin ?memv_adjoin.
apply; apply: adjoin_separable sepKy (adjoin_separable sepKy_x _).
by rewrite defKz base_separable ?memv_adjoin.
Qed.
Lemma separable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> separable_element K (v_ i)) ->
separable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> sepKi.
by elim/big_ind: _; [apply/base_separable/mem0v | apply: separable_add |].
Qed.
Lemma inseparable_add K x y :
purely_inseparable_element K x -> purely_inseparable_element K y ->
purely_inseparable_element K (x + y).
Proof.
have insepP := purely_inseparable_elementP_pchar.
move=> /insepP[n pcharLn Kxn] /insepP[m pcharLm Kym]; apply/insepP.
have pcharLnm: [pchar L].-nat (n * m)%N by rewrite pnatM pcharLn.
by exists (n * m)%N; rewrite ?exprDn_pchar // {2}mulnC !exprM memvD // rpredX.
Qed.
Lemma inseparable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> purely_inseparable_element K (v_ i)) ->
purely_inseparable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> insepKi.
by elim/big_ind: _; [apply/base_inseparable/mem0v | apply: inseparable_add |].
Qed.
Lemma separableP {K E} :
reflect (forall y, y \in E -> separable_element K y) (separable K E).
Proof.
apply/(iffP idP)=> [/allP|] sepK_E; last by apply/allP=> x /vbasis_mem/sepK_E.
move=> y /coord_vbasis->; apply/separable_sum=> i _.
have: separable_element K (vbasis E)`_i by apply/sepK_E/memt_nth.
by move/adjoin_separableP; apply; rewrite rpredZ ?memv_adjoin.
Qed.
Lemma purely_inseparableP {K E} :
reflect (forall y, y \in E -> purely_inseparable_element K y)
(purely_inseparable K E).
Proof.
apply/(iffP idP)=> [/allP|] sep'K_E; last by apply/allP=> x /vbasis_mem/sep'K_E.
move=> y /coord_vbasis->; apply/inseparable_sum=> i _.
have: purely_inseparable_element K (vbasis E)`_i by apply/sep'K_E/memt_nth.
case/purely_inseparable_elementP_pchar=> n pcharLn K_Ein.
by apply/purely_inseparable_elementP_pchar; exists n; rewrite // exprZn rpredZ.
Qed.
Lemma adjoin_separable_eq K x : separable_element K x = separable K <<K; x>>%VS.
Proof. exact: sameP adjoin_separableP separableP. Qed.
Lemma separable_inseparable_decomposition E K :
{x | x \in E /\ separable_element K x & purely_inseparable <<K; x>> E}.
Proof.
without loss sKE: K / (K <= E)%VS.
case/(_ _ (capvSr K E)) => x [Ex sepKEx] /purely_inseparableP sep'KExE.
exists x; first by split; last exact/(separable_elementS _ sepKEx)/capvSl.
apply/purely_inseparableP=> y /sep'KExE; apply: sub_inseparable.
exact/adjoinSl/capvSl.
pose E_ i := (vbasis E)`_i; pose fP i := separable_exponent_pchar K (E_ i).
pose f i := E_ i ^+ ex_minn (fP i); pose s := mkseq f (\dim E).
pose K' := <<K & s>>%VS.
have sepKs: all (separable_element K) s.
by rewrite all_map /f; apply/allP=> i _ /=; case: ex_minnP => m /andP[].
have [x sepKx defKx]: {x | x \in E /\ separable_element K x & K' = <<K; x>>%VS}.
have: all [in E] s.
rewrite all_map; apply/allP=> i; rewrite mem_iota => ltis /=.
by rewrite rpredX // vbasis_mem // memt_nth.
rewrite {}/K'; elim/last_ind: s sepKs => [|s t IHs].
by exists 0; [rewrite base_separable mem0v | rewrite adjoin_nil addv0].
rewrite adjoin_rcons !all_rcons => /andP[sepKt sepKs] /andP[/= Et Es].
have{IHs sepKs Es} [y [Ey sepKy] ->{s}] := IHs sepKs Es.
have /sig_eqW[x defKx] := Primitive_Element_Theorem t sepKy.
exists x; [split | exact: defKx].
suffices: (<<K; x>> <= E)%VS by case/FadjoinP.
by rewrite -defKx !(sameP FadjoinP andP) sKE Ey Et.
apply/adjoin_separableP=> z; rewrite -defKx => Kyt_z.
apply: adjoin_separable sepKy _; apply: adjoin_separableP Kyt_z.
exact: separable_elementS (subv_adjoin K y) sepKt.
exists x; rewrite // -defKx; apply/(all_nthP 0)=> i; rewrite size_tuple => ltiE.
apply/purely_inseparable_elementP_pchar.
exists (ex_minn (fP i)); first by case: ex_minnP => n /andP[].
by apply/seqv_sub_adjoin/map_f; rewrite mem_iota.
Qed.
Definition separable_generator K E : L :=
s2val (locked (separable_inseparable_decomposition E K)).
Lemma separable_generator_mem E K : separable_generator K E \in E.
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generatorP E K : separable_element K (separable_generator K E).
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generator_maximal E K :
purely_inseparable <<K; separable_generator K E>> E.
Proof. by rewrite /separable_generator; case: (locked _). Qed.
Lemma sub_adjoin_separable_generator E K :
separable K E -> (E <= <<K; separable_generator K E>>)%VS.
Proof.
move/separableP=> sepK_E; apply/subvP=> v Ev.
rewrite -separable_inseparable_element.
have /purely_inseparableP-> // := separable_generator_maximal E K.
by rewrite (separable_elementS _ (sepK_E _ Ev)) // subv_adjoin.
Qed.
Lemma eq_adjoin_separable_generator E K :
separable K E -> (K <= E)%VS ->
E = <<K; separable_generator K E>>%VS :> {vspace _}.
Proof.
move=> sepK_E sKE; apply/eqP; rewrite eqEsubv sub_adjoin_separable_generator //.
by apply/FadjoinP/andP; rewrite sKE separable_generator_mem.
Qed.
Lemma separable_refl K : separable K K.
Proof. exact/separableP/base_separable. Qed.
Lemma separable_trans M K E : separable K M -> separable M E -> separable K E.
Proof.
move/sub_adjoin_separable_generator.
set x := separable_generator K M => sMKx /separableP sepM_E.
apply/separableP => w /sepM_E/(separable_elementS sMKx).
case/strong_Primitive_Element_Theorem => _ _ -> //.
exact: separable_generatorP.
Qed.
Lemma separableS K1 K2 E2 E1 :
(K1 <= K2)%VS -> (E2 <= E1)%VS -> separable K1 E1 -> separable K2 E2.
Proof.
move=> sK12 /subvP sE21 /separableP sepK1_E1.
by apply/separableP=> y /sE21/sepK1_E1/(separable_elementS sK12).
Qed.
Lemma separableSl K M E : (K <= M)%VS -> separable K E -> separable M E.
Proof. by move/separableS; apply. Qed.
Lemma separableSr K M E : (M <= E)%VS -> separable K E -> separable K M.
Proof. exact: separableS. Qed.
Lemma separable_Fadjoin_seq K rs :
all (separable_element K) rs -> separable K <<K & rs>>.
Proof.
elim/last_ind: rs => [|s x IHs] in K *.
by rewrite adjoin_nil subfield_closed separable_refl.
rewrite all_rcons adjoin_rcons => /andP[sepKx /IHs/separable_trans-> //].
by rewrite -adjoin_separable_eq (separable_elementS _ sepKx) ?subv_adjoin_seq.
Qed.
Lemma purely_inseparable_refl K : purely_inseparable K K.
Proof. by apply/purely_inseparableP; apply: base_inseparable. Qed.
Lemma purely_inseparable_trans M K E :
purely_inseparable K M -> purely_inseparable M E -> purely_inseparable K E.
Proof.
have insepP := purely_inseparableP => /insepP insepK_M /insepP insepM_E.
have insepPe := purely_inseparable_elementP_pchar.
apply/insepP=> x /insepM_E/insepPe[n pcharLn /insepK_M/insepPe[m pcharLm Kxnm]].
by apply/insepPe; exists (n * m)%N; rewrite ?exprM // pnatM pcharLn pcharLm.
Qed.
End Separable.
Arguments separable_elementP {F L K x}.
Arguments separablePn_pchar {F L K x}.
Arguments Derivation_separableP {F L K x}.
Arguments adjoin_separableP {F L K x}.
Arguments purely_inseparable_elementP_pchar {F L K x}.
Arguments separableP {F L K E}.
Arguments purely_inseparableP {F L K E}.
|
vcharacter.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient finalg action gproduct.
From mathcomp Require Import zmodp commutator cyclic center pgroup sylow.
From mathcomp Require Import frobenius vector ssrnum ssrint archimedean intdiv.
From mathcomp Require Import algC algnum classfun character integral_char.
(******************************************************************************)
(* This file provides basic notions of virtual character theory: *)
(* 'Z[S, A] == collective predicate for the phi that are Z-linear *)
(* combinations of elements of S : seq 'CF(G) and have *)
(* support in A : {set gT}. *)
(* 'Z[S] == collective predicate for the Z-linear combinations of *)
(* elements of S. *)
(* 'Z[irr G] == the collective predicate for virtual characters. *)
(* dirr G == the collective predicate for normal virtual characters, *)
(* i.e., virtual characters of norm 1: *)
(* mu \in dirr G <=> m \in 'Z[irr G] and '[mu] = 1 *)
(* <=> mu or - mu \in irr G. *)
(* --> othonormal subsets of 'Z[irr G] are contained in dirr G. *)
(* dIirr G == an index type for normal virtual characters. *)
(* dchi i == the normal virtual character of index i. *)
(* of_irr i == the (unique) irreducible constituent of dchi i: *)
(* dchi i = 'chi_(of_irr i) or - 'chi_(of_irr i). *)
(* ndirr i == the index of - dchi i. *)
(* dirr1 G == the normal virtual character index of 1 : 'CF(G), the *)
(* principal character. *)
(* dirr_dIirr j f == the index i (or dirr1 G if it does not exist) such that *)
(* dchi i = f j. *)
(* dirr_constt phi == the normal virtual character constituents of phi: *)
(* i \in dirr_constt phi <=> [dchi i, phi] > 0. *)
(* to_dirr phi i == the normal virtual character constituent of phi with an *)
(* irreducible constituent i, when i \in irr_constt phi. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section Basics.
Variables (gT : finGroupType) (B : {set gT}) (S : seq 'CF(B)) (A : {set gT}).
Definition Zchar : {pred 'CF(B)} :=
[pred phi in 'CF(B, A) | dec_Cint_span (in_tuple S) phi].
Lemma cfun0_zchar : 0 \in Zchar.
Proof.
rewrite inE mem0v; apply/sumboolP; exists 0.
by rewrite big1 // => i _; rewrite ffunE.
Qed.
Fact Zchar_zmod : zmod_closed Zchar.
Proof.
split; first exact: cfun0_zchar.
move=> phi xi /andP[Aphi /sumboolP[a Da]] /andP[Axi /sumboolP[b Db]].
rewrite inE rpredB // Da Db -sumrB; apply/sumboolP; exists (a - b).
by apply: eq_bigr => i _; rewrite -mulrzBr !ffunE.
Qed.
HB.instance Definition _ := GRing.isZmodClosed.Build (classfun B) Zchar
Zchar_zmod.
Lemma scale_zchar a phi : a \in Num.int -> phi \in Zchar -> a *: phi \in Zchar.
Proof. by case/intrP=> m -> Zphi; rewrite scaler_int rpredMz. Qed.
End Basics.
Notation "''Z[' S , A ]" := (Zchar S A) (format "''Z[' S , A ]") : group_scope.
Notation "''Z[' S ]" := 'Z[S, setT] (format "''Z[' S ]") : group_scope.
Section Zchar.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (A B : {set gT}) (S : seq 'CF(G)).
Lemma zchar_split S A phi :
phi \in 'Z[S, A] = (phi \in 'Z[S]) && (phi \in 'CF(G, A)).
Proof. by rewrite !inE cfun_onT andbC. Qed.
Lemma zcharD1E phi S : (phi \in 'Z[S, G^#]) = (phi \in 'Z[S]) && (phi 1%g == 0).
Proof. by rewrite zchar_split cfunD1E. Qed.
Lemma zcharD1 phi S A :
(phi \in 'Z[S, A^#]) = (phi \in 'Z[S, A]) && (phi 1%g == 0).
Proof. by rewrite zchar_split cfun_onD1 andbA -zchar_split. Qed.
Lemma zcharW S A : {subset 'Z[S, A] <= 'Z[S]}.
Proof. by move=> phi; rewrite zchar_split => /andP[]. Qed.
Lemma zchar_on S A : {subset 'Z[S, A] <= 'CF(G, A)}.
Proof. by move=> phi /andP[]. Qed.
Lemma zchar_onS A B S : A \subset B -> {subset 'Z[S, A] <= 'Z[S, B]}.
Proof.
move=> sAB phi; rewrite zchar_split (zchar_split _ B) => /andP[->].
exact: cfun_onS.
Qed.
Lemma zchar_onG S : 'Z[S, G] =i 'Z[S].
Proof. by move=> phi; rewrite zchar_split cfun_onG andbT. Qed.
Lemma irr_vchar_on A : {subset 'Z[irr G, A] <= 'CF(G, A)}.
Proof. exact: zchar_on. Qed.
Lemma support_zchar S A phi : phi \in 'Z[S, A] -> support phi \subset A.
Proof. by move/zchar_on; rewrite cfun_onE. Qed.
Lemma mem_zchar_on S A phi :
phi \in 'CF(G, A) -> phi \in S -> phi \in 'Z[S, A].
Proof.
move=> Aphi /(@tnthP _ _ (in_tuple S))[i Dphi]; rewrite inE /= {}Aphi {phi}Dphi.
apply/sumboolP; exists [ffun j => (j == i)%:Z].
rewrite (bigD1 i) //= ffunE eqxx (tnth_nth 0) big1 ?addr0 // => j i'j.
by rewrite ffunE (negPf i'j).
Qed.
(* A special lemma is needed because trivial fails to use the cfun_onT Hint. *)
Lemma mem_zchar S phi : phi \in S -> phi \in 'Z[S].
Proof. by move=> Sphi; rewrite mem_zchar_on ?cfun_onT. Qed.
Lemma zchar_nth_expansion S A phi :
phi \in 'Z[S, A] ->
{z | forall i, z i \in Num.int & phi = \sum_(i < size S) z i *: S`_i}.
Proof.
case/andP=> _ /sumboolP/sig_eqW[/= z ->]; exists (intr \o z) => //=.
by apply: eq_bigr => i _; rewrite scaler_int.
Qed.
Lemma zchar_tuple_expansion n (S : n.-tuple 'CF(G)) A phi :
phi \in 'Z[S, A] ->
{z | forall i, z i \in Num.int & phi = \sum_(i < n) z i *: S`_i}.
Proof. by move/zchar_nth_expansion; rewrite size_tuple. Qed.
(* A pure seq version with the extra hypothesis of S's unicity. *)
Lemma zchar_expansion S A phi : uniq S ->
phi \in 'Z[S, A] ->
{z | forall xi, z xi \in Num.int & phi = \sum_(xi <- S) z xi *: xi}.
Proof.
move=> Suniq /zchar_nth_expansion[z Zz ->] /=.
pose zS xi := oapp z 0 (insub (index xi S)).
exists zS => [xi | ]; rewrite {}/zS; first by case: (insub _) => /=.
rewrite (big_nth 0) big_mkord; apply: eq_bigr => i _; congr (_ *: _).
by rewrite index_uniq // valK.
Qed.
Lemma zchar_span S A : {subset 'Z[S, A] <= <<S>>%VS}.
Proof.
move=> _ /zchar_nth_expansion[z Zz ->] /=.
by apply: rpred_sum => i _; rewrite rpredZ // memv_span ?mem_nth.
Qed.
Lemma zchar_trans S1 S2 A B :
{subset S1 <= 'Z[S2, B]} -> {subset 'Z[S1, A] <= 'Z[S2, A]}.
Proof.
move=> sS12 phi; rewrite !(zchar_split _ A) andbC => /andP[->]; rewrite andbT.
case/zchar_nth_expansion=> z Zz ->; apply: rpred_sum => i _.
by rewrite scale_zchar // (@zcharW _ B) ?sS12 ?mem_nth.
Qed.
Lemma zchar_trans_on S1 S2 A :
{subset S1 <= 'Z[S2, A]} -> {subset 'Z[S1] <= 'Z[S2, A]}.
Proof.
move=> sS12 _ /zchar_nth_expansion[z Zz ->]; apply: rpred_sum => i _.
by rewrite scale_zchar // sS12 ?mem_nth.
Qed.
Lemma zchar_sub_irr S A :
{subset S <= 'Z[irr G]} -> {subset 'Z[S, A] <= 'Z[irr G, A]}.
Proof. exact: zchar_trans. Qed.
Lemma zchar_subset S1 S2 A :
{subset S1 <= S2} -> {subset 'Z[S1, A] <= 'Z[S2, A]}.
Proof.
move=> sS12; apply: zchar_trans setT _ => // f /sS12 S2f.
by rewrite mem_zchar.
Qed.
Lemma zchar_subseq S1 S2 A :
subseq S1 S2 -> {subset 'Z[S1, A] <= 'Z[S2, A]}.
Proof. by move/mem_subseq; apply: zchar_subset. Qed.
Lemma zchar_filter S A (p : pred 'CF(G)) :
{subset 'Z[filter p S, A] <= 'Z[S, A]}.
Proof. by apply: zchar_subset=> f; apply/mem_subseq/filter_subseq. Qed.
End Zchar.
Section VChar.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (A B : {set gT}) (phi chi : 'CF(G)) (S : seq 'CF(G)).
Lemma char_vchar chi : chi \is a character -> chi \in 'Z[irr G].
Proof.
case/char_sum_irr=> r ->; apply: rpred_sum => i _.
by rewrite mem_zchar ?mem_tnth.
Qed.
Lemma irr_vchar i : 'chi[G]_i \in 'Z[irr G].
Proof. exact/char_vchar/irr_char. Qed.
Lemma cfun1_vchar : 1 \in 'Z[irr G]. Proof. by rewrite -irr0 irr_vchar. Qed.
Lemma vcharP phi :
reflect (exists2 chi1, chi1 \is a character
& exists2 chi2, chi2 \is a character & phi = chi1 - chi2)
(phi \in 'Z[irr G]).
Proof.
apply: (iffP idP) => [| [a Na [b Nb ->]]]; last by rewrite rpredB ?char_vchar.
case/zchar_tuple_expansion=> z Zz ->; rewrite (bigID (fun i => 0 <= z i)) /=.
set chi1 := \sum_(i | _) _; set nchi2 := \sum_(i | _) _.
exists chi1; last exists (- nchi2); last by rewrite opprK.
apply: rpred_sum => i zi_ge0; rewrite -tnth_nth rpredZ_nat ?irr_char //.
by rewrite natrEint Zz.
rewrite -sumrN rpred_sum // => i zi_lt0; rewrite -scaleNr -tnth_nth.
rewrite rpredZ_nat ?irr_char // natrEint rpredN Zz oppr_ge0 ltW //.
by rewrite real_ltNge ?Rreal_int.
Qed.
Lemma Aint_vchar phi x : phi \in 'Z[irr G] -> phi x \in Aint.
Proof.
case/vcharP=> [chi1 Nchi1 [chi2 Nchi2 ->]].
by rewrite !cfunE rpredB ?Aint_char.
Qed.
Lemma Cint_vchar1 phi : phi \in 'Z[irr G] -> phi 1%g \in Num.int.
Proof.
case/vcharP=> phi1 Nphi1 [phi2 Nphi2 ->].
by rewrite !cfunE rpredB // rpred_nat_num ?Cnat_char1.
Qed.
Lemma Cint_cfdot_vchar_irr i phi :
phi \in 'Z[irr G] -> '[phi, 'chi_i] \in Num.int.
Proof.
case/vcharP=> chi1 Nchi1 [chi2 Nchi2 ->].
by rewrite cfdotBl rpredB // rpred_nat_num ?Cnat_cfdot_char_irr.
Qed.
Lemma cfdot_vchar_r phi psi :
psi \in 'Z[irr G] -> '[phi, psi] = \sum_i '[phi, 'chi_i] * '[psi, 'chi_i].
Proof.
move=> Zpsi; rewrite cfdot_sum_irr; apply: eq_bigr => i _; congr (_ * _).
by rewrite aut_intr ?Cint_cfdot_vchar_irr.
Qed.
Lemma Cint_cfdot_vchar :
{in 'Z[irr G] &, forall phi psi, '[phi, psi] \in Num.int}.
Proof.
move=> phi psi Zphi Zpsi; rewrite /= cfdot_vchar_r // rpred_sum // => k _.
by rewrite rpredM ?Cint_cfdot_vchar_irr.
Qed.
Lemma Cnat_cfnorm_vchar : {in 'Z[irr G], forall phi, '[phi] \in Num.nat}.
Proof. by move=> phi Zphi; rewrite /= natrEint cfnorm_ge0 Cint_cfdot_vchar. Qed.
Fact vchar_mulr_closed : mulr_closed 'Z[irr G].
Proof.
split; first exact: cfun1_vchar.
move=> _ _ /vcharP[xi1 Nxi1 [xi2 Nxi2 ->]] /vcharP[xi3 Nxi3 [xi4 Nxi4 ->]].
by rewrite mulrBl !mulrBr !(rpredB, rpredD) // char_vchar ?rpredM.
Qed.
HB.instance Definition _ := GRing.isMulClosed.Build (classfun G) 'Z[irr G]
vchar_mulr_closed.
Lemma mul_vchar A :
{in 'Z[irr G, A] &, forall phi psi, phi * psi \in 'Z[irr G, A]}.
Proof.
move=> phi psi; rewrite zchar_split => /andP[Zphi Aphi] /zcharW Zpsi.
rewrite zchar_split rpredM //; apply/cfun_onP=> x A'x.
by rewrite cfunE (cfun_onP Aphi) ?mul0r.
Qed.
Section CfdotPairwiseOrthogonal.
Variables (M : {group gT}) (S : seq 'CF(G)) (nu : 'CF(G) -> 'CF(M)).
Hypotheses (Inu : {in 'Z[S] &, isometry nu}) (oSS : pairwise_orthogonal S).
Let freeS := orthogonal_free oSS.
Let uniqS : uniq S := free_uniq freeS.
Let Z_S : {subset S <= 'Z[S]}. Proof. by move=> phi; apply: mem_zchar. Qed.
Let notS0 : 0 \notin S. Proof. by case/andP: oSS. Qed.
Let dotSS := proj2 (pairwise_orthogonalP oSS).
Lemma map_pairwise_orthogonal : pairwise_orthogonal (map nu S).
Proof.
have inj_nu: {in S &, injective nu}.
move=> phi psi Sphi Spsi /= eq_nu; apply: contraNeq (memPn notS0 _ Sphi).
by rewrite -cfnorm_eq0 -Inu ?Z_S // {2}eq_nu Inu ?Z_S // => /dotSS->.
have notSnu0: 0 \notin map nu S.
apply: contra notS0 => /mapP[phi Sphi /esym/eqP].
by rewrite -cfnorm_eq0 Inu ?Z_S // cfnorm_eq0 => /eqP <-.
apply/pairwise_orthogonalP; split; first by rewrite /= notSnu0 map_inj_in_uniq.
move=> _ _ /mapP[phi Sphi ->] /mapP[psi Spsi ->].
by rewrite (inj_in_eq inj_nu) // Inu ?Z_S //; apply: dotSS.
Qed.
Lemma cfproj_sum_orthogonal P z phi :
phi \in S ->
'[\sum_(xi <- S | P xi) z xi *: nu xi, nu phi]
= if P phi then z phi * '[phi] else 0.
Proof.
move=> Sphi; have defS := perm_to_rem Sphi.
rewrite cfdot_suml (perm_big _ defS) big_cons /= cfdotZl Inu ?Z_S //.
rewrite big1_seq ?addr0 // => xi; rewrite mem_rem_uniq ?inE //.
by case/and3P=> _ neq_xi Sxi; rewrite cfdotZl Inu ?Z_S // dotSS ?mulr0.
Qed.
Lemma cfdot_sum_orthogonal z1 z2 :
'[\sum_(xi <- S) z1 xi *: nu xi, \sum_(xi <- S) z2 xi *: nu xi]
= \sum_(xi <- S) z1 xi * (z2 xi)^* * '[xi].
Proof.
rewrite cfdot_sumr; apply: eq_big_seq => phi Sphi.
by rewrite cfdotZr cfproj_sum_orthogonal // mulrCA mulrA.
Qed.
Lemma cfnorm_sum_orthogonal z :
'[\sum_(xi <- S) z xi *: nu xi] = \sum_(xi <- S) `|z xi| ^+ 2 * '[xi].
Proof.
by rewrite cfdot_sum_orthogonal; apply: eq_bigr => xi _; rewrite normCK.
Qed.
Lemma cfnorm_orthogonal : '[\sum_(xi <- S) nu xi] = \sum_(xi <- S) '[xi].
Proof.
rewrite -(eq_bigr _ (fun _ _ => scale1r _)) cfnorm_sum_orthogonal.
by apply: eq_bigr => xi; rewrite normCK conjC1 !mul1r.
Qed.
End CfdotPairwiseOrthogonal.
Lemma orthogonal_span S phi :
pairwise_orthogonal S -> phi \in <<S>>%VS ->
{z | z = fun xi => '[phi, xi] / '[xi] & phi = \sum_(xi <- S) z xi *: xi}.
Proof.
move=> oSS /free_span[|c -> _]; first exact: orthogonal_free.
set z := fun _ => _ : algC; exists z => //; apply: eq_big_seq => u Su.
rewrite /z cfproj_sum_orthogonal // mulfK // cfnorm_eq0.
by rewrite (memPn _ u Su); case/andP: oSS.
Qed.
Section CfDotOrthonormal.
Variables (M : {group gT}) (S : seq 'CF(G)) (nu : 'CF(G) -> 'CF(M)).
Hypotheses (Inu : {in 'Z[S] &, isometry nu}) (onS : orthonormal S).
Let oSS := orthonormal_orthogonal onS.
Let freeS := orthogonal_free oSS.
Let nS1 : {in S, forall phi, '[phi] = 1}.
Proof. by move=> phi Sphi; case/orthonormalP: onS => _ -> //; rewrite eqxx. Qed.
Lemma map_orthonormal : orthonormal (map nu S).
Proof.
rewrite !orthonormalE map_pairwise_orthogonal // andbT.
by apply/allP=> _ /mapP[xi Sxi ->]; rewrite /= Inu ?nS1 // mem_zchar.
Qed.
Lemma cfproj_sum_orthonormal z phi :
phi \in S -> '[\sum_(xi <- S) z xi *: nu xi, nu phi] = z phi.
Proof. by move=> Sphi; rewrite cfproj_sum_orthogonal // nS1 // mulr1. Qed.
Lemma cfdot_sum_orthonormal z1 z2 :
'[\sum_(xi <- S) z1 xi *: xi, \sum_(xi <- S) z2 xi *: xi]
= \sum_(xi <- S) z1 xi * (z2 xi)^*.
Proof.
rewrite cfdot_sum_orthogonal //; apply: eq_big_seq => phi /nS1->.
by rewrite mulr1.
Qed.
Lemma cfnorm_sum_orthonormal z :
'[\sum_(xi <- S) z xi *: nu xi] = \sum_(xi <- S) `|z xi| ^+ 2.
Proof.
rewrite cfnorm_sum_orthogonal //.
by apply: eq_big_seq => xi /nS1->; rewrite mulr1.
Qed.
Lemma cfnorm_map_orthonormal : '[\sum_(xi <- S) nu xi] = (size S)%:R.
Proof.
by rewrite cfnorm_orthogonal // (eq_big_seq _ nS1) big_tnth sumr_const card_ord.
Qed.
Lemma orthonormal_span phi :
phi \in <<S>>%VS ->
{z | z = fun xi => '[phi, xi] & phi = \sum_(xi <- S) z xi *: xi}.
Proof.
case/orthogonal_span=> // _ -> {2}->; set z := fun _ => _ : algC.
by exists z => //; apply: eq_big_seq => xi /nS1->; rewrite divr1.
Qed.
End CfDotOrthonormal.
Lemma cfnorm_orthonormal S :
orthonormal S -> '[\sum_(xi <- S) xi] = (size S)%:R.
Proof. exact: cfnorm_map_orthonormal. Qed.
Lemma vchar_orthonormalP S :
{subset S <= 'Z[irr G]} ->
reflect (exists I : {set Iirr G}, exists b : Iirr G -> bool,
perm_eq S [seq (-1) ^+ b i *: 'chi_i | i in I])
(orthonormal S).
Proof.
move=> vcS; apply: (equivP orthonormalP).
split=> [[uniqS oSS] | [I [b defS]]]; last first.
split=> [|xi1 xi2]; rewrite ?(perm_mem defS).
rewrite (perm_uniq defS) map_inj_uniq ?enum_uniq // => i j /eqP.
by rewrite eq_signed_irr => /andP[_ /eqP].
case/mapP=> [i _ ->] /mapP[j _ ->]; rewrite eq_signed_irr.
rewrite cfdotZl cfdotZr rmorph_sign mulrA cfdot_irr -signr_addb mulr_natr.
by rewrite mulrb andbC; case: eqP => //= ->; rewrite addbb eqxx.
pose I := [set i | ('chi_i \in S) || (- 'chi_i \in S)].
pose b i := - 'chi_i \in S; exists I, b.
apply: uniq_perm => // [|xi].
rewrite map_inj_uniq ?enum_uniq // => i j /eqP.
by rewrite eq_signed_irr => /andP[_ /eqP].
apply/idP/mapP=> [Sxi | [i Ii ->{xi}]]; last first.
move: Ii; rewrite mem_enum inE orbC -/(b i).
by case b_i: (b i); rewrite (scale1r, scaleN1r).
have: '[xi] = 1 by rewrite oSS ?eqxx.
have vc_xi := vcS _ Sxi; rewrite cfdot_sum_irr.
case/natr_sum_eq1 => [i _ | i [_ /eqP norm_xi_i xi_i'_0]].
by rewrite -normCK rpredX // natr_norm_int ?Cint_cfdot_vchar_irr.
suffices def_xi: xi = (-1) ^+ b i *: 'chi_i.
exists i; rewrite // mem_enum inE -/(b i) orbC.
by case: (b i) def_xi Sxi => // ->; rewrite scale1r.
move: Sxi; rewrite [xi]cfun_sum_cfdot (bigD1 i) //.
rewrite big1 //= ?addr0 => [|j ne_ji]; last first.
apply/eqP; rewrite scaler_eq0 -normr_eq0 -[_ == 0](expf_eq0 _ 2) normCK.
by rewrite xi_i'_0 ?eqxx.
have:= norm_xi_i; rewrite (aut_intr _ (Cint_cfdot_vchar_irr _ _)) //.
rewrite -subr_eq0 subr_sqr_1 mulf_eq0 subr_eq0 addr_eq0 /b scaler_sign.
case/pred2P=> ->; last by rewrite scaleN1r => ->.
rewrite scale1r => Sxi; case: ifP => // SNxi.
have:= oSS _ _ Sxi SNxi; rewrite cfdotNr cfdot_irr eqxx; case: eqP => // _.
by move/eqP; rewrite oppr_eq0 oner_eq0.
Qed.
Lemma vchar_norm1P phi :
phi \in 'Z[irr G] -> '[phi] = 1 ->
exists b : bool, exists i : Iirr G, phi = (-1) ^+ b *: 'chi_i.
Proof.
move=> Zphi phiN1.
have: orthonormal phi by rewrite /orthonormal/= phiN1 eqxx.
case/vchar_orthonormalP=> [xi /predU1P[->|] // | I [b def_phi]].
have: phi \in (phi : seq _) := mem_head _ _.
by rewrite (perm_mem def_phi) => /mapP[i _ ->]; exists (b i), i.
Qed.
Lemma zchar_small_norm phi n :
phi \in 'Z[irr G] -> '[phi] = n%:R -> (n < 4)%N ->
{S : n.-tuple 'CF(G) |
[/\ orthonormal S, {subset S <= 'Z[irr G]} & phi = \sum_(xi <- S) xi]}.
Proof.
move=> Zphi def_n lt_n_4.
pose S := [seq '[phi, 'chi_i] *: 'chi_i | i in irr_constt phi].
have def_phi: phi = \sum_(xi <- S) xi.
rewrite big_image big_mkcond {1}[phi]cfun_sum_cfdot.
by apply: eq_bigr => i _; rewrite if_neg; case: eqP => // ->; rewrite scale0r.
have orthS: orthonormal S.
apply/orthonormalP; split=> [|_ _ /mapP[i phi_i ->] /mapP[j _ ->]].
rewrite map_inj_in_uniq ?enum_uniq // => i j; rewrite mem_enum => phi_i _.
by move/eqP; rewrite eq_scaled_irr (negbTE phi_i) => /andP[_ /= /eqP].
rewrite eq_scaled_irr cfdotZl cfdotZr cfdot_irr mulrA mulr_natr mulrb.
rewrite mem_enum in phi_i; rewrite (negbTE phi_i) andbC; case: eqP => // <-.
have /natrP[m def_m] := natr_norm_int (Cint_cfdot_vchar_irr i Zphi).
apply/eqP; rewrite eqxx /= -normCK def_m -natrX eqr_nat eqn_leq lt0n.
rewrite expn_eq0 andbT -eqC_nat -def_m normr_eq0 [~~ _]phi_i andbT.
rewrite (leq_exp2r _ 1) // -ltnS -(@ltn_exp2r _ _ 2) //.
apply: leq_ltn_trans lt_n_4; rewrite -leC_nat -def_n natrX.
rewrite cfdot_sum_irr (bigD1 i) //= -normCK def_m addrC -subr_ge0 addrK.
by rewrite sumr_ge0 // => ? _; apply: mul_conjC_ge0.
have <-: size S = n.
by apply/eqP; rewrite -eqC_nat -def_n def_phi cfnorm_orthonormal.
exists (in_tuple S); split=> // _ /mapP[i _ ->].
by rewrite scale_zchar ?irr_vchar // Cint_cfdot_vchar_irr.
Qed.
Lemma vchar_norm2 phi :
phi \in 'Z[irr G, G^#] -> '[phi] = 2 ->
exists i, exists2 j, j != i & phi = 'chi_i - 'chi_j.
Proof.
rewrite zchar_split cfunD1E => /andP[Zphi phi1_0].
case/zchar_small_norm => // [[[|chi [|xi [|?]]] //= S2]].
case=> /andP[/and3P[Nchi Nxi _] /= ochi] /allP/and3P[Zchi Zxi _].
rewrite big_cons big_seq1 => def_phi.
have [b [i def_chi]] := vchar_norm1P Zchi (eqP Nchi).
have [c [j def_xi]] := vchar_norm1P Zxi (eqP Nxi).
have neq_ji: j != i.
apply: contraTneq ochi; rewrite !andbT def_chi def_xi => ->.
rewrite cfdotZl cfdotZr rmorph_sign cfnorm_irr mulr1 -signr_addb.
by rewrite signr_eq0.
have neq_bc: b != c.
apply: contraTneq phi1_0; rewrite def_phi def_chi def_xi => ->.
rewrite -scalerDr !cfunE mulf_eq0 signr_eq0 eq_le lt_geF //.
by rewrite ltr_pDl ?irr1_gt0.
rewrite {}def_phi {}def_chi {}def_xi !scaler_sign.
case: b c neq_bc => [|] [|] // _; last by exists i, j.
by exists j, i; rewrite 1?eq_sym // addrC.
Qed.
End VChar.
Section Isometries.
Variables (gT : finGroupType) (L G : {group gT}) (S : seq 'CF(L)).
Implicit Type nu : {additive 'CF(L) -> 'CF(G)}.
Lemma Zisometry_of_cfnorm (tauS : seq 'CF(G)) :
pairwise_orthogonal S -> pairwise_orthogonal tauS ->
map cfnorm tauS = map cfnorm S -> {subset tauS <= 'Z[irr G]} ->
{tau : {linear 'CF(L) -> 'CF(G)} | map tau S = tauS
& {in 'Z[S], isometry tau, to 'Z[irr G]}}.
Proof.
move=> oSS oTT /isometry_of_cfnorm[||tau defT Itau] // Z_T; exists tau => //.
split=> [|_ /zchar_nth_expansion[u Zu ->]].
by apply: sub_in2 Itau; apply: zchar_span.
rewrite big_seq linear_sum rpred_sum // => xi Sxi.
by rewrite linearZ scale_zchar ?Z_T // -defT map_f ?mem_nth.
Qed.
Lemma Zisometry_of_iso f :
free S -> {in S, isometry f, to 'Z[irr G]} ->
{tau : {linear 'CF(L) -> 'CF(G)} | {in S, tau =1 f}
& {in 'Z[S], isometry tau, to 'Z[irr G]}}.
Proof.
move=> freeS [If Zf]; have [tau Dtau Itau] := isometry_of_free freeS If.
exists tau => //; split; first by apply: sub_in2 Itau; apply: zchar_span.
move=> _ /zchar_nth_expansion[a Za ->]; rewrite linear_sum rpred_sum // => i _.
by rewrite linearZ rpredZ_int ?Dtau ?Zf ?mem_nth.
Qed.
Lemma Zisometry_inj A nu :
{in 'Z[S, A] &, isometry nu} -> {in 'Z[S, A] &, injective nu}.
Proof. by move/isometry_raddf_inj; apply; apply: rpredB. Qed.
Lemma isometry_in_zchar nu : {in S &, isometry nu} -> {in 'Z[S] &, isometry nu}.
Proof.
move=> Inu _ _ /zchar_nth_expansion[u Zu ->] /zchar_nth_expansion[v Zv ->].
rewrite !raddf_sum; apply: eq_bigr => j _ /=.
rewrite !cfdot_suml; apply: eq_bigr => i _.
by rewrite !raddfZ_int //= !cfdotZl !cfdotZr Inu ?mem_nth.
Qed.
End Isometries.
Section AutVchar.
Variables (u : {rmorphism algC -> algC}) (gT : finGroupType) (G : {group gT}).
Local Notation "alpha ^u" := (cfAut u alpha).
Implicit Type (S : seq 'CF(G)) (phi chi : 'CF(G)).
Lemma cfAut_zchar S A psi :
cfAut_closed u S -> psi \in 'Z[S, A] -> psi^u \in 'Z[S, A].
Proof.
rewrite zchar_split => SuS /andP[/zchar_nth_expansion[z Zz Dpsi] Apsi].
rewrite zchar_split cfAut_on {}Apsi {psi}Dpsi rmorph_sum rpred_sum //= => i _.
by rewrite cfAutZ_Cint // scale_zchar // mem_zchar ?SuS ?mem_nth.
Qed.
Lemma cfAut_vchar A psi : psi \in 'Z[irr G, A] -> psi^u \in 'Z[irr G, A].
Proof. by apply: cfAut_zchar; apply: irr_aut_closed. Qed.
Lemma sub_aut_zchar S A psi :
{subset S <= 'Z[irr G]} -> psi \in 'Z[S, A] -> psi^u \in 'Z[S, A] ->
psi - psi^u \in 'Z[S, A^#].
Proof.
move=> Z_S Spsi Spsi_u; rewrite zcharD1 !cfunE subr_eq0 rpredB //=.
by rewrite aut_intr // Cint_vchar1 // (zchar_trans Z_S) ?(zcharW Spsi).
Qed.
Lemma conjC_vcharAut chi x : chi \in 'Z[irr G] -> (u (chi x))^* = u (chi x)^*.
Proof.
case/vcharP=> chi1 Nchi1 [chi2 Nchi2 ->].
by rewrite !cfunE !rmorphB !conjC_charAut.
Qed.
Lemma cfdot_aut_vchar phi chi :
chi \in 'Z[irr G] -> '[phi^u , chi^u] = u '[phi, chi].
Proof.
by case/vcharP=> chi1 Nchi1 [chi2 Nchi2 ->]; rewrite !raddfB /= !cfdot_aut_char.
Qed.
Lemma vchar_aut A chi : (chi^u \in 'Z[irr G, A]) = (chi \in 'Z[irr G, A]).
Proof.
rewrite !(zchar_split _ A) cfAut_on; congr (_ && _).
apply/idP/idP=> [Zuchi|]; last exact: cfAut_vchar.
rewrite [chi]cfun_sum_cfdot rpred_sum // => i _.
rewrite scale_zchar ?irr_vchar //.
by rewrite -(intr_aut u) -cfdot_aut_irr -aut_IirrE Cint_cfdot_vchar_irr.
Qed.
End AutVchar.
Definition cfConjC_vchar := cfAut_vchar conjC.
Section MoreVchar.
Variables (gT : finGroupType) (G H : {group gT}).
Lemma cfRes_vchar phi : phi \in 'Z[irr G] -> 'Res[H] phi \in 'Z[irr H].
Proof.
case/vcharP=> xi1 Nx1 [xi2 Nxi2 ->].
by rewrite raddfB rpredB ?char_vchar ?cfRes_char.
Qed.
Lemma cfRes_vchar_on A phi :
H \subset G -> phi \in 'Z[irr G, A] -> 'Res[H] phi \in 'Z[irr H, A].
Proof.
rewrite zchar_split => sHG /andP[Zphi Aphi]; rewrite zchar_split cfRes_vchar //.
apply/cfun_onP=> x /(cfun_onP Aphi); rewrite !cfunElock !genGid sHG => ->.
exact: mul0rn.
Qed.
Lemma cfInd_vchar phi : phi \in 'Z[irr H] -> 'Ind[G] phi \in 'Z[irr G].
Proof.
move=> /vcharP[xi1 Nx1 [xi2 Nxi2 ->]].
by rewrite raddfB rpredB ?char_vchar ?cfInd_char.
Qed.
Lemma sub_conjC_vchar A phi :
phi \in 'Z[irr G, A] -> phi - (phi^*)%CF \in 'Z[irr G, A^#].
Proof.
move=> Zphi; rewrite sub_aut_zchar ?cfAut_zchar // => _ /irrP[i ->].
exact: irr_vchar.
exact: cfConjC_irr.
Qed.
Lemma Frobenius_kernel_exists :
[Frobenius G with complement H] -> {K : {group gT} | [Frobenius G = K ><| H]}.
Proof.
move=> frobG; have [_ ntiHG] := andP frobG.
have [[_ sHG regGH][_ tiHG /eqP defNH]] := (normedTI_memJ_P ntiHG, and3P ntiHG).
suffices /sigW[K defG]: exists K, gval K ><| H == G by exists K; apply/andP.
pose K1 := G :\: cover (H^# :^: G).
have oK1: #|K1| = #|G : H|.
rewrite cardsD (setIidPr _); last first.
rewrite cover_imset; apply/bigcupsP=> x Gx.
by rewrite sub_conjg conjGid ?groupV // (subset_trans (subsetDl _ _)).
rewrite (cover_partition (partition_normedTI ntiHG)) -(Lagrange sHG).
by rewrite (card_support_normedTI ntiHG) (cardsD1 1%g) group1 mulSn addnK.
suffices extG i: {j | {in H, 'chi[G]_j =1 'chi[H]_i} & K1 \subset cfker 'chi_j}.
pose K := [group of \bigcap_i cfker 'chi_(s2val (extG i))].
have nKH: H \subset 'N(K).
by apply/norms_bigcap/bigcapsP=> i _; apply: subset_trans (cfker_norm _).
have tiKH: K :&: H = 1%g.
apply/trivgP; rewrite -(TI_cfker_irr H) /= setIC; apply/bigcapsP=> i _.
apply/subsetP=> x /setIP[Hx /bigcapP/(_ i isT)/=]; rewrite !cfkerEirr !inE.
by case: (extG i) => /= j def_j _; rewrite !def_j.
exists K; rewrite sdprodE // eqEcard TI_cardMg // mul_subG //=; last first.
by rewrite (bigcap_min (0 : Iirr H)) ?cfker_sub.
rewrite -(Lagrange sHG) mulnC leq_pmul2r // -oK1 subset_leq_card //.
by apply/bigcapsP=> i _; case: (extG i).
case i0: (i == 0).
exists 0 => [x Hx|]; last by rewrite irr0 cfker_cfun1 subsetDl.
by rewrite (eqP i0) !irr0 !cfun1E // (subsetP sHG) ?Hx.
have ochi1: '['chi_i, 1] = 0 by rewrite -irr0 cfdot_irr i0.
pose a := 'chi_i 1%g; have Za: a \in Num.int by rewrite intrE Cnat_irr1.
pose theta := 'chi_i - a%:A; pose phi := 'Ind[G] theta + a%:A.
have /cfun_onP theta0: theta \in 'CF(H, H^#).
by rewrite cfunD1E !cfunE cfun11 mulr1 subrr.
have RItheta: 'Res ('Ind[G] theta) = theta.
apply/cfun_inP=> x Hx; rewrite cfResE ?cfIndE // (big_setID H) /= addrC.
apply: canLR (mulKf (neq0CG H)) _; rewrite (setIidPr sHG) mulr_natl.
rewrite big1 ?add0r => [|y /setDP[/regGH tiHy H'y]]; last first.
have [-> | ntx] := eqVneq x 1%g; first by rewrite conj1g theta0 ?inE ?eqxx.
by rewrite theta0 ?tiHy // !inE ntx.
by rewrite -sumr_const; apply: eq_bigr => y Hy; rewrite cfunJ.
have ophi1: '[phi, 1] = 0.
rewrite cfdotDl -cfdot_Res_r cfRes_cfun1 // cfdotBl !cfdotZl !cfnorm1.
by rewrite ochi1 add0r addNr.
have{ochi1} n1phi: '[phi] = 1.
have: '[phi - a%:A] = '[theta] by rewrite addrK -cfdot_Res_l RItheta.
rewrite !cfnormBd ?cfnormZ ?cfdotZr ?ophi1 ?ochi1 ?mulr0 //.
by rewrite !cfnorm1 cfnorm_irr => /addIr.
have Zphi: phi \in 'Z[irr G].
by rewrite rpredD ?cfInd_vchar ?rpredB ?irr_vchar // scale_zchar ?rpred1.
have def_phi: {in H, phi =1 'chi_i}.
move=> x Hx /=; rewrite !cfunE -[_ x](cfResE _ sHG) ?RItheta //.
by rewrite !cfunE !cfun1E ?(subsetP sHG) ?Hx ?subrK.
have [j def_chi_j]: {j | 'chi_j = phi}.
apply/sig_eqW; have [[] [j]] := vchar_norm1P Zphi n1phi; last first.
by rewrite scale1r; exists j.
move/cfunP/(_ 1%g)/eqP; rewrite scaleN1r def_phi // cfunE -addr_eq0 eq_le.
by rewrite lt_geF // ltr_pDl ?irr1_gt0.
exists j; rewrite ?cfkerEirr def_chi_j //; apply/subsetP => x /setDP[Gx notHx].
rewrite inE cfunE def_phi // cfunE -/a cfun1E // Gx mulr1 cfIndE //.
rewrite big1 ?mulr0 ?add0r // => y Gy; apply/theta0/(contra _ notHx) => Hxy.
by rewrite -(conjgK y x) cover_imset -class_supportEr imset2_f ?groupV.
Qed.
End MoreVchar.
Definition dirr (gT : finGroupType) (B : {set gT}) : {pred 'CF(B)} :=
[pred f | (f \in irr B) || (- f \in irr B)].
Arguments dirr {gT}.
Section Norm1vchar.
Variables (gT : finGroupType) (G : {group gT}).
Fact dirr_oppr_closed : oppr_closed (dirr G).
Proof. by move=> xi; rewrite !inE opprK orbC. Qed.
HB.instance Definition _ := GRing.isOppClosed.Build (classfun G) (dirr G)
dirr_oppr_closed.
Lemma dirr_opp v : (- v \in dirr G) = (v \in dirr G). Proof. exact: rpredN. Qed.
Lemma dirr_sign n v : ((-1)^+ n *: v \in dirr G) = (v \in dirr G).
Proof. exact: rpredZsign. Qed.
Lemma irr_dirr i : 'chi_i \in dirr G.
Proof. by rewrite !inE mem_irr. Qed.
Lemma dirrP f :
reflect (exists b : bool, exists i, f = (-1) ^+ b *: 'chi_i) (f \in dirr G).
Proof.
apply: (iffP idP) => [| [b [i ->]]]; last by rewrite dirr_sign irr_dirr.
case/orP=> /irrP[i Hf]; first by exists false, i; rewrite scale1r.
by exists true, i; rewrite scaleN1r -Hf opprK.
Qed.
(* This should perhaps be the definition of dirr. *)
Lemma dirrE phi : phi \in dirr G = (phi \in 'Z[irr G]) && ('[phi] == 1).
Proof.
apply/dirrP/andP=> [[b [i ->]] | [Zphi /eqP/vchar_norm1P]]; last exact.
by rewrite rpredZsign irr_vchar cfnorm_sign cfnorm_irr.
Qed.
Lemma cfdot_dirr f g : f \in dirr G -> g \in dirr G ->
'[f, g] = (if f == - g then -1 else (f == g)%:R).
Proof.
case/dirrP=> [b1 [i1 ->]] /dirrP[b2 [i2 ->]].
rewrite cfdotZl cfdotZr rmorph_sign mulrA -signr_addb cfdot_irr.
rewrite -scaleNr -signrN !eq_scaled_irr signr_eq0 !(inj_eq signr_inj) /=.
by rewrite -!negb_add addbN mulr_sign -mulNrn mulrb; case: ifP.
Qed.
Lemma dirr_norm1 phi : phi \in 'Z[irr G] -> '[phi] = 1 -> phi \in dirr G.
Proof. by rewrite dirrE => -> -> /=. Qed.
Lemma dirr_aut u phi : (cfAut u phi \in dirr G) = (phi \in dirr G).
Proof.
rewrite !dirrE vchar_aut; apply: andb_id2l => /cfdot_aut_vchar->.
exact: fmorph_eq1.
Qed.
Definition dIirr (B : {set gT}) := (bool * (Iirr B))%type.
Definition dirr1 (B : {set gT}) : dIirr B := (false, 0).
Definition ndirr (B : {set gT}) (i : dIirr B) : dIirr B :=
(~~ i.1, i.2).
Lemma ndirr_diff (i : dIirr G) : ndirr i != i.
Proof. by case: i => [] [|] i. Qed.
Lemma ndirrK : involutive (@ndirr G).
Proof. by move=> [b i]; rewrite /ndirr /= negbK. Qed.
Lemma ndirr_inj : injective (@ndirr G).
Proof. exact: (inv_inj ndirrK). Qed.
Definition dchi (B : {set gT}) (i : dIirr B) : 'CF(B) := (-1)^+ i.1 *: 'chi_i.2.
Lemma dchi1 : dchi (dirr1 G) = 1.
Proof. by rewrite /dchi scale1r irr0. Qed.
Lemma dirr_dchi i : dchi i \in dirr G.
Proof. by apply/dirrP; exists i.1; exists i.2. Qed.
Lemma dIrrP phi : reflect (exists i, phi = dchi i) (phi \in dirr G).
Proof.
by apply: (iffP idP)=> [/dirrP[b]|] [i ->]; [exists (b, i) | apply: dirr_dchi].
Qed.
Lemma dchi_ndirrE (i : dIirr G) : dchi (ndirr i) = - dchi i.
Proof. by case: i => [b i]; rewrite /ndirr /dchi signrN scaleNr. Qed.
Lemma cfdot_dchi (i j : dIirr G) :
'[dchi i, dchi j] = (i == j)%:R - (i == ndirr j)%:R.
Proof.
case: i => bi i; case: j => bj j; rewrite cfdot_dirr ?dirr_dchi // !xpair_eqE.
rewrite -dchi_ndirrE !eq_scaled_irr signr_eq0 !(inj_eq signr_inj) /=.
by rewrite -!negb_add addbN negbK; case: andP => [[->]|]; rewrite ?subr0 ?add0r.
Qed.
Lemma dchi_vchar i : dchi i \in 'Z[irr G].
Proof. by case: i => b i; rewrite rpredZsign irr_vchar. Qed.
Lemma cfnorm_dchi (i : dIirr G) : '[dchi i] = 1.
Proof. by case: i => b i; rewrite cfnorm_sign cfnorm_irr. Qed.
Lemma dirr_inj : injective (@dchi G).
Proof.
case=> b1 i1 [b2 i2] /eqP; rewrite eq_scaled_irr (inj_eq signr_inj) /=.
by rewrite signr_eq0 -xpair_eqE => /eqP.
Qed.
Definition dirr_dIirr (B : {set gT}) J (f : J -> 'CF(B)) j : dIirr B :=
odflt (dirr1 B) [pick i | dchi i == f j].
Lemma dirr_dIirrPE J (f : J -> 'CF(G)) (P : pred J) :
(forall j, P j -> f j \in dirr G) ->
forall j, P j -> dchi (dirr_dIirr f j) = f j.
Proof.
rewrite /dirr_dIirr => dirrGf j Pj; case: pickP => [i /eqP //|].
by have /dIrrP[i-> /(_ i)/eqP] := dirrGf j Pj.
Qed.
Lemma dirr_dIirrE J (f : J -> 'CF(G)) :
(forall j, f j \in dirr G) -> forall j, dchi (dirr_dIirr f j) = f j.
Proof. by move=> dirrGf j; apply: (@dirr_dIirrPE _ _ xpredT). Qed.
Definition dirr_constt (B : {set gT}) (phi: 'CF(B)) : {set (dIirr B)} :=
[set i | 0 < '[phi, dchi i]].
Lemma dirr_consttE (phi : 'CF(G)) (i : dIirr G) :
(i \in dirr_constt phi) = (0 < '[phi, dchi i]).
Proof. by rewrite inE. Qed.
Lemma Cnat_dirr (phi : 'CF(G)) i :
phi \in 'Z[irr G] -> i \in dirr_constt phi -> '[phi, dchi i] \in Num.nat.
Proof.
move=> PiZ; rewrite natrEint dirr_consttE andbC => /ltW -> /=.
by case: i => b i; rewrite cfdotZr rmorph_sign rpredMsign Cint_cfdot_vchar_irr.
Qed.
Lemma dirr_constt_oppr (i : dIirr G) (phi : 'CF(G)) :
(i \in dirr_constt (-phi)) = (ndirr i \in dirr_constt phi).
Proof. by rewrite !dirr_consttE dchi_ndirrE cfdotNl cfdotNr. Qed.
Lemma dirr_constt_oppI (phi: 'CF(G)) :
dirr_constt phi :&: dirr_constt (-phi) = set0.
Proof.
apply/setP=> i; rewrite inE !dirr_consttE cfdotNl inE.
apply/idP=> /andP [L1 L2]; have := ltr_pDl L1 L2.
by rewrite subrr lt_def eqxx.
Qed.
Lemma dirr_constt_oppl (phi: 'CF(G)) i :
i \in dirr_constt phi -> (ndirr i) \notin dirr_constt phi.
Proof.
by rewrite !dirr_consttE dchi_ndirrE cfdotNr oppr_gt0 => /ltW /le_gtF ->.
Qed.
Definition to_dirr (B : {set gT}) (phi : 'CF(B)) (i : Iirr B) : dIirr B :=
('[phi, 'chi_i] < 0, i).
Definition of_irr (B : {set gT}) (i : dIirr B) : Iirr B := i.2.
Lemma irr_constt_to_dirr (phi: 'CF(G)) i : phi \in 'Z[irr G] ->
(i \in irr_constt phi) = (to_dirr phi i \in dirr_constt phi).
Proof.
move=> Zphi; rewrite irr_consttE dirr_consttE cfdotZr rmorph_sign /=.
by rewrite -real_normrEsign ?normr_gt0 ?Rreal_int // Cint_cfdot_vchar_irr.
Qed.
Lemma to_dirrK (phi: 'CF(G)) : cancel (to_dirr phi) (@of_irr G).
Proof. by []. Qed.
Lemma of_irrK (phi: 'CF(G)) :
{in dirr_constt phi, cancel (@of_irr G) (to_dirr phi)}.
Proof.
case=> b i; rewrite dirr_consttE cfdotZr rmorph_sign /= /to_dirr mulr_sign.
by rewrite fun_if oppr_gt0; case: b => [|/ltW/le_gtF] ->.
Qed.
Lemma cfdot_todirrE (phi: 'CF(G)) i (phi_i := dchi (to_dirr phi i)) :
'[phi, phi_i] *: phi_i = '[phi, 'chi_i] *: 'chi_i.
Proof. by rewrite cfdotZr rmorph_sign mulrC -scalerA signrZK. Qed.
Lemma cfun_sum_dconstt (phi : 'CF(G)) :
phi \in 'Z[irr G] ->
phi = \sum_(i in dirr_constt phi) '[phi, dchi i] *: dchi i.
Proof.
move=> PiZ; rewrite [LHS]cfun_sum_constt.
rewrite (reindex (to_dirr phi))=> [/= |]; last first.
by exists (@of_irr _)=> //; apply: of_irrK .
by apply: eq_big => i; rewrite ?irr_constt_to_dirr // cfdot_todirrE.
Qed.
Lemma cnorm_dconstt (phi : 'CF(G)) :
phi \in 'Z[irr G] ->
'[phi] = \sum_(i in dirr_constt phi) '[phi, dchi i] ^+ 2.
Proof.
move=> PiZ; rewrite {1 2}(cfun_sum_dconstt PiZ).
rewrite cfdot_suml; apply: eq_bigr=> i IiD.
rewrite cfdot_sumr (bigD1 i) //= big1 ?addr0 => [|j /andP [JiD IdJ]].
rewrite cfdotZr cfdotZl cfdot_dchi eqxx eq_sym (negPf (ndirr_diff i)).
by rewrite subr0 mulr1 aut_natr ?Cnat_dirr.
rewrite cfdotZr cfdotZl cfdot_dchi eq_sym (negPf IdJ) -natrB ?mulr0 //.
by rewrite (negPf (contraNneq _ (dirr_constt_oppl JiD))) => // <-.
Qed.
Lemma dirr_small_norm (phi : 'CF(G)) n :
phi \in 'Z[irr G] -> '[phi] = n%:R -> (n < 4)%N ->
[/\ #|dirr_constt phi| = n, dirr_constt phi :&: dirr_constt (- phi) = set0 &
phi = \sum_(i in dirr_constt phi) dchi i].
Proof.
move=> PiZ Pln; rewrite ltnNge -leC_nat => Nl4.
suffices Fd i: i \in dirr_constt phi -> '[phi, dchi i] = 1.
split; last 2 [by apply/setP=> u; rewrite !inE cfdotNl oppr_gt0 lt_asym].
apply/eqP; rewrite -eqC_nat -sumr_const -Pln (cnorm_dconstt PiZ).
by apply/eqP/eq_bigr=> i Hi; rewrite Fd // expr1n.
rewrite {1}[phi]cfun_sum_dconstt //.
by apply: eq_bigr => i /Fd->; rewrite scale1r.
move=> IiD; apply: contraNeq Nl4 => phi_i_neq1.
rewrite -Pln cnorm_dconstt // (bigD1 i) ?ler_wpDr ?sumr_ge0 //=.
by move=> j /andP[JiD _]; rewrite exprn_ge0 ?natr_ge0 ?Cnat_dirr.
have /natrP[m Dm] := Cnat_dirr PiZ IiD; rewrite Dm -natrX ler_nat (leq_sqr 2).
by rewrite ltn_neqAle eq_sym -eqC_nat -ltC_nat -Dm phi_i_neq1 -dirr_consttE.
Qed.
Lemma cfdot_sum_dchi (phi1 phi2 : 'CF(G)) :
'[\sum_(i in dirr_constt phi1) dchi i,
\sum_(i in dirr_constt phi2) dchi i] =
#|dirr_constt phi1 :&: dirr_constt phi2|%:R -
#|dirr_constt phi1 :&: dirr_constt (- phi2)|%:R.
Proof.
rewrite addrC (big_setID (dirr_constt (- phi2))) /= cfdotDl; congr (_ + _).
rewrite cfdot_suml -sumr_const -sumrN; apply: eq_bigr => i /setIP[p1i p2i].
rewrite cfdot_sumr (bigD1 (ndirr i)) -?dirr_constt_oppr //= dchi_ndirrE.
rewrite cfdotNr cfnorm_dchi big1 ?addr0 // => j /andP[p2j i'j].
rewrite cfdot_dchi -(inv_eq ndirrK) [in rhs in - rhs]eq_sym (negPf i'j) subr0.
rewrite (negPf (contraTneq _ p2i)) // => ->.
by rewrite dirr_constt_oppr dirr_constt_oppl.
rewrite cfdot_sumr (big_setID (dirr_constt phi1)) setIC /= addrC.
rewrite big1 ?add0r => [|j /setDP[p2j p1'j]]; last first.
rewrite cfdot_suml big1 // => i /setDP[p1i p2'i].
rewrite cfdot_dchi (negPf (contraTneq _ p1i)) => [|-> //].
rewrite (negPf (contraNneq _ p2'i)) ?subrr // => ->.
by rewrite dirr_constt_oppr ndirrK.
rewrite -sumr_const; apply: eq_bigr => i /setIP[p1i p2i]; rewrite cfdot_suml.
rewrite (bigD1 i) /=; last by rewrite inE dirr_constt_oppr dirr_constt_oppl.
rewrite cfnorm_dchi big1 ?addr0 // => j /andP[/setDP[p1j _] i'j].
rewrite cfdot_dchi (negPf i'j) (negPf (contraTneq _ p1j)) ?subrr // => ->.
exact: dirr_constt_oppl.
Qed.
Lemma cfdot_dirr_eq1 :
{in dirr G &, forall phi psi, ('[phi, psi] == 1) = (phi == psi)}.
Proof.
move=> _ _ /dirrP[b1 [i1 ->]] /dirrP[b2 [i2 ->]].
rewrite eq_signed_irr cfdotZl cfdotZr rmorph_sign cfdot_irr mulrA -signr_addb.
rewrite pmulrn -rmorphMsign (eqr_int _ _ 1) -negb_add.
by case: (b1 (+) b2) (i1 == i2) => [] [].
Qed.
Lemma cfdot_add_dirr_eq1 :
{in dirr G & &, forall phi1 phi2 psi,
'[phi1 + phi2, psi] = 1 -> psi = phi1 \/ psi = phi2}.
Proof.
move=> _ _ _ /dirrP[b1 [i1 ->]] /dirrP[b2 [i2 ->]] /dirrP[c [j ->]] /eqP.
rewrite cfdotDl !cfdotZl !cfdotZr !rmorph_sign !cfdot_irr !mulrA -!signr_addb.
rewrite 2!{1}signrE !mulrBl !mul1r -!natrM addrCA -subr_eq0 -!addrA.
rewrite -!opprD addrA subr_eq0 -mulrSr -!natrD eqr_nat => eq_phi_psi.
apply/pred2P; rewrite /= !eq_signed_irr -!negb_add !(eq_sym j) !(addbC c).
by case: (i1 == j) eq_phi_psi; case: (i2 == j); do 2!case: (_ (+) c).
Qed.
End Norm1vchar.
Prenex Implicits ndirr ndirrK to_dirr to_dirrK of_irr.
Arguments of_irrK {gT G phi} [i] phi_i : rename.
|
Basic.lean
|
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
-/
import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Group.End
import Mathlib.Logic.Equiv.Set
import Mathlib.Tactic.Common
/-!
# Extra lemmas about permutations
This file proves miscellaneous lemmas about `Equiv.Perm`.
## TODO
Most of the content of this file was moved to `Algebra.Group.End` in
https://github.com/leanprover-community/mathlib4/pull/22141.
It would be good to merge the remaining lemmas with other files, eg `GroupTheory.Perm.ViaEmbedding`
looks like it could benefit from such a treatment (splitting into the algebra and non-algebra parts)
-/
universe u v
namespace Equiv
variable {α : Type u} {β : Type v}
namespace Perm
@[simp] lemma image_inv (f : Perm α) (s : Set α) : ↑f⁻¹ '' s = f ⁻¹' s := f⁻¹.image_eq_preimage _
@[simp] lemma preimage_inv (f : Perm α) (s : Set α) : ↑f⁻¹ ⁻¹' s = f '' s :=
(f.image_eq_preimage _).symm
end Perm
section Swap
variable [DecidableEq α]
@[simp]
theorem swap_smul_self_smul [MulAction (Perm α) β] (i j : α) (x : β) :
swap i j • swap i j • x = x := by simp [smul_smul]
theorem swap_smul_involutive [MulAction (Perm α) β] (i j : α) :
Function.Involutive (swap i j • · : β → β) := swap_smul_self_smul i j
end Swap
end Equiv
open Equiv Function
namespace Set
variable {α : Type*} {f : Perm α} {s : Set α}
lemma BijOn.perm_inv (hf : BijOn f s s) : BijOn ↑(f⁻¹) s s := hf.symm f.invOn
lemma MapsTo.perm_pow : MapsTo f s s → ∀ n : ℕ, MapsTo (f ^ n) s s := by
simp_rw [Equiv.Perm.coe_pow]; exact MapsTo.iterate
lemma SurjOn.perm_pow : SurjOn f s s → ∀ n : ℕ, SurjOn (f ^ n) s s := by
simp_rw [Equiv.Perm.coe_pow]; exact SurjOn.iterate
lemma BijOn.perm_pow : BijOn f s s → ∀ n : ℕ, BijOn (f ^ n) s s := by
simp_rw [Equiv.Perm.coe_pow]; exact BijOn.iterate
lemma BijOn.perm_zpow (hf : BijOn f s s) : ∀ n : ℤ, BijOn (f ^ n) s s
| Int.ofNat n => hf.perm_pow n
| Int.negSucc n => (hf.perm_pow (n + 1)).perm_inv
end Set
|
Character.lean
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Abelian
import Mathlib.Algebra.Lie.Solvable
import Mathlib.LinearAlgebra.Dual.Defs
/-!
# Characters of Lie algebras
A character of a Lie algebra `L` over a commutative ring `R` is a morphism of Lie algebras `L → R`,
where `R` is regarded as a Lie algebra over itself via the ring commutator. For an Abelian Lie
algebra (e.g., a Cartan subalgebra of a semisimple Lie algebra) a character is just a linear form.
## Main definitions
* `LieAlgebra.LieCharacter`
* `LieAlgebra.lieCharacterEquivLinearDual`
## Tags
lie algebra, lie character
-/
universe u v w w₁
namespace LieAlgebra
variable (R : Type u) (L : Type v) [CommRing R] [LieRing L] [LieAlgebra R L]
/-- A character of a Lie algebra is a morphism to the scalars. -/
abbrev LieCharacter :=
L →ₗ⁅R⁆ R
variable {R L}
theorem lieCharacter_apply_lie (χ : LieCharacter R L) (x y : L) : χ ⁅x, y⁆ = 0 := by
rw [LieHom.map_lie, LieRing.of_associative_ring_bracket, mul_comm, sub_self]
@[simp]
theorem lieCharacter_apply_lie' (χ : LieCharacter R L) (x y : L) : ⁅χ x, χ y⁆ = 0 := by
rw [LieRing.of_associative_ring_bracket, mul_comm, sub_self]
theorem lieCharacter_apply_of_mem_derived (χ : LieCharacter R L) {x : L}
(h : x ∈ derivedSeries R L 1) : χ x = 0 := by
rw [derivedSeries_def, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_zero, ←
LieSubmodule.mem_toSubmodule, LieSubmodule.lieIdeal_oper_eq_linear_span] at h
refine Submodule.span_induction ?_ ?_ ?_ ?_ h
· rintro y ⟨⟨z, hz⟩, ⟨⟨w, hw⟩, rfl⟩⟩; apply lieCharacter_apply_lie
· exact χ.map_zero
· intro y z _ _ hy hz; rw [LieHom.map_add, hy, hz, add_zero]
· intro t y _ hy; rw [LieHom.map_smul, hy, smul_zero]
/-- For an Abelian Lie algebra, characters are just linear forms. -/
@[simps! apply symm_apply]
def lieCharacterEquivLinearDual [IsLieAbelian L] : LieCharacter R L ≃ Module.Dual R L where
toFun χ := (χ : L →ₗ[R] R)
invFun ψ :=
{ ψ with
map_lie' := fun {x y} => by
rw [LieModule.IsTrivial.trivial, LieRing.of_associative_ring_bracket, mul_comm, sub_self,
LinearMap.toFun_eq_coe, LinearMap.map_zero] }
end LieAlgebra
|
NoncommProd.lean
|
/-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
import Mathlib.Algebra.Group.Commute.Hom
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Data.Fintype.Basic
/-!
# Products (respectively, sums) over a finset or a multiset.
The regular `Finset.prod` and `Multiset.prod` require `[CommMonoid α]`.
Often, there are collections `s : Finset α` where `[Monoid α]` and we know,
in a dependent fashion, that for all the terms `∀ (x ∈ s) (y ∈ s), Commute x y`.
This allows to still have a well-defined product over `s`.
## Main definitions
- `Finset.noncommProd`, requiring a proof of commutativity of held terms
- `Multiset.noncommProd`, requiring a proof of commutativity of held terms
## Implementation details
While `List.prod` is defined via `List.foldl`, `noncommProd` is defined via
`Multiset.foldr` for neater proofs and definitions. By the commutativity assumption,
the two must be equal.
TODO: Tidy up this file by using the fact that the submonoid generated by commuting
elements is commutative and using the `Finset.prod` versions of lemmas to prove the `noncommProd`
version.
-/
variable {F ι α β γ : Type*} (f : α → β → β) (op : α → α → α)
namespace Multiset
/-- Fold of a `s : Multiset α` with `f : α → β → β`, given a proof that `LeftCommutative f`
on all elements `x ∈ s`. -/
def noncommFoldr (s : Multiset α)
(comm : { x | x ∈ s }.Pairwise fun x y => ∀ b, f x (f y b) = f y (f x b)) (b : β) : β :=
letI : LeftCommutative (α := { x // x ∈ s }) (f ∘ Subtype.val) :=
⟨fun ⟨_, hx⟩ ⟨_, hy⟩ =>
haveI : IsRefl α fun x y => ∀ b, f x (f y b) = f y (f x b) := ⟨fun _ _ => rfl⟩
comm.of_refl hx hy⟩
s.attach.foldr (f ∘ Subtype.val) b
@[simp]
theorem noncommFoldr_coe (l : List α) (comm) (b : β) :
noncommFoldr f (l : Multiset α) comm b = l.foldr f b := by
simp only [noncommFoldr, coe_foldr, coe_attach, List.attach, List.attachWith, Function.comp_def]
rw [← List.foldr_map]
simp [List.map_pmap]
@[simp]
theorem noncommFoldr_empty (h) (b : β) : noncommFoldr f (0 : Multiset α) h b = b :=
rfl
theorem noncommFoldr_cons (s : Multiset α) (a : α) (h h') (b : β) :
noncommFoldr f (a ::ₘ s) h b = f a (noncommFoldr f s h' b) := by
induction s using Quotient.inductionOn
simp
theorem noncommFoldr_eq_foldr (s : Multiset α) [h : LeftCommutative f] (b : β) :
noncommFoldr f s (fun x _ y _ _ => h.left_comm x y) b = foldr f b s := by
induction s using Quotient.inductionOn
simp
section assoc
variable [assoc : Std.Associative op]
/-- Fold of a `s : Multiset α` with an associative `op : α → α → α`, given a proofs that `op`
is commutative on all elements `x ∈ s`. -/
def noncommFold (s : Multiset α) (comm : { x | x ∈ s }.Pairwise fun x y => op x y = op y x) :
α → α :=
noncommFoldr op s fun x hx y hy h b => by rw [← assoc.assoc, comm hx hy h, assoc.assoc]
@[simp]
theorem noncommFold_coe (l : List α) (comm) (a : α) :
noncommFold op (l : Multiset α) comm a = l.foldr op a := by simp [noncommFold]
@[simp]
theorem noncommFold_empty (h) (a : α) : noncommFold op (0 : Multiset α) h a = a :=
rfl
theorem noncommFold_cons (s : Multiset α) (a : α) (h h') (x : α) :
noncommFold op (a ::ₘ s) h x = op a (noncommFold op s h' x) := by
induction s using Quotient.inductionOn
simp
theorem noncommFold_eq_fold (s : Multiset α) [Std.Commutative op] (a : α) :
noncommFold op s (fun x _ y _ _ => Std.Commutative.comm x y) a = fold op a s := by
induction s using Quotient.inductionOn
simp
end assoc
variable [Monoid α] [Monoid β]
/-- Product of a `s : Multiset α` with `[Monoid α]`, given a proof that `*` commutes
on all elements `x ∈ s`. -/
@[to_additive
/-- Sum of a `s : Multiset α` with `[AddMonoid α]`, given a proof that `+` commutes
on all elements `x ∈ s`. -/]
def noncommProd (s : Multiset α) (comm : { x | x ∈ s }.Pairwise Commute) : α :=
s.noncommFold (· * ·) comm 1
@[to_additive (attr := simp)]
theorem noncommProd_coe (l : List α) (comm) : noncommProd (l : Multiset α) comm = l.prod := by
rw [noncommProd]
simp only [noncommFold_coe]
induction' l with hd tl hl
· simp
· rw [List.prod_cons, List.foldr, hl]
intro x hx y hy
exact comm (List.mem_cons_of_mem _ hx) (List.mem_cons_of_mem _ hy)
@[to_additive (attr := simp)]
theorem noncommProd_empty (h) : noncommProd (0 : Multiset α) h = 1 :=
rfl
@[to_additive (attr := simp)]
theorem noncommProd_cons (s : Multiset α) (a : α) (comm) :
noncommProd (a ::ₘ s) comm = a * noncommProd s (comm.mono fun _ => mem_cons_of_mem) := by
induction s using Quotient.inductionOn
simp
@[to_additive]
theorem noncommProd_cons' (s : Multiset α) (a : α) (comm) :
noncommProd (a ::ₘ s) comm = noncommProd s (comm.mono fun _ => mem_cons_of_mem) * a := by
induction' s using Quotient.inductionOn with s
simp only [quot_mk_to_coe, cons_coe, noncommProd_coe, List.prod_cons]
induction' s with hd tl IH
· simp
· rw [List.prod_cons, mul_assoc, ← IH, ← mul_assoc, ← mul_assoc]
· congr 1
apply comm.of_refl <;> simp
· intro x hx y hy
simp only [quot_mk_to_coe, List.mem_cons, mem_coe, cons_coe] at hx hy
apply comm
· cases hx <;> simp [*]
· cases hy <;> simp [*]
@[to_additive]
theorem noncommProd_add (s t : Multiset α) (comm) :
noncommProd (s + t) comm =
noncommProd s (comm.mono <| subset_of_le <| s.le_add_right t) *
noncommProd t (comm.mono <| subset_of_le <| t.le_add_left s) := by
rcases s with ⟨⟩
rcases t with ⟨⟩
simp
@[to_additive]
lemma noncommProd_induction (s : Multiset α) (comm)
(p : α → Prop) (hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p x) :
p (s.noncommProd comm) := by
induction' s using Quotient.inductionOn with l
simp only [quot_mk_to_coe, noncommProd_coe, mem_coe] at base ⊢
exact l.prod_induction p hom unit base
variable [FunLike F α β]
@[to_additive]
protected theorem map_noncommProd_aux [MulHomClass F α β] (s : Multiset α)
(comm : { x | x ∈ s }.Pairwise Commute) (f : F) : { x | x ∈ s.map f }.Pairwise Commute := by
simp only [Multiset.mem_map]
rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ _
exact (comm.of_refl hx hy).map f
@[to_additive]
theorem map_noncommProd [MonoidHomClass F α β] (s : Multiset α) (comm) (f : F) :
f (s.noncommProd comm) = (s.map f).noncommProd (Multiset.map_noncommProd_aux s comm f) := by
induction s using Quotient.inductionOn
simpa using map_list_prod f _
@[to_additive noncommSum_eq_card_nsmul]
theorem noncommProd_eq_pow_card (s : Multiset α) (comm) (m : α) (h : ∀ x ∈ s, x = m) :
s.noncommProd comm = m ^ Multiset.card s := by
induction s using Quotient.inductionOn
simp only [quot_mk_to_coe, noncommProd_coe, coe_card, mem_coe] at *
exact List.prod_eq_pow_card _ m h
@[to_additive]
theorem noncommProd_eq_prod {α : Type*} [CommMonoid α] (s : Multiset α) :
(noncommProd s fun _ _ _ _ _ => Commute.all _ _) = prod s := by
induction s using Quotient.inductionOn
simp
@[to_additive]
theorem noncommProd_commute (s : Multiset α) (comm) (y : α) (h : ∀ x ∈ s, Commute y x) :
Commute y (s.noncommProd comm) := by
induction s using Quotient.inductionOn
simp only [quot_mk_to_coe, noncommProd_coe]
exact Commute.list_prod_right _ _ h
theorem mul_noncommProd_erase [DecidableEq α] (s : Multiset α) {a : α} (h : a ∈ s) (comm)
(comm' := fun _ hx _ hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) :
a * (s.erase a).noncommProd comm' = s.noncommProd comm := by
induction' s using Quotient.inductionOn with l
simp only [quot_mk_to_coe, mem_coe, coe_erase, noncommProd_coe] at comm h ⊢
suffices ∀ x ∈ l, ∀ y ∈ l, x * y = y * x by rw [List.prod_erase_of_comm h this]
intro x hx y hy
rcases eq_or_ne x y with rfl | hxy
· rfl
exact comm hx hy hxy
theorem noncommProd_erase_mul [DecidableEq α] (s : Multiset α) {a : α} (h : a ∈ s) (comm)
(comm' := fun _ hx _ hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) :
(s.erase a).noncommProd comm' * a = s.noncommProd comm := by
suffices ∀ b ∈ erase s a, Commute a b by
rw [← (noncommProd_commute (s.erase a) comm' a this).eq, mul_noncommProd_erase s h comm comm']
intro b hb
rcases eq_or_ne a b with rfl | hab
· rfl
exact comm h (mem_of_mem_erase hb) hab
end Multiset
namespace Finset
variable [Monoid β] [Monoid γ]
open scoped Function -- required for scoped `on` notation
/-- Proof used in definition of `Finset.noncommProd` -/
@[to_additive]
theorem noncommProd_lemma (s : Finset α) (f : α → β)
(comm : (s : Set α).Pairwise (Commute on f)) :
Set.Pairwise { x | x ∈ Multiset.map f s.val } Commute := by
simp_rw [Multiset.mem_map]
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ _
exact comm.of_refl ha hb
/-- Product of a `s : Finset α` mapped with `f : α → β` with `[Monoid β]`,
given a proof that `*` commutes on all elements `f x` for `x ∈ s`. -/
@[to_additive
/-- Sum of a `s : Finset α` mapped with `f : α → β` with `[AddMonoid β]`,
given a proof that `+` commutes on all elements `f x` for `x ∈ s`. -/]
def noncommProd (s : Finset α) (f : α → β)
(comm : (s : Set α).Pairwise (Commute on f)) : β :=
(s.1.map f).noncommProd <| noncommProd_lemma s f comm
@[to_additive]
lemma noncommProd_induction (s : Finset α) (f : α → β) (comm)
(p : β → Prop) (hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p (f x)) :
p (s.noncommProd f comm) := by
refine Multiset.noncommProd_induction _ _ _ hom unit fun b hb ↦ ?_
obtain (⟨a, ha : a ∈ s, rfl : f a = b⟩) := by simpa using hb
exact base a ha
@[to_additive (attr := congr)]
theorem noncommProd_congr {s₁ s₂ : Finset α} {f g : α → β} (h₁ : s₁ = s₂)
(h₂ : ∀ x ∈ s₂, f x = g x) (comm) :
noncommProd s₁ f comm =
noncommProd s₂ g fun x hx y hy h => by
dsimp only [Function.onFun]
rw [← h₂ _ hx, ← h₂ _ hy]
subst h₁
exact comm hx hy h := by
simp_rw [noncommProd, Multiset.map_congr (congr_arg _ h₁) h₂]
@[to_additive (attr := simp)]
theorem noncommProd_toFinset [DecidableEq α] (l : List α) (f : α → β) (comm) (hl : l.Nodup) :
noncommProd l.toFinset f comm = (l.map f).prod := by
rw [← List.dedup_eq_self] at hl
simp [noncommProd, hl]
@[to_additive (attr := simp)]
theorem noncommProd_empty (f : α → β) (h) : noncommProd (∅ : Finset α) f h = 1 :=
rfl
@[to_additive (attr := simp)]
theorem noncommProd_cons (s : Finset α) (a : α) (f : α → β)
(ha : a ∉ s) (comm) :
noncommProd (cons a s ha) f comm =
f a * noncommProd s f (comm.mono fun _ => Finset.mem_cons.2 ∘ .inr) := by
simp_rw [noncommProd, Finset.cons_val, Multiset.map_cons, Multiset.noncommProd_cons]
@[to_additive]
theorem noncommProd_cons' (s : Finset α) (a : α) (f : α → β)
(ha : a ∉ s) (comm) :
noncommProd (cons a s ha) f comm =
noncommProd s f (comm.mono fun _ => Finset.mem_cons.2 ∘ .inr) * f a := by
simp_rw [noncommProd, Finset.cons_val, Multiset.map_cons, Multiset.noncommProd_cons']
@[to_additive (attr := simp)]
theorem noncommProd_insert_of_notMem [DecidableEq α] (s : Finset α) (a : α) (f : α → β) (comm)
(ha : a ∉ s) :
noncommProd (insert a s) f comm =
f a * noncommProd s f (comm.mono fun _ => mem_insert_of_mem) := by
simp only [← cons_eq_insert _ _ ha, noncommProd_cons]
@[deprecated (since := "2025-05-23")]
alias noncommSum_insert_of_not_mem := noncommSum_insert_of_notMem
@[to_additive existing, deprecated (since := "2025-05-23")]
alias noncommProd_insert_of_not_mem := noncommProd_insert_of_notMem
@[to_additive]
theorem noncommProd_insert_of_notMem' [DecidableEq α] (s : Finset α) (a : α) (f : α → β) (comm)
(ha : a ∉ s) :
noncommProd (insert a s) f comm =
noncommProd s f (comm.mono fun _ => mem_insert_of_mem) * f a := by
simp only [← cons_eq_insert _ _ ha, noncommProd_cons']
@[deprecated (since := "2025-05-23")]
alias noncommSum_insert_of_not_mem' := noncommSum_insert_of_notMem'
@[to_additive existing, deprecated (since := "2025-05-23")]
alias noncommProd_insert_of_not_mem' := noncommProd_insert_of_notMem'
@[to_additive (attr := simp)]
theorem noncommProd_singleton (a : α) (f : α → β) :
noncommProd ({a} : Finset α) f
(by
norm_cast
exact Set.pairwise_singleton _ _) =
f a := mul_one _
variable [FunLike F β γ]
@[to_additive]
theorem map_noncommProd [MonoidHomClass F β γ] (s : Finset α) (f : α → β) (comm) (g : F) :
g (s.noncommProd f comm) =
s.noncommProd (fun i => g (f i)) fun _ hx _ hy _ => (comm.of_refl hx hy).map g := by
simp [noncommProd, Multiset.map_noncommProd]
@[to_additive noncommSum_eq_card_nsmul]
theorem noncommProd_eq_pow_card (s : Finset α) (f : α → β) (comm) (m : β) (h : ∀ x ∈ s, f x = m) :
s.noncommProd f comm = m ^ s.card := by
rw [noncommProd, Multiset.noncommProd_eq_pow_card _ _ m]
· simp only [Finset.card_def, Multiset.card_map]
· simpa using h
@[to_additive]
theorem noncommProd_commute (s : Finset α) (f : α → β) (comm) (y : β)
(h : ∀ x ∈ s, Commute y (f x)) : Commute y (s.noncommProd f comm) := by
apply Multiset.noncommProd_commute
intro y
rw [Multiset.mem_map]
rintro ⟨x, ⟨hx, rfl⟩⟩
exact h x hx
theorem mul_noncommProd_erase [DecidableEq α] (s : Finset α) {a : α} (h : a ∈ s) (f : α → β) (comm)
(comm' := fun _ hx _ hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) :
f a * (s.erase a).noncommProd f comm' = s.noncommProd f comm := by
classical
simpa only [← Multiset.map_erase_of_mem _ _ h] using
Multiset.mul_noncommProd_erase (s.1.map f) (Multiset.mem_map_of_mem f h) _
theorem noncommProd_erase_mul [DecidableEq α] (s : Finset α) {a : α} (h : a ∈ s) (f : α → β) (comm)
(comm' := fun _ hx _ hy hxy ↦ comm (s.mem_of_mem_erase hx) (s.mem_of_mem_erase hy) hxy) :
(s.erase a).noncommProd f comm' * f a = s.noncommProd f comm := by
classical
simpa only [← Multiset.map_erase_of_mem _ _ h] using
Multiset.noncommProd_erase_mul (s.1.map f) (Multiset.mem_map_of_mem f h) _
@[to_additive]
theorem noncommProd_eq_prod {β : Type*} [CommMonoid β] (s : Finset α) (f : α → β) :
(noncommProd s f fun _ _ _ _ _ => Commute.all _ _) = s.prod f := by
induction' s using Finset.cons_induction_on with a s ha IH
· simp
· simp [IH]
/-- The non-commutative version of `Finset.prod_union` -/
@[to_additive /-- The non-commutative version of `Finset.sum_union` -/]
theorem noncommProd_union_of_disjoint [DecidableEq α] {s t : Finset α} (h : Disjoint s t)
(f : α → β) (comm : { x | x ∈ s ∪ t }.Pairwise (Commute on f)) :
noncommProd (s ∪ t) f comm =
noncommProd s f (comm.mono <| coe_subset.2 subset_union_left) *
noncommProd t f (comm.mono <| coe_subset.2 subset_union_right) := by
obtain ⟨sl, sl', rfl⟩ := exists_list_nodup_eq s
obtain ⟨tl, tl', rfl⟩ := exists_list_nodup_eq t
rw [List.disjoint_toFinset_iff_disjoint] at h
calc noncommProd (List.toFinset sl ∪ List.toFinset tl) f comm
_ = noncommProd ⟨↑(sl ++ tl), Multiset.coe_nodup.2 (sl'.append tl' h)⟩ f
(by convert comm; simp [Set.ext_iff]) :=
noncommProd_congr (by ext; simp) (by simp) _
_ = noncommProd (List.toFinset sl) f (comm.mono <| coe_subset.2 subset_union_left) *
noncommProd (List.toFinset tl) f (comm.mono <| coe_subset.2 subset_union_right) := by
simp [noncommProd, List.dedup_eq_self.2 sl', List.dedup_eq_self.2 tl']
@[to_additive]
theorem noncommProd_mul_distrib_aux {s : Finset α} {f : α → β} {g : α → β}
(comm_ff : (s : Set α).Pairwise (Commute on f))
(comm_gg : (s : Set α).Pairwise (Commute on g))
(comm_gf : (s : Set α).Pairwise fun x y => Commute (g x) (f y)) :
(s : Set α).Pairwise fun x y => Commute ((f * g) x) ((f * g) y) := by
intro x hx y hy h
apply Commute.mul_left <;> apply Commute.mul_right
· exact comm_ff.of_refl hx hy
· exact (comm_gf hy hx h.symm).symm
· exact comm_gf hx hy h
· exact comm_gg.of_refl hx hy
/-- The non-commutative version of `Finset.prod_mul_distrib` -/
@[to_additive /-- The non-commutative version of `Finset.sum_add_distrib` -/]
theorem noncommProd_mul_distrib {s : Finset α} (f : α → β) (g : α → β) (comm_ff comm_gg comm_gf) :
noncommProd s (f * g) (noncommProd_mul_distrib_aux comm_ff comm_gg comm_gf) =
noncommProd s f comm_ff * noncommProd s g comm_gg := by
induction' s using Finset.cons_induction_on with x s hnotMem ih
· simp
rw [Finset.noncommProd_cons, Finset.noncommProd_cons, Finset.noncommProd_cons, Pi.mul_apply,
ih (comm_ff.mono fun _ => mem_cons_of_mem) (comm_gg.mono fun _ => mem_cons_of_mem)
(comm_gf.mono fun _ => mem_cons_of_mem),
(noncommProd_commute _ _ _ _ fun y hy => ?_).mul_mul_mul_comm]
exact comm_gf (mem_cons_self x s) (mem_cons_of_mem hy) (ne_of_mem_of_not_mem hy hnotMem).symm
section FinitePi
variable {M : ι → Type*} [∀ i, Monoid (M i)]
@[to_additive]
theorem noncommProd_mul_single [Fintype ι] [DecidableEq ι] (x : ∀ i, M i) :
(univ.noncommProd (fun i => Pi.mulSingle i (x i)) fun i _ j _ _ =>
Pi.mulSingle_apply_commute x i j) = x := by
ext i
apply (univ.map_noncommProd (fun i ↦ MonoidHom.mulSingle M i (x i)) ?a
(Pi.evalMonoidHom M i)).trans
case a =>
intro i _ j _ _
exact Pi.mulSingle_apply_commute x i j
convert (noncommProd_congr (insert_erase (mem_univ i)).symm _ _).trans _
· intro j
exact Pi.mulSingle j (x j) i
· intro j _; dsimp
· rw [noncommProd_insert_of_notMem _ _ _ _ (notMem_erase _ _),
noncommProd_eq_pow_card (univ.erase i), one_pow, mul_one]
· simp only [Pi.mulSingle_eq_same]
· intro j hj
simp? at hj says simp only [mem_erase, ne_eq, mem_univ, and_true] at hj
simp only [Pi.mulSingle, Function.update, Pi.one_apply,
dite_eq_right_iff]
intro h
simp [*] at *
@[to_additive]
theorem _root_.MonoidHom.pi_ext [Finite ι] [DecidableEq ι] {f g : (∀ i, M i) →* γ}
(h : ∀ i x, f (Pi.mulSingle i x) = g (Pi.mulSingle i x)) : f = g := by
cases nonempty_fintype ι
ext x
rw [← noncommProd_mul_single x, univ.map_noncommProd, univ.map_noncommProd]
congr 1 with i; exact h i (x i)
end FinitePi
end Finset
|
classfun.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient finalg action gproduct zmodp.
From mathcomp Require Import commutator cyclic center pgroup sylow matrix.
From mathcomp Require Import vector falgebra ssrnum algC algnum archimedean.
(******************************************************************************)
(* This file contains the basic theory of class functions: *)
(* 'CF(G) == the type of class functions on G : {group gT}, i.e., *)
(* which map gT to the type algC of complex algebraics, *)
(* have support in G, and are constant on each conjugacy *)
(* class of G. 'CF(G) implements the falgType interface of *)
(* finite-dimensional F-algebras. *)
(* The identity 1 : 'CF(G) is the indicator function of G, *)
(* and (later) the principal character. *)
(* --> The %CF scope (cfun_scope) is bound to the 'CF(_) types. *)
(* 'CF(G)%VS == the (total) vector space of 'CF(G). *)
(* 'CF(G, A) == the subspace of functions in 'CF(G) with support in A. *)
(* phi x == the image of x : gT under phi : 'CF(G). *)
(* #[phi]%CF == the multiplicative order of phi : 'CF(G). *)
(* cfker phi == the kernel of phi : 'CF(G); note that cfker phi <| G. *)
(* cfaithful phi <=> phi : 'CF(G) is faithful (has a trivial kernel). *)
(* '1_A == the indicator function of A as a function of 'CF(G). *)
(* (Provided A <| G; G is determined by the context.) *)
(* phi^*%CF == the function conjugate to phi : 'CF(G). *)
(* cfAut u phi == the function conjugate to phi by an algC-automorphism u *)
(* phi^u The notation "_ ^u" is only reserved; it is up to *)
(* clients to set Notation "phi ^u" := (cfAut u phi). *)
(* '[phi, psi] == the convolution of phi, psi : 'CF(G) over G, normalised *)
(* '[phi, psi]_G by #|G| so that '[1, 1]_G = 1 (G is usually inferred). *)
(* cfdotr psi phi == '[phi, psi] (self-expanding). *)
(* '[phi], '[phi]_G == the squared norm '[phi, phi] of phi : 'CF(G). *)
(* orthogonal R S <=> each phi in R : seq 'CF(G) is orthogonal to each psi in *)
(* S, i.e., '[phi, psi] = 0. As 'CF(G) coerces to seq, one *)
(* can write orthogonal phi S and orthogonal phi psi. *)
(* pairwise_orthogonal S <=> the class functions in S are pairwise orthogonal *)
(* AND non-zero. *)
(* orthonormal S <=> S is pairwise orthogonal and all class functions in S *)
(* have norm 1. *)
(* isometry tau <-> tau : 'CF(D) -> 'CF(R) is an isometry, mapping *)
(* '[_, _]_D to '[_, _]_R. *)
(* {in CD, isometry tau, to CR} <-> in the domain CD, tau is an isometry *)
(* whose range is contained in CR. *)
(* cfReal phi <=> phi is real, i.e., phi^* == phi. *)
(* cfAut_closed u S <-> S : seq 'CF(G) is closed under conjugation by u. *)
(* cfConjC_closed S <-> S : seq 'CF(G) is closed under complex conjugation. *)
(* conjC_subset S1 S2 <-> S1 : seq 'CF(G) represents a subset of S2 closed *)
(* under complex conjugation. *)
(* := [/\ uniq S1, {subset S1 <= S2} & cfConjC_closed S1]. *)
(* 'Res[H] phi == the restriction of phi : 'CF(G) to a function of 'CF(H) *)
(* 'Res[H, G] phi 'Res[H] phi x = phi x if x \in H (when H \subset G), *)
(* 'Res phi 'Res[H] phi x = 0 if x \notin H. The syntax variants *)
(* allow H and G to be inferred; the default is to specify *)
(* H explicitly, and infer G from the type of phi. *)
(* 'Ind[G] phi == the class function of 'CF(G) induced by phi : 'CF(H), *)
(* 'Ind[G, H] phi when H \subset G. As with 'Res phi, both G and H can *)
(* 'Ind phi be inferred, though usually G isn't. *)
(* cfMorph phi == the class function in 'CF(G) that maps x to phi (f x), *)
(* where phi : 'CF(f @* G), provided G \subset 'dom f. *)
(* cfIsom isoGR phi == the class function in 'CF(R) that maps f x to phi x, *)
(* given isoGR : isom G R f, f : {morphism G >-> rT} and *)
(* phi : 'CF(G). *)
(* (phi %% H)%CF == special case of cfMorph phi, when phi : 'CF(G / H). *)
(* (phi / H)%CF == the class function in 'CF(G / H) that coincides with *)
(* phi : 'CF(G) on cosets of H \subset cfker phi. *)
(* For a group G that is a semidirect product (defG : K ><| H = G), we have *)
(* cfSdprod KxH phi == for phi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* For a group G that is a direct product (with KxH : K \x H = G), we have *)
(* cfDprodl KxH phi == for phi : 'CF(K), the class function of 'CF(G) that *)
(* maps k * h to phi k when k \in K and h \in H. *)
(* cfDprodr KxH psi == for psi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* cfDprod KxH phi psi == for phi : 'CF(K), psi : 'CF(H), the class function *)
(* of 'CF(G) that maps k * h to phi k * psi h (this is *)
(* the product of the two functions above). *)
(* Finally, given defG : \big[dprod/1]_(i | P i) A i = G, with G and A i *)
(* groups and i ranges over a finType, we have *)
(* cfBigdprodi defG phi == for phi : 'CF(A i) s.t. P i, the class function *)
(* of 'CF(G) that maps x to phi x_i, where x_i is the *)
(* (A i)-component of x : G. *)
(* cfBigdprod defG phi == for phi : forall i, 'CF(A i), the class function *)
(* of 'CF(G) that maps x to \prod_(i | P i) phi i x_i, *)
(* where x_i is the (A i)-component of x : G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope cfun_scope.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Delimit Scope cfun_scope with CF.
Reserved Notation "''CF' ( G , A )" (format "''CF' ( G , A )").
Reserved Notation "''CF' ( G )" (format "''CF' ( G )").
Reserved Notation "''1_' G" (at level 8, G at level 2, format "''1_' G").
Reserved Notation "''Res[' H , G ]". (* only parsing *)
Reserved Notation "''Res[' H ]" (format "''Res[' H ]").
Reserved Notation "''Res'". (* only parsing *)
Reserved Notation "''Ind[' G , H ]". (* only parsing *)
Reserved Notation "''Ind[' G ]". (* only "''Ind[' G ]" *)
Reserved Notation "''Ind'". (* only parsing *)
Reserved Notation "'[ phi , psi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "'[ phi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "phi ^u" (format "phi ^u").
Section AlgC.
(* Arithmetic properties of group orders in the characteristic 0 field algC. *)
Variable (gT : finGroupType).
Implicit Types (G : {group gT}) (B : {set gT}).
Lemma neq0CG G : (#|G|)%:R != 0 :> algC. Proof. exact: natrG_neq0. Qed.
Lemma neq0CiG G B : (#|G : B|)%:R != 0 :> algC.
Proof. exact: natr_indexg_neq0. Qed.
Lemma gt0CG G : 0 < #|G|%:R :> algC. Proof. exact: natrG_gt0. Qed.
Lemma gt0CiG G B : 0 < #|G : B|%:R :> algC. Proof. exact: natr_indexg_gt0. Qed.
Lemma algC'G_pchar G : [pchar algC]^'.-group G.
Proof. by apply/pgroupP=> p _; rewrite inE /= pchar_num. Qed.
End AlgC.
#[deprecated(since="mathcomp 2.4.0", note="Use algC'G_pchar instead.")]
Notation algC'G := (algC'G_pchar) (only parsing).
Section Defs.
Variable gT : finGroupType.
Definition is_class_fun (B : {set gT}) (f : {ffun gT -> algC}) :=
[forall x, forall y in B, f (x ^ y) == f x] && (support f \subset B).
Lemma intro_class_fun (G : {group gT}) f :
{in G &, forall x y, f (x ^ y) = f x} ->
(forall x, x \notin G -> f x = 0) ->
is_class_fun G (finfun f).
Proof.
move=> fJ Gf; apply/andP; split; last first.
by apply/supportP=> x notAf; rewrite ffunE Gf.
apply/'forall_eqfun_inP=> x y Gy; rewrite !ffunE.
by have [/fJ-> // | notGx] := boolP (x \in G); rewrite !Gf ?groupJr.
Qed.
Variable B : {set gT}.
Local Notation G := <<B>>.
Record classfun : predArgType :=
Classfun {cfun_val; _ : is_class_fun G cfun_val}.
Implicit Types phi psi xi : classfun.
(* The default expansion lemma cfunE requires key = 0. *)
Fact classfun_key : unit. Proof. by []. Qed.
Definition Cfun := locked_with classfun_key (fun flag : nat => Classfun).
HB.instance Definition _ := [isSub for cfun_val].
HB.instance Definition _ := [Choice of classfun by <:].
Definition cfun_eqType : eqType := classfun.
Definition fun_of_cfun phi := cfun_val phi : gT -> algC.
Coercion fun_of_cfun : classfun >-> Funclass.
Lemma cfunElock k f fP : @Cfun k (finfun f) fP =1 f.
Proof. by rewrite locked_withE; apply: ffunE. Qed.
Lemma cfunE f fP : @Cfun 0 (finfun f) fP =1 f.
Proof. exact: cfunElock. Qed.
Lemma cfunP phi psi : phi =1 psi <-> phi = psi.
Proof. by split=> [/ffunP/val_inj | ->]. Qed.
Lemma cfun0gen phi x : x \notin G -> phi x = 0.
Proof. by case: phi => f fP; case: (andP fP) => _ /supportP; apply. Qed.
Lemma cfun_in_genP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof.
move=> eq_phi; apply/cfunP=> x.
by have [/eq_phi-> // | notAx] := boolP (x \in G); rewrite !cfun0gen.
Qed.
Lemma cfunJgen phi x y : y \in G -> phi (x ^ y) = phi x.
Proof.
case: phi => f fP Gy; apply/eqP.
by case: (andP fP) => /'forall_forall_inP->.
Qed.
Fact cfun_zero_subproof : is_class_fun G (0 : {ffun _}).
Proof. exact: intro_class_fun. Qed.
Definition cfun_zero := Cfun 0 cfun_zero_subproof.
Fact cfun_comp_subproof f phi :
f 0 = 0 -> is_class_fun G [ffun x => f (phi x)].
Proof.
by move=> f0; apply: intro_class_fun => [x y _ /cfunJgen | x /cfun0gen] ->.
Qed.
Definition cfun_comp f f0 phi := Cfun 0 (@cfun_comp_subproof f phi f0).
Definition cfun_opp := cfun_comp (oppr0 _).
Fact cfun_add_subproof phi psi : is_class_fun G [ffun x => phi x + psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite !cfun0gen ?add0r.
Qed.
Definition cfun_add phi psi := Cfun 0 (cfun_add_subproof phi psi).
Fact cfun_indicator_subproof (A : {set gT}) :
is_class_fun G [ffun x => ((x \in G) && (x ^: G \subset A))%:R].
Proof.
apply: intro_class_fun => [x y Gx Gy | x /negbTE/= -> //].
by rewrite groupJr ?classGidl.
Qed.
Definition cfun_indicator A := Cfun 1 (cfun_indicator_subproof A).
Local Notation "''1_' A" := (cfun_indicator A) : ring_scope.
Lemma cfun1Egen x : '1_G x = (x \in G)%:R.
Proof. by rewrite cfunElock andb_idr // => /class_subG->. Qed.
Fact cfun_mul_subproof phi psi : is_class_fun G [ffun x => phi x * psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite cfun0gen ?mul0r.
Qed.
Definition cfun_mul phi psi := Cfun 0 (cfun_mul_subproof phi psi).
Definition cfun_unit := [pred phi : classfun | [forall x in G, phi x != 0]].
Definition cfun_inv phi :=
if phi \in cfun_unit then cfun_comp (invr0 _) phi else phi.
Definition cfun_scale a := cfun_comp (mulr0 a).
Fact cfun_addA : associative cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE addrA. Qed.
Fact cfun_addC : commutative cfun_add.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE addrC. Qed.
Fact cfun_add0 : left_id cfun_zero cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE add0r. Qed.
Fact cfun_addN : left_inverse cfun_zero cfun_opp cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build classfun
cfun_addA cfun_addC cfun_add0 cfun_addN.
Lemma muln_cfunE phi n x : (phi *+ n) x = phi x *+ n.
Proof. by elim: n => [|n IHn]; rewrite ?mulrS !cfunE ?IHn. Qed.
Lemma sum_cfunE I r (P : pred I) (phi : I -> classfun) x :
(\sum_(i <- r | P i) phi i) x = \sum_(i <- r | P i) (phi i) x.
Proof. by elim/big_rec2: _ => [|i _ psi _ <-]; rewrite cfunE. Qed.
Fact cfun_mulA : associative cfun_mul.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_mulC : commutative cfun_mul.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE mulrC. Qed.
Fact cfun_mul1 : left_id '1_G cfun_mul.
Proof.
by move=> phi; apply: cfun_in_genP => x Gx; rewrite !cfunE cfun1Egen Gx mul1r.
Qed.
Fact cfun_mulD : left_distributive cfun_mul cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
Fact cfun_nz1 : '1_G != 0.
Proof.
by apply/eqP=> /cfunP/(_ 1%g)/eqP; rewrite cfun1Egen cfunE group1 oner_eq0.
Qed.
HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build classfun
cfun_mulA cfun_mulC cfun_mul1 cfun_mulD cfun_nz1.
Definition cfun_nzRingType : nzRingType := classfun.
#[deprecated(since="mathcomp 2.4.0",
note="Use cfun_nzRingType instead.")]
Notation cfun_ringType := (cfun_nzRingType) (only parsing).
Lemma expS_cfunE phi n x : (phi ^+ n.+1) x = phi x ^+ n.+1.
Proof. by elim: n => //= n IHn; rewrite !cfunE IHn. Qed.
Fact cfun_mulV : {in cfun_unit, left_inverse 1 cfun_inv *%R}.
Proof.
move=> phi Uphi; rewrite /cfun_inv Uphi; apply/cfun_in_genP=> x Gx.
by rewrite !cfunE cfun1Egen Gx mulVf ?(forall_inP Uphi).
Qed.
Fact cfun_unitP phi psi : psi * phi = 1 -> phi \in cfun_unit.
Proof.
move/cfunP=> phiK; apply/forall_inP=> x Gx; rewrite -unitfE; apply/unitrP.
by exists (psi x); have:= phiK x; rewrite !cfunE cfun1Egen Gx mulrC.
Qed.
Fact cfun_inv0id : {in [predC cfun_unit], cfun_inv =1 id}.
Proof. by rewrite /cfun_inv => phi /negbTE/= ->. Qed.
HB.instance Definition _ :=
GRing.ComNzRing_hasMulInverse.Build classfun cfun_mulV cfun_unitP cfun_inv0id.
Fact cfun_scaleA a b phi :
cfun_scale a (cfun_scale b phi) = cfun_scale (a * b) phi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scale1 : left_id 1 cfun_scale.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE mul1r. Qed.
Fact cfun_scaleDr : right_distributive cfun_scale +%R.
Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunE mulrDr. Qed.
Fact cfun_scaleDl phi : {morph cfun_scale^~ phi : a b / a + b}.
Proof. by move=> a b; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build algC classfun
cfun_scaleA cfun_scale1 cfun_scaleDr cfun_scaleDl.
Fact cfun_scaleAl a phi psi : a *: (phi * psi) = (a *: phi) * psi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scaleAr a phi psi : a *: (phi * psi) = phi * (a *: psi).
Proof. by rewrite !(mulrC phi) cfun_scaleAl. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build algC classfun
cfun_scaleAl.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build algC classfun
cfun_scaleAr.
Section Automorphism.
Variable u : {rmorphism algC -> algC}.
Definition cfAut := cfun_comp (rmorph0 u).
Lemma cfAut_cfun1i A : cfAut '1_A = '1_A.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cfAutZ a phi : cfAut (a *: phi) = u a *: cfAut phi.
Proof. by apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
Lemma cfAut_is_zmod_morphism : zmod_morphism cfAut.
Proof.
by move=> phi psi; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE /= rmorphB.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_zmod_morphism` instead")]
Definition cfAut_is_additive := cfAut_is_zmod_morphism.
Lemma cfAut_is_monoid_morphism : monoid_morphism cfAut.
Proof.
by split=> [|phi psi]; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE rmorphM.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_monoid_morphism` instead")]
Definition cfAut_is_multiplicative :=
(fun g => (g.2,g.1)) cfAut_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build classfun classfun cfAut
cfAut_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build classfun classfun cfAut
cfAut_is_monoid_morphism.
Lemma cfAut_cfun1 : cfAut 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfAut_scalable : scalable_for (u \; *:%R) cfAut.
Proof. by move=> a phi; apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build algC classfun classfun (u \; *:%R) cfAut
cfAut_scalable.
Definition cfAut_closed (S : seq classfun) :=
{in S, forall phi, cfAut phi \in S}.
End Automorphism.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Definition cfReal phi := cfAut conjC phi == phi.
Definition cfConjC_subset (S1 S2 : seq classfun) :=
[/\ uniq S1, {subset S1 <= S2} & cfAut_closed conjC S1].
Fact cfun_vect_iso : Vector.axiom #|classes G| classfun.
Proof.
exists (fun phi => \row_i phi (repr (enum_val i))) => [a phi psi|].
by apply/rowP=> i; rewrite !(mxE, cfunE).
set n := #|_|; pose eK x : 'I_n := enum_rank_in (classes1 _) (x ^: G).
have rV2vP v : is_class_fun G [ffun x => v (eK x) *+ (x \in G)].
apply: intro_class_fun => [x y Gx Gy | x /negbTE/=-> //].
by rewrite groupJr // /eK classGidl.
exists (fun v : 'rV_n => Cfun 0 (rV2vP (v 0))) => [phi | v].
apply/cfun_in_genP=> x Gx; rewrite cfunE Gx mxE enum_rankK_in ?mem_classes //.
by have [y Gy ->] := repr_class <<B>> x; rewrite cfunJgen.
apply/rowP=> i; rewrite mxE cfunE; have /imsetP[x Gx def_i] := enum_valP i.
rewrite def_i; have [y Gy ->] := repr_class <<B>> x.
by rewrite groupJ // /eK classGidl // -def_i enum_valK_in.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build algC classfun cfun_vect_iso.
Definition cfun_vectType : vectType _ := classfun.
Definition cfun_base A : #|classes B ::&: A|.-tuple classfun :=
[tuple of [seq '1_xB | xB in classes B ::&: A]].
Definition classfun_on A := <<cfun_base A>>%VS.
Definition cfdot phi psi := #|B|%:R^-1 * \sum_(x in B) phi x * (psi x)^*.
Definition cfdotr psi phi := cfdot phi psi.
Definition cfnorm phi := cfdot phi phi.
Coercion seq_of_cfun phi := [:: phi].
Definition cforder phi := \big[lcmn/1]_(x in <<B>>) #[phi x]%C.
End Defs.
Bind Scope cfun_scope with classfun.
Arguments classfun {gT} B%_g.
Arguments classfun_on {gT} B%_g A%_g.
Arguments cfun_indicator {gT} B%_g.
Arguments cfAut {gT B%_g} u phi%_CF.
Arguments cfReal {gT B%_g} phi%_CF.
Arguments cfdot {gT B%_g} phi%_CF psi%_CF.
Arguments cfdotr {gT B%_g} psi%_CF phi%_CF /.
Arguments cfnorm {gT B%_g} phi%_CF /.
Notation "''CF' ( G )" := (classfun G) : type_scope.
Notation "''CF' ( G )" := (@fullv _ (cfun_vectType G)) : vspace_scope.
Notation "''1_' A" := (cfun_indicator _ A) : ring_scope.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Notation "1" := (@GRing.one (cfun_nzRingType _)) (only parsing) : cfun_scope.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Notation "phi ^*" := (cfAut conjC phi) : cfun_scope.
Notation cfConjC_closed := (cfAut_closed conjC).
Prenex Implicits cfReal.
(* Workaround for overeager projection reduction. *)
Notation eqcfP := (@eqP (cfun_eqType _) _ _) (only parsing).
Notation "#[ phi ]" := (cforder phi) : cfun_scope.
Notation "''[' u , v ]_ G":= (@cfdot _ G u v) (only parsing) : ring_scope.
Notation "''[' u , v ]" := (cfdot u v) : ring_scope.
Notation "''[' u ]_ G" := '[u, u]_G (only parsing) : ring_scope.
Notation "''[' u ]" := '[u, u] : ring_scope.
Section Predicates.
Variables (gT rT : finGroupType) (D : {set gT}) (R : {set rT}).
Implicit Types (phi psi : 'CF(D)) (S : seq 'CF(D)) (tau : 'CF(D) -> 'CF(R)).
Definition cfker phi := [set x in D | [forall y, phi (x * y)%g == phi y]].
Definition cfaithful phi := cfker phi \subset [1].
Definition ortho_rec S1 S2 :=
all [pred phi | all [pred psi | '[phi, psi] == 0] S2] S1.
Definition orthogonal := ortho_rec.
Arguments orthogonal : simpl never.
Fixpoint pair_ortho_rec S :=
if S is psi :: S' then ortho_rec psi S' && pair_ortho_rec S' else true.
(* We exclude 0 from pairwise orthogonal sets. *)
Definition pairwise_orthogonal S := (0 \notin S) && pair_ortho_rec S.
Definition orthonormal S := all [pred psi | '[psi] == 1] S && pair_ortho_rec S.
Definition isometry tau := forall phi psi, '[tau phi, tau psi] = '[phi, psi].
Definition isometry_from_to mCFD tau mCFR :=
prop_in2 mCFD (inPhantom (isometry tau))
/\ prop_in1 mCFD (inPhantom (forall phi, in_mem (tau phi) mCFR)).
End Predicates.
Arguments orthogonal : simpl never.
Arguments cfker {gT D%_g} phi%_CF.
Arguments cfaithful {gT D%_g} phi%_CF.
Arguments orthogonal {gT D%_g} S1%_CF S2%_CF.
Arguments pairwise_orthogonal {gT D%_g} S%_CF.
Arguments orthonormal {gT D%_g} S%_CF.
Arguments isometry {gT rT D%_g R%_g} tau%_CF.
Notation "{ 'in' CFD , 'isometry' tau , 'to' CFR }" :=
(isometry_from_to (mem CFD) tau (mem CFR))
(format "{ 'in' CFD , 'isometry' tau , 'to' CFR }")
: type_scope.
Section ClassFun.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (A B : {set gT}) (H K : {group gT}) (phi psi xi : 'CF(G)).
Local Notation "''1_' A" := (cfun_indicator G A).
Lemma cfun0 phi x : x \notin G -> phi x = 0.
Proof. by rewrite -{1}(genGid G) => /(cfun0gen phi). Qed.
Lemma support_cfun phi : support phi \subset G.
Proof. by apply/subsetP=> g; apply: contraR => /cfun0->. Qed.
Lemma cfunJ phi x y : y \in G -> phi (x ^ y) = phi x.
Proof. by rewrite -{1}(genGid G) => /(cfunJgen phi)->. Qed.
Lemma cfun_repr phi x : phi (repr (x ^: G)) = phi x.
Proof. by have [y Gy ->] := repr_class G x; apply: cfunJ. Qed.
Lemma cfun_inP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof. by rewrite -{1}genGid => /cfun_in_genP. Qed.
Lemma cfuniE A x : A <| G -> '1_A x = (x \in A)%:R.
Proof.
case/andP=> sAG nAG; rewrite cfunElock genGid.
by rewrite class_sub_norm // andb_idl // => /(subsetP sAG).
Qed.
Lemma support_cfuni A : A <| G -> support '1_A =i A.
Proof. by move=> nsAG x; rewrite !inE cfuniE // pnatr_eq0 -lt0n lt0b. Qed.
Lemma eq_mul_cfuni A phi : A <| G -> {in A, phi * '1_A =1 phi}.
Proof. by move=> nsAG x Ax; rewrite cfunE cfuniE // Ax mulr1. Qed.
Lemma eq_cfuni A : A <| G -> {in A, '1_A =1 (1 : 'CF(G))}.
Proof. by rewrite -['1_A]mul1r; apply: eq_mul_cfuni. Qed.
Lemma cfuniG : '1_G = 1.
Proof. by rewrite -[G in '1_G]genGid. Qed.
Lemma cfun1E g : (1 : 'CF(G)) g = (g \in G)%:R.
Proof. by rewrite -cfuniG cfuniE. Qed.
Lemma cfun11 : (1 : 'CF(G)) 1%g = 1.
Proof. by rewrite cfun1E group1. Qed.
Lemma prod_cfunE I r (P : pred I) (phi : I -> 'CF(G)) x :
x \in G -> (\prod_(i <- r | P i) phi i) x = \prod_(i <- r | P i) (phi i) x.
Proof.
by move=> Gx; elim/big_rec2: _ => [|i _ psi _ <-]; rewrite ?cfunE ?cfun1E ?Gx.
Qed.
Lemma exp_cfunE phi n x : x \in G -> (phi ^+ n) x = phi x ^+ n.
Proof. by rewrite -[n]card_ord -!prodr_const; apply: prod_cfunE. Qed.
Lemma mul_cfuni A B : '1_A * '1_B = '1_(A :&: B) :> 'CF(G).
Proof.
apply/cfunP=> g; rewrite !cfunElock -natrM mulnb subsetI.
by rewrite andbCA !andbA andbb.
Qed.
Lemma cfun_classE x y : '1_(x ^: G) y = ((x \in G) && (y \in x ^: G))%:R.
Proof.
rewrite cfunElock genGid class_sub_norm ?class_norm //; congr (_ : bool)%:R.
by apply: andb_id2r => /imsetP[z Gz ->]; rewrite groupJr.
Qed.
Lemma cfun_on_sum A :
'CF(G, A) = (\sum_(xG in classes G | xG \subset A) <['1_xG]>)%VS.
Proof.
by rewrite ['CF(G, A)]span_def big_image; apply: eq_bigl => xG; rewrite !inE.
Qed.
Lemma cfun_onP A phi :
reflect (forall x, x \notin A -> phi x = 0) (phi \in 'CF(G, A)).
Proof.
apply: (iffP idP) => [/coord_span-> x notAx | Aphi].
set b := cfun_base G A; rewrite sum_cfunE big1 // => i _; rewrite cfunE.
have /mapP[xG]: b`_i \in b by rewrite -tnth_nth mem_tnth.
rewrite mem_enum => /setIdP[/imsetP[y Gy ->] Ay] ->.
by rewrite cfun_classE Gy (contraNF (subsetP Ay x)) ?mulr0.
suffices <-: \sum_(xG in classes G) phi (repr xG) *: '1_xG = phi.
apply: memv_suml => _ /imsetP[x Gx ->]; rewrite rpredZeq cfun_repr.
have [s_xG_A | /subsetPn[_ /imsetP[y Gy ->]]] := boolP (x ^: G \subset A).
by rewrite cfun_on_sum [_ \in _](sumv_sup (x ^: G)) ?mem_classes ?orbT.
by move/Aphi; rewrite cfunJ // => ->; rewrite eqxx.
apply/cfun_inP=> x Gx; rewrite sum_cfunE (bigD1 (x ^: G)) ?mem_classes //=.
rewrite cfunE cfun_repr cfun_classE Gx class_refl mulr1.
rewrite big1 ?addr0 // => _ /andP[/imsetP[y Gy ->]]; apply: contraNeq.
rewrite cfunE cfun_repr cfun_classE Gy mulf_eq0 => /norP[_].
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Arguments cfun_onP {A phi}.
Lemma cfun_on0 A phi x : phi \in 'CF(G, A) -> x \notin A -> phi x = 0.
Proof. by move/cfun_onP; apply. Qed.
Lemma sum_by_classes (R : nzRingType) (F : gT -> R) :
{in G &, forall g h, F (g ^ h) = F g} ->
\sum_(g in G) F g = \sum_(xG in classes G) #|xG|%:R * F (repr xG).
Proof.
move=> FJ; rewrite {1}(partition_big _ _ ((@mem_classes gT)^~ G)) /=.
apply: eq_bigr => _ /imsetP[x Gx ->]; have [y Gy ->] := repr_class G x.
rewrite mulr_natl -sumr_const FJ {y Gy}//; apply/esym/eq_big=> y /=.
apply/idP/andP=> [xGy | [Gy /eqP<-]]; last exact: class_refl.
by rewrite (class_eqP xGy) (subsetP (class_subG Gx (subxx _))).
by case/imsetP=> z Gz ->; rewrite FJ.
Qed.
Lemma cfun_base_free A : free (cfun_base G A).
Proof.
have b_i (i : 'I_#|classes G ::&: A|) : (cfun_base G A)`_i = '1_(enum_val i).
by rewrite /enum_val -!tnth_nth tnth_map.
apply/freeP => s S0 i; move/cfunP/(_ (repr (enum_val i))): S0.
rewrite sum_cfunE (bigD1 i) //= big1 ?addr0 => [|j].
rewrite b_i !cfunE; have /setIdP[/imsetP[x Gx ->] _] := enum_valP i.
by rewrite cfun_repr cfun_classE Gx class_refl mulr1.
apply: contraNeq; rewrite b_i !cfunE mulf_eq0 => /norP[_].
rewrite -(inj_eq enum_val_inj).
have /setIdP[/imsetP[x _ ->] _] := enum_valP i; rewrite cfun_repr.
have /setIdP[/imsetP[y Gy ->] _] := enum_valP j; rewrite cfun_classE Gy.
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Lemma dim_cfun : \dim 'CF(G) = #|classes G|.
Proof. by rewrite dimvf /dim /= genGid. Qed.
Lemma dim_cfun_on A : \dim 'CF(G, A) = #|classes G ::&: A|.
Proof. by rewrite (eqnP (cfun_base_free A)) size_tuple. Qed.
Lemma dim_cfun_on_abelian A : abelian G -> A \subset G -> \dim 'CF(G, A) = #|A|.
Proof.
move/abelian_classP=> cGG sAG; rewrite -(card_imset _ set1_inj) dim_cfun_on.
apply/eq_card=> xG; rewrite !inE.
apply/andP/imsetP=> [[/imsetP[x Gx ->] Ax] | [x Ax ->]] {xG}.
by rewrite cGG ?sub1set // in Ax *; exists x.
by rewrite -{1}(cGG x) ?mem_classes ?(subsetP sAG) ?sub1set.
Qed.
Lemma cfuni_on A : '1_A \in 'CF(G, A).
Proof.
apply/cfun_onP=> x notAx; rewrite cfunElock genGid.
by case: andP => // [[_ s_xG_A]]; rewrite (subsetP s_xG_A) ?class_refl in notAx.
Qed.
Lemma mul_cfuni_on A phi : phi * '1_A \in 'CF(G, A).
Proof.
by apply/cfun_onP=> x /(cfun_onP (cfuni_on A)) Ax0; rewrite cfunE Ax0 mulr0.
Qed.
Lemma cfun_onE phi A : (phi \in 'CF(G, A)) = (support phi \subset A).
Proof. exact: (sameP cfun_onP supportP). Qed.
Lemma cfun_onT phi : phi \in 'CF(G, [set: gT]).
Proof. by rewrite cfun_onE. Qed.
Lemma cfun_onD1 phi A :
(phi \in 'CF(G, A^#)) = (phi \in 'CF(G, A)) && (phi 1%g == 0).
Proof.
by rewrite !cfun_onE -!(eq_subset (in_set (support _))) subsetD1 !inE negbK.
Qed.
Lemma cfun_onG phi : phi \in 'CF(G, G).
Proof. by rewrite cfun_onE support_cfun. Qed.
Lemma cfunD1E phi : (phi \in 'CF(G, G^#)) = (phi 1%g == 0).
Proof. by rewrite cfun_onD1 cfun_onG. Qed.
Lemma cfunGid : 'CF(G, G) = 'CF(G)%VS.
Proof. by apply/vspaceP=> phi; rewrite cfun_onG memvf. Qed.
Lemma cfun_onS A B phi : B \subset A -> phi \in 'CF(G, B) -> phi \in 'CF(G, A).
Proof. by rewrite !cfun_onE => sBA /subset_trans->. Qed.
Lemma cfun_complement A :
A <| G -> ('CF(G, A) + 'CF(G, G :\: A)%SET = 'CF(G))%VS.
Proof.
case/andP=> sAG nAG; rewrite -cfunGid [rhs in _ = rhs]cfun_on_sum.
rewrite (bigID (fun B => B \subset A)) /=.
congr (_ + _)%VS; rewrite cfun_on_sum; apply: eq_bigl => /= xG.
rewrite andbAC; apply/esym/andb_idr=> /andP[/imsetP[x Gx ->] _].
by rewrite class_subG.
rewrite -andbA; apply: andb_id2l => /imsetP[x Gx ->].
by rewrite !class_sub_norm ?normsD ?normG // inE andbC.
Qed.
Lemma cfConjCE phi x : ( phi^* )%CF x = (phi x)^*.
Proof. by rewrite cfunE. Qed.
Lemma cfConjCK : involutive (fun phi => phi^* )%CF.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= conjCK. Qed.
Lemma cfConjC_cfun1 : ( 1^* )%CF = 1 :> 'CF(G).
Proof. exact: rmorph1. Qed.
(* Class function kernel and faithful class functions *)
Fact cfker_is_group phi : group_set (cfker phi).
Proof.
apply/group_setP; split=> [|x y]; rewrite !inE ?group1.
by apply/forallP=> y; rewrite mul1g.
case/andP=> Gx /forallP-Kx /andP[Gy /forallP-Ky]; rewrite groupM //.
by apply/forallP=> z; rewrite -mulgA (eqP (Kx _)) Ky.
Qed.
Canonical cfker_group phi := Group (cfker_is_group phi).
Lemma cfker_sub phi : cfker phi \subset G.
Proof. by rewrite /cfker setIdE subsetIl. Qed.
Lemma cfker_norm phi : G \subset 'N(cfker phi).
Proof.
apply/subsetP=> z Gz; have phiJz := cfunJ phi _ (groupVr Gz).
rewrite inE; apply/subsetP=> _ /imsetP[x /setIdP[Gx /forallP-Kx] ->].
rewrite inE groupJ //; apply/forallP=> y.
by rewrite -(phiJz y) -phiJz conjMg conjgK Kx.
Qed.
Lemma cfker_normal phi : cfker phi <| G.
Proof. by rewrite /normal cfker_sub cfker_norm. Qed.
Lemma cfkerMl phi x y : x \in cfker phi -> phi (x * y)%g = phi y.
Proof. by case/setIdP=> _ /eqfunP->. Qed.
Lemma cfkerMr phi x y : x \in cfker phi -> phi (y * x)%g = phi y.
Proof.
by move=> Kx; rewrite conjgC cfkerMl ?cfunJ ?(subsetP (cfker_sub phi)).
Qed.
Lemma cfker1 phi x : x \in cfker phi -> phi x = phi 1%g.
Proof. by move=> Kx; rewrite -[x]mulg1 cfkerMl. Qed.
Lemma cfker_cfun0 : @cfker _ G 0 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfunE.
Qed.
Lemma cfker_add phi psi : cfker phi :&: cfker psi \subset cfker (phi + psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_sum I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\sum_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun0.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_add _ _).
Qed.
Lemma cfker_scale a phi : cfker phi \subset cfker (a *: phi).
Proof.
apply/subsetP=> x Kphi_x; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE cfkerMl.
Qed.
Lemma cfker_scale_nz a phi : a != 0 -> cfker (a *: phi) = cfker phi.
Proof.
move=> nz_a; apply/eqP.
by rewrite eqEsubset -{2}(scalerK nz_a phi) !cfker_scale.
Qed.
Lemma cfker_opp phi : cfker (- phi) = cfker phi.
Proof. by rewrite -scaleN1r cfker_scale_nz // oppr_eq0 oner_eq0. Qed.
Lemma cfker_cfun1 : @cfker _ G 1 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfun1E groupMl.
Qed.
Lemma cfker_mul phi psi : cfker phi :&: cfker psi \subset cfker (phi * psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_prod I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\prod_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun1.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_mul _ _).
Qed.
Lemma cfaithfulE phi : cfaithful phi = (cfker phi \subset [1]).
Proof. by []. Qed.
End ClassFun.
Arguments classfun_on {gT} B%_g A%_g.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Arguments cfun_onP {gT G A phi}.
Arguments cfConjCK {gT G} phi : rename.
#[global] Hint Resolve cfun_onT : core.
Section DotProduct.
Variable (gT : finGroupType) (G : {group gT}).
Implicit Types (M : {group gT}) (phi psi xi : 'CF(G)) (R S : seq 'CF(G)).
Lemma cfdotE phi psi :
'[phi, psi] = #|G|%:R^-1 * \sum_(x in G) phi x * (psi x)^*.
Proof. by []. Qed.
Lemma cfdotElr A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A :&: B) phi x * (psi x)^*.
Proof.
move=> Aphi Bpsi; rewrite (big_setID G)/= cfdotE (big_setID (A :&: B))/= setIC.
congr (_ * (_ + _)); rewrite !big1 // => x /setDP[_].
by move/cfun0->; rewrite mul0r.
rewrite inE; case/nandP=> notABx; first by rewrite (cfun_on0 Aphi) ?mul0r.
by rewrite (cfun_on0 Bpsi) // rmorph0 mulr0.
Qed.
Lemma cfdotEl A phi psi :
phi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Aphi; rewrite (cfdotElr Aphi (cfun_onT psi)) setIT. Qed.
Lemma cfdotEr A phi psi :
psi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Apsi; rewrite (cfdotElr (cfun_onT phi) Apsi) setTI. Qed.
Lemma cfdot_complement A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, G :\: A) -> '[phi, psi] = 0.
Proof.
move=> Aphi A'psi; rewrite (cfdotElr Aphi A'psi).
by rewrite setDE setICA setICr setI0 big_set0 mulr0.
Qed.
Lemma cfnormE A phi :
phi \in 'CF(G, A) -> '[phi] = #|G|%:R^-1 * (\sum_(x in A) `|phi x| ^+ 2).
Proof. by move/cfdotEl->; rewrite (eq_bigr _ (fun _ _ => normCK _)). Qed.
Lemma eq_cfdotl A phi1 phi2 psi :
psi \in 'CF(G, A) -> {in A, phi1 =1 phi2} -> '[phi1, psi] = '[phi2, psi].
Proof.
move/cfdotEr=> eq_dot eq_phi; rewrite !eq_dot; congr (_ * _).
by apply: eq_bigr => x Ax; rewrite eq_phi.
Qed.
Lemma cfdot_cfuni A B :
A <| G -> B <| G -> '['1_A, '1_B]_G = #|A :&: B|%:R / #|G|%:R.
Proof.
move=> nsAG nsBG; rewrite (cfdotElr (cfuni_on G A) (cfuni_on G B)) mulrC.
congr (_ / _); rewrite -sumr_const; apply: eq_bigr => x /setIP[Ax Bx].
by rewrite !cfuniE // Ax Bx mul1r rmorph1.
Qed.
Lemma cfnorm1 : '[1]_G = 1.
Proof. by rewrite cfdot_cfuni ?genGid // setIid divff ?neq0CG. Qed.
Lemma cfdotrE psi phi : cfdotr psi phi = '[phi, psi]. Proof. by []. Qed.
Lemma cfdotr_is_linear xi : linear (cfdotr xi : 'CF(G) -> algC^o).
Proof.
move=> a phi psi; rewrite scalerAr -mulrDr; congr (_ * _).
rewrite linear_sum -big_split; apply: eq_bigr => x _ /=.
by rewrite !cfunE mulrDl -mulrA.
Qed.
HB.instance Definition _ xi := GRing.isSemilinear.Build algC _ _ _ (cfdotr xi)
(GRing.semilinear_linear (cfdotr_is_linear xi)).
Lemma cfdot0l xi : '[0, xi] = 0.
Proof. by rewrite -cfdotrE linear0. Qed.
Lemma cfdotNl xi phi : '[- phi, xi] = - '[phi, xi].
Proof. by rewrite -!cfdotrE linearN. Qed.
Lemma cfdotDl xi phi psi : '[phi + psi, xi] = '[phi, xi] + '[psi, xi].
Proof. by rewrite -!cfdotrE linearD. Qed.
Lemma cfdotBl xi phi psi : '[phi - psi, xi] = '[phi, xi] - '[psi, xi].
Proof. by rewrite -!cfdotrE linearB. Qed.
Lemma cfdotMnl xi phi n : '[phi *+ n, xi] = '[phi, xi] *+ n.
Proof. by rewrite -!cfdotrE linearMn. Qed.
Lemma cfdot_suml xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[\sum_(i <- r | P i) phi i, xi] = \sum_(i <- r | P i) '[phi i, xi].
Proof. by rewrite -!cfdotrE linear_sum. Qed.
Lemma cfdotZl xi a phi : '[a *: phi, xi] = a * '[phi, xi].
Proof. by rewrite -!cfdotrE linearZ. Qed.
Lemma cfdotC phi psi : '[phi, psi] = ('[psi, phi])^*.
Proof.
rewrite /cfdot rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr=> x _; rewrite rmorphM /= conjCK mulrC.
Qed.
Lemma eq_cfdotr A phi psi1 psi2 :
phi \in 'CF(G, A) -> {in A, psi1 =1 psi2} -> '[phi, psi1] = '[phi, psi2].
Proof. by move=> Aphi /eq_cfdotl eq_dot; rewrite cfdotC eq_dot // -cfdotC. Qed.
Lemma cfdotBr xi phi psi : '[xi, phi - psi] = '[xi, phi] - '[xi, psi].
Proof. by rewrite !(cfdotC xi) -rmorphB cfdotBl. Qed.
HB.instance Definition _ xi :=
GRing.isZmodMorphism.Build _ _ (cfdot xi) (cfdotBr xi).
Lemma cfdot0r xi : '[xi, 0] = 0. Proof. exact: raddf0. Qed.
Lemma cfdotNr xi phi : '[xi, - phi] = - '[xi, phi].
Proof. exact: raddfN. Qed.
Lemma cfdotDr xi phi psi : '[xi, phi + psi] = '[xi, phi] + '[xi, psi].
Proof. exact: raddfD. Qed.
Lemma cfdotMnr xi phi n : '[xi, phi *+ n] = '[xi, phi] *+ n.
Proof. exact: raddfMn. Qed.
Lemma cfdot_sumr xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[xi, \sum_(i <- r | P i) phi i] = \sum_(i <- r | P i) '[xi, phi i].
Proof. exact: raddf_sum. Qed.
Lemma cfdotZr a xi phi : '[xi, a *: phi] = a^* * '[xi, phi].
Proof. by rewrite !(cfdotC xi) cfdotZl rmorphM. Qed.
Lemma cfdot_cfAut (u : {rmorphism algC -> algC}) phi psi :
{in image psi G, {morph u : x / x^*}} ->
'[cfAut u phi, cfAut u psi] = u '[phi, psi].
Proof.
move=> uC; rewrite rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr => x Gx; rewrite !cfunE rmorphM /= uC ?map_f ?mem_enum.
Qed.
Lemma cfdot_conjC phi psi : '[phi^*, psi^*] = '[phi, psi]^*.
Proof. by rewrite cfdot_cfAut. Qed.
Lemma cfdot_conjCl phi psi : '[phi^*, psi] = '[phi, psi^*]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfdot_conjCr phi psi : '[phi, psi^*] = '[phi^*, psi]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfnorm_ge0 phi : 0 <= '[phi].
Proof.
by rewrite mulr_ge0 ?invr_ge0 ?ler0n ?sumr_ge0 // => x _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_eq0 phi : ('[phi] == 0) = (phi == 0).
Proof.
apply/idP/eqP=> [|->]; last by rewrite cfdot0r.
rewrite mulf_eq0 invr_eq0 (negbTE (neq0CG G)) /= => /eqP/psumr_eq0P phi0.
apply/cfun_inP=> x Gx; apply/eqP; rewrite cfunE -mul_conjC_eq0.
by rewrite phi0 // => y _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_gt0 phi : ('[phi] > 0) = (phi != 0).
Proof. by rewrite lt_def cfnorm_ge0 cfnorm_eq0 andbT. Qed.
Lemma sqrt_cfnorm_ge0 phi : 0 <= sqrtC '[phi].
Proof. by rewrite sqrtC_ge0 cfnorm_ge0. Qed.
Lemma sqrt_cfnorm_eq0 phi : (sqrtC '[phi] == 0) = (phi == 0).
Proof. by rewrite sqrtC_eq0 cfnorm_eq0. Qed.
Lemma sqrt_cfnorm_gt0 phi : (sqrtC '[phi] > 0) = (phi != 0).
Proof. by rewrite sqrtC_gt0 cfnorm_gt0. Qed.
Lemma cfnormZ a phi : '[a *: phi]= `|a| ^+ 2 * '[phi]_G.
Proof. by rewrite cfdotZl cfdotZr mulrA normCK. Qed.
Lemma cfnormN phi : '[- phi] = '[phi].
Proof. by rewrite cfdotNl raddfN opprK. Qed.
Lemma cfnorm_sign n phi : '[(-1) ^+ n *: phi] = '[phi].
Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?cfnormN. Qed.
Lemma cfnormD phi psi :
let d := '[phi, psi] in '[phi + psi] = '[phi] + '[psi] + ( d + d^* ).
Proof. by rewrite /= addrAC -cfdotC cfdotDl !cfdotDr !addrA. Qed.
Lemma cfnormB phi psi :
let d := '[phi, psi] in '[phi - psi] = '[phi] + '[psi] - ( d + d^* ).
Proof. by rewrite /= cfnormD cfnormN cfdotNr rmorphN -opprD. Qed.
Lemma cfnormDd phi psi : '[phi, psi] = 0 -> '[phi + psi] = '[phi] + '[psi].
Proof. by move=> ophipsi; rewrite cfnormD ophipsi rmorph0 !addr0. Qed.
Lemma cfnormBd phi psi : '[phi, psi] = 0 -> '[phi - psi] = '[phi] + '[psi].
Proof.
by move=> ophipsi; rewrite cfnormDd ?cfnormN // cfdotNr ophipsi oppr0.
Qed.
Lemma cfnorm_conjC phi : '[phi^*] = '[phi].
Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed.
Lemma cfCauchySchwarz phi psi :
`|'[phi, psi]| ^+ 2 <= '[phi] * '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_psi] /= := eqVneq psi 0.
by apply/leifP; rewrite !cfdot0r normCK mul0r mulr0.
without loss ophi: phi / '[phi, psi] = 0.
move=> IHo; pose a := '[phi, psi] / '[psi]; pose phi1 := phi - a *: psi.
have ophi: '[phi1, psi] = 0.
by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr.
rewrite (canRL (subrK _) (erefl phi1)) rpredDr ?rpredZ ?memv_line //.
rewrite cfdotDl ophi add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)).
rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ophi mulr0.
by have:= IHo _ ophi; rewrite mulrDl -leifBLR subrr ophi normCK mul0r.
rewrite ophi normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0.
rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_psi) /=.
apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ophi mulr0.
by rewrite cfnorm_eq0 => /eqP->; apply: rpred0.
Qed.
Lemma cfCauchySchwarz_sqrt phi psi :
`|'[phi, psi]| <= sqrtC '[phi] * sqrtC '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?qualifE/= ?cfnorm_ge0 //.
rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM ?qualifE/= ?cfnorm_ge0 //;
[ exact: cfCauchySchwarz | exact: O.. ].
Qed.
Lemma cf_triangle_leif phi psi :
sqrtC '[phi + psi] <= sqrtC '[phi] + sqrtC '[psi]
?= iff ~~ free (phi :: psi) && (0 <= coord [tuple psi] 0 phi).
Proof.
rewrite -(mono_in_leif ler_sqr) ?rpredD ?qualifE/= ?sqrtC_ge0 ?cfnorm_ge0 //;
[| exact: O.. ].
rewrite andbC sqrrD !sqrtCK addrAC cfnormD (mono_leif (lerD2l _)).
rewrite -mulr_natr -[_ + _](divfK (negbT (eqC_nat 2 0))) -/('Re _).
rewrite (mono_leif (ler_pM2r _)) ?ltr0n //.
have:= leif_trans (leif_Re_Creal '[phi, psi]) (cfCauchySchwarz_sqrt phi psi).
congr (_ <= _ ?= iff _); first by rewrite ReE.
apply: andb_id2r; rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC /=.
have [-> | nz_psi] := eqVneq psi 0; first by rewrite cfdot0r coord0.
case/vlineP=> [x ->]; rewrite cfdotZl linearZ pmulr_lge0 ?cfnorm_gt0 //=.
by rewrite (coord_free 0) ?seq1_free // eqxx mulr1.
Qed.
Lemma orthogonal_cons phi R S :
orthogonal (phi :: R) S = orthogonal phi S && orthogonal R S.
Proof. by rewrite /orthogonal /= andbT. Qed.
Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal phi psi).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthogonalP S R :
reflect {in S & R, forall phi psi, '[phi, psi] = 0} (orthogonal S R).
Proof.
apply: (iffP allP) => oSR phi => [psi /oSR/allP opS /opS/eqP // | /oSR opS].
by apply/allP=> psi /= /opS->.
Qed.
Lemma orthoPl phi S :
reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal phi S).
Proof.
by rewrite [orthogonal _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP.
Qed.
Arguments orthoPl {phi S}.
Lemma orthogonal_sym : symmetric (@orthogonal _ G).
Proof.
apply: symmetric_from_pre => R S /orthogonalP oRS.
by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite cfdotC oRS ?rmorph0.
Qed.
Lemma orthoPr S psi :
reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal S psi).
Proof.
rewrite orthogonal_sym.
by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite cfdotC oSpsi ?conjC0.
Qed.
Lemma eq_orthogonal R1 R2 S1 S2 :
R1 =i R2 -> S1 =i S2 -> orthogonal R1 S1 = orthogonal R2 S2.
Proof.
move=> eqR eqS; rewrite [orthogonal _ _](eq_all_r eqR).
by apply: eq_all => psi /=; apply: eq_all_r.
Qed.
Lemma orthogonal_catl R1 R2 S :
orthogonal (R1 ++ R2) S = orthogonal R1 S && orthogonal R2 S.
Proof. exact: all_cat. Qed.
Lemma orthogonal_catr R S1 S2 :
orthogonal R (S1 ++ S2) = orthogonal R S1 && orthogonal R S2.
Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed.
Lemma span_orthogonal S1 S2 phi1 phi2 :
orthogonal S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS ->
'[phi1, phi2] = 0.
Proof.
move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->.
rewrite cfdot_suml big1 // => i _; rewrite cfdot_sumr big1 // => j _.
by rewrite cfdotZl cfdotZr oS12 ?mem_nth ?mulr0.
Qed.
Lemma orthogonal_split S beta :
{X : 'CF(G) & X \in <<S>>%VS &
{Y | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal Y S]}}.
Proof.
suffices [X S_X [Y -> oYS]]:
{X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal Y S}}.
- exists X => //; exists Y.
by rewrite cfdotC (span_orthogonal oYS) ?memv_span1 ?conjC0.
elim: S beta => [|phi S IHS] beta.
by exists 0; last exists beta; rewrite ?mem0v ?add0r.
have [[U S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta).
pose Z := '[Y, V] / '[V] *: V; exists (X + Z).
rewrite /Z -{4}(addKr U V) scalerDr scalerN addrA addrC span_cons.
by rewrite memv_add ?memvB ?memvZ ?memv_line.
exists (Y - Z); first by rewrite addrCA !addrA addrK addrC.
apply/orthoPl=> psi /[!inE] /predU1P[-> | Spsi]; last first.
by rewrite cfdotBl cfdotZl (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS).
rewrite cfdotBl !cfdotDr (span_orthogonal oYS) // ?memv_span ?mem_head //.
rewrite !cfdotZl (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //.
have [-> | nzV] := eqVneq V 0; first by rewrite cfdot0r !mul0r subrr.
by rewrite divfK ?cfnorm_eq0 ?subrr.
Qed.
Lemma map_orthogonal M (nu : 'CF(G) -> 'CF(M)) S R (A : {pred 'CF(G)}) :
{in A &, isometry nu} -> {subset S <= A} -> {subset R <= A} ->
orthogonal (map nu S) (map nu R) = orthogonal S R.
Proof.
move=> Inu sSA sRA; rewrite [orthogonal _ _]all_map.
apply: eq_in_all => phi Sphi; rewrite /= all_map.
by apply: eq_in_all => psi Rpsi; rewrite /= Inu ?(sSA phi) ?(sRA psi).
Qed.
Lemma orthogonal_oppr S R : orthogonal S (map -%R R) = orthogonal S R.
Proof.
wlog suffices IH: S R / orthogonal S R -> orthogonal S (map -%R R).
by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK.
move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->].
by rewrite cfdotNr oSR ?oppr0.
Qed.
Lemma orthogonal_oppl S R : orthogonal (map -%R S) R = orthogonal S R.
Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed.
Lemma pairwise_orthogonalP S :
reflect (uniq (0 :: S)
/\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0})
(pairwise_orthogonal S).
Proof.
rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case.
elim: S notS0 => [|phi S IH] /=; first by left.
rewrite inE eq_sym andbT => /norP[nz_phi /IH{}IH].
have [opS | not_opS] := allP; last first.
right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=.
by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp).
rewrite (contra (opS _)) /= ?cfnorm_eq0 //.
apply: (iffP IH) => [] [uniqS oSS]; last first.
by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead.
split=> // psi xi /[!inE] /predU1P[-> // | Spsi].
by case/predU1P=> [-> | /opS] /eqP.
case/predU1P=> [-> _ | Sxi /oSS-> //].
by apply/eqP; rewrite cfdotC conjC_eq0 [_ == 0]opS.
Qed.
Lemma pairwise_orthogonal_cat R S :
pairwise_orthogonal (R ++ S) =
[&& pairwise_orthogonal R, pairwise_orthogonal S & orthogonal R S].
Proof.
rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr.
elim: R => [|phi R /= ->]; rewrite ?andbT // orthogonal_cons all_cat -!andbA /=.
by do !bool_congr.
Qed.
Lemma eq_pairwise_orthogonal R S :
perm_eq R S -> pairwise_orthogonal R = pairwise_orthogonal S.
Proof.
apply: catCA_perm_subst R S => R S S'.
rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA.
by do !bool_congr.
Qed.
Lemma sub_pairwise_orthogonal S1 S2 :
{subset S1 <= S2} -> uniq S1 ->
pairwise_orthogonal S2 -> pairwise_orthogonal S1.
Proof.
move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2].
apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //.
by split=> //; apply: sub_in2 oS2.
Qed.
Lemma orthogonal_free S : pairwise_orthogonal S -> free S.
Proof.
case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS].
rewrite -(in_tupleE S); apply/freeP => a aS0 i.
have S_i: S`_i \in S by apply: mem_nth.
have /eqP: '[S`_i, 0]_G = 0 := cfdot0r _.
rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first.
by rewrite cfdotZr oSS ?mulr0 ?mem_nth // eq_sym nth_uniq.
rewrite addr0 cfdotZr mulf_eq0 conjC_eq0 cfnorm_eq0.
by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0.
Qed.
Lemma filter_pairwise_orthogonal S p :
pairwise_orthogonal S -> pairwise_orthogonal (filter p S).
Proof.
move=> orthoS; apply: sub_pairwise_orthogonal (orthoS).
exact: mem_subseq (filter_subseq p S).
exact/filter_uniq/free_uniq/orthogonal_free.
Qed.
Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S.
Proof.
by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= cfdot0r eq_sym oner_eq0.
Qed.
Lemma orthonormalE S :
orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S.
Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed.
Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S.
Proof. by rewrite orthonormalE => /andP[_]. Qed.
Lemma orthonormal_cat R S :
orthonormal (R ++ S) = [&& orthonormal R, orthonormal S & orthogonal R S].
Proof.
rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA.
by do !bool_congr.
Qed.
Lemma eq_orthonormal R S : perm_eq R S -> orthonormal R = orthonormal S.
Proof.
move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)).
by rewrite (eq_pairwise_orthogonal eqRS).
Qed.
Lemma orthonormal_free S : orthonormal S -> free S.
Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed.
Lemma orthonormalP S :
reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi]_G = (phi == psi)%:R})
(orthonormal S).
Proof.
rewrite orthonormalE; have [/= normS | not_normS] := allP; last first.
by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx.
apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS].
split=> // [|phi psi]; first by case/andP: uniqS.
by have [-> _ /normS/eqP | /oSS] := eqVneq.
split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->.
by rewrite /= (contra (normS _)) // cfdot0r eq_sym oner_eq0.
Qed.
Lemma sub_orthonormal S1 S2 :
{subset S1 <= S2} -> uniq S1 -> orthonormal S2 -> orthonormal S1.
Proof.
move=> sS12 uniqS1 /orthonormalP[_ oS1].
by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _.
Qed.
Lemma orthonormal2P phi psi :
reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1]
(orthonormal [:: phi; psi]).
Proof.
rewrite /orthonormal /= !andbT andbC.
by apply: (iffP and3P) => [] []; do 3!move/eqP->.
Qed.
Lemma conjC_pair_orthogonal S chi :
cfConjC_closed S -> ~~ has cfReal S -> pairwise_orthogonal S -> chi \in S ->
pairwise_orthogonal (chi :: chi^*%CF).
Proof.
move=> ccS /hasPn nrS oSS Schi; apply: sub_pairwise_orthogonal oSS.
by apply/allP; rewrite /= Schi ccS.
by rewrite /= inE eq_sym nrS.
Qed.
Lemma cfdot_real_conjC phi psi : cfReal phi -> '[phi, psi^*]_G = '[phi, psi]^*.
Proof. by rewrite -cfdot_conjC => /eqcfP->. Qed.
Lemma extend_cfConjC_subset S X phi :
cfConjC_closed S -> ~~ has cfReal S -> phi \in S -> phi \notin X ->
cfConjC_subset X S -> cfConjC_subset [:: phi, phi^* & X]%CF S.
Proof.
move=> ccS nrS Sphi X'phi [uniqX /allP-sXS ccX].
split; last 1 [by apply/allP; rewrite /= Sphi ccS | apply/allP]; rewrite /= inE.
by rewrite negb_or X'phi eq_sym (hasPn nrS) // (contra (ccX _)) ?cfConjCK.
by rewrite cfConjCK !mem_head orbT; apply/allP=> xi Xxi; rewrite !inE ccX ?orbT.
Qed.
(* Note: other isometry lemmas, and the dot product lemmas for orthogonal *)
(* and orthonormal sequences are in vcharacter, because we need the 'Z[S] *)
(* notation for the isometry domains. Alternatively, this could be moved to *)
(* cfun. *)
End DotProduct.
Arguments orthoP {gT G phi psi}.
Arguments orthoPl {gT G phi S}.
Arguments orthoPr {gT G S psi}.
Arguments orthogonalP {gT G S R}.
Arguments pairwise_orthogonalP {gT G S}.
Arguments orthonormalP {gT G S}.
Section CfunOrder.
Variables (gT : finGroupType) (G : {group gT}) (phi : 'CF(G)).
Lemma dvdn_cforderP n :
reflect {in G, forall x, phi x ^+ n = 1} (#[phi]%CF %| n)%N.
Proof.
apply: (iffP (dvdn_biglcmP _ _ _)); rewrite genGid => phiG1 x Gx.
by apply/eqP; rewrite -dvdn_orderC phiG1.
by rewrite dvdn_orderC phiG1.
Qed.
Lemma dvdn_cforder n : (#[phi]%CF %| n) = (phi ^+ n == 1).
Proof.
apply/dvdn_cforderP/eqP=> phi_n_1 => [|x Gx].
by apply/cfun_inP=> x Gx; rewrite exp_cfunE // cfun1E Gx phi_n_1.
by rewrite -exp_cfunE // phi_n_1 // cfun1E Gx.
Qed.
Lemma exp_cforder : phi ^+ #[phi]%CF = 1.
Proof. by apply/eqP; rewrite -dvdn_cforder. Qed.
End CfunOrder.
Arguments dvdn_cforderP {gT G phi n}.
Section MorphOrder.
Variables (aT rT : finGroupType) (G : {group aT}) (R : {group rT}).
Variable f : {rmorphism 'CF(G) -> 'CF(R)}.
Lemma cforder_rmorph phi : #[f phi]%CF %| #[phi]%CF.
Proof. by rewrite dvdn_cforder -rmorphXn exp_cforder rmorph1. Qed.
Lemma cforder_inj_rmorph phi : injective f -> #[f phi]%CF = #[phi]%CF.
Proof.
move=> inj_f; apply/eqP; rewrite eqn_dvd cforder_rmorph dvdn_cforder /=.
by rewrite -(rmorph_eq1 _ inj_f) rmorphXn exp_cforder.
Qed.
End MorphOrder.
Section BuildIsometries.
Variable (gT : finGroupType) (L G : {group gT}).
Implicit Types (phi psi xi : 'CF(L)) (R S : seq 'CF(L)).
Implicit Types (U : {pred 'CF(L)}) (W : {pred 'CF(G)}).
Lemma sub_iso_to U1 U2 W1 W2 tau :
{subset U2 <= U1} -> {subset W1 <= W2} ->
{in U1, isometry tau, to W1} -> {in U2, isometry tau, to W2}.
Proof.
by move=> sU sW [Itau Wtau]; split=> [|u /sU/Wtau/sW //]; apply: sub_in2 Itau.
Qed.
Lemma isometry_of_free S f :
free S -> {in S &, isometry f} ->
{tau : {linear 'CF(L) -> 'CF(G)} |
{in S, tau =1 f} & {in <<S>>%VS &, isometry tau}}.
Proof.
move=> freeS If; have defS := free_span freeS.
have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S).
have{} Dtau: {in S, tau =1 f}.
by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau.
exists tau => // _ _ /defS[a -> _] /defS[b -> _].
rewrite !{1}linear_sum !{1}cfdot_suml; apply/eq_big_seq=> xi1 Sxi1.
rewrite !{1}cfdot_sumr; apply/eq_big_seq=> xi2 Sxi2.
by rewrite !linearZ /= !Dtau // !cfdotZl !cfdotZr If.
Qed.
Lemma isometry_of_cfnorm S tauS :
pairwise_orthogonal S -> pairwise_orthogonal tauS ->
map cfnorm tauS = map cfnorm S ->
{tau : {linear 'CF(L) -> 'CF(G)} | map tau S = tauS
& {in <<S>>%VS &, isometry tau}}.
Proof.
move=> oS oT eq_nST; have freeS := orthogonal_free oS.
have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map.
have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)).
exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=.
apply: eq_bigr => i _ /=; rewrite linearZ !cfdotZr !cfdot_suml; congr (_ * _).
apply: eq_bigr => j _ /=; rewrite linearZ !cfdotZl; congr (_ * _).
rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i.
by rewrite -!['[_]](nth_map 0 0 cfnorm) ?eq_sz // eq_nST.
have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS.
have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT.
by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz.
Qed.
Lemma isometry_raddf_inj U (tau : {additive 'CF(L) -> 'CF(G)}) :
{in U &, isometry tau} -> {in U &, forall u v, u - v \in U} ->
{in U &, injective tau}.
Proof.
move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB.
by rewrite -cfnorm_eq0 Itau ?linU // cfnorm_eq0 subr_eq0 => /eqP.
Qed.
Lemma opp_isometry : @isometry _ _ G G -%R.
Proof. by move=> x y; rewrite cfdotNl cfdotNr opprK. Qed.
End BuildIsometries.
Section Restrict.
Variables (gT : finGroupType) (A B : {set gT}).
Local Notation H := <<A>>.
Local Notation G := <<B>>.
Fact cfRes_subproof (phi : 'CF(B)) :
is_class_fun H [ffun x => phi (if H \subset G then x else 1%g) *+ (x \in H)].
Proof.
apply: intro_class_fun => /= [x y Hx Hy | x /negbTE/=-> //].
by rewrite Hx (groupJ Hx) //; case: subsetP => // sHG; rewrite cfunJgen ?sHG.
Qed.
Definition cfRes phi := Cfun 1 (cfRes_subproof phi).
Lemma cfResE phi : A \subset B -> {in A, cfRes phi =1 phi}.
Proof. by move=> sAB x Ax; rewrite cfunElock mem_gen ?genS. Qed.
Lemma cfRes1 phi : cfRes phi 1%g = phi 1%g.
Proof. by rewrite cfunElock if_same group1. Qed.
Lemma cfRes_is_linear : linear cfRes.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfRes
(GRing.semilinear_linear cfRes_is_linear).
Lemma cfRes_cfun1 : cfRes 1 = 1.
Proof.
apply: cfun_in_genP => x Hx; rewrite cfunElock Hx !cfun1Egen Hx.
by case: subsetP => [-> // | _]; rewrite group1.
Qed.
Lemma cfRes_is_monoid_morphism : monoid_morphism cfRes.
Proof.
split=> [|phi psi]; [exact: cfRes_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfRes_is_monoid_morphism` instead")]
Definition cfRes_is_multiplicative :=
(fun g => (g.2,g.1)) cfRes_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfRes
cfRes_is_monoid_morphism.
End Restrict.
Arguments cfRes {gT} A%_g {B%_g} phi%_CF.
Notation "''Res[' H , G ]" := (@cfRes _ H G) (only parsing) : ring_scope.
Notation "''Res[' H ]" := 'Res[H, _] : ring_scope.
Notation "''Res'" := 'Res[_] (only parsing) : ring_scope.
Section MoreRestrict.
Variables (gT : finGroupType) (G H : {group gT}).
Implicit Types (A : {set gT}) (phi : 'CF(G)).
Lemma cfResEout phi : ~~ (H \subset G) -> 'Res[H] phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x.
by rewrite cfunE cfun1E mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfResRes A phi :
A \subset H -> H \subset G -> 'Res[A] ('Res[H] phi) = 'Res[A] phi.
Proof.
move=> sAH sHG; apply/cfunP=> x; rewrite !cfunElock !genGid !gen_subG sAH sHG.
by rewrite (subset_trans sAH) // -mulrnA mulnb -in_setI (setIidPr _) ?gen_subG.
Qed.
Lemma cfRes_id A psi : 'Res[A] psi = psi.
Proof. by apply/cfun_in_genP=> x Ax; rewrite cfunElock Ax subxx. Qed.
Lemma sub_cfker_Res A phi :
A \subset H -> A \subset cfker phi -> A \subset cfker ('Res[H, G] phi).
Proof.
move=> sAH kerA; apply/subsetP=> x Ax; have Hx := subsetP sAH x Ax.
rewrite inE Hx; apply/forallP=> y; rewrite !cfunElock !genGid groupMl //.
by rewrite !(fun_if phi) cfkerMl // (subsetP kerA).
Qed.
Lemma eq_cfker_Res phi : H \subset cfker phi -> cfker ('Res[H, G] phi) = H.
Proof. by move=> kH; apply/eqP; rewrite eqEsubset cfker_sub sub_cfker_Res. Qed.
Lemma cfRes_sub_ker phi : H \subset cfker phi -> 'Res[H, G] phi = (phi 1%g)%:A.
Proof.
move=> kerHphi; have sHG := subset_trans kerHphi (cfker_sub phi).
apply/cfun_inP=> x Hx; have ker_x := subsetP kerHphi x Hx.
by rewrite cfResE // cfunE cfun1E Hx mulr1 cfker1.
Qed.
Lemma cforder_Res phi : #['Res[H] phi]%CF %| #[phi]%CF.
Proof. exact: cforder_rmorph. Qed.
End MoreRestrict.
Section Morphim.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Section Main.
Variable G : {group aT}.
Implicit Type phi : 'CF(f @* G).
Fact cfMorph_subproof phi :
is_class_fun <<G>>
[ffun x => phi (if G \subset D then f x else 1%g) *+ (x \in G)].
Proof.
rewrite genGid; apply: intro_class_fun => [x y Gx Gy | x /negPf-> //].
rewrite Gx groupJ //; case subsetP => // sGD.
by rewrite morphJ ?cfunJ ?mem_morphim ?sGD.
Qed.
Definition cfMorph phi := Cfun 1 (cfMorph_subproof phi).
Lemma cfMorphE phi x : G \subset D -> x \in G -> cfMorph phi x = phi (f x).
Proof. by rewrite cfunElock => -> ->. Qed.
Lemma cfMorph1 phi : cfMorph phi 1%g = phi 1%g.
Proof. by rewrite cfunElock morph1 if_same group1. Qed.
Lemma cfMorphEout phi : ~~ (G \subset D) -> cfMorph phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sGD; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_sGD.
Qed.
Lemma cfMorph_cfun1 : cfMorph 1 = 1.
Proof.
apply/cfun_inP=> x Gx; rewrite cfunElock !cfun1E Gx.
by case: subsetP => [sGD | _]; rewrite ?group1 // mem_morphim ?sGD.
Qed.
Fact cfMorph_is_linear : linear cfMorph.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr -mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfMorph
(GRing.semilinear_linear cfMorph_is_linear).
Fact cfMorph_is_monoid_morphism : monoid_morphism cfMorph.
Proof.
split=> [|phi psi]; [exact: cfMorph_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfMorph
cfMorph_is_monoid_morphism.
Hypothesis sGD : G \subset D.
Lemma cfMorph_inj : injective cfMorph.
Proof.
move=> phi1 phi2 eq_phi; apply/cfun_inP=> _ /morphimP[x Dx Gx ->].
by rewrite -!cfMorphE // eq_phi.
Qed.
Lemma cfMorph_eq1 phi : (cfMorph phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfMorph_inj. Qed.
Lemma cfker_morph phi : cfker (cfMorph phi) = G :&: f @*^-1 (cfker phi).
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
have Dx := subsetP sGD x Gx; rewrite Dx mem_morphim //=.
apply/forallP/forallP=> Kx y.
have [{y} /morphimP[y Dy Gy ->] | fG'y] := boolP (y \in f @* G).
by rewrite -morphM // -!(cfMorphE phi) ?groupM.
by rewrite !cfun0 ?groupMl // mem_morphim.
have [Gy | G'y] := boolP (y \in G); last by rewrite !cfun0 ?groupMl.
by rewrite !cfMorphE ?groupM ?morphM // (subsetP sGD).
Qed.
Lemma cfker_morph_im phi : f @* cfker (cfMorph phi) = cfker phi.
Proof. by rewrite cfker_morph // morphim_setIpre (setIidPr (cfker_sub _)). Qed.
Lemma sub_cfker_morph phi (A : {set aT}) :
(A \subset cfker (cfMorph phi)) = (A \subset G) && (f @* A \subset cfker phi).
Proof.
rewrite cfker_morph // subsetI; apply: andb_id2l => sAG.
by rewrite sub_morphim_pre // (subset_trans sAG).
Qed.
Lemma sub_morphim_cfker phi (A : {set aT}) :
A \subset G -> (f @* A \subset cfker phi) = (A \subset cfker (cfMorph phi)).
Proof. by move=> sAG; rewrite sub_cfker_morph ?sAG. Qed.
Lemma cforder_morph phi : #[cfMorph phi]%CF = #[phi]%CF.
Proof. exact/cforder_inj_rmorph/cfMorph_inj. Qed.
End Main.
Lemma cfResMorph (G H : {group aT}) (phi : 'CF(f @* G)) :
H \subset G -> G \subset D -> 'Res (cfMorph phi) = cfMorph ('Res[f @* H] phi).
Proof.
move=> sHG sGD; have sHD := subset_trans sHG sGD.
apply/cfun_inP=> x Hx; have [Gx Dx] := (subsetP sHG x Hx, subsetP sHD x Hx).
by rewrite !(cfMorphE, cfResE) ?morphimS ?mem_morphim //.
Qed.
End Morphim.
Prenex Implicits cfMorph.
Section Isomorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Let defR := isom_im isoGR.
Local Notation G1 := (isom_inv isoGR @* R).
Let defG : G1 = G := isom_im (isom_sym isoGR).
Fact cfIsom_key : unit. Proof. by []. Qed.
Definition cfIsom :=
locked_with cfIsom_key (cfMorph \o 'Res[G1] : 'CF(G) -> 'CF(R)).
Canonical cfIsom_unlockable := [unlockable of cfIsom].
Lemma cfIsomE phi (x : aT : finType) : x \in G -> cfIsom phi (f x) = phi x.
Proof.
move=> Gx; rewrite unlock cfMorphE //= /restrm ?defG ?cfRes_id ?invmE //.
by rewrite -defR mem_morphim.
Qed.
Lemma cfIsom1 phi : cfIsom phi 1%g = phi 1%g.
Proof. by rewrite -(morph1 f) cfIsomE. Qed.
Lemma cfIsom_is_zmod_morphism : zmod_morphism cfIsom.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_zmod_morphism` instead")]
Definition cfIsom_is_additive := cfIsom_is_zmod_morphism.
Lemma cfIsom_is_monoid_morphism : monoid_morphism cfIsom.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_monoid_morphism` instead")]
Definition cfIsom_is_multiplicative :=
(fun g => (g.2,g.1)) cfIsom_is_monoid_morphism.
Lemma cfIsom_is_scalable : scalable cfIsom.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfIsom cfIsom_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfIsom
cfIsom_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfIsom
cfIsom_is_scalable.
Lemma cfIsom_cfun1 : cfIsom 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_isom phi : cfker (cfIsom phi) = f @* cfker phi.
Proof.
rewrite unlock cfker_morph // defG cfRes_id morphpre_restrm morphpre_invm.
by rewrite -defR !morphimIim.
Qed.
End Isomorphism.
Prenex Implicits cfIsom.
Section InvMorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Lemma cfIsomK : cancel (cfIsom isoGR) (cfIsom (isom_sym isoGR)).
Proof.
move=> phi; apply/cfun_inP=> x Gx; rewrite -{1}(invmE (isom_inj isoGR) Gx).
by rewrite !cfIsomE // -(isom_im isoGR) mem_morphim.
Qed.
Lemma cfIsomKV : cancel (cfIsom (isom_sym isoGR)) (cfIsom isoGR).
Proof.
move=> phi; apply/cfun_inP=> y Ry; pose injGR := isom_inj isoGR.
rewrite -{1}[y](invmK injGR) ?(isom_im isoGR) //.
suffices /morphpreP[fGy Gf'y]: y \in invm injGR @*^-1 G by rewrite !cfIsomE.
by rewrite morphpre_invm (isom_im isoGR).
Qed.
Lemma cfIsom_inj : injective (cfIsom isoGR). Proof. exact: can_inj cfIsomK. Qed.
Lemma cfIsom_eq1 phi : (cfIsom isoGR phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfIsom_inj. Qed.
Lemma cforder_isom phi : #[cfIsom isoGR phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfIsom_inj. Qed.
End InvMorphism.
Arguments cfIsom_inj {aT rT G f R} isoGR [phi1 phi2] : rename.
Section Coset.
Variables (gT : finGroupType) (G : {group gT}) (B : {set gT}).
Implicit Type rT : finGroupType.
Local Notation H := <<B>>%g.
Definition cfMod : 'CF(G / B) -> 'CF(G) := cfMorph.
Definition ffun_Quo (phi : 'CF(G)) :=
[ffun Hx : coset_of B =>
phi (if B \subset cfker phi then repr Hx else 1%g) *+ (Hx \in G / B)%g].
Fact cfQuo_subproof phi : is_class_fun <<G / B>> (ffun_Quo phi).
Proof.
rewrite genGid; apply: intro_class_fun => [|Hx /negPf-> //].
move=> _ _ /morphimP[x Nx Gx ->] /morphimP[z Nz Gz ->].
rewrite -morphJ ?mem_morphim ?val_coset_prim ?groupJ //= -gen_subG.
case: subsetP => // KphiH; do 2!case: repr_rcosetP => _ /KphiH/cfkerMl->.
by rewrite cfunJ.
Qed.
Definition cfQuo phi := Cfun 1 (cfQuo_subproof phi).
Local Notation "phi / 'B'" := (cfQuo phi)
(at level 40, left associativity) : cfun_scope.
Local Notation "phi %% 'B'" := (cfMod phi) (at level 40) : cfun_scope.
(* We specialize the cfMorph lemmas to cfMod by strengthening the domain *)
(* condition G \subset 'N(H) to H <| G; the cfMorph lemmas can be used if the *)
(* stronger results are needed. *)
Lemma cfModE phi x : B <| G -> x \in G -> (phi %% B)%CF x = phi (coset B x).
Proof. by move/normal_norm=> nBG; apply: cfMorphE. Qed.
Lemma cfMod1 phi : (phi %% B)%CF 1%g = phi 1%g. Proof. exact: cfMorph1. Qed.
HB.instance Definition _ := GRing.LRMorphism.on cfMod.
Lemma cfMod_cfun1 : (1 %% B)%CF = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_mod phi : B <| G -> B \subset cfker (phi %% B).
Proof.
case/andP=> sBG nBG; rewrite cfker_morph // subsetI sBG.
apply: subset_trans _ (ker_sub_pre _ _); rewrite ker_coset_prim subsetI.
by rewrite (subset_trans sBG nBG) sub_gen.
Qed.
(* Note that cfQuo is nondegenerate even when G does not normalize B. *)
Lemma cfQuoEnorm (phi : 'CF(G)) x :
B \subset cfker phi -> x \in 'N_G(B) -> (phi / B)%CF (coset B x) = phi x.
Proof.
rewrite cfunElock -gen_subG => sHK /setIP[Gx nHx]; rewrite sHK /=.
rewrite mem_morphim // val_coset_prim //.
by case: repr_rcosetP => _ /(subsetP sHK)/cfkerMl->.
Qed.
Lemma cfQuoE (phi : 'CF(G)) x :
B <| G -> B \subset cfker phi -> x \in G -> (phi / B)%CF (coset B x) = phi x.
Proof. by case/andP=> _ nBG sBK Gx; rewrite cfQuoEnorm // (setIidPl _). Qed.
Lemma cfQuo1 (phi : 'CF(G)) : (phi / B)%CF 1%g = phi 1%g.
Proof. by rewrite cfunElock repr_coset1 group1 if_same. Qed.
Lemma cfQuoEout (phi : 'CF(G)) :
~~ (B \subset cfker phi) -> (phi / B)%CF = (phi 1%g)%:A.
Proof.
move/negPf=> not_kerB; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_kerB.
Qed.
(* cfQuo is only linear on the class functions that have H in their kernel. *)
Lemma cfQuo_cfun1 : (1 / B)%CF = 1.
Proof.
apply/cfun_inP=> Hx G_Hx; rewrite cfunElock !cfun1E G_Hx cfker_cfun1 -gen_subG.
have [x nHx Gx ->] := morphimP G_Hx.
case: subsetP=> [sHG | _]; last by rewrite group1.
by rewrite val_coset_prim //; case: repr_rcosetP => y /sHG/groupM->.
Qed.
(* Cancellation properties *)
Lemma cfModK : B <| G -> cancel cfMod cfQuo.
Proof.
move=> nsBG phi; apply/cfun_inP=> _ /morphimP[x Nx Gx ->] //.
by rewrite cfQuoE ?cfker_mod ?cfModE.
Qed.
Lemma cfQuoK :
B <| G -> forall phi, B \subset cfker phi -> (phi / B %% B)%CF = phi.
Proof.
by move=> nsHG phi sHK; apply/cfun_inP=> x Gx; rewrite cfModE ?cfQuoE.
Qed.
Lemma cfMod_eq1 psi : B <| G -> (psi %% B == 1)%CF = (psi == 1).
Proof. by move/cfModK/can_eq <-; rewrite rmorph1. Qed.
Lemma cfQuo_eq1 phi :
B <| G -> B \subset cfker phi -> (phi / B == 1)%CF = (phi == 1).
Proof. by move=> nsBG kerH; rewrite -cfMod_eq1 // cfQuoK. Qed.
End Coset.
Arguments cfQuo {gT G%_G} B%_g phi%_CF.
Arguments cfMod {gT G%_G B%_g} phi%_CF.
Notation "phi / H" := (cfQuo H phi) : cfun_scope.
Notation "phi %% H" := (@cfMod _ _ H phi) : cfun_scope.
Section MoreCoset.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (H K : {group gT}) (phi : 'CF(G)).
Lemma cfResMod H K (psi : 'CF(G / K)) :
H \subset G -> K <| G -> ('Res (psi %% K) = 'Res[H / K] psi %% K)%CF.
Proof. by move=> sHG /andP[_]; apply: cfResMorph. Qed.
Lemma quotient_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> (cfker (psi %% K) / K)%g = cfker psi.
Proof. by case/andP=> _ /cfker_morph_im <-. Qed.
Lemma sub_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> A \subset 'N(K) ->
(A \subset cfker (psi %% K)) = (A / K \subset cfker psi)%g.
Proof.
by move=> nsKG nKA; rewrite -(quotientSGK nKA) ?quotient_cfker_mod// cfker_mod.
Qed.
Lemma cfker_quo H phi :
H <| G -> H \subset cfker (phi) -> cfker (phi / H) = (cfker phi / H)%g.
Proof.
move=> nsHG /cfQuoK {2}<- //; have [sHG nHG] := andP nsHG.
by rewrite cfker_morph 1?quotientGI // cosetpreK (setIidPr _) ?cfker_sub.
Qed.
Lemma cfQuoEker phi x :
x \in G -> (phi / cfker phi)%CF (coset (cfker phi) x) = phi x.
Proof. by move/cfQuoE->; rewrite ?cfker_normal. Qed.
Lemma cfaithful_quo phi : cfaithful (phi / cfker phi).
Proof. by rewrite cfaithfulE cfker_quo ?cfker_normal ?trivg_quotient. Qed.
(* Note that there is no requirement that K be normal in H or G. *)
Lemma cfResQuo H K phi :
K \subset cfker phi -> K \subset H -> H \subset G ->
('Res[H / K] (phi / K) = 'Res[H] phi / K)%CF.
Proof.
move=> kerK sKH sHG; apply/cfun_inP=> xb Hxb; rewrite cfResE ?quotientS //.
have{xb Hxb} [x nKx Hx ->] := morphimP Hxb.
by rewrite !cfQuoEnorm ?cfResE// 1?inE ?Hx ?(subsetP sHG)// sub_cfker_Res.
Qed.
Lemma cfQuoInorm K phi :
K \subset cfker phi -> (phi / K)%CF = 'Res ('Res['N_G(K)] phi / K)%CF.
Proof.
move=> kerK; rewrite -cfResQuo ?subsetIl ?quotientInorm ?cfRes_id //.
by rewrite subsetI normG (subset_trans kerK) ?cfker_sub.
Qed.
Lemma cforder_mod H (psi : 'CF(G / H)) : H <| G -> #[psi %% H]%CF = #[psi]%CF.
Proof. by move/cfModK/can_inj/cforder_inj_rmorph->. Qed.
Lemma cforder_quo H phi :
H <| G -> H \subset cfker phi -> #[phi / H]%CF = #[phi]%CF.
Proof. by move=> nsHG kerHphi; rewrite -cforder_mod ?cfQuoK. Qed.
End MoreCoset.
Section Product.
Variable (gT : finGroupType) (G : {group gT}).
Lemma cfunM_onI A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) -> phi * psi \in 'CF(G, A :&: B).
Proof.
rewrite !cfun_onE => Aphi Bpsi; apply/subsetP=> x; rewrite !inE cfunE mulf_eq0.
by case/norP=> /(subsetP Aphi)-> /(subsetP Bpsi).
Qed.
Lemma cfunM_on A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, A) -> phi * psi \in 'CF(G, A).
Proof. by move=> Aphi Bpsi; rewrite -[A]setIid cfunM_onI. Qed.
End Product.
Section SDproduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis defG : K ><| H = G.
Fact cfSdprodKey : unit. Proof. by []. Qed.
Definition cfSdprod :=
locked_with cfSdprodKey
(cfMorph \o cfIsom (tagged (sdprod_isom defG)) : 'CF(H) -> 'CF(G)).
Canonical cfSdprod_unlockable := [unlockable of cfSdprod].
Lemma cfSdprod_is_zmod_morphism : zmod_morphism cfSdprod.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_zmod_morphism` instead")]
Definition cfSdprod_is_additive := cfSdprod_is_zmod_morphism.
Lemma cfSdprod_is_monoid_morphism : monoid_morphism cfSdprod.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_monoid_morphism` instead")]
Definition cfSdprod_is_multiplicative :=
(fun g => (g.2,g.1)) cfSdprod_is_monoid_morphism.
Lemma cfSdprod_is_scalable : scalable cfSdprod.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfSdprod cfSdprod_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfSdprod
cfSdprod_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfSdprod
cfSdprod_is_scalable.
Lemma cfSdprod1 phi : cfSdprod phi 1%g = phi 1%g.
Proof. by rewrite unlock /= cfMorph1 cfIsom1. Qed.
Let nsKG : K <| G. Proof. by have [] := sdprod_context defG. Qed.
Let sHG : H \subset G. Proof. by have [] := sdprod_context defG. Qed.
Let sKG : K \subset G. Proof. by have [] := andP nsKG. Qed.
Lemma cfker_sdprod phi : K \subset cfker (cfSdprod phi).
Proof. by rewrite unlock_with cfker_mod. Qed.
Lemma cfSdprodEr phi : {in H, cfSdprod phi =1 phi}.
Proof. by move=> y Hy; rewrite unlock cfModE ?cfIsomE ?(subsetP sHG). Qed.
Lemma cfSdprodE phi : {in K & H, forall x y, cfSdprod phi (x * y)%g = phi y}.
Proof.
by move=> x y Kx Hy; rewrite /= cfkerMl ?(subsetP (cfker_sdprod _)) ?cfSdprodEr.
Qed.
Lemma cfSdprodK : cancel cfSdprod 'Res[H].
Proof. by move=> phi; apply/cfun_inP=> x Hx; rewrite cfResE ?cfSdprodEr. Qed.
Lemma cfSdprod_inj : injective cfSdprod. Proof. exact: can_inj cfSdprodK. Qed.
Lemma cfSdprod_eq1 phi : (cfSdprod phi == 1) = (phi == 1).
Proof. exact: rmorph_eq1 cfSdprod_inj. Qed.
Lemma cfRes_sdprodK phi : K \subset cfker phi -> cfSdprod ('Res[H] phi) = phi.
Proof.
move=> kerK; apply/cfun_inP=> _ /(mem_sdprod defG)[x [y [Kx Hy -> _]]].
by rewrite cfSdprodE // cfResE // cfkerMl ?(subsetP kerK).
Qed.
Lemma sdprod_cfker phi : K ><| cfker phi = cfker (cfSdprod phi).
Proof.
have [skerH [_ _ nKH tiKH]] := (cfker_sub phi, sdprodP defG).
rewrite unlock cfker_morph ?normal_norm // cfker_isom restrmEsub //=.
rewrite -(sdprod_modl defG) ?sub_cosetpre //=; congr (_ ><| _).
by rewrite quotientK ?(subset_trans skerH) // -group_modr //= setIC tiKH mul1g.
Qed.
Lemma cforder_sdprod phi : #[cfSdprod phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfSdprod_inj. Qed.
End SDproduct.
Section DProduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis KxH : K \x H = G.
Lemma reindex_dprod R idx (op : Monoid.com_law idx) (F : gT -> R) :
\big[op/idx]_(g in G) F g =
\big[op/idx]_(k in K) \big[op/idx]_(h in H) F (k * h)%g.
Proof.
have /mulgmP/misomP[fM /isomP[injf im_f]] := KxH.
rewrite pair_big_dep -im_f morphimEdom big_imset; last exact/injmP.
by apply: eq_big => [][x y]; rewrite ?inE.
Qed.
Definition cfDprodr := cfSdprod (dprodWsd KxH).
Definition cfDprodl := cfSdprod (dprodWsdC KxH).
Definition cfDprod phi psi := cfDprodl phi * cfDprodr psi.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodl.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodr.
Lemma cfDprodl1 phi : cfDprodl phi 1%g = phi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprodr1 psi : cfDprodr psi 1%g = psi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprod1 phi psi : cfDprod phi psi 1%g = phi 1%g * psi 1%g.
Proof. by rewrite cfunE /= !cfSdprod1. Qed.
Lemma cfDprodl_eq1 phi : (cfDprodl phi == 1) = (phi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprodr_eq1 psi : (cfDprodr psi == 1) = (psi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprod_cfun1r phi : cfDprod phi 1 = cfDprodl phi.
Proof. by rewrite /cfDprod rmorph1 mulr1. Qed.
Lemma cfDprod_cfun1l psi : cfDprod 1 psi = cfDprodr psi.
Proof. by rewrite /cfDprod rmorph1 mul1r. Qed.
Lemma cfDprod_cfun1 : cfDprod 1 1 = 1.
Proof. by rewrite cfDprod_cfun1l rmorph1. Qed.
Lemma cfDprod_split phi psi : cfDprod phi psi = cfDprod phi 1 * cfDprod 1 psi.
Proof. by rewrite cfDprod_cfun1l cfDprod_cfun1r. Qed.
Let nsKG : K <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let nsHG : H <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let cKH : H \subset 'C(K). Proof. by have [] := dprodP KxH. Qed.
Let sKG := normal_sub nsKG.
Let sHG := normal_sub nsHG.
Lemma cfDprodlK : cancel cfDprodl 'Res[K]. Proof. exact: cfSdprodK. Qed.
Lemma cfDprodrK : cancel cfDprodr 'Res[H]. Proof. exact: cfSdprodK. Qed.
Lemma cfker_dprodl phi : cfker phi \x H = cfker (cfDprodl phi).
Proof.
by rewrite dprodC -sdprod_cfker dprodEsd // centsC (centsS (cfker_sub _)).
Qed.
Lemma cfker_dprodr psi : K \x cfker psi = cfker (cfDprodr psi).
Proof. by rewrite -sdprod_cfker dprodEsd // (subset_trans (cfker_sub _)). Qed.
Lemma cfDprodEl phi : {in K & H, forall k h, cfDprodl phi (k * h)%g = phi k}.
Proof. by move=> k h Kk Hh /=; rewrite -(centsP cKH) // cfSdprodE. Qed.
Lemma cfDprodEr psi : {in K & H, forall k h, cfDprodr psi (k * h)%g = psi h}.
Proof. exact: cfSdprodE. Qed.
Lemma cfDprodE phi psi :
{in K & H, forall h k, cfDprod phi psi (h * k)%g = phi h * psi k}.
Proof. by move=> k h Kk Hh /=; rewrite cfunE cfDprodEl ?cfDprodEr. Qed.
Lemma cfDprod_Resl phi psi : 'Res[K] (cfDprod phi psi) = psi 1%g *: phi.
Proof.
by apply/cfun_inP=> x Kx; rewrite cfunE cfResE // -{1}[x]mulg1 mulrC cfDprodE.
Qed.
Lemma cfDprod_Resr phi psi : 'Res[H] (cfDprod phi psi) = phi 1%g *: psi.
Proof.
by apply/cfun_inP=> y Hy; rewrite cfunE cfResE // -{1}[y]mul1g cfDprodE.
Qed.
Lemma cfDprodKl (psi : 'CF(H)) : psi 1%g = 1 -> cancel (cfDprod^~ psi) 'Res.
Proof. by move=> psi1 phi; rewrite cfDprod_Resl psi1 scale1r. Qed.
Lemma cfDprodKr (phi : 'CF(K)) : phi 1%g = 1 -> cancel (cfDprod phi) 'Res.
Proof. by move=> phi1 psi; rewrite cfDprod_Resr phi1 scale1r. Qed.
(* Note that equality holds here iff either cfker phi = K and cfker psi = H, *)
(* or else phi != 0, psi != 0 and coprime #|K : cfker phi| #|H : cfker phi|. *)
Lemma cfker_dprod phi psi :
cfker phi <*> cfker psi \subset cfker (cfDprod phi psi).
Proof.
rewrite -genM_join gen_subG; apply/subsetP=> _ /mulsgP[x y kKx kHy ->] /=.
have [[Kx _] [Hy _]] := (setIdP kKx, setIdP kHy).
have Gxy: (x * y)%g \in G by rewrite -(dprodW KxH) mem_mulg.
rewrite inE Gxy; apply/forallP=> g.
have [Gg | G'g] := boolP (g \in G); last by rewrite !cfun0 1?groupMl.
have{g Gg} [k [h [Kk Hh -> _]]] := mem_dprod KxH Gg.
rewrite mulgA -(mulgA x) (centsP cKH y) // mulgA -mulgA !cfDprodE ?groupM //.
by rewrite !cfkerMl.
Qed.
Lemma cfdot_dprod phi1 phi2 psi1 psi2 :
'[cfDprod phi1 psi1, cfDprod phi2 psi2] = '[phi1, phi2] * '[psi1, psi2].
Proof.
rewrite !cfdotE mulrCA -mulrA mulrCA mulrA -invfM -natrM (dprod_card KxH).
congr (_ * _); rewrite big_distrl reindex_dprod /=; apply: eq_bigr => k Kk.
rewrite big_distrr; apply: eq_bigr => h Hh /=.
by rewrite mulrCA -mulrA -rmorphM mulrCA mulrA !cfDprodE.
Qed.
Lemma cfDprodl_iso : isometry cfDprodl.
Proof.
by move=> phi1 phi2; rewrite -!cfDprod_cfun1r cfdot_dprod cfnorm1 mulr1.
Qed.
Lemma cfDprodr_iso : isometry cfDprodr.
Proof.
by move=> psi1 psi2; rewrite -!cfDprod_cfun1l cfdot_dprod cfnorm1 mul1r.
Qed.
Lemma cforder_dprodl phi : #[cfDprodl phi]%CF = #[phi]%CF.
Proof. exact: cforder_sdprod. Qed.
Lemma cforder_dprodr psi : #[cfDprodr psi]%CF = #[psi]%CF.
Proof. exact: cforder_sdprod. Qed.
End DProduct.
Lemma cfDprodC (gT : finGroupType) (G K H : {group gT})
(KxH : K \x H = G) (HxK : H \x K = G) chi psi :
cfDprod KxH chi psi = cfDprod HxK psi chi.
Proof.
rewrite /cfDprod mulrC.
by congr (_ * _); congr (cfSdprod _ _); apply: eq_irrelevance.
Qed.
Section Bigdproduct.
Variables (gT : finGroupType) (I : finType) (P : pred I).
Variables (A : I -> {group gT}) (G : {group gT}).
Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G.
Let sAG i : P i -> A i \subset G.
Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed.
Fact cfBigdprodi_subproof i :
gval (if P i then A i else 1%G) \x <<\bigcup_(j | P j && (j != i)) A j>> = G.
Proof.
have:= defG; rewrite fun_if big_mkcond (bigD1 i) // -big_mkcondl /= => defGi.
by have [[_ Gi' _ defGi']] := dprodP defGi; rewrite (bigdprodWY defGi') -defGi'.
Qed.
Definition cfBigdprodi i := cfDprodl (cfBigdprodi_subproof i) \o 'Res[_, A i].
HB.instance Definition _ i := GRing.LRMorphism.on (@cfBigdprodi i).
Lemma cfBigdprodi1 i (phi : 'CF(A i)) : cfBigdprodi phi 1%g = phi 1%g.
Proof. by rewrite cfDprodl1 cfRes1. Qed.
Lemma cfBigdprodi_eq1 i (phi : 'CF(A i)) :
P i -> (cfBigdprodi phi == 1) = (phi == 1).
Proof. by move=> Pi; rewrite cfSdprod_eq1 Pi cfRes_id. Qed.
Lemma cfBigdprodiK i : P i -> cancel (@cfBigdprodi i) 'Res[A i].
Proof.
move=> Pi phi; have:= cfDprodlK (cfBigdprodi_subproof i) ('Res phi).
by rewrite -[cfDprodl _ _]/(cfBigdprodi phi) Pi cfRes_id.
Qed.
Lemma cfBigdprodi_inj i : P i -> injective (@cfBigdprodi i).
Proof. by move/cfBigdprodiK; apply: can_inj. Qed.
Lemma cfBigdprodEi i (phi : 'CF(A i)) x :
P i -> (forall j, P j -> x j \in A j) ->
cfBigdprodi phi (\prod_(j | P j) x j)%g = phi (x i).
Proof.
have [r big_r [Ur mem_r] _] := big_enumP P => Pi AxP.
have:= bigdprodWcp defG; rewrite -!big_r => defGr.
have{AxP} [r_i Axr]: i \in r /\ {in r, forall j, x j \in A j}.
by split=> [|j]; rewrite mem_r // => /AxP.
rewrite (perm_bigcprod defGr Axr (perm_to_rem r_i)) big_cons.
rewrite cfDprodEl ?Pi ?cfRes_id ?Axr // big_seq group_prod // => j.
rewrite mem_rem_uniq // => /andP[i'j /= r_j].
by apply/mem_gen/bigcupP; exists j; [rewrite -mem_r r_j | apply: Axr].
Qed.
Lemma cfBigdprodi_iso i : P i -> isometry (@cfBigdprodi i).
Proof. by move=> Pi phi psi; rewrite cfDprodl_iso Pi !cfRes_id. Qed.
Definition cfBigdprod (phi : forall i, 'CF(A i)) :=
\prod_(i | P i) cfBigdprodi (phi i).
Lemma cfBigdprodE phi x :
(forall i, P i -> x i \in A i) ->
cfBigdprod phi (\prod_(i | P i) x i)%g = \prod_(i | P i) phi i (x i).
Proof.
move=> Ax; rewrite prod_cfunE; last by rewrite -(bigdprodW defG) mem_prodg.
by apply: eq_bigr => i Pi; rewrite cfBigdprodEi.
Qed.
Lemma cfBigdprod1 phi : cfBigdprod phi 1%g = \prod_(i | P i) phi i 1%g.
Proof. by rewrite prod_cfunE //; apply/eq_bigr=> i _; apply: cfBigdprodi1. Qed.
Lemma cfBigdprodK phi (Phi := cfBigdprod phi) i (a := phi i 1%g / Phi 1%g) :
Phi 1%g != 0 -> P i -> a != 0 /\ a *: 'Res[A i] Phi = phi i.
Proof.
move=> nzPhi Pi; split.
rewrite mulf_neq0 ?invr_eq0 // (contraNneq _ nzPhi) // => phi_i0.
by rewrite cfBigdprod1 (bigD1 i) //= phi_i0 mul0r.
apply/cfun_inP=> x Aix; rewrite cfunE cfResE ?sAG // mulrAC.
have {1}->: x = (\prod_(j | P j) (if j == i then x else 1))%g.
rewrite -big_mkcondr (big_pred1 i) ?eqxx // => j /=.
by apply: andb_idl => /eqP->.
rewrite cfBigdprodE => [|j _]; last by case: eqP => // ->.
apply: canLR (mulfK nzPhi) _; rewrite cfBigdprod1 !(bigD1 i Pi) /= eqxx.
by rewrite mulrCA !mulrA; congr (_ * _); apply: eq_bigr => j /andP[_ /negPf->].
Qed.
Lemma cfdot_bigdprod phi psi :
'[cfBigdprod phi, cfBigdprod psi] = \prod_(i | P i) '[phi i, psi i].
Proof.
apply: canLR (mulKf (neq0CG G)) _; rewrite -(bigdprod_card defG).
rewrite (big_morph _ (@natrM _) (erefl _)) -big_split /=.
rewrite (eq_bigr _ (fun i _ => mulVKf (neq0CG _) _)) (big_distr_big_dep 1%g) /=.
set F := pfamily _ _ _; pose h (f : {ffun I -> gT}) := (\prod_(i | P i) f i)%g.
pose is_hK x f := forall f1, (f1 \in F) && (h f1 == x) = (f == f1).
have /fin_all_exists[h1 Dh1] x: exists f, x \in G -> is_hK x f.
case Gx: (x \in G); last by exists [ffun _ => x].
have [f [Af fK Uf]] := mem_bigdprod defG Gx.
exists [ffun i => if P i then f i else 1%g] => _ f1.
apply/andP/eqP=> [[/pfamilyP[Pf1 Af1] /eqP Dx] | <-].
by apply/ffunP=> i; rewrite ffunE; case: ifPn => [/Uf-> | /(supportP Pf1)].
split; last by rewrite fK; apply/eqP/eq_bigr=> i Pi; rewrite ffunE Pi.
by apply/familyP=> i; rewrite ffunE !unfold_in; case: ifP => //= /Af.
rewrite (reindex_onto h h1) /= => [|x /Dh1/(_ (h1 x))]; last first.
by rewrite eqxx => /andP[_ /eqP].
apply/eq_big => [f | f /andP[/Dh1<- /andP[/pfamilyP[_ Af] _]]]; last first.
by rewrite !cfBigdprodE // rmorph_prod -big_split /=.
apply/idP/idP=> [/andP[/Dh1<-] | Ff]; first by rewrite eqxx andbT.
have /pfamilyP[_ Af] := Ff; suffices Ghf: h f \in G by rewrite -Dh1 ?Ghf ?Ff /=.
by apply/group_prod=> i Pi; rewrite (subsetP (sAG Pi)) ?Af.
Qed.
End Bigdproduct.
Section MorphIsometry.
Variable gT : finGroupType.
Implicit Types (D G H K : {group gT}) (aT rT : finGroupType).
Lemma cfMorph_iso aT rT (G D : {group aT}) (f : {morphism D >-> rT}) :
G \subset D -> isometry (cfMorph : 'CF(f @* G) -> 'CF(G)).
Proof.
move=> sGD phi psi; rewrite !cfdotE card_morphim (setIidPr sGD).
rewrite -(LagrangeI G ('ker f)) /= mulnC natrM invfM -mulrA.
congr (_ * _); apply: (canLR (mulKf (neq0CG _))).
rewrite mulr_sumr (partition_big_imset f) /= -morphimEsub //.
apply: eq_bigr => _ /morphimP[x Dx Gx ->].
rewrite -(card_rcoset _ x) mulr_natl -sumr_const.
apply/eq_big => [y | y /andP[Gy /eqP <-]]; last by rewrite !cfMorphE.
rewrite mem_rcoset inE groupMr ?groupV // -mem_rcoset.
by apply: andb_id2l => /(subsetP sGD) Dy; apply: sameP eqP (rcoset_kerP f _ _).
Qed.
Lemma cfIsom_iso rT G (R : {group rT}) (f : {morphism G >-> rT}) :
forall isoG : isom G R f, isometry (cfIsom isoG).
Proof.
move=> isoG phi psi; rewrite unlock cfMorph_iso //; set G1 := _ @* R.
by rewrite -(isom_im (isom_sym isoG)) -/G1 in phi psi *; rewrite !cfRes_id.
Qed.
Lemma cfMod_iso H G : H <| G -> isometry (@cfMod _ G H).
Proof. by case/andP=> _; apply: cfMorph_iso. Qed.
Lemma cfQuo_iso H G :
H <| G -> {in [pred phi | H \subset cfker phi] &, isometry (@cfQuo _ G H)}.
Proof.
by move=> nsHG phi psi sHkphi sHkpsi; rewrite -(cfMod_iso nsHG) !cfQuoK.
Qed.
Lemma cfnorm_quo H G phi :
H <| G -> H \subset cfker phi -> '[phi / H] = '[phi]_G.
Proof. by move=> nsHG sHker; apply: cfQuo_iso. Qed.
Lemma cfSdprod_iso K H G (defG : K ><| H = G) : isometry (cfSdprod defG).
Proof.
move=> phi psi; have [/andP[_ nKG] _ _ _ _] := sdprod_context defG.
by rewrite [cfSdprod _]locked_withE cfMorph_iso ?cfIsom_iso.
Qed.
End MorphIsometry.
Section Induced.
Variable gT : finGroupType.
Section Def.
Variables B A : {set gT}.
Local Notation G := <<B>>.
Local Notation H := <<A>>.
(* The default value for the ~~ (H \subset G) case matches the one for cfRes *)
(* so that Frobenius reciprocity holds even in this degenerate case. *)
Definition ffun_cfInd (phi : 'CF(A)) :=
[ffun x => if H \subset G then #|A|%:R^-1 * (\sum_(y in G) phi (x ^ y))
else #|G|%:R * '[phi, 1] *+ (x == 1%g)].
Fact cfInd_subproof phi : is_class_fun G (ffun_cfInd phi).
Proof.
apply: intro_class_fun => [x y Gx Gy | x H'x]; last first.
case: subsetP => [sHG | _]; last by rewrite (negPf (group1_contra H'x)).
rewrite big1 ?mulr0 // => y Gy; rewrite cfun0gen ?(contra _ H'x) //= => /sHG.
by rewrite memJ_norm ?(subsetP (normG _)).
rewrite conjg_eq1 (reindex_inj (mulgI y^-1)%g); congr (if _ then _ * _ else _).
by apply: eq_big => [z | z Gz]; rewrite ?groupMl ?groupV // -conjgM mulKVg.
Qed.
Definition cfInd phi := Cfun 1 (cfInd_subproof phi).
Lemma cfInd_is_linear : linear cfInd.
Proof.
move=> c phi psi; apply/cfunP=> x; rewrite !cfunElock; case: ifP => _.
rewrite mulrCA -mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * _); apply: eq_bigr => y _; rewrite !cfunE.
rewrite mulrnAr -mulrnDl !(mulrCA c) -!mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * (_ * _) *+ _); apply: eq_bigr => y; rewrite !cfunE mulrA mulrDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfInd
(GRing.semilinear_linear cfInd_is_linear).
End Def.
Local Notation "''Ind[' B , A ]" := (@cfInd B A) : ring_scope.
Local Notation "''Ind[' B ]" := 'Ind[B, _] : ring_scope.
Lemma cfIndE (G H : {group gT}) phi x :
H \subset G -> 'Ind[G, H] phi x = #|H|%:R^-1 * (\sum_(y in G) phi (x ^ y)).
Proof. by rewrite cfunElock !genGid => ->. Qed.
Variables G K H : {group gT}.
Implicit Types (phi : 'CF(H)) (psi : 'CF(G)).
Lemma cfIndEout phi :
~~ (H \subset G) -> 'Ind[G] phi = (#|G|%:R * '[phi, 1]) *: '1_1%G.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x; rewrite cfunE cfuniE ?normal1 // inE.
by rewrite mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfIndEsdprod (phi : 'CF(K)) x :
K ><| H = G -> 'Ind[G] phi x = \sum_(w in H) phi (x ^ w)%g.
Proof.
move=> defG; have [/andP[sKG _] _ mulKH nKH _] := sdprod_context defG.
rewrite cfIndE //; apply: canLR (mulKf (neq0CG _)) _; rewrite -mulKH mulr_sumr.
rewrite (set_partition_big _ (rcosets_partition_mul H K)) ?big_imset /=.
apply: eq_bigr => y Hy; rewrite rcosetE norm_rlcoset ?(subsetP nKH) //.
rewrite -lcosetE mulr_natl big_imset /=; last exact: in2W (mulgI _).
by rewrite -sumr_const; apply: eq_bigr => z Kz; rewrite conjgM cfunJ.
have [{}nKH /isomP[injf _]] := sdprod_isom defG.
apply: can_in_inj (fun Ky => invm injf (coset K (repr Ky))) _ => y Hy.
by rewrite rcosetE -val_coset ?(subsetP nKH) // coset_reprK invmE.
Qed.
Lemma cfInd_on A phi :
H \subset G -> phi \in 'CF(H, A) -> 'Ind[G] phi \in 'CF(G, class_support A G).
Proof.
move=> sHG Af; apply/cfun_onP=> g AG'g; rewrite cfIndE ?big1 ?mulr0 // => h Gh.
apply: (cfun_on0 Af); apply: contra AG'g => Agh.
by rewrite -[g](conjgK h) memJ_class_support // groupV.
Qed.
Lemma cfInd_id phi : 'Ind[H] phi = phi.
Proof.
apply/cfun_inP=> x Hx; rewrite cfIndE // (eq_bigr _ (cfunJ phi x)) sumr_const.
by rewrite -[phi x *+ _]mulr_natl mulKf ?neq0CG.
Qed.
Lemma cfInd_normal phi : H <| G -> 'Ind[G] phi \in 'CF(G, H).
Proof.
case/andP=> sHG nHG; apply: (cfun_onS (class_support_sub_norm (subxx _) nHG)).
by rewrite cfInd_on ?cfun_onG.
Qed.
Lemma cfInd1 phi : H \subset G -> 'Ind[G] phi 1%g = #|G : H|%:R * phi 1%g.
Proof.
move=> sHG; rewrite cfIndE // natf_indexg // -mulrA mulrCA; congr (_ * _).
by rewrite mulr_natl -sumr_const; apply: eq_bigr => x; rewrite conj1g.
Qed.
Lemma cfInd_cfun1 : H <| G -> 'Ind[G, H] 1 = #|G : H|%:R *: '1_H.
Proof.
move=> nsHG; have [sHG nHG] := andP nsHG; rewrite natf_indexg // mulrC.
apply/cfunP=> x; rewrite cfIndE ?cfunE ?cfuniE // -mulrA; congr (_ * _).
rewrite mulr_natl -sumr_const; apply: eq_bigr => y Gy.
by rewrite cfun1E -{1}(normsP nHG y Gy) memJ_conjg.
Qed.
Lemma cfnorm_Ind_cfun1 : H <| G -> '['Ind[G, H] 1] = #|G : H|%:R.
Proof.
move=> nsHG; rewrite cfInd_cfun1 // cfnormZ normr_nat cfdot_cfuni // setIid.
by rewrite expr2 {2}natf_indexg ?normal_sub // !mulrA divfK ?mulfK ?neq0CG.
Qed.
Lemma cfIndInd phi :
K \subset G -> H \subset K -> 'Ind[G] ('Ind[K] phi) = 'Ind[G] phi.
Proof.
move=> sKG sHK; apply/cfun_inP=> x Gx; rewrite !cfIndE ?(subset_trans sHK) //.
apply: canLR (mulKf (neq0CG K)) _; rewrite mulr_sumr mulr_natl.
transitivity (\sum_(y in G) \sum_(z in K) #|H|%:R^-1 * phi ((x ^ y) ^ z)).
by apply: eq_bigr => y Gy; rewrite cfIndE // -mulr_sumr.
symmetry; rewrite exchange_big /= -sumr_const; apply: eq_bigr => z Kz.
rewrite (reindex_inj (mulIg z)).
by apply: eq_big => [y | y _]; rewrite ?conjgM // groupMr // (subsetP sKG).
Qed.
(* This is Isaacs, Lemma (5.2). *)
Lemma Frobenius_reciprocity phi psi : '[phi, 'Res[H] psi] = '['Ind[G] phi, psi].
Proof.
have [sHG | not_sHG] := boolP (H \subset G); last first.
rewrite cfResEout // cfIndEout // cfdotZr cfdotZl mulrAC; congr (_ * _).
rewrite (cfdotEl _ (cfuni_on _ _)) mulVKf ?neq0CG // big_set1.
by rewrite cfuniE ?normal1 ?set11 ?mul1r.
transitivity (#|H|%:R^-1 * \sum_(x in G) phi x * (psi x)^* ).
rewrite (big_setID H) /= (setIidPr sHG) addrC big1 ?add0r; last first.
by move=> x /setDP[_ /cfun0->]; rewrite mul0r.
by congr (_ * _); apply: eq_bigr => x Hx; rewrite cfResE.
set h' := _^-1; apply: canRL (mulKf (neq0CG G)) _.
transitivity (h' * \sum_(y in G) \sum_(x in G) phi (x ^ y) * (psi (x ^ y))^* ).
rewrite mulrCA mulr_natl -sumr_const; congr (_ * _); apply: eq_bigr => y Gy.
by rewrite (reindex_acts 'J _ Gy) ?astabsJ ?normG.
rewrite exchange_big mulr_sumr; apply: eq_bigr => x _; rewrite cfIndE //=.
by rewrite -mulrA mulr_suml; congr (_ * _); apply: eq_bigr => y /(cfunJ psi)->.
Qed.
Definition cfdot_Res_r := Frobenius_reciprocity.
Lemma cfdot_Res_l psi phi : '['Res[H] psi, phi] = '[psi, 'Ind[G] phi].
Proof. by rewrite cfdotC cfdot_Res_r -cfdotC. Qed.
Lemma cfIndM phi psi: H \subset G ->
'Ind[G] (phi * ('Res[H] psi)) = 'Ind[G] phi * psi.
Proof.
move=> HsG; apply/cfun_inP=> x Gx; rewrite !cfIndE // !cfunE !cfIndE // -mulrA.
congr (_ * _); rewrite mulr_suml; apply: eq_bigr=> i iG; rewrite !cfunE.
case: (boolP (x ^ i \in H)) => xJi; last by rewrite cfun0gen ?mul0r ?genGid.
by rewrite !cfResE //; congr (_ * _); rewrite cfunJgen ?genGid.
Qed.
End Induced.
Arguments cfInd {gT} B%_g {A%_g} phi%_CF.
Notation "''Ind[' G , H ]" := (@cfInd _ G H) (only parsing) : ring_scope.
Notation "''Ind[' G ]" := 'Ind[G, _] : ring_scope.
Notation "''Ind'" := 'Ind[_] (only parsing) : ring_scope.
Section MorphInduced.
Variables (aT rT : finGroupType) (D G H : {group aT}) (R S : {group rT}).
Lemma cfIndMorph (f : {morphism D >-> rT}) (phi : 'CF(f @* H)) :
'ker f \subset H -> H \subset G -> G \subset D ->
'Ind[G] (cfMorph phi) = cfMorph ('Ind[f @* G] phi).
Proof.
move=> sKH sHG sGD; have [sHD inD] := (subset_trans sHG sGD, subsetP sGD).
apply/cfun_inP=> /= x Gx; have [Dx sKG] := (inD x Gx, subset_trans sKH sHG).
rewrite cfMorphE ?cfIndE ?morphimS // (partition_big_imset f) -morphimEsub //=.
rewrite card_morphim (setIidPr sHD) natf_indexg // invfM invrK -mulrA.
congr (_ * _); rewrite mulr_sumr; apply: eq_bigr => _ /morphimP[y Dy Gy ->].
rewrite -(card_rcoset _ y) mulr_natl -sumr_const.
apply: eq_big => [z | z /andP[Gz /eqP <-]].
have [Gz | G'z] := boolP (z \in G).
by rewrite (sameP eqP (rcoset_kerP _ _ _)) ?inD.
by case: rcosetP G'z => // [[t Kt ->]]; rewrite groupM // (subsetP sKG).
have [Dz Dxz] := (inD z Gz, inD (x ^ z) (groupJ Gx Gz)); rewrite -morphJ //.
have [Hxz | notHxz] := boolP (x ^ z \in H); first by rewrite cfMorphE.
by rewrite !cfun0 // -sub1set -morphim_set1 // morphimSGK ?sub1set.
Qed.
Variables (g : {morphism G >-> rT}) (h : {morphism H >-> rT}).
Hypotheses (isoG : isom G R g) (isoH : isom H S h) (eq_hg : {in H, h =1 g}).
Hypothesis sHG : H \subset G.
Lemma cfResIsom phi : 'Res[S] (cfIsom isoG phi) = cfIsom isoH ('Res[H] phi).
Proof.
have [[injg defR] [injh defS]] := (isomP isoG, isomP isoH).
rewrite !morphimEdom in defS defR; apply/cfun_inP=> s.
rewrite -{1}defS => /imsetP[x Hx ->] {s}; have Gx := subsetP sHG x Hx.
rewrite {1}eq_hg ?(cfResE, cfIsomE) // -defS -?eq_hg ?imset_f // -defR.
by rewrite (eq_in_imset eq_hg) imsetS.
Qed.
Lemma cfIndIsom phi : 'Ind[R] (cfIsom isoH phi) = cfIsom isoG ('Ind[G] phi).
Proof.
have [[injg defR] [_ defS]] := (isomP isoG, isomP isoH).
rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS.
apply/cfun_inP=> s; rewrite -{1}defR => /morphimP[x _ Gx ->]{s}.
rewrite cfIsomE ?cfIndE // -defR -{1}defS ?morphimS ?card_injm // morphimEdom.
congr (_ * _); rewrite big_imset //=; last exact/injmP.
apply: eq_bigr => y Gy; rewrite -morphJ //.
have [Hxy | H'xy] := boolP (x ^ y \in H); first by rewrite -eq_hg ?cfIsomE.
by rewrite !cfun0 -?defS // -sub1set -morphim_set1 ?injmSK ?sub1set // groupJ.
Qed.
End MorphInduced.
Section FieldAutomorphism.
Variables (u : {rmorphism algC -> algC}) (gT rT : finGroupType).
Variables (G K H : {group gT}) (f : {morphism G >-> rT}) (R : {group rT}).
Implicit Types (phi : 'CF(G)) (S : seq 'CF(G)).
Local Notation "phi ^u" := (cfAut u phi).
Lemma cfAutZ_nat n phi : (n%:R *: phi)^u = n%:R *: phi^u.
Proof. exact: raddfZnat. Qed.
Lemma cfAutZ_Cnat z phi : z \in Num.nat -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_nat. Qed.
Lemma cfAutZ_Cint z phi : z \in Num.int -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_int. Qed.
Lemma cfAutK : cancel (@cfAut gT G u) (cfAut (algC_invaut u)).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_autK. Qed.
Lemma cfAutVK : cancel (cfAut (algC_invaut u)) (@cfAut gT G u).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_invautK. Qed.
Lemma cfAut_inj : injective (@cfAut gT G u).
Proof. exact: can_inj cfAutK. Qed.
Lemma cfAut_eq1 phi : (cfAut u phi == 1) = (phi == 1).
Proof. by rewrite rmorph_eq1 //; apply: cfAut_inj. Qed.
Lemma support_cfAut phi : support phi^u =i support phi.
Proof. by move=> x; rewrite !inE cfunE fmorph_eq0. Qed.
Lemma map_cfAut_free S : cfAut_closed u S -> free S -> free (map (cfAut u) S).
Proof.
set Su := map _ S => sSuS freeS; have uniqS := free_uniq freeS.
have uniqSu: uniq Su by rewrite (map_inj_uniq cfAut_inj).
have{} sSuS: {subset Su <= S} by move=> _ /mapP[phi Sphi ->]; apply: sSuS.
have [|_ eqSuS] := uniq_min_size uniqSu sSuS; first by rewrite size_map.
by rewrite (perm_free (uniq_perm uniqSu uniqS eqSuS)).
Qed.
Lemma cfAut_on A phi : (phi^u \in 'CF(G, A)) = (phi \in 'CF(G, A)).
Proof. by rewrite !cfun_onE (eq_subset (support_cfAut phi)). Qed.
Lemma cfker_aut phi : cfker phi^u = cfker phi.
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
by apply/forallP/forallP=> Kx y;
have:= Kx y; rewrite !cfunE (inj_eq (fmorph_inj u)).
Qed.
Lemma cfAut_cfuni A : ('1_A)^u = '1_A :> 'CF(G).
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cforder_aut phi : #[phi^u]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfAut_inj. Qed.
Lemma cfAutRes phi : ('Res[H] phi)^u = 'Res phi^u.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutMorph (psi : 'CF(f @* H)) : (cfMorph psi)^u = cfMorph psi^u.
Proof. by apply/cfun_inP=> x Hx; rewrite !cfunElock Hx. Qed.
Lemma cfAutIsom (isoGR : isom G R f) phi :
(cfIsom isoGR phi)^u = cfIsom isoGR phi^u.
Proof.
apply/cfun_inP=> y; have [_ {1}<-] := isomP isoGR => /morphimP[x _ Gx ->{y}].
by rewrite !(cfunE, cfIsomE).
Qed.
Lemma cfAutQuo phi : (phi / H)^u = (phi^u / H)%CF.
Proof. by apply/cfunP=> Hx; rewrite !cfunElock cfker_aut rmorphMn. Qed.
Lemma cfAutMod (psi : 'CF(G / H)) : (psi %% H)^u = (psi^u %% H)%CF.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutInd (psi : 'CF(H)) : ('Ind[G] psi)^u = 'Ind psi^u.
Proof.
have [sHG | not_sHG] := boolP (H \subset G).
apply/cfunP=> x; rewrite !(cfunE, cfIndE) // rmorphM /= fmorphV rmorph_nat.
by congr (_ * _); rewrite rmorph_sum; apply: eq_bigr => y; rewrite !cfunE.
rewrite !cfIndEout // linearZ /= cfAut_cfuni rmorphM rmorph_nat /=.
rewrite -cfdot_cfAut ?rmorph1 // => _ /imageP[x Hx ->].
by rewrite cfun1E Hx !rmorph1.
Qed.
Hypothesis KxH : K \x H = G.
Lemma cfAutDprodl (phi : 'CF(K)) : (cfDprodl KxH phi)^u = cfDprodl KxH phi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEl).
Qed.
Lemma cfAutDprodr (psi : 'CF(H)) : (cfDprodr KxH psi)^u = cfDprodr KxH psi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEr).
Qed.
Lemma cfAutDprod (phi : 'CF(K)) (psi : 'CF(H)) :
(cfDprod KxH phi psi)^u = cfDprod KxH phi^u psi^u.
Proof. by rewrite rmorphM /= cfAutDprodl cfAutDprodr. Qed.
End FieldAutomorphism.
Arguments cfAutK u {gT G}.
Arguments cfAutVK u {gT G}.
Arguments cfAut_inj u {gT G} [phi1 phi2] : rename.
Definition conj_cfRes := cfAutRes conjC.
Definition cfker_conjC := cfker_aut conjC.
Definition conj_cfQuo := cfAutQuo conjC.
Definition conj_cfMod := cfAutMod conjC.
Definition conj_cfInd := cfAutInd conjC.
Definition cfconjC_eq1 := cfAut_eq1 conjC.
|
Lifts.lean
|
/-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Eval.Subring
import Mathlib.Algebra.Polynomial.Monic
/-!
# Polynomials that lift
Given semirings `R` and `S` with a morphism `f : R →+* S`, we define a subsemiring `lifts` of
`S[X]` by the image of `RingHom.of (map f)`.
Then, we prove that a polynomial that lifts can always be lifted to a polynomial of the same degree
and that a monic polynomial that lifts can be lifted to a monic polynomial (of the same degree).
## Main definition
* `lifts (f : R →+* S)` : the subsemiring of polynomials that lift.
## Main results
* `lifts_and_degree_eq` : A polynomial lifts if and only if it can be lifted to a polynomial
of the same degree.
* `lifts_and_degree_eq_and_monic` : A monic polynomial lifts if and only if it can be lifted to a
monic polynomial of the same degree.
* `lifts_iff_alg` : if `R` is commutative, a polynomial lifts if and only if it is in the image of
`mapAlg`, where `mapAlg : R[X] →ₐ[R] S[X]` is the only `R`-algebra map
that sends `X` to `X`.
## Implementation details
In general `R` and `S` are semiring, so `lifts` is a semiring. In the case of rings, see
`lifts_iff_lifts_ring`.
Since we do not assume `R` to be commutative, we cannot say in general that the set of polynomials
that lift is a subalgebra. (By `lift_iff` this is true if `R` is commutative.)
-/
open Polynomial
noncomputable section
namespace Polynomial
universe u v w
section Semiring
variable {R : Type u} [Semiring R] {S : Type v} [Semiring S] {f : R →+* S}
/-- We define the subsemiring of polynomials that lifts as the image of `RingHom.of (map f)`. -/
def lifts (f : R →+* S) : Subsemiring S[X] :=
RingHom.rangeS (mapRingHom f)
theorem mem_lifts (p : S[X]) : p ∈ lifts f ↔ ∃ q : R[X], map f q = p := by
simp only [coe_mapRingHom, lifts, RingHom.mem_rangeS]
theorem lifts_iff_set_range (p : S[X]) : p ∈ lifts f ↔ p ∈ Set.range (map f) := by
simp only [coe_mapRingHom, lifts, Set.mem_range, RingHom.mem_rangeS]
theorem lifts_iff_ringHom_rangeS (p : S[X]) : p ∈ lifts f ↔ p ∈ (mapRingHom f).rangeS := by
simp only [coe_mapRingHom, lifts, RingHom.mem_rangeS]
theorem lifts_iff_coeff_lifts (p : S[X]) : p ∈ lifts f ↔ ∀ n : ℕ, p.coeff n ∈ Set.range f := by
rw [lifts_iff_ringHom_rangeS, mem_map_rangeS f]
rfl
theorem lifts_iff_coeffs_subset_range (p : S[X]) :
p ∈ lifts f ↔ (p.coeffs : Set S) ⊆ Set.range f := by
rw [lifts_iff_coeff_lifts]
constructor
· intro h _ hc
obtain ⟨n, ⟨-, hn⟩⟩ := mem_coeffs_iff.mp hc
exact hn ▸ h n
· intro h n
by_cases hn : p.coeff n = 0
· exact ⟨0, by simp [hn]⟩
· exact h <| coeff_mem_coeffs _ _ hn
/-- If `(r : R)`, then `C (f r)` lifts. -/
theorem C_mem_lifts (f : R →+* S) (r : R) : C (f r) ∈ lifts f :=
⟨C r, by
simp only [coe_mapRingHom, map_C]⟩
/-- If `(s : S)` is in the image of `f`, then `C s` lifts. -/
theorem C'_mem_lifts {f : R →+* S} {s : S} (h : s ∈ Set.range f) : C s ∈ lifts f := by
obtain ⟨r, rfl⟩ := Set.mem_range.1 h
use C r
simp only [coe_mapRingHom, map_C]
/-- The polynomial `X` lifts. -/
theorem X_mem_lifts (f : R →+* S) : (X : S[X]) ∈ lifts f :=
⟨X, by
simp only [coe_mapRingHom, map_X]⟩
/-- The polynomial `X ^ n` lifts. -/
theorem X_pow_mem_lifts (f : R →+* S) (n : ℕ) : (X ^ n : S[X]) ∈ lifts f :=
⟨X ^ n, by
simp only [coe_mapRingHom, map_pow, map_X]⟩
/-- If `p` lifts and `(r : R)` then `r * p` lifts. -/
theorem base_mul_mem_lifts {p : S[X]} (r : R) (hp : p ∈ lifts f) : C (f r) * p ∈ lifts f := by
simp only [lifts, RingHom.mem_rangeS] at hp ⊢
obtain ⟨p₁, rfl⟩ := hp
use C r * p₁
simp only [coe_mapRingHom, map_C, map_mul]
/-- If `(s : S)` is in the image of `f`, then `monomial n s` lifts. -/
theorem monomial_mem_lifts {s : S} (n : ℕ) (h : s ∈ Set.range f) : monomial n s ∈ lifts f := by
obtain ⟨r, rfl⟩ := Set.mem_range.1 h
use monomial n r
simp only [coe_mapRingHom, map_monomial]
/-- If `p` lifts then `p.erase n` lifts. -/
theorem erase_mem_lifts {p : S[X]} (n : ℕ) (h : p ∈ lifts f) : p.erase n ∈ lifts f := by
rw [lifts_iff_ringHom_rangeS, mem_map_rangeS] at h ⊢
intro k
by_cases hk : k = n
· use 0
simp only [hk, RingHom.map_zero, erase_same]
obtain ⟨i, hi⟩ := h k
use i
simp only [hi, hk, erase_ne, Ne, not_false_iff]
section LiftDeg
theorem monomial_mem_lifts_and_degree_eq {s : S} {n : ℕ} (hl : monomial n s ∈ lifts f) :
∃ q : R[X], map f q = monomial n s ∧ q.degree = (monomial n s).degree := by
rcases eq_or_ne s 0 with rfl | h
· exact ⟨0, by simp⟩
obtain ⟨a, rfl⟩ := coeff_monomial_same n s ▸ (monomial n s).lifts_iff_coeff_lifts.mp hl n
refine ⟨monomial n a, map_monomial f, ?_⟩
rw [degree_monomial, degree_monomial n h]
exact mt (fun ha ↦ ha ▸ map_zero f) h
/-- A polynomial lifts if and only if it can be lifted to a polynomial of the same degree. -/
theorem mem_lifts_and_degree_eq {p : S[X]} (hlifts : p ∈ lifts f) :
∃ q : R[X], map f q = p ∧ q.degree = p.degree := by
rw [lifts_iff_coeff_lifts] at hlifts
let g : ℕ → R := fun k ↦ (hlifts k).choose
have hg : ∀ k, f (g k) = p.coeff k := fun k ↦ (hlifts k).choose_spec
let q : R[X] := ∑ k ∈ p.support, monomial k (g k)
have hq : map f q = p := by simp_rw [q, Polynomial.map_sum, map_monomial, hg, ← as_sum_support]
have hq' : q.support = p.support := by
simp_rw [Finset.ext_iff, mem_support_iff, q, finset_sum_coeff, coeff_monomial,
Finset.sum_ite_eq', ite_ne_right_iff, mem_support_iff, and_iff_left_iff_imp, not_imp_not]
exact fun k h ↦ by rw [← hg, h, map_zero]
exact ⟨q, hq, congrArg Finset.max hq'⟩
end LiftDeg
section Monic
/-- A monic polynomial lifts if and only if it can be lifted to a monic polynomial
of the same degree. -/
theorem lifts_and_degree_eq_and_monic [Nontrivial S] {p : S[X]} (hlifts : p ∈ lifts f)
(hp : p.Monic) : ∃ q : R[X], map f q = p ∧ q.degree = p.degree ∧ q.Monic := by
rw [lifts_iff_coeff_lifts] at hlifts
let g : ℕ → R := fun k ↦ (hlifts k).choose
have hg k : f (g k) = p.coeff k := (hlifts k).choose_spec
let q : R[X] := X ^ p.natDegree + ∑ k ∈ Finset.range p.natDegree, C (g k) * X ^ k
have hq : map f q = p := by
simp_rw [q, Polynomial.map_add, Polynomial.map_sum, Polynomial.map_mul, Polynomial.map_pow,
map_X, map_C, hg, ← hp.as_sum]
have h : q.Monic := monic_X_pow_add (by simp_rw [← Fin.sum_univ_eq_sum_range, degree_sum_fin_lt])
exact ⟨q, hq, hq ▸ (h.degree_map f).symm, h⟩
theorem lifts_and_natDegree_eq_and_monic {p : S[X]} (hlifts : p ∈ lifts f) (hp : p.Monic) :
∃ q : R[X], map f q = p ∧ q.natDegree = p.natDegree ∧ q.Monic := by
rcases subsingleton_or_nontrivial S with hR | hR
· obtain rfl : p = 1 := Subsingleton.elim _ _
exact ⟨1, Subsingleton.elim _ _, by simp, by simp⟩
obtain ⟨p', h₁, h₂, h₃⟩ := lifts_and_degree_eq_and_monic hlifts hp
exact ⟨p', h₁, natDegree_eq_of_degree_eq h₂, h₃⟩
end Monic
end Semiring
section Ring
variable {R : Type u} [Ring R] {S : Type v} [Ring S] (f : R →+* S)
/-- The subring of polynomials that lift. -/
def liftsRing (f : R →+* S) : Subring S[X] :=
RingHom.range (mapRingHom f)
/-- If `R` and `S` are rings, `p` is in the subring of polynomials that lift if and only if it is in
the subsemiring of polynomials that lift. -/
theorem lifts_iff_liftsRing (p : S[X]) : p ∈ lifts f ↔ p ∈ liftsRing f := by
simp only [lifts, liftsRing, RingHom.mem_range, RingHom.mem_rangeS]
end Ring
section Algebra
variable {R : Type u} [CommSemiring R] {S : Type v} [Semiring S] [Algebra R S]
/-- A polynomial `p` lifts if and only if it is in the image of `mapAlg`. -/
theorem mem_lifts_iff_mem_alg (R : Type u) [CommSemiring R] {S : Type v} [Semiring S] [Algebra R S]
(p : S[X]) : p ∈ lifts (algebraMap R S) ↔ p ∈ AlgHom.range (@mapAlg R _ S _ _) := by
simp only [coe_mapRingHom, lifts, mapAlg_eq_map, AlgHom.mem_range, RingHom.mem_rangeS]
/-- If `p` lifts and `(r : R)` then `r • p` lifts. -/
theorem smul_mem_lifts {p : S[X]} (r : R) (hp : p ∈ lifts (algebraMap R S)) :
r • p ∈ lifts (algebraMap R S) := by
rw [mem_lifts_iff_mem_alg] at hp ⊢
exact Subalgebra.smul_mem (mapAlg R S).range hp r
theorem monic_of_monic_mapAlg [FaithfulSMul R S] {p : Polynomial R} (hp : (mapAlg R S p).Monic) :
p.Monic :=
monic_of_injective (FaithfulSMul.algebraMap_injective R S) hp
end Algebra
end Polynomial
|
Ideal.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.Algebra.MonoidAlgebra.Ideal
import Mathlib.Algebra.MvPolynomial.Division
/-!
# Lemmas about ideals of `MvPolynomial`
Notably this contains results about monomial ideals.
## Main results
* `MvPolynomial.mem_ideal_span_monomial_image`
* `MvPolynomial.mem_ideal_span_X_image`
-/
variable {σ R : Type*}
namespace MvPolynomial
variable [CommSemiring R]
/-- `x` is in a monomial ideal generated by `s` iff every element of its support dominates one of
the generators. Note that `si ≤ xi` is analogous to saying that the monomial corresponding to `si`
divides the monomial corresponding to `xi`. -/
theorem mem_ideal_span_monomial_image {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} :
x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔ ∀ xi ∈ x.support, ∃ si ∈ s, si ≤ xi := by
refine AddMonoidAlgebra.mem_ideal_span_of'_image.trans ?_
simp_rw [le_iff_exists_add, add_comm]
rfl
theorem mem_ideal_span_monomial_image_iff_dvd {x : MvPolynomial σ R} {s : Set (σ →₀ ℕ)} :
x ∈ Ideal.span ((fun s => monomial s (1 : R)) '' s) ↔
∀ xi ∈ x.support, ∃ si ∈ s, monomial si 1 ∣ monomial xi (x.coeff xi) := by
refine mem_ideal_span_monomial_image.trans (forall₂_congr fun xi hxi => ?_)
simp_rw [monomial_dvd_monomial, one_dvd, and_true, mem_support_iff.mp hxi, false_or]
/-- `x` is in a monomial ideal generated by variables `X` iff every element of its support
has a component in `s`. -/
theorem mem_ideal_span_X_image {x : MvPolynomial σ R} {s : Set σ} :
x ∈ Ideal.span (MvPolynomial.X '' s : Set (MvPolynomial σ R)) ↔
∀ m ∈ x.support, ∃ i ∈ s, (m : σ →₀ ℕ) i ≠ 0 := by
have := @mem_ideal_span_monomial_image σ R _ x ((fun i => Finsupp.single i 1) '' s)
rw [Set.image_image] at this
refine this.trans ?_
simp [Nat.one_le_iff_ne_zero]
end MvPolynomial
|
Core.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.Tactic.Attr.Register
/-!
# Simp tags for core lemmas
In Lean 4, an attribute declared with `register_simp_attr` cannot be used in the same file. So, we
declare all `simp` attributes used in `Mathlib` in `Mathlib/Tactic/Attr/Register` and tag lemmas
from the core library and the `Batteries` library with these attributes in this file.
-/
attribute [simp] id_map'
attribute [functor_norm, monad_norm] seq_assoc pure_seq pure_bind bind_assoc bind_pure map_pure
attribute [monad_norm] seq_eq_bind_map
-- Porting note: changed some `iff` lemmas to `eq` lemmas
attribute [mfld_simps] id and_true true_and Function.comp_apply and_self eq_self not_false
true_or or_true heq_eq_eq forall_const and_imp
attribute [nontriviality] eq_iff_true_of_subsingleton
|
Tendsto.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad
-/
import Mathlib.Order.Filter.Basic
import Mathlib.Order.Filter.Map
/-!
# Convergence in terms of filters
The general notion of limit of a map with respect to filters on the source and target types
is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation.
For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to
some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of
`M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`,
which is a special case of `mem_closure_of_tendsto` from `Topology/Basic`.
-/
open Set Filter
variable {α β γ : Type*} {ι : Sort*}
namespace Filter
theorem tendsto_def {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, f ⁻¹' s ∈ l₁ :=
Iff.rfl
theorem tendsto_iff_eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ ⦃p : β → Prop⦄, (∀ᶠ y in l₂, p y) → ∀ᶠ x in l₁, p (f x) :=
Iff.rfl
theorem tendsto_iff_forall_eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ ∀ s ∈ l₂, ∀ᶠ x in l₁, f x ∈ s :=
Iff.rfl
lemma Tendsto.eventually_mem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {s : Set β}
(hf : Tendsto f l₁ l₂) (h : s ∈ l₂) : ∀ᶠ x in l₁, f x ∈ s :=
hf h
theorem Tendsto.eventually {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop}
(hf : Tendsto f l₁ l₂) (h : ∀ᶠ y in l₂, p y) : ∀ᶠ x in l₁, p (f x) :=
hf h
theorem not_tendsto_iff_exists_frequently_notMem {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
¬Tendsto f l₁ l₂ ↔ ∃ s ∈ l₂, ∃ᶠ x in l₁, f x ∉ s := by
simp only [tendsto_iff_forall_eventually_mem, not_forall, exists_prop, not_eventually]
@[deprecated (since := "2025-05-24")]
alias not_tendsto_iff_exists_frequently_nmem := not_tendsto_iff_exists_frequently_notMem
theorem Tendsto.frequently {f : α → β} {l₁ : Filter α} {l₂ : Filter β} {p : β → Prop}
(hf : Tendsto f l₁ l₂) (h : ∃ᶠ x in l₁, p (f x)) : ∃ᶠ y in l₂, p y :=
mt hf.eventually h
theorem Tendsto.frequently_map {l₁ : Filter α} {l₂ : Filter β} {p : α → Prop} {q : β → Prop}
(f : α → β) (c : Filter.Tendsto f l₁ l₂) (w : ∀ x, p x → q (f x)) (h : ∃ᶠ x in l₁, p x) :
∃ᶠ y in l₂, q y :=
c.frequently (h.mono w)
@[simp]
theorem tendsto_bot {f : α → β} {l : Filter β} : Tendsto f ⊥ l := by simp [Tendsto]
theorem Tendsto.of_neBot_imp {f : α → β} {la : Filter α} {lb : Filter β}
(h : NeBot la → Tendsto f la lb) : Tendsto f la lb := by
rcases eq_or_neBot la with rfl | hla
· exact tendsto_bot
· exact h hla
@[simp] theorem tendsto_top {f : α → β} {l : Filter α} : Tendsto f l ⊤ := le_top
theorem le_map_of_right_inverse {mab : α → β} {mba : β → α} {f : Filter α} {g : Filter β}
(h₁ : mab ∘ mba =ᶠ[g] id) (h₂ : Tendsto mba g f) : g ≤ map mab f := by
rw [← @map_id _ g, ← map_congr h₁, ← map_map]
exact map_mono h₂
theorem tendsto_of_isEmpty [IsEmpty α] {f : α → β} {la : Filter α} {lb : Filter β} :
Tendsto f la lb := by simp only [filter_eq_bot_of_isEmpty la, tendsto_bot]
theorem eventuallyEq_of_left_inv_of_right_inv {f : α → β} {g₁ g₂ : β → α} {fa : Filter α}
{fb : Filter β} (hleft : ∀ᶠ x in fa, g₁ (f x) = x) (hright : ∀ᶠ y in fb, f (g₂ y) = y)
(htendsto : Tendsto g₂ fb fa) : g₁ =ᶠ[fb] g₂ :=
(htendsto.eventually hleft).mp <| hright.mono fun _ hr hl => (congr_arg g₁ hr.symm).trans hl
theorem tendsto_iff_comap {f : α → β} {l₁ : Filter α} {l₂ : Filter β} :
Tendsto f l₁ l₂ ↔ l₁ ≤ l₂.comap f :=
map_le_iff_le_comap
alias ⟨Tendsto.le_comap, _⟩ := tendsto_iff_comap
protected theorem Tendsto.disjoint {f : α → β} {la₁ la₂ : Filter α} {lb₁ lb₂ : Filter β}
(h₁ : Tendsto f la₁ lb₁) (hd : Disjoint lb₁ lb₂) (h₂ : Tendsto f la₂ lb₂) : Disjoint la₁ la₂ :=
(disjoint_comap hd).mono h₁.le_comap h₂.le_comap
theorem tendsto_congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂) :
Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ := by rw [Tendsto, Tendsto, map_congr hl]
theorem Tendsto.congr' {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (hl : f₁ =ᶠ[l₁] f₂)
(h : Tendsto f₁ l₁ l₂) : Tendsto f₂ l₁ l₂ :=
(tendsto_congr' hl).1 h
theorem tendsto_congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) :
Tendsto f₁ l₁ l₂ ↔ Tendsto f₂ l₁ l₂ :=
tendsto_congr' (univ_mem' h)
theorem Tendsto.congr {f₁ f₂ : α → β} {l₁ : Filter α} {l₂ : Filter β} (h : ∀ x, f₁ x = f₂ x) :
Tendsto f₁ l₁ l₂ → Tendsto f₂ l₁ l₂ :=
(tendsto_congr h).1
theorem tendsto_id' {x y : Filter α} : Tendsto id x y ↔ x ≤ y :=
Iff.rfl
theorem tendsto_id {x : Filter α} : Tendsto id x x :=
le_refl x
theorem Tendsto.comp {f : α → β} {g : β → γ} {x : Filter α} {y : Filter β} {z : Filter γ}
(hg : Tendsto g y z) (hf : Tendsto f x y) : Tendsto (g ∘ f) x z := fun _ hs => hf (hg hs)
protected theorem Tendsto.iterate {f : α → α} {l : Filter α} (h : Tendsto f l l) :
∀ n, Tendsto (f^[n]) l l
| 0 => tendsto_id
| (n + 1) => (h.iterate n).comp h
theorem Tendsto.mono_left {f : α → β} {x y : Filter α} {z : Filter β} (hx : Tendsto f x z)
(h : y ≤ x) : Tendsto f y z :=
(map_mono h).trans hx
theorem Tendsto.mono_right {f : α → β} {x : Filter α} {y z : Filter β} (hy : Tendsto f x y)
(hz : y ≤ z) : Tendsto f x z :=
le_trans hy hz
theorem Tendsto.neBot {f : α → β} {x : Filter α} {y : Filter β} (h : Tendsto f x y) [hx : NeBot x] :
NeBot y :=
(hx.map _).mono h
theorem tendsto_map {f : α → β} {x : Filter α} : Tendsto f x (map f x) :=
le_refl (map f x)
@[simp]
theorem tendsto_map'_iff {f : β → γ} {g : α → β} {x : Filter α} {y : Filter γ} :
Tendsto f (map g x) y ↔ Tendsto (f ∘ g) x y := by
rw [Tendsto, Tendsto, map_map]
alias ⟨_, tendsto_map'⟩ := tendsto_map'_iff
theorem tendsto_comap {f : α → β} {x : Filter β} : Tendsto f (comap f x) x :=
map_comap_le
@[simp]
theorem tendsto_comap_iff {f : α → β} {g : β → γ} {a : Filter α} {c : Filter γ} :
Tendsto f a (c.comap g) ↔ Tendsto (g ∘ f) a c :=
⟨fun h => tendsto_comap.comp h, fun h => map_le_iff_le_comap.mp <| by rwa [map_map]⟩
theorem tendsto_comap'_iff {m : α → β} {f : Filter α} {g : Filter β} {i : γ → α} (h : range i ∈ f) :
Tendsto (m ∘ i) (comap i f) g ↔ Tendsto m f g := by
rw [Tendsto, ← map_compose]
simp only [(· ∘ ·), map_comap_of_mem h, Tendsto]
theorem Tendsto.of_tendsto_comp {f : α → β} {g : β → γ} {a : Filter α} {b : Filter β} {c : Filter γ}
(hfg : Tendsto (g ∘ f) a c) (hg : comap g c ≤ b) : Tendsto f a b := by
rw [tendsto_iff_comap] at hfg ⊢
calc
a ≤ comap (g ∘ f) c := hfg
_ ≤ comap f b := by simpa [comap_comap] using comap_mono hg
theorem comap_eq_of_inverse {f : Filter α} {g : Filter β} {φ : α → β} (ψ : β → α) (eq : ψ ∘ φ = id)
(hφ : Tendsto φ f g) (hψ : Tendsto ψ g f) : comap φ g = f := by
refine ((comap_mono <| map_le_iff_le_comap.1 hψ).trans ?_).antisymm (map_le_iff_le_comap.1 hφ)
rw [comap_comap, eq, comap_id]
theorem map_eq_of_inverse {f : Filter α} {g : Filter β} {φ : α → β} (ψ : β → α) (eq : φ ∘ ψ = id)
(hφ : Tendsto φ f g) (hψ : Tendsto ψ g f) : map φ f = g := by
refine le_antisymm hφ (le_trans ?_ (map_mono hψ))
rw [map_map, eq, map_id]
theorem tendsto_inf {f : α → β} {x : Filter α} {y₁ y₂ : Filter β} :
Tendsto f x (y₁ ⊓ y₂) ↔ Tendsto f x y₁ ∧ Tendsto f x y₂ := by
simp only [Tendsto, le_inf_iff]
theorem tendsto_inf_left {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} (h : Tendsto f x₁ y) :
Tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_left) h
theorem tendsto_inf_right {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} (h : Tendsto f x₂ y) :
Tendsto f (x₁ ⊓ x₂) y :=
le_trans (map_mono inf_le_right) h
theorem Tendsto.inf {f : α → β} {x₁ x₂ : Filter α} {y₁ y₂ : Filter β} (h₁ : Tendsto f x₁ y₁)
(h₂ : Tendsto f x₂ y₂) : Tendsto f (x₁ ⊓ x₂) (y₁ ⊓ y₂) :=
tendsto_inf.2 ⟨tendsto_inf_left h₁, tendsto_inf_right h₂⟩
@[simp]
theorem tendsto_iInf {f : α → β} {x : Filter α} {y : ι → Filter β} :
Tendsto f x (⨅ i, y i) ↔ ∀ i, Tendsto f x (y i) := by
simp only [Tendsto, le_iInf_iff]
theorem tendsto_iInf' {f : α → β} {x : ι → Filter α} {y : Filter β} (i : ι)
(hi : Tendsto f (x i) y) : Tendsto f (⨅ i, x i) y :=
hi.mono_left <| iInf_le _ _
theorem tendsto_iInf_iInf {f : α → β} {x : ι → Filter α} {y : ι → Filter β}
(h : ∀ i, Tendsto f (x i) (y i)) : Tendsto f (iInf x) (iInf y) :=
tendsto_iInf.2 fun i => tendsto_iInf' i (h i)
@[simp]
theorem tendsto_sup {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} :
Tendsto f (x₁ ⊔ x₂) y ↔ Tendsto f x₁ y ∧ Tendsto f x₂ y := by
simp only [Tendsto, map_sup, sup_le_iff]
theorem Tendsto.sup {f : α → β} {x₁ x₂ : Filter α} {y : Filter β} :
Tendsto f x₁ y → Tendsto f x₂ y → Tendsto f (x₁ ⊔ x₂) y := fun h₁ h₂ => tendsto_sup.mpr ⟨h₁, h₂⟩
theorem Tendsto.sup_sup {f : α → β} {x₁ x₂ : Filter α} {y₁ y₂ : Filter β}
(h₁ : Tendsto f x₁ y₁) (h₂ : Tendsto f x₂ y₂) : Tendsto f (x₁ ⊔ x₂) (y₁ ⊔ y₂) :=
tendsto_sup.mpr ⟨h₁.mono_right le_sup_left, h₂.mono_right le_sup_right⟩
@[simp]
theorem tendsto_iSup {f : α → β} {x : ι → Filter α} {y : Filter β} :
Tendsto f (⨆ i, x i) y ↔ ∀ i, Tendsto f (x i) y := by simp only [Tendsto, map_iSup, iSup_le_iff]
theorem tendsto_iSup_iSup {f : α → β} {x : ι → Filter α} {y : ι → Filter β}
(h : ∀ i, Tendsto f (x i) (y i)) : Tendsto f (iSup x) (iSup y) :=
tendsto_iSup.2 fun i => (h i).mono_right <| le_iSup _ _
@[simp] theorem tendsto_principal {f : α → β} {l : Filter α} {s : Set β} :
Tendsto f l (𝓟 s) ↔ ∀ᶠ a in l, f a ∈ s := by
simp only [Tendsto, le_principal_iff, mem_map', Filter.Eventually]
theorem tendsto_principal_principal {f : α → β} {s : Set α} {t : Set β} :
Tendsto f (𝓟 s) (𝓟 t) ↔ ∀ a ∈ s, f a ∈ t := by
simp
@[simp] theorem tendsto_pure {f : α → β} {a : Filter α} {b : β} :
Tendsto f a (pure b) ↔ ∀ᶠ x in a, f x = b := by
simp only [Tendsto, le_pure_iff, mem_map', mem_singleton_iff, Filter.Eventually]
theorem tendsto_pure_pure (f : α → β) (a : α) : Tendsto f (pure a) (pure (f a)) :=
tendsto_pure.2 rfl
theorem tendsto_const_pure {a : Filter α} {b : β} : Tendsto (fun _ => b) a (pure b) :=
tendsto_pure.2 <| univ_mem' fun _ => rfl
theorem pure_le_iff {a : α} {l : Filter α} : pure a ≤ l ↔ ∀ s ∈ l, a ∈ s :=
Iff.rfl
theorem tendsto_pure_left {f : α → β} {a : α} {l : Filter β} :
Tendsto f (pure a) l ↔ ∀ s ∈ l, f a ∈ s :=
Iff.rfl
@[simp]
theorem map_inf_principal_preimage {f : α → β} {s : Set β} {l : Filter α} :
map f (l ⊓ 𝓟 (f ⁻¹' s)) = map f l ⊓ 𝓟 s :=
Filter.ext fun t => by simp only [mem_map', mem_inf_principal, mem_setOf_eq, mem_preimage]
/-- If two filters are disjoint, then a function cannot tend to both of them along a non-trivial
filter. -/
theorem Tendsto.not_tendsto {f : α → β} {a : Filter α} {b₁ b₂ : Filter β} (hf : Tendsto f a b₁)
[NeBot a] (hb : Disjoint b₁ b₂) : ¬Tendsto f a b₂ := fun hf' =>
(tendsto_inf.2 ⟨hf, hf'⟩).neBot.ne hb.eq_bot
protected theorem Tendsto.if {l₁ : Filter α} {l₂ : Filter β} {f g : α → β} {p : α → Prop}
[∀ x, Decidable (p x)] (h₀ : Tendsto f (l₁ ⊓ 𝓟 { x | p x }) l₂)
(h₁ : Tendsto g (l₁ ⊓ 𝓟 { x | ¬p x }) l₂) :
Tendsto (fun x => if p x then f x else g x) l₁ l₂ := by
simp only [tendsto_def, mem_inf_principal] at *
intro s hs
filter_upwards [h₀ s hs, h₁ s hs] with x hp₀ hp₁
rw [mem_preimage]
split_ifs with h
exacts [hp₀ h, hp₁ h]
protected theorem Tendsto.if' {α β : Type*} {l₁ : Filter α} {l₂ : Filter β} {f g : α → β}
{p : α → Prop} [DecidablePred p] (hf : Tendsto f l₁ l₂) (hg : Tendsto g l₁ l₂) :
Tendsto (fun a => if p a then f a else g a) l₁ l₂ :=
(tendsto_inf_left hf).if (tendsto_inf_left hg)
protected theorem Tendsto.piecewise {l₁ : Filter α} {l₂ : Filter β} {f g : α → β} {s : Set α}
[∀ x, Decidable (x ∈ s)] (h₀ : Tendsto f (l₁ ⊓ 𝓟 s) l₂) (h₁ : Tendsto g (l₁ ⊓ 𝓟 sᶜ) l₂) :
Tendsto (piecewise s f g) l₁ l₂ :=
Tendsto.if h₀ h₁
end Filter
theorem Set.MapsTo.tendsto {s : Set α} {t : Set β} {f : α → β} (h : MapsTo f s t) :
Filter.Tendsto f (𝓟 s) (𝓟 t) :=
Filter.tendsto_principal_principal.2 h
theorem Filter.EventuallyEq.comp_tendsto {l : Filter α} {f : α → β} {f' : α → β}
(H : f =ᶠ[l] f') {g : γ → α} {lc : Filter γ} (hg : Tendsto g lc l) :
f ∘ g =ᶠ[lc] f' ∘ g :=
hg.eventually H
variable {F : Filter α} {G : Filter β}
theorem Filter.map_mapsTo_Iic_iff_tendsto {m : α → β} :
MapsTo (map m) (Iic F) (Iic G) ↔ Tendsto m F G :=
⟨fun hm ↦ hm right_mem_Iic, fun hm _ ↦ hm.mono_left⟩
alias ⟨_, Filter.Tendsto.map_mapsTo_Iic⟩ := Filter.map_mapsTo_Iic_iff_tendsto
theorem Filter.map_mapsTo_Iic_iff_mapsTo {s : Set α} {t : Set β} {m : α → β} :
MapsTo (map m) (Iic <| 𝓟 s) (Iic <| 𝓟 t) ↔ MapsTo m s t := by
rw [map_mapsTo_Iic_iff_tendsto, tendsto_principal_principal, MapsTo]
alias ⟨_, Set.MapsTo.filter_map_Iic⟩ := Filter.map_mapsTo_Iic_iff_mapsTo
|
seq.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat.
(******************************************************************************)
(* The seq type is the ssreflect type for sequences; it is an alias for the *)
(* standard Coq list type. The ssreflect library equips it with many *)
(* operations, as well as eqType and predType (and, later, choiceType) *)
(* structures. The operations are geared towards reflection: they generally *)
(* expect and provide boolean predicates, e.g., the membership predicate *)
(* expects an eqType. To avoid any confusion we do not Import the Coq List *)
(* module. *)
(* As there is no true subtyping in Coq, we don't use a type for non-empty *)
(* sequences; rather, we pass explicitly the head and tail of the sequence. *)
(* The empty sequence is especially bothersome for subscripting, since it *)
(* forces us to pass a default value. This default value can often be hidden *)
(* by a notation. *)
(* Here is the list of seq operations: *)
(* ** Constructors: *)
(* seq T == the type of sequences of items of type T. *)
(* bitseq == seq bool. *)
(* [::], nil, Nil T == the empty sequence (of type T). *)
(* x :: s, cons x s, Cons T x s == the sequence x followed by s (of type T). *)
(* [:: x] == the singleton sequence. *)
(* [:: x_0; ...; x_n] == the explicit sequence of the x_i. *)
(* [:: x_0, ..., x_n & s] == the sequence of the x_i, followed by s. *)
(* rcons s x == the sequence s, followed by x. *)
(* All of the above, except rcons, can be used in patterns. We define a view *)
(* lastP and an induction principle last_ind that can be used to decompose *)
(* or traverse a sequence in a right to left order. The view lemma lastP has *)
(* a dependent family type, so the ssreflect tactic case/lastP: p => [|p' x] *)
(* will generate two subgoals in which p has been replaced by [::] and by *)
(* rcons p' x, respectively. *)
(* ** Factories: *)
(* nseq n x == a sequence of n x's. *)
(* ncons n x s == a sequence of n x's, followed by s. *)
(* seqn n x_0 ... x_n-1 == the sequence of the x_i; can be partially applied. *)
(* iota m n == the sequence m, m + 1, ..., m + n - 1. *)
(* mkseq f n == the sequence f 0, f 1, ..., f (n - 1). *)
(* ** Sequential access: *)
(* head x0 s == the head (zero'th item) of s if s is non-empty, else x0. *)
(* ohead s == None if s is empty, else Some x when the head of s is x. *)
(* behead s == s minus its head, i.e., s' if s = x :: s', else [::]. *)
(* last x s == the last element of x :: s (which is non-empty). *)
(* belast x s == x :: s minus its last item. *)
(* ** Dimensions: *)
(* size s == the number of items (length) in s. *)
(* shape ss == the sequence of sizes of the items of the sequence of *)
(* sequences ss. *)
(* ** Random access: *)
(* nth x0 s i == the item i of s (numbered from 0), or x0 if s does *)
(* not have at least i+1 items (i.e., size x <= i) *)
(* s`_i == standard notation for nth x0 s i for a default x0, *)
(* e.g., 0 for rings. *)
(* onth s i == Some x if x is the i^th idem of s (numbered from 0), *)
(* or None if size s <= i) *)
(* set_nth x0 s i y == s where item i has been changed to y; if s does not *)
(* have an item i, it is first padded with copies of x0 *)
(* to size i+1. *)
(* incr_nth s i == the nat sequence s with item i incremented (s is *)
(* first padded with 0's to size i+1, if needed). *)
(* ** Predicates: *)
(* nilp s <=> s is [::]. *)
(* := (size s == 0). *)
(* x \in s == x appears in s (this requires an eqType for T). *)
(* index x s == the first index at which x appears in s, or size s if *)
(* x \notin s. *)
(* has a s <=> a holds for some item in s, where a is an applicative *)
(* bool predicate. *)
(* all a s <=> a holds for all items in s. *)
(* 'has_aP <-> the view reflect (exists2 x, x \in s & A x) (has a s), *)
(* where aP x : reflect (A x) (a x). *)
(* 'all_aP <=> the view for reflect {in s, forall x, A x} (all a s). *)
(* all2 r s t <=> the (bool) relation r holds for all _respective_ items *)
(* in s and t, which must also have the same size, i.e., *)
(* for s := [:: x1; ...; x_m] and t := [:: y1; ...; y_n], *)
(* the condition [&& r x_1 y_1, ..., r x_n y_n & m == n]. *)
(* find p s == the index of the first item in s for which p holds, *)
(* or size s if no such item is found. *)
(* count p s == the number of items of s for which p holds. *)
(* count_mem x s == the multiplicity of x in s, i.e., count (pred1 x) s. *)
(* tally s == a tally of s, i.e., a sequence of (item, multiplicity) *)
(* pairs for all items in sequence s (without duplicates). *)
(* incr_tally bs x == increment the multiplicity of x in the tally bs, or add *)
(* x with multiplicity 1 at then end if x is not in bs. *)
(* bs \is a wf_tally <=> bs is well-formed tally, with no duplicate items or *)
(* null multiplicities. *)
(* tally_seq bs == the expansion of a tally bs into a sequence where each *)
(* (x, n) pair expands into a sequence of n x's. *)
(* constant s <=> all items in s are identical (trivial if s = [::]). *)
(* uniq s <=> all the items in s are pairwise different. *)
(* subseq s1 s2 <=> s1 is a subsequence of s2, i.e., s1 = mask m s2 for *)
(* some m : bitseq (see below). *)
(* infix s1 s2 <=> s1 is a contiguous subsequence of s2, i.e., *)
(* s ++ s1 ++ s' = s2 for some sequences s, s'. *)
(* prefix s1 s2 <=> s1 is a subchain of s2 appearing at the beginning *)
(* of s2. *)
(* suffix s1 s2 <=> s1 is a subchain of s2 appearing at the end of s2. *)
(* infix_index s1 s2 <=> the first index at which s1 appears in s2, *)
(* or (size s2).+1 if infix s1 s2 is false. *)
(* perm_eq s1 s2 <=> s2 is a permutation of s1, i.e., s1 and s2 have the *)
(* items (with the same repetitions), but possibly in a *)
(* different order. *)
(* perm_eql s1 s2 <-> s1 and s2 behave identically on the left of perm_eq. *)
(* perm_eqr s1 s2 <-> s1 and s2 behave identically on the right of perm_eq. *)
(* --> These left/right transitive versions of perm_eq make it easier to *)
(* chain a sequence of equivalences. *)
(* permutations s == a duplicate-free list of all permutations of s. *)
(* ** Filtering: *)
(* filter p s == the subsequence of s consisting of all the items *)
(* for which the (boolean) predicate p holds. *)
(* rem x s == the subsequence of s, where the first occurrence *)
(* of x has been removed (compare filter (predC1 x) s *)
(* where ALL occurrences of x are removed). *)
(* undup s == the subsequence of s containing only the first *)
(* occurrence of each item in s, i.e., s with all *)
(* duplicates removed. *)
(* mask m s == the subsequence of s selected by m : bitseq, with *)
(* item i of s selected by bit i in m (extra items or *)
(* bits are ignored. *)
(* ** Surgery: *)
(* s1 ++ s2, cat s1 s2 == the concatenation of s1 and s2. *)
(* take n s == the sequence containing only the first n items of s *)
(* (or all of s if size s <= n). *)
(* drop n s == s minus its first n items ([::] if size s <= n) *)
(* rot n s == s rotated left n times (or s if size s <= n). *)
(* := drop n s ++ take n s *)
(* rotr n s == s rotated right n times (or s if size s <= n). *)
(* rev s == the (linear time) reversal of s. *)
(* catrev s1 s2 == the reversal of s1 followed by s2 (this is the *)
(* recursive form of rev). *)
(* ** Dependent iterator: for s : seq S and t : S -> seq T *)
(* [seq E | x <- s, y <- t] := flatten [seq [seq E | x <- t] | y <- s] *)
(* == the sequence of all the f x y, with x and y drawn from *)
(* s and t, respectively, in row-major order, *)
(* and where t is possibly dependent in elements of s *)
(* allpairs_dep f s t := self expanding definition for *)
(* [seq f x y | x <- s, y <- t y] *)
(* ** Iterators: for s == [:: x_1, ..., x_n], t == [:: y_1, ..., y_m], *)
(* allpairs f s t := same as allpairs_dep but where t is non dependent, *)
(* i.e. self expanding definition for *)
(* [seq f x y | x <- s, y <- t] *)
(* := [:: f x_1 y_1; ...; f x_1 y_m; f x_2 y_1; ...; f x_n y_m] *)
(* allrel r xs ys := all [pred x | all (r x) ys] xs *)
(* <=> r x y holds whenever x is in xs and y is in ys *)
(* all2rel r xs := allrel r xs xs *)
(* <=> the proposition r x y holds for all possible x, y in xs.*)
(* pairwise r xs <=> the relation r holds for any i-th and j-th element of *)
(* xs such that i < j. *)
(* map f s == the sequence [:: f x_1, ..., f x_n]. *)
(* pmap pf s == the sequence [:: y_i1, ..., y_ik] where i1 < ... < ik, *)
(* pf x_i = Some y_i, and pf x_j = None iff j is not in *)
(* {i1, ..., ik}. *)
(* foldr f a s == the right fold of s by f (i.e., the natural iterator). *)
(* := f x_1 (f x_2 ... (f x_n a)) *)
(* sumn s == x_1 + (x_2 + ... + (x_n + 0)) (when s : seq nat). *)
(* foldl f a s == the left fold of s by f. *)
(* := f (f ... (f a x_1) ... x_n-1) x_n *)
(* scanl f a s == the sequence of partial accumulators of foldl f a s. *)
(* := [:: f a x_1; ...; foldl f a s] *)
(* pairmap f a s == the sequence of f applied to consecutive items in a :: s. *)
(* := [:: f a x_1; f x_1 x_2; ...; f x_n-1 x_n] *)
(* zip s t == itemwise pairing of s and t (dropping any extra items). *)
(* := [:: (x_1, y_1); ...; (x_mn, y_mn)] with mn = minn n m. *)
(* unzip1 s == [:: (x_1).1; ...; (x_n).1] when s : seq (S * T). *)
(* unzip2 s == [:: (x_1).2; ...; (x_n).2] when s : seq (S * T). *)
(* flatten s == x_1 ++ ... ++ x_n ++ [::] when s : seq (seq T). *)
(* reshape r s == s reshaped into a sequence of sequences whose sizes are *)
(* given by r (truncating if s is too long or too short). *)
(* := [:: [:: x_1; ...; x_r1]; *)
(* [:: x_(r1 + 1); ...; x_(r0 + r1)]; *)
(* ...; *)
(* [:: x_(r1 + ... + r(k-1) + 1); ...; x_(r0 + ... rk)]] *)
(* flatten_index sh r c == the index, in flatten ss, of the item of indexes *)
(* (r, c) in any sequence of sequences ss of shape sh *)
(* := sh_1 + sh_2 + ... + sh_r + c *)
(* reshape_index sh i == the index, in reshape sh s, of the sequence *)
(* containing the i-th item of s. *)
(* reshape_offset sh i == the offset, in the (reshape_index sh i)-th *)
(* sequence of reshape sh s of the i-th item of s *)
(* ** Notation for manifest comprehensions: *)
(* [seq x <- s | C] := filter (fun x => C) s. *)
(* [seq E | x <- s] := map (fun x => E) s. *)
(* [seq x <- s | C1 & C2] := [seq x <- s | C1 && C2]. *)
(* [seq E | x <- s & C] := [seq E | x <- [seq x | C]]. *)
(* --> The above allow optional type casts on the eigenvariables, as in *)
(* [seq x : T <- s | C] or [seq E | x : T <- s, y : U <- t]. The cast may be *)
(* needed as type inference considers E or C before s. *)
(* We are quite systematic in providing lemmas to rewrite any composition *)
(* of two operations. "rev", whose simplifications are not natural, is *)
(* protected with simpl never. *)
(* ** The following are equivalent: *)
(* [<-> P0; P1; ..; Pn] <-> P0, P1, ..., Pn are all equivalent. *)
(* := P0 -> P1 -> ... -> Pn -> P0 *)
(* if T : [<-> P0; P1; ..; Pn] is such an equivalence, and i, j are in nat *)
(* then T i j is a proof of the equivalence Pi <-> Pj between Pi and Pj; *)
(* when i (resp. j) is out of bounds, Pi (resp. Pj) defaults to P0. *)
(* The tactic tfae splits the goal into n+1 implications to prove. *)
(* An example of use can be found in fingraph theorem orbitPcycle. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope seq_scope.
Reserved Notation "[ '<->' P0 ; P1 ; .. ; Pn ]"
(format "[ '<->' '[' P0 ; '/' P1 ; '/' .. ; '/' Pn ']' ]").
Delimit Scope seq_scope with SEQ.
Open Scope seq_scope.
(* Inductive seq (T : Type) : Type := Nil | Cons of T & seq T. *)
Notation seq := list.
Bind Scope seq_scope with list.
Arguments cons {T%_type} x s%_SEQ : rename.
Arguments nil {T%_type} : rename.
Notation Cons T := (@cons T) (only parsing).
Notation Nil T := (@nil T) (only parsing).
(* As :: and ++ are (improperly) declared in Init.datatypes, we only rebind *)
(* them here. *)
Infix "::" := cons : seq_scope.
Notation "[ :: ]" := nil (format "[ :: ]") : seq_scope.
Notation "[ :: x1 ]" := (x1 :: [::]) (format "[ :: x1 ]") : seq_scope.
Notation "[ :: x & s ]" := (x :: s) (only parsing) : seq_scope.
Notation "[ :: x1 , x2 , .. , xn & s ]" := (x1 :: x2 :: .. (xn :: s) ..)
(format
"'[hv' [ :: '[' x1 , '/' x2 , '/' .. , '/' xn ']' '/ ' & s ] ']'"
) : seq_scope.
Notation "[ :: x1 ; x2 ; .. ; xn ]" := (x1 :: x2 :: .. [:: xn] ..)
(format "[ :: '[' x1 ; '/' x2 ; '/' .. ; '/' xn ']' ]"
) : seq_scope.
Section Sequences.
Variable n0 : nat. (* numerical parameter for take, drop et al *)
Variable T : Type. (* must come before the implicit Type *)
Variable x0 : T. (* default for head/nth *)
Implicit Types x y z : T.
Implicit Types m n : nat.
Implicit Type s : seq T.
Fixpoint size s := if s is _ :: s' then (size s').+1 else 0.
Lemma size0nil s : size s = 0 -> s = [::]. Proof. by case: s. Qed.
Definition nilp s := size s == 0.
Lemma nilP s : reflect (s = [::]) (nilp s).
Proof. by case: s => [|x s]; constructor. Qed.
Definition ohead s := if s is x :: _ then Some x else None.
Definition head s := if s is x :: _ then x else x0.
Definition behead s := if s is _ :: s' then s' else [::].
Lemma size_behead s : size (behead s) = (size s).-1.
Proof. by case: s. Qed.
(* Factories *)
Definition ncons n x := iter n (cons x).
Definition nseq n x := ncons n x [::].
Lemma size_ncons n x s : size (ncons n x s) = n + size s.
Proof. by elim: n => //= n ->. Qed.
Lemma size_nseq n x : size (nseq n x) = n.
Proof. by rewrite size_ncons addn0. Qed.
(* n-ary, dependently typed constructor. *)
Fixpoint seqn_type n := if n is n'.+1 then T -> seqn_type n' else seq T.
Fixpoint seqn_rec f n : seqn_type n :=
if n is n'.+1 return seqn_type n then
fun x => seqn_rec (fun s => f (x :: s)) n'
else f [::].
Definition seqn := seqn_rec id.
(* Sequence catenation "cat". *)
Fixpoint cat s1 s2 := if s1 is x :: s1' then x :: s1' ++ s2 else s2
where "s1 ++ s2" := (cat s1 s2) : seq_scope.
Lemma cat0s s : [::] ++ s = s. Proof. by []. Qed.
Lemma cat1s x s : [:: x] ++ s = x :: s. Proof. by []. Qed.
Lemma cat_cons x s1 s2 : (x :: s1) ++ s2 = x :: s1 ++ s2. Proof. by []. Qed.
Lemma cat_nseq n x s : nseq n x ++ s = ncons n x s.
Proof. by elim: n => //= n ->. Qed.
Lemma nseqD n1 n2 x : nseq (n1 + n2) x = nseq n1 x ++ nseq n2 x.
Proof. by rewrite cat_nseq /nseq /ncons iterD. Qed.
Lemma cats0 s : s ++ [::] = s.
Proof. by elim: s => //= x s ->. Qed.
Lemma catA s1 s2 s3 : s1 ++ s2 ++ s3 = (s1 ++ s2) ++ s3.
Proof. by elim: s1 => //= x s1 ->. Qed.
Lemma size_cat s1 s2 : size (s1 ++ s2) = size s1 + size s2.
Proof. by elim: s1 => //= x s1 ->. Qed.
Lemma cat_nilp s1 s2 : nilp (s1 ++ s2) = nilp s1 && nilp s2.
Proof. by case: s1. Qed.
(* last, belast, rcons, and last induction. *)
Fixpoint rcons s z := if s is x :: s' then x :: rcons s' z else [:: z].
Lemma rcons_cons x s z : rcons (x :: s) z = x :: rcons s z.
Proof. by []. Qed.
Lemma cats1 s z : s ++ [:: z] = rcons s z.
Proof. by elim: s => //= x s ->. Qed.
Fixpoint last x s := if s is x' :: s' then last x' s' else x.
Fixpoint belast x s := if s is x' :: s' then x :: (belast x' s') else [::].
Lemma lastI x s : x :: s = rcons (belast x s) (last x s).
Proof. by elim: s x => [|y s IHs] x //=; rewrite IHs. Qed.
Lemma last_cons x y s : last x (y :: s) = last y s.
Proof. by []. Qed.
Lemma size_rcons s x : size (rcons s x) = (size s).+1.
Proof. by rewrite -cats1 size_cat addnC. Qed.
Lemma size_belast x s : size (belast x s) = size s.
Proof. by elim: s x => [|y s IHs] x //=; rewrite IHs. Qed.
Lemma last_cat x s1 s2 : last x (s1 ++ s2) = last (last x s1) s2.
Proof. by elim: s1 x => [|y s1 IHs] x //=; rewrite IHs. Qed.
Lemma last_rcons x s z : last x (rcons s z) = z.
Proof. by rewrite -cats1 last_cat. Qed.
Lemma belast_cat x s1 s2 :
belast x (s1 ++ s2) = belast x s1 ++ belast (last x s1) s2.
Proof. by elim: s1 x => [|y s1 IHs] x //=; rewrite IHs. Qed.
Lemma belast_rcons x s z : belast x (rcons s z) = x :: s.
Proof. by rewrite lastI -!cats1 belast_cat. Qed.
Lemma cat_rcons x s1 s2 : rcons s1 x ++ s2 = s1 ++ x :: s2.
Proof. by rewrite -cats1 -catA. Qed.
Lemma rcons_cat x s1 s2 : rcons (s1 ++ s2) x = s1 ++ rcons s2 x.
Proof. by rewrite -!cats1 catA. Qed.
Variant last_spec : seq T -> Type :=
| LastNil : last_spec [::]
| LastRcons s x : last_spec (rcons s x).
Lemma lastP s : last_spec s.
Proof. case: s => [|x s]; [left | rewrite lastI; right]. Qed.
Lemma last_ind P :
P [::] -> (forall s x, P s -> P (rcons s x)) -> forall s, P s.
Proof.
move=> Hnil Hlast s; rewrite -(cat0s s).
elim: s [::] Hnil => [|x s2 IHs] s1 Hs1; first by rewrite cats0.
by rewrite -cat_rcons; apply/IHs/Hlast.
Qed.
(* Sequence indexing. *)
Fixpoint nth s n {struct n} :=
if s is x :: s' then if n is n'.+1 then @nth s' n' else x else x0.
Fixpoint set_nth s n y {struct n} :=
if s is x :: s' then if n is n'.+1 then x :: @set_nth s' n' y else y :: s'
else ncons n x0 [:: y].
Lemma nth0 s : nth s 0 = head s. Proof. by []. Qed.
Lemma nth_default s n : size s <= n -> nth s n = x0.
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma if_nth s b n : b || (size s <= n) ->
(if b then nth s n else x0) = nth s n.
Proof. by case: leqP; case: ifP => //= *; rewrite nth_default. Qed.
Lemma nth_nil n : nth [::] n = x0.
Proof. by case: n. Qed.
Lemma nth_seq1 n x : nth [:: x] n = if n == 0 then x else x0.
Proof. by case: n => [|[]]. Qed.
Lemma last_nth x s : last x s = nth (x :: s) (size s).
Proof. by elim: s x => [|y s IHs] x /=. Qed.
Lemma nth_last s : nth s (size s).-1 = last x0 s.
Proof. by case: s => //= x s; rewrite last_nth. Qed.
Lemma nth_behead s n : nth (behead s) n = nth s n.+1.
Proof. by case: s n => [|x s] [|n]. Qed.
Lemma nth_cat s1 s2 n :
nth (s1 ++ s2) n = if n < size s1 then nth s1 n else nth s2 (n - size s1).
Proof. by elim: s1 n => [|x s1 IHs] []. Qed.
Lemma nth_rcons s x n :
nth (rcons s x) n =
if n < size s then nth s n else if n == size s then x else x0.
Proof. by elim: s n => [|y s IHs] [] //=; apply: nth_nil. Qed.
Lemma nth_rcons_default s i : nth (rcons s x0) i = nth s i.
Proof.
by rewrite nth_rcons; case: ltngtP => //[/ltnW ?|->]; rewrite nth_default.
Qed.
Lemma nth_ncons m x s n :
nth (ncons m x s) n = if n < m then x else nth s (n - m).
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma nth_nseq m x n : nth (nseq m x) n = (if n < m then x else x0).
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma eq_from_nth s1 s2 :
size s1 = size s2 -> (forall i, i < size s1 -> nth s1 i = nth s2 i) ->
s1 = s2.
Proof.
elim: s1 s2 => [|x1 s1 IHs1] [|x2 s2] //= [eq_sz] eq_s12.
by rewrite [x1](eq_s12 0) // (IHs1 s2) // => i; apply: (eq_s12 i.+1).
Qed.
Lemma size_set_nth s n y : size (set_nth s n y) = maxn n.+1 (size s).
Proof.
rewrite maxnC; elim: s n => [|x s IHs] [|n] //=.
- by rewrite size_ncons addn1.
- by rewrite IHs maxnSS.
Qed.
Lemma set_nth_nil n y : set_nth [::] n y = ncons n x0 [:: y].
Proof. by case: n. Qed.
Lemma nth_set_nth s n y : nth (set_nth s n y) =1 [eta nth s with n |-> y].
Proof.
elim: s n => [|x s IHs] [|n] [|m] //=; rewrite ?nth_nil ?IHs // nth_ncons eqSS.
case: ltngtP => // [lt_nm | ->]; last by rewrite subnn.
by rewrite nth_default // subn_gt0.
Qed.
Lemma set_set_nth s n1 y1 n2 y2 (s2 := set_nth s n2 y2) :
set_nth (set_nth s n1 y1) n2 y2 = if n1 == n2 then s2 else set_nth s2 n1 y1.
Proof.
have [-> | ne_n12] := eqVneq.
apply: eq_from_nth => [|i _]; first by rewrite !size_set_nth maxnA maxnn.
by do 2!rewrite !nth_set_nth /=; case: eqP.
apply: eq_from_nth => [|i _]; first by rewrite !size_set_nth maxnCA.
by do 2!rewrite !nth_set_nth /=; case: eqP => // ->; case: eqVneq ne_n12.
Qed.
(* find, count, has, all. *)
Section SeqFind.
Variable a : pred T.
Fixpoint find s := if s is x :: s' then if a x then 0 else (find s').+1 else 0.
Fixpoint filter s :=
if s is x :: s' then if a x then x :: filter s' else filter s' else [::].
Fixpoint count s := if s is x :: s' then a x + count s' else 0.
Fixpoint has s := if s is x :: s' then a x || has s' else false.
Fixpoint all s := if s is x :: s' then a x && all s' else true.
Lemma size_filter s : size (filter s) = count s.
Proof. by elim: s => //= x s <-; case (a x). Qed.
Lemma has_count s : has s = (0 < count s).
Proof. by elim: s => //= x s ->; case (a x). Qed.
Lemma size_filter_gt0 s : (size (filter s) > 0) = (has s).
Proof. by rewrite size_filter -has_count. Qed.
Lemma count_size s : count s <= size s.
Proof. by elim: s => //= x s; case: (a x); last apply: leqW. Qed.
Lemma all_count s : all s = (count s == size s).
Proof.
elim: s => //= x s; case: (a x) => _ //=.
by rewrite add0n eqn_leq andbC ltnNge count_size.
Qed.
Lemma filter_all s : all (filter s).
Proof. by elim: s => //= x s IHs; case: ifP => //= ->. Qed.
Lemma all_filterP s : reflect (filter s = s) (all s).
Proof.
apply: (iffP idP) => [| <-]; last exact: filter_all.
by elim: s => //= x s IHs /andP[-> Hs]; rewrite IHs.
Qed.
Lemma filter_id s : filter (filter s) = filter s.
Proof. by apply/all_filterP; apply: filter_all. Qed.
Lemma has_find s : has s = (find s < size s).
Proof. by elim: s => //= x s IHs; case (a x); rewrite ?leqnn. Qed.
Lemma find_size s : find s <= size s.
Proof. by elim: s => //= x s IHs; case (a x). Qed.
Lemma find_cat s1 s2 :
find (s1 ++ s2) = if has s1 then find s1 else size s1 + find s2.
Proof.
by elim: s1 => //= x s1 IHs; case: (a x) => //; rewrite IHs (fun_if succn).
Qed.
Lemma has_nil : has [::] = false. Proof. by []. Qed.
Lemma has_seq1 x : has [:: x] = a x.
Proof. exact: orbF. Qed.
Lemma has_nseq n x : has (nseq n x) = (0 < n) && a x.
Proof. by elim: n => //= n ->; apply: andKb. Qed.
Lemma has_seqb (b : bool) x : has (nseq b x) = b && a x.
Proof. by rewrite has_nseq lt0b. Qed.
Lemma all_nil : all [::] = true. Proof. by []. Qed.
Lemma all_seq1 x : all [:: x] = a x.
Proof. exact: andbT. Qed.
Lemma all_nseq n x : all (nseq n x) = (n == 0) || a x.
Proof. by elim: n => //= n ->; apply: orKb. Qed.
Lemma all_nseqb (b : bool) x : all (nseq b x) = b ==> a x.
Proof. by rewrite all_nseq eqb0 implybE. Qed.
Lemma filter_nseq n x : filter (nseq n x) = nseq (a x * n) x.
Proof. by elim: n => /= [|n ->]; case: (a x). Qed.
Lemma count_nseq n x : count (nseq n x) = a x * n.
Proof. by rewrite -size_filter filter_nseq size_nseq. Qed.
Lemma find_nseq n x : find (nseq n x) = ~~ a x * n.
Proof. by elim: n => /= [|n ->]; case: (a x). Qed.
Lemma nth_find s : has s -> a (nth s (find s)).
Proof. by elim: s => //= x s IHs; case a_x: (a x). Qed.
Lemma before_find s i : i < find s -> a (nth s i) = false.
Proof. by elim: s i => //= x s IHs; case: ifP => // a'x [|i] // /(IHs i). Qed.
Lemma hasNfind s : ~~ has s -> find s = size s.
Proof. by rewrite has_find; case: ltngtP (find_size s). Qed.
Lemma filter_cat s1 s2 : filter (s1 ++ s2) = filter s1 ++ filter s2.
Proof. by elim: s1 => //= x s1 ->; case (a x). Qed.
Lemma filter_rcons s x :
filter (rcons s x) = if a x then rcons (filter s) x else filter s.
Proof. by rewrite -!cats1 filter_cat /=; case (a x); rewrite /= ?cats0. Qed.
Lemma count_cat s1 s2 : count (s1 ++ s2) = count s1 + count s2.
Proof. by rewrite -!size_filter filter_cat size_cat. Qed.
Lemma has_cat s1 s2 : has (s1 ++ s2) = has s1 || has s2.
Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs orbA. Qed.
Lemma has_rcons s x : has (rcons s x) = a x || has s.
Proof. by rewrite -cats1 has_cat has_seq1 orbC. Qed.
Lemma all_cat s1 s2 : all (s1 ++ s2) = all s1 && all s2.
Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs andbA. Qed.
Lemma all_rcons s x : all (rcons s x) = a x && all s.
Proof. by rewrite -cats1 all_cat all_seq1 andbC. Qed.
End SeqFind.
Lemma find_pred0 s : find pred0 s = size s. Proof. by []. Qed.
Lemma find_predT s : find predT s = 0.
Proof. by case: s. Qed.
Lemma eq_find a1 a2 : a1 =1 a2 -> find a1 =1 find a2.
Proof. by move=> Ea; elim=> //= x s IHs; rewrite Ea IHs. Qed.
Lemma eq_filter a1 a2 : a1 =1 a2 -> filter a1 =1 filter a2.
Proof. by move=> Ea; elim=> //= x s IHs; rewrite Ea IHs. Qed.
Lemma eq_count a1 a2 : a1 =1 a2 -> count a1 =1 count a2.
Proof. by move=> Ea s; rewrite -!size_filter (eq_filter Ea). Qed.
Lemma eq_has a1 a2 : a1 =1 a2 -> has a1 =1 has a2.
Proof. by move=> Ea s; rewrite !has_count (eq_count Ea). Qed.
Lemma eq_all a1 a2 : a1 =1 a2 -> all a1 =1 all a2.
Proof. by move=> Ea s; rewrite !all_count (eq_count Ea). Qed.
Lemma all_filter (p q : pred T) xs :
all p (filter q xs) = all [pred i | q i ==> p i] xs.
Proof. by elim: xs => //= x xs <-; case: (q x). Qed.
Section SubPred.
Variable (a1 a2 : pred T).
Hypothesis s12 : subpred a1 a2.
Lemma sub_find s : find a2 s <= find a1 s.
Proof. by elim: s => //= x s IHs; case: ifP => // /(contraFF (@s12 x))->. Qed.
Lemma sub_has s : has a1 s -> has a2 s.
Proof. by rewrite !has_find; apply: leq_ltn_trans (sub_find s). Qed.
Lemma sub_count s : count a1 s <= count a2 s.
Proof.
by elim: s => //= x s; apply: leq_add; case a1x: (a1 x); rewrite // s12.
Qed.
Lemma sub_all s : all a1 s -> all a2 s.
Proof.
by rewrite !all_count !eqn_leq !count_size => /leq_trans-> //; apply: sub_count.
Qed.
End SubPred.
Lemma filter_pred0 s : filter pred0 s = [::]. Proof. by elim: s. Qed.
Lemma filter_predT s : filter predT s = s.
Proof. by elim: s => //= x s ->. Qed.
Lemma filter_predI a1 a2 s : filter (predI a1 a2) s = filter a1 (filter a2 s).
Proof. by elim: s => //= x s ->; rewrite andbC; case: (a2 x). Qed.
Lemma count_pred0 s : count pred0 s = 0.
Proof. by rewrite -size_filter filter_pred0. Qed.
Lemma count_predT s : count predT s = size s.
Proof. by rewrite -size_filter filter_predT. Qed.
Lemma count_predUI a1 a2 s :
count (predU a1 a2) s + count (predI a1 a2) s = count a1 s + count a2 s.
Proof.
elim: s => //= x s IHs; rewrite /= addnACA [RHS]addnACA IHs.
by case: (a1 x) => //; rewrite addn0.
Qed.
Lemma count_predC a s : count a s + count (predC a) s = size s.
Proof. by elim: s => //= x s IHs; rewrite addnACA IHs; case: (a _). Qed.
Lemma count_filter a1 a2 s : count a1 (filter a2 s) = count (predI a1 a2) s.
Proof. by rewrite -!size_filter filter_predI. Qed.
Lemma has_pred0 s : has pred0 s = false.
Proof. by rewrite has_count count_pred0. Qed.
Lemma has_predT s : has predT s = (0 < size s).
Proof. by rewrite has_count count_predT. Qed.
Lemma has_predC a s : has (predC a) s = ~~ all a s.
Proof. by elim: s => //= x s ->; case (a x). Qed.
Lemma has_predU a1 a2 s : has (predU a1 a2) s = has a1 s || has a2 s.
Proof. by elim: s => //= x s ->; rewrite -!orbA; do !bool_congr. Qed.
Lemma all_pred0 s : all pred0 s = (size s == 0).
Proof. by rewrite all_count count_pred0 eq_sym. Qed.
Lemma all_predT s : all predT s.
Proof. by rewrite all_count count_predT. Qed.
Lemma allT (a : pred T) s : (forall x, a x) -> all a s.
Proof. by move/eq_all->; apply/all_predT. Qed.
Lemma all_predC a s : all (predC a) s = ~~ has a s.
Proof. by elim: s => //= x s ->; case (a x). Qed.
Lemma all_predI a1 a2 s : all (predI a1 a2) s = all a1 s && all a2 s.
Proof.
apply: (can_inj negbK); rewrite negb_and -!has_predC -has_predU.
by apply: eq_has => x; rewrite /= negb_and.
Qed.
(* Surgery: drop, take, rot, rotr. *)
Fixpoint drop n s {struct s} :=
match s, n with
| _ :: s', n'.+1 => drop n' s'
| _, _ => s
end.
Lemma drop_behead : drop n0 =1 iter n0 behead.
Proof. by elim: n0 => [|n IHn] [|x s] //; rewrite iterSr -IHn. Qed.
Lemma drop0 s : drop 0 s = s. Proof. by case: s. Qed.
Lemma drop1 : drop 1 =1 behead. Proof. by case=> [|x [|y s]]. Qed.
Lemma drop_oversize n s : size s <= n -> drop n s = [::].
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma drop_size s : drop (size s) s = [::].
Proof. by rewrite drop_oversize // leqnn. Qed.
Lemma drop_cons x s :
drop n0 (x :: s) = if n0 is n.+1 then drop n s else x :: s.
Proof. by []. Qed.
Lemma size_drop s : size (drop n0 s) = size s - n0.
Proof. by elim: s n0 => [|x s IHs] []. Qed.
Lemma drop_cat s1 s2 :
drop n0 (s1 ++ s2) =
if n0 < size s1 then drop n0 s1 ++ s2 else drop (n0 - size s1) s2.
Proof. by elim: s1 n0 => [|x s1 IHs] []. Qed.
Lemma drop_size_cat n s1 s2 : size s1 = n -> drop n (s1 ++ s2) = s2.
Proof. by move <-; elim: s1 => //=; rewrite drop0. Qed.
Lemma nconsK n x : cancel (ncons n x) (drop n).
Proof. by elim: n => // -[]. Qed.
Lemma drop_drop s n1 n2 : drop n1 (drop n2 s) = drop (n1 + n2) s.
Proof. by elim: s n2 => // x s ihs [|n2]; rewrite ?drop0 ?addn0 ?addnS /=. Qed.
Fixpoint take n s {struct s} :=
match s, n with
| x :: s', n'.+1 => x :: take n' s'
| _, _ => [::]
end.
Lemma take0 s : take 0 s = [::]. Proof. by case: s. Qed.
Lemma take_oversize n s : size s <= n -> take n s = s.
Proof. by elim: s n => [|x s IHs] [|n] //= /IHs->. Qed.
Lemma take_size s : take (size s) s = s.
Proof. exact: take_oversize. Qed.
Lemma take_cons x s :
take n0 (x :: s) = if n0 is n.+1 then x :: (take n s) else [::].
Proof. by []. Qed.
Lemma drop_rcons s : n0 <= size s ->
forall x, drop n0 (rcons s x) = rcons (drop n0 s) x.
Proof. by elim: s n0 => [|y s IHs] []. Qed.
Lemma cat_take_drop s : take n0 s ++ drop n0 s = s.
Proof. by elim: s n0 => [|x s IHs] [|n] //=; rewrite IHs. Qed.
Lemma size_takel s : n0 <= size s -> size (take n0 s) = n0.
Proof.
by move/subKn; rewrite -size_drop -[in size s](cat_take_drop s) size_cat addnK.
Qed.
Lemma size_take s : size (take n0 s) = if n0 < size s then n0 else size s.
Proof.
have [le_sn | lt_ns] := leqP (size s) n0; first by rewrite take_oversize.
by rewrite size_takel // ltnW.
Qed.
Lemma size_take_min s : size (take n0 s) = minn n0 (size s).
Proof. exact: size_take. Qed.
Lemma take_cat s1 s2 :
take n0 (s1 ++ s2) =
if n0 < size s1 then take n0 s1 else s1 ++ take (n0 - size s1) s2.
Proof.
elim: s1 n0 => [|x s1 IHs] [|n] //=.
by rewrite ltnS subSS -(fun_if (cons x)) -IHs.
Qed.
Lemma take_size_cat n s1 s2 : size s1 = n -> take n (s1 ++ s2) = s1.
Proof. by move <-; elim: s1 => [|x s1 IHs]; rewrite ?take0 //= IHs. Qed.
Lemma takel_cat s1 s2 : n0 <= size s1 -> take n0 (s1 ++ s2) = take n0 s1.
Proof.
by rewrite take_cat; case: ltngtP => // ->; rewrite subnn take0 take_size cats0.
Qed.
Lemma nth_drop s i : nth (drop n0 s) i = nth s (n0 + i).
Proof.
rewrite -[s in RHS]cat_take_drop nth_cat size_take ltnNge.
case: ltnP => [?|le_s_n0]; rewrite ?(leq_trans le_s_n0) ?leq_addr ?addKn //=.
by rewrite drop_oversize // !nth_default.
Qed.
Lemma find_ltn p s i : has p (take i s) -> find p s < i.
Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs. Qed.
Lemma has_take p s i : has p s -> has p (take i s) = (find p s < i).
Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs ->. Qed.
Lemma has_take_leq (p : pred T) (s : seq T) i : i <= size s ->
has p (take i s) = (find p s < i).
Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs ->. Qed.
Lemma nth_take i : i < n0 -> forall s, nth (take n0 s) i = nth s i.
Proof.
move=> lt_i_n0 s; case lt_n0_s: (n0 < size s).
by rewrite -[s in RHS]cat_take_drop nth_cat size_take lt_n0_s /= lt_i_n0.
by rewrite -[s in LHS]cats0 take_cat lt_n0_s /= cats0.
Qed.
Lemma take_min i j s : take (minn i j) s = take i (take j s).
Proof. by elim: s i j => //= a l IH [|i] [|j] //=; rewrite minnSS IH. Qed.
Lemma take_takel i j s : i <= j -> take i (take j s) = take i s.
Proof. by move=> ?; rewrite -take_min (minn_idPl _). Qed.
Lemma take_taker i j s : j <= i -> take i (take j s) = take j s.
Proof. by move=> ?; rewrite -take_min (minn_idPr _). Qed.
Lemma take_drop i j s : take i (drop j s) = drop j (take (i + j) s).
Proof. by rewrite addnC; elim: s i j => // x s IHs [|i] [|j] /=. Qed.
Lemma takeD i j s : take (i + j) s = take i s ++ take j (drop i s).
Proof.
elim: i j s => [|i IHi] [|j] [|a s] //; first by rewrite take0 addn0 cats0.
by rewrite addSn /= IHi.
Qed.
Lemma takeC i j s : take i (take j s) = take j (take i s).
Proof. by rewrite -!take_min minnC. Qed.
Lemma take_nseq i j x : i <= j -> take i (nseq j x) = nseq i x.
Proof. by move=>/subnKC <-; rewrite nseqD take_size_cat // size_nseq. Qed.
Lemma drop_nseq i j x : drop i (nseq j x) = nseq (j - i) x.
Proof.
case: (leqP i j) => [/subnKC {1}<-|/ltnW j_le_i].
by rewrite nseqD drop_size_cat // size_nseq.
by rewrite drop_oversize ?size_nseq // (eqP j_le_i).
Qed.
(* drop_nth and take_nth below do NOT use the default n0, because the "n" *)
(* can be inferred from the condition, whereas the nth default value x0 *)
(* will have to be given explicitly (and this will provide "d" as well). *)
Lemma drop_nth n s : n < size s -> drop n s = nth s n :: drop n.+1 s.
Proof. by elim: s n => [|x s IHs] [|n] Hn //=; rewrite ?drop0 1?IHs. Qed.
Lemma take_nth n s : n < size s -> take n.+1 s = rcons (take n s) (nth s n).
Proof. by elim: s n => [|x s IHs] //= [|n] Hn /=; rewrite ?take0 -?IHs. Qed.
(* Rotation *)
Definition rot n s := drop n s ++ take n s.
Lemma rot0 s : rot 0 s = s.
Proof. by rewrite /rot drop0 take0 cats0. Qed.
Lemma size_rot s : size (rot n0 s) = size s.
Proof. by rewrite -[s in RHS]cat_take_drop /rot !size_cat addnC. Qed.
Lemma rot_oversize n s : size s <= n -> rot n s = s.
Proof. by move=> le_s_n; rewrite /rot take_oversize ?drop_oversize. Qed.
Lemma rot_size s : rot (size s) s = s.
Proof. exact: rot_oversize. Qed.
Lemma has_rot s a : has a (rot n0 s) = has a s.
Proof. by rewrite has_cat orbC -has_cat cat_take_drop. Qed.
Lemma rot_size_cat s1 s2 : rot (size s1) (s1 ++ s2) = s2 ++ s1.
Proof. by rewrite /rot take_size_cat ?drop_size_cat. Qed.
Definition rotr n s := rot (size s - n) s.
Lemma rotK : cancel (rot n0) (rotr n0).
Proof.
move=> s; rewrite /rotr size_rot -size_drop {2}/rot.
by rewrite rot_size_cat cat_take_drop.
Qed.
Lemma rot_inj : injective (rot n0). Proof. exact (can_inj rotK). Qed.
(* (efficient) reversal *)
Fixpoint catrev s1 s2 := if s1 is x :: s1' then catrev s1' (x :: s2) else s2.
Definition rev s := catrev s [::].
Lemma catrev_catl s t u : catrev (s ++ t) u = catrev t (catrev s u).
Proof. by elim: s u => /=. Qed.
Lemma catrev_catr s t u : catrev s (t ++ u) = catrev s t ++ u.
Proof. by elim: s t => //= x s IHs t; rewrite -IHs. Qed.
Lemma catrevE s t : catrev s t = rev s ++ t.
Proof. by rewrite -catrev_catr. Qed.
Lemma rev_cons x s : rev (x :: s) = rcons (rev s) x.
Proof. by rewrite -cats1 -catrevE. Qed.
Lemma size_rev s : size (rev s) = size s.
Proof. by elim: s => // x s IHs; rewrite rev_cons size_rcons IHs. Qed.
Lemma rev_nilp s : nilp (rev s) = nilp s.
Proof. by rewrite /nilp size_rev. Qed.
Lemma rev_cat s t : rev (s ++ t) = rev t ++ rev s.
Proof. by rewrite -catrev_catr -catrev_catl. Qed.
Lemma rev_rcons s x : rev (rcons s x) = x :: rev s.
Proof. by rewrite -cats1 rev_cat. Qed.
Lemma revK : involutive rev.
Proof. by elim=> //= x s IHs; rewrite rev_cons rev_rcons IHs. Qed.
Lemma nth_rev n s : n < size s -> nth (rev s) n = nth s (size s - n.+1).
Proof.
elim/last_ind: s => // s x IHs in n *.
rewrite rev_rcons size_rcons ltnS subSS -cats1 nth_cat /=.
case: n => [|n] lt_n_s; first by rewrite subn0 ltnn subnn.
by rewrite subnSK //= leq_subr IHs.
Qed.
Lemma filter_rev a s : filter a (rev s) = rev (filter a s).
Proof. by elim: s => //= x s IH; rewrite fun_if !rev_cons filter_rcons IH. Qed.
Lemma count_rev a s : count a (rev s) = count a s.
Proof. by rewrite -!size_filter filter_rev size_rev. Qed.
Lemma has_rev a s : has a (rev s) = has a s.
Proof. by rewrite !has_count count_rev. Qed.
Lemma all_rev a s : all a (rev s) = all a s.
Proof. by rewrite !all_count count_rev size_rev. Qed.
Lemma rev_nseq n x : rev (nseq n x) = nseq n x.
Proof. by elim: n => // n IHn; rewrite -[in LHS]addn1 nseqD rev_cat IHn. Qed.
End Sequences.
Prenex Implicits size ncons nseq head ohead behead last rcons belast.
Arguments seqn {T} n.
Prenex Implicits cat take drop rot rotr catrev.
Prenex Implicits find count nth all has filter.
Arguments rev {T} s : simpl never.
Arguments nth : simpl nomatch.
Arguments set_nth : simpl nomatch.
Arguments take : simpl nomatch.
Arguments drop : simpl nomatch.
Arguments nilP {T s}.
Arguments all_filterP {T a s}.
Arguments rotK n0 {T} s : rename.
Arguments rot_inj {n0 T} [s1 s2] eq_rot_s12 : rename.
Arguments revK {T} s : rename.
Notation count_mem x := (count (pred_of_simpl (pred1 x))).
Infix "++" := cat : seq_scope.
Notation "[ 'seq' x <- s | C ]" := (filter (fun x => C%B) s)
(x at level 99,
format "[ '[hv' 'seq' x <- s '/ ' | C ] ']'") : seq_scope.
Notation "[ 'seq' x <- s | C1 & C2 ]" := [seq x <- s | C1 && C2]
(format "[ '[hv' 'seq' x <- s '/ ' | C1 '/ ' & C2 ] ']'") : seq_scope.
Notation "[ 'seq' ' x <- s | C ]" := (filter (fun x => C%B) s)
(x strict pattern,
format "[ '[hv' 'seq' ' x <- s '/ ' | C ] ']'") : seq_scope.
Notation "[ 'seq' ' x <- s | C1 & C2 ]" := [seq x <- s | C1 && C2]
(x strict pattern,
format "[ '[hv' 'seq' ' x <- s '/ ' | C1 '/ ' & C2 ] ']'") : seq_scope.
Notation "[ 'seq' x : T <- s | C ]" := (filter (fun x : T => C%B) s)
(only parsing).
Notation "[ 'seq' x : T <- s | C1 & C2 ]" := [seq x : T <- s | C1 && C2]
(only parsing).
(* Double induction/recursion. *)
Lemma seq_ind2 {S T} (P : seq S -> seq T -> Type) :
P [::] [::] ->
(forall x y s t, size s = size t -> P s t -> P (x :: s) (y :: t)) ->
forall s t, size s = size t -> P s t.
Proof.
by move=> Pnil Pcons; elim=> [|x s IHs] [|y t] //= [eq_sz]; apply/Pcons/IHs.
Qed.
Section AllIff.
(* The Following Are Equivalent *)
(* We introduce a specific conjunction, used to chain the consecutive *)
(* items in a circular list of implications *)
Inductive all_iff_and (P Q : Prop) : Prop := AllIffConj of P & Q.
Definition all_iff (P0 : Prop) (Ps : seq Prop) : Prop :=
let fix loop (P : Prop) (Qs : seq Prop) : Prop :=
if Qs is Q :: Qs then all_iff_and (P -> Q) (loop Q Qs) else P -> P0 in
loop P0 Ps.
Lemma all_iffLR P0 Ps : all_iff P0 Ps ->
forall m n, nth P0 (P0 :: Ps) m -> nth P0 (P0 :: Ps) n.
Proof.
move=> iffPs; have PsS n: nth P0 Ps n -> nth P0 Ps n.+1.
elim: n P0 Ps iffPs => [|n IHn] P0 [|P [|Q Ps]] //= [iP0P] //; first by case.
by rewrite nth_nil.
by case=> iPQ iffPs; apply: IHn; split=> // /iP0P.
have{PsS} lePs: {homo nth P0 Ps : m n / m <= n >-> (m -> n)}.
by move=> m n /subnK<-; elim: {n}(n - m) => // n IHn /IHn; apply: PsS.
move=> m n P_m; have{m P_m} hP0: P0.
case: m P_m => //= m /(lePs m _ (leq_maxl m (size Ps))).
by rewrite nth_default ?leq_maxr.
case: n =>// n; apply: lePs 0 n (leq0n n) _.
by case: Ps iffPs hP0 => // P Ps [].
Qed.
Lemma all_iffP P0 Ps :
all_iff P0 Ps -> forall m n, nth P0 (P0 :: Ps) m <-> nth P0 (P0 :: Ps) n.
Proof. by move=> /all_iffLR-iffPs m n; split => /iffPs. Qed.
End AllIff.
Arguments all_iffLR {P0 Ps}.
Arguments all_iffP {P0 Ps}.
Coercion all_iffP : all_iff >-> Funclass.
(* This means "the following are all equivalent: P0, ... Pn" *)
Notation "[ '<->' P0 ; P1 ; .. ; Pn ]" :=
(all_iff P0 (@cons Prop P1 (.. (@cons Prop Pn nil) ..))) : form_scope.
Ltac tfae := do !apply: AllIffConj.
Section FindSpec.
Variable (T : Type) (a : {pred T}) (s : seq T).
Variant find_spec : bool -> nat -> Type :=
| NotFound of ~~ has a s : find_spec false (size s)
| Found (i : nat) of i < size s & (forall x0, a (nth x0 s i)) &
(forall x0 j, j < i -> a (nth x0 s j) = false) : find_spec true i.
Lemma findP : find_spec (has a s) (find a s).
Proof.
have [a_s|aNs] := boolP (has a s); last by rewrite hasNfind//; constructor.
by constructor=> [|x0|x0]; rewrite -?has_find ?nth_find//; apply: before_find.
Qed.
End FindSpec.
Arguments findP {T}.
Section RotRcons.
Variable T : Type.
Implicit Types (x : T) (s : seq T).
Lemma rot1_cons x s : rot 1 (x :: s) = rcons s x.
Proof. by rewrite /rot /= take0 drop0 -cats1. Qed.
Lemma rcons_inj s1 s2 x1 x2 :
rcons s1 x1 = rcons s2 x2 :> seq T -> (s1, x1) = (s2, x2).
Proof. by rewrite -!rot1_cons => /rot_inj[-> ->]. Qed.
Lemma rcons_injl x : injective (rcons^~ x).
Proof. by move=> s1 s2 /rcons_inj[]. Qed.
Lemma rcons_injr s : injective (rcons s).
Proof. by move=> x1 x2 /rcons_inj[]. Qed.
End RotRcons.
Arguments rcons_inj {T s1 x1 s2 x2} eq_rcons : rename.
Arguments rcons_injl {T} x [s1 s2] eq_rcons : rename.
Arguments rcons_injr {T} s [x1 x2] eq_rcons : rename.
(* Equality and eqType for seq. *)
Section EqSeq.
Variables (n0 : nat) (T : eqType) (x0 : T).
Local Notation nth := (nth x0).
Implicit Types (x y z : T) (s : seq T).
Fixpoint eqseq s1 s2 {struct s2} :=
match s1, s2 with
| [::], [::] => true
| x1 :: s1', x2 :: s2' => (x1 == x2) && eqseq s1' s2'
| _, _ => false
end.
Lemma eqseqP : Equality.axiom eqseq.
Proof.
move; elim=> [|x1 s1 IHs] [|x2 s2]; do [by constructor | simpl].
have [<-|neqx] := x1 =P x2; last by right; case.
by apply: (iffP (IHs s2)) => [<-|[]].
Qed.
HB.instance Definition _ := hasDecEq.Build (seq T) eqseqP.
Lemma eqseqE : eqseq = eq_op. Proof. by []. Qed.
Lemma eqseq_cons x1 x2 s1 s2 :
(x1 :: s1 == x2 :: s2) = (x1 == x2) && (s1 == s2).
Proof. by []. Qed.
Lemma eqseq_cat s1 s2 s3 s4 :
size s1 = size s2 -> (s1 ++ s3 == s2 ++ s4) = (s1 == s2) && (s3 == s4).
Proof.
elim: s1 s2 => [|x1 s1 IHs] [|x2 s2] //= [sz12].
by rewrite !eqseq_cons -andbA IHs.
Qed.
Lemma eqseq_rcons s1 s2 x1 x2 :
(rcons s1 x1 == rcons s2 x2) = (s1 == s2) && (x1 == x2).
Proof. by rewrite -(can_eq revK) !rev_rcons eqseq_cons andbC (can_eq revK). Qed.
Lemma size_eq0 s : (size s == 0) = (s == [::]).
Proof. exact: (sameP nilP eqP). Qed.
Lemma nilpE s : nilp s = (s == [::]). Proof. by case: s. Qed.
Lemma has_filter a s : has a s = (filter a s != [::]).
Proof. by rewrite -size_eq0 size_filter has_count lt0n. Qed.
(* mem_seq and index. *)
(* mem_seq defines a predType for seq. *)
Fixpoint mem_seq (s : seq T) :=
if s is y :: s' then xpredU1 y (mem_seq s') else xpred0.
Definition seq_eqclass := seq T.
Identity Coercion seq_of_eqclass : seq_eqclass >-> seq.
Coercion pred_of_seq (s : seq_eqclass) : {pred T} := mem_seq s.
Canonical seq_predType := PredType (pred_of_seq : seq T -> pred T).
(* The line below makes mem_seq a canonical instance of topred. *)
Canonical mem_seq_predType := PredType mem_seq.
Lemma in_cons y s x : (x \in y :: s) = (x == y) || (x \in s).
Proof. by []. Qed.
Lemma in_nil x : (x \in [::]) = false.
Proof. by []. Qed.
Lemma mem_seq1 x y : (x \in [:: y]) = (x == y).
Proof. by rewrite in_cons orbF. Qed.
(* to be repeated after the Section discharge. *)
Let inE := (mem_seq1, in_cons, inE).
Lemma forall_cons {P : T -> Prop} {a s} :
{in a::s, forall x, P x} <-> P a /\ {in s, forall x, P x}.
Proof.
split=> [A|[A B]]; last by move => x /predU1P [-> //|]; apply: B.
by split=> [|b Hb]; apply: A; rewrite !inE ?eqxx ?Hb ?orbT.
Qed.
Lemma exists_cons {P : T -> Prop} {a s} :
(exists2 x, x \in a::s & P x) <-> P a \/ exists2 x, x \in s & P x.
Proof.
split=> [[x /predU1P[->|x_s] Px]|]; [by left| by right; exists x|].
by move=> [?|[x x_s ?]]; [exists a|exists x]; rewrite ?inE ?eqxx ?x_s ?orbT.
Qed.
Lemma mem_seq2 x y z : (x \in [:: y; z]) = xpred2 y z x.
Proof. by rewrite !inE. Qed.
Lemma mem_seq3 x y z t : (x \in [:: y; z; t]) = xpred3 y z t x.
Proof. by rewrite !inE. Qed.
Lemma mem_seq4 x y z t u : (x \in [:: y; z; t; u]) = xpred4 y z t u x.
Proof. by rewrite !inE. Qed.
Lemma mem_cat x s1 s2 : (x \in s1 ++ s2) = (x \in s1) || (x \in s2).
Proof. by elim: s1 => //= y s1 IHs; rewrite !inE /= -orbA -IHs. Qed.
Lemma mem_rcons s y : rcons s y =i y :: s.
Proof. by move=> x; rewrite -cats1 /= mem_cat mem_seq1 orbC in_cons. Qed.
Lemma mem_head x s : x \in x :: s.
Proof. exact: predU1l. Qed.
Lemma mem_last x s : last x s \in x :: s.
Proof. by rewrite lastI mem_rcons mem_head. Qed.
Lemma mem_behead s : {subset behead s <= s}.
Proof. by case: s => // y s x; apply: predU1r. Qed.
Lemma mem_belast s y : {subset belast y s <= y :: s}.
Proof. by move=> x ys'x; rewrite lastI mem_rcons mem_behead. Qed.
Lemma mem_nth s n : n < size s -> nth s n \in s.
Proof.
by elim: s n => // x s IHs [_|n sz_s]; rewrite ?mem_head // mem_behead ?IHs.
Qed.
Lemma mem_take s x : x \in take n0 s -> x \in s.
Proof. by move=> s0x; rewrite -(cat_take_drop n0 s) mem_cat /= s0x. Qed.
Lemma mem_drop s x : x \in drop n0 s -> x \in s.
Proof. by move=> s0'x; rewrite -(cat_take_drop n0 s) mem_cat /= s0'x orbT. Qed.
Lemma last_eq s z x y : x != y -> z != y -> (last x s == y) = (last z s == y).
Proof. by move=> /negPf xz /negPf yz; case: s => [|t s]//; rewrite xz yz. Qed.
Section Filters.
Implicit Type a : pred T.
Lemma hasP {a s} : reflect (exists2 x, x \in s & a x) (has a s).
Proof.
elim: s => [|y s IHs] /=; first by right; case.
exact: equivP (orPP idP IHs) (iff_sym exists_cons).
Qed.
Lemma allP {a s} : reflect {in s, forall x, a x} (all a s).
Proof.
elim: s => [|/= y s IHs]; first by left.
exact: equivP (andPP idP IHs) (iff_sym forall_cons).
Qed.
Lemma hasPn a s : reflect {in s, forall x, ~~ a x} (~~ has a s).
Proof. by rewrite -all_predC; apply: allP. Qed.
Lemma allPn a s : reflect (exists2 x, x \in s & ~~ a x) (~~ all a s).
Proof. by rewrite -has_predC; apply: hasP. Qed.
Lemma allss s : all [in s] s. Proof. exact/allP. Qed.
Lemma mem_filter a x s : (x \in filter a s) = a x && (x \in s).
Proof.
rewrite andbC; elim: s => //= y s IHs.
rewrite (fun_if (fun s' : seq T => x \in s')) !in_cons {}IHs.
by case: eqP => [->|_]; case (a y); rewrite /= ?andbF.
Qed.
Variables (a : pred T) (s : seq T) (A : T -> Prop).
Hypothesis aP : forall x, reflect (A x) (a x).
Lemma hasPP : reflect (exists2 x, x \in s & A x) (has a s).
Proof. by apply: (iffP hasP) => -[x ? /aP]; exists x. Qed.
Lemma allPP : reflect {in s, forall x, A x} (all a s).
Proof. by apply: (iffP allP) => a_s x /a_s/aP. Qed.
End Filters.
Section EqIn.
Variables a1 a2 : pred T.
Lemma eq_in_filter s : {in s, a1 =1 a2} -> filter a1 s = filter a2 s.
Proof. by elim: s => //= x s IHs /forall_cons [-> /IHs ->]. Qed.
Lemma eq_in_find s : {in s, a1 =1 a2} -> find a1 s = find a2 s.
Proof. by elim: s => //= x s IHs /forall_cons [-> /IHs ->]. Qed.
Lemma eq_in_count s : {in s, a1 =1 a2} -> count a1 s = count a2 s.
Proof. by move/eq_in_filter=> eq_a12; rewrite -!size_filter eq_a12. Qed.
Lemma eq_in_all s : {in s, a1 =1 a2} -> all a1 s = all a2 s.
Proof. by move=> eq_a12; rewrite !all_count eq_in_count. Qed.
Lemma eq_in_has s : {in s, a1 =1 a2} -> has a1 s = has a2 s.
Proof. by move/eq_in_filter=> eq_a12; rewrite !has_filter eq_a12. Qed.
End EqIn.
Lemma eq_has_r s1 s2 : s1 =i s2 -> has^~ s1 =1 has^~ s2.
Proof.
by move=> Es a; apply/hasP/hasP=> -[x sx ax]; exists x; rewrite ?Es in sx *.
Qed.
Lemma eq_all_r s1 s2 : s1 =i s2 -> all^~ s1 =1 all^~ s2.
Proof. by move=> Es a; apply/negb_inj; rewrite -!has_predC (eq_has_r Es). Qed.
Lemma has_sym s1 s2 : has [in s1] s2 = has [in s2] s1.
Proof. by apply/hasP/hasP=> -[x]; exists x. Qed.
Lemma has_pred1 x s : has (pred1 x) s = (x \in s).
Proof. by rewrite -(eq_has (mem_seq1^~ x)) (has_sym [:: x]) /= orbF. Qed.
Lemma mem_rev s : rev s =i s.
Proof. by move=> a; rewrite -!has_pred1 has_rev. Qed.
(* Constant sequences, i.e., the image of nseq. *)
Definition constant s := if s is x :: s' then all (pred1 x) s' else true.
Lemma all_pred1P x s : reflect (s = nseq (size s) x) (all (pred1 x) s).
Proof.
elim: s => [|y s IHs] /=; first by left.
case: eqP => [->{y} | ne_xy]; last by right=> [] [? _]; case ne_xy.
by apply: (iffP IHs) => [<- //| []].
Qed.
Lemma all_pred1_constant x s : all (pred1 x) s -> constant s.
Proof. by case: s => //= y s /andP[/eqP->]. Qed.
Lemma all_pred1_nseq x n : all (pred1 x) (nseq n x).
Proof. by rewrite all_nseq /= eqxx orbT. Qed.
Lemma mem_nseq n x y : (y \in nseq n x) = (0 < n) && (y == x).
Proof. by rewrite -has_pred1 has_nseq eq_sym. Qed.
Lemma nseqP n x y : reflect (y = x /\ n > 0) (y \in nseq n x).
Proof. by rewrite mem_nseq andbC; apply: (iffP andP) => -[/eqP]. Qed.
Lemma constant_nseq n x : constant (nseq n x).
Proof. exact: all_pred1_constant (all_pred1_nseq x n). Qed.
(* Uses x0 *)
Lemma constantP s : reflect (exists x, s = nseq (size s) x) (constant s).
Proof.
apply: (iffP idP) => [| [x ->]]; last exact: constant_nseq.
case: s => [|x s] /=; first by exists x0.
by move/all_pred1P=> def_s; exists x; rewrite -def_s.
Qed.
(* Duplicate-freenes. *)
Fixpoint uniq s := if s is x :: s' then (x \notin s') && uniq s' else true.
Lemma cons_uniq x s : uniq (x :: s) = (x \notin s) && uniq s.
Proof. by []. Qed.
Lemma cat_uniq s1 s2 :
uniq (s1 ++ s2) = [&& uniq s1, ~~ has [in s1] s2 & uniq s2].
Proof.
elim: s1 => [|x s1 IHs]; first by rewrite /= has_pred0.
by rewrite has_sym /= mem_cat !negb_or has_sym IHs -!andbA; do !bool_congr.
Qed.
Lemma uniq_catC s1 s2 : uniq (s1 ++ s2) = uniq (s2 ++ s1).
Proof. by rewrite !cat_uniq has_sym andbCA andbA andbC. Qed.
Lemma uniq_catCA s1 s2 s3 : uniq (s1 ++ s2 ++ s3) = uniq (s2 ++ s1 ++ s3).
Proof.
by rewrite !catA -!(uniq_catC s3) !(cat_uniq s3) uniq_catC !has_cat orbC.
Qed.
Lemma rcons_uniq s x : uniq (rcons s x) = (x \notin s) && uniq s.
Proof. by rewrite -cats1 uniq_catC. Qed.
Lemma filter_uniq s a : uniq s -> uniq (filter a s).
Proof.
elim: s => //= x s IHs /andP[s'x]; case: ifP => //= a_x /IHs->.
by rewrite mem_filter a_x s'x.
Qed.
Lemma rot_uniq s : uniq (rot n0 s) = uniq s.
Proof. by rewrite /rot uniq_catC cat_take_drop. Qed.
Lemma rev_uniq s : uniq (rev s) = uniq s.
Proof.
elim: s => // x s IHs.
by rewrite rev_cons -cats1 cat_uniq /= andbT andbC mem_rev orbF IHs.
Qed.
Lemma count_memPn x s : reflect (count_mem x s = 0) (x \notin s).
Proof. by rewrite -has_pred1 has_count -eqn0Ngt; apply: eqP. Qed.
Lemma count_uniq_mem s x : uniq s -> count_mem x s = (x \in s).
Proof.
elim: s => //= y s IHs /andP[/negbTE s'y /IHs-> {IHs}].
by rewrite in_cons; case: (eqVneq y x) => // <-; rewrite s'y.
Qed.
Lemma leq_uniq_countP x s1 s2 : uniq s1 ->
reflect (x \in s1 -> x \in s2) (count_mem x s1 <= count_mem x s2).
Proof.
move/count_uniq_mem->; case: (boolP (_ \in _)) => //= _; last by constructor.
by rewrite -has_pred1 has_count; apply: (iffP idP) => //; apply.
Qed.
Lemma leq_uniq_count s1 s2 : uniq s1 -> {subset s1 <= s2} ->
(forall x, count_mem x s1 <= count_mem x s2).
Proof. by move=> s1_uniq s1_s2 x; apply/leq_uniq_countP/s1_s2. Qed.
Lemma filter_pred1_uniq s x : uniq s -> x \in s -> filter (pred1 x) s = [:: x].
Proof.
move=> uniq_s s_x; rewrite (all_pred1P _ _ (filter_all _ _)).
by rewrite size_filter count_uniq_mem ?s_x.
Qed.
(* Removing duplicates *)
Fixpoint undup s :=
if s is x :: s' then if x \in s' then undup s' else x :: undup s' else [::].
Lemma size_undup s : size (undup s) <= size s.
Proof. by elim: s => //= x s IHs; case: (x \in s) => //=; apply: ltnW. Qed.
Lemma mem_undup s : undup s =i s.
Proof.
move=> x; elim: s => //= y s IHs.
by case s_y: (y \in s); rewrite !inE IHs //; case: eqP => [->|].
Qed.
Lemma undup_uniq s : uniq (undup s).
Proof.
by elim: s => //= x s IHs; case s_x: (x \in s); rewrite //= mem_undup s_x.
Qed.
Lemma undup_id s : uniq s -> undup s = s.
Proof. by elim: s => //= x s IHs /andP[/negbTE-> /IHs->]. Qed.
Lemma ltn_size_undup s : (size (undup s) < size s) = ~~ uniq s.
Proof.
by elim: s => //= x s IHs; case s_x: (x \in s); rewrite //= ltnS size_undup.
Qed.
Lemma filter_undup p s : filter p (undup s) = undup (filter p s).
Proof.
elim: s => //= x s IHs; rewrite (fun_if undup) [_ = _]fun_if /= mem_filter /=.
by rewrite (fun_if (filter p)) /= IHs; case: ifP => -> //=; apply: if_same.
Qed.
Lemma undup_nil s : undup s = [::] -> s = [::].
Proof. by case: s => //= x s; rewrite -mem_undup; case: ifP; case: undup. Qed.
Lemma undup_cat s t :
undup (s ++ t) = [seq x <- undup s | x \notin t] ++ undup t.
Proof. by elim: s => //= x s ->; rewrite mem_cat; do 2 case: in_mem => //=. Qed.
Lemma undup_rcons s x : undup (rcons s x) = rcons [seq y <- undup s | y != x] x.
Proof.
by rewrite -!cats1 undup_cat; congr cat; apply: eq_filter => y; rewrite inE.
Qed.
Lemma count_undup s p : count p (undup s) <= count p s.
Proof. by rewrite -!size_filter filter_undup size_undup. Qed.
Lemma has_undup p s : has p (undup s) = has p s.
Proof. by apply: eq_has_r => x; rewrite mem_undup. Qed.
Lemma all_undup p s : all p (undup s) = all p s.
Proof. by apply: eq_all_r => x; rewrite mem_undup. Qed.
(* Lookup *)
Definition index x := find (pred1 x).
Lemma index_size x s : index x s <= size s.
Proof. by rewrite /index find_size. Qed.
Lemma index_mem x s : (index x s < size s) = (x \in s).
Proof. by rewrite -has_pred1 has_find. Qed.
Lemma memNindex x s : x \notin s -> index x s = size s.
Proof. by rewrite -has_pred1 => /hasNfind. Qed.
Lemma nth_index x s : x \in s -> nth s (index x s) = x.
Proof. by rewrite -has_pred1 => /(nth_find x0)/eqP. Qed.
Lemma index_inj s : {in s &, injective (index ^~ s)}.
Proof.
by move=> x y x_s y_s eidx; rewrite -(nth_index x_s) eidx nth_index.
Qed.
Lemma index_cat x s1 s2 :
index x (s1 ++ s2) = if x \in s1 then index x s1 else size s1 + index x s2.
Proof. by rewrite /index find_cat has_pred1. Qed.
Lemma index_ltn x s i : x \in take i s -> index x s < i.
Proof. by rewrite -has_pred1; apply: find_ltn. Qed.
Lemma in_take x s i : x \in s -> (x \in take i s) = (index x s < i).
Proof. by rewrite -?has_pred1; apply: has_take. Qed.
Lemma in_take_leq x s i : i <= size s -> (x \in take i s) = (index x s < i).
Proof. by rewrite -?has_pred1; apply: has_take_leq. Qed.
Lemma index_nth i s : i < size s -> index (nth s i) s <= i.
Proof.
move=> lti; rewrite -ltnS index_ltn// -(@nth_take i.+1)// mem_nth // size_take.
by case: ifP.
Qed.
Lemma nthK s: uniq s -> {in gtn (size s), cancel (nth s) (index^~ s)}.
Proof.
elim: s => //= x s IHs /andP[s'x Us] i; rewrite inE ltnS eq_sym -if_neg.
by case: i => /= [_|i lt_i_s]; rewrite ?eqxx ?IHs ?(memPn s'x) ?mem_nth.
Qed.
Lemma index_uniq i s : i < size s -> uniq s -> index (nth s i) s = i.
Proof. by move/nthK. Qed.
Lemma index_head x s : index x (x :: s) = 0.
Proof. by rewrite /= eqxx. Qed.
Lemma index_last x s : uniq (x :: s) -> index (last x s) (x :: s) = size s.
Proof.
rewrite lastI rcons_uniq -cats1 index_cat size_belast.
by case: ifP => //=; rewrite eqxx addn0.
Qed.
Lemma nth_uniq s i j :
i < size s -> j < size s -> uniq s -> (nth s i == nth s j) = (i == j).
Proof. by move=> lti ltj /nthK/can_in_eq->. Qed.
Lemma uniqPn s :
reflect (exists i j, [/\ i < j, j < size s & nth s i = nth s j]) (~~ uniq s).
Proof.
apply: (iffP idP) => [|[i [j [ltij ltjs]]]]; last first.
by apply: contra_eqN => Us; rewrite nth_uniq ?ltn_eqF // (ltn_trans ltij).
elim: s => // x s IHs /nandP[/negbNE | /IHs[i [j]]]; last by exists i.+1, j.+1.
by exists 0, (index x s).+1; rewrite !ltnS index_mem /= nth_index.
Qed.
Lemma uniqP s : reflect {in gtn (size s) &, injective (nth s)} (uniq s).
Proof.
apply: (iffP idP) => [/nthK/can_in_inj// | nth_inj].
apply/uniqPn => -[i [j [ltij ltjs /nth_inj/eqP/idPn]]].
by rewrite !inE (ltn_trans ltij ltjs) ltn_eqF //=; case.
Qed.
Lemma mem_rot s : rot n0 s =i s.
Proof. by move=> x; rewrite -[s in RHS](cat_take_drop n0) !mem_cat /= orbC. Qed.
Lemma eqseq_rot s1 s2 : (rot n0 s1 == rot n0 s2) = (s1 == s2).
Proof. exact/inj_eq/rot_inj. Qed.
Lemma drop_index s (n := index x0 s) : x0 \in s -> drop n s = x0 :: drop n.+1 s.
Proof. by move=> xs; rewrite (drop_nth x0) ?index_mem ?nth_index. Qed.
(* lemmas about the pivot pattern [_ ++ _ :: _] *)
Lemma index_pivot x s1 s2 (s := s1 ++ x :: s2) : x \notin s1 ->
index x s = size s1.
Proof. by rewrite index_cat/= eqxx addn0; case: ifPn. Qed.
Lemma take_pivot x s2 s1 (s := s1 ++ x :: s2) : x \notin s1 ->
take (index x s) s = s1.
Proof. by move=> /index_pivot->; rewrite take_size_cat. Qed.
Lemma rev_pivot x s1 s2 : rev (s1 ++ x :: s2) = rev s2 ++ x :: rev s1.
Proof. by rewrite rev_cat rev_cons cat_rcons. Qed.
Lemma eqseq_pivot2l x s1 s2 s3 s4 : x \notin s1 -> x \notin s3 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
move=> xNs1 xNs3; apply/idP/idP => [E|/andP[/eqP-> /eqP->]//].
suff S : size s1 = size s3 by rewrite eqseq_cat// eqseq_cons eqxx in E.
by rewrite -(index_pivot s2 xNs1) (eqP E) index_pivot.
Qed.
Lemma eqseq_pivot2r x s1 s2 s3 s4 : x \notin s2 -> x \notin s4 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
move=> xNs2 xNs4; rewrite -(can_eq revK) !rev_pivot.
by rewrite eqseq_pivot2l ?mem_rev // !(can_eq revK) andbC.
Qed.
Lemma eqseq_pivotl x s1 s2 s3 s4 : x \notin s1 -> x \notin s2 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
move=> xNs1 xNs2; apply/idP/idP => [E|/andP[/eqP-> /eqP->]//].
rewrite -(@eqseq_pivot2l x)//; have /eqP/(congr1 (count_mem x)) := E.
rewrite !count_cat/= eqxx !addnS (count_memPn _ _ xNs1) (count_memPn _ _ xNs2).
by move=> -[/esym/eqP]; rewrite addn_eq0 => /andP[/eqP/count_memPn].
Qed.
Lemma eqseq_pivotr x s1 s2 s3 s4 : x \notin s3 -> x \notin s4 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof. by move=> *; rewrite eq_sym eqseq_pivotl//; case: eqVneq => /=. Qed.
Lemma uniq_eqseq_pivotl x s1 s2 s3 s4 : uniq (s1 ++ x :: s2) ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
by rewrite uniq_catC/= mem_cat => /andP[/norP[? ?] _]; rewrite eqseq_pivotl.
Qed.
Lemma uniq_eqseq_pivotr x s1 s2 s3 s4 : uniq (s3 ++ x :: s4) ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof. by move=> ?; rewrite eq_sym uniq_eqseq_pivotl//; case: eqVneq => /=. Qed.
End EqSeq.
Arguments eqseq : simpl nomatch.
Notation "'has_ view" := (hasPP _ (fun _ => view))
(at level 4, right associativity, format "''has_' view").
Notation "'all_ view" := (allPP _ (fun _ => view))
(at level 4, right associativity, format "''all_' view").
Section RotIndex.
Variables (T : eqType).
Implicit Types x y z : T.
Lemma rot_index s x (i := index x s) : x \in s ->
rot i s = x :: (drop i.+1 s ++ take i s).
Proof. by move=> x_s; rewrite /rot drop_index. Qed.
Variant rot_to_spec s x := RotToSpec i s' of rot i s = x :: s'.
Lemma rot_to s x : x \in s -> rot_to_spec s x.
Proof. by move=> /rot_index /RotToSpec. Qed.
End RotIndex.
Definition inE := (mem_seq1, in_cons, inE).
Prenex Implicits mem_seq1 constant uniq undup index.
Arguments eqseq {T} !_ !_.
Arguments pred_of_seq {T} s x /.
Arguments eqseqP {T x y}.
Arguments hasP {T a s}.
Arguments hasPn {T a s}.
Arguments allP {T a s}.
Arguments allPn {T a s}.
Arguments nseqP {T n x y}.
Arguments count_memPn {T x s}.
Arguments uniqPn {T} x0 {s}.
Arguments uniqP {T} x0 {s}.
Arguments forall_cons {T P a s}.
Arguments exists_cons {T P a s}.
(* Since both `all [in s] s`, `all (mem s) s`, and `all (pred_of_seq s) s` *)
(* may appear in goals, the following hint has to be declared using the *)
(* `Hint Extern` command. Additionally, `mem` and `pred_of_seq` in the above *)
(* terms do not reduce to each other; thus, stating `allss` in the form of *)
(* one of them makes `apply: allss` fail for the other case. Since both `mem` *)
(* and `pred_of_seq` reduce to `mem_seq`, the following explicit type *)
(* annotation for `allss` makes it work for both cases. *)
#[export] Hint Extern 0 (is_true (all _ _)) =>
apply: (allss : forall T s, all (mem_seq s) s) : core.
Section NthTheory.
Lemma nthP (T : eqType) (s : seq T) x x0 :
reflect (exists2 i, i < size s & nth x0 s i = x) (x \in s).
Proof.
apply: (iffP idP) => [|[n Hn <-]]; last exact: mem_nth.
by exists (index x s); [rewrite index_mem | apply nth_index].
Qed.
Variable T : Type.
Implicit Types (a : pred T) (x : T).
Lemma has_nthP a s x0 :
reflect (exists2 i, i < size s & a (nth x0 s i)) (has a s).
Proof.
elim: s => [|x s IHs] /=; first by right; case.
case nax: (a x); first by left; exists 0.
by apply: (iffP IHs) => [[i]|[[|i]]]; [exists i.+1 | rewrite nax | exists i].
Qed.
Lemma all_nthP a s x0 :
reflect (forall i, i < size s -> a (nth x0 s i)) (all a s).
Proof.
rewrite -(eq_all (fun x => negbK (a x))) all_predC.
case: (has_nthP _ _ x0) => [na_s | a_s]; [right=> a_s | left=> i lti].
by case: na_s => i lti; rewrite a_s.
by apply/idPn=> na_si; case: a_s; exists i.
Qed.
Lemma set_nthE s x0 n x :
set_nth x0 s n x = if n < size s
then take n s ++ x :: drop n.+1 s
else s ++ ncons (n - size s) x0 [:: x].
Proof.
elim: s n => [|a s IH] n /=; first by rewrite subn0 set_nth_nil.
case: n => [|n]; first by rewrite drop0.
by rewrite ltnS /=; case: ltnP (IH n) => _ ->.
Qed.
Lemma count_set_nth a s x0 n x :
count a (set_nth x0 s n x) =
count a s + a x - a (nth x0 s n) * (n < size s) + (a x0) * (n - size s).
Proof.
rewrite set_nthE; case: ltnP => [nlts|nges]; last first.
rewrite -cat_nseq !count_cat count_nseq /=.
by rewrite muln0 addn0 subn0 addnAC addnA.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
rewrite -[in count a s](cat_take_drop n s) [drop n s](drop_nth x0)//.
by rewrite !count_cat/= muln1 muln0 addn0 addnAC !addnA [in RHS]addnAC addnK.
Qed.
Lemma count_set_nth_ltn a s x0 n x : n < size s ->
count a (set_nth x0 s n x) = count a s + a x - a (nth x0 s n).
Proof.
move=> nlts; rewrite count_set_nth nlts muln1.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
by rewrite muln0 addn0.
Qed.
Lemma count_set_nthF a s x0 n x : ~~ a x0 ->
count a (set_nth x0 s n x) = count a s + a x - a (nth x0 s n).
Proof.
move=> /negbTE ax0; rewrite count_set_nth ax0 mul0n addn0.
case: ltnP => [_|nges]; first by rewrite muln1.
by rewrite nth_default// ax0 subn0.
Qed.
End NthTheory.
Lemma set_nth_default T s (y0 x0 : T) n : n < size s -> nth x0 s n = nth y0 s n.
Proof. by elim: s n => [|y s' IHs] [|n] //= /IHs. Qed.
Lemma headI T s (x : T) : rcons s x = head x s :: behead (rcons s x).
Proof. by case: s. Qed.
Arguments nthP {T s x}.
Arguments has_nthP {T a s}.
Arguments all_nthP {T a s}.
Definition bitseq := seq bool.
#[hnf] HB.instance Definition _ := Equality.on bitseq.
Canonical bitseq_predType := Eval hnf in [predType of bitseq].
(* Generalizations of splitP (from path.v): split_find_nth and split_find *)
Section FindNth.
Variables (T : Type).
Implicit Types (x : T) (p : pred T) (s : seq T).
Variant split_find_nth_spec p : seq T -> seq T -> seq T -> T -> Type :=
FindNth x s1 s2 of p x & ~~ has p s1 :
split_find_nth_spec p (rcons s1 x ++ s2) s1 s2 x.
Lemma split_find_nth x0 p s (i := find p s) :
has p s -> split_find_nth_spec p s (take i s) (drop i.+1 s) (nth x0 s i).
Proof.
move=> p_s; rewrite -[X in split_find_nth_spec _ X](cat_take_drop i s).
rewrite (drop_nth x0 _) -?has_find// -cat_rcons.
by constructor; [apply: nth_find | rewrite has_take -?leqNgt].
Qed.
Variant split_find_spec p : seq T -> seq T -> seq T -> Type :=
FindSplit x s1 s2 of p x & ~~ has p s1 :
split_find_spec p (rcons s1 x ++ s2) s1 s2.
Lemma split_find p s (i := find p s) :
has p s -> split_find_spec p s (take i s) (drop i.+1 s).
Proof.
by case: s => // x ? in i * => ?; case: split_find_nth => //; constructor.
Qed.
Lemma nth_rcons_cat_find x0 p s1 s2 x (s := rcons s1 x ++ s2) :
p x -> ~~ has p s1 -> nth x0 s (find p s) = x.
Proof.
move=> pz pNs1; rewrite /s cat_rcons find_cat (negPf pNs1).
by rewrite nth_cat/= pz addn0 subnn ltnn.
Qed.
End FindNth.
(* Incrementing the ith nat in a seq nat, padding with 0's if needed. This *)
(* allows us to use nat seqs as bags of nats. *)
Fixpoint incr_nth v i {struct i} :=
if v is n :: v' then if i is i'.+1 then n :: incr_nth v' i' else n.+1 :: v'
else ncons i 0 [:: 1].
Arguments incr_nth : simpl nomatch.
Lemma nth_incr_nth v i j : nth 0 (incr_nth v i) j = (i == j) + nth 0 v j.
Proof.
elim: v i j => [|n v IHv] [|i] [|j] //=; rewrite ?eqSS ?addn0 //; try by case j.
elim: i j => [|i IHv] [|j] //=; rewrite ?eqSS //; by case j.
Qed.
Lemma size_incr_nth v i :
size (incr_nth v i) = if i < size v then size v else i.+1.
Proof.
elim: v i => [|n v IHv] [|i] //=; first by rewrite size_ncons /= addn1.
by rewrite IHv; apply: fun_if.
Qed.
Lemma incr_nth_inj v : injective (incr_nth v).
Proof.
move=> i j /(congr1 (nth 0 ^~ i)); apply: contra_eq => neq_ij.
by rewrite !nth_incr_nth eqn_add2r eqxx /nat_of_bool ifN_eqC.
Qed.
Lemma incr_nthC v i j :
incr_nth (incr_nth v i) j = incr_nth (incr_nth v j) i.
Proof.
apply: (@eq_from_nth _ 0) => [|k _]; last by rewrite !nth_incr_nth addnCA.
by do !rewrite size_incr_nth leqNgt if_neg -/(maxn _ _); apply: maxnAC.
Qed.
(* Equality up to permutation *)
Section PermSeq.
Variable T : eqType.
Implicit Type s : seq T.
Definition perm_eq s1 s2 :=
all [pred x | count_mem x s1 == count_mem x s2] (s1 ++ s2).
Lemma permP s1 s2 : reflect (count^~ s1 =1 count^~ s2) (perm_eq s1 s2).
Proof.
apply: (iffP allP) => /= [eq_cnt1 a | eq_cnt x _]; last exact/eqP.
have [n le_an] := ubnP (count a (s1 ++ s2)); elim: n => // n IHn in a le_an *.
have [/eqP|] := posnP (count a (s1 ++ s2)).
by rewrite count_cat addn_eq0; do 2!case: eqP => // ->.
rewrite -has_count => /hasP[x s12x a_x]; pose a' := predD1 a x.
have cnt_a' s: count a s = count_mem x s + count a' s.
rewrite -count_predUI -[LHS]addn0 -(count_pred0 s).
by congr (_ + _); apply: eq_count => y /=; case: eqP => // ->.
rewrite !cnt_a' (eqnP (eq_cnt1 _ s12x)) (IHn a') // -ltnS.
apply: leq_trans le_an.
by rewrite ltnS cnt_a' -add1n leq_add2r -has_count has_pred1.
Qed.
Lemma perm_refl s : perm_eq s s.
Proof. exact/permP. Qed.
Hint Resolve perm_refl : core.
Lemma perm_sym : symmetric perm_eq.
Proof. by move=> s1 s2; apply/permP/permP=> eq_s12 a. Qed.
Lemma perm_trans : transitive perm_eq.
Proof. by move=> s2 s1 s3 /permP-eq12 /permP/(ftrans eq12)/permP. Qed.
Notation perm_eql s1 s2 := (perm_eq s1 =1 perm_eq s2).
Notation perm_eqr s1 s2 := (perm_eq^~ s1 =1 perm_eq^~ s2).
Lemma permEl s1 s2 : perm_eql s1 s2 -> perm_eq s1 s2. Proof. by move->. Qed.
Lemma permPl s1 s2 : reflect (perm_eql s1 s2) (perm_eq s1 s2).
Proof.
apply: (iffP idP) => [eq12 s3 | -> //]; apply/idP/idP; last exact: perm_trans.
by rewrite -!(perm_sym s3) => /perm_trans; apply.
Qed.
Lemma permPr s1 s2 : reflect (perm_eqr s1 s2) (perm_eq s1 s2).
Proof.
by apply/(iffP idP) => [/permPl eq12 s3| <- //]; rewrite !(perm_sym s3) eq12.
Qed.
Lemma perm_catC s1 s2 : perm_eql (s1 ++ s2) (s2 ++ s1).
Proof. by apply/permPl/permP=> a; rewrite !count_cat addnC. Qed.
Lemma perm_cat2l s1 s2 s3 : perm_eq (s1 ++ s2) (s1 ++ s3) = perm_eq s2 s3.
Proof.
apply/permP/permP=> eq23 a; apply/eqP;
by move/(_ a)/eqP: eq23; rewrite !count_cat eqn_add2l.
Qed.
Lemma perm_catl s t1 t2 : perm_eq t1 t2 -> perm_eql (s ++ t1) (s ++ t2).
Proof. by move=> eq_t12; apply/permPl; rewrite perm_cat2l. Qed.
Lemma perm_cons x s1 s2 : perm_eq (x :: s1) (x :: s2) = perm_eq s1 s2.
Proof. exact: (perm_cat2l [::x]). Qed.
Lemma perm_cat2r s1 s2 s3 : perm_eq (s2 ++ s1) (s3 ++ s1) = perm_eq s2 s3.
Proof. by do 2!rewrite perm_sym perm_catC; apply: perm_cat2l. Qed.
Lemma perm_catr s1 s2 t : perm_eq s1 s2 -> perm_eql (s1 ++ t) (s2 ++ t).
Proof. by move=> eq_s12; apply/permPl; rewrite perm_cat2r. Qed.
Lemma perm_cat s1 s2 t1 t2 :
perm_eq s1 s2 -> perm_eq t1 t2 -> perm_eq (s1 ++ t1) (s2 ++ t2).
Proof. by move=> /perm_catr-> /perm_catl->. Qed.
Lemma perm_catAC s1 s2 s3 : perm_eql ((s1 ++ s2) ++ s3) ((s1 ++ s3) ++ s2).
Proof. by apply/permPl; rewrite -!catA perm_cat2l perm_catC. Qed.
Lemma perm_catCA s1 s2 s3 : perm_eql (s1 ++ s2 ++ s3) (s2 ++ s1 ++ s3).
Proof. by apply/permPl; rewrite !catA perm_cat2r perm_catC. Qed.
Lemma perm_catACA s1 s2 s3 s4 :
perm_eql ((s1 ++ s2) ++ (s3 ++ s4)) ((s1 ++ s3) ++ (s2 ++ s4)).
Proof. by apply/permPl; rewrite perm_catAC !catA perm_catAC. Qed.
Lemma perm_rcons x s : perm_eql (rcons s x) (x :: s).
Proof. by move=> /= s2; rewrite -cats1 perm_catC. Qed.
Lemma perm_rot n s : perm_eql (rot n s) s.
Proof. by move=> /= s2; rewrite perm_catC cat_take_drop. Qed.
Lemma perm_rotr n s : perm_eql (rotr n s) s.
Proof. exact: perm_rot. Qed.
Lemma perm_rev s : perm_eql (rev s) s.
Proof. by apply/permPl/permP=> i; rewrite count_rev. Qed.
Lemma perm_filter s1 s2 a :
perm_eq s1 s2 -> perm_eq (filter a s1) (filter a s2).
Proof. by move/permP=> s12_count; apply/permP=> Q; rewrite !count_filter. Qed.
Lemma perm_filterC a s : perm_eql (filter a s ++ filter (predC a) s) s.
Proof.
apply/permPl; elim: s => //= x s IHs.
by case: (a x); last rewrite /= -cat1s perm_catCA; rewrite perm_cons.
Qed.
Lemma perm_size s1 s2 : perm_eq s1 s2 -> size s1 = size s2.
Proof. by move/permP=> eq12; rewrite -!count_predT eq12. Qed.
Lemma perm_mem s1 s2 : perm_eq s1 s2 -> s1 =i s2.
Proof. by move/permP=> eq12 x; rewrite -!has_pred1 !has_count eq12. Qed.
Lemma perm_nilP s : reflect (s = [::]) (perm_eq s [::]).
Proof. by apply: (iffP idP) => [/perm_size/eqP/nilP | ->]. Qed.
Lemma perm_consP x s t :
reflect (exists i u, rot i t = x :: u /\ perm_eq u s)
(perm_eq t (x :: s)).
Proof.
apply: (iffP idP) => [eq_txs | [i [u [Dt eq_us]]]].
have /rot_to[i u Dt]: x \in t by rewrite (perm_mem eq_txs) mem_head.
by exists i, u; rewrite -(perm_cons x) -Dt perm_rot.
by rewrite -(perm_rot i) Dt perm_cons.
Qed.
Lemma perm_has s1 s2 a : perm_eq s1 s2 -> has a s1 = has a s2.
Proof. by move/perm_mem/eq_has_r. Qed.
Lemma perm_all s1 s2 a : perm_eq s1 s2 -> all a s1 = all a s2.
Proof. by move/perm_mem/eq_all_r. Qed.
Lemma perm_small_eq s1 s2 : size s2 <= 1 -> perm_eq s1 s2 -> s1 = s2.
Proof.
move=> s2_le1 eqs12; move/perm_size: eqs12 s2_le1 (perm_mem eqs12).
by case: s2 s1 => [|x []] // [|y []] // _ _ /(_ x) /[!(inE, eqxx)] /eqP->.
Qed.
Lemma uniq_leq_size s1 s2 : uniq s1 -> {subset s1 <= s2} -> size s1 <= size s2.
Proof.
elim: s1 s2 => //= x s1 IHs s2 /andP[not_s1x Us1] /forall_cons[s2x ss12].
have [i s3 def_s2] := rot_to s2x; rewrite -(size_rot i s2) def_s2.
apply: IHs => // y s1y; have:= ss12 y s1y.
by rewrite -(mem_rot i) def_s2 inE (negPf (memPn _ y s1y)).
Qed.
Lemma leq_size_uniq s1 s2 :
uniq s1 -> {subset s1 <= s2} -> size s2 <= size s1 -> uniq s2.
Proof.
elim: s1 s2 => [[] | x s1 IHs s2] // Us1x; have /andP[not_s1x Us1] := Us1x.
case/forall_cons => /rot_to[i s3 def_s2] ss12 le_s21.
rewrite -(rot_uniq i) -(size_rot i) def_s2 /= in le_s21 *.
have ss13 y (s1y : y \in s1): y \in s3.
by have:= ss12 y s1y; rewrite -(mem_rot i) def_s2 inE (negPf (memPn _ y s1y)).
rewrite IHs // andbT; apply: contraL _ le_s21 => s3x; rewrite -leqNgt.
by apply/(uniq_leq_size Us1x)/allP; rewrite /= s3x; apply/allP.
Qed.
Lemma uniq_size_uniq s1 s2 :
uniq s1 -> s1 =i s2 -> uniq s2 = (size s2 == size s1).
Proof.
move=> Us1 eqs12; apply/idP/idP=> [Us2 | /eqP eq_sz12].
by rewrite eqn_leq !uniq_leq_size // => y; rewrite eqs12.
by apply: (leq_size_uniq Us1) => [y|]; rewrite (eqs12, eq_sz12).
Qed.
Lemma uniq_min_size s1 s2 :
uniq s1 -> {subset s1 <= s2} -> size s2 <= size s1 ->
(size s1 = size s2) * (s1 =i s2).
Proof.
move=> Us1 ss12 le_s21; have Us2: uniq s2 := leq_size_uniq Us1 ss12 le_s21.
suffices: s1 =i s2 by split; first by apply/eqP; rewrite -uniq_size_uniq.
move=> x; apply/idP/idP=> [/ss12// | s2x]; apply: contraLR le_s21 => not_s1x.
rewrite -ltnNge (@uniq_leq_size (x :: s1)) /= ?not_s1x //.
by apply/allP; rewrite /= s2x; apply/allP.
Qed.
Lemma eq_uniq s1 s2 : size s1 = size s2 -> s1 =i s2 -> uniq s1 = uniq s2.
Proof.
move=> eq_sz12 eq_s12.
by apply/idP/idP=> Us; rewrite (uniq_size_uniq Us) ?eq_sz12 ?eqxx.
Qed.
Lemma perm_uniq s1 s2 : perm_eq s1 s2 -> uniq s1 = uniq s2.
Proof. by move=> eq_s12; apply/eq_uniq; [apply/perm_size | apply/perm_mem]. Qed.
Lemma uniq_perm s1 s2 : uniq s1 -> uniq s2 -> s1 =i s2 -> perm_eq s1 s2.
Proof.
move=> Us1 Us2 eq12; apply/allP=> x _; apply/eqP.
by rewrite !count_uniq_mem ?eq12.
Qed.
Lemma perm_undup s1 s2 : s1 =i s2 -> perm_eq (undup s1) (undup s2).
Proof.
by move=> Es12; rewrite uniq_perm ?undup_uniq // => s; rewrite !mem_undup.
Qed.
Lemma count_mem_uniq s : (forall x, count_mem x s = (x \in s)) -> uniq s.
Proof.
move=> count1_s; have Uus := undup_uniq s.
suffices: perm_eq s (undup s) by move/perm_uniq->.
by apply/allP=> x _; apply/eqP; rewrite (count_uniq_mem x Uus) mem_undup.
Qed.
Lemma eq_count_undup a s1 s2 :
{in a, s1 =i s2} -> count a (undup s1) = count a (undup s2).
Proof.
move=> s1_eq_s2; rewrite -!size_filter !filter_undup.
apply/perm_size/perm_undup => x.
by rewrite !mem_filter; case: (boolP (a x)) => //= /s1_eq_s2.
Qed.
Lemma catCA_perm_ind P :
(forall s1 s2 s3, P (s1 ++ s2 ++ s3) -> P (s2 ++ s1 ++ s3)) ->
(forall s1 s2, perm_eq s1 s2 -> P s1 -> P s2).
Proof.
move=> PcatCA s1 s2 eq_s12; rewrite -[s1]cats0 -[s2]cats0.
elim: s2 nil => [|x s2 IHs] s3 in s1 eq_s12 *.
by case: s1 {eq_s12}(perm_size eq_s12).
have /rot_to[i s' def_s1]: x \in s1 by rewrite (perm_mem eq_s12) mem_head.
rewrite -(cat_take_drop i s1) -catA => /PcatCA.
rewrite catA -/(rot i s1) def_s1 /= -cat1s => /PcatCA/IHs/PcatCA; apply.
by rewrite -(perm_cons x) -def_s1 perm_rot.
Qed.
Lemma catCA_perm_subst R F :
(forall s1 s2 s3, F (s1 ++ s2 ++ s3) = F (s2 ++ s1 ++ s3) :> R) ->
(forall s1 s2, perm_eq s1 s2 -> F s1 = F s2).
Proof.
move=> FcatCA s1 s2 /catCA_perm_ind => ind_s12.
by apply: (ind_s12 (eq _ \o F)) => //= *; rewrite FcatCA.
Qed.
End PermSeq.
Notation perm_eql s1 s2 := (perm_eq s1 =1 perm_eq s2).
Notation perm_eqr s1 s2 := (perm_eq^~ s1 =1 perm_eq^~ s2).
Arguments permP {T s1 s2}.
Arguments permPl {T s1 s2}.
Arguments permPr {T s1 s2}.
Prenex Implicits perm_eq.
#[global] Hint Resolve perm_refl : core.
Section RotrLemmas.
Variables (n0 : nat) (T : Type) (T' : eqType).
Implicit Types (x : T) (s : seq T).
Lemma size_rotr s : size (rotr n0 s) = size s.
Proof. by rewrite size_rot. Qed.
Lemma mem_rotr (s : seq T') : rotr n0 s =i s.
Proof. by move=> x; rewrite mem_rot. Qed.
Lemma rotr_size_cat s1 s2 : rotr (size s2) (s1 ++ s2) = s2 ++ s1.
Proof. by rewrite /rotr size_cat addnK rot_size_cat. Qed.
Lemma rotr1_rcons x s : rotr 1 (rcons s x) = x :: s.
Proof. by rewrite -rot1_cons rotK. Qed.
Lemma has_rotr a s : has a (rotr n0 s) = has a s.
Proof. by rewrite has_rot. Qed.
Lemma rotr_uniq (s : seq T') : uniq (rotr n0 s) = uniq s.
Proof. by rewrite rot_uniq. Qed.
Lemma rotrK : cancel (@rotr T n0) (rot n0).
Proof.
move=> s; have [lt_n0s | ge_n0s] := ltnP n0 (size s).
by rewrite -{1}(subKn (ltnW lt_n0s)) -{1}[size s]size_rotr; apply: rotK.
by rewrite -[in RHS](rot_oversize ge_n0s) /rotr (eqnP ge_n0s) rot0.
Qed.
Lemma rotr_inj : injective (@rotr T n0).
Proof. exact (can_inj rotrK). Qed.
Lemma take_rev s : take n0 (rev s) = rev (drop (size s - n0) s).
Proof.
set m := _ - n0; rewrite -[s in LHS](cat_take_drop m) rev_cat take_cat.
rewrite size_rev size_drop -minnE minnC leq_min ltnn /m.
by have [_|/eqnP->] := ltnP; rewrite ?subnn take0 cats0.
Qed.
Lemma rev_take s : rev (take n0 s) = drop (size s - n0) (rev s).
Proof. by rewrite -[s in take _ s]revK take_rev revK size_rev. Qed.
Lemma drop_rev s : drop n0 (rev s) = rev (take (size s - n0) s).
Proof.
set m := _ - n0; rewrite -[s in LHS](cat_take_drop m) rev_cat drop_cat.
rewrite size_rev size_drop -minnE minnC leq_min ltnn /m.
by have [_|/eqnP->] := ltnP; rewrite ?take0 // subnn drop0.
Qed.
Lemma rev_drop s : rev (drop n0 s) = take (size s - n0) (rev s).
Proof. by rewrite -[s in drop _ s]revK drop_rev revK size_rev. Qed.
Lemma rev_rotr s : rev (rotr n0 s) = rot n0 (rev s).
Proof. by rewrite rev_cat -take_rev -drop_rev. Qed.
Lemma rev_rot s : rev (rot n0 s) = rotr n0 (rev s).
Proof. by apply: canLR revK _; rewrite rev_rotr revK. Qed.
End RotrLemmas.
Arguments rotrK n0 {T} s : rename.
Arguments rotr_inj {n0 T} [s1 s2] eq_rotr_s12 : rename.
Section RotCompLemmas.
Variable T : Type.
Implicit Type s : seq T.
Lemma rotD m n s : m + n <= size s -> rot (m + n) s = rot m (rot n s).
Proof.
move=> sz_s; rewrite [LHS]/rot -[take _ s](cat_take_drop n).
rewrite 5!(catA, =^~ rot_size_cat) !cat_take_drop.
by rewrite size_drop !size_takel ?leq_addl ?addnK.
Qed.
Lemma rotS n s : n < size s -> rot n.+1 s = rot 1 (rot n s).
Proof. exact: (@rotD 1). Qed.
Lemma rot_add_mod m n s : n <= size s -> m <= size s ->
rot m (rot n s) = rot (if m + n <= size s then m + n else m + n - size s) s.
Proof.
move=> Hn Hm; case: leqP => [/rotD // | /ltnW Hmn]; symmetry.
by rewrite -{2}(rotK n s) /rotr -rotD size_rot addnBA ?subnK ?addnK.
Qed.
Lemma rot_minn n s : rot n s = rot (minn n (size s)) s.
Proof.
by case: (leqP n (size s)) => // /leqW ?; rewrite rot_size rot_oversize.
Qed.
Definition rot_add s n m (k := size s) (p := minn m k + minn n k) :=
locked (if p <= k then p else p - k).
Lemma leq_rot_add n m s : rot_add s n m <= size s.
Proof.
by unlock rot_add; case: ifP; rewrite // leq_subLR leq_add // geq_minr.
Qed.
Lemma rot_addC n m s : rot_add s n m = rot_add s m n.
Proof. by unlock rot_add; rewrite ![minn n _ + _]addnC. Qed.
Lemma rot_rot_add n m s : rot m (rot n s) = rot (rot_add s n m) s.
Proof.
unlock rot_add.
by rewrite (rot_minn n) (rot_minn m) rot_add_mod ?size_rot ?geq_minr.
Qed.
Lemma rot_rot m n s : rot m (rot n s) = rot n (rot m s).
Proof. by rewrite rot_rot_add rot_addC -rot_rot_add. Qed.
Lemma rot_rotr m n s : rot m (rotr n s) = rotr n (rot m s).
Proof. by rewrite [RHS]/rotr size_rot rot_rot. Qed.
Lemma rotr_rotr m n s : rotr m (rotr n s) = rotr n (rotr m s).
Proof. by rewrite /rotr !size_rot rot_rot. Qed.
End RotCompLemmas.
Section Mask.
Variables (n0 : nat) (T : Type).
Implicit Types (m : bitseq) (s : seq T).
Fixpoint mask m s {struct m} :=
match m, s with
| b :: m', x :: s' => if b then x :: mask m' s' else mask m' s'
| _, _ => [::]
end.
Lemma mask_false s n : mask (nseq n false) s = [::].
Proof. by elim: s n => [|x s IHs] [|n] /=. Qed.
Lemma mask_true s n : size s <= n -> mask (nseq n true) s = s.
Proof. by elim: s n => [|x s IHs] [|n] //= Hn; congr (_ :: _); apply: IHs. Qed.
Lemma mask0 m : mask m [::] = [::].
Proof. by case: m. Qed.
Lemma mask0s s : mask [::] s = [::]. Proof. by []. Qed.
Lemma mask1 b x : mask [:: b] [:: x] = nseq b x.
Proof. by case: b. Qed.
Lemma mask_cons b m x s : mask (b :: m) (x :: s) = nseq b x ++ mask m s.
Proof. by case: b. Qed.
Lemma size_mask m s : size m = size s -> size (mask m s) = count id m.
Proof. by move: m s; apply: seq_ind2 => // -[] x m s /= _ ->. Qed.
Lemma mask_cat m1 m2 s1 s2 :
size m1 = size s1 -> mask (m1 ++ m2) (s1 ++ s2) = mask m1 s1 ++ mask m2 s2.
Proof. by move: m1 s1; apply: seq_ind2 => // -[] m1 x1 s1 /= _ ->. Qed.
Lemma mask_rcons b m x s : size m = size s ->
mask (rcons m b) (rcons s x) = mask m s ++ nseq b x.
Proof. by move=> ms; rewrite -!cats1 mask_cat//; case: b. Qed.
Lemma all_mask a m s : all a s -> all a (mask m s).
Proof. by elim: s m => [|x s IHs] [|[] m]//= /andP[ax /IHs->]; rewrite ?ax. Qed.
Lemma has_mask_cons a b m x s :
has a (mask (b :: m) (x :: s)) = b && a x || has a (mask m s).
Proof. by case: b. Qed.
Lemma has_mask a m s : has a (mask m s) -> has a s.
Proof. by apply/contraTT; rewrite -!all_predC; apply: all_mask. Qed.
Lemma rev_mask m s : size m = size s -> rev (mask m s) = mask (rev m) (rev s).
Proof.
move: m s; apply: seq_ind2 => //= b x m s eq_size_sm IH.
by case: b; rewrite !rev_cons mask_rcons ?IH ?size_rev// (cats1, cats0).
Qed.
Lemma mask_rot m s : size m = size s ->
mask (rot n0 m) (rot n0 s) = rot (count id (take n0 m)) (mask m s).
Proof.
move=> Ems; rewrite mask_cat ?size_drop ?Ems // -rot_size_cat.
by rewrite size_mask -?mask_cat ?size_take ?Ems // !cat_take_drop.
Qed.
Lemma resize_mask m s : {m1 | size m1 = size s & mask m s = mask m1 s}.
Proof.
exists (take (size s) m ++ nseq (size s - size m) false).
by elim: s m => [|x s IHs] [|b m] //=; rewrite (size_nseq, IHs).
by elim: s m => [|x s IHs] [|b m] //=; rewrite (mask_false, IHs).
Qed.
Lemma takeEmask i s : take i s = mask (nseq i true) s.
Proof. by elim: i s => [s|i IHi []// ? ?]; rewrite ?take0 //= IHi. Qed.
Lemma dropEmask i s :
drop i s = mask (nseq i false ++ nseq (size s - i) true) s.
Proof. by elim: i s => [s|? ? []//]; rewrite drop0/= mask_true// subn0. Qed.
End Mask.
Arguments mask _ !_ !_.
Section EqMask.
Variables (n0 : nat) (T : eqType).
Implicit Types (s : seq T) (m : bitseq).
Lemma mem_mask_cons x b m y s :
(x \in mask (b :: m) (y :: s)) = b && (x == y) || (x \in mask m s).
Proof. by case: b. Qed.
Lemma mem_mask x m s : x \in mask m s -> x \in s.
Proof. by rewrite -!has_pred1 => /has_mask. Qed.
Lemma in_mask x m s :
uniq s -> x \in mask m s = (x \in s) && nth false m (index x s).
Proof.
elim: s m => [|y s IHs] [|[] m]//= /andP[yNs ?]; rewrite ?in_cons ?IHs //=;
by have [->|neq_xy] //= := eqVneq; rewrite ?andbF // (negPf yNs).
Qed.
Lemma mask_uniq s : uniq s -> forall m, uniq (mask m s).
Proof.
elim: s => [|x s IHs] Uxs [|b m] //=.
case: b Uxs => //= /andP[s'x Us]; rewrite {}IHs // andbT.
by apply: contra s'x; apply: mem_mask.
Qed.
Lemma mem_mask_rot m s :
size m = size s -> mask (rot n0 m) (rot n0 s) =i mask m s.
Proof. by move=> Ems x; rewrite mask_rot // mem_rot. Qed.
End EqMask.
Section Subseq.
Variable T : eqType.
Implicit Type s : seq T.
Fixpoint subseq s1 s2 :=
if s2 is y :: s2' then
if s1 is x :: s1' then subseq (if x == y then s1' else s1) s2' else true
else s1 == [::].
Lemma sub0seq s : subseq [::] s. Proof. by case: s. Qed.
Lemma subseq0 s : subseq s [::] = (s == [::]). Proof. by []. Qed.
Lemma subseq_refl s : subseq s s.
Proof. by elim: s => //= x s IHs; rewrite eqxx. Qed.
Hint Resolve subseq_refl : core.
Lemma subseqP s1 s2 :
reflect (exists2 m, size m = size s2 & s1 = mask m s2) (subseq s1 s2).
Proof.
elim: s2 s1 => [|y s2 IHs2] [|x s1].
- by left; exists [::].
- by right=> -[m /eqP/nilP->].
- by left; exists (nseq (size s2).+1 false); rewrite ?size_nseq //= mask_false.
apply: {IHs2}(iffP (IHs2 _)) => [] [m sz_m def_s1].
by exists ((x == y) :: m); rewrite /= ?sz_m // -def_s1; case: eqP => // ->.
case: eqP => [_ | ne_xy]; last first.
by case: m def_s1 sz_m => [|[] m] //; [case | move=> -> [<-]; exists m].
pose i := index true m; have def_m_i: take i m = nseq (size (take i m)) false.
apply/all_pred1P; apply/(all_nthP true) => j.
rewrite size_take ltnNge geq_min negb_or -ltnNge => /andP[lt_j_i _].
rewrite nth_take //= -negb_add addbF -addbT -negb_eqb.
by rewrite [_ == _](before_find _ lt_j_i).
have lt_i_m: i < size m.
rewrite ltnNge; apply/negP=> le_m_i; rewrite take_oversize // in def_m_i.
by rewrite def_m_i mask_false in def_s1.
rewrite size_take lt_i_m in def_m_i.
exists (take i m ++ drop i.+1 m).
rewrite size_cat size_take size_drop lt_i_m.
by rewrite sz_m in lt_i_m *; rewrite subnKC.
rewrite {s1 def_s1}[s1](congr1 behead def_s1).
rewrite -[s2](cat_take_drop i) -[m in LHS](cat_take_drop i) {}def_m_i -cat_cons.
have sz_i_s2: size (take i s2) = i by apply: size_takel; rewrite sz_m in lt_i_m.
rewrite lastI cat_rcons !mask_cat ?size_nseq ?size_belast ?mask_false //=.
by rewrite (drop_nth true) // nth_index -?index_mem.
Qed.
Lemma mask_subseq m s : subseq (mask m s) s.
Proof. by apply/subseqP; have [m1] := resize_mask m s; exists m1. Qed.
Lemma subseq_trans : transitive subseq.
Proof.
move=> _ _ s /subseqP[m2 _ ->] /subseqP[m1 _ ->].
elim: s => [|x s IHs] in m2 m1 *; first by rewrite !mask0.
case: m1 => [|[] m1]; first by rewrite mask0.
case: m2 => [|[] m2] //; first by rewrite /= eqxx IHs.
case/subseqP: (IHs m2 m1) => m sz_m def_s; apply/subseqP.
by exists (false :: m); rewrite //= sz_m.
case/subseqP: (IHs m2 m1) => m sz_m def_s; apply/subseqP.
by exists (false :: m); rewrite //= sz_m.
Qed.
Lemma cat_subseq s1 s2 s3 s4 :
subseq s1 s3 -> subseq s2 s4 -> subseq (s1 ++ s2) (s3 ++ s4).
Proof.
case/subseqP=> m1 sz_m1 -> /subseqP [m2 sz_m2 ->]; apply/subseqP.
by exists (m1 ++ m2); rewrite ?size_cat ?mask_cat ?sz_m1 ?sz_m2.
Qed.
Lemma prefix_subseq s1 s2 : subseq s1 (s1 ++ s2).
Proof. by rewrite -[s1 in subseq s1]cats0 cat_subseq ?sub0seq. Qed.
Lemma suffix_subseq s1 s2 : subseq s2 (s1 ++ s2).
Proof. exact: cat_subseq (sub0seq s1) _. Qed.
Lemma take_subseq s i : subseq (take i s) s.
Proof. by rewrite -[s in X in subseq _ X](cat_take_drop i) prefix_subseq. Qed.
Lemma drop_subseq s i : subseq (drop i s) s.
Proof. by rewrite -[s in X in subseq _ X](cat_take_drop i) suffix_subseq. Qed.
Lemma mem_subseq s1 s2 : subseq s1 s2 -> {subset s1 <= s2}.
Proof. by case/subseqP=> m _ -> x; apply: mem_mask. Qed.
Lemma sub1seq x s : subseq [:: x] s = (x \in s).
Proof. by elim: s => //= y s /[1!inE]; case: ifP; rewrite ?sub0seq. Qed.
Lemma size_subseq s1 s2 : subseq s1 s2 -> size s1 <= size s2.
Proof. by case/subseqP=> m sz_m ->; rewrite size_mask -sz_m ?count_size. Qed.
Lemma size_subseq_leqif s1 s2 :
subseq s1 s2 -> size s1 <= size s2 ?= iff (s1 == s2).
Proof.
move=> sub12; split; first exact: size_subseq.
apply/idP/eqP=> [|-> //]; case/subseqP: sub12 => m sz_m ->{s1}.
rewrite size_mask -sz_m // -all_count -(eq_all eqb_id).
by move/(@all_pred1P _ true)->; rewrite sz_m mask_true.
Qed.
Lemma subseq_anti : antisymmetric subseq.
Proof.
move=> s1 s2 /andP[] /size_subseq_leqif /leqifP.
by case: eqP => [//|_] + /size_subseq; rewrite ltnNge => /negP.
Qed.
Lemma subseq_cons s x : subseq s (x :: s).
Proof. exact: suffix_subseq [:: x] s. Qed.
Lemma cons_subseq s1 s2 x : subseq (x :: s1) s2 -> subseq s1 s2.
Proof. exact/subseq_trans/subseq_cons. Qed.
Lemma subseq_rcons s x : subseq s (rcons s x).
Proof. by rewrite -cats1 prefix_subseq. Qed.
Lemma subseq_uniq s1 s2 : subseq s1 s2 -> uniq s2 -> uniq s1.
Proof. by case/subseqP=> m _ -> Us2; apply: mask_uniq. Qed.
Lemma take_uniq s n : uniq s -> uniq (take n s).
Proof. exact/subseq_uniq/take_subseq. Qed.
Lemma drop_uniq s n : uniq s -> uniq (drop n s).
Proof. exact/subseq_uniq/drop_subseq. Qed.
Lemma undup_subseq s : subseq (undup s) s.
Proof.
elim: s => //= x s; case: (_ \in _); last by rewrite eqxx.
by case: (undup s) => //= y u; case: (_ == _) => //=; apply: cons_subseq.
Qed.
Lemma subseq_rev s1 s2 : subseq (rev s1) (rev s2) = subseq s1 s2.
Proof.
wlog suff W : s1 s2 / subseq s1 s2 -> subseq (rev s1) (rev s2).
by apply/idP/idP => /W //; rewrite !revK.
by case/subseqP => m size_m ->; rewrite rev_mask // mask_subseq.
Qed.
Lemma subseq_cat2l s s1 s2 : subseq (s ++ s1) (s ++ s2) = subseq s1 s2.
Proof. by elim: s => // x s IHs; rewrite !cat_cons /= eqxx. Qed.
Lemma subseq_cat2r s s1 s2 : subseq (s1 ++ s) (s2 ++ s) = subseq s1 s2.
Proof. by rewrite -subseq_rev !rev_cat subseq_cat2l subseq_rev. Qed.
Lemma subseq_rot p s n :
subseq p s -> exists2 k, k <= n & subseq (rot k p) (rot n s).
Proof.
move=> /subseqP[m size_m ->].
exists (count id (take n m)); last by rewrite -mask_rot // mask_subseq.
by rewrite (leq_trans (count_size _ _))// size_take_min geq_minl.
Qed.
End Subseq.
Prenex Implicits subseq.
Arguments subseqP {T s1 s2}.
#[global] Hint Resolve subseq_refl : core.
Section Rem.
Variables (T : eqType) (x : T).
Fixpoint rem s := if s is y :: t then (if y == x then t else y :: rem t) else s.
Lemma rem_cons y s : rem (y :: s) = if y == x then s else y :: rem s.
Proof. by []. Qed.
Lemma remE s : rem s = take (index x s) s ++ drop (index x s).+1 s.
Proof. by elim: s => //= y s ->; case: eqVneq; rewrite ?drop0. Qed.
Lemma rem_id s : x \notin s -> rem s = s.
Proof. by elim: s => //= y s IHs /norP[neq_yx /IHs->]; case: eqVneq neq_yx. Qed.
Lemma perm_to_rem s : x \in s -> perm_eq s (x :: rem s).
Proof.
move=> xs; rewrite remE -[X in perm_eq X](cat_take_drop (index x s)).
by rewrite drop_index// -cat1s perm_catCA cat1s.
Qed.
Lemma size_rem s : x \in s -> size (rem s) = (size s).-1.
Proof. by move/perm_to_rem/perm_size->. Qed.
Lemma rem_subseq s : subseq (rem s) s.
Proof.
elim: s => //= y s IHs; rewrite eq_sym.
by case: ifP => _; [apply: subseq_cons | rewrite eqxx].
Qed.
Lemma rem_uniq s : uniq s -> uniq (rem s).
Proof. by apply: subseq_uniq; apply: rem_subseq. Qed.
Lemma mem_rem s : {subset rem s <= s}.
Proof. exact: mem_subseq (rem_subseq s). Qed.
Lemma rem_mem y s : y != x -> y \in s -> y \in rem s.
Proof.
move=> yx; elim: s => [//|z s IHs] /=.
rewrite inE => /orP[/eqP<-|ys]; first by rewrite (negbTE yx) inE eqxx.
by case: ifP => _ //; rewrite inE IHs ?orbT.
Qed.
Lemma rem_filter s : uniq s -> rem s = filter (predC1 x) s.
Proof.
elim: s => //= y s IHs /andP[not_s_y /IHs->].
by case: eqP => //= <-; apply/esym/all_filterP; rewrite all_predC has_pred1.
Qed.
Lemma mem_rem_uniq s : uniq s -> rem s =i [predD1 s & x].
Proof. by move/rem_filter=> -> y; rewrite mem_filter. Qed.
Lemma mem_rem_uniqF s : uniq s -> x \in rem s = false.
Proof. by move/mem_rem_uniq->; rewrite inE eqxx. Qed.
Lemma count_rem P s : count P (rem s) = count P s - (x \in s) && P x.
Proof.
have [/perm_to_rem/permP->|xNs]/= := boolP (x \in s); first by rewrite addKn.
by rewrite subn0 rem_id.
Qed.
Lemma count_mem_rem y s : count_mem y (rem s) = count_mem y s - (x == y).
Proof.
rewrite count_rem; have []//= := boolP (x \in s).
by case: eqP => // <- /count_memPn->.
Qed.
End Rem.
Section Map.
Variables (n0 : nat) (T1 : Type) (x1 : T1).
Variables (T2 : Type) (x2 : T2) (f : T1 -> T2).
Fixpoint map s := if s is x :: s' then f x :: map s' else [::].
Lemma map_cons x s : map (x :: s) = f x :: map s.
Proof. by []. Qed.
Lemma map_nseq x : map (nseq n0 x) = nseq n0 (f x).
Proof. by elim: n0 => // *; congr (_ :: _). Qed.
Lemma map_cat s1 s2 : map (s1 ++ s2) = map s1 ++ map s2.
Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs. Qed.
Lemma size_map s : size (map s) = size s.
Proof. by elim: s => //= x s ->. Qed.
Lemma behead_map s : behead (map s) = map (behead s).
Proof. by case: s. Qed.
Lemma nth_map n s : n < size s -> nth x2 (map s) n = f (nth x1 s n).
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma map_rcons s x : map (rcons s x) = rcons (map s) (f x).
Proof. by rewrite -!cats1 map_cat. Qed.
Lemma last_map s x : last (f x) (map s) = f (last x s).
Proof. by elim: s x => /=. Qed.
Lemma belast_map s x : belast (f x) (map s) = map (belast x s).
Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed.
Lemma filter_map a s : filter a (map s) = map (filter (preim f a) s).
Proof. by elim: s => //= x s IHs; rewrite (fun_if map) /= IHs. Qed.
Lemma find_map a s : find a (map s) = find (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma has_map a s : has a (map s) = has (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma all_map a s : all a (map s) = all (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma all_mapT (a : pred T2) s : (forall x, a (f x)) -> all a (map s).
Proof. by rewrite all_map => /allT->. Qed.
Lemma count_map a s : count a (map s) = count (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma map_take s : map (take n0 s) = take n0 (map s).
Proof. by elim: n0 s => [|n IHn] [|x s] //=; rewrite IHn. Qed.
Lemma map_drop s : map (drop n0 s) = drop n0 (map s).
Proof. by elim: n0 s => [|n IHn] [|x s] //=; rewrite IHn. Qed.
Lemma map_rot s : map (rot n0 s) = rot n0 (map s).
Proof. by rewrite /rot map_cat map_take map_drop. Qed.
Lemma map_rotr s : map (rotr n0 s) = rotr n0 (map s).
Proof. by apply: canRL (rotK n0) _; rewrite -map_rot rotrK. Qed.
Lemma map_rev s : map (rev s) = rev (map s).
Proof. by elim: s => //= x s IHs; rewrite !rev_cons -!cats1 map_cat IHs. Qed.
Lemma map_mask m s : map (mask m s) = mask m (map s).
Proof. by elim: m s => [|[|] m IHm] [|x p] //=; rewrite IHm. Qed.
Lemma inj_map : injective f -> injective map.
Proof. by move=> injf; elim=> [|x s IHs] [|y t] //= [/injf-> /IHs->]. Qed.
Lemma inj_in_map (A : {pred T1}) :
{in A &, injective f} -> {in [pred s | all [in A] s] &, injective map}.
Proof.
move=> injf; elim=> [|x s IHs] [|y t] //= /andP[Ax As] /andP[Ay At].
by case=> /injf-> // /IHs->.
Qed.
End Map.
(* Sequence indexing with error. *)
Section onth.
Variable T : Type.
Implicit Types x y z : T.
Implicit Types m n : nat.
Implicit Type s : seq T.
Fixpoint onth s n {struct n} : option T :=
if s isn't x :: s then None else
if n isn't n.+1 then Some x else onth s n.
Lemma odflt_onth x0 s n : odflt x0 (onth s n) = nth x0 s n.
Proof. by elim: n s => [|? ?] []. Qed.
Lemma onthE s : onth s =1 nth None (map Some s).
Proof. by move=> n; elim: n s => [|? ?] []. Qed.
Lemma onth_nth x0 x t n : onth t n = Some x -> nth x0 t n = x.
Proof. by move=> tn; rewrite -odflt_onth tn. Qed.
Lemma onth0n n : onth [::] n = None. Proof. by case: n. Qed.
Lemma onth1P x y n : onth [:: x] n = Some y <-> n = 0 /\ x = y.
Proof. by case: n => [|[]]; split=> // -[] // _ ->. Qed.
Lemma onthTE s n : onth s n = (n < size s) :> bool.
Proof. by elim: n s => [|? ?] []. Qed.
Lemma onthNE s n: ~~ onth s n = (size s <= n).
Proof. by rewrite onthTE -leqNgt. Qed.
Lemma onth_default n s : size s <= n -> onth s n = None.
Proof. by rewrite -onthNE; case: onth. Qed.
Lemma onth_cat s1 s2 n :
onth (s1 ++ s2) n = if n < size s1 then onth s1 n else onth s2 (n - size s1).
Proof. by elim: n s1 => [|? ?] []. Qed.
Lemma onth_nseq x n m : onth (nseq n x) m = if m < n then Some x else None.
Proof. by rewrite onthE/= -nth_nseq map_nseq. Qed.
Lemma eq_onthP {s1 s2} :
[<-> s1 = s2;
forall i : nat, i < maxn (size s1) (size s2) -> onth s1 i = onth s2 i;
forall i : nat, onth s1 i = onth s2 i].
Proof.
tfae=> [->//|eqs12 i|eqs12].
have := eqs12 i; case: ltnP => [_ ->//|].
by rewrite geq_max => /andP[is1 is2] _; rewrite !onth_default.
have /eqP eq_size_12 : size s1 == size s2.
by rewrite eqn_leq -!onthNE eqs12 onthNE -eqs12 onthNE !leqnn.
apply/(inj_map Some_inj)/(@eq_from_nth _ None); rewrite !size_map//.
by move=> i _; rewrite -!onthE eqs12.
Qed.
Lemma eq_from_onth [s1 s2 : seq T] :
(forall i : nat, onth s1 i = onth s2 i) -> s1 = s2.
Proof. by move/(eq_onthP 0 2). Qed.
Lemma eq_from_onth_le [s1 s2 : seq T] :
(forall i : nat, i < maxn (size s1) (size s2) -> onth s1 i = onth s2 i) ->
s1 = s2.
Proof. by move/(eq_onthP 0 1). Qed.
End onth.
Lemma onth_map {T S} n (s : seq T) (f : T -> S) :
onth (map f s) n = omap f (onth s n).
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma inj_onth_map {T S} n (s : seq T) (f : T -> S) x :
injective f -> onth (map f s) n = Some (f x) -> onth s n = Some x.
Proof. by rewrite onth_map => /inj_omap + fs; apply. Qed.
Section onthEqType.
Variables T : eqType.
Implicit Types x y z : T.
Implicit Types i m n : nat.
Implicit Type s : seq T.
Lemma onthP s x : reflect (exists i, onth s i = Some x) (x \in s).
Proof.
elim: s => [|y s IHs]; first by constructor=> -[] [].
rewrite in_cons; case: eqVneq => [->|/= Nxy]; first by constructor; exists 0.
apply: (iffP idP) => [/IHs[i <-]|[[|i]//=]]; first by exists i.+1.
by move=> [eq_xy]; rewrite eq_xy eqxx in Nxy.
by move=> six; apply/IHs; exists i.
Qed.
Lemma onthPn s x : reflect (forall i, onth s i != Some x) (x \notin s).
Proof.
apply: (iffP idP); first by move=> /onthP + i; apply: contra_not_neq; exists i.
by move=> nsix; apply/onthP => -[n /eqP/negPn]; rewrite nsix.
Qed.
Lemma onth_inj s n m : uniq s -> minn m n < size s ->
onth s n = onth s m -> n = m.
Proof.
elim: s m n => [|x s IHs]//= [|m] [|n]//=; rewrite ?minnSS !ltnS.
- by move=> /andP[+ _] _ /eqP => /onthPn/(_ _)/negPf->.
- by move=> /andP[+ _] _ /esym /eqP => /onthPn/(_ _)/negPf->.
by move=> /andP[xNs /IHs]/[apply]/[apply]->.
Qed.
End onthEqType.
Arguments onthP {T s x}.
Arguments onthPn {T s x}.
Arguments onth_nth {T}.
Arguments onth_inj {T}.
Notation "[ 'seq' E | i <- s ]" := (map (fun i => E) s)
(i binder, format "[ '[hv' 'seq' E '/ ' | i <- s ] ']'") : seq_scope.
Notation "[ 'seq' E | i <- s & C ]" := [seq E | i <- [seq i <- s | C]]
(i binder,
format "[ '[hv' 'seq' E '/ ' | i <- s '/ ' & C ] ']'") : seq_scope.
Notation "[ 'seq' E : R | i <- s ]" := (@map _ R (fun i => E) s)
(i binder, only parsing) : seq_scope.
Notation "[ 'seq' E : R | i <- s & C ]" := [seq E : R | i <- [seq i <- s | C]]
(i binder, only parsing) : seq_scope.
Lemma filter_mask T a (s : seq T) : filter a s = mask (map a s) s.
Proof. by elim: s => //= x s <-; case: (a x). Qed.
Lemma all_sigP T a (s : seq T) : all a s -> {s' : seq (sig a) | s = map sval s'}.
Proof.
elim: s => /= [_|x s ihs /andP [ax /ihs [s' ->]]]; first by exists [::].
by exists (exist a x ax :: s').
Qed.
Section MiscMask.
Lemma leq_count_mask T (P : {pred T}) m s : count P (mask m s) <= count P s.
Proof.
by elim: s m => [|x s IHs] [|[] m]//=;
rewrite ?leq_add2l (leq_trans (IHs _)) ?leq_addl.
Qed.
Variable (T : eqType).
Implicit Types (s : seq T) (m : bitseq).
Lemma mask_filter s m : uniq s -> mask m s = [seq i <- s | i \in mask m s].
Proof.
elim: m s => [|[] m IH] [|x s /= /andP[/negP xS uS]]; rewrite ?filter_pred0 //.
rewrite inE eqxx /=; congr cons; rewrite [LHS]IH//.
by apply/eq_in_filter => ? /[1!inE]; case: eqP => [->|].
by case: ifP => [/mem_mask //|_]; apply: IH.
Qed.
Lemma leq_count_subseq P s1 s2 : subseq s1 s2 -> count P s1 <= count P s2.
Proof. by move=> /subseqP[m _ ->]; rewrite leq_count_mask. Qed.
Lemma count_maskP s1 s2 :
(forall x, count_mem x s1 <= count_mem x s2) <->
exists2 m : bitseq, size m = size s2 & perm_eq s1 (mask m s2).
Proof.
split=> [s1_le|[m _ /permP s1ms2 x]]; last by rewrite s1ms2 leq_count_mask.
suff [m mP]: exists m, perm_eq s1 (mask m s2).
by have [m' sm' eqm] := resize_mask m s2; exists m'; rewrite -?eqm.
elim: s2 => [|x s2 IHs]//= in s1 s1_le *.
by exists [::]; apply/allP => x _/=; rewrite eqn_leq s1_le.
have [y|m s1s2] := IHs (rem x s1); first by rewrite count_mem_rem leq_subLR.
exists ((x \in s1) :: m); have [|/rem_id<-//] := boolP (x \in s1).
by move/perm_to_rem/permPl->; rewrite perm_cons.
Qed.
Lemma count_subseqP s1 s2 :
(forall x, count_mem x s1 <= count_mem x s2) <->
exists2 s, subseq s s2 & perm_eq s1 s.
Proof.
split=> [/count_maskP[m _]|]; first by exists (mask m s2); rewrite ?mask_subseq.
by move=> -[_/subseqP[m sm ->] ?]; apply/count_maskP; exists m.
Qed.
End MiscMask.
Section FilterSubseq.
Variable T : eqType.
Implicit Types (s : seq T) (a : pred T).
Lemma filter_subseq a s : subseq (filter a s) s.
Proof. by apply/subseqP; exists (map a s); rewrite ?size_map ?filter_mask. Qed.
Lemma subseq_filter s1 s2 a :
subseq s1 (filter a s2) = all a s1 && subseq s1 s2.
Proof.
elim: s2 s1 => [|x s2 IHs] [|y s1] //=; rewrite ?andbF ?sub0seq //.
by case a_x: (a x); rewrite /= !IHs /=; case: eqP => // ->; rewrite a_x.
Qed.
Lemma subseq_uniqP s1 s2 :
uniq s2 -> reflect (s1 = filter [in s1] s2) (subseq s1 s2).
Proof.
move=> uniq_s2; apply: (iffP idP) => [ss12 | ->]; last exact: filter_subseq.
apply/eqP; rewrite -size_subseq_leqif ?subseq_filter ?(introT allP) //.
apply/eqP/esym/perm_size.
rewrite uniq_perm ?filter_uniq ?(subseq_uniq ss12) // => x.
by rewrite mem_filter; apply: andb_idr; apply: (mem_subseq ss12).
Qed.
Lemma uniq_subseq_pivot x (s1 s2 s3 s4 : seq T) (s := s3 ++ x :: s4) :
uniq s -> subseq (s1 ++ x :: s2) s = (subseq s1 s3 && subseq s2 s4).
Proof.
move=> uniq_s; apply/idP/idP => [sub_s'_s|/andP[? ?]]; last first.
by rewrite cat_subseq //= eqxx.
have uniq_s' := subseq_uniq sub_s'_s uniq_s.
have/eqP {sub_s'_s uniq_s} := subseq_uniqP _ uniq_s sub_s'_s.
rewrite !filter_cat /= mem_cat inE eqxx orbT /=.
rewrite uniq_eqseq_pivotl // => /andP [/eqP -> /eqP ->].
by rewrite !filter_subseq.
Qed.
Lemma perm_to_subseq s1 s2 :
subseq s1 s2 -> {s3 | perm_eq s2 (s1 ++ s3)}.
Proof.
elim Ds2: s2 s1 => [|y s2' IHs] [|x s1] //=; try by exists s2; rewrite Ds2.
case: eqP => [-> | _] /IHs[s3 perm_s2] {IHs}.
by exists s3; rewrite perm_cons.
by exists (rcons s3 y); rewrite -cat_cons -perm_rcons -!cats1 catA perm_cat2r.
Qed.
Lemma subseq_rem x : {homo rem x : s1 s2 / @subseq T s1 s2}.
Proof.
move=> s1 s2; elim: s2 s1 => [|x2 s2 IHs2] [|x1 s1]; rewrite ?sub0seq //=.
have [->|_] := eqVneq x1 x2; first by case: eqP => //= _ /IHs2; rewrite eqxx.
move=> /IHs2/subseq_trans->//.
by have [->|_] := eqVneq x x2; [apply: rem_subseq|apply: subseq_cons].
Qed.
End FilterSubseq.
Arguments subseq_uniqP [T s1 s2].
Section EqMap.
Variables (n0 : nat) (T1 : eqType) (x1 : T1).
Variables (T2 : eqType) (x2 : T2) (f : T1 -> T2).
Implicit Type s : seq T1.
Lemma map_f s x : x \in s -> f x \in map f s.
Proof.
by elim: s => //= y s IHs /predU1P[->|/IHs]; [apply: predU1l | apply: predU1r].
Qed.
Lemma mapP s y : reflect (exists2 x, x \in s & y = f x) (y \in map f s).
Proof.
elim: s => [|x s IHs]; [by right; case|rewrite /= inE].
exact: equivP (orPP eqP IHs) (iff_sym exists_cons).
Qed.
Lemma subset_mapP (s : seq T1) (s' : seq T2) :
{subset s' <= map f s} <-> exists2 t, all (mem s) t & s' = map f t.
Proof.
split => [|[r /allP/= rE ->] _ /mapP[x xr ->]]; last by rewrite map_f ?rE.
elim: s' => [|x s' IHs'] subss'; first by exists [::].
have /mapP[y ys ->] := subss' _ (mem_head _ _).
have [x' x's'|t st ->] := IHs'; first by rewrite subss'// inE x's' orbT.
by exists (y :: t); rewrite //= ys st.
Qed.
Lemma map_uniq s : uniq (map f s) -> uniq s.
Proof.
elim: s => //= x s IHs /andP[not_sfx /IHs->]; rewrite andbT.
by apply: contra not_sfx => sx; apply/mapP; exists x.
Qed.
Lemma map_inj_in_uniq s : {in s &, injective f} -> uniq (map f s) = uniq s.
Proof.
elim: s => //= x s IHs //= injf; congr (~~ _ && _).
apply/mapP/idP=> [[y sy /injf] | ]; last by exists x.
by rewrite mem_head mem_behead // => ->.
by apply: IHs => y z sy sz; apply: injf => //; apply: predU1r.
Qed.
Lemma map_subseq s1 s2 : subseq s1 s2 -> subseq (map f s1) (map f s2).
Proof.
case/subseqP=> m sz_m ->; apply/subseqP.
by exists m; rewrite ?size_map ?map_mask.
Qed.
Lemma nth_index_map s x0 x :
{in s &, injective f} -> x \in s -> nth x0 s (index (f x) (map f s)) = x.
Proof.
elim: s => //= y s IHs inj_f s_x; rewrite (inj_in_eq inj_f) ?mem_head //.
move: s_x; rewrite inE; have [-> // | _] := eqVneq; apply: IHs.
by apply: sub_in2 inj_f => z; apply: predU1r.
Qed.
Lemma perm_map s t : perm_eq s t -> perm_eq (map f s) (map f t).
Proof. by move/permP=> Est; apply/permP=> a; rewrite !count_map Est. Qed.
Lemma sub_map s1 s2 : {subset s1 <= s2} -> {subset map f s1 <= map f s2}.
Proof. by move=> sub_s ? /mapP[x x_s ->]; rewrite map_f ?sub_s. Qed.
Lemma eq_mem_map s1 s2 : s1 =i s2 -> map f s1 =i map f s2.
Proof. by move=> Es x; apply/idP/idP; apply: sub_map => ?; rewrite Es. Qed.
Hypothesis Hf : injective f.
Lemma mem_map s x : (f x \in map f s) = (x \in s).
Proof. by apply/mapP/idP=> [[y Hy /Hf->] //|]; exists x. Qed.
Lemma index_map s x : index (f x) (map f s) = index x s.
Proof. by rewrite /index; elim: s => //= y s IHs; rewrite (inj_eq Hf) IHs. Qed.
Lemma map_inj_uniq s : uniq (map f s) = uniq s.
Proof. by apply: map_inj_in_uniq; apply: in2W. Qed.
Lemma undup_map_inj s : undup (map f s) = map f (undup s).
Proof. by elim: s => //= s0 s ->; rewrite mem_map //; case: (_ \in _). Qed.
Lemma perm_map_inj s t : perm_eq (map f s) (map f t) -> perm_eq s t.
Proof.
move/permP=> Est; apply/allP=> x _ /=.
have Dx: pred1 x =1 preim f (pred1 (f x)) by move=> y /=; rewrite inj_eq.
by rewrite !(eq_count Dx) -!count_map Est.
Qed.
End EqMap.
Arguments mapP {T1 T2 f s y}.
Arguments subset_mapP {T1 T2}.
Lemma map_of_seq (T1 : eqType) T2 (s : seq T1) (fs : seq T2) (y0 : T2) :
{f | uniq s -> size fs = size s -> map f s = fs}.
Proof.
exists (fun x => nth y0 fs (index x s)) => uAs eq_sz.
apply/esym/(@eq_from_nth _ y0); rewrite ?size_map eq_sz // => i ltis.
by have x0 : T1 by [case: (s) ltis]; rewrite (nth_map x0) // index_uniq.
Qed.
Section MapComp.
Variable S T U : Type.
Lemma map_id (s : seq T) : map id s = s.
Proof. by elim: s => //= x s ->. Qed.
Lemma eq_map (f g : S -> T) : f =1 g -> map f =1 map g.
Proof. by move=> Ef; elim=> //= x s ->; rewrite Ef. Qed.
Lemma map_comp (f : T -> U) (g : S -> T) s : map (f \o g) s = map f (map g s).
Proof. by elim: s => //= x s ->. Qed.
Lemma mapK (f : S -> T) (g : T -> S) : cancel f g -> cancel (map f) (map g).
Proof. by move=> fK; elim=> //= x s ->; rewrite fK. Qed.
Lemma mapK_in (A : {pred S}) (f : S -> T) (g : T -> S) :
{in A, cancel f g} -> {in [pred s | all [in A] s], cancel (map f) (map g)}.
Proof. by move=> fK; elim=> //= x s IHs /andP[/fK-> /IHs->]. Qed.
End MapComp.
Lemma eq_in_map (S : eqType) T (f g : S -> T) (s : seq S) :
{in s, f =1 g} <-> map f s = map g s.
Proof.
elim: s => //= x s IHs; split=> [/forall_cons[-> ?]|]; first by rewrite IHs.1.
by move=> -[? ?]; apply/forall_cons; split=> [//|]; apply: IHs.2.
Qed.
Lemma map_id_in (T : eqType) f (s : seq T) : {in s, f =1 id} -> map f s = s.
Proof. by move/eq_in_map->; apply: map_id. Qed.
(* Map a partial function *)
Section Pmap.
Variables (aT rT : Type) (f : aT -> option rT) (g : rT -> aT).
Fixpoint pmap s :=
if s is x :: s' then let r := pmap s' in oapp (cons^~ r) r (f x) else [::].
Lemma map_pK : pcancel g f -> cancel (map g) pmap.
Proof. by move=> gK; elim=> //= x s ->; rewrite gK. Qed.
Lemma size_pmap s : size (pmap s) = count [eta f] s.
Proof. by elim: s => //= x s <-; case: (f _). Qed.
Lemma pmapS_filter s : map some (pmap s) = map f (filter [eta f] s).
Proof. by elim: s => //= x s; case fx: (f x) => //= [u] <-; congr (_ :: _). Qed.
Hypothesis fK : ocancel f g.
Lemma pmap_filter s : map g (pmap s) = filter [eta f] s.
Proof. by elim: s => //= x s <-; rewrite -{3}(fK x); case: (f _). Qed.
Lemma pmap_cat s t : pmap (s ++ t) = pmap s ++ pmap t.
Proof. by elim: s => //= x s ->; case/f: x. Qed.
Lemma all_pmap (p : pred rT) s :
all p (pmap s) = all [pred i | oapp p true (f i)] s.
Proof. by elim: s => //= x s <-; case: f. Qed.
End Pmap.
Lemma eq_in_pmap (aT : eqType) rT (f1 f2 : aT -> option rT) s :
{in s, f1 =1 f2} -> pmap f1 s = pmap f2 s.
Proof. by elim: s => //= a s IHs /forall_cons [-> /IHs ->]. Qed.
Lemma eq_pmap aT rT (f1 f2 : aT -> option rT) :
f1 =1 f2 -> pmap f1 =1 pmap f2.
Proof. by move=> Ef; elim => //= a s ->; rewrite Ef. Qed.
Section EqPmap.
Variables (aT rT : eqType) (f : aT -> option rT) (g : rT -> aT).
Lemma mem_pmap s u : (u \in pmap f s) = (Some u \in map f s).
Proof. by elim: s => //= x s IHs; rewrite in_cons -IHs; case: (f x). Qed.
Hypothesis fK : ocancel f g.
Lemma can2_mem_pmap : pcancel g f -> forall s u, (u \in pmap f s) = (g u \in s).
Proof.
by move=> gK s u; rewrite -(mem_map (pcan_inj gK)) pmap_filter // mem_filter gK.
Qed.
Lemma pmap_uniq s : uniq s -> uniq (pmap f s).
Proof. move/(filter_uniq f); rewrite -(pmap_filter fK); exact: map_uniq. Qed.
Lemma perm_pmap s t : perm_eq s t -> perm_eq (pmap f s) (pmap f t).
Proof.
move=> eq_st; apply/(perm_map_inj Some_inj); rewrite !pmapS_filter.
exact/perm_map/perm_filter.
Qed.
End EqPmap.
Section PmapSub.
Variables (T : Type) (p : pred T) (sT : subType p).
Lemma size_pmap_sub s : size (pmap (insub : T -> option sT) s) = count p s.
Proof. by rewrite size_pmap (eq_count (isSome_insub _)). Qed.
End PmapSub.
Section EqPmapSub.
Variables (T : eqType) (p : pred T) (sT : subEqType p).
Let insT : T -> option sT := insub.
Lemma mem_pmap_sub s u : (u \in pmap insT s) = (val u \in s).
Proof. exact/(can2_mem_pmap (insubK _))/valK. Qed.
Lemma pmap_sub_uniq s : uniq s -> uniq (pmap insT s).
Proof. exact: (pmap_uniq (insubK _)). Qed.
End EqPmapSub.
(* Index sequence *)
Fixpoint iota m n := if n is n'.+1 then m :: iota m.+1 n' else [::].
Lemma size_iota m n : size (iota m n) = n.
Proof. by elim: n m => //= n IHn m; rewrite IHn. Qed.
Lemma iotaD m n1 n2 : iota m (n1 + n2) = iota m n1 ++ iota (m + n1) n2.
Proof. by elim: n1 m => [|n1 IHn1] m; rewrite ?addn0 // -addSnnS /= -IHn1. Qed.
Lemma iotaDl m1 m2 n : iota (m1 + m2) n = map (addn m1) (iota m2 n).
Proof. by elim: n m2 => //= n IHn m2; rewrite -addnS IHn. Qed.
Lemma nth_iota p m n i : i < n -> nth p (iota m n) i = m + i.
Proof.
by move/subnKC <-; rewrite addSnnS iotaD nth_cat size_iota ltnn subnn.
Qed.
Lemma mem_iota m n i : (i \in iota m n) = (m <= i < m + n).
Proof.
elim: n m => [|n IHn] /= m; first by rewrite addn0 ltnNge andbN.
by rewrite in_cons IHn addnS ltnS; case: ltngtP => // ->; rewrite leq_addr.
Qed.
Lemma iota_uniq m n : uniq (iota m n).
Proof. by elim: n m => //= n IHn m; rewrite mem_iota ltnn /=. Qed.
Lemma take_iota k m n : take k (iota m n) = iota m (minn k n).
Proof.
have [lt_k_n|le_n_k] := ltnP.
by elim: k n lt_k_n m => [|k IHk] [|n] //= H m; rewrite IHk.
by apply: take_oversize; rewrite size_iota.
Qed.
Lemma drop_iota k m n : drop k (iota m n) = iota (m + k) (n - k).
Proof.
by elim: k m n => [|k IHk] m [|n] //=; rewrite ?addn0 // IHk addnS subSS.
Qed.
Lemma filter_iota_ltn m n j : j <= n ->
[seq i <- iota m n | i < m + j] = iota m j.
Proof.
elim: n m j => [m j|n IHn m [|j] jlen]; first by rewrite leqn0 => /eqP ->.
rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => i.
by rewrite addn0 ltnNge mem_iota => /andP[->].
by rewrite /= addnS leq_addr -addSn IHn.
Qed.
Lemma filter_iota_leq n m j : j < n ->
[seq i <- iota m n | i <= m + j] = iota m j.+1.
Proof.
elim: n m j => [//|n IHn] m [|j] jlen /=; rewrite leq_addr.
rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => i.
by rewrite addn0 leqNgt mem_iota => /andP[->].
by rewrite addnS -addSn IHn -1?ltnS.
Qed.
(* Making a sequence of a specific length, using indexes to compute items. *)
Section MakeSeq.
Variables (T : Type) (x0 : T).
Definition mkseq f n : seq T := map f (iota 0 n).
Lemma size_mkseq f n : size (mkseq f n) = n.
Proof. by rewrite size_map size_iota. Qed.
Lemma mkseqS f n :
mkseq f n.+1 = rcons (mkseq f n) (f n).
Proof. by rewrite /mkseq -addn1 iotaD add0n map_cat cats1. Qed.
Lemma eq_mkseq f g : f =1 g -> mkseq f =1 mkseq g.
Proof. by move=> Efg n; apply: eq_map Efg _. Qed.
Lemma nth_mkseq f n i : i < n -> nth x0 (mkseq f n) i = f i.
Proof. by move=> Hi; rewrite (nth_map 0) ?nth_iota ?size_iota. Qed.
Lemma mkseq_nth s : mkseq (nth x0 s) (size s) = s.
Proof.
by apply: (@eq_from_nth _ x0); rewrite size_mkseq // => i Hi; rewrite nth_mkseq.
Qed.
Variant mkseq_spec s : seq T -> Type :=
| MapIota n f : s = mkseq f n -> mkseq_spec s (mkseq f n).
Lemma mkseqP s : mkseq_spec s s.
Proof. by rewrite -[s]mkseq_nth; constructor. Qed.
Lemma map_nth_iota0 s i :
i <= size s -> [seq nth x0 s j | j <- iota 0 i] = take i s.
Proof.
by move=> ile; rewrite -[s in RHS]mkseq_nth -map_take take_iota (minn_idPl _).
Qed.
Lemma map_nth_iota s i j : j <= size s - i ->
[seq nth x0 s k | k <- iota i j] = take j (drop i s).
Proof.
elim: i => [|i IH] in s j *; first by rewrite subn0 drop0 => /map_nth_iota0->.
case: s => [|x s /IH<-]; first by rewrite leqn0 => /eqP->.
by rewrite -add1n iotaDl -map_comp.
Qed.
End MakeSeq.
Section MakeEqSeq.
Variable T : eqType.
Lemma mkseq_uniqP (f : nat -> T) n :
reflect {in gtn n &, injective f} (uniq (mkseq f n)).
Proof.
apply: (equivP (uniqP (f 0))); rewrite size_mkseq.
by split=> injf i j lti ltj; have:= injf i j lti ltj; rewrite !nth_mkseq.
Qed.
Lemma mkseq_uniq (f : nat -> T) n : injective f -> uniq (mkseq f n).
Proof. by move/map_inj_uniq->; apply: iota_uniq. Qed.
Lemma perm_iotaP {s t : seq T} x0 (It := iota 0 (size t)) :
reflect (exists2 Is, perm_eq Is It & s = map (nth x0 t) Is) (perm_eq s t).
Proof.
apply: (iffP idP) => [Est | [Is eqIst ->]]; last first.
by rewrite -{2}[t](mkseq_nth x0) perm_map.
elim: t => [|x t IHt] in s It Est *.
by rewrite (perm_small_eq _ Est) //; exists [::].
have /rot_to[k s1 Ds]: x \in s by rewrite (perm_mem Est) mem_head.
have [|Is1 eqIst1 Ds1] := IHt s1; first by rewrite -(perm_cons x) -Ds perm_rot.
exists (rotr k (0 :: map succn Is1)).
by rewrite perm_rot /It /= perm_cons (iotaDl 1) perm_map.
by rewrite map_rotr /= -map_comp -(@eq_map _ _ (nth x0 t)) // -Ds1 -Ds rotK.
Qed.
End MakeEqSeq.
Arguments perm_iotaP {T s t}.
Section FoldRight.
Variables (T : Type) (R : Type) (f : T -> R -> R) (z0 : R).
Fixpoint foldr s := if s is x :: s' then f x (foldr s') else z0.
End FoldRight.
Section FoldRightComp.
Variables (T1 T2 : Type) (h : T1 -> T2).
Variables (R : Type) (f : T2 -> R -> R) (z0 : R).
Lemma foldr_cat s1 s2 : foldr f z0 (s1 ++ s2) = foldr f (foldr f z0 s2) s1.
Proof. by elim: s1 => //= x s1 ->. Qed.
Lemma foldr_rcons s x : foldr f z0 (rcons s x) = foldr f (f x z0) s.
Proof. by rewrite -cats1 foldr_cat. Qed.
Lemma foldr_map s : foldr f z0 (map h s) = foldr (fun x z => f (h x) z) z0 s.
Proof. by elim: s => //= x s ->. Qed.
End FoldRightComp.
(* Quick characterization of the null sequence. *)
Definition sumn := foldr addn 0.
Lemma sumn_ncons x n s : sumn (ncons n x s) = x * n + sumn s.
Proof. by rewrite mulnC; elim: n => //= n ->; rewrite addnA. Qed.
Lemma sumn_nseq x n : sumn (nseq n x) = x * n.
Proof. by rewrite sumn_ncons addn0. Qed.
Lemma sumn_cat s1 s2 : sumn (s1 ++ s2) = sumn s1 + sumn s2.
Proof. by elim: s1 => //= x s1 ->; rewrite addnA. Qed.
Lemma sumn_count T (a : pred T) s : sumn [seq a i : nat | i <- s] = count a s.
Proof. by elim: s => //= s0 s /= ->. Qed.
Lemma sumn_rcons s n : sumn (rcons s n) = sumn s + n.
Proof. by rewrite -cats1 sumn_cat /= addn0. Qed.
Lemma perm_sumn s1 s2 : perm_eq s1 s2 -> sumn s1 = sumn s2.
Proof.
by apply/catCA_perm_subst: s1 s2 => s1 s2 s3; rewrite !sumn_cat addnCA.
Qed.
Lemma sumn_rot s n : sumn (rot n s) = sumn s.
Proof. by apply/perm_sumn; rewrite perm_rot. Qed.
Lemma sumn_rev s : sumn (rev s) = sumn s.
Proof. by apply/perm_sumn; rewrite perm_rev. Qed.
Lemma natnseq0P s : reflect (s = nseq (size s) 0) (sumn s == 0).
Proof.
apply: (iffP idP) => [|->]; last by rewrite sumn_nseq.
by elim: s => //= x s IHs; rewrite addn_eq0 => /andP[/eqP-> /IHs <-].
Qed.
Lemma sumn_set_nth s x0 n x :
sumn (set_nth x0 s n x) =
sumn s + x - (nth x0 s n) * (n < size s) + x0 * (n - size s).
Proof.
rewrite set_nthE; case: ltnP => [nlts|nges]; last first.
by rewrite sumn_cat sumn_ncons /= addn0 muln0 subn0 addnAC addnA.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
rewrite -[in sumn s](cat_take_drop n s) [drop n s](drop_nth x0)//.
by rewrite !sumn_cat /= muln1 muln0 addn0 addnAC !addnA [in RHS]addnAC addnK.
Qed.
Lemma sumn_set_nth_ltn s x0 n x : n < size s ->
sumn (set_nth x0 s n x) = sumn s + x - nth x0 s n.
Proof.
move=> nlts; rewrite sumn_set_nth nlts muln1.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
by rewrite muln0 addn0.
Qed.
Lemma sumn_set_nth0 s n x : sumn (set_nth 0 s n x) = sumn s + x - nth 0 s n.
Proof.
rewrite sumn_set_nth mul0n addn0.
by case: ltnP => [_|nges]; rewrite ?muln1// nth_default.
Qed.
Section FoldLeft.
Variables (T R : Type) (f : R -> T -> R).
Fixpoint foldl z s := if s is x :: s' then foldl (f z x) s' else z.
Lemma foldl_rev z s : foldl z (rev s) = foldr (fun x z => f z x) z s.
Proof.
by elim/last_ind: s z => // s x IHs z; rewrite rev_rcons -cats1 foldr_cat -IHs.
Qed.
Lemma foldl_cat z s1 s2 : foldl z (s1 ++ s2) = foldl (foldl z s1) s2.
Proof.
by rewrite -(revK (s1 ++ s2)) foldl_rev rev_cat foldr_cat -!foldl_rev !revK.
Qed.
Lemma foldl_rcons z s x : foldl z (rcons s x) = f (foldl z s) x.
Proof. by rewrite -cats1 foldl_cat. Qed.
End FoldLeft.
Section Folds.
Variables (T : Type) (f : T -> T -> T).
Hypotheses (fA : associative f) (fC : commutative f).
Lemma foldl_foldr x0 l : foldl f x0 l = foldr f x0 l.
Proof.
elim: l x0 => [//|x1 l IHl] x0 /=; rewrite {}IHl.
by elim: l x0 x1 => [//|x2 l IHl] x0 x1 /=; rewrite IHl !fA [f x2 x1]fC.
Qed.
End Folds.
Section Scan.
Variables (T1 : Type) (x1 : T1) (T2 : Type) (x2 : T2).
Variables (f : T1 -> T1 -> T2) (g : T1 -> T2 -> T1).
Fixpoint pairmap x s := if s is y :: s' then f x y :: pairmap y s' else [::].
Lemma size_pairmap x s : size (pairmap x s) = size s.
Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed.
Lemma pairmap_cat x s1 s2 :
pairmap x (s1 ++ s2) = pairmap x s1 ++ pairmap (last x s1) s2.
Proof. by elim: s1 x => //= y s1 IHs1 x; rewrite IHs1. Qed.
Lemma nth_pairmap s n : n < size s ->
forall x, nth x2 (pairmap x s) n = f (nth x1 (x :: s) n) (nth x1 s n).
Proof. by elim: s n => [|y s IHs] [|n] //= Hn x; apply: IHs. Qed.
Fixpoint scanl x s :=
if s is y :: s' then let x' := g x y in x' :: scanl x' s' else [::].
Lemma size_scanl x s : size (scanl x s) = size s.
Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed.
Lemma scanl_cat x s1 s2 :
scanl x (s1 ++ s2) = scanl x s1 ++ scanl (foldl g x s1) s2.
Proof. by elim: s1 x => //= y s1 IHs1 x; rewrite IHs1. Qed.
Lemma scanl_rcons x s1 y :
scanl x (rcons s1 y) = rcons (scanl x s1) (foldl g x (rcons s1 y)).
Proof. by rewrite -!cats1 scanl_cat foldl_cat. Qed.
Lemma nth_cons_scanl s n : n <= size s ->
forall x, nth x1 (x :: scanl x s) n = foldl g x (take n s).
Proof. by elim: s n => [|y s IHs] [|n] Hn x //=; rewrite IHs. Qed.
Lemma nth_scanl s n : n < size s ->
forall x, nth x1 (scanl x s) n = foldl g x (take n.+1 s).
Proof. by move=> n_lt x; rewrite -nth_cons_scanl. Qed.
Lemma scanlK :
(forall x, cancel (g x) (f x)) -> forall x, cancel (scanl x) (pairmap x).
Proof. by move=> Hfg x s; elim: s x => //= y s IHs x; rewrite Hfg IHs. Qed.
Lemma pairmapK :
(forall x, cancel (f x) (g x)) -> forall x, cancel (pairmap x) (scanl x).
Proof. by move=> Hgf x s; elim: s x => //= y s IHs x; rewrite Hgf IHs. Qed.
End Scan.
Prenex Implicits mask map pmap foldr foldl scanl pairmap.
Section Zip.
Variables (S T : Type) (r : S -> T -> bool).
Fixpoint zip (s : seq S) (t : seq T) {struct t} :=
match s, t with
| x :: s', y :: t' => (x, y) :: zip s' t'
| _, _ => [::]
end.
Definition unzip1 := map (@fst S T).
Definition unzip2 := map (@snd S T).
Fixpoint all2 s t :=
match s, t with
| [::], [::] => true
| x :: s, y :: t => r x y && all2 s t
| _, _ => false
end.
Lemma zip_unzip s : zip (unzip1 s) (unzip2 s) = s.
Proof. by elim: s => [|[x y] s /= ->]. Qed.
Lemma unzip1_zip s t : size s <= size t -> unzip1 (zip s t) = s.
Proof. by elim: s t => [|x s IHs] [|y t] //= le_s_t; rewrite IHs. Qed.
Lemma unzip2_zip s t : size t <= size s -> unzip2 (zip s t) = t.
Proof. by elim: s t => [|x s IHs] [|y t] //= le_t_s; rewrite IHs. Qed.
Lemma size1_zip s t : size s <= size t -> size (zip s t) = size s.
Proof. by elim: s t => [|x s IHs] [|y t] //= Hs; rewrite IHs. Qed.
Lemma size2_zip s t : size t <= size s -> size (zip s t) = size t.
Proof. by elim: s t => [|x s IHs] [|y t] //= Hs; rewrite IHs. Qed.
Lemma size_zip s t : size (zip s t) = minn (size s) (size t).
Proof. by elim: s t => [|x s IHs] [|t2 t] //=; rewrite IHs minnSS. Qed.
Lemma zip_cat s1 s2 t1 t2 :
size s1 = size t1 -> zip (s1 ++ s2) (t1 ++ t2) = zip s1 t1 ++ zip s2 t2.
Proof. by move: s1 t1; apply: seq_ind2 => //= x y s1 t1 _ ->. Qed.
Lemma nth_zip x y s t i :
size s = size t -> nth (x, y) (zip s t) i = (nth x s i, nth y t i).
Proof. by elim: i s t => [|i IHi] [|y1 s1] [|y2 t] //= [/IHi->]. Qed.
Lemma nth_zip_cond p s t i :
nth p (zip s t) i
= (if i < size (zip s t) then (nth p.1 s i, nth p.2 t i) else p).
Proof.
rewrite size_zip ltnNge geq_min.
by elim: s t i => [|x s IHs] [|y t] [|i] //=; rewrite ?orbT -?IHs.
Qed.
Lemma zip_rcons s t x y :
size s = size t -> zip (rcons s x) (rcons t y) = rcons (zip s t) (x, y).
Proof. by move=> eq_sz; rewrite -!cats1 zip_cat //= eq_sz. Qed.
Lemma rev_zip s t : size s = size t -> rev (zip s t) = zip (rev s) (rev t).
Proof.
move: s t; apply: seq_ind2 => //= x y s t eq_sz IHs.
by rewrite !rev_cons IHs zip_rcons ?size_rev.
Qed.
Lemma all2E s t :
all2 s t = (size s == size t) && all [pred xy | r xy.1 xy.2] (zip s t).
Proof. by elim: s t => [|x s IHs] [|y t] //=; rewrite IHs andbCA. Qed.
Lemma zip_map I f g (s : seq I) :
zip (map f s) (map g s) = [seq (f i, g i) | i <- s].
Proof. by elim: s => //= i s ->. Qed.
Lemma unzip1_map_nth_zip x y s t l :
size s = size t ->
unzip1 [seq nth (x, y) (zip s t) i | i <- l] = [seq nth x s i | i <- l].
Proof. by move=> st; elim: l => [//=|n l IH /=]; rewrite nth_zip ?IH ?st. Qed.
Lemma unzip2_map_nth_zip x y s t l :
size s = size t ->
unzip2 [seq nth (x, y) (zip s t) i | i <- l] = [seq nth y t i | i <- l].
Proof. by move=> st; elim: l => [//=|n l IH /=]; rewrite nth_zip ?IH ?st. Qed.
End Zip.
Lemma zip_uniql (S T : eqType) (s : seq S) (t : seq T) :
uniq s -> uniq (zip s t).
Proof.
case: s t => [|s0 s] [|t0 t] //; apply: contraTT => /(uniqPn (s0, t0)) [i [j]].
case=> o z; rewrite !nth_zip_cond !ifT ?js ?(ltn_trans o)// => -[n _].
by apply/(uniqPn s0); exists i, j; rewrite o n (leq_trans z) ?size_zip?geq_minl.
Qed.
Lemma zip_uniqr (S T : eqType) (s : seq S) (t : seq T) :
uniq t -> uniq (zip s t).
Proof.
case: s t => [|s0 s] [|t0 t] //; apply: contraTT => /(uniqPn (s0, t0)) [i [j]].
case=> o z; rewrite !nth_zip_cond !ifT ?js ?(ltn_trans o)// => -[_ n].
by apply/(uniqPn t0); exists i, j; rewrite o n (leq_trans z) ?size_zip?geq_minr.
Qed.
Lemma perm_zip_sym (S T : eqType) (s1 s2 : seq S) (t1 t2 : seq T) :
perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq (zip t1 s1) (zip t2 s2).
Proof.
have swap t s : zip t s = map (fun u => (u.2, u.1)) (zip s t).
by elim: s t => [|x s +] [|y t]//= => ->.
by rewrite [zip t1 s1]swap [zip t2 s2]swap; apply: perm_map.
Qed.
Lemma perm_zip1 {S T : eqType} (t1 t2 : seq T) (s1 s2 : seq S):
size s1 = size t1 -> size s2 = size t2 ->
perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq s1 s2.
Proof.
wlog [x y] : s1 s2 t1 t2 / (S * T)%type => [hwlog|].
case: s2 t2 => [|x s2] [|y t2] //; last exact: hwlog.
by case: s1 t1 => [|u s1] [|v t1]//= _ _ /perm_nilP.
move=> eq1 eq2 /(perm_iotaP (x, y))[ns nsP /(congr1 (@unzip1 _ _))].
rewrite unzip1_zip ?unzip1_map_nth_zip -?eq1// => ->.
by apply/(perm_iotaP x); exists ns; rewrite // size_zip -eq2 minnn in nsP.
Qed.
Lemma perm_zip2 {S T : eqType} (s1 s2 : seq S) (t1 t2 : seq T) :
size s1 = size t1 -> size s2 = size t2 ->
perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq t1 t2.
Proof. by move=> ? ? ?; rewrite (@perm_zip1 _ _ s1 s2) 1?perm_zip_sym. Qed.
Prenex Implicits zip unzip1 unzip2 all2.
Lemma eqseq_all (T : eqType) (s t : seq T) : (s == t) = all2 eq_op s t.
Proof. by elim: s t => [|x s +] [|y t]//= => <-. Qed.
Lemma eq_map_all I (T : eqType) (f g : I -> T) (s : seq I) :
(map f s == map g s) = all [pred xy | xy.1 == xy.2] [seq (f i, g i) | i <- s].
Proof. by rewrite eqseq_all all2E !size_map eqxx zip_map. Qed.
Section Flatten.
Variable T : Type.
Implicit Types (s : seq T) (ss : seq (seq T)).
Definition flatten := foldr cat (Nil T).
Definition shape := map (@size T).
Fixpoint reshape sh s :=
if sh is n :: sh' then take n s :: reshape sh' (drop n s) else [::].
Definition flatten_index sh r c := sumn (take r sh) + c.
Definition reshape_index sh i := find (pred1 0) (scanl subn i.+1 sh).
Definition reshape_offset sh i := i - sumn (take (reshape_index sh i) sh).
Lemma size_flatten ss : size (flatten ss) = sumn (shape ss).
Proof. by elim: ss => //= s ss <-; rewrite size_cat. Qed.
Lemma flatten_cat ss1 ss2 : flatten (ss1 ++ ss2) = flatten ss1 ++ flatten ss2.
Proof. by elim: ss1 => //= s ss1 ->; rewrite catA. Qed.
Lemma size_reshape sh s : size (reshape sh s) = size sh.
Proof. by elim: sh s => //= s0 sh IHsh s; rewrite IHsh. Qed.
Lemma nth_reshape (sh : seq nat) l n :
nth [::] (reshape sh l) n = take (nth 0 sh n) (drop (sumn (take n sh)) l).
Proof.
elim: n sh l => [| n IHn] [| sh0 sh] l; rewrite ?take0 ?drop0 //=.
by rewrite addnC -drop_drop; apply: IHn.
Qed.
Lemma flattenK ss : reshape (shape ss) (flatten ss) = ss.
Proof.
by elim: ss => //= s ss IHss; rewrite take_size_cat ?drop_size_cat ?IHss.
Qed.
Lemma reshapeKr sh s : size s <= sumn sh -> flatten (reshape sh s) = s.
Proof.
elim: sh s => [[]|n sh IHsh] //= s sz_s; rewrite IHsh ?cat_take_drop //.
by rewrite size_drop leq_subLR.
Qed.
Lemma reshapeKl sh s : size s >= sumn sh -> shape (reshape sh s) = sh.
Proof.
elim: sh s => [[]|n sh IHsh] //= s sz_s.
rewrite size_takel; last exact: leq_trans (leq_addr _ _) sz_s.
by rewrite IHsh // -(leq_add2l n) size_drop -maxnE leq_max sz_s orbT.
Qed.
Lemma flatten_rcons ss s : flatten (rcons ss s) = flatten ss ++ s.
Proof. by rewrite -cats1 flatten_cat /= cats0. Qed.
Lemma flatten_seq1 s : flatten [seq [:: x] | x <- s] = s.
Proof. by elim: s => //= s0 s ->. Qed.
Lemma count_flatten ss P :
count P (flatten ss) = sumn [seq count P x | x <- ss].
Proof. by elim: ss => //= s ss IHss; rewrite count_cat IHss. Qed.
Lemma filter_flatten ss (P : pred T) :
filter P (flatten ss) = flatten [seq filter P i | i <- ss].
Proof. by elim: ss => // s ss /= <-; apply: filter_cat. Qed.
Lemma rev_flatten ss :
rev (flatten ss) = flatten (rev (map rev ss)).
Proof.
by elim: ss => //= s ss IHss; rewrite rev_cons flatten_rcons -IHss rev_cat.
Qed.
Lemma nth_shape ss i : nth 0 (shape ss) i = size (nth [::] ss i).
Proof.
rewrite /shape; case: (ltnP i (size ss)) => Hi; first exact: nth_map.
by rewrite !nth_default // size_map.
Qed.
Lemma shape_rev ss : shape (rev ss) = rev (shape ss).
Proof. exact: map_rev. Qed.
Lemma eq_from_flatten_shape ss1 ss2 :
flatten ss1 = flatten ss2 -> shape ss1 = shape ss2 -> ss1 = ss2.
Proof. by move=> Eflat Esh; rewrite -[LHS]flattenK Eflat Esh flattenK. Qed.
Lemma rev_reshape sh s :
size s = sumn sh -> rev (reshape sh s) = map rev (reshape (rev sh) (rev s)).
Proof.
move=> sz_s; apply/(canLR revK)/eq_from_flatten_shape.
rewrite reshapeKr ?sz_s // -rev_flatten reshapeKr ?revK //.
by rewrite size_rev sumn_rev sz_s.
transitivity (rev (shape (reshape (rev sh) (rev s)))).
by rewrite !reshapeKl ?revK ?size_rev ?sz_s ?sumn_rev.
rewrite shape_rev; congr (rev _); rewrite -[RHS]map_comp.
by under eq_map do rewrite /= size_rev.
Qed.
Lemma reshape_rcons s sh n (m := sumn sh) :
m + n = size s ->
reshape (rcons sh n) s = rcons (reshape sh (take m s)) (drop m s).
Proof.
move=> Dmn; apply/(can_inj revK); rewrite rev_reshape ?rev_rcons ?sumn_rcons //.
rewrite /= take_rev drop_rev -Dmn addnK revK -rev_reshape //.
by rewrite size_takel // -Dmn leq_addr.
Qed.
Lemma flatten_indexP sh r c :
c < nth 0 sh r -> flatten_index sh r c < sumn sh.
Proof.
move=> lt_c_sh; rewrite -[sh in sumn sh](cat_take_drop r) sumn_cat ltn_add2l.
suffices lt_r_sh: r < size sh by rewrite (drop_nth 0 lt_r_sh) ltn_addr.
by case: ltnP => // le_sh_r; rewrite nth_default in lt_c_sh.
Qed.
Lemma reshape_indexP sh i : i < sumn sh -> reshape_index sh i < size sh.
Proof.
rewrite /reshape_index; elim: sh => //= n sh IHsh in i *; rewrite subn_eq0.
by have [// | le_n_i] := ltnP i n; rewrite -leq_subLR subSn // => /IHsh.
Qed.
Lemma reshape_offsetP sh i :
i < sumn sh -> reshape_offset sh i < nth 0 sh (reshape_index sh i).
Proof.
rewrite /reshape_offset /reshape_index; elim: sh => //= n sh IHsh in i *.
rewrite subn_eq0; have [| le_n_i] := ltnP i n; first by rewrite subn0.
by rewrite -leq_subLR /= subnDA subSn // => /IHsh.
Qed.
Lemma reshape_indexK sh i :
flatten_index sh (reshape_index sh i) (reshape_offset sh i) = i.
Proof.
rewrite /reshape_offset /reshape_index /flatten_index -subSKn.
elim: sh => //= n sh IHsh in i *; rewrite subn_eq0; have [//|le_n_i] := ltnP.
by rewrite /= subnDA subSn // -addnA IHsh subnKC.
Qed.
Lemma flatten_indexKl sh r c :
c < nth 0 sh r -> reshape_index sh (flatten_index sh r c) = r.
Proof.
rewrite /reshape_index /flatten_index.
elim: sh r => [|n sh IHsh] [|r] //= lt_c_sh; first by rewrite ifT.
by rewrite -addnA -addnS addKn IHsh.
Qed.
Lemma flatten_indexKr sh r c :
c < nth 0 sh r -> reshape_offset sh (flatten_index sh r c) = c.
Proof.
rewrite /reshape_offset /reshape_index /flatten_index.
elim: sh r => [|n sh IHsh] [|r] //= lt_c_sh; first by rewrite ifT ?subn0.
by rewrite -addnA -addnS addKn /= subnDl IHsh.
Qed.
Lemma nth_flatten x0 ss i (r := reshape_index (shape ss) i) :
nth x0 (flatten ss) i = nth x0 (nth [::] ss r) (reshape_offset (shape ss) i).
Proof.
rewrite /reshape_offset -subSKn {}/r /reshape_index.
elim: ss => //= s ss IHss in i *; rewrite subn_eq0 nth_cat.
by have [//|le_s_i] := ltnP; rewrite subnDA subSn /=.
Qed.
Lemma reshape_leq sh i1 i2
(r1 := reshape_index sh i1) (c1 := reshape_offset sh i1)
(r2 := reshape_index sh i2) (c2 := reshape_offset sh i2) :
(i1 <= i2) = ((r1 < r2) || ((r1 == r2) && (c1 <= c2))).
Proof.
rewrite {}/r1 {}/c1 {}/r2 {}/c2 /reshape_offset /reshape_index.
elim: sh => [|s0 s IHs] /= in i1 i2 *; rewrite ?subn0 ?subn_eq0 //.
have [[] i1s0 [] i2s0] := (ltnP i1 s0, ltnP i2 s0); first by rewrite !subn0.
- by apply: leq_trans i2s0; apply/ltnW.
- by apply/negP => /(leq_trans i1s0); rewrite leqNgt i2s0.
by rewrite !subSn // !eqSS !ltnS !subnDA -IHs leq_subLR subnKC.
Qed.
End Flatten.
Prenex Implicits flatten shape reshape.
Lemma map_flatten S T (f : T -> S) ss :
map f (flatten ss) = flatten (map (map f) ss).
Proof. by elim: ss => // s ss /= <-; apply: map_cat. Qed.
Lemma flatten_map1 (S T : Type) (f : S -> T) s :
flatten [seq [:: f x] | x <- s] = map f s.
Proof. by elim: s => //= s0 s ->. Qed.
Lemma undup_flatten_nseq n (T : eqType) (s : seq T) : 0 < n ->
undup (flatten (nseq n s)) = undup s.
Proof.
elim: n => [|[|n]/= IHn]//= _; rewrite ?cats0// undup_cat {}IHn//.
rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => x.
by rewrite mem_undup mem_cat => ->.
Qed.
Lemma sumn_flatten (ss : seq (seq nat)) :
sumn (flatten ss) = sumn (map sumn ss).
Proof. by elim: ss => // s ss /= <-; apply: sumn_cat. Qed.
Lemma map_reshape T S (f : T -> S) sh s :
map (map f) (reshape sh s) = reshape sh (map f s).
Proof. by elim: sh s => //= sh0 sh IHsh s; rewrite map_take IHsh map_drop. Qed.
Section EqFlatten.
Variables S T : eqType.
Lemma flattenP (A : seq (seq T)) x :
reflect (exists2 s, s \in A & x \in s) (x \in flatten A).
Proof.
elim: A => /= [|s A IH_A]; [by right; case | rewrite mem_cat].
by apply: equivP (iff_sym exists_cons); apply: (orPP idP IH_A).
Qed.
Arguments flattenP {A x}.
Lemma flatten_mapP (A : S -> seq T) s y :
reflect (exists2 x, x \in s & y \in A x) (y \in flatten (map A s)).
Proof.
apply: (iffP flattenP) => [[_ /mapP[x sx ->]] | [x sx]] Axy; first by exists x.
by exists (A x); rewrite ?map_f.
Qed.
Lemma perm_flatten (ss1 ss2 : seq (seq T)) :
perm_eq ss1 ss2 -> perm_eq (flatten ss1) (flatten ss2).
Proof.
move=> eq_ss; apply/permP=> a; apply/catCA_perm_subst: ss1 ss2 eq_ss.
by move=> ss1 ss2 ss3; rewrite !flatten_cat !count_cat addnCA.
Qed.
End EqFlatten.
Arguments flattenP {T A x}.
Arguments flatten_mapP {S T A s y}.
Notation "[ 'seq' E | x <- s , y <- t ]" :=
(flatten [seq [seq E | y <- t] | x <- s])
(x binder, y binder,
format "[ '[hv' 'seq' E '/ ' | x <- s , '/ ' y <- t ] ']'")
: seq_scope.
Notation "[ 'seq' E : R | x <- s , y <- t ]" :=
(flatten [seq [seq E : R | y <- t] | x <- s])
(x binder, y binder, only parsing) : seq_scope.
Section PrefixSuffixInfix.
Variables T : eqType.
Implicit Type s : seq T.
Fixpoint prefix s1 s2 {struct s2} :=
if s1 isn't x :: s1' then true else
if s2 isn't y :: s2' then false else
(x == y) && prefix s1' s2'.
Lemma prefixE s1 s2 : prefix s1 s2 = (take (size s1) s2 == s1).
Proof. by elim: s2 s1 => [|y s2 +] [|x s1]//= => ->; rewrite eq_sym. Qed.
Lemma prefix_refl s : prefix s s. Proof. by rewrite prefixE take_size. Qed.
Lemma prefixs0 s : prefix s [::] = (s == [::]). Proof. by case: s. Qed.
Lemma prefix0s s : prefix [::] s. Proof. by case: s. Qed.
Lemma prefix_cons s1 s2 x y :
prefix (x :: s1) (y :: s2) = (x == y) && prefix s1 s2.
Proof. by []. Qed.
Lemma prefix_catr s1 s2 s1' s3 : size s1 = size s1' ->
prefix (s1 ++ s2) (s1' ++ s3) = (s1 == s1') && prefix s2 s3.
Proof.
elim: s1 s1' => [|x s1 IHs1] [|y s1']//= [eqs1].
by rewrite IHs1// eqseq_cons andbA.
Qed.
Lemma prefix_prefix s1 s2 : prefix s1 (s1 ++ s2).
Proof. by rewrite prefixE take_cat ltnn subnn take0 cats0. Qed.
Hint Resolve prefix_prefix : core.
Lemma prefixP {s1 s2} :
reflect (exists s2' : seq T, s2 = s1 ++ s2') (prefix s1 s2).
Proof.
apply: (iffP idP) => [|[{}s2 ->]]; last exact: prefix_prefix.
by rewrite prefixE => /eqP<-; exists (drop (size s1) s2); rewrite cat_take_drop.
Qed.
Lemma prefix_trans : transitive prefix.
Proof. by move=> _ s2 _ /prefixP[s1 ->] /prefixP[s3 ->]; rewrite -catA. Qed.
Lemma prefixs1 s x : prefix s [:: x] = (s == [::]) || (s == [:: x]).
Proof. by case: s => //= y s; rewrite prefixs0 eqseq_cons. Qed.
Lemma catl_prefix s1 s2 s3 : prefix (s1 ++ s3) s2 -> prefix s1 s2.
Proof. by move=> /prefixP [s2'] ->; rewrite -catA. Qed.
Lemma prefix_catl s1 s2 s3 : prefix s1 s2 -> prefix s1 (s2 ++ s3).
Proof. by move=> /prefixP [s2'] ->; rewrite -catA. Qed.
Lemma prefix_rcons s x : prefix s (rcons s x).
Proof. by rewrite -cats1 prefix_prefix. Qed.
Definition suffix s1 s2 := prefix (rev s1) (rev s2).
Lemma suffixE s1 s2 : suffix s1 s2 = (drop (size s2 - size s1) s2 == s1).
Proof. by rewrite /suffix prefixE take_rev (can_eq revK) size_rev. Qed.
Lemma suffix_refl s : suffix s s.
Proof. exact: prefix_refl. Qed.
Lemma suffixs0 s : suffix s [::] = (s == [::]).
Proof. by rewrite /suffix prefixs0 -!nilpE rev_nilp. Qed.
Lemma suffix0s s : suffix [::] s.
Proof. exact: prefix0s. Qed.
Lemma prefix_rev s1 s2 : prefix (rev s1) (rev s2) = suffix s1 s2.
Proof. by []. Qed.
Lemma prefix_revLR s1 s2 : prefix (rev s1) s2 = suffix s1 (rev s2).
Proof. by rewrite -prefix_rev revK. Qed.
Lemma suffix_rev s1 s2 : suffix (rev s1) (rev s2) = prefix s1 s2.
Proof. by rewrite -prefix_rev !revK. Qed.
Lemma suffix_revLR s1 s2 : suffix (rev s1) s2 = prefix s1 (rev s2).
Proof. by rewrite -prefix_rev revK. Qed.
Lemma suffix_suffix s1 s2 : suffix s2 (s1 ++ s2).
Proof. by rewrite /suffix rev_cat prefix_prefix. Qed.
Hint Resolve suffix_suffix : core.
Lemma suffixP {s1 s2} :
reflect (exists s2' : seq T, s2 = s2' ++ s1) (suffix s1 s2).
Proof.
apply: (iffP prefixP) => [[s2' rev_s2]|[s2' ->]]; exists (rev s2'); last first.
by rewrite rev_cat.
by rewrite -[s2]revK rev_s2 rev_cat revK.
Qed.
Lemma suffix_trans : transitive suffix.
Proof. by move=> _ s2 _ /suffixP[s1 ->] /suffixP[s3 ->]; rewrite catA. Qed.
Lemma suffix_rcons s1 s2 x y :
suffix (rcons s1 x) (rcons s2 y) = (x == y) && suffix s1 s2.
Proof. by rewrite /suffix 2!rev_rcons prefix_cons. Qed.
Lemma suffix_catl s1 s2 s3 s3' : size s3 = size s3' ->
suffix (s1 ++ s3) (s2 ++ s3') = (s3 == s3') && suffix s1 s2.
Proof.
by move=> eqs3; rewrite /suffix !rev_cat prefix_catr ?size_rev// (can_eq revK).
Qed.
Lemma suffix_catr s1 s2 s3 : suffix s1 s2 -> suffix s1 (s3 ++ s2).
Proof. by move=> /suffixP [s2'] ->; rewrite catA suffix_suffix. Qed.
Lemma catl_suffix s s1 s2 : suffix (s ++ s1) s2 -> suffix s1 s2.
Proof. by move=> /suffixP [s2'] ->; rewrite catA suffix_suffix. Qed.
Lemma suffix_cons s x : suffix s (x :: s).
Proof. by rewrite /suffix rev_cons prefix_rcons. Qed.
Fixpoint infix s1 s2 :=
if s2 is y :: s2' then prefix s1 s2 || infix s1 s2' else s1 == [::].
Fixpoint infix_index s1 s2 :=
if prefix s1 s2 then 0
else if s2 is y :: s2' then (infix_index s1 s2').+1 else 1.
Lemma infix0s s : infix [::] s. Proof. by case: s. Qed.
Lemma infixs0 s : infix s [::] = (s == [::]). Proof. by case: s. Qed.
Lemma infix_consl s1 y s2 :
infix s1 (y :: s2) = prefix s1 (y :: s2) || infix s1 s2.
Proof. by []. Qed.
Lemma infix_indexss s : infix_index s s = 0.
Proof. by case: s => //= x s; rewrite eqxx prefix_refl. Qed.
Lemma infix_index_le s1 s2 : infix_index s1 s2 <= (size s2).+1.
Proof. by elim: s2 => [|x s2'] /=; case: ifP. Qed.
Lemma infixTindex s1 s2 : (infix_index s1 s2 <= size s2) = infix s1 s2.
Proof. by elim: s2 s1 => [|y s2 +] [|x s1]//= => <-; case: ifP. Qed.
Lemma infixPn s1 s2 :
reflect (infix_index s1 s2 = (size s2).+1) (~~ infix s1 s2).
Proof.
rewrite -infixTindex -ltnNge; apply: (iffP idP) => [s2lt|->//].
by apply/eqP; rewrite eqn_leq s2lt infix_index_le.
Qed.
Lemma infix_index0s s : infix_index [::] s = 0.
Proof. by case: s. Qed.
Lemma infix_indexs0 s : infix_index s [::] = (s != [::]).
Proof. by case: s. Qed.
Lemma infixE s1 s2 : infix s1 s2 =
(take (size s1) (drop (infix_index s1 s2) s2) == s1).
Proof.
elim: s2 s1 => [|y s2 +] [|x s1]//= => -> /=.
by case: ifP => // /andP[/eqP-> ps1s2/=]; rewrite eqseq_cons -prefixE eqxx.
Qed.
Lemma infix_refl s : infix s s.
Proof. by rewrite infixE infix_indexss// drop0 take_size. Qed.
Lemma prefixW s1 s2 : prefix s1 s2 -> infix s1 s2.
Proof. by elim: s2 s1 => [|y s2 IHs2] [|x s1]//=->. Qed.
Lemma prefix_infix s1 s2 : infix s1 (s1 ++ s2).
Proof. exact: prefixW. Qed.
Hint Resolve prefix_infix : core.
Lemma infix_infix s1 s2 s3 : infix s2 (s1 ++ s2 ++ s3).
Proof. by elim: s1 => //= x s1 ->; rewrite orbT. Qed.
Hint Resolve infix_infix : core.
Lemma suffix_infix s1 s2 : infix s2 (s1 ++ s2).
Proof. by rewrite -[X in s1 ++ X]cats0. Qed.
Hint Resolve suffix_infix : core.
Lemma infixP {s1 s2} :
reflect (exists s s' : seq T, s2 = s ++ s1 ++ s') (infix s1 s2).
Proof.
apply: (iffP idP) => [|[p [s {s2}->]]]//=; rewrite infixE => /eqP<-.
set k := infix_index _ _; exists (take k s2), (drop (size s1 + k) s2).
by rewrite -drop_drop !cat_take_drop.
Qed.
Lemma infix_rev s1 s2 : infix (rev s1) (rev s2) = infix s1 s2.
Proof.
gen have sr : s1 s2 / infix s1 s2 -> infix (rev s1) (rev s2); last first.
by apply/idP/idP => /sr; rewrite ?revK.
by move=> /infixP[s [p ->]]; rewrite !rev_cat -catA.
Qed.
Lemma suffixW s1 s2 : suffix s1 s2 -> infix s1 s2.
Proof. by rewrite -infix_rev; apply: prefixW. Qed.
Lemma infix_trans : transitive infix.
Proof.
move=> s s1 s2 /infixP[s1p [s1s def_s]] /infixP[sp [ss def_s2]].
by apply/infixP; exists (sp ++ s1p),(s1s ++ ss); rewrite def_s2 def_s -!catA.
Qed.
Lemma infix_revLR s1 s2 : infix (rev s1) s2 = infix s1 (rev s2).
Proof. by rewrite -infix_rev revK. Qed.
Lemma infix_rconsl s1 s2 y :
infix s1 (rcons s2 y) = suffix s1 (rcons s2 y) || infix s1 s2.
Proof.
rewrite -infix_rev rev_rcons infix_consl.
by rewrite -rev_rcons prefix_rev infix_rev.
Qed.
Lemma infix_cons s x : infix s (x :: s).
Proof. by rewrite -cat1s suffix_infix. Qed.
Lemma infixs1 s x : infix s [:: x] = (s == [::]) || (s == [:: x]).
Proof. by rewrite infix_consl prefixs1 orbC orbA orbb. Qed.
Lemma catl_infix s s1 s2 : infix (s ++ s1) s2 -> infix s1 s2.
Proof. apply: infix_trans; exact/suffixW/suffix_suffix. Qed.
Lemma catr_infix s s1 s2 : infix (s1 ++ s) s2 -> infix s1 s2.
Proof.
by rewrite -infix_rev rev_cat => /catl_infix; rewrite infix_rev.
Qed.
Lemma cons2_infix s1 s2 x : infix (x :: s1) (x :: s2) -> infix s1 s2.
Proof.
by rewrite /= eqxx /= -cat1s => /orP[/prefixW//|]; exact: catl_infix.
Qed.
Lemma rcons2_infix s1 s2 x : infix (rcons s1 x) (rcons s2 x) -> infix s1 s2.
Proof. by rewrite -infix_rev !rev_rcons => /cons2_infix; rewrite infix_rev. Qed.
Lemma catr2_infix s s1 s2 : infix (s ++ s1) (s ++ s2) -> infix s1 s2.
Proof. by elim: s => //= x s IHs /cons2_infix. Qed.
Lemma catl2_infix s s1 s2 : infix (s1 ++ s) (s2 ++ s) -> infix s1 s2.
Proof. by rewrite -infix_rev !rev_cat => /catr2_infix; rewrite infix_rev. Qed.
Lemma infix_catl s1 s2 s3 : infix s1 s2 -> infix s1 (s3 ++ s2).
Proof. by move=> is12; apply: infix_trans is12 (suffix_infix _ _). Qed.
Lemma infix_catr s1 s2 s3 : infix s1 s2 -> infix s1 (s2 ++ s3).
Proof.
case: s3 => [|x s /infixP [p [sf]] ->]; first by rewrite cats0.
by rewrite -catA; apply: infix_catl; rewrite -catA prefix_infix.
Qed.
Lemma prefix_infix_trans s2 s1 s3 :
prefix s1 s2 -> infix s2 s3 -> infix s1 s3.
Proof. by move=> /prefixW/infix_trans; apply. Qed.
Lemma suffix_infix_trans s2 s1 s3 :
suffix s1 s2 -> infix s2 s3 -> infix s1 s3.
Proof. by move=> /suffixW/infix_trans; apply. Qed.
Lemma infix_prefix_trans s2 s1 s3 :
infix s1 s2 -> prefix s2 s3 -> infix s1 s3.
Proof. by move=> + /prefixW; apply: infix_trans. Qed.
Lemma infix_suffix_trans s2 s1 s3 :
infix s1 s2 -> suffix s2 s3 -> infix s1 s3.
Proof. by move=> + /suffixW; apply: infix_trans. Qed.
Lemma prefix_suffix_trans s2 s1 s3 :
prefix s1 s2 -> suffix s2 s3 -> infix s1 s3.
Proof. by move=> /prefixW + /suffixW +; apply: infix_trans. Qed.
Lemma suffix_prefix_trans s2 s1 s3 :
suffix s1 s2 -> prefix s2 s3 -> infix s1 s3.
Proof. by move=> /suffixW + /prefixW +; apply: infix_trans. Qed.
Lemma infixW s1 s2 : infix s1 s2 -> subseq s1 s2.
Proof.
move=> /infixP[sp [ss ->]].
exact: subseq_trans (prefix_subseq _ _) (suffix_subseq _ _).
Qed.
Lemma mem_infix s1 s2 : infix s1 s2 -> {subset s1 <= s2}.
Proof. by move=> /infixW subH; apply: mem_subseq. Qed.
Lemma infix1s s x : infix [:: x] s = (x \in s).
Proof. by elim: s => // x' s /= ->; rewrite in_cons prefix0s andbT. Qed.
Lemma prefix1s s x : prefix [:: x] s -> x \in s.
Proof. by rewrite -infix1s => /prefixW. Qed.
Lemma suffix1s s x : suffix [:: x] s -> x \in s.
Proof. by rewrite -infix1s => /suffixW. Qed.
Lemma infix_rcons s x : infix s (rcons s x).
Proof. by rewrite -cats1 prefix_infix. Qed.
Lemma infix_uniq s1 s2 : infix s1 s2 -> uniq s2 -> uniq s1.
Proof. by move=> /infixW /subseq_uniq subH. Qed.
Lemma prefix_uniq s1 s2 : prefix s1 s2 -> uniq s2 -> uniq s1.
Proof. by move=> /prefixW /infix_uniq preH. Qed.
Lemma suffix_uniq s1 s2 : suffix s1 s2 -> uniq s2 -> uniq s1.
Proof. by move=> /suffixW /infix_uniq preH. Qed.
Lemma prefix_take s i : prefix (take i s) s.
Proof. by rewrite -{2}[s](cat_take_drop i). Qed.
Lemma suffix_drop s i : suffix (drop i s) s.
Proof. by rewrite -{2}[s](cat_take_drop i). Qed.
Lemma infix_take s i : infix (take i s) s.
Proof. by rewrite prefixW // prefix_take. Qed.
Lemma prefix_drop_gt0 s i : ~~ prefix (drop i s) s -> i > 0.
Proof. by case: i => //=; rewrite drop0 ltnn prefix_refl. Qed.
Lemma infix_drop s i : infix (drop i s) s.
Proof. by rewrite -{2}[s](cat_take_drop i). Qed.
Lemma consr_infix s1 s2 x : infix (x :: s1) s2 -> infix [:: x] s2.
Proof. by rewrite -cat1s => /catr_infix. Qed.
Lemma consl_infix s1 s2 x : infix (x :: s1) s2 -> infix s1 s2.
Proof. by rewrite -cat1s => /catl_infix. Qed.
Lemma prefix_index s1 s2 : prefix s1 s2 -> infix_index s1 s2 = 0.
Proof. by case: s1 s2 => [|x s1] [|y s2] //= ->. Qed.
Lemma size_infix s1 s2 : infix s1 s2 -> size s1 <= size s2.
Proof. by move=> /infixW; apply: size_subseq. Qed.
Lemma size_prefix s1 s2 : prefix s1 s2 -> size s1 <= size s2.
Proof. by move=> /prefixW; apply: size_infix. Qed.
Lemma size_suffix s1 s2 : suffix s1 s2 -> size s1 <= size s2.
Proof. by move=> /suffixW; apply: size_infix. Qed.
End PrefixSuffixInfix.
Section AllPairsDep.
Variables (S S' : Type) (T T' : S -> Type) (R : Type).
Implicit Type f : forall x, T x -> R.
Definition allpairs_dep f s t := [seq f x y | x <- s, y <- t x].
Lemma size_allpairs_dep f s t :
size [seq f x y | x <- s, y <- t x] = sumn [seq size (t x) | x <- s].
Proof. by elim: s => //= x s IHs; rewrite size_cat size_map IHs. Qed.
Lemma allpairs0l f t : [seq f x y | x <- [::], y <- t x] = [::].
Proof. by []. Qed.
Lemma allpairs0r f s : [seq f x y | x <- s, y <- [::]] = [::].
Proof. by elim: s. Qed.
Lemma allpairs1l f x t :
[seq f x y | x <- [:: x], y <- t x] = [seq f x y | y <- t x].
Proof. exact: cats0. Qed.
Lemma allpairs1r f s y :
[seq f x y | x <- s, y <- [:: y x]] = [seq f x (y x) | x <- s].
Proof. exact: flatten_map1. Qed.
Lemma allpairs_cons f x s t :
[seq f x y | x <- x :: s, y <- t x] =
[seq f x y | y <- t x] ++ [seq f x y | x <- s, y <- t x].
Proof. by []. Qed.
Lemma eq_allpairs (f1 f2 : forall x, T x -> R) s t :
(forall x, f1 x =1 f2 x) ->
[seq f1 x y | x <- s, y <- t x] = [seq f2 x y | x <- s, y <- t x].
Proof. by move=> eq_f; under eq_map do under eq_map do rewrite eq_f. Qed.
Lemma eq_allpairsr (f : forall x, T x -> R) s t1 t2 : (forall x, t1 x = t2 x) ->
[seq f x y | x <- s, y <- t1 x] = [seq f x y | x <- s, y <- t2 x].
Proof. by move=> eq_t; under eq_map do rewrite eq_t. Qed.
Lemma allpairs_cat f s1 s2 t :
[seq f x y | x <- s1 ++ s2, y <- t x] =
[seq f x y | x <- s1, y <- t x] ++ [seq f x y | x <- s2, y <- t x].
Proof. by rewrite map_cat flatten_cat. Qed.
Lemma allpairs_rcons f x s t :
[seq f x y | x <- rcons s x, y <- t x] =
[seq f x y | x <- s, y <- t x] ++ [seq f x y | y <- t x].
Proof. by rewrite -cats1 allpairs_cat allpairs1l. Qed.
Lemma allpairs_mapl f (g : S' -> S) s t :
[seq f x y | x <- map g s, y <- t x] = [seq f (g x) y | x <- s, y <- t (g x)].
Proof. by rewrite -map_comp. Qed.
Lemma allpairs_mapr f (g : forall x, T' x -> T x) s t :
[seq f x y | x <- s, y <- map (g x) (t x)] =
[seq f x (g x y) | x <- s, y <- t x].
Proof. by under eq_map do rewrite -map_comp. Qed.
End AllPairsDep.
Arguments allpairs_dep {S T R} f s t /.
Lemma map_allpairs S T R R' (g : R' -> R) f s t :
map g [seq f x y | x : S <- s, y : T x <- t x] =
[seq g (f x y) | x <- s, y <- t x].
Proof. by rewrite map_flatten allpairs_mapl allpairs_mapr. Qed.
Section AllPairsNonDep.
Variables (S T R : Type) (f : S -> T -> R).
Implicit Types (s : seq S) (t : seq T).
Definition allpairs s t := [seq f x y | x <- s, y <- t].
Lemma size_allpairs s t : size [seq f x y | x <- s, y <- t] = size s * size t.
Proof. by elim: s => //= x s IHs; rewrite size_cat size_map IHs. Qed.
End AllPairsNonDep.
Arguments allpairs {S T R} f s t /.
Section EqAllPairsDep.
Variables (S : eqType) (T : S -> eqType).
Implicit Types (R : eqType) (s : seq S) (t : forall x, seq (T x)).
Lemma allpairsPdep R (f : forall x, T x -> R) s t (z : R) :
reflect (exists x y, [/\ x \in s, y \in t x & z = f x y])
(z \in [seq f x y | x <- s, y <- t x]).
Proof.
apply: (iffP flatten_mapP); first by case=> x sx /mapP[y ty ->]; exists x, y.
by case=> x [y [sx ty ->]]; exists x; last apply: map_f.
Qed.
Variable R : eqType.
Implicit Type f : forall x, T x -> R.
Lemma allpairs_f_dep f s t x y :
x \in s -> y \in t x -> f x y \in [seq f x y | x <- s, y <- t x].
Proof. by move=> sx ty; apply/allpairsPdep; exists x, y. Qed.
Lemma eq_in_allpairs_dep f1 f2 s t :
{in s, forall x, {in t x, f1 x =1 f2 x}} <->
[seq f1 x y : R | x <- s, y <- t x] = [seq f2 x y | x <- s, y <- t x].
Proof.
split=> [eq_f | eq_fst x s_x].
by congr flatten; apply/eq_in_map=> x s_x; apply/eq_in_map/eq_f.
apply/eq_in_map; apply/eq_in_map: x s_x; apply/eq_from_flatten_shape => //.
by rewrite /shape -!map_comp; apply/eq_map=> x /=; rewrite !size_map.
Qed.
Lemma perm_allpairs_dep f s1 t1 s2 t2 :
perm_eq s1 s2 -> {in s1, forall x, perm_eq (t1 x) (t2 x)} ->
perm_eq [seq f x y | x <- s1, y <- t1 x] [seq f x y | x <- s2, y <- t2 x].
Proof.
elim: s1 s2 t1 t2 => [s2 t1 t2 |a s1 IH s2 t1 t2 perm_s2 perm_t1].
by rewrite perm_sym => /perm_nilP->.
have mem_a : a \in s2 by rewrite -(perm_mem perm_s2) inE eqxx.
rewrite -[s2](cat_take_drop (index a s2)).
rewrite allpairs_cat (drop_nth a) ?index_mem //= nth_index //=.
rewrite perm_sym perm_catC -catA perm_cat //; last first.
rewrite perm_catC -allpairs_cat.
rewrite -remE perm_sym IH // => [|x xI]; last first.
by apply: perm_t1; rewrite inE xI orbT.
by rewrite -(perm_cons a) (perm_trans perm_s2 (perm_to_rem _)).
have /perm_t1 : a \in a :: s1 by rewrite inE eqxx.
rewrite perm_sym; elim: (t2 a) (t1 a) => /= [s4|b s3 IH1 s4 perm_s4].
by rewrite perm_sym => /perm_nilP->.
have mem_b : b \in s4 by rewrite -(perm_mem perm_s4) inE eqxx.
rewrite -[s4](cat_take_drop (index b s4)).
rewrite map_cat /= (drop_nth b) ?index_mem //= nth_index //=.
rewrite perm_sym perm_catC /= perm_cons // perm_catC -map_cat.
rewrite -remE perm_sym IH1 // -(perm_cons b).
by apply: perm_trans perm_s4 (perm_to_rem _).
Qed.
Lemma mem_allpairs_dep f s1 t1 s2 t2 :
s1 =i s2 -> {in s1, forall x, t1 x =i t2 x} ->
[seq f x y | x <- s1, y <- t1 x] =i [seq f x y | x <- s2, y <- t2 x].
Proof.
move=> eq_s eq_t z; apply/allpairsPdep/allpairsPdep=> -[x [y [sx ty ->]]];
by exists x, y; rewrite -eq_s in sx *; rewrite eq_t in ty *.
Qed.
Lemma allpairs_uniq_dep f s t (st := [seq Tagged T y | x <- s, y <- t x]) :
let g (p : {x : S & T x}) : R := f (tag p) (tagged p) in
uniq s -> {in s, forall x, uniq (t x)} -> {in st &, injective g} ->
uniq [seq f x y | x <- s, y <- t x].
Proof.
move=> g Us Ut; rewrite -(map_allpairs g (existT T)) => /map_inj_in_uniq->{f g}.
elim: s Us => //= x s IHs /andP[s'x Us] in st Ut *; rewrite {st}cat_uniq.
rewrite {}IHs {Us}// ?andbT => [|x1 s_s1]; last exact/Ut/mem_behead.
have injT: injective (existT T x) by move=> y z /eqP; rewrite eq_Tagged => /eqP.
rewrite (map_inj_in_uniq (in2W injT)) {injT}Ut ?mem_head // has_sym has_map.
by apply: contra s'x => /hasP[y _ /allpairsPdep[z [_ [? _ /(congr1 tag)/=->]]]].
Qed.
End EqAllPairsDep.
Arguments allpairsPdep {S T R f s t z}.
Section MemAllPairs.
Variables (S : Type) (T : S -> Type) (R : eqType).
Implicit Types (f : forall x, T x -> R) (s : seq S).
Lemma perm_allpairs_catr f s t1 t2 :
perm_eql [seq f x y | x <- s, y <- t1 x ++ t2 x]
([seq f x y | x <- s, y <- t1 x] ++ [seq f x y | x <- s, y <- t2 x]).
Proof.
apply/permPl; rewrite perm_sym; elim: s => //= x s ihs.
by rewrite perm_catACA perm_cat ?map_cat.
Qed.
Lemma mem_allpairs_catr f s y0 t :
[seq f x y | x <- s, y <- y0 x ++ t x] =i
[seq f x y | x <- s, y <- y0 x] ++ [seq f x y | x <- s, y <- t x].
Proof. exact/perm_mem/permPl/perm_allpairs_catr. Qed.
Lemma perm_allpairs_consr f s y0 t :
perm_eql [seq f x y | x <- s, y <- y0 x :: t x]
([seq f x (y0 x) | x <- s] ++ [seq f x y | x <- s, y <- t x]).
Proof.
by apply/permPl; rewrite (perm_allpairs_catr _ _ (fun=> [:: _])) allpairs1r.
Qed.
Lemma mem_allpairs_consr f s t y0 :
[seq f x y | x <- s, y <- y0 x :: t x] =i
[seq f x (y0 x) | x <- s] ++ [seq f x y | x <- s, y <- t x].
Proof. exact/perm_mem/permPl/perm_allpairs_consr. Qed.
Lemma allpairs_rconsr f s y0 t :
perm_eql [seq f x y | x <- s, y <- rcons (t x) (y0 x)]
([seq f x y | x <- s, y <- t x] ++ [seq f x (y0 x) | x <- s]).
Proof.
apply/permPl; rewrite -(eq_allpairsr _ _ (fun=> cats1 _ _)).
by rewrite perm_allpairs_catr allpairs1r.
Qed.
Lemma mem_allpairs_rconsr f s t y0 :
[seq f x y | x <- s, y <- rcons (t x) (y0 x)] =i
([seq f x y | x <- s, y <- t x] ++ [seq f x (y0 x) | x <- s]).
Proof. exact/perm_mem/permPl/allpairs_rconsr. Qed.
End MemAllPairs.
Lemma all_allpairsP
(S : eqType) (T : S -> eqType) (R : Type)
(p : pred R) (f : forall x : S, T x -> R)
(s : seq S) (t : forall x : S, seq (T x)) :
reflect (forall (x : S) (y : T x), x \in s -> y \in t x -> p (f x y))
(all p [seq f x y | x <- s, y <- t x]).
Proof.
elim: s => [|x s IHs]; first by constructor.
rewrite /= all_cat all_map /preim.
apply/(iffP andP)=> [[/allP /= ? ? x' y x'_in_xs]|p_xs_t].
by move: x'_in_xs y => /[1!inE] /predU1P [-> //|? ?]; exact: IHs.
split; first by apply/allP => ?; exact/p_xs_t/mem_head.
by apply/IHs => x' y x'_in_s; apply: p_xs_t; rewrite inE x'_in_s orbT.
Qed.
Arguments all_allpairsP {S T R p f s t}.
Section EqAllPairs.
Variables S T R : eqType.
Implicit Types (f : S -> T -> R) (s : seq S) (t : seq T).
Lemma allpairsP f s t (z : R) :
reflect (exists p, [/\ p.1 \in s, p.2 \in t & z = f p.1 p.2])
(z \in [seq f x y | x <- s, y <- t]).
Proof.
by apply: (iffP allpairsPdep) => [[x[y]]|[[x y]]]; [exists (x, y)|exists x, y].
Qed.
Lemma allpairs_f f s t x y :
x \in s -> y \in t -> f x y \in [seq f x y | x <- s, y <- t].
Proof. exact: allpairs_f_dep. Qed.
Lemma eq_in_allpairs f1 f2 s t :
{in s & t, f1 =2 f2} <->
[seq f1 x y : R | x <- s, y <- t] = [seq f2 x y | x <- s, y <- t].
Proof.
split=> [eq_f | /eq_in_allpairs_dep-eq_f x y /eq_f/(_ y)//].
by apply/eq_in_allpairs_dep=> x /eq_f.
Qed.
Lemma perm_allpairs f s1 t1 s2 t2 :
perm_eq s1 s2 -> perm_eq t1 t2 ->
perm_eq [seq f x y | x <- s1, y <- t1] [seq f x y | x <- s2, y <- t2].
Proof. by move=> perm_s perm_t; apply: perm_allpairs_dep. Qed.
Lemma mem_allpairs f s1 t1 s2 t2 :
s1 =i s2 -> t1 =i t2 ->
[seq f x y | x <- s1, y <- t1] =i [seq f x y | x <- s2, y <- t2].
Proof. by move=> eq_s eq_t; apply: mem_allpairs_dep. Qed.
Lemma allpairs_uniq f s t (st := [seq (x, y) | x <- s, y <- t]) :
uniq s -> uniq t -> {in st &, injective (uncurry f)} ->
uniq [seq f x y | x <- s, y <- t].
Proof.
move=> Us Ut inj_f; rewrite -(map_allpairs (uncurry f) (@pair S T)) -/st.
rewrite map_inj_in_uniq // allpairs_uniq_dep {Us Ut st inj_f}//.
by apply: in2W => -[x1 y1] [x2 y2] /= [-> ->].
Qed.
End EqAllPairs.
Arguments allpairsP {S T R f s t z}.
Arguments perm_nilP {T s}.
Arguments perm_consP {T x s t}.
Section AllRel.
Variables (T S : Type) (r : T -> S -> bool).
Implicit Types (x : T) (y : S) (xs : seq T) (ys : seq S).
Definition allrel xs ys := all [pred x | all (r x) ys] xs.
Lemma allrel0l ys : allrel [::] ys. Proof. by []. Qed.
Lemma allrel0r xs : allrel xs [::]. Proof. by elim: xs. Qed.
Lemma allrel_consl x xs ys : allrel (x :: xs) ys = all (r x) ys && allrel xs ys.
Proof. by []. Qed.
Lemma allrel_consr xs y ys :
allrel xs (y :: ys) = all (r^~ y) xs && allrel xs ys.
Proof. exact: all_predI. Qed.
Lemma allrel_cons2 x y xs ys :
allrel (x :: xs) (y :: ys) =
[&& r x y, all (r x) ys, all (r^~ y) xs & allrel xs ys].
Proof. by rewrite /= allrel_consr -andbA. Qed.
Lemma allrel1l x ys : allrel [:: x] ys = all (r x) ys. Proof. exact: andbT. Qed.
Lemma allrel1r xs y : allrel xs [:: y] = all (r^~ y) xs.
Proof. by rewrite allrel_consr allrel0r andbT. Qed.
Lemma allrel_catl xs xs' ys :
allrel (xs ++ xs') ys = allrel xs ys && allrel xs' ys.
Proof. exact: all_cat. Qed.
Lemma allrel_catr xs ys ys' :
allrel xs (ys ++ ys') = allrel xs ys && allrel xs ys'.
Proof.
elim: ys => /= [|y ys ihys]; first by rewrite allrel0r.
by rewrite !allrel_consr ihys andbA.
Qed.
Lemma allrel_maskl m xs ys : allrel xs ys -> allrel (mask m xs) ys.
Proof.
by elim: m xs => [|[] m IHm] [|x xs] //= /andP [xys /IHm->]; rewrite ?xys.
Qed.
Lemma allrel_maskr m xs ys : allrel xs ys -> allrel xs (mask m ys).
Proof. by elim: xs => //= x xs IHxs /andP [/all_mask->]. Qed.
Lemma allrel_filterl a xs ys : allrel xs ys -> allrel (filter a xs) ys.
Proof. by rewrite filter_mask; apply: allrel_maskl. Qed.
Lemma allrel_filterr a xs ys : allrel xs ys -> allrel xs (filter a ys).
Proof. by rewrite filter_mask; apply: allrel_maskr. Qed.
Lemma allrel_allpairsE xs ys :
allrel xs ys = all id [seq r x y | x <- xs, y <- ys].
Proof. by elim: xs => //= x xs ->; rewrite all_cat all_map. Qed.
End AllRel.
Arguments allrel {T S} r xs ys : simpl never.
Arguments allrel0l {T S} r ys.
Arguments allrel0r {T S} r xs.
Arguments allrel_consl {T S} r x xs ys.
Arguments allrel_consr {T S} r xs y ys.
Arguments allrel1l {T S} r x ys.
Arguments allrel1r {T S} r xs y.
Arguments allrel_catl {T S} r xs xs' ys.
Arguments allrel_catr {T S} r xs ys ys'.
Arguments allrel_maskl {T S} r m xs ys.
Arguments allrel_maskr {T S} r m xs ys.
Arguments allrel_filterl {T S} r a xs ys.
Arguments allrel_filterr {T S} r a xs ys.
Arguments allrel_allpairsE {T S} r xs ys.
Notation all2rel r xs := (allrel r xs xs).
Lemma sub_in_allrel
{T S : Type} (P : {pred T}) (Q : {pred S}) (r r' : T -> S -> bool) :
{in P & Q, forall x y, r x y -> r' x y} ->
forall xs ys, all P xs -> all Q ys -> allrel r xs ys -> allrel r' xs ys.
Proof.
move=> rr' + ys; elim=> //= x xs IHxs /andP [Px Pxs] Qys.
rewrite !allrel_consl => /andP [+ {}/IHxs-> //]; rewrite andbT.
by elim: ys Qys => //= y ys IHys /andP [Qy Qys] /andP [/rr'-> // /IHys->].
Qed.
Lemma sub_allrel {T S : Type} (r r' : T -> S -> bool) :
(forall x y, r x y -> r' x y) ->
forall xs ys, allrel r xs ys -> allrel r' xs ys.
Proof.
by move=> rr' xs ys; apply/sub_in_allrel/all_predT/all_predT; apply: in2W.
Qed.
Lemma eq_in_allrel {T S : Type} (P : {pred T}) (Q : {pred S}) r r' :
{in P & Q, r =2 r'} ->
forall xs ys, all P xs -> all Q ys -> allrel r xs ys = allrel r' xs ys.
Proof.
move=> rr' xs ys Pxs Qys.
by apply/idP/idP; apply/sub_in_allrel/Qys/Pxs => ? ? ? ?; rewrite rr'.
Qed.
Lemma eq_allrel {T S : Type} (r r' : T -> S -> bool) :
r =2 r' -> allrel r =2 allrel r'.
Proof. by move=> rr' xs ys; apply/eq_in_allrel/all_predT/all_predT. Qed.
Lemma allrelC {T S : Type} (r : T -> S -> bool) xs ys :
allrel r xs ys = allrel (fun y => r^~ y) ys xs.
Proof. by elim: xs => [|x xs ih]; [elim: ys | rewrite allrel_consr -ih]. Qed.
Lemma allrel_mapl {T T' S : Type} (f : T' -> T) (r : T -> S -> bool) xs ys :
allrel r (map f xs) ys = allrel (fun x => r (f x)) xs ys.
Proof. exact: all_map. Qed.
Lemma allrel_mapr {T S S' : Type} (f : S' -> S) (r : T -> S -> bool) xs ys :
allrel r xs (map f ys) = allrel (fun x y => r x (f y)) xs ys.
Proof. by rewrite allrelC allrel_mapl allrelC. Qed.
Lemma allrelP {T S : eqType} {r : T -> S -> bool} {xs ys} :
reflect {in xs & ys, forall x y, r x y} (allrel r xs ys).
Proof. by rewrite allrel_allpairsE; exact: all_allpairsP. Qed.
Lemma allrelT {T S : Type} (xs : seq T) (ys : seq S) :
allrel (fun _ _ => true) xs ys = true.
Proof. by elim: xs => //= ? ?; rewrite allrel_consl all_predT. Qed.
Lemma allrel_relI {T S : Type} (r r' : T -> S -> bool) xs ys :
allrel (fun x y => r x y && r' x y) xs ys = allrel r xs ys && allrel r' xs ys.
Proof. by rewrite -all_predI; apply: eq_all => ?; rewrite /= -all_predI. Qed.
Lemma allrel_revl {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) :
allrel r (rev s1) s2 = allrel r s1 s2.
Proof. exact: all_rev. Qed.
Lemma allrel_revr {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) :
allrel r s1 (rev s2) = allrel r s1 s2.
Proof. by rewrite allrelC allrel_revl allrelC. Qed.
Lemma allrel_rev2 {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) :
allrel r (rev s1) (rev s2) = allrel r s1 s2.
Proof. by rewrite allrel_revr allrel_revl. Qed.
Lemma eq_allrel_meml {T : eqType} {S} (r : T -> S -> bool) (s1 s1' : seq T) s2 :
s1 =i s1' -> allrel r s1 s2 = allrel r s1' s2.
Proof. by move=> eqs1; apply: eq_all_r. Qed.
Lemma eq_allrel_memr {T} {S : eqType} (r : T -> S -> bool) s1 (s2 s2' : seq S) :
s2 =i s2' -> allrel r s1 s2 = allrel r s1 s2'.
Proof. by rewrite ![allrel _ s1 _]allrelC; apply: eq_allrel_meml. Qed.
Lemma eq_allrel_mem2 {T S : eqType} (r : T -> S -> bool)
(s1 s1' : seq T) (s2 s2' : seq S) :
s1 =i s1' -> s2 =i s2' -> allrel r s1 s2 = allrel r s1' s2'.
Proof. by move=> /eq_allrel_meml -> /eq_allrel_memr ->. Qed.
Section All2Rel.
Variable (T : nonPropType) (r : rel T).
Implicit Types (x y z : T) (xs : seq T).
Hypothesis (rsym : symmetric r).
Lemma all2rel1 x : all2rel r [:: x] = r x x.
Proof. by rewrite /allrel /= !andbT. Qed.
Lemma all2rel2 x y : all2rel r [:: x; y] = r x x && r y y && r x y.
Proof. by rewrite /allrel /= rsym; do 3 case: r. Qed.
Lemma all2rel_cons x xs :
all2rel r (x :: xs) = [&& r x x, all (r x) xs & all2rel r xs].
Proof.
rewrite allrel_cons2; congr andb; rewrite andbA -all_predI; congr andb.
by elim: xs => //= y xs ->; rewrite rsym andbb.
Qed.
End All2Rel.
Section Pairwise.
Variables (T : Type) (r : T -> T -> bool).
Implicit Types (x y : T) (xs ys : seq T).
Fixpoint pairwise xs : bool :=
if xs is x :: xs then all (r x) xs && pairwise xs else true.
Lemma pairwise_cons x xs : pairwise (x :: xs) = all (r x) xs && pairwise xs.
Proof. by []. Qed.
Lemma pairwise_cat xs ys :
pairwise (xs ++ ys) = [&& allrel r xs ys, pairwise xs & pairwise ys].
Proof. by elim: xs => //= x xs ->; rewrite all_cat -!andbA; bool_congr. Qed.
Lemma pairwise_rcons xs x :
pairwise (rcons xs x) = all (r^~ x) xs && pairwise xs.
Proof. by rewrite -cats1 pairwise_cat allrel1r andbT. Qed.
Lemma pairwise2 x y : pairwise [:: x; y] = r x y.
Proof. by rewrite /= !andbT. Qed.
Lemma pairwise_mask m xs : pairwise xs -> pairwise (mask m xs).
Proof.
by elim: m xs => [|[] m IHm] [|x xs] //= /andP [? ?]; rewrite ?IHm // all_mask.
Qed.
Lemma pairwise_filter a xs : pairwise xs -> pairwise (filter a xs).
Proof. by rewrite filter_mask; apply: pairwise_mask. Qed.
Lemma pairwiseP x0 xs :
reflect {in gtn (size xs) &, {homo nth x0 xs : i j / i < j >-> r i j}}
(pairwise xs).
Proof.
elim: xs => /= [|x xs IHxs]; first exact: (iffP idP).
apply: (iffP andP) => [[r_x_xs pxs] i j|Hnth]; rewrite -?topredE /= ?ltnS.
by case: i j => [|i] [|j] //= gti gtj ij; [exact/all_nthP | exact/IHxs].
split; last by apply/IHxs => // i j; apply/(Hnth i.+1 j.+1).
by apply/(all_nthP x0) => i gti; apply/(Hnth 0 i.+1).
Qed.
Lemma pairwise_all2rel :
reflexive r -> symmetric r -> forall xs, pairwise xs = all2rel r xs.
Proof.
by move=> r_refl r_sym; elim => //= x xs ->; rewrite all2rel_cons // r_refl.
Qed.
End Pairwise.
Arguments pairwise {T} r xs.
Arguments pairwise_cons {T} r x xs.
Arguments pairwise_cat {T} r xs ys.
Arguments pairwise_rcons {T} r xs x.
Arguments pairwise2 {T} r x y.
Arguments pairwise_mask {T r} m {xs}.
Arguments pairwise_filter {T r} a {xs}.
Arguments pairwiseP {T r} x0 {xs}.
Arguments pairwise_all2rel {T r} r_refl r_sym xs.
Lemma sub_in_pairwise {T : Type} (P : {pred T}) (r r' : rel T) :
{in P &, subrel r r'} ->
forall xs, all P xs -> pairwise r xs -> pairwise r' xs.
Proof.
move=> rr'; elim=> //= x xs IHxs /andP [Px Pxs] /andP [+ {}/IHxs->] //.
rewrite andbT; elim: xs Pxs => //= x' xs IHxs /andP [? ?] /andP [+ /IHxs->] //.
by rewrite andbT; apply: rr'.
Qed.
Lemma sub_pairwise {T : Type} (r r' : rel T) xs :
subrel r r' -> pairwise r xs -> pairwise r' xs.
Proof. by move=> rr'; apply/sub_in_pairwise/all_predT; apply: in2W. Qed.
Lemma eq_in_pairwise {T : Type} (P : {pred T}) (r r' : rel T) :
{in P &, r =2 r'} -> forall xs, all P xs -> pairwise r xs = pairwise r' xs.
Proof.
move=> rr' xs Pxs.
by apply/idP/idP; apply/sub_in_pairwise/Pxs => ? ? ? ?; rewrite rr'.
Qed.
Lemma eq_pairwise {T : Type} (r r' : rel T) :
r =2 r' -> pairwise r =i pairwise r'.
Proof. by move=> rr' xs; apply/eq_in_pairwise/all_predT. Qed.
Lemma pairwise_map {T T' : Type} (f : T' -> T) (r : rel T) xs :
pairwise r (map f xs) = pairwise (relpre f r) xs.
Proof. by elim: xs => //= x xs ->; rewrite all_map. Qed.
Lemma pairwise_relI {T : Type} (r r' : rel T) (s : seq T) :
pairwise [rel x y | r x y && r' x y] s = pairwise r s && pairwise r' s.
Proof. by elim: s => //= x s ->; rewrite andbACA all_predI. Qed.
Section EqPairwise.
Variables (T : eqType) (r : T -> T -> bool).
Implicit Types (xs ys : seq T).
Lemma subseq_pairwise xs ys : subseq xs ys -> pairwise r ys -> pairwise r xs.
Proof. by case/subseqP => m _ ->; apply: pairwise_mask. Qed.
Lemma uniq_pairwise xs : uniq xs = pairwise [rel x y | x != y] xs.
Proof.
elim: xs => //= x xs ->; congr andb; rewrite -has_pred1 -all_predC.
by elim: xs => //= x' xs ->; case: eqVneq.
Qed.
Lemma pairwise_uniq xs : irreflexive r -> pairwise r xs -> uniq xs.
Proof.
move=> r_irr; rewrite uniq_pairwise; apply/sub_pairwise => x y.
by apply: contraTneq => ->; rewrite r_irr.
Qed.
Lemma pairwise_eq : antisymmetric r ->
forall xs ys, pairwise r xs -> pairwise r ys -> perm_eq xs ys -> xs = ys.
Proof.
move=> r_asym; elim=> [|x xs IHxs] [|y ys] //=; try by move=> ? ? /perm_size.
move=> /andP [r_x_xs pxs] /andP [r_y_ys pys] eq_xs_ys.
move: (mem_head y ys) (mem_head x xs).
rewrite -(perm_mem eq_xs_ys) [x \in _](perm_mem eq_xs_ys) !inE.
case: eqVneq eq_xs_ys => /= [->|ne_xy] eq_xs_ys ys_x xs_y.
by rewrite (IHxs ys) // -(perm_cons x).
by case/eqP: ne_xy; apply: r_asym; rewrite (allP r_x_xs) ?(allP r_y_ys).
Qed.
Lemma pairwise_trans s : antisymmetric r ->
pairwise r s -> {in s & &, transitive r}.
Proof.
move=> /(_ _ _ _)/eqP r_anti + y x z => /pairwiseP-/(_ y) ltP ys xs zs.
have [-> //|neqxy] := eqVneq x y; have [-> //|neqzy] := eqVneq z y.
move=> lxy lyz; move: ys xs zs lxy neqxy lyz neqzy.
move=> /(nthP y)[j jlt <-] /(nthP y)[i ilt <-] /(nthP y)[k klt <-].
have [ltij|ltji|->] := ltngtP i j; last 2 first.
- by move=> leij; rewrite r_anti// leij ltP.
- by move=> lejj; rewrite r_anti// lejj.
move=> _ _; have [ltjk|ltkj|->] := ltngtP j k; last 2 first.
- by move=> lejk; rewrite r_anti// lejk ltP.
- by move=> lekk; rewrite r_anti// lekk.
by move=> _ _; apply: (ltP) => //; apply: ltn_trans ltjk.
Qed.
End EqPairwise.
Arguments subseq_pairwise {T r xs ys}.
Arguments uniq_pairwise {T} xs.
Arguments pairwise_uniq {T r xs}.
Arguments pairwise_eq {T r} r_asym {xs ys}.
Section Permutations.
Variable T : eqType.
Implicit Types (x : T) (s t : seq T) (bs : seq (T * nat)) (acc : seq (seq T)).
Fixpoint incr_tally bs x :=
if bs isn't b :: bs then [:: (x, 1)] else
if x == b.1 then (x, b.2.+1) :: bs else b :: incr_tally bs x.
Definition tally s := foldl incr_tally [::] s.
Definition wf_tally :=
[qualify a bs : seq (T * nat) | uniq (unzip1 bs) && (0 \notin unzip2 bs)].
Definition tally_seq bs := flatten [seq nseq b.2 b.1 | b <- bs].
Local Notation tseq := tally_seq.
Lemma size_tally_seq bs : size (tally_seq bs) = sumn (unzip2 bs).
Proof.
by rewrite size_flatten /shape -map_comp; under eq_map do rewrite /= size_nseq.
Qed.
Lemma tally_seqK : {in wf_tally, cancel tally_seq tally}.
Proof.
move=> bs /andP[]; elim: bs => [|[x [|n]] bs IHbs] //= /andP[bs'x Ubs] bs'0.
rewrite inE /tseq /tally /= -[n.+1]addn1 in bs'0 *.
elim: n 1 => /= [|n IHn] m; last by rewrite eqxx IHn addnS.
rewrite -{}[in RHS]IHbs {Ubs bs'0}// /tally /tally_seq add0n.
elim: bs bs'x [::] => [|[y n] bs IHbs] //= /[1!inE] /norP[y'x bs'x].
by elim: n => [|n IHn] bs1 /=; [rewrite IHbs | rewrite eq_sym ifN // IHn].
Qed.
Lemma incr_tallyP x : {homo incr_tally^~ x : bs / bs \in wf_tally}.
Proof.
move=> bs /andP[]; rewrite unfold_in.
elim: bs => [|[y [|n]] bs IHbs] //= /andP[bs'y Ubs] /[1!inE] /= bs'0.
have [<- | y'x] /= := eqVneq y; first by rewrite bs'y Ubs.
rewrite -andbA {}IHbs {Ubs bs'0}// andbT.
elim: bs bs'y => [|b bs IHbs] /=; rewrite inE ?y'x // => /norP[b'y bs'y].
by case: ifP => _; rewrite /= inE negb_or ?y'x // b'y IHbs.
Qed.
Lemma tallyP s : tally s \is a wf_tally.
Proof.
rewrite /tally; set bs := [::]; have: bs \in wf_tally by [].
by elim: s bs => //= x s IHs bs /(incr_tallyP x)/IHs.
Qed.
Lemma tallyK s : perm_eq (tally_seq (tally s)) s.
Proof.
rewrite -[s in perm_eq _ s]cats0 -[nil]/(tseq [::]) /tally.
elim: s [::] => //= x s IHs bs; rewrite {IHs}(permPl (IHs _)).
rewrite perm_sym -cat1s perm_catCA {s}perm_cat2l.
elim: bs => //= b bs IHbs; case: eqP => [-> | _] //=.
by rewrite -cat1s perm_catCA perm_cat2l.
Qed.
Lemma tallyEl s : perm_eq (unzip1 (tally s)) (undup s).
Proof.
have /andP[Ubs bs'0] := tallyP s; set bs := tally s in Ubs bs'0 *.
rewrite uniq_perm ?undup_uniq {Ubs}// => x.
rewrite mem_undup -(perm_mem (tallyK s)) -/bs.
elim: bs => [|[y [|m]] bs IHbs] //= in bs'0 *.
by rewrite inE IHbs // mem_cat mem_nseq.
Qed.
Lemma tallyE s : perm_eq (tally s) [seq (x, count_mem x s) | x <- undup s].
Proof.
have /andP[Ubs _] := tallyP s; pose b := [fun s x => (x, count_mem x (tseq s))].
suffices /permPl->: perm_eq (tally s) (map (b (tally s)) (unzip1 (tally s))).
congr perm_eq: (perm_map (b (tally s)) (tallyEl s)).
by under eq_map do rewrite /= (permP (tallyK s)).
elim: (tally s) Ubs => [|[x m] bs IH] //= /andP[bs'x /IH-IHbs {IH}].
rewrite /tseq /= -/(tseq _) count_cat count_nseq /= eqxx mul1n.
rewrite (count_memPn _) ?addn0 ?perm_cons; last first.
apply: contra bs'x; elim: {b IHbs}bs => //= b bs IHbs.
by rewrite mem_cat mem_nseq inE andbC; case: (_ == _).
congr perm_eq: IHbs; apply/eq_in_map=> y bs_y; congr (y, _).
by rewrite count_cat count_nseq /= (negPf (memPnC bs'x y bs_y)).
Qed.
Lemma perm_tally s1 s2 : perm_eq s1 s2 -> perm_eq (tally s1) (tally s2).
Proof.
move=> eq_s12; apply: (@perm_trans _ [seq (x, count_mem x s2) | x <- undup s1]).
by congr perm_eq: (tallyE s1); under eq_map do rewrite (permP eq_s12).
by rewrite (permPr (tallyE s2)); apply/perm_map/perm_undup/(perm_mem eq_s12).
Qed.
Lemma perm_tally_seq bs1 bs2 :
perm_eq bs1 bs2 -> perm_eq (tally_seq bs1) (tally_seq bs2).
Proof. by move=> Ebs12; rewrite perm_flatten ?perm_map. Qed.
Local Notation perm_tseq := perm_tally_seq.
Lemma perm_count_undup s :
perm_eq (flatten [seq nseq (count_mem x s) x | x <- undup s]) s.
Proof.
by rewrite -(permPr (tallyK s)) (permPr (perm_tseq (tallyE s))) /tseq -map_comp.
Qed.
Local Fixpoint cons_perms_ perms_rec (s : seq T) bs bs2 acc :=
if bs isn't b :: bs1 then acc else
if b isn't (x, m.+1) then cons_perms_ perms_rec s bs1 bs2 acc else
let acc_xs := perms_rec (x :: s) ((x, m) :: bs1 ++ bs2) acc in
cons_perms_ perms_rec s bs1 (b :: bs2) acc_xs.
Local Fixpoint perms_rec n s bs acc :=
if n isn't n.+1 then s :: acc else cons_perms_ (perms_rec n) s bs [::] acc.
Local Notation cons_perms n := (cons_perms_ (perms_rec n) [::]).
Definition permutations s := perms_rec (size s) [::] (tally s) [::].
Let permsP s : exists n bs,
[/\ permutations s = perms_rec n [::] bs [::],
size (tseq bs) == n, perm_eq (tseq bs) s & uniq (unzip1 bs)].
Proof.
have /andP[Ubs _] := tallyP s; exists (size s), (tally s).
by rewrite (perm_size (tallyK s)) tallyK.
Qed.
Local Notation bsCA := (permEl (perm_catCA _ [:: _] _)).
Let cons_permsE : forall n x bs bs1 bs2,
let cp := cons_perms n bs bs2 in let perms s := perms_rec n s bs1 [::] in
cp (perms [:: x]) = cp [::] ++ [seq rcons t x | t <- perms [::]].
Proof.
pose is_acc f := forall acc, f acc = f [::] ++ acc. (* f is accumulating. *)
have cpE: forall f & forall s bs, is_acc (f s bs), is_acc (cons_perms_ f _ _ _).
move=> s bs bs2 f fE acc; elim: bs => [|[x [|m]] bs IHbs] //= in s bs2 acc *.
by rewrite fE IHbs catA -IHbs.
have prE: is_acc (perms_rec _ _ _) by elim=> //= n IHn s bs; apply: cpE.
pose has_suffix f := forall s : seq T, f s = [seq t ++ s | t <- f [::]].
suffices prEs n bs: has_suffix (fun s => perms_rec n s bs [::]).
move=> n x bs bs1 bs2 /=; rewrite cpE // prEs.
by under eq_map do rewrite cats1.
elim: n bs => //= n IHn bs s; elim: bs [::] => [|[x [|m]] bs IHbs] //= bs1.
rewrite cpE // IHbs IHn [in RHS]cpE // [in RHS]IHn map_cat -map_comp.
by congr (_ ++ _); apply: eq_map => t /=; rewrite -catA.
Qed.
Lemma mem_permutations s t : (t \in permutations s) = perm_eq t s.
Proof.
have{s} [n [bs [-> Dn /permPr<- _]]] := permsP s.
elim: n => [|n IHn] /= in t bs Dn *.
by rewrite inE (nilP Dn); apply/eqP/perm_nilP.
rewrite -[bs in tseq bs]cats0 in Dn *; have x0 : T by case: (tseq _) Dn.
rewrite -[RHS](@andb_idl (last x0 t \in tseq bs)); last first.
case/lastP: t {IHn} => [|t x] Dt; first by rewrite -(perm_size Dt) in Dn.
by rewrite -[bs]cats0 -(perm_mem Dt) last_rcons mem_rcons mem_head.
elim: bs [::] => [|[x [|m]] bs IHbs] //= bs2 in Dn *.
rewrite cons_permsE -!cat_cons !mem_cat (mem_nseq m.+1) orbC andb_orl.
rewrite {}IHbs ?(perm_size (perm_tseq bsCA)) //= (permPr (perm_tseq bsCA)).
congr (_ || _); apply/mapP/andP=> [[t1 Dt1 ->] | [/eqP]].
by rewrite last_rcons perm_rcons perm_cons IHn in Dt1 *.
case/lastP: t => [_ /perm_size//|t y]; rewrite last_rcons perm_rcons => ->.
by rewrite perm_cons; exists t; rewrite ?IHn.
Qed.
Lemma permutations_uniq s : uniq (permutations s).
Proof.
have{s} [n [bs [-> Dn _ Ubs]]] := permsP s.
elim: n => //= n IHn in bs Dn Ubs *; rewrite -[bs]cats0 /unzip1 in Dn Ubs.
elim: bs [::] => [|[x [|m]] bs IHbs] //= bs2 in Dn Ubs *.
by case/andP: Ubs => _ /IHbs->.
rewrite /= cons_permsE cat_uniq has_sym andbCA andbC.
rewrite {}IHbs; first 1 last; first by rewrite (perm_size (perm_tseq bsCA)).
by rewrite (perm_uniq (perm_map _ bsCA)).
rewrite (map_inj_uniq (rcons_injl x)) {}IHn {Dn}//=.
have: x \notin unzip1 bs by apply: contraL Ubs; rewrite map_cat mem_cat => ->.
move: {bs2 m Ubs}(perms_rec n _ _ _) (_ :: bs2) => ts.
elim: bs => [|[y [|m]] bs IHbs] //= /[1!inE] bs2 /norP[x'y /IHbs//].
rewrite cons_permsE has_cat negb_or has_map => ->.
by apply/hasPn=> t _; apply: contra x'y => /mapP[t1 _ /rcons_inj[_ ->]].
Qed.
Notation perms := permutations.
Lemma permutationsE s :
0 < size s ->
perm_eq (perms s) [seq x :: t | x <- undup s, t <- perms (rem x s)].
Proof.
move=> nt_s; apply/uniq_perm=> [||t]; first exact: permutations_uniq.
apply/allpairs_uniq_dep=> [|x _|]; rewrite ?undup_uniq ?permutations_uniq //.
by case=> [_ _] [x t] _ _ [-> ->].
rewrite mem_permutations; apply/idP/allpairsPdep=> [Dt | [x [t1 []]]].
rewrite -(perm_size Dt) in nt_s; case: t nt_s => // x t _ in Dt *.
have s_x: x \in s by rewrite -(perm_mem Dt) mem_head.
exists x, t; rewrite mem_undup mem_permutations; split=> //.
by rewrite -(perm_cons x) (permPl Dt) perm_to_rem.
rewrite mem_undup mem_permutations -(perm_cons x) => s_x Dt1 ->.
by rewrite (permPl Dt1) perm_sym perm_to_rem.
Qed.
Lemma permutationsErot x s (le_x := fun t => iota 0 (index x t + 1)) :
perm_eq (perms (x :: s)) [seq rot i (x :: t) | t <- perms s, i <- le_x t].
Proof.
have take'x t i: i <= index x t -> i <= size t /\ x \notin take i t.
move=> le_i_x; have le_i_t: i <= size t := leq_trans le_i_x (index_size x t).
case: (nthP x) => // -[j lt_j_i /eqP]; rewrite size_takel // in lt_j_i.
by rewrite nth_take // [_ == _](before_find x (leq_trans lt_j_i le_i_x)).
pose xrot t i := rot i (x :: t); pose xrotV t := index x (rev (rot 1 t)).
have xrotK t: {in le_x t, cancel (xrot t) xrotV}.
move=> i; rewrite mem_iota addn1 /xrotV => /take'x[le_i_t ti'x].
rewrite -rotD ?rev_cat //= rev_cons cat_rcons index_cat mem_rev size_rev.
by rewrite ifN // size_takel //= eqxx addn0.
apply/uniq_perm=> [||t]; first exact: permutations_uniq.
apply/allpairs_uniq_dep=> [|t _|]; rewrite ?permutations_uniq ?iota_uniq //.
move=> _ _ /allpairsPdep[t [i [_ ? ->]]] /allpairsPdep[u [j [_ ? ->]]] Etu.
have Eij: i = j by rewrite -(xrotK t i) // /xrot Etu xrotK.
by move: Etu; rewrite Eij => /rot_inj[->].
rewrite mem_permutations; apply/esym; apply/allpairsPdep/idP=> [[u [i]] | Dt].
rewrite mem_permutations => -[Du _ /(canLR (rotK i))]; rewrite /rotr.
by set j := (j in rot j _) => Dt; apply/perm_consP; exists j, u.
pose r := rev (rot 1 t); pose i := index x r; pose u := rev (take i r).
have r_x: x \in r by rewrite mem_rev mem_rot (perm_mem Dt) mem_head.
have [v Duv]: {v | rot i (x :: u ++ v) = t}; first exists (rev (drop i.+1 r)).
rewrite -rev_cat -rev_rcons -rot1_cons -cat_cons -(nth_index x r_x).
by rewrite -drop_nth ?index_mem // rot_rot !rev_rot revK rotK rotrK.
exists (u ++ v), i; rewrite mem_permutations -(perm_cons x) -(perm_rot i) Duv.
rewrite mem_iota addn1 ltnS /= index_cat mem_rev size_rev.
by have /take'x[le_i_t ti'x] := leqnn i; rewrite ifN ?size_takel ?leq_addr.
Qed.
Lemma size_permutations s : uniq s -> size (permutations s) = (size s)`!.
Proof.
move Dn: (size s) => n Us; elim: n s => [[]|n IHn s] //= in Dn Us *.
rewrite (perm_size (permutationsE _)) ?Dn // undup_id // factS -Dn.
rewrite -(size_iota 0 n`!) -(size_allpairs (fun=>id)) !size_allpairs_dep.
by apply/congr1/eq_in_map=> x sx; rewrite size_iota IHn ?size_rem ?Dn ?rem_uniq.
Qed.
Lemma permutations_all_uniq s : uniq s -> all uniq (permutations s).
Proof.
by move=> Us; apply/allP=> t; rewrite mem_permutations => /perm_uniq->.
Qed.
Lemma perm_permutations s t :
perm_eq s t -> perm_eq (permutations s) (permutations t).
Proof.
move=> Est; apply/uniq_perm; try exact: permutations_uniq.
by move=> u; rewrite !mem_permutations (permPr Est).
Qed.
End Permutations.
|
SumCoeff.lean
|
/-
Copyright (c) 2025 Xavier Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.Analysis.Asymptotics.SpecificAsymptotics
import Mathlib.Analysis.InnerProductSpace.Calculus
import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals
import Mathlib.NumberTheory.AbelSummation
import Mathlib.NumberTheory.LSeries.Basic
/-!
# Partial sums of coefficients of L-series
We prove several results involving partial sums of coefficients (or norm of coefficients) of
L-series.
## Main results
* `LSeriesSummable_of_sum_norm_bigO`: for `f : ℕ → ℂ`, if the partial sums
`∑ k ∈ Icc 1 n, ‖f k‖` are `O(n ^ r)` for some real `0 ≤ r`, then the L-series `LSeries f`
converges at `s : ℂ` for all `s` such that `r < s.re`.
* `LSeries_eq_mul_integral` : for `f : ℕ → ℂ`, if the partial sums `∑ k ∈ Icc 1 n, f k` are
`O(n ^ r)` for some real `0 ≤ r` and the L-series `LSeries f` converges at `s : ℂ` with
`r < s.re`, then `LSeries f s = s * ∫ t in Set.Ioi 1, (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1))`.
* `LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div` : assume that `f : ℕ → ℂ` satisfies that
`(∑ k ∈ Icc 1 n, f k) / n` tends to some complex number `l` when `n → ∞` and that the L-series
`LSeries f` converges for all `s : ℝ` such that `1 < s`. Then `(s - 1) * LSeries f s` tends
to `l` when `s → 1` with `1 < s`.
-/
open Finset Filter MeasureTheory Topology Complex Asymptotics
section summable
variable {f : ℕ → ℂ} {r : ℝ} {s : ℂ}
private theorem LSeriesSummable_of_sum_norm_bigO_aux (hf : f 0 = 0)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, ‖f k‖) =O[atTop] fun n ↦ (n : ℝ) ^ r)
(hr : 0 ≤ r) (hs : r < s.re) :
LSeriesSummable f s := by
have h₁ : -s ≠ 0 := neg_ne_zero.mpr <| ne_zero_of_re_pos (hr.trans_lt hs)
have h₂ : (-s).re + r ≤ 0 := by
rw [neg_re, neg_add_nonpos_iff]
exact hs.le
have h₃ (t : ℝ) (ht : t ∈ Set.Ici 1) : DifferentiableAt ℝ (fun x : ℝ ↦ ‖(x : ℂ) ^ (-s)‖) t :=
have ht' : t ≠ 0 := (zero_lt_one.trans_le ht).ne'
(differentiableAt_id.ofReal_cpow_const ht' h₁).norm ℝ <|
(cpow_ne_zero_iff_of_exponent_ne_zero h₁).mpr <| ofReal_ne_zero.mpr ht'
have h₄ : (deriv fun t : ℝ ↦ ‖(t : ℂ) ^ (-s)‖) =ᶠ[atTop] fun t ↦ -s.re * t ^ (-(s.re + 1)) := by
filter_upwards [eventually_gt_atTop 0] with t ht
rw [deriv_norm_ofReal_cpow _ ht, neg_re, neg_add']
simp_rw [LSeriesSummable, funext (LSeries.term_def₀ hf s), mul_comm (f _)]
refine summable_mul_of_bigO_atTop' (f := fun t ↦ (t : ℂ) ^ (-s))
(g := fun t ↦ t ^ (-(s.re + 1) + r)) _ h₃ ?_ ?_ ?_ ?_
· refine (Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi
(integrableOn_Ioi_deriv_norm_ofReal_cpow zero_lt_one ?_)).locallyIntegrableOn
exact neg_re _ ▸ neg_nonpos.mpr <| hr.trans hs.le
· refine (IsBigO.mul_atTop_rpow_natCast_of_isBigO_rpow _ _ _ ?_ hO h₂).congr_right (by simp)
exact (norm_ofReal_cpow_eventually_eq_atTop _).isBigO.natCast_atTop
· refine h₄.isBigO.of_const_mul_right.mul_atTop_rpow_of_isBigO_rpow _ r _ ?_ le_rfl
exact (hO.comp_tendsto tendsto_nat_floor_atTop).trans <|
isEquivalent_nat_floor.isBigO.rpow hr (eventually_ge_atTop 0)
· rwa [integrableAtFilter_rpow_atTop_iff, neg_add_lt_iff_lt_add, add_neg_cancel_right]
/-- If the partial sums `∑ k ∈ Icc 1 n, ‖f k‖` are `O(n ^ r)` for some real `0 ≤ r`, then the
L-series `LSeries f` converges at `s : ℂ` for all `s` such that `r < s.re`. -/
theorem LSeriesSummable_of_sum_norm_bigO
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, ‖f k‖) =O[atTop] fun n ↦ (n : ℝ) ^ r)
(hr : 0 ≤ r) (hs : r < s.re) :
LSeriesSummable f s := by
have h₁ : (fun n ↦ if n = 0 then 0 else f n) =ᶠ[atTop] f := by
filter_upwards [eventually_ne_atTop 0] with n hn using by simp_rw [if_neg hn]
refine (LSeriesSummable_of_sum_norm_bigO_aux (if_pos rfl) ?_ hr hs).congr' _ h₁
refine hO.congr' (Eventually.of_forall fun _ ↦ Finset.sum_congr rfl fun _ h ↦ ?_) EventuallyEq.rfl
rw [if_neg (zero_lt_one.trans_le (mem_Icc.mp h).1).ne']
/-- If `f` takes nonnegative real values and the partial sums `∑ k ∈ Icc 1 n, f k` are `O(n ^ r)`
for some real `0 ≤ r`, then the L-series `LSeries f` converges at `s : ℂ` for all `s`
such that `r < s.re`. -/
theorem LSeriesSummable_of_sum_norm_bigO_and_nonneg
{f : ℕ → ℝ} (hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r)
(hf : ∀ n, 0 ≤ f n) (hr : 0 ≤ r) (hs : r < s.re) :
LSeriesSummable (fun n ↦ f n) s :=
LSeriesSummable_of_sum_norm_bigO (by simpa [abs_of_nonneg (hf _)]) hr hs
end summable
section integralrepresentation
private theorem LSeries_eq_mul_integral_aux {f : ℕ → ℂ} (hf : f 0 = 0) {r : ℝ} (hr : 0 ≤ r) {s : ℂ}
(hs : r < s.re) (hS : LSeriesSummable f s)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r) :
LSeries f s = s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1)) := by
have h₁ : (-s - 1).re + r < -1 := by
rwa [sub_re, one_re, neg_re, neg_sub_left, neg_add_lt_iff_lt_add, add_neg_cancel_comm]
have h₂ : s ≠ 0 := ne_zero_of_re_pos (hr.trans_lt hs)
have h₃ (t : ℝ) (ht : t ∈ Set.Ici 1) : DifferentiableAt ℝ (fun x : ℝ ↦ (x : ℂ) ^ (-s)) t :=
differentiableAt_id.ofReal_cpow_const (zero_lt_one.trans_le ht).ne' (neg_ne_zero.mpr h₂)
have h₄ : ∀ n, ∑ k ∈ Icc 0 n, f k = ∑ k ∈ Icc 1 n, f k := fun n ↦ by
rw [← insert_Icc_add_one_left_eq_Icc n.zero_le, sum_insert (by aesop), hf, zero_add, zero_add]
simp_rw [← h₄] at hO
rw [← integral_const_mul]
refine tendsto_nhds_unique ((tendsto_add_atTop_iff_nat 1).mpr hS.hasSum.tendsto_sum_nat) ?_
simp_rw [Nat.range_succ_eq_Icc_zero, LSeries.term_def₀ hf, mul_comm (f _)]
convert tendsto_sum_mul_atTop_nhds_one_sub_integral₀ (f := fun x ↦ (x : ℂ) ^ (-s)) (l := 0)
?_ hf h₃ ?_ ?_ ?_ (integrableAtFilter_rpow_atTop_iff.mpr h₁)
· rw [zero_sub, ← integral_neg]
refine setIntegral_congr_fun measurableSet_Ioi fun t ht ↦ ?_
rw [deriv_ofReal_cpow_const (zero_lt_one.trans ht).ne', h₄]
· ring_nf
· exact neg_ne_zero.mpr <| ne_zero_of_re_pos (hr.trans_lt hs)
· refine (Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi <|
integrableOn_Ioi_deriv_ofReal_cpow zero_lt_one
(by simpa using hr.trans_lt hs)).locallyIntegrableOn
· have hlim : Tendsto (fun n : ℕ ↦ (n : ℝ) ^ (-(s.re - r))) atTop (𝓝 0) :=
(tendsto_rpow_neg_atTop (by rwa [sub_pos])).comp tendsto_natCast_atTop_atTop
refine (IsBigO.mul_atTop_rpow_natCast_of_isBigO_rpow (-s.re) _ _ ?_ hO ?_).trans_tendsto hlim
· exact isBigO_norm_left.mp <| (norm_ofReal_cpow_eventually_eq_atTop _).isBigO.natCast_atTop
· linarith
· refine .mul_atTop_rpow_of_isBigO_rpow (-(s + 1).re) r _ ?_ ?_ (by rw [← neg_re, neg_add'])
· simpa [-neg_add_rev, neg_add'] using isBigO_deriv_ofReal_cpow_const_atTop _
· exact (hO.comp_tendsto tendsto_nat_floor_atTop).trans <|
isEquivalent_nat_floor.isBigO.rpow hr (eventually_ge_atTop 0)
/-- If the partial sums `∑ k ∈ Icc 1 n, f k` are `O(n ^ r)` for some real `0 ≤ r` and the
L-series `LSeries f` converges at `s : ℂ` with `r < s.re`, then
`LSeries f s = s * ∫ t in Set.Ioi 1, (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1))`. -/
theorem LSeries_eq_mul_integral (f : ℕ → ℂ) {r : ℝ} (hr : 0 ≤ r) {s : ℂ} (hs : r < s.re)
(hS : LSeriesSummable f s)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r) :
LSeries f s = s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1)) := by
rw [← LSeriesSummable_congr' s (f := fun n ↦ if n = 0 then 0 else f n)
(by filter_upwards [eventually_ne_atTop 0] with n h using if_neg h)] at hS
have (n : _) : ∑ k ∈ Icc 1 n, (if k = 0 then 0 else f k) = ∑ k ∈ Icc 1 n, f k :=
Finset.sum_congr rfl fun k hk ↦ by rw [if_neg (zero_lt_one.trans_le (mem_Icc.mp hk).1).ne']
rw [← LSeries_congr _ (fun _ ↦ if_neg _), LSeries_eq_mul_integral_aux (if_pos rfl) hr hs hS] <;>
simp_all
/-- A version of `LSeries_eq_mul_integral` where we use the stronger condition that the partial sums
`∑ k ∈ Icc 1 n, ‖f k‖` are `O(n ^ r)` to deduce the integral representation. -/
theorem LSeries_eq_mul_integral' (f : ℕ → ℂ) {r : ℝ} (hr : 0 ≤ r) {s : ℂ} (hs : r < s.re)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, ‖f k‖) =O[atTop] fun n ↦ (n : ℝ) ^ r) :
LSeries f s = s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1)) :=
LSeries_eq_mul_integral _ hr hs (LSeriesSummable_of_sum_norm_bigO hO hr hs) <|
(isBigO_of_le _ fun _ ↦ (norm_sum_le _ _).trans <| Real.le_norm_self _).trans hO
/-- If `f` takes nonnegative real values and the partial sums `∑ k ∈ Icc 1 n, f k` are `O(n ^ r)`
for some real `0 ≤ r`, then for `s : ℂ` with `r < s.re`, we have
`LSeries f s = s * ∫ t in Set.Ioi 1, (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * t ^ (-(s + 1))`. -/
theorem LSeries_eq_mul_integral_of_nonneg (f : ℕ → ℝ) {r : ℝ} (hr : 0 ≤ r) {s : ℂ} (hs : r < s.re)
(hO : (fun n ↦ ∑ k ∈ Icc 1 n, f k) =O[atTop] fun n ↦ (n : ℝ) ^ r) (hf : ∀ n, 0 ≤ f n) :
LSeries (fun n ↦ f n) s =
s * ∫ t in Set.Ioi (1 : ℝ), (∑ k ∈ Icc 1 ⌊t⌋₊, (f k : ℂ)) * t ^ (-(s + 1)) :=
LSeries_eq_mul_integral' _ hr hs <| hO.congr_left fun _ ↦ by simp [abs_of_nonneg (hf _)]
end integralrepresentation
noncomputable section residue
variable {f : ℕ → ℂ} {l : ℂ}
section lemmas
private theorem lemma₁ (hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l))
{s : ℝ} (hs : 1 < s) :
IntegrableOn (fun t : ℝ ↦ (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * (t : ℂ) ^ (-(s : ℂ) - 1)) (Set.Ici 1) := by
have h₁ : LocallyIntegrableOn (fun t : ℝ ↦ (∑ k ∈ Icc 1 ⌊t⌋₊, f k) * (t : ℂ) ^ (-(s : ℂ) - 1))
(Set.Ici 1) := by
simp_rw [mul_comm]
refine locallyIntegrableOn_mul_sum_Icc f zero_le_one ?_
refine ContinuousOn.locallyIntegrableOn (fun t ht ↦ ?_) measurableSet_Ici
exact (continuousAt_ofReal_cpow_const _ _ <|
Or.inr (zero_lt_one.trans_le ht).ne').continuousWithinAt
have h₂ : (fun t : ℝ ↦ ∑ k ∈ Icc 1 ⌊t⌋₊, f k) =O[atTop] fun t ↦ t ^ (1 : ℝ) := by
simp_rw [Real.rpow_one]
refine IsBigO.trans_isEquivalent ?_ isEquivalent_nat_floor
have : Tendsto (fun n ↦ (∑ k ∈ Icc 1 n, f k) / ((n : ℝ) ^ (1 : ℝ) : ℝ)) atTop (𝓝 l) := by
simpa using hlim
simpa using (isBigO_atTop_natCast_rpow_of_tendsto_div_rpow this).comp_tendsto
tendsto_nat_floor_atTop
refine h₁.integrableOn_of_isBigO_atTop (g := fun t ↦ t ^ (-s)) ?_ ?_
· refine IsBigO.mul_atTop_rpow_of_isBigO_rpow 1 (-s - 1) _ h₂ ?_ (by linarith)
exact (norm_ofReal_cpow_eventually_eq_atTop _).isBigO.of_norm_left
· rwa [integrableAtFilter_rpow_atTop_iff, neg_lt_neg_iff]
private theorem lemma₂ {s T ε : ℝ} {S : ℝ → ℂ} (hs : 1 < s)
(hS₁ : LocallyIntegrableOn (fun t ↦ S t) (Set.Ici 1)) (hS₂ : ∀ t ≥ T, ‖S t‖ ≤ ε * t) :
IntegrableOn (fun t : ℝ ↦ ‖S t‖ * (t ^ (-s - 1))) (Set.Ici 1) := by
have h : LocallyIntegrableOn (fun t : ℝ ↦ ‖S t‖ * (t ^ (-s - 1))) (Set.Ici 1) := by
refine hS₁.norm.mul_continuousOn ?_ isLocallyClosed_Ici
exact fun t ht ↦ (Real.continuousAt_rpow_const _ _
<| Or.inl (zero_lt_one.trans_le ht).ne').continuousWithinAt
refine h.integrableOn_of_isBigO_atTop (g := fun t ↦ t ^ (-s)) (isBigO_iff.mpr ⟨ε, ?_⟩) ?_
· filter_upwards [eventually_ge_atTop T, eventually_gt_atTop 0] with t ht ht'
simpa [abs_of_nonneg, Real.rpow_nonneg, ht'.le, Real.rpow_sub ht', mul_assoc, ht'.ne',
mul_div_cancel₀] using mul_le_mul_of_nonneg_right (hS₂ t ht) (norm_nonneg <| t ^ (-s - 1))
· exact integrableAtFilter_rpow_atTop_iff.mpr <| neg_lt_neg_iff.mpr hs
end lemmas
section proof
-- See `LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃` for the strategy of proof
private theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₁
(hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l)) {ε : ℝ} (hε : 0 < ε) :
∀ᶠ t : ℝ in atTop, ‖(∑ k ∈ Icc 1 ⌊t⌋₊, f k) - l * t‖ < ε * t := by
have h_lim' : Tendsto (fun t : ℝ ↦ (∑ k ∈ Icc 1 ⌊t⌋₊, f k : ℂ) / t) atTop (𝓝 l) := by
refine (mul_one l ▸ ofReal_one ▸ ((hlim.comp tendsto_nat_floor_atTop).mul <|
tendsto_ofReal_iff.mpr <| tendsto_nat_floor_div_atTop)).congr' ?_
filter_upwards [eventually_ge_atTop 1] with t ht
simp [div_mul_div_cancel₀ (show (⌊t⌋₊ : ℂ) ≠ 0 by simpa)]
filter_upwards [eventually_gt_atTop 0, Metric.tendsto_nhds.mp h_lim' ε hε] with t ht₁ ht₂
rwa [dist_eq_norm, div_sub' (ne_zero_of_re_pos ht₁), norm_div, norm_real,
Real.norm_of_nonneg ht₁.le, mul_comm, div_lt_iff₀ ht₁] at ht₂
private theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₂ {s T ε : ℝ} {S : ℝ → ℂ}
(hS : LocallyIntegrableOn (fun t ↦ S t - l * t) (Set.Ici 1)) (hε : 0 < ε)
(hs : 1 < s) (hT₁ : 1 ≤ T) (hT : ∀ t ≥ T, ‖S t - l * t‖ ≤ ε * t) :
(s - 1) * ∫ (t : ℝ) in Set.Ioi T, ‖S t - l * t‖ * t ^ (-s - 1) ≤ ε := by
have hT₀ : 0 < T := zero_lt_one.trans_le hT₁
have h {t : ℝ} (ht : 0 < t) : t ^ (-s) = t * t ^ (-s - 1) := by
rw [Real.rpow_sub ht, Real.rpow_one, mul_div_cancel₀ _ ht.ne']
calc
_ ≤ (s - 1) * ∫ (t : ℝ) in Set.Ioi T, ε * t ^ (-s) := by
refine mul_le_mul_of_nonneg_left (setIntegral_mono_on ?_ ?_ measurableSet_Ioi fun t ht ↦ ?_)
(sub_pos_of_lt hs).le
· exact (lemma₂ hs hS hT).mono_set <| Set.Ioi_subset_Ici_iff.mpr hT₁
· exact (integrableOn_Ioi_rpow_of_lt (neg_lt_neg_iff.mpr hs) hT₀).const_mul _
· have ht' : 0 < t := hT₀.trans ht
rw [h ht', ← mul_assoc]
exact mul_le_mul_of_nonneg_right (hT t ht.le) (Real.rpow_nonneg ht'.le _)
_ ≤ ε * ((s - 1) * ∫ (t : ℝ) in Set.Ioi 1, t ^ (-s)) := by
rw [integral_const_mul, ← mul_assoc, ← mul_assoc, mul_comm ε]
refine mul_le_mul_of_nonneg_left (setIntegral_mono_set ?_ ?_
(Set.Ioi_subset_Ioi hT₁).eventuallyLE) (mul_nonneg (sub_pos_of_lt hs).le hε.le)
· exact integrableOn_Ioi_rpow_of_lt (neg_lt_neg_iff.mpr hs) zero_lt_one
· exact (ae_restrict_iff' measurableSet_Ioi).mpr <| univ_mem' fun t ht ↦
Real.rpow_nonneg (zero_le_one.trans ht.le) _
_ = ε := by
rw [integral_Ioi_rpow_of_lt (by rwa [neg_lt_neg_iff]) zero_lt_one, Real.one_rpow]
field_simp [show -s + 1 ≠ 0 by linarith, hε.ne']
ring
private theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃
(hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l))
(hfS : ∀ s : ℝ, 1 < s → LSeriesSummable f s) {ε : ℝ} (hε : ε > 0) :
∃ C ≥ 0, (fun s : ℝ ↦ ‖(s - 1) * LSeries f s - s * l‖) ≤ᶠ[𝓝[>] 1]
fun s ↦ (s - 1) * s * C + s * ε := by
obtain ⟨T, hT₁, hT⟩ := (eventually_forall_ge_atTop.mpr
(LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₁
hlim hε)).frequently.forall_exists_of_atTop 1
let S : ℝ → ℂ := fun t ↦ ∑ k ∈ Icc 1 ⌊t⌋₊, f k
let C := ∫ t in Set.Ioc 1 T, ‖S t - l * t‖ * t ^ (-1 - 1 : ℝ)
have hC : 0 ≤ C := by
refine setIntegral_nonneg_ae measurableSet_Ioc (univ_mem' fun t ht ↦ ?_)
exact mul_nonneg (norm_nonneg _) <| Real.rpow_nonneg (zero_le_one.trans ht.1.le) _
refine ⟨C, hC, ?_⟩
filter_upwards [eventually_mem_nhdsWithin] with s hs
rw [Set.mem_Ioi] at hs
have hs' : 0 ≤ (s - 1) * s := mul_nonneg (sub_nonneg.mpr hs.le) (zero_le_one.trans hs.le)
have h₀ : LocallyIntegrableOn (fun t ↦ S t - l * t) (Set.Ici 1) := by
refine .sub ?_ <| ContinuousOn.locallyIntegrableOn (by fun_prop) measurableSet_Ici
simpa using locallyIntegrableOn_mul_sum_Icc f zero_le_one (locallyIntegrableOn_const 1)
have h₁ : IntegrableOn (fun t ↦ ‖S t - l * t‖ * t ^ (-s - 1)) (Set.Ici 1) :=
lemma₂ hs h₀ fun t ht ↦ (hT t ht).le
have h₂ : IntegrableOn (fun t : ℝ ↦ ‖S t - l * t‖ * (t ^ ((-1 : ℝ) - 1))) (Set.Ioc 1 T) := by
refine ((h₀.norm.mul_continuousOn ?_ isLocallyClosed_Ici).integrableOn_compact_subset
Set.Icc_subset_Ici_self isCompact_Icc).mono_set Set.Ioc_subset_Icc_self
exact fun t ht ↦ (Real.continuousAt_rpow_const _ _
<| Or.inl (zero_lt_one.trans_le ht).ne').continuousWithinAt
have h₃ : (s - 1) * ∫ (t : ℝ) in Set.Ioi 1, (t : ℂ) ^ (-s : ℂ) = 1 := by
rw [integral_Ioi_cpow_of_lt (by rwa [neg_re, neg_lt_neg_iff]) zero_lt_one, ofReal_one,
one_cpow, show -(s : ℂ) + 1 = -(s - 1) by ring, neg_div_neg_eq, mul_div_cancel₀]
exact (sub_ne_zero.trans ofReal_ne_one).mpr hs.ne'
let Cs := ∫ t in Set.Ioc 1 T, ‖S t - l * t‖ * t ^ (-s - 1)
have h₄ : Cs ≤ C := by
refine setIntegral_mono_on ?_ h₂ measurableSet_Ioc fun t ht ↦ ?_
· exact h₁.mono_set <| Set.Ioc_subset_Ioi_self.trans Set.Ioi_subset_Ici_self
· gcongr
exact ht.1.le
calc
-- First, we replace `s * l` by `(s - 1) * s` times the integral of `l * t ^ (-s)` using `h₃`
-- and replace `LSeries f s` by its integral representation.
_ = ‖((s - 1) * s * ∫ t in Set.Ioi 1, S t * ↑t ^ (-(s : ℂ) - 1)) -
l * s * ((s - 1) * ∫ (t : ℝ) in Set.Ioi 1, ↑t ^ (-(s : ℂ)))‖ := by
rw [h₃, mul_one, mul_comm l, LSeries_eq_mul_integral _ zero_le_one (by rwa [ofReal_re])
(hfS _ hs), neg_add', mul_assoc]
exact isBigO_atTop_natCast_rpow_of_tendsto_div_rpow (a := l) (by simpa using hlim)
_ = ‖(s - 1) * s * ∫ t in Set.Ioi 1, (S t * (t : ℂ) ^ (-s - 1 : ℂ) - l * t ^ (-s : ℂ))‖ := by
rw [integral_sub, integral_const_mul]
· congr; ring
· exact (lemma₁ hlim hs).mono_set Set.Ioi_subset_Ici_self
· exact (integrableOn_Ioi_cpow_of_lt
(by rwa [neg_re, ofReal_re, neg_lt_neg_iff]) zero_lt_one).const_mul _
_ = ‖(s - 1) * s * ∫ t in Set.Ioi 1, (S t - l * t) * (t : ℂ) ^ (-s - 1 : ℂ)‖ := by
congr 2
refine setIntegral_congr_fun measurableSet_Ioi fun t ht ↦ ?_
replace ht : (t : ℂ) ≠ 0 := ne_zero_of_one_lt_re ht
rw [sub_mul, cpow_sub _ _ ht, cpow_one, mul_assoc, mul_div_cancel₀ _ ht]
_ ≤ (s - 1) * s * ∫ t in Set.Ioi 1, ‖(S t - l * ↑t) * ↑t ^ (-s - 1 : ℂ)‖ := by
rw [norm_mul, show ((s : ℂ) - 1) * s = ((s - 1) * s : ℝ) by simp, norm_real,
Real.norm_of_nonneg hs']
exact mul_le_mul_of_nonneg_left (norm_integral_le_integral_norm _) hs'
-- Next, step is to bound the integral of `‖S t - l * t‖ * t ^ (-s - 1)`.
_ = (s - 1) * s * ∫ t in Set.Ioi 1, ‖S t - l * t‖ * t ^ (-s - 1) := by
congr 1
refine setIntegral_congr_fun measurableSet_Ioi fun t ht ↦ ?_
replace ht : 0 ≤ t := zero_le_one.trans ht.le
rw [norm_mul, show (-(s : ℂ) - 1) = (-s - 1 : ℝ) by simp, ← ofReal_cpow ht, norm_real,
Real.norm_of_nonneg (Real.rpow_nonneg ht _)]
-- For that, we cut the integral in two parts using `T` as the cutting point.
_ = (s - 1) * s * (Cs + ∫ t in Set.Ioi T, ‖S t - l * t‖ * t ^ (-s - 1)) := by
rw [← Set.Ioc_union_Ioi_eq_Ioi hT₁, setIntegral_union Set.Ioc_disjoint_Ioi_same
measurableSet_Ioi]
· exact h₁.mono_set <| Set.Ioc_subset_Ioi_self.trans Set.Ioi_subset_Ici_self
· exact h₁.mono_set <| Set.Ioi_subset_Ici_self.trans <| Set.Ici_subset_Ici.mpr hT₁
-- The first part can be bounded by `C` using `h₄`.
_ ≤ (s - 1) * s * C + s * ((s - 1) * ∫ t in Set.Ioi T, ‖S t - l * t‖ * t ^ (-s - 1)) := by
rw [mul_add, ← mul_assoc, mul_comm s]
gcongr
-- The second part is bounded using `LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₂`
-- since `‖S t - l t‖ ≤ ε * t` for all `t ≥ T`.
_ ≤ (s - 1) * s * C + s * ε := by
gcongr
exact LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₂ h₀ hε hs hT₁
fun t ht ↦ (hT t ht.le).le
theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div
(hlim : Tendsto (fun n : ℕ ↦ (∑ k ∈ Icc 1 n, f k) / n) atTop (𝓝 l))
(hfS : ∀ s : ℝ, 1 < s → LSeriesSummable f s) :
Tendsto (fun s : ℝ ↦ (s - 1) * LSeries f s) (𝓝[>] 1) (𝓝 l) := by
have h₁ {C ε : ℝ} : Tendsto (fun s ↦ (s - 1) * s * C + s * ε) (𝓝[>] 1) (𝓝 ε) := by
rw [show 𝓝 ε = 𝓝 ((1 - 1) * 1 * C + 1 * ε) by congr; ring]
exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop))
have h₂ : IsBoundedUnder
(fun x1 x2 ↦ x1 ≤ x2) (𝓝[>] 1) fun s : ℝ ↦ ‖(s - 1) * LSeries f s - s * l‖ := by
obtain ⟨C, _, hC₂⟩ :=
LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃ hlim hfS zero_lt_one
exact h₁.isBoundedUnder_le.mono_le hC₂
suffices Tendsto (fun s : ℝ ↦ (s - 1) * LSeries f s - s * l) (𝓝[>] 1) (𝓝 0) by
rw [show 𝓝 l = 𝓝 (0 + 1 * l) by congr; ring]
have h₃ : Tendsto (fun s : ℝ ↦ s * l) (𝓝[>] 1) (𝓝 (1 * l)) :=
tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop))
exact (this.add h₃).congr fun _ ↦ by ring
refine tendsto_zero_iff_norm_tendsto_zero.mpr <| tendsto_of_le_liminf_of_limsup_le ?_ ?_ h₂ ?_
· exact le_liminf_of_le h₂.isCoboundedUnder_ge (univ_mem' (fun _ ↦ norm_nonneg _))
· refine le_of_forall_pos_le_add fun ε hε ↦ ?_
rw [zero_add]
obtain ⟨C, hC₁, hC₂⟩ := LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_aux₃ hlim hfS hε
refine le_of_le_of_eq (limsup_le_limsup hC₂ ?_ h₁.isBoundedUnder_le) h₁.limsup_eq
exact isCoboundedUnder_le_of_eventually_le _ (univ_mem' fun _ ↦ norm_nonneg _)
· exact isBoundedUnder_of_eventually_ge (univ_mem' fun _ ↦ norm_nonneg _)
theorem LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div_and_nonneg (f : ℕ → ℝ) {l : ℝ}
(hf : Tendsto (fun n ↦ (∑ k ∈ Icc 1 n, f k) / (n : ℝ)) atTop (𝓝 l))
(hf' : ∀ n, 0 ≤ f n) :
Tendsto (fun s : ℝ ↦ (s - 1) * LSeries (fun n ↦ f n) s) (𝓝[>] 1) (𝓝 l) := by
refine LSeries_tendsto_sub_mul_nhds_one_of_tendsto_sum_div (f := fun n ↦ f n)
(hf.ofReal.congr fun _ ↦ ?_) fun s hs ↦ ?_
· simp
· refine LSeriesSummable_of_sum_norm_bigO_and_nonneg ?_ hf' zero_le_one hs
exact isBigO_atTop_natCast_rpow_of_tendsto_div_rpow (by simpa)
end proof
end residue
|
SplitEqualizer.lean
|
/-
Copyright (c) 2024 Jack McKoen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jack McKoen
-/
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
/-!
# Split Equalizers
We define what it means for a triple of morphisms `f g : X ⟶ Y`, `ι : W ⟶ X` to be a split
equalizer: there is a retraction `r` of `ι` and a retraction `t` of `g`, which additionally satisfy
`t ≫ f = r ≫ ι`.
In addition, we show that every split equalizer is an equalizer
(`CategoryTheory.IsSplitEqualizer.isEqualizer`) and absolute
(`CategoryTheory.IsSplitEqualizer.map`)
A pair `f g : X ⟶ Y` has a split equalizer if there is a `W` and `ι : W ⟶ X` making `f,g,ι` a
split equalizer.
A pair `f g : X ⟶ Y` has a `G`-split equalizer if `G f, G g` has a split equalizer.
These definitions and constructions are useful in particular for the comonadicity theorems.
This file was adapted from `Mathlib/CategoryTheory/Limits/Shapes/SplitCoequalizer.lean`. Please try
to keep them in sync.
-/
namespace CategoryTheory
universe v v₂ u u₂
variable {C : Type u} [Category.{v} C]
variable {D : Type u₂} [Category.{v₂} D]
variable (G : C ⥤ D)
variable {X Y : C} (f g : X ⟶ Y)
/-- A split equalizer diagram consists of morphisms
```
ι f
W → X ⇉ Y
g
```
satisfying `ι ≫ f = ι ≫ g` together with morphisms
```
r t
W ← X ← Y
```
satisfying `ι ≫ r = 𝟙 W`, `g ≫ t = 𝟙 X` and `f ≫ t = r ≫ ι`.
The name "equalizer" is appropriate, since any split equalizer is a equalizer, see
`CategoryTheory.IsSplitEqualizer.isEqualizer`.
Split equalizers are also absolute, since a functor preserves all the structure above.
-/
structure IsSplitEqualizer {W : C} (ι : W ⟶ X) where
/-- A map from `X` to the equalizer -/
leftRetraction : X ⟶ W
/-- A map in the opposite direction to `f` and `g` -/
rightRetraction : Y ⟶ X
/-- Composition of `ι` with `f` and with `g` agree -/
condition : ι ≫ f = ι ≫ g := by cat_disch
/-- `leftRetraction` splits `ι` -/
ι_leftRetraction : ι ≫ leftRetraction = 𝟙 W := by cat_disch
/-- `rightRetraction` splits `g` -/
bottom_rightRetraction : g ≫ rightRetraction = 𝟙 X := by cat_disch
/-- `f` composed with `rightRetraction` is `leftRetraction` composed with `ι` -/
top_rightRetraction : f ≫ rightRetraction = leftRetraction ≫ ι := by cat_disch
instance {X : C} : Inhabited (IsSplitEqualizer (𝟙 X) (𝟙 X) (𝟙 X)) where
default := { leftRetraction := 𝟙 X, rightRetraction := 𝟙 X }
open IsSplitEqualizer
attribute [reassoc] condition
attribute [reassoc (attr := simp)] ι_leftRetraction bottom_rightRetraction top_rightRetraction
variable {f g}
/-- Split equalizers are absolute: they are preserved by any functor. -/
@[simps]
def IsSplitEqualizer.map {W : C} {ι : W ⟶ X} (q : IsSplitEqualizer f g ι) (F : C ⥤ D) :
IsSplitEqualizer (F.map f) (F.map g) (F.map ι) where
leftRetraction := F.map q.leftRetraction
rightRetraction := F.map q.rightRetraction
condition := by rw [← F.map_comp, q.condition, F.map_comp]
ι_leftRetraction := by rw [← F.map_comp, q.ι_leftRetraction, F.map_id]
bottom_rightRetraction := by rw [← F.map_comp, q.bottom_rightRetraction, F.map_id]
top_rightRetraction := by rw [← F.map_comp, q.top_rightRetraction, F.map_comp]
section
open Limits
/-- A split equalizer clearly induces a fork. -/
@[simps! pt]
def IsSplitEqualizer.asFork {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) :
Fork f g := Fork.ofι h t.condition
@[simp]
theorem IsSplitEqualizer.asFork_ι {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) :
t.asFork.ι = h := rfl
/--
The fork induced by a split equalizer is an equalizer, justifying the name. In some cases it
is more convenient to show a given fork is an equalizer by showing it is split.
-/
def IsSplitEqualizer.isEqualizer {W : C} {h : W ⟶ X} (t : IsSplitEqualizer f g h) :
IsLimit t.asFork :=
Fork.IsLimit.mk' _ fun s =>
⟨ s.ι ≫ t.leftRetraction,
by simp [- top_rightRetraction, ← t.top_rightRetraction, s.condition_assoc],
fun hm => by simp [← hm] ⟩
end
variable (f g)
/--
The pair `f,g` is a cosplit pair if there is an `h : W ⟶ X` so that `f, g, h` forms a split
equalizer in `C`.
-/
class HasSplitEqualizer : Prop where
/-- There is some split equalizer -/
splittable : ∃ (W : C) (h : W ⟶ X), Nonempty (IsSplitEqualizer f g h)
/--
The pair `f,g` is a `G`-cosplit pair if there is an `h : W ⟶ G X` so that `G f, G g, h` forms a
split equalizer in `D`.
-/
abbrev Functor.IsCosplitPair : Prop :=
HasSplitEqualizer (G.map f) (G.map g)
/-- Get the equalizer object from the typeclass `IsCosplitPair`. -/
noncomputable def HasSplitEqualizer.equalizerOfSplit [HasSplitEqualizer f g] : C :=
(splittable (f := f) (g := g)).choose
/-- Get the equalizer morphism from the typeclass `IsCosplitPair`. -/
noncomputable def HasSplitEqualizer.equalizerι [HasSplitEqualizer f g] :
HasSplitEqualizer.equalizerOfSplit f g ⟶ X :=
(splittable (f := f) (g := g)).choose_spec.choose
/-- The equalizer morphism `equalizerι` gives a split equalizer on `f,g`. -/
noncomputable def HasSplitEqualizer.isSplitEqualizer [HasSplitEqualizer f g] :
IsSplitEqualizer f g (HasSplitEqualizer.equalizerι f g) :=
Classical.choice (splittable (f := f) (g := g)).choose_spec.choose_spec
/-- If `f, g` is cosplit, then `G f, G g` is cosplit. -/
instance map_is_cosplit_pair [HasSplitEqualizer f g] : HasSplitEqualizer (G.map f) (G.map g) where
splittable :=
⟨_, _, ⟨IsSplitEqualizer.map (HasSplitEqualizer.isSplitEqualizer f g) _⟩⟩
namespace Limits
/-- If a pair has a split equalizer, it has a equalizer. -/
instance (priority := 1) hasEqualizer_of_hasSplitEqualizer [HasSplitEqualizer f g] :
HasEqualizer f g :=
HasLimit.mk ⟨_, (HasSplitEqualizer.isSplitEqualizer f g).isEqualizer⟩
end Limits
end CategoryTheory
|
Chunk.lean
|
/-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Combinatorics.SimpleGraph.Regularity.Bound
import Mathlib.Combinatorics.SimpleGraph.Regularity.Equitabilise
import Mathlib.Combinatorics.SimpleGraph.Regularity.Uniform
/-!
# Chunk of the increment partition for Szemerédi Regularity Lemma
In the proof of Szemerédi Regularity Lemma, we need to partition each part of a starting partition
to increase the energy. This file defines those partitions of parts and shows that they locally
increase the energy.
This entire file is internal to the proof of Szemerédi Regularity Lemma.
## Main declarations
* `SzemerediRegularity.chunk`: The partition of a part of the starting partition.
* `SzemerediRegularity.edgeDensity_chunk_uniform`: `chunk` does not locally decrease the edge
density between uniform parts too much.
* `SzemerediRegularity.edgeDensity_chunk_not_uniform`: `chunk` locally increases the edge density
between non-uniform parts.
## TODO
Once ported to mathlib4, this file will be a great golfing ground for Heather's new tactic
`gcongr`.
## References
[Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp]
-/
open Finpartition Finset Fintype Rel Nat
open scoped SzemerediRegularity.Positivity
namespace SzemerediRegularity
variable {α : Type*} [Fintype α] [DecidableEq α] {P : Finpartition (univ : Finset α)}
(hP : P.IsEquipartition) (G : SimpleGraph α) [DecidableRel G.Adj] (ε : ℝ) {U : Finset α}
(hU : U ∈ P.parts) (V : Finset α)
local notation3 "m" => (card α / stepBound #P.parts : ℕ)
/-!
### Definitions
We define `chunk`, the partition of a part, and `star`, the sets of parts of `chunk` that are
contained in the corresponding witness of non-uniformity.
-/
/-- The portion of `SzemerediRegularity.increment` which partitions `U`. -/
noncomputable def chunk : Finpartition U :=
if hUcard : #U = m * 4 ^ #P.parts + (card α / #P.parts - m * 4 ^ #P.parts) then
(atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₁ hUcard
else (atomise U <| P.nonuniformWitnesses G ε U).equitabilise <| card_aux₂ hP hU hUcard
-- `hP` and `hU` are used to get that `U` has size
-- `m * 4 ^ #P.parts + a or m * 4 ^ #P.parts + a + 1`
/-- The portion of `SzemerediRegularity.chunk` which is contained in the witness of non-uniformity
of `U` and `V`. -/
noncomputable def star (V : Finset α) : Finset (Finset α) :=
{A ∈ (chunk hP G ε hU).parts | A ⊆ G.nonuniformWitness ε U V}
/-!
### Density estimates
We estimate the density between parts of `chunk`.
-/
theorem biUnion_star_subset_nonuniformWitness :
(star hP G ε hU V).biUnion id ⊆ G.nonuniformWitness ε U V :=
biUnion_subset_iff_forall_subset.2 fun _ hA => (mem_filter.1 hA).2
variable {hP G ε hU V} {𝒜 : Finset (Finset α)} {s : Finset α}
theorem star_subset_chunk : star hP G ε hU V ⊆ (chunk hP G ε hU).parts :=
filter_subset _ _
private theorem card_nonuniformWitness_sdiff_biUnion_star (hV : V ∈ P.parts) (hUV : U ≠ V)
(h₂ : ¬G.IsUniform ε U V) :
#(G.nonuniformWitness ε U V \ (star hP G ε hU V).biUnion id) ≤ 2 ^ (#P.parts - 1) * m := by
have hX : G.nonuniformWitness ε U V ∈ P.nonuniformWitnesses G ε U :=
nonuniformWitness_mem_nonuniformWitnesses h₂ hV hUV
have q : G.nonuniformWitness ε U V \ (star hP G ε hU V).biUnion id ⊆
{B ∈ (atomise U <| P.nonuniformWitnesses G ε U).parts |
B ⊆ G.nonuniformWitness ε U V ∧ B.Nonempty}.biUnion
fun B => B \ {A ∈ (chunk hP G ε hU).parts | A ⊆ B}.biUnion id := by
intro x hx
rw [← biUnion_filter_atomise hX (G.nonuniformWitness_subset h₂), star, mem_sdiff,
mem_biUnion] at hx
simp only [not_exists, mem_biUnion, and_imp, mem_filter,
not_and, mem_sdiff, id, mem_sdiff] at hx ⊢
obtain ⟨⟨B, hB₁, hB₂⟩, hx⟩ := hx
exact ⟨B, hB₁, hB₂, fun A hA AB => hx A hA <| AB.trans hB₁.2.1⟩
apply (card_le_card q).trans (card_biUnion_le.trans _)
trans ∑ B ∈ (atomise U <| P.nonuniformWitnesses G ε U).parts with
B ⊆ G.nonuniformWitness ε U V ∧ B.Nonempty, m
· suffices ∀ B ∈ (atomise U <| P.nonuniformWitnesses G ε U).parts,
#(B \ {A ∈ (chunk hP G ε hU).parts | A ⊆ B}.biUnion id) ≤ m by
exact sum_le_sum fun B hB => this B <| filter_subset _ _ hB
intro B hB
unfold chunk
split_ifs with h₁
· convert card_parts_equitabilise_subset_le _ (card_aux₁ h₁) hB
· convert card_parts_equitabilise_subset_le _ (card_aux₂ hP hU h₁) hB
rw [sum_const]
refine mul_le_mul_right' ?_ _
have t := card_filter_atomise_le_two_pow (s := U) hX
refine t.trans (pow_right_mono₀ (by simp) <| tsub_le_tsub_right ?_ _)
exact card_image_le.trans (card_le_card <| filter_subset _ _)
private theorem one_sub_eps_mul_card_nonuniformWitness_le_card_star (hV : V ∈ P.parts)
(hUV : U ≠ V) (hunif : ¬G.IsUniform ε U V) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
(hε₁ : ε ≤ 1) :
(1 - ε / 10) * #(G.nonuniformWitness ε U V) ≤ #((star hP G ε hU V).biUnion id) := by
have hP₁ : 0 < #P.parts := Finset.card_pos.2 ⟨_, hU⟩
have : (↑2 ^ #P.parts : ℝ) * m / (#U * ε) ≤ ε / 10 := by
rw [← div_div, div_le_iff₀']
swap
· sz_positivity
refine le_of_mul_le_mul_left ?_ (pow_pos zero_lt_two #P.parts)
calc
↑2 ^ #P.parts * ((↑2 ^ #P.parts * m : ℝ) / #U) =
((2 : ℝ) * 2) ^ #P.parts * m / #U := by
rw [mul_pow, ← mul_div_assoc, mul_assoc]
_ = ↑4 ^ #P.parts * m / #U := by norm_num
_ ≤ 1 := div_le_one_of_le₀ (pow_mul_m_le_card_part hP hU) (cast_nonneg _)
_ ≤ ↑2 ^ #P.parts * ε ^ 2 / 10 := by
refine (one_le_sq_iff₀ <| by positivity).1 ?_
rw [div_pow, mul_pow, pow_right_comm, ← pow_mul ε, one_le_div (by positivity)]
calc
(↑10 ^ 2) = 100 := by norm_num
_ ≤ ↑4 ^ #P.parts * ε ^ 5 := hPε
_ ≤ ↑4 ^ #P.parts * ε ^ 4 := by
gcongr _ * ?_
exact pow_le_pow_of_le_one (by sz_positivity) hε₁ (by decide)
_ = (↑2 ^ 2) ^ #P.parts * ε ^ (2 * 2) := by norm_num
_ = ↑2 ^ #P.parts * (ε * (ε / 10)) := by rw [mul_div_assoc, sq, mul_div_assoc]
calc
(↑1 - ε / 10) * #(G.nonuniformWitness ε U V) ≤
(↑1 - ↑2 ^ #P.parts * m / (#U * ε)) * #(G.nonuniformWitness ε U V) := by gcongr
_ = #(G.nonuniformWitness ε U V) -
↑2 ^ #P.parts * m / (#U * ε) * #(G.nonuniformWitness ε U V) := by
rw [sub_mul, one_mul]
_ ≤ #(G.nonuniformWitness ε U V) - ↑2 ^ (#P.parts - 1) * m := by
refine sub_le_sub_left ?_ _
have : (2 : ℝ) ^ #P.parts = ↑2 ^ (#P.parts - 1) * 2 := by
rw [← _root_.pow_succ, tsub_add_cancel_of_le (succ_le_iff.2 hP₁)]
rw [← mul_div_right_comm, this, mul_right_comm _ (2 : ℝ), mul_assoc, le_div_iff₀]
· gcongr _ * ?_
exact (G.le_card_nonuniformWitness hunif).trans
(le_mul_of_one_le_left (cast_nonneg _) one_le_two)
have := Finset.card_pos.mpr (P.nonempty_of_mem_parts hU)
sz_positivity
_ ≤ #((star hP G ε hU V).biUnion id) := by
rw [sub_le_comm, ←
cast_sub (card_le_card <| biUnion_star_subset_nonuniformWitness hP G ε hU V), ←
card_sdiff (biUnion_star_subset_nonuniformWitness hP G ε hU V)]
exact mod_cast card_nonuniformWitness_sdiff_biUnion_star hV hUV hunif
/-! ### `chunk` -/
theorem card_chunk (hm : m ≠ 0) : #(chunk hP G ε hU).parts = 4 ^ #P.parts := by
unfold chunk
split_ifs
· rw [card_parts_equitabilise _ _ hm, tsub_add_cancel_of_le]
exact le_of_lt a_add_one_le_four_pow_parts_card
· rw [card_parts_equitabilise _ _ hm, tsub_add_cancel_of_le a_add_one_le_four_pow_parts_card]
theorem card_eq_of_mem_parts_chunk (hs : s ∈ (chunk hP G ε hU).parts) :
#s = m ∨ #s = m + 1 := by
unfold chunk at hs
split_ifs at hs <;> exact card_eq_of_mem_parts_equitabilise hs
theorem m_le_card_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : m ≤ #s :=
(card_eq_of_mem_parts_chunk hs).elim ge_of_eq fun i => by simp [i]
theorem card_le_m_add_one_of_mem_chunk_parts (hs : s ∈ (chunk hP G ε hU).parts) : #s ≤ m + 1 :=
(card_eq_of_mem_parts_chunk hs).elim (fun i => by simp [i]) fun i => i.le
theorem card_biUnion_star_le_m_add_one_card_star_mul :
(#((star hP G ε hU V).biUnion id) : ℝ) ≤ #(star hP G ε hU V) * (m + 1) :=
mod_cast card_biUnion_le_card_mul _ _ _ fun _ hs =>
card_le_m_add_one_of_mem_chunk_parts <| star_subset_chunk hs
private theorem le_sum_card_subset_chunk_parts (h𝒜 : 𝒜 ⊆ (chunk hP G ε hU).parts) (hs : s ∈ 𝒜) :
(#𝒜 : ℝ) * #s * (m / (m + 1)) ≤ #(𝒜.sup id) := by
rw [mul_div_assoc', div_le_iff₀ coe_m_add_one_pos, mul_right_comm]
gcongr
· rw [← (ofSubset _ h𝒜 rfl).sum_card_parts, ofSubset_parts, ← cast_mul, cast_le]
exact card_nsmul_le_sum _ _ _ fun x hx => m_le_card_of_mem_chunk_parts <| h𝒜 hx
· exact mod_cast card_le_m_add_one_of_mem_chunk_parts (h𝒜 hs)
private theorem sum_card_subset_chunk_parts_le (m_pos : (0 : ℝ) < m)
(h𝒜 : 𝒜 ⊆ (chunk hP G ε hU).parts) (hs : s ∈ 𝒜) :
(#(𝒜.sup id) : ℝ) ≤ #𝒜 * #s * ((m + 1) / m) := by
rw [sup_eq_biUnion, mul_div_assoc', le_div_iff₀ m_pos, mul_right_comm]
gcongr
· norm_cast
refine card_biUnion_le_card_mul _ _ _ fun x hx => ?_
apply card_le_m_add_one_of_mem_chunk_parts (h𝒜 hx)
· exact mod_cast m_le_card_of_mem_chunk_parts (h𝒜 hs)
private theorem one_sub_le_m_div_m_add_one_sq [Nonempty α]
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5) :
↑1 - ε ^ 5 / ↑50 ≤ (m / (m + 1 : ℝ)) ^ 2 := by
have : (m : ℝ) / (m + 1) = 1 - 1 / (m + 1) := by
rw [one_sub_div coe_m_add_one_pos.ne', add_sub_cancel_right]
rw [this, sub_sq, one_pow, mul_one]
refine le_trans ?_ (le_add_of_nonneg_right <| sq_nonneg _)
rw [sub_le_sub_iff_left, ← le_div_iff₀' (show (0 : ℝ) < 2 by norm_num), div_div,
one_div_le coe_m_add_one_pos, one_div_div]
· refine le_trans ?_ (le_add_of_nonneg_right zero_le_one)
norm_num
apply hundred_div_ε_pow_five_le_m hPα hPε
sz_positivity
private theorem m_add_one_div_m_le_one_add [Nonempty α]
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5) (hε₁ : ε ≤ 1) :
((m + 1 : ℝ) / m) ^ 2 ≤ ↑1 + ε ^ 5 / 49 := by
have : 0 ≤ ε := by sz_positivity
rw [same_add_div (by sz_positivity)]
calc
_ ≤ (1 + ε ^ 5 / 100) ^ 2 := by
gcongr (1 + ?_) ^ 2
rw [← one_div_div (100 : ℝ)]
exact one_div_le_one_div_of_le (by sz_positivity) (hundred_div_ε_pow_five_le_m hPα hPε)
_ = 1 + ε ^ 5 * (50⁻¹ + ε ^ 5 / 10000) := by ring
_ ≤ 1 + ε ^ 5 * (50⁻¹ + 1 ^ 5 / 10000) := by gcongr
_ ≤ 1 + ε ^ 5 * 49⁻¹ := by gcongr; norm_num
_ = 1 + ε ^ 5 / 49 := by rw [div_eq_mul_inv]
private theorem density_sub_eps_le_sum_density_div_card [Nonempty α]
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
{hU : U ∈ P.parts} {hV : V ∈ P.parts} {A B : Finset (Finset α)}
(hA : A ⊆ (chunk hP G ε hU).parts) (hB : B ⊆ (chunk hP G ε hV).parts) :
(G.edgeDensity (A.biUnion id) (B.biUnion id)) - ε ^ 5 / 50 ≤
(∑ ab ∈ A.product B, (G.edgeDensity ab.1 ab.2 : ℝ)) / (#A * #B) := by
have : ↑(G.edgeDensity (A.biUnion id) (B.biUnion id)) - ε ^ 5 / ↑50 ≤
(↑1 - ε ^ 5 / 50) * G.edgeDensity (A.biUnion id) (B.biUnion id) := by
rw [sub_mul, one_mul, sub_le_sub_iff_left]
refine mul_le_of_le_one_right (by sz_positivity) ?_
exact mod_cast G.edgeDensity_le_one _ _
refine this.trans ?_
conv_rhs => -- Porting note: LHS and RHS need separate treatment to get the desired form
simp only [SimpleGraph.edgeDensity_def, sum_div, Rat.cast_div, div_div]
conv_lhs =>
rw [SimpleGraph.edgeDensity_def, SimpleGraph.interedges, ← sup_eq_biUnion, ← sup_eq_biUnion,
Rel.card_interedges_finpartition _ (ofSubset _ hA rfl) (ofSubset _ hB rfl), ofSubset_parts,
ofSubset_parts]
simp only [cast_sum, sum_div, mul_sum, Rat.cast_sum, Rat.cast_div,
mul_div_left_comm ((1 : ℝ) - _)]
push_cast
apply sum_le_sum
simp only [and_imp, Prod.forall, mem_product]
rintro x y hx hy
rw [mul_mul_mul_comm, mul_comm (#x : ℝ), mul_comm (#y : ℝ), le_div_iff₀, mul_assoc]
· refine mul_le_of_le_one_right (cast_nonneg _) ?_
rw [div_mul_eq_mul_div, ← mul_assoc, mul_assoc]
refine div_le_one_of_le₀ ?_ (by positivity)
refine (mul_le_mul_of_nonneg_right (one_sub_le_m_div_m_add_one_sq hPα hPε) ?_).trans ?_
· exact mod_cast _root_.zero_le _
rw [sq, mul_mul_mul_comm, mul_comm ((m : ℝ) / _), mul_comm ((m : ℝ) / _)]
gcongr
· apply le_sum_card_subset_chunk_parts hA hx
· apply le_sum_card_subset_chunk_parts hB hy
refine mul_pos (mul_pos ?_ ?_) (mul_pos ?_ ?_) <;> rw [cast_pos, Finset.card_pos]
exacts [⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
private theorem sum_density_div_card_le_density_add_eps [Nonempty α]
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
(hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts} {A B : Finset (Finset α)}
(hA : A ⊆ (chunk hP G ε hU).parts) (hB : B ⊆ (chunk hP G ε hV).parts) :
(∑ ab ∈ A.product B, G.edgeDensity ab.1 ab.2 : ℝ) / (#A * #B) ≤
G.edgeDensity (A.biUnion id) (B.biUnion id) + ε ^ 5 / 49 := by
have : (↑1 + ε ^ 5 / ↑49) * G.edgeDensity (A.biUnion id) (B.biUnion id) ≤
G.edgeDensity (A.biUnion id) (B.biUnion id) + ε ^ 5 / 49 := by
rw [add_mul, one_mul, add_le_add_iff_left]
refine mul_le_of_le_one_right (by sz_positivity) ?_
exact mod_cast G.edgeDensity_le_one _ _
refine le_trans ?_ this
conv_lhs => -- Porting note: LHS and RHS need separate treatment to get the desired form
simp only [SimpleGraph.edgeDensity, edgeDensity, sum_div, Rat.cast_div, div_div]
conv_rhs =>
rw [SimpleGraph.edgeDensity, edgeDensity, ← sup_eq_biUnion, ← sup_eq_biUnion,
Rel.card_interedges_finpartition _ (ofSubset _ hA rfl) (ofSubset _ hB rfl)]
simp only [cast_sum, mul_sum, sum_div, Rat.cast_sum, Rat.cast_div,
mul_div_left_comm ((1 : ℝ) + _)]
push_cast
apply sum_le_sum
simp only [and_imp, Prod.forall, mem_product, show A.product B = A ×ˢ B by rfl]
intro x y hx hy
rw [mul_mul_mul_comm, mul_comm (#x : ℝ), mul_comm (#y : ℝ), div_le_iff₀, mul_assoc]
· refine le_mul_of_one_le_right (cast_nonneg _) ?_
rw [div_mul_eq_mul_div, one_le_div]
· refine le_trans ?_ (mul_le_mul_of_nonneg_right (m_add_one_div_m_le_one_add hPα hPε hε₁) ?_)
· rw [sq, mul_mul_mul_comm, mul_comm (_ / (m : ℝ)), mul_comm (_ / (m : ℝ))]
gcongr
exacts [sum_card_subset_chunk_parts_le (by sz_positivity) hA hx,
sum_card_subset_chunk_parts_le (by sz_positivity) hB hy]
· exact mod_cast _root_.zero_le _
rw [← cast_mul, cast_pos]
apply mul_pos <;> rw [Finset.card_pos, sup_eq_biUnion, biUnion_nonempty]
· exact ⟨_, hx, nonempty_of_mem_parts _ (hA hx)⟩
· exact ⟨_, hy, nonempty_of_mem_parts _ (hB hy)⟩
refine mul_pos (mul_pos ?_ ?_) (mul_pos ?_ ?_) <;> rw [cast_pos, Finset.card_pos]
exacts [⟨_, hx⟩, nonempty_of_mem_parts _ (hA hx), ⟨_, hy⟩, nonempty_of_mem_parts _ (hB hy)]
private theorem average_density_near_total_density [Nonempty α]
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
(hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts} {A B : Finset (Finset α)}
(hA : A ⊆ (chunk hP G ε hU).parts) (hB : B ⊆ (chunk hP G ε hV).parts) :
|(∑ ab ∈ A.product B, G.edgeDensity ab.1 ab.2 : ℝ) / (#A * #B) -
G.edgeDensity (A.biUnion id) (B.biUnion id)| ≤ ε ^ 5 / 49 := by
rw [abs_sub_le_iff]
constructor
· rw [sub_le_iff_le_add']
exact sum_density_div_card_le_density_add_eps hPα hPε hε₁ hA hB
suffices (G.edgeDensity (A.biUnion id) (B.biUnion id) : ℝ) -
(∑ ab ∈ A.product B, (G.edgeDensity ab.1 ab.2 : ℝ)) / (#A * #B) ≤ ε ^ 5 / 50 by
apply this.trans
gcongr <;> [sz_positivity; norm_num]
rw [sub_le_iff_le_add, ← sub_le_iff_le_add']
apply density_sub_eps_le_sum_density_div_card hPα hPε hA hB
private theorem edgeDensity_chunk_aux [Nonempty α] (hP)
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
(hU : U ∈ P.parts) (hV : V ∈ P.parts) :
(G.edgeDensity U V : ℝ) ^ 2 - ε ^ 5 / ↑25 ≤
((∑ ab ∈ (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
(G.edgeDensity ab.1 ab.2 : ℝ)) / ↑16 ^ #P.parts) ^ 2 := by
obtain hGε | hGε := le_total (G.edgeDensity U V : ℝ) (ε ^ 5 / 50)
· refine (sub_nonpos_of_le <| (sq_le ?_ ?_).trans <| hGε.trans ?_).trans (sq_nonneg _)
· exact mod_cast G.edgeDensity_nonneg _ _
· exact mod_cast G.edgeDensity_le_one _ _
· exact div_le_div_of_nonneg_left (by sz_positivity) (by norm_num) (by norm_num)
rw [← sub_nonneg] at hGε
have : 0 ≤ ε := by sz_positivity
calc
_ = G.edgeDensity U V ^ 2 - 1 * ε ^ 5 / 25 + 0 ^ 10 / 2500 := by ring
_ ≤ G.edgeDensity U V ^ 2 - G.edgeDensity U V * ε ^ 5 / 25 + ε ^ 10 / 2500 := by
gcongr; exact mod_cast G.edgeDensity_le_one ..
_ = (G.edgeDensity U V - ε ^ 5 / 50) ^ 2 := by ring
_ ≤ _ := by
gcongr
have rflU := Set.Subset.refl (chunk hP G ε hU).parts.toSet
have rflV := Set.Subset.refl (chunk hP G ε hV).parts.toSet
refine (le_trans ?_ <| density_sub_eps_le_sum_density_div_card hPα hPε rflU rflV).trans ?_
· rw [biUnion_parts, biUnion_parts]
· rw [card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ← cast_mul, ← mul_pow, cast_pow]
norm_cast
private theorem abs_density_star_sub_density_le_eps (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
(hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts} (hUV' : U ≠ V) (hUV : ¬G.IsUniform ε U V) :
|(G.edgeDensity ((star hP G ε hU V).biUnion id) ((star hP G ε hV U).biUnion id) : ℝ) -
G.edgeDensity (G.nonuniformWitness ε U V) (G.nonuniformWitness ε V U)| ≤ ε / 5 := by
convert abs_edgeDensity_sub_edgeDensity_le_two_mul G.Adj
(biUnion_star_subset_nonuniformWitness hP G ε hU V)
(biUnion_star_subset_nonuniformWitness hP G ε hV U) (by sz_positivity)
(one_sub_eps_mul_card_nonuniformWitness_le_card_star hV hUV' hUV hPε hε₁)
(one_sub_eps_mul_card_nonuniformWitness_le_card_star hU hUV'.symm (fun hVU => hUV hVU.symm)
hPε hε₁) using 1
linarith
private theorem eps_le_card_star_div [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≤ card α)
(hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5) (hε₁ : ε ≤ 1) (hU : U ∈ P.parts) (hV : V ∈ P.parts)
(hUV : U ≠ V) (hunif : ¬G.IsUniform ε U V) :
↑4 / ↑5 * ε ≤ #(star hP G ε hU V) / ↑4 ^ #P.parts := by
have hm : (0 : ℝ) ≤ 1 - (↑m)⁻¹ := sub_nonneg_of_le (inv_le_one_of_one_le₀ <| one_le_m_coe hPα)
have hε : 0 ≤ 1 - ε / 10 :=
sub_nonneg_of_le (div_le_one_of_le₀ (hε₁.trans <| by norm_num) <| by norm_num)
have hε₀ : 0 < ε := by sz_positivity
calc
4 / 5 * ε = (1 - 1 / 10) * (1 - 9⁻¹) * ε := by norm_num
_ ≤ (1 - ε / 10) * (1 - (↑m)⁻¹) * (#(G.nonuniformWitness ε U V) / #U) := by
gcongr
exacts [mod_cast (show 9 ≤ 100 by norm_num).trans (hundred_le_m hPα hPε hε₁),
(le_div_iff₀' <| cast_pos.2 (P.nonempty_of_mem_parts hU).card_pos).2 <|
G.le_card_nonuniformWitness hunif]
_ = (1 - ε / 10) * #(G.nonuniformWitness ε U V) * ((1 - (↑m)⁻¹) / #U) := by
rw [mul_assoc, mul_assoc, mul_div_left_comm]
_ ≤ #((star hP G ε hU V).biUnion id) * ((1 - (↑m)⁻¹) / #U) := by
gcongr
exact one_sub_eps_mul_card_nonuniformWitness_le_card_star hV hUV hunif hPε hε₁
_ ≤ #(star hP G ε hU V) * (m + 1) * ((1 - (↑m)⁻¹) / #U) := by
gcongr
exact card_biUnion_star_le_m_add_one_card_star_mul
_ ≤ #(star hP G ε hU V) * (m + ↑1) * ((↑1 - (↑m)⁻¹) / (↑4 ^ #P.parts * m)) := by
gcongr
· sz_positivity
· exact pow_mul_m_le_card_part hP hU
_ ≤ #(star hP G ε hU V) / ↑4 ^ #P.parts := by
rw [mul_assoc, mul_comm ((4 : ℝ) ^ #P.parts), ← div_div, ← mul_div_assoc, ← mul_comm_div]
refine mul_le_of_le_one_right (by positivity) ?_
have hm : (0 : ℝ) < m := by sz_positivity
rw [mul_div_assoc', div_le_one hm, ← one_div, one_sub_div hm.ne', mul_div_assoc',
div_le_iff₀ hm]
linarith
/-!
### Final bounds
Those inequalities are the end result of all this hard work.
-/
/-- Lower bound on the edge densities between non-uniform parts of `SzemerediRegularity.star`. -/
private theorem edgeDensity_star_not_uniform [Nonempty α]
(hPα : #P.parts * 16 ^ #P.parts ≤ card α) (hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5)
(hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts} (hUVne : U ≠ V) (hUV : ¬G.IsUniform ε U V) :
↑3 / ↑4 * ε ≤
|(∑ ab ∈ (star hP G ε hU V).product (star hP G ε hV U), (G.edgeDensity ab.1 ab.2 : ℝ)) /
(#(star hP G ε hU V) * #(star hP G ε hV U)) -
(∑ ab ∈ (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
(G.edgeDensity ab.1 ab.2 : ℝ)) / (16 : ℝ) ^ #P.parts| := by
rw [show (16 : ℝ) = ↑4 ^ 2 by norm_num, pow_right_comm, sq ((4 : ℝ) ^ _)]
set p : ℝ :=
(∑ ab ∈ (star hP G ε hU V).product (star hP G ε hV U), (G.edgeDensity ab.1 ab.2 : ℝ)) /
(#(star hP G ε hU V) * #(star hP G ε hV U))
set q : ℝ :=
(∑ ab ∈ (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
(G.edgeDensity ab.1 ab.2 : ℝ)) / (↑4 ^ #P.parts * ↑4 ^ #P.parts)
set r : ℝ := ↑(G.edgeDensity ((star hP G ε hU V).biUnion id) ((star hP G ε hV U).biUnion id))
set s : ℝ := ↑(G.edgeDensity (G.nonuniformWitness ε U V) (G.nonuniformWitness ε V U))
set t : ℝ := ↑(G.edgeDensity U V)
have hrs : |r - s| ≤ ε / 5 := abs_density_star_sub_density_le_eps hPε hε₁ hUVne hUV
have hst : ε ≤ |s - t| := by
-- After https://github.com/leanprover/lean4/pull/2734, we need to do the zeta reduction before `mod_cast`.
unfold s t
exact mod_cast G.nonuniformWitness_spec hUVne hUV
have hpr : |p - r| ≤ ε ^ 5 / 49 :=
average_density_near_total_density hPα hPε hε₁ star_subset_chunk star_subset_chunk
have hqt : |q - t| ≤ ε ^ 5 / 49 := by
have := average_density_near_total_density hPα hPε hε₁
(Subset.refl (chunk hP G ε hU).parts) (Subset.refl (chunk hP G ε hV).parts)
simp_rw [← sup_eq_biUnion, sup_parts, card_chunk (m_pos hPα).ne', cast_pow] at this
norm_num at this
exact this
have hε' : ε ^ 5 ≤ ε := by
simpa using pow_le_pow_of_le_one (by sz_positivity) hε₁ (show 1 ≤ 5 by norm_num)
rw [abs_sub_le_iff] at hrs hpr hqt
rw [le_abs] at hst ⊢
cases hst
· left; linarith
· right; linarith
/-- Lower bound on the edge densities between non-uniform parts of `SzemerediRegularity.increment`.
-/
theorem edgeDensity_chunk_not_uniform [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≤ card α)
(hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5) (hε₁ : ε ≤ 1) {hU : U ∈ P.parts} {hV : V ∈ P.parts}
(hUVne : U ≠ V) (hUV : ¬G.IsUniform ε U V) :
(G.edgeDensity U V : ℝ) ^ 2 - ε ^ 5 / ↑25 + ε ^ 4 / ↑3 ≤
(∑ ab ∈ (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
(G.edgeDensity ab.1 ab.2 : ℝ) ^ 2) / ↑16 ^ #P.parts :=
calc
↑(G.edgeDensity U V) ^ 2 - ε ^ 5 / 25 + ε ^ 4 / ↑3 ≤ ↑(G.edgeDensity U V) ^ 2 - ε ^ 5 / ↑25 +
#(star hP G ε hU V) * #(star hP G ε hV U) / ↑16 ^ #P.parts *
(↑9 / ↑16) * ε ^ 2 := by
apply add_le_add_left
have Ul : 4 / 5 * ε ≤ #(star hP G ε hU V) / _ :=
eps_le_card_star_div hPα hPε hε₁ hU hV hUVne hUV
have Vl : 4 / 5 * ε ≤ #(star hP G ε hV U) / _ :=
eps_le_card_star_div hPα hPε hε₁ hV hU hUVne.symm fun h => hUV h.symm
rw [show (16 : ℝ) = ↑4 ^ 2 by norm_num, pow_right_comm, sq ((4 : ℝ) ^ _), ←
_root_.div_mul_div_comm, mul_assoc]
have : 0 < ε := by sz_positivity
have UVl := mul_le_mul Ul Vl (by positivity) ?_
swap
· -- This seems faster than `exact div_nonneg (by positivity) (by positivity)` and *much*
-- (tens of seconds) faster than `positivity` on its own.
apply div_nonneg <;> positivity
refine le_trans ?_ (mul_le_mul_of_nonneg_right UVl ?_)
· norm_num
nlinarith
· norm_num
positivity
_ ≤ (∑ ab ∈ (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
(G.edgeDensity ab.1 ab.2 : ℝ) ^ 2) / ↑16 ^ #P.parts := by
have t : (star hP G ε hU V).product (star hP G ε hV U) ⊆
(chunk hP G ε hU).parts.product (chunk hP G ε hV).parts :=
product_subset_product star_subset_chunk star_subset_chunk
have hε : 0 ≤ ε := by sz_positivity
have sp : ∀ (a b : Finset (Finset α)), a.product b = a ×ˢ b := fun a b => rfl
have := add_div_le_sum_sq_div_card t (fun x => (G.edgeDensity x.1 x.2 : ℝ))
((G.edgeDensity U V : ℝ) ^ 2 - ε ^ 5 / ↑25) (show 0 ≤ 3 / 4 * ε by linarith) ?_ ?_
· simp_rw [sp, card_product, card_chunk (m_pos hPα).ne', ← mul_pow, cast_pow, mul_pow,
div_pow, ← mul_assoc] at this
norm_num at this
exact this
· simp_rw [sp, card_product, card_chunk (m_pos hPα).ne', ← mul_pow]
norm_num
exact edgeDensity_star_not_uniform hPα hPε hε₁ hUVne hUV
· rw [sp, card_product]
apply (edgeDensity_chunk_aux hP hPα hPε hU hV).trans
· rw [card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ← mul_pow]
norm_num
/-- Lower bound on the edge densities between parts of `SzemerediRegularity.increment`. This is the
blanket lower bound used the uniform parts. -/
theorem edgeDensity_chunk_uniform [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≤ card α)
(hPε : ↑100 ≤ ↑4 ^ #P.parts * ε ^ 5) (hU : U ∈ P.parts) (hV : V ∈ P.parts) :
(G.edgeDensity U V : ℝ) ^ 2 - ε ^ 5 / ↑25 ≤
(∑ ab ∈ (chunk hP G ε hU).parts.product (chunk hP G ε hV).parts,
(G.edgeDensity ab.1 ab.2 : ℝ) ^ 2) / ↑16 ^ #P.parts := by
apply (edgeDensity_chunk_aux (hP := hP) hPα hPε hU hV).trans
have key : (16 : ℝ) ^ #P.parts = #((chunk hP G ε hU).parts ×ˢ (chunk hP G ε hV).parts) := by
rw [card_product, cast_mul, card_chunk (m_pos hPα).ne', card_chunk (m_pos hPα).ne', ←
cast_mul, ← mul_pow]; norm_cast
simp_rw [key]
convert sum_div_card_sq_le_sum_sq_div_card (α := ℝ)
end SzemerediRegularity
|
StarOrdered.lean
|
/-
Copyright (c) 2024 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Topology.ContinuousMap.ContinuousMapZero
import Mathlib.Topology.ContinuousMap.Ordered
/-! # Continuous functions as a star-ordered ring
The type class `ContinuousSqrt` gives a sufficient condition on `R` to make `C(α, R)`
and `C(α, R)₀` into a `StarOrderedRing` for any topological space `α`, thereby providing a means
by which we can ensure `C(α, R)` has this property. This condition is satisfied
by `ℝ≥0`, `ℝ`, and `ℂ`, and the instances can be found in the file
`Mathlib/Topology/ContinuousMap/ContinuousSqrt.lean`.
## Implementation notes
Instead of asking for a well-behaved square root on `{x : R | 0 ≤ x}` in the obvious way, we instead
require that, for every `x y : R` such that `x ≤ y`, there exist some `s` such that `x + s*s = y`.
This is because we need this type class to work for `ℝ≥0` for the
continuous functional calculus. We could instead assume `[OrderedSub R] [ContinuousSub R]`, but that
would lead to a proliferation of type class assumptions in the general case of the continuous
functional calculus, which we want to avoid because there is *already* a proliferation of type
classes there. At the moment, we only expect this class to be used in that context so this is a
reasonable compromise.
The field `ContinuousSqrt.sqrt` is data, which means that, if we implement an instance of the class
for a generic C⋆-algebra, we'll get a non-defeq diamond for the case `R := ℂ`. This shouldn't really
be a problem since the only purpose is to obtain the instance `StarOrderedRing C(α, R)`, which is a
`Prop`, but we note it for future reference.
-/
/-- A type class encoding the property that there is a continuous square root function on
nonnegative elements. This holds for `ℝ≥0`, `ℝ` and `ℂ` (as well as any C⋆-algebra), and this
allows us to derive an instance of `StarOrderedRing C(α, R)` under appropriate hypotheses.
In order for this to work on `ℝ≥0`, we actually must force our square root function to be defined
on and well-behaved for pairs `x : R × R` with `x.1 ≤ x.2`. -/
class ContinuousSqrt (R : Type*) [LE R] [NonUnitalSemiring R] [TopologicalSpace R] where
/-- `sqrt (a, b)` returns a value `s` such that `b = a + s * s` when `a ≤ b`. -/
protected sqrt : R × R → R
protected continuousOn_sqrt : ContinuousOn sqrt {x | x.1 ≤ x.2}
protected sqrt_nonneg (x : R × R) : x.1 ≤ x.2 → 0 ≤ sqrt x
protected sqrt_mul_sqrt (x : R × R) : x.1 ≤ x.2 → x.2 = x.1 + sqrt x * sqrt x
namespace ContinuousMap
variable {α : Type*} [TopologicalSpace α]
instance {R : Type*} [PartialOrder R] [NonUnitalSemiring R] [StarRing R]
[StarOrderedRing R] [TopologicalSpace R] [ContinuousStar R] [IsTopologicalSemiring R]
[ContinuousSqrt R] : StarOrderedRing C(α, R) := by
refine StarOrderedRing.of_le_iff ?_
intro f g
constructor
· rw [ContinuousMap.le_def]
intro h
use (mk _ ContinuousSqrt.continuousOn_sqrt.restrict).comp
⟨_, map_continuous (f.prodMk g) |>.codRestrict (s := {x | x.1 ≤ x.2}) (by exact h)⟩
ext x
simpa [IsSelfAdjoint.star_eq <| .of_nonneg (ContinuousSqrt.sqrt_nonneg (f x, g x) (h x))]
using ContinuousSqrt.sqrt_mul_sqrt (f x, g x) (h x)
· rintro ⟨p, rfl⟩
exact fun x ↦ le_add_of_nonneg_right (star_mul_self_nonneg (p x))
end ContinuousMap
namespace ContinuousMapZero
variable {α : Type*} [TopologicalSpace α] [Zero α]
instance instStarOrderedRing {R : Type*}
[TopologicalSpace R] [CommSemiring R] [PartialOrder R] [NoZeroDivisors R] [StarRing R]
[StarOrderedRing R] [IsTopologicalSemiring R] [ContinuousStar R] [StarOrderedRing C(α, R)] :
StarOrderedRing C(α, R)₀ where
le_iff f g := by
constructor
· rw [le_def, ← ContinuousMap.coe_coe, ← ContinuousMap.coe_coe g, ← ContinuousMap.le_def,
StarOrderedRing.le_iff]
rintro ⟨p, hp_mem, hp⟩
induction hp_mem using AddSubmonoid.closure_induction_left generalizing f g with
| one => exact ⟨0, zero_mem _, by ext x; congrm($(hp) x)⟩
| mul_left s s_mem p p_mem hp' =>
obtain ⟨s, rfl⟩ := s_mem
simp only at *
have h₀ : (star s * s + p) 0 = 0 := by simpa using congr($(hp) 0).symm
rw [← add_assoc] at hp
have p'₀ : 0 ≤ p 0 := by rw [← StarOrderedRing.nonneg_iff] at p_mem; exact p_mem 0
have s₉ : (star s * s) 0 = 0 := le_antisymm ((le_add_of_nonneg_right p'₀).trans_eq h₀)
(star_mul_self_nonneg (s 0))
have s₀' : s 0 = 0 := by aesop
let s' : C(α, R)₀ := ⟨s, s₀'⟩
obtain ⟨p', hp'_mem, rfl⟩ := hp' (f + star s' * s') g hp
refine ⟨star s' * s' + p', ?_, by rw [add_assoc]⟩
exact add_mem (AddSubmonoid.subset_closure ⟨s', rfl⟩) hp'_mem
· rintro ⟨p, hp, rfl⟩
induction hp using AddSubmonoid.closure_induction generalizing f with
| mem s s_mem =>
obtain ⟨s, rfl⟩ := s_mem
exact fun x ↦ le_add_of_nonneg_right (star_mul_self_nonneg (s x))
| one => simp
| mul g₁ g₂ _ _ h₁ h₂ => calc
f ≤ f + g₁ := h₁ f
_ ≤ (f + g₁) + g₂ := h₂ (f + g₁)
_ = f + (g₁ + g₂) := add_assoc _ _ _
end ContinuousMapZero
|
numdomain.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 ssrAC div fintype path bigop order finset fingroup.
From mathcomp Require Import ssralg poly orderedzmod.
(******************************************************************************)
(* Number structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines some classes to manipulate number structures, i.e, *)
(* structures with an order and a norm. To use this file, insert *)
(* "Import Num.Theory." before your scripts. You can also "Import Num.Def." *)
(* to enjoy shorter notations (e.g., minr instead of Num.min, lerif instead *)
(* of Num.leif, etc.). *)
(* *)
(* This file defines the following number structures: *)
(* *)
(* semiNormedZmodType == Zmodule with a semi-norm *)
(* The HB class is called SemiNormedZmodule. *)
(* normedZmodType == Zmodule with a norm *)
(* The HB class is called NormedZmodule. *)
(* numDomainType == Integral domain with an order and a norm *)
(* The HB class is called NumDomain. *)
(* *)
(* Over these structures, we have the following operations: *)
(* `|x| == norm of x *)
(* Num.sg x == sign of x: equal to 0 iff x = 0, to 1 iff x > 0, and *)
(* to -1 in all other cases (including x < 0) *)
(* *)
(* - list of prefixes : *)
(* p : positive *)
(* n : negative *)
(* sp : strictly positive *)
(* sn : strictly negative *)
(* i : interior = in [0, 1] or ]0, 1[ *)
(* e : exterior = in [1, +oo[ or ]1; +oo[ *)
(* w : non strict (weak) monotony *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope order_scope.
Local Open Scope group_scope.
Local Open Scope ring_scope.
Import Order.TTheory GRing.Theory.
Import orderedzmod.Num.
Module Num.
HB.mixin Record Zmodule_isSemiNormed (R : POrderedZmodule.type) M
of GRing.Zmodule M := {
norm : M -> R;
ler_normD : forall x y, norm (x + y) <= norm x + norm y;
normrMn : forall x n, norm (x *+ n) = norm x *+ n;
normrN : forall x, norm (- x) = norm x;
}.
#[short(type="semiNormedZmodType")]
HB.structure Definition SemiNormedZmodule (R : porderZmodType) :=
{ M of Zmodule_isSemiNormed R M & GRing.Zmodule M }.
HB.mixin Record SemiNormedZmodule_isPositiveDefinite
(R : POrderedZmodule.type) M of @SemiNormedZmodule R M := {
normr0_eq0 : forall x : M, norm x = 0 -> x = 0;
}.
#[short(type="normedZmodType")]
HB.structure Definition NormedZmodule (R : porderZmodType) :=
{ M of SemiNormedZmodule_isPositiveDefinite R M & SemiNormedZmodule R M }.
Arguments norm {R M} x : rename.
HB.factory Record Zmodule_isNormed (R : POrderedZmodule.type) M
of GRing.Zmodule M := {
norm : M -> R;
ler_normD : forall x y, norm (x + y) <= norm x + norm y;
normr0_eq0 : forall x, norm x = 0 -> x = 0;
normrMn : forall x n, norm (x *+ n) = norm x *+ n;
normrN : forall x, norm (- x) = norm x;
}.
HB.builders Context (R : POrderedZmodule.type) M of Zmodule_isNormed R M.
HB.instance Definition _ :=
Zmodule_isSemiNormed.Build R M ler_normD normrMn normrN.
HB.instance Definition _ :=
SemiNormedZmodule_isPositiveDefinite.Build R M normr0_eq0.
HB.end.
Module NormedZmoduleExports.
Bind Scope ring_scope with NormedZmodule.sort.
(* Notation "[ 'normedZmodType' R 'of' T 'for' cT ]" :=
(@clone _ (Phant R) T cT _ idfun)
(format "[ 'normedZmodType' R 'of' T 'for' cT ]") :
form_scope.
Notation "[ 'normedZmodType' R 'of' T ]" := (@clone _ (Phant R) T _ _ id)
(format "[ 'normedZmodType' R 'of' T ]") : form_scope. *)
End NormedZmoduleExports.
HB.export NormedZmoduleExports.
HB.mixin Record isNumRing R of GRing.NzRing R & POrderedZmodule R
& NormedZmodule (POrderedZmodule.clone R _) R := {
addr_gt0 : forall x y : R, 0 < x -> 0 < y -> 0 < (x + y);
ger_leVge : forall x y : R, 0 <= x -> 0 <= y -> (x <= y) || (y <= x);
normrM : {morph (norm : R -> R) : x y / x * y};
ler_def : forall x y : R, (x <= y) = (norm (y - x) == (y - x));
}.
#[short(type="numDomainType")]
HB.structure Definition NumDomain := { R of
GRing.IntegralDomain R &
POrderedZmodule R &
NormedZmodule (POrderedZmodule.clone R _) R &
isNumRing R
}.
Arguments addr_gt0 {_} [x y] : rename.
Arguments ger_leVge {_} [x y] : rename.
(* TODO: make isNumDomain depend on intermediate structures *)
(* TODO: make isNumDomain.sort canonically a NumDomain *)
Module NumDomainExports.
Bind Scope ring_scope with NumDomain.sort.
End NumDomainExports.
HB.export NumDomainExports.
Module Export Def.
Notation normr := norm.
Notation "`| x |" := (norm x) : ring_scope.
Section NumDomainDef.
Context {R : numDomainType}.
Definition sgr (x : R) : R := if x == 0 then 0 else if x < 0 then -1 else 1.
End NumDomainDef.
End Def.
Notation sg := sgr.
(* (Exported) symbolic syntax. *)
Module Export Syntax.
Notation "`| x |" := (norm x) : ring_scope.
End Syntax.
Section ExtensionAxioms.
Variable R : numDomainType.
Definition real_axiom : Prop := forall x : R, x \is real.
Definition archimedean_axiom : Prop := forall x : R, exists ub, `|x| < ub%:R.
Definition real_closed_axiom : Prop :=
forall (p : {poly R}) (a b : R),
a <= b -> p.[a] <= 0 <= p.[b] -> exists2 x, a <= x <= b & root p x.
End ExtensionAxioms.
(* The rest of the numbers interface hierarchy. *)
#[short(type="realDomainType")]
HB.structure Definition RealDomain :=
{ R of Order.Total ring_display R & NumDomain R }.
Module RealDomainExports.
Bind Scope ring_scope with RealDomain.sort.
End RealDomainExports.
HB.export RealDomainExports.
(* The elementary theory needed to support the definition of the derived *)
(* operations for the extensions described above. *)
Module Import Internals.
Section NumDomain.
Variable R : numDomainType.
Implicit Types x y : R.
(* Basic consequences (just enough to get predicate closure properties). *)
Lemma ger0_def x : (0 <= x) = (`|x| == x).
Proof. by rewrite ler_def subr0. Qed.
Lemma subr_ge0 x y : (0 <= x - y) = (y <= x).
Proof. by rewrite ger0_def -ler_def. Qed.
Lemma oppr_ge0 x : (0 <= - x) = (x <= 0).
Proof. by rewrite -sub0r subr_ge0. Qed.
Lemma ler01 : 0 <= 1 :> R.
Proof.
have n1_nz: `|1 : R| != 0 by apply: contraNneq (@oner_neq0 R) => /normr0_eq0->.
by rewrite ger0_def -(inj_eq (mulfI n1_nz)) -normrM !mulr1.
Qed.
Lemma ltr01 : 0 < 1 :> R. Proof. by rewrite lt_def oner_neq0 ler01. Qed.
Lemma le0r x : (0 <= x) = (x == 0) || (0 < x).
Proof. by rewrite le_eqVlt eq_sym. Qed.
Lemma addr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x + y.
Proof.
rewrite le0r; case/predU1P=> [-> | x_pos]; rewrite ?add0r // le0r.
by case/predU1P=> [-> | y_pos]; rewrite ltW ?addr0 ?addr_gt0.
Qed.
Lemma pmulr_rgt0 x y : 0 < x -> (0 < x * y) = (0 < y).
Proof.
rewrite !lt_def !ger0_def normrM mulf_eq0 negb_or => /andP[x_neq0 /eqP->].
by rewrite x_neq0 (inj_eq (mulfI x_neq0)).
Qed.
(* Closure properties of the real predicates. *)
Lemma posrE x : (x \is pos) = (0 < x). Proof. by []. Qed.
Lemma nnegrE x : (x \is nneg) = (0 <= x). Proof. by []. Qed.
Lemma realE x : (x \is real) = (0 <= x) || (x <= 0). Proof. by []. Qed.
Fact pos_divr_closed : divr_closed (@pos R).
Proof.
split=> [|x y x_gt0 y_gt0]; rewrite posrE ?ltr01 //.
have [Uy|/invr_out->] := boolP (y \is a GRing.unit); last by rewrite pmulr_rgt0.
by rewrite -(pmulr_rgt0 _ y_gt0) mulrC divrK.
Qed.
#[export]
HB.instance Definition _ := GRing.isDivClosed.Build R Rpos_pred
pos_divr_closed.
Fact nneg_divr_closed : divr_closed (@nneg R).
Proof.
split=> [|x y]; rewrite !nnegrE ?ler01 ?le0r // -!posrE.
case/predU1P=> [-> _ | x_gt0]; first by rewrite mul0r eqxx.
by case/predU1P=> [-> | y_gt0]; rewrite ?invr0 ?mulr0 ?eqxx // orbC rpred_div.
Qed.
#[export]
HB.instance Definition _ := GRing.isDivClosed.Build R Rnneg_pred
nneg_divr_closed.
Fact nneg_addr_closed : addr_closed (@nneg R).
Proof. by split; [apply: lexx | apply: addr_ge0]. Qed.
#[export]
HB.instance Definition _ := GRing.isAddClosed.Build R Rnneg_pred
nneg_addr_closed.
Fact real_oppr_closed : oppr_closed (@real R).
Proof. by move=> x; rewrite /= !realE oppr_ge0 orbC -!oppr_ge0 opprK. Qed.
#[export]
HB.instance Definition _ := GRing.isOppClosed.Build R Rreal_pred
real_oppr_closed.
Fact real_addr_closed : addr_closed (@real R).
Proof.
split=> [|x y Rx Ry]; first by rewrite realE lexx.
without loss{Rx} x_ge0: x y Ry / 0 <= x.
case/orP: Rx => [? | x_le0]; first exact.
by rewrite -rpredN opprD; apply; rewrite ?rpredN ?oppr_ge0.
case/orP: Ry => [y_ge0 | y_le0]; first by rewrite realE -nnegrE rpredD.
by rewrite realE -[y]opprK orbC -oppr_ge0 opprB !subr_ge0 ger_leVge ?oppr_ge0.
Qed.
#[export]
HB.instance Definition _ := GRing.isAddClosed.Build R Rreal_pred
real_addr_closed.
Fact real_divr_closed : divr_closed (@real R).
Proof.
split=> [|x y Rx Ry]; first by rewrite realE ler01.
without loss{Rx} x_ge0: x / 0 <= x.
case/orP: Rx => [? | x_le0]; first exact.
by rewrite -rpredN -mulNr; apply; rewrite ?oppr_ge0.
without loss{Ry} y_ge0: y / 0 <= y; last by rewrite realE -nnegrE rpred_div.
case/orP: Ry => [? | y_le0]; first exact.
by rewrite -rpredN -mulrN -invrN; apply; rewrite ?oppr_ge0.
Qed.
#[export]
HB.instance Definition _ := GRing.isDivClosed.Build R Rreal_pred
real_divr_closed.
End NumDomain.
Lemma num_real (R : realDomainType) (x : R) : x \is real.
Proof. exact: le_total. Qed.
Module Exports. HB.reexport. End Exports.
End Internals.
Module PredInstances.
Export Internals.Exports.
End PredInstances.
Module Export Theory.
Section NumIntegralDomainTheory.
Variable R : numDomainType.
Implicit Types (V : semiNormedZmodType R) (x y z t : R).
Implicit Types (W : normedZmodType R).
(* Lemmas from the signature (reexported). *)
Definition ler_normD V (x y : V) : `|x + y| <= `|x| + `|y| :=
ler_normD x y.
Definition addr_gt0 x y : 0 < x -> 0 < y -> 0 < x + y := @addr_gt0 R x y.
Definition normr0_eq0 W (x : W) : `|x| = 0 -> x = 0 := @normr0_eq0 R W x.
Definition ger_leVge x y : 0 <= x -> 0 <= y -> (x <= y) || (y <= x) :=
@ger_leVge R x y.
Definition normrM : {morph norm : x y / (x : R) * y} := @normrM R.
Definition ler_def x y : (x <= y) = (`|y - x| == y - x) := ler_def x y.
Definition normrMn V (x : V) n : `|x *+ n| = `|x| *+ n := normrMn x n.
Definition normrN V (x : V) : `|- x| = `|x| := normrN x.
(* Predicate definitions. *)
Lemma posrE x : (x \is pos) = (0 < x). Proof. by []. Qed.
Lemma negrE x : (x \is neg) = (x < 0). Proof. by []. Qed.
Lemma nnegrE x : (x \is nneg) = (0 <= x). Proof. by []. Qed.
Lemma nposrE x : (x \is npos) = (x <= 0). Proof. by []. Qed.
Lemma realE x : (x \is real) = (0 <= x) || (x <= 0). Proof. by []. Qed.
(* General properties of <= and < *)
Lemma lt0r x : (0 < x) = (x != 0) && (0 <= x). Proof. exact: lt_def. Qed.
Lemma le0r x : (0 <= x) = (x == 0) || (0 < x). Proof. exact: le0r. Qed.
Lemma lt0r_neq0 (x : R) : 0 < x -> x != 0. Proof. by move=> /gt_eqF ->. Qed.
Lemma ltr0_neq0 (x : R) : x < 0 -> x != 0. Proof. by move=> /lt_eqF ->. Qed.
Lemma pmulr_rgt0 x y : 0 < x -> (0 < x * y) = (0 < y).
Proof. exact: pmulr_rgt0. Qed.
Lemma pmulr_rge0 x y : 0 < x -> (0 <= x * y) = (0 <= y).
Proof. by move=> x_gt0; rewrite !le0r mulf_eq0 pmulr_rgt0 // gt_eqF. Qed.
(* Integer comparisons and characteristic 0. *)
Lemma ler01 : 0 <= 1 :> R. Proof. exact: ler01. Qed.
Lemma ltr01 : 0 < 1 :> R. Proof. exact: ltr01. Qed.
Lemma ler0n n : 0 <= n%:R :> R. Proof. by rewrite -nnegrE rpred_nat. Qed.
Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler01) : core.
Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr01) : core.
Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler0n) : core.
Lemma ltr0Sn n : 0 < n.+1%:R :> R.
Proof. by elim: n => // n; apply: addr_gt0. Qed.
Lemma ltr0n n : (0 < n%:R :> R) = (0 < n)%N.
Proof. by case: n => //= n; apply: ltr0Sn. Qed.
Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr0Sn) : core.
Lemma pnatr_eq0 n : (n%:R == 0 :> R) = (n == 0)%N.
Proof. by case: n => [|n]; rewrite ?mulr0n ?eqxx // gt_eqF. Qed.
Lemma pchar_num : [pchar R] =i pred0.
Proof. by case=> // p /=; rewrite !inE pnatr_eq0 andbF. Qed.
(* Properties of the norm. *)
Lemma ger0_def x : (0 <= x) = (`|x| == x). Proof. exact: ger0_def. Qed.
Lemma normr_idP {x} : reflect (`|x| = x) (0 <= x).
Proof. by rewrite ger0_def; apply: eqP. Qed.
Lemma ger0_norm x : 0 <= x -> `|x| = x. Proof. exact: normr_idP. Qed.
Lemma normr1 : `|1 : R| = 1. Proof. exact: ger0_norm. Qed.
Lemma normr_nat n : `|n%:R : R| = n%:R. Proof. exact: ger0_norm. Qed.
Lemma normr_prod I r (P : pred I) (F : I -> R) :
`|\prod_(i <- r | P i) F i| = \prod_(i <- r | P i) `|F i|.
Proof. exact: (big_morph norm normrM normr1). Qed.
Lemma normrX n x : `|x ^+ n| = `|x| ^+ n.
Proof. by rewrite -(card_ord n) -!prodr_const normr_prod. Qed.
Lemma normr_unit : {homo (@norm _ (* R *) R) : x / x \is a GRing.unit}.
Proof.
move=> x /= /unitrP [y [yx xy]]; apply/unitrP; exists `|y|.
by rewrite -!normrM xy yx normr1.
Qed.
Lemma normrV : {in GRing.unit, {morph (@norm _ (* R *) R) : x / x ^-1}}.
Proof.
move=> x ux; apply: (mulrI (normr_unit ux)).
by rewrite -normrM !divrr ?normr1 ?normr_unit.
Qed.
Lemma normrN1 : `|-1 : R| = 1.
Proof.
have: `|-1 : R| ^+ 2 == 1 by rewrite -normrX -signr_odd normr1.
rewrite sqrf_eq1 => /orP[/eqP //|]; rewrite -ger0_def le0r oppr_eq0 oner_eq0.
by move/(addr_gt0 ltr01); rewrite subrr ltxx.
Qed.
Lemma big_real x0 op I (P : pred I) F (s : seq I) :
{in real &, forall x y, op x y \is real} -> x0 \is real ->
{in P, forall i, F i \is real} -> \big[op/x0]_(i <- s | P i) F i \is real.
Proof. exact: comparable_bigr. Qed.
Lemma sum_real I (P : pred I) (F : I -> R) (s : seq I) :
{in P, forall i, F i \is real} -> \sum_(i <- s | P i) F i \is real.
Proof. by apply/big_real; [apply: rpredD | apply: rpred0]. Qed.
Lemma prod_real I (P : pred I) (F : I -> R) (s : seq I) :
{in P, forall i, F i \is real} -> \prod_(i <- s | P i) F i \is real.
Proof. by apply/big_real; [apply: rpredM | apply: rpred1]. Qed.
Section SemiNormedZmoduleTheory.
Variable V : semiNormedZmodType R.
Implicit Types (v w : V).
Lemma normr0 : `|0 : V| = 0.
Proof. by rewrite -(mulr0n 0) normrMn mulr0n. Qed.
Lemma distrC v w : `|v - w| = `|w - v|.
Proof. by rewrite -opprB normrN. Qed.
Lemma normr_id v : `| `|v| | = `|v|.
Proof.
have nz2: 2 != 0 :> R by rewrite pnatr_eq0.
apply: (mulfI nz2); rewrite -{1}normr_nat -normrM mulr_natl mulr2n ger0_norm //.
by rewrite -{2}normrN -normr0 -(subrr v) ler_normD.
Qed.
Lemma normr_ge0 v : 0 <= `|v|. Proof. by rewrite ger0_def normr_id. Qed.
Lemma normr_lt0 v : `|v| < 0 = false.
Proof. by rewrite le_gtF// normr_ge0. Qed.
Lemma gtr0_norm_neq0 v : `|v| > 0 -> (v != 0).
Proof. by apply: contra_ltN => /eqP->; rewrite normr0. Qed.
Lemma gtr0_norm_eq0F v : `|v| > 0 -> (v == 0) = false.
Proof. by move=> /gtr0_norm_neq0/negPf->. Qed.
End SemiNormedZmoduleTheory.
Section NormedZmoduleTheory.
Variable V : normedZmodType R.
Implicit Types (v w : V).
Lemma normr0P v : reflect (`|v| = 0) (v == 0).
Proof. by apply: (iffP eqP)=> [->|/normr0_eq0 //]; apply: normr0. Qed.
Definition normr_eq0 v := sameP (`|v| =P 0) (normr0P v).
Lemma normr_le0 v : `|v| <= 0 = (v == 0).
Proof. by rewrite -normr_eq0 eq_le normr_ge0 andbT. Qed.
Lemma normr_gt0 v : `|v| > 0 = (v != 0).
Proof. by rewrite lt_def normr_eq0 normr_ge0 andbT. Qed.
End NormedZmoduleTheory.
Definition normrE := (normr_id, normr0, normr1, normrN1, normr_ge0, normr_eq0,
normr_lt0, normr_le0, normr_gt0, normrN).
Lemma ler0_def x : (x <= 0) = (`|x| == - x).
Proof. by rewrite ler_def sub0r normrN. Qed.
Lemma ler0_norm x : x <= 0 -> `|x| = - x.
Proof. by move=> x_le0; rewrite -[r in _ = r]ger0_norm ?normrN ?oppr_ge0. Qed.
Definition gtr0_norm x (hx : 0 < x) := ger0_norm (ltW hx).
Definition ltr0_norm x (hx : x < 0) := ler0_norm (ltW hx).
Lemma ger0_le_norm :
{in nneg &, {mono (@normr _ R) : x y / x <= y}}.
Proof. by move=> x y; rewrite !nnegrE => x0 y0; rewrite !ger0_norm. Qed.
Lemma gtr0_le_norm :
{in pos &, {mono (@normr _ R) : x y / x <= y}}.
Proof. by move=> x y; rewrite !posrE => /ltW x0 /ltW y0; exact: ger0_le_norm. Qed.
Lemma ler0_ge_norm :
{in npos &, {mono (@normr _ R) : x y / x <= y >-> x >= y}}.
Proof.
move=> x y; rewrite !nposrE => x0 y0.
by rewrite !ler0_norm// -[LHS]subr_ge0 opprK addrC subr_ge0.
Qed.
Lemma ltr0_ge_norm :
{in neg &, {mono (@normr _ R) : x y / x <= y >-> x >= y}}.
Proof. by move=> x y; rewrite !negrE => /ltW x0 /ltW y0; exact: ler0_ge_norm. Qed.
(* Comparison to 0 of a difference *)
Lemma subr_ge0 x y : (0 <= y - x) = (x <= y). Proof. exact: subr_ge0. Qed.
Lemma subr_gt0 x y : (0 < y - x) = (x < y).
Proof. by rewrite !lt_def subr_eq0 subr_ge0. Qed.
Lemma subr_le0 x y : (y - x <= 0) = (y <= x).
Proof. by rewrite -[LHS]subr_ge0 opprB add0r subr_ge0. Qed. (* FIXME: rewrite pattern *)
Lemma subr_lt0 x y : (y - x < 0) = (y < x).
Proof. by rewrite -[LHS]subr_gt0 opprB add0r subr_gt0. Qed. (* FIXME: rewrite pattern *)
Definition subr_lte0 := (subr_le0, subr_lt0).
Definition subr_gte0 := (subr_ge0, subr_gt0).
Definition subr_cp0 := (subr_lte0, subr_gte0).
(* Comparability in a numDomain *)
Lemma comparable0r x : (0 >=< x)%R = (x \is Num.real). Proof. by []. Qed.
Lemma comparabler0 x : (x >=< 0)%R = (x \is Num.real).
Proof. by rewrite comparable_sym. Qed.
Lemma subr_comparable0 x y : (x - y >=< 0)%R = (x >=< y)%R.
Proof. by rewrite /comparable subr_ge0 subr_le0. Qed.
Lemma comparablerE x y : (x >=< y)%R = (x - y \is Num.real).
Proof. by rewrite -comparabler0 subr_comparable0. Qed.
Lemma comparabler_trans : transitive (comparable : rel R).
Proof.
move=> y x z; rewrite !comparablerE => xBy_real yBz_real.
by have := rpredD xBy_real yBz_real; rewrite addrA addrNK.
Qed.
(* Ordered ring properties. *)
Definition lter01 := (ler01, ltr01).
Lemma addr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x + y.
Proof. exact: addr_ge0. Qed.
End NumIntegralDomainTheory.
#[deprecated(since="mathcomp 2.4.0",note="Use pchar_num instead.")]
Notation char_num := pchar_num (only parsing).
Arguments ler01 {R}.
Arguments ltr01 {R}.
Arguments normr_idP {R x}.
Arguments normr0P {R V v}.
#[global] Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler01) : core.
#[global] Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr01) : core.
#[global] Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler0n) : core.
#[global] Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr0Sn) : core.
#[global] Hint Extern 0 (is_true (0 <= norm _)) => apply: normr_ge0 : core.
Lemma normr_nneg (R : numDomainType) (x : R) : `|x| \is Num.nneg.
Proof. by rewrite qualifE /=. Qed.
#[global] Hint Resolve normr_nneg : core.
Section NumDomainOperationTheory.
Variable R : numDomainType.
Implicit Types x y z t : R.
(* Comparison and opposite. *)
Lemma lerN2 : {mono -%R : x y /~ x <= y :> R}.
Proof. by move=> x y /=; rewrite -subr_ge0 opprK addrC subr_ge0. Qed.
Hint Resolve lerN2 : core.
Lemma ltrN2 : {mono -%R : x y /~ x < y :> R}.
Proof. by move=> x y /=; rewrite leW_nmono. Qed.
Hint Resolve ltrN2 : core.
Definition lterN2 := (lerN2, ltrN2).
Lemma lerNr x y : (x <= - y) = (y <= - x).
Proof. by rewrite (monoRL opprK lerN2). Qed.
Lemma ltrNr x y : (x < - y) = (y < - x).
Proof. by rewrite (monoRL opprK (leW_nmono _)). Qed.
Definition lterNr := (lerNr, ltrNr).
Lemma lerNl x y : (- x <= y) = (- y <= x).
Proof. by rewrite (monoLR opprK lerN2). Qed.
Lemma ltrNl x y : (- x < y) = (- y < x).
Proof. by rewrite (monoLR opprK (leW_nmono _)). Qed.
Definition lterNl := (lerNl, ltrNl).
Lemma oppr_ge0 x : (0 <= - x) = (x <= 0). Proof. by rewrite lerNr oppr0. Qed.
Lemma oppr_gt0 x : (0 < - x) = (x < 0). Proof. by rewrite ltrNr oppr0. Qed.
Definition oppr_gte0 := (oppr_ge0, oppr_gt0).
Lemma oppr_le0 x : (- x <= 0) = (0 <= x). Proof. by rewrite lerNl oppr0. Qed.
Lemma oppr_lt0 x : (- x < 0) = (0 < x). Proof. by rewrite ltrNl oppr0. Qed.
Lemma gtrN x : 0 < x -> - x < x.
Proof. by move=> n0; rewrite -subr_lt0 -opprD oppr_lt0 addr_gt0. Qed.
Definition oppr_lte0 := (oppr_le0, oppr_lt0).
Definition oppr_cp0 := (oppr_gte0, oppr_lte0).
Definition lterNE := (oppr_cp0, lterN2).
Lemma ge0_cp x : 0 <= x -> (- x <= 0) * (- x <= x).
Proof. by move=> hx; rewrite oppr_cp0 hx (@le_trans _ _ 0) ?oppr_cp0. Qed.
Lemma gt0_cp x : 0 < x ->
(0 <= x) * (- x <= 0) * (- x <= x) * (- x < 0) * (- x < x).
Proof.
move=> hx; move: (ltW hx) => hx'; rewrite !ge0_cp hx' //.
by rewrite oppr_cp0 hx // (@lt_trans _ _ 0) ?oppr_cp0.
Qed.
Lemma le0_cp x : x <= 0 -> (0 <= - x) * (x <= - x).
Proof. by move=> hx; rewrite oppr_cp0 hx (@le_trans _ _ 0) ?oppr_cp0. Qed.
Lemma lt0_cp x :
x < 0 -> (x <= 0) * (0 <= - x) * (x <= - x) * (0 < - x) * (x < - x).
Proof.
move=> hx; move: (ltW hx) => hx'; rewrite !le0_cp // hx'.
by rewrite oppr_cp0 hx // (@lt_trans _ _ 0) ?oppr_cp0.
Qed.
(* Properties of the real subset. *)
Lemma ger0_real x : 0 <= x -> x \is real.
Proof. by rewrite realE => ->. Qed.
Lemma ler0_real x : x <= 0 -> x \is real.
Proof. by rewrite realE orbC => ->. Qed.
Lemma gtr0_real x : 0 < x -> x \is real. Proof. by move=> /ltW/ger0_real. Qed.
Lemma ltr0_real x : x < 0 -> x \is real. Proof. by move=> /ltW/ler0_real. Qed.
Lemma real0 : 0 \is @real R. Proof. exact: rpred0. Qed.
Lemma real1 : 1 \is @real R. Proof. exact: rpred1. Qed.
Lemma realn n : n%:R \is @real R. Proof. exact: rpred_nat. Qed.
#[local] Hint Resolve real0 real1 : core.
Lemma ler_leVge x y : x <= 0 -> y <= 0 -> (x <= y) || (y <= x).
Proof. by rewrite -!oppr_ge0 => /(ger_leVge _) /[apply]; rewrite !lerN2. Qed.
Lemma real_leVge x y : x \is real -> y \is real -> (x <= y) || (y <= x).
Proof. by rewrite -comparabler0 -comparable0r => /comparabler_trans P/P. Qed.
Lemma real_comparable x y : x \is real -> y \is real -> x >=< y.
Proof. exact: real_leVge. Qed.
Lemma realB : {in real &, forall x y, x - y \is real}.
Proof. exact: rpredB. Qed.
Lemma realN : {mono (@GRing.opp R) : x / x \is real}.
Proof. exact: rpredN. Qed.
Lemma realBC x y : (x - y \is real) = (y - x \is real).
Proof. exact: rpredBC. Qed.
Lemma realD : {in real &, forall x y, x + y \is real}.
Proof. exact: rpredD. Qed.
(* dichotomy and trichotomy *)
Variant ler_xor_gt (x y : R) : R -> R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| LerNotGt of x <= y : ler_xor_gt x y x x y y (y - x) (y - x) true false
| GtrNotLe of y < x : ler_xor_gt x y y y x x (x - y) (x - y) false true.
Variant ltr_xor_ge (x y : R) : R -> R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| LtrNotGe of x < y : ltr_xor_ge x y x x y y (y - x) (y - x) false true
| GerNotLt of y <= x : ltr_xor_ge x y y y x x (x - y) (x - y) true false.
Variant comparer x y : R -> R -> R -> R -> R -> R ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| ComparerLt of x < y : comparer x y x x y y (y - x) (y - x)
false false false true false true
| ComparerGt of x > y : comparer x y y y x x (x - y) (x - y)
false false true false true false
| ComparerEq of x = y : comparer x y x x x x 0 0
true true true true false false.
Lemma real_leP x y : x \is real -> y \is real ->
ler_xor_gt x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (x <= y) (y < x).
Proof.
move=> xR yR; case: (comparable_leP (real_leVge xR yR)) => xy.
- by rewrite [`|x - y|]distrC !ger0_norm ?subr_cp0 //; constructor.
- by rewrite [`|y - x|]distrC !gtr0_norm ?subr_cp0 //; constructor.
Qed.
Lemma real_ltP x y : x \is real -> y \is real ->
ltr_xor_ge x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (y <= x) (x < y).
Proof. by move=> xR yR; case: real_leP=> //; constructor. Qed.
Lemma real_ltNge : {in real &, forall x y, (x < y) = ~~ (y <= x)}.
Proof. by move=> x y xR yR /=; case: real_leP. Qed.
Lemma real_leNgt : {in real &, forall x y, (x <= y) = ~~ (y < x)}.
Proof. by move=> x y xR yR /=; case: real_leP. Qed.
Lemma real_ltgtP x y : x \is real -> y \is real ->
comparer x y (min y x) (min x y) (max y x) (max x y) `|x - y| `|y - x|
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof.
move=> xR yR; case: (comparable_ltgtP (real_leVge yR xR)) => [?|?|->].
- by rewrite [`|y - x|]distrC !gtr0_norm ?subr_gt0//; constructor.
- by rewrite [`|x - y|]distrC !gtr0_norm ?subr_gt0//; constructor.
- by rewrite subrr normr0; constructor.
Qed.
Variant ger0_xor_lt0 (x : R) : R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| Ger0NotLt0 of 0 <= x : ger0_xor_lt0 x 0 0 x x x false true
| Ltr0NotGe0 of x < 0 : ger0_xor_lt0 x x x 0 0 (- x) true false.
Variant ler0_xor_gt0 (x : R) : R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| Ler0NotLe0 of x <= 0 : ler0_xor_gt0 x x x 0 0 (- x) false true
| Gtr0NotGt0 of 0 < x : ler0_xor_gt0 x 0 0 x x x true false.
Variant comparer0 x : R -> R -> R -> R -> R ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| ComparerGt0 of 0 < x : comparer0 x 0 0 x x x false false false true false true
| ComparerLt0 of x < 0 : comparer0 x x x 0 0 (- x) false false true false true false
| ComparerEq0 of x = 0 : comparer0 x 0 0 0 0 0 true true true true false false.
Lemma real_ge0P x : x \is real -> ger0_xor_lt0 x
(min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (x < 0) (0 <= x).
Proof.
move=> hx; rewrite -[X in `|X|]subr0; case: real_leP;
by rewrite ?subr0 ?sub0r //; constructor.
Qed.
Lemma real_le0P x : x \is real -> ler0_xor_gt0 x
(min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 < x) (x <= 0).
Proof.
move=> hx; rewrite -[X in `|X|]subr0; case: real_ltP;
by rewrite ?subr0 ?sub0r //; constructor.
Qed.
Lemma real_ltgt0P x : x \is real ->
comparer0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 == x) (x == 0) (x <= 0) (0 <= x) (x < 0) (x > 0).
Proof.
move=> hx; rewrite -[X in `|X|]subr0; case: (@real_ltgtP 0 x);
by rewrite ?subr0 ?sub0r //; constructor.
Qed.
Lemma max_real : {in real &, forall x y, max x y \is real}.
Proof. exact: comparable_maxr. Qed.
Lemma min_real : {in real &, forall x y, min x y \is real}.
Proof. exact: comparable_minr. Qed.
Lemma bigmax_real I x0 (r : seq I) (P : pred I) (f : I -> R):
x0 \is real -> {in P, forall i : I, f i \is real} ->
\big[max/x0]_(i <- r | P i) f i \is real.
Proof. exact/big_real/max_real. Qed.
Lemma bigmin_real I x0 (r : seq I) (P : pred I) (f : I -> R):
x0 \is real -> {in P, forall i : I, f i \is real} ->
\big[min/x0]_(i <- r | P i) f i \is real.
Proof. exact/big_real/min_real. Qed.
Lemma real_neqr_lt : {in real &, forall x y, (x != y) = (x < y) || (y < x)}.
Proof. by move=> * /=; case: real_ltgtP. Qed.
Lemma lerB_real x y : x <= y -> y - x \is real.
Proof. by move=> le_xy; rewrite ger0_real // subr_ge0. Qed.
Lemma gerB_real x y : x <= y -> x - y \is real.
Proof. by move=> le_xy; rewrite ler0_real // subr_le0. Qed.
Lemma ler_real y x : x <= y -> (x \is real) = (y \is real).
Proof. by move=> le_xy; rewrite -(addrNK x y) rpredDl ?lerB_real. Qed.
Lemma ger_real x y : y <= x -> (x \is real) = (y \is real).
Proof. by move=> le_yx; rewrite -(ler_real le_yx). Qed.
Lemma ger1_real x : 1 <= x -> x \is real. Proof. by move=> /ger_real->. Qed.
Lemma ler1_real x : x <= 1 -> x \is real. Proof. by move=> /ler_real->. Qed.
Lemma Nreal_leF x y : y \is real -> x \notin real -> (x <= y) = false.
Proof. by move=> yR; apply: contraNF=> /ler_real->. Qed.
Lemma Nreal_geF x y : y \is real -> x \notin real -> (y <= x) = false.
Proof. by move=> yR; apply: contraNF=> /ger_real->. Qed.
Lemma Nreal_ltF x y : y \is real -> x \notin real -> (x < y) = false.
Proof. by move=> yR xNR; rewrite lt_def Nreal_leF ?andbF. Qed.
Lemma Nreal_gtF x y : y \is real -> x \notin real -> (y < x) = false.
Proof. by move=> yR xNR; rewrite lt_def Nreal_geF ?andbF. Qed.
(* real wlog *)
Lemma real_wlog_ler P :
(forall a b, P b a -> P a b) -> (forall a b, a <= b -> P a b) ->
forall a b : R, a \is real -> b \is real -> P a b.
Proof.
move=> sP hP a b ha hb; wlog: a b ha hb / a <= b => [hwlog|]; last exact: hP.
by case: (real_leP ha hb)=> [/hP //|/ltW hba]; apply/sP/hP.
Qed.
Lemma real_wlog_ltr P :
(forall a, P a a) -> (forall a b, (P b a -> P a b)) ->
(forall a b, a < b -> P a b) ->
forall a b : R, a \is real -> b \is real -> P a b.
Proof.
move=> rP sP hP; apply: real_wlog_ler=> // a b.
by rewrite le_eqVlt; case: eqVneq => [->|] //= _ /hP.
Qed.
(* Monotony of addition *)
Lemma lerD2l x : {mono +%R x : y z / y <= z}.
Proof. by move=> y z; rewrite -subr_ge0 opprD addrAC addNKr addrC subr_ge0. Qed.
Lemma lerD2r x : {mono +%R^~ x : y z / y <= z}.
Proof. by move=> y z; rewrite ![_ + x]addrC lerD2l. Qed.
Lemma ltrD2l x : {mono +%R x : y z / y < z}.
Proof. by move=> y z; rewrite (leW_mono (lerD2l _)). Qed.
Lemma ltrD2r x : {mono +%R^~ x : y z / y < z}.
Proof. by move=> y z /=; rewrite (leW_mono (lerD2r _)). Qed.
Definition lerD2 := (lerD2l, lerD2r).
Definition ltrD2 := (ltrD2l, ltrD2r).
Definition lterD2 := (lerD2, ltrD2).
(* Addition, subtraction and transitivity *)
Lemma lerD x y z t : x <= y -> z <= t -> x + z <= y + t.
Proof. by move=> lxy lzt; rewrite (@le_trans _ _ (y + z)) ?lterD2. Qed.
Lemma ler_ltD x y z t : x <= y -> z < t -> x + z < y + t.
Proof. by move=> lxy lzt; rewrite (@le_lt_trans _ _ (y + z)) ?lterD2. Qed.
Lemma ltr_leD x y z t : x < y -> z <= t -> x + z < y + t.
Proof. by move=> lxy lzt; rewrite (@lt_le_trans _ _ (y + z)) ?lterD2. Qed.
Lemma ltrD x y z t : x < y -> z < t -> x + z < y + t.
Proof. by move=> lxy lzt; rewrite ltr_leD // ltW. Qed.
Lemma lerB x y z t : x <= y -> t <= z -> x - z <= y - t.
Proof. by move=> lxy ltz; rewrite lerD // lterN2. Qed.
Lemma ler_ltB x y z t : x <= y -> t < z -> x - z < y - t.
Proof. by move=> lxy lzt; rewrite ler_ltD // lterN2. Qed.
Lemma ltr_leB x y z t : x < y -> t <= z -> x - z < y - t.
Proof. by move=> lxy lzt; rewrite ltr_leD // lterN2. Qed.
Lemma ltrB x y z t : x < y -> t < z -> x - z < y - t.
Proof. by move=> lxy lzt; rewrite ltrD // lterN2. Qed.
Lemma lerBlDr x y z : (x - y <= z) = (x <= z + y).
Proof. by rewrite (monoLR (addrK _) (lerD2r _)). Qed.
Lemma ltrBlDr x y z : (x - y < z) = (x < z + y).
Proof. by rewrite (monoLR (addrK _) (ltrD2r _)). Qed.
Lemma lerBrDr x y z : (x <= y - z) = (x + z <= y).
Proof. by rewrite (monoLR (addrNK _) (lerD2r _)). Qed.
Lemma ltrBrDr x y z : (x < y - z) = (x + z < y).
Proof. by rewrite (monoLR (addrNK _) (ltrD2r _)). Qed.
Definition lerBDr := (lerBlDr, lerBrDr).
Definition ltrBDr := (ltrBlDr, ltrBrDr).
Definition lterBDr := (lerBDr, ltrBDr).
Lemma lerBlDl x y z : (x - y <= z) = (x <= y + z).
Proof. by rewrite lterBDr addrC. Qed.
Lemma ltrBlDl x y z : (x - y < z) = (x < y + z).
Proof. by rewrite lterBDr addrC. Qed.
Lemma lerBrDl x y z : (x <= y - z) = (z + x <= y).
Proof. by rewrite lerBrDr addrC. Qed.
Lemma ltrBrDl x y z : (x < y - z) = (z + x < y).
Proof. by rewrite lterBDr addrC. Qed.
Definition lerBDl := (lerBlDl, lerBrDl).
Definition ltrBDl := (ltrBlDl, ltrBrDl).
Definition lterBDl := (lerBDl, ltrBDl).
Lemma lerDl x y : (x <= x + y) = (0 <= y).
Proof. by rewrite -{1}[x]addr0 lterD2. Qed.
Lemma ltrDl x y : (x < x + y) = (0 < y).
Proof. by rewrite -{1}[x]addr0 lterD2. Qed.
Lemma lerDr x y : (x <= y + x) = (0 <= y).
Proof. by rewrite -{1}[x]add0r lterD2. Qed.
Lemma ltrDr x y : (x < y + x) = (0 < y).
Proof. by rewrite -{1}[x]add0r lterD2. Qed.
Lemma gerDl x y : (x + y <= x) = (y <= 0).
Proof. by rewrite -{2}[x]addr0 lterD2. Qed.
Lemma gerBl x y : (x - y <= x) = (0 <= y).
Proof. by rewrite lerBlDl lerDr. Qed.
Lemma gtrDl x y : (x + y < x) = (y < 0).
Proof. by rewrite -{2}[x]addr0 lterD2. Qed.
Lemma gtrBl x y : (x - y < x) = (0 < y).
Proof. by rewrite ltrBlDl ltrDr. Qed.
Lemma gerDr x y : (y + x <= x) = (y <= 0).
Proof. by rewrite -{2}[x]add0r lterD2. Qed.
Lemma gtrDr x y : (y + x < x) = (y < 0).
Proof. by rewrite -{2}[x]add0r lterD2. Qed.
Definition cprD := (lerDl, lerDr, gerDl, gerDl,
ltrDl, ltrDr, gtrDl, gtrDl).
(* Addition with left member known to be positive/negative *)
Lemma ler_wpDl y x z : 0 <= x -> y <= z -> y <= x + z.
Proof. by move=> *; rewrite -[y]add0r lerD. Qed.
Lemma ltr_wpDl y x z : 0 <= x -> y < z -> y < x + z.
Proof. by move=> *; rewrite -[y]add0r ler_ltD. Qed.
Lemma ltr_pwDl y x z : 0 < x -> y <= z -> y < x + z.
Proof. by move=> *; rewrite -[y]add0r ltr_leD. Qed.
Lemma ltr_pDl y x z : 0 < x -> y < z -> y < x + z.
Proof. by move=> *; rewrite -[y]add0r ltrD. Qed.
Lemma ler_wnDl y x z : x <= 0 -> y <= z -> x + y <= z.
Proof. by move=> *; rewrite -[z]add0r lerD. Qed.
Lemma ltr_wnDl y x z : x <= 0 -> y < z -> x + y < z.
Proof. by move=> *; rewrite -[z]add0r ler_ltD. Qed.
Lemma ltr_nwDl y x z : x < 0 -> y <= z -> x + y < z.
Proof. by move=> *; rewrite -[z]add0r ltr_leD. Qed.
Lemma ltr_nDl y x z : x < 0 -> y < z -> x + y < z.
Proof. by move=> *; rewrite -[z]add0r ltrD. Qed.
(* Addition with right member we know positive/negative *)
Lemma ler_wpDr y x z : 0 <= x -> y <= z -> y <= z + x.
Proof. by move=> *; rewrite addrC ler_wpDl. Qed.
Lemma ltr_wpDr y x z : 0 <= x -> y < z -> y < z + x.
Proof. by move=> *; rewrite addrC ltr_wpDl. Qed.
Lemma ltr_pwDr y x z : 0 < x -> y <= z -> y < z + x.
Proof. by move=> *; rewrite addrC ltr_pwDl. Qed.
Lemma ltr_pDr y x z : 0 < x -> y < z -> y < z + x.
Proof. by move=> *; rewrite addrC ltr_pDl. Qed.
Lemma ler_wnDr y x z : x <= 0 -> y <= z -> y + x <= z.
Proof. by move=> *; rewrite addrC ler_wnDl. Qed.
Lemma ltr_wnDr y x z : x <= 0 -> y < z -> y + x < z.
Proof. by move=> *; rewrite addrC ltr_wnDl. Qed.
Lemma ltr_nwDr y x z : x < 0 -> y <= z -> y + x < z.
Proof. by move=> *; rewrite addrC ltr_nwDl. Qed.
Lemma ltr_nDr y x z : x < 0 -> y < z -> y + x < z.
Proof. by move=> *; rewrite addrC ltr_nDl. Qed.
(* x and y have the same sign and their sum is null *)
Lemma paddr_eq0 (x y : R) :
0 <= x -> 0 <= y -> (x + y == 0) = (x == 0) && (y == 0).
Proof.
rewrite le0r; case/orP=> [/eqP->|hx]; first by rewrite add0r eqxx.
by rewrite (gt_eqF hx) /= => hy; rewrite gt_eqF // ltr_pwDl.
Qed.
Lemma naddr_eq0 (x y : R) :
x <= 0 -> y <= 0 -> (x + y == 0) = (x == 0) && (y == 0).
Proof.
by move=> lex0 ley0; rewrite -oppr_eq0 opprD paddr_eq0 ?oppr_cp0 // !oppr_eq0.
Qed.
Lemma addr_ss_eq0 (x y : R) :
(0 <= x) && (0 <= y) || (x <= 0) && (y <= 0) ->
(x + y == 0) = (x == 0) && (y == 0).
Proof. by case/orP=> /andP []; [apply: paddr_eq0 | apply: naddr_eq0]. Qed.
(* big sum and ler *)
Lemma sumr_ge0 I (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> 0 <= \sum_(i <- r | P i) (F i).
Proof. exact: (big_ind _ _ (@ler_wpDl 0)). Qed.
Lemma sumr_le0 I (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> F i <= 0) -> \sum_(i <- r | P i) F i <= 0.
Proof. by move=> F0; elim/big_ind : _ => // i x Pi; exact/ler_wnDl. Qed.
Lemma ler_sum I (r : seq I) (P : pred I) (F G : I -> R) :
(forall i, P i -> F i <= G i) ->
\sum_(i <- r | P i) F i <= \sum_(i <- r | P i) G i.
Proof. exact: (big_ind2 _ (lexx _) lerD). Qed.
Lemma ler_sum_nat (m n : nat) (F G : nat -> R) :
(forall i, (m <= i < n)%N -> F i <= G i) ->
\sum_(m <= i < n) F i <= \sum_(m <= i < n) G i.
Proof. by move=> le_FG; rewrite !big_nat ler_sum. Qed.
Lemma ltr_sum I (r : seq I) (P : pred I) (F G : I -> R) :
has P r -> (forall i, P i -> F i < G i) ->
\sum_(i <- r | P i) F i < \sum_(i <- r | P i) G i.
Proof.
rewrite -big_filter -[ltRHS]big_filter -size_filter_gt0.
case: filter (filter_all P r) => //= x {}r /andP[Px Pr] _ ltFG.
rewrite !big_cons ltr_leD// ?ltFG// -(all_filterP Pr) !big_filter.
by rewrite ler_sum => // i Pi; rewrite ltW ?ltFG.
Qed.
Lemma ltr_sum_nat (m n : nat) (F G : nat -> R) :
(m < n)%N -> (forall i, (m <= i < n)%N -> F i < G i) ->
\sum_(m <= i < n) F i < \sum_(m <= i < n) G i.
Proof.
move=> lt_mn i; rewrite big_nat [ltRHS]big_nat ltr_sum//.
by apply/hasP; exists m; rewrite ?mem_index_iota leqnn lt_mn.
Qed.
Lemma psumr_eq0 (I : eqType) (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) ->
(\sum_(i <- r | P i) (F i) == 0) = (all (fun i => (P i) ==> (F i == 0)) r).
Proof.
elim: r=> [|a r ihr hr] /=; rewrite (big_nil, big_cons); first by rewrite eqxx.
by case: ifP=> pa /=; rewrite ?paddr_eq0 ?ihr ?hr // sumr_ge0.
Qed.
(* :TODO: Cyril : See which form to keep *)
Lemma psumr_eq0P (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> \sum_(i | P i) F i = 0 ->
(forall i, P i -> F i = 0).
Proof.
move=> F_ge0 /eqP; rewrite psumr_eq0 // -big_all big_andE => /forallP hF i Pi.
by move: (hF i); rewrite implyTb Pi /= => /eqP.
Qed.
Lemma psumr_neq0 (I : eqType) (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) ->
(\sum_(i <- r | P i) (F i) != 0) = (has (fun i => P i && (0 < F i)) r).
Proof.
move=> F_ge0; rewrite psumr_eq0// -has_predC; apply: eq_has => x /=.
by case Px: (P x); rewrite //= lt_def F_ge0 ?andbT.
Qed.
Lemma psumr_neq0P (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> \sum_(i | P i) F i <> 0 ->
(exists i, P i && (0 < F i)).
Proof. by move=> ? /eqP; rewrite psumr_neq0// => /hasP[x _ ?]; exists x. Qed.
(* mulr and ler/ltr *)
Lemma ler_pM2l x : 0 < x -> {mono *%R x : x y / x <= y}.
Proof.
by move=> x_gt0 y z /=; rewrite -subr_ge0 -mulrBr pmulr_rge0 // subr_ge0.
Qed.
Lemma ltr_pM2l x : 0 < x -> {mono *%R x : x y / x < y}.
Proof. by move=> x_gt0; apply: leW_mono (ler_pM2l _). Qed.
Definition lter_pM2l := (ler_pM2l, ltr_pM2l).
Lemma ler_pM2r x : 0 < x -> {mono *%R^~ x : x y / x <= y}.
Proof. by move=> x_gt0 y z /=; rewrite ![_ * x]mulrC ler_pM2l. Qed.
Lemma ltr_pM2r x : 0 < x -> {mono *%R^~ x : x y / x < y}.
Proof. by move=> x_gt0; apply: leW_mono (ler_pM2r _). Qed.
Definition lter_pM2r := (ler_pM2r, ltr_pM2r).
Lemma ler_nM2l x : x < 0 -> {mono *%R x : x y /~ x <= y}.
Proof. by move=> x_lt0 y z /=; rewrite -lerN2 -!mulNr ler_pM2l ?oppr_gt0. Qed.
Lemma ltr_nM2l x : x < 0 -> {mono *%R x : x y /~ x < y}.
Proof. by move=> x_lt0; apply: leW_nmono (ler_nM2l _). Qed.
Definition lter_nM2l := (ler_nM2l, ltr_nM2l).
Lemma ler_nM2r x : x < 0 -> {mono *%R^~ x : x y /~ x <= y}.
Proof. by move=> x_lt0 y z /=; rewrite ![_ * x]mulrC ler_nM2l. Qed.
Lemma ltr_nM2r x : x < 0 -> {mono *%R^~ x : x y /~ x < y}.
Proof. by move=> x_lt0; apply: leW_nmono (ler_nM2r _). Qed.
Definition lter_nM2r := (ler_nM2r, ltr_nM2r).
Lemma ler_wpM2l x : 0 <= x -> {homo *%R x : y z / y <= z}.
Proof.
by rewrite le0r => /orP[/eqP-> y z | /ler_pM2l/mono2W//]; rewrite !mul0r.
Qed.
Lemma ler_wpM2r x : 0 <= x -> {homo *%R^~ x : y z / y <= z}.
Proof. by move=> x_ge0 y z leyz; rewrite ![_ * x]mulrC ler_wpM2l. Qed.
Lemma ler_wnM2l x : x <= 0 -> {homo *%R x : y z /~ y <= z}.
by move=> x_le0 y z leyz; rewrite -![x * _]mulrNN ler_wpM2l ?lterNE. Qed.
Lemma ler_wnM2r x : x <= 0 -> {homo *%R^~ x : y z /~ y <= z}.
Proof. by move=> x_le0 y z leyz; rewrite -![_ * x]mulrNN ler_wpM2r ?lterNE. Qed.
(* Binary forms, for backchaining. *)
Lemma ler_pM x1 y1 x2 y2 :
0 <= x1 -> 0 <= x2 -> x1 <= y1 -> x2 <= y2 -> x1 * x2 <= y1 * y2.
Proof.
move=> x1ge0 x2ge0 le_xy1 le_xy2; have y1ge0 := le_trans x1ge0 le_xy1.
exact: le_trans (ler_wpM2r x2ge0 le_xy1) (ler_wpM2l y1ge0 le_xy2).
Qed.
Lemma ltr_pM x1 y1 x2 y2 :
0 <= x1 -> 0 <= x2 -> x1 < y1 -> x2 < y2 -> x1 * x2 < y1 * y2.
Proof.
move=> x1ge0 x2ge0 lt_xy1 lt_xy2; have y1gt0 := le_lt_trans x1ge0 lt_xy1.
by rewrite (le_lt_trans (ler_wpM2r x2ge0 (ltW lt_xy1))) ?ltr_pM2l.
Qed.
(* complement for x *+ n and <= or < *)
Lemma ler_pMn2r n : (0 < n)%N -> {mono (@GRing.natmul R)^~ n : x y / x <= y}.
Proof.
by case: n => // n _ x y /=; rewrite -mulr_natl -[y *+ _]mulr_natl ler_pM2l.
Qed.
Lemma ltr_pMn2r n : (0 < n)%N -> {mono (@GRing.natmul R)^~ n : x y / x < y}.
Proof. by move/ler_pMn2r/leW_mono. Qed.
Lemma pmulrnI n : (0 < n)%N -> injective ((@GRing.natmul R)^~ n).
Proof. by move/ler_pMn2r/inc_inj. Qed.
Lemma eqr_pMn2r n : (0 < n)%N -> {mono (@GRing.natmul R)^~ n : x y / x == y}.
Proof. by move/pmulrnI/inj_eq. Qed.
Lemma pmulrn_lgt0 x n : (0 < n)%N -> (0 < x *+ n) = (0 < x).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ltr_pMn2r // mul0rn. Qed.
Lemma pmulrn_llt0 x n : (0 < n)%N -> (x *+ n < 0) = (x < 0).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ltr_pMn2r // mul0rn. Qed.
Lemma pmulrn_lge0 x n : (0 < n)%N -> (0 <= x *+ n) = (0 <= x).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ler_pMn2r // mul0rn. Qed.
Lemma pmulrn_lle0 x n : (0 < n)%N -> (x *+ n <= 0) = (x <= 0).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ler_pMn2r // mul0rn. Qed.
Lemma ltr_wMn2r x y n : x < y -> (x *+ n < y *+ n) = (0 < n)%N.
Proof. by move=> ltxy; case: n=> // n; rewrite ltr_pMn2r. Qed.
Lemma ltr_wpMn2r n : (0 < n)%N -> {homo (@GRing.natmul R)^~ n : x y / x < y}.
Proof. by move=> n_gt0 x y /= / ltr_wMn2r ->. Qed.
Lemma ler_wMn2r n : {homo (@GRing.natmul R)^~ n : x y / x <= y}.
Proof. by move=> x y hxy /=; case: n=> // n; rewrite ler_pMn2r. Qed.
Lemma mulrn_wge0 x n : 0 <= x -> 0 <= x *+ n.
Proof. by move=> /(ler_wMn2r n); rewrite mul0rn. Qed.
Lemma mulrn_wle0 x n : x <= 0 -> x *+ n <= 0.
Proof. by move=> /(ler_wMn2r n); rewrite mul0rn. Qed.
Lemma lerMn2r n x y : (x *+ n <= y *+ n) = ((n == 0) || (x <= y)).
Proof. by case: n => [|n]; rewrite ?lexx ?eqxx // ler_pMn2r. Qed.
Lemma ltrMn2r n x y : (x *+ n < y *+ n) = ((0 < n)%N && (x < y)).
Proof. by case: n => [|n]; rewrite ?lexx ?eqxx // ltr_pMn2r. Qed.
Lemma eqrMn2r n x y : (x *+ n == y *+ n) = (n == 0)%N || (x == y).
Proof. by rewrite !(@eq_le _ R) !lerMn2r -orb_andr. Qed.
(* More characteristic zero properties. *)
Lemma mulrn_eq0 x n : (x *+ n == 0) = ((n == 0)%N || (x == 0)).
Proof. by rewrite -mulr_natl mulf_eq0 pnatr_eq0. Qed.
Lemma eqNr x : (- x == x) = (x == 0).
Proof. by rewrite eq_sym -addr_eq0 -mulr2n mulrn_eq0. Qed.
Lemma mulrIn x : x != 0 -> injective (GRing.natmul x).
Proof.
move=> x_neq0 m n; without loss /subnK <-: m n / (n <= m)%N.
by move=> IH eq_xmn; case/orP: (leq_total m n) => /IH->.
by move/eqP; rewrite mulrnDr -subr_eq0 addrK mulrn_eq0 => /predU1P[-> | /idPn].
Qed.
Lemma ler_wpMn2l x :
0 <= x -> {homo (@GRing.natmul R x) : m n / (m <= n)%N >-> m <= n}.
Proof. by move=> xge0 m n /subnK <-; rewrite mulrnDr ler_wpDl ?mulrn_wge0. Qed.
Lemma ler_wnMn2l x :
x <= 0 -> {homo (@GRing.natmul R x) : m n / (n <= m)%N >-> m <= n}.
Proof.
by move=> xle0 m n hmn /=; rewrite -lerN2 -!mulNrn ler_wpMn2l // oppr_cp0.
Qed.
Lemma mulrn_wgt0 x n : 0 < x -> 0 < x *+ n = (0 < n)%N.
Proof. by case: n => // n hx; rewrite pmulrn_lgt0. Qed.
Lemma mulrn_wlt0 x n : x < 0 -> x *+ n < 0 = (0 < n)%N.
Proof. by case: n => // n hx; rewrite pmulrn_llt0. Qed.
Lemma ler_pMn2l x :
0 < x -> {mono (@GRing.natmul R x) : m n / (m <= n)%N >-> m <= n}.
Proof.
move=> x_gt0 m n /=; case: leqP => hmn; first by rewrite ler_wpMn2l // ltW.
by rewrite -(subnK (ltnW hmn)) mulrnDr gerDr lt_geF // mulrn_wgt0 // subn_gt0.
Qed.
Lemma ltr_pMn2l x :
0 < x -> {mono (@GRing.natmul R x) : m n / (m < n)%N >-> m < n}.
Proof. by move=> x_gt0; apply: leW_mono (ler_pMn2l _). Qed.
Lemma ler_nMn2l x :
x < 0 -> {mono (@GRing.natmul R x) : m n / (n <= m)%N >-> m <= n}.
Proof. by move=> xlt0 m n /=; rewrite -lerN2 -!mulNrn ler_pMn2l// oppr_gt0. Qed.
Lemma ltr_nMn2l x :
x < 0 -> {mono (@GRing.natmul R x) : m n / (n < m)%N >-> m < n}.
Proof. by move=> x_lt0; apply: leW_nmono (ler_nMn2l _). Qed.
Lemma ler_nat m n : (m%:R <= n%:R :> R) = (m <= n)%N.
Proof. by rewrite ler_pMn2l. Qed.
Lemma ltr_nat m n : (m%:R < n%:R :> R) = (m < n)%N.
Proof. by rewrite ltr_pMn2l. Qed.
Lemma eqr_nat m n : (m%:R == n%:R :> R) = (m == n)%N.
Proof. by rewrite (inj_eq (mulrIn _)) ?oner_eq0. Qed.
Lemma pnatr_eq1 n : (n%:R == 1 :> R) = (n == 1)%N.
Proof. exact: eqr_nat 1. Qed.
Lemma lern0 n : (n%:R <= 0 :> R) = (n == 0).
Proof. by rewrite -[0]/0%:R ler_nat leqn0. Qed.
Lemma ltrn0 n : (n%:R < 0 :> R) = false.
Proof. by rewrite -[0]/0%:R ltr_nat ltn0. Qed.
Lemma ler1n n : 1 <= n%:R :> R = (1 <= n)%N. Proof. by rewrite -ler_nat. Qed.
Lemma ltr1n n : 1 < n%:R :> R = (1 < n)%N. Proof. by rewrite -ltr_nat. Qed.
Lemma lern1 n : n%:R <= 1 :> R = (n <= 1)%N. Proof. by rewrite -ler_nat. Qed.
Lemma ltrn1 n : n%:R < 1 :> R = (n < 1)%N. Proof. by rewrite -ltr_nat. Qed.
Lemma ltrN10 : -1 < 0 :> R. Proof. by rewrite oppr_lt0. Qed.
Lemma lerN10 : -1 <= 0 :> R. Proof. by rewrite oppr_le0. Qed.
Lemma ltr10 : 1 < 0 :> R = false. Proof. by rewrite le_gtF. Qed.
Lemma ler10 : 1 <= 0 :> R = false. Proof. by rewrite lt_geF. Qed.
Lemma ltr0N1 : 0 < -1 :> R = false. Proof. by rewrite le_gtF // lerN10. Qed.
Lemma ler0N1 : 0 <= -1 :> R = false. Proof. by rewrite lt_geF // ltrN10. Qed.
#[deprecated(since="mathcomp 2.4.0", note="use `mulrn_wgt0` instead")]
Lemma pmulrn_rgt0 x n : 0 < x -> 0 < x *+ n = (0 < n)%N.
Proof. exact: mulrn_wgt0. Qed.
Lemma pmulrn_rlt0 x n : 0 < x -> x *+ n < 0 = false.
Proof. by move=> x_gt0; rewrite -(mulr0n x) ltr_pMn2l. Qed.
Lemma pmulrn_rge0 x n : 0 < x -> 0 <= x *+ n.
Proof. by move=> x_gt0; rewrite -(mulr0n x) ler_pMn2l. Qed.
Lemma pmulrn_rle0 x n : 0 < x -> x *+ n <= 0 = (n == 0)%N.
Proof. by move=> x_gt0; rewrite -(mulr0n x) ler_pMn2l ?leqn0. Qed.
Lemma nmulrn_rgt0 x n : x < 0 -> 0 < x *+ n = false.
Proof. by move=> x_lt0; rewrite -(mulr0n x) ltr_nMn2l. Qed.
Lemma nmulrn_rge0 x n : x < 0 -> 0 <= x *+ n = (n == 0)%N.
Proof. by move=> x_lt0; rewrite -(mulr0n x) ler_nMn2l ?leqn0. Qed.
Lemma nmulrn_rle0 x n : x < 0 -> x *+ n <= 0.
Proof. by move=> x_lt0; rewrite -(mulr0n x) ler_nMn2l. Qed.
(* (x * y) compared to 0 *)
(* Remark : pmulr_rgt0 and pmulr_rge0 are defined above *)
(* x positive and y right *)
Lemma pmulr_rlt0 x y : 0 < x -> (x * y < 0) = (y < 0).
Proof.
by move=> x_gt0; rewrite -[LHS]oppr_gt0 -mulrN pmulr_rgt0 // oppr_gt0.
Qed.
Lemma pmulr_rle0 x y : 0 < x -> (x * y <= 0) = (y <= 0).
Proof.
by move=> x_gt0; rewrite -[LHS]oppr_ge0 -mulrN pmulr_rge0 // oppr_ge0.
Qed.
(* x positive and y left *)
Lemma pmulr_lgt0 x y : 0 < x -> (0 < y * x) = (0 < y).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rgt0. Qed.
Lemma pmulr_lge0 x y : 0 < x -> (0 <= y * x) = (0 <= y).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rge0. Qed.
Lemma pmulr_llt0 x y : 0 < x -> (y * x < 0) = (y < 0).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rlt0. Qed.
Lemma pmulr_lle0 x y : 0 < x -> (y * x <= 0) = (y <= 0).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rle0. Qed.
(* x negative and y right *)
Lemma nmulr_rgt0 x y : x < 0 -> (0 < x * y) = (y < 0).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rgt0 lterNE. Qed.
Lemma nmulr_rge0 x y : x < 0 -> (0 <= x * y) = (y <= 0).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rge0 lterNE. Qed.
Lemma nmulr_rlt0 x y : x < 0 -> (x * y < 0) = (0 < y).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rlt0 lterNE. Qed.
Lemma nmulr_rle0 x y : x < 0 -> (x * y <= 0) = (0 <= y).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rle0 lterNE. Qed.
(* x negative and y left *)
Lemma nmulr_lgt0 x y : x < 0 -> (0 < y * x) = (y < 0).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rgt0. Qed.
Lemma nmulr_lge0 x y : x < 0 -> (0 <= y * x) = (y <= 0).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rge0. Qed.
Lemma nmulr_llt0 x y : x < 0 -> (y * x < 0) = (0 < y).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rlt0. Qed.
Lemma nmulr_lle0 x y : x < 0 -> (y * x <= 0) = (0 <= y).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rle0. Qed.
(* weak and symmetric lemmas *)
Lemma mulr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x * y.
Proof. by move=> x_ge0 y_ge0; rewrite -(mulr0 x) ler_wpM2l. Qed.
Lemma mulr_le0 x y : x <= 0 -> y <= 0 -> 0 <= x * y.
Proof. by move=> x_le0 y_le0; rewrite -(mulr0 x) ler_wnM2l. Qed.
Lemma mulr_ge0_le0 x y : 0 <= x -> y <= 0 -> x * y <= 0.
Proof. by move=> x_le0 y_le0; rewrite -(mulr0 x) ler_wpM2l. Qed.
Lemma mulr_le0_ge0 x y : x <= 0 -> 0 <= y -> x * y <= 0.
Proof. by move=> x_le0 y_le0; rewrite -(mulr0 x) ler_wnM2l. Qed.
(* mulr_gt0 with only one case *)
Lemma mulr_gt0 x y : 0 < x -> 0 < y -> 0 < x * y.
Proof. by move=> x_gt0 y_gt0; rewrite pmulr_rgt0. Qed.
(* and reverse direction *)
Lemma mulr_ge0_gt0 x y : 0 <= x -> 0 <= y -> (0 < x * y) = (0 < x) && (0 < y).
Proof.
rewrite le_eqVlt => /predU1P[<-|x0]; first by rewrite mul0r ltxx.
rewrite le_eqVlt => /predU1P[<-|y0]; first by rewrite mulr0 ltxx andbC.
by apply/idP/andP=> [|_]; rewrite pmulr_rgt0.
Qed.
(* Iterated products *)
Lemma prodr_ge0 I r (P : pred I) (E : I -> R) :
(forall i, P i -> 0 <= E i) -> 0 <= \prod_(i <- r | P i) E i.
Proof. by move=> Ege0; rewrite -nnegrE rpred_prod. Qed.
Lemma prodr_gt0 I r (P : pred I) (E : I -> R) :
(forall i, P i -> 0 < E i) -> 0 < \prod_(i <- r | P i) E i.
Proof. by move=> Ege0; rewrite -posrE rpred_prod. Qed.
Lemma ler_prod I r (P : pred I) (E1 E2 : I -> R) :
(forall i, P i -> 0 <= E1 i <= E2 i) ->
\prod_(i <- r | P i) E1 i <= \prod_(i <- r | P i) E2 i.
Proof.
move=> leE12; elim/(big_load (fun x => 0 <= x)): _.
elim/big_rec2: _ => // i x2 x1 /leE12/andP[le0Ei leEi12] [x1ge0 le_x12].
by rewrite mulr_ge0 // ler_pM.
Qed.
Lemma ltr_prod I r (P : pred I) (E1 E2 : I -> R) :
has P r -> (forall i, P i -> 0 <= E1 i < E2 i) ->
\prod_(i <- r | P i) E1 i < \prod_(i <- r | P i) E2 i.
Proof.
elim: r => //= i r IHr; rewrite !big_cons; case: ifP => {IHr}// Pi _ ltE12.
have /andP[le0E1i ltE12i] := ltE12 i Pi; set E2r := \prod_(j <- r | P j) E2 j.
apply: le_lt_trans (_ : E1 i * E2r < E2 i * E2r).
by rewrite ler_wpM2l ?ler_prod // => j /ltE12/andP[-> /ltW].
by rewrite ltr_pM2r ?prodr_gt0 // => j /ltE12/andP[le0E1j /le_lt_trans->].
Qed.
Lemma ltr_prod_nat (E1 E2 : nat -> R) (n m : nat) :
(m < n)%N -> (forall i, (m <= i < n)%N -> 0 <= E1 i < E2 i) ->
\prod_(m <= i < n) E1 i < \prod_(m <= i < n) E2 i.
Proof.
move=> lt_mn ltE12; rewrite !big_nat ltr_prod {ltE12}//.
by apply/hasP; exists m; rewrite ?mem_index_iota leqnn.
Qed.
(* real of mul *)
Lemma realMr x y : x != 0 -> x \is real -> (x * y \is real) = (y \is real).
Proof.
move=> x_neq0 xR; case: real_ltgtP x_neq0 => // hx _; rewrite !realE.
by rewrite nmulr_rge0 // nmulr_rle0 // orbC.
by rewrite pmulr_rge0 // pmulr_rle0 // orbC.
Qed.
Lemma realrM x y : y != 0 -> y \is real -> (x * y \is real) = (x \is real).
Proof. by move=> y_neq0 yR; rewrite mulrC realMr. Qed.
Lemma realM : {in real &, forall x y, x * y \is real}.
Proof. exact: rpredM. Qed.
Lemma realrMn x n : (n != 0)%N -> (x *+ n \is real) = (x \is real).
Proof. by move=> n_neq0; rewrite -mulr_natl realMr ?realn ?pnatr_eq0. Qed.
(* ler/ltr and multiplication between a positive/negative *)
Lemma ger_pMl x y : 0 < y -> (x * y <= y) = (x <= 1).
Proof. by move=> hy; rewrite -{2}[y]mul1r ler_pM2r. Qed.
Lemma gtr_pMl x y : 0 < y -> (x * y < y) = (x < 1).
Proof. by move=> hy; rewrite -{2}[y]mul1r ltr_pM2r. Qed.
Lemma ger_pMr x y : 0 < y -> (y * x <= y) = (x <= 1).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ler_pM2l. Qed.
Lemma gtr_pMr x y : 0 < y -> (y * x < y) = (x < 1).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ltr_pM2l. Qed.
Lemma ler_pMl x y : 0 < y -> (y <= x * y) = (1 <= x).
Proof. by move=> hy; rewrite -{1}[y]mul1r ler_pM2r. Qed.
Lemma ltr_pMl x y : 0 < y -> (y < x * y) = (1 < x).
Proof. by move=> hy; rewrite -{1}[y]mul1r ltr_pM2r. Qed.
Lemma ler_pMr x y : 0 < y -> (y <= y * x) = (1 <= x).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ler_pM2l. Qed.
Lemma ltr_pMr x y : 0 < y -> (y < y * x) = (1 < x).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ltr_pM2l. Qed.
Lemma ger_nMl x y : y < 0 -> (x * y <= y) = (1 <= x).
Proof. by move=> hy; rewrite -{2}[y]mul1r ler_nM2r. Qed.
Lemma gtr_nMl x y : y < 0 -> (x * y < y) = (1 < x).
Proof. by move=> hy; rewrite -{2}[y]mul1r ltr_nM2r. Qed.
Lemma ger_nMr x y : y < 0 -> (y * x <= y) = (1 <= x).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ler_nM2l. Qed.
Lemma gtr_nMr x y : y < 0 -> (y * x < y) = (1 < x).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ltr_nM2l. Qed.
Lemma ler_nMl x y : y < 0 -> (y <= x * y) = (x <= 1).
Proof. by move=> hy; rewrite -{1}[y]mul1r ler_nM2r. Qed.
Lemma ltr_nMl x y : y < 0 -> (y < x * y) = (x < 1).
Proof. by move=> hy; rewrite -{1}[y]mul1r ltr_nM2r. Qed.
Lemma ler_nMr x y : y < 0 -> (y <= y * x) = (x <= 1).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ler_nM2l. Qed.
Lemma ltr_nMr x y : y < 0 -> (y < y * x) = (x < 1).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ltr_nM2l. Qed.
(* ler/ltr and multiplication between a positive/negative
and a exterior (1 <= _) or interior (0 <= _ <= 1) *)
Lemma ler_peMl x y : 0 <= y -> 1 <= x -> y <= x * y.
Proof. by move=> hy hx; rewrite -{1}[y]mul1r ler_wpM2r. Qed.
Lemma ler_neMl x y : y <= 0 -> 1 <= x -> x * y <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mul1r ler_wnM2r. Qed.
Lemma ler_peMr x y : 0 <= y -> 1 <= x -> y <= y * x.
Proof. by move=> hy hx; rewrite -{1}[y]mulr1 ler_wpM2l. Qed.
Lemma ler_neMr x y : y <= 0 -> 1 <= x -> y * x <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mulr1 ler_wnM2l. Qed.
Lemma ler_piMl x y : 0 <= y -> x <= 1 -> x * y <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mul1r ler_wpM2r. Qed.
Lemma ler_niMl x y : y <= 0 -> x <= 1 -> y <= x * y.
Proof. by move=> hy hx; rewrite -{1}[y]mul1r ler_wnM2r. Qed.
Lemma ler_piMr x y : 0 <= y -> x <= 1 -> y * x <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mulr1 ler_wpM2l. Qed.
Lemma ler_niMr x y : y <= 0 -> x <= 1 -> y <= y * x.
Proof. by move=> hx hy; rewrite -{1}[y]mulr1 ler_wnM2l. Qed.
Lemma mulr_ile1 x y : 0 <= x -> 0 <= y -> x <= 1 -> y <= 1 -> x * y <= 1.
Proof. by move=> *; rewrite (@le_trans _ _ y) ?ler_piMl. Qed.
Lemma prodr_ile1 {I : Type} (s : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i <= 1) -> \prod_(j <- s | P j) F j <= 1.
Proof.
elim: s => [_ | y s ih xs01]; rewrite ?big_nil// big_cons.
case: ifPn => Py; last by rewrite ih.
have /andP[y0 y1] : 0 <= F y <= 1 by rewrite xs01// mem_head.
rewrite mulr_ile1 ?andbT//; last first.
by rewrite ih// => e xs; rewrite xs01// in_cons xs orbT.
by rewrite prodr_ge0// => x /xs01 /andP[].
Qed.
Lemma mulr_ilt1 x y : 0 <= x -> 0 <= y -> x < 1 -> y < 1 -> x * y < 1.
Proof. by move=> *; rewrite (@le_lt_trans _ _ y) ?ler_piMl // ltW. Qed.
Definition mulr_ilte1 := (mulr_ile1, mulr_ilt1).
Lemma mulr_ege1 x y : 1 <= x -> 1 <= y -> 1 <= x * y.
Proof.
by move=> le1x le1y; rewrite (@le_trans _ _ y) ?ler_peMl // (le_trans ler01).
Qed.
Lemma mulr_egt1 x y : 1 < x -> 1 < y -> 1 < x * y.
Proof.
by move=> le1x lt1y; rewrite (@lt_trans _ _ y) // ltr_pMl // (lt_trans ltr01).
Qed.
Definition mulr_egte1 := (mulr_ege1, mulr_egt1).
Definition mulr_cp1 := (mulr_ilte1, mulr_egte1).
(* ler and ^-1 *)
Lemma invr_gt0 x : (0 < x^-1) = (0 < x).
Proof.
have [ux | nux] := boolP (x \is a GRing.unit); last by rewrite invr_out.
by apply/idP/idP=> /ltr_pM2r <-; rewrite mul0r (mulrV, mulVr) ?ltr01.
Qed.
Lemma invr_ge0 x : (0 <= x^-1) = (0 <= x).
Proof. by rewrite !le0r invr_gt0 invr_eq0. Qed.
Lemma invr_lt0 x : (x^-1 < 0) = (x < 0).
Proof. by rewrite -oppr_cp0 -invrN invr_gt0 oppr_cp0. Qed.
Lemma invr_le0 x : (x^-1 <= 0) = (x <= 0).
Proof. by rewrite -oppr_cp0 -invrN invr_ge0 oppr_cp0. Qed.
Definition invr_gte0 := (invr_ge0, invr_gt0).
Definition invr_lte0 := (invr_le0, invr_lt0).
Lemma divr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x / y.
Proof. by move=> x_ge0 y_ge0; rewrite mulr_ge0 ?invr_ge0. Qed.
Lemma divr_gt0 x y : 0 < x -> 0 < y -> 0 < x / y.
Proof. by move=> x_gt0 y_gt0; rewrite pmulr_rgt0 ?invr_gt0. Qed.
Lemma realV : {mono (@GRing.inv R) : x / x \is real}.
Proof. exact: rpredV. Qed.
(* ler and exprn *)
Lemma exprn_ge0 n x : 0 <= x -> 0 <= x ^+ n.
Proof. by move=> xge0; rewrite -nnegrE rpredX. Qed.
Lemma realX n : {in real, forall x, x ^+ n \is real}.
Proof. exact: rpredX. Qed.
Lemma exprn_gt0 n x : 0 < x -> 0 < x ^+ n.
Proof.
by rewrite !lt0r expf_eq0 => /andP[/negPf-> /exprn_ge0->]; rewrite andbF.
Qed.
Definition exprn_gte0 := (exprn_ge0, exprn_gt0).
Lemma exprn_ile1 n x : 0 <= x -> x <= 1 -> x ^+ n <= 1.
Proof.
move=> xge0 xle1; elim: n=> [|*]; rewrite ?expr0 // exprS.
by rewrite mulr_ile1 ?exprn_ge0.
Qed.
Lemma exprn_ilt1 n x : 0 <= x -> x < 1 -> x ^+ n < 1 = (n != 0).
Proof.
move=> xge0 xlt1.
case: n; [by rewrite eqxx ltxx | elim=> [|n ihn]; first by rewrite expr1].
by rewrite exprS mulr_ilt1 // exprn_ge0.
Qed.
Definition exprn_ilte1 := (exprn_ile1, exprn_ilt1).
Lemma exprn_ege1 n x : 1 <= x -> 1 <= x ^+ n.
Proof.
by move=> x_ge1; elim: n=> [|n ihn]; rewrite ?expr0 // exprS mulr_ege1.
Qed.
Lemma exprn_egt1 n x : 1 < x -> 1 < x ^+ n = (n != 0).
Proof.
move=> xgt1; case: n; first by rewrite eqxx ltxx.
by elim=> [|n ihn]; rewrite ?expr1// exprS mulr_egt1 // exprn_ge0.
Qed.
Definition exprn_egte1 := (exprn_ege1, exprn_egt1).
Definition exprn_cp1 := (exprn_ilte1, exprn_egte1).
Lemma ler_iXnr x n : (0 < n)%N -> 0 <= x -> x <= 1 -> x ^+ n <= x.
Proof. by case: n => n // *; rewrite exprS ler_piMr // exprn_ile1. Qed.
Lemma ltr_iXnr x n : 0 < x -> x < 1 -> (x ^+ n < x) = (1 < n)%N.
Proof.
case: n=> [|[|n]] //; first by rewrite expr0 => _ /lt_gtF ->.
by move=> x0 x1; rewrite exprS gtr_pMr // ?exprn_ilt1 // ltW.
Qed.
Definition lter_iXnr := (ler_iXnr, ltr_iXnr).
Lemma ler_eXnr x n : (0 < n)%N -> 1 <= x -> x <= x ^+ n.
Proof.
case: n => // n _ x_ge1.
by rewrite exprS ler_peMr ?(le_trans _ x_ge1) // exprn_ege1.
Qed.
Lemma ltr_eXnr x n : 1 < x -> (x < x ^+ n) = (1 < n)%N.
Proof.
move=> x_ge1; case: n=> [|[|n]] //; first by rewrite expr0 lt_gtF.
by rewrite exprS ltr_pMr ?(lt_trans _ x_ge1) ?exprn_egt1.
Qed.
Definition lter_eXnr := (ler_eXnr, ltr_eXnr).
Definition lter_Xnr := (lter_iXnr, lter_eXnr).
Lemma ler_wiXn2l x :
0 <= x -> x <= 1 -> {homo GRing.exp x : m n / (n <= m)%N >-> m <= n}.
Proof.
move=> xge0 xle1 m n /= hmn.
by rewrite -(subnK hmn) exprD ler_piMl ?(exprn_ge0, exprn_ile1).
Qed.
Lemma ler_weXn2l x : 1 <= x -> {homo GRing.exp x : m n / (m <= n)%N >-> m <= n}.
Proof.
move=> xge1 m n /= hmn; rewrite -(subnK hmn) exprD.
by rewrite ler_peMl ?(exprn_ge0, exprn_ege1) // (le_trans _ xge1) ?ler01.
Qed.
Lemma ieexprn_weq1 x n : 0 <= x -> (x ^+ n == 1) = ((n == 0) || (x == 1)).
Proof.
move=> xle0; case: n => [|n]; first by rewrite expr0 eqxx.
case: (@real_ltgtP x 1); do ?by rewrite ?ger0_real.
+ by move=> x_lt1; rewrite 1?lt_eqF // exprn_ilt1.
+ by move=> x_lt1; rewrite 1?gt_eqF // exprn_egt1.
by move->; rewrite expr1n eqxx.
Qed.
Lemma ieexprIn x : 0 < x -> x != 1 -> injective (GRing.exp x).
Proof.
move=> x_gt0 x_neq1 m n; without loss /subnK <-: m n / (n <= m)%N.
by move=> IH eq_xmn; case/orP: (leq_total m n) => /IH->.
case: {m}(m - n)%N => // m /eqP/idPn[]; rewrite -[x ^+ n]mul1r exprD.
by rewrite (inj_eq (mulIf _)) ?ieexprn_weq1 ?ltW // expf_neq0 ?gt_eqF.
Qed.
Lemma ler_iXn2l x :
0 < x -> x < 1 -> {mono GRing.exp x : m n / (n <= m)%N >-> m <= n}.
Proof.
move=> xgt0 xlt1; apply: (le_nmono (inj_nhomo_lt _ _)); last first.
by apply/ler_wiXn2l; exact/ltW.
by apply: ieexprIn; rewrite ?lt_eqF ?ltr_cpable.
Qed.
Lemma ltr_iXn2l x :
0 < x -> x < 1 -> {mono GRing.exp x : m n / (n < m)%N >-> m < n}.
Proof. by move=> xgt0 xlt1; apply: (leW_nmono (ler_iXn2l _ _)). Qed.
Definition lter_iXn2l := (ler_iXn2l, ltr_iXn2l).
Lemma ler_eXn2l x :
1 < x -> {mono GRing.exp x : m n / (m <= n)%N >-> m <= n}.
Proof.
move=> xgt1; apply: (le_mono (inj_homo_lt _ _)); last first.
by apply: ler_weXn2l; rewrite ltW.
by apply: ieexprIn; rewrite ?gt_eqF ?gtr_cpable //; apply: lt_trans xgt1.
Qed.
Lemma ltr_eXn2l x :
1 < x -> {mono (GRing.exp x) : m n / (m < n)%N >-> m < n}.
Proof. by move=> xgt1; apply: (leW_mono (ler_eXn2l _)). Qed.
Definition lter_eXn2l := (ler_eXn2l, ltr_eXn2l).
Lemma ltrXn2r n x y : 0 <= x -> x < y -> x ^+ n < y ^+ n = (n != 0).
Proof.
move=> xge0 xlty; case: n; first by rewrite ltxx.
elim=> [|n IHn]; rewrite ?[_ ^+ _.+2]exprS //.
rewrite (@le_lt_trans _ _ (x * y ^+ n.+1)) ?ler_wpM2l ?ltr_pM2r ?IHn //.
by rewrite ltW.
by rewrite exprn_gt0 // (le_lt_trans xge0).
Qed.
Lemma lerXn2r n : {in nneg & , {homo (@GRing.exp R)^~ n : x y / x <= y}}.
Proof.
move=> x y /= x0 y0 xy; elim: n => [|n IHn]; rewrite !(expr0, exprS) //.
by rewrite (@le_trans _ _ (x * y ^+ n)) ?ler_wpM2l ?ler_wpM2r ?exprn_ge0.
Qed.
Definition lterXn2r := (lerXn2r, ltrXn2r).
Lemma ltr_wpXn2r n :
(0 < n)%N -> {in nneg & , {homo (@GRing.exp R)^~ n : x y / x < y}}.
Proof. by move=> ngt0 x y /= x0 y0 hxy; rewrite ltrXn2r // -lt0n. Qed.
Lemma ler_pXn2r n :
(0 < n)%N -> {in nneg & , {mono (@GRing.exp R)^~ n : x y / x <= y}}.
Proof.
case: n => // n _ x y; rewrite !qualifE /= => x_ge0 y_ge0.
have [-> | nzx] := eqVneq x 0; first by rewrite exprS mul0r exprn_ge0.
rewrite -subr_ge0 subrXX pmulr_lge0 ?subr_ge0 //= big_ord_recr /=.
rewrite subnn expr0 mul1r /= ltr_pwDr // ?exprn_gt0 ?lt0r ?nzx //.
by rewrite sumr_ge0 // => i _; rewrite mulr_ge0 ?exprn_ge0.
Qed.
Lemma ltr_pXn2r n :
(0 < n)%N -> {in nneg & , {mono (@GRing.exp R)^~ n : x y / x < y}}.
Proof.
by move=> n_gt0 x y x_ge0 y_ge0; rewrite !lt_neqAle !eq_le !ler_pXn2r.
Qed.
Definition lter_pXn2r := (ler_pXn2r, ltr_pXn2r).
Lemma pexpIrn n : (0 < n)%N -> {in nneg &, injective ((@GRing.exp R)^~ n)}.
Proof. by move=> n_gt0; apply: inc_inj_in (ler_pXn2r _). Qed.
(* expr and ler/ltr *)
Lemma expr_le1 n x : (0 < n)%N -> 0 <= x -> (x ^+ n <= 1) = (x <= 1).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ler_pXn2r // [_ \in _]ler01.
Qed.
Lemma expr_lt1 n x : (0 < n)%N -> 0 <= x -> (x ^+ n < 1) = (x < 1).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ltr_pXn2r // [_ \in _]ler01.
Qed.
Definition expr_lte1 := (expr_le1, expr_lt1).
Lemma expr_ge1 n x : (0 < n)%N -> 0 <= x -> (1 <= x ^+ n) = (1 <= x).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ler_pXn2r // [_ \in _]ler01.
Qed.
Lemma expr_gt1 n x : (0 < n)%N -> 0 <= x -> (1 < x ^+ n) = (1 < x).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ltr_pXn2r // [_ \in _]ler01.
Qed.
Definition expr_gte1 := (expr_ge1, expr_gt1).
Lemma pexpr_eq1 x n : (0 < n)%N -> 0 <= x -> (x ^+ n == 1) = (x == 1).
Proof. by move=> ngt0 xge0; rewrite !eq_le expr_le1 // expr_ge1. Qed.
Lemma pexprn_eq1 x n : 0 <= x -> (x ^+ n == 1) = (n == 0) || (x == 1).
Proof. by case: n => [|n] xge0; rewrite ?eqxx // pexpr_eq1 ?gtn_eqF. Qed.
Lemma eqrXn2 n x y :
(0 < n)%N -> 0 <= x -> 0 <= y -> (x ^+ n == y ^+ n) = (x == y).
Proof. by move=> ngt0 xge0 yge0; rewrite (inj_in_eq (pexpIrn _)). Qed.
Lemma sqrp_eq1 x : 0 <= x -> (x ^+ 2 == 1) = (x == 1).
Proof. by move/pexpr_eq1->. Qed.
Lemma sqrn_eq1 x : x <= 0 -> (x ^+ 2 == 1) = (x == -1).
Proof. by rewrite -sqrrN -oppr_ge0 -eqr_oppLR => /sqrp_eq1. Qed.
Lemma ler_sqr : {in nneg &, {mono (fun x => x ^+ 2) : x y / x <= y}}.
Proof. exact: ler_pXn2r. Qed.
Lemma ltr_sqr : {in nneg &, {mono (fun x => x ^+ 2) : x y / x < y}}.
Proof. exact: ltr_pXn2r. Qed.
Lemma ler_pV2 :
{in [pred x in GRing.unit | 0 < x] &, {mono (@GRing.inv R) : x y /~ x <= y}}.
Proof.
move=> x y /andP [ux hx] /andP [uy hy] /=.
by rewrite -(ler_pM2l hx) -(ler_pM2r hy) !(divrr, mulrVK) ?unitf_gt0 // mul1r.
Qed.
Lemma ler_nV2 :
{in [pred x in GRing.unit | x < 0] &, {mono (@GRing.inv R) : x y /~ x <= y}}.
Proof.
move=> x y /andP [ux hx] /andP [uy hy] /=.
by rewrite -(ler_nM2l hx) -(ler_nM2r hy) !(divrr, mulrVK) ?unitf_lt0 // mul1r.
Qed.
Lemma ltr_pV2 :
{in [pred x in GRing.unit | 0 < x] &, {mono (@GRing.inv R) : x y /~ x < y}}.
Proof. exact: leW_nmono_in ler_pV2. Qed.
Lemma ltr_nV2 :
{in [pred x in GRing.unit | x < 0] &, {mono (@GRing.inv R) : x y /~ x < y}}.
Proof. exact: leW_nmono_in ler_nV2. Qed.
Lemma invr_gt1 x : x \is a GRing.unit -> 0 < x -> (1 < x^-1) = (x < 1).
Proof.
by move=> Ux xgt0; rewrite -{1}[1]invr1 ltr_pV2 ?inE ?unitr1 ?ltr01 ?Ux.
Qed.
Lemma invr_ge1 x : x \is a GRing.unit -> 0 < x -> (1 <= x^-1) = (x <= 1).
Proof.
by move=> Ux xgt0; rewrite -{1}[1]invr1 ler_pV2 ?inE ?unitr1 ?ltr01 // Ux.
Qed.
Definition invr_gte1 := (invr_ge1, invr_gt1).
Lemma invr_le1 x (ux : x \is a GRing.unit) (hx : 0 < x) :
(x^-1 <= 1) = (1 <= x).
Proof. by rewrite -invr_ge1 ?invr_gt0 ?unitrV // invrK. Qed.
Lemma invr_lt1 x (ux : x \is a GRing.unit) (hx : 0 < x) : (x^-1 < 1) = (1 < x).
Proof. by rewrite -invr_gt1 ?invr_gt0 ?unitrV // invrK. Qed.
Definition invr_lte1 := (invr_le1, invr_lt1).
Definition invr_cp1 := (invr_gte1, invr_lte1).
(* max and min *)
Lemma natr_min (m n : nat) : (Order.min m n)%:R = Order.min m%:R n%:R :> R.
Proof. by rewrite !minElt ltr_nat /Order.lt/= -fun_if. Qed.
Lemma natr_max (m n : nat) : (Order.max m n)%:R = Order.max m%:R n%:R :> R.
Proof. by rewrite !maxElt ltr_nat /Order.lt/= -fun_if. Qed.
Lemma addr_min_max x y : min x y + max x y = x + y.
Proof. by rewrite /min /max; case: ifP => //; rewrite addrC. Qed.
Lemma addr_max_min x y : max x y + min x y = x + y.
Proof. by rewrite addrC addr_min_max. Qed.
Lemma minr_to_max x y : min x y = x + y - max x y.
Proof. by rewrite -[x + y]addr_min_max addrK. Qed.
Lemma maxr_to_min x y : max x y = x + y - min x y.
Proof. by rewrite -[x + y]addr_max_min addrK. Qed.
Lemma real_oppr_max : {in real &, {morph -%R : x y / max x y >-> min x y : R}}.
Proof.
by move=> x y xr yr; rewrite !(fun_if, if_arg) ltrN2; case: real_ltgtP => // ->.
Qed.
Lemma real_oppr_min : {in real &, {morph -%R : x y / min x y >-> max x y : R}}.
Proof.
by move=> x y xr yr; rewrite -[RHS]opprK real_oppr_max ?realN// !opprK.
Qed.
Lemma real_addr_minl : {in real & real & real, @left_distributive R R +%R min}.
Proof.
by move=> x y z xr yr zr; case: (@real_leP (_ + _)); rewrite ?realD//;
rewrite lterD2; case: real_leP.
Qed.
Lemma real_addr_minr : {in real & real & real, @right_distributive R R +%R min}.
Proof. by move=> x y z xr yr zr; rewrite !(addrC x) real_addr_minl. Qed.
Lemma real_addr_maxl : {in real & real & real, @left_distributive R R +%R max}.
Proof.
by move=> x y z xr yr zr; case: (@real_leP (_ + _)); rewrite ?realD//;
rewrite lterD2; case: real_leP.
Qed.
Lemma real_addr_maxr : {in real & real & real, @right_distributive R R +%R max}.
Proof. by move=> x y z xr yr zr; rewrite !(addrC x) real_addr_maxl. Qed.
Lemma minr_pMr x y z : 0 <= x -> x * min y z = min (x * y) (x * z).
Proof.
have [|x_gt0||->]// := comparableP x; last by rewrite !mul0r minxx.
by rewrite !(fun_if, if_arg) lter_pM2l//; case: (y < z).
Qed.
Lemma maxr_pMr x y z : 0 <= x -> x * max y z = max (x * y) (x * z).
Proof.
have [|x_gt0||->]// := comparableP x; last by rewrite !mul0r maxxx.
by rewrite !(fun_if, if_arg) lter_pM2l//; case: (y < z).
Qed.
Lemma real_maxr_nMr x y z : x <= 0 -> y \is real -> z \is real ->
x * max y z = min (x * y) (x * z).
Proof.
move=> x0 yr zr; rewrite -[_ * _]opprK -mulrN real_oppr_max// -mulNr.
by rewrite minr_pMr ?oppr_ge0// !(mulNr, mulrN, opprK).
Qed.
Lemma real_minr_nMr x y z : x <= 0 -> y \is real -> z \is real ->
x * min y z = max (x * y) (x * z).
Proof.
move=> x0 yr zr; rewrite -[_ * _]opprK -mulrN real_oppr_min// -mulNr.
by rewrite maxr_pMr ?oppr_ge0// !(mulNr, mulrN, opprK).
Qed.
Lemma minr_pMl x y z : 0 <= x -> min y z * x = min (y * x) (z * x).
Proof. by move=> *; rewrite mulrC minr_pMr // ![_ * x]mulrC. Qed.
Lemma maxr_pMl x y z : 0 <= x -> max y z * x = max (y * x) (z * x).
Proof. by move=> *; rewrite mulrC maxr_pMr // ![_ * x]mulrC. Qed.
Lemma real_minr_nMl x y z : x <= 0 -> y \is real -> z \is real ->
min y z * x = max (y * x) (z * x).
Proof. by move=> *; rewrite mulrC real_minr_nMr // ![_ * x]mulrC. Qed.
Lemma real_maxr_nMl x y z : x <= 0 -> y \is real -> z \is real ->
max y z * x = min (y * x) (z * x).
Proof. by move=> *; rewrite mulrC real_maxr_nMr // ![_ * x]mulrC. Qed.
Lemma real_maxrN x : x \is real -> max x (- x) = `|x|.
Proof.
move=> x_real; rewrite /max.
by case: real_ge0P => // [/ge0_cp [] | /lt0_cp []];
case: (@real_leP (- x) x); rewrite ?realN.
Qed.
Lemma real_maxNr x : x \is real -> max (- x) x = `|x|.
Proof.
by move=> x_real; rewrite comparable_maxC ?real_maxrN ?real_comparable ?realN.
Qed.
Lemma real_minrN x : x \is real -> min x (- x) = - `|x|.
Proof.
by move=> x_real; rewrite -[LHS]opprK real_oppr_min ?opprK ?real_maxNr ?realN.
Qed.
Lemma real_minNr x : x \is real -> min (- x) x = - `|x|.
Proof.
by move=> x_real; rewrite -[LHS]opprK real_oppr_min ?opprK ?real_maxrN ?realN.
Qed.
Section RealDomainArgExtremum.
Context {I : finType} (i0 : I).
Context (P : pred I) (F : I -> R) (Pi0 : P i0).
Hypothesis F_real : {in P, forall i, F i \is real}.
Lemma real_arg_minP : extremum_spec <=%R P F [arg min_(i < i0 | P i) F i].
Proof.
by apply: comparable_arg_minP => // i j iP jP; rewrite real_comparable ?F_real.
Qed.
Lemma real_arg_maxP : extremum_spec >=%R P F [arg max_(i > i0 | P i) F i].
Proof.
by apply: comparable_arg_maxP => // i j iP jP; rewrite real_comparable ?F_real.
Qed.
End RealDomainArgExtremum.
(* norm *)
Lemma real_ler_norm x : x \is real -> x <= `|x|.
Proof.
by case/real_ge0P=> hx //; rewrite (le_trans (ltW hx)) // oppr_ge0 ltW.
Qed.
(* norm + add *)
Section NormedZmoduleTheory.
Variable V : semiNormedZmodType R.
Implicit Types (u v w : V).
Lemma normr_real v : `|v| \is real. Proof. by apply/ger0_real. Qed.
Hint Resolve normr_real : core.
Lemma ler_norm_sum I r (G : I -> V) (P : pred I):
`|\sum_(i <- r | P i) G i| <= \sum_(i <- r | P i) `|G i|.
Proof.
elim/big_rec2: _ => [|i y x _]; first by rewrite normr0.
by rewrite -(lerD2l `|G i|); apply: le_trans; apply: ler_normD.
Qed.
Lemma ler_normB v w : `|v - w| <= `|v| + `|w|.
Proof. by rewrite (le_trans (ler_normD _ _)) ?normrN. Qed.
Lemma ler_distD u v w : `|v - w| <= `|v - u| + `|u - w|.
Proof. by rewrite (le_trans _ (ler_normD _ _)) // addrA addrNK. Qed.
Lemma lerB_normD v w : `|v| - `|w| <= `|v + w|.
Proof.
by rewrite -{1}[v](addrK w) lterBDl (le_trans (ler_normD _ _))// addrC normrN.
Qed.
Lemma lerB_dist v w : `|v| - `|w| <= `|v - w|.
Proof. by rewrite -[`|w|]normrN lerB_normD. Qed.
Lemma ler_dist_dist v w : `| `|v| - `|w| | <= `|v - w|.
Proof.
have [||_|_] // := @real_leP `|v| `|w|; last by rewrite lerB_dist.
by rewrite distrC lerB_dist.
Qed.
Lemma ler_dist_normD v w : `| `|v| - `|w| | <= `|v + w|.
Proof. by rewrite -[w]opprK normrN ler_dist_dist. Qed.
Lemma ler_nnorml v x : x < 0 -> `|v| <= x = false.
Proof. by move=> h; rewrite lt_geF //; apply/(lt_le_trans h). Qed.
Lemma ltr_nnorml v x : x <= 0 -> `|v| < x = false.
Proof. by move=> h; rewrite le_gtF //; apply/(le_trans h). Qed.
Definition lter_nnormr := (ler_nnorml, ltr_nnorml).
End NormedZmoduleTheory.
Hint Extern 0 (is_true (norm _ \is real)) => apply: normr_real : core.
Lemma real_ler_norml x y : x \is real -> (`|x| <= y) = (- y <= x <= y).
Proof.
move=> xR; wlog x_ge0 : x xR / 0 <= x => [hwlog|].
move: (xR) => /(@real_leVge 0) /orP [|/hwlog->|hx] //.
by rewrite -[x]opprK normrN lerN2 andbC lerNl hwlog ?realN ?oppr_ge0.
rewrite ger0_norm //; have [le_xy|] := boolP (x <= y); last by rewrite andbF.
by rewrite (le_trans _ x_ge0) // oppr_le0 (le_trans x_ge0).
Qed.
Lemma real_ler_normlP x y :
x \is real -> reflect ((-x <= y) * (x <= y)) (`|x| <= y).
Proof.
by move=> Rx; rewrite real_ler_norml // lerNl; apply: (iffP andP) => [] [].
Qed.
Arguments real_ler_normlP {x y}.
Lemma real_eqr_norml x y :
x \is real -> (`|x| == y) = ((x == y) || (x == -y)) && (0 <= y).
Proof.
move=> Rx.
apply/idP/idP=> [|/andP[/pred2P[]-> /ger0_norm/eqP]]; rewrite ?normrE //.
case: real_le0P => // hx; rewrite 1?eqr_oppLR => /eqP exy.
by move: hx; rewrite exy ?oppr_le0 eqxx orbT //.
by move: hx=> /ltW; rewrite exy eqxx.
Qed.
Lemma real_eqr_norm2 x y :
x \is real -> y \is real -> (`|x| == `|y|) = (x == y) || (x == -y).
Proof.
move=> Rx Ry; rewrite real_eqr_norml // normrE andbT.
by case: real_le0P; rewrite // opprK orbC.
Qed.
Lemma real_ltr_norml x y : x \is real -> (`|x| < y) = (- y < x < y).
Proof.
move=> Rx; wlog x_ge0 : x Rx / 0 <= x => [hwlog|].
move: (Rx) => /(@real_leVge 0) /orP [|/hwlog->|hx] //.
by rewrite -[x]opprK normrN ltrN2 andbC ltrNl hwlog ?realN ?oppr_ge0.
rewrite ger0_norm //; have [le_xy|] := boolP (x < y); last by rewrite andbF.
by rewrite (lt_le_trans _ x_ge0) // oppr_lt0 (le_lt_trans x_ge0).
Qed.
Definition real_lter_norml := (real_ler_norml, real_ltr_norml).
Lemma real_ltr_normlP x y :
x \is real -> reflect ((-x < y) * (x < y)) (`|x| < y).
Proof.
by move=> Rx; rewrite real_ltr_norml // ltrNl; apply: (iffP (@andP _ _)); case.
Qed.
Arguments real_ltr_normlP {x y}.
Lemma real_ler_normr x y : y \is real -> (x <= `|y|) = (x <= y) || (x <= - y).
Proof.
move=> Ry.
have [xR|xNR] := boolP (x \is real); last by rewrite ?Nreal_leF ?realN.
rewrite real_leNgt ?real_ltr_norml // negb_and -?real_leNgt ?realN //.
by rewrite orbC lerNr.
Qed.
Lemma real_ltr_normr x y : y \is real -> (x < `|y|) = (x < y) || (x < - y).
Proof.
move=> Ry.
have [xR|xNR] := boolP (x \is real); last by rewrite ?Nreal_ltF ?realN.
rewrite real_ltNge ?real_ler_norml // negb_and -?real_ltNge ?realN //.
by rewrite orbC ltrNr.
Qed.
Definition real_lter_normr := (real_ler_normr, real_ltr_normr).
Lemma real_ltr_normlW x y : x \is real -> `|x| < y -> x < y.
Proof. by move=> ?; case/real_ltr_normlP. Qed.
Lemma real_ltrNnormlW x y : x \is real -> `|x| < y -> - y < x.
Proof. by move=> ?; case/real_ltr_normlP => //; rewrite ltrNl. Qed.
Lemma real_ler_normlW x y : x \is real -> `|x| <= y -> x <= y.
Proof. by move=> ?; case/real_ler_normlP. Qed.
Lemma real_lerNnormlW x y : x \is real -> `|x| <= y -> - y <= x.
Proof. by move=> ?; case/real_ler_normlP => //; rewrite lerNl. Qed.
Lemma real_ler_distl x y e :
x - y \is real -> (`|x - y| <= e) = (y - e <= x <= y + e).
Proof. by move=> Rxy; rewrite real_lter_norml // !lterBDl. Qed.
Lemma real_ltr_distl x y e :
x - y \is real -> (`|x - y| < e) = (y - e < x < y + e).
Proof. by move=> Rxy; rewrite real_lter_norml // !lterBDl. Qed.
Definition real_lter_distl := (real_ler_distl, real_ltr_distl).
Lemma real_ltr_distlDr x y e : x - y \is real -> `|x - y| < e -> x < y + e.
Proof. by move=> ?; rewrite real_ltr_distl // => /andP[]. Qed.
Lemma real_ler_distlDr x y e : x - y \is real -> `|x - y| <= e -> x <= y + e.
Proof. by move=> ?; rewrite real_ler_distl // => /andP[]. Qed.
Lemma real_ltr_distlCDr x y e : x - y \is real -> `|x - y| < e -> y < x + e.
Proof. by rewrite realBC (distrC x) => ? /real_ltr_distlDr; apply. Qed.
Lemma real_ler_distlCDr x y e : x - y \is real -> `|x - y| <= e -> y <= x + e.
Proof. by rewrite realBC distrC => ? /real_ler_distlDr; apply. Qed.
Lemma real_ltr_distlBl x y e : x - y \is real -> `|x - y| < e -> x - e < y.
Proof. by move/real_ltr_distlDr; rewrite ltrBlDr; apply. Qed.
Lemma real_ler_distlBl x y e : x - y \is real -> `|x - y| <= e -> x - e <= y.
Proof. by move/real_ler_distlDr; rewrite lerBlDr; apply. Qed.
Lemma real_ltr_distlCBl x y e : x - y \is real -> `|x - y| < e -> y - e < x.
Proof. by rewrite realBC distrC => ? /real_ltr_distlBl; apply. Qed.
Lemma real_ler_distlCBl x y e : x - y \is real -> `|x - y| <= e -> y - e <= x.
Proof. by rewrite realBC distrC => ? /real_ler_distlBl; apply. Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `ger0_def` instead")]
Lemma eqr_norm_id x : (`|x| == x) = (0 <= x). Proof. by rewrite ger0_def. Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `ler0_def` instead")]
Lemma eqr_normN x : (`|x| == - x) = (x <= 0). Proof. by rewrite ler0_def. Qed.
Definition eqr_norm_idVN := =^~ (ger0_def, ler0_def).
Lemma real_exprn_even_ge0 n x : x \is real -> ~~ odd n -> 0 <= x ^+ n.
Proof.
move=> xR even_n; have [/exprn_ge0 -> //|x_lt0] := real_ge0P xR.
rewrite -[x]opprK -mulN1r exprMn -signr_odd (negPf even_n) expr0 mul1r.
by rewrite exprn_ge0 ?oppr_ge0 ?ltW.
Qed.
Lemma real_exprn_even_gt0 n x :
x \is real -> ~~ odd n -> (0 < x ^+ n) = (n == 0)%N || (x != 0).
Proof.
move=> xR n_even; rewrite lt0r real_exprn_even_ge0 ?expf_eq0 //.
by rewrite andbT negb_and lt0n negbK.
Qed.
Lemma real_exprn_even_le0 n x :
x \is real -> ~~ odd n -> (x ^+ n <= 0) = (n != 0) && (x == 0).
Proof.
move=> xR n_even; rewrite !real_leNgt ?rpred0 ?rpredX //.
by rewrite real_exprn_even_gt0 // negb_or negbK.
Qed.
Lemma real_exprn_even_lt0 n x :
x \is real -> ~~ odd n -> (x ^+ n < 0) = false.
Proof. by move=> xR n_even; rewrite le_gtF // real_exprn_even_ge0. Qed.
Lemma real_exprn_odd_ge0 n x :
x \is real -> odd n -> (0 <= x ^+ n) = (0 <= x).
Proof.
case/real_ge0P => [x_ge0|x_lt0] n_odd; first by rewrite exprn_ge0.
apply: negbTE; rewrite lt_geF //.
case: n n_odd => // n /= n_even; rewrite exprS pmulr_llt0 //.
by rewrite real_exprn_even_gt0 ?ler0_real ?ltW // (lt_eqF x_lt0) ?orbT.
Qed.
Lemma real_exprn_odd_gt0 n x : x \is real -> odd n -> (0 < x ^+ n) = (0 < x).
Proof.
by move=> xR n_odd; rewrite !lt0r expf_eq0 real_exprn_odd_ge0; case: n n_odd.
Qed.
Lemma real_exprn_odd_le0 n x : x \is real -> odd n -> (x ^+ n <= 0) = (x <= 0).
Proof.
by move=> xR n_odd; rewrite !real_leNgt ?rpred0 ?rpredX // real_exprn_odd_gt0.
Qed.
Lemma real_exprn_odd_lt0 n x : x \is real -> odd n -> (x ^+ n < 0) = (x < 0).
Proof.
by move=> xR n_odd; rewrite !real_ltNge ?rpred0 ?rpredX // real_exprn_odd_ge0.
Qed.
(* GG: Could this be a better definition of "real" ? *)
Lemma realEsqr x : (x \is real) = (0 <= x ^+ 2).
Proof. by rewrite ger0_def normrX eqf_sqr -ger0_def -ler0_def. Qed.
Lemma real_normK x : x \is real -> `|x| ^+ 2 = x ^+ 2.
Proof. by move=> Rx; rewrite -normrX ger0_norm -?realEsqr. Qed.
(* Binary sign ((-1) ^+ s). *)
Lemma normr_sign s : `|(-1) ^+ s : R| = 1.
Proof. by rewrite normrX normrN1 expr1n. Qed.
Lemma normrMsign s x : `|(-1) ^+ s * x| = `|x|.
Proof. by rewrite normrM normr_sign mul1r. Qed.
Lemma signr_gt0 (b : bool) : (0 < (-1) ^+ b :> R) = ~~ b.
Proof. by case: b; rewrite (ltr01, ltr0N1). Qed.
Lemma signr_lt0 (b : bool) : ((-1) ^+ b < 0 :> R) = b.
Proof. by case: b; rewrite // ?(ltrN10, ltr10). Qed.
Lemma signr_ge0 (b : bool) : (0 <= (-1) ^+ b :> R) = ~~ b.
Proof. by rewrite le0r signr_eq0 signr_gt0. Qed.
Lemma signr_le0 (b : bool) : ((-1) ^+ b <= 0 :> R) = b.
Proof. by rewrite le_eqVlt signr_eq0 signr_lt0. Qed.
(* This actually holds for char R != 2. *)
Lemma signr_inj : injective (fun b : bool => (-1) ^+ b : R).
Proof. exact: can_inj (fun x => 0 >= x) signr_le0. Qed.
(* Ternary sign (sg). *)
Lemma sgr_def x : sg x = (-1) ^+ (x < 0)%R *+ (x != 0).
Proof. by rewrite /sg; do 2!case: ifP => //. Qed.
Lemma neqr0_sign x : x != 0 -> (-1) ^+ (x < 0)%R = sgr x.
Proof. by rewrite sgr_def => ->. Qed.
Lemma gtr0_sg x : 0 < x -> sg x = 1.
Proof. by move=> x_gt0; rewrite /sg gt_eqF // lt_gtF. Qed.
Lemma ltr0_sg x : x < 0 -> sg x = -1.
Proof. by move=> x_lt0; rewrite /sg x_lt0 lt_eqF. Qed.
Lemma sgr0 : sg 0 = 0 :> R. Proof. by rewrite /sgr eqxx. Qed.
Lemma sgr1 : sg 1 = 1 :> R. Proof. by rewrite gtr0_sg // ltr01. Qed.
Lemma sgrN1 : sg (-1) = -1 :> R. Proof. by rewrite ltr0_sg // ltrN10. Qed.
Definition sgrE := (sgr0, sgr1, sgrN1).
Lemma sqr_sg x : sg x ^+ 2 = (x != 0)%:R.
Proof. by rewrite sgr_def exprMn_n sqrr_sign -mulnn mulnb andbb. Qed.
Lemma mulr_sg_eq1 x y : (sg x * y == 1) = (x != 0) && (sg x == y).
Proof.
rewrite /sg eq_sym; case: ifP => _; first by rewrite mul0r oner_eq0.
by case: ifP => _; rewrite ?mul1r // mulN1r eqr_oppLR.
Qed.
Lemma mulr_sg_eqN1 x y : (sg x * sg y == -1) = (x != 0) && (sg x == - sg y).
Proof.
move/sg: y => y; rewrite /sg eq_sym eqr_oppLR.
case: ifP => _; first by rewrite mul0r oppr0 oner_eq0.
by case: ifP => _; rewrite ?mul1r // mulN1r eqr_oppLR.
Qed.
Lemma sgr_eq0 x : (sg x == 0) = (x == 0).
Proof. by rewrite -sqrf_eq0 sqr_sg pnatr_eq0; case: (x == 0). Qed.
Lemma sgr_odd n x : x != 0 -> (sg x) ^+ n = (sg x) ^+ (odd n).
Proof. by rewrite /sg; do 2!case: ifP => // _; rewrite ?expr1n ?signr_odd. Qed.
Lemma sgrMn x n : sg (x *+ n) = (n != 0)%:R * sg x.
Proof.
case: n => [|n]; first by rewrite mulr0n sgr0 mul0r.
by rewrite !sgr_def mulrn_eq0 mul1r pmulrn_llt0.
Qed.
Lemma sgr_nat n : sg n%:R = (n != 0)%:R :> R.
Proof. by rewrite sgrMn sgr1 mulr1. Qed.
Lemma sgr_id x : sg (sg x) = sg x.
Proof. by rewrite !(fun_if sg) !sgrE. Qed.
Lemma sgr_lt0 x : (sg x < 0) = (x < 0).
Proof.
rewrite /sg; case: eqP => [-> // | _].
by case: ifP => _; rewrite ?ltrN10 // lt_gtF.
Qed.
Lemma sgr_le0 x : (sgr x <= 0) = (x <= 0).
Proof. by rewrite !le_eqVlt sgr_eq0 sgr_lt0. Qed.
(* sign and norm *)
Lemma realEsign x : x \is real -> x = (-1) ^+ (x < 0)%R * `|x|.
Proof. by case/real_ge0P; rewrite (mul1r, mulN1r) ?opprK. Qed.
Lemma realNEsign x : x \is real -> - x = (-1) ^+ (0 < x)%R * `|x|.
Proof. by move=> Rx; rewrite -normrN -oppr_lt0 -realEsign ?rpredN. Qed.
Lemma real_normrEsign (x : R) (xR : x \is real) : `|x| = (-1) ^+ (x < 0)%R * x.
Proof. by rewrite {3}[x]realEsign // signrMK. Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `realEsign` instead")]
Lemma real_mulr_sign_norm x : x \is real -> (-1) ^+ (x < 0)%R * `|x| = x.
Proof. by move/realEsign. Qed.
Lemma real_mulr_Nsign_norm x : x \is real -> (-1) ^+ (0 < x)%R * `|x| = - x.
Proof. by move/realNEsign. Qed.
Lemma realEsg x : x \is real -> x = sgr x * `|x|.
Proof.
move=> xR; have [-> | ] := eqVneq x 0; first by rewrite normr0 mulr0.
by move=> /neqr0_sign <-; rewrite -realEsign.
Qed.
Lemma normr_sg x : `|sg x| = (x != 0)%:R.
Proof. by rewrite sgr_def -mulr_natr normrMsign normr_nat. Qed.
Lemma sgr_norm x : sg `|x| = (x != 0)%:R.
Proof. by rewrite /sg le_gtF // normr_eq0 mulrb if_neg. Qed.
(* leif *)
Lemma leif_nat_r m n C : (m%:R <= n%:R ?= iff C :> R) = (m <= n ?= iff C)%N.
Proof. by rewrite /leif !ler_nat eqr_nat. Qed.
Lemma leifBLR x y z C : (x - y <= z ?= iff C) = (x <= z + y ?= iff C).
Proof. by rewrite /leif !eq_le lerBlDr lerBrDr. Qed.
Lemma leifBRL x y z C : (x <= y - z ?= iff C) = (x + z <= y ?= iff C).
Proof. by rewrite -leifBLR opprK. Qed.
Lemma leifD x1 y1 C1 x2 y2 C2 :
x1 <= y1 ?= iff C1 -> x2 <= y2 ?= iff C2 ->
x1 + x2 <= y1 + y2 ?= iff C1 && C2.
Proof.
rewrite -(mono_leif (C := C1) (lerD2r x2)).
rewrite -(mono_leif (C := C2) (lerD2l y1)).
exact: leif_trans.
Qed.
Lemma leif_sum (I : finType) (P C : pred I) (E1 E2 : I -> R) :
(forall i, P i -> E1 i <= E2 i ?= iff C i) ->
\sum_(i | P i) E1 i <= \sum_(i | P i) E2 i ?= iff [forall (i | P i), C i].
Proof.
move=> leE12; rewrite -big_andE.
elim/big_rec3: _ => [|i Ci m2 m1 /leE12]; first by rewrite /leif lexx eqxx.
exact: leifD.
Qed.
Lemma leif_0_sum (I : finType) (P C : pred I) (E : I -> R) :
(forall i, P i -> 0 <= E i ?= iff C i) ->
0 <= \sum_(i | P i) E i ?= iff [forall (i | P i), C i].
Proof. by move/leif_sum; rewrite big1_eq. Qed.
Lemma real_leif_norm x : x \is real -> x <= `|x| ?= iff (0 <= x).
Proof.
by move=> xR; rewrite ger0_def eq_sym; apply: leif_eq; rewrite real_ler_norm.
Qed.
Lemma leif_pM x1 x2 y1 y2 C1 C2 :
0 <= x1 -> 0 <= x2 -> x1 <= y1 ?= iff C1 -> x2 <= y2 ?= iff C2 ->
x1 * x2 <= y1 * y2 ?= iff (y1 * y2 == 0) || C1 && C2.
Proof.
move=> x1_ge0 x2_ge0 le_xy1 le_xy2; have [y_0 | ] := eqVneq _ 0.
apply/leifP; rewrite y_0 /= mulf_eq0 !eq_le x1_ge0 x2_ge0 !andbT.
move/eqP: y_0; rewrite mulf_eq0.
by case/pred2P=> <-; rewrite (le_xy1, le_xy2) ?orbT.
rewrite /= mulf_eq0 => /norP[y1nz y2nz].
have y1_gt0: 0 < y1 by rewrite lt_def y1nz (le_trans _ le_xy1).
have [x2_0 | x2nz] := eqVneq x2 0.
apply/leifP; rewrite -le_xy2 x2_0 eq_sym (negPf y2nz) andbF mulr0.
by rewrite mulr_gt0 // lt_def y2nz -x2_0 le_xy2.
have:= le_xy2; rewrite -[X in X -> _](mono_leif (ler_pM2l y1_gt0)).
by apply: leif_trans; rewrite (mono_leif (ler_pM2r _)) // lt_def x2nz.
Qed.
Lemma leif_nM x1 x2 y1 y2 C1 C2 :
y1 <= 0 -> y2 <= 0 -> x1 <= y1 ?= iff C1 -> x2 <= y2 ?= iff C2 ->
y1 * y2 <= x1 * x2 ?= iff (x1 * x2 == 0) || C1 && C2.
Proof.
rewrite -!oppr_ge0 -mulrNN -[x1 * x2]mulrNN => y1le0 y2le0 le_xy1 le_xy2.
by apply: leif_pM => //; rewrite (nmono_leif lerN2).
Qed.
Lemma leif_pprod (I : finType) (P C : pred I) (E1 E2 : I -> R) :
(forall i, P i -> 0 <= E1 i) ->
(forall i, P i -> E1 i <= E2 i ?= iff C i) ->
let pi E := \prod_(i | P i) E i in
pi E1 <= pi E2 ?= iff (pi E2 == 0) || [forall (i | P i), C i].
Proof.
move=> E1_ge0 leE12 /=; rewrite -big_andE; elim/(big_load (fun x => 0 <= x)): _.
elim/big_rec3: _ => [|i Ci m2 m1 Pi [m1ge0 le_m12]].
by split=> //; apply/leifP; rewrite orbT.
have Ei_ge0 := E1_ge0 i Pi; split; first by rewrite mulr_ge0.
congr (leif _ _ _): (leif_pM Ei_ge0 m1ge0 (leE12 i Pi) le_m12).
by rewrite mulf_eq0 -!orbA; congr (_ || _); rewrite !orb_andr orbA orbb.
Qed.
(* lteif *)
Lemma subr_lteifr0 C x y : (y - x < 0 ?<= if C) = (y < x ?<= if C).
Proof. by case: C => /=; rewrite subr_lte0. Qed.
Lemma subr_lteif0r C x y : (0 < y - x ?<= if C) = (x < y ?<= if C).
Proof. by case: C => /=; rewrite subr_gte0. Qed.
Definition subr_lteif0 := (subr_lteifr0, subr_lteif0r).
Lemma lteif01 C : 0 < 1 ?<= if C :> R.
Proof. by case: C; rewrite /= lter01. Qed.
Lemma lteifNl C x y : - x < y ?<= if C = (- y < x ?<= if C).
Proof. by case: C; rewrite /= lterNl. Qed.
Lemma lteifNr C x y : x < - y ?<= if C = (y < - x ?<= if C).
Proof. by case: C; rewrite /= lterNr. Qed.
Lemma lteif0Nr C x : 0 < - x ?<= if C = (x < 0 ?<= if C).
Proof. by case: C; rewrite /= (oppr_ge0, oppr_gt0). Qed.
Lemma lteifNr0 C x : - x < 0 ?<= if C = (0 < x ?<= if C).
Proof. by case: C; rewrite /= (oppr_le0, oppr_lt0). Qed.
Lemma lteifN2 C : {mono -%R : x y /~ x < y ?<= if C :> R}.
Proof. by case: C => ? ?; rewrite /= lterN2. Qed.
Definition lteif_oppE := (lteif0Nr, lteifNr0, lteifN2).
Lemma lteifD2l C x : {mono +%R x : y z / y < z ?<= if C}.
Proof. by case: C => ? ?; rewrite /= lterD2. Qed.
Lemma lteifD2r C x : {mono +%R^~ x : y z / y < z ?<= if C}.
Proof. by case: C => ? ?; rewrite /= lterD2. Qed.
Definition lteifD2 := (lteifD2l, lteifD2r).
Lemma lteifBlDr C x y z : (x - y < z ?<= if C) = (x < z + y ?<= if C).
Proof. by case: C; rewrite /= lterBDr. Qed.
Lemma lteifBrDr C x y z : (x < y - z ?<= if C) = (x + z < y ?<= if C).
Proof. by case: C; rewrite /= lterBDr. Qed.
Definition lteifBDr := (lteifBlDr, lteifBrDr).
Lemma lteifBlDl C x y z : (x - y < z ?<= if C) = (x < y + z ?<= if C).
Proof. by case: C; rewrite /= lterBDl. Qed.
Lemma lteifBrDl C x y z : (x < y - z ?<= if C) = (z + x < y ?<= if C).
Proof. by case: C; rewrite /= lterBDl. Qed.
Definition lteifBDl := (lteifBlDl, lteifBrDl).
Lemma lteif_pM2l C x : 0 < x -> {mono *%R x : y z / y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_pM2l. Qed.
Lemma lteif_pM2r C x : 0 < x -> {mono *%R^~ x : y z / y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_pM2r. Qed.
Lemma lteif_nM2l C x : x < 0 -> {mono *%R x : y z /~ y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_nM2l. Qed.
Lemma lteif_nM2r C x : x < 0 -> {mono *%R^~ x : y z /~ y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_nM2r. Qed.
Lemma lteif_nnormr C x y : y < 0 ?<= if ~~ C -> (`|x| < y ?<= if C) = false.
Proof. by case: C => ?; rewrite /= lter_nnormr. Qed.
Lemma real_lteifNE x y C : x \is Num.real -> y \is Num.real ->
x < y ?<= if ~~ C = ~~ (y < x ?<= if C).
Proof. by move=> ? ?; rewrite comparable_lteifNE ?real_comparable. Qed.
Lemma real_lteif_norml C x y :
x \is Num.real ->
(`|x| < y ?<= if C) = ((- y < x ?<= if C) && (x < y ?<= if C)).
Proof. by case: C => ?; rewrite /= real_lter_norml. Qed.
Lemma real_lteif_normr C x y :
y \is Num.real ->
(x < `|y| ?<= if C) = ((x < y ?<= if C) || (x < - y ?<= if C)).
Proof. by case: C => ?; rewrite /= real_lter_normr. Qed.
Lemma real_lteif_distl C x y e :
x - y \is real ->
(`|x - y| < e ?<= if C) = (y - e < x ?<= if C) && (x < y + e ?<= if C).
Proof. by case: C => /= ?; rewrite real_lter_distl. Qed.
(* Mean inequalities. *)
Lemma real_leif_mean_square_scaled x y :
x \is real -> y \is real -> x * y *+ 2 <= x ^+ 2 + y ^+ 2 ?= iff (x == y).
Proof.
move=> Rx Ry; rewrite -[_ *+ 2]add0r -leifBRL addrAC -sqrrB -subr_eq0.
by rewrite -sqrf_eq0 eq_sym; apply: leif_eq; rewrite -realEsqr rpredB.
Qed.
Lemma real_leif_AGM2_scaled x y :
x \is real -> y \is real -> x * y *+ 4 <= (x + y) ^+ 2 ?= iff (x == y).
Proof.
move=> Rx Ry; rewrite sqrrD addrAC (mulrnDr _ 2) -leifBLR addrK.
exact: real_leif_mean_square_scaled.
Qed.
Lemma leif_AGM_scaled (I : finType) (A : {pred I}) (E : I -> R) (n := #|A|) :
{in A, forall i, 0 <= E i *+ n} ->
\prod_(i in A) (E i *+ n) <= (\sum_(i in A) E i) ^+ n
?= iff [forall i in A, forall j in A, E i == E j].
Proof.
have [m leAm] := ubnP #|A|; elim: m => // m IHm in A leAm E n * => Ege0.
apply/leifP; case: ifPn => [/forall_inP-Econstant | Enonconstant].
have [i /= Ai | A0] := pickP [in A]; last by rewrite [n]eq_card0 ?big_pred0.
have /eqfun_inP-E_i := Econstant i Ai; rewrite -(eq_bigr _ E_i) sumr_const.
by rewrite exprMn_n prodrMn_const -(eq_bigr _ E_i) prodr_const.
set mu := \sum_(i in A) E i; pose En i := E i *+ n.
pose cmp_mu s := [pred i | s * mu < s * En i].
have{Enonconstant} has_cmp_mu e (s := (-1) ^+ e): {i | i \in A & cmp_mu s i}.
apply/sig2W/exists_inP; apply: contraR Enonconstant => /exists_inPn-mu_s_A.
have n_gt0 i: i \in A -> (0 < n)%N by rewrite [n](cardD1 i) => ->.
have{} mu_s_A i: i \in A -> s * En i <= s * mu.
move=> Ai; rewrite real_leNgt ?mu_s_A ?rpredMsign ?ger0_real ?Ege0 //.
by rewrite -(pmulrn_lge0 _ (n_gt0 i Ai)) -sumrMnl sumr_ge0.
have [_ /esym/eqfun_inP] := leif_sum (fun i Ai => leif_eq (mu_s_A i Ai)).
rewrite sumr_const -/n -mulr_sumr sumrMnl -/mu mulrnAr eqxx => A_mu.
apply/forall_inP=> i Ai; apply/eqfun_inP=> j Aj.
by apply: (pmulrnI (n_gt0 i Ai)); apply: (can_inj (signrMK e)); rewrite !A_mu.
have [[i Ai Ei_lt_mu] [j Aj Ej_gt_mu]] := (has_cmp_mu 1, has_cmp_mu 0)%N.
rewrite {cmp_mu has_cmp_mu}/= !mul1r !mulN1r ltrN2 in Ei_lt_mu Ej_gt_mu.
pose A' := [predD1 A & i]; pose n' := #|A'|.
have [Dn n_gt0]: n = n'.+1 /\ (n > 0)%N by rewrite [n](cardD1 i) Ai.
have i'j: j != i by apply: contraTneq Ej_gt_mu => ->; rewrite lt_gtF.
have{i'j} A'j: j \in A' by rewrite !inE Aj i'j.
have mu_gt0: 0 < mu := le_lt_trans (Ege0 i Ai) Ei_lt_mu.
rewrite (bigD1 i) // big_andbC (bigD1 j) //= mulrA; set pi := \prod_(k | _) _.
have [-> | nz_pi] := eqVneq pi 0; first by rewrite !mulr0 exprn_gt0.
have{nz_pi} pi_gt0: 0 < pi.
by rewrite lt_def nz_pi prodr_ge0 // => k /andP[/andP[_ /Ege0]].
rewrite -/(En i) -/(En j); pose E' := [eta En with j |-> En i + En j - mu].
have E'ge0 k: k \in A' -> E' k *+ n' >= 0.
case/andP=> /= _ Ak; apply: mulrn_wge0; case: ifP => _; last exact: Ege0.
by rewrite subr_ge0 ler_wpDl ?Ege0 // ltW.
rewrite -/n Dn in leAm; have{leAm IHm E'ge0}: _ <= _ := IHm _ leAm _ E'ge0.
have ->: \sum_(k in A') E' k = mu *+ n'.
apply: (addrI mu); rewrite -mulrS -Dn -sumrMnl (bigD1 i Ai) big_andbC /=.
rewrite !(bigD1 j A'j) /= addrCA eqxx !addrA subrK; congr (_ + _).
by apply: eq_bigr => k /andP[_ /negPf->].
rewrite prodrMn_const exprMn_n -/n' ler_pMn2r ?expn_gt0; last by case: (n').
have ->: \prod_(k in A') E' k = E' j * pi.
by rewrite (bigD1 j) //=; congr *%R; apply: eq_bigr => k /andP[_ /negPf->].
rewrite -(ler_pM2l mu_gt0) -exprS -Dn mulrA; apply: lt_le_trans.
rewrite ltr_pM2r //= eqxx -addrA mulrDr mulrC -ltrBlDl -mulrBl.
by rewrite mulrC ltr_pM2r ?subr_gt0.
Qed.
(* Polynomial bound. *)
Implicit Type p : {poly R}.
Lemma poly_disk_bound p b : {ub | forall x, `|x| <= b -> `|p.[x]| <= ub}.
Proof.
exists (\sum_(j < size p) `|p`_j| * b ^+ j) => x le_x_b.
rewrite horner_coef (le_trans (ler_norm_sum _ _ _)) ?ler_sum // => j _.
rewrite normrM normrX ler_wpM2l ?lerXn2r ?unfold_in //=.
exact: le_trans (normr_ge0 x) le_x_b.
Qed.
End NumDomainOperationTheory.
#[global] Hint Resolve lerN2 ltrN2 normr_real : core.
#[global] Hint Extern 0 (is_true (_%:R \is real)) => apply: realn : core.
#[global] Hint Extern 0 (is_true (0 \is real)) => apply: real0 : core.
#[global] Hint Extern 0 (is_true (1 \is real)) => apply: real1 : core.
Arguments ler_sqr {R} [x y].
Arguments ltr_sqr {R} [x y].
Arguments signr_inj {R} [x1 x2].
Arguments real_ler_normlP {R x y}.
Arguments real_ltr_normlP {R x y}.
Section NumDomainMonotonyTheoryForReals.
Local Open Scope order_scope.
Variables (R R' : numDomainType) (D : pred R) (f : R -> R') (f' : R -> nat).
Implicit Types (m n p : nat) (x y z : R) (u v w : R').
Lemma real_mono :
{homo f : x y / x < y} -> {in real &, {mono f : x y / x <= y}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy | le_yx] := real_leP xR yR.
by rewrite ltW_homo.
by rewrite lt_geF ?mf.
Qed.
Lemma real_nmono :
{homo f : x y /~ x < y} -> {in real &, {mono f : x y /~ x <= y}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy|le_yx] := real_ltP xR yR.
by rewrite lt_geF ?mf.
by rewrite ltW_nhomo.
Qed.
Lemma real_mono_in :
{in D &, {homo f : x y / x < y}} ->
{in [pred x in D | x \is real] &, {mono f : x y / x <= y}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma real_nmono_in :
{in D &, {homo f : x y /~ x < y}} ->
{in [pred x in D | x \is real] &, {mono f : x y /~ x <= y}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma realn_mono : {homo f' : x y / x < y >-> (x < y)} ->
{in real &, {mono f' : x y / x <= y >-> (x <= y)}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy | le_yx] := real_leP xR yR.
by rewrite ltW_homo.
by rewrite lt_geF ?mf.
Qed.
Lemma realn_nmono : {homo f' : x y / y < x >-> (x < y)} ->
{in real &, {mono f' : x y / y <= x >-> (x <= y)}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy|le_yx] := real_ltP xR yR.
by rewrite lt_geF ?mf.
by rewrite ltW_nhomo.
Qed.
Lemma realn_mono_in : {in D &, {homo f' : x y / x < y >-> (x < y)}} ->
{in [pred x in D | x \is real] &, {mono f' : x y / x <= y >-> (x <= y)}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma realn_nmono_in : {in D &, {homo f' : x y / y < x >-> (x < y)}} ->
{in [pred x in D | x \is real] &, {mono f' : x y / y <= x >-> (x <= y)}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
End NumDomainMonotonyTheoryForReals.
Section FinGroup.
Variables (R : numDomainType) (gT : finGroupType).
Implicit Types G : {group gT}.
Lemma natrG_gt0 G : #|G|%:R > 0 :> R.
Proof. by rewrite ltr0n cardG_gt0. Qed.
Lemma natrG_neq0 G : #|G|%:R != 0 :> R.
Proof. by rewrite gt_eqF // natrG_gt0. Qed.
Lemma natr_indexg_gt0 G B : #|G : B|%:R > 0 :> R.
Proof. by rewrite ltr0n indexg_gt0. Qed.
Lemma natr_indexg_neq0 G B : #|G : B|%:R != 0 :> R.
Proof. by rewrite gt_eqF // natr_indexg_gt0. Qed.
End FinGroup.
Section RealDomainTheory.
Variable R : realDomainType.
Implicit Types x y z t : R.
Lemma num_real x : x \is real. Proof. exact: num_real. Qed.
Hint Resolve num_real : core.
Lemma lerP x y : ler_xor_gt x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (x <= y) (y < x).
Proof. exact: real_leP. Qed.
Lemma ltrP x y : ltr_xor_ge x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (y <= x) (x < y).
Proof. exact: real_ltP. Qed.
Lemma ltrgtP x y :
comparer x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (y == x) (x == y)
(x >= y) (x <= y) (x > y) (x < y) .
Proof. exact: real_ltgtP. Qed.
Lemma ger0P x : ger0_xor_lt0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (x < 0) (0 <= x).
Proof. exact: real_ge0P. Qed.
Lemma ler0P x : ler0_xor_gt0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 < x) (x <= 0).
Proof. exact: real_le0P. Qed.
Lemma ltrgt0P x : comparer0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 == x) (x == 0) (x <= 0) (0 <= x) (x < 0) (x > 0).
Proof. exact: real_ltgt0P. Qed.
(* sign *)
Lemma mulr_lt0 x y :
(x * y < 0) = [&& x != 0, y != 0 & (x < 0) (+) (y < 0)].
Proof.
have [x_gt0|x_lt0|->] /= := ltrgt0P x; last by rewrite mul0r.
by rewrite pmulr_rlt0 //; case: ltrgt0P.
by rewrite nmulr_rlt0 //; case: ltrgt0P.
Qed.
Lemma neq0_mulr_lt0 x y :
x != 0 -> y != 0 -> (x * y < 0) = (x < 0) (+) (y < 0).
Proof. by move=> x_neq0 y_neq0; rewrite mulr_lt0 x_neq0 y_neq0. Qed.
Lemma mulr_sign_lt0 (b : bool) x :
((-1) ^+ b * x < 0) = (x != 0) && (b (+) (x < 0)%R).
Proof. by rewrite mulr_lt0 signr_lt0 signr_eq0. Qed.
(* sign & norm *)
Lemma mulr_sign_norm x : (-1) ^+ (x < 0)%R * `|x| = x.
Proof. by rewrite -realEsign. Qed.
Lemma mulr_Nsign_norm x : (-1) ^+ (0 < x)%R * `|x| = - x.
Proof. by rewrite real_mulr_Nsign_norm. Qed.
Lemma numEsign x : x = (-1) ^+ (x < 0)%R * `|x|.
Proof. by rewrite -realEsign. Qed.
Lemma numNEsign x : -x = (-1) ^+ (0 < x)%R * `|x|.
Proof. by rewrite -realNEsign. Qed.
Lemma normrEsign x : `|x| = (-1) ^+ (x < 0)%R * x.
Proof. by rewrite -real_normrEsign. Qed.
End RealDomainTheory.
#[global] Hint Resolve num_real : core.
Section RealDomainOperations.
Notation "[ 'arg' 'min_' ( i < i0 | P ) F ]" :=
(Order.arg_min (disp := ring_display) i0 (fun i => P%B) (fun i => F)) :
ring_scope.
Notation "[ 'arg' 'min_' ( i < i0 'in' A ) F ]" :=
[arg min_(i < i0 | i \in A) F] : ring_scope.
Notation "[ 'arg' 'min_' ( i < i0 ) F ]" := [arg min_(i < i0 | true) F] :
ring_scope.
Notation "[ 'arg' 'max_' ( i > i0 | P ) F ]" :=
(Order.arg_max (disp := ring_display) i0 (fun i => P%B) (fun i => F)) :
ring_scope.
Notation "[ 'arg' 'max_' ( i > i0 'in' A ) F ]" :=
[arg max_(i > i0 | i \in A) F] : ring_scope.
Notation "[ 'arg' 'max_' ( i > i0 ) F ]" := [arg max_(i > i0 | true) F] :
ring_scope.
(* sgr section *)
Variable R : realDomainType.
Implicit Types x y z t : R.
Let numR_real := @num_real R.
Hint Resolve numR_real : core.
Lemma sgr_cp0 x :
((sg x == 1) = (0 < x)) *
((sg x == -1) = (x < 0)) *
((sg x == 0) = (x == 0)).
Proof.
rewrite -[1]/((-1) ^+ false) -signrN lt0r leNgt sgr_def.
case: (x =P 0) => [-> | _]; first by rewrite !(eq_sym 0) !signr_eq0 ltxx eqxx.
by rewrite !(inj_eq signr_inj) eqb_id eqbF_neg signr_eq0 //.
Qed.
Variant sgr_val x : R -> bool -> bool -> bool -> bool -> bool -> bool
-> bool -> bool -> bool -> bool -> bool -> bool -> R -> Set :=
| SgrNull of x = 0 : sgr_val x 0 true true true true false false
true false false true false false 0
| SgrPos of x > 0 : sgr_val x x false false true false false true
false false true false false true 1
| SgrNeg of x < 0 : sgr_val x (- x) false true false false true false
false true false false true false (-1).
Lemma sgrP x :
sgr_val x `|x| (0 == x) (x <= 0) (0 <= x) (x == 0) (x < 0) (0 < x)
(0 == sg x) (-1 == sg x) (1 == sg x)
(sg x == 0) (sg x == -1) (sg x == 1) (sg x).
Proof.
by rewrite ![_ == sg _]eq_sym !sgr_cp0 /sg; case: ltrgt0P; constructor.
Qed.
Lemma normrEsg x : `|x| = sg x * x.
Proof. by case: sgrP; rewrite ?(mul0r, mul1r, mulN1r). Qed.
Lemma numEsg x : x = sg x * `|x|.
Proof. by case: sgrP; rewrite !(mul1r, mul0r, mulrNN). Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `numEsg` instead")]
Lemma mulr_sg_norm x : sg x * `|x| = x. Proof. by rewrite -numEsg. Qed.
Lemma sgrM x y : sg (x * y) = sg x * sg y.
Proof.
rewrite !sgr_def mulr_lt0 andbA mulrnAr mulrnAl -mulrnA mulnb -negb_or mulf_eq0.
by case: (~~ _) => //; rewrite signr_addb.
Qed.
Lemma sgrN x : sg (- x) = - sg x.
Proof. by rewrite -mulrN1 sgrM sgrN1 mulrN1. Qed.
Lemma sgrX n x : sg (x ^+ n) = (sg x) ^+ n.
Proof. by elim: n => [|n IHn]; rewrite ?sgr1 // !exprS sgrM IHn. Qed.
Lemma sgr_smul x y : sg (sg x * y) = sg x * sg y.
Proof. by rewrite sgrM sgr_id. Qed.
Lemma sgr_gt0 x : (sg x > 0) = (x > 0).
Proof. by rewrite -[LHS]sgr_cp0 sgr_id sgr_cp0. Qed.
Lemma sgr_ge0 x : (sgr x >= 0) = (x >= 0).
Proof. by rewrite !leNgt sgr_lt0. Qed.
(* norm section *)
Lemma ler_norm x : (x <= `|x|).
Proof. exact: real_ler_norm. Qed.
Lemma ler_norml x y : (`|x| <= y) = (- y <= x <= y).
Proof. exact: real_ler_norml. Qed.
Lemma ler_normlP x y : reflect ((- x <= y) * (x <= y)) (`|x| <= y).
Proof. exact: real_ler_normlP. Qed.
Arguments ler_normlP {x y}.
Lemma eqr_norml x y : (`|x| == y) = ((x == y) || (x == -y)) && (0 <= y).
Proof. exact: real_eqr_norml. Qed.
Lemma eqr_norm2 x y : (`|x| == `|y|) = (x == y) || (x == -y).
Proof. exact: real_eqr_norm2. Qed.
Lemma ltr_norml x y : (`|x| < y) = (- y < x < y).
Proof. exact: real_ltr_norml. Qed.
Definition lter_norml := (ler_norml, ltr_norml).
Lemma ltr_normlP x y : reflect ((-x < y) * (x < y)) (`|x| < y).
Proof. exact: real_ltr_normlP. Qed.
Arguments ltr_normlP {x y}.
Lemma ltr_normlW x y : `|x| < y -> x < y. Proof. exact: real_ltr_normlW. Qed.
Lemma ltrNnormlW x y : `|x| < y -> - y < x. Proof. exact: real_ltrNnormlW. Qed.
Lemma ler_normlW x y : `|x| <= y -> x <= y. Proof. exact: real_ler_normlW. Qed.
Lemma lerNnormlW x y : `|x| <= y -> - y <= x. Proof. exact: real_lerNnormlW. Qed.
Lemma ler_normr x y : (x <= `|y|) = (x <= y) || (x <= - y).
Proof. exact: real_ler_normr. Qed.
Lemma ltr_normr x y : (x < `|y|) = (x < y) || (x < - y).
Proof. exact: real_ltr_normr. Qed.
Definition lter_normr := (ler_normr, ltr_normr).
Lemma ler_distl x y e : (`|x - y| <= e) = (y - e <= x <= y + e).
Proof. exact: real_ler_distl. Qed.
Lemma ltr_distl x y e : (`|x - y| < e) = (y - e < x < y + e).
Proof. exact: real_ltr_distl. Qed.
Definition lter_distl := (ler_distl, ltr_distl).
Lemma ltr_distlC x y e : (`|x - y| < e) = (x - e < y < x + e).
Proof. by rewrite distrC ltr_distl. Qed.
Lemma ler_distlC x y e : (`|x - y| <= e) = (x - e <= y <= x + e).
Proof. by rewrite distrC ler_distl. Qed.
Definition lter_distlC := (ler_distlC, ltr_distlC).
Lemma ltr_distlDr x y e : `|x - y| < e -> x < y + e.
Proof. exact: real_ltr_distlDr. Qed.
Lemma ler_distlDr x y e : `|x - y| <= e -> x <= y + e.
Proof. exact: real_ler_distlDr. Qed.
Lemma ltr_distlCDr x y e : `|x - y| < e -> y < x + e.
Proof. exact: real_ltr_distlCDr. Qed.
Lemma ler_distlCDr x y e : `|x - y| <= e -> y <= x + e.
Proof. exact: real_ler_distlCDr. Qed.
Lemma ltr_distlBl x y e : `|x - y| < e -> x - e < y.
Proof. exact: real_ltr_distlBl. Qed.
Lemma ler_distlBl x y e : `|x - y| <= e -> x - e <= y.
Proof. exact: real_ler_distlBl. Qed.
Lemma ltr_distlCBl x y e : `|x - y| < e -> y - e < x.
Proof. exact: real_ltr_distlCBl. Qed.
Lemma ler_distlCBl x y e : `|x - y| <= e -> y - e <= x.
Proof. exact: real_ler_distlCBl. Qed.
Lemma exprn_even_ge0 n x : ~~ odd n -> 0 <= x ^+ n.
Proof. by move=> even_n; rewrite real_exprn_even_ge0 ?num_real. Qed.
Lemma exprn_even_gt0 n x : ~~ odd n -> (0 < x ^+ n) = (n == 0)%N || (x != 0).
Proof. by move=> even_n; rewrite real_exprn_even_gt0 ?num_real. Qed.
Lemma exprn_even_le0 n x : ~~ odd n -> (x ^+ n <= 0) = (n != 0) && (x == 0).
Proof. by move=> even_n; rewrite real_exprn_even_le0 ?num_real. Qed.
Lemma exprn_even_lt0 n x : ~~ odd n -> (x ^+ n < 0) = false.
Proof. by move=> even_n; rewrite real_exprn_even_lt0 ?num_real. Qed.
Lemma exprn_odd_ge0 n x : odd n -> (0 <= x ^+ n) = (0 <= x).
Proof. by move=> even_n; rewrite real_exprn_odd_ge0 ?num_real. Qed.
Lemma exprn_odd_gt0 n x : odd n -> (0 < x ^+ n) = (0 < x).
Proof. by move=> even_n; rewrite real_exprn_odd_gt0 ?num_real. Qed.
Lemma exprn_odd_le0 n x : odd n -> (x ^+ n <= 0) = (x <= 0).
Proof. by move=> even_n; rewrite real_exprn_odd_le0 ?num_real. Qed.
Lemma exprn_odd_lt0 n x : odd n -> (x ^+ n < 0) = (x < 0).
Proof. by move=> even_n; rewrite real_exprn_odd_lt0 ?num_real. Qed.
(* lteif *)
Lemma lteif_norml C x y :
(`|x| < y ?<= if C) = (- y < x ?<= if C) && (x < y ?<= if C).
Proof. by case: C; rewrite /= lter_norml. Qed.
Lemma lteif_normr C x y :
(x < `|y| ?<= if C) = (x < y ?<= if C) || (x < - y ?<= if C).
Proof. by case: C; rewrite /= lter_normr. Qed.
Lemma lteif_distl C x y e :
(`|x - y| < e ?<= if C) = (y - e < x ?<= if C) && (x < y + e ?<= if C).
Proof. by case: C; rewrite /= lter_distl. Qed.
(* Special lemmas for squares. *)
Lemma sqr_ge0 x : 0 <= x ^+ 2. Proof. by rewrite exprn_even_ge0. Qed.
Lemma sqr_norm_eq1 x : (x ^+ 2 == 1) = (`|x| == 1).
Proof. by rewrite sqrf_eq1 eqr_norml ler01 andbT. Qed.
Lemma leif_mean_square_scaled x y :
x * y *+ 2 <= x ^+ 2 + y ^+ 2 ?= iff (x == y).
Proof. exact: real_leif_mean_square_scaled. Qed.
Lemma leif_AGM2_scaled x y : x * y *+ 4 <= (x + y) ^+ 2 ?= iff (x == y).
Proof. exact: real_leif_AGM2_scaled. Qed.
Section MinMax.
Lemma oppr_max : {morph -%R : x y / max x y >-> min x y : R}.
Proof. by move=> x y; apply: real_oppr_max. Qed.
Lemma oppr_min : {morph -%R : x y / min x y >-> max x y : R}.
Proof. by move=> x y; apply: real_oppr_min. Qed.
Lemma addr_minl : @left_distributive R R +%R min.
Proof. by move=> x y z; apply: real_addr_minl. Qed.
Lemma addr_minr : @right_distributive R R +%R min.
Proof. by move=> x y z; apply: real_addr_minr. Qed.
Lemma addr_maxl : @left_distributive R R +%R max.
Proof. by move=> x y z; apply: real_addr_maxl. Qed.
Lemma addr_maxr : @right_distributive R R +%R max.
Proof. by move=> x y z; apply: real_addr_maxr. Qed.
Lemma minr_nMr x y z : x <= 0 -> x * min y z = max (x * y) (x * z).
Proof. by move=> x_le0; apply: real_minr_nMr. Qed.
Lemma maxr_nMr x y z : x <= 0 -> x * max y z = min (x * y) (x * z).
Proof. by move=> x_le0; apply: real_maxr_nMr. Qed.
Lemma minr_nMl x y z : x <= 0 -> min y z * x = max (y * x) (z * x).
Proof. by move=> x_le0; apply: real_minr_nMl. Qed.
Lemma maxr_nMl x y z : x <= 0 -> max y z * x = min (y * x) (z * x).
Proof. by move=> x_le0; apply: real_maxr_nMl. Qed.
Lemma maxrN x : max x (- x) = `|x|. Proof. exact: real_maxrN. Qed.
Lemma maxNr x : max (- x) x = `|x|. Proof. exact: real_maxNr. Qed.
Lemma minrN x : min x (- x) = - `|x|. Proof. exact: real_minrN. Qed.
Lemma minNr x : min (- x) x = - `|x|. Proof. exact: real_minNr. Qed.
End MinMax.
Section PolyBounds.
Variable p : {poly R}.
Lemma poly_itv_bound a b : {ub | forall x, a <= x <= b -> `|p.[x]| <= ub}.
Proof.
have [ub le_p_ub] := poly_disk_bound p (Num.max `|a| `|b|).
exists ub => x /andP[le_a_x le_x_b]; rewrite le_p_ub // le_max !ler_normr.
by have [_|_] := ler0P x; rewrite ?lerN2 ?le_a_x ?le_x_b orbT.
Qed.
Lemma monic_Cauchy_bound : p \is monic -> {b | forall x, x >= b -> p.[x] > 0}.
Proof.
move/monicP=> mon_p; pose n := (size p - 2)%N.
have [p_le1 | p_gt1] := leqP (size p) 1.
exists 0 => x _; rewrite (size1_polyC p_le1) hornerC.
by rewrite -[p`_0]lead_coefC -size1_polyC // mon_p ltr01.
pose lb := \sum_(j < n.+1) `|p`_j|; exists (lb + 1) => x le_ub_x.
have x_ge1: 1 <= x; last have x_gt0 := lt_le_trans ltr01 x_ge1.
by rewrite -(lerD2l lb) ler_wpDl ?sumr_ge0 // => j _.
rewrite horner_coef -(subnK p_gt1) -/n addnS big_ord_recr /= addn1.
rewrite [in p`__]subnSK // subn1 -lead_coefE mon_p mul1r -ltrBlDl sub0r.
apply: le_lt_trans (_ : lb * x ^+ n < _); last first.
by rewrite exprS ltr_pM2r ?exprn_gt0// -(ltrD2r 1) ltr_pwDr.
rewrite -sumrN mulr_suml ler_sum // => j _; apply: le_trans (ler_norm _) _.
rewrite normrN normrM ler_wpM2l // normrX.
by rewrite ger0_norm ?(ltW x_gt0) // ler_weXn2l ?leq_ord.
Qed.
End PolyBounds.
End RealDomainOperations.
End Theory.
HB.factory Record IntegralDomain_isNumRing R of GRing.IntegralDomain R := {
Rle : rel R;
Rlt : rel R;
norm : R -> R;
normD : forall x y, Rle (norm (x + y)) (norm x + norm y);
addr_gt0 : forall x y, Rlt 0 x -> Rlt 0 y -> Rlt 0 (x + y);
norm_eq0 : forall x, norm x = 0 -> x = 0;
ger_total : forall x y, Rle 0 x -> Rle 0 y -> Rle x y || Rle y x;
normM : {morph norm : x y / x * y};
le_def : forall x y, (Rle x y) = (norm (y - x) == y - x);
lt_def : forall x y, (Rlt x y) = (y != x) && (Rle x y)
}.
HB.builders Context R of IntegralDomain_isNumRing R.
Local Notation "x <= y" := (Rle x y) : ring_scope.
Local Notation "x < y" := (Rlt x y) : ring_scope.
Local Notation "`| x |" := (norm x) : ring_scope.
Lemma ltrr x : x < x = false. Proof. by rewrite lt_def eqxx. Qed.
Lemma ge0_def x : (0 <= x) = (`|x| == x).
Proof. by rewrite le_def subr0. Qed.
Lemma subr_ge0 x y : (0 <= x - y) = (y <= x).
Proof. by rewrite ge0_def -le_def. Qed.
Lemma subr_gt0 x y : (0 < y - x) = (x < y).
Proof. by rewrite !lt_def subr_eq0 subr_ge0. Qed.
Lemma lt_trans : transitive Rlt.
Proof.
move=> y x z le_xy le_yz.
by rewrite -subr_gt0 -(subrK y z) -addrA addr_gt0 // subr_gt0.
Qed.
Lemma le01 : 0 <= 1.
Proof.
have n1_nz: `|1| != 0 :> R by apply: contraNneq (@oner_neq0 R) => /norm_eq0->.
by rewrite ge0_def -(inj_eq (mulfI n1_nz)) -normM !mulr1.
Qed.
Lemma lt01 : 0 < 1.
Proof. by rewrite lt_def oner_neq0 le01. Qed.
Lemma ltW x y : x < y -> x <= y. Proof. by rewrite lt_def => /andP[]. Qed.
Lemma lerr x : x <= x.
Proof.
have n2: `|2| == 2 :> R by rewrite -ge0_def ltW ?addr_gt0 ?lt01.
rewrite le_def subrr -(inj_eq (addrI `|0|)) addr0 -mulr2n -mulr_natr.
by rewrite -(eqP n2) -normM mul0r.
Qed.
Lemma le_def' x y : (x <= y) = (x == y) || (x < y).
Proof. by rewrite lt_def; case: eqVneq => //= ->; rewrite lerr. Qed.
Lemma le_trans : transitive Rle.
by move=> y x z; rewrite !le_def' => /predU1P [->|hxy] // /predU1P [<-|hyz];
rewrite ?hxy ?(lt_trans hxy hyz) orbT.
Qed.
Lemma normrMn x n : `|x *+ n| = `|x| *+ n.
Proof.
rewrite -mulr_natr -[RHS]mulr_natr normM.
congr (_ * _); apply/eqP; rewrite -ge0_def.
elim: n => [|n ih]; [exact: lerr | apply: (le_trans ih)].
by rewrite le_def -natrB // subSnn -[_%:R]subr0 -le_def mulr1n le01.
Qed.
Lemma normrN1 : `|-1| = 1 :> R.
Proof.
have: `|-1| ^+ 2 == 1 :> R
by rewrite expr2 /= -normM mulrNN mul1r -[1]subr0 -le_def le01.
rewrite sqrf_eq1 => /predU1P [] //; rewrite -[-1]subr0 -le_def.
have ->: 0 <= -1 = (-1 == 0 :> R) || (0 < -1)
by rewrite lt_def; case: eqP => // ->; rewrite lerr.
by rewrite oppr_eq0 oner_eq0 => /(addr_gt0 lt01); rewrite subrr ltrr.
Qed.
Lemma normrN x : `|- x| = `|x|.
Proof. by rewrite -mulN1r normM -[RHS]mul1r normrN1. Qed.
HB.instance Definition _ :=
Order.LtLe_isPOrder.Build ring_display R le_def' ltrr lt_trans.
HB.instance Definition _ :=
Zmodule_isNormed.Build _ R normD norm_eq0 normrMn normrN.
HB.instance Definition _ :=
isNumRing.Build R addr_gt0 ger_total normM le_def.
HB.end.
HB.factory Record NumDomain_isReal R of NumDomain R := {
real : real_axiom R
}.
HB.builders Context R of NumDomain_isReal R.
Lemma le_total : Order.POrder_isTotal ring_display R.
Proof.
constructor=> x y; move: (real (x - y)).
by rewrite unfold_in /= !ler_def subr0 add0r opprB orbC.
Qed.
HB.instance Definition _ := le_total.
HB.end.
HB.factory Record IntegralDomain_isLeReal R of GRing.IntegralDomain R := {
Rle : rel R;
Rlt : rel R;
norm : R -> R;
le0_add : forall x y, Rle 0 x -> Rle 0 y -> Rle 0 (x + y);
le0_mul : forall x y, Rle 0 x -> Rle 0 y -> Rle 0 (x * y);
le0_anti : forall x, Rle 0 x -> Rle x 0 -> x = 0;
sub_ge0 : forall x y, Rle 0 (y - x) = Rle x y;
le0_total : forall x, Rle 0 x || Rle x 0;
normN : forall x, norm (- x) = norm x;
ge0_norm : forall x, Rle 0 x -> norm x = x;
lt_def : forall x y, Rlt x y = (y != x) && Rle x y;
}.
HB.builders Context R of IntegralDomain_isLeReal R.
Local Notation le := Rle.
Local Notation lt := Rlt.
Local Notation "x <= y" := (le x y) : ring_scope.
Local Notation "x < y" := (lt x y) : ring_scope.
Local Notation "`| x |" := (norm x) : ring_scope.
Let le0N x : (0 <= - x) = (x <= 0). Proof. by rewrite -sub0r sub_ge0. Qed.
Let leN_total x : 0 <= x \/ 0 <= - x.
Proof. by apply/orP; rewrite le0N le0_total. Qed.
Let le00 : 0 <= 0. Proof. by have:= le0_total 0; rewrite orbb. Qed.
Fact lt0_add x y : 0 < x -> 0 < y -> 0 < x + y.
Proof.
rewrite !lt_def => /andP [x_neq0 l0x] /andP [y_neq0 l0y]; rewrite le0_add //.
rewrite andbT addr_eq0; apply: contraNneq x_neq0 => hxy.
by rewrite [x](@le0_anti) // hxy -le0N opprK.
Qed.
Fact eq0_norm x : `|x| = 0 -> x = 0.
Proof.
case: (leN_total x) => /ge0_norm => [-> // | Dnx nx0].
by rewrite -[x]opprK -Dnx normN nx0 oppr0.
Qed.
Fact le_def x y : (x <= y) = (`|y - x| == y - x).
Proof.
wlog ->: x y / x = 0 by move/(_ 0 (y - x)); rewrite subr0 sub_ge0 => ->.
rewrite {x}subr0; apply/idP/eqP=> [/ge0_norm// | Dy].
by have [//| ny_ge0] := leN_total y; rewrite -Dy -normN ge0_norm.
Qed.
Fact normM : {morph norm : x y / x * y}.
Proof.
move=> x y /=; wlog x_ge0 : x / 0 <= x.
by move=> IHx; case: (leN_total x) => /IHx//; rewrite mulNr !normN.
wlog y_ge0 : y / 0 <= y; last by rewrite ?ge0_norm ?le0_mul.
by move=> IHy; case: (leN_total y) => /IHy//; rewrite mulrN !normN.
Qed.
Fact le_normD x y : `|x + y| <= `|x| + `|y|.
Proof.
wlog x_ge0 : x y / 0 <= x.
by move=> IH; case: (leN_total x) => /IH// /(_ (- y)); rewrite -opprD !normN.
rewrite -sub_ge0 ge0_norm //; have [y_ge0 | ny_ge0] := leN_total y.
by rewrite !ge0_norm ?subrr ?le0_add.
rewrite -normN ge0_norm //; have [hxy|hxy] := leN_total (x + y).
by rewrite ge0_norm // opprD addrCA -addrA addKr le0_add.
by rewrite -normN ge0_norm // opprK addrCA addrNK le0_add.
Qed.
Fact le_total : total le.
Proof. by move=> x y; rewrite -sub_ge0 -opprB le0N orbC -sub_ge0 le0_total. Qed.
HB.instance Definition _ := IntegralDomain_isNumRing.Build R
le_normD lt0_add eq0_norm (in2W le_total) normM le_def lt_def.
HB.instance Definition _ := Order.POrder_isTotal.Build ring_display R
le_total.
HB.end.
HB.factory Record IntegralDomain_isLtReal R of GRing.IntegralDomain R := {
Rlt : rel R;
Rle : rel R;
norm : R -> R;
lt0_add : forall x y, Rlt 0 x -> Rlt 0 y -> Rlt 0 (x + y);
lt0_mul : forall x y, Rlt 0 x -> Rlt 0 y -> Rlt 0 (x * y);
lt0_ngt0 : forall x, Rlt 0 x -> ~~ (Rlt x 0);
sub_gt0 : forall x y, Rlt 0 (y - x) = Rlt x y;
lt0_total : forall x, x != 0 -> Rlt 0 x || Rlt x 0;
normN : forall x, norm (- x) = norm x;
ge0_norm : forall x, Rle 0 x -> norm x = x;
le_def : forall x y, Rle x y = (x == y) || Rlt x y;
}.
HB.builders Context R of IntegralDomain_isLtReal R.
Local Notation le := Rle.
Local Notation lt := Rlt.
Local Notation "x < y" := (lt x y) : ring_scope.
Local Notation "x <= y" := (le x y) : ring_scope.
Local Notation "`| x |" := (norm x) : ring_scope.
Fact lt0N x : (- x < 0) = (0 < x).
Proof. by rewrite -sub_gt0 add0r opprK. Qed.
Let leN_total x : 0 <= x \/ 0 <= - x.
Proof.
rewrite !le_def [_ == - x]eq_sym oppr_eq0 -[0 < - x]lt0N opprK.
apply/orP; case: (eqVneq x) => //=; exact: lt0_total.
Qed.
Let le00 : (0 <= 0). Proof. by rewrite le_def eqxx. Qed.
Fact sub_ge0 x y : (0 <= y - x) = (x <= y).
Proof. by rewrite !le_def eq_sym subr_eq0 eq_sym sub_gt0. Qed.
Fact le0_add x y : 0 <= x -> 0 <= y -> 0 <= x + y.
Proof.
rewrite !le_def => /predU1P [<-|x_gt0]; first by rewrite add0r.
by case/predU1P=> [<-|y_gt0]; rewrite ?addr0 ?x_gt0 ?lt0_add // orbT.
Qed.
Fact le0_mul x y : 0 <= x -> 0 <= y -> 0 <= x * y.
Proof.
rewrite !le_def => /predU1P [<-|x_gt0]; first by rewrite mul0r eqxx.
by case/predU1P=> [<-|y_gt0]; rewrite ?mulr0 ?eqxx ?lt0_mul // orbT.
Qed.
Fact normM : {morph norm : x y / x * y}.
Proof.
move=> x y /=; wlog x_ge0 : x / 0 <= x.
by move=> IHx; case: (leN_total x) => /IHx//; rewrite mulNr !normN.
wlog y_ge0 : y / 0 <= y; last by rewrite ?ge0_norm ?le0_mul.
by move=> IHy; case: (leN_total y) => /IHy//; rewrite mulrN !normN.
Qed.
Fact le_normD x y : `|x + y| <= `|x| + `|y|.
Proof.
wlog x_ge0 : x y / 0 <= x.
by move=> IH; case: (leN_total x) => /IH// /(_ (- y)); rewrite -opprD !normN.
rewrite -sub_ge0 ge0_norm //; have [y_ge0 | ny_ge0] := leN_total y.
by rewrite !ge0_norm ?subrr ?le0_add.
rewrite -normN ge0_norm //; have [hxy|hxy] := leN_total (x + y).
by rewrite ge0_norm // opprD addrCA -addrA addKr le0_add.
by rewrite -normN ge0_norm // opprK addrCA addrNK le0_add.
Qed.
Fact eq0_norm x : `|x| = 0 -> x = 0.
Proof.
case: (leN_total x) => /ge0_norm => [-> // | Dnx nx0].
by rewrite -[x]opprK -Dnx normN nx0 oppr0.
Qed.
Fact le_def' x y : (x <= y) = (`|y - x| == y - x).
Proof.
wlog ->: x y / x = 0 by move/(_ 0 (y - x)); rewrite subr0 sub_ge0 => ->.
rewrite {x}subr0; apply/idP/eqP=> [/ge0_norm// | Dy].
by have [//| ny_ge0] := leN_total y; rewrite -Dy -normN ge0_norm.
Qed.
Fact lt_def x y : (x < y) = (y != x) && (x <= y).
Proof.
rewrite le_def; case: eqVneq => //= ->; rewrite -sub_gt0 subrr.
by apply/idP=> lt00; case/negP: (lt0_ngt0 lt00).
Qed.
Fact le_total : total le.
Proof.
move=> x y; rewrite !le_def; have [->|] //= := eqVneq; rewrite -subr_eq0.
by move/lt0_total; rewrite -(sub_gt0 (x - y)) sub0r opprB !sub_gt0 orbC.
Qed.
HB.instance Definition _ := IntegralDomain_isNumRing.Build R
le_normD lt0_add eq0_norm (in2W le_total) normM le_def' lt_def.
HB.instance Definition _ := Order.POrder_isTotal.Build ring_display R
le_total.
HB.end.
Module Exports. HB.reexport. End Exports.
End Num.
Export Num.Exports Num.Syntax Num.PredInstances.
|
OfBilinear.lean
|
/-
Copyright (c) 2024 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.LinearAlgebra.RootSystem.Defs
/-!
# Root pairings made from bilinear forms
A common construction of root systems is given by taking the set of all vectors in an integral
lattice for which reflection yields an automorphism of the lattice. In this file, we generalize
this construction, replacing the ring of integers with an arbitrary commutative ring and the
integral lattice with an arbitrary reflexive module equipped with a bilinear form.
## Main definitions:
* `LinearMap.IsReflective`: Length is a regular value of `R`, and reflection is definable.
* `LinearMap.IsReflective.coroot`: The coroot corresponding to a reflective vector.
* `RootPairing.of_Bilinear`: The root pairing whose roots are reflective vectors.
## TODO
* properties
-/
open Set Function Module
noncomputable section
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
namespace LinearMap
/-- A vector `x` is reflective with respect to a bilinear form if multiplication by its norm is
injective, and for any vector `y`, the norm of `x` divides twice the inner product of `x` and `y`.
These conditions are what we need when describing reflection as a map taking `y` to
`y - 2 • (B x y) / (B x x) • x`. -/
structure IsReflective (B : M →ₗ[R] M →ₗ[R] R) (x : M) : Prop where
regular : IsRegular (B x x)
dvd_two_mul : ∀ y, B x x ∣ 2 * B x y
variable (B : M →ₗ[R] M →ₗ[R] R) {x : M}
namespace IsReflective
lemma of_dvd_two [IsCancelMulZero R] [NeZero (2 : R)] (hx : B x x ∣ 2) :
IsReflective B x where
regular := isRegular_of_ne_zero <| fun contra ↦ by simp [contra, two_ne_zero (α := R)] at hx
dvd_two_mul y := hx.mul_right (B x y)
variable (hx : IsReflective B x)
/-- The coroot attached to a reflective vector. -/
def coroot : M →ₗ[R] R where
toFun y := (hx.2 y).choose
map_add' a b := by
refine hx.1.1 ?_
simp only
rw [← (hx.2 (a + b)).choose_spec, mul_add, ← (hx.2 a).choose_spec, ← (hx.2 b).choose_spec,
map_add, mul_add]
map_smul' r a := by
refine hx.1.1 ?_
simp only [RingHom.id_apply]
rw [← (hx.2 (r • a)).choose_spec, smul_eq_mul, mul_left_comm, ← (hx.2 a).choose_spec, map_smul,
two_mul, smul_eq_mul, two_mul, mul_add]
@[simp]
lemma apply_self_mul_coroot_apply {y : M} : B x x * coroot B hx y = 2 * B x y :=
(hx.dvd_two_mul y).choose_spec.symm
@[simp]
lemma smul_coroot : B x x • coroot B hx = 2 • B x := by
ext y
simp [smul_apply, smul_eq_mul, nsmul_eq_mul, Nat.cast_ofNat, apply_self_mul_coroot_apply]
@[simp]
lemma coroot_apply_self : coroot B hx x = 2 :=
hx.regular.left <| by simp [mul_comm _ (B x x)]
lemma isOrthogonal_reflection (hSB : LinearMap.IsSymm B) :
B.IsOrthogonal (Module.reflection (coroot_apply_self B hx)) := by
intro y z
simp only [reflection_apply, LinearMap.map_sub, map_smul, sub_apply,
smul_apply, smul_eq_mul]
refine hx.1.1 ?_
simp only [mul_sub, ← mul_assoc, apply_self_mul_coroot_apply]
rw [sub_eq_iff_eq_add, ← hSB.eq x y, RingHom.id_apply, mul_assoc _ _ (B x x), mul_comm _ (B x x),
apply_self_mul_coroot_apply]
ring
lemma reflective_reflection (hSB : LinearMap.IsSymm B) {y : M}
(hx : IsReflective B x) (hy : IsReflective B y) :
IsReflective B (Module.reflection (coroot_apply_self B hx) y) := by
constructor
· rw [isOrthogonal_reflection B hx hSB]
exact hy.1
· intro z
have hz : Module.reflection (coroot_apply_self B hx)
(Module.reflection (coroot_apply_self B hx) z) = z := by
exact (LinearEquiv.eq_symm_apply (Module.reflection (coroot_apply_self B hx))).mp rfl
rw [← hz, isOrthogonal_reflection B hx hSB,
isOrthogonal_reflection B hx hSB]
exact hy.2 _
end IsReflective
end LinearMap
namespace RootPairing
open LinearMap IsReflective
/-- The root pairing given by all reflective vectors for a bilinear form. -/
def ofBilinear [IsReflexive R M] (B : M →ₗ[R] M →ₗ[R] R) (hNB : LinearMap.Nondegenerate B)
(hSB : LinearMap.IsSymm B) (h2 : IsRegular (2 : R)) :
RootPairing {x : M | IsReflective B x} R M (Dual R M) where
toPerfectPairing := (IsReflexive.toPerfectPairingDual (R := R) (M := M)).flip
root := Embedding.subtype fun x ↦ IsReflective B x
coroot :=
{ toFun := fun x => IsReflective.coroot B x.2
inj' := by
intro x y hxy
simp only [mem_setOf_eq] at hxy -- x* = y*
have h1 : ∀ z, IsReflective.coroot B x.2 z = IsReflective.coroot B y.2 z :=
fun z => congrFun (congrArg DFunLike.coe hxy) z
have h2x : ∀ z, B x x * IsReflective.coroot B x.2 z =
B x x * IsReflective.coroot B y.2 z :=
fun z => congrArg (HMul.hMul ((B x) x)) (h1 z)
have h2y : ∀ z, B y y * IsReflective.coroot B x.2 z =
B y y * IsReflective.coroot B y.2 z :=
fun z => congrArg (HMul.hMul ((B y) y)) (h1 z)
simp_rw [apply_self_mul_coroot_apply B x.2] at h2x -- 2(x,z) = (x,x)y*(z)
simp_rw [apply_self_mul_coroot_apply B y.2] at h2y -- (y,y)x*(z) = 2(y,z)
have h2xy : B x x = B y y := by
refine h2.1 ?_
dsimp only
specialize h2x y
rw [coroot_apply_self] at h2x
specialize h2y x
rw [coroot_apply_self] at h2y
rw [mul_comm, ← h2x, ← hSB.eq, RingHom.id_apply, ← h2y, mul_comm]
rw [Subtype.ext_iff_val, ← sub_eq_zero]
refine hNB.1 _ (fun z => ?_)
rw [map_sub, LinearMap.sub_apply, sub_eq_zero]
refine h2.1 ?_
dsimp only
rw [h2x z, ← h2y z, hxy, h2xy] }
root_coroot_two x := by
dsimp only [coe_setOf, Embedding.coe_subtype, PerfectPairing.toLinearMap_apply, mem_setOf_eq,
id_eq, eq_mp_eq_cast, RingHom.id_apply, eq_mpr_eq_cast, cast_eq, LinearMap.sub_apply,
Embedding.coeFn_mk, PerfectPairing.flip_apply_apply]
exact coroot_apply_self B x.2
reflectionPerm x :=
{ toFun := fun y => ⟨(Module.reflection (coroot_apply_self B x.2) y),
reflective_reflection B hSB x.2 y.2⟩
invFun := fun y => ⟨(Module.reflection (coroot_apply_self B x.2) y),
reflective_reflection B hSB x.2 y.2⟩
left_inv := by
intro y
simp [involutive_reflection (coroot_apply_self B x.2) y]
right_inv := by
intro y
simp [involutive_reflection (coroot_apply_self B x.2) y] }
reflectionPerm_root x y := by
simp [Module.reflection_apply]
reflectionPerm_coroot x y := by
simp only [coe_setOf, mem_setOf_eq, Embedding.coeFn_mk, Embedding.subtype_apply,
PerfectPairing.flip_apply_apply, IsReflexive.toPerfectPairingDual_toFun, Equiv.coe_fn_mk]
ext z
simp only [sub_apply, smul_apply, smul_eq_mul]
refine y.2.1.1 ?_
simp only [mem_setOf_eq, mul_sub, apply_self_mul_coroot_apply B y.2, ← mul_assoc]
rw [← isOrthogonal_reflection B x.2 hSB y y, apply_self_mul_coroot_apply, ← hSB.eq z,
← hSB.eq z, RingHom.id_apply, RingHom.id_apply, Module.reflection_apply, map_sub,
mul_sub, sub_eq_sub_iff_comm, sub_left_inj]
refine x.2.1.1 ?_
simp only [mem_setOf_eq, map_smul, smul_eq_mul]
rw [← mul_assoc _ _ (B z x), ← mul_assoc _ _ (B z x), mul_left_comm,
apply_self_mul_coroot_apply B x.2, mul_left_comm (B x x), apply_self_mul_coroot_apply B x.2,
← hSB.eq x y, RingHom.id_apply, ← hSB.eq x z, RingHom.id_apply]
ring
end RootPairing
|
LeftDerived.lean
|
/-
Copyright (c) 2025 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Functor.KanExtension.Basic
import Mathlib.CategoryTheory.Localization.Predicate
/-!
# Left derived functors
In this file, given a functor `F : C ⥤ H`, and `L : C ⥤ D` that is a
localization functor for `W : MorphismProperty C`, we define
`F.totalLeftDerived L W : D ⥤ H` as the right Kan extension of `F`
along `L`: it is defined if the type class `F.HasLeftDerivedFunctor W`
asserting the existence of a right Kan extension is satisfied.
(The name `totalLeftDerived` is to avoid name-collision with
`Functor.leftDerived` which are the left derived functors in
the context of abelian categories.)
Given `LF : D ⥤ H` and `α : L ⋙ RF ⟶ F`, we also introduce a type class
`F.IsLeftDerivedFunctor α W` saying that `α` is a right Kan extension of `F`
along the localization functor `L`.
(This file was obtained by dualizing the results in the file
`Mathlib.CategoryTheory.Functor.Derived.RightDerived`.)
## References
* https://ncatlab.org/nlab/show/derived+functor
-/
namespace CategoryTheory
namespace Functor
variable {C C' D D' H H' : Type _} [Category C] [Category C']
[Category D] [Category D'] [Category H] [Category H']
(LF'' LF' LF : D ⥤ H) {F F' F'' : C ⥤ H} (e : F ≅ F') {L : C ⥤ D}
(α'' : L ⋙ LF'' ⟶ F'') (α' : L ⋙ LF' ⟶ F') (α : L ⋙ LF ⟶ F) (α'₂ : L ⋙ LF' ⟶ F)
(W : MorphismProperty C)
/-- A functor `LF : D ⥤ H` is a left derived functor of `F : C ⥤ H`
if it is equipped with a natural transformation `α : L ⋙ LF ⟶ F`
which makes it a right Kan extension of `F` along `L`,
where `L : C ⥤ D` is a localization functor for `W : MorphismProperty C`. -/
class IsLeftDerivedFunctor (LF : D ⥤ H) {F : C ⥤ H} {L : C ⥤ D} (α : L ⋙ LF ⟶ F)
(W : MorphismProperty C) [L.IsLocalization W] : Prop where
isRightKanExtension (LF α) : LF.IsRightKanExtension α
lemma isLeftDerivedFunctor_iff_isRightKanExtension [L.IsLocalization W] :
LF.IsLeftDerivedFunctor α W ↔ LF.IsRightKanExtension α := by
constructor
· exact fun _ => IsLeftDerivedFunctor.isRightKanExtension LF α W
· exact fun h => ⟨h⟩
variable {RF RF'} in
lemma isLeftDerivedFunctor_iff_of_iso (α' : L ⋙ LF' ⟶ F) (W : MorphismProperty C)
[L.IsLocalization W] (e : LF ≅ LF') (comm : whiskerLeft L e.hom ≫ α' = α) :
LF.IsLeftDerivedFunctor α W ↔ LF'.IsLeftDerivedFunctor α' W := by
simp only [isLeftDerivedFunctor_iff_isRightKanExtension]
exact isRightKanExtension_iff_of_iso e _ _ comm
section
variable [L.IsLocalization W] [LF.IsLeftDerivedFunctor α W]
/-- Constructor for natural transformations to a left derived functor. -/
noncomputable def leftDerivedLift (G : D ⥤ H) (β : L ⋙ G ⟶ F) : G ⟶ LF :=
have := IsLeftDerivedFunctor.isRightKanExtension LF α W
LF.liftOfIsRightKanExtension α G β
@[reassoc (attr := simp)]
lemma leftDerived_fac (G : D ⥤ H) (β : L ⋙ G ⟶ F) :
whiskerLeft L (LF.leftDerivedLift α W G β) ≫ α = β :=
have := IsLeftDerivedFunctor.isRightKanExtension LF α W
LF.liftOfIsRightKanExtension_fac α G β
@[reassoc (attr := simp)]
lemma leftDerived_fac_app (G : D ⥤ H) (β : L ⋙ G ⟶ F) (X : C) :
(LF.leftDerivedLift α W G β).app (L.obj X) ≫ α.app X = β.app X :=
have := IsLeftDerivedFunctor.isRightKanExtension LF α W
LF.liftOfIsRightKanExtension_fac_app α G β X
include W in
lemma leftDerived_ext (G : D ⥤ H) (γ₁ γ₂ : G ⟶ LF)
(hγ : whiskerLeft L γ₁ ≫ α = whiskerLeft L γ₂ ≫ α) : γ₁ = γ₂ :=
have := IsLeftDerivedFunctor.isRightKanExtension LF α W
LF.hom_ext_of_isRightKanExtension α γ₁ γ₂ hγ
/-- The natural transformation `LF' ⟶ LF` on left derived functors that is
induced by a natural transformation `F' ⟶ F`. -/
noncomputable def leftDerivedNatTrans (τ : F' ⟶ F) : LF' ⟶ LF :=
LF.leftDerivedLift α W LF' (α' ≫ τ)
@[reassoc (attr := simp)]
lemma leftDerivedNatTrans_fac (τ : F' ⟶ F) :
whiskerLeft L (leftDerivedNatTrans LF' LF α' α W τ) ≫ α = α' ≫ τ := by
dsimp only [leftDerivedNatTrans]
simp
@[reassoc (attr := simp)]
lemma leftDerivedNatTrans_app (τ : F' ⟶ F) (X : C) :
(leftDerivedNatTrans LF' LF α' α W τ).app (L.obj X) ≫ α.app X =
α'.app X ≫ τ.app X := by
dsimp only [leftDerivedNatTrans]
simp
@[simp]
lemma leftDerivedNatTrans_id :
leftDerivedNatTrans LF LF α α W (𝟙 F) = 𝟙 LF :=
leftDerived_ext LF α W _ _ _ (by simp)
variable [LF'.IsLeftDerivedFunctor α' W]
@[reassoc (attr := simp)]
lemma leftDerivedNatTrans_comp (τ' : F'' ⟶ F') (τ : F' ⟶ F) :
leftDerivedNatTrans LF'' LF' α'' α' W τ' ≫ leftDerivedNatTrans LF' LF α' α W τ =
leftDerivedNatTrans LF'' LF α'' α W (τ' ≫ τ) :=
leftDerived_ext LF α W _ _ _ (by simp)
/-- The natural isomorphism `LF' ≅ LF` on left derived functors that is
induced by a natural isomorphism `F' ≅ F`. -/
@[simps]
noncomputable def leftDerivedNatIso (τ : F' ≅ F) :
LF' ≅ LF where
hom := leftDerivedNatTrans LF' LF α' α W τ.hom
inv := leftDerivedNatTrans LF LF' α α' W τ.inv
/-- Uniqueness (up to a natural isomorphism) of the left derived functor. -/
noncomputable abbrev leftDerivedUnique [LF'.IsLeftDerivedFunctor α'₂ W] : LF ≅ LF' :=
leftDerivedNatIso LF LF' α α'₂ W (Iso.refl F)
lemma isLeftDerivedFunctor_iff_isIso_leftDerivedLift (G : D ⥤ H) (β : L ⋙ G ⟶ F) :
G.IsLeftDerivedFunctor β W ↔ IsIso (LF.leftDerivedLift α W G β) := by
rw [isLeftDerivedFunctor_iff_isRightKanExtension]
have := IsLeftDerivedFunctor.isRightKanExtension _ α W
exact isRightKanExtension_iff_isIso _ α _ (by simp)
end
variable (F)
/-- A functor `F : C ⥤ H` has a left derived functor with respect to
`W : MorphismProperty C` if it has a right Kan extension along
`W.Q : C ⥤ W.Localization` (or any localization functor `L : C ⥤ D`
for `W`, see `hasLeftDerivedFunctor_iff`). -/
class HasLeftDerivedFunctor : Prop where
hasRightKanExtension' : HasRightKanExtension W.Q F
variable (L)
variable [L.IsLocalization W]
lemma hasLeftDerivedFunctor_iff :
F.HasLeftDerivedFunctor W ↔ HasRightKanExtension L F := by
have : HasLeftDerivedFunctor F W ↔ HasRightKanExtension W.Q F :=
⟨fun h => h.hasRightKanExtension', fun h => ⟨h⟩⟩
rw [this, hasRightExtension_iff_postcomp₁ (Localization.compUniqFunctor W.Q L W) F]
variable {F}
include e in
lemma hasLeftDerivedFunctor_iff_of_iso :
HasLeftDerivedFunctor F W ↔ HasLeftDerivedFunctor F' W := by
rw [hasLeftDerivedFunctor_iff F W.Q W, hasLeftDerivedFunctor_iff F' W.Q W,
hasRightExtension_iff_of_iso₂ W.Q e]
variable (F)
lemma HasLeftDerivedFunctor.hasRightKanExtension [HasLeftDerivedFunctor F W] :
HasRightKanExtension L F := by
simpa only [← hasLeftDerivedFunctor_iff F L W]
variable {F L W}
lemma HasLeftDerivedFunctor.mk' [LF.IsLeftDerivedFunctor α W] :
HasLeftDerivedFunctor F W := by
have := IsLeftDerivedFunctor.isRightKanExtension LF α W
simpa only [hasLeftDerivedFunctor_iff F L W] using HasRightKanExtension.mk LF α
section
variable (F) [F.HasLeftDerivedFunctor W] (L W)
/-- Given a functor `F : C ⥤ H`, and a localization functor `L : D ⥤ H` for `W`,
this is the left derived functor `D ⥤ H` of `F`, i.e. the right Kan extension
of `F` along `L`. -/
noncomputable def totalLeftDerived : D ⥤ H :=
have := HasLeftDerivedFunctor.hasRightKanExtension F L W
rightKanExtension L F
/-- The canonical natural transformation `L ⋙ F.totalLeftDerived L W ⟶ F`. -/
noncomputable def totalLeftDerivedCounit : L ⋙ F.totalLeftDerived L W ⟶ F :=
have := HasLeftDerivedFunctor.hasRightKanExtension F L W
rightKanExtensionCounit L F
instance : (F.totalLeftDerived L W).IsLeftDerivedFunctor
(F.totalLeftDerivedCounit L W) W where
isRightKanExtension := by
dsimp [totalLeftDerived, totalLeftDerivedCounit]
infer_instance
end
end Functor
end CategoryTheory
|
Ideal.lean
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker, Aaron Anderson
-/
import Mathlib.RingTheory.Ideal.Operations
import Mathlib.RingTheory.UniqueFactorizationDomain.Defs
/-!
# Unique factorization and ascending chain condition on ideals
## Main results
* `Ideal.setOf_isPrincipal_wellFoundedOn_gt`, `WfDvdMonoid.of_setOf_isPrincipal_wellFoundedOn_gt`
in a domain, well-foundedness of the strict version of ∣ is equivalent to the ascending
chain condition on principal ideals.
-/
variable {α : Type*}
open UniqueFactorizationMonoid in
/-- Every non-zero prime ideal in a unique factorization domain contains a prime element. -/
theorem Ideal.IsPrime.exists_mem_prime_of_ne_bot {R : Type*} [CommSemiring R] [IsDomain R]
[UniqueFactorizationMonoid R] {I : Ideal R} (hI₂ : I.IsPrime) (hI : I ≠ ⊥) :
∃ x ∈ I, Prime x := by
classical
obtain ⟨a : R, ha₁ : a ∈ I, ha₂ : a ≠ 0⟩ := Submodule.exists_mem_ne_zero_of_ne_bot hI
replace ha₁ : (factors a).prod ∈ I := by
obtain ⟨u : Rˣ, hu : (factors a).prod * u = a⟩ := factors_prod ha₂
rwa [← hu, mul_unit_mem_iff_mem _ u.isUnit] at ha₁
obtain ⟨p : R, hp₁ : p ∈ factors a, hp₂ : p ∈ I⟩ :=
(hI₂.multiset_prod_mem_iff_exists_mem <| factors a).1 ha₁
exact ⟨p, hp₂, prime_of_factor p hp₁⟩
section Ideal
/-- The ascending chain condition on principal ideals holds in a `WfDvdMonoid` domain. -/
lemma Ideal.setOf_isPrincipal_wellFoundedOn_gt [CommSemiring α] [WfDvdMonoid α] [IsDomain α] :
{I : Ideal α | I.IsPrincipal}.WellFoundedOn (· > ·) := by
have : {I : Ideal α | I.IsPrincipal} = ((fun a ↦ Ideal.span {a}) '' Set.univ) := by
ext
simp [Submodule.isPrincipal_iff, eq_comm]
rw [this, Set.wellFoundedOn_image, Set.wellFoundedOn_univ]
convert wellFounded_dvdNotUnit (α := α)
ext
exact Ideal.span_singleton_lt_span_singleton
/-- The ascending chain condition on principal ideals in a domain is sufficient to prove that
the domain is `WfDvdMonoid`. -/
lemma WfDvdMonoid.of_setOf_isPrincipal_wellFoundedOn_gt [CommSemiring α] [IsDomain α]
(h : {I : Ideal α | I.IsPrincipal}.WellFoundedOn (· > ·)) :
WfDvdMonoid α := by
have : WellFounded (α := {I : Ideal α // I.IsPrincipal}) (· > ·) := h
constructor
convert InvImage.wf (fun a => ⟨Ideal.span ({a} : Set α), _, rfl⟩) this
ext
exact Ideal.span_singleton_lt_span_singleton.symm
end Ideal
|
Imo2001Q3.lean
|
/-
Copyright (c) 2025 Jeremy Tan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Tan
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise
import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Fintype.Prod
import Mathlib.Tactic.NormNum.Ineq
/-!
# IMO 2001 Q3
Twenty-one girls and twenty-one boys took part in a mathematical competition. It turned out that
1. each contestant solved at most six problems, and
2. for each pair of a girl and a boy, there was at least one problem that was solved by
both the girl and the boy.
Show that there is a problem that was solved by at least three girls and at least three boys.
# Solution
Note that not all of the problems a girl $g$ solves can be "hard" for boys, in the sense that
at most two boys solved it. If that was true, by condition 1 at most $6 × 2 = 12$ boys solved
some problem $g$, but by condition 2 that property holds for all 21 boys, which is a
contradiction.
Hence there are at most 5 problems $g$ solved that are hard for boys, and the number of girl-boy
pairs who solved some problem in common that was hard for boys is at most $5 × 2 × 21 = 210$.
By the same reasoning this bound holds when "girls" and "boys" are swapped throughout, but there
are $21^2$ girl-boy pairs in all and $21^2 > 210 + 210$, so some girl-boy pairs solved only problems
in common that were not hard for girls or boys. By condition 2 the result follows.
-/
namespace Imo2001Q3
open Finset
/-- The conditions on the problems the girls and boys solved, represented as functions from `Fin 21`
(index in cohort) to the finset of problems they solved (numbered arbitrarily). -/
structure Condition (G B : Fin 21 → Finset ℕ) where
/-- Every girl solved at most six problems. -/
G_le_6 (i) : #(G i) ≤ 6
/-- Every boy solved at most six problems. -/
B_le_6 (j) : #(B j) ≤ 6
/-- Every girl-boy pair solved at least one problem in common. -/
G_inter_B (i j) : ¬Disjoint (G i) (B j)
/-- A problem is easy for a cohort (boys or girls) if at least three of its members solved it. -/
def Easy (F : Fin 21 → Finset ℕ) (p : ℕ) : Prop := 3 ≤ #{i | p ∈ F i}
variable {G B : Fin 21 → Finset ℕ}
open Classical in
/-- Every contestant solved at most five problems that were not easy for the other cohort. -/
lemma card_not_easy_le_five {i : Fin 21} (hG : #(G i) ≤ 6) (hB : ∀ j, ¬Disjoint (G i) (B j)) :
#{p ∈ G i | ¬Easy B p} ≤ 5 := by
by_contra! h
replace h := le_antisymm (card_filter_le ..) (hG.trans h)
simp_rw [card_filter_eq_iff, Easy, not_le] at h
suffices 21 ≤ 12 by norm_num at this
calc
_ = #{j | ¬Disjoint (G i) (B j)} := by simp [filter_true_of_mem fun j _ ↦ hB j]
_ = #((G i).biUnion fun p ↦ {j | p ∈ B j}) := by congr 1; ext j; simp [not_disjoint_iff]
_ ≤ ∑ p ∈ G i, #{j | p ∈ B j} := card_biUnion_le
_ ≤ ∑ p ∈ G i, 2 := sum_le_sum fun p mp ↦ Nat.le_of_lt_succ (h p mp)
_ ≤ _ := by rw [sum_const, smul_eq_mul]; omega
open Classical in
/-- There are at most 210 girl-boy pairs who solved some problem in common that was not easy for
a fixed cohort. -/
lemma card_not_easy_le_210 (hG : ∀ i, #(G i) ≤ 6) (hB : ∀ i j, ¬Disjoint (G i) (B j)) :
#{ij : Fin 21 × Fin 21 | ∃ p, ¬Easy B p ∧ p ∈ G ij.1 ∩ B ij.2} ≤ 210 :=
calc
_ = ∑ i, #{j | ∃ p, ¬Easy B p ∧ p ∈ G i ∩ B j} := by
simp_rw [card_filter, ← univ_product_univ, sum_product]
_ = ∑ i, #({p ∈ G i | ¬Easy B p}.biUnion fun p ↦ {j | p ∈ B j}) := by
congr!; ext
simp_rw [mem_biUnion, mem_inter, mem_filter]
congr! 2; tauto
_ ≤ ∑ i, ∑ p ∈ G i with ¬Easy B p, #{j | p ∈ B j} := sum_le_sum fun _ _ ↦ card_biUnion_le
_ ≤ ∑ i, ∑ p ∈ G i with ¬Easy B p, 2 := by
gcongr with i _ p mp
rw [mem_filter, Easy, not_le] at mp
exact Nat.le_of_lt_succ mp.2
_ ≤ ∑ i : Fin 21, 5 * 2 := by
gcongr with i
rw [sum_const, smul_eq_mul]
exact mul_le_mul_right' (card_not_easy_le_five (hG _) (hB _)) _
_ = _ := by norm_num
theorem result (h : Condition G B) : ∃ p, Easy G p ∧ Easy B p := by
obtain ⟨G_le_6, B_le_6, G_inter_B⟩ := h
have B_inter_G : ∀ i j, ¬Disjoint (B i) (G j) := fun i j ↦ by
rw [disjoint_comm]; exact G_inter_B j i
have cB := card_not_easy_le_210 G_le_6 G_inter_B
have cG := card_not_easy_le_210 B_le_6 B_inter_G
rw [← card_map ⟨_, Prod.swap_injective⟩] at cG
have key := (card_union_le _ _).trans (add_le_add cB cG) |>.trans_lt
(show _ < #(@univ (Fin 21 × Fin 21) _) by simp)
obtain ⟨⟨i, j⟩, -, hij⟩ := exists_mem_notMem_of_card_lt_card key
simp_rw [mem_union, mem_map, mem_filter_univ, Function.Embedding.coeFn_mk, Prod.exists,
Prod.swap_prod_mk, Prod.mk.injEq, existsAndEq, true_and, and_true, not_or, not_exists,
not_and', not_not, mem_inter, and_imp] at hij
obtain ⟨p, pG, pB⟩ := not_disjoint_iff.mp (G_inter_B i j)
use p, hij.2 _ pB pG, hij.1 _ pG pB
end Imo2001Q3
|
Deriv.lean
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov, David Loeffler
-/
import Mathlib.Analysis.Convex.Slope
import Mathlib.Analysis.Calculus.Deriv.MeanValue
/-!
# Convexity of functions and derivatives
Here we relate convexity of functions `ℝ → ℝ` to properties of their derivatives.
## Main results
* `MonotoneOn.convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function
is increasing or its second derivative is nonnegative, then the original function is convex.
* `ConvexOn.monotoneOn_deriv`: if a function is convex and differentiable, then its derivative is
monotone.
-/
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Topology NNReal
/-!
## Monotonicity of `f'` implies convexity of `f`
-/
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem MonotoneOn.convexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D))
(hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn ℝ D f :=
convexOn_of_slope_mono_adjacent hD
(by
intro x y z hx hz hxy hyz
-- First we prove some trivial inclusions
have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz
have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩
have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD')
obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b = (f z - f y) / (z - y) :=
exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD')
rw [← ha, ← hb]
exact hf'_mono (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb).le)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior,
and `f'` is antitone on the interior, then `f` is concave on `D`. -/
theorem AntitoneOn.concaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D))
(h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn ℝ D f :=
haveI : MonotoneOn (deriv (-f)) (interior D) := by
simpa only [← deriv.neg] using h_anti.neg
neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg)
theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) :
∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by
have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hay with ⟨b, ⟨hab, hby⟩⟩
refine ⟨b, ⟨hxa.trans hab, hby⟩, ?_⟩
rw [← ha]
exact hf'_mono ⟨hxa, hay⟩ ⟨hxa.trans hab, hby⟩ hab
theorem StrictMonoOn.exists_slope_lt_deriv {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by
by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0
· apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h
· push_neg at h
rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩
obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, (f w - f x) / (w - x) < deriv f a := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _
· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
· intro z hz
rw [← hw]
apply ne_of_lt
exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2
obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, (f y - f w) / (y - w) < deriv f b := by
apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _
· refine hf.mono (Icc_subset_Icc hxw.le le_rfl)
· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
· intro z hz
rw [← hw]
apply ne_of_gt
exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1
refine ⟨b, ⟨hxw.trans hwb, hby⟩, ?_⟩
simp only [div_lt_iff₀, hxy, hxw, hwy, sub_pos] at ha hb ⊢
have : deriv f a * (w - x) < deriv f b * (w - x) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _
· exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb)
· rw [← hw]
exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le
linarith
theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) :
∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by
have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem =>
(differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) :=
exists_deriv_eq_slope f hxy hf A
rcases nonempty_Ioo.2 hxa with ⟨b, ⟨hxb, hba⟩⟩
refine ⟨b, ⟨hxb, hba.trans hay⟩, ?_⟩
rw [← ha]
exact hf'_mono ⟨hxb, hba.trans hay⟩ ⟨hxa, hay⟩ hba
theorem StrictMonoOn.exists_deriv_lt_slope {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y))
(hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) :
∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by
by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0
· apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h
· push_neg at h
rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩
obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, deriv f a < (f w - f x) / (w - x) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _
· exact hf.mono (Icc_subset_Icc le_rfl hwy.le)
· exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le)
· intro z hz
rw [← hw]
apply ne_of_lt
exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2
obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, deriv f b < (f y - f w) / (y - w) := by
apply StrictMonoOn.exists_deriv_lt_slope_aux _ hwy _ _
· refine hf.mono (Icc_subset_Icc hxw.le le_rfl)
· exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl)
· intro z hz
rw [← hw]
apply ne_of_gt
exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1
refine ⟨a, ⟨hxa, haw.trans hwy⟩, ?_⟩
simp only [lt_div_iff₀, hxy, hxw, hwy, sub_pos] at ha hb ⊢
have : deriv f a * (y - w) < deriv f b * (y - w) := by
apply mul_lt_mul _ le_rfl (sub_pos.2 hwy) _
· exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb)
· rw [← hw]
exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le
linarith
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, and `f'` is strictly monotone on the
interior, then `f` is strictly convex on `D`.
Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict monotonicity of `f'`. -/
theorem StrictMonoOn.strictConvexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : StrictMonoOn (deriv f) (interior D)) : StrictConvexOn ℝ D f :=
strictConvexOn_of_slope_strict_mono_adjacent hD fun {x y z} hx hz hxy hyz => by
-- First we prove some trivial inclusions
have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz
have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD
have hxyD' : Ioo x y ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩
have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD
have hyzD' : Ioo y z ⊆ interior D :=
subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩
-- Then we get points `a` and `b` in each interval `[x, y]` and `[y, z]` where the derivatives
-- can be compared to the slopes between `x, y` and `y, z` respectively.
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a :=
StrictMonoOn.exists_slope_lt_deriv (hf.mono hxyD) hxy (hf'.mono hxyD')
obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b < (f z - f y) / (z - y) :=
StrictMonoOn.exists_deriv_lt_slope (hf.mono hyzD) hyz (hf'.mono hyzD')
apply ha.trans (lt_trans _ hb)
exact hf' (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f'` is strictly antitone on the
interior, then `f` is strictly concave on `D`.
Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict antitonicity of `f'`. -/
theorem StrictAntiOn.strictConcaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (h_anti : StrictAntiOn (deriv f) (interior D)) :
StrictConcaveOn ℝ D f :=
have : StrictMonoOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg
neg_neg f ▸ (this.strictConvexOn_of_deriv hD hf.neg).neg
/-- If a function `f` is differentiable and `f'` is monotone on `ℝ` then `f` is convex. -/
theorem Monotone.convexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f)
(hf'_mono : Monotone (deriv f)) : ConvexOn ℝ univ f :=
(hf'_mono.monotoneOn _).convexOn_of_deriv convex_univ hf.continuous.continuousOn
hf.differentiableOn
/-- If a function `f` is differentiable and `f'` is antitone on `ℝ` then `f` is concave. -/
theorem Antitone.concaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f)
(hf'_anti : Antitone (deriv f)) : ConcaveOn ℝ univ f :=
(hf'_anti.antitoneOn _).concaveOn_of_deriv convex_univ hf.continuous.continuousOn
hf.differentiableOn
/-- If a function `f` is continuous and `f'` is strictly monotone on `ℝ` then `f` is strictly
convex. Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict monotonicity of `f'`. -/
theorem StrictMono.strictConvexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f)
(hf'_mono : StrictMono (deriv f)) : StrictConvexOn ℝ univ f :=
(hf'_mono.strictMonoOn _).strictConvexOn_of_deriv convex_univ hf.continuousOn
/-- If a function `f` is continuous and `f'` is strictly antitone on `ℝ` then `f` is strictly
concave. Note that we don't require differentiability, since it is guaranteed at all but at most
one point by the strict antitonicity of `f'`. -/
theorem StrictAnti.strictConcaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f)
(hf'_anti : StrictAnti (deriv f)) : StrictConcaveOn ℝ univ f :=
(hf'_anti.strictAntiOn _).strictConcaveOn_of_deriv convex_univ hf.continuousOn
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/
theorem convexOn_of_deriv2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D)
(hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D))
(hf''_nonneg : ∀ x ∈ interior D, 0 ≤ deriv^[2] f x) : ConvexOn ℝ D f :=
(monotoneOn_of_deriv_nonneg hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by
rwa [interior_interior]).convexOn_of_deriv
hD hf hf'
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/
theorem concaveOn_of_deriv2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D)
(hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D))
(hf''_nonpos : ∀ x ∈ interior D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f :=
(antitoneOn_of_deriv_nonpos hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by
rwa [interior_interior]).concaveOn_of_deriv
hD hf hf'
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/
lemma convexOn_of_hasDerivWithinAt2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x)
(hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x)
(hf''₀ : ∀ x ∈ interior D, 0 ≤ f'' x) : ConvexOn ℝ D f := by
have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf'
refine convexOn_of_deriv2_nonneg hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_
· rw [differentiableOn_congr this]
exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt
· rintro x hx
convert hf''₀ _ hx using 1
dsimp
rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx]
exact (hf'' _ hy).congr this <| by rw [this hy]
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its
interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/
lemma concaveOn_of_hasDerivWithinAt2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ}
(hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x)
(hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x)
(hf''₀ : ∀ x ∈ interior D, f'' x ≤ 0) : ConcaveOn ℝ D f := by
have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf'
refine concaveOn_of_deriv2_nonpos hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_
· rw [differentiableOn_congr this]
exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt
· rintro x hx
convert hf''₀ _ hx using 1
dsimp
rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx]
exact (hf'' _ hy).congr this <| by rw [this hy]
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on the
interior, then `f` is strictly convex on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
theorem strictConvexOn_of_deriv2_pos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, 0 < (deriv^[2] f) x) :
StrictConvexOn ℝ D f :=
((strictMonoOn_of_deriv_pos hD.interior fun z hz =>
(differentiableAt_of_deriv_ne_zero
(hf'' z hz).ne').differentiableWithinAt.continuousWithinAt) <|
by rwa [interior_interior]).strictConvexOn_of_deriv
hD hf
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on the
interior, then `f` is strictly concave on `D`.
Note that we don't require twice differentiability explicitly as it already implied by the second
derivative being strictly negative, except at at most one point. -/
theorem strictConcaveOn_of_deriv2_neg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, deriv^[2] f x < 0) :
StrictConcaveOn ℝ D f :=
((strictAntiOn_of_deriv_neg hD.interior fun z hz =>
(differentiableAt_of_deriv_ne_zero
(hf'' z hz).ne).differentiableWithinAt.continuousWithinAt) <|
by rwa [interior_interior]).strictConcaveOn_of_deriv
hD hf
/-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and
`f''` is nonnegative on `D`, then `f` is convex on `D`. -/
theorem convexOn_of_deriv2_nonneg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D)
(hf''_nonneg : ∀ x ∈ D, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ D f :=
convexOn_of_deriv2_nonneg hD hf'.continuousOn (hf'.mono interior_subset)
(hf''.mono interior_subset) fun x hx => hf''_nonneg x (interior_subset hx)
/-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and
`f''` is nonpositive on `D`, then `f` is concave on `D`. -/
theorem concaveOn_of_deriv2_nonpos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D)
(hf''_nonpos : ∀ x ∈ D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f :=
concaveOn_of_deriv2_nonpos hD hf'.continuousOn (hf'.mono interior_subset)
(hf''.mono interior_subset) fun x hx => hf''_nonpos x (interior_subset hx)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on `D`,
then `f` is strictly convex on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
theorem strictConvexOn_of_deriv2_pos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f :=
strictConvexOn_of_deriv2_pos hD hf fun x hx => hf'' x (interior_subset hx)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on `D`,
then `f` is strictly concave on `D`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly negative, except at at most one point. -/
theorem strictConcaveOn_of_deriv2_neg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ}
(hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f :=
strictConcaveOn_of_deriv2_neg hD hf fun x hx => hf'' x (interior_subset hx)
/-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonnegative on `ℝ`,
then `f` is convex on `ℝ`. -/
theorem convexOn_univ_of_deriv2_nonneg {f : ℝ → ℝ} (hf' : Differentiable ℝ f)
(hf'' : Differentiable ℝ (deriv f)) (hf''_nonneg : ∀ x, 0 ≤ (deriv^[2] f) x) :
ConvexOn ℝ univ f :=
convexOn_of_deriv2_nonneg' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ =>
hf''_nonneg x
/-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonpositive on `ℝ`,
then `f` is concave on `ℝ`. -/
theorem concaveOn_univ_of_deriv2_nonpos {f : ℝ → ℝ} (hf' : Differentiable ℝ f)
(hf'' : Differentiable ℝ (deriv f)) (hf''_nonpos : ∀ x, deriv^[2] f x ≤ 0) :
ConcaveOn ℝ univ f :=
concaveOn_of_deriv2_nonpos' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ =>
hf''_nonpos x
/-- If a function `f` is continuous on `ℝ`, and `f''` is strictly positive on `ℝ`,
then `f` is strictly convex on `ℝ`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly positive, except at at most one point. -/
theorem strictConvexOn_univ_of_deriv2_pos {f : ℝ → ℝ} (hf : Continuous f)
(hf'' : ∀ x, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ univ f :=
strictConvexOn_of_deriv2_pos' convex_univ hf.continuousOn fun x _ => hf'' x
/-- If a function `f` is continuous on `ℝ`, and `f''` is strictly negative on `ℝ`,
then `f` is strictly concave on `ℝ`.
Note that we don't require twice differentiability explicitly as it is already implied by the second
derivative being strictly negative, except at at most one point. -/
theorem strictConcaveOn_univ_of_deriv2_neg {f : ℝ → ℝ} (hf : Continuous f)
(hf'' : ∀ x, deriv^[2] f x < 0) : StrictConcaveOn ℝ univ f :=
strictConcaveOn_of_deriv2_neg' convex_univ hf.continuousOn fun x _ => hf'' x
/-!
## Convexity of `f` implies monotonicity of `f'`
In this section we prove inequalities relating derivatives of convex functions to slopes of secant
lines, and deduce that if `f` is convex then its derivative is monotone (and similarly for strict
convexity / strict monotonicity).
-/
section slope
variable {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
{s : Set 𝕜} {f : 𝕜 → 𝕜} {x : 𝕜}
/-- If `f : 𝕜 → 𝕜` is convex on `s`, then for any point `x ∈ s` the slope of the secant line of `f`
through `x` is monotone on `s \ {x}`. -/
lemma ConvexOn.slope_mono (hfc : ConvexOn 𝕜 s f) (hx : x ∈ s) : MonotoneOn (slope f x) (s \ {x}) :=
(slope_fun_def_field f _).symm ▸ fun _ hy _ hz hz' ↦ hfc.secant_mono hx (mem_of_mem_diff hy)
(mem_of_mem_diff hz) (notMem_of_mem_diff hy :) (notMem_of_mem_diff hz :) hz'
lemma ConvexOn.monotoneOn_slope_gt (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ s) :
MonotoneOn (slope f x) {y ∈ s | x < y} :=
(hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩
lemma ConvexOn.monotoneOn_slope_lt (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ s) :
MonotoneOn (slope f x) {y ∈ s | y < x} :=
(hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩
/-- If `f : 𝕜 → 𝕜` is concave on `s`, then for any point `x ∈ s` the slope of the secant line of `f`
through `x` is antitone on `s \ {x}`. -/
lemma ConcaveOn.slope_anti (hfc : ConcaveOn 𝕜 s f) (hx : x ∈ s) :
AntitoneOn (slope f x) (s \ {x}) := by
rw [← neg_neg f, slope_neg_fun]
exact (ConvexOn.slope_mono hfc.neg hx).neg
lemma ConcaveOn.antitoneOn_slope_gt (hfc : ConcaveOn 𝕜 s f) (hxs : x ∈ s) :
AntitoneOn (slope f x) {y ∈ s | x < y} :=
(hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩
lemma ConcaveOn.antitoneOn_slope_lt (hfc : ConcaveOn 𝕜 s f) (hxs : x ∈ s) :
AntitoneOn (slope f x) {y ∈ s | y < x} :=
(hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩
variable [TopologicalSpace 𝕜] [OrderTopology 𝕜]
lemma bddBelow_slope_lt_of_mem_interior (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ interior s) :
BddBelow (slope f x '' {y ∈ s | x < y}) := by
obtain ⟨y, hyx, hys⟩ : ∃ y, y < x ∧ y ∈ s :=
Eventually.exists_lt (mem_interior_iff_mem_nhds.mp hxs)
refine bddBelow_iff_subset_Ici.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩
simp_rw [mem_Ici, ← hz']
refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hyx.trans hz.2).le
· simp [hys, hyx.ne]
· simp [hz.2.ne', hz.1]
lemma bddAbove_slope_gt_of_mem_interior (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ interior s) :
BddAbove (slope f x '' {y ∈ s | y < x}) := by
obtain ⟨y, hyx, hys⟩ : ∃ y, x < y ∧ y ∈ s :=
Eventually.exists_gt (mem_interior_iff_mem_nhds.mp hxs)
refine bddAbove_iff_subset_Iic.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩
simp_rw [mem_Iic, ← hz']
refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hz.2.trans hyx).le
· simp [hz.2.ne, hz.1]
· simp [hys, hyx.ne']
end slope
namespace ConvexOn
variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ}
section Interior
/-!
### Left and right derivative of a convex function in the interior of the set
-/
lemma hasDerivWithinAt_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (sInf (slope f x '' {y ∈ S | x < y})) (Ioi x) x := by
have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
simp_rw [hasDerivWithinAt_iff_tendsto_slope]
simp only [mem_Ioi, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self]
have h : Ioo x b ⊆ {y | y ∈ S ∧ x < y} := fun z hz ↦ ⟨habs ⟨hxab.1.trans hz.1, hz.2⟩, hz.1⟩
have h_Ioo : Tendsto (slope f x) (𝓝[>] x) (𝓝 (sInf (slope f x '' Ioo x b))) :=
((monotoneOn_slope_gt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_right
(by simpa using hxab.2) ((bddBelow_slope_lt_of_mem_interior hfc hxs).mono (image_mono h))
suffices sInf (slope f x '' Ioo x b) = sInf (slope f x '' {y ∈ S | x < y}) by rwa [← this]
apply (monotoneOn_slope_gt hfc (habs hxab)).csInf_eq_of_subset_of_forall_exists_le
(bddBelow_slope_lt_of_mem_interior hfc hxs) h ?_
rintro y ⟨hyS, hxy⟩
obtain ⟨z, hxz, hzy⟩ := exists_between (lt_min hxab.2 hxy)
exact ⟨z, ⟨hxz, hzy.trans_le (min_le_left _ _)⟩, hzy.le.trans (min_le_right _ _)⟩
lemma hasDerivWithinAt_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (sSup (slope f x '' {y ∈ S | y < x})) (Iio x) x := by
have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
simp_rw [hasDerivWithinAt_iff_tendsto_slope]
simp only [mem_Iio, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self]
have h : Ioo a x ⊆ {y | y ∈ S ∧ y < x} := fun z hz ↦ ⟨habs ⟨hz.1, hz.2.trans hxab.2⟩, hz.2⟩
have h_Ioo : Tendsto (slope f x) (𝓝[<] x) (𝓝 (sSup (slope f x '' Ioo a x))) :=
((monotoneOn_slope_lt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_left
(by simpa using hxab.1) ((bddAbove_slope_gt_of_mem_interior hfc hxs).mono (image_mono h))
suffices sSup (slope f x '' Ioo a x) = sSup (slope f x '' {y ∈ S | y < x}) by rwa [← this]
apply (monotoneOn_slope_lt hfc (habs hxab)).csSup_eq_of_subset_of_forall_exists_le
(bddAbove_slope_gt_of_mem_interior hfc hxs) h ?_
rintro y ⟨hyS, hyx⟩
obtain ⟨z, hyz, hzx⟩ := exists_between (max_lt hxab.1 hyx)
exact ⟨z, ⟨(le_max_left _ _).trans_lt hyz, hzx⟩, (le_max_right _ _).trans hyz.le⟩
lemma differentiableWithinAt_Ioi_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
DifferentiableWithinAt ℝ f (Ioi x) x :=
(hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).differentiableWithinAt
lemma differentiableWithinAt_Iio_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
DifferentiableWithinAt ℝ f (Iio x) x :=
(hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).differentiableWithinAt
lemma hasDerivWithinAt_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (derivWithin f (Ioi x) x) (Ioi x) x :=
(hfc.differentiableWithinAt_Ioi_of_mem_interior hxs).hasDerivWithinAt
lemma hasDerivWithinAt_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
HasDerivWithinAt f (derivWithin f (Iio x) x) (Iio x) x :=
(hfc.differentiableWithinAt_Iio_of_mem_interior hxs).hasDerivWithinAt
lemma rightDeriv_eq_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
derivWithin f (Ioi x) x = sInf (slope f x '' {y | y ∈ S ∧ x < y}) :=
(hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Ioi x)
lemma leftDeriv_eq_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
derivWithin f (Iio x) x = sSup (slope f x '' {y | y ∈ S ∧ y < x}) :=
(hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Iio x)
lemma monotoneOn_rightDeriv (hfc : ConvexOn ℝ S f) :
MonotoneOn (fun x ↦ derivWithin f (Ioi x) x) (interior S) := by
intro x hxs y hys hxy
rcases eq_or_lt_of_le hxy with rfl | hxy; · rfl
simp_rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs,
hfc.rightDeriv_eq_sInf_slope_of_mem_interior hys]
refine csInf_le_of_le (b := slope f x y) (bddBelow_slope_lt_of_mem_interior hfc hxs)
⟨y, by simp only [mem_setOf_eq, hxy, and_true]; exact interior_subset hys⟩
(le_csInf ?_ ?_)
· have hys' := hys
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hys'
obtain ⟨a, b, hxab, habs⟩ := hys'
rw [image_nonempty]
obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2
exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩
· rintro _ ⟨z, ⟨hzs, hyz : y < z⟩, rfl⟩
rw [slope_comm]
exact slope_mono hfc (interior_subset hys) ⟨interior_subset hxs, hxy.ne⟩ ⟨hzs, hyz.ne'⟩
(hxy.trans hyz).le
lemma monotoneOn_leftDeriv (hfc : ConvexOn ℝ S f) :
MonotoneOn (fun x ↦ derivWithin f (Iio x) x) (interior S) := by
intro x hxs y hys hxy
rcases eq_or_lt_of_le hxy with rfl | hxy; · rfl
simp_rw [hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs,
hfc.leftDeriv_eq_sSup_slope_of_mem_interior hys]
refine le_csSup_of_le (b := slope f x y) (bddAbove_slope_gt_of_mem_interior hfc hys)
⟨x, by simp only [slope_comm, mem_setOf_eq, hxy, and_true]; exact interior_subset hxs⟩
(csSup_le ?_ ?_)
· have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
rw [image_nonempty]
obtain ⟨z, hxz, hzb⟩ := exists_between hxab.1
exact ⟨z, habs ⟨hxz, hzb.trans hxab.2⟩, hzb⟩
· rintro _ ⟨z, ⟨hzs, hyz : z < x⟩, rfl⟩
exact slope_mono hfc (interior_subset hxs) ⟨hzs, hyz.ne⟩ ⟨interior_subset hys, hxy.ne'⟩
(hyz.trans hxy).le
lemma leftDeriv_le_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) :
derivWithin f (Iio x) x ≤ derivWithin f (Ioi x) x := by
have hxs' := hxs
rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs'
obtain ⟨a, b, hxab, habs⟩ := hxs'
rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs,
hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs]
refine csSup_le ?_ ?_
· rw [image_nonempty]
obtain ⟨z, haz, hzx⟩ := exists_between hxab.1
exact ⟨z, habs ⟨haz, hzx.trans hxab.2⟩, hzx⟩
rintro _ ⟨z, ⟨hzs, hzx⟩, rfl⟩
refine le_csInf ?_ ?_
· rw [image_nonempty]
obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2
exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩
rintro _ ⟨y, ⟨hys, hxy⟩, rfl⟩
exact slope_mono hfc (interior_subset hxs) ⟨hzs, hzx.ne⟩ ⟨hys, hxy.ne'⟩ (hzx.trans hxy).le
end Interior
section left
/-!
### Convex functions, derivative at left endpoint of secant
-/
/-- If `f : ℝ → ℝ` is convex on `S` and right-differentiable at `x ∈ S`, then the slope of any
secant line with left endpoint at `x` is bounded below by the right derivative of `f` at `x`. -/
lemma le_slope_of_hasDerivWithinAt_Ioi (hfc : ConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) :
f' ≤ slope f x y := by
apply le_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' notMem_Ioi_self).mp hf'
simp_rw [eventually_nhdsWithin_iff, slope_def_field]
filter_upwards [eventually_lt_nhds hxy] with t ht (ht' : x < t)
refine hfc.secant_mono hx (?_ : t ∈ S) hy ht'.ne' hxy.ne' ht.le
exact hfc.1.ordConnected.out hx hy ⟨ht'.le, ht.le⟩
/-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` using `derivWithin`. -/
lemma rightDeriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Ioi x) x) :
derivWithin f (Ioi x) x ≤ slope f x y :=
le_slope_of_hasDerivWithinAt_Ioi hfc hx hy hxy hfd.hasDerivWithinAt
lemma rightDeriv_le_slope_of_mem_interior (hfc : ConvexOn ℝ S f)
{y : ℝ} (hxs : x ∈ interior S) (hys : y ∈ S) (hxy : x < y) :
derivWithin f (Ioi x) x ≤ slope f x y :=
rightDeriv_le_slope hfc (interior_subset hxs) hys hxy
(differentiableWithinAt_Ioi_of_mem_interior hfc hxs)
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `x`, then the slope of any
secant line with left endpoint at `x` is bounded below by the derivative of `f` within `S` at `x`.
This is fractionally weaker than `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` but simpler to apply
under a `DifferentiableOn S` hypothesis. -/
lemma le_slope_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivWithinAt f f' S x) :
f' ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy <|
hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy
/-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt` using `derivWithin`. -/
lemma derivWithin_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S x) :
derivWithin f S x ≤ slope f x y :=
le_slope_of_hasDerivWithinAt hfc hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `x ∈ S`, then the slope of any secant
line with left endpoint at `x` is bounded below by the derivative of `f` at `x`. -/
lemma le_slope_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(ha : HasDerivAt f f' x) :
f' ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy ha.hasDerivWithinAt
/-- Reformulation of `ConvexOn.le_slope_of_hasDerivAt` using `deriv` -/
lemma deriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f x) :
deriv f x ≤ slope f x y :=
le_slope_of_hasDerivAt hfc hx hy hxy hfd.hasDerivAt
end left
section right
/-!
### Convex functions, derivative at right endpoint of secant
-/
/-- If `f : ℝ → ℝ` is convex on `S` and left-differentiable at `y ∈ S`, then the slope of any secant
line with right endpoint at `y` is bounded above by the left derivative of `f` at `y`. -/
lemma slope_le_of_hasDerivWithinAt_Iio (hfc : ConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) :
slope f x y ≤ f' := by
apply ge_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' notMem_Iio_self).mp hf'
simp_rw [eventually_nhdsWithin_iff, slope_comm f x y, slope_def_field]
filter_upwards [eventually_gt_nhds hxy] with t ht (ht' : t < y)
refine hfc.secant_mono hy hx (?_ : t ∈ S) hxy.ne ht'.ne ht.le
exact hfc.1.ordConnected.out hx hy ⟨ht.le, ht'.le⟩
/-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` using `derivWithin`. -/
lemma slope_le_leftDeriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Iio y) y) :
slope f x y ≤ derivWithin f (Iio y) y :=
hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt
lemma slope_le_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f)
(hys : x ∈ S) (hxs : y ∈ interior S) (hxy : x < y) :
slope f x y ≤ derivWithin f (Iio y) y :=
slope_le_leftDeriv hfc hys (interior_subset hxs) hxy
(differentiableWithinAt_Iio_of_mem_interior hfc hxs)
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `y`, then the slope of any
secant line with right endpoint at `y` is bounded above by the derivative of `f` within `S` at `y`.
This is fractionally weaker than `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` but simpler to apply
under a `DifferentiableOn S` hypothesis. -/
lemma slope_le_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivWithinAt f f' S y) :
slope f x y ≤ f' :=
hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy <|
hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy
/-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt` using `derivWithin`. -/
lemma slope_le_derivWithin (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S y) :
slope f x y ≤ derivWithin f S y :=
hfc.slope_le_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `y ∈ S`, then the slope of any secant
line with right endpoint at `y` is bounded above by the derivative of `f` at `y`. -/
lemma slope_le_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivAt f f' y) :
slope f x y ≤ f' :=
hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt
/-- Reformulation of `ConvexOn.slope_le_of_hasDerivAt` using `deriv`. -/
lemma slope_le_deriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f y) :
slope f x y ≤ deriv f y :=
hfc.slope_le_of_hasDerivAt hx hy hxy hfd.hasDerivAt
end right
/-!
### Convex functions, monotonicity of derivative
-/
/-- If `f` is convex on `S` and differentiable on `S`, then its derivative within `S` is monotone
on `S`. -/
lemma monotoneOn_derivWithin (hfc : ConvexOn ℝ S f) (hfd : DifferentiableOn ℝ f S) :
MonotoneOn (derivWithin f S) S := by
intro x hx y hy hxy
rcases eq_or_lt_of_le hxy with rfl | hxy'
· rfl
exact (hfc.derivWithin_le_slope hx hy hxy' (hfd x hx)).trans
(hfc.slope_le_derivWithin hx hy hxy' (hfd y hy))
/-- If `f` is convex on `S` and differentiable at all points of `S`, then its derivative is monotone
on `S`. -/
theorem monotoneOn_deriv (hfc : ConvexOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) :
MonotoneOn (deriv f) S := by
intro x hx y hy hxy
rcases eq_or_lt_of_le hxy with rfl | hxy'
· rfl
exact (hfc.deriv_le_slope hx hy hxy' (hfd x hx)).trans (hfc.slope_le_deriv hx hy hxy' (hfd y hy))
lemma isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg (hf : ConvexOn ℝ S f) (hx : x ∈ interior S)
(hf_ld : derivWithin f (Iio x) x ≤ 0) (hf_rd : 0 ≤ derivWithin f (Ioi x) x) :
IsMinOn f S x := by
intro y hy
rcases lt_trichotomy x y with hxy | h_eq | hyx
· suffices 0 ≤ slope f x y by
simp only [slope_def_field, div_nonneg_iff, sub_nonneg, tsub_le_iff_right, zero_add,
not_le.mpr hxy, and_false, or_false] at this
exact this.1
exact hf_rd.trans <| rightDeriv_le_slope_of_mem_interior hf hx hy hxy
· simp [h_eq]
· suffices slope f x y ≤ 0 by
simp only [slope_def_field, div_nonpos_iff, sub_nonneg, tsub_le_iff_right, zero_add,
not_le.mpr hyx, and_false, or_false] at this
exact this.1
rw [slope_comm]
exact (slope_le_leftDeriv_of_mem_interior hf hy hx hyx).trans hf_ld
lemma isMinOn_of_rightDeriv_eq_zero (hf : ConvexOn ℝ S f) (hx : x ∈ interior S)
(hf_rd : derivWithin f (Ioi x) x = 0) :
IsMinOn f S x := by
refine hf.isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg hx ?_ hf_rd.symm.le
exact (hf.leftDeriv_le_rightDeriv_of_mem_interior hx).trans_eq hf_rd
lemma isMinOn_of_leftDeriv_eq_zero (hf : ConvexOn ℝ S f) (hx : x ∈ interior S)
(hf_ld : derivWithin f (Iio x) x = 0) :
IsMinOn f S x := by
refine hf.isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg hx hf_ld.le ?_
exact hf_ld.symm.le.trans (hf.leftDeriv_le_rightDeriv_of_mem_interior hx)
end ConvexOn
namespace StrictConvexOn
variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ}
section left
/-!
### Strict convex functions, derivative at left endpoint of secant
-/
/-- If `f : ℝ → ℝ` is strictly convex on `S` and right-differentiable at `x ∈ S`, then the slope of
any secant line with left endpoint at `x` is strictly greater than the right derivative of `f` at
`x`. -/
lemma lt_slope_of_hasDerivWithinAt_Ioi (hfc : StrictConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) :
f' < slope f x y := by
obtain ⟨u, hxu, huy⟩ := exists_between hxy
have hu : u ∈ S := hfc.1.ordConnected.out hx hy ⟨hxu.le, huy.le⟩
have := hfc.secant_strict_mono hx hu hy hxu.ne' hxy.ne' huy
simp only [← slope_def_field] at this
exact (hfc.convexOn.le_slope_of_hasDerivWithinAt_Ioi hx hu hxu hf').trans_lt this
lemma rightDeriv_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Ioi x) x) :
derivWithin f (Ioi x) x < slope f x y :=
hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable within `S` at `x ∈ S`, then the
slope of any secant line with left endpoint at `x` is strictly greater than the derivative of `f`
within `S` at `x`.
This is fractionally weaker than `StrictConvexOn.lt_slope_of_hasDerivWithinAt_Ioi` but simpler to
apply under a `DifferentiableOn S` hypothesis. -/
lemma lt_slope_of_hasDerivWithinAt (hfc : StrictConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S x) :
f' < slope f x y :=
hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy <|
hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy
lemma derivWithin_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S x) :
derivWithin f S x < slope f x y :=
hfc.lt_slope_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `x ∈ S`, then the slope of any
secant line with left endpoint at `x` is strictly greater than the derivative of `f` at `x`. -/
lemma lt_slope_of_hasDerivAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivAt f f' x) :
f' < slope f x y :=
hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hf'.hasDerivWithinAt
lemma deriv_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f x) :
deriv f x < slope f x y :=
hfc.lt_slope_of_hasDerivAt hx hy hxy hfd.hasDerivAt
end left
section right
/-!
### Strict convex functions, derivative at right endpoint of secant
-/
/-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `y ∈ S`, then the slope of any
secant line with right endpoint at `y` is strictly less than the left derivative at `y`. -/
lemma slope_lt_of_hasDerivWithinAt_Iio (hfc : StrictConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) :
slope f x y < f' := by
obtain ⟨u, hxu, huy⟩ := exists_between hxy
have hu : u ∈ S := hfc.1.ordConnected.out hx hy ⟨hxu.le, huy.le⟩
have := hfc.secant_strict_mono hy hx hu hxy.ne huy.ne hxu
simp_rw [← slope_def_field, slope_comm _ y] at this
exact this.trans_le <| hfc.convexOn.slope_le_of_hasDerivWithinAt_Iio hu hy huy hf'
lemma slope_lt_leftDeriv (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Iio y) y) :
slope f x y < derivWithin f (Iio y) y :=
hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable within `S` at `y ∈ S`, then the
slope of any secant line with right endpoint at `y` is strictly less than the derivative of `f`
within `S` at `y`.
This is fractionally weaker than `StrictConvexOn.slope_lt_of_hasDerivWithinAt_Iio` but simpler to
apply under a `DifferentiableOn S` hypothesis. -/
lemma slope_lt_of_hasDerivWithinAt (hfc : StrictConvexOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) :
slope f x y < f' :=
hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy <|
hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy
lemma slope_lt_derivWithin (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S y) :
slope f x y < derivWithin f S y :=
hfc.slope_lt_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
/-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `y ∈ S`, then the slope of any
secant line with right endpoint at `y` is strictly less than the derivative of `f` at `y`. -/
lemma slope_lt_of_hasDerivAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivAt f f' y) :
slope f x y < f' :=
hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt
lemma slope_lt_deriv (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f y) :
slope f x y < deriv f y :=
hfc.slope_lt_of_hasDerivAt hx hy hxy hfd.hasDerivAt
end right
/-!
### Strict convex functions, strict monotonicity of derivative
-/
/-- If `f` is convex on `S` and differentiable on `S`, then its derivative within `S` is monotone
on `S`. -/
lemma strictMonoOn_derivWithin (hfc : StrictConvexOn ℝ S f) (hfd : DifferentiableOn ℝ f S) :
StrictMonoOn (derivWithin f S) S := by
intro x hx y hy hxy
exact (hfc.derivWithin_lt_slope hx hy hxy (hfd x hx)).trans
(hfc.slope_lt_derivWithin hx hy hxy (hfd y hy))
/-- If `f` is convex on `S` and differentiable at all points of `S`, then its derivative is monotone
on `S`. -/
lemma strictMonoOn_deriv (hfc : StrictConvexOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) :
StrictMonoOn (deriv f) S := by
intro x hx y hy hxy
exact (hfc.deriv_lt_slope hx hy hxy (hfd x hx)).trans (hfc.slope_lt_deriv hx hy hxy (hfd y hy))
end StrictConvexOn
section MirrorImage
variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ}
namespace ConcaveOn
section left
/-!
### Concave functions, derivative at left endpoint of secant
-/
lemma slope_le_of_hasDerivWithinAt_Ioi (hfc : ConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) :
slope f x y ≤ f' := by
simpa only [Pi.neg_def, slope_neg, neg_neg] using
neg_le_neg (hfc.neg.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy hf'.neg)
lemma slope_le_rightDeriv (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Ioi x) x) :
slope f x y ≤ derivWithin f (Ioi x) x :=
hfc.slope_le_of_hasDerivWithinAt_Ioi hx hy hxy hfd.hasDerivWithinAt
lemma slope_le_of_hasDerivWithinAt (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : HasDerivWithinAt f f' S x) :
slope f x y ≤ f' :=
hfc.slope_le_of_hasDerivWithinAt_Ioi hx hy hxy <|
hfd.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy
lemma slope_le_derivWithin (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S x) :
slope f x y ≤ derivWithin f S x :=
hfc.slope_le_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
lemma slope_le_of_hasDerivAt (hfc : ConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' x) :
slope f x y ≤ f' :=
hfc.slope_le_of_hasDerivWithinAt_Ioi hx hy hxy hf'.hasDerivWithinAt
lemma slope_le_deriv (hfc : ConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) :
slope f x y ≤ deriv f x :=
hfc.slope_le_of_hasDerivAt hx hy hxy hfd.hasDerivAt
end left
section right
/-!
### Concave functions, derivative at right endpoint of secant
-/
lemma le_slope_of_hasDerivWithinAt_Iio (hfc : ConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) :
f' ≤ slope f x y := by
simpa only [neg_neg, Pi.neg_def, slope_neg] using
neg_le_neg (hfc.neg.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hf'.neg)
lemma leftDeriv_le_slope (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Iio y) y) :
derivWithin f (Iio y) y ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt
lemma le_slope_of_hasDerivWithinAt (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivWithinAt f f' S y) :
f' ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt_Iio hx hy hxy <|
hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy
lemma derivWithin_le_slope (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S y) :
derivWithin f S y ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
lemma le_slope_of_hasDerivAt (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivAt f f' y) :
f' ≤ slope f x y :=
hfc.le_slope_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt
lemma deriv_le_slope (hfc : ConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f y) :
deriv f y ≤ slope f x y :=
hfc.le_slope_of_hasDerivAt hx hy hxy hfd.hasDerivAt
end right
/-!
### Concave functions, anti-monotonicity of derivative
-/
lemma antitoneOn_derivWithin (hfc : ConcaveOn ℝ S f) (hfd : DifferentiableOn ℝ f S) :
AntitoneOn (derivWithin f S) S := by
intro x hx y hy hxy
rcases eq_or_lt_of_le hxy with rfl | hxy'
· rfl
exact (hfc.derivWithin_le_slope hx hy hxy' (hfd y hy)).trans
(hfc.slope_le_derivWithin hx hy hxy' (hfd x hx))
/-- If `f` is concave on `S` and differentiable at all points of `S`, then its derivative is
antitone (monotone decreasing) on `S`. -/
theorem antitoneOn_deriv (hfc : ConcaveOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) :
AntitoneOn (deriv f) S := by
simpa using (hfc.neg.monotoneOn_deriv (fun x hx ↦ (hfd x hx).neg)).neg
end ConcaveOn
namespace StrictConcaveOn
section left
/-!
### Strict concave functions, derivative at left endpoint of secant
-/
lemma slope_lt_of_hasDerivWithinAt_Ioi (hfc : StrictConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) :
slope f x y < f' := by
simpa only [Pi.neg_def, slope_neg, neg_neg] using
neg_lt_neg (hfc.neg.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hf'.neg)
lemma slope_lt_rightDeriv (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Ioi x) x) :
slope f x y < derivWithin f (Ioi x) x :=
hfc.slope_lt_of_hasDerivWithinAt_Ioi hx hy hxy hfd.hasDerivWithinAt
lemma slope_lt_of_hasDerivWithinAt (hfc : StrictConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : HasDerivWithinAt f f' S x) :
slope f x y < f' := by
simpa only [Pi.neg_def, slope_neg, neg_neg] using
neg_lt_neg (hfc.neg.lt_slope_of_hasDerivWithinAt hx hy hxy hfd.neg)
lemma slope_lt_derivWithin (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S x) :
slope f x y < derivWithin f S x :=
hfc.slope_lt_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
lemma slope_lt_of_hasDerivAt (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : HasDerivAt f f' x) :
slope f x y < f' := by
simpa only [Pi.neg_def, slope_neg, neg_neg] using
neg_lt_neg (hfc.neg.lt_slope_of_hasDerivAt hx hy hxy hfd.neg)
lemma slope_lt_deriv (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f x) :
slope f x y < deriv f x :=
hfc.slope_lt_of_hasDerivAt hx hy hxy hfd.hasDerivAt
end left
section right
/-!
### Strict concave functions, derivative at right endpoint of secant
-/
lemma lt_slope_of_hasDerivWithinAt_Iio (hfc : StrictConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) :
f' < slope f x y := by
simpa only [Pi.neg_def, slope_neg, neg_neg] using
neg_lt_neg (hfc.neg.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hf'.neg)
lemma leftDeriv_lt_slope (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f (Iio y) y) :
derivWithin f (Iio y) y < slope f x y :=
hfc.lt_slope_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt
lemma lt_slope_of_hasDerivWithinAt (hfc : StrictConcaveOn ℝ S f)
(hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) :
f' < slope f x y := by
simpa only [neg_neg, Pi.neg_def, slope_neg] using
neg_lt_neg (hfc.neg.slope_lt_of_hasDerivWithinAt hx hy hxy hf'.neg)
lemma derivWithin_lt_slope (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableWithinAt ℝ f S y) :
derivWithin f S y < slope f x y :=
hfc.lt_slope_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt
lemma lt_slope_of_hasDerivAt (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hf' : HasDerivAt f f' y) :
f' < slope f x y :=
hfc.lt_slope_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt
lemma deriv_lt_slope (hfc : StrictConcaveOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y)
(hfd : DifferentiableAt ℝ f y) :
deriv f y < slope f x y :=
hfc.lt_slope_of_hasDerivAt hx hy hxy hfd.hasDerivAt
end right
/-!
### Strict concave functions, anti-monotonicity of derivative
-/
lemma strictAntiOn_derivWithin (hfc : StrictConcaveOn ℝ S f) (hfd : DifferentiableOn ℝ f S) :
StrictAntiOn (derivWithin f S) S := by
intro x hx y hy hxy
exact (hfc.derivWithin_lt_slope hx hy hxy (hfd y hy)).trans
(hfc.slope_lt_derivWithin hx hy hxy (hfd x hx))
theorem strictAntiOn_deriv (hfc : StrictConcaveOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) :
StrictAntiOn (deriv f) S := by
simpa using (hfc.neg.strictMonoOn_deriv (fun x hx ↦ (hfd x hx).neg)).neg
end StrictConcaveOn
end MirrorImage
|
notation3.lean
|
import Mathlib.Util.Notation3
import Mathlib.Data.Nat.Basic
set_option linter.style.setOption false
set_option pp.unicode.fun true
set_option autoImplicit true
namespace Test
-- set_option trace.notation3 true
def Filter (α : Type) : Type := (α → Prop) → Prop
def Filter.atTop [Preorder α] : Filter α := fun _ => True
def Filter.eventually (p : α → Prop) (f : Filter α) := f p
notation3 "∀ᶠ " (...) " in " f ", " r:(scoped p => Filter.eventually p f) => r
/-- info: ∀ᶠ (x : ℕ) (y : ℕ) in Filter.atTop, x < y : Prop -/
#guard_msgs in #check ∀ᶠ (x : Nat) (y) in Filter.atTop, x < y
/-- info: ∀ᶠ (x : ℕ) in Filter.atTop, x < 3 : Prop -/
#guard_msgs in #check ∀ᶠ x in Filter.atTop, x < 3
/-!
Test that `pp.tagAppFns` causes tokens to be tagged with head constant.
-/
open Lean in
def findWithTag (tag : Nat) (f : Format) : List Format :=
match f with
| .nil => []
| .line => []
| .align _ => []
| .text _ => []
| .nest _ f' => findWithTag tag f'
| .append f' f'' => findWithTag tag f' ++ findWithTag tag f''
| .group f' _ => findWithTag tag f'
| .tag t f' => (if t = tag then [f'] else []) ++ findWithTag tag f'
open Lean Elab Term in
def testTagAppFns (n : Name) : TermElabM Unit := do
let stx ← `(∀ᶠ x in Filter.atTop, x < 3)
let e ← elabTermAndSynthesize stx none
let f ← Meta.ppExprWithInfos e
-- Find tags for the constant `n`
let tags : Array Nat := f.infos.foldl (init := #[]) fun tags tag info =>
match info with
| .ofTermInfo info | .ofDelabTermInfo info =>
if info.expr.isConstOf n then
tags.push tag
else
tags
| _ => tags
let fmts := tags.map (findWithTag · f.fmt)
unless fmts.all (!·.isEmpty) do throwError "missing tag"
let fmts := fmts.toList.flatten
logInfo m!"{repr <| fmts.map (·.pretty.trim)}"
section
/-- info: [] -/
#guard_msgs in #eval testTagAppFns ``Filter.eventually
set_option pp.tagAppFns true
/-- info: ["∀ᶠ", "in", ","] -/
#guard_msgs in #eval testTagAppFns ``Filter.eventually
end
-- Testing lambda expressions:
notation3 "∀ᶠ' " f ", " p => Filter.eventually (fun x => (p : _ → _) x) f
/-- info: ∀ᶠ' Filter.atTop, fun x ↦ x < 3 : Prop -/
#guard_msgs in #check ∀ᶠ' Filter.atTop, fun x => x < 3
def foobar (p : α → Prop) (f : Prop) := ∀ x, p x = f
notation3 "∀ᶠᶠ " (...) " in " f ": "
r1:(scoped p => Filter.eventually p f) ", " r2:(scoped p => foobar p r1) => r2
/-- info: ∀ᶠᶠ (x : ℕ) (y : ℕ) in Filter.atTop: x < y, x = y : Prop -/
#guard_msgs in #check ∀ᶠᶠ (x : Nat) (y) in Filter.atTop: x < y, x = y
/-- info: ∀ᶠᶠ (x : ℕ) in Filter.atTop: x < 3, x = 1 : Prop -/
#guard_msgs in #check ∀ᶠᶠ x in Filter.atTop: x < 3, x = 1
/-- info: ∀ᶠᶠ (x : ℕ) in Filter.atTop: x < 3, x = 1 : Prop -/
#guard_msgs in #check foobar (fun x ↦ Eq x 1) (Filter.atTop.eventually fun x ↦ LT.lt x 3)
/-- info: foobar (fun y ↦ y = 1) (∀ᶠ (x : ℕ) in Filter.atTop, x < 3) : Prop -/
#guard_msgs in #check foobar (fun y ↦ Eq y 1) (Filter.atTop.eventually fun x ↦ LT.lt x 3)
notation3 "∃' " (...) ", " r:(scoped p => Exists p) => r
/-- info: ∃' (a : ℕ) (_ : a < 3), a < 3 : Prop -/
#guard_msgs in #check ∃' a < 3, a < 3
/-- info: ∃' (x : ℕ) (_ : x < 3), True : Prop -/
#guard_msgs in #check ∃' _ < 3, True
/-- info: ∃' (x : ℕ) (_ : x < 1) (x_1 : ℕ) (_ : x_1 < 2), x = 0 : Prop -/
#guard_msgs in #check ∃' (x < 1) (_ < 2), x = 0
def func (x : α) : α := x
notation3 "func! " (...) ", " r:(scoped p => func p) => r
/-- info: (func! (x : ℕ → ℕ), x) fun x ↦ x * 2 : ℕ → ℕ -/
#guard_msgs in #check (func! (x : Nat → Nat), x) (· * 2)
structure MyUnit where
notation3 "~{" (x"; "* => foldl (a b => (a, b)) MyUnit) "}~" => x
/-- info: ~{1; true; ~{2}~}~ : ((Type × ℕ) × Bool) × Type × ℕ -/
#guard_msgs in #check ~{1; true; ~{2}~}~
/-- info: ~{}~ : Type -/
#guard_msgs in #check ~{}~
structure MyUnit' where
instance : OfNat MyUnit' (nat_lit 0) := ⟨{}⟩
notation3 "MyUnit'0" => (0 : MyUnit')
/-- info: MyUnit'0 : MyUnit' -/
#guard_msgs in #check (0 : MyUnit')
/-- info: 0 : ℕ -/
#guard_msgs in #check 0
notation3 "%[" (x", "* => foldr (a b => a :: b) []) "]" => x
/-- info: %[1, 2, 3] : List ℕ -/
#guard_msgs in #check %[1, 2, 3]
def foo (a : Nat) (f : Nat → Nat) := a + f a
def bar (a b : Nat) := a * b
notation3 "*[" x "] " (...) ", " v:(scoped c => bar x (foo x c)) => v
/-- info: *[1] (x : ℕ) (y : ℕ), x + y : ℕ -/
#guard_msgs in #check *[1] (x) (y), x + y
/-- info: bar 1 : ℕ → ℕ -/
#guard_msgs in #check bar 1
-- Checking that the `<|` macro is expanded when making matcher
def foo' (a : Nat) (f : Nat → Nat) := a + f a
def bar' (a b : Nat) := a * b
notation3 "*'[" x "] " (...) ", " v:(scoped c => bar' x <| foo' x c) => v
/-- info: *'[1] (x : ℕ) (y : ℕ), x + y : ℕ -/
#guard_msgs in #check *'[1] (x) (y), x + y
/-- info: bar' 1 : ℕ → ℕ -/
#guard_msgs in #check bar' 1
-- Need to give type ascription to `p` so that `p x` elaborates when making matcher
notation3 "MyPi " (...) ", " r:(scoped p => (x : _) → (p : _ → _) x) => r
/-- info: MyPi (x : ℕ) (y : ℕ), x < y : Prop -/
#guard_msgs in #check MyPi (x : Nat) (y : Nat), x < y
-- The notation parses fine, but the delaborator never succeeds, which is expected
def myId (x : α) := x
notation3 "BAD " c "; " (x", "* => foldl (a b => b) c) " DAB" => myId x
/-- info: myId 3 : ℕ -/
#guard_msgs in #check BAD 1; 2, 3 DAB
section
variable (x : Nat)
local notation3 "y" => x + 1
/-- info: y : ℕ -/
#guard_msgs in #check y
/-- info: y : ℕ -/
#guard_msgs in #check x + 1
end
section
variable (α : Type u) [Add α]
local notation3 x " +α " y => (x + y : α)
variable (x y : α)
/-- info: x +α y : α -/
#guard_msgs in #check x +α y
/-- info: x +α y : α -/
#guard_msgs in #check x + y
/-- info: 1 + 2 : ℕ -/
#guard_msgs in #check 1 + 2
end
def idStr : String → String := id
/--
error: Application type mismatch: The argument
Nat.zero
has type
ℕ
but is expected to have type
String
in the application
idStr Nat.zero
---
warning: Was not able to generate a pretty printer for this notation. If you do not expect it to be pretty printable, then you can use `notation3 (prettyPrint := false)`. If the notation expansion refers to section variables, be sure to do `local notation3`. Otherwise, you might be able to adjust the notation expansion to make it matchable; pretty printing relies on deriving an expression matcher from the expansion. (Use `set_option trace.notation3 true` to get some debug information.)
-/
#guard_msgs in
notation3 "error" => idStr Nat.zero
section
/--
warning: Was not able to generate a pretty printer for this notation. If you do not expect it to be
pretty printable, then you can use `notation3 (prettyPrint := false)`. If the notation expansion
refers to section variables, be sure to do `local notation3`. Otherwise, you might be able to adjust
the notation expansion to make it matchable; pretty printing relies on deriving an expression
matcher from the expansion. (Use `set_option trace.notation3 true` to get some debug information.)
-/
#guard_msgs (warning, drop error) in local notation3 "#" n => Fin.mk n (by decide)
end
section
set_option linter.unusedTactic false
local notation3 (prettyPrint := false) "#" n => Fin.mk n (by decide)
example : Fin 5 := #1
/--
error: Tactic `decide` proved that the proposition
6 < 5
is false
-/
#guard_msgs in example : Fin 5 := #6
end
section test_scoped
scoped[MyNotation] notation3 "π" => (3 : Nat)
/-- error: Unknown identifier `π` -/
#guard_msgs in #check π
open scoped MyNotation
/-- info: π : ℕ -/
#guard_msgs in #check π
end test_scoped
/-!
Verifying that delaborator does not match the exact `Inhabited` instance.
Instead, it matches that it's an application of `Inhabited.default` whose first argument is `Nat`.
-/
/--
trace: [notation3] syntax declaration has name Test.termδNat
---
trace: [notation3] Generating matcher for pattern default
[notation3] Matcher creation succeeded; assembling delaborator
[notation3] matcher:
matchApp✝ (matchApp✝ (matchExpr✝ (Expr.isConstOf✝ · `Inhabited.default)) (matchExpr✝ (Expr.isConstOf✝ · `Nat)))
pure✝ >=>
pure✝
[notation3] Creating delaborator for key Mathlib.Notation3.DelabKey.app (some `Inhabited.default) 2
---
trace: [notation3] Defined delaborator Test.termδNat.«delab_app.Inhabited.default»
-/
#guard_msgs in
set_option trace.notation3 true in
notation3 "δNat" => (default : Nat)
/-- info: δNat : ℕ -/
#guard_msgs in #check (default : Nat)
/-- info: δNat : ℕ -/
#guard_msgs in #check @default Nat (Inhabited.mk 5)
notation3 "(" "ignorez " "SVP" ")" => Sort _
notation3 "Objet " "mathématique " "supérieur" => Type _
notation3 "Énoncé" => Prop
notation3 "Objet " "mathématique" => Type
/-- info: 1 = 1 : Énoncé -/
#guard_msgs in #check 1 = 1
/-- info: Énoncé : Objet mathématique -/
#guard_msgs in #check Prop
/-- info: Nat : Objet mathématique -/
#guard_msgs in #check Nat
/-- info: Objet mathématique : Objet mathématique supérieur -/
#guard_msgs in #check Type
/-- info: PSum.{u, v} (α : (ignorez SVP)) (β : (ignorez SVP)) : (ignorez SVP) -/
#guard_msgs in #check PSum
end Test
|
algC.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype seq choice.
From mathcomp Require Import div fintype path bigop finset prime order ssralg.
From mathcomp Require Import poly polydiv mxpoly generic_quotient countalg.
From mathcomp Require Import ssrnum closed_field ssrint archimedean rat intdiv.
From mathcomp Require Import algebraics_fundamentals.
(******************************************************************************)
(* This file provides an axiomatic construction of the algebraic numbers. *)
(* The construction only assumes the existence of an algebraically closed *)
(* filed with an automorphism of order 2; this amounts to the purely *)
(* algebraic contents of the Fundamenta Theorem of Algebra. *)
(* algC == the closed, countable field of algebraic numbers. *)
(* algCeq, algCnzRing, ..., algCnumField == structures for algC. *)
(* The ssrnum interfaces are implemented for algC as follows: *)
(* x <= y <=> (y - x) is a nonnegative real *)
(* x < y <=> (y - x) is a (strictly) positive real *)
(* `|z| == the complex norm of z, i.e., sqrtC (z * z^* ). *)
(* Creal == the subset of real numbers (:= Num.real for algC). *)
(* 'i == the imaginary number (:= sqrtC (-1)). *)
(* 'Re z == the real component of z. *)
(* 'Im z == the imaginary component of z. *)
(* z^* == the complex conjugate of z (:= conjC z). *)
(* sqrtC z == a nonnegative square root of z, i.e., 0 <= sqrt x if 0 <= x. *)
(* n.-root z == more generally, for n > 0, an nth root of z, chosen with a *)
(* minimal non-negative argument for n > 1 (i.e., with a *)
(* maximal real part subject to a nonnegative imaginary part). *)
(* Note that n.-root (-1) is a primitive 2nth root of unity, *)
(* an thus not equal to -1 for n odd > 1 (this will be shown in *)
(* file cyclotomic.v). *)
(* In addition, we provide: *)
(* Crat == the subset of rational numbers. *)
(* getCrat z == some a : rat such that ratr a = z, provided z \in Crat. *)
(* minCpoly z == the minimal (monic) polynomial over Crat with root z. *)
(* algC_invaut nu == an inverse of nu : {rmorphism algC -> algC}. *)
(* (x %| y)%C <=> y is an integer (Num.int) multiple of x; if x or y *)
(* (x %| y)%Cx are of type nat or int they are coerced to algC. *)
(* The (x %| y)%Cx display form is a workaround for *)
(* design limitations of the Coq Notation facilities. *)
(* (x == y %[mod z])%C <=> x and y differ by an integer (Num.int) multiple of *)
(* z; as above, arguments of type nat or int are cast to algC. *)
(* (x != y %[mod z])%C <=> x and y do not differ by an integer multiple of z. *)
(* algR == the subset of real algebraic numbers. *)
(* algR_norm x == the norm of (x : algR). *)
(* algR_pfactor x == the minimal (monic) polynomial over algR with root x. *)
(* algC_pfactor x == the minimal (monic) polynomial over algR with root x, *)
(* with coefficients in algC. *)
(* Note that in file algnum we give an alternative definition of divisibility *)
(* based on algebraic integers, overloading the notation in the %A scope. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope C_scope.
Declare Scope C_core_scope.
Declare Scope C_expanded_scope.
Import Order.TTheory GRing.Theory Num.Theory.
Local Open Scope ring_scope.
HB.factory Record isComplex L of GRing.ClosedField L := {
conj : {rmorphism L -> L};
conjK : involutive conj;
conj_nt : ~ conj =1 id
}.
HB.builders Context L of isComplex L.
Lemma nz2: 2 != 0 :> L.
Proof.
apply/eqP=> pchar2; apply: conj_nt => e; apply/eqP/idPn=> eJ.
have opp_id x: - x = x :> L.
by apply/esym/eqP; rewrite -addr_eq0 -mulr2n -mulr_natl pchar2 mul0r.
have{} pchar2: 2%N \in [pchar L] by apply/eqP.
without loss{eJ} eJ: e / conj e = e + 1.
move/(_ (e / (e + conj e))); apply.
rewrite fmorph_div rmorphD /= conjK -{1}[conj e](addNKr e) mulrDl.
by rewrite opp_id (addrC e) divff // addr_eq0 opp_id.
pose a := e * conj e; have aJ: conj a = a by rewrite rmorphM /= conjK mulrC.
have [w Dw] := @solve_monicpoly _ 2%N (nth 0 [:: e * a; - 1]) isT.
have{} Dw: w ^+ 2 + w = e * a.
by rewrite Dw !big_ord_recl big_ord0 /= mulr1 mulN1r addr0 subrK.
pose b := w + conj w; have bJ: conj b = b by rewrite rmorphD /= conjK addrC.
have Db2: b ^+ 2 + b = a.
rewrite -pFrobenius_autE // rmorphD addrACA Dw /= pFrobenius_autE -rmorphXn.
by rewrite -rmorphD Dw rmorphM /= aJ eJ -mulrDl -{1}[e]opp_id addKr mul1r.
have /eqP[] := oner_eq0 L; apply: (addrI b); rewrite addr0 -{2}bJ.
have: (b + e) * (b + conj e) == 0.
(* FIX ME : had to add pattern selection *)
rewrite mulrDl 2![_ * (b + _)]mulrDr -/a.
rewrite addrA addr_eq0 opp_id (mulrC e) -addrA.
by rewrite -mulrDr eJ addrAC -{2}[e]opp_id subrr add0r mulr1 Db2.
rewrite mulf_eq0 !addr_eq0 !opp_id => /pred2P[] -> //.
by rewrite {2}eJ rmorphD rmorph1.
Qed.
Lemma mul2I: injective (fun z : L => z *+ 2).
Proof.
have nz2 := nz2.
by move=> x y; rewrite /= -mulr_natl -(mulr_natl y) => /mulfI->.
Qed.
Definition sqrt x : L :=
sval (sig_eqW (@solve_monicpoly _ 2%N (nth 0 [:: x]) isT)).
Lemma sqrtK x: sqrt x ^+ 2 = x.
Proof.
rewrite /sqrt; case: sig_eqW => /= y ->.
by rewrite !big_ord_recl big_ord0 /= mulr1 mul0r !addr0.
Qed.
Lemma sqrtE x y: y ^+ 2 = x -> {b : bool | y = (-1) ^+ b * sqrt x}.
Proof.
move=> Dx; exists (y != sqrt x); apply/eqP; rewrite mulr_sign if_neg.
by case: ifPn => //; apply/implyP; rewrite implyNb -eqf_sqr Dx sqrtK.
Qed.
Definition i := sqrt (- 1).
Lemma sqrMi x: (i * x) ^+ 2 = - x ^+ 2.
Proof. by rewrite exprMn sqrtK mulN1r. Qed.
Lemma iJ : conj i = - i.
Proof.
have nz2 := nz2.
have /sqrtE[b]: conj i ^+ 2 = - 1 by rewrite -rmorphXn /= sqrtK rmorphN1.
rewrite mulr_sign -/i; case: b => // Ri.
case: conj_nt => z; wlog zJ: z / conj z = - z.
move/(_ (z - conj z)); rewrite !rmorphB conjK opprB => zJ.
by apply/mul2I/(canRL (subrK _)); rewrite -addrA zJ // addrC subrK.
have [-> | nz_z] := eqVneq z 0; first exact: rmorph0.
have [u Ru [v Rv Dz]]:
exists2 u, conj u = u & exists2 v, conj v = v & (u + z * v) ^+ 2 = z.
- pose y := sqrt z; exists ((y + conj y) / 2).
by rewrite fmorph_div rmorphD /= conjK addrC rmorph_nat.
exists ((y - conj y) / (z *+ 2)).
rewrite fmorph_div rmorphMn /= zJ mulNrn invrN mulrN -mulNr rmorphB opprB.
by rewrite conjK.
rewrite -(mulr_natl z) invfM (mulrC z) !mulrA divfK // -mulrDl addrACA.
(* FIX ME : had to add the explicit pattern *)
by rewrite subrr addr0 -mulr2n -[_ *+ 2]mulr_natr mulfK ?Neq0 ?sqrtK.
suff u0: u = 0 by rewrite -Dz u0 add0r rmorphXn rmorphM /= Rv zJ mulNr sqrrN.
suff [b Du]: exists b : bool, u = (-1) ^+ b * i * z * v.
apply: mul2I; rewrite mul0rn mulr2n -{2}Ru.
by rewrite Du !rmorphM /= rmorph_sign Rv Ri zJ !mulrN mulNr subrr.
have/eqP:= zJ; rewrite -addr_eq0 -{1 2}Dz rmorphXn rmorphD rmorphM /= Ru Rv zJ.
rewrite mulNr sqrrB sqrrD addrACA (addrACA (u ^+ 2)) addNr addr0 -!mulr2n.
rewrite -mulrnDl -(mul0rn _ 2) (inj_eq mul2I) /= -[rhs in _ + rhs]opprK.
rewrite -sqrMi subr_eq0 eqf_sqr -mulNr !mulrA.
by case/pred2P=> ->; [exists false | exists true]; rewrite mulr_sign.
Qed.
Definition norm x := sqrt x * conj (sqrt x).
Lemma normK x : norm x ^+ 2 = x * conj x.
Proof. by rewrite exprMn -rmorphXn sqrtK. Qed.
Lemma normE x y : y ^+ 2 = x -> norm x = y * conj y.
Proof.
rewrite /norm => /sqrtE[b /(canLR (signrMK b)) <-].
by rewrite !rmorphM /= rmorph_sign mulrACA -mulrA signrMK.
Qed.
Lemma norm_eq0 x : norm x = 0 -> x = 0.
Proof.
by move/eqP; rewrite mulf_eq0 fmorph_eq0 -mulf_eq0 -expr2 sqrtK => /eqP.
Qed.
Lemma normM x y : norm (x * y) = norm x * norm y.
Proof.
by rewrite mulrACA -rmorphM; apply: normE; rewrite exprMn !sqrtK.
Qed.
Lemma normN x : norm (- x) = norm x.
Proof.
by rewrite -mulN1r normM {1}/norm iJ mulrN -expr2 sqrtK opprK mul1r.
Qed.
Definition le x y := norm (y - x) == y - x.
Definition lt x y := (y != x) && le x y.
Lemma posE x: le 0 x = (norm x == x).
Proof. by rewrite /le subr0. Qed.
Lemma leB x y: le x y = le 0 (y - x).
Proof. by rewrite posE. Qed.
Lemma posP x : reflect (exists y, x = y * conj y) (le 0 x).
Proof.
rewrite posE; apply: (iffP eqP) => [Dx | [y {x}->]]; first by exists (sqrt x).
by rewrite (normE (normK y)) rmorphM /= conjK (mulrC (conj _)) -expr2 normK.
Qed.
Lemma posJ x : le 0 x -> conj x = x.
Proof.
by case/posP=> {x}u ->; rewrite rmorphM /= conjK mulrC.
Qed.
Lemma pos_linear x y : le 0 x -> le 0 y -> le x y || le y x.
Proof.
move=> pos_x pos_y; rewrite leB -opprB orbC leB !posE normN -eqf_sqr.
by rewrite normK rmorphB !posJ ?subrr.
Qed.
Lemma sposDl x y : lt 0 x -> le 0 y -> lt 0 (x + y).
Proof.
have sqrtJ z : le 0 z -> conj (sqrt z) = sqrt z.
rewrite posE -{2}[z]sqrtK -subr_eq0 -mulrBr mulf_eq0 subr_eq0.
by case/pred2P=> ->; rewrite ?rmorph0.
case/andP=> nz_x /sqrtJ uJ /sqrtJ vJ.
set u := sqrt x in uJ; set v := sqrt y in vJ; pose w := u + i * v.
have ->: x + y = w * conj w.
rewrite rmorphD rmorphM /= iJ uJ vJ mulNr mulrC -subr_sqr sqrMi opprK.
by rewrite !sqrtK.
apply/andP; split; last by apply/posP; exists w.
rewrite -normK expf_eq0 //=; apply: contraNneq nz_x => /norm_eq0 w0.
rewrite -[x]sqrtK expf_eq0 /= -/u -(inj_eq mul2I) !mulr2n -{2}(rmorph0 conj).
by rewrite -w0 rmorphD rmorphM /= iJ uJ vJ mulNr addrACA subrr addr0.
Qed.
Lemma sposD x y : lt 0 x -> lt 0 y -> lt 0 (x + y).
Proof.
by move=> x_gt0 /andP[_]; apply: sposDl.
Qed.
Lemma normD x y : le (norm (x + y)) (norm x + norm y).
Proof.
have sposM u v: lt 0 u -> le 0 (u * v) -> le 0 v.
by rewrite /lt !posE normM andbC => /andP[/eqP-> /mulfI/inj_eq->].
have posD u v: le 0 u -> le 0 v -> le 0 (u + v).
have [-> | nz_u u_ge0 v_ge0] := eqVneq u 0; first by rewrite add0r.
by have /andP[]: lt 0 (u + v) by rewrite sposDl // /lt nz_u.
have le_sqr u v: conj u = u -> le 0 v -> le (u ^+ 2) (v ^+ 2) -> le u v.
case: (eqVneq u 0) => [-> //|nz_u Ru v_ge0].
have [u_gt0 | u_le0 _] := boolP (lt 0 u).
by rewrite leB (leB u) subr_sqr mulrC addrC; apply: sposM; apply: sposDl.
rewrite leB posD // posE normN -addr_eq0; apply/eqP.
rewrite /lt nz_u posE -subr_eq0 in u_le0; apply: (mulfI u_le0).
by rewrite mulr0 -subr_sqr normK Ru subrr.
have pos_norm z: le 0 (norm z) by apply/posP; exists (sqrt z).
rewrite le_sqr ?posJ ?posD // sqrrD !normK -normM rmorphD mulrDl !mulrDr.
rewrite addrA addrC !addrA -(addrC (y * conj y)) !addrA.
move: (y * _ + _) => u; rewrite -!addrA leB opprD addrACA {u}subrr add0r -leB.
rewrite {}le_sqr ?posD //.
by rewrite rmorphD !rmorphM /= !conjK addrC (mulrC x) (mulrC y).
rewrite -mulr2n -mulr_natr exprMn normK -natrX mulr_natr sqrrD mulrACA.
rewrite -rmorphM (mulrC y x) addrAC leB mulrnA mulr2n opprD addrACA.
rewrite subrr addr0 {2}(mulrC x) rmorphM mulrACA -opprB addrAC -sqrrB -sqrMi.
apply/posP; exists (i * (x * conj y - y * conj x)); congr (_ * _).
rewrite !(rmorphM, rmorphB) iJ !conjK mulNr -[in RHS]mulrN opprB.
by rewrite (mulrC x) (mulrC y).
Qed.
HB.instance Definition _ :=
Num.IntegralDomain_isNumRing.Build L normD sposD norm_eq0
pos_linear normM (fun x y => erefl (le x y))
(fun x y => erefl (lt x y)).
HB.instance Definition _ :=
Num.NumField_isImaginary.Build L (sqrtK _) normK.
HB.end.
Module Algebraics.
Module Type Specification.
Parameter type : Type.
Parameter conjMixin : Num.ClosedField type.
Parameter isCountable : Countable type.
(* Note that this cannot be included in conjMixin since a few proofs
depend from nat_num being definitionally equal to (truncn x)%:R == x *)
Axiom archimedean : Num.archimedean_axiom (Num.ClosedField.Pack conjMixin).
Axiom algebraic : integralRange (@ratr (Num.ClosedField.Pack conjMixin)).
End Specification.
Module Implementation : Specification.
Definition L := tag Fundamental_Theorem_of_Algebraics.
Definition conjL : {rmorphism L -> L} :=
s2val (tagged Fundamental_Theorem_of_Algebraics).
Fact conjL_K : involutive conjL.
Proof. exact: s2valP (tagged Fundamental_Theorem_of_Algebraics). Qed.
Fact conjL_nt : ~ conjL =1 id.
Proof. exact: s2valP' (tagged Fundamental_Theorem_of_Algebraics). Qed.
Definition L' : Type := eta L.
HB.instance Definition _ := GRing.ClosedField.on L'.
HB.instance Definition _ := isComplex.Build L' conjL_K conjL_nt.
Notation cfType := (L' : closedFieldType).
Definition QtoL : {rmorphism _ -> _} := @ratr cfType.
Notation pQtoL := (map_poly QtoL).
Definition rootQtoL p_j :=
if p_j.1 == 0 then 0 else
(sval (closed_field_poly_normal (pQtoL p_j.1)))`_p_j.2.
Definition eq_root p_j q_k := rootQtoL p_j == rootQtoL q_k.
Fact eq_root_is_equiv : equiv_class_of eq_root.
Proof. by rewrite /eq_root; split=> [ ? | ? ? | ? ? ? ] // /eqP->. Qed.
Canonical eq_root_equiv := EquivRelPack eq_root_is_equiv.
Definition type : Type := {eq_quot eq_root}%qT.
HB.instance Definition _ : EqQuotient _ eq_root type := EqQuotient.on type.
HB.instance Definition _ := Choice.on type.
HB.instance Definition _ := isCountable.Build type
(pcan_pickleK (can_pcan reprK)).
Definition CtoL (u : type) := rootQtoL (repr u).
Fact CtoL_inj : injective CtoL.
Proof. by move=> u v /eqP eq_uv; rewrite -[u]reprK -[v]reprK; apply/eqmodP. Qed.
Fact CtoL_P u : integralOver QtoL (CtoL u).
Proof.
rewrite /CtoL /rootQtoL; case: (repr u) => p j /=.
case: (closed_field_poly_normal _) => r Dp /=.
case: ifPn => [_ | nz_p]; first exact: integral0.
have [/(nth_default 0)-> | lt_j_r] := leqP (size r) j; first exact: integral0.
apply/integral_algebraic; exists p; rewrite // Dp -mul_polyC rootM orbC.
by rewrite root_prod_XsubC mem_nth.
Qed.
Fact LtoC_subproof z : integralOver QtoL z -> {u | CtoL u = z}.
Proof.
case/sig2_eqW=> p mon_p pz0; rewrite /CtoL.
pose j := index z (sval (closed_field_poly_normal (pQtoL p))).
pose u := \pi_type%qT (p, j); exists u; have /eqmodP/eqP-> := reprK u.
rewrite /rootQtoL -if_neg monic_neq0 //; apply: nth_index => /=.
case: (closed_field_poly_normal _) => r /= Dp.
by rewrite Dp (monicP _) ?(monic_map QtoL) // scale1r root_prod_XsubC in pz0.
Qed.
Definition LtoC z Az := sval (@LtoC_subproof z Az).
Fact LtoC_K z Az : CtoL (@LtoC z Az) = z.
Proof. exact: (svalP (LtoC_subproof Az)). Qed.
Fact CtoL_K u : LtoC (CtoL_P u) = u.
Proof. by apply: CtoL_inj; rewrite LtoC_K. Qed.
Definition zero := LtoC (integral0 _).
Definition add u v := LtoC (integral_add (CtoL_P u) (CtoL_P v)).
Definition opp u := LtoC (integral_opp (CtoL_P u)).
Fact addA : associative add.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K addrA. Qed.
Fact addC : commutative add.
Proof. by move=> u v; apply: CtoL_inj; rewrite !LtoC_K addrC. Qed.
Fact add0 : left_id zero add.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K add0r. Qed.
Fact addN : left_inverse zero opp add.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build type addA addC add0 addN.
Fact CtoL_is_zmod_morphism : zmod_morphism CtoL.
Proof. by move=> u v; rewrite !LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_inj_is_zmod_morphism` instead")]
Definition CtoL_is_additive := CtoL_is_zmod_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build type L' CtoL
CtoL_is_zmod_morphism.
Definition one := LtoC (integral1 _).
Definition mul u v := LtoC (integral_mul (CtoL_P u) (CtoL_P v)).
Definition inv u := LtoC (integral_inv (CtoL_P u)).
Fact mulA : associative mul.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K mulrA. Qed.
Fact mulC : commutative mul.
Proof. by move=> u v; apply: CtoL_inj; rewrite !LtoC_K mulrC. Qed.
Fact mul1 : left_id one mul.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K mul1r. Qed.
Fact mulD : left_distributive mul +%R.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K mulrDl. Qed.
Fact one_nz : one != 0 :> type.
Proof. by rewrite -(inj_eq CtoL_inj) !LtoC_K oner_eq0. Qed.
HB.instance Definition _ :=
GRing.Zmodule_isComNzRing.Build type mulA mulC mul1 mulD one_nz.
Fact CtoL_is_monoid_morphism : monoid_morphism CtoL.
Proof. by split=> [|u v]; rewrite !LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_is_monoid_morphism` instead")]
Definition CtoL_is_multiplicative :=
(fun g => (g.2,g.1)) CtoL_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build type L' CtoL
CtoL_is_monoid_morphism.
Fact mulVf u : u != 0 -> inv u * u = 1.
Proof.
rewrite -(inj_eq CtoL_inj) rmorph0 => nz_u.
by apply: CtoL_inj; rewrite !LtoC_K mulVf.
Qed.
Fact inv0 : inv 0 = 0. Proof. by apply: CtoL_inj; rewrite !LtoC_K invr0. Qed.
HB.instance Definition _ := GRing.ComNzRing_isField.Build type mulVf inv0.
Fact closedFieldAxiom : GRing.closed_field_axiom type.
Proof.
move=> n a n_gt0; pose p := 'X^n - \poly_(i < n) CtoL (a i).
have Ap : {in p : seq L, integralRange QtoL}.
move=> _ /(nthP 0)[j _ <-]; rewrite coefB coefXn coef_poly.
apply: integral_sub; first exact: integral_nat.
by case: ifP => _; [apply: CtoL_P | apply: integral0].
have sz_p : size p = n.+1.
by rewrite size_polyDl size_polyXn // size_polyN ltnS size_poly.
have [z pz0] : exists z, root p z by apply/closed_rootP; rewrite sz_p eqSS -lt0n.
have Az: integralOver ratr z.
by apply: integral_root Ap; rewrite // -size_poly_gt0 sz_p.
exists (LtoC Az); apply/CtoL_inj; rewrite -[CtoL _]subr0 -(rootP pz0).
rewrite rmorphXn /= LtoC_K hornerD hornerXn hornerN opprD addNKr opprK.
rewrite horner_poly rmorph_sum; apply: eq_bigr => k _.
by rewrite rmorphM rmorphXn /= LtoC_K.
Qed.
HB.instance Definition _ := Field_isAlgClosed.Build type closedFieldAxiom.
Fact conj_subproof u : integralOver QtoL (conjL (CtoL u)).
Proof.
have [p mon_p pu0] := CtoL_P u; exists p => //.
rewrite -(fmorph_root conjL) conjL_K map_poly_id // => _ /(nthP 0)[j _ <-].
by rewrite coef_map fmorph_rat.
Qed.
Fact conj_is_nmod_morphism : nmod_morphism (fun u => LtoC (conj_subproof u)).
Proof.
by split=> [|u v]; apply: CtoL_inj; rewrite LtoC_K ?raddf0// !rmorphD/= !LtoC_K.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `conj_is_nmod_morphism` instead")]
Definition conj_is_semi_additive := conj_is_nmod_morphism.
Fact conj_is_zmod_morphism : {morph (fun u => LtoC (conj_subproof u)) : x / - x}.
Proof. by move=> u; apply: CtoL_inj; rewrite LtoC_K !raddfN /= LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_inj_is_zmod_morphism` instead")]
Definition conj_is_additive := conj_is_zmod_morphism.
Fact conj_is_monoid_morphism : monoid_morphism (fun u => LtoC (conj_subproof u)).
Proof.
split=> [|u v]; apply: CtoL_inj; first by rewrite !LtoC_K rmorph1.
by rewrite LtoC_K 3!{1}rmorphM /= !LtoC_K.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `conj_is_monoid_morphism` instead")]
Definition conj_is_multiplicative :=
(fun g => (g.2,g.1)) conj_is_monoid_morphism.
Definition conj : {rmorphism type -> type} :=
GRing.RMorphism.Pack
(GRing.RMorphism.Class
(GRing.isNmodMorphism.Build _ _ _ conj_is_nmod_morphism)
(GRing.isMonoidMorphism.Build _ _ _ conj_is_monoid_morphism)).
Lemma conjK : involutive conj.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K conjL_K. Qed.
Fact conj_nt : ~ conj =1 id.
Proof.
have [i i2]: exists i : type, i ^+ 2 = -1.
have [i] := @solve_monicpoly _ 2%N (nth 0 [:: -1 : type]) isT.
by rewrite !big_ord_recl big_ord0 /= mul0r mulr1 !addr0; exists i.
move/(_ i)/(congr1 CtoL); rewrite LtoC_K => iL_J.
have/lt_geF/idP[] := @ltr01 cfType.
rewrite -oppr_ge0 -(rmorphN1 CtoL).
by rewrite -i2 rmorphXn /= expr2 -{2}iL_J -normCK exprn_ge0.
Qed.
HB.instance Definition _ := isComplex.Build type conjK conj_nt.
Definition conjMixin := Num.ClosedField.on type.
Lemma algebraic : integralRange (@ratr type).
Proof.
move=> u; have [p mon_p pu0] := CtoL_P u; exists p => {mon_p}//.
rewrite -(fmorph_root CtoL) -map_poly_comp; congr (root _ _):pu0.
by apply/esym/eq_map_poly; apply: fmorph_eq_rat.
Qed.
Fact archimedean : Num.archimedean_axiom type.
Proof. exact: rat_algebraic_archimedean algebraic. Qed.
Definition isCountable := Countable.on type.
End Implementation.
Definition divisor := Implementation.type.
#[export] HB.instance Definition _ := Implementation.conjMixin.
#[export] HB.instance Definition _ :=
Num.NumDomain_bounded_isArchimedean.Build Implementation.type
Implementation.archimedean.
#[export] HB.instance Definition _ := Implementation.isCountable.
Module Internals.
Import Implementation.
Local Notation algC := type.
Local Notation QtoC := (ratr : rat -> algC).
Local Notation pQtoC := (map_poly QtoC : {poly rat} -> {poly algC}).
Fact algCi_subproof : {i : algC | i ^+ 2 = -1}.
Proof. exact: GRing.imaginary_exists. Qed.
Variant getCrat_spec : Type := GetCrat_spec CtoQ of cancel QtoC CtoQ.
Fact getCrat_subproof : getCrat_spec.
Proof.
have isQ := rat_algebraic_decidable algebraic.
exists (fun z => if isQ z is left Qz then sval (sig_eqW Qz) else 0) => a.
case: (isQ _) => [Qa | []]; last by exists a.
by case: (sig_eqW _) => b /= /fmorph_inj.
Qed.
Fact minCpoly_subproof (x : algC) :
{p : {poly rat} | p \is monic & forall q, root (pQtoC q) x = (p %| q)%R}.
Proof.
have isQ := rat_algebraic_decidable algebraic.
have [p [mon_p px0 irr_p]] := minPoly_decidable_closure isQ (algebraic x).
exists p => // q; apply/idP/idP=> [qx0 | /dvdpP[r ->]]; last first.
by rewrite rmorphM rootM px0 orbT.
suffices /eqp_dvdl <-: gcdp p q %= p by apply: dvdp_gcdr.
rewrite irr_p ?dvdp_gcdl ?gtn_eqF // -(size_map_poly QtoC) gcdp_map /=.
rewrite (@root_size_gt1 _ x) ?root_gcd ?px0 //.
by rewrite gcdp_eq0 negb_and map_poly_eq0 monic_neq0.
Qed.
Definition algC_divisor (x : algC) := x : divisor.
Definition int_divisor m := m%:~R : divisor.
Definition nat_divisor n := n%:R : divisor.
End Internals.
Module Import Exports.
Import Implementation Internals.
Notation algC := type.
Delimit Scope C_scope with C.
Delimit Scope C_core_scope with Cc.
Delimit Scope C_expanded_scope with Cx.
Open Scope C_core_scope.
Notation algCeq := (type : eqType).
Notation algCzmod := (type : zmodType).
Notation algCnzRing := (type : nzRingType).
#[deprecated(since="mathcomp 2.4.0",
note="Use algCnzRing instead.")]
Notation algCring := (type : nzRingType).
Notation algCuring := (type : unitRingType).
Notation algCnum := (type : numDomainType).
Notation algCfield := (type : fieldType).
Notation algCnumField := (type : numFieldType).
Notation algCnumClosedField := (type : numClosedFieldType).
Notation Creal := (@Num.Def.Rreal algCnum).
Definition getCrat := let: GetCrat_spec CtoQ _ := getCrat_subproof in CtoQ.
Definition Crat : {pred algC} := fun x => ratr (getCrat x) == x.
Definition minCpoly x : {poly algC} :=
let: exist2 p _ _ := minCpoly_subproof x in map_poly ratr p.
Coercion nat_divisor : nat >-> divisor.
Coercion int_divisor : int >-> divisor.
Coercion algC_divisor : algC >-> divisor.
Lemma nCdivE (p : nat) : p = p%:R :> divisor. Proof. by []. Qed.
Lemma zCdivE (p : int) : p = p%:~R :> divisor. Proof. by []. Qed.
Definition CdivE := (nCdivE, zCdivE).
Definition dvdC (x : divisor) : {pred algC} :=
fun y => if x == 0 then y == 0 else y / x \in Num.int.
Notation "x %| y" := (y \in dvdC x) : C_expanded_scope.
Notation "x %| y" := (@in_mem divisor y (mem (dvdC x))) : C_scope.
Definition eqCmod (e x y : divisor) := (e %| x - y)%C.
Notation "x == y %[mod e ]" := (eqCmod e x y) : C_scope.
Notation "x != y %[mod e ]" := (~~ (x == y %[mod e])%C) : C_scope.
End Exports.
Module HBExports. HB.reexport. End HBExports.
End Algebraics.
Export Algebraics.Exports.
Export Algebraics.HBExports.
Section AlgebraicsTheory.
Implicit Types (x y z : algC) (n : nat) (m : int) (b : bool).
Import Algebraics.Internals.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation CtoQ := getCrat.
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Let intr_inj_ZtoC := (intr_inj : injective ZtoC).
#[local] Hint Resolve intr_inj_ZtoC : core.
(* Specialization of a few basic ssrnum order lemmas. *)
Definition eqC_nat n p : (n%:R == p%:R :> algC) = (n == p) := eqr_nat _ n p.
Definition leC_nat n p : (n%:R <= p%:R :> algC) = (n <= p)%N := ler_nat _ n p.
Definition ltC_nat n p : (n%:R < p%:R :> algC) = (n < p)%N := ltr_nat _ n p.
Definition Cpchar : [pchar algC] =i pred0 := @pchar_num _.
(* This can be used in the converse direction to evaluate assertions over *)
(* manifest rationals, such as 3^-1 + 7%:%^-1 < 2%:%^-1 :> algC. *)
(* Missing norm and integer exponent, due to gaps in ssrint and rat. *)
Definition CratrE :=
let CnF : numClosedFieldType := algC in
let QtoCm : {rmorphism _ -> _} := @ratr CnF in
((rmorph0 QtoCm, rmorph1 QtoCm, rmorphMn QtoCm, rmorphN QtoCm, rmorphD QtoCm),
(rmorphM QtoCm, rmorphXn QtoCm, fmorphV QtoCm),
(rmorphMz QtoCm, rmorphXz QtoCm, @ratr_norm CnF, @ratr_sg CnF),
=^~ (@ler_rat CnF, @ltr_rat CnF, (inj_eq (fmorph_inj QtoCm)))).
Definition CintrE :=
let CnF : numClosedFieldType := algC in
let ZtoCm : {rmorphism _ -> _} := *~%R (1 : CnF) in
((rmorph0 ZtoCm, rmorph1 ZtoCm, rmorphMn ZtoCm, rmorphN ZtoCm, rmorphD ZtoCm),
(rmorphM ZtoCm, rmorphXn ZtoCm),
(rmorphMz ZtoCm, @intr_norm CnF, @intr_sg CnF),
=^~ (@ler_int CnF, @ltr_int CnF, (inj_eq (@intr_inj CnF)))).
Let nz2 : 2 != 0 :> algC.
Proof. by rewrite pnatr_eq0. Qed.
(* Conjugation and norm. *)
Definition algC_algebraic x := Algebraics.Implementation.algebraic x.
(* Real number subset. *)
Lemma algCrect x : x = 'Re x + 'i * 'Im x.
Proof. by rewrite [LHS]Crect. Qed.
Lemma algCreal_Re x : 'Re x \is Creal.
Proof. by rewrite Creal_Re. Qed.
Lemma algCreal_Im x : 'Im x \is Creal.
Proof. by rewrite Creal_Im. Qed.
Hint Resolve algCreal_Re algCreal_Im : core.
(* Integer divisibility. *)
Lemma dvdCP x y : reflect (exists2 z, z \in Num.int & y = z * x) (x %| y)%C.
Proof.
rewrite unfold_in; have [-> | nz_x] := eqVneq.
by apply: (iffP eqP) => [-> | [z _ ->]]; first exists 0; rewrite ?mulr0.
apply: (iffP idP) => [Zyx | [z Zz ->]]; last by rewrite mulfK.
by exists (y / x); rewrite ?divfK.
Qed.
Lemma dvdCP_nat x y : 0 <= x -> 0 <= y -> (x %| y)%C -> {n | y = n%:R * x}.
Proof.
move=> x_ge0 y_ge0 x_dv_y; apply: sig_eqW.
case/dvdCP: x_dv_y => z Zz -> in y_ge0 *; move: x_ge0 y_ge0 Zz.
rewrite le_eqVlt => /predU1P[<- | ]; first by exists 22%N; rewrite !mulr0.
by move=> /pmulr_lge0-> /intrEge0-> /natrP[n ->]; exists n.
Qed.
Lemma dvdC0 x : (x %| 0)%C.
Proof. by apply/dvdCP; exists 0; rewrite ?mul0r. Qed.
Lemma dvd0C x : (0 %| x)%C = (x == 0).
Proof. by rewrite unfold_in eqxx. Qed.
Lemma dvdC_mull x y z : y \in Num.int -> (x %| z)%C -> (x %| y * z)%C.
Proof.
move=> Zy /dvdCP[m Zm ->]; apply/dvdCP.
by exists (y * m); rewrite ?mulrA ?rpredM.
Qed.
Lemma dvdC_mulr x y z : y \in Num.int -> (x %| z)%C -> (x %| z * y)%C.
Proof. by rewrite mulrC; apply: dvdC_mull. Qed.
Lemma dvdC_mul2r x y z : y != 0 -> (x * y %| z * y)%C = (x %| z)%C.
Proof.
move=> nz_y; rewrite !unfold_in !(mulIr_eq0 _ (mulIf nz_y)).
by rewrite mulrAC invfM mulrA divfK.
Qed.
Lemma dvdC_mul2l x y z : y != 0 -> (y * x %| y * z)%C = (x %| z)%C.
Proof. by rewrite !(mulrC y); apply: dvdC_mul2r. Qed.
Lemma dvdC_trans x y z : (x %| y)%C -> (y %| z)%C -> (x %| z)%C.
Proof. by move=> x_dv_y /dvdCP[m Zm ->]; apply: dvdC_mull. Qed.
Lemma dvdC_refl x : (x %| x)%C.
Proof. by apply/dvdCP; exists 1; rewrite ?mul1r. Qed.
Hint Resolve dvdC_refl : core.
Lemma dvdC_zmod x : zmod_closed (dvdC x).
Proof.
split=> [| _ _ /dvdCP[y Zy ->] /dvdCP[z Zz ->]]; first exact: dvdC0.
by rewrite -mulrBl dvdC_mull ?rpredB.
Qed.
HB.instance Definition _ x := GRing.isZmodClosed.Build _ (dvdC x) (dvdC_zmod x).
Lemma dvdC_nat (p n : nat) : (p %| n)%C = (p %| n)%N.
Proof.
rewrite unfold_in intrEge0 ?divr_ge0 ?invr_ge0 ?ler0n // !pnatr_eq0.
have [-> | nz_p] := eqVneq; first by rewrite dvd0n.
apply/natrP/dvdnP=> [[q def_q] | [q ->]]; exists q.
by apply/eqP; rewrite -eqC_nat natrM -def_q divfK ?pnatr_eq0.
by rewrite [num in num / _]natrM mulfK ?pnatr_eq0.
Qed.
Lemma dvdC_int (p : nat) x :
x \in Num.int -> (p %| x)%C = (p %| `|Num.floor x|)%N.
Proof.
move=> Zx; rewrite -{1}(floorK Zx) {1}[Num.floor x]intEsign.
by rewrite rmorphMsign rpredMsign dvdC_nat.
Qed.
(* Elementary modular arithmetic. *)
Lemma eqCmod_refl e x : (x == x %[mod e])%C.
Proof. by rewrite /eqCmod subrr rpred0. Qed.
Lemma eqCmodm0 e : (e == 0 %[mod e])%C. Proof. by rewrite /eqCmod subr0. Qed.
Hint Resolve eqCmod_refl eqCmodm0 : core.
Lemma eqCmod0 e x : (x == 0 %[mod e])%C = (e %| x)%C.
Proof. by rewrite /eqCmod subr0. Qed.
Lemma eqCmod_sym e x y : ((x == y %[mod e]) = (y == x %[mod e]))%C.
Proof. by rewrite /eqCmod -opprB rpredN. Qed.
Lemma eqCmod_trans e y x z :
(x == y %[mod e] -> y == z %[mod e] -> x == z %[mod e])%C.
Proof.
by move=> Exy Eyz; rewrite /eqCmod -[x](subrK y) -[_ - z]addrA rpredD.
Qed.
Lemma eqCmod_transl e x y z :
(x == y %[mod e])%C -> (x == z %[mod e])%C = (y == z %[mod e])%C.
Proof. by move/(sym_left_transitive (eqCmod_sym e) (@eqCmod_trans e)). Qed.
Lemma eqCmod_transr e x y z :
(x == y %[mod e])%C -> (z == x %[mod e])%C = (z == y %[mod e])%C.
Proof. by move/(sym_right_transitive (eqCmod_sym e) (@eqCmod_trans e)). Qed.
Lemma eqCmodN e x y : (- x == y %[mod e])%C = (x == - y %[mod e])%C.
Proof. by rewrite eqCmod_sym /eqCmod !opprK addrC. Qed.
Lemma eqCmodDr e x y z : (y + x == z + x %[mod e])%C = (y == z %[mod e])%C.
Proof. by rewrite /eqCmod addrAC opprD !addrA subrK. Qed.
Lemma eqCmodDl e x y z : (x + y == x + z %[mod e])%C = (y == z %[mod e])%C.
Proof. by rewrite !(addrC x) eqCmodDr. Qed.
Lemma eqCmodD e x1 x2 y1 y2 :
(x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 + y1 == x2 + y2 %[mod e])%C.
Proof.
by rewrite -(eqCmodDl e x2 y1) -(eqCmodDr e y1); apply: eqCmod_trans.
Qed.
Lemma eqCmod_nat (e m n : nat) : (m == n %[mod e])%C = (m == n %[mod e]).
Proof.
without loss lenm: m n / (n <= m)%N.
by move=> IH; case/orP: (leq_total m n) => /IH //; rewrite eqCmod_sym eq_sym.
by rewrite /eqCmod -natrB // dvdC_nat eqn_mod_dvd.
Qed.
Lemma eqCmod0_nat (e m : nat) : (m == 0 %[mod e])%C = (e %| m)%N.
Proof. by rewrite eqCmod0 dvdC_nat. Qed.
Lemma eqCmodMr e :
{in Num.int, forall z x y, x == y %[mod e] -> x * z == y * z %[mod e]}%C.
Proof. by move=> z Zz x y; rewrite /eqCmod -mulrBl => /dvdC_mulr->. Qed.
Lemma eqCmodMl e :
{in Num.int, forall z x y, x == y %[mod e] -> z * x == z * y %[mod e]}%C.
Proof. by move=> z Zz x y Exy; rewrite !(mulrC z) eqCmodMr. Qed.
Lemma eqCmodMl0 e : {in Num.int, forall x, x * e == 0 %[mod e]}%C.
Proof. by move=> x Zx; rewrite -(mulr0 x) eqCmodMl. Qed.
Lemma eqCmodMr0 e : {in Num.int, forall x, e * x == 0 %[mod e]}%C.
Proof. by move=> x Zx; rewrite /= mulrC eqCmodMl0. Qed.
Lemma eqCmod_addl_mul e : {in Num.int, forall x y, x * e + y == y %[mod e]}%C.
Proof. by move=> x Zx y; rewrite -{2}[y]add0r eqCmodDr eqCmodMl0. Qed.
Lemma eqCmodM e : {in Num.int & Num.int, forall x1 y2 x2 y1,
x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 * y1 == x2 * y2 %[mod e]}%C.
Proof.
move=> x1 y2 Zx1 Zy2 x2 y1 eq_x /(eqCmodMl Zx1)/eqCmod_trans-> //.
exact: eqCmodMr.
Qed.
(* Rational number subset. *)
Lemma ratCK : cancel QtoC CtoQ.
Proof. by rewrite /getCrat; case: getCrat_subproof. Qed.
Lemma getCratK : {in Crat, cancel CtoQ QtoC}.
Proof. by move=> x /eqP. Qed.
Lemma Crat_rat (a : rat) : QtoC a \in Crat.
Proof. by rewrite unfold_in ratCK. Qed.
Lemma CratP x : reflect (exists a, x = QtoC a) (x \in Crat).
Proof.
by apply: (iffP eqP) => [<- | [a ->]]; [exists (CtoQ x) | rewrite ratCK].
Qed.
Lemma Crat0 : 0 \in Crat. Proof. by apply/CratP; exists 0; rewrite rmorph0. Qed.
Lemma Crat1 : 1 \in Crat. Proof. by apply/CratP; exists 1; rewrite rmorph1. Qed.
#[local] Hint Resolve Crat0 Crat1 : core.
Fact Crat_divring_closed : divring_closed Crat.
Proof.
split=> // _ _ /CratP[x ->] /CratP[y ->].
by rewrite -rmorphB Crat_rat.
by rewrite -fmorph_div Crat_rat.
Qed.
HB.instance Definition _ := GRing.isDivringClosed.Build _ Crat
Crat_divring_closed.
Lemma rpred_Crat (S : divringClosed algC) : {subset Crat <= S}.
Proof. by move=> _ /CratP[a ->]; apply: rpred_rat. Qed.
Lemma conj_Crat z : z \in Crat -> z^* = z.
Proof. by move/getCratK <-; rewrite fmorph_div !rmorph_int. Qed.
Lemma Creal_Crat : {subset Crat <= Creal}.
Proof. by move=> x /conj_Crat/CrealP. Qed.
Lemma Cint_rat a : (QtoC a \in Num.int) = (a \in Num.int).
Proof.
apply/idP/idP=> [Za | /numqK <-]; last by rewrite rmorph_int.
apply/intrP; exists (Num.floor (QtoC a)); apply: (can_inj ratCK).
by rewrite rmorph_int floorK.
Qed.
Lemma minCpolyP x :
{p : {poly rat} | minCpoly x = pQtoC p /\ p \is monic
& forall q, root (pQtoC q) x = (p %| q)%R}.
Proof. by rewrite /minCpoly; case: (minCpoly_subproof x) => p; exists p. Qed.
Lemma minCpoly_monic x : minCpoly x \is monic.
Proof. by have [p [-> mon_p] _] := minCpolyP x; rewrite map_monic. Qed.
Lemma minCpoly_eq0 x : (minCpoly x == 0) = false.
Proof. exact/negbTE/monic_neq0/minCpoly_monic. Qed.
Lemma root_minCpoly x : root (minCpoly x) x.
Proof. by have [p [-> _] ->] := minCpolyP x. Qed.
Lemma size_minCpoly x : (1 < size (minCpoly x))%N.
Proof. by apply: root_size_gt1 (root_minCpoly x); rewrite ?minCpoly_eq0. Qed.
(* Basic properties of automorphisms. *)
Section AutC.
Implicit Type nu : {rmorphism algC -> algC}.
Lemma aut_Crat nu : {in Crat, nu =1 id}.
Proof. by move=> _ /CratP[a ->]; apply: fmorph_rat. Qed.
Lemma Crat_aut nu x : (nu x \in Crat) = (x \in Crat).
Proof.
apply/idP/idP=> /CratP[a] => [|->]; last by rewrite fmorph_rat Crat_rat.
by rewrite -(fmorph_rat nu) => /fmorph_inj->; apply: Crat_rat.
Qed.
Lemma algC_invaut_subproof nu x : {y | nu y = x}.
Proof.
have [r Dp] := closed_field_poly_normal (minCpoly x).
suffices /mapP/sig2_eqW[y _ ->]: x \in map nu r by exists y.
rewrite -root_prod_XsubC; congr (root _ x): (root_minCpoly x).
have [q [Dq _] _] := minCpolyP x; rewrite Dq -(eq_map_poly (fmorph_rat nu)).
rewrite (map_poly_comp nu) -{q}Dq Dp (monicP (minCpoly_monic x)) scale1r.
rewrite rmorph_prod big_map /=; apply: eq_bigr => z _.
by rewrite rmorphB /= map_polyX map_polyC.
Qed.
Definition algC_invaut nu x := sval (algC_invaut_subproof nu x).
Lemma algC_invautK nu : cancel (algC_invaut nu) nu.
Proof. by move=> x; rewrite /algC_invaut; case: algC_invaut_subproof. Qed.
Lemma algC_autK nu : cancel nu (algC_invaut nu).
Proof. exact: inj_can_sym (algC_invautK nu) (fmorph_inj nu). Qed.
Fact algC_invaut_is_zmod_morphism nu : zmod_morphism (algC_invaut nu).
Proof. exact: can2_zmod_morphism (algC_autK nu) (algC_invautK nu). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algC_invaut_is_zmod_morphism` instead")]
Definition algC_invaut_is_additive := algC_invaut_is_zmod_morphism.
Fact algC_invaut_is_monoid_morphism nu : monoid_morphism (algC_invaut nu).
Proof. exact: can2_monoid_morphism (algC_autK nu) (algC_invautK nu). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algC_invaut_is_monoid_morphism` instead")]
Definition algC_invaut_is_multiplicative nu :=
(fun g => (g.2,g.1)) (algC_invaut_is_monoid_morphism nu).
HB.instance Definition _ (nu : {rmorphism algC -> algC}) :=
GRing.isZmodMorphism.Build algC algC (algC_invaut nu)
(algC_invaut_is_zmod_morphism nu).
HB.instance Definition _ (nu : {rmorphism algC -> algC}) :=
GRing.isMonoidMorphism.Build algC algC (algC_invaut nu)
(algC_invaut_is_monoid_morphism nu).
Lemma minCpoly_aut nu x : minCpoly (nu x) = minCpoly x.
Proof.
wlog suffices dvd_nu: nu x / (minCpoly x %| minCpoly (nu x))%R.
apply/eqP; rewrite -eqp_monic ?minCpoly_monic //; apply/andP; split=> //.
by rewrite -{2}(algC_autK nu x) dvd_nu.
have [[q [Dq _] min_q] [q1 [Dq1 _] _]] := (minCpolyP x, minCpolyP (nu x)).
rewrite Dq Dq1 dvdp_map -min_q -(fmorph_root nu) -map_poly_comp.
by rewrite (eq_map_poly (fmorph_rat nu)) -Dq1 root_minCpoly.
Qed.
End AutC.
End AlgebraicsTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use Cpchar instead.")]
Notation Cchar := (Cpchar) (only parsing).
#[global] Hint Resolve Crat0 Crat1 dvdC0 dvdC_refl eqCmod_refl eqCmodm0 : core.
Local Notation "p ^^ f" := (map_poly f p)
(at level 30, f at level 30, format "p ^^ f").
Record algR := in_algR {algRval :> algC; algRvalP : algRval \is Creal}.
HB.instance Definition _ := [isSub for algRval].
HB.instance Definition _ := [Countable of algR by <:].
HB.instance Definition _ := [SubChoice_isSubIntegralDomain of algR by <:].
HB.instance Definition _ := [SubIntegralDomain_isSubField of algR by <:].
HB.instance Definition _ : Order.isPOrder ring_display algR :=
Order.CancelPartial.Pcan _ valK.
Lemma total_algR : total (<=%O : rel (algR : porderType _)).
Proof. by move=> x y; apply/real_leVge/valP/valP. Qed.
HB.instance Definition _ := Order.POrder_isTotal.Build _ algR total_algR.
Lemma algRval_is_zmod_morphism : zmod_morphism algRval. Proof. by []. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algRval_is_zmod_morphism` instead")]
Definition algRval_is_additive := algRval_is_zmod_morphism.
Lemma algRval_is_monoid_morphism : monoid_morphism algRval. Proof. by []. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algRval_is_monoid_morphism` instead")]
Definition algRval_is_multiplicative :=
(fun g => (g.2,g.1)) algRval_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build algR algC algRval
algRval_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build algR algC algRval
algRval_is_monoid_morphism.
Definition algR_norm (x : algR) : algR := in_algR (normr_real (val x)).
Lemma algR_ler_normD x y : algR_norm (x + y) <= (algR_norm x + algR_norm y).
Proof. exact: ler_normD. Qed.
Lemma algR_normr0_eq0 x : algR_norm x = 0 -> x = 0.
Proof. by move=> /(congr1 val)/normr0_eq0 ?; apply/val_inj. Qed.
Lemma algR_normrMn x n : algR_norm (x *+ n) = algR_norm x *+ n.
Proof. by apply/val_inj; rewrite /= !rmorphMn/= normrMn. Qed.
Lemma algR_normrN x : algR_norm (- x) = algR_norm x.
Proof. by apply/val_inj; apply: normrN. Qed.
Section Num.
Section withz.
Let z : algR := 0.
Lemma algR_addr_gt0 (x y : algR) : z < x -> z < y -> z < x + y.
Proof. exact: addr_gt0. Qed.
Lemma algR_ger_leVge (x y : algR) : z <= x -> z <= y -> (x <= y) || (y <= x).
Proof. exact: ger_leVge. Qed.
Lemma algR_normrM : {morph algR_norm : x y / x * y}.
Proof. by move=> *; apply/val_inj; apply: normrM. Qed.
Lemma algR_ler_def (x y : algR) : (x <= y) = (algR_norm (y - x) == y - x).
Proof. by apply: ler_def. Qed.
End withz.
HB.instance Definition _ := Num.Zmodule_isNormed.Build _ algR
algR_ler_normD algR_normr0_eq0 algR_normrMn algR_normrN.
HB.instance Definition _ := Num.isNumRing.Build algR
algR_addr_gt0 algR_ger_leVge algR_normrM algR_ler_def.
End Num.
Definition algR_archiFieldMixin : Num.archimedean_axiom algR.
Proof.
move=> /= x; have := real_floorD1_gt (valP `|x|).
set n := Num.floor _ + 1 => x_lt.
exists (`|(n + 1)%R|%N); apply: (lt_le_trans x_lt _).
by rewrite /= rmorphMn/= pmulrn ler_int (le_trans _ (lez_abs _))// lerDl.
Qed.
HB.instance Definition _ := Num.NumDomain_bounded_isArchimedean.Build algR
algR_archiFieldMixin.
Definition algR_pfactor (x : algC) : {poly algR} :=
if x \is Creal =P true is ReflectT xR then 'X - (in_algR xR)%:P else
'X^2 - (in_algR (Creal_Re x) *+ 2) *: 'X + ((in_algR (normr_real x))^+2)%:P.
Notation algC_pfactor x := (algR_pfactor x ^^ algRval).
Lemma algR_pfactorRE (x : algC) (xR : x \is Creal) :
algR_pfactor x = 'X - (in_algR xR)%:P.
Proof.
rewrite /algR_pfactor; case: eqP xR => //= p1 p2.
by rewrite (bool_irrelevance p1 p2).
Qed.
Lemma algC_pfactorRE (x : algC) : x \is Creal ->
algC_pfactor x = 'X - x%:P.
Proof. by move=> xR; rewrite algR_pfactorRE map_polyXsubC. Qed.
Lemma algR_pfactorCE (x : algC) : x \isn't Creal ->
algR_pfactor x =
'X^2 - (in_algR (Creal_Re x) *+ 2) *: 'X + ((in_algR (normr_real x))^+2)%:P.
Proof. by rewrite /algR_pfactor; case: eqP => // p; rewrite p. Qed.
Lemma algC_pfactorCE (x : algC) : x \isn't Creal ->
algC_pfactor x = ('X - x%:P) * ('X - x^*%:P).
Proof.
move=> xNR; rewrite algR_pfactorCE//=.
rewrite rmorphD /= rmorphB/= !map_polyZ !map_polyXn/= map_polyX.
rewrite (map_polyC algRval)/=.
rewrite mulrBl !mulrBr -!addrA; congr (_ + _).
rewrite opprD addrA opprK -opprD -rmorphM/= -normCK; congr (- _ + _).
rewrite mulrC !mul_polyC -scalerDl.
rewrite [x in RHS]algCrect conjC_rect ?Creal_Re ?Creal_Im//.
by rewrite addrACA addNr addr0.
Qed.
Lemma algC_pfactorE x :
algC_pfactor x = ('X - x%:P) * ('X - x^*%:P) ^+ (x \isn't Creal).
Proof.
by have [/algC_pfactorRE|/algC_pfactorCE] := boolP (_ \is _); rewrite ?mulr1.
Qed.
Lemma size_algC_pfactor x : size (algC_pfactor x) = (x \isn't Creal).+2.
Proof.
have [xR|xNR] := boolP (_ \is _); first by rewrite algC_pfactorRE// size_XsubC.
by rewrite algC_pfactorCE// size_mul ?size_XsubC ?polyXsubC_eq0.
Qed.
Lemma size_algR_pfactor x : size (algR_pfactor x) = (x \isn't Creal).+2.
Proof. by have := size_algC_pfactor x; rewrite size_map_poly. Qed.
Lemma algC_pfactor_eq0 x : (algC_pfactor x == 0) = false.
Proof. by rewrite -size_poly_eq0 size_algC_pfactor. Qed.
Lemma algR_pfactor_eq0 x : (algR_pfactor x == 0) = false.
Proof. by rewrite -size_poly_eq0 size_algR_pfactor. Qed.
Lemma algC_pfactorCgt0 x y : x \isn't Creal -> y \is Creal ->
(algC_pfactor x).[y] > 0.
Proof.
move=> xNR yR; rewrite algC_pfactorCE// hornerM !hornerXsubC.
rewrite [x]algCrect conjC_rect ?Creal_Re ?Creal_Im// !opprD !addrA opprK.
rewrite -subr_sqr exprMn sqrCi mulN1r opprK ltr_wpDl//.
- by rewrite real_exprn_even_ge0// ?rpredB// ?Creal_Re.
by rewrite real_exprn_even_gt0 ?Creal_Im ?orTb//=; apply/eqP/Creal_ImP.
Qed.
Lemma algR_pfactorR_mul_gt0 (x a b : algC) :
x \is Creal -> a \is Creal -> b \is Creal ->
a <= b ->
((algC_pfactor x).[a] * (algC_pfactor x).[b] <= 0) =
(a <= x <= b).
Proof.
move=> xR aR bR ab; rewrite !algC_pfactorRE// !hornerXsubC.
have [lt_xa|lt_ax|->]/= := real_ltgtP xR aR; last first.
- by rewrite subrr mul0r lexx ab.
- by rewrite nmulr_rle0 ?subr_lt0 ?subr_ge0.
rewrite pmulr_rle0 ?subr_gt0// subr_le0.
by apply: negbTE; rewrite -real_ltNge// (lt_le_trans lt_xa).
Qed.
Lemma monic_algC_pfactor x : algC_pfactor x \is monic.
Proof. by rewrite algC_pfactorE rpredM ?rpredX ?monicXsubC. Qed.
Lemma monic_algR_pfactor x : algR_pfactor x \is monic.
Proof. by have := monic_algC_pfactor x; rewrite map_monic. Qed.
Lemma poly_algR_pfactor (p : {poly algR}) :
{ r : seq algC |
p ^^ algRval = val (lead_coef p) *: \prod_(z <- r) algC_pfactor z }.
Proof.
wlog p_monic : p / p \is monic => [hwlog|].
have [->|pN0] := eqVneq p 0.
by exists [::]; rewrite lead_coef0/= rmorph0 scale0r.
have [|r] := hwlog ((lead_coef p)^-1 *: p).
by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0//.
rewrite !lead_coefZ mulVf ?lead_coef_eq0//= scale1r.
rewrite map_polyZ/= => /(canRL (scalerKV _))->; first by exists r.
by rewrite fmorph_eq0 lead_coef_eq0.
suff: {r : seq algC | p ^^ algRval = \prod_(z <- r) algC_pfactor z}.
by move=> [r rP]; exists r; rewrite rP (monicP _)// scale1r.
have [/= r pr] := closed_field_poly_normal (p ^^ algRval).
rewrite (monicP _) ?monic_map ?scale1r// {p_monic} in pr *.
have [n] := ubnP (size r).
elim: n r => // n IHn [|x r]/= in p pr *.
by exists [::]; rewrite pr !big_nil.
rewrite ltnS => r_lt.
have xJxr : x^* \in x :: r.
rewrite -root_prod_XsubC -pr.
have /eq_map_poly-> : algRval =1 Num.conj_op \o algRval.
by move=> a /=; rewrite (CrealP (algRvalP _)).
by rewrite map_poly_comp mapf_root pr root_prod_XsubC mem_head.
have xJr : (x \isn't Creal) ==> (x^* \in r) by rewrite implyNb CrealE.
have pxdvdC : algC_pfactor x %| p ^^ algRval.
rewrite pr algC_pfactorE big_cons/= dvdp_mul2l ?polyXsubC_eq0//.
by case: (_ \is _) xJr; rewrite ?dvd1p// dvdp_XsubCl root_prod_XsubC.
pose pr'x := p %/ algR_pfactor x.
have [||r'] := IHn (if x \is Creal then r else rem x^* r) pr'x; last 2 first.
- by case: (_ \is _) in xJr *; rewrite ?size_rem// (leq_ltn_trans (leq_pred _)).
- move=> /eqP; rewrite map_divp -dvdp_eq_mul ?algC_pfactor_eq0//= => /eqP->.
by exists (x :: r'); rewrite big_cons mulrC.
rewrite map_divp/= pr big_cons algC_pfactorE/=.
rewrite divp_pmul2l ?expf_neq0 ?polyXsubC_eq0//.
case: (_ \is _) => /= in xJr *; first by rewrite divp1//.
by rewrite (big_rem _ xJr)/= mulKp ?polyXsubC_eq0.
Qed.
Definition algR_rcfMixin : Num.real_closed_axiom algR.
Proof.
move=> p a b le_ab /andP[pa_le0 pb_ge0]/=.
case: ltgtP pa_le0 => //= pa0 _; last first.
by exists a; rewrite ?lexx// rootE pa0.
case: ltgtP pb_ge0 => //= pb0 _; last first.
by exists b; rewrite ?lexx ?andbT// rootE -pb0.
have p_neq0 : p != 0 by apply: contraTneq pa0 => ->; rewrite horner0 ltxx.
have {pa0 pb0} pab0 : p.[a] * p.[b] < 0 by rewrite pmulr_llt0.
wlog p_monic : p p_neq0 pab0 / p \is monic => [hwlog|].
have [|||x axb] := hwlog ((lead_coef p)^-1 *: p).
- by rewrite scaler_eq0 invr_eq0 lead_coef_eq0 (negPf p_neq0).
- rewrite !hornerE/= -mulrA mulrACA -expr2 pmulr_rlt0//.
by rewrite exprn_even_gt0//= invr_eq0 lead_coef_eq0.
- by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0 ?eqxx.
by rewrite rootZ ?invr_eq0 ?lead_coef_eq0//; exists x.
have /= [rs prs] := poly_algR_pfactor p.
rewrite (monicP _) ?monic_map// scale1r {p_monic} in prs.
pose ab := [pred x | val a <= x <= val b].
have abR : {subset ab <= Creal}.
move=> x /andP[+ _].
by rewrite -subr_ge0 => /ger0_real; rewrite rpredBr// algRvalP.
wlog : p pab0 {p_neq0 prs} /
p ^^ algRval = \prod_(x <- rs | x \in ab) ('X - x%:P) => [hw|].
move: prs; rewrite -!rmorph_prod => /map_poly_inj.
rewrite (bigID ab)/=; set q := (X in X * _); set u := (X in _ * X) => pqu.
have [||] := hw q; last first.
- by move=> x; exists x => //; rewrite pqu rootM q0.
- by rewrite rmorph_prod/=; under eq_bigr do rewrite algC_pfactorRE ?abR//.
have := pab0; rewrite pqu !hornerM mulrACA [_ * _ * _ < 0]pmulr_llt0//.
rewrite !horner_prod -big_split/= prodr_gt0// => x.
have [xR|xNR] := boolP (x \is Creal); last first.
rewrite (_ : (0 < ?[a]) = (algRval 0 < algRval ?a))//=.
by rewrite -!horner_map/= mulr_gt0 ?algC_pfactorCgt0 ?algRvalP.
apply: contraNT; rewrite -leNgt.
rewrite (_ : (?[a] <= 0) = (algRval ?a <= algRval 0))//= -!horner_map/=.
by rewrite algR_pfactorR_mul_gt0 ?algRvalP.
rewrite -big_filter; have := filter_all ab rs.
set rsab := filter _ _.
have: all (mem Creal) rsab.
by apply/allP => x; rewrite mem_filter => /andP[/abR].
case: rsab => [_ _|x rsab]/=; rewrite (big_nil, big_cons).
move=> pval1; move: pab0.
have /map_poly_inj-> : p ^^ algRval = 1 ^^ algRval by rewrite rmorph1.
by rewrite !hornerE ltr10.
move=> /andP[xR rsabR] /andP[axb arsb] prsab.
exists (in_algR xR) => //=.
by rewrite -(mapf_root algRval)//= prsab rootM root_XsubC eqxx.
Qed.
HB.instance Definition _ := Num.RealField_isClosed.Build algR algR_rcfMixin.
|
Basic.lean
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.BigOperators.Finprod
import Mathlib.Algebra.GroupWithZero.Action.Defs
import Mathlib.Algebra.GroupWithZero.NonZeroDivisors
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
import Mathlib.Algebra.Ring.GeomSum
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Data.Nat.Lattice
import Mathlib.RingTheory.Nilpotent.Defs
/-!
# Nilpotent elements
This file develops the basic theory of nilpotent elements. In particular it shows that the
nilpotent elements are closed under many operations.
For the definition of `nilradical`, see `Mathlib/RingTheory/Nilpotent/Lemmas.lean`.
## Main definitions
* `isNilpotent_neg_iff`
* `Commute.isNilpotent_add`
* `Commute.isNilpotent_sub`
-/
universe u v
open Function Set
variable {R S : Type*} {x y : R}
theorem IsNilpotent.neg [Ring R] (h : IsNilpotent x) : IsNilpotent (-x) := by
obtain ⟨n, hn⟩ := h
use n
rw [neg_pow, hn, mul_zero]
@[simp]
theorem isNilpotent_neg_iff [Ring R] : IsNilpotent (-x) ↔ IsNilpotent x :=
⟨fun h => neg_neg x ▸ h.neg, fun h => h.neg⟩
lemma IsNilpotent.smul [MonoidWithZero R] [MonoidWithZero S] [MulActionWithZero R S]
[SMulCommClass R S S] [IsScalarTower R S S] {a : S} (ha : IsNilpotent a) (t : R) :
IsNilpotent (t • a) := by
obtain ⟨k, ha⟩ := ha
use k
rw [smul_pow, ha, smul_zero]
theorem IsNilpotent.isUnit_sub_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r - 1) := by
obtain ⟨n, hn⟩ := hnil
refine ⟨⟨r - 1, -∑ i ∈ Finset.range n, r ^ i, ?_, ?_⟩, rfl⟩
· simp [mul_geom_sum, hn]
· simp [geom_sum_mul, hn]
theorem IsNilpotent.isUnit_one_sub [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 - r) := by
rw [← IsUnit.neg_iff, neg_sub]
exact isUnit_sub_one hnil
theorem IsNilpotent.isUnit_add_one [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (r + 1) := by
rw [← IsUnit.neg_iff, neg_add']
exact isUnit_sub_one hnil.neg
theorem IsNilpotent.isUnit_one_add [Ring R] {r : R} (hnil : IsNilpotent r) : IsUnit (1 + r) :=
add_comm r 1 ▸ isUnit_add_one hnil
theorem IsNilpotent.isUnit_add_left_of_commute [Ring R] {r u : R}
(hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) :
IsUnit (u + r) := by
rw [← Units.isUnit_mul_units _ hu.unit⁻¹, add_mul, IsUnit.mul_val_inv]
replace h_comm : Commute r (↑hu.unit⁻¹) := Commute.units_inv_right h_comm
refine IsNilpotent.isUnit_one_add ?_
exact (hu.unit⁻¹.isUnit.isNilpotent_mul_unit_of_commute_iff h_comm).mpr hnil
theorem IsNilpotent.isUnit_add_right_of_commute [Ring R] {r u : R}
(hnil : IsNilpotent r) (hu : IsUnit u) (h_comm : Commute r u) :
IsUnit (r + u) :=
add_comm r u ▸ hnil.isUnit_add_left_of_commute hu h_comm
lemma IsUnit.not_isNilpotent [Ring R] [Nontrivial R] {x : R} (hx : IsUnit x) :
¬ IsNilpotent x := by
intro H
simpa using H.isUnit_add_right_of_commute hx.neg (by simp)
lemma IsNilpotent.not_isUnit [Ring R] [Nontrivial R] {x : R} (hx : IsNilpotent x) :
¬ IsUnit x :=
mt IsUnit.not_isNilpotent (by simpa only [not_not] using hx)
lemma IsIdempotentElem.eq_zero_of_isNilpotent [MonoidWithZero R] {e : R}
(idem : IsIdempotentElem e) (nilp : IsNilpotent e) : e = 0 := by
obtain ⟨rfl | n, hn⟩ := nilp
· rw [pow_zero] at hn; rw [← one_mul e, hn, zero_mul]
· rw [← hn, idem.pow_succ_eq]
alias IsNilpotent.eq_zero_of_isIdempotentElem := IsIdempotentElem.eq_zero_of_isNilpotent
instance [Zero R] [Pow R ℕ] [Zero S] [Pow S ℕ] [IsReduced R] [IsReduced S] : IsReduced (R × S) where
eq_zero _ := fun ⟨n, hn⟩ ↦ have hn := Prod.ext_iff.1 hn
Prod.ext (IsReduced.eq_zero _ ⟨n, hn.1⟩) (IsReduced.eq_zero _ ⟨n, hn.2⟩)
theorem Prime.isRadical [CommMonoidWithZero R] {y : R} (hy : Prime y) : IsRadical y :=
fun _ _ ↦ hy.dvd_of_dvd_pow
theorem zero_isRadical_iff [MonoidWithZero R] : IsRadical (0 : R) ↔ IsReduced R := by
simp_rw [isReduced_iff, IsNilpotent, exists_imp, ← zero_dvd_iff]
exact forall_swap
theorem isReduced_iff_pow_one_lt [MonoidWithZero R] (k : ℕ) (hk : 1 < k) :
IsReduced R ↔ ∀ x : R, x ^ k = 0 → x = 0 := by
simp_rw [← zero_isRadical_iff, isRadical_iff_pow_one_lt k hk, zero_dvd_iff]
theorem IsRadical.of_dvd [CancelCommMonoidWithZero R] {x y : R} (hy : IsRadical y) (h0 : y ≠ 0)
(hxy : x ∣ y) : IsRadical x := (isRadical_iff_pow_one_lt 2 one_lt_two).2 <| by
obtain ⟨z, rfl⟩ := hxy
refine fun w dvd ↦ ((mul_dvd_mul_iff_right <| right_ne_zero_of_mul h0).mp <| hy 2 _ ?_)
rw [mul_pow]
gcongr
exact dvd_pow_self _ two_ne_zero
namespace Commute
section Semiring
variable [Semiring R]
theorem add_pow_eq_zero_of_add_le_succ_of_pow_eq_zero (h_comm : Commute x y) {m n k : ℕ}
(hx : x ^ m = 0) (hy : y ^ n = 0) (h : m + n ≤ k + 1) :
(x + y) ^ k = 0 := by
rw [h_comm.add_pow']
apply Finset.sum_eq_zero
rintro ⟨i, j⟩ hij
suffices x ^ i * y ^ j = 0 by simp only [this, nsmul_eq_mul, mul_zero]
by_cases hi : m ≤ i
· rw [pow_eq_zero_of_le hi hx, zero_mul]
rw [pow_eq_zero_of_le ?_ hy, mul_zero]
linarith [Finset.mem_antidiagonal.mp hij]
theorem add_pow_add_eq_zero_of_pow_eq_zero (h_comm : Commute x y) {m n : ℕ}
(hx : x ^ m = 0) (hy : y ^ n = 0) :
(x + y) ^ (m + n - 1) = 0 :=
h_comm.add_pow_eq_zero_of_add_le_succ_of_pow_eq_zero hx hy <| by rw [← Nat.sub_le_iff_le_add]
theorem isNilpotent_add (h_comm : Commute x y) (hx : IsNilpotent x) (hy : IsNilpotent y) :
IsNilpotent (x + y) := by
obtain ⟨n, hn⟩ := hx
obtain ⟨m, hm⟩ := hy
exact ⟨_, add_pow_add_eq_zero_of_pow_eq_zero h_comm hn hm⟩
protected lemma isNilpotent_sum {ι : Type*} {s : Finset ι} {f : ι → R}
(hnp : ∀ i ∈ s, IsNilpotent (f i)) (h_comm : ∀ i j, i ∈ s → j ∈ s → Commute (f i) (f j)) :
IsNilpotent (∑ i ∈ s, f i) := by
classical
induction s using Finset.induction with
| empty => simp
| insert j s hj ih => ?_
rw [Finset.sum_insert hj]
apply Commute.isNilpotent_add
· exact Commute.sum_right _ _ _ (fun i hi ↦ h_comm _ _ (by simp) (by simp [hi]))
· apply hnp; simp
· exact ih (fun i hi ↦ hnp i (by simp [hi]))
(fun i j hi hj ↦ h_comm i j (by simp [hi]) (by simp [hj]))
theorem isNilpotent_finsum {ι : Type*} {f : ι → R}
(hf : ∀ b, IsNilpotent (f b)) (h_comm : ∀ i j, Commute (f i) (f j)) :
IsNilpotent (finsum f) := by
classical
by_cases h : Set.Finite f.support
· rw [finsum_def, dif_pos h]
exact Commute.isNilpotent_sum (fun b _ ↦ hf b) (fun _ _ _ _ ↦ h_comm _ _)
· simp only [finsum_def, dif_neg h, IsNilpotent.zero]
protected lemma isNilpotent_mul_right_iff (h_comm : Commute x y) (hy : y ∈ nonZeroDivisorsRight R) :
IsNilpotent (x * y) ↔ IsNilpotent x := by
refine ⟨?_, h_comm.isNilpotent_mul_right⟩
rintro ⟨k, hk⟩
rw [mul_pow h_comm] at hk
exact ⟨k, (nonZeroDivisorsRight R).pow_mem hy k _ hk⟩
protected lemma isNilpotent_mul_left_iff (h_comm : Commute x y) (hx : x ∈ nonZeroDivisorsLeft R) :
IsNilpotent (x * y) ↔ IsNilpotent y := by
refine ⟨?_, h_comm.isNilpotent_mul_left⟩
rintro ⟨k, hk⟩
rw [mul_pow h_comm] at hk
exact ⟨k, (nonZeroDivisorsLeft R).pow_mem hx k _ hk⟩
end Semiring
section Ring
variable [Ring R]
theorem isNilpotent_sub (h_comm : Commute x y) (hx : IsNilpotent x) (hy : IsNilpotent y) :
IsNilpotent (x - y) := by
rw [← neg_right_iff] at h_comm
rw [← isNilpotent_neg_iff] at hy
rw [sub_eq_add_neg]
exact h_comm.isNilpotent_add hx hy
end Ring
end Commute
section CommSemiring
variable [CommSemiring R] {x y : R}
lemma isNilpotent_sum {ι : Type*} {s : Finset ι} {f : ι → R}
(hnp : ∀ i ∈ s, IsNilpotent (f i)) :
IsNilpotent (∑ i ∈ s, f i) :=
Commute.isNilpotent_sum hnp fun _ _ _ _ ↦ Commute.all _ _
theorem isNilpotent_finsum {ι : Type*} {f : ι → R}
(hf : ∀ b, IsNilpotent (f b)) :
IsNilpotent (finsum f) :=
Commute.isNilpotent_finsum hf fun _ _ ↦ Commute.all _ _
end CommSemiring
lemma NoZeroSMulDivisors.isReduced (R M : Type*)
[MonoidWithZero R] [Zero M] [MulActionWithZero R M] [Nontrivial M] [NoZeroSMulDivisors R M] :
IsReduced R := by
refine ⟨fun x ⟨k, hk⟩ ↦ ?_⟩
induction' k with k ih
· rw [pow_zero] at hk
exact eq_zero_of_zero_eq_one hk.symm x
· obtain ⟨m : M, hm : m ≠ 0⟩ := exists_ne (0 : M)
have : x ^ (k + 1) • m = 0 := by simp only [hk, zero_smul]
rw [pow_succ', mul_smul] at this
rcases eq_zero_or_eq_zero_of_smul_eq_zero this with rfl | hx
· rfl
· exact ih <| (eq_zero_or_eq_zero_of_smul_eq_zero hx).resolve_right hm
|
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.
|
PreservesSheafification.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.Sites.Localization
import Mathlib.CategoryTheory.Sites.CompatibleSheafification
import Mathlib.CategoryTheory.Sites.Whiskering
import Mathlib.CategoryTheory.Sites.Sheafification
/-! # Functors which preserve sheafification
In this file, given a Grothendieck topology `J` on `C` and `F : A ⥤ B`,
we define a type class `J.PreservesSheafification F`. We say that `F` preserves
the sheafification if whenever a morphism of presheaves `P₁ ⟶ P₂` induces
an isomorphism on the associated sheaves, then the induced map `P₁ ⋙ F ⟶ P₂ ⋙ F`
also induces an isomorphism on the associated sheaves. (Note: it suffices to check
this property for the map from any presheaf `P` to its associated sheaf, see
`GrothendieckTopology.preservesSheafification_iff_of_adjunctions`).
In general, we define `Sheaf.composeAndSheafify J F : Sheaf J A ⥤ Sheaf J B` as the functor
which sends a sheaf `G` to the sheafification of the composition `G.val ⋙ F`.
If `J.PreservesSheafification F`, we show that this functor can also be thought of
as the localization of the functor `_ ⋙ F` on presheaves: we construct an isomorphism
`presheafToSheafCompComposeAndSheafifyIso` between
`presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F` and
`(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B`.
Moreover, if we assume `J.HasSheafCompose F`, we obtain an isomorphism
`sheafifyComposeIso J F P : sheafify J (P ⋙ F) ≅ sheafify J P ⋙ F`.
We show that under suitable assumptions, the forgetful functor from a concrete
category preserves sheafification; this holds more generally for
functors between such concrete categories which commute both with
suitable limits and colimits.
## TODO
* construct an isomorphism `Sheaf.composeAndSheafify J F ≅ sheafCompose J F`
-/
universe v u
namespace CategoryTheory
open Category Limits Functor
variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C)
{A B : Type*} [Category A] [Category B] (F : A ⥤ B)
namespace GrothendieckTopology
/-- A functor `F : A ⥤ B` preserves the sheafification for the Grothendieck
topology `J` on a category `C` if whenever a morphism of presheaves `f : P₁ ⟶ P₂`
in `Cᵒᵖ ⥤ A` is such that becomes an iso after sheafification, then it is
also the case of `whiskerRight f F : P₁ ⋙ F ⟶ P₂ ⋙ F`. -/
class PreservesSheafification : Prop where
le : J.W ≤ J.W.inverseImage ((whiskeringRight Cᵒᵖ A B).obj F)
variable [PreservesSheafification J F]
lemma W_of_preservesSheafification
{P₁ P₂ : Cᵒᵖ ⥤ A} (f : P₁ ⟶ P₂) (hf : J.W f) :
J.W (whiskerRight f F) :=
PreservesSheafification.le _ hf
variable [HasWeakSheafify J B]
lemma W_isInvertedBy_whiskeringRight_presheafToSheaf :
J.W.IsInvertedBy (((whiskeringRight Cᵒᵖ A B).obj F) ⋙ presheafToSheaf J B) := by
intro P₁ P₂ f hf
dsimp
rw [← W_iff]
exact J.W_of_preservesSheafification F _ hf
end GrothendieckTopology
section
variable [HasWeakSheafify J B]
/-- This is the functor sending a sheaf `X : Sheaf J A` to the sheafification
of `X.val ⋙ F`. -/
noncomputable abbrev Sheaf.composeAndSheafify : Sheaf J A ⥤ Sheaf J B :=
sheafToPresheaf J A ⋙ (whiskeringRight _ _ _).obj F ⋙ presheafToSheaf J B
variable [HasWeakSheafify J A]
/-- The canonical natural transformation from
`(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B` to
`presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F`. -/
@[simps!]
noncomputable def toPresheafToSheafCompComposeAndSheafify :
(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B ⟶
presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F :=
whiskerRight (sheafificationAdjunction J A).unit
((whiskeringRight _ _ _).obj F ⋙ presheafToSheaf J B)
variable [J.PreservesSheafification F]
instance : IsIso (toPresheafToSheafCompComposeAndSheafify J F) := by
rw [NatTrans.isIso_iff_isIso_app]
intro X
dsimp
simpa only [← J.W_iff] using J.W_of_preservesSheafification F _ (J.W_toSheafify X)
/-- The canonical isomorphism between `presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F`
and `(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B` when `F : A ⥤ B`
preserves sheafification. -/
@[simps! inv_app]
noncomputable def presheafToSheafCompComposeAndSheafifyIso :
presheafToSheaf J A ⋙ Sheaf.composeAndSheafify J F ≅
(whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B :=
(asIso (toPresheafToSheafCompComposeAndSheafify J F)).symm
noncomputable instance : Localization.Lifting (presheafToSheaf J A) J.W
((whiskeringRight Cᵒᵖ A B).obj F ⋙ presheafToSheaf J B) (Sheaf.composeAndSheafify J F) :=
⟨presheafToSheafCompComposeAndSheafifyIso J F⟩
end
section
variable {G₁ : (Cᵒᵖ ⥤ A) ⥤ Sheaf J A} (adj₁ : G₁ ⊣ sheafToPresheaf J A)
{G₂ : (Cᵒᵖ ⥤ B) ⥤ Sheaf J B}
lemma GrothendieckTopology.preservesSheafification_iff_of_adjunctions
(adj₂ : G₂ ⊣ sheafToPresheaf J B) :
J.PreservesSheafification F ↔ ∀ (P : Cᵒᵖ ⥤ A),
IsIso (G₂.map (whiskerRight (adj₁.unit.app P) F)) := by
simp only [← J.W_iff_isIso_map_of_adjunction adj₂]
constructor
· intro _ P
apply W_of_preservesSheafification
rw [J.W_iff_isIso_map_of_adjunction adj₁]
infer_instance
· intro h
constructor
intro P₁ P₂ f hf
rw [J.W_iff_isIso_map_of_adjunction adj₁] at hf
dsimp [MorphismProperty.inverseImage]
rw [← (W _).postcomp_iff _ _ (h P₂), ← whiskerRight_comp]
erw [adj₁.unit.naturality f]
dsimp only [Functor.comp_map]
rw [whiskerRight_comp, (W _).precomp_iff _ _ (h P₁)]
apply Localization.LeftBousfield.W_of_isIso
section HasSheafCompose
variable (adj₂ : G₂ ⊣ sheafToPresheaf J B) [J.HasSheafCompose F]
/-- The canonical natural transformation
`(whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ⟶ G₁ ⋙ sheafCompose J F`
when `F : A ⥤ B` is such that `J.HasSheafCompose F`, and that `G₁` and `G₂` are
left adjoints to the forget functors `sheafToPresheaf`. -/
def sheafComposeNatTrans :
(whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ⟶ G₁ ⋙ sheafCompose J F where
app P := (adj₂.homEquiv _ _).symm (whiskerRight (adj₁.unit.app P) F)
naturality {P Q} f := by
dsimp
erw [← adj₂.homEquiv_naturality_left_symm,
← adj₂.homEquiv_naturality_right_symm]
dsimp
rw [← whiskerRight_comp, ← whiskerRight_comp]
erw [adj₁.unit.naturality f]
rfl
lemma sheafComposeNatTrans_fac (P : Cᵒᵖ ⥤ A) :
adj₂.unit.app (P ⋙ F) ≫
(sheafToPresheaf J B).map ((sheafComposeNatTrans J F adj₁ adj₂).app P) =
whiskerRight (adj₁.unit.app P) F := by
simp [sheafComposeNatTrans, -sheafToPresheaf_obj, -sheafToPresheaf_map,
Adjunction.homEquiv_counit]
lemma sheafComposeNatTrans_app_uniq (P : Cᵒᵖ ⥤ A)
(α : G₂.obj (P ⋙ F) ⟶ (sheafCompose J F).obj (G₁.obj P))
(hα : adj₂.unit.app (P ⋙ F) ≫ (sheafToPresheaf J B).map α =
whiskerRight (adj₁.unit.app P) F) :
α = (sheafComposeNatTrans J F adj₁ adj₂).app P := by
apply (adj₂.homEquiv _ _).injective
dsimp [sheafComposeNatTrans]
erw [Equiv.apply_symm_apply]
rw [← hα]
apply adj₂.homEquiv_unit
lemma GrothendieckTopology.preservesSheafification_iff_of_adjunctions_of_hasSheafCompose :
J.PreservesSheafification F ↔ IsIso (sheafComposeNatTrans J F adj₁ adj₂) := by
rw [J.preservesSheafification_iff_of_adjunctions F adj₁ adj₂,
NatTrans.isIso_iff_isIso_app]
apply forall_congr'
intro P
rw [← J.W_iff_isIso_map_of_adjunction adj₂, ← J.W_sheafToPresheaf_map_iff_isIso,
← sheafComposeNatTrans_fac J F adj₁ adj₂,
(W _).precomp_iff _ _ (J.W_adj_unit_app adj₂ (P ⋙ F))]
variable [J.PreservesSheafification F]
instance : IsIso (sheafComposeNatTrans J F adj₁ adj₂) := by
rw [← J.preservesSheafification_iff_of_adjunctions_of_hasSheafCompose]
infer_instance
/-- The canonical natural isomorphism
`(whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ≅ G₁ ⋙ sheafCompose J F`
when `F : A ⥤ B` preserves sheafification, and that `G₁` and `G₂` are
left adjoints to the forget functors `sheafToPresheaf`. -/
noncomputable def sheafComposeNatIso :
(whiskeringRight Cᵒᵖ A B).obj F ⋙ G₂ ≅ G₁ ⋙ sheafCompose J F :=
asIso (sheafComposeNatTrans J F adj₁ adj₂)
end HasSheafCompose
end
section HasSheafCompose
variable [HasWeakSheafify J A] [HasWeakSheafify J B] [J.HasSheafCompose F]
[J.PreservesSheafification F] (P : Cᵒᵖ ⥤ A)
/-- The canonical isomorphism `sheafify J (P ⋙ F) ≅ sheafify J P ⋙ F` when
`F` preserves the sheafification. -/
noncomputable def sheafifyComposeIso :
sheafify J (P ⋙ F) ≅ sheafify J P ⋙ F :=
(sheafToPresheaf J B).mapIso
((sheafComposeNatIso J F (sheafificationAdjunction J A) (sheafificationAdjunction J B)).app P)
@[reassoc (attr := simp)]
lemma sheafComposeIso_hom_fac :
toSheafify J (P ⋙ F) ≫ (sheafifyComposeIso J F P).hom =
whiskerRight (toSheafify J P) F :=
sheafComposeNatTrans_fac J F (sheafificationAdjunction J A) (sheafificationAdjunction J B) P
@[reassoc (attr := simp)]
lemma sheafComposeIso_inv_fac :
whiskerRight (toSheafify J P) F ≫ (sheafifyComposeIso J F P).inv =
toSheafify J (P ⋙ F) := by
rw [← sheafComposeIso_hom_fac, assoc, Iso.hom_inv_id, comp_id]
end HasSheafCompose
namespace GrothendieckTopology
section
variable {D E : Type*} [Category.{max v u} D] [Category.{max v u} E] (F : D ⥤ E)
[∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) D]
[∀ (J : MulticospanShape.{max v u, max v u}), HasLimitsOfShape (WalkingMulticospan J) E]
[∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D]
[∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ E]
[∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ F]
[∀ (X : C) (W : J.Cover X) (P : Cᵒᵖ ⥤ D), PreservesLimit (W.index P).multicospan F]
{FD : D → D → Type*} {CD : D → Type (max v u)} {FE : E → E → Type*} {CE : E → Type (max v u)}
[∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [∀ X Y, FunLike (FE X Y) (CE X) (CE Y)]
[instCCD : ConcreteCategory D FD] [instCCE : ConcreteCategory E FE]
[∀ X, PreservesColimitsOfShape (Cover J X)ᵒᵖ (forget D)]
[∀ X, PreservesColimitsOfShape (Cover J X)ᵒᵖ (forget E)]
[PreservesLimits (forget D)] [PreservesLimits (forget E)]
[(forget D).ReflectsIsomorphisms] [(forget E).ReflectsIsomorphisms]
include instCCD instCCE in
lemma sheafToPresheaf_map_sheafComposeNatTrans_eq_sheafifyCompIso_inv (P : Cᵒᵖ ⥤ D) :
(sheafToPresheaf J E).map
((sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)).app P) =
(sheafifyCompIso J F P).inv := by
suffices (sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)).app P =
⟨(sheafifyCompIso J F P).inv⟩ by
rw [this]
rfl
apply ((plusPlusAdjunction J E).homEquiv _ _).injective
convert sheafComposeNatTrans_fac J F (plusPlusAdjunction J D) (plusPlusAdjunction J E) P
dsimp [plusPlusAdjunction]
simp
instance (P : Cᵒᵖ ⥤ D) :
IsIso ((sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)).app P) := by
rw [← isIso_iff_of_reflects_iso _ (sheafToPresheaf J E),
sheafToPresheaf_map_sheafComposeNatTrans_eq_sheafifyCompIso_inv]
infer_instance
instance : IsIso (sheafComposeNatTrans J F (plusPlusAdjunction J D) (plusPlusAdjunction J E)) :=
NatIso.isIso_of_isIso_app _
instance : PreservesSheafification J F := by
rw [preservesSheafification_iff_of_adjunctions_of_hasSheafCompose _ _
(plusPlusAdjunction J D) (plusPlusAdjunction J E)]
infer_instance
end
attribute [local instance] Types.instFunLike Types.instConcreteCategory in
example {D : Type*} [Category.{max v u} D] {FD : D → D → Type*} {CD : D → Type (max v u)}
[∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{max v u} D FD]
[PreservesLimits (forget D)]
[∀ X : C, HasColimitsOfShape (J.Cover X)ᵒᵖ D]
[∀ X : C, PreservesColimitsOfShape (J.Cover X)ᵒᵖ (forget D)]
[∀ (J : MulticospanShape.{max v u, max v u}),
Limits.HasLimitsOfShape (Limits.WalkingMulticospan J) D]
[(forget D).ReflectsIsomorphisms] : PreservesSheafification J (forget D) :=
instPreservesSheafification _ _
end GrothendieckTopology
end CategoryTheory
|
Interval.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.Data.DFinsupp.Interval
import Mathlib.Data.DFinsupp.Multiset
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Data.Nat.Lattice
/-!
# Finite intervals of multisets
This file provides the `LocallyFiniteOrder` instance for `Multiset α` and calculates the
cardinality of its finite intervals.
## Implementation notes
We implement the intervals via the intervals on `DFinsupp`, rather than via filtering
`Multiset.Powerset`; this is because `(Multiset.replicate n x).Powerset` has `2^n` entries not `n+1`
entries as it contains duplicates. We do not go via `Finsupp` as this would be noncomputable, and
multisets are typically used computationally.
-/
open Finset DFinsupp Function
open Pointwise
variable {α : Type*}
namespace Multiset
variable [DecidableEq α] (s t : Multiset α)
instance instLocallyFiniteOrder : LocallyFiniteOrder (Multiset α) :=
LocallyFiniteOrder.ofIcc (Multiset α)
(fun s t => (Finset.Icc (toDFinsupp s) (toDFinsupp t)).map
Multiset.equivDFinsupp.toEquiv.symm.toEmbedding)
fun s t x => by simp
theorem Icc_eq :
Finset.Icc s t = (Finset.Icc (toDFinsupp s) (toDFinsupp t)).map
Multiset.equivDFinsupp.toEquiv.symm.toEmbedding :=
rfl
theorem uIcc_eq :
uIcc s t =
(uIcc (toDFinsupp s) (toDFinsupp t)).map Multiset.equivDFinsupp.toEquiv.symm.toEmbedding :=
(Icc_eq _ _).trans <| by simp [uIcc]
theorem card_Icc :
#(Finset.Icc s t) = ∏ i ∈ s.toFinset ∪ t.toFinset, (t.count i + 1 - s.count i) := by
simp_rw [Icc_eq, Finset.card_map, DFinsupp.card_Icc, Nat.card_Icc, Multiset.toDFinsupp_apply,
toDFinsupp_support]
theorem card_Ico :
#(Finset.Ico s t) = ∏ i ∈ s.toFinset ∪ t.toFinset, (t.count i + 1 - s.count i) - 1 := by
rw [Finset.card_Ico_eq_card_Icc_sub_one, card_Icc]
theorem card_Ioc :
#(Finset.Ioc s t) = ∏ i ∈ s.toFinset ∪ t.toFinset, (t.count i + 1 - s.count i) - 1 := by
rw [Finset.card_Ioc_eq_card_Icc_sub_one, card_Icc]
theorem card_Ioo :
#(Finset.Ioo s t) = ∏ i ∈ s.toFinset ∪ t.toFinset, (t.count i + 1 - s.count i) - 2 := by
rw [Finset.card_Ioo_eq_card_Icc_sub_two, card_Icc]
theorem card_uIcc :
(uIcc s t).card = ∏ i ∈ s.toFinset ∪ t.toFinset, ((t.count i - s.count i : ℤ).natAbs + 1) := by
simp_rw [uIcc_eq, Finset.card_map, DFinsupp.card_uIcc, Nat.card_uIcc, Multiset.toDFinsupp_apply,
toDFinsupp_support]
theorem card_Iic : (Finset.Iic s).card = ∏ i ∈ s.toFinset, (s.count i + 1) := by
simp_rw [Iic_eq_Icc, card_Icc, bot_eq_zero, toFinset_zero, empty_union, count_zero, tsub_zero]
end Multiset
|
Defs.lean
|
/-
Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Patrick Massot
-/
-- This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl.
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.GroupTheory.Congruence.Hom
import Mathlib.GroupTheory.Coset.Defs
/-!
# Quotients of groups by normal subgroups
This file defines the group structure on the quotient by a normal subgroup.
## Main definitions
* `QuotientGroup.Quotient.Group`: the group structure on `G/N` given a normal subgroup `N` of `G`.
* `mk'`: the canonical group homomorphism `G →* G/N` given a normal subgroup `N` of `G`.
* `lift φ`: the group homomorphism `G/N →* H` given a group homomorphism `φ : G →* H` such that
`N ⊆ ker φ`.
* `map f`: the group homomorphism `G/N →* H/M` given a group homomorphism `f : G →* H` such that
`N ⊆ f⁻¹(M)`.
## Tags
quotient groups
-/
open Function
open scoped Pointwise
universe u v w x
namespace QuotientGroup
variable {G : Type u} [Group G] (N : Subgroup G) [nN : N.Normal] {H : Type v} [Group H]
{M : Type x} [Monoid M]
/-- The congruence relation generated by a normal subgroup. -/
@[to_additive /-- The additive congruence relation generated by a normal additive subgroup. -/]
protected def con : Con G where
toSetoid := leftRel N
mul' := fun {a b c d} hab hcd => by
rw [leftRel_eq] at hab hcd ⊢
dsimp only
calc
c⁻¹ * (a⁻¹ * b) * c⁻¹⁻¹ * (c⁻¹ * d) ∈ N := N.mul_mem (nN.conj_mem _ hab _) hcd
_ = (a * c)⁻¹ * (b * d) := by
simp only [mul_inv_rev, mul_assoc, inv_mul_cancel_left]
@[to_additive]
instance Quotient.group : Group (G ⧸ N) :=
(QuotientGroup.con N).group
/--
The congruence relation defined by the kernel of a group homomorphism is equal to its kernel
as a congruence relation.
-/
@[to_additive QuotientAddGroup.con_ker_eq_addConKer
/-- The additive congruence relation defined by the kernel of an additive group homomorphism is
equal to its kernel as an additive congruence relation. -/]
theorem con_ker_eq_conKer (f : G →* M) : QuotientGroup.con f.ker = Con.ker f := by
ext
rw [QuotientGroup.con, Con.rel_mk, Setoid.comm', leftRel_apply, Con.ker_rel, MonoidHom.eq_iff]
/-- The group homomorphism from `G` to `G/N`. -/
@[to_additive /-- The additive group homomorphism from `G` to `G/N`. -/]
def mk' : G →* G ⧸ N :=
MonoidHom.mk' QuotientGroup.mk fun _ _ => rfl
@[to_additive (attr := simp)]
theorem coe_mk' : (mk' N : G → G ⧸ N) = mk :=
rfl
@[to_additive (attr := simp)]
theorem mk'_apply (x : G) : mk' N x = x :=
rfl
@[to_additive]
theorem mk'_surjective : Surjective <| mk' N :=
@mk_surjective _ _ N
@[to_additive]
theorem mk'_eq_mk' {x y : G} : mk' N x = mk' N y ↔ ∃ z ∈ N, x * z = y :=
QuotientGroup.eq.trans <| by
simp only [← _root_.eq_inv_mul_iff_mul_eq, exists_eq_right]
/-- Two `MonoidHom`s from a quotient group are equal if their compositions with
`QuotientGroup.mk'` are equal.
See note [partially-applied ext lemmas]. -/
@[to_additive (attr := ext 1100) /-- Two `AddMonoidHom`s from an additive quotient group are equal
if their compositions with `AddQuotientGroup.mk'` are equal.
See note [partially-applied ext lemmas]. -/]
theorem monoidHom_ext ⦃f g : G ⧸ N →* M⦄ (h : f.comp (mk' N) = g.comp (mk' N)) : f = g :=
MonoidHom.ext fun x => QuotientGroup.induction_on x <| (DFunLike.congr_fun h :)
@[to_additive (attr := simp)]
theorem eq_one_iff {N : Subgroup G} [N.Normal] (x : G) : (x : G ⧸ N) = 1 ↔ x ∈ N := by
refine QuotientGroup.eq.trans ?_
rw [mul_one, Subgroup.inv_mem_iff]
@[to_additive (attr := simp)]
lemma mk'_comp_subtype : (mk' N).comp N.subtype = 1 := by ext; simp
/- Note: `range_mk'` is a lemma about the primed constructor `QuotientGroup.mk'`, not a
modified version of some `range_mk`. -/
set_option linter.docPrime false in
@[to_additive (attr := simp)]
theorem range_mk' : (QuotientGroup.mk' N).range = ⊤ :=
MonoidHom.range_eq_top.mpr (mk'_surjective N)
@[to_additive]
theorem ker_le_range_iff {I : Type w} [MulOneClass I] (f : G →* H) [f.range.Normal] (g : H →* I) :
g.ker ≤ f.range ↔ (mk' f.range).comp g.ker.subtype = 1 :=
⟨fun h => MonoidHom.ext fun ⟨_, hx⟩ => (eq_one_iff _).mpr <| h hx,
fun h x hx => (eq_one_iff _).mp <| by exact DFunLike.congr_fun h ⟨x, hx⟩⟩
@[to_additive (attr := simp)]
theorem ker_mk' : MonoidHom.ker (QuotientGroup.mk' N : G →* G ⧸ N) = N :=
Subgroup.ext eq_one_iff
@[to_additive]
theorem eq_iff_div_mem {N : Subgroup G} [nN : N.Normal] {x y : G} :
(x : G ⧸ N) = y ↔ x / y ∈ N := by
refine eq_comm.trans (QuotientGroup.eq.trans ?_)
rw [nN.mem_comm_iff, div_eq_mul_inv]
-- for commutative groups we don't need normality assumption
@[to_additive]
instance Quotient.commGroup {G : Type*} [CommGroup G] (N : Subgroup G) : CommGroup (G ⧸ N) :=
{ toGroup := have := N.normal_of_comm; QuotientGroup.Quotient.group N
mul_comm := fun a b => Quotient.inductionOn₂' a b fun a b => congr_arg mk (mul_comm a b) }
local notation " Q " => G ⧸ N
@[to_additive (attr := simp)]
theorem mk_one : ((1 : G) : Q) = 1 :=
rfl
@[to_additive (attr := simp)]
theorem mk_mul (a b : G) : ((a * b : G) : Q) = a * b :=
rfl
@[to_additive (attr := simp)]
theorem mk_inv (a : G) : ((a⁻¹ : G) : Q) = (a : Q)⁻¹ :=
rfl
@[to_additive (attr := simp)]
theorem mk_div (a b : G) : ((a / b : G) : Q) = a / b :=
rfl
@[to_additive (attr := simp)]
theorem mk_pow (a : G) (n : ℕ) : ((a ^ n : G) : Q) = (a : Q) ^ n :=
rfl
@[to_additive (attr := simp)]
theorem mk_zpow (a : G) (n : ℤ) : ((a ^ n : G) : Q) = (a : Q) ^ n :=
rfl
@[to_additive (attr := simp)] lemma map_mk'_self : N.map (mk' N) = ⊥ := by aesop
/--
The subgroup defined by the class of `1` for a congruence relation on a group.
-/
@[to_additive
/-- The `AddSubgroup` defined by the class of `0` for an additive congruence relation
on an `AddGroup`. -/]
protected def _root_.Con.subgroup (c : Con G) : Subgroup G where
carrier := { x | c x 1 }
one_mem' := c.refl 1
mul_mem' hx hy := by simpa using c.mul hx hy
inv_mem' h := by simpa using c.inv h
@[to_additive (attr := simp)]
theorem _root_.Con.mem_subgroup_iff {c : Con G} {x : G} :
x ∈ c.subgroup ↔ c x 1 := Iff.rfl
@[to_additive]
instance (c : Con G) : c.subgroup.Normal :=
⟨fun x hx g ↦ by simpa using (c.mul (c.mul (c.refl g) hx) (c.refl g⁻¹))⟩
@[to_additive (attr := simp)]
theorem _root_.Con.subgroup_quotientGroupCon (H : Subgroup G) [H.Normal] :
(QuotientGroup.con H).subgroup = H := by
ext
simp [QuotientGroup.con, leftRel_apply]
@[to_additive (attr := simp)]
theorem con_subgroup (c : Con G) :
QuotientGroup.con c.subgroup = c := by
ext x y
rw [QuotientGroup.con, Con.rel_mk, leftRel_apply, Con.mem_subgroup_iff]
exact ⟨fun h ↦ by simpa using c.mul (c.refl x) (c.symm h),
fun h ↦ by simpa using c.mul (c.refl x⁻¹) (c.symm h)⟩
/--
The normal subgroups correspond to the congruence relations on a group.
-/
@[to_additive (attr := simps) AddSubgroup.orderIsoAddCon
/-- The normal subgroups correspond to the additive congruence relations on an `AddGroup`. -/]
def _root_.Subgroup.orderIsoCon :
{ N : Subgroup G // N.Normal } ≃o Con G where
toFun N := letI : N.val.Normal := N.prop; QuotientGroup.con N
invFun c := ⟨c.subgroup, inferInstance⟩
left_inv := fun ⟨N, _⟩ ↦ Subtype.mk_eq_mk.mpr (Con.subgroup_quotientGroupCon N)
right_inv c := QuotientGroup.con_subgroup c
map_rel_iff' := by
simp only [QuotientGroup.con, Equiv.coe_fn_mk, Con.le_def, Con.rel_mk, leftRel_apply]
refine ⟨fun h x _ ↦ ?_, fun hle _ _ h ↦ hle h⟩
specialize @h 1 x
simp_all
@[to_additive (attr := simp)]
lemma con_le_iff {N M : Subgroup G} [N.Normal] [M.Normal] :
QuotientGroup.con N ≤ QuotientGroup.con M ↔ N ≤ M :=
(Subgroup.orderIsoCon.map_rel_iff (a := ⟨N, inferInstance⟩) (b := ⟨M, inferInstance⟩))
@[to_additive (attr := gcongr)]
lemma con_mono {N M : Subgroup G} [hN : N.Normal] [hM : M.Normal] (h : N ≤ M) :
QuotientGroup.con N ≤ QuotientGroup.con M :=
con_le_iff.mpr h
/-- A group homomorphism `φ : G →* M` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a
group homomorphism `G/N →* M`. -/
@[to_additive /-- An `AddGroup` homomorphism `φ : G →+ M` with `N ⊆ ker(φ)` descends (i.e. `lift`s)
to a group homomorphism `G/N →* M`. -/]
def lift (φ : G →* M) (HN : N ≤ φ.ker) : Q →* M :=
(QuotientGroup.con N).lift φ <| con_ker_eq_conKer φ ▸ con_mono HN
@[to_additive (attr := simp)]
theorem lift_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (g : Q) = φ g :=
rfl
@[to_additive (attr := simp)]
theorem lift_mk' {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (mk g : Q) = φ g :=
rfl
-- TODO: replace `mk` with `mk'`)
@[to_additive (attr := simp)]
theorem lift_comp_mk' (φ : G →* M) (HN : N ≤ φ.ker) :
(QuotientGroup.lift N φ HN).comp (QuotientGroup.mk' N) = φ :=
rfl
@[to_additive (attr := simp)]
theorem lift_quot_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) :
lift N φ HN (Quot.mk _ g : Q) = φ g :=
rfl
@[to_additive]
theorem lift_surjective_of_surjective (φ : G →* M) (hφ : Function.Surjective φ) (HN : N ≤ φ.ker) :
Function.Surjective (QuotientGroup.lift N φ HN) :=
Quotient.lift_surjective _ _ hφ
@[to_additive]
theorem ker_lift (φ : G →* M) (HN : N ≤ φ.ker) :
(QuotientGroup.lift N φ HN).ker = Subgroup.map (QuotientGroup.mk' N) φ.ker := by
rw [← congrArg MonoidHom.ker (lift_comp_mk' N φ HN), ← MonoidHom.comap_ker,
Subgroup.map_comap_eq_self_of_surjective (mk'_surjective N)]
/-- A group homomorphism `f : G →* H` induces a map `G/N →* H/M` if `N ⊆ f⁻¹(M)`. -/
@[to_additive
/-- An `AddGroup` homomorphism `f : G →+ H` induces a map `G/N →+ H/M` if `N ⊆ f⁻¹(M)`. -/]
def map (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) : G ⧸ N →* H ⧸ M := by
refine QuotientGroup.lift N ((mk' M).comp f) ?_
intro x hx
refine QuotientGroup.eq.2 ?_
rw [mul_one, Subgroup.inv_mem_iff]
exact h hx
@[to_additive (attr := simp)]
theorem map_mk (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) :
map N M f h ↑x = ↑(f x) :=
rfl
@[to_additive]
theorem map_mk' (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) :
map N M f h (mk' _ x) = ↑(f x) :=
rfl
@[to_additive]
theorem map_surjective_of_surjective (M : Subgroup H) [M.Normal] (f : G →* H)
(hf : Function.Surjective (mk ∘ f : G → H ⧸ M)) (h : N ≤ M.comap f) :
Function.Surjective (map N M f h) :=
lift_surjective_of_surjective _ _ hf _
@[to_additive]
theorem ker_map (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ Subgroup.comap f M) :
(map N M f h).ker = Subgroup.map (mk' N) (M.comap f) := by
simp_rw [← ker_mk' M, MonoidHom.comap_ker]
exact QuotientGroup.ker_lift _ _ _
@[to_additive]
theorem map_id_apply (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) (x) :
map N N (MonoidHom.id _) h x = x :=
induction_on x fun _x => rfl
@[to_additive (attr := simp)]
theorem map_id (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) :
map N N (MonoidHom.id _) h = MonoidHom.id _ :=
MonoidHom.ext (map_id_apply N h)
@[to_additive (attr := simp)]
theorem map_map {I : Type*} [Group I] (M : Subgroup H) (O : Subgroup I) [M.Normal] [O.Normal]
(f : G →* H) (g : H →* I) (hf : N ≤ Subgroup.comap f M) (hg : M ≤ Subgroup.comap g O)
(hgf : N ≤ Subgroup.comap (g.comp f) O :=
hf.trans ((Subgroup.comap_mono hg).trans_eq (Subgroup.comap_comap _ _ _)))
(x : G ⧸ N) : map M O g hg (map N M f hf x) = map N O (g.comp f) hgf x := by
refine induction_on x fun x => ?_
simp only [map_mk, MonoidHom.comp_apply]
@[to_additive (attr := simp)]
theorem map_comp_map {I : Type*} [Group I] (M : Subgroup H) (O : Subgroup I) [M.Normal] [O.Normal]
(f : G →* H) (g : H →* I) (hf : N ≤ Subgroup.comap f M) (hg : M ≤ Subgroup.comap g O)
(hgf : N ≤ Subgroup.comap (g.comp f) O :=
hf.trans ((Subgroup.comap_mono hg).trans_eq (Subgroup.comap_comap _ _ _))) :
(map M O g hg).comp (map N M f hf) = map N O (g.comp f) hgf :=
MonoidHom.ext (map_map N M O f g hf hg hgf)
section Pointwise
open Set
@[to_additive (attr := simp)] lemma image_coe : ((↑) : G → Q) '' N = 1 :=
congr_arg ((↑) : Subgroup Q → Set Q) <| map_mk'_self N
@[to_additive]
lemma preimage_image_coe (s : Set G) : ((↑) : G → Q) ⁻¹' ((↑) '' s) = N * s := by
ext a
constructor
· rintro ⟨b, hb, h⟩
refine ⟨a / b, (QuotientGroup.eq_one_iff _).1 ?_, b, hb, div_mul_cancel _ _⟩
simp only [h, QuotientGroup.mk_div, div_self']
· rintro ⟨a, ha, b, hb, rfl⟩
refine ⟨b, hb, ?_⟩
simpa only [QuotientGroup.mk_mul, right_eq_mul, QuotientGroup.eq_one_iff]
@[to_additive]
lemma image_coe_inj {s t : Set G} : ((↑) : G → Q) '' s = ((↑) : G → Q) '' t ↔ ↑N * s = N * t := by
simp_rw [← preimage_image_coe]
exact QuotientGroup.mk_surjective.preimage_injective.eq_iff.symm
end Pointwise
section congr
variable (G' : Subgroup G) (H' : Subgroup H) [Subgroup.Normal G'] [Subgroup.Normal H']
/-- `QuotientGroup.congr` lifts the isomorphism `e : G ≃ H` to `G ⧸ G' ≃ H ⧸ H'`,
given that `e` maps `G` to `H`. -/
@[to_additive /-- `QuotientAddGroup.congr` lifts the isomorphism `e : G ≃ H` to `G ⧸ G' ≃ H ⧸ H'`,
given that `e` maps `G` to `H`. -/]
def congr (e : G ≃* H) (he : G'.map e = H') : G ⧸ G' ≃* H ⧸ H' :=
{ map G' H' e (he ▸ G'.le_comap_map (e : G →* H)) with
toFun := map G' H' e (he ▸ G'.le_comap_map (e : G →* H))
invFun := map H' G' e.symm (he ▸ (G'.map_equiv_eq_comap_symm e).le)
left_inv := fun x => by
rw [map_map G' H' G' e e.symm (he ▸ G'.le_comap_map (e : G →* H))
(he ▸ (G'.map_equiv_eq_comap_symm e).le)]
simp only [← MulEquiv.coe_monoidHom_trans, MulEquiv.self_trans_symm,
MulEquiv.coe_monoidHom_refl, map_id_apply]
right_inv := fun x => by
rw [map_map H' G' H' e.symm e (he ▸ (G'.map_equiv_eq_comap_symm e).le)
(he ▸ G'.le_comap_map (e : G →* H)) ]
simp only [← MulEquiv.coe_monoidHom_trans, MulEquiv.symm_trans_self,
MulEquiv.coe_monoidHom_refl, map_id_apply] }
@[simp]
theorem congr_mk (e : G ≃* H) (he : G'.map ↑e = H') (x) : congr G' H' e he (mk x) = e x :=
rfl
theorem congr_mk' (e : G ≃* H) (he : G'.map ↑e = H') (x) :
congr G' H' e he (mk' G' x) = mk' H' (e x) :=
rfl
@[simp]
theorem congr_apply (e : G ≃* H) (he : G'.map ↑e = H') (x : G) :
congr G' H' e he x = mk' H' (e x) :=
rfl
@[simp]
theorem congr_refl (he : G'.map (MulEquiv.refl G : G →* G) = G' := Subgroup.map_id G') :
congr G' G' (MulEquiv.refl G) he = MulEquiv.refl (G ⧸ G') := by
ext ⟨x⟩
rfl
@[simp]
theorem congr_symm (e : G ≃* H) (he : G'.map ↑e = H') :
(congr G' H' e he).symm = congr H' G' e.symm ((Subgroup.map_symm_eq_iff_map_eq _).mpr he) :=
rfl
end congr
end QuotientGroup
|
Radical.lean
|
/-
Copyright (c) 2024 Jineon Baek, Seewoo Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jineon Baek, Seewoo Lee, Bhavik Mehta, Arend Mellendijk
-/
import Mathlib.Algebra.EuclideanDomain.Basic
import Mathlib.Algebra.Order.Group.Finset
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.UniqueFactorizationDomain.NormalizedFactors
import Mathlib.RingTheory.UniqueFactorizationDomain.Nat
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.Data.Nat.PrimeFin
import Mathlib.Algebra.Squarefree.Basic
/-!
# Radical of an element of a unique factorization normalization monoid
This file defines a radical of an element `a` of a unique factorization normalization
monoid, which is defined as a product of normalized prime factors of `a` without duplication.
This is different from the radical of an ideal.
## Main declarations
- `radical`: The radical of an element `a` in a unique factorization monoid is the product of
its prime factors.
- `radical_eq_of_associated`: If `a` and `b` are associates, i.e. `a * u = b` for some unit `u`,
then `radical a = radical b`.
- `radical_unit_mul`: Multiplying unit does not change the radical.
- `radical_dvd_self`: `radical a` divides `a`.
- `radical_pow`: `radical (a ^ n) = radical a` for any `n ≥ 1`
- `radical_of_prime`: Radical of a prime element is equal to its normalization
- `radical_pow_of_prime`: Radical of a power of prime element is equal to its normalization
- `radical_mul`: Radical is multiplicative for two relatively prime elements.
- `radical_prod`: Radical is multiplicative for finitely many relatively prime elements.
### For unique factorization domains
### For Euclidean domains
- `EuclideanDomain.divRadical`: For an element `a` in an Euclidean domain, `a / radical a`.
- `EuclideanDomain.divRadical_mul`: `divRadical` of a product is the product of `divRadical`s.
- `IsCoprime.divRadical`: `divRadical` of coprime elements are coprime.
## For natural numbers
- `UniqueFactorizationMonoid.primeFactors_eq_natPrimeFactors`: The prime factors of a natural number
are the same as the prime factors defined in `Nat.primeFactors`.
- `Nat.radical_le_self`: The radical of a natural number is less than or equal to the number itself.
- `Nat.two_le_radical`: If a natural number is at least 2, then its radical is at least 2.
## TODO
- Make a comparison with `Ideal.radical`. Especially, for principal ideal,
`Ideal.radical (Ideal.span {a}) = Ideal.span {radical a}`.
-/
noncomputable section
namespace UniqueFactorizationMonoid
-- `CancelCommMonoidWithZero` is required by `UniqueFactorizationMonoid`
variable {M : Type*} [CancelCommMonoidWithZero M] [NormalizationMonoid M]
[UniqueFactorizationMonoid M] {a b u : M}
open scoped Classical in
/-- The finite set of prime factors of an element in a unique factorization monoid. -/
def primeFactors (a : M) : Finset M :=
(normalizedFactors a).toFinset
lemma mem_primeFactors : a ∈ primeFactors b ↔ a ∈ normalizedFactors b := by
simp only [primeFactors, Multiset.mem_toFinset]
theorem _root_.Associated.primeFactors_eq {a b : M} (h : Associated a b) :
primeFactors a = primeFactors b := by
unfold primeFactors
rw [h.normalizedFactors_eq]
@[simp] lemma primeFactors_zero : primeFactors (0 : M) = ∅ := by simp [primeFactors]
@[simp] lemma primeFactors_one : primeFactors (1 : M) = ∅ := by simp [primeFactors]
lemma pairwise_primeFactors_isRelPrime :
Set.Pairwise (primeFactors a : Set M) IsRelPrime := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp
intro x hx y hy hxy
simp only [Finset.mem_coe, mem_primeFactors, mem_normalizedFactors_iff' ha₀] at hx hy
rw [hx.1.isRelPrime_iff_not_dvd]
contrapose! hxy
have : Associated x y := hx.1.associated_of_dvd hy.1 hxy
exact this.eq_of_normalized hx.2.1 hy.2.1
theorem primeFactors_pow (a : M) {n : ℕ} (hn : n ≠ 0) : primeFactors (a ^ n) = primeFactors a := by
simp_rw [primeFactors, normalizedFactors_pow, Multiset.toFinset_nsmul _ _ hn]
@[simp]
theorem primeFactors_pow' (a : M) {n : ℕ} [NeZero n] : primeFactors (a ^ n) = primeFactors a :=
primeFactors_pow a NeZero.out
lemma normalizedFactors_nodup (ha : IsRadical a) : (normalizedFactors a).Nodup := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp
rwa [← squarefree_iff_nodup_normalizedFactors ha₀, ← isRadical_iff_squarefree_of_ne_zero ha₀]
/--
If `x` is a unit, then the finset of prime factors of `x` is empty.
The converse is true with a nonzero assumption, see `primeFactors_eq_empty_iff`.
-/
lemma primeFactors_of_isUnit (h : IsUnit a) : primeFactors a = ∅ := by
classical
rw [primeFactors, normalizedFactors_of_isUnit h, Multiset.toFinset_zero]
/--
The finset of prime factors of `x` is empty if and only if `x` is a unit.
The converse is true without the nonzero assumption, see `primeFactors_of_isUnit`.
-/
theorem primeFactors_eq_empty_iff (ha : a ≠ 0) : primeFactors a = ∅ ↔ IsUnit a := by
classical
rw [primeFactors, Multiset.toFinset_eq_empty, normalizedFactors_eq_zero_iff ha]
lemma primeFactors_val_eq_normalizedFactors (ha : IsRadical a) :
(primeFactors a).val = normalizedFactors a := by
classical
rw [primeFactors, Multiset.toFinset_val, Multiset.dedup_eq_self]
exact normalizedFactors_nodup ha
-- Note that the non-zero assumptions are necessary here.
theorem primeFactors_mul_eq_union [DecidableEq M] (ha : a ≠ 0) (hb : b ≠ 0) :
primeFactors (a * b) = primeFactors a ∪ primeFactors b := by
ext p
simp [mem_normalizedFactors_iff', mem_primeFactors, ha, hb]
/-- Relatively prime elements have disjoint prime factors (as finsets). -/
theorem disjoint_primeFactors (hc : IsRelPrime a b) :
Disjoint (primeFactors a) (primeFactors b) := by
classical
exact Multiset.disjoint_toFinset.mpr (disjoint_normalizedFactors hc)
theorem primeFactors_mul_eq_disjUnion (hc : IsRelPrime a b) :
primeFactors (a * b) =
(primeFactors a).disjUnion (primeFactors b) (disjoint_primeFactors hc) := by
obtain rfl | ha := eq_or_ne a 0
· rw [isRelPrime_zero_left] at hc
simp only [zero_mul, primeFactors_zero, Finset.empty_disjUnion, primeFactors_of_isUnit hc]
obtain rfl | hb := eq_or_ne b 0
· rw [isRelPrime_zero_right] at hc
simp only [mul_zero, primeFactors_zero, primeFactors_of_isUnit hc, Finset.disjUnion_empty]
classical
rw [Finset.disjUnion_eq_union, primeFactors_mul_eq_union ha hb]
/--
Radical of an element `a` in a unique factorization monoid is the product of
the prime factors of `a`.
-/
def radical (a : M) : M :=
(primeFactors a).prod id
@[simp] theorem radical_zero : radical (0 : M) = 1 := by simp [radical]
@[deprecated (since := "2025-05-31")] alias radical_zero_eq := radical_zero
@[simp] theorem radical_one : radical (1 : M) = 1 := by simp [radical]
@[deprecated (since := "2025-05-31")] alias radical_one_eq := radical_one
lemma radical_eq_of_primeFactors_eq (h : primeFactors a = primeFactors b) :
radical a = radical b := by
simp only [radical, h]
theorem radical_eq_of_associated (h : Associated a b) : radical a = radical b :=
radical_eq_of_primeFactors_eq h.primeFactors_eq
lemma radical_associated (ha : IsRadical a) (ha' : a ≠ 0) :
Associated (radical a) a := by
rw [radical, ← Finset.prod_val, primeFactors_val_eq_normalizedFactors ha]
exact prod_normalizedFactors ha'
/-- If `a` is a radical element, then it divides its radical. -/
lemma _root_.IsRadical.dvd_radical (ha : IsRadical a) (ha' : a ≠ 0) : a ∣ radical a :=
(radical_associated ha ha').dvd'
theorem radical_of_isUnit (h : IsUnit a) : radical a = 1 :=
(radical_eq_of_associated (associated_one_iff_isUnit.mpr h)).trans radical_one
theorem radical_mul_of_isUnit_left (h : IsUnit u) : radical (u * a) = radical a :=
radical_eq_of_associated (associated_unit_mul_left _ _ h)
theorem radical_mul_of_isUnit_right (h : IsUnit u) : radical (a * u) = radical a :=
radical_eq_of_associated (associated_mul_unit_left _ _ h)
theorem radical_pow (a : M) {n : ℕ} (hn : n ≠ 0) : radical (a ^ n) = radical a := by
simp_rw [radical, primeFactors_pow a hn]
theorem radical_dvd_self : radical a ∣ a := by
classical
by_cases ha : a = 0
· rw [ha]
apply dvd_zero
· rw [radical, ← Finset.prod_val, ← (prod_normalizedFactors ha).dvd_iff_dvd_right]
apply Multiset.prod_dvd_prod_of_le
rw [primeFactors, Multiset.toFinset_val]
apply Multiset.dedup_le
theorem radical_of_prime (ha : Prime a) : radical a = normalize a := by
rw [radical, primeFactors]
rw [normalizedFactors_irreducible ha.irreducible]
simp only [Multiset.toFinset_singleton, id, Finset.prod_singleton]
theorem radical_pow_of_prime (ha : Prime a) {n : ℕ} (hn : n ≠ 0) :
radical (a ^ n) = normalize a := by
rw [radical_pow a hn]
exact radical_of_prime ha
@[simp] theorem radical_ne_zero [Nontrivial M] : radical a ≠ 0 := by
rw [radical, ← Finset.prod_val]
apply Multiset.prod_ne_zero
rw [primeFactors]
simp only [Multiset.toFinset_val, Multiset.mem_dedup]
exact zero_notMem_normalizedFactors _
/--
An irreducible `a` divides the radical of `b` if and only if it divides `b` itself.
Note this generalises to radical elements `a`, see `UniqueFactorizationMonoid.dvd_radical_iff`.
-/
lemma dvd_radical_iff_of_irreducible (ha : Irreducible a) (hb : b ≠ 0) :
a ∣ radical b ↔ a ∣ b := by
constructor
· intro ha
exact ha.trans radical_dvd_self
· intro ha'
obtain ⟨c, hc, hc'⟩ := exists_mem_normalizedFactors_of_dvd hb ha ha'
exact hc'.dvd.trans (Finset.dvd_prod_of_mem _ (by simpa [mem_primeFactors] using hc))
lemma isRadical_radical : IsRadical (radical a) := by
intro n p ha
rw [radical]
apply Finset.prod_dvd_of_isRelPrime
· exact pairwise_primeFactors_isRelPrime
intro i hi
simp only [mem_primeFactors] at hi
have : i ∣ radical a := by
rw [dvd_radical_iff_of_irreducible]
· exact dvd_of_mem_normalizedFactors hi
· exact irreducible_of_normalized_factor i hi
· rintro rfl
simp only [normalizedFactors_zero, Multiset.notMem_zero] at hi
exact (prime_of_normalized_factor i hi).isRadical n p (this.trans ha)
lemma squarefree_radical : Squarefree (radical a) := by
nontriviality M
exact isRadical_radical.squarefree (by simp [radical_ne_zero])
@[simp] lemma primeFactors_radical : primeFactors (radical a) = primeFactors a := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp [primeFactors]
have : Nontrivial M := ⟨a, 0, ha₀⟩
ext p
simp +contextual [mem_primeFactors, mem_normalizedFactors_iff',
dvd_radical_iff_of_irreducible, ha₀]
theorem radical_eq_one_iff : radical a = 1 ↔ a = 0 ∨ IsUnit a := by
refine ⟨?_, (Or.elim · (by simp +contextual) radical_of_isUnit)⟩
intro h
rw [or_iff_not_imp_left]
intro ha
have : primeFactors a = ∅ := by rw [← primeFactors_radical, h, primeFactors_one]
rwa [primeFactors_eq_empty_iff ha] at this
@[simp]
lemma radical_radical : radical (radical a) = radical a :=
radical_eq_of_primeFactors_eq primeFactors_radical
lemma radical_dvd_radical_iff_normalizedFactors_subset_normalizedFactors :
radical a ∣ radical b ↔ normalizedFactors a ⊆ normalizedFactors b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp
have : Nontrivial M := ⟨a, 0, ha₀⟩
rw [dvd_iff_normalizedFactors_le_normalizedFactors radical_ne_zero radical_ne_zero,
Multiset.le_iff_subset (normalizedFactors_nodup isRadical_radical)]
simp only [Multiset.subset_iff, ← mem_primeFactors, primeFactors_radical]
lemma radical_dvd_radical_iff_primeFactors_subset_primeFactors :
radical a ∣ radical b ↔ primeFactors a ⊆ primeFactors b := by
classical
rw [radical_dvd_radical_iff_normalizedFactors_subset_normalizedFactors, primeFactors,
primeFactors, Multiset.toFinset_subset]
/-- If `a` divides `b`, then the radical of `a` divides the radical of `b`. The theorem requires
that `b ≠ 0`, since `radical 0 = 1` but `a ∣ 0` holds for every `a`. -/
lemma radical_dvd_radical (h : a ∣ b) (hb₀ : b ≠ 0) : radical a ∣ radical b := by
obtain rfl | ha₀ := eq_or_ne a 0
· simp
rw [dvd_iff_normalizedFactors_le_normalizedFactors ha₀ hb₀] at h
rw [radical_dvd_radical_iff_normalizedFactors_subset_normalizedFactors]
exact Multiset.subset_of_le h
/--
If `a` is a radical element, then `a` divides the radical of `b` if and only if it divides `b`.
Note the forward implication holds without the `b ≠ 0` assumption via `radical_dvd_self`.
-/
lemma dvd_radical_iff (ha : IsRadical a) (hb₀ : b ≠ 0) : a ∣ radical b ↔ a ∣ b := by
refine ⟨fun ha' ↦ ha'.trans radical_dvd_self, fun hab ↦ ?_⟩
obtain rfl | ha₀ := eq_or_ne a 0
· simp_all
· exact (ha.dvd_radical ha₀).trans (radical_dvd_radical hab hb₀)
theorem radical_dvd_iff_primeFactors_subset (hb : b ≠ 0) :
radical a ∣ b ↔ primeFactors a ⊆ primeFactors b := by
rw [← dvd_radical_iff isRadical_radical hb,
radical_dvd_radical_iff_primeFactors_subset_primeFactors]
/-- Radical is multiplicative for relatively prime elements. -/
theorem radical_mul (hc : IsRelPrime a b) :
radical (a * b) = radical a * radical b := by
simp_rw [radical]
rw [primeFactors_mul_eq_disjUnion hc, Finset.prod_disjUnion (disjoint_primeFactors hc)]
theorem radical_prod {ι : Type*} {f : ι → M} (s : Finset ι)
(h : Set.Pairwise (s : Set ι) (Function.onFun IsRelPrime f)) :
radical (∏ i ∈ s, f i) = ∏ i ∈ s, radical (f i) := by
induction s using Finset.cons_induction with
| empty => simp
| cons i s his ih =>
simp only [Finset.prod_cons]
rw [Finset.coe_cons,
Set.pairwise_insert_of_symmetric_of_notMem (symmetric_isRelPrime.comap _) (by simpa)] at h
rw [radical_mul, ih h.1]
exact IsRelPrime.prod_right h.2
theorem radical_mul_dvd : radical (a * b) ∣ radical a * radical b := by
classical
obtain rfl | ha := eq_or_ne a 0
· simp
obtain rfl | hb := eq_or_ne b 0
· simp
nontriviality M
simp [radical_dvd_iff_primeFactors_subset, primeFactors_mul_eq_union,
primeFactors_mul_eq_union ha hb, primeFactors_radical]
theorem radical_prod_dvd {ι : Type*} {s : Finset ι} {f : ι → M} :
radical (∏ i ∈ s, f i) ∣ ∏ i ∈ s, radical (f i) := by
induction s using Finset.cons_induction with
| empty => simp
| cons i s h ih =>
simp only [Finset.prod_cons]
exact radical_mul_dvd.trans (mul_dvd_mul_left _ ih)
end UniqueFactorizationMonoid
open UniqueFactorizationMonoid
/-! Theorems for UFDs -/
namespace UniqueFactorizationDomain
variable {R : Type*} [CommRing R] [IsDomain R] [NormalizationMonoid R]
[UniqueFactorizationMonoid R] {a b : R}
/-- Coprime elements have disjoint prime factors (as multisets). -/
@[deprecated "UniqueFactorizationMonoid.disjoint_normalizedFactors, IsCoprime.isRelPrime"
(since := "2025-05-31")]
theorem disjoint_normalizedFactors (hc : IsCoprime a b) :
Disjoint (normalizedFactors a) (normalizedFactors b) :=
UniqueFactorizationMonoid.disjoint_normalizedFactors hc.isRelPrime
/-- Coprime elements have disjoint prime factors (as finsets). -/
@[deprecated "UniqueFactorizationMonoid.disjoint_primeFactors, IsCoprime.isRelPrime"
(since := "2025-05-31")]
theorem disjoint_primeFactors (hc : IsCoprime a b) :
Disjoint (primeFactors a) (primeFactors b) :=
UniqueFactorizationMonoid.disjoint_primeFactors hc.isRelPrime
set_option linter.deprecated false in
@[deprecated "UniqueFactorizationMonoid.primeFactors_mul_eq_disjUnion, IsCoprime.isRelPrime"
(since := "2025-05-31")]
theorem mul_primeFactors_disjUnion
(hc : IsCoprime a b) : primeFactors (a * b) =
(primeFactors a).disjUnion (primeFactors b) (disjoint_primeFactors hc) :=
UniqueFactorizationMonoid.primeFactors_mul_eq_disjUnion hc.isRelPrime
/-- Radical is multiplicative for coprime elements. -/
@[deprecated "UniqueFactorizationMonoid.radical_mul, IsCoprime.isRelPrime" (since := "2025-05-31")]
theorem radical_mul (hc : IsCoprime a b) :
radical (a * b) = radical a * radical b :=
UniqueFactorizationMonoid.radical_mul hc.isRelPrime
@[simp]
theorem radical_neg : radical (-a) = radical a :=
radical_eq_of_associated Associated.rfl.neg_left
theorem radical_neg_one : radical (-1 : R) = 1 := by simp
end UniqueFactorizationDomain
open UniqueFactorizationDomain
namespace EuclideanDomain
variable {E : Type*} [EuclideanDomain E] [NormalizationMonoid E] [UniqueFactorizationMonoid E]
{a b u x : E}
/-- Division of an element by its radical in an Euclidean domain. -/
def divRadical (a : E) : E := a / radical a
theorem radical_mul_divRadical : radical a * divRadical a = a := by
rw [divRadical, ← EuclideanDomain.mul_div_assoc _ radical_dvd_self,
mul_div_cancel_left₀ _ radical_ne_zero]
theorem divRadical_mul_radical : divRadical a * radical a = a := by
rw [mul_comm]
exact radical_mul_divRadical
theorem divRadical_ne_zero (ha : a ≠ 0) : divRadical a ≠ 0 := by
rw [← radical_mul_divRadical (a := a)] at ha
exact right_ne_zero_of_mul ha
theorem divRadical_isUnit (hu : IsUnit u) : IsUnit (divRadical u) := by
rwa [divRadical, radical_of_isUnit hu, EuclideanDomain.div_one]
theorem eq_divRadical (h : radical a * x = a) : x = divRadical a := by
apply EuclideanDomain.eq_div_of_mul_eq_left radical_ne_zero
rwa [mul_comm]
theorem divRadical_mul (hab : IsCoprime a b) :
divRadical (a * b) = divRadical a * divRadical b := by
symm; apply eq_divRadical
rw [UniqueFactorizationMonoid.radical_mul hab.isRelPrime]
rw [mul_mul_mul_comm, radical_mul_divRadical, radical_mul_divRadical]
theorem divRadical_dvd_self (a : E) : divRadical a ∣ a :=
⟨radical a, divRadical_mul_radical.symm⟩
theorem _root_.IsCoprime.divRadical {a b : E} (h : IsCoprime a b) :
IsCoprime (divRadical a) (divRadical b) := by
rw [← radical_mul_divRadical (a := a)] at h
rw [← radical_mul_divRadical (a := b)] at h
exact h.of_mul_left_right.of_mul_right_right
end EuclideanDomain
section Nat
lemma UniqueFactorizationMonoid.primeFactors_eq_natPrimeFactors :
primeFactors = Nat.primeFactors := by
ext n : 1
rw [primeFactors, Nat.factors_eq, Nat.primeFactors]
-- this convert is necessary because of the different DecidableEq instances
convert List.toFinset_coe _
namespace Nat
@[simp] theorem radical_le_self_iff {n : ℕ} : radical n ≤ n ↔ n ≠ 0 :=
⟨by aesop, fun h ↦ Nat.le_of_dvd (by omega) radical_dvd_self⟩
@[simp] theorem two_le_radical_iff {n : ℕ} : 2 ≤ radical n ↔ 2 ≤ n := by
refine ⟨?_, ?_⟩
· match n with | 0 | 1 | _ + 2 => simp
· intro hn
obtain ⟨p, hp, hpn⟩ := Nat.exists_prime_and_dvd (show n ≠ 1 by omega)
trans p
· apply hp.two_le
· apply Nat.le_of_dvd (Nat.pos_of_ne_zero radical_ne_zero)
rwa [dvd_radical_iff_of_irreducible hp.prime.irreducible (by omega)]
@[simp] theorem one_lt_radical_iff {n : ℕ} : 1 < radical n ↔ 1 < n := two_le_radical_iff
@[simp] theorem radical_le_one_iff {n : ℕ} : radical n ≤ 1 ↔ n ≤ 1 := by
simpa only [not_lt] using one_lt_radical_iff.not
theorem radical_pos (n : ℕ) : 0 < radical n := pos_of_ne_zero radical_ne_zero
end Nat
end Nat
|
HomotopyEquivalence.lean
|
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.AlgebraicTopology.DoldKan.Normalized
/-!
# The normalized Moore complex and the alternating face map complex are homotopy equivalent
In this file, when the category `A` is abelian, we obtain the homotopy equivalence
`homotopyEquivNormalizedMooreComplexAlternatingFaceMapComplex` between the
normalized Moore complex and the alternating face map complex of a simplicial object in `A`.
-/
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
CategoryTheory.Preadditive Simplicial DoldKan
noncomputable section
namespace AlgebraicTopology
namespace DoldKan
variable {C : Type*} [Category C] [Preadditive C] (X : SimplicialObject C)
/-- Inductive construction of homotopies from `P q` to `𝟙 _` -/
noncomputable def homotopyPToId : ∀ q : ℕ, Homotopy (P q : K[X] ⟶ _) (𝟙 _)
| 0 => Homotopy.refl _
| q + 1 => by
refine
Homotopy.trans (Homotopy.ofEq ?_)
(Homotopy.trans
(Homotopy.add (homotopyPToId q) (Homotopy.compLeft (homotopyHσToZero q) (P q)))
(Homotopy.ofEq ?_))
· simp only [P_succ, comp_add, comp_id]
· simp only [add_zero, comp_zero]
/-- The complement projection `Q q` to `P q` is homotopic to zero. -/
def homotopyQToZero (q : ℕ) : Homotopy (Q q : K[X] ⟶ _) 0 :=
Homotopy.equivSubZero.toFun (homotopyPToId X q).symm
theorem homotopyPToId_eventually_constant {q n : ℕ} (hqn : n < q) :
((homotopyPToId X (q + 1)).hom n (n + 1) : X _⦋n⦌ ⟶ X _⦋n + 1⦌) =
(homotopyPToId X q).hom n (n + 1) := by
simp only [homotopyHσToZero, AlternatingFaceMapComplex.obj_X, Homotopy.trans_hom,
Homotopy.ofEq_hom, Pi.zero_apply, Homotopy.add_hom, Homotopy.compLeft_hom, add_zero,
Homotopy.nullHomotopy'_hom, ComplexShape.down_Rel, hσ'_eq_zero hqn (c_mk (n + 1) n rfl),
dite_eq_ite, ite_self, comp_zero, zero_add, homotopyPToId]
/-- Construction of the homotopy from `PInfty` to the identity using eventually
(termwise) constant homotopies from `P q` to the identity for all `q` -/
@[simps]
def homotopyPInftyToId : Homotopy (PInfty : K[X] ⟶ _) (𝟙 _) where
hom i j := (homotopyPToId X (j + 1)).hom i j
zero i j hij := Homotopy.zero _ i j hij
comm n := by
rcases n with _ | n
· simpa only [Homotopy.dNext_zero_chainComplex, Homotopy.prevD_chainComplex,
PInfty_f, P_f_0_eq, zero_add] using (homotopyPToId X 2).comm 0
· simpa only [Homotopy.dNext_succ_chainComplex, Homotopy.prevD_chainComplex,
HomologicalComplex.id_f, PInfty_f, ← P_is_eventually_constant (le_refl <| n + 1),
homotopyPToId_eventually_constant X (Nat.lt_add_one (Nat.succ n)),
Homotopy.dNext_succ_chainComplex, Homotopy.prevD_chainComplex]
using (homotopyPToId X (n + 2)).comm (n + 1)
/-- The inclusion of the Moore complex in the alternating face map complex
is a homotopy equivalence -/
@[simps]
def homotopyEquivNormalizedMooreComplexAlternatingFaceMapComplex {A : Type*} [Category A]
[Abelian A] {Y : SimplicialObject A} :
HomotopyEquiv ((normalizedMooreComplex A).obj Y) ((alternatingFaceMapComplex A).obj Y) where
hom := inclusionOfMooreComplexMap Y
inv := PInftyToNormalizedMooreComplex Y
homotopyHomInvId := Homotopy.ofEq (splitMonoInclusionOfMooreComplexMap Y).id
homotopyInvHomId := Homotopy.trans
(Homotopy.ofEq (PInftyToNormalizedMooreComplex_comp_inclusionOfMooreComplexMap Y))
(homotopyPInftyToId Y)
end DoldKan
end AlgebraicTopology
|
BestFirst.lean
|
import Mathlib.Data.MLList.BestFirst
import Mathlib.Data.Nat.Basic
/-!
# Testing best first search and beam search.
We check that `bestFirstSearch` can find its way around a wall.
-/
open Lean MLList Function
def Point := Int × Int
deriving Repr
def wall : Point → Bool :=
fun ⟨x, y⟩ => x ≤ 3 || y ≤ 3 || x ≥ 20 || y ≥ 20 || (x ≥ 6 && y ≥ 6)
def nbhd : Point → MLList MetaM Point :=
fun ⟨x, y⟩ => MLList.ofList
([(x+1,y), (x-1,y), (x,y+1), (x,y-1)].filter wall)
def emb : Point → Nat ×ₗ (Int ×ₗ Int)
| (x, y) => (x.natAbs^2 + y.natAbs^2, x, y)
lemma emb_injective : Injective emb :=
fun ⟨x, y⟩ ⟨w, z⟩ h => by injection h
instance : LinearOrder Point := LinearOrder.lift' _ emb_injective
run_cmd Elab.Command.liftTermElabM do
let r :=
(← bestFirstSearch nbhd (10, 10) (maxQueued := some 4) |>.takeUpToFirst (· = (0,0)) |>.force)
if r ≠
[(10, 10), (11, 10), (9, 10), (8, 10), (7, 10), (6, 10), (6, 11), (6, 9), (7, 9), (6, 8),
(7, 8), (6, 7), (7, 7), (6, 6), (7, 6), (8, 6), (8, 7), (9, 6), (9, 7), (8, 8), (10, 6),
(9, 8), (8, 9), (10, 7), (11, 6), (9, 9), (11, 7), (10, 8), (12, 6), (10, 9), (11, 8),
(13, 6), (12, 7), (11, 9), (12, 8), (13, 7), (12, 9), (13, 8), (14, 7), (13, 9), (12, 10),
(14, 8), (13, 10), (12, 11), (15, 7), (14, 6), (15, 6), (15, 8), (14, 9), (16, 6), (15, 9),
(14, 10), (16, 8), (17, 6), (16, 7), (15, 10), (14, 11), (17, 7), (15, 11), (13, 11),
(13, 12), (14, 12), (12, 12), (11, 12), (10, 12), (9, 12), (8, 12), (7, 12), (6, 12), (6, 13),
(7, 13), (7, 11), (8, 11), (9, 11), (10, 11), (6, 14), (11, 11), (7, 14), (6, 15), (8, 14),
(7, 15), (9, 14), (8, 15), (8, 13), (9, 13), (10, 13), (6, 16), (11, 13), (10, 14), (12, 13),
(11, 14), (7, 16), (6, 17), (10, 15), (8, 16), (7, 17), (9, 16), (8, 17), (6, 18), (10, 16),
(9, 17), (9, 15), (8, 18), (11, 16), (10, 17), (12, 16), (11, 17), (11, 15), (12, 15),
(13, 15), (12, 14), (13, 14), (14, 14), (13, 13), (14, 13), (15, 13), (16, 13), (15, 14),
(15, 12), (16, 12), (17, 12), (16, 11), (17, 11), (16, 10), (17, 10), (16, 9), (17, 9),
(18, 9), (17, 8), (18, 8), (19, 8), (18, 7), (19, 7), (18, 6), (19, 6), (20, 6), (21, 6),
(20, 7), (20, 5), (21, 5), (20, 4), (21, 4), (20, 3), (21, 3), (19, 3), (18, 3), (17, 3),
(16, 3), (15, 3), (14, 3), (13, 3), (12, 3), (11, 3), (10, 3), (9, 3), (8, 3), (7, 3),
(6, 3), (5, 3), (4, 3), (3, 3), (2, 3), (1, 3), (0, 3), (-1, 3), (0, 4), (0, 2), (1, 2),
(-1, 2), (0, 1), (1, 1), (-1, 1), (0, 0)]
then throwError "Test failed!"
|
Basic.lean
|
/-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis
-/
import Mathlib.Algebra.Group.Torsion
import Mathlib.Algebra.Order.Group.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
/-!
# Lemmas about the interaction of power operations with order
-/
-- We should need only a minimal development of sets in order to get here.
assert_not_exists Set.Subsingleton
open Function Int
variable {α : Type*}
section OrderedCommGroup
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {m n : ℤ} {a b : α}
@[to_additive zsmul_left_strictMono]
lemma zpow_right_strictMono (ha : 1 < a) : StrictMono fun n : ℤ ↦ a ^ n := by
refine strictMono_int_of_lt_succ fun n ↦ ?_
rw [zpow_add_one]
exact lt_mul_of_one_lt_right' (a ^ n) ha
@[to_additive zsmul_left_strictAnti]
lemma zpow_right_strictAnti (ha : a < 1) : StrictAnti fun n : ℤ ↦ a ^ n := by
refine strictAnti_int_of_succ_lt fun n ↦ ?_
rw [zpow_add_one]
exact mul_lt_of_lt_one_right' (a ^ n) ha
@[to_additive zsmul_left_inj]
lemma zpow_right_inj (ha : 1 < a) {m n : ℤ} : a ^ m = a ^ n ↔ m = n :=
(zpow_right_strictMono ha).injective.eq_iff
@[to_additive zsmul_left_mono]
lemma zpow_right_mono (ha : 1 ≤ a) : Monotone fun n : ℤ ↦ a ^ n := by
refine monotone_int_of_le_succ fun n ↦ ?_
rw [zpow_add_one]
exact le_mul_of_one_le_right' ha
@[to_additive (attr := gcongr) zsmul_le_zsmul_left]
lemma zpow_le_zpow_right (ha : 1 ≤ a) (h : m ≤ n) : a ^ m ≤ a ^ n := zpow_right_mono ha h
@[to_additive (attr := gcongr) zsmul_lt_zsmul_left]
lemma zpow_lt_zpow_right (ha : 1 < a) (h : m < n) : a ^ m < a ^ n := zpow_right_strictMono ha h
@[to_additive zsmul_le_zsmul_iff_left]
lemma zpow_le_zpow_iff_right (ha : 1 < a) : a ^ m ≤ a ^ n ↔ m ≤ n :=
(zpow_right_strictMono ha).le_iff_le
@[to_additive zsmul_lt_zsmul_iff_left]
lemma zpow_lt_zpow_iff_right (ha : 1 < a) : a ^ m < a ^ n ↔ m < n :=
(zpow_right_strictMono ha).lt_iff_lt
variable (α)
@[to_additive zsmul_strictMono_right]
lemma zpow_left_strictMono (hn : 0 < n) : StrictMono ((· ^ n) : α → α) := fun a b hab => by
rw [← one_lt_div', ← div_zpow]; exact one_lt_zpow (one_lt_div'.2 hab) hn
@[to_additive zsmul_mono_right]
lemma zpow_left_mono (hn : 0 ≤ n) : Monotone ((· ^ n) : α → α) := fun a b hab => by
rw [← one_le_div', ← div_zpow]; exact one_le_zpow (one_le_div'.2 hab) hn
variable {α}
@[to_additive (attr := gcongr) zsmul_le_zsmul_right]
lemma zpow_le_zpow_left (hn : 0 ≤ n) (h : a ≤ b) : a ^ n ≤ b ^ n := zpow_left_mono α hn h
@[to_additive (attr := gcongr) zsmul_lt_zsmul_right]
lemma zpow_lt_zpow_left (hn : 0 < n) (h : a < b) : a ^ n < b ^ n := zpow_left_strictMono α hn h
end OrderedCommGroup
section LinearOrderedCommGroup
variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] {n : ℤ} {a b : α}
@[to_additive zsmul_le_zsmul_iff_right]
lemma zpow_le_zpow_iff_left (hn : 0 < n) : a ^ n ≤ b ^ n ↔ a ≤ b :=
(zpow_left_strictMono α hn).le_iff_le
@[to_additive zsmul_lt_zsmul_iff_right]
lemma zpow_lt_zpow_iff_left (hn : 0 < n) : a ^ n < b ^ n ↔ a < b :=
(zpow_left_strictMono α hn).lt_iff_lt
@[to_additive]
instance : IsMulTorsionFree α where pow_left_injective _ hn := (pow_left_strictMono hn).injective
variable (α) in
/-- A nontrivial densely linear ordered commutative group can't be a cyclic group. -/
@[to_additive
/-- A nontrivial densely linear ordered additive commutative group can't be a cyclic group. -/]
theorem not_isCyclic_of_denselyOrdered [DenselyOrdered α] [Nontrivial α] : ¬IsCyclic α := by
intro h
rcases exists_zpow_surjective α with ⟨a, ha⟩
rcases lt_trichotomy a 1 with hlt | rfl | hlt
· rcases exists_between hlt with ⟨b, hab, hb⟩
rcases ha b with ⟨k, rfl⟩
suffices 0 < k ∧ k < 1 by omega
rw [← one_lt_inv'] at hlt
simp_rw [← zpow_lt_zpow_iff_right hlt]
simp_all
· rcases exists_ne (1 : α) with ⟨b, hb⟩
simpa [hb.symm] using ha b
· rcases exists_between hlt with ⟨b, hb, hba⟩
rcases ha b with ⟨k, rfl⟩
suffices 0 < k ∧ k < 1 by omega
simp_rw [← zpow_lt_zpow_iff_right hlt]
simp_all
end LinearOrderedCommGroup
|
Semisimple.lean
|
/-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Module.Torsion
import Mathlib.FieldTheory.Perfect
import Mathlib.LinearAlgebra.AnnihilatingPolynomial
import Mathlib.RingTheory.Artinian.Instances
import Mathlib.RingTheory.Ideal.Quotient.Nilpotent
import Mathlib.RingTheory.SimpleModule.Basic
/-!
# Semisimple linear endomorphisms
Given an `R`-module `M` together with an `R`-linear endomorphism `f : M → M`, the following two
conditions are equivalent:
1. Every `f`-invariant submodule of `M` has an `f`-invariant complement.
2. `M` is a semisimple `R[X]`-module, where the action of the polynomial ring is induced by `f`.
A linear endomorphism `f` satisfying these equivalent conditions is known as a *semisimple*
endomorphism. We provide basic definitions and results about such endomorphisms in this file.
## Main definitions / results:
* `Module.End.IsSemisimple`: the definition that a linear endomorphism is semisimple
* `Module.End.isSemisimple_iff`: the characterisation of semisimplicity in terms of invariant
submodules.
* `Module.End.eq_zero_of_isNilpotent_isSemisimple`: the zero endomorphism is the only endomorphism
that is both nilpotent and semisimple.
* `Module.End.isSemisimple_of_squarefree_aeval_eq_zero`: an endomorphism that is a root of a
square-free polynomial is semisimple (in finite dimensions over a field).
* `Module.End.IsSemisimple.minpoly_squarefree`: the minimal polynomial of a semisimple
endomorphism is squarefree.
* `IsSemisimple.of_mem_adjoin_pair`: every endomorphism in the subalgebra generated by two
commuting semisimple endomorphisms is semisimple, if the base field is perfect.
## TODO
In finite dimensions over a field:
* Triangularizable iff diagonalisable for semisimple endomorphisms
-/
open Set Function Polynomial
variable {R M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
namespace Module.End
section CommRing
variable (f : End R M)
/-- A linear endomorphism of an `R`-module `M` is called *semisimple* if the induced `R[X]`-module
structure on `M` is semisimple. This is equivalent to saying that every `f`-invariant `R`-submodule
of `M` has an `f`-invariant complement: see `Module.End.isSemisimple_iff`. -/
def IsSemisimple := IsSemisimpleModule R[X] (AEval' f)
/-- A weaker version of semisimplicity that only prescribes behaviour on finitely-generated
submodules. -/
def IsFinitelySemisimple : Prop :=
∀ p (hp : p ∈ invtSubmodule f), Module.Finite R p → IsSemisimple (LinearMap.restrict f hp)
variable {f}
/-- A linear endomorphism is semisimple if every invariant submodule has in invariant complement.
See also `Module.End.isSemisimple_iff`. -/
lemma isSemisimple_iff' :
f.IsSemisimple ↔ ∀ p : invtSubmodule f, ∃ q : invtSubmodule f, IsCompl p q := by
rw [IsSemisimple, isSemisimpleModule_iff, (AEval.mapSubmodule R M f).symm.complementedLattice_iff,
complementedLattice_iff]
rfl
lemma isSemisimple_iff :
f.IsSemisimple ↔ ∀ p ∈ invtSubmodule f, ∃ q ∈ invtSubmodule f, IsCompl p q := by
simp [isSemisimple_iff']
lemma isSemisimple_restrict_iff (p) (hp : p ∈ invtSubmodule f) :
IsSemisimple (LinearMap.restrict f hp) ↔
∀ q ∈ f.invtSubmodule, q ≤ p → ∃ r ≤ p, r ∈ f.invtSubmodule ∧ Disjoint q r ∧ q ⊔ r = p := by
let e : Submodule R[X] (AEval' (f.restrict hp)) ≃o Iic (AEval.mapSubmodule R M f ⟨p, hp⟩) :=
(Submodule.orderIsoMapComap <| AEval.restrict_equiv_mapSubmodule f p hp).trans
(Submodule.mapIic _)
simp_rw [IsSemisimple, isSemisimpleModule_iff, e.complementedLattice_iff, disjoint_iff,
← (OrderIso.Iic _ _).complementedLattice_iff, Iic.complementedLattice_iff, Subtype.forall,
Subtype.exists, Subtype.mk_le_mk, Sublattice.mk_inf_mk, Sublattice.mk_sup_mk, Subtype.mk.injEq,
exists_and_left, exists_and_right, invtSubmodule.mk_eq_bot_iff, exists_prop, and_assoc]
rfl
/-- A linear endomorphism is finitely semisimple if it is semisimple on every finitely-generated
invariant submodule.
See also `Module.End.isFinitelySemisimple_iff`. -/
lemma isFinitelySemisimple_iff' :
f.IsFinitelySemisimple ↔ ∀ p (hp : p ∈ invtSubmodule f),
Module.Finite R p → IsSemisimple (LinearMap.restrict f hp) :=
Iff.rfl
/-- A characterisation of `Module.End.IsFinitelySemisimple` using only the lattice of submodules of
`M` (thus avoiding submodules of submodules). -/
lemma isFinitelySemisimple_iff :
f.IsFinitelySemisimple ↔ ∀ p ∈ invtSubmodule f, Module.Finite R p → ∀ q ∈ invtSubmodule f,
q ≤ p → ∃ r, r ≤ p ∧ r ∈ invtSubmodule f ∧ Disjoint q r ∧ q ⊔ r = p := by
simp_rw [isFinitelySemisimple_iff', isSemisimple_restrict_iff]
@[simp]
lemma isSemisimple_zero [IsSemisimpleModule R M] : IsSemisimple (0 : Module.End R M) := by
simpa [isSemisimple_iff] using exists_isCompl
@[simp]
lemma isSemisimple_id [IsSemisimpleModule R M] : IsSemisimple (LinearMap.id : Module.End R M) := by
simpa [isSemisimple_iff] using exists_isCompl
@[simp] lemma isSemisimple_neg : (-f).IsSemisimple ↔ f.IsSemisimple := by
simp [isSemisimple_iff, mem_invtSubmodule]
variable (f) in
protected lemma _root_.LinearEquiv.isSemisimple_iff {M₂ : Type*} [AddCommGroup M₂] [Module R M₂]
(g : End R M₂) (e : M ≃ₗ[R] M₂) (he : e ∘ₗ f = g ∘ₗ e) :
f.IsSemisimple ↔ g.IsSemisimple := by
let e : AEval' f ≃ₗ[R[X]] AEval' g := LinearEquiv.ofAEval _ (e.trans (AEval'.of g)) fun x ↦ by
simpa [AEval'.X_smul_of] using LinearMap.congr_fun he x
simp_rw [IsSemisimple, isSemisimpleModule_iff,
(Submodule.orderIsoMapComap e).complementedLattice_iff]
lemma eq_zero_of_isNilpotent_isSemisimple (hn : IsNilpotent f) (hs : f.IsSemisimple) : f = 0 := by
have ⟨n, h0⟩ := hn
rw [← aeval_X (R := R) f]; rw [← aeval_X_pow (R := R) f] at h0
rw [← RingHom.mem_ker, ← AEval.annihilator_eq_ker_aeval (M := M)] at h0 ⊢
exact hs.annihilator_isRadical _ _ ⟨n, h0⟩
lemma eq_zero_of_isNilpotent_of_isFinitelySemisimple
(hn : IsNilpotent f) (hs : IsFinitelySemisimple f) : f = 0 := by
have (p) (hp₁ : p ∈ f.invtSubmodule) (hp₂ : Module.Finite R p) : f.restrict hp₁ = 0 := by
specialize hs p hp₁ hp₂
replace hn : IsNilpotent (f.restrict hp₁) := isNilpotent.restrict hp₁ hn
exact eq_zero_of_isNilpotent_isSemisimple hn hs
ext x
obtain ⟨k : ℕ, hk : f ^ k = 0⟩ := hn
let p := Submodule.span R {(f ^ i) x | (i : ℕ) (_ : i ≤ k)}
have hp₁ : p ∈ f.invtSubmodule := by
simp only [mem_invtSubmodule, p, Submodule.span_le]
rintro - ⟨i, hi, rfl⟩
apply Submodule.subset_span
rcases lt_or_eq_of_le hi with hik | rfl
· exact ⟨i + 1, hik, by simpa [Module.End.pow_apply] using iterate_succ_apply' f i x⟩
· exact ⟨i, by simp [hk]⟩
have hp₂ : Module.Finite R p := by
let g : ℕ → M := fun i ↦ (f ^ i) x
have hg : {(f ^ i) x | (i : ℕ) (_ : i ≤ k)} = g '' Iic k := by ext; simp [g]
exact Module.Finite.span_of_finite _ <| hg ▸ toFinite (g '' Iic k)
simpa [LinearMap.restrict_apply, Subtype.ext_iff] using
LinearMap.congr_fun (this p hp₁ hp₂) ⟨x, Submodule.subset_span ⟨0, k.zero_le, rfl⟩⟩
@[simp]
lemma isSemisimple_sub_algebraMap_iff {μ : R} :
(f - algebraMap R (End R M) μ).IsSemisimple ↔ f.IsSemisimple := by
suffices ∀ p : Submodule R M, p ≤ p.comap (f - algebraMap R (Module.End R M) μ) ↔ p ≤ p.comap f by
simp [mem_invtSubmodule, isSemisimple_iff, this]
refine fun p ↦ ⟨fun h x hx ↦ ?_, fun h x hx ↦ p.sub_mem (h hx) (p.smul_mem μ hx)⟩
simpa using p.add_mem (h hx) (p.smul_mem μ hx)
lemma IsSemisimple.restrict {p : Submodule R M} (hp : p ∈ f.invtSubmodule) (hf : f.IsSemisimple) :
IsSemisimple (f.restrict hp) := by
rw [IsSemisimple] at hf ⊢
let e : Submodule R[X] (AEval' (LinearMap.restrict f hp)) ≃o
Iic (AEval.mapSubmodule R M f ⟨p, hp⟩) :=
(Submodule.orderIsoMapComap <| AEval.restrict_equiv_mapSubmodule f p hp).trans <|
Submodule.mapIic _
exact (isSemisimpleModule_iff ..).mpr (e.complementedLattice_iff.mpr inferInstance)
lemma IsSemisimple.isFinitelySemisimple (hf : f.IsSemisimple) :
f.IsFinitelySemisimple :=
isFinitelySemisimple_iff'.mp fun _ _ _ ↦ hf.restrict _
@[simp]
lemma isFinitelySemisimple_iff_isSemisimple [Module.Finite R M] :
f.IsFinitelySemisimple ↔ f.IsSemisimple := by
refine ⟨fun hf ↦ isSemisimple_iff.mpr fun p hp ↦ ?_, IsSemisimple.isFinitelySemisimple⟩
obtain ⟨q, -, hq₁, hq₂, hq₃⟩ :=
isFinitelySemisimple_iff.mp hf ⊤ (invtSubmodule.top_mem f) inferInstance p hp le_top
exact ⟨q, hq₁, hq₂, codisjoint_iff.mpr hq₃⟩
@[simp]
lemma isFinitelySemisimple_sub_algebraMap_iff {μ : R} :
(f - algebraMap R (End R M) μ).IsFinitelySemisimple ↔ f.IsFinitelySemisimple := by
suffices ∀ p : Submodule R M, p ≤ p.comap (f - algebraMap R (Module.End R M) μ) ↔ p ≤ p.comap f by
simp_rw [isFinitelySemisimple_iff, mem_invtSubmodule, this]
refine fun p ↦ ⟨fun h x hx ↦ ?_, fun h x hx ↦ p.sub_mem (h hx) (p.smul_mem μ hx)⟩
simpa using p.add_mem (h hx) (p.smul_mem μ hx)
lemma IsFinitelySemisimple.restrict {p : Submodule R M} (hp : p ∈ f.invtSubmodule)
(hf : f.IsFinitelySemisimple) :
IsFinitelySemisimple (f.restrict hp) := by
intro q hq₁ hq₂
have := invtSubmodule.map_subtype_mem_of_mem_invtSubmodule f hp hq₁
let e : q ≃ₗ[R] q.map p.subtype := p.equivSubtypeMap q
rw [e.isSemisimple_iff ((LinearMap.restrict f hp).restrict hq₁) (LinearMap.restrict f this) rfl]
exact hf _ this (Finite.map q p.subtype)
end CommRing
section field
variable {K : Type*} [Field K] [Module K M] {f g : End K M}
lemma IsSemisimple_smul_iff {t : K} (ht : t ≠ 0) :
(t • f).IsSemisimple ↔ f.IsSemisimple := by
simp [isSemisimple_iff, mem_invtSubmodule, Submodule.comap_smul f (h := ht)]
lemma IsSemisimple_smul (t : K) (h : f.IsSemisimple) :
(t • f).IsSemisimple := by
wlog ht : t ≠ 0; · simp [not_not.mp ht]
rwa [IsSemisimple_smul_iff ht]
theorem isSemisimple_of_squarefree_aeval_eq_zero {p : K[X]}
(hp : Squarefree p) (hpf : aeval f p = 0) : f.IsSemisimple := by
rw [← RingHom.mem_ker, ← AEval.annihilator_eq_ker_aeval (M := M), mem_annihilator,
← IsTorsionBy, ← isTorsionBySet_singleton_iff, isTorsionBySet_iff_is_torsion_by_span] at hpf
let R := K[X] ⧸ Ideal.span {p}
have : IsReduced R :=
(Ideal.isRadical_iff_quotient_reduced _).mp (isRadical_iff_span_singleton.mp hp.isRadical)
have : FiniteDimensional K R := (AdjoinRoot.powerBasis hp.ne_zero).finite
have : IsArtinianRing R := .of_finite K R
have : IsSemisimpleRing R := IsArtinianRing.isSemisimpleRing_of_isReduced R
letI : Module R (AEval' f) := Module.IsTorsionBySet.module hpf
let e : AEval' f →ₛₗ[Ideal.Quotient.mk (Ideal.span {p})] AEval' f :=
{ AddMonoidHom.id _ with map_smul' := fun _ _ ↦ rfl }
exact (e.isSemisimpleModule_iff_of_bijective bijective_id).mpr inferInstance
variable [FiniteDimensional K M]
section
variable (hf : f.IsSemisimple)
include hf
/-- The minimal polynomial of a semisimple endomorphism is square free -/
theorem IsSemisimple.minpoly_squarefree : Squarefree (minpoly K f) :=
IsRadical.squarefree (minpoly.ne_zero <| Algebra.IsIntegral.isIntegral _) <| by
rw [isRadical_iff_span_singleton, span_minpoly_eq_annihilator]; exact hf.annihilator_isRadical
protected theorem IsSemisimple.aeval (p : K[X]) : (aeval f p).IsSemisimple :=
let R := K[X] ⧸ Ideal.span {minpoly K f}
have : Module.Finite K R :=
(AdjoinRoot.powerBasis' <| minpoly.monic <| Algebra.IsIntegral.isIntegral f).finite
have : IsReduced R := (Ideal.isRadical_iff_quotient_reduced _).mp <|
span_minpoly_eq_annihilator K f ▸ hf.annihilator_isRadical
isSemisimple_of_squarefree_aeval_eq_zero ((minpoly.isRadical K _).squarefree <|
minpoly.ne_zero <| .of_finite K <| Ideal.Quotient.mkₐ K (.span {minpoly K f}) p) <| by
rw [← Ideal.Quotient.liftₐ_comp (.span {minpoly K f}) (aeval f)
fun a h ↦ by rwa [Ideal.span, ← minpoly.ker_aeval_eq_span_minpoly] at h, aeval_algHom,
AlgHom.comp_apply, AlgHom.comp_apply, ← aeval_algHom_apply, minpoly.aeval, map_zero]
theorem IsSemisimple.of_mem_adjoin_singleton {a : End K M}
(ha : a ∈ Algebra.adjoin K {f}) : a.IsSemisimple := by
rw [Algebra.adjoin_singleton_eq_range_aeval] at ha; obtain ⟨p, rfl⟩ := ha; exact .aeval hf _
protected theorem IsSemisimple.pow (n : ℕ) : (f ^ n).IsSemisimple :=
.of_mem_adjoin_singleton hf (pow_mem (Algebra.self_mem_adjoin_singleton _ _) _)
end
section PerfectField
variable [PerfectField K] (comm : Commute f g) (hf : f.IsSemisimple) (hg : g.IsSemisimple)
include comm hf hg
attribute [local simp] Submodule.Quotient.quot_mk_eq_mk in
theorem IsSemisimple.of_mem_adjoin_pair {a : End K M} (ha : a ∈ Algebra.adjoin K {f, g}) :
a.IsSemisimple := by
let R := K[X] ⧸ Ideal.span {minpoly K f}
let S := AdjoinRoot ((minpoly K g).map <| algebraMap K R)
have : Module.Finite K R :=
(AdjoinRoot.powerBasis' <| minpoly.monic <| Algebra.IsIntegral.isIntegral f).finite
have : Module.Finite R S :=
(AdjoinRoot.powerBasis' <| (minpoly.monic <| Algebra.IsIntegral.isIntegral g).map _).finite
have : IsScalarTower K R S := .of_algebraMap_eq fun _ ↦ rfl
have : Module.Finite K S := .trans R S
have : IsArtinianRing R := .of_finite K R
have : IsReduced R := (Ideal.isRadical_iff_quotient_reduced _).mp <|
span_minpoly_eq_annihilator K f ▸ hf.annihilator_isRadical
have : IsReduced S := by
simp_rw [S, AdjoinRoot, ← Ideal.isRadical_iff_quotient_reduced, ← isRadical_iff_span_singleton]
exact (PerfectField.separable_iff_squarefree.mpr hg.minpoly_squarefree).map.squarefree.isRadical
let φ : S →ₐ[K] End K M := Ideal.Quotient.liftₐ _ (eval₂AlgHom' (Ideal.Quotient.liftₐ _ (aeval f)
fun a ↦ ?_) g ?_) ((Ideal.span_singleton_le_iff_mem _).mpr ?_ : _ ≤ RingHom.ker _)
rotate_left 1
· rw [Ideal.span, ← minpoly.ker_aeval_eq_span_minpoly]; exact id
· rintro ⟨p⟩; exact p.induction_on (fun k ↦ by simp [R, Algebra.commute_algebraMap_left])
(fun p q hp hq ↦ by simpa [R] using hp.add_left hq)
fun n k ↦ by simpa [R, pow_succ, ← mul_assoc _ _ X] using (·.mul_left comm)
· simpa only [RingHom.mem_ker, eval₂AlgHom'_apply, eval₂_map, AlgHom.comp_algebraMap_of_tower]
using minpoly.aeval K g
have : Algebra.adjoin K {f, g} ≤ φ.range := Algebra.adjoin_le fun x ↦ by
rintro (hx | hx) <;> rw [hx]
· exact ⟨AdjoinRoot.of _ (AdjoinRoot.root _), (eval₂_C _ _).trans (aeval_X f)⟩
· exact ⟨AdjoinRoot.root _, eval₂_X _ _⟩
obtain ⟨p, rfl⟩ := (AlgHom.mem_range _).mp (this ha)
refine isSemisimple_of_squarefree_aeval_eq_zero
((minpoly.isRadical K p).squarefree <| minpoly.ne_zero <| .of_finite K p) ?_
rw [aeval_algHom, φ.comp_apply, minpoly.aeval, map_zero]
theorem IsSemisimple.add_of_commute : (f + g).IsSemisimple := .of_mem_adjoin_pair
comm hf hg <| add_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl)
theorem IsSemisimple.sub_of_commute : (f - g).IsSemisimple := .of_mem_adjoin_pair
comm hf hg <| sub_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl)
theorem IsSemisimple.mul_of_commute : (f * g).IsSemisimple := .of_mem_adjoin_pair
comm hf hg <| mul_mem (Algebra.subset_adjoin <| .inl rfl) (Algebra.subset_adjoin <| .inr rfl)
end PerfectField
end field
end Module.End
|
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.
|
Module.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.RingTheory.Spectrum.Prime.Topology
import Mathlib.RingTheory.Support
/-!
# Subsets of prime spectra related to modules
## Main results
- `LocalizedModule.subsingleton_iff_disjoint` : `M[1/f] = 0 ↔ D(f) ∩ Supp M = 0`.
- `Module.isClosed_support` : If `M` is a finite `R`-module, then `Supp M` is closed.
## TODO
- If `M` is finitely presented, the complement of `Supp M` is quasi-compact. (stacks#051B)
-/
variable {R A M : Type*} [CommRing R] [AddCommGroup M] [Module R M]
[CommRing A] [Algebra R A] [Module A M]
variable (R M) in
lemma IsLocalRing.closedPoint_mem_support [IsLocalRing R] [Nontrivial M] :
IsLocalRing.closedPoint R ∈ Module.support R M := by
obtain ⟨p, hp⟩ := (Module.nonempty_support_iff (R := R)).mpr ‹_›
exact Module.mem_support_mono le_top hp
/-- `M[1/f] = 0` if and only if `D(f) ∩ Supp M = 0`. -/
lemma LocalizedModule.subsingleton_iff_disjoint {f : R} :
Subsingleton (LocalizedModule (.powers f) M) ↔
Disjoint ↑(PrimeSpectrum.basicOpen f) (Module.support R M) := by
rw [subsingleton_iff_support_subset, PrimeSpectrum.basicOpen_eq_zeroLocus_compl,
disjoint_compl_left_iff, Set.le_iff_subset]
lemma Module.stableUnderSpecialization_support :
StableUnderSpecialization (Module.support R M) := by
intros x y e H
rw [mem_support_iff_exists_annihilator] at H ⊢
obtain ⟨m, hm⟩ := H
exact ⟨m, hm.trans ((PrimeSpectrum.le_iff_specializes _ _).mpr e)⟩
lemma Module.isClosed_support [Module.Finite R M] :
IsClosed (Module.support R M) := by
rw [support_eq_zeroLocus]
apply PrimeSpectrum.isClosed_zeroLocus
lemma Module.support_subset_preimage_comap [IsScalarTower R A M] :
Module.support A M ⊆ PrimeSpectrum.comap (algebraMap R A) ⁻¹' Module.support R M := by
intro x hx
simp only [Set.mem_preimage, mem_support_iff', PrimeSpectrum.comap_asIdeal, Ideal.mem_comap,
ne_eq, not_imp_not] at hx ⊢
obtain ⟨m, hm⟩ := hx
exact ⟨m, fun r e ↦ hm _ (by simpa)⟩
|
alt.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice.
From mathcomp Require Import div fintype tuple tuple bigop prime finset ssralg.
From mathcomp Require Import zmodp fingroup morphism perm automorphism quotient.
From mathcomp Require Import action cyclic pgroup gseries sylow.
From mathcomp Require Import primitive_action nilpotent maximal.
(******************************************************************************)
(* Definitions of the symmetric and alternate groups, and some properties. *)
(* 'Sym_T == The symmetric group over type T (which must have a finType *)
(* structure). *)
(* := [set: {perm T}] *)
(* 'Alt_T == The alternating group over type T. *)
(******************************************************************************)
Unset Printing Implicit Defensive.
Set Implicit Arguments.
Unset Strict Implicit.
Import GroupScope GRing.
HB.instance Definition _ := isMulGroup.Build bool addbA addFb addbb.
Section SymAltDef.
Variable T : finType.
Implicit Types (s : {perm T}) (x y z : T).
(** Definitions of the alternate groups and some Properties **)
Definition Sym : {set {perm T}} := setT.
Canonical Sym_group := Eval hnf in [group of Sym].
Local Notation "'Sym_T" := Sym.
Canonical sign_morph := @Morphism _ _ 'Sym_T _ (in2W (@odd_permM _)).
Definition Alt := 'ker (@odd_perm T).
Canonical Alt_group := Eval hnf in [group of Alt].
Local Notation "'Alt_T" := Alt.
Lemma Alt_even p : (p \in 'Alt_T) = ~~ p.
Proof. by rewrite !inE /=; case: odd_perm. Qed.
Lemma Alt_subset : 'Alt_T \subset 'Sym_T.
Proof. exact: subsetT. Qed.
Lemma Alt_normal : 'Alt_T <| 'Sym_T.
Proof. exact: ker_normal. Qed.
Lemma Alt_norm : 'Sym_T \subset 'N('Alt_T).
Proof. by case/andP: Alt_normal. Qed.
Let n := #|T|.
Lemma Alt_index : 1 < n -> #|'Sym_T : 'Alt_T| = 2.
Proof.
move=> lt1n; rewrite -card_quotient ?Alt_norm //=.
have : ('Sym_T / 'Alt_T) \isog (@odd_perm T @* 'Sym_T) by apply: first_isog.
case/isogP=> g /injmP/card_in_imset <-.
rewrite /morphim setIid=> ->; rewrite -card_bool; apply: eq_card => b.
apply/imsetP; case: b => /=; last first.
by exists (1 : {perm T}); [rewrite setIid inE | rewrite odd_perm1].
case: (pickP T) lt1n => [x1 _ | d0]; last by rewrite /n eq_card0.
rewrite /n (cardD1 x1) ltnS lt0n => /existsP[x2 /=].
by rewrite eq_sym andbT -odd_tperm; exists (tperm x1 x2); rewrite ?inE.
Qed.
Lemma card_Sym : #|'Sym_T| = n`!.
Proof.
rewrite -[n]cardsE -card_perm; apply: eq_card => p.
by apply/idP/subsetP=> [? ?|]; rewrite !inE.
Qed.
Lemma card_Alt : 1 < n -> (2 * #|'Alt_T|)%N = n`!.
Proof.
by move/Alt_index <-; rewrite mulnC (Lagrange Alt_subset) card_Sym.
Qed.
Lemma Sym_trans : [transitive^n 'Sym_T, on setT | 'P].
Proof.
apply/imsetP; pose t1 := [tuple of enum T].
have dt1: t1 \in n.-dtuple(setT) by rewrite inE enum_uniq; apply/subsetP.
exists t1 => //; apply/setP=> t; apply/idP/imsetP=> [|[a _ ->{t}]]; last first.
by apply: n_act_dtuple => //; apply/astabsP=> x; rewrite !inE.
case/dtuple_onP=> injt _; have injf := inj_comp injt enum_rank_inj.
exists (perm injf); first by rewrite inE.
apply: eq_from_tnth => i; rewrite tnth_map /= [aperm _ _]permE; congr tnth.
by rewrite (tnth_nth (enum_default i)) enum_valK.
Qed.
Lemma Alt_trans : [transitive^n.-2 'Alt_T, on setT | 'P].
Proof.
case n_m2: n Sym_trans => [|[|m]] /= tr_m2; try exact: ntransitive0.
have tr_m := ntransitive_weak (leqW (leqnSn m)) tr_m2.
case/imsetP: tr_m2; case/tupleP=> x; case/tupleP=> y t.
rewrite !dtuple_on_add 2![x \in _]inE inE negb_or /= -!andbA.
case/and4P=> nxy ntx nty dt _; apply/imsetP; exists t => //; apply/setP=> u.
apply/idP/imsetP=> [|[a _ ->{u}]]; last first.
by apply: n_act_dtuple => //; apply/astabsP=> z; rewrite !inE.
case/(atransP2 tr_m dt)=> /= a _ ->{u}.
case odd_a: (odd_perm a); last by exists a => //; rewrite !inE /= odd_a.
exists (tperm x y * a); first by rewrite !inE /= odd_permM odd_tperm nxy odd_a.
apply/val_inj/eq_in_map => z tz; rewrite actM /= /aperm; congr (a _).
by case: tpermP ntx nty => // <-; rewrite tz.
Qed.
Lemma aperm_faithful (A : {group {perm T}}) : [faithful A, on setT | 'P].
Proof.
by apply/faithfulP=> /= p _ np1; apply/eqP/perm_act1P=> y; rewrite np1 ?inE.
Qed.
End SymAltDef.
Arguments Sym T%_type.
Arguments Sym_group T%_type.
Arguments Alt T%_type.
Arguments Alt_group T%_type.
Notation "''Sym_' T" := (Sym T)
(at level 8, T at level 2, format "''Sym_' T") : group_scope.
Notation "''Sym_' T" := (Sym_group T) : Group_scope.
Notation "''Alt_' T" := (Alt T)
(at level 8, T at level 2, format "''Alt_' T") : group_scope.
Notation "''Alt_' T" := (Alt_group T) : Group_scope.
Lemma trivial_Alt_2 (T : finType) : #|T| <= 2 -> 'Alt_T = 1.
Proof.
rewrite leq_eqVlt => /predU1P[] oT.
by apply: card_le1_trivg; rewrite -leq_double -mul2n card_Alt oT.
suffices Sym1: 'Sym_T = 1 by apply/trivgP; rewrite -Sym1 subsetT.
by apply: card1_trivg; rewrite card_Sym; case: #|T| oT; do 2?case.
Qed.
Lemma simple_Alt_3 (T : finType) : #|T| = 3 -> simple 'Alt_T.
Proof.
move=> T3; have{T3} oA: #|'Alt_T| = 3.
by apply: double_inj; rewrite -mul2n card_Alt T3.
apply/simpleP; split=> [|K]; [by rewrite trivg_card1 oA | case/andP=> sKH _].
have:= cardSg sKH; rewrite oA dvdn_divisors // !inE orbC /= -oA.
case/pred2P=> eqK; [right | left]; apply/eqP.
by rewrite eqEcard sKH eqK leqnn.
by rewrite eq_sym eqEcard sub1G eqK cards1.
Qed.
Lemma not_simple_Alt_4 (T : finType) : #|T| = 4 -> ~~ simple 'Alt_T.
Proof.
move=> oT; set A := 'Alt_T.
have oA: #|A| = 12 by apply: double_inj; rewrite -mul2n card_Alt oT.
suffices [p]: exists p, [/\ prime p, 1 < #|A|`_p < #|A| & #|'Syl_p(A)| == 1%N].
case=> p_pr pA_int; rewrite /A; case/normal_sylowP=> P; case/pHallP.
rewrite /= -/A => sPA pP nPA; apply/simpleP=> [] [_]; rewrite -pP in pA_int.
by case/(_ P)=> // defP; rewrite defP oA ?cards1 in pA_int.
have: #|'Syl_3(A)| \in filter [pred d | d %% 3 == 1%N] (divisors 12).
by rewrite mem_filter -dvdn_divisors //= -oA card_Syl_dvd ?card_Syl_mod.
rewrite /= oA mem_seq2 orbC.
case/predU1P=> [oQ3|]; [exists 2 | exists 3]; split; rewrite ?p_part //.
pose A3 := [set x : {perm T} | #[x] == 3]; suffices oA3: #|A :&: A3| = 8.
have sQ2 P: P \in 'Syl_2(A) -> P :=: A :\: A3.
rewrite inE pHallE oA p_part -natTrecE /= => /andP[sPA /eqP oP].
apply/eqP; rewrite eqEcard -(leq_add2l 8) -{1}oA3 cardsID oA oP.
rewrite andbT subsetD sPA; apply/exists_inP=> -[x] /= Px.
by rewrite inE => /eqP ox; have:= order_dvdG Px; rewrite oP ox.
have [/= P sylP] := Sylow_exists 2 [group of A].
rewrite -(([set P] =P 'Syl_2(A)) _) ?cards1 // eqEsubset sub1set inE sylP.
by apply/subsetP=> Q sylQ; rewrite inE -val_eqE /= !sQ2 // inE.
rewrite -[8]/(4 * 2)%N -{}oQ3 -sum1_card -sum_nat_const.
rewrite (partition_big (fun x => <[x]>%G) [in 'Syl_3(A)]) => [|x]; last first.
by case/setIP=> Ax; rewrite /= !inE pHallE p_part cycle_subG Ax oA.
apply: eq_bigr => Q; rewrite inE pHallE oA p_part -?natTrecE //=.
case/andP=> sQA /eqP oQ; have:= oQ.
rewrite (cardsD1 1) group1 -sum1_card => [[/= <-]]; apply: eq_bigl => x.
rewrite setIC -val_eqE /= 2!inE in_setD1 -andbA -{4}[x]expg1 -order_dvdn dvdn1.
apply/and3P/andP=> [[/eqP-> _ /eqP <-] | [ntx Qx]]; first by rewrite cycle_id.
have:= order_dvdG Qx; rewrite oQ dvdn_divisors // mem_seq2 (negPf ntx) /=.
by rewrite eqEcard cycle_subG Qx (subsetP sQA) // oQ /order => /eqP->.
Qed.
Lemma simple_Alt5_base (T : finType) : #|T| = 5 -> simple 'Alt_T.
Proof.
move=> oT.
have F1: #|'Alt_T| = 60 by apply: double_inj; rewrite -mul2n card_Alt oT.
have FF (H : {group {perm T}}): H <| 'Alt_T -> H :<>: 1 -> 20 %| #|H|.
- move=> Hh1 Hh3.
have [x _]: exists x, x \in T by apply/existsP/eqP; rewrite oT.
have F2 := Alt_trans T; rewrite oT /= in F2.
have F3: [transitive 'Alt_T, on setT | 'P] by apply: ntransitive1 F2.
have F4: [primitive 'Alt_T, on setT | 'P] by apply: ntransitive_primitive F2.
case: (prim_trans_norm F4 Hh1) => F5.
by case: Hh3; apply/trivgP; apply: subset_trans F5 (aperm_faithful _).
have F6: 5 %| #|H| by rewrite -oT -cardsT (atrans_dvd F5).
have F7: 4 %| #|H|.
have F7: #|[set~ x]| = 4 by rewrite cardsC1 oT.
case: (pickP [in [set~ x]]) => [y Hy | ?]; last by rewrite eq_card0 in F7.
pose K := 'C_H[x | 'P]%G.
have F8 : K \subset H by apply: subsetIl.
pose Gx := 'C_('Alt_T)[x | 'P]%G.
have F9: [transitive^2 Gx, on [set~ x] | 'P].
by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE.
have F10: [transitive Gx, on [set~ x] | 'P].
exact: ntransitive1 F9.
have F11: [primitive Gx, on [set~ x] | 'P].
exact: ntransitive_primitive F9.
have F12: K \subset Gx by apply: setSI; apply: normal_sub.
have F13: K <| Gx by rewrite /(K <| _) F12 normsIG // normal_norm.
case: (prim_trans_norm F11 F13) => Ksub; last first.
by apply: dvdn_trans (cardSg F8); rewrite -F7; apply: atrans_dvd Ksub.
have F14: [faithful Gx, on [set~ x] | 'P].
apply/subsetP=> g; do 2![case/setIP] => Altg cgx cgx'.
apply: (subsetP (aperm_faithful 'Alt_T)).
rewrite inE Altg /=; apply/astabP=> z _.
case: (z =P x) => [->|]; first exact: (astab1P cgx).
by move/eqP=> nxz; rewrite (astabP cgx') ?inE //.
have Hreg g (z : T): g \in H -> g z = z -> g = 1.
have F15 h: h \in H -> h x = x -> h = 1.
move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P.
by rewrite (trivGP (subset_trans Ksub F14)) => /set1P.
move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //.
case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g.
apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz.
by case/normalP: Hh1 => _ nH1; rewrite -(nH1 _ Hg1) memJ_conjg.
clear K F8 F12 F13 Ksub F14.
case: (Cauchy _ F6) => // h Hh /eqP Horder.
have diff_hnx_x n: 0 < n -> n < 5 -> x != (h ^+ n) x.
move=> Hn1 Hn2; rewrite eq_sym; apply/negP => HH.
have: #[h ^+ n] = 5.
rewrite orderXgcd // (eqP Horder).
by move: Hn1 Hn2 {HH}; do 5 (case: n => [|n] //).
have Hhd2: h ^+ n \in H by rewrite groupX.
by rewrite (Hreg _ _ Hhd2 (eqP HH)) order1.
pose S1 := [tuple x; h x; (h ^+ 3) x].
have DnS1: S1 \in 3.-dtuple(setT).
rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT.
rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM.
by rewrite (inj_eq perm_inj) diff_hnx_x.
pose S2 := [tuple x; h x; (h ^+ 2) x].
have DnS2: S2 \in 3.-dtuple(setT).
rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT.
rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM.
by rewrite (inj_eq perm_inj) diff_hnx_x.
case: (atransP2 F2 DnS1 DnS2) => g Hg [/=].
rewrite /aperm => Hgx Hghx Hgh3x.
have h_g_com: h * g = g * h.
suff HH: (g * h * g^-1) * h^-1 = 1 by rewrite -[h * g]mul1g -HH !gnorm.
apply: (Hreg _ x); last first.
by rewrite !permM -Hgx Hghx -!permM mulKVg mulgV perm1.
rewrite groupM // ?groupV // (conjgCV g) mulgK -mem_conjg.
by case/normalP: Hh1 => _ ->.
have: (g * (h ^+ 2) * g ^-1) x = (h ^+ 3) x.
rewrite !permM -Hgx.
have ->: h (h x) = (h ^+ 2) x by rewrite /= permM.
by rewrite {1}Hgh3x -!permM /= mulgV mulg1 -expgSr.
rewrite commuteX // mulgK {1}[expgn]lock expgS permM -lock.
by move/perm_inj=> eqxhx; case/eqP: (diff_hnx_x 1%N isT isT); rewrite expg1.
by rewrite (@Gauss_dvd 4 5) // F7.
apply/simpleP; split => [|H Hnorm]; first by rewrite trivg_card1 F1.
case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1.
by left; apply: card1_trivg; rewrite Hcard1.
right; case Hcard60: (#|H| == 60); move/eqP: Hcard60 => Hcard60.
by apply/eqP; rewrite eqEcard Hcard60 F1 andbT; case/andP: Hnorm.
have {Hcard1 Hcard60} Hcard20: #|H| = 20.
have Hdiv: 20 %| #|H| by apply: FF => // HH; case Hcard1; rewrite HH cards1.
case H20: (#|H| == 20); first exact/eqP.
case: Hcard60; case/andP: Hnorm; move/cardSg; rewrite F1 => Hdiv1 _.
by case/dvdnP: Hdiv H20 Hdiv1 => n ->; move: n; do 4!case=> //.
have prime_5: prime 5 by [].
have nSyl5: #|'Syl_5(H)| = 1%N.
move: (card_Syl_dvd 5 H) (card_Syl_mod H prime_5).
rewrite Hcard20; case: (card _) => // n Hdiv.
move: (dvdn_leq (isT: (0 < 20)%N) Hdiv).
by move: (n) Hdiv; do 20 (case=> //).
case: (Sylow_exists 5 H) => S; case/pHallP=> sSH oS.
have{} oS: #|S| = 5 by rewrite oS p_part Hcard20.
suff: 20 %| #|S| by rewrite oS.
apply: FF => [|S1]; last by rewrite S1 cards1 in oS.
apply: char_normal_trans Hnorm; apply: lone_subgroup_char => // Q sQH isoQS.
rewrite subEproper; apply/norP=> [[nQS _]]; move: nSyl5.
rewrite (cardsD1 S) (cardsD1 Q) 4!{1}inE nQS !pHallE sQH sSH Hcard20 p_part.
by rewrite (card_isog isoQS) oS.
Qed.
Section Restrict.
Variables (T : finType) (x : T).
Notation T' := {y | y != x}.
Lemma rfd_funP (p : {perm T}) (u : T') :
let p1 := if p x == x then p else 1 in p1 (val u) != x.
Proof.
case: (p x =P x) => /= [pxx | _]; last by rewrite perm1 (valP u).
by rewrite -[x in _ != x]pxx (inj_eq perm_inj); apply: (valP u).
Qed.
Definition rfd_fun p := [fun u => Sub ((_ : {perm T}) _) (rfd_funP p u) : T'].
Lemma rfdP p : injective (rfd_fun p).
Proof.
apply: can_inj (rfd_fun p^-1) _ => u; apply: val_inj => /=.
rewrite -(can_eq (permK p)) permKV eq_sym.
by case: eqP => _; rewrite !(perm1, permK).
Qed.
Definition rfd p := perm (@rfdP p).
Hypothesis card_T : 2 < #|T|.
Lemma rfd_morph : {in 'C_('Sym_T)[x | 'P] &, {morph rfd : y z / y * z}}.
Proof.
move=> p q; rewrite !setIA !setIid; move/astab1P=> p_x; move/astab1P=> q_x.
apply/permP=> u; apply: val_inj.
by rewrite permE /= !permM !permE /= [p x]p_x [q x]q_x eqxx permM /=.
Qed.
Canonical rfd_morphism := Morphism rfd_morph.
Definition rgd_fun (p : {perm T'}) :=
[fun x1 => if insub x1 is Some u then sval (p u) else x].
Lemma rgdP p : injective (rgd_fun p).
Proof.
apply: can_inj (rgd_fun p^-1) _ => y /=.
case: (insubP _ y) => [u _ val_u|]; first by rewrite valK permK.
by rewrite negbK; move/eqP->; rewrite insubF //= eqxx.
Qed.
Definition rgd p := perm (@rgdP p).
Lemma rfd_odd (p : {perm T}) : p x = x -> rfd p = p :> bool.
Proof.
have rfd1: rfd 1 = 1.
by apply/permP => u; apply: val_inj; rewrite permE /= if_same !perm1.
have [n] := ubnP #|[set x | p x != x]|; elim: n p => // n IHn p le_p_n px_x.
have [p_id | [x1 Hx1]] := set_0Vmem [set x | p x != x].
suffices ->: p = 1 by rewrite rfd1 !odd_perm1.
by apply/permP => z; apply: contraFeq (in_set0 z); rewrite perm1 -p_id inE.
have nx1x: x1 != x by apply: contraTneq Hx1 => ->; rewrite inE px_x eqxx.
have npxx1: p x != x1 by apply: contraNneq nx1x => <-; rewrite px_x.
have npx1x: p x1 != x by rewrite -px_x (inj_eq perm_inj).
pose p1 := p * tperm x1 (p x1).
have fix_p1 y: p y = y -> p1 y = y.
by move=> pyy; rewrite permM; have [<-|/perm_inj<-|] := tpermP; rewrite ?pyy.
have p1x_x: p1 x = x by apply: fix_p1.
have{le_p_n} lt_p1_n: #|[set x | p1 x != x]| < n.
move: le_p_n; rewrite ltnS (cardsD1 x1) Hx1; apply/leq_trans/subset_leq_card.
rewrite subsetD1 inE permM tpermR eqxx andbT.
by apply/subsetP=> y /[!inE]; apply: contraNneq=> /fix_p1->.
transitivity (p1 (+) true); last first.
by rewrite odd_permM odd_tperm -Hx1 inE eq_sym addbK.
have ->: p = p1 * tperm x1 (p x1) by rewrite -tpermV mulgK.
rewrite morphM; last 2 first; first by rewrite 2!inE; apply/astab1P.
by rewrite 2!inE; apply/astab1P; rewrite -[RHS]p1x_x permM px_x.
rewrite odd_permM IHn //=; congr (_ (+) _).
pose x2 : T' := Sub x1 nx1x; pose px2 : T' := Sub (p x1) npx1x.
suffices ->: rfd (tperm x1 (p x1)) = tperm x2 px2.
by rewrite odd_tperm eq_sym; rewrite inE in Hx1.
apply/permP => z; apply/val_eqP; rewrite permE /= tpermD // eqxx.
by rewrite !permE /= -!val_eqE /= !(fun_if sval) /=.
Qed.
Lemma rfd_iso : 'C_('Alt_T)[x | 'P] \isog 'Alt_T'.
Proof.
have rgd_x p: rgd p x = x by rewrite permE /= insubF //= eqxx.
have rfd_rgd p: rfd (rgd p) = p.
apply/permP => [[z Hz]]; apply/val_eqP; rewrite !permE.
by rewrite /= [rgd _ _]permE /= insubF eqxx // permE /= insubT.
have sSd: 'C_('Alt_T)[x | 'P] \subset 'dom rfd.
by apply/subsetP=> p /[!inE]/= /andP[].
apply/isogP; exists [morphism of restrm sSd rfd] => /=; last first.
rewrite morphim_restrm setIid; apply/setP=> z; apply/morphimP/idP=> [[p _]|].
case/setIP; rewrite Alt_even => Hp; move/astab1P=> Hp1 ->.
by rewrite Alt_even rfd_odd.
have dz': rgd z x == x by rewrite rgd_x.
move=> kz; exists (rgd z); last by rewrite /= rfd_rgd.
by rewrite 2!inE (sameP astab1P eqP).
rewrite 4!inE /= (sameP astab1P eqP) dz' -rfd_odd; last exact/eqP.
by rewrite rfd_rgd mker // ?set11.
apply/injmP=> x1 y1 /=.
case/setIP=> Hax1; move/astab1P; rewrite /= /aperm => Hx1.
case/setIP=> Hay1; move/astab1P; rewrite /= /aperm => Hy1 Hr.
apply/permP => z.
case (z =P x) => [->|]; [by rewrite Hx1 | move/eqP => nzx].
move: (congr1 (fun q : {perm T'} => q (Sub z nzx)) Hr).
by rewrite !permE => [[]]; rewrite Hx1 Hy1 !eqxx.
Qed.
End Restrict.
Lemma simple_Alt5 (T : finType) : #|T| >= 5 -> simple 'Alt_T.
Proof.
suff F1 n: #|T| = n + 5 -> simple 'Alt_T by move/subnK/esym/F1.
elim: n T => [| n Hrec T Hde]; first exact: simple_Alt5_base.
have oT: 5 < #|T| by rewrite Hde addnC.
apply/simpleP; split=> [|H Hnorm]; last have [Hh1 nH] := andP Hnorm.
rewrite trivg_card1 -[#|_|]half_double -mul2n card_Alt Hde addnC //.
by rewrite addSn factS mulnC -(prednK (fact_gt0 _)).
case E1: (pred0b T); first by rewrite /pred0b in E1; rewrite (eqP E1) in oT.
case/pred0Pn: E1 => x _; have Hx := in_setT x.
have F2: [transitive^4 'Alt_T, on setT | 'P].
by apply: ntransitive_weak (Alt_trans T); rewrite -(subnKC oT).
have F3 := ntransitive1 (isT: 0 < 4) F2.
have F4 := ntransitive_primitive (isT: 1 < 4) F2.
case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1.
by left; apply: card1_trivg; rewrite Hcard1.
right; case: (prim_trans_norm F4 Hnorm) => F5.
by rewrite (trivGP (subset_trans F5 (aperm_faithful _))) cards1 in Hcard1.
case E1: (pred0b (predD1 T x)).
rewrite /pred0b in E1; move: oT.
by rewrite (cardD1 x) (eqP E1); case: (T x).
case/pred0Pn: E1 => y Hdy; case/andP: (Hdy) => diff_x_y Hy.
pose K := 'C_H[x | 'P]%G.
have F8: K \subset H by apply: subsetIl.
pose Gx := 'C_('Alt_T)[x | 'P].
have F9: [transitive^3 Gx, on [set~ x] | 'P].
by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE.
have F10: [transitive Gx, on [set~ x] | 'P].
by apply: ntransitive1 F9.
have F11: [primitive Gx, on [set~ x] | 'P].
by apply: ntransitive_primitive F9.
have F12: K \subset Gx by rewrite setSI // normal_sub.
have F13: K <| Gx by apply/andP; rewrite normsIG.
have:= prim_trans_norm F11; case/(_ K) => //= => Ksub; last first.
have F14: Gx * H = 'Alt_T by apply/(subgroup_transitiveP _ _ F3).
have: simple Gx.
by rewrite (isog_simple (rfd_iso x)) Hrec //= card_sig cardC1 Hde.
case/simpleP=> _ simGx; case/simGx: F13 => /= HH2.
case Ez: (pred0b (predD1 (predD1 T x) y)).
move: oT; rewrite /pred0b in Ez.
by rewrite (cardD1 x) (cardD1 y) (eqP Ez) inE /= inE /= diff_x_y.
case/pred0Pn: Ez => z; case/andP => diff_y_z Hdz.
have [diff_x_z Hz] := andP Hdz.
have: z \in [set~ x] by rewrite !inE.
rewrite -(atransP Ksub y) ?inE //; case/imsetP => g.
rewrite /= HH2 inE; move/eqP=> -> HH4.
by case/negP: diff_y_z; rewrite HH4 act1.
by rewrite /= -F14 -[Gx]HH2 (mulSGid F8).
have F14: [faithful Gx, on [set~ x] | 'P].
apply: subset_trans (aperm_faithful 'Sym_T); rewrite subsetI subsetT.
apply/subsetP=> g; do 2![case/setIP]=> _ cgx cgx'; apply/astabP=> z _ /=.
case: (z =P x) => [->|]; first exact: (astab1P cgx).
by move/eqP=> zx; rewrite [_ g](astabP cgx') ?inE.
have Hreg g z: g \in H -> g z = z -> g = 1.
have F15 h: h \in H -> h x = x -> h = 1.
move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P.
by rewrite [K](trivGP (subset_trans Ksub F14)) => /set1P.
move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //.
case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g.
apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz.
by rewrite memJ_norm ?(subsetP nH).
clear K F8 F12 F13 Ksub F14.
have Hcard: 5 < #|H|.
apply: (leq_trans oT); apply: dvdn_leq; first exact: cardG_gt0.
by rewrite -cardsT (atrans_dvd F5).
case Eh: (pred0b [predD1 H & 1]).
by move: Hcard; rewrite /pred0b in Eh; rewrite (cardD1 1) group1 (eqP Eh).
case/pred0Pn: Eh => h; case/andP => diff_1_h /= Hh.
case Eg: (pred0b (predD1 (predD1 [predD1 H & 1] h) h^-1)).
move: Hcard; rewrite ltnNge; case/negP.
rewrite (cardD1 1) group1 (cardD1 h) (cardD1 h^-1) (eqnP Eg).
by do 2!case: (_ \in _).
case/pred0Pn: Eg => g; case/andP => diff_h1_g; case/andP => diff_h_g.
case/andP => diff_1_g /= Hg.
case diff_hx_x: (h x == x).
by case/negP: diff_1_h; apply/eqP; apply: (Hreg _ _ Hh (eqP diff_hx_x)).
case diff_gx_x: (g x == x).
case/negP: diff_1_g; apply/eqP; apply: (Hreg _ _ Hg (eqP diff_gx_x)).
case diff_gx_hx: (g x == h x).
case/negP: diff_h_g; apply/eqP; symmetry; apply: (mulIg g^-1); rewrite gsimp.
apply: (Hreg _ x); first by rewrite groupM // groupV.
by rewrite permM -(eqP diff_gx_hx) -permM mulgV perm1.
case diff_hgx_x: ((h * g) x == x).
case/negP: diff_h1_g; apply/eqP; apply: (mulgI h); rewrite !gsimp.
by apply: (Hreg _ x); [apply: groupM | apply/eqP].
case diff_hgx_hx: ((h * g) x == h x).
case/negP: diff_1_g; apply/eqP.
by apply: (Hreg _ (h x)) => //; apply/eqP; rewrite -permM.
case diff_hgx_gx: ((h * g) x == g x).
by case/idP: diff_hx_x; rewrite -(can_eq (permK g)) -permM.
case Ez: (pred0b
(predD1 (predD1 (predD1 (predD1 T x) (h x)) (g x)) ((h * g) x))).
- move: oT; rewrite /pred0b in Ez.
rewrite (cardD1 x) (cardD1 (h x)) (cardD1 (g x)) (cardD1 ((h * g) x)).
by rewrite (eqP Ez) addnC; do 3!case: (_ x \in _).
case/pred0Pn: Ez => z.
case/and5P=> diff_hgx_z diff_gx_z diff_hx_z diff_x_z /= Hz.
pose S1 := [tuple x; h x; g x; z].
have DnS1: S1 \in 4.-dtuple(setT).
rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT.
rewrite -!(eq_sym z) diff_gx_z diff_x_z diff_hx_z.
by rewrite !(eq_sym x) diff_hx_x diff_gx_x eq_sym diff_gx_hx.
pose S2 := [tuple x; h x; g x; (h * g) x].
have DnS2: S2 \in 4.-dtuple(setT).
rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT !(eq_sym x).
rewrite diff_hx_x diff_gx_x diff_hgx_x.
by rewrite !(eq_sym (h x)) diff_gx_hx diff_hgx_hx eq_sym diff_hgx_gx.
case: (atransP2 F2 DnS1 DnS2) => k Hk [/=].
rewrite /aperm => Hkx Hkhx Hkgx Hkhgx.
have h_k_com: h * k = k * h.
suff HH: (k * h * k^-1) * h^-1 = 1 by rewrite -[h * k]mul1g -HH !gnorm.
apply: (Hreg _ x); last first.
by rewrite !permM -Hkx Hkhx -!permM mulKVg mulgV perm1.
by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH).
have g_k_com: g * k = k * g.
suff HH: (k * g * k^-1) * g^-1 = 1 by rewrite -[g * k]mul1g -HH !gnorm.
apply: (Hreg _ x); last first.
by rewrite !permM -Hkx Hkgx -!permM mulKVg mulgV perm1.
by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH).
have HH: (k * (h * g) * k ^-1) x = z.
by rewrite 2!permM -Hkx Hkhgx -permM mulgV perm1.
case/negP: diff_hgx_z.
rewrite -HH !mulgA -h_k_com -!mulgA [k * _]mulgA.
by rewrite -g_k_com -!mulgA mulgV mulg1.
Qed.
Lemma gen_tperm_circular_shift (X : finType) x y c : prime #|X| ->
x != y -> #[c]%g = #|X| ->
<<[set tperm x y; c]>>%g = ('Sym_X)%g.
Proof.
move=> Xprime neq_xy ord_c; apply/eqP; rewrite eqEsubset subsetT/=.
have c_gt1 : (1 < #[c]%g)%N by rewrite ord_c prime_gt1.
have cppSS : #[c]%g.-2.+2 = #|X| by rewrite ?prednK ?ltn_predRL.
pose f (i : 'Z_#[c]%g) : X := Zpm i x.
have [g fK gK] : bijective f.
apply: inj_card_bij; rewrite ?cppSS ?card_ord// /f /Zpm => i j cijx.
pose stabx := ('C_<[c]>[x | 'P])%g.
have cjix : (c ^+ (j - i)%R)%g x = x.
by apply: (@perm_inj _ (c ^+ i)%g); rewrite -permM -expgD_Zp// addrNK.
have : (c ^+ (j - i)%R)%g \in stabx.
by rewrite !inE ?groupX ?mem_gen ?sub1set ?inE// ['P%act _ _]cjix eqxx.
rewrite [stabx]perm_prime_astab// => /set1gP.
move=> /(congr1 (mulg (c ^+ i))); rewrite -expgD_Zp// addrC addrNK mulg1.
by move=> /eqP; rewrite eq_expg_ord// ?cppSS ?ord_c// => /eqP->.
pose gsf s := g \o s \o f.
have gsf_inj (s : {perm X}) : injective (gsf s).
apply: inj_comp; last exact: can_inj fK.
by apply: inj_comp; [exact: can_inj gK|exact: perm_inj].
pose fsg s := f \o s \o g.
have fsg_inj (s : {perm _}) : injective (fsg s).
apply: inj_comp; last exact: can_inj gK.
by apply: inj_comp; [exact: can_inj fK|exact: perm_inj].
have gsf_morphic : morphic 'Sym_X (fun s => perm (gsf_inj s)).
apply/morphicP => u v _ _; apply/permP => /= i.
by rewrite !permE/= !permE /gsf /= gK permM.
pose phi := morphm gsf_morphic; rewrite /= in phi.
have phi_inj : ('injm phi)%g.
apply/subsetP => /= u /mker/=; rewrite morphmE => gsfu1.
apply/set1gP/permP=> z; have /permP/(_ (g z)) := gsfu1.
by rewrite !perm1 permE /gsf/= gK => /(can_inj gK).
have phiT : (phi @* 'Sym_X)%g = [set: {perm 'Z_#[c]%g}].
apply/eqP; rewrite eqEsubset subsetT/=; apply/subsetP => /= u _.
apply/morphimP; exists (perm (fsg_inj u)); rewrite ?in_setT//.
by apply/permP => /= i; rewrite morphmE permE /gsf/fsg/= permE/= !fK.
have f0 : f 0%R = x by rewrite /f /Zpm permX.
pose k := g y; have k_gt0 : (k > 0)%N.
by rewrite lt0n (val_eqE k 0%R) -(can_eq fK) eq_sym gK f0.
have phixy : phi (tperm x y) = tperm (0%R : 'Z_#[c]) k.
apply/permP => i; rewrite permE/= /gsf/=; apply: (canLR fK).
by rewrite !permE/= -f0 -[y]gK !(can_eq fK) -!fun_if.
have phic : phi c = perm (addrI (1%R : 'Z_#[c])).
apply/permP => i; rewrite /phi morphmE !permE /gsf/=; apply: (canLR fK).
by rewrite /f /Zpm -permM addrC expgD_Zp.
rewrite -(injmSK phi_inj)//= morphim_gen/= ?subsetT//= -/phi.
rewrite phiT /morphim !setTI/= -/phi imsetU1 imset_set1/= phixy phic.
suff /gen_tpermn_circular_shift<- : coprime #[c]%g.-2.+2 (k - 0)%R by [].
by rewrite subr0 prime_coprime ?gtnNdvd// ?cppSS.
Qed.
Section Perm_solvable.
Local Open Scope nat_scope.
Variable T : finType.
Lemma solvable_AltF : 4 < #|T| -> solvable 'Alt_T = false.
Proof.
move=> card_T; apply/negP => Alt_solvable.
have/simple_Alt5 Alt_simple := card_T.
have := simple_sol_prime Alt_solvable Alt_simple.
have lt_T n : n <= 4 -> n < #|T| by move/leq_ltn_trans; apply.
have -> : #|('Alt_T)%G| = #|T|`! %/ 2 by rewrite -card_Alt ?mulKn ?lt_T.
move/even_prime => [/eqP|]; apply/negP.
rewrite neq_ltn leq_divRL // mulnC -[2 * 3]/(3`!).
by apply/orP; right; apply/ltnW/ltn_fact/lt_T.
by rewrite -dvdn2 dvdn_divRL dvdn_fact //=; apply/ltnW/lt_T.
Qed.
Lemma solvable_SymF : 4 < #|T| -> solvable 'Sym_T = false.
Proof. by rewrite (series_sol (Alt_normal T)) => /solvable_AltF->. Qed.
End Perm_solvable.
|
Complex.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.MeasureTheory.Measure.Haar.InnerProductSpace
import Mathlib.MeasureTheory.Constructions.BorelSpace.Complex
/-!
# Lebesgue measure on `ℂ`
In this file, we consider the Lebesgue measure on `ℂ` defined as the push-forward of the volume
on `ℝ²` under the natural isomorphism and prove that it is equal to the measure `volume` of `ℂ`
coming from its `InnerProductSpace` structure over `ℝ`. For that, we consider the two frequently
used ways to represent `ℝ²` in `mathlib`: `ℝ × ℝ` and `Fin 2 → ℝ`, define measurable equivalences
(`MeasurableEquiv`) to both types and prove that both of them are volume preserving (in the sense
of `MeasureTheory.measurePreserving`).
-/
open MeasureTheory Module
noncomputable section
namespace Complex
/-- Measurable equivalence between `ℂ` and `ℝ² = Fin 2 → ℝ`. -/
def measurableEquivPi : ℂ ≃ᵐ (Fin 2 → ℝ) :=
basisOneI.equivFun.toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv
@[simp]
theorem measurableEquivPi_apply (a : ℂ) :
measurableEquivPi a = ![a.re, a.im] := rfl
@[simp]
theorem measurableEquivPi_symm_apply (p : (Fin 2) → ℝ) :
measurableEquivPi.symm p = (p 0) + (p 1) * I := rfl
/-- Measurable equivalence between `ℂ` and `ℝ × ℝ`. -/
def measurableEquivRealProd : ℂ ≃ᵐ ℝ × ℝ :=
equivRealProdCLM.toHomeomorph.toMeasurableEquiv
@[simp]
theorem measurableEquivRealProd_apply (a : ℂ) : measurableEquivRealProd a = (a.re, a.im) := rfl
@[simp]
theorem measurableEquivRealProd_symm_apply (p : ℝ × ℝ) :
measurableEquivRealProd.symm p = {re := p.1, im := p.2} := rfl
theorem volume_preserving_equiv_pi : MeasurePreserving measurableEquivPi := by
convert (measurableEquivPi.symm.measurable.measurePreserving volume).symm
rw [← addHaarMeasure_eq_volume_pi, ← Basis.parallelepiped_basisFun, ← Basis.addHaar,
measurableEquivPi, Homeomorph.toMeasurableEquiv_symm_coe,
ContinuousLinearEquiv.coe_symm_toHomeomorph, Basis.map_addHaar, eq_comm]
exact (Basis.addHaar_eq_iff _ _).mpr Complex.orthonormalBasisOneI.volume_parallelepiped
theorem volume_preserving_equiv_real_prod : MeasurePreserving measurableEquivRealProd :=
(volume_preserving_finTwoArrow ℝ).comp volume_preserving_equiv_pi
end Complex
|
MkIffOfInductive.lean
|
import Mathlib.Tactic.MkIffOfInductiveProp
import Mathlib.Data.List.Perm.Lattice
mk_iff_of_inductive_prop List.Chain test.chain_iff
example {α : Type _} (R : α → α → Prop) (a : α) (al : List α) :
List.Chain R a al ↔
al = List.nil ∨ ∃ (b : α) (l : List α), R a b ∧ List.Chain R b l ∧ al = b :: l :=
test.chain_iff R a al
-- check that the statement prints nicely
/--
info: test.chain_iff.{u_1} {α : Type u_1} (R : α → α → Prop) (a✝ : α) (a✝¹ : List α) :
List.Chain R a✝ a✝¹ ↔ a✝¹ = [] ∨ ∃ b l, R a✝ b ∧ List.Chain R b l ∧ a✝¹ = b :: l
-/
#guard_msgs in
#check test.chain_iff
mk_iff_of_inductive_prop False test.false_iff
example : False ↔ False := test.false_iff
mk_iff_of_inductive_prop True test.true_iff
example : True ↔ True := test.true_iff
universe u
mk_iff_of_inductive_prop Nonempty test.non_empty_iff
example (α : Sort u) : Nonempty α ↔ ∃ (_ : α), True := test.non_empty_iff α
mk_iff_of_inductive_prop And test.and_iff
example (p q : Prop) : And p q ↔ p ∧ q := test.and_iff p q
mk_iff_of_inductive_prop Or test.or_iff
example (p q : Prop) : Or p q ↔ p ∨ q := test.or_iff p q
mk_iff_of_inductive_prop Eq test.eq_iff
example (α : Sort u) (a b : α) : a = b ↔ b = a := test.eq_iff a b
mk_iff_of_inductive_prop HEq test.heq_iff
example {α : Sort u} (a : α) {β : Sort u} (b : β) : a ≍ b ↔ β = α ∧ b ≍ a := test.heq_iff a b
mk_iff_of_inductive_prop List.Perm test.perm_iff
open scoped List in
example {α : Type _} (a b : List α) :
a ~ b ↔
a = List.nil ∧ b = List.nil ∨
(∃ (x : α) (l₁ l₂ : List α), l₁ ~ l₂ ∧ a = x :: l₁ ∧ b = x :: l₂) ∨
(∃ (x y : α) (l : List α), a = y :: x :: l ∧ b = x :: y :: l) ∨
∃ (l₂ : List α), a ~ l₂ ∧ l₂ ~ b := test.perm_iff a b
mk_iff_of_inductive_prop List.Pairwise test.pairwise_iff
example {α : Type} (R : α → α → Prop) (al : List α) :
List.Pairwise R al ↔
al = List.nil ∨
∃ (a : α) (l : List α), (∀ (a' : α), a' ∈ l → R a a') ∧ List.Pairwise R l ∧ al = a :: l := test.pairwise_iff R al
inductive test.is_true (p : Prop) : Prop
| triviality (h : p) : test.is_true p
mk_iff_of_inductive_prop test.is_true test.is_true_iff
example (p : Prop) : test.is_true p ↔ p := test.is_true_iff p
@[mk_iff]
structure foo (m n : Nat) : Prop where
equal : m = n
sum_eq_two : m + n = 2
example (m n : Nat) : foo m n ↔ m = n ∧ m + n = 2 := foo_iff m n
@[mk_iff bar]
structure foo2 (m n : Nat) : Prop where
equal : m = n
sum_eq_two : m + n = 2
example (m n : Nat) : foo2 m n ↔ m = n ∧ m + n = 2 := bar m n
@[mk_iff]
inductive ReflTransGen {α : Type _} (r : α → α → Prop) (a : α) : α → Prop
| refl : ReflTransGen r a a
| tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c
example {α : Type} (r : α → α → Prop) (a c : α) :
ReflTransGen r a c ↔ c = a ∨ ∃ b : α, ReflTransGen r a b ∧ r b c :=
reflTransGen_iff r a c
|
presentation.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq.
From mathcomp Require Import fintype finset fingroup morphism.
(******************************************************************************)
(* Support for generator-and-relation presentations of groups. We provide the *)
(* syntax: *)
(* G \homg Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) *)
(* <=> G is generated by elements x_1, ..., x_m satisfying the relations *)
(* s_1 = t_1, ..., s_m = t_m, i.e., G is a homomorphic image of the *)
(* group generated by the x_i, subject to the relations s_j = t_j. *)
(* G \isog Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) *)
(* <=> G is isomorphic to the largest finite factor of the group generated *)
(* by the x_i, subject to the relations s_j = t_j. In particular, *)
(* if the abstract group defined by the presentation is finite, *)
(* it means that G is actually isomorphic to it. This is an *)
(* intensional predicate (in Prop), as even the non-triviality of a *)
(* generated group is undecidable. *)
(* Syntax details: *)
(* - Grp is a literal constant. *)
(* - There must be at least one generator and one relation. *)
(* - A relation s_j = 1 can be abbreviated as simply s_j (a.k.a. a relator). *)
(* - Two consecutive relations s_j = t, s_j+1 = t can be abbreviated *)
(* s_j = s_j+1 = t. *)
(* - The s_j and t_j are terms built from the x_i and the standard group *)
(* operators *, 1, ^-1, ^+, ^-, ^, [~ u_1, ..., u_k]; no other operator or *)
(* abbreviation may be used, as the notation is implemented using static *)
(* overloading. *)
(* - This is the closest we could get to the notation used in Aschbacher, *)
(* Grp (x_1, ... x_n : t_1,1 = ... = t_1,k1, ..., t_m,1 = ... = t_m,km) *)
(* under the current limitations of the Coq Notation facility. *)
(* Semantics details: *)
(* - G \isog Grp (...) : Prop expands to the statement *)
(* forall rT (H : {group rT}), (H \homg G) = (H \homg Grp (...)) *)
(* (with rT : finGroupType). *)
(* - G \homg Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) : bool, with *)
(* G : {set gT}, is convertible to the boolean expression *)
(* [exists t : gT * ... gT, let: (x_1, ..., x_n) := t in *)
(* (<[x_1]> <*> ... <*> <[x_n]>, (s_1, ... (s_m-1, s_m) ...)) *)
(* == (G, (t_1, ... (t_m-1, t_m) ...))] *)
(* where the tuple comparison above is convertible to the conjunction *)
(* [&& <[x_1]> <*> ... <*> <[x_n]> == G, s_1 == t_1, ... & s_m == t_m] *)
(* Thus G \homg Grp (...) can be easily exploited by destructing the tuple *)
(* created case/existsP, then destructing the tuple equality with case/eqP. *)
(* Conversely it can be proved by using apply/existsP, providing the tuple *)
(* with a single exists (u_1, ..., u_n), then using rewrite !xpair_eqE /= *)
(* to expose the conjunction, and optionally using an apply/and{m+1}P view *)
(* to split it into subgoals (in that case, the rewrite is in principle *)
(* redundant, but necessary in practice because of the poor performance of *)
(* conversion in the Coq unifier). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Module Presentation.
Section Presentation.
Implicit Types gT rT : finGroupType.
Implicit Type vT : finType. (* tuple value type *)
Inductive term :=
| Cst of nat
| Idx
| Inv of term
| Exp of term & nat
| Mul of term & term
| Conj of term & term
| Comm of term & term.
Fixpoint eval {gT} e t : gT :=
match t with
| Cst i => nth 1 e i
| Idx => 1
| Inv t1 => (eval e t1)^-1
| Exp t1 n => eval e t1 ^+ n
| Mul t1 t2 => eval e t1 * eval e t2
| Conj t1 t2 => eval e t1 ^ eval e t2
| Comm t1 t2 => [~ eval e t1, eval e t2]
end.
Inductive formula := Eq2 of term & term | And of formula & formula.
Definition Eq1 s := Eq2 s Idx.
Definition Eq3 s1 s2 t := And (Eq2 s1 t) (Eq2 s2 t).
Inductive rel_type := NoRel | Rel vT of vT & vT.
Definition bool_of_rel r := if r is Rel vT v1 v2 then v1 == v2 else true.
Local Coercion bool_of_rel : rel_type >-> bool.
Definition and_rel vT (v1 v2 : vT) r :=
if r is Rel wT w1 w2 then Rel (v1, w1) (v2, w2) else Rel v1 v2.
Fixpoint rel {gT} (e : seq gT) f r :=
match f with
| Eq2 s t => and_rel (eval e s) (eval e t) r
| And f1 f2 => rel e f1 (rel e f2 r)
end.
Inductive type := Generator of term -> type | Formula of formula.
Definition Cast p : type := p. (* syntactic scope cast *)
Local Coercion Formula : formula >-> type.
Inductive env gT := Env of {set gT} & seq gT.
Definition env1 {gT} (x : gT : finType) := Env <[x]> [:: x].
Fixpoint sat gT vT B n (s : vT -> env gT) p :=
match p with
| Formula f =>
[exists v, let: Env A e := s v in and_rel A B (rel (rev e) f NoRel)]
| Generator p' =>
let s' v := let: Env A e := s v.1 in Env (A <*> <[v.2]>) (v.2 :: e) in
sat B n.+1 s' (p' (Cst n))
end.
Definition hom gT (B : {set gT}) p := sat B 1 env1 (p (Cst 0)).
Definition iso gT (B : {set gT}) p :=
forall rT (H : {group rT}), (H \homg B) = hom H p.
End Presentation.
End Presentation.
Import Presentation.
Coercion bool_of_rel : rel_type >-> bool.
Coercion Eq1 : term >-> formula.
Coercion Formula : formula >-> type.
Declare Custom Entry group_presentation.
Notation "x * y" := (Mul x y)
(in custom group_presentation at level 40, left associativity).
Notation "x ^+ n" := (Exp x n)
(in custom group_presentation at level 29, n constr at level 28).
Notation "x ^ y" := (Conj x y)
(in custom group_presentation at level 30, right associativity).
Notation "x ^-1" := (Inv x) (in custom group_presentation at level 3).
Notation "x ^- n" := (Inv (Exp x n))
(in custom group_presentation at level 29, n constr at level 28).
Notation "[ ~ x1 , x2 , .. , xn ]" := (Comm .. (Comm x1 x2) .. xn)
(in custom group_presentation, x1, x2, xn at level 100).
Notation "x = y" := (Eq2 x y) (in custom group_presentation at level 70).
Notation "x = y = z" := (Eq3 x y z) (in custom group_presentation at level 70,
y at next level).
Notation "r1 , r2 , .. , rn" := (And .. (And r1 r2) .. rn)
(in custom group_presentation at level 200).
Notation "( p )" := p (in custom group_presentation, p at level 200).
Notation "1" := Idx (in custom group_presentation).
Notation "x" := x (in custom group_presentation at level 0, x ident).
Notation "x : p" := (Generator (fun x => Cast p))
(in custom group_presentation, x ident, p custom group_presentation at level 200).
Arguments hom _ _%_group_scope.
Arguments iso _ _%_group_scope.
Notation "H \homg 'Grp' p" := (hom H p)
(p at level 0, format "H \homg 'Grp' p") : group_scope.
Notation "H \isog 'Grp' p" := (iso H p)
(p at level 0, format "H \isog 'Grp' p") : group_scope.
Notation "H \homg 'Grp' ( x : p )" := (hom H (fun x => Cast p))
(x ident, p custom group_presentation at level 200,
format "'[hv' H '/ ' \homg 'Grp' ( x : p ) ']'") : group_scope.
Notation "H \isog 'Grp' ( x : p )" := (iso H (fun x => Cast p))
(x ident, p custom group_presentation at level 200,
format "'[hv' H '/ ' \isog 'Grp' ( x : p ) ']'") : group_scope.
Section PresentationTheory.
Implicit Types gT rT : finGroupType.
Import Presentation.
Lemma isoGrp_hom gT (G : {group gT}) p : G \isog Grp p -> G \homg Grp p.
Proof. by move <-; apply: homg_refl. Qed.
Lemma isoGrpP gT (G : {group gT}) p rT (H : {group rT}) :
G \isog Grp p -> reflect (#|H| = #|G| /\ H \homg Grp p) (H \isog G).
Proof.
move=> isoGp; apply: (iffP idP) => [isoGH | [oH homHp]].
by rewrite (card_isog isoGH) -isoGp isog_hom.
by rewrite isogEcard isoGp homHp /= oH.
Qed.
Lemma homGrp_trans rT gT (H : {set rT}) (G : {group gT}) p :
H \homg G -> G \homg Grp p -> H \homg Grp p.
Proof.
case/homgP=> h <-{H}; rewrite /hom; move: {p}(p _) => p.
have evalG e t: all [in G] e -> eval (map h e) t = h (eval e t).
move=> Ge; apply: (@proj2 (eval e t \in G)); elim: t => /=.
- move=> i; case: (leqP (size e) i) => [le_e_i | lt_i_e].
by rewrite !nth_default ?size_map ?morph1.
by rewrite (nth_map 1) // [_ \in G](allP Ge) ?mem_nth.
- by rewrite morph1.
- by move=> t [Gt ->]; rewrite groupV morphV.
- by move=> t [Gt ->] n; rewrite groupX ?morphX.
- by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupM ?morphM.
- by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupJ ?morphJ.
by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupR ?morphR.
have and_relE xT x1 x2 r: @and_rel xT x1 x2 r = (x1 == x2) && r :> bool.
by case: r => //=; rewrite andbT.
have rsatG e f: all [in G] e -> rel e f NoRel -> rel (map h e) f NoRel.
move=> Ge; have: NoRel -> NoRel by []; move: NoRel {2 4}NoRel.
elim: f => [x1 x2 | f1 IH1 f2 IH2] r hr IHr; last by apply: IH1; apply: IH2.
by rewrite !and_relE !evalG //; case/andP; move/eqP->; rewrite eqxx.
set s := env1; set vT := gT : finType in s *.
set s' := env1; set vT' := rT : finType in s' *.
have (v): let: Env A e := s v in
A \subset G -> all [in G] e /\ exists v', s' v' = Env (h @* A) (map h e).
- rewrite /= cycle_subG andbT => Gv; rewrite morphim_cycle //.
by split; last exists (h v).
elim: p 1%N vT vT' s s' => /= [p IHp | f] n vT vT' s s' Gs.
apply: IHp => [[v x]] /=; case: (s v) {Gs}(Gs v) => A e /= Gs.
rewrite join_subG cycle_subG; case/andP=> sAG Gx; rewrite Gx.
have [//|-> [v' def_v']] := Gs; split=> //; exists (v', h x); rewrite def_v'.
by congr (Env _ _); rewrite morphimY ?cycle_subG // morphim_cycle.
case/existsP=> v; case: (s v) {Gs}(Gs v) => /= A e Gs.
rewrite and_relE => /andP[/eqP defA rel_f].
have{Gs} [|Ge [v' def_v']] := Gs; first by rewrite defA.
apply/existsP; exists v'; rewrite def_v' and_relE defA eqxx /=.
by rewrite -map_rev rsatG ?(eq_all_r (mem_rev e)).
Qed.
Lemma eq_homGrp gT rT (G : {group gT}) (H : {group rT}) p :
G \isog H -> (G \homg Grp p) = (H \homg Grp p).
Proof.
by rewrite isogEhom => /andP[homGH homHG]; apply/idP/idP; apply: homGrp_trans.
Qed.
Lemma isoGrp_trans gT rT (G : {group gT}) (H : {group rT}) p :
G \isog H -> H \isog Grp p -> G \isog Grp p.
Proof. by move=> isoGH isoHp kT K; rewrite -isoHp; apply: eq_homgr. Qed.
Lemma intro_isoGrp gT (G : {group gT}) p :
G \homg Grp p -> (forall rT (H : {group rT}), H \homg Grp p -> H \homg G) ->
G \isog Grp p.
Proof.
move=> homGp freeG rT H.
by apply/idP/idP=> [homHp|]; [apply: homGrp_trans homGp | apply: freeG].
Qed.
End PresentationTheory.
|
Lattice.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import Mathlib.Algebra.Algebra.Operations
import Mathlib.Algebra.Algebra.Subalgebra.Basic
/-!
# Complete lattice structure of subalgebras
In this file we define `Algebra.adjoin` and the complete lattice structure on subalgebras.
More lemmas about `adjoin` can be found in `Mathlib/RingTheory/Adjoin/Basic.lean`.
-/
assert_not_exists Polynomial
universe u u' v w w'
namespace Algebra
variable (R : Type u) {A : Type v} {B : Type w}
variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
/-- The minimal subalgebra that includes `s`. -/
@[simps toSubsemiring]
def adjoin (s : Set A) : Subalgebra R A :=
{ Subsemiring.closure (Set.range (algebraMap R A) ∪ s) with
algebraMap_mem' := fun r => Subsemiring.subset_closure <| Or.inl ⟨r, rfl⟩ }
variable {R}
protected theorem gc : GaloisConnection (adjoin R : Set A → Subalgebra R A) (↑) := fun s S =>
⟨fun H => le_trans (le_trans Set.subset_union_right Subsemiring.subset_closure) H,
fun H => show Subsemiring.closure (Set.range (algebraMap R A) ∪ s) ≤ S.toSubsemiring from
Subsemiring.closure_le.2 <| Set.union_subset S.range_subset H⟩
/-- Galois insertion between `adjoin` and `coe`. -/
protected def gi : GaloisInsertion (adjoin R : Set A → Subalgebra R A) (↑) where
choice s hs := (adjoin R s).copy s <| le_antisymm (Algebra.gc.le_u_l s) hs
gc := Algebra.gc
le_l_u S := (Algebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl
choice_eq _ _ := Subalgebra.copy_eq _ _ _
instance : CompleteLattice (Subalgebra R A) where
__ := GaloisInsertion.liftCompleteLattice Algebra.gi
bot := (Algebra.ofId R A).range
bot_le _S := fun _a ⟨_r, hr⟩ => hr ▸ algebraMap_mem _ _
theorem sup_def (S T : Subalgebra R A) : S ⊔ T = adjoin R (S ∪ T : Set A) := rfl
theorem sSup_def (S : Set (Subalgebra R A)) : sSup S = adjoin R (⋃₀ (SetLike.coe '' S)) := rfl
@[simp]
theorem coe_top : (↑(⊤ : Subalgebra R A) : Set A) = Set.univ := rfl
@[simp]
theorem mem_top {x : A} : x ∈ (⊤ : Subalgebra R A) := Set.mem_univ x
@[simp]
theorem top_toSubmodule : Subalgebra.toSubmodule (⊤ : Subalgebra R A) = ⊤ := rfl
@[simp]
theorem top_toSubsemiring : (⊤ : Subalgebra R A).toSubsemiring = ⊤ := rfl
@[simp]
theorem top_toSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] :
(⊤ : Subalgebra R A).toSubring = ⊤ := rfl
@[simp]
theorem toSubmodule_eq_top {S : Subalgebra R A} : Subalgebra.toSubmodule S = ⊤ ↔ S = ⊤ :=
Subalgebra.toSubmodule.injective.eq_iff' top_toSubmodule
@[simp]
theorem toSubsemiring_eq_top {S : Subalgebra R A} : S.toSubsemiring = ⊤ ↔ S = ⊤ :=
Subalgebra.toSubsemiring_injective.eq_iff' top_toSubsemiring
@[simp]
theorem toSubring_eq_top {R A : Type*} [CommRing R] [Ring A] [Algebra R A] {S : Subalgebra R A} :
S.toSubring = ⊤ ↔ S = ⊤ :=
Subalgebra.toSubring_injective.eq_iff' top_toSubring
theorem mem_sup_left {S T : Subalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T :=
have : S ≤ S ⊔ T := le_sup_left; (this ·)
theorem mem_sup_right {S T : Subalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T :=
have : T ≤ S ⊔ T := le_sup_right; (this ·)
theorem mul_mem_sup {S T : Subalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=
(S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)
theorem map_sup (f : A →ₐ[R] B) (S T : Subalgebra R A) : (S ⊔ T).map f = S.map f ⊔ T.map f :=
(Subalgebra.gc_map_comap f).l_sup
theorem map_inf (f : A →ₐ[R] B) (hf : Function.Injective f) (S T : Subalgebra R A) :
(S ⊓ T).map f = S.map f ⊓ T.map f := SetLike.coe_injective (Set.image_inter hf)
@[simp, norm_cast]
theorem coe_inf (S T : Subalgebra R A) : (↑(S ⊓ T) : Set A) = (S ∩ T : Set A) := rfl
@[simp]
theorem mem_inf {S T : Subalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T := Iff.rfl
open Subalgebra in
@[simp]
theorem inf_toSubmodule (S T : Subalgebra R A) :
toSubmodule (S ⊓ T) = toSubmodule S ⊓ toSubmodule T := rfl
@[simp]
theorem inf_toSubsemiring (S T : Subalgebra R A) :
(S ⊓ T).toSubsemiring = S.toSubsemiring ⊓ T.toSubsemiring :=
rfl
@[simp]
theorem sup_toSubsemiring (S T : Subalgebra R A) :
(S ⊔ T).toSubsemiring = S.toSubsemiring ⊔ T.toSubsemiring := by
rw [← S.toSubsemiring.closure_eq, ← T.toSubsemiring.closure_eq, ← Subsemiring.closure_union]
simp_rw [sup_def, adjoin_toSubsemiring, Subalgebra.coe_toSubsemiring]
congr 1
rw [Set.union_eq_right]
rintro _ ⟨x, rfl⟩
exact Set.mem_union_left _ (algebraMap_mem S x)
@[simp, norm_cast]
theorem coe_sInf (S : Set (Subalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=
sInf_image
theorem mem_sInf {S : Set (Subalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by
simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]
@[simp]
theorem sInf_toSubmodule (S : Set (Subalgebra R A)) :
Subalgebra.toSubmodule (sInf S) = sInf (Subalgebra.toSubmodule '' S) :=
SetLike.coe_injective <| by simp
@[simp]
theorem sInf_toSubsemiring (S : Set (Subalgebra R A)) :
(sInf S).toSubsemiring = sInf (Subalgebra.toSubsemiring '' S) :=
SetLike.coe_injective <| by simp
open Subalgebra in
@[simp]
theorem sSup_toSubsemiring (S : Set (Subalgebra R A)) (hS : S.Nonempty) :
(sSup S).toSubsemiring = sSup (toSubsemiring '' S) := by
have h : toSubsemiring '' S = Subsemiring.closure '' (SetLike.coe '' S) := by
rw [Set.image_image]
congr! with x
exact x.toSubsemiring.closure_eq.symm
rw [h, sSup_image, ← Subsemiring.closure_sUnion, sSup_def, adjoin_toSubsemiring]
congr 1
rw [Set.union_eq_right]
rintro _ ⟨x, rfl⟩
obtain ⟨y, hy⟩ := hS
simp only [Set.mem_sUnion, Set.mem_image, exists_exists_and_eq_and, SetLike.mem_coe]
exact ⟨y, hy, algebraMap_mem y x⟩
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} {S : ι → Subalgebra R A} : (↑(⨅ i, S i) : Set A) = ⋂ i, S i := by
simp [iInf]
theorem mem_iInf {ι : Sort*} {S : ι → Subalgebra R A} {x : A} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by
simp only [iInf, mem_sInf, Set.forall_mem_range]
theorem map_iInf {ι : Sort*} [Nonempty ι] (f : A →ₐ[R] B) (hf : Function.Injective f)
(s : ι → Subalgebra R A) : (iInf s).map f = ⨅ (i : ι), (s i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s)
open Subalgebra in
@[simp]
theorem iInf_toSubmodule {ι : Sort*} (S : ι → Subalgebra R A) :
toSubmodule (⨅ i, S i) = ⨅ i, toSubmodule (S i) :=
SetLike.coe_injective <| by simp
@[simp]
theorem iInf_toSubsemiring {ι : Sort*} (S : ι → Subalgebra R A) :
(iInf S).toSubsemiring = ⨅ i, (S i).toSubsemiring := by
simp only [iInf, sInf_toSubsemiring, ← Set.range_comp, Function.comp_def]
@[simp]
theorem iSup_toSubsemiring {ι : Sort*} [Nonempty ι] (S : ι → Subalgebra R A) :
(iSup S).toSubsemiring = ⨆ i, (S i).toSubsemiring := by
simp only [iSup, Set.range_nonempty, sSup_toSubsemiring, ← Set.range_comp, Function.comp_def]
lemma mem_iSup_of_mem {ι : Sort*} {S : ι → Subalgebra R A} (i : ι) {x : A} (hx : x ∈ S i) :
x ∈ iSup S :=
le_iSup S i hx
@[elab_as_elim]
lemma iSup_induction {ι : Sort*} (S : ι → Subalgebra R A) {motive : A → Prop}
{x : A} (mem : x ∈ ⨆ i, S i)
(basic : ∀ i, ∀ a ∈ S i, motive a)
(zero : motive 0) (one : motive 1)
(add : ∀ a b, motive a → motive b → motive (a + b))
(mul : ∀ a b, motive a → motive b → motive (a * b))
(algebraMap : ∀ r, motive (algebraMap R A r)) : motive x := by
let T : Subalgebra R A :=
{ carrier := {x | motive x}
mul_mem' {a b} := mul a b
one_mem' := one
add_mem' {a b} := add a b
zero_mem' := zero
algebraMap_mem' := algebraMap }
suffices iSup S ≤ T from this mem
rwa [iSup_le_iff]
/-- A dependent version of `Subalgebra.iSup_induction`. -/
@[elab_as_elim]
theorem iSup_induction' {ι : Sort*} (S : ι → Subalgebra R A) {motive : ∀ x, (x ∈ ⨆ i, S i) → Prop}
{x : A} (mem : x ∈ ⨆ i, S i)
(basic : ∀ (i) (x) (hx : x ∈ S i), motive x (mem_iSup_of_mem i hx))
(zero : motive 0 (zero_mem _)) (one : motive 1 (one_mem _))
(add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›))
(mul : ∀ x y hx hy, motive x hx → motive y hy → motive (x * y) (mul_mem ‹_› ‹_›))
(algebraMap : ∀ r, motive (algebraMap R A r) (Subalgebra.algebraMap_mem _ ‹_›)) :
motive x mem := by
refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, S i) (hc : motive x hx) ↦ hc
exact iSup_induction S (motive := fun x' ↦ ∃ h, motive x' h) mem
(fun _ _ h ↦ ⟨_, basic _ _ h⟩) ⟨_, zero⟩ ⟨_, one⟩ (fun _ _ h h' ↦ ⟨_, add _ _ _ _ h.2 h'.2⟩)
(fun _ _ h h' ↦ ⟨_, mul _ _ _ _ h.2 h'.2⟩) fun _ ↦ ⟨_, algebraMap _⟩
instance : Inhabited (Subalgebra R A) := ⟨⊥⟩
theorem mem_bot {x : A} : x ∈ (⊥ : Subalgebra R A) ↔ x ∈ Set.range (algebraMap R A) := Iff.rfl
/-- TODO: change proof to `rfl` when fixing https://github.com/leanprover-community/mathlib4/issues/18110. -/
theorem toSubmodule_bot : Subalgebra.toSubmodule (⊥ : Subalgebra R A) = 1 :=
Submodule.one_eq_range.symm
@[simp]
theorem coe_bot : ((⊥ : Subalgebra R A) : Set A) = Set.range (algebraMap R A) := rfl
theorem eq_top_iff {S : Subalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=
⟨fun h x => by rw [h]; exact mem_top, fun h => by
ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩
theorem _root_.AlgHom.range_eq_top (f : A →ₐ[R] B) :
f.range = (⊤ : Subalgebra R B) ↔ Function.Surjective f :=
Algebra.eq_top_iff
@[simp]
theorem range_ofId : (Algebra.ofId R A).range = ⊥ := rfl
@[simp]
theorem range_id : (AlgHom.id R A).range = ⊤ :=
SetLike.coe_injective Set.range_id
@[simp]
theorem map_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R A).map f = f.range :=
SetLike.coe_injective Set.image_univ
@[simp]
theorem map_bot (f : A →ₐ[R] B) : (⊥ : Subalgebra R A).map f = ⊥ :=
Subalgebra.toSubmodule_injective <| by
simpa only [Subalgebra.map_toSubmodule, toSubmodule_bot] using Submodule.map_one _
@[simp]
theorem comap_top (f : A →ₐ[R] B) : (⊤ : Subalgebra R B).comap f = ⊤ :=
eq_top_iff.2 fun _x => mem_top
/-- `AlgHom` to `⊤ : Subalgebra R A`. -/
def toTop : A →ₐ[R] (⊤ : Subalgebra R A) :=
(AlgHom.id R A).codRestrict ⊤ fun _ => mem_top
theorem surjective_algebraMap_iff :
Function.Surjective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=
⟨fun h =>
eq_bot_iff.2 fun y _ =>
let ⟨_x, hx⟩ := h y
hx ▸ Subalgebra.algebraMap_mem _ _,
fun h y => Algebra.mem_bot.1 <| eq_bot_iff.1 h (Algebra.mem_top : y ∈ _)⟩
theorem bijective_algebraMap_iff {R A : Type*} [Field R] [Semiring A] [Nontrivial A]
[Algebra R A] : Function.Bijective (algebraMap R A) ↔ (⊤ : Subalgebra R A) = ⊥ :=
⟨fun h => surjective_algebraMap_iff.1 h.2, fun h =>
⟨(algebraMap R A).injective, surjective_algebraMap_iff.2 h⟩⟩
/-- The bottom subalgebra is isomorphic to the base ring. -/
noncomputable def botEquivOfInjective (h : Function.Injective (algebraMap R A)) :
(⊥ : Subalgebra R A) ≃ₐ[R] R :=
AlgEquiv.symm <|
AlgEquiv.ofBijective (Algebra.ofId R _)
⟨fun _x _y hxy => h (congr_arg Subtype.val hxy :), fun ⟨_y, x, hx⟩ => ⟨x, Subtype.eq hx⟩⟩
/-- The bottom subalgebra is isomorphic to the field. -/
@[simps! symm_apply]
noncomputable def botEquiv (F R : Type*) [Field F] [Semiring R] [Nontrivial R] [Algebra F R] :
(⊥ : Subalgebra F R) ≃ₐ[F] F :=
botEquivOfInjective (RingHom.injective _)
end Algebra
namespace Subalgebra
open Algebra
variable {R : Type u} {A : Type v} {B : Type w}
variable [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
variable (S : Subalgebra R A)
/-- The top subalgebra is isomorphic to the algebra.
This is the algebra version of `Submodule.topEquiv`. -/
@[simps!]
def topEquiv : (⊤ : Subalgebra R A) ≃ₐ[R] A :=
AlgEquiv.ofAlgHom (Subalgebra.val ⊤) toTop rfl rfl
instance _root_.AlgHom.subsingleton [Subsingleton (Subalgebra R A)] : Subsingleton (A →ₐ[R] B) :=
⟨fun f g =>
AlgHom.ext fun a =>
have : a ∈ (⊥ : Subalgebra R A) := Subsingleton.elim (⊤ : Subalgebra R A) ⊥ ▸ mem_top
let ⟨_x, hx⟩ := Set.mem_range.mp (mem_bot.mp this)
hx ▸ (f.commutes _).trans (g.commutes _).symm⟩
instance _root_.AlgEquiv.subsingleton_left [Subsingleton (Subalgebra R A)] :
Subsingleton (A ≃ₐ[R] B) :=
⟨fun f g => AlgEquiv.ext fun x => AlgHom.ext_iff.mp (Subsingleton.elim f.toAlgHom g.toAlgHom) x⟩
instance _root_.AlgEquiv.subsingleton_right [Subsingleton (Subalgebra R B)] :
Subsingleton (A ≃ₐ[R] B) :=
⟨fun f g => by rw [← f.symm_symm, Subsingleton.elim f.symm g.symm, g.symm_symm]⟩
instance : Unique (Subalgebra R R) :=
{ inferInstanceAs (Inhabited (Subalgebra R R)) with
uniq := by
intro S
refine le_antisymm ?_ bot_le
intro _ _
simp only [Set.mem_range, mem_bot, algebraMap_self_apply, exists_apply_eq_apply, default] }
section Center
variable (R A)
@[simp]
theorem center_eq_top (A : Type*) [CommSemiring A] [Algebra R A] : center R A = ⊤ :=
SetLike.coe_injective (Set.center_eq_univ A)
end Center
section Centralizer
variable (R)
@[simp]
theorem centralizer_eq_top_iff_subset {s : Set A} : centralizer R s = ⊤ ↔ s ⊆ center R A :=
SetLike.ext'_iff.trans Set.centralizer_eq_top_iff_subset
end Centralizer
end Subalgebra
section Equalizer
namespace AlgHom
variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
variable {F : Type*}
variable [FunLike F A B] [AlgHomClass F R A B]
@[simp]
theorem equalizer_eq_top {φ ψ : F} : equalizer φ ψ = ⊤ ↔ φ = ψ := by
simp [SetLike.ext_iff, DFunLike.ext_iff]
@[simp]
theorem equalizer_same (φ : F) : equalizer φ φ = ⊤ := equalizer_eq_top.2 rfl
theorem eqOn_sup {φ ψ : F} {S T : Subalgebra R A} (hS : Set.EqOn φ ψ S) (hT : Set.EqOn φ ψ T) :
Set.EqOn φ ψ ↑(S ⊔ T) := by
rw [← le_equalizer] at hS hT ⊢
exact sup_le hS hT
theorem ext_on_codisjoint {φ ψ : F} {S T : Subalgebra R A} (hST : Codisjoint S T)
(hS : Set.EqOn φ ψ S) (hT : Set.EqOn φ ψ T) : φ = ψ :=
DFunLike.ext _ _ fun _ ↦ eqOn_sup hS hT <| hST.eq_top.symm ▸ trivial
end AlgHom
end Equalizer
section MapComap
namespace Subalgebra
variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
theorem map_comap_eq (f : A →ₐ[R] B) (S : Subalgebra R B) : (S.comap f).map f = S ⊓ f.range :=
SetLike.coe_injective Set.image_preimage_eq_inter_range
theorem map_comap_eq_self
{f : A →ₐ[R] B} {S : Subalgebra R B} (h : S ≤ f.range) : (S.comap f).map f = S := by
simpa only [inf_of_le_left h] using map_comap_eq f S
theorem map_comap_eq_self_of_surjective
{f : A →ₐ[R] B} (hf : Function.Surjective f) (S : Subalgebra R B) : (S.comap f).map f = S :=
map_comap_eq_self <| by simp [(AlgHom.range_eq_top f).2 hf]
end Subalgebra
end MapComap
section Adjoin
universe uR uS uA uB
open Submodule Subsemiring
variable {R : Type uR} {S : Type uS} {A : Type uA} {B : Type uB}
namespace Algebra
section Semiring
variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B]
variable [Algebra R S] [Algebra R A] [Algebra S A] [Algebra R B] [IsScalarTower R S A]
variable {s t : Set A}
@[simp, aesop safe 20 (rule_sets := [SetLike])]
theorem subset_adjoin : s ⊆ adjoin R s :=
Algebra.gc.le_u_l s
@[aesop 80% (rule_sets := [SetLike])]
theorem mem_adjoin_of_mem {s : Set A} {x : A} (hx : x ∈ s) : x ∈ adjoin R s := subset_adjoin hx
theorem adjoin_le {S : Subalgebra R A} (H : s ⊆ S) : adjoin R s ≤ S :=
Algebra.gc.l_le H
theorem adjoin_singleton_le {S : Subalgebra R A} {a : A} (H : a ∈ S) : adjoin R {a} ≤ S :=
adjoin_le (Set.singleton_subset_iff.mpr H)
theorem adjoin_eq_sInf : adjoin R s = sInf { p : Subalgebra R A | s ⊆ p } :=
le_antisymm (le_sInf fun _ h => adjoin_le h) (sInf_le subset_adjoin)
theorem adjoin_le_iff {S : Subalgebra R A} : adjoin R s ≤ S ↔ s ⊆ S :=
Algebra.gc _ _
@[gcongr]
theorem adjoin_mono (H : s ⊆ t) : adjoin R s ≤ adjoin R t :=
Algebra.gc.monotone_l H
theorem adjoin_eq_of_le (S : Subalgebra R A) (h₁ : s ⊆ S) (h₂ : S ≤ adjoin R s) : adjoin R s = S :=
le_antisymm (adjoin_le h₁) h₂
theorem adjoin_eq (S : Subalgebra R A) : adjoin R ↑S = S :=
adjoin_eq_of_le _ (Set.Subset.refl _) subset_adjoin
theorem adjoin_iUnion {α : Type*} (s : α → Set A) :
adjoin R (Set.iUnion s) = ⨆ i : α, adjoin R (s i) :=
(@Algebra.gc R A _ _ _).l_iSup
theorem adjoin_attach_biUnion [DecidableEq A] {α : Type*} {s : Finset α} (f : s → Finset A) :
adjoin R (s.attach.biUnion f : Set A) = ⨆ x, adjoin R (f x) := by simp [adjoin_iUnion]
@[elab_as_elim]
theorem adjoin_induction {p : (x : A) → x ∈ adjoin R s → Prop}
(mem : ∀ (x) (hx : x ∈ s), p x (subset_adjoin hx))
(algebraMap : ∀ r, p (algebraMap R A r) (algebraMap_mem _ r))
(add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy))
(mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
{x : A} (hx : x ∈ adjoin R s) : p x hx :=
let S : Subalgebra R A :=
{ carrier := { x | ∃ hx, p x hx }
mul_mem' := by rintro _ _ ⟨_, hpx⟩ ⟨_, hpy⟩; exact ⟨_, mul _ _ _ _ hpx hpy⟩
add_mem' := by rintro _ _ ⟨_, hpx⟩ ⟨_, hpy⟩; exact ⟨_, add _ _ _ _ hpx hpy⟩
algebraMap_mem' := fun r ↦ ⟨_, algebraMap r⟩ }
adjoin_le (S := S) (fun y hy ↦ ⟨subset_adjoin hy, mem y hy⟩) hx |>.elim fun _ ↦ _root_.id
/-- Induction principle for the algebra generated by a set `s`: show that `p x y` holds for any
`x y ∈ adjoin R s` given that it holds for `x y ∈ s` and that it satisfies a number of
natural properties. -/
@[elab_as_elim]
theorem adjoin_induction₂ {s : Set A} {p : (x y : A) → x ∈ adjoin R s → y ∈ adjoin R s → Prop}
(mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_adjoin hx) (subset_adjoin hy))
(algebraMap_both : ∀ r₁ r₂, p (algebraMap R A r₁) (algebraMap R A r₂) (algebraMap_mem _ r₁)
(algebraMap_mem _ r₂))
(algebraMap_left : ∀ (r) (x) (hx : x ∈ s), p (algebraMap R A r) x (algebraMap_mem _ r)
(subset_adjoin hx))
(algebraMap_right : ∀ (r) (x) (hx : x ∈ s), p x (algebraMap R A r) (subset_adjoin hx)
(algebraMap_mem _ r))
(add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz)
(add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz))
(mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz)
(mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz))
{x y : A} (hx : x ∈ adjoin R s) (hy : y ∈ adjoin R s) :
p x y hx hy := by
induction hy using adjoin_induction with
| mem z hz => induction hx using adjoin_induction with
| mem _ h => exact mem_mem _ _ h hz
| algebraMap _ => exact algebraMap_left _ _ hz
| mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂
| add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂
| algebraMap r =>
induction hx using adjoin_induction with
| mem _ h => exact algebraMap_right _ _ h
| algebraMap _ => exact algebraMap_both _ _
| mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂
| add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂
| mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂
| add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂
@[simp]
theorem adjoin_adjoin_coe_preimage {s : Set A} : adjoin R (((↑) : adjoin R s → A) ⁻¹' s) = ⊤ := by
refine eq_top_iff.2 fun ⟨x, hx⟩ ↦
adjoin_induction (fun a ha ↦ ?_) (fun r ↦ ?_) (fun _ _ _ _ ↦ ?_) (fun _ _ _ _ ↦ ?_) hx
· exact subset_adjoin ha
· exact Subalgebra.algebraMap_mem _ r
· exact Subalgebra.add_mem _
· exact Subalgebra.mul_mem _
theorem adjoin_union (s t : Set A) : adjoin R (s ∪ t) = adjoin R s ⊔ adjoin R t :=
(Algebra.gc : GaloisConnection _ ((↑) : Subalgebra R A → Set A)).l_sup
variable (R A)
@[simp]
theorem adjoin_empty : adjoin R (∅ : Set A) = ⊥ := Algebra.gc.l_bot
@[simp]
theorem adjoin_univ : adjoin R (Set.univ : Set A) = ⊤ := Algebra.gi.l_top
variable {R} in
@[simp]
theorem adjoin_singleton_algebraMap (x : R) : adjoin R {algebraMap R A x} = ⊥ :=
bot_unique <| adjoin_singleton_le <| Subalgebra.algebraMap_mem _ _
@[simp]
theorem adjoin_singleton_natCast (n : ℕ) : adjoin R {(n : A)} = ⊥ := by
simpa using adjoin_singleton_algebraMap A (n : R)
@[simp]
theorem adjoin_singleton_zero : adjoin R ({0} : Set A) = ⊥ :=
mod_cast adjoin_singleton_natCast R A 0
@[simp]
theorem adjoin_singleton_one : adjoin R ({1} : Set A) = ⊥ :=
mod_cast adjoin_singleton_natCast R A 1
variable {A} (s)
variable {R} in
@[simp]
theorem adjoin_insert_algebraMap (x : R) (s : Set A) :
adjoin R (insert (algebraMap R A x) s) = adjoin R s := by
rw [Set.insert_eq, adjoin_union]
simp
@[simp]
theorem adjoin_insert_natCast (n : ℕ) (s : Set A) : adjoin R (insert (n : A) s) = adjoin R s :=
mod_cast adjoin_insert_algebraMap (n : R) s
@[simp]
theorem adjoin_insert_zero (s : Set A) : adjoin R (insert 0 s) = adjoin R s :=
mod_cast adjoin_insert_natCast R 0 s
@[simp]
theorem adjoin_insert_one (s : Set A) : adjoin R (insert 1 s) = adjoin R s :=
mod_cast adjoin_insert_natCast R 1 s
theorem adjoin_eq_span : Subalgebra.toSubmodule (adjoin R s) = span R (Submonoid.closure s) := by
apply le_antisymm
· intro r hr
rcases Subsemiring.mem_closure_iff_exists_list.1 hr with ⟨L, HL, rfl⟩
clear hr
induction' L with hd tl ih
· exact zero_mem _
rw [List.forall_mem_cons] at HL
rw [List.map_cons, List.sum_cons]
refine Submodule.add_mem _ ?_ (ih HL.2)
replace HL := HL.1
clear ih tl
suffices ∃ (z r : _) (_hr : r ∈ Submonoid.closure s), z • r = List.prod hd by
rcases this with ⟨z, r, hr, hzr⟩
rw [← hzr]
exact smul_mem _ _ (subset_span hr)
induction' hd with hd tl ih
· exact ⟨1, 1, (Submonoid.closure s).one_mem', one_smul _ _⟩
rw [List.forall_mem_cons] at HL
rcases ih HL.2 with ⟨z, r, hr, hzr⟩
rw [List.prod_cons, ← hzr]
rcases HL.1 with (⟨hd, rfl⟩ | hs)
· refine ⟨hd * z, r, hr, ?_⟩
rw [Algebra.smul_def, Algebra.smul_def, (algebraMap _ _).map_mul, _root_.mul_assoc]
· exact
⟨z, hd * r, Submonoid.mul_mem _ (Submonoid.subset_closure hs) hr,
(mul_smul_comm _ _ _).symm⟩
refine span_le.2 ?_
change Submonoid.closure s ≤ (adjoin R s).toSubsemiring.toSubmonoid
exact Submonoid.closure_le.2 subset_adjoin
theorem span_le_adjoin (s : Set A) : span R s ≤ Subalgebra.toSubmodule (adjoin R s) :=
span_le.mpr subset_adjoin
theorem adjoin_toSubmodule_le {s : Set A} {t : Submodule R A} :
Subalgebra.toSubmodule (adjoin R s) ≤ t ↔ ↑(Submonoid.closure s) ⊆ (t : Set A) := by
rw [adjoin_eq_span, span_le]
theorem adjoin_eq_span_of_subset {s : Set A} (hs : ↑(Submonoid.closure s) ⊆ (span R s : Set A)) :
Subalgebra.toSubmodule (adjoin R s) = span R s :=
le_antisymm ((adjoin_toSubmodule_le R).mpr hs) (span_le_adjoin R s)
@[simp]
theorem adjoin_span {s : Set A} : adjoin R (Submodule.span R s : Set A) = adjoin R s :=
le_antisymm (adjoin_le (span_le_adjoin _ _)) (adjoin_mono Submodule.subset_span)
theorem adjoin_image (f : A →ₐ[R] B) (s : Set A) : adjoin R (f '' s) = (adjoin R s).map f :=
le_antisymm (adjoin_le <| Set.image_mono subset_adjoin) <|
Subalgebra.map_le.2 <| adjoin_le <| Set.image_subset_iff.1 <| by
simp only [Set.image_id', coe_carrier_toSubmonoid, Subalgebra.coe_toSubsemiring,
Subalgebra.coe_comap]
exact fun x hx => subset_adjoin ⟨x, hx, rfl⟩
@[simp]
theorem adjoin_insert_adjoin (x : A) : adjoin R (insert x ↑(adjoin R s)) = adjoin R (insert x s) :=
le_antisymm
(adjoin_le
(Set.insert_subset_iff.mpr
⟨subset_adjoin (Set.mem_insert _ _), adjoin_mono (Set.subset_insert _ _)⟩))
(Algebra.adjoin_mono (Set.insert_subset_insert Algebra.subset_adjoin))
theorem mem_adjoin_of_map_mul {s} {x : A} {f : A →ₗ[R] B} (hf : ∀ a₁ a₂, f (a₁ * a₂) = f a₁ * f a₂)
(h : x ∈ adjoin R s) : f x ∈ adjoin R (f '' (s ∪ {1})) := by
induction h using adjoin_induction with
| mem a ha => exact subset_adjoin ⟨a, ⟨Set.subset_union_left ha, rfl⟩⟩
| algebraMap r =>
have : f 1 ∈ adjoin R (f '' (s ∪ {1})) :=
subset_adjoin ⟨1, ⟨Set.subset_union_right <| Set.mem_singleton 1, rfl⟩⟩
convert Subalgebra.smul_mem (adjoin R (f '' (s ∪ {1}))) this r
rw [algebraMap_eq_smul_one]
exact f.map_smul _ _
| add y z _ _ hy hz => simpa [hy, hz] using Subalgebra.add_mem _ hy hz
| mul y z _ _ hy hz => simpa [hf, hy, hz] using Subalgebra.mul_mem _ hy hz
lemma adjoin_le_centralizer_centralizer (s : Set A) :
adjoin R s ≤ Subalgebra.centralizer R (Subalgebra.centralizer R s) :=
adjoin_le Set.subset_centralizer_centralizer
/-- If all elements of `s : Set A` commute pairwise, then `adjoin s` is a commutative semiring. -/
abbrev adjoinCommSemiringOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) :
CommSemiring (adjoin R s) :=
{ (adjoin R s).toSemiring with
mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦
have := adjoin_le_centralizer_centralizer R s
Subtype.ext <| Set.centralizer_centralizer_comm_of_comm hcomm _ (this h₁) _ (this h₂) }
variable {R}
lemma commute_of_mem_adjoin_of_forall_mem_commute {a b : A} {s : Set A}
(hb : b ∈ adjoin R s) (h : ∀ b ∈ s, Commute a b) :
Commute a b := by
induction hb using adjoin_induction with
| mem x hx => exact h x hx
| algebraMap r => exact commutes r a |>.symm
| add y z _ _ hy hz => exact hy.add_right hz
| mul y z _ _ hy hz => exact hy.mul_right hz
lemma commute_of_mem_adjoin_singleton_of_commute {a b c : A}
(hc : c ∈ adjoin R {b}) (h : Commute a b) :
Commute a c :=
commute_of_mem_adjoin_of_forall_mem_commute hc <| by simpa
lemma commute_of_mem_adjoin_self {a b : A} (hb : b ∈ adjoin R {a}) :
Commute a b :=
commute_of_mem_adjoin_singleton_of_commute hb rfl
variable (R)
theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) :=
Algebra.subset_adjoin (Set.mem_singleton_iff.mpr rfl)
end Semiring
section CommSemiring
variable [CommSemiring R] [CommSemiring A]
variable [Algebra R A] {s t : Set A}
variable (R s t)
theorem adjoin_union_coe_submodule :
Subalgebra.toSubmodule (adjoin R (s ∪ t)) =
Subalgebra.toSubmodule (adjoin R s) * Subalgebra.toSubmodule (adjoin R t) := by
rw [adjoin_eq_span, adjoin_eq_span, adjoin_eq_span, span_mul_span]
congr 1 with z; simp [Submonoid.closure_union, Submonoid.mem_sup, Set.mem_mul]
end CommSemiring
section Ring
variable [CommRing R] [Ring A]
variable [Algebra R A] {s t : Set A}
@[simp]
theorem adjoin_singleton_intCast (n : ℤ) : adjoin R {(n : A)} = ⊥ := by
simpa using adjoin_singleton_algebraMap A (n : R)
@[simp]
theorem adjoin_insert_intCast (n : ℤ) (s : Set A) : adjoin R (insert (n : A) s) = adjoin R s := by
simpa using adjoin_insert_algebraMap (n : R) s
theorem adjoin_eq_ring_closure (s : Set A) :
(adjoin R s).toSubring = Subring.closure (Set.range (algebraMap R A) ∪ s) :=
.symm <| Subring.closure_eq_of_le (by simp [adjoin]) fun x hx =>
Subsemiring.closure_induction Subring.subset_closure (Subring.zero_mem _) (Subring.one_mem _)
(fun _ _ _ _ => Subring.add_mem _) (fun _ _ _ _ => Subring.mul_mem _) hx
theorem mem_adjoin_iff {s : Set A} {x : A} :
x ∈ adjoin R s ↔ x ∈ Subring.closure (Set.range (algebraMap R A) ∪ s) := by
rw [← Subalgebra.mem_toSubring, adjoin_eq_ring_closure]
variable (R)
/-- If all elements of `s : Set A` commute pairwise, then `adjoin R s` is a commutative
ring. -/
abbrev adjoinCommRingOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) :
CommRing (adjoin R s) :=
{ (adjoin R s).toRing, adjoinCommSemiringOfComm R hcomm with }
end Ring
end Algebra
open Algebra Subalgebra
namespace AlgHom
variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
theorem map_adjoin (φ : A →ₐ[R] B) (s : Set A) : (adjoin R s).map φ = adjoin R (φ '' s) :=
(adjoin_image _ _ _).symm
@[simp]
theorem map_adjoin_singleton (e : A →ₐ[R] B) (x : A) :
(adjoin R {x}).map e = adjoin R {e x} := by
rw [map_adjoin, Set.image_singleton]
theorem adjoin_le_equalizer (φ₁ φ₂ : A →ₐ[R] B) {s : Set A} (h : s.EqOn φ₁ φ₂) :
adjoin R s ≤ equalizer φ₁ φ₂ :=
adjoin_le h
theorem ext_of_adjoin_eq_top {s : Set A} (h : adjoin R s = ⊤) ⦃φ₁ φ₂ : A →ₐ[R] B⦄
(hs : s.EqOn φ₁ φ₂) : φ₁ = φ₂ :=
ext fun _x => adjoin_le_equalizer φ₁ φ₂ hs <| h.symm ▸ trivial
/-- Two algebra morphisms are equal on `Algebra.span s`iff they are equal on s -/
theorem eqOn_adjoin_iff {φ ψ : A →ₐ[R] B} {s : Set A} :
Set.EqOn φ ψ (adjoin R s) ↔ Set.EqOn φ ψ s := by
have (S : Set A) : S ≤ equalizer φ ψ ↔ Set.EqOn φ ψ S := Iff.rfl
simp only [← this, Set.le_eq_subset, SetLike.coe_subset_coe, adjoin_le_iff]
theorem adjoin_ext {s : Set A} ⦃φ₁ φ₂ : adjoin R s →ₐ[R] B⦄
(h : ∀ x hx, φ₁ ⟨x, subset_adjoin hx⟩ = φ₂ ⟨x, subset_adjoin hx⟩) : φ₁ = φ₂ :=
ext fun ⟨x, hx⟩ ↦ adjoin_induction h (fun _ ↦ φ₂.commutes _ ▸ φ₁.commutes _)
(fun _ _ _ _ h₁ h₂ ↦ by convert congr_arg₂ (· + ·) h₁ h₂ <;> rw [← map_add] <;> rfl)
(fun _ _ _ _ h₁ h₂ ↦ by convert congr_arg₂ (· * ·) h₁ h₂ <;> rw [← map_mul] <;> rfl) hx
theorem ext_of_eq_adjoin {S : Subalgebra R A} {s : Set A} (hS : S = adjoin R s) ⦃φ₁ φ₂ : S →ₐ[R] B⦄
(h : ∀ x hx, φ₁ ⟨x, hS.ge (subset_adjoin hx)⟩ = φ₂ ⟨x, hS.ge (subset_adjoin hx)⟩) :
φ₁ = φ₂ := by
subst hS; exact adjoin_ext h
end AlgHom
section NatInt
theorem Algebra.adjoin_nat {R : Type*} [Semiring R] (s : Set R) :
adjoin ℕ s = subalgebraOfSubsemiring (Subsemiring.closure s) :=
le_antisymm (adjoin_le Subsemiring.subset_closure)
(Subsemiring.closure_le.2 subset_adjoin : Subsemiring.closure s ≤ (adjoin ℕ s).toSubsemiring)
theorem Algebra.adjoin_int {R : Type*} [Ring R] (s : Set R) :
adjoin ℤ s = subalgebraOfSubring (Subring.closure s) :=
le_antisymm (adjoin_le Subring.subset_closure)
(Subring.closure_le.2 subset_adjoin : Subring.closure s ≤ (adjoin ℤ s).toSubring)
/-- The `ℕ`-algebra equivalence between `Subsemiring.closure s` and `Algebra.adjoin ℕ s` given
by the identity map. -/
def Subsemiring.closureEquivAdjoinNat {R : Type*} [Semiring R] (s : Set R) :
Subsemiring.closure s ≃ₐ[ℕ] Algebra.adjoin ℕ s :=
Subalgebra.equivOfEq (subalgebraOfSubsemiring <| Subsemiring.closure s) _ (adjoin_nat s).symm
/-- The `ℤ`-algebra equivalence between `Subring.closure s` and `Algebra.adjoin ℤ s` given by
the identity map. -/
def Subring.closureEquivAdjoinInt {R : Type*} [Ring R] (s : Set R) :
Subring.closure s ≃ₐ[ℤ] Algebra.adjoin ℤ s :=
Subalgebra.equivOfEq (subalgebraOfSubring <| Subring.closure s) _ (adjoin_int s).symm
end NatInt
section
variable (F E : Type*) {K : Type*} [CommSemiring E] [Semiring K] [SMul F E] [Algebra E K]
/-- If `K / E / F` is a ring extension tower, `L` is a submonoid of `K / F` which is generated by
`S` as an `F`-module, then `E[L]` is generated by `S` as an `E`-module. -/
theorem Submonoid.adjoin_eq_span_of_eq_span [Semiring F] [Module F K] [IsScalarTower F E K]
(L : Submonoid K) {S : Set K} (h : (L : Set K) = span F S) :
toSubmodule (adjoin E (L : Set K)) = span E S := by
rw [adjoin_eq_span, L.closure_eq, h]
exact (span_le.mpr <| span_subset_span _ _ _).antisymm (span_mono subset_span)
variable [CommSemiring F] [Algebra F K] [IsScalarTower F E K] (L : Subalgebra F K) {F}
/-- If `K / E / F` is a ring extension tower, `L` is a subalgebra of `K / F` which is generated by
`S` as an `F`-module, then `E[L]` is generated by `S` as an `E`-module. -/
theorem Subalgebra.adjoin_eq_span_of_eq_span {S : Set K} (h : toSubmodule L = span F S) :
toSubmodule (adjoin E (L : Set K)) = span E S :=
L.toSubmonoid.adjoin_eq_span_of_eq_span F E (congr_arg ((↑) : _ → Set K) h)
end
section CommSemiring
variable (R) [CommSemiring R] [Ring A] [Algebra R A] [Ring B] [Algebra R B]
lemma NonUnitalAlgebra.adjoin_le_algebra_adjoin (s : Set A) :
adjoin R s ≤ (Algebra.adjoin R s).toNonUnitalSubalgebra := adjoin_le Algebra.subset_adjoin
lemma Algebra.adjoin_nonUnitalSubalgebra (s : Set A) :
adjoin R (NonUnitalAlgebra.adjoin R s : Set A) = adjoin R s :=
le_antisymm
(adjoin_le <| NonUnitalAlgebra.adjoin_le_algebra_adjoin R s)
(adjoin_le <| (NonUnitalAlgebra.subset_adjoin R).trans subset_adjoin)
end CommSemiring
namespace Subalgebra
variable [CommSemiring R] [Ring A] [Algebra R A] [Ring B] [Algebra R B]
theorem comap_map_eq (f : A →ₐ[R] B) (S : Subalgebra R A) :
(S.map f).comap f = S ⊔ Algebra.adjoin R (f ⁻¹' {0}) := by
apply le_antisymm
· intro x hx
rw [mem_comap, mem_map] at hx
obtain ⟨y, hy, hxy⟩ := hx
replace hxy : x - y ∈ f ⁻¹' {0} := by simp [hxy]
rw [← Algebra.adjoin_eq S, ← Algebra.adjoin_union, ← add_sub_cancel y x]
exact Subalgebra.add_mem _
(Algebra.subset_adjoin <| Or.inl hy) (Algebra.subset_adjoin <| Or.inr hxy)
· rw [← map_le, Algebra.map_sup, f.map_adjoin]
apply le_of_eq
rw [sup_eq_left, Algebra.adjoin_le_iff]
exact (Set.image_preimage_subset f {0}).trans (Set.singleton_subset_iff.2 (S.map f).zero_mem)
theorem comap_map_eq_self {f : A →ₐ[R] B} {S : Subalgebra R A}
(h : f ⁻¹' {0} ⊆ S) : (S.map f).comap f = S := by
convert comap_map_eq f S
rwa [left_eq_sup, Algebra.adjoin_le_iff]
end Subalgebra
end Adjoin
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.