Context stringlengths 227 76.5k | target stringlengths 0 11.6k | file_name stringlengths 21 79 | start int64 14 3.67k | end int64 16 3.69k |
|---|---|---|---|---|
/-
Copyright (c) 2022 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Invertible
import Mathlib.Data.Sigma.Basic
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.Int.Cast.Basic
import Qq.MetaM
/-!
## The `Result` type for `norm_num`
We set up predicates `IsNat`, `IsInt`, and `IsRat`,
stating that an element of a ring is equal to the "normal form" of a natural number, integer,
or rational number coerced into that ring.
We then define `Result e`, which contains a proof that a typed expression `e : Q($Ξ±)`
is equal to the coercion of an explicit natural number, integer, or rational number,
or is either `true` or `false`.
-/
universe u
variable {Ξ± : Type u}
open Lean
open Lean.Meta Qq Lean.Elab Term
namespace Mathlib
namespace Meta.NormNum
variable {u : Level}
/-- A shortcut (non)instance for `AddMonoidWithOne β` to shrink generated proofs. -/
def instAddMonoidWithOneNat : AddMonoidWithOne β := inferInstance
/-- A shortcut (non)instance for `AddMonoidWithOne Ξ±` from `Ring Ξ±` to shrink generated proofs. -/
def instAddMonoidWithOne {Ξ± : Type u} [Ring Ξ±] : AddMonoidWithOne Ξ± := inferInstance
/-- Helper function to synthesize a typed `AddMonoidWithOne Ξ±` expression. -/
def inferAddMonoidWithOne (Ξ± : Q(Type u)) : MetaM Q(AddMonoidWithOne $Ξ±) :=
return β synthInstanceQ q(AddMonoidWithOne $Ξ±) <|>
throwError "not an AddMonoidWithOne"
/-- Helper function to synthesize a typed `Semiring Ξ±` expression. -/
def inferSemiring (Ξ± : Q(Type u)) : MetaM Q(Semiring $Ξ±) :=
return β synthInstanceQ q(Semiring $Ξ±) <|> throwError "not a semiring"
/-- Helper function to synthesize a typed `Ring Ξ±` expression. -/
def inferRing (Ξ± : Q(Type u)) : MetaM Q(Ring $Ξ±) :=
return β synthInstanceQ q(Ring $Ξ±) <|> throwError "not a ring"
/--
Represent an integer as a "raw" typed expression.
This uses `.lit (.natVal n)` internally to represent a natural number,
rather than the preferred `OfNat.ofNat` form.
We use this internally to avoid unnecessary typeclass searches.
This function is the inverse of `Expr.intLit!`.
-/
def mkRawIntLit (n : β€) : Q(β€) :=
let lit : Q(β) := mkRawNatLit n.natAbs
if 0 β€ n then q(.ofNat $lit) else q(.negOfNat $lit)
/--
Represent an integer as a "raw" typed expression.
This `.lit (.natVal n)` internally to represent a natural number,
rather than the preferred `OfNat.ofNat` form.
We use this internally to avoid unnecessary typeclass searches.
-/
def mkRawRatLit (q : β) : Q(β) :=
let nlit : Q(β€) := mkRawIntLit q.num
let dlit : Q(β) := mkRawNatLit q.den
q(mkRat $nlit $dlit)
/-- Extract the raw natlit representing the absolute value of a raw integer literal
(of the type produced by `Mathlib.Meta.NormNum.mkRawIntLit`) along with an equality proof. -/
def rawIntLitNatAbs (n : Q(β€)) : (m : Q(β)) Γ Q(Int.natAbs $n = $m) :=
if n.isAppOfArity ``Int.ofNat 1 then
have m : Q(β) := n.appArg!
β¨m, show Q(Int.natAbs (Int.ofNat $m) = $m) from q(Int.natAbs_natCast $m)β©
else if n.isAppOfArity ``Int.negOfNat 1 then
have m : Q(β) := n.appArg!
β¨m, show Q(Int.natAbs (Int.negOfNat $m) = $m) from q(Int.natAbs_neg $m)β©
else
panic! "not a raw integer literal"
/--
Constructs an `ofNat` application `a'` with the canonical instance, together with a proof that
the instance is equal to the result of `Nat.cast` on the given `AddMonoidWithOne` instance.
This function is performance-critical, as many higher level tactics have to construct numerals.
So rather than using typeclass search we hardcode the (relatively small) set of solutions
to the typeclass problem.
-/
def mkOfNat (Ξ± : Q(Type u)) (_sΞ± : Q(AddMonoidWithOne $Ξ±)) (lit : Q(β)) :
MetaM ((a' : Q($Ξ±)) Γ Q($lit = $a')) := do
if Ξ±.isConstOf ``Nat then
let a' : Q(β) := q(OfNat.ofNat $lit : β)
pure β¨a', (q(Eq.refl $a') : Expr)β©
else if Ξ±.isConstOf ``Int then
let a' : Q(β€) := q(OfNat.ofNat $lit : β€)
pure β¨a', (q(Eq.refl $a') : Expr)β©
else if Ξ±.isConstOf ``Rat then
let a' : Q(β) := q(OfNat.ofNat $lit : β)
pure β¨a', (q(Eq.refl $a') : Expr)β©
else
let some n := lit.rawNatLit? | failure
match n with
| 0 => pure β¨q(0 : $Ξ±), (q(Nat.cast_zero (R := $Ξ±)) : Expr)β©
| 1 => pure β¨q(1 : $Ξ±), (q(Nat.cast_one (R := $Ξ±)) : Expr)β©
| k+2 =>
let k : Q(β) := mkRawNatLit k
let _x : Q(Nat.AtLeastTwo $lit) :=
(q(instNatAtLeastTwo (n := $k)) : Expr)
let a' : Q($Ξ±) := q(OfNat.ofNat $lit)
pure β¨a', (q(Eq.refl $a') : Expr)β©
/-- Assert that an element of a semiring is equal to the coercion of some natural number. -/
structure IsNat {Ξ± : Type u} [AddMonoidWithOne Ξ±] (a : Ξ±) (n : β) : Prop where
/-- The element is equal to the coercion of the natural number. -/
out : a = n
theorem IsNat.raw_refl (n : β) : IsNat n n := β¨rflβ©
/--
A "raw nat cast" is an expression of the form `(Nat.rawCast lit : Ξ±)` where `lit` is a raw
natural number literal. These expressions are used by tactics like `ring` to decrease the number
of typeclass arguments required in each use of a number literal at type `Ξ±`.
-/
@[simp] def _root_.Nat.rawCast {Ξ± : Type u} [AddMonoidWithOne Ξ±] (n : β) : Ξ± := n
theorem IsNat.to_eq {Ξ± : Type u} [AddMonoidWithOne Ξ±] {n} : {a a' : Ξ±} β IsNat a n β n = a' β a = a'
| _, _, β¨rflβ©, rfl => rfl
theorem IsNat.to_raw_eq {a : Ξ±} {n : β} [AddMonoidWithOne Ξ±] : IsNat (a : Ξ±) n β a = n.rawCast
| β¨eβ© => e
theorem IsNat.of_raw (Ξ±) [AddMonoidWithOne Ξ±] (n : β) : IsNat (n.rawCast : Ξ±) n := β¨rflβ©
@[elab_as_elim]
theorem isNat.natElim {p : β β Prop} : {n : β} β {n' : β} β IsNat n n' β p n' β p n
| _, _, β¨rflβ©, h => h
/-- Assert that an element of a ring is equal to the coercion of some integer. -/
structure IsInt [Ring Ξ±] (a : Ξ±) (n : β€) : Prop where
/-- The element is equal to the coercion of the integer. -/
out : a = n
/--
A "raw int cast" is an expression of the form:
* `(Nat.rawCast lit : Ξ±)` where `lit` is a raw natural number literal
* `(Int.rawCast (Int.negOfNat lit) : Ξ±)` where `lit` is a nonzero raw natural number literal
(That is, we only actually use this function for negative integers.) This representation is used by
tactics like `ring` to decrease the number of typeclass arguments required in each use of a number
literal at type `Ξ±`.
-/
@[simp] def _root_.Int.rawCast [Ring Ξ±] (n : β€) : Ξ± := n
theorem IsInt.to_isNat {Ξ±} [Ring Ξ±] : β {a : Ξ±} {n}, IsInt a (.ofNat n) β IsNat a n
| _, _, β¨rflβ© => β¨by simpβ©
theorem IsNat.to_isInt {Ξ±} [Ring Ξ±] : β {a : Ξ±} {n}, IsNat a n β IsInt a (.ofNat n)
| _, _, β¨rflβ© => β¨by simpβ©
theorem IsInt.to_raw_eq {a : Ξ±} {n : β€} [Ring Ξ±] : IsInt (a : Ξ±) n β a = n.rawCast
| β¨eβ© => e
theorem IsInt.of_raw (Ξ±) [Ring Ξ±] (n : β€) : IsInt (n.rawCast : Ξ±) n := β¨rflβ©
theorem IsInt.neg_to_eq {Ξ±} [Ring Ξ±] {n} :
{a a' : Ξ±} β IsInt a (.negOfNat n) β n = a' β a = -a'
| _, _, β¨rflβ©, rfl => by simp [Int.negOfNat_eq, Int.cast_neg]
theorem IsInt.nonneg_to_eq {Ξ±} [Ring Ξ±] {n}
{a a' : Ξ±} (h : IsInt a (.ofNat n)) (e : n = a') : a = a' := h.to_isNat.to_eq e
/--
Assert that an element of a ring is equal to `num / denom`
(and `denom` is invertible so that this makes sense).
We will usually also have `num` and `denom` coprime,
although this is not part of the definition.
-/
inductive IsRat [Ring Ξ±] (a : Ξ±) (num : β€) (denom : β) : Prop
| mk (inv : Invertible (denom : Ξ±)) (eq : a = num * β
(denom : Ξ±))
/--
A "raw rat cast" is an expression of the form:
* `(Nat.rawCast lit : Ξ±)` where `lit` is a raw natural number literal
* `(Int.rawCast (Int.negOfNat lit) : Ξ±)` where `lit` is a nonzero raw natural number literal
* `(Rat.rawCast n d : Ξ±)` where `n` is a raw int literal, `d` is a raw nat literal, and `d` is not
`1` or `0`.
(where a raw int literal is of the form `Int.ofNat lit` or `Int.negOfNat nzlit` where `lit` is a raw
nat literal)
This representation is used by tactics like `ring` to decrease the number of typeclass arguments
required in each use of a number literal at type `Ξ±`.
-/
@[simp]
def _root_.Rat.rawCast [DivisionRing Ξ±] (n : β€) (d : β) : Ξ± := n / d
theorem IsRat.to_isNat {Ξ±} [Ring Ξ±] : β {a : Ξ±} {n}, IsRat a (.ofNat n) (nat_lit 1) β IsNat a n
| | _, _, β¨inv, rflβ© => have := @invertibleOne Ξ± _; β¨by simpβ©
| Mathlib/Tactic/NormNum/Result.lean | 212 | 213 |
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Algebra.Group.Submonoid.BigOperators
import Mathlib.GroupTheory.Subsemigroup.Center
import Mathlib.RingTheory.NonUnitalSubring.Defs
import Mathlib.RingTheory.NonUnitalSubsemiring.Basic
/-!
# `NonUnitalSubring`s
Let `R` be a non-unital ring.
We prove that non-unital subrings are a complete lattice, and that you can `map` (pushforward) and
`comap` (pull back) them along ring homomorphisms.
We define the `closure` construction from `Set R` to `NonUnitalSubring R`, sending a subset of
`R` to the non-unital subring it generates, and prove that it is a Galois insertion.
## Main definitions
Notation used here:
`(R : Type u) [NonUnitalRing R] (S : Type u) [NonUnitalRing S] (f g : R ββ+* S)`
`(A : NonUnitalSubring R) (B : NonUnitalSubring S) (s : Set R)`
* `instance : CompleteLattice (NonUnitalSubring R)` : the complete lattice structure on the
non-unital subrings.
* `NonUnitalSubring.center` : the center of a non-unital ring `R`.
* `NonUnitalSubring.closure` : non-unital subring closure of a set, i.e., the smallest
non-unital subring that includes the set.
* `NonUnitalSubring.gi` : `closure : Set M β NonUnitalSubring M` and coercion
`coe : NonUnitalSubring M β Set M`
form a `GaloisInsertion`.
* `comap f B : NonUnitalSubring A` : the preimage of a non-unital subring `B` along the
non-unital ring homomorphism `f`
* `map f A : NonUnitalSubring B` : the image of a non-unital subring `A` along the
non-unital ring homomorphism `f`.
* `Prod A B : NonUnitalSubring (R Γ S)` : the product of non-unital subrings
* `f.range : NonUnitalSubring B` : the range of the non-unital ring homomorphism `f`.
* `eq_locus f g : NonUnitalSubring R` : given non-unital ring homomorphisms `f g : R ββ+* S`,
the non-unital subring of `R` where `f x = g x`
## Implementation notes
A non-unital subring is implemented as a `NonUnitalSubsemiring` which is also an
additive subgroup.
Lattice inclusion (e.g. `β€` and `β`) is used rather than set notation (`β` and `β©`), although
`β` is defined as membership of a non-unital subring's underlying set.
## Tags
non-unital subring
-/
universe u v w
section Basic
variable {R : Type u} {S : Type v} [NonUnitalNonAssocRing R]
namespace NonUnitalSubring
variable (s : NonUnitalSubring R)
/-- Sum of a list of elements in a non-unital subring is in the non-unital subring. -/
protected theorem list_sum_mem {l : List R} : (β x β l, x β s) β l.sum β s :=
list_sum_mem
/-- Sum of a multiset of elements in a `NonUnitalSubring` of a `NonUnitalRing` is
in the `NonUnitalSubring`. -/
protected theorem multiset_sum_mem {R} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
(m : Multiset R) : (β a β m, a β s) β m.sum β s :=
multiset_sum_mem _
/-- Sum of elements in a `NonUnitalSubring` of a `NonUnitalRing` indexed by a `Finset`
is in the `NonUnitalSubring`. -/
protected theorem sum_mem {R : Type*} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R)
{ΞΉ : Type*} {t : Finset ΞΉ} {f : ΞΉ β R} (h : β c β t, f c β s) : (β i β t, f i) β s :=
sum_mem h
/-! ## top -/
/-- The non-unital subring `R` of the ring `R`. -/
instance : Top (NonUnitalSubring R) :=
β¨{ (β€ : Subsemigroup R), (β€ : AddSubgroup R) with }β©
@[simp]
theorem mem_top (x : R) : x β (β€ : NonUnitalSubring R) :=
Set.mem_univ x
@[simp]
theorem coe_top : ((β€ : NonUnitalSubring R) : Set R) = Set.univ :=
rfl
/-- The ring equiv between the top element of `NonUnitalSubring R` and `R`. -/
@[simps!]
def topEquiv : (β€ : NonUnitalSubring R) β+* R := NonUnitalSubsemiring.topEquiv
end NonUnitalSubring
end Basic
section Hom
namespace NonUnitalSubring
variable {F : Type w} {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
[FunLike F R S] [NonUnitalRingHomClass F R S] (s : NonUnitalSubring R)
/-! ## comap -/
/-- The preimage of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def comap {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring S) :
NonUnitalSubring R :=
{ s.toSubsemigroup.comap (f : R ββ* S), s.toAddSubgroup.comap (f : R β+ S) with
carrier := f β»ΒΉ' s.carrier }
@[simp]
theorem coe_comap (s : NonUnitalSubring S) (f : F) : (s.comap f : Set R) = f β»ΒΉ' s :=
rfl
@[simp]
theorem mem_comap {s : NonUnitalSubring S} {f : F} {x : R} : x β s.comap f β f x β s :=
Iff.rfl
theorem comap_comap (s : NonUnitalSubring T) (g : S ββ+* T) (f : R ββ+* S) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-! ## map -/
/-- The image of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/
def map {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring R) :
NonUnitalSubring S :=
{ s.toSubsemigroup.map (f : R ββ* S), s.toAddSubgroup.map (f : R β+ S) with
carrier := f '' s.carrier }
@[simp]
theorem coe_map (f : F) (s : NonUnitalSubring R) : (s.map f : Set S) = f '' s :=
rfl
@[simp]
theorem mem_map {f : F} {s : NonUnitalSubring R} {y : S} : y β s.map f β β x β s, f x = y :=
Set.mem_image _ _ _
@[simp]
theorem map_id : s.map (NonUnitalRingHom.id R) = s :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (g : S ββ+* T) (f : R ββ+* S) : (s.map f).map g = s.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubring R} {t : NonUnitalSubring S} :
s.map f β€ t β s β€ t.comap f :=
Set.image_subset_iff
theorem gc_map_comap (f : F) :
GaloisConnection (map f : NonUnitalSubring R β NonUnitalSubring S) (comap f) := fun _S _T =>
map_le_iff_le_comap
/-- A `NonUnitalSubring` is isomorphic to its image under an injective function -/
noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R β S)) :
s β+* s.map f :=
{
Equiv.Set.image f s
hf with
map_mul' := fun _ _ => Subtype.ext (map_mul f _ _)
map_add' := fun _ _ => Subtype.ext (map_add f _ _) }
@[simp]
theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) :
(equivMapOfInjective s f hf x : S) = f x :=
rfl
end NonUnitalSubring
namespace NonUnitalRingHom
variable {R : Type u} {S : Type v} {T : Type*}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T]
(g : S ββ+* T) (f : R ββ+* S)
/-! ## range -/
/-- The range of a ring homomorphism, as a `NonUnitalSubring` of the target.
See Note [range copy pattern]. -/
def range {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
(f : R ββ+* S) : NonUnitalSubring S :=
((β€ : NonUnitalSubring R).map f).copy (Set.range f) Set.image_univ.symm
@[simp]
theorem coe_range : (f.range : Set S) = Set.range f :=
rfl
@[simp]
theorem mem_range {f : R ββ+* S} {y : S} : y β f.range β β x, f x = y :=
Iff.rfl
theorem range_eq_map (f : R ββ+* S) : f.range = NonUnitalSubring.map f β€ := by ext; simp
theorem mem_range_self (f : R ββ+* S) (x : R) : f x β f.range :=
mem_range.mpr β¨x, rflβ©
theorem map_range : f.range.map g = (g.comp f).range := by
simpa only [range_eq_map] using (β€ : NonUnitalSubring R).map_map g f
/-- The range of a ring homomorphism is a fintype, if the domain is a fintype.
Note: this instance can form a diamond with `Subtype.fintype` in the
presence of `Fintype S`. -/
instance fintypeRange [Fintype R] [DecidableEq S] (f : R ββ+* S) : Fintype (range f) :=
Set.fintypeRange f
end NonUnitalRingHom
namespace NonUnitalSubring
section Order
variable {R : Type u} [NonUnitalNonAssocRing R]
/-! ## bot -/
instance : Bot (NonUnitalSubring R) :=
β¨(0 : R ββ+* R).rangeβ©
instance : Inhabited (NonUnitalSubring R) :=
β¨β₯β©
theorem coe_bot : ((β₯ : NonUnitalSubring R) : Set R) = {0} :=
(NonUnitalRingHom.coe_range (0 : R ββ+* R)).trans (@Set.range_const R R _ 0)
theorem mem_bot {x : R} : x β (β₯ : NonUnitalSubring R) β x = 0 :=
show x β ((β₯ : NonUnitalSubring R) : Set R) β x = 0 by rw [coe_bot, Set.mem_singleton_iff]
/-! ## inf -/
/-- The inf of two `NonUnitalSubring`s is their intersection. -/
instance : Min (NonUnitalSubring R) :=
β¨fun s t =>
{ s.toSubsemigroup β t.toSubsemigroup, s.toAddSubgroup β t.toAddSubgroup with
carrier := s β© t }β©
@[simp]
theorem coe_inf (p p' : NonUnitalSubring R) :
((p β p' : NonUnitalSubring R) : Set R) = (p : Set R) β© p' :=
rfl
@[simp]
theorem mem_inf {p p' : NonUnitalSubring R} {x : R} : x β p β p' β x β p β§ x β p' :=
Iff.rfl
instance : InfSet (NonUnitalSubring R) :=
β¨fun s =>
NonUnitalSubring.mk' (β t β s, βt) (β¨
t β s, NonUnitalSubring.toSubsemigroup t)
(β¨
t β s, NonUnitalSubring.toAddSubgroup t) (by simp) (by simp)β©
@[simp, norm_cast]
theorem coe_sInf (S : Set (NonUnitalSubring R)) :
((sInf S : NonUnitalSubring R) : Set R) = β s β S, βs :=
rfl
theorem mem_sInf {S : Set (NonUnitalSubring R)} {x : R} : x β sInf S β β p β S, x β p :=
Set.mem_iInterβ
@[simp, norm_cast]
theorem coe_iInf {ΞΉ : Sort*} {S : ΞΉ β NonUnitalSubring R} : (β(β¨
i, S i) : Set R) = β i, S i := by
simp only [iInf, coe_sInf, Set.biInter_range]
theorem mem_iInf {ΞΉ : Sort*} {S : ΞΉ β NonUnitalSubring R} {x : R} :
(x β β¨
i, S i) β β i, x β S i := by simp only [iInf, mem_sInf, Set.forall_mem_range]
@[simp]
theorem sInf_toSubsemigroup (s : Set (NonUnitalSubring R)) :
(sInf s).toSubsemigroup = β¨
t β s, NonUnitalSubring.toSubsemigroup t :=
mk'_toSubsemigroup _ _
@[simp]
theorem sInf_toAddSubgroup (s : Set (NonUnitalSubring R)) :
(sInf s).toAddSubgroup = β¨
t β s, NonUnitalSubring.toAddSubgroup t :=
mk'_toAddSubgroup _ _
/-- `NonUnitalSubring`s of a ring form a complete lattice. -/
instance : CompleteLattice (NonUnitalSubring R) :=
{ completeLatticeOfInf (NonUnitalSubring R) fun _s =>
IsGLB.of_image (@fun _ _ : NonUnitalSubring R => SetLike.coe_subset_coe)
isGLB_biInf with
bot := β₯
bot_le := fun s _x hx => (mem_bot.mp hx).symm βΈ zero_mem s
top := β€
le_top := fun _ _ _ => trivial
inf := (Β· β Β·)
inf_le_left := fun _ _ _ => And.left
inf_le_right := fun _ _ _ => And.right
le_inf := fun _s _tβ _tβ hβ hβ _x hx => β¨hβ hx, hβ hxβ© }
theorem eq_top_iff' (A : NonUnitalSubring R) : A = β€ β β x : R, x β A :=
eq_top_iff.trans β¨fun h m => h <| mem_top m, fun h m _ => h mβ©
end Order
/-! ## Center of a ring -/
section Center
variable {R : Type u}
section NonUnitalNonAssocRing
variable (R) [NonUnitalNonAssocRing R]
/-- The center of a ring `R` is the set of elements that commute with everything in `R` -/
def center : NonUnitalSubring R :=
{ NonUnitalSubsemiring.center R with
neg_mem' := Set.neg_mem_center }
theorem coe_center : β(center R) = Set.center R :=
rfl
@[simp]
theorem center_toNonUnitalSubsemiring :
(center R).toNonUnitalSubsemiring = NonUnitalSubsemiring.center R :=
rfl
/-- The center is commutative and associative. -/
instance center.instNonUnitalCommRing : NonUnitalCommRing (center R) :=
{ NonUnitalSubsemiring.center.instNonUnitalCommSemiring R,
inferInstanceAs <| NonUnitalNonAssocRing (center R) with }
variable {R}
/-- The center of isomorphic (not necessarily unital or associative) rings are isomorphic. -/
@[simps!] def centerCongr {S} [NonUnitalNonAssocRing S] (e : R β+* S) : center R β+* center S :=
NonUnitalSubsemiring.centerCongr e
/-- The center of a (not necessarily uintal or associative) ring
is isomorphic to the center of its opposite. -/
@[simps!] def centerToMulOpposite : center R β+* center Rα΅α΅α΅ :=
NonUnitalSubsemiring.centerToMulOpposite
end NonUnitalNonAssocRing
section NonUnitalRing
variable [NonUnitalRing R]
-- no instance diamond, unlike the unital version
example : (center.instNonUnitalCommRing _).toNonUnitalRing =
NonUnitalSubringClass.toNonUnitalRing (center R) := by
with_reducible_and_instances rfl
theorem mem_center_iff {z : R} : z β center R β β g, g * z = z * g := Subsemigroup.mem_center_iff
instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (Β· β center R) := fun _ =>
decidable_of_iff' _ mem_center_iff
@[simp]
theorem center_eq_top (R) [NonUnitalCommRing R] : center R = β€ :=
SetLike.coe_injective (Set.center_eq_univ R)
end NonUnitalRing
end Center
/-! ## `NonUnitalSubring` closure of a subset -/
variable {F : Type w} {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S]
/-- The `NonUnitalSubring` generated by a set. -/
def closure (s : Set R) : NonUnitalSubring R :=
sInf {S | s β S}
theorem mem_closure {x : R} {s : Set R} : x β closure s β β S : NonUnitalSubring R, s β S β x β S :=
mem_sInf
/-- The `NonUnitalSubring` generated by a set includes the set. -/
@[simp, aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_closure {s : Set R} : s β closure s := fun _x hx => mem_closure.2 fun _S hS => hS hx
theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P β closure s) : P β s := fun h =>
hP (subset_closure h)
/-- A `NonUnitalSubring` `t` includes `closure s` if and only if it includes `s`. -/
@[simp]
theorem closure_le {s : Set R} {t : NonUnitalSubring R} : closure s β€ t β s β t :=
β¨Set.Subset.trans subset_closure, fun h => sInf_le hβ©
/-- `NonUnitalSubring` closure of a set is monotone in its argument: if `s β t`,
then `closure s β€ closure t`. -/
@[gcongr]
theorem closure_mono β¦s t : Set Rβ¦ (h : s β t) : closure s β€ closure t :=
closure_le.2 <| Set.Subset.trans h subset_closure
theorem closure_eq_of_le {s : Set R} {t : NonUnitalSubring R} (hβ : s β t) (hβ : t β€ closure s) :
closure s = t :=
le_antisymm (closure_le.2 hβ) hβ
/-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements
of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all
elements of the closure of `s`. -/
@[elab_as_elim]
theorem closure_induction {s : Set R} {p : (x : R) β x β closure s β Prop}
(mem : β (x) (hx : x β s), p x (subset_closure hx)) (zero : p 0 (zero_mem _))
(add : β x y hx hy, p x hx β p y hy β p (x + y) (add_mem hx hy))
(neg : β x hx, p x hx β p (-x) (neg_mem hx))
(mul : β x y hx hy, p x hx β p y hy β p (x * y) (mul_mem hx hy))
{x} (hx : x β closure s) : p x hx :=
let K : NonUnitalSubring R :=
{ carrier := { x | β hx, p x hx }
mul_mem' := fun β¨_, hpxβ© β¨_, hpyβ© β¦ β¨_, mul _ _ _ _ hpx hpyβ©
add_mem' := fun β¨_, hpxβ© β¨_, hpyβ© β¦ β¨_, add _ _ _ _ hpx hpyβ©
neg_mem' := fun β¨_, hpxβ© β¦ β¨_, neg _ _ hpxβ©
zero_mem' := β¨_, zeroβ© }
closure_le (t := K) |>.mpr (fun y hy β¦ β¨subset_closure hy, mem y hyβ©) hx |>.elim fun _ β¦ id
/-- An induction principle for closure membership, for predicates with two arguments. -/
@[elab_as_elim]
theorem closure_inductionβ {s : Set R} {p : (x y : R) β x β closure s β y β closure s β Prop}
(mem_mem : β (x) (y) (hx : x β s) (hy : y β s), p x y (subset_closure hx) (subset_closure hy))
(zero_left : β x hx, p 0 x (zero_mem _) hx) (zero_right : β x hx, p x 0 hx (zero_mem _))
(neg_left : β x y hx hy, p x y hx hy β p (-x) y (neg_mem hx) hy)
(neg_right : β x y hx hy, p x y hx hy β p x (-y) hx (neg_mem hy))
(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 : R} (hx : x β closure s) (hy : y β closure s) :
p x y hx hy := by
induction hy using closure_induction with
| mem z hz => induction hx using closure_induction with
| mem _ h => exact mem_mem _ _ h hz
| zero => exact zero_left _ _
| mul _ _ _ _ hβ hβ => exact mul_left _ _ _ _ _ _ hβ hβ
| add _ _ _ _ hβ hβ => exact add_left _ _ _ _ _ _ hβ hβ
| neg _ _ h => exact neg_left _ _ _ _ h
| zero => exact zero_right x hx
| mul _ _ _ _ hβ hβ => exact mul_right _ _ _ _ _ _ hβ hβ
| add _ _ _ _ hβ hβ => exact add_right _ _ _ _ _ _ hβ hβ
| neg _ _ h => exact neg_right _ _ _ _ h
theorem mem_closure_iff {s : Set R} {x} :
x β closure s β x β AddSubgroup.closure (Subsemigroup.closure s : Set R) :=
β¨fun h => by
induction h using closure_induction with
| mem _ hx => exact AddSubgroup.subset_closure (Subsemigroup.subset_closure hx)
| zero => exact zero_mem _
| add _ _ _ _ hx hy => exact add_mem hx hy
| neg x _ hx => exact neg_mem hx
| mul _ _ _hx _hy hx hy =>
clear _hx _hy
induction hx, hy using AddSubgroup.closure_inductionβ with
| mem _ _ hx hy => exact AddSubgroup.subset_closure (mul_mem hx hy)
| one_left => simpa using zero_mem _
| one_right => simpa using zero_mem _
| mul_left _ _ _ _ _ _ hβ hβ => simpa [add_mul] using add_mem hβ hβ
| mul_right _ _ _ _ _ _ hβ hβ => simpa [mul_add] using add_mem hβ hβ
| inv_left _ _ _ _ h => simpa [neg_mul] using neg_mem h
| inv_right _ _ _ _ h => simpa [mul_neg] using neg_mem h,
fun h => by
induction h using AddSubgroup.closure_induction with
| mem _ hx => induction hx using Subsemigroup.closure_induction with
| mem _ h => exact subset_closure h
| mul _ _ _ _ hβ hβ => exact mul_mem hβ hβ
| one => exact zero_mem _
| mul _ _ _ _ hβ hβ => exact add_mem hβ hβ
| inv _ _ h => exact neg_mem hβ©
/-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/
def closureNonUnitalCommRingOfComm {R : Type u} [NonUnitalRing R] {s : Set R}
(hcomm : β a β s, β b β s, a * b = b * a) : NonUnitalCommRing (closure s) :=
{ (closure s).toNonUnitalRing with
mul_comm := fun β¨x, hxβ© β¨y, hyβ© => by
ext
simp only [MulMemClass.mk_mul_mk]
induction hx, hy using closure_inductionβ with
| mem_mem x y hx hy => exact hcomm x hx y hy
| zero_left x _ => exact Commute.zero_left x
| zero_right x _ => exact Commute.zero_right x
| mul_left _ _ _ _ _ _ hβ hβ => exact Commute.mul_left hβ hβ
| mul_right _ _ _ _ _ _ hβ hβ => exact Commute.mul_right hβ hβ
| add_left _ _ _ _ _ _ hβ hβ => exact Commute.add_left hβ hβ
| add_right _ _ _ _ _ _ hβ hβ => exact Commute.add_right hβ hβ
| neg_left _ _ _ _ h => exact Commute.neg_left h
| neg_right _ _ _ _ h => exact Commute.neg_right h }
variable (R) in
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : GaloisInsertion (@closure R _) SetLike.coe where
choice s _ := closure s
gc _s _t := closure_le
le_l_u _s := subset_closure
choice_eq _s _h := rfl
/-- Closure of a `NonUnitalSubring` `S` equals `S`. -/
@[simp]
theorem closure_eq (s : NonUnitalSubring R) : closure (s : Set R) = s :=
(NonUnitalSubring.gi R).l_u_eq s
@[simp]
theorem closure_empty : closure (β
: Set R) = β₯ :=
(NonUnitalSubring.gi R).gc.l_bot
@[simp]
theorem closure_univ : closure (Set.univ : Set R) = β€ :=
@coe_top R _ βΈ closure_eq β€
theorem closure_union (s t : Set R) : closure (s βͺ t) = closure s β closure t :=
(NonUnitalSubring.gi R).gc.l_sup
theorem closure_iUnion {ΞΉ} (s : ΞΉ β Set R) : closure (β i, s i) = β¨ i, closure (s i) :=
(NonUnitalSubring.gi R).gc.l_iSup
theorem closure_sUnion (s : Set (Set R)) : closure (ββ s) = β¨ t β s, closure t :=
(NonUnitalSubring.gi R).gc.l_sSup
theorem map_sup (s t : NonUnitalSubring R) (f : F) : (s β t).map f = s.map f β t.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ΞΉ : Sort*} (f : F) (s : ΞΉ β NonUnitalSubring R) :
(iSup s).map f = β¨ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem map_inf (s t : NonUnitalSubring R) (f : F) (hf : Function.Injective f) :
(s β t).map f = s.map f β t.map f := SetLike.coe_injective (Set.image_inter hf)
theorem map_iInf {ΞΉ : Sort*} [Nonempty ΞΉ] (f : F) (hf : Function.Injective f)
(s : ΞΉ β NonUnitalSubring R) : (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)
theorem comap_inf (s t : NonUnitalSubring S) (f : F) : (s β t).comap f = s.comap f β t.comap f :=
(gc_map_comap f).u_inf
theorem comap_iInf {ΞΉ : Sort*} (f : F) (s : ΞΉ β NonUnitalSubring S) :
(iInf s).comap f = β¨
i, (s i).comap f :=
(gc_map_comap f).u_iInf
@[simp]
theorem map_bot (f : R ββ+* S) : (β₯ : NonUnitalSubring R).map f = β₯ :=
(gc_map_comap f).l_bot
@[simp]
theorem comap_top (f : R ββ+* S) : (β€ : NonUnitalSubring S).comap f = β€ :=
(gc_map_comap f).u_top
/-- Given `NonUnitalSubring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s ΓΛ’ t`
as a `NonUnitalSubring` of `R Γ S`. -/
def prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) : NonUnitalSubring (R Γ S) :=
{ s.toSubsemigroup.prod t.toSubsemigroup, s.toAddSubgroup.prod t.toAddSubgroup with
carrier := s ΓΛ’ t }
@[norm_cast]
theorem coe_prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) :
(s.prod t : Set (R Γ S)) = (s : Set R) ΓΛ’ t :=
rfl
theorem mem_prod {s : NonUnitalSubring R} {t : NonUnitalSubring S} {p : R Γ S} :
p β s.prod t β p.1 β s β§ p.2 β t :=
Iff.rfl
@[mono]
theorem prod_mono β¦sβ sβ : NonUnitalSubring Rβ¦ (hs : sβ β€ sβ) β¦tβ tβ : NonUnitalSubring Sβ¦
(ht : tβ β€ tβ) : sβ.prod tβ β€ sβ.prod tβ :=
Set.prod_mono hs ht
theorem prod_mono_right (s : NonUnitalSubring R) :
Monotone fun t : NonUnitalSubring S => s.prod t :=
prod_mono (le_refl s)
theorem prod_mono_left (t : NonUnitalSubring S) : Monotone fun s : NonUnitalSubring R => s.prod t :=
fun _sβ _sβ hs => prod_mono hs (le_refl t)
theorem prod_top (s : NonUnitalSubring R) :
s.prod (β€ : NonUnitalSubring S) = s.comap (NonUnitalRingHom.fst R S) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_fst]
theorem top_prod (s : NonUnitalSubring S) :
(β€ : NonUnitalSubring R).prod s = s.comap (NonUnitalRingHom.snd R S) :=
ext fun x => by simp [mem_prod, MonoidHom.coe_snd]
@[simp]
theorem top_prod_top : (β€ : NonUnitalSubring R).prod (β€ : NonUnitalSubring S) = β€ :=
(top_prod _).trans <| comap_top _
/-- Product of `NonUnitalSubring`s is isomorphic to their product as rings. -/
def prodEquiv (s : NonUnitalSubring R) (t : NonUnitalSubring S) : s.prod t β+* s Γ t :=
{ Equiv.Set.prod (s : Set R) (t : Set S) with
map_mul' := fun _ _ => rfl
map_add' := fun _ _ => rfl }
/-- The underlying set of a non-empty directed Sup of `NonUnitalSubring`s is just a union of the
`NonUnitalSubring`s. Note that this fails without the directedness assumption (the union of two
`NonUnitalSubring`s is typically not a `NonUnitalSubring`) -/
theorem mem_iSup_of_directed {ΞΉ} [hΞΉ : Nonempty ΞΉ] {S : ΞΉ β NonUnitalSubring R}
(hS : Directed (Β· β€ Β·) S) {x : R} : (x β β¨ i, S i) β β i, x β S i := by
refine β¨?_, fun β¨i, hiβ© β¦ le_iSup S i hiβ©
let U : NonUnitalSubring R :=
NonUnitalSubring.mk' (β i, (S i : Set R)) (β¨ i, (S i).toSubsemigroup) (β¨ i, (S i).toAddSubgroup)
(Subsemigroup.coe_iSup_of_directed hS) (AddSubgroup.coe_iSup_of_directed hS)
suffices β¨ i, S i β€ U by simpa [U] using @this x
exact iSup_le fun i x hx β¦ Set.mem_iUnion.2 β¨i, hxβ©
theorem coe_iSup_of_directed {ΞΉ} [Nonempty ΞΉ] {S : ΞΉ β NonUnitalSubring R}
(hS : Directed (Β· β€ Β·) S) : ((β¨ i, S i : NonUnitalSubring R) : Set R) = β i, S i :=
Set.ext fun x β¦ by simp [mem_iSup_of_directed hS]
theorem mem_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty)
(hS : DirectedOn (Β· β€ Β·) S) {x : R} : x β sSup S β β s β S, x β s := by
haveI : Nonempty S := Sne.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk,
exists_prop]
theorem coe_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty)
(hS : DirectedOn (Β· β€ Β·) S) : (β(sSup S) : Set R) = β s β S, βs :=
Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS]
theorem mem_map_equiv {f : R β+* S} {K : NonUnitalSubring R} {x : S} :
x β K.map (f : R ββ+* S) β f.symm x β K :=
@Set.mem_image_equiv _ _ (K : Set R) f.toEquiv x
theorem map_equiv_eq_comap_symm (f : R β+* S) (K : NonUnitalSubring R) :
K.map (f : R ββ+* S) = K.comap f.symm :=
SetLike.coe_injective (f.toEquiv.image_eq_preimage K)
theorem comap_equiv_eq_map_symm (f : R β+* S) (K : NonUnitalSubring S) :
K.comap (f : R ββ+* S) = K.map f.symm :=
(map_equiv_eq_comap_symm f.symm K).symm
end NonUnitalSubring
namespace NonUnitalRingHom
variable {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
open NonUnitalSubring
/-- Restriction of a ring homomorphism to its range interpreted as a `NonUnitalSubring`.
This is the bundled version of `Set.rangeFactorization`. -/
def rangeRestrict (f : R ββ+* S) : R ββ+* f.range :=
NonUnitalRingHom.codRestrict f f.range fun x => β¨x, rflβ©
@[simp]
theorem coe_rangeRestrict (f : R ββ+* S) (x : R) : (f.rangeRestrict x : S) = f x :=
rfl
theorem rangeRestrict_surjective (f : R ββ+* S) : Function.Surjective f.rangeRestrict :=
fun β¨_y, hyβ© =>
let β¨x, hxβ© := mem_range.mp hy
β¨x, Subtype.ext hxβ©
theorem range_eq_top {f : R ββ+* S} :
f.range = (β€ : NonUnitalSubring S) β Function.Surjective f :=
SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_eq_univ
@[deprecated (since := "2024-11-11")] alias range_top_iff_surjective := range_eq_top
/-- The range of a surjective ring homomorphism is the whole of the codomain. -/
@[simp]
theorem range_eq_top_of_surjective (f : R ββ+* S) (hf : Function.Surjective f) :
f.range = (β€ : NonUnitalSubring S) :=
range_eq_top.2 hf
@[deprecated (since := "2024-11-11")] alias range_top_of_surjective := range_eq_top_of_surjective
/-- The `NonUnitalSubring` of elements `x : R` such that `f x = g x`, i.e.,
the equalizer of f and g as a `NonUnitalSubring` of R -/
def eqLocus (f g : R ββ+* S) : NonUnitalSubring R :=
{ (f : R ββ* S).eqLocus g, (f : R β+ S).eqLocus g with carrier := {x | f x = g x} }
@[simp]
theorem eqLocus_same (f : R ββ+* S) : f.eqLocus f = β€ :=
SetLike.ext fun _ => eq_self_iff_true _
/-- If two ring homomorphisms are equal on a set, then they are equal on its
`NonUnitalSubring` closure. -/
theorem eqOn_set_closure {f g : R ββ+* S} {s : Set R} (h : Set.EqOn f g s) :
Set.EqOn f g (closure s) :=
show closure s β€ f.eqLocus g from closure_le.2 h
theorem eq_of_eqOn_set_top {f g : R ββ+* S} (h : Set.EqOn f g (β€ : NonUnitalSubring R)) : f = g :=
ext fun _x => h trivial
theorem eq_of_eqOn_set_dense {s : Set R} (hs : closure s = β€) {f g : R ββ+* S} (h : s.EqOn f g) :
f = g :=
eq_of_eqOn_set_top <| hs βΈ eqOn_set_closure h
theorem closure_preimage_le (f : R ββ+* S) (s : Set S) : closure (f β»ΒΉ' s) β€ (closure s).comap f :=
closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
/-- The image under a ring homomorphism of the `NonUnitalSubring` generated by a set equals
the `NonUnitalSubring` generated by the image of the set. -/
theorem map_closure (f : R ββ+* S) (s : Set R) : (closure s).map f = closure (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (NonUnitalSubring.gi S).gc
(NonUnitalSubring.gi R).gc fun _ β¦ rfl
end NonUnitalRingHom
namespace NonUnitalSubring
variable {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
open NonUnitalRingHom
@[simp]
theorem range_subtype (s : NonUnitalSubring R) : (NonUnitalSubringClass.subtype s).range = s :=
SetLike.coe_injective <| (coe_srange _).trans Subtype.range_coe
theorem range_fst : NonUnitalRingHom.srange (fst R S) = β€ :=
NonUnitalSubsemiring.range_fst
theorem range_snd : NonUnitalRingHom.srange (snd R S) = β€ :=
NonUnitalSubsemiring.range_snd
end NonUnitalSubring
namespace RingEquiv
variable {R : Type u} {S : Type v} [NonUnitalRing R] [NonUnitalRing S] {s t : NonUnitalSubring R}
/-- Makes the identity isomorphism from a proof two `NonUnitalSubring`s of a multiplicative
monoid are equal. -/
def nonUnitalSubringCongr (h : s = t) : s β+* t :=
{
Equiv.setCongr <| congr_arg _ h with
map_mul' := fun _ _ => rfl
map_add' := fun _ _ => rfl }
/-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its
`RingHom.range`. -/
def ofLeftInverse' {g : S β R} {f : R ββ+* S} (h : Function.LeftInverse g f) : R β+* f.range :=
{ f.rangeRestrict with
toFun := fun x => f.rangeRestrict x
invFun := fun x => (g β NonUnitalSubringClass.subtype f.range) x
left_inv := h
right_inv := fun x =>
Subtype.ext <|
let β¨x', hx'β© := NonUnitalRingHom.mem_range.mp x.prop
show f (g x) = x by rw [β hx', h x'] }
@[simp]
theorem ofLeftInverse'_apply {g : S β R} {f : R ββ+* S} (h : Function.LeftInverse g f) (x : R) :
β(ofLeftInverse' h x) = f x :=
rfl
@[simp]
theorem ofLeftInverse'_symm_apply {g : S β R} {f : R ββ+* S} (h : Function.LeftInverse g f)
(x : f.range) : (ofLeftInverse' h).symm x = g x :=
rfl
end RingEquiv
namespace NonUnitalSubring
variable {F : Type w} {R : Type u} {S : Type v}
[NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
[FunLike F R S] [NonUnitalRingHomClass F R S]
theorem closure_preimage_le (f : F) (s : Set S) :
closure ((f : R β S) β»ΒΉ' s) β€ (closure s).comap f :=
closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx
end NonUnitalSubring
end Hom
| Mathlib/RingTheory/NonUnitalSubring/Basic.lean | 866 | 873 | |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import Mathlib.Analysis.InnerProductSpace.Subspace
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
/-!
# Angles between vectors
This file defines unoriented angles in real inner product spaces.
## Main definitions
* `InnerProductGeometry.angle` is the undirected angle between two vectors.
## TODO
Prove the triangle inequality for the angle.
-/
assert_not_exists HasFDerivAt ConformalAt
noncomputable section
open Real Set
open Real
open RealInnerProductSpace
namespace InnerProductGeometry
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace β V] {x y : V}
/-- The undirected angle between two vectors. If either vector is 0,
this is Ο/2. See `Orientation.oangle` for the corresponding oriented angle
definition. -/
def angle (x y : V) : β :=
Real.arccos (βͺx, yβ« / (βxβ * βyβ))
theorem continuousAt_angle {x : V Γ V} (hx1 : x.1 β 0) (hx2 : x.2 β 0) :
ContinuousAt (fun y : V Γ V => angle y.1 y.2) x := by
unfold angle
fun_prop (disch := simp [*])
theorem angle_smul_smul {c : β} (hc : c β 0) (x y : V) : angle (c β’ x) (c β’ y) = angle x y := by
have : c * c β 0 := mul_ne_zero hc hc
rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs,
mul_mul_mul_comm _ βxβ, abs_mul_abs_self, β mul_assoc c c, mul_div_mul_left _ _ this]
@[simp]
theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F]
[InnerProductSpace β E] [InnerProductSpace β F] (f : E ββα΅’[β] F) (u v : E) :
angle (f u) (f v) = angle u v := by
rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map]
@[simp, norm_cast]
theorem _root_.Submodule.angle_coe {s : Submodule β V} (x y : s) :
angle (x : V) (y : V) = angle x y :=
s.subtypeβα΅’.angle_map x y
/-- The cosine of the angle between two vectors. -/
theorem cos_angle (x y : V) : Real.cos (angle x y) = βͺx, yβ« / (βxβ * βyβ) :=
Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1
(abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2
/-- The angle between two vectors does not depend on their order. -/
theorem angle_comm (x y : V) : angle x y = angle y x := by
unfold angle
rw [real_inner_comm, mul_comm]
/-- The angle between the negation of two vectors. -/
@[simp]
theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by
unfold angle
rw [inner_neg_neg, norm_neg, norm_neg]
/-- The angle between two vectors is nonnegative. -/
theorem angle_nonneg (x y : V) : 0 β€ angle x y :=
Real.arccos_nonneg _
/-- The angle between two vectors is at most Ο. -/
theorem angle_le_pi (x y : V) : angle x y β€ Ο :=
Real.arccos_le_pi _
/-- The sine of the angle between two vectors is nonnegative. -/
theorem sin_angle_nonneg (x y : V) : 0 β€ sin (angle x y) :=
sin_nonneg_of_nonneg_of_le_pi (angle_nonneg x y) (angle_le_pi x y)
/-- The angle between a vector and the negation of another vector. -/
theorem angle_neg_right (x y : V) : angle x (-y) = Ο - angle x y := by
unfold angle
rw [β Real.arccos_neg, norm_neg, inner_neg_right, neg_div]
/-- The angle between the negation of a vector and another vector. -/
theorem angle_neg_left (x y : V) : angle (-x) y = Ο - angle x y := by
rw [β angle_neg_neg, neg_neg, angle_neg_right]
proof_wanted angle_triangle (x y z : V) : angle x z β€ angle x y + angle y z
/-- The angle between the zero vector and a vector. -/
@[simp]
theorem angle_zero_left (x : V) : angle 0 x = Ο / 2 := by
unfold angle
rw [inner_zero_left, zero_div, Real.arccos_zero]
/-- The angle between a vector and the zero vector. -/
@[simp]
theorem angle_zero_right (x : V) : angle x 0 = Ο / 2 := by
unfold angle
rw [inner_zero_right, zero_div, Real.arccos_zero]
/-- The angle between a nonzero vector and itself. -/
@[simp]
theorem angle_self {x : V} (hx : x β 0) : angle x x = 0 := by
unfold angle
rw [β real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : βͺx, xβ« β 0),
Real.arccos_one]
/-- The angle between a nonzero vector and its negation. -/
@[simp]
theorem angle_self_neg_of_nonzero {x : V} (hx : x β 0) : angle x (-x) = Ο := by
rw [angle_neg_right, angle_self hx, sub_zero]
/-- The angle between the negation of a nonzero vector and that
vector. -/
@[simp]
theorem angle_neg_self_of_nonzero {x : V} (hx : x β 0) : angle (-x) x = Ο := by
rw [angle_comm, angle_self_neg_of_nonzero hx]
/-- The angle between a vector and a positive multiple of a vector. -/
@[simp]
theorem angle_smul_right_of_pos (x y : V) {r : β} (hr : 0 < r) : angle x (r β’ y) = angle x y := by
unfold angle
rw [inner_smul_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), β mul_assoc,
mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)]
/-- The angle between a positive multiple of a vector and a vector. -/
| @[simp]
theorem angle_smul_left_of_pos (x y : V) {r : β} (hr : 0 < r) : angle (r β’ x) y = angle x y := by
| Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean | 142 | 143 |
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro, Yury Kudryashov
-/
import Mathlib.Topology.Order.IsLUB
/-!
# Order topology on a densely ordered set
-/
open Set Filter TopologicalSpace Topology Function
open OrderDual (toDual ofDual)
variable {Ξ± Ξ² : Type*}
section DenselyOrdered
variable [TopologicalSpace Ξ±] [LinearOrder Ξ±] [OrderTopology Ξ±] [DenselyOrdered Ξ±] {a b : Ξ±}
{s : Set Ξ±}
/-- The closure of the interval `(a, +β)` is the closed interval `[a, +β)`, unless `a` is a top
element. -/
theorem closure_Ioi' {a : Ξ±} (h : (Ioi a).Nonempty) : closure (Ioi a) = Ici a := by
apply Subset.antisymm
Β· exact closure_minimal Ioi_subset_Ici_self isClosed_Ici
Β· rw [β diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff]
exact isGLB_Ioi.mem_closure h
/-- The closure of the interval `(a, +β)` is the closed interval `[a, +β)`. -/
@[simp]
theorem closure_Ioi (a : Ξ±) [NoMaxOrder Ξ±] : closure (Ioi a) = Ici a :=
closure_Ioi' nonempty_Ioi
/-- The closure of the interval `(-β, a)` is the closed interval `(-β, a]`, unless `a` is a bottom
element. -/
theorem closure_Iio' (h : (Iio a).Nonempty) : closure (Iio a) = Iic a :=
closure_Ioi' (Ξ± := Ξ±α΅α΅) h
/-- The closure of the interval `(-β, a)` is the interval `(-β, a]`. -/
@[simp]
theorem closure_Iio (a : Ξ±) [NoMinOrder Ξ±] : closure (Iio a) = Iic a :=
closure_Iio' nonempty_Iio
/-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ioo {a b : Ξ±} (hab : a β b) : closure (Ioo a b) = Icc a b := by
apply Subset.antisymm
Β· exact closure_minimal Ioo_subset_Icc_self isClosed_Icc
Β· rcases hab.lt_or_lt with hab | hab
| Β· rw [β diff_subset_closure_iff, Icc_diff_Ioo_same hab.le]
have hab' : (Ioo a b).Nonempty := nonempty_Ioo.2 hab
simp only [insert_subset_iff, singleton_subset_iff]
exact β¨(isGLB_Ioo hab).mem_closure hab', (isLUB_Ioo hab).mem_closure hab'β©
Β· rw [Icc_eq_empty_of_lt hab]
exact empty_subset _
/-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/
@[simp]
theorem closure_Ioc {a b : Ξ±} (hab : a β b) : closure (Ioc a b) = Icc a b := by
| Mathlib/Topology/Order/DenselyOrdered.lean | 52 | 61 |
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yury Kudryashov, SΓ©bastien GouΓ«zel, Chris Hughes
-/
import Mathlib.Data.Fin.Rev
import Mathlib.Data.Nat.Find
/-!
# Operation on tuples
We interpret maps `β i : Fin n, Ξ± i` as `n`-tuples of elements of possibly varying type `Ξ± i`,
`(Ξ± 0, β¦, Ξ± (n-1))`. A particular case is `Fin n β Ξ±` of elements with all the same type.
In this case when `Ξ± i` is a constant map, then tuples are isomorphic (but not definitionally equal)
to `Vector`s.
## Main declarations
There are three (main) ways to consider `Fin n` as a subtype of `Fin (n + 1)`, hence three (main)
ways to move between tuples of length `n` and of length `n + 1` by adding/removing an entry.
### Adding at the start
* `Fin.succ`: Send `i : Fin n` to `i + 1 : Fin (n + 1)`. This is defined in Core.
* `Fin.cases`: Induction/recursion principle for `Fin`: To prove a property/define a function for
all `Fin (n + 1)`, it is enough to prove/define it for `0` and for `i.succ` for all `i : Fin n`.
This is defined in Core.
* `Fin.cons`: Turn a tuple `f : Fin n β Ξ±` and an entry `a : Ξ±` into a tuple
`Fin.cons a f : Fin (n + 1) β Ξ±` by adding `a` at the start. In general, tuples can be dependent
functions, in which case `f : β i : Fin n, Ξ± i.succ` and `a : Ξ± 0`. This is a special case of
`Fin.cases`.
* `Fin.tail`: Turn a tuple `f : Fin (n + 1) β Ξ±` into a tuple `Fin.tail f : Fin n β Ξ±` by forgetting
the start. In general, tuples can be dependent functions,
in which case `Fin.tail f : β i : Fin n, Ξ± i.succ`.
### Adding at the end
* `Fin.castSucc`: Send `i : Fin n` to `i : Fin (n + 1)`. This is defined in Core.
* `Fin.lastCases`: Induction/recursion principle for `Fin`: To prove a property/define a function
for all `Fin (n + 1)`, it is enough to prove/define it for `last n` and for `i.castSucc` for all
`i : Fin n`. This is defined in Core.
* `Fin.snoc`: Turn a tuple `f : Fin n β Ξ±` and an entry `a : Ξ±` into a tuple
`Fin.snoc f a : Fin (n + 1) β Ξ±` by adding `a` at the end. In general, tuples can be dependent
functions, in which case `f : β i : Fin n, Ξ± i.castSucc` and `a : Ξ± (last n)`. This is a
special case of `Fin.lastCases`.
* `Fin.init`: Turn a tuple `f : Fin (n + 1) β Ξ±` into a tuple `Fin.init f : Fin n β Ξ±` by forgetting
the start. In general, tuples can be dependent functions,
in which case `Fin.init f : β i : Fin n, Ξ± i.castSucc`.
### Adding in the middle
For a **pivot** `p : Fin (n + 1)`,
* `Fin.succAbove`: Send `i : Fin n` to
* `i : Fin (n + 1)` if `i < p`,
* `i + 1 : Fin (n + 1)` if `p β€ i`.
* `Fin.succAboveCases`: Induction/recursion principle for `Fin`: To prove a property/define a
function for all `Fin (n + 1)`, it is enough to prove/define it for `p` and for `p.succAbove i`
for all `i : Fin n`.
* `Fin.insertNth`: Turn a tuple `f : Fin n β Ξ±` and an entry `a : Ξ±` into a tuple
`Fin.insertNth f a : Fin (n + 1) β Ξ±` by adding `a` in position `p`. In general, tuples can be
dependent functions, in which case `f : β i : Fin n, Ξ± (p.succAbove i)` and `a : Ξ± p`. This is a
special case of `Fin.succAboveCases`.
* `Fin.removeNth`: Turn a tuple `f : Fin (n + 1) β Ξ±` into a tuple `Fin.removeNth p f : Fin n β Ξ±`
by forgetting the `p`-th value. In general, tuples can be dependent functions,
in which case `Fin.removeNth f : β i : Fin n, Ξ± (succAbove p i)`.
`p = 0` means we add at the start. `p = last n` means we add at the end.
### Miscellaneous
* `Fin.find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never
satisfied.
* `Fin.append a b` : append two tuples.
* `Fin.repeat n a` : repeat a tuple `n` times.
-/
assert_not_exists Monoid
universe u v
namespace Fin
variable {m n : β}
open Function
section Tuple
/-- There is exactly one tuple of size zero. -/
example (Ξ± : Fin 0 β Sort u) : Unique (β i : Fin 0, Ξ± i) := by infer_instance
theorem tuple0_le {Ξ± : Fin 0 β Type*} [β i, Preorder (Ξ± i)] (f g : β i, Ξ± i) : f β€ g :=
finZeroElim
variable {Ξ± : Fin (n + 1) β Sort u} (x : Ξ± 0) (q : β i, Ξ± i) (p : β i : Fin n, Ξ± i.succ) (i : Fin n)
(y : Ξ± i.succ) (z : Ξ± 0)
/-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/
def tail (q : β i, Ξ± i) : β i : Fin n, Ξ± i.succ := fun i β¦ q i.succ
theorem tail_def {n : β} {Ξ± : Fin (n + 1) β Sort*} {q : β i, Ξ± i} :
(tail fun k : Fin (n + 1) β¦ q k) = fun k : Fin n β¦ q k.succ :=
rfl
/-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/
def cons (x : Ξ± 0) (p : β i : Fin n, Ξ± i.succ) : β i, Ξ± i := fun j β¦ Fin.cases x p j
@[simp]
theorem tail_cons : tail (cons x p) = p := by
simp +unfoldPartialApp [tail, cons]
@[simp]
theorem cons_succ : cons x p i.succ = p i := by simp [cons]
@[simp]
theorem cons_zero : cons x p 0 = x := by simp [cons]
@[simp]
theorem cons_one {Ξ± : Fin (n + 2) β Sort*} (x : Ξ± 0) (p : β i : Fin n.succ, Ξ± i.succ) :
cons x p 1 = p 0 := by
rw [β cons_succ x p]; rfl
/-- Updating a tuple and adding an element at the beginning commute. -/
@[simp]
theorem cons_update : cons x (update p i y) = update (cons x p) i.succ y := by
ext j
by_cases h : j = 0
Β· rw [h]
simp [Ne.symm (succ_ne_zero i)]
Β· let j' := pred j h
have : j'.succ = j := succ_pred j h
rw [β this, cons_succ]
by_cases h' : j' = i
Β· rw [h']
simp
Β· have : j'.succ β i.succ := by rwa [Ne, succ_inj]
rw [update_of_ne h', update_of_ne this, cons_succ]
/-- As a binary function, `Fin.cons` is injective. -/
theorem cons_injective2 : Function.Injective2 (@cons n Ξ±) := fun xβ yβ x y h β¦
β¨congr_fun h 0, funext fun i β¦ by simpa using congr_fun h (Fin.succ i)β©
@[simp]
theorem cons_inj {xβ yβ : Ξ± 0} {x y : β i : Fin n, Ξ± i.succ} :
cons xβ x = cons yβ y β xβ = yβ β§ x = y :=
cons_injective2.eq_iff
theorem cons_left_injective (x : β i : Fin n, Ξ± i.succ) : Function.Injective fun xβ β¦ cons xβ x :=
cons_injective2.left _
theorem cons_right_injective (xβ : Ξ± 0) : Function.Injective (cons xβ) :=
cons_injective2.right _
/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it
directly. -/
theorem update_cons_zero : update (cons x p) 0 z = cons z p := by
ext j
by_cases h : j = 0
Β· rw [h]
simp
Β· simp only [h, update_of_ne, Ne, not_false_iff]
let j' := pred j h
have : j'.succ = j := succ_pred j h
rw [β this, cons_succ, cons_succ]
/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/
@[simp]
theorem cons_self_tail : cons (q 0) (tail q) = q := by
ext j
by_cases h : j = 0
Β· rw [h]
simp
Β· let j' := pred j h
have : j'.succ = j := succ_pred j h
rw [β this]
unfold tail
rw [cons_succ]
/-- Equivalence between tuples of length `n + 1` and pairs of an element and a tuple of length `n`
given by separating out the first element of the tuple.
This is `Fin.cons` as an `Equiv`. -/
@[simps]
def consEquiv (Ξ± : Fin (n + 1) β Type*) : Ξ± 0 Γ (β i, Ξ± (succ i)) β β i, Ξ± i where
toFun f := cons f.1 f.2
invFun f := (f 0, tail f)
left_inv f := by simp
right_inv f := by simp
/-- Recurse on an `n+1`-tuple by splitting it into a single element and an `n`-tuple. -/
@[elab_as_elim]
def consCases {P : (β i : Fin n.succ, Ξ± i) β Sort v} (h : β xβ x, P (Fin.cons xβ x))
(x : β i : Fin n.succ, Ξ± i) : P x :=
_root_.cast (by rw [cons_self_tail]) <| h (x 0) (tail x)
@[simp]
theorem consCases_cons {P : (β i : Fin n.succ, Ξ± i) β Sort v} (h : β xβ x, P (Fin.cons xβ x))
(xβ : Ξ± 0) (x : β i : Fin n, Ξ± i.succ) : @consCases _ _ _ h (cons xβ x) = h xβ x := by
rw [consCases, cast_eq]
congr
/-- Recurse on a tuple by splitting into `Fin.elim0` and `Fin.cons`. -/
@[elab_as_elim]
def consInduction {Ξ± : Sort*} {P : β {n : β}, (Fin n β Ξ±) β Sort v} (h0 : P Fin.elim0)
(h : β {n} (xβ) (x : Fin n β Ξ±), P x β P (Fin.cons xβ x)) : β {n : β} (x : Fin n β Ξ±), P x
| 0, x => by convert h0
| _ + 1, x => consCases (fun _ _ β¦ h _ _ <| consInduction h0 h _) x
theorem cons_injective_of_injective {Ξ±} {xβ : Ξ±} {x : Fin n β Ξ±} (hxβ : xβ β Set.range x)
(hx : Function.Injective x) : Function.Injective (cons xβ x : Fin n.succ β Ξ±) := by
refine Fin.cases ?_ ?_
Β· refine Fin.cases ?_ ?_
Β· intro
rfl
Β· intro j h
rw [cons_zero, cons_succ] at h
exact hxβ.elim β¨_, h.symmβ©
Β· intro i
refine Fin.cases ?_ ?_
Β· intro h
rw [cons_zero, cons_succ] at h
exact hxβ.elim β¨_, hβ©
Β· intro j h
rw [cons_succ, cons_succ] at h
exact congr_arg _ (hx h)
theorem cons_injective_iff {Ξ±} {xβ : Ξ±} {x : Fin n β Ξ±} :
Function.Injective (cons xβ x : Fin n.succ β Ξ±) β xβ β Set.range x β§ Function.Injective x := by
refine β¨fun h β¦ β¨?_, ?_β©, fun h β¦ cons_injective_of_injective h.1 h.2β©
Β· rintro β¨i, hiβ©
replace h := @h i.succ 0
simp [hi] at h
Β· simpa [Function.comp] using h.comp (Fin.succ_injective _)
@[simp]
theorem forall_fin_zero_pi {Ξ± : Fin 0 β Sort*} {P : (β i, Ξ± i) β Prop} :
(β x, P x) β P finZeroElim :=
β¨fun h β¦ h _, fun h x β¦ Subsingleton.elim finZeroElim x βΈ hβ©
@[simp]
theorem exists_fin_zero_pi {Ξ± : Fin 0 β Sort*} {P : (β i, Ξ± i) β Prop} :
(β x, P x) β P finZeroElim :=
β¨fun β¨x, hβ© β¦ Subsingleton.elim x finZeroElim βΈ h, fun h β¦ β¨_, hβ©β©
theorem forall_fin_succ_pi {P : (β i, Ξ± i) β Prop} : (β x, P x) β β a v, P (Fin.cons a v) :=
β¨fun h a v β¦ h (Fin.cons a v), consCasesβ©
theorem exists_fin_succ_pi {P : (β i, Ξ± i) β Prop} : (β x, P x) β β a v, P (Fin.cons a v) :=
β¨fun β¨x, hβ© β¦ β¨x 0, tail x, (cons_self_tail x).symm βΈ hβ©, fun β¨_, _, hβ© β¦ β¨_, hβ©β©
/-- Updating the first element of a tuple does not change the tail. -/
@[simp]
theorem tail_update_zero : tail (update q 0 z) = tail q := by
ext j
simp [tail]
/-- Updating a nonzero element and taking the tail commute. -/
@[simp]
theorem tail_update_succ : tail (update q i.succ y) = update (tail q) i y := by
ext j
by_cases h : j = i
Β· rw [h]
simp [tail]
Β· simp [tail, (Fin.succ_injective n).ne h, h]
theorem comp_cons {Ξ± : Sort*} {Ξ² : Sort*} (g : Ξ± β Ξ²) (y : Ξ±) (q : Fin n β Ξ±) :
g β cons y q = cons (g y) (g β q) := by
| ext j
by_cases h : j = 0
Β· rw [h]
| Mathlib/Data/Fin/Tuple/Basic.lean | 270 | 272 |
/-
Copyright (c) 2023 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.Shift.CommShift
/-!
# Shift induced from a category to another
In this file, we introduce a sufficient condition on a functor
`F : C β₯€ D` so that a shift on `C` by a monoid `A` induces a shift on `D`.
More precisely, when the functor `(D β₯€ D) β₯€ C β₯€ D` given
by the precomposition with `F` is fully faithful, and that
all the shift functors on `C` can be lifted to functors `D β₯€ D`
(i.e. we have functors `s a : D β₯€ D` for all `a : A`, and isomorphisms
`F β s a β
shiftFunctor C a β F`), then these functors `s a` are
the shift functors of a term of type `HasShift D A`.
As this condition on the functor `F` is satisfied for quotient and localization
functors, the main construction `HasShift.induced` in this file shall be
used for both quotient and localized shifts.
-/
namespace CategoryTheory
variable {C D : Type _} [Category C] [Category D]
(F : C β₯€ D) {A : Type _} [AddMonoid A] [HasShift C A]
(s : A β D β₯€ D) (i : β a, F β s a β
shiftFunctor C a β F)
[((whiskeringLeft C D D).obj F).Full] [((whiskeringLeft C D D).obj F).Faithful]
namespace HasShift
namespace Induced
/-- The `zero` field of the `ShiftMkCore` structure for the induced shift. -/
noncomputable def zero : s 0 β
π D :=
((whiskeringLeft C D D).obj F).preimageIso ((i 0) βͺβ«
isoWhiskerRight (shiftFunctorZero C A) F βͺβ« F.leftUnitor βͺβ« F.rightUnitor.symm)
/-- The `add` field of the `ShiftMkCore` structure for the induced shift. -/
noncomputable def add (a b : A) : s (a + b) β
s a β s b :=
((whiskeringLeft C D D).obj F).preimageIso
(i (a + b) βͺβ« isoWhiskerRight (shiftFunctorAdd C a b) F βͺβ«
Functor.associator _ _ _ βͺβ«
isoWhiskerLeft _ (i b).symm βͺβ« (Functor.associator _ _ _).symm βͺβ«
isoWhiskerRight (i a).symm _ βͺβ« Functor.associator _ _ _)
@[simp]
lemma zero_hom_app_obj (X : C) :
(zero F s i).hom.app (F.obj X) =
(i 0).hom.app X β« F.map ((shiftFunctorZero C A).hom.app X) := by
have h : whiskerLeft F (zero F s i).hom = _ :=
((whiskeringLeft C D D).obj F).map_preimage _
exact (NatTrans.congr_app h X).trans (by simp)
@[simp]
lemma zero_inv_app_obj (X : C) :
(zero F s i).inv.app (F.obj X) =
F.map ((shiftFunctorZero C A).inv.app X) β« (i 0).inv.app X := by
have h : whiskerLeft F (zero F s i).inv = _ :=
((whiskeringLeft C D D).obj F).map_preimage _
exact (NatTrans.congr_app h X).trans (by simp)
@[simp]
lemma add_hom_app_obj (a b : A) (X : C) :
(add F s i a b).hom.app (F.obj X) =
(i (a + b)).hom.app X β« F.map ((shiftFunctorAdd C a b).hom.app X) β«
(i b).inv.app ((shiftFunctor C a).obj X) β« (s b).map ((i a).inv.app X) := by
have h : whiskerLeft F (add F s i a b).hom = _ :=
((whiskeringLeft C D D).obj F).map_preimage _
exact (NatTrans.congr_app h X).trans (by simp)
@[simp]
lemma add_inv_app_obj (a b : A) (X : C) :
(add F s i a b).inv.app (F.obj X) =
(s b).map ((i a).hom.app X) β« (i b).hom.app ((shiftFunctor C a).obj X) β«
F.map ((shiftFunctorAdd C a b).inv.app X) β« (i (a + b)).inv.app X := by
have h : whiskerLeft F (add F s i a b).inv = _ :=
((whiskeringLeft C D D).obj F).map_preimage _
exact (NatTrans.congr_app h X).trans (by simp)
end Induced
variable (A)
/-- When `F : C β₯€ D` is a functor satisfying suitable technical assumptions,
this is the induced term of type `HasShift D A` deduced from `[HasShift C A]`. -/
noncomputable def induced : HasShift D A :=
hasShiftMk D A
{ F := s
zero := Induced.zero F s i
add := Induced.add F s i
zero_add_hom_app := fun n => by
suffices (Induced.add F s i 0 n).hom =
eqToHom (by rw [zero_add]; rfl) β« whiskerRight (Induced.zero F s i ).inv (s n) by
intro X
simpa using NatTrans.congr_app this X
apply ((whiskeringLeft C D D).obj F).map_injective
ext X
have eq := dcongr_arg (fun a => (i a).hom.app X) (zero_add n)
dsimp
simp only [Induced.add_hom_app_obj, eq, shiftFunctorAdd_zero_add_hom_app,
Functor.map_comp, eqToHom_map, Category.assoc, eqToHom_trans_assoc,
eqToHom_refl, Category.id_comp, eqToHom_app, Induced.zero_inv_app_obj]
erw [β NatTrans.naturality_assoc, Iso.hom_inv_id_app_assoc]
rfl
add_zero_hom_app := fun n => by
suffices (Induced.add F s i n 0).hom =
eqToHom (by rw [add_zero]; rfl) β« whiskerLeft (s n) (Induced.zero F s i).inv by
intro X
simpa using NatTrans.congr_app this X
apply ((whiskeringLeft C D D).obj F).map_injective
ext X
dsimp
erw [Induced.add_hom_app_obj, dcongr_arg (fun a => (i a).hom.app X) (add_zero n),
β cancel_mono ((s 0).map ((i n).hom.app X)), Category.assoc,
Category.assoc, Category.assoc, Category.assoc, Category.assoc,
Category.assoc, β (s 0).map_comp, Iso.inv_hom_id_app, Functor.map_id, Category.comp_id,
β NatTrans.naturality, Induced.zero_inv_app_obj,
shiftFunctorAdd_add_zero_hom_app]
simp [eqToHom_map, eqToHom_app]
assoc_hom_app := fun mβ mβ mβ => by
suffices (Induced.add F s i (mβ + mβ) mβ).hom β«
whiskerRight (Induced.add F s i mβ mβ).hom (s mβ) =
eqToHom (by rw [add_assoc]) β« (Induced.add F s i mβ (mβ + mβ)).hom β«
whiskerLeft (s mβ) (Induced.add F s i mβ mβ).hom by
intro X
simpa using NatTrans.congr_app this X
apply ((whiskeringLeft C D D).obj F).map_injective
ext X
dsimp
have eq := F.congr_map (shiftFunctorAdd'_assoc_hom_app
mβ mβ mβ _ _ (mβ+mβ+mβ) rfl rfl rfl X)
simp only [shiftFunctorAdd'_eq_shiftFunctorAdd] at eq
simp only [Functor.comp_obj, Functor.map_comp, shiftFunctorAdd',
Iso.trans_hom, eqToIso.hom, NatTrans.comp_app, eqToHom_app,
Category.assoc] at eq
rw [β cancel_mono ((s mβ).map ((s mβ).map ((i mβ).hom.app X)))]
simp only [Induced.add_hom_app_obj, Category.assoc, Functor.map_comp]
slice_lhs 4 5 =>
erw [β Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id]
erw [Category.id_comp]
slice_lhs 6 7 =>
erw [β Functor.map_comp, β Functor.map_comp, Iso.inv_hom_id_app,
(s mβ).map_id, (s mβ).map_id]
erw [Category.comp_id, β NatTrans.naturality_assoc, reassoc_of% eq,
dcongr_arg (fun a => (i a).hom.app X) (add_assoc mβ mβ mβ).symm]
simp only [Functor.comp_obj, eqToHom_map, eqToHom_app, NatTrans.naturality_assoc,
Induced.add_hom_app_obj, Functor.comp_map, Category.assoc, Iso.inv_hom_id_app_assoc,
eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, Category.comp_id,
β Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id] }
end HasShift
lemma shiftFunctor_of_induced (a : A) :
letI := HasShift.induced F A s i
shiftFunctor D a = s a := by
rfl
variable (A)
@[simp]
| lemma shiftFunctorZero_hom_app_obj_of_induced (X : C) :
letI := HasShift.induced F A s i
(shiftFunctorZero D A).hom.app (F.obj X) =
(i 0).hom.app X β« F.map ((shiftFunctorZero C A).hom.app X) := by
letI := HasShift.induced F A s i
simp only [ShiftMkCore.shiftFunctorZero_eq, HasShift.Induced.zero_hom_app_obj]
| Mathlib/CategoryTheory/Shift/Induced.lean | 165 | 171 |
/-
Copyright (c) 2021 Benjamin Davidson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog
import Mathlib.Analysis.SpecialFunctions.NonIntegrable
import Mathlib.Analysis.SpecialFunctions.Pow.Deriv
import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv
import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts
/-!
# Integration of specific interval integrals
This file contains proofs of the integrals of various specific functions. This includes:
* Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log`
* Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)`
* The integral of `cos x ^ 2 - sin x ^ 2`
* Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n β₯ 2`
* The computation of `β« x in 0..Ο, sin x ^ n` as a product for even and odd `n` (used in proving the
Wallis product for pi)
* Integrals of the form `sin x ^ m * cos x ^ n`
With these lemmas, many simple integrals can be computed by `simp` or `norm_num`.
This file also contains some facts about the interval integrability of specific functions.
This file is still being developed.
## Tags
integrate, integration, integrable, integrability
-/
open Real Set Finset
open scoped Real Interval
variable {a b : β} (n : β)
namespace intervalIntegral
open MeasureTheory
variable {f : β β β} {ΞΌ : Measure β} [IsLocallyFiniteMeasure ΞΌ] (c d : β)
/-! ### Interval integrability -/
@[simp]
theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) ΞΌ a b :=
(continuous_pow n).intervalIntegrable a b
theorem intervalIntegrable_zpow {n : β€} (h : 0 β€ n β¨ (0 : β) β [[a, b]]) :
IntervalIntegrable (fun x => x ^ n) ΞΌ a b :=
(continuousOn_id.zpowβ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable
/-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the
measure is volume. -/
theorem intervalIntegrable_rpow {r : β} (h : 0 β€ r β¨ (0 : β) β [[a, b]]) :
IntervalIntegrable (fun x => x ^ r) ΞΌ a b :=
(continuousOn_id.rpow_const fun _ hx =>
h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable
/-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a
stronger hypothesis on `r`. -/
theorem intervalIntegrable_rpow' {r : β} (h : -1 < r) :
IntervalIntegrable (fun x => x ^ r) volume a b := by
suffices β c : β, IntervalIntegrable (fun x => x ^ r) volume 0 c by
exact IntervalIntegrable.trans (this a).symm (this b)
have : β c : β, 0 β€ c β IntervalIntegrable (fun x => x ^ r) volume 0 c := by
intro c hc
rw [intervalIntegrable_iff, uIoc_of_le hc]
have hderiv : β x β Ioo 0 c, HasDerivAt (fun x : β => x ^ (r + 1) / (r + 1)) (x ^ r) x := by
intro x hx
convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1
field_simp [(by linarith : r + 1 β 0)]
apply integrableOn_deriv_of_nonneg _ hderiv
Β· intro x hx; apply rpow_nonneg hx.1.le
Β· refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith
intro c; rcases le_total 0 c with (hc | hc)
Β· exact this c hc
Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero]
have m := (this (-c) (by linarith)).smul (cos (r * Ο))
rw [intervalIntegrable_iff] at m β’
refine m.congr_fun ?_ measurableSet_Ioc; intro x hx
rw [uIoc_of_le (by linarith : 0 β€ -c)] at hx
simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm,
rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)]
/-- The power function `x β¦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/
lemma integrableOn_Ioo_rpow_iff {s t : β} (ht : 0 < t) :
IntegrableOn (fun x β¦ x ^ s) (Ioo (0 : β) t) β -1 < s := by
refine β¨fun h β¦ ?_, fun h β¦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le]
using intervalIntegrable_rpow' h (a := 0) (b := t)β©
contrapose! h
intro H
have I : 0 < min 1 t := lt_min zero_lt_one ht
have H' : IntegrableOn (fun x β¦ x ^ s) (Ioo 0 (min 1 t)) :=
H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl
have : IntegrableOn (fun x β¦ xβ»ΒΉ) (Ioo 0 (min 1 t)) := by
apply H'.mono' measurable_inv.aestronglyMeasurable
filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx
simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)]
rwa [β Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1]
exact lt_of_lt_of_le hx.2 (min_le_left _ _)
have : IntervalIntegrable (fun x β¦ xβ»ΒΉ) volume 0 (min 1 t) := by
rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le]
simp [intervalIntegrable_inv_iff, I.ne] at this
/-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the
measure is volume. -/
theorem intervalIntegrable_cpow {r : β} (h : 0 β€ r.re β¨ (0 : β) β [[a, b]]) :
IntervalIntegrable (fun x : β => (x : β) ^ r) ΞΌ a b := by
by_cases h2 : (0 : β) β [[a, b]]
Β· -- Easy case #1: 0 β [a, b] -- use continuity.
refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable
exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2)
rw [eq_false h2, or_false] at h
rcases lt_or_eq_of_le h with (h' | h')
Β· -- Easy case #2: 0 < re r -- again use continuity
exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _
-- Now the hard case: re r = 0 and 0 is in the interval.
refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_
Β· refine (measurable_of_continuousOn_compl_singleton (0 : β) ?_).aestronglyMeasurable
exact continuousOn_of_forall_continuousAt fun x hx =>
Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx)
-- reduce to case of integral over `[0, c]`
suffices β c : β, IntervalIntegrable (fun x : β => β(x : β) ^ rβ) ΞΌ 0 c from
(this a).symm.trans (this b)
intro c
rcases le_or_lt 0 c with (hc | hc)
Β· -- case `0 β€ c`: integrand is identically 1
have : IntervalIntegrable (fun _ => 1 : β β β) ΞΌ 0 c := intervalIntegrable_const
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this β’
refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc
dsimp only
rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, β h', rpow_zero]
Β· -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r β 0`.
apply IntervalIntegrable.symm
rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le]
rw [β Ioo_union_right hc, integrableOn_union, and_comm]; constructor
Β· refine integrableOn_singleton_iff.mpr (Or.inr ?_)
exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact
isCompact_singleton
Β· have : β x : β, x β Ioo c 0 β βComplex.exp (βΟ * Complex.I * r)β = β(x : β) ^ rβ := by
intro x hx
rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, β Complex.ofReal_neg,
Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), β h',
rpow_zero, one_mul]
refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo
rw [integrableOn_const]
refine Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_)
exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc
/-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a
stronger hypothesis on `r`. -/
theorem intervalIntegrable_cpow' {r : β} (h : -1 < r.re) :
IntervalIntegrable (fun x : β => (x : β) ^ r) volume a b := by
suffices β c : β, IntervalIntegrable (fun x => (x : β) ^ r) volume 0 c by
exact IntervalIntegrable.trans (this a).symm (this b)
have : β c : β, 0 β€ c β IntervalIntegrable (fun x => (x : β) ^ r) volume 0 c := by
intro c hc
rw [β IntervalIntegrable.intervalIntegrable_norm_iff]
Β· rw [intervalIntegrable_iff]
apply IntegrableOn.congr_fun
Β· rw [β intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h
Β· intro x hx
rw [uIoc_of_le hc] at hx
dsimp only
rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1]
Β· exact measurableSet_uIoc
Β· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc
refine continuousOn_of_forall_continuousAt fun x hx => ?_
rw [uIoc_of_le hc] at hx
refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt
rw [Complex.ofReal_re]
exact hx.1
intro c; rcases le_total 0 c with (hc | hc)
Β· exact this c hc
Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero]
have m := (this (-c) (by linarith)).const_mul (Complex.exp (Ο * Complex.I * r))
rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 β€ -c)] at m β’
refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc
dsimp only
have : -x β€ 0 := by linarith [hx.1]
rw [Complex.ofReal_cpow_of_nonpos this, mul_comm]
simp
/-- The complex power function `x β¦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/
theorem integrableOn_Ioo_cpow_iff {s : β} {t : β} (ht : 0 < t) :
IntegrableOn (fun x : β β¦ (x : β) ^ s) (Ioo (0 : β) t) β -1 < s.re := by
refine β¨fun h β¦ ?_, fun h β¦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le]
using intervalIntegrable_cpow' h (a := 0) (b := t)β©
have B : IntegrableOn (fun a β¦ a ^ s.re) (Ioo 0 t) := by
apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm
intro a ha
simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1]
rwa [integrableOn_Ioo_rpow_iff ht] at B
@[simp]
theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) ΞΌ a b :=
continuous_id.intervalIntegrable a b
theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) ΞΌ a b :=
continuous_const.intervalIntegrable a b
theorem intervalIntegrable_one_div (h : β x : β, x β [[a, b]] β f x β 0)
(hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) ΞΌ a b :=
(continuousOn_const.div hf h).intervalIntegrable
@[simp]
theorem intervalIntegrable_inv (h : β x : β, x β [[a, b]] β f x β 0)
(hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)β»ΒΉ) ΞΌ a b := by
simpa only [one_div] using intervalIntegrable_one_div h hf
@[simp]
theorem intervalIntegrable_exp : IntervalIntegrable exp ΞΌ a b :=
continuous_exp.intervalIntegrable a b
@[simp]
theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]])
(h : β x : β, x β [[a, b]] β f x β 0) :
IntervalIntegrable (fun x => log (f x)) ΞΌ a b :=
(ContinuousOn.log hf h).intervalIntegrable
/-- See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but
assuming the measure is volume. -/
@[simp]
theorem intervalIntegrable_log (h : (0 : β) β [[a, b]]) : IntervalIntegrable log ΞΌ a b :=
IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h
/-- The real logarithm is interval integrable (with respect to the volume measure) on every
interval. See `intervalIntegrable_log` for a version applying to any locally finite measure,
but with an additional hypothesis on the interval. -/
@[simp]
theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by
-- Log is even, so it suffices to consider the case 0 < a and b = 0
apply intervalIntegrable_of_even (log_neg_eq_log Β· |>.symm)
intro x hx
-- Split integral
apply IntervalIntegrable.trans (b := 1)
Β· -- Show integrability on [0β¦1] using non-negativity of the derivative
rw [β neg_neg log]
apply IntervalIntegrable.neg
apply intervalIntegrable_deriv_of_nonneg (g := fun x β¦ -(x * log x - x))
Β· exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg
Β· intro s β¨hs, _β©
norm_num at *
simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm)
Β· intro s β¨hsβ, hsββ©
norm_num at *
exact (log_nonpos_iff hsβ.le).mpr hsβ.le
Β· -- Show integrability on [1β¦t] by continuity
apply ContinuousOn.intervalIntegrable
apply Real.continuousOn_log.mono
apply Set.not_mem_uIcc_of_lt zero_lt_one at hx
simpa
@[simp]
theorem intervalIntegrable_sin : IntervalIntegrable sin ΞΌ a b :=
continuous_sin.intervalIntegrable a b
@[simp]
theorem intervalIntegrable_cos : IntervalIntegrable cos ΞΌ a b :=
continuous_cos.intervalIntegrable a b
theorem intervalIntegrable_one_div_one_add_sq :
IntervalIntegrable (fun x : β => 1 / (β1 + x ^ 2)) ΞΌ a b := by
refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b
Β· fun_prop
Β· nlinarith
@[simp]
theorem intervalIntegrable_inv_one_add_sq :
IntervalIntegrable (fun x : β => (β1 + x ^ 2)β»ΒΉ) ΞΌ a b := by
field_simp; exact mod_cast intervalIntegrable_one_div_one_add_sq
/-! ### Integrals of the form `c * β« x in a..b, f (c * x + d)` -/
section
@[simp]
theorem mul_integral_comp_mul_right : (c * β« x in a..b, f (x * c)) = β« x in a * c..b * c, f x :=
smul_integral_comp_mul_right f c
@[simp]
theorem mul_integral_comp_mul_left : (c * β« x in a..b, f (c * x)) = β« x in c * a..c * b, f x :=
smul_integral_comp_mul_left f c
@[simp]
theorem inv_mul_integral_comp_div : (cβ»ΒΉ * β« x in a..b, f (x / c)) = β« x in a / c..b / c, f x :=
inv_smul_integral_comp_div f c
@[simp]
theorem mul_integral_comp_mul_add :
(c * β« x in a..b, f (c * x + d)) = β« x in c * a + d..c * b + d, f x :=
smul_integral_comp_mul_add f c d
@[simp]
theorem mul_integral_comp_add_mul :
(c * β« x in a..b, f (d + c * x)) = β« x in d + c * a..d + c * b, f x :=
smul_integral_comp_add_mul f c d
@[simp]
theorem inv_mul_integral_comp_div_add :
(cβ»ΒΉ * β« x in a..b, f (x / c + d)) = β« x in a / c + d..b / c + d, f x :=
inv_smul_integral_comp_div_add f c d
@[simp]
theorem inv_mul_integral_comp_add_div :
(cβ»ΒΉ * β« x in a..b, f (d + x / c)) = β« x in d + a / c..d + b / c, f x :=
inv_smul_integral_comp_add_div f c d
@[simp]
theorem mul_integral_comp_mul_sub :
(c * β« x in a..b, f (c * x - d)) = β« x in c * a - d..c * b - d, f x :=
smul_integral_comp_mul_sub f c d
@[simp]
theorem mul_integral_comp_sub_mul :
(c * β« x in a..b, f (d - c * x)) = β« x in d - c * b..d - c * a, f x :=
smul_integral_comp_sub_mul f c d
@[simp]
theorem inv_mul_integral_comp_div_sub :
(cβ»ΒΉ * β« x in a..b, f (x / c - d)) = β« x in a / c - d..b / c - d, f x :=
inv_smul_integral_comp_div_sub f c d
@[simp]
theorem inv_mul_integral_comp_sub_div :
(cβ»ΒΉ * β« x in a..b, f (d - x / c)) = β« x in d - b / c..d - a / c, f x :=
inv_smul_integral_comp_sub_div f c d
end
end intervalIntegral
open intervalIntegral
/-! ### Integrals of simple functions -/
theorem integral_cpow {r : β} (h : -1 < r.re β¨ r β -1 β§ (0 : β) β [[a, b]]) :
(β« x : β in a..b, (x : β) ^ r) = ((b : β) ^ (r + 1) - (a : β) ^ (r + 1)) / (r + 1) := by
rw [sub_div]
have hr : r + 1 β 0 := by
rcases h with h | h
Β· apply_fun Complex.re
rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg]
exact h.ne'
Β· rw [Ne, β add_eq_zero_iff_eq_neg] at h; exact h.1
by_cases hab : (0 : β) β [[a, b]]
Β· apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_)
(intervalIntegrable_cpow (r := r) <| Or.inr hab)
refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_
contrapose! hr; rwa [add_eq_zero_iff_eq_neg]
replace h : -1 < r.re := by tauto
suffices β c : β, (β« x : β in (0)..c, (x : β) ^ r) =
(c : β) ^ (r + 1) / (r + 1) - (0 : β) ^ (r + 1) / (r + 1) by
rw [β integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h)
(@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr]
ring
intro c
apply integral_eq_sub_of_hasDeriv_right
Β· refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn
rwa [Complex.add_re, Complex.one_re, β neg_lt_iff_pos_add]
Β· refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt
Β· rcases le_total c 0 with (hc | hc)
Β· rw [max_eq_left hc] at hx; exact hx.2.ne
Β· rw [min_eq_left hc] at hx; exact hx.1.ne'
Β· contrapose! hr; rw [hr]; ring
Β· exact intervalIntegrable_cpow' h
theorem integral_rpow {r : β} (h : -1 < r β¨ r β -1 β§ (0 : β) β [[a, b]]) :
β« x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by
have h' : -1 < (r : β).re β¨ (r : β) β -1 β§ (0 : β) β [[a, b]] := by
cases h
Β· left; rwa [Complex.ofReal_re]
Β· right; rwa [β Complex.ofReal_one, β Complex.ofReal_neg, Ne, Complex.ofReal_inj]
have :
(β« x in a..b, (x : β) ^ (r : β)) = ((b : β) ^ (r + 1 : β) - (a : β) ^ (r + 1 : β)) / (r + 1) :=
integral_cpow h'
apply_fun Complex.re at this; convert this
Β· simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def,
β RCLike.re_eq_complex_re, smul_eq_mul]
rw [integral_re]
refine intervalIntegrable_iff.mp ?_
rcases h' with h' | h'
Β· exact intervalIntegrable_cpow' h'
Β· exact intervalIntegrable_cpow (Or.inr h'.2)
Β· rw [(by push_cast; rfl : (r : β) + 1 = ((r + 1 : β) : β))]
simp_rw [div_eq_inv_mul, β Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def]
theorem integral_zpow {n : β€} (h : 0 β€ n β¨ n β -1 β§ (0 : β) β [[a, b]]) :
β« x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by
replace h : -1 < (n : β) β¨ (n : β) β -1 β§ (0 : β) β [[a, b]] := mod_cast h
exact mod_cast integral_rpow h
@[simp]
theorem integral_pow : β« x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by
simpa only [β Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg)
/-- Integral of `|x - a| ^ n` over `Ξ a b`. This integral appears in the proof of the
Picard-LindelΓΆf/Cauchy-Lipschitz theorem. -/
theorem integral_pow_abs_sub_uIoc : β« x in Ξ a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by
rcases le_or_lt a b with hab | hab
Β· calc
β« x in Ξ a b, |x - a| ^ n = β« x in a..b, |x - a| ^ n := by
rw [uIoc_of_le hab, β integral_of_le hab]
_ = β« x in (0)..(b - a), x ^ n := by
simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self]
refine integral_congr fun x hx => congr_argβ Pow.pow (abs_of_nonneg <| ?_) rfl
rw [uIcc_of_le (sub_nonneg.2 hab)] at hx
exact hx.1
_ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)]
Β· calc
β« x in Ξ a b, |x - a| ^ n = β« x in b..a, |x - a| ^ n := by
rw [uIoc_of_ge hab.le, β integral_of_le hab.le]
_ = β« x in b - a..0, (-x) ^ n := by
simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self]
refine integral_congr fun x hx => congr_argβ Pow.pow (abs_of_nonpos <| ?_) rfl
rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx
exact hx.2
_ = |b - a| ^ (n + 1) / (n + 1) := by
simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)]
@[simp]
theorem integral_id : β« x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by
have := @integral_pow a b 1
norm_num at this
exact this
theorem integral_one : (β« _ in a..b, (1 : β)) = b - a := by
simp only [mul_one, smul_eq_mul, integral_const]
theorem integral_const_on_unit_interval : β« _ in a..a + 1, b = b := by simp
@[simp]
theorem integral_inv (h : (0 : β) β [[a, b]]) : β« x in a..b, xβ»ΒΉ = log (b / a) := by
have h' := fun x (hx : x β [[a, b]]) => ne_of_mem_of_not_mem hx h
rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx))
(continuousOn_invβ.mono <| subset_compl_singleton_iff.mpr h),
log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)]
@[simp]
theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : β« x in a..b, xβ»ΒΉ = log (b / a) :=
| integral_inv <| not_mem_uIcc_of_lt ha hb
| Mathlib/Analysis/SpecialFunctions/Integrals.lean | 448 | 449 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, YaΓ«l Dillies
-/
import Mathlib.Order.Cover
import Mathlib.Order.Interval.Finset.Defs
/-!
# Intervals as finsets
This file provides basic results about all the `Finset.Ixx`, which are defined in
`Order.Interval.Finset.Defs`.
In addition, it shows that in a locally finite order `β€` and `<` are the transitive closures of,
respectively, `β©Ώ` and `β`, which then leads to a characterization of monotone and strictly
functions whose domain is a locally finite order. In particular, this file proves:
* `le_iff_transGen_wcovBy`: `β€` is the transitive closure of `β©Ώ`
* `lt_iff_transGen_covBy`: `<` is the transitive closure of `β`
* `monotone_iff_forall_wcovBy`: Characterization of monotone functions
* `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions
## TODO
This file was originally only about `Finset.Ico a b` where `a b : β`. No care has yet been taken to
generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general,
what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure.
Complete the API. See
https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235
for some ideas.
-/
assert_not_exists MonoidWithZero Finset.sum
open Function OrderDual
open FinsetInterval
variable {ΞΉ Ξ± : Type*} {a aβ aβ b bβ bβ c x : Ξ±}
namespace Finset
section Preorder
variable [Preorder Ξ±]
section LocallyFiniteOrder
variable [LocallyFiniteOrder Ξ±]
@[simp]
theorem nonempty_Icc : (Icc a b).Nonempty β a β€ b := by
rw [β coe_nonempty, coe_Icc, Set.nonempty_Icc]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias β¨_, Aesop.nonempty_Icc_of_leβ© := nonempty_Icc
@[simp]
theorem nonempty_Ico : (Ico a b).Nonempty β a < b := by
rw [β coe_nonempty, coe_Ico, Set.nonempty_Ico]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias β¨_, Aesop.nonempty_Ico_of_ltβ© := nonempty_Ico
@[simp]
theorem nonempty_Ioc : (Ioc a b).Nonempty β a < b := by
rw [β coe_nonempty, coe_Ioc, Set.nonempty_Ioc]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias β¨_, Aesop.nonempty_Ioc_of_ltβ© := nonempty_Ioc
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem nonempty_Ioo [DenselyOrdered Ξ±] : (Ioo a b).Nonempty β a < b := by
rw [β coe_nonempty, coe_Ioo, Set.nonempty_Ioo]
@[simp]
theorem Icc_eq_empty_iff : Icc a b = β
β Β¬a β€ b := by
rw [β coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff]
@[simp]
theorem Ico_eq_empty_iff : Ico a b = β
β Β¬a < b := by
rw [β coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff]
@[simp]
theorem Ioc_eq_empty_iff : Ioc a b = β
β Β¬a < b := by
rw [β coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff]
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem Ioo_eq_empty_iff [DenselyOrdered Ξ±] : Ioo a b = β
β Β¬a < b := by
rw [β coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff]
alias β¨_, Icc_eq_emptyβ© := Icc_eq_empty_iff
alias β¨_, Ico_eq_emptyβ© := Ico_eq_empty_iff
alias β¨_, Ioc_eq_emptyβ© := Ioc_eq_empty_iff
@[simp]
theorem Ioo_eq_empty (h : Β¬a < b) : Ioo a b = β
:=
eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2)
@[simp]
theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = β
:=
Icc_eq_empty h.not_le
@[simp]
theorem Ico_eq_empty_of_le (h : b β€ a) : Ico a b = β
:=
Ico_eq_empty h.not_lt
@[simp]
theorem Ioc_eq_empty_of_le (h : b β€ a) : Ioc a b = β
:=
Ioc_eq_empty h.not_lt
@[simp]
theorem Ioo_eq_empty_of_le (h : b β€ a) : Ioo a b = β
:=
Ioo_eq_empty h.not_lt
theorem left_mem_Icc : a β Icc a b β a β€ b := by simp only [mem_Icc, true_and, le_rfl]
theorem left_mem_Ico : a β Ico a b β a < b := by simp only [mem_Ico, true_and, le_refl]
theorem right_mem_Icc : b β Icc a b β a β€ b := by simp only [mem_Icc, and_true, le_rfl]
theorem right_mem_Ioc : b β Ioc a b β a < b := by simp only [mem_Ioc, and_true, le_rfl]
theorem left_not_mem_Ioc : a β Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1
theorem left_not_mem_Ioo : a β Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1
theorem right_not_mem_Ico : b β Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2
theorem right_not_mem_Ioo : b β Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2
@[gcongr]
theorem Icc_subset_Icc (ha : aβ β€ aβ) (hb : bβ β€ bβ) : Icc aβ bβ β Icc aβ bβ := by
simpa [β coe_subset] using Set.Icc_subset_Icc ha hb
@[gcongr]
theorem Ico_subset_Ico (ha : aβ β€ aβ) (hb : bβ β€ bβ) : Ico aβ bβ β Ico aβ bβ := by
simpa [β coe_subset] using Set.Ico_subset_Ico ha hb
@[gcongr]
theorem Ioc_subset_Ioc (ha : aβ β€ aβ) (hb : bβ β€ bβ) : Ioc aβ bβ β Ioc aβ bβ := by
simpa [β coe_subset] using Set.Ioc_subset_Ioc ha hb
@[gcongr]
theorem Ioo_subset_Ioo (ha : aβ β€ aβ) (hb : bβ β€ bβ) : Ioo aβ bβ β Ioo aβ bβ := by
simpa [β coe_subset] using Set.Ioo_subset_Ioo ha hb
@[gcongr]
theorem Icc_subset_Icc_left (h : aβ β€ aβ) : Icc aβ b β Icc aβ b :=
Icc_subset_Icc h le_rfl
@[gcongr]
theorem Ico_subset_Ico_left (h : aβ β€ aβ) : Ico aβ b β Ico aβ b :=
Ico_subset_Ico h le_rfl
@[gcongr]
theorem Ioc_subset_Ioc_left (h : aβ β€ aβ) : Ioc aβ b β Ioc aβ b :=
Ioc_subset_Ioc h le_rfl
@[gcongr]
theorem Ioo_subset_Ioo_left (h : aβ β€ aβ) : Ioo aβ b β Ioo aβ b :=
Ioo_subset_Ioo h le_rfl
@[gcongr]
theorem Icc_subset_Icc_right (h : bβ β€ bβ) : Icc a bβ β Icc a bβ :=
Icc_subset_Icc le_rfl h
@[gcongr]
theorem Ico_subset_Ico_right (h : bβ β€ bβ) : Ico a bβ β Ico a bβ :=
Ico_subset_Ico le_rfl h
@[gcongr]
theorem Ioc_subset_Ioc_right (h : bβ β€ bβ) : Ioc a bβ β Ioc a bβ :=
Ioc_subset_Ioc le_rfl h
@[gcongr]
theorem Ioo_subset_Ioo_right (h : bβ β€ bβ) : Ioo a bβ β Ioo a bβ :=
Ioo_subset_Ioo le_rfl h
theorem Ico_subset_Ioo_left (h : aβ < aβ) : Ico aβ b β Ioo aβ b := by
rw [β coe_subset, coe_Ico, coe_Ioo]
exact Set.Ico_subset_Ioo_left h
theorem Ioc_subset_Ioo_right (h : bβ < bβ) : Ioc a bβ β Ioo a bβ := by
rw [β coe_subset, coe_Ioc, coe_Ioo]
exact Set.Ioc_subset_Ioo_right h
theorem Icc_subset_Ico_right (h : bβ < bβ) : Icc a bβ β Ico a bβ := by
rw [β coe_subset, coe_Icc, coe_Ico]
exact Set.Icc_subset_Ico_right h
theorem Ioo_subset_Ico_self : Ioo a b β Ico a b := by
rw [β coe_subset, coe_Ioo, coe_Ico]
exact Set.Ioo_subset_Ico_self
theorem Ioo_subset_Ioc_self : Ioo a b β Ioc a b := by
rw [β coe_subset, coe_Ioo, coe_Ioc]
exact Set.Ioo_subset_Ioc_self
theorem Ico_subset_Icc_self : Ico a b β Icc a b := by
rw [β coe_subset, coe_Ico, coe_Icc]
exact Set.Ico_subset_Icc_self
theorem Ioc_subset_Icc_self : Ioc a b β Icc a b := by
rw [β coe_subset, coe_Ioc, coe_Icc]
exact Set.Ioc_subset_Icc_self
theorem Ioo_subset_Icc_self : Ioo a b β Icc a b :=
Ioo_subset_Ico_self.trans Ico_subset_Icc_self
theorem Icc_subset_Icc_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Icc aβ bβ β aβ β€ aβ β§ bβ β€ bβ := by
rw [β coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff hβ]
theorem Icc_subset_Ioo_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ioo aβ bβ β aβ < aβ β§ bβ < bβ := by
rw [β coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff hβ]
theorem Icc_subset_Ico_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ico aβ bβ β aβ β€ aβ β§ bβ < bβ := by
rw [β coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff hβ]
theorem Icc_subset_Ioc_iff (hβ : aβ β€ bβ) : Icc aβ bβ β Ioc aβ bβ β aβ < aβ β§ bβ β€ bβ :=
(Icc_subset_Ico_iff hβ.dual).trans and_comm
--TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff`
theorem Icc_ssubset_Icc_left (hI : aβ β€ bβ) (ha : aβ < aβ) (hb : bβ β€ bβ) :
Icc aβ bβ β Icc aβ bβ := by
rw [β coe_ssubset, coe_Icc, coe_Icc]
exact Set.Icc_ssubset_Icc_left hI ha hb
theorem Icc_ssubset_Icc_right (hI : aβ β€ bβ) (ha : aβ β€ aβ) (hb : bβ < bβ) :
Icc aβ bβ β Icc aβ bβ := by
rw [β coe_ssubset, coe_Icc, coe_Icc]
exact Set.Icc_ssubset_Icc_right hI ha hb
@[simp]
theorem Ioc_disjoint_Ioc_of_le {d : Ξ±} (hbc : b β€ c) : Disjoint (Ioc a b) (Ioc c d) :=
disjoint_left.2 fun _ h1 h2 β¦ not_and_of_not_left _
((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2)
variable (a)
theorem Ico_self : Ico a a = β
:=
Ico_eq_empty <| lt_irrefl _
theorem Ioc_self : Ioc a a = β
:=
Ioc_eq_empty <| lt_irrefl _
theorem Ioo_self : Ioo a a = β
:=
Ioo_eq_empty <| lt_irrefl _
variable {a}
/-- A set with upper and lower bounds in a locally finite order is a fintype -/
def _root_.Set.fintypeOfMemBounds {s : Set Ξ±} [DecidablePred (Β· β s)] (ha : a β lowerBounds s)
(hb : b β upperBounds s) : Fintype s :=
Set.fintypeSubset (Set.Icc a b) fun _ hx => β¨ha hx, hb hxβ©
section Filter
theorem Ico_filter_lt_of_le_left [DecidablePred (Β· < c)] (hca : c β€ a) :
{x β Ico a b | x < c} = β
:=
filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt
theorem Ico_filter_lt_of_right_le [DecidablePred (Β· < c)] (hbc : b β€ c) :
{x β Ico a b | x < c} = Ico a b :=
filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc
theorem Ico_filter_lt_of_le_right [DecidablePred (Β· < c)] (hcb : c β€ b) :
{x β Ico a b | x < c} = Ico a c := by
ext x
rw [mem_filter, mem_Ico, mem_Ico, and_right_comm]
exact and_iff_left_of_imp fun h => h.2.trans_le hcb
theorem Ico_filter_le_of_le_left {a b c : Ξ±} [DecidablePred (c β€ Β·)] (hca : c β€ a) :
{x β Ico a b | c β€ x} = Ico a b :=
filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1
theorem Ico_filter_le_of_right_le {a b : Ξ±} [DecidablePred (b β€ Β·)] :
{x β Ico a b | b β€ x} = β
:=
filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le
theorem Ico_filter_le_of_left_le {a b c : Ξ±} [DecidablePred (c β€ Β·)] (hac : a β€ c) :
{x β Ico a b | c β€ x} = Ico c b := by
ext x
rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm]
exact and_iff_right_of_imp fun h => hac.trans h.1
theorem Icc_filter_lt_of_lt_right {a b c : Ξ±} [DecidablePred (Β· < c)] (h : b < c) :
{x β Icc a b | x < c} = Icc a b :=
filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h
theorem Ioc_filter_lt_of_lt_right {a b c : Ξ±} [DecidablePred (Β· < c)] (h : b < c) :
{x β Ioc a b | x < c} = Ioc a b :=
filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h
theorem Iic_filter_lt_of_lt_right {Ξ±} [Preorder Ξ±] [LocallyFiniteOrderBot Ξ±] {a c : Ξ±}
[DecidablePred (Β· < c)] (h : a < c) : {x β Iic a | x < c} = Iic a :=
filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h
variable (a b) [Fintype Ξ±]
theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j β§ j < b] :
({j | a < j β§ j < b} : Finset _) = Ioo a b := by ext; simp
theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j β§ j β€ b] :
({j | a < j β§ j β€ b} : Finset _) = Ioc a b := by ext; simp
theorem filter_le_lt_eq_Ico [DecidablePred fun j => a β€ j β§ j < b] :
({j | a β€ j β§ j < b} : Finset _) = Ico a b := by ext; simp
theorem filter_le_le_eq_Icc [DecidablePred fun j => a β€ j β§ j β€ b] :
({j | a β€ j β§ j β€ b} : Finset _) = Icc a b := by ext; simp
end Filter
end LocallyFiniteOrder
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop Ξ±]
@[simp]
theorem Ioi_eq_empty : Ioi a = β
β IsMax a := by
rw [β coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff]
@[simp] alias β¨_, _root_.IsMax.finsetIoi_eqβ© := Ioi_eq_empty
@[simp] lemma Ioi_nonempty : (Ioi a).Nonempty β Β¬ IsMax a := by simp [nonempty_iff_ne_empty]
theorem Ioi_top [OrderTop Ξ±] : Ioi (β€ : Ξ±) = β
:= Ioi_eq_empty.mpr isMax_top
@[simp]
theorem Ici_bot [OrderBot Ξ±] [Fintype Ξ±] : Ici (β₯ : Ξ±) = univ := by
ext a; simp only [mem_Ici, bot_le, mem_univ]
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
lemma nonempty_Ici : (Ici a).Nonempty := β¨a, mem_Ici.2 le_rflβ©
lemma nonempty_Ioi : (Ioi a).Nonempty β Β¬ IsMax a := by simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias β¨_, Aesop.nonempty_Ioi_of_not_isMaxβ© := nonempty_Ioi
@[simp]
theorem Ici_subset_Ici : Ici a β Ici b β b β€ a := by
simp [β coe_subset]
@[gcongr]
alias β¨_, _root_.GCongr.Finset.Ici_subset_Iciβ© := Ici_subset_Ici
@[simp]
theorem Ici_ssubset_Ici : Ici a β Ici b β b < a := by
simp [β coe_ssubset]
@[gcongr]
alias β¨_, _root_.GCongr.Finset.Ici_ssubset_Iciβ© := Ici_ssubset_Ici
@[gcongr]
theorem Ioi_subset_Ioi (h : a β€ b) : Ioi b β Ioi a := by
simpa [β coe_subset] using Set.Ioi_subset_Ioi h
@[gcongr]
theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b β Ioi a := by
simpa [β coe_ssubset] using Set.Ioi_ssubset_Ioi h
variable [LocallyFiniteOrder Ξ±]
theorem Icc_subset_Ici_self : Icc a b β Ici a := by
simpa [β coe_subset] using Set.Icc_subset_Ici_self
theorem Ico_subset_Ici_self : Ico a b β Ici a := by
simpa [β coe_subset] using Set.Ico_subset_Ici_self
theorem Ioc_subset_Ioi_self : Ioc a b β Ioi a := by
simpa [β coe_subset] using Set.Ioc_subset_Ioi_self
theorem Ioo_subset_Ioi_self : Ioo a b β Ioi a := by
simpa [β coe_subset] using Set.Ioo_subset_Ioi_self
theorem Ioc_subset_Ici_self : Ioc a b β Ici a :=
Ioc_subset_Icc_self.trans Icc_subset_Ici_self
theorem Ioo_subset_Ici_self : Ioo a b β Ici a :=
Ioo_subset_Ico_self.trans Ico_subset_Ici_self
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot Ξ±]
@[simp]
theorem Iio_eq_empty : Iio a = β
β IsMin a := Ioi_eq_empty (Ξ± := Ξ±α΅α΅)
@[simp] alias β¨_, _root_.IsMin.finsetIio_eqβ© := Iio_eq_empty
@[simp] lemma Iio_nonempty : (Iio a).Nonempty β Β¬ IsMin a := by simp [nonempty_iff_ne_empty]
theorem Iio_bot [OrderBot Ξ±] : Iio (β₯ : Ξ±) = β
:= Iio_eq_empty.mpr isMin_bot
@[simp]
theorem Iic_top [OrderTop Ξ±] [Fintype Ξ±] : Iic (β€ : Ξ±) = univ := by
ext a; simp only [mem_Iic, le_top, mem_univ]
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
lemma nonempty_Iic : (Iic a).Nonempty := β¨a, mem_Iic.2 le_rflβ©
lemma nonempty_Iio : (Iio a).Nonempty β Β¬ IsMin a := by simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias β¨_, Aesop.nonempty_Iio_of_not_isMinβ© := nonempty_Iio
@[simp]
theorem Iic_subset_Iic : Iic a β Iic b β a β€ b := by
simp [β coe_subset]
@[gcongr]
alias β¨_, _root_.GCongr.Finset.Iic_subset_Iicβ© := Iic_subset_Iic
@[simp]
theorem Iic_ssubset_Iic : Iic a β Iic b β a < b := by
simp [β coe_ssubset]
@[gcongr]
alias β¨_, _root_.GCongr.Finset.Iic_ssubset_Iicβ© := Iic_ssubset_Iic
@[gcongr]
theorem Iio_subset_Iio (h : a β€ b) : Iio a β Iio b := by
simpa [β coe_subset] using Set.Iio_subset_Iio h
@[gcongr]
theorem Iio_ssubset_Iio (h : a < b) : Iio a β Iio b := by
simpa [β coe_ssubset] using Set.Iio_ssubset_Iio h
variable [LocallyFiniteOrder Ξ±]
theorem Icc_subset_Iic_self : Icc a b β Iic b := by
simpa [β coe_subset] using Set.Icc_subset_Iic_self
theorem Ioc_subset_Iic_self : Ioc a b β Iic b := by
simpa [β coe_subset] using Set.Ioc_subset_Iic_self
theorem Ico_subset_Iio_self : Ico a b β Iio b := by
simpa [β coe_subset] using Set.Ico_subset_Iio_self
theorem Ioo_subset_Iio_self : Ioo a b β Iio b := by
simpa [β coe_subset] using Set.Ioo_subset_Iio_self
theorem Ico_subset_Iic_self : Ico a b β Iic b :=
Ico_subset_Icc_self.trans Icc_subset_Iic_self
theorem Ioo_subset_Iic_self : Ioo a b β Iic b :=
Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self
theorem Iic_disjoint_Ioc (h : a β€ b) : Disjoint (Iic a) (Ioc b c) :=
disjoint_left.2 fun _ hax hbcx β¦ (mem_Iic.1 hax).not_lt <| lt_of_le_of_lt h (mem_Ioc.1 hbcx).1
/-- An equivalence between `Finset.Iic a` and `Set.Iic a`. -/
def _root_.Equiv.IicFinsetSet (a : Ξ±) : Iic a β Set.Iic a where
toFun b := β¨b.1, coe_Iic a βΈ mem_coe.2 b.2β©
invFun b := β¨b.1, by rw [β mem_coe, coe_Iic a]; exact b.2β©
left_inv := fun _ β¦ rfl
right_inv := fun _ β¦ rfl
end LocallyFiniteOrderBot
section LocallyFiniteOrderTop
variable [LocallyFiniteOrderTop Ξ±] {a : Ξ±}
theorem Ioi_subset_Ici_self : Ioi a β Ici a := by
simpa [β coe_subset] using Set.Ioi_subset_Ici_self
theorem _root_.BddBelow.finite {s : Set Ξ±} (hs : BddBelow s) : s.Finite :=
let β¨a, haβ© := hs
(Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx
theorem _root_.Set.Infinite.not_bddBelow {s : Set Ξ±} : s.Infinite β Β¬BddBelow s :=
mt BddBelow.finite
variable [Fintype Ξ±]
theorem filter_lt_eq_Ioi [DecidablePred (a < Β·)] : ({x | a < x} : Finset _) = Ioi a := by ext; simp
theorem filter_le_eq_Ici [DecidablePred (a β€ Β·)] : ({x | a β€ x} : Finset _) = Ici a := by ext; simp
end LocallyFiniteOrderTop
section LocallyFiniteOrderBot
variable [LocallyFiniteOrderBot Ξ±] {a : Ξ±}
theorem Iio_subset_Iic_self : Iio a β Iic a := by
simpa [β coe_subset] using Set.Iio_subset_Iic_self
theorem _root_.BddAbove.finite {s : Set Ξ±} (hs : BddAbove s) : s.Finite :=
hs.dual.finite
theorem _root_.Set.Infinite.not_bddAbove {s : Set Ξ±} : s.Infinite β Β¬BddAbove s :=
mt BddAbove.finite
variable [Fintype Ξ±]
theorem filter_gt_eq_Iio [DecidablePred (Β· < a)] : ({x | x < a} : Finset _) = Iio a := by ext; simp
theorem filter_ge_eq_Iic [DecidablePred (Β· β€ a)] : ({x | x β€ a} : Finset _) = Iic a := by ext; simp
end LocallyFiniteOrderBot
section LocallyFiniteOrder
variable [LocallyFiniteOrder Ξ±]
@[simp]
theorem Icc_bot [OrderBot Ξ±] : Icc (β₯ : Ξ±) a = Iic a := rfl
@[simp]
theorem Icc_top [OrderTop Ξ±] : Icc a (β€ : Ξ±) = Ici a := rfl
@[simp]
theorem Ico_bot [OrderBot Ξ±] : Ico (β₯ : Ξ±) a = Iio a := rfl
@[simp]
theorem Ioc_top [OrderTop Ξ±] : Ioc a (β€ : Ξ±) = Ioi a := rfl
theorem Icc_bot_top [BoundedOrder Ξ±] [Fintype Ξ±] : Icc (β₯ : Ξ±) (β€ : Ξ±) = univ := by
rw [Icc_bot, Iic_top]
end LocallyFiniteOrder
variable [LocallyFiniteOrderTop Ξ±] [LocallyFiniteOrderBot Ξ±]
theorem disjoint_Ioi_Iio (a : Ξ±) : Disjoint (Ioi a) (Iio a) :=
disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] [LocallyFiniteOrder Ξ±] {a b c : Ξ±}
@[simp]
theorem Icc_self (a : Ξ±) : Icc a a = {a} := by rw [β coe_eq_singleton, coe_Icc, Set.Icc_self]
@[simp]
theorem Icc_eq_singleton_iff : Icc a b = {c} β a = c β§ b = c := by
rw [β coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff]
theorem Ico_disjoint_Ico_consecutive (a b c : Ξ±) : Disjoint (Ico a b) (Ico b c) :=
disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1
@[simp]
theorem Ici_top [OrderTop Ξ±] : Ici (β€ : Ξ±) = {β€} := Icc_eq_singleton_iff.2 β¨rfl, rflβ©
@[simp]
theorem Iic_bot [OrderBot Ξ±] : Iic (β₯ : Ξ±) = {β₯} := Icc_eq_singleton_iff.2 β¨rfl, rflβ©
section DecidableEq
variable [DecidableEq Ξ±]
@[simp]
theorem Icc_erase_left (a b : Ξ±) : (Icc a b).erase a = Ioc a b := by simp [β coe_inj]
@[simp]
theorem Icc_erase_right (a b : Ξ±) : (Icc a b).erase b = Ico a b := by simp [β coe_inj]
@[simp]
theorem Ico_erase_left (a b : Ξ±) : (Ico a b).erase a = Ioo a b := by simp [β coe_inj]
@[simp]
theorem Ioc_erase_right (a b : Ξ±) : (Ioc a b).erase b = Ioo a b := by simp [β coe_inj]
@[simp]
theorem Icc_diff_both (a b : Ξ±) : Icc a b \ {a, b} = Ioo a b := by simp [β coe_inj]
@[simp]
theorem Ico_insert_right (h : a β€ b) : insert b (Ico a b) = Icc a b := by
rw [β coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h]
@[simp]
theorem Ioc_insert_left (h : a β€ b) : insert a (Ioc a b) = Icc a b := by
rw [β coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h]
@[simp]
theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by
rw [β coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h]
@[simp]
theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by
rw [β coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h]
@[simp]
theorem Icc_diff_Ico_self (h : a β€ b) : Icc a b \ Ico a b = {b} := by simp [β coe_inj, h]
@[simp]
theorem Icc_diff_Ioc_self (h : a β€ b) : Icc a b \ Ioc a b = {a} := by simp [β coe_inj, h]
@[simp]
theorem Icc_diff_Ioo_self (h : a β€ b) : Icc a b \ Ioo a b = {a, b} := by simp [β coe_inj, h]
@[simp]
theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [β coe_inj, h]
@[simp]
theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [β coe_inj, h]
| Mathlib/Order/Interval/Finset/Basic.lean | 608 | 608 | |
/-
Copyright (c) 2023 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Algebra.Group.Prod
/-!
# Typeclasses for power-associative structures
In this file we define power-associativity for algebraic structures with a multiplication operation.
The class is a Prop-valued mixin named `NatPowAssoc`.
## Results
- `npow_add` a defining property: `x ^ (k + n) = x ^ k * x ^ n`
- `npow_one` a defining property: `x ^ 1 = x`
- `npow_assoc` strictly positive powers of an element have associative multiplication.
- `npow_comm` `x ^ m * x ^ n = x ^ n * x ^ m` for strictly positive `m` and `n`.
- `npow_mul` `x ^ (m * n) = (x ^ m) ^ n` for strictly positive `m` and `n`.
- `npow_eq_pow` monoid exponentiation coincides with semigroup exponentiation.
## Instances
We also produce the following instances:
- `NatPowAssoc` for Monoids, Pi types and products.
## TODO
* to_additive?
-/
assert_not_exists DenselyOrdered
variable {M : Type*}
/-- A mixin for power-associative multiplication. -/
class NatPowAssoc (M : Type*) [MulOneClass M] [Pow M β] : Prop where
/-- Multiplication is power-associative. -/
protected npow_add : β (k n : β) (x : M), x ^ (k + n) = x ^ k * x ^ n
/-- Exponent zero is one. -/
protected npow_zero : β (x : M), x ^ 0 = 1
/-- Exponent one is identity. -/
protected npow_one : β (x : M), x ^ 1 = x
section MulOneClass
variable [MulOneClass M] [Pow M β] [NatPowAssoc M]
theorem npow_add (k n : β) (x : M) : x ^ (k + n) = x ^ k * x ^ n :=
NatPowAssoc.npow_add k n x
@[simp]
theorem npow_zero (x : M) : x ^ 0 = 1 :=
NatPowAssoc.npow_zero x
@[simp]
theorem npow_one (x : M) : x ^ 1 = x :=
NatPowAssoc.npow_one x
theorem npow_mul_assoc (k m n : β) (x : M) :
(x ^ k * x ^ m) * x ^ n = x ^ k * (x ^ m * x ^ n) := by
simp only [β npow_add, add_assoc]
theorem npow_mul_comm (m n : β) (x : M) :
x ^ m * x ^ n = x ^ n * x ^ m := by simp only [β npow_add, add_comm]
theorem npow_mul (x : M) (m n : β) : x ^ (m * n) = (x ^ m) ^ n := by
induction n with
| zero => rw [npow_zero, Nat.mul_zero, npow_zero]
| succ n ih => rw [mul_add, npow_add, ih, mul_one, npow_add, npow_one]
theorem npow_mul' (x : M) (m n : β) : x ^ (m * n) = (x ^ n) ^ m := by
rw [mul_comm]
exact npow_mul x n m
end MulOneClass
section Neg
theorem neg_npow_assoc {R : Type*} [NonAssocRing R] [Pow R β] [NatPowAssoc R] (a b : R) (k : β) :
(-1)^k * a * b = (-1)^k * (a * b) := by
induction k with
| zero => simp only [npow_zero, one_mul]
| succ k ih =>
rw [npow_add, npow_one, β neg_mul_comm, mul_one]
simp only [neg_mul, ih]
end Neg
instance Pi.instNatPowAssoc {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} [β i, MulOneClass <| Ξ± i] [β i, Pow (Ξ± i) β]
[β i, NatPowAssoc <| Ξ± i] : NatPowAssoc (β i, Ξ± i) where
npow_add _ _ _ := by ext; simp [npow_add]
npow_zero _ := by ext; simp
npow_one _ := by ext; simp
instance Prod.instNatPowAssoc {N : Type*} [MulOneClass M] [Pow M β] [NatPowAssoc M] [MulOneClass N]
[Pow N β] [NatPowAssoc N] : NatPowAssoc (M Γ N) where
npow_add _ _ _ := by ext <;> simp [npow_add]
npow_zero _ := by ext <;> simp
npow_one _ := by ext <;> simp
section Monoid
variable [Monoid M]
instance Monoid.PowAssoc : NatPowAssoc M where
npow_add _ _ _ := pow_add _ _ _
npow_zero _ := pow_zero _
npow_one _ := pow_one _
@[simp, norm_cast]
| theorem Nat.cast_npow (R : Type*) [NonAssocSemiring R] [Pow R β] [NatPowAssoc R] (n m : β) :
(β(n ^ m) : R) = (βn : R) ^ m := by
induction m with
| zero => simp only [pow_zero, Nat.cast_one, npow_zero]
| succ m ih => rw [npow_add, npow_add, Nat.cast_mul, ih, npow_one, npow_one]
| Mathlib/Algebra/Group/NatPowAssoc.lean | 117 | 121 |
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.FormalMultilinearSeries
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Tactic.Bound.Attribute
import Mathlib.Topology.Algebra.InfiniteSum.Module
/-!
# Analytic functions
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Ξ£ pβ zβΏ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pβ` is a continuous `n`-multilinear map. In general, `pβ` is not unique (in two
dimensions, taking `pβ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pβ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : β`.
* `p.radius`: the largest `r : ββ₯0β` such that `βp nβ * r^n` grows subexponentially.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `βp nβ * r ^ n`
is bounded above, then `r β€ p.radius`;
* `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`,
`p.isLittleO_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`βp nβ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_isBigO`: if `r β 0` and `βp nβ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partialSum n x`: the sum `β_{i = 0}^{n-1} pα΅’ xβ±`.
* `p.sum x`: the sum `β'_{i = 0}^{β} pα΅’ xβ±`.
Additionally, let `f` be a function from `E` to `F`.
* `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = β'_n pβ yβΏ`.
* `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds
`HasFPowerSeriesOnBall f p x r`.
* `AnalyticAt π f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`.
* `AnalyticOnNhd π f s`: the function `f` is analytic at every point of `s`.
We also define versions of `HasFPowerSeriesOnBall`, `AnalyticAt`, and `AnalyticOnNhd` restricted to
a set, similar to `ContinuousWithinAt`. See `Mathlib.Analysis.Analytic.Within` for basic properties.
* `AnalyticWithinAt π f s x` means a power series at `x` converges to `f` on `π[s βͺ {x}] x`.
* `AnalyticOn π f s t` means `β x β t, AnalyticWithinAt π f s x`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and
`AnalyticAt.continuousAt`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable section
variable {π E F G : Type*}
open Topology NNReal Filter ENNReal Set Asymptotics
namespace FormalMultilinearSeries
variable [Semiring π] [AddCommMonoid E] [AddCommMonoid F] [Module π E] [Module π F]
variable [TopologicalSpace E] [TopologicalSpace F]
variable [ContinuousAdd E] [ContinuousAdd F]
variable [ContinuousConstSMul π E] [ContinuousConstSMul π F]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Ξ£ pβ xβΏ`. A
priori, it only behaves well when `βxβ < p.radius`. -/
protected def sum (p : FormalMultilinearSeries π E F) (x : E) : F :=
β' n : β, p n fun _ => x
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum
`Ξ£ pβ xα΅` for `k β {0,..., n-1}`. -/
def partialSum (p : FormalMultilinearSeries π E F) (n : β) (x : E) : F :=
β k β Finset.range n, p k fun _ : Fin k => x
/-- The partial sums of a formal multilinear series are continuous. -/
theorem partialSum_continuous (p : FormalMultilinearSeries π E F) (n : β) :
Continuous (p.partialSum n) := by
unfold partialSum
fun_prop
end FormalMultilinearSeries
/-! ### The radius of a formal multilinear series -/
variable [NontriviallyNormedField π] [NormedAddCommGroup E] [NormedSpace π E] [NormedAddCommGroup F]
[NormedSpace π F] [NormedAddCommGroup G] [NormedSpace π G]
namespace FormalMultilinearSeries
variable (p : FormalMultilinearSeries π E F) {r : ββ₯0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Ξ£ βpββ βyββΏ`
converges for all `βyβ < r`. This implies that `Ξ£ pβ yβΏ` converges for all `βyβ < r`, but these
definitions are *not* equivalent in general. -/
def radius (p : FormalMultilinearSeries π E F) : ββ₯0β :=
β¨ (r : ββ₯0) (C : β) (_ : β n, βp nβ * (r : β) ^ n β€ C), (r : ββ₯0β)
/-- If `βpββ rβΏ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound (C : β) {r : ββ₯0} (h : β n : β, βp nβ * (r : β) ^ n β€ C) :
(r : ββ₯0β) β€ p.radius :=
le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ββ₯0β)) h
/-- If `βpββ rβΏ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound_nnreal (C : ββ₯0) {r : ββ₯0} (h : β n : β, βp nββ * r ^ n β€ C) :
(r : ββ₯0β) β€ p.radius :=
p.le_radius_of_bound C fun n => mod_cast h n
/-- If `βpββ rβΏ = O(1)`, as `n β β`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_isBigO (h : (fun n => βp nβ * (r : β) ^ n) =O[atTop] fun _ => (1 : β)) :
βr β€ p.radius :=
Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC =>
p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n)
theorem le_radius_of_eventually_le (C) (h : βαΆ n in atTop, βp nβ * (r : β) ^ n β€ C) :
βr β€ p.radius :=
p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa
theorem le_radius_of_summable_nnnorm (h : Summable fun n => βp nββ * r ^ n) : βr β€ p.radius :=
p.le_radius_of_bound_nnreal (β' n, βp nββ * r ^ n) fun _ => h.le_tsum' _
theorem le_radius_of_summable (h : Summable fun n => βp nβ * (r : β) ^ n) : βr β€ p.radius :=
p.le_radius_of_summable_nnnorm <| by
simp only [β coe_nnnorm] at h
exact mod_cast h
|
theorem radius_eq_top_of_forall_nnreal_isBigO
(h : β r : ββ₯0, (fun n => βp nβ * (r : β) ^ n) =O[atTop] fun _ => (1 : β)) : p.radius = β :=
| Mathlib/Analysis/Analytic/Basic.lean | 147 | 149 |
/-
Copyright (c) 2022 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.Analysis.InnerProductSpace.PiL2
/-!
# Additive Haar measure constructed from a basis
Given a basis of a finite-dimensional real vector space, we define the corresponding Lebesgue
measure, which gives measure `1` to the parallelepiped spanned by the basis.
## Main definitions
* `parallelepiped v` is the parallelepiped spanned by a finite family of vectors.
* `Basis.parallelepiped` is the parallelepiped associated to a basis, seen as a compact set with
nonempty interior.
* `Basis.addHaar` is the Lebesgue measure associated to a basis, giving measure `1` to the
corresponding parallelepiped.
In particular, we declare a `MeasureSpace` instance on any finite-dimensional inner product space,
by using the Lebesgue measure associated to some orthonormal basis (which is in fact independent
of the basis).
-/
open Set TopologicalSpace MeasureTheory MeasureTheory.Measure Module
open scoped Pointwise
noncomputable section
variable {ΞΉ ΞΉ' E F : Type*}
section Fintype
variable [Fintype ΞΉ] [Fintype ΞΉ']
section AddCommGroup
variable [AddCommGroup E] [Module β E] [AddCommGroup F] [Module β F]
/-- The closed parallelepiped spanned by a finite family of vectors. -/
def parallelepiped (v : ΞΉ β E) : Set E :=
(fun t : ΞΉ β β => β i, t i β’ v i) '' Icc 0 1
theorem mem_parallelepiped_iff (v : ΞΉ β E) (x : E) :
x β parallelepiped v β β t β Icc (0 : ΞΉ β β) 1, x = β i, t i β’ v i := by
simp [parallelepiped, eq_comm]
theorem parallelepiped_basis_eq (b : Basis ΞΉ β E) :
parallelepiped b = {x | β i, b.repr x i β Set.Icc 0 1} := by
classical
ext x
simp_rw [mem_parallelepiped_iff, mem_setOf_eq, b.ext_elem_iff, _root_.map_sum,
map_smul, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single, smul_eq_mul,
mul_one, Finsupp.single_apply, Finset.sum_ite_eq', Finset.mem_univ, ite_true, mem_Icc,
Pi.le_def, Pi.zero_apply, Pi.one_apply, β forall_and]
aesop
theorem image_parallelepiped (f : E ββ[β] F) (v : ΞΉ β E) :
f '' parallelepiped v = parallelepiped (f β v) := by
simp only [parallelepiped, β image_comp]
congr 1 with t
simp only [Function.comp_apply, _root_.map_sum, LinearMap.map_smulββ, RingHom.id_apply]
/-- Reindexing a family of vectors does not change their parallelepiped. -/
@[simp]
theorem parallelepiped_comp_equiv (v : ΞΉ β E) (e : ΞΉ' β ΞΉ) :
parallelepiped (v β e) = parallelepiped v := by
simp only [parallelepiped]
let K : (ΞΉ' β β) β (ΞΉ β β) := Equiv.piCongrLeft' (fun _a : ΞΉ' => β) e
have : Icc (0 : ΞΉ β β) 1 = K '' Icc (0 : ΞΉ' β β) 1 := by
rw [β Equiv.preimage_eq_iff_eq_image]
ext x
simp only [K, mem_preimage, mem_Icc, Pi.le_def, Pi.zero_apply, Equiv.piCongrLeft'_apply,
Pi.one_apply]
refine
β¨fun h => β¨fun i => ?_, fun i => ?_β©, fun h =>
β¨fun i => h.1 (e.symm i), fun i => h.2 (e.symm i)β©β©
Β· simpa only [Equiv.symm_apply_apply] using h.1 (e i)
Β· simpa only [Equiv.symm_apply_apply] using h.2 (e i)
rw [this, β image_comp]
congr 1 with x
have := fun z : ΞΉ' β β => e.symm.sum_comp fun i => z i β’ v (e i)
simp_rw [Equiv.apply_symm_apply] at this
simp_rw [Function.comp_apply, mem_image, mem_Icc, K, Equiv.piCongrLeft'_apply, this]
-- The parallelepiped associated to an orthonormal basis of `β` is either `[0, 1]` or `[-1, 0]`.
theorem parallelepiped_orthonormalBasis_one_dim (b : OrthonormalBasis ΞΉ β β) :
parallelepiped b = Icc 0 1 β¨ parallelepiped b = Icc (-1) 0 := by
have e : ΞΉ β Fin 1 := by
apply Fintype.equivFinOfCardEq
simp only [β finrank_eq_card_basis b.toBasis, finrank_self]
have B : parallelepiped (b.reindex e) = parallelepiped b := by
convert parallelepiped_comp_equiv b e.symm
ext i
simp only [OrthonormalBasis.coe_reindex]
rw [β B]
let F : β β Fin 1 β β := fun t => fun _i => t
have A : Icc (0 : Fin 1 β β) 1 = F '' Icc (0 : β) 1 := by
apply Subset.antisymm
Β· intro x hx
refine β¨x 0, β¨hx.1 0, hx.2 0β©, ?_β©
ext j
simp only [F, Subsingleton.elim j 0]
Β· rintro x β¨y, hy, rflβ©
exact β¨fun _j => hy.1, fun _j => hy.2β©
rcases orthonormalBasis_one_dim (b.reindex e) with (H | H)
Β· left
simp_rw [parallelepiped, H, A, Algebra.id.smul_eq_mul, mul_one]
simp only [F, Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton,
β image_comp, Function.comp_apply, image_id']
Β· right
simp_rw [H, parallelepiped, Algebra.id.smul_eq_mul, A]
simp only [F, Finset.univ_unique, Fin.default_eq_zero, mul_neg, mul_one, Finset.sum_neg_distrib,
Finset.sum_singleton, β image_comp, Function.comp, image_neg_eq_neg, neg_Icc, neg_zero]
theorem parallelepiped_eq_sum_segment (v : ΞΉ β E) : parallelepiped v = β i, segment β 0 (v i) := by
ext
simp only [mem_parallelepiped_iff, Set.mem_finset_sum, Finset.mem_univ, forall_true_left,
segment_eq_image, smul_zero, zero_add, β Set.pi_univ_Icc, Set.mem_univ_pi]
constructor
Β· rintro β¨t, ht, rflβ©
exact β¨t β’ v, fun {i} => β¨t i, ht _, by simpβ©, rflβ©
rintro β¨g, hg, rflβ©
choose t ht hg using @hg
refine β¨@t, @ht, ?_β©
simp_rw [hg]
theorem convex_parallelepiped (v : ΞΉ β E) : Convex β (parallelepiped v) := by
rw [parallelepiped_eq_sum_segment]
exact convex_sum _ fun _i _hi => convex_segment _ _
/-- A `parallelepiped` is the convex hull of its vertices -/
theorem parallelepiped_eq_convexHull (v : ΞΉ β E) :
parallelepiped v = convexHull β (β i, {(0 : E), v i}) := by
simp_rw [convexHull_sum, convexHull_pair, parallelepiped_eq_sum_segment]
/-- The axis aligned parallelepiped over `ΞΉ β β` is a cuboid. -/
theorem parallelepiped_single [DecidableEq ΞΉ] (a : ΞΉ β β) :
(parallelepiped fun i => Pi.single i (a i)) = Set.uIcc 0 a := by
ext x
simp_rw [Set.uIcc, mem_parallelepiped_iff, Set.mem_Icc, Pi.le_def, β forall_and, Pi.inf_apply,
Pi.sup_apply, β Pi.single_smul', Pi.one_apply, Pi.zero_apply, β Pi.smul_apply',
Finset.univ_sum_single (_ : ΞΉ β β)]
constructor
Β· rintro β¨t, ht, rflβ© i
specialize ht i
simp_rw [smul_eq_mul, Pi.mul_apply]
| rcases le_total (a i) 0 with hai | hai
Β· rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai]
exact β¨le_mul_of_le_one_left hai ht.2, mul_nonpos_of_nonneg_of_nonpos ht.1 haiβ©
Β· rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai]
exact β¨mul_nonneg ht.1 hai, mul_le_of_le_one_left hai ht.2β©
Β· intro h
refine β¨fun i => x i / a i, fun i => ?_, funext fun i => ?_β©
Β· specialize h i
rcases le_total (a i) 0 with hai | hai
Β· rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai] at h
exact β¨div_nonneg_of_nonpos h.2 hai, div_le_one_of_ge h.1 haiβ©
Β· rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai] at h
exact β¨div_nonneg h.1 hai, div_le_one_of_leβ h.2 haiβ©
Β· specialize h i
simp only [smul_eq_mul, Pi.mul_apply]
rcases eq_or_ne (a i) 0 with hai | hai
Β· rw [hai, inf_idem, sup_idem, β le_antisymm_iff] at h
rw [hai, β h, zero_div, zero_mul]
Β· rw [div_mul_cancelβ _ hai]
end AddCommGroup
section NormedSpace
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace β E] [NormedSpace β F]
/-- The parallelepiped spanned by a basis, as a compact set with nonempty interior. -/
def Basis.parallelepiped (b : Basis ΞΉ β E) : PositiveCompacts E where
carrier := _root_.parallelepiped b
| Mathlib/MeasureTheory/Measure/Haar/OfBasis.lean | 153 | 181 |
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.Order.Archimedean.IndicatorCard
import Mathlib.Probability.Martingale.Centering
import Mathlib.Probability.Martingale.Convergence
import Mathlib.Probability.Martingale.OptionalStopping
/-!
# Generalized Borel-Cantelli lemma
This file proves LΓ©vy's generalized Borel-Cantelli lemma which is a generalization of the
Borel-Cantelli lemmas. With this generalization, one can easily deduce the Borel-Cantelli lemmas
by choosing appropriate filtrations. This file also contains the one sided martingale bound which
is required to prove the generalized Borel-Cantelli.
**Note**: the usual Borel-Cantelli lemmas are not in this file.
See `MeasureTheory.measure_limsup_atTop_eq_zero` for the first (which does not depend on
the results here), and `ProbabilityTheory.measure_limsup_eq_one` for the second (which does).
## Main results
- `MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto`: the one sided martingale bound: given
a submartingale `f` with uniformly bounded differences, the set for which `f` converges is almost
everywhere equal to the set for which it is bounded.
- `MeasureTheory.ae_mem_limsup_atTop_iff`: LΓ©vy's generalized Borel-Cantelli:
given a filtration `β±` and a sequence of sets `s` such that `s n β β± n` for all `n`,
`limsup atTop s` is almost everywhere equal to the set for which `β β[s (n + 1)β£β± n] = β`.
-/
open Filter
open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology
namespace MeasureTheory
variable {Ξ© : Type*} {m0 : MeasurableSpace Ξ©} {ΞΌ : Measure Ξ©} {β± : Filtration β m0} {f : β β Ξ© β β}
/-!
### One sided martingale bound
-/
-- TODO: `leastGE` should be defined taking values in `WithTop β` once the `stoppedProcess`
-- refactor is complete
/-- `leastGE f r n` is the stopping time corresponding to the first time `f β₯ r`. -/
noncomputable def leastGE (f : β β Ξ© β β) (r : β) (n : β) :=
hitting f (Set.Ici r) 0 n
theorem Adapted.isStoppingTime_leastGE (r : β) (n : β) (hf : Adapted β± f) :
IsStoppingTime β± (leastGE f r n) :=
hitting_isStoppingTime hf measurableSet_Ici
theorem leastGE_le {i : β} {r : β} (Ο : Ξ©) : leastGE f r i Ο β€ i :=
hitting_le Ο
-- The following four lemmas shows `leastGE` behaves like a stopped process. Ideally we should
-- define `leastGE` as a stopping time and take its stopped process. However, we can't do that
-- with our current definition since a stopping time takes only finite indices. An upcoming
-- refactor should hopefully make it possible to have stopping times taking infinity as a value
theorem leastGE_mono {n m : β} (hnm : n β€ m) (r : β) (Ο : Ξ©) : leastGE f r n Ο β€ leastGE f r m Ο :=
hitting_mono hnm
theorem leastGE_eq_min (Ο : Ξ© β β) (r : β) (Ο : Ξ©) {n : β} (hΟn : β Ο, Ο Ο β€ n) :
leastGE f r (Ο Ο) Ο = min (Ο Ο) (leastGE f r n Ο) := by
classical
refine le_antisymm (le_min (leastGE_le _) (leastGE_mono (hΟn Ο) r Ο)) ?_
by_cases hle : Ο Ο β€ leastGE f r n Ο
Β· rw [min_eq_left hle, leastGE]
by_cases h : β j β Set.Icc 0 (Ο Ο), f j Ο β Set.Ici r
Β· refine hle.trans (Eq.le ?_)
rw [leastGE, β hitting_eq_hitting_of_exists (hΟn Ο) h]
Β· simp only [hitting, if_neg h, le_rfl]
Β· rw [min_eq_right (not_le.1 hle).le, leastGE, leastGE, β
hitting_eq_hitting_of_exists (hΟn Ο) _]
rw [not_le, leastGE, hitting_lt_iff _ (hΟn Ο)] at hle
exact
let β¨j, hjβ, hjββ© := hle
β¨j, β¨hjβ.1, hjβ.2.leβ©, hjββ©
theorem stoppedValue_stoppedValue_leastGE (f : β β Ξ© β β) (Ο : Ξ© β β) (r : β) {n : β}
(hΟn : β Ο, Ο Ο β€ n) : stoppedValue (fun i => stoppedValue f (leastGE f r i)) Ο =
stoppedValue (stoppedProcess f (leastGE f r n)) Ο := by
ext1 Ο
simp +unfoldPartialApp only [stoppedProcess, stoppedValue]
rw [leastGE_eq_min _ _ _ hΟn]
theorem Submartingale.stoppedValue_leastGE [IsFiniteMeasure ΞΌ] (hf : Submartingale f β± ΞΌ) (r : β) :
Submartingale (fun i => stoppedValue f (leastGE f r i)) β± ΞΌ := by
rw [submartingale_iff_expected_stoppedValue_mono]
Β· intro Ο Ο hΟ hΟ hΟ_le_Ο hΟ_bdd
obtain β¨n, hΟ_le_nβ© := hΟ_bdd
simp_rw [stoppedValue_stoppedValue_leastGE f Ο r fun i => (hΟ_le_Ο i).trans (hΟ_le_n i)]
simp_rw [stoppedValue_stoppedValue_leastGE f Ο r hΟ_le_n]
refine hf.expected_stoppedValue_mono ?_ ?_ ?_ fun Ο => (min_le_left _ _).trans (hΟ_le_n Ο)
Β· exact hΟ.min (hf.adapted.isStoppingTime_leastGE _ _)
Β· exact hΟ.min (hf.adapted.isStoppingTime_leastGE _ _)
Β· exact fun Ο => min_le_min (hΟ_le_Ο Ο) le_rfl
Β· exact fun i => stronglyMeasurable_stoppedValue_of_le hf.adapted.progMeasurable_of_discrete
(hf.adapted.isStoppingTime_leastGE _ _) leastGE_le
Β· exact fun i => integrable_stoppedValue _ (hf.adapted.isStoppingTime_leastGE _ _) hf.integrable
leastGE_le
variable {r : β} {R : ββ₯0}
theorem norm_stoppedValue_leastGE_le (hr : 0 β€ r) (hf0 : f 0 = 0)
(hbdd : βα΅ Ο βΞΌ, β i, |f (i + 1) Ο - f i Ο| β€ R) (i : β) :
βα΅ Ο βΞΌ, stoppedValue f (leastGE f r i) Ο β€ r + R := by
filter_upwards [hbdd] with Ο hbddΟ
change f (leastGE f r i Ο) Ο β€ r + R
by_cases heq : leastGE f r i Ο = 0
Β· rw [heq, hf0, Pi.zero_apply]
exact add_nonneg hr R.coe_nonneg
Β· obtain β¨k, hkβ© := Nat.exists_eq_succ_of_ne_zero heq
| rw [hk, add_comm, β sub_le_iff_le_add]
have := not_mem_of_lt_hitting (hk.symm βΈ k.lt_succ_self : k < leastGE f r i Ο) (zero_le _)
simp only [Set.mem_union, Set.mem_Iic, Set.mem_Ici, not_or, not_le] at this
exact (sub_lt_sub_left this _).le.trans ((le_abs_self _).trans (hbddΟ _))
theorem Submartingale.stoppedValue_leastGE_eLpNorm_le [IsFiniteMeasure ΞΌ] (hf : Submartingale f β± ΞΌ)
(hr : 0 β€ r) (hf0 : f 0 = 0) (hbdd : βα΅ Ο βΞΌ, β i, |f (i + 1) Ο - f i Ο| β€ R) (i : β) :
eLpNorm (stoppedValue f (leastGE f r i)) 1 ΞΌ β€ 2 * ΞΌ Set.univ * ENNReal.ofReal (r + R) := by
refine eLpNorm_one_le_of_le' ((hf.stoppedValue_leastGE r).integrable _) ?_
(norm_stoppedValue_leastGE_le hr hf0 hbdd i)
rw [β setIntegral_univ]
refine le_trans ?_ ((hf.stoppedValue_leastGE r).setIntegral_le (zero_le _) MeasurableSet.univ)
simp_rw [stoppedValue, leastGE, hitting_of_le le_rfl, hf0, integral_zero', le_rfl]
| Mathlib/Probability/Martingale/BorelCantelli.lean | 120 | 132 |
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne
-/
import Mathlib.Analysis.Convex.Jensen
import Mathlib.Analysis.Convex.Mul
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
/-!
# Mean value inequalities
In this file we prove several mean inequalities for finite sums. Versions for integrals of some of
these inequalities are available in `MeasureTheory.MeanInequalities`.
## Main theorems: generalized mean inequality
The inequality says that for two non-negative vectors $w$ and $z$ with $\sum_{i\in s} w_i=1$
and $p β€ q$ we have
$$
\sqrt[p]{\sum_{i\in s} w_i z_i^p} β€ \sqrt[q]{\sum_{i\in s} w_i z_i^q}.
$$
Currently we only prove this inequality for $p=1$. As in the rest of `Mathlib`, we provide
different theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents
(`zpow_arith_mean_le_arith_mean_zpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and
`arith_mean_le_rpow_mean`). In the first two cases we prove
$$
\left(\sum_{i\in s} w_i z_i\right)^n β€ \sum_{i\in s} w_i z_i^n
$$
in order to avoid using real exponents. For real exponents we prove both this and standard versions.
## TODO
- each inequality `A β€ B` should come with a theorem `A = B β _`; one of the ways to prove them
is to define `StrictConvexOn` functions.
- generalized mean inequality with any `p β€ q`, including negative numbers;
- prove that the power mean tends to the geometric mean as the exponent tends to zero.
-/
universe u v
open Finset NNReal ENNReal
noncomputable section
variable {ΞΉ : Type u} (s : Finset ΞΉ)
namespace Real
theorem pow_arith_mean_le_arith_mean_pow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i β s, w i = 1) (hz : β i β s, 0 β€ z i) (n : β) :
(β i β s, w i * z i) ^ n β€ β i β s, w i * z i ^ n :=
(convexOn_pow n).map_sum_le hw hw' hz
theorem pow_arith_mean_le_arith_mean_pow_of_even (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i β s, w i = 1) {n : β} (hn : Even n) :
(β i β s, w i * z i) ^ n β€ β i β s, w i * z i ^ n :=
hn.convexOn_pow.map_sum_le hw hw' fun _ _ => Set.mem_univ _
theorem zpow_arith_mean_le_arith_mean_zpow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i β s, w i = 1) (hz : β i β s, 0 < z i) (m : β€) :
(β i β s, w i * z i) ^ m β€ β i β s, w i * z i ^ m :=
(convexOn_zpow m).map_sum_le hw hw' hz
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i)
(hw' : β i β s, w i = 1) (hz : β i β s, 0 β€ z i) {p : β} (hp : 1 β€ p) :
(β i β s, w i * z i) ^ p β€ β i β s, w i * z i ^ p :=
(convexOn_rpow hp).map_sum_le hw hw' hz
theorem arith_mean_le_rpow_mean (w z : ΞΉ β β) (hw : β i β s, 0 β€ w i) (hw' : β i β s, w i = 1)
(hz : β i β s, 0 β€ z i) {p : β} (hp : 1 β€ p) :
β i β s, w i * z i β€ (β i β s, w i * z i ^ p) ^ (1 / p) := by
have : 0 < p := by positivity
rw [β rpow_le_rpow_iff _ _ this, β rpow_mul, one_div_mul_cancel (ne_of_gt this), rpow_one]
Β· exact rpow_arith_mean_le_arith_mean_rpow s w z hw hw' hz hp
all_goals
apply_rules [sum_nonneg, rpow_nonneg]
intro i hi
apply_rules [mul_nonneg, rpow_nonneg, hw i hi, hz i hi]
end Real
namespace NNReal
/-- Weighted generalized mean inequality, version sums over finite sets, with `ββ₯0`-valued
functions and natural exponent. -/
theorem pow_arith_mean_le_arith_mean_pow (w z : ΞΉ β ββ₯0) (hw' : β i β s, w i = 1) (n : β) :
(β i β s, w i * z i) ^ n β€ β i β s, w i * z i ^ n :=
mod_cast
Real.pow_arith_mean_le_arith_mean_pow s _ _ (fun i _ => (w i).coe_nonneg)
(mod_cast hw') (fun i _ => (z i).coe_nonneg) n
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ββ₯0`-valued
functions and real exponents. -/
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β ββ₯0) (hw' : β i β s, w i = 1) {p : β}
(hp : 1 β€ p) : (β i β s, w i * z i) ^ p β€ β i β s, w i * z i ^ p :=
mod_cast
Real.rpow_arith_mean_le_arith_mean_rpow s _ _ (fun i _ => (w i).coe_nonneg)
(mod_cast hw') (fun i _ => (z i).coe_nonneg) hp
/-- Weighted generalized mean inequality, version for two elements of `ββ₯0` and real exponents. -/
theorem rpow_arith_mean_le_arith_mean2_rpow (wβ wβ zβ zβ : ββ₯0) (hw' : wβ + wβ = 1) {p : β}
(hp : 1 β€ p) : (wβ * zβ + wβ * zβ) ^ p β€ wβ * zβ ^ p + wβ * zβ ^ p := by
have h := rpow_arith_mean_le_arith_mean_rpow univ ![wβ, wβ] ![zβ, zβ] ?_ hp
Β· simpa [Fin.sum_univ_succ] using h
Β· simp [hw', Fin.sum_univ_succ]
/-- Unweighted mean inequality, version for two elements of `ββ₯0` and real exponents. -/
theorem rpow_add_le_mul_rpow_add_rpow (zβ zβ : ββ₯0) {p : β} (hp : 1 β€ p) :
(zβ + zβ) ^ p β€ (2 : ββ₯0) ^ (p - 1) * (zβ ^ p + zβ ^ p) := by
rcases eq_or_lt_of_le hp with (rfl | h'p)
Β· simp only [rpow_one, sub_self, rpow_zero, one_mul]; rfl
convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * zβ) (2 * zβ) (add_halves 1) hp
using 1
Β· simp only [one_div, inv_mul_cancel_leftβ, Ne, mul_eq_zero, two_ne_zero, one_ne_zero,
not_false_iff]
Β· have A : p - 1 β 0 := ne_of_gt (sub_pos.2 h'p)
simp only [mul_rpow, rpow_sub' A, div_eq_inv_mul, rpow_one, mul_one]
ring
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ββ₯0`-valued
functions and real exponents. -/
theorem arith_mean_le_rpow_mean (w z : ΞΉ β ββ₯0) (hw' : β i β s, w i = 1) {p : β} (hp : 1 β€ p) :
β i β s, w i * z i β€ (β i β s, w i * z i ^ p) ^ (1 / p) :=
mod_cast
Real.arith_mean_le_rpow_mean s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw')
(fun i _ => (z i).coe_nonneg) hp
private theorem add_rpow_le_one_of_add_le_one {p : β} (a b : ββ₯0) (hab : a + b β€ 1) (hp1 : 1 β€ p) :
a ^ p + b ^ p β€ 1 := by
have h_le_one : β x : ββ₯0, x β€ 1 β x ^ p β€ x := fun x hx => rpow_le_self_of_le_one hx hp1
have ha : a β€ 1 := (self_le_add_right a b).trans hab
have hb : b β€ 1 := (self_le_add_left b a).trans hab
exact (add_le_add (h_le_one a ha) (h_le_one b hb)).trans hab
theorem add_rpow_le_rpow_add {p : β} (a b : ββ₯0) (hp1 : 1 β€ p) : a ^ p + b ^ p β€ (a + b) ^ p := by
have hp_pos : 0 < p := by positivity
by_cases h_zero : a + b = 0
Β· simp [add_eq_zero.mp h_zero, hp_pos.ne']
have h_nonzero : Β¬(a = 0 β§ b = 0) := by rwa [add_eq_zero] at h_zero
have h_add : a / (a + b) + b / (a + b) = 1 := by rw [div_add_div_same, div_self h_zero]
have h := add_rpow_le_one_of_add_le_one (a / (a + b)) (b / (a + b)) h_add.le hp1
rw [div_rpow a (a + b), div_rpow b (a + b)] at h
have hab_0 : (a + b) ^ p β 0 := by simp [hp_pos, h_nonzero]
have hab_0' : 0 < (a + b) ^ p := zero_lt_iff.mpr hab_0
have h_mul : (a + b) ^ p * (a ^ p / (a + b) ^ p + b ^ p / (a + b) ^ p) β€ (a + b) ^ p := by
nth_rw 4 [β mul_one ((a + b) ^ p)]
exact (mul_le_mul_left hab_0').mpr h
rwa [div_eq_mul_inv, div_eq_mul_inv, mul_add, mul_comm (a ^ p), mul_comm (b ^ p), β mul_assoc, β
mul_assoc, mul_inv_cancelβ hab_0, one_mul, one_mul] at h_mul
theorem rpow_add_rpow_le_add {p : β} (a b : ββ₯0) (hp1 : 1 β€ p) :
(a ^ p + b ^ p) ^ (1 / p) β€ a + b := by
rw [one_div]
rw [β @NNReal.le_rpow_inv_iff _ _ pβ»ΒΉ (by simp [lt_of_lt_of_le zero_lt_one hp1])]
rw [inv_inv]
exact add_rpow_le_rpow_add _ _ hp1
theorem rpow_add_rpow_le {p q : β} (a b : ββ₯0) (hp_pos : 0 < p) (hpq : p β€ q) :
(a ^ q + b ^ q) ^ (1 / q) β€ (a ^ p + b ^ p) ^ (1 / p) := by
have h_rpow : β a : ββ₯0, a ^ q = (a ^ p) ^ (q / p) := fun a => by
rw [β NNReal.rpow_mul, div_eq_inv_mul, β mul_assoc, mul_inv_cancelβ hp_pos.ne.symm,
one_mul]
have h_rpow_add_rpow_le_add :
((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) β€ a ^ p + b ^ p := by
refine rpow_add_rpow_le_add (a ^ p) (b ^ p) ?_
rwa [one_le_div hp_pos]
rw [h_rpow a, h_rpow b, one_div p, NNReal.le_rpow_inv_iff hp_pos, β NNReal.rpow_mul, mul_comm,
mul_one_div]
rwa [one_div_div] at h_rpow_add_rpow_le_add
theorem rpow_add_le_add_rpow {p : β} (a b : ββ₯0) (hp : 0 β€ p) (hp1 : p β€ 1) :
(a + b) ^ p β€ a ^ p + b ^ p := by
rcases hp.eq_or_lt with (rfl | hp_pos)
Β· simp
have h := rpow_add_rpow_le a b hp_pos hp1
rw [one_div_one, one_div] at h
repeat' rw [NNReal.rpow_one] at h
exact (NNReal.le_rpow_inv_iff hp_pos).mp h
end NNReal
namespace Real
lemma add_rpow_le_rpow_add {p : β} {a b : β} (ha : 0 β€ a) (hb : 0 β€ b) (hp1 : 1 β€ p) :
a ^ p + b ^ p β€ (a + b) ^ p := by
lift a to NNReal using ha
lift b to NNReal using hb
exact_mod_cast NNReal.add_rpow_le_rpow_add a b hp1
lemma rpow_add_rpow_le_add {p : β} {a b : β} (ha : 0 β€ a) (hb : 0 β€ b) (hp1 : 1 β€ p) :
(a ^ p + b ^ p) ^ (1 / p) β€ a + b := by
lift a to NNReal using ha
lift b to NNReal using hb
exact_mod_cast NNReal.rpow_add_rpow_le_add a b hp1
lemma rpow_add_rpow_le {p q : β} {a b : β} (ha : 0 β€ a) (hb : 0 β€ b) (hp_pos : 0 < p)
(hpq : p β€ q) :
(a ^ q + b ^ q) ^ (1 / q) β€ (a ^ p + b ^ p) ^ (1 / p) := by
lift a to NNReal using ha
lift b to NNReal using hb
exact_mod_cast NNReal.rpow_add_rpow_le a b hp_pos hpq
lemma rpow_add_le_add_rpow {p : β} {a b : β} (ha : 0 β€ a) (hb : 0 β€ b) (hp : 0 β€ p)
(hp1 : p β€ 1) :
(a + b) ^ p β€ a ^ p + b ^ p := by
lift a to NNReal using ha
lift b to NNReal using hb
exact_mod_cast NNReal.rpow_add_le_add_rpow a b hp hp1
end Real
namespace ENNReal
/-- Weighted generalized mean inequality, version for sums over finite sets, with `ββ₯0β`-valued
functions and real exponents. -/
theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β ββ₯0β) (hw' : β i β s, w i = 1) {p : β}
(hp : 1 β€ p) : (β i β s, w i * z i) ^ p β€ β i β s, w i * z i ^ p := by
have hp_pos : 0 < p := by positivity
have hp_nonneg : 0 β€ p := by positivity
have hp_not_neg : Β¬p < 0 := by simp [hp_nonneg]
have h_top_iff_rpow_top : β (i : ΞΉ), i β s β (w i * z i = β€ β w i * z i ^ p = β€) := by
simp [ENNReal.mul_eq_top, hp_pos, hp_nonneg, hp_not_neg]
refine le_of_top_imp_top_of_toNNReal_le ?_ ?_
Β· -- first, prove `(β i β s, w i * z i) ^ p = β€ β β i β s, (w i * z i ^ p) = β€`
rw [rpow_eq_top_iff, sum_eq_top, sum_eq_top]
intro h
simp only [and_false, hp_not_neg, false_or] at h
rcases h.left with β¨a, H, haβ©
use a, H
rwa [β h_top_iff_rpow_top a H]
Β· -- second, suppose both `(β i β s, w i * z i) ^ p β β€` and `β i β s, (w i * z i ^ p) β β€`,
-- and prove `((β i β s, w i * z i) ^ p).toNNReal β€ (β i β s, (w i * z i ^ p)).toNNReal`,
-- by using `NNReal.rpow_arith_mean_le_arith_mean_rpow`.
intro h_top_rpow_sum _
-- show hypotheses needed to put the `.toNNReal` inside the sums.
have h_top : β a : ΞΉ, a β s β w a * z a β β€ :=
haveI h_top_sum : β i β s, w i * z i β β€ := by
intro h
rw [h, top_rpow_of_pos hp_pos] at h_top_rpow_sum
exact h_top_rpow_sum rfl
fun a ha => (lt_top_of_sum_ne_top h_top_sum ha).ne
have h_top_rpow : β a : ΞΉ, a β s β w a * z a ^ p β β€ := by
intro i hi
specialize h_top i hi
rwa [Ne, β h_top_iff_rpow_top i hi]
-- put the `.toNNReal` inside the sums.
simp_rw [toNNReal_sum h_top_rpow, toNNReal_rpow, toNNReal_sum h_top, toNNReal_mul,
toNNReal_rpow]
-- use corresponding nnreal result
refine
NNReal.rpow_arith_mean_le_arith_mean_rpow s (fun i => (w i).toNNReal)
(fun i => (z i).toNNReal) ?_ hp
-- verify the hypothesis `β i β s, (w i).toNNReal = 1`, using `β i β s, w i = 1` .
have h_sum_nnreal : β i β s, w i = β(β i β s, (w i).toNNReal) := by
rw [coe_finset_sum]
refine sum_congr rfl fun i hi => (coe_toNNReal ?_).symm
refine (lt_top_of_sum_ne_top ?_ hi).ne
exact hw'.symm βΈ ENNReal.one_ne_top
rwa [β coe_inj, β h_sum_nnreal]
/-- Weighted generalized mean inequality, version for two elements of `ββ₯0β` and real
exponents. -/
theorem rpow_arith_mean_le_arith_mean2_rpow (wβ wβ zβ zβ : ββ₯0β) (hw' : wβ + wβ = 1) {p : β}
(hp : 1 β€ p) : (wβ * zβ + wβ * zβ) ^ p β€ wβ * zβ ^ p + wβ * zβ ^ p := by
have h := rpow_arith_mean_le_arith_mean_rpow univ ![wβ, wβ] ![zβ, zβ] ?_ hp
Β· simpa [Fin.sum_univ_succ] using h
Β· simp [hw', Fin.sum_univ_succ]
/-- Unweighted mean inequality, version for two elements of `ββ₯0β` and real exponents. -/
theorem rpow_add_le_mul_rpow_add_rpow (zβ zβ : ββ₯0β) {p : β} (hp : 1 β€ p) :
(zβ + zβ) ^ p β€ (2 : ββ₯0β) ^ (p - 1) * (zβ ^ p + zβ ^ p) := by
convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * zβ) (2 * zβ)
(ENNReal.add_halves 1) hp using 1
Β· simp [β mul_assoc, ENNReal.inv_mul_cancel two_ne_zero ofNat_ne_top]
Β· simp only [mul_rpow_of_nonneg _ _ (zero_le_one.trans hp), rpow_sub _ _ two_ne_zero ofNat_ne_top,
ENNReal.div_eq_inv_mul, rpow_one, mul_one]
ring
theorem add_rpow_le_rpow_add {p : β} (a b : ββ₯0β) (hp1 : 1 β€ p) : a ^ p + b ^ p β€ (a + b) ^ p := by
have hp_pos : 0 < p := by positivity
by_cases h_top : a + b = β€
Β· rw [β @ENNReal.rpow_eq_top_iff_of_pos (a + b) p hp_pos] at h_top
rw [h_top]
| exact le_top
obtain β¨ha_top, hb_topβ© := add_ne_top.mp h_top
lift a to ββ₯0 using ha_top
lift b to ββ₯0 using hb_top
simpa [ENNReal.coe_rpow_of_nonneg _ hp_pos.le] using
ENNReal.coe_le_coe.2 (NNReal.add_rpow_le_rpow_add a b hp1)
theorem rpow_add_rpow_le_add {p : β} (a b : ββ₯0β) (hp1 : 1 β€ p) :
| Mathlib/Analysis/MeanInequalitiesPow.lean | 289 | 296 |
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Analysis.Convex.Hull
import Mathlib.LinearAlgebra.AffineSpace.Basis
/-!
# Convex combinations
This file defines convex combinations of points in a vector space.
## Main declarations
* `Finset.centerMass`: Center of mass of a finite family of points.
## Implementation notes
We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way
mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few
lemmas unconditional on the sum of the weights being `1`.
-/
open Set Function Pointwise
universe u u'
section
variable {R R' E F ΞΉ ΞΉ' Ξ± : Type*} [Field R] [Field R'] [AddCommGroup E] [AddCommGroup F]
[AddCommGroup Ξ±] [LinearOrder Ξ±] [Module R E] [Module R F] [Module R Ξ±] {s : Set E}
/-- Center of mass of a finite collection of points with prescribed weights.
Note that we require neither `0 β€ w i` nor `β w = 1`. -/
def Finset.centerMass (t : Finset ΞΉ) (w : ΞΉ β R) (z : ΞΉ β E) : E :=
(β i β t, w i)β»ΒΉ β’ β i β t, w i β’ z i
variable (i j : ΞΉ) (c : R) (t : Finset ΞΉ) (w : ΞΉ β R) (z : ΞΉ β E)
open Finset
theorem Finset.centerMass_empty : (β
: Finset ΞΉ).centerMass w z = 0 := by
simp only [centerMass, sum_empty, smul_zero]
theorem Finset.centerMass_pair [DecidableEq ΞΉ] (hne : i β j) :
({i, j} : Finset ΞΉ).centerMass w z = (w i / (w i + w j)) β’ z i + (w j / (w i + w j)) β’ z j := by
simp only [centerMass, sum_pair hne]
module
variable {w}
theorem Finset.centerMass_insert [DecidableEq ΞΉ] (ha : i β t) (hw : β j β t, w j β 0) :
(insert i t).centerMass w z =
(w i / (w i + β j β t, w j)) β’ z i +
((β j β t, w j) / (w i + β j β t, w j)) β’ t.centerMass w z := by
simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, β div_eq_inv_mul]
congr 2
rw [div_mul_eq_mul_div, mul_inv_cancelβ hw, one_div]
theorem Finset.centerMass_singleton (hw : w i β 0) : ({i} : Finset ΞΉ).centerMass w z = z i := by
rw [centerMass, sum_singleton, sum_singleton]
match_scalars
field_simp
@[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by
simp [centerMass, inv_neg]
lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R]
[IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c β 0) :
t.centerMass (c β’ w) z = t.centerMass w z := by
simp [centerMass, -smul_assoc, smul_assoc c, β smul_sum, smul_invβ, smul_smul_smul_comm, hc]
theorem Finset.centerMass_eq_of_sum_1 (hw : β i β t, w i = 1) :
t.centerMass w z = β i β t, w i β’ z i := by
simp only [Finset.centerMass, hw, inv_one, one_smul]
theorem Finset.centerMass_smul : (t.centerMass w fun i => c β’ z i) = c β’ t.centerMass w z := by
simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc]
/-- A convex combination of two centers of mass is a center of mass as well. This version
deals with two different index types. -/
theorem Finset.centerMass_segment' (s : Finset ΞΉ) (t : Finset ΞΉ') (ws : ΞΉ β R) (zs : ΞΉ β E)
(wt : ΞΉ' β R) (zt : ΞΉ' β E) (hws : β i β s, ws i = 1) (hwt : β i β t, wt i = 1) (a b : R)
(hab : a + b = 1) : a β’ s.centerMass ws zs + b β’ t.centerMass wt zt = (s.disjSum t).centerMass
(Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by
rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, β
Finset.sum_sumElim, Finset.centerMass_eq_of_sum_1]
Β· congr with β¨β© <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul]
Β· rw [sum_sumElim, β mul_sum, β mul_sum, hws, hwt, mul_one, mul_one, hab]
/-- A convex combination of two centers of mass is a center of mass as well. This version
works if two centers of mass share the set of original points. -/
theorem Finset.centerMass_segment (s : Finset ΞΉ) (wβ wβ : ΞΉ β R) (z : ΞΉ β E)
(hwβ : β i β s, wβ i = 1) (hwβ : β i β s, wβ i = 1) (a b : R) (hab : a + b = 1) :
a β’ s.centerMass wβ z + b β’ s.centerMass wβ z =
s.centerMass (fun i => a * wβ i + b * wβ i) z := by
have hw : (β i β s, (a * wβ i + b * wβ i)) = 1 := by
simp only [β mul_sum, sum_add_distrib, mul_one, *]
simp only [Finset.centerMass_eq_of_sum_1, Finset.centerMass_eq_of_sum_1 _ _ hw,
smul_sum, sum_add_distrib, add_smul, mul_smul, *]
theorem Finset.centerMass_ite_eq [DecidableEq ΞΉ] (hi : i β t) :
t.centerMass (fun j => if i = j then (1 : R) else 0) z = z i := by
rw [Finset.centerMass_eq_of_sum_1]
Β· trans β j β t, if i = j then z i else 0
Β· congr with i
split_ifs with h
exacts [h βΈ one_smul _ _, zero_smul _ _]
Β· rw [sum_ite_eq, if_pos hi]
Β· rw [sum_ite_eq, if_pos hi]
variable {t}
theorem Finset.centerMass_subset {t' : Finset ΞΉ} (ht : t β t') (h : β i β t', i β t β w i = 0) :
t.centerMass w z = t'.centerMass w z := by
rw [centerMass, sum_subset ht h, smul_sum, centerMass, smul_sum]
apply sum_subset ht
intro i hit' hit
rw [h i hit' hit, zero_smul, smul_zero]
theorem Finset.centerMass_filter_ne_zero [β i, Decidable (w i β 0)] :
{i β t | w i β 0}.centerMass w z = t.centerMass w z :=
Finset.centerMass_subset z (filter_subset _ _) fun i hit hit' => by
simpa only [hit, mem_filter, true_and, Ne, Classical.not_not] using hit'
namespace Finset
variable [LinearOrder R] [IsStrictOrderedRing R] [IsOrderedAddMonoid Ξ±] [OrderedSMul R Ξ±]
theorem centerMass_le_sup {s : Finset ΞΉ} {f : ΞΉ β Ξ±} {w : ΞΉ β R} (hwβ : β i β s, 0 β€ w i)
(hwβ : 0 < β i β s, w i) :
s.centerMass w f β€ s.sup' (nonempty_of_ne_empty <| by rintro rfl; simp at hwβ) f := by
rw [centerMass, inv_smul_le_iff_of_pos hwβ, sum_smul]
exact sum_le_sum fun i hi => smul_le_smul_of_nonneg_left (le_sup' _ hi) <| hwβ i hi
theorem inf_le_centerMass {s : Finset ΞΉ} {f : ΞΉ β Ξ±} {w : ΞΉ β R} (hwβ : β i β s, 0 β€ w i)
(hwβ : 0 < β i β s, w i) :
s.inf' (nonempty_of_ne_empty <| by rintro rfl; simp at hwβ) f β€ s.centerMass w f :=
centerMass_le_sup (Ξ± := Ξ±α΅α΅) hwβ hwβ
end Finset
|
variable {z}
lemma Finset.centerMass_of_sum_add_sum_eq_zero {s t : Finset ΞΉ}
(hw : β i β s, w i + β i β t, w i = 0) (hz : β i β s, w i β’ z i + β i β t, w i β’ z i = 0) :
| Mathlib/Analysis/Convex/Combination.lean | 144 | 148 |
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Equalizers
import Mathlib.CategoryTheory.Abelian.Images
import Mathlib.CategoryTheory.Preadditive.Basic
/-!
# Every NonPreadditiveAbelian category is preadditive
In mathlib, we define an abelian category as a preadditive category with a zero object,
kernels and cokernels, products and coproducts and in which every monomorphism and epimorphism is
normal.
While virtually every interesting abelian category has a natural preadditive structure (which is why
it is included in the definition), preadditivity is not actually needed: Every category that has
all of the other properties appearing in the definition of an abelian category admits a preadditive
structure. This is the construction we carry out in this file.
The proof proceeds in roughly five steps:
1. Prove some results (for example that all equalizers exist) that would be trivial if we already
had the preadditive structure but are a bit of work without it.
2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel.
The results of the first two steps are also useful for the "normal" development of abelian
categories, and will be used there.
3. For every object `A`, define a "subtraction" morphism `Ο : A β¨― A βΆ A` and use it to define
subtraction on morphisms as `f - g := prod.lift f g β« Ο`.
4. Prove a small number of identities about this subtraction from the definition of `Ο`.
5. From these identities, prove a large number of other identities that imply that defining
`f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition
is bilinear.
The construction is non-trivial and it is quite remarkable that this abelian group structure can
be constructed purely from the existence of a few limits and colimits. Even more remarkably,
since abelian categories admit exactly one preadditive structure (see
`subsingletonPreadditiveOfHasBinaryBiproducts`), the construction manages to exactly
reconstruct any natural preadditive structure the category may have.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
noncomputable section
open CategoryTheory
open CategoryTheory.Limits
namespace CategoryTheory
section
universe v u
variable (C : Type u) [Category.{v} C]
/-- We call a category `NonPreadditiveAbelian` if it has a zero object, kernels, cokernels, binary
products and coproducts, and every monomorphism and every epimorphism is normal. -/
class NonPreadditiveAbelian extends HasZeroMorphisms C, IsNormalMonoCategory C,
IsNormalEpiCategory C where
[has_zero_object : HasZeroObject C]
[has_kernels : HasKernels C]
[has_cokernels : HasCokernels C]
[has_finite_products : HasFiniteProducts C]
[has_finite_coproducts : HasFiniteCoproducts C]
attribute [instance] NonPreadditiveAbelian.has_zero_object
attribute [instance] NonPreadditiveAbelian.has_kernels
attribute [instance] NonPreadditiveAbelian.has_cokernels
attribute [instance] NonPreadditiveAbelian.has_finite_products
attribute [instance] NonPreadditiveAbelian.has_finite_coproducts
end
end CategoryTheory
open CategoryTheory
universe v u
variable {C : Type u} [Category.{v} C] [NonPreadditiveAbelian C]
namespace CategoryTheory.NonPreadditiveAbelian
section Factor
variable {P Q : C} (f : P βΆ Q)
/-- The map `p : P βΆ image f` is an epimorphism -/
instance : Epi (Abelian.factorThruImage f) :=
let I := Abelian.image f
let p := Abelian.factorThruImage f
let i := kernel.ΞΉ (cokernel.Ο f)
-- It will suffice to consider some g : I βΆ R such that p β« g = 0 and show that g = 0.
NormalMonoCategory.epi_of_zero_cancel
_ fun R (g : I βΆ R) (hpg : p β« g = 0) => by
-- Since C is abelian, u := ker g β« i is the kernel of some morphism h.
let u := kernel.ΞΉ g β« i
haveI hu := normalMonoOfMono u
let h := hu.g
-- By hypothesis, p factors through the kernel of g via some t.
obtain β¨t, htβ© := kernel.lift' g p hpg
have fh : f β« h = 0 :=
calc
f β« h = (p β« i) β« h := (Abelian.image.fac f).symm βΈ rfl
_ = ((t β« kernel.ΞΉ g) β« i) β« h := ht βΈ rfl
_ = t β« u β« h := by simp only [u, Category.assoc]
_ = t β« 0 := hu.w βΈ rfl
_ = 0 := HasZeroMorphisms.comp_zero _ _
-- h factors through the cokernel of f via some l.
obtain β¨l, hlβ© := cokernel.desc' f h fh
have hih : i β« h = 0 :=
calc
i β« h = i β« cokernel.Ο f β« l := hl βΈ rfl
_ = 0 β« l := by rw [β Category.assoc, kernel.condition]
_ = 0 := zero_comp
-- i factors through u = ker h via some s.
obtain β¨s, hsβ© := NormalMono.lift' u i hih
have hs' : (s β« kernel.ΞΉ g) β« i = π I β« i := by rw [Category.assoc, hs, Category.id_comp]
haveI : Epi (kernel.ΞΉ g) := epi_of_epi_fac ((cancel_mono _).1 hs')
-- ker g is an epimorphism, but ker g β« g = 0 = ker g β« 0, so g = 0 as required.
exact zero_of_epi_comp _ (kernel.condition g)
instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) :=
isIso_of_mono_of_epi <| Abelian.factorThruImage f
/-- The canonical morphism `i : coimage f βΆ Q` is a monomorphism -/
instance : Mono (Abelian.factorThruCoimage f) :=
let I := Abelian.coimage f
let i := Abelian.factorThruCoimage f
let p := cokernel.Ο (kernel.ΞΉ f)
NormalEpiCategory.mono_of_cancel_zero _ fun R (g : R βΆ I) (hgi : g β« i = 0) => by
-- Since C is abelian, u := p β« coker g is the cokernel of some morphism h.
let u := p β« cokernel.Ο g
haveI hu := normalEpiOfEpi u
let h := hu.g
-- By hypothesis, i factors through the cokernel of g via some t.
obtain β¨t, htβ© := cokernel.desc' g i hgi
have hf : h β« f = 0 :=
calc
h β« f = h β« p β« i := (Abelian.coimage.fac f).symm βΈ rfl
_ = h β« p β« cokernel.Ο g β« t := ht βΈ rfl
_ = h β« u β« t := by simp only [u, Category.assoc]
_ = 0 β« t := by rw [β Category.assoc, hu.w]
_ = 0 := zero_comp
-- h factors through the kernel of f via some l.
obtain β¨l, hlβ© := kernel.lift' f h hf
have hhp : h β« p = 0 :=
calc
h β« p = (l β« kernel.ΞΉ f) β« p := hl βΈ rfl
_ = l β« 0 := by rw [Category.assoc, cokernel.condition]
_ = 0 := comp_zero
-- p factors through u = coker h via some s.
obtain β¨s, hsβ© := NormalEpi.desc' u p hhp
have hs' : p β« cokernel.Ο g β« s = p β« π I := by rw [β Category.assoc, hs, Category.comp_id]
haveI : Mono (cokernel.Ο g) := mono_of_mono_fac ((cancel_epi _).1 hs')
-- coker g is a monomorphism, but g β« coker g = 0 = 0 β« coker g, so g = 0 as required.
exact zero_of_comp_mono _ (cokernel.condition g)
instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) :=
isIso_of_mono_of_epi _
end Factor
section CokernelOfKernel
variable {X Y : C} {f : X βΆ Y}
/-- In a `NonPreadditiveAbelian` category, an epi is the cokernel of its kernel. More precisely:
If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel
of `Fork.ΞΉ s`. -/
def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) :
IsColimit (CokernelCofork.ofΟ f (KernelFork.condition s)) :=
IsCokernel.cokernelIso _ _
(cokernel.ofIsoComp _ _ (Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit _) h)
(ConeMorphism.w (Limits.IsLimit.uniqueUpToIso (limit.isLimit _) h).hom _))
(asIso <| Abelian.factorThruCoimage f) (Abelian.coimage.fac f)
/-- In a `NonPreadditiveAbelian` category, a mono is the kernel of its cokernel. More precisely:
If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel
of `Cofork.Ο s`. -/
def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) :
IsLimit (KernelFork.ofΞΉ f (CokernelCofork.condition s)) :=
IsKernel.isoKernel _ _
(kernel.ofCompIso _ _ (Limits.IsColimit.coconePointUniqueUpToIso h (colimit.isColimit _))
(CoconeMorphism.w (Limits.IsColimit.uniqueUpToIso h <| colimit.isColimit _).hom _))
(asIso <| Abelian.factorThruImage f) (Abelian.image.fac f)
end CokernelOfKernel
section
/-- The composite `A βΆ A β¨― A βΆ cokernel (Ξ A)`, where the first map is `(π A, 0)` and the second map
is the canonical projection into the cokernel. -/
abbrev r (A : C) : A βΆ cokernel (diag A) :=
prod.lift (π A) 0 β« cokernel.Ο (diag A)
instance mono_Ξ {A : C} : Mono (diag A) :=
mono_of_mono_fac <| prod.lift_fst _ _
instance mono_r {A : C} : Mono (r A) := by
let hl : IsLimit (KernelFork.ofΞΉ (diag A) (cokernel.condition (diag A))) :=
monoIsKernelOfCokernel _ (colimit.isColimit _)
apply NormalEpiCategory.mono_of_cancel_zero
intro Z x hx
have hxx : (x β« prod.lift (π A) (0 : A βΆ A)) β« cokernel.Ο (diag A) = 0 := by
rw [Category.assoc, hx]
obtain β¨y, hyβ© := KernelFork.IsLimit.lift' hl _ hxx
rw [KernelFork.ΞΉ_ofΞΉ] at hy
have hyy : y = 0 := by
erw [β Category.comp_id y, β Limits.prod.lift_snd (π A) (π A), β Category.assoc, hy,
Category.assoc, prod.lift_snd, HasZeroMorphisms.comp_zero]
haveI : Mono (prod.lift (π A) (0 : A βΆ A)) := mono_of_mono_fac (prod.lift_fst _ _)
apply (cancel_mono (prod.lift (π A) (0 : A βΆ A))).1
rw [β hy, hyy, zero_comp, zero_comp]
instance epi_r {A : C} : Epi (r A) := by
have hlp : prod.lift (π A) (0 : A βΆ A) β« Limits.prod.snd = 0 := prod.lift_snd _ _
let hp1 : IsLimit (KernelFork.ofΞΉ (prod.lift (π A) (0 : A βΆ A)) hlp) := by
refine Fork.IsLimit.mk _ (fun s => Fork.ΞΉ s β« Limits.prod.fst) ?_ ?_
Β· intro s
apply Limits.prod.hom_ext <;> simp
Β· intro s m h
haveI : Mono (prod.lift (π A) (0 : A βΆ A)) := mono_of_mono_fac (prod.lift_fst _ _)
apply (cancel_mono (prod.lift (π A) (0 : A βΆ A))).1
convert h
apply Limits.prod.hom_ext <;> simp
let hp2 : IsColimit (CokernelCofork.ofΟ (Limits.prod.snd : A β¨― A βΆ A) hlp) :=
epiIsCokernelOfKernel _ hp1
apply NormalMonoCategory.epi_of_zero_cancel
intro Z z hz
have h : prod.lift (π A) (0 : A βΆ A) β« cokernel.Ο (diag A) β« z = 0 := by rw [β Category.assoc, hz]
obtain β¨t, htβ© := CokernelCofork.IsColimit.desc' hp2 _ h
rw [CokernelCofork.Ο_ofΟ] at ht
have htt : t = 0 := by
rw [β Category.id_comp t]
change π A β« t = 0
rw [β Limits.prod.lift_snd (π A) (π A), Category.assoc, ht, β Category.assoc,
cokernel.condition, zero_comp]
apply (cancel_epi (cokernel.Ο (diag A))).1
rw [β ht, htt, comp_zero, comp_zero]
instance isIso_r {A : C} : IsIso (r A) :=
isIso_of_mono_of_epi _
/-- The composite `A β¨― A βΆ cokernel (diag A) βΆ A` given by the natural projection into the cokernel
followed by the inverse of `r`. In the category of modules, using the normal kernels and
cokernels, this map is equal to the map `(a, b) β¦ a - b`, hence the name `Ο` for
"subtraction". -/
abbrev Ο {A : C} : A β¨― A βΆ A :=
cokernel.Ο (diag A) β« inv (r A)
end
@[reassoc]
theorem diag_Ο {X : C} : diag X β« Ο = 0 := by rw [cokernel.condition_assoc, zero_comp]
@[reassoc (attr := simp)]
theorem lift_Ο {X : C} : prod.lift (π X) 0 β« Ο = π X := by rw [β Category.assoc, IsIso.hom_inv_id]
@[reassoc]
theorem lift_map {X Y : C} (f : X βΆ Y) :
prod.lift (π X) 0 β« Limits.prod.map f f = f β« prod.lift (π Y) 0 := by simp
/-- Ο is a cokernel of Ξ X. -/
def isColimitΟ {X : C} : IsColimit (CokernelCofork.ofΟ (Ο : X β¨― X βΆ X) diag_Ο) :=
cokernel.cokernelIso _ Ο (asIso (r X)).symm (by rw [Iso.symm_hom, asIso_inv])
/-- This is the key identity satisfied by `Ο`. -/
theorem Ο_comp {X Y : C} (f : X βΆ Y) : Ο β« f = Limits.prod.map f f β« Ο := by
obtain β¨g, hgβ© :=
CokernelCofork.IsColimit.desc' isColimitΟ (Limits.prod.map f f β« Ο) (by
rw [prod.diag_map_assoc, diag_Ο, comp_zero])
suffices hfg : f = g by rw [β hg, Cofork.Ο_ofΟ, hfg]
calc
f = f β« prod.lift (π Y) 0 β« Ο := by rw [lift_Ο, Category.comp_id]
_ = prod.lift (π X) 0 β« Limits.prod.map f f β« Ο := by rw [lift_map_assoc]
_ = prod.lift (π X) 0 β« Ο β« g := by rw [β hg, CokernelCofork.Ο_ofΟ]
_ = g := by rw [β Category.assoc, lift_Ο, Category.id_comp]
section
-- We write `f - g` for `prod.lift f g β« Ο`.
/-- Subtraction of morphisms in a `NonPreadditiveAbelian` category. -/
def hasSub {X Y : C} : Sub (X βΆ Y) :=
β¨fun f g => prod.lift f g β« Οβ©
attribute [local instance] hasSub
-- We write `-f` for `0 - f`.
/-- Negation of morphisms in a `NonPreadditiveAbelian` category. -/
def hasNeg {X Y : C} : Neg (X βΆ Y) where
neg := fun f => 0 - f
attribute [local instance] hasNeg
-- We write `f + g` for `f - (-g)`.
/-- Addition of morphisms in a `NonPreadditiveAbelian` category. -/
def hasAdd {X Y : C} : Add (X βΆ Y) :=
β¨fun f g => f - -gβ©
attribute [local instance] hasAdd
theorem sub_def {X Y : C} (a b : X βΆ Y) : a - b = prod.lift a b β« Ο := rfl
theorem add_def {X Y : C} (a b : X βΆ Y) : a + b = a - -b := rfl
theorem neg_def {X Y : C} (a : X βΆ Y) : -a = 0 - a := rfl
theorem sub_zero {X Y : C} (a : X βΆ Y) : a - 0 = a := by
rw [sub_def]
conv_lhs =>
congr; congr; rw [β Category.comp_id a]
case a.g => rw [show 0 = a β« (0 : Y βΆ Y) by simp]
rw [β prod.comp_lift, Category.assoc, lift_Ο, Category.comp_id]
theorem sub_self {X Y : C} (a : X βΆ Y) : a - a = 0 := by
rw [sub_def, β Category.comp_id a, β prod.comp_lift, Category.assoc, diag_Ο, comp_zero]
theorem lift_sub_lift {X Y : C} (a b c d : X βΆ Y) :
prod.lift a b - prod.lift c d = prod.lift (a - c) (b - d) := by
simp only [sub_def]
ext
Β· rw [Category.assoc, Ο_comp, prod.lift_map_assoc, prod.lift_fst, prod.lift_fst, prod.lift_fst]
Β· rw [Category.assoc, Ο_comp, prod.lift_map_assoc, prod.lift_snd, prod.lift_snd, prod.lift_snd]
theorem sub_sub_sub {X Y : C} (a b c d : X βΆ Y) : a - c - (b - d) = a - b - (c - d) := by
rw [sub_def, β lift_sub_lift, sub_def, Category.assoc, Ο_comp, prod.lift_map_assoc]; rfl
theorem neg_sub {X Y : C} (a b : X βΆ Y) : -a - b = -b - a := by
conv_lhs => rw [neg_def, β sub_zero b, sub_sub_sub, sub_zero, β neg_def]
theorem neg_neg {X Y : C} (a : X βΆ Y) : - -a = a := by
rw [neg_def, neg_def]
conv_lhs =>
congr; rw [β sub_self a]
rw [sub_sub_sub, sub_zero, sub_self, sub_zero]
theorem add_comm {X Y : C} (a b : X βΆ Y) : a + b = b + a := by
rw [add_def]
conv_lhs => rw [β neg_neg a]
rw [neg_def, neg_def, neg_def, sub_sub_sub]
conv_lhs =>
congr
next => skip
rw [β neg_def, neg_sub]
rw [sub_sub_sub, add_def, β neg_def, neg_neg b, neg_def]
theorem add_neg {X Y : C} (a b : X βΆ Y) : a + -b = a - b := by rw [add_def, neg_neg]
theorem add_neg_cancel {X Y : C} (a : X βΆ Y) : a + -a = 0 := by rw [add_neg, sub_self]
theorem neg_add_cancel {X Y : C} (a : X βΆ Y) : -a + a = 0 := by rw [add_comm, add_neg_cancel]
theorem neg_sub' {X Y : C} (a b : X βΆ Y) : -(a - b) = -a + b := by
rw [neg_def, neg_def]
conv_lhs => rw [β sub_self (0 : X βΆ Y)]
rw [sub_sub_sub, add_def, neg_def]
theorem neg_add {X Y : C} (a b : X βΆ Y) : -(a + b) = -a - b := by rw [add_def, neg_sub', add_neg]
theorem sub_add {X Y : C} (a b c : X βΆ Y) : a - b + c = a - (b - c) := by
rw [add_def, neg_def, sub_sub_sub, sub_zero]
theorem add_assoc {X Y : C} (a b c : X βΆ Y) : a + b + c = a + (b + c) := by
conv_lhs =>
congr; rw [add_def]
rw [sub_add, β add_neg, neg_sub', neg_neg]
theorem add_zero {X Y : C} (a : X βΆ Y) : a + 0 = a := by rw [add_def, neg_def, sub_self, sub_zero]
theorem comp_sub {X Y Z : C} (f : X βΆ Y) (g h : Y βΆ Z) : f β« (g - h) = f β« g - f β« h := by
rw [sub_def, β Category.assoc, prod.comp_lift, sub_def]
theorem sub_comp {X Y Z : C} (f g : X βΆ Y) (h : Y βΆ Z) : (f - g) β« h = f β« h - g β« h := by
rw [sub_def, Category.assoc, Ο_comp, β Category.assoc, prod.lift_map, sub_def]
theorem comp_add (X Y Z : C) (f : X βΆ Y) (g h : Y βΆ Z) : f β« (g + h) = f β« g + f β« h := by
rw [add_def, comp_sub, neg_def, comp_sub, comp_zero, add_def, neg_def]
theorem add_comp (X Y Z : C) (f g : X βΆ Y) (h : Y βΆ Z) : (f + g) β« h = f β« h + g β« h := by
rw [add_def, sub_comp, neg_def, sub_comp, zero_comp, add_def, neg_def]
/-- Every `NonPreadditiveAbelian` category is preadditive. -/
def preadditive : Preadditive C where
homGroup X Y :=
{ add := (Β· + Β·)
add_assoc := add_assoc
zero := 0
zero_add := neg_neg
add_zero := add_zero
neg := fun f => -f
neg_add_cancel := neg_add_cancel
sub_eq_add_neg := fun f g => (add_neg f g).symm -- Porting note: autoParam failed
add_comm := add_comm
nsmul := nsmulRec
zsmul := zsmulRec }
| add_comp := add_comp
| Mathlib/CategoryTheory/Abelian/NonPreadditive.lean | 411 | 411 |
/-
Copyright (c) 2021 Lu-Ming Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lu-Ming Zhang
-/
import Mathlib.Algebra.Group.Fin.Basic
import Mathlib.LinearAlgebra.Matrix.Symmetric
import Mathlib.Tactic.Abel
/-!
# Circulant matrices
This file contains the definition and basic results about circulant matrices.
Given a vector `v : n β Ξ±` indexed by a type that is endowed with subtraction,
`Matrix.circulant v` is the matrix whose `(i, j)`th entry is `v (i - j)`.
## Main results
- `Matrix.circulant`: the circulant matrix generated by a given vector `v : n β Ξ±`.
- `Matrix.circulant_mul`: the product of two circulant matrices `circulant v` and `circulant w` is
the circulant matrix generated by `circulant v *α΅₯ w`.
- `Matrix.circulant_mul_comm`: multiplication of circulant matrices commutes when the elements do.
## Implementation notes
`Matrix.Fin.foo` is the `Fin n` version of `Matrix.foo`.
Namely, the index type of the circulant matrices in discussion is `Fin n`.
## Tags
circulant, matrix
-/
variable {Ξ± Ξ² n R : Type*}
namespace Matrix
open Function
open Matrix
/-- Given the condition `[Sub n]` and a vector `v : n β Ξ±`,
we define `circulant v` to be the circulant matrix generated by `v` of type `Matrix n n Ξ±`.
The `(i,j)`th entry is defined to be `v (i - j)`. -/
def circulant [Sub n] (v : n β Ξ±) : Matrix n n Ξ± :=
of fun i j => v (i - j)
-- TODO: set as an equation lemma for `circulant`, see https://github.com/leanprover-community/mathlib4/pull/3024
@[simp]
theorem circulant_apply [Sub n] (v : n β Ξ±) (i j) : circulant v i j = v (i - j) := rfl
theorem circulant_col_zero_eq [SubtractionMonoid n] (v : n β Ξ±) (i : n) : circulant v i 0 = v i :=
congr_arg v (sub_zero _)
theorem circulant_injective [SubtractionMonoid n] :
Injective (circulant : (n β Ξ±) β Matrix n n Ξ±) := by
intro v w h
ext k
rw [β circulant_col_zero_eq v, β circulant_col_zero_eq w, h]
theorem Fin.circulant_injective : β n, Injective fun v : Fin n β Ξ± => circulant v
| 0 => by simp [Injective]
| _ + 1 => Matrix.circulant_injective
@[simp]
theorem circulant_inj [SubtractionMonoid n] {v w : n β Ξ±} : circulant v = circulant w β v = w :=
circulant_injective.eq_iff
@[simp]
theorem Fin.circulant_inj {n} {v w : Fin n β Ξ±} : circulant v = circulant w β v = w :=
(Fin.circulant_injective n).eq_iff
theorem transpose_circulant [SubtractionMonoid n] (v : n β Ξ±) :
(circulant v)α΅ = circulant fun i => v (-i) := by ext; simp
theorem conjTranspose_circulant [Star Ξ±] [SubtractionMonoid n] (v : n β Ξ±) :
(circulant v)α΄΄ = circulant (star fun i => v (-i)) := by ext; simp
theorem Fin.transpose_circulant : β {n} (v : Fin n β Ξ±), (circulant v)α΅ = circulant fun i => v (-i)
| 0 => by simp [Injective, eq_iff_true_of_subsingleton]
| _ + 1 => Matrix.transpose_circulant
theorem Fin.conjTranspose_circulant [Star Ξ±] :
β {n} (v : Fin n β Ξ±), (circulant v)α΄΄ = circulant (star fun i => v (-i))
| | 0 => by simp [Injective, eq_iff_true_of_subsingleton]
| _ + 1 => Matrix.conjTranspose_circulant
| Mathlib/LinearAlgebra/Matrix/Circulant.lean | 86 | 87 |
/-
Copyright (c) 2024 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.Data.Matroid.Constructions
import Mathlib.Data.Set.Notation
/-!
# Maps between matroids
This file defines maps and comaps, which move a matroid on one type to a matroid on another
using a function between the types. The constructions are (up to isomorphism)
just combinations of restrictions and parallel extensions, so are not mathematically difficult.
Because a matroid `M : Matroid Ξ±` is defined with am embedded ground set `M.E : Set Ξ±`
which contains all the structure of `M`, there are several types of map and comap
one could reasonably ask for;
for instance, we could map `M : Matroid Ξ±` to a `Matroid Ξ²` using either
a function `f : Ξ± β Ξ²`, a function `f : βM.E β Ξ²` or indeed a function `f : βM.E β βE`
for some `E : Set Ξ²`. We attempt to give definitions that capture most reasonable use cases.
`Matroid.map` and `Matroid.comap` are defined in terms of bare functions rather than
functions defined on subtypes, so are often easier to work in practice than the subtype variants.
In fact, the statement that `N = Matroid.map M f _` for some `f : Ξ± β Ξ²`
is equivalent to the existence of an isomorphism from `M` to `N`,
except in the trivial degenerate case where `M` is an empty matroid on a nonempty type and `N`
is an empty matroid on an empty type.
This can be simpler to use than an actual formal isomorphism, which requires subtypes.
## Main definitions
In the definitions below, `M` and `N` are matroids on `Ξ±` and `Ξ²` respectively.
* For `f : Ξ± β Ξ²`, `Matroid.comap N f` is the matroid on `Ξ±` with ground set `f β»ΒΉ' N.E`
in which each `I` is independent if and only if `f` is injective on `I` and
`f '' I` is independent in `N`.
(For each nonloop `x` of `N`, the set `f β»ΒΉ' {x}` is a parallel class of `N.comap f`)
* `Matroid.comapOn N f E` is the restriction of `N.comap f` to `E` for some `E : Set Ξ±`.
* For an embedding `f : M.E βͺ Ξ²` defined on the subtype `βM.E`,
`Matroid.mapSetEmbedding M f` is the matroid on `Ξ²` with ground set `range f`
whose independent sets are the images of those in `M`. This matroid is isomorphic to `M`.
* For a function `f : Ξ± β Ξ²` and a proof `hf` that `f` is injective on `M.E`,
`Matroid.map f hf` is the matroid on `Ξ²` with ground set `f '' M.E`
whose independent sets are the images of those in `M`. This matroid is isomorphic to `M`,
and does not depend on the values `f` takes outside `M.E`.
* `Matroid.mapEmbedding f` is a version of `Matroid.map` where `f : Ξ± βͺ Ξ²` is a bundled embedding.
It is defined separately because the global injectivity of `f` gives some nicer `simp` lemmas.
* `Matroid.mapEquiv f` is a version of `Matroid.map` where `f : Ξ± β Ξ²` is a bundled equivalence.
It is defined separately because we get even nicer `simp` lemmas.
* `Matroid.mapSetEquiv f` is a version of `Matroid.map` where `f : M.E β E` is an equivalence on
subtypes. It gives a matroid on `Ξ²` with ground set `E`.
* For `X : Set Ξ±`, `Matroid.restrictSubtype M X` is the `Matroid β₯X` with ground set
`univ : Set β₯X`. This matroid is isomorphic to `M βΎ X`.
## Implementation details
The definition of `comap` is the only place where we need to actually define a matroid from scratch.
After `comap` is defined, we can define `map` and its variants indirectly in terms of `comap`.
If `f : Ξ± β Ξ²` is injective on `M.E`, the independent sets of `M.map f hf` are the images of
the independent set of `M`; i.e. `(M.map f hf).Indep I β β Iβ, M.Indep Iβ β§ I = f '' Iβ`.
But if `f` is globally injective, we can phrase this more directly;
indeed, `(M.map f _).Indep I β M.Indep (f β»ΒΉ' I) β§ I β range f`.
If `f` is an equivalence we have `(M.map f _).Indep I β M.Indep (f.symm '' I)`.
In order that these stronger statements can be `@[simp]`,
we define `mapEmbedding` and `mapEquiv` separately from `map`.
## Notes
For finite matroids, both maps and comaps are a special case of a construction of
Perfect [perfect1969matroid] in which a matroid structure can be transported across an arbitrary
bipartite graph that may not correspond to a function at all (See [oxley2011], Theorem 11.2.12).
It would have been nice to use this more general construction as a basis for the definition
of both `Matroid.map` and `Matroid.comap`.
Unfortunately, we can't do this, because the construction doesn't extend to infinite matroids.
Specifically, if `Mβ` and `Mβ` are matroids on the same type `Ξ±`,
and `f` is the natural function from `Ξ± β Ξ±` to `Ξ±`,
then the images under `f` of the independent sets of the direct sum `Mβ β Mβ` are
the independent sets of a matroid if and only if the union of `Mβ` and `Mβ` is a matroid,
and unions do not exist for some pairs of infinite matroids: see [aignerhorev2012infinite].
For this reason, `Matroid.map` requires injectivity to be well-defined in general.
## TODO
* Bundled matroid isomorphisms.
* Maps of finite matroids across bipartite graphs.
## References
* [E. Aigner-Horev, J. Carmesin, J. FrΓΆhlic, Infinite Matroid Union][aignerhorev2012infinite]
* [H. Perfect, Independence Spaces and Combinatorial Problems][perfect1969matroid]
* [J. Oxley, Matroid Theory][oxley2011]
-/
assert_not_exists Field
open Set Function Set.Notation
namespace Matroid
variable {Ξ± Ξ² : Type*} {f : Ξ± β Ξ²} {E I : Set Ξ±} {M : Matroid Ξ±} {N : Matroid Ξ²}
section comap
/-- The pullback of a matroid on `Ξ²` by a function `f : Ξ± β Ξ²` to a matroid on `Ξ±`.
Elements with the same (nonloop) image are parallel and the ground set is `f β»ΒΉ' M.E`.
The matroids `M.comap f` and `M βΎ range f` have isomorphic simplifications;
the preimage of each nonloop of `M βΎ range f` is a parallel class. -/
def comap (N : Matroid Ξ²) (f : Ξ± β Ξ²) : Matroid Ξ± :=
IndepMatroid.matroid <|
{ E := f β»ΒΉ' N.E
Indep := fun I β¦ N.Indep (f '' I) β§ InjOn f I
indep_empty := by simp
indep_subset := fun _ _ h hIJ β¦ β¨h.1.subset (image_subset _ hIJ), InjOn.mono hIJ h.2β©
indep_aug := by
rintro I B β¨hI, hIinjβ© hImax hBmax
obtain β¨I', hII', hI', hI'injβ© := (not_maximal_subset_iff β¨hI, hIinjβ©).1 hImax
have hβ : Β¬(N βΎ range f).IsBase (f '' I) := by
refine fun hB β¦ hII'.ne ?_
have h_im := hB.eq_of_subset_indep (by simpa) (image_subset _ hII'.subset)
rwa [hI'inj.image_eq_image_iff hII'.subset Subset.rfl] at h_im
have hβ : (N βΎ range f).IsBase (f '' B) := by
refine Indep.isBase_of_forall_insert (by simpa using hBmax.1.1) ?_
rintro _ β¨β¨e, heB, rflβ©, hfeβ© hi
rw [restrict_indep_iff, β image_insert_eq] at hi
have hinj : InjOn f (insert e B) := by
rw [injOn_insert (fun heB β¦ hfe (mem_image_of_mem f heB))]
exact β¨hBmax.1.2, hfeβ©
refine hBmax.not_prop_of_ssuperset (t := insert e B) (ssubset_insert ?_) β¨hi.1, hinjβ©
exact fun heB β¦ hfe <| mem_image_of_mem f heB
obtain β¨_, β¨β¨e, he, rflβ©, he'β©, heiβ© := Indep.exists_insert_of_not_isBase (by simpa) hβ hβ
have heI : e β I := fun heI β¦ he' (mem_image_of_mem f heI)
rw [β image_insert_eq, restrict_indep_iff] at hei
exact β¨e, β¨he, heIβ©, hei.1, (injOn_insert heI).2 β¨hIinj, he'β©β©
indep_maximal := by
rintro X - I β¨hI, hIinjβ© hIX
obtain β¨J, hJβ© := (N βΎ range f).existsMaximalSubsetProperty_indep (f '' X) (by simp)
(f '' I) (by simpa) (image_subset _ hIX)
simp only [restrict_indep_iff, image_subset_iff, maximal_subset_iff, mem_setOf_eq, and_imp,
and_assoc] at hJ β’
obtain β¨hIJ, hJ, hJf, hJX, hJmaxβ© := hJ
obtain β¨Jβ, hIJβ, hJβX, hbjβ© := hIinj.bijOn_image.exists_extend_of_subset hIX
(image_subset f hIJ) (image_subset_iff.2 <| preimage_mono hJX)
obtain rfl : f '' Jβ = J := by rw [β image_preimage_eq_of_subset hJf, hbj.image_eq]
refine β¨Jβ, hIJβ, hJ, hbj.injOn, hJβX, fun K hK hKinj hKX hJβK β¦ ?_β©
rw [β hKinj.image_eq_image_iff hJβK Subset.rfl, hJmax hK (image_subset_range _ _)
(image_subset f hKX) (image_subset f hJβK)]
subset_ground := fun _ hI e heI β¦ hI.1.subset_ground β¨e, heI, rflβ© }
@[simp] lemma comap_indep_iff : (N.comap f).Indep I β N.Indep (f '' I) β§ InjOn f I := Iff.rfl
@[simp] lemma comap_ground_eq (N : Matroid Ξ²) (f : Ξ± β Ξ²) : (N.comap f).E = f β»ΒΉ' N.E := rfl
@[simp] lemma comap_dep_iff :
(N.comap f).Dep I β N.Dep (f '' I) β¨ (N.Indep (f '' I) β§ Β¬ InjOn f I) := by
rw [Dep, comap_indep_iff, not_and, comap_ground_eq, Dep, image_subset_iff]
refine β¨fun β¨hi, hβ© β¦ ?_, ?_β©
Β· rw [and_iff_left h, β imp_iff_not_or]
exact fun hI β¦ β¨hI, hi hIβ©
rintro (β¨hI, hIEβ© | hI)
Β· exact β¨fun h β¦ (hI h).elim, hIEβ©
rw [iff_true_intro hI.1, iff_true_intro hI.2, implies_true, true_and]
simpa using hI.1.subset_ground
@[simp] lemma comap_id (N : Matroid Ξ²) : N.comap id = N :=
ext_indep rfl <| by simp [injective_id.injOn]
lemma comap_indep_iff_of_injOn (hf : InjOn f (f β»ΒΉ' N.E)) :
(N.comap f).Indep I β N.Indep (f '' I) := by
rw [comap_indep_iff, and_iff_left_iff_imp]
refine fun hi β¦ hf.mono <| subset_trans ?_ (preimage_mono hi.subset_ground)
apply subset_preimage_image
@[simp] lemma comap_emptyOn (f : Ξ± β Ξ²) : comap (emptyOn Ξ²) f = emptyOn Ξ± := by
simp [β ground_eq_empty_iff]
@[simp] lemma comap_loopyOn (f : Ξ± β Ξ²) (E : Set Ξ²) : comap (loopyOn E) f = loopyOn (f β»ΒΉ' E) := by
rw [eq_loopyOn_iff]; aesop
@[simp] lemma comap_isBasis_iff {I X : Set Ξ±} :
(N.comap f).IsBasis I X β N.IsBasis (f '' I) (f '' X) β§ I.InjOn f β§ I β X := by
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· obtain β¨hI, hinjβ© := comap_indep_iff.1 h.indep
refine β¨hI.isBasis_of_forall_insert (image_subset f h.subset) fun e he β¦ ?_, hinj, h.subsetβ©
simp only [mem_diff, mem_image, not_exists, not_and, and_imp, forall_exists_index,
forall_apply_eq_imp_iffβ] at he
obtain β¨β¨e, heX, rflβ©, heβ© := he
have heI : e β I := fun heI β¦ (he e heI rfl)
replace h := h.insert_dep β¨heX, heIβ©
simp only [comap_dep_iff, image_insert_eq, or_iff_not_imp_right, injOn_insert heI,
hinj, mem_image, not_exists, not_and, true_and, not_forall, Classical.not_imp, not_not] at h
exact h (fun _ β¦ he)
refine Indep.isBasis_of_forall_insert ?_ h.2.2 fun e β¨heX, heIβ© β¦ ?_
Β· simp [comap_indep_iff, h.1.indep, h.2]
have hIE : insert e I β (N.comap f).E := by
simp_rw [comap_ground_eq, β image_subset_iff]
exact (image_subset _ (insert_subset heX h.2.2)).trans h.1.subset_ground
suffices N.Indep (insert (f e) (f '' I)) β β x β I, f x = f e
by simpa [β not_indep_iff hIE, injOn_insert heI, h.2.1, image_insert_eq]
exact h.1.mem_of_insert_indep (mem_image_of_mem f heX)
@[simp] lemma comap_isBase_iff {B : Set Ξ±} :
(N.comap f).IsBase B β N.IsBasis (f '' B) (f '' (f β»ΒΉ' N.E)) β§ B.InjOn f β§ B β f β»ΒΉ' N.E := by
rw [β isBasis_ground_iff, comap_isBasis_iff]; rfl
@[simp] lemma comap_isBasis'_iff {I X : Set Ξ±} :
(N.comap f).IsBasis' I X β N.IsBasis' (f '' I) (f '' X) β§ I.InjOn f β§ I β X := by
simp only [isBasis'_iff_isBasis_inter_ground, comap_ground_eq, comap_isBasis_iff,
image_inter_preimage, subset_inter_iff, β and_assoc, and_congr_left_iff, and_iff_left_iff_imp,
and_imp]
exact fun h _ _ β¦ (image_subset_iff.1 h.indep.subset_ground)
instance comap_finitary (N : Matroid Ξ²) [N.Finitary] (f : Ξ± β Ξ²) : (N.comap f).Finitary := by
refine β¨fun I hI β¦ ?_β©
rw [comap_indep_iff, indep_iff_forall_finite_subset_indep]
simp only [forall_subset_image_iff]
refine β¨fun J hJ hfin β¦ ?_,
fun x hx y hy β¦ (hI _ (pair_subset hx hy) (by simp)).2 (by simp) (by simp)β©
obtain β¨J', hJ'J, hJ'β© := (surjOn_image f J).exists_bijOn_subset
rw [β hJ'.image_eq] at hfin β’
exact (hI J' (hJ'J.trans hJ) (hfin.of_finite_image hJ'.injOn)).1
instance comap_rankFinite (N : Matroid Ξ²) [N.RankFinite] (f : Ξ± β Ξ²) : (N.comap f).RankFinite := by
obtain β¨B, hBβ© := (N.comap f).exists_isBase
refine hB.rankFinite_of_finite ?_
simp only [comap_isBase_iff] at hB
exact (hB.1.indep.finite.of_finite_image hB.2.1)
end comap
section comapOn
variable {E B I : Set Ξ±}
/-- The pullback of a matroid on `Ξ²` by a function `f : Ξ± β Ξ²` to a matroid on `Ξ±`,
restricted to a ground set `E`.
The matroids `M.comapOn f E` and `M βΎ (f '' E)` have isomorphic simplifications;
elements with the same nonloop image are parallel. -/
def comapOn (N : Matroid Ξ²) (E : Set Ξ±) (f : Ξ± β Ξ²) : Matroid Ξ± := (N.comap f) βΎ E
lemma comapOn_preimage_eq (N : Matroid Ξ²) (f : Ξ± β Ξ²) : N.comapOn (f β»ΒΉ' N.E) f = N.comap f := by
rw [comapOn, restrict_eq_self_iff]; rfl
@[simp] lemma comapOn_indep_iff :
(N.comapOn E f).Indep I β (N.Indep (f '' I) β§ InjOn f I β§ I β E) := by
simp [comapOn, and_assoc]
@[simp] lemma comapOn_ground_eq : (N.comapOn E f).E = E := rfl
lemma comapOn_isBase_iff :
(N.comapOn E f).IsBase B β N.IsBasis' (f '' B) (f '' E) β§ B.InjOn f β§ B β E := by
rw [comapOn, isBase_restrict_iff', comap_isBasis'_iff]
lemma comapOn_isBase_iff_of_surjOn (h : SurjOn f E N.E) :
(N.comapOn E f).IsBase B β (N.IsBase (f '' B) β§ InjOn f B β§ B β E) := by
simp_rw [comapOn_isBase_iff, and_congr_left_iff, and_imp, isBasis'_iff_isBasis_inter_ground,
inter_eq_self_of_subset_right h, isBasis_ground_iff, implies_true]
lemma comapOn_isBase_iff_of_bijOn (h : BijOn f E N.E) :
(N.comapOn E f).IsBase B β N.IsBase (f '' B) β§ B β E := by
rw [β and_iff_left_of_imp (IsBase.subset_ground (M := N.comapOn E f) (B := B)),
comapOn_ground_eq, and_congr_left_iff]
suffices h' : B β E β InjOn f B from fun hB β¦
by simp [hB, comapOn_isBase_iff_of_surjOn h.surjOn, h']
exact fun hBE β¦ h.injOn.mono hBE
lemma comapOn_dual_eq_of_bijOn (h : BijOn f E N.E) :
(N.comapOn E f)βΆ = NβΆ.comapOn E f := by
refine ext_isBase (by simp) (fun B hB β¦ ?_)
rw [comapOn_isBase_iff_of_bijOn (by simpa), dual_isBase_iff, comapOn_isBase_iff_of_bijOn h,
dual_isBase_iff _, comapOn_ground_eq, and_iff_left diff_subset, and_iff_left (by simpa),
h.injOn.image_diff_subset (by simpa), h.image_eq]
exact (h.mapsTo.mono_left (show B β E by simpa)).image_subset
instance comapOn_finitary [N.Finitary] : (N.comapOn E f).Finitary := by
rw [comapOn]; infer_instance
instance comapOn_rankFinite [N.RankFinite] : (N.comapOn E f).RankFinite := by
rw [comapOn]; infer_instance
end comapOn
section mapSetEmbedding
/-- Map a matroid `M` to an isomorphic copy in `Ξ²` using an embedding `M.E βͺ Ξ²`. -/
def mapSetEmbedding (M : Matroid Ξ±) (f : M.E βͺ Ξ²) : Matroid Ξ² := Matroid.ofExistsMatroid
(E := range f)
(Indep := fun I β¦ M.Indep β(f β»ΒΉ' I) β§ I β range f)
(hM := by
classical
obtain (rfl | β¨β¨e,heβ©β©) := eq_emptyOn_or_nonempty M
Β· refine β¨emptyOn Ξ², ?_β©
simp only [emptyOn_ground] at f
simp [range_eq_empty f, subset_empty_iff]
have _ : Nonempty M.E := β¨β¨e,heβ©β©
have _ : Nonempty Ξ± := β¨eβ©
refine β¨M.comapOn (range f) (fun x β¦ β(invFunOn f univ x)), rfl, ?_β©
simp_rw [comapOn_indep_iff, β and_assoc, and_congr_left_iff, subset_range_iff_exists_image_eq]
rintro _ β¨I, rflβ©
rw [β image_image, InjOn.invFunOn_image f.injective.injOn (subset_univ _),
preimage_image_eq _ f.injective, and_iff_left_iff_imp]
rintro - x hx y hy
simp only [EmbeddingLike.apply_eq_iff_eq, Subtype.val_inj]
exact (invFunOn_injOn_image f univ) (image_subset f (subset_univ I) hx)
(image_subset f (subset_univ I) hy) )
@[simp] lemma mapSetEmbedding_ground (M : Matroid Ξ±) (f : M.E βͺ Ξ²) :
(M.mapSetEmbedding f).E = range f := rfl
@[simp] lemma mapSetEmbedding_indep_iff {f : M.E βͺ Ξ²} {I : Set Ξ²} :
(M.mapSetEmbedding f).Indep I β M.Indep β(f β»ΒΉ' I) β§ I β range f := Iff.rfl
lemma Indep.exists_eq_image_of_mapSetEmbedding {f : M.E βͺ Ξ²} {I : Set Ξ²}
(hI : (M.mapSetEmbedding f).Indep I) : β (Iβ : Set M.E), M.Indep Iβ β§ I = f '' Iβ :=
β¨f β»ΒΉ' I, hI.1, Eq.symm <| image_preimage_eq_of_subset hI.2β©
lemma mapSetEmbedding_indep_iff' {f : M.E βͺ Ξ²} {I : Set Ξ²} :
(M.mapSetEmbedding f).Indep I β β (Iβ : Set M.E), M.Indep βIβ β§ I = f '' Iβ := by
simp only [mapSetEmbedding_indep_iff, subset_range_iff_exists_image_eq]
constructor
Β· rintro β¨hI, I, rflβ©
exact β¨I, by rwa [preimage_image_eq _ f.injective] at hI, rflβ©
rintro β¨I, hI, rflβ©
rw [preimage_image_eq _ f.injective]
exact β¨hI, _, rflβ©
end mapSetEmbedding
section map
/-- Given a function `f` that is injective on `M.E`, the copy of `M` in `Ξ²` whose independent sets
are the images of those in `M`. If `Ξ²` is a nonempty type, then `N : Matroid Ξ²` is a map of `M`
if and only if `M` and `N` are isomorphic. -/
def map (M : Matroid Ξ±) (f : Ξ± β Ξ²) (hf : InjOn f M.E) : Matroid Ξ² := Matroid.ofExistsMatroid
(E := f '' M.E)
(Indep := fun I β¦ β Iβ, M.Indep Iβ β§ I = f '' Iβ)
(hM := by
refine β¨M.mapSetEmbedding β¨_, hf.injectiveβ©, by simp, fun I β¦ ?_β©
simp_rw [mapSetEmbedding_indep_iff', Embedding.coeFn_mk, restrict_apply,
β image_image f Subtype.val, Subtype.exists_set_subtype (p := fun J β¦ M.Indep J β§ I = f '' J)]
exact β¨fun β¨Iβ, _, hIββ© β¦ β¨Iβ, hIββ©, fun β¨Iβ, hIββ© β¦ β¨Iβ, hIβ.1.subset_ground, hIββ©β©)
@[simp] lemma map_ground (M : Matroid Ξ±) (f : Ξ± β Ξ²) (hf) : (M.map f hf).E = f '' M.E := rfl
@[simp] lemma map_indep_iff {hf} {I : Set Ξ²} :
(M.map f hf).Indep I β β Iβ, M.Indep Iβ β§ I = f '' Iβ := Iff.rfl
lemma Indep.map (hI : M.Indep I) (f : Ξ± β Ξ²) (hf) : (M.map f hf).Indep (f '' I) :=
map_indep_iff.2 β¨I, hI, rflβ©
lemma Indep.exists_bijOn_of_map {I : Set Ξ²} (hf) (hI : (M.map f hf).Indep I) :
β Iβ, M.Indep Iβ β§ BijOn f Iβ I := by
obtain β¨Iβ, hIβ, rflβ© := hI
exact β¨Iβ, hIβ, (hf.mono hIβ.subset_ground).bijOn_imageβ©
lemma map_image_indep_iff {hf} {I : Set Ξ±} (hI : I β M.E) :
(M.map f hf).Indep (f '' I) β M.Indep I := by
rw [map_indep_iff]
refine β¨fun β¨J, hJ, hIJβ© β¦ ?_, fun h β¦ β¨I, h, rflβ©β©
rw [hf.image_eq_image_iff hI hJ.subset_ground] at hIJ; rwa [hIJ]
| @[simp] lemma map_isBase_iff (M : Matroid Ξ±) (f : Ξ± β Ξ²) (hf) {B : Set Ξ²} :
(M.map f hf).IsBase B β β Bβ, M.IsBase Bβ β§ B = f '' Bβ := by
rw [isBase_iff_maximal_indep]
refine β¨fun h β¦ ?_, ?_β©
Β· obtain β¨Bβ, hBβ, hbijβ© := h.prop.exists_bijOn_of_map
refine β¨Bβ, hBβ.isBase_of_maximal fun J hJ hBβJ β¦ ?_, hbij.image_eq.symmβ©
rw [β hf.image_eq_image_iff hBβ.subset_ground hJ.subset_ground, hbij.image_eq]
exact h.eq_of_subset (hJ.map f hf) (hbij.image_eq βΈ image_subset f hBβJ)
rintro β¨B, hB, rflβ©
rw [maximal_subset_iff]
refine β¨hB.indep.map f hf, fun I hI hBI β¦ ?_β©
obtain β¨Iβ, hIβ, hbijβ© := hI.exists_bijOn_of_map
rw [β hbij.image_eq, hf.image_subset_image_iff hB.subset_ground hIβ.subset_ground] at hBI
| Mathlib/Data/Matroid/Map.lean | 374 | 386 |
/-
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.GroupTheory.GroupAction.SubMulAction
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Pointwise monoid structures on SubMulAction
This file provides `SubMulAction.Monoid` and weaker typeclasses, which show that `SubMulAction`s
inherit the same pointwise multiplications as sets.
To match `Submodule.idemSemiring`, we do not put these in the `Pointwise` locale.
-/
open Pointwise
variable {R M : Type*}
namespace SubMulAction
section One
variable [Monoid R] [MulAction R M] [One M]
instance : One (SubMulAction R M) where
one :=
{ carrier := Set.range fun r : R => r β’ (1 : M)
smul_mem' := fun r _ β¨r', hr'β© => hr' βΈ β¨r * r', mul_smul _ _ _β© }
theorem coe_one : β(1 : SubMulAction R M) = Set.range fun r : R => r β’ (1 : M) :=
rfl
@[simp]
theorem mem_one {x : M} : x β (1 : SubMulAction R M) β β r : R, r β’ (1 : M) = x :=
Iff.rfl
theorem subset_coe_one : (1 : Set M) β (1 : SubMulAction R M) := fun _ hx =>
β¨1, (one_smul _ _).trans hx.symmβ©
end One
section Mul
variable [Monoid R] [MulAction R M] [Mul M] [IsScalarTower R M M]
instance : Mul (SubMulAction R M) where
mul p q :=
{ carrier := Set.image2 (Β· * Β·) p q
smul_mem' := fun r _ β¨mβ, hmβ, mβ, hmβ, hβ© =>
h βΈ smul_mul_assoc r mβ mβ βΈ Set.mul_mem_mul (p.smul_mem _ hmβ) hmβ }
@[norm_cast]
theorem coe_mul (p q : SubMulAction R M) : β(p * q) = (p * q : Set M) :=
rfl
theorem mem_mul {p q : SubMulAction R M} {x : M} : x β p * q β β y β p, β z β q, y * z = x :=
Set.mem_mul
end Mul
section MulOneClass
variable [Monoid R] [MulAction R M] [MulOneClass M] [IsScalarTower R M M] [SMulCommClass R M M]
-- Porting note: giving the instance the name `mulOneClass`
instance mulOneClass : MulOneClass (SubMulAction R M) where
mul := (Β· * Β·)
one := 1
mul_one a := by
ext x
simp only [mem_mul, mem_one, mul_smul_comm, exists_exists_eq_and, mul_one]
constructor
Β· rintro β¨y, hy, r, rflβ©
exact smul_mem _ _ hy
Β· intro hx
exact β¨x, hx, 1, one_smul _ _β©
one_mul a := by
ext x
simp only [mem_mul, mem_one, smul_mul_assoc, exists_exists_eq_and, one_mul]
refine β¨?_, fun hx => β¨1, x, hx, one_smul _ _β©β©
rintro β¨r, y, hy, rflβ©
exact smul_mem _ _ hy
end MulOneClass
section Semigroup
variable [Monoid R] [MulAction R M] [Semigroup M] [IsScalarTower R M M]
-- Porting note: giving the instance the name `semiGroup`
instance semiGroup : Semigroup (SubMulAction R M) where
mul := (Β· * Β·)
mul_assoc _ _ _ := SetLike.coe_injective (mul_assoc (_ : Set _) _ _)
end Semigroup
section Monoid
variable [Monoid R] [MulAction R M] [Monoid M] [IsScalarTower R M M] [SMulCommClass R M M]
instance : Monoid (SubMulAction R M) :=
{ SubMulAction.semiGroup,
SubMulAction.mulOneClass with }
theorem coe_pow (p : SubMulAction R M) : β {n : β} (_ : n β 0), β(p ^ n) = (p : Set M) ^ n
| 0, hn => (hn rfl).elim
| 1, _ => by rw [pow_one, pow_one]
| n + 2, _ => by
rw [pow_succ _ (n + 1), pow_succ _ (n + 1), coe_mul, coe_pow _ n.succ_ne_zero]
| theorem subset_coe_pow (p : SubMulAction R M) : β {n : β}, (p : Set M) ^ n β β(p ^ n)
| 0 => by
rw [pow_zero, pow_zero]
exact subset_coe_one
| n + 1 => by rw [β Nat.succ_eq_add_one, coe_pow _ n.succ_ne_zero]
| Mathlib/GroupTheory/GroupAction/SubMulAction/Pointwise.lean | 116 | 120 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes HΓΆlzl, Kim Morrison, Jens Wagemaker, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.SetTheory.Cardinal.Order
/-!
# Theory of univariate polynomials
We define the multiset of roots of a polynomial, and prove basic results about it.
## Main definitions
* `Polynomial.roots p`: The multiset containing all the roots of `p`, including their
multiplicities.
* `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`.
## Main statements
* `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its
degree, it can be written as the product of its leading coefficient with `β (X - a)` where `a`
ranges through its roots.
-/
assert_not_exists Ideal
open Multiset Finset
noncomputable section
namespace Polynomial
universe u v w z
variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : β}
section CommRing
variable [CommRing R] [IsDomain R] {p q : R[X]}
section Roots
/-- `roots p` noncomputably gives a multiset containing all the roots of `p`,
including their multiplicities. -/
noncomputable def roots (p : R[X]) : Multiset R :=
haveI := Classical.decEq R
haveI := Classical.dec (p = 0)
if h : p = 0 then β
else Classical.choose (exists_multiset_roots h)
theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] :
p.roots = if h : p = 0 then β
else Classical.choose (exists_multiset_roots h) := by
rename_i iR ip0
obtain rfl := Subsingleton.elim iR (Classical.decEq R)
obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0))
rfl
@[simp]
theorem roots_zero : (0 : R[X]).roots = 0 :=
dif_pos rfl
theorem card_roots (hp0 : p β 0) : (Multiset.card (roots p) : WithBot β) β€ degree p := by
classical
unfold roots
rw [dif_neg hp0]
exact (Classical.choose_spec (exists_multiset_roots hp0)).1
theorem card_roots' (p : R[X]) : Multiset.card p.roots β€ natDegree p := by
by_cases hp0 : p = 0
Β· simp [hp0]
exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0))
theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) :
(Multiset.card (p - C a).roots : WithBot β) β€ degree p :=
calc
(Multiset.card (p - C a).roots : WithBot β) β€ degree (p - C a) :=
card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm βΈ degree_C_le
_ = degree p := by rw [sub_eq_add_neg, β C_neg]; exact degree_add_C hp0
theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) :
Multiset.card (p - C a).roots β€ natDegree p :=
WithBot.coe_le_coe.1
(le_trans (card_roots_sub_C hp0)
(le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl]))
@[simp]
theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by
classical
by_cases hp : p = 0
Β· simp [hp]
rw [roots_def, dif_neg hp]
exact (Classical.choose_spec (exists_multiset_roots hp)).2 a
@[simp]
theorem mem_roots' : a β p.roots β p β 0 β§ IsRoot p a := by
classical
rw [β count_pos, count_roots p, rootMultiplicity_pos']
theorem mem_roots (hp : p β 0) : a β p.roots β IsRoot p a :=
mem_roots'.trans <| and_iff_right hp
theorem ne_zero_of_mem_roots (h : a β p.roots) : p β 0 :=
(mem_roots'.1 h).1
theorem isRoot_of_mem_roots (h : a β p.roots) : IsRoot p a :=
(mem_roots'.1 h).2
theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S β+* R}
(hf : Function.Injective f) {x : R} (hp : p β 0) : x β (p.map f).roots β p.evalβ f x = 0 := by
rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map]
lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p β 0) : x β roots p β aeval x p = 0 := by
rw [aeval_def, β mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w,
Algebra.id.map_eq_id, map_id]
theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val β p.roots) :
#Z β€ p.natDegree :=
(Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p)
theorem finite_setOf_isRoot {p : R[X]} (hp : p β 0) : Set.Finite { x | IsRoot p x } := by
classical
simpa only [β Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp]
using p.roots.toFinset.finite_toSet
theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 :=
not_imp_comm.mp finite_setOf_isRoot h
theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p β 0) : β xβ, β x, p.IsRoot x β x β€ xβ :=
Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp
theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p β 0) : β xβ, β x, p.IsRoot x β xβ β€ x :=
Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp
theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) :
p = q := by
rw [β sub_eq_zero]
apply eq_zero_of_infinite_isRoot
simpa only [IsRoot, eval_sub, sub_eq_zero]
theorem roots_mul {p q : R[X]} (hpq : p * q β 0) : (p * q).roots = p.roots + q.roots := by
classical
exact Multiset.ext.mpr fun r => by
rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq]
theorem roots.le_of_dvd (h : q β 0) : p β£ q β roots p β€ roots q := by
rintro β¨k, rflβ©
exact Multiset.le_iff_exists_add.mpr β¨k.roots, roots_mul hβ©
theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x β (p - C a).roots β p β C a β§ p.eval x = a := by
rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C]
theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) :
x β (p - C a).roots β p.eval x = a :=
mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm βΈ degree_C_le
@[simp]
theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by
classical
ext s
rw [count_roots, rootMultiplicity_X_sub_C, count_singleton]
@[simp]
theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r)
@[simp]
theorem roots_X : roots (X : R[X]) = {0} := by rw [β roots_X_sub_C, C_0, sub_zero]
@[simp]
theorem roots_C (x : R) : (C x).roots = 0 := by
classical exact
if H : x = 0 then by rw [H, C_0, roots_zero]
else
Multiset.ext.mpr fun r => (by
rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)])
@[simp]
theorem roots_one : (1 : R[X]).roots = β
:=
roots_C 1
@[simp]
theorem roots_C_mul (p : R[X]) (ha : a β 0) : (C a * p).roots = p.roots := by
by_cases hp : p = 0 <;>
simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C,
zero_add, mul_zero]
@[simp]
theorem roots_smul_nonzero (p : R[X]) (ha : a β 0) : (a β’ p).roots = p.roots := by
rw [smul_eq_C_mul, roots_C_mul _ ha]
@[simp]
lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by
rw [β neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)]
@[simp]
theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X - C b).roots =
{aβ»ΒΉ * b} := by
rw [β roots_C_mul _ (Units.ne_zero aβ»ΒΉ), mul_sub, β mul_assoc, β C_mul, β C_mul,
Units.inv_mul, C_1, one_mul]
exact roots_X_sub_C (aβ»ΒΉ * b)
@[simp]
theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X + C b).roots =
{-(aβ»ΒΉ * b)} := by
rw [β sub_neg_eq_add, β C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg]
theorem roots_list_prod (L : List R[X]) :
(0 : R[X]) β L β L.prod.roots = (L : Multiset R[X]).bind roots :=
List.recOn L (fun _ => roots_one) fun hd tl ih H => by
rw [List.mem_cons, not_or] at H
rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), β
Multiset.cons_coe, Multiset.cons_bind, ih H.2]
theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) β m β m.prod.roots = m.bind roots := by
rcases m with β¨Lβ©
simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L
theorem roots_prod {ΞΉ : Type*} (f : ΞΉ β R[X]) (s : Finset ΞΉ) :
s.prod f β 0 β (s.prod f).roots = s.val.bind fun i => roots (f i) := by
rcases s with β¨m, hmβ©
simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f)
@[simp]
theorem roots_pow (p : R[X]) (n : β) : (p ^ n).roots = n β’ p.roots := by
induction n with
| zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero]
| succ n ihn =>
rcases eq_or_ne p 0 with (rfl | hp)
Β· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero]
Β· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul]
theorem roots_X_pow (n : β) : (X ^ n : R[X]).roots = n β’ ({0} : Multiset R) := by
rw [roots_pow, roots_X]
theorem roots_C_mul_X_pow (ha : a β 0) (n : β) :
Polynomial.roots (C a * X ^ n) = n β’ ({0} : Multiset R) := by
rw [roots_C_mul _ ha, roots_X_pow]
@[simp]
theorem roots_monomial (ha : a β 0) (n : β) : (monomial n a).roots = n β’ ({0} : Multiset R) := by
rw [β C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha]
theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by
apply (roots_prod (fun a => X - C a) s ?_).trans
Β· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
Β· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a)
@[simp]
theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by
rw [roots_multiset_prod, Multiset.bind_map]
Β· simp_rw [roots_X_sub_C]
rw [Multiset.bind_singleton, Multiset.map_id']
Β· rw [Multiset.mem_map]
rintro β¨a, -, hβ©
exact X_sub_C_ne_zero a h
theorem card_roots_X_pow_sub_C {n : β} (hn : 0 < n) (a : R) :
Multiset.card (roots ((X : R[X]) ^ n - C a)) β€ n :=
WithBot.coe_le_coe.1 <|
calc
(Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot β) β€ degree ((X : R[X]) ^ n - C a) :=
card_roots (X_pow_sub_C_ne_zero hn a)
_ = n := degree_X_pow_sub_C hn a
section NthRoots
/-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/
def nthRoots (n : β) (a : R) : Multiset R :=
roots ((X : R[X]) ^ n - C a)
@[simp]
theorem mem_nthRoots {n : β} (hn : 0 < n) {a x : R} : x β nthRoots n a β x ^ n = a := by
rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow,
eval_X, sub_eq_zero]
@[simp]
theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by
simp only [empty_eq_zero, pow_zero, nthRoots, β C_1, β C_sub, roots_C]
@[simp]
theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : β) :
nthRoots n (0 : R) = Multiset.replicate n 0 := by
rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton]
theorem card_nthRoots (n : β) (a : R) : Multiset.card (nthRoots n a) β€ n := by
classical exact
(if hn : n = 0 then
if h : (X : R[X]) ^ n - C a = 0 then by
simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero]
else
WithBot.coe_le_coe.1
(le_trans (card_roots h)
(by
rw [hn, pow_zero, β C_1, β RingHom.map_sub]
exact degree_C_le))
else by
rw [β Nat.cast_le (Ξ± := WithBot β)]
rw [β degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a]
exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a))
@[simp]
theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 β Β¬IsSquare r := by
simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2),
β not_exists, eq_comm]
/-- The multiset `nthRoots βn a` as a Finset. Previously `nthRootsFinset n` was defined to be
`nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/
def nthRootsFinset (n : β) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R :=
haveI := Classical.decEq R
Multiset.toFinset (nthRoots n a)
lemma nthRootsFinset_def (n : β) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] :
nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by
unfold nthRootsFinset
convert rfl
@[simp]
theorem mem_nthRootsFinset {n : β} (h : 0 < n) (a : R) {x : R} :
x β nthRootsFinset n a β x ^ (n : β) = a := by
classical
rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h]
@[simp]
theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = β
:= by
classical simp [nthRootsFinset_def]
theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[MonoidHomClass F R S] {a : R} {x : R} (hx : x β nthRootsFinset n a) (f : F) :
f x β nthRootsFinset n (f a) := by
by_cases hn : n = 0
Β· simp [hn] at hx
Β· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, β map_pow, (mem_nthRootsFinset
(Nat.pos_of_ne_zero hn) a).1 hx]
theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S]
[RingHomClass F R S] {x : R} (hx : x β nthRootsFinset n 1) (f : F) :
f x β nthRootsFinset n 1 := by
rw [β (map_one f)]
exact map_mem_nthRootsFinset hx _
theorem mul_mem_nthRootsFinset
{Ξ·β Ξ·β : R} {aβ aβ : R} (hΞ·β : Ξ·β β nthRootsFinset n aβ) (hΞ·β : Ξ·β β nthRootsFinset n aβ) :
Ξ·β * Ξ·β β nthRootsFinset n (aβ * aβ) := by
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hΞ·β
| succ n =>
rw [mem_nthRootsFinset n.succ_pos] at hΞ·β hΞ·β β’
rw [mul_pow, hΞ·β, hΞ·β]
theorem ne_zero_of_mem_nthRootsFinset {Ξ· : R} {a : R} (ha : a β 0) (hΞ· : Ξ· β nthRootsFinset n a) :
Ξ· β 0 := by
nontriviality R
rintro rfl
cases n with
| zero =>
simp only [nthRootsFinset_zero, not_mem_empty] at hΞ·
| succ n =>
rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hΞ·
exact ha hΞ·.symm
theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 β nthRootsFinset n (1 : R) := by
rw [mem_nthRootsFinset hn, one_pow]
end NthRoots
theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : β x, p.eval x = 0) : p = 0 := by
classical
by_contra hp
refine @Fintype.false R _ ?_
exact β¨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))β©
theorem funext [Infinite R] {p q : R[X]} (ext : β r : R, p.eval r = q.eval r) : p = q := by
rw [β sub_eq_zero]
apply zero_of_eval_zero
intro x
rw [eval_sub, sub_eq_zero, ext]
variable [CommRing T]
/-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is
the multiset of roots of `p` regarded as a polynomial over `S`. -/
noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S :=
(p.map (algebraMap T S)).roots
theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
p.aroots S = (p.map (algebraMap T S)).roots :=
rfl
theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} :
a β p.aroots S β p.map (algebraMap T S) β 0 β§ aeval a p = 0 := by
rw [mem_roots', IsRoot.def, β evalβ_eq_eval_map, aeval_def]
theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a β p.aroots S β p β 0 β§ aeval a p = 0 := by
rw [mem_aroots', Polynomial.map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q β 0) :
(p * q).aroots S = p.aroots S + q.aroots S := by
suffices map (algebraMap T S) p * map (algebraMap T S) q β 0 by
rw [aroots_def, Polynomial.map_mul, roots_mul this]
rwa [β Polynomial.map_mul, Polynomial.map_ne_zero_iff
(FaithfulSMul.algebraMap_injective T S)]
@[simp]
theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S]
(r : T) : aroots (X - C r) S = {algebraMap T S r} := by
rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C]
@[simp]
theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] :
aroots (X : T[X]) S = {0} := by
rw [aroots_def, map_X, roots_X]
@[simp]
theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by
rw [aroots_def, map_C, roots_C]
@[simp]
theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by
rw [β C_0, aroots_C]
@[simp]
theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] :
(1 : T[X]).aroots S = 0 :=
aroots_C 1
@[simp]
theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) :
(-p).aroots S = p.aroots S := by
rw [aroots, Polynomial.map_neg, roots_neg]
@[simp]
theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β 0) :
(C a * p).aroots S = p.aroots S := by
rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul]
rwa [map_ne_zero_iff]
exact FaithfulSMul.algebraMap_injective T S
@[simp]
theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β 0) :
(a β’ p).aroots S = p.aroots S := by
rw [smul_eq_C_mul, aroots_C_mul _ ha]
@[simp]
theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : β) :
(p ^ n).aroots S = n β’ p.aroots S := by
rw [aroots_def, Polynomial.map_pow, roots_pow]
theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : β) :
(X ^ n : T[X]).aroots S = n β’ ({0} : Multiset S) := by
rw [aroots_pow, aroots_X]
theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a β 0) (n : β) :
(C a * X ^ n : T[X]).aroots S = n β’ ({0} : Multiset S) := by
rw [aroots_C_mul _ ha, aroots_X_pow]
@[simp]
theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : T} (ha : a β 0) (n : β) :
(monomial n a).aroots S = n β’ ({0} : Multiset S) := by
rw [β C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha]
variable (R S) in
@[simp]
theorem aroots_map (p : T[X]) [CommRing S] [Algebra T S] [Algebra S R] [Algebra T R]
[IsScalarTower T S R] :
(p.map (algebraMap T S)).aroots R = p.aroots R := by
rw [aroots_def, aroots_def, map_map, IsScalarTower.algebraMap_eq T S R]
/-- The set of distinct roots of `p` in `S`.
If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset
where multiple roots have the appropriate multiplicity. -/
def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S :=
haveI := Classical.decEq S
(p.aroots S).toFinset
theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] :
p.rootSet S = (p.aroots S).toFinset := by
rw [rootSet]
convert rfl
@[simp]
theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = β
:= by
classical
rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty]
@[simp]
theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = β
:= by
rw [β C_0, rootSet_C]
@[simp]
theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = β
:= by
rw [β C_1, rootSet_C]
@[simp]
theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] :
(-p).rootSet S = p.rootSet S := by
rw [rootSet, aroots_neg, rootSet]
instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
Fintype (p.rootSet S) :=
FinsetCoe.fintype _
theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] :
(p.rootSet S).Finite :=
Set.toFinite _
/-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set
is finite. -/
theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S]
(m : R β+* S) (d : β) {U : Set R} (h : U.Finite) :
(β (f : R[X]) (_ : f.natDegree β€ d β§ β i, f.coeff i β U),
((f.map m).roots.toFinset.toSet : Set S)).Finite :=
Set.Finite.biUnion
(by
-- We prove that the set of polynomials under consideration is finite because its
-- image by the injective map `Ο` is finite
let Ο : R[X] β Fin (d + 1) β R := fun f i => f.coeff i
refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn Ο _)
Β· exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i
Β· refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_
exact id congr_fun hxy β¨i, Nat.lt_succ_of_le hiβ©)
fun _ _ => Finset.finite_toSet _
theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} :
a β p.rootSet S β p.map (algebraMap T S) β 0 β§ aeval a p = 0 := by
classical
rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots']
theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] {a : S} : a β p.rootSet S β p β 0 β§ aeval a p = 0 := by
rw [mem_rootSet', Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)]
theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S]
[NoZeroSMulDivisors T S] (hp : p β 0) {a : S} : a β p.rootSet S β aeval a p = 0 :=
mem_rootSet.trans <| and_iff_right hp
theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 β p.map (algebraMap T S) = 0)
(f : S ββ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by
rw [mem_rootSet'] at hx β’
rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero]
exact β¨mt hp hx.1, rflβ©
theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(h : a β p.rootSet S) : p β 0 := fun hf => by rwa [hf, rootSet_zero] at h
theorem aeval_eq_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S}
(hx : a β p.rootSet S) : aeval a p = 0 :=
(mem_rootSet'.1 hx).2
theorem rootSet_mapsTo {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S']
[IsDomain S'] [Algebra T S'] [NoZeroSMulDivisors T S'] (f : S ββ[T] S') :
(p.rootSet S).MapsTo f (p.rootSet S') := by
refine rootSet_maps_to' (fun hβ => ?_) f
obtain rfl : p = 0 :=
map_injective _ (FaithfulSMul.algebraMap_injective T S') (by rwa [Polynomial.map_zero])
exact Polynomial.map_zero _
theorem mem_rootSet_of_injective [CommRing S] {p : S[X]} [Algebra S R]
(h : Function.Injective (algebraMap S R)) {x : R} (hp : p β 0) :
x β p.rootSet R β aeval x p = 0 := by
classical
exact Multiset.mem_toFinset.trans (mem_roots_map_of_injective h hp)
end Roots
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero {R} [CommRing R] [IsDomain R]
(p : R[X]) {ΞΉ} [Fintype ΞΉ] {f : ΞΉ β R} (hf : Function.Injective f)
(heval : β i, p.eval (f i) = 0) (hcard : natDegree p < Fintype.card ΞΉ) : p = 0 := by
classical
by_contra hp
refine lt_irrefl #p.roots.toFinset ?_
calc
#p.roots.toFinset β€ Multiset.card p.roots := Multiset.toFinset_card_le _
_ β€ natDegree p := Polynomial.card_roots' p
_ < Fintype.card ΞΉ := hcard
_ = Fintype.card (Set.range f) := (Set.card_range_of_injective hf).symm
_ = #(Finset.univ.image f) := by rw [β Set.toFinset_card, Set.toFinset_range]
_ β€ #p.roots.toFinset := Finset.card_mono ?_
intro _
simp only [Finset.mem_image, Finset.mem_univ, true_and, Multiset.mem_toFinset, mem_roots', ne_eq,
IsRoot.def, forall_exists_index, hp, not_false_eq_true]
rintro x rfl
exact heval _
lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero' {R} [CommRing R] [IsDomain R]
(p : R[X]) (s : Finset R) (heval : β i β s, p.eval i = 0) (hcard : natDegree p < #s) :
p = 0 :=
eq_zero_of_natDegree_lt_card_of_eval_eq_zero p Subtype.val_injective
(fun i : s β¦ heval i i.prop) (hcard.trans_eq (Fintype.card_coe s).symm)
open Cardinal in
lemma eq_zero_of_forall_eval_zero_of_natDegree_lt_card
(f : R[X]) (hf : β r, f.eval r = 0) (hfR : f.natDegree < #R) : f = 0 := by
obtain hR|hR := finite_or_infinite R
Β· have := Fintype.ofFinite R
apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero f Function.injective_id hf
simpa only [mk_fintype, Nat.cast_lt] using hfR
Β· exact zero_of_eval_zero _ hf
open Cardinal in
lemma exists_eval_ne_zero_of_natDegree_lt_card (f : R[X]) (hf : f β 0) (hfR : f.natDegree < #R) :
β r, f.eval r β 0 := by
contrapose! hf
exact eq_zero_of_forall_eval_zero_of_natDegree_lt_card f hf hfR
section
omit [IsDomain R]
theorem monic_multisetProd_X_sub_C (s : Multiset R) : Monic (s.map fun a => X - C a).prod :=
monic_multiset_prod_of_monic _ _ fun a _ => monic_X_sub_C a
theorem monic_prod_X_sub_C {Ξ± : Type*} (b : Ξ± β R) (s : Finset Ξ±) :
Monic (β a β s, (X - C (b a))) :=
monic_prod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
theorem monic_finprod_X_sub_C {Ξ± : Type*} (b : Ξ± β R) : Monic (βαΆ k, (X - C (b k))) :=
monic_finprod_of_monic _ _ fun a _ => monic_X_sub_C (b a)
end
theorem prod_multiset_root_eq_finset_root [DecidableEq R] :
(p.roots.map fun a => X - C a).prod =
p.roots.toFinset.prod fun a => (X - C a) ^ rootMultiplicity a p := by
simp only [count_roots, Finset.prod_multiset_map_count]
/-- The product `β (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/
theorem prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map fun a => X - C a).prod β£ p := by
classical
rw [β map_dvd_map _ (IsFractionRing.injective R <| FractionRing R)
(monic_multisetProd_X_sub_C p.roots)]
rw [prod_multiset_root_eq_finset_root, Polynomial.map_prod]
refine Finset.prod_dvd_of_coprime (fun a _ b _ h => ?_) fun a _ => ?_
Β· simp_rw [Polynomial.map_pow, Polynomial.map_sub, map_C, map_X]
exact (pairwise_coprime_X_sub_C (IsFractionRing.injective R <| FractionRing R) h).pow
Β· exact Polynomial.map_dvd _ (pow_rootMultiplicity_dvd p a)
/-- A Galois connection. -/
theorem _root_.Multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p β 0) (s : Multiset R) :
(s.map fun a => X - C a).prod β£ p β s β€ p.roots := by
classical exact
β¨fun h =>
Multiset.le_iff_count.2 fun r => by
rw [count_roots, le_rootMultiplicity_iff hp, β Multiset.prod_replicate, β
Multiset.map_replicate fun a => X - C a, β Multiset.filter_eq]
exact (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| s.filter_le _).trans h,
fun h =>
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvdβ©
theorem exists_prod_multiset_X_sub_C_mul (p : R[X]) :
β q,
(p.roots.map fun a => X - C a).prod * q = p β§
Multiset.card p.roots + q.natDegree = p.natDegree β§ q.roots = 0 := by
obtain β¨q, heβ© := p.prod_multiset_X_sub_C_dvd
use q, he.symm
obtain rfl | hq := eq_or_ne q 0
Β· rw [mul_zero] at he
subst he
simp
constructor
Β· conv_rhs => rw [he]
rw [(monic_multisetProd_X_sub_C p.roots).natDegree_mul' hq,
natDegree_multiset_prod_X_sub_C_eq_card]
Β· replace he := congr_arg roots he.symm
rw [roots_mul, roots_multiset_prod_X_sub_C] at he
exacts [add_eq_left.1 he, mul_ne_zero (monic_multisetProd_X_sub_C p.roots).ne_zero hq]
/-- A polynomial `p` that has as many roots as its degree
can be written `p = p.leadingCoeff * β(X - a)`, for `a` in `p.roots`. -/
theorem C_leadingCoeff_mul_prod_multiset_X_sub_C (hroots : Multiset.card p.roots = p.natDegree) :
C p.leadingCoeff * (p.roots.map fun a => X - C a).prod = p :=
(eq_leadingCoeff_mul_of_monic_of_dvd_of_natDegree_le (monic_multisetProd_X_sub_C p.roots)
p.prod_multiset_X_sub_C_dvd
((natDegree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm
/-- A monic polynomial `p` that has as many roots as its degree
can be written `p = β(X - a)`, for `a` in `p.roots`. -/
theorem prod_multiset_X_sub_C_of_monic_of_roots_card_eq (hp : p.Monic)
(hroots : Multiset.card p.roots = p.natDegree) : (p.roots.map fun a => X - C a).prod = p := by
convert C_leadingCoeff_mul_prod_multiset_X_sub_C hroots
rw [hp.leadingCoeff, C_1, one_mul]
theorem Monic.isUnit_leadingCoeff_of_dvd {a p : R[X]} (hp : Monic p) (hap : a β£ p) :
IsUnit a.leadingCoeff :=
isUnit_of_dvd_one (by simpa only [hp.leadingCoeff] using leadingCoeff_dvd_leadingCoeff hap)
/-- To check a monic polynomial is irreducible, it suffices to check only for
divisors that have smaller degree.
See also: `Polynomial.Monic.irreducible_iff_natDegree`.
-/
theorem Monic.irreducible_iff_degree_lt {p : R[X]} (p_monic : Monic p) (p_1 : p β 1) :
Irreducible p β β q, degree q β€ β(p.natDegree / 2) β q β£ p β IsUnit q := by
simp only [p_monic.irreducible_iff_lt_natDegree_lt p_1, Finset.mem_Ioc, and_imp,
natDegree_pos_iff_degree_pos, natDegree_le_iff_degree_le]
constructor
Β· rintro h q deg_le dvd
by_contra q_unit
have := degree_pos_of_not_isUnit_of_dvd_monic p_monic q_unit dvd
have hu := p_monic.isUnit_leadingCoeff_of_dvd dvd
refine (h _ (monic_of_isUnit_leadingCoeff_inv_smul hu) ?_ ?_ (dvd_trans ?_ dvd)).elim
Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)]
Β· rw [Units.smul_def, Polynomial.smul_eq_C_mul, (isUnit_C.mpr (Units.isUnit _)).mul_left_dvd]
Β· rintro h q _ deg_pos deg_le dvd
exact deg_pos.ne' <| degree_eq_zero_of_isUnit (h q deg_le dvd)
end CommRing
section
variable {A B : Type*} [CommRing A] [CommRing B]
theorem le_rootMultiplicity_map {p : A[X]} {f : A β+* B} (hmap : map f p β 0) (a : A) :
rootMultiplicity a p β€ rootMultiplicity (f a) (p.map f) := by
rw [le_rootMultiplicity_iff hmap]
refine _root_.trans ?_ ((mapRingHom f).map_dvd (pow_rootMultiplicity_dvd p a))
rw [map_pow, map_sub, coe_mapRingHom, map_X, map_C]
theorem eq_rootMultiplicity_map {p : A[X]} {f : A β+* B} (hf : Function.Injective f) (a : A) :
rootMultiplicity a p = rootMultiplicity (f a) (p.map f) := by
by_cases hp0 : p = 0; Β· simp only [hp0, rootMultiplicity_zero, Polynomial.map_zero]
apply le_antisymm (le_rootMultiplicity_map ((Polynomial.map_ne_zero_iff hf).mpr hp0) a)
rw [le_rootMultiplicity_iff hp0, β map_dvd_map f hf ((monic_X_sub_C a).pow _),
Polynomial.map_pow, Polynomial.map_sub, map_X, map_C]
apply pow_rootMultiplicity_dvd
theorem count_map_roots [IsDomain A] [DecidableEq B] {p : A[X]} {f : A β+* B} (hmap : map f p β 0)
(b : B) :
(p.roots.map f).count b β€ rootMultiplicity b (p.map f) := by
rw [le_rootMultiplicity_iff hmap, β Multiset.prod_replicate, β
Multiset.map_replicate fun a => X - C a]
rw [β Multiset.filter_eq]
refine
(Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| Multiset.filter_le (Eq b) _).trans ?_
convert Polynomial.map_dvd f p.prod_multiset_X_sub_C_dvd
simp only [Polynomial.map_multiset_prod, Multiset.map_map]
congr; ext1
simp only [Function.comp_apply, Polynomial.map_sub, map_X, map_C]
theorem count_map_roots_of_injective [IsDomain A] [DecidableEq B] (p : A[X]) {f : A β+* B}
(hf : Function.Injective f) (b : B) :
(p.roots.map f).count b β€ rootMultiplicity b (p.map f) := by
by_cases hp0 : p = 0
Β· simp only [hp0, roots_zero, Multiset.map_zero, Multiset.count_zero, Polynomial.map_zero,
rootMultiplicity_zero, le_refl]
Β· exact count_map_roots ((Polynomial.map_ne_zero_iff hf).mpr hp0) b
theorem map_roots_le [IsDomain A] [IsDomain B] {p : A[X]} {f : A β+* B} (h : p.map f β 0) :
p.roots.map f β€ (p.map f).roots := by
classical
exact Multiset.le_iff_count.2 fun b => by
rw [count_roots]
apply count_map_roots h
theorem map_roots_le_of_injective [IsDomain A] [IsDomain B] (p : A[X]) {f : A β+* B}
(hf : Function.Injective f) : p.roots.map f β€ (p.map f).roots := by
by_cases hp0 : p = 0
Β· simp only [hp0, roots_zero, Multiset.map_zero, Polynomial.map_zero, le_rfl]
exact map_roots_le ((Polynomial.map_ne_zero_iff hf).mpr hp0)
theorem card_roots_le_map [IsDomain A] [IsDomain B] {p : A[X]} {f : A β+* B} (h : p.map f β 0) :
Multiset.card p.roots β€ Multiset.card (p.map f).roots := by
rw [β p.roots.card_map f]
exact Multiset.card_le_card (map_roots_le h)
theorem card_roots_le_map_of_injective [IsDomain A] [IsDomain B] {p : A[X]} {f : A β+* B}
(hf : Function.Injective f) : Multiset.card p.roots β€ Multiset.card (p.map f).roots := by
by_cases hp0 : p = 0
Β· simp only [hp0, roots_zero, Polynomial.map_zero, Multiset.card_zero, le_rfl]
exact card_roots_le_map ((Polynomial.map_ne_zero_iff hf).mpr hp0)
theorem roots_map_of_injective_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]}
{f : A β+* B} (hf : Function.Injective f) (hroots : Multiset.card p.roots = p.natDegree) :
p.roots.map f = (p.map f).roots := by
apply Multiset.eq_of_le_of_card_le (map_roots_le_of_injective p hf)
simpa only [Multiset.card_map, hroots] using (card_roots' _).trans natDegree_map_le
theorem roots_map_of_map_ne_zero_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]}
(f : A β+* B) (h : p.map f β 0) (hroots : p.roots.card = p.natDegree) :
p.roots.map f = (p.map f).roots :=
eq_of_le_of_card_le (map_roots_le h) <| by
simpa only [Multiset.card_map, hroots] using (p.map f).card_roots'.trans natDegree_map_le
theorem Monic.roots_map_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]} (hm : p.Monic)
(f : A β+* B) (hroots : p.roots.card = p.natDegree) : p.roots.map f = (p.map f).roots :=
roots_map_of_map_ne_zero_of_card_eq_natDegree f (map_monic_ne_zero hm) hroots
end
end Polynomial
| Mathlib/Algebra/Polynomial/Roots.lean | 812 | 816 | |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Group.Nat.Even
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Data.Nat.Cast.Commute
import Mathlib.Data.Set.Operations
import Mathlib.Logic.Function.Iterate
/-!
# Even and odd elements in rings
This file defines odd elements and proves some general facts about even and odd elements of rings.
As opposed to `Even`, `Odd` does not have a multiplicative counterpart.
## TODO
Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring`
assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved
to `Mathlib.Algebra.Group.Even`.
## See also
`Mathlib.Algebra.Group.Even` for the definition of even elements.
-/
assert_not_exists DenselyOrdered OrderedRing
open MulOpposite
variable {F Ξ± Ξ² : Type*}
section Monoid
variable [Monoid Ξ±] [HasDistribNeg Ξ±] {n : β} {a : Ξ±}
@[simp] lemma Even.neg_pow : Even n β β a : Ξ±, (-a) ^ n = a ^ n := by
rintro β¨c, rflβ© a
simp_rw [β two_mul, pow_mul, neg_sq]
lemma Even.neg_one_pow (h : Even n) : (-1 : Ξ±) ^ n = 1 := by rw [h.neg_pow, one_pow]
end Monoid
section DivisionMonoid
variable [DivisionMonoid Ξ±] [HasDistribNeg Ξ±] {a : Ξ±} {n : β€}
lemma Even.neg_zpow : Even n β β a : Ξ±, (-a) ^ n = a ^ n := by
rintro β¨c, rflβ© a; simp_rw [β Int.two_mul, zpow_mul, zpow_two, neg_mul_neg]
lemma Even.neg_one_zpow (h : Even n) : (-1 : Ξ±) ^ n = 1 := by rw [h.neg_zpow, one_zpow]
end DivisionMonoid
@[simp] lemma IsSquare.zero [MulZeroClass Ξ±] : IsSquare (0 : Ξ±) := β¨0, (mul_zero _).symmβ©
section Semiring
variable [Semiring Ξ±] [Semiring Ξ²] {a b : Ξ±} {m n : β}
lemma even_iff_exists_two_mul : Even a β β b, a = 2 * b := by simp [even_iff_exists_two_nsmul]
lemma even_iff_two_dvd : Even a β 2 β£ a := by simp [Even, Dvd.dvd, two_mul]
alias β¨Even.two_dvd, _β© := even_iff_two_dvd
lemma Even.trans_dvd (ha : Even a) (hab : a β£ b) : Even b :=
| even_iff_two_dvd.2 <| ha.two_dvd.trans hab
| Mathlib/Algebra/Ring/Parity.lean | 69 | 69 |
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang
-/
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.Algebra.Pi
import Mathlib.Algebra.BigOperators.RingEquiv
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Matrix.Mul
import Mathlib.LinearAlgebra.Pi
/-!
# Matrices
This file contains basic results on matrices including bundled versions of matrix operators.
## Implementation notes
For convenience, `Matrix m n Ξ±` is defined as `m β n β Ξ±`, as this allows elements of the matrix
to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the
form `fun i j β¦ _` or even `(fun i j β¦ _ : Matrix m n Ξ±)`, as these are not recognized by Lean
as having the right type. Instead, `Matrix.of` should be used.
## TODO
Under various conditions, multiplication of infinite matrices makes sense.
These have not yet been implemented.
-/
assert_not_exists Star
universe u u' v w
variable {l m n o : Type*} {m' : o β Type*} {n' : o β Type*}
variable {R : Type*} {S : Type*} {Ξ± : Type v} {Ξ² : Type w} {Ξ³ : Type*}
namespace Matrix
instance decidableEq [DecidableEq Ξ±] [Fintype m] [Fintype n] : DecidableEq (Matrix m n Ξ±) :=
Fintype.decidablePiFintype
instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (Ξ±) [Fintype Ξ±] :
Fintype (Matrix m n Ξ±) := inferInstanceAs (Fintype (m β n β Ξ±))
instance {n m} [Finite m] [Finite n] (Ξ±) [Finite Ξ±] :
Finite (Matrix m n Ξ±) := inferInstanceAs (Finite (m β n β Ξ±))
section
variable (R)
/-- This is `Matrix.of` bundled as a linear equivalence. -/
def ofLinearEquiv [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : (m β n β Ξ±) ββ[R] Matrix m n Ξ± where
__ := ofAddEquiv
map_smul' _ _ := rfl
@[simp] lemma coe_ofLinearEquiv [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] :
β(ofLinearEquiv _ : (m β n β Ξ±) ββ[R] Matrix m n Ξ±) = of := rfl
@[simp] lemma coe_ofLinearEquiv_symm [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] :
β((ofLinearEquiv _).symm : Matrix m n Ξ± ββ[R] (m β n β Ξ±)) = of.symm := rfl
end
theorem sum_apply [AddCommMonoid Ξ±] (i : m) (j : n) (s : Finset Ξ²) (g : Ξ² β Matrix m n Ξ±) :
(β c β s, g c) i j = β c β s, g c i j :=
(congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _)
end Matrix
open Matrix
namespace Matrix
section Diagonal
variable [DecidableEq n]
variable (n Ξ±)
/-- `Matrix.diagonal` as an `AddMonoidHom`. -/
@[simps]
def diagonalAddMonoidHom [AddZeroClass Ξ±] : (n β Ξ±) β+ Matrix n n Ξ± where
toFun := diagonal
map_zero' := diagonal_zero
map_add' x y := (diagonal_add x y).symm
variable (R)
/-- `Matrix.diagonal` as a `LinearMap`. -/
@[simps]
def diagonalLinearMap [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : (n β Ξ±) ββ[R] Matrix n n Ξ± :=
{ diagonalAddMonoidHom n Ξ± with map_smul' := diagonal_smul }
variable {n Ξ± R}
section One
variable [Zero Ξ±] [One Ξ±]
lemma zero_le_one_elem [Preorder Ξ±] [ZeroLEOneClass Ξ±] (i j : n) :
0 β€ (1 : Matrix n n Ξ±) i j := by
by_cases hi : i = j
Β· subst hi
simp
Β· simp [hi]
lemma zero_le_one_row [Preorder Ξ±] [ZeroLEOneClass Ξ±] (i : n) :
0 β€ (1 : Matrix n n Ξ±) i :=
zero_le_one_elem i
end One
end Diagonal
section Diag
variable (n Ξ±)
/-- `Matrix.diag` as an `AddMonoidHom`. -/
@[simps]
def diagAddMonoidHom [AddZeroClass Ξ±] : Matrix n n Ξ± β+ n β Ξ± where
toFun := diag
map_zero' := diag_zero
map_add' := diag_add
variable (R)
/-- `Matrix.diag` as a `LinearMap`. -/
@[simps]
def diagLinearMap [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : Matrix n n Ξ± ββ[R] n β Ξ± :=
{ diagAddMonoidHom n Ξ± with map_smul' := diag_smul }
variable {n Ξ± R}
@[simp]
theorem diag_list_sum [AddMonoid Ξ±] (l : List (Matrix n n Ξ±)) : diag l.sum = (l.map diag).sum :=
map_list_sum (diagAddMonoidHom n Ξ±) l
@[simp]
theorem diag_multiset_sum [AddCommMonoid Ξ±] (s : Multiset (Matrix n n Ξ±)) :
diag s.sum = (s.map diag).sum :=
map_multiset_sum (diagAddMonoidHom n Ξ±) s
@[simp]
theorem diag_sum {ΞΉ} [AddCommMonoid Ξ±] (s : Finset ΞΉ) (f : ΞΉ β Matrix n n Ξ±) :
diag (β i β s, f i) = β i β s, diag (f i) :=
map_sum (diagAddMonoidHom n Ξ±) f s
end Diag
open Matrix
section AddCommMonoid
variable [AddCommMonoid Ξ±] [Mul Ξ±]
end AddCommMonoid
section NonAssocSemiring
variable [NonAssocSemiring Ξ±]
variable (Ξ± n)
/-- `Matrix.diagonal` as a `RingHom`. -/
@[simps]
def diagonalRingHom [Fintype n] [DecidableEq n] : (n β Ξ±) β+* Matrix n n Ξ± :=
{ diagonalAddMonoidHom n Ξ± with
toFun := diagonal
map_one' := diagonal_one
map_mul' := fun _ _ => (diagonal_mul_diagonal' _ _).symm }
end NonAssocSemiring
section Semiring
variable [Semiring Ξ±]
theorem diagonal_pow [Fintype n] [DecidableEq n] (v : n β Ξ±) (k : β) :
diagonal v ^ k = diagonal (v ^ k) :=
(map_pow (diagonalRingHom n Ξ±) v k).symm
/-- The ring homomorphism `Ξ± β+* Matrix n n Ξ±`
sending `a` to the diagonal matrix with `a` on the diagonal.
-/
def scalar (n : Type u) [DecidableEq n] [Fintype n] : Ξ± β+* Matrix n n Ξ± :=
(diagonalRingHom n Ξ±).comp <| Pi.constRingHom n Ξ±
section Scalar
variable [DecidableEq n] [Fintype n]
@[simp]
theorem scalar_apply (a : Ξ±) : scalar n a = diagonal fun _ => a :=
rfl
theorem scalar_inj [Nonempty n] {r s : Ξ±} : scalar n r = scalar n s β r = s :=
(diagonal_injective.comp Function.const_injective).eq_iff
theorem scalar_commute_iff {r : Ξ±} {M : Matrix n n Ξ±} :
Commute (scalar n r) M β r β’ M = MulOpposite.op r β’ M := by
simp_rw [Commute, SemiconjBy, scalar_apply, β smul_eq_diagonal_mul, β op_smul_eq_mul_diagonal]
theorem scalar_commute (r : Ξ±) (hr : β r', Commute r r') (M : Matrix n n Ξ±) :
Commute (scalar n r) M := scalar_commute_iff.2 <| ext fun _ _ => hr _
end Scalar
end Semiring
section Algebra
variable [Fintype n] [DecidableEq n]
variable [CommSemiring R] [Semiring Ξ±] [Semiring Ξ²] [Algebra R Ξ±] [Algebra R Ξ²]
instance instAlgebra : Algebra R (Matrix n n Ξ±) where
algebraMap := (Matrix.scalar n).comp (algebraMap R Ξ±)
commutes' _ _ := scalar_commute _ (fun _ => Algebra.commutes _ _) _
smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r]
theorem algebraMap_matrix_apply {r : R} {i j : n} :
algebraMap R (Matrix n n Ξ±) r i j = if i = j then algebraMap R Ξ± r else 0 := by
dsimp [algebraMap, Algebra.algebraMap, Matrix.scalar]
split_ifs with h <;> simp [h, Matrix.one_apply_ne]
theorem algebraMap_eq_diagonal (r : R) :
algebraMap R (Matrix n n Ξ±) r = diagonal (algebraMap R (n β Ξ±) r) := rfl
theorem algebraMap_eq_diagonalRingHom :
algebraMap R (Matrix n n Ξ±) = (diagonalRingHom n Ξ±).comp (algebraMap R _) := rfl
@[simp]
theorem map_algebraMap (r : R) (f : Ξ± β Ξ²) (hf : f 0 = 0)
(hfβ : f (algebraMap R Ξ± r) = algebraMap R Ξ² r) :
(algebraMap R (Matrix n n Ξ±) r).map f = algebraMap R (Matrix n n Ξ²) r := by
rw [algebraMap_eq_diagonal, algebraMap_eq_diagonal, diagonal_map hf]
simp [hfβ]
variable (R)
/-- `Matrix.diagonal` as an `AlgHom`. -/
@[simps]
def diagonalAlgHom : (n β Ξ±) ββ[R] Matrix n n Ξ± :=
{ diagonalRingHom n Ξ± with
toFun := diagonal
commutes' := fun r => (algebraMap_eq_diagonal r).symm }
end Algebra
section AddHom
variable [Add Ξ±]
variable (R Ξ±) in
/-- Extracting entries from a matrix as an additive homomorphism. -/
@[simps]
def entryAddHom (i : m) (j : n) : AddHom (Matrix m n Ξ±) Ξ± where
toFun M := M i j
map_add' _ _ := rfl
-- It is necessary to spell out the name of the coercion explicitly on the RHS
-- for unification to succeed
lemma entryAddHom_eq_comp {i : m} {j : n} :
entryAddHom Ξ± i j =
((Pi.evalAddHom (fun _ => Ξ±) j).comp (Pi.evalAddHom _ i)).comp
(AddHomClass.toAddHom ofAddEquiv.symm) :=
rfl
end AddHom
section AddMonoidHom
variable [AddZeroClass Ξ±]
variable (R Ξ±) in
/--
Extracting entries from a matrix as an additive monoid homomorphism. Note this cannot be upgraded to
a ring homomorphism, as it does not respect multiplication.
-/
@[simps]
def entryAddMonoidHom (i : m) (j : n) : Matrix m n Ξ± β+ Ξ± where
toFun M := M i j
map_add' _ _ := rfl
map_zero' := rfl
-- It is necessary to spell out the name of the coercion explicitly on the RHS
-- for unification to succeed
lemma entryAddMonoidHom_eq_comp {i : m} {j : n} :
entryAddMonoidHom Ξ± i j =
((Pi.evalAddMonoidHom (fun _ => Ξ±) j).comp (Pi.evalAddMonoidHom _ i)).comp
(AddMonoidHomClass.toAddMonoidHom ofAddEquiv.symm) := by
rfl
@[simp] lemma evalAddMonoidHom_comp_diagAddMonoidHom (i : m) :
(Pi.evalAddMonoidHom _ i).comp (diagAddMonoidHom m Ξ±) = entryAddMonoidHom Ξ± i i := by
simp [AddMonoidHom.ext_iff]
@[simp] lemma entryAddMonoidHom_toAddHom {i : m} {j : n} :
(entryAddMonoidHom Ξ± i j : AddHom _ _) = entryAddHom Ξ± i j := rfl
end AddMonoidHom
section LinearMap
variable [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±]
variable (R Ξ±) in
/--
Extracting entries from a matrix as a linear map. Note this cannot be upgraded to an algebra
homomorphism, as it does not respect multiplication.
-/
@[simps]
def entryLinearMap (i : m) (j : n) :
Matrix m n Ξ± ββ[R] Ξ± where
toFun M := M i j
map_add' _ _ := rfl
map_smul' _ _ := rfl
-- It is necessary to spell out the name of the coercion explicitly on the RHS
-- for unification to succeed
lemma entryLinearMap_eq_comp {i : m} {j : n} :
entryLinearMap R Ξ± i j =
LinearMap.proj j ββ LinearMap.proj i ββ (ofLinearEquiv R).symm.toLinearMap := by
rfl
@[simp] lemma proj_comp_diagLinearMap (i : m) :
LinearMap.proj i ββ diagLinearMap m R Ξ± = entryLinearMap R Ξ± i i := by
simp [LinearMap.ext_iff]
@[simp] lemma entryLinearMap_toAddMonoidHom {i : m} {j : n} :
(entryLinearMap R Ξ± i j : _ β+ _) = entryAddMonoidHom Ξ± i j := rfl
@[simp] lemma entryLinearMap_toAddHom {i : m} {j : n} :
(entryLinearMap R Ξ± i j : AddHom _ _) = entryAddHom Ξ± i j := rfl
end LinearMap
end Matrix
/-!
### Bundled versions of `Matrix.map`
-/
namespace Equiv
/-- The `Equiv` between spaces of matrices induced by an `Equiv` between their
coefficients. This is `Matrix.map` as an `Equiv`. -/
@[simps apply]
def mapMatrix (f : Ξ± β Ξ²) : Matrix m n Ξ± β Matrix m n Ξ² where
toFun M := M.map f
invFun M := M.map f.symm
left_inv _ := Matrix.ext fun _ _ => f.symm_apply_apply _
right_inv _ := Matrix.ext fun _ _ => f.apply_symm_apply _
@[simp]
theorem mapMatrix_refl : (Equiv.refl Ξ±).mapMatrix = Equiv.refl (Matrix m n Ξ±) :=
rfl
@[simp]
theorem mapMatrix_symm (f : Ξ± β Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n Ξ² β _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : Ξ± β Ξ²) (g : Ξ² β Ξ³) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n Ξ± β _) :=
rfl
end Equiv
namespace AddMonoidHom
variable [AddZeroClass Ξ±] [AddZeroClass Ξ²] [AddZeroClass Ξ³]
/-- The `AddMonoidHom` between spaces of matrices induced by an `AddMonoidHom` between their
coefficients. This is `Matrix.map` as an `AddMonoidHom`. -/
@[simps]
def mapMatrix (f : Ξ± β+ Ξ²) : Matrix m n Ξ± β+ Matrix m n Ξ² where
toFun M := M.map f
map_zero' := Matrix.map_zero f f.map_zero
map_add' := Matrix.map_add f f.map_add
@[simp]
theorem mapMatrix_id : (AddMonoidHom.id Ξ±).mapMatrix = AddMonoidHom.id (Matrix m n Ξ±) :=
rfl
@[simp]
theorem mapMatrix_comp (f : Ξ² β+ Ξ³) (g : Ξ± β+ Ξ²) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n Ξ± β+ _) :=
rfl
@[simp] lemma entryAddMonoidHom_comp_mapMatrix (f : Ξ± β+ Ξ²) (i : m) (j : n) :
(entryAddMonoidHom Ξ² i j).comp f.mapMatrix = f.comp (entryAddMonoidHom Ξ± i j) := rfl
end AddMonoidHom
namespace AddEquiv
variable [Add Ξ±] [Add Ξ²] [Add Ξ³]
/-- The `AddEquiv` between spaces of matrices induced by an `AddEquiv` between their
coefficients. This is `Matrix.map` as an `AddEquiv`. -/
@[simps apply]
def mapMatrix (f : Ξ± β+ Ξ²) : Matrix m n Ξ± β+ Matrix m n Ξ² :=
{ f.toEquiv.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm
map_add' := Matrix.map_add f (map_add f) }
@[simp]
theorem mapMatrix_refl : (AddEquiv.refl Ξ±).mapMatrix = AddEquiv.refl (Matrix m n Ξ±) :=
rfl
@[simp]
theorem mapMatrix_symm (f : Ξ± β+ Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n Ξ² β+ _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : Ξ± β+ Ξ²) (g : Ξ² β+ Ξ³) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n Ξ± β+ _) :=
rfl
@[simp] lemma entryAddHom_comp_mapMatrix (f : Ξ± β+ Ξ²) (i : m) (j : n) :
(entryAddHom Ξ² i j).comp (AddHomClass.toAddHom f.mapMatrix) =
(f : AddHom Ξ± Ξ²).comp (entryAddHom _ i j) := rfl
end AddEquiv
namespace LinearMap
variable [Semiring R] [AddCommMonoid Ξ±] [AddCommMonoid Ξ²] [AddCommMonoid Ξ³]
variable [Module R Ξ±] [Module R Ξ²] [Module R Ξ³]
/-- The `LinearMap` between spaces of matrices induced by a `LinearMap` between their
coefficients. This is `Matrix.map` as a `LinearMap`. -/
@[simps]
def mapMatrix (f : Ξ± ββ[R] Ξ²) : Matrix m n Ξ± ββ[R] Matrix m n Ξ² where
toFun M := M.map f
map_add' := Matrix.map_add f f.map_add
map_smul' r := Matrix.map_smul f r (f.map_smul r)
@[simp]
theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n Ξ± ββ[R] _) :=
rfl
@[simp]
theorem mapMatrix_comp (f : Ξ² ββ[R] Ξ³) (g : Ξ± ββ[R] Ξ²) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n Ξ± ββ[R] _) :=
rfl
@[simp] lemma entryLinearMap_comp_mapMatrix (f : Ξ± ββ[R] Ξ²) (i : m) (j : n) :
entryLinearMap R _ i j ββ f.mapMatrix = f ββ entryLinearMap R _ i j := rfl
end LinearMap
namespace LinearEquiv
variable [Semiring R] [AddCommMonoid Ξ±] [AddCommMonoid Ξ²] [AddCommMonoid Ξ³]
variable [Module R Ξ±] [Module R Ξ²] [Module R Ξ³]
/-- The `LinearEquiv` between spaces of matrices induced by a `LinearEquiv` between their
coefficients. This is `Matrix.map` as a `LinearEquiv`. -/
@[simps apply]
def mapMatrix (f : Ξ± ββ[R] Ξ²) : Matrix m n Ξ± ββ[R] Matrix m n Ξ² :=
{ f.toEquiv.mapMatrix,
f.toLinearMap.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm }
@[simp]
theorem mapMatrix_refl : (LinearEquiv.refl R Ξ±).mapMatrix = LinearEquiv.refl R (Matrix m n Ξ±) :=
rfl
@[simp]
theorem mapMatrix_symm (f : Ξ± ββ[R] Ξ²) :
f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n Ξ² ββ[R] _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : Ξ± ββ[R] Ξ²) (g : Ξ² ββ[R] Ξ³) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n Ξ± ββ[R] _) :=
rfl
@[simp] lemma mapMatrix_toLinearMap (f : Ξ± ββ[R] Ξ²) :
(f.mapMatrix : _ ββ[R] Matrix m n Ξ²).toLinearMap = f.toLinearMap.mapMatrix := by
rfl
@[simp] lemma entryLinearMap_comp_mapMatrix (f : Ξ± ββ[R] Ξ²) (i : m) (j : n) :
entryLinearMap R _ i j ββ f.mapMatrix.toLinearMap =
f.toLinearMap ββ entryLinearMap R _ i j := by
simp only [mapMatrix_toLinearMap, LinearMap.entryLinearMap_comp_mapMatrix]
end LinearEquiv
namespace RingHom
variable [Fintype m] [DecidableEq m]
variable [NonAssocSemiring Ξ±] [NonAssocSemiring Ξ²] [NonAssocSemiring Ξ³]
/-- The `RingHom` between spaces of square matrices induced by a `RingHom` between their
coefficients. This is `Matrix.map` as a `RingHom`. -/
@[simps]
def mapMatrix (f : Ξ± β+* Ξ²) : Matrix m m Ξ± β+* Matrix m m Ξ² :=
{ f.toAddMonoidHom.mapMatrix with
toFun := fun M => M.map f
map_one' := by simp
map_mul' := fun _ _ => Matrix.map_mul }
@[simp]
theorem mapMatrix_id : (RingHom.id Ξ±).mapMatrix = RingHom.id (Matrix m m Ξ±) :=
rfl
@[simp]
theorem mapMatrix_comp (f : Ξ² β+* Ξ³) (g : Ξ± β+* Ξ²) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m Ξ± β+* _) :=
rfl
end RingHom
namespace RingEquiv
variable [Fintype m] [DecidableEq m]
variable [NonAssocSemiring Ξ±] [NonAssocSemiring Ξ²] [NonAssocSemiring Ξ³]
/-- The `RingEquiv` between spaces of square matrices induced by a `RingEquiv` between their
coefficients. This is `Matrix.map` as a `RingEquiv`. -/
@[simps apply]
def mapMatrix (f : Ξ± β+* Ξ²) : Matrix m m Ξ± β+* Matrix m m Ξ² :=
{ f.toRingHom.mapMatrix,
f.toAddEquiv.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm }
@[simp]
theorem mapMatrix_refl : (RingEquiv.refl Ξ±).mapMatrix = RingEquiv.refl (Matrix m m Ξ±) :=
rfl
@[simp]
theorem mapMatrix_symm (f : Ξ± β+* Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m Ξ² β+* _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : Ξ± β+* Ξ²) (g : Ξ² β+* Ξ³) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m Ξ± β+* _) :=
rfl
open MulOpposite in
/--
For any ring `R`, we have ring isomorphism `Matβββ(Rα΅α΅) β
(Matβββ(R))α΅α΅` given by transpose.
-/
@[simps apply symm_apply]
def mopMatrix : Matrix m m Ξ±α΅α΅α΅ β+* (Matrix m m Ξ±)α΅α΅α΅ where
toFun M := op (M.transpose.map unop)
invFun M := M.unop.transpose.map op
left_inv _ := by aesop
right_inv _ := by aesop
map_mul' _ _ := unop_injective <| by ext; simp [transpose, mul_apply]
map_add' _ _ := by aesop
end RingEquiv
namespace AlgHom
variable [Fintype m] [DecidableEq m]
variable [CommSemiring R] [Semiring Ξ±] [Semiring Ξ²] [Semiring Ξ³]
variable [Algebra R Ξ±] [Algebra R Ξ²] [Algebra R Ξ³]
/-- The `AlgHom` between spaces of square matrices induced by an `AlgHom` between their
coefficients. This is `Matrix.map` as an `AlgHom`. -/
@[simps]
def mapMatrix (f : Ξ± ββ[R] Ξ²) : Matrix m m Ξ± ββ[R] Matrix m m Ξ² :=
{ f.toRingHom.mapMatrix with
toFun := fun M => M.map f
commutes' := fun r => Matrix.map_algebraMap r f (map_zero _) (f.commutes r) }
@[simp]
theorem mapMatrix_id : (AlgHom.id R Ξ±).mapMatrix = AlgHom.id R (Matrix m m Ξ±) :=
rfl
@[simp]
theorem mapMatrix_comp (f : Ξ² ββ[R] Ξ³) (g : Ξ± ββ[R] Ξ²) :
f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m Ξ± ββ[R] _) :=
rfl
end AlgHom
namespace AlgEquiv
variable [Fintype m] [DecidableEq m]
variable [CommSemiring R] [Semiring Ξ±] [Semiring Ξ²] [Semiring Ξ³]
variable [Algebra R Ξ±] [Algebra R Ξ²] [Algebra R Ξ³]
/-- The `AlgEquiv` between spaces of square matrices induced by an `AlgEquiv` between their
coefficients. This is `Matrix.map` as an `AlgEquiv`. -/
@[simps apply]
def mapMatrix (f : Ξ± ββ[R] Ξ²) : Matrix m m Ξ± ββ[R] Matrix m m Ξ² :=
{ f.toAlgHom.mapMatrix,
f.toRingEquiv.mapMatrix with
toFun := fun M => M.map f
invFun := fun M => M.map f.symm }
@[simp]
theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m Ξ± ββ[R] _) :=
rfl
@[simp]
theorem mapMatrix_symm (f : Ξ± ββ[R] Ξ²) :
f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m Ξ² ββ[R] _) :=
rfl
@[simp]
theorem mapMatrix_trans (f : Ξ± ββ[R] Ξ²) (g : Ξ² ββ[R] Ξ³) :
f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m Ξ± ββ[R] _) :=
rfl
/-- For any algebra `Ξ±` over a ring `R`, we have an `R`-algebra isomorphism
`Matβββ(Ξ±α΅α΅) β
(Matβββ(R))α΅α΅` given by transpose. If `Ξ±` is commutative,
we can get rid of the `α΅α΅` in the left-hand side, see `Matrix.transposeAlgEquiv`. -/
@[simps!] def mopMatrix : Matrix m m Ξ±α΅α΅α΅ ββ[R] (Matrix m m Ξ±)α΅α΅α΅ where
__ := RingEquiv.mopMatrix
commutes' _ := MulOpposite.unop_injective <| by
ext; simp [algebraMap_matrix_apply, eq_comm, apply_ite MulOpposite.unop]
end AlgEquiv
open Matrix
namespace Matrix
section Transpose
open Matrix
variable (m n Ξ±)
/-- `Matrix.transpose` as an `AddEquiv` -/
@[simps apply]
def transposeAddEquiv [Add Ξ±] : Matrix m n Ξ± β+ Matrix n m Ξ± where
toFun := transpose
invFun := transpose
left_inv := transpose_transpose
right_inv := transpose_transpose
map_add' := transpose_add
@[simp]
theorem transposeAddEquiv_symm [Add Ξ±] : (transposeAddEquiv m n Ξ±).symm = transposeAddEquiv n m Ξ± :=
rfl
variable {m n Ξ±}
theorem transpose_list_sum [AddMonoid Ξ±] (l : List (Matrix m n Ξ±)) :
l.sumα΅ = (l.map transpose).sum :=
map_list_sum (transposeAddEquiv m n Ξ±) l
theorem transpose_multiset_sum [AddCommMonoid Ξ±] (s : Multiset (Matrix m n Ξ±)) :
s.sumα΅ = (s.map transpose).sum :=
(transposeAddEquiv m n Ξ±).toAddMonoidHom.map_multiset_sum s
theorem transpose_sum [AddCommMonoid Ξ±] {ΞΉ : Type*} (s : Finset ΞΉ) (M : ΞΉ β Matrix m n Ξ±) :
(β i β s, M i)α΅ = β i β s, (M i)α΅ :=
map_sum (transposeAddEquiv m n Ξ±) _ s
variable (m n R Ξ±)
/-- `Matrix.transpose` as a `LinearMap` -/
@[simps apply]
def transposeLinearEquiv [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] :
Matrix m n Ξ± ββ[R] Matrix n m Ξ± :=
{ transposeAddEquiv m n Ξ± with map_smul' := transpose_smul }
@[simp]
theorem transposeLinearEquiv_symm [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] :
(transposeLinearEquiv m n R Ξ±).symm = transposeLinearEquiv n m R Ξ± :=
rfl
variable {m n R Ξ±}
variable (m Ξ±)
/-- `Matrix.transpose` as a `RingEquiv` to the opposite ring -/
@[simps]
def transposeRingEquiv [AddCommMonoid Ξ±] [CommSemigroup Ξ±] [Fintype m] :
Matrix m m Ξ± β+* (Matrix m m Ξ±)α΅α΅α΅ :=
{ (transposeAddEquiv m m Ξ±).trans MulOpposite.opAddEquiv with
toFun := fun M => MulOpposite.op Mα΅
invFun := fun M => M.unopα΅
map_mul' := fun M N =>
(congr_arg MulOpposite.op (transpose_mul M N)).trans (MulOpposite.op_mul _ _)
left_inv := fun M => transpose_transpose M
right_inv := fun M => MulOpposite.unop_injective <| transpose_transpose M.unop }
variable {m Ξ±}
@[simp]
theorem transpose_pow [CommSemiring Ξ±] [Fintype m] [DecidableEq m] (M : Matrix m m Ξ±) (k : β) :
(M ^ k)α΅ = Mα΅ ^ k :=
MulOpposite.op_injective <| map_pow (transposeRingEquiv m Ξ±) M k
theorem transpose_list_prod [CommSemiring Ξ±] [Fintype m] [DecidableEq m] (l : List (Matrix m m Ξ±)) :
l.prodα΅ = (l.map transpose).reverse.prod :=
(transposeRingEquiv m Ξ±).unop_map_list_prod l
variable (R m Ξ±)
/-- `Matrix.transpose` as an `AlgEquiv` to the opposite ring -/
@[simps]
def transposeAlgEquiv [CommSemiring R] [CommSemiring Ξ±] [Fintype m] [DecidableEq m] [Algebra R Ξ±] :
Matrix m m Ξ± ββ[R] (Matrix m m Ξ±)α΅α΅α΅ :=
{ (transposeAddEquiv m m Ξ±).trans MulOpposite.opAddEquiv,
transposeRingEquiv m Ξ± with
toFun := fun M => MulOpposite.op Mα΅
commutes' := fun r => by
simp only [algebraMap_eq_diagonal, diagonal_transpose, MulOpposite.algebraMap_apply] }
variable {R m Ξ±}
end Transpose
end Matrix
| Mathlib/Data/Matrix/Basic.lean | 1,232 | 1,234 | |
/-
Copyright (c) 2023 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.Homology
/-!
# Quasi-isomorphisms of short complexes
This file introduces the typeclass `QuasiIso Ο` for a morphism `Ο : Sβ βΆ Sβ`
of short complexes (which have homology): the condition is that the induced
morphism `homologyMap Ο` in homology is an isomorphism.
-/
namespace CategoryTheory
open Category Limits
namespace ShortComplex
variable {C : Type _} [Category C] [HasZeroMorphisms C]
{Sβ Sβ Sβ Sβ : ShortComplex C}
[Sβ.HasHomology] [Sβ.HasHomology] [Sβ.HasHomology] [Sβ.HasHomology]
/-- A morphism `Ο : Sβ βΆ Sβ` of short complexes that have homology is a quasi-isomorphism if
the induced map `homologyMap Ο : Sβ.homology βΆ Sβ.homology` is an isomorphism. -/
class QuasiIso (Ο : Sβ βΆ Sβ) : Prop where
/-- the homology map is an isomorphism -/
isIso' : IsIso (homologyMap Ο)
instance QuasiIso.isIso (Ο : Sβ βΆ Sβ) [QuasiIso Ο] : IsIso (homologyMap Ο) := QuasiIso.isIso'
lemma quasiIso_iff (Ο : Sβ βΆ Sβ) :
QuasiIso Ο β IsIso (homologyMap Ο) := by
constructor
Β· intro h
infer_instance
Β· intro h
exact β¨hβ©
instance quasiIso_of_isIso (Ο : Sβ βΆ Sβ) [IsIso Ο] : QuasiIso Ο :=
β¨(homologyMapIso (asIso Ο)).isIso_homβ©
instance quasiIso_comp (Ο : Sβ βΆ Sβ) (Ο' : Sβ βΆ Sβ) [hΟ : QuasiIso Ο] [hΟ' : QuasiIso Ο'] :
QuasiIso (Ο β« Ο') := by
rw [quasiIso_iff] at hΟ hΟ' β’
rw [homologyMap_comp]
infer_instance
lemma quasiIso_of_comp_left (Ο : Sβ βΆ Sβ) (Ο' : Sβ βΆ Sβ)
[hΟ : QuasiIso Ο] [hΟΟ' : QuasiIso (Ο β« Ο')] :
QuasiIso Ο' := by
rw [quasiIso_iff] at hΟ hΟΟ' β’
rw [homologyMap_comp] at hΟΟ'
exact IsIso.of_isIso_comp_left (homologyMap Ο) (homologyMap Ο')
lemma quasiIso_iff_comp_left (Ο : Sβ βΆ Sβ) (Ο' : Sβ βΆ Sβ) [hΟ : QuasiIso Ο] :
QuasiIso (Ο β« Ο') β QuasiIso Ο' := by
constructor
Β· intro
exact quasiIso_of_comp_left Ο Ο'
Β· intro
exact quasiIso_comp Ο Ο'
lemma quasiIso_of_comp_right (Ο : Sβ βΆ Sβ) (Ο' : Sβ βΆ Sβ)
[hΟ' : QuasiIso Ο'] [hΟΟ' : QuasiIso (Ο β« Ο')] :
QuasiIso Ο := by
rw [quasiIso_iff] at hΟ' hΟΟ' β’
rw [homologyMap_comp] at hΟΟ'
exact IsIso.of_isIso_comp_right (homologyMap Ο) (homologyMap Ο')
lemma quasiIso_iff_comp_right (Ο : Sβ βΆ Sβ) (Ο' : Sβ βΆ Sβ) [hΟ' : QuasiIso Ο'] :
QuasiIso (Ο β« Ο') β QuasiIso Ο := by
constructor
Β· intro
exact quasiIso_of_comp_right Ο Ο'
Β· intro
exact quasiIso_comp Ο Ο'
lemma quasiIso_of_arrow_mk_iso (Ο : Sβ βΆ Sβ) (Ο' : Sβ βΆ Sβ) (e : Arrow.mk Ο β
Arrow.mk Ο')
[hΟ : QuasiIso Ο] : QuasiIso Ο' := by
let Ξ± : Sβ βΆ Sβ := e.inv.left
let Ξ² : Sβ βΆ Sβ := e.hom.right
suffices Ο' = Ξ± β« Ο β« Ξ² by
rw [this]
infer_instance
simp only [Ξ±, Ξ², Arrow.w_mk_right_assoc, Arrow.mk_left, Arrow.mk_right, Arrow.mk_hom,
β Arrow.comp_right, e.inv_hom_id, Arrow.id_right, comp_id]
lemma quasiIso_iff_of_arrow_mk_iso (Ο : Sβ βΆ Sβ) (Ο' : Sβ βΆ Sβ) (e : Arrow.mk Ο β
Arrow.mk Ο') :
QuasiIso Ο β QuasiIso Ο' :=
β¨fun _ => quasiIso_of_arrow_mk_iso Ο Ο' e, fun _ => quasiIso_of_arrow_mk_iso Ο' Ο e.symmβ©
lemma LeftHomologyMapData.quasiIso_iff {Ο : Sβ βΆ Sβ} {hβ : Sβ.LeftHomologyData}
{hβ : Sβ.LeftHomologyData} (Ξ³ : LeftHomologyMapData Ο hβ hβ) :
QuasiIso Ο β IsIso Ξ³.ΟH := by
rw [ShortComplex.quasiIso_iff, Ξ³.homologyMap_eq]
constructor
Β· intro h
haveI : IsIso (Ξ³.ΟH β« (LeftHomologyData.homologyIso hβ).inv) :=
IsIso.of_isIso_comp_left (LeftHomologyData.homologyIso hβ).hom _
exact IsIso.of_isIso_comp_right _ (LeftHomologyData.homologyIso hβ).inv
Β· intro h
infer_instance
lemma RightHomologyMapData.quasiIso_iff {Ο : Sβ βΆ Sβ} {hβ : Sβ.RightHomologyData}
{hβ : Sβ.RightHomologyData} (Ξ³ : RightHomologyMapData Ο hβ hβ) :
QuasiIso Ο β IsIso Ξ³.ΟH := by
rw [ShortComplex.quasiIso_iff, Ξ³.homologyMap_eq]
constructor
Β· intro h
haveI : IsIso (Ξ³.ΟH β« (RightHomologyData.homologyIso hβ).inv) :=
IsIso.of_isIso_comp_left (RightHomologyData.homologyIso hβ).hom _
exact IsIso.of_isIso_comp_right _ (RightHomologyData.homologyIso hβ).inv
Β· intro h
infer_instance
lemma quasiIso_iff_isIso_leftHomologyMap' (Ο : Sβ βΆ Sβ)
(hβ : Sβ.LeftHomologyData) (hβ : Sβ.LeftHomologyData) :
QuasiIso Ο β IsIso (leftHomologyMap' Ο hβ hβ) := by
have Ξ³ : LeftHomologyMapData Ο hβ hβ := default
rw [Ξ³.quasiIso_iff, Ξ³.leftHomologyMap'_eq]
lemma quasiIso_iff_isIso_rightHomologyMap' (Ο : Sβ βΆ Sβ)
(hβ : Sβ.RightHomologyData) (hβ : Sβ.RightHomologyData) :
QuasiIso Ο β IsIso (rightHomologyMap' Ο hβ hβ) := by
have Ξ³ : RightHomologyMapData Ο hβ hβ := default
rw [Ξ³.quasiIso_iff, Ξ³.rightHomologyMap'_eq]
lemma quasiIso_iff_isIso_homologyMap' (Ο : Sβ βΆ Sβ)
(hβ : Sβ.HomologyData) (hβ : Sβ.HomologyData) :
QuasiIso Ο β IsIso (homologyMap' Ο hβ hβ) :=
quasiIso_iff_isIso_leftHomologyMap' _ _ _
lemma quasiIso_of_epi_of_isIso_of_mono (Ο : Sβ βΆ Sβ) [Epi Ο.Οβ] [IsIso Ο.Οβ] [Mono Ο.Οβ] :
QuasiIso Ο := by
rw [((LeftHomologyMapData.ofEpiOfIsIsoOfMono Ο) Sβ.leftHomologyData).quasiIso_iff]
dsimp
infer_instance
lemma quasiIso_opMap_iff (Ο : Sβ βΆ Sβ) :
QuasiIso (opMap Ο) β QuasiIso Ο := by
have Ξ³ : HomologyMapData Ο Sβ.homologyData Sβ.homologyData := default
rw [Ξ³.left.quasiIso_iff, Ξ³.op.right.quasiIso_iff]
dsimp
constructor
Β· intro h
apply isIso_of_op
Β· intro h
infer_instance
lemma quasiIso_opMap (Ο : Sβ βΆ Sβ) [QuasiIso Ο] :
QuasiIso (opMap Ο) := by
rw [quasiIso_opMap_iff]
infer_instance
lemma quasiIso_unopMap {Sβ Sβ : ShortComplex Cα΅α΅} [Sβ.HasHomology] [Sβ.HasHomology]
[Sβ.unop.HasHomology] [Sβ.unop.HasHomology]
(Ο : Sβ βΆ Sβ) [QuasiIso Ο] : QuasiIso (unopMap Ο) := by
rw [β quasiIso_opMap_iff]
change QuasiIso Ο
infer_instance
lemma quasiIso_iff_isIso_liftCycles (Ο : Sβ βΆ Sβ)
(hfβ : Sβ.f = 0) (hgβ : Sβ.g = 0) (hfβ : Sβ.f = 0) :
QuasiIso Ο β IsIso (Sβ.liftCycles Ο.Οβ (by rw [Ο.commββ, hgβ, zero_comp])) := by
let H : LeftHomologyMapData Ο (LeftHomologyData.ofZeros Sβ hfβ hgβ)
(LeftHomologyData.ofIsLimitKernelFork Sβ hfβ _ Sβ.cyclesIsKernel) :=
{ ΟK := Sβ.liftCycles Ο.Οβ (by rw [Ο.commββ, hgβ, zero_comp])
ΟH := Sβ.liftCycles Ο.Οβ (by rw [Ο.commββ, hgβ, zero_comp]) }
exact H.quasiIso_iff
| lemma quasiIso_iff_isIso_descOpcycles (Ο : Sβ βΆ Sβ)
(hgβ : Sβ.g = 0) (hfβ : Sβ.f = 0) (hgβ : Sβ.g = 0) :
QuasiIso Ο β IsIso (Sβ.descOpcycles Ο.Οβ (by rw [β Ο.commββ, hfβ, comp_zero])) := by
let H : RightHomologyMapData Ο
(RightHomologyData.ofIsColimitCokernelCofork Sβ hgβ _ Sβ.opcyclesIsCokernel)
(RightHomologyData.ofZeros Sβ hfβ hgβ) :=
{ ΟQ := Sβ.descOpcycles Ο.Οβ (by rw [β Ο.commββ, hfβ, comp_zero])
ΟH := Sβ.descOpcycles Ο.Οβ (by rw [β Ο.commββ, hfβ, comp_zero]) }
exact H.quasiIso_iff
| Mathlib/Algebra/Homology/ShortComplex/QuasiIso.lean | 176 | 184 |
/-
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, Simon Hudon, Mario Carneiro
-/
import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Nat.Init
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.SplitIfs
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {Ξ± Ξ² G M : Type*}
section ite
variable [Pow Ξ± Ξ²]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : Ξ±) (b : p β Ξ²) (c : Β¬ p β Ξ²) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p β Ξ±) (b : Β¬ p β Ξ±) (c : Ξ²) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : Ξ±) (b c : Ξ²) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : Ξ±) (c : Ξ²) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup Ξ±]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· * Β·) := β¨mul_assocβ©
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`."]
theorem comp_mul_left (x y : Ξ±) : (x * Β·) β (y * Β·) = (x * y * Β·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`."]
theorem comp_mul_right (x y : Ξ±) : (Β· * x) β (Β· * y) = (Β· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (Ξ± := G) (Β· * Β·) := β¨mul_commβ©
section MulOneClass
variable [MulOneClass M]
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 β b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * Β·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (Β· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [β mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : β}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m β€ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [β pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m β€ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [β pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n β 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [β pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n β 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [β pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul "If `n β’ x = 0`, then `m β’ x` is the same as `(m % n) β’ x`"]
lemma pow_eq_pow_mod (m : β) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : β n, a * b = 1 β a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : β n : β, (a * Β·)^[n] = (a ^ n * Β·)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : β n : β, (Β· * a)^[n] = (Β· * a ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ', mul_right_iterate]
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * Β·)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (Β· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : β) : β n : β, (fun x : M β¦ x ^ k)^[n] = (Β· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : β n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a β b = 1 := calc
a * b = a β a * b = a * 1 := by rw [mul_one]
_ β b = 1 := mul_left_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left
@[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_eq_self
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b β b = 1 :=
eq_comm.trans mul_eq_left
@[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_right
@[to_additive]
theorem mul_ne_left : a * b β a β b β 1 := mul_eq_left.not
@[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left
@[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_ne_self
@[to_additive]
theorem left_ne_mul : a β a * b β b β 1 := left_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_right
end LeftCancelMonoid
section RightCancelMonoid
variable [RightCancelMonoid M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b β a = 1 := calc
a * b = b β a * b = 1 * b := by rw [one_mul]
_ β a = 1 := mul_right_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right
@[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_eq_self
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b β a = 1 :=
eq_comm.trans mul_eq_right
@[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
| @[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add
set_option linter.existingAttributeWarning false in
| Mathlib/Algebra/Group/Basic.lean | 276 | 278 |
/-
Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Data.Rat.Cast.Defs
/-!
# Casts of rational numbers into characteristic zero fields (or division rings).
-/
open Function
variable {F ΞΉ Ξ± Ξ² : Type*}
namespace Rat
variable [DivisionRing Ξ±] [CharZero Ξ±] {p q : β}
@[stacks 09FR "Characteristic zero case."]
lemma cast_injective : Injective ((β) : β β Ξ±)
| β¨nβ, dβ, dβ0, cββ©, β¨nβ, dβ, dβ0, cββ©, h => by
have dβa : (dβ : Ξ±) β 0 := Nat.cast_ne_zero.2 dβ0
have dβa : (dβ : Ξ±) β 0 := Nat.cast_ne_zero.2 dβ0
rw [mk'_eq_divInt, mk'_eq_divInt] at h β’
rw [cast_divInt_of_ne_zero, cast_divInt_of_ne_zero] at h <;> simp [dβ0, dβ0] at h β’
rwa [eq_div_iff_mul_eq dβa, division_def, mul_assoc, (dβ.cast_commute (dβ : Ξ±)).inv_leftβ.eq, β
| mul_assoc, β division_def, eq_comm, eq_div_iff_mul_eq dβa, eq_comm, β Int.cast_natCast dβ, β
Int.cast_mul, β Int.cast_natCast dβ, β Int.cast_mul, Int.cast_inj, β mkRat_eq_iff dβ0 dβ0]
at h
@[simp, norm_cast] lemma cast_inj : (p : Ξ±) = q β p = q := cast_injective.eq_iff
@[simp, norm_cast] lemma cast_eq_zero : (p : Ξ±) = 0 β p = 0 := cast_injective.eq_iff' cast_zero
lemma cast_ne_zero : (p : Ξ±) β 0 β p β 0 := cast_eq_zero.ne
@[simp, norm_cast] lemma cast_add (p q : β) : β(p + q) = (p + q : Ξ±) :=
cast_add_of_ne_zero (Nat.cast_ne_zero.2 p.pos.ne') (Nat.cast_ne_zero.2 q.pos.ne')
| Mathlib/Data/Rat/Cast/CharZero.lean | 28 | 38 |
/-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Kim Morrison, Apurva Nakade, Yuyang Zhao
-/
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.SetTheory.PGame.Algebra
import Mathlib.Tactic.Abel
/-!
# Combinatorial games.
In this file we construct an instance `OrderedAddCommGroup SetTheory.Game`.
## Multiplication on pre-games
We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems
about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x β y` does not
imply `x * z β y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless,
the abelian group structure on games allows us to simplify many proofs for pre-games.
-/
-- Porting note: many definitions here are noncomputable as the compiler does not support PGame.rec
noncomputable section
namespace SetTheory
open Function PGame
universe u
-- Porting note: moved the setoid instance to PGame.lean
/-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from
two sets of combinatorial games that have been constructed at an earlier
stage. To do this in type theory, we say that a combinatorial pre-game is built
inductively from two families of combinatorial games indexed over any type
in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`,
reflecting that it is a proper class in ZFC.
A combinatorial game is then constructed by quotienting by the equivalence
`x β y β x β€ y β§ y β€ x`. -/
abbrev Game :=
Quotient PGame.setoid
namespace Game
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11445): added this definition
/-- Negation of games. -/
instance : Neg Game where
neg := Quot.map Neg.neg <| fun _ _ => (neg_equiv_neg_iff).2
instance : Zero Game where zero := β¦0β§
instance : Add Game where
add := Quotient.mapβ HAdd.hAdd <| fun _ _ hx _ _ hy => PGame.add_congr hx hy
instance instAddCommGroupWithOneGame : AddCommGroupWithOne Game where
zero := β¦0β§
one := β¦1β§
add_zero := by
rintro β¨xβ©
exact Quot.sound (add_zero_equiv x)
zero_add := by
rintro β¨xβ©
exact Quot.sound (zero_add_equiv x)
add_assoc := by
rintro β¨xβ© β¨yβ© β¨zβ©
exact Quot.sound add_assoc_equiv
neg_add_cancel := Quotient.ind <| fun x => Quot.sound (neg_add_cancel_equiv x)
add_comm := by
rintro β¨xβ© β¨yβ©
exact Quot.sound add_comm_equiv
nsmul := nsmulRec
zsmul := zsmulRec
instance : Inhabited Game :=
β¨0β©
theorem zero_def : (0 : Game) = β¦0β§ :=
rfl
instance instPartialOrderGame : PartialOrder Game where
le := Quotient.liftβ (Β· β€ Β·) fun _ _ _ _ hx hy => propext (le_congr hx hy)
le_refl := by
rintro β¨xβ©
exact le_refl x
le_trans := by
rintro β¨xβ© β¨yβ© β¨zβ©
exact @le_trans _ _ x y z
le_antisymm := by
rintro β¨xβ© β¨yβ© hβ hβ
apply Quot.sound
exact β¨hβ, hββ©
lt := Quotient.liftβ (Β· < Β·) fun _ _ _ _ hx hy => propext (lt_congr hx hy)
lt_iff_le_not_le := by
rintro β¨xβ© β¨yβ©
exact @lt_iff_le_not_le _ _ x y
/-- The less or fuzzy relation on games.
If `0 β§ x` (less or fuzzy with), then Left can win `x` as the first player. -/
def LF : Game β Game β Prop :=
Quotient.liftβ PGame.LF fun _ _ _ _ hx hy => propext (lf_congr hx hy)
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
theorem not_le : β {x y : Game}, Β¬x β€ y β Game.LF y x := by
rintro β¨xβ© β¨yβ©
exact PGame.not_le
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
theorem not_lf : β {x y : Game}, Β¬Game.LF x y β y β€ x := by
rintro β¨xβ© β¨yβ©
exact PGame.not_lf
/-- The fuzzy, confused, or incomparable relation on games.
If `x β 0`, then the first player can always win `x`. -/
def Fuzzy : Game β Game β Prop :=
Quotient.liftβ PGame.Fuzzy fun _ _ _ _ hx hy => propext (fuzzy_congr hx hy)
-- Porting note: had to replace β§ with LF, otherwise cannot differentiate with the operator on PGame
instance : IsTrichotomous Game LF :=
β¨by
rintro β¨xβ© β¨yβ©
change _ β¨ β¦xβ§ = β¦yβ§ β¨ _
rw [Quotient.eq]
apply lf_or_equiv_or_gfβ©
/-! It can be useful to use these lemmas to turn `PGame` inequalities into `Game` inequalities, as
the `AddCommGroup` structure on `Game` often simplifies many proofs. -/
end Game
namespace PGame
-- Porting note: In a lot of places, I had to add explicitly that the quotient element was a Game.
-- In Lean4, quotients don't have the setoid as an instance argument,
-- but as an explicit argument, see https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/confusion.20between.20equivalence.20and.20instance.20setoid/near/360822354
theorem le_iff_game_le {x y : PGame} : x β€ y β (β¦xβ§ : Game) β€ β¦yβ§ :=
Iff.rfl
theorem lf_iff_game_lf {x y : PGame} : x β§ y β Game.LF β¦xβ§ β¦yβ§ :=
Iff.rfl
theorem lt_iff_game_lt {x y : PGame} : x < y β (β¦xβ§ : Game) < β¦yβ§ :=
Iff.rfl
theorem equiv_iff_game_eq {x y : PGame} : x β y β (β¦xβ§ : Game) = β¦yβ§ :=
(@Quotient.eq' _ _ x y).symm
alias β¨game_eq, _β© := equiv_iff_game_eq
theorem fuzzy_iff_game_fuzzy {x y : PGame} : x β y β Game.Fuzzy β¦xβ§ β¦yβ§ :=
Iff.rfl
end PGame
namespace Game
local infixl:50 " β§ " => LF
local infixl:50 " β " => Fuzzy
instance addLeftMono : AddLeftMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_le_add_left _ _ _ _ b c h aβ©
instance addRightMono : AddRightMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_le_add_right _ _ _ _ b c h aβ©
instance addLeftStrictMono : AddLeftStrictMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_lt_add_left _ _ _ _ b c h aβ©
instance addRightStrictMono : AddRightStrictMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_lt_add_right _ _ _ _ b c h aβ©
theorem add_lf_add_right : β {b c : Game} (_ : b β§ c) (a), (b + a : Game) β§ c + a := by
rintro β¨bβ© β¨cβ© h β¨aβ©
apply PGame.add_lf_add_right h
theorem add_lf_add_left : β {b c : Game} (_ : b β§ c) (a), (a + b : Game) β§ a + c := by
rintro β¨bβ© β¨cβ© h β¨aβ©
apply PGame.add_lf_add_left h
instance isOrderedAddMonoid : IsOrderedAddMonoid Game :=
{ add_le_add_left := @add_le_add_left _ _ _ Game.addLeftMono }
/-- A small family of games is bounded above. -/
lemma bddAbove_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β Game.{u}) :
BddAbove (Set.range f) := by
obtain β¨x, hxβ© := PGame.bddAbove_range_of_small (Quotient.out β f)
refine β¨β¦xβ§, Set.forall_mem_range.2 fun i β¦ ?_β©
simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i
/-- A small set of games is bounded above. -/
lemma bddAbove_of_small (s : Set Game.{u}) [Small.{u} s] : BddAbove s := by
simpa using bddAbove_range_of_small (Subtype.val : s β Game.{u})
/-- A small family of games is bounded below. -/
lemma bddBelow_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β Game.{u}) :
BddBelow (Set.range f) := by
obtain β¨x, hxβ© := PGame.bddBelow_range_of_small (Quotient.out β f)
refine β¨β¦xβ§, Set.forall_mem_range.2 fun i β¦ ?_β©
simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i
/-- A small set of games is bounded below. -/
lemma bddBelow_of_small (s : Set Game.{u}) [Small.{u} s] : BddBelow s := by
simpa using bddBelow_range_of_small (Subtype.val : s β Game.{u})
end Game
namespace PGame
@[simp] theorem quot_zero : (β¦0β§ : Game) = 0 := rfl
@[simp] theorem quot_one : (β¦1β§ : Game) = 1 := rfl
@[simp] theorem quot_neg (a : PGame) : (β¦-aβ§ : Game) = -β¦aβ§ := rfl
@[simp] theorem quot_add (a b : PGame) : β¦a + bβ§ = (β¦aβ§ : Game) + β¦bβ§ := rfl
@[simp] theorem quot_sub (a b : PGame) : β¦a - bβ§ = (β¦aβ§ : Game) - β¦bβ§ := rfl
@[simp]
theorem quot_natCast : β n : β, β¦(n : PGame)β§ = (n : Game)
| 0 => rfl
| n + 1 => by
rw [PGame.nat_succ, quot_add, Nat.cast_add, Nat.cast_one, quot_natCast]
rfl
theorem quot_eq_of_mk'_quot_eq {x y : PGame} (L : x.LeftMoves β y.LeftMoves)
(R : x.RightMoves β y.RightMoves) (hl : β i, (β¦x.moveLeft iβ§ : Game) = β¦y.moveLeft (L i)β§)
(hr : β j, (β¦x.moveRight jβ§ : Game) = β¦y.moveRight (R j)β§) : (β¦xβ§ : Game) = β¦yβ§ :=
game_eq (.of_equiv L R (fun _ => equiv_iff_game_eq.2 (hl _))
(fun _ => equiv_iff_game_eq.2 (hr _)))
/-! Multiplicative operations can be defined at the level of pre-games,
but to prove their properties we need to use the abelian group structure of games.
Hence we define them here. -/
/-- The product of `x = {xL | xR}` and `y = {yL | yR}` is
`{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, xR*y + x*yL - xR*yL}`. -/
instance : Mul PGame.{u} :=
β¨fun x y => by
induction x generalizing y with | mk xl xr _ _ IHxl IHxr => _
induction y with | mk yl yr yL yR IHyl IHyr => _
have y := mk yl yr yL yR
refine β¨(xl Γ yl) β (xr Γ yr), (xl Γ yr) β (xr Γ yl), ?_, ?_β© <;> rintro (β¨i, jβ© | β¨i, jβ©)
Β· exact IHxl i y + IHyl j - IHxl i (yL j)
Β· exact IHxr i y + IHyr j - IHxr i (yR j)
Β· exact IHxl i y + IHyr j - IHxl i (yR j)
Β· exact IHxr i y + IHyl j - IHxr i (yL j)β©
theorem leftMoves_mul :
β x y : PGame.{u},
(x * y).LeftMoves = (x.LeftMoves Γ y.LeftMoves β x.RightMoves Γ y.RightMoves)
| β¨_, _, _, _β©, β¨_, _, _, _β© => rfl
theorem rightMoves_mul :
β x y : PGame.{u},
(x * y).RightMoves = (x.LeftMoves Γ y.RightMoves β x.RightMoves Γ y.LeftMoves)
| β¨_, _, _, _β©, β¨_, _, _, _β© => rfl
/-- Turns two left or right moves for `x` and `y` into a left move for `x * y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toLeftMovesMul {x y : PGame} :
(x.LeftMoves Γ y.LeftMoves) β (x.RightMoves Γ y.RightMoves) β (x * y).LeftMoves :=
Equiv.cast (leftMoves_mul x y).symm
/-- Turns a left and a right move for `x` and `y` into a right move for `x * y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toRightMovesMul {x y : PGame} :
(x.LeftMoves Γ y.RightMoves) β (x.RightMoves Γ y.LeftMoves) β (x * y).RightMoves :=
Equiv.cast (rightMoves_mul x y).symm
@[simp]
theorem mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inl (i, j)) =
xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j :=
rfl
@[simp]
theorem mul_moveLeft_inl {x y : PGame} {i j} :
(x * y).moveLeft (toLeftMovesMul (Sum.inl (i, j))) =
x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inr (i, j)) =
xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j :=
rfl
@[simp]
theorem mul_moveLeft_inr {x y : PGame} {i j} :
(x * y).moveLeft (toLeftMovesMul (Sum.inr (i, j))) =
x.moveRight i * y + x * y.moveRight j - x.moveRight i * y.moveRight j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inl (i, j)) =
xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j :=
rfl
@[simp]
theorem mul_moveRight_inl {x y : PGame} {i j} :
(x * y).moveRight (toRightMovesMul (Sum.inl (i, j))) =
x.moveLeft i * y + x * y.moveRight j - x.moveLeft i * y.moveRight j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inr (i, j)) =
xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j :=
rfl
@[simp]
theorem mul_moveRight_inr {x y : PGame} {i j} :
(x * y).moveRight (toRightMovesMul (Sum.inr (i, j))) =
x.moveRight i * y + x * y.moveLeft j - x.moveRight i * y.moveLeft j := by
cases x
cases y
rfl
@[simp]
theorem neg_mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inl (i, j)) =
-(xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j) :=
rfl
@[simp]
theorem neg_mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inr (i, j)) =
-(xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j) :=
rfl
@[simp]
theorem neg_mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inl (i, j)) =
-(xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j) :=
rfl
@[simp]
theorem neg_mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inr (i, j)) =
-(xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j) :=
rfl
theorem leftMoves_mul_cases {x y : PGame} (k) {P : (x * y).LeftMoves β Prop}
(hl : β ix iy, P <| toLeftMovesMul (Sum.inl β¨ix, iyβ©))
(hr : β jx jy, P <| toLeftMovesMul (Sum.inr β¨jx, jyβ©)) : P k := by
rw [β toLeftMovesMul.apply_symm_apply k]
rcases toLeftMovesMul.symm k with (β¨ix, iyβ© | β¨jx, jyβ©)
Β· apply hl
Β· apply hr
theorem rightMoves_mul_cases {x y : PGame} (k) {P : (x * y).RightMoves β Prop}
(hl : β ix jy, P <| toRightMovesMul (Sum.inl β¨ix, jyβ©))
(hr : β jx iy, P <| toRightMovesMul (Sum.inr β¨jx, iyβ©)) : P k := by
rw [β toRightMovesMul.apply_symm_apply k]
rcases toRightMovesMul.symm k with (β¨ix, iyβ© | β¨jx, jyβ©)
Β· apply hl
Β· apply hr
/-- `x * y` and `y * x` have the same moves. -/
protected lemma mul_comm (x y : PGame) : x * y β‘ y * x :=
match x, y with
| β¨xl, xr, xL, xRβ©, β¨yl, yr, yL, yRβ© => by
refine Identical.of_equiv ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _))
((Equiv.sumComm _ _).trans ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _))) ?_ ?_ <;>
Β· rintro (β¨_, _β© | β¨_, _β©) <;>
exact ((((PGame.mul_comm _ (mk _ _ _ _)).add (PGame.mul_comm (mk _ _ _ _) _)).trans
(PGame.add_comm _ _)).sub (PGame.mul_comm _ _))
termination_by (x, y)
/-- `x * y` and `y * x` have the same moves. -/
def mulCommRelabelling (x y : PGame.{u}) : x * y β‘r y * x :=
match x, y with
| β¨xl, xr, xL, xRβ©, β¨yl, yr, yL, yRβ© => by
refine β¨Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _),
(Equiv.sumComm _ _).trans (Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _)), ?_, ?_β©
<;>
rintro (β¨i, jβ© | β¨i, jβ©) <;>
{ dsimp
exact ((addCommRelabelling _ _).trans <|
(mulCommRelabelling _ _).addCongr (mulCommRelabelling _ _)).subCongr
(mulCommRelabelling _ _) }
termination_by (x, y)
theorem quot_mul_comm (x y : PGame.{u}) : (β¦x * yβ§ : Game) = β¦y * xβ§ :=
game_eq (x.mul_comm y).equiv
/-- `x * y` is equivalent to `y * x`. -/
theorem mul_comm_equiv (x y : PGame) : x * y β y * x :=
Quotient.exact <| quot_mul_comm _ _
instance isEmpty_leftMoves_mul (x y : PGame.{u})
[IsEmpty (x.LeftMoves Γ y.LeftMoves β x.RightMoves Γ y.RightMoves)] :
IsEmpty (x * y).LeftMoves := by
cases x
cases y
assumption
instance isEmpty_rightMoves_mul (x y : PGame.{u})
[IsEmpty (x.LeftMoves Γ y.RightMoves β x.RightMoves Γ y.LeftMoves)] :
IsEmpty (x * y).RightMoves := by
cases x
cases y
assumption
/-- `x * 0` has exactly the same moves as `0`. -/
protected lemma mul_zero (x : PGame) : x * 0 β‘ 0 := identical_zero _
/-- `x * 0` has exactly the same moves as `0`. -/
def mulZeroRelabelling (x : PGame) : x * 0 β‘r 0 :=
Relabelling.isEmpty _
/-- `x * 0` is equivalent to `0`. -/
theorem mul_zero_equiv (x : PGame) : x * 0 β 0 :=
x.mul_zero.equiv
@[simp]
theorem quot_mul_zero (x : PGame) : (β¦x * 0β§ : Game) = 0 :=
game_eq x.mul_zero_equiv
/-- `0 * x` has exactly the same moves as `0`. -/
protected lemma zero_mul (x : PGame) : 0 * x β‘ 0 := identical_zero _
/-- `0 * x` has exactly the same moves as `0`. -/
def zeroMulRelabelling (x : PGame) : 0 * x β‘r 0 :=
Relabelling.isEmpty _
/-- `0 * x` is equivalent to `0`. -/
theorem zero_mul_equiv (x : PGame) : 0 * x β 0 :=
x.zero_mul.equiv
@[simp]
theorem quot_zero_mul (x : PGame) : (β¦0 * xβ§ : Game) = 0 :=
game_eq x.zero_mul_equiv
/-- `-x * y` and `-(x * y)` have the same moves. -/
def negMulRelabelling (x y : PGame.{u}) : -x * y β‘r -(x * y) :=
match x, y with
| β¨xl, xr, xL, xRβ©, β¨yl, yr, yL, yRβ© => by
refine β¨Equiv.sumComm _ _, Equiv.sumComm _ _, ?_, ?_β© <;>
rintro (β¨i, jβ© | β¨i, jβ©) <;>
Β· dsimp
apply ((negAddRelabelling _ _).trans _).symm
apply ((negAddRelabelling _ _).trans (Relabelling.addCongr _ _)).subCongr
-- Porting note: we used to just do `<;> exact (negMulRelabelling _ _).symm` from here.
Β· exact (negMulRelabelling _ _).symm
Β· exact (negMulRelabelling _ _).symm
-- Porting note: not sure what has gone wrong here.
-- The goal is hideous here, and the `exact` doesn't work,
-- but if we just `change` it to look like the mathlib3 goal then we're fine!?
change -(mk xl xr xL xR * _) β‘r _
exact (negMulRelabelling _ _).symm
termination_by (x, y)
/-- `x * -y` and `-(x * y)` have the same moves. -/
@[simp]
lemma mul_neg (x y : PGame) : x * -y = -(x * y) :=
match x, y with
| mk xl xr xL xR, mk yl yr yL yR => by
refine ext rfl rfl ?_ ?_ <;> rintro (β¨i, jβ© | β¨i, jβ©) _ β¨rflβ©
all_goals
dsimp
rw [PGame.neg_sub', PGame.neg_add]
congr
exacts [mul_neg _ (mk ..), mul_neg .., mul_neg ..]
termination_by (x, y)
/-- `-x * y` and `-(x * y)` have the same moves. -/
lemma neg_mul (x y : PGame) : -x * y β‘ -(x * y) :=
((PGame.mul_comm _ _).trans (of_eq (mul_neg _ _))).trans (PGame.mul_comm _ _).neg
@[simp]
theorem quot_neg_mul (x y : PGame) : (β¦-x * yβ§ : Game) = -β¦x * yβ§ :=
game_eq (x.neg_mul y).equiv
/-- `x * -y` and `-(x * y)` have the same moves. -/
def mulNegRelabelling (x y : PGame) : x * -y β‘r -(x * y) :=
(mulCommRelabelling x _).trans <| (negMulRelabelling _ x).trans (mulCommRelabelling y x).negCongr
theorem quot_mul_neg (x y : PGame) : β¦x * -yβ§ = (-β¦x * yβ§ : Game) :=
game_eq (by rw [mul_neg])
theorem quot_neg_mul_neg (x y : PGame) : β¦-x * -yβ§ = (β¦x * yβ§ : Game) := by simp
@[simp]
theorem quot_left_distrib (x y z : PGame) : (β¦x * (y + z)β§ : Game) = β¦x * yβ§ + β¦x * zβ§ :=
match x, y, z with
| mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by
let x := mk xl xr xL xR
let y := mk yl yr yL yR
let z := mk zl zr zL zR
refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_
Β· fconstructor
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;>
-- Porting note: we've increased `maxDepth` here from `5` to `6`.
-- Likely this sort of off-by-one error is just a change in the implementation
-- of `solve_by_elim`.
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;> rfl
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;> rfl
Β· fconstructor
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;> rfl
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;> rfl
-- Porting note: explicitly wrote out arguments to each recursive
-- quot_left_distrib reference below, because otherwise the decreasing_by block
-- failed. Previously, each branch ended with: `simp [quot_left_distrib]; abel`
-- See https://github.com/leanprover/lean4/issues/2288
Β· rintro (β¨i, j | kβ© | β¨i, j | kβ©)
Β· change
β¦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)β§ =
β¦xL i * y + x * yL j - xL i * yL j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_left_distrib (xL i) (yL j) (mk zl zr zL zR)]
abel
Β· change
β¦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)β§ =
β¦x * y + (xL i * z + x * zL k - xL i * zL k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zL k)]
abel
Β· change
β¦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)β§ =
β¦xR i * y + x * yR j - xR i * yR j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_left_distrib (xR i) (yR j) (mk zl zr zL zR)]
abel
Β· change
β¦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)β§ =
β¦x * y + (xR i * z + x * zR k - xR i * zR k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zR k)]
abel
Β· rintro (β¨i, j | kβ© | β¨i, j | kβ©)
Β· change
β¦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)β§ =
β¦xL i * y + x * yR j - xL i * yR j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_left_distrib (xL i) (yR j) (mk zl zr zL zR)]
abel
Β· change
β¦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)β§ =
β¦x * y + (xL i * z + x * zR k - xL i * zR k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zR k)]
abel
Β· change
β¦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)β§ =
β¦xR i * y + x * yL j - xR i * yL j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_left_distrib (xR i) (yL j) (mk zl zr zL zR)]
abel
Β· change
β¦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)β§ =
β¦x * y + (xR i * z + x * zL k - xR i * zL k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zL k)]
abel
termination_by (x, y, z)
/-- `x * (y + z)` is equivalent to `x * y + x * z`. -/
theorem left_distrib_equiv (x y z : PGame) : x * (y + z) β x * y + x * z :=
Quotient.exact <| quot_left_distrib _ _ _
@[simp]
theorem quot_left_distrib_sub (x y z : PGame) : (β¦x * (y - z)β§ : Game) = β¦x * yβ§ - β¦x * zβ§ := by
change (β¦x * (y + -z)β§ : Game) = β¦x * yβ§ + -β¦x * zβ§
rw [quot_left_distrib, quot_mul_neg]
@[simp]
theorem quot_right_distrib (x y z : PGame) : (β¦(x + y) * zβ§ : Game) = β¦x * zβ§ + β¦y * zβ§ := by
simp only [quot_mul_comm, quot_left_distrib]
/-- `(x + y) * z` is equivalent to `x * z + y * z`. -/
theorem right_distrib_equiv (x y z : PGame) : (x + y) * z β x * z + y * z :=
Quotient.exact <| quot_right_distrib _ _ _
@[simp]
theorem quot_right_distrib_sub (x y z : PGame) : (β¦(y - z) * xβ§ : Game) = β¦y * xβ§ - β¦z * xβ§ := by
change (β¦(y + -z) * xβ§ : Game) = β¦y * xβ§ + -β¦z * xβ§
rw [quot_right_distrib, quot_neg_mul]
/-- `x * 1` has the same moves as `x`. -/
def mulOneRelabelling : β x : PGame.{u}, x * 1 β‘r x
| β¨xl, xr, xL, xRβ© => by
-- Porting note: the next four lines were just `unfold has_one.one,`
show _ * One.one β‘r _
unfold One.one
unfold instOnePGame
change mk _ _ _ _ * mk _ _ _ _ β‘r _
refine β¨(Equiv.sumEmpty _ _).trans (Equiv.prodPUnit _),
(Equiv.emptySum _ _).trans (Equiv.prodPUnit _), ?_, ?_β© <;>
(try rintro (β¨i, β¨β©β© | β¨i, β¨β©β©)) <;>
{ dsimp
apply (Relabelling.subCongr (Relabelling.refl _) (mulZeroRelabelling _)).trans
rw [sub_zero_eq_add_zero]
exact (addZeroRelabelling _).trans <|
(((mulOneRelabelling _).addCongr (mulZeroRelabelling _)).trans <| addZeroRelabelling _) }
/-- `1 * x` has the same moves as `x`. -/
protected lemma one_mul : β (x : PGame), 1 * x β‘ x
| β¨xl, xr, xL, xRβ© => by
refine Identical.of_equiv ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _))
((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ?_ ?_ <;>
Β· rintro (β¨β¨β©, _β© | β¨β¨β©, _β©)
exact ((((PGame.zero_mul (mk _ _ _ _)).add (PGame.one_mul _)).trans (PGame.zero_add _)).sub
(PGame.zero_mul _)).trans (PGame.sub_zero _)
/-- `x * 1` has the same moves as `x`. -/
protected lemma mul_one (x : PGame) : x * 1 β‘ x := (x.mul_comm _).trans x.one_mul
@[simp]
theorem quot_mul_one (x : PGame) : (β¦x * 1β§ : Game) = β¦xβ§ :=
game_eq x.mul_one.equiv
/-- `x * 1` is equivalent to `x`. -/
theorem mul_one_equiv (x : PGame) : x * 1 β x :=
Quotient.exact <| quot_mul_one x
/-- `1 * x` has the same moves as `x`. -/
def oneMulRelabelling (x : PGame) : 1 * x β‘r x :=
(mulCommRelabelling 1 x).trans <| mulOneRelabelling x
@[simp]
theorem quot_one_mul (x : PGame) : (β¦1 * xβ§ : Game) = β¦xβ§ :=
game_eq x.one_mul.equiv
/-- `1 * x` is equivalent to `x`. -/
theorem one_mul_equiv (x : PGame) : 1 * x β x :=
Quotient.exact <| quot_one_mul x
theorem quot_mul_assoc (x y z : PGame) : (β¦x * y * zβ§ : Game) = β¦x * (y * z)β§ :=
match x, y, z with
| mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by
let x := mk xl xr xL xR
let y := mk yl yr yL yR
let z := mk zl zr zL zR
refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_
Β· fconstructor
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;>
-- Porting note: as above, increased the `maxDepth` here by 1.
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;> rfl
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;> rfl
Β· fconstructor
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;> rfl
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;> rfl
-- Porting note: explicitly wrote out arguments to each recursive
-- quot_mul_assoc reference below, because otherwise the decreasing_by block
-- failed. Each branch previously ended with: `simp [quot_mul_assoc]; abel`
-- See https://github.com/leanprover/lean4/issues/2288
Β· rintro (β¨β¨i, jβ© | β¨i, jβ©, kβ© | β¨β¨i, jβ© | β¨i, jβ©, kβ©)
Β· change
β¦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zL k -
(xL i * y + x * yL j - xL i * yL j) * zL kβ§ =
β¦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) -
xL i * (yL j * z + y * zL k - yL j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)]
rw [quot_mul_assoc (xL i) (yL j) (zL k)]
abel
Β· change
β¦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zL k -
(xR i * y + x * yR j - xR i * yR j) * zL kβ§ =
β¦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) -
xR i * (yR j * z + y * zL k - yR j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)]
rw [quot_mul_assoc (xR i) (yR j) (zL k)]
abel
Β· change
β¦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zR k -
(xL i * y + x * yR j - xL i * yR j) * zR kβ§ =
β¦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) -
xL i * (yR j * z + y * zR k - yR j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)]
rw [quot_mul_assoc (xL i) (yR j) (zR k)]
abel
Β· change
β¦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zR k -
(xR i * y + x * yL j - xR i * yL j) * zR kβ§ =
β¦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) -
xR i * (yL j * z + y * zR k - yL j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)]
rw [quot_mul_assoc (xR i) (yL j) (zR k)]
abel
Β· rintro (β¨β¨i, jβ© | β¨i, jβ©, kβ© | β¨β¨i, jβ© | β¨i, jβ©, kβ©)
Β· change
β¦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zR k -
(xL i * y + x * yL j - xL i * yL j) * zR kβ§ =
β¦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) -
xL i * (yL j * z + y * zR k - yL j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)]
rw [quot_mul_assoc (xL i) (yL j) (zR k)]
abel
Β· change
β¦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zR k -
(xR i * y + x * yR j - xR i * yR j) * zR kβ§ =
β¦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) -
xR i * (yR j * z + y * zR k - yR j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)]
rw [quot_mul_assoc (xR i) (yR j) (zR k)]
abel
Β· change
β¦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zL k -
(xL i * y + x * yR j - xL i * yR j) * zL kβ§ =
β¦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) -
xL i * (yR j * z + y * zL k - yR j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)]
rw [quot_mul_assoc (xL i) (yR j) (zL k)]
abel
Β· change
β¦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zL k -
(xR i * y + x * yL j - xR i * yL j) * zL kβ§ =
β¦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) -
xR i * (yL j * z + y * zL k - yL j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)]
rw [quot_mul_assoc (xR i) (yL j) (zL k)]
abel
termination_by (x, y, z)
/-- `x * y * z` is equivalent to `x * (y * z)`. -/
theorem mul_assoc_equiv (x y z : PGame) : x * y * z β x * (y * z) :=
Quotient.exact <| quot_mul_assoc _ _ _
/-- The left options of `x * y` of the first kind, i.e. of the form `xL * y + x * yL - xL * yL`. -/
def mulOption (x y : PGame) (i : LeftMoves x) (j : LeftMoves y) : PGame :=
x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j
/-- Any left option of `x * y` of the first kind is also a left option of `x * -(-y)` of
the first kind. -/
lemma mulOption_neg_neg {x} (y) {i j} :
mulOption x y i j = mulOption x (-(-y)) i (toLeftMovesNeg <| toRightMovesNeg j) := by
simp [mulOption]
/-- The left options of `x * y` agree with that of `y * x` up to equivalence. -/
lemma mulOption_symm (x y) {i j} : β¦mulOption x y i jβ§ = (β¦mulOption y x j iβ§ : Game) := by
dsimp only [mulOption, quot_sub, quot_add]
rw [add_comm]
congr 1
on_goal 1 => congr 1
all_goals rw [quot_mul_comm]
/-- The left options of `x * y` of the second kind are the left options of `(-x) * (-y)` of the
first kind, up to equivalence. -/
lemma leftMoves_mul_iff {x y : PGame} (P : Game β Prop) :
(β k, P β¦(x * y).moveLeft kβ§) β
(β i j, P β¦mulOption x y i jβ§) β§ (β i j, P β¦mulOption (-x) (-y) i jβ§) := by
cases x; cases y
constructor <;> intro h
on_goal 1 =>
constructor <;> intros i j
Β· exact h (Sum.inl (i, j))
convert h (Sum.inr (i, j)) using 1
on_goal 2 =>
rintro (β¨i, jβ© | β¨i, jβ©)
Β· exact h.1 i j
convert h.2 i j using 1
all_goals
dsimp only [mk_mul_moveLeft_inr, quot_sub, quot_add, neg_def, mulOption, moveLeft_mk]
rw [β neg_def, β neg_def]
congr 1
on_goal 1 => congr 1
all_goals rw [quot_neg_mul_neg]
/-- The right options of `x * y` are the left options of `x * (-y)` and of `(-x) * y` of the first
kind, up to equivalence. -/
lemma rightMoves_mul_iff {x y : PGame} (P : Game β Prop) :
(β k, P β¦(x * y).moveRight kβ§) β
(β i j, P (-β¦mulOption x (-y) i jβ§)) β§ (β i j, P (-β¦mulOption (-x) y i jβ§)) := by
cases x; cases y
constructor <;> intro h
on_goal 1 =>
constructor <;> intros i j
on_goal 1 => convert h (Sum.inl (i, j))
on_goal 2 => convert h (Sum.inr (i, j))
on_goal 3 =>
rintro (β¨i, jβ© | β¨i, jβ©)
on_goal 1 => convert h.1 i j using 1
on_goal 2 => convert h.2 i j using 1
all_goals
dsimp [mulOption]
rw [neg_sub', neg_add, β neg_def]
congr 1
on_goal 1 => congr 1
any_goals rw [quot_neg_mul, neg_neg]
iterate 6 rw [quot_mul_neg, neg_neg]
/-- Because the two halves of the definition of `inv` produce more elements
on each side, we have to define the two families inductively.
This is the indexing set for the function, and `invVal` is the function part. -/
inductive InvTy (l r : Type u) : Bool β Type u
| zero : InvTy l r false
| leftβ : r β InvTy l r false β InvTy l r false
| leftβ : l β InvTy l r true β InvTy l r false
| rightβ : l β InvTy l r false β InvTy l r true
| rightβ : r β InvTy l r true β InvTy l r true
instance (l r : Type u) [IsEmpty l] [IsEmpty r] : IsEmpty (InvTy l r true) :=
β¨by rintro (_ | _ | _ | a | a) <;> exact isEmptyElim aβ©
instance InvTy.instInhabited (l r : Type u) : Inhabited (InvTy l r false) :=
β¨InvTy.zeroβ©
instance uniqueInvTy (l r : Type u) [IsEmpty l] [IsEmpty r] : Unique (InvTy l r false) :=
{ InvTy.instInhabited l r with
uniq := by
rintro (a | a | a)
Β· rfl
all_goals exact isEmptyElim a }
/-- Because the two halves of the definition of `inv` produce more elements
of each side, we have to define the two families inductively.
This is the function part, defined by recursion on `InvTy`. -/
def invVal {l r} (L : l β PGame) (R : r β PGame) (IHl : l β PGame) (IHr : r β PGame)
(x : PGame) : β {b}, InvTy l r b β PGame
| _, InvTy.zero => 0
| _, InvTy.leftβ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i
| _, InvTy.leftβ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i
| _, InvTy.rightβ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i
| _, InvTy.rightβ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i
@[simp]
theorem invVal_isEmpty {l r : Type u} {b} (L R IHl IHr) (i : InvTy l r b) (x) [IsEmpty l]
[IsEmpty r] : invVal L R IHl IHr x i = 0 := by
obtain - | a | a | a | a := i
Β· rfl
all_goals exact isEmptyElim a
/-- The inverse of a positive surreal number `x = {L | R}` is
given by `xβ»ΒΉ = {0,
(1 + (R - x) * xβ»ΒΉL) * R, (1 + (L - x) * xβ»ΒΉR) * L |
(1 + (L - x) * xβ»ΒΉL) * L, (1 + (R - x) * xβ»ΒΉR) * R}`.
Because the two halves `xβ»ΒΉL, xβ»ΒΉR` of `xβ»ΒΉ` are used in their own
definition, the sets and elements are inductively generated. -/
def inv' : PGame β PGame
| β¨l, r, L, Rβ© =>
let l' := { i // 0 < L i }
let L' : l' β PGame := fun i => L i.1
let IHl' : l' β PGame := fun i => inv' (L i.1)
let IHr i := inv' (R i)
let x := mk l r L R
β¨InvTy l' r false, InvTy l' r true, invVal L' R IHl' IHr x, invVal L' R IHl' IHr xβ©
theorem zero_lf_inv' : β x : PGame, 0 β§ inv' x
| β¨xl, xr, xL, xRβ© => by
convert lf_mk _ _ InvTy.zero
rfl
/-- `inv' 0` has exactly the same moves as `1`. -/
def inv'Zero : inv' 0 β‘r 1 := by
change mk _ _ _ _ β‘r 1
refine β¨?_, ?_, fun i => ?_, IsEmpty.elim ?_β©
Β· apply Equiv.equivPUnit (InvTy _ _ _)
Β· apply Equiv.equivPEmpty (InvTy _ _ _)
Β· -- Porting note: we added `rfl` after the `simp`
-- (because `simp` now uses `rfl` only at reducible transparency)
-- Can we improve the simp set so it is not needed?
simp; rfl
Β· dsimp
infer_instance
theorem inv'_zero_equiv : inv' 0 β 1 :=
inv'Zero.equiv
/-- `inv' 1` has exactly the same moves as `1`. -/
lemma inv'_one : inv' 1 β‘ 1 := by
rw [Identical.ext_iff]
constructor
Β· simp [memβ_def, inv', isEmpty_subtype]
Β· simp [memα΅£_def, inv', isEmpty_subtype]
/-- `inv' 1` has exactly the same moves as `1`. -/
| def inv'One : inv' 1 β‘r (1 : PGame.{u}) := by
change Relabelling (mk _ _ _ _) 1
have : IsEmpty { _i : PUnit.{u + 1} // (0 : PGame.{u}) < 0 } := by
rw [lt_self_iff_false]
| Mathlib/SetTheory/Game/Basic.lean | 975 | 978 |
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Order.Filter.Tendsto
import Mathlib.Data.PFun
/-!
# `Tendsto` for relations and partial functions
This file generalizes `Filter` definitions from functions to partial functions and relations.
## Considering functions and partial functions as relations
A function `f : Ξ± β Ξ²` can be considered as the relation `Rel Ξ± Ξ²` which relates `x` and `f x` for
all `x`, and nothing else. This relation is called `Function.Graph f`.
A partial function `f : Ξ± β. Ξ²` can be considered as the relation `Rel Ξ± Ξ²` which relates `x` and
`f x` for all `x` for which `f x` exists, and nothing else. This relation is called
`PFun.Graph' f`.
In this regard, a function is a relation for which every element in `Ξ±` is related to exactly one
element in `Ξ²` and a partial function is a relation for which every element in `Ξ±` is related to at
most one element in `Ξ²`.
This file leverages this analogy to generalize `Filter` definitions from functions to partial
functions and relations.
## Notes
`Set.preimage` can be generalized to relations in two ways:
* `Rel.preimage` returns the image of the set under the inverse relation.
* `Rel.core` returns the set of elements that are only related to those in the set.
Both generalizations are sensible in the context of filters, so `Filter.comap` and `Filter.Tendsto`
get two generalizations each.
We first take care of relations. Then the definitions for partial functions are taken as special
cases of the definitions for relations.
-/
universe u v w
namespace Filter
variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w}
open Filter
/-! ### Relations -/
/-- The forward map of a filter under a relation. Generalization of `Filter.map` to relations. Note
that `Rel.core` generalizes `Set.preimage`. -/
def rmap (r : Rel Ξ± Ξ²) (l : Filter Ξ±) : Filter Ξ² where
sets := { s | r.core s β l }
univ_sets := by simp
sets_of_superset hs st := mem_of_superset hs (Rel.core_mono _ st)
inter_sets hs ht := by
simp only [Set.mem_setOf_eq]
convert inter_mem hs ht
rw [β Rel.core_inter]
theorem rmap_sets (r : Rel Ξ± Ξ²) (l : Filter Ξ±) : (l.rmap r).sets = r.core β»ΒΉ' l.sets :=
rfl
@[simp]
theorem mem_rmap (r : Rel Ξ± Ξ²) (l : Filter Ξ±) (s : Set Ξ²) : s β l.rmap r β r.core s β l :=
Iff.rfl
@[simp]
theorem rmap_rmap (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) (l : Filter Ξ±) :
rmap s (rmap r l) = rmap (r.comp s) l :=
filter_eq <| by simp [rmap_sets, Set.preimage, Rel.core_comp]
@[simp]
theorem rmap_compose (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) : rmap s β rmap r = rmap (r.comp s) :=
funext <| rmap_rmap _ _
/-- Generic "limit of a relation" predicate. `RTendsto r lβ lβ` asserts that for every
`lβ`-neighborhood `a`, the `r`-core of `a` is an `lβ`-neighborhood. One generalization of
`Filter.Tendsto` to relations. -/
def RTendsto (r : Rel Ξ± Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :=
lβ.rmap r β€ lβ
theorem rtendsto_def (r : Rel Ξ± Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :
RTendsto r lβ lβ β β s β lβ, r.core s β lβ :=
Iff.rfl
/-- One way of taking the inverse map of a filter under a relation. One generalization of
`Filter.comap` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/
def rcomap (r : Rel Ξ± Ξ²) (f : Filter Ξ²) : Filter Ξ± where
sets := Rel.image (fun s t => r.core s β t) f.sets
univ_sets := β¨Set.univ, univ_mem, Set.subset_univ _β©
sets_of_superset := fun β¨a', ha', ma'aβ© ab => β¨a', ha', ma'a.trans abβ©
inter_sets := fun β¨a', haβ, haββ© β¨b', hbβ, hbββ© =>
β¨a' β© b', inter_mem haβ hbβ, (r.core_inter a' b').subset.trans (Set.inter_subset_inter haβ hbβ)β©
theorem rcomap_sets (r : Rel Ξ± Ξ²) (f : Filter Ξ²) :
(rcomap r f).sets = Rel.image (fun s t => r.core s β t) f.sets :=
rfl
theorem rcomap_rcomap (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) (l : Filter Ξ³) :
rcomap r (rcomap s l) = rcomap (r.comp s) l :=
filter_eq <| by
ext t; simp only [rcomap_sets, Rel.image, Filter.mem_sets, Set.mem_setOf_eq, Rel.core_comp]
constructor
Β· rintro β¨u, β¨v, vsets, hvβ©, hβ©
exact β¨v, vsets, Set.Subset.trans (Rel.core_mono _ hv) hβ©
rintro β¨t, tsets, htβ©
exact β¨Rel.core s t, β¨t, tsets, Set.Subset.rflβ©, htβ©
@[simp]
theorem rcomap_compose (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) : rcomap r β rcomap s = rcomap (r.comp s) :=
funext <| rcomap_rcomap _ _
theorem rtendsto_iff_le_rcomap (r : Rel Ξ± Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :
RTendsto r lβ lβ β lβ β€ lβ.rcomap r := by
rw [rtendsto_def]
simp_rw [β lβ.mem_sets]
constructor
Β· simpa [Filter.le_def, rcomap, Rel.mem_image] using fun h s t tlβ => mem_of_superset (h t tlβ)
Β· simpa [Filter.le_def, rcomap, Rel.mem_image] using fun h t tlβ => h _ t tlβ Set.Subset.rfl
-- Interestingly, there does not seem to be a way to express this relation using a forward map.
-- Given a filter `f` on `Ξ±`, we want a filter `f'` on `Ξ²` such that `r.preimage s β f` if
-- and only if `s β f'`. But the intersection of two sets satisfying the lhs may be empty.
/-- One way of taking the inverse map of a filter under a relation. Generalization of `Filter.comap`
to relations. -/
def rcomap' (r : Rel Ξ± Ξ²) (f : Filter Ξ²) : Filter Ξ± where
sets := Rel.image (fun s t => r.preimage s β t) f.sets
univ_sets := β¨Set.univ, univ_mem, Set.subset_univ _β©
sets_of_superset := fun β¨a', ha', ma'aβ© ab => β¨a', ha', ma'a.trans abβ©
inter_sets := fun β¨a', haβ, haββ© β¨b', hbβ, hbββ© =>
β¨a' β© b', inter_mem haβ hbβ,
(@Rel.preimage_inter _ _ r _ _).trans (Set.inter_subset_inter haβ hbβ)β©
@[simp]
theorem mem_rcomap' (r : Rel Ξ± Ξ²) (l : Filter Ξ²) (s : Set Ξ±) :
s β l.rcomap' r β β t β l, r.preimage t β s :=
Iff.rfl
theorem rcomap'_sets (r : Rel Ξ± Ξ²) (f : Filter Ξ²) :
(rcomap' r f).sets = Rel.image (fun s t => r.preimage s β t) f.sets :=
rfl
@[simp]
theorem rcomap'_rcomap' (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) (l : Filter Ξ³) :
rcomap' r (rcomap' s l) = rcomap' (r.comp s) l :=
Filter.ext fun t => by
simp only [mem_rcomap', Rel.preimage_comp]
constructor
Β· rintro β¨u, β¨v, vsets, hvβ©, hβ©
exact β¨v, vsets, (Rel.preimage_mono _ hv).trans hβ©
rintro β¨t, tsets, htβ©
exact β¨s.preimage t, β¨t, tsets, Set.Subset.rflβ©, htβ©
@[simp]
theorem rcomap'_compose (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) : rcomap' r β rcomap' s = rcomap' (r.comp s) :=
funext <| rcomap'_rcomap' _ _
/-- Generic "limit of a relation" predicate. `RTendsto' r lβ lβ` asserts that for every
`lβ`-neighborhood `a`, the `r`-preimage of `a` is an `lβ`-neighborhood. One generalization of
`Filter.Tendsto` to relations. -/
def RTendsto' (r : Rel Ξ± Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :=
lβ β€ lβ.rcomap' r
theorem rtendsto'_def (r : Rel Ξ± Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :
RTendsto' r lβ lβ β β s β lβ, r.preimage s β lβ := by
unfold RTendsto' rcomap'; constructor
Β· simpa [le_def, Rel.mem_image] using fun h s hs => h _ _ hs Set.Subset.rfl
Β· simpa [le_def, Rel.mem_image] using fun h s t ht => mem_of_superset (h t ht)
theorem tendsto_iff_rtendsto (lβ : Filter Ξ±) (lβ : Filter Ξ²) (f : Ξ± β Ξ²) :
Tendsto f lβ lβ β RTendsto (Function.graph f) lβ lβ := by
simp [tendsto_def, Function.graph, rtendsto_def, Rel.core, Set.preimage]
theorem tendsto_iff_rtendsto' (lβ : Filter Ξ±) (lβ : Filter Ξ²) (f : Ξ± β Ξ²) :
Tendsto f lβ lβ β RTendsto' (Function.graph f) lβ lβ := by
simp [tendsto_def, Function.graph, rtendsto'_def, Rel.preimage_def, Set.preimage]
/-! ### Partial functions -/
/-- The forward map of a filter under a partial function. Generalization of `Filter.map` to partial
functions. -/
def pmap (f : Ξ± β. Ξ²) (l : Filter Ξ±) : Filter Ξ² :=
Filter.rmap f.graph' l
@[simp]
theorem mem_pmap (f : Ξ± β. Ξ²) (l : Filter Ξ±) (s : Set Ξ²) : s β l.pmap f β f.core s β l :=
Iff.rfl
/-- Generic "limit of a partial function" predicate. `PTendsto r lβ lβ` asserts that for every
`lβ`-neighborhood `a`, the `p`-core of `a` is an `lβ`-neighborhood. One generalization of
`Filter.Tendsto` to partial function. -/
def PTendsto (f : Ξ± β. Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :=
lβ.pmap f β€ lβ
theorem ptendsto_def (f : Ξ± β. Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :
PTendsto f lβ lβ β β s β lβ, f.core s β lβ :=
Iff.rfl
theorem ptendsto_iff_rtendsto (lβ : Filter Ξ±) (lβ : Filter Ξ²) (f : Ξ± β. Ξ²) :
PTendsto f lβ lβ β RTendsto f.graph' lβ lβ :=
Iff.rfl
theorem pmap_res (l : Filter Ξ±) (s : Set Ξ±) (f : Ξ± β Ξ²) :
pmap (PFun.res f s) l = map f (l β π s) := by
ext t
simp only [PFun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or]
rfl
theorem tendsto_iff_ptendsto (lβ : Filter Ξ±) (lβ : Filter Ξ²) (s : Set Ξ±) (f : Ξ± β Ξ²) :
Tendsto f (lβ β π s) lβ β PTendsto (PFun.res f s) lβ lβ := by
simp only [Tendsto, PTendsto, pmap_res]
theorem tendsto_iff_ptendsto_univ (lβ : Filter Ξ±) (lβ : Filter Ξ²) (f : Ξ± β Ξ²) :
Tendsto f lβ lβ β PTendsto (PFun.res f Set.univ) lβ lβ := by
rw [β tendsto_iff_ptendsto]
simp [principal_univ]
/-- Inverse map of a filter under a partial function. One generalization of `Filter.comap` to
partial functions. -/
def pcomap' (f : Ξ± β. Ξ²) (l : Filter Ξ²) : Filter Ξ± :=
Filter.rcomap' f.graph' l
/-- Generic "limit of a partial function" predicate. `PTendsto' r lβ lβ` asserts that for every
`lβ`-neighborhood `a`, the `p`-preimage of `a` is an `lβ`-neighborhood. One generalization of
`Filter.Tendsto` to partial functions. -/
def PTendsto' (f : Ξ± β. Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :=
lβ β€ lβ.rcomap' f.graph'
theorem ptendsto'_def (f : Ξ± β. Ξ²) (lβ : Filter Ξ±) (lβ : Filter Ξ²) :
| PTendsto' f lβ lβ β β s β lβ, f.preimage s β lβ :=
rtendsto'_def _ _ _
theorem ptendsto_of_ptendsto' {f : Ξ± β. Ξ²} {lβ : Filter Ξ±} {lβ : Filter Ξ²} :
PTendsto' f lβ lβ β PTendsto f lβ lβ := by
| Mathlib/Order/Filter/Partial.lean | 236 | 240 |
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Order.Group.Pointwise.Interval
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.Rat.Cardinal
import Mathlib.SetTheory.Cardinal.Continuum
/-!
# The cardinality of the reals
This file shows that the real numbers have cardinality continuum, i.e. `#β = π `.
We show that `#β β€ π ` by noting that every real number is determined by a Cauchy-sequence of the
form `β β β`, which has cardinality `π `. To show that `#β β₯ π ` we define an injection from
`{0, 1} ^ β` to `β` with `f β¦ Ξ£ n, f n * (1 / 3) ^ n`.
We conclude that all intervals with distinct endpoints have cardinality continuum.
## Main definitions
* `Cardinal.cantorFunction` is the function that sends `f` in `{0, 1} ^ β` to `β` by
`f β¦ Ξ£' n, f n * (1 / 3) ^ n`
## Main statements
* `Cardinal.mk_real : #β = π `: the reals have cardinality continuum.
* `Cardinal.not_countable_real`: the universal set of real numbers is not countable.
We can use this same proof to show that all the other sets in this file are not countable.
* 8 lemmas of the form `mk_Ixy_real` for `x,y β {i,o,c}` state that intervals on the reals
have cardinality continuum.
## Notation
* `π ` : notation for `Cardinal.continuum` in locale `Cardinal`, defined in `SetTheory.Continuum`.
## Tags
continuum, cardinality, reals, cardinality of the reals
-/
open Nat Set
open Cardinal
noncomputable section
namespace Cardinal
variable {c : β} {f g : β β Bool} {n : β}
/-- The body of the sum in `cantorFunction`.
`cantorFunctionAux c f n = c ^ n` if `f n = true`;
`cantorFunctionAux c f n = 0` if `f n = false`. -/
def cantorFunctionAux (c : β) (f : β β Bool) (n : β) : β :=
cond (f n) (c ^ n) 0
@[simp]
theorem cantorFunctionAux_true (h : f n = true) : cantorFunctionAux c f n = c ^ n := by
simp [cantorFunctionAux, h]
@[simp]
theorem cantorFunctionAux_false (h : f n = false) : cantorFunctionAux c f n = 0 := by
simp [cantorFunctionAux, h]
theorem cantorFunctionAux_nonneg (h : 0 β€ c) : 0 β€ cantorFunctionAux c f n := by
cases h' : f n
Β· simp [h']
Β· simpa [h'] using pow_nonneg h _
theorem cantorFunctionAux_eq (h : f n = g n) :
cantorFunctionAux c f n = cantorFunctionAux c g n := by simp [cantorFunctionAux, h]
theorem cantorFunctionAux_zero (f : β β Bool) : cantorFunctionAux c f 0 = cond (f 0) 1 0 := by
cases h : f 0 <;> simp [h]
theorem cantorFunctionAux_succ (f : β β Bool) :
(fun n => cantorFunctionAux c f (n + 1)) = fun n =>
c * cantorFunctionAux c (fun n => f (n + 1)) n := by
ext n
cases h : f (n + 1) <;> simp [h, _root_.pow_succ']
theorem summable_cantor_function (f : β β Bool) (h1 : 0 β€ c) (h2 : c < 1) :
Summable (cantorFunctionAux c f) := by
apply (summable_geometric_of_lt_one h1 h2).summable_of_eq_zero_or_self
intro n; cases h : f n <;> simp [h]
/-- `cantorFunction c (f : β β Bool)` is `Ξ£ n, f n * c ^ n`, where `true` is interpreted as `1` and
`false` is interpreted as `0`. It is implemented using `cantorFunctionAux`. -/
def cantorFunction (c : β) (f : β β Bool) : β :=
β' n, cantorFunctionAux c f n
theorem cantorFunction_le (h1 : 0 β€ c) (h2 : c < 1) (h3 : β n, f n β g n) :
cantorFunction c f β€ cantorFunction c g := by
apply (summable_cantor_function f h1 h2).tsum_le_tsum _ (summable_cantor_function g h1 h2)
intro n; cases h : f n
Β· simp [h, cantorFunctionAux_nonneg h1]
replace h3 : g n = true := h3 n h; simp [h, h3]
theorem cantorFunction_succ (f : β β Bool) (h1 : 0 β€ c) (h2 : c < 1) :
cantorFunction c f = cond (f 0) 1 0 + c * cantorFunction c fun n => f (n + 1) := by
rw [cantorFunction, (summable_cantor_function f h1 h2).tsum_eq_zero_add]
rw [cantorFunctionAux_succ, tsum_mul_left, cantorFunctionAux, pow_zero, cantorFunction]
/-- `cantorFunction c` is strictly increasing with if `0 < c < 1/2`, if we endow `β β Bool` with a
lexicographic order. The lexicographic order doesn't exist for these infinitary products, so we
explicitly write out what it means. -/
theorem increasing_cantorFunction (h1 : 0 < c) (h2 : c < 1 / 2) {n : β} {f g : β β Bool}
(hn : β k < n, f k = g k) (fn : f n = false) (gn : g n = true) :
cantorFunction c f < cantorFunction c g := by
have h3 : c < 1 := by
apply h2.trans
norm_num
induction' n with n ih generalizing f g
Β· let f_max : β β Bool := fun n => Nat.rec false (fun _ _ => true) n
have hf_max : β n, f n β f_max n := by
intro n hn
cases n
Β· rw [fn] at hn
contradiction
simp [f_max]
let g_min : β β Bool := fun n => Nat.rec true (fun _ _ => false) n
have hg_min : β n, g_min n β g n := by
intro n hn
cases n
Β· rw [gn]
simp at hn
apply (cantorFunction_le (le_of_lt h1) h3 hf_max).trans_lt
refine lt_of_lt_of_le ?_ (cantorFunction_le (le_of_lt h1) h3 hg_min)
have : c / (1 - c) < 1 := by
rw [div_lt_one, lt_sub_iff_add_lt]
Β· convert _root_.add_lt_add h2 h2
norm_num
rwa [sub_pos]
convert this
Β· rw [cantorFunction_succ _ (le_of_lt h1) h3, div_eq_mul_inv, β
tsum_geometric_of_lt_one (le_of_lt h1) h3]
apply zero_add
Β· refine (tsum_eq_single 0 ?_).trans ?_
Β· intro n hn
cases n
Β· contradiction
simp [g_min]
Β· exact cantorFunctionAux_zero _
rw [cantorFunction_succ f (le_of_lt h1) h3, cantorFunction_succ g (le_of_lt h1) h3]
rw [hn 0 <| zero_lt_succ n]
apply add_lt_add_left
rw [mul_lt_mul_left h1]
exact ih (fun k hk => hn _ <| Nat.succ_lt_succ hk) fn gn
/-- `cantorFunction c` is injective if `0 < c < 1/2`. -/
theorem cantorFunction_injective (h1 : 0 < c) (h2 : c < 1 / 2) :
Function.Injective (cantorFunction c) := by
intro f g hfg
classical
contrapose hfg with h
have : β n, f n β g n := Function.ne_iff.mp h
let n := Nat.find this
have hn : β k : β, k < n β f k = g k := by
intro k hk
apply of_not_not
exact Nat.find_min this hk
cases fn : f n
Β· apply _root_.ne_of_lt
refine increasing_cantorFunction h1 h2 hn fn ?_
| apply Bool.eq_true_of_not_eq_false
rw [β fn]
apply Ne.symm
exact Nat.find_spec this
Β· apply _root_.ne_of_gt
refine increasing_cantorFunction h1 h2 (fun k hk => (hn k hk).symm) ?_ fn
apply Bool.eq_false_of_not_eq_true
rw [β fn]
apply Ne.symm
exact Nat.find_spec this
/-- The cardinality of the reals, as a type. -/
theorem mk_real : #β = π := by
apply le_antisymm
Β· rw [Real.equivCauchy.cardinal_eq]
apply mk_quotient_le.trans
apply (mk_subtype_le _).trans_eq
rw [β power_def, mk_nat, mkRat, aleph0_power_aleph0]
Β· convert mk_le_of_injective (cantorFunction_injective _ _)
Β· rw [β power_def, mk_bool, mk_nat, two_power_aleph0]
Β· exact 1 / 3
Β· norm_num
Β· norm_num
/-- The cardinality of the reals, as a set. -/
theorem mk_univ_real : #(Set.univ : Set β) = π := by rw [mk_univ, mk_real]
/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/
instance : Uncountable β := by
rw [β aleph0_lt_mk_iff, mk_real]
| Mathlib/Data/Real/Cardinality.lean | 168 | 197 |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.GCDMonoid.Finset
import Mathlib.Algebra.Polynomial.CancelLeads
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Algebra.Polynomial.FieldDivision
/-!
# GCD structures on polynomials
Definitions and basic results about polynomials over GCD domains, particularly their contents
and primitive polynomials.
## Main Definitions
Let `p : R[X]`.
- `p.content` is the `gcd` of the coefficients of `p`.
- `p.IsPrimitive` indicates that `p.content = 1`.
## Main Results
- `Polynomial.content_mul`:
If `p q : R[X]`, then `(p * q).content = p.content * q.content`.
- `Polynomial.NormalizedGcdMonoid`:
The polynomial ring of a GCD domain is itself a GCD domain.
## Note
This has nothing to do with minimal polynomials of primitive elements in finite fields.
-/
namespace Polynomial
section Primitive
variable {R : Type*} [CommSemiring R]
/-- A polynomial is primitive when the only constant polynomials dividing it are units.
Note: This has nothing to do with minimal polynomials of primitive elements in finite fields. -/
def IsPrimitive (p : R[X]) : Prop :=
β r : R, C r β£ p β IsUnit r
theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive β β r : R, C r β£ p β IsUnit r :=
Iff.rfl
@[simp]
theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h =>
isUnit_C.mp (isUnit_of_dvd_one h)
theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by
rintro r β¨q, hβ©
exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [β coeff_C_mul, β h])
theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p β 0 := by
rintro rfl
exact (hp 0 (dvd_zero (C 0))).ne_zero rfl
theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q β£ p) : IsPrimitive q :=
fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq)
/-- An irreducible nonconstant polynomial over a domain is primitive. -/
theorem _root_.Irreducible.isPrimitive [NoZeroDivisors R]
{p : Polynomial R} (hp : Irreducible p) (hp' : p.natDegree β 0) : p.IsPrimitive := by
rintro r β¨q, hqβ©
suffices Β¬IsUnit q by simpa using ((hp.2 hq).resolve_right this).map Polynomial.constantCoeff
intro H
have hr : r β 0 := by rintro rfl; simp_all
obtain β¨s, hs, rflβ© := Polynomial.isUnit_iff.mp H
simp [hq, Polynomial.natDegree_C_mul hr] at hp'
end Primitive
variable {R : Type*} [CommRing R] [IsDomain R]
section NormalizedGCDMonoid
variable [NormalizedGCDMonoid R]
/-- `p.content` is the `gcd` of the coefficients of `p`. -/
def content (p : R[X]) : R :=
p.support.gcd p.coeff
theorem content_dvd_coeff {p : R[X]} (n : β) : p.content β£ p.coeff n := by
by_cases h : n β p.support
Β· apply Finset.gcd_dvd h
rw [mem_support_iff, Classical.not_not] at h
rw [h]
apply dvd_zero
@[simp]
theorem content_C {r : R} : (C r).content = normalize r := by
rw [content]
by_cases h0 : r = 0
Β· simp [h0]
have h : (C r).support = {0} := support_monomial _ h0
simp [h]
@[simp]
theorem content_zero : content (0 : R[X]) = 0 := by rw [β C_0, content_C, normalize_zero]
@[simp]
theorem content_one : content (1 : R[X]) = 1 := by rw [β C_1, content_C, normalize_one]
theorem content_X_mul {p : R[X]} : content (X * p) = content p := by
rw [content, content, Finset.gcd_def, Finset.gcd_def]
refine congr rfl ?_
have h : (X * p).support = p.support.map β¨Nat.succ, Nat.succ_injectiveβ© := by
ext a
simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne, mem_support_iff]
rcases a with - | a
Β· simp [coeff_X_mul_zero, Nat.succ_ne_zero]
rw [mul_comm, coeff_mul_X]
constructor
Β· intro h
use a
Β· rintro β¨b, β¨h1, h2β©β©
rw [β Nat.succ_injective h2]
apply h1
rw [h]
simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map]
refine congr (congr rfl ?_) rfl
ext a
rw [mul_comm]
simp [coeff_mul_X]
@[simp]
theorem content_X_pow {k : β} : content ((X : R[X]) ^ k) = 1 := by
induction' k with k hi
Β· simp
rw [pow_succ', content_X_mul, hi]
@[simp]
theorem content_X : content (X : R[X]) = 1 := by rw [β mul_one X, content_X_mul, content_one]
theorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by
by_cases h0 : r = 0; Β· simp [h0]
rw [content]; rw [content]; rw [β Finset.gcd_mul_left]
refine congr (congr rfl ?_) ?_ <;> ext <;> simp [h0, mem_support_iff]
@[simp]
theorem content_monomial {r : R} {k : β} : content (monomial k r) = normalize r := by
rw [β C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one]
theorem content_eq_zero_iff {p : R[X]} : content p = 0 β p = 0 := by
rw [content, Finset.gcd_eq_zero_iff]
constructor <;> intro h
Β· ext n
by_cases h0 : n β p.support
Β· rw [h n h0, coeff_zero]
Β· rw [mem_support_iff] at h0
push_neg at h0
simp [h0]
Β· intro x
simp [h]
-- Porting note: this reduced with simp so created `normUnit_content` and put simp on it
theorem normalize_content {p : R[X]} : normalize p.content = p.content :=
Finset.normalize_gcd
@[simp]
theorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by
by_cases hp0 : p.content = 0
Β· simp [hp0]
Β· ext
apply mul_left_cancelβ hp0
rw [β normalize_apply, normalize_content, Units.val_one, mul_one]
theorem content_eq_gcd_range_of_lt (p : R[X]) (n : β) (h : p.natDegree < n) :
p.content = (Finset.range n).gcd p.coeff := by
apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd
Β· rw [Finset.dvd_gcd_iff]
intro i _
apply content_dvd_coeff _
Β· apply Finset.gcd_mono
intro i
simp only [Nat.lt_succ_iff, mem_support_iff, Ne, Finset.mem_range]
contrapose!
intro h1
apply coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le h h1)
theorem content_eq_gcd_range_succ (p : R[X]) :
p.content = (Finset.range p.natDegree.succ).gcd p.coeff :=
content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _)
theorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) :
p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by
by_cases h : p = 0
Β· simp [h]
rw [β leadingCoeff_eq_zero, leadingCoeff, β Ne, β mem_support_iff] at h
rw [content, β Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content,
eraseLead_support]
refine congr rfl (Finset.gcd_congr rfl fun i hi => ?_)
rw [Finset.mem_erase] at hi
rw [eraseLead_coeff, if_neg hi.1]
theorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r β£ p.content β C r β£ p := by
rw [C_dvd_iff_dvd_coeff]
constructor
Β· intro h i
apply h.trans (content_dvd_coeff _)
Β· intro h
rw [content, Finset.dvd_gcd_iff]
intro i _
apply h i
theorem C_content_dvd (p : R[X]) : C p.content β£ p :=
dvd_content_iff_C_dvd.1 dvd_rfl
theorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive β p.content = 1 := by
rw [β normalize_content, normalize_eq_one, IsPrimitive]
simp_rw [β dvd_content_iff_C_dvd]
exact β¨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd hβ©
theorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 :=
isPrimitive_iff_content_eq_one.mp hp
section PrimPart
/-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by
`p.content`. If `p = 0`, then `p.primPart = 1`. -/
noncomputable def primPart (p : R[X]) : R[X] :=
letI := Classical.decEq R
if p = 0 then 1 else Classical.choose (C_content_dvd p)
theorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by
by_cases h : p = 0; Β· simp [h]
rw [primPart, if_neg h, β Classical.choose_spec (C_content_dvd p)]
@[simp]
theorem primPart_zero : primPart (0 : R[X]) = 1 :=
if_pos rfl
theorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by
by_cases h : p = 0; Β· simp [h]
rw [β content_eq_zero_iff] at h
rw [isPrimitive_iff_content_eq_one]
apply mul_left_cancelβ h
conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content]
theorem content_primPart (p : R[X]) : p.primPart.content = 1 :=
p.isPrimitive_primPart.content_eq_one
theorem primPart_ne_zero (p : R[X]) : p.primPart β 0 :=
p.isPrimitive_primPart.ne_zero
theorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by
by_cases h : C p.content = 0
Β· rw [C_eq_zero, content_eq_zero_iff] at h
simp [h]
conv_rhs =>
rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add]
@[simp]
theorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by
rw [β one_mul p.primPart, β C_1, β hp.content_eq_one, β p.eq_C_content_mul_primPart]
theorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by
by_cases h0 : r = 0
Β· simp [h0]
unfold IsUnit
refine
β¨β¨C β(normUnit r)β»ΒΉ, C β(normUnit r), by rw [β RingHom.map_mul, Units.inv_mul, C_1], by
rw [β RingHom.map_mul, Units.mul_inv, C_1]β©,
?_β©
rw [β normalize_eq_zero, β C_eq_zero] at h0
apply mul_left_cancelβ h0
conv_rhs => rw [β content_C, β (C r).eq_C_content_mul_primPart]
simp only [Units.val_mk, normalize_apply, RingHom.map_mul]
rw [mul_assoc, β RingHom.map_mul, Units.mul_inv, C_1, mul_one]
theorem primPart_dvd (p : R[X]) : p.primPart β£ p :=
Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm
theorem aeval_primPart_eq_zero {S : Type*} [Ring S] [IsDomain S] [Algebra R S]
[NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p β 0) (hp : aeval s p = 0) :
aeval s p.primPart = 0 := by
rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp
have hcont : p.content β 0 := fun h => hpzero (content_eq_zero_iff.1 h)
replace hcont := Function.Injective.ne (FaithfulSMul.algebraMap_injective R S) hcont
rw [map_zero] at hcont
exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp
theorem evalβ_primPart_eq_zero {S : Type*} [CommSemiring S] [IsDomain S] {f : R β+* S}
(hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p β 0) (hp : evalβ f s p = 0) :
evalβ f s p.primPart = 0 := by
rw [eq_C_content_mul_primPart p, evalβ_mul, evalβ_C] at hp
have hcont : p.content β 0 := fun h => hpzero (content_eq_zero_iff.1 h)
replace hcont := Function.Injective.ne hinj hcont
rw [map_zero] at hcont
exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp
end PrimPart
theorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a β£ p - q) :
GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content := by
rw [content_eq_gcd_range_of_lt p (max p.natDegree q.natDegree).succ
(lt_of_le_of_lt (le_max_left _ _) (Nat.lt_succ_self _))]
rw [content_eq_gcd_range_of_lt q (max p.natDegree q.natDegree).succ
(lt_of_le_of_lt (le_max_right _ _) (Nat.lt_succ_self _))]
apply Finset.gcd_eq_of_dvd_sub
intro x _
obtain β¨w, hwβ© := h
use w.coeff x
rw [β coeff_sub, hw, coeff_C_mul]
theorem content_mul_aux {p q : R[X]} :
GCDMonoid.gcd (p * q).eraseLead.content p.leadingCoeff =
GCDMonoid.gcd (p.eraseLead * q).content p.leadingCoeff := by
rw [gcd_comm (content _) _, gcd_comm (content _) _]
apply gcd_content_eq_of_dvd_sub
rw [β self_sub_C_mul_X_pow, β self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add,
sub_sub_cancel, leadingCoeff_mul, RingHom.map_mul, mul_assoc, mul_assoc]
apply dvd_sub (Dvd.intro _ rfl) (Dvd.intro _ rfl)
@[simp]
theorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by
classical
suffices h :
β (n : β) (p q : R[X]), (p * q).degree < n β (p * q).content = p.content * q.content by
apply h
apply lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _))
intro n
induction' n with n ih
Β· intro p q hpq
rw [Nat.cast_zero,
Nat.WithBot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq
rcases hpq with (rfl | rfl) <;> simp
intro p q hpq
by_cases p0 : p = 0
Β· simp [p0]
by_cases q0 : q = 0
Β· simp [q0]
rw [degree_eq_natDegree (mul_ne_zero p0 q0), Nat.cast_lt,
Nat.lt_succ_iff_lt_or_eq, β Nat.cast_lt (Ξ± := WithBot β),
β degree_eq_natDegree (mul_ne_zero p0 q0), natDegree_mul p0 q0] at hpq
rcases hpq with (hlt | heq)
Β· apply ih _ _ hlt
rw [β p.natDegree_primPart, β q.natDegree_primPart, β Nat.cast_inj (R := WithBot β),
Nat.cast_add, β degree_eq_natDegree p.primPart_ne_zero,
β degree_eq_natDegree q.primPart_ne_zero] at heq
rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart]
suffices h : (q.primPart * p.primPart).content = 1 by
rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.primPart, mul_assoc, content_C_mul,
content_C_mul, h, mul_one, content_primPart, content_primPart, mul_one, mul_one]
rw [β normalize_content, normalize_eq_one, isUnit_iff_dvd_one,
content_eq_gcd_leadingCoeff_content_eraseLead, leadingCoeff_mul, gcd_comm]
apply (gcd_mul_dvd_mul_gcd _ _ _).trans
rw [content_mul_aux, ih, content_primPart, mul_one, gcd_comm, β
content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart, one_mul,
mul_comm q.primPart, content_mul_aux, ih, content_primPart, mul_one, gcd_comm, β
content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart]
Β· rw [β heq, degree_mul, WithBot.add_lt_add_iff_right]
Β· apply degree_erase_lt p.primPart_ne_zero
Β· rw [Ne, degree_eq_bot]
apply q.primPart_ne_zero
Β· rw [mul_comm, β heq, degree_mul, WithBot.add_lt_add_iff_left]
Β· apply degree_erase_lt q.primPart_ne_zero
Β· rw [Ne, degree_eq_bot]
apply p.primPart_ne_zero
theorem IsPrimitive.mul {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :
(p * q).IsPrimitive := by
rw [isPrimitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one]
@[simp]
theorem primPart_mul {p q : R[X]} (h0 : p * q β 0) :
(p * q).primPart = p.primPart * q.primPart := by
rw [Ne, β content_eq_zero_iff, β C_eq_zero] at h0
apply mul_left_cancelβ h0
conv_lhs =>
rw [β (p * q).eq_C_content_mul_primPart, p.eq_C_content_mul_primPart,
q.eq_C_content_mul_primPart]
rw [content_mul, RingHom.map_mul]
ring
theorem IsPrimitive.dvd_primPart_iff_dvd {p q : R[X]} (hp : p.IsPrimitive) (hq : q β 0) :
p β£ q.primPart β p β£ q := by
refine β¨fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_primPart.symm), fun h => ?_β©
rcases h with β¨r, rflβ©
apply Dvd.intro _
rw [primPart_mul hq, hp.primPart_eq]
theorem exists_primitive_lcm_of_isPrimitive {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) :
β r : R[X], r.IsPrimitive β§ β s : R[X], p β£ s β§ q β£ s β r β£ s := by
classical
have h : β (n : β) (r : R[X]), r.natDegree = n β§ r.IsPrimitive β§ p β£ r β§ q β£ r :=
β¨(p * q).natDegree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _β©
rcases Nat.find_spec h with β¨r, rdeg, rprim, pr, qrβ©
refine β¨r, rprim, fun s => β¨?_, fun rs => β¨pr.trans rs, qr.trans rsβ©β©β©
suffices hs : β (n : β) (s : R[X]), s.natDegree = n β p β£ s β§ q β£ s β r β£ s from
hs s.natDegree s rfl
clear s
by_contra! con
rcases Nat.find_spec con with β¨s, sdeg, β¨ps, qsβ©, rsβ©
have s0 : s β 0 := by
contrapose! rs
simp [rs]
have hs :=
Nat.find_min' h
| β¨_, s.natDegree_primPart, s.isPrimitive_primPart, (hp.dvd_primPart_iff_dvd s0).2 ps,
(hq.dvd_primPart_iff_dvd s0).2 qsβ©
rw [β rdeg] at hs
| Mathlib/RingTheory/Polynomial/Content.lean | 403 | 405 |
/-
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, Simon Hudon, Mario Carneiro
-/
import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Nat.Init
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.SplitIfs
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {Ξ± Ξ² G M : Type*}
section ite
variable [Pow Ξ± Ξ²]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : Ξ±) (b : p β Ξ²) (c : Β¬ p β Ξ²) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p β Ξ±) (b : Β¬ p β Ξ±) (c : Ξ²) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : Ξ±) (b c : Ξ²) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : Ξ±) (c : Ξ²) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup Ξ±]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· * Β·) := β¨mul_assocβ©
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`."]
theorem comp_mul_left (x y : Ξ±) : (x * Β·) β (y * Β·) = (x * y * Β·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`."]
theorem comp_mul_right (x y : Ξ±) : (Β· * x) β (Β· * y) = (Β· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (Ξ± := G) (Β· * Β·) := β¨mul_commβ©
section MulOneClass
variable [MulOneClass M]
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 β b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * Β·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (Β· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [β mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : β}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m β€ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [β pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m β€ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [β pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n β 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [β pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n β 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [β pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul "If `n β’ x = 0`, then `m β’ x` is the same as `(m % n) β’ x`"]
lemma pow_eq_pow_mod (m : β) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : β n, a * b = 1 β a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : β n : β, (a * Β·)^[n] = (a ^ n * Β·)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : β n : β, (Β· * a)^[n] = (Β· * a ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ', mul_right_iterate]
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * Β·)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (Β· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : β) : β n : β, (fun x : M β¦ x ^ k)^[n] = (Β· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : β n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a β b = 1 := calc
a * b = a β a * b = a * 1 := by rw [mul_one]
_ β b = 1 := mul_left_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left
@[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_eq_self
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b β b = 1 :=
eq_comm.trans mul_eq_left
@[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_right
@[to_additive]
theorem mul_ne_left : a * b β a β b β 1 := mul_eq_left.not
@[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left
@[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_ne_self
@[to_additive]
theorem left_ne_mul : a β a * b β b β 1 := left_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_right
end LeftCancelMonoid
section RightCancelMonoid
variable [RightCancelMonoid M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b β a = 1 := calc
a * b = b β a * b = 1 * b := by rw [one_mul]
_ β a = 1 := mul_right_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right
@[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_eq_self
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b β a = 1 :=
eq_comm.trans mul_eq_right
@[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_left
@[to_additive]
theorem mul_ne_right : a * b β b β a β 1 := mul_eq_right.not
@[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right
@[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_ne_self
@[to_additive]
theorem right_ne_mul : b β a * b β a β 1 := right_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_left
end RightCancelMonoid
section CancelCommMonoid
variable [CancelCommMonoid Ξ±] {a b c d : Ξ±}
@[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c β b = d := by aesop
@[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a β c β b β d := by aesop
end CancelCommMonoid
section InvolutiveInv
variable [InvolutiveInv G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_involutive : Function.Involutive (Inv.inv : G β G) :=
inv_inv
@[to_additive (attr := simp)]
theorem inv_surjective : Function.Surjective (Inv.inv : G β G) :=
inv_involutive.surjective
@[to_additive]
theorem inv_injective : Function.Injective (Inv.inv : G β G) :=
inv_involutive.injective
@[to_additive (attr := simp)]
theorem inv_inj : aβ»ΒΉ = bβ»ΒΉ β a = b :=
inv_injective.eq_iff
@[to_additive]
theorem inv_eq_iff_eq_inv : aβ»ΒΉ = b β a = bβ»ΒΉ :=
β¨fun h => h βΈ (inv_inv a).symm, fun h => h.symm βΈ inv_inv bβ©
variable (G)
@[to_additive]
theorem inv_comp_inv : Inv.inv β Inv.inv = @id G :=
inv_involutive.comp_self
@[to_additive]
theorem leftInverse_inv : LeftInverse (fun a : G β¦ aβ»ΒΉ) fun a β¦ aβ»ΒΉ :=
inv_inv
@[to_additive]
theorem rightInverse_inv : RightInverse (fun a : G β¦ aβ»ΒΉ) fun a β¦ aβ»ΒΉ :=
inv_inv
end InvolutiveInv
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by
rw [div_eq_mul_inv, one_mul, div_eq_mul_inv]
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c :=
(mul_div_assoc _ _ _).symm
@[to_additive]
theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv]
@[to_additive]
theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div]
end DivInvMonoid
section DivInvOneMonoid
variable [DivInvOneMonoid G]
@[to_additive (attr := simp)]
theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv]
@[to_additive]
theorem one_div_one : (1 : G) / 1 = 1 :=
div_one _
end DivInvOneMonoid
section DivisionMonoid
variable [DivisionMonoid Ξ±] {a b c d : Ξ±}
attribute [local simp] mul_assoc div_eq_mul_inv
@[to_additive]
theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = aβ»ΒΉ :=
(inv_eq_of_mul_eq_one_right h).symm
@[to_additive]
theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_left h, one_div]
@[to_additive]
theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_right h, one_div]
@[to_additive]
theorem eq_of_div_eq_one (h : a / b = 1) : a = b :=
inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [β div_eq_mul_inv]
@[to_additive]
lemma eq_of_inv_mul_eq_one (h : aβ»ΒΉ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
lemma eq_of_mul_inv_eq_one (h : a * bβ»ΒΉ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
theorem div_ne_one_of_ne : a β b β a / b β 1 :=
mt eq_of_div_eq_one
variable (a b c)
@[to_additive]
theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp
@[to_additive]
theorem inv_div_left : aβ»ΒΉ / b = (b * a)β»ΒΉ := by simp
@[to_additive (attr := simp)]
theorem inv_div : (a / b)β»ΒΉ = b / a := by simp
@[to_additive]
theorem one_div_div : 1 / (a / b) = b / a := by simp
@[to_additive]
theorem one_div_one_div : 1 / (1 / a) = a := by simp
@[to_additive]
theorem div_eq_div_iff_comm : a / b = c / d β b / a = d / c :=
inv_inj.symm.trans <| by simp only [inv_div]
@[to_additive]
instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid Ξ± :=
{ DivisionMonoid.toDivInvMonoid with
inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : Ξ±) 1).symm }
@[to_additive (attr := simp)]
lemma inv_pow (a : Ξ±) : β n : β, aβ»ΒΉ ^ n = (a ^ n)β»ΒΉ
| 0 => by rw [pow_zero, pow_zero, inv_one]
| n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev]
-- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`.
@[to_additive zsmul_zero, simp]
lemma one_zpow : β n : β€, (1 : Ξ±) ^ n = 1
| (n : β) => by rw [zpow_natCast, one_pow]
| .negSucc n => by rw [zpow_negSucc, one_pow, inv_one]
@[to_additive (attr := simp) neg_zsmul]
lemma zpow_neg (a : Ξ±) : β n : β€, a ^ (-n) = (a ^ n)β»ΒΉ
| (_ + 1 : β) => DivInvMonoid.zpow_neg' _ _
| 0 => by simp
| Int.negSucc n => by
rw [zpow_negSucc, inv_inv, β zpow_natCast]
rfl
@[to_additive neg_one_zsmul_add]
lemma mul_zpow_neg_one (a b : Ξ±) : (a * b) ^ (-1 : β€) = b ^ (-1 : β€) * a ^ (-1 : β€) := by
simp only [zpow_neg, zpow_one, mul_inv_rev]
@[to_additive zsmul_neg]
lemma inv_zpow (a : Ξ±) : β n : β€, aβ»ΒΉ ^ n = (a ^ n)β»ΒΉ
| (n : β) => by rw [zpow_natCast, zpow_natCast, inv_pow]
| .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow]
@[to_additive (attr := simp) zsmul_neg']
lemma inv_zpow' (a : Ξ±) (n : β€) : aβ»ΒΉ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg]
@[to_additive nsmul_zero_sub]
lemma one_div_pow (a : Ξ±) (n : β) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow]
@[to_additive zsmul_zero_sub]
lemma one_div_zpow (a : Ξ±) (n : β€) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow]
variable {a b c}
@[to_additive (attr := simp)]
theorem inv_eq_one : aβ»ΒΉ = 1 β a = 1 :=
inv_injective.eq_iff' inv_one
@[to_additive (attr := simp)]
theorem one_eq_inv : 1 = aβ»ΒΉ β a = 1 :=
eq_comm.trans inv_eq_one
@[to_additive]
theorem inv_ne_one : aβ»ΒΉ β 1 β a β 1 :=
inv_eq_one.not
@[to_additive]
theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by
rw [β one_div_one_div a, h, one_div_one_div]
-- Note that `mul_zsmul` and `zpow_mul` have the primes swapped
-- when additivised since their argument order,
-- and therefore the more "natural" choice of lemma, is reversed.
@[to_additive mul_zsmul'] lemma zpow_mul (a : Ξ±) : β m n : β€, a ^ (m * n) = (a ^ m) ^ n
| (m : β), (n : β) => by
rw [zpow_natCast, zpow_natCast, β pow_mul, β zpow_natCast]
rfl
| (m : β), .negSucc n => by
rw [zpow_natCast, zpow_negSucc, β pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj,
β zpow_natCast]
| .negSucc m, (n : β) => by
rw [zpow_natCast, zpow_negSucc, β inv_pow, β pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow,
inv_inj, β zpow_natCast]
| .negSucc m, .negSucc n => by
rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, β pow_mul, β
zpow_natCast]
rfl
@[to_additive mul_zsmul]
lemma zpow_mul' (a : Ξ±) (m n : β€) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul]
@[to_additive]
theorem zpow_comm (a : Ξ±) (m n : β€) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [β zpow_mul, zpow_mul']
variable (a b c)
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp
@[to_additive (attr := simp)]
theorem div_inv_eq_mul : a / bβ»ΒΉ = a * b := by simp
@[to_additive]
theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by
simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid Ξ±] (a b c d : Ξ±)
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive neg_add]
theorem mul_inv : (a * b)β»ΒΉ = aβ»ΒΉ * bβ»ΒΉ := by simp
@[to_additive]
theorem inv_div' : (a / b)β»ΒΉ = aβ»ΒΉ / bβ»ΒΉ := by simp
@[to_additive]
theorem div_eq_inv_mul : a / b = bβ»ΒΉ * a := by simp
@[to_additive]
theorem inv_mul_eq_div : aβ»ΒΉ * b = b / a := by simp
@[to_additive] lemma inv_div_comm (a b : Ξ±) : aβ»ΒΉ / b = bβ»ΒΉ / a := by simp
@[to_additive]
theorem inv_mul' : (a * b)β»ΒΉ = aβ»ΒΉ / b := by simp
@[to_additive]
theorem inv_div_inv : aβ»ΒΉ / bβ»ΒΉ = b / a := by simp
@[to_additive]
theorem inv_inv_div_inv : (aβ»ΒΉ / bβ»ΒΉ)β»ΒΉ = a / b := by simp
@[to_additive]
theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp
@[to_additive]
theorem div_right_comm : a / b / c = a / c / b := by simp
@[to_additive, field_simps]
theorem div_div : a / b / c = a / (b * c) := by simp
@[to_additive]
theorem div_mul : a / b * c = a / (b / c) := by simp
@[to_additive]
theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp
@[to_additive]
theorem mul_div_right_comm : a * b / c = a / c * b := by simp
@[to_additive]
theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp
@[to_additive, field_simps]
theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp
@[to_additive]
theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp
@[to_additive]
theorem mul_comm_div : a / b * c = a * (c / b) := by simp
@[to_additive]
theorem div_mul_comm : a / b * c = c / b * a := by simp
@[to_additive]
theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp
@[to_additive]
theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp
@[to_additive]
theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp
@[to_additive]
theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp
@[to_additive]
theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp
@[to_additive zsmul_add] lemma mul_zpow : β n : β€, (a * b) ^ n = a ^ n * b ^ n
| (n : β) => by simp_rw [zpow_natCast, mul_pow]
| .negSucc n => by simp_rw [zpow_negSucc, β inv_pow, mul_inv, mul_pow]
@[to_additive nsmul_sub]
lemma div_pow (a b : Ξ±) (n : β) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_pow, inv_pow]
@[to_additive zsmul_sub]
lemma div_zpow (a b : Ξ±) (n : β€) : (a / b) ^ n = a ^ n / b ^ n := by
simp only [div_eq_mul_inv, mul_zpow, inv_zpow]
attribute [field_simps] div_pow div_zpow
end DivisionCommMonoid
section Group
variable [Group G] {a b c d : G} {n : β€}
@[to_additive (attr := simp)]
theorem div_eq_inv_self : a / b = bβ»ΒΉ β a = 1 := by rw [div_eq_mul_inv, mul_eq_right]
@[to_additive]
theorem mul_left_surjective (a : G) : Surjective (a * Β·) :=
fun x β¦ β¨aβ»ΒΉ * x, mul_inv_cancel_left a xβ©
@[to_additive]
theorem mul_right_surjective (a : G) : Function.Surjective fun x β¦ x * a := fun x β¦
β¨x * aβ»ΒΉ, inv_mul_cancel_right x aβ©
@[to_additive]
theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * cβ»ΒΉ := by simp [h.symm]
@[to_additive]
theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = bβ»ΒΉ * c := by simp [h.symm]
@[to_additive]
theorem inv_mul_eq_of_eq_mul (h : b = a * c) : aβ»ΒΉ * b = c := by simp [h]
@[to_additive]
theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * bβ»ΒΉ = c := by simp [h]
@[to_additive]
theorem eq_mul_of_mul_inv_eq (h : a * cβ»ΒΉ = b) : a = b * c := by simp [h.symm]
@[to_additive]
theorem eq_mul_of_inv_mul_eq (h : bβ»ΒΉ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_inv_mul (h : b = aβ»ΒΉ * c) : a * b = c := by rw [h, mul_inv_cancel_left]
@[to_additive]
theorem mul_eq_of_eq_mul_inv (h : a = c * bβ»ΒΉ) : a * b = c := by simp [h]
@[to_additive]
theorem mul_eq_one_iff_eq_inv : a * b = 1 β a = bβ»ΒΉ :=
β¨eq_inv_of_mul_eq_one_left, fun h β¦ by rw [h, inv_mul_cancel]β©
@[to_additive]
theorem mul_eq_one_iff_inv_eq : a * b = 1 β aβ»ΒΉ = b := by
rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv]
/-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_eq_inv' : a * b = 1 β b = aβ»ΒΉ := by
rw [mul_eq_one_iff_inv_eq, eq_comm]
/-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/
@[to_additive]
theorem mul_eq_one_iff_inv_eq' : a * b = 1 β bβ»ΒΉ = a := by
rw [mul_eq_one_iff_eq_inv, eq_comm]
@[to_additive]
theorem eq_inv_iff_mul_eq_one : a = bβ»ΒΉ β a * b = 1 :=
mul_eq_one_iff_eq_inv.symm
@[to_additive]
theorem inv_eq_iff_mul_eq_one : aβ»ΒΉ = b β a * b = 1 :=
mul_eq_one_iff_inv_eq.symm
@[to_additive]
theorem eq_mul_inv_iff_mul_eq : a = b * cβ»ΒΉ β a * c = b :=
β¨fun h β¦ by rw [h, inv_mul_cancel_right], fun h β¦ by rw [β h, mul_inv_cancel_right]β©
@[to_additive]
theorem eq_inv_mul_iff_mul_eq : a = bβ»ΒΉ * c β b * a = c :=
β¨fun h β¦ by rw [h, mul_inv_cancel_left], fun h β¦ by rw [β h, inv_mul_cancel_left]β©
@[to_additive]
theorem inv_mul_eq_iff_eq_mul : aβ»ΒΉ * b = c β b = a * c :=
β¨fun h β¦ by rw [β h, mul_inv_cancel_left], fun h β¦ by rw [h, inv_mul_cancel_left]β©
@[to_additive]
theorem mul_inv_eq_iff_eq_mul : a * bβ»ΒΉ = c β a = c * b :=
β¨fun h β¦ by rw [β h, inv_mul_cancel_right], fun h β¦ by rw [h, mul_inv_cancel_right]β©
@[to_additive]
theorem mul_inv_eq_one : a * bβ»ΒΉ = 1 β a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv]
@[to_additive]
theorem inv_mul_eq_one : aβ»ΒΉ * b = 1 β a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj]
@[to_additive (attr := simp)]
theorem conj_eq_one_iff : a * b * aβ»ΒΉ = 1 β b = 1 := by
rw [mul_inv_eq_one, mul_eq_left]
@[to_additive]
theorem div_left_injective : Function.Injective fun a β¦ a / b := by
-- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`.
simp only [div_eq_mul_inv]
exact fun a a' h β¦ mul_left_injective bβ»ΒΉ h
@[to_additive]
theorem div_right_injective : Function.Injective fun a β¦ b / a := by
-- FIXME see above
simp only [div_eq_mul_inv]
exact fun a a' h β¦ inv_injective (mul_right_injective b h)
@[to_additive (attr := simp)]
lemma div_mul_cancel_right (a b : G) : a / (b * a) = bβ»ΒΉ := by rw [β inv_div, mul_div_cancel_right]
@[to_additive (attr := simp)]
theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by
rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right]
@[to_additive eq_sub_of_add_eq]
theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [β h]
@[to_additive sub_eq_of_eq_add]
theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h]
| Mathlib/Algebra/Group/Basic.lean | 741 | 741 | |
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Group.Subsemigroup.Operations
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Order.Filter.Extr
/-!
# Lemmas about the `sup` and `inf` of the support of `AddMonoidAlgebra`
## TODO
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized for some yet-to-be-defined `degree`s.
-/
variable {R R' A T B ΞΉ : Type*}
namespace AddMonoidAlgebra
/-!
# sup-degree and inf-degree of an `AddMonoidAlgebra`
Let `R` be a semiring and let `A` be a `SemilatticeSup`.
For an element `f : R[A]`, this file defines
* `AddMonoidAlgebra.supDegree`: the sup-degree taking values in `WithBot A`,
* `AddMonoidAlgebra.infDegree`: the inf-degree taking values in `WithTop A`.
If the grading type `A` is a linearly ordered additive monoid, then these two notions of degree
coincide with the standard one:
* the sup-degree is the maximum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `β₯`, if `f = 0`;
* the inf-degree is the minimum of the exponents of the monomials that appear with non-zero
coefficient in `f`, or `β€`, if `f = 0`.
The main results are
* `AddMonoidAlgebra.supDegree_mul_le`:
the sup-degree of a product is at most the sum of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_mul`:
the inf-degree of a product is at least the sum of the inf-degrees,
* `AddMonoidAlgebra.supDegree_add_le`:
the sup-degree of a sum is at most the sup of the sup-degrees,
* `AddMonoidAlgebra.le_infDegree_add`:
the inf-degree of a sum is at least the inf of the inf-degrees.
## Implementation notes
The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a
"generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
Next, the general lemmas get specialized twice:
* once for `supDegree` (essentially a simple application) and
* once for `infDegree` (a simple application, via `OrderDual`).
These final lemmas are the ones that likely get used the most. The generic lemmas about
`Finset.support.sup` may not be used directly much outside of this file.
To see this in action, you can look at the triple
`(sup_support_mul_le, maxDegree_mul_le, le_minDegree_mul)`.
-/
section GeneralResultsAssumingSemilatticeSup
variable [SemilatticeSup B] [OrderBot B] [SemilatticeInf T] [OrderTop T]
section Semiring
variable [Semiring R]
section ExplicitDegrees
/-!
In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in
a type with *b*ot or *t*op respectively.
-/
variable (degb : A β B) (degt : A β T) (f g : R[A])
theorem sup_support_add_le :
(f + g).support.sup degb β€ f.support.sup degb β g.support.sup degb := by
classical
exact (Finset.sup_mono Finsupp.support_add).trans_eq Finset.sup_union
theorem le_inf_support_add : f.support.inf degt β g.support.inf degt β€ (f + g).support.inf degt :=
sup_support_add_le (fun a : A => OrderDual.toDual (degt a)) f g
end ExplicitDegrees
section AddOnly
variable [Add A] [Add B] [Add T] [AddLeftMono B] [AddRightMono B]
[AddLeftMono T] [AddRightMono T]
theorem sup_support_mul_le {degb : A β B} (degbm : β {a b}, degb (a + b) β€ degb a + degb b)
(f g : R[A]) :
(f * g).support.sup degb β€ f.support.sup degb + g.support.sup degb := by
classical
exact (Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds β¦
degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds)
theorem le_inf_support_mul {degt : A β T} (degtm : β {a b}, degt a + degt b β€ degt (a + b))
(f g : R[A]) :
f.support.inf degt + g.support.inf degt β€ (f * g).support.inf degt :=
sup_support_mul_le (B := Tα΅α΅) degtm f g
end AddOnly
section AddMonoids
variable [AddMonoid A] [AddMonoid B] [AddLeftMono B] [AddRightMono B]
[AddMonoid T] [AddLeftMono T] [AddRightMono T]
{degb : A β B} {degt : A β T}
theorem sup_support_list_prod_le (degb0 : degb 0 β€ 0)
(degbm : β a b, degb (a + b) β€ degb a + degb b) :
β l : List R[A],
l.prod.support.sup degb β€ (l.map fun f : R[A] => f.support.sup degb).sum
| [] => by
rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil]
exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)]
| f::fs => by
rw [List.prod_cons, List.map_cons, List.sum_cons]
exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans
(add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _)
theorem le_inf_support_list_prod (degt0 : 0 β€ degt 0)
(degtm : β a b, degt a + degt b β€ degt (a + b)) (l : List R[A]) :
(l.map fun f : R[A] => f.support.inf degt).sum β€ l.prod.support.inf degt := by
refine OrderDual.ofDual_le_ofDual.mpr ?_
refine sup_support_list_prod_le ?_ ?_ l
Β· refine (OrderDual.ofDual_le_ofDual.mp ?_)
| exact degt0
Β· refine (fun a b => OrderDual.ofDual_le_ofDual.mp ?_)
exact degtm a b
theorem sup_support_pow_le (degb0 : degb 0 β€ 0) (degbm : β a b, degb (a + b) β€ degb a + degb b)
(n : β) (f : R[A]) : (f ^ n).support.sup degb β€ n β’ f.support.sup degb := by
rw [β List.prod_replicate, β List.sum_replicate]
refine (sup_support_list_prod_le degb0 degbm _).trans_eq ?_
rw [List.map_replicate]
| Mathlib/Algebra/MonoidAlgebra/Degree.lean | 138 | 146 |
/-
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.CharZero
import Mathlib.Algebra.Ring.Int.Units
import Mathlib.GroupTheory.Coprod.Basic
import Mathlib.GroupTheory.Complement
/-!
## HNN Extensions of Groups
This file defines the HNN extension of a group `G`, `HNNExtension G A B Ο`. Given a group `G`,
subgroups `A` and `B` and an isomorphism `Ο` of `A` and `B`, we adjoin a letter `t` to `G`, such
that for any `a β A`, the conjugate of `of a` by `t` is `of (Ο a)`, where `of` is the canonical map
from `G` into the `HNNExtension`. This construction is named after Graham Higman, Bernhard Neumann
and Hanna Neumann.
## Main definitions
- `HNNExtension G A B Ο` : The HNN Extension of a group `G`, where `A` and `B` are subgroups and `Ο`
is an isomorphism between `A` and `B`.
- `HNNExtension.of` : The canonical embedding of `G` into `HNNExtension G A B Ο`.
- `HNNExtension.t` : The stable letter of the HNN extension.
- `HNNExtension.lift` : Define a function `HNNExtension G A B Ο β* H`, by defining it on `G` and `t`
- `HNNExtension.of_injective` : The canonical embedding `G β* HNNExtension G A B Ο` is injective.
- `HNNExtension.ReducedWord.toList_eq_nil_of_mem_of_range` : Britton's Lemma. If an element of
`G` is represented by a reduced word, then this reduced word does not contain `t`.
-/
assert_not_exists Field
open Monoid Coprod Multiplicative Subgroup Function
/-- The relation we quotient the coproduct by to form an `HNNExtension`. -/
def HNNExtension.con (G : Type*) [Group G] (A B : Subgroup G) (Ο : A β* B) :
Con (G β Multiplicative β€) :=
conGen (fun x y => β (a : A),
x = inr (ofAdd 1) * inl (a : G) β§
y = inl (Ο a : G) * inr (ofAdd 1))
/-- The HNN Extension of a group `G`, `HNNExtension G A B Ο`. Given a group `G`, subgroups `A` and
`B` and an isomorphism `Ο` of `A` and `B`, we adjoin a letter `t` to `G`, such that for
any `a β A`, the conjugate of `of a` by `t` is `of (Ο a)`, where `of` is the canonical
map from `G` into the `HNNExtension`. -/
def HNNExtension (G : Type*) [Group G] (A B : Subgroup G) (Ο : A β* B) : Type _ :=
(HNNExtension.con G A B Ο).Quotient
variable {G : Type*} [Group G] {A B : Subgroup G} {Ο : A β* B} {H : Type*}
[Group H] {M : Type*} [Monoid M]
instance : Group (HNNExtension G A B Ο) := by
delta HNNExtension; infer_instance
namespace HNNExtension
/-- The canonical embedding `G β* HNNExtension G A B Ο` -/
def of : G β* HNNExtension G A B Ο :=
(HNNExtension.con G A B Ο).mk'.comp inl
/-- The stable letter of the `HNNExtension` -/
def t : HNNExtension G A B Ο :=
(HNNExtension.con G A B Ο).mk'.comp inr (ofAdd 1)
theorem t_mul_of (a : A) :
t * (of (a : G) : HNNExtension G A B Ο) = of (Ο a : G) * t :=
(Con.eq _).2 <| ConGen.Rel.of _ _ <| β¨a, by simpβ©
theorem of_mul_t (b : B) :
(of (b : G) : HNNExtension G A B Ο) * t = t * of (Ο.symm b : G) := by
rw [t_mul_of]; simp
theorem equiv_eq_conj (a : A) :
(of (Ο a : G) : HNNExtension G A B Ο) = t * of (a : G) * tβ»ΒΉ := by
rw [t_mul_of]; simp
theorem equiv_symm_eq_conj (b : B) :
(of (Ο.symm b : G) : HNNExtension G A B Ο) = tβ»ΒΉ * of (b : G) * t := by
rw [mul_assoc, of_mul_t]; simp
theorem inv_t_mul_of (b : B) :
tβ»ΒΉ * (of (b : G) : HNNExtension G A B Ο) = of (Ο.symm b : G) * tβ»ΒΉ := by
rw [equiv_symm_eq_conj]; simp
theorem of_mul_inv_t (a : A) :
(of (a : G) : HNNExtension G A B Ο) * tβ»ΒΉ = tβ»ΒΉ * of (Ο a : G) := by
rw [equiv_eq_conj]; simp [mul_assoc]
/-- Define a function `HNNExtension G A B Ο β* H`, by defining it on `G` and `t` -/
def lift (f : G β* H) (x : H) (hx : β a : A, x * f βa = f (Ο a : G) * x) :
HNNExtension G A B Ο β* H :=
Con.lift _ (Coprod.lift f (zpowersHom H x)) (Con.conGen_le <| by
rintro _ _ β¨a, rfl, rflβ©
simp [hx])
@[simp]
theorem lift_t (f : G β* H) (x : H) (hx : β a : A, x * f βa = f (Ο a : G) * x) :
lift f x hx t = x := by
delta HNNExtension; simp [lift, t]
@[simp]
theorem lift_of (f : G β* H) (x : H) (hx : β a : A, x * f βa = f (Ο a : G) * x) (g : G) :
lift f x hx (of g) = f g := by
delta HNNExtension; simp [lift, of]
@[ext high]
theorem hom_ext {f g : HNNExtension G A B Ο β* M}
(hg : f.comp of = g.comp of) (ht : f t = g t) : f = g :=
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
Coprod.hom_ext hg (MonoidHom.ext_mint ht)
@[elab_as_elim]
theorem induction_on {motive : HNNExtension G A B Ο β Prop}
(x : HNNExtension G A B Ο) (of : β g, motive (of g))
(t : motive t) (mul : β x y, motive x β motive y β motive (x * y))
(inv : β x, motive x β motive xβ»ΒΉ) : motive x := by
let S : Subgroup (HNNExtension G A B Ο) :=
{ carrier := setOf motive
one_mem' := by simpa using of 1
mul_mem' := mul _ _
inv_mem' := inv _ }
let f : HNNExtension G A B Ο β* S :=
lift (HNNExtension.of.codRestrict S of)
β¨HNNExtension.t, tβ© (by intro a; ext; simp [equiv_eq_conj, mul_assoc])
have hf : S.subtype.comp f = MonoidHom.id _ :=
hom_ext (by ext; simp [f]) (by simp [f])
show motive (MonoidHom.id _ x)
rw [β hf]
exact (f x).2
variable (A B Ο)
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : β€Λ£` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is `Ο` when `u = 1` and `Οβ»ΒΉ` when `u = -1`. `toSubgroup u` is the subgroup
such that for any `a β toSubgroup u`, `t ^ (u : β€) * a = toSubgroupEquiv a * t ^ (u : β€)`. -/
def toSubgroup (u : β€Λ£) : Subgroup G :=
if u = 1 then A else B
@[simp]
theorem toSubgroup_one : toSubgroup A B 1 = A := rfl
@[simp]
theorem toSubgroup_neg_one : toSubgroup A B (-1) = B := rfl
variable {A B}
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : β€Λ£` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is the group ismorphism from `toSubgroup A B u` to `toSubgroup A B (-u)`.
It is defined to be `Ο` when `u = 1` and `Οβ»ΒΉ` when `u = -1`. -/
def toSubgroupEquiv (u : β€Λ£) : toSubgroup A B u β* toSubgroup A B (-u) :=
if hu : u = 1 then hu βΈ Ο else by
convert Ο.symm <;>
cases Int.units_eq_one_or u <;> simp_all
@[simp]
theorem toSubgroupEquiv_one : toSubgroupEquiv Ο 1 = Ο := rfl
@[simp]
theorem toSubgroupEquiv_neg_one : toSubgroupEquiv Ο (-1) = Ο.symm := rfl
@[simp]
theorem toSubgroupEquiv_neg_apply (u : β€Λ£) (a : toSubgroup A B u) :
(toSubgroupEquiv Ο (-u) (toSubgroupEquiv Ο u a) : G) = a := by
rcases Int.units_eq_one_or u with rfl | rfl
Β· simp [toSubgroup]
Β· simp only [toSubgroup_neg_one, toSubgroupEquiv_neg_one, SetLike.coe_eq_coe]
exact Ο.apply_symm_apply a
namespace NormalWord
variable (G A B)
/-- To put word in the HNN Extension into a normal form, we must choose an element of each right
coset of both `A` and `B`, such that the chosen element of the subgroup itself is `1`. -/
structure TransversalPair : Type _ where
/-- The transversal of each subgroup -/
set : β€Λ£ β Set G
/-- We have exactly one element of each coset of the subgroup -/
compl : β u, IsComplement (toSubgroup A B u : Subgroup G) (set u)
instance TransversalPair.nonempty : Nonempty (TransversalPair G A B) := by
choose t ht using fun u β¦ (toSubgroup A B u).exists_isComplement_right 1
exact β¨β¨t, fun i β¦ (ht i).1β©β©
/-- A reduced word is a `head`, which is an element of `G`, followed by the product list of pairs.
There should also be no sequences of the form `t^u * g * t^-u`, where `g` is in
`toSubgroup A B u` This is a less strict condition than required for `NormalWord`. -/
structure ReducedWord : Type _ where
/-- Every `ReducedWord` is the product of an element of the group and a word made up
of letters each of which is in the transversal. `head` is that element of the base group. -/
head : G
/-- The list of pairs `(β€Λ£ Γ G)`, where each pair `(u, g)` represents the element `t^u * g` of
`HNNExtension G A B Ο` -/
toList : List (β€Λ£ Γ G)
/-- There are no sequences of the form `t^u * g * t^-u` where `g β toSubgroup A B u` -/
chain : toList.Chain' (fun a b => a.2 β toSubgroup A B a.1 β a.1 = b.1)
/-- The empty reduced word. -/
@[simps]
def ReducedWord.empty : ReducedWord G A B :=
{ head := 1
toList := []
chain := List.chain'_nil }
variable {G A B}
/-- The product of a `ReducedWord` as an element of the `HNNExtension` -/
def ReducedWord.prod : ReducedWord G A B β HNNExtension G A B Ο :=
fun w => of w.head * (w.toList.map (fun x => t ^ (x.1 : β€) * of x.2)).prod
/-- Given a `TransversalPair`, we can make a normal form for words in the `HNNExtension G A B Ο`.
The normal form is a `head`, which is an element of `G`, followed by the product list of pairs,
`t ^ u * g`, where `u` is `1` or `-1` and `g` is the chosen element of its right coset of
`toSubgroup A B u`. There should also be no sequences of the form `t^u * g * t^-u`
where `g β toSubgroup A B u` -/
structure _root_.HNNExtension.NormalWord (d : TransversalPair G A B) : Type _
extends ReducedWord G A B where
/-- Every element `g : G` in the list is the chosen element of its coset -/
mem_set : β (u : β€Λ£) (g : G), (u, g) β toList β g β d.set u
variable {d : TransversalPair G A B}
@[ext]
theorem ext {w w' : NormalWord d}
(h1 : w.head = w'.head) (h2 : w.toList = w'.toList) : w = w' := by
rcases w with β¨β¨β©, _β©; cases w'; simp_all
/-- The empty word -/
@[simps]
def empty : NormalWord d :=
{ head := 1
toList := []
mem_set := by simp
chain := List.chain'_nil }
/-- The `NormalWord` representing an element `g` of the group `G`, which is just the element `g`
itself. -/
@[simps]
def ofGroup (g : G) : NormalWord d :=
{ head := g
toList := []
mem_set := by simp
chain := List.chain'_nil }
instance : Inhabited (NormalWord d) := β¨emptyβ©
instance : MulAction G (NormalWord d) :=
{ smul := fun g w => { w with head := g * w.head }
one_smul := by simp [instHSMul]
mul_smul := by simp [instHSMul, mul_assoc] }
theorem group_smul_def (g : G) (w : NormalWord d) :
g β’ w = { w with head := g * w.head } := rfl
@[simp]
theorem group_smul_head (g : G) (w : NormalWord d) : (g β’ w).head = g * w.head := rfl
@[simp]
theorem group_smul_toList (g : G) (w : NormalWord d) : (g β’ w).toList = w.toList := rfl
instance : FaithfulSMul G (NormalWord d) := β¨by simp [group_smul_def]β©
/-- A constructor to append an element `g` of `G` and `u : β€Λ£` to a word `w` with sufficient
hypotheses that no normalization or cancellation need take place for the result to be in normal form
-/
@[simps]
def cons (g : G) (u : β€Λ£) (w : NormalWord d) (h1 : w.head β d.set u)
(h2 : β u' β Option.map Prod.fst w.toList.head?, w.head β toSubgroup A B u β u = u') :
NormalWord d :=
{ head := g,
toList := (u, w.head) :: w.toList,
mem_set := by
intro u' g' h'
simp only [List.mem_cons, Prod.mk.injEq] at h'
rcases h' with β¨rfl, rflβ© | h'
Β· exact h1
Β· exact w.mem_set _ _ h'
chain := by
refine List.chain'_cons'.2 β¨?_, w.chainβ©
rintro β¨u', g'β© hu' hw1
exact h2 _ (by simp_all) hw1 }
/-- A recursor to induct on a `NormalWord`, by proving the property is preserved under `cons` -/
@[elab_as_elim]
def consRecOn {motive : NormalWord d β Sort*} (w : NormalWord d)
(ofGroup : β g, motive (ofGroup g))
(cons : β (g : G) (u : β€Λ£) (w : NormalWord d) (h1 : w.head β d.set u)
(h2 : β u' β Option.map Prod.fst w.toList.head?,
w.head β toSubgroup A B u β u = u'),
motive w β motive (cons g u w h1 h2)) : motive w := by
rcases w with β¨β¨g, l, chainβ©, mem_setβ©
induction l generalizing g with
| nil => exact ofGroup _
| cons a l ih =>
exact cons g a.1
{ head := a.2
toList := l
mem_set := fun _ _ h => mem_set _ _ (List.mem_cons_of_mem _ h),
chain := (List.chain'_cons'.1 chain).2 }
(mem_set a.1 a.2 List.mem_cons_self)
(by simpa using (List.chain'_cons'.1 chain).1)
(ih _ _ _)
@[simp]
theorem consRecOn_ofGroup {motive : NormalWord d β Sort*}
(g : G) (ofGroup : β g, motive (ofGroup g))
(cons : β (g : G) (u : β€Λ£) (w : NormalWord d) (h1 : w.head β d.set u)
(h2 : β u' β Option.map Prod.fst w.toList.head?, w.head
β toSubgroup A B u β u = u'),
motive w β motive (cons g u w h1 h2)) :
consRecOn (.ofGroup g) ofGroup cons = ofGroup g := rfl
@[simp]
theorem consRecOn_cons {motive : NormalWord d β Sort*}
(g : G) (u : β€Λ£) (w : NormalWord d) (h1 : w.head β d.set u)
(h2 : β u' β Option.map Prod.fst w.toList.head?, w.head β toSubgroup A B u β u = u')
(ofGroup : β g, motive (ofGroup g))
(cons : β (g : G) (u : β€Λ£) (w : NormalWord d) (h1 : w.head β d.set u)
(h2 : β u' β Option.map Prod.fst w.toList.head?,
w.head β toSubgroup A B u β u = u'),
motive w β motive (cons g u w h1 h2)) :
consRecOn (.cons g u w h1 h2) ofGroup cons = cons g u w h1 h2
(consRecOn w ofGroup cons) := rfl
@[simp]
theorem smul_cons (gβ gβ : G) (u : β€Λ£) (w : NormalWord d) (h1 : w.head β d.set u)
(h2 : β u' β Option.map Prod.fst w.toList.head?, w.head β toSubgroup A B u β u = u') :
gβ β’ cons gβ u w h1 h2 = cons (gβ * gβ) u w h1 h2 :=
rfl
@[simp]
theorem smul_ofGroup (gβ gβ : G) :
gβ β’ (ofGroup gβ : NormalWord d) = ofGroup (gβ * gβ) := rfl
variable (d)
/-- The action of `t^u` on `ofGroup g`. The normal form will be
`a * t^u * g'` where `a β toSubgroup A B (-u)` -/
noncomputable def unitsSMulGroup (u : β€Λ£) (g : G) :
(toSubgroup A B (-u)) Γ d.set u :=
let g' := (d.compl u).equiv g
(toSubgroupEquiv Ο u g'.1, g'.2)
theorem unitsSMulGroup_snd (u : β€Λ£) (g : G) :
(unitsSMulGroup Ο d u g).2 = ((d.compl u).equiv g).2 := by
rcases Int.units_eq_one_or u with rfl | rfl <;> rfl
variable {d}
/-- `Cancels u w` is a predicate expressing whether `t^u` cancels with some occurrence
of `t^-u` when we multiply `t^u` by `w`. -/
def Cancels (u : β€Λ£) (w : NormalWord d) : Prop :=
(w.head β (toSubgroup A B u : Subgroup G)) β§ w.toList.head?.map Prod.fst = some (-u)
/-- Multiplying `t^u` by `w` in the special case where cancellation happens -/
def unitsSMulWithCancel (u : β€Λ£) (w : NormalWord d) : Cancels u w β NormalWord d :=
consRecOn w
(by simp [Cancels, ofGroup]; tauto)
(fun g _ w _ _ _ can =>
(toSubgroupEquiv Ο u β¨g, can.1β© : G) β’ w)
/-- Multiplying `t^u` by a `NormalWord`, `w` and putting the result in normal form. -/
noncomputable def unitsSMul (u : β€Λ£) (w : NormalWord d) : NormalWord d :=
letI := Classical.dec
if h : Cancels u w
then unitsSMulWithCancel Ο u w h
else let g' := unitsSMulGroup Ο d u w.head
cons g'.1 u ((g'.2 * w.headβ»ΒΉ : G) β’ w)
(by simp)
(by
simp only [g', group_smul_toList, Option.mem_def, Option.map_eq_some_iff, Prod.exists,
exists_and_right, exists_eq_right, group_smul_head, inv_mul_cancel_right,
forall_exists_index, unitsSMulGroup]
simp only [Cancels, Option.map_eq_some_iff, Prod.exists, exists_and_right, exists_eq_right,
not_and, not_exists] at h
intro u' x hx hmem
have : w.head β toSubgroup A B u := by
have := (d.compl u).rightCosetEquivalence_equiv_snd w.head
rw [RightCosetEquivalence, rightCoset_eq_iff, mul_mem_cancel_left hmem] at this
simp_all
have := h this x
simp_all [Int.units_ne_iff_eq_neg])
|
/-- A condition for not cancelling whose hypothese are the same as those of the `cons` function. -/
theorem not_cancels_of_cons_hyp (u : β€Λ£) (w : NormalWord d)
(h2 : β u' β Option.map Prod.fst w.toList.head?,
w.head β toSubgroup A B u β u = u') :
Β¬ Cancels u w := by
simp only [Cancels, Option.map_eq_some_iff, Prod.exists,
exists_and_right, exists_eq_right, not_and, not_exists]
intro hw x hx
| Mathlib/GroupTheory/HNNExtension.lean | 385 | 393 |
/-
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, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Basic
/-!
# Maps between real and extended non-negative real numbers
This file focuses on the functions `ENNReal.toReal : ββ₯0β β β` and `ENNReal.ofReal : β β ββ₯0β` which
were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between
these functions and the algebraic and lattice operations, although a few may appear in earlier
files.
This file provides a `positivity` extension for `ENNReal.ofReal`.
# Main theorems
- `trichotomy (p : ββ₯0β) : p = 0 β¨ p = β β¨ 0 < p.toReal`: often used for `WithLp` and `lp`
- `dichotomy (p : ββ₯0β) [Fact (1 β€ p)] : p = β β¨ 1 β€ p.toReal`: often used for `WithLp` and `lp`
- `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between
indexed or set infima and suprema in `β`, `ββ₯0` and `ββ₯0β`. This is especially useful because
`ββ₯0β` is a complete lattice.
-/
assert_not_exists Finset
open Set NNReal ENNReal
namespace ENNReal
section Real
variable {a b c d : ββ₯0β} {r p q : ββ₯0}
theorem toReal_add (ha : a β β) (hb : b β β) : (a + b).toReal = a.toReal + b.toReal := by
lift a to ββ₯0 using ha
lift b to ββ₯0 using hb
rfl
theorem toReal_add_le : (a + b).toReal β€ a.toReal + b.toReal :=
if ha : a = β then by simp only [ha, top_add, toReal_top, zero_add, toReal_nonneg]
else
if hb : b = β then by simp only [hb, add_top, toReal_top, add_zero, toReal_nonneg]
else le_of_eq (toReal_add ha hb)
theorem ofReal_add {p q : β} (hp : 0 β€ p) (hq : 0 β€ q) :
ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by
rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, β coe_add, coe_inj,
Real.toNNReal_add hp hq]
theorem ofReal_add_le {p q : β} : ENNReal.ofReal (p + q) β€ ENNReal.ofReal p + ENNReal.ofReal q :=
coe_le_coe.2 Real.toNNReal_add_le
@[simp]
theorem toReal_le_toReal (ha : a β β) (hb : b β β) : a.toReal β€ b.toReal β a β€ b := by
lift a to ββ₯0 using ha
lift b to ββ₯0 using hb
norm_cast
@[gcongr]
theorem toReal_mono (hb : b β β) (h : a β€ b) : a.toReal β€ b.toReal :=
(toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h
theorem toReal_mono' (h : a β€ b) (ht : b = β β a = β) : a.toReal β€ b.toReal := by
rcases eq_or_ne a β with rfl | ha
Β· exact toReal_nonneg
Β· exact toReal_mono (mt ht ha) h
@[simp]
theorem toReal_lt_toReal (ha : a β β) (hb : b β β) : a.toReal < b.toReal β a < b := by
lift a to ββ₯0 using ha
lift b to ββ₯0 using hb
norm_cast
@[gcongr]
theorem toReal_strict_mono (hb : b β β) (h : a < b) : a.toReal < b.toReal :=
(toReal_lt_toReal h.ne_top hb).2 h
@[gcongr]
theorem toNNReal_mono (hb : b β β) (h : a β€ b) : a.toNNReal β€ b.toNNReal :=
toReal_mono hb h
theorem le_toNNReal_of_coe_le (h : p β€ a) (ha : a β β) : p β€ a.toNNReal :=
@toNNReal_coe p βΈ toNNReal_mono ha h
@[simp]
theorem toNNReal_le_toNNReal (ha : a β β) (hb : b β β) : a.toNNReal β€ b.toNNReal β a β€ b :=
β¨fun h => by rwa [β coe_toNNReal ha, β coe_toNNReal hb, coe_le_coe], toNNReal_mono hbβ©
@[gcongr]
theorem toNNReal_strict_mono (hb : b β β) (h : a < b) : a.toNNReal < b.toNNReal := by
simpa [β ENNReal.coe_lt_coe, hb, h.ne_top]
@[simp]
theorem toNNReal_lt_toNNReal (ha : a β β) (hb : b β β) : a.toNNReal < b.toNNReal β a < b :=
β¨fun h => by rwa [β coe_toNNReal ha, β coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hbβ©
theorem toNNReal_lt_of_lt_coe (h : a < p) : a.toNNReal < p :=
@toNNReal_coe p βΈ toNNReal_strict_mono coe_ne_top h
theorem toReal_max (hr : a β β) (hp : b β β) :
ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) :=
(le_total a b).elim
(fun h => by simp only [h, ENNReal.toReal_mono hp h, max_eq_right]) fun h => by
simp only [h, ENNReal.toReal_mono hr h, max_eq_left]
theorem toReal_min {a b : ββ₯0β} (hr : a β β) (hp : b β β) :
ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) :=
(le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, min_eq_left])
fun h => by simp only [h, ENNReal.toReal_mono hr h, min_eq_right]
theorem toReal_sup {a b : ββ₯0β} : a β β β b β β β (a β b).toReal = a.toReal β b.toReal :=
toReal_max
theorem toReal_inf {a b : ββ₯0β} : a β β β b β β β (a β b).toReal = a.toReal β b.toReal :=
toReal_min
theorem toNNReal_pos_iff : 0 < a.toNNReal β 0 < a β§ a < β := by
induction a <;> simp
theorem toNNReal_pos {a : ββ₯0β} (haβ : a β 0) (ha_top : a β β) : 0 < a.toNNReal :=
toNNReal_pos_iff.mpr β¨bot_lt_iff_ne_bot.mpr haβ, lt_top_iff_ne_top.mpr ha_topβ©
theorem toReal_pos_iff : 0 < a.toReal β 0 < a β§ a < β :=
NNReal.coe_pos.trans toNNReal_pos_iff
theorem toReal_pos {a : ββ₯0β} (haβ : a β 0) (ha_top : a β β) : 0 < a.toReal :=
toReal_pos_iff.mpr β¨bot_lt_iff_ne_bot.mpr haβ, lt_top_iff_ne_top.mpr ha_topβ©
@[gcongr, bound]
theorem ofReal_le_ofReal {p q : β} (h : p β€ q) : ENNReal.ofReal p β€ ENNReal.ofReal q := by
simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h]
theorem ofReal_le_of_le_toReal {a : β} {b : ββ₯0β} (h : a β€ ENNReal.toReal b) :
ENNReal.ofReal a β€ b :=
| (ofReal_le_ofReal h).trans ofReal_toReal_le
@[simp]
theorem ofReal_le_ofReal_iff {p q : β} (h : 0 β€ q) :
ENNReal.ofReal p β€ ENNReal.ofReal q β p β€ q := by
| Mathlib/Data/ENNReal/Real.lean | 138 | 142 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.CharP.Two
import Mathlib.Data.Nat.Cast.Field
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.Data.Nat.Factorization.Induction
import Mathlib.Data.Nat.Periodic
/-!
# Euler's totient function
This file defines [Euler's totient function](https://en.wikipedia.org/wiki/Euler's_totient_function)
`Nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`.
We prove the divisor sum formula, namely that `n` equals `Ο` summed over the divisors of `n`. See
`sum_totient`. We also prove two lemmas to help compute totients, namely `totient_mul` and
`totient_prime_pow`.
-/
assert_not_exists Algebra LinearMap
open Finset
namespace Nat
/-- Euler's totient function. This counts the number of naturals strictly less than `n` which are
coprime with `n`. -/
def totient (n : β) : β := #{a β range n | n.Coprime a}
@[inherit_doc]
scoped notation "Ο" => Nat.totient
@[simp]
theorem totient_zero : Ο 0 = 0 :=
rfl
@[simp]
theorem totient_one : Ο 1 = 1 := rfl
theorem totient_eq_card_coprime (n : β) : Ο n = #{a β range n | n.Coprime a} := rfl
/-- A characterisation of `Nat.totient` that avoids `Finset`. -/
theorem totient_eq_card_lt_and_coprime (n : β) : Ο n = Nat.card { m | m < n β§ n.Coprime m } := by
let e : { m | m < n β§ n.Coprime m } β {x β range n | n.Coprime x} :=
{ toFun := fun m => β¨m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.propertyβ©
invFun := fun m => β¨m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.propertyβ©
left_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta]
right_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta] }
rw [totient_eq_card_coprime, card_congr e, card_eq_fintype_card, Fintype.card_coe]
theorem totient_le (n : β) : Ο n β€ n :=
((range n).card_filter_le _).trans_eq (card_range n)
theorem totient_lt (n : β) (hn : 1 < n) : Ο n < n :=
(card_lt_card (filter_ssubset.2 β¨0, by simp [hn.ne', pos_of_gt hn]β©)).trans_eq (card_range n)
@[simp]
theorem totient_eq_zero : β {n : β}, Ο n = 0 β n = 0
| 0 => by decide
| n + 1 =>
suffices β x < n + 1, (n + 1).gcd x = 1 by simpa [totient, filter_eq_empty_iff]
β¨1 % (n + 1), mod_lt _ n.succ_pos, by rw [gcd_comm, β gcd_rec, gcd_one_right]β©
@[simp] theorem totient_pos {n : β} : 0 < Ο n β 0 < n := by simp [pos_iff_ne_zero]
instance neZero_totient {n : β} [NeZero n] : NeZero n.totient :=
β¨(totient_pos.mpr <| NeZero.pos n).ne'β©
theorem filter_coprime_Ico_eq_totient (a n : β) :
#{x β Ico n (n + a) | a.Coprime x} = totient a := by
rw [totient, filter_Ico_card_eq_of_periodic, count_eq_card_filter_range]
exact periodic_coprime a
theorem Ico_filter_coprime_le {a : β} (k n : β) (a_pos : 0 < a) :
#{x β Ico k (k + n) | a.Coprime x} β€ totient a * (n / a + 1) := by
conv_lhs => rw [β Nat.mod_add_div n a]
induction' n / a with i ih
Β· rw [β filter_coprime_Ico_eq_totient a k]
simp only [add_zero, mul_one, mul_zero, le_of_lt (mod_lt n a_pos), zero_add]
gcongr
exact le_of_lt (mod_lt n a_pos)
simp only [mul_succ]
simp_rw [β add_assoc] at ih β’
calc
#{x β Ico k (k + n % a + a * i + a) | a.Coprime x}
β€ #{x β Ico k (k + n % a + a * i) βͺ
Ico (k + n % a + a * i) (k + n % a + a * i + a) | a.Coprime x} := by
gcongr
apply Ico_subset_Ico_union_Ico
_ β€ #{x β Ico k (k + n % a + a * i) | a.Coprime x} + a.totient := by
rw [filter_union, β filter_coprime_Ico_eq_totient a (k + n % a + a * i)]
apply card_union_le
_ β€ a.totient * i + a.totient + a.totient := add_le_add_right ih (totient a)
open ZMod
/-- Note this takes an explicit `Fintype ((ZMod n)Λ£)` argument to avoid trouble with instance
diamonds. -/
@[simp]
theorem _root_.ZMod.card_units_eq_totient (n : β) [NeZero n] [Fintype (ZMod n)Λ£] :
Fintype.card (ZMod n)Λ£ = Ο n :=
calc
Fintype.card (ZMod n)Λ£ = Fintype.card { x : ZMod n // x.val.Coprime n } :=
Fintype.card_congr ZMod.unitsEquivCoprime
_ = Ο n := by
obtain β¨m, rflβ© : β m, n = m + 1 := exists_eq_succ_of_ne_zero NeZero.out
simp only [totient, Finset.card_eq_sum_ones, Fintype.card_subtype, Finset.sum_filter, β
Fin.sum_univ_eq_sum_range, @Nat.coprime_comm (m + 1)]
rfl
theorem totient_even {n : β} (hn : 2 < n) : Even n.totient := by
haveI : Fact (1 < n) := β¨one_lt_two.trans hnβ©
haveI : NeZero n := NeZero.of_gt hn
suffices 2 = orderOf (-1 : (ZMod n)Λ£) by
rw [β ZMod.card_units_eq_totient, even_iff_two_dvd, this]
exact orderOf_dvd_card
rw [β orderOf_units, Units.coe_neg_one, orderOf_neg_one, ringChar.eq (ZMod n) n, if_neg hn.ne']
theorem totient_mul {m n : β} (h : m.Coprime n) : Ο (m * n) = Ο m * Ο n :=
if hmn0 : m * n = 0 then by
rcases Nat.mul_eq_zero.1 hmn0 with h | h <;>
simp only [totient_zero, mul_zero, zero_mul, h]
else by
haveI : NeZero (m * n) := β¨hmn0β©
haveI : NeZero m := β¨left_ne_zero_of_mul hmn0β©
haveI : NeZero n := β¨right_ne_zero_of_mul hmn0β©
simp only [β ZMod.card_units_eq_totient]
rw [Fintype.card_congr (Units.mapEquiv (ZMod.chineseRemainder h).toMulEquiv).toEquiv,
Fintype.card_congr (@MulEquiv.prodUnits (ZMod m) (ZMod n) _ _).toEquiv, Fintype.card_prod]
/-- For `d β£ n`, the totient of `n/d` equals the number of values `k < n` such that `gcd n k = d` -/
theorem totient_div_of_dvd {n d : β} (hnd : d β£ n) :
Ο (n / d) = #{k β range n | n.gcd k = d} := by
rcases d.eq_zero_or_pos with (rfl | hd0); Β· simp [eq_zero_of_zero_dvd hnd]
rcases hnd with β¨x, rflβ©
rw [Nat.mul_div_cancel_left x hd0]
apply Finset.card_bij fun k _ => d * k
Β· simp only [mem_filter, mem_range, and_imp, Coprime]
refine fun a ha1 ha2 => β¨(mul_lt_mul_left hd0).2 ha1, ?_β©
rw [gcd_mul_left, ha2, mul_one]
Β· simp [hd0.ne']
Β· simp only [mem_filter, mem_range, exists_prop, and_imp]
refine fun b hb1 hb2 => ?_
have : d β£ b := by
rw [β hb2]
apply gcd_dvd_right
rcases this with β¨q, rflβ©
refine β¨q, β¨β¨(mul_lt_mul_left hd0).1 hb1, ?_β©, rflβ©β©
rwa [gcd_mul_left, mul_right_eq_self_iff hd0] at hb2
theorem sum_totient (n : β) : n.divisors.sum Ο = n := by
rcases n.eq_zero_or_pos with (rfl | hn)
Β· simp
rw [β sum_div_divisors n Ο]
have : n = β d β n.divisors, #{k β range n | n.gcd k = d} := by
nth_rw 1 [β card_range n]
refine card_eq_sum_card_fiberwise fun x _ => mem_divisors.2 β¨?_, hn.ne'β©
apply gcd_dvd_left
nth_rw 3 [this]
exact sum_congr rfl fun x hx => totient_div_of_dvd (dvd_of_mem_divisors hx)
theorem sum_totient' (n : β) : β m β range n.succ with m β£ n, Ο m = n := by
convert sum_totient _ using 1
simp only [Nat.divisors, sum_filter, range_eq_Ico]
rw [sum_eq_sum_Ico_succ_bot] <;> simp
/-- When `p` is prime, then the totient of `p ^ (n + 1)` is `p ^ n * (p - 1)` -/
theorem totient_prime_pow_succ {p : β} (hp : p.Prime) (n : β) : Ο (p ^ (n + 1)) = p ^ n * (p - 1) :=
calc
Ο (p ^ (n + 1)) = #{a β range (p ^ (n + 1)) | (p ^ (n + 1)).Coprime a} :=
totient_eq_card_coprime _
_ = #(range (p ^ (n + 1)) \ (range (p ^ n)).image (Β· * p)) :=
congr_arg card
(by
rw [sdiff_eq_filter]
apply filter_congr
simp only [mem_range, mem_filter, coprime_pow_left_iff n.succ_pos, mem_image, not_exists,
hp.coprime_iff_not_dvd]
intro a ha
constructor
Β· intro hap b h; rcases h with β¨_, rflβ©
exact hap (dvd_mul_left _ _)
Β· rintro h β¨b, rflβ©
rw [pow_succ'] at ha
exact h b β¨lt_of_mul_lt_mul_left ha (zero_le _), mul_comm _ _β©)
_ = _ := by
have h1 : Function.Injective (Β· * p) := mul_left_injectiveβ hp.ne_zero
have h2 : (range (p ^ n)).image (Β· * p) β range (p ^ (n + 1)) := fun a => by
simp only [mem_image, mem_range, exists_imp]
rintro b β¨h, rflβ©
rw [Nat.pow_succ]
exact (mul_lt_mul_right hp.pos).2 h
rw [card_sdiff h2, Finset.card_image_of_injective _ h1, card_range, card_range, β
one_mul (p ^ n), pow_succ', β tsub_mul, one_mul, mul_comm]
/-- When `p` is prime, then the totient of `p ^ n` is `p ^ (n - 1) * (p - 1)` -/
theorem totient_prime_pow {p : β} (hp : p.Prime) {n : β} (hn : 0 < n) :
Ο (p ^ n) = p ^ (n - 1) * (p - 1) := by
rcases exists_eq_succ_of_ne_zero (pos_iff_ne_zero.1 hn) with β¨m, rflβ©
exact totient_prime_pow_succ hp _
theorem totient_prime {p : β} (hp : p.Prime) : Ο p = p - 1 := by
rw [β pow_one p, totient_prime_pow hp] <;> simp
theorem totient_eq_iff_prime {p : β} (hp : 0 < p) : p.totient = p - 1 β p.Prime := by
refine β¨fun h => ?_, totient_primeβ©
replace hp : 1 < p := by
apply lt_of_le_of_ne
Β· rwa [succ_le_iff]
Β· rintro rfl
rw [totient_one, tsub_self] at h
exact one_ne_zero h
rw [totient_eq_card_coprime, range_eq_Ico, β Ico_insert_succ_left hp.le, Finset.filter_insert,
if_neg (not_coprime_of_dvd_of_dvd hp (dvd_refl p) (dvd_zero p)), β Nat.card_Ico 1 p] at h
refine
p.prime_of_coprime hp fun n hn hnz => Finset.filter_card_eq h n <| Finset.mem_Ico.mpr β¨?_, hnβ©
rwa [succ_le_iff, pos_iff_ne_zero]
theorem card_units_zmod_lt_sub_one {p : β} (hp : 1 < p) [Fintype (ZMod p)Λ£] :
Fintype.card (ZMod p)Λ£ β€ p - 1 := by
haveI : NeZero p := β¨(pos_of_gt hp).ne'β©
rw [ZMod.card_units_eq_totient p]
exact Nat.le_sub_one_of_lt (Nat.totient_lt p hp)
theorem prime_iff_card_units (p : β) [Fintype (ZMod p)Λ£] :
p.Prime β Fintype.card (ZMod p)Λ£ = p - 1 := by
rcases eq_zero_or_neZero p with hp | hp
Β· subst hp
simp only [ZMod, not_prime_zero, false_iff, zero_tsub]
-- the subst created a non-defeq but subsingleton instance diamond; resolve it
suffices Fintype.card β€Λ£ β 0 by convert this
simp
rw [ZMod.card_units_eq_totient, Nat.totient_eq_iff_prime <| NeZero.pos p]
@[simp]
theorem totient_two : Ο 2 = 1 :=
(totient_prime prime_two).trans rfl
theorem totient_eq_one_iff : β {n : β}, n.totient = 1 β n = 1 β¨ n = 2
| | 0 => by simp
| 1 => by simp
| 2 => by simp
| n + 3 => by
have : 3 β€ n + 3 := le_add_self
| Mathlib/Data/Nat/Totient.lean | 242 | 246 |
/-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Gabin Kolly
-/
import Mathlib.Data.Finite.Sum
import Mathlib.Data.Fintype.Order
import Mathlib.ModelTheory.FinitelyGenerated
import Mathlib.ModelTheory.Quotients
import Mathlib.Order.DirectedInverseSystem
/-!
# Direct Limits of First-Order Structures
This file constructs the direct limit of a directed system of first-order embeddings.
## Main Definitions
- `FirstOrder.Language.DirectLimit G f` is the direct limit of the directed system `f` of
first-order embeddings between the structures indexed by `G`.
- `FirstOrder.Language.DirectLimit.lift` is the universal property of the direct limit: maps
from the components to another module that respect the directed system structure give rise to
a unique map out of the direct limit.
- `FirstOrder.Language.DirectLimit.equiv_lift` is the equivalence between limits of
isomorphic direct systems.
-/
universe v w w' uβ uβ
open FirstOrder
namespace FirstOrder
namespace Language
open Structure Set
variable {L : Language} {ΞΉ : Type v} [Preorder ΞΉ]
variable {G : ΞΉ β Type w} [β i, L.Structure (G i)]
variable (f : β i j, i β€ j β G i βͺ[L] G j)
namespace DirectedSystem
alias map_self := DirectedSystem.map_self'
alias map_map := DirectedSystem.map_map'
variable {G' : β β Type w} [β i, L.Structure (G' i)] (f' : β n : β, G' n βͺ[L] G' (n + 1))
/-- Given a chain of embeddings of structures indexed by `β`, defines a `DirectedSystem` by
composing them. -/
def natLERec (m n : β) (h : m β€ n) : G' m βͺ[L] G' n :=
Nat.leRecOn h (@fun k g => (f' k).comp g) (Embedding.refl L _)
@[simp]
theorem coe_natLERec (m n : β) (h : m β€ n) :
(natLERec f' m n h : G' m β G' n) = Nat.leRecOn h (@fun k => f' k) := by
obtain β¨k, rflβ© := Nat.exists_eq_add_of_le h
ext x
induction' k with k ih
Β· -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [natLERec, Nat.leRecOn_self, Embedding.refl_apply, Nat.leRecOn_self]
Β· -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644
erw [Nat.leRecOn_succ le_self_add, natLERec, Nat.leRecOn_succ le_self_add, β natLERec,
Embedding.comp_apply, ih]
instance natLERec.directedSystem : DirectedSystem G' fun i j h => natLERec f' i j h :=
β¨fun _ _ => congr (congr rfl (Nat.leRecOn_self _)) rfl,
fun _ _ _ hij hjk => by simp [Nat.leRecOn_trans hij hjk]β©
end DirectedSystem
set_option linter.unusedVariables false in
/-- Alias for `Ξ£ i, G i`.
Instead of `Ξ£ i, G i`, we use the alias `Language.Structure.Sigma` which depends on `f`.
This way, Lean can infer what `L` and `f` are in the `Setoid` instance.
Otherwise we have a "cannot find synthesization order" error.
See also the discussion at
https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/local.20instance.20cannot.20find.20synthesization.20order.20in.20porting
-/
@[nolint unusedArguments]
protected abbrev Structure.Sigma (f : β i j, i β€ j β G i βͺ[L] G j) := Ξ£ i, G i
local notation "Ξ£Λ£" => Structure.Sigma
/-- Constructor for `FirstOrder.Language.Structure.Sigma` alias. -/
abbrev Structure.Sigma.mk (i : ΞΉ) (x : G i) : Ξ£Λ£ f := β¨i, xβ©
namespace DirectLimit
/-- Raises a family of elements in the `Ξ£`-type to the same level along the embeddings. -/
def unify {Ξ± : Type*} (x : Ξ± β Ξ£Λ£ f) (i : ΞΉ) (h : i β upperBounds (range (Sigma.fst β x)))
(a : Ξ±) : G i :=
f (x a).1 i (h (mem_range_self a)) (x a).2
variable [DirectedSystem G fun i j h => f i j h]
@[simp]
theorem unify_sigma_mk_self {Ξ± : Type*} {i : ΞΉ} {x : Ξ± β G i} :
(unify f (fun a => .mk f i (x a)) i fun _ β¨_, hjβ© =>
_root_.trans (le_of_eq hj.symm) (refl _)) = x := by
ext a
rw [unify]
apply DirectedSystem.map_self
theorem comp_unify {Ξ± : Type*} {x : Ξ± β Ξ£Λ£ f} {i j : ΞΉ} (ij : i β€ j)
(h : i β upperBounds (range (Sigma.fst β x))) :
f i j ij β unify f x i h = unify f x j
fun k hk => _root_.trans (mem_upperBounds.1 h k hk) ij := by
ext a
simp [unify, DirectedSystem.map_map]
end DirectLimit
variable (G)
namespace DirectLimit
/-- The directed limit glues together the structures along the embeddings. -/
def setoid [DirectedSystem G fun i j h => f i j h] [IsDirected ΞΉ (Β· β€ Β·)] : Setoid (Ξ£Λ£ f) where
r := fun β¨i, xβ© β¨j, yβ© => β (k : ΞΉ) (ik : i β€ k) (jk : j β€ k), f i k ik x = f j k jk y
iseqv :=
β¨fun β¨i, _β© => β¨i, refl i, refl i, rflβ©, @fun β¨_, _β© β¨_, _β© β¨k, ik, jk, hβ© =>
β¨k, jk, ik, h.symmβ©,
@fun β¨i, xβ© β¨j, yβ© β¨k, zβ© β¨ij, hiij, hjij, hijβ© β¨jk, hjjk, hkjk, hjkβ© => by
obtain β¨ijk, hijijk, hjkijkβ© := directed_of (Β· β€ Β·) ij jk
refine β¨ijk, le_trans hiij hijijk, le_trans hkjk hjkijk, ?_β©
rw [β DirectedSystem.map_map, hij, DirectedSystem.map_map]
Β· symm
rw [β DirectedSystem.map_map, β hjk, DirectedSystem.map_map]
assumption
assumptionβ©
/-- The structure on the `Ξ£`-type which becomes the structure on the direct limit after quotienting.
-/
noncomputable def sigmaStructure [IsDirected ΞΉ (Β· β€ Β·)] [Nonempty ΞΉ] : L.Structure (Ξ£Λ£ f) where
funMap F x :=
β¨_,
funMap F
(unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1))
(Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))β©
RelMap R x :=
RelMap R
(unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1))
(Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))
end DirectLimit
/-- The direct limit of a directed system is the structures glued together along the embeddings. -/
def DirectLimit [DirectedSystem G fun i j h => f i j h] [IsDirected ΞΉ (Β· β€ Β·)] :=
Quotient (DirectLimit.setoid G f)
attribute [local instance] DirectLimit.setoid DirectLimit.sigmaStructure
instance [DirectedSystem G fun i j h => f i j h] [IsDirected ΞΉ (Β· β€ Β·)] [Inhabited ΞΉ]
[Inhabited (G default)] : Inhabited (DirectLimit G f) :=
β¨β¦β¨default, defaultβ©β§β©
namespace DirectLimit
variable [IsDirected ΞΉ (Β· β€ Β·)] [DirectedSystem G fun i j h => f i j h]
theorem equiv_iff {x y : Ξ£Λ£ f} {i : ΞΉ} (hx : x.1 β€ i) (hy : y.1 β€ i) :
x β y β (f x.1 i hx) x.2 = (f y.1 i hy) y.2 := by
cases x
cases y
refine β¨fun xy => ?_, fun xy => β¨i, hx, hy, xyβ©β©
obtain β¨j, _, _, hβ© := xy
obtain β¨k, ik, jkβ© := directed_of (Β· β€ Β·) i j
have h := congr_arg (f j k jk) h
apply (f i k ik).injective
rw [DirectedSystem.map_map, DirectedSystem.map_map] at *
exact h
theorem funMap_unify_equiv {n : β} (F : L.Functions n) (x : Fin n β Ξ£Λ£ f) (i j : ΞΉ)
(hi : i β upperBounds (range (Sigma.fst β x))) (hj : j β upperBounds (range (Sigma.fst β x))) :
Structure.Sigma.mk f i (funMap F (unify f x i hi)) β .mk f j (funMap F (unify f x j hj)) := by
obtain β¨k, ik, jkβ© := directed_of (Β· β€ Β·) i j
refine β¨k, ik, jk, ?_β©
rw [(f i k ik).map_fun, (f j k jk).map_fun, comp_unify, comp_unify]
theorem relMap_unify_equiv {n : β} (R : L.Relations n) (x : Fin n β Ξ£Λ£ f) (i j : ΞΉ)
(hi : i β upperBounds (range (Sigma.fst β x))) (hj : j β upperBounds (range (Sigma.fst β x))) :
RelMap R (unify f x i hi) = RelMap R (unify f x j hj) := by
obtain β¨k, ik, jkβ© := directed_of (Β· β€ Β·) i j
rw [β (f i k ik).map_rel, comp_unify, β (f j k jk).map_rel, comp_unify]
variable [Nonempty ΞΉ]
theorem exists_unify_eq {Ξ± : Type*} [Finite Ξ±] {x y : Ξ± β Ξ£Λ£ f} (xy : x β y) :
β (i : ΞΉ) (hx : i β upperBounds (range (Sigma.fst β x)))
(hy : i β upperBounds (range (Sigma.fst β y))), unify f x i hx = unify f y i hy := by
obtain β¨i, hiβ© := Finite.bddAbove_range (Sum.elim (fun a => (x a).1) fun a => (y a).1)
rw [Sum.elim_range, upperBounds_union] at hi
simp_rw [β Function.comp_apply (f := Sigma.fst)] at hi
exact β¨i, hi.1, hi.2, funext fun a => (equiv_iff G f _ _).1 (xy a)β©
theorem funMap_equiv_unify {n : β} (F : L.Functions n) (x : Fin n β Ξ£Λ£ f) (i : ΞΉ)
(hi : i β upperBounds (range (Sigma.fst β x))) :
funMap F x β .mk f _ (funMap F (unify f x i hi)) :=
funMap_unify_equiv G f F x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi
theorem relMap_equiv_unify {n : β} (R : L.Relations n) (x : Fin n β Ξ£Λ£ f) (i : ΞΉ)
(hi : i β upperBounds (range (Sigma.fst β x))) :
RelMap R x = RelMap R (unify f x i hi) :=
relMap_unify_equiv G f R x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi
/-- The direct limit `setoid` respects the structure `sigmaStructure`, so quotienting by it
gives rise to a valid structure. -/
noncomputable instance prestructure : L.Prestructure (DirectLimit.setoid G f) where
toStructure := sigmaStructure G f
fun_equiv {n} {F} x y xy := by
obtain β¨i, hx, hy, hβ© := exists_unify_eq G f xy
refine
Setoid.trans (funMap_equiv_unify G f F x i hx)
(Setoid.trans ?_ (Setoid.symm (funMap_equiv_unify G f F y i hy)))
rw [h]
rel_equiv {n} {R} x y xy := by
obtain β¨i, hx, hy, hβ© := exists_unify_eq G f xy
refine _root_.trans (relMap_equiv_unify G f R x i hx)
(_root_.trans ?_ (symm (relMap_equiv_unify G f R y i hy)))
rw [h]
/-- The `L.Structure` on a direct limit of `L.Structure`s. -/
noncomputable instance instStructureDirectLimit : L.Structure (DirectLimit G f) :=
Language.quotientStructure
@[simp]
theorem funMap_quotient_mk'_sigma_mk' {n : β} {F : L.Functions n} {i : ΞΉ} {x : Fin n β G i} :
funMap F (fun a => (β¦.mk f i (x a)β§ : DirectLimit G f)) = β¦.mk f i (funMap F x)β§ := by
simp only [funMap_quotient_mk', Quotient.eq]
obtain β¨k, ik, jkβ© :=
directed_of (Β· β€ Β·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i))
refine β¨k, jk, ik, ?_β©
simp only [Embedding.map_fun, comp_unify]
rfl
@[simp]
theorem relMap_quotient_mk'_sigma_mk' {n : β} {R : L.Relations n} {i : ΞΉ} {x : Fin n β G i} :
RelMap R (fun a => (β¦.mk f i (x a)β§ : DirectLimit G f)) = RelMap R x := by
rw [relMap_quotient_mk']
obtain β¨k, _, _β© :=
directed_of (Β· β€ Β·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i))
rw [relMap_equiv_unify G f R (fun a => .mk f i (x a)) i]
rw [unify_sigma_mk_self]
theorem exists_quotient_mk'_sigma_mk'_eq {Ξ± : Type*} [Finite Ξ±] (x : Ξ± β DirectLimit G f) :
β (i : ΞΉ) (y : Ξ± β G i), x = fun a => β¦.mk f i (y a)β§ := by
obtain β¨i, hiβ© := Finite.bddAbove_range fun a => (x a).out.1
refine β¨i, unify f (Quotient.out β x) i hi, ?_β©
ext a
rw [Quotient.eq_mk_iff_out, unify]
generalize_proofs r
change _ β Structure.Sigma.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd)
have : (.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) : Ξ£Λ£ f).fst β€ i :=
le_rfl
rw [equiv_iff G f (i := i) (hi _) this]
Β· simp only [DirectedSystem.map_self]
exact β¨a, rflβ©
variable (L ΞΉ)
/-- The canonical map from a component to the direct limit. -/
def of (i : ΞΉ) : G i βͺ[L] DirectLimit G f where
toFun := fun a => β¦.mk f i aβ§
inj' x y h := by
rw [Quotient.eq] at h
obtain β¨j, h1, _, h3β© := h
exact (f i j h1).injective h3
map_fun' F x := by
rw [β funMap_quotient_mk'_sigma_mk']
rfl
map_rel' := by
intro n R x
change RelMap R (fun a => (β¦.mk f i (x a)β§ : DirectLimit G f)) β _
simp only [relMap_quotient_mk'_sigma_mk']
| variable {L ΞΉ G f}
@[simp]
theorem of_apply {i : ΞΉ} {x : G i} : of L ΞΉ G f i x = β¦.mk f i xβ§ :=
rfl
-- This is not a simp-lemma because it is not in simp-normal form,
-- but the simp-normal version of this theorem would not be useful.
theorem of_f {i j : ΞΉ} {hij : i β€ j} {x : G i} : of L ΞΉ G f j (f i j hij x) = of L ΞΉ G f i x := by
rw [of_apply, of_apply, Quotient.eq]
refine Setoid.symm β¨j, hij, refl j, ?_β©
simp only [DirectedSystem.map_self]
| Mathlib/ModelTheory/DirectLimit.lean | 281 | 293 |
/-
Copyright (c) 2022 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import Mathlib.Data.Finset.NAry
import Mathlib.Data.Finset.Slice
import Mathlib.Data.Set.Sups
/-!
# Set family operations
This file defines a few binary operations on `Finset Ξ±` for use in set family combinatorics.
## Main declarations
* `Finset.sups s t`: Finset of elements of the form `a β b` where `a β s`, `b β t`.
* `Finset.infs s t`: Finset of elements of the form `a β b` where `a β s`, `b β t`.
* `Finset.disjSups s t`: Finset of elements of the form `a β b` where `a β s`, `b β t` and `a`
and `b` are disjoint.
* `Finset.diffs`: Finset of elements of the form `a \ b` where `a β s`, `b β t`.
* `Finset.compls`: Finset of elements of the form `aαΆ` where `a β s`.
## Notation
We define the following notation in locale `FinsetFamily`:
* `s β» t` for `Finset.sups`
* `s βΌ t` for `Finset.infs`
* `s β t` for `Finset.disjSups s t`
* `s \\ t` for `Finset.diffs`
* `sαΆΛ’` for `Finset.compls`
## References
[B. BollobΓ‘s, *Combinatorics*][bollobas1986]
-/
open Function
open SetFamily
variable {F Ξ± Ξ² : Type*}
namespace Finset
section Sups
variable [DecidableEq Ξ±] [DecidableEq Ξ²]
variable [SemilatticeSup Ξ±] [SemilatticeSup Ξ²] [FunLike F Ξ± Ξ²] [SupHomClass F Ξ± Ξ²]
variable (s sβ sβ t tβ tβ u v : Finset Ξ±)
/-- `s β» t` is the finset of elements of the form `a β b` where `a β s`, `b β t`. -/
protected def hasSups : HasSups (Finset Ξ±) :=
β¨imageβ (Β· β Β·)β©
scoped[FinsetFamily] attribute [instance] Finset.hasSups
open FinsetFamily
variable {s t} {a b c : Ξ±}
@[simp]
theorem mem_sups : c β s β» t β β a β s, β b β t, a β b = c := by simp [(Β· β» Β·)]
variable (s t)
@[simp, norm_cast]
theorem coe_sups : (β(s β» t) : Set Ξ±) = βs β» βt :=
coe_imageβ _ _ _
theorem card_sups_le : #(s β» t) β€ #s * #t := card_imageβ_le _ _ _
theorem card_sups_iff : #(s β» t) = #s * #t β (s ΓΛ’ t : Set (Ξ± Γ Ξ±)).InjOn fun x => x.1 β x.2 :=
card_imageβ_iff
variable {s sβ sβ t tβ tβ u}
theorem sup_mem_sups : a β s β b β t β a β b β s β» t :=
mem_imageβ_of_mem
theorem sups_subset : sβ β sβ β tβ β tβ β sβ β» tβ β sβ β» tβ :=
imageβ_subset
theorem sups_subset_left : tβ β tβ β s β» tβ β s β» tβ :=
imageβ_subset_left
theorem sups_subset_right : sβ β sβ β sβ β» t β sβ β» t :=
imageβ_subset_right
lemma image_subset_sups_left : b β t β s.image (Β· β b) β s β» t := image_subset_imageβ_left
lemma image_subset_sups_right : a β s β t.image (a β Β·) β s β» t := image_subset_imageβ_right
theorem forall_sups_iff {p : Ξ± β Prop} : (β c β s β» t, p c) β β a β s, β b β t, p (a β b) :=
forall_mem_imageβ
@[simp]
theorem sups_subset_iff : s β» t β u β β a β s, β b β t, a β b β u :=
imageβ_subset_iff
@[simp]
theorem sups_nonempty : (s β» t).Nonempty β s.Nonempty β§ t.Nonempty :=
imageβ_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected theorem Nonempty.sups : s.Nonempty β t.Nonempty β (s β» t).Nonempty :=
Nonempty.imageβ
theorem Nonempty.of_sups_left : (s β» t).Nonempty β s.Nonempty :=
Nonempty.of_imageβ_left
theorem Nonempty.of_sups_right : (s β» t).Nonempty β t.Nonempty :=
Nonempty.of_imageβ_right
@[simp]
theorem empty_sups : β
β» t = β
:=
imageβ_empty_left
@[simp]
theorem sups_empty : s β» β
= β
:=
imageβ_empty_right
@[simp]
theorem sups_eq_empty : s β» t = β
β s = β
β¨ t = β
:=
imageβ_eq_empty_iff
@[simp] lemma singleton_sups : {a} β» t = t.image (a β Β·) := imageβ_singleton_left
@[simp] lemma sups_singleton : s β» {b} = s.image (Β· β b) := imageβ_singleton_right
theorem singleton_sups_singleton : ({a} β» {b} : Finset Ξ±) = {a β b} :=
imageβ_singleton
theorem sups_union_left : (sβ βͺ sβ) β» t = sβ β» t βͺ sβ β» t :=
imageβ_union_left
theorem sups_union_right : s β» (tβ βͺ tβ) = s β» tβ βͺ s β» tβ :=
imageβ_union_right
theorem sups_inter_subset_left : (sβ β© sβ) β» t β sβ β» t β© sβ β» t :=
imageβ_inter_subset_left
theorem sups_inter_subset_right : s β» (tβ β© tβ) β s β» tβ β© s β» tβ :=
imageβ_inter_subset_right
theorem subset_sups {s t : Set Ξ±} :
βu β s β» t β β s' t' : Finset Ξ±, βs' β s β§ βt' β t β§ u β s' β» t' :=
subset_set_imageβ
lemma image_sups (f : F) (s t : Finset Ξ±) : image f (s β» t) = image f s β» image f t :=
image_imageβ_distrib <| map_sup f
lemma map_sups (f : F) (hf) (s t : Finset Ξ±) :
map β¨f, hfβ© (s β» t) = map β¨f, hfβ© s β» map β¨f, hfβ© t := by
simpa [map_eq_image] using image_sups f s t
lemma subset_sups_self : s β s β» s := fun _a ha β¦ mem_sups.2 β¨_, ha, _, ha, sup_idem _β©
lemma sups_subset_self : s β» s β s β SupClosed (s : Set Ξ±) := sups_subset_iff
@[simp] lemma sups_eq_self : s β» s = s β SupClosed (s : Set Ξ±) := by simp [β coe_inj]
@[simp] lemma univ_sups_univ [Fintype Ξ±] : (univ : Finset Ξ±) β» univ = univ := by simp
lemma filter_sups_le [DecidableLE Ξ±] (s t : Finset Ξ±) (a : Ξ±) :
{b β s β» t | b β€ a} = {b β s | b β€ a} β» {b β t | b β€ a} := by
simp only [β coe_inj, coe_filter, coe_sups, β mem_coe, Set.sep_sups_le]
variable (s t u)
lemma biUnion_image_sup_left : s.biUnion (fun a β¦ t.image (a β Β·)) = s β» t := biUnion_image_left
lemma biUnion_image_sup_right : t.biUnion (fun b β¦ s.image (Β· β b)) = s β» t := biUnion_image_right
theorem image_sup_product (s t : Finset Ξ±) : (s ΓΛ’ t).image (uncurry (Β· β Β·)) = s β» t :=
image_uncurry_product _ _ _
theorem sups_assoc : s β» t β» u = s β» (t β» u) := imageβ_assoc sup_assoc
theorem sups_comm : s β» t = t β» s := imageβ_comm sup_comm
theorem sups_left_comm : s β» (t β» u) = t β» (s β» u) :=
imageβ_left_comm sup_left_comm
theorem sups_right_comm : s β» t β» u = s β» u β» t :=
imageβ_right_comm sup_right_comm
theorem sups_sups_sups_comm : s β» t β» (u β» v) = s β» u β» (t β» v) :=
imageβ_imageβ_imageβ_comm sup_sup_sup_comm
end Sups
section Infs
variable [DecidableEq Ξ±] [DecidableEq Ξ²]
variable [SemilatticeInf Ξ±] [SemilatticeInf Ξ²] [FunLike F Ξ± Ξ²] [InfHomClass F Ξ± Ξ²]
variable (s sβ sβ t tβ tβ u v : Finset Ξ±)
/-- `s βΌ t` is the finset of elements of the form `a β b` where `a β s`, `b β t`. -/
protected def hasInfs : HasInfs (Finset Ξ±) :=
β¨imageβ (Β· β Β·)β©
scoped[FinsetFamily] attribute [instance] Finset.hasInfs
open FinsetFamily
variable {s t} {a b c : Ξ±}
@[simp]
theorem mem_infs : c β s βΌ t β β a β s, β b β t, a β b = c := by simp [(Β· βΌ Β·)]
variable (s t)
@[simp, norm_cast]
theorem coe_infs : (β(s βΌ t) : Set Ξ±) = βs βΌ βt :=
coe_imageβ _ _ _
theorem card_infs_le : #(s βΌ t) β€ #s * #t := card_imageβ_le _ _ _
theorem card_infs_iff : #(s βΌ t) = #s * #t β (s ΓΛ’ t : Set (Ξ± Γ Ξ±)).InjOn fun x => x.1 β x.2 :=
card_imageβ_iff
variable {s sβ sβ t tβ tβ u}
theorem inf_mem_infs : a β s β b β t β a β b β s βΌ t :=
mem_imageβ_of_mem
theorem infs_subset : sβ β sβ β tβ β tβ β sβ βΌ tβ β sβ βΌ tβ :=
imageβ_subset
theorem infs_subset_left : tβ β tβ β s βΌ tβ β s βΌ tβ :=
imageβ_subset_left
theorem infs_subset_right : sβ β sβ β sβ βΌ t β sβ βΌ t :=
imageβ_subset_right
lemma image_subset_infs_left : b β t β s.image (Β· β b) β s βΌ t := image_subset_imageβ_left
lemma image_subset_infs_right : a β s β t.image (a β Β·) β s βΌ t := image_subset_imageβ_right
theorem forall_infs_iff {p : Ξ± β Prop} : (β c β s βΌ t, p c) β β a β s, β b β t, p (a β b) :=
forall_mem_imageβ
@[simp]
theorem infs_subset_iff : s βΌ t β u β β a β s, β b β t, a β b β u :=
imageβ_subset_iff
@[simp]
theorem infs_nonempty : (s βΌ t).Nonempty β s.Nonempty β§ t.Nonempty :=
imageβ_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected theorem Nonempty.infs : s.Nonempty β t.Nonempty β (s βΌ t).Nonempty :=
Nonempty.imageβ
theorem Nonempty.of_infs_left : (s βΌ t).Nonempty β s.Nonempty :=
Nonempty.of_imageβ_left
theorem Nonempty.of_infs_right : (s βΌ t).Nonempty β t.Nonempty :=
Nonempty.of_imageβ_right
@[simp]
theorem empty_infs : β
βΌ t = β
:=
imageβ_empty_left
@[simp]
theorem infs_empty : s βΌ β
= β
:=
imageβ_empty_right
@[simp]
theorem infs_eq_empty : s βΌ t = β
β s = β
β¨ t = β
:=
imageβ_eq_empty_iff
@[simp] lemma singleton_infs : {a} βΌ t = t.image (a β Β·) := imageβ_singleton_left
@[simp] lemma infs_singleton : s βΌ {b} = s.image (Β· β b) := imageβ_singleton_right
theorem singleton_infs_singleton : ({a} βΌ {b} : Finset Ξ±) = {a β b} :=
imageβ_singleton
theorem infs_union_left : (sβ βͺ sβ) βΌ t = sβ βΌ t βͺ sβ βΌ t :=
imageβ_union_left
theorem infs_union_right : s βΌ (tβ βͺ tβ) = s βΌ tβ βͺ s βΌ tβ :=
imageβ_union_right
theorem infs_inter_subset_left : (sβ β© sβ) βΌ t β sβ βΌ t β© sβ βΌ t :=
imageβ_inter_subset_left
theorem infs_inter_subset_right : s βΌ (tβ β© tβ) β s βΌ tβ β© s βΌ tβ :=
imageβ_inter_subset_right
theorem subset_infs {s t : Set Ξ±} :
βu β s βΌ t β β s' t' : Finset Ξ±, βs' β s β§ βt' β t β§ u β s' βΌ t' :=
subset_set_imageβ
lemma image_infs (f : F) (s t : Finset Ξ±) : image f (s βΌ t) = image f s βΌ image f t :=
image_imageβ_distrib <| map_inf f
lemma map_infs (f : F) (hf) (s t : Finset Ξ±) :
map β¨f, hfβ© (s βΌ t) = map β¨f, hfβ© s βΌ map β¨f, hfβ© t := by
simpa [map_eq_image] using image_infs f s t
lemma subset_infs_self : s β s βΌ s := fun _a ha β¦ mem_infs.2 β¨_, ha, _, ha, inf_idem _β©
lemma infs_self_subset : s βΌ s β s β InfClosed (s : Set Ξ±) := infs_subset_iff
@[simp] lemma infs_self : s βΌ s = s β InfClosed (s : Set Ξ±) := by simp [β coe_inj]
@[simp] lemma univ_infs_univ [Fintype Ξ±] : (univ : Finset Ξ±) βΌ univ = univ := by simp
lemma filter_infs_le [DecidableLE Ξ±] (s t : Finset Ξ±) (a : Ξ±) :
{b β s βΌ t | a β€ b} = {b β s | a β€ b} βΌ {b β t | a β€ b} := by
simp only [β coe_inj, coe_filter, coe_infs, β mem_coe, Set.sep_infs_le]
variable (s t u)
lemma biUnion_image_inf_left : s.biUnion (fun a β¦ t.image (a β Β·)) = s βΌ t := biUnion_image_left
lemma biUnion_image_inf_right : t.biUnion (fun b β¦ s.image (Β· β b)) = s βΌ t := biUnion_image_right
theorem image_inf_product (s t : Finset Ξ±) : (s ΓΛ’ t).image (uncurry (Β· β Β·)) = s βΌ t :=
image_uncurry_product _ _ _
theorem infs_assoc : s βΌ t βΌ u = s βΌ (t βΌ u) := imageβ_assoc inf_assoc
theorem infs_comm : s βΌ t = t βΌ s := imageβ_comm inf_comm
theorem infs_left_comm : s βΌ (t βΌ u) = t βΌ (s βΌ u) :=
imageβ_left_comm inf_left_comm
theorem infs_right_comm : s βΌ t βΌ u = s βΌ u βΌ t :=
imageβ_right_comm inf_right_comm
theorem infs_infs_infs_comm : s βΌ t βΌ (u βΌ v) = s βΌ u βΌ (t βΌ v) :=
imageβ_imageβ_imageβ_comm inf_inf_inf_comm
end Infs
open FinsetFamily
section DistribLattice
variable [DecidableEq Ξ±]
variable [DistribLattice Ξ±] (s t u : Finset Ξ±)
theorem sups_infs_subset_left : s β» t βΌ u β (s β» t) βΌ (s β» u) :=
imageβ_distrib_subset_left sup_inf_left
theorem sups_infs_subset_right : t βΌ u β» s β (t β» s) βΌ (u β» s) :=
imageβ_distrib_subset_right sup_inf_right
theorem infs_sups_subset_left : s βΌ (t β» u) β s βΌ t β» s βΌ u :=
imageβ_distrib_subset_left inf_sup_left
theorem infs_sups_subset_right : (t β» u) βΌ s β t βΌ s β» u βΌ s :=
imageβ_distrib_subset_right inf_sup_right
end DistribLattice
section Finset
variable [DecidableEq Ξ±]
variable {π β¬ : Finset (Finset Ξ±)} {s t : Finset Ξ±}
@[simp] lemma powerset_union (s t : Finset Ξ±) : (s βͺ t).powerset = s.powerset β» t.powerset := by
ext u
simp only [mem_sups, mem_powerset, le_eq_subset, sup_eq_union]
refine β¨fun h β¦ β¨_, inter_subset_left (sβ := u), _, inter_subset_left (sβ := u), ?_β©, ?_β©
Β· rwa [β union_inter_distrib_right, inter_eq_right]
Β· rintro β¨v, hv, w, hw, rflβ©
exact union_subset_union hv hw
@[simp] lemma powerset_inter (s t : Finset Ξ±) : (s β© t).powerset = s.powerset βΌ t.powerset := by
ext u
simp only [mem_infs, mem_powerset, le_eq_subset, inf_eq_inter]
refine β¨fun h β¦ β¨_, inter_subset_left (sβ := u), _, inter_subset_left (sβ := u), ?_β©, ?_β©
Β· rwa [β inter_inter_distrib_right, inter_eq_right]
Β· rintro β¨v, hv, w, hw, rflβ©
exact inter_subset_inter hv hw
@[simp] lemma powerset_sups_powerset_self (s : Finset Ξ±) :
s.powerset β» s.powerset = s.powerset := by simp [β powerset_union]
@[simp] lemma powerset_infs_powerset_self (s : Finset Ξ±) :
s.powerset βΌ s.powerset = s.powerset := by simp [β powerset_inter]
lemma union_mem_sups : s β π β t β β¬ β s βͺ t β π β» β¬ := sup_mem_sups
lemma inter_mem_infs : s β π β t β β¬ β s β© t β π βΌ β¬ := inf_mem_infs
end Finset
section DisjSups
variable [DecidableEq Ξ±]
variable [SemilatticeSup Ξ±] [OrderBot Ξ±] [DecidableRel (Ξ± := Ξ±) Disjoint]
(s sβ sβ t tβ tβ u : Finset Ξ±)
/-- The finset of elements of the form `a β b` where `a β s`, `b β t` and `a` and `b` are disjoint.
-/
def disjSups : Finset Ξ± := {ab β s ΓΛ’ t | Disjoint ab.1 ab.2}.image fun ab => ab.1 β ab.2
@[inherit_doc]
scoped[FinsetFamily] infixl:74 " β " => Finset.disjSups
open FinsetFamily
variable {s t u} {a b c : Ξ±}
@[simp]
theorem mem_disjSups : c β s β t β β a β s, β b β t, Disjoint a b β§ a β b = c := by
simp [disjSups, and_assoc]
theorem disjSups_subset_sups : s β t β s β» t := by
simp_rw [subset_iff, mem_sups, mem_disjSups]
exact fun c β¨a, b, ha, hb, _, hcβ© => β¨a, b, ha, hb, hcβ©
variable (s t)
theorem card_disjSups_le : #(s β t) β€ #s * #t :=
(card_le_card disjSups_subset_sups).trans <| card_sups_le _ _
variable {s sβ sβ t tβ tβ}
theorem disjSups_subset (hs : sβ β sβ) (ht : tβ β tβ) : sβ β tβ β sβ β tβ :=
image_subset_image <| filter_subset_filter _ <| product_subset_product hs ht
theorem disjSups_subset_left (ht : tβ β tβ) : s β tβ β s β tβ :=
disjSups_subset Subset.rfl ht
theorem disjSups_subset_right (hs : sβ β sβ) : sβ β t β sβ β t :=
disjSups_subset hs Subset.rfl
theorem forall_disjSups_iff {p : Ξ± β Prop} :
(β c β s β t, p c) β β a β s, β b β t, Disjoint a b β p (a β b) := by
simp_rw [mem_disjSups]
refine β¨fun h a ha b hb hab => h _ β¨_, ha, _, hb, hab, rflβ©, ?_β©
rintro h _ β¨a, ha, b, hb, hab, rflβ©
exact h _ ha _ hb hab
@[simp]
theorem disjSups_subset_iff : s β t β u β β a β s, β b β t, Disjoint a b β a β b β u :=
forall_disjSups_iff
theorem Nonempty.of_disjSups_left : (s β t).Nonempty β s.Nonempty := by
simp_rw [Finset.Nonempty, mem_disjSups]
exact fun β¨_, a, ha, _β© => β¨a, haβ©
theorem Nonempty.of_disjSups_right : (s β t).Nonempty β t.Nonempty := by
simp_rw [Finset.Nonempty, mem_disjSups]
exact fun β¨_, _, _, b, hb, _β© => β¨b, hbβ©
@[simp]
theorem disjSups_empty_left : β
β t = β
:= by simp [disjSups]
@[simp]
theorem disjSups_empty_right : s β β
= β
:= by simp [disjSups]
theorem disjSups_singleton : ({a} β {b} : Finset Ξ±) = if Disjoint a b then {a β b} else β
:= by
split_ifs with h <;> simp [disjSups, filter_singleton, h]
theorem disjSups_union_left : (sβ βͺ sβ) β t = sβ β t βͺ sβ β t := by
simp [disjSups, filter_union, image_union]
theorem disjSups_union_right : s β (tβ βͺ tβ) = s β tβ βͺ s β tβ := by
simp [disjSups, filter_union, image_union]
theorem disjSups_inter_subset_left : (sβ β© sβ) β t β sβ β t β© sβ β t := by
simpa only [disjSups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _
theorem disjSups_inter_subset_right : s β (tβ β© tβ) β s β tβ β© s β tβ := by
simpa only [disjSups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _
variable (s t)
theorem disjSups_comm : s β t = t β s := by
aesop (add simp disjoint_comm, simp sup_comm)
instance : @Std.Commutative (Finset Ξ±) (Β· β Β·) := β¨disjSups_commβ©
end DisjSups
open FinsetFamily
section DistribLattice
variable [DecidableEq Ξ±]
variable [DistribLattice Ξ±] [OrderBot Ξ±] [DecidableRel (Ξ± := Ξ±) Disjoint] (s t u v : Finset Ξ±)
theorem disjSups_assoc : β s t u : Finset Ξ±, s β t β u = s β (t β u) := by
refine (associative_of_commutative_of_le inferInstance ?_).assoc
simp only [le_eq_subset, disjSups_subset_iff, mem_disjSups]
rintro s t u _ β¨a, ha, b, hb, hab, rflβ© c hc habc
rw [disjoint_sup_left] at habc
exact β¨a, ha, _, β¨b, hb, c, hc, habc.2, rflβ©, hab.sup_right habc.1, (sup_assoc ..).symmβ©
instance : @Std.Associative (Finset Ξ±) (Β· β Β·) := β¨disjSups_assocβ©
theorem disjSups_left_comm : s β (t β u) = t β (s β u) := by
simp_rw [β disjSups_assoc, disjSups_comm s]
theorem disjSups_right_comm : s β t β u = s β u β t := by simp_rw [disjSups_assoc, disjSups_comm]
theorem disjSups_disjSups_disjSups_comm : s β t β (u β v) = s β u β (t β v) := by
simp_rw [β disjSups_assoc, disjSups_right_comm]
end DistribLattice
section Diffs
variable [DecidableEq Ξ±]
variable [GeneralizedBooleanAlgebra Ξ±] (s sβ sβ t tβ tβ u : Finset Ξ±)
/-- `s \\ t` is the finset of elements of the form `a \ b` where `a β s`, `b β t`. -/
def diffs : Finset Ξ± β Finset Ξ± β Finset Ξ± := imageβ (Β· \ Β·)
@[inherit_doc]
scoped[FinsetFamily] infixl:74 " \\\\ " => Finset.diffs
-- This notation is meant to have higher precedence than `\` and `β`, but still within the
-- realm of other binary notation
open FinsetFamily
variable {s t} {a b c : Ξ±}
@[simp] lemma mem_diffs : c β s \\ t β β a β s, β b β t, a \ b = c := by simp [(Β· \\ Β·)]
variable (s t)
@[simp, norm_cast] lemma coe_diffs : (β(s \\ t) : Set Ξ±) = Set.image2 (Β· \ Β·) s t :=
coe_imageβ _ _ _
lemma card_diffs_le : #(s \\ t) β€ #s * #t := card_imageβ_le _ _ _
lemma card_diffs_iff : #(s \\ t) = #s * #t β (s ΓΛ’ t : Set (Ξ± Γ Ξ±)).InjOn fun x β¦ x.1 \ x.2 :=
card_imageβ_iff
variable {s sβ sβ t tβ tβ u}
lemma sdiff_mem_diffs : a β s β b β t β a \ b β s \\ t := mem_imageβ_of_mem
lemma diffs_subset : sβ β sβ β tβ β tβ β sβ \\ tβ β sβ \\ tβ := imageβ_subset
lemma diffs_subset_left : tβ β tβ β s \\ tβ β s \\ tβ := imageβ_subset_left
lemma diffs_subset_right : sβ β sβ β sβ \\ t β sβ \\ t := imageβ_subset_right
lemma image_subset_diffs_left : b β t β s.image (Β· \ b) β s \\ t := image_subset_imageβ_left
lemma image_subset_diffs_right : a β s β t.image (a \ Β·) β s \\ t := image_subset_imageβ_right
lemma forall_mem_diffs {p : Ξ± β Prop} : (β c β s \\ t, p c) β β a β s, β b β t, p (a \ b) :=
forall_mem_imageβ
@[simp] lemma diffs_subset_iff : s \\ t β u β β a β s, β b β t, a \ b β u := imageβ_subset_iff
@[simp]
lemma diffs_nonempty : (s \\ t).Nonempty β s.Nonempty β§ t.Nonempty := imageβ_nonempty_iff
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected lemma Nonempty.diffs : s.Nonempty β t.Nonempty β (s \\ t).Nonempty := Nonempty.imageβ
lemma Nonempty.of_diffs_left : (s \\ t).Nonempty β s.Nonempty := Nonempty.of_imageβ_left
lemma Nonempty.of_diffs_right : (s \\ t).Nonempty β t.Nonempty := Nonempty.of_imageβ_right
@[simp] lemma empty_diffs : β
\\ t = β
:= imageβ_empty_left
@[simp] lemma diffs_empty : s \\ β
= β
:= imageβ_empty_right
@[simp] lemma diffs_eq_empty : s \\ t = β
β s = β
β¨ t = β
:= imageβ_eq_empty_iff
@[simp] lemma singleton_diffs : {a} \\ t = t.image (a \ Β·) := imageβ_singleton_left
@[simp] lemma diffs_singleton : s \\ {b} = s.image (Β· \ b) := imageβ_singleton_right
lemma singleton_diffs_singleton : ({a} \\ {b} : Finset Ξ±) = {a \ b} := imageβ_singleton
lemma diffs_union_left : (sβ βͺ sβ) \\ t = sβ \\ t βͺ sβ \\ t := imageβ_union_left
lemma diffs_union_right : s \\ (tβ βͺ tβ) = s \\ tβ βͺ s \\ tβ := imageβ_union_right
lemma diffs_inter_subset_left : (sβ β© sβ) \\ t β sβ \\ t β© sβ \\ t := imageβ_inter_subset_left
lemma diffs_inter_subset_right : s \\ (tβ β© tβ) β s \\ tβ β© s \\ tβ := imageβ_inter_subset_right
lemma subset_diffs {s t : Set Ξ±} :
βu β Set.image2 (Β· \ Β·) s t β β s' t' : Finset Ξ±, βs' β s β§ βt' β t β§ u β s' \\ t' :=
subset_set_imageβ
variable (s t u)
lemma biUnion_image_sdiff_left : s.biUnion (fun a β¦ t.image (a \ Β·)) = s \\ t := biUnion_image_left
lemma biUnion_image_sdiff_right : t.biUnion (fun b β¦ s.image (Β· \ b)) = s \\ t :=
biUnion_image_right
lemma image_sdiff_product (s t : Finset Ξ±) : (s ΓΛ’ t).image (uncurry (Β· \ Β·)) = s \\ t :=
image_uncurry_product _ _ _
lemma diffs_right_comm : s \\ t \\ u = s \\ u \\ t := imageβ_right_comm sdiff_right_comm
end Diffs
section Compls
variable [BooleanAlgebra Ξ±] (s sβ sβ t : Finset Ξ±)
/-- `sαΆΛ’` is the finset of elements of the form `aαΆ` where `a β s`. -/
def compls : Finset Ξ± β Finset Ξ± := map β¨compl, compl_injectiveβ©
@[inherit_doc]
scoped[FinsetFamily] postfix:max "αΆΛ’" => Finset.compls
open FinsetFamily
variable {s t} {a : Ξ±}
@[simp] lemma mem_compls : a β sαΆΛ’ β aαΆ β s := by
rw [Iff.comm, β mem_map' β¨compl, compl_injectiveβ©, Embedding.coeFn_mk, compl_compl, compls]
variable (s t)
@[simp] lemma image_compl [DecidableEq Ξ±] : s.image compl = sαΆΛ’ := by simp [compls, map_eq_image]
@[simp, norm_cast] lemma coe_compls : (βsαΆΛ’ : Set Ξ±) = compl '' βs := coe_map _ _
@[simp] lemma card_compls : #sαΆΛ’ = #s := card_map _
variable {s sβ sβ t}
lemma compl_mem_compls : a β s β aαΆ β sαΆΛ’ := mem_map_of_mem _
@[simp] lemma compls_subset_compls : sβαΆΛ’ β sβαΆΛ’ β sβ β sβ := map_subset_map
lemma forall_mem_compls {p : Ξ± β Prop} : (β a β sαΆΛ’, p a) β β a β s, p aαΆ := forall_mem_map
lemma exists_compls_iff {p : Ξ± β Prop} : (β a β sαΆΛ’, p a) β β a β s, p aαΆ := by aesop
@[simp] lemma compls_compls (s : Finset Ξ±) : sαΆΛ’αΆΛ’ = s := by ext; simp
lemma compls_subset_iff : sαΆΛ’ β t β s β tαΆΛ’ := by rw [β compls_subset_compls, compls_compls]
@[simp]
lemma compls_nonempty : sαΆΛ’.Nonempty β s.Nonempty := map_nonempty
protected alias β¨Nonempty.of_compls, Nonempty.complsβ© := compls_nonempty
attribute [aesop safe apply (rule_sets := [finsetNonempty])] Nonempty.compls
@[simp] lemma compls_empty : (β
: Finset Ξ±)αΆΛ’ = β
:= map_empty _
@[simp] lemma compls_eq_empty : sαΆΛ’ = β
β s = β
:= map_eq_empty
@[simp] lemma compls_singleton (a : Ξ±) : {a}αΆΛ’ = {aαΆ} := map_singleton _ _
@[simp] lemma compls_univ [Fintype Ξ±] : (univ : Finset Ξ±)αΆΛ’ = univ := by ext; simp
variable [DecidableEq Ξ±]
@[simp] lemma compls_union (s t : Finset Ξ±) : (s βͺ t)αΆΛ’ = sαΆΛ’ βͺ tαΆΛ’ := map_union _ _
@[simp] lemma compls_inter (s t : Finset Ξ±) : (s β© t)αΆΛ’ = sαΆΛ’ β© tαΆΛ’ := map_inter _ _
@[simp] lemma compls_infs (s t : Finset Ξ±) : (s βΌ t)αΆΛ’ = sαΆΛ’ β» tαΆΛ’ := by
simp_rw [β image_compl]; exact image_imageβ_distrib fun _ _ β¦ compl_inf
@[simp] lemma compls_sups (s t : Finset Ξ±) : (s β» t)αΆΛ’ = sαΆΛ’ βΌ tαΆΛ’ := by
simp_rw [β image_compl]; exact image_imageβ_distrib fun _ _ β¦ compl_sup
@[simp] lemma infs_compls_eq_diffs (s t : Finset Ξ±) : s βΌ tαΆΛ’ = s \\ t := by
ext; simp [sdiff_eq]; aesop
@[simp] lemma compls_infs_eq_diffs (s t : Finset Ξ±) : sαΆΛ’ βΌ t = t \\ s := by
rw [infs_comm, infs_compls_eq_diffs]
@[simp] lemma diffs_compls_eq_infs (s t : Finset Ξ±) : s \\ tαΆΛ’ = s βΌ t := by
rw [β infs_compls_eq_diffs, compls_compls]
variable {Ξ± : Type*} [DecidableEq Ξ±] [Fintype Ξ±] {π : Finset (Finset Ξ±)} {n : β}
protected lemma _root_.Set.Sized.compls (hπ : (π : Set (Finset Ξ±)).Sized n) :
(παΆΛ’ : Set (Finset Ξ±)).Sized (Fintype.card Ξ± - n) :=
Finset.forall_mem_compls.2 <| fun s hs β¦ by rw [Finset.card_compl, hπ hs]
lemma sized_compls (hn : n β€ Fintype.card Ξ±) :
(παΆΛ’ : Set (Finset Ξ±)).Sized n β (π : Set (Finset Ξ±)).Sized (Fintype.card Ξ± - n) where
mp hπ := by simpa using hπ.compls
mpr hπ := by simpa only [Nat.sub_sub_self hn] using hπ.compls
end Compls
end Finset
| Mathlib/Data/Finset/Sups.lean | 737 | 737 | |
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.Topology.Algebra.Constructions
import Mathlib.Topology.Bases
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Topology.UniformSpace.Basic
/-!
# Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets.
-/
universe u v
open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity
variable {Ξ± : Type u} {Ξ² : Type v} [uniformSpace : UniformSpace Ξ±]
/-- A filter `f` is Cauchy if for every entourage `r`, there exists an
`s β f` such that `s Γ s β r`. This is a generalization of Cauchy
sequences, because if `a : β β Ξ±` then the filter of sets containing
cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/
def Cauchy (f : Filter Ξ±) :=
NeBot f β§ f ΓΛ’ f β€ π€ Ξ±
/-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s β f`
has a limit in `s` (formally, it satisfies `f β€ π x` for some `x β s`). -/
def IsComplete (s : Set Ξ±) :=
β f, Cauchy f β f β€ π s β β x β s, f β€ π x
theorem Filter.HasBasis.cauchy_iff {ΞΉ} {p : ΞΉ β Prop} {s : ΞΉ β Set (Ξ± Γ Ξ±)} (h : (π€ Ξ±).HasBasis p s)
{f : Filter Ξ±} :
Cauchy f β NeBot f β§ β i, p i β β t β f, β x β t, β y β t, (x, y) β s i :=
and_congr Iff.rfl <|
(f.basis_sets.prod_self.le_basis_iff h).trans <| by
simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm]
theorem cauchy_iff' {f : Filter Ξ±} :
Cauchy f β NeBot f β§ β s β π€ Ξ±, β t β f, β x β t, β y β t, (x, y) β s :=
(π€ Ξ±).basis_sets.cauchy_iff
theorem cauchy_iff {f : Filter Ξ±} : Cauchy f β NeBot f β§ β s β π€ Ξ±, β t β f, t ΓΛ’ t β s :=
cauchy_iff'.trans <| by
simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm]
lemma cauchy_iff_le {l : Filter Ξ±} [hl : l.NeBot] :
Cauchy l β l ΓΛ’ l β€ π€ Ξ± := by
simp only [Cauchy, hl, true_and]
theorem Cauchy.ultrafilter_of {l : Filter Ξ±} (h : Cauchy l) :
Cauchy (@Ultrafilter.of _ l h.1 : Filter Ξ±) := by
haveI := h.1
have := Ultrafilter.of_le l
exact β¨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2β©
theorem cauchy_map_iff {l : Filter Ξ²} {f : Ξ² β Ξ±} :
Cauchy (l.map f) β NeBot l β§ Tendsto (fun p : Ξ² Γ Ξ² => (f p.1, f p.2)) (l ΓΛ’ l) (π€ Ξ±) := by
rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto]
theorem cauchy_map_iff' {l : Filter Ξ²} [hl : NeBot l] {f : Ξ² β Ξ±} :
Cauchy (l.map f) β Tendsto (fun p : Ξ² Γ Ξ² => (f p.1, f p.2)) (l ΓΛ’ l) (π€ Ξ±) :=
cauchy_map_iff.trans <| and_iff_right hl
theorem Cauchy.mono {f g : Filter Ξ±} [hg : NeBot g] (h_c : Cauchy f) (h_le : g β€ f) : Cauchy g :=
β¨hg, le_trans (Filter.prod_mono h_le h_le) h_c.rightβ©
theorem Cauchy.mono' {f g : Filter Ξ±} (h_c : Cauchy f) (_ : NeBot g) (h_le : g β€ f) : Cauchy g :=
h_c.mono h_le
theorem cauchy_nhds {a : Ξ±} : Cauchy (π a) :=
β¨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)β©
theorem cauchy_pure {a : Ξ±} : Cauchy (pure a) :=
cauchy_nhds.mono (pure_le_nhds a)
theorem Filter.Tendsto.cauchy_map {l : Filter Ξ²} [NeBot l] {f : Ξ² β Ξ±} {a : Ξ±}
(h : Tendsto f l (π a)) : Cauchy (map f l) :=
cauchy_nhds.mono h
lemma Cauchy.mono_uniformSpace {u v : UniformSpace Ξ²} {F : Filter Ξ²} (huv : u β€ v)
(hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F :=
β¨hF.1, hF.2.trans huvβ©
lemma cauchy_inf_uniformSpace {u v : UniformSpace Ξ²} {F : Filter Ξ²} :
Cauchy (uniformSpace := u β v) F β
Cauchy (uniformSpace := u) F β§ Cauchy (uniformSpace := v) F := by
unfold Cauchy
rw [inf_uniformity (u := u), le_inf_iff, and_and_left]
lemma cauchy_iInf_uniformSpace {ΞΉ : Sort*} [Nonempty ΞΉ] {u : ΞΉ β UniformSpace Ξ²}
{l : Filter Ξ²} :
Cauchy (uniformSpace := β¨
i, u i) l β β i, Cauchy (uniformSpace := u i) l := by
unfold Cauchy
rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const]
lemma cauchy_iInf_uniformSpace' {ΞΉ : Sort*} {u : ΞΉ β UniformSpace Ξ²}
{l : Filter Ξ²} [l.NeBot] :
Cauchy (uniformSpace := β¨
i, u i) l β β i, Cauchy (uniformSpace := u i) l := by
simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff]
lemma cauchy_comap_uniformSpace {u : UniformSpace Ξ²} {Ξ±} {f : Ξ± β Ξ²} {l : Filter Ξ±} :
Cauchy (uniformSpace := comap f u) l β Cauchy (map f l) := by
simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap]
rfl
lemma cauchy_prod_iff [UniformSpace Ξ²] {F : Filter (Ξ± Γ Ξ²)} :
Cauchy F β Cauchy (map Prod.fst F) β§ Cauchy (map Prod.snd F) := by
simp_rw [instUniformSpaceProd, β cauchy_comap_uniformSpace, β cauchy_inf_uniformSpace]
theorem Cauchy.prod [UniformSpace Ξ²] {f : Filter Ξ±} {g : Filter Ξ²} (hf : Cauchy f) (hg : Cauchy g) :
Cauchy (f ΓΛ’ g) := by
have := hf.1; have := hg.1
simpa [cauchy_prod_iff, hf.1] using β¨hf, hgβ©
/-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and
`SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s`
one can choose a set `t β f` of diameter `s` such that it contains a point `y`
with `(x, y) β s`, then `f` converges to `x`. -/
theorem le_nhds_of_cauchy_adhp_aux {f : Filter Ξ±} {x : Ξ±}
(adhs : β s β π€ Ξ±, β t β f, t ΓΛ’ t β s β§ β y, (x, y) β s β§ y β t) : f β€ π x := by
-- Consider a neighborhood `s` of `x`
intro s hs
-- Take an entourage twice smaller than `s`
rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with β¨U, U_mem, hUβ©
-- Take a set `t β f`, `t Γ t β U`, and a point `y β t` such that `(x, y) β U`
rcases adhs U U_mem with β¨t, t_mem, ht, y, hxy, hyβ©
apply mem_of_superset t_mem
-- Given a point `z β t`, we have `(x, y) β U` and `(y, z) β t Γ t β U`, hence `z β s`
exact fun z hz => hU (prodMk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl
/-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point
for `f`. -/
theorem le_nhds_of_cauchy_adhp {f : Filter Ξ±} {x : Ξ±} (hf : Cauchy f) (adhs : ClusterPt x f) :
f β€ π x :=
le_nhds_of_cauchy_adhp_aux
(fun s hs => by
obtain β¨t, t_mem, htβ© : β t β f, t ΓΛ’ t β s := (cauchy_iff.1 hf).2 s hs
use t, t_mem, ht
exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem))
theorem le_nhds_iff_adhp_of_cauchy {f : Filter Ξ±} {x : Ξ±} (hf : Cauchy f) :
f β€ π x β ClusterPt x f :=
β¨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hfβ©
nonrec theorem Cauchy.map [UniformSpace Ξ²] {f : Filter Ξ±} {m : Ξ± β Ξ²} (hf : Cauchy f)
(hm : UniformContinuous m) : Cauchy (map m f) :=
β¨hf.1.map _,
calc
map m f ΓΛ’ map m f = map (Prod.map m m) (f ΓΛ’ f) := Filter.prod_map_map_eq
_ β€ Filter.map (Prod.map m m) (π€ Ξ±) := map_mono hf.right
_ β€ π€ Ξ² := hmβ©
nonrec theorem Cauchy.comap [UniformSpace Ξ²] {f : Filter Ξ²} {m : Ξ± β Ξ²} (hf : Cauchy f)
(hm : comap (fun p : Ξ± Γ Ξ± => (m p.1, m p.2)) (π€ Ξ²) β€ π€ Ξ±) [NeBot (comap m f)] :
Cauchy (comap m f) :=
β¨βΉ_βΊ,
calc
comap m f ΓΛ’ comap m f = comap (Prod.map m m) (f ΓΛ’ f) := prod_comap_comap_eq
_ β€ comap (Prod.map m m) (π€ Ξ²) := comap_mono hf.right
_ β€ π€ Ξ± := hmβ©
theorem Cauchy.comap' [UniformSpace Ξ²] {f : Filter Ξ²} {m : Ξ± β Ξ²} (hf : Cauchy f)
(hm : Filter.comap (fun p : Ξ± Γ Ξ± => (m p.1, m p.2)) (π€ Ξ²) β€ π€ Ξ±)
(_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) :=
hf.comap hm
/-- Cauchy sequences. Usually defined on β, but often it is also useful to say that a function
defined on β is Cauchy at +β to deduce convergence. Therefore, we define it in a type class that
is general enough to cover both β and β, which are the main motivating examples. -/
def CauchySeq [Preorder Ξ²] (u : Ξ² β Ξ±) :=
Cauchy (atTop.map u)
theorem CauchySeq.tendsto_uniformity [Preorder Ξ²] {u : Ξ² β Ξ±} (h : CauchySeq u) :
Tendsto (Prod.map u u) atTop (π€ Ξ±) := by
simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right
theorem CauchySeq.nonempty [Preorder Ξ²] {u : Ξ² β Ξ±} (hu : CauchySeq u) : Nonempty Ξ² :=
@nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1
theorem CauchySeq.mem_entourage {Ξ² : Type*} [SemilatticeSup Ξ²] {u : Ξ² β Ξ±} (h : CauchySeq u)
{V : Set (Ξ± Γ Ξ±)} (hV : V β π€ Ξ±) : β kβ, β i j, kβ β€ i β kβ β€ j β (u i, u j) β V := by
haveI := h.nonempty
have := h.tendsto_uniformity; rw [β prod_atTop_atTop_eq] at this
simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV
theorem Filter.Tendsto.cauchySeq [SemilatticeSup Ξ²] [Nonempty Ξ²] {f : Ξ² β Ξ±} {x}
(hx : Tendsto f atTop (π x)) : CauchySeq f :=
hx.cauchy_map
theorem cauchySeq_const [SemilatticeSup Ξ²] [Nonempty Ξ²] (x : Ξ±) : CauchySeq fun _ : Ξ² => x :=
tendsto_const_nhds.cauchySeq
theorem cauchySeq_iff_tendsto [Nonempty Ξ²] [SemilatticeSup Ξ²] {u : Ξ² β Ξ±} :
CauchySeq u β Tendsto (Prod.map u u) atTop (π€ Ξ±) :=
cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def]
theorem CauchySeq.comp_tendsto {Ξ³} [Preorder Ξ²] [SemilatticeSup Ξ³] [Nonempty Ξ³] {f : Ξ² β Ξ±}
(hf : CauchySeq f) {g : Ξ³ β Ξ²} (hg : Tendsto g atTop atTop) : CauchySeq (f β g) :=
β¨inferInstance, le_trans (prod_le_prod.mpr β¨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hgβ©) hf.2β©
theorem CauchySeq.comp_injective [SemilatticeSup Ξ²] [NoMaxOrder Ξ²] [Nonempty Ξ²] {u : β β Ξ±}
(hu : CauchySeq u) {f : Ξ² β β} (hf : Injective f) : CauchySeq (u β f) :=
hu.comp_tendsto <| Nat.cofinite_eq_atTop βΈ hf.tendsto_cofinite.mono_left atTop_le_cofinite
theorem Function.Bijective.cauchySeq_comp_iff {f : β β β} (hf : Bijective f) (u : β β Ξ±) :
CauchySeq (u β f) β CauchySeq u := by
refine β¨fun H => ?_, fun H => H.comp_injective hf.injectiveβ©
lift f to β β β using hf
simpa only [Function.comp_def, f.apply_symm_apply] using H.comp_injective f.symm.injective
theorem CauchySeq.subseq_subseq_mem {V : β β Set (Ξ± Γ Ξ±)} (hV : β n, V n β π€ Ξ±) {u : β β Ξ±}
(hu : CauchySeq u) {f g : β β β} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) :
β Ο : β β β, StrictMono Ο β§ β n, ((u β f β Ο) n, (u β g β Ο) n) β V n := by
rw [cauchySeq_iff_tendsto] at hu
exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV
-- todo: generalize this and other lemmas to a nonempty semilattice
theorem cauchySeq_iff' {u : β β Ξ±} :
CauchySeq u β β V β π€ Ξ±, βαΆ k in atTop, k β Prod.map u u β»ΒΉ' V :=
cauchySeq_iff_tendsto
theorem cauchySeq_iff {u : β β Ξ±} :
CauchySeq u β β V β π€ Ξ±, β N, β k β₯ N, β l β₯ N, (u k, u l) β V := by
simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply]
theorem CauchySeq.prodMap {Ξ³ Ξ΄} [UniformSpace Ξ²] [Preorder Ξ³] [Preorder Ξ΄] {u : Ξ³ β Ξ±} {v : Ξ΄ β Ξ²}
(hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by
simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv
@[deprecated (since := "2025-03-10")]
alias CauchySeq.prod_map := CauchySeq.prodMap
theorem CauchySeq.prodMk {Ξ³} [UniformSpace Ξ²] [Preorder Ξ³] {u : Ξ³ β Ξ±} {v : Ξ³ β Ξ²}
(hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) :=
haveI := hu.1.of_map
(Cauchy.prod hu hv).mono (tendsto_map.prodMk tendsto_map)
@[deprecated (since := "2025-03-10")]
alias CauchySeq.prod := CauchySeq.prodMk
theorem CauchySeq.eventually_eventually [Preorder Ξ²] {u : Ξ² β Ξ±} (hu : CauchySeq u)
{V : Set (Ξ± Γ Ξ±)} (hV : V β π€ Ξ±) : βαΆ k in atTop, βαΆ l in atTop, (u k, u l) β V :=
eventually_atTop_curry <| hu.tendsto_uniformity hV
theorem UniformContinuous.comp_cauchySeq {Ξ³} [UniformSpace Ξ²] [Preorder Ξ³] {f : Ξ± β Ξ²}
(hf : UniformContinuous f) {u : Ξ³ β Ξ±} (hu : CauchySeq u) : CauchySeq (f β u) :=
hu.map hf
theorem CauchySeq.subseq_mem {V : β β Set (Ξ± Γ Ξ±)} (hV : β n, V n β π€ Ξ±) {u : β β Ξ±}
(hu : CauchySeq u) : β Ο : β β β, StrictMono Ο β§ β n, (u <| Ο (n + 1), u <| Ο n) β V n := by
have : β n, β N, β k β₯ N, β l β₯ k, (u l, u k) β V n := fun n => by
rw [cauchySeq_iff] at hu
rcases hu _ (hV n) with β¨N, Hβ©
exact β¨N, fun k hk l hl => H _ (le_trans hk hl) _ hkβ©
obtain β¨Ο : β β β, Ο_extr : StrictMono Ο, hΟ : β n, β l β₯ Ο n, (u l, u <| Ο n) β V nβ© :=
extraction_forall_of_eventually' this
exact β¨Ο, Ο_extr, fun n => hΟ _ _ (Ο_extr <| Nat.lt_add_one n).leβ©
theorem Filter.Tendsto.subseq_mem_entourage {V : β β Set (Ξ± Γ Ξ±)} (hV : β n, V n β π€ Ξ±) {u : β β Ξ±}
{a : Ξ±} (hu : Tendsto u atTop (π a)) : β Ο : β β β, StrictMono Ο β§ (u (Ο 0), a) β V 0 β§
β n, (u <| Ο (n + 1), u <| Ο n) β V (n + 1) := by
rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with β¨n, hnβ©
rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with
β¨Ο, Ο_mono, hΟVβ©
exact β¨fun k => Ο k + n, Ο_mono.add_const _, hn _ le_add_self, hΟVβ©
/-- If a Cauchy sequence has a convergent subsequence, then it converges. -/
theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder Ξ²] {u : Ξ² β Ξ±} (hu : CauchySeq u)
{ΞΉ : Type*} {f : ΞΉ β Ξ²} {p : Filter ΞΉ} [NeBot p] (hf : Tendsto f p atTop) {a : Ξ±}
(ha : Tendsto (u β f) p (π a)) : Tendsto u atTop (π a) :=
le_nhds_of_cauchy_adhp hu (ha.mapClusterPt.of_comp hf)
/-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/
theorem cauchySeq_shift {u : β β Ξ±} (k : β) : CauchySeq (fun n β¦ u (n + k)) β CauchySeq u := by
constructor <;> intro h
Β· rw [cauchySeq_iff] at h β’
intro V mV
obtain β¨N, hβ© := h V mV
use N + k
intro a ha b hb
convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega
Β· exact h.comp_tendsto (tendsto_add_atTop_nat k)
theorem Filter.HasBasis.cauchySeq_iff {Ξ³} [Nonempty Ξ²] [SemilatticeSup Ξ²] {u : Ξ² β Ξ±} {p : Ξ³ β Prop}
{s : Ξ³ β Set (Ξ± Γ Ξ±)} (h : (π€ Ξ±).HasBasis p s) :
CauchySeq u β β i, p i β β N, β m, N β€ m β β n, N β€ n β (u m, u n) β s i := by
rw [cauchySeq_iff_tendsto, β prod_atTop_atTop_eq]
refine (atTop_basis.prod_self.tendsto_iff h).trans ?_
simp only [exists_prop, true_and, MapsTo, preimage, subset_def, Prod.forall, mem_prod_eq,
mem_setOf_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ β€ _) Ξ²]
theorem Filter.HasBasis.cauchySeq_iff' {Ξ³} [Nonempty Ξ²] [SemilatticeSup Ξ²] {u : Ξ² β Ξ±}
{p : Ξ³ β Prop} {s : Ξ³ β Set (Ξ± Γ Ξ±)} (H : (π€ Ξ±).HasBasis p s) :
CauchySeq u β β i, p i β β N, β n β₯ N, (u n, u N) β s i := by
refine H.cauchySeq_iff.trans β¨fun h i hi => ?_, fun h i hi => ?_β©
Β· exact (h i hi).imp fun N hN n hn => hN n hn N le_rfl
Β· rcases comp_symm_of_uniformity (H.mem_of_mem hi) with β¨t, ht, ht', htsβ©
rcases H.mem_iff.1 ht with β¨j, hj, hjtβ©
refine (h j hj).imp fun N hN m hm n hn => hts β¨u N, hjt ?_, ht' <| hjt ?_β©
exacts [hN m hm, hN n hn]
theorem cauchySeq_of_controlled [SemilatticeSup Ξ²] [Nonempty Ξ²] (U : Ξ² β Set (Ξ± Γ Ξ±))
(hU : β s β π€ Ξ±, β n, U n β s) {f : Ξ² β Ξ±}
(hf : β β¦N m n : Ξ²β¦, N β€ m β N β€ n β (f m, f n) β U N) : CauchySeq f :=
cauchySeq_iff_tendsto.2
(by
intro s hs
rw [mem_map, mem_atTop_sets]
obtain β¨N, hNβ© := hU s hs
refine β¨(N, N), fun mn hmn => ?_β©
obtain β¨m, nβ© := mn
exact hN (hf hmn.1 hmn.2))
theorem isComplete_iff_clusterPt {s : Set Ξ±} :
IsComplete s β β l, Cauchy l β l β€ π s β β x β s, ClusterPt x l :=
forallβ_congr fun _ hl _ => exists_congr fun _ => and_congr_right fun _ =>
le_nhds_iff_adhp_of_cauchy hl
theorem isComplete_iff_ultrafilter {s : Set Ξ±} :
IsComplete s β β l : Ultrafilter Ξ±, Cauchy (l : Filter Ξ±) β βl β€ π s β β x β s, βl β€ π x := by
refine β¨fun h l => h l, fun H => isComplete_iff_clusterPt.2 fun l hl hls => ?_β©
haveI := hl.1
rcases H (Ultrafilter.of l) hl.ultrafilter_of ((Ultrafilter.of_le l).trans hls) with β¨x, hxs, hxlβ©
exact β¨x, hxs, (ClusterPt.of_le_nhds hxl).mono (Ultrafilter.of_le l)β©
theorem isComplete_iff_ultrafilter' {s : Set Ξ±} :
IsComplete s β β l : Ultrafilter Ξ±, Cauchy (l : Filter Ξ±) β s β l β β x β s, βl β€ π x :=
isComplete_iff_ultrafilter.trans <| by simp only [le_principal_iff, Ultrafilter.mem_coe]
protected theorem IsComplete.union {s t : Set Ξ±} (hs : IsComplete s) (ht : IsComplete t) :
IsComplete (s βͺ t) := by
simp only [isComplete_iff_ultrafilter', Ultrafilter.union_mem_iff, or_imp] at *
exact fun l hl =>
β¨fun hsl => (hs l hl hsl).imp fun x hx => β¨Or.inl hx.1, hx.2β©, fun htl =>
(ht l hl htl).imp fun x hx => β¨Or.inr hx.1, hx.2β©β©
theorem isComplete_iUnion_separated {ΞΉ : Sort*} {s : ΞΉ β Set Ξ±} (hs : β i, IsComplete (s i))
{U : Set (Ξ± Γ Ξ±)} (hU : U β π€ Ξ±) (hd : β (i j : ΞΉ), β x β s i, β y β s j, (x, y) β U β i = j) :
IsComplete (β i, s i) := by
set S := β i, s i
intro l hl hls
rw [le_principal_iff] at hls
obtain β¨hl_ne, hl'β© := cauchy_iff.1 hl
obtain β¨t, htS, htl, htUβ© : β t, t β S β§ t β l β§ t ΓΛ’ t β U := by
rcases hl' U hU with β¨t, htl, htUβ©
refine β¨t β© S, inter_subset_right, inter_mem htl hls, Subset.trans ?_ htUβ©
gcongr <;> apply inter_subset_left
obtain β¨i, hiβ© : β i, t β s i := by
rcases Filter.nonempty_of_mem htl with β¨x, hxβ©
rcases mem_iUnion.1 (htS hx) with β¨i, hiβ©
refine β¨i, fun y hy => ?_β©
rcases mem_iUnion.1 (htS hy) with β¨j, hjβ©
rwa [hd i j x hi y hj (htU <| mk_mem_prod hx hy)]
rcases hs i l hl (le_principal_iff.2 <| mem_of_superset htl hi) with β¨x, hxs, hlxβ©
exact β¨x, mem_iUnion.2 β¨i, hxsβ©, hlxβ©
/-- A complete space is defined here using uniformities. A uniform space
is complete if every Cauchy filter converges. -/
class CompleteSpace (Ξ± : Type u) [UniformSpace Ξ±] : Prop where
/-- In a complete uniform space, every Cauchy filter converges. -/
complete : β {f : Filter Ξ±}, Cauchy f β β x, f β€ π x
theorem complete_univ {Ξ± : Type u} [UniformSpace Ξ±] [CompleteSpace Ξ±] :
IsComplete (univ : Set Ξ±) := fun f hf _ => by
rcases CompleteSpace.complete hf with β¨x, hxβ©
exact β¨x, mem_univ x, hxβ©
instance CompleteSpace.prod [UniformSpace Ξ²] [CompleteSpace Ξ±] [CompleteSpace Ξ²] :
CompleteSpace (Ξ± Γ Ξ²) where
complete hf :=
let β¨x1, hx1β© := CompleteSpace.complete <| hf.map uniformContinuous_fst
let β¨x2, hx2β© := CompleteSpace.complete <| hf.map uniformContinuous_snd
β¨(x1, x2), by rw [nhds_prod_eq, le_prod]; constructor <;> assumptionβ©
lemma CompleteSpace.fst_of_prod [UniformSpace Ξ²] [CompleteSpace (Ξ± Γ Ξ²)] [h : Nonempty Ξ²] :
CompleteSpace Ξ± where
complete hf :=
let β¨yβ© := h
let β¨(a, b), habβ© := CompleteSpace.complete <| hf.prod <| cauchy_pure (a := y)
β¨a, by simpa only [map_fst_prod, nhds_prod_eq] using map_mono (m := Prod.fst) habβ©
lemma CompleteSpace.snd_of_prod [UniformSpace Ξ²] [CompleteSpace (Ξ± Γ Ξ²)] [h : Nonempty Ξ±] :
CompleteSpace Ξ² where
complete hf :=
let β¨xβ© := h
let β¨(a, b), habβ© := CompleteSpace.complete <| (cauchy_pure (a := x)).prod hf
β¨b, by simpa only [map_snd_prod, nhds_prod_eq] using map_mono (m := Prod.snd) habβ©
lemma completeSpace_prod_of_nonempty [UniformSpace Ξ²] [Nonempty Ξ±] [Nonempty Ξ²] :
CompleteSpace (Ξ± Γ Ξ²) β CompleteSpace Ξ± β§ CompleteSpace Ξ² :=
β¨fun _ β¦ β¨.fst_of_prod (Ξ² := Ξ²), .snd_of_prod (Ξ± := Ξ±)β©, fun β¨_, _β© β¦ .prodβ©
@[to_additive]
instance CompleteSpace.mulOpposite [CompleteSpace Ξ±] : CompleteSpace Ξ±α΅α΅α΅ where
complete hf :=
MulOpposite.op_surjective.exists.mpr <|
let β¨x, hxβ© := CompleteSpace.complete (hf.map MulOpposite.uniformContinuous_unop)
β¨x, (map_le_iff_le_comap.mp hx).trans_eq <| MulOpposite.comap_unop_nhds _β©
/-- If `univ` is complete, the space is a complete space -/
theorem completeSpace_of_isComplete_univ (h : IsComplete (univ : Set Ξ±)) : CompleteSpace Ξ± :=
β¨fun hf => let β¨x, _, hxβ© := h _ hf ((@principal_univ Ξ±).symm βΈ le_top); β¨x, hxβ©β©
theorem completeSpace_iff_isComplete_univ : CompleteSpace Ξ± β IsComplete (univ : Set Ξ±) :=
β¨@complete_univ Ξ± _, completeSpace_of_isComplete_univβ©
theorem completeSpace_iff_ultrafilter :
CompleteSpace Ξ± β β l : Ultrafilter Ξ±, Cauchy (l : Filter Ξ±) β β x : Ξ±, βl β€ π x := by
simp [completeSpace_iff_isComplete_univ, isComplete_iff_ultrafilter]
theorem cauchy_iff_exists_le_nhds [CompleteSpace Ξ±] {l : Filter Ξ±} [NeBot l] :
Cauchy l β β x, l β€ π x :=
β¨CompleteSpace.complete, fun β¨_, hxβ© => cauchy_nhds.mono hxβ©
theorem cauchy_map_iff_exists_tendsto [CompleteSpace Ξ±] {l : Filter Ξ²} {f : Ξ² β Ξ±} [NeBot l] :
Cauchy (l.map f) β β x, Tendsto f l (π x) :=
cauchy_iff_exists_le_nhds
/-- A Cauchy sequence in a complete space converges -/
theorem cauchySeq_tendsto_of_complete [Preorder Ξ²] [CompleteSpace Ξ±] {u : Ξ² β Ξ±}
(H : CauchySeq u) : β x, Tendsto u atTop (π x) :=
CompleteSpace.complete H
/-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/
theorem cauchySeq_tendsto_of_isComplete [Preorder Ξ²] {K : Set Ξ±} (hβ : IsComplete K)
{u : Ξ² β Ξ±} (hβ : β n, u n β K) (hβ : CauchySeq u) : β v β K, Tendsto u atTop (π v) :=
hβ _ hβ <| le_principal_iff.2 <| mem_map_iff_exists_image.2
β¨univ, univ_mem, by rwa [image_univ, range_subset_iff]β©
theorem Cauchy.le_nhds_lim [CompleteSpace Ξ±] {f : Filter Ξ±} (hf : Cauchy f) :
haveI := hf.1.nonempty; f β€ π (lim f) :=
_root_.le_nhds_lim (CompleteSpace.complete hf)
theorem CauchySeq.tendsto_limUnder [Preorder Ξ²] [CompleteSpace Ξ±] {u : Ξ² β Ξ±} (h : CauchySeq u) :
haveI := h.1.nonempty; Tendsto u atTop (π <| limUnder atTop u) :=
h.le_nhds_lim
theorem IsClosed.isComplete [CompleteSpace Ξ±] {s : Set Ξ±} (h : IsClosed s) : IsComplete s :=
fun _ cf fs =>
let β¨x, hxβ© := CompleteSpace.complete cf
β¨x, isClosed_iff_clusterPt.mp h x (cf.left.mono (le_inf hx fs)), hxβ©
/-- A set `s` is totally bounded if for every entourage `d` there is a finite
set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/
def TotallyBounded (s : Set Ξ±) : Prop :=
β d β π€ Ξ±, β t : Set Ξ±, t.Finite β§ s β β y β t, { x | (x, y) β d }
theorem TotallyBounded.exists_subset {s : Set Ξ±} (hs : TotallyBounded s) {U : Set (Ξ± Γ Ξ±)}
(hU : U β π€ Ξ±) : β t, t β s β§ Set.Finite t β§ s β β y β t, { x | (x, y) β U } := by
rcases comp_symm_of_uniformity hU with β¨r, hr, rs, rUβ©
rcases hs r hr with β¨k, fk, ksβ©
let u := k β© { y | β x β s, (x, y) β r }
choose f hfs hfr using fun x : u => x.coe_prop.2
refine β¨range f, ?_, ?_, ?_β©
Β· exact range_subset_iff.2 hfs
Β· haveI : Fintype u := (fk.inter_of_left _).fintype
exact finite_range f
Β· intro x xs
obtain β¨y, hy, xyβ© := mem_iUnionβ.1 (ks xs)
rw [biUnion_range, mem_iUnion]
set z : β₯u := β¨y, hy, β¨x, xs, xyβ©β©
exact β¨z, rU <| mem_compRel.2 β¨y, xy, rs (hfr z)β©β©
theorem totallyBounded_iff_subset {s : Set Ξ±} :
TotallyBounded s β
β d β π€ Ξ±, β t, t β s β§ Set.Finite t β§ s β β y β t, { x | (x, y) β d } :=
β¨fun H _ hd β¦ H.exists_subset hd, fun H d hd β¦ let β¨t, _, htβ© := H d hd; β¨t, htβ©β©
theorem Filter.HasBasis.totallyBounded_iff {ΞΉ} {p : ΞΉ β Prop} {U : ΞΉ β Set (Ξ± Γ Ξ±)}
(H : (π€ Ξ±).HasBasis p U) {s : Set Ξ±} :
TotallyBounded s β β i, p i β β t : Set Ξ±, Set.Finite t β§ s β β y β t, { x | (x, y) β U i } :=
H.forall_iff fun _ _ hUV h =>
h.imp fun _ ht => β¨ht.1, ht.2.trans <| iUnionβ_mono fun _ _ _ hy => hUV hyβ©
theorem totallyBounded_of_forall_symm {s : Set Ξ±}
(h : β V β π€ Ξ±, IsSymmetricRel V β β t : Set Ξ±, Set.Finite t β§ s β β y β t, ball y V) :
TotallyBounded s :=
UniformSpace.hasBasis_symmetric.totallyBounded_iff.2 fun V hV => by
simpa only [ball_eq_of_symmetry hV.2] using h V hV.1 hV.2
theorem TotallyBounded.subset {sβ sβ : Set Ξ±} (hs : sβ β sβ) (h : TotallyBounded sβ) :
TotallyBounded sβ := fun d hd =>
let β¨t, htβ, htββ© := h d hd
β¨t, htβ, Subset.trans hs htββ©
/-- The closure of a totally bounded set is totally bounded. -/
theorem TotallyBounded.closure {s : Set Ξ±} (h : TotallyBounded s) : TotallyBounded (closure s) :=
uniformity_hasBasis_closed.totallyBounded_iff.2 fun V hV =>
let β¨t, htf, hstβ© := h V hV.1
β¨t, htf, closure_minimal hst <| htf.isClosed_biUnion fun _ _ => hV.2.preimage (.prodMk_left _)β©
@[simp]
lemma totallyBounded_closure {s : Set Ξ±} : TotallyBounded (closure s) β TotallyBounded s :=
β¨fun h β¦ h.subset subset_closure, TotallyBounded.closureβ©
/-- A finite indexed union is totally bounded
if and only if each set of the family is totally bounded. -/
@[simp]
lemma totallyBounded_iUnion {ΞΉ : Sort*} [Finite ΞΉ] {s : ΞΉ β Set Ξ±} :
TotallyBounded (β i, s i) β β i, TotallyBounded (s i) := by
refine β¨fun h i β¦ h.subset (subset_iUnion _ _), fun h U hU β¦ ?_β©
choose t htf ht using (h Β· U hU)
refine β¨β i, t i, finite_iUnion htf, ?_β©
rw [biUnion_iUnion]
gcongr; apply ht
/-- A union indexed by a finite set is totally bounded
if and only if each set of the family is totally bounded. -/
lemma totallyBounded_biUnion {ΞΉ : Type*} {I : Set ΞΉ} (hI : I.Finite) {s : ΞΉ β Set Ξ±} :
TotallyBounded (β i β I, s i) β β i β I, TotallyBounded (s i) := by
have := hI.to_subtype
rw [biUnion_eq_iUnion, totallyBounded_iUnion, Subtype.forall]
/-- A union of a finite family of sets is totally bounded
if and only if each set of the family is totally bounded. -/
lemma totallyBounded_sUnion {S : Set (Set Ξ±)} (hS : S.Finite) :
TotallyBounded (ββ S) β β s β S, TotallyBounded s := by
rw [sUnion_eq_biUnion, totallyBounded_biUnion hS]
/-- A finite set is totally bounded. -/
lemma Set.Finite.totallyBounded {s : Set Ξ±} (hs : s.Finite) : TotallyBounded s := fun _U hU β¦
β¨s, hs, fun _x hx β¦ mem_biUnion hx <| refl_mem_uniformity hUβ©
/-- A subsingleton is totally bounded. -/
lemma Set.Subsingleton.totallyBounded {s : Set Ξ±} (hs : s.Subsingleton) :
TotallyBounded s :=
hs.finite.totallyBounded
@[simp]
lemma totallyBounded_singleton (a : Ξ±) : TotallyBounded {a} := (finite_singleton a).totallyBounded
@[simp]
theorem totallyBounded_empty : TotallyBounded (β
: Set Ξ±) := finite_empty.totallyBounded
/-- The union of two sets is totally bounded
if and only if each of the two sets is totally bounded. -/
@[simp]
lemma totallyBounded_union {s t : Set Ξ±} :
TotallyBounded (s βͺ t) β TotallyBounded s β§ TotallyBounded t := by
rw [union_eq_iUnion, totallyBounded_iUnion]
simp [and_comm]
/-- The union of two totally bounded sets is totally bounded. -/
protected lemma TotallyBounded.union {s t : Set Ξ±} (hs : TotallyBounded s) (ht : TotallyBounded t) :
TotallyBounded (s βͺ t) :=
totallyBounded_union.2 β¨hs, htβ©
@[simp]
lemma totallyBounded_insert (a : Ξ±) {s : Set Ξ±} :
TotallyBounded (insert a s) β TotallyBounded s := by
simp_rw [β singleton_union, totallyBounded_union, totallyBounded_singleton, true_and]
protected alias β¨_, TotallyBounded.insertβ© := totallyBounded_insert
/-- The image of a totally bounded set under a uniformly continuous map is totally bounded. -/
theorem TotallyBounded.image [UniformSpace Ξ²] {f : Ξ± β Ξ²} {s : Set Ξ±} (hs : TotallyBounded s)
(hf : UniformContinuous f) : TotallyBounded (f '' s) := fun t ht =>
have : { p : Ξ± Γ Ξ± | (f p.1, f p.2) β t } β π€ Ξ± := hf ht
let β¨c, hfc, hctβ© := hs _ this
β¨f '' c, hfc.image f, by
simp only [mem_image, iUnion_exists, biUnion_and', iUnion_iUnion_eq_right, image_subset_iff,
preimage_iUnion, preimage_setOf_eq]
simp? [subset_def] at hct says
simp only [mem_setOf_eq, subset_def, mem_iUnion, exists_prop] at hct
intro x hx
simpa using hct x hxβ©
theorem Ultrafilter.cauchy_of_totallyBounded {s : Set Ξ±} (f : Ultrafilter Ξ±) (hs : TotallyBounded s)
(h : βf β€ π s) : Cauchy (f : Filter Ξ±) :=
β¨f.neBot', fun _ ht =>
let β¨t', ht'β, ht'_symm, ht'_tβ© := comp_symm_of_uniformity ht
let β¨i, hi, hs_unionβ© := hs t' ht'β
have : (β y β i, { x | (x, y) β t' }) β f := mem_of_superset (le_principal_iff.mp h) hs_union
have : β y β i, { x | (x, y) β t' } β f := (Ultrafilter.finite_biUnion_mem_iff hi).1 this
let β¨y, _, hifβ© := this
have : { x | (x, y) β t' } ΓΛ’ { x | (x, y) β t' } β compRel t' t' :=
fun β¨_, _β© β¨(hβ : (_, y) β t'), (hβ : (_, y) β t')β© => β¨y, hβ, ht'_symm hββ©
mem_of_superset (prod_mem_prod hif hif) (Subset.trans this ht'_t)β©
theorem totallyBounded_iff_filter {s : Set Ξ±} :
TotallyBounded s β β f, NeBot f β f β€ π s β β c β€ f, Cauchy c := by
constructor
Β· exact fun H f hf hfs => β¨Ultrafilter.of f, Ultrafilter.of_le f,
(Ultrafilter.of f).cauchy_of_totallyBounded H ((Ultrafilter.of_le f).trans hfs)β©
Β· intro H d hd
contrapose! H with hd_cover
set f := β¨
t : Finset Ξ±, π (s \ β y β t, { x | (x, y) β d })
have hb : HasAntitoneBasis f fun t : Finset Ξ± β¦ s \ β y β t, { x | (x, y) β d } :=
.iInf_principal fun _ _ β¦ diff_subset_diff_right β biUnion_subset_biUnion_left
have : Filter.NeBot f := hb.1.neBot_iff.2 fun _ β¦
diff_nonempty.2 <| hd_cover _ (Finset.finite_toSet _)
have : f β€ π s := iInf_le_of_le β
(by simp)
refine β¨f, βΉ_βΊ, βΉ_βΊ, fun c hcf hc => ?_β©
rcases mem_prod_same_iff.1 (hc.2 hd) with β¨m, hm, hmdβ©
rcases hc.1.nonempty_of_mem hm with β¨y, hymβ©
have : s \ {x | (x, y) β d} β c := by simpa using hcf (hb.mem {y})
rcases hc.1.nonempty_of_mem (inter_mem hm this) with β¨z, hzm, -, hyzβ©
exact hyz (hmd β¨hzm, hymβ©)
|
theorem totallyBounded_iff_ultrafilter {s : Set Ξ±} :
TotallyBounded s β β f : Ultrafilter Ξ±, βf β€ π s β Cauchy (f : Filter Ξ±) := by
refine β¨fun hs f => f.cauchy_of_totallyBounded hs, fun H => totallyBounded_iff_filter.2 ?_β©
intro f hf hfs
exact β¨Ultrafilter.of f, Ultrafilter.of_le f, H _ ((Ultrafilter.of_le f).trans hfs)β©
theorem isCompact_iff_totallyBounded_isComplete {s : Set Ξ±} :
IsCompact s β TotallyBounded s β§ IsComplete s :=
β¨fun hs =>
β¨totallyBounded_iff_ultrafilter.2 fun f hf =>
let β¨_, _, fxβ© := isCompact_iff_ultrafilter_le_nhds.1 hs f hf
cauchy_nhds.mono fx,
fun f fc fs =>
let β¨a, as, faβ© := @hs f fc.1 fs
β¨a, as, le_nhds_of_cauchy_adhp fc faβ©β©,
fun β¨ht, hcβ© =>
isCompact_iff_ultrafilter_le_nhds.2 fun f hf =>
hc _ (totallyBounded_iff_ultrafilter.1 ht f hf) hfβ©
| Mathlib/Topology/UniformSpace/Cauchy.lean | 601 | 619 |
/-
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
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ΞΉ : Sort*} {Ξ± : Type u} {Ξ² : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] {x y : Ξ±} {s t : Set Ξ±} {Ξ¦ : Ξ± β Ξ²}
/-! ### Distance of a point to a set as a function into `ββ₯0β`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : Ξ±) (s : Set Ξ±) : ββ₯0β :=
β¨
y β s, edist x y
@[simp]
theorem infEdist_empty : infEdist x β
= β :=
iInf_emptyset
theorem le_infEdist {d} : d β€ infEdist x s β β y β s, d β€ edist x y := by
simp only [infEdist, le_iInf_iff]
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s βͺ t) = infEdist x s β infEdist x t :=
iInf_union
@[simp]
theorem infEdist_iUnion (f : ΞΉ β Set Ξ±) (x : Ξ±) : infEdist x (β i, f i) = β¨
i, infEdist x (f i) :=
iInf_iUnion f _
lemma infEdist_biUnion {ΞΉ : Type*} (f : ΞΉ β Set Ξ±) (I : Set ΞΉ) (x : Ξ±) :
infEdist x (β i β I, f i) = β¨
i β I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y β s) : infEdist x s β€ edist x y :=
iInfβ_le y h
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x β s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x βΈ infEdist_le_edist_of_mem h
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s β t) : infEdist x t β€ infEdist x s :=
iInf_le_iInf_of_subset h
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ββ₯0β} : infEdist x s < r β β y β s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s β€ infEdist y s + edist x y :=
calc
β¨
z β s, edist x z β€ β¨
z β s, edist y z + edist x y :=
iInfβ_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (β¨
z β s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
theorem infEdist_le_edist_add_infEdist : infEdist x s β€ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
theorem edist_le_infEdist_add_ediam (hy : y β s) : edist x y β€ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInfβ fun i hi => ?_
calc
edist x y β€ edist x i + edist i y := edist_triangle _ _ _
_ β€ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forallβ_true_iff]
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun Ξ΅ Ξ΅pos h => ?_
have Ξ΅0 : 0 < (Ξ΅ / 2 : ββ₯0β) := by simpa [pos_iff_ne_zero] using Ξ΅pos
have : infEdist x (closure s) < infEdist x (closure s) + Ξ΅ / 2 :=
ENNReal.lt_add_right h.ne Ξ΅0.ne'
obtain β¨y : Ξ±, ycs : y β closure s, hy : edist x y < infEdist x (closure s) + βΞ΅ / 2β© :=
infEdist_lt_iff.mp this
obtain β¨z : Ξ±, zs : z β s, dyz : edist y z < βΞ΅ / 2β© := EMetric.mem_closure_iff.1 ycs (Ξ΅ / 2) Ξ΅0
calc
infEdist x s β€ edist x z := infEdist_le_edist_of_mem zs
_ β€ edist x y + edist y z := edist_triangle _ _ _
_ β€ infEdist x (closure s) + Ξ΅ / 2 + Ξ΅ / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + βΞ΅ := by rw [add_assoc, ENNReal.add_halves]
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x β closure s β infEdist x s = 0 :=
β¨fun h => by
rw [β infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun Ξ΅ Ξ΅pos => infEdist_lt_iff.mp <| by rwa [h]β©
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x β s β infEdist x s = 0 := by
rw [β mem_closure_iff_infEdist_zero, h.closure_eq]
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : Ξ±} {E : Set Ξ±} :
0 < infEdist x E β x β closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
theorem infEdist_closure_pos_iff_not_mem_closure {x : Ξ±} {E : Set Ξ±} :
0 < infEdist x (closure E) β x β closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : Ξ±} {E : Set Ξ±} (h : x β closure E) :
β Ξ΅ : β, 0 < Ξ΅ β§ ENNReal.ofReal Ξ΅ < infEdist x E := by
rw [β infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with β¨Ξ΅, β¨_, β¨Ξ΅_pos, Ξ΅_ltβ©β©β©
exact β¨Ξ΅, β¨ENNReal.ofReal_pos.mp Ξ΅_pos, Ξ΅_ltβ©β©
theorem disjoint_closedBall_of_lt_infEdist {r : ββ₯0β} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s β€ edist x y := infEdist_le_edist_of_mem h'y
_ β€ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
/-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
@[to_additive (attr := simp)]
theorem infEdist_smul {M} [SMul M Ξ±] [IsIsometricSMul M Ξ±] (c : M) (x : Ξ±) (s : Set Ξ±) :
infEdist (c β’ x) (c β’ s) = infEdist x s :=
infEdist_image (isometry_smul _ _)
theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set Ξ±} (hU : IsOpen U) :
β F : β β Set Ξ±, (β n, IsClosed (F n)) β§ (β n, F n β U) β§ β n, F n = U β§ Monotone F := by
obtain β¨a, a_pos, a_lt_oneβ© : β a : ββ₯0β, 0 < a β§ a < 1 := exists_between zero_lt_one
let F := fun n : β => (fun x => infEdist x UαΆ) β»ΒΉ' Ici (a ^ n)
have F_subset : β n, F n β U := fun n x hx β¦ by
by_contra h
have : infEdist x UαΆ β 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne'
exact this (infEdist_zero_of_mem h)
refine β¨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_β©
Β· show β n, F n = U
refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_
have : Β¬x β UαΆ := by simpa using hx
rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this
have B : 0 < infEdist x UαΆ := by simpa [pos_iff_ne_zero] using this
have : Filter.Tendsto (fun n => a ^ n) atTop (π 0) :=
ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one
rcases ((tendsto_order.1 this).2 _ B).exists with β¨n, hnβ©
simp only [mem_iUnion, mem_Ici, mem_preimage]
exact β¨n, hn.leβ©
show Monotone F
intro m n hmn x hx
simp only [F, mem_Ici, mem_preimage] at hx β’
apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx
theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : Ξ±) :
β y β s, infEdist x s = edist x y := by
have A : Continuous fun y => edist x y := continuous_const.edist continuous_id
obtain β¨y, ys, hyβ© := hs.exists_isMinOn hne A.continuousOn
exact β¨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])β©
theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) :
β r : ββ₯0, 0 < r β§ β x β s, β y β t, (r : ββ₯0β) < edist x y := by
rcases s.eq_empty_or_nonempty with (rfl | hne)
Β· use 1
simp
obtain β¨x, hx, hβ© := hs.exists_isMinOn hne continuous_infEdist.continuousOn
have : 0 < infEdist x t :=
pos_iff_ne_zero.2 fun H => hst.le_bot β¨hx, (mem_iff_infEdist_zero_of_closed ht).mpr Hβ©
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with β¨r, hβ, hrβ©
exact β¨r, ENNReal.coe_pos.mp hβ, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hzβ©
end InfEdist
/-! ### The Hausdorff distance as a function into `ββ₯0β`. -/
/-- The Hausdorff edistance between two sets is the smallest `r` such that each set
is contained in the `r`-neighborhood of the other one -/
irreducible_def hausdorffEdist {Ξ± : Type u} [PseudoEMetricSpace Ξ±] (s t : Set Ξ±) : ββ₯0β :=
(β¨ x β s, infEdist x t) β β¨ y β t, infEdist y s
section HausdorffEdist
variable [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] {x : Ξ±} {s t u : Set Ξ±} {Ξ¦ : Ξ± β Ξ²}
/-- The Hausdorff edistance of a set to itself vanishes. -/
@[simp]
theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by
simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero]
exact fun x hx => infEdist_zero_of_mem hx
/-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/
theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by
simp only [hausdorffEdist_def]; apply sup_comm
/-- Bounding the Hausdorff edistance by bounding the edistance of any point
in each set to the other set -/
theorem hausdorffEdist_le_of_infEdist {r : ββ₯0β} (H1 : β x β s, infEdist x t β€ r)
(H2 : β x β t, infEdist x s β€ r) : hausdorffEdist s t β€ r := by
simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff]
exact β¨H1, H2β©
/-- Bounding the Hausdorff edistance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
theorem hausdorffEdist_le_of_mem_edist {r : ββ₯0β} (H1 : β x β s, β y β t, edist x y β€ r)
(H2 : β x β t, β y β s, edist x y β€ r) : hausdorffEdist s t β€ r := by
refine hausdorffEdist_le_of_infEdist (fun x xs β¦ ?_) (fun x xt β¦ ?_)
Β· rcases H1 x xs with β¨y, yt, hyβ©
exact le_trans (infEdist_le_edist_of_mem yt) hy
Β· rcases H2 x xt with β¨y, ys, hyβ©
exact le_trans (infEdist_le_edist_of_mem ys) hy
/-- The distance to a set is controlled by the Hausdorff distance. -/
theorem infEdist_le_hausdorffEdist_of_mem (h : x β s) : infEdist x t β€ hausdorffEdist s t := by
rw [hausdorffEdist_def]
refine le_trans ?_ le_sup_left
exact le_iSupβ (Ξ± := ββ₯0β) x h
/-- If the Hausdorff distance is `< r`, then any point in one of the sets has
a corresponding point at distance `< r` in the other set. -/
theorem exists_edist_lt_of_hausdorffEdist_lt {r : ββ₯0β} (h : x β s) (H : hausdorffEdist s t < r) :
β y β t, edist x y < r :=
infEdist_lt_iff.mp <|
calc
infEdist x t β€ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h
_ < r := H
/-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance
between `s` and `t`. -/
theorem infEdist_le_infEdist_add_hausdorffEdist :
infEdist x t β€ infEdist x s + hausdorffEdist s t :=
ENNReal.le_of_forall_pos_le_add fun Ξ΅ Ξ΅pos h => by
have Ξ΅0 : (Ξ΅ / 2 : ββ₯0β) β 0 := by simpa [pos_iff_ne_zero] using Ξ΅pos
have : infEdist x s < infEdist x s + Ξ΅ / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne Ξ΅0
obtain β¨y : Ξ±, ys : y β s, dxy : edist x y < infEdist x s + βΞ΅ / 2β© := infEdist_lt_iff.mp this
have : hausdorffEdist s t < hausdorffEdist s t + Ξ΅ / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne Ξ΅0
obtain β¨z : Ξ±, zt : z β t, dyz : edist y z < hausdorffEdist s t + βΞ΅ / 2β© :=
exists_edist_lt_of_hausdorffEdist_lt ys this
calc
infEdist x t β€ edist x z := infEdist_le_edist_of_mem zt
_ β€ edist x y + edist y z := edist_triangle _ _ _
_ β€ infEdist x s + Ξ΅ / 2 + (hausdorffEdist s t + Ξ΅ / 2) := add_le_add dxy.le dyz.le
_ = infEdist x s + hausdorffEdist s t + Ξ΅ := by
simp [ENNReal.add_halves, add_comm, add_left_comm]
/-- The Hausdorff edistance is invariant under isometries. -/
theorem hausdorffEdist_image (h : Isometry Ξ¦) :
hausdorffEdist (Ξ¦ '' s) (Ξ¦ '' t) = hausdorffEdist s t := by
simp only [hausdorffEdist_def, iSup_image, infEdist_image h]
/-- The Hausdorff distance is controlled by the diameter of the union. -/
theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) :
hausdorffEdist s t β€ diam (s βͺ t) := by
rcases hs with β¨x, xsβ©
rcases ht with β¨y, ytβ©
refine hausdorffEdist_le_of_mem_edist ?_ ?_
Β· intro z hz
exact β¨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)β©
Β· intro z hz
exact β¨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)β©
/-- The Hausdorff distance satisfies the triangle inequality. -/
theorem hausdorffEdist_triangle : hausdorffEdist s u β€ hausdorffEdist s t + hausdorffEdist t u := by
rw [hausdorffEdist_def]
simp only [sup_le_iff, iSup_le_iff]
constructor
Β· show β x β s, infEdist x u β€ hausdorffEdist s t + hausdorffEdist t u
exact fun x xs =>
calc
infEdist x u β€ infEdist x t + hausdorffEdist t u :=
infEdist_le_infEdist_add_hausdorffEdist
_ β€ hausdorffEdist s t + hausdorffEdist t u :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _
Β· show β x β u, infEdist x s β€ hausdorffEdist s t + hausdorffEdist t u
exact fun x xu =>
calc
infEdist x s β€ infEdist x t + hausdorffEdist t s :=
infEdist_le_infEdist_add_hausdorffEdist
_ β€ hausdorffEdist u t + hausdorffEdist t s :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _
_ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm]
/-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/
theorem hausdorffEdist_zero_iff_closure_eq_closure :
hausdorffEdist s t = 0 β closure s = closure t := by
simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, β subset_def,
β mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff]
/-- The Hausdorff edistance between a set and its closure vanishes. -/
@[simp]
theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure]
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closureβ : hausdorffEdist (closure s) t = hausdorffEdist s t := by
refine le_antisymm ?_ ?_
Β· calc
_ β€ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle
_ = hausdorffEdist s t := by simp [hausdorffEdist_comm]
Β· calc
_ β€ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle
_ = hausdorffEdist (closure s) t := by simp
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closureβ : hausdorffEdist s (closure t) = hausdorffEdist s t := by
simp [@hausdorffEdist_comm _ _ s _]
/-- The Hausdorff edistance between sets or their closures is the same. -/
theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by
simp
/-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/
theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) :
hausdorffEdist s t = 0 β s = t := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq]
/-- The Haudorff edistance to the empty set is infinite. -/
theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s β
= β := by
rcases ne with β¨x, xsβ©
have : infEdist x β
β€ hausdorffEdist s β
:= infEdist_le_hausdorffEdist_of_mem xs
simpa using this
/-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/
theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t β β€) :
t.Nonempty :=
t.eq_empty_or_nonempty.resolve_left fun ht β¦ fin (ht.symm βΈ hausdorffEdist_empty hs)
theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t β β€) :
(s = β
β§ t = β
) β¨ (s.Nonempty β§ t.Nonempty) := by
rcases s.eq_empty_or_nonempty with hs | hs
Β· rcases t.eq_empty_or_nonempty with ht | ht
Β· exact Or.inl β¨hs, htβ©
Β· rw [hausdorffEdist_comm] at fin
exact Or.inr β¨nonempty_of_hausdorffEdist_ne_top ht fin, htβ©
Β· exact Or.inr β¨hs, nonempty_of_hausdorffEdist_ne_top hs finβ©
end HausdorffEdist
-- section
end EMetric
/-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to
`sInf` and `sSup` on `β` (which is only conditionally complete), we use the notions in `ββ₯0β`
formulated in terms of the edistance, and coerce them to `β`.
Then their properties follow readily from the corresponding properties in `ββ₯0β`,
modulo some tedious rewriting of inequalities from one to the other. -/
--namespace
namespace Metric
section
variable [PseudoMetricSpace Ξ±] [PseudoMetricSpace Ξ²] {s t u : Set Ξ±} {x y : Ξ±} {Ξ¦ : Ξ± β Ξ²}
open EMetric
/-! ### Distance of a point to a set as a function into `β`. -/
/-- The minimal distance of a point to a set -/
def infDist (x : Ξ±) (s : Set Ξ±) : β :=
ENNReal.toReal (infEdist x s)
theorem infDist_eq_iInf : infDist x s = β¨
y : s, dist x y := by
rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf]
Β· simp only [dist_edist]
Β· exact fun _ β¦ edist_ne_top _ _
/-- The minimal distance is always nonnegative -/
theorem infDist_nonneg : 0 β€ infDist x s := toReal_nonneg
/-- The minimal distance to the empty set is 0 (if you want to have the more reasonable
value `β` instead, use `EMetric.infEdist`, which takes values in `ββ₯0β`) -/
@[simp]
theorem infDist_empty : infDist x β
= 0 := by simp [infDist]
lemma isGLB_infDist (hs : s.Nonempty) : IsGLB ((dist x Β·) '' s) (infDist x s) := by
simpa [infDist_eq_iInf, sInf_image']
using isGLB_csInf (hs.image _) β¨0, by simp [lowerBounds, dist_nonneg]β©
/-- In a metric space, the minimal edistance to a nonempty set is finite. -/
theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s β β€ := by
rcases h with β¨y, hyβ©
exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy)
@[simp]
theorem infEdist_eq_top_iff : infEdist x s = β β s = β
:= by
rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top]
/-- The minimal distance of a point to a set containing it vanishes. -/
theorem infDist_zero_of_mem (h : x β s) : infDist x s = 0 := by
simp [infEdist_zero_of_mem h, infDist]
/-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/
@[simp]
theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist]
/-- The minimal distance to a set is bounded by the distance to any point in this set. -/
theorem infDist_le_dist_of_mem (h : y β s) : infDist x s β€ dist x y := by
rw [dist_edist, infDist]
exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h)
/-- The minimal distance is monotone with respect to inclusion. -/
theorem infDist_le_infDist_of_subset (h : s β t) (hs : s.Nonempty) : infDist x t β€ infDist x s :=
ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h)
lemma le_infDist {r : β} (hs : s.Nonempty) : r β€ infDist x s β β β¦yβ¦, y β s β r β€ dist x y := by
simp_rw [infDist, β ENNReal.ofReal_le_iff_le_toReal (infEdist_ne_top hs), le_infEdist,
ENNReal.ofReal_le_iff_le_toReal (edist_ne_top _ _), β dist_edist]
/-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/
theorem infDist_lt_iff {r : β} (hs : s.Nonempty) : infDist x s < r β β y β s, dist x y < r := by
simp [β not_le, le_infDist hs]
/-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo
the distance between `x` and `y`. -/
theorem infDist_le_infDist_add_dist : infDist x s β€ infDist y s + dist x y := by
rw [infDist, infDist, dist_edist]
refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _))
simp only [infEdist_eq_top_iff, imp_self]
theorem not_mem_of_dist_lt_infDist (h : dist x y < infDist x s) : y β s := fun hy =>
h.not_le <| infDist_le_dist_of_mem hy
theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s :=
disjoint_left.2 fun _y hy => not_mem_of_dist_lt_infDist <| mem_ball'.1 hy
theorem ball_infDist_subset_compl : ball x (infDist x s) β sαΆ :=
(disjoint_ball_infDist (s := s)).subset_compl_right
theorem ball_infDist_compl_subset : ball x (infDist x sαΆ) β s :=
ball_infDist_subset_compl.trans_eq (compl_compl s)
theorem disjoint_closedBall_of_lt_infDist {r : β} (h : r < infDist x s) :
Disjoint (closedBall x r) s :=
disjoint_ball_infDist.mono_left <| closedBall_subset_ball h
theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y β s) :
dist x y β€ infDist x s + diam s := by
rw [infDist, diam, dist_edist]
exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top β¨y, hyβ©) hs.ediam_ne_top
variable (s)
/-- The minimal distance to a set is Lipschitz in point with constant 1 -/
theorem lipschitz_infDist_pt : LipschitzWith 1 (infDist Β· s) :=
LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist
/-- The minimal distance to a set is uniformly continuous in point -/
theorem uniformContinuous_infDist_pt : UniformContinuous (infDist Β· s) :=
(lipschitz_infDist_pt s).uniformContinuous
/-- The minimal distance to a set is continuous in point -/
@[continuity]
theorem continuous_infDist_pt : Continuous (infDist Β· s) :=
(uniformContinuous_infDist_pt s).continuous
variable {s}
/-- The minimal distances to a set and its closure coincide. -/
theorem infDist_closure : infDist x (closure s) = infDist x s := by
simp [infDist, infEdist_closure]
/-- If a point belongs to the closure of `s`, then its infimum distance to `s` equals zero.
The converse is true provided that `s` is nonempty, see `Metric.mem_closure_iff_infDist_zero`. -/
theorem infDist_zero_of_mem_closure (hx : x β closure s) : infDist x s = 0 := by
rw [β infDist_closure]
exact infDist_zero_of_mem hx
/-- A point belongs to the closure of `s` iff its infimum distance to this set vanishes. -/
theorem mem_closure_iff_infDist_zero (h : s.Nonempty) : x β closure s β infDist x s = 0 := by
simp [mem_closure_iff_infEdist_zero, infDist, ENNReal.toReal_eq_zero_iff, infEdist_ne_top h]
theorem infDist_pos_iff_not_mem_closure (hs : s.Nonempty) :
x β closure s β 0 < infDist x s :=
(mem_closure_iff_infDist_zero hs).not.trans infDist_nonneg.gt_iff_ne.symm
/-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes -/
theorem _root_.IsClosed.mem_iff_infDist_zero (h : IsClosed s) (hs : s.Nonempty) :
x β s β infDist x s = 0 := by rw [β mem_closure_iff_infDist_zero hs, h.closure_eq]
/-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes. -/
theorem _root_.IsClosed.not_mem_iff_infDist_pos (h : IsClosed s) (hs : s.Nonempty) :
x β s β 0 < infDist x s := by
simp [h.mem_iff_infDist_zero hs, infDist_nonneg.gt_iff_ne]
theorem continuousAt_inv_infDist_pt (h : x β closure s) :
ContinuousAt (fun x β¦ (infDist x s)β»ΒΉ) x := by
rcases s.eq_empty_or_nonempty with (rfl | hs)
Β· simp only [infDist_empty, continuousAt_const]
Β· refine (continuous_infDist_pt s).continuousAt.invβ ?_
rwa [Ne, β mem_closure_iff_infDist_zero hs]
/-- The infimum distance is invariant under isometries. -/
theorem infDist_image (hΦ : Isometry Φ) : infDist (Φ x) (Φ '' t) = infDist x t := by
simp [infDist, infEdist_image hΦ]
theorem infDist_inter_closedBall_of_mem (h : y β s) :
infDist x (s β© closedBall x (dist y x)) = infDist x s := by
replace h : y β s β© closedBall x (dist y x) := β¨h, mem_closedBall.2 le_rflβ©
refine le_antisymm ?_ (infDist_le_infDist_of_subset inter_subset_left β¨y, hβ©)
refine not_lt.1 fun hlt => ?_
rcases (infDist_lt_iff β¨y, h.1β©).mp hlt with β¨z, hzs, hzβ©
rcases le_or_lt (dist z x) (dist y x) with hle | hlt
Β· exact hz.not_le (infDist_le_dist_of_mem β¨hzs, hleβ©)
Β· rw [dist_comm z, dist_comm y] at hlt
exact (hlt.trans hz).not_le (infDist_le_dist_of_mem h)
theorem _root_.IsCompact.exists_infDist_eq_dist (h : IsCompact s) (hne : s.Nonempty) (x : Ξ±) :
β y β s, infDist x s = dist x y :=
let β¨y, hys, hyβ© := h.exists_infEdist_eq_edist hne x
β¨y, hys, by rw [infDist, dist_edist, hy]β©
theorem _root_.IsClosed.exists_infDist_eq_dist [ProperSpace Ξ±] (h : IsClosed s) (hne : s.Nonempty)
(x : Ξ±) : β y β s, infDist x s = dist x y := by
rcases hne with β¨z, hzβ©
rw [β infDist_inter_closedBall_of_mem hz]
set t := s β© closedBall x (dist z x)
have htc : IsCompact t := (isCompact_closedBall x (dist z x)).inter_left h
have htne : t.Nonempty := β¨z, hz, mem_closedBall.2 le_rflβ©
obtain β¨y, β¨hys, -β©, hydβ© : β y β t, infDist x t = dist x y := htc.exists_infDist_eq_dist htne x
exact β¨y, hys, hydβ©
theorem exists_mem_closure_infDist_eq_dist [ProperSpace Ξ±] (hne : s.Nonempty) (x : Ξ±) :
β y β closure s, infDist x s = dist x y := by
simpa only [infDist_closure] using isClosed_closure.exists_infDist_eq_dist hne.closure x
/-! ### Distance of a point to a set as a function into `ββ₯0`. -/
/-- The minimal distance of a point to a set as a `ββ₯0` -/
def infNndist (x : Ξ±) (s : Set Ξ±) : ββ₯0 :=
ENNReal.toNNReal (infEdist x s)
@[simp]
theorem coe_infNndist : (infNndist x s : β) = infDist x s :=
rfl
/-- The minimal distance to a set (as `ββ₯0`) is Lipschitz in point with constant 1 -/
theorem lipschitz_infNndist_pt (s : Set Ξ±) : LipschitzWith 1 fun x => infNndist x s :=
LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist
/-- The minimal distance to a set (as `ββ₯0`) is uniformly continuous in point -/
theorem uniformContinuous_infNndist_pt (s : Set Ξ±) : UniformContinuous fun x => infNndist x s :=
(lipschitz_infNndist_pt s).uniformContinuous
/-- The minimal distance to a set (as `ββ₯0`) is continuous in point -/
theorem continuous_infNndist_pt (s : Set Ξ±) : Continuous fun x => infNndist x s :=
(uniformContinuous_infNndist_pt s).continuous
/-! ### The Hausdorff distance as a function into `β`. -/
/-- The Hausdorff distance between two sets is the smallest nonnegative `r` such that each set is
included in the `r`-neighborhood of the other. If there is no such `r`, it is defined to
be `0`, arbitrarily. -/
def hausdorffDist (s t : Set Ξ±) : β :=
ENNReal.toReal (hausdorffEdist s t)
/-- The Hausdorff distance is nonnegative. -/
theorem hausdorffDist_nonneg : 0 β€ hausdorffDist s t := by simp [hausdorffDist]
/-- If two sets are nonempty and bounded in a metric space, they are at finite Hausdorff
edistance. -/
theorem hausdorffEdist_ne_top_of_nonempty_of_bounded (hs : s.Nonempty) (ht : t.Nonempty)
(bs : IsBounded s) (bt : IsBounded t) : hausdorffEdist s t β β€ := by
rcases hs with β¨cs, hcsβ©
rcases ht with β¨ct, hctβ©
rcases bs.subset_closedBall ct with β¨rs, hrsβ©
rcases bt.subset_closedBall cs with β¨rt, hrtβ©
have : hausdorffEdist s t β€ ENNReal.ofReal (max rs rt) := by
apply hausdorffEdist_le_of_mem_edist
Β· intro x xs
exists ct, hct
have : dist x ct β€ max rs rt := le_trans (hrs xs) (le_max_left _ _)
rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff]
exact le_trans dist_nonneg this
Β· intro x xt
exists cs, hcs
have : dist x cs β€ max rs rt := le_trans (hrt xt) (le_max_right _ _)
rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff]
exact le_trans dist_nonneg this
exact ne_top_of_le_ne_top ENNReal.ofReal_ne_top this
/-- The Hausdorff distance between a set and itself is zero. -/
@[simp]
theorem hausdorffDist_self_zero : hausdorffDist s s = 0 := by simp [hausdorffDist]
/-- The Hausdorff distances from `s` to `t` and from `t` to `s` coincide. -/
theorem hausdorffDist_comm : hausdorffDist s t = hausdorffDist t s := by
simp [hausdorffDist, hausdorffEdist_comm]
/-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable
value `β` instead, use `EMetric.hausdorffEdist`, which takes values in `ββ₯0β`). -/
@[simp]
theorem hausdorffDist_empty : hausdorffDist s β
= 0 := by
rcases s.eq_empty_or_nonempty with h | h
Β· simp [h]
Β· simp [hausdorffDist, hausdorffEdist_empty h]
/-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable
value `β` instead, use `EMetric.hausdorffEdist`, which takes values in `ββ₯0β`). -/
@[simp]
theorem hausdorffDist_empty' : hausdorffDist β
s = 0 := by simp [hausdorffDist_comm]
/-- Bounding the Hausdorff distance by bounding the distance of any point
in each set to the other set -/
theorem hausdorffDist_le_of_infDist {r : β} (hr : 0 β€ r) (H1 : β x β s, infDist x t β€ r)
(H2 : β x β t, infDist x s β€ r) : hausdorffDist s t β€ r := by
rcases s.eq_empty_or_nonempty with hs | hs
Β· rwa [hs, hausdorffDist_empty']
rcases t.eq_empty_or_nonempty with ht | ht
Β· rwa [ht, hausdorffDist_empty]
have : hausdorffEdist s t β€ ENNReal.ofReal r := by
apply hausdorffEdist_le_of_infEdist _ _
Β· simpa only [infDist, β ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top ht) hr] using H1
Β· simpa only [infDist, β ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top hs) hr] using H2
exact ENNReal.toReal_le_of_le_ofReal hr this
/-- Bounding the Hausdorff distance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
theorem hausdorffDist_le_of_mem_dist {r : β} (hr : 0 β€ r) (H1 : β x β s, β y β t, dist x y β€ r)
(H2 : β x β t, β y β s, dist x y β€ r) : hausdorffDist s t β€ r := by
apply hausdorffDist_le_of_infDist hr
Β· intro x xs
rcases H1 x xs with β¨y, yt, hyβ©
exact le_trans (infDist_le_dist_of_mem yt) hy
Β· intro x xt
rcases H2 x xt with β¨y, ys, hyβ©
exact le_trans (infDist_le_dist_of_mem ys) hy
/-- The Hausdorff distance is controlled by the diameter of the union. -/
theorem hausdorffDist_le_diam (hs : s.Nonempty) (bs : IsBounded s) (ht : t.Nonempty)
(bt : IsBounded t) : hausdorffDist s t β€ diam (s βͺ t) := by
rcases hs with β¨x, xsβ©
rcases ht with β¨y, ytβ©
refine hausdorffDist_le_of_mem_dist diam_nonneg ?_ ?_
Β· exact fun z hz => β¨y, yt, dist_le_diam_of_mem (bs.union bt) (subset_union_left hz)
(subset_union_right yt)β©
Β· exact fun z hz => β¨x, xs, dist_le_diam_of_mem (bs.union bt) (subset_union_right hz)
(subset_union_left xs)β©
/-- The distance to a set is controlled by the Hausdorff distance. -/
theorem infDist_le_hausdorffDist_of_mem (hx : x β s) (fin : hausdorffEdist s t β β€) :
infDist x t β€ hausdorffDist s t :=
toReal_mono fin (infEdist_le_hausdorffEdist_of_mem hx)
/-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance
`< r` of a point in the other set. -/
theorem exists_dist_lt_of_hausdorffDist_lt {r : β} (h : x β s) (H : hausdorffDist s t < r)
(fin : hausdorffEdist s t β β€) : β y β t, dist x y < r := by
have r0 : 0 < r := lt_of_le_of_lt hausdorffDist_nonneg H
have : hausdorffEdist s t < ENNReal.ofReal r := by
rwa [hausdorffDist, β ENNReal.toReal_ofReal (le_of_lt r0),
ENNReal.toReal_lt_toReal fin ENNReal.ofReal_ne_top] at H
rcases exists_edist_lt_of_hausdorffEdist_lt h this with β¨y, hy, yrβ©
rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff r0] at yr
exact β¨y, hy, yrβ©
/-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance
`< r` of a point in the other set. -/
theorem exists_dist_lt_of_hausdorffDist_lt' {r : β} (h : y β t) (H : hausdorffDist s t < r)
(fin : hausdorffEdist s t β β€) : β x β s, dist x y < r := by
rw [hausdorffDist_comm] at H
rw [hausdorffEdist_comm] at fin
simpa [dist_comm] using exists_dist_lt_of_hausdorffDist_lt h H fin
/-- The infimum distance to `s` and `t` are the same, up to the Hausdorff distance
between `s` and `t` -/
theorem infDist_le_infDist_add_hausdorffDist (fin : hausdorffEdist s t β β€) :
infDist x t β€ infDist x s + hausdorffDist s t := by
refine toReal_le_add' infEdist_le_infEdist_add_hausdorffEdist (fun h β¦ ?_) (flip absurd fin)
rw [infEdist_eq_top_iff, β not_nonempty_iff_eq_empty] at h β’
rw [hausdorffEdist_comm] at fin
exact mt (nonempty_of_hausdorffEdist_ne_top Β· fin) h
/-- The Hausdorff distance is invariant under isometries. -/
theorem hausdorffDist_image (h : Isometry Ξ¦) :
hausdorffDist (Ξ¦ '' s) (Ξ¦ '' t) = hausdorffDist s t := by
simp [hausdorffDist, hausdorffEdist_image h]
/-- The Hausdorff distance satisfies the triangle inequality. -/
theorem hausdorffDist_triangle (fin : hausdorffEdist s t β β€) :
hausdorffDist s u β€ hausdorffDist s t + hausdorffDist t u := by
refine toReal_le_add' hausdorffEdist_triangle (flip absurd fin) (not_imp_not.1 fun h β¦ ?_)
rw [hausdorffEdist_comm] at fin
exact ne_top_of_le_ne_top (add_ne_top.2 β¨fin, hβ©) hausdorffEdist_triangle
/-- The Hausdorff distance satisfies the triangle inequality. -/
theorem hausdorffDist_triangle' (fin : hausdorffEdist t u β β€) :
hausdorffDist s u β€ hausdorffDist s t + hausdorffDist t u := by
rw [hausdorffEdist_comm] at fin
have I : hausdorffDist u s β€ hausdorffDist u t + hausdorffDist t s :=
hausdorffDist_triangle fin
simpa [add_comm, hausdorffDist_comm] using I
/-- The Hausdorff distance between a set and its closure vanishes. -/
@[simp]
theorem hausdorffDist_self_closure : hausdorffDist s (closure s) = 0 := by simp [hausdorffDist]
/-- Replacing a set by its closure does not change the Hausdorff distance. -/
@[simp]
theorem hausdorffDist_closureβ : hausdorffDist (closure s) t = hausdorffDist s t := by
simp [hausdorffDist]
/-- Replacing a set by its closure does not change the Hausdorff distance. -/
@[simp]
theorem hausdorffDist_closureβ : hausdorffDist s (closure t) = hausdorffDist s t := by
simp [hausdorffDist]
/-- The Hausdorff distances between two sets and their closures coincide. -/
theorem hausdorffDist_closure : hausdorffDist (closure s) (closure t) = hausdorffDist s t := by
simp [hausdorffDist]
/-- Two sets are at zero Hausdorff distance if and only if they have the same closures. -/
theorem hausdorffDist_zero_iff_closure_eq_closure (fin : hausdorffEdist s t β β€) :
hausdorffDist s t = 0 β closure s = closure t := by
simp [β hausdorffEdist_zero_iff_closure_eq_closure, hausdorffDist,
ENNReal.toReal_eq_zero_iff, fin]
/-- Two closed sets are at zero Hausdorff distance if and only if they coincide. -/
theorem _root_.IsClosed.hausdorffDist_zero_iff_eq (hs : IsClosed s) (ht : IsClosed t)
(fin : hausdorffEdist s t β β€) : hausdorffDist s t = 0 β s = t := by
simp [β hausdorffEdist_zero_iff_eq_of_closed hs ht, hausdorffDist, ENNReal.toReal_eq_zero_iff,
fin]
end
end Metric
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 870 | 870 | |
/-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Bryan Gin-ge Chen, YaΓ«l Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Logic.Equiv.Basic
/-!
# Symmetric difference and bi-implication
This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras.
## Examples
Some examples are
* The symmetric difference of two sets is the set of elements that are in either but not both.
* The symmetric difference on propositions is `Xor'`.
* The symmetric difference on `Bool` is `Bool.xor`.
* The equivalence of propositions. Two propositions are equivalent if they imply each other.
* The symmetric difference translates to addition when considering a Boolean algebra as a Boolean
ring.
## Main declarations
* `symmDiff`: The symmetric difference operator, defined as `(a \ b) β (b \ a)`
* `bihimp`: The bi-implication operator, defined as `(b β¨ a) β (a β¨ b)`
In generalized Boolean algebras, the symmetric difference operator is:
* `symmDiff_comm`: commutative, and
* `symmDiff_assoc`: associative.
## Notations
* `a β b`: `symmDiff a b`
* `a β b`: `bihimp a b`
## References
The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A
Proof from the Book" by John McCuan:
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
## Tags
boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication,
Heyting
-/
assert_not_exists RelIso
open Function OrderDual
variable {ΞΉ Ξ± Ξ² : Type*} {Ο : ΞΉ β Type*}
/-- The symmetric difference operator on a type with `β` and `\` is `(A \ B) β (B \ A)`. -/
def symmDiff [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : Ξ± :=
a \ b β b \ a
/-- The Heyting bi-implication is `(b β¨ a) β (a β¨ b)`. This generalizes equivalence of
propositions. -/
def bihimp [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : Ξ± :=
(b β¨ a) β (a β¨ b)
/-- Notation for symmDiff -/
scoped[symmDiff] infixl:100 " β " => symmDiff
/-- Notation for bihimp -/
scoped[symmDiff] infixl:100 " β " => bihimp
open scoped symmDiff
theorem symmDiff_def [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : a β b = a \ b β b \ a :=
rfl
theorem bihimp_def [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : a β b = (b β¨ a) β (a β¨ b) :=
rfl
theorem symmDiff_eq_Xor' (p q : Prop) : p β q = Xor' p q :=
rfl
@[simp]
theorem bihimp_iff_iff {p q : Prop} : p β q β (p β q) :=
iff_iff_implies_and_implies.symm.trans Iff.comm
@[simp]
theorem Bool.symmDiff_eq_xor : β p q : Bool, p β q = xor p q := by decide
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra Ξ±] (a b c : Ξ±)
@[simp]
theorem toDual_symmDiff : toDual (a β b) = toDual a β toDual b :=
rfl
@[simp]
theorem ofDual_bihimp (a b : Ξ±α΅α΅) : ofDual (a β b) = ofDual a β ofDual b :=
rfl
theorem symmDiff_comm : a β b = b β a := by simp only [symmDiff, sup_comm]
instance symmDiff_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· β Β·) :=
β¨symmDiff_commβ©
@[simp]
theorem symmDiff_self : a β a = β₯ := by rw [symmDiff, sup_idem, sdiff_self]
@[simp]
theorem symmDiff_bot : a β β₯ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq]
@[simp]
theorem bot_symmDiff : β₯ β a = a := by rw [symmDiff_comm, symmDiff_bot]
@[simp]
theorem symmDiff_eq_bot {a b : Ξ±} : a β b = β₯ β a = b := by
simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff]
theorem symmDiff_of_le {a b : Ξ±} (h : a β€ b) : a β b = b \ a := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq]
theorem symmDiff_of_ge {a b : Ξ±} (h : b β€ a) : a β b = a \ b := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq]
theorem symmDiff_le {a b c : Ξ±} (ha : a β€ b β c) (hb : b β€ a β c) : a β b β€ c :=
sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb
theorem symmDiff_le_iff {a b c : Ξ±} : a β b β€ c β a β€ b β c β§ b β€ a β c := by
simp_rw [symmDiff, sup_le_iff, sdiff_le_iff]
@[simp]
theorem symmDiff_le_sup {a b : Ξ±} : a β b β€ a β b :=
sup_le_sup sdiff_le sdiff_le
theorem symmDiff_eq_sup_sdiff_inf : a β b = (a β b) \ (a β b) := by simp [sup_sdiff, symmDiff]
theorem Disjoint.symmDiff_eq_sup {a b : Ξ±} (h : Disjoint a b) : a β b = a β b := by
rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right]
theorem symmDiff_sdiff : a β b \ c = a \ (b β c) β b \ (a β c) := by
rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left]
@[simp]
theorem symmDiff_sdiff_inf : a β b \ (a β b) = a β b := by
rw [symmDiff_sdiff]
simp [symmDiff]
@[simp]
theorem symmDiff_sdiff_eq_sup : a β (b \ a) = a β b := by
rw [symmDiff, sdiff_idem]
exact
le_antisymm (sup_le_sup sdiff_le sdiff_le)
(sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup)
@[simp]
theorem sdiff_symmDiff_eq_sup : (a \ b) β b = a β b := by
rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm]
@[simp]
theorem symmDiff_sup_inf : a β b β a β b = a β b := by
refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_
rw [sup_inf_left, symmDiff]
refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right)
Β· rw [sup_right_comm]
exact le_sup_of_le_left le_sdiff_sup
Β· rw [sup_assoc]
exact le_sup_of_le_right le_sdiff_sup
@[simp]
theorem inf_sup_symmDiff : a β b β a β b = a β b := by rw [sup_comm, symmDiff_sup_inf]
@[simp]
theorem symmDiff_symmDiff_inf : a β b β (a β b) = a β b := by
rw [β symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf]
@[simp]
theorem inf_symmDiff_symmDiff : (a β b) β (a β b) = a β b := by
rw [symmDiff_comm, symmDiff_symmDiff_inf]
theorem symmDiff_triangle : a β c β€ a β b β b β c := by
refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_
rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff]
theorem le_symmDiff_sup_right (a b : Ξ±) : a β€ (a β b) β b := by
convert symmDiff_triangle a b β₯ <;> rw [symmDiff_bot]
theorem le_symmDiff_sup_left (a b : Ξ±) : b β€ (a β b) β a :=
symmDiff_comm a b βΈ le_symmDiff_sup_right ..
end GeneralizedCoheytingAlgebra
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra Ξ±] (a b c : Ξ±)
@[simp]
theorem toDual_bihimp : toDual (a β b) = toDual a β toDual b :=
rfl
@[simp]
theorem ofDual_symmDiff (a b : Ξ±α΅α΅) : ofDual (a β b) = ofDual a β ofDual b :=
rfl
theorem bihimp_comm : a β b = b β a := by simp only [(Β· β Β·), inf_comm]
instance bihimp_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· β Β·) :=
β¨bihimp_commβ©
@[simp]
theorem bihimp_self : a β a = β€ := by rw [bihimp, inf_idem, himp_self]
@[simp]
theorem bihimp_top : a β β€ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq]
@[simp]
theorem top_bihimp : β€ β a = a := by rw [bihimp_comm, bihimp_top]
@[simp]
theorem bihimp_eq_top {a b : Ξ±} : a β b = β€ β a = b :=
@symmDiff_eq_bot Ξ±α΅α΅ _ _ _
theorem bihimp_of_le {a b : Ξ±} (h : a β€ b) : a β b = b β¨ a := by
rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq]
theorem bihimp_of_ge {a b : Ξ±} (h : b β€ a) : a β b = a β¨ b := by
rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq]
theorem le_bihimp {a b c : Ξ±} (hb : a β b β€ c) (hc : a β c β€ b) : a β€ b β c :=
le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb
theorem le_bihimp_iff {a b c : Ξ±} : a β€ b β c β a β b β€ c β§ a β c β€ b := by
simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm]
@[simp]
theorem inf_le_bihimp {a b : Ξ±} : a β b β€ a β b :=
inf_le_inf le_himp le_himp
theorem bihimp_eq_inf_himp_inf : a β b = a β b β¨ a β b := by simp [himp_inf_distrib, bihimp]
theorem Codisjoint.bihimp_eq_inf {a b : Ξ±} (h : Codisjoint a b) : a β b = a β b := by
rw [bihimp, h.himp_eq_left, h.himp_eq_right]
theorem himp_bihimp : a β¨ b β c = (a β c β¨ b) β (a β b β¨ c) := by
rw [bihimp, himp_inf_distrib, himp_himp, himp_himp]
@[simp]
theorem sup_himp_bihimp : a β b β¨ a β b = a β b := by
rw [himp_bihimp]
simp [bihimp]
@[simp]
theorem bihimp_himp_eq_inf : a β (a β¨ b) = a β b :=
@symmDiff_sdiff_eq_sup Ξ±α΅α΅ _ _ _
@[simp]
theorem himp_bihimp_eq_inf : (b β¨ a) β b = a β b :=
@sdiff_symmDiff_eq_sup Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_inf_sup : a β b β (a β b) = a β b :=
@symmDiff_sup_inf Ξ±α΅α΅ _ _ _
@[simp]
theorem sup_inf_bihimp : (a β b) β a β b = a β b :=
@inf_sup_symmDiff Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_bihimp_sup : a β b β (a β b) = a β b :=
@symmDiff_symmDiff_inf Ξ±α΅α΅ _ _ _
@[simp]
theorem sup_bihimp_bihimp : (a β b) β (a β b) = a β b :=
@inf_symmDiff_symmDiff Ξ±α΅α΅ _ _ _
theorem bihimp_triangle : a β b β b β c β€ a β c :=
@symmDiff_triangle Ξ±α΅α΅ _ _ _ _
end GeneralizedHeytingAlgebra
section CoheytingAlgebra
variable [CoheytingAlgebra Ξ±] (a : Ξ±)
@[simp]
theorem symmDiff_top' : a β β€ = οΏ’a := by simp [symmDiff]
@[simp]
theorem top_symmDiff' : β€ β a = οΏ’a := by simp [symmDiff]
@[simp]
theorem hnot_symmDiff_self : (οΏ’a) β a = β€ := by
rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self]
exact Codisjoint.top_le codisjoint_hnot_left
@[simp]
theorem symmDiff_hnot_self : a β (οΏ’a) = β€ := by rw [symmDiff_comm, hnot_symmDiff_self]
theorem IsCompl.symmDiff_eq_top {a b : Ξ±} (h : IsCompl a b) : a β b = β€ := by
rw [h.eq_hnot, hnot_symmDiff_self]
end CoheytingAlgebra
section HeytingAlgebra
variable [HeytingAlgebra Ξ±] (a : Ξ±)
@[simp]
theorem bihimp_bot : a β β₯ = aαΆ := by simp [bihimp]
@[simp]
theorem bot_bihimp : β₯ β a = aαΆ := by simp [bihimp]
@[simp]
theorem compl_bihimp_self : aαΆ β a = β₯ :=
@hnot_symmDiff_self Ξ±α΅α΅ _ _
@[simp]
theorem bihimp_hnot_self : a β aαΆ = β₯ :=
@symmDiff_hnot_self Ξ±α΅α΅ _ _
theorem IsCompl.bihimp_eq_bot {a b : Ξ±} (h : IsCompl a b) : a β b = β₯ := by
rw [h.eq_compl, compl_bihimp_self]
end HeytingAlgebra
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra Ξ±] (a b c d : Ξ±)
@[simp]
theorem sup_sdiff_symmDiff : (a β b) \ a β b = a β b :=
sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf])
theorem disjoint_symmDiff_inf : Disjoint (a β b) (a β b) := by
rw [symmDiff_eq_sup_sdiff_inf]
exact disjoint_sdiff_self_left
theorem inf_symmDiff_distrib_left : a β b β c = (a β b) β (a β c) := by
rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left,
symmDiff_eq_sup_sdiff_inf]
theorem inf_symmDiff_distrib_right : a β b β c = (a β c) β (b β c) := by
simp_rw [inf_comm _ c, inf_symmDiff_distrib_left]
theorem sdiff_symmDiff : c \ a β b = c β a β b β c \ a β c \ b := by
simp only [(Β· β Β·), sdiff_sdiff_sup_sdiff']
theorem sdiff_symmDiff' : c \ a β b = c β a β b β c \ (a β b) := by
rw [sdiff_symmDiff, sdiff_sup]
@[simp]
theorem symmDiff_sdiff_left : a β b \ a = b \ a := by
rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]
@[simp]
theorem symmDiff_sdiff_right : a β b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left]
@[simp]
theorem sdiff_symmDiff_left : a \ a β b = a β b := by simp [sdiff_symmDiff]
@[simp]
theorem sdiff_symmDiff_right : b \ a β b = a β b := by
rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left]
theorem symmDiff_eq_sup : a β b = a β b β Disjoint a b := by
refine β¨fun h => ?_, Disjoint.symmDiff_eq_supβ©
rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h
exact h.of_disjoint_inf_of_le le_sup_left
@[simp]
theorem le_symmDiff_iff_left : a β€ a β b β Disjoint a b := by
refine β¨fun h => ?_, fun h => h.symmDiff_eq_sup.symm βΈ le_sup_leftβ©
rw [symmDiff_eq_sup_sdiff_inf] at h
exact disjoint_iff_inf_le.mpr (le_sdiff_right.1 <| inf_le_of_left_le h).le
@[simp]
theorem le_symmDiff_iff_right : b β€ a β b β Disjoint a b := by
rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm]
theorem symmDiff_symmDiff_left :
a β b β c = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c :=
calc
a β b β c = a β b \ c β c \ a β b := symmDiff_def _ _
_ = a \ (b β c) β b \ (a β c) β (c \ (a β b) β c β a β b) := by
{ rw [sdiff_symmDiff', sup_comm (c β a β b), symmDiff_sdiff] }
_ = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c := by ac_rfl
theorem symmDiff_symmDiff_right :
a β (b β c) = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c :=
calc
a β (b β c) = a \ b β c β b β c \ a := symmDiff_def _ _
_ = a \ (b β c) β a β b β c β (b \ (c β a) β c \ (b β a)) := by
{ rw [sdiff_symmDiff', sup_comm (a β b β c), symmDiff_sdiff] }
_ = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c := by ac_rfl
theorem symmDiff_assoc : a β b β c = a β (b β c) := by
rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right]
instance symmDiff_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· β Β·) :=
β¨symmDiff_assocβ©
theorem symmDiff_left_comm : a β (b β c) = b β (a β c) := by
simp_rw [β symmDiff_assoc, symmDiff_comm]
theorem symmDiff_right_comm : a β b β c = a β c β b := by simp_rw [symmDiff_assoc, symmDiff_comm]
theorem symmDiff_symmDiff_symmDiff_comm : a β b β (c β d) = a β c β (b β d) := by
simp_rw [symmDiff_assoc, symmDiff_left_comm]
@[simp]
theorem symmDiff_symmDiff_cancel_left : a β (a β b) = b := by simp [β symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_cancel_right : b β a β a = b := by simp [symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_self' : a β b β a = b := by
rw [symmDiff_comm, symmDiff_symmDiff_cancel_left]
theorem symmDiff_left_involutive (a : Ξ±) : Involutive (Β· β a) :=
symmDiff_symmDiff_cancel_right _
theorem symmDiff_right_involutive (a : Ξ±) : Involutive (a β Β·) :=
symmDiff_symmDiff_cancel_left _
theorem symmDiff_left_injective (a : Ξ±) : Injective (Β· β a) :=
Function.Involutive.injective (symmDiff_left_involutive a)
theorem symmDiff_right_injective (a : Ξ±) : Injective (a β Β·) :=
Function.Involutive.injective (symmDiff_right_involutive _)
theorem symmDiff_left_surjective (a : Ξ±) : Surjective (Β· β a) :=
Function.Involutive.surjective (symmDiff_left_involutive _)
theorem symmDiff_right_surjective (a : Ξ±) : Surjective (a β Β·) :=
Function.Involutive.surjective (symmDiff_right_involutive _)
variable {a b c}
@[simp]
theorem symmDiff_left_inj : a β b = c β b β a = c :=
(symmDiff_left_injective _).eq_iff
@[simp]
theorem symmDiff_right_inj : a β b = a β c β b = c :=
(symmDiff_right_injective _).eq_iff
@[simp]
theorem symmDiff_eq_left : a β b = a β b = β₯ :=
calc
a β b = a β a β b = a β β₯ := by rw [symmDiff_bot]
_ β b = β₯ := by rw [symmDiff_right_inj]
@[simp]
theorem symmDiff_eq_right : a β b = b β a = β₯ := by rw [symmDiff_comm, symmDiff_eq_left]
protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) :
Disjoint (a β b) c := by
rw [symmDiff_eq_sup_sdiff_inf]
exact (ha.sup_left hb).disjoint_sdiff_left
protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) :
Disjoint a (b β c) :=
(ha.symm.symmDiff_left hb.symm).symm
theorem symmDiff_eq_iff_sdiff_eq (ha : a β€ c) : a β b = c β c \ a = b := by
rw [β symmDiff_of_le ha]
exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm
end GeneralizedBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±] (a b c d : Ξ±)
/-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to
the `GeneralizedBooleanAlgebra` ones -/
section CogeneralizedBooleanAlgebra
@[simp]
theorem inf_himp_bihimp : a β b β¨ a β b = a β b :=
@sup_sdiff_symmDiff Ξ±α΅α΅ _ _ _
theorem codisjoint_bihimp_sup : Codisjoint (a β b) (a β b) :=
@disjoint_symmDiff_inf Ξ±α΅α΅ _ _ _
@[simp]
theorem himp_bihimp_left : a β¨ a β b = a β¨ b :=
@symmDiff_sdiff_left Ξ±α΅α΅ _ _ _
@[simp]
theorem himp_bihimp_right : b β¨ a β b = b β¨ a :=
@symmDiff_sdiff_right Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_himp_left : a β b β¨ a = a β b :=
@sdiff_symmDiff_left Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_himp_right : a β b β¨ b = a β b :=
@sdiff_symmDiff_right Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_eq_inf : a β b = a β b β Codisjoint a b :=
@symmDiff_eq_sup Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_le_iff_left : a β b β€ a β Codisjoint a b :=
@le_symmDiff_iff_left Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_le_iff_right : a β b β€ b β Codisjoint a b :=
@le_symmDiff_iff_right Ξ±α΅α΅ _ _ _
theorem bihimp_assoc : a β b β c = a β (b β c) :=
@symmDiff_assoc Ξ±α΅α΅ _ _ _ _
instance bihimp_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· β Β·) :=
β¨bihimp_assocβ©
theorem bihimp_left_comm : a β (b β c) = b β (a β c) := by simp_rw [β bihimp_assoc, bihimp_comm]
theorem bihimp_right_comm : a β b β c = a β c β b := by simp_rw [bihimp_assoc, bihimp_comm]
theorem bihimp_bihimp_bihimp_comm : a β b β (c β d) = a β c β (b β d) := by
simp_rw [bihimp_assoc, bihimp_left_comm]
@[simp]
theorem bihimp_bihimp_cancel_left : a β (a β b) = b := by simp [β bihimp_assoc]
@[simp]
theorem bihimp_bihimp_cancel_right : b β a β a = b := by simp [bihimp_assoc]
@[simp]
theorem bihimp_bihimp_self : a β b β a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left]
theorem bihimp_left_involutive (a : Ξ±) : Involutive (Β· β a) :=
bihimp_bihimp_cancel_right _
theorem bihimp_right_involutive (a : Ξ±) : Involutive (a β Β·) :=
bihimp_bihimp_cancel_left _
theorem bihimp_left_injective (a : Ξ±) : Injective (Β· β a) :=
@symmDiff_left_injective Ξ±α΅α΅ _ _
theorem bihimp_right_injective (a : Ξ±) : Injective (a β Β·) :=
@symmDiff_right_injective Ξ±α΅α΅ _ _
theorem bihimp_left_surjective (a : Ξ±) : Surjective (Β· β a) :=
@symmDiff_left_surjective Ξ±α΅α΅ _ _
theorem bihimp_right_surjective (a : Ξ±) : Surjective (a β Β·) :=
@symmDiff_right_surjective Ξ±α΅α΅ _ _
variable {a b c}
@[simp]
theorem bihimp_left_inj : a β b = c β b β a = c :=
(bihimp_left_injective _).eq_iff
@[simp]
theorem bihimp_right_inj : a β b = a β c β b = c :=
(bihimp_right_injective _).eq_iff
@[simp]
theorem bihimp_eq_left : a β b = a β b = β€ :=
@symmDiff_eq_left Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_eq_right : a β b = b β a = β€ :=
@symmDiff_eq_right Ξ±α΅α΅ _ _ _
protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) :
Codisjoint (a β b) c :=
(ha.inf_left hb).mono_left inf_le_bihimp
protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) :
Codisjoint a (b β c) :=
(ha.inf_right hb).mono_right inf_le_bihimp
end CogeneralizedBooleanAlgebra
theorem symmDiff_eq : a β b = a β bαΆ β b β aαΆ := by simp only [(Β· β Β·), sdiff_eq]
theorem bihimp_eq : a β b = (a β bαΆ) β (b β aαΆ) := by simp only [(Β· β Β·), himp_eq]
theorem symmDiff_eq' : a β b = (a β b) β (aαΆ β bαΆ) := by
rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf]
theorem bihimp_eq' : a β b = a β b β aαΆ β bαΆ :=
@symmDiff_eq' Ξ±α΅α΅ _ _ _
theorem symmDiff_top : a β β€ = aαΆ :=
symmDiff_top' _
theorem top_symmDiff : β€ β a = aαΆ :=
top_symmDiff' _
@[simp]
theorem compl_symmDiff : (a β b)αΆ = a β b := by
simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm]
@[simp]
theorem compl_bihimp : (a β b)αΆ = a β b :=
@compl_symmDiff Ξ±α΅α΅ _ _ _
@[simp]
theorem compl_symmDiff_compl : aαΆ β bαΆ = a β b :=
(sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq]
@[simp]
theorem compl_bihimp_compl : aαΆ β bαΆ = a β b :=
@compl_symmDiff_compl Ξ±α΅α΅ _ _ _
@[simp]
theorem symmDiff_eq_top : a β b = β€ β IsCompl a b := by
rw [symmDiff_eq', β compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff,
codisjoint_iff, and_comm]
@[simp]
theorem bihimp_eq_bot : a β b = β₯ β IsCompl a b := by
rw [bihimp_eq', β compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff,
codisjoint_iff]
@[simp]
theorem compl_symmDiff_self : aαΆ β a = β€ :=
hnot_symmDiff_self _
@[simp]
theorem symmDiff_compl_self : a β aαΆ = β€ :=
symmDiff_hnot_self _
theorem symmDiff_symmDiff_right' :
a β (b β c) = a β b β c β a β bαΆ β cαΆ β aαΆ β b β cαΆ β aαΆ β bαΆ β c :=
calc
a β (b β c) = a β (b β c β bαΆ β cαΆ) β (b β cαΆ β c β bαΆ) β aαΆ := by
{ rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] }
_ = a β b β c β a β bαΆ β cαΆ β b β cαΆ β aαΆ β c β bαΆ β aαΆ := by
{ rw [inf_sup_left, inf_sup_right, β sup_assoc, β inf_assoc, β inf_assoc] }
| _ = a β b β c β a β bαΆ β cαΆ β aαΆ β b β cαΆ β aαΆ β bαΆ β c := (by
congr 1
| Mathlib/Order/SymmDiff.lean | 642 | 643 |
/-
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, Yury Kudryashov, Kim Morrison
-/
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Algebra.Algebra.NonUnitalHom
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Algebra.MonoidAlgebra.MapDomain
import Mathlib.Data.Finsupp.SMul
import Mathlib.LinearAlgebra.Finsupp.SumProd
/-!
# Monoid algebras
-/
noncomputable section
open Finset
open Finsupp hiding single mapDomain
universe uβ uβ uβ uβ
variable (k : Type uβ) (G : Type uβ) (H : Type*) {R : Type*}
/-! ### Multiplicative monoids -/
namespace MonoidAlgebra
variable {k G}
/-! #### Non-unital, non-associative algebra structure -/
section NonUnitalNonAssocAlgebra
variable (k) [Semiring k] [DistribSMul R k] [Mul G]
variable {A : Type uβ} [NonUnitalNonAssocSemiring A]
/-- A non_unital `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem nonUnitalAlgHom_ext [DistribMulAction k A] {Οβ Οβ : MonoidAlgebra k G βββ[k] A}
(h : β x, Οβ (single x 1) = Οβ (single x 1)) : Οβ = Οβ :=
NonUnitalAlgHom.to_distribMulActionHom_injective <|
Finsupp.distribMulActionHom_ext' fun a => DistribMulActionHom.ext_ring (h a)
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {Οβ Οβ : MonoidAlgebra k G βββ[k] A}
(h : Οβ.toMulHom.comp (ofMagma k G) = Οβ.toMulHom.comp (ofMagma k G)) : Οβ = Οβ :=
nonUnitalAlgHom_ext k <| DFunLike.congr_fun h
/-- The functor `G β¦ MonoidAlgebra k G`, from the category of magmas to the category of non-unital,
non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/
@[simps apply_apply symm_apply]
def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] :
(G ββ* A) β (MonoidAlgebra k G βββ[k] A) where
toFun f :=
{ liftAddHom fun x => (smulAddHom k A).flip (f x) with
toFun := fun a => a.sum fun m t => t β’ f m
map_smul' := fun t' a => by
rw [Finsupp.smul_sum, sum_smul_index']
Β· simp_rw [smul_assoc, MonoidHom.id_apply]
Β· intro m
exact zero_smul k (f m)
map_mul' := fun aβ aβ => by
let g : G β k β A := fun m t => t β’ f m
have hβ : β m, g m 0 = 0 := by
intro m
exact zero_smul k (f m)
have hβ : β (m) (tβ tβ : k), g m (tβ + tβ) = g m tβ + g m tβ := by
intros
rw [β add_smul]
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp_rw [Finsupp.mul_sum, Finsupp.sum_mul, smul_mul_smul_comm, β f.map_mul, mul_def,
sum_comm aβ aβ]
rw [sum_sum_index hβ hβ]; congr; ext
rw [sum_sum_index hβ hβ]; congr; ext
rw [sum_single_index (hβ _)] }
invFun F := F.toMulHom.comp (ofMagma k G)
left_inv f := by
ext m
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
right_inv F := by
ext m
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
end NonUnitalNonAssocAlgebra
/-! #### Algebra structure -/
section Algebra
/-- The instance `Algebra k (MonoidAlgebra A G)` whenever we have `Algebra k A`.
In particular this provides the instance `Algebra k (MonoidAlgebra k G)`.
-/
instance algebra {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
Algebra k (MonoidAlgebra A G) where
algebraMap := singleOneRingHom.comp (algebraMap k A)
smul_def' := fun r a => by
ext
rw [Finsupp.coe_smul]
simp [single_one_mul_apply, Algebra.smul_def, Pi.smul_apply]
commutes' := fun r f => by
refine Finsupp.ext fun _ => ?_
simp [single_one_mul_apply, mul_single_one_apply, Algebra.commutes]
/-- `Finsupp.single 1` as an `AlgHom` -/
@[simps! apply]
def singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
A ββ[k] MonoidAlgebra A G :=
{ singleOneRingHom with
commutes' := fun r => by
ext
simp
rfl }
@[simp]
theorem coe_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
β(algebraMap k (MonoidAlgebra A G)) = single 1 β algebraMap k A :=
rfl
theorem single_eq_algebraMap_mul_of [CommSemiring k] [Monoid G] (a : G) (b : k) :
single a b = algebraMap k (MonoidAlgebra k G) b * of k G a := by simp
theorem single_algebraMap_eq_algebraMap_mul_of {A : Type*} [CommSemiring k] [Semiring A]
[Algebra k A] [Monoid G] (a : G) (b : k) :
single a (algebraMap k A b) = algebraMap k (MonoidAlgebra A G) b * of A G a := by simp
instance isLocalHom_singleOneAlgHom
{A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
IsLocalHom (singleOneAlgHom : A ββ[k] MonoidAlgebra A G) where
map_nonunit := isLocalHom_singleOneRingHom.map_nonunit
instance isLocalHom_algebraMap
{A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G]
[IsLocalHom (algebraMap k A)] :
IsLocalHom (algebraMap k (MonoidAlgebra A G)) where
map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleOneAlgHom (k := k).map_nonunit _ hx
end Algebra
section lift
variable [CommSemiring k] [Monoid G] [Monoid H]
variable {A : Type uβ} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B]
/-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/
def liftNCAlgHom (f : A ββ[k] B) (g : G β* B) (h_comm : β x y, Commute (f x) (g y)) :
MonoidAlgebra A G ββ[k] B :=
{ liftNCRingHom (f : A β+* B) g h_comm with
commutes' := by simp [liftNCRingHom] }
/-- A `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem algHom_ext β¦Οβ Οβ : MonoidAlgebra k G ββ[k] Aβ¦
(h : β x, Οβ (single x 1) = Οβ (single x 1)) : Οβ = Οβ :=
AlgHom.toLinearMap_injective <| Finsupp.lhom_ext' fun a => LinearMap.ext_ring (h a)
-- The priority must be `high`.
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem algHom_ext' β¦Οβ Οβ : MonoidAlgebra k G ββ[k] Aβ¦
(h :
(Οβ : MonoidAlgebra k G β* A).comp (of k G) = (Οβ : MonoidAlgebra k G β* A).comp (of k G)) :
Οβ = Οβ :=
algHom_ext <| DFunLike.congr_fun h
variable (k G A)
/-- Any monoid homomorphism `G β* A` can be lifted to an algebra homomorphism
`MonoidAlgebra k G ββ[k] A`. -/
def lift : (G β* A) β (MonoidAlgebra k G ββ[k] A) where
invFun f := (f : MonoidAlgebra k G β* A).comp (of k G)
toFun F := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _
left_inv f := by
ext
simp [liftNCAlgHom, liftNCRingHom]
right_inv F := by
ext
simp [liftNCAlgHom, liftNCRingHom]
variable {k G H A}
theorem lift_apply' (F : G β* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => algebraMap k A b * F a :=
rfl
theorem lift_apply (F : G β* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => b β’ F a := by simp only [lift_apply', Algebra.smul_def]
theorem lift_def (F : G β* A) : β(lift k G A F) = liftNC ((algebraMap k A : k β+* A) : k β+ A) F :=
rfl
@[simp]
theorem lift_symm_apply (F : MonoidAlgebra k G ββ[k] A) (x : G) :
(lift k G A).symm F x = F (single x 1) :=
rfl
@[simp]
theorem lift_single (F : G β* A) (a b) : lift k G A F (single a b) = b β’ F a := by
rw [lift_def, liftNC_single, Algebra.smul_def, AddMonoidHom.coe_coe]
theorem lift_of (F : G β* A) (x) : lift k G A F (of k G x) = F x := by simp
theorem lift_unique' (F : MonoidAlgebra k G ββ[k] A) :
F = lift k G A ((F : MonoidAlgebra k G β* A).comp (of k G)) :=
((lift k G A).apply_symm_apply F).symm
/-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by
its values on `F (single a 1)`. -/
theorem lift_unique (F : MonoidAlgebra k G ββ[k] A) (f : MonoidAlgebra k G) :
F f = f.sum fun a b => b β’ F (single a 1) := by
conv_lhs =>
rw [lift_unique' F]
simp [lift_apply]
/-- If `f : G β H` is a homomorphism between two magmas, then
`Finsupp.mapDomain f` is a non-unital algebra homomorphism between their magma algebras. -/
@[simps apply]
def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A]
{G H F : Type*} [Mul G] [Mul H] [FunLike F G H] [MulHomClass F G H] (f : F) :
MonoidAlgebra A G βββ[k] MonoidAlgebra A H :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G β+ MonoidAlgebra A H) with
map_mul' := fun x y => mapDomain_mul f x y
map_smul' := fun r x => mapDomain_smul r x }
variable (A) in
theorem mapDomain_algebraMap {F : Type*} [FunLike F G H] [MonoidHomClass F G H] (f : F) (r : k) :
mapDomain f (algebraMap k (MonoidAlgebra A G) r) = algebraMap k (MonoidAlgebra A H) r := by
simp only [coe_algebraMap, mapDomain_single, map_one, (Β· β Β·)]
/-- If `f : G β H` is a multiplicative homomorphism between two monoids, then
`Finsupp.mapDomain f` is an algebra homomorphism between their monoid algebras. -/
@[simps!]
def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {H F : Type*}
[Monoid H] [FunLike F G H] [MonoidHomClass F G H] (f : F) :
MonoidAlgebra A G ββ[k] MonoidAlgebra A H :=
{ mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f }
@[simp]
lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] :
mapDomainAlgHom k A (MonoidHom.id G) = AlgHom.id k (MonoidAlgebra A G) := by
ext; simp [MonoidHom.id, β Function.id_def]
@[simp]
lemma mapDomainAlgHom_comp (k A) {Gβ Gβ Gβ} [CommSemiring k] [Semiring A] [Algebra k A]
[Monoid Gβ] [Monoid Gβ] [Monoid Gβ] (f : Gβ β* Gβ) (g : Gβ β* Gβ) :
mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by
ext; simp [mapDomain_comp]
variable (k A)
/-- If `e : G β* H` is a multiplicative equivalence between two monoids, then
`MonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/
def domCongr (e : G β* H) : MonoidAlgebra A G ββ[k] MonoidAlgebra A H :=
AlgEquiv.ofLinearEquiv
(Finsupp.domLCongr e : (G ββ A) ββ[k] (H ββ A))
((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e)
(fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <|
congr_argβ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm)
theorem domCongr_toAlgHom (e : G β* H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e :=
AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _
@[simp] theorem domCongr_apply (e : G β* H) (f : MonoidAlgebra A G) (h : H) :
domCongr k A e f h = f (e.symm h) :=
rfl
@[simp] theorem domCongr_support (e : G β* H) (f : MonoidAlgebra A G) :
(domCongr k A e f).support = f.support.map e :=
rfl
@[simp] theorem domCongr_single (e : G β* H) (g : G) (a : A) :
domCongr k A e (single g a) = single (e g) a :=
Finsupp.equivMapDomain_single _ _ _
@[simp] theorem domCongr_refl : domCongr k A (MulEquiv.refl G) = AlgEquiv.refl :=
AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl
@[simp] theorem domCongr_symm (e : G β* H) : (domCongr k A e).symm = domCongr k A e.symm := rfl
end lift
section
variable (k)
/-- When `V` is a `k[G]`-module, multiplication by a group element `g` is a `k`-linear map. -/
def GroupSMul.linearMap [Monoid G] [CommSemiring k] (V : Type uβ) [AddCommMonoid V] [Module k V]
[Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G) : V ββ[k] V where
toFun v := single g (1 : k) β’ v
map_add' x y := smul_add (single g (1 : k)) x y
map_smul' _c _x := smul_algebra_smul_comm _ _ _
@[simp]
theorem GroupSMul.linearMap_apply [Monoid G] [CommSemiring k] (V : Type uβ) [AddCommMonoid V]
[Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G)
(v : V) : (GroupSMul.linearMap k V g) v = single g (1 : k) β’ v :=
rfl
section
variable {k}
variable [Monoid G] [CommSemiring k] {V : Type uβ} {W : Type uβ} [AddCommMonoid V] [Module k V]
[Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] [AddCommMonoid W]
[Module k W] [Module (MonoidAlgebra k G) W] [IsScalarTower k (MonoidAlgebra k G) W]
(f : V ββ[k] W)
/-- Build a `k[G]`-linear map from a `k`-linear map and evidence that it is `G`-equivariant. -/
def equivariantOfLinearOfComm
(h : β (g : G) (v : V), f (single g (1 : k) β’ v) = single g (1 : k) β’ f v) :
V ββ[MonoidAlgebra k G] W where
toFun := f
map_add' v v' := by simp
map_smul' c v := by
refine Finsupp.induction c ?_ ?_
Β· simp
Β· intro g r c' _nm _nz w
dsimp at *
simp only [add_smul, f.map_add, w, add_left_inj, single_eq_algebraMap_mul_of, β smul_smul]
rw [algebraMap_smul (MonoidAlgebra k G) r, algebraMap_smul (MonoidAlgebra k G) r, f.map_smul,
of_apply, h g v]
variable (h : β (g : G) (v : V), f (single g (1 : k) β’ v) = single g (1 : k) β’ f v)
@[simp]
theorem equivariantOfLinearOfComm_apply (v : V) : (equivariantOfLinearOfComm f h) v = f v :=
rfl
end
end
end MonoidAlgebra
namespace AddMonoidAlgebra
variable {k G H}
/-! #### Non-unital, non-associative algebra structure -/
section NonUnitalNonAssocAlgebra
variable (k) [Semiring k] [DistribSMul R k] [Add G]
variable {A : Type uβ} [NonUnitalNonAssocSemiring A]
/-- A non_unital `k`-algebra homomorphism from `k[G]` is uniquely defined by its
values on the functions `single a 1`. -/
theorem nonUnitalAlgHom_ext [DistribMulAction k A] {Οβ Οβ : k[G] βββ[k] A}
(h : β x, Οβ (single x 1) = Οβ (single x 1)) : Οβ = Οβ :=
@MonoidAlgebra.nonUnitalAlgHom_ext k (Multiplicative G) _ _ _ _ _ Οβ Οβ h
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {Οβ Οβ : k[G] βββ[k] A}
(h : Οβ.toMulHom.comp (ofMagma k G) = Οβ.toMulHom.comp (ofMagma k G)) : Οβ = Οβ :=
@MonoidAlgebra.nonUnitalAlgHom_ext' k (Multiplicative G) _ _ _ _ _ Οβ Οβ h
/-- The functor `G β¦ k[G]`, from the category of magmas to the category of
non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other
direction. -/
@[simps apply_apply symm_apply]
def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] :
(Multiplicative G ββ* A) β (k[G] βββ[k] A) :=
{ (MonoidAlgebra.liftMagma k : (Multiplicative G ββ* A) β (_ βββ[k] A)) with
toFun := fun f =>
{ (MonoidAlgebra.liftMagma k f :) with
toFun := fun a => sum a fun m t => t β’ f (Multiplicative.ofAdd m) }
invFun := fun F => F.toMulHom.comp (ofMagma k G) }
end NonUnitalNonAssocAlgebra
/-! #### Algebra structure -/
section Algebra
/-- The instance `Algebra R k[G]` whenever we have `Algebra R k`.
In particular this provides the instance `Algebra k k[G]`.
-/
instance algebra [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
Algebra R k[G] where
algebraMap := singleZeroRingHom.comp (algebraMap R k)
smul_def' := fun r a => by
ext
rw [Finsupp.coe_smul]
simp [single_zero_mul_apply, Algebra.smul_def, Pi.smul_apply]
commutes' := fun r f => by
refine Finsupp.ext fun _ => ?_
simp [single_zero_mul_apply, mul_single_zero_apply, Algebra.commutes]
/-- `Finsupp.single 0` as an `AlgHom` -/
@[simps! apply]
def singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : k ββ[R] k[G] :=
{ singleZeroRingHom with
commutes' := fun r => by
ext
simp
rfl }
@[simp]
theorem coe_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
(algebraMap R k[G] : R β k[G]) = single 0 β algebraMap R k :=
rfl
instance isLocalHom_singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] :
IsLocalHom (singleZeroAlgHom : k ββ[R] k[G]) where
map_nonunit := isLocalHom_singleZeroRingHom.map_nonunit
instance isLocalHom_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G]
[IsLocalHom (algebraMap R k)] :
IsLocalHom (algebraMap R k[G]) where
map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleZeroAlgHom (R := R).map_nonunit _ hx
end Algebra
section lift
variable [CommSemiring k] [AddMonoid G]
variable {A : Type uβ} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B]
/-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/
def liftNCAlgHom (f : A ββ[k] B) (g : Multiplicative G β* B) (h_comm : β x y, Commute (f x) (g y)) :
A[G] ββ[k] B :=
{ liftNCRingHom (f : A β+* B) g h_comm with
commutes' := by simp [liftNCRingHom] }
/-- A `k`-algebra homomorphism from `k[G]` is uniquely defined by its
values on the functions `single a 1`. -/
theorem algHom_ext β¦Οβ Οβ : k[G] ββ[k] Aβ¦
(h : β x, Οβ (single x 1) = Οβ (single x 1)) : Οβ = Οβ :=
@MonoidAlgebra.algHom_ext k (Multiplicative G) _ _ _ _ _ _ _ h
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem algHom_ext' β¦Οβ Οβ : k[G] ββ[k] Aβ¦
(h : (Οβ : k[G] β* A).comp (of k G) = (Οβ : k[G] β* A).comp (of k G)) :
Οβ = Οβ :=
algHom_ext <| DFunLike.congr_fun h
variable (k G A)
/-- Any monoid homomorphism `G β* A` can be lifted to an algebra homomorphism
`k[G] ββ[k] A`. -/
def lift : (Multiplicative G β* A) β (k[G] ββ[k] A) :=
{ @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ with
invFun := fun f => (f : k[G] β* A).comp (of k G)
toFun := fun F =>
{ @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ F with
toFun := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _ } }
variable {k G A}
theorem lift_apply' (F : Multiplicative G β* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => algebraMap k A b * F (Multiplicative.ofAdd a) :=
rfl
theorem lift_apply (F : Multiplicative G β* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => b β’ F (Multiplicative.ofAdd a) := by
simp only [lift_apply', Algebra.smul_def]
theorem lift_def (F : Multiplicative G β* A) :
β(lift k G A F) = liftNC ((algebraMap k A : k β+* A) : k β+ A) F :=
rfl
@[simp]
theorem lift_symm_apply (F : k[G] ββ[k] A) (x : Multiplicative G) :
(lift k G A).symm F x = F (single x.toAdd 1) :=
rfl
theorem lift_of (F : Multiplicative G β* A) (x : Multiplicative G) :
lift k G A F (of k G x) = F x := MonoidAlgebra.lift_of F x
@[simp]
theorem lift_single (F : Multiplicative G β* A) (a b) :
lift k G A F (single a b) = b β’ F (Multiplicative.ofAdd a) :=
MonoidAlgebra.lift_single F (.ofAdd a) b
lemma lift_of' (F : Multiplicative G β* A) (x : G) :
lift k G A F (of' k G x) = F (Multiplicative.ofAdd x) :=
lift_of F x
theorem lift_unique' (F : k[G] ββ[k] A) :
F = lift k G A ((F : k[G] β* A).comp (of k G)) :=
((lift k G A).apply_symm_apply F).symm
/-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by
its values on `F (single a 1)`. -/
theorem lift_unique (F : k[G] ββ[k] A) (f : MonoidAlgebra k G) :
F f = f.sum fun a b => b β’ F (single a 1) := by
conv_lhs =>
rw [lift_unique' F]
simp [lift_apply]
theorem algHom_ext_iff {Οβ Οβ : k[G] ββ[k] A} :
(β x, Οβ (Finsupp.single x 1) = Οβ (Finsupp.single x 1)) β Οβ = Οβ :=
β¨fun h => algHom_ext h, by rintro rfl _; rflβ©
end lift
theorem mapDomain_algebraMap (A : Type*) {H F : Type*} [CommSemiring k] [Semiring A] [Algebra k A]
[AddMonoid G] [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H]
(f : F) (r : k) :
mapDomain f (algebraMap k A[G] r) = algebraMap k A[H] r := by
simp only [Function.comp_apply, mapDomain_single, AddMonoidAlgebra.coe_algebraMap, map_zero]
/-- If `f : G β H` is a homomorphism between two additive magmas, then `Finsupp.mapDomain f` is a
non-unital algebra homomorphism between their additive magma algebras. -/
@[simps apply]
def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A]
{G H F : Type*} [Add G] [Add H] [FunLike F G H] [AddHomClass F G H] (f : F) :
A[G] βββ[k] A[H] :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G β+ MonoidAlgebra A H) with
map_mul' := fun x y => mapDomain_mul f x y
map_smul' := fun r x => mapDomain_smul r x }
/-- If `f : G β H` is an additive homomorphism between two additive monoids, then
`Finsupp.mapDomain f` is an algebra homomorphism between their add monoid algebras. -/
@[simps!]
def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G]
{H F : Type*} [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) :
A[G] ββ[k] A[H] :=
{ mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f }
@[simp]
lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] :
mapDomainAlgHom k A (AddMonoidHom.id G) = AlgHom.id k (AddMonoidAlgebra A G) := by
ext; simp [AddMonoidHom.id, β Function.id_def]
@[simp]
lemma mapDomainAlgHom_comp (k A) {Gβ Gβ Gβ} [CommSemiring k] [Semiring A] [Algebra k A]
[AddMonoid Gβ] [AddMonoid Gβ] [AddMonoid Gβ] (f : Gβ β+ Gβ) (g : Gβ β+ Gβ) :
mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by
ext; simp [mapDomain_comp]
variable (k A)
variable [CommSemiring k] [AddMonoid G] [AddMonoid H] [Semiring A] [Algebra k A]
/-- If `e : G β* H` is a multiplicative equivalence between two monoids, then
`AddMonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/
def domCongr (e : G β+ H) : A[G] ββ[k] A[H] :=
AlgEquiv.ofLinearEquiv
(Finsupp.domLCongr e : (G ββ A) ββ[k] (H ββ A))
((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e)
(fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <|
congr_argβ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm)
theorem domCongr_toAlgHom (e : G β+ H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e :=
AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _
@[simp] theorem domCongr_apply (e : G β+ H) (f : MonoidAlgebra A G) (h : H) :
domCongr k A e f h = f (e.symm h) :=
rfl
@[simp] theorem domCongr_support (e : G β+ H) (f : MonoidAlgebra A G) :
(domCongr k A e f).support = f.support.map e :=
rfl
@[simp] theorem domCongr_single (e : G β+ H) (g : G) (a : A) :
domCongr k A e (single g a) = single (e g) a :=
Finsupp.equivMapDomain_single _ _ _
@[simp] theorem domCongr_refl : domCongr k A (AddEquiv.refl G) = AlgEquiv.refl :=
AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl
@[simp] theorem domCongr_symm (e : G β+ H) : (domCongr k A e).symm = domCongr k A e.symm := rfl
end AddMonoidAlgebra
variable [CommSemiring R]
/-- The algebra equivalence between `AddMonoidAlgebra` and `MonoidAlgebra` in terms of
`Multiplicative`. -/
def AddMonoidAlgebra.toMultiplicativeAlgEquiv [Semiring k] [Algebra R k] [AddMonoid G] :
AddMonoidAlgebra k G ββ[R] MonoidAlgebra k (Multiplicative G) :=
{ AddMonoidAlgebra.toMultiplicative k G with
commutes' := fun r => by simp [AddMonoidAlgebra.toMultiplicative] }
/-- The algebra equivalence between `MonoidAlgebra` and `AddMonoidAlgebra` in terms of
`Additive`. -/
def MonoidAlgebra.toAdditiveAlgEquiv [Semiring k] [Algebra R k] [Monoid G] :
MonoidAlgebra k G ββ[R] AddMonoidAlgebra k (Additive G) :=
{ MonoidAlgebra.toAdditive k G with commutes' := fun r => by simp [MonoidAlgebra.toAdditive] }
| Mathlib/Algebra/MonoidAlgebra/Basic.lean | 986 | 990 | |
/-
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.Unbundled.Basic
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Util.AssertExists
/-!
# Ordered groups
This file defines bundled ordered groups and develops a few basic results.
## Implementation details
Unfortunately, the number of `'` appended to lemmas in this file
may differ between the multiplicative and the additive version of a lemma.
The reason is that we did not want to change existing names in the library.
-/
/-
`NeZero` theory should not be needed at this point in the ordered algebraic hierarchy.
-/
assert_not_imported Mathlib.Algebra.NeZero
open Function
universe u
variable {Ξ± : Type u}
/-- An ordered additive commutative group is an additive commutative group
with a partial order in which addition is strictly monotone. -/
@[deprecated "Use `[AddCommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedAddMonoid Ξ±]` instead."
(since := "2025-04-10")]
structure OrderedAddCommGroup (Ξ± : Type u) extends AddCommGroup Ξ±, PartialOrder Ξ± where
/-- Addition is monotone in an ordered additive commutative group. -/
protected add_le_add_left : β a b : Ξ±, a β€ b β β c : Ξ±, c + a β€ c + b
set_option linter.existingAttributeWarning false in
/-- An ordered commutative group is a commutative group
with a partial order in which multiplication is strictly monotone. -/
@[to_additive,
deprecated "Use `[CommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedMonoid Ξ±]` instead."
(since := "2025-04-10")]
structure OrderedCommGroup (Ξ± : Type u) extends CommGroup Ξ±, PartialOrder Ξ± where
/-- Multiplication is monotone in an ordered commutative group. -/
protected mul_le_mul_left : β a b : Ξ±, a β€ b β β c : Ξ±, c * a β€ c * b
alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left'
attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left'
alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left'
attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left
alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left'
attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left
-- See note [lower instance priority]
@[to_additive IsOrderedAddMonoid.toIsOrderedCancelAddMonoid]
instance (priority := 100) IsOrderedMonoid.toIsOrderedCancelMonoid
[CommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedMonoid Ξ±] : IsOrderedCancelMonoid Ξ± where
le_of_mul_le_mul_left a b c bc := by simpa using mul_le_mul_left' bc aβ»ΒΉ
le_of_mul_le_mul_right a b c bc := by simpa using mul_le_mul_left' bc aβ»ΒΉ
/-!
### Linearly ordered commutative groups
-/
set_option linter.deprecated false in
/-- A linearly ordered additive commutative group is an
additive commutative group with a linear order in which
addition is monotone. -/
@[deprecated "Use `[AddCommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedAddMonoid Ξ±]` instead."
(since := "2025-04-10")]
structure LinearOrderedAddCommGroup (Ξ± : Type u) extends OrderedAddCommGroup Ξ±, LinearOrder Ξ±
set_option linter.existingAttributeWarning false in
set_option linter.deprecated false in
/-- A linearly ordered commutative group is a
commutative group with a linear order in which
multiplication is monotone. -/
@[to_additive,
deprecated "Use `[CommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedMonoid Ξ±]` instead."
(since := "2025-04-10")]
structure LinearOrderedCommGroup (Ξ± : Type u) extends OrderedCommGroup Ξ±, LinearOrder Ξ±
attribute [nolint docBlame]
LinearOrderedCommGroup.toLinearOrder LinearOrderedAddCommGroup.toLinearOrder
section LinearOrderedCommGroup
variable [CommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedMonoid Ξ±] {a : Ξ±}
@[to_additive LinearOrderedAddCommGroup.add_lt_add_left]
theorem LinearOrderedCommGroup.mul_lt_mul_left' (a b : Ξ±) (h : a < b) (c : Ξ±) : c * a < c * b :=
_root_.mul_lt_mul_left' h c
@[to_additive eq_zero_of_neg_eq]
theorem eq_one_of_inv_eq' (h : aβ»ΒΉ = a) : a = 1 :=
match lt_trichotomy a 1 with
| Or.inl hβ =>
have : 1 < a := h βΈ one_lt_inv_of_inv hβ
absurd hβ this.asymm
| Or.inr (Or.inl hβ) => hβ
| Or.inr (Or.inr hβ) =>
have : a < 1 := h βΈ inv_lt_one'.mpr hβ
absurd hβ this.asymm
@[to_additive exists_zero_lt]
theorem exists_one_lt' [Nontrivial Ξ±] : β a : Ξ±, 1 < a := by
obtain β¨y, hyβ© := Decidable.exists_ne (1 : Ξ±)
obtain h|h := hy.lt_or_lt
Β· exact β¨yβ»ΒΉ, one_lt_inv'.mpr hβ©
Β· exact β¨y, hβ©
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMaxOrder [Nontrivial Ξ±] : NoMaxOrder Ξ± :=
β¨by
obtain β¨y, hyβ© : β a : Ξ±, 1 < a := exists_one_lt'
exact fun a => β¨a * y, lt_mul_of_one_lt_right' a hyβ©β©
-- see Note [lower instance priority]
@[to_additive]
instance (priority := 100) LinearOrderedCommGroup.to_noMinOrder [Nontrivial Ξ±] : NoMinOrder Ξ± :=
β¨by
obtain β¨y, hyβ© : β a : Ξ±, 1 < a := exists_one_lt'
exact fun a => β¨a / y, (div_lt_self_iff a).mpr hyβ©β©
@[to_additive (attr := simp)]
theorem inv_le_self_iff : aβ»ΒΉ β€ a β 1 β€ a := by simp [inv_le_iff_one_le_mul']
@[to_additive (attr := simp)]
theorem inv_lt_self_iff : aβ»ΒΉ < a β 1 < a := by simp [inv_lt_iff_one_lt_mul]
@[to_additive (attr := simp)]
theorem le_inv_self_iff : a β€ aβ»ΒΉ β a β€ 1 := by simp [β not_iff_not]
@[to_additive (attr := simp)]
theorem lt_inv_self_iff : a < aβ»ΒΉ β a < 1 := by simp [β not_iff_not]
end LinearOrderedCommGroup
section NormNumLemmas
/- The following lemmas are stated so that the `norm_num` tactic can use them with the
expected signatures. -/
variable [CommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedMonoid Ξ±] {a b : Ξ±}
@[to_additive (attr := gcongr) neg_le_neg]
theorem inv_le_inv' : a β€ b β bβ»ΒΉ β€ aβ»ΒΉ :=
inv_le_inv_iff.mpr
@[to_additive (attr := gcongr) neg_lt_neg]
theorem inv_lt_inv' : a < b β bβ»ΒΉ < aβ»ΒΉ :=
inv_lt_inv_iff.mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_lt_one_of_one_lt : 1 < a β aβ»ΒΉ < 1 :=
inv_lt_one_iff_one_lt.mpr
-- The additive version is also a `linarith` lemma.
@[to_additive]
theorem inv_le_one_of_one_le : 1 β€ a β aβ»ΒΉ β€ 1 :=
inv_le_one'.mpr
@[to_additive neg_nonneg_of_nonpos]
theorem one_le_inv_of_le_one : a β€ 1 β 1 β€ aβ»ΒΉ :=
one_le_inv'.mpr
end NormNumLemmas
| Mathlib/Algebra/Order/Group/Defs.lean | 215 | 217 | |
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes HΓΆlzl, Mario Carneiro, SΓ©bastien GouΓ«zel
-/
import Mathlib.Topology.Bornology.Constructions
import Mathlib.Topology.MetricSpace.Pseudo.Defs
import Mathlib.Topology.UniformSpace.UniformEmbedding
/-!
# Products of pseudometric spaces and other constructions
This file constructs the supremum distance on binary products of pseudometric spaces and provides
instances for type synonyms.
-/
open Bornology Filter Metric Set Topology
open scoped NNReal
variable {Ξ± Ξ² : Type*} [PseudoMetricSpace Ξ±]
/-- Pseudometric space structure pulled back by a function. -/
abbrev PseudoMetricSpace.induced {Ξ± Ξ²} (f : Ξ± β Ξ²) (m : PseudoMetricSpace Ξ²) :
PseudoMetricSpace Ξ± where
dist x y := dist (f x) (f y)
dist_self _ := dist_self _
dist_comm _ _ := dist_comm _ _
dist_triangle _ _ _ := dist_triangle _ _ _
edist x y := edist (f x) (f y)
edist_dist _ _ := edist_dist _ _
toUniformSpace := UniformSpace.comap f m.toUniformSpace
uniformity_dist := (uniformity_basis_dist.comap _).eq_biInf
toBornology := Bornology.induced f
cobounded_sets := Set.ext fun s => mem_comap_iff_compl.trans <| by
simp only [β isBounded_def, isBounded_iff, forall_mem_image, mem_setOf]
/-- Pull back a pseudometric space structure by an inducing map. This is a version of
`PseudoMetricSpace.induced` useful in case if the domain already has a `TopologicalSpace`
structure. -/
def Topology.IsInducing.comapPseudoMetricSpace {Ξ± Ξ² : Type*} [TopologicalSpace Ξ±]
[m : PseudoMetricSpace Ξ²] {f : Ξ± β Ξ²} (hf : IsInducing f) : PseudoMetricSpace Ξ± :=
.replaceTopology (.induced f m) hf.eq_induced
@[deprecated (since := "2024-10-28")]
alias Inducing.comapPseudoMetricSpace := IsInducing.comapPseudoMetricSpace
/-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of
`PseudoMetricSpace.induced` useful in case if the domain already has a `UniformSpace`
structure. -/
def IsUniformInducing.comapPseudoMetricSpace {Ξ± Ξ²} [UniformSpace Ξ±] [m : PseudoMetricSpace Ξ²]
(f : Ξ± β Ξ²) (h : IsUniformInducing f) : PseudoMetricSpace Ξ± :=
.replaceUniformity (.induced f m) h.comap_uniformity.symm
instance Subtype.pseudoMetricSpace {p : Ξ± β Prop} : PseudoMetricSpace (Subtype p) :=
PseudoMetricSpace.induced Subtype.val βΉ_βΊ
lemma Subtype.dist_eq {p : Ξ± β Prop} (x y : Subtype p) : dist x y = dist (x : Ξ±) y := rfl
lemma Subtype.nndist_eq {p : Ξ± β Prop} (x y : Subtype p) : nndist x y = nndist (x : Ξ±) y := rfl
namespace MulOpposite
@[to_additive]
instance instPseudoMetricSpace : PseudoMetricSpace Ξ±α΅α΅α΅ :=
PseudoMetricSpace.induced MulOpposite.unop βΉ_βΊ
@[to_additive (attr := simp)]
lemma dist_unop (x y : Ξ±α΅α΅α΅) : dist (unop x) (unop y) = dist x y := rfl
@[to_additive (attr := simp)]
lemma dist_op (x y : Ξ±) : dist (op x) (op y) = dist x y := rfl
@[to_additive (attr := simp)]
lemma nndist_unop (x y : Ξ±α΅α΅α΅) : nndist (unop x) (unop y) = nndist x y := rfl
@[to_additive (attr := simp)]
lemma nndist_op (x y : Ξ±) : nndist (op x) (op y) = nndist x y := rfl
end MulOpposite
section NNReal
instance : PseudoMetricSpace ββ₯0 := Subtype.pseudoMetricSpace
lemma NNReal.dist_eq (a b : ββ₯0) : dist a b = |(a : β) - b| := rfl
lemma NNReal.nndist_eq (a b : ββ₯0) : nndist a b = max (a - b) (b - a) :=
eq_of_forall_ge_iff fun _ => by
simp only [max_le_iff, tsub_le_iff_right (Ξ± := ββ₯0)]
simp only [β NNReal.coe_le_coe, coe_nndist, dist_eq, abs_sub_le_iff,
tsub_le_iff_right, NNReal.coe_add]
@[simp]
lemma NNReal.nndist_zero_eq_val (z : ββ₯0) : nndist 0 z = z := by
simp only [NNReal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le']
@[simp]
| lemma NNReal.nndist_zero_eq_val' (z : ββ₯0) : nndist z 0 = z := by
rw [nndist_comm]
exact NNReal.nndist_zero_eq_val z
lemma NNReal.le_add_nndist (a b : ββ₯0) : a β€ b + nndist a b := by
| Mathlib/Topology/MetricSpace/Pseudo/Constructions.lean | 98 | 102 |
/-
Copyright (c) 2023 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import Mathlib.Data.Finset.Lattice.Fold
/-!
# Irreducible and prime elements in an order
This file defines irreducible and prime elements in an order and shows that in a well-founded
lattice every element decomposes as a supremum of irreducible elements.
An element is sup-irreducible (resp. inf-irreducible) if it isn't `β₯` and can't be written as the
supremum of any strictly smaller elements. An element is sup-prime (resp. inf-prime) if it isn't `β₯`
and is greater than the supremum of any two elements less than it.
Primality implies irreducibility in general. The converse only holds in distributive lattices.
Both hold for all (non-minimal) elements in a linear order.
## Main declarations
* `SupIrred a`: Sup-irreducibility, `a` isn't minimal and `a = b β c β a = b β¨ a = c`
* `InfIrred a`: Inf-irreducibility, `a` isn't maximal and `a = b β c β a = b β¨ a = c`
* `SupPrime a`: Sup-primality, `a` isn't minimal and `a β€ b β c β a β€ b β¨ a β€ c`
* `InfIrred a`: Inf-primality, `a` isn't maximal and `a β₯ b β c β a β₯ b β¨ a β₯ c`
* `exists_supIrred_decomposition`/`exists_infIrred_decomposition`: Decomposition into irreducibles
in a well-founded semilattice.
-/
open Finset OrderDual
variable {ΞΉ Ξ± : Type*}
/-! ### Irreducible and prime elements -/
section SemilatticeSup
variable [SemilatticeSup Ξ±] {a b c : Ξ±}
/-- A sup-irreducible element is a non-bottom element which isn't the supremum of anything smaller.
-/
def SupIrred (a : Ξ±) : Prop :=
Β¬IsMin a β§ β β¦b cβ¦, b β c = a β b = a β¨ c = a
/-- A sup-prime element is a non-bottom element which isn't less than the supremum of anything
smaller. -/
def SupPrime (a : Ξ±) : Prop :=
Β¬IsMin a β§ β β¦b cβ¦, a β€ b β c β a β€ b β¨ a β€ c
theorem SupIrred.not_isMin (ha : SupIrred a) : Β¬IsMin a :=
ha.1
theorem SupPrime.not_isMin (ha : SupPrime a) : Β¬IsMin a :=
ha.1
theorem IsMin.not_supIrred (ha : IsMin a) : Β¬SupIrred a := fun h => h.1 ha
theorem IsMin.not_supPrime (ha : IsMin a) : Β¬SupPrime a := fun h => h.1 ha
@[simp]
theorem not_supIrred : Β¬SupIrred a β IsMin a β¨ β b c, b β c = a β§ b < a β§ c < a := by
rw [SupIrred, not_and_or]
push_neg
rw [existsβ_congr]
simp +contextual [@eq_comm _ _ a]
@[simp]
theorem not_supPrime : Β¬SupPrime a β IsMin a β¨ β b c, a β€ b β c β§ Β¬a β€ b β§ Β¬a β€ c := by
rw [SupPrime, not_and_or]; push_neg; rfl
protected theorem SupPrime.supIrred : SupPrime a β SupIrred a :=
And.imp_right fun h b c ha => by simpa [β ha] using h ha.ge
theorem SupPrime.le_sup (ha : SupPrime a) : a β€ b β c β a β€ b β¨ a β€ c :=
β¨fun h => ha.2 h, fun h => h.elim le_sup_of_le_left le_sup_of_le_rightβ©
variable [OrderBot Ξ±] {s : Finset ΞΉ} {f : ΞΉ β Ξ±}
@[simp]
theorem not_supIrred_bot : Β¬SupIrred (β₯ : Ξ±) :=
isMin_bot.not_supIrred
@[simp]
theorem not_supPrime_bot : Β¬SupPrime (β₯ : Ξ±) :=
isMin_bot.not_supPrime
theorem SupIrred.ne_bot (ha : SupIrred a) : a β β₯ := by rintro rfl; exact not_supIrred_bot ha
theorem SupPrime.ne_bot (ha : SupPrime a) : a β β₯ := by rintro rfl; exact not_supPrime_bot ha
theorem SupIrred.finset_sup_eq (ha : SupIrred a) (h : s.sup f = a) : β i β s, f i = a := by
classical
induction' s using Finset.induction with i s _ ih
Β· simpa [ha.ne_bot] using h.symm
simp only [exists_prop, exists_mem_insert] at ih β’
rw [sup_insert] at h
exact (ha.2 h).imp_right ih
theorem SupPrime.le_finset_sup (ha : SupPrime a) : a β€ s.sup f β β i β s, a β€ f i := by
classical
induction' s using Finset.induction with i s _ ih
Β· simp [ha.ne_bot]
Β· simp only [exists_prop, exists_mem_insert, sup_insert, ha.le_sup, ih]
variable [WellFoundedLT Ξ±]
/-- In a well-founded lattice, any element is the supremum of finitely many sup-irreducible
elements. This is the order-theoretic analogue of prime factorisation. -/
theorem exists_supIrred_decomposition (a : Ξ±) :
β s : Finset Ξ±, s.sup id = a β§ β β¦bβ¦, b β s β SupIrred b := by
classical
apply WellFoundedLT.induction a _
clear a
rintro a ih
by_cases ha : SupIrred a
Β· exact β¨{a}, by simp [ha]β©
rw [not_supIrred] at ha
obtain ha | β¨b, c, rfl, hb, hcβ© := ha
Β· exact β¨β
, by simp [ha.eq_bot]β©
obtain β¨s, rfl, hsβ© := ih _ hb
obtain β¨t, rfl, htβ© := ih _ hc
exact β¨s βͺ t, sup_union, forall_mem_union.2 β¨hs, htβ©β©
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf Ξ±] {a b c : Ξ±}
/-- An inf-irreducible element is a non-top element which isn't the infimum of anything bigger. -/
def InfIrred (a : Ξ±) : Prop :=
Β¬IsMax a β§ β β¦b cβ¦, b β c = a β b = a β¨ c = a
/-- An inf-prime element is a non-top element which isn't bigger than the infimum of anything
bigger. -/
def InfPrime (a : Ξ±) : Prop :=
Β¬IsMax a β§ β β¦b cβ¦, b β c β€ a β b β€ a β¨ c β€ a
@[simp]
theorem IsMax.not_infIrred (ha : IsMax a) : Β¬InfIrred a := fun h => h.1 ha
@[simp]
theorem IsMax.not_infPrime (ha : IsMax a) : Β¬InfPrime a := fun h => h.1 ha
@[simp]
theorem not_infIrred : Β¬InfIrred a β IsMax a β¨ β b c, b β c = a β§ a < b β§ a < c :=
@not_supIrred Ξ±α΅α΅ _ _
@[simp]
theorem not_infPrime : Β¬InfPrime a β IsMax a β¨ β b c, b β c β€ a β§ Β¬b β€ a β§ Β¬c β€ a :=
@not_supPrime Ξ±α΅α΅ _ _
protected theorem InfPrime.infIrred : InfPrime a β InfIrred a :=
And.imp_right fun h b c ha => by simpa [β ha] using h ha.le
theorem InfPrime.inf_le (ha : InfPrime a) : b β c β€ a β b β€ a β¨ c β€ a :=
β¨fun h => ha.2 h, fun h => h.elim inf_le_of_left_le inf_le_of_right_leβ©
variable [OrderTop Ξ±] {s : Finset ΞΉ} {f : ΞΉ β Ξ±}
theorem not_infIrred_top : Β¬InfIrred (β€ : Ξ±) :=
isMax_top.not_infIrred
theorem not_infPrime_top : Β¬InfPrime (β€ : Ξ±) :=
isMax_top.not_infPrime
theorem InfIrred.ne_top (ha : InfIrred a) : a β β€ := by rintro rfl; exact not_infIrred_top ha
theorem InfPrime.ne_top (ha : InfPrime a) : a β β€ := by rintro rfl; exact not_infPrime_top ha
theorem InfIrred.finset_inf_eq : InfIrred a β s.inf f = a β β i β s, f i = a :=
@SupIrred.finset_sup_eq _ Ξ±α΅α΅ _ _ _ _ _
theorem InfPrime.finset_inf_le (ha : InfPrime a) : s.inf f β€ a β β i β s, f i β€ a :=
@SupPrime.le_finset_sup _ Ξ±α΅α΅ _ _ _ _ _ ha
variable [WellFoundedGT Ξ±]
|
/-- In a cowell-founded lattice, any element is the infimum of finitely many inf-irreducible
| Mathlib/Order/Irreducible.lean | 181 | 182 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : β) :
IsCauSeq abs fun n => β m β range n, βz ^ m / m.factorialβ :=
let β¨n, hnβ© := exists_nat_gt βzβ
have hn0 : (0 : β) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (βzβ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iffβ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
β div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : β) : IsCauSeq (βΒ·β) fun n => β m β range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : β) : CauSeq β (βΒ·β) :=
β¨fun n => β m β range n, z ^ m / m.factorial, isCauSeq_exp zβ©
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : β) : β :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : β) : β :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : β)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun Ξ΅ Ξ΅0 => β¨1, fun j hj => ?_β©
convert (config := .unfoldSameFun) Ξ΅0 -- Ξ΅0 : Ξ΅ > 0 but goal is _ < Ξ΅
rcases j with - | j
Β· exact absurd hj (not_le_of_gt zero_lt_one)
Β· dsimp [exp']
induction' j with j ih
Β· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
Β· rw [β ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : β j : β, (β m β range j, (x + y) ^ m / m.factorial) =
β i β range j, β k β range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have hβ : (m.choose I : β) β 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have hβ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [β hβ, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : β), mul_assoc, mul_left_comm (m.choose I : β)β»ΒΉ,
mul_comm (m.choose I : β)]
rw [inv_mul_cancelβ hβ]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative β` to `β` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative β) β :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List β) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative β) expMonoidHom l
theorem exp_multiset_sum (s : Multiset β) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative β) β _ _ expMonoidHom s
theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) :
exp (β x β s, f x) = β x β s, exp (f x) :=
map_prod (Ξ² := Multiplicative β) expMonoidHom f s
lemma exp_nsmul (x : β) (n : β) : exp (n β’ x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative β) β _ _ expMonoidHom _ _
theorem exp_nat_mul (x : β) : β n : β, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, β exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x β 0 := fun h =>
zero_ne_one (Ξ± := β) <| by rw [β exp_zero, β add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)β»ΒΉ := by
rw [β mul_right_inj' (exp_ne_zero x), β exp_add]; simp [mul_inv_cancelβ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : β) (n : β€) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
Β· simp [exp_nat_mul]
Β· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [β lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_divβ, map_pow, β ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : β) : ((exp x).re : β) = exp x :=
conj_eq_iff_re.1 <| by rw [β exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : β) : (Real.exp x : β) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : β) : (exp x).im = 0 := by rw [β ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : β) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : β)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative β` to `β` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative β) β :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List β) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative β) expMonoidHom l
theorem exp_multiset_sum (s : Multiset β) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative β) β _ _ expMonoidHom s
theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) :
exp (β x β s, f x) = β x β s, exp (f x) :=
map_prod (Ξ² := Multiplicative β) expMonoidHom f s
lemma exp_nsmul (x : β) (n : β) : exp (n β’ x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative β) β _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : β) (n : β) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x β 0 := fun h =>
exp_ne_zero x <| by rw [exp, β ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)β»ΒΉ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : β} (hx : 0 β€ x) (n : β) : β i β range n, x ^ i / i ! β€ exp x :=
calc
β i β range n, x ^ i / i ! β€ lim (β¨_, isCauSeq_re (exp' x)β© : CauSeq β abs) := by
refine le_lim (CauSeq.le_of_exists β¨n, fun j hj => ?_β©)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ β¦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, β cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 β€ x) (n : β) : x ^ n / n ! β€ exp x :=
calc
x ^ n / n ! β€ β k β range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k β¦ x ^ k / k !) (fun k _ β¦ by positivity) (self_mem_range_succ n)
_ β€ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : β} (hx : 0 β€ x) : 1 + x + x ^ 2 / 2 β€ exp x :=
calc
1 + x + x ^ 2 / 2 = β i β range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ β€ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : β} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : β} (hx : 0 β€ x) : x + 1 β€ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
Β· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : β} (hx : 0 β€ x) : 1 β€ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : β) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one β one_le_exp) fun h => by
rw [β neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : β) : 0 β€ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : β) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : β) : exp |x| β€ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [β sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : β} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : β} (h : x β€ y) : exp x β€ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : β} : exp x < exp y β x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : β} : exp x β€ exp y β x β€ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : β} : exp x = exp y β x = y :=
exp_injective.eq_iff
@[simp]
| theorem exp_eq_one_iff : exp x = 1 β x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : β} : 1 < exp x β 0 < x := by rw [β exp_zero, exp_lt_exp]
| Mathlib/Data/Complex/Exponential.lean | 319 | 323 |
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sort
/-!
# Compositions
A composition of a natural number `n` is a decomposition `n = iβ + ... + i_{k-1}` of `n` into a sum
of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into
non-empty blocks of consecutive integers, where the `iβ±Ό` are the lengths of the blocks.
This notion is closely related to that of a partition of `n`, but in a composition of `n` the
order of the `iβ±Ό`s matters.
We implement two different structures covering these two viewpoints on compositions. The first
one, made of a list of positive integers summing to `n`, is the main one and is called
`Composition n`. The second one is useful for combinatorial arguments (for instance to show that
the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}`
containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost
points of each block. The main API is built on `Composition n`, and we provide an equivalence
between the two types.
## Main functions
* `c : Composition n` is a structure, made of a list of integers which are all positive and
add up to `n`.
* `composition_card` states that the cardinality of `Composition n` is exactly
`2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which
is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is
nat subtraction).
Let `c : Composition n` be a composition of `n`. Then
* `c.blocks` is the list of blocks in `c`.
* `c.length` is the number of blocks in the composition.
* `c.blocksFun : Fin c.length β β` is the realization of `c.blocks` as a function on
`Fin c.length`. This is the main object when using compositions to understand the composition of
analytic functions.
* `c.sizeUpTo : β β β` is the sum of the size of the blocks up to `i`.;
* `c.embedding i : Fin (c.blocksFun i) β Fin n` is the increasing embedding of the `i`-th block in
`Fin n`;
* `c.index j`, for `j : Fin n`, is the index of the block containing `j`.
* `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`.
* `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`.
Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition
of `n`.
* `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the
blocks of `c`.
* `join_splitWrtComposition` states that splitting a list and then joining it gives back the
original list.
* `splitWrtComposition_join` states that joining a list of lists, and then splitting it back
according to the right composition, gives back the original list of lists.
We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`.
`c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries`
and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not
make sense in the edge case `n = 0`, while the previous description works in all cases).
The elements of this set (other than `n`) correspond to leftmost points of blocks.
Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We
only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able
to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv
between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n`
from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that
`CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)`
(see `compositionAsSet_card` and `composition_card`).
## Implementation details
The main motivation for this structure and its API is in the construction of the composition of
formal multilinear series, and the proof that the composition of analytic functions is analytic.
The representation of a composition as a list is very handy as lists are very flexible and already
have a well-developed API.
## Tags
Composition, partition
## References
<https://en.wikipedia.org/wiki/Composition_(combinatorics)>
-/
assert_not_exists Field
open List
variable {n : β}
/-- A composition of `n` is a list of positive integers summing to `n`. -/
@[ext]
structure Composition (n : β) where
/-- List of positive integers summing to `n` -/
blocks : List β
/-- Proof of positivity for `blocks` -/
blocks_pos : β {i}, i β blocks β 0 < i
/-- Proof that `blocks` sums to `n` -/
blocks_sum : blocks.sum = n
deriving DecidableEq
attribute [simp] Composition.blocks_sum
/-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of
consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding
a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and
get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure
`CompositionAsSet n`. -/
@[ext]
structure CompositionAsSet (n : β) where
/-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}` -/
boundaries : Finset (Fin n.succ)
/-- Proof that `0` is a member of `boundaries` -/
zero_mem : (0 : Fin n.succ) β boundaries
/-- Last element of the composition -/
getLast_mem : Fin.last n β boundaries
deriving DecidableEq
instance {n : β} : Inhabited (CompositionAsSet n) :=
β¨β¨Finset.univ, Finset.mem_univ _, Finset.mem_univ _β©β©
attribute [simp] CompositionAsSet.zero_mem CompositionAsSet.getLast_mem
/-!
### Compositions
A composition of an integer `n` is a decomposition `n = iβ + ... + i_{k-1}` of `n` into a sum of
positive integers.
-/
namespace Composition
variable (c : Composition n)
instance (n : β) : ToString (Composition n) :=
β¨fun c => toString c.blocksβ©
/-- The length of a composition, i.e., the number of blocks in the composition. -/
abbrev length : β :=
c.blocks.length
theorem blocks_length : c.blocks.length = c.length :=
rfl
/-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic
functions using compositions, this is the main player. -/
def blocksFun : Fin c.length β β := c.blocks.get
@[simp]
theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks :=
ofFn_get _
@[simp]
theorem sum_blocksFun : β i, c.blocksFun i = n := by
conv_rhs => rw [β c.blocks_sum, β ofFn_blocksFun, sum_ofFn]
@[simp]
theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i β c.blocks :=
get_mem _ _
theorem one_le_blocks {i : β} (h : i β c.blocks) : 1 β€ i :=
c.blocks_pos h
theorem blocks_le {i : β} (h : i β c.blocks) : i β€ n := by
rw [β c.blocks_sum]
exact List.le_sum_of_mem h
@[simp]
theorem one_le_blocks' {i : β} (h : i < c.length) : 1 β€ c.blocks[i] :=
c.one_le_blocks (get_mem (blocks c) _)
@[simp]
theorem blocks_pos' (i : β) (h : i < c.length) : 0 < c.blocks[i] :=
c.one_le_blocks' h
@[simp]
theorem one_le_blocksFun (i : Fin c.length) : 1 β€ c.blocksFun i :=
c.one_le_blocks (c.blocksFun_mem_blocks i)
@[simp]
theorem blocksFun_le {n} (c : Composition n) (i : Fin c.length) :
c.blocksFun i β€ n :=
c.blocks_le <| getElem_mem _
@[simp]
theorem length_le : c.length β€ n := by
conv_rhs => rw [β c.blocks_sum]
exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi
@[simp]
theorem blocks_eq_nil : c.blocks = [] β n = 0 := by
constructor
Β· intro h
simpa using congr(List.sum $h)
Β· rintro rfl
rw [β length_eq_zero_iff, β nonpos_iff_eq_zero]
exact c.length_le
protected theorem length_eq_zero : c.length = 0 β n = 0 := by
simp
@[simp]
theorem length_pos_iff : 0 < c.length β 0 < n := by
simp [pos_iff_ne_zero]
alias β¨_, length_pos_of_posβ© := length_pos_iff
/-- The sum of the sizes of the blocks in a composition up to `i`. -/
def sizeUpTo (i : β) : β :=
(c.blocks.take i).sum
@[simp]
theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo]
theorem sizeUpTo_ofLength_le (i : β) (h : c.length β€ i) : c.sizeUpTo i = n := by
dsimp [sizeUpTo]
convert c.blocks_sum
exact take_of_length_le h
@[simp]
theorem sizeUpTo_length : c.sizeUpTo c.length = n :=
c.sizeUpTo_ofLength_le c.length le_rfl
theorem sizeUpTo_le (i : β) : c.sizeUpTo i β€ n := by
conv_rhs => rw [β c.blocks_sum, β sum_take_add_sum_drop _ i]
exact Nat.le_add_right _ _
theorem sizeUpTo_succ {i : β} (h : i < c.length) :
c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i] := by
simp only [sizeUpTo]
rw [sum_take_succ _ _ h]
theorem sizeUpTo_succ' (i : Fin c.length) :
c.sizeUpTo ((i : β) + 1) = c.sizeUpTo i + c.blocksFun i :=
c.sizeUpTo_succ i.2
theorem sizeUpTo_strict_mono {i : β} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by
rw [c.sizeUpTo_succ h]
simp
theorem monotone_sizeUpTo : Monotone c.sizeUpTo :=
monotone_sum_take _
/-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundary : Fin (c.length + 1) βͺo Fin (n + 1) :=
(OrderEmbedding.ofStrictMono fun i => β¨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)β©) <|
Fin.strictMono_iff_lt_succ.2 fun β¨_, hiβ© => c.sizeUpTo_strict_mono hi
@[simp]
theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff]
@[simp]
theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by
simp [boundary, Fin.ext_iff]
/-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include
a virtual point at the right of the last block, to make for a nice equiv with
`CompositionAsSet n`. -/
def boundaries : Finset (Fin (n + 1)) :=
Finset.univ.map c.boundary.toEmbedding
theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries]
/-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost
point of each block, and adding a virtual point at the right of the last block. -/
def toCompositionAsSet : CompositionAsSet n where
boundaries := c.boundaries
zero_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact β¨0, And.intro True.intro rflβ©
getLast_mem := by
simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map]
exact β¨Fin.last c.length, And.intro True.intro c.boundary_lastβ©
/-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is
exactly `c.boundary`. -/
theorem orderEmbOfFin_boundaries :
c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by
refine (Finset.orderEmbOfFin_unique' _ ?_).symm
exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _)
/-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocksFun i)`) into
`Fin n` at the relevant position. -/
def embedding (i : Fin c.length) : Fin (c.blocksFun i) βͺo Fin n :=
(Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <|
calc
c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ i.2).symm
_ β€ c.sizeUpTo c.length := monotone_sum_take _ i.2
_ = n := c.sizeUpTo_length
@[simp]
theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.embedding i j : β) = c.sizeUpTo i + j :=
rfl
/-- `index_exists` asserts there is some `i` with `j < c.sizeUpTo (i+1)`.
In the next definition `index` we use `Nat.find` to produce the minimal such index.
-/
theorem index_exists {j : β} (h : j < n) : β i : β, j < c.sizeUpTo (i + 1) β§ i < c.length := by
have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h
have : 0 < c.blocks.sum := by rwa [β c.blocks_sum] at n_pos
have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this
refine β¨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)β©
have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos
simp [this, h]
/-- `c.index j` is the index of the block in the composition `c` containing `j`. -/
def index (j : Fin n) : Fin c.length :=
β¨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2β©
theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : β) < c.sizeUpTo (c.index j).succ :=
(Nat.find_spec (c.index_exists j.2)).1
theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) β€ j := by
by_contra H
set i := c.index j
push_neg at H
have i_pos : (0 : β) < i := by
by_contra! i_pos
revert H
simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero]
let iβ := (i : β).pred
have iβ_lt_i : iβ < i := Nat.pred_lt (ne_of_gt i_pos)
have iβ_succ : iβ + 1 = i := Nat.succ_pred_eq_of_pos i_pos
have := Nat.find_min (c.index_exists j.2) iβ_lt_i
simp [lt_trans iβ_lt_i (c.index j).2, iβ_succ] at this
exact Nat.lt_le_asymm H this
/-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with
`Fin (c.blocksFun (c.index j))` through the canonical increasing bijection. -/
def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) :=
β¨j - c.sizeUpTo (c.index j), by
rw [tsub_lt_iff_right, add_comm, β sizeUpTo_succ']
Β· exact lt_sizeUpTo_index_succ _ _
Β· exact sizeUpTo_index_le _ _β©
@[simp]
theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : β) = j - c.sizeUpTo (c.index j) :=
rfl
theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by
rw [Fin.ext_iff]
apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j)
theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} :
j β Set.range (c.embedding i) β c.sizeUpTo i β€ j β§ (j : β) < c.sizeUpTo (i : β).succ := by
constructor
Β· intro h
rcases Set.mem_range.2 h with β¨k, hkβ©
rw [Fin.ext_iff] at hk
dsimp at hk
rw [β hk]
simp [sizeUpTo_succ', k.is_lt]
Β· intro h
apply Set.mem_range.2
refine β¨β¨j - c.sizeUpTo i, ?_β©, ?_β©
Β· rw [tsub_lt_iff_left, β sizeUpTo_succ']
Β· exact h.2
Β· exact h.1
Β· rw [Fin.ext_iff]
exact add_tsub_cancel_of_le h.1
/-- The embeddings of different blocks of a composition are disjoint. -/
theorem disjoint_range {iβ iβ : Fin c.length} (h : iβ β iβ) :
Disjoint (Set.range (c.embedding iβ)) (Set.range (c.embedding iβ)) := by
classical
wlog h' : iβ < iβ
Β· exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm
by_contra d
obtain β¨x, hxβ, hxββ© :
β x : Fin n, x β Set.range (c.embedding iβ) β§ x β Set.range (c.embedding iβ) :=
Set.not_disjoint_iff.1 d
have A : (iβ : β).succ β€ iβ := Nat.succ_le_of_lt h'
apply lt_irrefl (x : β)
calc
(x : β) < c.sizeUpTo (iβ : β).succ := (c.mem_range_embedding_iff.1 hxβ).2
_ β€ c.sizeUpTo (iβ : β) := monotone_sum_take _ A
_ β€ x := (c.mem_range_embedding_iff.1 hxβ).1
theorem mem_range_embedding (j : Fin n) : j β Set.range (c.embedding (c.index j)) := by
have : c.embedding (c.index j) (c.invEmbedding j) β Set.range (c.embedding (c.index j)) :=
Set.mem_range_self _
rwa [c.embedding_comp_inv j] at this
theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} :
j β Set.range (c.embedding i) β i = c.index j := by
constructor
Β· rw [β not_imp_not]
intro h
exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j)
Β· intro h
rw [h]
exact c.mem_range_embedding j
theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) :
c.index (c.embedding i j) = i := by
symm
rw [β mem_range_embedding_iff']
apply Set.mem_range_self
theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) :
(c.invEmbedding (c.embedding i j) : β) = j := by
simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left]
/-- Equivalence between the disjoint union of the blocks (each of them seen as
`Fin (c.blocksFun i)`) with `Fin n`. -/
def blocksFinEquiv : (Ξ£i : Fin c.length, Fin (c.blocksFun i)) β Fin n where
toFun x := c.embedding x.1 x.2
invFun j := β¨c.index j, c.invEmbedding jβ©
left_inv x := by
rcases x with β¨i, yβ©
dsimp
congr; Β· exact c.index_embedding _ _
rw [Fin.heq_ext_iff]
Β· exact c.invEmbedding_comp _ _
Β· rw [c.index_embedding]
right_inv j := c.embedding_comp_inv j
theorem blocksFun_congr {nβ nβ : β} (cβ : Composition nβ) (cβ : Composition nβ) (iβ : Fin cβ.length)
(iβ : Fin cβ.length) (hn : nβ = nβ) (hc : cβ.blocks = cβ.blocks) (hi : (iβ : β) = iβ) :
cβ.blocksFun iβ = cβ.blocksFun iβ := by
cases hn
rw [β Composition.ext_iff] at hc
cases hc
congr
rwa [Fin.ext_iff]
/-- Two compositions (possibly of different integers) coincide if and only if they have the
same sequence of blocks. -/
theorem sigma_eq_iff_blocks_eq {c : Ξ£ n, Composition n} {c' : Ξ£ n, Composition n} :
c = c' β c.2.blocks = c'.2.blocks := by
refine β¨fun H => by rw [H], fun H => ?_β©
rcases c with β¨n, cβ©
rcases c' with β¨n', c'β©
have : n = n' := by rw [β c.blocks_sum, β c'.blocks_sum, H]
induction this
congr
ext1
exact H
/-! ### The composition `Composition.ones` -/
/-- The composition made of blocks all of size `1`. -/
def ones (n : β) : Composition n :=
β¨replicate n (1 : β), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simpβ©
instance {n : β} : Inhabited (Composition n) :=
β¨Composition.ones nβ©
@[simp]
theorem ones_length (n : β) : (ones n).length = n :=
List.length_replicate
@[simp]
theorem ones_blocks (n : β) : (ones n).blocks = replicate n (1 : β) :=
rfl
@[simp]
theorem ones_blocksFun (n : β) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by
simp only [blocksFun, ones, get_eq_getElem, getElem_replicate]
@[simp]
theorem ones_sizeUpTo (n : β) (i : β) : (ones n).sizeUpTo i = min i n := by
simp [sizeUpTo, ones_blocks, take_replicate]
@[simp]
theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) :
(ones n).embedding i β¨0, hβ© = β¨i, lt_of_lt_of_le i.2 (ones n).length_leβ© := by
ext
simpa using i.2.le
theorem eq_ones_iff {c : Composition n} : c = ones n β β i β c.blocks, i = 1 := by
constructor
Β· rintro rfl
exact fun i => eq_of_mem_replicate
Β· intro H
ext1
have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H
have : c.blocks.length = n := by
conv_rhs => rw [β c.blocks_sum, A]
simp
rw [A, this, ones_blocks]
theorem ne_ones_iff {c : Composition n} : c β ones n β β i β c.blocks, 1 < i := by
refine (not_congr eq_ones_iff).trans ?_
have : β j β c.blocks, j = 1 β j β€ 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj]
simp +contextual [this]
theorem eq_ones_iff_length {c : Composition n} : c = ones n β c.length = n := by
constructor
Β· rintro rfl
exact ones_length n
Β· contrapose
intro H length_n
apply lt_irrefl n
calc
n = β i : Fin c.length, 1 := by simp [length_n]
_ < β i : Fin c.length, c.blocksFun i := by
{
obtain β¨i, hi, i_blocksβ© : β i β c.blocks, 1 < i := ne_ones_iff.1 H
rw [β ofFn_blocksFun, mem_ofFn' c.blocksFun, Set.mem_range] at hi
obtain β¨j : Fin c.length, hj : c.blocksFun j = iβ© := hi
rw [β hj] at i_blocks
exact Finset.sum_lt_sum (fun i _ => one_le_blocksFun c i) β¨j, Finset.mem_univ _, i_blocksβ©
}
_ = n := c.sum_blocksFun
theorem eq_ones_iff_le_length {c : Composition n} : c = ones n β n β€ c.length := by
simp [eq_ones_iff_length, le_antisymm_iff, c.length_le]
/-! ### The composition `Composition.single` -/
/-- The composition made of a single block of size `n`. -/
def single (n : β) (h : 0 < n) : Composition n :=
β¨[n], by simp [h], by simpβ©
@[simp]
theorem single_length {n : β} (h : 0 < n) : (single n h).length = 1 :=
rfl
@[simp]
theorem single_blocks {n : β} (h : 0 < n) : (single n h).blocks = [n] :=
rfl
@[simp]
theorem single_blocksFun {n : β} (h : 0 < n) (i : Fin (single n h).length) :
(single n h).blocksFun i = n := by simp [blocksFun, single, blocks, i.2]
@[simp]
theorem single_embedding {n : β} (h : 0 < n) (i : Fin n) :
((single n h).embedding (0 : Fin 1)) i = i := by
ext
simp
theorem eq_single_iff_length {n : β} (h : 0 < n) {c : Composition n} :
c = single n h β c.length = 1 := by
| constructor
Β· intro H
| Mathlib/Combinatorics/Enumerative/Composition.lean | 544 | 545 |
/-
Copyright (c) 2022 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.Ring.Nat
/-!
# Double countings
This file gathers a few double counting arguments.
## Bipartite graphs
In a bipartite graph (considered as a relation `r : Ξ± β Ξ² β Prop`), we can bound the number of edges
between `s : Finset Ξ±` and `t : Finset Ξ²` by the minimum/maximum of edges over all `a β s` times the
size of `s`. Similarly for `t`. Combining those two yields inequalities between the sizes of `s`
and `t`.
* `bipartiteBelow`: `s.bipartiteBelow r b` are the elements of `s` below `b` wrt to `r`. Its size
is the number of edges of `b` in `s`.
* `bipartiteAbove`: `t.bipartite_Above r a` are the elements of `t` above `a` wrt to `r`. Its size
is the number of edges of `a` in `t`.
* `card_mul_le_card_mul`, `card_mul_le_card_mul'`: Double counting the edges of a bipartite graph
from below and from above.
* `card_mul_eq_card_mul`: Equality combination of the previous.
## Implementation notes
For the formulation of double-counting arguments where a bipartite graph is considered as a
bipartite simple graph `G : SimpleGraph V`, see `Mathlib.Combinatorics.SimpleGraph.Bipartite`.
-/
assert_not_exists Field
open Finset Function Relator
variable {R Ξ± Ξ² : Type*}
/-! ### Bipartite graph -/
namespace Finset
section Bipartite
variable (r : Ξ± β Ξ² β Prop) (s : Finset Ξ±) (t : Finset Ξ²) (a : Ξ±) (b : Ξ²)
[DecidablePred (r a)] [β a, Decidable (r a b)] {m n : β}
/-- Elements of `s` which are "below" `b` according to relation `r`. -/
def bipartiteBelow : Finset Ξ± := {a β s | r a b}
/-- Elements of `t` which are "above" `a` according to relation `r`. -/
def bipartiteAbove : Finset Ξ² := {b β t | r a b}
theorem bipartiteBelow_swap : t.bipartiteBelow (swap r) a = t.bipartiteAbove r a := rfl
theorem bipartiteAbove_swap : s.bipartiteAbove (swap r) b = s.bipartiteBelow r b := rfl
@[simp, norm_cast]
theorem coe_bipartiteBelow : s.bipartiteBelow r b = ({a β s | r a b} : Set Ξ±) := coe_filter _ _
@[simp, norm_cast]
theorem coe_bipartiteAbove : t.bipartiteAbove r a = ({b β t | r a b} : Set Ξ²) := coe_filter _ _
variable {s t a b}
@[simp]
theorem mem_bipartiteBelow {a : Ξ±} : a β s.bipartiteBelow r b β a β s β§ r a b := mem_filter
@[simp]
theorem mem_bipartiteAbove {b : Ξ²} : b β t.bipartiteAbove r a β b β t β§ r a b := mem_filter
@[to_additive]
theorem prod_prod_bipartiteAbove_eq_prod_prod_bipartiteBelow
[CommMonoid R] (f : Ξ± β Ξ² β R) [β a b, Decidable (r a b)] :
β a β s, β b β t.bipartiteAbove r a, f a b = β b β t, β a β s.bipartiteBelow r b, f a b := by
simp_rw [bipartiteAbove, bipartiteBelow, prod_filter]
exact prod_comm
theorem sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow [β a b, Decidable (r a b)] :
(β a β s, #(t.bipartiteAbove r a)) = β b β t, #(s.bipartiteBelow r b) := by
simp_rw [card_eq_sum_ones, sum_sum_bipartiteAbove_eq_sum_sum_bipartiteBelow]
section OrderedSemiring
variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {m n : R}
/-- **Double counting** argument.
Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS
is an upper bound. -/
theorem card_nsmul_le_card_nsmul [β a b, Decidable (r a b)]
(hm : β a β s, m β€ #(t.bipartiteAbove r a))
(hn : β b β t, #(s.bipartiteBelow r b) β€ n) : #s β’ m β€ #t β’ n :=
calc
_ β€ β a β s, (#(t.bipartiteAbove r a) : R) := s.card_nsmul_le_sum _ _ hm
_ = β b β t, (#(s.bipartiteBelow r b) : R) := by
norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow]
_ β€ _ := t.sum_le_card_nsmul _ _ hn
/-- **Double counting** argument.
Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS
is an upper bound. -/
theorem card_nsmul_le_card_nsmul' [β a b, Decidable (r a b)]
(hn : β b β t, n β€ #(s.bipartiteBelow r b))
(hm : β a β s, #(t.bipartiteAbove r a) β€ m) : #t β’ n β€ #s β’ m :=
card_nsmul_le_card_nsmul (swap r) hn hm
end OrderedSemiring
section StrictOrderedSemiring
variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] (r : Ξ± β Ξ² β Prop)
{s : Finset Ξ±} {t : Finset Ξ²} (a b) {m n : R}
/-- **Double counting** argument.
Considering `r` as a bipartite graph, the LHS is a strict lower bound on the number of edges while
the RHS is an upper bound. -/
theorem card_nsmul_lt_card_nsmul_of_lt_of_le [β a b, Decidable (r a b)] (hs : s.Nonempty)
(hm : β a β s, m < #(t.bipartiteAbove r a))
(hn : β b β t, #(s.bipartiteBelow r b) β€ n) : #s β’ m < #t β’ n :=
calc
_ = β _a β s, m := by rw [sum_const]
_ < β a β s, (#(t.bipartiteAbove r a) : R) := sum_lt_sum_of_nonempty hs hm
_ = β b β t, (#(s.bipartiteBelow r b) : R) := by
norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow]
_ β€ _ := t.sum_le_card_nsmul _ _ hn
/-- **Double counting** argument.
Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS
is a strict upper bound. -/
theorem card_nsmul_lt_card_nsmul_of_le_of_lt [β a b, Decidable (r a b)] (ht : t.Nonempty)
(hm : β a β s, m β€ #(t.bipartiteAbove r a))
| (hn : β b β t, #(s.bipartiteBelow r b) < n) : #s β’ m < #t β’ n :=
calc
_ β€ β a β s, (#(t.bipartiteAbove r a) : R) := s.card_nsmul_le_sum _ _ hm
| Mathlib/Combinatorics/Enumerative/DoubleCounting.lean | 138 | 140 |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * Ο`. For some purposes,
angles modulo `Ο` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `Ο` can be represented
modulo `2 * Ο` as equalities of `(2 : β€) β’ ΞΈ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace β V] [InnerProductSpace β V']
variable [Fact (finrank β V = 2)] [Fact (finrank β V' = 2)] (o : Orientation β V (Fin 2))
local notation "Ο" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * Ο`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
@[fun_prop]
theorem continuousAt_oangle {x : V Γ V} (hx1 : x.1 β 0) (hx2 : x.2 β 0) :
ContinuousAt (fun y : V Γ V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
Β· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuousβ).mul continuous_const)).continuousAt
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, β ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * Ο))
apply arg_ofReal_of_nonneg
positivity
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : x β 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : y β 0 := by
rintro rfl; simp at h
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y β 0) : x β y := by
rintro rfl; simp at h
/-- If the angle between two vectors is `Ο`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `Ο / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο / 2 : β)) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) :
y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the angle between two vectors is `-Ο / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο / 2 : β)) : x β y :=
o.ne_of_oangle_ne_zero (h.symm βΈ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β 0)
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : x β 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : y β 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β 0) : x β y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y β 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β y :=
o.ne_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y β 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β y :=
o.ne_of_oangle_sign_ne_zero (h.symm βΈ by decide : (o.oangle x y).sign β 0)
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
/-- Negating the first vector passed to `oangle` adds `Ο` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle (-x) y = o.oangle x y + Ο := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the second vector passed to `oangle` adds `Ο` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x β 0) (hy : y β 0) :
o.oangle x (-y) = o.oangle x y + Ο := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : β€) β’ o.oangle (-x) y = (2 : β€) β’ o.oangle x y := by
by_cases hx : x = 0
Β· simp [hx]
Β· by_cases hy : y = 0
Β· simp [hy]
Β· simp [o.oangle_neg_left hx hy]
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : β€) β’ o.oangle x (-y) = (2 : β€) β’ o.oangle x y := by
by_cases hx : x = 0
Β· simp [hx]
Β· by_cases hy : y = 0
Β· simp [hy]
Β· simp [o.oangle_neg_right hx hy]
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle]
/-- Negating the first vector produces the same angle as negating the second vector. -/
theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by
rw [β neg_neg y, oangle_neg_neg, neg_neg]
/-- The angle between the negation of a nonzero vector and that vector is `Ο`. -/
@[simp]
theorem oangle_neg_self_left {x : V} (hx : x β 0) : o.oangle (-x) x = Ο := by
simp [oangle_neg_left, hx]
/-- The angle between a nonzero vector and its negation is `Ο`. -/
@[simp]
theorem oangle_neg_self_right {x : V} (hx : x β 0) : o.oangle x (-x) = Ο := by
simp [oangle_neg_right, hx]
/-- Twice the angle between the negation of a vector and that vector is 0. -/
theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : β€) β’ o.oangle (-x) x = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Twice the angle between a vector and its negation is 0. -/
theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : β€) β’ o.oangle x (-x) = 0 := by
by_cases hx : x = 0 <;> simp [hx]
/-- Adding the angles between two vectors in each order, with the first vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by
rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel]
/-- Adding the angles between two vectors in each order, with the second vector in each angle
negated, results in 0. -/
@[simp]
| theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 243 | 243 |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ΞΉ Ξ± Ξ² : Type*}
section LinearOrderedSemifield
variable [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d e : Ξ±} {m n : β€}
/-!
### Relating two divisions.
-/
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_le_div_right (hc : 0 < c) : a / c β€ b / c β a β€ b := div_le_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c β a < b := div_lt_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")]
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c β c < b :=
div_lt_div_iff_of_pos_left ha hb hc
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b β€ a / c β c β€ b :=
div_le_div_iff_of_pos_left ha hb hc
@[deprecated div_lt_div_iffβ (since := "2024-11-12")]
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d β a * d < c * b :=
div_lt_div_iffβ b0 d0
@[deprecated div_le_div_iffβ (since := "2024-11-12")]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b β€ c / d β a * d β€ c * b :=
div_le_div_iffβ b0 d0
@[deprecated div_le_divβ (since := "2024-11-12")]
theorem div_le_div (hc : 0 β€ c) (hac : a β€ c) (hd : 0 < d) (hbd : d β€ b) : a / b β€ c / d :=
div_le_divβ hc hac hd hbd
@[deprecated div_lt_divβ (since := "2024-11-12")]
theorem div_lt_div (hac : a < c) (hbd : d β€ b) (c0 : 0 β€ c) (d0 : 0 < d) : a / b < c / d :=
div_lt_divβ hac hbd c0 d0
@[deprecated div_lt_divβ' (since := "2024-11-12")]
theorem div_lt_div' (hac : a β€ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
div_lt_divβ' hac hbd c0 d0
/-!
### Relating one division and involving `1`
-/
@[bound]
theorem div_le_self (ha : 0 β€ a) (hb : 1 β€ b) : a / b β€ a := by
simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb
@[bound]
theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by
simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb
@[bound]
theorem le_div_self (ha : 0 β€ a) (hbβ : 0 < b) (hbβ : b β€ 1) : a β€ a / b := by
simpa only [div_one] using div_le_div_of_nonneg_left ha hbβ hbβ
theorem one_le_div (hb : 0 < b) : 1 β€ a / b β b β€ a := by rw [le_div_iffβ hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b β€ 1 β a β€ b := by rw [div_le_iffβ hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b β b < a := by rw [lt_div_iffβ hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 β a < b := by rw [div_lt_iffβ hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a β€ b β 1 / b β€ a := by
simpa using inv_le_commβ ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b β 1 / b < a := by
simpa using inv_lt_commβ ha hb
theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a β€ 1 / b β b β€ 1 / a := by
simpa using le_inv_commβ ha hb
theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b β b < 1 / a := by
simpa using lt_inv_commβ ha hb
@[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a β 1 < a / b := (one_lt_div b0).mpr
@[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b β a / b < 1 := (div_lt_one b0).mpr
/-!
### Relating two divisions, involving `1`
-/
theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a β€ b) : 1 / b β€ 1 / a := by
simpa using inv_antiβ ha h
theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by
rwa [lt_div_iffβ' ha, β div_eq_mul_one_div, div_lt_one (ha.trans h)]
theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a β€ 1 / b) : b β€ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h
theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h
/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and
`le_of_one_div_le_one_div` -/
theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a β€ 1 / b β b β€ a :=
div_le_div_iff_of_pos_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b β b < a :=
div_lt_div_iff_of_pos_left zero_lt_one ha hb
theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by
rwa [lt_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one]
theorem one_le_one_div (h1 : 0 < a) (h2 : a β€ 1) : 1 β€ 1 / a := by
rwa [le_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one]
/-!
### Results about halving.
The equalities also hold in semifields of characteristic `0`.
-/
theorem half_pos (h : 0 < a) : 0 < a / 2 :=
div_pos h zero_lt_two
theorem one_half_pos : (0 : Ξ±) < 1 / 2 :=
half_pos zero_lt_one
@[simp]
theorem half_le_self_iff : a / 2 β€ a β 0 β€ a := by
rw [div_le_iffβ (zero_lt_two' Ξ±), mul_two, le_add_iff_nonneg_left]
@[simp]
theorem half_lt_self_iff : a / 2 < a β 0 < a := by
rw [div_lt_iffβ (zero_lt_two' Ξ±), mul_two, lt_add_iff_pos_left]
alias β¨_, half_le_selfβ© := half_le_self_iff
alias β¨_, half_lt_selfβ© := half_lt_self_iff
alias div_two_lt_of_pos := half_lt_self
theorem one_half_lt_one : (1 / 2 : Ξ±) < 1 :=
half_lt_self zero_lt_one
theorem two_inv_lt_one : (2β»ΒΉ : Ξ±) < 1 :=
(one_div _).symm.trans_lt one_half_lt_one
theorem left_lt_add_div_two : a < (a + b) / 2 β a < b := by simp [lt_div_iffβ, mul_two]
theorem add_div_two_lt_right : (a + b) / 2 < b β a < b := by simp [div_lt_iffβ, mul_two]
theorem add_thirds (a : Ξ±) : a / 3 + a / 3 + a / 3 = a := by
rw [div_add_div_same, div_add_div_same, β two_mul, β add_one_mul 2 a, two_add_one_eq_three,
mul_div_cancel_leftβ a three_ne_zero]
/-!
### Miscellaneous lemmas
-/
@[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b β 0 < b := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos]
@[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b β 0 < a := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)]
theorem mul_le_mul_of_mul_div_le (h : a * (b / c) β€ d) (hc : 0 < c) : b * a β€ d * c := by
rw [β mul_div_assoc] at h
rwa [mul_comm b, β div_le_iffβ hc]
theorem div_mul_le_div_mul_of_div_le_div (h : a / b β€ c / d) (he : 0 β€ e) :
a / (b * e) β€ c / (d * e) := by
rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div]
exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he)
theorem exists_pos_mul_lt {a : Ξ±} (h : 0 < a) (b : Ξ±) : β c : Ξ±, 0 < c β§ b * c < a := by
have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one))
refine β¨a / max (b + 1) 1, this, ?_β©
rw [β lt_div_iffβ this, div_div_cancelβ h.ne']
exact lt_max_iff.2 (Or.inl <| lt_add_one _)
theorem exists_pos_lt_mul {a : Ξ±} (h : 0 < a) (b : Ξ±) : β c : Ξ±, 0 < c β§ b < c * a :=
let β¨c, hcβ, hcβ© := exists_pos_mul_lt h b;
β¨cβ»ΒΉ, inv_pos.2 hcβ, by rwa [β div_eq_inv_mul, lt_div_iffβ hcβ]β©
lemma monotone_div_right_of_nonneg (ha : 0 β€ a) : Monotone (Β· / a) :=
fun _b _c hbc β¦ div_le_div_of_nonneg_right hbc ha
lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (Β· / a) :=
fun _b _c hbc β¦ div_lt_div_of_pos_right hbc ha
theorem Monotone.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β Ξ±} (hf : Monotone f) {c : Ξ±}
(hc : 0 β€ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf
theorem StrictMono.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β Ξ±} (hf : StrictMono f) {c : Ξ±}
(hc : 0 < c) : StrictMono fun x => f x / c := by
simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc)
-- see Note [lower instance priority]
instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered Ξ± where
dense aβ aβ h :=
β¨(aβ + aβ) / 2,
calc
aβ = (aβ + aβ) / 2 := (add_self_div_two aβ).symm
_ < (aβ + aβ) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two
,
calc
(aβ + aβ) / 2 < (aβ + aβ) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two
_ = aβ := add_self_div_two aβ
β©
theorem min_div_div_right {c : Ξ±} (hc : 0 β€ c) (a b : Ξ±) : min (a / c) (b / c) = min a b / c :=
(monotone_div_right_of_nonneg hc).map_min.symm
theorem max_div_div_right {c : Ξ±} (hc : 0 β€ c) (a b : Ξ±) : max (a / c) (b / c) = max a b / c :=
(monotone_div_right_of_nonneg hc).map_max.symm
theorem one_div_strictAntiOn : StrictAntiOn (fun x : Ξ± => 1 / x) (Set.Ioi 0) :=
fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy
theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 β€ a) {m n : β} (mn : m β€ n) :
1 / a ^ n β€ 1 / a ^ m := by
refine (one_div_le_one_div ?_ ?_).mpr (pow_right_monoβ a1 mn) <;>
exact pow_pos (zero_lt_one.trans_le a1) _
theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : β} (mn : m < n) :
1 / a ^ n < 1 / a ^ m := by
refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_rightβ a1 mn) <;>
exact pow_pos (zero_lt_one.trans a1) _
theorem one_div_pow_anti (a1 : 1 β€ a) : Antitone fun n : β => 1 / a ^ n := fun _ _ =>
one_div_pow_le_one_div_pow_of_le a1
theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β => 1 / a ^ n := fun _ _ =>
one_div_pow_lt_one_div_pow_of_lt a1
theorem inv_strictAntiOn : StrictAntiOn (fun x : Ξ± => xβ»ΒΉ) (Set.Ioi 0) := fun _ hx _ hy xy =>
(inv_lt_invβ hy hx).2 xy
theorem inv_pow_le_inv_pow_of_le (a1 : 1 β€ a) {m n : β} (mn : m β€ n) : (a ^ n)β»ΒΉ β€ (a ^ m)β»ΒΉ := by
convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp
theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : β} (mn : m < n) : (a ^ n)β»ΒΉ < (a ^ m)β»ΒΉ := by
convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp
theorem inv_pow_anti (a1 : 1 β€ a) : Antitone fun n : β => (a ^ n)β»ΒΉ := fun _ _ =>
inv_pow_le_inv_pow_of_le a1
theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β => (a ^ n)β»ΒΉ := fun _ _ =>
inv_pow_lt_inv_pow_of_lt a1
theorem le_iff_forall_one_lt_le_mulβ {Ξ± : Type*}
[Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±]
{a b : Ξ±} (hb : 0 β€ b) : a β€ b β β Ξ΅, 1 < Ξ΅ β a β€ b * Ξ΅ := by
refine β¨fun h _ hΞ΅ β¦ h.trans <| le_mul_of_one_le_right hb hΞ΅.le, fun h β¦ ?_β©
obtain rfl|hb := hb.eq_or_lt
Β· simp_rw [zero_mul] at h
exact h 2 one_lt_two
refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_
convert h (x / b) ((one_lt_div hb).mpr hbx)
rw [mul_div_cancelβ _ hb.ne']
/-! ### Results about `IsGLB` -/
theorem IsGLB.mul_left {s : Set Ξ±} (ha : 0 β€ a) (hs : IsGLB s b) :
IsGLB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
Β· exact (OrderIso.mulLeftβ _ ha).isGLB_image'.2 hs
Β· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isGLB_singleton
theorem IsGLB.mul_right {s : Set Ξ±} (ha : 0 β€ a) (hs : IsGLB s b) :
IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
end LinearOrderedSemifield
section
variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d : Ξ±} {n : β€}
/-! ### Lemmas about pos, nonneg, nonpos, neg -/
theorem div_pos_iff : 0 < a / b β 0 < a β§ 0 < b β¨ a < 0 β§ b < 0 := by
simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero]
theorem div_neg_iff : a / b < 0 β 0 < a β§ b < 0 β¨ a < 0 β§ 0 < b := by
simp [division_def, mul_neg_iff]
theorem div_nonneg_iff : 0 β€ a / b β 0 β€ a β§ 0 β€ b β¨ a β€ 0 β§ b β€ 0 := by
simp [division_def, mul_nonneg_iff]
theorem div_nonpos_iff : a / b β€ 0 β 0 β€ a β§ b β€ 0 β¨ a β€ 0 β§ 0 β€ b := by
simp [division_def, mul_nonpos_iff]
theorem div_nonneg_of_nonpos (ha : a β€ 0) (hb : b β€ 0) : 0 β€ a / b :=
div_nonneg_iff.2 <| Or.inr β¨ha, hbβ©
theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=
div_pos_iff.2 <| Or.inr β¨ha, hbβ©
theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=
div_neg_iff.2 <| Or.inr β¨ha, hbβ©
theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=
div_neg_iff.2 <| Or.inl β¨ha, hbβ©
/-! ### Relating one division with another term -/
theorem div_le_iff_of_neg (hc : c < 0) : b / c β€ a β a * c β€ b :=
β¨fun h => div_mul_cancelβ b (ne_of_lt hc) βΈ mul_le_mul_of_nonpos_right h hc.le, fun h =>
calc
a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc)
_ β₯ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le
_ = b / c := (div_eq_mul_one_div b c).symm
β©
theorem div_le_iff_of_neg' (hc : c < 0) : b / c β€ a β c * a β€ b := by
rw [mul_comm, div_le_iff_of_neg hc]
theorem le_div_iff_of_neg (hc : c < 0) : a β€ b / c β b β€ a * c := by
rw [β neg_neg c, mul_neg, div_neg, le_neg, div_le_iffβ (neg_pos.2 hc), neg_mul]
theorem le_div_iff_of_neg' (hc : c < 0) : a β€ b / c β b β€ c * a := by
rw [mul_comm, le_div_iff_of_neg hc]
theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a β a * c < b :=
lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc
theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a β c * a < b := by
rw [mul_comm, div_lt_iff_of_neg hc]
theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c β b < a * c :=
lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc
theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c β b < c * a := by
rw [mul_comm, lt_div_iff_of_neg hc]
theorem div_le_one_of_ge (h : b β€ a) (hb : b β€ 0) : a / b β€ 1 := by
simpa only [neg_div_neg_eq] using div_le_one_of_leβ (neg_le_neg h) (neg_nonneg_of_nonpos hb)
/-! ### Bi-implications of inequalities using inversions -/
theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ β€ bβ»ΒΉ β b β€ a := by
rw [β one_div, div_le_iff_of_neg ha, β div_eq_inv_mul, div_le_iff_of_neg hb, one_mul]
theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ β€ b β bβ»ΒΉ β€ a := by
rw [β inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv]
theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a β€ bβ»ΒΉ β b β€ aβ»ΒΉ := by
rw [β inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv]
theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ < bβ»ΒΉ β b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)
theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ < b β bβ»ΒΉ < a :=
lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)
theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < bβ»ΒΉ β b < aβ»ΒΉ :=
lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)
/-!
### Monotonicity results involving inversion
-/
theorem sub_inv_antitoneOn_Ioi :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Ioi c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab β¦
inv_le_invβ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Iio :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Iio c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab β¦
inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Icc_right (ha : c < a) :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Icc a b) := by
by_cases hab : a β€ b
Β· exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha
Β· simp [hab, Set.Subsingleton.antitoneOn]
theorem sub_inv_antitoneOn_Icc_left (ha : b < c) :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Icc a b) := by
by_cases hab : a β€ b
Β· exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha
Β· simp [hab, Set.Subsingleton.antitoneOn]
theorem inv_antitoneOn_Ioi :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Ioi 0) := by
convert sub_inv_antitoneOn_Ioi (Ξ± := Ξ±)
exact (sub_zero _).symm
theorem inv_antitoneOn_Iio :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Iio 0) := by
convert sub_inv_antitoneOn_Iio (Ξ± := Ξ±)
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_right (ha : 0 < a) :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_right ha
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_left (hb : b < 0) :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_left hb
exact (sub_zero _).symm
/-! ### Relating two divisions -/
theorem div_le_div_of_nonpos_of_le (hc : c β€ 0) (h : b β€ a) : a / c β€ b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc)
theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc)
theorem div_le_div_right_of_neg (hc : c < 0) : a / c β€ b / c β b β€ a :=
β¨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.leβ©
theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c β b < a :=
lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc
/-! ### Relating one division and involving `1` -/
theorem one_le_div_of_neg (hb : b < 0) : 1 β€ a / b β a β€ b := by rw [le_div_iff_of_neg hb, one_mul]
theorem div_le_one_of_neg (hb : b < 0) : a / b β€ 1 β b β€ a := by rw [div_le_iff_of_neg hb, one_mul]
theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b β a < b := by rw [lt_div_iff_of_neg hb, one_mul]
theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 β b < a := by rw [div_lt_iff_of_neg hb, one_mul]
theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a β€ b β 1 / b β€ a := by
simpa using inv_le_of_neg ha hb
theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b β 1 / b < a := by
simpa using inv_lt_of_neg ha hb
theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a β€ 1 / b β b β€ 1 / a := by
simpa using le_inv_of_neg ha hb
theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b β b < 1 / a := by
simpa using lt_inv_of_neg ha hb
theorem one_lt_div_iff : 1 < a / b β 0 < b β§ b < a β¨ b < 0 β§ a < b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
Β· simp [hb, hb.not_lt, one_lt_div_of_neg]
Β· simp [lt_irrefl, zero_le_one]
Β· simp [hb, hb.not_lt, one_lt_div]
theorem one_le_div_iff : 1 β€ a / b β 0 < b β§ b β€ a β¨ b < 0 β§ a β€ b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
Β· simp [hb, hb.not_lt, one_le_div_of_neg]
Β· simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one]
| Β· simp [hb, hb.not_lt, one_le_div]
| Mathlib/Algebra/Order/Field/Basic.lean | 483 | 483 |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne
-/
import Mathlib.MeasureTheory.Integral.Bochner.Basic
import Mathlib.MeasureTheory.Integral.Bochner.L1
import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory
deprecated_module (since := "2025-04-13")
| Mathlib/MeasureTheory/Integral/Bochner.lean | 1,714 | 1,719 | |
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, SΓ©bastien GouΓ«zel
-/
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric
import Mathlib.MeasureTheory.Group.Pointwise
import Mathlib.MeasureTheory.Measure.Doubling
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
/-!
# Relationship between the Haar and Lebesgue measures
We prove that the Haar measure and Lebesgue measure are equal on `β` and on `β^ΞΉ`, in
`MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`.
We deduce basic properties of any Haar measure on a finite dimensional real vector space:
* `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the
absolute value of its determinant.
* `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure
of `f β»ΒΉ' s` is the measure of `s` multiplied by the absolute value of the inverse of the
determinant of `f`.
* `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the
measure of `s` multiplied by the absolute value of the determinant of `f`.
* `addHaar_submodule` : a strict submodule has measure `0`.
* `addHaar_smul` : the measure of `r β’ s` is `|r| ^ dim * ΞΌ s`.
* `addHaar_ball`: the measure of `ball x r` is `r ^ dim * ΞΌ (ball 0 1)`.
* `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * ΞΌ (ball 0 1)`.
* `addHaar_sphere`: spheres have zero measure.
This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`.
This measure is called `AlternatingMap.measure`. Its main property is
`Ο.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned
by vectors `vβ, ..., vβ` is given by `|Ο v|`.
We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has
density one for the rescaled copies `{x} + r β’ t` of a given set `t` with positive measure, in
`tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r β’ t` for
small `r`, see `eventually_nonempty_inter_smul_of_density_one`.
Statements on integrals of functions with respect to an additive Haar measure can be found in
`MeasureTheory.Measure.Haar.NormedSpace`.
-/
assert_not_exists MeasureTheory.integral
open TopologicalSpace Set Filter Metric Bornology
open scoped ENNReal Pointwise Topology NNReal
/-- The interval `[0,1]` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts β where
carrier := Icc 0 1
isCompact' := isCompact_Icc
interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one]
universe u
/-- The set `[0,1]^ΞΉ` as a compact set with non-empty interior. -/
def TopologicalSpace.PositiveCompacts.piIcc01 (ΞΉ : Type*) [Finite ΞΉ] :
PositiveCompacts (ΞΉ β β) where
carrier := pi univ fun _ => Icc 0 1
isCompact' := isCompact_univ_pi fun _ => isCompact_Icc
interior_nonempty' := by
simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo,
imp_true_iff, zero_lt_one]
/-- The parallelepiped formed from the standard basis for `ΞΉ β β` is `[0,1]^ΞΉ` -/
theorem Basis.parallelepiped_basisFun (ΞΉ : Type*) [Fintype ΞΉ] :
(Pi.basisFun β ΞΉ).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ΞΉ :=
SetLike.coe_injective <| by
refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm)
Β· classical convert parallelepiped_single (ΞΉ := ΞΉ) 1
Β· exact zero_le_one
/-- A parallelepiped can be expressed on the standard basis. -/
theorem Basis.parallelepiped_eq_map {ΞΉ E : Type*} [Fintype ΞΉ] [NormedAddCommGroup E]
[NormedSpace β E] (b : Basis ΞΉ β E) :
b.parallelepiped = (PositiveCompacts.piIcc01 ΞΉ).map b.equivFun.symm
b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by
classical
rw [β Basis.parallelepiped_basisFun, β Basis.parallelepiped_map]
congr with x
simp [Pi.single_apply]
open MeasureTheory MeasureTheory.Measure
theorem Basis.map_addHaar {ΞΉ E F : Type*} [Fintype ΞΉ] [NormedAddCommGroup E] [NormedAddCommGroup F]
[NormedSpace β E] [NormedSpace β F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E]
[BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F]
(b : Basis ΞΉ β E) (f : E βL[β] F) :
map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by
have : IsAddHaarMeasure (map f b.addHaar) :=
AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous
rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable
(PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map]
erw [β image_parallelepiped, f.toEquiv.preimage_image, addHaar_self]
namespace MeasureTheory
open Measure TopologicalSpace.PositiveCompacts Module
/-!
### The Lebesgue measure is a Haar measure on `β` and on `β^ΞΉ`.
-/
/-- The Haar measure equals the Lebesgue measure on `β`. -/
theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by
convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01]
/-- The Haar measure equals the Lebesgue measure on `β^ΞΉ`. -/
theorem addHaarMeasure_eq_volume_pi (ΞΉ : Type*) [Fintype ΞΉ] :
addHaarMeasure (piIcc01 ΞΉ) = volume := by
convert (addHaarMeasure_unique volume (piIcc01 ΞΉ)).symm
simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : β) 1, PositiveCompacts.coe_mk,
Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero]
theorem isAddHaarMeasure_volume_pi (ΞΉ : Type*) [Fintype ΞΉ] :
IsAddHaarMeasure (volume : Measure (ΞΉ β β)) :=
inferInstance
namespace Measure
/-!
### Strict subspaces have zero measure
-/
open scoped Function -- required for scoped `on` notation
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/
theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E]
[NormedSpace β E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional β E] (ΞΌ : Measure E)
[IsAddHaarMeasure ΞΌ] {s : Set E} (u : β β E) (sb : IsBounded s) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : ΞΌ s = 0 := by
by_contra h
apply lt_irrefl β
calc
β = β' _ : β, ΞΌ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm
_ = β' n : β, ΞΌ ({u n} + s) := by
congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add]
_ = ΞΌ (β n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by
simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's
_ = ΞΌ (range u + s) := by rw [β iUnion_add, iUnion_singleton_eq_range]
_ < β := (hu.add sb).measure_lt_top
/-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure
zero. -/
theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E]
[NormedSpace β E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional β E] (ΞΌ : Measure E)
[IsAddHaarMeasure ΞΌ] {s : Set E} (u : β β E) (hu : IsBounded (range u))
(hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : ΞΌ s = 0 := by
suffices H : β R, ΞΌ (s β© closedBall 0 R) = 0 by
apply le_antisymm _ (zero_le _)
calc
ΞΌ s β€ β' n : β, ΞΌ (s β© closedBall 0 n) := by
conv_lhs => rw [β iUnion_inter_closedBall_nat s 0]
exact measure_iUnion_le _
_ = 0 := by simp only [H, tsum_zero]
intro R
apply addHaar_eq_zero_of_disjoint_translates_aux ΞΌ u
(isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall)
refine pairwise_disjoint_mono hs fun n => ?_
exact add_subset_add Subset.rfl inter_subset_left
/-- A strict vector subspace has measure zero. -/
theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace β E] [MeasurableSpace E]
[BorelSpace E] [FiniteDimensional β E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (s : Submodule β E)
(hs : s β β€) : ΞΌ s = 0 := by
obtain β¨x, hxβ© : β x, x β s := by
simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs
obtain β¨c, cpos, coneβ© : β c : β, 0 < c β§ c < 1 := β¨1 / 2, by norm_num, by norm_numβ©
have A : IsBounded (range fun n : β => c ^ n β’ x) :=
have : Tendsto (fun n : β => c ^ n β’ x) atTop (π ((0 : β) β’ x)) :=
(tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x
isBounded_range_of_tendsto _ this
apply addHaar_eq_zero_of_disjoint_translates ΞΌ _ A _
(Submodule.closed_of_finiteDimensional s).measurableSet
intro m n hmn
simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage,
SetLike.mem_coe]
intro y hym hyn
have A : (c ^ n - c ^ m) β’ x β s := by
convert s.sub_mem hym hyn using 1
simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub]
have H : c ^ n - c ^ m β 0 := by
simpa only [sub_eq_zero, Ne] using (pow_right_strictAntiβ cpos cone).injective.ne hmn.symm
have : x β s := by
convert s.smul_mem (c ^ n - c ^ m)β»ΒΉ A
rw [smul_smul, inv_mul_cancelβ H, one_smul]
exact hx this
/-- A strict affine subspace has measure zero. -/
theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace β E]
[MeasurableSpace E] [BorelSpace E] [FiniteDimensional β E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ]
(s : AffineSubspace β E) (hs : s β β€) : ΞΌ s = 0 := by
rcases s.eq_bot_or_nonempty with (rfl | hne)
Β· rw [AffineSubspace.bot_coe, measure_empty]
rw [Ne, β AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs
rcases hne with β¨x, hx : x β sβ©
simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg,
image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule ΞΌ s.direction hs
/-!
### Applying a linear map rescales Haar measure by the determinant
We first prove this on `ΞΉ β β`, using that this is already known for the product Lebesgue
measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real
vector space by using a linear equiv with a space of the form `ΞΉ β β`, and arguing that such a
linear equiv maps Haar measure to Haar measure.
-/
theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ΞΉ : Type*} [Finite ΞΉ] {f : (ΞΉ β β) ββ[β] ΞΉ β β}
(hf : LinearMap.det f β 0) (ΞΌ : Measure (ΞΉ β β)) [IsAddHaarMeasure ΞΌ] :
Measure.map f ΞΌ = ENNReal.ofReal (abs (LinearMap.det f)β»ΒΉ) β’ ΞΌ := by
cases nonempty_fintype ΞΉ
/- We have already proved the result for the Lebesgue product measure, using matrices.
We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/
have := addHaarMeasure_unique ΞΌ (piIcc01 ΞΉ)
rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul,
Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β E] [MeasurableSpace E] [BorelSpace E]
[FiniteDimensional β E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ]
theorem map_linearMap_addHaar_eq_smul_addHaar {f : E ββ[β] E} (hf : LinearMap.det f β 0) :
Measure.map f ΞΌ = ENNReal.ofReal |(LinearMap.det f)β»ΒΉ| β’ ΞΌ := by
-- we reduce to the case of `E = ΞΉ β β`, for which we have already proved the result using
-- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`.
let ΞΉ := Fin (finrank β E)
haveI : FiniteDimensional β (ΞΉ β β) := by infer_instance
have : finrank β E = finrank β (ΞΉ β β) := by simp [ΞΉ]
have e : E ββ[β] ΞΉ β β := LinearEquiv.ofFinrankEq E (ΞΉ β β) this
-- next line is to avoid `g` getting reduced by `simp`.
obtain β¨g, hgβ© : β g, g = (e : E ββ[β] ΞΉ β β).comp (f.comp (e.symm : (ΞΉ β β) ββ[β] E)) := β¨_, rflβ©
have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e
rw [β gdet] at hf β’
have fg : f = (e.symm : (ΞΉ β β) ββ[β] E).comp (g.comp (e : E ββ[β] ΞΉ β β)) := by
ext x
simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp,
LinearEquiv.symm_apply_apply, hg]
simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp]
have Ce : Continuous e := (e : E ββ[β] ΞΉ β β).continuous_of_finiteDimensional
have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g
have Cesymm : Continuous e.symm := (e.symm : (ΞΉ β β) ββ[β] E).continuous_of_finiteDimensional
rw [β map_map Cesymm.measurable (Cg.comp Ce).measurable, β map_map Cg.measurable Ce.measurable]
haveI : IsAddHaarMeasure (map e ΞΌ) := (e : E β+ (ΞΉ β β)).isAddHaarMeasure_map ΞΌ Ce Cesymm
have ecomp : e.symm β e = id := by
ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply]
rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e ΞΌ), Measure.map_smul,
map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id]
/-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure
equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearMap {f : E ββ[β] E} (hf : LinearMap.det f β 0) (s : Set E) :
ΞΌ (f β»ΒΉ' s) = ENNReal.ofReal |(LinearMap.det f)β»ΒΉ| * ΞΌ s :=
calc
ΞΌ (f β»ΒΉ' s) = Measure.map f ΞΌ s :=
((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply
s).symm
_ = ENNReal.ofReal |(LinearMap.det f)β»ΒΉ| * ΞΌ s := by
rw [map_linearMap_addHaar_eq_smul_addHaar ΞΌ hf]; rfl
/-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure
equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearMap {f : E βL[β] E}
(hf : LinearMap.det (f : E ββ[β] E) β 0) (s : Set E) :
ΞΌ (f β»ΒΉ' s) = ENNReal.ofReal (abs (LinearMap.det (f : E ββ[β] E))β»ΒΉ) * ΞΌ s :=
addHaar_preimage_linearMap ΞΌ hf s
/-- The preimage of a set `s` under a linear equiv `f` has measure
equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_linearEquiv (f : E ββ[β] E) (s : Set E) :
ΞΌ (f β»ΒΉ' s) = ENNReal.ofReal |LinearMap.det (f.symm : E ββ[β] E)| * ΞΌ s := by
have A : LinearMap.det (f : E ββ[β] E) β 0 := (LinearEquiv.isUnit_det' f).ne_zero
convert addHaar_preimage_linearMap ΞΌ A s
simp only [LinearEquiv.det_coe_symm]
/-- The preimage of a set `s` under a continuous linear equiv `f` has measure
equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/
@[simp]
theorem addHaar_preimage_continuousLinearEquiv (f : E βL[β] E) (s : Set E) :
ΞΌ (f β»ΒΉ' s) = ENNReal.ofReal |LinearMap.det (f.symm : E ββ[β] E)| * ΞΌ s :=
addHaar_preimage_linearEquiv ΞΌ _ s
/-- The image of a set `s` under a linear map `f` has measure
equal to `ΞΌ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_linearMap (f : E ββ[β] E) (s : Set E) :
ΞΌ (f '' s) = ENNReal.ofReal |LinearMap.det f| * ΞΌ s := by
rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf)
Β· let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv
change ΞΌ (g '' s) = _
rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv]
congr
Β· simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero]
have : ΞΌ (LinearMap.range f) = 0 :=
addHaar_submodule ΞΌ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne
exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _)
/-- The image of a set `s` under a continuous linear map `f` has measure
equal to `ΞΌ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearMap (f : E βL[β] E) (s : Set E) :
ΞΌ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E ββ[β] E)| * ΞΌ s :=
addHaar_image_linearMap ΞΌ _ s
/-- The image of a set `s` under a continuous linear equiv `f` has measure
equal to `ΞΌ s` times the absolute value of the determinant of `f`. -/
@[simp]
theorem addHaar_image_continuousLinearEquiv (f : E βL[β] E) (s : Set E) :
ΞΌ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E ββ[β] E)| * ΞΌ s :=
ΞΌ.addHaar_image_linearMap (f : E ββ[β] E) s
theorem LinearMap.quasiMeasurePreserving (f : E ββ[β] E) (hf : LinearMap.det f β 0) :
QuasiMeasurePreserving f ΞΌ ΞΌ := by
refine β¨f.continuous_of_finiteDimensional.measurable, ?_β©
rw [map_linearMap_addHaar_eq_smul_addHaar ΞΌ hf]
exact smul_absolutelyContinuous
theorem ContinuousLinearMap.quasiMeasurePreserving (f : E βL[β] E) (hf : f.det β 0) :
QuasiMeasurePreserving f ΞΌ ΞΌ :=
LinearMap.quasiMeasurePreserving ΞΌ (f : E ββ[β] E) hf
/-!
### Basic properties of Haar measures on real vector spaces
-/
theorem map_addHaar_smul {r : β} (hr : r β 0) :
Measure.map (r β’ Β·) ΞΌ = ENNReal.ofReal (abs (r ^ finrank β E)β»ΒΉ) β’ ΞΌ := by
let f : E ββ[β] E := r β’ (1 : E ββ[β] E)
change Measure.map f ΞΌ = _
have hf : LinearMap.det f β 0 := by
simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one]
intro h
exact hr (pow_eq_zero h)
simp only [f, map_linearMap_addHaar_eq_smul_addHaar ΞΌ hf, mul_one, LinearMap.det_smul, map_one]
theorem quasiMeasurePreserving_smul {r : β} (hr : r β 0) :
QuasiMeasurePreserving (r β’ Β·) ΞΌ ΞΌ := by
refine β¨measurable_const_smul r, ?_β©
rw [map_addHaar_smul ΞΌ hr]
exact smul_absolutelyContinuous
@[simp]
theorem addHaar_preimage_smul {r : β} (hr : r β 0) (s : Set E) :
ΞΌ ((r β’ Β·) β»ΒΉ' s) = ENNReal.ofReal (abs (r ^ finrank β E)β»ΒΉ) * ΞΌ s :=
calc
ΞΌ ((r β’ Β·) β»ΒΉ' s) = Measure.map (r β’ Β·) ΞΌ s :=
((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm
_ = ENNReal.ofReal (abs (r ^ finrank β E)β»ΒΉ) * ΞΌ s := by
rw [map_addHaar_smul ΞΌ hr, coe_smul, Pi.smul_apply, smul_eq_mul]
/-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/
@[simp]
theorem addHaar_smul (r : β) (s : Set E) :
ΞΌ (r β’ s) = ENNReal.ofReal (abs (r ^ finrank β E)) * ΞΌ s := by
rcases ne_or_eq r 0 with (h | rfl)
Β· rw [β preimage_smul_invβ h, addHaar_preimage_smul ΞΌ (inv_ne_zero h), inv_pow, inv_inv]
rcases eq_empty_or_nonempty s with (rfl | hs)
Β· simp only [measure_empty, mul_zero, smul_set_empty]
rw [zero_smul_set hs, β singleton_zero]
by_cases h : finrank β E = 0
Β· haveI : Subsingleton E := finrank_zero_iff.1 h
simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs,
pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))]
Β· haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h)
simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff,
zero_pow, measure_singleton]
theorem addHaar_smul_of_nonneg {r : β} (hr : 0 β€ r) (s : Set E) :
ΞΌ (r β’ s) = ENNReal.ofReal (r ^ finrank β E) * ΞΌ s := by
rw [addHaar_smul, abs_pow, abs_of_nonneg hr]
variable {ΞΌ} {s : Set E}
-- Note: We might want to rename this once we acquire the lemma corresponding to
-- `MeasurableSet.const_smul`
theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s ΞΌ) (r : β) :
NullMeasurableSet (r β’ s) ΞΌ := by
obtain rfl | hs' := s.eq_empty_or_nonempty
Β· simp
obtain rfl | hr := eq_or_ne r 0
Β· simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _
obtain β¨t, ht, hstβ© := hs
refine β¨_, ht.const_smul_of_ne_zero hr, ?_β©
rw [β measure_symmDiff_eq_zero_iff] at hst β’
rw [β smul_set_symmDiffβ hr, addHaar_smul ΞΌ, hst, mul_zero]
variable (ΞΌ)
@[simp]
theorem addHaar_image_homothety (x : E) (r : β) (s : Set E) :
ΞΌ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank β E)) * ΞΌ s :=
calc
ΞΌ (AffineMap.homothety x r '' s) = ΞΌ ((fun y => y + x) '' (r β’ (fun y => y + -x) '' s)) := by
simp only [β image_smul, image_image, β sub_eq_add_neg]; rfl
_ = ENNReal.ofReal (abs (r ^ finrank β E)) * ΞΌ s := by
simp only [image_add_right, measure_preimage_add_right, addHaar_smul]
/-! We don't need to state `map_addHaar_neg` here, because it has already been proved for
general Haar measures on general commutative groups. -/
/-! ### Measure of balls -/
theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E]
(ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : β) : ΞΌ (ball x r) = ΞΌ (ball (0 : E) r) := by
have : ball (0 : E) r = (x + Β·) β»ΒΉ' ball x r := by simp [preimage_add_ball]
rw [this, measure_preimage_add]
theorem addHaar_real_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : β) :
ΞΌ.real (ball x r) = ΞΌ.real (ball (0 : E) r) := by
simp [measureReal_def, addHaar_ball_center]
theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : β) :
ΞΌ (closedBall x r) = ΞΌ (closedBall (0 : E) r) := by
have : closedBall (0 : E) r = (x + Β·) β»ΒΉ' closedBall x r := by simp [preimage_add_closedBall]
rw [this, measure_preimage_add]
theorem addHaar_real_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E]
[BorelSpace E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : β) :
ΞΌ.real (closedBall x r) = ΞΌ.real (closedBall (0 : E) r) := by
simp [measureReal_def, addHaar_closedBall_center]
theorem addHaar_ball_mul_of_pos (x : E) {r : β} (hr : 0 < r) (s : β) :
ΞΌ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank β E) * ΞΌ (ball 0 s) := by
have : ball (0 : E) (r * s) = r β’ ball (0 : E) s := by
simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero]
simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow]
theorem addHaar_ball_of_pos (x : E) {r : β} (hr : 0 < r) :
ΞΌ (ball x r) = ENNReal.ofReal (r ^ finrank β E) * ΞΌ (ball 0 1) := by
rw [β addHaar_ball_mul_of_pos ΞΌ x hr, mul_one]
theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : β} (hr : 0 β€ r) (s : β) :
ΞΌ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank β E) * ΞΌ (ball 0 s) := by
rcases hr.eq_or_lt with (rfl | h)
Β· simp only [zero_pow (finrank_pos (R := β) (M := E)).ne', measure_empty, zero_mul,
ENNReal.ofReal_zero, ball_zero]
Β· exact addHaar_ball_mul_of_pos ΞΌ x h s
theorem addHaar_ball [Nontrivial E] (x : E) {r : β} (hr : 0 β€ r) :
ΞΌ (ball x r) = ENNReal.ofReal (r ^ finrank β E) * ΞΌ (ball 0 1) := by
rw [β addHaar_ball_mul ΞΌ x hr, mul_one]
|
theorem addHaar_closedBall_mul_of_pos (x : E) {r : β} (hr : 0 < r) (s : β) :
ΞΌ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank β E) * ΞΌ (closedBall 0 s) := by
have : closedBall (0 : E) (r * s) = r β’ closedBall (0 : E) s := by
simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le]
| Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean | 454 | 458 |
/-
Copyright (c) 2023 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Topology.Connected.Basic
import Mathlib.Topology.Separation.Hausdorff
import Mathlib.Topology.Connected.Clopen
/-!
# Separated maps and locally injective maps out of a topological space.
This module introduces a pair of dual notions `IsSeparatedMap` and `IsLocallyInjective`.
A function from a topological space `X` to a type `Y` is a separated map if any two distinct
points in `X` with the same image in `Y` can be separated by open neighborhoods.
A constant function is a separated map if and only if `X` is a `T2Space`.
A function from a topological space `X` is locally injective if every point of `X`
has a neighborhood on which `f` is injective.
A constant function is locally injective if and only if `X` is discrete.
Given `f : X β Y` we can form the pullback $X \times_Y X$; the diagonal map
$\Delta: X \to X \times_Y X$ is always an embedding. It is a closed embedding
iff `f` is a separated map, iff the equal locus of any two continuous maps
coequalized by `f` is closed. It is an open embedding iff `f` is locally injective,
iff any such equal locus is open. Therefore, if `f` is a locally injective separated map,
the equal locus of two continuous maps coequalized by `f` is clopen, so if the two maps
agree on a point, then they agree on the whole connected component.
The analogue of separated maps and locally injective maps in algebraic geometry are
separated morphisms and unramified morphisms, respectively.
## Reference
https://stacks.math.columbia.edu/tag/0CY0
-/
open Topology
variable {X Y A} [TopologicalSpace X] [TopologicalSpace A]
protected lemma Topology.IsEmbedding.toPullbackDiag (f : X β Y) : IsEmbedding (toPullbackDiag f) :=
.mk' _ (injective_toPullbackDiag f) fun x β¦ by
simp [nhds_induced, Filter.comap_comap, nhds_prod_eq, Filter.comap_prod, Function.comp_def,
Filter.comap_id']
@[deprecated (since := "2024-10-26")]
alias embedding_toPullbackDiag := IsEmbedding.toPullbackDiag
lemma Continuous.mapPullback {Xβ Xβ Yβ Yβ Zβ Zβ}
[TopologicalSpace Xβ] [TopologicalSpace Xβ] [TopologicalSpace Zβ] [TopologicalSpace Zβ]
{fβ : Xβ β Yβ} {gβ : Zβ β Yβ} {fβ : Xβ β Yβ} {gβ : Zβ β Yβ}
{mapX : Xβ β Xβ} (contX : Continuous mapX) {mapY : Yβ β Yβ}
{mapZ : Zβ β Zβ} (contZ : Continuous mapZ)
{commX : fβ β mapX = mapY β fβ} {commZ : gβ β mapZ = mapY β gβ} :
Continuous (Function.mapPullback mapX mapY mapZ commX commZ) := by
refine continuous_induced_rng.mpr (.prodMk ?_ ?_) <;>
apply_rules [continuous_fst, continuous_snd, continuous_subtype_val, Continuous.comp]
/-- A function from a topological space `X` to a type `Y` is a separated map if any two distinct
points in `X` with the same image in `Y` can be separated by open neighborhoods. -/
def IsSeparatedMap (f : X β Y) : Prop := β xβ xβ, f xβ = f xβ β
xβ β xβ β β sβ sβ, IsOpen sβ β§ IsOpen sβ β§ xβ β sβ β§ xβ β sβ β§ Disjoint sβ sβ
lemma t2space_iff_isSeparatedMap (y : Y) : T2Space X β IsSeparatedMap fun _ : X β¦ y :=
β¨fun β¨t2β© _ _ _ hne β¦ t2 hne, fun sep β¦ β¨fun xβ xβ hne β¦ sep xβ xβ rfl hneβ©β©
lemma T2Space.isSeparatedMap [T2Space X] (f : X β Y) : IsSeparatedMap f := fun _ _ _ β¦ t2_separation
lemma Function.Injective.isSeparatedMap {f : X β Y} (inj : f.Injective) : IsSeparatedMap f :=
fun _ _ he hne β¦ (hne (inj he)).elim
lemma isSeparatedMap_iff_disjoint_nhds {f : X β Y} : IsSeparatedMap f β
β xβ xβ, f xβ = f xβ β xβ β xβ β Disjoint (π xβ) (π xβ) :=
forallβ_congr fun x x' _ β¦ by simp only [(nhds_basis_opens x).disjoint_iff (nhds_basis_opens x'),
exists_prop, β exists_and_left, and_assoc, and_comm, and_left_comm]
lemma isSeparatedMap_iff_nhds {f : X β Y} : IsSeparatedMap f β
β xβ xβ, f xβ = f xβ β xβ β xβ β β sβ β π xβ, β sβ β π xβ, Disjoint sβ sβ := by
simp_rw [isSeparatedMap_iff_disjoint_nhds, Filter.disjoint_iff]
open Set Filter in
theorem isSeparatedMap_iff_isClosed_diagonal {f : X β Y} :
IsSeparatedMap f β IsClosed f.pullbackDiagonal := by
simp_rw [isSeparatedMap_iff_nhds, β isOpen_compl_iff, isOpen_iff_mem_nhds,
Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq]
refine forallβ_congr fun xβ xβ _ _ β¦ β¨fun h β¦ ?_, fun β¨t, ht, t_subβ© β¦ ?_β©
Β· simp_rw [β Filter.disjoint_iff, β compl_diagonal_mem_prod] at h
exact β¨_, h, subset_rflβ©
Β· obtain β¨sβ, hβ, sβ, hβ, s_subβ© := mem_prod_iff.mp ht
exact β¨sβ, hβ, sβ, hβ, disjoint_left.2 fun x hβ hβ β¦ @t_sub β¨(x, x), rflβ© (s_sub β¨hβ, hββ©) rflβ©
theorem isSeparatedMap_iff_isClosedEmbedding {f : X β Y} :
IsSeparatedMap f β IsClosedEmbedding (toPullbackDiag f) := by
rw [isSeparatedMap_iff_isClosed_diagonal, β range_toPullbackDiag]
exact β¨fun h β¦ β¨.toPullbackDiag f, hβ©, fun h β¦ h.isClosed_rangeβ©
theorem isSeparatedMap_iff_isClosedMap {f : X β Y} :
IsSeparatedMap f β IsClosedMap (toPullbackDiag f) :=
isSeparatedMap_iff_isClosedEmbedding.trans
β¨IsClosedEmbedding.isClosedMap, .of_continuous_injective_isClosedMap
(IsEmbedding.toPullbackDiag f).continuous (injective_toPullbackDiag f)β©
open Function.Pullback in
theorem IsSeparatedMap.pullback {f : X β Y} (sep : IsSeparatedMap f) (g : A β Y) :
IsSeparatedMap (@snd X Y A f g) := by
rw [isSeparatedMap_iff_isClosed_diagonal] at sep β’
rw [β preimage_map_fst_pullbackDiagonal]
refine sep.preimage (Continuous.mapPullback ?_ ?_) <;>
apply_rules [continuous_fst, continuous_subtype_val, Continuous.comp]
theorem IsSeparatedMap.comp_left {A} {f : X β Y} (sep : IsSeparatedMap f) {g : Y β A}
(inj : g.Injective) : IsSeparatedMap (g β f) := fun xβ xβ he β¦ sep xβ xβ (inj he)
theorem IsSeparatedMap.comp_right {f : X β Y} (sep : IsSeparatedMap f) {g : A β X}
(cont : Continuous g) (inj : g.Injective) : IsSeparatedMap (f β g) := by
rw [isSeparatedMap_iff_isClosed_diagonal] at sep β’
rw [β inj.preimage_pullbackDiagonal]
exact sep.preimage (cont.mapPullback cont)
/-- A function from a topological space `X` is locally injective if every point of `X`
has a neighborhood on which `f` is injective. -/
def IsLocallyInjective (f : X β Y) : Prop := β x : X, β U, IsOpen U β§ x β U β§ U.InjOn f
lemma Function.Injective.IsLocallyInjective {f : X β Y} (inj : f.Injective) :
IsLocallyInjective f := fun _ β¦ β¨_, isOpen_univ, trivial, fun _ _ _ _ β¦ @inj _ _β©
lemma isLocallyInjective_iff_nhds {f : X β Y} :
IsLocallyInjective f β β x : X, β U β π x, U.InjOn f := by
constructor <;> intro h x
Β· obtain β¨U, ho, hm, hiβ© := h x; exact β¨U, ho.mem_nhds hm, hiβ©
Β· obtain β¨U, hn, hiβ© := h x
exact β¨interior U, isOpen_interior, mem_interior_iff_mem_nhds.mpr hn, hi.mono interior_subsetβ©
theorem isLocallyInjective_iff_isOpen_diagonal {f : X β Y} :
IsLocallyInjective f β IsOpen f.pullbackDiagonal := by
simp_rw [isLocallyInjective_iff_nhds, isOpen_iff_mem_nhds,
Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq, Filter.mem_comap]
refine β¨?_, fun h x β¦ ?_β©
Β· rintro h x x' hx (rfl : x = x')
obtain β¨U, hn, hiβ© := h x
exact β¨_, Filter.prod_mem_prod hn hn, fun {p} hp β¦ hi hp.1 hp.2 p.2β©
Β· obtain β¨t, ht, t_subβ© := h x x rfl rfl
| obtain β¨tβ, hβ, tβ, hβ, prod_subβ© := Filter.mem_prod_iff.mp ht
exact β¨tβ β© tβ, Filter.inter_mem hβ hβ,
fun xβ hβ xβ hβ he β¦ @t_sub β¨(xβ, xβ), heβ© (prod_sub β¨hβ.1, hβ.2β©)β©
| Mathlib/Topology/SeparatedMap.lean | 144 | 147 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import Mathlib.Data.Finset.Sym
import Mathlib.LinearAlgebra.BilinearMap
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
import Mathlib.LinearAlgebra.Matrix.Symmetric
/-!
# Quadratic maps
This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`.
An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M β N` such
that:
* `QuadraticMap.map_smul`: `Q (a β’ x) = (a * a) β’ Q x`
* `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`,
`QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`:
the map `QuadraticMap.polar Q := fun x y β¦ Q (x + y) - Q x - Q y` is bilinear.
This notion generalizes to commutative semirings using the approach in [izhakian2016][] which
requires that there be a (possibly non-unique) companion bilinear map `B` such that
`β x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`.
To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`.
Quadratic maps come with a scalar multiplication, `(a β’ Q) x = a β’ Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `QuadraticMap.ofPolar`: a more familiar constructor that works on rings
* `QuadraticMap.associated`: associated bilinear map
* `QuadraticMap.PosDef`: positive definite quadratic maps
* `QuadraticMap.Anisotropic`: anisotropic quadratic maps
* `QuadraticMap.discr`: discriminant of a quadratic map
* `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map.
## Main statements
* `QuadraticMap.associated_left_inverse`,
* `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic maps and symmetric
bilinear forms
* `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear map `B`.
## Notation
In this file, the variable `R` is used when a `CommSemiring` structure is available.
The variable `S` is used when `R` itself has a `β’` action.
## Implementation notes
While the definition and many results make sense if we drop commutativity assumptions,
the correct definition of a quadratic maps in the noncommutative setting would require
substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some
suitable conjugation $r^*$.
The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867)
has some further discussion.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic map, homogeneous polynomial, quadratic polynomial
-/
universe u v w
variable {S T : Type*}
variable {R : Type*} {M N P A : Type*}
open LinearMap (BilinMap BilinForm)
section Polar
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
namespace QuadraticMap
/-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`.
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M β N) (x y : M) :=
f (x + y) - f x - f y
protected theorem map_add (f : M β N) (x y : M) :
f (x + y) = f x + f y + polar f x y := by
rw [polar]
abel
theorem polar_add (f g : M β N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by
simp only [polar, Pi.add_apply]
abel
theorem polar_neg (f : M β N) (x y : M) : polar (-f) x y = -polar f x y := by
simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add]
theorem polar_smul [Monoid S] [DistribMulAction S N] (f : M β N) (s : S) (x y : M) :
polar (s β’ f) x y = s β’ polar f x y := by simp only [polar, Pi.smul_apply, smul_sub]
theorem polar_comm (f : M β N) (x y : M) : polar f x y = polar f y x := by
rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)]
/-- Auxiliary lemma to express bilinearity of `QuadraticMap.polar` without subtraction. -/
theorem polar_add_left_iff {f : M β N} {x x' y : M} :
polar f (x + x') y = polar f x y + polar f x' y β
f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by
simp only [β add_assoc]
simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub]
simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)]
rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)),
add_right_comm (f (x + y)), add_left_inj]
theorem polar_comp {F : Type*} [AddCommGroup S] [FunLike F N S] [AddMonoidHomClass F N S]
(f : M β N) (g : F) (x y : M) :
polar (g β f) x y = g (polar f x y) := by
simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub]
/-- `QuadraticMap.polar` as a function from `Sym2`. -/
def polarSym2 (f : M β N) : Sym2 M β N :=
Sym2.lift β¨polar f, polar_comm _β©
@[simp]
lemma polarSym2_sym2Mk (f : M β N) (xy : M Γ M) : polarSym2 f (.mk xy) = polar f xy.1 xy.2 := rfl
end QuadraticMap
end Polar
/-- A quadratic map on a module.
For a more familiar constructor when `R` is a ring, see `QuadraticMap.ofPolar`. -/
structure QuadraticMap (R : Type u) (M : Type v) (N : Type w) [CommSemiring R] [AddCommMonoid M]
[Module R M] [AddCommMonoid N] [Module R N] where
toFun : M β N
toFun_smul : β (a : R) (x : M), toFun (a β’ x) = (a * a) β’ toFun x
exists_companion' : β B : BilinMap R M N, β x y, toFun (x + y) = toFun x + toFun y + B x y
section QuadraticForm
variable (R : Type u) (M : Type v) [CommSemiring R] [AddCommMonoid M] [Module R M]
/-- A quadratic form on a module. -/
abbrev QuadraticForm : Type _ := QuadraticMap R M R
end QuadraticForm
namespace QuadraticMap
section DFunLike
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable {Q Q' : QuadraticMap R M N}
instance instFunLike : FunLike (QuadraticMap R M N) M N where
coe := toFun
coe_injective' x y h := by cases x; cases y; congr
variable (Q)
/-- The `simp` normal form for a quadratic map is `DFunLike.coe`, not `toFun`. -/
@[simp]
theorem toFun_eq_coe : Q.toFun = βQ :=
rfl
-- this must come after the coe_to_fun definition
initialize_simps_projections QuadraticMap (toFun β apply)
variable {Q}
@[ext]
theorem ext (H : β x : M, Q x = Q' x) : Q = Q' :=
DFunLike.ext _ _ H
theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x :=
DFunLike.congr_fun h _
/-- Copy of a `QuadraticMap` with a new `toFun` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (Q : QuadraticMap R M N) (Q' : M β N) (h : Q' = βQ) : QuadraticMap R M N where
toFun := Q'
toFun_smul := h.symm βΈ Q.toFun_smul
exists_companion' := h.symm βΈ Q.exists_companion'
@[simp]
theorem coe_copy (Q : QuadraticMap R M N) (Q' : M β N) (h : Q' = βQ) : β(Q.copy Q' h) = Q' :=
rfl
theorem copy_eq (Q : QuadraticMap R M N) (Q' : M β N) (h : Q' = βQ) : Q.copy Q' h = Q :=
DFunLike.ext' h
end DFunLike
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N]
variable (Q : QuadraticMap R M N)
protected theorem map_smul (a : R) (x : M) : Q (a β’ x) = (a * a) β’ Q x :=
Q.toFun_smul a x
theorem exists_companion : β B : BilinMap R M N, β x y, Q (x + y) = Q x + Q y + B x y :=
Q.exists_companion'
theorem map_add_add_add_map (x y z : M) :
Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by
obtain β¨B, hβ© := Q.exists_companion
rw [add_comm z x]
simp only [h, LinearMap.map_addβ]
abel
theorem map_add_self (x : M) : Q (x + x) = 4 β’ Q x := by
rw [β two_smul R x, Q.map_smul, β Nat.cast_smul_eq_nsmul R]
norm_num
-- not @[simp] because it is superseded by `ZeroHomClass.map_zero`
protected theorem map_zero : Q 0 = 0 := by
rw [β @zero_smul R _ _ _ _ (0 : M), Q.map_smul, zero_mul, zero_smul]
instance zeroHomClass : ZeroHomClass (QuadraticMap R M N) M N :=
{ QuadraticMap.instFunLike (R := R) (M := M) (N := N) with map_zero := QuadraticMap.map_zero }
theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [SMul S M] [IsScalarTower S R M]
[Module S N] [IsScalarTower S R N] (a : S)
(x : M) : Q (a β’ x) = (a * a) β’ Q x := by
rw [β IsScalarTower.algebraMap_smul R a x, Q.map_smul, β RingHom.map_mul, algebraMap_smul]
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M] [AddCommGroup N]
variable [Module R M] [Module R N] (Q : QuadraticMap R M N)
@[simp]
protected theorem map_neg (x : M) : Q (-x) = Q x := by
rw [β @neg_one_smul R _ _ _ _ x, Q.map_smul, neg_one_mul, neg_neg, one_smul]
protected theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [β neg_sub, Q.map_neg]
@[simp]
theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by
simp only [polar, zero_add, QuadraticMap.map_zero, sub_zero, sub_self]
@[simp]
theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y :=
polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y
@[simp]
theorem polar_smul_left (a : R) (x y : M) : polar Q (a β’ x) y = a β’ polar Q x y := by
obtain β¨B, hβ© := Q.exists_companion
simp_rw [polar, h, Q.map_smul, LinearMap.map_smulβ, sub_sub, add_sub_cancel_left]
@[simp]
theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by
rw [β neg_one_smul R x, polar_smul_left, neg_one_smul]
@[simp]
theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
@[simp]
theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by
simp only [add_zero, polar, QuadraticMap.map_zero, sub_self]
@[simp]
theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by
rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left]
@[simp]
theorem polar_smul_right (a : R) (x y : M) : polar Q x (a β’ y) = a β’ polar Q x y := by
rw [polar_comm Q x, polar_comm Q x, polar_smul_left]
@[simp]
theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by
rw [β neg_one_smul R y, polar_smul_right, neg_one_smul]
@[simp]
theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by
rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right]
@[simp]
theorem polar_self (x : M) : polar Q x x = 2 β’ Q x := by
rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, β two_smul β, β two_smul β, β mul_smul]
norm_num
/-- `QuadraticMap.polar` as a bilinear map -/
@[simps!]
def polarBilin : BilinMap R M N :=
LinearMap.mkβ R (polar Q) (polar_add_left Q) (polar_smul_left Q) (polar_add_right Q)
(polar_smul_right Q)
lemma polarSym2_map_smul {ΞΉ} (Q : QuadraticMap R M N) (g : ΞΉ β M) (l : ΞΉ β R) (p : Sym2 ΞΉ) :
polarSym2 Q (p.map (l β’ g)) = (p.map l).mul β’ polarSym2 Q (p.map g) := by
obtain β¨_, _β© := p; simp [β smul_assoc, mul_comm]
variable [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] [Module S N]
[IsScalarTower S R N]
@[simp]
theorem polar_smul_left_of_tower (a : S) (x y : M) : polar Q (a β’ x) y = a β’ polar Q x y := by
rw [β IsScalarTower.algebraMap_smul R a x, polar_smul_left, algebraMap_smul]
| @[simp]
theorem polar_smul_right_of_tower (a : S) (x y : M) : polar Q x (a β’ y) = a β’ polar Q x y := by
rw [β IsScalarTower.algebraMap_smul R a y, polar_smul_right, algebraMap_smul]
| Mathlib/LinearAlgebra/QuadraticForm/Basic.lean | 316 | 318 |
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Logic.IsEmpty
import Mathlib.Tactic.Inhabit
/-!
# Types with a unique term
In this file we define a typeclass `Unique`,
which expresses that a type has a unique term.
In other words, a type that is `Inhabited` and a `Subsingleton`.
## Main declaration
* `Unique`: a typeclass that expresses that a type has a unique term.
## Main statements
* `Unique.mk'`: an inhabited subsingleton type is `Unique`. This can not be an instance because it
would lead to loops in typeclass inference.
* `Function.Surjective.unique`: if the domain of a surjective function is `Unique`, then its
codomain is `Unique` as well.
* `Function.Injective.subsingleton`: if the codomain of an injective function is `Subsingleton`,
then its domain is `Subsingleton` as well.
* `Function.Injective.unique`: if the codomain of an injective function is `Subsingleton` and its
domain is `Inhabited`, then its domain is `Unique`.
## Implementation details
The typeclass `Unique Ξ±` is implemented as a type,
rather than a `Prop`-valued predicate,
for good definitional properties of the default term.
-/
universe u v w
-- Don't generate injectivity lemmas, which the `simpNF` linter will complain about.
set_option genInjectivity false in
/-- `Unique Ξ±` expresses that `Ξ±` is a type with a unique term `default`.
This is implemented as a type, rather than a `Prop`-valued predicate,
for good definitional properties of the default term. -/
@[ext]
structure Unique (Ξ± : Sort u) extends Inhabited Ξ± where
/-- In a `Unique` type, every term is equal to the default element (from `Inhabited`). -/
uniq : β a : Ξ±, a = default
attribute [class] Unique
theorem unique_iff_existsUnique (Ξ± : Sort u) : Nonempty (Unique Ξ±) β β! _ : Ξ±, True :=
β¨fun β¨uβ© β¦ β¨u.default, trivial, fun a _ β¦ u.uniq aβ©,
fun β¨a, _, hβ© β¦ β¨β¨β¨aβ©, fun _ β¦ h _ trivialβ©β©β©
@[deprecated (since := "2024-12-17")] alias unique_iff_exists_unique := unique_iff_existsUnique
theorem unique_subtype_iff_existsUnique {Ξ±} (p : Ξ± β Prop) :
Nonempty (Unique (Subtype p)) β β! a, p a :=
β¨fun β¨uβ© β¦ β¨u.default.1, u.default.2, fun a h β¦ congr_arg Subtype.val (u.uniq β¨a, hβ©)β©,
fun β¨a, ha, heβ© β¦ β¨β¨β¨β¨a, haβ©β©, fun β¨b, hbβ© β¦ by
congr
exact he b hbβ©β©β©
@[deprecated (since := "2024-12-17")]
alias unique_subtype_iff_exists_unique := unique_subtype_iff_existsUnique
/-- Given an explicit `a : Ξ±` with `Subsingleton Ξ±`, we can construct
a `Unique Ξ±` instance. This is a def because the typeclass search cannot
arbitrarily invent the `a : Ξ±` term. Nevertheless, these instances are all
equivalent by `Unique.Subsingleton.unique`.
See note [reducible non-instances]. -/
abbrev uniqueOfSubsingleton {Ξ± : Sort*} [Subsingleton Ξ±] (a : Ξ±) : Unique Ξ± where
default := a
uniq _ := Subsingleton.elim _ _
instance PUnit.instUnique : Unique PUnit.{u} where
default := PUnit.unit
uniq x := subsingleton x _
@[simp]
theorem PUnit.default_eq_unit : (default : PUnit) = PUnit.unit :=
rfl
/-- Every provable proposition is unique, as all proofs are equal. -/
def uniqueProp {p : Prop} (h : p) : Unique.{0} p where
default := h
uniq _ := rfl
instance : Unique True :=
uniqueProp trivial
namespace Unique
open Function
section
variable {Ξ± : Sort*} [Unique Ξ±]
-- see Note [lower instance priority]
instance (priority := 100) : Inhabited Ξ± :=
toInhabited βΉUnique Ξ±βΊ
theorem eq_default (a : Ξ±) : a = default :=
uniq _ a
theorem default_eq (a : Ξ±) : default = a :=
(uniq _ a).symm
-- see Note [lower instance priority]
instance (priority := 100) instSubsingleton : Subsingleton Ξ± :=
subsingleton_of_forall_eq _ eq_default
theorem forall_iff {p : Ξ± β Prop} : (β a, p a) β p default :=
β¨fun h β¦ h _, fun h x β¦ by rwa [Unique.eq_default x]β©
theorem exists_iff {p : Ξ± β Prop} : Exists p β p default :=
β¨fun β¨a, haβ© β¦ eq_default a βΈ ha, Exists.intro defaultβ©
end
variable {Ξ± : Sort*}
@[ext]
protected theorem subsingleton_unique' : β hβ hβ : Unique Ξ±, hβ = hβ
| β¨β¨xβ©, hβ©, β¨β¨yβ©, _β© => by congr; rw [h x, h y]
instance subsingleton_unique : Subsingleton (Unique Ξ±) :=
β¨Unique.subsingleton_unique'β©
/-- Construct `Unique` from `Inhabited` and `Subsingleton`. Making this an instance would create
a loop in the class inheritance graph. -/
abbrev mk' (Ξ± : Sort u) [hβ : Inhabited Ξ±] [Subsingleton Ξ±] : Unique Ξ± :=
{ hβ with uniq := fun _ β¦ Subsingleton.elim _ _ }
end Unique
theorem nonempty_unique (Ξ± : Sort u) [Subsingleton Ξ±] [Nonempty Ξ±] : Nonempty (Unique Ξ±) := by
inhabit Ξ±
exact β¨Unique.mk' Ξ±β©
theorem unique_iff_subsingleton_and_nonempty (Ξ± : Sort u) :
Nonempty (Unique Ξ±) β Subsingleton Ξ± β§ Nonempty Ξ± :=
β¨fun β¨uβ© β¦ by constructor <;> exact inferInstance,
fun β¨hs, hnβ© β¦ nonempty_unique Ξ±β©
variable {Ξ± : Sort*}
@[simp]
theorem Pi.default_def {Ξ² : Ξ± β Sort v} [β a, Inhabited (Ξ² a)] :
@default (β a, Ξ² a) _ = fun a : Ξ± β¦ @default (Ξ² a) _ :=
rfl
theorem Pi.default_apply {Ξ² : Ξ± β Sort v} [β a, Inhabited (Ξ² a)] (a : Ξ±) :
@default (β a, Ξ² a) _ a = default :=
rfl
instance Pi.unique {Ξ² : Ξ± β Sort v} [β a, Unique (Ξ² a)] : Unique (β a, Ξ² a) where
uniq := fun _ β¦ funext fun _ β¦ Unique.eq_default _
/-- There is a unique function on an empty domain. -/
instance Pi.uniqueOfIsEmpty [IsEmpty Ξ±] (Ξ² : Ξ± β Sort v) : Unique (β a, Ξ² a) where
default := isEmptyElim
uniq _ := funext isEmptyElim
theorem eq_const_of_subsingleton {Ξ² : Sort*} [Subsingleton Ξ±] (f : Ξ± β Ξ²) (a : Ξ±) :
f = Function.const Ξ± (f a) :=
funext fun x β¦ Subsingleton.elim x a βΈ rfl
theorem eq_const_of_unique {Ξ² : Sort*} [Unique Ξ±] (f : Ξ± β Ξ²) : f = Function.const Ξ± (f default) :=
eq_const_of_subsingleton ..
theorem heq_const_of_unique [Unique Ξ±] {Ξ² : Ξ± β Sort v} (f : β a, Ξ² a) :
HEq f (Function.const Ξ± (f default)) :=
(Function.hfunext rfl) fun i _ _ β¦ by rw [Subsingleton.elim i default]; rfl
namespace Function
variable {Ξ² : Sort*} {f : Ξ± β Ξ²}
/-- If the codomain of an injective function is a subsingleton, then the domain
is a subsingleton as well. -/
protected theorem Injective.subsingleton (hf : Injective f) [Subsingleton Ξ²] : Subsingleton Ξ± :=
β¨fun _ _ β¦ hf <| Subsingleton.elim _ _β©
/-- If the domain of a surjective function is a subsingleton, then the codomain is a subsingleton as
well. -/
protected theorem Surjective.subsingleton [Subsingleton Ξ±] (hf : Surjective f) : Subsingleton Ξ² :=
| β¨hf.forallβ.2 fun x y β¦ congr_arg f <| Subsingleton.elim x yβ©
/-- If the domain of a surjective function is a singleton,
| Mathlib/Logic/Unique.lean | 196 | 198 |
/-
Copyright (c) 2021 RΓ©my Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: RΓ©my Degenne
-/
import Mathlib.Probability.Independence.Basic
import Mathlib.Probability.Independence.Conditional
/-!
# Kolmogorov's 0-1 law
Let `s : ΞΉ β MeasurableSpace Ξ©` be an independent sequence of sub-Ο-algebras. Then any set which
is measurable with respect to the tail Ο-algebra `limsup s atTop` has probability 0 or 1.
## Main statements
* `measure_zero_or_one_of_measurableSet_limsup_atTop`: Kolmogorov's 0-1 law. Any set which is
measurable with respect to the tail Ο-algebra `limsup s atTop` of an independent sequence of
Ο-algebras `s` has probability 0 or 1.
-/
open MeasureTheory MeasurableSpace
open scoped MeasureTheory ENNReal
namespace ProbabilityTheory
variable {Ξ± Ξ© ΞΉ : Type*} {_mΞ± : MeasurableSpace Ξ±} {s : ΞΉ β MeasurableSpace Ξ©}
{m m0 : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌΞ± : Measure Ξ±} {ΞΌ : Measure Ξ©}
theorem Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ξ©}
(h_indep : Kernel.IndepSet t t ΞΊ ΞΌΞ±) :
βα΅ a βΞΌΞ±, ΞΊ a t = 0 β¨ ΞΊ a t = 1 β¨ ΞΊ a t = β := by
specialize h_indep t t (measurableSet_generateFrom (Set.mem_singleton t))
(measurableSet_generateFrom (Set.mem_singleton t))
filter_upwards [h_indep] with a ha
by_cases h0 : ΞΊ a t = 0
Β· exact Or.inl h0
by_cases h_top : ΞΊ a t = β
Β· exact Or.inr (Or.inr h_top)
rw [β one_mul (ΞΊ a (t β© t)), Set.inter_self, ENNReal.mul_left_inj h0 h_top] at ha
exact Or.inr (Or.inl ha.symm)
theorem measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ξ©}
(h_indep : IndepSet t t ΞΌ) : ΞΌ t = 0 β¨ ΞΌ t = 1 β¨ ΞΌ t = β := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self h_indep
theorem Kernel.measure_eq_zero_or_one_of_indepSet_self' (h : βα΅ a βΞΌΞ±, IsFiniteMeasure (ΞΊ a))
{t : Set Ξ©} (h_indep : IndepSet t t ΞΊ ΞΌΞ±) :
βα΅ a βΞΌΞ±, ΞΊ a t = 0 β¨ ΞΊ a t = 1 := by
filter_upwards [measure_eq_zero_or_one_or_top_of_indepSet_self h_indep, h] with a h_0_1_top h'
simpa only [measure_ne_top (ΞΊ a), or_false] using h_0_1_top
theorem Kernel.measure_eq_zero_or_one_of_indepSet_self [h : β a, IsFiniteMeasure (ΞΊ a)] {t : Set Ξ©}
(h_indep : IndepSet t t ΞΊ ΞΌΞ±) :
βα΅ a βΞΌΞ±, ΞΊ a t = 0 β¨ ΞΊ a t = 1 :=
Kernel.measure_eq_zero_or_one_of_indepSet_self' (ae_of_all ΞΌΞ± h) h_indep
theorem measure_eq_zero_or_one_of_indepSet_self [IsFiniteMeasure ΞΌ] {t : Set Ξ©}
(h_indep : IndepSet t t ΞΌ) : ΞΌ t = 0 β¨ ΞΌ t = 1 := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep
theorem condExp_eq_zero_or_one_of_condIndepSet_self
[StandardBorelSpace Ξ©]
(hm : m β€ m0) [hΞΌ : IsFiniteMeasure ΞΌ] {t : Set Ξ©} (ht : MeasurableSet t)
(h_indep : CondIndepSet m hm t t ΞΌ) :
βα΅ Ο βΞΌ, (ΞΌβ¦t | mβ§) Ο = 0 β¨ (ΞΌβ¦t | mβ§) Ο = 1 := by
-- TODO: Why is not inferred?
have (a) : IsFiniteMeasure (condExpKernel ΞΌ m a) := inferInstance
have h := ae_of_ae_trim hm (Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep)
filter_upwards [condExpKernel_ae_eq_condExp hm ht, h] with Ο hΟ_eq hΟ
rwa [β hΟ_eq, measureReal_eq_zero_iff, measureReal_def, ENNReal.toReal_eq_one_iff]
@[deprecated (since := "2025-01-21")]
alias condexp_eq_zero_or_one_of_condIndepSet_self := condExp_eq_zero_or_one_of_condIndepSet_self
open Filter
theorem Kernel.indep_biSup_compl (h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±) (t : Set ΞΉ) :
Indep (β¨ n β t, s n) (β¨ n β tαΆ, s n) ΞΊ ΞΌΞ± :=
indep_iSup_of_disjoint h_le h_indep disjoint_compl_right
theorem indep_biSup_compl (h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΌ) (t : Set ΞΉ) :
Indep (β¨ n β t, s n) (β¨ n β tαΆ, s n) ΞΌ :=
Kernel.indep_biSup_compl h_le h_indep t
theorem condIndep_biSup_compl [StandardBorelSpace Ξ©]
(hm : m β€ m0) [IsFiniteMeasure ΞΌ]
(h_le : β n, s n β€ m0) (h_indep : iCondIndep m hm s ΞΌ) (t : Set ΞΉ) :
CondIndep m (β¨ n β t, s n) (β¨ n β tαΆ, s n) hm ΞΌ :=
Kernel.indep_biSup_compl h_le h_indep t
section Abstract
variable {Ξ² : Type*} {p : Set ΞΉ β Prop} {f : Filter ΞΉ} {ns : Ξ² β Set ΞΉ}
/-! We prove a version of Kolmogorov's 0-1 law for the Ο-algebra `limsup s f` where `f` is a filter
for which we can define the following two functions:
* `p : Set ΞΉ β Prop` such that for a set `t`, `p t β tαΆ β f`,
* `ns : Ξ± β Set ΞΉ` a directed sequence of sets which all verify `p` and such that
`β a, ns a = Set.univ`.
For the example of `f = atTop`, we can take
`p = bddAbove` and `ns : ΞΉ β Set ΞΉ := fun i => Set.Iic i`.
-/
theorem Kernel.indep_biSup_limsup (h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±)
(hf : β t, p t β tαΆ β f) {t : Set ΞΉ} (ht : p t) :
Indep (β¨ n β t, s n) (limsup s f) ΞΊ ΞΌΞ± := by
refine indep_of_indep_of_le_right (indep_biSup_compl h_le h_indep t) ?_
refine limsSup_le_of_le (by isBoundedDefault) ?_
simp only [Set.mem_compl_iff, eventually_map]
exact eventually_of_mem (hf t ht) le_iSupβ
theorem indep_biSup_limsup
(h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΌ) (hf : β t, p t β tαΆ β f)
{t : Set ΞΉ} (ht : p t) :
Indep (β¨ n β t, s n) (limsup s f) ΞΌ :=
Kernel.indep_biSup_limsup h_le h_indep hf ht
theorem condIndep_biSup_limsup [StandardBorelSpace Ξ©]
(hm : m β€ m0) [IsFiniteMeasure ΞΌ]
(h_le : β n, s n β€ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : β t, p t β tαΆ β f)
{t : Set ΞΉ} (ht : p t) :
CondIndep m (β¨ n β t, s n) (limsup s f) hm ΞΌ :=
Kernel.indep_biSup_limsup h_le h_indep hf ht
theorem Kernel.indep_iSup_directed_limsup (h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±)
(hf : β t, p t β tαΆ β f) (hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) :
Indep (β¨ a, β¨ n β ns a, s n) (limsup s f) ΞΊ ΞΌΞ± := by
rcases eq_or_ne ΞΌΞ± 0 with rfl | hΞΌ
Β· simp
obtain β¨Ξ·, Ξ·_eq, hΞ·β© : β (Ξ· : Kernel Ξ± Ξ©), ΞΊ =α΅[ΞΌΞ±] Ξ· β§ IsMarkovKernel Ξ· :=
exists_ae_eq_isMarkovKernel h_indep.ae_isProbabilityMeasure hΞΌ
replace h_indep := h_indep.congr Ξ·_eq
apply Indep.congr (Filter.EventuallyEq.symm Ξ·_eq)
apply indep_iSup_of_directed_le
Β· exact fun a => indep_biSup_limsup h_le h_indep hf (hnsp a)
Β· exact fun a => iSupβ_le fun n _ => h_le n
Β· exact limsup_le_iSup.trans (iSup_le h_le)
Β· intro a b
obtain β¨c, hcβ© := hns a b
refine β¨c, ?_, ?_β© <;> refine iSup_mono fun n => iSup_mono' fun hn => β¨?_, le_rflβ©
Β· exact hc.1 hn
Β· exact hc.2 hn
theorem indep_iSup_directed_limsup
(h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΌ)
(hf : β t, p t β tαΆ β f) (hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) :
Indep (β¨ a, β¨ n β ns a, s n) (limsup s f) ΞΌ :=
Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp
theorem condIndep_iSup_directed_limsup [StandardBorelSpace Ξ©]
(hm : m β€ m0) [IsFiniteMeasure ΞΌ]
(h_le : β n, s n β€ m0) (h_indep : iCondIndep m hm s ΞΌ)
(hf : β t, p t β tαΆ β f) (hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) :
CondIndep m (β¨ a, β¨ n β ns a, s n) (limsup s f) hm ΞΌ :=
Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp
theorem Kernel.indep_iSup_limsup (h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±)
(hf : β t, p t β tαΆ β f)
(hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) (hns_univ : β n, β a, n β ns a) :
Indep (β¨ n, s n) (limsup s f) ΞΊ ΞΌΞ± := by
suffices (β¨ a, β¨ n β ns a, s n) = β¨ n, s n by
rw [β this]
exact indep_iSup_directed_limsup h_le h_indep hf hns hnsp
rw [iSup_comm]
refine iSup_congr fun n => ?_
have h : β¨ (i : Ξ²) (_ : n β ns i), s n = β¨ _ : β i, n β ns i, s n := by rw [iSup_exists]
haveI : Nonempty (β i : Ξ², n β ns i) := β¨hns_univ nβ©
rw [h, iSup_const]
theorem indep_iSup_limsup
(h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΌ) (hf : β t, p t β tαΆ β f)
(hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) (hns_univ : β n, β a, n β ns a) :
Indep (β¨ n, s n) (limsup s f) ΞΌ :=
Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ
theorem condIndep_iSup_limsup [StandardBorelSpace Ξ©]
(hm : m β€ m0) [IsFiniteMeasure ΞΌ]
(h_le : β n, s n β€ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : β t, p t β tαΆ β f)
(hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) (hns_univ : β n, β a, n β ns a) :
CondIndep m (β¨ n, s n) (limsup s f) hm ΞΌ :=
Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ
theorem Kernel.indep_limsup_self (h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±)
(hf : β t, p t β tαΆ β f)
(hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) (hns_univ : β n, β a, n β ns a) :
Indep (limsup s f) (limsup s f) ΞΊ ΞΌΞ± :=
indep_of_indep_of_le_left (indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ) limsup_le_iSup
theorem indep_limsup_self
(h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΌ) (hf : β t, p t β tαΆ β f)
(hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) (hns_univ : β n, β a, n β ns a) :
Indep (limsup s f) (limsup s f) ΞΌ :=
Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ
theorem condIndep_limsup_self [StandardBorelSpace Ξ©]
(hm : m β€ m0) [IsFiniteMeasure ΞΌ]
(h_le : β n, s n β€ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : β t, p t β tαΆ β f)
(hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a)) (hns_univ : β n, β a, n β ns a) :
CondIndep m (limsup s f) (limsup s f) hm ΞΌ :=
Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ
theorem Kernel.measure_zero_or_one_of_measurableSet_limsup (h_le : β n, s n β€ m0)
(h_indep : iIndep s ΞΊ ΞΌΞ±)
(hf : β t, p t β tαΆ β f) (hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a))
(hns_univ : β n, β a, n β ns a) {t : Set Ξ©} (ht_tail : MeasurableSet[limsup s f] t) :
βα΅ a βΞΌΞ±, ΞΊ a t = 0 β¨ ΞΊ a t = 1 := by
apply measure_eq_zero_or_one_of_indepSet_self' ?_
((indep_limsup_self h_le h_indep hf hns hnsp hns_univ).indepSet_of_measurableSet ht_tail
ht_tail)
filter_upwards [h_indep.ae_isProbabilityMeasure] with a ha using by infer_instance
theorem measure_zero_or_one_of_measurableSet_limsup
(h_le : β n, s n β€ m0) (h_indep : iIndep s ΞΌ)
| (hf : β t, p t β tαΆ β f) (hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a))
(hns_univ : β n, β a, n β ns a) {t : Set Ξ©} (ht_tail : MeasurableSet[limsup s f] t) :
ΞΌ t = 0 β¨ ΞΌ t = 1 := by
simpa only [ae_dirac_eq, Filter.eventually_pure]
using Kernel.measure_zero_or_one_of_measurableSet_limsup h_le h_indep hf hns hnsp hns_univ
ht_tail
theorem condExp_zero_or_one_of_measurableSet_limsup [StandardBorelSpace Ξ©]
(hm : m β€ m0) [IsFiniteMeasure ΞΌ]
(h_le : β n, s n β€ m0) (h_indep : iCondIndep m hm s ΞΌ)
(hf : β t, p t β tαΆ β f) (hns : Directed (Β· β€ Β·) ns) (hnsp : β a, p (ns a))
(hns_univ : β n, β a, n β ns a) {t : Set Ξ©} (ht_tail : MeasurableSet[limsup s f] t) :
βα΅ Ο βΞΌ, (ΞΌβ¦t | mβ§) Ο = 0 β¨ (ΞΌβ¦t | mβ§) Ο = 1 := by
have h := ae_of_ae_trim hm
| Mathlib/Probability/Independence/ZeroOne.lean | 219 | 232 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Chris Hughes, Floris van Doorn, YaΓ«l Dillies
-/
import Mathlib.Data.Nat.Basic
import Mathlib.Tactic.GCongr.CoreAttrs
import Mathlib.Tactic.Common
import Mathlib.Tactic.Monotonicity.Attr
/-!
# Factorial and variants
This file defines the factorial, along with the ascending and descending variants.
For the proof that the factorial of `n` counts the permutations of an `n`-element set,
see `Fintype.card_perm`.
## Main declarations
* `Nat.factorial`: The factorial.
* `Nat.ascFactorial`: The ascending factorial. It is the product of natural numbers from `n` to
`n + k - 1`.
* `Nat.descFactorial`: The descending factorial. It is the product of natural numbers from
`n - k + 1` to `n`.
-/
namespace Nat
/-- `Nat.factorial n` is the factorial of `n`. -/
def factorial : β β β
| 0 => 1
| succ n => succ n * factorial n
/-- factorial notation `(n)!` for `Nat.factorial n`.
In Lean, names can end with exclamation marks (e.g. `List.get!`), so you cannot write
`n!` in Lean, but must write `(n)!` or `n !` instead. The former is preferred, since
Lean can confuse the `!` in `n !` as the (prefix) boolean negation operation in some
cases.
For numerals the parentheses are not required, so e.g. `0!` or `1!` work fine.
Todo: replace occurrences of `n !` with `(n)!` in Mathlib. -/
scoped notation:10000 n "!" => Nat.factorial n
section Factorial
variable {m n : β}
@[simp] theorem factorial_zero : 0! = 1 :=
rfl
theorem factorial_succ (n : β) : (n + 1)! = (n + 1) * n ! :=
rfl
@[simp] theorem factorial_one : 1! = 1 :=
rfl
@[simp] theorem factorial_two : 2! = 2 :=
rfl
theorem mul_factorial_pred (hn : n β 0) : n * (n - 1)! = n ! :=
Nat.sub_add_cancel (one_le_iff_ne_zero.mpr hn) βΈ rfl
theorem factorial_pos : β n, 0 < n !
| 0 => Nat.zero_lt_one
| succ n => Nat.mul_pos (succ_pos _) (factorial_pos n)
theorem factorial_ne_zero (n : β) : n ! β 0 :=
ne_of_gt (factorial_pos _)
theorem factorial_dvd_factorial {m n} (h : m β€ n) : m ! β£ n ! := by
induction h with
| refl => exact Nat.dvd_refl _
| step _ ih => exact Nat.dvd_trans ih (Nat.dvd_mul_left _ _)
theorem dvd_factorial : β {m n}, 0 < m β m β€ n β m β£ n !
| succ _, _, _, h => Nat.dvd_trans (Nat.dvd_mul_right _ _) (factorial_dvd_factorial h)
@[mono, gcongr]
theorem factorial_le {m n} (h : m β€ n) : m ! β€ n ! :=
le_of_dvd (factorial_pos _) (factorial_dvd_factorial h)
theorem factorial_mul_pow_le_factorial : β {m n : β}, m ! * (m + 1) ^ n β€ (m + n)!
| m, 0 => by simp
| m, n + 1 => by
rw [β Nat.add_assoc, factorial_succ, Nat.mul_comm (_ + 1), Nat.pow_succ, β Nat.mul_assoc]
exact Nat.mul_le_mul factorial_mul_pow_le_factorial (succ_le_succ (le_add_right _ _))
theorem factorial_lt (hn : 0 < n) : n ! < m ! β n < m := by
refine β¨fun h => not_le.mp fun hmn => Nat.not_le_of_lt h (factorial_le hmn), fun h => ?_β©
have : β {n}, 0 < n β n ! < (n + 1)! := by
intro k hk
rw [factorial_succ, succ_mul, Nat.lt_add_left_iff_pos]
exact Nat.mul_pos hk k.factorial_pos
induction h generalizing hn with
| refl => exact this hn
| step hnk ih => exact lt_trans (ih hn) <| this <| lt_trans hn <| lt_of_succ_le hnk
@[gcongr]
lemma factorial_lt_of_lt {m n : β} (hn : 0 < n) (h : n < m) : n ! < m ! := (factorial_lt hn).mpr h
@[simp] lemma one_lt_factorial : 1 < n ! β 1 < n := factorial_lt Nat.one_pos
@[simp]
theorem factorial_eq_one : n ! = 1 β n β€ 1 := by
constructor
Β· intro h
rw [β not_lt, β one_lt_factorial, h]
apply lt_irrefl
Β· rintro (_|_|_) <;> rfl
theorem factorial_inj (hn : 1 < n) : n ! = m ! β n = m := by
refine β¨fun h => ?_, congr_arg _β©
obtain hnm | rfl | hnm := lt_trichotomy n m
Β· rw [β factorial_lt <| lt_of_succ_lt hn, h] at hnm
cases lt_irrefl _ hnm
Β· rfl
rw [β one_lt_factorial, h, one_lt_factorial] at hn
rw [β factorial_lt <| lt_of_succ_lt hn, h] at hnm
cases lt_irrefl _ hnm
theorem factorial_inj' (h : 1 < n β¨ 1 < m) : n ! = m ! β n = m := by
obtain hn|hm := h
Β· exact factorial_inj hn
Β· rw [eq_comm, factorial_inj hm, eq_comm]
theorem self_le_factorial : β n : β, n β€ n !
| 0 => Nat.zero_le _
| k + 1 => Nat.le_mul_of_pos_right _ (Nat.one_le_of_lt k.factorial_pos)
theorem lt_factorial_self {n : β} (hi : 3 β€ n) : n < n ! := by
have : 0 < n := by omega
have hn : 1 < pred n := le_pred_of_lt (succ_le_iff.mp hi)
rw [β succ_pred_eq_of_pos βΉ0 < nβΊ, factorial_succ]
exact (Nat.lt_mul_iff_one_lt_right (pred n).succ_pos).2
((Nat.lt_of_lt_of_le hn (self_le_factorial _)))
theorem add_factorial_succ_lt_factorial_add_succ {i : β} (n : β) (hi : 2 β€ i) :
i + (n + 1)! < (i + n + 1)! := by
rw [factorial_succ (i + _), Nat.add_mul, Nat.one_mul]
have := (i + n).self_le_factorial
refine Nat.add_lt_add_of_lt_of_le (Nat.lt_of_le_of_lt ?_ ((Nat.lt_mul_iff_one_lt_right ?_).2 ?_))
(factorial_le ?_) <;> omega
theorem add_factorial_lt_factorial_add {i n : β} (hi : 2 β€ i) (hn : 1 β€ n) :
i + n ! < (i + n)! := by
cases hn
Β· rw [factorial_one]
exact lt_factorial_self (succ_le_succ hi)
exact add_factorial_succ_lt_factorial_add_succ _ hi
theorem add_factorial_succ_le_factorial_add_succ (i : β) (n : β) :
i + (n + 1)! β€ (i + (n + 1))! := by
cases (le_or_lt (2 : β) i)
Β· rw [β Nat.add_assoc]
apply Nat.le_of_lt
apply add_factorial_succ_lt_factorial_add_succ
assumption
Β· match i with
| 0 => simp
| 1 =>
rw [β Nat.add_assoc, factorial_succ (1 + n), Nat.add_mul, Nat.one_mul, Nat.add_comm 1 n,
Nat.add_le_add_iff_right]
exact Nat.mul_pos n.succ_pos n.succ.factorial_pos
| succ (succ n) => contradiction
theorem add_factorial_le_factorial_add (i : β) {n : β} (n1 : 1 β€ n) : i + n ! β€ (i + n)! := by
rcases n1 with - | @h
Β· exact self_le_factorial _
exact add_factorial_succ_le_factorial_add_succ i h
theorem factorial_mul_pow_sub_le_factorial {n m : β} (hnm : n β€ m) : n ! * n ^ (m - n) β€ m ! := by
calc
_ β€ n ! * (n + 1) ^ (m - n) := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _)
_ β€ _ := by simpa [hnm] using @Nat.factorial_mul_pow_le_factorial n (m - n)
lemma factorial_le_pow : β n, n ! β€ n ^ n
| 0 => le_refl _
| n + 1 =>
calc
_ β€ (n + 1) * n ^ n := Nat.mul_le_mul_left _ n.factorial_le_pow
_ β€ (n + 1) * (n + 1) ^ n := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _)
_ = _ := by rw [pow_succ']
end Factorial
/-! ### Ascending and descending factorials -/
section AscFactorial
/-- `n.ascFactorial k = n (n + 1) β― (n + k - 1)`. This is closely related to `ascPochhammer`, but
much less general. -/
def ascFactorial (n : β) : β β β
| 0 => 1
| k + 1 => (n + k) * ascFactorial n k
@[simp]
theorem ascFactorial_zero (n : β) : n.ascFactorial 0 = 1 :=
rfl
theorem ascFactorial_succ {n k : β} : n.ascFactorial k.succ = (n + k) * n.ascFactorial k :=
rfl
theorem zero_ascFactorial : β (k : β), (0 : β).ascFactorial k.succ = 0
| 0 => by
rw [ascFactorial_succ, ascFactorial_zero, Nat.zero_add, Nat.zero_mul]
| (k+1) => by
rw [ascFactorial_succ, zero_ascFactorial k, Nat.mul_zero]
@[simp]
theorem one_ascFactorial : β (k : β), (1 : β).ascFactorial k = k.factorial
| 0 => ascFactorial_zero 1
| (k+1) => by
rw [ascFactorial_succ, one_ascFactorial k, Nat.add_comm, factorial_succ]
theorem succ_ascFactorial (n : β) :
β k, n * n.succ.ascFactorial k = (n + k) * n.ascFactorial k
| 0 => by rw [Nat.add_zero, ascFactorial_zero, ascFactorial_zero]
| k + 1 => by rw [ascFactorial, Nat.mul_left_comm, succ_ascFactorial n k, ascFactorial, succ_add,
β Nat.add_assoc]
/-- `(n + 1).ascFactorial k = (n + k) ! / n !` but without β-division. See
`Nat.ascFactorial_eq_div` for the version with β-division. -/
theorem factorial_mul_ascFactorial (n : β) : β k, n ! * (n + 1).ascFactorial k = (n + k)!
| 0 => by rw [ascFactorial_zero, Nat.add_zero, Nat.mul_one]
| k + 1 => by
rw [ascFactorial_succ, β Nat.add_assoc, factorial_succ, Nat.mul_comm (n + 1 + k),
β Nat.mul_assoc, factorial_mul_ascFactorial n k, Nat.mul_comm, Nat.add_right_comm]
/-- `n.ascFactorial k = (n + k - 1)! / (n - 1)!` for `n > 0` but without β-division. See
`Nat.ascFactorial_eq_div` for the version with β-division. Consider using
`factorial_mul_ascFactorial` to avoid complications of β-subtraction. -/
theorem factorial_mul_ascFactorial' (n k : β) (h : 0 < n) :
(n - 1) ! * n.ascFactorial k = (n + k - 1)! := by
rw [Nat.sub_add_comm h, Nat.sub_one]
nth_rw 2 [Nat.eq_add_of_sub_eq h rfl]
rw [Nat.sub_one, factorial_mul_ascFactorial]
theorem ascFactorial_mul_ascFactorial (n l k : β) :
n.ascFactorial l * (n + l).ascFactorial k = n.ascFactorial (l + k) := by
cases n with
| zero =>
cases l
Β· simp only [ascFactorial_zero, Nat.add_zero, Nat.one_mul, Nat.zero_add]
Β· simp only [Nat.add_right_comm, zero_ascFactorial, Nat.zero_add, Nat.zero_mul]
| succ n' =>
apply Nat.mul_left_cancel (factorial_pos n')
simp only [Nat.add_assoc, β Nat.mul_assoc, factorial_mul_ascFactorial]
rw [Nat.add_comm 1 l, β Nat.add_assoc, factorial_mul_ascFactorial, Nat.add_assoc]
/-- Avoid in favor of `Nat.factorial_mul_ascFactorial` if you can. β-division isn't worth it. -/
theorem ascFactorial_eq_div (n k : β) : (n + 1).ascFactorial k = (n + k)! / n ! :=
Nat.eq_div_of_mul_eq_right n.factorial_ne_zero (factorial_mul_ascFactorial _ _)
/-- Avoid in favor of `Nat.factorial_mul_ascFactorial'` if you can. β-division isn't worth it. -/
theorem ascFactorial_eq_div' (n k : β) (h : 0 < n) :
n.ascFactorial k = (n + k - 1)! / (n - 1) ! :=
Nat.eq_div_of_mul_eq_right (n - 1).factorial_ne_zero (factorial_mul_ascFactorial' _ _ h)
theorem ascFactorial_of_sub {n k : β} :
(n - k) * (n - k + 1).ascFactorial k = (n - k).ascFactorial (k + 1) := by
rw [succ_ascFactorial, ascFactorial_succ]
theorem pow_succ_le_ascFactorial (n : β) : β k : β, n ^ k β€ n.ascFactorial k
| 0 => by rw [ascFactorial_zero, Nat.pow_zero]
| k + 1 => by
rw [Nat.pow_succ, Nat.mul_comm, ascFactorial_succ, β succ_ascFactorial]
exact Nat.mul_le_mul (Nat.le_refl n)
(Nat.le_trans (Nat.pow_le_pow_left (le_succ n) k) (pow_succ_le_ascFactorial n.succ k))
| theorem pow_lt_ascFactorial' (n k : β) : (n + 1) ^ (k + 2) < (n + 1).ascFactorial (k + 2) := by
rw [Nat.pow_succ, ascFactorial, Nat.mul_comm]
exact Nat.mul_lt_mul_of_lt_of_le' (Nat.lt_add_of_pos_right k.succ_pos)
| Mathlib/Data/Nat/Factorial/Basic.lean | 272 | 274 |
/-
Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Algebra.Polynomial.Splits
import Mathlib.Tactic.IntervalCases
/-!
# Cubics and discriminants
This file defines cubic polynomials over a semiring and their discriminants over a splitting field.
## Main definitions
* `Cubic`: the structure representing a cubic polynomial.
* `Cubic.disc`: the discriminant of a cubic polynomial.
## Main statements
* `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if
the cubic has no duplicate roots.
## References
* https://en.wikipedia.org/wiki/Cubic_equation
* https://en.wikipedia.org/wiki/Discriminant
## Tags
cubic, discriminant, polynomial, root
-/
noncomputable section
/-- The structure representing a cubic polynomial. -/
@[ext]
structure Cubic (R : Type*) where
/-- The degree-3 coefficient -/
a : R
/-- The degree-2 coefficient -/
b : R
/-- The degree-1 coefficient -/
c : R
/-- The degree-0 coefficient -/
d : R
namespace Cubic
open Polynomial
variable {R S F K : Type*}
instance [Inhabited R] : Inhabited (Cubic R) :=
β¨β¨default, default, default, defaultβ©β©
instance [Zero R] : Zero (Cubic R) :=
β¨β¨0, 0, 0, 0β©β©
section Basic
variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R]
/-- Convert a cubic polynomial to a polynomial. -/
def toPoly (P : Cubic R) : R[X] :=
C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d
theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} :
C w * (X - C x) * (X - C y) * (X - C z) =
toPoly β¨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)β© := by
simp only [toPoly, C_neg, C_add, C_mul]
ring1
theorem prod_X_sub_C_eq [CommRing S] {x y z : S} :
(X - C x) * (X - C y) * (X - C z) =
toPoly β¨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)β© := by
rw [β one_mul <| X - C x, β C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul]
/-! ### Coefficients -/
section Coeff
private theorem coeffs : (β n > 3, P.toPoly.coeff n = 0) β§ P.toPoly.coeff 3 = P.a β§
P.toPoly.coeff 2 = P.b β§ P.toPoly.coeff 1 = P.c β§ P.toPoly.coeff 0 = P.d := by
simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow]
norm_num
intro n hn
repeat' rw [if_neg]
any_goals omega
repeat' rw [zero_add]
@[simp]
theorem coeff_eq_zero {n : β} (hn : 3 < n) : P.toPoly.coeff n = 0 :=
coeffs.1 n hn
@[simp]
theorem coeff_eq_a : P.toPoly.coeff 3 = P.a :=
coeffs.2.1
@[simp]
theorem coeff_eq_b : P.toPoly.coeff 2 = P.b :=
coeffs.2.2.1
@[simp]
theorem coeff_eq_c : P.toPoly.coeff 1 = P.c :=
coeffs.2.2.2.1
@[simp]
theorem coeff_eq_d : P.toPoly.coeff 0 = P.d :=
coeffs.2.2.2.2
theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [β coeff_eq_a, h, coeff_eq_a]
theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [β coeff_eq_b, h, coeff_eq_b]
theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [β coeff_eq_c, h, coeff_eq_c]
theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [β coeff_eq_d, h, coeff_eq_d]
theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly β P = Q :=
β¨fun h β¦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPolyβ©
theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by
rw [toPoly, ha, C_0, zero_mul, zero_add]
theorem of_a_eq_zero' : toPoly β¨0, b, c, dβ© = C b * X ^ 2 + C c * X + C d :=
of_a_eq_zero rfl
theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by
rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add]
theorem of_b_eq_zero' : toPoly β¨0, 0, c, dβ© = C c * X + C d :=
of_b_eq_zero rfl rfl
theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by
rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add]
theorem of_c_eq_zero' : toPoly β¨0, 0, 0, dβ© = C d :=
of_c_eq_zero rfl rfl rfl
theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly = 0 := by
rw [of_c_eq_zero ha hb hc, hd, C_0]
theorem of_d_eq_zero' : (β¨0, 0, 0, 0β© : Cubic R).toPoly = 0 :=
of_d_eq_zero rfl rfl rfl rfl
theorem zero : (0 : Cubic R).toPoly = 0 :=
of_d_eq_zero'
theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 β P = 0 := by
rw [β zero, toPoly_injective]
private theorem ne_zero (h0 : P.a β 0 β¨ P.b β 0 β¨ P.c β 0 β¨ P.d β 0) : P.toPoly β 0 := by
contrapose! h0
rw [(toPoly_eq_zero_iff P).mp h0]
exact β¨rfl, rfl, rfl, rflβ©
theorem ne_zero_of_a_ne_zero (ha : P.a β 0) : P.toPoly β 0 :=
(or_imp.mp ne_zero).1 ha
theorem ne_zero_of_b_ne_zero (hb : P.b β 0) : P.toPoly β 0 :=
(or_imp.mp (or_imp.mp ne_zero).2).1 hb
theorem ne_zero_of_c_ne_zero (hc : P.c β 0) : P.toPoly β 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc
theorem ne_zero_of_d_ne_zero (hd : P.d β 0) : P.toPoly β 0 :=
(or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd
@[simp]
theorem leadingCoeff_of_a_ne_zero (ha : P.a β 0) : P.toPoly.leadingCoeff = P.a :=
leadingCoeff_cubic ha
@[simp]
theorem leadingCoeff_of_a_ne_zero' (ha : a β 0) : (toPoly β¨a, b, c, dβ©).leadingCoeff = a :=
leadingCoeff_of_a_ne_zero ha
@[simp]
theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b β 0) : P.toPoly.leadingCoeff = P.b := by
rw [of_a_eq_zero ha, leadingCoeff_quadratic hb]
@[simp]
theorem leadingCoeff_of_b_ne_zero' (hb : b β 0) : (toPoly β¨0, b, c, dβ©).leadingCoeff = b :=
leadingCoeff_of_b_ne_zero rfl hb
@[simp]
theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β 0) :
P.toPoly.leadingCoeff = P.c := by
rw [of_b_eq_zero ha hb, leadingCoeff_linear hc]
@[simp]
theorem leadingCoeff_of_c_ne_zero' (hc : c β 0) : (toPoly β¨0, 0, c, dβ©).leadingCoeff = c :=
leadingCoeff_of_c_ne_zero rfl rfl hc
@[simp]
theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.leadingCoeff = P.d := by
rw [of_c_eq_zero ha hb hc, leadingCoeff_C]
theorem leadingCoeff_of_c_eq_zero' : (toPoly β¨0, 0, 0, dβ©).leadingCoeff = d :=
leadingCoeff_of_c_eq_zero rfl rfl rfl
theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_a_ne_zero (ha βΈ one_ne_zero), ha]
theorem monic_of_a_eq_one' : (toPoly β¨1, b, c, dβ©).Monic :=
monic_of_a_eq_one rfl
theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_b_ne_zero ha (hb βΈ one_ne_zero), hb]
theorem monic_of_b_eq_one' : (toPoly β¨0, 1, c, dβ©).Monic :=
monic_of_b_eq_one rfl rfl
theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by
nontriviality R
rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc βΈ one_ne_zero), hc]
theorem monic_of_c_eq_one' : (toPoly β¨0, 0, 1, dβ©).Monic :=
monic_of_c_eq_one rfl rfl rfl
theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) :
P.toPoly.Monic := by
rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd]
theorem monic_of_d_eq_one' : (toPoly β¨0, 0, 0, 1β©).Monic :=
monic_of_d_eq_one rfl rfl rfl rfl
end Coeff
/-! ### Degrees -/
section Degree
/-- The equivalence between cubic polynomials and polynomials of degree at most three. -/
@[simps]
def equiv : Cubic R β { p : R[X] // p.degree β€ 3 } where
toFun P := β¨P.toPoly, degree_cubic_leβ©
invFun f := β¨coeff f 3, coeff f 2, coeff f 1, coeff f 0β©
left_inv P := by ext <;> simp only [Subtype.coe_mk, coeffs]
right_inv f := by
ext n
obtain hn | hn := le_or_lt n 3
Β· interval_cases n <;> simp only [Nat.succ_eq_add_one] <;> ring_nf <;> try simp only [coeffs]
Β· rw [coeff_eq_zero hn, (degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2]
simpa using hn
@[simp]
theorem degree_of_a_ne_zero (ha : P.a β 0) : P.toPoly.degree = 3 :=
degree_cubic ha
@[simp]
theorem degree_of_a_ne_zero' (ha : a β 0) : (toPoly β¨a, b, c, dβ©).degree = 3 :=
degree_of_a_ne_zero ha
theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree β€ 2 := by
simpa only [of_a_eq_zero ha] using degree_quadratic_le
theorem degree_of_a_eq_zero' : (toPoly β¨0, b, c, dβ©).degree β€ 2 :=
degree_of_a_eq_zero rfl
@[simp]
theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b β 0) : P.toPoly.degree = 2 := by
rw [of_a_eq_zero ha, degree_quadratic hb]
@[simp]
theorem degree_of_b_ne_zero' (hb : b β 0) : (toPoly β¨0, b, c, dβ©).degree = 2 :=
degree_of_b_ne_zero rfl hb
theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree β€ 1 := by
simpa only [of_b_eq_zero ha hb] using degree_linear_le
theorem degree_of_b_eq_zero' : (toPoly β¨0, 0, c, dβ©).degree β€ 1 :=
degree_of_b_eq_zero rfl rfl
@[simp]
theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β 0) : P.toPoly.degree = 1 := by
rw [of_b_eq_zero ha hb, degree_linear hc]
@[simp]
theorem degree_of_c_ne_zero' (hc : c β 0) : (toPoly β¨0, 0, c, dβ©).degree = 1 :=
degree_of_c_ne_zero rfl rfl hc
theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree β€ 0 := by
simpa only [of_c_eq_zero ha hb hc] using degree_C_le
theorem degree_of_c_eq_zero' : (toPoly β¨0, 0, 0, dβ©).degree β€ 0 :=
degree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d β 0) :
P.toPoly.degree = 0 := by
rw [of_c_eq_zero ha hb hc, degree_C hd]
@[simp]
theorem degree_of_d_ne_zero' (hd : d β 0) : (toPoly β¨0, 0, 0, dβ©).degree = 0 :=
degree_of_d_ne_zero rfl rfl rfl hd
@[simp]
theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) :
P.toPoly.degree = β₯ := by
rw [of_d_eq_zero ha hb hc hd, degree_zero]
theorem degree_of_d_eq_zero' : (β¨0, 0, 0, 0β© : Cubic R).toPoly.degree = β₯ :=
degree_of_d_eq_zero rfl rfl rfl rfl
@[simp]
theorem degree_of_zero : (0 : Cubic R).toPoly.degree = β₯ :=
degree_of_d_eq_zero'
@[simp]
theorem natDegree_of_a_ne_zero (ha : P.a β 0) : P.toPoly.natDegree = 3 :=
natDegree_cubic ha
@[simp]
theorem natDegree_of_a_ne_zero' (ha : a β 0) : (toPoly β¨a, b, c, dβ©).natDegree = 3 :=
natDegree_of_a_ne_zero ha
theorem natDegree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.natDegree β€ 2 := by
simpa only [of_a_eq_zero ha] using natDegree_quadratic_le
theorem natDegree_of_a_eq_zero' : (toPoly β¨0, b, c, dβ©).natDegree β€ 2 :=
natDegree_of_a_eq_zero rfl
@[simp]
theorem natDegree_of_b_ne_zero (ha : P.a = 0) (hb : P.b β 0) : P.toPoly.natDegree = 2 := by
rw [of_a_eq_zero ha, natDegree_quadratic hb]
@[simp]
theorem natDegree_of_b_ne_zero' (hb : b β 0) : (toPoly β¨0, b, c, dβ©).natDegree = 2 :=
natDegree_of_b_ne_zero rfl hb
theorem natDegree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.natDegree β€ 1 := by
simpa only [of_b_eq_zero ha hb] using natDegree_linear_le
theorem natDegree_of_b_eq_zero' : (toPoly β¨0, 0, c, dβ©).natDegree β€ 1 :=
natDegree_of_b_eq_zero rfl rfl
@[simp]
theorem natDegree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β 0) :
P.toPoly.natDegree = 1 := by
rw [of_b_eq_zero ha hb, natDegree_linear hc]
@[simp]
theorem natDegree_of_c_ne_zero' (hc : c β 0) : (toPoly β¨0, 0, c, dβ©).natDegree = 1 :=
natDegree_of_c_ne_zero rfl rfl hc
@[simp]
theorem natDegree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) :
P.toPoly.natDegree = 0 := by
rw [of_c_eq_zero ha hb hc, natDegree_C]
theorem natDegree_of_c_eq_zero' : (toPoly β¨0, 0, 0, dβ©).natDegree = 0 :=
natDegree_of_c_eq_zero rfl rfl rfl
@[simp]
theorem natDegree_of_zero : (0 : Cubic R).toPoly.natDegree = 0 :=
natDegree_of_c_eq_zero'
end Degree
/-! ### Map across a homomorphism -/
section Map
variable [Semiring S] {Ο : R β+* S}
/-- Map a cubic polynomial across a semiring homomorphism. -/
def map (Ο : R β+* S) (P : Cubic R) : Cubic S :=
β¨Ο P.a, Ο P.b, Ο P.c, Ο P.dβ©
theorem map_toPoly : (map Ο P).toPoly = Polynomial.map Ο P.toPoly := by
simp only [map, toPoly, map_C, map_X, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow]
end Map
end Basic
section Roots
open Multiset
/-! ### Roots over an extension -/
section Extension
variable {P : Cubic R} [CommRing R] [CommRing S] {Ο : R β+* S}
/-- The roots of a cubic polynomial. -/
def roots [IsDomain R] (P : Cubic R) : Multiset R :=
P.toPoly.roots
theorem map_roots [IsDomain S] : (map Ο P).roots = (Polynomial.map Ο P.toPoly).roots := by
rw [roots, map_toPoly]
theorem mem_roots_iff [IsDomain R] (h0 : P.toPoly β 0) (x : R) :
x β P.roots β P.a * x ^ 3 + P.b * x ^ 2 + P.c * x + P.d = 0 := by
rw [roots, mem_roots h0, IsRoot, toPoly]
simp only [eval_C, eval_X, eval_add, eval_mul, eval_pow]
theorem card_roots_le [IsDomain R] [DecidableEq R] : P.roots.toFinset.card β€ 3 := by
apply (toFinset_card_le P.toPoly.roots).trans
by_cases hP : P.toPoly = 0
Β· exact (card_roots' P.toPoly).trans (by rw [hP, natDegree_zero]; exact zero_le 3)
Β· exact WithBot.coe_le_coe.1 ((card_roots hP).trans degree_cubic_le)
end Extension
variable {P : Cubic F} [Field F] [Field K] {Ο : F β+* K} {x y z : K}
/-! ### Roots over a splitting field -/
section Split
theorem splits_iff_card_roots (ha : P.a β 0) :
Splits Ο P.toPoly β Multiset.card (map Ο P).roots = 3 := by
replace ha : (map Ο P).a β 0 := (_root_.map_ne_zero Ο).mpr ha
nth_rw 1 [β RingHom.id_comp Ο]
rw [roots, β splits_map_iff, β map_toPoly, Polynomial.splits_iff_card_roots,
β ((degree_eq_iff_natDegree_eq <| ne_zero_of_a_ne_zero ha).1 <| degree_of_a_ne_zero ha : _ = 3)]
theorem splits_iff_roots_eq_three (ha : P.a β 0) :
Splits Ο P.toPoly β β x y z : K, (map Ο P).roots = {x, y, z} := by
rw [splits_iff_card_roots ha, card_eq_three]
theorem eq_prod_three_roots (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
(map Ο P).toPoly = C (Ο P.a) * (X - C x) * (X - C y) * (X - C z) := by
rw [map_toPoly,
eq_prod_roots_of_splits <|
(splits_iff_roots_eq_three ha).mpr <| Exists.intro x <| Exists.intro y <| Exists.intro z h3,
leadingCoeff_of_a_ne_zero ha, β map_roots, h3]
change C (Ο P.a) * ((X - C x) ::β (X - C y) ::β {X - C z}).prod = _
rw [prod_cons, prod_cons, prod_singleton, mul_assoc, mul_assoc]
theorem eq_sum_three_roots (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
map Ο P =
β¨Ο P.a, Ο P.a * -(x + y + z), Ο P.a * (x * y + x * z + y * z), Ο P.a * -(x * y * z)β© := by
apply_fun @toPoly _ _
Β· rw [eq_prod_three_roots ha h3, C_mul_prod_X_sub_C_eq]
Β· exact fun P Q β¦ (toPoly_injective P Q).mp
theorem b_eq_three_roots (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
Ο P.b = Ο P.a * -(x + y + z) := by
injection eq_sum_three_roots ha h3
theorem c_eq_three_roots (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
Ο P.c = Ο P.a * (x * y + x * z + y * z) := by
injection eq_sum_three_roots ha h3
theorem d_eq_three_roots (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
Ο P.d = Ο P.a * -(x * y * z) := by
injection eq_sum_three_roots ha h3
end Split
/-! ### Discriminant over a splitting field -/
section Discriminant
/-- The discriminant of a cubic polynomial. -/
def disc {R : Type*} [Ring R] (P : Cubic R) : R :=
P.b ^ 2 * P.c ^ 2 - 4 * P.a * P.c ^ 3 - 4 * P.b ^ 3 * P.d - 27 * P.a ^ 2 * P.d ^ 2 +
18 * P.a * P.b * P.c * P.d
theorem disc_eq_prod_three_roots (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
Ο P.disc = (Ο P.a * Ο P.a * (x - y) * (x - z) * (y - z)) ^ 2 := by
simp only [disc, RingHom.map_add, RingHom.map_sub, RingHom.map_mul, map_pow, map_ofNat]
rw [b_eq_three_roots ha h3, c_eq_three_roots ha h3, d_eq_three_roots ha h3]
ring1
theorem disc_ne_zero_iff_roots_ne (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
P.disc β 0 β x β y β§ x β z β§ y β z := by
rw [β _root_.map_ne_zero Ο, disc_eq_prod_three_roots ha h3, pow_two]
simp_rw [mul_ne_zero_iff, sub_ne_zero, _root_.map_ne_zero, and_self_iff, and_iff_right ha,
and_assoc]
theorem disc_ne_zero_iff_roots_nodup (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z}) :
P.disc β 0 β (map Ο P).roots.Nodup := by
rw [disc_ne_zero_iff_roots_ne ha h3, h3]
change _ β (x ::β y ::β {z}).Nodup
rw [nodup_cons, nodup_cons, mem_cons, mem_singleton, mem_singleton]
simp only [nodup_singleton]
tauto
theorem card_roots_of_disc_ne_zero [DecidableEq K] (ha : P.a β 0) (h3 : (map Ο P).roots = {x, y, z})
(hd : P.disc β 0) : (map Ο P).roots.toFinset.card = 3 := by
rw [toFinset_card_of_nodup <| (disc_ne_zero_iff_roots_nodup ha h3).mp hd,
β splits_iff_card_roots ha, splits_iff_roots_eq_three ha]
exact β¨x, β¨y, β¨z, h3β©β©β©
end Discriminant
end Roots
end Cubic
| Mathlib/Algebra/CubicDiscriminant.lean | 521 | 528 | |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Logic.Encodable.Pi
import Mathlib.Logic.Function.Iterate
/-!
# The primitive recursive functions
The primitive recursive functions are the least collection of functions
`β β β` which are closed under projections (using the `pair`
pairing function), composition, zero, successor, and primitive recursion
(i.e. `Nat.rec` where the motive is `C n := β`).
We can extend this definition to a large class of basic types by
using canonical encodings of types as natural numbers (GΓΆdel numbering),
which we implement through the type class `Encodable`. (More precisely,
we need that the composition of encode with decode yields a
primitive recursive function, so we have the `Primcodable` type class
for this.)
In the above, the pairing function is primitive recursive by definition.
This deviates from the textbook definition of primitive recursive functions,
which instead work with *`n`-ary* functions. We formalize the textbook
definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is
equivalent to our chosen formulation. For more discussionn of this and
other design choices in this formalization, see [carneiro2019].
## Main definitions
- `Nat.Primrec f`: `f` is primitive recursive, for functions `f : β β β`
- `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types
- `Primcodable Ξ±`: well-behaved encoding of `Ξ±` into `β`, i.e. one such that roundtripping through
the encoding functions adds no computational power
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open List (Vector)
open Denumerable Encodable Function
namespace Nat
/-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/
@[simp, reducible]
def unpaired {Ξ±} (f : β β β β Ξ±) (n : β) : Ξ± :=
f n.unpair.1 n.unpair.2
/-- The primitive recursive functions `β β β`. -/
protected inductive Primrec : (β β β) β Prop
| zero : Nat.Primrec fun _ => 0
| protected succ : Nat.Primrec succ
| left : Nat.Primrec fun n => n.unpair.1
| right : Nat.Primrec fun n => n.unpair.2
| pair {f g} : Nat.Primrec f β Nat.Primrec g β Nat.Primrec fun n => pair (f n) (g n)
| comp {f g} : Nat.Primrec f β Nat.Primrec g β Nat.Primrec fun n => f (g n)
| prec {f g} :
Nat.Primrec f β
Nat.Primrec g β
Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH)
namespace Primrec
theorem of_eq {f g : β β β} (hf : Nat.Primrec f) (H : β n, f n = g n) : Nat.Primrec g :=
(funext H : f = g) βΈ hf
theorem const : β n : β, Nat.Primrec fun _ => n
| 0 => zero
| n + 1 => Primrec.succ.comp (const n)
protected theorem id : Nat.Primrec id :=
(left.pair right).of_eq fun n => by simp
theorem prec1 {f} (m : β) (hf : Nat.Primrec f) :
Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH :=
((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp
theorem casesOn1 {f} (m : β) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn Β· m f) :=
(prec1 m (hf.comp left)).of_eq <| by simp
-- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor.
theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) :
Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) :=
(prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp
protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) :=
(pair right left).of_eq fun n => by simp
theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) :=
(hf.comp .swap).of_eq fun n => by simp
theorem pred : Nat.Primrec pred :=
(casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*]
theorem add : Nat.Primrec (unpaired (Β· + Β·)) :=
(prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc]
theorem sub : Nat.Primrec (unpaired (Β· - Β·)) :=
(prec .id ((pred.comp right).comp right)).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq]
theorem mul : Nat.Primrec (unpaired (Β· * Β·)) :=
(prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by
| simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst]
| Mathlib/Computability/Primrec.lean | 110 | 111 |
/-
Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.Ring.Rat
import Mathlib.Algebra.Ring.Int.Parity
import Mathlib.Data.PNat.Defs
/-!
# Further lemmas for the Rational Numbers
-/
namespace Rat
theorem num_dvd (a) {b : β€} (b0 : b β 0) : (a /. b).num β£ a := by
rcases e : a /. b with β¨n, d, h, cβ©
rw [Rat.mk'_eq_divInt, divInt_eq_iff b0 (mod_cast h)] at e
refine Int.natAbs_dvd.1 <| Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <|
c.dvd_of_dvd_mul_right ?_
have := congr_arg Int.natAbs e
simp only [Int.natAbs_mul, Int.natAbs_natCast] at this; simp [this]
theorem den_dvd (a b : β€) : ((a /. b).den : β€) β£ b := by
by_cases b0 : b = 0; Β· simp [b0]
rcases e : a /. b with β¨n, d, h, cβ©
rw [mk'_eq_divInt, divInt_eq_iff b0 (ne_of_gt (Int.natCast_pos.2 (Nat.pos_of_ne_zero h)))] at e
refine Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.symm.dvd_of_dvd_mul_left ?_
rw [β Int.natAbs_mul, β Int.natCast_dvd_natCast, Int.dvd_natAbs, β e]; simp
theorem num_den_mk {q : β} {n d : β€} (hd : d β 0) (qdf : q = n /. d) :
β c : β€, n = c * q.num β§ d = c * q.den := by
obtain rfl | hn := eq_or_ne n 0
Β· simp [qdf]
have : q.num * d = n * βq.den := by
refine (divInt_eq_iff ?_ hd).mp ?_
Β· exact Int.natCast_ne_zero.mpr (Rat.den_nz _)
Β· rwa [num_divInt_den]
have hqdn : q.num β£ n := by
rw [qdf]
exact Rat.num_dvd _ hd
refine β¨n / q.num, ?_, ?_β©
Β· rw [Int.ediv_mul_cancel hqdn]
Β· refine Int.eq_mul_div_of_mul_eq_mul_of_dvd_left ?_ hqdn this
rw [qdf]
exact Rat.num_ne_zero.2 ((divInt_ne_zero hd).mpr hn)
theorem num_mk (n d : β€) : (n /. d).num = d.sign * n / n.gcd d := by
have (m : β) : Int.natAbs (m + 1) = m + 1 := by
rw [β Nat.cast_one, β Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
rw [β Int.tdiv_eq_ediv_of_dvd] <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
Int.zero_ediv, Int.ofNat_dvd_left, Nat.gcd_dvd_left, this]
theorem den_mk (n d : β€) : (n /. d).den = if d = 0 then 1 else d.natAbs / n.gcd d := by
have (m : β) : Int.natAbs (m + 1) = m + 1 := by
rw [β Nat.cast_one, β Nat.cast_add, Int.natAbs_cast]
rcases d with ((_ | _) | _) <;>
simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
if_neg (Nat.cast_add_one_ne_zero _), this]
theorem add_den_dvd_lcm (qβ qβ : β) : (qβ + qβ).den β£ qβ.den.lcm qβ.den := by
rw [add_def, normalize_eq, Nat.div_dvd_iff_dvd_mul (Nat.gcd_dvd_right _ _)
(Nat.gcd_ne_zero_right (by simp)), β Nat.gcd_mul_lcm,
mul_dvd_mul_iff_right (Nat.lcm_ne_zero (by simp) (by simp)), Nat.dvd_gcd_iff]
refine β¨?_, dvd_mul_right _ _β©
rw [β Int.natCast_dvd_natCast, Int.dvd_natAbs]
apply Int.dvd_add
<;> apply dvd_mul_of_dvd_right <;> rw [Int.natCast_dvd_natCast]
<;> [exact Nat.gcd_dvd_right _ _; exact Nat.gcd_dvd_left _ _]
theorem add_den_dvd (qβ qβ : β) : (qβ + qβ).den β£ qβ.den * qβ.den := by
rw [add_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_den_dvd (qβ qβ : β) : (qβ * qβ).den β£ qβ.den * qβ.den := by
rw [mul_def, normalize_eq]
apply Nat.div_dvd_of_dvd
apply Nat.gcd_dvd_right
theorem mul_num (qβ qβ : β) :
(qβ * qβ).num = qβ.num * qβ.num / Nat.gcd (qβ.num * qβ.num).natAbs (qβ.den * qβ.den) := by
rw [mul_def, normalize_eq]
theorem mul_den (qβ qβ : β) :
(qβ * qβ).den =
qβ.den * qβ.den / Nat.gcd (qβ.num * qβ.num).natAbs (qβ.den * qβ.den) := by
rw [mul_def, normalize_eq]
theorem mul_self_num (q : β) : (q * q).num = q.num * q.num := by
rw [mul_num, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Int.ofNat_one, Int.ediv_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem mul_self_den (q : β) : (q * q).den = q.den * q.den := by
rw [Rat.mul_den, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Nat.div_one]
exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced)
theorem add_num_den (q r : β) :
q + r = (q.num * r.den + q.den * r.num : β€) /. (βq.den * βr.den : β€) := by
have hqd : (q.den : β€) β 0 := Int.natCast_ne_zero_iff_pos.2 q.den_pos
have hrd : (r.den : β€) β 0 := Int.natCast_ne_zero_iff_pos.2 r.den_pos
conv_lhs => rw [β num_divInt_den q, β num_divInt_den r, divInt_add_divInt _ _ hqd hrd]
rw [mul_comm r.num q.den]
theorem isSquare_iff {q : β} : IsSquare q β IsSquare q.num β§ IsSquare q.den := by
constructor
Β· rintro β¨qr, rflβ©
rw [Rat.mul_self_num, mul_self_den]
simp only [IsSquare.mul_self, and_self]
Β· rintro β¨β¨nr, hnrβ©, β¨dr, hdrβ©β©
refine β¨nr / dr, ?_β©
rw [div_mul_div_comm, β Int.cast_mul, β Nat.cast_mul, β hnr, β hdr, num_div_den]
@[norm_cast, simp]
theorem isSquare_natCast_iff {n : β} : IsSquare (n : β) β IsSquare n := by
simp_rw [isSquare_iff, num_natCast, den_natCast, IsSquare.one, and_true, Int.isSquare_natCast_iff]
@[norm_cast, simp]
theorem isSquare_intCast_iff {z : β€} : IsSquare (z : β) β IsSquare z := by
simp_rw [isSquare_iff, intCast_num, intCast_den, IsSquare.one, and_true]
@[simp]
theorem isSquare_ofNat_iff {n : β} :
IsSquare (ofNat(n) : β) β IsSquare (OfNat.ofNat n : β) :=
isSquare_natCast_iff
section Casts
theorem exists_eq_mul_div_num_and_eq_mul_div_den (n : β€) {d : β€} (d_ne_zero : d β 0) :
β c : β€, n = c * ((n : β) / d).num β§ (d : β€) = c * ((n : β) / d).den :=
| haveI : (n : β) / d = Rat.divInt n d := by rw [β Rat.divInt_eq_div]
Rat.num_den_mk d_ne_zero this
| Mathlib/Data/Rat/Lemmas.lean | 137 | 138 |
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.Comap
import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving
/-!
# Restricting a measure to a subset or a subtype
Given a measure `ΞΌ` on a type `Ξ±` and a subset `s` of `Ξ±`, we define a measure `ΞΌ.restrict s` as
the restriction of `ΞΌ` to `s` (still as a measure on `Ξ±`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R Ξ± Ξ² Ξ΄ Ξ³ ΞΉ : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace Ξ±} [MeasurableSpace Ξ²] [MeasurableSpace Ξ³]
variable {ΞΌ ΞΌβ ΞΌβ ΞΌβ Ξ½ Ξ½' Ξ½β Ξ½β : Measure Ξ±} {s s' t : Set Ξ±}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `ΞΌ` to a set `s` as an `ββ₯0β`-linear map. -/
noncomputable def restrictβ {m0 : MeasurableSpace Ξ±} (s : Set Ξ±) : Measure Ξ± ββ[ββ₯0β] Measure Ξ± :=
liftLinear (OuterMeasure.restrict s) fun ΞΌ s' hs' t => by
suffices ΞΌ (s β© t) = ΞΌ (s β© t β© s') + ΞΌ ((s β© t) \ s') by
simpa [β Set.inter_assoc, Set.inter_comm _ s, β inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
/-- Restrict a measure `ΞΌ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace Ξ±} (ΞΌ : Measure Ξ±) (s : Set Ξ±) : Measure Ξ± :=
restrictβ s ΞΌ
@[simp]
theorem restrictβ_apply {_m0 : MeasurableSpace Ξ±} (s : Set Ξ±) (ΞΌ : Measure Ξ±) :
restrictβ s ΞΌ = ΞΌ.restrict s :=
rfl
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(ΞΌ.restrict s).toOuterMeasure = OuterMeasure.restrict s ΞΌ.toOuterMeasure := by
simp_rw [restrict, restrictβ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, ΞΌ.trimmed]
theorem restrict_applyβ (ht : NullMeasurableSet t (ΞΌ.restrict s)) : ΞΌ.restrict s t = ΞΌ (t β© s) := by
rw [β restrictβ_apply, restrictβ, liftLinear_applyβ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t β© s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : ΞΌ.restrict s t = ΞΌ (t β© s) :=
restrict_applyβ ht.nullMeasurableSet
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace Ξ±} β¦s s' : Set Ξ±β¦ β¦ΞΌ Ξ½ : Measure Ξ±β¦ (hs : s β€α΅[ΞΌ] s')
(hΞΌΞ½ : ΞΌ β€ Ξ½) : ΞΌ.restrict s β€ Ξ½.restrict s' :=
Measure.le_iff.2 fun t ht => calc
ΞΌ.restrict s t = ΞΌ (t β© s) := restrict_apply ht
_ β€ ΞΌ (t β© s') := (measure_mono_ae <| hs.mono fun _x hx β¨hxt, hxsβ© => β¨hxt, hx hxsβ©)
_ β€ Ξ½ (t β© s') := le_iff'.1 hΞΌΞ½ (t β© s')
_ = Ξ½.restrict s' t := (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono, gcongr]
theorem restrict_mono {_m0 : MeasurableSpace Ξ±} β¦s s' : Set Ξ±β¦ (hs : s β s') β¦ΞΌ Ξ½ : Measure Ξ±β¦
(hΞΌΞ½ : ΞΌ β€ Ξ½) : ΞΌ.restrict s β€ Ξ½.restrict s' :=
restrict_mono' (ae_of_all _ hs) hΞΌΞ½
@[gcongr]
theorem restrict_mono_measure {_ : MeasurableSpace Ξ±} {ΞΌ Ξ½ : Measure Ξ±} (h : ΞΌ β€ Ξ½) (s : Set Ξ±) :
ΞΌ.restrict s β€ Ξ½.restrict s :=
restrict_mono subset_rfl h
@[gcongr]
theorem restrict_mono_set {_ : MeasurableSpace Ξ±} (ΞΌ : Measure Ξ±) {s t : Set Ξ±} (h : s β t) :
ΞΌ.restrict s β€ ΞΌ.restrict t :=
restrict_mono h le_rfl
theorem restrict_mono_ae (h : s β€α΅[ΞΌ] t) : ΞΌ.restrict s β€ ΞΌ.restrict t :=
restrict_mono' h (le_refl ΞΌ)
theorem restrict_congr_set (h : s =α΅[ΞΌ] t) : ΞΌ.restrict s = ΞΌ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t β© s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : ΞΌ.restrict s t = ΞΌ (t β© s) := by
rw [β toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_applyβ' (hs : NullMeasurableSet s ΞΌ) : ΞΌ.restrict s t = ΞΌ (t β© s) := by
rw [β restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
theorem restrict_le_self : ΞΌ.restrict s β€ ΞΌ :=
Measure.le_iff.2 fun t ht => calc
ΞΌ.restrict s t = ΞΌ (t β© s) := restrict_apply ht
_ β€ ΞΌ t := measure_mono inter_subset_left
variable (ΞΌ)
theorem restrict_eq_self (h : s β t) : ΞΌ.restrict t s = ΞΌ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
ΞΌ s β€ ΞΌ (toMeasurable (ΞΌ.restrict t) s β© t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = ΞΌ.restrict t s := by
rw [β restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
@[simp]
theorem restrict_apply_self (s : Set Ξ±) : (ΞΌ.restrict s) s = ΞΌ s :=
restrict_eq_self ΞΌ Subset.rfl
variable {ΞΌ}
theorem restrict_apply_univ (s : Set Ξ±) : ΞΌ.restrict s univ = ΞΌ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
theorem le_restrict_apply (s t : Set Ξ±) : ΞΌ (t β© s) β€ ΞΌ.restrict s t :=
calc
ΞΌ (t β© s) = ΞΌ.restrict s (t β© s) := (restrict_eq_self ΞΌ inter_subset_right).symm
_ β€ ΞΌ.restrict s t := measure_mono inter_subset_left
theorem restrict_apply_le (s t : Set Ξ±) : ΞΌ.restrict s t β€ ΞΌ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s β t) : ΞΌ.restrict s t = ΞΌ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self ΞΌ s).symm.trans_le <| measure_mono h)
@[simp]
theorem restrict_add {_m0 : MeasurableSpace Ξ±} (ΞΌ Ξ½ : Measure Ξ±) (s : Set Ξ±) :
(ΞΌ + Ξ½).restrict s = ΞΌ.restrict s + Ξ½.restrict s :=
(restrictβ s).map_add ΞΌ Ξ½
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace Ξ±} (s : Set Ξ±) : (0 : Measure Ξ±).restrict s = 0 :=
(restrictβ s).map_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace Ξ±} {R : Type*} [SMul R ββ₯0β]
[IsScalarTower R ββ₯0β ββ₯0β] (c : R) (ΞΌ : Measure Ξ±) (s : Set Ξ±) :
(c β’ ΞΌ).restrict s = c β’ ΞΌ.restrict s := by
simpa only [smul_one_smul] using (restrictβ s).map_smul (c β’ 1) ΞΌ
theorem restrict_restrictβ (hs : NullMeasurableSet s (ΞΌ.restrict t)) :
(ΞΌ.restrict t).restrict s = ΞΌ.restrict (s β© t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_applyβ (hu.nullMeasurableSet.inter hs)]
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (ΞΌ.restrict t).restrict s = ΞΌ.restrict (s β© t) :=
restrict_restrictβ hs.nullMeasurableSet
theorem restrict_restrict_of_subset (h : s β t) : (ΞΌ.restrict t).restrict s = ΞΌ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
theorem restrict_restrictβ' (ht : NullMeasurableSet t ΞΌ) :
(ΞΌ.restrict t).restrict s = ΞΌ.restrict (s β© t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_applyβ' ht, inter_assoc]
theorem restrict_restrict' (ht : MeasurableSet t) :
(ΞΌ.restrict t).restrict s = ΞΌ.restrict (s β© t) :=
restrict_restrictβ' ht.nullMeasurableSet
theorem restrict_comm (hs : MeasurableSet s) :
(ΞΌ.restrict t).restrict s = (ΞΌ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : ΞΌ.restrict s t = 0 β ΞΌ (t β© s) = 0 := by
rw [restrict_apply ht]
theorem measure_inter_eq_zero_of_restrict (h : ΞΌ.restrict s t = 0) : ΞΌ (t β© s) = 0 :=
nonpos_iff_eq_zero.1 (h βΈ le_restrict_apply _ _)
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : ΞΌ.restrict s t = 0 β ΞΌ (t β© s) = 0 := by
rw [restrict_apply' hs]
@[simp]
theorem restrict_eq_zero : ΞΌ.restrict s = 0 β ΞΌ s = 0 := by
rw [β measure_univ_eq_zero, restrict_apply_univ]
/-- If `ΞΌ s β 0`, then `ΞΌ.restrict s β 0`, in terms of `NeZero` instances. -/
instance restrict.neZero [NeZero (ΞΌ s)] : NeZero (ΞΌ.restrict s) :=
β¨mt restrict_eq_zero.mp <| NeZero.ne _β©
theorem restrict_zero_set {s : Set Ξ±} (h : ΞΌ s = 0) : ΞΌ.restrict s = 0 :=
restrict_eq_zero.2 h
@[simp]
theorem restrict_empty : ΞΌ.restrict β
= 0 :=
restrict_zero_set measure_empty
@[simp]
theorem restrict_univ : ΞΌ.restrict univ = ΞΌ :=
ext fun s hs => by simp [hs]
theorem restrict_inter_add_diffβ (s : Set Ξ±) (ht : NullMeasurableSet t ΞΌ) :
ΞΌ.restrict (s β© t) + ΞΌ.restrict (s \ t) = ΞΌ.restrict s := by
ext1 u hu
simp only [add_apply, restrict_apply hu, β inter_assoc, diff_eq]
exact measure_inter_add_diffβ (u β© s) ht
theorem restrict_inter_add_diff (s : Set Ξ±) (ht : MeasurableSet t) :
ΞΌ.restrict (s β© t) + ΞΌ.restrict (s \ t) = ΞΌ.restrict s :=
restrict_inter_add_diffβ s ht.nullMeasurableSet
theorem restrict_union_add_interβ (s : Set Ξ±) (ht : NullMeasurableSet t ΞΌ) :
ΞΌ.restrict (s βͺ t) + ΞΌ.restrict (s β© t) = ΞΌ.restrict s + ΞΌ.restrict t := by
rw [β restrict_inter_add_diffβ (s βͺ t) ht, union_inter_cancel_right, union_diff_right, β
restrict_inter_add_diffβ s ht, add_comm, β add_assoc, add_right_comm]
theorem restrict_union_add_inter (s : Set Ξ±) (ht : MeasurableSet t) :
ΞΌ.restrict (s βͺ t) + ΞΌ.restrict (s β© t) = ΞΌ.restrict s + ΞΌ.restrict t :=
restrict_union_add_interβ s ht.nullMeasurableSet
theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set Ξ±) :
ΞΌ.restrict (s βͺ t) + ΞΌ.restrict (s β© t) = ΞΌ.restrict s + ΞΌ.restrict t := by
simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs
theorem restrict_unionβ (h : AEDisjoint ΞΌ s t) (ht : NullMeasurableSet t ΞΌ) :
ΞΌ.restrict (s βͺ t) = ΞΌ.restrict s + ΞΌ.restrict t := by
simp [β restrict_union_add_interβ s ht, restrict_zero_set h]
theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) :
ΞΌ.restrict (s βͺ t) = ΞΌ.restrict s + ΞΌ.restrict t :=
restrict_unionβ h.aedisjoint ht.nullMeasurableSet
theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) :
ΞΌ.restrict (s βͺ t) = ΞΌ.restrict s + ΞΌ.restrict t := by
rw [union_comm, restrict_union h.symm hs, add_comm]
@[simp]
theorem restrict_add_restrict_compl (hs : MeasurableSet s) :
ΞΌ.restrict s + ΞΌ.restrict sαΆ = ΞΌ := by
rw [β restrict_union (@disjoint_compl_right (Set Ξ±) _ _) hs.compl, union_compl_self,
restrict_univ]
@[simp]
theorem restrict_compl_add_restrict (hs : MeasurableSet s) : ΞΌ.restrict sαΆ + ΞΌ.restrict s = ΞΌ := by
rw [add_comm, restrict_add_restrict_compl hs]
theorem restrict_union_le (s s' : Set Ξ±) : ΞΌ.restrict (s βͺ s') β€ ΞΌ.restrict s + ΞΌ.restrict s' :=
le_iff.2 fun t ht β¦ by
simpa [ht, inter_union_distrib_left] using measure_union_le (t β© s) (t β© s')
theorem restrict_iUnion_apply_ae [Countable ΞΉ] {s : ΞΉ β Set Ξ±} (hd : Pairwise (AEDisjoint ΞΌ on s))
(hm : β i, NullMeasurableSet (s i) ΞΌ) {t : Set Ξ±} (ht : MeasurableSet t) :
ΞΌ.restrict (β i, s i) t = β' i, ΞΌ.restrict (s i) t := by
simp only [restrict_apply, ht, inter_iUnion]
exact
measure_iUnionβ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right)
fun i => ht.nullMeasurableSet.inter (hm i)
theorem restrict_iUnion_apply [Countable ΞΉ] {s : ΞΉ β Set Ξ±} (hd : Pairwise (Disjoint on s))
(hm : β i, MeasurableSet (s i)) {t : Set Ξ±} (ht : MeasurableSet t) :
ΞΌ.restrict (β i, s i) t = β' i, ΞΌ.restrict (s i) t :=
restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht
theorem restrict_iUnion_apply_eq_iSup [Countable ΞΉ] {s : ΞΉ β Set Ξ±} (hd : Directed (Β· β Β·) s)
{t : Set Ξ±} (ht : MeasurableSet t) : ΞΌ.restrict (β i, s i) t = β¨ i, ΞΌ.restrict (s i) t := by
simp only [restrict_apply ht, inter_iUnion]
rw [Directed.measure_iUnion]
exacts [hd.mono_comp _ fun sβ sβ => inter_subset_inter_right _]
/-- The restriction of the pushforward measure is the pushforward of the restriction. For a version
assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/
theorem restrict_map {f : Ξ± β Ξ²} (hf : Measurable f) {s : Set Ξ²} (hs : MeasurableSet s) :
(ΞΌ.map f).restrict s = (ΞΌ.restrict <| f β»ΒΉ' s).map f :=
ext fun t ht => by simp [*, hf ht]
theorem restrict_toMeasurable (h : ΞΌ s β β) : ΞΌ.restrict (toMeasurable ΞΌ s) = ΞΌ.restrict s :=
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h,
inter_comm]
theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace Ξ±} β¦s : Set Ξ±β¦ β¦ΞΌ : Measure Ξ±β¦
(hs : βα΅ x βΞΌ, x β s) : ΞΌ.restrict s = ΞΌ :=
calc
ΞΌ.restrict s = ΞΌ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs)
_ = ΞΌ := restrict_univ
theorem restrict_congr_meas (hs : MeasurableSet s) :
ΞΌ.restrict s = Ξ½.restrict s β β t β s, MeasurableSet t β ΞΌ t = Ξ½ t :=
β¨fun H t hts ht => by
rw [β inter_eq_self_of_subset_left hts, β restrict_apply ht, H, restrict_apply ht], fun H =>
ext fun t ht => by
rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]β©
theorem restrict_congr_mono (hs : s β t) (h : ΞΌ.restrict t = Ξ½.restrict t) :
ΞΌ.restrict s = Ξ½.restrict s := by
rw [β restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs]
/-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all
measurable subsets of `s βͺ t`. -/
theorem restrict_union_congr :
ΞΌ.restrict (s βͺ t) = Ξ½.restrict (s βͺ t) β
ΞΌ.restrict s = Ξ½.restrict s β§ ΞΌ.restrict t = Ξ½.restrict t := by
refine β¨fun h β¦ β¨restrict_congr_mono subset_union_left h,
restrict_congr_mono subset_union_right hβ©, ?_β©
rintro β¨hs, htβ©
ext1 u hu
simp only [restrict_apply hu, inter_union_distrib_left]
rcases exists_measurable_supersetβ ΞΌ Ξ½ (u β© s) with β¨US, hsub, hm, hΞΌ, hΞ½β©
calc
ΞΌ (u β© s βͺ u β© t) = ΞΌ (US βͺ u β© t) :=
measure_union_congr_of_subset hsub hΞΌ.le Subset.rfl le_rfl
_ = ΞΌ US + ΞΌ ((u β© t) \ US) := (measure_add_diff hm.nullMeasurableSet _).symm
_ = restrict ΞΌ s u + restrict ΞΌ t (u \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hΞΌ, β inter_comm t, inter_diff_assoc]
_ = restrict Ξ½ s u + restrict Ξ½ t (u \ US) := by rw [hs, ht]
_ = Ξ½ US + Ξ½ ((u β© t) \ US) := by
simp only [restrict_apply, hu, hu.diff hm, hΞ½, β inter_comm t, inter_diff_assoc]
_ = Ξ½ (US βͺ u β© t) := measure_add_diff hm.nullMeasurableSet _
_ = Ξ½ (u β© s βͺ u β© t) := .symm <| measure_union_congr_of_subset hsub hΞ½.le Subset.rfl le_rfl
theorem restrict_finset_biUnion_congr {s : Finset ΞΉ} {t : ΞΉ β Set Ξ±} :
ΞΌ.restrict (β i β s, t i) = Ξ½.restrict (β i β s, t i) β
β i β s, ΞΌ.restrict (t i) = Ξ½.restrict (t i) := by
classical
induction' s using Finset.induction_on with i s _ hs; Β· simp
simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert]
rw [restrict_union_congr, β hs]
theorem restrict_iUnion_congr [Countable ΞΉ] {s : ΞΉ β Set Ξ±} :
ΞΌ.restrict (β i, s i) = Ξ½.restrict (β i, s i) β β i, ΞΌ.restrict (s i) = Ξ½.restrict (s i) := by
refine β¨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_β©
ext1 t ht
have D : Directed (Β· β Β·) fun t : Finset ΞΉ => β i β t, s i :=
Monotone.directed_le fun tβ tβ ht => biUnion_subset_biUnion_left ht
rw [iUnion_eq_iUnion_finset]
simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i]
theorem restrict_biUnion_congr {s : Set ΞΉ} {t : ΞΉ β Set Ξ±} (hc : s.Countable) :
ΞΌ.restrict (β i β s, t i) = Ξ½.restrict (β i β s, t i) β
β i β s, ΞΌ.restrict (t i) = Ξ½.restrict (t i) := by
haveI := hc.toEncodable
simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr]
theorem restrict_sUnion_congr {S : Set (Set Ξ±)} (hc : S.Countable) :
ΞΌ.restrict (ββ S) = Ξ½.restrict (ββ S) β β s β S, ΞΌ.restrict s = Ξ½.restrict s := by
rw [sUnion_eq_biUnion, restrict_biUnion_congr hc]
/-- This lemma shows that `Inf` and `restrict` commute for measures. -/
theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace Ξ±} {m : Set (Measure Ξ±)}
(hm : m.Nonempty) (ht : MeasurableSet t) :
(sInf m).restrict t = sInf ((fun ΞΌ : Measure Ξ± => ΞΌ.restrict t) '' m) := by
ext1 s hs
simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht),
Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, β
Set.image_image _ toOuterMeasure, β OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _),
OuterMeasure.restrict_apply]
theorem exists_mem_of_measure_ne_zero_of_ae (hs : ΞΌ s β 0) {p : Ξ± β Prop}
(hp : βα΅ x βΞΌ.restrict s, p x) : β x, x β s β§ p x := by
rw [β ΞΌ.restrict_apply_self, β frequently_ae_mem_iff] at hs
exact (hs.and_eventually hp).exists
/-- If a quasi measure preserving map `f` maps a set `s` to a set `t`,
then it is quasi measure preserving with respect to the restrictions of the measures. -/
theorem QuasiMeasurePreserving.restrict {Ξ½ : Measure Ξ²} {f : Ξ± β Ξ²}
(hf : QuasiMeasurePreserving f ΞΌ Ξ½) {t : Set Ξ²} (hmaps : MapsTo f s t) :
QuasiMeasurePreserving f (ΞΌ.restrict s) (Ξ½.restrict t) where
measurable := hf.measurable
absolutelyContinuous := by
refine AbsolutelyContinuous.mk fun u hum β¦ ?_
suffices Ξ½ (u β© t) = 0 β ΞΌ (f β»ΒΉ' u β© s) = 0 by simpa [hum, hf.measurable, hf.measurable hum]
refine fun hu β¦ measure_mono_null ?_ (hf.preimage_null hu)
rw [preimage_inter]
gcongr
assumption
/-! ### Extensionality results -/
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`). -/
theorem ext_iff_of_iUnion_eq_univ [Countable ΞΉ] {s : ΞΉ β Set Ξ±} (hs : β i, s i = univ) :
ΞΌ = Ξ½ β β i, ΞΌ.restrict (s i) = Ξ½.restrict (s i) := by
rw [β restrict_iUnion_congr, hs, restrict_univ, restrict_univ]
alias β¨_, ext_of_iUnion_eq_univβ© := ext_iff_of_iUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `biUnion`). -/
theorem ext_iff_of_biUnion_eq_univ {S : Set ΞΉ} {s : ΞΉ β Set Ξ±} (hc : S.Countable)
(hs : β i β S, s i = univ) : ΞΌ = Ξ½ β β i β S, ΞΌ.restrict (s i) = Ξ½.restrict (s i) := by
rw [β restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ]
alias β¨_, ext_of_biUnion_eq_univβ© := ext_iff_of_biUnion_eq_univ
/-- Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`). -/
theorem ext_iff_of_sUnion_eq_univ {S : Set (Set Ξ±)} (hc : S.Countable) (hs : ββ S = univ) :
| ΞΌ = Ξ½ β β s β S, ΞΌ.restrict s = Ξ½.restrict s :=
ext_iff_of_biUnion_eq_univ hc <| by rwa [β sUnion_eq_biUnion]
alias β¨_, ext_of_sUnion_eq_univβ© := ext_iff_of_sUnion_eq_univ
theorem ext_of_generateFrom_of_cover {S T : Set (Set Ξ±)} (h_gen : βΉ_βΊ = generateFrom S)
(hc : T.Countable) (h_inter : IsPiSystem S) (hU : ββ T = univ) (htop : β t β T, ΞΌ t β β)
(ST_eq : β t β T, β s β S, ΞΌ (s β© t) = Ξ½ (s β© t)) (T_eq : β t β T, ΞΌ t = Ξ½ t) : ΞΌ = Ξ½ := by
| Mathlib/MeasureTheory/Measure/Restrict.lean | 417 | 424 |
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.Matrix.ToLin
/-! # Free modules over PID
A free `R`-module `M` is a module with a basis over `R`,
equivalently it is an `R`-module linearly equivalent to `ΞΉ ββ R` for some `ΞΉ`.
This file proves a submodule of a free `R`-module of finite rank is also
a free `R`-module of finite rank, if `R` is a principal ideal domain (PID),
i.e. we have instances `[IsDomain R] [IsPrincipalIdealRing R]`.
We express "free `R`-module of finite rank" as a module `M` which has a basis
`b : ΞΉ β R`, where `ΞΉ` is a `Fintype`.
We call the cardinality of `ΞΉ` the rank of `M` in this file;
it would be equal to `finrank R M` if `R` is a field and `M` is a vector space.
## Main results
In this section, `M` is a free and finitely generated `R`-module, and
`N` is a submodule of `M`.
- `Submodule.inductionOnRank`: if `P` holds for `β₯ : Submodule R M` and if
`P N` follows from `P N'` for all `N'` that are of lower rank, then `P` holds
on all submodules
- `Submodule.exists_basis_of_pid`: if `R` is a PID, then `N : Submodule R M` is
free and finitely generated. This is the first part of the structure theorem
for modules.
- `Submodule.smithNormalForm`: if `R` is a PID, then `M` has a basis
`bM` and `N` has a basis `bN` such that `bN i = a i β’ bM i`.
Equivalently, a linear map `f : M ββ M` with `range f = N` can be written as
a matrix in Smith normal form, a diagonal matrix with the coefficients `a i`
along the diagonal.
## Tags
free module, finitely generated module, rank, structure theorem
-/
universe u v
section Ring
variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M]
variable {ΞΉ : Type*} (b : Basis ΞΉ R M)
open Submodule.IsPrincipal Submodule
theorem eq_bot_of_generator_maximal_map_eq_zero (b : Basis ΞΉ R M) {N : Submodule R M}
{Ο : M ββ[R] R} (hΟ : β Ο : M ββ[R] R, Β¬N.map Ο < N.map Ο) [(N.map Ο).IsPrincipal]
(hgen : generator (N.map Ο) = (0 : R)) : N = β₯ := by
rw [Submodule.eq_bot_iff]
intro x hx
refine b.ext_elem fun i β¦ ?_
rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hΟ
rw [LinearEquiv.map_zero, Finsupp.zero_apply]
exact
(Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hΟ (Finsupp.lapply i ββ βb.repr)) _
β¨x, hx, rflβ©
theorem eq_bot_of_generator_maximal_submoduleImage_eq_zero {N O : Submodule R M} (b : Basis ΞΉ R O)
(hNO : N β€ O) {Ο : O ββ[R] R} (hΟ : β Ο : O ββ[R] R, Β¬Ο.submoduleImage N < Ο.submoduleImage N)
[(Ο.submoduleImage N).IsPrincipal] (hgen : generator (Ο.submoduleImage N) = 0) : N = β₯ := by
rw [Submodule.eq_bot_iff]
intro x hx
refine (mk_eq_zero _ _).mp (show (β¨x, hNO hxβ© : O) = 0 from b.ext_elem fun i β¦ ?_)
rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hΟ
rw [LinearEquiv.map_zero, Finsupp.zero_apply]
refine (Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hΟ (Finsupp.lapply i ββ βb.repr)) _ ?_
exact (LinearMap.mem_submoduleImage_of_le hNO).mpr β¨x, hx, rflβ©
end Ring
section IsDomain
variable {ΞΉ : Type*} {R : Type*} [CommRing R] [IsDomain R]
variable {M : Type*} [AddCommGroup M] [Module R M] {b : ΞΉ β M}
open Submodule.IsPrincipal Set Submodule
theorem dvd_generator_iff {I : Ideal R} [I.IsPrincipal] {x : R} (hx : x β I) :
x β£ generator I β I = Ideal.span {x} := by
conv_rhs => rw [β span_singleton_generator I]
| rw [Ideal.submodule_span_eq, Ideal.span_singleton_eq_span_singleton, β dvd_dvd_iff_associated,
β mem_iff_generator_dvd]
exact β¨fun h β¦ β¨hx, hβ©, fun h β¦ h.2β©
end IsDomain
| Mathlib/LinearAlgebra/FreeModule/PID.lean | 93 | 98 |
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying, RΓ©my Degenne
-/
import Mathlib.Probability.Process.Adapted
import Mathlib.MeasureTheory.Constructions.BorelSpace.Order
/-!
# Stopping times, stopped processes and stopped values
Definition and properties of stopping times.
## Main definitions
* `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a
function `Ο` such that for all `i`, the preimage of `{j | j β€ i}` along `Ο` is
`f i`-measurable
* `MeasureTheory.IsStoppingTime.measurableSpace`: the Ο-algebra associated with a stopping time
## Main results
* `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is
progressively measurable.
* `memLp_stoppedProcess`: if a process belongs to `βp` at every time in `β`, then its stopped
process belongs to `βp` as well.
## Tags
stopping time, stochastic process
-/
open Filter Order TopologicalSpace
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
variable {Ξ© Ξ² ΞΉ : Type*} {m : MeasurableSpace Ξ©}
/-! ### Stopping times -/
/-- A stopping time with respect to some filtration `f` is a function
`Ο` such that for all `i`, the preimage of `{j | j β€ i}` along `Ο` is measurable
with respect to `f i`.
Intuitively, the stopping time `Ο` describes some stopping rule such that at time
`i`, we may determine it with the information we have at time `i`. -/
def IsStoppingTime [Preorder ΞΉ] (f : Filtration ΞΉ m) (Ο : Ξ© β ΞΉ) :=
β i : ΞΉ, MeasurableSet[f i] <| {Ο | Ο Ο β€ i}
theorem isStoppingTime_const [Preorder ΞΉ] (f : Filtration ΞΉ m) (i : ΞΉ) :
IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const]
section MeasurableSet
section Preorder
variable [Preorder ΞΉ] {f : Filtration ΞΉ m} {Ο : Ξ© β ΞΉ}
protected theorem IsStoppingTime.measurableSet_le (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο β€ i} :=
hΟ i
theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο < i} := by
by_cases hi_min : IsMin i
Β· suffices {Ο : Ξ© | Ο Ο < i} = β
by rw [this]; exact @MeasurableSet.empty _ (f i)
ext1 Ο
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
rw [isMin_iff_forall_not_lt] at hi_min
exact hi_min (Ο Ο)
have : {Ο : Ξ© | Ο Ο < i} = Ο β»ΒΉ' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min]
rw [this]
exact f.mono (pred_le i) _ (hΟ.measurableSet_le <| pred i)
end Preorder
section CountableStoppingTime
namespace IsStoppingTime
variable [PartialOrder ΞΉ] {Ο : Ξ© β ΞΉ} {f : Filtration ΞΉ m}
protected theorem measurableSet_eq_of_countable_range (hΟ : IsStoppingTime f Ο)
(h_countable : (Set.range Ο).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο | Ο Ο = i} := by
have : {Ο | Ο Ο = i} = {Ο | Ο Ο β€ i} \ β (j β Set.range Ο) (_ : j < i), {Ο | Ο Ο β€ j} := by
ext1 a
simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq',
Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le]
constructor <;> intro h
Β· simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff]
Β· exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl
rw [this]
refine (hΟ.measurableSet_le i).diff ?_
refine MeasurableSet.biUnion h_countable fun j _ => ?_
classical
rw [Set.iUnion_eq_if]
split_ifs with hji
Β· exact f.mono hji.le _ (hΟ.measurableSet_le j)
Β· exact @MeasurableSet.empty _ (f i)
protected theorem measurableSet_eq_of_countable [Countable ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο = i} :=
hΟ.measurableSet_eq_of_countable_range (Set.to_countable _) i
protected theorem measurableSet_lt_of_countable_range (hΟ : IsStoppingTime f Ο)
(h_countable : (Set.range Ο).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο | Ο Ο < i} := by
have : {Ο | Ο Ο < i} = {Ο | Ο Ο β€ i} \ {Ο | Ο Ο = i} := by ext1 Ο; simp [lt_iff_le_and_ne]
rw [this]
exact (hΟ.measurableSet_le i).diff (hΟ.measurableSet_eq_of_countable_range h_countable i)
protected theorem measurableSet_lt_of_countable [Countable ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο < i} :=
hΟ.measurableSet_lt_of_countable_range (Set.to_countable _) i
protected theorem measurableSet_ge_of_countable_range {ΞΉ} [LinearOrder ΞΉ] {Ο : Ξ© β ΞΉ}
{f : Filtration ΞΉ m} (hΟ : IsStoppingTime f Ο) (h_countable : (Set.range Ο).Countable) (i : ΞΉ) :
MeasurableSet[f i] {Ο | i β€ Ο Ο} := by
have : {Ο | i β€ Ο Ο} = {Ο | Ο Ο < i}αΆ := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt]
rw [this]
exact (hΟ.measurableSet_lt_of_countable_range h_countable i).compl
protected theorem measurableSet_ge_of_countable {ΞΉ} [LinearOrder ΞΉ] {Ο : Ξ© β ΞΉ} {f : Filtration ΞΉ m}
[Countable ΞΉ] (hΟ : IsStoppingTime f Ο) (i : ΞΉ) : MeasurableSet[f i] {Ο | i β€ Ο Ο} :=
hΟ.measurableSet_ge_of_countable_range (Set.to_countable _) i
end IsStoppingTime
end CountableStoppingTime
section LinearOrder
variable [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο : Ξ© β ΞΉ}
theorem IsStoppingTime.measurableSet_gt (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | i < Ο Ο} := by
have : {Ο | i < Ο Ο} = {Ο | Ο Ο β€ i}αΆ := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le]
rw [this]
exact (hΟ.measurableSet_le i).compl
section TopologicalSpace
variable [TopologicalSpace ΞΉ] [OrderTopology ΞΉ] [FirstCountableTopology ΞΉ]
/-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/
theorem IsStoppingTime.measurableSet_lt_of_isLUB (hΟ : IsStoppingTime f Ο) (i : ΞΉ)
(h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {Ο | Ο Ο < i} := by
by_cases hi_min : IsMin i
Β· suffices {Ο | Ο Ο < i} = β
by rw [this]; exact @MeasurableSet.empty _ (f i)
ext1 Ο
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
exact isMin_iff_forall_not_lt.mp hi_min (Ο Ο)
obtain β¨seq, -, -, h_tendsto, h_boundβ© :
β seq : β β ΞΉ, Monotone seq β§ (β j, seq j β€ i) β§ Tendsto seq atTop (π i) β§ β j, seq j < i :=
h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min)
have h_Ioi_eq_Union : Set.Iio i = β j, {k | k β€ seq j} := by
ext1 k
simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq]
refine β¨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_β©
Β· rw [tendsto_atTop'] at h_tendsto
have h_nhds : Set.Ici k β π i :=
mem_nhds_iff.mpr β¨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_iβ©
obtain β¨a, haβ© : β a : β, β b : β, b β₯ a β k β€ seq b := h_tendsto (Set.Ici k) h_nhds
exact β¨a, ha a le_rflβ©
Β· obtain β¨j, hk_seq_jβ© := h_exists_k_le_seq
exact hk_seq_j.trans_lt (h_bound j)
have h_lt_eq_preimage : {Ο | Ο Ο < i} = Ο β»ΒΉ' Set.Iio i := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio]
rw [h_lt_eq_preimage, h_Ioi_eq_Union]
simp only [Set.preimage_iUnion, Set.preimage_setOf_eq]
exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hΟ.measurableSet_le (seq n))
theorem IsStoppingTime.measurableSet_lt (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο < i} := by
obtain β¨i', hi'_lubβ© : β i', IsLUB (Set.Iio i) i' := exists_lub_Iio i
rcases lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i | h_Iio_eq_Iic
Β· rw [β hi'_eq_i] at hi'_lub β’
exact hΟ.measurableSet_lt_of_isLUB i' hi'_lub
Β· have h_lt_eq_preimage : {Ο : Ξ© | Ο Ο < i} = Ο β»ΒΉ' Set.Iio i := rfl
rw [h_lt_eq_preimage, h_Iio_eq_Iic]
exact f.mono (lub_Iio_le i hi'_lub) _ (hΟ.measurableSet_le i')
theorem IsStoppingTime.measurableSet_ge (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | i β€ Ο Ο} := by
have : {Ο | i β€ Ο Ο} = {Ο | Ο Ο < i}αΆ := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt]
rw [this]
exact (hΟ.measurableSet_lt i).compl
theorem IsStoppingTime.measurableSet_eq (hΟ : IsStoppingTime f Ο) (i : ΞΉ) :
MeasurableSet[f i] {Ο | Ο Ο = i} := by
have : {Ο | Ο Ο = i} = {Ο | Ο Ο β€ i} β© {Ο | Ο Ο β₯ i} := by
ext1 Ο; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff]
rw [this]
exact (hΟ.measurableSet_le i).inter (hΟ.measurableSet_ge i)
theorem IsStoppingTime.measurableSet_eq_le (hΟ : IsStoppingTime f Ο) {i j : ΞΉ} (hle : i β€ j) :
MeasurableSet[f j] {Ο | Ο Ο = i} :=
f.mono hle _ <| hΟ.measurableSet_eq i
theorem IsStoppingTime.measurableSet_lt_le (hΟ : IsStoppingTime f Ο) {i j : ΞΉ} (hle : i β€ j) :
MeasurableSet[f j] {Ο | Ο Ο < i} :=
f.mono hle _ <| hΟ.measurableSet_lt i
end TopologicalSpace
end LinearOrder
section Countable
theorem isStoppingTime_of_measurableSet_eq [Preorder ΞΉ] [Countable ΞΉ] {f : Filtration ΞΉ m}
{Ο : Ξ© β ΞΉ} (hΟ : β i, MeasurableSet[f i] {Ο | Ο Ο = i}) : IsStoppingTime f Ο := by
intro i
rw [show {Ο | Ο Ο β€ i} = β k β€ i, {Ο | Ο Ο = k} by ext; simp]
refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_
exact f.mono hk _ (hΟ k)
end Countable
end MeasurableSet
namespace IsStoppingTime
protected theorem max [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο Ο : Ξ© β ΞΉ} (hΟ : IsStoppingTime f Ο)
(hΟ : IsStoppingTime f Ο) : IsStoppingTime f fun Ο => max (Ο Ο) (Ο Ο) := by
intro i
simp_rw [max_le_iff, Set.setOf_and]
exact (hΟ i).inter (hΟ i)
protected theorem max_const [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο : Ξ© β ΞΉ}
(hΟ : IsStoppingTime f Ο) (i : ΞΉ) : IsStoppingTime f fun Ο => max (Ο Ο) i :=
hΟ.max (isStoppingTime_const f i)
protected theorem min [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο Ο : Ξ© β ΞΉ} (hΟ : IsStoppingTime f Ο)
(hΟ : IsStoppingTime f Ο) : IsStoppingTime f fun Ο => min (Ο Ο) (Ο Ο) := by
intro i
simp_rw [min_le_iff, Set.setOf_or]
exact (hΟ i).union (hΟ i)
protected theorem min_const [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο : Ξ© β ΞΉ}
(hΟ : IsStoppingTime f Ο) (i : ΞΉ) : IsStoppingTime f fun Ο => min (Ο Ο) i :=
hΟ.min (isStoppingTime_const f i)
|
theorem add_const [AddGroup ΞΉ] [Preorder ΞΉ] [AddRightMono ΞΉ]
[AddLeftMono ΞΉ] {f : Filtration ΞΉ m} {Ο : Ξ© β ΞΉ} (hΟ : IsStoppingTime f Ο)
{i : ΞΉ} (hi : 0 β€ i) : IsStoppingTime f fun Ο => Ο Ο + i := by
intro j
| Mathlib/Probability/Process/Stopping.lean | 248 | 252 |
/-
Copyright (c) 2022 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Function.ConvergenceInMeasure
import Mathlib.MeasureTheory.Function.L1Space.Integrable
/-!
# Uniform integrability
This file contains the definitions for uniform integrability (both in the measure theory sense
as well as the probability theory sense). This file also contains the Vitali convergence theorem
which establishes a relation between uniform integrability, convergence in measure and
Lp convergence.
Uniform integrability plays a vital role in the theory of martingales most notably is used to
formulate the martingale convergence theorem.
## Main definitions
* `MeasureTheory.UnifIntegrable`: uniform integrability in the measure theory sense.
In particular, a sequence of functions `f` is uniformly integrable if for all `Ξ΅ > 0`, there
exists some `Ξ΄ > 0` such that for all sets `s` of smaller measure than `Ξ΄`, the Lp-norm of
`f i` restricted `s` is smaller than `Ξ΅` for all `i`.
* `MeasureTheory.UniformIntegrable`: uniform integrability in the probability theory sense.
In particular, a sequence of measurable functions `f` is uniformly integrable in the
probability theory sense if it is uniformly integrable in the measure theory sense and
has uniformly bounded Lp-norm.
# Main results
* `MeasureTheory.unifIntegrable_finite`: a finite sequence of Lp functions is uniformly
integrable.
* `MeasureTheory.tendsto_Lp_finite_of_tendsto_ae`: a sequence of Lp functions which is uniformly
integrable converges in Lp if they converge almost everywhere.
* `MeasureTheory.tendstoInMeasure_iff_tendsto_Lp_finite`: Vitali convergence theorem:
a sequence of Lp functions converges in Lp if and only if it is uniformly integrable
and converges in measure.
## Tags
uniform integrable, uniformly absolutely continuous integral, Vitali convergence theorem
-/
noncomputable section
open scoped MeasureTheory NNReal ENNReal Topology
namespace MeasureTheory
open Set Filter TopologicalSpace
variable {Ξ± Ξ² ΞΉ : Type*} {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} [NormedAddCommGroup Ξ²]
/-- Uniform integrability in the measure theory sense.
A sequence of functions `f` is said to be uniformly integrable if for all `Ξ΅ > 0`, there exists
some `Ξ΄ > 0` such that for all sets `s` with measure less than `Ξ΄`, the Lp-norm of `f i`
restricted on `s` is less than `Ξ΅`.
Uniform integrability is also known as uniformly absolutely continuous integrals. -/
def UnifIntegrable {_ : MeasurableSpace Ξ±} (f : ΞΉ β Ξ± β Ξ²) (p : ββ₯0β) (ΞΌ : Measure Ξ±) : Prop :=
β β¦Ξ΅ : ββ¦ (_ : 0 < Ξ΅), β (Ξ΄ : β) (_ : 0 < Ξ΄), β i s,
MeasurableSet s β ΞΌ s β€ ENNReal.ofReal Ξ΄ β eLpNorm (s.indicator (f i)) p ΞΌ β€ ENNReal.ofReal Ξ΅
/-- In probability theory, a family of measurable functions is uniformly integrable if it is
uniformly integrable in the measure theory sense and is uniformly bounded. -/
def UniformIntegrable {_ : MeasurableSpace Ξ±} (f : ΞΉ β Ξ± β Ξ²) (p : ββ₯0β) (ΞΌ : Measure Ξ±) : Prop :=
(β i, AEStronglyMeasurable (f i) ΞΌ) β§ UnifIntegrable f p ΞΌ β§ β C : ββ₯0, β i, eLpNorm (f i) p ΞΌ β€ C
namespace UniformIntegrable
protected theorem aestronglyMeasurable {f : ΞΉ β Ξ± β Ξ²} {p : ββ₯0β} (hf : UniformIntegrable f p ΞΌ)
(i : ΞΉ) : AEStronglyMeasurable (f i) ΞΌ :=
hf.1 i
@[deprecated (since := "2025-04-09")]
alias aeStronglyMeasurable := UniformIntegrable.aestronglyMeasurable
protected theorem unifIntegrable {f : ΞΉ β Ξ± β Ξ²} {p : ββ₯0β} (hf : UniformIntegrable f p ΞΌ) :
UnifIntegrable f p ΞΌ :=
hf.2.1
protected theorem memLp {f : ΞΉ β Ξ± β Ξ²} {p : ββ₯0β} (hf : UniformIntegrable f p ΞΌ) (i : ΞΉ) :
MemLp (f i) p ΞΌ :=
β¨hf.1 i,
let β¨_, _, hCβ© := hf.2
lt_of_le_of_lt (hC i) ENNReal.coe_lt_topβ©
end UniformIntegrable
section UnifIntegrable
/-! ### `UnifIntegrable`
This section deals with uniform integrability in the measure theory sense. -/
namespace UnifIntegrable
variable {f g : ΞΉ β Ξ± β Ξ²} {p : ββ₯0β}
protected theorem add (hf : UnifIntegrable f p ΞΌ) (hg : UnifIntegrable g p ΞΌ) (hp : 1 β€ p)
(hf_meas : β i, AEStronglyMeasurable (f i) ΞΌ) (hg_meas : β i, AEStronglyMeasurable (g i) ΞΌ) :
UnifIntegrable (f + g) p ΞΌ := by
intro Ξ΅ hΞ΅
have hΞ΅2 : 0 < Ξ΅ / 2 := half_pos hΞ΅
obtain β¨Ξ΄β, hΞ΄β_pos, hfΞ΄ββ© := hf hΞ΅2
obtain β¨Ξ΄β, hΞ΄β_pos, hgΞ΄ββ© := hg hΞ΅2
refine β¨min Ξ΄β Ξ΄β, lt_min hΞ΄β_pos hΞ΄β_pos, fun i s hs hΞΌs => ?_β©
simp_rw [Pi.add_apply, Set.indicator_add']
refine (eLpNorm_add_le ((hf_meas i).indicator hs) ((hg_meas i).indicator hs) hp).trans ?_
have hΞ΅_halves : ENNReal.ofReal Ξ΅ = ENNReal.ofReal (Ξ΅ / 2) + ENNReal.ofReal (Ξ΅ / 2) := by
rw [β ENNReal.ofReal_add hΞ΅2.le hΞ΅2.le, add_halves]
rw [hΞ΅_halves]
exact add_le_add (hfΞ΄β i s hs (hΞΌs.trans (ENNReal.ofReal_le_ofReal (min_le_left _ _))))
(hgΞ΄β i s hs (hΞΌs.trans (ENNReal.ofReal_le_ofReal (min_le_right _ _))))
protected theorem neg (hf : UnifIntegrable f p ΞΌ) : UnifIntegrable (-f) p ΞΌ := by
simp_rw [UnifIntegrable, Pi.neg_apply, Set.indicator_neg', eLpNorm_neg]
exact hf
protected theorem sub (hf : UnifIntegrable f p ΞΌ) (hg : UnifIntegrable g p ΞΌ) (hp : 1 β€ p)
(hf_meas : β i, AEStronglyMeasurable (f i) ΞΌ) (hg_meas : β i, AEStronglyMeasurable (g i) ΞΌ) :
UnifIntegrable (f - g) p ΞΌ := by
rw [sub_eq_add_neg]
exact hf.add hg.neg hp hf_meas fun i => (hg_meas i).neg
protected theorem ae_eq (hf : UnifIntegrable f p ΞΌ) (hfg : β n, f n =α΅[ΞΌ] g n) :
UnifIntegrable g p ΞΌ := by
classical
intro Ξ΅ hΞ΅
obtain β¨Ξ΄, hΞ΄_pos, hfΞ΄β© := hf hΞ΅
refine β¨Ξ΄, hΞ΄_pos, fun n s hs hΞΌs => (le_of_eq <| eLpNorm_congr_ae ?_).trans (hfΞ΄ n s hs hΞΌs)β©
filter_upwards [hfg n] with x hx
simp_rw [Set.indicator_apply, hx]
/-- Uniform integrability is preserved by restriction of the functions to a set. -/
protected theorem indicator (hf : UnifIntegrable f p ΞΌ) (E : Set Ξ±) :
UnifIntegrable (fun i => E.indicator (f i)) p ΞΌ := fun Ξ΅ hΞ΅ β¦ by
obtain β¨Ξ΄, hΞ΄_pos, hΞ΅β© := hf hΞ΅
refine β¨Ξ΄, hΞ΄_pos, fun i s hs hΞΌs β¦ ?_β©
calc
eLpNorm (s.indicator (E.indicator (f i))) p ΞΌ
= eLpNorm (E.indicator (s.indicator (f i))) p ΞΌ := by
simp only [indicator_indicator, inter_comm]
_ β€ eLpNorm (s.indicator (f i)) p ΞΌ := eLpNorm_indicator_le _
_ β€ ENNReal.ofReal Ξ΅ := hΞ΅ _ _ hs hΞΌs
/-- Uniform integrability is preserved by restriction of the measure to a set. -/
protected theorem restrict (hf : UnifIntegrable f p ΞΌ) (E : Set Ξ±) :
UnifIntegrable f p (ΞΌ.restrict E) := fun Ξ΅ hΞ΅ β¦ by
obtain β¨Ξ΄, hΞ΄_pos, hδΡ⩠:= hf hΞ΅
refine β¨Ξ΄, hΞ΄_pos, fun i s hs hΞΌs β¦ ?_β©
rw [ΞΌ.restrict_apply hs, β measure_toMeasurable] at hΞΌs
calc
eLpNorm (indicator s (f i)) p (ΞΌ.restrict E) = eLpNorm (f i) p (ΞΌ.restrict (s β© E)) := by
rw [eLpNorm_indicator_eq_eLpNorm_restrict hs, ΞΌ.restrict_restrict hs]
_ β€ eLpNorm (f i) p (ΞΌ.restrict (toMeasurable ΞΌ (s β© E))) :=
eLpNorm_mono_measure _ <| Measure.restrict_mono (subset_toMeasurable _ _) le_rfl
_ = eLpNorm (indicator (toMeasurable ΞΌ (s β© E)) (f i)) p ΞΌ :=
(eLpNorm_indicator_eq_eLpNorm_restrict (measurableSet_toMeasurable _ _)).symm
_ †ENNReal.ofReal Ρ := hδΡ i _ (measurableSet_toMeasurable _ _) hμs
end UnifIntegrable
theorem unifIntegrable_zero_meas [MeasurableSpace Ξ±] {p : ββ₯0β} {f : ΞΉ β Ξ± β Ξ²} :
UnifIntegrable f p (0 : Measure Ξ±) :=
fun Ξ΅ _ => β¨1, one_pos, fun i s _ _ => by simpβ©
theorem unifIntegrable_congr_ae {p : ββ₯0β} {f g : ΞΉ β Ξ± β Ξ²} (hfg : β n, f n =α΅[ΞΌ] g n) :
UnifIntegrable f p ΞΌ β UnifIntegrable g p ΞΌ :=
β¨fun hf => hf.ae_eq hfg, fun hg => hg.ae_eq fun n => (hfg n).symmβ©
theorem tendsto_indicator_ge (f : Ξ± β Ξ²) (x : Ξ±) :
Tendsto (fun M : β => { x | (M : β) β€ βf xββ }.indicator f x) atTop (π 0) := by
refine tendsto_atTop_of_eventually_const (iβ := Nat.ceil (βf xββ : β) + 1) fun n hn => ?_
rw [Set.indicator_of_not_mem]
simp only [not_le, Set.mem_setOf_eq]
refine lt_of_le_of_lt (Nat.le_ceil _) ?_
refine lt_of_lt_of_le (lt_add_one _) ?_
norm_cast
variable {p : ββ₯0β}
section
variable {f : Ξ± β Ξ²}
/-- This lemma is weaker than `MeasureTheory.MemLp.integral_indicator_norm_ge_nonneg_le`
as the latter provides `0 β€ M` and does not require the measurability of `f`. -/
theorem MemLp.integral_indicator_norm_ge_le (hf : MemLp f 1 ΞΌ) (hmeas : StronglyMeasurable f)
{Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) :
β M : β, (β«β» x, β{ x | M β€ βf xββ }.indicator f xββ βΞΌ) β€ ENNReal.ofReal Ξ΅ := by
have htendsto :
βα΅ x βΞΌ, Tendsto (fun M : β => { x | (M : β) β€ βf xββ }.indicator f x) atTop (π 0) :=
univ_mem' (id fun x => tendsto_indicator_ge f x)
have hmeas : β M : β, AEStronglyMeasurable ({ x | (M : β) β€ βf xββ }.indicator f) ΞΌ := by
intro M
apply hf.1.indicator
apply StronglyMeasurable.measurableSet_le stronglyMeasurable_const
hmeas.nnnorm.measurable.coe_nnreal_real.stronglyMeasurable
have hbound : HasFiniteIntegral (fun x => βf xβ) ΞΌ := by
rw [memLp_one_iff_integrable] at hf
exact hf.norm.2
have : Tendsto (fun n : β β¦ β«β» a, ENNReal.ofReal β{ x | n β€ βf xββ }.indicator f a - 0β βΞΌ)
atTop (π 0) := by
refine tendsto_lintegral_norm_of_dominated_convergence hmeas hbound ?_ htendsto
refine fun n => univ_mem' (id fun x => ?_)
by_cases hx : (n : β) β€ βf xβ
Β· dsimp
rwa [Set.indicator_of_mem]
Β· dsimp
rw [Set.indicator_of_not_mem, norm_zero]
Β· exact norm_nonneg _
Β· assumption
rw [ENNReal.tendsto_atTop_zero] at this
obtain β¨M, hMβ© := this (ENNReal.ofReal Ξ΅) (ENNReal.ofReal_pos.2 hΞ΅)
simp only [zero_tsub, zero_le, sub_zero, zero_add, coe_nnnorm,
Set.mem_Icc] at hM
refine β¨M, ?_β©
convert hM M le_rfl
simp only [coe_nnnorm, ENNReal.ofReal_eq_coe_nnreal (norm_nonneg _)]
rfl
/-- This lemma is superseded by `MeasureTheory.MemLp.integral_indicator_norm_ge_nonneg_le`
which does not require measurability. -/
theorem MemLp.integral_indicator_norm_ge_nonneg_le_of_meas (hf : MemLp f 1 ΞΌ)
(hmeas : StronglyMeasurable f) {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) :
β M : β, 0 β€ M β§ (β«β» x, β{ x | M β€ βf xββ }.indicator f xββ βΞΌ) β€ ENNReal.ofReal Ξ΅ :=
let β¨M, hMβ© := hf.integral_indicator_norm_ge_le hmeas hΞ΅
β¨max M 0, le_max_right _ _, by simpaβ©
theorem MemLp.integral_indicator_norm_ge_nonneg_le (hf : MemLp f 1 ΞΌ) {Ξ΅ : β} (hΞ΅ : 0 < Ξ΅) :
β M : β, 0 β€ M β§ (β«β» x, β{ x | M β€ βf xββ }.indicator f xββ βΞΌ) β€ ENNReal.ofReal Ξ΅ := by
have hf_mk : MemLp (hf.1.mk f) 1 ΞΌ := (memLp_congr_ae hf.1.ae_eq_mk).mp hf
obtain β¨M, hM_pos, hfMβ© :=
hf_mk.integral_indicator_norm_ge_nonneg_le_of_meas hf.1.stronglyMeasurable_mk hΞ΅
refine β¨M, hM_pos, (le_of_eq ?_).trans hfMβ©
refine lintegral_congr_ae ?_
filter_upwards [hf.1.ae_eq_mk] with x hx
simp only [Set.indicator_apply, coe_nnnorm, Set.mem_setOf_eq, ENNReal.coe_inj, hx.symm]
theorem MemLp.eLpNormEssSup_indicator_norm_ge_eq_zero (hf : MemLp f β ΞΌ)
(hmeas : StronglyMeasurable f) :
β M : β, eLpNormEssSup ({ x | M β€ βf xββ }.indicator f) ΞΌ = 0 := by
have hbdd : eLpNormEssSup f ΞΌ < β := hf.eLpNorm_lt_top
refine β¨(eLpNorm f β ΞΌ + 1).toReal, ?_β©
rw [eLpNormEssSup_indicator_eq_eLpNormEssSup_restrict]
Β· have : ΞΌ.restrict { x : Ξ± | (eLpNorm f β€ ΞΌ + 1).toReal β€ βf xββ } = 0 := by
simp only [coe_nnnorm, eLpNorm_exponent_top, Measure.restrict_eq_zero]
have : { x : Ξ± | (eLpNormEssSup f ΞΌ + 1).toReal β€ βf xβ } β
{ x : Ξ± | eLpNormEssSup f ΞΌ < βf xββ } := by
intro x hx
rw [Set.mem_setOf_eq, β ENNReal.toReal_lt_toReal hbdd.ne ENNReal.coe_lt_top.ne,
ENNReal.coe_toReal, coe_nnnorm]
refine lt_of_lt_of_le ?_ hx
rw [ENNReal.toReal_lt_toReal hbdd.ne]
Β· exact ENNReal.lt_add_right hbdd.ne one_ne_zero
Β· exact (ENNReal.add_lt_top.2 β¨hbdd, ENNReal.one_lt_topβ©).ne
rw [β nonpos_iff_eq_zero]
refine (measure_mono this).trans ?_
have hle := enorm_ae_le_eLpNormEssSup f ΞΌ
simp_rw [ae_iff, not_le] at hle
exact nonpos_iff_eq_zero.2 hle
rw [this, eLpNormEssSup_measure_zero]
exact measurableSet_le measurable_const hmeas.nnnorm.measurable.subtype_coe
/- This lemma is slightly weaker than `MeasureTheory.MemLp.eLpNorm_indicator_norm_ge_pos_le` as the
latter provides `0 < M`. -/
theorem MemLp.eLpNorm_indicator_norm_ge_le (hf : MemLp f p ΞΌ) (hmeas : StronglyMeasurable f) {Ξ΅ : β}
(hΞ΅ : 0 < Ξ΅) : β M : β, eLpNorm ({ x | M β€ βf xββ }.indicator f) p ΞΌ β€ ENNReal.ofReal Ξ΅ := by
by_cases hp_ne_zero : p = 0
Β· refine β¨1, hp_ne_zero.symm βΈ ?_β©
simp [eLpNorm_exponent_zero]
by_cases hp_ne_top : p = β
Β· subst hp_ne_top
obtain β¨M, hMβ© := hf.eLpNormEssSup_indicator_norm_ge_eq_zero hmeas
refine β¨M, ?_β©
simp only [eLpNorm_exponent_top, hM, zero_le]
obtain β¨M, hM', hMβ© := MemLp.integral_indicator_norm_ge_nonneg_le
(ΞΌ := ΞΌ) (hf.norm_rpow hp_ne_zero hp_ne_top) (Real.rpow_pos_of_pos hΞ΅ p.toReal)
refine β¨M ^ (1 / p.toReal), ?_β©
rw [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top, β ENNReal.rpow_one (ENNReal.ofReal Ξ΅)]
conv_rhs => rw [β mul_one_div_cancel (ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm]
rw [ENNReal.rpow_mul,
ENNReal.rpow_le_rpow_iff (one_div_pos.2 <| ENNReal.toReal_pos hp_ne_zero hp_ne_top),
ENNReal.ofReal_rpow_of_pos hΞ΅]
convert hM using 3 with x
rw [enorm_indicator_eq_indicator_enorm, enorm_indicator_eq_indicator_enorm]
have hiff : M ^ (1 / p.toReal) β€ βf xββ β M β€ ββf xβ ^ p.toRealββ := by
rw [coe_nnnorm, coe_nnnorm, Real.norm_rpow_of_nonneg (norm_nonneg _), norm_norm,
β Real.rpow_le_rpow_iff hM' (Real.rpow_nonneg (norm_nonneg _) _)
(one_div_pos.2 <| ENNReal.toReal_pos hp_ne_zero hp_ne_top), β Real.rpow_mul (norm_nonneg _),
mul_one_div_cancel (ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm, Real.rpow_one]
by_cases hx : x β { x : Ξ± | M ^ (1 / p.toReal) β€ βf xββ }
| Β· rw [Set.indicator_of_mem hx, Set.indicator_of_mem, Real.enorm_of_nonneg (by positivity),
β ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) ENNReal.toReal_nonneg, ofReal_norm]
rw [Set.mem_setOf_eq]
rwa [β hiff]
Β· rw [Set.indicator_of_not_mem hx, Set.indicator_of_not_mem]
Β· simp [ENNReal.toReal_pos hp_ne_zero hp_ne_top]
Β· rw [Set.mem_setOf_eq]
rwa [β hiff]
/-- This lemma implies that a single function is uniformly integrable (in the probability sense). -/
| Mathlib/MeasureTheory/Function/UniformIntegrable.lean | 298 | 307 |
/-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.LinearAlgebra.Dimension.Constructions
/-!
# Some results on free modules over rings satisfying strong rank condition
This file contains some results on free modules over rings satisfying strong rank condition.
Most of them are generalized from the same result assuming the base ring being division ring,
and are moved from the files `Mathlib/LinearAlgebra/Dimension/DivisionRing.lean`
and `Mathlib/LinearAlgebra/FiniteDimensional.lean`.
-/
open Cardinal Module Module Set Submodule
universe u v
section Module
variable {K : Type u} {V : Type v} [Ring K] [StrongRankCondition K] [AddCommGroup V] [Module K V]
/-- The `ΞΉ` indexed basis on `V`, where `ΞΉ` is an empty type and `V` is zero-dimensional.
See also `Module.finBasis`.
-/
noncomputable def Basis.ofRankEqZero [Module.Free K V] {ΞΉ : Type*} [IsEmpty ΞΉ]
(hV : Module.rank K V = 0) : Basis ΞΉ K V :=
haveI : Subsingleton V := by
obtain β¨_, bβ© := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (hV βΈ b.mk_eq_rank'')
exact b.repr.toEquiv.subsingleton
Basis.empty _
@[simp]
theorem Basis.ofRankEqZero_apply [Module.Free K V] {ΞΉ : Type*} [IsEmpty ΞΉ]
(hV : Module.rank K V = 0) (i : ΞΉ) : Basis.ofRankEqZero hV i = 0 := rfl
theorem le_rank_iff_exists_linearIndependent [Module.Free K V] {c : Cardinal} :
c β€ Module.rank K V β β s : Set V, #s = c β§ LinearIndepOn K id s := by
haveI := nontrivial_of_invariantBasisNumber K
constructor
Β· intro h
obtain β¨ΞΊ, t'β© := Module.Free.exists_basis (R := K) (M := V)
let t := t'.reindexRange
have : LinearIndepOn K id (Set.range t') := by
convert t.linearIndependent.linearIndepOn_id
ext
simp [t]
rw [β t.mk_eq_rank'', le_mk_iff_exists_subset] at h
rcases h with β¨s, hst, hscβ©
exact β¨s, hsc, this.mono hstβ©
Β· rintro β¨s, rfl, siβ©
exact si.cardinal_le_rank
theorem le_rank_iff_exists_linearIndependent_finset
[Module.Free K V] {n : β} : βn β€ Module.rank K V β
β s : Finset V, s.card = n β§ LinearIndependent K ((β) : β₯(s : Set V) β V) := by
simp only [le_rank_iff_exists_linearIndependent, mk_set_eq_nat_iff_finset]
constructor
Β· rintro β¨s, β¨t, rfl, rflβ©, siβ©
exact β¨t, rfl, siβ©
Β· rintro β¨s, rfl, siβ©
exact β¨s, β¨s, rfl, rflβ©, siβ©
/-- A vector space has dimension at most `1` if and only if there is a
single vector of which all vectors are multiples. -/
theorem rank_le_one_iff [Module.Free K V] :
Module.rank K V β€ 1 β β vβ : V, β v, β r : K, r β’ vβ = v := by
obtain β¨ΞΊ, bβ© := Module.Free.exists_basis (R := K) (M := V)
constructor
Β· intro hd
rw [β b.mk_eq_rank'', le_one_iff_subsingleton] at hd
rcases isEmpty_or_nonempty ΞΊ with hb | β¨β¨iβ©β©
Β· use 0
have h' : β v : V, v = 0 := by
simpa [range_eq_empty, Submodule.eq_bot_iff] using b.span_eq.symm
intro v
simp [h' v]
Β· use b i
have h' : (K β b i) = β€ :=
(subsingleton_range b).eq_singleton_of_mem (mem_range_self i) βΈ b.span_eq
intro v
have hv : v β (β€ : Submodule K V) := mem_top
rwa [β h', mem_span_singleton] at hv
Β· rintro β¨vβ, hvββ©
have h : (K β vβ) = β€ := by
ext
simp [mem_span_singleton, hvβ]
rw [β rank_top, β h]
refine (rank_span_le _).trans_eq ?_
simp
/-- A vector space has dimension `1` if and only if there is a
single non-zero vector of which all vectors are multiples. -/
theorem rank_eq_one_iff [Module.Free K V] :
Module.rank K V = 1 β β vβ : V, vβ β 0 β§ β v, β r : K, r β’ vβ = v := by
haveI := nontrivial_of_invariantBasisNumber K
refine β¨fun h β¦ ?_, fun β¨vβ, h, hvβ© β¦ (rank_le_one_iff.2 β¨vβ, hvβ©).antisymm ?_β©
Β· obtain β¨vβ, hvβ© := rank_le_one_iff.1 h.le
refine β¨vβ, fun hzero β¦ ?_, hvβ©
simp_rw [hzero, smul_zero, exists_const] at hv
haveI : Subsingleton V := .intro fun _ _ β¦ by simp_rw [β hv]
exact one_ne_zero (h βΈ rank_subsingleton' K V)
Β· by_contra H
rw [not_le, lt_one_iff_zero] at H
obtain β¨ΞΊ, bβ© := Module.Free.exists_basis (R := K) (M := V)
haveI := mk_eq_zero_iff.1 (H βΈ b.mk_eq_rank'')
haveI := b.repr.toEquiv.subsingleton
exact h (Subsingleton.elim _ _)
/-- A submodule has dimension at most `1` if and only if there is a
single vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_le_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s β€ 1 β β vβ β s, s β€ K β vβ := by
simp_rw [rank_le_one_iff, le_span_singleton_iff]
constructor
Β· rintro β¨β¨vβ, hvββ©, hβ©
use vβ, hvβ
intro v hv
obtain β¨r, hrβ© := h β¨v, hvβ©
use r
rwa [Subtype.ext_iff, coe_smul] at hr
Β· rintro β¨vβ, hvβ, hβ©
use β¨vβ, hvββ©
rintro β¨v, hvβ©
obtain β¨r, hrβ© := h v hv
use r
rwa [Subtype.ext_iff, coe_smul]
/-- A submodule has dimension `1` if and only if there is a
single non-zero vector in the submodule such that the submodule is contained in
its span. -/
theorem rank_submodule_eq_one_iff (s : Submodule K V) [Module.Free K s] :
Module.rank K s = 1 β β vβ β s, vβ β 0 β§ s β€ K β vβ := by
simp_rw [rank_eq_one_iff, le_span_singleton_iff]
refine β¨fun β¨β¨vβ, hvββ©, H, hβ© β¦ β¨vβ, hvβ, fun h' β¦ by
simp only [h', ne_eq] at H; exact H rfl, fun v hv β¦ ?_β©,
fun β¨vβ, hvβ, H, hβ© β¦ β¨β¨vβ, hvββ©,
fun h' β¦ H (by rwa [AddSubmonoid.mk_eq_zero] at h'), fun β¨v, hvβ© β¦ ?_β©β©
Β· obtain β¨r, hrβ© := h β¨v, hvβ©
exact β¨r, by rwa [Subtype.ext_iff, coe_smul] at hrβ©
Β· obtain β¨r, hrβ© := h v hv
exact β¨r, by rwa [Subtype.ext_iff, coe_smul]β©
/-- A submodule has dimension at most `1` if and only if there is a
single vector, not necessarily in the submodule, such that the
submodule is contained in its span. -/
theorem rank_submodule_le_one_iff' (s : Submodule K V) [Module.Free K s] :
Module.rank K s β€ 1 β β vβ, s β€ K β vβ := by
haveI := nontrivial_of_invariantBasisNumber K
constructor
Β· rw [rank_submodule_le_one_iff]
rintro β¨vβ, _, hβ©
exact β¨vβ, hβ©
Β· rintro β¨vβ, hβ©
obtain β¨ΞΊ, bβ© := Module.Free.exists_basis (R := K) (M := s)
simpa [b.mk_eq_rank''] using b.linearIndependent.map' _ (ker_inclusion _ _ h)
|>.cardinal_le_rank.trans (rank_span_le {vβ})
theorem Submodule.rank_le_one_iff_isPrincipal (W : Submodule K V) [Module.Free K W] :
Module.rank K W β€ 1 β W.IsPrincipal := by
simp only [rank_le_one_iff, Submodule.isPrincipal_iff, le_antisymm_iff, le_span_singleton_iff,
span_singleton_le_iff_mem]
constructor
Β· rintro β¨β¨m, hmβ©, hm'β©
choose f hf using hm'
exact β¨m, β¨fun v hv => β¨f β¨v, hvβ©, congr_arg ((β) : W β V) (hf β¨v, hvβ©)β©, hmβ©β©
Β· rintro β¨a, β¨h, haβ©β©
choose f hf using h
exact β¨β¨a, haβ©, fun v => β¨f v.1 v.2, Subtype.ext (hf v.1 v.2)β©β©
theorem Module.rank_le_one_iff_top_isPrincipal [Module.Free K V] :
Module.rank K V β€ 1 β (β€ : Submodule K V).IsPrincipal := by
haveI := Module.Free.of_equiv (topEquiv (R := K) (M := V)).symm
rw [β Submodule.rank_le_one_iff_isPrincipal, rank_top]
/-- A module has dimension 1 iff there is some `v : V` so `{v}` is a basis.
-/
theorem finrank_eq_one_iff [Module.Free K V] (ΞΉ : Type*) [Unique ΞΉ] :
finrank K V = 1 β Nonempty (Basis ΞΉ K V) := by
constructor
Β· intro h
exact β¨Module.basisUnique ΞΉ hβ©
Β· rintro β¨bβ©
simpa using finrank_eq_card_basis b
/-- A module has dimension 1 iff there is some nonzero `v : V` so every vector is a multiple of `v`.
-/
theorem finrank_eq_one_iff' [Module.Free K V] :
finrank K V = 1 β β v β 0, β w : V, β c : K, c β’ v = w := by
rw [β rank_eq_one_iff]
exact toNat_eq_iff one_ne_zero
/-- A finite dimensional module has dimension at most 1 iff
there is some `v : V` so every vector is a multiple of `v`.
| -/
theorem finrank_le_one_iff [Module.Free K V] [Module.Finite K V] :
finrank K V β€ 1 β β v : V, β w : V, β c : K, c β’ v = w := by
rw [β rank_le_one_iff, β finrank_eq_rank, Nat.cast_le_one]
| Mathlib/LinearAlgebra/Dimension/FreeAndStrongRankCondition.lean | 203 | 206 |
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine
import Mathlib.Tactic.IntervalCases
/-!
# Triangles
This file proves basic geometrical results about distances and angles
in (possibly degenerate) triangles in real inner product spaces and
Euclidean affine spaces. More specialized results, and results
developed for simplices in general rather than just for triangles, are
in separate files. Definitions and results that make sense in more
general affine spaces rather than just in the Euclidean case go under
`LinearAlgebra.AffineSpace`.
## Implementation notes
Results in this file are generally given in a form with only those
non-degeneracy conditions needed for the particular result, rather
than requiring affine independence of the points of a triangle
unnecessarily.
## References
* https://en.wikipedia.org/wiki/Law_of_cosines
* https://en.wikipedia.org/wiki/Pons_asinorum
* https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle
-/
noncomputable section
open scoped CharZero Real RealInnerProductSpace
namespace InnerProductGeometry
/-!
### Geometrical results on triangles in real inner product spaces
This section develops some results on (possibly degenerate) triangles
in real inner product spaces, where those definitions and results can
most conveniently be developed in terms of vectors and then used to
deduce corresponding results for Euclidean affine spaces.
-/
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace β V]
/-- **Law of cosines** (cosine rule), vector angle form. -/
theorem norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (x y : V) :
βx - yβ * βx - yβ = βxβ * βxβ + βyβ * βyβ - 2 * βxβ * βyβ * Real.cos (angle x y) := by
rw [show 2 * βxβ * βyβ * Real.cos (angle x y) = 2 * (Real.cos (angle x y) * (βxβ * βyβ)) by ring,
cos_angle_mul_norm_mul_norm, β real_inner_self_eq_norm_mul_norm, β
real_inner_self_eq_norm_mul_norm, β real_inner_self_eq_norm_mul_norm, real_inner_sub_sub_self,
sub_add_eq_add_sub]
/-- **Pons asinorum**, vector angle form. -/
theorem angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : βxβ = βyβ) :
angle x (x - y) = angle y (y - x) := by
refine Real.injOn_cos β¨angle_nonneg _ _, angle_le_pi _ _β© β¨angle_nonneg _ _, angle_le_pi _ _β© ?_
rw [cos_angle, cos_angle, h, β neg_sub, norm_neg, neg_sub, inner_sub_right, inner_sub_right,
real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y]
/-- **Converse of pons asinorum**, vector angle form. -/
theorem norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V}
(h : angle x (x - y) = angle y (y - x)) (hpi : angle x y β Ο) : βxβ = βyβ := by
replace h := Real.arccos_injOn (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y)))
(abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h
by_cases hxy : x = y
Β· rw [hxy]
Β· rw [β norm_neg (y - x), neg_sub, mul_comm, mul_comm βyβ, div_eq_mul_inv, div_eq_mul_inv,
mul_inv_rev, mul_inv_rev, β mul_assoc, β mul_assoc] at h
replace h :=
mul_right_cancelβ (inv_ne_zero fun hz => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz))) h
rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm,
real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib,
mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub, β mul_sub_left_distrib] at h
by_cases hx0 : x = 0
Β· rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h
rw [hx0, norm_zero, h]
Β· by_cases hy0 : y = 0
Β· rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h
rw [hy0, norm_zero, h]
Β· rw [inv_sub_inv (fun hz => hx0 (norm_eq_zero.1 hz)) fun hz => hy0 (norm_eq_zero.1 hz), β
neg_sub, β mul_div_assoc, mul_comm, mul_div_assoc, β mul_neg_one] at h
symm
by_contra hyx
replace h := (mul_left_cancelβ (sub_ne_zero_of_ne hyx) h).symm
rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, β angle_eq_pi_iff] at h
exact hpi h
/-- The cosine of the sum of two angles in a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
theorem cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle {x y : V} (hx : x β 0) (hy : y β 0) :
Real.cos (angle x (x - y) + angle y (y - x)) = -Real.cos (angle x y) := by
by_cases hxy : x = y
Β· rw [hxy, angle_self hy]
simp
Β· rw [Real.cos_add, cos_angle, cos_angle, cos_angle]
have hxn : βxβ β 0 := fun h => hx (norm_eq_zero.1 h)
have hyn : βyβ β 0 := fun h => hy (norm_eq_zero.1 h)
have hxyn : βx - yβ β 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))
apply mul_right_cancelβ hxn
apply mul_right_cancelβ hyn
apply mul_right_cancelβ hxyn
apply mul_right_cancelβ hxyn
have H1 :
Real.sin (angle x (x - y)) * Real.sin (angle y (y - x)) * βxβ * βyβ * βx - yβ * βx - yβ =
Real.sin (angle x (x - y)) * (βxβ * βx - yβ) *
(Real.sin (angle y (y - x)) * (βyβ * βx - yβ)) := by
ring
have H2 :
βͺx, xβ« * (βͺx, xβ« - βͺx, yβ« - (βͺx, yβ« - βͺy, yβ«)) - (βͺx, xβ« - βͺx, yβ«) * (βͺx, xβ« - βͺx, yβ«) =
βͺx, xβ« * βͺy, yβ« - βͺx, yβ« * βͺx, yβ« := by
ring
have H3 :
βͺy, yβ« * (βͺy, yβ« - βͺx, yβ« - (βͺx, yβ« - βͺx, xβ«)) - (βͺy, yβ« - βͺx, yβ«) * (βͺy, yβ« - βͺx, yβ«) =
βͺx, xβ« * βͺy, yβ« - βͺx, yβ« * βͺx, yβ« := by
ring
rw [mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib,
H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, sin_angle_mul_norm_mul_norm,
norm_sub_rev y x, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right,
inner_sub_right, inner_sub_right, real_inner_comm x y, H2, H3,
Real.mul_self_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y)),
real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two]
-- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow
-- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster.
simp (disch := field_simp_discharge) only [sub_div', div_div, mul_div_assoc',
div_mul_eq_mul_div, div_sub', neg_div', neg_sub, eq_div_iff, div_eq_iff]
ring
/-- The sine of the sum of two angles in a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
theorem sin_angle_sub_add_angle_sub_rev_eq_sin_angle {x y : V} (hx : x β 0) (hy : y β 0) :
Real.sin (angle x (x - y) + angle y (y - x)) = Real.sin (angle x y) := by
by_cases hxy : x = y
Β· rw [hxy, angle_self hy]
simp
Β· rw [Real.sin_add, cos_angle, cos_angle]
have hxn : βxβ β 0 := fun h => hx (norm_eq_zero.1 h)
have hyn : βyβ β 0 := fun h => hy (norm_eq_zero.1 h)
have hxyn : βx - yβ β 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h))
apply mul_right_cancelβ hxn
apply mul_right_cancelβ hyn
apply mul_right_cancelβ hxyn
apply mul_right_cancelβ hxyn
have H1 :
Real.sin (angle x (x - y)) * (βͺy, y - xβ« / (βyβ * βy - xβ)) * βxβ * βyβ * βx - yβ =
Real.sin (angle x (x - y)) * (βxβ * βx - yβ) * (βͺy, y - xβ« / (βyβ * βy - xβ)) * βyβ := by
ring
have H2 :
βͺx, x - yβ« / (βxβ * βy - xβ) * Real.sin (angle y (y - x)) * βxβ * βyβ * βy - xβ =
βͺx, x - yβ« / (βxβ * βy - xβ) * (Real.sin (angle y (y - x)) * (βyβ * βy - xβ)) * βxβ := by
ring
have H3 :
βͺx, xβ« * (βͺx, xβ« - βͺx, yβ« - (βͺx, yβ« - βͺy, yβ«)) - (βͺx, xβ« - βͺx, yβ«) * (βͺx, xβ« - βͺx, yβ«) =
βͺx, xβ« * βͺy, yβ« - βͺx, yβ« * βͺx, yβ« := by
ring
have H4 :
βͺy, yβ« * (βͺy, yβ« - βͺx, yβ« - (βͺx, yβ« - βͺx, xβ«)) - (βͺy, yβ« - βͺx, yβ«) * (βͺy, yβ« - βͺx, yβ«) =
βͺx, xβ« * βͺy, yβ« - βͺx, yβ« * βͺx, yβ« := by
ring
rw [right_distrib, right_distrib, right_distrib, right_distrib, H1, sin_angle_mul_norm_mul_norm,
norm_sub_rev x y, H2, sin_angle_mul_norm_mul_norm, norm_sub_rev y x,
mul_assoc (Real.sin (angle x y)), sin_angle_mul_norm_mul_norm, inner_sub_left, inner_sub_left,
inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H3,
H4, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two]
-- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow
-- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster.
simp (disch := field_simp_discharge) only [mul_div_assoc', div_mul_eq_mul_div, div_div,
sub_div', Real.sqrt_div', Real.sqrt_mul_self, add_div', div_add', eq_div_iff, div_eq_iff]
ring
/-- The cosine of the sum of the angles of a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
theorem cos_angle_add_angle_sub_add_angle_sub_eq_neg_one {x y : V} (hx : x β 0) (hy : y β 0) :
Real.cos (angle x y + angle x (x - y) + angle y (y - x)) = -1 := by
rw [add_assoc, Real.cos_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy,
sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy, mul_neg, β neg_add', add_comm, β sq, β sq,
Real.sin_sq_add_cos_sq]
/-- The sine of the sum of the angles of a possibly degenerate
triangle (where two given sides are nonzero), vector angle form. -/
theorem sin_angle_add_angle_sub_add_angle_sub_eq_zero {x y : V} (hx : x β 0) (hy : y β 0) :
Real.sin (angle x y + angle x (x - y) + angle y (y - x)) = 0 := by
rw [add_assoc, Real.sin_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy,
sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy]
ring
/-- The sum of the angles of a possibly degenerate triangle (where the
two given sides are nonzero), vector angle form. -/
theorem angle_add_angle_sub_add_angle_sub_eq_pi {x y : V} (hx : x β 0) (hy : y β 0) :
angle x y + angle x (x - y) + angle y (y - x) = Ο := by
have hcos := cos_angle_add_angle_sub_add_angle_sub_eq_neg_one hx hy
have hsin := sin_angle_add_angle_sub_add_angle_sub_eq_zero hx hy
rw [Real.sin_eq_zero_iff] at hsin
obtain β¨n, hnβ© := hsin
symm at hn
have h0 : 0 β€ angle x y + angle x (x - y) + angle y (y - x) :=
| add_nonneg (add_nonneg (angle_nonneg _ _) (angle_nonneg _ _)) (angle_nonneg _ _)
have h3lt : angle x y + angle x (x - y) + angle y (y - x) < Ο + Ο + Ο := by
by_contra hnlt
have hxy : angle x y = Ο := by
by_contra hxy
exact hnlt (add_lt_add_of_lt_of_le (add_lt_add_of_lt_of_le (lt_of_le_of_ne
(angle_le_pi _ _) hxy) (angle_le_pi _ _)) (angle_le_pi _ _))
rw [hxy] at hnlt
rw [angle_eq_pi_iff] at hxy
rcases hxy with β¨hx, β¨r, β¨hr, hxrβ©β©β©
rw [hxr, β one_smul β x, β mul_smul, mul_one, β sub_smul, one_smul, sub_eq_add_neg,
angle_smul_right_of_pos _ _ (add_pos zero_lt_one (neg_pos_of_neg hr)), angle_self hx,
add_zero] at hnlt
apply hnlt
rw [add_assoc]
exact add_lt_add_left (lt_of_le_of_lt (angle_le_pi _ _) (lt_add_of_pos_right Ο Real.pi_pos)) _
have hn0 : 0 β€ n := by
rw [hn, mul_nonneg_iff_left_nonneg_of_pos Real.pi_pos] at h0
norm_cast at h0
have hn3 : n < 3 := by
rw [hn, show Ο + Ο + Ο = 3 * Ο by ring] at h3lt
replace h3lt := lt_of_mul_lt_mul_right h3lt (le_of_lt Real.pi_pos)
norm_cast at h3lt
interval_cases n
Β· simp [hn] at hcos
Β· norm_num [hn]
Β· simp [hn] at hcos
end InnerProductGeometry
namespace EuclideanGeometry
/-!
### Geometrical results on triangles in Euclidean affine spaces
| Mathlib/Geometry/Euclidean/Triangle.lean | 207 | 241 |
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.Dual
import Mathlib.Analysis.InnerProductSpace.Orientation
import Mathlib.Data.Complex.FiniteDimensional
import Mathlib.Data.Complex.Orientation
import Mathlib.Tactic.LinearCombination
/-!
# Oriented two-dimensional real inner product spaces
This file defines constructions specific to the geometry of an oriented two-dimensional real inner
product space `E`.
## Main declarations
* `Orientation.areaForm`: an antisymmetric bilinear form `E ββ[β] E ββ[β] β` (usual notation `Ο`).
Morally, when `Ο` is evaluated on two vectors, it gives the oriented area of the parallelogram
they span. (But mathlib does not yet have a construction of oriented area, and in fact the
construction of oriented area should pass through `Ο`.)
* `Orientation.rightAngleRotation`: an isometric automorphism `E ββα΅’[β] E` (usual notation `J`).
This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined,
in such a way that this automorphism is equal to rotation by 90 degrees.
* `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]`
for `E`.
* `Orientation.kahler`: a complex-valued real-bilinear map `E ββ[β] E ββ[β] β`. Its real part is the
inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`,
the complex number `o.kahler x y` has modulus `βxβ * βyβ`. In a later file, oriented angles
(`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the
oriented angle from `x` to `y`.
## Main results
* `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x`
* `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if
and only if `0 β€ βͺx, yβ«` and `Ο x y = 0`
* `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = βaβ ^ 2 * o.kahler x y`
* `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete
interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner
product space `β`
* `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`,
`Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `β`,
expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete
interpretations on `β`
## Implementation notes
Notation `Ο` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be
defined locally in each file which uses them, since otherwise one would need a more cumbersome
notation which mentions the orientation explicitly (something like `Ο[o]`). Write
```
local notation "Ο" => o.areaForm
local notation "J" => o.rightAngleRotation
```
-/
noncomputable section
open scoped RealInnerProductSpace ComplexConjugate
open Module
lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K]
[AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V :=
.of_fact_finrank_eq_succ 1
attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two
variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace β E] [Fact (finrank β E = 2)]
(o : Orientation β E (Fin 2))
namespace Orientation
/-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual
notation `Ο`). When evaluated on two vectors, it gives the oriented area of the parallelogram they
span. -/
irreducible_def areaForm : E ββ[β] E ββ[β] β := by
let z : E [β^Fin 0]ββ[β] β ββ[β] β :=
AlternatingMap.constLinearEquivOfIsEmpty.symm
let y : E [β^Fin 1]ββ[β] β ββ[β] E ββ[β] β :=
LinearMap.llcomp β E (E [β^Fin 0]ββ[β] β) β z ββ AlternatingMap.curryLeftLinearMap
exact y ββ AlternatingMap.curryLeftLinearMap (R' := β) o.volumeForm
local notation "Ο" => o.areaForm
theorem areaForm_to_volumeForm (x y : E) : Ο x y = o.volumeForm ![x, y] := by simp [areaForm]
@[simp]
theorem areaForm_apply_self (x : E) : Ο x x = 0 := by
rw [areaForm_to_volumeForm]
refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) β 1)
Β· simp
Β· norm_num
theorem areaForm_swap (x y : E) : Ο x y = -Ο y x := by
simp only [areaForm_to_volumeForm]
convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) β 1)
Β· ext i
fin_cases i <;> rfl
Β· norm_num
@[simp]
theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by
ext x y
simp [areaForm_to_volumeForm]
/-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/
def areaForm' : E βL[β] E βL[β] β :=
LinearMap.toContinuousLinearMap
(β(LinearMap.toContinuousLinearMap : (E ββ[β] β) ββ[β] E βL[β] β) ββ o.areaForm)
@[simp]
theorem areaForm'_apply (x : E) :
o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) :=
rfl
theorem abs_areaForm_le (x y : E) : |Ο x y| β€ βxβ * βyβ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y]
theorem areaForm_le (x y : E) : Ο x y β€ βxβ * βyβ := by
simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y]
theorem abs_areaForm_of_orthogonal {x y : E} (h : βͺx, yβ« = 0) : |Ο x y| = βxβ * βyβ := by
rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal]
Β· simp [Fin.prod_univ_succ]
intro i j hij
fin_cases i <;> fin_cases j
Β· simp_all
Β· simpa using h
Β· simpa [real_inner_comm] using h
Β· simp_all
theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace β F]
| [hF : Fact (finrank β F = 2)] (Ο : E ββα΅’[β] F) (x y : F) :
(Orientation.map (Fin 2) Ο.toLinearEquiv o).areaForm x y =
| Mathlib/Analysis/InnerProductSpace/TwoDim.lean | 147 | 148 |
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.Group.Subgroup.Finite
import Mathlib.GroupTheory.GroupAction.Quotient
import Mathlib.GroupTheory.Perm.Basic
import Mathlib.LinearAlgebra.Alternating.Basic
import Mathlib.LinearAlgebra.Multilinear.TensorProduct
/-!
# Exterior product of alternating maps
In this file we define `AlternatingMap.domCoprod`
to be the exterior product of two alternating maps,
taking values in the tensor product of the codomains of the original maps.
-/
suppress_compilation
open TensorProduct
variable {ΞΉa ΞΉb : Type*} [Fintype ΞΉa] [Fintype ΞΉb]
variable {R' : Type*} {Mα΅’ Nβ Nβ : Type*} [CommSemiring R'] [AddCommGroup Nβ] [Module R' Nβ]
[AddCommGroup Nβ] [Module R' Nβ] [AddCommMonoid Mα΅’] [Module R' Mα΅’]
namespace Equiv.Perm
/-- Elements which are considered equivalent if they differ only by swaps within Ξ± or Ξ² -/
abbrev ModSumCongr (Ξ± Ξ² : Type*) :=
_ β§Έ (Equiv.Perm.sumCongrHom Ξ± Ξ²).range
end Equiv.Perm
namespace AlternatingMap
open Equiv
variable [DecidableEq ΞΉa] [DecidableEq ΞΉb]
/-- summand used in `AlternatingMap.domCoprod` -/
def domCoprod.summand (a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ) (b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ)
(Ο : Perm.ModSumCongr ΞΉa ΞΉb) : MultilinearMap R' (fun _ : ΞΉa β ΞΉb => Mα΅’) (Nβ β[R'] Nβ) :=
Quotient.liftOn' Ο
(fun Ο =>
Equiv.Perm.sign Ο β’
(MultilinearMap.domCoprod βa βb : MultilinearMap R' (fun _ => Mα΅’) (Nβ β Nβ)).domDomCongr Ο)
fun Οβ Οβ H => by
rw [QuotientGroup.leftRel_apply] at H
obtain β¨β¨sl, srβ©, hβ© := H
ext v
simp only [MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply,
coe_multilinearMap, MultilinearMap.smul_apply]
replace h := inv_mul_eq_iff_eq_mul.mp h.symm
have : Equiv.Perm.sign (Οβ * Perm.sumCongrHom _ _ (sl, sr))
= Equiv.Perm.sign Οβ * (Equiv.Perm.sign sl * Equiv.Perm.sign sr) := by simp
rw [h, this, mul_smul, mul_smul, smul_left_cancel_iff, β TensorProduct.tmul_smul,
TensorProduct.smul_tmul', a.map_congr_perm _ sl, b.map_congr_perm _ sr]
simp only [Sum.map_inr, Perm.sumCongrHom_apply, Perm.sumCongr_apply, Sum.map_inl,
Function.comp_def, Perm.coe_mul]
theorem domCoprod.summand_mk'' (a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ) (b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ)
(Ο : Equiv.Perm (ΞΉa β ΞΉb)) :
domCoprod.summand a b (Quotient.mk'' Ο) =
Equiv.Perm.sign Ο β’
(MultilinearMap.domCoprod βa βb : MultilinearMap R' (fun _ => Mα΅’) (Nβ β Nβ)).domDomCongr
Ο :=
rfl
/-- Swapping elements in `Ο` with equal values in `v` results in an addition that cancels -/
theorem domCoprod.summand_add_swap_smul_eq_zero (a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ)
(b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ) (Ο : Perm.ModSumCongr ΞΉa ΞΉb) {v : ΞΉa β ΞΉb β Mα΅’}
{i j : ΞΉa β ΞΉb} (hv : v i = v j) (hij : i β j) :
domCoprod.summand a b Ο v + domCoprod.summand a b (swap i j β’ Ο) v = 0 := by
refine Quotient.inductionOn' Ο fun Ο => ?_
dsimp only [Quotient.liftOn'_mk'', Quotient.map'_mk'', MulAction.Quotient.smul_mk,
domCoprod.summand]
rw [smul_eq_mul, Perm.sign_mul, Perm.sign_swap hij]
simp only [one_mul, neg_mul, Function.comp_apply, Units.neg_smul, Perm.coe_mul, Units.val_neg,
MultilinearMap.smul_apply, MultilinearMap.neg_apply, MultilinearMap.domDomCongr_apply,
MultilinearMap.domCoprod_apply]
convert add_neg_cancel (G := Nβ β[R'] Nβ) _ using 6 <;>
Β· ext k
rw [Equiv.apply_swap_eq_self hv]
/-- Swapping elements in `Ο` with equal values in `v` result in zero if the swap has no effect
on the quotient. -/
theorem domCoprod.summand_eq_zero_of_smul_invariant (a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ)
(b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ) (Ο : Perm.ModSumCongr ΞΉa ΞΉb) {v : ΞΉa β ΞΉb β Mα΅’}
{i j : ΞΉa β ΞΉb} (hv : v i = v j) (hij : i β j) :
swap i j β’ Ο = Ο β domCoprod.summand a b Ο v = 0 := by
refine Quotient.inductionOn' Ο fun Ο => ?_
dsimp only [Quotient.liftOn'_mk'', Quotient.map'_mk'', MultilinearMap.smul_apply,
MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply, domCoprod.summand]
intro hΟ
obtain β¨β¨sl, srβ©, hΟβ© := QuotientGroup.leftRel_apply.mp (Quotient.exact' hΟ)
rcases hi : Οβ»ΒΉ i with i' | i' <;> rcases hj : Οβ»ΒΉ j with j' | j' <;>
rw [Perm.inv_eq_iff_eq] at hi hj <;> substs hi hj
-- the term pairs with and cancels another term
case inl.inr => simpa using Equiv.congr_fun hΟ (Sum.inl i')
case inr.inl => simpa using Equiv.congr_fun hΟ (Sum.inr i')
-- the term does not pair but is zero
case inl.inl =>
suffices (a fun i β¦ v (Ο (Sum.inl i))) = 0 by simp_all
exact AlternatingMap.map_eq_zero_of_eq _ _ hv fun hij' => hij (hij' βΈ rfl)
case inr.inr =>
suffices (b fun i β¦ v (Ο (Sum.inr i))) = 0 by simp_all
exact b.map_eq_zero_of_eq _ hv fun hij' => hij (hij' βΈ rfl)
/-- Like `MultilinearMap.domCoprod`, but ensures the result is also alternating.
Note that this is usually defined (for instance, as used in Proposition 22.24 in [Gallier2011Notes])
over integer indices `ΞΉa = Fin n` and `ΞΉb = Fin m`, as
$$
(f \wedge g)(u_1, \ldots, u_{m+n}) =
\sum_{\operatorname{shuffle}(m, n)} \operatorname{sign}(\sigma)
f(u_{\sigma(1)}, \ldots, u_{\sigma(m)}) g(u_{\sigma(m+1)}, \ldots, u_{\sigma(m+n)}),
$$
where $\operatorname{shuffle}(m, n)$ consists of all permutations of $[1, m+n]$ such that
$\sigma(1) < \cdots < \sigma(m)$ and $\sigma(m+1) < \cdots < \sigma(m+n)$.
Here, we generalize this by replacing:
* the product in the sum with a tensor product
* the filtering of $[1, m+n]$ to shuffles with an isomorphic quotient
* the additions in the subscripts of $\sigma$ with an index of type `Sum`
The specialized version can be obtained by combining this definition with `finSumFinEquiv` and
`LinearMap.mul'`.
-/
@[simps]
def domCoprod (a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ) (b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ) :
Mα΅’ [β^ΞΉa β ΞΉb]ββ[R'] (Nβ β[R'] Nβ) :=
{ β Ο : Perm.ModSumCongr ΞΉa ΞΉb, domCoprod.summand a b Ο with
toFun := fun v => (β(β Ο : Perm.ModSumCongr ΞΉa ΞΉb, domCoprod.summand a b Ο)) v
map_eq_zero_of_eq' := fun v i j hv hij => by
rw [MultilinearMap.sum_apply]
exact
Finset.sum_involution (fun Ο _ => Equiv.swap i j β’ Ο)
(fun Ο _ => domCoprod.summand_add_swap_smul_eq_zero a b Ο hv hij)
(fun Ο _ => mt <| domCoprod.summand_eq_zero_of_smul_invariant a b Ο hv hij)
(fun Ο _ => Finset.mem_univ _) fun Ο _ =>
Equiv.swap_smul_involutive i j Ο }
theorem domCoprod_coe (a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ) (b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ) :
(β(a.domCoprod b) : MultilinearMap R' (fun _ => Mα΅’) _) =
β Ο : Perm.ModSumCongr ΞΉa ΞΉb, domCoprod.summand a b Ο :=
MultilinearMap.ext fun _ => rfl
/-- A more bundled version of `AlternatingMap.domCoprod` that maps
`((ΞΉβ β N) β Nβ) β ((ΞΉβ β N) β Nβ)` to `(ΞΉβ β ΞΉβ β N) β Nβ β Nβ`. -/
def domCoprod' :
(Mα΅’ [β^ΞΉa]ββ[R'] Nβ) β[R'] (Mα΅’ [β^ΞΉb]ββ[R'] Nβ) ββ[R']
(Mα΅’ [β^ΞΉa β ΞΉb]ββ[R'] (Nβ β[R'] Nβ)) :=
TensorProduct.lift <| by
refine
LinearMap.mkβ R' domCoprod (fun mβ mβ n => ?_) (fun c m n => ?_) (fun m nβ nβ => ?_)
fun c m n => ?_ <;>
Β· ext
simp only [domCoprod_apply, add_apply, smul_apply, β Finset.sum_add_distrib,
Finset.smul_sum, MultilinearMap.sum_apply, domCoprod.summand]
congr
ext Ο
refine Quotient.inductionOn' Ο fun Ο => ?_
simp only [Quotient.liftOn'_mk'', coe_add, coe_smul, MultilinearMap.smul_apply,
β MultilinearMap.domCoprod'_apply]
simp only [TensorProduct.add_tmul, β TensorProduct.smul_tmul', TensorProduct.tmul_add,
TensorProduct.tmul_smul, LinearMap.map_add, LinearMap.map_smul]
first | rw [β smul_add] | rw [smul_comm]
rfl
@[simp]
theorem domCoprod'_apply (a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ) (b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ) :
domCoprod' (a ββ[R'] b) = domCoprod a b :=
rfl
end AlternatingMap
open Equiv
/-- A helper lemma for `MultilinearMap.domCoprod_alternization`. -/
theorem MultilinearMap.domCoprod_alternization_coe [DecidableEq ΞΉa] [DecidableEq ΞΉb]
(a : MultilinearMap R' (fun _ : ΞΉa => Mα΅’) Nβ) (b : MultilinearMap R' (fun _ : ΞΉb => Mα΅’) Nβ) :
MultilinearMap.domCoprod (MultilinearMap.alternatization a)
(MultilinearMap.alternatization b) =
β Οa : Perm ΞΉa, β Οb : Perm ΞΉb,
Equiv.Perm.sign Οa β’ Equiv.Perm.sign Οb β’
MultilinearMap.domCoprod (a.domDomCongr Οa) (b.domDomCongr Οb) := by
simp_rw [β MultilinearMap.domCoprod'_apply, MultilinearMap.alternatization_coe]
simp_rw [TensorProduct.sum_tmul, TensorProduct.tmul_sum, _root_.map_sum,
β TensorProduct.smul_tmul', TensorProduct.tmul_smul]
rfl
open AlternatingMap
open Perm in
/-- Computing the `MultilinearMap.alternatization` of the `MultilinearMap.domCoprod` is the same
as computing the `AlternatingMap.domCoprod` of the `MultilinearMap.alternatization`s.
-/
theorem MultilinearMap.domCoprod_alternization [DecidableEq ΞΉa] [DecidableEq ΞΉb]
(a : MultilinearMap R' (fun _ : ΞΉa => Mα΅’) Nβ) (b : MultilinearMap R' (fun _ : ΞΉb => Mα΅’) Nβ) :
MultilinearMap.alternatization (MultilinearMap.domCoprod a b) =
a.alternatization.domCoprod (MultilinearMap.alternatization b) := by
apply coe_multilinearMap_injective
rw [domCoprod_coe, MultilinearMap.alternatization_coe,
Finset.sum_partition (QuotientGroup.leftRel (Perm.sumCongrHom ΞΉa ΞΉb).range)]
congr 1
ext1 Ο
induction Ο using Quotient.inductionOn' with
| h Ο =>
set f := sumCongrHom ΞΉa ΞΉb
calc
β Ο β _, sign Ο β’ domDomCongr Ο (a.domCoprod b) =
β Ο β {Ο | Οβ»ΒΉ * Ο β f.range}, sign Ο β’ domDomCongr Ο (a.domCoprod b) := by
simp [QuotientGroup.leftRel_apply, f]
_ = β Ο β {Ο | Οβ»ΒΉ β f.range}, sign (Ο * Ο) β’ domDomCongr (Ο * Ο) (a.domCoprod b) := by
conv_lhs => rw [β Finset.map_univ_equiv (Equiv.mulLeft Ο), Finset.filter_map, Finset.sum_map]
simp [Function.comp_def, -MonoidHom.mem_range]
_ = β Ο, sign (Ο * f Ο) β’ domDomCongr (Ο * f Ο) (a.domCoprod b) := by
simp_rw [f, Subgroup.inv_mem_iff, MonoidHom.mem_range, Finset.univ_filter_exists,
Finset.sum_image sumCongrHom_injective.injOn]
_ = β Ο : Perm ΞΉa Γ Perm ΞΉb,
sign Ο β’ (domDomCongrEquiv Ο) (sign Ο.1 β’ sign Ο.2 β’
(domDomCongr Ο.1 a).domCoprod (domDomCongr Ο.2 b)) := by
simp [f, domDomCongr_mul, domCoprod_domDomCongr_sumCongr, mul_smul]
_ = domCoprod.summand (alternatization a) (alternatization b) (Quotient.mk'' Ο) := by
simp [domCoprod.summand_mk'', domCoprod_alternization_coe, β domDomCongrEquiv_apply,
Finset.smul_sum, β Finset.sum_product']
| /-- Taking the `MultilinearMap.alternatization` of the `MultilinearMap.domCoprod` of two
`AlternatingMap`s gives a scaled version of the `AlternatingMap.coprod` of those maps.
-/
theorem MultilinearMap.domCoprod_alternization_eq [DecidableEq ΞΉa] [DecidableEq ΞΉb]
(a : Mα΅’ [β^ΞΉa]ββ[R'] Nβ) (b : Mα΅’ [β^ΞΉb]ββ[R'] Nβ) :
MultilinearMap.alternatization
(MultilinearMap.domCoprod a b : MultilinearMap R' (fun _ : ΞΉa β ΞΉb => Mα΅’) (Nβ β Nβ)) =
((Fintype.card ΞΉa).factorial * (Fintype.card ΞΉb).factorial) β’ a.domCoprod b := by
rw [MultilinearMap.domCoprod_alternization, coe_alternatization, coe_alternatization, mul_smul,
β AlternatingMap.domCoprod'_apply, β AlternatingMap.domCoprod'_apply,
β TensorProduct.smul_tmul', TensorProduct.tmul_smul,
LinearMap.map_smul_of_tower AlternatingMap.domCoprod',
LinearMap.map_smul_of_tower AlternatingMap.domCoprod']
| Mathlib/LinearAlgebra/Alternating/DomCoprod.lean | 230 | 266 |
/-
Copyright (c) 2022 Vincent Beffara. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Vincent Beffara
-/
import Mathlib.Analysis.Analytic.IsolatedZeros
import Mathlib.Analysis.Complex.CauchyIntegral
import Mathlib.Analysis.Complex.AbsMax
import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas
/-!
# The open mapping theorem for holomorphic functions
This file proves the open mapping theorem for holomorphic functions, namely that an analytic
function on a preconnected set of the complex plane is either constant or open. The main step is to
show a local version of the theorem that states that if `f` is analytic at a point `zβ`, then either
it is constant in a neighborhood of `zβ` or it maps any neighborhood of `zβ` to a neighborhood of
its image `f zβ`. The results extend in higher dimension to `g : E β β`.
The proof of the local version on `β` goes through two main steps: first, assuming that the function
is not constant around `zβ`, use the isolated zero principle to show that `βf zβ` is bounded below
on a small `sphere zβ r` around `zβ`, and then use the maximum principle applied to the auxiliary
function `(fun z β¦ βf z - vβ)` to show that any `v` close enough to `f zβ` is in `f '' ball zβ r`.
That second step is implemented in `DiffContOnCl.ball_subset_image_closedBall`.
## Main results
* `AnalyticAt.eventually_constant_or_nhds_le_map_nhds` is the local version of the open mapping
theorem around a point;
* `AnalyticOnNhd.is_constant_or_isOpen` is the open mapping theorem on a connected open set.
-/
open Set Filter Metric Complex
open scoped Topology
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β E] {U : Set E} {f : β β β} {g : E β β}
{zβ : β} {Ξ΅ r : β}
/-- If the modulus of a holomorphic function `f` is bounded below by `Ξ΅` on a circle, then its range
contains a disk of radius `Ξ΅ / 2`. -/
theorem DiffContOnCl.ball_subset_image_closedBall (h : DiffContOnCl β f (ball zβ r)) (hr : 0 < r)
| (hf : β z β sphere zβ r, Ξ΅ β€ βf z - f zββ) (hzβ : βαΆ z in π zβ, f z β f zβ) :
ball (f zβ) (Ξ΅ / 2) β f '' closedBall zβ r := by
/- This is a direct application of the maximum principle. Pick `v` close to `f zβ`, and look at
the function `fun z β¦ βf z - vβ`: it is bounded below on the circle, and takes a small value
at `zβ` so it is not constant on the disk, which implies that its infimum is equal to `0` and
hence that `v` is in the range of `f`. -/
rintro v hv
have h1 : DiffContOnCl β (fun z => f z - v) (ball zβ r) := h.sub_const v
have h2 : ContinuousOn (fun z => βf z - vβ) (closedBall zβ r) :=
continuous_norm.comp_continuousOn (closure_ball zβ hr.ne.symm βΈ h1.continuousOn)
have h3 : AnalyticOnNhd β f (ball zβ r) := h.differentiableOn.analyticOnNhd isOpen_ball
have h4 : β z β sphere zβ r, Ξ΅ / 2 β€ βf z - vβ := fun z hz => by
linarith [hf z hz, show βv - f zββ < Ξ΅ / 2 from mem_ball.mp hv,
norm_sub_sub_norm_sub_le_norm_sub (f z) v (f zβ)]
have h5 : βf zβ - vβ < Ξ΅ / 2 := by simpa [β dist_eq_norm, dist_comm] using mem_ball.mp hv
obtain β¨z, hz1, hz2β© : β z β ball zβ r, IsLocalMin (fun z => βf z - vβ) z :=
exists_isLocalMin_mem_ball h2 (mem_closedBall_self hr.le) fun z hz => h5.trans_le (h4 z hz)
refine β¨z, ball_subset_closedBall hz1, sub_eq_zero.mp ?_β©
have h6 := h1.differentiableOn.eventually_differentiableAt (isOpen_ball.mem_nhds hz1)
refine (eventually_eq_or_eq_zero_of_isLocalMin_norm h6 hz2).resolve_left fun key => ?_
have h7 : βαΆ w in π z, f w = f z := by filter_upwards [key] with h; field_simp
replace h7 : βαΆ w in π[β ] z, f w = f z := (h7.filter_mono nhdsWithin_le_nhds).frequently
have h8 : IsPreconnected (ball zβ r) := (convex_ball zβ r).isPreconnected
have h9 := h3.eqOn_of_preconnected_of_frequently_eq analyticOnNhd_const h8 hz1 h7
have h10 : f z = f zβ := (h9 (mem_ball_self hr)).symm
exact not_eventually.mpr hzβ (mem_of_superset (ball_mem_nhds zβ hr) (h10 βΈ h9))
| Mathlib/Analysis/Complex/OpenMapping.lean | 44 | 70 |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Data.List.Lattice
import Mathlib.Data.Bool.Basic
import Mathlib.Order.Lattice
/-!
# Intervals in β
This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m`
and strictly less than `n`.
## TODO
- Define `Ioo` and `Icc`, state basic lemmas about them.
- Also do the versions for integers?
- One could generalise even further, defining 'locally finite partial orders', for which
`Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model.
- Once the above is done, get rid of `Int.range` (and maybe `List.range'`?).
-/
open Nat
namespace List
/-- `Ico n m` is the list of natural numbers `n β€ x < m`.
(Ico stands for "interval, closed-open".)
See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well
as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico`
for sets, multisets and finite sets respectively.
-/
def Ico (n m : β) : List β :=
range' n (m - n)
namespace Ico
theorem zero_bot (n : β) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range']
@[simp]
theorem length (n m : β) : length (Ico n m) = m - n := by
dsimp [Ico]
simp [length_range']
theorem pairwise_lt (n m : β) : Pairwise (Β· < Β·) (Ico n m) := by
dsimp [Ico]
simp [pairwise_lt_range']
theorem nodup (n m : β) : Nodup (Ico n m) := by
dsimp [Ico]
simp [nodup_range']
@[simp]
theorem mem {n m l : β} : l β Ico n m β n β€ l β§ l < m := by
suffices n β€ l β§ l < n + (m - n) β n β€ l β§ l < m by simp [Ico, this]
omega
theorem eq_nil_of_le {n m : β} (h : m β€ n) : Ico n m = [] := by
simp [Ico, Nat.sub_eq_zero_iff_le.mpr h]
theorem map_add (n m k : β) : (Ico n m).map (k + Β·) = Ico (n + k) (m + k) := by
rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k]
theorem map_sub (n m k : β) (hβ : k β€ n) :
((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by
rw [Ico, Ico, Nat.sub_sub_sub_cancel_right hβ, map_sub_range' hβ]
@[simp]
theorem self_empty {n : β} : Ico n n = [] :=
eq_nil_of_le (le_refl n)
@[simp]
theorem eq_empty_iff {n m : β} : Ico n m = [] β m β€ n :=
Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [β length, h, List.length]) eq_nil_of_le
theorem append_consecutive {n m l : β} (hnm : n β€ m) (hml : m β€ l) :
Ico n m ++ Ico m l = Ico n l := by
dsimp only [Ico]
convert range'_append using 2
Β· rw [Nat.one_mul, Nat.add_sub_cancel' hnm]
Β· omega
@[simp]
theorem inter_consecutive (n m l : β) : Ico n m β© Ico m l = [] := by
apply eq_nil_iff_forall_not_mem.2
intro a
simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem]
intro _ hβ hβ
exfalso
exact not_lt_of_ge hβ hβ
@[simp]
theorem bagInter_consecutive (n m l : Nat) :
@List.bagInter β instBEqOfDecidableEq (Ico n m) (Ico m l) = [] :=
(bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l)
@[simp]
theorem succ_singleton {n : β} : Ico n (n + 1) = [n] := by
dsimp [Ico]
simp [range', Nat.add_sub_cancel_left]
theorem succ_top {n m : β} (h : n β€ m) : Ico n (m + 1) = Ico n m ++ [m] := by
rwa [β succ_singleton, append_consecutive]
exact Nat.le_succ _
theorem eq_cons {n m : β} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by
rw [β append_consecutive (Nat.le_succ n) h, succ_singleton]
rfl
@[simp]
theorem pred_singleton {m : β} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by
simp [Ico, Nat.sub_sub_self (succ_le_of_lt h)]
theorem chain'_succ (n m : β) : Chain' (fun a b => b = succ a) (Ico n m) := by
by_cases h : n < m
Β· rw [eq_cons h]
exact chain_succ_range' _ _ 1
Β· rw [eq_nil_of_le (le_of_not_gt h)]
trivial
theorem not_mem_top {n m : β} : m β Ico n m := by simp
theorem filter_lt_of_top_le {n m l : β} (hml : m β€ l) :
((Ico n m).filter fun x => x < l) = Ico n m :=
filter_eq_self.2 fun k hk => by
simp only [(lt_of_lt_of_le (mem.1 hk).2 hml), decide_true]
theorem filter_lt_of_le_bot {n m l : β} (hln : l β€ n) : ((Ico n m).filter fun x => x < l) = [] :=
filter_eq_nil_iff.2 fun k hk => by
simp only [decide_eq_true_eq, not_lt]
apply le_trans hln
exact (mem.1 hk).1
theorem filter_lt_of_ge {n m l : β} (hlm : l β€ m) :
((Ico n m).filter fun x => x < l) = Ico n l := by
rcases le_total n l with hnl | hln
Β· rw [β append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l),
filter_lt_of_le_bot (le_refl l), append_nil]
Β· rw [eq_nil_of_le hln, filter_lt_of_le_bot hln]
@[simp]
theorem filter_lt (n m l : β) :
((Ico n m).filter fun x => x < l) = Ico n (min m l) := by
rcases le_total m l with hml | hlm
Β· rw [min_eq_left hml, filter_lt_of_top_le hml]
Β· rw [min_eq_right hlm, filter_lt_of_ge hlm]
theorem filter_le_of_le_bot {n m l : β} (hln : l β€ n) :
((Ico n m).filter fun x => l β€ x) = Ico n m :=
| filter_eq_self.2 fun k hk => by
| Mathlib/Data/List/Intervals.lean | 153 | 153 |
/-
Copyright (c) 2022 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.MeasureTheory.Measure.Haar.Basic
import Mathlib.Analysis.InnerProductSpace.PiL2
/-!
# Additive Haar measure constructed from a basis
Given a basis of a finite-dimensional real vector space, we define the corresponding Lebesgue
measure, which gives measure `1` to the parallelepiped spanned by the basis.
## Main definitions
* `parallelepiped v` is the parallelepiped spanned by a finite family of vectors.
* `Basis.parallelepiped` is the parallelepiped associated to a basis, seen as a compact set with
nonempty interior.
* `Basis.addHaar` is the Lebesgue measure associated to a basis, giving measure `1` to the
corresponding parallelepiped.
In particular, we declare a `MeasureSpace` instance on any finite-dimensional inner product space,
by using the Lebesgue measure associated to some orthonormal basis (which is in fact independent
of the basis).
-/
open Set TopologicalSpace MeasureTheory MeasureTheory.Measure Module
open scoped Pointwise
noncomputable section
variable {ΞΉ ΞΉ' E F : Type*}
section Fintype
variable [Fintype ΞΉ] [Fintype ΞΉ']
section AddCommGroup
variable [AddCommGroup E] [Module β E] [AddCommGroup F] [Module β F]
/-- The closed parallelepiped spanned by a finite family of vectors. -/
def parallelepiped (v : ΞΉ β E) : Set E :=
(fun t : ΞΉ β β => β i, t i β’ v i) '' Icc 0 1
theorem mem_parallelepiped_iff (v : ΞΉ β E) (x : E) :
x β parallelepiped v β β t β Icc (0 : ΞΉ β β) 1, x = β i, t i β’ v i := by
simp [parallelepiped, eq_comm]
theorem parallelepiped_basis_eq (b : Basis ΞΉ β E) :
parallelepiped b = {x | β i, b.repr x i β Set.Icc 0 1} := by
classical
ext x
simp_rw [mem_parallelepiped_iff, mem_setOf_eq, b.ext_elem_iff, _root_.map_sum,
map_smul, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single, smul_eq_mul,
mul_one, Finsupp.single_apply, Finset.sum_ite_eq', Finset.mem_univ, ite_true, mem_Icc,
Pi.le_def, Pi.zero_apply, Pi.one_apply, β forall_and]
aesop
theorem image_parallelepiped (f : E ββ[β] F) (v : ΞΉ β E) :
f '' parallelepiped v = parallelepiped (f β v) := by
simp only [parallelepiped, β image_comp]
congr 1 with t
simp only [Function.comp_apply, _root_.map_sum, LinearMap.map_smulββ, RingHom.id_apply]
/-- Reindexing a family of vectors does not change their parallelepiped. -/
@[simp]
theorem parallelepiped_comp_equiv (v : ΞΉ β E) (e : ΞΉ' β ΞΉ) :
parallelepiped (v β e) = parallelepiped v := by
simp only [parallelepiped]
let K : (ΞΉ' β β) β (ΞΉ β β) := Equiv.piCongrLeft' (fun _a : ΞΉ' => β) e
have : Icc (0 : ΞΉ β β) 1 = K '' Icc (0 : ΞΉ' β β) 1 := by
rw [β Equiv.preimage_eq_iff_eq_image]
ext x
simp only [K, mem_preimage, mem_Icc, Pi.le_def, Pi.zero_apply, Equiv.piCongrLeft'_apply,
Pi.one_apply]
refine
β¨fun h => β¨fun i => ?_, fun i => ?_β©, fun h =>
β¨fun i => h.1 (e.symm i), fun i => h.2 (e.symm i)β©β©
Β· simpa only [Equiv.symm_apply_apply] using h.1 (e i)
Β· simpa only [Equiv.symm_apply_apply] using h.2 (e i)
rw [this, β image_comp]
congr 1 with x
have := fun z : ΞΉ' β β => e.symm.sum_comp fun i => z i β’ v (e i)
simp_rw [Equiv.apply_symm_apply] at this
simp_rw [Function.comp_apply, mem_image, mem_Icc, K, Equiv.piCongrLeft'_apply, this]
-- The parallelepiped associated to an orthonormal basis of `β` is either `[0, 1]` or `[-1, 0]`.
theorem parallelepiped_orthonormalBasis_one_dim (b : OrthonormalBasis ΞΉ β β) :
parallelepiped b = Icc 0 1 β¨ parallelepiped b = Icc (-1) 0 := by
have e : ΞΉ β Fin 1 := by
apply Fintype.equivFinOfCardEq
simp only [β finrank_eq_card_basis b.toBasis, finrank_self]
have B : parallelepiped (b.reindex e) = parallelepiped b := by
convert parallelepiped_comp_equiv b e.symm
ext i
simp only [OrthonormalBasis.coe_reindex]
rw [β B]
let F : β β Fin 1 β β := fun t => fun _i => t
have A : Icc (0 : Fin 1 β β) 1 = F '' Icc (0 : β) 1 := by
apply Subset.antisymm
Β· intro x hx
refine β¨x 0, β¨hx.1 0, hx.2 0β©, ?_β©
ext j
simp only [F, Subsingleton.elim j 0]
Β· rintro x β¨y, hy, rflβ©
exact β¨fun _j => hy.1, fun _j => hy.2β©
rcases orthonormalBasis_one_dim (b.reindex e) with (H | H)
Β· left
simp_rw [parallelepiped, H, A, Algebra.id.smul_eq_mul, mul_one]
simp only [F, Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton,
β image_comp, Function.comp_apply, image_id']
Β· right
simp_rw [H, parallelepiped, Algebra.id.smul_eq_mul, A]
simp only [F, Finset.univ_unique, Fin.default_eq_zero, mul_neg, mul_one, Finset.sum_neg_distrib,
Finset.sum_singleton, β image_comp, Function.comp, image_neg_eq_neg, neg_Icc, neg_zero]
theorem parallelepiped_eq_sum_segment (v : ΞΉ β E) : parallelepiped v = β i, segment β 0 (v i) := by
ext
simp only [mem_parallelepiped_iff, Set.mem_finset_sum, Finset.mem_univ, forall_true_left,
segment_eq_image, smul_zero, zero_add, β Set.pi_univ_Icc, Set.mem_univ_pi]
constructor
Β· rintro β¨t, ht, rflβ©
exact β¨t β’ v, fun {i} => β¨t i, ht _, by simpβ©, rflβ©
rintro β¨g, hg, rflβ©
choose t ht hg using @hg
refine β¨@t, @ht, ?_β©
simp_rw [hg]
theorem convex_parallelepiped (v : ΞΉ β E) : Convex β (parallelepiped v) := by
rw [parallelepiped_eq_sum_segment]
exact convex_sum _ fun _i _hi => convex_segment _ _
/-- A `parallelepiped` is the convex hull of its vertices -/
theorem parallelepiped_eq_convexHull (v : ΞΉ β E) :
parallelepiped v = convexHull β (β i, {(0 : E), v i}) := by
simp_rw [convexHull_sum, convexHull_pair, parallelepiped_eq_sum_segment]
/-- The axis aligned parallelepiped over `ΞΉ β β` is a cuboid. -/
theorem parallelepiped_single [DecidableEq ΞΉ] (a : ΞΉ β β) :
(parallelepiped fun i => Pi.single i (a i)) = Set.uIcc 0 a := by
ext x
simp_rw [Set.uIcc, mem_parallelepiped_iff, Set.mem_Icc, Pi.le_def, β forall_and, Pi.inf_apply,
| Pi.sup_apply, β Pi.single_smul', Pi.one_apply, Pi.zero_apply, β Pi.smul_apply',
Finset.univ_sum_single (_ : ΞΉ β β)]
constructor
| Mathlib/MeasureTheory/Measure/Haar/OfBasis.lean | 147 | 149 |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.BoxIntegral.Partition.Filter
import Mathlib.Analysis.BoxIntegral.Partition.Measure
import Mathlib.Analysis.Oscillation
import Mathlib.Data.Bool.Basic
import Mathlib.MeasureTheory.Measure.Real
import Mathlib.Topology.UniformSpace.Compact
/-!
# Integrals of Riemann, Henstock-Kurzweil, and McShane
In this file we define the integral of a function over a box in `ββΏ`. The same definition works for
Riemann, Henstock-Kurzweil, and McShane integrals.
As usual, we represent `ββΏ` as the type of functions `ΞΉ β β` for some finite type `ΞΉ`. A rectangular
box `(l, u]` in `ββΏ` is defined to be the set `{x : ΞΉ β β | β i, l i < x i β§ x i β€ u i}`, see
`BoxIntegral.Box`.
Let `vol` be a box-additive function on boxes in `ββΏ` with codomain `E βL[β] F`. Given a function
`f : ββΏ β E`, a box `I` and a tagged partition `Ο` of this box, the *integral sum* of `f` over `Ο`
with respect to the volume `vol` is the sum of `vol J (f (Ο.tag J))` over all boxes of `Ο`. Here
`Ο.tag J` is the point (tag) in `ββΏ` associated with the box `J`.
The integral is defined as the limit of integral sums along a filter. Different filters correspond
to different integration theories. In order to avoid code duplication, all our definitions and
theorems take an argument `l : BoxIntegral.IntegrationParams`. This is a type that holds three
boolean values, and encodes eight filters including those corresponding to Riemann,
Henstock-Kurzweil, and McShane integrals.
Following the design of infinite sums (see `hasSum` and `tsum`), we define a predicate
`BoxIntegral.HasIntegral` and a function `BoxIntegral.integral` that returns a vector satisfying
the predicate or zero if the function is not integrable.
Then we prove some basic properties of box integrals (linearity, a formula for the integral of a
constant). We also prove a version of the Henstock-Sacks inequality (see
`BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet` and
`BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`), prove
integrability of continuous functions, and provide a criterion for integrability w.r.t. a
non-Riemann filter (e.g., Henstock-Kurzweil and McShane).
## Notation
- `ββΏ`: local notation for `ΞΉ β β`
## Tags
integral
-/
open scoped Topology NNReal Filter Uniformity BoxIntegral
open Set Finset Function Filter Metric BoxIntegral.IntegrationParams
noncomputable section
namespace BoxIntegral
universe u v w
variable {ΞΉ : Type u} {E : Type v} {F : Type w} [NormedAddCommGroup E] [NormedSpace β E]
[NormedAddCommGroup F] [NormedSpace β F] {I J : Box ΞΉ} {Ο : TaggedPrepartition I}
open TaggedPrepartition
local notation "ββΏ" => ΞΉ β β
/-!
### Integral sum and its basic properties
-/
/-- The integral sum of `f : ββΏ β E` over a tagged prepartition `Ο` w.r.t. box-additive volume `vol`
with codomain `E βL[β] F` is the sum of `vol J (f (Ο.tag J))` over all boxes of `Ο`. -/
def integralSum (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) (Ο : TaggedPrepartition I) : F :=
β J β Ο.boxes, vol J (f (Ο.tag J))
theorem integralSum_biUnionTagged (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) (Ο : Prepartition I)
(Οi : β J, TaggedPrepartition J) :
integralSum f vol (Ο.biUnionTagged Οi) = β J β Ο.boxes, integralSum f vol (Οi J) := by
refine (Ο.sum_biUnion_boxes _ _).trans <| sum_congr rfl fun J hJ => sum_congr rfl fun J' hJ' => ?_
rw [Ο.tag_biUnionTagged hJ hJ']
theorem integralSum_biUnion_partition (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F)
(Ο : TaggedPrepartition I) (Οi : β J, Prepartition J) (hΟi : β J β Ο, (Οi J).IsPartition) :
integralSum f vol (Ο.biUnionPrepartition Οi) = integralSum f vol Ο := by
refine (Ο.sum_biUnion_boxes _ _).trans (sum_congr rfl fun J hJ => ?_)
calc
(β J' β (Οi J).boxes, vol J' (f (Ο.tag <| Ο.toPrepartition.biUnionIndex Οi J'))) =
β J' β (Οi J).boxes, vol J' (f (Ο.tag J)) :=
sum_congr rfl fun J' hJ' => by rw [Prepartition.biUnionIndex_of_mem _ hJ hJ']
_ = vol J (f (Ο.tag J)) :=
(vol.map β¨β¨fun g : E βL[β] F => g (f (Ο.tag J)), rflβ©, fun _ _ => rflβ©).sum_partition_boxes
le_top (hΟi J hJ)
theorem integralSum_inf_partition (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) (Ο : TaggedPrepartition I)
{Ο' : Prepartition I} (h : Ο'.IsPartition) :
integralSum f vol (Ο.infPrepartition Ο') = integralSum f vol Ο :=
integralSum_biUnion_partition f vol Ο _ fun _J hJ => h.restrict (Prepartition.le_of_mem _ hJ)
open Classical in
theorem integralSum_fiberwise {Ξ±} (g : Box ΞΉ β Ξ±) (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F)
(Ο : TaggedPrepartition I) :
(β y β Ο.boxes.image g, integralSum f vol (Ο.filter (g Β· = y))) = integralSum f vol Ο :=
Ο.sum_fiberwise g fun J => vol J (f <| Ο.tag J)
theorem integralSum_sub_partitions (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F)
{Οβ Οβ : TaggedPrepartition I} (hβ : Οβ.IsPartition) (hβ : Οβ.IsPartition) :
integralSum f vol Οβ - integralSum f vol Οβ =
β J β (Οβ.toPrepartition β Οβ.toPrepartition).boxes,
(vol J (f <| (Οβ.infPrepartition Οβ.toPrepartition).tag J) -
vol J (f <| (Οβ.infPrepartition Οβ.toPrepartition).tag J)) := by
rw [β integralSum_inf_partition f vol Οβ hβ, β integralSum_inf_partition f vol Οβ hβ,
integralSum, integralSum, Finset.sum_sub_distrib]
simp only [infPrepartition_toPrepartition, inf_comm]
@[simp]
theorem integralSum_disjUnion (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) {Οβ Οβ : TaggedPrepartition I}
(h : Disjoint Οβ.iUnion Οβ.iUnion) :
integralSum f vol (Οβ.disjUnion Οβ h) = integralSum f vol Οβ + integralSum f vol Οβ := by
refine (Prepartition.sum_disj_union_boxes h _).trans
(congr_argβ (Β· + Β·) (sum_congr rfl fun J hJ => ?_) (sum_congr rfl fun J hJ => ?_))
Β· rw [disjUnion_tag_of_mem_left _ hJ]
Β· rw [disjUnion_tag_of_mem_right _ hJ]
@[simp]
theorem integralSum_add (f g : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) (Ο : TaggedPrepartition I) :
integralSum (f + g) vol Ο = integralSum f vol Ο + integralSum g vol Ο := by
simp only [integralSum, Pi.add_apply, (vol _).map_add, Finset.sum_add_distrib]
@[simp]
theorem integralSum_neg (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) (Ο : TaggedPrepartition I) :
integralSum (-f) vol Ο = -integralSum f vol Ο := by
simp only [integralSum, Pi.neg_apply, (vol _).map_neg, Finset.sum_neg_distrib]
@[simp]
theorem integralSum_smul (c : β) (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) (Ο : TaggedPrepartition I) :
integralSum (c β’ f) vol Ο = c β’ integralSum f vol Ο := by
simp only [integralSum, Finset.smul_sum, Pi.smul_apply, ContinuousLinearMap.map_smul]
variable [Fintype ΞΉ]
/-!
### Basic integrability theory
-/
/-- The predicate `HasIntegral I l f vol y` says that `y` is the integral of `f` over `I` along `l`
w.r.t. volume `vol`. This means that integral sums of `f` tend to `π y` along
`BoxIntegral.IntegrationParams.toFilteriUnion I β€`. -/
def HasIntegral (I : Box ΞΉ) (l : IntegrationParams) (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) (y : F) :
Prop :=
Tendsto (integralSum f vol) (l.toFilteriUnion I β€) (π y)
/-- A function is integrable if there exists a vector that satisfies the `HasIntegral`
predicate. -/
def Integrable (I : Box ΞΉ) (l : IntegrationParams) (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) :=
β y, HasIntegral I l f vol y
open Classical in
/-- The integral of a function `f` over a box `I` along a filter `l` w.r.t. a volume `vol`.
Returns zero on non-integrable functions. -/
def integral (I : Box ΞΉ) (l : IntegrationParams) (f : ββΏ β E) (vol : ΞΉ βα΅α΅ E βL[β] F) :=
if h : Integrable I l f vol then h.choose else 0
-- Porting note: using the above notation ββΏ here causes the theorem below to be silently ignored
-- see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Lean.204.20doesn't.20add.20lemma.20to.20the.20environment/near/363764522
-- and https://github.com/leanprover/lean4/issues/2257
variable {l : IntegrationParams} {f g : (ΞΉ β β) β E} {vol : ΞΉ βα΅α΅ E βL[β] F} {y y' : F}
/-- Reinterpret `BoxIntegral.HasIntegral` as `Filter.Tendsto`, e.g., dot-notation theorems
that are shadowed in the `BoxIntegral.HasIntegral` namespace. -/
theorem HasIntegral.tendsto (h : HasIntegral I l f vol y) :
Tendsto (integralSum f vol) (l.toFilteriUnion I β€) (π y) :=
h
/-- The `Ξ΅`-`Ξ΄` definition of `BoxIntegral.HasIntegral`. -/
theorem hasIntegral_iff : HasIntegral I l f vol y β
β Ξ΅ > (0 : β), β r : ββ₯0 β ββΏ β Ioi (0 : β), (β c, l.RCond (r c)) β§
β c Ο, l.MemBaseSet I c (r c) Ο β IsPartition Ο β dist (integralSum f vol Ο) y β€ Ξ΅ :=
((l.hasBasis_toFilteriUnion_top I).tendsto_iff nhds_basis_closedBall).trans <| by
simp [@forall_swap ββ₯0 (TaggedPrepartition I)]
/-- Quite often it is more natural to prove an estimate of the form `a * Ξ΅`, not `Ξ΅` in the RHS of
`BoxIntegral.hasIntegral_iff`, so we provide this auxiliary lemma. -/
theorem HasIntegral.of_mul (a : β)
(h : β Ξ΅ : β, 0 < Ξ΅ β β r : ββ₯0 β ββΏ β Ioi (0 : β), (β c, l.RCond (r c)) β§ β c Ο,
l.MemBaseSet I c (r c) Ο β IsPartition Ο β dist (integralSum f vol Ο) y β€ a * Ξ΅) :
HasIntegral I l f vol y := by
refine hasIntegral_iff.2 fun Ξ΅ hΞ΅ => ?_
rcases exists_pos_mul_lt hΞ΅ a with β¨Ξ΅', hΞ΅', haβ©
rcases h Ξ΅' hΞ΅' with β¨r, hr, Hβ©
exact β¨r, hr, fun c Ο hΟ hΟp => (H c Ο hΟ hΟp).trans ha.leβ©
theorem integrable_iff_cauchy [CompleteSpace F] :
Integrable I l f vol β Cauchy ((l.toFilteriUnion I β€).map (integralSum f vol)) :=
cauchy_map_iff_exists_tendsto.symm
/-- In a complete space, a function is integrable if and only if its integral sums form a Cauchy
net. Here we restate this fact in terms of `β Ξ΅ > 0, β r, ...`. -/
theorem integrable_iff_cauchy_basis [CompleteSpace F] : Integrable I l f vol β
β Ξ΅ > (0 : β), β r : ββ₯0 β ββΏ β Ioi (0 : β), (β c, l.RCond (r c)) β§
β cβ cβ Οβ Οβ, l.MemBaseSet I cβ (r cβ) Οβ β Οβ.IsPartition β l.MemBaseSet I cβ (r cβ) Οβ β
Οβ.IsPartition β dist (integralSum f vol Οβ) (integralSum f vol Οβ) β€ Ξ΅ := by
rw [integrable_iff_cauchy, cauchy_map_iff',
(l.hasBasis_toFilteriUnion_top _).prod_self.tendsto_iff uniformity_basis_dist_le]
refine forallβ_congr fun Ξ΅ _ => exists_congr fun r => ?_
simp only [exists_prop, Prod.forall, Set.mem_iUnion, exists_imp, prodMk_mem_set_prod_eq, and_imp,
mem_inter_iff, mem_setOf_eq]
exact
and_congr Iff.rfl
β¨fun H cβ cβ Οβ Οβ hβ hUβ hβ hUβ => H Οβ Οβ cβ hβ hUβ cβ hβ hUβ,
fun H Οβ Οβ cβ hβ hUβ cβ hβ hUβ => H cβ cβ Οβ Οβ hβ hUβ hβ hUββ©
theorem HasIntegral.mono {lβ lβ : IntegrationParams} (h : HasIntegral I lβ f vol y) (hl : lβ β€ lβ) :
HasIntegral I lβ f vol y :=
h.mono_left <| IntegrationParams.toFilteriUnion_mono _ hl _
protected theorem Integrable.hasIntegral (h : Integrable I l f vol) :
HasIntegral I l f vol (integral I l f vol) := by
rw [integral, dif_pos h]
exact Classical.choose_spec h
theorem Integrable.mono {l'} (h : Integrable I l f vol) (hle : l' β€ l) : Integrable I l' f vol :=
β¨_, h.hasIntegral.mono hleβ©
theorem HasIntegral.unique (h : HasIntegral I l f vol y) (h' : HasIntegral I l f vol y') : y = y' :=
tendsto_nhds_unique h h'
theorem HasIntegral.integrable (h : HasIntegral I l f vol y) : Integrable I l f vol :=
β¨_, hβ©
theorem HasIntegral.integral_eq (h : HasIntegral I l f vol y) : integral I l f vol = y :=
h.integrable.hasIntegral.unique h
nonrec theorem HasIntegral.add (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') :
HasIntegral I l (f + g) vol (y + y') := by
simpa only [HasIntegral, β integralSum_add] using h.add h'
theorem Integrable.add (hf : Integrable I l f vol) (hg : Integrable I l g vol) :
Integrable I l (f + g) vol :=
(hf.hasIntegral.add hg.hasIntegral).integrable
theorem integral_add (hf : Integrable I l f vol) (hg : Integrable I l g vol) :
integral I l (f + g) vol = integral I l f vol + integral I l g vol :=
(hf.hasIntegral.add hg.hasIntegral).integral_eq
nonrec theorem HasIntegral.neg (hf : HasIntegral I l f vol y) : HasIntegral I l (-f) vol (-y) := by
simpa only [HasIntegral, β integralSum_neg] using hf.neg
theorem Integrable.neg (hf : Integrable I l f vol) : Integrable I l (-f) vol :=
hf.hasIntegral.neg.integrable
theorem Integrable.of_neg (hf : Integrable I l (-f) vol) : Integrable I l f vol :=
neg_neg f βΈ hf.neg
@[simp]
theorem integrable_neg : Integrable I l (-f) vol β Integrable I l f vol :=
β¨fun h => h.of_neg, fun h => h.negβ©
@[simp]
theorem integral_neg : integral I l (-f) vol = -integral I l f vol := by
classical
exact if h : Integrable I l f vol then h.hasIntegral.neg.integral_eq
else by rw [integral, integral, dif_neg h, dif_neg (mt Integrable.of_neg h), neg_zero]
theorem HasIntegral.sub (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') :
HasIntegral I l (f - g) vol (y - y') := by simpa only [sub_eq_add_neg] using h.add h'.neg
theorem Integrable.sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) :
Integrable I l (f - g) vol :=
(hf.hasIntegral.sub hg.hasIntegral).integrable
theorem integral_sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) :
integral I l (f - g) vol = integral I l f vol - integral I l g vol :=
(hf.hasIntegral.sub hg.hasIntegral).integral_eq
theorem hasIntegral_const (c : E) : HasIntegral I l (fun _ => c) vol (vol I c) :=
tendsto_const_nhds.congr' <| (l.eventually_isPartition I).mono fun _Ο hΟ => Eq.symm <|
(vol.map β¨β¨fun g : E βL[β] F β¦ g c, rflβ©, fun _ _ β¦ rflβ©).sum_partition_boxes le_top hΟ
@[simp]
theorem integral_const (c : E) : integral I l (fun _ => c) vol = vol I c :=
(hasIntegral_const c).integral_eq
theorem integrable_const (c : E) : Integrable I l (fun _ => c) vol :=
β¨_, hasIntegral_const cβ©
theorem hasIntegral_zero : HasIntegral I l (fun _ => (0 : E)) vol 0 := by
simpa only [β (vol I).map_zero] using hasIntegral_const (0 : E)
theorem integrable_zero : Integrable I l (fun _ => (0 : E)) vol :=
β¨0, hasIntegral_zeroβ©
theorem integral_zero : integral I l (fun _ => (0 : E)) vol = 0 :=
hasIntegral_zero.integral_eq
theorem HasIntegral.sum {Ξ± : Type*} {s : Finset Ξ±} {f : Ξ± β ββΏ β E} {g : Ξ± β F}
(h : β i β s, HasIntegral I l (f i) vol (g i)) :
HasIntegral I l (fun x => β i β s, f i x) vol (β i β s, g i) := by
classical
induction' s using Finset.induction_on with a s ha ihs; Β· simp [hasIntegral_zero]
simp only [Finset.sum_insert ha]; rw [Finset.forall_mem_insert] at h
exact h.1.add (ihs h.2)
theorem HasIntegral.smul (hf : HasIntegral I l f vol y) (c : β) :
HasIntegral I l (c β’ f) vol (c β’ y) := by
simpa only [HasIntegral, β integralSum_smul] using
(tendsto_const_nhds : Tendsto _ _ (π c)).smul hf
theorem Integrable.smul (hf : Integrable I l f vol) (c : β) : Integrable I l (c β’ f) vol :=
(hf.hasIntegral.smul c).integrable
theorem Integrable.of_smul {c : β} (hf : Integrable I l (c β’ f) vol) (hc : c β 0) :
Integrable I l f vol := by
simpa [inv_smul_smulβ hc] using hf.smul cβ»ΒΉ
@[simp]
theorem integral_smul (c : β) : integral I l (fun x => c β’ f x) vol = c β’ integral I l f vol := by
rcases eq_or_ne c 0 with (rfl | hc); Β· simp only [zero_smul, integral_zero]
by_cases hf : Integrable I l f vol
Β· exact (hf.hasIntegral.smul c).integral_eq
Β· have : Β¬Integrable I l (fun x => c β’ f x) vol := mt (fun h => h.of_smul hc) hf
rw [integral, integral, dif_neg hf, dif_neg this, smul_zero]
open MeasureTheory
/-- The integral of a nonnegative function w.r.t. a volume generated by a locally-finite measure is
nonnegative. -/
theorem integral_nonneg {g : ββΏ β β} (hg : β x β Box.Icc I, 0 β€ g x) (ΞΌ : Measure ββΏ)
[IsLocallyFiniteMeasure ΞΌ] : 0 β€ integral I l g ΞΌ.toBoxAdditive.toSMul := by
by_cases hgi : Integrable I l g ΞΌ.toBoxAdditive.toSMul
Β· refine ge_of_tendsto' hgi.hasIntegral fun Ο => sum_nonneg fun J _ => ?_
exact mul_nonneg ENNReal.toReal_nonneg (hg _ <| Ο.tag_mem_Icc _)
Β· rw [integral, dif_neg hgi]
/-- If `βf xβ β€ g x` on `[l, u]` and `g` is integrable, then the norm of the integral of `f` is less
than or equal to the integral of `g`. -/
theorem norm_integral_le_of_norm_le {g : ββΏ β β} (hle : β x β Box.Icc I, βf xβ β€ g x)
(ΞΌ : Measure ββΏ) [IsLocallyFiniteMeasure ΞΌ] (hg : Integrable I l g ΞΌ.toBoxAdditive.toSMul) :
β(integral I l f ΞΌ.toBoxAdditive.toSMul : E)β β€ integral I l g ΞΌ.toBoxAdditive.toSMul := by
by_cases hfi : Integrable.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul
Β· refine le_of_tendsto_of_tendsto' hfi.hasIntegral.norm hg.hasIntegral fun Ο => ?_
refine norm_sum_le_of_le _ fun J _ => ?_
simp only [BoxAdditiveMap.toSMul_apply, norm_smul, smul_eq_mul, Real.norm_eq_abs,
ΞΌ.toBoxAdditive_apply, abs_of_nonneg measureReal_nonneg]
exact mul_le_mul_of_nonneg_left (hle _ <| Ο.tag_mem_Icc _) ENNReal.toReal_nonneg
Β· rw [integral, dif_neg hfi, norm_zero]
exact integral_nonneg (fun x hx => (norm_nonneg _).trans (hle x hx)) ΞΌ
theorem norm_integral_le_of_le_const {c : β}
(hc : β x β Box.Icc I, βf xβ β€ c) (ΞΌ : Measure ββΏ) [IsLocallyFiniteMeasure ΞΌ] :
β(integral I l f ΞΌ.toBoxAdditive.toSMul : E)β β€ ΞΌ.real I * c := by
simpa only [integral_const] using norm_integral_le_of_norm_le hc ΞΌ (integrable_const c)
/-!
# Henstock-Sacks inequality and integrability on subboxes
Henstock-Sacks inequality for Henstock-Kurzweil integral says the following. Let `f` be a function
integrable on a box `I`; let `r : ββΏ β (0, β)` be a function such that for any tagged partition of
`I` subordinate to `r`, the integral sum over this partition is `Ξ΅`-close to the integral. Then for
any tagged prepartition (i.e. a finite collections of pairwise disjoint subboxes of `I` with tagged
points) `Ο`, the integral sum over `Ο` differs from the integral of `f` over the part of `I` covered
by `Ο` by at most `Ξ΅`. The actual statement in the library is a bit more complicated to make it work
for any `BoxIntegral.IntegrationParams`. We formalize several versions of this inequality in
`BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet`,
`BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`, and
`BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`.
Instead of using predicate assumptions on `r`, we define
`BoxIntegral.Integrable.convergenceR (h : integrable I l f vol) (Ξ΅ : β) (c : ββ₯0) : ββΏ β (0, β)`
to be a function `r` such that
- if `l.bRiemann`, then `r` is a constant;
- if `Ξ΅ > 0`, then for any tagged partition `Ο` of `I` subordinate to `r` (more precisely,
satisfying the predicate `l.mem_base_set I c r`), the integral sum of `f` over `Ο` differs from
the integral of `f` over `I` by at most `Ξ΅`.
The proof is mostly based on
[Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55].
-/
namespace Integrable
/-- If `Ξ΅ > 0`, then `BoxIntegral.Integrable.convergenceR` is a function `r : ββ₯0 β ββΏ β (0, β)`
such that for every `c : ββ₯0`, for every tagged partition `Ο` subordinate to `r` (and satisfying
additional distortion estimates if `BoxIntegral.IntegrationParams.bDistortion l = true`), the
corresponding integral sum is `Ξ΅`-close to the integral.
If `BoxIntegral.IntegrationParams.bRiemann = true`, then `r c x` does not depend on `x`. If
`Ξ΅ β€ 0`, then we use `r c x = 1`. -/
def convergenceR (h : Integrable I l f vol) (Ξ΅ : β) : ββ₯0 β ββΏ β Ioi (0 : β) :=
if hΞ΅ : 0 < Ξ΅ then (hasIntegral_iff.1 h.hasIntegral Ξ΅ hΞ΅).choose
else fun _ _ => β¨1, Set.mem_Ioi.2 zero_lt_oneβ©
variable {c cβ cβ : ββ₯0} {Ξ΅ Ξ΅β Ξ΅β : β} {Οβ Οβ : TaggedPrepartition I}
theorem convergenceR_cond (h : Integrable I l f vol) (Ξ΅ : β) (c : ββ₯0) :
l.RCond (h.convergenceR Ξ΅ c) := by
rw [convergenceR]; split_ifs with hβ
exacts [(hasIntegral_iff.1 h.hasIntegral Ξ΅ hβ).choose_spec.1 _, fun _ x => rfl]
theorem dist_integralSum_integral_le_of_memBaseSet (h : Integrable I l f vol) (hβ : 0 < Ξ΅)
(hΟ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο) (hΟp : Ο.IsPartition) :
dist (integralSum f vol Ο) (integral I l f vol) β€ Ξ΅ := by
rw [convergenceR, dif_pos hβ] at hΟ
exact (hasIntegral_iff.1 h.hasIntegral Ξ΅ hβ).choose_spec.2 c _ hΟ hΟp
/-- **Henstock-Sacks inequality**. Let `rβ rβ : ββΏ β (0, β)` be a function such that for any tagged
*partition* of `I` subordinate to `rβ`, `k=1,2`, the integral sum of `f` over this partition differs
from the integral of `f` by at most `Ξ΅β`. Then for any two tagged *prepartition* `Οβ Οβ` subordinate
to `rβ` and `rβ` respectively and covering the same part of `I`, the integral sums of `f` over these
prepartitions differ from each other by at most `Ξ΅β + Ξ΅β`.
The actual statement
- uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`;
- uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of βsubordinate to `r`β to
account for additional requirements like being a Henstock partition or having a bounded
distortion.
See also `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq` and
`BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`.
-/
theorem dist_integralSum_le_of_memBaseSet (h : Integrable I l f vol) (hposβ : 0 < Ξ΅β)
(hposβ : 0 < Ξ΅β) (hβ : l.MemBaseSet I cβ (h.convergenceR Ξ΅β cβ) Οβ)
(hβ : l.MemBaseSet I cβ (h.convergenceR Ξ΅β cβ) Οβ) (HU : Οβ.iUnion = Οβ.iUnion) :
dist (integralSum f vol Οβ) (integralSum f vol Οβ) β€ Ξ΅β + Ξ΅β := by
rcases hβ.exists_common_compl hβ HU with β¨Ο, hΟU, hΟcβ, hΟcββ©
set r : ββΏ β Ioi (0 : β) := fun x => min (h.convergenceR Ξ΅β cβ x) (h.convergenceR Ξ΅β cβ x)
set Οr := Ο.toSubordinate r
have Hβ :
dist (integralSum f vol (Οβ.unionComplToSubordinate Ο hΟU r)) (integral I l f vol) β€ Ξ΅β :=
h.dist_integralSum_integral_le_of_memBaseSet hposβ
(hβ.unionComplToSubordinate (fun _ _ => min_le_left _ _) hΟU hΟcβ)
(isPartition_unionComplToSubordinate _ _ _ _)
rw [HU] at hΟU
have Hβ :
dist (integralSum f vol (Οβ.unionComplToSubordinate Ο hΟU r)) (integral I l f vol) β€ Ξ΅β :=
h.dist_integralSum_integral_le_of_memBaseSet hposβ
(hβ.unionComplToSubordinate (fun _ _ => min_le_right _ _) hΟU hΟcβ)
(isPartition_unionComplToSubordinate _ _ _ _)
simpa [unionComplToSubordinate] using (dist_triangle_right _ _ _).trans (add_le_add Hβ Hβ)
/-- If `f` is integrable on `I` along `l`, then for two sufficiently fine tagged prepartitions
(in the sense of the filter `BoxIntegral.IntegrationParams.toFilter l I`) such that they cover
the same part of `I`, the integral sums of `f` over `Οβ` and `Οβ` are very close to each other. -/
theorem tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity (h : Integrable I l f vol) :
Tendsto (fun Ο : TaggedPrepartition I Γ TaggedPrepartition I =>
(integralSum f vol Ο.1, integralSum f vol Ο.2))
((l.toFilter I ΓΛ’ l.toFilter I) β π {Ο | Ο.1.iUnion = Ο.2.iUnion}) (π€ F) := by
refine (((l.hasBasis_toFilter I).prod_self.inf_principal _).tendsto_iff
uniformity_basis_dist_le).2 fun Ξ΅ Ξ΅0 => ?_
replace Ξ΅0 := half_pos Ξ΅0
use h.convergenceR (Ξ΅ / 2), h.convergenceR_cond (Ξ΅ / 2); rintro β¨Οβ, Οββ© β¨β¨hβ, hββ©, hUβ©
rw [β add_halves Ξ΅]
exact h.dist_integralSum_le_of_memBaseSet Ξ΅0 Ξ΅0 hβ.choose_spec hβ.choose_spec hU
/-- If `f` is integrable on a box `I` along `l`, then for any fixed subset `s` of `I` that can be
represented as a finite union of boxes, the integral sums of `f` over tagged prepartitions that
cover exactly `s` form a Cauchy βsequenceβ along `l`. -/
theorem cauchy_map_integralSum_toFilteriUnion (h : Integrable I l f vol) (Οβ : Prepartition I) :
Cauchy ((l.toFilteriUnion I Οβ).map (integralSum f vol)) := by
refine β¨inferInstance, ?_β©
rw [prod_map_map_eq, β toFilter_inf_iUnion_eq, β prod_inf_prod, prod_principal_principal]
exact h.tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity.mono_left
(inf_le_inf_left _ <| principal_mono.2 fun Ο h => h.1.trans h.2.symm)
variable [CompleteSpace F]
theorem to_subbox_aux (h : Integrable I l f vol) (hJ : J β€ I) :
β y : F, HasIntegral J l f vol y β§
Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (π y) := by
refine (cauchy_map_iff_exists_tendsto.1
(h.cauchy_map_integralSum_toFilteriUnion (.single I J hJ))).imp fun y hy β¦ β¨?_, hyβ©
convert hy.comp (l.tendsto_embedBox_toFilteriUnion_top hJ) -- faster than `exact` here
/-- If `f` is integrable on a box `I`, then it is integrable on any subbox of `I`. -/
theorem to_subbox (h : Integrable I l f vol) (hJ : J β€ I) : Integrable J l f vol :=
(h.to_subbox_aux hJ).imp fun _ => And.left
/-- If `f` is integrable on a box `I`, then integral sums of `f` over tagged prepartitions
that cover exactly a subbox `J β€ I` tend to the integral of `f` over `J` along `l`. -/
theorem tendsto_integralSum_toFilteriUnion_single (h : Integrable I l f vol) (hJ : J β€ I) :
Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ))
(π <| integral J l f vol) :=
let β¨_y, hβ, hββ© := h.to_subbox_aux hJ
hβ.integral_eq.symm βΈ hβ
/-- **Henstock-Sacks inequality**. Let `r : ββΏ β (0, β)` be a function such that for any tagged
*partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the
integral of `f` by at most `Ξ΅`. Then for any tagged *prepartition* `Ο` subordinate to `r`, the
integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I`
covered by `Ο` by at most `Ξ΅`.
The actual statement
- uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`;
- uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of βsubordinate to `r`β to
account for additional requirements like being a Henstock partition or having a bounded
distortion;
- takes an extra argument `Οβ : prepartition I` and an assumption `Ο.Union = Οβ.Union` instead of
using `Ο.to_prepartition`.
-/
theorem dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq (h : Integrable I l f vol)
(h0 : 0 < Ξ΅) (hΟ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο) {Οβ : Prepartition I}
(hU : Ο.iUnion = Οβ.iUnion) :
dist (integralSum f vol Ο) (β J β Οβ.boxes, integral J l f vol) β€ Ξ΅ := by
-- Let us prove that the distance is less than or equal to `Ξ΅ + Ξ΄` for all positive `Ξ΄`.
refine le_of_forall_pos_le_add fun Ξ΄ Ξ΄0 => ?_
-- First we choose some constants.
set Ξ΄' : β := Ξ΄ / (#Οβ.boxes + 1)
have H0 : 0 < (#Οβ.boxes + 1 : β) := Nat.cast_add_one_pos _
have Ξ΄'0 : 0 < Ξ΄' := div_pos Ξ΄0 H0
set C := max Οβ.distortion Οβ.compl.distortion
/- Next we choose a tagged partition of each `J β Οβ` such that the integral sum of `f` over this
partition is `Ξ΄'`-close to the integral of `f` over `J`. -/
have : β J β Οβ, β Οi : TaggedPrepartition J,
Οi.IsPartition β§ dist (integralSum f vol Οi) (integral J l f vol) β€ Ξ΄' β§
l.MemBaseSet J C (h.convergenceR Ξ΄' C) Οi := by
intro J hJ
have Hle : J β€ I := Οβ.le_of_mem hJ
have HJi : Integrable J l f vol := h.to_subbox Hle
set r := fun x => min (h.convergenceR Ξ΄' C x) (HJi.convergenceR Ξ΄' C x)
have hJd : J.distortion β€ C := le_trans (Finset.le_sup hJ) (le_max_left _ _)
rcases l.exists_memBaseSet_isPartition J hJd r with β¨ΟJ, hC, hpβ©
have hCβ : l.MemBaseSet J C (HJi.convergenceR Ξ΄' C) ΟJ := by
refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_right _ _
have hCβ : l.MemBaseSet J C (h.convergenceR Ξ΄' C) ΟJ := by
refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_left _ _
exact β¨ΟJ, hp, HJi.dist_integralSum_integral_le_of_memBaseSet Ξ΄'0 hCβ hp, hCββ©
/- Now we combine these tagged partitions into a tagged prepartition of `I` that covers the
same part of `I` as `Οβ` and apply `BoxIntegral.dist_integralSum_le_of_memBaseSet` to
`Ο` and this prepartition. -/
choose! Οi hΟip hΟiΞ΄' hΟiC using this
have : l.MemBaseSet I C (h.convergenceR Ξ΄' C) (Οβ.biUnionTagged Οi) :=
biUnionTagged_memBaseSet hΟiC hΟip fun _ => le_max_right _ _
have hU' : Ο.iUnion = (Οβ.biUnionTagged Οi).iUnion :=
hU.trans (Prepartition.iUnion_biUnion_partition _ hΟip).symm
have := h.dist_integralSum_le_of_memBaseSet h0 Ξ΄'0 hΟ this hU'
rw [integralSum_biUnionTagged] at this
calc
dist (integralSum f vol Ο) (β J β Οβ.boxes, integral J l f vol) β€
dist (integralSum f vol Ο) (β J β Οβ.boxes, integralSum f vol (Οi J)) +
dist (β J β Οβ.boxes, integralSum f vol (Οi J)) (β J β Οβ.boxes, integral J l f vol) :=
dist_triangle _ _ _
_ β€ Ξ΅ + Ξ΄' + β _J β Οβ.boxes, Ξ΄' := add_le_add this (dist_sum_sum_le_of_le _ hΟiΞ΄')
_ = Ξ΅ + Ξ΄ := by field_simp [Ξ΄']; ring
/-- **Henstock-Sacks inequality**. Let `r : ββΏ β (0, β)` be a function such that for any tagged
*partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the
integral of `f` by at most `Ξ΅`. Then for any tagged *prepartition* `Ο` subordinate to `r`, the
integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I`
covered by `Ο` by at most `Ξ΅`.
The actual statement
- uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`;
- uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of βsubordinate to `r`β to
| account for additional requirements like being a Henstock partition or having a bounded
distortion;
-/
theorem dist_integralSum_sum_integral_le_of_memBaseSet (h : Integrable I l f vol) (h0 : 0 < Ξ΅)
(hΟ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο) :
dist (integralSum f vol Ο) (β J β Ο.boxes, integral J l f vol) β€ Ξ΅ :=
h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq h0 hΟ rfl
/-- Integral sum of `f` over a tagged prepartition `Ο` such that `Ο.Union = Οβ.Union` tends to the
sum of integrals of `f` over the boxes of `Οβ`. -/
theorem tendsto_integralSum_sum_integral (h : Integrable I l f vol) (Οβ : Prepartition I) :
Tendsto (integralSum f vol) (l.toFilteriUnion I Οβ)
(π <| β J β Οβ.boxes, integral J l f vol) := by
refine ((l.hasBasis_toFilteriUnion I Οβ).tendsto_iff nhds_basis_closedBall).2 fun Ξ΅ Ξ΅0 => ?_
refine β¨h.convergenceR Ξ΅, h.convergenceR_cond Ξ΅, ?_β©
simp only [mem_inter_iff, Set.mem_iUnion, mem_setOf_eq]
rintro Ο β¨c, hc, hUβ©
exact h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq Ξ΅0 hc hU
/-- If `f` is integrable on `I`, then `fun J β¦ integral J l f vol` is box-additive on subboxes of
`I`: if `Οβ`, `Οβ` are two prepartitions of `I` covering the same part of `I`, the sum of integrals
of `f` over the boxes of `Οβ` is equal to the sum of integrals of `f` over the boxes of `Οβ`.
See also `BoxIntegral.Integrable.toBoxAdditive` for a bundled version. -/
theorem sum_integral_congr (h : Integrable I l f vol) {Οβ Οβ : Prepartition I}
(hU : Οβ.iUnion = Οβ.iUnion) :
β J β Οβ.boxes, integral J l f vol = β J β Οβ.boxes, integral J l f vol := by
refine tendsto_nhds_unique (h.tendsto_integralSum_sum_integral Οβ) ?_
rw [l.toFilteriUnion_congr _ hU]
exact h.tendsto_integralSum_sum_integral Οβ
/-- If `f` is integrable on `I`, then `fun J β¦ integral J l f vol` is box-additive on subboxes of
`I`: if `Οβ`, `Οβ` are two prepartitions of `I` covering the same part of `I`, the sum of integrals
of `f` over the boxes of `Οβ` is equal to the sum of integrals of `f` over the boxes of `Οβ`.
See also `BoxIntegral.Integrable.sum_integral_congr` for an unbundled version. -/
@[simps]
def toBoxAdditive (h : Integrable I l f vol) : ΞΉ βα΅α΅[I] F where
toFun J := integral J l f vol
sum_partition_boxes' J hJ Ο hΟ := by
replace hΟ := hΟ.iUnion_eq; rw [β Prepartition.iUnion_top] at hΟ
rw [(h.to_subbox (WithTop.coe_le_coe.1 hJ)).sum_integral_congr hΟ, Prepartition.top_boxes,
sum_singleton]
| Mathlib/Analysis/BoxIntegral/Basic.lean | 564 | 607 |
/-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kyle Miller, Eric Wieser
-/
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Data.Int.GCD
import Mathlib.Tactic.NormNum
/-! # `norm_num` extensions for GCD-adjacent functions
This module defines some `norm_num` extensions for functions such as
`Nat.gcd`, `Nat.lcm`, `Int.gcd`, and `Int.lcm`.
Note that `Nat.coprime` is reducible and defined in terms of `Nat.gcd`, so the `Nat.gcd` extension
also indirectly provides a `Nat.coprime` extension.
-/
namespace Tactic
namespace NormNum
theorem int_gcd_helper' {d : β} {x y : β€} (a b : β€) (hβ : (d : β€) β£ x) (hβ : (d : β€) β£ y)
(hβ : x * a + y * b = d) : Int.gcd x y = d := by
refine Nat.dvd_antisymm ?_ (Int.natCast_dvd_natCast.1 (Int.dvd_coe_gcd hβ hβ))
rw [β Int.natCast_dvd_natCast, β hβ]
apply dvd_add
Β· exact Int.gcd_dvd_left.mul_right _
Β· exact Int.gcd_dvd_right.mul_right _
theorem nat_gcd_helper_dvd_left (x y : β) (h : y % x = 0) : Nat.gcd x y = x :=
Nat.gcd_eq_left (Nat.dvd_of_mod_eq_zero h)
theorem nat_gcd_helper_dvd_right (x y : β) (h : x % y = 0) : Nat.gcd x y = y :=
Nat.gcd_eq_right (Nat.dvd_of_mod_eq_zero h)
|
theorem nat_gcd_helper_2 (d x y a b : β) (hu : x % d = 0) (hv : y % d = 0)
(h : x * a = y * b + d) : Nat.gcd x y = d := by
rw [β Int.gcd_natCast_natCast]
apply int_gcd_helper' a (-b)
(Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hu))
(Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hv))
rw [mul_neg, β sub_eq_add_neg, sub_eq_iff_eq_add']
| Mathlib/Tactic/NormNum/GCD.lean | 36 | 43 |
/-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Kim Morrison, Apurva Nakade, Yuyang Zhao
-/
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.SetTheory.PGame.Algebra
import Mathlib.Tactic.Abel
/-!
# Combinatorial games.
In this file we construct an instance `OrderedAddCommGroup SetTheory.Game`.
## Multiplication on pre-games
We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems
about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x β y` does not
imply `x * z β y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless,
the abelian group structure on games allows us to simplify many proofs for pre-games.
-/
-- Porting note: many definitions here are noncomputable as the compiler does not support PGame.rec
noncomputable section
namespace SetTheory
open Function PGame
universe u
-- Porting note: moved the setoid instance to PGame.lean
/-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from
two sets of combinatorial games that have been constructed at an earlier
stage. To do this in type theory, we say that a combinatorial pre-game is built
inductively from two families of combinatorial games indexed over any type
in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`,
reflecting that it is a proper class in ZFC.
A combinatorial game is then constructed by quotienting by the equivalence
`x β y β x β€ y β§ y β€ x`. -/
abbrev Game :=
Quotient PGame.setoid
namespace Game
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11445): added this definition
/-- Negation of games. -/
instance : Neg Game where
neg := Quot.map Neg.neg <| fun _ _ => (neg_equiv_neg_iff).2
instance : Zero Game where zero := β¦0β§
instance : Add Game where
add := Quotient.mapβ HAdd.hAdd <| fun _ _ hx _ _ hy => PGame.add_congr hx hy
instance instAddCommGroupWithOneGame : AddCommGroupWithOne Game where
zero := β¦0β§
one := β¦1β§
add_zero := by
rintro β¨xβ©
exact Quot.sound (add_zero_equiv x)
zero_add := by
rintro β¨xβ©
exact Quot.sound (zero_add_equiv x)
add_assoc := by
rintro β¨xβ© β¨yβ© β¨zβ©
exact Quot.sound add_assoc_equiv
neg_add_cancel := Quotient.ind <| fun x => Quot.sound (neg_add_cancel_equiv x)
add_comm := by
rintro β¨xβ© β¨yβ©
exact Quot.sound add_comm_equiv
nsmul := nsmulRec
zsmul := zsmulRec
instance : Inhabited Game :=
β¨0β©
theorem zero_def : (0 : Game) = β¦0β§ :=
rfl
instance instPartialOrderGame : PartialOrder Game where
le := Quotient.liftβ (Β· β€ Β·) fun _ _ _ _ hx hy => propext (le_congr hx hy)
le_refl := by
rintro β¨xβ©
exact le_refl x
le_trans := by
rintro β¨xβ© β¨yβ© β¨zβ©
exact @le_trans _ _ x y z
le_antisymm := by
rintro β¨xβ© β¨yβ© hβ hβ
apply Quot.sound
exact β¨hβ, hββ©
lt := Quotient.liftβ (Β· < Β·) fun _ _ _ _ hx hy => propext (lt_congr hx hy)
lt_iff_le_not_le := by
rintro β¨xβ© β¨yβ©
exact @lt_iff_le_not_le _ _ x y
/-- The less or fuzzy relation on games.
If `0 β§ x` (less or fuzzy with), then Left can win `x` as the first player. -/
def LF : Game β Game β Prop :=
Quotient.liftβ PGame.LF fun _ _ _ _ hx hy => propext (lf_congr hx hy)
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
theorem not_le : β {x y : Game}, Β¬x β€ y β Game.LF y x := by
rintro β¨xβ© β¨yβ©
exact PGame.not_le
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
theorem not_lf : β {x y : Game}, Β¬Game.LF x y β y β€ x := by
rintro β¨xβ© β¨yβ©
exact PGame.not_lf
/-- The fuzzy, confused, or incomparable relation on games.
If `x β 0`, then the first player can always win `x`. -/
def Fuzzy : Game β Game β Prop :=
Quotient.liftβ PGame.Fuzzy fun _ _ _ _ hx hy => propext (fuzzy_congr hx hy)
-- Porting note: had to replace β§ with LF, otherwise cannot differentiate with the operator on PGame
instance : IsTrichotomous Game LF :=
β¨by
rintro β¨xβ© β¨yβ©
change _ β¨ β¦xβ§ = β¦yβ§ β¨ _
rw [Quotient.eq]
apply lf_or_equiv_or_gfβ©
/-! It can be useful to use these lemmas to turn `PGame` inequalities into `Game` inequalities, as
the `AddCommGroup` structure on `Game` often simplifies many proofs. -/
end Game
namespace PGame
-- Porting note: In a lot of places, I had to add explicitly that the quotient element was a Game.
-- In Lean4, quotients don't have the setoid as an instance argument,
-- but as an explicit argument, see https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/confusion.20between.20equivalence.20and.20instance.20setoid/near/360822354
theorem le_iff_game_le {x y : PGame} : x β€ y β (β¦xβ§ : Game) β€ β¦yβ§ :=
Iff.rfl
theorem lf_iff_game_lf {x y : PGame} : x β§ y β Game.LF β¦xβ§ β¦yβ§ :=
Iff.rfl
theorem lt_iff_game_lt {x y : PGame} : x < y β (β¦xβ§ : Game) < β¦yβ§ :=
Iff.rfl
theorem equiv_iff_game_eq {x y : PGame} : x β y β (β¦xβ§ : Game) = β¦yβ§ :=
(@Quotient.eq' _ _ x y).symm
alias β¨game_eq, _β© := equiv_iff_game_eq
theorem fuzzy_iff_game_fuzzy {x y : PGame} : x β y β Game.Fuzzy β¦xβ§ β¦yβ§ :=
Iff.rfl
end PGame
namespace Game
local infixl:50 " β§ " => LF
local infixl:50 " β " => Fuzzy
instance addLeftMono : AddLeftMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_le_add_left _ _ _ _ b c h aβ©
instance addRightMono : AddRightMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_le_add_right _ _ _ _ b c h aβ©
instance addLeftStrictMono : AddLeftStrictMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_lt_add_left _ _ _ _ b c h aβ©
instance addRightStrictMono : AddRightStrictMono Game :=
β¨by
rintro β¨aβ© β¨bβ© β¨cβ© h
exact @add_lt_add_right _ _ _ _ b c h aβ©
theorem add_lf_add_right : β {b c : Game} (_ : b β§ c) (a), (b + a : Game) β§ c + a := by
rintro β¨bβ© β¨cβ© h β¨aβ©
apply PGame.add_lf_add_right h
theorem add_lf_add_left : β {b c : Game} (_ : b β§ c) (a), (a + b : Game) β§ a + c := by
rintro β¨bβ© β¨cβ© h β¨aβ©
apply PGame.add_lf_add_left h
instance isOrderedAddMonoid : IsOrderedAddMonoid Game :=
{ add_le_add_left := @add_le_add_left _ _ _ Game.addLeftMono }
/-- A small family of games is bounded above. -/
lemma bddAbove_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β Game.{u}) :
BddAbove (Set.range f) := by
obtain β¨x, hxβ© := PGame.bddAbove_range_of_small (Quotient.out β f)
refine β¨β¦xβ§, Set.forall_mem_range.2 fun i β¦ ?_β©
simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i
/-- A small set of games is bounded above. -/
lemma bddAbove_of_small (s : Set Game.{u}) [Small.{u} s] : BddAbove s := by
simpa using bddAbove_range_of_small (Subtype.val : s β Game.{u})
/-- A small family of games is bounded below. -/
lemma bddBelow_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β Game.{u}) :
BddBelow (Set.range f) := by
obtain β¨x, hxβ© := PGame.bddBelow_range_of_small (Quotient.out β f)
refine β¨β¦xβ§, Set.forall_mem_range.2 fun i β¦ ?_β©
simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i
/-- A small set of games is bounded below. -/
lemma bddBelow_of_small (s : Set Game.{u}) [Small.{u} s] : BddBelow s := by
simpa using bddBelow_range_of_small (Subtype.val : s β Game.{u})
end Game
namespace PGame
@[simp] theorem quot_zero : (β¦0β§ : Game) = 0 := rfl
@[simp] theorem quot_one : (β¦1β§ : Game) = 1 := rfl
@[simp] theorem quot_neg (a : PGame) : (β¦-aβ§ : Game) = -β¦aβ§ := rfl
@[simp] theorem quot_add (a b : PGame) : β¦a + bβ§ = (β¦aβ§ : Game) + β¦bβ§ := rfl
@[simp] theorem quot_sub (a b : PGame) : β¦a - bβ§ = (β¦aβ§ : Game) - β¦bβ§ := rfl
@[simp]
theorem quot_natCast : β n : β, β¦(n : PGame)β§ = (n : Game)
| 0 => rfl
| n + 1 => by
rw [PGame.nat_succ, quot_add, Nat.cast_add, Nat.cast_one, quot_natCast]
rfl
theorem quot_eq_of_mk'_quot_eq {x y : PGame} (L : x.LeftMoves β y.LeftMoves)
(R : x.RightMoves β y.RightMoves) (hl : β i, (β¦x.moveLeft iβ§ : Game) = β¦y.moveLeft (L i)β§)
(hr : β j, (β¦x.moveRight jβ§ : Game) = β¦y.moveRight (R j)β§) : (β¦xβ§ : Game) = β¦yβ§ :=
game_eq (.of_equiv L R (fun _ => equiv_iff_game_eq.2 (hl _))
(fun _ => equiv_iff_game_eq.2 (hr _)))
/-! Multiplicative operations can be defined at the level of pre-games,
but to prove their properties we need to use the abelian group structure of games.
Hence we define them here. -/
/-- The product of `x = {xL | xR}` and `y = {yL | yR}` is
`{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, xR*y + x*yL - xR*yL}`. -/
instance : Mul PGame.{u} :=
β¨fun x y => by
induction x generalizing y with | mk xl xr _ _ IHxl IHxr => _
induction y with | mk yl yr yL yR IHyl IHyr => _
have y := mk yl yr yL yR
refine β¨(xl Γ yl) β (xr Γ yr), (xl Γ yr) β (xr Γ yl), ?_, ?_β© <;> rintro (β¨i, jβ© | β¨i, jβ©)
Β· exact IHxl i y + IHyl j - IHxl i (yL j)
Β· exact IHxr i y + IHyr j - IHxr i (yR j)
Β· exact IHxl i y + IHyr j - IHxl i (yR j)
Β· exact IHxr i y + IHyl j - IHxr i (yL j)β©
theorem leftMoves_mul :
β x y : PGame.{u},
(x * y).LeftMoves = (x.LeftMoves Γ y.LeftMoves β x.RightMoves Γ y.RightMoves)
| β¨_, _, _, _β©, β¨_, _, _, _β© => rfl
theorem rightMoves_mul :
β x y : PGame.{u},
(x * y).RightMoves = (x.LeftMoves Γ y.RightMoves β x.RightMoves Γ y.LeftMoves)
| β¨_, _, _, _β©, β¨_, _, _, _β© => rfl
/-- Turns two left or right moves for `x` and `y` into a left move for `x * y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toLeftMovesMul {x y : PGame} :
(x.LeftMoves Γ y.LeftMoves) β (x.RightMoves Γ y.RightMoves) β (x * y).LeftMoves :=
Equiv.cast (leftMoves_mul x y).symm
/-- Turns a left and a right move for `x` and `y` into a right move for `x * y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toRightMovesMul {x y : PGame} :
(x.LeftMoves Γ y.RightMoves) β (x.RightMoves Γ y.LeftMoves) β (x * y).RightMoves :=
Equiv.cast (rightMoves_mul x y).symm
@[simp]
theorem mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inl (i, j)) =
xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j :=
rfl
@[simp]
theorem mul_moveLeft_inl {x y : PGame} {i j} :
(x * y).moveLeft (toLeftMovesMul (Sum.inl (i, j))) =
x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inr (i, j)) =
xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j :=
rfl
@[simp]
theorem mul_moveLeft_inr {x y : PGame} {i j} :
(x * y).moveLeft (toLeftMovesMul (Sum.inr (i, j))) =
x.moveRight i * y + x * y.moveRight j - x.moveRight i * y.moveRight j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inl (i, j)) =
xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j :=
rfl
@[simp]
theorem mul_moveRight_inl {x y : PGame} {i j} :
(x * y).moveRight (toRightMovesMul (Sum.inl (i, j))) =
x.moveLeft i * y + x * y.moveRight j - x.moveLeft i * y.moveRight j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inr (i, j)) =
xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j :=
rfl
@[simp]
theorem mul_moveRight_inr {x y : PGame} {i j} :
(x * y).moveRight (toRightMovesMul (Sum.inr (i, j))) =
x.moveRight i * y + x * y.moveLeft j - x.moveRight i * y.moveLeft j := by
cases x
cases y
rfl
@[simp]
theorem neg_mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inl (i, j)) =
-(xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j) :=
rfl
@[simp]
theorem neg_mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inr (i, j)) =
-(xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j) :=
rfl
@[simp]
theorem neg_mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inl (i, j)) =
-(xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j) :=
rfl
@[simp]
theorem neg_mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inr (i, j)) =
-(xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j) :=
rfl
theorem leftMoves_mul_cases {x y : PGame} (k) {P : (x * y).LeftMoves β Prop}
(hl : β ix iy, P <| toLeftMovesMul (Sum.inl β¨ix, iyβ©))
(hr : β jx jy, P <| toLeftMovesMul (Sum.inr β¨jx, jyβ©)) : P k := by
rw [β toLeftMovesMul.apply_symm_apply k]
rcases toLeftMovesMul.symm k with (β¨ix, iyβ© | β¨jx, jyβ©)
Β· apply hl
Β· apply hr
theorem rightMoves_mul_cases {x y : PGame} (k) {P : (x * y).RightMoves β Prop}
(hl : β ix jy, P <| toRightMovesMul (Sum.inl β¨ix, jyβ©))
(hr : β jx iy, P <| toRightMovesMul (Sum.inr β¨jx, iyβ©)) : P k := by
rw [β toRightMovesMul.apply_symm_apply k]
rcases toRightMovesMul.symm k with (β¨ix, iyβ© | β¨jx, jyβ©)
Β· apply hl
Β· apply hr
/-- `x * y` and `y * x` have the same moves. -/
protected lemma mul_comm (x y : PGame) : x * y β‘ y * x :=
match x, y with
| β¨xl, xr, xL, xRβ©, β¨yl, yr, yL, yRβ© => by
refine Identical.of_equiv ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _))
((Equiv.sumComm _ _).trans ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _))) ?_ ?_ <;>
Β· rintro (β¨_, _β© | β¨_, _β©) <;>
exact ((((PGame.mul_comm _ (mk _ _ _ _)).add (PGame.mul_comm (mk _ _ _ _) _)).trans
(PGame.add_comm _ _)).sub (PGame.mul_comm _ _))
termination_by (x, y)
/-- `x * y` and `y * x` have the same moves. -/
def mulCommRelabelling (x y : PGame.{u}) : x * y β‘r y * x :=
match x, y with
| β¨xl, xr, xL, xRβ©, β¨yl, yr, yL, yRβ© => by
refine β¨Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _),
(Equiv.sumComm _ _).trans (Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _)), ?_, ?_β©
<;>
rintro (β¨i, jβ© | β¨i, jβ©) <;>
{ dsimp
exact ((addCommRelabelling _ _).trans <|
(mulCommRelabelling _ _).addCongr (mulCommRelabelling _ _)).subCongr
(mulCommRelabelling _ _) }
termination_by (x, y)
theorem quot_mul_comm (x y : PGame.{u}) : (β¦x * yβ§ : Game) = β¦y * xβ§ :=
game_eq (x.mul_comm y).equiv
/-- `x * y` is equivalent to `y * x`. -/
theorem mul_comm_equiv (x y : PGame) : x * y β y * x :=
Quotient.exact <| quot_mul_comm _ _
instance isEmpty_leftMoves_mul (x y : PGame.{u})
[IsEmpty (x.LeftMoves Γ y.LeftMoves β x.RightMoves Γ y.RightMoves)] :
IsEmpty (x * y).LeftMoves := by
cases x
cases y
assumption
instance isEmpty_rightMoves_mul (x y : PGame.{u})
[IsEmpty (x.LeftMoves Γ y.RightMoves β x.RightMoves Γ y.LeftMoves)] :
IsEmpty (x * y).RightMoves := by
cases x
cases y
assumption
/-- `x * 0` has exactly the same moves as `0`. -/
protected lemma mul_zero (x : PGame) : x * 0 β‘ 0 := identical_zero _
/-- `x * 0` has exactly the same moves as `0`. -/
def mulZeroRelabelling (x : PGame) : x * 0 β‘r 0 :=
Relabelling.isEmpty _
/-- `x * 0` is equivalent to `0`. -/
theorem mul_zero_equiv (x : PGame) : x * 0 β 0 :=
x.mul_zero.equiv
@[simp]
theorem quot_mul_zero (x : PGame) : (β¦x * 0β§ : Game) = 0 :=
game_eq x.mul_zero_equiv
/-- `0 * x` has exactly the same moves as `0`. -/
protected lemma zero_mul (x : PGame) : 0 * x β‘ 0 := identical_zero _
/-- `0 * x` has exactly the same moves as `0`. -/
def zeroMulRelabelling (x : PGame) : 0 * x β‘r 0 :=
Relabelling.isEmpty _
/-- `0 * x` is equivalent to `0`. -/
theorem zero_mul_equiv (x : PGame) : 0 * x β 0 :=
x.zero_mul.equiv
@[simp]
theorem quot_zero_mul (x : PGame) : (β¦0 * xβ§ : Game) = 0 :=
game_eq x.zero_mul_equiv
/-- `-x * y` and `-(x * y)` have the same moves. -/
def negMulRelabelling (x y : PGame.{u}) : -x * y β‘r -(x * y) :=
match x, y with
| β¨xl, xr, xL, xRβ©, β¨yl, yr, yL, yRβ© => by
refine β¨Equiv.sumComm _ _, Equiv.sumComm _ _, ?_, ?_β© <;>
rintro (β¨i, jβ© | β¨i, jβ©) <;>
Β· dsimp
apply ((negAddRelabelling _ _).trans _).symm
apply ((negAddRelabelling _ _).trans (Relabelling.addCongr _ _)).subCongr
-- Porting note: we used to just do `<;> exact (negMulRelabelling _ _).symm` from here.
Β· exact (negMulRelabelling _ _).symm
Β· exact (negMulRelabelling _ _).symm
-- Porting note: not sure what has gone wrong here.
-- The goal is hideous here, and the `exact` doesn't work,
-- but if we just `change` it to look like the mathlib3 goal then we're fine!?
change -(mk xl xr xL xR * _) β‘r _
exact (negMulRelabelling _ _).symm
termination_by (x, y)
/-- `x * -y` and `-(x * y)` have the same moves. -/
@[simp]
lemma mul_neg (x y : PGame) : x * -y = -(x * y) :=
match x, y with
| mk xl xr xL xR, mk yl yr yL yR => by
refine ext rfl rfl ?_ ?_ <;> rintro (β¨i, jβ© | β¨i, jβ©) _ β¨rflβ©
all_goals
dsimp
rw [PGame.neg_sub', PGame.neg_add]
congr
exacts [mul_neg _ (mk ..), mul_neg .., mul_neg ..]
termination_by (x, y)
/-- `-x * y` and `-(x * y)` have the same moves. -/
lemma neg_mul (x y : PGame) : -x * y β‘ -(x * y) :=
((PGame.mul_comm _ _).trans (of_eq (mul_neg _ _))).trans (PGame.mul_comm _ _).neg
@[simp]
theorem quot_neg_mul (x y : PGame) : (β¦-x * yβ§ : Game) = -β¦x * yβ§ :=
game_eq (x.neg_mul y).equiv
/-- `x * -y` and `-(x * y)` have the same moves. -/
def mulNegRelabelling (x y : PGame) : x * -y β‘r -(x * y) :=
(mulCommRelabelling x _).trans <| (negMulRelabelling _ x).trans (mulCommRelabelling y x).negCongr
theorem quot_mul_neg (x y : PGame) : β¦x * -yβ§ = (-β¦x * yβ§ : Game) :=
game_eq (by rw [mul_neg])
theorem quot_neg_mul_neg (x y : PGame) : β¦-x * -yβ§ = (β¦x * yβ§ : Game) := by simp
@[simp]
theorem quot_left_distrib (x y z : PGame) : (β¦x * (y + z)β§ : Game) = β¦x * yβ§ + β¦x * zβ§ :=
match x, y, z with
| mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by
let x := mk xl xr xL xR
let y := mk yl yr yL yR
let z := mk zl zr zL zR
refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_
Β· fconstructor
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;>
-- Porting note: we've increased `maxDepth` here from `5` to `6`.
-- Likely this sort of off-by-one error is just a change in the implementation
-- of `solve_by_elim`.
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;> rfl
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;> rfl
Β· fconstructor
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, _ | _β© | β¨_, _ | _β©) <;> rfl
Β· rintro (β¨β¨_, _β© | β¨_, _β©β© | β¨_, _β© | β¨_, _β©) <;> rfl
-- Porting note: explicitly wrote out arguments to each recursive
-- quot_left_distrib reference below, because otherwise the decreasing_by block
-- failed. Previously, each branch ended with: `simp [quot_left_distrib]; abel`
-- See https://github.com/leanprover/lean4/issues/2288
Β· rintro (β¨i, j | kβ© | β¨i, j | kβ©)
Β· change
β¦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)β§ =
β¦xL i * y + x * yL j - xL i * yL j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_left_distrib (xL i) (yL j) (mk zl zr zL zR)]
abel
Β· change
β¦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)β§ =
β¦x * y + (xL i * z + x * zL k - xL i * zL k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zL k)]
abel
Β· change
β¦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)β§ =
β¦xR i * y + x * yR j - xR i * yR j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_left_distrib (xR i) (yR j) (mk zl zr zL zR)]
abel
Β· change
β¦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)β§ =
β¦x * y + (xR i * z + x * zR k - xR i * zR k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zR k)]
abel
Β· rintro (β¨i, j | kβ© | β¨i, j | kβ©)
Β· change
β¦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)β§ =
β¦xL i * y + x * yR j - xL i * yR j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_left_distrib (xL i) (yR j) (mk zl zr zL zR)]
abel
Β· change
β¦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)β§ =
β¦x * y + (xL i * z + x * zR k - xL i * zR k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zR k)]
abel
Β· change
β¦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)β§ =
β¦xR i * y + x * yL j - xR i * yL j + x * zβ§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_left_distrib (xR i) (yL j) (mk zl zr zL zR)]
abel
Β· change
β¦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)β§ =
β¦x * y + (xR i * z + x * zL k - xR i * zL k)β§
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zL k)]
abel
termination_by (x, y, z)
/-- `x * (y + z)` is equivalent to `x * y + x * z`. -/
theorem left_distrib_equiv (x y z : PGame) : x * (y + z) β x * y + x * z :=
Quotient.exact <| quot_left_distrib _ _ _
@[simp]
theorem quot_left_distrib_sub (x y z : PGame) : (β¦x * (y - z)β§ : Game) = β¦x * yβ§ - β¦x * zβ§ := by
change (β¦x * (y + -z)β§ : Game) = β¦x * yβ§ + -β¦x * zβ§
rw [quot_left_distrib, quot_mul_neg]
@[simp]
theorem quot_right_distrib (x y z : PGame) : (β¦(x + y) * zβ§ : Game) = β¦x * zβ§ + β¦y * zβ§ := by
simp only [quot_mul_comm, quot_left_distrib]
/-- `(x + y) * z` is equivalent to `x * z + y * z`. -/
theorem right_distrib_equiv (x y z : PGame) : (x + y) * z β x * z + y * z :=
Quotient.exact <| quot_right_distrib _ _ _
@[simp]
theorem quot_right_distrib_sub (x y z : PGame) : (β¦(y - z) * xβ§ : Game) = β¦y * xβ§ - β¦z * xβ§ := by
change (β¦(y + -z) * xβ§ : Game) = β¦y * xβ§ + -β¦z * xβ§
rw [quot_right_distrib, quot_neg_mul]
/-- `x * 1` has the same moves as `x`. -/
def mulOneRelabelling : β x : PGame.{u}, x * 1 β‘r x
| β¨xl, xr, xL, xRβ© => by
-- Porting note: the next four lines were just `unfold has_one.one,`
show _ * One.one β‘r _
unfold One.one
unfold instOnePGame
change mk _ _ _ _ * mk _ _ _ _ β‘r _
refine β¨(Equiv.sumEmpty _ _).trans (Equiv.prodPUnit _),
(Equiv.emptySum _ _).trans (Equiv.prodPUnit _), ?_, ?_β© <;>
(try rintro (β¨i, β¨β©β© | β¨i, β¨β©β©)) <;>
{ dsimp
apply (Relabelling.subCongr (Relabelling.refl _) (mulZeroRelabelling _)).trans
rw [sub_zero_eq_add_zero]
exact (addZeroRelabelling _).trans <|
(((mulOneRelabelling _).addCongr (mulZeroRelabelling _)).trans <| addZeroRelabelling _) }
/-- `1 * x` has the same moves as `x`. -/
protected lemma one_mul : β (x : PGame), 1 * x β‘ x
| β¨xl, xr, xL, xRβ© => by
refine Identical.of_equiv ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _))
((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ?_ ?_ <;>
Β· rintro (β¨β¨β©, _β© | β¨β¨β©, _β©)
exact ((((PGame.zero_mul (mk _ _ _ _)).add (PGame.one_mul _)).trans (PGame.zero_add _)).sub
(PGame.zero_mul _)).trans (PGame.sub_zero _)
/-- `x * 1` has the same moves as `x`. -/
protected lemma mul_one (x : PGame) : x * 1 β‘ x := (x.mul_comm _).trans x.one_mul
@[simp]
theorem quot_mul_one (x : PGame) : (β¦x * 1β§ : Game) = β¦xβ§ :=
game_eq x.mul_one.equiv
/-- `x * 1` is equivalent to `x`. -/
theorem mul_one_equiv (x : PGame) : x * 1 β x :=
Quotient.exact <| quot_mul_one x
/-- `1 * x` has the same moves as `x`. -/
def oneMulRelabelling (x : PGame) : 1 * x β‘r x :=
(mulCommRelabelling 1 x).trans <| mulOneRelabelling x
@[simp]
theorem quot_one_mul (x : PGame) : (β¦1 * xβ§ : Game) = β¦xβ§ :=
game_eq x.one_mul.equiv
/-- `1 * x` is equivalent to `x`. -/
theorem one_mul_equiv (x : PGame) : 1 * x β x :=
Quotient.exact <| quot_one_mul x
theorem quot_mul_assoc (x y z : PGame) : (β¦x * y * zβ§ : Game) = β¦x * (y * z)β§ :=
match x, y, z with
| mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by
let x := mk xl xr xL xR
let y := mk yl yr yL yR
let z := mk zl zr zL zR
refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_
Β· fconstructor
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;>
-- Porting note: as above, increased the `maxDepth` here by 1.
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;> rfl
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;> rfl
Β· fconstructor
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
Β· rintro (β¨β¨_, _β© | β¨_, _β©, _β© | β¨β¨_, _β© | β¨_, _β©, _β©) <;> rfl
Β· rintro (β¨_, β¨_, _β© | β¨_, _β©β© | β¨_, β¨_, _β© | β¨_, _β©β©) <;> rfl
-- Porting note: explicitly wrote out arguments to each recursive
-- quot_mul_assoc reference below, because otherwise the decreasing_by block
-- failed. Each branch previously ended with: `simp [quot_mul_assoc]; abel`
-- See https://github.com/leanprover/lean4/issues/2288
Β· rintro (β¨β¨i, jβ© | β¨i, jβ©, kβ© | β¨β¨i, jβ© | β¨i, jβ©, kβ©)
Β· change
β¦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zL k -
(xL i * y + x * yL j - xL i * yL j) * zL kβ§ =
β¦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) -
xL i * (yL j * z + y * zL k - yL j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)]
rw [quot_mul_assoc (xL i) (yL j) (zL k)]
abel
Β· change
β¦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zL k -
(xR i * y + x * yR j - xR i * yR j) * zL kβ§ =
β¦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) -
xR i * (yR j * z + y * zL k - yR j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)]
rw [quot_mul_assoc (xR i) (yR j) (zL k)]
abel
Β· change
β¦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zR k -
(xL i * y + x * yR j - xL i * yR j) * zR kβ§ =
β¦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) -
xL i * (yR j * z + y * zR k - yR j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)]
rw [quot_mul_assoc (xL i) (yR j) (zR k)]
abel
Β· change
β¦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zR k -
(xR i * y + x * yL j - xR i * yL j) * zR kβ§ =
β¦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) -
xR i * (yL j * z + y * zR k - yL j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)]
rw [quot_mul_assoc (xR i) (yL j) (zR k)]
abel
Β· rintro (β¨β¨i, jβ© | β¨i, jβ©, kβ© | β¨β¨i, jβ© | β¨i, jβ©, kβ©)
Β· change
β¦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zR k -
(xL i * y + x * yL j - xL i * yL j) * zR kβ§ =
β¦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) -
xL i * (yL j * z + y * zR k - yL j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)]
rw [quot_mul_assoc (xL i) (yL j) (zR k)]
abel
Β· change
β¦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zR k -
(xR i * y + x * yR j - xR i * yR j) * zR kβ§ =
β¦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) -
xR i * (yR j * z + y * zR k - yR j * zR k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)]
rw [quot_mul_assoc (xR i) (yR j) (zR k)]
abel
Β· change
β¦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zL k -
(xL i * y + x * yR j - xL i * yR j) * zL kβ§ =
β¦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) -
xL i * (yR j * z + y * zL k - yR j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)]
rw [quot_mul_assoc (xL i) (yR j) (zL k)]
abel
Β· change
β¦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zL k -
(xR i * y + x * yL j - xR i * yL j) * zL kβ§ =
β¦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) -
xR i * (yL j * z + y * zL k - yL j * zL k)β§
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)]
rw [quot_mul_assoc (xR i) (yL j) (zL k)]
abel
termination_by (x, y, z)
/-- `x * y * z` is equivalent to `x * (y * z)`. -/
theorem mul_assoc_equiv (x y z : PGame) : x * y * z β x * (y * z) :=
Quotient.exact <| quot_mul_assoc _ _ _
/-- The left options of `x * y` of the first kind, i.e. of the form `xL * y + x * yL - xL * yL`. -/
def mulOption (x y : PGame) (i : LeftMoves x) (j : LeftMoves y) : PGame :=
x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j
/-- Any left option of `x * y` of the first kind is also a left option of `x * -(-y)` of
the first kind. -/
lemma mulOption_neg_neg {x} (y) {i j} :
mulOption x y i j = mulOption x (-(-y)) i (toLeftMovesNeg <| toRightMovesNeg j) := by
simp [mulOption]
/-- The left options of `x * y` agree with that of `y * x` up to equivalence. -/
lemma mulOption_symm (x y) {i j} : β¦mulOption x y i jβ§ = (β¦mulOption y x j iβ§ : Game) := by
dsimp only [mulOption, quot_sub, quot_add]
rw [add_comm]
congr 1
on_goal 1 => congr 1
all_goals rw [quot_mul_comm]
/-- The left options of `x * y` of the second kind are the left options of `(-x) * (-y)` of the
first kind, up to equivalence. -/
lemma leftMoves_mul_iff {x y : PGame} (P : Game β Prop) :
(β k, P β¦(x * y).moveLeft kβ§) β
(β i j, P β¦mulOption x y i jβ§) β§ (β i j, P β¦mulOption (-x) (-y) i jβ§) := by
cases x; cases y
constructor <;> intro h
on_goal 1 =>
constructor <;> intros i j
Β· exact h (Sum.inl (i, j))
convert h (Sum.inr (i, j)) using 1
on_goal 2 =>
rintro (β¨i, jβ© | β¨i, jβ©)
Β· exact h.1 i j
convert h.2 i j using 1
all_goals
dsimp only [mk_mul_moveLeft_inr, quot_sub, quot_add, neg_def, mulOption, moveLeft_mk]
rw [β neg_def, β neg_def]
congr 1
on_goal 1 => congr 1
all_goals rw [quot_neg_mul_neg]
/-- The right options of `x * y` are the left options of `x * (-y)` and of `(-x) * y` of the first
kind, up to equivalence. -/
lemma rightMoves_mul_iff {x y : PGame} (P : Game β Prop) :
(β k, P β¦(x * y).moveRight kβ§) β
(β i j, P (-β¦mulOption x (-y) i jβ§)) β§ (β i j, P (-β¦mulOption (-x) y i jβ§)) := by
cases x; cases y
constructor <;> intro h
on_goal 1 =>
constructor <;> intros i j
on_goal 1 => convert h (Sum.inl (i, j))
on_goal 2 => convert h (Sum.inr (i, j))
on_goal 3 =>
rintro (β¨i, jβ© | β¨i, jβ©)
on_goal 1 => convert h.1 i j using 1
on_goal 2 => convert h.2 i j using 1
all_goals
dsimp [mulOption]
rw [neg_sub', neg_add, β neg_def]
congr 1
on_goal 1 => congr 1
any_goals rw [quot_neg_mul, neg_neg]
iterate 6 rw [quot_mul_neg, neg_neg]
/-- Because the two halves of the definition of `inv` produce more elements
on each side, we have to define the two families inductively.
This is the indexing set for the function, and `invVal` is the function part. -/
inductive InvTy (l r : Type u) : Bool β Type u
| zero : InvTy l r false
| leftβ : r β InvTy l r false β InvTy l r false
| leftβ : l β InvTy l r true β InvTy l r false
| rightβ : l β InvTy l r false β InvTy l r true
| rightβ : r β InvTy l r true β InvTy l r true
instance (l r : Type u) [IsEmpty l] [IsEmpty r] : IsEmpty (InvTy l r true) :=
β¨by rintro (_ | _ | _ | a | a) <;> exact isEmptyElim aβ©
instance InvTy.instInhabited (l r : Type u) : Inhabited (InvTy l r false) :=
β¨InvTy.zeroβ©
instance uniqueInvTy (l r : Type u) [IsEmpty l] [IsEmpty r] : Unique (InvTy l r false) :=
{ InvTy.instInhabited l r with
uniq := by
rintro (a | a | a)
Β· rfl
all_goals exact isEmptyElim a }
/-- Because the two halves of the definition of `inv` produce more elements
of each side, we have to define the two families inductively.
This is the function part, defined by recursion on `InvTy`. -/
def invVal {l r} (L : l β PGame) (R : r β PGame) (IHl : l β PGame) (IHr : r β PGame)
(x : PGame) : β {b}, InvTy l r b β PGame
| _, InvTy.zero => 0
| _, InvTy.leftβ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i
| _, InvTy.leftβ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i
| _, InvTy.rightβ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i
| _, InvTy.rightβ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i
@[simp]
theorem invVal_isEmpty {l r : Type u} {b} (L R IHl IHr) (i : InvTy l r b) (x) [IsEmpty l]
[IsEmpty r] : invVal L R IHl IHr x i = 0 := by
obtain - | a | a | a | a := i
Β· rfl
all_goals exact isEmptyElim a
/-- The inverse of a positive surreal number `x = {L | R}` is
given by `xβ»ΒΉ = {0,
(1 + (R - x) * xβ»ΒΉL) * R, (1 + (L - x) * xβ»ΒΉR) * L |
(1 + (L - x) * xβ»ΒΉL) * L, (1 + (R - x) * xβ»ΒΉR) * R}`.
Because the two halves `xβ»ΒΉL, xβ»ΒΉR` of `xβ»ΒΉ` are used in their own
definition, the sets and elements are inductively generated. -/
def inv' : PGame β PGame
| β¨l, r, L, Rβ© =>
let l' := { i // 0 < L i }
let L' : l' β PGame := fun i => L i.1
let IHl' : l' β PGame := fun i => inv' (L i.1)
let IHr i := inv' (R i)
let x := mk l r L R
β¨InvTy l' r false, InvTy l' r true, invVal L' R IHl' IHr x, invVal L' R IHl' IHr xβ©
theorem zero_lf_inv' : β x : PGame, 0 β§ inv' x
| β¨xl, xr, xL, xRβ© => by
convert lf_mk _ _ InvTy.zero
rfl
/-- `inv' 0` has exactly the same moves as `1`. -/
def inv'Zero : inv' 0 β‘r 1 := by
| change mk _ _ _ _ β‘r 1
refine β¨?_, ?_, fun i => ?_, IsEmpty.elim ?_β©
Β· apply Equiv.equivPUnit (InvTy _ _ _)
Β· apply Equiv.equivPEmpty (InvTy _ _ _)
Β· -- Porting note: we added `rfl` after the `simp`
| Mathlib/SetTheory/Game/Basic.lean | 953 | 957 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Ring.Associated
import Mathlib.Algebra.Star.Unitary
import Mathlib.RingTheory.PrincipalIdealDomain
import Mathlib.Tactic.Ring
import Mathlib.Algebra.EuclideanDomain.Int
/-! # β€[βd]
The ring of integers adjoined with a square root of `d : β€`.
After defining the norm, we show that it is a linearly ordered commutative ring,
as well as an integral domain.
We provide the universal property, that ring homomorphisms `β€βd β+* R` correspond
to choices of square roots of `d` in `R`.
-/
/-- The ring of integers adjoined with a square root of `d`.
These have the form `a + b βd` where `a b : β€`. The components
are called `re` and `im` by analogy to the negative `d` case. -/
@[ext]
structure Zsqrtd (d : β€) where
/-- Component of the integer not multiplied by `βd` -/
re : β€
/-- Component of the integer multiplied by `βd` -/
im : β€
deriving DecidableEq
@[inherit_doc] prefix:100 "β€β" => Zsqrtd
namespace Zsqrtd
section
variable {d : β€}
/-- Convert an integer to a `β€βd` -/
def ofInt (n : β€) : β€βd :=
β¨n, 0β©
theorem ofInt_re (n : β€) : (ofInt n : β€βd).re = n :=
rfl
theorem ofInt_im (n : β€) : (ofInt n : β€βd).im = 0 :=
rfl
/-- The zero of the ring -/
instance : Zero (β€βd) :=
β¨ofInt 0β©
@[simp]
theorem zero_re : (0 : β€βd).re = 0 :=
rfl
@[simp]
theorem zero_im : (0 : β€βd).im = 0 :=
rfl
instance : Inhabited (β€βd) :=
β¨0β©
/-- The one of the ring -/
instance : One (β€βd) :=
β¨ofInt 1β©
@[simp]
theorem one_re : (1 : β€βd).re = 1 :=
rfl
@[simp]
theorem one_im : (1 : β€βd).im = 0 :=
rfl
/-- The representative of `βd` in the ring -/
def sqrtd : β€βd :=
β¨0, 1β©
@[simp]
theorem sqrtd_re : (sqrtd : β€βd).re = 0 :=
rfl
@[simp]
theorem sqrtd_im : (sqrtd : β€βd).im = 1 :=
rfl
/-- Addition of elements of `β€βd` -/
instance : Add (β€βd) :=
β¨fun z w => β¨z.1 + w.1, z.2 + w.2β©β©
@[simp]
theorem add_def (x y x' y' : β€) : (β¨x, yβ© + β¨x', y'β© : β€βd) = β¨x + x', y + y'β© :=
rfl
@[simp]
theorem add_re (z w : β€βd) : (z + w).re = z.re + w.re :=
rfl
@[simp]
theorem add_im (z w : β€βd) : (z + w).im = z.im + w.im :=
rfl
/-- Negation in `β€βd` -/
instance : Neg (β€βd) :=
β¨fun z => β¨-z.1, -z.2β©β©
@[simp]
theorem neg_re (z : β€βd) : (-z).re = -z.re :=
rfl
@[simp]
theorem neg_im (z : β€βd) : (-z).im = -z.im :=
rfl
/-- Multiplication in `β€βd` -/
instance : Mul (β€βd) :=
β¨fun z w => β¨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1β©β©
@[simp]
theorem mul_re (z w : β€βd) : (z * w).re = z.re * w.re + d * z.im * w.im :=
rfl
@[simp]
theorem mul_im (z w : β€βd) : (z * w).im = z.re * w.im + z.im * w.re :=
rfl
instance addCommGroup : AddCommGroup (β€βd) := by
refine
{ add := (Β· + Β·)
zero := (0 : β€βd)
sub := fun a b => a + -b
neg := Neg.neg
nsmul := @nsmulRec (β€βd) β¨0β© β¨(Β· + Β·)β©
zsmul := @zsmulRec (β€βd) β¨0β© β¨(Β· + Β·)β© β¨Neg.negβ© (@nsmulRec (β€βd) β¨0β© β¨(Β· + Β·)β©)
add_assoc := ?_
zero_add := ?_
add_zero := ?_
neg_add_cancel := ?_
add_comm := ?_ } <;>
intros <;>
ext <;>
simp [add_comm, add_left_comm]
@[simp]
theorem sub_re (z w : β€βd) : (z - w).re = z.re - w.re :=
rfl
@[simp]
theorem sub_im (z w : β€βd) : (z - w).im = z.im - w.im :=
rfl
instance addGroupWithOne : AddGroupWithOne (β€βd) :=
{ Zsqrtd.addCommGroup with
natCast := fun n => ofInt n
intCast := ofInt
one := 1 }
instance commRing : CommRing (β€βd) := by
refine
{ Zsqrtd.addGroupWithOne with
mul := (Β· * Β·)
npow := @npowRec (β€βd) β¨1β© β¨(Β· * Β·)β©,
add_comm := ?_
left_distrib := ?_
right_distrib := ?_
zero_mul := ?_
mul_zero := ?_
mul_assoc := ?_
one_mul := ?_
mul_one := ?_
mul_comm := ?_ } <;>
intros <;>
ext <;>
simp <;>
ring
instance : AddMonoid (β€βd) := by infer_instance
instance : Monoid (β€βd) := by infer_instance
instance : CommMonoid (β€βd) := by infer_instance
instance : CommSemigroup (β€βd) := by infer_instance
instance : Semigroup (β€βd) := by infer_instance
instance : AddCommSemigroup (β€βd) := by infer_instance
instance : AddSemigroup (β€βd) := by infer_instance
instance : CommSemiring (β€βd) := by infer_instance
instance : Semiring (β€βd) := by infer_instance
instance : Ring (β€βd) := by infer_instance
instance : Distrib (β€βd) := by infer_instance
/-- Conjugation in `β€βd`. The conjugate of `a + b βd` is `a - b βd`. -/
instance : Star (β€βd) where
star z := β¨z.1, -z.2β©
@[simp]
theorem star_mk (x y : β€) : star (β¨x, yβ© : β€βd) = β¨x, -yβ© :=
rfl
@[simp]
theorem star_re (z : β€βd) : (star z).re = z.re :=
rfl
@[simp]
theorem star_im (z : β€βd) : (star z).im = -z.im :=
rfl
instance : StarRing (β€βd) where
star_involutive _ := Zsqrtd.ext rfl (neg_neg _)
star_mul a b := by ext <;> simp <;> ring
star_add _ _ := Zsqrtd.ext rfl (neg_add _ _)
-- Porting note: proof was `by decide`
instance nontrivial : Nontrivial (β€βd) :=
β¨β¨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)β©β©
@[simp]
theorem natCast_re (n : β) : (n : β€βd).re = n :=
rfl
@[simp]
theorem ofNat_re (n : β) [n.AtLeastTwo] : (ofNat(n) : β€βd).re = n :=
rfl
@[simp]
theorem natCast_im (n : β) : (n : β€βd).im = 0 :=
rfl
@[simp]
theorem ofNat_im (n : β) [n.AtLeastTwo] : (ofNat(n) : β€βd).im = 0 :=
rfl
theorem natCast_val (n : β) : (n : β€βd) = β¨n, 0β© :=
rfl
@[simp]
theorem intCast_re (n : β€) : (n : β€βd).re = n := by cases n <;> rfl
@[simp]
theorem intCast_im (n : β€) : (n : β€βd).im = 0 := by cases n <;> rfl
theorem intCast_val (n : β€) : (n : β€βd) = β¨n, 0β© := by ext <;> simp
instance : CharZero (β€βd) where cast_injective m n := by simp [Zsqrtd.ext_iff]
@[simp]
theorem ofInt_eq_intCast (n : β€) : (ofInt n : β€βd) = n := by ext <;> simp [ofInt_re, ofInt_im]
@[simp]
theorem nsmul_val (n : β) (x y : β€) : (n : β€βd) * β¨x, yβ© = β¨n * x, n * yβ© := by ext <;> simp
@[simp]
theorem smul_val (n x y : β€) : (n : β€βd) * β¨x, yβ© = β¨n * x, n * yβ© := by ext <;> simp
theorem smul_re (a : β€) (b : β€βd) : (βa * b).re = a * b.re := by simp
theorem smul_im (a : β€) (b : β€βd) : (βa * b).im = a * b.im := by simp
@[simp]
theorem muld_val (x y : β€) : sqrtd (d := d) * β¨x, yβ© = β¨d * y, xβ© := by ext <;> simp
@[simp]
theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp
@[simp]
theorem smuld_val (n x y : β€) : sqrtd * (n : β€βd) * β¨x, yβ© = β¨d * n * y, n * xβ© := by ext <;> simp
theorem decompose {x y : β€} : (β¨x, yβ© : β€βd) = x + sqrtd (d := d) * y := by ext <;> simp
theorem mul_star {x y : β€} : (β¨x, yβ© * star β¨x, yβ© : β€βd) = x * x - d * y * y := by
ext <;> simp [sub_eq_add_neg, mul_comm]
theorem intCast_dvd (z : β€) (a : β€βd) : βz β£ a β z β£ a.re β§ z β£ a.im := by
constructor
Β· rintro β¨x, rflβ©
simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff,
mul_re, mul_zero, intCast_im]
Β· rintro β¨β¨r, hrβ©, β¨i, hiβ©β©
use β¨r, iβ©
rw [smul_val, Zsqrtd.ext_iff]
exact β¨hr, hiβ©
@[simp, norm_cast]
theorem intCast_dvd_intCast (a b : β€) : (a : β€βd) β£ b β a β£ b := by
rw [intCast_dvd]
constructor
Β· rintro β¨hre, -β©
rwa [intCast_re] at hre
Β· rw [intCast_re, intCast_im]
exact fun hc => β¨hc, dvd_zero aβ©
protected theorem eq_of_smul_eq_smul_left {a : β€} {b c : β€βd} (ha : a β 0) (h : βa * b = a * c) :
b = c := by
rw [Zsqrtd.ext_iff] at h β’
apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancelβ ha
section Gcd
theorem gcd_eq_zero_iff (a : β€βd) : Int.gcd a.re a.im = 0 β a = 0 := by
simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re]
theorem gcd_pos_iff (a : β€βd) : 0 < Int.gcd a.re a.im β a β 0 :=
pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff
theorem isCoprime_of_dvd_isCoprime {a b : β€βd} (hcoprime : IsCoprime a.re a.im) (hdvd : b β£ a) :
IsCoprime b.re b.im := by
apply isCoprime_of_dvd
Β· rintro β¨hre, himβ©
obtain rfl : b = 0 := Zsqrtd.ext hre him
rw [zero_dvd_iff] at hdvd
simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime
Β· rintro z hz - hzdvdu hzdvdv
apply hz
obtain β¨ha, hbβ© : z β£ a.re β§ z β£ a.im := by
rw [β intCast_dvd]
apply dvd_trans _ hdvd
rw [intCast_dvd]
exact β¨hzdvdu, hzdvdvβ©
exact hcoprime.isUnit_of_dvd' ha hb
@[deprecated (since := "2025-01-23")] alias coprime_of_dvd_coprime := isCoprime_of_dvd_isCoprime
theorem exists_coprime_of_gcd_pos {a : β€βd} (hgcd : 0 < Int.gcd a.re a.im) :
β b : β€βd, a = ((Int.gcd a.re a.im : β€) : β€βd) * b β§ IsCoprime b.re b.im := by
obtain β¨re, im, H1, Hre, Himβ© := Int.exists_gcd_one hgcd
rw [mul_comm] at Hre Him
refine β¨β¨re, imβ©, ?_, ?_β©
Β· rw [smul_val, β Hre, β Him]
Β· rw [Int.isCoprime_iff_gcd_eq_one, H1]
end Gcd
/-- Read `SqLe a c b d` as `a βc β€ b βd` -/
def SqLe (a c b d : β) : Prop :=
c * a * a β€ d * b * b
theorem sqLe_of_le {c d x y z w : β} (xz : z β€ x) (yw : y β€ w) (xy : SqLe x c y d) : SqLe z c w d :=
le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <|
le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _))
theorem sqLe_add_mixed {c d x y z w : β} (xy : SqLe x c y d) (zw : SqLe z c w d) :
c * (x * z) β€ d * (y * w) :=
Nat.mul_self_le_mul_self_iff.1 <| by
simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _)
theorem sqLe_add {c d x y z w : β} (xy : SqLe x c y d) (zw : SqLe z c w d) :
SqLe (x + z) c (y + w) d := by
have xz := sqLe_add_mixed xy zw
simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw
simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *]
theorem sqLe_cancel {c d x y z w : β} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) :
SqLe z c w d := by
apply le_of_not_gt
intro l
refine not_le_of_gt ?_ h
simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt]
have hm := sqLe_add_mixed zw (le_of_lt l)
simp only [SqLe, mul_assoc, gt_iff_lt] at l zw
exact
lt_of_le_of_lt (add_le_add_right zw _)
(add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _)
theorem sqLe_smul {c d x y : β} (n : β) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by
simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy
theorem sqLe_mul {d x y z w : β} :
(SqLe x 1 y d β SqLe z 1 w d β SqLe (x * w + y * z) d (x * z + d * y * w) 1) β§
(SqLe x 1 y d β SqLe w d z 1 β SqLe (x * z + d * y * w) 1 (x * w + y * z) d) β§
(SqLe y d x 1 β SqLe z 1 w d β SqLe (x * z + d * y * w) 1 (x * w + y * z) d) β§
(SqLe y d x 1 β SqLe w d z 1 β SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by
refine β¨?_, ?_, ?_, ?_β© <;>
Β· intro xy zw
have :=
Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy))
(sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw))
refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_)
convert this using 1
simp only [one_mul, Int.natCast_add, Int.natCast_mul]
ring
open Int in
/-- "Generalized" `nonneg`. `nonnegg c d x y` means `a βc + b βd β₯ 0`;
we are interested in the case `c = 1` but this is more symmetric -/
def Nonnegg (c d : β) : β€ β β€ β Prop
| (a : β), (b : β) => True
| (a : β), -[b+1] => SqLe (b + 1) c a d
| -[a+1], (b : β) => SqLe (a + 1) d b c
| -[_+1], -[_+1] => False
theorem nonnegg_comm {c d : β} {x y : β€} : Nonnegg c d x y = Nonnegg d c y x := by
cases x <;> cases y <;> rfl
theorem nonnegg_neg_pos {c d} : β {a b : β}, Nonnegg c d (-a) b β SqLe a d b c
| 0, b => β¨by simp [SqLe, Nat.zero_le], fun _ => trivialβ©
| a + 1, b => by rfl
theorem nonnegg_pos_neg {c d} {a b : β} : Nonnegg c d a (-b) β SqLe b c a d := by
rw [nonnegg_comm]; exact nonnegg_neg_pos
open Int in
theorem nonnegg_cases_right {c d} {a : β} :
β {b : β€}, (β x : β, b = -x β SqLe x c a d) β Nonnegg c d a b
| (b : Nat), _ => trivial
| -[b+1], h => h (b + 1) rfl
theorem nonnegg_cases_left {c d} {b : β} {a : β€} (h : β x : β, a = -x β SqLe x d b c) :
Nonnegg c d a b :=
cast nonnegg_comm (nonnegg_cases_right h)
section Norm
/-- The norm of an element of `β€[βd]`. -/
def norm (n : β€βd) : β€ :=
n.re * n.re - d * n.im * n.im
theorem norm_def (n : β€βd) : n.norm = n.re * n.re - d * n.im * n.im :=
rfl
@[simp]
theorem norm_zero : norm (0 : β€βd) = 0 := by simp [norm]
@[simp]
theorem norm_one : norm (1 : β€βd) = 1 := by simp [norm]
@[simp]
theorem norm_intCast (n : β€) : norm (n : β€βd) = n * n := by simp [norm]
@[simp]
theorem norm_natCast (n : β) : norm (n : β€βd) = n * n :=
norm_intCast n
| @[simp]
theorem norm_mul (n m : β€βd) : norm (n * m) = norm n * norm m := by
simp only [norm, mul_im, mul_re]
ring
/-- `norm` as a `MonoidHom`. -/
def normMonoidHom : β€βd β* β€ where
toFun := norm
map_mul' := norm_mul
map_one' := norm_one
theorem norm_eq_mul_conj (n : β€βd) : (norm n : β€βd) = n * star n := by
ext <;> simp [norm, star, mul_comm, sub_eq_add_neg]
| Mathlib/NumberTheory/Zsqrtd/Basic.lean | 446 | 459 |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Complex.Arg
import Mathlib.Analysis.SpecialFunctions.Log.Basic
/-!
# The complex `log` function
Basic properties, relationship with `exp`.
-/
noncomputable section
namespace Complex
open Set Filter Bornology
open scoped Real Topology ComplexConjugate
/-- Inverse of the `exp` function. Returns values such that `(log x).im > - Ο` and `(log x).im β€ Ο`.
`log 0 = 0` -/
@[pp_nodot]
noncomputable def log (x : β) : β :=
Real.log βxβ + arg x * I
theorem log_re (x : β) : x.log.re = Real.log βxβ := by simp [log]
theorem log_im (x : β) : x.log.im = x.arg := by simp [log]
theorem neg_pi_lt_log_im (x : β) : -Ο < (log x).im := by simp only [log_im, neg_pi_lt_arg]
theorem log_im_le_pi (x : β) : (log x).im β€ Ο := by simp only [log_im, arg_le_pi]
theorem exp_log {x : β} (hx : x β 0) : exp (log x) = x := by
rw [log, exp_add_mul_I, β ofReal_sin, sin_arg, β ofReal_cos, cos_arg hx, β ofReal_exp,
Real.exp_log (norm_pos_iff.mpr hx), mul_add, ofReal_div, ofReal_div,
mul_div_cancelβ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), β mul_assoc,
mul_div_cancelβ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), re_add_im]
@[simp]
theorem range_exp : Set.range exp = {0}αΆ :=
Set.ext fun x =>
β¨by
rintro β¨x, rflβ©
exact exp_ne_zero x, fun hx => β¨log x, exp_log hxβ©β©
theorem log_exp {x : β} (hxβ : -Ο < x.im) (hxβ : x.im β€ Ο) : log (exp x) = x := by
rw [log, norm_exp, Real.log_exp, exp_eq_exp_re_mul_sin_add_cos, β ofReal_exp,
arg_mul_cos_add_sin_mul_I (Real.exp_pos _) β¨hxβ, hxββ©, re_add_im]
theorem exp_inj_of_neg_pi_lt_of_le_pi {x y : β} (hxβ : -Ο < x.im) (hxβ : x.im β€ Ο) (hyβ : -Ο < y.im)
(hyβ : y.im β€ Ο) (hxy : exp x = exp y) : x = y := by
rw [β log_exp hxβ hxβ, β log_exp hyβ hyβ, hxy]
theorem ofReal_log {x : β} (hx : 0 β€ x) : (x.log : β) = log x :=
Complex.ext (by rw [log_re, ofReal_re, Complex.norm_of_nonneg hx])
(by rw [ofReal_im, log_im, arg_ofReal_of_nonneg hx])
@[simp, norm_cast]
lemma natCast_log {n : β} : Real.log n = log n := ofReal_natCast n βΈ ofReal_log n.cast_nonneg
@[simp]
lemma ofNat_log {n : β} [n.AtLeastTwo] :
Real.log ofNat(n) = log (OfNat.ofNat n) :=
natCast_log
theorem log_ofReal_re (x : β) : (log (x : β)).re = Real.log x := by simp [log_re]
theorem log_ofReal_mul {r : β} (hr : 0 < r) {x : β} (hx : x β 0) :
log (r * x) = Real.log r + log x := by
replace hx := norm_ne_zero_iff.mpr hx
simp_rw [log, norm_mul, norm_real, arg_real_mul _ hr, Real.norm_of_nonneg hr.le,
Real.log_mul hr.ne' hx, ofReal_add, add_assoc]
theorem log_mul_ofReal (r : β) (hr : 0 < r) (x : β) (hx : x β 0) :
log (x * r) = Real.log r + log x := by rw [mul_comm, log_ofReal_mul hr hx]
lemma log_mul_eq_add_log_iff {x y : β} (hxβ : x β 0) (hyβ : y β 0) :
log (x * y) = log x + log y β arg x + arg y β Set.Ioc (-Ο) Ο := by
refine Complex.ext_iff.trans <| Iff.trans ?_ <| arg_mul_eq_add_arg_iff hxβ hyβ
simp_rw [add_re, add_im, log_re, log_im, norm_mul,
Real.log_mul (norm_ne_zero_iff.mpr hxβ) (norm_ne_zero_iff.mpr hyβ), true_and]
|
alias β¨_, log_mulβ© := log_mul_eq_add_log_iff
@[simp]
theorem log_zero : log 0 = 0 := by simp [log]
| Mathlib/Analysis/SpecialFunctions/Complex/Log.lean | 86 | 90 |
/-
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, Eric Wieser
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Analysis.Calculus.Deriv.Pow
import Mathlib.Analysis.Calculus.Deriv.Add
/-!
# Derivatives of polynomials
In this file we prove that derivatives of polynomials in the analysis sense agree with their
derivatives in the algebraic sense.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`analysis/calculus/deriv/basic`.
## TODO
* Add results about multivariable polynomials.
* Generalize some (most?) results to an algebra over the base field.
## Keywords
derivative, polynomial
-/
universe u
open scoped Polynomial
open ContinuousLinearMap (smulRight)
variable {π : Type u} [NontriviallyNormedField π] {x : π} {s : Set π}
namespace Polynomial
/-! ### Derivative of a polynomial -/
variable {R : Type*} [CommSemiring R] [Algebra R π]
variable (p : π[X]) (q : R[X])
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected theorem hasStrictDerivAt (x : π) :
HasStrictDerivAt (fun x => p.eval x) (p.derivative.eval x) x := by
induction p using Polynomial.induction_on' with
| add p q hp hq => simpa using hp.add hq
| monomial n a => simpa [mul_assoc, derivative_monomial]
using (hasStrictDerivAt_pow n x).const_mul a
protected theorem hasStrictDerivAt_aeval (x : π) :
HasStrictDerivAt (fun x => aeval x q) (aeval x (derivative q)) x := by
simpa only [aeval_def, evalβ_eq_eval_map, derivative_map] using
(q.map (algebraMap R π)).hasStrictDerivAt x
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected theorem hasDerivAt (x : π) : HasDerivAt (fun x => p.eval x) (p.derivative.eval x) x :=
(p.hasStrictDerivAt x).hasDerivAt
protected theorem hasDerivAt_aeval (x : π) :
HasDerivAt (fun x => aeval x q) (aeval x (derivative q)) x :=
(q.hasStrictDerivAt_aeval x).hasDerivAt
protected theorem hasDerivWithinAt (x : π) (s : Set π) :
HasDerivWithinAt (fun x => p.eval x) (p.derivative.eval x) s x :=
(p.hasDerivAt x).hasDerivWithinAt
protected theorem hasDerivWithinAt_aeval (x : π) (s : Set π) :
HasDerivWithinAt (fun x => aeval x q) (aeval x (derivative q)) s x :=
(q.hasDerivAt_aeval x).hasDerivWithinAt
protected theorem differentiableAt : DifferentiableAt π (fun x => p.eval x) x :=
(p.hasDerivAt x).differentiableAt
protected theorem differentiableAt_aeval : DifferentiableAt π (fun x => aeval x q) x :=
(q.hasDerivAt_aeval x).differentiableAt
protected theorem differentiableWithinAt : DifferentiableWithinAt π (fun x => p.eval x) s x :=
p.differentiableAt.differentiableWithinAt
protected theorem differentiableWithinAt_aeval :
DifferentiableWithinAt π (fun x => aeval x q) s x :=
q.differentiableAt_aeval.differentiableWithinAt
protected theorem differentiable : Differentiable π fun x => p.eval x := fun _ => p.differentiableAt
protected theorem differentiable_aeval : Differentiable π fun x : π => aeval x q := fun _ =>
q.differentiableAt_aeval
protected theorem differentiableOn : DifferentiableOn π (fun x => p.eval x) s :=
p.differentiable.differentiableOn
protected theorem differentiableOn_aeval : DifferentiableOn π (fun x => aeval x q) s :=
q.differentiable_aeval.differentiableOn
@[simp]
protected theorem deriv : deriv (fun x => p.eval x) x = p.derivative.eval x :=
(p.hasDerivAt x).deriv
@[simp]
protected theorem deriv_aeval : deriv (fun x => aeval x q) x = aeval x (derivative q) :=
(q.hasDerivAt_aeval x).deriv
protected theorem derivWithin (hxs : UniqueDiffWithinAt π s x) :
derivWithin (fun x => p.eval x) s x = p.derivative.eval x := by
rw [DifferentiableAt.derivWithin p.differentiableAt hxs]
exact p.deriv
protected theorem derivWithin_aeval (hxs : UniqueDiffWithinAt π s x) :
derivWithin (fun x => aeval x q) s x = aeval x (derivative q) := by
simpa only [aeval_def, evalβ_eq_eval_map, derivative_map] using
(q.map (algebraMap R π)).derivWithin hxs
protected theorem hasFDerivAt (x : π) :
HasFDerivAt (fun x => p.eval x) (smulRight (1 : π βL[π] π) (p.derivative.eval x)) x :=
p.hasDerivAt x
protected theorem hasFDerivAt_aeval (x : π) :
HasFDerivAt (fun x => aeval x q) (smulRight (1 : π βL[π] π) (aeval x (derivative q))) x :=
q.hasDerivAt_aeval x
protected theorem hasFDerivWithinAt (x : π) :
HasFDerivWithinAt (fun x => p.eval x) (smulRight (1 : π βL[π] π) (p.derivative.eval x)) s x :=
(p.hasFDerivAt x).hasFDerivWithinAt
protected theorem hasFDerivWithinAt_aeval (x : π) :
HasFDerivWithinAt (fun x => aeval x q) (smulRight (1 : π βL[π] π)
(aeval x (derivative q))) s x :=
(q.hasFDerivAt_aeval x).hasFDerivWithinAt
@[simp]
protected theorem fderiv :
fderiv π (fun x => p.eval x) x = smulRight (1 : π βL[π] π) (p.derivative.eval x) :=
(p.hasFDerivAt x).fderiv
| @[simp]
protected theorem fderiv_aeval :
fderiv π (fun x => aeval x q) x = smulRight (1 : π βL[π] π) (aeval x (derivative q)) :=
(q.hasFDerivAt_aeval x).fderiv
| Mathlib/Analysis/Calculus/Deriv/Polynomial.lean | 140 | 143 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes HΓΆlzl, Sander Dahmen, Kim Morrison
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.LinearAlgebra.LinearIndependent.Basic
import Mathlib.Data.Set.Card
/-!
# Dimension of modules and vector spaces
## Main definitions
* The rank of a module is defined as `Module.rank : Cardinal`.
This is defined as the supremum of the cardinalities of linearly independent subsets.
## Main statements
* `LinearMap.rank_le_of_injective`: the source of an injective linear map has dimension
at most that of the target.
* `LinearMap.rank_le_of_surjective`: the target of a surjective linear map has dimension
at most that of that source.
## Implementation notes
Many theorems in this file are not universe-generic when they relate dimensions
in different universes. They should be as general as they can be without
inserting `lift`s. The types `M`, `M'`, ... all live in different universes,
and `Mβ`, `Mβ`, ... all live in the same universe.
-/
noncomputable section
universe w w' u u' v v'
variable {R : Type u} {R' : Type u'} {M Mβ : Type v} {M' : Type v'}
open Cardinal Submodule Function Set
section Module
section
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable (R M)
/-- The rank of a module, defined as a term of type `Cardinal`.
We define this as the supremum of the cardinalities of linearly independent subsets.
The supremum may not be attained, see https://mathoverflow.net/a/263053.
For a free module over any ring satisfying the strong rank condition
(e.g. left-noetherian rings, commutative rings, and in particular division rings and fields),
this is the same as the dimension of the space (i.e. the cardinality of any basis).
In particular this agrees with the usual notion of the dimension of a vector space.
See also `Module.finrank` for a `β`-valued function which returns the correct value
for a finite-dimensional vector space (but 0 for an infinite-dimensional vector space).
-/
@[stacks 09G3 "first part"]
protected irreducible_def Module.rank : Cardinal :=
β¨ ΞΉ : { s : Set M // LinearIndepOn R id s }, (#ΞΉ.1)
theorem rank_le_card : Module.rank R M β€ #M :=
(Module.rank_def _ _).trans_le (ciSup_le' fun _ β¦ mk_set_le _)
lemma nonempty_linearIndependent_set : Nonempty {s : Set M // LinearIndepOn R id s } :=
β¨β¨β
, linearIndepOn_empty _ _β©β©
end
namespace LinearIndependent
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable [Nontrivial R]
theorem cardinal_lift_le_rank {ΞΉ : Type w} {v : ΞΉ β M}
(hv : LinearIndependent R v) :
Cardinal.lift.{v} #ΞΉ β€ Cardinal.lift.{w} (Module.rank R M) := by
rw [Module.rank]
refine le_trans ?_ (lift_le.mpr <| le_ciSup (bddAbove_range _) β¨_, hv.linearIndepOn_idβ©)
exact lift_mk_le'.mpr β¨(Equiv.ofInjective _ hv.injective).toEmbeddingβ©
lemma aleph0_le_rank {ΞΉ : Type w} [Infinite ΞΉ] {v : ΞΉ β M}
(hv : LinearIndependent R v) : β΅β β€ Module.rank R M :=
aleph0_le_lift.mp <| (aleph0_le_lift.mpr <| aleph0_le_mk ΞΉ).trans hv.cardinal_lift_le_rank
theorem cardinal_le_rank {ΞΉ : Type v} {v : ΞΉ β M}
(hv : LinearIndependent R v) : #ΞΉ β€ Module.rank R M := by
simpa using hv.cardinal_lift_le_rank
theorem cardinal_le_rank' {s : Set M}
(hs : LinearIndependent R (fun x => x : s β M)) : #s β€ Module.rank R M :=
hs.cardinal_le_rank
theorem _root_.LinearIndepOn.encard_le_toENat_rank {ΞΉ : Type*} {v : ΞΉ β M} {s : Set ΞΉ}
(hs : LinearIndepOn R v s) : s.encard β€ (Module.rank R M).toENat := by
simpa using OrderHom.mono (Ξ² := ββ) Cardinal.toENat hs.linearIndependent.cardinal_lift_le_rank
end LinearIndependent
section SurjectiveInjective
section Semiring
variable [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R']
section
variable [AddCommMonoid M'] [Module R' M']
/-- If `M / R` and `M' / R'` are modules, `i : R' β R` is an injective map
non-zero elements, `j : M β+ M'` is an injective monoid homomorphism, such that the scalar
multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to
the rank of `M' / R'`. As a special case, taking `R = R'` it is
`LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_injective_injectiveβ (i : R' β R) (j : M β+ M')
(hi : Injective i) (hj : Injective j)
(hc : β (r : R') (m : M), j (i r β’ m) = r β’ j m) :
lift.{v'} (Module.rank R M) β€ lift.{v} (Module.rank R' M') := by
simp_rw [Module.rank, lift_iSup (bddAbove_range _)]
exact ciSup_mono' (bddAbove_range _) fun β¨s, hβ© β¦ β¨β¨j '' s,
LinearIndepOn.id_image (h.linearIndependent.map_of_injective_injectiveβ i j hi hj hc)β©,
lift_mk_le'.mpr β¨(Equiv.Set.image j s hj).toEmbeddingβ©β©
/-- If `M / R` and `M' / R'` are modules, `i : R β R'` is a surjective map, and
`j : M β+ M'` is an injective monoid homomorphism, such that the scalar multiplications on `M` and
`M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`.
As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_surjective_injective (i : R β R') (j : M β+ M')
(hi : Surjective i) (hj : Injective j) (hc : β (r : R) (m : M), j (r β’ m) = i r β’ j m) :
lift.{v'} (Module.rank R M) β€ lift.{v} (Module.rank R' M') := by
obtain β¨i', hi'β© := hi.hasRightInverse
refine lift_rank_le_of_injective_injectiveβ i' j (fun _ _ h β¦ ?_) hj fun r m β¦ ?_
Β· apply_fun i at h
rwa [hi', hi'] at h
rw [hc (i' r) m, hi']
/-- If `M / R` and `M' / R'` are modules, `i : R β R'` is a bijective map which maps zero to zero,
`j : M β+ M'` is a group isomorphism, such that the scalar multiplications on `M` and `M'` are
compatible, then the rank of `M / R` is equal to the rank of `M' / R'`.
As a special case, taking `R = R'` it is `LinearEquiv.lift_rank_eq`. -/
theorem lift_rank_eq_of_equiv_equiv (i : R β R') (j : M β+ M')
(hi : Bijective i) (hc : β (r : R) (m : M), j (r β’ m) = i r β’ j m) :
lift.{v'} (Module.rank R M) = lift.{v} (Module.rank R' M') :=
(lift_rank_le_of_surjective_injective i j hi.2 j.injective hc).antisymm <|
lift_rank_le_of_injective_injectiveβ i j.symm hi.1
j.symm.injective fun _ _ β¦ j.symm_apply_eq.2 <| by erw [hc, j.apply_symm_apply]
end
section
variable [AddCommMonoid Mβ] [Module R' Mβ]
/-- The same-universe version of `lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injectiveβ (i : R' β R) (j : M β+ Mβ)
(hi : Injective i) (hj : Injective j)
(hc : β (r : R') (m : M), j (i r β’ m) = r β’ j m) :
Module.rank R M β€ Module.rank R' Mβ := by
simpa only [lift_id] using lift_rank_le_of_injective_injectiveβ i j hi hj hc
/-- The same-universe version of `lift_rank_le_of_surjective_injective`. -/
theorem rank_le_of_surjective_injective (i : R β R') (j : M β+ Mβ)
(hi : Surjective i) (hj : Injective j)
(hc : β (r : R) (m : M), j (r β’ m) = i r β’ j m) :
Module.rank R M β€ Module.rank R' Mβ := by
simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc
/-- The same-universe version of `lift_rank_eq_of_equiv_equiv`. -/
theorem rank_eq_of_equiv_equiv (i : R β R') (j : M β+ Mβ)
(hi : Bijective i) (hc : β (r : R) (m : M), j (r β’ m) = i r β’ j m) :
Module.rank R M = Module.rank R' Mβ := by
simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hi hc
end
end Semiring
section Ring
variable [Ring R] [AddCommGroup M] [Module R M] [Ring R']
/-- If `M / R` and `M' / R'` are modules, `i : R' β R` is a map which sends non-zero elements to
non-zero elements, `j : M β+ M'` is an injective group homomorphism, such that the scalar
multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to
the rank of `M' / R'`. As a special case, taking `R = R'` it is
`LinearMap.lift_rank_le_of_injective`. -/
theorem lift_rank_le_of_injective_injective [AddCommGroup M'] [Module R' M']
(i : R' β R) (j : M β+ M') (hi : β r, i r = 0 β r = 0) (hj : Injective j)
(hc : β (r : R') (m : M), j (i r β’ m) = r β’ j m) :
lift.{v'} (Module.rank R M) β€ lift.{v} (Module.rank R' M') := by
simp_rw [Module.rank, lift_iSup (bddAbove_range _)]
exact ciSup_mono' (bddAbove_range _) fun β¨s, hβ© β¦
β¨β¨j '' s, LinearIndepOn.id_image <| h.linearIndependent.map_of_injective_injective i j hi
(fun _ _ β¦ hj <| by rwa [j.map_zero]) hcβ©,
lift_mk_le'.mpr β¨(Equiv.Set.image j s hj).toEmbeddingβ©β©
/-- The same-universe version of `lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injective [AddCommGroup Mβ] [Module R' Mβ]
(i : R' β R) (j : M β+ Mβ) (hi : β r, i r = 0 β r = 0) (hj : Injective j)
(hc : β (r : R') (m : M), j (i r β’ m) = r β’ j m) :
Module.rank R M β€ Module.rank R' Mβ := by
simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc
end Ring
namespace Algebra
variable {R : Type w} {S : Type v} [CommSemiring R] [Semiring S] [Algebra R S]
{R' : Type w'} {S' : Type v'} [CommSemiring R'] [Semiring S'] [Algebra R' S']
/-- If `S / R` and `S' / R'` are algebras, `i : R' β+* R` and `j : S β+* S'` are injective ring
homomorphisms, such that `R' β R β S β S'` and `R' β S'` commute, then the rank of `S / R` is
smaller than or equal to the rank of `S' / R'`. -/
theorem lift_rank_le_of_injective_injective
(i : R' β+* R) (j : S β+* S') (hi : Injective i) (hj : Injective j)
(hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') :
lift.{v'} (Module.rank R S) β€ lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_le_of_injective_injectiveβ i j hi hj fun r _ β¦ ?_
have := congr($hc r)
simp only [RingHom.coe_comp, comp_apply] at this
simp_rw [smul_def, AddMonoidHom.coe_coe, map_mul, this]
/-- If `S / R` and `S' / R'` are algebras, `i : R β+* R'` is a surjective ring homomorphism,
`j : S β+* S'` is an injective ring homomorphism, such that `R β R' β S'` and `R β S β S'` commute,
then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/
theorem lift_rank_le_of_surjective_injective
(i : R β+* R') (j : S β+* S') (hi : Surjective i) (hj : Injective j)
(hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) :
lift.{v'} (Module.rank R S) β€ lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_le_of_surjective_injective i j hi hj fun r _ β¦ ?_
have := congr($hc r)
simp only [RingHom.coe_comp, comp_apply] at this
simp only [smul_def, AddMonoidHom.coe_coe, map_mul, ZeroHom.coe_coe, this]
/-- If `S / R` and `S' / R'` are algebras, `i : R β+* R'` and `j : S β+* S'` are
ring isomorphisms, such that `R β R' β S'` and `R β S β S'` commute,
then the rank of `S / R` is equal to the rank of `S' / R'`. -/
theorem lift_rank_eq_of_equiv_equiv (i : R β+* R') (j : S β+* S')
(hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) :
lift.{v'} (Module.rank R S) = lift.{v} (Module.rank R' S') := by
refine _root_.lift_rank_eq_of_equiv_equiv i j i.bijective fun r _ β¦ ?_
have := congr($hc r)
simp only [RingEquiv.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, comp_apply] at this
simp only [smul_def, RingEquiv.coe_toAddEquiv, map_mul, ZeroHom.coe_coe, this]
variable {S' : Type v} [Semiring S'] [Algebra R' S']
/-- The same-universe version of `Algebra.lift_rank_le_of_injective_injective`. -/
theorem rank_le_of_injective_injective
(i : R' β+* R) (j : S β+* S') (hi : Injective i) (hj : Injective j)
(hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') :
Module.rank R S β€ Module.rank R' S' := by
simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc
/-- The same-universe version of `Algebra.lift_rank_le_of_surjective_injective`. -/
theorem rank_le_of_surjective_injective
(i : R β+* R') (j : S β+* S') (hi : Surjective i) (hj : Injective j)
(hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) :
Module.rank R S β€ Module.rank R' S' := by
simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc
/-- The same-universe version of `Algebra.lift_rank_eq_of_equiv_equiv`. -/
theorem rank_eq_of_equiv_equiv (i : R β+* R') (j : S β+* S')
(hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) :
Module.rank R S = Module.rank R' S' := by
simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hc
end Algebra
end SurjectiveInjective
variable [Semiring R] [AddCommMonoid M] [Module R M]
[Semiring R'] [AddCommMonoid M'] [AddCommMonoid Mβ]
[Module R M'] [Module R Mβ] [Module R' M'] [Module R' Mβ]
section
theorem LinearMap.lift_rank_le_of_injective (f : M ββ[R] M') (i : Injective f) :
| Cardinal.lift.{v'} (Module.rank R M) β€ Cardinal.lift.{v} (Module.rank R M') :=
lift_rank_le_of_injective_injectiveβ (RingHom.id R) f (fun _ _ h β¦ h) i f.map_smul
theorem LinearMap.rank_le_of_injective (f : M ββ[R] Mβ) (i : Injective f) :
| Mathlib/LinearAlgebra/Dimension/Basic.lean | 278 | 281 |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta HernΓ‘ndez Palacios
-/
import Mathlib.SetTheory.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Cofinality
This file contains the definition of cofinality of an order and an ordinal number.
## Main Definitions
* `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset
`s` that is *cofinal*, i.e. `β x, β y β s, r x y`.
* `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order.
## Main Statements
* `Cardinal.lt_power_cof`: A consequence of KΓΆnig's theorem stating that `c < c ^ c.ord.cof` for
`c β₯ β΅β`.
## Implementation Notes
* The cofinality is defined for ordinals.
If `c` is a cardinal number, its cofinality is `c.ord.cof`.
-/
noncomputable section
open Function Cardinal Set Order
open scoped Ordinal
universe u v w
variable {Ξ± : Type u} {Ξ² : Type v} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
/-! ### Cofinality of orders -/
attribute [local instance] IsRefl.swap
namespace Order
/-- Cofinality of a reflexive order `βΌ`. This is the smallest cardinality
of a subset `S : Set Ξ±` such that `β a, β b β S, a βΌ b`. -/
def cof (r : Ξ± β Ξ± β Prop) : Cardinal :=
sInf { c | β S : Set Ξ±, (β a, β b β S, r a b) β§ #S = c }
/-- The set in the definition of `Order.cof` is nonempty. -/
private theorem cof_nonempty (r : Ξ± β Ξ± β Prop) [IsRefl Ξ± r] :
{ c | β S : Set Ξ±, (β a, β b β S, r a b) β§ #S = c }.Nonempty :=
β¨_, Set.univ, fun a => β¨a, β¨β©, refl _β©, rflβ©
theorem cof_le (r : Ξ± β Ξ± β Prop) {S : Set Ξ±} (h : β a, β b β S, r a b) : cof r β€ #S :=
csInf_le' β¨S, h, rflβ©
theorem le_cof [IsRefl Ξ± r] (c : Cardinal) :
c β€ cof r β β {S : Set Ξ±}, (β a, β b β S, r a b) β c β€ #S := by
rw [cof, le_csInf_iff'' (cof_nonempty r)]
use fun H S h => H _ β¨S, h, rflβ©
rintro H d β¨S, h, rflβ©
exact H h
end Order
namespace RelIso
private theorem cof_le_lift [IsRefl Ξ² s] (f : r βr s) :
Cardinal.lift.{v} (Order.cof r) β€ Cardinal.lift.{u} (Order.cof s) := by
rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)]
rintro - β¨-, β¨u, H, rflβ©, rflβ©
apply csInf_le'
refine β¨_, β¨f.symm '' u, fun a => ?_, rflβ©, lift_mk_eq'.2 β¨(f.symm.toEquiv.image u).symmβ©β©
rcases H (f a) with β¨b, hb, hb'β©
refine β¨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_β©
rwa [RelIso.apply_symm_apply]
theorem cof_eq_lift [IsRefl Ξ² s] (f : r βr s) :
Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) :=
have := f.toRelEmbedding.isRefl
(f.cof_le_lift).antisymm (f.symm.cof_le_lift)
theorem cof_eq {Ξ± Ξ² : Type u} {r : Ξ± β Ξ± β Prop} {s} [IsRefl Ξ² s] (f : r βr s) :
Order.cof r = Order.cof s :=
lift_inj.1 (f.cof_eq_lift)
end RelIso
/-! ### Cofinality of ordinals -/
namespace Ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is
unbounded, in the sense `β a, β b β S, a β€ b`.
In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/
def cof (o : Ordinal.{u}) : Cardinal.{u} :=
o.liftOn (fun a β¦ Order.cof (swap a.rαΆ)) fun _ _ β¨fβ© β¦ f.compl.swap.cof_eq
theorem cof_type (r : Ξ± β Ξ± β Prop) [IsWellOrder Ξ± r] : (type r).cof = Order.cof (swap rαΆ) :=
rfl
theorem cof_type_lt [LinearOrder Ξ±] [IsWellOrder Ξ± (Β· < Β·)] :
(@type Ξ± (Β· < Β·) _).cof = @Order.cof Ξ± (Β· β€ Β·) := by
rw [cof_type, compl_lt, swap_ge]
theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (Β· β€ Β·) := by
conv_lhs => rw [β type_toType o, cof_type_lt]
theorem le_cof_type [IsWellOrder Ξ± r] {c} : c β€ cof (type r) β β S, Unbounded r S β c β€ #S :=
(le_csInf_iff'' (Order.cof_nonempty _)).trans
β¨fun H S h => H _ β¨S, h, rflβ©, by
rintro H d β¨S, h, rflβ©
exact H _ hβ©
theorem cof_type_le [IsWellOrder Ξ± r] {S : Set Ξ±} (h : Unbounded r S) : cof (type r) β€ #S :=
le_cof_type.1 le_rfl S h
theorem lt_cof_type [IsWellOrder Ξ± r] {S : Set Ξ±} : #S < cof (type r) β Bounded r S := by
simpa using not_imp_not.2 cof_type_le
theorem cof_eq (r : Ξ± β Ξ± β Prop) [IsWellOrder Ξ± r] : β S, Unbounded r S β§ #S = cof (type r) :=
csInf_mem (Order.cof_nonempty (swap rαΆ))
theorem ord_cof_eq (r : Ξ± β Ξ± β Prop) [IsWellOrder Ξ± r] :
β S, Unbounded r S β§ type (Subrel r (Β· β S)) = (cof (type r)).ord := by
let β¨S, hS, eβ© := cof_eq r
let β¨s, _, e'β© := Cardinal.ord_eq S
let T : Set Ξ± := { a | β aS : a β S, β b : S, s b β¨_, aSβ© β r b a }
suffices Unbounded r T by
refine β¨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)β©
rw [β e, e']
refine
(RelEmbedding.ofMonotone
(fun a : T =>
(β¨a,
let β¨aS, _β© := a.2
aSβ© :
S))
fun a b h => ?_).ordinal_type_le
rcases a with β¨a, aS, haβ©
rcases b with β¨b, bS, hbβ©
change s β¨a, _β© β¨b, _β©
refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_
Β· exact asymm h (ha _ hn)
Β· intro e
injection e with e
subst b
exact irrefl _ h
intro a
have : { b : S | Β¬r b a }.Nonempty :=
let β¨b, bS, baβ© := hS a
β¨β¨b, bSβ©, baβ©
let b := (IsWellFounded.wf : WellFounded s).min _ this
have ba : Β¬r b a := IsWellFounded.wf.min_mem _ this
refine β¨b, β¨b.2, fun c => not_imp_not.1 fun h => ?_β©, baβ©
rw [show β b : S, (β¨b, b.2β© : S) = b by intro b; cases b; rfl]
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
/-! ### Cofinality of suprema and least strict upper bounds -/
private theorem card_mem_cof {o} : β (ΞΉ : _) (f : ΞΉ β Ordinal), lsub.{u, u} f = o β§ #ΞΉ = o.card :=
β¨_, _, lsub_typein o, mk_toType oβ©
/-- The set in the `lsub` characterization of `cof` is nonempty. -/
theorem cof_lsub_def_nonempty (o) :
{ a : Cardinal | β (ΞΉ : _) (f : ΞΉ β Ordinal), lsub.{u, u} f = o β§ #ΞΉ = a }.Nonempty :=
β¨_, card_mem_cofβ©
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
sInf { a : Cardinal | β (ΞΉ : Type u) (f : ΞΉ β Ordinal), lsub.{u, u} f = o β§ #ΞΉ = a } := by
refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_)
Β· rintro a β¨ΞΉ, f, hf, rflβ©
rw [β type_toType o]
refine
(cof_type_le fun a => ?_).trans
(@mk_le_of_injective _ _
(fun s : typein ((Β· < Β·) : o.toType β o.toType β Prop) β»ΒΉ' Set.range f =>
Classical.choose s.prop)
fun s t hst => by
let H := congr_arg f hst
rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
Subtype.coe_inj] at H)
have := typein_lt_self a
simp_rw [β hf, lt_lsub_iff] at this
obtain β¨i, hiβ© := this
refine β¨enum (Ξ± := o.toType) (Β· < Β·) β¨f i, ?_β©, ?_, ?_β©
Β· rw [type_toType, β hf]
apply lt_lsub
Β· rw [mem_preimage, typein_enum]
exact mem_range_self i
Β· rwa [β typein_le_typein, typein_enum]
Β· rcases cof_eq (Ξ± := o.toType) (Β· < Β·) with β¨S, hS, hS'β©
let f : S β Ordinal := fun s => typein LT.lt s.val
refine β¨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i)
(le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'β©
rw [β type_toType o] at ha
rcases hS (enum (Β· < Β·) β¨a, haβ©) with β¨b, hb, hb'β©
rw [β typein_le_typein, typein_enum] at hb'
exact hb'.trans_lt (lt_lsub.{u, u} f β¨b, hbβ©)
@[simp]
theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by
refine inductionOn o fun Ξ± r _ β¦ ?_
rw [β type_uLift, cof_type, cof_type, β Cardinal.lift_id'.{v, u} (Order.cof _),
β Cardinal.lift_umax]
apply RelIso.cof_eq_lift β¨Equiv.ulift.symm, _β©
simp [swap]
theorem cof_le_card (o) : cof o β€ card o := by
rw [cof_eq_sInf_lsub]
exact csInf_le' card_mem_cof
theorem cof_ord_le (c : Cardinal) : c.ord.cof β€ c := by simpa using cof_le_card c.ord
theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord β€ o :=
(ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o)
theorem exists_lsub_cof (o : Ordinal) :
β (ΞΉ : _) (f : ΞΉ β Ordinal), lsub.{u, u} f = o β§ #ΞΉ = cof o := by
rw [cof_eq_sInf_lsub]
exact csInf_mem (cof_lsub_def_nonempty o)
theorem cof_lsub_le {ΞΉ} (f : ΞΉ β Ordinal) : cof (lsub.{u, u} f) β€ #ΞΉ := by
rw [cof_eq_sInf_lsub]
exact csInf_le' β¨ΞΉ, f, rfl, rflβ©
theorem cof_lsub_le_lift {ΞΉ} (f : ΞΉ β Ordinal) :
cof (lsub.{u, v} f) β€ Cardinal.lift.{v, u} #ΞΉ := by
rw [β mk_uLift.{u, v}]
convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ΞΉ => f i.down
exact
lsub_eq_of_range_eq.{u, max u v, max u v}
(Set.ext fun x => β¨fun β¨i, hiβ© => β¨ULift.up.{v, u} i, hiβ©, fun β¨i, hiβ© => β¨_, hiβ©β©)
theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} :
a β€ cof o β β {ΞΉ} (f : ΞΉ β Ordinal), lsub.{u, u} f = o β a β€ #ΞΉ := by
rw [cof_eq_sInf_lsub]
exact
(le_csInf_iff'' (cof_lsub_def_nonempty o)).trans
β¨fun H ΞΉ f hf => H _ β¨ΞΉ, f, hf, rflβ©, fun H b β¨ΞΉ, f, hf, hbβ© => by
rw [β hb]
exact H _ hfβ©
theorem lsub_lt_ord_lift {ΞΉ} {f : ΞΉ β Ordinal} {c : Ordinal}
(hΞΉ : Cardinal.lift.{v, u} #ΞΉ < c.cof)
(hf : β i, f i < c) : lsub.{u, v} f < c :=
lt_of_le_of_ne (lsub_le hf) fun h => by
subst h
exact (cof_lsub_le_lift.{u, v} f).not_lt hΞΉ
theorem lsub_lt_ord {ΞΉ} {f : ΞΉ β Ordinal} {c : Ordinal} (hΞΉ : #ΞΉ < c.cof) :
(β i, f i < c) β lsub.{u, u} f < c :=
lsub_lt_ord_lift (by rwa [(#ΞΉ).lift_id])
theorem cof_iSup_le_lift {ΞΉ} {f : ΞΉ β Ordinal} (H : β i, f i < iSup f) :
cof (iSup f) β€ Cardinal.lift.{v, u} #ΞΉ := by
rw [β Ordinal.sup] at *
rw [β sup_eq_lsub_iff_lt_sup.{u, v}] at H
rw [H]
exact cof_lsub_le_lift f
theorem cof_iSup_le {ΞΉ} {f : ΞΉ β Ordinal} (H : β i, f i < iSup f) :
cof (iSup f) β€ #ΞΉ := by
rw [β (#ΞΉ).lift_id]
exact cof_iSup_le_lift H
theorem iSup_lt_ord_lift {ΞΉ} {f : ΞΉ β Ordinal} {c : Ordinal} (hΞΉ : Cardinal.lift.{v, u} #ΞΉ < c.cof)
(hf : β i, f i < c) : iSup f < c :=
(sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hΞΉ hf)
theorem iSup_lt_ord {ΞΉ} {f : ΞΉ β Ordinal} {c : Ordinal} (hΞΉ : #ΞΉ < c.cof) :
(β i, f i < c) β iSup f < c :=
iSup_lt_ord_lift (by rwa [(#ΞΉ).lift_id])
theorem iSup_lt_lift {ΞΉ} {f : ΞΉ β Cardinal} {c : Cardinal}
(hΞΉ : Cardinal.lift.{v, u} #ΞΉ < c.ord.cof)
(hf : β i, f i < c) : iSup f < c := by
rw [β ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)]
refine iSup_lt_ord_lift hΞΉ fun i => ?_
rw [ord_lt_ord]
apply hf
theorem iSup_lt {ΞΉ} {f : ΞΉ β Cardinal} {c : Cardinal} (hΞΉ : #ΞΉ < c.ord.cof) :
(β i, f i < c) β iSup f < c :=
iSup_lt_lift (by rwa [(#ΞΉ).lift_id])
theorem nfpFamily_lt_ord_lift {ΞΉ} {f : ΞΉ β Ordinal β Ordinal} {c} (hc : β΅β < cof c)
(hc' : Cardinal.lift.{v, u} #ΞΉ < cof c) (hf : β (i), β b < c, f i b < c) {a} (ha : a < c) :
nfpFamily f a < c := by
refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ΞΉ)).trans_lt ?_) fun l => ?_
Β· rw [lift_max]
apply max_lt _ hc'
rwa [Cardinal.lift_aleph0]
Β· induction' l with i l H
Β· exact ha
Β· exact hf _ _ H
theorem nfpFamily_lt_ord {ΞΉ} {f : ΞΉ β Ordinal β Ordinal} {c} (hc : β΅β < cof c) (hc' : #ΞΉ < cof c)
(hf : β (i), β b < c, f i b < c) {a} : a < c β nfpFamily.{u, u} f a < c :=
nfpFamily_lt_ord_lift hc (by rwa [(#ΞΉ).lift_id]) hf
theorem nfp_lt_ord {f : Ordinal β Ordinal} {c} (hc : β΅β < cof c) (hf : β i < c, f i < c) {a} :
a < c β nfp f a < c :=
nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf
theorem exists_blsub_cof (o : Ordinal) :
β f : β a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by
rcases exists_lsub_cof o with β¨ΞΉ, f, hf, hΞΉβ©
rcases Cardinal.ord_eq ΞΉ with β¨r, hr, hΞΉ'β©
rw [β @blsub_eq_lsub' ΞΉ r hr] at hf
rw [β hΞΉ, hΞΉ']
exact β¨_, hfβ©
theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} :
a β€ cof b β β {o} (f : β a < o, Ordinal), blsub.{u, u} o f = b β a β€ o.card :=
le_cof_iff_lsub.trans
β¨fun H o f hf => by simpa using H _ hf, fun H ΞΉ f hf => by
rcases Cardinal.ord_eq ΞΉ with β¨r, hr, hΞΉ'β©
rw [β @blsub_eq_lsub' ΞΉ r hr] at hf
simpa using H _ hfβ©
theorem cof_blsub_le_lift {o} (f : β a < o, Ordinal) :
cof (blsub.{u, v} o f) β€ Cardinal.lift.{v, u} o.card := by
rw [β mk_toType o]
exact cof_lsub_le_lift _
theorem cof_blsub_le {o} (f : β a < o, Ordinal) : cof (blsub.{u, u} o f) β€ o.card := by
rw [β o.card.lift_id]
exact cof_blsub_le_lift f
theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : β a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : β i hi, f i hi < c) : blsub.{u, v} o f < c :=
lt_of_le_of_ne (blsub_le hf) fun h =>
ho.not_le (by simpa [β iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f)
theorem blsub_lt_ord {o : Ordinal} {f : β a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof)
(hf : β i hi, f i hi < c) : blsub.{u, u} o f < c :=
blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf
theorem cof_bsup_le_lift {o : Ordinal} {f : β a < o, Ordinal} (H : β i h, f i h < bsup.{u, v} o f) :
cof (bsup.{u, v} o f) β€ Cardinal.lift.{v, u} o.card := by
rw [β bsup_eq_blsub_iff_lt_bsup.{u, v}] at H
rw [H]
exact cof_blsub_le_lift.{u, v} f
theorem cof_bsup_le {o : Ordinal} {f : β a < o, Ordinal} :
(β i h, f i h < bsup.{u, u} o f) β cof (bsup.{u, u} o f) β€ o.card := by
rw [β o.card.lift_id]
exact cof_bsup_le_lift
theorem bsup_lt_ord_lift {o : Ordinal} {f : β a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : β i hi, f i hi < c) : bsup.{u, v} o f < c :=
(bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf)
theorem bsup_lt_ord {o : Ordinal} {f : β a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) :
(β i hi, f i hi < c) β bsup.{u, u} o f < c :=
bsup_lt_ord_lift (by rwa [o.card.lift_id])
/-! ### Basic results -/
@[simp]
theorem cof_zero : cof 0 = 0 := by
refine LE.le.antisymm ?_ (Cardinal.zero_le _)
rw [β card_zero]
exact cof_le_card 0
@[simp]
theorem cof_eq_zero {o} : cof o = 0 β o = 0 :=
β¨inductionOn o fun _ r _ z =>
let β¨_, hl, eβ© := cof_eq r
type_eq_zero_iff_isEmpty.2 <|
β¨fun a =>
let β¨_, h, _β© := hl a
(mk_eq_zero_iff.1 (e.trans z)).elim' β¨_, hβ©β©,
fun e => by simp [e]β©
theorem cof_ne_zero {o} : cof o β 0 β o β 0 :=
cof_eq_zero.not
@[simp]
theorem cof_succ (o) : cof (succ o) = 1 := by
apply le_antisymm
Β· refine inductionOn o fun Ξ± r _ => ?_
change cof (type _) β€ _
rw [β (_ : #_ = 1)]
Β· apply cof_type_le
refine fun a => β¨Sum.inr PUnit.unit, Set.mem_singleton _, ?_β©
rcases a with (a | β¨β¨β¨β©β©β©) <;> simp [EmptyRelation]
Β· rw [Cardinal.mk_fintype, Set.card_singleton]
simp
Β· rw [β Cardinal.succ_zero, succ_le_iff]
simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h =>
succ_ne_zero o (cof_eq_zero.1 (Eq.symm h))
@[simp]
theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 β β a, o = succ a :=
β¨inductionOn o fun Ξ± r _ z => by
rcases cof_eq r with β¨S, hl, eβ©; rw [z] at e
obtain β¨aβ© := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero)
refine
β¨typein r a,
Eq.symm <|
Quotient.sound
β¨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_β©β©
Β· apply Sum.rec <;> [exact Subtype.val; exact fun _ => a]
Β· rcases x with (x | β¨β¨β¨β©β©β©) <;> rcases y with (y | β¨β¨β¨β©β©β©) <;>
simp [Subrel, Order.Preimage, EmptyRelation]
exact x.2
Β· suffices r x a β¨ β _ : PUnit.{u}, βa = x by
convert this
dsimp [RelEmbedding.ofMonotone]; simp
rcases trichotomous_of r x a with (h | h | h)
Β· exact Or.inl h
Β· exact Or.inr β¨PUnit.unit, h.symmβ©
Β· rcases hl x with β¨a', aS, hnβ©
refine absurd h ?_
convert hn
change (a : Ξ±) = β(β¨a', aSβ© : S)
have := le_one_iff_subsingleton.1 (le_of_eq e)
congr!,
fun β¨a, eβ© => by simp [e]β©
/-! ### Fundamental sequences -/
-- TODO: move stuff about fundamental sequences to their own file.
/-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at
`a`. We provide `o` explicitly in order to avoid type rewrites. -/
def IsFundamentalSequence (a o : Ordinal.{u}) (f : β b < o, Ordinal.{u}) : Prop :=
o β€ a.cof.ord β§ (β {i j} (hi hj), i < j β f i hi < f j hj) β§ blsub.{u, u} o f = a
namespace IsFundamentalSequence
variable {a o : Ordinal.{u}} {f : β b < o, Ordinal.{u}}
protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o :=
hf.1.antisymm' <| by
rw [β hf.2.2]
exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o)
protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} :
β hi hj, i < j β f i hi < f j hj :=
hf.2.1
theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a :=
hf.2.2
theorem ord_cof (hf : IsFundamentalSequence a o f) :
IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by
have H := hf.cof_eq
subst H
exact hf
theorem id_of_le_cof (h : o β€ o.cof.ord) : IsFundamentalSequence o o fun a _ => a :=
β¨h, @fun _ _ _ _ => id, blsub_id oβ©
protected theorem zero {f : β b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f :=
β¨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero fβ©
protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by
refine β¨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero oβ©
Β· rw [cof_succ, ord_one]
Β· rw [lt_one_iff_zero] at hi hj
rw [hi, hj] at h
exact h.false.elim
protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o)
(hj : j < o) (hij : i β€ j) : f i hi β€ f j hj := by
rcases lt_or_eq_of_le hij with (hij | rfl)
Β· exact (hf.2.1 hi hj hij).le
Β· rfl
theorem trans {a o o' : Ordinal.{u}} {f : β b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f)
{g : β b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) :
IsFundamentalSequence a o' fun i hi =>
f (g i hi) (by rw [β hg.2.2]; apply lt_blsub) := by
refine β¨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_β©
Β· rw [hf.cof_eq]
exact hg.1.trans (ord_cof_le o)
Β· rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)]
Β· exact hf.2.2
Β· exact hg.2.2
protected theorem lt {a o : Ordinal} {s : Ξ p < o, Ordinal}
(h : IsFundamentalSequence a o s) {p : Ordinal} (hp : p < o) : s p hp < a :=
h.blsub_eq βΈ lt_blsub s p hp
end IsFundamentalSequence
/-- Every ordinal has a fundamental sequence. -/
theorem exists_fundamental_sequence (a : Ordinal.{u}) :
β f, IsFundamentalSequence a a.cof.ord f := by
suffices h : β o f, IsFundamentalSequence a o f by
rcases h with β¨o, f, hfβ©
exact β¨_, hf.ord_cofβ©
rcases exists_lsub_cof a with β¨ΞΉ, f, hf, hΞΉβ©
rcases ord_eq ΞΉ with β¨r, wo, hrβ©
haveI := wo
let r' := Subrel r fun i β¦ β j, r j i β f j < f i
let hrr' : r' βͺr r := Subrel.relEmbedding _ _
haveI := hrr'.isWellOrder
refine
β¨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' β¨j, hβ©).prop _ ?_,
le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_β©
Β· rw [β hΞΉ, hr]
Β· change r (hrr'.1 _) (hrr'.1 _)
rwa [hrr'.2, @enum_lt_enum _ r']
Β· rw [β hf, lsub_le_iff]
intro i
suffices h : β i' hi', f i β€ bfamilyOfFamily' r' (fun i => f i) i' hi' by
rcases h with β¨i', hi', hfgβ©
exact hfg.trans_lt (lt_blsub _ _ _)
by_cases h : β j, r j i β f j < f i
Β· refine β¨typein r' β¨i, hβ©, typein_lt_type _ _, ?_β©
rw [bfamilyOfFamily'_typein]
Β· push_neg at h
obtain β¨hji, hijβ© := wo.wf.min_mem _ h
refine β¨typein r' β¨_, fun k hkj => lt_of_lt_of_le ?_ hijβ©, typein_lt_type _ _, ?_β©
Β· by_contra! H
exact (wo.wf.not_lt_min _ h β¨IsTrans.trans _ _ _ hkj hji, Hβ©) hkj
Β· rwa [bfamilyOfFamily'_typein]
@[simp]
theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by
obtain β¨f, hfβ© := exists_fundamental_sequence a
obtain β¨g, hgβ© := exists_fundamental_sequence a.cof.ord
exact ord_injective (hf.trans hg).cof_eq.symm
protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} β Ordinal.{u}} (hf : IsNormal f)
{a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) :
IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by
refine β¨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_β©
Β· rcases exists_lsub_cof (f a) with β¨ΞΉ, f', hf', hΞΉβ©
rw [β hg.cof_eq, ord_le_ord, β hΞΉ]
suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i β€ f b }) = a by
rw [β this]
apply cof_lsub_le
have H : β i, β b < a, f' i β€ f b := fun i => by
have := lt_lsub.{u, u} f' i
rw [hf', β IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this
simpa using this
refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_)
Β· rcases H i with β¨b, hb, hb'β©
exact lt_of_le_of_lt (csInf_le' hb') hb
Β· have := hf.strictMono hb
rw [β hf', lt_lsub_iff] at this
obtain β¨i, hiβ© := this
rcases H i with β¨b, _, hbβ©
exact
((le_csInf_iff'' β¨b, by exact hbβ©).2 fun c hc =>
hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i)
Β· rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g
hg.2.2]
exact IsNormal.blsub_eq.{u, u} hf ha
theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a :=
let β¨_, hgβ© := exists_fundamental_sequence a
ord_injective (hf.isFundamentalSequence ha hg).cof_eq
theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a β€ cof (f a) := by
rcases zero_or_succ_or_limit a with (rfl | β¨b, rflβ© | ha)
Β· rw [cof_zero]
exact zero_le _
Β· rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, β Ordinal.pos_iff_ne_zero]
exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b)
Β· rw [hf.cof_eq ha]
@[simp]
theorem cof_add (a b : Ordinal) : b β 0 β cof (a + b) = cof b := fun h => by
rcases zero_or_succ_or_limit b with (rfl | β¨c, rflβ© | hb)
Β· contradiction
Β· rw [add_succ, cof_succ, cof_succ]
Β· exact (isNormal_add_right a).cof_eq hb
theorem aleph0_le_cof {o} : β΅β β€ cof o β IsLimit o := by
rcases zero_or_succ_or_limit o with (rfl | β¨o, rflβ© | l)
| Β· simp [not_zero_isLimit, Cardinal.aleph0_ne_zero]
Β· simp [not_succ_isLimit, Cardinal.one_lt_aleph0]
| Mathlib/SetTheory/Cardinal/Cofinality.lean | 580 | 581 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Tape
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.PFun
import Mathlib.Computability.PostTuringMachine
/-!
# Turing machines
The files `PostTuringMachine.lean` and `TuringMachine.lean` define
a sequence of simple machine languages, starting with Turing machines and working
up to more complex languages based on Wang B-machines.
`PostTuringMachine.lean` covers the TM0 model and TM1 model;
`TuringMachine.lean` adds the TM2 model.
## Naming conventions
Each model of computation in this file shares a naming convention for the elements of a model of
computation. These are the parameters for the language:
* `Ξ` is the alphabet on the tape.
* `Ξ` is the set of labels, or internal machine states.
* `Ο` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and
later models achieve this by mixing it into `Ξ`.
* `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks.
All of these variables denote "essentially finite" types, but for technical reasons it is
convenient to allow them to be infinite anyway. When using an infinite type, we will be interested
to prove that only finitely many values of the type are ever interacted with.
Given these parameters, there are a few common structures for the model that arise:
* `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is
finite, and for later models it is an infinite inductive type representing "possible program
texts".
* `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with
its environment.
* `Machine` is the set of all machines in the model. Usually this is approximately a function
`Ξ β Stmt`, although different models have different ways of halting and other actions.
* `step : Cfg β Option Cfg` is the function that describes how the state evolves over one step.
If `step c = none`, then `c` is a terminal state, and the result of the computation is read off
from `c`. Because of the type of `step`, these models are all deterministic by construction.
* `init : Input β Cfg` sets up the initial state. The type `Input` depends on the model;
in most cases it is `List Ξ`.
* `eval : Machine β Input β Part Output`, given a machine `M` and input `i`, starts from
`init i`, runs `step` until it reaches an output, and then applies a function `Cfg β Output` to
the final state to obtain the result. The type `Output` depends on the model.
* `Supports : Machine β Finset Ξ β Prop` asserts that a machine `M` starts in `S : Finset Ξ`, and
can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input
cannot depend on its values outside `S`. We use this to allow `Ξ` to be an infinite set when
convenient, and prove that only finitely many of these states are actually accessible. This
formalizes "essentially finite" mentioned above.
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Relation
open Nat (iterate)
open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply'
iterate_zero_apply)
namespace Turing
/-!
## The TM2 model
The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite)
collection of stacks, each with elements of different types (the alphabet of stack `k : K` is
`Ξ k`). The statements are:
* `push k (f : Ο β Ξ k) q` puts `f a` on the `k`-th stack, then does `q`.
* `pop k (f : Ο β Option (Ξ k) β Ο) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, and removes this element from the stack, then does `q`.
* `peek k (f : Ο β Option (Ξ k) β Ο) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, then does `q`.
* `load (f : Ο β Ο) q` reads nothing but applies `f` to the internal state, then does `q`.
* `branch (f : Ο β Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`.
* `goto (f : Ο β Ξ)` jumps to label `f a`.
* `halt` halts on the next step.
The configuration is a tuple `(l, var, stk)` where `l : Option Ξ` is the current label to run or
`none` for the halting state, `var : Ο` is the (finite) internal state, and `stk : β k, List (Ξ k)`
is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not
`ListBlank`s, they have definite ends that can be detected by the `pop` command.)
Given a designated stack `k` and a value `L : List (Ξ k)`, the initial configuration has all the
stacks empty except the designated "input" stack; in `eval` this designated stack also functions
as the output stack.
-/
namespace TM2
variable {K : Type*}
-- Index type of stacks
variable (Ξ : K β Type*)
-- Type of stack elements
variable (Ξ : Type*)
-- Type of function labels
variable (Ο : Type*)
-- Type of variable settings
/-- The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. -/
inductive Stmt
| push : β k, (Ο β Ξ k) β Stmt β Stmt
| peek : β k, (Ο β Option (Ξ k) β Ο) β Stmt β Stmt
| pop : β k, (Ο β Option (Ξ k) β Ο) β Stmt β Stmt
| load : (Ο β Ο) β Stmt β Stmt
| branch : (Ο β Bool) β Stmt β Stmt β Stmt
| goto : (Ο β Ξ) β Stmt
| halt : Stmt
open Stmt
instance Stmt.inhabited : Inhabited (Stmt Ξ Ξ Ο) :=
β¨haltβ©
/-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of
local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite
size.) -/
structure Cfg where
/-- The current label to run (or `none` for the halting state) -/
l : Option Ξ
/-- The internal state -/
var : Ο
/-- The (finite) collection of internal stacks -/
stk : β k, List (Ξ k)
instance Cfg.inhabited [Inhabited Ο] : Inhabited (Cfg Ξ Ξ Ο) :=
β¨β¨default, default, defaultβ©β©
variable {Ξ Ξ Ο}
section
variable [DecidableEq K]
/-- The step function for the TM2 model. -/
def stepAux : Stmt Ξ Ξ Ο β Ο β (β k, List (Ξ k)) β Cfg Ξ Ξ Ο
| push k f q, v, S => stepAux q v (update S k (f v :: S k))
| peek k f q, v, S => stepAux q (f v (S k).head?) S
| pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail)
| load a q, v, S => stepAux q (a v) S
| branch f qβ qβ, v, S => cond (f v) (stepAux qβ v S) (stepAux qβ v S)
| goto f, v, S => β¨some (f v), v, Sβ©
| halt, v, S => β¨none, v, Sβ©
/-- The step function for the TM2 model. -/
def step (M : Ξ β Stmt Ξ Ξ Ο) : Cfg Ξ Ξ Ο β Option (Cfg Ξ Ξ Ο)
| β¨none, _, _β© => none
| β¨some l, v, Sβ© => some (stepAux (M l) v S)
attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3
stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2
/-- The (reflexive) reachability relation for the TM2 model. -/
def Reaches (M : Ξ β Stmt Ξ Ξ Ο) : Cfg Ξ Ξ Ο β Cfg Ξ Ξ Ο β Prop :=
ReflTransGen fun a b β¦ b β step M a
end
/-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/
def SupportsStmt (S : Finset Ξ) : Stmt Ξ Ξ Ο β Prop
| push _ _ q => SupportsStmt S q
| peek _ _ q => SupportsStmt S q
| pop _ _ q => SupportsStmt S q
| load _ q => SupportsStmt S q
| branch _ qβ qβ => SupportsStmt S qβ β§ SupportsStmt S qβ
| goto l => β v, l v β S
| halt => True
section
open scoped Classical in
/-- The set of subtree statements in a statement. -/
noncomputable def stmtsβ : Stmt Ξ Ξ Ο β Finset (Stmt Ξ Ξ Ο)
| Q@(push _ _ q) => insert Q (stmtsβ q)
| Q@(peek _ _ q) => insert Q (stmtsβ q)
| Q@(pop _ _ q) => insert Q (stmtsβ q)
| Q@(load _ q) => insert Q (stmtsβ q)
| Q@(branch _ qβ qβ) => insert Q (stmtsβ qβ βͺ stmtsβ qβ)
| Q@(goto _) => {Q}
| Q@halt => {Q}
theorem stmtsβ_self {q : Stmt Ξ Ξ Ο} : q β stmtsβ q := by
cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmtsβ]
theorem stmtsβ_trans {qβ qβ : Stmt Ξ Ξ Ο} : qβ β stmtsβ qβ β stmtsβ qβ β stmtsβ qβ := by
classical
intro hββ qβ hββ
induction qβ with (
simp only [stmtsβ] at hββ β’
simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at hββ)
| branch f qβ qβ IHβ IHβ =>
rcases hββ with (rfl | hββ | hββ)
Β· unfold stmtsβ at hββ
exact hββ
Β· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IHβ hββ))
Β· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IHβ hββ))
| goto l => subst hββ; exact hββ
| halt => subst hββ; exact hββ
| load _ q IH | _ _ _ q IH =>
rcases hββ with (rfl | hββ)
Β· unfold stmtsβ at hββ
exact hββ
Β· exact Finset.mem_insert_of_mem (IH hββ)
theorem stmtsβ_supportsStmt_mono {S : Finset Ξ} {qβ qβ : Stmt Ξ Ξ Ο} (h : qβ β stmtsβ qβ)
(hs : SupportsStmt S qβ) : SupportsStmt S qβ := by
induction qβ with
simp only [stmtsβ, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton]
at h hs
| branch f qβ qβ IHβ IHβ => rcases h with (rfl | h | h); exacts [hs, IHβ h hs.1, IHβ h hs.2]
| goto l => subst h; exact hs
| halt => subst h; trivial
| load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs]
open scoped Classical in
/-- The set of statements accessible from initial set `S` of labels. -/
noncomputable def stmts (M : Ξ β Stmt Ξ Ξ Ο) (S : Finset Ξ) : Finset (Option (Stmt Ξ Ξ Ο)) :=
Finset.insertNone (S.biUnion fun q β¦ stmtsβ (M q))
theorem stmts_trans {M : Ξ β Stmt Ξ Ξ Ο} {S : Finset Ξ} {qβ qβ : Stmt Ξ Ξ Ο} (hβ : qβ β stmtsβ qβ) :
some qβ β stmts M S β some qβ β stmts M S := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls hβ β¦ β¨_, ls, stmtsβ_trans hβ hββ©
end
variable [Inhabited Ξ]
/-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in
`S` jump only to other states in `S`. -/
def Supports (M : Ξ β Stmt Ξ Ξ Ο) (S : Finset Ξ) :=
default β S β§ β q β S, SupportsStmt S (M q)
theorem stmts_supportsStmt {M : Ξ β Stmt Ξ Ξ Ο} {S : Finset Ξ} {q : Stmt Ξ Ξ Ο}
(ss : Supports M S) : some q β stmts M S β SupportsStmt S q := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h β¦ stmtsβ_supportsStmt_mono h (ss.2 _ ls)
variable [DecidableEq K]
theorem step_supports (M : Ξ β Stmt Ξ Ξ Ο) {S : Finset Ξ} (ss : Supports M S) :
β {c c' : Cfg Ξ Ξ Ο}, c' β step M c β c.l β Finset.insertNone S β c'.l β Finset.insertNone S
| β¨some lβ, v, Tβ©, c', hβ, hβ => by
replace hβ := ss.2 _ (Finset.some_mem_insertNone.1 hβ)
simp only [step, Option.mem_def, Option.some.injEq] at hβ; subst c'
revert hβ; induction M lβ generalizing v T with intro hs
| branch p qβ' qβ' IHβ IHβ =>
unfold stepAux; cases p v
Β· exact IHβ _ _ hs.2
Β· exact IHβ _ _ hs.1
| goto => exact Finset.some_mem_insertNone.2 (hs _)
| halt => apply Multiset.mem_cons_self
| load _ _ IH | _ _ _ _ IH => exact IH _ _ hs
variable [Inhabited Ο]
/-- The initial state of the TM2 model. The input is provided on a designated stack. -/
def init (k : K) (L : List (Ξ k)) : Cfg Ξ Ξ Ο :=
β¨some default, default, update (fun _ β¦ []) k Lβ©
/-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/
def eval (M : Ξ β Stmt Ξ Ξ Ο) (k : K) (L : List (Ξ k)) : Part (List (Ξ k)) :=
(Turing.eval (step M) (init k L)).map fun c β¦ c.stk k
end TM2
/-!
## TM2 emulator in TM1
To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a
TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of
stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack
1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this:
```
bottom: ... | _ | T | _ | _ | _ | _ | ...
stack 1: ... | _ | b | a | _ | _ | _ | ...
stack 2: ... | _ | f | e | d | c | _ | ...
```
where a tape element is a vertical slice through the diagram. Here the alphabet is
`Ξ' := Bool Γ β k, Option (Ξ k)`, where:
* `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the
tail of all stacks. It is never modified.
* `stk k : Option (Ξ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is
the blank value). Note that the head of the stack is at the far end; this is so that push and pop
don't have to do any shifting.
In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions,
it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the
end of the appropriate stack, make its changes, and then return to the bottom. So the states are:
* `normal (l : Ξ)`: waiting at `bottom` to execute function `l`
* `go k (s : StAct k) (q : Stmtβ)`: travelling to the right to get to the end of stack `k` in
order to perform stack action `s`, and later continue with executing `q`
* `ret (q : Stmtβ)`: travelling to the left after having performed a stack action, and executing
`q` once we arrive
Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the
length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)`
steps to run when emulated in TM1, where `m` is the length of the input.
-/
namespace TM2to1
-- A displaced lemma proved in unnecessary generality
theorem stk_nth_val {K : Type*} {Ξ : K β Type*} {L : ListBlank (β k, Option (Ξ k))} {k S} (n)
(hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) :
L.nth n k = S.reverse[n]? := by
rw [β proj_map_nth, hL, β List.map_reverse, ListBlank.nth_mk,
List.getI_eq_iget_getElem?, List.getElem?_map]
cases S.reverse[n]? <;> rfl
variable (K : Type*)
variable (Ξ : K β Type*)
variable {Ξ Ο : Type*}
/-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom,
plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/
def Ξ' :=
Bool Γ β k, Option (Ξ k)
variable {K Ξ}
instance Ξ'.inhabited : Inhabited (Ξ' K Ξ) :=
β¨β¨false, fun _ β¦ noneβ©β©
instance Ξ'.fintype [DecidableEq K] [Fintype K] [β k, Fintype (Ξ k)] : Fintype (Ξ' K Ξ) :=
instFintypeProd _ _
/-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function
to express the program state in terms of a tape with only the stacks themselves. -/
def addBottom (L : ListBlank (β k, Option (Ξ k))) : ListBlank (Ξ' K Ξ) :=
ListBlank.cons (true, L.head) (L.tail.map β¨Prod.mk false, rflβ©)
theorem addBottom_map (L : ListBlank (β k, Option (Ξ k))) :
(addBottom L).map β¨Prod.snd, by rflβ© = L := by
simp only [addBottom, ListBlank.map_cons]
convert ListBlank.cons_head_tail L
generalize ListBlank.tail L = L'
refine L'.induction_on fun l β¦ ?_; simp
theorem addBottom_modifyNth (f : (β k, Option (Ξ k)) β β k, Option (Ξ k))
(L : ListBlank (β k, Option (Ξ k))) (n : β) :
(addBottom L).modifyNth (fun a β¦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by
cases n <;>
simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons]
congr; symm; apply ListBlank.map_modifyNth; intro; rfl
theorem addBottom_nth_snd (L : ListBlank (β k, Option (Ξ k))) (n : β) :
((addBottom L).nth n).2 = L.nth n := by
conv => rhs; rw [β addBottom_map L, ListBlank.nth_map]
theorem addBottom_nth_succ_fst (L : ListBlank (β k, Option (Ξ k))) (n : β) :
((addBottom L).nth (n + 1)).1 = false := by
rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map]
theorem addBottom_head_fst (L : ListBlank (β k, Option (Ξ k))) : (addBottom L).head.1 = true := by
rw [addBottom, ListBlank.head_cons]
variable (K Ξ Ο) in
/-- A stack action is a command that interacts with the top of a stack. Our default position
is at the bottom of all the stacks, so we have to hold on to this action while going to the end
to modify the stack. -/
inductive StAct (k : K)
| push : (Ο β Ξ k) β StAct k
| peek : (Ο β Option (Ξ k) β Ο) β StAct k
| pop : (Ο β Option (Ξ k) β Ο) β StAct k
instance StAct.inhabited {k : K} : Inhabited (StAct K Ξ Ο k) :=
β¨StAct.peek fun s _ β¦ sβ©
section
open StAct
/-- The TM2 statement corresponding to a stack action. -/
def stRun {k : K} : StAct K Ξ Ο k β TM2.Stmt Ξ Ξ Ο β TM2.Stmt Ξ Ξ Ο
| push f => TM2.Stmt.push k f
| peek f => TM2.Stmt.peek k f
| pop f => TM2.Stmt.pop k f
/-- The effect of a stack action on the local variables, given the value of the stack. -/
def stVar {k : K} (v : Ο) (l : List (Ξ k)) : StAct K Ξ Ο k β Ο
| push _ => v
| peek f => f v l.head?
| pop f => f v l.head?
/-- The effect of a stack action on the stack. -/
def stWrite {k : K} (v : Ο) (l : List (Ξ k)) : StAct K Ξ Ο k β List (Ξ k)
| push f => f v :: l
| peek _ => l
| pop _ => l.tail
/-- We have partitioned the TM2 statements into "stack actions", which require going to the end
of the stack, and all other actions, which do not. This is a modified recursor which lumps the
stack actions into one. -/
@[elab_as_elim]
def stmtStRec.{l} {motive : TM2.Stmt Ξ Ξ Ο β Sort l}
(run : β (k) (s : StAct K Ξ Ο k) (q) (_ : motive q), motive (stRun s q))
(load : β (a q) (_ : motive q), motive (TM2.Stmt.load a q))
(branch : β (p qβ qβ) (_ : motive qβ) (_ : motive qβ), motive (TM2.Stmt.branch p qβ qβ))
(goto : β l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : β n, motive n
| TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q)
| TM2.Stmt.branch _ qβ qβ =>
branch _ _ _ (stmtStRec run load branch goto halt qβ) (stmtStRec run load branch goto halt qβ)
| TM2.Stmt.goto _ => goto _
| TM2.Stmt.halt => halt
theorem supports_run (S : Finset Ξ) {k : K} (s : StAct K Ξ Ο k) (q : TM2.Stmt Ξ Ξ Ο) :
TM2.SupportsStmt S (stRun s q) β TM2.SupportsStmt S q := by
cases s <;> rfl
end
variable (K Ξ Ξ Ο)
/-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the
next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and
return to the bottom, respectively. -/
inductive Ξ'
| normal : Ξ β Ξ'
| go (k : K) : StAct K Ξ Ο k β TM2.Stmt Ξ Ξ Ο β Ξ'
| ret : TM2.Stmt Ξ Ξ Ο β Ξ'
variable {K Ξ Ξ Ο}
open Ξ'
instance Ξ'.inhabited [Inhabited Ξ] : Inhabited (Ξ' K Ξ Ξ Ο) :=
β¨normal defaultβ©
open TM1.Stmt
section
variable [DecidableEq K]
/-- The program corresponding to state transitions at the end of a stack. Here we start out just
after the top of the stack, and should end just after the new top of the stack. -/
def trStAct {k : K} (q : TM1.Stmt (Ξ' K Ξ) (Ξ' K Ξ Ξ Ο) Ο) :
StAct K Ξ Ο k β TM1.Stmt (Ξ' K Ξ) (Ξ' K Ξ Ξ Ο) Ο
| StAct.push f => (write fun a s β¦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q
| StAct.peek f => move Dir.left <| (load fun a s β¦ f s (a.2 k)) <| move Dir.right q
| StAct.pop f =>
branch (fun a _ β¦ a.1) (load (fun _ s β¦ f s none) q)
(move Dir.left <|
(load fun a s β¦ f s (a.2 k)) <| write (fun a _ β¦ (a.1, update a.2 k none)) q)
/-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty
except for the input stack, and the stack bottom mark is set at the head. -/
def trInit (k : K) (L : List (Ξ k)) : List (Ξ' K Ξ) :=
let L' : List (Ξ' K Ξ) := L.reverse.map fun a β¦ (false, update (fun _ β¦ none) k (some a))
(true, L'.headI.2) :: L'.tail
theorem step_run {k : K} (q : TM2.Stmt Ξ Ξ Ο) (v : Ο) (S : β k, List (Ξ k)) : β s : StAct K Ξ Ο k,
TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s))
| StAct.push _ => rfl
| StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl
| StAct.pop _ => rfl
end
/-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents,
but stack actions are deferred by going to the corresponding `go` state, so that we can find the
appropriate stack top. -/
def trNormal : TM2.Stmt Ξ Ξ Ο β TM1.Stmt (Ξ' K Ξ) (Ξ' K Ξ Ξ Ο) Ο
| TM2.Stmt.push k f q => goto fun _ _ β¦ go k (StAct.push f) q
| TM2.Stmt.peek k f q => goto fun _ _ β¦ go k (StAct.peek f) q
| TM2.Stmt.pop k f q => goto fun _ _ β¦ go k (StAct.pop f) q
| TM2.Stmt.load a q => load (fun _ β¦ a) (trNormal q)
| TM2.Stmt.branch f qβ qβ => branch (fun _ β¦ f) (trNormal qβ) (trNormal qβ)
| TM2.Stmt.goto l => goto fun _ s β¦ normal (l s)
| TM2.Stmt.halt => halt
theorem trNormal_run {k : K} (s : StAct K Ξ Ο k) (q : TM2.Stmt Ξ Ξ Ο) :
trNormal (stRun s q) = goto fun _ _ β¦ go k s q := by
cases s <;> rfl
section
open scoped Classical in
/-- The set of machine states accessible from an initial TM2 statement. -/
noncomputable def trStmtsβ : TM2.Stmt Ξ Ξ Ο β Finset (Ξ' K Ξ Ξ Ο)
| TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} βͺ trStmtsβ q
| TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} βͺ trStmtsβ q
| TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} βͺ trStmtsβ q
| TM2.Stmt.load _ q => trStmtsβ q
| TM2.Stmt.branch _ qβ qβ => trStmtsβ qβ βͺ trStmtsβ qβ
| _ => β
theorem trStmtsβ_run {k : K} {s : StAct K Ξ Ο k} {q : TM2.Stmt Ξ Ξ Ο} :
open scoped Classical in
trStmtsβ (stRun s q) = {go k s q, ret q} βͺ trStmtsβ q := by
cases s <;> simp only [trStmtsβ, stRun]
theorem tr_respects_auxβ [DecidableEq K] {k : K} {q : TM1.Stmt (Ξ' K Ξ) (Ξ' K Ξ Ξ Ο) Ο} {v : Ο}
{S : β k, List (Ξ k)} {L : ListBlank (β k, Option (Ξ k))}
(hL : β k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Ξ Ο k) :
let v' := stVar v (S k) o
let Sk' := stWrite v (S k) o
let S' := update S k Sk'
β L' : ListBlank (β k, Option (Ξ k)),
(β k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) β§
TM1.stepAux (trStAct q o) v
((Tape.move Dir.right)^[(S k).length] (Tape.mk' β
(addBottom L))) =
TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' β
(addBottom L'))) := by
simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux]
| push f =>
have := Tape.write_move_right_n fun a : Ξ' K Ξ β¦ (a.1, update a.2 k (some (f v)))
refine
β¨_, fun k' β¦ ?_, by
-- Porting note: `rw [...]` to `erw [...]; rfl`.
-- https://github.com/leanprover-community/mathlib4/issues/5164
rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this]
erw [addBottom_modifyNth fun a β¦ update a k (some (f v))]
rw [Nat.add_one, iterate_succ']
rflβ©
refine ListBlank.ext fun i β¦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
Β· subst k'
split_ifs with h
<;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map]
Β· rw [List.getI_eq_getElem _, List.getElem_append_right] <;>
simp only [List.length_append, List.length_reverse, List.length_map, β h,
Nat.sub_self, List.length_singleton, List.getElem_singleton,
le_refl, Nat.lt_succ_self]
rw [β proj_map_nth, hL, ListBlank.nth_mk]
rcases lt_or_gt_of_ne h with h | h
Β· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
Β· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
Β· split_ifs <;> rw [Function.update_of_ne h', β proj_map_nth, hL]
rw [Function.update_of_ne h']
| peek f =>
rw [Function.update_eq_self]
use L, hL; rw [Tape.move_left_right]; congr
cases e : S k; Β· rfl
rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left,
Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e,
List.reverse_cons, β List.length_reverse, List.getElem?_concat_length]
rfl
| pop f =>
rcases e : S k with - | β¨hd, tlβ©
Β· simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length,
Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil]
rw [β e, Function.update_eq_self]
exact β¨L, hL, by rw [addBottom_head_fst, cond]β©
Β· refine
β¨_, fun k' β¦ ?_, by
erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst,
cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head,
Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Ξ' K Ξ β¦ (a.1, update a.2 k none),
addBottom_modifyNth fun a β¦ update a k none, addBottom_nth_snd,
stk_nth_val _ (hL k), e,
show (List.cons hd tl).reverse[tl.length]? = some hd by
rw [List.reverse_cons, β List.length_reverse, List.getElem?_concat_length],
List.head?, List.tail]β©
refine ListBlank.ext fun i β¦ ?_
rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val]
by_cases h' : k' = k
Β· subst k'
split_ifs with h <;> simp only [Function.update_self, ListBlank.nth_mk, List.tail]
Β· rw [List.getI_eq_default]
Β· rfl
rw [h, List.length_reverse, List.length_map]
rw [β proj_map_nth, hL, ListBlank.nth_mk, e, List.map, List.reverse_cons]
rcases lt_or_gt_of_ne h with h | h
Β· rw [List.getI_append]
simpa only [List.length_map, List.length_reverse] using h
Β· rw [gt_iff_lt] at h
rw [List.getI_eq_default, List.getI_eq_default] <;>
simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse,
List.length_append, List.length_map]
Β· split_ifs <;> rw [Function.update_of_ne h', β proj_map_nth, hL]
rw [Function.update_of_ne h']
end
variable [DecidableEq K]
variable (M : Ξ β TM2.Stmt Ξ Ξ Ο)
/-- The TM2 emulator machine states written as a TM1 program.
This handles the `go` and `ret` states, which shuttle to and from a stack top. -/
def tr : Ξ' K Ξ Ξ Ο β TM1.Stmt (Ξ' K Ξ) (Ξ' K Ξ Ξ Ο) Ο
| normal q => trNormal (M q)
| go k s q =>
branch (fun a _ β¦ (a.2 k).isNone) (trStAct (goto fun _ _ β¦ ret q) s)
(move Dir.right <| goto fun _ _ β¦ go k s q)
| ret q => branch (fun a _ β¦ a.1) (trNormal q) (move Dir.left <| goto fun _ _ β¦ ret q)
/-- The relation between TM2 configurations and TM1 configurations of the TM2 emulator. -/
inductive TrCfg : TM2.Cfg Ξ Ξ Ο β TM1.Cfg (Ξ' K Ξ) (Ξ' K Ξ Ξ Ο) Ο β Prop
| mk {q : Option Ξ} {v : Ο} {S : β k, List (Ξ k)} (L : ListBlank (β k, Option (Ξ k))) :
(β k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) β
TrCfg β¨q, v, Sβ© β¨q.map normal, v, Tape.mk' β
(addBottom L)β©
theorem tr_respects_auxβ {k} (o q v) {S : List (Ξ k)} {L : ListBlank (β k, Option (Ξ k))}
(hL : L.map (proj k) = ListBlank.mk (S.map some).reverse) (n) (H : n β€ S.length) :
Reachesβ (TM1.step (tr M)) β¨some (go k o q), v, Tape.mk' β
(addBottom L)β©
β¨some (go k o q), v, (Tape.move Dir.right)^[n] (Tape.mk' β
(addBottom L))β© := by
induction' n with n IH; Β· rfl
apply (IH (le_of_lt H)).tail
rw [iterate_succ_apply']
simp only [TM1.step, TM1.stepAux, tr, Tape.mk'_nth_nat, Tape.move_right_n_head,
addBottom_nth_snd, Option.mem_def]
rw [stk_nth_val _ hL, List.getElem?_eq_getElem]
Β· rfl
Β· rwa [List.length_reverse]
theorem tr_respects_auxβ {q v} {L : ListBlank (β k, Option (Ξ k))} (n) : Reachesβ (TM1.step (tr M))
β¨some (ret q), v, (Tape.move Dir.right)^[n] (Tape.mk' β
(addBottom L))β©
β¨some (ret q), v, Tape.mk' β
(addBottom L)β© := by
induction' n with n IH; Β· rfl
refine Reachesβ.head ?_ IH
simp only [Option.mem_def, TM1.step]
rw [Option.some_inj, tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat,
addBottom_nth_succ_fst, TM1.stepAux, iterate_succ', Function.comp_apply, Tape.move_right_left]
rfl
theorem tr_respects_aux {q v T k} {S : β k, List (Ξ k)}
(hT : β k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse)
(o : StAct K Ξ Ο k)
(IH : β {v : Ο} {S : β k : K, List (Ξ k)} {T : ListBlank (β k, Option (Ξ k))},
(β k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) β
β b, TrCfg (TM2.stepAux q v S) b β§
Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal q) v (Tape.mk' β
(addBottom T))) b) :
β b, TrCfg (TM2.stepAux (stRun o q) v S) b β§ Reaches (TM1.step (tr M))
(TM1.stepAux (trNormal (stRun o q)) v (Tape.mk' β
(addBottom T))) b := by
simp only [trNormal_run, step_run]
have hgo := tr_respects_auxβ M o q v (hT k) _ le_rfl
obtain β¨T', hT', hrunβ© := tr_respects_auxβ (Ξ := Ξ) hT o
have := hgo.tail' rfl
rw [tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd,
stk_nth_val _ (hT k), List.getElem?_eq_none (le_of_eq List.length_reverse),
Option.isNone, cond, hrun, TM1.stepAux] at this
obtain β¨c, gc, rcβ© := IH hT'
refine β¨c, gc, (this.toβ.trans (tr_respects_auxβ M _) c (TransGen.head' rfl ?_)).to_reflTransGenβ©
rw [tr, TM1.stepAux, Tape.mk'_head, addBottom_head_fst]
exact rc
attribute [local simp] Respects TM2.step TM2.stepAux trNormal
theorem tr_respects : Respects (TM2.step M) (TM1.step (tr M)) TrCfg := by
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
intro cβ cβ h
obtain @β¨- | l, v, S, L, hTβ© := h; Β· constructor
rsuffices β¨b, c, rβ© : β b, _ β§ Reaches (TM1.step (tr M)) _ _
Β· exact β¨b, c, TransGen.head' rfl rβ©
simp only [tr]
generalize M l = N
induction N using stmtStRec generalizing v S L hT with
| run k s q IH => exact tr_respects_aux M hT s @IH
| load a _ IH => exact IH _ hT
| branch p qβ qβ IHβ IHβ =>
unfold TM2.stepAux trNormal TM1.stepAux
beta_reduce
cases p v <;> [exact IHβ _ hT; exact IHβ _ hT]
| goto => exact β¨_, β¨_, hTβ©, ReflTransGen.reflβ©
| halt => exact β¨_, β¨_, hTβ©, ReflTransGen.reflβ©
section
variable [Inhabited Ξ] [Inhabited Ο]
theorem trCfg_init (k) (L : List (Ξ k)) : TrCfg (TM2.init k L)
(TM1.init (trInit k L) : TM1.Cfg (Ξ' K Ξ) (Ξ' K Ξ Ξ Ο) Ο) := by
rw [(_ : TM1.init _ = _)]
Β· refine β¨ListBlank.mk (L.reverse.map fun a β¦ update default k (some a)), fun k' β¦ ?_β©
refine ListBlank.ext fun i β¦ ?_
rw [ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map_map]
have : ((proj k').f β fun a => update (Ξ² := fun k => Option (Ξ k)) default k (some a))
= fun a => (proj k').f (update (Ξ² := fun k => Option (Ξ k)) default k (some a)) := rfl
rw [this, List.getElem?_map, proj, PointedMap.mk_val]
simp only []
by_cases h : k' = k
Β· subst k'
simp only [Function.update_self]
rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, β List.map_reverse, List.getElem?_map]
Β· simp only [Function.update_of_ne h]
rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map, List.reverse_nil]
cases L.reverse[i]? <;> rfl
Β· rw [trInit, TM1.init]
congr <;> cases L.reverse <;> try rfl
simp only [List.map_map, List.tail_cons, List.map]
rfl
theorem tr_eval_dom (k) (L : List (Ξ k)) :
(TM1.eval (tr M) (trInit k L)).Dom β (TM2.eval M k L).Dom :=
Turing.tr_eval_dom (tr_respects M) (trCfg_init k L)
theorem tr_eval (k) (L : List (Ξ k)) {Lβ Lβ} (Hβ : Lβ β TM1.eval (tr M) (trInit k L))
(Hβ : Lβ β TM2.eval M k L) :
β (S : β k, List (Ξ k)) (L' : ListBlank (β k, Option (Ξ k))),
addBottom L' = Lβ β§
(β k, L'.map (proj k) = ListBlank.mk ((S k).map some).reverse) β§ S k = Lβ := by
obtain β¨cβ, hβ, rflβ© := (Part.mem_map_iff _).1 Hβ
obtain β¨cβ, hβ, rflβ© := (Part.mem_map_iff _).1 Hβ
obtain β¨_, β¨L', hTβ©, hββ© := Turing.tr_eval (tr_respects M) (trCfg_init k L) hβ
cases Part.mem_unique hβ hβ
exact β¨_, L', by simp only [Tape.mk'_rightβ], hT, rflβ©
end
section
variable [Inhabited Ξ]
open scoped Classical in
/-- The support of a set of TM2 states in the TM2 emulator. -/
noncomputable def trSupp (S : Finset Ξ) : Finset (Ξ' K Ξ Ξ Ο) :=
S.biUnion fun l β¦ insert (normal l) (trStmtsβ (M l))
open scoped Classical in
theorem tr_supports {S} (ss : TM2.Supports M S) : TM1.Supports (tr M) (trSupp M S) :=
β¨Finset.mem_biUnion.2 β¨_, ss.1, Finset.mem_insert.2 <| Or.inl rflβ©, fun l' h β¦ by
suffices β (q) (_ : TM2.SupportsStmt S q) (_ : β x β trStmtsβ q, x β trSupp M S),
TM1.SupportsStmt (trSupp M S) (trNormal q) β§
β l' β trStmtsβ q, TM1.SupportsStmt (trSupp M S) (tr M l') by
rcases Finset.mem_biUnion.1 h with β¨l, lS, hβ©
have :=
this _ (ss.2 l lS) fun x hx β¦ Finset.mem_biUnion.2 β¨_, lS, Finset.mem_insert_of_mem hxβ©
rcases Finset.mem_insert.1 h with (rfl | h) <;> [exact this.1; exact this.2 _ h]
clear h l'
refine stmtStRec ?_ ?_ ?_ ?_ ?_
Β· intro _ s _ IH ss' sub -- stack op
rw [TM2to1.supports_run] at ss'
simp only [TM2to1.trStmtsβ_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton]
at sub
have hgo := sub _ (Or.inl <| Or.inl rfl)
have hret := sub _ (Or.inl <| Or.inr rfl)
obtain β¨IHβ, IHββ© := IH ss' fun x hx β¦ sub x <| Or.inr hx
refine β¨by simp only [trNormal_run, TM1.SupportsStmt]; intros; exact hgo, fun l h β¦ ?_β©
rw [trStmtsβ_run] at h
simp only [TM2to1.trStmtsβ_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton]
at h
rcases h with (β¨rfl | rflβ© | h)
Β· cases s
Β· exact β¨fun _ _ β¦ hret, fun _ _ β¦ hgoβ©
Β· exact β¨fun _ _ β¦ hret, fun _ _ β¦ hgoβ©
Β· exact β¨β¨fun _ _ β¦ hret, fun _ _ β¦ hretβ©, fun _ _ β¦ hgoβ©
Β· unfold TM1.SupportsStmt TM2to1.tr
exact β¨IHβ, fun _ _ β¦ hretβ©
Β· exact IHβ _ h
Β· intro _ _ IH ss' sub -- load
unfold TM2to1.trStmtsβ at sub β’
exact IH ss' sub
Β· intro _ _ _ IHβ IHβ ss' sub -- branch
unfold TM2to1.trStmtsβ at sub
obtain β¨IHββ, IHβββ© := IHβ ss'.1 fun x hx β¦ sub x <| Finset.mem_union_left _ hx
obtain β¨IHββ, IHβββ© := IHβ ss'.2 fun x hx β¦ sub x <| Finset.mem_union_right _ hx
refine β¨β¨IHββ, IHβββ©, fun l h β¦ ?_β©
rw [trStmtsβ] at h
rcases Finset.mem_union.1 h with (h | h) <;> [exact IHββ _ h; exact IHββ _ h]
Β· intro _ ss' _ -- goto
simp only [trStmtsβ, Finset.not_mem_empty]; refine β¨?_, fun _ β¦ False.elimβ©
exact fun _ v β¦ Finset.mem_biUnion.2 β¨_, ss' v, Finset.mem_insert_self _ _β©
Β· intro _ _ -- halt
simp only [trStmtsβ, Finset.not_mem_empty]
exact β¨trivial, fun _ β¦ False.elimβ©β©
end
end TM2to1
end Turing
| Mathlib/Computability/TuringMachine.lean | 2,382 | 2,387 | |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Alex Kontorovich
-/
import Mathlib.Data.Set.Piecewise
import Mathlib.Order.Filter.Tendsto
import Mathlib.Order.Filter.Bases.Finite
/-!
# (Co)product of a family of filters
In this file we define two filters on `Ξ i, Ξ± i` and prove some basic properties of these filters.
* `Filter.pi (f : Ξ i, Filter (Ξ± i))` to be the maximal filter on `Ξ i, Ξ± i` such that
`β i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as
`Ξ i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed
products.
* `Filter.coprodα΅’ (f : Ξ i, Filter (Ξ± i))`: a generalization of `Filter.coprod`; it is the supremum
of `comap (eval i) (f i)`.
-/
open Set Function Filter
namespace Filter
variable {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} {f fβ fβ : (i : ΞΉ) β Filter (Ξ± i)} {s : (i : ΞΉ) β Set (Ξ± i)}
{p : β i, Ξ± i β Prop}
section Pi
theorem tendsto_eval_pi (f : β i, Filter (Ξ± i)) (i : ΞΉ) : Tendsto (eval i) (pi f) (f i) :=
tendsto_iInf' i tendsto_comap
theorem tendsto_pi {Ξ² : Type*} {m : Ξ² β β i, Ξ± i} {l : Filter Ξ²} :
Tendsto m l (pi f) β β i, Tendsto (fun x => m x i) l (f i) := by
simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl
/-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to
`f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a
product of topological spaces. -/
alias β¨Tendsto.apply, _β© := tendsto_pi
theorem le_pi {g : Filter (β i, Ξ± i)} : g β€ pi f β β i, Tendsto (eval i) g (f i) :=
tendsto_pi
@[mono]
theorem pi_mono (h : β i, fβ i β€ fβ i) : pi fβ β€ pi fβ :=
iInf_mono fun i => comap_mono <| h i
theorem mem_pi_of_mem (i : ΞΉ) {s : Set (Ξ± i)} (hs : s β f i) : eval i β»ΒΉ' s β pi f :=
mem_iInf_of_mem i <| preimage_mem_comap hs
theorem pi_mem_pi {I : Set ΞΉ} (hI : I.Finite) (h : β i β I, s i β f i) : I.pi s β pi f := by
rw [pi_def, biInter_eq_iInter]
refine mem_iInf_of_iInter hI (fun i => ?_) Subset.rfl
exact preimage_mem_comap (h i i.2)
theorem mem_pi {s : Set (β i, Ξ± i)} :
s β pi f β β I : Set ΞΉ, I.Finite β§ β t : β i, Set (Ξ± i), (β i, t i β f i) β§ I.pi t β s := by
constructor
Β· simp only [pi, mem_iInf', mem_comap, pi_def]
rintro β¨I, If, V, hVf, -, rfl, -β©
choose t htf htV using hVf
exact β¨I, If, t, htf, iInterβ_mono fun i _ => htV iβ©
Β· rintro β¨I, If, t, htf, htsβ©
exact mem_of_superset (pi_mem_pi If fun i _ => htf i) hts
theorem mem_pi' {s : Set (β i, Ξ± i)} :
s β pi f β β I : Finset ΞΉ, β t : β i, Set (Ξ± i), (β i, t i β f i) β§ Set.pi (βI) t β s :=
mem_pi.trans exists_finite_iff_finset
theorem mem_of_pi_mem_pi [β i, NeBot (f i)] {I : Set ΞΉ} (h : I.pi s β pi f) {i : ΞΉ} (hi : i β I) :
s i β f i := by
classical
rcases mem_pi.1 h with β¨I', -, t, htf, htsβ©
refine mem_of_superset (htf i) fun x hx => ?_
have : β i, (t i).Nonempty := fun i => nonempty_of_mem (htf i)
choose g hg using this
have : update g i x β I'.pi t := fun j _ => by
rcases eq_or_ne j i with (rfl | hne) <;> simp [*]
simpa using hts this i hi
@[simp]
theorem pi_mem_pi_iff [β i, NeBot (f i)] {I : Set ΞΉ} (hI : I.Finite) :
I.pi s β pi f β β i β I, s i β f i :=
β¨fun h _i hi => mem_of_pi_mem_pi h hi, pi_mem_pi hIβ©
theorem Eventually.eval_pi {i : ΞΉ} (hf : βαΆ x : Ξ± i in f i, p i x) :
βαΆ x : β i : ΞΉ, Ξ± i in pi f, p i (x i) := (tendsto_eval_pi _ _).eventually hf
theorem eventually_pi [Finite ΞΉ] (hf : β i, βαΆ x in f i, p i x) :
βαΆ x : β i, Ξ± i in pi f, β i, p i (x i) := eventually_all.2 fun _i => (hf _).eval_pi
theorem hasBasis_pi {ΞΉ' : ΞΉ β Type*} {s : β i, ΞΉ' i β Set (Ξ± i)} {p : β i, ΞΉ' i β Prop}
(h : β i, (f i).HasBasis (p i) (s i)) :
(pi f).HasBasis (fun If : Set ΞΉ Γ β i, ΞΉ' i => If.1.Finite β§ β i β If.1, p i (If.2 i))
fun If : Set ΞΉ Γ β i, ΞΉ' i => If.1.pi fun i => s i <| If.2 i := by
simpa [Set.pi_def] using hasBasis_iInf' fun i => (h i).comap (eval i : (β j, Ξ± j) β Ξ± i)
theorem hasBasis_pi_same_index {ΞΊ : Type*} {p : ΞΊ β Prop} {s : Ξ i : ΞΉ, ΞΊ β Set (Ξ± i)}
(h : β i : ΞΉ, (f i).HasBasis p (s i))
(h_dir : β I : Set ΞΉ, β k : ΞΉ β ΞΊ, I.Finite β (β i β I, p (k i)) β
β kβ, p kβ β§ β i β I, s i kβ β s i (k i)) :
(pi f).HasBasis (fun Ik : Set ΞΉ Γ ΞΊ β¦ Ik.1.Finite β§ p Ik.2)
(fun Ik β¦ Ik.1.pi (fun i β¦ s i Ik.2)) := by
refine hasBasis_pi h |>.to_hasBasis ?_ ?_
Β· rintro β¨I, kβ© β¨hI, hkβ©
rcases h_dir I k hI hk with β¨kβ, hkβ, hkβ'β©
exact β¨β¨I, kββ©, β¨hI, hkββ©, Set.pi_mono hkβ'β©
Β· rintro β¨I, kβ© β¨hI, hkβ©
exact β¨β¨I, fun _ β¦ kβ©, β¨hI, fun _ _ β¦ hkβ©, subset_rflβ©
theorem HasBasis.pi_self {Ξ± : Type*} {ΞΊ : Type*} {f : Filter Ξ±} {p : ΞΊ β Prop} {s : ΞΊ β Set Ξ±}
(h : f.HasBasis p s) :
(pi fun _ β¦ f).HasBasis (fun Ik : Set ΞΉ Γ ΞΊ β¦ Ik.1.Finite β§ p Ik.2)
(fun Ik β¦ Ik.1.pi (fun _ β¦ s Ik.2)) := by
refine hasBasis_pi_same_index (fun _ β¦ h) (fun I k hI hk β¦ ?_)
rcases h.mem_iff.mp (biInter_mem hI |>.mpr fun i hi β¦ h.mem_of_mem (hk i hi))
with β¨kβ, hkβ, hkβ'β©
exact β¨kβ, hkβ, fun i hi β¦ hkβ'.trans (biInter_subset_of_mem hi)β©
theorem le_pi_principal (s : (i : ΞΉ) β Set (Ξ± i)) :
π (univ.pi s) β€ pi fun i β¦ π (s i) :=
le_pi.2 fun i β¦ tendsto_principal_principal.2 fun _f hf β¦ hf i trivial
/-- The indexed product of finitely many principal filters
is the principal filter corresponding to the cylinder `Set.univ.pi s`.
If the index type is infinite, then `mem_pi_principal` and `hasBasis_pi_principal` may be useful. -/
@[simp]
theorem pi_principal [Finite ΞΉ] (s : (i : ΞΉ) β Set (Ξ± i)) :
pi (fun i β¦ π (s i)) = π (univ.pi s) := by
simp [Filter.pi, Set.pi_def]
/-- The indexed product of a (possibly, infinite) family of principal filters
is generated by the finite `Set.pi` cylinders.
If the index type is finite, then the indexed product of principal filters
is a pricipal filter, see `pi_principal`. -/
theorem mem_pi_principal {t : Set ((i : ΞΉ) β Ξ± i)} :
t β pi (fun i β¦ π (s i)) β β I : Set ΞΉ, I.Finite β§ I.pi s β t :=
(hasBasis_pi (fun i β¦ hasBasis_principal _)).mem_iff.trans <| by simp
/-- The indexed product of a (possibly, infinite) family of principal filters
is generated by the finite `Set.pi` cylinders.
If the index type is finite, then the indexed product of principal filters
is a pricipal filter, see `pi_principal`. -/
theorem hasBasis_pi_principal (s : (i : ΞΉ) β Set (Ξ± i)) :
HasBasis (pi fun i β¦ π (s i)) Set.Finite (Set.pi Β· s) :=
β¨fun _ β¦ mem_pi_principalβ©
/-- The indexed product of finitely many pure filters `pure (f i)` is the pure filter `pure f`.
If the index type is infinite, then `mem_pi_pure` and `hasBasis_pi_pure` below may be useful. -/
@[simp]
theorem pi_pure [Finite ΞΉ] (f : (i : ΞΉ) β Ξ± i) : pi (pure <| f Β·) = pure f := by
simp only [β principal_singleton, pi_principal, univ_pi_singleton]
/-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)`
is generated by the sets of functions that are equal to `f` on a finite set.
If the index type is finite, then the indexed product of pure filters is a pure filter,
see `pi_pure`. -/
theorem mem_pi_pure {f : (i : ΞΉ) β Ξ± i} {s : Set ((i : ΞΉ) β Ξ± i)} :
s β pi (fun i β¦ pure (f i)) β β I : Set ΞΉ, I.Finite β§ β g, (β i β I, g i = f i) β g β s := by
simp only [β principal_singleton, mem_pi_principal]
simp [subset_def]
/-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)`
is generated by the sets of functions that are equal to `f` on a finite set.
If the index type is finite, then the indexed product of pure filters is a pure filter,
see `pi_pure`. -/
theorem hasBasis_pi_pure (f : (i : ΞΉ) β Ξ± i) :
HasBasis (pi fun i β¦ pure (f i)) Set.Finite (fun I β¦ {g | β i β I, g i = f i}) :=
β¨fun _ β¦ mem_pi_pureβ©
@[simp]
theorem pi_inf_principal_univ_pi_eq_bot :
pi f β π (Set.pi univ s) = β₯ β β i, f i β π (s i) = β₯ := by
constructor
Β· simp only [inf_principal_eq_bot, mem_pi]
contrapose!
rintro (hsf : β i, βαΆ x in f i, x β s i) I - t htf hts
have : β i, (s i β© t i).Nonempty := fun i => ((hsf i).and_eventually (htf i)).exists
choose x hxs hxt using this
exact hts (fun i _ => hxt i) (mem_univ_pi.2 hxs)
Β· simp only [inf_principal_eq_bot]
rintro β¨i, hiβ©
filter_upwards [mem_pi_of_mem i hi] with x using mt fun h => h i trivial
@[simp]
theorem pi_inf_principal_pi_eq_bot [β i, NeBot (f i)] {I : Set ΞΉ} :
pi f β π (Set.pi I s) = β₯ β β i β I, f i β π (s i) = β₯ := by
classical
rw [β univ_pi_piecewise_univ I, pi_inf_principal_univ_pi_eq_bot]
refine exists_congr fun i => ?_
by_cases hi : i β I <;> simp [hi, NeBot.ne']
@[simp]
theorem pi_inf_principal_univ_pi_neBot :
NeBot (pi f β π (Set.pi univ s)) β β i, NeBot (f i β π (s i)) := by simp [neBot_iff]
@[simp]
theorem pi_inf_principal_pi_neBot [β i, NeBot (f i)] {I : Set ΞΉ} :
NeBot (pi f β π (I.pi s)) β β i β I, NeBot (f i β π (s i)) := by simp [neBot_iff]
instance PiInfPrincipalPi.neBot [h : β i, NeBot (f i β π (s i))] {I : Set ΞΉ} :
NeBot (pi f β π (I.pi s)) :=
(pi_inf_principal_univ_pi_neBot.2 βΉ_βΊ).mono <|
inf_le_inf_left _ <| principal_mono.2 fun _ hx i _ => hx i trivial
@[simp]
theorem pi_eq_bot : pi f = β₯ β β i, f i = β₯ := by
simpa using @pi_inf_principal_univ_pi_eq_bot ΞΉ Ξ± f fun _ => univ
@[simp]
theorem pi_neBot : NeBot (pi f) β β i, NeBot (f i) := by simp [neBot_iff]
instance [β i, NeBot (f i)] : NeBot (pi f) :=
pi_neBot.2 βΉ_βΊ
@[simp]
theorem map_eval_pi (f : β i, Filter (Ξ± i)) [β i, NeBot (f i)] (i : ΞΉ) :
| map (eval i) (pi f) = f i := by
refine le_antisymm (tendsto_eval_pi f i) fun s hs => ?_
| Mathlib/Order/Filter/Pi.lean | 229 | 230 |
/-
Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark
-/
import Mathlib.Algebra.Polynomial.Expand
import Mathlib.Algebra.Polynomial.Laurent
import Mathlib.Algebra.Polynomial.Eval.SMul
import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.RingTheory.Polynomial.Nilpotent
/-!
# Characteristic polynomials
We give methods for computing coefficients of the characteristic polynomial.
## Main definitions
- `Matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial
over a nonzero ring is the dimension of the matrix
- `Matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the
characteristic polynomial, up to sign.
- `Matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th
coefficient of the characteristic polynomial, where d is the dimension of the matrix.
For a nonzero ring, this is the second-highest coefficient.
- `Matrix.charpolyRev` the reverse of the characteristic polynomial.
- `Matrix.reverse_charpoly` characterises the reverse of the characteristic polynomial.
-/
noncomputable section
universe u v w z
open Finset Matrix Polynomial
variable {R : Type u} [CommRing R]
variable {n G : Type v} [DecidableEq n] [Fintype n]
variable {Ξ± Ξ² : Type v} [DecidableEq Ξ±]
variable {M : Matrix n n R}
namespace Matrix
theorem charmatrix_apply_natDegree [Nontrivial R] (i j : n) :
(charmatrix M i j).natDegree = ite (i = j) 1 0 := by
by_cases h : i = j <;> simp [h, β degree_eq_iff_natDegree_eq_of_pos (Nat.succ_pos 0)]
theorem charmatrix_apply_natDegree_le (i j : n) :
(charmatrix M i j).natDegree β€ ite (i = j) 1 0 := by
split_ifs with h <;> simp [h, natDegree_X_le]
variable (M)
theorem charpoly_sub_diagonal_degree_lt :
(M.charpoly - β i : n, (X - C (M i i))).degree < β(Fintype.card n - 1) := by
rw [charpoly, det_apply', β insert_erase (mem_univ (Equiv.refl n)),
sum_insert (not_mem_erase (Equiv.refl n) univ), add_comm]
simp only [charmatrix_apply_eq, one_mul, Equiv.Perm.sign_refl, id, Int.cast_one,
Units.val_one, add_sub_cancel_right, Equiv.coe_refl]
rw [β mem_degreeLT]
apply Submodule.sum_mem (degreeLT R (Fintype.card n - 1))
intro c hc; rw [β C_eq_intCast, C_mul']
apply Submodule.smul_mem (degreeLT R (Fintype.card n - 1)) ββ(Equiv.Perm.sign c)
rw [mem_degreeLT]
apply lt_of_le_of_lt degree_le_natDegree _
rw [Nat.cast_lt]
apply lt_of_le_of_lt _ (Equiv.Perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc))
apply le_trans (Polynomial.natDegree_prod_le univ fun i : n => charmatrix M (c i) i) _
rw [card_eq_sum_ones]; rw [sum_filter]; apply sum_le_sum
intros
apply charmatrix_apply_natDegree_le
theorem charpoly_coeff_eq_prod_coeff_of_le {k : β} (h : Fintype.card n - 1 β€ k) :
M.charpoly.coeff k = (β i : n, (X - C (M i i))).coeff k := by
apply eq_of_sub_eq_zero; rw [β coeff_sub]
apply Polynomial.coeff_eq_zero_of_degree_lt
apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) ?_
rw [Nat.cast_le]; apply h
theorem det_of_card_zero (h : Fintype.card n = 0) (M : Matrix n n R) : M.det = 1 := by
rw [Fintype.card_eq_zero_iff] at h
suffices M = 1 by simp [this]
ext i
exact h.elim i
theorem charpoly_degree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.degree = Fintype.card n := by
by_cases h : Fintype.card n = 0
Β· rw [h]
unfold charpoly
rw [det_of_card_zero]
Β· simp
Β· assumption
rw [β sub_add_cancel M.charpoly (β i : n, (X - C (M i i)))]
-- Porting note: added `β` in front of `Fintype.card n`
have h1 : (β i : n, (X - C (M i i))).degree = β(Fintype.card n) := by
rw [degree_eq_iff_natDegree_eq_of_pos (Nat.pos_of_ne_zero h), natDegree_prod']
Β· simp_rw [natDegree_X_sub_C]
rw [β Finset.card_univ, sum_const, smul_eq_mul, mul_one]
simp_rw [(monic_X_sub_C _).leadingCoeff]
simp
rw [degree_add_eq_right_of_degree_lt]
Β· exact h1
rw [h1]
apply lt_trans (charpoly_sub_diagonal_degree_lt M)
rw [Nat.cast_lt]
rw [β Nat.pred_eq_sub_one]
apply Nat.pred_lt
apply h
@[simp] theorem charpoly_natDegree_eq_dim [Nontrivial R] (M : Matrix n n R) :
M.charpoly.natDegree = Fintype.card n :=
natDegree_eq_of_degree_eq_some (charpoly_degree_eq_dim M)
theorem charpoly_monic (M : Matrix n n R) : M.charpoly.Monic := by
nontriviality R
by_cases h : Fintype.card n = 0
Β· rw [charpoly, det_of_card_zero h]
apply monic_one
have mon : (β i : n, (X - C (M i i))).Monic := by
apply monic_prod_of_monic univ fun i : n => X - C (M i i)
simp [monic_X_sub_C]
rw [β sub_add_cancel (β i : n, (X - C (M i i))) M.charpoly] at mon
rw [Monic] at *
rwa [leadingCoeff_add_of_degree_lt] at mon
rw [charpoly_degree_eq_dim]
rw [β neg_sub]
rw [degree_neg]
apply lt_trans (charpoly_sub_diagonal_degree_lt M)
rw [Nat.cast_lt]
rw [β Nat.pred_eq_sub_one]
apply Nat.pred_lt
apply h
/-- See also `Matrix.coeff_charpolyRev_eq_neg_trace`. -/
theorem trace_eq_neg_charpoly_coeff [Nonempty n] (M : Matrix n n R) :
trace M = -M.charpoly.coeff (Fintype.card n - 1) := by
rw [charpoly_coeff_eq_prod_coeff_of_le _ le_rfl, Fintype.card,
prod_X_sub_C_coeff_card_pred univ (fun i : n => M i i) Fintype.card_pos, neg_neg, trace]
simp_rw [diag_apply]
theorem matPolyEquiv_symm_map_eval (M : (Matrix n n R)[X]) (r : R) :
(matPolyEquiv.symm M).map (eval r) = M.eval (scalar n r) := by
suffices ((aeval r).mapMatrix.comp matPolyEquiv.symm.toAlgHom : (Matrix n n R)[X] ββ[R] _) =
(evalβAlgHom' (AlgHom.id R _) (scalar n r)
fun x => (scalar_commute _ (Commute.all _) _).symm) from
DFunLike.congr_fun this M
ext : 1
Β· ext M : 1
simp [Function.comp_def]
Β· simp [smul_eq_diagonal_mul]
theorem matPolyEquiv_eval_eq_map (M : Matrix n n R[X]) (r : R) :
| (matPolyEquiv M).eval (scalar n r) = M.map (eval r) := by
simpa only [AlgEquiv.symm_apply_apply] using (matPolyEquiv_symm_map_eval (matPolyEquiv M) r).symm
-- I feel like this should use `Polynomial.algHom_evalβ_algebraMap`
theorem matPolyEquiv_eval (M : Matrix n n R[X]) (r : R) (i j : n) :
(matPolyEquiv M).eval (scalar n r) i j = (M i j).eval r := by
rw [matPolyEquiv_eval_eq_map, map_apply]
theorem eval_det (M : Matrix n n R[X]) (r : R) :
Polynomial.eval r M.det = (Polynomial.eval (scalar n r) (matPolyEquiv M)).det := by
| Mathlib/LinearAlgebra/Matrix/Charpoly/Coeff.lean | 156 | 165 |
/-
Copyright (c) 2022 Praneeth Kolichala. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Praneeth Kolichala
-/
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Nat.BinaryRec
import Mathlib.Data.List.Defs
import Mathlib.Tactic.Convert
import Mathlib.Tactic.GeneralizeProofs
import Mathlib.Tactic.Says
/-!
# Additional properties of binary recursion on `Nat`
This file documents additional properties of binary recursion,
which allows us to more easily work with operations which do depend
on the number of leading zeros in the binary representation of `n`.
For example, we can more easily work with `Nat.bits` and `Nat.size`.
See also: `Nat.bitwise`, `Nat.pow` (for various lemmas about `size` and `shiftLeft`/`shiftRight`),
and `Nat.digits`.
-/
assert_not_exists Monoid
-- Once we're in the `Nat` namespace, `xor` will inconveniently resolve to `Nat.xor`.
/-- `bxor` denotes the `xor` function i.e. the exclusive-or function on type `Bool`. -/
local notation "bxor" => xor
namespace Nat
universe u
variable {m n : β}
/-- `boddDiv2 n` returns a 2-tuple of type `(Bool, Nat)` where the `Bool` value indicates whether
`n` is odd or not and the `Nat` value returns `βn/2β` -/
def boddDiv2 : β β Bool Γ β
| 0 => (false, 0)
| succ n =>
match boddDiv2 n with
| (false, m) => (true, m)
| (true, m) => (false, succ m)
/-- `div2 n = βn/2β` the greatest integer smaller than `n/2` -/
def div2 (n : β) : β := (boddDiv2 n).2
/-- `bodd n` returns `true` if `n` is odd -/
def bodd (n : β) : Bool := (boddDiv2 n).1
@[simp] lemma bodd_zero : bodd 0 = false := rfl
@[simp] lemma bodd_one : bodd 1 = true := rfl
lemma bodd_two : bodd 2 = false := rfl
@[simp]
lemma bodd_succ (n : β) : bodd (succ n) = not (bodd n) := by
simp only [bodd, boddDiv2]
let β¨b,mβ© := boddDiv2 n
cases b <;> rfl
@[simp]
lemma bodd_add (m n : β) : bodd (m + n) = bxor (bodd m) (bodd n) := by
induction n
case zero => simp
case succ n ih => simp [β Nat.add_assoc, Bool.xor_not, ih]
@[simp]
lemma bodd_mul (m n : β) : bodd (m * n) = (bodd m && bodd n) := by
induction n with
| zero => simp
| succ n IH =>
simp only [mul_succ, bodd_add, IH, bodd_succ]
cases bodd m <;> cases bodd n <;> rfl
lemma mod_two_of_bodd (n : β) : n % 2 = (bodd n).toNat := by
have := congr_arg bodd (mod_add_div n 2)
simp? [not] at this says
simp only [bodd_add, bodd_mul, bodd_succ, not, bodd_zero, Bool.false_and, Bool.bne_false]
at this
have _ : β b, and false b = false := by
intro b
cases b <;> rfl
have _ : β b, bxor b false = b := by
intro b
cases b <;> rfl
rw [β this]
rcases mod_two_eq_zero_or_one n with h | h <;> rw [h] <;> rfl
@[simp] lemma div2_zero : div2 0 = 0 := rfl
@[simp] lemma div2_one : div2 1 = 0 := rfl
lemma div2_two : div2 2 = 1 := rfl
@[simp]
lemma div2_succ (n : β) : div2 (n + 1) = cond (bodd n) (succ (div2 n)) (div2 n) := by
simp only [bodd, boddDiv2, div2]
rcases boddDiv2 n with β¨_|_, _β© <;> simp
attribute [local simp] Nat.add_comm Nat.add_assoc Nat.add_left_comm Nat.mul_comm Nat.mul_assoc
lemma bodd_add_div2 : β n, (bodd n).toNat + 2 * div2 n = n
| 0 => rfl
| succ n => by
simp only [bodd_succ, Bool.cond_not, div2_succ, Nat.mul_comm]
refine Eq.trans ?_ (congr_arg succ (bodd_add_div2 n))
cases bodd n
Β· simp
Β· simp; omega
lemma div2_val (n) : div2 n = n / 2 := by
refine Nat.eq_of_mul_eq_mul_left (by decide)
(Nat.add_left_cancel (Eq.trans ?_ (Nat.mod_add_div n 2).symm))
rw [mod_two_of_bodd, bodd_add_div2]
lemma bit_decomp (n : Nat) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans <| (Nat.add_comm _ _).trans <| bodd_add_div2 _
lemma bit_zero : bit false 0 = 0 :=
rfl
/-- `shiftLeft' b m n` performs a left shift of `m` `n` times
and adds the bit `b` as the least significant bit each time.
Returns the corresponding natural number -/
def shiftLeft' (b : Bool) (m : β) : β β β
| 0 => m
| n + 1 => bit b (shiftLeft' b m n)
@[simp]
lemma shiftLeft'_false : β n, shiftLeft' false m n = m <<< n
| 0 => rfl
| n + 1 => by
have : 2 * (m * 2^n) = 2^(n+1)*m := by
rw [Nat.mul_comm, Nat.mul_assoc, β Nat.pow_succ]; simp
simp [shiftLeft_eq, shiftLeft', bit_val, shiftLeft'_false, this]
/-- Lean takes the unprimed name for `Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n`. -/
@[simp] lemma shiftLeft_eq' (m n : Nat) : shiftLeft m n = m <<< n := rfl
@[simp] lemma shiftRight_eq (m n : Nat) : shiftRight m n = m >>> n := rfl
lemma binaryRec_decreasing (h : n β 0) : div2 n < n := by
rw [div2_val]
apply (div_lt_iff_lt_mul <| succ_pos 1).2
have := Nat.mul_lt_mul_of_pos_left (lt_succ_self 1)
(lt_of_le_of_ne n.zero_le h.symm)
rwa [Nat.mul_one] at this
/-- `size n` : Returns the size of a natural number in
bits i.e. the length of its binary representation -/
def size : β β β :=
binaryRec 0 fun _ _ => succ
/-- `bits n` returns a list of Bools which correspond to the binary representation of n, where
the head of the list represents the least significant bit -/
def bits : β β List Bool :=
binaryRec [] fun b _ IH => b :: IH
/-- `ldiff a b` performs bitwise set difference. For each corresponding
pair of bits taken as booleans, say `aα΅’` and `bα΅’`, it applies the
boolean operation `aα΅’ β§ Β¬bα΅’` to obtain the `iα΅Κ°` bit of the result. -/
def ldiff : β β β β β :=
bitwise fun a b => a && not b
/-! bitwise ops -/
lemma bodd_bit (b n) : bodd (bit b n) = b := by
rw [bit_val]
simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
Bool.not_true, Bool.and_false, Bool.xor_false]
cases b <;> cases bodd n <;> rfl
lemma div2_bit (b n) : div2 (bit b n) = n := by
rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
<;> cases b
<;> decide
lemma shiftLeft'_add (b m n) : β k, shiftLeft' b m (n + k) = shiftLeft' b (shiftLeft' b m n) k
| 0 => rfl
| k + 1 => congr_arg (bit b) (shiftLeft'_add b m n k)
lemma shiftLeft'_sub (b m) : β {n k}, k β€ n β shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k
| _, 0, _ => rfl
| n + 1, k + 1, h => by
rw [succ_sub_succ_eq_sub, shiftLeft', Nat.add_comm, shiftRight_add]
simp only [shiftLeft'_sub, Nat.le_of_succ_le_succ h, shiftRight_succ, shiftRight_zero]
simp [β div2_val, div2_bit]
lemma shiftLeft_sub : β (m : Nat) {n k}, k β€ n β m <<< (n - k) = (m <<< n) >>> k :=
fun _ _ _ hk => by simp only [β shiftLeft'_false, shiftLeft'_sub false _ hk]
lemma bodd_eq_one_and_ne_zero : β n, bodd n = (1 &&& n != 0)
| 0 => rfl
| 1 => rfl
| n + 2 => by simpa using bodd_eq_one_and_ne_zero n
lemma testBit_bit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
simp only [shiftRight_eq_div_pow]
simp [β div2_val, div2_bit]
rw [β shiftRight_add, Nat.add_comm] at this
simp only [bodd_eq_one_and_ne_zero] at this
exact this
/-! ### `boddDiv2_eq` and `bodd` -/
@[simp]
theorem boddDiv2_eq (n : β) : boddDiv2 n = (bodd n, div2 n) := rfl
@[simp]
theorem div2_bit0 (n) : div2 (2 * n) = n :=
div2_bit false n
-- simp can prove this
theorem div2_bit1 (n) : div2 (2 * n + 1) = n :=
div2_bit true n
/-! ### `bit0` and `bit1` -/
theorem bit_add : β (b : Bool) (n m : β), bit b (n + m) = bit false n + bit b m
| true, _, _ => by dsimp [bit]; omega
| false, _, _ => by dsimp [bit]; omega
theorem bit_add' : β (b : Bool) (n m : β), bit b (n + m) = bit b n + bit false m
| true, _, _ => by dsimp [bit]; omega
| false, _, _ => by dsimp [bit]; omega
theorem bit_ne_zero (b) {n} (h : n β 0) : bit b n β 0 := by
cases b <;> dsimp [bit] <;> omega
@[simp]
theorem bitCasesOn_bit0 {motive : β β Sort u} (H : β b n, motive (bit b n)) (n : β) :
bitCasesOn (2 * n) H = H false n :=
bitCasesOn_bit H false n
@[simp]
theorem bitCasesOn_bit1 {motive : β β Sort u} (H : β b n, motive (bit b n)) (n : β) :
bitCasesOn (2 * n + 1) H = H true n :=
bitCasesOn_bit H true n
theorem bit_cases_on_injective {motive : β β Sort u} :
Function.Injective fun H : β b n, motive (bit b n) => fun n => bitCasesOn n H := by
intro Hβ Hβ h
ext b n
simpa only [bitCasesOn_bit] using congr_fun h (bit b n)
@[simp]
theorem bit_cases_on_inj {motive : β β Sort u} (Hβ Hβ : β b n, motive (bit b n)) :
((fun n => bitCasesOn n Hβ) = fun n => bitCasesOn n Hβ) β Hβ = Hβ :=
bit_cases_on_injective.eq_iff
lemma bit_le : β (b : Bool) {m n : β}, m β€ n β bit b m β€ bit b n
| true, _, _, h => by dsimp [bit]; omega
| false, _, _, h => by dsimp [bit]; omega
lemma bit_lt_bit (a b) (h : m < n) : bit a m < bit b n := calc
bit a m < 2 * n := by cases a <;> dsimp [bit] <;> omega
_ β€ bit b n := by cases b <;> dsimp [bit] <;> omega
@[simp]
theorem zero_bits : bits 0 = [] := by simp [Nat.bits]
@[simp]
theorem bits_append_bit (n : β) (b : Bool) (hn : n = 0 β b = true) :
(bit b n).bits = b :: n.bits := by
rw [Nat.bits, Nat.bits, binaryRec_eq]
simpa
@[simp]
theorem bit0_bits (n : β) (hn : n β 0) : (2 * n).bits = false :: n.bits :=
bits_append_bit n false fun hn' => absurd hn' hn
@[simp]
theorem bit1_bits (n : β) : (2 * n + 1).bits = true :: n.bits :=
bits_append_bit n true fun _ => rfl
@[simp]
theorem one_bits : Nat.bits 1 = [true] := by
convert bit1_bits 0
simp
-- TODO Find somewhere this can live.
-- example : bits 3423 = [true, true, true, true, true, false, true, false, true, false, true, true]
-- := by norm_num
theorem bodd_eq_bits_head (n : β) : n.bodd = n.bits.headI := by
induction n using Nat.binaryRec' with
| z => simp
| f _ _ h _ => simp [bodd_bit, bits_append_bit _ _ h]
theorem div2_bits_eq_tail (n : β) : n.div2.bits = n.bits.tail := by
induction n using Nat.binaryRec' with
| z => simp
| f _ _ h _ => simp [div2_bit, bits_append_bit _ _ h]
end Nat
| Mathlib/Data/Nat/Bits.lean | 546 | 560 | |
/-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Bilinear
import Mathlib.Algebra.Algebra.Opposite
import Mathlib.Algebra.Group.Pointwise.Finset.Basic
import Mathlib.Algebra.Group.Pointwise.Set.BigOperators
import Mathlib.Algebra.Module.Submodule.Pointwise
import Mathlib.Algebra.Ring.NonZeroDivisors
import Mathlib.Algebra.Ring.Submonoid.Pointwise
import Mathlib.Data.Set.Semiring
import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise
/-!
# Multiplication and division of submodules of an algebra.
An interface for multiplication and division of sub-R-modules of an R-algebra A is developed.
## Main definitions
Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra.
* `1 : Submodule R A` : the R-submodule R of the R-algebra A
* `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
the smallest submodule containing all the products `m * n`.
* `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such
that `a β’ J β I`
It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`.
Additionally, in the `Pointwise` locale we promote `Submodule.pointwiseDistribMulAction` to a
`MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`.
When `R` is not necessarily commutative, and `A` is merely a `R`-module with a ring structure
such that `IsScalarTower R A A` holds (equivalent to the data of a ring homomorphism `R β+* A`
by `ringHomEquivModuleIsScalarTower`), we can still define `1 : Submodule R A` and
`Mul (Submodule R A)`, but `1` is only a left identity, not necessarily a right one.
## Tags
multiplication of submodules, division of submodules, submodule semiring
-/
universe uΞΉ u v
open Algebra Set MulOpposite
open Pointwise
namespace SubMulAction
variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A]
theorem algebraMap_mem (r : R) : algebraMap R A r β (1 : SubMulAction R A) :=
β¨r, (algebraMap_eq_smul_one r).symmβ©
theorem mem_one' {x : A} : x β (1 : SubMulAction R A) β β y, algebraMap R A y = x :=
exists_congr fun r => by rw [algebraMap_eq_smul_one]
end SubMulAction
namespace Submodule
section Module
variable {R : Type u} [Semiring R] {A : Type v} [Semiring A] [Module R A]
-- TODO: Why is this in a file about `Algebra`?
-- TODO: potentially change this back to `LinearMap.range (Algebra.linearMap R A)`
-- once a version of `Algebra` without the `commutes'` field is introduced.
-- See issue https://github.com/leanprover-community/mathlib4/issues/18110.
/-- `1 : Submodule R A` is the submodule `R β 1` of `A`.
-/
instance one : One (Submodule R A) :=
β¨LinearMap.range (LinearMap.toSpanSingleton R A 1)β©
theorem one_eq_span : (1 : Submodule R A) = R β 1 :=
(LinearMap.span_singleton_eq_range _ _ _).symm
theorem le_one_toAddSubmonoid : 1 β€ (1 : Submodule R A).toAddSubmonoid := by
rintro x β¨n, rflβ©
exact β¨n, show (n : R) β’ (1 : A) = n by rw [Nat.cast_smul_eq_nsmul, nsmul_one]β©
@[simp]
theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 :=
SetLike.ext fun _ β¦ by rw [one_eq_span, SubMulAction.mem_one]; exact mem_span_singleton
theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 :=
one_eq_span
@[simp]
theorem one_le {P : Submodule R A} : (1 : Submodule R A) β€ P β (1 : A) β P := by
simp [one_eq_span]
variable {M : Type*} [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M]
instance : SMul (Submodule R A) (Submodule R M) where
smul A' M' :=
{ __ := A'.toAddSubmonoid β’ M'.toAddSubmonoid
smul_mem' := fun r m hm β¦ AddSubmonoid.smul_induction_on hm
(fun a ha m hm β¦ by rw [β smul_assoc]; exact AddSubmonoid.smul_mem_smul (A'.smul_mem r ha) hm)
fun mβ mβ hβ hβ β¦ by rw [smul_add]; exact (A'.1 β’ M'.1).add_mem hβ hβ }
section
variable {I J : Submodule R A} {N P : Submodule R M}
theorem smul_toAddSubmonoid : (I β’ N).toAddSubmonoid = I.toAddSubmonoid β’ N.toAddSubmonoid := rfl
theorem smul_mem_smul {r} {n} (hr : r β I) (hn : n β N) : r β’ n β I β’ N :=
AddSubmonoid.smul_mem_smul hr hn
theorem smul_le : I β’ N β€ P β β r β I, β n β N, r β’ n β P :=
AddSubmonoid.smul_le
@[simp, norm_cast]
lemma coe_set_smul : (I : Set A) β’ N = I β’ N :=
set_smul_eq_of_le _ _ _
(fun _ _ hr hx β¦ smul_mem_smul hr hx)
(smul_le.mpr fun _ hr _ hx β¦ mem_set_smul_of_mem_mem hr hx)
@[elab_as_elim]
theorem smul_induction_on {p : M β Prop} {x} (H : x β I β’ N) (smul : β r β I, β n β N, p (r β’ n))
(add : β x y, p x β p y β p (x + y)) : p x :=
AddSubmonoid.smul_induction_on H smul add
/-- Dependent version of `Submodule.smul_induction_on`. -/
@[elab_as_elim]
theorem smul_induction_on' {x : M} (hx : x β I β’ N) {p : β x, x β I β’ N β Prop}
(smul : β (r : A) (hr : r β I) (n : M) (hn : n β N), p (r β’ n) (smul_mem_smul hr hn))
(add : β x hx y hy, p x hx β p y hy β p (x + y) (add_mem βΉ_βΊ βΉ_βΊ)) : p x hx := by
refine Exists.elim ?_ fun (h : x β I β’ N) (H : p x h) β¦ H
exact smul_induction_on hx (fun a ha x hx β¦ β¨_, smul _ ha _ hxβ©)
fun x y β¨_, hxβ© β¨_, hyβ© β¦ β¨_, add _ _ _ _ hx hyβ©
theorem smul_mono (hij : I β€ J) (hnp : N β€ P) : I β’ N β€ J β’ P :=
AddSubmonoid.smul_le_smul hij hnp
theorem smul_mono_left (h : I β€ J) : I β’ N β€ J β’ N :=
smul_mono h le_rfl
instance : CovariantClass (Submodule R A) (Submodule R M) HSMul.hSMul LE.le :=
β¨fun _ _ => smul_mono le_rflβ©
variable (I J N P)
@[simp]
theorem smul_bot : I β’ (β₯ : Submodule R M) = β₯ :=
toAddSubmonoid_injective <| AddSubmonoid.addSubmonoid_smul_bot _
@[simp]
theorem bot_smul : (β₯ : Submodule R A) β’ N = β₯ :=
le_bot_iff.mp <| smul_le.mpr <| by rintro _ rfl _ _; rw [zero_smul]; exact zero_mem _
theorem smul_sup : I β’ (N β P) = I β’ N β I β’ P :=
toAddSubmonoid_injective <| by
simp only [smul_toAddSubmonoid, sup_toAddSubmonoid, AddSubmonoid.addSubmonoid_smul_sup]
theorem sup_smul : (I β J) β’ N = I β’ N β J β’ N :=
le_antisymm (smul_le.mpr fun mn hmn p hp β¦ by
obtain β¨m, hm, n, hn, rflβ© := mem_sup.mp hmn
rw [add_smul]; exact add_mem_sup (smul_mem_smul hm hp) <| smul_mem_smul hn hp)
(sup_le (smul_mono_left le_sup_left) <| smul_mono_left le_sup_right)
protected theorem smul_assoc {B} [Semiring B] [Module R B] [Module A B] [Module B M]
[IsScalarTower R A B] [IsScalarTower R B M] [IsScalarTower A B M]
(I : Submodule R A) (J : Submodule R B) (N : Submodule R M) :
(I β’ J) β’ N = I β’ J β’ N :=
le_antisymm
(smul_le.2 fun _ hrsij t htn β¦ smul_induction_on hrsij
(fun r hr s hs β¦ smul_assoc r s t βΈ smul_mem_smul hr (smul_mem_smul hs htn))
fun x y β¦ (add_smul x y t).symm βΈ add_mem)
(smul_le.2 fun r hr _ hsn β¦ smul_induction_on hsn
(fun j hj n hn β¦ (smul_assoc r j n).symm βΈ smul_mem_smul (smul_mem_smul hr hj) hn)
fun mβ mβ β¦ (smul_add r mβ mβ) βΈ add_mem)
theorem smul_iSup {ΞΉ : Sort*} {I : Submodule R A} {t : ΞΉ β Submodule R M} :
I β’ (β¨ i, t i)= β¨ i, I β’ t i :=
toAddSubmonoid_injective <| by
simp only [smul_toAddSubmonoid, iSup_toAddSubmonoid, AddSubmonoid.smul_iSup]
theorem iSup_smul {ΞΉ : Sort*} {t : ΞΉ β Submodule R A} {N : Submodule R M} :
(β¨ i, t i) β’ N = β¨ i, t i β’ N :=
le_antisymm (smul_le.mpr fun t ht s hs β¦ iSup_induction _ (motive := (Β· β’ s β _)) ht
(fun i t ht β¦ mem_iSup_of_mem i <| smul_mem_smul ht hs)
(by simp_rw [zero_smul]; apply zero_mem) fun x y β¦ by simp_rw [add_smul]; apply add_mem)
(iSup_le fun i β¦ Submodule.smul_mono_left <| le_iSup _ i)
protected theorem one_smul : (1 : Submodule R A) β’ N = N := by
refine le_antisymm (smul_le.mpr fun r hr m hm β¦ ?_) fun m hm β¦ ?_
Β· obtain β¨r, rflβ© := hr
rw [LinearMap.toSpanSingleton_apply, smul_one_smul]; exact N.smul_mem r hm
Β· rw [β one_smul A m]; exact smul_mem_smul (one_le.mp le_rfl) hm
theorem smul_subset_smul : (βI : Set A) β’ (βN : Set M) β (β(I β’ N) : Set M) :=
AddSubmonoid.smul_subset_smul
end
variable [IsScalarTower R A A]
/-- Multiplication of sub-R-modules of an R-module A that is also a semiring. The submodule `M * N`
consists of finite sums of elements `m * n` for `m β M` and `n β N`. -/
instance mul : Mul (Submodule R A) where
mul := (Β· β’ Β·)
variable (S T : Set A) {M N P Q : Submodule R A} {m n : A}
theorem mul_mem_mul (hm : m β M) (hn : n β N) : m * n β M * N :=
smul_mem_smul hm hn
theorem mul_le : M * N β€ P β β m β M, β n β N, m * n β P :=
smul_le
theorem mul_toAddSubmonoid (M N : Submodule R A) :
(M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := rfl
@[elab_as_elim]
protected theorem mul_induction_on {C : A β Prop} {r : A} (hr : r β M * N)
(hm : β m β M, β n β N, C (m * n)) (ha : β x y, C x β C y β C (x + y)) : C r :=
smul_induction_on hr hm ha
/-- A dependent version of `mul_induction_on`. -/
@[elab_as_elim]
protected theorem mul_induction_on' {C : β r, r β M * N β Prop}
(mem_mul_mem : β m (hm : m β M) n (hn : n β N), C (m * n) (mul_mem_mul hm hn))
(add : β x hx y hy, C x hx β C y hy β C (x + y) (add_mem hx hy)) {r : A} (hr : r β M * N) :
C r hr :=
smul_induction_on' hr mem_mul_mem add
variable (M)
@[simp]
theorem mul_bot : M * β₯ = β₯ :=
smul_bot _
@[simp]
theorem bot_mul : β₯ * M = β₯ :=
bot_smul _
protected theorem one_mul : (1 : Submodule R A) * M = M :=
Submodule.one_smul _
variable {M}
@[mono]
theorem mul_le_mul (hmp : M β€ P) (hnq : N β€ Q) : M * N β€ P * Q :=
smul_mono hmp hnq
theorem mul_le_mul_left (h : M β€ N) : M * P β€ N * P :=
smul_mono_left h
theorem mul_le_mul_right (h : N β€ P) : M * N β€ M * P :=
smul_mono_right _ h
theorem mul_comm_of_commute (h : β m β M, β n β N, Commute m n) : M * N = N * M :=
toAddSubmonoid_injective <| AddSubmonoid.mul_comm_of_commute h
variable (M N P)
theorem mul_sup : M * (N β P) = M * N β M * P :=
smul_sup _ _ _
theorem sup_mul : (M β N) * P = M * P β N * P :=
sup_smul _ _ _
theorem mul_subset_mul : (βM : Set A) * (βN : Set A) β (β(M * N) : Set A) :=
smul_subset_smul _ _
lemma restrictScalars_mul {A B C} [Semiring A] [Semiring B] [Semiring C]
[SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C]
[IsScalarTower A B C] {I J : Submodule B C} :
(I * J).restrictScalars A = I.restrictScalars A * J.restrictScalars A :=
rfl
variable {ΞΉ : Sort uΞΉ}
theorem iSup_mul (s : ΞΉ β Submodule R A) (t : Submodule R A) : (β¨ i, s i) * t = β¨ i, s i * t :=
iSup_smul
theorem mul_iSup (t : Submodule R A) (s : ΞΉ β Submodule R A) : (t * β¨ i, s i) = β¨ i, t * s i :=
smul_iSup
/-- Sub-`R`-modules of an `R`-module form an idempotent semiring. -/
instance : NonUnitalSemiring (Submodule R A) where
__ := toAddSubmonoid_injective.semigroup _ mul_toAddSubmonoid
zero_mul := bot_mul
mul_zero := mul_bot
left_distrib := mul_sup
right_distrib := sup_mul
instance : Pow (Submodule R A) β where
pow s n := npowRec n s
theorem pow_eq_npowRec {n : β} : M ^ n = npowRec n M := rfl
protected theorem pow_zero : M ^ 0 = 1 := rfl
protected theorem pow_succ {n : β} : M ^ (n + 1) = M ^ n * M := rfl
protected theorem pow_add {m n : β} (h : n β 0) : M ^ (m + n) = M ^ m * M ^ n :=
npowRec_add m n h _ M.one_mul
protected theorem pow_one : M ^ 1 = M := by
rw [Submodule.pow_succ, Submodule.pow_zero, Submodule.one_mul]
/-- `Submodule.pow_succ` with the right hand side commuted. -/
protected theorem pow_succ' {n : β} (h : n β 0) : M ^ (n + 1) = M * M ^ n := by
rw [add_comm, M.pow_add h, Submodule.pow_one]
theorem pow_toAddSubmonoid {n : β} (h : n β 0) : (M ^ n).toAddSubmonoid = M.toAddSubmonoid ^ n := by
induction n with
| zero => exact (h rfl).elim
| succ n ih =>
rw [Submodule.pow_succ, pow_succ, mul_toAddSubmonoid]
cases n with
| zero => rw [Submodule.pow_zero, pow_zero, one_mul, β mul_toAddSubmonoid, Submodule.one_mul]
| succ n => rw [ih n.succ_ne_zero]
theorem le_pow_toAddSubmonoid {n : β} : M.toAddSubmonoid ^ n β€ (M ^ n).toAddSubmonoid := by
obtain rfl | hn := Decidable.eq_or_ne n 0
Β· rw [Submodule.pow_zero, pow_zero]
exact le_one_toAddSubmonoid
Β· exact (pow_toAddSubmonoid M hn).ge
theorem pow_subset_pow {n : β} : (βM : Set A) ^ n β β(M ^ n : Submodule R A) :=
trans AddSubmonoid.pow_subset_pow (le_pow_toAddSubmonoid M)
theorem pow_mem_pow {x : A} (hx : x β M) (n : β) : x ^ n β M ^ n :=
pow_subset_pow _ <| Set.pow_mem_pow hx
lemma restrictScalars_pow {A B C : Type*} [Semiring A] [Semiring B]
[Semiring C] [SMul A B] [Module A C] [Module B C]
[IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C]
{I : Submodule B C} :
β {n : β}, (hn : n β 0) β (I ^ n).restrictScalars A = I.restrictScalars A ^ n
| 1, _ => by simp [Submodule.pow_one]
| n + 2, _ => by
simp [Submodule.pow_succ (n := n + 1), restrictScalars_mul, restrictScalars_pow n.succ_ne_zero]
end Module
|
variable {ΞΉ : Sort uΞΉ}
variable {R : Type u} [CommSemiring R]
section AlgebraSemiring
variable {A : Type v} [Semiring A] [Algebra R A]
variable (S T : Set A) {M N P Q : Submodule R A} {m n : A}
| Mathlib/Algebra/Algebra/Operations.lean | 345 | 353 |
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.FinitePresentation
import Mathlib.RingTheory.FiniteStability
import Mathlib.RingTheory.Ideal.Cotangent
import Mathlib.RingTheory.Ideal.Quotient.Nilpotent
import Mathlib.RingTheory.Localization.Away.AdjoinRoot
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# Smooth morphisms
An `R`-algebra `A` is formally smooth if for every `R`-algebra,
every square-zero ideal `I : Ideal B` and `f : A ββ[R] B β§Έ I`, there exists
at least one lift `A ββ[R] B`.
It is smooth if it is formally smooth and of finite presentation.
We show that the property of being formally smooth extends onto nilpotent ideals,
and that it is stable under `R`-algebra homomorphisms and compositions.
We show that smooth is stable under algebra isomorphisms, composition and
localization at an element.
-/
-- Porting note: added to make the syntax work below.
open scoped TensorProduct
universe u
namespace Algebra
section
variable (R : Type u) [CommSemiring R]
variable (A : Type u) [Semiring A] [Algebra R A]
/-- An `R` algebra `A` is formally smooth if for every `R`-algebra, every square-zero ideal
`I : Ideal B` and `f : A ββ[R] B β§Έ I`, there exists at least one lift `A ββ[R] B`. -/
@[mk_iff, stacks 00TI]
class FormallySmooth : Prop where
comp_surjective :
β β¦B : Type uβ¦ [CommRing B],
β [Algebra R B] (I : Ideal B) (_ : I ^ 2 = β₯),
Function.Surjective ((Ideal.Quotient.mkβ R I).comp : (A ββ[R] B) β A ββ[R] B β§Έ I)
end
namespace FormallySmooth
section
variable {R : Type u} [CommSemiring R]
variable {A : Type u} [Semiring A] [Algebra R A]
variable {B : Type u} [CommRing B] [Algebra R B]
theorem exists_lift {B : Type u} [CommRing B] [_RB : Algebra R B]
[FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I) (g : A ββ[R] B β§Έ I) :
β f : A ββ[R] B, (Ideal.Quotient.mkβ R I).comp f = g := by
revert g
change Function.Surjective (Ideal.Quotient.mkβ R I).comp
revert _RB
apply Ideal.IsNilpotent.induction_on (S := B) I hI
Β· intro B _ I hI _; exact FormallySmooth.comp_surjective I hI
Β· intro B _ I J hIJ hβ hβ _ g
let this : ((B β§Έ I) β§Έ J.map (Ideal.Quotient.mk I)) ββ[R] B β§Έ J :=
{
(DoubleQuot.quotQuotEquivQuotSup I J).trans
(Ideal.quotEquivOfEq (sup_eq_right.mpr hIJ)) with
commutes' := fun x => rfl }
obtain β¨g', eβ© := hβ (this.symm.toAlgHom.comp g)
obtain β¨g', rflβ© := hβ g'
replace e := congr_arg this.toAlgHom.comp e
conv_rhs at e =>
rw [β AlgHom.comp_assoc, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_eq_coe,
AlgEquiv.comp_symm, AlgHom.id_comp]
exact β¨g', eβ©
/-- For a formally smooth `R`-algebra `A` and a map `f : A ββ[R] B β§Έ I` with `I` square-zero,
this is an arbitrary lift `A ββ[R] B`. -/
noncomputable def lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A ββ[R] B β§Έ I) : A ββ[R] B :=
(FormallySmooth.exists_lift I hI g).choose
@[simp]
theorem comp_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A ββ[R] B β§Έ I) : (Ideal.Quotient.mkβ R I).comp (FormallySmooth.lift I hI g) = g :=
(FormallySmooth.exists_lift I hI g).choose_spec
@[simp]
theorem mk_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A ββ[R] B β§Έ I) (x : A) : Ideal.Quotient.mk I (FormallySmooth.lift I hI g x) = g x :=
AlgHom.congr_fun (FormallySmooth.comp_lift I hI g :) x
variable {C : Type u} [CommRing C] [Algebra R C]
/-- For a formally smooth `R`-algebra `A` and a map `f : A ββ[R] B β§Έ I` with `I` nilpotent,
this is an arbitrary lift `A ββ[R] B`. -/
noncomputable def liftOfSurjective [FormallySmooth R A] (f : A ββ[R] C)
(g : B ββ[R] C) (hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B β+* C)) :
A ββ[R] B :=
FormallySmooth.lift _ hg' ((Ideal.quotientKerAlgEquivOfSurjective hg).symm.toAlgHom.comp f)
@[simp]
theorem liftOfSurjective_apply [FormallySmooth R A] (f : A ββ[R] C) (g : B ββ[R] C)
(hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker g) (x : A) :
g (FormallySmooth.liftOfSurjective f g hg hg' x) = f x := by
apply (Ideal.quotientKerAlgEquivOfSurjective hg).symm.injective
conv_rhs => rw [β AlgHom.coe_coe, β AlgHom.comp_apply, β FormallySmooth.mk_lift (A := A) _ hg']
apply (Ideal.quotientKerAlgEquivOfSurjective hg).injective
rw [AlgEquiv.apply_symm_apply, Ideal.quotientKerAlgEquivOfSurjective_apply]
simp only [liftOfSurjective, β RingHom.ker_coe_toRingHom g, RingHom.kerLift_mk,
AlgEquiv.toAlgHom_eq_coe, RingHom.coe_coe]
@[simp]
theorem comp_liftOfSurjective [FormallySmooth R A] (f : A ββ[R] C) (g : B ββ[R] C)
(hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B β+* C)) :
g.comp (FormallySmooth.liftOfSurjective f g hg hg') = f :=
AlgHom.ext (FormallySmooth.liftOfSurjective_apply f g hg hg')
end
section OfEquiv
variable {R : Type u} [CommSemiring R]
variable {A B : Type u} [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
theorem of_equiv [FormallySmooth R A] (e : A ββ[R] B) : FormallySmooth R B := by
constructor
intro C _ _ I hI f
use (FormallySmooth.lift I β¨2, hIβ© (f.comp e : A ββ[R] C β§Έ I)).comp e.symm
rw [β AlgHom.comp_assoc, FormallySmooth.comp_lift, AlgHom.comp_assoc, AlgEquiv.comp_symm,
AlgHom.comp_id]
theorem iff_of_equiv (e : A ββ[R] B) : FormallySmooth R A β FormallySmooth R B :=
β¨fun _ β¦ of_equiv e, fun _ β¦ of_equiv e.symmβ©
end OfEquiv
section Polynomial
open scoped Polynomial
|
variable (R : Type u) [CommSemiring R]
instance mvPolynomial (Ο : Type u) : FormallySmooth R (MvPolynomial Ο R) := by
constructor
intro C _ _ I _ f
| Mathlib/RingTheory/Smooth/Basic.lean | 148 | 153 |
/-
Copyright (c) 2021 RΓ©my Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne
-/
import Mathlib.MeasureTheory.Integral.FinMeasAdditive
/-!
# Extension of a linear function from indicators to L1
Given `T : Set Ξ± β E βL[β] F` with `DominatedFinMeasAdditive ΞΌ T C`, we construct an extension
of `T` to integrable simple functions, which are finite sums of indicators of measurable sets
with finite measure, then to integrable functions, which are limits of integrable simple functions.
The main result is a continuous linear map `(Ξ± ββ[ΞΌ] E) βL[β] F`.
This extension process is used to define the Bochner integral
in the `Mathlib.MeasureTheory.Integral.Bochner.Basic` file
and the conditional expectation of an integrable function
in `Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1`.
## Main definitions
- `setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) : (Ξ± ββ[ΞΌ] E) βL[β] F`: the extension of `T`
from indicators to L1.
- `setToFun ΞΌ T (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± β E) : F`: a version of the
extension which applies to functions (with value 0 if the function is not integrable).
## Properties
For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on
all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on
measurable sets with finite measure, like `β s, MeasurableSet s β ΞΌ s < β β T s = T' s`.
The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details.
Linearity:
- `setToFun_zero_left : setToFun ΞΌ 0 hT f = 0`
- `setToFun_add_left : setToFun ΞΌ (T + T') _ f = setToFun ΞΌ T hT f + setToFun ΞΌ T' hT' f`
- `setToFun_smul_left : setToFun ΞΌ (fun s β¦ c β’ (T s)) (hT.smul c) f = c β’ setToFun ΞΌ T hT f`
- `setToFun_zero : setToFun ΞΌ T hT (0 : Ξ± β E) = 0`
- `setToFun_neg : setToFun ΞΌ T hT (-f) = - setToFun ΞΌ T hT f`
If `f` and `g` are integrable:
- `setToFun_add : setToFun ΞΌ T hT (f + g) = setToFun ΞΌ T hT f + setToFun ΞΌ T hT g`
- `setToFun_sub : setToFun ΞΌ T hT (f - g) = setToFun ΞΌ T hT f - setToFun ΞΌ T hT g`
If `T` is verifies `β c : π, β s x, T s (c β’ x) = c β’ T s x`:
- `setToFun_smul : setToFun ΞΌ T hT (c β’ f) = c β’ setToFun ΞΌ T hT f`
Other:
- `setToFun_congr_ae (h : f =α΅[ΞΌ] g) : setToFun ΞΌ T hT f = setToFun ΞΌ T hT g`
- `setToFun_measure_zero (h : ΞΌ = 0) : setToFun ΞΌ T hT f = 0`
If the space is also an ordered additive group with an order closed topology and `T` is such that
`0 β€ T s x` for `0 β€ x`, we also prove order-related properties:
- `setToFun_mono_left (h : β s x, T s x β€ T' s x) : setToFun ΞΌ T hT f β€ setToFun ΞΌ T' hT' f`
- `setToFun_nonneg (hf : 0 β€α΅[ΞΌ] f) : 0 β€ setToFun ΞΌ T hT f`
- `setToFun_mono (hfg : f β€α΅[ΞΌ] g) : setToFun ΞΌ T hT f β€ setToFun ΞΌ T hT g`
-/
noncomputable section
open scoped Topology NNReal
open Set Filter TopologicalSpace ENNReal
namespace MeasureTheory
variable {Ξ± E F F' G π : Type*} [NormedAddCommGroup E] [NormedSpace β E]
[NormedAddCommGroup F] [NormedSpace β F] [NormedAddCommGroup F'] [NormedSpace β F']
[NormedAddCommGroup G] {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±}
namespace L1
open AEEqFun Lp.simpleFunc Lp
namespace SimpleFunc
theorem norm_eq_sum_mul (f : Ξ± βββ[ΞΌ] G) :
βfβ = β x β (toSimpleFunc f).range, ΞΌ.real (toSimpleFunc f β»ΒΉ' {x}) * βxβ := by
rw [norm_toSimpleFunc, eLpNorm_one_eq_lintegral_enorm]
have h_eq := SimpleFunc.map_apply (βΒ·ββ) (toSimpleFunc f)
simp_rw [β h_eq, measureReal_def]
rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum]
Β· congr
ext1 x
rw [ENNReal.toReal_mul, mul_comm, β ofReal_norm_eq_enorm,
ENNReal.toReal_ofReal (norm_nonneg _)]
Β· intro x _
by_cases hx0 : x = 0
Β· rw [hx0]; simp
Β· exact
ENNReal.mul_ne_top ENNReal.coe_ne_top
(SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne
section SetToL1S
variable [NormedField π] [NormedSpace π E]
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
/-- Extend `Set Ξ± β (E βL[β] F')` to `(Ξ± βββ[ΞΌ] E) β F'`. -/
def setToL1S (T : Set Ξ± β E βL[β] F) (f : Ξ± βββ[ΞΌ] E) : F :=
(toSimpleFunc f).setToSimpleFunc T
theorem setToL1S_eq_setToSimpleFunc (T : Set Ξ± β E βL[β] F) (f : Ξ± βββ[ΞΌ] E) :
setToL1S T f = (toSimpleFunc f).setToSimpleFunc T :=
rfl
@[simp]
theorem setToL1S_zero_left (f : Ξ± βββ[ΞΌ] E) : setToL1S (0 : Set Ξ± β E βL[β] F) f = 0 :=
SimpleFunc.setToSimpleFunc_zero _
theorem setToL1S_zero_left' {T : Set Ξ± β E βL[β] F}
(h_zero : β s, MeasurableSet s β ΞΌ s < β β T s = 0) (f : Ξ± βββ[ΞΌ] E) : setToL1S T f = 0 :=
SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f)
theorem setToL1S_congr (T : Set Ξ± β E βL[β] F) (h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0)
(h_add : FinMeasAdditive ΞΌ T) {f g : Ξ± βββ[ΞΌ] E} (h : toSimpleFunc f =α΅[ΞΌ] toSimpleFunc g) :
setToL1S T f = setToL1S T g :=
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h
theorem setToL1S_congr_left (T T' : Set Ξ± β E βL[β] F)
(h : β s, MeasurableSet s β ΞΌ s < β β T s = T' s) (f : Ξ± βββ[ΞΌ] E) :
setToL1S T f = setToL1S T' f :=
SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f)
/-- `setToL1S` does not change if we replace the measure `ΞΌ` by `ΞΌ'` with `ΞΌ βͺ ΞΌ'`. The statement
uses two functions `f` and `f'` because they have to belong to different types, but morally these
are the same function (we have `f =α΅[ΞΌ] f'`). -/
theorem setToL1S_congr_measure {ΞΌ' : Measure Ξ±} (T : Set Ξ± β E βL[β] F)
(h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0) (h_add : FinMeasAdditive ΞΌ T) (hΞΌ : ΞΌ βͺ ΞΌ')
(f : Ξ± βββ[ΞΌ] E) (f' : Ξ± βββ[ΞΌ'] E) (h : (f : Ξ± β E) =α΅[ΞΌ] f') :
setToL1S T f = setToL1S T f' := by
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_
refine (toSimpleFunc_eq_toFun f).trans ?_
suffices (f' : Ξ± β E) =α΅[ΞΌ] simpleFunc.toSimpleFunc f' from h.trans this
have goal' : (f' : Ξ± β E) =α΅[ΞΌ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm
exact hΞΌ.ae_eq goal'
theorem setToL1S_add_left (T T' : Set Ξ± β E βL[β] F) (f : Ξ± βββ[ΞΌ] E) :
setToL1S (T + T') f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left T T'
theorem setToL1S_add_left' (T T' T'' : Set Ξ± β E βL[β] F)
(h_add : β s, MeasurableSet s β ΞΌ s < β β T'' s = T s + T' s) (f : Ξ± βββ[ΞΌ] E) :
setToL1S T'' f = setToL1S T f + setToL1S T' f :=
SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f)
theorem setToL1S_smul_left (T : Set Ξ± β E βL[β] F) (c : β) (f : Ξ± βββ[ΞΌ] E) :
setToL1S (fun s => c β’ T s) f = c β’ setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left T c _
theorem setToL1S_smul_left' (T T' : Set Ξ± β E βL[β] F) (c : β)
(h_smul : β s, MeasurableSet s β ΞΌ s < β β T' s = c β’ T s) (f : Ξ± βββ[ΞΌ] E) :
setToL1S T' f = c β’ setToL1S T f :=
SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f)
theorem setToL1S_add (T : Set Ξ± β E βL[β] F) (h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0)
(h_add : FinMeasAdditive ΞΌ T) (f g : Ξ± βββ[ΞΌ] E) :
setToL1S T (f + g) = setToL1S T f + setToL1S T g := by
simp_rw [setToL1S]
rw [β SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f)
(SimpleFunc.integrable g)]
exact
SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _)
(add_toSimpleFunc f g)
theorem setToL1S_neg {T : Set Ξ± β E βL[β] F} (h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0)
(h_add : FinMeasAdditive ΞΌ T) (f : Ξ± βββ[ΞΌ] E) : setToL1S T (-f) = -setToL1S T f := by
simp_rw [setToL1S]
have : simpleFunc.toSimpleFunc (-f) =α΅[ΞΌ] β(-simpleFunc.toSimpleFunc f) :=
neg_toSimpleFunc f
rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this]
exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f)
theorem setToL1S_sub {T : Set Ξ± β E βL[β] F} (h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0)
(h_add : FinMeasAdditive ΞΌ T) (f g : Ξ± βββ[ΞΌ] E) :
setToL1S T (f - g) = setToL1S T f - setToL1S T g := by
rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg]
theorem setToL1S_smul_real (T : Set Ξ± β E βL[β] F)
(h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0) (h_add : FinMeasAdditive ΞΌ T) (c : β)
(f : Ξ± βββ[ΞΌ] E) : setToL1S T (c β’ f) = c β’ setToL1S T f := by
simp_rw [setToL1S]
rw [β SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace β E] [NormedSpace π E]
[DistribSMul π F] (T : Set Ξ± β E βL[β] F) (h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0)
(h_add : FinMeasAdditive ΞΌ T) (h_smul : β c : π, β s x, T s (c β’ x) = c β’ T s x) (c : π)
(f : Ξ± βββ[ΞΌ] E) : setToL1S T (c β’ f) = c β’ setToL1S T f := by
simp_rw [setToL1S]
rw [β SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)]
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact smul_toSimpleFunc c f
theorem norm_setToL1S_le (T : Set Ξ± β E βL[β] F) {C : β}
(hT_norm : β s, MeasurableSet s β ΞΌ s < β β βT sβ β€ C * ΞΌ.real s) (f : Ξ± βββ[ΞΌ] E) :
βsetToL1S T fβ β€ C * βfβ := by
rw [setToL1S, norm_eq_sum_mul f]
exact
SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm _
(SimpleFunc.integrable f)
theorem setToL1S_indicatorConst {T : Set Ξ± β E βL[β] F} {s : Set Ξ±}
(h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0) (h_add : FinMeasAdditive ΞΌ T)
(hs : MeasurableSet s) (hΞΌs : ΞΌ s < β) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 hs hΞΌs.ne x) = T s x := by
have h_empty : T β
= 0 := h_zero _ MeasurableSet.empty measure_empty
rw [setToL1S_eq_setToSimpleFunc]
refine Eq.trans ?_ (SimpleFunc.setToSimpleFunc_indicator T h_empty hs x)
refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_
exact toSimpleFunc_indicatorConst hs hΞΌs.ne x
theorem setToL1S_const [IsFiniteMeasure ΞΌ] {T : Set Ξ± β E βL[β] F}
(h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0) (h_add : FinMeasAdditive ΞΌ T) (x : E) :
setToL1S T (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top ΞΌ _) x) = T univ x :=
setToL1S_indicatorConst h_zero h_add MeasurableSet.univ (measure_lt_top _ _) x
section Order
variable {G'' G' : Type*}
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace β G']
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace β G'']
{T : Set Ξ± β G'' βL[β] G'}
theorem setToL1S_mono_left {T T' : Set Ξ± β E βL[β] G''} (hTT' : β s x, T s x β€ T' s x)
(f : Ξ± βββ[ΞΌ] E) : setToL1S T f β€ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1S_mono_left' {T T' : Set Ξ± β E βL[β] G''}
(hTT' : β s, MeasurableSet s β ΞΌ s < β β β x, T s x β€ T' s x) (f : Ξ± βββ[ΞΌ] E) :
setToL1S T f β€ setToL1S T' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G''] in
theorem setToL1S_nonneg (h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0)
(h_add : FinMeasAdditive ΞΌ T)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f : Ξ± βββ[ΞΌ] G''}
(hf : 0 β€ f) : 0 β€ setToL1S T f := by
simp_rw [setToL1S]
obtain β¨f', hf', hff'β© := exists_simpleFunc_nonneg_ae_eq hf
replace hff' : simpleFunc.toSimpleFunc f =α΅[ΞΌ] f' :=
(Lp.simpleFunc.toSimpleFunc_eq_toFun f).trans hff'
rw [SimpleFunc.setToSimpleFunc_congr _ h_zero h_add (SimpleFunc.integrable _) hff']
exact
SimpleFunc.setToSimpleFunc_nonneg' T hT_nonneg _ hf' ((SimpleFunc.integrable f).congr hff')
theorem setToL1S_mono (h_zero : β s, MeasurableSet s β ΞΌ s = 0 β T s = 0)
(h_add : FinMeasAdditive ΞΌ T)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f g : Ξ± βββ[ΞΌ] G''}
(hfg : f β€ g) : setToL1S T f β€ setToL1S T g := by
rw [β sub_nonneg] at hfg β’
rw [β setToL1S_sub h_zero h_add]
exact setToL1S_nonneg h_zero h_add hT_nonneg hfg
end Order
variable [NormedSpace π F]
variable (Ξ± E ΞΌ π)
/-- Extend `Set Ξ± β E βL[β] F` to `(Ξ± βββ[ΞΌ] E) βL[π] F`. -/
def setToL1SCLM' {T : Set Ξ± β E βL[β] F} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(h_smul : β c : π, β s x, T s (c β’ x) = c β’ T s x) : (Ξ± βββ[ΞΌ] E) βL[π] F :=
LinearMap.mkContinuous
β¨β¨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1β©,
setToL1S_smul T (fun _ => hT.eq_zero_of_measure_zero) hT.1 h_smulβ©
C fun f => norm_setToL1S_le T hT.2 f
/-- Extend `Set Ξ± β E βL[β] F` to `(Ξ± βββ[ΞΌ] E) βL[β] F`. -/
def setToL1SCLM {T : Set Ξ± β E βL[β] F} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C) :
(Ξ± βββ[ΞΌ] E) βL[β] F :=
LinearMap.mkContinuous
β¨β¨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1β©,
setToL1S_smul_real T (fun _ => hT.eq_zero_of_measure_zero) hT.1β©
C fun f => norm_setToL1S_le T hT.2 f
variable {Ξ± E ΞΌ π}
variable {T T' T'' : Set Ξ± β E βL[β] F} {C C' C'' : β}
@[simp]
theorem setToL1SCLM_zero_left (hT : DominatedFinMeasAdditive ΞΌ (0 : Set Ξ± β E βL[β] F) C)
(f : Ξ± βββ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f = 0 :=
setToL1S_zero_left _
theorem setToL1SCLM_zero_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(h_zero : β s, MeasurableSet s β ΞΌ s < β β T s = 0) (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ hT f = 0 :=
setToL1S_zero_left' h_zero f
theorem setToL1SCLM_congr_left (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : T = T') (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ hT f = setToL1SCLM Ξ± E ΞΌ hT' f :=
setToL1S_congr_left T T' (fun _ _ _ => by rw [h]) f
theorem setToL1SCLM_congr_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : β s, MeasurableSet s β ΞΌ s < β β T s = T' s)
(f : Ξ± βββ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f = setToL1SCLM Ξ± E ΞΌ hT' f :=
setToL1S_congr_left T T' h f
theorem setToL1SCLM_congr_measure {ΞΌ' : Measure Ξ±} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ' T C') (hΞΌ : ΞΌ βͺ ΞΌ') (f : Ξ± βββ[ΞΌ] E) (f' : Ξ± βββ[ΞΌ'] E)
(h : (f : Ξ± β E) =α΅[ΞΌ] f') : setToL1SCLM Ξ± E ΞΌ hT f = setToL1SCLM Ξ± E ΞΌ' hT' f' :=
setToL1S_congr_measure T (fun _ => hT.eq_zero_of_measure_zero) hT.1 hΞΌ _ _ h
theorem setToL1SCLM_add_left (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ (hT.add hT') f = setToL1SCLM Ξ± E ΞΌ hT f + setToL1SCLM Ξ± E ΞΌ hT' f :=
setToL1S_add_left T T' f
theorem setToL1SCLM_add_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (hT'' : DominatedFinMeasAdditive ΞΌ T'' C'')
(h_add : β s, MeasurableSet s β ΞΌ s < β β T'' s = T s + T' s) (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ hT'' f = setToL1SCLM Ξ± E ΞΌ hT f + setToL1SCLM Ξ± E ΞΌ hT' f :=
setToL1S_add_left' T T' T'' h_add f
theorem setToL1SCLM_smul_left (c : β) (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ (hT.smul c) f = c β’ setToL1SCLM Ξ± E ΞΌ hT f :=
setToL1S_smul_left T c f
theorem setToL1SCLM_smul_left' (c : β) (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C')
(h_smul : β s, MeasurableSet s β ΞΌ s < β β T' s = c β’ T s) (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ hT' f = c β’ setToL1SCLM Ξ± E ΞΌ hT f :=
setToL1S_smul_left' T T' c h_smul f
theorem norm_setToL1SCLM_le {T : Set Ξ± β E βL[β] F} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hC : 0 β€ C) : βsetToL1SCLM Ξ± E ΞΌ hTβ β€ C :=
LinearMap.mkContinuous_norm_le _ hC _
theorem norm_setToL1SCLM_le' {T : Set Ξ± β E βL[β] F} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C) :
βsetToL1SCLM Ξ± E ΞΌ hTβ β€ max C 0 :=
LinearMap.mkContinuous_norm_le' _ _
theorem setToL1SCLM_const [IsFiniteMeasure ΞΌ] {T : Set Ξ± β E βL[β] F} {C : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (x : E) :
setToL1SCLM Ξ± E ΞΌ hT (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top ΞΌ _) x) =
T univ x :=
setToL1S_const (fun _ => hT.eq_zero_of_measure_zero) hT.1 x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace β G'']
[NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace β G']
theorem setToL1SCLM_mono_left {T T' : Set Ξ± β E βL[β] G''} {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C')
(hTT' : β s x, T s x β€ T' s x) (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ hT f β€ setToL1SCLM Ξ± E ΞΌ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _
theorem setToL1SCLM_mono_left' {T T' : Set Ξ± β E βL[β] G''} {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C')
(hTT' : β s, MeasurableSet s β ΞΌ s < β β β x, T s x β€ T' s x) (f : Ξ± βββ[ΞΌ] E) :
setToL1SCLM Ξ± E ΞΌ hT f β€ setToL1SCLM Ξ± E ΞΌ hT' f :=
SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f)
omit [IsOrderedAddMonoid G'] in
theorem setToL1SCLM_nonneg {T : Set Ξ± β G' βL[β] G''} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f : Ξ± βββ[ΞΌ] G'}
(hf : 0 β€ f) : 0 β€ setToL1SCLM Ξ± G' ΞΌ hT f :=
setToL1S_nonneg (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf
theorem setToL1SCLM_mono {T : Set Ξ± β G' βL[β] G''} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f g : Ξ± βββ[ΞΌ] G'}
(hfg : f β€ g) : setToL1SCLM Ξ± G' ΞΌ hT f β€ setToL1SCLM Ξ± G' ΞΌ hT g :=
setToL1S_mono (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg
end Order
end SetToL1S
end SimpleFunc
open SimpleFunc
section SetToL1
attribute [local instance] Lp.simpleFunc.module
attribute [local instance] Lp.simpleFunc.normedSpace
variable (π) [NontriviallyNormedField π] [NormedSpace π E] [NormedSpace π F] [CompleteSpace F]
{T T' T'' : Set Ξ± β E βL[β] F} {C C' C'' : β}
/-- Extend `Set Ξ± β (E βL[β] F)` to `(Ξ± ββ[ΞΌ] E) βL[π] F`. -/
def setToL1' (hT : DominatedFinMeasAdditive ΞΌ T C)
(h_smul : β c : π, β s x, T s (c β’ x) = c β’ T s x) : (Ξ± ββ[ΞΌ] E) βL[π] F :=
(setToL1SCLM' Ξ± E π ΞΌ hT h_smul).extend (coeToLp Ξ± E π) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
variable {π}
/-- Extend `Set Ξ± β E βL[β] F` to `(Ξ± ββ[ΞΌ] E) βL[β] F`. -/
def setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) : (Ξ± ββ[ΞΌ] E) βL[β] F :=
(setToL1SCLM Ξ± E ΞΌ hT).extend (coeToLp Ξ± E β) (simpleFunc.denseRange one_ne_top)
simpleFunc.isUniformInducing
theorem setToL1_eq_setToL1SCLM (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± βββ[ΞΌ] E) :
setToL1 hT f = setToL1SCLM Ξ± E ΞΌ hT f :=
uniformly_extend_of_ind simpleFunc.isUniformInducing (simpleFunc.denseRange one_ne_top)
(setToL1SCLM Ξ± E ΞΌ hT).uniformContinuous _
theorem setToL1_eq_setToL1' (hT : DominatedFinMeasAdditive ΞΌ T C)
(h_smul : β c : π, β s x, T s (c β’ x) = c β’ T s x) (f : Ξ± ββ[ΞΌ] E) :
setToL1 hT f = setToL1' π hT h_smul f :=
rfl
@[simp]
theorem setToL1_zero_left (hT : DominatedFinMeasAdditive ΞΌ (0 : Set Ξ± β E βL[β] F) C)
(f : Ξ± ββ[ΞΌ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left hT f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply]
theorem setToL1_zero_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(h_zero : β s, MeasurableSet s β ΞΌ s < β β T s = 0) (f : Ξ± ββ[ΞΌ] E) : setToL1 hT f = 0 := by
suffices setToL1 hT = 0 by rw [this]; simp
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_
ext1 f
rw [setToL1SCLM_zero_left' hT h_zero f, ContinuousLinearMap.zero_comp,
ContinuousLinearMap.zero_apply]
theorem setToL1_congr_left (T T' : Set Ξ± β E βL[β] F) {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : T = T')
(f : Ξ± ββ[ΞΌ] E) : setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ hT f by rw [β this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact setToL1SCLM_congr_left hT' hT h.symm f
theorem setToL1_congr_left' (T T' : Set Ξ± β E βL[β] F) {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C')
(h : β s, MeasurableSet s β ΞΌ s < β β T s = T' s) (f : Ξ± ββ[ΞΌ] E) :
setToL1 hT f = setToL1 hT' f := by
suffices setToL1 hT = setToL1 hT' by rw [this]
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_
ext1 f
suffices setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ hT f by rw [β this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM]
exact (setToL1SCLM_congr_left' hT hT' h f).symm
theorem setToL1_add_left (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (f : Ξ± ββ[ΞΌ] E) :
setToL1 (hT.add hT') f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 (hT.add hT') = setToL1 hT + setToL1 hT' by
rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ (hT.add hT')) _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ (hT.add hT') f by
rw [β this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left hT hT']
theorem setToL1_add_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (hT'' : DominatedFinMeasAdditive ΞΌ T'' C'')
(h_add : β s, MeasurableSet s β ΞΌ s < β β T'' s = T s + T' s) (f : Ξ± ββ[ΞΌ] E) :
setToL1 hT'' f = setToL1 hT f + setToL1 hT' f := by
suffices setToL1 hT'' = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT'') _ _ _ _ ?_
ext1 f
suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ hT'' f by rw [β this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM,
setToL1SCLM_add_left' hT hT' hT'' h_add]
theorem setToL1_smul_left (hT : DominatedFinMeasAdditive ΞΌ T C) (c : β) (f : Ξ± ββ[ΞΌ] E) :
setToL1 (hT.smul c) f = c β’ setToL1 hT f := by
suffices setToL1 (hT.smul c) = c β’ setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ (hT.smul c)) _ _ _ _ ?_
ext1 f
suffices c β’ setToL1 hT f = setToL1SCLM Ξ± E ΞΌ (hT.smul c) f by rw [β this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left c hT]
theorem setToL1_smul_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (c : β)
(h_smul : β s, MeasurableSet s β ΞΌ s < β β T' s = c β’ T s) (f : Ξ± ββ[ΞΌ] E) :
setToL1 hT' f = c β’ setToL1 hT f := by
suffices setToL1 hT' = c β’ setToL1 hT by rw [this, ContinuousLinearMap.smul_apply]
refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT') _ _ _ _ ?_
ext1 f
suffices c β’ setToL1 hT f = setToL1SCLM Ξ± E ΞΌ hT' f by rw [β this]; simp [coeToLp]
rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left' c hT hT' h_smul]
theorem setToL1_smul (hT : DominatedFinMeasAdditive ΞΌ T C)
(h_smul : β c : π, β s x, T s (c β’ x) = c β’ T s x) (c : π) (f : Ξ± ββ[ΞΌ] E) :
setToL1 hT (c β’ f) = c β’ setToL1 hT f := by
rw [setToL1_eq_setToL1' hT h_smul, setToL1_eq_setToL1' hT h_smul]
exact ContinuousLinearMap.map_smul _ _ _
theorem setToL1_simpleFunc_indicatorConst (hT : DominatedFinMeasAdditive ΞΌ T C) {s : Set Ξ±}
(hs : MeasurableSet s) (hΞΌs : ΞΌ s < β) (x : E) :
setToL1 hT (simpleFunc.indicatorConst 1 hs hΞΌs.ne x) = T s x := by
rw [setToL1_eq_setToL1SCLM]
exact setToL1S_indicatorConst (fun s => hT.eq_zero_of_measure_zero) hT.1 hs hΞΌs x
theorem setToL1_indicatorConstLp (hT : DominatedFinMeasAdditive ΞΌ T C) {s : Set Ξ±}
(hs : MeasurableSet s) (hΞΌs : ΞΌ s β β) (x : E) :
setToL1 hT (indicatorConstLp 1 hs hΞΌs x) = T s x := by
rw [β Lp.simpleFunc.coe_indicatorConst hs hΞΌs x]
exact setToL1_simpleFunc_indicatorConst hT hs hΞΌs.lt_top x
theorem setToL1_const [IsFiniteMeasure ΞΌ] (hT : DominatedFinMeasAdditive ΞΌ T C) (x : E) :
setToL1 hT (indicatorConstLp 1 MeasurableSet.univ (measure_ne_top _ _) x) = T univ x :=
setToL1_indicatorConstLp hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace β G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace β G']
theorem setToL1_mono_left' {T T' : Set Ξ± β E βL[β] G''} {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C')
(hTT' : β s, MeasurableSet s β ΞΌ s < β β β x, T s x β€ T' s x) (f : Ξ± ββ[ΞΌ] E) :
setToL1 hT f β€ setToL1 hT' f := by
induction f using Lp.induction (hp_ne_top := one_ne_top) with
| @indicatorConst c s hs hΞΌs =>
rw [setToL1_simpleFunc_indicatorConst hT hs hΞΌs, setToL1_simpleFunc_indicatorConst hT' hs hΞΌs]
exact hTT' s hs hΞΌs c
| @add f g hf hg _ hf_le hg_le =>
rw [(setToL1 hT).map_add, (setToL1 hT').map_add]
exact add_le_add hf_le hg_le
| isClosed => exact isClosed_le (setToL1 hT).continuous (setToL1 hT').continuous
theorem setToL1_mono_left {T T' : Set Ξ± β E βL[β] G''} {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C')
(hTT' : β s x, T s x β€ T' s x) (f : Ξ± ββ[ΞΌ] E) : setToL1 hT f β€ setToL1 hT' f :=
setToL1_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToL1_nonneg {T : Set Ξ± β G' βL[β] G''} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f : Ξ± ββ[ΞΌ] G'}
(hf : 0 β€ f) : 0 β€ setToL1 hT f := by
suffices β f : { g : Ξ± ββ[ΞΌ] G' // 0 β€ g }, 0 β€ setToL1 hT f from
this (β¨f, hfβ© : { g : Ξ± ββ[ΞΌ] G' // 0 β€ g })
refine fun g =>
@isClosed_property { g : Ξ± βββ[ΞΌ] G' // 0 β€ g } { g : Ξ± ββ[ΞΌ] G' // 0 β€ g } _ _
(fun g => 0 β€ setToL1 hT g)
(denseRange_coeSimpleFuncNonnegToLpNonneg 1 ΞΌ G' one_ne_top) ?_ ?_ g
Β· exact isClosed_le continuous_zero ((setToL1 hT).continuous.comp continuous_induced_dom)
Β· intro g
have : (coeSimpleFuncNonnegToLpNonneg 1 ΞΌ G' g : Ξ± ββ[ΞΌ] G') = (g : Ξ± βββ[ΞΌ] G') := rfl
rw [this, setToL1_eq_setToL1SCLM]
exact setToL1S_nonneg (fun s => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2
theorem setToL1_mono [IsOrderedAddMonoid G']
{T : Set Ξ± β G' βL[β] G''} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f g : Ξ± ββ[ΞΌ] G'}
(hfg : f β€ g) : setToL1 hT f β€ setToL1 hT g := by
rw [β sub_nonneg] at hfg β’
rw [β (setToL1 hT).map_sub]
exact setToL1_nonneg hT hT_nonneg hfg
end Order
theorem norm_setToL1_le_norm_setToL1SCLM (hT : DominatedFinMeasAdditive ΞΌ T C) :
βsetToL1 hTβ β€ βsetToL1SCLM Ξ± E ΞΌ hTβ :=
calc
βsetToL1 hTβ β€ (1 : ββ₯0) * βsetToL1SCLM Ξ± E ΞΌ hTβ := by
refine
ContinuousLinearMap.opNorm_extend_le (setToL1SCLM Ξ± E ΞΌ hT) (coeToLp Ξ± E β)
(simpleFunc.denseRange one_ne_top) fun x => le_of_eq ?_
rw [NNReal.coe_one, one_mul]
simp [coeToLp]
_ = βsetToL1SCLM Ξ± E ΞΌ hTβ := by rw [NNReal.coe_one, one_mul]
theorem norm_setToL1_le_mul_norm (hT : DominatedFinMeasAdditive ΞΌ T C) (hC : 0 β€ C)
(f : Ξ± ββ[ΞΌ] E) : βsetToL1 hT fβ β€ C * βfβ :=
calc
βsetToL1 hT fβ β€ βsetToL1SCLM Ξ± E ΞΌ hTβ * βfβ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ β€ C * βfβ := mul_le_mul (norm_setToL1SCLM_le hT hC) le_rfl (norm_nonneg _) hC
theorem norm_setToL1_le_mul_norm' (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± ββ[ΞΌ] E) :
βsetToL1 hT fβ β€ max C 0 * βfβ :=
calc
βsetToL1 hT fβ β€ βsetToL1SCLM Ξ± E ΞΌ hTβ * βfβ :=
ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _
_ β€ max C 0 * βfβ :=
mul_le_mul (norm_setToL1SCLM_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _)
theorem norm_setToL1_le (hT : DominatedFinMeasAdditive ΞΌ T C) (hC : 0 β€ C) : βsetToL1 hTβ β€ C :=
ContinuousLinearMap.opNorm_le_bound _ hC (norm_setToL1_le_mul_norm hT hC)
theorem norm_setToL1_le' (hT : DominatedFinMeasAdditive ΞΌ T C) : βsetToL1 hTβ β€ max C 0 :=
ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) (norm_setToL1_le_mul_norm' hT)
theorem setToL1_lipschitz (hT : DominatedFinMeasAdditive ΞΌ T C) :
LipschitzWith (Real.toNNReal C) (setToL1 hT) :=
(setToL1 hT).lipschitz.weaken (norm_setToL1_le' hT)
/-- If `fs i β f` in `L1`, then `setToL1 hT (fs i) β setToL1 hT f`. -/
theorem tendsto_setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± ββ[ΞΌ] E) {ΞΉ}
(fs : ΞΉ β Ξ± ββ[ΞΌ] E) {l : Filter ΞΉ} (hfs : Tendsto fs l (π f)) :
Tendsto (fun i => setToL1 hT (fs i)) l (π <| setToL1 hT f) :=
((setToL1 hT).continuous.tendsto _).comp hfs
end SetToL1
end L1
section Function
variable [CompleteSpace F] {T T' T'' : Set Ξ± β E βL[β] F} {C C' C'' : β} {f g : Ξ± β E}
variable (ΞΌ T)
open Classical in
/-- Extend `T : Set Ξ± β E βL[β] F` to `(Ξ± β E) β F` (for integrable functions `Ξ± β E`). We set it to
0 if the function is not integrable. -/
def setToFun (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± β E) : F :=
if hf : Integrable f ΞΌ then L1.setToL1 hT (hf.toL1 f) else 0
variable {ΞΌ T}
theorem setToFun_eq (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) :
setToFun ΞΌ T hT f = L1.setToL1 hT (hf.toL1 f) :=
dif_pos hf
theorem L1.setToFun_eq_setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± ββ[ΞΌ] E) :
setToFun ΞΌ T hT f = L1.setToL1 hT f := by
rw [setToFun_eq hT (L1.integrable_coeFn f), Integrable.toL1_coeFn]
theorem setToFun_undef (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Β¬Integrable f ΞΌ) :
setToFun ΞΌ T hT f = 0 :=
dif_neg hf
theorem setToFun_non_aestronglyMeasurable (hT : DominatedFinMeasAdditive ΞΌ T C)
(hf : Β¬AEStronglyMeasurable f ΞΌ) : setToFun ΞΌ T hT f = 0 :=
setToFun_undef hT (not_and_of_not_left _ hf)
@[deprecated (since := "2025-04-09")]
alias setToFun_non_aEStronglyMeasurable := setToFun_non_aestronglyMeasurable
theorem setToFun_congr_left (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : T = T') (f : Ξ± β E) :
setToFun ΞΌ T hT f = setToFun ΞΌ T' hT' f := by
by_cases hf : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left T T' hT hT' h]
Β· simp_rw [setToFun_undef _ hf]
theorem setToFun_congr_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : β s, MeasurableSet s β ΞΌ s < β β T s = T' s)
(f : Ξ± β E) : setToFun ΞΌ T hT f = setToFun ΞΌ T' hT' f := by
by_cases hf : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left' T T' hT hT' h]
Β· simp_rw [setToFun_undef _ hf]
theorem setToFun_add_left (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (f : Ξ± β E) :
setToFun ΞΌ (T + T') (hT.add hT') f = setToFun ΞΌ T hT f + setToFun ΞΌ T' hT' f := by
by_cases hf : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left hT hT']
Β· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_add_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (hT'' : DominatedFinMeasAdditive ΞΌ T'' C'')
(h_add : β s, MeasurableSet s β ΞΌ s < β β T'' s = T s + T' s) (f : Ξ± β E) :
setToFun ΞΌ T'' hT'' f = setToFun ΞΌ T hT f + setToFun ΞΌ T' hT' f := by
by_cases hf : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left' hT hT' hT'' h_add]
Β· simp_rw [setToFun_undef _ hf, add_zero]
theorem setToFun_smul_left (hT : DominatedFinMeasAdditive ΞΌ T C) (c : β) (f : Ξ± β E) :
setToFun ΞΌ (fun s => c β’ T s) (hT.smul c) f = c β’ setToFun ΞΌ T hT f := by
by_cases hf : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left hT c]
Β· simp_rw [setToFun_undef _ hf, smul_zero]
theorem setToFun_smul_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ T' C') (c : β)
(h_smul : β s, MeasurableSet s β ΞΌ s < β β T' s = c β’ T s) (f : Ξ± β E) :
setToFun ΞΌ T' hT' f = c β’ setToFun ΞΌ T hT f := by
by_cases hf : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left' hT hT' c h_smul]
Β· simp_rw [setToFun_undef _ hf, smul_zero]
@[simp]
theorem setToFun_zero (hT : DominatedFinMeasAdditive ΞΌ T C) : setToFun ΞΌ T hT (0 : Ξ± β E) = 0 := by
rw [Pi.zero_def, setToFun_eq hT (integrable_zero _ _ _)]
simp only [β Pi.zero_def]
rw [Integrable.toL1_zero, ContinuousLinearMap.map_zero]
@[simp]
theorem setToFun_zero_left {hT : DominatedFinMeasAdditive ΞΌ (0 : Set Ξ± β E βL[β] F) C} :
setToFun ΞΌ 0 hT f = 0 := by
by_cases hf : Integrable f ΞΌ
Β· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left hT _
Β· exact setToFun_undef hT hf
theorem setToFun_zero_left' (hT : DominatedFinMeasAdditive ΞΌ T C)
(h_zero : β s, MeasurableSet s β ΞΌ s < β β T s = 0) : setToFun ΞΌ T hT f = 0 := by
by_cases hf : Integrable f ΞΌ
Β· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left' hT h_zero _
Β· exact setToFun_undef hT hf
theorem setToFun_add (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ)
(hg : Integrable g ΞΌ) : setToFun ΞΌ T hT (f + g) = setToFun ΞΌ T hT f + setToFun ΞΌ T hT g := by
rw [setToFun_eq hT (hf.add hg), setToFun_eq hT hf, setToFun_eq hT hg, Integrable.toL1_add,
(L1.setToL1 hT).map_add]
theorem setToFun_finset_sum' (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ} (s : Finset ΞΉ)
{f : ΞΉ β Ξ± β E} (hf : β i β s, Integrable (f i) ΞΌ) :
setToFun ΞΌ T hT (β i β s, f i) = β i β s, setToFun ΞΌ T hT (f i) := by
classical
revert hf
refine Finset.induction_on s ?_ ?_
Β· intro _
simp only [setToFun_zero, Finset.sum_empty]
Β· intro i s his ih hf
simp only [his, Finset.sum_insert, not_false_iff]
rw [setToFun_add hT (hf i (Finset.mem_insert_self i s)) _]
Β· rw [ih fun i hi => hf i (Finset.mem_insert_of_mem hi)]
Β· convert integrable_finset_sum s fun i hi => hf i (Finset.mem_insert_of_mem hi) with x
simp
theorem setToFun_finset_sum (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ} (s : Finset ΞΉ) {f : ΞΉ β Ξ± β E}
(hf : β i β s, Integrable (f i) ΞΌ) :
(setToFun ΞΌ T hT fun a => β i β s, f i a) = β i β s, setToFun ΞΌ T hT (f i) := by
convert setToFun_finset_sum' hT s hf with a; simp
theorem setToFun_neg (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± β E) :
setToFun ΞΌ T hT (-f) = -setToFun ΞΌ T hT f := by
by_cases hf : Integrable f ΞΌ
Β· rw [setToFun_eq hT hf, setToFun_eq hT hf.neg, Integrable.toL1_neg,
(L1.setToL1 hT).map_neg]
Β· rw [setToFun_undef hT hf, setToFun_undef hT, neg_zero]
rwa [β integrable_neg_iff] at hf
theorem setToFun_sub (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ)
(hg : Integrable g ΞΌ) : setToFun ΞΌ T hT (f - g) = setToFun ΞΌ T hT f - setToFun ΞΌ T hT g := by
rw [sub_eq_add_neg, sub_eq_add_neg, setToFun_add hT hf hg.neg, setToFun_neg hT g]
theorem setToFun_smul [NontriviallyNormedField π] [NormedSpace π E] [NormedSpace π F]
(hT : DominatedFinMeasAdditive ΞΌ T C) (h_smul : β c : π, β s x, T s (c β’ x) = c β’ T s x) (c : π)
(f : Ξ± β E) : setToFun ΞΌ T hT (c β’ f) = c β’ setToFun ΞΌ T hT f := by
by_cases hf : Integrable f ΞΌ
Β· rw [setToFun_eq hT hf, setToFun_eq hT, Integrable.toL1_smul',
L1.setToL1_smul hT h_smul c _]
Β· by_cases hr : c = 0
Β· rw [hr]; simp
Β· have hf' : Β¬Integrable (c β’ f) ΞΌ := by rwa [integrable_smul_iff hr f]
rw [setToFun_undef hT hf, setToFun_undef hT hf', smul_zero]
theorem setToFun_congr_ae (hT : DominatedFinMeasAdditive ΞΌ T C) (h : f =α΅[ΞΌ] g) :
setToFun ΞΌ T hT f = setToFun ΞΌ T hT g := by
by_cases hfi : Integrable f ΞΌ
Β· have hgi : Integrable g ΞΌ := hfi.congr h
rw [setToFun_eq hT hfi, setToFun_eq hT hgi, (Integrable.toL1_eq_toL1_iff f g hfi hgi).2 h]
Β· have hgi : Β¬Integrable g ΞΌ := by rw [integrable_congr h] at hfi; exact hfi
rw [setToFun_undef hT hfi, setToFun_undef hT hgi]
theorem setToFun_measure_zero (hT : DominatedFinMeasAdditive ΞΌ T C) (h : ΞΌ = 0) :
setToFun ΞΌ T hT f = 0 := by
have : f =α΅[ΞΌ] 0 := by simp [h, EventuallyEq]
rw [setToFun_congr_ae hT this, setToFun_zero]
theorem setToFun_measure_zero' (hT : DominatedFinMeasAdditive ΞΌ T C)
(h : β s, MeasurableSet s β ΞΌ s < β β ΞΌ s = 0) : setToFun ΞΌ T hT f = 0 :=
setToFun_zero_left' hT fun s hs hΞΌs => hT.eq_zero_of_measure_zero hs (h s hs hΞΌs)
theorem setToFun_toL1 (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) :
setToFun ΞΌ T hT (hf.toL1 f) = setToFun ΞΌ T hT f :=
setToFun_congr_ae hT hf.coeFn_toL1
theorem setToFun_indicator_const (hT : DominatedFinMeasAdditive ΞΌ T C) {s : Set Ξ±}
(hs : MeasurableSet s) (hΞΌs : ΞΌ s β β) (x : E) :
setToFun ΞΌ T hT (s.indicator fun _ => x) = T s x := by
rw [setToFun_congr_ae hT (@indicatorConstLp_coeFn _ _ _ 1 _ _ _ hs hΞΌs x).symm]
rw [L1.setToFun_eq_setToL1 hT]
exact L1.setToL1_indicatorConstLp hT hs hΞΌs x
theorem setToFun_const [IsFiniteMeasure ΞΌ] (hT : DominatedFinMeasAdditive ΞΌ T C) (x : E) :
(setToFun ΞΌ T hT fun _ => x) = T univ x := by
have : (fun _ : Ξ± => x) = Set.indicator univ fun _ => x := (indicator_univ _).symm
rw [this]
exact setToFun_indicator_const hT MeasurableSet.univ (measure_ne_top _ _) x
section Order
variable {G' G'' : Type*}
[NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G'']
[NormedSpace β G''] [CompleteSpace G'']
[NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace β G']
theorem setToFun_mono_left' {T T' : Set Ξ± β E βL[β] G''} {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C')
(hTT' : β s, MeasurableSet s β ΞΌ s < β β β x, T s x β€ T' s x) (f : Ξ± β E) :
setToFun ΞΌ T hT f β€ setToFun ΞΌ T' hT' f := by
by_cases hf : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hf]; exact L1.setToL1_mono_left' hT hT' hTT' _
Β· simp_rw [setToFun_undef _ hf, le_rfl]
theorem setToFun_mono_left {T T' : Set Ξ± β E βL[β] G''} {C C' : β}
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C')
(hTT' : β s x, T s x β€ T' s x) (f : Ξ± ββ[ΞΌ] E) : setToFun ΞΌ T hT f β€ setToFun ΞΌ T' hT' f :=
setToFun_mono_left' hT hT' (fun s _ _ x => hTT' s x) f
theorem setToFun_nonneg {T : Set Ξ± β G' βL[β] G''} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f : Ξ± β G'}
(hf : 0 β€α΅[ΞΌ] f) : 0 β€ setToFun ΞΌ T hT f := by
by_cases hfi : Integrable f ΞΌ
Β· simp_rw [setToFun_eq _ hfi]
refine L1.setToL1_nonneg hT hT_nonneg ?_
rw [β Lp.coeFn_le]
have h0 := Lp.coeFn_zero G' 1 ΞΌ
have h := Integrable.coeFn_toL1 hfi
filter_upwards [h0, h, hf] with _ h0a ha hfa
rw [h0a, ha]
exact hfa
Β· simp_rw [setToFun_undef _ hfi, le_rfl]
theorem setToFun_mono [IsOrderedAddMonoid G']
{T : Set Ξ± β G' βL[β] G''} {C : β} (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT_nonneg : β s, MeasurableSet s β ΞΌ s < β β β x, 0 β€ x β 0 β€ T s x) {f g : Ξ± β G'}
(hf : Integrable f ΞΌ) (hg : Integrable g ΞΌ) (hfg : f β€α΅[ΞΌ] g) :
setToFun ΞΌ T hT f β€ setToFun ΞΌ T hT g := by
rw [β sub_nonneg, β setToFun_sub hT hg hf]
refine setToFun_nonneg hT hT_nonneg (hfg.mono fun a ha => ?_)
rw [Pi.sub_apply, Pi.zero_apply, sub_nonneg]
exact ha
end Order
@[continuity]
theorem continuous_setToFun (hT : DominatedFinMeasAdditive ΞΌ T C) :
Continuous fun f : Ξ± ββ[ΞΌ] E => setToFun ΞΌ T hT f := by
simp_rw [L1.setToFun_eq_setToL1 hT]; exact ContinuousLinearMap.continuous _
/-- If `F i β f` in `L1`, then `setToFun ΞΌ T hT (F i) β setToFun ΞΌ T hT f`. -/
theorem tendsto_setToFun_of_L1 (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ} (f : Ξ± β E)
(hfi : Integrable f ΞΌ) {fs : ΞΉ β Ξ± β E} {l : Filter ΞΉ} (hfsi : βαΆ i in l, Integrable (fs i) ΞΌ)
(hfs : Tendsto (fun i => β«β» x, βfs i x - f xββ βΞΌ) l (π 0)) :
Tendsto (fun i => setToFun ΞΌ T hT (fs i)) l (π <| setToFun ΞΌ T hT f) := by
classical
let f_lp := hfi.toL1 f
let F_lp i := if hFi : Integrable (fs i) ΞΌ then hFi.toL1 (fs i) else 0
have tendsto_L1 : Tendsto F_lp l (π f_lp) := by
rw [Lp.tendsto_Lp_iff_tendsto_eLpNorm']
simp_rw [eLpNorm_one_eq_lintegral_enorm, Pi.sub_apply]
refine (tendsto_congr' ?_).mp hfs
filter_upwards [hfsi] with i hi
refine lintegral_congr_ae ?_
filter_upwards [hi.coeFn_toL1, hfi.coeFn_toL1] with x hxi hxf
simp_rw [F_lp, dif_pos hi, hxi, f_lp, hxf]
suffices Tendsto (fun i => setToFun ΞΌ T hT (F_lp i)) l (π (setToFun ΞΌ T hT f)) by
refine (tendsto_congr' ?_).mp this
filter_upwards [hfsi] with i hi
suffices h_ae_eq : F_lp i =α΅[ΞΌ] fs i from setToFun_congr_ae hT h_ae_eq
simp_rw [F_lp, dif_pos hi]
exact hi.coeFn_toL1
rw [setToFun_congr_ae hT hfi.coeFn_toL1.symm]
exact ((continuous_setToFun hT).tendsto f_lp).comp tendsto_L1
theorem tendsto_setToFun_approxOn_of_measurable (hT : DominatedFinMeasAdditive ΞΌ T C)
[MeasurableSpace E] [BorelSpace E] {f : Ξ± β E} {s : Set E} [SeparableSpace s]
(hfi : Integrable f ΞΌ) (hfm : Measurable f) (hs : βα΅ x βΞΌ, f x β closure s) {yβ : E}
(hβ : yβ β s) (hβi : Integrable (fun _ => yβ) ΞΌ) :
Tendsto (fun n => setToFun ΞΌ T hT (SimpleFunc.approxOn f hfm s yβ hβ n)) atTop
(π <| setToFun ΞΌ T hT f) :=
tendsto_setToFun_of_L1 hT _ hfi
(Eventually.of_forall (SimpleFunc.integrable_approxOn hfm hfi hβ hβi))
(SimpleFunc.tendsto_approxOn_L1_enorm hfm _ hs (hfi.sub hβi).2)
theorem tendsto_setToFun_approxOn_of_measurable_of_range_subset
(hT : DominatedFinMeasAdditive ΞΌ T C) [MeasurableSpace E] [BorelSpace E] {f : Ξ± β E}
(fmeas : Measurable f) (hf : Integrable f ΞΌ) (s : Set E) [SeparableSpace s]
(hs : range f βͺ {0} β s) :
Tendsto (fun n => setToFun ΞΌ T hT (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n)) atTop
(π <| setToFun ΞΌ T hT f) := by
refine tendsto_setToFun_approxOn_of_measurable hT hf fmeas ?_ _ (integrable_zero _ _ _)
exact Eventually.of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _)))
/-- Auxiliary lemma for `setToFun_congr_measure`: the function sending `f : Ξ± ββ[ΞΌ] G` to
`f : Ξ± ββ[ΞΌ'] G` is continuous when `ΞΌ' β€ c' β’ ΞΌ` for `c' β β`. -/
theorem continuous_L1_toL1 {ΞΌ' : Measure Ξ±} (c' : ββ₯0β) (hc' : c' β β) (hΞΌ'_le : ΞΌ' β€ c' β’ ΞΌ) :
Continuous fun f : Ξ± ββ[ΞΌ] G =>
(Integrable.of_measure_le_smul hc' hΞΌ'_le (L1.integrable_coeFn f)).toL1 f := by
by_cases hc'0 : c' = 0
Β· have hΞΌ'0 : ΞΌ' = 0 := by rw [β Measure.nonpos_iff_eq_zero']; refine hΞΌ'_le.trans ?_; simp [hc'0]
have h_im_zero :
(fun f : Ξ± ββ[ΞΌ] G =>
(Integrable.of_measure_le_smul hc' hΞΌ'_le (L1.integrable_coeFn f)).toL1 f) =
0 := by
ext1 f; ext1; simp_rw [hΞΌ'0]; simp only [ae_zero, EventuallyEq, eventually_bot]
rw [h_im_zero]
exact continuous_zero
rw [Metric.continuous_iff]
intro f Ξ΅ hΞ΅_pos
use Ξ΅ / 2 / c'.toReal
refine β¨div_pos (half_pos hΞ΅_pos) (toReal_pos hc'0 hc'), ?_β©
intro g hfg
rw [Lp.dist_def] at hfg β’
let h_int := fun f' : Ξ± ββ[ΞΌ] G => (L1.integrable_coeFn f').of_measure_le_smul hc' hΞΌ'_le
have :
eLpNorm (β(Integrable.toL1 g (h_int g)) - β(Integrable.toL1 f (h_int f))) 1 ΞΌ' =
eLpNorm (βg - βf) 1 ΞΌ' :=
eLpNorm_congr_ae ((Integrable.coeFn_toL1 _).sub (Integrable.coeFn_toL1 _))
rw [this]
have h_eLpNorm_ne_top : eLpNorm (βg - βf) 1 ΞΌ β β := by
rw [β eLpNorm_congr_ae (Lp.coeFn_sub _ _)]; exact Lp.eLpNorm_ne_top _
calc
(eLpNorm (βg - βf) 1 ΞΌ').toReal β€ (c' * eLpNorm (βg - βf) 1 ΞΌ).toReal := by
refine toReal_mono (ENNReal.mul_ne_top hc' h_eLpNorm_ne_top) ?_
refine (eLpNorm_mono_measure (βg - βf) hΞΌ'_le).trans_eq ?_
rw [eLpNorm_smul_measure_of_ne_zero hc'0, smul_eq_mul]
simp
_ = c'.toReal * (eLpNorm (βg - βf) 1 ΞΌ).toReal := toReal_mul
_ β€ c'.toReal * (Ξ΅ / 2 / c'.toReal) := by gcongr
_ = Ξ΅ / 2 := by
refine mul_div_cancelβ (Ξ΅ / 2) ?_; rw [Ne, toReal_eq_zero_iff]; simp [hc', hc'0]
_ < Ξ΅ := half_lt_self hΞ΅_pos
theorem setToFun_congr_measure_of_integrable {ΞΌ' : Measure Ξ±} (c' : ββ₯0β) (hc' : c' β β)
(hΞΌ'_le : ΞΌ' β€ c' β’ ΞΌ) (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ' T C') (f : Ξ± β E) (hfΞΌ : Integrable f ΞΌ) :
setToFun ΞΌ T hT f = setToFun ΞΌ' T hT' f := by
-- integrability for `ΞΌ` implies integrability for `ΞΌ'`.
have h_int : β g : Ξ± β E, Integrable g ΞΌ β Integrable g ΞΌ' := fun g hg =>
Integrable.of_measure_le_smul hc' hΞΌ'_le hg
-- We use `Integrable.induction`
apply hfΞΌ.induction (P := fun f => setToFun ΞΌ T hT f = setToFun ΞΌ' T hT' f)
Β· intro c s hs hΞΌs
have hΞΌ's : ΞΌ' s β β := by
refine ((hΞΌ'_le s).trans_lt ?_).ne
rw [Measure.smul_apply, smul_eq_mul]
exact ENNReal.mul_lt_top hc'.lt_top hΞΌs
rw [setToFun_indicator_const hT hs hΞΌs.ne, setToFun_indicator_const hT' hs hΞΌ's]
Β· intro fβ gβ _ hfβ hgβ h_eq_f h_eq_g
rw [setToFun_add hT hfβ hgβ, setToFun_add hT' (h_int fβ hfβ) (h_int gβ hgβ), h_eq_f, h_eq_g]
Β· refine isClosed_eq (continuous_setToFun hT) ?_
have :
(fun f : Ξ± ββ[ΞΌ] E => setToFun ΞΌ' T hT' f) = fun f : Ξ± ββ[ΞΌ] E =>
setToFun ΞΌ' T hT' ((h_int f (L1.integrable_coeFn f)).toL1 f) := by
ext1 f; exact setToFun_congr_ae hT' (Integrable.coeFn_toL1 _).symm
rw [this]
exact (continuous_setToFun hT').comp (continuous_L1_toL1 c' hc' hΞΌ'_le)
Β· intro fβ gβ hfg _ hf_eq
have hfg' : fβ =α΅[ΞΌ'] gβ := (Measure.absolutelyContinuous_of_le_smul hΞΌ'_le).ae_eq hfg
rw [β setToFun_congr_ae hT hfg, hf_eq, setToFun_congr_ae hT' hfg']
theorem setToFun_congr_measure {ΞΌ' : Measure Ξ±} (c c' : ββ₯0β) (hc : c β β) (hc' : c' β β)
(hΞΌ_le : ΞΌ β€ c β’ ΞΌ') (hΞΌ'_le : ΞΌ' β€ c' β’ ΞΌ) (hT : DominatedFinMeasAdditive ΞΌ T C)
(hT' : DominatedFinMeasAdditive ΞΌ' T C') (f : Ξ± β E) :
setToFun ΞΌ T hT f = setToFun ΞΌ' T hT' f := by
by_cases hf : Integrable f ΞΌ
Β· exact setToFun_congr_measure_of_integrable c' hc' hΞΌ'_le hT hT' f hf
Β· -- if `f` is not integrable, both `setToFun` are 0.
have h_int : β g : Ξ± β E, Β¬Integrable g ΞΌ β Β¬Integrable g ΞΌ' := fun g =>
mt fun h => h.of_measure_le_smul hc hΞΌ_le
simp_rw [setToFun_undef _ hf, setToFun_undef _ (h_int f hf)]
theorem setToFun_congr_measure_of_add_right {ΞΌ' : Measure Ξ±}
(hT_add : DominatedFinMeasAdditive (ΞΌ + ΞΌ') T C') (hT : DominatedFinMeasAdditive ΞΌ T C)
(f : Ξ± β E) (hf : Integrable f (ΞΌ + ΞΌ')) :
setToFun (ΞΌ + ΞΌ') T hT_add f = setToFun ΞΌ T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [β add_zero ΞΌ]
exact add_le_add le_rfl bot_le
theorem setToFun_congr_measure_of_add_left {ΞΌ' : Measure Ξ±}
(hT_add : DominatedFinMeasAdditive (ΞΌ + ΞΌ') T C') (hT : DominatedFinMeasAdditive ΞΌ' T C)
(f : Ξ± β E) (hf : Integrable f (ΞΌ + ΞΌ')) :
setToFun (ΞΌ + ΞΌ') T hT_add f = setToFun ΞΌ' T hT f := by
refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf
rw [one_smul]
nth_rw 1 [β zero_add ΞΌ']
exact add_le_add_right bot_le ΞΌ'
theorem setToFun_top_smul_measure (hT : DominatedFinMeasAdditive (β β’ ΞΌ) T C) (f : Ξ± β E) :
setToFun (β β’ ΞΌ) T hT f = 0 := by
refine setToFun_measure_zero' hT fun s _ hΞΌs => ?_
rw [lt_top_iff_ne_top] at hΞΌs
simp only [true_and, Measure.smul_apply, ENNReal.mul_eq_top, eq_self_iff_true,
top_ne_zero, Ne, not_false_iff, not_or, Classical.not_not, smul_eq_mul] at hΞΌs
simp only [hΞΌs.right, Measure.smul_apply, mul_zero, smul_eq_mul]
theorem setToFun_congr_smul_measure (c : ββ₯0β) (hc_ne_top : c β β)
(hT : DominatedFinMeasAdditive ΞΌ T C) (hT_smul : DominatedFinMeasAdditive (c β’ ΞΌ) T C')
(f : Ξ± β E) : setToFun ΞΌ T hT f = setToFun (c β’ ΞΌ) T hT_smul f := by
by_cases hc0 : c = 0
Β· simp [hc0] at hT_smul
have h : β s, MeasurableSet s β ΞΌ s < β β T s = 0 := fun s hs _ => hT_smul.eq_zero hs
rw [setToFun_zero_left' _ h, setToFun_measure_zero]
simp [hc0]
refine setToFun_congr_measure cβ»ΒΉ c ?_ hc_ne_top (le_of_eq ?_) le_rfl hT hT_smul f
Β· simp [hc0]
Β· rw [smul_smul, ENNReal.inv_mul_cancel hc0 hc_ne_top, one_smul]
theorem norm_setToFun_le_mul_norm (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± ββ[ΞΌ] E)
(hC : 0 β€ C) : βsetToFun ΞΌ T hT fβ β€ C * βfβ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm hT hC f
theorem norm_setToFun_le_mul_norm' (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± ββ[ΞΌ] E) :
βsetToFun ΞΌ T hT fβ β€ max C 0 * βfβ := by
rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm' hT f
theorem norm_setToFun_le (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) (hC : 0 β€ C) :
βsetToFun ΞΌ T hT fβ β€ C * βhf.toL1 fβ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm hT hC _
theorem norm_setToFun_le' (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) :
βsetToFun ΞΌ T hT fβ β€ max C 0 * βhf.toL1 fβ := by
rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm' hT _
/-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their image by
`setToFun`.
We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound ΞΌ` instead
(i.e. not requiring that `bound` is measurable), but in all applications proving integrability
is easier. -/
theorem tendsto_setToFun_of_dominated_convergence (hT : DominatedFinMeasAdditive ΞΌ T C)
{fs : β β Ξ± β E} {f : Ξ± β E} (bound : Ξ± β β)
(fs_measurable : β n, AEStronglyMeasurable (fs n) ΞΌ) (bound_integrable : Integrable bound ΞΌ)
(h_bound : β n, βα΅ a βΞΌ, βfs n aβ β€ bound a)
(h_lim : βα΅ a βΞΌ, Tendsto (fun n => fs n a) atTop (π (f a))) :
Tendsto (fun n => setToFun ΞΌ T hT (fs n)) atTop (π <| setToFun ΞΌ T hT f) := by
-- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions.
have f_measurable : AEStronglyMeasurable f ΞΌ :=
aestronglyMeasurable_of_tendsto_ae _ fs_measurable h_lim
-- all functions we consider are integrable
have fs_int : β n, Integrable (fs n) ΞΌ := fun n =>
bound_integrable.mono' (fs_measurable n) (h_bound _)
have f_int : Integrable f ΞΌ :=
β¨f_measurable,
hasFiniteIntegral_of_dominated_convergence bound_integrable.hasFiniteIntegral h_bound
h_limβ©
-- it suffices to prove the result for the corresponding L1 functions
suffices
Tendsto (fun n => L1.setToL1 hT ((fs_int n).toL1 (fs n))) atTop
(π (L1.setToL1 hT (f_int.toL1 f))) by
convert this with n
Β· exact setToFun_eq hT (fs_int n)
Β· exact setToFun_eq hT f_int
-- the convergence of setToL1 follows from the convergence of the L1 functions
refine L1.tendsto_setToL1 hT _ _ ?_
-- up to some rewriting, what we need to prove is `h_lim`
rw [tendsto_iff_norm_sub_tendsto_zero]
have lintegral_norm_tendsto_zero :
Tendsto (fun n => ENNReal.toReal <| β«β» a, ENNReal.ofReal βfs n a - f aβ βΞΌ) atTop (π 0) :=
(tendsto_toReal zero_ne_top).comp
(tendsto_lintegral_norm_of_dominated_convergence fs_measurable
bound_integrable.hasFiniteIntegral h_bound h_lim)
convert lintegral_norm_tendsto_zero with n
rw [L1.norm_def]
congr 1
refine lintegral_congr_ae ?_
rw [β Integrable.toL1_sub]
refine ((fs_int n).sub f_int).coeFn_toL1.mono fun x hx => ?_
dsimp only
rw [hx, ofReal_norm_eq_enorm, Pi.sub_apply]
/-- Lebesgue dominated convergence theorem for filters with a countable basis -/
theorem tendsto_setToFun_filter_of_dominated_convergence (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ}
{l : Filter ΞΉ} [l.IsCountablyGenerated] {fs : ΞΉ β Ξ± β E} {f : Ξ± β E} (bound : Ξ± β β)
(hfs_meas : βαΆ n in l, AEStronglyMeasurable (fs n) ΞΌ)
(h_bound : βαΆ n in l, βα΅ a βΞΌ, βfs n aβ β€ bound a) (bound_integrable : Integrable bound ΞΌ)
(h_lim : βα΅ a βΞΌ, Tendsto (fun n => fs n a) l (π (f a))) :
Tendsto (fun n => setToFun ΞΌ T hT (fs n)) l (π <| setToFun ΞΌ T hT f) := by
rw [tendsto_iff_seq_tendsto]
intro x xl
have hxl : β s β l, β a, β b β₯ a, x b β s := by rwa [tendsto_atTop'] at xl
have h :
{ x : ΞΉ | (fun n => AEStronglyMeasurable (fs n) ΞΌ) x } β©
{ x : ΞΉ | (fun n => βα΅ a βΞΌ, βfs n aβ β€ bound a) x } β l :=
inter_mem hfs_meas h_bound
obtain β¨k, hβ© := hxl _ h
rw [β tendsto_add_atTop_iff_nat k]
refine tendsto_setToFun_of_dominated_convergence hT bound ?_ bound_integrable ?_ ?_
Β· exact fun n => (h _ (self_le_add_left _ _)).1
Β· exact fun n => (h _ (self_le_add_left _ _)).2
Β· filter_upwards [h_lim]
refine fun a h_lin => @Tendsto.comp _ _ _ (fun n => x (n + k)) (fun n => fs n a) _ _ _ h_lin ?_
rwa [tendsto_add_atTop_iff_nat]
variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X]
theorem continuousWithinAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C)
{fs : X β Ξ± β E} {xβ : X} {bound : Ξ± β β} {s : Set X}
(hfs_meas : βαΆ x in π[s] xβ, AEStronglyMeasurable (fs x) ΞΌ)
(h_bound : βαΆ x in π[s] xβ, βα΅ a βΞΌ, βfs x aβ β€ bound a) (bound_integrable : Integrable bound ΞΌ)
(h_cont : βα΅ a βΞΌ, ContinuousWithinAt (fun x => fs x a) s xβ) :
ContinuousWithinAt (fun x => setToFun ΞΌ T hT (fs x)) s xβ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound βΉ_βΊ βΉ_βΊ βΉ_βΊ βΉ_βΊ
theorem continuousAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : X β Ξ± β E}
{xβ : X} {bound : Ξ± β β} (hfs_meas : βαΆ x in π xβ, AEStronglyMeasurable (fs x) ΞΌ)
(h_bound : βαΆ x in π xβ, βα΅ a βΞΌ, βfs x aβ β€ bound a) (bound_integrable : Integrable bound ΞΌ)
(h_cont : βα΅ a βΞΌ, ContinuousAt (fun x => fs x a) xβ) :
ContinuousAt (fun x => setToFun ΞΌ T hT (fs x)) xβ :=
tendsto_setToFun_filter_of_dominated_convergence hT bound βΉ_βΊ βΉ_βΊ βΉ_βΊ βΉ_βΊ
theorem continuousOn_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : X β Ξ± β E}
{bound : Ξ± β β} {s : Set X} (hfs_meas : β x β s, AEStronglyMeasurable (fs x) ΞΌ)
(h_bound : β x β s, βα΅ a βΞΌ, βfs x aβ β€ bound a) (bound_integrable : Integrable bound ΞΌ)
(h_cont : βα΅ a βΞΌ, ContinuousOn (fun x => fs x a) s) :
ContinuousOn (fun x => setToFun ΞΌ T hT (fs x)) s := by
intro x hx
refine continuousWithinAt_setToFun_of_dominated hT ?_ ?_ bound_integrable ?_
Β· filter_upwards [self_mem_nhdsWithin] with x hx using hfs_meas x hx
Β· filter_upwards [self_mem_nhdsWithin] with x hx using h_bound x hx
Β· filter_upwards [h_cont] with a ha using ha x hx
theorem continuous_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : X β Ξ± β E}
{bound : Ξ± β β} (hfs_meas : β x, AEStronglyMeasurable (fs x) ΞΌ)
(h_bound : β x, βα΅ a βΞΌ, βfs x aβ β€ bound a) (bound_integrable : Integrable bound ΞΌ)
(h_cont : βα΅ a βΞΌ, Continuous fun x => fs x a) : Continuous fun x => setToFun ΞΌ T hT (fs x) :=
continuous_iff_continuousAt.mpr fun _ =>
continuousAt_setToFun_of_dominated hT (Eventually.of_forall hfs_meas)
(Eventually.of_forall h_bound) βΉ_βΊ <|
h_cont.mono fun _ => Continuous.continuousAt
end Function
end MeasureTheory
| Mathlib/MeasureTheory/Integral/SetToL1.lean | 1,704 | 1,743 | |
/-
Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.Data.Nat.EvenOddRec
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.LinearCombination
/-!
# Elliptic divisibility sequences
This file defines the type of an elliptic divisibility sequence (EDS) and a few examples.
## Mathematical background
Let `R` be a commutative ring. An elliptic sequence is a sequence `W : β€ β R` satisfying
`W(m + n)W(m - n)W(r)Β² = W(m + r)W(m - r)W(n)Β² - W(n + r)W(n - r)W(m)Β²` for any `m, n, r β β€`.
A divisibility sequence is a sequence `W : β€ β R` satisfying `W(m) β£ W(n)` for any `m, n β β€` such
that `m β£ n`. An elliptic divisibility sequence is simply a divisibility sequence that is elliptic.
Some examples of EDSs include
* the identity sequence,
* certain terms of Lucas sequences, and
* division polynomials of elliptic curves.
## Main definitions
* `IsEllSequence`: a sequence indexed by integers is an elliptic sequence.
* `IsDivSequence`: a sequence indexed by integers is a divisibility sequence.
* `IsEllDivSequence`: a sequence indexed by integers is an EDS.
* `preNormEDS'`: the auxiliary sequence for a normalised EDS indexed by `β`.
* `preNormEDS`: the auxiliary sequence for a normalised EDS indexed by `β€`.
* `normEDS`: the canonical example of a normalised EDS indexed by `β€`.
## Main statements
* TODO: prove that `normEDS` satisfies `IsEllDivSequence`.
* TODO: prove that a normalised sequence satisfying `IsEllDivSequence` can be given by `normEDS`.
## Implementation notes
The normalised EDS `normEDS b c d n` is defined in terms of the auxiliary sequence
`preNormEDS (b ^ 4) c d n`, which are equal when `n` is odd, and which differ by a factor of `b`
when `n` is even. This coincides with the definition in the references since both agree for
`normEDS b c d 2` and for `normEDS b c d 4`, and the correct factors of `b` are removed in
`normEDS b c d (2 * (m + 2) + 1)` and in `normEDS b c d (2 * (m + 3))`.
One reason is to avoid the necessity for ring division by `b` in the inductive definition of
`normEDS b c d (2 * (m + 3))`. The idea is that, it can be shown that `normEDS b c d (2 * (m + 3))`
always contains a factor of `b`, so it is possible to remove a factor of `b` *a posteriori*, but
stating this lemma requires first defining `normEDS b c d (2 * (m + 3))`, which requires having this
factor of `b` *a priori*. Another reason is to allow the definition of univariate `n`-division
polynomials of elliptic curves, omitting a factor of the bivariate `2`-division polynomial.
## References
M Ward, *Memoir on Elliptic Divisibility Sequences*
## Tags
elliptic, divisibility, sequence
-/
universe u v
variable {R : Type u} [CommRing R]
section IsEllDivSequence
variable (W : β€ β R)
/-- The proposition that a sequence indexed by integers is an elliptic sequence. -/
def IsEllSequence : Prop :=
β m n r : β€, W (m + n) * W (m - n) * W r ^ 2 =
W (m + r) * W (m - r) * W n ^ 2 - W (n + r) * W (n - r) * W m ^ 2
/-- The proposition that a sequence indexed by integers is a divisibility sequence. -/
def IsDivSequence : Prop :=
β m n : β, m β£ n β W m β£ W n
/-- The proposition that a sequence indexed by integers is an EDS. -/
def IsEllDivSequence : Prop :=
IsEllSequence W β§ IsDivSequence W
lemma isEllSequence_id : IsEllSequence id :=
fun _ _ _ => by simp only [id_eq]; ring1
lemma isDivSequence_id : IsDivSequence id :=
fun _ _ => Int.ofNat_dvd.mpr
/-- The identity sequence is an EDS. -/
theorem isEllDivSequence_id : IsEllDivSequence id :=
β¨isEllSequence_id, isDivSequence_idβ©
variable {W}
lemma IsEllSequence.smul (h : IsEllSequence W) (x : R) : IsEllSequence (x β’ W) :=
fun m n r => by
linear_combination (norm := (simp only [Pi.smul_apply, smul_eq_mul]; ring1)) x ^ 4 * h m n r
lemma IsDivSequence.smul (h : IsDivSequence W) (x : R) : IsDivSequence (x β’ W) :=
fun m n r => mul_dvd_mul_left x <| h m n r
lemma IsEllDivSequence.smul (h : IsEllDivSequence W) (x : R) : IsEllDivSequence (x β’ W) :=
β¨h.left.smul x, h.right.smul xβ©
end IsEllDivSequence
/-- Strong recursion principle for a normalised EDS: if we have
* `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`,
* for all `m : β` we can prove `P (2 * (m + 3))` from `P k` for all `k < 2 * (m + 3)`, and
* for all `m : β` we can prove `P (2 * (m + 2) + 1)` from `P k` for all `k < 2 * (m + 2) + 1`,
then we have `P n` for all `n : β`. -/
@[elab_as_elim]
noncomputable def normEDSRec' {P : β β Sort u}
(zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4)
(even : β m : β, (β k < 2 * (m + 3), P k) β P (2 * (m + 3)))
(odd : β m : β, (β k < 2 * (m + 2) + 1, P k) β P (2 * (m + 2) + 1)) (n : β) : P n :=
n.evenOddStrongRec (by rintro (_ | _ | _ | _) h; exacts [zero, two, four, even _ h])
(by rintro (_ | _ | _) h; exacts [one, three, odd _ h])
/-- Recursion principle for a normalised EDS: if we have
* `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`,
* for all `m : β` we can prove `P (2 * (m + 3))` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`,
`P (m + 4)`, and `P (m + 5)`, and
* for all `m : β` we can prove `P (2 * (m + 2) + 1)` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`,
and `P (m + 4)`,
then we have `P n` for all `n : β`. -/
@[elab_as_elim]
noncomputable def normEDSRec {P : β β Sort u}
(zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4)
(even : β m : β, P (m + 1) β P (m + 2) β P (m + 3) β P (m + 4) β P (m + 5) β P (2 * (m + 3)))
(odd : β m : β, P (m + 1) β P (m + 2) β P (m + 3) β P (m + 4) β P (2 * (m + 2) + 1)) (n : β) :
P n :=
normEDSRec' zero one two three four
(fun _ ih => by apply even <;> exact ih _ <| by linarith only)
(fun _ ih => by apply odd <;> exact ih _ <| by linarith only) n
variable (b c d : R)
section PreNormEDS
/-- The auxiliary sequence for a normalised EDS `W : β β R`, with initial values
| `W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`. -/
def preNormEDS' (b c d : R) : β β R
| 0 => 0
| Mathlib/NumberTheory/EllipticDivisibilitySequence.lean | 145 | 147 |
/-
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, Johannes HΓΆlzl, Mario Carneiro
-/
import Mathlib.Logic.Pairwise
import Mathlib.Data.Set.BooleanAlgebra
/-!
# The set lattice
This file is a collection of results on the complete atomic boolean algebra structure of `Set Ξ±`.
Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`.
## Main declarations
* `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `ββ s = β x β s, x` and
`ββ s = β x β s, x`.
* `Set.completeAtomicBooleanAlgebra`: `Set Ξ±` is a `CompleteAtomicBooleanAlgebra` with `β€ = β`,
`< = β`, `β = β©`, `β = βͺ`, `β¨
= β`, `β¨ = β` and `\` as the set difference.
See `Set.instBooleanAlgebra`.
* `Set.unionEqSigmaOfDisjoint`: Equivalence between `β i, t i` and `Ξ£ i, t i`, where `t` is an
indexed family of disjoint sets.
## Naming convention
In lemma names,
* `β i, s i` is called `iUnion`
* `β i, s i` is called `iInter`
* `β i j, s i j` is called `iUnionβ`. This is an `iUnion` inside an `iUnion`.
* `β i j, s i j` is called `iInterβ`. This is an `iInter` inside an `iInter`.
* `β i β s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnionβ`
where `j : i β s`.
* `β i β s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInterβ`
where `j : i β s`.
## Notation
* `β`: `Set.iUnion`
* `β`: `Set.iInter`
* `ββ`: `Set.sUnion`
* `ββ`: `Set.sInter`
-/
open Function Set
universe u
variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {ΞΉ ΞΉ' ΞΉβ : Sort*} {ΞΊ ΞΊβ ΞΊβ : ΞΉ β Sort*} {ΞΊ' : ΞΉ' β Sort*}
namespace Set
/-! ### Complete lattice and complete Boolean algebra instances -/
theorem mem_iUnionβ {x : Ξ³} {s : β i, ΞΊ i β Set Ξ³} : (x β β (i) (j), s i j) β β i j, x β s i j := by
simp_rw [mem_iUnion]
theorem mem_iInterβ {x : Ξ³} {s : β i, ΞΊ i β Set Ξ³} : (x β β (i) (j), s i j) β β i j, x β s i j := by
simp_rw [mem_iInter]
theorem mem_iUnion_of_mem {s : ΞΉ β Set Ξ±} {a : Ξ±} (i : ΞΉ) (ha : a β s i) : a β β i, s i :=
mem_iUnion.2 β¨i, haβ©
theorem mem_iUnionβ_of_mem {s : β i, ΞΊ i β Set Ξ±} {a : Ξ±} {i : ΞΉ} (j : ΞΊ i) (ha : a β s i j) :
a β β (i) (j), s i j :=
mem_iUnionβ.2 β¨i, j, haβ©
theorem mem_iInter_of_mem {s : ΞΉ β Set Ξ±} {a : Ξ±} (h : β i, a β s i) : a β β i, s i :=
mem_iInter.2 h
theorem mem_iInterβ_of_mem {s : β i, ΞΊ i β Set Ξ±} {a : Ξ±} (h : β i j, a β s i j) :
a β β (i) (j), s i j :=
mem_iInterβ.2 h
/-! ### Union and intersection over an indexed family of sets -/
@[congr]
theorem iUnion_congr_Prop {p q : Prop} {fβ : p β Set Ξ±} {fβ : q β Set Ξ±} (pq : p β q)
(f : β x, fβ (pq.mpr x) = fβ x) : iUnion fβ = iUnion fβ :=
iSup_congr_Prop pq f
@[congr]
theorem iInter_congr_Prop {p q : Prop} {fβ : p β Set Ξ±} {fβ : q β Set Ξ±} (pq : p β q)
(f : β x, fβ (pq.mpr x) = fβ x) : iInter fβ = iInter fβ :=
iInf_congr_Prop pq f
theorem iUnion_plift_up (f : PLift ΞΉ β Set Ξ±) : β i, f (PLift.up i) = β i, f i :=
iSup_plift_up _
theorem iUnion_plift_down (f : ΞΉ β Set Ξ±) : β i, f (PLift.down i) = β i, f i :=
iSup_plift_down _
theorem iInter_plift_up (f : PLift ΞΉ β Set Ξ±) : β i, f (PLift.up i) = β i, f i :=
iInf_plift_up _
theorem iInter_plift_down (f : ΞΉ β Set Ξ±) : β i, f (PLift.down i) = β i, f i :=
iInf_plift_down _
theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : β _ : p, s = if p then s else β
:=
iSup_eq_if _
theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p β Set Ξ±) :
β h : p, s h = if h : p then s h else β
:=
iSup_eq_dif _
theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : β _ : p, s = if p then s else univ :=
iInf_eq_if _
theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p β Set Ξ±) :
β h : p, s h = if h : p then s h else univ :=
_root_.iInf_eq_dif _
theorem exists_set_mem_of_union_eq_top {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β Set Ξ²)
(w : β i β t, s i = β€) (x : Ξ²) : β i β t, x β s i := by
have p : x β β€ := Set.mem_univ x
rw [β w, Set.mem_iUnion] at p
simpa using p
theorem nonempty_of_union_eq_top_of_nonempty {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β Set Ξ±)
(H : Nonempty Ξ±) (w : β i β t, s i = β€) : t.Nonempty := by
obtain β¨x, m, -β© := exists_set_mem_of_union_eq_top t s w H.some
exact β¨x, mβ©
theorem nonempty_of_nonempty_iUnion
{s : ΞΉ β Set Ξ±} (h_Union : (β i, s i).Nonempty) : Nonempty ΞΉ := by
obtain β¨x, hxβ© := h_Union
exact β¨Classical.choose <| mem_iUnion.mp hxβ©
theorem nonempty_of_nonempty_iUnion_eq_univ
{s : ΞΉ β Set Ξ±} [Nonempty Ξ±] (h_Union : β i, s i = univ) : Nonempty ΞΉ :=
nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty)
theorem setOf_exists (p : ΞΉ β Ξ² β Prop) : { x | β i, p i x } = β i, { x | p i x } :=
ext fun _ => mem_iUnion.symm
theorem setOf_forall (p : ΞΉ β Ξ² β Prop) : { x | β i, p i x } = β i, { x | p i x } :=
ext fun _ => mem_iInter.symm
theorem iUnion_subset {s : ΞΉ β Set Ξ±} {t : Set Ξ±} (h : β i, s i β t) : β i, s i β t :=
iSup_le h
theorem iUnionβ_subset {s : β i, ΞΊ i β Set Ξ±} {t : Set Ξ±} (h : β i j, s i j β t) :
β (i) (j), s i j β t :=
iUnion_subset fun x => iUnion_subset (h x)
theorem subset_iInter {t : Set Ξ²} {s : ΞΉ β Set Ξ²} (h : β i, t β s i) : t β β i, s i :=
le_iInf h
theorem subset_iInterβ {s : Set Ξ±} {t : β i, ΞΊ i β Set Ξ±} (h : β i j, s β t i j) :
s β β (i) (j), t i j :=
subset_iInter fun x => subset_iInter <| h x
@[simp]
theorem iUnion_subset_iff {s : ΞΉ β Set Ξ±} {t : Set Ξ±} : β i, s i β t β β i, s i β t :=
β¨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subsetβ©
theorem iUnionβ_subset_iff {s : β i, ΞΊ i β Set Ξ±} {t : Set Ξ±} :
β (i) (j), s i j β t β β i j, s i j β t := by simp_rw [iUnion_subset_iff]
@[simp]
theorem subset_iInter_iff {s : Set Ξ±} {t : ΞΉ β Set Ξ±} : (s β β i, t i) β β i, s β t i :=
le_iInf_iff
theorem subset_iInterβ_iff {s : Set Ξ±} {t : β i, ΞΊ i β Set Ξ±} :
(s β β (i) (j), t i j) β β i j, s β t i j := by simp_rw [subset_iInter_iff]
theorem subset_iUnion : β (s : ΞΉ β Set Ξ²) (i : ΞΉ), s i β β i, s i :=
le_iSup
theorem iInter_subset : β (s : ΞΉ β Set Ξ²) (i : ΞΉ), β i, s i β s i :=
iInf_le
lemma iInter_subset_iUnion [Nonempty ΞΉ] {s : ΞΉ β Set Ξ±} : β i, s i β β i, s i := iInf_le_iSup
theorem subset_iUnionβ {s : β i, ΞΊ i β Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : s i j β β (i') (j'), s i' j' :=
le_iSupβ i j
theorem iInterβ_subset {s : β i, ΞΊ i β Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : β (i) (j), s i j β s i j :=
iInfβ_le i j
/-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem subset_iUnion_of_subset {s : Set Ξ±} {t : ΞΉ β Set Ξ±} (i : ΞΉ) (h : s β t i) : s β β i, t i :=
le_iSup_of_le i h
/-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i`
explicit for this purpose. -/
theorem iInter_subset_of_subset {s : ΞΉ β Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (h : s i β t) :
β i, s i β t :=
iInf_le_of_le i h
/-- This rather trivial consequence of `subset_iUnionβ` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem subset_iUnionβ_of_subset {s : Set Ξ±} {t : β i, ΞΊ i β Set Ξ±} (i : ΞΉ) (j : ΞΊ i)
(h : s β t i j) : s β β (i) (j), t i j :=
le_iSupβ_of_le i j h
/-- This rather trivial consequence of `iInterβ_subset` is convenient with `apply`, and has `i` and
`j` explicit for this purpose. -/
theorem iInterβ_subset_of_subset {s : β i, ΞΊ i β Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (j : ΞΊ i)
(h : s i j β t) : β (i) (j), s i j β t :=
iInfβ_le_of_le i j h
theorem iUnion_mono {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : β i, s i β β i, t i :=
iSup_mono h
@[gcongr]
theorem iUnion_mono'' {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : iUnion s β iUnion t :=
iSup_mono h
theorem iUnionβ_mono {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j β t i j) :
β (i) (j), s i j β β (i) (j), t i j :=
iSupβ_mono h
theorem iInter_mono {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : β i, s i β β i, t i :=
iInf_mono h
@[gcongr]
theorem iInter_mono'' {s t : ΞΉ β Set Ξ±} (h : β i, s i β t i) : iInter s β iInter t :=
iInf_mono h
theorem iInterβ_mono {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j β t i j) :
β (i) (j), s i j β β (i) (j), t i j :=
iInfβ_mono h
theorem iUnion_mono' {s : ΞΉ β Set Ξ±} {t : ΞΉβ β Set Ξ±} (h : β i, β j, s i β t j) :
β i, s i β β i, t i :=
iSup_mono' h
theorem iUnionβ_mono' {s : β i, ΞΊ i β Set Ξ±} {t : β i', ΞΊ' i' β Set Ξ±}
(h : β i j, β i' j', s i j β t i' j') : β (i) (j), s i j β β (i') (j'), t i' j' :=
iSupβ_mono' h
theorem iInter_mono' {s : ΞΉ β Set Ξ±} {t : ΞΉ' β Set Ξ±} (h : β j, β i, s i β t j) :
β i, s i β β j, t j :=
Set.subset_iInter fun j =>
let β¨i, hiβ© := h j
iInter_subset_of_subset i hi
theorem iInterβ_mono' {s : β i, ΞΊ i β Set Ξ±} {t : β i', ΞΊ' i' β Set Ξ±}
(h : β i' j', β i j, s i j β t i' j') : β (i) (j), s i j β β (i') (j'), t i' j' :=
subset_iInterβ_iff.2 fun i' j' =>
let β¨_, _, hstβ© := h i' j'
(iInterβ_subset _ _).trans hst
theorem iUnionβ_subset_iUnion (ΞΊ : ΞΉ β Sort*) (s : ΞΉ β Set Ξ±) :
β (i) (_ : ΞΊ i), s i β β i, s i :=
iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl
theorem iInter_subset_iInterβ (ΞΊ : ΞΉ β Sort*) (s : ΞΉ β Set Ξ±) :
β i, s i β β (i) (_ : ΞΊ i), s i :=
iInter_mono fun _ => subset_iInter fun _ => Subset.rfl
theorem iUnion_setOf (P : ΞΉ β Ξ± β Prop) : β i, { x : Ξ± | P i x } = { x : Ξ± | β i, P i x } := by
ext
exact mem_iUnion
theorem iInter_setOf (P : ΞΉ β Ξ± β Prop) : β i, { x : Ξ± | P i x } = { x : Ξ± | β i, P i x } := by
ext
exact mem_iInter
theorem iUnion_congr_of_surjective {f : ΞΉ β Set Ξ±} {g : ΞΉβ β Set Ξ±} (h : ΞΉ β ΞΉβ) (h1 : Surjective h)
(h2 : β x, g (h x) = f x) : β x, f x = β y, g y :=
h1.iSup_congr h h2
theorem iInter_congr_of_surjective {f : ΞΉ β Set Ξ±} {g : ΞΉβ β Set Ξ±} (h : ΞΉ β ΞΉβ) (h1 : Surjective h)
(h2 : β x, g (h x) = f x) : β x, f x = β y, g y :=
h1.iInf_congr h h2
lemma iUnion_congr {s t : ΞΉ β Set Ξ±} (h : β i, s i = t i) : β i, s i = β i, t i := iSup_congr h
lemma iInter_congr {s t : ΞΉ β Set Ξ±} (h : β i, s i = t i) : β i, s i = β i, t i := iInf_congr h
lemma iUnionβ_congr {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j = t i j) :
β (i) (j), s i j = β (i) (j), t i j :=
iUnion_congr fun i => iUnion_congr <| h i
lemma iInterβ_congr {s t : β i, ΞΊ i β Set Ξ±} (h : β i j, s i j = t i j) :
β (i) (j), s i j = β (i) (j), t i j :=
iInter_congr fun i => iInter_congr <| h i
section Nonempty
variable [Nonempty ΞΉ] {f : ΞΉ β Set Ξ±} {s : Set Ξ±}
lemma iUnion_const (s : Set Ξ²) : β _ : ΞΉ, s = s := iSup_const
lemma iInter_const (s : Set Ξ²) : β _ : ΞΉ, s = s := iInf_const
lemma iUnion_eq_const (hf : β i, f i = s) : β i, f i = s :=
(iUnion_congr hf).trans <| iUnion_const _
lemma iInter_eq_const (hf : β i, f i = s) : β i, f i = s :=
(iInter_congr hf).trans <| iInter_const _
end Nonempty
@[simp]
theorem compl_iUnion (s : ΞΉ β Set Ξ²) : (β i, s i)αΆ = β i, (s i)αΆ :=
compl_iSup
theorem compl_iUnionβ (s : β i, ΞΊ i β Set Ξ±) : (β (i) (j), s i j)αΆ = β (i) (j), (s i j)αΆ := by
simp_rw [compl_iUnion]
@[simp]
theorem compl_iInter (s : ΞΉ β Set Ξ²) : (β i, s i)αΆ = β i, (s i)αΆ :=
compl_iInf
theorem compl_iInterβ (s : β i, ΞΊ i β Set Ξ±) : (β (i) (j), s i j)αΆ = β (i) (j), (s i j)αΆ := by
simp_rw [compl_iInter]
-- classical -- complete_boolean_algebra
theorem iUnion_eq_compl_iInter_compl (s : ΞΉ β Set Ξ²) : β i, s i = (β i, (s i)αΆ)αΆ := by
simp only [compl_iInter, compl_compl]
-- classical -- complete_boolean_algebra
theorem iInter_eq_compl_iUnion_compl (s : ΞΉ β Set Ξ²) : β i, s i = (β i, (s i)αΆ)αΆ := by
simp only [compl_iUnion, compl_compl]
theorem inter_iUnion (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s β© β i, t i) = β i, s β© t i :=
inf_iSup_eq _ _
theorem iUnion_inter (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) β© s = β i, t i β© s :=
iSup_inf_eq _ _
theorem iUnion_union_distrib (s : ΞΉ β Set Ξ²) (t : ΞΉ β Set Ξ²) :
β i, s i βͺ t i = (β i, s i) βͺ β i, t i :=
iSup_sup_eq
theorem iInter_inter_distrib (s : ΞΉ β Set Ξ²) (t : ΞΉ β Set Ξ²) :
β i, s i β© t i = (β i, s i) β© β i, t i :=
iInf_inf_eq
theorem union_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s βͺ β i, t i) = β i, s βͺ t i :=
sup_iSup
theorem iUnion_union [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) βͺ s = β i, t i βͺ s :=
iSup_sup
theorem inter_iInter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s β© β i, t i) = β i, s β© t i :=
inf_iInf
theorem iInter_inter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) β© s = β i, t i β© s :=
iInf_inf
theorem insert_iUnion [Nonempty ΞΉ] (x : Ξ²) (t : ΞΉ β Set Ξ²) :
insert x (β i, t i) = β i, insert x (t i) := by
simp_rw [β union_singleton, iUnion_union]
-- classical
theorem union_iInter (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s βͺ β i, t i) = β i, s βͺ t i :=
sup_iInf_eq _ _
theorem iInter_union (s : ΞΉ β Set Ξ²) (t : Set Ξ²) : (β i, s i) βͺ t = β i, s i βͺ t :=
iInf_sup_eq _ _
theorem insert_iInter (x : Ξ²) (t : ΞΉ β Set Ξ²) : insert x (β i, t i) = β i, insert x (t i) := by
simp_rw [β union_singleton, iInter_union]
theorem iUnion_diff (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (β i, t i) \ s = β i, t i \ s :=
iUnion_inter _ _
theorem diff_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s \ β i, t i) = β i, s \ t i := by
rw [diff_eq, compl_iUnion, inter_iInter]; rfl
theorem diff_iInter (s : Set Ξ²) (t : ΞΉ β Set Ξ²) : (s \ β i, t i) = β i, s \ t i := by
rw [diff_eq, compl_iInter, inter_iUnion]; rfl
theorem iUnion_inter_subset {ΞΉ Ξ±} {s t : ΞΉ β Set Ξ±} : β i, s i β© t i β (β i, s i) β© β i, t i :=
le_iSup_inf_iSup s t
theorem iUnion_inter_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· β€ Β·)] {s t : ΞΉ β Set Ξ±}
(hs : Monotone s) (ht : Monotone t) : β i, s i β© t i = (β i, s i) β© β i, t i :=
iSup_inf_of_monotone hs ht
theorem iUnion_inter_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· β€ Β·))] {s t : ΞΉ β Set Ξ±}
(hs : Antitone s) (ht : Antitone t) : β i, s i β© t i = (β i, s i) β© β i, t i :=
iSup_inf_of_antitone hs ht
theorem iInter_union_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· β€ Β·))] {s t : ΞΉ β Set Ξ±}
(hs : Monotone s) (ht : Monotone t) : β i, s i βͺ t i = (β i, s i) βͺ β i, t i :=
iInf_sup_of_monotone hs ht
theorem iInter_union_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· β€ Β·)] {s t : ΞΉ β Set Ξ±}
(hs : Antitone s) (ht : Antitone t) : β i, s i βͺ t i = (β i, s i) βͺ β i, t i :=
iInf_sup_of_antitone hs ht
/-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/
theorem iUnion_iInter_subset {s : ΞΉ β ΞΉ' β Set Ξ±} : (β j, β i, s i j) β β i, β j, s i j :=
iSup_iInf_le_iInf_iSup (flip s)
theorem iUnion_option {ΞΉ} (s : Option ΞΉ β Set Ξ±) : β o, s o = s none βͺ β i, s (some i) :=
iSup_option s
theorem iInter_option {ΞΉ} (s : Option ΞΉ β Set Ξ±) : β o, s o = s none β© β i, s (some i) :=
iInf_option s
section
variable (p : ΞΉ β Prop) [DecidablePred p]
theorem iUnion_dite (f : β i, p i β Set Ξ±) (g : β i, Β¬p i β Set Ξ±) :
β i, (if h : p i then f i h else g i h) = (β (i) (h : p i), f i h) βͺ β (i) (h : Β¬p i), g i h :=
iSup_dite _ _ _
theorem iUnion_ite (f g : ΞΉ β Set Ξ±) :
β i, (if p i then f i else g i) = (β (i) (_ : p i), f i) βͺ β (i) (_ : Β¬p i), g i :=
iUnion_dite _ _ _
theorem iInter_dite (f : β i, p i β Set Ξ±) (g : β i, Β¬p i β Set Ξ±) :
β i, (if h : p i then f i h else g i h) = (β (i) (h : p i), f i h) β© β (i) (h : Β¬p i), g i h :=
iInf_dite _ _ _
theorem iInter_ite (f g : ΞΉ β Set Ξ±) :
β i, (if p i then f i else g i) = (β (i) (_ : p i), f i) β© β (i) (_ : Β¬p i), g i :=
iInter_dite _ _ _
end
/-! ### Unions and intersections indexed by `Prop` -/
theorem iInter_false {s : False β Set Ξ±} : iInter s = univ :=
iInf_false
theorem iUnion_false {s : False β Set Ξ±} : iUnion s = β
:=
iSup_false
@[simp]
theorem iInter_true {s : True β Set Ξ±} : iInter s = s trivial :=
iInf_true
@[simp]
theorem iUnion_true {s : True β Set Ξ±} : iUnion s = s trivial :=
iSup_true
@[simp]
theorem iInter_exists {p : ΞΉ β Prop} {f : Exists p β Set Ξ±} :
β x, f x = β (i) (h : p i), f β¨i, hβ© :=
iInf_exists
@[simp]
theorem iUnion_exists {p : ΞΉ β Prop} {f : Exists p β Set Ξ±} :
β x, f x = β (i) (h : p i), f β¨i, hβ© :=
iSup_exists
@[simp]
theorem iUnion_empty : (β _ : ΞΉ, β
: Set Ξ±) = β
:=
iSup_bot
@[simp]
theorem iInter_univ : (β _ : ΞΉ, univ : Set Ξ±) = univ :=
iInf_top
section
variable {s : ΞΉ β Set Ξ±}
@[simp]
theorem iUnion_eq_empty : β i, s i = β
β β i, s i = β
:=
iSup_eq_bot
@[simp]
theorem iInter_eq_univ : β i, s i = univ β β i, s i = univ :=
iInf_eq_top
@[simp]
theorem nonempty_iUnion : (β i, s i).Nonempty β β i, (s i).Nonempty := by
simp [nonempty_iff_ne_empty]
theorem nonempty_biUnion {t : Set Ξ±} {s : Ξ± β Set Ξ²} :
(β i β t, s i).Nonempty β β i β t, (s i).Nonempty := by simp
theorem iUnion_nonempty_index (s : Set Ξ±) (t : s.Nonempty β Set Ξ²) :
β h, t h = β x β s, t β¨x, βΉ_βΊβ© :=
iSup_exists
end
@[simp]
theorem iInter_iInter_eq_left {b : Ξ²} {s : β x : Ξ², x = b β Set Ξ±} :
β (x) (h : x = b), s x h = s b rfl :=
iInf_iInf_eq_left
@[simp]
theorem iInter_iInter_eq_right {b : Ξ²} {s : β x : Ξ², b = x β Set Ξ±} :
β (x) (h : b = x), s x h = s b rfl :=
iInf_iInf_eq_right
@[simp]
theorem iUnion_iUnion_eq_left {b : Ξ²} {s : β x : Ξ², x = b β Set Ξ±} :
β (x) (h : x = b), s x h = s b rfl :=
iSup_iSup_eq_left
@[simp]
theorem iUnion_iUnion_eq_right {b : Ξ²} {s : β x : Ξ², b = x β Set Ξ±} :
β (x) (h : b = x), s x h = s b rfl :=
iSup_iSup_eq_right
theorem iInter_or {p q : Prop} (s : p β¨ q β Set Ξ±) :
β h, s h = (β h : p, s (Or.inl h)) β© β h : q, s (Or.inr h) :=
iInf_or
theorem iUnion_or {p q : Prop} (s : p β¨ q β Set Ξ±) :
β h, s h = (β i, s (Or.inl i)) βͺ β j, s (Or.inr j) :=
iSup_or
theorem iUnion_and {p q : Prop} (s : p β§ q β Set Ξ±) : β h, s h = β (hp) (hq), s β¨hp, hqβ© :=
iSup_and
theorem iInter_and {p q : Prop} (s : p β§ q β Set Ξ±) : β h, s h = β (hp) (hq), s β¨hp, hqβ© :=
iInf_and
theorem iUnion_comm (s : ΞΉ β ΞΉ' β Set Ξ±) : β (i) (i'), s i i' = β (i') (i), s i i' :=
iSup_comm
theorem iInter_comm (s : ΞΉ β ΞΉ' β Set Ξ±) : β (i) (i'), s i i' = β (i') (i), s i i' :=
iInf_comm
theorem iUnion_sigma {Ξ³ : Ξ± β Type*} (s : Sigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iSup_sigma
theorem iUnion_sigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : Sigma Ξ³, s ia.1 ia.2 :=
iSup_sigma' _
theorem iInter_sigma {Ξ³ : Ξ± β Type*} (s : Sigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iInf_sigma
theorem iInter_sigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : Sigma Ξ³, s ia.1 ia.2 :=
iInf_sigma' _
theorem iUnionβ_comm (s : β iβ, ΞΊβ iβ β β iβ, ΞΊβ iβ β Set Ξ±) :
β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ = β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ :=
iSupβ_comm _
theorem iInterβ_comm (s : β iβ, ΞΊβ iβ β β iβ, ΞΊβ iβ β Set Ξ±) :
β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ = β (iβ) (jβ) (iβ) (jβ), s iβ jβ iβ jβ :=
iInfβ_comm _
@[simp]
theorem biUnion_and (p : ΞΉ β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p x β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p x β§ q x y), s x y h =
β (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y β¨hx, hyβ© := by
simp only [iUnion_and, @iUnion_comm _ ΞΉ']
@[simp]
theorem biUnion_and' (p : ΞΉ' β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p y β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p y β§ q x y), s x y h =
β (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y β¨hy, hxβ© := by
simp only [iUnion_and, @iUnion_comm _ ΞΉ]
@[simp]
theorem biInter_and (p : ΞΉ β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p x β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p x β§ q x y), s x y h =
β (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y β¨hx, hyβ© := by
simp only [iInter_and, @iInter_comm _ ΞΉ']
@[simp]
theorem biInter_and' (p : ΞΉ' β Prop) (q : ΞΉ β ΞΉ' β Prop) (s : β x y, p y β§ q x y β Set Ξ±) :
β (x : ΞΉ) (y : ΞΉ') (h : p y β§ q x y), s x y h =
β (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y β¨hy, hxβ© := by
simp only [iInter_and, @iInter_comm _ ΞΉ]
@[simp]
theorem iUnion_iUnion_eq_or_left {b : Ξ²} {p : Ξ² β Prop} {s : β x : Ξ², x = b β¨ p x β Set Ξ±} :
β (x) (h), s x h = s b (Or.inl rfl) βͺ β (x) (h : p x), s x (Or.inr h) := by
simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left]
@[simp]
theorem iInter_iInter_eq_or_left {b : Ξ²} {p : Ξ² β Prop} {s : β x : Ξ², x = b β¨ p x β Set Ξ±} :
β (x) (h), s x h = s b (Or.inl rfl) β© β (x) (h : p x), s x (Or.inr h) := by
simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left]
lemma iUnion_sum {s : Ξ± β Ξ² β Set Ξ³} : β x, s x = (β x, s (.inl x)) βͺ β x, s (.inr x) := iSup_sum
lemma iInter_sum {s : Ξ± β Ξ² β Set Ξ³} : β x, s x = (β x, s (.inl x)) β© β x, s (.inr x) := iInf_sum
theorem iUnion_psigma {Ξ³ : Ξ± β Type*} (s : PSigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iSup_psigma _
/-- A reversed version of `iUnion_psigma` with a curried map. -/
theorem iUnion_psigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : PSigma Ξ³, s ia.1 ia.2 :=
iSup_psigma' _
theorem iInter_psigma {Ξ³ : Ξ± β Type*} (s : PSigma Ξ³ β Set Ξ²) : β ia, s ia = β i, β a, s β¨i, aβ© :=
iInf_psigma _
/-- A reversed version of `iInter_psigma` with a curried map. -/
theorem iInter_psigma' {Ξ³ : Ξ± β Type*} (s : β i, Ξ³ i β Set Ξ²) :
β i, β a, s i a = β ia : PSigma Ξ³, s ia.1 ia.2 :=
iInf_psigma' _
/-! ### Bounded unions and intersections -/
/-- A specialization of `mem_iUnionβ`. -/
theorem mem_biUnion {s : Set Ξ±} {t : Ξ± β Set Ξ²} {x : Ξ±} {y : Ξ²} (xs : x β s) (ytx : y β t x) :
y β β x β s, t x :=
mem_iUnionβ_of_mem xs ytx
/-- A specialization of `mem_iInterβ`. -/
theorem mem_biInter {s : Set Ξ±} {t : Ξ± β Set Ξ²} {y : Ξ²} (h : β x β s, y β t x) :
y β β x β s, t x :=
mem_iInterβ_of_mem h
/-- A specialization of `subset_iUnionβ`. -/
theorem subset_biUnion_of_mem {s : Set Ξ±} {u : Ξ± β Set Ξ²} {x : Ξ±} (xs : x β s) :
u x β β x β s, u x :=
subset_iUnionβ (s := fun i _ => u i) x xs
/-- A specialization of `iInterβ_subset`. -/
theorem biInter_subset_of_mem {s : Set Ξ±} {t : Ξ± β Set Ξ²} {x : Ξ±} (xs : x β s) :
β x β s, t x β t x :=
iInterβ_subset x xs
lemma biInter_subset_biUnion {s : Set Ξ±} (hs : s.Nonempty) {t : Ξ± β Set Ξ²} :
β x β s, t x β β x β s, t x := biInf_le_biSup hs
theorem biUnion_subset_biUnion_left {s s' : Set Ξ±} {t : Ξ± β Set Ξ²} (h : s β s') :
β x β s, t x β β x β s', t x :=
iUnionβ_subset fun _ hx => subset_biUnion_of_mem <| h hx
theorem biInter_subset_biInter_left {s s' : Set Ξ±} {t : Ξ± β Set Ξ²} (h : s' β s) :
β x β s, t x β β x β s', t x :=
subset_iInterβ fun _ hx => biInter_subset_of_mem <| h hx
theorem biUnion_mono {s s' : Set Ξ±} {t t' : Ξ± β Set Ξ²} (hs : s' β s) (h : β x β s, t x β t' x) :
β x β s', t x β β x β s, t' x :=
(biUnion_subset_biUnion_left hs).trans <| iUnionβ_mono h
theorem biInter_mono {s s' : Set Ξ±} {t t' : Ξ± β Set Ξ²} (hs : s β s') (h : β x β s, t x β t' x) :
β x β s', t x β β x β s, t' x :=
(biInter_subset_biInter_left hs).trans <| iInterβ_mono h
theorem biUnion_eq_iUnion (s : Set Ξ±) (t : β x β s, Set Ξ²) :
β x β s, t x βΉ_βΊ = β x : s, t x x.2 :=
iSup_subtype'
theorem biInter_eq_iInter (s : Set Ξ±) (t : β x β s, Set Ξ²) :
β x β s, t x βΉ_βΊ = β x : s, t x x.2 :=
iInf_subtype'
@[simp] lemma biUnion_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : β a β s, t = t :=
biSup_const hs
@[simp] lemma biInter_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : β a β s, t = t :=
biInf_const hs
theorem iUnion_subtype (p : Ξ± β Prop) (s : { x // p x } β Set Ξ²) :
β x : { x // p x }, s x = β (x) (hx : p x), s β¨x, hxβ© :=
iSup_subtype
theorem iInter_subtype (p : Ξ± β Prop) (s : { x // p x } β Set Ξ²) :
β x : { x // p x }, s x = β (x) (hx : p x), s β¨x, hxβ© :=
iInf_subtype
theorem biInter_empty (u : Ξ± β Set Ξ²) : β x β (β
: Set Ξ±), u x = univ :=
iInf_emptyset
theorem biInter_univ (u : Ξ± β Set Ξ²) : β x β @univ Ξ±, u x = β x, u x :=
iInf_univ
@[simp]
theorem biUnion_self (s : Set Ξ±) : β x β s, s = s :=
Subset.antisymm (iUnionβ_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx
@[simp]
theorem iUnion_nonempty_self (s : Set Ξ±) : β _ : s.Nonempty, s = s := by
rw [iUnion_nonempty_index, biUnion_self]
theorem biInter_singleton (a : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a} : Set Ξ±), s x = s a :=
iInf_singleton
theorem biInter_union (s t : Set Ξ±) (u : Ξ± β Set Ξ²) :
β x β s βͺ t, u x = (β x β s, u x) β© β x β t, u x :=
iInf_union
theorem biInter_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β insert a s, t x = t a β© β x β s, t x := by simp
theorem biInter_pair (a b : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a, b} : Set Ξ±), s x = s a β© s b := by
rw [biInter_insert, biInter_singleton]
theorem biInter_inter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β Set Ξ±) (t : Set Ξ±) :
β i β s, f i β© t = (β i β s, f i) β© t := by
haveI : Nonempty s := hs.to_subtype
simp [biInter_eq_iInter, β iInter_inter]
theorem inter_biInter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β Set Ξ±) (t : Set Ξ±) :
β i β s, t β© f i = t β© β i β s, f i := by
rw [inter_comm, β biInter_inter hs]
simp [inter_comm]
theorem biUnion_empty (s : Ξ± β Set Ξ²) : β x β (β
: Set Ξ±), s x = β
:=
iSup_emptyset
theorem biUnion_univ (s : Ξ± β Set Ξ²) : β x β @univ Ξ±, s x = β x, s x :=
iSup_univ
theorem biUnion_singleton (a : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a} : Set Ξ±), s x = s a :=
iSup_singleton
@[simp]
theorem biUnion_of_singleton (s : Set Ξ±) : β x β s, {x} = s :=
ext <| by simp
theorem biUnion_union (s t : Set Ξ±) (u : Ξ± β Set Ξ²) :
β x β s βͺ t, u x = (β x β s, u x) βͺ β x β t, u x :=
iSup_union
@[simp]
theorem iUnion_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β Set Ξ²) :
β i, f i = β i β s, f β¨i, βΉi β sβΊβ© :=
iUnion_subtype _ _
@[simp]
theorem iInter_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β Set Ξ²) :
β i, f i = β i β s, f β¨i, βΉi β sβΊβ© :=
iInter_subtype _ _
theorem biUnion_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β insert a s, t x = t a βͺ β x β s, t x := by simp
theorem biUnion_pair (a b : Ξ±) (s : Ξ± β Set Ξ²) : β x β ({a, b} : Set Ξ±), s x = s a βͺ s b := by
simp
theorem inter_iUnionβ (s : Set Ξ±) (t : β i, ΞΊ i β Set Ξ±) :
(s β© β (i) (j), t i j) = β (i) (j), s β© t i j := by simp only [inter_iUnion]
theorem iUnionβ_inter (s : β i, ΞΊ i β Set Ξ±) (t : Set Ξ±) :
(β (i) (j), s i j) β© t = β (i) (j), s i j β© t := by simp_rw [iUnion_inter]
theorem union_iInterβ (s : Set Ξ±) (t : β i, ΞΊ i β Set Ξ±) :
(s βͺ β (i) (j), t i j) = β (i) (j), s βͺ t i j := by simp_rw [union_iInter]
theorem iInterβ_union (s : β i, ΞΊ i β Set Ξ±) (t : Set Ξ±) :
(β (i) (j), s i j) βͺ t = β (i) (j), s i j βͺ t := by simp_rw [iInter_union]
theorem mem_sUnion_of_mem {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x β t) (ht : t β S) :
x β ββ S :=
β¨t, ht, hxβ©
-- is this theorem really necessary?
theorem not_mem_of_not_mem_sUnion {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x β ββ S)
(ht : t β S) : x β t := fun h => hx β¨t, ht, hβ©
theorem sInter_subset_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t β S) : ββ S β t :=
sInf_le tS
theorem subset_sUnion_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t β S) : t β ββ S :=
le_sSup tS
theorem subset_sUnion_of_subset {s : Set Ξ±} (t : Set (Set Ξ±)) (u : Set Ξ±) (hβ : s β u)
(hβ : u β t) : s β ββ t :=
Subset.trans hβ (subset_sUnion_of_mem hβ)
theorem sUnion_subset {S : Set (Set Ξ±)} {t : Set Ξ±} (h : β t' β S, t' β t) : ββ S β t :=
sSup_le h
@[simp]
theorem sUnion_subset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : ββ s β t β β t' β s, t' β t :=
sSup_le_iff
/-- `sUnion` is monotone under taking a subset of each set. -/
lemma sUnion_mono_subsets {s : Set (Set Ξ±)} {f : Set Ξ± β Set Ξ±} (hf : β t : Set Ξ±, t β f t) :
ββ s β ββ (f '' s) :=
fun _ β¨t, htx, hxtβ© β¦ β¨f t, mem_image_of_mem f htx, hf t hxtβ©
/-- `sUnion` is monotone under taking a superset of each set. -/
lemma sUnion_mono_supsets {s : Set (Set Ξ±)} {f : Set Ξ± β Set Ξ±} (hf : β t : Set Ξ±, f t β t) :
ββ (f '' s) β ββ s :=
-- If t β f '' s is arbitrary; t = f u for some u : Set Ξ±.
fun _ β¨_, β¨u, hus, hutβ©, hxtβ© β¦ β¨u, hus, (hut βΈ hf u) hxtβ©
theorem subset_sInter {S : Set (Set Ξ±)} {t : Set Ξ±} (h : β t' β S, t β t') : t β ββ S :=
le_sInf h
@[simp]
theorem subset_sInter_iff {S : Set (Set Ξ±)} {t : Set Ξ±} : t β ββ S β β t' β S, t β t' :=
le_sInf_iff
@[gcongr]
theorem sUnion_subset_sUnion {S T : Set (Set Ξ±)} (h : S β T) : ββ S β ββ T :=
sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs)
@[gcongr]
theorem sInter_subset_sInter {S T : Set (Set Ξ±)} (h : S β T) : ββ T β ββ S :=
subset_sInter fun _ hs => sInter_subset_of_mem (h hs)
@[simp]
theorem sUnion_empty : ββ β
= (β
: Set Ξ±) :=
sSup_empty
@[simp]
theorem sInter_empty : ββ β
= (univ : Set Ξ±) :=
sInf_empty
@[simp]
theorem sUnion_singleton (s : Set Ξ±) : ββ {s} = s :=
sSup_singleton
@[simp]
theorem sInter_singleton (s : Set Ξ±) : ββ {s} = s :=
sInf_singleton
@[simp]
theorem sUnion_eq_empty {S : Set (Set Ξ±)} : ββ S = β
β β s β S, s = β
:=
sSup_eq_bot
@[simp]
theorem sInter_eq_univ {S : Set (Set Ξ±)} : ββ S = univ β β s β S, s = univ :=
sInf_eq_top
theorem subset_powerset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : s β π« t β ββ s β t :=
sUnion_subset_iff.symm
/-- `ββ` and `π«` form a Galois connection. -/
theorem sUnion_powerset_gc :
GaloisConnection (ββ Β· : Set (Set Ξ±) β Set Ξ±) (π« Β· : Set Ξ± β Set (Set Ξ±)) :=
gc_sSup_Iic
/-- `ββ` and `π«` form a Galois insertion. -/
def sUnionPowersetGI :
GaloisInsertion (ββ Β· : Set (Set Ξ±) β Set Ξ±) (π« Β· : Set Ξ± β Set (Set Ξ±)) :=
gi_sSup_Iic
@[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI
/-- If all sets in a collection are either `β
` or `Set.univ`, then so is their union. -/
theorem sUnion_mem_empty_univ {S : Set (Set Ξ±)} (h : S β {β
, univ}) :
ββ S β ({β
, univ} : Set (Set Ξ±)) := by
simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall]
rintro β¨s, hs, hneβ©
obtain rfl : s = univ := (h hs).resolve_left hne
exact univ_subset_iff.1 <| subset_sUnion_of_mem hs
@[simp]
theorem nonempty_sUnion {S : Set (Set Ξ±)} : (ββ S).Nonempty β β s β S, Set.Nonempty s := by
simp [nonempty_iff_ne_empty]
theorem Nonempty.of_sUnion {s : Set (Set Ξ±)} (h : (ββ s).Nonempty) : s.Nonempty :=
let β¨s, hs, _β© := nonempty_sUnion.1 h
β¨s, hsβ©
theorem Nonempty.of_sUnion_eq_univ [Nonempty Ξ±] {s : Set (Set Ξ±)} (h : ββ s = univ) : s.Nonempty :=
Nonempty.of_sUnion <| h.symm βΈ univ_nonempty
theorem sUnion_union (S T : Set (Set Ξ±)) : ββ (S βͺ T) = ββ S βͺ ββ T :=
sSup_union
theorem sInter_union (S T : Set (Set Ξ±)) : ββ (S βͺ T) = ββ S β© ββ T :=
sInf_union
@[simp]
theorem sUnion_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : ββ insert s T = s βͺ ββ T :=
sSup_insert
@[simp]
theorem sInter_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : ββ insert s T = s β© ββ T :=
sInf_insert
@[simp]
theorem sUnion_diff_singleton_empty (s : Set (Set Ξ±)) : ββ (s \ {β
}) = ββ s :=
sSup_diff_singleton_bot s
@[simp]
theorem sInter_diff_singleton_univ (s : Set (Set Ξ±)) : ββ (s \ {univ}) = ββ s :=
sInf_diff_singleton_top s
theorem sUnion_pair (s t : Set Ξ±) : ββ {s, t} = s βͺ t :=
sSup_pair
theorem sInter_pair (s t : Set Ξ±) : ββ {s, t} = s β© t :=
sInf_pair
@[simp]
theorem sUnion_image (f : Ξ± β Set Ξ²) (s : Set Ξ±) : ββ (f '' s) = β a β s, f a :=
sSup_image
@[simp]
theorem sInter_image (f : Ξ± β Set Ξ²) (s : Set Ξ±) : ββ (f '' s) = β a β s, f a :=
sInf_image
@[simp]
lemma sUnion_image2 (f : Ξ± β Ξ² β Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) :
ββ (image2 f s t) = β (a β s) (b β t), f a b := sSup_image2
@[simp]
lemma sInter_image2 (f : Ξ± β Ξ² β Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) :
ββ (image2 f s t) = β (a β s) (b β t), f a b := sInf_image2
@[simp]
theorem sUnion_range (f : ΞΉ β Set Ξ²) : ββ range f = β x, f x :=
rfl
@[simp]
theorem sInter_range (f : ΞΉ β Set Ξ²) : ββ range f = β x, f x :=
rfl
theorem iUnion_eq_univ_iff {f : ΞΉ β Set Ξ±} : β i, f i = univ β β x, β i, x β f i := by
simp only [eq_univ_iff_forall, mem_iUnion]
theorem iUnionβ_eq_univ_iff {s : β i, ΞΊ i β Set Ξ±} :
β (i) (j), s i j = univ β β a, β i j, a β s i j := by
simp only [iUnion_eq_univ_iff, mem_iUnion]
theorem sUnion_eq_univ_iff {c : Set (Set Ξ±)} : ββ c = univ β β a, β b β c, a β b := by
simp only [eq_univ_iff_forall, mem_sUnion]
-- classical
theorem iInter_eq_empty_iff {f : ΞΉ β Set Ξ±} : β i, f i = β
β β x, β i, x β f i := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
theorem iInterβ_eq_empty_iff {s : β i, ΞΊ i β Set Ξ±} :
β (i) (j), s i j = β
β β a, β i j, a β s i j := by
simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall]
-- classical
theorem sInter_eq_empty_iff {c : Set (Set Ξ±)} : ββ c = β
β β a, β b β c, a β b := by
simp [Set.eq_empty_iff_forall_not_mem]
-- classical
@[simp]
theorem nonempty_iInter {f : ΞΉ β Set Ξ±} : (β i, f i).Nonempty β β x, β i, x β f i := by
simp [nonempty_iff_ne_empty, iInter_eq_empty_iff]
-- classical
theorem nonempty_iInterβ {s : β i, ΞΊ i β Set Ξ±} :
(β (i) (j), s i j).Nonempty β β a, β i j, a β s i j := by
simp
-- classical
@[simp]
theorem nonempty_sInter {c : Set (Set Ξ±)} : (ββ c).Nonempty β β a, β b β c, a β b := by
simp [nonempty_iff_ne_empty, sInter_eq_empty_iff]
-- classical
theorem compl_sUnion (S : Set (Set Ξ±)) : (ββ S)αΆ = ββ (compl '' S) :=
ext fun x => by simp
-- classical
theorem sUnion_eq_compl_sInter_compl (S : Set (Set Ξ±)) : ββ S = (ββ (compl '' S))αΆ := by
rw [β compl_compl (ββ S), compl_sUnion]
-- classical
theorem compl_sInter (S : Set (Set Ξ±)) : (ββ S)αΆ = ββ (compl '' S) := by
rw [sUnion_eq_compl_sInter_compl, compl_compl_image]
-- classical
theorem sInter_eq_compl_sUnion_compl (S : Set (Set Ξ±)) : ββ S = (ββ (compl '' S))αΆ := by
rw [β compl_compl (ββ S), compl_sInter]
theorem inter_empty_of_inter_sUnion_empty {s t : Set Ξ±} {S : Set (Set Ξ±)} (hs : t β S)
(h : s β© ββ S = β
) : s β© t = β
:=
eq_empty_of_subset_empty <| by
rw [β h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs)
theorem range_sigma_eq_iUnion_range {Ξ³ : Ξ± β Type*} (f : Sigma Ξ³ β Ξ²) :
range f = β a, range fun b => f β¨a, bβ© :=
Set.ext <| by simp
theorem iUnion_eq_range_sigma (s : Ξ± β Set Ξ²) : β i, s i = range fun a : Ξ£i, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_eq_range_psigma (s : ΞΉ β Set Ξ²) : β i, s i = range fun a : Ξ£'i, s i => a.2 := by
simp [Set.ext_iff]
theorem iUnion_image_preimage_sigma_mk_eq_self {ΞΉ : Type*} {Ο : ΞΉ β Type*} (s : Set (Sigma Ο)) :
β i, Sigma.mk i '' (Sigma.mk i β»ΒΉ' s) = s := by
ext x
simp only [mem_iUnion, mem_image, mem_preimage]
constructor
Β· rintro β¨i, a, h, rflβ©
exact h
Β· intro h
obtain β¨i, aβ© := x
exact β¨i, a, h, rflβ©
theorem Sigma.univ (X : Ξ± β Type*) : (Set.univ : Set (Ξ£a, X a)) = β a, range (Sigma.mk a) :=
Set.ext fun x =>
iff_of_true trivial β¨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta xβ©
alias sUnion_mono := sUnion_subset_sUnion
alias sInter_mono := sInter_subset_sInter
theorem iUnion_subset_iUnion_const {s : Set Ξ±} (h : ΞΉ β ΞΉβ) : β _ : ΞΉ, s β β _ : ΞΉβ, s :=
iSup_const_mono (Ξ± := Set Ξ±) h
@[simp]
theorem iUnion_singleton_eq_range (f : Ξ± β Ξ²) : β x : Ξ±, {f x} = range f := by
ext x
simp [@eq_comm _ x]
theorem iUnion_insert_eq_range_union_iUnion {ΞΉ : Type*} (x : ΞΉ β Ξ²) (t : ΞΉ β Set Ξ²) :
β i, insert (x i) (t i) = range x βͺ β i, t i := by
simp_rw [β union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range]
theorem iUnion_of_singleton (Ξ± : Type*) : (β x, {x} : Set Ξ±) = univ := by simp [Set.ext_iff]
theorem iUnion_of_singleton_coe (s : Set Ξ±) : β i : s, ({(i : Ξ±)} : Set Ξ±) = s := by simp
theorem sUnion_eq_biUnion {s : Set (Set Ξ±)} : ββ s = β (i : Set Ξ±) (_ : i β s), i := by
rw [β sUnion_image, image_id']
theorem sInter_eq_biInter {s : Set (Set Ξ±)} : ββ s = β (i : Set Ξ±) (_ : i β s), i := by
rw [β sInter_image, image_id']
theorem sUnion_eq_iUnion {s : Set (Set Ξ±)} : ββ s = β i : s, i := by
simp only [β sUnion_range, Subtype.range_coe]
theorem sInter_eq_iInter {s : Set (Set Ξ±)} : ββ s = β i : s, i := by
simp only [β sInter_range, Subtype.range_coe]
@[simp]
theorem iUnion_of_empty [IsEmpty ΞΉ] (s : ΞΉ β Set Ξ±) : β i, s i = β
:=
iSup_of_empty _
@[simp]
theorem iInter_of_empty [IsEmpty ΞΉ] (s : ΞΉ β Set Ξ±) : β i, s i = univ :=
iInf_of_empty _
theorem union_eq_iUnion {sβ sβ : Set Ξ±} : sβ βͺ sβ = β b : Bool, cond b sβ sβ :=
sup_eq_iSup sβ sβ
theorem inter_eq_iInter {sβ sβ : Set Ξ±} : sβ β© sβ = β b : Bool, cond b sβ sβ :=
inf_eq_iInf sβ sβ
theorem sInter_union_sInter {S T : Set (Set Ξ±)} :
ββ S βͺ ββ T = β p β S ΓΛ’ T, (p : Set Ξ± Γ Set Ξ±).1 βͺ p.2 :=
sInf_sup_sInf
theorem sUnion_inter_sUnion {s t : Set (Set Ξ±)} :
ββ s β© ββ t = β p β s ΓΛ’ t, (p : Set Ξ± Γ Set Ξ±).1 β© p.2 :=
sSup_inf_sSup
theorem biUnion_iUnion (s : ΞΉ β Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β β i, s i, t x = β (i) (x β s i), t x := by simp [@iUnion_comm _ ΞΉ]
theorem biInter_iUnion (s : ΞΉ β Set Ξ±) (t : Ξ± β Set Ξ²) :
β x β β i, s i, t x = β (i) (x β s i), t x := by simp [@iInter_comm _ ΞΉ]
theorem sUnion_iUnion (s : ΞΉ β Set (Set Ξ±)) : ββ β i, s i = β i, ββ s i := by
simp only [sUnion_eq_biUnion, biUnion_iUnion]
theorem sInter_iUnion (s : ΞΉ β Set (Set Ξ±)) : ββ β i, s i = β i, ββ s i := by
simp only [sInter_eq_biInter, biInter_iUnion]
theorem iUnion_range_eq_sUnion {Ξ± Ξ² : Type*} (C : Set (Set Ξ±)) {f : β s : C, Ξ² β (s : Type _)}
(hf : β s : C, Surjective (f s)) : β y : Ξ², range (fun s : C => (f s y).val) = ββ C := by
ext x; constructor
Β· rintro β¨s, β¨y, rflβ©, β¨s, hsβ©, rflβ©
refine β¨_, hs, ?_β©
exact (f β¨s, hsβ© y).2
Β· rintro β¨s, hs, hxβ©
obtain β¨y, hyβ© := hf β¨s, hsβ© β¨x, hxβ©
refine β¨_, β¨y, rflβ©, β¨s, hsβ©, ?_β©
exact congr_arg Subtype.val hy
theorem iUnion_range_eq_iUnion (C : ΞΉ β Set Ξ±) {f : β x : ΞΉ, Ξ² β C x}
(hf : β x : ΞΉ, Surjective (f x)) : β y : Ξ², range (fun x : ΞΉ => (f x y).val) = β x, C x := by
ext x; rw [mem_iUnion, mem_iUnion]; constructor
Β· rintro β¨y, i, rflβ©
exact β¨i, (f i y).2β©
Β· rintro β¨i, hxβ©
obtain β¨y, hyβ© := hf i β¨x, hxβ©
exact β¨y, i, congr_arg Subtype.val hyβ©
theorem union_distrib_iInter_left (s : ΞΉ β Set Ξ±) (t : Set Ξ±) : (t βͺ β i, s i) = β i, t βͺ s i :=
sup_iInf_eq _ _
theorem union_distrib_iInterβ_left (s : Set Ξ±) (t : β i, ΞΊ i β Set Ξ±) :
(s βͺ β (i) (j), t i j) = β (i) (j), s βͺ t i j := by simp_rw [union_distrib_iInter_left]
theorem union_distrib_iInter_right (s : ΞΉ β Set Ξ±) (t : Set Ξ±) : (β i, s i) βͺ t = β i, s i βͺ t :=
iInf_sup_eq _ _
theorem union_distrib_iInterβ_right (s : β i, ΞΊ i β Set Ξ±) (t : Set Ξ±) :
(β (i) (j), s i j) βͺ t = β (i) (j), s i j βͺ t := by simp_rw [union_distrib_iInter_right]
lemma biUnion_lt_eq_iUnion [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m < n), s m = β n, s n := biSup_lt_eq_iSup
lemma biUnion_le_eq_iUnion [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β€ n), s m = β n, s n := biSup_le_eq_iSup
lemma biInter_lt_eq_iInter [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m < n), s m = β (n), s n := biInf_lt_eq_iInf
lemma biInter_le_eq_iInter [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β€ n), s m = β (n), s n := biInf_le_eq_iInf
lemma biUnion_gt_eq_iUnion [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m > n), s m = β n, s n := biSup_gt_eq_iSup
lemma biUnion_ge_eq_iUnion [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β₯ n), s m = β n, s n := biSup_ge_eq_iSup
lemma biInter_gt_eq_iInf [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m > n), s m = β n, s n := biInf_gt_eq_iInf
lemma biInter_ge_eq_iInf [Preorder Ξ±] {s : Ξ± β Set Ξ²} :
β (n) (m β₯ n), s m = β n, s n := biInf_ge_eq_iInf
section le
variable {ΞΉ : Type*} [PartialOrder ΞΉ] (s : ΞΉ β Set Ξ±) (i : ΞΉ)
theorem biUnion_le : (β j β€ i, s j) = (β j < i, s j) βͺ s i :=
biSup_le_eq_sup s i
theorem biInter_le : (β j β€ i, s j) = (β j < i, s j) β© s i :=
biInf_le_eq_inf s i
theorem biUnion_ge : (β j β₯ i, s j) = s i βͺ β j > i, s j :=
biSup_ge_eq_sup s i
theorem biInter_ge : (β j β₯ i, s j) = s i β© β j > i, s j :=
biInf_ge_eq_inf s i
end le
section Pi
variable {Ο : Ξ± β Type*}
theorem pi_def (i : Set Ξ±) (s : β a, Set (Ο a)) : pi i s = β a β i, eval a β»ΒΉ' s a := by
ext
simp
theorem univ_pi_eq_iInter (t : β i, Set (Ο i)) : pi univ t = β i, eval i β»ΒΉ' t i := by
simp only [pi_def, iInter_true, mem_univ]
theorem pi_diff_pi_subset (i : Set Ξ±) (s t : β a, Set (Ο a)) :
pi i s \ pi i t β β a β i, eval a β»ΒΉ' (s a \ t a) := by
refine diff_subset_comm.2 fun x hx a ha => ?_
simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not,
eval_apply] at hx
exact hx.2 _ ha (hx.1 _ ha)
theorem iUnion_univ_pi {ΞΉ : Ξ± β Type*} (t : (a : Ξ±) β ΞΉ a β Set (Ο a)) :
β x : (a : Ξ±) β ΞΉ a, pi univ (fun a => t a (x a)) = pi univ fun a => β j : ΞΉ a, t a j := by
ext
simp [Classical.skolem]
end Pi
section Directed
theorem directedOn_iUnion {r} {f : ΞΉ β Set Ξ±} (hd : Directed (Β· β Β·) f)
(h : β x, DirectedOn r (f x)) : DirectedOn r (β x, f x) := by
simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp]
exact fun aβ bβ fbβ aβ bβ fbβ =>
let β¨z, zbβ, zbββ© := hd bβ bβ
let β¨x, xf, xaβ, xaββ© := h z aβ (zbβ fbβ) aβ (zbβ fbβ)
β¨x, β¨z, xfβ©, xaβ, xaββ©
theorem directedOn_sUnion {r} {S : Set (Set Ξ±)} (hd : DirectedOn (Β· β Β·) S)
(h : β x β S, DirectedOn r x) : DirectedOn r (ββ S) := by
rw [sUnion_eq_iUnion]
exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i β¦ h i.1 i.2)
theorem pairwise_iUnionβ {S : Set (Set Ξ±)} (hd : DirectedOn (Β· β Β·) S)
(r : Ξ± β Ξ± β Prop) (h : β s β S, s.Pairwise r) : (β s β S, s).Pairwise r := by
simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp]
intro x S hS hx y T hT hy hne
obtain β¨U, hU, hSU, hTUβ© := hd S hS T hT
exact h U hU (hSU hx) (hTU hy) hne
end Directed
end Set
namespace Function
namespace Surjective
theorem iUnion_comp {f : ΞΉ β ΞΉβ} (hf : Surjective f) (g : ΞΉβ β Set Ξ±) : β x, g (f x) = β y, g y :=
hf.iSup_comp g
theorem iInter_comp {f : ΞΉ β ΞΉβ} (hf : Surjective f) (g : ΞΉβ β Set Ξ±) : β x, g (f x) = β y, g y :=
hf.iInf_comp g
end Surjective
end Function
| /-!
### Disjoint sets
| Mathlib/Data/Set/Lattice.lean | 1,188 | 1,189 |
/-
Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Robert Y. Lewis, Johannes HΓΆlzl, Mario Carneiro, SΓ©bastien GouΓ«zel
-/
import Mathlib.Topology.Bornology.Constructions
import Mathlib.Topology.MetricSpace.Pseudo.Defs
import Mathlib.Topology.UniformSpace.UniformEmbedding
/-!
# Products of pseudometric spaces and other constructions
This file constructs the supremum distance on binary products of pseudometric spaces and provides
instances for type synonyms.
-/
open Bornology Filter Metric Set Topology
open scoped NNReal
variable {Ξ± Ξ² : Type*} [PseudoMetricSpace Ξ±]
/-- Pseudometric space structure pulled back by a function. -/
abbrev PseudoMetricSpace.induced {Ξ± Ξ²} (f : Ξ± β Ξ²) (m : PseudoMetricSpace Ξ²) :
PseudoMetricSpace Ξ± where
dist x y := dist (f x) (f y)
dist_self _ := dist_self _
dist_comm _ _ := dist_comm _ _
dist_triangle _ _ _ := dist_triangle _ _ _
edist x y := edist (f x) (f y)
edist_dist _ _ := edist_dist _ _
toUniformSpace := UniformSpace.comap f m.toUniformSpace
uniformity_dist := (uniformity_basis_dist.comap _).eq_biInf
toBornology := Bornology.induced f
cobounded_sets := Set.ext fun s => mem_comap_iff_compl.trans <| by
simp only [β isBounded_def, isBounded_iff, forall_mem_image, mem_setOf]
/-- Pull back a pseudometric space structure by an inducing map. This is a version of
`PseudoMetricSpace.induced` useful in case if the domain already has a `TopologicalSpace`
structure. -/
def Topology.IsInducing.comapPseudoMetricSpace {Ξ± Ξ² : Type*} [TopologicalSpace Ξ±]
[m : PseudoMetricSpace Ξ²] {f : Ξ± β Ξ²} (hf : IsInducing f) : PseudoMetricSpace Ξ± :=
.replaceTopology (.induced f m) hf.eq_induced
@[deprecated (since := "2024-10-28")]
alias Inducing.comapPseudoMetricSpace := IsInducing.comapPseudoMetricSpace
/-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of
`PseudoMetricSpace.induced` useful in case if the domain already has a `UniformSpace`
structure. -/
def IsUniformInducing.comapPseudoMetricSpace {Ξ± Ξ²} [UniformSpace Ξ±] [m : PseudoMetricSpace Ξ²]
(f : Ξ± β Ξ²) (h : IsUniformInducing f) : PseudoMetricSpace Ξ± :=
.replaceUniformity (.induced f m) h.comap_uniformity.symm
instance Subtype.pseudoMetricSpace {p : Ξ± β Prop} : PseudoMetricSpace (Subtype p) :=
PseudoMetricSpace.induced Subtype.val βΉ_βΊ
lemma Subtype.dist_eq {p : Ξ± β Prop} (x y : Subtype p) : dist x y = dist (x : Ξ±) y := rfl
lemma Subtype.nndist_eq {p : Ξ± β Prop} (x y : Subtype p) : nndist x y = nndist (x : Ξ±) y := rfl
namespace MulOpposite
@[to_additive]
instance instPseudoMetricSpace : PseudoMetricSpace Ξ±α΅α΅α΅ :=
PseudoMetricSpace.induced MulOpposite.unop βΉ_βΊ
@[to_additive (attr := simp)]
lemma dist_unop (x y : Ξ±α΅α΅α΅) : dist (unop x) (unop y) = dist x y := rfl
@[to_additive (attr := simp)]
lemma dist_op (x y : Ξ±) : dist (op x) (op y) = dist x y := rfl
@[to_additive (attr := simp)]
lemma nndist_unop (x y : Ξ±α΅α΅α΅) : nndist (unop x) (unop y) = nndist x y := rfl
@[to_additive (attr := simp)]
lemma nndist_op (x y : Ξ±) : nndist (op x) (op y) = nndist x y := rfl
end MulOpposite
section NNReal
instance : PseudoMetricSpace ββ₯0 := Subtype.pseudoMetricSpace
lemma NNReal.dist_eq (a b : ββ₯0) : dist a b = |(a : β) - b| := rfl
lemma NNReal.nndist_eq (a b : ββ₯0) : nndist a b = max (a - b) (b - a) :=
eq_of_forall_ge_iff fun _ => by
simp only [max_le_iff, tsub_le_iff_right (Ξ± := ββ₯0)]
simp only [β NNReal.coe_le_coe, coe_nndist, dist_eq, abs_sub_le_iff,
tsub_le_iff_right, NNReal.coe_add]
@[simp]
lemma NNReal.nndist_zero_eq_val (z : ββ₯0) : nndist 0 z = z := by
simp only [NNReal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le']
@[simp]
lemma NNReal.nndist_zero_eq_val' (z : ββ₯0) : nndist z 0 = z := by
rw [nndist_comm]
exact NNReal.nndist_zero_eq_val z
lemma NNReal.le_add_nndist (a b : ββ₯0) : a β€ b + nndist a b := by
suffices (a : β) β€ (b : β) + dist a b by
rwa [β NNReal.coe_le_coe, NNReal.coe_add, coe_nndist]
rw [β sub_le_iff_le_add']
exact le_of_abs_le (dist_eq a b).ge
lemma NNReal.ball_zero_eq_Ico' (c : ββ₯0) :
Metric.ball (0 : ββ₯0) c.toReal = Set.Ico 0 c := by ext x; simp
lemma NNReal.ball_zero_eq_Ico (c : β) :
Metric.ball (0 : ββ₯0) c = Set.Ico 0 c.toNNReal := by
by_cases c_pos : 0 < c
Β· convert NNReal.ball_zero_eq_Ico' β¨c, c_pos.leβ©
simp [Real.toNNReal, c_pos.le]
simp [not_lt.mp c_pos]
lemma NNReal.closedBall_zero_eq_Icc' (c : ββ₯0) :
Metric.closedBall (0 : ββ₯0) c.toReal = Set.Icc 0 c := by ext x; simp
lemma NNReal.closedBall_zero_eq_Icc {c : β} (c_nn : 0 β€ c) :
Metric.closedBall (0 : ββ₯0) c = Set.Icc 0 c.toNNReal := by
convert NNReal.closedBall_zero_eq_Icc' β¨c, c_nnβ©
simp [Real.toNNReal, c_nn]
end NNReal
namespace ULift
variable [PseudoMetricSpace Ξ²]
instance : PseudoMetricSpace (ULift Ξ²) := PseudoMetricSpace.induced ULift.down βΉ_βΊ
lemma dist_eq (x y : ULift Ξ²) : dist x y = dist x.down y.down := rfl
lemma nndist_eq (x y : ULift Ξ²) : nndist x y = nndist x.down y.down := rfl
@[simp] lemma dist_up_up (x y : Ξ²) : dist (ULift.up x) (ULift.up y) = dist x y := rfl
@[simp] lemma nndist_up_up (x y : Ξ²) : nndist (ULift.up x) (ULift.up y) = nndist x y := rfl
end ULift
section Prod
variable [PseudoMetricSpace Ξ²]
instance Prod.pseudoMetricSpaceMax : PseudoMetricSpace (Ξ± Γ Ξ²) :=
let i := PseudoEMetricSpace.toPseudoMetricSpaceOfDist
(fun x y : Ξ± Γ Ξ² => dist x.1 y.1 β dist x.2 y.2)
(fun _ _ => (max_lt (edist_lt_top _ _) (edist_lt_top _ _)).ne) fun x y => by
simp only [dist_edist, β ENNReal.toReal_max (edist_ne_top _ _) (edist_ne_top _ _),
Prod.edist_eq]
i.replaceBornology fun s => by
simp only [β isBounded_image_fst_and_snd, isBounded_iff_eventually, forall_mem_image, β
eventually_and, β forall_and, β max_le_iff]
rfl
lemma Prod.dist_eq {x y : Ξ± Γ Ξ²} : dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl
@[simp]
lemma dist_prod_same_left {x : Ξ±} {yβ yβ : Ξ²} : dist (x, yβ) (x, yβ) = dist yβ yβ := by
simp [Prod.dist_eq, dist_nonneg]
@[simp]
lemma dist_prod_same_right {xβ xβ : Ξ±} {y : Ξ²} : dist (xβ, y) (xβ, y) = dist xβ xβ := by
simp [Prod.dist_eq, dist_nonneg]
lemma ball_prod_same (x : Ξ±) (y : Ξ²) (r : β) : ball x r ΓΛ’ ball y r = ball (x, y) r :=
ext fun z => by simp [Prod.dist_eq]
lemma closedBall_prod_same (x : Ξ±) (y : Ξ²) (r : β) :
closedBall x r ΓΛ’ closedBall y r = closedBall (x, y) r := ext fun z => by simp [Prod.dist_eq]
lemma sphere_prod (x : Ξ± Γ Ξ²) (r : β) :
sphere x r = sphere x.1 r ΓΛ’ closedBall x.2 r βͺ closedBall x.1 r ΓΛ’ sphere x.2 r := by
obtain hr | rfl | hr := lt_trichotomy r 0
Β· simp [hr]
Β· cases x
simp_rw [β closedBall_eq_sphere_of_nonpos le_rfl, union_self, closedBall_prod_same]
Β· ext β¨x', y'β©
simp_rw [Set.mem_union, Set.mem_prod, Metric.mem_closedBall, Metric.mem_sphere, Prod.dist_eq,
max_eq_iff]
refine or_congr (and_congr_right ?_) (and_comm.trans (and_congr_left ?_))
all_goals rintro rfl; rfl
end Prod
lemma uniformContinuous_dist : UniformContinuous fun p : Ξ± Γ Ξ± => dist p.1 p.2 :=
Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 =>
β¨Ξ΅ / 2, half_pos Ξ΅0, fun {a b} h =>
calc dist (dist a.1 a.2) (dist b.1 b.2) β€ dist a.1 b.1 + dist a.2 b.2 :=
| dist_dist_dist_le _ _ _ _
_ β€ dist a b + dist a b := add_le_add (le_max_left _ _) (le_max_right _ _)
| Mathlib/Topology/MetricSpace/Pseudo/Constructions.lean | 191 | 192 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.Group.Action.Pi
import Mathlib.Algebra.Order.AbsoluteValue.Basic
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Algebra.Order.Group.MinMax
import Mathlib.Algebra.Ring.Pi
import Mathlib.Data.Setoid.Basic
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.Tactic.GCongr
/-!
# Cauchy sequences
A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where
applicable, lemmas that will be reused in other contexts have been stated in extra generality.
There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology.
This is a concrete implementation that is useful for simplicity and computability reasons.
## Important definitions
* `IsCauSeq`: a predicate that says `f : β β Ξ²` is Cauchy.
* `CauSeq`: the type of Cauchy sequences valued in type `Ξ²` with respect to an absolute value
function `abv`.
## Tags
sequence, cauchy, abs val, absolute value
-/
assert_not_exists Finset Module Submonoid FloorRing Module
variable {Ξ± Ξ² : Type*}
open IsAbsoluteValue
section
variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Ring Ξ²]
(abv : Ξ² β Ξ±) [IsAbsoluteValue abv]
theorem rat_add_continuous_lemma {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) :
β Ξ΄ > 0, β {aβ aβ bβ bβ : Ξ²}, abv (aβ - bβ) < Ξ΄ β abv (aβ - bβ) < Ξ΄ β
abv (aβ + aβ - (bβ + bβ)) < Ξ΅ :=
β¨Ξ΅ / 2, half_pos Ξ΅0, fun {aβ aβ bβ bβ} hβ hβ => by
simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using
lt_of_le_of_lt (abv_add abv _ _) (add_lt_add hβ hβ)β©
theorem rat_mul_continuous_lemma {Ξ΅ Kβ Kβ : Ξ±} (Ξ΅0 : 0 < Ξ΅) :
β Ξ΄ > 0, β {aβ aβ bβ bβ : Ξ²}, abv aβ < Kβ β abv bβ < Kβ β abv (aβ - bβ) < Ξ΄ β
abv (aβ - bβ) < Ξ΄ β abv (aβ * aβ - bβ * bβ) < Ξ΅ := by
have K0 : (0 : Ξ±) < max 1 (max Kβ Kβ) := lt_of_lt_of_le zero_lt_one (le_max_left _ _)
have Ξ΅K := div_pos (half_pos Ξ΅0) K0
refine β¨_, Ξ΅K, fun {aβ aβ bβ bβ} haβ hbβ hβ hβ => ?_β©
replace haβ := lt_of_lt_of_le haβ (le_trans (le_max_left _ Kβ) (le_max_right 1 _))
replace hbβ := lt_of_lt_of_le hbβ (le_trans (le_max_right Kβ _) (le_max_right 1 _))
set M := max 1 (max Kβ Kβ)
have : abv (aβ - bβ) * abv bβ + abv (aβ - bβ) * abv aβ < Ξ΅ / 2 / M * M + Ξ΅ / 2 / M * M := by
gcongr
rw [β abv_mul abv, mul_comm, div_mul_cancelβ _ (ne_of_gt K0), β abv_mul abv, add_halves] at this
simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using
lt_of_le_of_lt (abv_add abv _ _) this
theorem rat_inv_continuous_lemma {Ξ² : Type*} [DivisionRing Ξ²] (abv : Ξ² β Ξ±) [IsAbsoluteValue abv]
{Ξ΅ K : Ξ±} (Ξ΅0 : 0 < Ξ΅) (K0 : 0 < K) :
β Ξ΄ > 0, β {a b : Ξ²}, K β€ abv a β K β€ abv b β abv (a - b) < Ξ΄ β abv (aβ»ΒΉ - bβ»ΒΉ) < Ξ΅ := by
refine β¨K * Ξ΅ * K, mul_pos (mul_pos K0 Ξ΅0) K0, fun {a b} ha hb h => ?_β©
have a0 := K0.trans_le ha
have b0 := K0.trans_le hb
rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv,
abv_inv abv, abv_sub abv]
refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le
rw [mul_assoc, inv_mul_cancel_rightβ b0.ne', β mul_assoc, mul_inv_cancelβ a0.ne', one_mul]
refine h.trans_le ?_
gcongr
end
/-- A sequence is Cauchy if the distance between its entries tends to zero. -/
@[nolint unusedArguments]
def IsCauSeq {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±]
{Ξ² : Type*} [Ring Ξ²] (abv : Ξ² β Ξ±) (f : β β Ξ²) :
Prop :=
β Ξ΅ > 0, β i, β j β₯ i, abv (f j - f i) < Ξ΅
namespace IsCauSeq
variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Ring Ξ²]
{abv : Ξ² β Ξ±} [IsAbsoluteValue abv] {f g : β β Ξ²}
-- see Note [nolint_ge]
--@[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchyβ (hf : IsCauSeq abv f) {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) :
β i, β j β₯ i, β k β₯ i, abv (f j - f k) < Ξ΅ := by
refine (hf _ (half_pos Ξ΅0)).imp fun i hi j ij k ik => ?_
rw [β add_halves Ξ΅]
refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_)
rw [abv_sub abv]; exact hi _ ik
theorem cauchyβ (hf : IsCauSeq abv f) {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) :
β i, β j β₯ i, β k β₯ j, abv (f k - f j) < Ξ΅ :=
let β¨i, Hβ© := hf.cauchyβ Ξ΅0
β¨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ijβ©
lemma bounded (hf : IsCauSeq abv f) : β r, β i, abv (f i) < r := by
obtain β¨i, hβ© := hf _ zero_lt_one
set R : β β Ξ± := @Nat.rec (fun _ => Ξ±) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR
have : β i, β j β€ i, abv (f j) β€ R i := by
refine Nat.rec (by simp [hR]) ?_
rintro i hi j (rfl | hj)
Β· simp [R]
Β· exact (hi j hj).trans (le_max_left _ _)
refine β¨R i + 1, fun j β¦ ?_β©
obtain hji | hij := le_total j i
Β· exact (this i _ hji).trans_lt (lt_add_one _)
Β· simpa using (abv_add abv _ _).trans_lt <| add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij)
lemma bounded' (hf : IsCauSeq abv f) (x : Ξ±) : β r > x, β i, abv (f i) < r :=
let β¨r, hβ© := hf.bounded
β¨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _),
fun i β¦ (h i).trans_le (le_max_left _ _)β©
lemma const (x : Ξ²) : IsCauSeq abv fun _ β¦ x :=
fun Ξ΅ Ξ΅0 β¦ β¨0, fun j _ => by simpa [abv_zero] using Ξ΅0β©
theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ Ξ΅0 =>
let β¨_, Ξ΄0, HΞ΄β© := rat_add_continuous_lemma abv Ξ΅0
let β¨i, Hβ© := exists_forall_ge_and (hf.cauchyβ Ξ΄0) (hg.cauchyβ Ξ΄0)
β¨i, fun _ ij =>
let β¨Hβ, Hββ© := H _ le_rfl
HΞ΄ (Hβ _ ij) (Hβ _ ij)β©
lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ Ξ΅0 =>
let β¨_, _, hFβ© := hf.bounded' 0
let β¨_, _, hGβ© := hg.bounded' 0
let β¨_, Ξ΄0, HΞ΄β© := rat_mul_continuous_lemma abv Ξ΅0
let β¨i, Hβ© := exists_forall_ge_and (hf.cauchyβ Ξ΄0) (hg.cauchyβ Ξ΄0)
β¨i, fun j ij =>
let β¨Hβ, Hββ© := H _ le_rfl
HΞ΄ (hF j) (hG i) (Hβ _ ij) (Hβ _ ij)β©
@[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) β IsCauSeq abv f := by
simp only [IsCauSeq, Pi.neg_apply, β neg_sub', abv_neg]
protected alias β¨of_neg, negβ© := isCauSeq_neg
end IsCauSeq
/-- `CauSeq Ξ² abv` is the type of `Ξ²`-valued Cauchy sequences, with respect to the absolute value
function `abv`. -/
def CauSeq {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±]
(Ξ² : Type*) [Ring Ξ²] (abv : Ξ² β Ξ±) : Type _ :=
{ f : β β Ξ² // IsCauSeq abv f }
namespace CauSeq
variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±]
section Ring
variable [Ring Ξ²] {abv : Ξ² β Ξ±}
instance : CoeFun (CauSeq Ξ² abv) fun _ => β β Ξ² :=
β¨Subtype.valβ©
@[ext]
theorem ext {f g : CauSeq Ξ² abv} (h : β i, f i = g i) : f = g := Subtype.eq (funext h)
theorem isCauSeq (f : CauSeq Ξ² abv) : IsCauSeq abv f :=
f.2
theorem cauchy (f : CauSeq Ξ² abv) : β {Ξ΅}, 0 < Ξ΅ β β i, β j β₯ i, abv (f j - f i) < Ξ΅ := @f.2
/-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with
the same values as `f`. -/
def ofEq (f : CauSeq Ξ² abv) (g : β β Ξ²) (e : β i, f i = g i) : CauSeq Ξ² abv :=
β¨g, fun Ξ΅ => by rw [show g = f from (funext e).symm]; exact f.cauchyβ©
variable [IsAbsoluteValue abv]
-- see Note [nolint_ge]
-- @[nolint ge_or_gt] -- Porting note: restore attribute
theorem cauchyβ (f : CauSeq Ξ² abv) {Ξ΅} :
0 < Ξ΅ β β i, β j β₯ i, β k β₯ i, abv (f j - f k) < Ξ΅ :=
f.2.cauchyβ
theorem cauchyβ (f : CauSeq Ξ² abv) {Ξ΅} : 0 < Ξ΅ β β i, β j β₯ i, β k β₯ j, abv (f k - f j) < Ξ΅ :=
f.2.cauchyβ
theorem bounded (f : CauSeq Ξ² abv) : β r, β i, abv (f i) < r := f.2.bounded
theorem bounded' (f : CauSeq Ξ² abv) (x : Ξ±) : β r > x, β i, abv (f i) < r := f.2.bounded' x
instance : Add (CauSeq Ξ² abv) :=
β¨fun f g => β¨f + g, f.2.add g.2β©β©
@[simp, norm_cast]
theorem coe_add (f g : CauSeq Ξ² abv) : β(f + g) = (f : β β Ξ²) + g :=
rfl
@[simp, norm_cast]
theorem add_apply (f g : CauSeq Ξ² abv) (i : β) : (f + g) i = f i + g i :=
rfl
variable (abv) in
/-- The constant Cauchy sequence. -/
def const (x : Ξ²) : CauSeq Ξ² abv := β¨fun _ β¦ x, IsCauSeq.const _β©
/-- The constant Cauchy sequence -/
local notation "const" => const abv
@[simp, norm_cast]
theorem coe_const (x : Ξ²) : (const x : β β Ξ²) = Function.const β x :=
rfl
@[simp, norm_cast]
theorem const_apply (x : Ξ²) (i : β) : (const x : β β Ξ²) i = x :=
rfl
theorem const_inj {x y : Ξ²} : (const x : CauSeq Ξ² abv) = const y β x = y :=
β¨fun h => congr_arg (fun f : CauSeq Ξ² abv => (f : β β Ξ²) 0) h, congr_arg _β©
instance : Zero (CauSeq Ξ² abv) :=
β¨const 0β©
instance : One (CauSeq Ξ² abv) :=
β¨const 1β©
instance : Inhabited (CauSeq Ξ² abv) :=
β¨0β©
@[simp, norm_cast]
theorem coe_zero : β(0 : CauSeq Ξ² abv) = 0 :=
rfl
@[simp, norm_cast]
theorem coe_one : β(1 : CauSeq Ξ² abv) = 1 :=
rfl
@[simp, norm_cast]
theorem zero_apply (i) : (0 : CauSeq Ξ² abv) i = 0 :=
rfl
@[simp, norm_cast]
theorem one_apply (i) : (1 : CauSeq Ξ² abv) i = 1 :=
rfl
@[simp]
theorem const_zero : const 0 = 0 :=
rfl
@[simp]
theorem const_one : const 1 = 1 :=
rfl
theorem const_add (x y : Ξ²) : const (x + y) = const x + const y :=
rfl
instance : Mul (CauSeq Ξ² abv) := β¨fun f g β¦ β¨f * g, f.2.mul g.2β©β©
@[simp, norm_cast]
theorem coe_mul (f g : CauSeq Ξ² abv) : β(f * g) = (f : β β Ξ²) * g :=
rfl
@[simp, norm_cast]
theorem mul_apply (f g : CauSeq Ξ² abv) (i : β) : (f * g) i = f i * g i :=
rfl
theorem const_mul (x y : Ξ²) : const (x * y) = const x * const y :=
rfl
instance : Neg (CauSeq Ξ² abv) := β¨fun f β¦ β¨-f, f.2.negβ©β©
@[simp, norm_cast]
theorem coe_neg (f : CauSeq Ξ² abv) : β(-f) = -f :=
rfl
@[simp, norm_cast]
theorem neg_apply (f : CauSeq Ξ² abv) (i) : (-f) i = -f i :=
rfl
theorem const_neg (x : Ξ²) : const (-x) = -const x :=
rfl
instance : Sub (CauSeq Ξ² abv) :=
β¨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]β©
@[simp, norm_cast]
theorem coe_sub (f g : CauSeq Ξ² abv) : β(f - g) = (f : β β Ξ²) - g :=
rfl
@[simp, norm_cast]
theorem sub_apply (f g : CauSeq Ξ² abv) (i : β) : (f - g) i = f i - g i :=
rfl
theorem const_sub (x y : Ξ²) : const (x - y) = const x - const y :=
rfl
section SMul
variable {G : Type*} [SMul G Ξ²] [IsScalarTower G Ξ² Ξ²]
instance : SMul G (CauSeq Ξ² abv) :=
β¨fun a f => (ofEq (const (a β’ (1 : Ξ²)) * f) (a β’ (f : β β Ξ²))) fun _ => smul_one_mul _ _β©
@[simp, norm_cast]
theorem coe_smul (a : G) (f : CauSeq Ξ² abv) : β(a β’ f) = a β’ (f : β β Ξ²) :=
rfl
@[simp, norm_cast]
theorem smul_apply (a : G) (f : CauSeq Ξ² abv) (i : β) : (a β’ f) i = a β’ f i :=
rfl
theorem const_smul (a : G) (x : Ξ²) : const (a β’ x) = a β’ const x :=
rfl
instance : IsScalarTower G (CauSeq Ξ² abv) (CauSeq Ξ² abv) :=
β¨fun a f g => Subtype.ext <| smul_assoc a (f : β β Ξ²) (g : β β Ξ²)β©
end SMul
instance addGroup : AddGroup (CauSeq Ξ² abv) :=
Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub
(fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _
instance instNatCast : NatCast (CauSeq Ξ² abv) := β¨fun n => const nβ©
instance instIntCast : IntCast (CauSeq Ξ² abv) := β¨fun n => const nβ©
instance addGroupWithOne : AddGroupWithOne (CauSeq Ξ² abv) :=
Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl
coe_add coe_neg coe_sub
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
(by intros; rfl)
instance : Pow (CauSeq Ξ² abv) β :=
β¨fun f n =>
(ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]β©
@[simp, norm_cast]
theorem coe_pow (f : CauSeq Ξ² abv) (n : β) : β(f ^ n) = (f : β β Ξ²) ^ n :=
rfl
@[simp, norm_cast]
theorem pow_apply (f : CauSeq Ξ² abv) (n i : β) : (f ^ n) i = f i ^ n :=
rfl
theorem const_pow (x : Ξ²) (n : β) : const (x ^ n) = const x ^ n :=
rfl
instance ring : Ring (CauSeq Ξ² abv) :=
Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub
(fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl
instance {Ξ² : Type*} [CommRing Ξ²] {abv : Ξ² β Ξ±} [IsAbsoluteValue abv] : CommRing (CauSeq Ξ² abv) :=
{ CauSeq.ring with
mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] }
/-- `LimZero f` holds when `f` approaches 0. -/
def LimZero {abv : Ξ² β Ξ±} (f : CauSeq Ξ² abv) : Prop :=
β Ξ΅ > 0, β i, β j β₯ i, abv (f j) < Ξ΅
theorem add_limZero {f g : CauSeq Ξ² abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g)
| Ξ΅, Ξ΅0 =>
(exists_forall_ge_and (hf _ <| half_pos Ξ΅0) (hg _ <| half_pos Ξ΅0)).imp fun _ H j ij => by
let β¨Hβ, Hββ© := H _ ij
simpa [add_halves Ξ΅] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add Hβ Hβ)
theorem mul_limZero_right (f : CauSeq Ξ² abv) {g} (hg : LimZero g) : LimZero (f * g)
| Ξ΅, Ξ΅0 =>
let β¨F, F0, hFβ© := f.bounded' 0
(hg _ <| div_pos Ξ΅0 F0).imp fun _ H j ij => by
have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0
rwa [mul_comm F, div_mul_cancelβ _ (ne_of_gt F0), β abv_mul] at this
theorem mul_limZero_left {f} (g : CauSeq Ξ² abv) (hg : LimZero f) : LimZero (f * g)
| Ξ΅, Ξ΅0 =>
let β¨G, G0, hGβ© := g.bounded' 0
(hg _ <| div_pos Ξ΅0 G0).imp fun _ H j ij => by
have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _)
rwa [div_mul_cancelβ _ (ne_of_gt G0), β abv_mul] at this
theorem neg_limZero {f : CauSeq Ξ² abv} (hf : LimZero f) : LimZero (-f) := by
rw [β neg_one_mul f]
exact mul_limZero_right _ hf
theorem sub_limZero {f g : CauSeq Ξ² abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by
simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg)
theorem limZero_sub_rev {f g : CauSeq Ξ² abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by
simpa using neg_limZero hfg
theorem zero_limZero : LimZero (0 : CauSeq Ξ² abv)
| Ξ΅, Ξ΅0 => β¨0, fun j _ => by simpa [abv_zero abv] using Ξ΅0β©
theorem const_limZero {x : Ξ²} : LimZero (const x) β x = 0 :=
β¨fun H =>
(abv_eq_zero abv).1 <|
(eq_of_le_of_forall_lt_imp_le_of_dense (abv_nonneg abv _)) fun _ Ξ΅0 =>
let β¨_, hiβ© := H _ Ξ΅0
le_of_lt <| hi _ le_rfl,
fun e => e.symm βΈ zero_limZeroβ©
instance equiv : Setoid (CauSeq Ξ² abv) :=
β¨fun f g => LimZero (f - g),
β¨fun f => by simp [zero_limZero],
fun f Ξ΅ hΞ΅ => by simpa using neg_limZero f Ξ΅ hΞ΅,
fun fg gh => by simpa using add_limZero fg ghβ©β©
theorem add_equiv_add {f1 f2 g1 g2 : CauSeq Ξ² abv} (hf : f1 β f2) (hg : g1 β g2) :
f1 + g1 β f2 + g2 := by simpa only [β add_sub_add_comm] using add_limZero hf hg
theorem neg_equiv_neg {f g : CauSeq Ξ² abv} (hf : f β g) : -f β -g := by
simpa only [neg_sub'] using neg_limZero hf
theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq Ξ² abv} (hf : f1 β f2) (hg : g1 β g2) :
f1 - g1 β f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg)
theorem equiv_defβ {f g : CauSeq Ξ² abv} (h : f β g) {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) :
β i, β j β₯ i, β k β₯ j, abv (f k - g j) < Ξ΅ :=
(exists_forall_ge_and (h _ <| half_pos Ξ΅0) (f.cauchyβ <| half_pos Ξ΅0)).imp fun _ H j ij k jk => by
let β¨hβ, hββ© := H _ ij
have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add hβ (hβ _ jk))
rwa [sub_add_sub_cancel', add_halves] at this
theorem limZero_congr {f g : CauSeq Ξ² abv} (h : f β g) : LimZero f β LimZero g :=
β¨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h lβ©
theorem abv_pos_of_not_limZero {f : CauSeq Ξ² abv} (hf : Β¬LimZero f) :
β K > 0, β i, β j β₯ i, K β€ abv (f j) := by
haveI := Classical.propDecidable
by_contra nk
refine hf fun Ξ΅ Ξ΅0 => ?_
simp? [not_forall] at nk says
simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp,
not_le] at nk
obtain β¨i, hiβ© := f.cauchyβ (half_pos Ξ΅0)
rcases nk _ (half_pos Ξ΅0) i with β¨j, ij, hjβ©
refine β¨j, fun k jk => ?_β©
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj)
rwa [sub_add_cancel, add_halves] at this
theorem of_near (f : β β Ξ²) (g : CauSeq Ξ² abv) (h : β Ξ΅ > 0, β i, β j β₯ i, abv (f j - g j) < Ξ΅) :
IsCauSeq abv f
| Ξ΅, Ξ΅0 =>
let β¨i, hiβ© := exists_forall_ge_and (h _ (half_pos <| half_pos Ξ΅0)) (g.cauchyβ <| half_pos Ξ΅0)
β¨i, fun j ij => by
obtain β¨hβ, hββ© := hi _ le_rfl; rw [abv_sub abv] at hβ
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 hβ)
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (hβ _ ij))
rwa [add_halves, add_halves, add_right_comm, sub_add_sub_cancel, sub_add_sub_cancel] at thisβ©
theorem not_limZero_of_not_congr_zero {f : CauSeq _ abv} (hf : Β¬f β 0) : Β¬LimZero f := by
intro h
have : LimZero (f - 0) := by simp [h]
exact hf this
theorem mul_equiv_zero (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f β 0) : g * f β 0 :=
have : LimZero (f - 0) := hf
have : LimZero (g * f) := mul_limZero_right _ <| by simpa
show LimZero (g * f - 0) by simpa
theorem mul_equiv_zero' (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f β 0) : f * g β 0 :=
have : LimZero (f - 0) := hf
have : LimZero (f * g) := mul_limZero_left _ <| by simpa
show LimZero (f * g - 0) by simpa
theorem mul_not_equiv_zero {f g : CauSeq _ abv} (hf : Β¬f β 0) (hg : Β¬g β 0) : Β¬f * g β 0 :=
fun (this : LimZero (f * g - 0)) => by
have hlz : LimZero (f * g) := by simpa
have hf' : Β¬LimZero f := by simpa using show Β¬LimZero (f - 0) from hf
have hg' : Β¬LimZero g := by simpa using show Β¬LimZero (g - 0) from hg
rcases abv_pos_of_not_limZero hf' with β¨a1, ha1, N1, hN1β©
rcases abv_pos_of_not_limZero hg' with β¨a2, ha2, N2, hN2β©
have : 0 < a1 * a2 := mul_pos ha1 ha2
obtain β¨N, hNβ© := hlz _ this
let i := max N (max N1 N2)
have hN' := hN i (le_max_left _ _)
have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _))
have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _))
apply not_le_of_lt hN'
change _ β€ abv (_ * _)
rw [abv_mul abv]
gcongr
theorem const_equiv {x y : Ξ²} : const x β const y β x = y :=
show LimZero _ β _ by rw [β const_sub, const_limZero, sub_eq_zero]
theorem mul_equiv_mul {f1 f2 g1 g2 : CauSeq Ξ² abv} (hf : f1 β f2) (hg : g1 β g2) :
f1 * g1 β f2 * g2 := by
simpa only [mul_sub, sub_mul, sub_add_sub_cancel]
using add_limZero (mul_limZero_left g1 hf) (mul_limZero_right f2 hg)
theorem smul_equiv_smul {G : Type*} [SMul G Ξ²] [IsScalarTower G Ξ² Ξ²] {f1 f2 : CauSeq Ξ² abv} (c : G)
(hf : f1 β f2) : c β’ f1 β c β’ f2 := by
simpa [const_smul, smul_one_mul _ _] using
mul_equiv_mul (const_equiv.mpr <| Eq.refl <| c β’ (1 : Ξ²)) hf
theorem pow_equiv_pow {f1 f2 : CauSeq Ξ² abv} (hf : f1 β f2) (n : β) : f1 ^ n β f2 ^ n := by
induction n with
| zero => simp only [pow_zero, Setoid.refl]
| succ n ih => simpa only [pow_succ'] using mul_equiv_mul hf ih
end Ring
section IsDomain
variable [Ring Ξ²] [IsDomain Ξ²] (abv : Ξ² β Ξ±) [IsAbsoluteValue abv]
theorem one_not_equiv_zero : Β¬const abv 1 β const abv 0 := fun h =>
have : β Ξ΅ > 0, β i, β k, i β€ k β abv (1 - 0) < Ξ΅ := h
have h1 : abv 1 β€ 0 :=
le_of_not_gt fun h2 : 0 < abv 1 =>
(Exists.elim (this _ h2)) fun i hi => lt_irrefl (abv 1) <| by simpa using hi _ le_rfl
have h2 : 0 β€ abv 1 := abv_nonneg abv _
have : abv 1 = 0 := le_antisymm h1 h2
have : (1 : Ξ²) = 0 := (abv_eq_zero abv).mp this
absurd this one_ne_zero
end IsDomain
section DivisionRing
variable [DivisionRing Ξ²] {abv : Ξ² β Ξ±} [IsAbsoluteValue abv]
theorem inv_aux {f : CauSeq Ξ² abv} (hf : Β¬LimZero f) :
β Ξ΅ > 0, β i, β j β₯ i, abv ((f j)β»ΒΉ - (f i)β»ΒΉ) < Ξ΅
| _, Ξ΅0 =>
let β¨_, K0, HKβ© := abv_pos_of_not_limZero hf
let β¨_, Ξ΄0, HΞ΄β© := rat_inv_continuous_lemma abv Ξ΅0 K0
let β¨i, Hβ© := exists_forall_ge_and HK (f.cauchyβ Ξ΄0)
β¨i, fun _ ij =>
let β¨iK, H'β© := H _ le_rfl
HΞ΄ (H _ ij).1 iK (H' _ ij)β©
/-- Given a Cauchy sequence `f` with nonzero limit, create a Cauchy sequence with values equal to
the inverses of the values of `f`. -/
def inv (f : CauSeq Ξ² abv) (hf : Β¬LimZero f) : CauSeq Ξ² abv :=
β¨_, inv_aux hfβ©
@[simp, norm_cast]
theorem coe_inv {f : CauSeq Ξ² abv} (hf) : β(inv f hf) = (f : β β Ξ²)β»ΒΉ :=
rfl
@[simp, norm_cast]
theorem inv_apply {f : CauSeq Ξ² abv} (hf i) : inv f hf i = (f i)β»ΒΉ :=
rfl
theorem inv_mul_cancel {f : CauSeq Ξ² abv} (hf) : inv f hf * f β 1 := fun Ξ΅ Ξ΅0 =>
let β¨K, K0, i, Hβ© := abv_pos_of_not_limZero hf
β¨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using Ξ΅0β©
theorem mul_inv_cancel {f : CauSeq Ξ² abv} (hf) : f * inv f hf β 1 := fun Ξ΅ Ξ΅0 =>
let β¨K, K0, i, Hβ© := abv_pos_of_not_limZero hf
β¨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using Ξ΅0β©
theorem const_inv {x : Ξ²} (hx : x β 0) :
const abv xβ»ΒΉ = inv (const abv x) (by rwa [const_limZero]) :=
rfl
end DivisionRing
section Abs
/-- The constant Cauchy sequence -/
local notation "const" => const abs
/-- The entries of a positive Cauchy sequence eventually have a positive lower bound. -/
def Pos (f : CauSeq Ξ± abs) : Prop :=
β K > 0, β i, β j β₯ i, K β€ f j
theorem not_limZero_of_pos {f : CauSeq Ξ± abs} : Pos f β Β¬LimZero f
| β¨_, F0, hFβ©, H =>
let β¨_, hβ© := exists_forall_ge_and hF (H _ F0)
let β¨hβ, hββ© := h _ le_rfl
not_lt_of_le hβ (abs_lt.1 hβ).2
theorem const_pos {x : Ξ±} : Pos (const x) β 0 < x :=
β¨fun β¨_, K0, _, hβ© => lt_of_lt_of_le K0 (h _ le_rfl), fun h => β¨x, h, 0, fun _ _ => le_rflβ©β©
theorem add_pos {f g : CauSeq Ξ± abs} : Pos f β Pos g β Pos (f + g)
| β¨_, F0, hFβ©, β¨_, G0, hGβ© =>
let β¨i, hβ© := exists_forall_ge_and hF hG
β¨_, _root_.add_pos F0 G0, i, fun _ ij =>
let β¨hβ, hββ© := h _ ij
add_le_add hβ hββ©
theorem pos_add_limZero {f g : CauSeq Ξ± abs} : Pos f β LimZero g β Pos (f + g)
| β¨F, F0, hFβ©, H =>
let β¨i, hβ© := exists_forall_ge_and hF (H _ (half_pos F0))
β¨_, half_pos F0, i, fun j ij => by
obtain β¨hβ, hββ© := h j ij
have := add_le_add hβ (le_of_lt (abs_lt.1 hβ).1)
rwa [β sub_eq_add_neg, sub_self_div_two] at thisβ©
protected theorem mul_pos {f g : CauSeq Ξ± abs} : Pos f β Pos g β Pos (f * g)
| β¨_, F0, hFβ©, β¨_, G0, hGβ© =>
let β¨i, hβ© := exists_forall_ge_and hF hG
β¨_, mul_pos F0 G0, i, fun _ ij =>
let β¨hβ, hββ© := h _ ij
mul_le_mul hβ hβ (le_of_lt G0) (le_trans (le_of_lt F0) hβ)β©
theorem trichotomy (f : CauSeq Ξ± abs) : Pos f β¨ LimZero f β¨ Pos (-f) := by
rcases Classical.em (LimZero f) with h | h <;> simp [*]
rcases abv_pos_of_not_limZero h with β¨K, K0, hKβ©
rcases exists_forall_ge_and hK (f.cauchyβ K0) with β¨i, hiβ©
refine (le_total 0 (f i)).imp ?_ ?_ <;>
refine fun h => β¨K, K0, i, fun j ij => ?_β© <;>
have := (hi _ ij).1 <;>
obtain β¨hβ, hββ© := hi _ le_rfl
Β· rwa [abs_of_nonneg] at this
rw [abs_of_nonneg h] at hβ
exact
(le_add_iff_nonneg_right _).1
(le_trans hβ <| neg_le_sub_iff_le_add'.1 <| le_of_lt (abs_lt.1 <| hβ _ ij).1)
Β· rwa [abs_of_nonpos] at this
rw [abs_of_nonpos h] at hβ
rw [β sub_le_sub_iff_right, zero_sub]
exact le_trans (le_of_lt (abs_lt.1 <| hβ _ ij).2) hβ
instance : LT (CauSeq Ξ± abs) :=
β¨fun f g => Pos (g - f)β©
instance : LE (CauSeq Ξ± abs) :=
β¨fun f g => f < g β¨ f β gβ©
theorem lt_of_lt_of_eq {f g h : CauSeq Ξ± abs} (fg : f < g) (gh : g β h) : f < h :=
show Pos (h - f) by
convert pos_add_limZero fg (neg_limZero gh) using 1
simp
theorem lt_of_eq_of_lt {f g h : CauSeq Ξ± abs} (fg : f β g) (gh : g < h) : f < h := by
have := pos_add_limZero gh (neg_limZero fg)
rwa [β sub_eq_add_neg, sub_sub_sub_cancel_right] at this
theorem lt_trans {f g h : CauSeq Ξ± abs} (fg : f < g) (gh : g < h) : f < h :=
show Pos (h - f) by
convert add_pos fg gh using 1
simp
theorem lt_irrefl {f : CauSeq Ξ± abs} : Β¬f < f
| h => not_limZero_of_pos h (by simp [zero_limZero])
theorem le_of_eq_of_le {f g h : CauSeq Ξ± abs} (hfg : f β g) (hgh : g β€ h) : f β€ h :=
hgh.elim (Or.inl β CauSeq.lt_of_eq_of_lt hfg) (Or.inr β Setoid.trans hfg)
theorem le_of_le_of_eq {f g h : CauSeq Ξ± abs} (hfg : f β€ g) (hgh : g β h) : f β€ h :=
hfg.elim (fun h => Or.inl (CauSeq.lt_of_lt_of_eq h hgh)) fun h => Or.inr (Setoid.trans h hgh)
instance : Preorder (CauSeq Ξ± abs) where
lt := (Β· < Β·)
le f g := f < g β¨ f β g
le_refl _ := Or.inr (Setoid.refl _)
le_trans _ _ _ fg gh :=
match fg, gh with
| Or.inl fg, Or.inl gh => Or.inl <| lt_trans fg gh
| Or.inl fg, Or.inr gh => Or.inl <| lt_of_lt_of_eq fg gh
| Or.inr fg, Or.inl gh => Or.inl <| lt_of_eq_of_lt fg gh
| Or.inr fg, Or.inr gh => Or.inr <| Setoid.trans fg gh
lt_iff_le_not_le _ _ :=
β¨fun h => β¨Or.inl h, not_or_intro (mt (lt_trans h) lt_irrefl) (not_limZero_of_pos h)β©,
fun β¨hβ, hββ© => hβ.resolve_right (mt (fun h => Or.inr (Setoid.symm h)) hβ)β©
theorem le_antisymm {f g : CauSeq Ξ± abs} (fg : f β€ g) (gf : g β€ f) : f β g :=
fg.resolve_left (not_lt_of_le gf)
theorem lt_total (f g : CauSeq Ξ± abs) : f < g β¨ f β g β¨ g < f :=
(trichotomy (g - f)).imp_right fun h =>
h.imp (fun h => Setoid.symm h) fun h => by rwa [neg_sub] at h
theorem le_total (f g : CauSeq Ξ± abs) : f β€ g β¨ g β€ f :=
(or_assoc.2 (lt_total f g)).imp_right Or.inl
theorem const_lt {x y : Ξ±} : const x < const y β x < y :=
show Pos _ β _ by rw [β const_sub, const_pos, sub_pos]
theorem const_le {x y : Ξ±} : const x β€ const y β x β€ y := by
rw [le_iff_lt_or_eq]; exact or_congr const_lt const_equiv
theorem le_of_exists {f g : CauSeq Ξ± abs} (h : β i, β j β₯ i, f j β€ g j) : f β€ g :=
let β¨i, hiβ© := h
(or_assoc.2 (CauSeq.lt_total f g)).elim id fun hgf =>
False.elim
(let β¨_, hK0, j, hKjβ© := hgf
not_lt_of_ge (hi (max i j) (le_max_left _ _))
(sub_pos.1 (lt_of_lt_of_le hK0 (hKj _ (le_max_right _ _)))))
theorem exists_gt (f : CauSeq Ξ± abs) : β a : Ξ±, f < const a :=
let β¨K, Hβ© := f.bounded
β¨K + 1, 1, zero_lt_one, 0, fun i _ => by
rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right]
exact le_of_lt (abs_lt.1 (H _)).2β©
theorem exists_lt (f : CauSeq Ξ± abs) : β a : Ξ±, const a < f :=
let β¨a, hβ© := (-f).exists_gt
β¨-a, show Pos _ by rwa [const_neg, sub_neg_eq_add, add_comm, β sub_neg_eq_add]β©
-- so named to match `rat_add_continuous_lemma`
theorem rat_sup_continuous_lemma {Ξ΅ : Ξ±} {aβ aβ bβ bβ : Ξ±} :
abs (aβ - bβ) < Ξ΅ β abs (aβ - bβ) < Ξ΅ β abs (aβ β aβ - bβ β bβ) < Ξ΅ := fun hβ hβ =>
(abs_max_sub_max_le_max _ _ _ _).trans_lt (max_lt hβ hβ)
-- so named to match `rat_add_continuous_lemma`
theorem rat_inf_continuous_lemma {Ξ΅ : Ξ±} {aβ aβ bβ bβ : Ξ±} :
abs (aβ - bβ) < Ξ΅ β abs (aβ - bβ) < Ξ΅ β abs (aβ β aβ - bβ β bβ) < Ξ΅ := fun hβ hβ =>
(abs_min_sub_min_le_max _ _ _ _).trans_lt (max_lt hβ hβ)
instance : Max (CauSeq Ξ± abs) :=
β¨fun f g =>
β¨f β g, fun _ Ξ΅0 =>
(exists_forall_ge_and (f.cauchyβ Ξ΅0) (g.cauchyβ Ξ΅0)).imp fun _ H _ ij =>
let β¨Hβ, Hββ© := H _ le_rfl
rat_sup_continuous_lemma (Hβ _ ij) (Hβ _ ij)β©β©
instance : Min (CauSeq Ξ± abs) :=
β¨fun f g =>
β¨f β g, fun _ Ξ΅0 =>
(exists_forall_ge_and (f.cauchyβ Ξ΅0) (g.cauchyβ Ξ΅0)).imp fun _ H _ ij =>
let β¨Hβ, Hββ© := H _ le_rfl
rat_inf_continuous_lemma (Hβ _ ij) (Hβ _ ij)β©β©
@[simp, norm_cast]
theorem coe_sup (f g : CauSeq Ξ± abs) : β(f β g) = (f : β β Ξ±) β g :=
rfl
@[simp, norm_cast]
theorem coe_inf (f g : CauSeq Ξ± abs) : β(f β g) = (f : β β Ξ±) β g :=
rfl
theorem sup_limZero {f g : CauSeq Ξ± abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f β g)
| Ξ΅, Ξ΅0 =>
(exists_forall_ge_and (hf _ Ξ΅0) (hg _ Ξ΅0)).imp fun _ H j ij => by
let β¨Hβ, Hββ© := H _ ij
rw [abs_lt] at Hβ Hβ β’
exact β¨lt_sup_iff.mpr (Or.inl Hβ.1), sup_lt_iff.mpr β¨Hβ.2, Hβ.2β©β©
theorem inf_limZero {f g : CauSeq Ξ± abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f β g)
| Ξ΅, Ξ΅0 =>
(exists_forall_ge_and (hf _ Ξ΅0) (hg _ Ξ΅0)).imp fun _ H j ij => by
let β¨Hβ, Hββ© := H _ ij
rw [abs_lt] at Hβ Hβ β’
exact β¨lt_inf_iff.mpr β¨Hβ.1, Hβ.1β©, inf_lt_iff.mpr (Or.inl Hβ.2)β©
theorem sup_equiv_sup {aβ bβ aβ bβ : CauSeq Ξ± abs} (ha : aβ β aβ) (hb : bβ β bβ) :
aβ β bβ β aβ β bβ := by
intro Ξ΅ Ξ΅0
obtain β¨ai, haiβ© := ha Ξ΅ Ξ΅0
obtain β¨bi, hbiβ© := hb Ξ΅ Ξ΅0
exact
β¨ai β bi, fun i hi =>
(abs_max_sub_max_le_max (aβ i) (bβ i) (aβ i) (bβ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))β©
theorem inf_equiv_inf {aβ bβ aβ bβ : CauSeq Ξ± abs} (ha : aβ β aβ) (hb : bβ β bβ) :
aβ β bβ β aβ β bβ := by
intro Ξ΅ Ξ΅0
obtain β¨ai, haiβ© := ha Ξ΅ Ξ΅0
obtain β¨bi, hbiβ© := hb Ξ΅ Ξ΅0
exact
β¨ai β bi, fun i hi =>
(abs_min_sub_min_le_max (aβ i) (bβ i) (aβ i) (bβ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))β©
protected theorem sup_lt {a b c : CauSeq Ξ± abs} (ha : a < c) (hb : b < c) : a β b < c := by
obtain β¨β¨Ξ΅a, Ξ΅a0, ia, haβ©, β¨Ξ΅b, Ξ΅b0, ib, hbβ©β© := ha, hb
refine β¨Ξ΅a β Ξ΅b, lt_inf_iff.mpr β¨Ξ΅a0, Ξ΅b0β©, ia β ib, fun i hi => ?_β©
have := min_le_min (ha _ (sup_le_iff.mp hi).1) (hb _ (sup_le_iff.mp hi).2)
exact this.trans_eq (min_sub_sub_left _ _ _)
protected theorem lt_inf {a b c : CauSeq Ξ± abs} (hb : a < b) (hc : a < c) : a < b β c := by
obtain β¨β¨Ξ΅b, Ξ΅b0, ib, hbβ©, β¨Ξ΅c, Ξ΅c0, ic, hcβ©β© := hb, hc
refine β¨Ξ΅b β Ξ΅c, lt_inf_iff.mpr β¨Ξ΅b0, Ξ΅c0β©, ib β ic, fun i hi => ?_β©
have := min_le_min (hb _ (sup_le_iff.mp hi).1) (hc _ (sup_le_iff.mp hi).2)
exact this.trans_eq (min_sub_sub_right _ _ _)
@[simp]
protected theorem sup_idem (a : CauSeq Ξ± abs) : a β a = a := Subtype.ext (sup_idem _)
@[simp]
protected theorem inf_idem (a : CauSeq Ξ± abs) : a β a = a := Subtype.ext (inf_idem _)
protected theorem sup_comm (a b : CauSeq Ξ± abs) : a β b = b β a := Subtype.ext (sup_comm _ _)
protected theorem inf_comm (a b : CauSeq Ξ± abs) : a β b = b β a := Subtype.ext (inf_comm _ _)
protected theorem sup_eq_right {a b : CauSeq Ξ± abs} (h : a β€ b) : a β b β b := by
obtain β¨Ξ΅, Ξ΅0 : _ < _, i, hβ© | h := h
Β· intro _ _
refine β¨i, fun j hj => ?_β©
dsimp
rw [β max_sub_sub_right]
rwa [sub_self, max_eq_right, abs_zero]
rw [sub_nonpos, β sub_nonneg]
exact Ξ΅0.le.trans (h _ hj)
Β· refine Setoid.trans (sup_equiv_sup h (Setoid.refl _)) ?_
rw [CauSeq.sup_idem]
protected theorem inf_eq_right {a b : CauSeq Ξ± abs} (h : b β€ a) : a β b β b := by
obtain β¨Ξ΅, Ξ΅0 : _ < _, i, hβ© | h := h
Β· intro _ _
refine β¨i, fun j hj => ?_β©
dsimp
rw [β min_sub_sub_right]
rwa [sub_self, min_eq_right, abs_zero]
exact Ξ΅0.le.trans (h _ hj)
Β· refine Setoid.trans (inf_equiv_inf (Setoid.symm h) (Setoid.refl _)) ?_
rw [CauSeq.inf_idem]
protected theorem sup_eq_left {a b : CauSeq Ξ± abs} (h : b β€ a) : a β b β a := by
simpa only [CauSeq.sup_comm] using CauSeq.sup_eq_right h
protected theorem inf_eq_left {a b : CauSeq Ξ± abs} (h : a β€ b) : a β b β a := by
simpa only [CauSeq.inf_comm] using CauSeq.inf_eq_right h
protected theorem le_sup_left {a b : CauSeq Ξ± abs} : a β€ a β b :=
le_of_exists β¨0, fun _ _ => le_sup_leftβ©
protected theorem inf_le_left {a b : CauSeq Ξ± abs} : a β b β€ a :=
le_of_exists β¨0, fun _ _ => inf_le_leftβ©
protected theorem le_sup_right {a b : CauSeq Ξ± abs} : b β€ a β b :=
le_of_exists β¨0, fun _ _ => le_sup_rightβ©
protected theorem inf_le_right {a b : CauSeq Ξ± abs} : a β b β€ b :=
le_of_exists β¨0, fun _ _ => inf_le_rightβ©
protected theorem sup_le {a b c : CauSeq Ξ± abs} (ha : a β€ c) (hb : b β€ c) : a β b β€ c := by
obtain ha | ha := ha
Β· obtain hb | hb := hb
Β· exact Or.inl (CauSeq.sup_lt ha hb)
Β· replace ha := le_of_le_of_eq ha.le (Setoid.symm hb)
refine le_of_le_of_eq (Or.inr ?_) hb
exact CauSeq.sup_eq_right ha
Β· replace hb := le_of_le_of_eq hb (Setoid.symm ha)
refine le_of_le_of_eq (Or.inr ?_) ha
exact CauSeq.sup_eq_left hb
protected theorem le_inf {a b c : CauSeq Ξ± abs} (hb : a β€ b) (hc : a β€ c) : a β€ b β c := by
obtain hb | hb := hb
Β· obtain hc | hc := hc
Β· exact Or.inl (CauSeq.lt_inf hb hc)
Β· replace hb := le_of_eq_of_le (Setoid.symm hc) hb.le
refine le_of_eq_of_le hc (Or.inr ?_)
exact Setoid.symm (CauSeq.inf_eq_right hb)
Β· replace hc := le_of_eq_of_le (Setoid.symm hb) hc
refine le_of_eq_of_le hb (Or.inr ?_)
exact Setoid.symm (CauSeq.inf_eq_left hc)
/-! Note that `DistribLattice (CauSeq Ξ± abs)` is not true because there is no `PartialOrder`. -/
protected theorem sup_inf_distrib_left (a b c : CauSeq Ξ± abs) : a β b β c = (a β b) β (a β c) :=
ext fun _ β¦ max_min_distrib_left _ _ _
protected theorem sup_inf_distrib_right (a b c : CauSeq Ξ± abs) : a β b β c = (a β c) β (b β c) :=
ext fun _ β¦ max_min_distrib_right _ _ _
end Abs
end CauSeq
| Mathlib/Algebra/Order/CauSeq/Basic.lean | 892 | 896 | |
/-
Copyright (c) 2020 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp
-/
import Mathlib.Algebra.Algebra.Spectrum.Basic
import Mathlib.Algebra.Module.LinearMap.Basic
import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.RingTheory.Nilpotent.Defs
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.Tactic.Peel
/-!
# Eigenvectors and eigenvalues
This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized
counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties
without choosing a basis and without using matrices.
An eigenspace of a linear map `f` for a scalar `ΞΌ` is the kernel of the map `(f - ΞΌ β’ id)`. The
nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = ΞΌ β’ x`. If
there are eigenvectors for a scalar `ΞΌ`, the scalar `ΞΌ` is called an eigenvalue.
There is no consensus in the literature whether `0` is an eigenvector. Our definition of
`HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we
write `x β f.eigenspace ΞΌ`.
A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `ΞΌ` is the kernel
of the map `(f - ΞΌ β’ id) ^ k`. The nonzero elements of a generalized eigenspace are generalized
eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `ΞΌ`,
the scalar `ΞΌ` is called a generalized eigenvalue.
The fact that the eigenvalues are the roots of the minimal polynomial is proved in
`LinearAlgebra.Eigenspace.Minpoly`.
The existence of eigenvalues over an algebraically closed field
(and the fact that the generalized eigenspaces then span) is deferred to
`LinearAlgebra.Eigenspace.IsAlgClosed`.
## References
* [Sheldon Axler, *Linear Algebra Done Right*][axler2015]
* https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
## Tags
eigenspace, eigenvector, eigenvalue, eigen
-/
universe u v w
namespace Module
namespace End
open Module Set
variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K]
[AddCommGroup V] [Module K V]
/-- The submodule `genEigenspace f ΞΌ k` for a linear map `f`, a scalar `ΞΌ`,
and a number `k : ββ` is the kernel of `(f - ΞΌ β’ id) ^ k` if `k` is a natural number
(see Def 8.10 of [axler2015]), or the union of all these kernels if `k = β`.
A generalized eigenspace for some exponent `k` is contained in
the generalized eigenspace for exponents larger than `k`. -/
def genEigenspace (f : End R M) (ΞΌ : R) : ββ βo Submodule R M where
toFun k := β¨ l : β, β¨ _ : l β€ k, LinearMap.ker ((f - ΞΌ β’ 1) ^ l)
monotone' _ _ hkl := biSup_mono fun _ hi β¦ hi.trans hkl
lemma mem_genEigenspace {f : End R M} {ΞΌ : R} {k : ββ} {x : M} :
x β f.genEigenspace ΞΌ k β β l : β, l β€ k β§ x β LinearMap.ker ((f - ΞΌ β’ 1) ^ l) := by
have : Nonempty {l : β // l β€ k} := β¨β¨0, zero_le _β©β©
have : Directed (ΞΉ := { i : β // i β€ k }) (Β· β€ Β·) fun i β¦ LinearMap.ker ((f - ΞΌ β’ 1) ^ (i : β)) :=
Monotone.directed_le fun m n h β¦ by simpa using (f - ΞΌ β’ 1).iterateKer.monotone h
simp_rw [genEigenspace, OrderHom.coe_mk, LinearMap.mem_ker, iSup_subtype',
Submodule.mem_iSup_of_directed _ this, LinearMap.mem_ker, Subtype.exists, exists_prop]
lemma genEigenspace_directed {f : End R M} {ΞΌ : R} {k : ββ} :
Directed (Β· β€ Β·) (fun l : {l : β // l β€ k} β¦ f.genEigenspace ΞΌ l) := by
have aux : Monotone ((β) : {l : β // l β€ k} β ββ) := fun x y h β¦ by simpa using h
exact ((genEigenspace f ΞΌ).monotone.comp aux).directed_le
lemma mem_genEigenspace_nat {f : End R M} {ΞΌ : R} {k : β} {x : M} :
x β f.genEigenspace ΞΌ k β x β LinearMap.ker ((f - ΞΌ β’ 1) ^ k) := by
rw [mem_genEigenspace]
constructor
Β· rintro β¨l, hl, hxβ©
simp only [Nat.cast_le] at hl
exact (f - ΞΌ β’ 1).iterateKer.monotone hl hx
Β· intro hx
exact β¨k, le_rfl, hxβ©
lemma mem_genEigenspace_top {f : End R M} {ΞΌ : R} {x : M} :
x β f.genEigenspace ΞΌ β€ β β k : β, x β LinearMap.ker ((f - ΞΌ β’ 1) ^ k) := by
simp [mem_genEigenspace]
lemma genEigenspace_nat {f : End R M} {ΞΌ : R} {k : β} :
f.genEigenspace ΞΌ k = LinearMap.ker ((f - ΞΌ β’ 1) ^ k) := by
ext; simp [mem_genEigenspace_nat]
lemma genEigenspace_eq_iSup_genEigenspace_nat (f : End R M) (ΞΌ : R) (k : ββ) :
f.genEigenspace ΞΌ k = β¨ l : {l : β // l β€ k}, f.genEigenspace ΞΌ l := by
simp_rw [genEigenspace_nat, genEigenspace, OrderHom.coe_mk, iSup_subtype]
lemma genEigenspace_top (f : End R M) (ΞΌ : R) :
f.genEigenspace ΞΌ β€ = β¨ k : β, f.genEigenspace ΞΌ k := by
rw [genEigenspace_eq_iSup_genEigenspace_nat, iSup_subtype]
simp only [le_top, iSup_pos, OrderHom.coe_mk]
lemma genEigenspace_one {f : End R M} {ΞΌ : R} :
f.genEigenspace ΞΌ 1 = LinearMap.ker (f - ΞΌ β’ 1) := by
rw [β Nat.cast_one, genEigenspace_nat, pow_one]
@[simp]
lemma mem_genEigenspace_one {f : End R M} {ΞΌ : R} {x : M} :
x β f.genEigenspace ΞΌ 1 β f x = ΞΌ β’ x := by
rw [genEigenspace_one, LinearMap.mem_ker, LinearMap.sub_apply,
sub_eq_zero, LinearMap.smul_apply, Module.End.one_apply]
-- `simp` can prove this using `genEigenspace_zero`
lemma mem_genEigenspace_zero {f : End R M} {ΞΌ : R} {x : M} :
x β f.genEigenspace ΞΌ 0 β x = 0 := by
rw [β Nat.cast_zero, mem_genEigenspace_nat, pow_zero, LinearMap.mem_ker, Module.End.one_apply]
@[simp]
lemma genEigenspace_zero {f : End R M} {ΞΌ : R} :
f.genEigenspace ΞΌ 0 = β₯ := by
ext; apply mem_genEigenspace_zero
@[simp]
lemma genEigenspace_zero_nat (f : End R M) (k : β) :
f.genEigenspace 0 k = LinearMap.ker (f ^ k) := by
ext; simp [mem_genEigenspace_nat]
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`,
and let `ΞΌ : R` and `k : ββ` be given.
Then `x : M` satisfies `HasUnifEigenvector f ΞΌ k x` if
`x β f.genEigenspace ΞΌ k` and `x β 0`.
For `k = 1`, this means that `x` is an eigenvector of `f` with eigenvalue `ΞΌ`. -/
def HasUnifEigenvector (f : End R M) (ΞΌ : R) (k : ββ) (x : M) : Prop :=
x β f.genEigenspace ΞΌ k β§ x β 0
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`.
Then `ΞΌ : R` and `k : ββ` satisfy `HasUnifEigenvalue f ΞΌ k` if
`f.genEigenspace ΞΌ k β β₯`.
For `k = 1`, this means that `ΞΌ` is an eigenvalue of `f`. -/
def HasUnifEigenvalue (f : End R M) (ΞΌ : R) (k : ββ) : Prop :=
f.genEigenspace ΞΌ k β β₯
/-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`.
For `k : ββ`, we define `UnifEigenvalues f k` to be the type of all
`ΞΌ : R` that satisfy `f.HasUnifEigenvalue ΞΌ k`.
For `k = 1` this is the type of all eigenvalues of `f`. -/
def UnifEigenvalues (f : End R M) (k : ββ) : Type _ :=
{ ΞΌ : R // f.HasUnifEigenvalue ΞΌ k }
/-- The underlying value of a bundled eigenvalue. -/
@[coe]
def UnifEigenvalues.val (f : Module.End R M) (k : ββ) : UnifEigenvalues f k β R := Subtype.val
instance UnifEigenvalues.instCoeOut {f : Module.End R M} (k : ββ) :
CoeOut (UnifEigenvalues f k) R where
coe := UnifEigenvalues.val f k
instance UnivEigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) (k : ββ) :
DecidableEq (UnifEigenvalues f k) :=
inferInstanceAs (DecidableEq (Subtype (fun x : R β¦ f.HasUnifEigenvalue x k)))
lemma HasUnifEigenvector.hasUnifEigenvalue {f : End R M} {ΞΌ : R} {k : ββ} {x : M}
(h : f.HasUnifEigenvector ΞΌ k x) : f.HasUnifEigenvalue ΞΌ k := by
rw [HasUnifEigenvalue, Submodule.ne_bot_iff]
use x; exact h
lemma HasUnifEigenvector.apply_eq_smul {f : End R M} {ΞΌ : R} {x : M}
(hx : f.HasUnifEigenvector ΞΌ 1 x) : f x = ΞΌ β’ x :=
mem_genEigenspace_one.mp hx.1
lemma HasUnifEigenvector.pow_apply {f : End R M} {ΞΌ : R} {v : M} (hv : f.HasUnifEigenvector ΞΌ 1 v)
(n : β) : (f ^ n) v = ΞΌ ^ n β’ v := by
induction n <;> simp [*, pow_succ f, hv.apply_eq_smul, smul_smul, pow_succ' ΞΌ]
theorem HasUnifEigenvalue.exists_hasUnifEigenvector
{f : End R M} {ΞΌ : R} {k : ββ} (hΞΌ : f.HasUnifEigenvalue ΞΌ k) :
β v, f.HasUnifEigenvector ΞΌ k v :=
Submodule.exists_mem_ne_zero_of_ne_bot hΞΌ
lemma HasUnifEigenvalue.pow {f : End R M} {ΞΌ : R} (h : f.HasUnifEigenvalue ΞΌ 1) (n : β) :
(f ^ n).HasUnifEigenvalue (ΞΌ ^ n) 1 := by
rw [HasUnifEigenvalue, Submodule.ne_bot_iff]
obtain β¨m : M, hmβ© := h.exists_hasUnifEigenvector
exact β¨m, by simpa [mem_genEigenspace_one] using hm.pow_apply n, hm.2β©
/-- A nilpotent endomorphism has nilpotent eigenvalues.
See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/
lemma HasUnifEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M}
(hfn : IsNilpotent f) {ΞΌ : R} (hf : f.HasUnifEigenvalue ΞΌ 1) :
IsNilpotent ΞΌ := by
obtain β¨m : M, hmβ© := hf.exists_hasUnifEigenvector
obtain β¨n : β, hn : f ^ n = 0β© := hfn
exact β¨n, by simpa [hn, hm.2, eq_comm (a := (0 : M))] using hm.pow_apply nβ©
lemma HasUnifEigenvalue.mem_spectrum {f : End R M} {ΞΌ : R} (hΞΌ : HasUnifEigenvalue f ΞΌ 1) :
ΞΌ β spectrum R f := by
refine spectrum.mem_iff.mpr fun h_unit β¦ ?_
set f' := LinearMap.GeneralLinearGroup.toLinearEquiv h_unit.unit
rcases hΞΌ.exists_hasUnifEigenvector with β¨v, hvβ©
refine hv.2 ((LinearMap.ker_eq_bot'.mp f'.ker) v (?_ : ΞΌ β’ v - f v = 0))
rw [hv.apply_eq_smul, sub_self]
lemma hasUnifEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {ΞΌ : K} :
f.HasUnifEigenvalue ΞΌ 1 β ΞΌ β spectrum K f := by
rw [spectrum.mem_iff, IsUnit.sub_iff, LinearMap.isUnit_iff_ker_eq_bot,
HasUnifEigenvalue, genEigenspace_one, ne_eq, not_iff_not]
simp [Submodule.ext_iff, LinearMap.mem_ker]
alias β¨_, HasUnifEigenvalue.of_mem_spectrumβ© := hasUnifEigenvalue_iff_mem_spectrum
lemma genEigenspace_div (f : End K V) (a b : K) (hb : b β 0) :
genEigenspace f (a / b) 1 = LinearMap.ker (b β’ f - a β’ 1) :=
calc
genEigenspace f (a / b) 1 = genEigenspace f (bβ»ΒΉ * a) 1 := by rw [div_eq_mul_inv, mul_comm]
_ = LinearMap.ker (f - (bβ»ΒΉ * a) β’ 1) := by rw [genEigenspace_one]
_ = LinearMap.ker (f - bβ»ΒΉ β’ a β’ 1) := by rw [smul_smul]
_ = LinearMap.ker (b β’ (f - bβ»ΒΉ β’ a β’ 1)) := by rw [LinearMap.ker_smul _ b hb]
_ = LinearMap.ker (b β’ f - a β’ 1) := by rw [smul_sub, smul_inv_smulβ hb]
/-- The generalized eigenrange for a linear map `f`, a scalar `ΞΌ`, and an exponent `k β ββ`
is the range of `(f - ΞΌ β’ id) ^ k` if `k` is a natural number,
or the infimum of these ranges if `k = β`. -/
def genEigenrange (f : End R M) (ΞΌ : R) (k : ββ) : Submodule R M :=
β¨
l : β, β¨
(_ : l β€ k), LinearMap.range ((f - ΞΌ β’ 1) ^ l)
lemma genEigenrange_nat {f : End R M} {ΞΌ : R} {k : β} :
f.genEigenrange ΞΌ k = LinearMap.range ((f - ΞΌ β’ 1) ^ k) := by
ext x
simp only [genEigenrange, Nat.cast_le, Submodule.mem_iInf, LinearMap.mem_range]
constructor
Β· intro h
exact h _ le_rfl
Β· rintro β¨x, rflβ© i hi
have : k = i + (k - i) := by omega
rw [this, pow_add]
exact β¨_, rflβ©
/-- The exponent of a generalized eigenvalue is never 0. -/
lemma HasUnifEigenvalue.exp_ne_zero {f : End R M} {ΞΌ : R} {k : β}
(h : f.HasUnifEigenvalue ΞΌ k) : k β 0 := by
rintro rfl
simp [HasUnifEigenvalue, Nat.cast_zero, genEigenspace_zero] at h
/-- If there exists a natural number `k` such that the kernel of `(f - ΞΌ β’ id) ^ k` is the
maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not
meaningful. -/
noncomputable def maxUnifEigenspaceIndex (f : End R M) (ΞΌ : R) :=
monotonicSequenceLimitIndex <| (f.genEigenspace ΞΌ).comp <| WithTop.coeOrderHom.toOrderHom
/-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel
`(f - ΞΌ β’ id) ^ k` for some `k`. -/
lemma genEigenspace_top_eq_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M) (ΞΌ : R) :
genEigenspace f ΞΌ β€ = f.genEigenspace ΞΌ (maxUnifEigenspaceIndex f ΞΌ) := by
have := WellFoundedGT.iSup_eq_monotonicSequenceLimit <|
(f.genEigenspace ΞΌ).comp <| WithTop.coeOrderHom.toOrderHom
convert this using 1
simp only [genEigenspace, OrderHom.coe_mk, le_top, iSup_pos, OrderHom.comp_coe,
Function.comp_def]
rw [iSup_prod', iSup_subtype', β sSup_range, β sSup_range]
congr
aesop
lemma genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M)
(ΞΌ : R) (k : ββ) :
f.genEigenspace ΞΌ k β€ f.genEigenspace ΞΌ (maxUnifEigenspaceIndex f ΞΌ) := by
rw [β genEigenspace_top_eq_maxUnifEigenspaceIndex]
exact (f.genEigenspace ΞΌ).monotone le_top
/-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
theorem genEigenspace_eq_genEigenspace_maxUnifEigenspaceIndex_of_le [IsNoetherian R M]
(f : End R M) (ΞΌ : R) {k : β} (hk : maxUnifEigenspaceIndex f ΞΌ β€ k) :
f.genEigenspace ΞΌ k = f.genEigenspace ΞΌ (maxUnifEigenspaceIndex f ΞΌ) :=
le_antisymm
(genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex _ _ _)
((f.genEigenspace ΞΌ).monotone <| by simpa using hk)
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for exponents larger than `k`. -/
lemma HasUnifEigenvalue.le {f : End R M} {ΞΌ : R} {k m : ββ}
(hm : k β€ m) (hk : f.HasUnifEigenvalue ΞΌ k) :
f.HasUnifEigenvalue ΞΌ m := by
unfold HasUnifEigenvalue at *
contrapose! hk
rw [β le_bot_iff, β hk]
exact (f.genEigenspace _).monotone hm
/-- A generalized eigenvalue for some exponent `k` is also
a generalized eigenvalue for positive exponents. -/
lemma HasUnifEigenvalue.lt {f : End R M} {ΞΌ : R} {k m : ββ}
(hm : 0 < m) (hk : f.HasUnifEigenvalue ΞΌ k) :
f.HasUnifEigenvalue ΞΌ m := by
apply HasUnifEigenvalue.le (k := 1) (Order.one_le_iff_pos.mpr hm)
intro contra; apply hk
rw [genEigenspace_one, LinearMap.ker_eq_bot] at contra
rw [eq_bot_iff]
intro x hx
rw [mem_genEigenspace] at hx
rcases hx with β¨l, -, hxβ©
rwa [LinearMap.ker_eq_bot.mpr] at hx
rw [Module.End.coe_pow (f - ΞΌ β’ 1) l]
exact Function.Injective.iterate contra l
/-- Generalized eigenvalues are actually just eigenvalues. -/
@[simp]
lemma hasUnifEigenvalue_iff_hasUnifEigenvalue_one {f : End R M} {ΞΌ : R} {k : ββ} (hk : 0 < k) :
f.HasUnifEigenvalue ΞΌ k β f.HasUnifEigenvalue ΞΌ 1 :=
β¨HasUnifEigenvalue.lt zero_lt_one, HasUnifEigenvalue.lt hkβ©
lemma maxUnifEigenspaceIndex_le_finrank [FiniteDimensional K V] (f : End K V) (ΞΌ : K) :
maxUnifEigenspaceIndex f ΞΌ β€ finrank K V := by
apply Nat.sInf_le
intro n hn
apply le_antisymm
Β· exact (f.genEigenspace ΞΌ).monotone <| WithTop.coeOrderHom.monotone hn
Β· show (f.genEigenspace ΞΌ) n β€ (f.genEigenspace ΞΌ) (finrank K V)
rw [genEigenspace_nat, genEigenspace_nat]
apply ker_pow_le_ker_pow_finrank
/-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`.
(Lemma 8.11 of [axler2015]) -/
lemma genEigenspace_le_genEigenspace_finrank [FiniteDimensional K V] (f : End K V)
(ΞΌ : K) (k : ββ) : f.genEigenspace ΞΌ k β€ f.genEigenspace ΞΌ (finrank K V) := by
calc f.genEigenspace ΞΌ k
β€ f.genEigenspace ΞΌ β€ := (f.genEigenspace _).monotone le_top
_ β€ f.genEigenspace ΞΌ (finrank K V) := by
rw [genEigenspace_top_eq_maxUnifEigenspaceIndex]
exact (f.genEigenspace _).monotone <| by simpa using maxUnifEigenspaceIndex_le_finrank f ΞΌ
/-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/
theorem genEigenspace_eq_genEigenspace_finrank_of_le [FiniteDimensional K V]
(f : End K V) (ΞΌ : K) {k : β} (hk : finrank K V β€ k) :
f.genEigenspace ΞΌ k = f.genEigenspace ΞΌ (finrank K V) :=
le_antisymm
(genEigenspace_le_genEigenspace_finrank _ _ _)
((f.genEigenspace ΞΌ).monotone <| by simpa using hk)
lemma mapsTo_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (ΞΌ : R) (k : ββ) :
MapsTo g (f.genEigenspace ΞΌ k) (f.genEigenspace ΞΌ k) := by
intro x hx
simp only [SetLike.mem_coe, mem_genEigenspace, LinearMap.mem_ker] at hx β’
rcases hx with β¨l, hl, hxβ©
replace h : Commute ((f - ΞΌ β’ (1 : End R M)) ^ l) g :=
(h.sub_left <| Algebra.commute_algebraMap_left ΞΌ g).pow_left l
use l, hl
rw [β LinearMap.comp_apply, β Module.End.mul_eq_comp, h.eq, Module.End.mul_eq_comp,
LinearMap.comp_apply, hx, map_zero]
/-- The restriction of `f - ΞΌ β’ 1` to the `k`-fold generalized `ΞΌ`-eigenspace is nilpotent. -/
lemma isNilpotent_restrict_genEigenspace_nat (f : End R M) (ΞΌ : R) (k : β)
(h : MapsTo (f - ΞΌ β’ (1 : End R M))
(f.genEigenspace ΞΌ k) (f.genEigenspace ΞΌ k) :=
mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f ΞΌ) ΞΌ k) :
IsNilpotent ((f - ΞΌ β’ 1).restrict h) := by
use k
ext β¨x, hxβ©
rw [mem_genEigenspace_nat] at hx
rw [LinearMap.zero_apply, ZeroMemClass.coe_zero, ZeroMemClass.coe_eq_zero,
Module.End.pow_restrict, LinearMap.restrict_apply]
ext
simpa
/-- The restriction of `f - ΞΌ β’ 1` to the generalized `ΞΌ`-eigenspace is nilpotent. -/
lemma isNilpotent_restrict_genEigenspace_top [IsNoetherian R M] (f : End R M) (ΞΌ : R)
(h : MapsTo (f - ΞΌ β’ (1 : End R M))
(f.genEigenspace ΞΌ β€) (f.genEigenspace ΞΌ β€) :=
mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f ΞΌ) ΞΌ _) :
IsNilpotent ((f - ΞΌ β’ 1).restrict h) := by
apply isNilpotent_restrict_of_le
on_goal 2 => apply isNilpotent_restrict_genEigenspace_nat f ΞΌ (maxUnifEigenspaceIndex f ΞΌ)
rw [genEigenspace_top_eq_maxUnifEigenspaceIndex]
/-- The submodule `eigenspace f ΞΌ` for a linear map `f` and a scalar `ΞΌ` consists of all vectors `x`
such that `f x = ΞΌ β’ x`. (Def 5.36 of [axler2015]). -/
abbrev eigenspace (f : End R M) (ΞΌ : R) : Submodule R M :=
f.genEigenspace ΞΌ 1
lemma eigenspace_def {f : End R M} {ΞΌ : R} :
f.eigenspace ΞΌ = LinearMap.ker (f - ΞΌ β’ 1) := by
rw [eigenspace, genEigenspace_one]
@[simp]
theorem eigenspace_zero (f : End R M) : f.eigenspace 0 = LinearMap.ker f := by
simp only [eigenspace, β Nat.cast_one (R := ββ), genEigenspace_zero_nat, pow_one]
/-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/
abbrev HasEigenvector (f : End R M) (ΞΌ : R) (x : M) : Prop :=
HasUnifEigenvector f ΞΌ 1 x
lemma hasEigenvector_iff {f : End R M} {ΞΌ : R} {x : M} :
f.HasEigenvector ΞΌ x β x β f.eigenspace ΞΌ β§ x β 0 := Iff.rfl
/-- A scalar `ΞΌ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x`
such that `f x = ΞΌ β’ x`. (Def 5.5 of [axler2015]). -/
abbrev HasEigenvalue (f : End R M) (a : R) : Prop :=
HasUnifEigenvalue f a 1
lemma hasEigenvalue_iff {f : End R M} {ΞΌ : R} :
f.HasEigenvalue ΞΌ β f.eigenspace ΞΌ β β₯ := Iff.rfl
/-- The eigenvalues of the endomorphism `f`, as a subtype of `R`. -/
abbrev Eigenvalues (f : End R M) : Type _ :=
UnifEigenvalues f 1
@[coe]
abbrev Eigenvalues.val (f : Module.End R M) : Eigenvalues f β R := UnifEigenvalues.val f 1
theorem hasEigenvalue_of_hasEigenvector {f : End R M} {ΞΌ : R} {x : M} (h : HasEigenvector f ΞΌ x) :
HasEigenvalue f ΞΌ :=
h.hasUnifEigenvalue
theorem mem_eigenspace_iff {f : End R M} {ΞΌ : R} {x : M} : x β eigenspace f ΞΌ β f x = ΞΌ β’ x :=
mem_genEigenspace_one
nonrec
theorem HasEigenvector.apply_eq_smul {f : End R M} {ΞΌ : R} {x : M} (hx : f.HasEigenvector ΞΌ x) :
f x = ΞΌ β’ x :=
hx.apply_eq_smul
nonrec
theorem HasEigenvector.pow_apply {f : End R M} {ΞΌ : R} {v : M} (hv : f.HasEigenvector ΞΌ v) (n : β) :
(f ^ n) v = ΞΌ ^ n β’ v :=
hv.pow_apply n
theorem HasEigenvalue.exists_hasEigenvector {f : End R M} {ΞΌ : R} (hΞΌ : f.HasEigenvalue ΞΌ) :
β v, f.HasEigenvector ΞΌ v :=
Submodule.exists_mem_ne_zero_of_ne_bot hΞΌ
nonrec
lemma HasEigenvalue.pow {f : End R M} {ΞΌ : R} (h : f.HasEigenvalue ΞΌ) (n : β) :
(f ^ n).HasEigenvalue (ΞΌ ^ n) :=
h.pow n
/-- A nilpotent endomorphism has nilpotent eigenvalues.
See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/
nonrec
lemma HasEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M}
(hfn : IsNilpotent f) {ΞΌ : R} (hf : f.HasEigenvalue ΞΌ) :
IsNilpotent ΞΌ :=
hf.isNilpotent_of_isNilpotent hfn
nonrec
theorem HasEigenvalue.mem_spectrum {f : End R M} {ΞΌ : R} (hΞΌ : HasEigenvalue f ΞΌ) :
ΞΌ β spectrum R f :=
hΞΌ.mem_spectrum
theorem hasEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {ΞΌ : K} :
f.HasEigenvalue ΞΌ β ΞΌ β spectrum K f :=
hasUnifEigenvalue_iff_mem_spectrum
alias β¨_, HasEigenvalue.of_mem_spectrumβ© := hasEigenvalue_iff_mem_spectrum
theorem eigenspace_div (f : End K V) (a b : K) (hb : b β 0) :
eigenspace f (a / b) = LinearMap.ker (b β’ f - algebraMap K (End K V) a) :=
genEigenspace_div f a b hb
@[deprecated genEigenspace_nat (since := "2024-10-28")]
lemma genEigenspace_def (f : End R M) (ΞΌ : R) (k : β) :
f.genEigenspace ΞΌ k = LinearMap.ker ((f - ΞΌ β’ 1) ^ k) :=
genEigenspace_nat
/-- A nonzero element of a generalized eigenspace is a generalized eigenvector.
(Def 8.9 of [axler2015]) -/
abbrev HasGenEigenvector (f : End R M) (ΞΌ : R) (k : β) (x : M) : Prop :=
HasUnifEigenvector f ΞΌ k x
lemma hasGenEigenvector_iff {f : End R M} {ΞΌ : R} {k : β} {x : M} :
f.HasGenEigenvector ΞΌ k x β x β f.genEigenspace ΞΌ k β§ x β 0 := Iff.rfl
/-- A scalar `ΞΌ` is a generalized eigenvalue for a linear map `f` and an exponent `k β β` if there
are generalized eigenvectors for `f`, `k`, and `ΞΌ`. -/
abbrev HasGenEigenvalue (f : End R M) (ΞΌ : R) (k : β) : Prop :=
HasUnifEigenvalue f ΞΌ k
lemma hasGenEigenvalue_iff {f : End R M} {ΞΌ : R} {k : β} :
f.HasGenEigenvalue ΞΌ k β f.genEigenspace ΞΌ k β β₯ := Iff.rfl
@[deprecated genEigenrange_nat (since := "2024-10-28")]
lemma genEigenrange_def {f : End R M} {ΞΌ : R} {k : β} :
f.genEigenrange ΞΌ k = LinearMap.range ((f - ΞΌ β’ 1) ^ k) :=
genEigenrange_nat
/-- The exponent of a generalized eigenvalue is never 0. -/
theorem exp_ne_zero_of_hasGenEigenvalue {f : End R M} {ΞΌ : R} {k : β}
(h : f.HasGenEigenvalue ΞΌ k) : k β 0 :=
HasUnifEigenvalue.exp_ne_zero h
/-- The union of the kernels of `(f - ΞΌ β’ id) ^ k` over all `k`. -/
abbrev maxGenEigenspace (f : End R M) (ΞΌ : R) : Submodule R M :=
genEigenspace f ΞΌ β€
lemma iSup_genEigenspace_eq (f : End R M) (ΞΌ : R) :
β¨ k : β, (f.genEigenspace ΞΌ) k = f.maxGenEigenspace ΞΌ := by
simp_rw [maxGenEigenspace, genEigenspace_top]
@[deprecated iSup_genEigenspace_eq (since := "2024-10-23")]
lemma maxGenEigenspace_def (f : End R M) (ΞΌ : R) :
f.maxGenEigenspace ΞΌ = β¨ k : β, f.genEigenspace ΞΌ k :=
(iSup_genEigenspace_eq f ΞΌ).symm
theorem genEigenspace_le_maximal (f : End R M) (ΞΌ : R) (k : β) :
f.genEigenspace ΞΌ k β€ f.maxGenEigenspace ΞΌ :=
(f.genEigenspace ΞΌ).monotone le_top
@[simp]
theorem mem_maxGenEigenspace (f : End R M) (ΞΌ : R) (m : M) :
m β f.maxGenEigenspace ΞΌ β β k : β, ((f - ΞΌ β’ (1 : End R M)) ^ k) m = 0 :=
| mem_genEigenspace_top
/-- If there exists a natural number `k` such that the kernel of `(f - ΞΌ β’ id) ^ k` is the
maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not
meaningful. -/
noncomputable abbrev maxGenEigenspaceIndex (f : End R M) (ΞΌ : R) :=
| Mathlib/LinearAlgebra/Eigenspace/Basic.lean | 522 | 527 |
/-
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, Julian Kuelshammer
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Group.Commute.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Finite
import Mathlib.Algebra.Group.Subgroup.Finite
import Mathlib.Algebra.Module.NatInt
import Mathlib.Algebra.Order.Group.Action
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Data.Int.ModEq
import Mathlib.Dynamics.PeriodicPts.Lemmas
import Mathlib.GroupTheory.Index
import Mathlib.NumberTheory.Divisors
import Mathlib.Order.Interval.Set.Infinite
/-!
# Order of an element
This file defines the order of an element of a finite group. For a finite group `G` the order of
`x β G` is the minimal `n β₯ 1` such that `x ^ n = 1`.
## Main definitions
* `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite
order.
* `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`.
* `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`
if `x` has infinite order.
* `addOrderOf` is the additive analogue of `orderOf`.
## Tags
order of an element
-/
assert_not_exists Field
open Function Fintype Nat Pointwise Subgroup Submonoid
open scoped Finset
variable {G H A Ξ± Ξ² : Type*}
section Monoid
variable [Monoid G] {a b x y : G} {n m : β}
section IsOfFinOrder
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed
@[to_additive]
theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * Β·) n 1 β x ^ n = 1 := by
rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one]
/-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there
exists `n β₯ 1` such that `x ^ n = 1`. -/
@[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an
additive monoid to be of finite order, i.e. there exists `n β₯ 1` such that `n β’ a = 0`."]
def IsOfFinOrder (x : G) : Prop :=
(1 : G) β periodicPts (x * Β·)
theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) β IsOfFinOrder x :=
Iff.rfl
theorem isOfFinOrder_ofAdd_iff {Ξ± : Type*} [AddMonoid Ξ±] {x : Ξ±} :
IsOfFinOrder (Multiplicative.ofAdd x) β IsOfFinAddOrder x := Iff.rfl
@[to_additive]
theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x β β n, 0 < n β§ x ^ n = 1 := by
simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one]
@[to_additive] alias β¨IsOfFinOrder.exists_pow_eq_one, _β© := isOfFinOrder_iff_pow_eq_one
@[to_additive]
lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} :
IsOfFinOrder x β β (n : β€), n β 0 β§ x ^ n = 1 := by
rw [isOfFinOrder_iff_pow_eq_one]
refine β¨fun β¨n, hn, hn'β© β¦ β¨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n βΈ hn'β©,
fun β¨n, hn, hn'β© β¦ β¨n.natAbs, Int.natAbs_pos.mpr hn, ?_β©β©
rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h
Β· rwa [h, zpow_natCast] at hn'
Β· rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn'
/-- See also `injective_pow_iff_not_isOfFinOrder`. -/
@[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."]
theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : β => x ^ n) :
Β¬IsOfFinOrder x := by
simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and]
intro n hn_pos hnx
rw [β pow_zero x] at hnx
rw [h hnx] at hn_pos
exact irrefl 0 hn_pos
/-- 1 is of finite order in any monoid. -/
@[to_additive (attr := simp) "0 is of finite order in any additive monoid."]
theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) :=
isOfFinOrder_iff_pow_eq_one.mpr β¨1, Nat.one_pos, one_pow 1β©
@[to_additive]
lemma IsOfFinOrder.pow {n : β} : IsOfFinOrder a β IsOfFinOrder (a ^ n) := by
simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro β¨m, hm, haβ©
exact β¨m, hm, by simp [pow_right_comm _ n, ha]β©
@[to_additive]
lemma IsOfFinOrder.of_pow {n : β} (h : IsOfFinOrder (a ^ n)) (hn : n β 0) : IsOfFinOrder a := by
rw [isOfFinOrder_iff_pow_eq_one] at *
rcases h with β¨m, hm, haβ©
exact β¨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]β©
@[to_additive (attr := simp)]
lemma isOfFinOrder_pow {n : β} : IsOfFinOrder (a ^ n) β IsOfFinOrder a β¨ n = 0 := by
rcases Decidable.eq_or_ne n 0 with rfl | hn
Β· simp
Β· exact β¨fun h β¦ .inl <| h.of_pow hn, fun h β¦ (h.resolve_right hn).powβ©
/-- Elements of finite order are of finite order in submonoids. -/
@[to_additive "Elements of finite order are of finite order in submonoids."]
theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} :
IsOfFinOrder (x : G) β IsOfFinOrder x := by
rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one]
norm_cast
theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x β IsOfFinOrder y := by
simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro β¨n, n_gt_0, eq'β©
exact β¨n, n_gt_0, by rw [β isConj_one_right, β eq']; exact h.pow nβ©
/-- The image of an element of finite order has finite order. -/
@[to_additive "The image of an element of finite additive order has finite additive order."]
theorem MonoidHom.isOfFinOrder [Monoid H] (f : G β* H) {x : G} (h : IsOfFinOrder x) :
IsOfFinOrder <| f x :=
isOfFinOrder_iff_pow_eq_one.mpr <| by
obtain β¨n, npos, hnβ© := h.exists_pow_eq_one
exact β¨n, npos, by rw [β f.map_pow, hn, f.map_one]β©
/-- If a direct product has finite order then so does each component. -/
@[to_additive "If a direct product has finite additive order then so does each component."]
theorem IsOfFinOrder.apply {Ξ· : Type*} {Gs : Ξ· β Type*} [β i, Monoid (Gs i)] {x : β i, Gs i}
(h : IsOfFinOrder x) : β i, IsOfFinOrder (x i) := by
obtain β¨n, npos, hnβ© := h.exists_pow_eq_one
exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr β¨n, npos, (congr_fun hn.symm _).symmβ©
/-- The submonoid generated by an element is a group if that element has finite order. -/
@[to_additive "The additive submonoid generated by an element is
an additive group if that element has finite order."]
noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) :
Group (Submonoid.powers x) := by
obtain β¨hpos, hxβ© := hx.exists_pow_eq_one.choose_spec
exact Submonoid.groupPowers hpos hx
end IsOfFinOrder
/-- `orderOf x` is the order of the element `x`, i.e. the `n β₯ 1`, s.t. `x ^ n = 1` if it exists.
Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/
@[to_additive
"`addOrderOf a` is the order of the element `a`, i.e. the `n β₯ 1`, s.t. `n β’ a = 0` if it
exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."]
noncomputable def orderOf (x : G) : β :=
minimalPeriod (x * Β·) 1
@[simp]
theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x :=
rfl
@[simp]
lemma orderOf_ofAdd_eq_addOrderOf {Ξ± : Type*} [AddMonoid Ξ±] (a : Ξ±) :
orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl
@[to_additive]
protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x :=
minimalPeriod_pos_of_mem_periodicPts h
@[to_additive addOrderOf_nsmul_eq_zero]
theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by
convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * Β·) 1)
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite
rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one]
@[to_additive]
theorem orderOf_eq_zero (h : Β¬IsOfFinOrder x) : orderOf x = 0 := by
rwa [orderOf, minimalPeriod, dif_neg]
@[to_additive]
theorem orderOf_eq_zero_iff : orderOf x = 0 β Β¬IsOfFinOrder x :=
β¨fun h H β¦ H.orderOf_pos.ne' h, orderOf_eq_zeroβ©
@[to_additive]
theorem orderOf_eq_zero_iff' : orderOf x = 0 β β n : β, 0 < n β x ^ n β 1 := by
simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and]
@[to_additive]
theorem orderOf_eq_iff {n} (h : 0 < n) :
orderOf x = n β x ^ n = 1 β§ β m, m < n β 0 < m β x ^ m β 1 := by
simp_rw [Ne, β isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod]
split_ifs with h1
Β· classical
rw [find_eq_iff]
simp only [h, true_and]
push_neg
rfl
Β· rw [iff_false_left h.ne]
rintro β¨h', -β©
exact h1 β¨n, h, h'β©
/-- A group element has finite order iff its order is positive. -/
@[to_additive
"A group element has finite additive order iff its order is positive."]
theorem orderOf_pos_iff : 0 < orderOf x β IsOfFinOrder x := by
rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero]
@[to_additive]
theorem IsOfFinOrder.mono [Monoid Ξ²] {y : Ξ²} (hx : IsOfFinOrder x) (h : orderOf y β£ orderOf x) :
IsOfFinOrder y := by rw [β orderOf_pos_iff] at hx β’; exact Nat.pos_of_dvd_of_pos h hx
@[to_additive]
theorem pow_ne_one_of_lt_orderOf (n0 : n β 0) (h : n < orderOf x) : x ^ n β 1 := fun j =>
not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j)
@[to_additive]
theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x β€ n :=
IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one])
@[to_additive (attr := simp)]
theorem orderOf_one : orderOf (1 : G) = 1 := by
rw [orderOf, β minimalPeriod_id (x := (1 : G)), β one_mul_eq_id]
@[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff]
theorem orderOf_eq_one_iff : orderOf x = 1 β x = 1 := by
rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one]
@[to_additive (attr := simp) mod_addOrderOf_nsmul]
lemma pow_mod_orderOf (x : G) (n : β) : x ^ (n % orderOf x) = x ^ n :=
calc
x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by
simp [pow_add, pow_mul, pow_orderOf_eq_one]
_ = x ^ n := by rw [Nat.mod_add_div]
@[to_additive]
theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x β£ n :=
IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h)
@[to_additive]
theorem orderOf_dvd_iff_pow_eq_one {n : β} : orderOf x β£ n β x ^ n = 1 :=
β¨fun h => by rw [β pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero],
orderOf_dvd_of_pow_eq_oneβ©
@[to_additive addOrderOf_smul_dvd]
theorem orderOf_pow_dvd (n : β) : orderOf (x ^ n) β£ orderOf x := by
rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow]
@[to_additive]
lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ Β·) := by
simpa only [mul_left_iterate, mul_one]
using iterate_injOn_Iio_minimalPeriod (f := (x * Β·)) (x := 1)
@[to_additive]
protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G]
(hx : IsOfFinOrder x) :
y β Submonoid.powers x β y β (Finset.range (orderOf x)).image (x ^ Β·) :=
Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _
@[to_additive]
protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) :
(Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ Β·) :=
Set.ext fun _ β¦ hx.mem_powers_iff_mem_range_orderOf
@[to_additive]
theorem pow_eq_one_iff_modEq : x ^ n = 1 β n β‘ 0 [MOD orderOf x] := by
rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one]
@[to_additive]
theorem orderOf_map_dvd {H : Type*} [Monoid H] (Ο : G β* H) (x : G) :
orderOf (Ο x) β£ orderOf x := by
apply orderOf_dvd_of_pow_eq_one
rw [β map_pow, pow_orderOf_eq_one]
apply map_one
@[to_additive]
theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : β m : β, (x ^ n) ^ m = x := by
by_cases h0 : orderOf x = 0
Β· rw [h0, coprime_zero_right] at h
exact β¨1, by rw [h, pow_one, pow_one]β©
by_cases h1 : orderOf x = 1
Β· exact β¨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]β©
obtain β¨m, hβ© := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr β¨h0, h1β©)
exact β¨m, by rw [β pow_mul, β pow_mod_orderOf, h, pow_one]β©
/-- If `x^n = 1`, but `x^(n/p) β 1` for all prime factors `p` of `n`,
then `x` has order `n` in `G`. -/
@[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x β 0` for
all prime factors `p` of `n`, then `x` has order `n` in `G`."]
theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1)
(hd : β p : β, p.Prime β p β£ n β x ^ (n / p) β 1) : orderOf x = n := by
-- Let `a` be `n/(orderOf x)`, and show `a = 1`
obtain β¨a, haβ© := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx)
suffices a = 1 by simp [this, ha]
-- Assume `a` is not one...
by_contra h
have a_min_fac_dvd_p_sub_one : a.minFac β£ n := by
obtain β¨b, hbβ© : β b : β, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd
rw [hb, β mul_assoc] at ha
exact Dvd.intro_left (orderOf x * b) ha.symm
-- Use the minimum prime factor of `a` as `p`.
refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_
rw [β orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm,
Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)]
Β· exact Nat.minFac_dvd a
Β· rw [isOfFinOrder_iff_pow_eq_one]
exact Exists.intro n (id β¨hn, hxβ©)
@[to_additive]
theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} :
orderOf x = orderOf y β β n : β, x ^ n = 1 β y ^ n = 1 := by
simp_rw [β isPeriodicPt_mul_iff_pow_eq_one, β minimalPeriod_eq_minimalPeriod_iff, orderOf]
/-- An injective homomorphism of monoids preserves orders of elements. -/
@[to_additive "An injective homomorphism of additive monoids preserves orders of elements."]
theorem orderOf_injective {H : Type*} [Monoid H] (f : G β* H) (hf : Function.Injective f) (x : G) :
orderOf (f x) = orderOf x := by
simp_rw [orderOf_eq_orderOf_iff, β f.map_pow, β f.map_one, hf.eq_iff, forall_const]
/-- A multiplicative equivalence preserves orders of elements. -/
@[to_additive (attr := simp) "An additive equivalence preserves orders of elements."]
lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G β* H) (x : G) :
orderOf (e x) = orderOf x :=
orderOf_injective e.toMonoidHom e.injective x
@[to_additive]
theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G β* H} (hf : Injective f) :
IsOfFinOrder (f x) β IsOfFinOrder x := by
rw [β orderOf_pos_iff, orderOf_injective f hf x, β orderOf_pos_iff]
@[to_additive (attr := norm_cast, simp)]
theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y :=
orderOf_injective H.subtype Subtype.coe_injective y
@[to_additive]
theorem orderOf_units {y : GΛ£} : orderOf (y : G) = orderOf y :=
orderOf_injective (Units.coeHom G) Units.ext y
/-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/
@[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive
unit with inverse `(addOrderOf x - 1) β’ x`. "]
noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : MΛ£ :=
β¨x, x ^ (orderOf x - 1),
by rw [β _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one],
by rw [β _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]β©
@[to_additive]
lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := β¨hx.unit, rflβ©
variable (x)
@[to_additive]
theorem orderOf_pow' (h : n β 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by
unfold orderOf
rw [β minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate]
@[to_additive]
lemma orderOf_pow_of_dvd {x : G} {n : β} (hn : n β 0) (dvd : n β£ orderOf x) :
orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd]
@[to_additive]
lemma orderOf_pow_orderOf_div {x : G} {n : β} (hx : orderOf x β 0) (hn : n β£ orderOf x) :
orderOf (x ^ (orderOf x / n)) = n := by
rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx]
rw [β Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx
variable (n)
@[to_additive]
protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) :
orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by
unfold orderOf
rw [β minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate]
@[to_additive]
lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by
by_cases hg : IsOfFinOrder y
Β· rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one]
Β· rw [m.coprime_zero_left.1 (orderOf_eq_zero hg βΈ h), pow_one]
@[to_additive]
lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) :
Nat.card (powers a : Set G) β€ orderOf a := by
classical
simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range]
using Finset.card_image_le (s := Finset.range (orderOf a))
@[to_additive]
lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by
classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _
namespace Commute
variable {x}
@[to_additive]
theorem orderOf_mul_dvd_lcm (h : Commute x y) :
orderOf (x * y) β£ Nat.lcm (orderOf x) (orderOf y) := by
rw [orderOf, β comp_mul_left]
exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left
@[to_additive]
theorem orderOf_dvd_lcm_mul (h : Commute x y):
orderOf y β£ Nat.lcm (orderOf x) (orderOf (x * y)) := by
by_cases h0 : orderOf x = 0
Β· rw [h0, lcm_zero_left]
apply dvd_zero
conv_lhs =>
rw [β one_mul y, β pow_orderOf_eq_one x, β succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0),
_root_.pow_succ, mul_assoc]
exact
(((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans
(lcm_dvd_iff.2 β¨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _β©)
@[to_additive addOrderOf_add_dvd_mul_addOrderOf]
theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y):
orderOf (x * y) β£ orderOf x * orderOf y :=
dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _)
@[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime]
theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y)
(hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by
rw [orderOf, β comp_mul_left]
exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco
/-- Commuting elements of finite order are closed under multiplication. -/
@[to_additive "Commuting elements of finite additive order are closed under addition."]
theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) :
IsOfFinOrder (x * y) :=
orderOf_pos_iff.mp <|
pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos
/-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes
with `y`, then `x * y` has the same order as `y`. -/
@[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd
"If each prime factor of
`addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`,
then `x + y` has the same order as `y`."]
theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y)
(hdvd : β p : β, p.Prime β p β£ orderOf x β p * orderOf x β£ orderOf y) :
orderOf (x * y) = orderOf y := by
have hoy := hy.orderOf_pos
have hxy := dvd_of_forall_prime_mul_dvd hdvd
apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, β orderOf_dvd_iff_pow_eq_one]
Β· exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl)
refine fun p hp hpy hd => hp.ne_one ?_
rw [β Nat.dvd_one, β mul_dvd_mul_iff_right hoy.ne', one_mul, β dvd_div_iff_mul_dvd hpy]
refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd)
by_cases h : p β£ orderOf x
exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy]
end Commute
section PPrime
variable {x n} {p : β} [hp : Fact p.Prime]
@[to_additive]
theorem orderOf_eq_prime_iff : orderOf x = p β x ^ p = 1 β§ x β 1 := by
rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one]
/-- The backward direction of `orderOf_eq_prime_iff`. -/
@[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."]
theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x β 1) : orderOf x = p :=
orderOf_eq_prime_iff.mpr β¨hg, hg1β©
@[to_additive addOrderOf_eq_prime_pow]
theorem orderOf_eq_prime_pow (hnot : Β¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :
orderOf x = p ^ (n + 1) := by
apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one]
@[to_additive exists_addOrderOf_eq_prime_pow_iff]
theorem exists_orderOf_eq_prime_pow_iff :
(β k : β, orderOf x = p ^ k) β β m : β, x ^ (p : β) ^ m = 1 :=
β¨fun β¨k, hkβ© => β¨k, by rw [β hk, pow_orderOf_eq_one]β©, fun β¨_, hmβ© => by
obtain β¨k, _, hkβ© := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm)
exact β¨k, hkβ©β©
end PPrime
/-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/
@[to_additive "The equivalence between `Fin (addOrderOf a)` and
`AddSubmonoid.multiples a`, sending `i` to `i β’ a`"]
noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) β powers x :=
Equiv.ofBijective (fun n β¦ β¨x ^ (n : β), β¨n, rflβ©β©) β¨fun β¨_, hββ© β¨_, hββ© ij β¦
Fin.ext (pow_injOn_Iio_orderOf hβ hβ (Subtype.mk_eq_mk.1 ij)), fun β¨_, i, rflβ© β¦
β¨β¨i % orderOf x, mod_lt _ hx.orderOf_posβ©, Subtype.eq <| pow_mod_orderOf _ _β©β©
@[to_additive (attr := simp)]
lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} :
finEquivPowers hx n = β¨x ^ (n : β), n, rflβ© := rfl
@[to_additive (attr := simp)]
lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : β) :
(finEquivPowers hx).symm β¨x ^ n, _, rflβ© = β¨n % orderOf x, Nat.mod_lt _ hx.orderOf_posβ© := by
rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, β pow_mod_orderOf, Fin.val_mk]
variable {x n} (hx : IsOfFinOrder x)
include hx
@[to_additive]
theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m β n β‘ m [MOD orderOf x] := by
wlog hmn : m β€ n generalizing m n
Β· rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)]
obtain β¨k, rflβ© := Nat.exists_eq_add_of_le hmn
rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq]
exact β¨fun h β¦ Nat.ModEq.add_left _ h, fun h β¦ Nat.ModEq.add_left_cancel' _ hβ©
@[to_additive]
lemma IsOfFinOrder.pow_inj_mod {n m : β} : x ^ n = x ^ m β n % orderOf x = m % orderOf x :=
hx.pow_eq_pow_iff_modEq
end Monoid
section CancelMonoid
variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : β}
@[to_additive]
theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m β n β‘ m [MOD orderOf x] := by
wlog hmn : m β€ n generalizing m n
Β· rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)]
obtain β¨k, rflβ© := Nat.exists_eq_add_of_le hmn
rw [β mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq]
exact β¨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ hβ©
@[to_additive (attr := simp)]
lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : β β¦ x ^ n) β Β¬IsOfFinOrder x := by
refine β¨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_β©
rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm
@[to_additive]
lemma pow_inj_mod {n m : β} : x ^ n = x ^ m β n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq
@[to_additive]
theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : β} : x ^ n = x ^ m β n = m := by
rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff]
@[to_additive]
theorem infinite_not_isOfFinOrder {x : G} (h : Β¬IsOfFinOrder x) :
{ y : G | Β¬IsOfFinOrder y }.Infinite := by
let s := { n | 0 < n }.image fun n : β => x ^ n
have hs : s β { y : G | Β¬IsOfFinOrder y } := by
rintro - β¨n, hn : 0 < n, rflβ© (contra : IsOfFinOrder (x ^ n))
apply h
rw [isOfFinOrder_iff_pow_eq_one] at contra β’
obtain β¨m, hm, hm'β© := contra
exact β¨n * m, mul_pos hn hm, by rwa [pow_mul]β©
suffices s.Infinite by exact this.mono hs
contrapose! h
have : Β¬Injective fun n : β => x ^ n := by
have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h)
contrapose! this
exact Set.injOn_of_injective this
rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this
@[to_additive (attr := simp)]
lemma finite_powers : (powers a : Set G).Finite β IsOfFinOrder a := by
refine β¨fun h β¦ ?_, IsOfFinOrder.finite_powersβ©
obtain β¨m, n, hmn, haβ© := h.exists_lt_map_eq_of_forall_mem (f := fun n : β β¦ a ^ n)
(fun n β¦ by simp [mem_powers_iff])
refine isOfFinOrder_iff_pow_eq_one.2 β¨n - m, tsub_pos_iff_lt.2 hmn, ?_β©
rw [β mul_left_cancel_iff (a := a ^ m), β pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one]
@[to_additive (attr := simp)]
lemma infinite_powers : (powers a : Set G).Infinite β Β¬ IsOfFinOrder a := finite_powers.not
/-- See also `orderOf_eq_card_powers`. -/
@[to_additive "See also `addOrder_eq_card_multiples`."]
lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by
classical
by_cases ha : IsOfFinOrder a
Β· exact (Nat.card_congr (finEquivPowers ha).symm).trans <| by simp
Β· have := (infinite_powers.2 ha).to_subtype
rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite]
end CancelMonoid
section Group
variable [Group G] {x y : G} {i : β€}
/-- Inverses of elements of finite order have finite order. -/
@[to_additive (attr := simp) "Inverses of elements of finite additive order
have finite additive order."]
theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder xβ»ΒΉ β IsOfFinOrder x := by
simp [isOfFinOrder_iff_pow_eq_one]
@[to_additive] alias β¨IsOfFinOrder.of_inv, IsOfFinOrder.invβ© := isOfFinOrder_inv_iff
@[to_additive]
theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : β€) β£ i β x ^ i = 1 := by
rcases Int.eq_nat_or_neg i with β¨i, rfl | rflβ©
Β· rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast]
Β· rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast,
orderOf_dvd_iff_pow_eq_one]
@[to_additive (attr := simp)]
theorem orderOf_inv (x : G) : orderOf xβ»ΒΉ = orderOf x := by simp [orderOf_eq_orderOf_iff]
@[to_additive]
theorem orderOf_dvd_sub_iff_zpow_eq_zpow {a b : β€} : (orderOf x : β€) β£ a - b β x ^ a = x ^ b := by
rw [orderOf_dvd_iff_zpow_eq_one, zpow_sub, mul_inv_eq_one]
namespace Subgroup
variable {H : Subgroup G}
@[to_additive (attr := norm_cast)]
lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a :=
orderOf_injective H.subtype Subtype.coe_injective _
@[to_additive (attr := simp)]
lemma orderOf_mk (a : G) (ha) : orderOf (β¨a, haβ© : H) = orderOf a := (orderOf_coe _).symm
end Subgroup
@[to_additive mod_addOrderOf_zsmul]
lemma zpow_mod_orderOf (x : G) (z : β€) : x ^ (z % (orderOf x : β€)) = x ^ z :=
calc
x ^ (z % (orderOf x : β€)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : β€) := by
simp [zpow_add, zpow_mul, pow_orderOf_eq_one]
_ = x ^ z := by rw [Int.emod_add_ediv]
@[to_additive (attr := simp) zsmul_smul_addOrderOf]
theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by
by_cases h : IsOfFinOrder x
Β· rw [β zpow_natCast, β zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow]
Β· rw [orderOf_eq_zero h, _root_.pow_zero]
@[to_additive]
theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : β€} : IsOfFinOrder (x ^ i) :=
isOfFinOrder_iff_pow_eq_one.mpr β¨orderOf x, h.orderOf_pos, zpow_pow_orderOfβ©
@[to_additive]
theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y β Subgroup.zpowers x) :
IsOfFinOrder y := by
obtain β¨k, rflβ© := Subgroup.mem_zpowers_iff.mp h'
exact h.zpow
@[to_additive]
theorem orderOf_dvd_of_mem_zpowers (h : y β Subgroup.zpowers x) : orderOf y β£ orderOf x := by
obtain β¨k, rflβ© := Subgroup.mem_zpowers_iff.mp h
rw [orderOf_dvd_iff_pow_eq_one]
exact zpow_pow_orderOf
theorem smul_eq_self_of_mem_zpowers {Ξ± : Type*} [MulAction G Ξ±] (hx : x β Subgroup.zpowers y)
{a : Ξ±} (hs : y β’ a = a) : x β’ a = a := by
obtain β¨k, rflβ© := Subgroup.mem_zpowers_iff.mp hx
rw [β MulAction.toPerm_apply, β MulAction.toPermHom_apply, MonoidHom.map_zpow _ y k,
MulAction.toPermHom_apply]
exact Function.IsFixedPt.perm_zpow (by exact hs) k -- Porting note: help elab'n with `by exact`
theorem vadd_eq_self_of_mem_zmultiples {Ξ± G : Type*} [AddGroup G] [AddAction G Ξ±] {x y : G}
(hx : x β AddSubgroup.zmultiples y) {a : Ξ±} (hs : y +α΅₯ a = a) : x +α΅₯ a = a :=
@smul_eq_self_of_mem_zpowers (Multiplicative G) _ _ _ Ξ± _ hx a hs
attribute [to_additive existing] smul_eq_self_of_mem_zpowers
@[to_additive]
lemma IsOfFinOrder.mem_powers_iff_mem_zpowers (hx : IsOfFinOrder x) :
y β powers x β y β zpowers x :=
β¨fun β¨n, hnβ© β¦ β¨n, by simp_allβ©, fun β¨i, hiβ© β¦ β¨(i % orderOf x).natAbs, by
dsimp only
rwa [β zpow_natCast, Int.natAbs_of_nonneg <| Int.emod_nonneg _ <|
Int.natCast_ne_zero_iff_pos.2 <| hx.orderOf_pos, zpow_mod_orderOf]β©β©
@[to_additive]
lemma IsOfFinOrder.powers_eq_zpowers (hx : IsOfFinOrder x) : (powers x : Set G) = zpowers x :=
Set.ext fun _ β¦ hx.mem_powers_iff_mem_zpowers
@[to_additive]
lemma IsOfFinOrder.mem_zpowers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) :
y β zpowers x β y β (Finset.range (orderOf x)).image (x ^ Β·) :=
hx.mem_powers_iff_mem_zpowers.symm.trans hx.mem_powers_iff_mem_range_orderOf
/-- The equivalence between `Fin (orderOf x)` and `Subgroup.zpowers x`, sending `i` to `x ^ i`. -/
@[to_additive "The equivalence between `Fin (addOrderOf a)` and
`Subgroup.zmultiples a`, sending `i` to `i β’ a`."]
noncomputable def finEquivZPowers (hx : IsOfFinOrder x) :
Fin (orderOf x) β zpowers x :=
(finEquivPowers hx).trans <| Equiv.setCongr hx.powers_eq_zpowers
@[to_additive]
lemma finEquivZPowers_apply (hx : IsOfFinOrder x) {n : Fin (orderOf x)} :
finEquivZPowers hx n = β¨x ^ (n : β), n, zpow_natCast x nβ© := rfl
@[to_additive]
lemma finEquivZPowers_symm_apply (hx : IsOfFinOrder x) (n : β) :
(finEquivZPowers hx).symm β¨x ^ n, β¨n, by simpβ©β© =
β¨n % orderOf x, Nat.mod_lt _ hx.orderOf_posβ© := by
rw [finEquivZPowers, Equiv.symm_trans_apply]; exact finEquivPowers_symm_apply _ n
end Group
section CommMonoid
variable [CommMonoid G] {x y : G}
/-- Elements of finite order are closed under multiplication. -/
@[to_additive "Elements of finite additive order are closed under addition."]
theorem IsOfFinOrder.mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) :=
(Commute.all x y).isOfFinOrder_mul hx hy
end CommMonoid
section FiniteMonoid
variable [Monoid G] {x : G} {n : β}
@[to_additive]
theorem sum_card_orderOf_eq_card_pow_eq_one [Fintype G] [DecidableEq G] (hn : n β 0) :
β m β divisors n, #{x : G | orderOf x = m} = #{x : G | x ^ n = 1} := by
refine (Finset.card_biUnion ?_).symm.trans ?_
Β· simp +contextual [Set.PairwiseDisjoint, Set.Pairwise, disjoint_iff, Finset.ext_iff]
Β· congr; ext; simp [hn, orderOf_dvd_iff_pow_eq_one]
@[to_additive]
theorem orderOf_le_card_univ [Fintype G] : orderOf x β€ Fintype.card G :=
Finset.le_card_of_inj_on_range (x ^ Β·) (fun _ _ β¦ Finset.mem_univ _) pow_injOn_Iio_orderOf
@[to_additive]
theorem orderOf_le_card [Finite G] : orderOf x β€ Nat.card G := by
obtain β¨β© := nonempty_fintype G
simpa using orderOf_le_card_univ
end FiniteMonoid
section FiniteCancelMonoid
variable [LeftCancelMonoid G]
-- TODO: Of course everything also works for `RightCancelMonoid`.
section Finite
variable [Finite G] {x y : G} {n : β}
-- TODO: Use this to show that a finite left cancellative monoid is a group.
@[to_additive]
lemma isOfFinOrder_of_finite (x : G) : IsOfFinOrder x := by
by_contra h; exact infinite_not_isOfFinOrder h <| Set.toFinite _
/-- This is the same as `IsOfFinOrder.orderOf_pos` but with one fewer explicit assumption since this
is automatic in case of a finite cancellative monoid. -/
@[to_additive "This is the same as `IsOfFinAddOrder.addOrderOf_pos` but with one fewer explicit
assumption since this is automatic in case of a finite cancellative additive monoid."]
lemma orderOf_pos (x : G) : 0 < orderOf x := (isOfFinOrder_of_finite x).orderOf_pos
/-- This is the same as `orderOf_pow'` and `orderOf_pow''` but with one assumption less which is
automatic in the case of a finite cancellative monoid. -/
@[to_additive "This is the same as `addOrderOf_nsmul'` and
`addOrderOf_nsmul` but with one assumption less which is automatic in the case of a
finite cancellative additive monoid."]
theorem orderOf_pow (x : G) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n :=
(isOfFinOrder_of_finite _).orderOf_pow ..
@[to_additive]
theorem mem_powers_iff_mem_range_orderOf [DecidableEq G] :
y β powers x β y β (Finset.range (orderOf x)).image (x ^ Β·) :=
Finset.mem_range_iff_mem_finset_range_of_mod_eq' (orderOf_pos x) <| pow_mod_orderOf _
/-- The equivalence between `Submonoid.powers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
@[to_additive
"The equivalence between `Submonoid.multiples` of two elements `a, b` of the same additive order,
mapping `i β’ a` to `i β’ b`."]
noncomputable def powersEquivPowers (h : orderOf x = orderOf y) : powers x β powers y :=
(finEquivPowers <| isOfFinOrder_of_finite _).symm.trans <|
(finCongr h).trans <| finEquivPowers <| isOfFinOrder_of_finite _
@[to_additive (attr := simp)]
theorem powersEquivPowers_apply (h : orderOf x = orderOf y) (n : β) :
powersEquivPowers h β¨x ^ n, n, rflβ© = β¨y ^ n, n, rflβ© := by
rw [powersEquivPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivPowers_symm_apply, β
Equiv.eq_symm_apply, finEquivPowers_symm_apply]
simp [h]
end Finite
variable [Fintype G] {x : G}
@[to_additive]
lemma orderOf_eq_card_powers : orderOf x = Fintype.card (powers x : Submonoid G) :=
(Fintype.card_fin (orderOf x)).symm.trans <|
Fintype.card_eq.2 β¨finEquivPowers <| isOfFinOrder_of_finite _β©
end FiniteCancelMonoid
section FiniteGroup
variable [Group G] {x y : G}
@[to_additive]
theorem zpow_eq_one_iff_modEq {n : β€} : x ^ n = 1 β n β‘ 0 [ZMOD orderOf x] := by
rw [Int.modEq_zero_iff_dvd, orderOf_dvd_iff_zpow_eq_one]
@[to_additive]
theorem zpow_eq_zpow_iff_modEq {m n : β€} : x ^ m = x ^ n β m β‘ n [ZMOD orderOf x] := by
rw [β mul_inv_eq_one, β zpow_sub, zpow_eq_one_iff_modEq, Int.modEq_iff_dvd, Int.modEq_iff_dvd,
zero_sub, neg_sub]
@[to_additive (attr := simp)]
theorem injective_zpow_iff_not_isOfFinOrder : (Injective fun n : β€ => x ^ n) β Β¬IsOfFinOrder x := by
refine β¨?_, fun h n m hnm => ?_β©
Β· simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro h β¨n, hn, hxβ©
exact Nat.cast_ne_zero.2 hn.ne' (h <| by simpa using hx)
rwa [zpow_eq_zpow_iff_modEq, orderOf_eq_zero_iff.2 h, Nat.cast_zero, Int.modEq_zero_iff] at hnm
section Finite
variable [Finite G]
@[to_additive]
theorem exists_zpow_eq_one (x : G) : β (i : β€) (_ : i β 0), x ^ (i : β€) = 1 := by
obtain β¨w, hw1, hw2β© := isOfFinOrder_of_finite x
refine β¨w, Int.natCast_ne_zero.mpr (_root_.ne_of_gt hw1), ?_β©
rw [zpow_natCast]
exact (isPeriodicPt_mul_iff_pow_eq_one _).mp hw2
@[to_additive]
lemma mem_powers_iff_mem_zpowers : y β powers x β y β zpowers x :=
(isOfFinOrder_of_finite _).mem_powers_iff_mem_zpowers
@[to_additive]
lemma powers_eq_zpowers (x : G) : (powers x : Set G) = zpowers x :=
(isOfFinOrder_of_finite _).powers_eq_zpowers
@[to_additive]
lemma mem_zpowers_iff_mem_range_orderOf [DecidableEq G] :
y β zpowers x β y β (Finset.range (orderOf x)).image (x ^ Β·) :=
(isOfFinOrder_of_finite _).mem_zpowers_iff_mem_range_orderOf
/-- The equivalence between `Subgroup.zpowers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
@[to_additive
"The equivalence between `Subgroup.zmultiples` of two elements `a, b` of the same additive order,
mapping `i β’ a` to `i β’ b`."]
noncomputable def zpowersEquivZPowers (h : orderOf x = orderOf y) :
Subgroup.zpowers x β Subgroup.zpowers y :=
(finEquivZPowers <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <|
finEquivZPowers <| isOfFinOrder_of_finite _
@[to_additive (attr := simp) zmultiples_equiv_zmultiples_apply]
theorem zpowersEquivZPowers_apply (h : orderOf x = orderOf y) (n : β) :
zpowersEquivZPowers h β¨x ^ n, n, zpow_natCast x nβ© = β¨y ^ n, n, zpow_natCast y nβ© := by
rw [zpowersEquivZPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivZPowers_symm_apply, β
Equiv.eq_symm_apply, finEquivZPowers_symm_apply]
simp [h]
end Finite
variable [Fintype G] {x : G} {n : β}
/-- See also `Nat.card_zpowers`. -/
@[to_additive "See also `Nat.card_zmultiples`."]
theorem Fintype.card_zpowers : Fintype.card (zpowers x) = orderOf x :=
| (Fintype.card_eq.2 β¨finEquivZPowers <| isOfFinOrder_of_finite _β©).symm.trans <|
Fintype.card_fin (orderOf x)
| Mathlib/GroupTheory/OrderOfElement.lean | 854 | 856 |
/-
Copyright (c) 2018 Ellen Arlt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin
-/
import Mathlib.Data.Matrix.Basic
import Mathlib.Data.Matrix.Composition
import Mathlib.Data.Matrix.ConjTranspose
/-!
# Block Matrices
## Main definitions
* `Matrix.fromBlocks`: build a block matrix out of 4 blocks
* `Matrix.toBlocksββ`, `Matrix.toBlocksββ`, `Matrix.toBlocksββ`, `Matrix.toBlocksββ`:
extract each of the four blocks from `Matrix.fromBlocks`.
* `Matrix.blockDiagonal`: block diagonal of equally sized blocks. On square blocks, this is a
ring homomorphisms, `Matrix.blockDiagonalRingHom`.
* `Matrix.blockDiag`: extract the blocks from the diagonal of a block diagonal matrix.
* `Matrix.blockDiagonal'`: block diagonal of unequally sized blocks. On square blocks, this is a
ring homomorphisms, `Matrix.blockDiagonal'RingHom`.
* `Matrix.blockDiag'`: extract the blocks from the diagonal of a block diagonal matrix.
-/
variable {l m n o p q : Type*} {m' n' p' : o β Type*}
variable {R : Type*} {S : Type*} {Ξ± : Type*} {Ξ² : Type*}
open Matrix
namespace Matrix
theorem dotProduct_block [Fintype m] [Fintype n] [Mul Ξ±] [AddCommMonoid Ξ±] (v w : m β n β Ξ±) :
v β¬α΅₯ w = v β Sum.inl β¬α΅₯ w β Sum.inl + v β Sum.inr β¬α΅₯ w β Sum.inr :=
Fintype.sum_sum_type _
section BlockMatrices
/-- We can form a single large matrix by flattening smaller 'block' matrices of compatible
dimensions. -/
@[pp_nodot]
def fromBlocks (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) :
Matrix (n β o) (l β m) Ξ± :=
of <| Sum.elim (fun i => Sum.elim (A i) (B i)) (fun j => Sum.elim (C j) (D j))
@[simp]
theorem fromBlocks_applyββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) (i : n) (j : l) : fromBlocks A B C D (Sum.inl i) (Sum.inl j) = A i j :=
rfl
@[simp]
theorem fromBlocks_applyββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) (i : n) (j : m) : fromBlocks A B C D (Sum.inl i) (Sum.inr j) = B i j :=
rfl
@[simp]
theorem fromBlocks_applyββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) (i : o) (j : l) : fromBlocks A B C D (Sum.inr i) (Sum.inl j) = C i j :=
rfl
@[simp]
theorem fromBlocks_applyββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) (i : o) (j : m) : fromBlocks A B C D (Sum.inr i) (Sum.inr j) = D i j :=
rfl
/-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding
"top left" submatrix. -/
def toBlocksββ (M : Matrix (n β o) (l β m) Ξ±) : Matrix n l Ξ± :=
of fun i j => M (Sum.inl i) (Sum.inl j)
/-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding
"top right" submatrix. -/
def toBlocksββ (M : Matrix (n β o) (l β m) Ξ±) : Matrix n m Ξ± :=
of fun i j => M (Sum.inl i) (Sum.inr j)
/-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding
"bottom left" submatrix. -/
def toBlocksββ (M : Matrix (n β o) (l β m) Ξ±) : Matrix o l Ξ± :=
of fun i j => M (Sum.inr i) (Sum.inl j)
/-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding
"bottom right" submatrix. -/
def toBlocksββ (M : Matrix (n β o) (l β m) Ξ±) : Matrix o m Ξ± :=
of fun i j => M (Sum.inr i) (Sum.inr j)
theorem fromBlocks_toBlocks (M : Matrix (n β o) (l β m) Ξ±) :
fromBlocks M.toBlocksββ M.toBlocksββ M.toBlocksββ M.toBlocksββ = M := by
ext i j
rcases i with β¨β© <;> rcases j with β¨β© <;> rfl
@[simp]
theorem toBlocks_fromBlocksββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocksββ = A :=
rfl
@[simp]
theorem toBlocks_fromBlocksββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocksββ = B :=
rfl
@[simp]
theorem toBlocks_fromBlocksββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocksββ = C :=
rfl
@[simp]
theorem toBlocks_fromBlocksββ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocksββ = D :=
rfl
/-- Two block matrices are equal if their blocks are equal. -/
theorem ext_iff_blocks {A B : Matrix (n β o) (l β m) Ξ±} :
A = B β
A.toBlocksββ = B.toBlocksββ β§
A.toBlocksββ = B.toBlocksββ β§ A.toBlocksββ = B.toBlocksββ β§ A.toBlocksββ = B.toBlocksββ :=
β¨fun h => h βΈ β¨rfl, rfl, rfl, rflβ©, fun β¨hββ, hββ, hββ, hβββ© => by
rw [β fromBlocks_toBlocks A, β fromBlocks_toBlocks B, hββ, hββ, hββ, hββ]β©
@[simp]
theorem fromBlocks_inj {A : Matrix n l Ξ±} {B : Matrix n m Ξ±} {C : Matrix o l Ξ±} {D : Matrix o m Ξ±}
{A' : Matrix n l Ξ±} {B' : Matrix n m Ξ±} {C' : Matrix o l Ξ±} {D' : Matrix o m Ξ±} :
fromBlocks A B C D = fromBlocks A' B' C' D' β A = A' β§ B = B' β§ C = C' β§ D = D' :=
ext_iff_blocks
theorem fromBlocks_map (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±)
(f : Ξ± β Ξ²) : (fromBlocks A B C D).map f =
fromBlocks (A.map f) (B.map f) (C.map f) (D.map f) := by
ext i j; rcases i with β¨β© <;> rcases j with β¨β© <;> simp [fromBlocks]
theorem fromBlocks_transpose (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) : (fromBlocks A B C D)α΅ = fromBlocks Aα΅ Cα΅ Bα΅ Dα΅ := by
ext i j
rcases i with β¨β© <;> rcases j with β¨β© <;> simp [fromBlocks]
theorem fromBlocks_conjTranspose [Star Ξ±] (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) : (fromBlocks A B C D)α΄΄ = fromBlocks Aα΄΄ Cα΄΄ Bα΄΄ Dα΄΄ := by
simp only [conjTranspose, fromBlocks_transpose, fromBlocks_map]
@[simp]
theorem fromBlocks_submatrix_sum_swap_left (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) (f : p β l β m) :
(fromBlocks A B C D).submatrix Sum.swap f = (fromBlocks C D A B).submatrix id f := by
ext i j
cases i <;> dsimp <;> cases f j <;> rfl
@[simp]
theorem fromBlocks_submatrix_sum_swap_right (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) (f : p β n β o) :
(fromBlocks A B C D).submatrix f Sum.swap = (fromBlocks B A D C).submatrix f id := by
ext i j
cases j <;> dsimp <;> cases f i <;> rfl
theorem fromBlocks_submatrix_sum_swap_sum_swap {l m n o Ξ± : Type*} (A : Matrix n l Ξ±)
(B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) :
(fromBlocks A B C D).submatrix Sum.swap Sum.swap = fromBlocks D C B A := by simp
/-- A 2x2 block matrix is block diagonal if the blocks outside of the diagonal vanish -/
def IsTwoBlockDiagonal [Zero Ξ±] (A : Matrix (n β o) (l β m) Ξ±) : Prop :=
toBlocksββ A = 0 β§ toBlocksββ A = 0
/-- Let `p` pick out certain rows and `q` pick out certain columns of a matrix `M`. Then
`toBlock M p q` is the corresponding block matrix. -/
def toBlock (M : Matrix m n Ξ±) (p : m β Prop) (q : n β Prop) : Matrix { a // p a } { a // q a } Ξ± :=
M.submatrix (β) (β)
@[simp]
theorem toBlock_apply (M : Matrix m n Ξ±) (p : m β Prop) (q : n β Prop) (i : { a // p a })
(j : { a // q a }) : toBlock M p q i j = M βi βj :=
rfl
/-- Let `p` pick out certain rows and columns of a square matrix `M`. Then
`toSquareBlockProp M p` is the corresponding block matrix. -/
def toSquareBlockProp (M : Matrix m m Ξ±) (p : m β Prop) : Matrix { a // p a } { a // p a } Ξ± :=
toBlock M _ _
theorem toSquareBlockProp_def (M : Matrix m m Ξ±) (p : m β Prop) :
toSquareBlockProp M p = of (fun i j : { a // p a } => M βi βj) :=
rfl
/-- Let `b` map rows and columns of a square matrix `M` to blocks. Then
`toSquareBlock M b k` is the block `k` matrix. -/
def toSquareBlock (M : Matrix m m Ξ±) (b : m β Ξ²) (k : Ξ²) :
Matrix { a // b a = k } { a // b a = k } Ξ± :=
toSquareBlockProp M _
theorem toSquareBlock_def (M : Matrix m m Ξ±) (b : m β Ξ²) (k : Ξ²) :
toSquareBlock M b k = of (fun i j : { a // b a = k } => M βi βj) :=
rfl
theorem fromBlocks_smul [SMul R Ξ±] (x : R) (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) : x β’ fromBlocks A B C D = fromBlocks (x β’ A) (x β’ B) (x β’ C) (x β’ D) := by
ext i j; rcases i with β¨β© <;> rcases j with β¨β© <;> simp [fromBlocks]
theorem fromBlocks_neg [Neg R] (A : Matrix n l R) (B : Matrix n m R) (C : Matrix o l R)
(D : Matrix o m R) : -fromBlocks A B C D = fromBlocks (-A) (-B) (-C) (-D) := by
ext i j
cases i <;> cases j <;> simp [fromBlocks]
@[simp]
theorem fromBlocks_zero [Zero Ξ±] : fromBlocks (0 : Matrix n l Ξ±) 0 0 (0 : Matrix o m Ξ±) = 0 := by
ext i j
rcases i with β¨β© <;> rcases j with β¨β© <;> rfl
theorem fromBlocks_add [Add Ξ±] (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±)
(D : Matrix o m Ξ±) (A' : Matrix n l Ξ±) (B' : Matrix n m Ξ±) (C' : Matrix o l Ξ±)
(D' : Matrix o m Ξ±) : fromBlocks A B C D + fromBlocks A' B' C' D' =
fromBlocks (A + A') (B + B') (C + C') (D + D') := by
ext i j; rcases i with β¨β© <;> rcases j with β¨β© <;> rfl
theorem fromBlocks_multiply [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring Ξ±] (A : Matrix n l Ξ±)
(B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (A' : Matrix l p Ξ±) (B' : Matrix l q Ξ±)
(C' : Matrix m p Ξ±) (D' : Matrix m q Ξ±) :
fromBlocks A B C D * fromBlocks A' B' C' D' =
fromBlocks (A * A' + B * C') (A * B' + B * D') (C * A' + D * C') (C * B' + D * D') := by
ext i j
rcases i with β¨β© <;> rcases j with β¨β© <;> simp only [fromBlocks, mul_apply, of_apply,
Sum.elim_inr, Fintype.sum_sum_type, Sum.elim_inl, add_apply]
theorem fromBlocks_mulVec [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring Ξ±] (A : Matrix n l Ξ±)
(B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (x : l β m β Ξ±) :
(fromBlocks A B C D) *α΅₯ x =
Sum.elim (A *α΅₯ (x β Sum.inl) + B *α΅₯ (x β Sum.inr))
(C *α΅₯ (x β Sum.inl) + D *α΅₯ (x β Sum.inr)) := by
ext i
cases i <;> simp [mulVec, dotProduct]
theorem vecMul_fromBlocks [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring Ξ±] (A : Matrix n l Ξ±)
(B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (x : n β o β Ξ±) :
x α΅₯* fromBlocks A B C D =
Sum.elim ((x β Sum.inl) α΅₯* A + (x β Sum.inr) α΅₯* C)
((x β Sum.inl) α΅₯* B + (x β Sum.inr) α΅₯* D) := by
ext i
cases i <;> simp [vecMul, dotProduct]
variable [DecidableEq l] [DecidableEq m]
section Zero
variable [Zero Ξ±]
theorem toBlock_diagonal_self (d : m β Ξ±) (p : m β Prop) :
Matrix.toBlock (diagonal d) p p = diagonal fun i : Subtype p => d βi := by
ext i j
by_cases h : i = j
Β· simp [h]
Β· simp [One.one, h, Subtype.val_injective.ne h]
theorem toBlock_diagonal_disjoint (d : m β Ξ±) {p q : m β Prop} (hpq : Disjoint p q) :
Matrix.toBlock (diagonal d) p q = 0 := by
ext β¨i, hiβ© β¨j, hjβ©
have : i β j := fun heq => hpq.le_bot i β¨hi, heq.symm βΈ hjβ©
simp [diagonal_apply_ne d this]
@[simp]
theorem fromBlocks_diagonal (dβ : l β Ξ±) (dβ : m β Ξ±) :
fromBlocks (diagonal dβ) 0 0 (diagonal dβ) = diagonal (Sum.elim dβ dβ) := by
ext i j
rcases i with β¨β© <;> rcases j with β¨β© <;> simp [diagonal]
@[simp]
lemma toBlocksββ_diagonal (v : l β m β Ξ±) :
toBlocksββ (diagonal v) = diagonal (fun i => v (Sum.inl i)) := by
unfold toBlocksββ
funext i j
simp only [ne_eq, Sum.inl.injEq, of_apply, diagonal_apply]
@[simp]
lemma toBlocksββ_diagonal (v : l β m β Ξ±) :
toBlocksββ (diagonal v) = diagonal (fun i => v (Sum.inr i)) := by
unfold toBlocksββ
funext i j
simp only [ne_eq, Sum.inr.injEq, of_apply, diagonal_apply]
@[simp]
lemma toBlocksββ_diagonal (v : l β m β Ξ±) : toBlocksββ (diagonal v) = 0 := rfl
@[simp]
lemma toBlocksββ_diagonal (v : l β m β Ξ±) : toBlocksββ (diagonal v) = 0 := rfl
end Zero
section HasZeroHasOne
variable [Zero Ξ±] [One Ξ±]
@[simp]
theorem fromBlocks_one : fromBlocks (1 : Matrix l l Ξ±) 0 0 (1 : Matrix m m Ξ±) = 1 := by
ext i j
rcases i with β¨β© <;> rcases j with β¨β© <;> simp [one_apply]
@[simp]
theorem toBlock_one_self (p : m β Prop) : Matrix.toBlock (1 : Matrix m m Ξ±) p p = 1 :=
toBlock_diagonal_self _ p
theorem toBlock_one_disjoint {p q : m β Prop} (hpq : Disjoint p q) :
Matrix.toBlock (1 : Matrix m m Ξ±) p q = 0 :=
toBlock_diagonal_disjoint _ hpq
end HasZeroHasOne
end BlockMatrices
section BlockDiagonal
variable [DecidableEq o]
section Zero
variable [Zero Ξ±] [Zero Ξ²]
/-- `Matrix.blockDiagonal M` turns a homogeneously-indexed collection of matrices
`M : o β Matrix m n Ξ±'` into an `m Γ o`-by-`n Γ o` block matrix which has the entries of `M` along
the diagonal and zero elsewhere.
See also `Matrix.blockDiagonal'` if the matrices may not have the same size everywhere.
-/
def blockDiagonal (M : o β Matrix m n Ξ±) : Matrix (m Γ o) (n Γ o) Ξ± :=
of <| (fun β¨i, kβ© β¨j, k'β© => if k = k' then M k i j else 0 : m Γ o β n Γ o β Ξ±)
-- TODO: set as an equation lemma for `blockDiagonal`, see https://github.com/leanprover-community/mathlib4/pull/3024
theorem blockDiagonal_apply' (M : o β Matrix m n Ξ±) (i k j k') :
blockDiagonal M β¨i, kβ© β¨j, k'β© = if k = k' then M k i j else 0 :=
rfl
theorem blockDiagonal_apply (M : o β Matrix m n Ξ±) (ik jk) :
blockDiagonal M ik jk = if ik.2 = jk.2 then M ik.2 ik.1 jk.1 else 0 := by
cases ik
cases jk
rfl
@[simp]
theorem blockDiagonal_apply_eq (M : o β Matrix m n Ξ±) (i j k) :
blockDiagonal M (i, k) (j, k) = M k i j :=
if_pos rfl
theorem blockDiagonal_apply_ne (M : o β Matrix m n Ξ±) (i j) {k k'} (h : k β k') :
blockDiagonal M (i, k) (j, k') = 0 :=
if_neg h
theorem blockDiagonal_map (M : o β Matrix m n Ξ±) (f : Ξ± β Ξ²) (hf : f 0 = 0) :
(blockDiagonal M).map f = blockDiagonal fun k => (M k).map f := by
ext
simp only [map_apply, blockDiagonal_apply, eq_comm]
rw [apply_ite f, hf]
@[simp]
theorem blockDiagonal_transpose (M : o β Matrix m n Ξ±) :
(blockDiagonal M)α΅ = blockDiagonal fun k => (M k)α΅ := by
ext
simp only [transpose_apply, blockDiagonal_apply, eq_comm]
split_ifs with h
Β· rw [h]
Β· rfl
@[simp]
theorem blockDiagonal_conjTranspose {Ξ± : Type*} [AddMonoid Ξ±] [StarAddMonoid Ξ±]
(M : o β Matrix m n Ξ±) : (blockDiagonal M)α΄΄ = blockDiagonal fun k => (M k)α΄΄ := by
simp only [conjTranspose, blockDiagonal_transpose]
rw [blockDiagonal_map _ star (star_zero Ξ±)]
@[simp]
theorem blockDiagonal_zero : blockDiagonal (0 : o β Matrix m n Ξ±) = 0 := by
ext
simp [blockDiagonal_apply]
@[simp]
theorem blockDiagonal_diagonal [DecidableEq m] (d : o β m β Ξ±) :
(blockDiagonal fun k => diagonal (d k)) = diagonal fun ik => d ik.2 ik.1 := by
ext β¨i, kβ© β¨j, k'β©
simp only [blockDiagonal_apply, diagonal_apply, Prod.mk_inj, β ite_and]
congr 1
rw [and_comm]
@[simp]
theorem blockDiagonal_one [DecidableEq m] [One Ξ±] : blockDiagonal (1 : o β Matrix m m Ξ±) = 1 :=
show (blockDiagonal fun _ : o => diagonal fun _ : m => (1 : Ξ±)) = diagonal fun _ => 1 by
rw [blockDiagonal_diagonal]
end Zero
@[simp]
theorem blockDiagonal_add [AddZeroClass Ξ±] (M N : o β Matrix m n Ξ±) :
blockDiagonal (M + N) = blockDiagonal M + blockDiagonal N := by
ext
simp only [blockDiagonal_apply, Pi.add_apply, add_apply]
split_ifs <;> simp
section
variable (o m n Ξ±)
/-- `Matrix.blockDiagonal` as an `AddMonoidHom`. -/
@[simps]
def blockDiagonalAddMonoidHom [AddZeroClass Ξ±] :
(o β Matrix m n Ξ±) β+ Matrix (m Γ o) (n Γ o) Ξ± where
toFun := blockDiagonal
map_zero' := blockDiagonal_zero
map_add' := blockDiagonal_add
end
@[simp]
theorem blockDiagonal_neg [AddGroup Ξ±] (M : o β Matrix m n Ξ±) :
blockDiagonal (-M) = -blockDiagonal M :=
map_neg (blockDiagonalAddMonoidHom m n o Ξ±) M
@[simp]
theorem blockDiagonal_sub [AddGroup Ξ±] (M N : o β Matrix m n Ξ±) :
blockDiagonal (M - N) = blockDiagonal M - blockDiagonal N :=
map_sub (blockDiagonalAddMonoidHom m n o Ξ±) M N
@[simp]
theorem blockDiagonal_mul [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring Ξ±]
(M : o β Matrix m n Ξ±) (N : o β Matrix n p Ξ±) :
(blockDiagonal fun k => M k * N k) = blockDiagonal M * blockDiagonal N := by
ext β¨i, kβ© β¨j, k'β©
simp only [blockDiagonal_apply, mul_apply, β Finset.univ_product_univ, Finset.sum_product]
split_ifs with h <;> simp [h]
section
| variable (Ξ± m o)
/-- `Matrix.blockDiagonal` as a `RingHom`. -/
@[simps]
def blockDiagonalRingHom [DecidableEq m] [Fintype o] [Fintype m] [NonAssocSemiring Ξ±] :
(o β Matrix m m Ξ±) β+* Matrix (m Γ o) (m Γ o) Ξ± :=
| Mathlib/Data/Matrix/Block.lean | 422 | 427 |
/-
Copyright (c) 2020 RΓ©my Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: RΓ©my Degenne, SΓ©bastien GouΓ«zel
-/
import Mathlib.Analysis.NormedSpace.IndicatorFunction
import Mathlib.Data.Fintype.Order
import Mathlib.MeasureTheory.Function.AEEqFun
import Mathlib.MeasureTheory.Function.LpSeminorm.Defs
import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
import Mathlib.MeasureTheory.Integral.Lebesgue.Countable
import Mathlib.MeasureTheory.Integral.Lebesgue.Sub
/-!
# Basic theorems about βp space
-/
noncomputable section
open TopologicalSpace MeasureTheory Filter
open scoped NNReal ENNReal Topology ComplexConjugate
variable {Ξ± Ξ΅ Ξ΅' E F G : Type*} {m m0 : MeasurableSpace Ξ±} {p : ββ₯0β} {q : β} {ΞΌ Ξ½ : Measure Ξ±}
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm Ξ΅] [ENorm Ξ΅']
namespace MeasureTheory
section Lp
section Top
theorem MemLp.eLpNorm_lt_top [TopologicalSpace Ξ΅] {f : Ξ± β Ξ΅} (hfp : MemLp f p ΞΌ) :
eLpNorm f p ΞΌ < β :=
hfp.2
@[deprecated (since := "2025-02-21")]
alias Memβp.eLpNorm_lt_top := MemLp.eLpNorm_lt_top
theorem MemLp.eLpNorm_ne_top [TopologicalSpace Ξ΅] {f : Ξ± β Ξ΅} (hfp : MemLp f p ΞΌ) :
eLpNorm f p ΞΌ β β :=
ne_of_lt hfp.2
@[deprecated (since := "2025-02-21")]
alias Memβp.eLpNorm_ne_top := MemLp.eLpNorm_ne_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : Ξ± β Ξ΅} (hq0_lt : 0 < q)
(hfq : eLpNorm' f q ΞΌ < β) : β«β» a, βf aββ ^ q βΞΌ < β := by
rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt]
exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq)
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' :=
lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : Ξ± β Ξ΅} (hp_ne_zero : p β 0)
(hp_ne_top : p β β) (hfp : eLpNorm f p ΞΌ < β) : β«β» a, βf aββ ^ p.toReal βΞΌ < β := by
apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top
Β· exact ENNReal.toReal_pos hp_ne_zero hp_ne_top
Β· simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp
@[deprecated (since := "2025-01-17")]
alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top :=
lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top
theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : Ξ± β Ξ΅} (hp_ne_zero : p β 0)
(hp_ne_top : p β β) : eLpNorm f p ΞΌ < β β β«β» a, (βf aββ) ^ p.toReal βΞΌ < β :=
β¨lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_ne_zero hp_ne_top, by
intro h
have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top
have : 0 < 1 / p.toReal := div_pos zero_lt_one hp'
simpa [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using
ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)β©
@[deprecated (since := "2025-02-04")] alias
eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top
end Top
section Zero
@[simp]
theorem eLpNorm'_exponent_zero {f : Ξ± β Ξ΅} : eLpNorm' f 0 ΞΌ = 1 := by
rw [eLpNorm', div_zero, ENNReal.rpow_zero]
@[simp]
theorem eLpNorm_exponent_zero {f : Ξ± β Ξ΅} : eLpNorm f 0 ΞΌ = 0 := by simp [eLpNorm]
@[simp]
theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace Ξ΅] {f : Ξ± β Ξ΅} :
MemLp f 0 ΞΌ β AEStronglyMeasurable f ΞΌ := by simp [MemLp, eLpNorm_exponent_zero]
@[deprecated (since := "2025-02-21")]
alias memβp_zero_iff_aestronglyMeasurable := memLp_zero_iff_aestronglyMeasurable
section ENormedAddMonoid
variable {Ξ΅ : Type*} [TopologicalSpace Ξ΅] [ENormedAddMonoid Ξ΅]
@[simp]
theorem eLpNorm'_zero (hp0_lt : 0 < q) : eLpNorm' (0 : Ξ± β Ξ΅) q ΞΌ = 0 := by
simp [eLpNorm'_eq_lintegral_enorm, hp0_lt]
@[simp]
theorem eLpNorm'_zero' (hq0_ne : q β 0) (hΞΌ : ΞΌ β 0) : eLpNorm' (0 : Ξ± β Ξ΅) q ΞΌ = 0 := by
rcases le_or_lt 0 q with hq0 | hq_neg
Β· exact eLpNorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm)
Β· simp [eLpNorm'_eq_lintegral_enorm, ENNReal.rpow_eq_zero_iff, hΞΌ, hq_neg]
@[simp]
theorem eLpNormEssSup_zero : eLpNormEssSup (0 : Ξ± β Ξ΅) ΞΌ = 0 := by
simp [eLpNormEssSup, β bot_eq_zero', essSup_const_bot]
@[simp]
theorem eLpNorm_zero : eLpNorm (0 : Ξ± β Ξ΅) p ΞΌ = 0 := by
by_cases h0 : p = 0
Β· simp [h0]
by_cases h_top : p = β
Β· simp only [h_top, eLpNorm_exponent_top, eLpNormEssSup_zero]
rw [β Ne] at h0
simp [eLpNorm_eq_eLpNorm' h0 h_top, ENNReal.toReal_pos h0 h_top]
@[simp]
theorem eLpNorm_zero' : eLpNorm (fun _ : Ξ± => (0 : Ξ΅)) p ΞΌ = 0 := eLpNorm_zero
@[simp] lemma MemLp.zero : MemLp (0 : Ξ± β Ξ΅) p ΞΌ :=
β¨aestronglyMeasurable_zero, by rw [eLpNorm_zero]; exact ENNReal.coe_lt_topβ©
@[simp] lemma MemLp.zero' : MemLp (fun _ : Ξ± => (0 : Ξ΅)) p ΞΌ := MemLp.zero
@[deprecated (since := "2025-02-21")]
alias Memβp.zero' := MemLp.zero'
@[deprecated (since := "2025-01-21")] alias zero_memβp := MemLp.zero
@[deprecated (since := "2025-01-21")] alias zero_mem_βp := MemLp.zero'
variable [MeasurableSpace Ξ±]
theorem eLpNorm'_measure_zero_of_pos {f : Ξ± β Ξ΅} (hq_pos : 0 < q) :
eLpNorm' f q (0 : Measure Ξ±) = 0 := by simp [eLpNorm', hq_pos]
theorem eLpNorm'_measure_zero_of_exponent_zero {f : Ξ± β Ξ΅} : eLpNorm' f 0 (0 : Measure Ξ±) = 1 := by
simp [eLpNorm']
theorem eLpNorm'_measure_zero_of_neg {f : Ξ± β Ξ΅} (hq_neg : q < 0) :
eLpNorm' f q (0 : Measure Ξ±) = β := by simp [eLpNorm', hq_neg]
end ENormedAddMonoid
@[simp]
theorem eLpNormEssSup_measure_zero {f : Ξ± β Ξ΅} : eLpNormEssSup f (0 : Measure Ξ±) = 0 := by
simp [eLpNormEssSup]
@[simp]
theorem eLpNorm_measure_zero {f : Ξ± β Ξ΅} : eLpNorm f p (0 : Measure Ξ±) = 0 := by
by_cases h0 : p = 0
Β· simp [h0]
by_cases h_top : p = β
Β· simp [h_top]
rw [β Ne] at h0
simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', ENNReal.toReal_pos h0 h_top]
section ContinuousENorm
variable {Ξ΅ : Type*} [TopologicalSpace Ξ΅] [ContinuousENorm Ξ΅]
@[simp] lemma memLp_measure_zero {f : Ξ± β Ξ΅} : MemLp f p (0 : Measure Ξ±) := by
simp [MemLp]
@[deprecated (since := "2025-02-21")]
alias memβp_measure_zero := memLp_measure_zero
end ContinuousENorm
end Zero
section Neg
@[simp]
theorem eLpNorm'_neg (f : Ξ± β F) (q : β) (ΞΌ : Measure Ξ±) : eLpNorm' (-f) q ΞΌ = eLpNorm' f q ΞΌ := by
simp [eLpNorm'_eq_lintegral_enorm]
@[simp]
theorem eLpNorm_neg (f : Ξ± β F) (p : ββ₯0β) (ΞΌ : Measure Ξ±) : eLpNorm (-f) p ΞΌ = eLpNorm f p ΞΌ := by
by_cases h0 : p = 0
Β· simp [h0]
by_cases h_top : p = β
Β· simp [h_top, eLpNormEssSup_eq_essSup_enorm]
simp [eLpNorm_eq_eLpNorm' h0 h_top]
lemma eLpNorm_sub_comm (f g : Ξ± β E) (p : ββ₯0β) (ΞΌ : Measure Ξ±) :
eLpNorm (f - g) p ΞΌ = eLpNorm (g - f) p ΞΌ := by simp [β eLpNorm_neg (f := f - g)]
theorem MemLp.neg {f : Ξ± β E} (hf : MemLp f p ΞΌ) : MemLp (-f) p ΞΌ :=
β¨AEStronglyMeasurable.neg hf.1, by simp [hf.right]β©
@[deprecated (since := "2025-02-21")]
alias Memβp.neg := MemLp.neg
|
theorem memLp_neg_iff {f : Ξ± β E} : MemLp (-f) p ΞΌ β MemLp f p ΞΌ :=
β¨fun h => neg_neg f βΈ h.neg, MemLp.negβ©
| Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean | 199 | 201 |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ΞΉ Ξ± Ξ² : Type*}
section LinearOrderedSemifield
variable [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d e : Ξ±} {m n : β€}
/-!
### Relating two divisions.
-/
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_le_div_right (hc : 0 < c) : a / c β€ b / c β a β€ b := div_le_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c β a < b := div_lt_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")]
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c β c < b :=
div_lt_div_iff_of_pos_left ha hb hc
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b β€ a / c β c β€ b :=
div_le_div_iff_of_pos_left ha hb hc
@[deprecated div_lt_div_iffβ (since := "2024-11-12")]
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d β a * d < c * b :=
div_lt_div_iffβ b0 d0
@[deprecated div_le_div_iffβ (since := "2024-11-12")]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b β€ c / d β a * d β€ c * b :=
div_le_div_iffβ b0 d0
@[deprecated div_le_divβ (since := "2024-11-12")]
theorem div_le_div (hc : 0 β€ c) (hac : a β€ c) (hd : 0 < d) (hbd : d β€ b) : a / b β€ c / d :=
div_le_divβ hc hac hd hbd
@[deprecated div_lt_divβ (since := "2024-11-12")]
theorem div_lt_div (hac : a < c) (hbd : d β€ b) (c0 : 0 β€ c) (d0 : 0 < d) : a / b < c / d :=
div_lt_divβ hac hbd c0 d0
@[deprecated div_lt_divβ' (since := "2024-11-12")]
theorem div_lt_div' (hac : a β€ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
div_lt_divβ' hac hbd c0 d0
/-!
### Relating one division and involving `1`
-/
@[bound]
theorem div_le_self (ha : 0 β€ a) (hb : 1 β€ b) : a / b β€ a := by
simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb
@[bound]
theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by
simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb
@[bound]
theorem le_div_self (ha : 0 β€ a) (hbβ : 0 < b) (hbβ : b β€ 1) : a β€ a / b := by
simpa only [div_one] using div_le_div_of_nonneg_left ha hbβ hbβ
theorem one_le_div (hb : 0 < b) : 1 β€ a / b β b β€ a := by rw [le_div_iffβ hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b β€ 1 β a β€ b := by rw [div_le_iffβ hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b β b < a := by rw [lt_div_iffβ hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 β a < b := by rw [div_lt_iffβ hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a β€ b β 1 / b β€ a := by
simpa using inv_le_commβ ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b β 1 / b < a := by
simpa using inv_lt_commβ ha hb
theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a β€ 1 / b β b β€ 1 / a := by
simpa using le_inv_commβ ha hb
theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b β b < 1 / a := by
simpa using lt_inv_commβ ha hb
@[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a β 1 < a / b := (one_lt_div b0).mpr
@[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b β a / b < 1 := (div_lt_one b0).mpr
/-!
### Relating two divisions, involving `1`
-/
theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a β€ b) : 1 / b β€ 1 / a := by
simpa using inv_antiβ ha h
theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by
rwa [lt_div_iffβ' ha, β div_eq_mul_one_div, div_lt_one (ha.trans h)]
theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a β€ 1 / b) : b β€ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h
theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h
/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and
`le_of_one_div_le_one_div` -/
theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a β€ 1 / b β b β€ a :=
div_le_div_iff_of_pos_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b β b < a :=
div_lt_div_iff_of_pos_left zero_lt_one ha hb
theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by
rwa [lt_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one]
theorem one_le_one_div (h1 : 0 < a) (h2 : a β€ 1) : 1 β€ 1 / a := by
rwa [le_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one]
/-!
### Results about halving.
The equalities also hold in semifields of characteristic `0`.
-/
theorem half_pos (h : 0 < a) : 0 < a / 2 :=
div_pos h zero_lt_two
theorem one_half_pos : (0 : Ξ±) < 1 / 2 :=
half_pos zero_lt_one
@[simp]
theorem half_le_self_iff : a / 2 β€ a β 0 β€ a := by
rw [div_le_iffβ (zero_lt_two' Ξ±), mul_two, le_add_iff_nonneg_left]
@[simp]
theorem half_lt_self_iff : a / 2 < a β 0 < a := by
rw [div_lt_iffβ (zero_lt_two' Ξ±), mul_two, lt_add_iff_pos_left]
alias β¨_, half_le_selfβ© := half_le_self_iff
alias β¨_, half_lt_selfβ© := half_lt_self_iff
alias div_two_lt_of_pos := half_lt_self
theorem one_half_lt_one : (1 / 2 : Ξ±) < 1 :=
half_lt_self zero_lt_one
theorem two_inv_lt_one : (2β»ΒΉ : Ξ±) < 1 :=
(one_div _).symm.trans_lt one_half_lt_one
theorem left_lt_add_div_two : a < (a + b) / 2 β a < b := by simp [lt_div_iffβ, mul_two]
theorem add_div_two_lt_right : (a + b) / 2 < b β a < b := by simp [div_lt_iffβ, mul_two]
theorem add_thirds (a : Ξ±) : a / 3 + a / 3 + a / 3 = a := by
rw [div_add_div_same, div_add_div_same, β two_mul, β add_one_mul 2 a, two_add_one_eq_three,
mul_div_cancel_leftβ a three_ne_zero]
/-!
### Miscellaneous lemmas
-/
@[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b β 0 < b := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos]
@[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b β 0 < a := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)]
theorem mul_le_mul_of_mul_div_le (h : a * (b / c) β€ d) (hc : 0 < c) : b * a β€ d * c := by
rw [β mul_div_assoc] at h
rwa [mul_comm b, β div_le_iffβ hc]
theorem div_mul_le_div_mul_of_div_le_div (h : a / b β€ c / d) (he : 0 β€ e) :
a / (b * e) β€ c / (d * e) := by
rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div]
exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he)
theorem exists_pos_mul_lt {a : Ξ±} (h : 0 < a) (b : Ξ±) : β c : Ξ±, 0 < c β§ b * c < a := by
have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one))
refine β¨a / max (b + 1) 1, this, ?_β©
rw [β lt_div_iffβ this, div_div_cancelβ h.ne']
exact lt_max_iff.2 (Or.inl <| lt_add_one _)
theorem exists_pos_lt_mul {a : Ξ±} (h : 0 < a) (b : Ξ±) : β c : Ξ±, 0 < c β§ b < c * a :=
let β¨c, hcβ, hcβ© := exists_pos_mul_lt h b;
β¨cβ»ΒΉ, inv_pos.2 hcβ, by rwa [β div_eq_inv_mul, lt_div_iffβ hcβ]β©
lemma monotone_div_right_of_nonneg (ha : 0 β€ a) : Monotone (Β· / a) :=
fun _b _c hbc β¦ div_le_div_of_nonneg_right hbc ha
lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (Β· / a) :=
fun _b _c hbc β¦ div_lt_div_of_pos_right hbc ha
theorem Monotone.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β Ξ±} (hf : Monotone f) {c : Ξ±}
(hc : 0 β€ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf
theorem StrictMono.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β Ξ±} (hf : StrictMono f) {c : Ξ±}
(hc : 0 < c) : StrictMono fun x => f x / c := by
simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc)
-- see Note [lower instance priority]
instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered Ξ± where
dense aβ aβ h :=
β¨(aβ + aβ) / 2,
calc
aβ = (aβ + aβ) / 2 := (add_self_div_two aβ).symm
_ < (aβ + aβ) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two
,
calc
(aβ + aβ) / 2 < (aβ + aβ) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two
_ = aβ := add_self_div_two aβ
β©
theorem min_div_div_right {c : Ξ±} (hc : 0 β€ c) (a b : Ξ±) : min (a / c) (b / c) = min a b / c :=
(monotone_div_right_of_nonneg hc).map_min.symm
theorem max_div_div_right {c : Ξ±} (hc : 0 β€ c) (a b : Ξ±) : max (a / c) (b / c) = max a b / c :=
(monotone_div_right_of_nonneg hc).map_max.symm
theorem one_div_strictAntiOn : StrictAntiOn (fun x : Ξ± => 1 / x) (Set.Ioi 0) :=
fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy
theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 β€ a) {m n : β} (mn : m β€ n) :
1 / a ^ n β€ 1 / a ^ m := by
refine (one_div_le_one_div ?_ ?_).mpr (pow_right_monoβ a1 mn) <;>
exact pow_pos (zero_lt_one.trans_le a1) _
theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : β} (mn : m < n) :
1 / a ^ n < 1 / a ^ m := by
refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_rightβ a1 mn) <;>
exact pow_pos (zero_lt_one.trans a1) _
theorem one_div_pow_anti (a1 : 1 β€ a) : Antitone fun n : β => 1 / a ^ n := fun _ _ =>
one_div_pow_le_one_div_pow_of_le a1
theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β => 1 / a ^ n := fun _ _ =>
one_div_pow_lt_one_div_pow_of_lt a1
theorem inv_strictAntiOn : StrictAntiOn (fun x : Ξ± => xβ»ΒΉ) (Set.Ioi 0) := fun _ hx _ hy xy =>
(inv_lt_invβ hy hx).2 xy
theorem inv_pow_le_inv_pow_of_le (a1 : 1 β€ a) {m n : β} (mn : m β€ n) : (a ^ n)β»ΒΉ β€ (a ^ m)β»ΒΉ := by
convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp
theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : β} (mn : m < n) : (a ^ n)β»ΒΉ < (a ^ m)β»ΒΉ := by
convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp
theorem inv_pow_anti (a1 : 1 β€ a) : Antitone fun n : β => (a ^ n)β»ΒΉ := fun _ _ =>
inv_pow_le_inv_pow_of_le a1
theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β => (a ^ n)β»ΒΉ := fun _ _ =>
inv_pow_lt_inv_pow_of_lt a1
theorem le_iff_forall_one_lt_le_mulβ {Ξ± : Type*}
[Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±]
{a b : Ξ±} (hb : 0 β€ b) : a β€ b β β Ξ΅, 1 < Ξ΅ β a β€ b * Ξ΅ := by
refine β¨fun h _ hΞ΅ β¦ h.trans <| le_mul_of_one_le_right hb hΞ΅.le, fun h β¦ ?_β©
obtain rfl|hb := hb.eq_or_lt
Β· simp_rw [zero_mul] at h
exact h 2 one_lt_two
refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_
convert h (x / b) ((one_lt_div hb).mpr hbx)
rw [mul_div_cancelβ _ hb.ne']
/-! ### Results about `IsGLB` -/
theorem IsGLB.mul_left {s : Set Ξ±} (ha : 0 β€ a) (hs : IsGLB s b) :
IsGLB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
Β· exact (OrderIso.mulLeftβ _ ha).isGLB_image'.2 hs
Β· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isGLB_singleton
theorem IsGLB.mul_right {s : Set Ξ±} (ha : 0 β€ a) (hs : IsGLB s b) :
IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
end LinearOrderedSemifield
section
variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d : Ξ±} {n : β€}
/-! ### Lemmas about pos, nonneg, nonpos, neg -/
theorem div_pos_iff : 0 < a / b β 0 < a β§ 0 < b β¨ a < 0 β§ b < 0 := by
simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero]
theorem div_neg_iff : a / b < 0 β 0 < a β§ b < 0 β¨ a < 0 β§ 0 < b := by
simp [division_def, mul_neg_iff]
theorem div_nonneg_iff : 0 β€ a / b β 0 β€ a β§ 0 β€ b β¨ a β€ 0 β§ b β€ 0 := by
simp [division_def, mul_nonneg_iff]
theorem div_nonpos_iff : a / b β€ 0 β 0 β€ a β§ b β€ 0 β¨ a β€ 0 β§ 0 β€ b := by
simp [division_def, mul_nonpos_iff]
theorem div_nonneg_of_nonpos (ha : a β€ 0) (hb : b β€ 0) : 0 β€ a / b :=
div_nonneg_iff.2 <| Or.inr β¨ha, hbβ©
theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=
div_pos_iff.2 <| Or.inr β¨ha, hbβ©
theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=
div_neg_iff.2 <| Or.inr β¨ha, hbβ©
theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=
div_neg_iff.2 <| Or.inl β¨ha, hbβ©
/-! ### Relating one division with another term -/
theorem div_le_iff_of_neg (hc : c < 0) : b / c β€ a β a * c β€ b :=
β¨fun h => div_mul_cancelβ b (ne_of_lt hc) βΈ mul_le_mul_of_nonpos_right h hc.le, fun h =>
calc
a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc)
_ β₯ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le
_ = b / c := (div_eq_mul_one_div b c).symm
β©
theorem div_le_iff_of_neg' (hc : c < 0) : b / c β€ a β c * a β€ b := by
rw [mul_comm, div_le_iff_of_neg hc]
theorem le_div_iff_of_neg (hc : c < 0) : a β€ b / c β b β€ a * c := by
rw [β neg_neg c, mul_neg, div_neg, le_neg, div_le_iffβ (neg_pos.2 hc), neg_mul]
theorem le_div_iff_of_neg' (hc : c < 0) : a β€ b / c β b β€ c * a := by
rw [mul_comm, le_div_iff_of_neg hc]
theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a β a * c < b :=
lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc
theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a β c * a < b := by
rw [mul_comm, div_lt_iff_of_neg hc]
theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c β b < a * c :=
lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc
theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c β b < c * a := by
rw [mul_comm, lt_div_iff_of_neg hc]
theorem div_le_one_of_ge (h : b β€ a) (hb : b β€ 0) : a / b β€ 1 := by
simpa only [neg_div_neg_eq] using div_le_one_of_leβ (neg_le_neg h) (neg_nonneg_of_nonpos hb)
/-! ### Bi-implications of inequalities using inversions -/
theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ β€ bβ»ΒΉ β b β€ a := by
rw [β one_div, div_le_iff_of_neg ha, β div_eq_inv_mul, div_le_iff_of_neg hb, one_mul]
theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ β€ b β bβ»ΒΉ β€ a := by
rw [β inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv]
theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a β€ bβ»ΒΉ β b β€ aβ»ΒΉ := by
rw [β inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv]
theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ < bβ»ΒΉ β b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)
theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : aβ»ΒΉ < b β bβ»ΒΉ < a :=
lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)
theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < bβ»ΒΉ β b < aβ»ΒΉ :=
lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)
/-!
### Monotonicity results involving inversion
-/
theorem sub_inv_antitoneOn_Ioi :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Ioi c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab β¦
inv_le_invβ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Iio :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Iio c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab β¦
inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Icc_right (ha : c < a) :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Icc a b) := by
by_cases hab : a β€ b
Β· exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha
Β· simp [hab, Set.Subsingleton.antitoneOn]
theorem sub_inv_antitoneOn_Icc_left (ha : b < c) :
AntitoneOn (fun x β¦ (x-c)β»ΒΉ) (Set.Icc a b) := by
by_cases hab : a β€ b
Β· exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha
Β· simp [hab, Set.Subsingleton.antitoneOn]
theorem inv_antitoneOn_Ioi :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Ioi 0) := by
convert sub_inv_antitoneOn_Ioi (Ξ± := Ξ±)
exact (sub_zero _).symm
theorem inv_antitoneOn_Iio :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Iio 0) := by
convert sub_inv_antitoneOn_Iio (Ξ± := Ξ±)
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_right (ha : 0 < a) :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_right ha
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_left (hb : b < 0) :
AntitoneOn (fun x : Ξ± β¦ xβ»ΒΉ) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_left hb
exact (sub_zero _).symm
/-! ### Relating two divisions -/
theorem div_le_div_of_nonpos_of_le (hc : c β€ 0) (h : b β€ a) : a / c β€ b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc)
theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by
rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c]
exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc)
theorem div_le_div_right_of_neg (hc : c < 0) : a / c β€ b / c β b β€ a :=
β¨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.leβ©
theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c β b < a :=
lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc
/-! ### Relating one division and involving `1` -/
theorem one_le_div_of_neg (hb : b < 0) : 1 β€ a / b β a β€ b := by rw [le_div_iff_of_neg hb, one_mul]
theorem div_le_one_of_neg (hb : b < 0) : a / b β€ 1 β b β€ a := by rw [div_le_iff_of_neg hb, one_mul]
theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b β a < b := by rw [lt_div_iff_of_neg hb, one_mul]
theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 β b < a := by rw [div_lt_iff_of_neg hb, one_mul]
theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a β€ b β 1 / b β€ a := by
simpa using inv_le_of_neg ha hb
theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b β 1 / b < a := by
simpa using inv_lt_of_neg ha hb
theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a β€ 1 / b β b β€ 1 / a := by
simpa using le_inv_of_neg ha hb
theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b β b < 1 / a := by
simpa using lt_inv_of_neg ha hb
theorem one_lt_div_iff : 1 < a / b β 0 < b β§ b < a β¨ b < 0 β§ a < b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
Β· simp [hb, hb.not_lt, one_lt_div_of_neg]
Β· simp [lt_irrefl, zero_le_one]
Β· simp [hb, hb.not_lt, one_lt_div]
theorem one_le_div_iff : 1 β€ a / b β 0 < b β§ b β€ a β¨ b < 0 β§ a β€ b := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
Β· simp [hb, hb.not_lt, one_le_div_of_neg]
Β· simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one]
Β· simp [hb, hb.not_lt, one_le_div]
theorem div_lt_one_iff : a / b < 1 β 0 < b β§ a < b β¨ b = 0 β¨ b < 0 β§ b < a := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
Β· simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg]
Β· simp [zero_lt_one]
Β· simp [hb, hb.not_lt, div_lt_one, hb.ne.symm]
theorem div_le_one_iff : a / b β€ 1 β 0 < b β§ a β€ b β¨ b = 0 β¨ b < 0 β§ b β€ a := by
rcases lt_trichotomy b 0 with (hb | rfl | hb)
Β· simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg]
Β· simp [zero_le_one]
Β· simp [hb, hb.not_lt, div_le_one, hb.ne.symm]
/-! ### Relating two divisions, involving `1` -/
theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a β€ b) : 1 / b β€ 1 / a := by
rwa [div_le_iff_of_neg' hb, β div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)]
theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by
rwa [div_lt_iff_of_neg' hb, β div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)]
theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a β€ 1 / b) : b β€ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h
theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a β€ 1 / b β b β€ a := by
simpa [one_div] using inv_le_inv_of_neg ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b β b < a :=
lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha)
theorem one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 :=
suffices 1 / a < 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this
one_div_lt_one_div_of_neg_of_lt h1 h2
theorem one_div_le_neg_one (h1 : a < 0) (h2 : -1 β€ a) : 1 / a β€ -1 :=
suffices 1 / a β€ 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this
one_div_le_one_div_of_neg_of_le h1 h2
/-! ### Results about halving -/
theorem sub_self_div_two (a : Ξ±) : a - a / 2 = a / 2 := by
suffices a / 2 + a / 2 - a / 2 = a / 2 by rwa [add_halves] at this
rw [add_sub_cancel_right]
theorem div_two_sub_self (a : Ξ±) : a / 2 - a = -(a / 2) := by
suffices a / 2 - (a / 2 + a / 2) = -(a / 2) by rwa [add_halves] at this
rw [sub_add_eq_sub_sub, sub_self, zero_sub]
theorem add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := by
rwa [β div_sub_div_same, sub_eq_add_neg, add_comm (b / 2), β add_assoc, β sub_eq_add_neg, β
lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two,
div_lt_div_iff_of_pos_right (zero_lt_two' Ξ±)]
/-- An inequality involving `2`. -/
theorem sub_one_div_inv_le_two (a2 : 2 β€ a) : (1 - 1 / a)β»ΒΉ β€ 2 := by
-- Take inverses on both sides to obtain `2β»ΒΉ β€ 1 - 1 / a`
refine (inv_antiβ (inv_pos.2 <| zero_lt_two' Ξ±) ?_).trans_eq (inv_inv (2 : Ξ±))
-- move `1 / a` to the left and `2β»ΒΉ` to the right.
rw [le_sub_iff_add_le, add_comm, β le_sub_iff_add_le]
-- take inverses on both sides and use the assumption `2 β€ a`.
convert (one_div a).le.trans (inv_antiβ zero_lt_two a2) using 1
-- show `1 - 1 / 2 = 1 / 2`.
rw [sub_eq_iff_eq_add, β two_mul, mul_inv_cancelβ two_ne_zero]
/-! ### Results about `IsLUB` -/
-- TODO: Generalize to `LinearOrderedSemifield`
theorem IsLUB.mul_left {s : Set Ξ±} (ha : 0 β€ a) (hs : IsLUB s b) :
IsLUB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
Β· exact (OrderIso.mulLeftβ _ ha).isLUB_image'.2 hs
Β· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isLUB_singleton
-- TODO: Generalize to `LinearOrderedSemifield`
theorem IsLUB.mul_right {s : Set Ξ±} (ha : 0 β€ a) (hs : IsLUB s b) :
IsLUB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
/-! ### Miscellaneous lemmas -/
theorem mul_sub_mul_div_mul_neg_iff (hc : c β 0) (hd : d β 0) :
(a * d - b * c) / (c * d) < 0 β a / c < b / d := by
rw [mul_comm b c, β div_sub_div _ _ hc hd, sub_lt_zero]
theorem mul_sub_mul_div_mul_nonpos_iff (hc : c β 0) (hd : d β 0) :
(a * d - b * c) / (c * d) β€ 0 β a / c β€ b / d := by
rw [mul_comm b c, β div_sub_div _ _ hc hd, sub_nonpos]
alias β¨div_lt_div_of_mul_sub_mul_div_neg, mul_sub_mul_div_mul_negβ© := mul_sub_mul_div_mul_neg_iff
alias β¨div_le_div_of_mul_sub_mul_div_nonpos, mul_sub_mul_div_mul_nonposβ© :=
mul_sub_mul_div_mul_nonpos_iff
theorem exists_add_lt_and_pos_of_lt (h : b < a) : β c, b + c < a β§ 0 < c :=
β¨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_twoβ©
theorem le_of_forall_sub_le (h : β Ξ΅ > 0, b - Ξ΅ β€ a) : b β€ a := by
contrapose! h
simpa only [@and_comm ((0 : Ξ±) < _), lt_sub_iff_add_lt, gt_iff_lt] using
exists_add_lt_and_pos_of_lt h
private lemma exists_lt_mul_left_of_nonneg {a b c : Ξ±} (ha : 0 β€ a) (hc : 0 β€ c) (h : c < a * b) :
β a' β Set.Ico 0 a, c < a' * b := by
have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha
obtain β¨a', ha', a_a'β© := exists_between ((div_lt_iffβ hb).2 h)
exact β¨a', β¨(div_nonneg hc hb.le).trans ha'.le, a_a'β©, (div_lt_iffβ hb).1 ha'β©
private lemma exists_lt_mul_right_of_nonneg {a b c : Ξ±} (ha : 0 β€ a) (hc : 0 β€ c) (h : c < a * b) :
β b' β Set.Ico 0 b, c < a * b' := by
have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha
simp_rw [mul_comm a] at h β’
exact exists_lt_mul_left_of_nonneg hb.le hc h
private lemma exists_mul_left_ltβ {a b c : Ξ±} (hc : a * b < c) : β a' > a, a' * b < c := by
rcases le_or_lt b 0 with hb | hb
Β· obtain β¨a', ha'β© := exists_gt a
exact β¨a', ha', hc.trans_le' (antitone_mul_right hb ha'.le)β©
Β· obtain β¨a', ha', hc'β© := exists_between ((lt_div_iffβ hb).2 hc)
exact β¨a', ha', (lt_div_iffβ hb).1 hc'β©
private lemma exists_mul_right_ltβ {a b c : Ξ±} (hc : a * b < c) : β b' > b, a * b' < c := by
simp_rw [mul_comm a] at hc β’; exact exists_mul_left_ltβ hc
lemma le_mul_of_forall_ltβ {a b c : Ξ±} (h : β a' > a, β b' > b, c β€ a' * b') : c β€ a * b := by
refine le_of_forall_gt_imp_ge_of_dense fun d hd β¦ ?_
obtain β¨a', ha', hdβ© := exists_mul_left_ltβ hd
obtain β¨b', hb', hdβ© := exists_mul_right_ltβ hd
exact (h a' ha' b' hb').trans hd.le
lemma mul_le_of_forall_lt_of_nonneg {a b c : Ξ±} (ha : 0 β€ a) (hc : 0 β€ c)
(h : β a' β₯ 0, a' < a β β b' β₯ 0, b' < b β a' * b' β€ c) : a * b β€ c := by
refine le_of_forall_lt_imp_le_of_dense fun d d_ab β¦ ?_
rcases lt_or_le d 0 with hd | hd
Β· exact hd.le.trans hc
obtain β¨a', ha', d_abβ© := exists_lt_mul_left_of_nonneg ha hd d_ab
obtain β¨b', hb', d_abβ© := exists_lt_mul_right_of_nonneg ha'.1 hd d_ab
exact d_ab.le.trans (h a' ha'.1 ha'.2 b' hb'.1 hb'.2)
theorem mul_self_inj_of_nonneg (a0 : 0 β€ a) (b0 : 0 β€ b) : a * a = b * b β a = b :=
mul_self_eq_mul_self_iff.trans <|
or_iff_left_of_imp fun h => by
subst a
have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0
rw [this, neg_zero]
theorem min_div_div_right_of_nonpos (hc : c β€ 0) (a b : Ξ±) : min (a / c) (b / c) = max a b / c :=
Eq.symm <| Antitone.map_max fun _ _ => div_le_div_of_nonpos_of_le hc
theorem max_div_div_right_of_nonpos (hc : c β€ 0) (a b : Ξ±) : max (a / c) (b / c) = min a b / c :=
Eq.symm <| Antitone.map_min fun _ _ => div_le_div_of_nonpos_of_le hc
theorem abs_inv (a : Ξ±) : |aβ»ΒΉ| = |a|β»ΒΉ :=
map_invβ (absHom : Ξ± β*β Ξ±) a
theorem abs_div (a b : Ξ±) : |a / b| = |a| / |b| :=
map_divβ (absHom : Ξ± β*β Ξ±) a b
theorem abs_one_div (a : Ξ±) : |1 / a| = 1 / |a| := by rw [abs_div, abs_one]
theorem uniform_continuous_npow_on_bounded (B : Ξ±) {Ξ΅ : Ξ±} (hΞ΅ : 0 < Ξ΅) (n : β) :
β Ξ΄ > 0, β q r : Ξ±, |r| β€ B β |q - r| β€ Ξ΄ β |q ^ n - r ^ n| < Ξ΅ := by
wlog B_pos : 0 < B generalizing B
Β· have β¨Ξ΄, Ξ΄_pos, contβ© := this 1 zero_lt_one
exact β¨Ξ΄, Ξ΄_pos, fun q r hr β¦ cont q r (hr.trans ((le_of_not_lt B_pos).trans zero_le_one))β©
have pos : 0 < 1 + βn * (B + 1) ^ (n - 1) := zero_lt_one.trans_le <| le_add_of_nonneg_right <|
mul_nonneg n.cast_nonneg <| (pow_pos (B_pos.trans <| lt_add_of_pos_right _ zero_lt_one) _).le
refine β¨min 1 (Ξ΅ / (1 + n * (B + 1) ^ (n - 1))), lt_min zero_lt_one (div_pos hΞ΅ pos),
fun q r hr hqr β¦ (abs_pow_sub_pow_le ..).trans_lt ?_β©
rw [le_inf_iff, le_div_iffβ pos, mul_one_add, β mul_assoc] at hqr
obtain h | h := (abs_nonneg (q - r)).eq_or_lt
Β· simpa only [β h, zero_mul] using hΞ΅
refine (lt_of_le_of_lt ?_ <| lt_add_of_pos_left _ h).trans_le hqr.2
refine mul_le_mul_of_nonneg_left (pow_le_pow_leftβ ((abs_nonneg _).trans le_sup_left) ?_ _)
(mul_nonneg (abs_nonneg _) n.cast_nonneg)
refine max_le ?_ (hr.trans <| le_add_of_nonneg_right zero_le_one)
exact add_sub_cancel r q βΈ (abs_add_le ..).trans (add_le_add hr hqr.1)
end
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
section LinearOrderedSemifield
variable {Ξ± : Type*} [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b : Ξ±}
private lemma div_nonneg_of_pos_of_nonneg (ha : 0 < a) (hb : 0 β€ b) : 0 β€ a / b :=
div_nonneg ha.le hb
private lemma div_nonneg_of_nonneg_of_pos (ha : 0 β€ a) (hb : 0 < b) : 0 β€ a / b :=
div_nonneg ha hb.le
omit [IsStrictOrderedRing Ξ±] in
private lemma div_ne_zero_of_pos_of_ne_zero (ha : 0 < a) (hb : b β 0) : a / b β 0 :=
div_ne_zero ha.ne' hb
omit [IsStrictOrderedRing Ξ±] in
private lemma div_ne_zero_of_ne_zero_of_pos (ha : a β 0) (hb : 0 < b) : a / b β 0 :=
div_ne_zero ha hb.ne'
private lemma zpow_zero_pos (a : Ξ±) : 0 < a ^ (0 : β€) := zero_lt_one.trans_eq (zpow_zero a).symm
end LinearOrderedSemifield
/-- The `positivity` extension which identifies expressions of the form `a / b`,
such that `positivity` successfully recognises both `a` and `b`. -/
@[positivity _ / _] def evalDiv : PositivityExt where eval {u Ξ±} zΞ± pΞ± e := do
let .app (.app (f : Q($Ξ± β $Ξ± β $Ξ±)) (a : Q($Ξ±))) (b : Q($Ξ±)) β withReducible (whnf e)
| throwError "not /"
let _e_eq : $e =Q $f $a $b := β¨β©
let _a β synthInstanceQ q(Semifield $Ξ±)
let _a β synthInstanceQ q(LinearOrder $Ξ±)
let _a β synthInstanceQ q(IsStrictOrderedRing $Ξ±)
assumeInstancesCommute
let β¨_f_eqβ© β withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(HDiv.hDiv)
let ra β core zΞ± pΞ± a; let rb β core zΞ± pΞ± b
match ra, rb with
| .positive pa, .positive pb => pure (.positive q(div_pos $pa $pb))
| .positive pa, .nonnegative pb => pure (.nonnegative q(div_nonneg_of_pos_of_nonneg $pa $pb))
| .nonnegative pa, .positive pb => pure (.nonnegative q(div_nonneg_of_nonneg_of_pos $pa $pb))
| .nonnegative pa, .nonnegative pb => pure (.nonnegative q(div_nonneg $pa $pb))
| .positive pa, .nonzero pb => pure (.nonzero q(div_ne_zero_of_pos_of_ne_zero $pa $pb))
| .nonzero pa, .positive pb => pure (.nonzero q(div_ne_zero_of_ne_zero_of_pos $pa $pb))
| .nonzero pa, .nonzero pb => pure (.nonzero q(div_ne_zero $pa $pb))
| _, _ => pure .none
/-- The `positivity` extension which identifies expressions of the form `aβ»ΒΉ`,
such that `positivity` successfully recognises `a`. -/
@[positivity _β»ΒΉ]
def evalInv : PositivityExt where eval {u Ξ±} zΞ± pΞ± e := do
let .app (f : Q($Ξ± β $Ξ±)) (a : Q($Ξ±)) β withReducible (whnf e) | throwError "not β»ΒΉ"
let _e_eq : $e =Q $f $a := β¨β©
let _a β synthInstanceQ q(Semifield $Ξ±)
let _a β synthInstanceQ q(LinearOrder $Ξ±)
let _a β synthInstanceQ q(IsStrictOrderedRing $Ξ±)
assumeInstancesCommute
let β¨_f_eqβ© β withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(Inv.inv)
let ra β core zΞ± pΞ± a
match ra with
| .positive pa => pure (.positive q(inv_pos_of_pos $pa))
| .nonnegative pa => pure (.nonnegative q(inv_nonneg_of_nonneg $pa))
| .nonzero pa => pure (.nonzero q(inv_ne_zero $pa))
| .none => pure .none
/-- The `positivity` extension which identifies expressions of the form `a ^ (0:β€)`. -/
@[positivity _ ^ (0 : β€), Pow.pow _ (0 : β€)]
def evalPowZeroInt : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do
let .app (.app _ (a : Q($Ξ±))) _ β withReducible (whnf e) | throwError "not ^"
let _a β synthInstanceQ q(Semifield $Ξ±)
let _a β synthInstanceQ q(LinearOrder $Ξ±)
let _a β synthInstanceQ q(IsStrictOrderedRing $Ξ±)
assumeInstancesCommute
let β¨_aβ© β Qq.assertDefEqQ q($e) q($a ^ (0 : β€))
pure (.positive q(zpow_zero_pos $a))
end Mathlib.Meta.Positivity
| Mathlib/Algebra/Order/Field/Basic.lean | 951 | 953 | |
/-
Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Bryan Gin-ge Chen, YaΓ«l Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Logic.Equiv.Basic
/-!
# Symmetric difference and bi-implication
This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras.
## Examples
Some examples are
* The symmetric difference of two sets is the set of elements that are in either but not both.
* The symmetric difference on propositions is `Xor'`.
* The symmetric difference on `Bool` is `Bool.xor`.
* The equivalence of propositions. Two propositions are equivalent if they imply each other.
* The symmetric difference translates to addition when considering a Boolean algebra as a Boolean
ring.
## Main declarations
* `symmDiff`: The symmetric difference operator, defined as `(a \ b) β (b \ a)`
* `bihimp`: The bi-implication operator, defined as `(b β¨ a) β (a β¨ b)`
In generalized Boolean algebras, the symmetric difference operator is:
* `symmDiff_comm`: commutative, and
* `symmDiff_assoc`: associative.
## Notations
* `a β b`: `symmDiff a b`
* `a β b`: `bihimp a b`
## References
The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A
Proof from the Book" by John McCuan:
* <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf>
## Tags
boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication,
Heyting
-/
assert_not_exists RelIso
open Function OrderDual
variable {ΞΉ Ξ± Ξ² : Type*} {Ο : ΞΉ β Type*}
/-- The symmetric difference operator on a type with `β` and `\` is `(A \ B) β (B \ A)`. -/
def symmDiff [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : Ξ± :=
a \ b β b \ a
/-- The Heyting bi-implication is `(b β¨ a) β (a β¨ b)`. This generalizes equivalence of
propositions. -/
def bihimp [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : Ξ± :=
(b β¨ a) β (a β¨ b)
/-- Notation for symmDiff -/
scoped[symmDiff] infixl:100 " β " => symmDiff
/-- Notation for bihimp -/
scoped[symmDiff] infixl:100 " β " => bihimp
open scoped symmDiff
theorem symmDiff_def [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : a β b = a \ b β b \ a :=
rfl
theorem bihimp_def [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : a β b = (b β¨ a) β (a β¨ b) :=
rfl
theorem symmDiff_eq_Xor' (p q : Prop) : p β q = Xor' p q :=
rfl
@[simp]
theorem bihimp_iff_iff {p q : Prop} : p β q β (p β q) :=
iff_iff_implies_and_implies.symm.trans Iff.comm
@[simp]
theorem Bool.symmDiff_eq_xor : β p q : Bool, p β q = xor p q := by decide
section GeneralizedCoheytingAlgebra
variable [GeneralizedCoheytingAlgebra Ξ±] (a b c : Ξ±)
@[simp]
theorem toDual_symmDiff : toDual (a β b) = toDual a β toDual b :=
rfl
@[simp]
theorem ofDual_bihimp (a b : Ξ±α΅α΅) : ofDual (a β b) = ofDual a β ofDual b :=
rfl
theorem symmDiff_comm : a β b = b β a := by simp only [symmDiff, sup_comm]
instance symmDiff_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· β Β·) :=
β¨symmDiff_commβ©
@[simp]
theorem symmDiff_self : a β a = β₯ := by rw [symmDiff, sup_idem, sdiff_self]
@[simp]
theorem symmDiff_bot : a β β₯ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq]
@[simp]
theorem bot_symmDiff : β₯ β a = a := by rw [symmDiff_comm, symmDiff_bot]
@[simp]
theorem symmDiff_eq_bot {a b : Ξ±} : a β b = β₯ β a = b := by
simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff]
theorem symmDiff_of_le {a b : Ξ±} (h : a β€ b) : a β b = b \ a := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq]
theorem symmDiff_of_ge {a b : Ξ±} (h : b β€ a) : a β b = a \ b := by
rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq]
theorem symmDiff_le {a b c : Ξ±} (ha : a β€ b β c) (hb : b β€ a β c) : a β b β€ c :=
sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb
theorem symmDiff_le_iff {a b c : Ξ±} : a β b β€ c β a β€ b β c β§ b β€ a β c := by
simp_rw [symmDiff, sup_le_iff, sdiff_le_iff]
@[simp]
theorem symmDiff_le_sup {a b : Ξ±} : a β b β€ a β b :=
sup_le_sup sdiff_le sdiff_le
theorem symmDiff_eq_sup_sdiff_inf : a β b = (a β b) \ (a β b) := by simp [sup_sdiff, symmDiff]
theorem Disjoint.symmDiff_eq_sup {a b : Ξ±} (h : Disjoint a b) : a β b = a β b := by
rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right]
theorem symmDiff_sdiff : a β b \ c = a \ (b β c) β b \ (a β c) := by
rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left]
@[simp]
theorem symmDiff_sdiff_inf : a β b \ (a β b) = a β b := by
rw [symmDiff_sdiff]
simp [symmDiff]
@[simp]
theorem symmDiff_sdiff_eq_sup : a β (b \ a) = a β b := by
rw [symmDiff, sdiff_idem]
exact
le_antisymm (sup_le_sup sdiff_le sdiff_le)
(sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup)
@[simp]
theorem sdiff_symmDiff_eq_sup : (a \ b) β b = a β b := by
rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm]
@[simp]
theorem symmDiff_sup_inf : a β b β a β b = a β b := by
refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_
rw [sup_inf_left, symmDiff]
refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right)
Β· rw [sup_right_comm]
exact le_sup_of_le_left le_sdiff_sup
Β· rw [sup_assoc]
exact le_sup_of_le_right le_sdiff_sup
@[simp]
theorem inf_sup_symmDiff : a β b β a β b = a β b := by rw [sup_comm, symmDiff_sup_inf]
@[simp]
theorem symmDiff_symmDiff_inf : a β b β (a β b) = a β b := by
rw [β symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf]
@[simp]
theorem inf_symmDiff_symmDiff : (a β b) β (a β b) = a β b := by
rw [symmDiff_comm, symmDiff_symmDiff_inf]
theorem symmDiff_triangle : a β c β€ a β b β b β c := by
refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_
rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff]
theorem le_symmDiff_sup_right (a b : Ξ±) : a β€ (a β b) β b := by
convert symmDiff_triangle a b β₯ <;> rw [symmDiff_bot]
theorem le_symmDiff_sup_left (a b : Ξ±) : b β€ (a β b) β a :=
symmDiff_comm a b βΈ le_symmDiff_sup_right ..
end GeneralizedCoheytingAlgebra
section GeneralizedHeytingAlgebra
variable [GeneralizedHeytingAlgebra Ξ±] (a b c : Ξ±)
@[simp]
theorem toDual_bihimp : toDual (a β b) = toDual a β toDual b :=
rfl
@[simp]
theorem ofDual_symmDiff (a b : Ξ±α΅α΅) : ofDual (a β b) = ofDual a β ofDual b :=
rfl
theorem bihimp_comm : a β b = b β a := by simp only [(Β· β Β·), inf_comm]
instance bihimp_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· β Β·) :=
β¨bihimp_commβ©
@[simp]
theorem bihimp_self : a β a = β€ := by rw [bihimp, inf_idem, himp_self]
@[simp]
theorem bihimp_top : a β β€ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq]
@[simp]
theorem top_bihimp : β€ β a = a := by rw [bihimp_comm, bihimp_top]
@[simp]
theorem bihimp_eq_top {a b : Ξ±} : a β b = β€ β a = b :=
@symmDiff_eq_bot Ξ±α΅α΅ _ _ _
theorem bihimp_of_le {a b : Ξ±} (h : a β€ b) : a β b = b β¨ a := by
rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq]
theorem bihimp_of_ge {a b : Ξ±} (h : b β€ a) : a β b = a β¨ b := by
rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq]
theorem le_bihimp {a b c : Ξ±} (hb : a β b β€ c) (hc : a β c β€ b) : a β€ b β c :=
le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb
theorem le_bihimp_iff {a b c : Ξ±} : a β€ b β c β a β b β€ c β§ a β c β€ b := by
simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm]
@[simp]
theorem inf_le_bihimp {a b : Ξ±} : a β b β€ a β b :=
inf_le_inf le_himp le_himp
theorem bihimp_eq_inf_himp_inf : a β b = a β b β¨ a β b := by simp [himp_inf_distrib, bihimp]
theorem Codisjoint.bihimp_eq_inf {a b : Ξ±} (h : Codisjoint a b) : a β b = a β b := by
rw [bihimp, h.himp_eq_left, h.himp_eq_right]
theorem himp_bihimp : a β¨ b β c = (a β c β¨ b) β (a β b β¨ c) := by
rw [bihimp, himp_inf_distrib, himp_himp, himp_himp]
@[simp]
theorem sup_himp_bihimp : a β b β¨ a β b = a β b := by
rw [himp_bihimp]
simp [bihimp]
@[simp]
theorem bihimp_himp_eq_inf : a β (a β¨ b) = a β b :=
@symmDiff_sdiff_eq_sup Ξ±α΅α΅ _ _ _
@[simp]
theorem himp_bihimp_eq_inf : (b β¨ a) β b = a β b :=
@sdiff_symmDiff_eq_sup Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_inf_sup : a β b β (a β b) = a β b :=
@symmDiff_sup_inf Ξ±α΅α΅ _ _ _
@[simp]
theorem sup_inf_bihimp : (a β b) β a β b = a β b :=
@inf_sup_symmDiff Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_bihimp_sup : a β b β (a β b) = a β b :=
@symmDiff_symmDiff_inf Ξ±α΅α΅ _ _ _
@[simp]
theorem sup_bihimp_bihimp : (a β b) β (a β b) = a β b :=
@inf_symmDiff_symmDiff Ξ±α΅α΅ _ _ _
theorem bihimp_triangle : a β b β b β c β€ a β c :=
@symmDiff_triangle Ξ±α΅α΅ _ _ _ _
end GeneralizedHeytingAlgebra
section CoheytingAlgebra
variable [CoheytingAlgebra Ξ±] (a : Ξ±)
@[simp]
theorem symmDiff_top' : a β β€ = οΏ’a := by simp [symmDiff]
@[simp]
theorem top_symmDiff' : β€ β a = οΏ’a := by simp [symmDiff]
@[simp]
theorem hnot_symmDiff_self : (οΏ’a) β a = β€ := by
rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self]
exact Codisjoint.top_le codisjoint_hnot_left
@[simp]
theorem symmDiff_hnot_self : a β (οΏ’a) = β€ := by rw [symmDiff_comm, hnot_symmDiff_self]
theorem IsCompl.symmDiff_eq_top {a b : Ξ±} (h : IsCompl a b) : a β b = β€ := by
rw [h.eq_hnot, hnot_symmDiff_self]
end CoheytingAlgebra
section HeytingAlgebra
variable [HeytingAlgebra Ξ±] (a : Ξ±)
@[simp]
theorem bihimp_bot : a β β₯ = aαΆ := by simp [bihimp]
@[simp]
theorem bot_bihimp : β₯ β a = aαΆ := by simp [bihimp]
@[simp]
theorem compl_bihimp_self : aαΆ β a = β₯ :=
@hnot_symmDiff_self Ξ±α΅α΅ _ _
@[simp]
theorem bihimp_hnot_self : a β aαΆ = β₯ :=
@symmDiff_hnot_self Ξ±α΅α΅ _ _
theorem IsCompl.bihimp_eq_bot {a b : Ξ±} (h : IsCompl a b) : a β b = β₯ := by
rw [h.eq_compl, compl_bihimp_self]
end HeytingAlgebra
section GeneralizedBooleanAlgebra
variable [GeneralizedBooleanAlgebra Ξ±] (a b c d : Ξ±)
@[simp]
theorem sup_sdiff_symmDiff : (a β b) \ a β b = a β b :=
sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf])
theorem disjoint_symmDiff_inf : Disjoint (a β b) (a β b) := by
rw [symmDiff_eq_sup_sdiff_inf]
exact disjoint_sdiff_self_left
theorem inf_symmDiff_distrib_left : a β b β c = (a β b) β (a β c) := by
rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left,
symmDiff_eq_sup_sdiff_inf]
theorem inf_symmDiff_distrib_right : a β b β c = (a β c) β (b β c) := by
simp_rw [inf_comm _ c, inf_symmDiff_distrib_left]
theorem sdiff_symmDiff : c \ a β b = c β a β b β c \ a β c \ b := by
simp only [(Β· β Β·), sdiff_sdiff_sup_sdiff']
theorem sdiff_symmDiff' : c \ a β b = c β a β b β c \ (a β b) := by
rw [sdiff_symmDiff, sdiff_sup]
@[simp]
theorem symmDiff_sdiff_left : a β b \ a = b \ a := by
rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq]
@[simp]
theorem symmDiff_sdiff_right : a β b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left]
@[simp]
theorem sdiff_symmDiff_left : a \ a β b = a β b := by simp [sdiff_symmDiff]
@[simp]
theorem sdiff_symmDiff_right : b \ a β b = a β b := by
rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left]
theorem symmDiff_eq_sup : a β b = a β b β Disjoint a b := by
refine β¨fun h => ?_, Disjoint.symmDiff_eq_supβ©
rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h
exact h.of_disjoint_inf_of_le le_sup_left
@[simp]
theorem le_symmDiff_iff_left : a β€ a β b β Disjoint a b := by
refine β¨fun h => ?_, fun h => h.symmDiff_eq_sup.symm βΈ le_sup_leftβ©
rw [symmDiff_eq_sup_sdiff_inf] at h
exact disjoint_iff_inf_le.mpr (le_sdiff_right.1 <| inf_le_of_left_le h).le
@[simp]
theorem le_symmDiff_iff_right : b β€ a β b β Disjoint a b := by
rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm]
theorem symmDiff_symmDiff_left :
a β b β c = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c :=
calc
a β b β c = a β b \ c β c \ a β b := symmDiff_def _ _
_ = a \ (b β c) β b \ (a β c) β (c \ (a β b) β c β a β b) := by
{ rw [sdiff_symmDiff', sup_comm (c β a β b), symmDiff_sdiff] }
_ = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c := by ac_rfl
theorem symmDiff_symmDiff_right :
a β (b β c) = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c :=
calc
a β (b β c) = a \ b β c β b β c \ a := symmDiff_def _ _
_ = a \ (b β c) β a β b β c β (b \ (c β a) β c \ (b β a)) := by
{ rw [sdiff_symmDiff', sup_comm (a β b β c), symmDiff_sdiff] }
_ = a \ (b β c) β b \ (a β c) β c \ (a β b) β a β b β c := by ac_rfl
theorem symmDiff_assoc : a β b β c = a β (b β c) := by
rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right]
instance symmDiff_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· β Β·) :=
β¨symmDiff_assocβ©
theorem symmDiff_left_comm : a β (b β c) = b β (a β c) := by
simp_rw [β symmDiff_assoc, symmDiff_comm]
theorem symmDiff_right_comm : a β b β c = a β c β b := by simp_rw [symmDiff_assoc, symmDiff_comm]
theorem symmDiff_symmDiff_symmDiff_comm : a β b β (c β d) = a β c β (b β d) := by
simp_rw [symmDiff_assoc, symmDiff_left_comm]
@[simp]
theorem symmDiff_symmDiff_cancel_left : a β (a β b) = b := by simp [β symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_cancel_right : b β a β a = b := by simp [symmDiff_assoc]
@[simp]
theorem symmDiff_symmDiff_self' : a β b β a = b := by
rw [symmDiff_comm, symmDiff_symmDiff_cancel_left]
theorem symmDiff_left_involutive (a : Ξ±) : Involutive (Β· β a) :=
symmDiff_symmDiff_cancel_right _
theorem symmDiff_right_involutive (a : Ξ±) : Involutive (a β Β·) :=
symmDiff_symmDiff_cancel_left _
theorem symmDiff_left_injective (a : Ξ±) : Injective (Β· β a) :=
Function.Involutive.injective (symmDiff_left_involutive a)
theorem symmDiff_right_injective (a : Ξ±) : Injective (a β Β·) :=
Function.Involutive.injective (symmDiff_right_involutive _)
theorem symmDiff_left_surjective (a : Ξ±) : Surjective (Β· β a) :=
Function.Involutive.surjective (symmDiff_left_involutive _)
theorem symmDiff_right_surjective (a : Ξ±) : Surjective (a β Β·) :=
Function.Involutive.surjective (symmDiff_right_involutive _)
variable {a b c}
@[simp]
theorem symmDiff_left_inj : a β b = c β b β a = c :=
(symmDiff_left_injective _).eq_iff
@[simp]
theorem symmDiff_right_inj : a β b = a β c β b = c :=
(symmDiff_right_injective _).eq_iff
@[simp]
theorem symmDiff_eq_left : a β b = a β b = β₯ :=
calc
a β b = a β a β b = a β β₯ := by rw [symmDiff_bot]
_ β b = β₯ := by rw [symmDiff_right_inj]
@[simp]
theorem symmDiff_eq_right : a β b = b β a = β₯ := by rw [symmDiff_comm, symmDiff_eq_left]
protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) :
Disjoint (a β b) c := by
rw [symmDiff_eq_sup_sdiff_inf]
exact (ha.sup_left hb).disjoint_sdiff_left
protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) :
Disjoint a (b β c) :=
(ha.symm.symmDiff_left hb.symm).symm
theorem symmDiff_eq_iff_sdiff_eq (ha : a β€ c) : a β b = c β c \ a = b := by
rw [β symmDiff_of_le ha]
exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm
end GeneralizedBooleanAlgebra
section BooleanAlgebra
variable [BooleanAlgebra Ξ±] (a b c d : Ξ±)
/-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to
the `GeneralizedBooleanAlgebra` ones -/
section CogeneralizedBooleanAlgebra
@[simp]
theorem inf_himp_bihimp : a β b β¨ a β b = a β b :=
@sup_sdiff_symmDiff Ξ±α΅α΅ _ _ _
theorem codisjoint_bihimp_sup : Codisjoint (a β b) (a β b) :=
@disjoint_symmDiff_inf Ξ±α΅α΅ _ _ _
@[simp]
theorem himp_bihimp_left : a β¨ a β b = a β¨ b :=
@symmDiff_sdiff_left Ξ±α΅α΅ _ _ _
@[simp]
theorem himp_bihimp_right : b β¨ a β b = b β¨ a :=
@symmDiff_sdiff_right Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_himp_left : a β b β¨ a = a β b :=
@sdiff_symmDiff_left Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_himp_right : a β b β¨ b = a β b :=
@sdiff_symmDiff_right Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_eq_inf : a β b = a β b β Codisjoint a b :=
@symmDiff_eq_sup Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_le_iff_left : a β b β€ a β Codisjoint a b :=
@le_symmDiff_iff_left Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_le_iff_right : a β b β€ b β Codisjoint a b :=
@le_symmDiff_iff_right Ξ±α΅α΅ _ _ _
theorem bihimp_assoc : a β b β c = a β (b β c) :=
@symmDiff_assoc Ξ±α΅α΅ _ _ _ _
instance bihimp_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· β Β·) :=
β¨bihimp_assocβ©
theorem bihimp_left_comm : a β (b β c) = b β (a β c) := by simp_rw [β bihimp_assoc, bihimp_comm]
theorem bihimp_right_comm : a β b β c = a β c β b := by simp_rw [bihimp_assoc, bihimp_comm]
theorem bihimp_bihimp_bihimp_comm : a β b β (c β d) = a β c β (b β d) := by
simp_rw [bihimp_assoc, bihimp_left_comm]
@[simp]
theorem bihimp_bihimp_cancel_left : a β (a β b) = b := by simp [β bihimp_assoc]
@[simp]
theorem bihimp_bihimp_cancel_right : b β a β a = b := by simp [bihimp_assoc]
@[simp]
theorem bihimp_bihimp_self : a β b β a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left]
theorem bihimp_left_involutive (a : Ξ±) : Involutive (Β· β a) :=
bihimp_bihimp_cancel_right _
theorem bihimp_right_involutive (a : Ξ±) : Involutive (a β Β·) :=
bihimp_bihimp_cancel_left _
theorem bihimp_left_injective (a : Ξ±) : Injective (Β· β a) :=
@symmDiff_left_injective Ξ±α΅α΅ _ _
theorem bihimp_right_injective (a : Ξ±) : Injective (a β Β·) :=
@symmDiff_right_injective Ξ±α΅α΅ _ _
theorem bihimp_left_surjective (a : Ξ±) : Surjective (Β· β a) :=
@symmDiff_left_surjective Ξ±α΅α΅ _ _
theorem bihimp_right_surjective (a : Ξ±) : Surjective (a β Β·) :=
@symmDiff_right_surjective Ξ±α΅α΅ _ _
variable {a b c}
@[simp]
theorem bihimp_left_inj : a β b = c β b β a = c :=
(bihimp_left_injective _).eq_iff
@[simp]
theorem bihimp_right_inj : a β b = a β c β b = c :=
(bihimp_right_injective _).eq_iff
@[simp]
theorem bihimp_eq_left : a β b = a β b = β€ :=
@symmDiff_eq_left Ξ±α΅α΅ _ _ _
@[simp]
theorem bihimp_eq_right : a β b = b β a = β€ :=
@symmDiff_eq_right Ξ±α΅α΅ _ _ _
protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) :
Codisjoint (a β b) c :=
(ha.inf_left hb).mono_left inf_le_bihimp
protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) :
Codisjoint a (b β c) :=
(ha.inf_right hb).mono_right inf_le_bihimp
end CogeneralizedBooleanAlgebra
theorem symmDiff_eq : a β b = a β bαΆ β b β aαΆ := by simp only [(Β· β Β·), sdiff_eq]
theorem bihimp_eq : a β b = (a β bαΆ) β (b β aαΆ) := by simp only [(Β· β Β·), himp_eq]
theorem symmDiff_eq' : a β b = (a β b) β (aαΆ β bαΆ) := by
rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf]
theorem bihimp_eq' : a β b = a β b β aαΆ β bαΆ :=
@symmDiff_eq' Ξ±α΅α΅ _ _ _
theorem symmDiff_top : a β β€ = aαΆ :=
symmDiff_top' _
theorem top_symmDiff : β€ β a = aαΆ :=
top_symmDiff' _
@[simp]
theorem compl_symmDiff : (a β b)αΆ = a β b := by
simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm]
@[simp]
theorem compl_bihimp : (a β b)αΆ = a β b :=
@compl_symmDiff Ξ±α΅α΅ _ _ _
@[simp]
theorem compl_symmDiff_compl : aαΆ β bαΆ = a β b :=
(sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq]
@[simp]
theorem compl_bihimp_compl : aαΆ β bαΆ = a β b :=
@compl_symmDiff_compl Ξ±α΅α΅ _ _ _
@[simp]
theorem symmDiff_eq_top : a β b = β€ β IsCompl a b := by
rw [symmDiff_eq', β compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff,
codisjoint_iff, and_comm]
@[simp]
theorem bihimp_eq_bot : a β b = β₯ β IsCompl a b := by
rw [bihimp_eq', β compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff,
codisjoint_iff]
@[simp]
theorem compl_symmDiff_self : aαΆ β a = β€ :=
hnot_symmDiff_self _
@[simp]
theorem symmDiff_compl_self : a β aαΆ = β€ :=
symmDiff_hnot_self _
theorem symmDiff_symmDiff_right' :
a β (b β c) = a β b β c β a β bαΆ β cαΆ β aαΆ β b β cαΆ β aαΆ β bαΆ β c :=
calc
a β (b β c) = a β (b β c β bαΆ β cαΆ) β (b β cαΆ β c β bαΆ) β aαΆ := by
{ rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] }
_ = a β b β c β a β bαΆ β cαΆ β b β cαΆ β aαΆ β c β bαΆ β aαΆ := by
{ rw [inf_sup_left, inf_sup_right, β sup_assoc, β inf_assoc, β inf_assoc] }
_ = a β b β c β a β bαΆ β cαΆ β aαΆ β b β cαΆ β aαΆ β bαΆ β c := (by
congr 1
Β· congr 1
rw [inf_comm, inf_assoc]
Β· apply inf_left_right_swap)
variable {a b c}
theorem Disjoint.le_symmDiff_sup_symmDiff_left (h : Disjoint a b) : c β€ a β c β b β c := by
trans c \ (a β b)
Β· rw [h.eq_bot, sdiff_bot]
Β· rw [sdiff_inf]
exact sup_le_sup le_sup_right le_sup_right
theorem Disjoint.le_symmDiff_sup_symmDiff_right (h : Disjoint b c) : a β€ a β b β a β c := by
simp_rw [symmDiff_comm a]
exact h.le_symmDiff_sup_symmDiff_left
theorem Codisjoint.bihimp_inf_bihimp_le_left (h : Codisjoint a b) : a β c β b β c β€ c :=
h.dual.le_symmDiff_sup_symmDiff_left
theorem Codisjoint.bihimp_inf_bihimp_le_right (h : Codisjoint b c) : a β b β a β c β€ a :=
h.dual.le_symmDiff_sup_symmDiff_right
end BooleanAlgebra
/-! ### Prod -/
section Prod
@[simp]
theorem symmDiff_fst [GeneralizedCoheytingAlgebra Ξ±] [GeneralizedCoheytingAlgebra Ξ²]
(a b : Ξ± Γ Ξ²) : (a β b).1 = a.1 β b.1 :=
rfl
@[simp]
theorem symmDiff_snd [GeneralizedCoheytingAlgebra Ξ±] [GeneralizedCoheytingAlgebra Ξ²]
(a b : Ξ± Γ Ξ²) : (a β b).2 = a.2 β b.2 :=
rfl
@[simp]
theorem bihimp_fst [GeneralizedHeytingAlgebra Ξ±] [GeneralizedHeytingAlgebra Ξ²] (a b : Ξ± Γ Ξ²) :
(a β b).1 = a.1 β b.1 :=
rfl
@[simp]
theorem bihimp_snd [GeneralizedHeytingAlgebra Ξ±] [GeneralizedHeytingAlgebra Ξ²] (a b : Ξ± Γ Ξ²) :
(a β b).2 = a.2 β b.2 :=
rfl
end Prod
/-! ### Pi -/
namespace Pi
theorem symmDiff_def [β i, GeneralizedCoheytingAlgebra (Ο i)] (a b : β i, Ο i) :
a β b = fun i => a i β b i :=
rfl
theorem bihimp_def [β i, GeneralizedHeytingAlgebra (Ο i)] (a b : β i, Ο i) :
a β b = fun i => a i β b i :=
rfl
@[simp]
theorem symmDiff_apply [β i, GeneralizedCoheytingAlgebra (Ο i)] (a b : β i, Ο i) (i : ΞΉ) :
(a β b) i = a i β b i :=
rfl
@[simp]
theorem bihimp_apply [β i, GeneralizedHeytingAlgebra (Ο i)] (a b : β i, Ο i) (i : ΞΉ) :
(a β b) i = a i β b i :=
rfl
end Pi
| Mathlib/Order/SymmDiff.lean | 749 | 750 | |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : β) :
IsCauSeq abs fun n => β m β range n, βz ^ m / m.factorialβ :=
let β¨n, hnβ© := exists_nat_gt βzβ
have hn0 : (0 : β) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (βzβ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iffβ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
β div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : β) : IsCauSeq (βΒ·β) fun n => β m β range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : β) : CauSeq β (βΒ·β) :=
β¨fun n => β m β range n, z ^ m / m.factorial, isCauSeq_exp zβ©
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : β) : β :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : β) : β :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : β)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun Ξ΅ Ξ΅0 => β¨1, fun j hj => ?_β©
convert (config := .unfoldSameFun) Ξ΅0 -- Ξ΅0 : Ξ΅ > 0 but goal is _ < Ξ΅
rcases j with - | j
Β· exact absurd hj (not_le_of_gt zero_lt_one)
Β· dsimp [exp']
induction' j with j ih
Β· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
Β· rw [β ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : β j : β, (β m β range j, (x + y) ^ m / m.factorial) =
β i β range j, β k β range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have hβ : (m.choose I : β) β 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have hβ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [β hβ, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : β), mul_assoc, mul_left_comm (m.choose I : β)β»ΒΉ,
mul_comm (m.choose I : β)]
rw [inv_mul_cancelβ hβ]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative β` to `β` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative β) β :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List β) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative β) expMonoidHom l
theorem exp_multiset_sum (s : Multiset β) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative β) β _ _ expMonoidHom s
theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) :
exp (β x β s, f x) = β x β s, exp (f x) :=
map_prod (Ξ² := Multiplicative β) expMonoidHom f s
lemma exp_nsmul (x : β) (n : β) : exp (n β’ x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative β) β _ _ expMonoidHom _ _
theorem exp_nat_mul (x : β) : β n : β, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, β exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x β 0 := fun h =>
zero_ne_one (Ξ± := β) <| by rw [β exp_zero, β add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)β»ΒΉ := by
rw [β mul_right_inj' (exp_ne_zero x), β exp_add]; simp [mul_inv_cancelβ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : β) (n : β€) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
Β· simp [exp_nat_mul]
Β· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [β lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_divβ, map_pow, β ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : β) : ((exp x).re : β) = exp x :=
conj_eq_iff_re.1 <| by rw [β exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : β) : (Real.exp x : β) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : β) : (exp x).im = 0 := by rw [β ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : β) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : β)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative β` to `β` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative β) β :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List β) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative β) expMonoidHom l
theorem exp_multiset_sum (s : Multiset β) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative β) β _ _ expMonoidHom s
theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β β) :
exp (β x β s, f x) = β x β s, exp (f x) :=
map_prod (Ξ² := Multiplicative β) expMonoidHom f s
lemma exp_nsmul (x : β) (n : β) : exp (n β’ x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative β) β _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : β) (n : β) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x β 0 := fun h =>
exp_ne_zero x <| by rw [exp, β ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)β»ΒΉ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : β} (hx : 0 β€ x) (n : β) : β i β range n, x ^ i / i ! β€ exp x :=
calc
β i β range n, x ^ i / i ! β€ lim (β¨_, isCauSeq_re (exp' x)β© : CauSeq β abs) := by
refine le_lim (CauSeq.le_of_exists β¨n, fun j hj => ?_β©)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ β¦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, β cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 β€ x) (n : β) : x ^ n / n ! β€ exp x :=
calc
x ^ n / n ! β€ β k β range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k β¦ x ^ k / k !) (fun k _ β¦ by positivity) (self_mem_range_succ n)
_ β€ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : β} (hx : 0 β€ x) : 1 + x + x ^ 2 / 2 β€ exp x :=
calc
1 + x + x ^ 2 / 2 = β i β range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ β€ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : β} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : β} (hx : 0 β€ x) : x + 1 β€ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
Β· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : β} (hx : 0 β€ x) : 1 β€ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : β) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one β one_le_exp) fun h => by
rw [β neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : β) : 0 β€ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : β) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : β) : exp |x| β€ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [β sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : β} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : β} (h : x β€ y) : exp x β€ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : β} : exp x < exp y β x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : β} : exp x β€ exp y β x β€ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : β} : exp x = exp y β x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 β x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : β} : 1 < exp x β 0 < x := by rw [β exp_zero, exp_lt_exp]
@[bound] private alias β¨_, Bound.one_lt_exp_of_posβ© := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : β} : exp x < 1 β x < 0 := by rw [β exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : β} : exp x β€ 1 β x β€ 0 :=
exp_zero βΈ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : β} : 1 β€ exp x β 0 β€ x :=
exp_zero βΈ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±]
(n j : β) (hn : 0 < n) :
(β m β range j with n β€ m, (1 / m.factorial : Ξ±)) β€ n.succ / (n.factorial * n) :=
calc
(β m β range j with n β€ m, (1 / m.factorial : Ξ±)) =
β m β range (j - n), (1 / ((m + n).factorial : Ξ±)) := by
refine sum_nbij' (Β· - n) (Β· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ β€ β m β range (j - n), ((n.factorial : Ξ±) * (n.succ : Ξ±) ^ m)β»ΒΉ := by
simp_rw [one_div]
gcongr
rw [β Nat.cast_pow, β Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : Ξ±)β»ΒΉ * β m β range (j - n), (n.succ : Ξ±)β»ΒΉ ^ m := by
simp [mul_inv, β mul_sum, β sum_mul, mul_comm, inv_pow]
_ = ((n.succ : Ξ±) - n.succ * (n.succ : Ξ±)β»ΒΉ ^ (j - n)) / (n.factorial * n) := by
have hβ : (n.succ : Ξ±) β 1 :=
@Nat.cast_one Ξ± _ βΈ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have hβ : (n.succ : Ξ±) β 0 := by positivity
have hβ : (n.factorial * n : Ξ±) β 0 := by positivity
have hβ : (n.succ - 1 : Ξ±) = n := by simp
rw [geom_sum_inv hβ hβ, eq_div_iff_mul_eq hβ, mul_comm _ (n.factorial * n : Ξ±),
β mul_assoc (n.factorialβ»ΒΉ : Ξ±), β mul_inv_rev, hβ, β mul_assoc (n.factorial * n : Ξ±),
mul_comm (n : Ξ±) n.factorial, mul_inv_cancelβ hβ, one_mul, mul_comm]
_ β€ n.succ / (n.factorial * n : Ξ±) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : β} (hx : βxβ β€ 1) {n : β} (hn : 0 < n) :
βexp x - β m β range n, x ^ m / m.factorialβ β€
βxβ ^ n * ((n.succ : β) * (n.factorial * n : β)β»ΒΉ) := by
rw [β lim_const (abv := norm) (β m β range n, _), exp, sub_eq_add_neg,
β lim_neg, lim_add, β lim_norm]
refine lim_le (CauSeq.le_of_exists β¨n, fun j hj => ?_β©)
simp_rw [β sub_eq_add_neg]
show
β(β m β range j, x ^ m / m.factorial) - β m β range n, x ^ m / m.factorialβ β€
βxβ ^ n * ((n.succ : β) * (n.factorial * n : β)β»ΒΉ)
rw [sum_range_sub_sum_range hj]
calc
ββ m β range j with n β€ m, (x ^ m / m.factorial : β)β
= ββ m β range j with n β€ m, (x ^ n * (x ^ (m - n) / m.factorial) : β)β := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [β mul_div_assoc, β pow_add, add_tsub_cancel_of_le hm.2]
_ β€ β m β range j with n β€ m, βx ^ n * (x ^ (m - n) / m.factorial)β :=
IsAbsoluteValue.abv_sum norm ..
_ β€ β m β range j with n β€ m, βxβ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_oneβ (norm_nonneg _) hx
_ = βxβ ^ n * β m β range j with n β€ m, (1 / m.factorial : β) := by
simp [abs_mul, abv_pow abs, abs_div, β mul_sum]
_ β€ βxβ ^ n * (n.succ * (n.factorial * n : β)β»ΒΉ) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : β} {n : β} (hx : βxβ / n.succ β€ 1 / 2) :
βexp x - β m β range n, x ^ m / m.factorialβ β€ βxβ ^ n / n.factorial * 2 := by
rw [β lim_const (abv := norm) (β m β range n, _),
exp, sub_eq_add_neg, β lim_neg, lim_add, β lim_norm]
refine lim_le (CauSeq.le_of_exists β¨n, fun j hj => ?_β©)
simp_rw [β sub_eq_add_neg]
show β(β m β range j, x ^ m / m.factorial) - β m β range n, x ^ m / m.factorialβ β€
βxβ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
| calc
| Mathlib/Data/Complex/Exponential.lean | 409 | 409 |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Tape
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.PFun
import Mathlib.Computability.PostTuringMachine
/-!
# Turing machines
The files `PostTuringMachine.lean` and `TuringMachine.lean` define
a sequence of simple machine languages, starting with Turing machines and working
up to more complex languages based on Wang B-machines.
`PostTuringMachine.lean` covers the TM0 model and TM1 model;
`TuringMachine.lean` adds the TM2 model.
## Naming conventions
Each model of computation in this file shares a naming convention for the elements of a model of
computation. These are the parameters for the language:
* `Ξ` is the alphabet on the tape.
* `Ξ` is the set of labels, or internal machine states.
* `Ο` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and
later models achieve this by mixing it into `Ξ`.
* `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks.
All of these variables denote "essentially finite" types, but for technical reasons it is
convenient to allow them to be infinite anyway. When using an infinite type, we will be interested
to prove that only finitely many values of the type are ever interacted with.
Given these parameters, there are a few common structures for the model that arise:
* `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is
finite, and for later models it is an infinite inductive type representing "possible program
texts".
* `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with
its environment.
* `Machine` is the set of all machines in the model. Usually this is approximately a function
`Ξ β Stmt`, although different models have different ways of halting and other actions.
* `step : Cfg β Option Cfg` is the function that describes how the state evolves over one step.
If `step c = none`, then `c` is a terminal state, and the result of the computation is read off
from `c`. Because of the type of `step`, these models are all deterministic by construction.
* `init : Input β Cfg` sets up the initial state. The type `Input` depends on the model;
in most cases it is `List Ξ`.
* `eval : Machine β Input β Part Output`, given a machine `M` and input `i`, starts from
`init i`, runs `step` until it reaches an output, and then applies a function `Cfg β Output` to
the final state to obtain the result. The type `Output` depends on the model.
* `Supports : Machine β Finset Ξ β Prop` asserts that a machine `M` starts in `S : Finset Ξ`, and
can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input
cannot depend on its values outside `S`. We use this to allow `Ξ` to be an infinite set when
convenient, and prove that only finitely many of these states are actually accessible. This
formalizes "essentially finite" mentioned above.
-/
assert_not_exists MonoidWithZero
open List (Vector)
open Relation
open Nat (iterate)
open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply'
iterate_zero_apply)
namespace Turing
/-!
## The TM2 model
The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite)
collection of stacks, each with elements of different types (the alphabet of stack `k : K` is
`Ξ k`). The statements are:
* `push k (f : Ο β Ξ k) q` puts `f a` on the `k`-th stack, then does `q`.
* `pop k (f : Ο β Option (Ξ k) β Ο) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, and removes this element from the stack, then does `q`.
* `peek k (f : Ο β Option (Ξ k) β Ο) q` changes the state to `f a (S k).head`, where `S k` is the
value of the `k`-th stack, then does `q`.
* `load (f : Ο β Ο) q` reads nothing but applies `f` to the internal state, then does `q`.
* `branch (f : Ο β Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`.
* `goto (f : Ο β Ξ)` jumps to label `f a`.
* `halt` halts on the next step.
The configuration is a tuple `(l, var, stk)` where `l : Option Ξ` is the current label to run or
`none` for the halting state, `var : Ο` is the (finite) internal state, and `stk : β k, List (Ξ k)`
is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not
`ListBlank`s, they have definite ends that can be detected by the `pop` command.)
Given a designated stack `k` and a value `L : List (Ξ k)`, the initial configuration has all the
stacks empty except the designated "input" stack; in `eval` this designated stack also functions
as the output stack.
-/
namespace TM2
variable {K : Type*}
-- Index type of stacks
variable (Ξ : K β Type*)
-- Type of stack elements
variable (Ξ : Type*)
-- Type of function labels
variable (Ο : Type*)
-- Type of variable settings
/-- The TM2 model removes the tape entirely from the TM1 model,
replacing it with an arbitrary (finite) collection of stacks.
The operation `push` puts an element on one of the stacks,
and `pop` removes an element from a stack (and modifying the
internal state based on the result). `peek` modifies the
internal state but does not remove an element. -/
inductive Stmt
| push : β k, (Ο β Ξ k) β Stmt β Stmt
| peek : β k, (Ο β Option (Ξ k) β Ο) β Stmt β Stmt
| pop : β k, (Ο β Option (Ξ k) β Ο) β Stmt β Stmt
| load : (Ο β Ο) β Stmt β Stmt
| branch : (Ο β Bool) β Stmt β Stmt β Stmt
| goto : (Ο β Ξ) β Stmt
| halt : Stmt
open Stmt
instance Stmt.inhabited : Inhabited (Stmt Ξ Ξ Ο) :=
β¨haltβ©
/-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of
local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite
size.) -/
structure Cfg where
/-- The current label to run (or `none` for the halting state) -/
l : Option Ξ
/-- The internal state -/
var : Ο
/-- The (finite) collection of internal stacks -/
stk : β k, List (Ξ k)
instance Cfg.inhabited [Inhabited Ο] : Inhabited (Cfg Ξ Ξ Ο) :=
β¨β¨default, default, defaultβ©β©
variable {Ξ Ξ Ο}
section
variable [DecidableEq K]
/-- The step function for the TM2 model. -/
def stepAux : Stmt Ξ Ξ Ο β Ο β (β k, List (Ξ k)) β Cfg Ξ Ξ Ο
| push k f q, v, S => stepAux q v (update S k (f v :: S k))
| peek k f q, v, S => stepAux q (f v (S k).head?) S
| pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail)
| load a q, v, S => stepAux q (a v) S
| branch f qβ qβ, v, S => cond (f v) (stepAux qβ v S) (stepAux qβ v S)
| goto f, v, S => β¨some (f v), v, Sβ©
| halt, v, S => β¨none, v, Sβ©
/-- The step function for the TM2 model. -/
def step (M : Ξ β Stmt Ξ Ξ Ο) : Cfg Ξ Ξ Ο β Option (Cfg Ξ Ξ Ο)
| β¨none, _, _β© => none
| β¨some l, v, Sβ© => some (stepAux (M l) v S)
attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3
stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2
/-- The (reflexive) reachability relation for the TM2 model. -/
def Reaches (M : Ξ β Stmt Ξ Ξ Ο) : Cfg Ξ Ξ Ο β Cfg Ξ Ξ Ο β Prop :=
ReflTransGen fun a b β¦ b β step M a
end
/-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/
def SupportsStmt (S : Finset Ξ) : Stmt Ξ Ξ Ο β Prop
| push _ _ q => SupportsStmt S q
| peek _ _ q => SupportsStmt S q
| pop _ _ q => SupportsStmt S q
| load _ q => SupportsStmt S q
| branch _ qβ qβ => SupportsStmt S qβ β§ SupportsStmt S qβ
| goto l => β v, l v β S
| halt => True
section
open scoped Classical in
/-- The set of subtree statements in a statement. -/
noncomputable def stmtsβ : Stmt Ξ Ξ Ο β Finset (Stmt Ξ Ξ Ο)
| Q@(push _ _ q) => insert Q (stmtsβ q)
| Q@(peek _ _ q) => insert Q (stmtsβ q)
| Q@(pop _ _ q) => insert Q (stmtsβ q)
| Q@(load _ q) => insert Q (stmtsβ q)
| Q@(branch _ qβ qβ) => insert Q (stmtsβ qβ βͺ stmtsβ qβ)
| Q@(goto _) => {Q}
| Q@halt => {Q}
theorem stmtsβ_self {q : Stmt Ξ Ξ Ο} : q β stmtsβ q := by
cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmtsβ]
theorem stmtsβ_trans {qβ qβ : Stmt Ξ Ξ Ο} : qβ β stmtsβ qβ β stmtsβ qβ β stmtsβ qβ := by
classical
intro hββ qβ hββ
induction qβ with (
simp only [stmtsβ] at hββ β’
simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at hββ)
| branch f qβ qβ IHβ IHβ =>
rcases hββ with (rfl | hββ | hββ)
Β· unfold stmtsβ at hββ
exact hββ
Β· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IHβ hββ))
Β· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IHβ hββ))
| goto l => subst hββ; exact hββ
| halt => subst hββ; exact hββ
| load _ q IH | _ _ _ q IH =>
rcases hββ with (rfl | hββ)
Β· unfold stmtsβ at hββ
exact hββ
Β· exact Finset.mem_insert_of_mem (IH hββ)
theorem stmtsβ_supportsStmt_mono {S : Finset Ξ} {qβ qβ : Stmt Ξ Ξ Ο} (h : qβ β stmtsβ qβ)
(hs : SupportsStmt S qβ) : SupportsStmt S qβ := by
induction qβ with
simp only [stmtsβ, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton]
at h hs
| branch f qβ qβ IHβ IHβ => rcases h with (rfl | h | h); exacts [hs, IHβ h hs.1, IHβ h hs.2]
| goto l => subst h; exact hs
| halt => subst h; trivial
| load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs]
open scoped Classical in
/-- The set of statements accessible from initial set `S` of labels. -/
noncomputable def stmts (M : Ξ β Stmt Ξ Ξ Ο) (S : Finset Ξ) : Finset (Option (Stmt Ξ Ξ Ο)) :=
Finset.insertNone (S.biUnion fun q β¦ stmtsβ (M q))
theorem stmts_trans {M : Ξ β Stmt Ξ Ξ Ο} {S : Finset Ξ} {qβ qβ : Stmt Ξ Ξ Ο} (hβ : qβ β stmtsβ qβ) :
some qβ β stmts M S β some qβ β stmts M S := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls hβ β¦ β¨_, ls, stmtsβ_trans hβ hββ©
end
variable [Inhabited Ξ]
/-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in
`S` jump only to other states in `S`. -/
def Supports (M : Ξ β Stmt Ξ Ξ Ο) (S : Finset Ξ) :=
default β S β§ β q β S, SupportsStmt S (M q)
theorem stmts_supportsStmt {M : Ξ β Stmt Ξ Ξ Ο} {S : Finset Ξ} {q : Stmt Ξ Ξ Ο}
(ss : Supports M S) : some q β stmts M S β SupportsStmt S q := by
simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq,
forall_eq', exists_imp, and_imp]
exact fun l ls h β¦ stmtsβ_supportsStmt_mono h (ss.2 _ ls)
variable [DecidableEq K]
theorem step_supports (M : Ξ β Stmt Ξ Ξ Ο) {S : Finset Ξ} (ss : Supports M S) :
β {c c' : Cfg Ξ Ξ Ο}, c' β step M c β c.l β Finset.insertNone S β c'.l β Finset.insertNone S
| β¨some lβ, v, Tβ©, c', hβ, hβ => by
replace hβ := ss.2 _ (Finset.some_mem_insertNone.1 hβ)
simp only [step, Option.mem_def, Option.some.injEq] at hβ; subst c'
revert hβ; induction M lβ generalizing v T with intro hs
| branch p qβ' qβ' IHβ IHβ =>
unfold stepAux; cases p v
Β· exact IHβ _ _ hs.2
Β· exact IHβ _ _ hs.1
| goto => exact Finset.some_mem_insertNone.2 (hs _)
| halt => apply Multiset.mem_cons_self
| load _ _ IH | _ _ _ _ IH => exact IH _ _ hs
variable [Inhabited Ο]
/-- The initial state of the TM2 model. The input is provided on a designated stack. -/
def init (k : K) (L : List (Ξ k)) : Cfg Ξ Ξ Ο :=
β¨some default, default, update (fun _ β¦ []) k Lβ©
/-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/
def eval (M : Ξ β Stmt Ξ Ξ Ο) (k : K) (L : List (Ξ k)) : Part (List (Ξ k)) :=
(Turing.eval (step M) (init k L)).map fun c β¦ c.stk k
end TM2
/-!
## TM2 emulator in TM1
To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a
TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of
stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack
1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this:
```
bottom: ... | _ | T | _ | _ | _ | _ | ...
stack 1: ... | _ | b | a | _ | _ | _ | ...
stack 2: ... | _ | f | e | d | c | _ | ...
```
where a tape element is a vertical slice through the diagram. Here the alphabet is
`Ξ' := Bool Γ β k, Option (Ξ k)`, where:
* `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the
tail of all stacks. It is never modified.
* `stk k : Option (Ξ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is
the blank value). Note that the head of the stack is at the far end; this is so that push and pop
don't have to do any shifting.
In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions,
it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the
end of the appropriate stack, make its changes, and then return to the bottom. So the states are:
* `normal (l : Ξ)`: waiting at `bottom` to execute function `l`
* `go k (s : StAct k) (q : Stmtβ)`: travelling to the right to get to the end of stack `k` in
order to perform stack action `s`, and later continue with executing `q`
* `ret (q : Stmtβ)`: travelling to the left after having performed a stack action, and executing
`q` once we arrive
Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the
length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)`
steps to run when emulated in TM1, where `m` is the length of the input.
-/
namespace TM2to1
-- A displaced lemma proved in unnecessary generality
theorem stk_nth_val {K : Type*} {Ξ : K β Type*} {L : ListBlank (β k, Option (Ξ k))} {k S} (n)
(hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) :
L.nth n k = S.reverse[n]? := by
rw [β proj_map_nth, hL, β List.map_reverse, ListBlank.nth_mk,
List.getI_eq_iget_getElem?, List.getElem?_map]
cases S.reverse[n]? <;> rfl
variable (K : Type*)
variable (Ξ : K β Type*)
variable {Ξ Ο : Type*}
/-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom,
plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/
def Ξ' :=
| Bool Γ β k, Option (Ξ k)
variable {K Ξ}
instance Ξ'.inhabited : Inhabited (Ξ' K Ξ) :=
β¨β¨false, fun _ β¦ noneβ©β©
instance Ξ'.fintype [DecidableEq K] [Fintype K] [β k, Fintype (Ξ k)] : Fintype (Ξ' K Ξ) :=
instFintypeProd _ _
| Mathlib/Computability/TuringMachine.lean | 346 | 354 |
/-
Copyright (c) 2021 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory
deprecated_module (since := "2025-04-06")
| Mathlib/MeasureTheory/Integral/VitaliCaratheodory.lean | 93 | 152 | |
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * Ο`. For some purposes,
angles modulo `Ο` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `Ο` can be represented
modulo `2 * Ο` as equalities of `(2 : β€) β’ ΞΈ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace β V] [InnerProductSpace β V']
variable [Fact (finrank β V = 2)] [Fact (finrank β V' = 2)] (o : Orientation β V (Fin 2))
local notation "Ο" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * Ο`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
@[fun_prop]
theorem continuousAt_oangle {x : V Γ V} (hx1 : x.1 β 0) (hx2 : x.2 β 0) :
ContinuousAt (fun y : V Γ V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
Β· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuousβ).mul continuous_const)).continuousAt
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
| @[simp]
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 68 | 68 |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.InitTail
/-!
# Truncated Witt vectors
The ring of truncated Witt vectors (of length `n`) is a quotient of the ring of Witt vectors.
It retains the first `n` coefficients of each Witt vector.
In this file, we set up the basic quotient API for this ring.
The ring of Witt vectors is the projective limit of all the rings of truncated Witt vectors.
## Main declarations
- `TruncatedWittVector`: the underlying type of the ring of truncated Witt vectors
- `TruncatedWittVector.instCommRing`: the ring structure on truncated Witt vectors
- `WittVector.truncate`: the quotient homomorphism that truncates a Witt vector,
to obtain a truncated Witt vector
- `TruncatedWittVector.truncate`: the homomorphism that truncates
a truncated Witt vector of length `n` to one of length `m` (for some `m β€ n`)
- `WittVector.lift`: the unique ring homomorphism into the ring of Witt vectors
that is compatible with a family of ring homomorphisms to the truncated Witt vectors:
this realizes the ring of Witt vectors as projective limit of the rings of truncated Witt vectors
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open Function (Injective Surjective)
noncomputable section
variable {p : β} (n : β) (R : Type*)
local notation "π" => WittVector p -- type as `\bbW`
/-- A truncated Witt vector over `R` is a vector of elements of `R`,
i.e., the first `n` coefficients of a Witt vector.
We will define operations on this type that are compatible with the (untruncated) Witt
vector operations.
`TruncatedWittVector p n R` takes a parameter `p : β` that is not used in the definition.
In practice, this number `p` is assumed to be a prime number,
and under this assumption we construct a ring structure on `TruncatedWittVector p n R`.
(`TruncatedWittVector pβ n R` and `TruncatedWittVector pβ n R` are definitionally
equal as types but will have different ring operations.)
-/
@[nolint unusedArguments]
def TruncatedWittVector (_ : β) (n : β) (R : Type*) :=
Fin n β R
instance (p n : β) (R : Type*) [Inhabited R] : Inhabited (TruncatedWittVector p n R) :=
β¨fun _ => defaultβ©
variable {n R}
namespace TruncatedWittVector
variable (p) in
/-- Create a `TruncatedWittVector` from a vector `x`. -/
def mk (x : Fin n β R) : TruncatedWittVector p n R :=
x
/-- `x.coeff i` is the `i`th entry of `x`. -/
def coeff (i : Fin n) (x : TruncatedWittVector p n R) : R :=
x i
@[ext]
theorem ext {x y : TruncatedWittVector p n R} (h : β i, x.coeff i = y.coeff i) : x = y :=
funext h
@[simp]
theorem coeff_mk (x : Fin n β R) (i : Fin n) : (mk p x).coeff i = x i :=
rfl
@[simp]
theorem mk_coeff (x : TruncatedWittVector p n R) : (mk p fun i => x.coeff i) = x := by
ext i; rw [coeff_mk]
variable [CommRing R]
/-- We can turn a truncated Witt vector `x` into a Witt vector
by setting all coefficients after `x` to be 0.
-/
def out (x : TruncatedWittVector p n R) : π R :=
@WittVector.mk' p _ fun i => if h : i < n then x.coeff β¨i, hβ© else 0
@[simp]
theorem coeff_out (x : TruncatedWittVector p n R) (i : Fin n) : x.out.coeff i = x.coeff i := by
rw [out]; dsimp only; rw [dif_pos i.is_lt, Fin.eta]
theorem out_injective : Injective (@out p n R _) := by
intro x y h
ext i
rw [WittVector.ext_iff] at h
simpa only [coeff_out] using h βi
end TruncatedWittVector
namespace WittVector
variable (n)
section
/-- `truncateFun n x` uses the first `n` entries of `x` to construct a `TruncatedWittVector`,
which has the same base `p` as `x`.
This function is bundled into a ring homomorphism in `WittVector.truncate` -/
def truncateFun (x : π R) : TruncatedWittVector p n R :=
TruncatedWittVector.mk p fun i => x.coeff i
end
variable {n}
@[simp]
theorem coeff_truncateFun (x : π R) (i : Fin n) : (truncateFun n x).coeff i = x.coeff i := by
rw [truncateFun, TruncatedWittVector.coeff_mk]
variable [CommRing R]
@[simp]
theorem out_truncateFun (x : π R) : (truncateFun n x).out = init n x := by
ext i
dsimp [TruncatedWittVector.out, init, select, coeff_mk]
split_ifs with hi; swap; Β· rfl
rw [coeff_truncateFun, Fin.val_mk]
end WittVector
namespace TruncatedWittVector
variable [CommRing R]
@[simp]
theorem truncateFun_out (x : TruncatedWittVector p n R) : x.out.truncateFun n = x := by
simp only [WittVector.truncateFun, coeff_out, mk_coeff]
open WittVector
variable (p n R)
variable [Fact p.Prime]
instance : Zero (TruncatedWittVector p n R) :=
β¨truncateFun n 0β©
instance : One (TruncatedWittVector p n R) :=
β¨truncateFun n 1β©
instance : NatCast (TruncatedWittVector p n R) :=
β¨fun i => truncateFun n iβ©
instance : IntCast (TruncatedWittVector p n R) :=
β¨fun i => truncateFun n iβ©
instance : Add (TruncatedWittVector p n R) :=
β¨fun x y => truncateFun n (x.out + y.out)β©
instance : Mul (TruncatedWittVector p n R) :=
β¨fun x y => truncateFun n (x.out * y.out)β©
instance : Neg (TruncatedWittVector p n R) :=
β¨fun x => truncateFun n (-x.out)β©
instance : Sub (TruncatedWittVector p n R) :=
β¨fun x y => truncateFun n (x.out - y.out)β©
instance hasNatScalar : SMul β (TruncatedWittVector p n R) :=
β¨fun m x => truncateFun n (m β’ x.out)β©
instance hasIntScalar : SMul β€ (TruncatedWittVector p n R) :=
β¨fun m x => truncateFun n (m β’ x.out)β©
instance hasNatPow : Pow (TruncatedWittVector p n R) β :=
β¨fun x m => truncateFun n (x.out ^ m)β©
@[simp]
theorem coeff_zero (i : Fin n) : (0 : TruncatedWittVector p n R).coeff i = 0 := by
show coeff i (truncateFun _ 0 : TruncatedWittVector p n R) = 0
rw [coeff_truncateFun, WittVector.zero_coeff]
end TruncatedWittVector
/-- A macro tactic used to prove that `truncateFun` respects ring operations. -/
macro (name := witt_truncateFun_tac) "witt_truncateFun_tac" : tactic =>
`(tactic|
{ show _ = WittVector.truncateFun n _
apply TruncatedWittVector.out_injective
iterate rw [WittVector.out_truncateFun]
first
| rw [WittVector.init_add]
| rw [WittVector.init_mul]
| rw [WittVector.init_neg]
| rw [WittVector.init_sub]
| rw [WittVector.init_nsmul]
| rw [WittVector.init_zsmul]
| rw [WittVector.init_pow]})
namespace WittVector
variable (p n R)
variable [CommRing R]
theorem truncateFun_surjective : Surjective (@truncateFun p n R) :=
Function.RightInverse.surjective TruncatedWittVector.truncateFun_out
variable [Fact p.Prime]
@[simp]
theorem truncateFun_zero : truncateFun n (0 : π R) = 0 := rfl
@[simp]
theorem truncateFun_one : truncateFun n (1 : π R) = 1 := rfl
variable {p R}
@[simp]
theorem truncateFun_add (x y : π R) :
truncateFun n (x + y) = truncateFun n x + truncateFun n y := by
witt_truncateFun_tac
@[simp]
theorem truncateFun_mul (x y : π R) :
truncateFun n (x * y) = truncateFun n x * truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_neg (x : π R) : truncateFun n (-x) = -truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_sub (x y : π R) :
truncateFun n (x - y) = truncateFun n x - truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_nsmul (m : β) (x : π R) : truncateFun n (m β’ x) = m β’ truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_zsmul (m : β€) (x : π R) : truncateFun n (m β’ x) = m β’ truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_pow (x : π R) (m : β) : truncateFun n (x ^ m) = truncateFun n x ^ m := by
witt_truncateFun_tac
theorem truncateFun_natCast (m : β) : truncateFun n (m : π R) = m := rfl
theorem truncateFun_intCast (m : β€) : truncateFun n (m : π R) = m := rfl
end WittVector
namespace TruncatedWittVector
open WittVector
variable (p n R)
variable [CommRing R]
variable [Fact p.Prime]
instance instCommRing : CommRing (TruncatedWittVector p n R) :=
(truncateFun_surjective p n R).commRing _ (truncateFun_zero p n R) (truncateFun_one p n R)
(truncateFun_add n) (truncateFun_mul n) (truncateFun_neg n) (truncateFun_sub n)
(truncateFun_nsmul n) (truncateFun_zsmul n) (truncateFun_pow n) (truncateFun_natCast n)
(truncateFun_intCast n)
end TruncatedWittVector
namespace WittVector
open TruncatedWittVector
|
variable (n)
| Mathlib/RingTheory/WittVector/Truncated.lean | 277 | 278 |
/-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.GroupTheory.Index
/-!
# Complements
In this file we define the complement of a subgroup.
## Main definitions
- `Subgroup.IsComplement S T` where `S` and `T` are subsets of `G` states that every `g : G` can be
written uniquely as a product `s * t` for `s β S`, `t β T`.
- `H.LeftTransversal` where `H` is a subgroup of `G` is the type of all left-complements of `H`,
i.e. the set of all `S : Set G` that contain exactly one element of each left coset of `H`.
- `H.RightTransversal` where `H` is a subgroup of `G` is the set of all right-complements of `H`,
i.e. the set of all `T : Set G` that contain exactly one element of each right coset of `H`.
## Main results
- `isComplement'_of_coprime` : Subgroups of coprime order are complements.
-/
open Function Set
open scoped Pointwise
namespace Subgroup
variable {G : Type*} [Group G] (H K : Subgroup G) (S T : Set G)
/-- `S` and `T` are complements if `(*) : S Γ T β G` is a bijection.
This notion generalizes left transversals, right transversals, and complementary subgroups. -/
@[to_additive "`S` and `T` are complements if `(+) : S Γ T β G` is a bijection"]
def IsComplement : Prop :=
Function.Bijective fun x : S Γ T => x.1.1 * x.2.1
/-- `H` and `K` are complements if `(*) : H Γ K β G` is a bijection -/
@[to_additive "`H` and `K` are complements if `(+) : H Γ K β G` is a bijection"]
abbrev IsComplement' :=
IsComplement (H : Set G) (K : Set G)
/-- The set of left-complements of `T : Set G` -/
@[to_additive (attr := deprecated IsComplement (since := "2024-12-18"))
"The set of left-complements of `T : Set G`"]
def leftTransversals : Set (Set G) :=
{ S : Set G | IsComplement S T }
/-- The set of right-complements of `S : Set G` -/
@[to_additive (attr := deprecated IsComplement (since := "2024-12-18"))
"The set of right-complements of `S : Set G`"]
def rightTransversals : Set (Set G) :=
{ T : Set G | IsComplement S T }
variable {H K S T}
@[to_additive]
theorem isComplement'_def : IsComplement' H K β IsComplement (H : Set G) (K : Set G) :=
Iff.rfl
@[to_additive]
theorem isComplement_iff_existsUnique :
IsComplement S T β β g : G, β! x : S Γ T, x.1.1 * x.2.1 = g :=
Function.bijective_iff_existsUnique _
@[to_additive]
theorem IsComplement.existsUnique (h : IsComplement S T) (g : G) :
β! x : S Γ T, x.1.1 * x.2.1 = g :=
isComplement_iff_existsUnique.mp h g
@[to_additive]
theorem IsComplement'.symm (h : IsComplement' H K) : IsComplement' K H := by
let Ο : H Γ K β K Γ H :=
Equiv.mk (fun x => β¨x.2β»ΒΉ, x.1β»ΒΉβ©) (fun x => β¨x.2β»ΒΉ, x.1β»ΒΉβ©)
(fun x => Prod.ext (inv_inv _) (inv_inv _)) fun x => Prod.ext (inv_inv _) (inv_inv _)
let Ο : G β G := Equiv.mk (fun g : G => gβ»ΒΉ) (fun g : G => gβ»ΒΉ) inv_inv inv_inv
suffices hf : (Ο β fun x : H Γ K => x.1.1 * x.2.1) = (fun x : K Γ H => x.1.1 * x.2.1) β Ο by
rw [isComplement'_def, IsComplement, β Equiv.bijective_comp Ο]
apply (congr_arg Function.Bijective hf).mp -- Porting note: This was a `rw` in mathlib3
rwa [Ο.comp_bijective]
exact funext fun x => mul_inv_rev _ _
@[to_additive]
theorem isComplement'_comm : IsComplement' H K β IsComplement' K H :=
β¨IsComplement'.symm, IsComplement'.symmβ©
@[to_additive]
theorem isComplement_univ_singleton {g : G} : IsComplement (univ : Set G) {g} :=
β¨fun β¨_, _, rflβ© β¨_, _, rflβ© h => Prod.ext (Subtype.ext (mul_right_cancel h)) rfl, fun x =>
β¨β¨β¨x * gβ»ΒΉ, β¨β©β©, g, rflβ©, inv_mul_cancel_right x gβ©β©
@[to_additive]
theorem isComplement_singleton_univ {g : G} : IsComplement ({g} : Set G) univ :=
β¨fun β¨β¨_, rflβ©, _β© β¨β¨_, rflβ©, _β© h => Prod.ext rfl (Subtype.ext (mul_left_cancel h)), fun x =>
β¨β¨β¨g, rflβ©, gβ»ΒΉ * x, β¨β©β©, mul_inv_cancel_left g xβ©β©
@[to_additive]
theorem isComplement_singleton_left {g : G} : IsComplement {g} S β S = univ := by
refine
β¨fun h => top_le_iff.mp fun x _ => ?_, fun h => (congr_arg _ h).mpr isComplement_singleton_univβ©
obtain β¨β¨β¨z, rfl : z = gβ©, y, _β©, hyβ© := h.2 (g * x)
rwa [β mul_left_cancel hy]
@[to_additive]
theorem isComplement_singleton_right {g : G} : IsComplement S {g} β S = univ := by
refine
β¨fun h => top_le_iff.mp fun x _ => ?_, fun h => h βΈ isComplement_univ_singletonβ©
obtain β¨y, hyβ© := h.2 (x * g)
conv_rhs at hy => rw [β show y.2.1 = g from y.2.2]
rw [β mul_right_cancel hy]
exact y.1.2
@[to_additive]
theorem isComplement_univ_left : IsComplement univ S β β g : G, S = {g} := by
refine
β¨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr β¨?_, fun a ha b hb => ?_β©, ?_β©
Β· obtain β¨a, _β© := h.2 1
exact β¨a.2.1, a.2.2β©
Β· have : (β¨β¨_, mem_top aβ»ΒΉβ©, β¨a, haβ©β© : (β€ : Set G) Γ S) = β¨β¨_, mem_top bβ»ΒΉβ©, β¨b, hbβ©β© :=
h.1 ((inv_mul_cancel a).trans (inv_mul_cancel b).symm)
exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).2
Β· rintro β¨g, rflβ©
exact isComplement_univ_singleton
@[to_additive]
theorem isComplement_univ_right : IsComplement S univ β β g : G, S = {g} := by
refine
β¨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr β¨?_, fun a ha b hb => ?_β©, ?_β©
Β· obtain β¨a, _β© := h.2 1
exact β¨a.1.1, a.1.2β©
Β· have : (β¨β¨a, haβ©, β¨_, mem_top aβ»ΒΉβ©β© : S Γ (β€ : Set G)) = β¨β¨b, hbβ©, β¨_, mem_top bβ»ΒΉβ©β© :=
h.1 ((mul_inv_cancel a).trans (mul_inv_cancel b).symm)
exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).1
Β· rintro β¨g, rflβ©
exact isComplement_singleton_univ
@[to_additive]
lemma IsComplement.mul_eq (h : IsComplement S T) : S * T = univ :=
eq_univ_of_forall fun x β¦ by simpa [mem_mul] using (h.existsUnique x).exists
@[to_additive (attr := simp)]
lemma not_isComplement_empty_left : Β¬ IsComplement β
T :=
fun h β¦ by simpa [eq_comm (a := β
)] using h.mul_eq
@[to_additive (attr := simp)]
lemma not_isComplement_empty_right : Β¬ IsComplement S β
:=
fun h β¦ by simpa [eq_comm (a := β
)] using h.mul_eq
@[to_additive]
lemma IsComplement.nonempty_left (hst : IsComplement S T) : S.Nonempty := by
contrapose! hst; simp [hst]
@[to_additive]
lemma IsComplement.nonempty_right (hst : IsComplement S T) : T.Nonempty := by
contrapose! hst; simp [hst]
@[to_additive] lemma IsComplement.pairwiseDisjoint_smul (hst : IsComplement S T) :
S.PairwiseDisjoint (Β· β’ T) := fun a ha b hb hab β¦ disjoint_iff_forall_ne.2 <| by
rintro _ β¨c, hc, rflβ© _ β¨d, hd, rflβ©
exact hst.1.ne (aβ := (β¨a, haβ©, β¨c, hcβ©)) (aβ:= (β¨b, hbβ©, β¨d, hdβ©)) (by simp [hab])
@[to_additive AddSubgroup.IsComplement.card_mul_card]
lemma IsComplement.card_mul_card (h : IsComplement S T) : Nat.card S * Nat.card T = Nat.card G :=
(Nat.card_prod _ _).symm.trans <| Nat.card_congr <| Equiv.ofBijective _ h
@[to_additive]
theorem isComplement'_top_bot : IsComplement' (β€ : Subgroup G) β₯ :=
isComplement_univ_singleton
@[to_additive]
theorem isComplement'_bot_top : IsComplement' (β₯ : Subgroup G) β€ :=
isComplement_singleton_univ
@[to_additive (attr := simp)]
theorem isComplement'_bot_left : IsComplement' β₯ H β H = β€ :=
isComplement_singleton_left.trans coe_eq_univ
@[to_additive (attr := simp)]
theorem isComplement'_bot_right : IsComplement' H β₯ β H = β€ :=
isComplement_singleton_right.trans coe_eq_univ
@[to_additive (attr := simp)]
theorem isComplement'_top_left : IsComplement' β€ H β H = β₯ :=
isComplement_univ_left.trans coe_eq_singleton
@[to_additive (attr := simp)]
theorem isComplement'_top_right : IsComplement' H β€ β H = β₯ :=
isComplement_univ_right.trans coe_eq_singleton
@[to_additive]
lemma isComplement_iff_existsUnique_inv_mul_mem :
IsComplement S T β β g, β! s : S, (s : G)β»ΒΉ * g β T := by
convert isComplement_iff_existsUnique with g
constructor <;> rintro β¨x, hx, hx'β©
Β· exact β¨(x, β¨_, hxβ©), by simp, by aesopβ©
Β· exact β¨x.1, by simp [β hx], fun y hy β¦ (Prod.ext_iff.1 <| by simpa using hx' (y, β¨_, hyβ©)).1β©
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_iff_existsUnique_inv_mul_mem (since := "2024-12-18"))]
theorem mem_leftTransversals_iff_existsUnique_inv_mul_mem :
S β leftTransversals T β β g : G, β! s : S, (s : G)β»ΒΉ * g β T := by
rw [leftTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique]
refine β¨fun h g => ?_, fun h g => ?_β©
Β· obtain β¨x, h1, h2β© := h g
exact
β¨x.1, (congr_arg (Β· β T) (eq_inv_mul_of_mul_eq h1)).mp x.2.2, fun y hy =>
(Prod.ext_iff.mp (h2 β¨y, (βy)β»ΒΉ * g, hyβ© (mul_inv_cancel_left βy g))).1β©
Β· obtain β¨x, h1, h2β© := h g
refine β¨β¨x, (βx)β»ΒΉ * g, h1β©, mul_inv_cancel_left (βx) g, fun y hy => ?_β©
have hf := h2 y.1 ((congr_arg (Β· β T) (eq_inv_mul_of_mul_eq hy)).mp y.2.2)
exact Prod.ext hf (Subtype.ext (eq_inv_mul_of_mul_eq (hf βΈ hy)))
@[to_additive]
lemma isComplement_iff_existsUnique_mul_inv_mem :
IsComplement S T β β g, β! t : T, g * (t : G)β»ΒΉ β S := by
convert isComplement_iff_existsUnique with g
constructor <;> rintro β¨x, hx, hx'β©
Β· exact β¨(β¨_, hxβ©, x), by simp, by aesopβ©
Β· exact β¨x.2, by simp [β hx], fun y hy β¦ (Prod.ext_iff.1 <| by simpa using hx' (β¨_, hyβ©, y)).2β©
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_iff_existsUnique_mul_inv_mem (since := "2024-12-18"))]
theorem mem_rightTransversals_iff_existsUnique_mul_inv_mem :
S β rightTransversals T β β g : G, β! s : S, g * (s : G)β»ΒΉ β T := by
rw [rightTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique]
refine β¨fun h g => ?_, fun h g => ?_β©
Β· obtain β¨x, h1, h2β© := h g
exact
β¨x.2, (congr_arg (Β· β T) (eq_mul_inv_of_mul_eq h1)).mp x.1.2, fun y hy =>
(Prod.ext_iff.mp (h2 β¨β¨g * (βy)β»ΒΉ, hyβ©, yβ© (inv_mul_cancel_right g y))).2β©
Β· obtain β¨x, h1, h2β© := h g
refine β¨β¨β¨g * (βx)β»ΒΉ, h1β©, xβ©, inv_mul_cancel_right g x, fun y hy => ?_β©
have hf := h2 y.2 ((congr_arg (Β· β T) (eq_mul_inv_of_mul_eq hy)).mp y.1.2)
exact Prod.ext (Subtype.ext (eq_mul_inv_of_mul_eq (hf βΈ hy))) hf
@[to_additive]
lemma isComplement_subgroup_right_iff_existsUnique_quotientGroupMk :
IsComplement S H β β q : G β§Έ H, β! s : S, QuotientGroup.mk s.1 = q := by
simp_rw [isComplement_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, β QuotientGroup.eq,
QuotientGroup.forall_mk]
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_right_iff_existsUnique_quotientGroupMk
(since := "2024-12-18"))]
theorem mem_leftTransversals_iff_existsUnique_quotient_mk''_eq :
S β leftTransversals (H : Set G) β
β q : Quotient (QuotientGroup.leftRel H), β! s : S, Quotient.mk'' s.1 = q := by
simp_rw [mem_leftTransversals_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, β
QuotientGroup.eq]
exact β¨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)β©
set_option linter.docPrime false in
@[to_additive]
lemma isComplement_subgroup_left_iff_existsUnique_quotientMk'' :
IsComplement H T β
β q : Quotient (QuotientGroup.rightRel H), β! t : T, Quotient.mk'' t.1 = q := by
simp_rw [isComplement_iff_existsUnique_mul_inv_mem, SetLike.mem_coe,
β QuotientGroup.rightRel_apply, β Quotient.eq'', Quotient.forall]
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_left_iff_existsUnique_quotientMk''
(since := "2024-12-18"))]
theorem mem_rightTransversals_iff_existsUnique_quotient_mk''_eq :
S β rightTransversals (H : Set G) β
β q : Quotient (QuotientGroup.rightRel H), β! s : S, Quotient.mk'' s.1 = q := by
simp_rw [mem_rightTransversals_iff_existsUnique_mul_inv_mem, SetLike.mem_coe, β
QuotientGroup.rightRel_apply, β Quotient.eq'']
exact β¨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)β©
@[to_additive]
lemma isComplement_subgroup_right_iff_bijective :
IsComplement S H β Bijective (S.restrict (QuotientGroup.mk : G β G β§Έ H)) :=
isComplement_subgroup_right_iff_existsUnique_quotientGroupMk.trans
(bijective_iff_existsUnique (S.restrict QuotientGroup.mk)).symm
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_right_iff_bijective (since := "2024-12-18"))]
theorem mem_leftTransversals_iff_bijective :
S β leftTransversals (H : Set G) β
Function.Bijective (S.restrict (Quotient.mk'' : G β Quotient (QuotientGroup.leftRel H))) :=
mem_leftTransversals_iff_existsUnique_quotient_mk''_eq.trans
(Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm
@[to_additive]
lemma isComplement_subgroup_left_iff_bijective :
IsComplement H T β
Bijective (T.restrict (Quotient.mk'' : G β Quotient (QuotientGroup.rightRel H))) :=
isComplement_subgroup_left_iff_existsUnique_quotientMk''.trans
(bijective_iff_existsUnique (T.restrict Quotient.mk'')).symm
set_option linter.deprecated false in
@[to_additive
(attr := deprecated isComplement_subgroup_left_iff_bijective (since := "2024-12-18"))]
theorem mem_rightTransversals_iff_bijective :
S β rightTransversals (H : Set G) β
Function.Bijective (S.restrict (Quotient.mk'' : G β Quotient (QuotientGroup.rightRel H))) :=
mem_rightTransversals_iff_existsUnique_quotient_mk''_eq.trans
(Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm
@[to_additive]
lemma IsComplement.card_left (h : IsComplement S H) : Nat.card S = H.index :=
Nat.card_congr <| .ofBijective _ <| isComplement_subgroup_right_iff_bijective.mp h
set_option linter.deprecated false in
@[to_additive (attr := deprecated IsComplement.card_left (since := "2024-12-18"))]
theorem card_left_transversal (h : S β leftTransversals (H : Set G)) : Nat.card S = H.index :=
Nat.card_congr <| Equiv.ofBijective _ <| mem_leftTransversals_iff_bijective.mp h
@[to_additive]
lemma IsComplement.card_right (h : IsComplement H T) : Nat.card T = H.index :=
Nat.card_congr <| (Equiv.ofBijective _ <| isComplement_subgroup_left_iff_bijective.mp h).trans <|
QuotientGroup.quotientRightRelEquivQuotientLeftRel H
set_option linter.deprecated false in
@[to_additive (attr := deprecated IsComplement.card_right (since := "2024-12-18"))]
theorem card_right_transversal (h : S β rightTransversals (H : Set G)) : Nat.card S = H.index :=
Nat.card_congr <|
(Equiv.ofBijective _ <| mem_rightTransversals_iff_bijective.mp h).trans <|
QuotientGroup.quotientRightRelEquivQuotientLeftRel H
@[to_additive]
lemma isComplement_range_left {f : G β§Έ H β G} (hf : β q, β(f q) = q) :
IsComplement (range f) H := by
rw [isComplement_subgroup_right_iff_bijective]
refine β¨?_, fun q β¦ β¨β¨f q, q, rflβ©, hf qβ©β©
rintro β¨-, qβ, rflβ© β¨-, qβ, rflβ© h
exact Subtype.ext <| congr_arg f <| ((hf qβ).symm.trans h).trans (hf qβ)
set_option linter.deprecated false in
@[to_additive (attr := deprecated isComplement_range_left (since := "2024-12-18"))]
theorem range_mem_leftTransversals {f : G β§Έ H β G} (hf : β q, β(f q) = q) :
Set.range f β leftTransversals (H : Set G) :=
mem_leftTransversals_iff_bijective.mpr
β¨by rintro β¨-, qβ, rflβ© β¨-, qβ, rflβ© h
exact Subtype.ext <| congr_arg f <| ((hf qβ).symm.trans h).trans (hf qβ),
fun q => β¨β¨f q, q, rflβ©, hf qβ©β©
@[to_additive]
lemma isComplement_range_right {f : Quotient (QuotientGroup.rightRel H) β G}
(hf : β q, Quotient.mk'' (f q) = q) : IsComplement H (range f) := by
rw [isComplement_subgroup_left_iff_bijective]
refine β¨?_, fun q β¦ β¨β¨f q, q, rflβ©, hf qβ©β©
rintro β¨-, qβ, rflβ© β¨-, qβ, rflβ© h
exact Subtype.ext <| congr_arg f <| ((hf qβ).symm.trans h).trans (hf qβ)
set_option linter.deprecated false in
@[to_additive (attr := deprecated isComplement_range_right (since := "2024-12-18"))]
theorem range_mem_rightTransversals {f : Quotient (QuotientGroup.rightRel H) β G}
(hf : β q, Quotient.mk'' (f q) = q) : Set.range f β rightTransversals (H : Set G) :=
mem_rightTransversals_iff_bijective.mpr
β¨by rintro β¨-, qβ, rflβ© β¨-, qβ, rflβ© h
exact Subtype.ext <| congr_arg f <| ((hf qβ).symm.trans h).trans (hf qβ),
fun q => β¨β¨f q, q, rflβ©, hf qβ©β©
@[to_additive]
lemma exists_isComplement_left (H : Subgroup G) (g : G) : β S, IsComplement S H β§ g β S := by
classical
refine β¨Set.range (Function.update Quotient.out _ g), isComplement_range_left fun q β¦ ?_,
QuotientGroup.mk g, Function.update_self (Quotient.mk'' g) g Quotient.outβ©
by_cases hq : q = Quotient.mk'' g
Β· exact hq.symm βΈ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
Β· refine Function.update_of_ne ?_ g Quotient.out βΈ q.out_eq'
exact hq
set_option linter.deprecated false in
@[to_additive (attr := deprecated exists_isComplement_left (since := "2024-12-18"))]
lemma exists_left_transversal (H : Subgroup G) (g : G) :
β S β leftTransversals (H : Set G), g β S := by
classical
refine
β¨Set.range (Function.update Quotient.out _ g), range_mem_leftTransversals fun q => ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.outβ©
by_cases hq : q = Quotient.mk'' g
Β· exact hq.symm βΈ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
Β· refine (Function.update_of_ne ?_ g Quotient.out) βΈ q.out_eq'
exact hq
@[to_additive]
lemma exists_isComplement_right (H : Subgroup G) (g : G) :
β T, IsComplement H T β§ g β T := by
classical
refine β¨Set.range (Function.update Quotient.out _ g), isComplement_range_right fun q β¦ ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.outβ©
by_cases hq : q = Quotient.mk'' g
Β· exact hq.symm βΈ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
Β· refine Function.update_of_ne ?_ g Quotient.out βΈ q.out_eq'
exact hq
set_option linter.deprecated false in
@[to_additive (attr := deprecated exists_isComplement_right (since := "2024-12-18"))]
lemma exists_right_transversal (H : Subgroup G) (g : G) :
β S β rightTransversals (H : Set G), g β S := by
classical
refine
β¨Set.range (Function.update Quotient.out _ g), range_mem_rightTransversals fun q => ?_,
Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.outβ©
by_cases hq : q = Quotient.mk'' g
Β· exact hq.symm βΈ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out)
Β· exact Eq.trans (congr_arg _ (Function.update_of_ne hq g Quotient.out)) q.out_eq'
/-- Given two subgroups `H' β H`, there exists a left transversal to `H'` inside `H`. -/
@[to_additive "Given two subgroups `H' β H`, there exists a transversal to `H'` inside `H`"]
lemma exists_left_transversal_of_le {H' H : Subgroup G} (h : H' β€ H) :
β S : Set G, S * H' = H β§ Nat.card S * Nat.card H' = Nat.card H := by
let H'' : Subgroup H := H'.comap H.subtype
have : H' = H''.map H.subtype := by simp [H'', h]
rw [this]
obtain β¨S, cmem, -β© := H''.exists_isComplement_left 1
refine β¨H.subtype '' S, ?_, ?_β©
Β· have : H.subtype '' (S * H'') = H.subtype '' S * H''.map H.subtype := image_mul H.subtype
rw [β this, cmem.mul_eq]
simp [Set.ext_iff]
Β· rw [β cmem.card_mul_card]
refine congr_argβ (Β· * Β·) ?_ ?_ <;>
exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm
/-- Given two subgroups `H' β H`, there exists a right transversal to `H'` inside `H`. -/
@[to_additive "Given two subgroups `H' β H`, there exists a transversal to `H'` inside `H`"]
lemma exists_right_transversal_of_le {H' H : Subgroup G} (h : H' β€ H) :
β S : Set G, H' * S = H β§ Nat.card H' * Nat.card S = Nat.card H := by
let H'' : Subgroup H := H'.comap H.subtype
have : H' = H''.map H.subtype := by simp [H'', h]
rw [this]
obtain β¨S, cmem, -β© := H''.exists_isComplement_right 1
refine β¨H.subtype '' S, ?_, ?_β©
Β· have : H.subtype '' (H'' * S) = H''.map H.subtype * H.subtype '' S := image_mul H.subtype
rw [β this, cmem.mul_eq]
simp [Set.ext_iff]
Β· have : Nat.card H'' * Nat.card S = Nat.card H := cmem.card_mul_card
rw [β this]
refine congr_argβ (Β· * Β·) ?_ ?_ <;>
exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm
namespace IsComplement
/-- The equivalence `G β S Γ T`, such that the inverse is `(*) : S Γ T β G` -/
noncomputable def equiv {S T : Set G} (hST : IsComplement S T) : G β S Γ T :=
(Equiv.ofBijective (fun x : S Γ T => x.1.1 * x.2.1) hST).symm
variable (hST : IsComplement S T) (hHT : IsComplement H T) (hSK : IsComplement S K)
@[simp] theorem equiv_symm_apply (x : S Γ T) : (hST.equiv.symm x : G) = x.1.1 * x.2.1 := rfl
@[simp]
theorem equiv_fst_mul_equiv_snd (g : G) : β(hST.equiv g).fst * (hST.equiv g).snd = g :=
(Equiv.ofBijective (fun x : S Γ T => x.1.1 * x.2.1) hST).right_inv g
theorem equiv_fst_eq_mul_inv (g : G) : β(hST.equiv g).fst = g * ((hST.equiv g).snd : G)β»ΒΉ :=
eq_mul_inv_of_mul_eq (hST.equiv_fst_mul_equiv_snd g)
theorem equiv_snd_eq_inv_mul (g : G) : β(hST.equiv g).snd = ((hST.equiv g).fst : G)β»ΒΉ * g :=
eq_inv_mul_of_mul_eq (hST.equiv_fst_mul_equiv_snd g)
theorem equiv_fst_eq_iff_leftCosetEquivalence {gβ gβ : G} :
(hSK.equiv gβ).fst = (hSK.equiv gβ).fst β LeftCosetEquivalence K gβ gβ := by
rw [LeftCosetEquivalence, leftCoset_eq_iff]
constructor
Β· intro h
rw [β hSK.equiv_fst_mul_equiv_snd gβ, β hSK.equiv_fst_mul_equiv_snd gβ, β h,
mul_inv_rev, β mul_assoc, inv_mul_cancel_right, β coe_inv, β coe_mul]
exact Subtype.property _
Β· intro h
apply (isComplement_iff_existsUnique_inv_mul_mem.1 hSK gβ).unique
Β· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp
Β· rw [SetLike.mem_coe, β mul_mem_cancel_right h]
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp [equiv_fst_eq_mul_inv, β mul_assoc]
theorem equiv_snd_eq_iff_rightCosetEquivalence {gβ gβ : G} :
(hHT.equiv gβ).snd = (hHT.equiv gβ).snd β RightCosetEquivalence H gβ gβ := by
rw [RightCosetEquivalence, rightCoset_eq_iff]
constructor
Β· intro h
rw [β hHT.equiv_fst_mul_equiv_snd gβ, β hHT.equiv_fst_mul_equiv_snd gβ, β h,
mul_inv_rev, mul_assoc, mul_inv_cancel_left, β coe_inv, β coe_mul]
exact Subtype.property _
Β· intro h
apply (isComplement_iff_existsUnique_mul_inv_mem.1 hHT gβ).unique
Β· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_snd_eq_inv_mul]; simp
Β· rw [SetLike.mem_coe, β mul_mem_cancel_left h]
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_snd_eq_inv_mul, mul_assoc]; simp
theorem leftCosetEquivalence_equiv_fst (g : G) :
LeftCosetEquivalence K g ((hSK.equiv g).fst : G) := by
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp [LeftCosetEquivalence, leftCoset_eq_iff]
theorem rightCosetEquivalence_equiv_snd (g : G) :
RightCosetEquivalence H g ((hHT.equiv g).snd : G) := by
-- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [RightCosetEquivalence, rightCoset_eq_iff, equiv_snd_eq_inv_mul]; simp
theorem equiv_fst_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 β T) (hg : g β S) :
(hST.equiv g).fst = β¨g, hgβ© := by
have : hST.equiv.symm (β¨g, hgβ©, β¨1, h1β©) = g := by
rw [equiv, Equiv.ofBijective]; simp
conv_lhs => rw [β this, Equiv.apply_symm_apply]
theorem equiv_snd_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 β S) (hg : g β T) :
(hST.equiv g).snd = β¨g, hgβ© := by
have : hST.equiv.symm (β¨1, h1β©, β¨g, hgβ©) = g := by
rw [equiv, Equiv.ofBijective]; simp
conv_lhs => rw [β this, Equiv.apply_symm_apply]
theorem equiv_snd_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 β T) (hg : g β S) :
(hST.equiv g).snd = β¨1, h1β© := by
ext
rw [equiv_snd_eq_inv_mul, equiv_fst_eq_self_of_mem_of_one_mem _ h1 hg, inv_mul_cancel]
theorem equiv_fst_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 β S) (hg : g β T) :
(hST.equiv g).fst = β¨1, h1β© := by
ext
rw [equiv_fst_eq_mul_inv, equiv_snd_eq_self_of_mem_of_one_mem _ h1 hg, mul_inv_cancel]
theorem equiv_mul_right (g : G) (k : K) :
hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * k) := by
have : (hSK.equiv (g * k)).fst = (hSK.equiv g).fst :=
hSK.equiv_fst_eq_iff_leftCosetEquivalence.2
(by simp [LeftCosetEquivalence, leftCoset_eq_iff])
ext
Β· rw [this]
Β· rw [coe_mul, equiv_snd_eq_inv_mul, this, equiv_snd_eq_inv_mul, mul_assoc]
theorem equiv_mul_right_of_mem {g k : G} (h : k β K) :
hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * β¨k, hβ©) :=
equiv_mul_right _ g β¨k, hβ©
theorem equiv_mul_left (h : H) (g : G) :
hHT.equiv (h * g) = (h * (hHT.equiv g).fst, (hHT.equiv g).snd) := by
have : (hHT.equiv (h * g)).2 = (hHT.equiv g).2 := hHT.equiv_snd_eq_iff_rightCosetEquivalence.2 ?_
Β· ext
Β· rw [coe_mul, equiv_fst_eq_mul_inv, this, equiv_fst_eq_mul_inv, mul_assoc]
Β· rw [this]
Β· simp [RightCosetEquivalence, β smul_smul]
theorem equiv_mul_left_of_mem {h g : G} (hh : h β H) :
hHT.equiv (h * g) = (β¨h, hhβ© * (hHT.equiv g).fst, (hHT.equiv g).snd) :=
equiv_mul_left _ β¨h, hhβ© g
theorem equiv_one (hs1 : 1 β S) (ht1 : 1 β T) :
hST.equiv 1 = (β¨1, hs1β©, β¨1, ht1β©) := by
rw [Equiv.apply_eq_iff_eq_symm_apply]; simp [equiv]
theorem equiv_fst_eq_self_iff_mem {g : G} (h1 : 1 β T) :
((hST.equiv g).fst : G) = g β g β S := by
constructor
Β· intro h
rw [β h]
exact Subtype.prop _
Β· intro h
rw [hST.equiv_fst_eq_self_of_mem_of_one_mem h1 h]
theorem equiv_snd_eq_self_iff_mem {g : G} (h1 : 1 β S) :
((hST.equiv g).snd : G) = g β g β T := by
constructor
Β· intro h
rw [β h]
exact Subtype.prop _
Β· intro h
rw [hST.equiv_snd_eq_self_of_mem_of_one_mem h1 h]
theorem coe_equiv_fst_eq_one_iff_mem {g : G} (h1 : 1 β S) :
((hST.equiv g).fst : G) = 1 β g β T := by
rw [equiv_fst_eq_mul_inv, mul_inv_eq_one, eq_comm, equiv_snd_eq_self_iff_mem _ h1]
theorem coe_equiv_snd_eq_one_iff_mem {g : G} (h1 : 1 β T) :
((hST.equiv g).snd : G) = 1 β g β S := by
rw [equiv_snd_eq_inv_mul, inv_mul_eq_one, equiv_fst_eq_self_iff_mem _ h1]
/-- A left transversal is in bijection with left cosets. -/
@[to_additive "A left transversal is in bijection with left cosets."]
noncomputable def leftQuotientEquiv (hS : IsComplement S H) : G β§Έ H β S :=
(Equiv.ofBijective _ (isComplement_subgroup_right_iff_bijective.mp hS)).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toEquiv := leftQuotientEquiv
/-- A left transversal is finite iff the subgroup has finite index. -/
@[to_additive "A left transversal is finite iff the subgroup has finite index."]
theorem finite_left_iff (h : IsComplement S H) : Finite S β H.FiniteIndex := by
rw [β h.leftQuotientEquiv.finite_iff]
exact β¨fun _ β¦ finiteIndex_of_finite_quotient, fun _ β¦ finite_quotient_of_finiteIndexβ©
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.finite_iff := finite_left_iff
@[to_additive]
lemma finite_left [H.FiniteIndex] (hS : IsComplement S H) : S.Finite := hS.finite_left_iff.2 βΉ_βΊ
@[to_additive]
theorem quotientGroupMk_leftQuotientEquiv (hS : IsComplement S H) (q : G β§Έ H) :
Quotient.mk'' (leftQuotientEquiv hS q : G) = q :=
hS.leftQuotientEquiv.symm_apply_apply q
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.mk''_toEquiv := quotientGroupMk_leftQuotientEquiv
@[to_additive]
theorem leftQuotientEquiv_apply {f : G β§Έ H β G} (hf : β q, (f q : G β§Έ H) = q) (q : G β§Έ H) :
(leftQuotientEquiv (isComplement_range_left hf) q : G) = f q := by
refine (Subtype.ext_iff.mp ?_).trans (Subtype.coe_mk (f q) β¨q, rflβ©)
exact (leftQuotientEquiv (isComplement_range_left hf)).apply_eq_iff_eq_symm_apply.mpr (hf q).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toEquiv_apply := leftQuotientEquiv_apply
/-- A left transversal can be viewed as a function mapping each element of the group
to the chosen representative from that left coset. -/
@[to_additive "A left transversal can be viewed as a function mapping each element of the group
to the chosen representative from that left coset."]
noncomputable def toLeftFun (hS : IsComplement S H) : G β S := leftQuotientEquiv hS β Quotient.mk''
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.toFun := toLeftFun
@[to_additive]
theorem inv_toLeftFun_mul_mem (hS : IsComplement S H) (g : G) :
(toLeftFun hS g : G)β»ΒΉ * g β H :=
QuotientGroup.leftRel_apply.mp <| Quotient.exact' <| quotientGroupMk_leftQuotientEquiv _ _
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.inv_toFun_mul_mem := inv_toLeftFun_mul_mem
@[to_additive]
theorem inv_mul_toLeftFun_mem (hS : IsComplement S H) (g : G) :
gβ»ΒΉ * toLeftFun hS g β H :=
(congr_arg (Β· β H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (inv_toLeftFun_mul_mem hS g))
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemLeftTransversals.inv_mul_toFun_mem := inv_mul_toLeftFun_mem
/-- A right transversal is in bijection with right cosets. -/
@[to_additive "A right transversal is in bijection with right cosets."]
noncomputable def rightQuotientEquiv (hT : IsComplement H T) :
Quotient (QuotientGroup.rightRel H) β T :=
(Equiv.ofBijective _ (isComplement_subgroup_left_iff_bijective.mp hT)).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.toEquiv := rightQuotientEquiv
/-- A right transversal is finite iff the subgroup has finite index. -/
@[to_additive "A right transversal is finite iff the subgroup has finite index."]
theorem finite_right_iff (h : IsComplement H T) : Finite T β H.FiniteIndex := by
rw [β h.rightQuotientEquiv.finite_iff,
(QuotientGroup.quotientRightRelEquivQuotientLeftRel H).finite_iff]
exact β¨fun _ β¦ finiteIndex_of_finite_quotient, fun _ β¦ finite_quotient_of_finiteIndexβ©
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.finite_iff := finite_right_iff
@[to_additive]
lemma finite_right [H.FiniteIndex] (hT : IsComplement H T) : T.Finite := hT.finite_right_iff.2 βΉ_βΊ
@[to_additive]
theorem mk''_rightQuotientEquiv (hT : IsComplement H T)
(q : Quotient (QuotientGroup.rightRel H)) : Quotient.mk'' (rightQuotientEquiv hT q : G) = q :=
(rightQuotientEquiv hT).symm_apply_apply q
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.mk''_toEquiv := mk''_rightQuotientEquiv
@[to_additive]
theorem rightQuotientEquiv_apply {f : Quotient (QuotientGroup.rightRel H) β G}
(hf : β q, Quotient.mk'' (f q) = q) (q : Quotient (QuotientGroup.rightRel H)) :
(rightQuotientEquiv (isComplement_range_right hf) q : G) = f q := by
refine (Subtype.ext_iff.mp ?_).trans (Subtype.coe_mk (f q) β¨q, rflβ©)
exact (rightQuotientEquiv (isComplement_range_right hf)).apply_eq_iff_eq_symm_apply.2 (hf q).symm
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.toEquiv_apply := rightQuotientEquiv_apply
/-- A right transversal can be viewed as a function mapping each element of the group
to the chosen representative from that right coset. -/
@[to_additive "A right transversal can be viewed as a function mapping each element of the group
to the chosen representative from that right coset."]
noncomputable def toRightFun (hT : IsComplement H T) : G β T := rightQuotientEquiv hT β .mk''
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRightTransversals.toFun := toRightFun
@[to_additive]
theorem mul_inv_toRightFun_mem (hT : IsComplement H T) (g : G) :
g * (toRightFun hT g : G)β»ΒΉ β H :=
QuotientGroup.rightRel_apply.mp <| Quotient.exact' <| mk''_rightQuotientEquiv _ _
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRighTransversals.mul_inv_toFun_mem := mul_inv_toRightFun_mem
@[to_additive]
theorem toRightFun_mul_inv_mem (hT : IsComplement H T) (g : G) :
(toRightFun hT g : G) * gβ»ΒΉ β H :=
(congr_arg (Β· β H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (mul_inv_toRightFun_mem hT g))
@[deprecated (since := "2024-12-28")]
alias _root_.Subgroup.MemRighTransversals.toFun_mul_inv_mem := toRightFun_mul_inv_mem
end IsComplement
section Action
open Pointwise MulAction MemLeftTransversals
| /-- The collection of left transversals of a subgroup -/
@[to_additive "The collection of left transversals of a subgroup."]
abbrev LeftTransversal (H : Subgroup G) := {S : Set G // IsComplement S H}
/-- The collection of right transversals of a subgroup -/
| Mathlib/GroupTheory/Complement.lean | 713 | 717 |
/-
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
-/
import Mathlib.Analysis.Calculus.Deriv.AffineMap
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.Deriv.Mul
import Mathlib.Analysis.Calculus.Deriv.Slope
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Analysis.Normed.Module.Convex
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Topology.Instances.RealVectorSpace
import Mathlib.Topology.LocallyConstant.Basic
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the
derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`,
so they work both for real and complex derivatives.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x β€ B x` or
`βf xβ β€ B x` from upper estimates on `f'` or `βf'β`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `βf xβ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `β`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `βf x - f aβ β€ C * βx - aβ`; several versions deal with
right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`).
* `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is
strictly differentiable. (This is a corollary of the mean value inequality.)
-/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β E] {F : Type*} [NormedAddCommGroup F]
[NormedSpace β F]
open Metric Set Asymptotics ContinuousLinearMap Filter
open scoped Topology NNReal
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope f x z < r)
{B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x := by
change Icc a b β { x | f x β€ B x }
set s := { x | f x β€ B x } β© Icc a b
have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB
have : IsClosed s := by
simp only [s, inter_comm]
exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le'
apply this.Icc_subset_of_forall_exists_gt ha
rintro x β¨hxB : f x β€ B x, xabβ© y hy
rcases hxB.lt_or_eq with hxB | hxB
Β· -- If `f x < B x`, then all we need is continuity of both sides
refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy))
have : βαΆ x in π[Icc a b] x, f x < B x :=
A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB)
have : βαΆ x in π[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this
exact this.mono fun y => le_of_lt
Β· rcases exists_between (bound x xab hxB) with β¨r, hfr, hrBβ©
specialize hf' x xab r hfr
have HB : βαΆ z in π[>] x, r < slope B x z :=
(hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici
(Ioi_mem_nhds hrB)
obtain β¨z, hfz, hzB, hzβ© : β z, slope f x z < r β§ r < slope B x z β§ z β Ioc x y :=
hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists
refine β¨z, ?_, hzβ©
have := (hfz.trans hzB).le
rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB,
sub_le_sub_iff_right] at this
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (f z - f x) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope f x z < r)
{B B' : β β β} (ha : f a β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by `B'`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) {B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
-- `bound` actually says `liminf (f z - f x) / (z - x) β€ B' x`
(bound : β x β Ico a b, β r, B' x < r β βαΆ z in π[>] x, slope f x z < r) :
β β¦xβ¦, x β Icc a b β f x β€ B x := by
have Hr : β x β Icc a b, β r > 0, f x β€ B x + r * (x - a) := fun x hx r hr => by
apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound
Β· rwa [sub_self, mul_zero, add_zero]
Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const))
Β· intro x hx
exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r)
Β· intro x _ _
rw [mul_one]
exact (lt_add_iff_pos_right _).2 hr
exact hx
intro x hx
have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 :=
continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const)
convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, f x = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a β€ B a`;
* `B` has derivative `B'` everywhere on `β`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x β€ B' x` on `[a, b)`.
Then `f x β€ B x` everywhere on `[a, b]`. -/
theorem image_le_of_deriv_right_le_deriv_boundary {f f' : β β β} {a b : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : f a β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, f' x β€ B' x) : β β¦xβ¦, x β Icc a b β f x β€ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr =>
(hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr)
/-! ### Vector-valued functions `f : β β E` -/
section
variable {f : β β E} {a b : β}
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `B` has right derivative at every point of `[a, b)`;
* for each `x β [a, b)` the right-side limit inferior of `(βf zβ - βf xβ) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. -/
theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*}
[NormedAddCommGroup E] {f : β β E} {f' : β β β} (hf : ContinuousOn f (Icc a b))
-- `hf'` actually says `liminf (βf zβ - βf xβ) / (z - x) β€ f' x`
(hf' : β x β Ico a b, β r, f' x < r β βαΆ z in π[>] x, slope (norm β f) x z < r)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf xβ = B x β f' x < B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB
hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* the norm of `f'` is strictly less than `B'` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf xβ = B x β βf' xβ < B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf
(fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `β`;
* the norm of `f'` is strictly less than `B'` whenever `βf xβ = B x`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, βf xβ = B x β βf' xβ < B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* we have `βf' xβ β€ B x` everywhere on `[a, b)`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : ContinuousOn B (Icc a b))
(hB' : β x β Ico a b, HasDerivWithinAt B (B' x) (Ici x) x)
(bound : β x β Ico a b, βf' xβ β€ B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB'
fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr)
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `βf aβ β€ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `β`;
* we have `βf' xβ β€ B x` everywhere on `[a, b)`.
Then `βf xβ β€ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : β β E}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
{B B' : β β β} (ha : βf aβ β€ B a) (hB : β x, HasDerivAt B (B' x) x)
(bound : β x β Ico a b, βf' xβ β€ B' x) : β β¦xβ¦, x β Icc a b β βf xβ β€ B x :=
image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha
(fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C`
satisfies `βf x - f aβ β€ C * (x - a)`. -/
theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : β β E} {C : β}
(hf : ContinuousOn f (Icc a b)) (hf' : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(bound : β x β Ico a b, βf' xβ β€ C) : β x β Icc a b, βf x - f aβ β€ C * (x - a) := by
let g x := f x - f a
have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const
have hg' : β x β Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by
intro x hx
simp [g, hf' x hx]
let B x := C * (x - a)
have hB : β x, HasDerivAt B C x := by
intro x
simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a))
convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound
simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero]
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `βf x - f aβ β€ C * (x - a)`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : β β E} {C : β}
(hf : β x β Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x)
(bound : β x β Ico a b, βf' xβ β€ C) : β x β Icc a b, βf x - f aβ β€ C * (x - a) := by
refine
norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt)
(fun x hx => ?_) bound
exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx)
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `βf x - f aβ β€ C * (x - a)`, `derivWithin`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment {C : β} (hf : DifferentiableOn β f (Icc a b))
(bound : β x β Ico a b, βderivWithin f (Icc a b) xβ β€ C) :
β x β Icc a b, βf x - f aβ β€ C * (x - a) := by
refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound
exact fun x hx => (hf x hx).hasDerivWithinAt
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `βf 1 - f 0β β€ C`, `HasDerivWithinAt`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : β β E} {C : β}
(hf : β x β Icc (0 : β) 1, HasDerivWithinAt f (f' x) (Icc (0 : β) 1) x)
(bound : β x β Ico (0 : β) 1, βf' xβ β€ C) : βf 1 - f 0β β€ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `βf 1 - f 0β β€ C`, `derivWithin` version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : β}
(hf : DifferentiableOn β f (Icc (0 : β) 1))
(bound : β x β Ico (0 : β) 1, βderivWithin f (Icc (0 : β) 1) xβ β€ C) : βf 1 - f 0β β€ C := by
simpa only [sub_zero, mul_one] using
norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one)
theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b))
(hderiv : β x β Ico a b, HasDerivWithinAt f 0 (Ici x) x) : β x β Icc a b, f x = f a := by
have : β x β Icc a b, βf x - f aβ β€ 0 * (x - a) := fun x hx =>
norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this
theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn β f (Icc a b))
(hderiv : β x β Ico a b, derivWithin f (Icc a b) x = 0) : β x β Icc a b, f x = f a := by
have H : β x β Ico a b, βderivWithin f (Icc a b) xβ β€ 0 := by
simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx
simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx =>
norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx
variable {f' g : β β E}
/-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`,
then they are equal everywhere on `[a, b]`. -/
theorem eq_of_has_deriv_right_eq (derivf : β x β Ico a b, HasDerivWithinAt f (f' x) (Ici x) x)
(derivg : β x β Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b))
(gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : β y β Icc a b, f y = g y := by
simp only [β @sub_eq_zero _ _ (f _)] at hi β’
exact hi βΈ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by
simpa only [sub_self] using (derivf y hy).sub (derivg y hy)
/-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere
on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/
theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn β f (Icc a b))
(gdiff : DifferentiableOn β g (Icc a b))
(hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) :
β y β Icc a b, f y = g y := by
have A : β y β Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy =>
(fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
have B : β y β Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy =>
(gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin
(Icc_mem_nhdsGE_of_mem hy)
exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm βΈ B y hy) fdiff.continuousOn
gdiff.continuousOn hi
end
/-!
### Vector-valued functions `f : E β G`
Theorems in this section work both for real and complex differentiable functions. We use assumptions
`[NontriviallyNormedField π] [IsRCLikeNormedField π] [NormedSpace π E] [NormedSpace π G]` to
achieve this result. For the domain `E` we also assume `[NormedSpace β E]` to have a notion
of a `Convex` set. -/
section
namespace Convex
variable {π G : Type*} [NontriviallyNormedField π] [IsRCLikeNormedField π]
[NormedSpace π E] [NormedAddCommGroup G] [NormedSpace π G]
{f g : E β G} {C : β} {s : Set E} {x y : E} {f' g' : E β E βL[π] G} {Ο : E βL[π] G}
instance (priority := 100) : PathConnectedSpace π := by
letI : RCLike π := IsRCLikeNormedField.rclike π
infer_instance
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then
the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasFDerivWithin_le
(hf : β x β s, HasFDerivWithinAt f (f' x) s x) (bound : β x β s, βf' xβ β€ C) (hs : Convex β s)
(xs : x β s) (ys : y β s) : βf y - f xβ β€ C * βy - xβ := by
letI : RCLike π := IsRCLikeNormedField.rclike π
letI : NormedSpace β G := RestrictScalars.normedSpace β π G
/- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined
on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`.
We just have to check the differentiability of the composition and bounds on its derivative,
which is straightforward but tedious for lack of automation. -/
set g := (AffineMap.lineMap x y : β β E)
have segm : MapsTo g (Icc 0 1 : Set β) s := hs.mapsTo_lineMap xs ys
have hD : β t β Icc (0 : β) 1,
HasDerivWithinAt (f β g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by
simpa using ((hf (g t) (segm ht)).restrictScalars β).comp_hasDerivWithinAt _
AffineMap.hasDerivWithinAt_lineMap segm
have bound : β t β Ico (0 : β) 1, βf' (g t) (y - x)β β€ C * βy - xβ := fun t ht =>
le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _
simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and
`LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ββ₯0}
(hf : β x β s, HasFDerivWithinAt f (f' x) s x) (bound : β x β s, βf' xββ β€ C)
(hs : Convex β s) : LipschitzOnWith C f s := by
rw [lipschitzOnWith_iff_norm_sub_le]
intro x x_in y y_in
exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ββ₯0` larger than `βf' xββ`, `f` is
`K`-Lipschitz on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims
existence of `K` instead of an explicit estimate. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex β s)
{f : E β G} (hder : βαΆ y in π[s] x, HasFDerivWithinAt f (f' y) s y)
(hcont : ContinuousWithinAt f' s x) (K : ββ₯0) (hK : βf' xββ < K) :
β t β π[s] x, LipschitzOnWith K f t := by
obtain β¨Ξ΅, Ξ΅0, hΞ΅β© : β Ξ΅ > 0,
ball x Ξ΅ β© s β { y | HasFDerivWithinAt f (f' y) s y β§ βf' yββ < K } :=
mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK))
rw [inter_comm] at hΞ΅
refine β¨s β© ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), ?_β©
exact
(hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le
(fun y hy => (hΞ΅ hy).1.mono inter_subset_left) fun y hy => (hΞ΅ hy).2.le
/-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β G` be a function
differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is
continuous within `s` at `x`. Then for any number `K : ββ₯0` larger than `βf' xββ`, `f` is Lipschitz
on some neighborhood of `x` within `s`. See also
`Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version
with an explicit estimate on the Lipschitz constant. -/
theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex β s) {f : E β G}
(hder : βαΆ y in π[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) :
β K, β t β π[s] x, LipschitzOnWith K f t :=
(exists_gt _).imp <|
hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont
/-- The mean value theorem on a convex set: if the derivative of a function within this set is
bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/
theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π f s)
(bound : β x β s, βfderivWithin π f s xβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound
xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and
`LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ββ₯0} (hf : DifferentiableOn π f s)
(bound : β x β s, βfderivWithin π f s xββ β€ C) (hs : Convex β s) : LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`,
then the function is `C`-Lipschitz. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βfderiv π f xβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f xβ β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on
`s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/
theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ββ₯0} (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βfderiv π f xββ β€ C) (hs : Convex β s) : LipschitzOnWith C f s :=
hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound
/-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is
`C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/
theorem _root_.lipschitzWith_of_nnnorm_fderiv_le
{E : Type*} [NormedAddCommGroup E] [NormedSpace π E] {f : E β G}
{C : ββ₯0} (hf : Differentiable π f)
(bound : β x, βfderiv π f xββ β€ C) : LipschitzWith C f := by
letI : RCLike π := IsRCLikeNormedField.rclike π
let A : NormedSpace β E := RestrictScalars.normedSpace β π E
rw [β lipschitzOnWith_univ]
exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ β¦ hf x) (fun x _ β¦ bound x) convex_univ
/-- Variant of the mean value inequality on a convex set, using a bound on the difference between
the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with
`HasFDerivWithinAt`. -/
theorem norm_image_sub_le_of_norm_hasFDerivWithin_le'
(hf : β x β s, HasFDerivWithinAt f (f' x) s x) (bound : β x β s, βf' x - Οβ β€ C)
(hs : Convex β s) (xs : x β s) (ys : y β s) : βf y - f x - Ο (y - x)β β€ C * βy - xβ := by
/- We subtract `Ο` to define a new function `g` for which `g' = 0`, for which the previous theorem
applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue
together the pieces, expressing back `f` in terms of `g`. -/
let g y := f y - Ο y
have hg : β x β s, HasFDerivWithinAt g (f' x - Ο) s x := fun x xs =>
(hf x xs).sub Ο.hasFDerivWithinAt
calc
βf y - f x - Ο (y - x)β = βf y - f x - (Ο y - Ο x)β := by simp
_ = βf y - Ο y - (f x - Ο x)β := by congr 1; abel
_ = βg y - g xβ := by simp [g]
_ β€ C * βy - xβ := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys
/-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/
theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π f s)
(bound : β x β s, βfderivWithin π f s x - Οβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f x - Ο (y - x)β β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound
xs ys
/-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/
theorem norm_image_sub_le_of_norm_fderiv_le' (hf : β x β s, DifferentiableAt π f x)
(bound : β x β s, βfderiv π f x - Οβ β€ C) (hs : Convex β s) (xs : x β s) (ys : y β s) :
βf y - f x - Ο (y - x)β β€ C * βy - xβ :=
hs.norm_image_sub_le_of_norm_hasFDerivWithin_le'
(fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys
/-- If a function has zero FrΓ©chet derivative at every point of a convex set,
then it is a constant on this set. -/
theorem is_const_of_fderivWithin_eq_zero (hs : Convex β s) (hf : DifferentiableOn π f s)
(hf' : β x β s, fderivWithin π f s x = 0) (hx : x β s) (hy : y β s) : f x = f y := by
have bound : β x β s, βfderivWithin π f s xβ β€ 0 := fun x hx => by
simp only [hf' x hx, norm_zero, le_rfl]
simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using
hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy
theorem _root_.is_const_of_fderiv_eq_zero
{E : Type*} [NormedAddCommGroup E] [NormedSpace π E] {f : E β G}
(hf : Differentiable π f) (hf' : β x, fderiv π f x = 0)
(x y : E) : f x = f y := by
letI : RCLike π := IsRCLikeNormedField.rclike π
let A : NormedSpace β E := RestrictScalars.normedSpace β π E
exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn
(fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial
/-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at
one point in that set, then they are equal on that set. -/
theorem eqOn_of_fderivWithin_eq (hs : Convex β s) (hf : DifferentiableOn π f s)
(hg : DifferentiableOn π g s) (hs' : UniqueDiffOn π s)
(hf' : s.EqOn (fderivWithin π f s) (fderivWithin π g s)) (hx : x β s) (hfgx : f x = g x) :
s.EqOn f g := fun y hy => by
suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this
refine hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => ?_) hx hy
rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' hz]
/-- If `f` has zero derivative on an open set, then `f` is locally constant on `s`. -/
-- TODO: change the spelling once we have `IsLocallyConstantOn`.
theorem _root_.IsOpen.isOpen_inter_preimage_of_fderiv_eq_zero
(hs : IsOpen s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (fderiv π f) 0) (t : Set G) : IsOpen (s β© f β»ΒΉ' t) := by
refine Metric.isOpen_iff.mpr fun y β¨hy, hy'β© β¦ ?_
obtain β¨r, hr, hβ© := Metric.isOpen_iff.mp hs y hy
refine β¨r, hr, Set.subset_inter h fun x hx β¦ ?_β©
have := (convex_ball y r).is_const_of_fderivWithin_eq_zero (hf.mono h) ?_ hx (mem_ball_self hr)
Β· simpa [this]
Β· intro z hz
simpa only [fderivWithin_of_isOpen Metric.isOpen_ball hz] using hf' (h hz)
theorem _root_.isLocallyConstant_of_fderiv_eq_zero (hβ : Differentiable π f)
(hβ : β x, fderiv π f x = 0) : IsLocallyConstant f := by
simpa using isOpen_univ.isOpen_inter_preimage_of_fderiv_eq_zero hβ.differentiableOn fun _ _ β¦ hβ _
/-- If `f` has zero derivative on a connected open set, then `f` is constant on `s`. -/
theorem _root_.IsOpen.exists_is_const_of_fderiv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (fderiv π f) 0) : β a, β x β s, f x = a := by
obtain (rfl|β¨y, hyβ©) := s.eq_empty_or_nonempty
Β· exact β¨0, by simpβ©
Β· refine β¨f y, fun x hx β¦ ?_β©
have hβ := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf hf' {f y}
have hβ := hf.continuousOn.comp_continuous continuous_subtype_val (fun x β¦ x.2)
by_contra hβ
obtain β¨t, ht, ht'β© := (isClosed_singleton (x := f y)).preimage hβ
have ht'' : β a β s, a β t β f a β f y := by simpa [Set.ext_iff] using ht'
obtain β¨z, Hβ, Hβ, Hββ© := hs' _ _ hβ ht (fun x h β¦ by simp [h, ht'', eq_or_ne]) β¨y, by simpaβ©
β¨x, by simp [ht'' _ hx, hx, hβ]β©
exact (ht'' _ Hβ).mp Hβ Hβ.2
theorem _root_.IsOpen.is_const_of_fderiv_eq_zero
(hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π f s)
(hf' : s.EqOn (fderiv π f) 0) {x y : E} (hx : x β s) (hy : y β s) : f x = f y := by
obtain β¨a, haβ© := hs.exists_is_const_of_fderiv_eq_zero hs' hf hf'
rw [ha x hx, ha y hy]
theorem _root_.IsOpen.exists_eq_add_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s)
(hf : DifferentiableOn π f s) (hg : DifferentiableOn π g s)
(hf' : s.EqOn (fderiv π f) (fderiv π g)) : β a, s.EqOn f (g Β· + a) := by
simp_rw [Set.EqOn, β sub_eq_iff_eq_add']
refine hs.exists_is_const_of_fderiv_eq_zero hs' (hf.sub hg) fun x hx β¦ ?_
rw [fderiv_sub (hf.differentiableAt (hs.mem_nhds hx)) (hg.differentiableAt (hs.mem_nhds hx)),
hf' hx, sub_self, Pi.zero_apply]
/-- If two functions have equal FrΓ©chet derivatives at every point of a connected open set,
and are equal at one point in that set, then they are equal on that set. -/
theorem _root_.IsOpen.eqOn_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s)
(hf : DifferentiableOn π f s) (hg : DifferentiableOn π g s)
(hf' : β x β s, fderiv π f x = fderiv π g x) (hx : x β s) (hfgx : f x = g x) :
s.EqOn f g := by
obtain β¨a, haβ© := hs.exists_eq_add_of_fderiv_eq hs' hf hg hf'
obtain rfl := left_eq_add.mp (hfgx.symm.trans (ha hx))
simpa using ha
theorem _root_.eq_of_fderiv_eq
{E : Type*} [NormedAddCommGroup E] [NormedSpace π E] {f g : E β G}
(hf : Differentiable π f) (hg : Differentiable π g)
(hf' : β x, fderiv π f x = fderiv π g x) (x : E) (hfgx : f x = g x) : f = g := by
letI : RCLike π := IsRCLikeNormedField.rclike π
let A : NormedSpace β E := RestrictScalars.normedSpace β π E
suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x
exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn
uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx
lemma isLittleO_pow_succ {xβ : E} {n : β} (hs : Convex β s) (hxβs : xβ β s)
(hff' : β x β s, HasFDerivWithinAt f (f' x) s x) (hf' : f' =o[π[s] xβ] fun x β¦ βx - xββ ^ n) :
(fun x β¦ f x - f xβ) =o[π[s] xβ] fun x β¦ βx - xββ ^ (n + 1) := by
rw [Asymptotics.isLittleO_iff] at hf' β’
intro c hc
simp_rw [norm_pow, pow_succ, β mul_assoc, norm_norm]
simp_rw [norm_pow, norm_norm] at hf'
| have : βαΆ x in π[s] xβ, segment β xβ x β s β§ β y β segment β xβ x, βf' yβ β€ c * βx - xββ ^ n := by
have h1 : βαΆ x in π[s] xβ, x β s := eventually_mem_nhdsWithin
filter_upwards [h1, hs.eventually_nhdsWithin_segment hxβs (hf' hc)] with x hxs h
refine β¨hs.segment_subset hxβs hxs, fun y hy β¦ (h y hy).trans ?_β©
gcongr
| Mathlib/Analysis/Calculus/MeanValue.lean | 655 | 659 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.